three.module.js 1.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319
  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 = '107dev';
  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. function Matrix3() {
  1406. this.elements = [
  1407. 1, 0, 0,
  1408. 0, 1, 0,
  1409. 0, 0, 1
  1410. ];
  1411. if ( arguments.length > 0 ) {
  1412. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  1413. }
  1414. }
  1415. Object.assign( Matrix3.prototype, {
  1416. isMatrix3: true,
  1417. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  1418. var te = this.elements;
  1419. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  1420. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  1421. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  1422. return this;
  1423. },
  1424. identity: function () {
  1425. this.set(
  1426. 1, 0, 0,
  1427. 0, 1, 0,
  1428. 0, 0, 1
  1429. );
  1430. return this;
  1431. },
  1432. clone: function () {
  1433. return new this.constructor().fromArray( this.elements );
  1434. },
  1435. copy: function ( m ) {
  1436. var te = this.elements;
  1437. var me = m.elements;
  1438. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  1439. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  1440. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  1441. return this;
  1442. },
  1443. setFromMatrix4: function ( m ) {
  1444. var me = m.elements;
  1445. this.set(
  1446. me[ 0 ], me[ 4 ], me[ 8 ],
  1447. me[ 1 ], me[ 5 ], me[ 9 ],
  1448. me[ 2 ], me[ 6 ], me[ 10 ]
  1449. );
  1450. return this;
  1451. },
  1452. applyToBufferAttribute: function () {
  1453. var v1 = new Vector3();
  1454. return function applyToBufferAttribute( attribute ) {
  1455. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  1456. v1.x = attribute.getX( i );
  1457. v1.y = attribute.getY( i );
  1458. v1.z = attribute.getZ( i );
  1459. v1.applyMatrix3( this );
  1460. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  1461. }
  1462. return attribute;
  1463. };
  1464. }(),
  1465. multiply: function ( m ) {
  1466. return this.multiplyMatrices( this, m );
  1467. },
  1468. premultiply: function ( m ) {
  1469. return this.multiplyMatrices( m, this );
  1470. },
  1471. multiplyMatrices: function ( a, b ) {
  1472. var ae = a.elements;
  1473. var be = b.elements;
  1474. var te = this.elements;
  1475. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  1476. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  1477. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  1478. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  1479. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  1480. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  1481. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  1482. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  1483. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  1484. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  1485. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  1486. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  1487. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  1488. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  1489. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  1490. return this;
  1491. },
  1492. multiplyScalar: function ( s ) {
  1493. var te = this.elements;
  1494. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  1495. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  1496. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  1497. return this;
  1498. },
  1499. determinant: function () {
  1500. var te = this.elements;
  1501. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  1502. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  1503. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  1504. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  1505. },
  1506. getInverse: function ( matrix, throwOnDegenerate ) {
  1507. if ( matrix && matrix.isMatrix4 ) {
  1508. console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
  1509. }
  1510. var me = matrix.elements,
  1511. te = this.elements,
  1512. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  1513. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  1514. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  1515. t11 = n33 * n22 - n32 * n23,
  1516. t12 = n32 * n13 - n33 * n12,
  1517. t13 = n23 * n12 - n22 * n13,
  1518. det = n11 * t11 + n21 * t12 + n31 * t13;
  1519. if ( det === 0 ) {
  1520. var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
  1521. if ( throwOnDegenerate === true ) {
  1522. throw new Error( msg );
  1523. } else {
  1524. console.warn( msg );
  1525. }
  1526. return this.identity();
  1527. }
  1528. var detInv = 1 / det;
  1529. te[ 0 ] = t11 * detInv;
  1530. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  1531. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  1532. te[ 3 ] = t12 * detInv;
  1533. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  1534. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  1535. te[ 6 ] = t13 * detInv;
  1536. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  1537. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  1538. return this;
  1539. },
  1540. transpose: function () {
  1541. var tmp, m = this.elements;
  1542. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  1543. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  1544. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  1545. return this;
  1546. },
  1547. getNormalMatrix: function ( matrix4 ) {
  1548. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  1549. },
  1550. transposeIntoArray: function ( r ) {
  1551. var m = this.elements;
  1552. r[ 0 ] = m[ 0 ];
  1553. r[ 1 ] = m[ 3 ];
  1554. r[ 2 ] = m[ 6 ];
  1555. r[ 3 ] = m[ 1 ];
  1556. r[ 4 ] = m[ 4 ];
  1557. r[ 5 ] = m[ 7 ];
  1558. r[ 6 ] = m[ 2 ];
  1559. r[ 7 ] = m[ 5 ];
  1560. r[ 8 ] = m[ 8 ];
  1561. return this;
  1562. },
  1563. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  1564. var c = Math.cos( rotation );
  1565. var s = Math.sin( rotation );
  1566. this.set(
  1567. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  1568. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  1569. 0, 0, 1
  1570. );
  1571. },
  1572. scale: function ( sx, sy ) {
  1573. var te = this.elements;
  1574. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  1575. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  1576. return this;
  1577. },
  1578. rotate: function ( theta ) {
  1579. var c = Math.cos( theta );
  1580. var s = Math.sin( theta );
  1581. var te = this.elements;
  1582. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  1583. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  1584. te[ 0 ] = c * a11 + s * a21;
  1585. te[ 3 ] = c * a12 + s * a22;
  1586. te[ 6 ] = c * a13 + s * a23;
  1587. te[ 1 ] = - s * a11 + c * a21;
  1588. te[ 4 ] = - s * a12 + c * a22;
  1589. te[ 7 ] = - s * a13 + c * a23;
  1590. return this;
  1591. },
  1592. translate: function ( tx, ty ) {
  1593. var te = this.elements;
  1594. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  1595. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  1596. return this;
  1597. },
  1598. equals: function ( matrix ) {
  1599. var te = this.elements;
  1600. var me = matrix.elements;
  1601. for ( var i = 0; i < 9; i ++ ) {
  1602. if ( te[ i ] !== me[ i ] ) return false;
  1603. }
  1604. return true;
  1605. },
  1606. fromArray: function ( array, offset ) {
  1607. if ( offset === undefined ) offset = 0;
  1608. for ( var i = 0; i < 9; i ++ ) {
  1609. this.elements[ i ] = array[ i + offset ];
  1610. }
  1611. return this;
  1612. },
  1613. toArray: function ( array, offset ) {
  1614. if ( array === undefined ) array = [];
  1615. if ( offset === undefined ) offset = 0;
  1616. var te = this.elements;
  1617. array[ offset ] = te[ 0 ];
  1618. array[ offset + 1 ] = te[ 1 ];
  1619. array[ offset + 2 ] = te[ 2 ];
  1620. array[ offset + 3 ] = te[ 3 ];
  1621. array[ offset + 4 ] = te[ 4 ];
  1622. array[ offset + 5 ] = te[ 5 ];
  1623. array[ offset + 6 ] = te[ 6 ];
  1624. array[ offset + 7 ] = te[ 7 ];
  1625. array[ offset + 8 ] = te[ 8 ];
  1626. return array;
  1627. }
  1628. } );
  1629. /**
  1630. * @author mrdoob / http://mrdoob.com/
  1631. * @author alteredq / http://alteredqualia.com/
  1632. * @author szimek / https://github.com/szimek/
  1633. */
  1634. var _canvas;
  1635. var ImageUtils = {
  1636. getDataURL: function ( image ) {
  1637. var canvas;
  1638. if ( typeof HTMLCanvasElement == 'undefined' ) {
  1639. return image.src;
  1640. } else if ( image instanceof HTMLCanvasElement ) {
  1641. canvas = image;
  1642. } else {
  1643. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  1644. _canvas.width = image.width;
  1645. _canvas.height = image.height;
  1646. var context = _canvas.getContext( '2d' );
  1647. if ( image instanceof ImageData ) {
  1648. context.putImageData( image, 0, 0 );
  1649. } else {
  1650. context.drawImage( image, 0, 0, image.width, image.height );
  1651. }
  1652. canvas = _canvas;
  1653. }
  1654. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  1655. return canvas.toDataURL( 'image/jpeg', 0.6 );
  1656. } else {
  1657. return canvas.toDataURL( 'image/png' );
  1658. }
  1659. }
  1660. };
  1661. /**
  1662. * @author mrdoob / http://mrdoob.com/
  1663. * @author alteredq / http://alteredqualia.com/
  1664. * @author szimek / https://github.com/szimek/
  1665. */
  1666. var textureId = 0;
  1667. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  1668. Object.defineProperty( this, 'id', { value: textureId ++ } );
  1669. this.uuid = _Math.generateUUID();
  1670. this.name = '';
  1671. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  1672. this.mipmaps = [];
  1673. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  1674. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  1675. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  1676. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  1677. this.minFilter = minFilter !== undefined ? minFilter : LinearMipmapLinearFilter;
  1678. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  1679. this.format = format !== undefined ? format : RGBAFormat;
  1680. this.type = type !== undefined ? type : UnsignedByteType;
  1681. this.offset = new Vector2( 0, 0 );
  1682. this.repeat = new Vector2( 1, 1 );
  1683. this.center = new Vector2( 0, 0 );
  1684. this.rotation = 0;
  1685. this.matrixAutoUpdate = true;
  1686. this.matrix = new Matrix3();
  1687. this.generateMipmaps = true;
  1688. this.premultiplyAlpha = false;
  1689. this.flipY = true;
  1690. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1691. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1692. //
  1693. // Also changing the encoding after already used by a Material will not automatically make the Material
  1694. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1695. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  1696. this.version = 0;
  1697. this.onUpdate = null;
  1698. }
  1699. Texture.DEFAULT_IMAGE = undefined;
  1700. Texture.DEFAULT_MAPPING = UVMapping;
  1701. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  1702. constructor: Texture,
  1703. isTexture: true,
  1704. updateMatrix: function () {
  1705. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  1706. },
  1707. clone: function () {
  1708. return new this.constructor().copy( this );
  1709. },
  1710. copy: function ( source ) {
  1711. this.name = source.name;
  1712. this.image = source.image;
  1713. this.mipmaps = source.mipmaps.slice( 0 );
  1714. this.mapping = source.mapping;
  1715. this.wrapS = source.wrapS;
  1716. this.wrapT = source.wrapT;
  1717. this.magFilter = source.magFilter;
  1718. this.minFilter = source.minFilter;
  1719. this.anisotropy = source.anisotropy;
  1720. this.format = source.format;
  1721. this.type = source.type;
  1722. this.offset.copy( source.offset );
  1723. this.repeat.copy( source.repeat );
  1724. this.center.copy( source.center );
  1725. this.rotation = source.rotation;
  1726. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1727. this.matrix.copy( source.matrix );
  1728. this.generateMipmaps = source.generateMipmaps;
  1729. this.premultiplyAlpha = source.premultiplyAlpha;
  1730. this.flipY = source.flipY;
  1731. this.unpackAlignment = source.unpackAlignment;
  1732. this.encoding = source.encoding;
  1733. return this;
  1734. },
  1735. toJSON: function ( meta ) {
  1736. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  1737. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  1738. return meta.textures[ this.uuid ];
  1739. }
  1740. var output = {
  1741. metadata: {
  1742. version: 4.5,
  1743. type: 'Texture',
  1744. generator: 'Texture.toJSON'
  1745. },
  1746. uuid: this.uuid,
  1747. name: this.name,
  1748. mapping: this.mapping,
  1749. repeat: [ this.repeat.x, this.repeat.y ],
  1750. offset: [ this.offset.x, this.offset.y ],
  1751. center: [ this.center.x, this.center.y ],
  1752. rotation: this.rotation,
  1753. wrap: [ this.wrapS, this.wrapT ],
  1754. format: this.format,
  1755. type: this.type,
  1756. encoding: this.encoding,
  1757. minFilter: this.minFilter,
  1758. magFilter: this.magFilter,
  1759. anisotropy: this.anisotropy,
  1760. flipY: this.flipY,
  1761. premultiplyAlpha: this.premultiplyAlpha,
  1762. unpackAlignment: this.unpackAlignment
  1763. };
  1764. if ( this.image !== undefined ) {
  1765. // TODO: Move to THREE.Image
  1766. var image = this.image;
  1767. if ( image.uuid === undefined ) {
  1768. image.uuid = _Math.generateUUID(); // UGH
  1769. }
  1770. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  1771. var url;
  1772. if ( Array.isArray( image ) ) {
  1773. // process array of images e.g. CubeTexture
  1774. url = [];
  1775. for ( var i = 0, l = image.length; i < l; i ++ ) {
  1776. url.push( ImageUtils.getDataURL( image[ i ] ) );
  1777. }
  1778. } else {
  1779. // process single image
  1780. url = ImageUtils.getDataURL( image );
  1781. }
  1782. meta.images[ image.uuid ] = {
  1783. uuid: image.uuid,
  1784. url: url
  1785. };
  1786. }
  1787. output.image = image.uuid;
  1788. }
  1789. if ( ! isRootObject ) {
  1790. meta.textures[ this.uuid ] = output;
  1791. }
  1792. return output;
  1793. },
  1794. dispose: function () {
  1795. this.dispatchEvent( { type: 'dispose' } );
  1796. },
  1797. transformUv: function ( uv ) {
  1798. if ( this.mapping !== UVMapping ) return uv;
  1799. uv.applyMatrix3( this.matrix );
  1800. if ( uv.x < 0 || uv.x > 1 ) {
  1801. switch ( this.wrapS ) {
  1802. case RepeatWrapping:
  1803. uv.x = uv.x - Math.floor( uv.x );
  1804. break;
  1805. case ClampToEdgeWrapping:
  1806. uv.x = uv.x < 0 ? 0 : 1;
  1807. break;
  1808. case MirroredRepeatWrapping:
  1809. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1810. uv.x = Math.ceil( uv.x ) - uv.x;
  1811. } else {
  1812. uv.x = uv.x - Math.floor( uv.x );
  1813. }
  1814. break;
  1815. }
  1816. }
  1817. if ( uv.y < 0 || uv.y > 1 ) {
  1818. switch ( this.wrapT ) {
  1819. case RepeatWrapping:
  1820. uv.y = uv.y - Math.floor( uv.y );
  1821. break;
  1822. case ClampToEdgeWrapping:
  1823. uv.y = uv.y < 0 ? 0 : 1;
  1824. break;
  1825. case MirroredRepeatWrapping:
  1826. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1827. uv.y = Math.ceil( uv.y ) - uv.y;
  1828. } else {
  1829. uv.y = uv.y - Math.floor( uv.y );
  1830. }
  1831. break;
  1832. }
  1833. }
  1834. if ( this.flipY ) {
  1835. uv.y = 1 - uv.y;
  1836. }
  1837. return uv;
  1838. }
  1839. } );
  1840. Object.defineProperty( Texture.prototype, "needsUpdate", {
  1841. set: function ( value ) {
  1842. if ( value === true ) this.version ++;
  1843. }
  1844. } );
  1845. /**
  1846. * @author supereggbert / http://www.paulbrunt.co.uk/
  1847. * @author philogb / http://blog.thejit.org/
  1848. * @author mikael emtinger / http://gomo.se/
  1849. * @author egraether / http://egraether.com/
  1850. * @author WestLangley / http://github.com/WestLangley
  1851. */
  1852. function Vector4( x, y, z, w ) {
  1853. this.x = x || 0;
  1854. this.y = y || 0;
  1855. this.z = z || 0;
  1856. this.w = ( w !== undefined ) ? w : 1;
  1857. }
  1858. Object.defineProperties( Vector4.prototype, {
  1859. "width": {
  1860. get: function () {
  1861. return this.z;
  1862. },
  1863. set: function ( value ) {
  1864. this.z = value;
  1865. }
  1866. },
  1867. "height": {
  1868. get: function () {
  1869. return this.w;
  1870. },
  1871. set: function ( value ) {
  1872. this.w = value;
  1873. }
  1874. }
  1875. } );
  1876. Object.assign( Vector4.prototype, {
  1877. isVector4: true,
  1878. set: function ( x, y, z, w ) {
  1879. this.x = x;
  1880. this.y = y;
  1881. this.z = z;
  1882. this.w = w;
  1883. return this;
  1884. },
  1885. setScalar: function ( scalar ) {
  1886. this.x = scalar;
  1887. this.y = scalar;
  1888. this.z = scalar;
  1889. this.w = scalar;
  1890. return this;
  1891. },
  1892. setX: function ( x ) {
  1893. this.x = x;
  1894. return this;
  1895. },
  1896. setY: function ( y ) {
  1897. this.y = y;
  1898. return this;
  1899. },
  1900. setZ: function ( z ) {
  1901. this.z = z;
  1902. return this;
  1903. },
  1904. setW: function ( w ) {
  1905. this.w = w;
  1906. return this;
  1907. },
  1908. setComponent: function ( index, value ) {
  1909. switch ( index ) {
  1910. case 0: this.x = value; break;
  1911. case 1: this.y = value; break;
  1912. case 2: this.z = value; break;
  1913. case 3: this.w = value; break;
  1914. default: throw new Error( 'index is out of range: ' + index );
  1915. }
  1916. return this;
  1917. },
  1918. getComponent: function ( index ) {
  1919. switch ( index ) {
  1920. case 0: return this.x;
  1921. case 1: return this.y;
  1922. case 2: return this.z;
  1923. case 3: return this.w;
  1924. default: throw new Error( 'index is out of range: ' + index );
  1925. }
  1926. },
  1927. clone: function () {
  1928. return new this.constructor( this.x, this.y, this.z, this.w );
  1929. },
  1930. copy: function ( v ) {
  1931. this.x = v.x;
  1932. this.y = v.y;
  1933. this.z = v.z;
  1934. this.w = ( v.w !== undefined ) ? v.w : 1;
  1935. return this;
  1936. },
  1937. add: function ( v, w ) {
  1938. if ( w !== undefined ) {
  1939. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1940. return this.addVectors( v, w );
  1941. }
  1942. this.x += v.x;
  1943. this.y += v.y;
  1944. this.z += v.z;
  1945. this.w += v.w;
  1946. return this;
  1947. },
  1948. addScalar: function ( s ) {
  1949. this.x += s;
  1950. this.y += s;
  1951. this.z += s;
  1952. this.w += s;
  1953. return this;
  1954. },
  1955. addVectors: function ( a, b ) {
  1956. this.x = a.x + b.x;
  1957. this.y = a.y + b.y;
  1958. this.z = a.z + b.z;
  1959. this.w = a.w + b.w;
  1960. return this;
  1961. },
  1962. addScaledVector: function ( v, s ) {
  1963. this.x += v.x * s;
  1964. this.y += v.y * s;
  1965. this.z += v.z * s;
  1966. this.w += v.w * s;
  1967. return this;
  1968. },
  1969. sub: function ( v, w ) {
  1970. if ( w !== undefined ) {
  1971. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1972. return this.subVectors( v, w );
  1973. }
  1974. this.x -= v.x;
  1975. this.y -= v.y;
  1976. this.z -= v.z;
  1977. this.w -= v.w;
  1978. return this;
  1979. },
  1980. subScalar: function ( s ) {
  1981. this.x -= s;
  1982. this.y -= s;
  1983. this.z -= s;
  1984. this.w -= s;
  1985. return this;
  1986. },
  1987. subVectors: function ( a, b ) {
  1988. this.x = a.x - b.x;
  1989. this.y = a.y - b.y;
  1990. this.z = a.z - b.z;
  1991. this.w = a.w - b.w;
  1992. return this;
  1993. },
  1994. multiplyScalar: function ( scalar ) {
  1995. this.x *= scalar;
  1996. this.y *= scalar;
  1997. this.z *= scalar;
  1998. this.w *= scalar;
  1999. return this;
  2000. },
  2001. applyMatrix4: function ( m ) {
  2002. var x = this.x, y = this.y, z = this.z, w = this.w;
  2003. var e = m.elements;
  2004. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  2005. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  2006. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  2007. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  2008. return this;
  2009. },
  2010. divideScalar: function ( scalar ) {
  2011. return this.multiplyScalar( 1 / scalar );
  2012. },
  2013. setAxisAngleFromQuaternion: function ( q ) {
  2014. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2015. // q is assumed to be normalized
  2016. this.w = 2 * Math.acos( q.w );
  2017. var s = Math.sqrt( 1 - q.w * q.w );
  2018. if ( s < 0.0001 ) {
  2019. this.x = 1;
  2020. this.y = 0;
  2021. this.z = 0;
  2022. } else {
  2023. this.x = q.x / s;
  2024. this.y = q.y / s;
  2025. this.z = q.z / s;
  2026. }
  2027. return this;
  2028. },
  2029. setAxisAngleFromRotationMatrix: function ( m ) {
  2030. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2031. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2032. var angle, x, y, z, // variables for result
  2033. epsilon = 0.01, // margin to allow for rounding errors
  2034. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  2035. te = m.elements,
  2036. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  2037. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  2038. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2039. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  2040. ( Math.abs( m13 - m31 ) < epsilon ) &&
  2041. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  2042. // singularity found
  2043. // first check for identity matrix which must have +1 for all terms
  2044. // in leading diagonal and zero in other terms
  2045. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  2046. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  2047. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  2048. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  2049. // this singularity is identity matrix so angle = 0
  2050. this.set( 1, 0, 0, 0 );
  2051. return this; // zero angle, arbitrary axis
  2052. }
  2053. // otherwise this singularity is angle = 180
  2054. angle = Math.PI;
  2055. var xx = ( m11 + 1 ) / 2;
  2056. var yy = ( m22 + 1 ) / 2;
  2057. var zz = ( m33 + 1 ) / 2;
  2058. var xy = ( m12 + m21 ) / 4;
  2059. var xz = ( m13 + m31 ) / 4;
  2060. var yz = ( m23 + m32 ) / 4;
  2061. if ( ( xx > yy ) && ( xx > zz ) ) {
  2062. // m11 is the largest diagonal term
  2063. if ( xx < epsilon ) {
  2064. x = 0;
  2065. y = 0.707106781;
  2066. z = 0.707106781;
  2067. } else {
  2068. x = Math.sqrt( xx );
  2069. y = xy / x;
  2070. z = xz / x;
  2071. }
  2072. } else if ( yy > zz ) {
  2073. // m22 is the largest diagonal term
  2074. if ( yy < epsilon ) {
  2075. x = 0.707106781;
  2076. y = 0;
  2077. z = 0.707106781;
  2078. } else {
  2079. y = Math.sqrt( yy );
  2080. x = xy / y;
  2081. z = yz / y;
  2082. }
  2083. } else {
  2084. // m33 is the largest diagonal term so base result on this
  2085. if ( zz < epsilon ) {
  2086. x = 0.707106781;
  2087. y = 0.707106781;
  2088. z = 0;
  2089. } else {
  2090. z = Math.sqrt( zz );
  2091. x = xz / z;
  2092. y = yz / z;
  2093. }
  2094. }
  2095. this.set( x, y, z, angle );
  2096. return this; // return 180 deg rotation
  2097. }
  2098. // as we have reached here there are no singularities so we can handle normally
  2099. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  2100. ( m13 - m31 ) * ( m13 - m31 ) +
  2101. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  2102. if ( Math.abs( s ) < 0.001 ) s = 1;
  2103. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2104. // caught by singularity test above, but I've left it in just in case
  2105. this.x = ( m32 - m23 ) / s;
  2106. this.y = ( m13 - m31 ) / s;
  2107. this.z = ( m21 - m12 ) / s;
  2108. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  2109. return this;
  2110. },
  2111. min: function ( v ) {
  2112. this.x = Math.min( this.x, v.x );
  2113. this.y = Math.min( this.y, v.y );
  2114. this.z = Math.min( this.z, v.z );
  2115. this.w = Math.min( this.w, v.w );
  2116. return this;
  2117. },
  2118. max: function ( v ) {
  2119. this.x = Math.max( this.x, v.x );
  2120. this.y = Math.max( this.y, v.y );
  2121. this.z = Math.max( this.z, v.z );
  2122. this.w = Math.max( this.w, v.w );
  2123. return this;
  2124. },
  2125. clamp: function ( min, max ) {
  2126. // assumes min < max, componentwise
  2127. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2128. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2129. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2130. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  2131. return this;
  2132. },
  2133. clampScalar: function () {
  2134. var min, max;
  2135. return function clampScalar( minVal, maxVal ) {
  2136. if ( min === undefined ) {
  2137. min = new Vector4();
  2138. max = new Vector4();
  2139. }
  2140. min.set( minVal, minVal, minVal, minVal );
  2141. max.set( maxVal, maxVal, maxVal, maxVal );
  2142. return this.clamp( min, max );
  2143. };
  2144. }(),
  2145. clampLength: function ( min, max ) {
  2146. var length = this.length();
  2147. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2148. },
  2149. floor: function () {
  2150. this.x = Math.floor( this.x );
  2151. this.y = Math.floor( this.y );
  2152. this.z = Math.floor( this.z );
  2153. this.w = Math.floor( this.w );
  2154. return this;
  2155. },
  2156. ceil: function () {
  2157. this.x = Math.ceil( this.x );
  2158. this.y = Math.ceil( this.y );
  2159. this.z = Math.ceil( this.z );
  2160. this.w = Math.ceil( this.w );
  2161. return this;
  2162. },
  2163. round: function () {
  2164. this.x = Math.round( this.x );
  2165. this.y = Math.round( this.y );
  2166. this.z = Math.round( this.z );
  2167. this.w = Math.round( this.w );
  2168. return this;
  2169. },
  2170. roundToZero: function () {
  2171. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2172. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2173. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2174. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  2175. return this;
  2176. },
  2177. negate: function () {
  2178. this.x = - this.x;
  2179. this.y = - this.y;
  2180. this.z = - this.z;
  2181. this.w = - this.w;
  2182. return this;
  2183. },
  2184. dot: function ( v ) {
  2185. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2186. },
  2187. lengthSq: function () {
  2188. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2189. },
  2190. length: function () {
  2191. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2192. },
  2193. manhattanLength: function () {
  2194. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  2195. },
  2196. normalize: function () {
  2197. return this.divideScalar( this.length() || 1 );
  2198. },
  2199. setLength: function ( length ) {
  2200. return this.normalize().multiplyScalar( length );
  2201. },
  2202. lerp: function ( v, alpha ) {
  2203. this.x += ( v.x - this.x ) * alpha;
  2204. this.y += ( v.y - this.y ) * alpha;
  2205. this.z += ( v.z - this.z ) * alpha;
  2206. this.w += ( v.w - this.w ) * alpha;
  2207. return this;
  2208. },
  2209. lerpVectors: function ( v1, v2, alpha ) {
  2210. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  2211. },
  2212. equals: function ( v ) {
  2213. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  2214. },
  2215. fromArray: function ( array, offset ) {
  2216. if ( offset === undefined ) offset = 0;
  2217. this.x = array[ offset ];
  2218. this.y = array[ offset + 1 ];
  2219. this.z = array[ offset + 2 ];
  2220. this.w = array[ offset + 3 ];
  2221. return this;
  2222. },
  2223. toArray: function ( array, offset ) {
  2224. if ( array === undefined ) array = [];
  2225. if ( offset === undefined ) offset = 0;
  2226. array[ offset ] = this.x;
  2227. array[ offset + 1 ] = this.y;
  2228. array[ offset + 2 ] = this.z;
  2229. array[ offset + 3 ] = this.w;
  2230. return array;
  2231. },
  2232. fromBufferAttribute: function ( attribute, index, offset ) {
  2233. if ( offset !== undefined ) {
  2234. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  2235. }
  2236. this.x = attribute.getX( index );
  2237. this.y = attribute.getY( index );
  2238. this.z = attribute.getZ( index );
  2239. this.w = attribute.getW( index );
  2240. return this;
  2241. }
  2242. } );
  2243. /**
  2244. * @author szimek / https://github.com/szimek/
  2245. * @author alteredq / http://alteredqualia.com/
  2246. * @author Marius Kintel / https://github.com/kintel
  2247. */
  2248. /*
  2249. In options, we can specify:
  2250. * Texture parameters for an auto-generated target texture
  2251. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2252. */
  2253. function WebGLRenderTarget( width, height, options ) {
  2254. this.width = width;
  2255. this.height = height;
  2256. this.scissor = new Vector4( 0, 0, width, height );
  2257. this.scissorTest = false;
  2258. this.viewport = new Vector4( 0, 0, width, height );
  2259. options = options || {};
  2260. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  2261. this.texture.image = {};
  2262. this.texture.image.width = width;
  2263. this.texture.image.height = height;
  2264. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2265. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2266. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2267. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  2268. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2269. }
  2270. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2271. constructor: WebGLRenderTarget,
  2272. isWebGLRenderTarget: true,
  2273. setSize: function ( width, height ) {
  2274. if ( this.width !== width || this.height !== height ) {
  2275. this.width = width;
  2276. this.height = height;
  2277. this.texture.image.width = width;
  2278. this.texture.image.height = height;
  2279. this.dispose();
  2280. }
  2281. this.viewport.set( 0, 0, width, height );
  2282. this.scissor.set( 0, 0, width, height );
  2283. },
  2284. clone: function () {
  2285. return new this.constructor().copy( this );
  2286. },
  2287. copy: function ( source ) {
  2288. this.width = source.width;
  2289. this.height = source.height;
  2290. this.viewport.copy( source.viewport );
  2291. this.texture = source.texture.clone();
  2292. this.depthBuffer = source.depthBuffer;
  2293. this.stencilBuffer = source.stencilBuffer;
  2294. this.depthTexture = source.depthTexture;
  2295. return this;
  2296. },
  2297. dispose: function () {
  2298. this.dispatchEvent( { type: 'dispose' } );
  2299. }
  2300. } );
  2301. /**
  2302. * @author Mugen87 / https://github.com/Mugen87
  2303. * @author Matt DesLauriers / @mattdesl
  2304. */
  2305. function WebGLMultisampleRenderTarget( width, height, options ) {
  2306. WebGLRenderTarget.call( this, width, height, options );
  2307. this.samples = 4;
  2308. }
  2309. WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), {
  2310. constructor: WebGLMultisampleRenderTarget,
  2311. isWebGLMultisampleRenderTarget: true,
  2312. copy: function ( source ) {
  2313. WebGLRenderTarget.prototype.copy.call( this, source );
  2314. this.samples = source.samples;
  2315. return this;
  2316. }
  2317. } );
  2318. /**
  2319. * @author mrdoob / http://mrdoob.com/
  2320. * @author supereggbert / http://www.paulbrunt.co.uk/
  2321. * @author philogb / http://blog.thejit.org/
  2322. * @author jordi_ros / http://plattsoft.com
  2323. * @author D1plo1d / http://github.com/D1plo1d
  2324. * @author alteredq / http://alteredqualia.com/
  2325. * @author mikael emtinger / http://gomo.se/
  2326. * @author timknip / http://www.floorplanner.com/
  2327. * @author bhouston / http://clara.io
  2328. * @author WestLangley / http://github.com/WestLangley
  2329. */
  2330. function Matrix4() {
  2331. this.elements = [
  2332. 1, 0, 0, 0,
  2333. 0, 1, 0, 0,
  2334. 0, 0, 1, 0,
  2335. 0, 0, 0, 1
  2336. ];
  2337. if ( arguments.length > 0 ) {
  2338. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2339. }
  2340. }
  2341. Object.assign( Matrix4.prototype, {
  2342. isMatrix4: true,
  2343. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2344. var te = this.elements;
  2345. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2346. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2347. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2348. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2349. return this;
  2350. },
  2351. identity: function () {
  2352. this.set(
  2353. 1, 0, 0, 0,
  2354. 0, 1, 0, 0,
  2355. 0, 0, 1, 0,
  2356. 0, 0, 0, 1
  2357. );
  2358. return this;
  2359. },
  2360. clone: function () {
  2361. return new Matrix4().fromArray( this.elements );
  2362. },
  2363. copy: function ( m ) {
  2364. var te = this.elements;
  2365. var me = m.elements;
  2366. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  2367. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  2368. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  2369. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  2370. return this;
  2371. },
  2372. copyPosition: function ( m ) {
  2373. var te = this.elements, me = m.elements;
  2374. te[ 12 ] = me[ 12 ];
  2375. te[ 13 ] = me[ 13 ];
  2376. te[ 14 ] = me[ 14 ];
  2377. return this;
  2378. },
  2379. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2380. xAxis.setFromMatrixColumn( this, 0 );
  2381. yAxis.setFromMatrixColumn( this, 1 );
  2382. zAxis.setFromMatrixColumn( this, 2 );
  2383. return this;
  2384. },
  2385. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2386. this.set(
  2387. xAxis.x, yAxis.x, zAxis.x, 0,
  2388. xAxis.y, yAxis.y, zAxis.y, 0,
  2389. xAxis.z, yAxis.z, zAxis.z, 0,
  2390. 0, 0, 0, 1
  2391. );
  2392. return this;
  2393. },
  2394. extractRotation: function () {
  2395. var v1 = new Vector3();
  2396. return function extractRotation( m ) {
  2397. // this method does not support reflection matrices
  2398. var te = this.elements;
  2399. var me = m.elements;
  2400. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  2401. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  2402. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  2403. te[ 0 ] = me[ 0 ] * scaleX;
  2404. te[ 1 ] = me[ 1 ] * scaleX;
  2405. te[ 2 ] = me[ 2 ] * scaleX;
  2406. te[ 3 ] = 0;
  2407. te[ 4 ] = me[ 4 ] * scaleY;
  2408. te[ 5 ] = me[ 5 ] * scaleY;
  2409. te[ 6 ] = me[ 6 ] * scaleY;
  2410. te[ 7 ] = 0;
  2411. te[ 8 ] = me[ 8 ] * scaleZ;
  2412. te[ 9 ] = me[ 9 ] * scaleZ;
  2413. te[ 10 ] = me[ 10 ] * scaleZ;
  2414. te[ 11 ] = 0;
  2415. te[ 12 ] = 0;
  2416. te[ 13 ] = 0;
  2417. te[ 14 ] = 0;
  2418. te[ 15 ] = 1;
  2419. return this;
  2420. };
  2421. }(),
  2422. makeRotationFromEuler: function ( euler ) {
  2423. if ( ! ( euler && euler.isEuler ) ) {
  2424. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2425. }
  2426. var te = this.elements;
  2427. var x = euler.x, y = euler.y, z = euler.z;
  2428. var a = Math.cos( x ), b = Math.sin( x );
  2429. var c = Math.cos( y ), d = Math.sin( y );
  2430. var e = Math.cos( z ), f = Math.sin( z );
  2431. if ( euler.order === 'XYZ' ) {
  2432. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2433. te[ 0 ] = c * e;
  2434. te[ 4 ] = - c * f;
  2435. te[ 8 ] = d;
  2436. te[ 1 ] = af + be * d;
  2437. te[ 5 ] = ae - bf * d;
  2438. te[ 9 ] = - b * c;
  2439. te[ 2 ] = bf - ae * d;
  2440. te[ 6 ] = be + af * d;
  2441. te[ 10 ] = a * c;
  2442. } else if ( euler.order === 'YXZ' ) {
  2443. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2444. te[ 0 ] = ce + df * b;
  2445. te[ 4 ] = de * b - cf;
  2446. te[ 8 ] = a * d;
  2447. te[ 1 ] = a * f;
  2448. te[ 5 ] = a * e;
  2449. te[ 9 ] = - b;
  2450. te[ 2 ] = cf * b - de;
  2451. te[ 6 ] = df + ce * b;
  2452. te[ 10 ] = a * c;
  2453. } else if ( euler.order === 'ZXY' ) {
  2454. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2455. te[ 0 ] = ce - df * b;
  2456. te[ 4 ] = - a * f;
  2457. te[ 8 ] = de + cf * b;
  2458. te[ 1 ] = cf + de * b;
  2459. te[ 5 ] = a * e;
  2460. te[ 9 ] = df - ce * b;
  2461. te[ 2 ] = - a * d;
  2462. te[ 6 ] = b;
  2463. te[ 10 ] = a * c;
  2464. } else if ( euler.order === 'ZYX' ) {
  2465. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2466. te[ 0 ] = c * e;
  2467. te[ 4 ] = be * d - af;
  2468. te[ 8 ] = ae * d + bf;
  2469. te[ 1 ] = c * f;
  2470. te[ 5 ] = bf * d + ae;
  2471. te[ 9 ] = af * d - be;
  2472. te[ 2 ] = - d;
  2473. te[ 6 ] = b * c;
  2474. te[ 10 ] = a * c;
  2475. } else if ( euler.order === 'YZX' ) {
  2476. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2477. te[ 0 ] = c * e;
  2478. te[ 4 ] = bd - ac * f;
  2479. te[ 8 ] = bc * f + ad;
  2480. te[ 1 ] = f;
  2481. te[ 5 ] = a * e;
  2482. te[ 9 ] = - b * e;
  2483. te[ 2 ] = - d * e;
  2484. te[ 6 ] = ad * f + bc;
  2485. te[ 10 ] = ac - bd * f;
  2486. } else if ( euler.order === 'XZY' ) {
  2487. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2488. te[ 0 ] = c * e;
  2489. te[ 4 ] = - f;
  2490. te[ 8 ] = d * e;
  2491. te[ 1 ] = ac * f + bd;
  2492. te[ 5 ] = a * e;
  2493. te[ 9 ] = ad * f - bc;
  2494. te[ 2 ] = bc * f - ad;
  2495. te[ 6 ] = b * e;
  2496. te[ 10 ] = bd * f + ac;
  2497. }
  2498. // bottom row
  2499. te[ 3 ] = 0;
  2500. te[ 7 ] = 0;
  2501. te[ 11 ] = 0;
  2502. // last column
  2503. te[ 12 ] = 0;
  2504. te[ 13 ] = 0;
  2505. te[ 14 ] = 0;
  2506. te[ 15 ] = 1;
  2507. return this;
  2508. },
  2509. makeRotationFromQuaternion: function () {
  2510. var zero = new Vector3( 0, 0, 0 );
  2511. var one = new Vector3( 1, 1, 1 );
  2512. return function makeRotationFromQuaternion( q ) {
  2513. return this.compose( zero, q, one );
  2514. };
  2515. }(),
  2516. lookAt: function () {
  2517. var x = new Vector3();
  2518. var y = new Vector3();
  2519. var z = new Vector3();
  2520. return function lookAt( eye, target, up ) {
  2521. var te = this.elements;
  2522. z.subVectors( eye, target );
  2523. if ( z.lengthSq() === 0 ) {
  2524. // eye and target are in the same position
  2525. z.z = 1;
  2526. }
  2527. z.normalize();
  2528. x.crossVectors( up, z );
  2529. if ( x.lengthSq() === 0 ) {
  2530. // up and z are parallel
  2531. if ( Math.abs( up.z ) === 1 ) {
  2532. z.x += 0.0001;
  2533. } else {
  2534. z.z += 0.0001;
  2535. }
  2536. z.normalize();
  2537. x.crossVectors( up, z );
  2538. }
  2539. x.normalize();
  2540. y.crossVectors( z, x );
  2541. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2542. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2543. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2544. return this;
  2545. };
  2546. }(),
  2547. multiply: function ( m, n ) {
  2548. if ( n !== undefined ) {
  2549. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2550. return this.multiplyMatrices( m, n );
  2551. }
  2552. return this.multiplyMatrices( this, m );
  2553. },
  2554. premultiply: function ( m ) {
  2555. return this.multiplyMatrices( m, this );
  2556. },
  2557. multiplyMatrices: function ( a, b ) {
  2558. var ae = a.elements;
  2559. var be = b.elements;
  2560. var te = this.elements;
  2561. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2562. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2563. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2564. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  2565. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  2566. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  2567. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  2568. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  2569. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  2570. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  2571. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  2572. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  2573. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  2574. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  2575. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  2576. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  2577. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  2578. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  2579. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  2580. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  2581. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  2582. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  2583. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  2584. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  2585. return this;
  2586. },
  2587. multiplyScalar: function ( s ) {
  2588. var te = this.elements;
  2589. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  2590. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  2591. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  2592. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  2593. return this;
  2594. },
  2595. applyToBufferAttribute: function () {
  2596. var v1 = new Vector3();
  2597. return function applyToBufferAttribute( attribute ) {
  2598. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2599. v1.x = attribute.getX( i );
  2600. v1.y = attribute.getY( i );
  2601. v1.z = attribute.getZ( i );
  2602. v1.applyMatrix4( this );
  2603. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  2604. }
  2605. return attribute;
  2606. };
  2607. }(),
  2608. determinant: function () {
  2609. var te = this.elements;
  2610. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  2611. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  2612. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  2613. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  2614. //TODO: make this more efficient
  2615. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  2616. return (
  2617. n41 * (
  2618. + n14 * n23 * n32
  2619. - n13 * n24 * n32
  2620. - n14 * n22 * n33
  2621. + n12 * n24 * n33
  2622. + n13 * n22 * n34
  2623. - n12 * n23 * n34
  2624. ) +
  2625. n42 * (
  2626. + n11 * n23 * n34
  2627. - n11 * n24 * n33
  2628. + n14 * n21 * n33
  2629. - n13 * n21 * n34
  2630. + n13 * n24 * n31
  2631. - n14 * n23 * n31
  2632. ) +
  2633. n43 * (
  2634. + n11 * n24 * n32
  2635. - n11 * n22 * n34
  2636. - n14 * n21 * n32
  2637. + n12 * n21 * n34
  2638. + n14 * n22 * n31
  2639. - n12 * n24 * n31
  2640. ) +
  2641. n44 * (
  2642. - n13 * n22 * n31
  2643. - n11 * n23 * n32
  2644. + n11 * n22 * n33
  2645. + n13 * n21 * n32
  2646. - n12 * n21 * n33
  2647. + n12 * n23 * n31
  2648. )
  2649. );
  2650. },
  2651. transpose: function () {
  2652. var te = this.elements;
  2653. var tmp;
  2654. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  2655. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  2656. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  2657. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  2658. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  2659. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  2660. return this;
  2661. },
  2662. setPosition: function ( x, y, z ) {
  2663. var te = this.elements;
  2664. if ( x.isVector3 ) {
  2665. te[ 12 ] = x.x;
  2666. te[ 13 ] = x.y;
  2667. te[ 14 ] = x.z;
  2668. } else {
  2669. te[ 12 ] = x;
  2670. te[ 13 ] = y;
  2671. te[ 14 ] = z;
  2672. }
  2673. return this;
  2674. },
  2675. getInverse: function ( m, throwOnDegenerate ) {
  2676. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  2677. var te = this.elements,
  2678. me = m.elements,
  2679. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  2680. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  2681. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  2682. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  2683. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  2684. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  2685. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  2686. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  2687. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  2688. if ( det === 0 ) {
  2689. var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
  2690. if ( throwOnDegenerate === true ) {
  2691. throw new Error( msg );
  2692. } else {
  2693. console.warn( msg );
  2694. }
  2695. return this.identity();
  2696. }
  2697. var detInv = 1 / det;
  2698. te[ 0 ] = t11 * detInv;
  2699. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  2700. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  2701. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  2702. te[ 4 ] = t12 * detInv;
  2703. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  2704. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  2705. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  2706. te[ 8 ] = t13 * detInv;
  2707. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  2708. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  2709. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  2710. te[ 12 ] = t14 * detInv;
  2711. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  2712. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  2713. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  2714. return this;
  2715. },
  2716. scale: function ( v ) {
  2717. var te = this.elements;
  2718. var x = v.x, y = v.y, z = v.z;
  2719. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  2720. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  2721. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  2722. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  2723. return this;
  2724. },
  2725. getMaxScaleOnAxis: function () {
  2726. var te = this.elements;
  2727. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  2728. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  2729. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  2730. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  2731. },
  2732. makeTranslation: function ( x, y, z ) {
  2733. this.set(
  2734. 1, 0, 0, x,
  2735. 0, 1, 0, y,
  2736. 0, 0, 1, z,
  2737. 0, 0, 0, 1
  2738. );
  2739. return this;
  2740. },
  2741. makeRotationX: function ( theta ) {
  2742. var c = Math.cos( theta ), s = Math.sin( theta );
  2743. this.set(
  2744. 1, 0, 0, 0,
  2745. 0, c, - s, 0,
  2746. 0, s, c, 0,
  2747. 0, 0, 0, 1
  2748. );
  2749. return this;
  2750. },
  2751. makeRotationY: function ( theta ) {
  2752. var c = Math.cos( theta ), s = Math.sin( theta );
  2753. this.set(
  2754. c, 0, s, 0,
  2755. 0, 1, 0, 0,
  2756. - s, 0, c, 0,
  2757. 0, 0, 0, 1
  2758. );
  2759. return this;
  2760. },
  2761. makeRotationZ: function ( theta ) {
  2762. var c = Math.cos( theta ), s = Math.sin( theta );
  2763. this.set(
  2764. c, - s, 0, 0,
  2765. s, c, 0, 0,
  2766. 0, 0, 1, 0,
  2767. 0, 0, 0, 1
  2768. );
  2769. return this;
  2770. },
  2771. makeRotationAxis: function ( axis, angle ) {
  2772. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  2773. var c = Math.cos( angle );
  2774. var s = Math.sin( angle );
  2775. var t = 1 - c;
  2776. var x = axis.x, y = axis.y, z = axis.z;
  2777. var tx = t * x, ty = t * y;
  2778. this.set(
  2779. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  2780. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  2781. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  2782. 0, 0, 0, 1
  2783. );
  2784. return this;
  2785. },
  2786. makeScale: function ( x, y, z ) {
  2787. this.set(
  2788. x, 0, 0, 0,
  2789. 0, y, 0, 0,
  2790. 0, 0, z, 0,
  2791. 0, 0, 0, 1
  2792. );
  2793. return this;
  2794. },
  2795. makeShear: function ( x, y, z ) {
  2796. this.set(
  2797. 1, y, z, 0,
  2798. x, 1, z, 0,
  2799. x, y, 1, 0,
  2800. 0, 0, 0, 1
  2801. );
  2802. return this;
  2803. },
  2804. compose: function ( position, quaternion, scale ) {
  2805. var te = this.elements;
  2806. var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  2807. var x2 = x + x, y2 = y + y, z2 = z + z;
  2808. var xx = x * x2, xy = x * y2, xz = x * z2;
  2809. var yy = y * y2, yz = y * z2, zz = z * z2;
  2810. var wx = w * x2, wy = w * y2, wz = w * z2;
  2811. var sx = scale.x, sy = scale.y, sz = scale.z;
  2812. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  2813. te[ 1 ] = ( xy + wz ) * sx;
  2814. te[ 2 ] = ( xz - wy ) * sx;
  2815. te[ 3 ] = 0;
  2816. te[ 4 ] = ( xy - wz ) * sy;
  2817. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  2818. te[ 6 ] = ( yz + wx ) * sy;
  2819. te[ 7 ] = 0;
  2820. te[ 8 ] = ( xz + wy ) * sz;
  2821. te[ 9 ] = ( yz - wx ) * sz;
  2822. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  2823. te[ 11 ] = 0;
  2824. te[ 12 ] = position.x;
  2825. te[ 13 ] = position.y;
  2826. te[ 14 ] = position.z;
  2827. te[ 15 ] = 1;
  2828. return this;
  2829. },
  2830. decompose: function () {
  2831. var vector = new Vector3();
  2832. var matrix = new Matrix4();
  2833. return function decompose( position, quaternion, scale ) {
  2834. var te = this.elements;
  2835. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  2836. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  2837. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  2838. // if determine is negative, we need to invert one scale
  2839. var det = this.determinant();
  2840. if ( det < 0 ) sx = - sx;
  2841. position.x = te[ 12 ];
  2842. position.y = te[ 13 ];
  2843. position.z = te[ 14 ];
  2844. // scale the rotation part
  2845. matrix.copy( this );
  2846. var invSX = 1 / sx;
  2847. var invSY = 1 / sy;
  2848. var invSZ = 1 / sz;
  2849. matrix.elements[ 0 ] *= invSX;
  2850. matrix.elements[ 1 ] *= invSX;
  2851. matrix.elements[ 2 ] *= invSX;
  2852. matrix.elements[ 4 ] *= invSY;
  2853. matrix.elements[ 5 ] *= invSY;
  2854. matrix.elements[ 6 ] *= invSY;
  2855. matrix.elements[ 8 ] *= invSZ;
  2856. matrix.elements[ 9 ] *= invSZ;
  2857. matrix.elements[ 10 ] *= invSZ;
  2858. quaternion.setFromRotationMatrix( matrix );
  2859. scale.x = sx;
  2860. scale.y = sy;
  2861. scale.z = sz;
  2862. return this;
  2863. };
  2864. }(),
  2865. makePerspective: function ( left, right, top, bottom, near, far ) {
  2866. if ( far === undefined ) {
  2867. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  2868. }
  2869. var te = this.elements;
  2870. var x = 2 * near / ( right - left );
  2871. var y = 2 * near / ( top - bottom );
  2872. var a = ( right + left ) / ( right - left );
  2873. var b = ( top + bottom ) / ( top - bottom );
  2874. var c = - ( far + near ) / ( far - near );
  2875. var d = - 2 * far * near / ( far - near );
  2876. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  2877. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  2878. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  2879. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  2880. return this;
  2881. },
  2882. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  2883. var te = this.elements;
  2884. var w = 1.0 / ( right - left );
  2885. var h = 1.0 / ( top - bottom );
  2886. var p = 1.0 / ( far - near );
  2887. var x = ( right + left ) * w;
  2888. var y = ( top + bottom ) * h;
  2889. var z = ( far + near ) * p;
  2890. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  2891. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  2892. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  2893. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  2894. return this;
  2895. },
  2896. equals: function ( matrix ) {
  2897. var te = this.elements;
  2898. var me = matrix.elements;
  2899. for ( var i = 0; i < 16; i ++ ) {
  2900. if ( te[ i ] !== me[ i ] ) return false;
  2901. }
  2902. return true;
  2903. },
  2904. fromArray: function ( array, offset ) {
  2905. if ( offset === undefined ) offset = 0;
  2906. for ( var i = 0; i < 16; i ++ ) {
  2907. this.elements[ i ] = array[ i + offset ];
  2908. }
  2909. return this;
  2910. },
  2911. toArray: function ( array, offset ) {
  2912. if ( array === undefined ) array = [];
  2913. if ( offset === undefined ) offset = 0;
  2914. var te = this.elements;
  2915. array[ offset ] = te[ 0 ];
  2916. array[ offset + 1 ] = te[ 1 ];
  2917. array[ offset + 2 ] = te[ 2 ];
  2918. array[ offset + 3 ] = te[ 3 ];
  2919. array[ offset + 4 ] = te[ 4 ];
  2920. array[ offset + 5 ] = te[ 5 ];
  2921. array[ offset + 6 ] = te[ 6 ];
  2922. array[ offset + 7 ] = te[ 7 ];
  2923. array[ offset + 8 ] = te[ 8 ];
  2924. array[ offset + 9 ] = te[ 9 ];
  2925. array[ offset + 10 ] = te[ 10 ];
  2926. array[ offset + 11 ] = te[ 11 ];
  2927. array[ offset + 12 ] = te[ 12 ];
  2928. array[ offset + 13 ] = te[ 13 ];
  2929. array[ offset + 14 ] = te[ 14 ];
  2930. array[ offset + 15 ] = te[ 15 ];
  2931. return array;
  2932. }
  2933. } );
  2934. /**
  2935. * @author mrdoob / http://mrdoob.com/
  2936. * @author WestLangley / http://github.com/WestLangley
  2937. * @author bhouston / http://clara.io
  2938. */
  2939. function Euler( x, y, z, order ) {
  2940. this._x = x || 0;
  2941. this._y = y || 0;
  2942. this._z = z || 0;
  2943. this._order = order || Euler.DefaultOrder;
  2944. }
  2945. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  2946. Euler.DefaultOrder = 'XYZ';
  2947. Object.defineProperties( Euler.prototype, {
  2948. x: {
  2949. get: function () {
  2950. return this._x;
  2951. },
  2952. set: function ( value ) {
  2953. this._x = value;
  2954. this._onChangeCallback();
  2955. }
  2956. },
  2957. y: {
  2958. get: function () {
  2959. return this._y;
  2960. },
  2961. set: function ( value ) {
  2962. this._y = value;
  2963. this._onChangeCallback();
  2964. }
  2965. },
  2966. z: {
  2967. get: function () {
  2968. return this._z;
  2969. },
  2970. set: function ( value ) {
  2971. this._z = value;
  2972. this._onChangeCallback();
  2973. }
  2974. },
  2975. order: {
  2976. get: function () {
  2977. return this._order;
  2978. },
  2979. set: function ( value ) {
  2980. this._order = value;
  2981. this._onChangeCallback();
  2982. }
  2983. }
  2984. } );
  2985. Object.assign( Euler.prototype, {
  2986. isEuler: true,
  2987. set: function ( x, y, z, order ) {
  2988. this._x = x;
  2989. this._y = y;
  2990. this._z = z;
  2991. this._order = order || this._order;
  2992. this._onChangeCallback();
  2993. return this;
  2994. },
  2995. clone: function () {
  2996. return new this.constructor( this._x, this._y, this._z, this._order );
  2997. },
  2998. copy: function ( euler ) {
  2999. this._x = euler._x;
  3000. this._y = euler._y;
  3001. this._z = euler._z;
  3002. this._order = euler._order;
  3003. this._onChangeCallback();
  3004. return this;
  3005. },
  3006. setFromRotationMatrix: function ( m, order, update ) {
  3007. var clamp = _Math.clamp;
  3008. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3009. var te = m.elements;
  3010. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  3011. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  3012. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  3013. order = order || this._order;
  3014. if ( order === 'XYZ' ) {
  3015. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  3016. if ( Math.abs( m13 ) < 0.99999 ) {
  3017. this._x = Math.atan2( - m23, m33 );
  3018. this._z = Math.atan2( - m12, m11 );
  3019. } else {
  3020. this._x = Math.atan2( m32, m22 );
  3021. this._z = 0;
  3022. }
  3023. } else if ( order === 'YXZ' ) {
  3024. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  3025. if ( Math.abs( m23 ) < 0.99999 ) {
  3026. this._y = Math.atan2( m13, m33 );
  3027. this._z = Math.atan2( m21, m22 );
  3028. } else {
  3029. this._y = Math.atan2( - m31, m11 );
  3030. this._z = 0;
  3031. }
  3032. } else if ( order === 'ZXY' ) {
  3033. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  3034. if ( Math.abs( m32 ) < 0.99999 ) {
  3035. this._y = Math.atan2( - m31, m33 );
  3036. this._z = Math.atan2( - m12, m22 );
  3037. } else {
  3038. this._y = 0;
  3039. this._z = Math.atan2( m21, m11 );
  3040. }
  3041. } else if ( order === 'ZYX' ) {
  3042. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  3043. if ( Math.abs( m31 ) < 0.99999 ) {
  3044. this._x = Math.atan2( m32, m33 );
  3045. this._z = Math.atan2( m21, m11 );
  3046. } else {
  3047. this._x = 0;
  3048. this._z = Math.atan2( - m12, m22 );
  3049. }
  3050. } else if ( order === 'YZX' ) {
  3051. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  3052. if ( Math.abs( m21 ) < 0.99999 ) {
  3053. this._x = Math.atan2( - m23, m22 );
  3054. this._y = Math.atan2( - m31, m11 );
  3055. } else {
  3056. this._x = 0;
  3057. this._y = Math.atan2( m13, m33 );
  3058. }
  3059. } else if ( order === 'XZY' ) {
  3060. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  3061. if ( Math.abs( m12 ) < 0.99999 ) {
  3062. this._x = Math.atan2( m32, m22 );
  3063. this._y = Math.atan2( m13, m11 );
  3064. } else {
  3065. this._x = Math.atan2( - m23, m33 );
  3066. this._y = 0;
  3067. }
  3068. } else {
  3069. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  3070. }
  3071. this._order = order;
  3072. if ( update !== false ) this._onChangeCallback();
  3073. return this;
  3074. },
  3075. setFromQuaternion: function () {
  3076. var matrix = new Matrix4();
  3077. return function setFromQuaternion( q, order, update ) {
  3078. matrix.makeRotationFromQuaternion( q );
  3079. return this.setFromRotationMatrix( matrix, order, update );
  3080. };
  3081. }(),
  3082. setFromVector3: function ( v, order ) {
  3083. return this.set( v.x, v.y, v.z, order || this._order );
  3084. },
  3085. reorder: function () {
  3086. // WARNING: this discards revolution information -bhouston
  3087. var q = new Quaternion();
  3088. return function reorder( newOrder ) {
  3089. q.setFromEuler( this );
  3090. return this.setFromQuaternion( q, newOrder );
  3091. };
  3092. }(),
  3093. equals: function ( euler ) {
  3094. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  3095. },
  3096. fromArray: function ( array ) {
  3097. this._x = array[ 0 ];
  3098. this._y = array[ 1 ];
  3099. this._z = array[ 2 ];
  3100. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  3101. this._onChangeCallback();
  3102. return this;
  3103. },
  3104. toArray: function ( array, offset ) {
  3105. if ( array === undefined ) array = [];
  3106. if ( offset === undefined ) offset = 0;
  3107. array[ offset ] = this._x;
  3108. array[ offset + 1 ] = this._y;
  3109. array[ offset + 2 ] = this._z;
  3110. array[ offset + 3 ] = this._order;
  3111. return array;
  3112. },
  3113. toVector3: function ( optionalResult ) {
  3114. if ( optionalResult ) {
  3115. return optionalResult.set( this._x, this._y, this._z );
  3116. } else {
  3117. return new Vector3( this._x, this._y, this._z );
  3118. }
  3119. },
  3120. _onChange: function ( callback ) {
  3121. this._onChangeCallback = callback;
  3122. return this;
  3123. },
  3124. _onChangeCallback: function () {}
  3125. } );
  3126. /**
  3127. * @author mrdoob / http://mrdoob.com/
  3128. */
  3129. function Layers() {
  3130. this.mask = 1 | 0;
  3131. }
  3132. Object.assign( Layers.prototype, {
  3133. set: function ( channel ) {
  3134. this.mask = 1 << channel | 0;
  3135. },
  3136. enable: function ( channel ) {
  3137. this.mask |= 1 << channel | 0;
  3138. },
  3139. toggle: function ( channel ) {
  3140. this.mask ^= 1 << channel | 0;
  3141. },
  3142. disable: function ( channel ) {
  3143. this.mask &= ~ ( 1 << channel | 0 );
  3144. },
  3145. test: function ( layers ) {
  3146. return ( this.mask & layers.mask ) !== 0;
  3147. }
  3148. } );
  3149. /**
  3150. * @author mrdoob / http://mrdoob.com/
  3151. * @author mikael emtinger / http://gomo.se/
  3152. * @author alteredq / http://alteredqualia.com/
  3153. * @author WestLangley / http://github.com/WestLangley
  3154. * @author elephantatwork / www.elephantatwork.ch
  3155. */
  3156. var object3DId = 0;
  3157. function Object3D() {
  3158. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  3159. this.uuid = _Math.generateUUID();
  3160. this.name = '';
  3161. this.type = 'Object3D';
  3162. this.parent = null;
  3163. this.children = [];
  3164. this.up = Object3D.DefaultUp.clone();
  3165. var position = new Vector3();
  3166. var rotation = new Euler();
  3167. var quaternion = new Quaternion();
  3168. var scale = new Vector3( 1, 1, 1 );
  3169. function onRotationChange() {
  3170. quaternion.setFromEuler( rotation, false );
  3171. }
  3172. function onQuaternionChange() {
  3173. rotation.setFromQuaternion( quaternion, undefined, false );
  3174. }
  3175. rotation._onChange( onRotationChange );
  3176. quaternion._onChange( onQuaternionChange );
  3177. Object.defineProperties( this, {
  3178. position: {
  3179. configurable: true,
  3180. enumerable: true,
  3181. value: position
  3182. },
  3183. rotation: {
  3184. configurable: true,
  3185. enumerable: true,
  3186. value: rotation
  3187. },
  3188. quaternion: {
  3189. configurable: true,
  3190. enumerable: true,
  3191. value: quaternion
  3192. },
  3193. scale: {
  3194. configurable: true,
  3195. enumerable: true,
  3196. value: scale
  3197. },
  3198. modelViewMatrix: {
  3199. value: new Matrix4()
  3200. },
  3201. normalMatrix: {
  3202. value: new Matrix3()
  3203. }
  3204. } );
  3205. this.matrix = new Matrix4();
  3206. this.matrixWorld = new Matrix4();
  3207. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  3208. this.matrixWorldNeedsUpdate = false;
  3209. this.layers = new Layers();
  3210. this.visible = true;
  3211. this.castShadow = false;
  3212. this.receiveShadow = false;
  3213. this.frustumCulled = true;
  3214. this.renderOrder = 0;
  3215. this.userData = {};
  3216. }
  3217. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  3218. Object3D.DefaultMatrixAutoUpdate = true;
  3219. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  3220. constructor: Object3D,
  3221. isObject3D: true,
  3222. onBeforeRender: function () {},
  3223. onAfterRender: function () {},
  3224. applyMatrix: function ( matrix ) {
  3225. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3226. this.matrix.premultiply( matrix );
  3227. this.matrix.decompose( this.position, this.quaternion, this.scale );
  3228. },
  3229. applyQuaternion: function ( q ) {
  3230. this.quaternion.premultiply( q );
  3231. return this;
  3232. },
  3233. setRotationFromAxisAngle: function ( axis, angle ) {
  3234. // assumes axis is normalized
  3235. this.quaternion.setFromAxisAngle( axis, angle );
  3236. },
  3237. setRotationFromEuler: function ( euler ) {
  3238. this.quaternion.setFromEuler( euler, true );
  3239. },
  3240. setRotationFromMatrix: function ( m ) {
  3241. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3242. this.quaternion.setFromRotationMatrix( m );
  3243. },
  3244. setRotationFromQuaternion: function ( q ) {
  3245. // assumes q is normalized
  3246. this.quaternion.copy( q );
  3247. },
  3248. rotateOnAxis: function () {
  3249. // rotate object on axis in object space
  3250. // axis is assumed to be normalized
  3251. var q1 = new Quaternion();
  3252. return function rotateOnAxis( axis, angle ) {
  3253. q1.setFromAxisAngle( axis, angle );
  3254. this.quaternion.multiply( q1 );
  3255. return this;
  3256. };
  3257. }(),
  3258. rotateOnWorldAxis: function () {
  3259. // rotate object on axis in world space
  3260. // axis is assumed to be normalized
  3261. // method assumes no rotated parent
  3262. var q1 = new Quaternion();
  3263. return function rotateOnWorldAxis( axis, angle ) {
  3264. q1.setFromAxisAngle( axis, angle );
  3265. this.quaternion.premultiply( q1 );
  3266. return this;
  3267. };
  3268. }(),
  3269. rotateX: function () {
  3270. var v1 = new Vector3( 1, 0, 0 );
  3271. return function rotateX( angle ) {
  3272. return this.rotateOnAxis( v1, angle );
  3273. };
  3274. }(),
  3275. rotateY: function () {
  3276. var v1 = new Vector3( 0, 1, 0 );
  3277. return function rotateY( angle ) {
  3278. return this.rotateOnAxis( v1, angle );
  3279. };
  3280. }(),
  3281. rotateZ: function () {
  3282. var v1 = new Vector3( 0, 0, 1 );
  3283. return function rotateZ( angle ) {
  3284. return this.rotateOnAxis( v1, angle );
  3285. };
  3286. }(),
  3287. translateOnAxis: function () {
  3288. // translate object by distance along axis in object space
  3289. // axis is assumed to be normalized
  3290. var v1 = new Vector3();
  3291. return function translateOnAxis( axis, distance ) {
  3292. v1.copy( axis ).applyQuaternion( this.quaternion );
  3293. this.position.add( v1.multiplyScalar( distance ) );
  3294. return this;
  3295. };
  3296. }(),
  3297. translateX: function () {
  3298. var v1 = new Vector3( 1, 0, 0 );
  3299. return function translateX( distance ) {
  3300. return this.translateOnAxis( v1, distance );
  3301. };
  3302. }(),
  3303. translateY: function () {
  3304. var v1 = new Vector3( 0, 1, 0 );
  3305. return function translateY( distance ) {
  3306. return this.translateOnAxis( v1, distance );
  3307. };
  3308. }(),
  3309. translateZ: function () {
  3310. var v1 = new Vector3( 0, 0, 1 );
  3311. return function translateZ( distance ) {
  3312. return this.translateOnAxis( v1, distance );
  3313. };
  3314. }(),
  3315. localToWorld: function ( vector ) {
  3316. return vector.applyMatrix4( this.matrixWorld );
  3317. },
  3318. worldToLocal: function () {
  3319. var m1 = new Matrix4();
  3320. return function worldToLocal( vector ) {
  3321. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  3322. };
  3323. }(),
  3324. lookAt: function () {
  3325. // This method does not support objects having non-uniformly-scaled parent(s)
  3326. var q1 = new Quaternion();
  3327. var m1 = new Matrix4();
  3328. var target = new Vector3();
  3329. var position = new Vector3();
  3330. return function lookAt( x, y, z ) {
  3331. if ( x.isVector3 ) {
  3332. target.copy( x );
  3333. } else {
  3334. target.set( x, y, z );
  3335. }
  3336. var parent = this.parent;
  3337. this.updateWorldMatrix( true, false );
  3338. position.setFromMatrixPosition( this.matrixWorld );
  3339. if ( this.isCamera || this.isLight ) {
  3340. m1.lookAt( position, target, this.up );
  3341. } else {
  3342. m1.lookAt( target, position, this.up );
  3343. }
  3344. this.quaternion.setFromRotationMatrix( m1 );
  3345. if ( parent ) {
  3346. m1.extractRotation( parent.matrixWorld );
  3347. q1.setFromRotationMatrix( m1 );
  3348. this.quaternion.premultiply( q1.inverse() );
  3349. }
  3350. };
  3351. }(),
  3352. add: function ( object ) {
  3353. if ( arguments.length > 1 ) {
  3354. for ( var i = 0; i < arguments.length; i ++ ) {
  3355. this.add( arguments[ i ] );
  3356. }
  3357. return this;
  3358. }
  3359. if ( object === this ) {
  3360. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  3361. return this;
  3362. }
  3363. if ( ( object && object.isObject3D ) ) {
  3364. if ( object.parent !== null ) {
  3365. object.parent.remove( object );
  3366. }
  3367. object.parent = this;
  3368. this.children.push( object );
  3369. object.dispatchEvent( { type: 'added' } );
  3370. } else {
  3371. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  3372. }
  3373. return this;
  3374. },
  3375. remove: function ( object ) {
  3376. if ( arguments.length > 1 ) {
  3377. for ( var i = 0; i < arguments.length; i ++ ) {
  3378. this.remove( arguments[ i ] );
  3379. }
  3380. return this;
  3381. }
  3382. var index = this.children.indexOf( object );
  3383. if ( index !== - 1 ) {
  3384. object.parent = null;
  3385. this.children.splice( index, 1 );
  3386. object.dispatchEvent( { type: 'removed' } );
  3387. }
  3388. return this;
  3389. },
  3390. attach: function () {
  3391. // adds object as a child of this, while maintaining the object's world transform
  3392. var m = new Matrix4();
  3393. return function attach( object ) {
  3394. this.updateWorldMatrix( true, false );
  3395. m.getInverse( this.matrixWorld );
  3396. if ( object.parent !== null ) {
  3397. object.parent.updateWorldMatrix( true, false );
  3398. m.multiply( object.parent.matrixWorld );
  3399. }
  3400. object.applyMatrix( m );
  3401. object.updateWorldMatrix( false, false );
  3402. this.add( object );
  3403. return this;
  3404. };
  3405. }(),
  3406. getObjectById: function ( id ) {
  3407. return this.getObjectByProperty( 'id', id );
  3408. },
  3409. getObjectByName: function ( name ) {
  3410. return this.getObjectByProperty( 'name', name );
  3411. },
  3412. getObjectByProperty: function ( name, value ) {
  3413. if ( this[ name ] === value ) return this;
  3414. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  3415. var child = this.children[ i ];
  3416. var object = child.getObjectByProperty( name, value );
  3417. if ( object !== undefined ) {
  3418. return object;
  3419. }
  3420. }
  3421. return undefined;
  3422. },
  3423. getWorldPosition: function ( target ) {
  3424. if ( target === undefined ) {
  3425. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  3426. target = new Vector3();
  3427. }
  3428. this.updateMatrixWorld( true );
  3429. return target.setFromMatrixPosition( this.matrixWorld );
  3430. },
  3431. getWorldQuaternion: function () {
  3432. var position = new Vector3();
  3433. var scale = new Vector3();
  3434. return function getWorldQuaternion( target ) {
  3435. if ( target === undefined ) {
  3436. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  3437. target = new Quaternion();
  3438. }
  3439. this.updateMatrixWorld( true );
  3440. this.matrixWorld.decompose( position, target, scale );
  3441. return target;
  3442. };
  3443. }(),
  3444. getWorldScale: function () {
  3445. var position = new Vector3();
  3446. var quaternion = new Quaternion();
  3447. return function getWorldScale( target ) {
  3448. if ( target === undefined ) {
  3449. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  3450. target = new Vector3();
  3451. }
  3452. this.updateMatrixWorld( true );
  3453. this.matrixWorld.decompose( position, quaternion, target );
  3454. return target;
  3455. };
  3456. }(),
  3457. getWorldDirection: function ( target ) {
  3458. if ( target === undefined ) {
  3459. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  3460. target = new Vector3();
  3461. }
  3462. this.updateMatrixWorld( true );
  3463. var e = this.matrixWorld.elements;
  3464. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  3465. },
  3466. raycast: function () {},
  3467. traverse: function ( callback ) {
  3468. callback( this );
  3469. var children = this.children;
  3470. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3471. children[ i ].traverse( callback );
  3472. }
  3473. },
  3474. traverseVisible: function ( callback ) {
  3475. if ( this.visible === false ) return;
  3476. callback( this );
  3477. var children = this.children;
  3478. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3479. children[ i ].traverseVisible( callback );
  3480. }
  3481. },
  3482. traverseAncestors: function ( callback ) {
  3483. var parent = this.parent;
  3484. if ( parent !== null ) {
  3485. callback( parent );
  3486. parent.traverseAncestors( callback );
  3487. }
  3488. },
  3489. updateMatrix: function () {
  3490. this.matrix.compose( this.position, this.quaternion, this.scale );
  3491. this.matrixWorldNeedsUpdate = true;
  3492. },
  3493. updateMatrixWorld: function ( force ) {
  3494. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3495. if ( this.matrixWorldNeedsUpdate || force ) {
  3496. if ( this.parent === null ) {
  3497. this.matrixWorld.copy( this.matrix );
  3498. } else {
  3499. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  3500. }
  3501. this.matrixWorldNeedsUpdate = false;
  3502. force = true;
  3503. }
  3504. // update children
  3505. var children = this.children;
  3506. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3507. children[ i ].updateMatrixWorld( force );
  3508. }
  3509. },
  3510. updateWorldMatrix: function ( updateParents, updateChildren ) {
  3511. var parent = this.parent;
  3512. if ( updateParents === true && parent !== null ) {
  3513. parent.updateWorldMatrix( true, false );
  3514. }
  3515. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3516. if ( this.parent === null ) {
  3517. this.matrixWorld.copy( this.matrix );
  3518. } else {
  3519. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  3520. }
  3521. // update children
  3522. if ( updateChildren === true ) {
  3523. var children = this.children;
  3524. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3525. children[ i ].updateWorldMatrix( false, true );
  3526. }
  3527. }
  3528. },
  3529. toJSON: function ( meta ) {
  3530. // meta is a string when called from JSON.stringify
  3531. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  3532. var output = {};
  3533. // meta is a hash used to collect geometries, materials.
  3534. // not providing it implies that this is the root object
  3535. // being serialized.
  3536. if ( isRootObject ) {
  3537. // initialize meta obj
  3538. meta = {
  3539. geometries: {},
  3540. materials: {},
  3541. textures: {},
  3542. images: {},
  3543. shapes: {}
  3544. };
  3545. output.metadata = {
  3546. version: 4.5,
  3547. type: 'Object',
  3548. generator: 'Object3D.toJSON'
  3549. };
  3550. }
  3551. // standard Object3D serialization
  3552. var object = {};
  3553. object.uuid = this.uuid;
  3554. object.type = this.type;
  3555. if ( this.name !== '' ) object.name = this.name;
  3556. if ( this.castShadow === true ) object.castShadow = true;
  3557. if ( this.receiveShadow === true ) object.receiveShadow = true;
  3558. if ( this.visible === false ) object.visible = false;
  3559. if ( this.frustumCulled === false ) object.frustumCulled = false;
  3560. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  3561. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  3562. object.layers = this.layers.mask;
  3563. object.matrix = this.matrix.toArray();
  3564. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  3565. // object specific properties
  3566. if ( this.isMesh && this.drawMode !== TrianglesDrawMode ) object.drawMode = this.drawMode;
  3567. //
  3568. function serialize( library, element ) {
  3569. if ( library[ element.uuid ] === undefined ) {
  3570. library[ element.uuid ] = element.toJSON( meta );
  3571. }
  3572. return element.uuid;
  3573. }
  3574. if ( this.isMesh || this.isLine || this.isPoints ) {
  3575. object.geometry = serialize( meta.geometries, this.geometry );
  3576. var parameters = this.geometry.parameters;
  3577. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  3578. var shapes = parameters.shapes;
  3579. if ( Array.isArray( shapes ) ) {
  3580. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  3581. var shape = shapes[ i ];
  3582. serialize( meta.shapes, shape );
  3583. }
  3584. } else {
  3585. serialize( meta.shapes, shapes );
  3586. }
  3587. }
  3588. }
  3589. if ( this.material !== undefined ) {
  3590. if ( Array.isArray( this.material ) ) {
  3591. var uuids = [];
  3592. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  3593. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  3594. }
  3595. object.material = uuids;
  3596. } else {
  3597. object.material = serialize( meta.materials, this.material );
  3598. }
  3599. }
  3600. //
  3601. if ( this.children.length > 0 ) {
  3602. object.children = [];
  3603. for ( var i = 0; i < this.children.length; i ++ ) {
  3604. object.children.push( this.children[ i ].toJSON( meta ).object );
  3605. }
  3606. }
  3607. if ( isRootObject ) {
  3608. var geometries = extractFromCache( meta.geometries );
  3609. var materials = extractFromCache( meta.materials );
  3610. var textures = extractFromCache( meta.textures );
  3611. var images = extractFromCache( meta.images );
  3612. var shapes = extractFromCache( meta.shapes );
  3613. if ( geometries.length > 0 ) output.geometries = geometries;
  3614. if ( materials.length > 0 ) output.materials = materials;
  3615. if ( textures.length > 0 ) output.textures = textures;
  3616. if ( images.length > 0 ) output.images = images;
  3617. if ( shapes.length > 0 ) output.shapes = shapes;
  3618. }
  3619. output.object = object;
  3620. return output;
  3621. // extract data from the cache hash
  3622. // remove metadata on each item
  3623. // and return as array
  3624. function extractFromCache( cache ) {
  3625. var values = [];
  3626. for ( var key in cache ) {
  3627. var data = cache[ key ];
  3628. delete data.metadata;
  3629. values.push( data );
  3630. }
  3631. return values;
  3632. }
  3633. },
  3634. clone: function ( recursive ) {
  3635. return new this.constructor().copy( this, recursive );
  3636. },
  3637. copy: function ( source, recursive ) {
  3638. if ( recursive === undefined ) recursive = true;
  3639. this.name = source.name;
  3640. this.up.copy( source.up );
  3641. this.position.copy( source.position );
  3642. this.quaternion.copy( source.quaternion );
  3643. this.scale.copy( source.scale );
  3644. this.matrix.copy( source.matrix );
  3645. this.matrixWorld.copy( source.matrixWorld );
  3646. this.matrixAutoUpdate = source.matrixAutoUpdate;
  3647. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  3648. this.layers.mask = source.layers.mask;
  3649. this.visible = source.visible;
  3650. this.castShadow = source.castShadow;
  3651. this.receiveShadow = source.receiveShadow;
  3652. this.frustumCulled = source.frustumCulled;
  3653. this.renderOrder = source.renderOrder;
  3654. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  3655. if ( recursive === true ) {
  3656. for ( var i = 0; i < source.children.length; i ++ ) {
  3657. var child = source.children[ i ];
  3658. this.add( child.clone() );
  3659. }
  3660. }
  3661. return this;
  3662. }
  3663. } );
  3664. /**
  3665. * @author mrdoob / http://mrdoob.com/
  3666. */
  3667. function Scene() {
  3668. Object3D.call( this );
  3669. this.type = 'Scene';
  3670. this.background = null;
  3671. this.fog = null;
  3672. this.overrideMaterial = null;
  3673. this.autoUpdate = true; // checked by the renderer
  3674. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  3675. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  3676. }
  3677. }
  3678. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  3679. constructor: Scene,
  3680. isScene: true,
  3681. copy: function ( source, recursive ) {
  3682. Object3D.prototype.copy.call( this, source, recursive );
  3683. if ( source.background !== null ) this.background = source.background.clone();
  3684. if ( source.fog !== null ) this.fog = source.fog.clone();
  3685. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  3686. this.autoUpdate = source.autoUpdate;
  3687. this.matrixAutoUpdate = source.matrixAutoUpdate;
  3688. return this;
  3689. },
  3690. toJSON: function ( meta ) {
  3691. var data = Object3D.prototype.toJSON.call( this, meta );
  3692. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  3693. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  3694. return data;
  3695. },
  3696. dispose: function () {
  3697. this.dispatchEvent( { type: 'dispose' } );
  3698. }
  3699. } );
  3700. /**
  3701. * @author bhouston / http://clara.io
  3702. * @author WestLangley / http://github.com/WestLangley
  3703. */
  3704. function Box3( min, max ) {
  3705. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  3706. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  3707. }
  3708. Object.assign( Box3.prototype, {
  3709. isBox3: true,
  3710. set: function ( min, max ) {
  3711. this.min.copy( min );
  3712. this.max.copy( max );
  3713. return this;
  3714. },
  3715. setFromArray: function ( array ) {
  3716. var minX = + Infinity;
  3717. var minY = + Infinity;
  3718. var minZ = + Infinity;
  3719. var maxX = - Infinity;
  3720. var maxY = - Infinity;
  3721. var maxZ = - Infinity;
  3722. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  3723. var x = array[ i ];
  3724. var y = array[ i + 1 ];
  3725. var z = array[ i + 2 ];
  3726. if ( x < minX ) minX = x;
  3727. if ( y < minY ) minY = y;
  3728. if ( z < minZ ) minZ = z;
  3729. if ( x > maxX ) maxX = x;
  3730. if ( y > maxY ) maxY = y;
  3731. if ( z > maxZ ) maxZ = z;
  3732. }
  3733. this.min.set( minX, minY, minZ );
  3734. this.max.set( maxX, maxY, maxZ );
  3735. return this;
  3736. },
  3737. setFromBufferAttribute: function ( attribute ) {
  3738. var minX = + Infinity;
  3739. var minY = + Infinity;
  3740. var minZ = + Infinity;
  3741. var maxX = - Infinity;
  3742. var maxY = - Infinity;
  3743. var maxZ = - Infinity;
  3744. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  3745. var x = attribute.getX( i );
  3746. var y = attribute.getY( i );
  3747. var z = attribute.getZ( i );
  3748. if ( x < minX ) minX = x;
  3749. if ( y < minY ) minY = y;
  3750. if ( z < minZ ) minZ = z;
  3751. if ( x > maxX ) maxX = x;
  3752. if ( y > maxY ) maxY = y;
  3753. if ( z > maxZ ) maxZ = z;
  3754. }
  3755. this.min.set( minX, minY, minZ );
  3756. this.max.set( maxX, maxY, maxZ );
  3757. return this;
  3758. },
  3759. setFromPoints: function ( points ) {
  3760. this.makeEmpty();
  3761. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3762. this.expandByPoint( points[ i ] );
  3763. }
  3764. return this;
  3765. },
  3766. setFromCenterAndSize: function () {
  3767. var v1 = new Vector3();
  3768. return function setFromCenterAndSize( center, size ) {
  3769. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  3770. this.min.copy( center ).sub( halfSize );
  3771. this.max.copy( center ).add( halfSize );
  3772. return this;
  3773. };
  3774. }(),
  3775. setFromObject: function ( object ) {
  3776. this.makeEmpty();
  3777. return this.expandByObject( object );
  3778. },
  3779. clone: function () {
  3780. return new this.constructor().copy( this );
  3781. },
  3782. copy: function ( box ) {
  3783. this.min.copy( box.min );
  3784. this.max.copy( box.max );
  3785. return this;
  3786. },
  3787. makeEmpty: function () {
  3788. this.min.x = this.min.y = this.min.z = + Infinity;
  3789. this.max.x = this.max.y = this.max.z = - Infinity;
  3790. return this;
  3791. },
  3792. isEmpty: function () {
  3793. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3794. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  3795. },
  3796. getCenter: function ( target ) {
  3797. if ( target === undefined ) {
  3798. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  3799. target = new Vector3();
  3800. }
  3801. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  3802. },
  3803. getSize: function ( target ) {
  3804. if ( target === undefined ) {
  3805. console.warn( 'THREE.Box3: .getSize() target is now required' );
  3806. target = new Vector3();
  3807. }
  3808. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  3809. },
  3810. expandByPoint: function ( point ) {
  3811. this.min.min( point );
  3812. this.max.max( point );
  3813. return this;
  3814. },
  3815. expandByVector: function ( vector ) {
  3816. this.min.sub( vector );
  3817. this.max.add( vector );
  3818. return this;
  3819. },
  3820. expandByScalar: function ( scalar ) {
  3821. this.min.addScalar( - scalar );
  3822. this.max.addScalar( scalar );
  3823. return this;
  3824. },
  3825. expandByObject: function () {
  3826. // Computes the world-axis-aligned bounding box of an object (including its children),
  3827. // accounting for both the object's, and children's, world transforms
  3828. var scope, i, l;
  3829. var v1 = new Vector3();
  3830. function traverse( node ) {
  3831. var geometry = node.geometry;
  3832. if ( geometry !== undefined ) {
  3833. if ( geometry.isGeometry ) {
  3834. var vertices = geometry.vertices;
  3835. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  3836. v1.copy( vertices[ i ] );
  3837. v1.applyMatrix4( node.matrixWorld );
  3838. scope.expandByPoint( v1 );
  3839. }
  3840. } else if ( geometry.isBufferGeometry ) {
  3841. var attribute = geometry.attributes.position;
  3842. if ( attribute !== undefined ) {
  3843. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  3844. v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
  3845. scope.expandByPoint( v1 );
  3846. }
  3847. }
  3848. }
  3849. }
  3850. }
  3851. return function expandByObject( object ) {
  3852. scope = this;
  3853. object.updateMatrixWorld( true );
  3854. object.traverse( traverse );
  3855. return this;
  3856. };
  3857. }(),
  3858. containsPoint: function ( point ) {
  3859. return point.x < this.min.x || point.x > this.max.x ||
  3860. point.y < this.min.y || point.y > this.max.y ||
  3861. point.z < this.min.z || point.z > this.max.z ? false : true;
  3862. },
  3863. containsBox: function ( box ) {
  3864. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  3865. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  3866. this.min.z <= box.min.z && box.max.z <= this.max.z;
  3867. },
  3868. getParameter: function ( point, target ) {
  3869. // This can potentially have a divide by zero if the box
  3870. // has a size dimension of 0.
  3871. if ( target === undefined ) {
  3872. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  3873. target = new Vector3();
  3874. }
  3875. return target.set(
  3876. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  3877. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  3878. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  3879. );
  3880. },
  3881. intersectsBox: function ( box ) {
  3882. // using 6 splitting planes to rule out intersections.
  3883. return box.max.x < this.min.x || box.min.x > this.max.x ||
  3884. box.max.y < this.min.y || box.min.y > this.max.y ||
  3885. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  3886. },
  3887. intersectsSphere: ( function () {
  3888. var closestPoint = new Vector3();
  3889. return function intersectsSphere( sphere ) {
  3890. // Find the point on the AABB closest to the sphere center.
  3891. this.clampPoint( sphere.center, closestPoint );
  3892. // If that point is inside the sphere, the AABB and sphere intersect.
  3893. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  3894. };
  3895. } )(),
  3896. intersectsPlane: function ( plane ) {
  3897. // We compute the minimum and maximum dot product values. If those values
  3898. // are on the same side (back or front) of the plane, then there is no intersection.
  3899. var min, max;
  3900. if ( plane.normal.x > 0 ) {
  3901. min = plane.normal.x * this.min.x;
  3902. max = plane.normal.x * this.max.x;
  3903. } else {
  3904. min = plane.normal.x * this.max.x;
  3905. max = plane.normal.x * this.min.x;
  3906. }
  3907. if ( plane.normal.y > 0 ) {
  3908. min += plane.normal.y * this.min.y;
  3909. max += plane.normal.y * this.max.y;
  3910. } else {
  3911. min += plane.normal.y * this.max.y;
  3912. max += plane.normal.y * this.min.y;
  3913. }
  3914. if ( plane.normal.z > 0 ) {
  3915. min += plane.normal.z * this.min.z;
  3916. max += plane.normal.z * this.max.z;
  3917. } else {
  3918. min += plane.normal.z * this.max.z;
  3919. max += plane.normal.z * this.min.z;
  3920. }
  3921. return ( min <= - plane.constant && max >= - plane.constant );
  3922. },
  3923. intersectsTriangle: ( function () {
  3924. // triangle centered vertices
  3925. var v0 = new Vector3();
  3926. var v1 = new Vector3();
  3927. var v2 = new Vector3();
  3928. // triangle edge vectors
  3929. var f0 = new Vector3();
  3930. var f1 = new Vector3();
  3931. var f2 = new Vector3();
  3932. var testAxis = new Vector3();
  3933. var center = new Vector3();
  3934. var extents = new Vector3();
  3935. var triangleNormal = new Vector3();
  3936. function satForAxes( axes ) {
  3937. var i, j;
  3938. for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  3939. testAxis.fromArray( axes, i );
  3940. // project the aabb onto the seperating axis
  3941. var r = extents.x * Math.abs( testAxis.x ) + extents.y * Math.abs( testAxis.y ) + extents.z * Math.abs( testAxis.z );
  3942. // project all 3 vertices of the triangle onto the seperating axis
  3943. var p0 = v0.dot( testAxis );
  3944. var p1 = v1.dot( testAxis );
  3945. var p2 = v2.dot( testAxis );
  3946. // actual test, basically see if either of the most extreme of the triangle points intersects r
  3947. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  3948. // points of the projected triangle are outside the projected half-length of the aabb
  3949. // the axis is seperating and we can exit
  3950. return false;
  3951. }
  3952. }
  3953. return true;
  3954. }
  3955. return function intersectsTriangle( triangle ) {
  3956. if ( this.isEmpty() ) {
  3957. return false;
  3958. }
  3959. // compute box center and extents
  3960. this.getCenter( center );
  3961. extents.subVectors( this.max, center );
  3962. // translate triangle to aabb origin
  3963. v0.subVectors( triangle.a, center );
  3964. v1.subVectors( triangle.b, center );
  3965. v2.subVectors( triangle.c, center );
  3966. // compute edge vectors for triangle
  3967. f0.subVectors( v1, v0 );
  3968. f1.subVectors( v2, v1 );
  3969. f2.subVectors( v0, v2 );
  3970. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3971. // 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
  3972. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3973. var axes = [
  3974. 0, - f0.z, f0.y, 0, - f1.z, f1.y, 0, - f2.z, f2.y,
  3975. f0.z, 0, - f0.x, f1.z, 0, - f1.x, f2.z, 0, - f2.x,
  3976. - f0.y, f0.x, 0, - f1.y, f1.x, 0, - f2.y, f2.x, 0
  3977. ];
  3978. if ( ! satForAxes( axes ) ) {
  3979. return false;
  3980. }
  3981. // test 3 face normals from the aabb
  3982. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  3983. if ( ! satForAxes( axes ) ) {
  3984. return false;
  3985. }
  3986. // finally testing the face normal of the triangle
  3987. // use already existing triangle edge vectors here
  3988. triangleNormal.crossVectors( f0, f1 );
  3989. axes = [ triangleNormal.x, triangleNormal.y, triangleNormal.z ];
  3990. return satForAxes( axes );
  3991. };
  3992. } )(),
  3993. clampPoint: function ( point, target ) {
  3994. if ( target === undefined ) {
  3995. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  3996. target = new Vector3();
  3997. }
  3998. return target.copy( point ).clamp( this.min, this.max );
  3999. },
  4000. distanceToPoint: function () {
  4001. var v1 = new Vector3();
  4002. return function distanceToPoint( point ) {
  4003. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  4004. return clampedPoint.sub( point ).length();
  4005. };
  4006. }(),
  4007. getBoundingSphere: function () {
  4008. var v1 = new Vector3();
  4009. return function getBoundingSphere( target ) {
  4010. if ( target === undefined ) {
  4011. console.error( 'THREE.Box3: .getBoundingSphere() target is now required' );
  4012. //target = new Sphere(); // removed to avoid cyclic dependency
  4013. }
  4014. this.getCenter( target.center );
  4015. target.radius = this.getSize( v1 ).length() * 0.5;
  4016. return target;
  4017. };
  4018. }(),
  4019. intersect: function ( box ) {
  4020. this.min.max( box.min );
  4021. this.max.min( box.max );
  4022. // 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.
  4023. if ( this.isEmpty() ) this.makeEmpty();
  4024. return this;
  4025. },
  4026. union: function ( box ) {
  4027. this.min.min( box.min );
  4028. this.max.max( box.max );
  4029. return this;
  4030. },
  4031. applyMatrix4: function () {
  4032. var points = [
  4033. new Vector3(),
  4034. new Vector3(),
  4035. new Vector3(),
  4036. new Vector3(),
  4037. new Vector3(),
  4038. new Vector3(),
  4039. new Vector3(),
  4040. new Vector3()
  4041. ];
  4042. return function applyMatrix4( matrix ) {
  4043. // transform of empty box is an empty box.
  4044. if ( this.isEmpty() ) return this;
  4045. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  4046. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  4047. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  4048. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  4049. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  4050. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  4051. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  4052. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  4053. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  4054. this.setFromPoints( points );
  4055. return this;
  4056. };
  4057. }(),
  4058. translate: function ( offset ) {
  4059. this.min.add( offset );
  4060. this.max.add( offset );
  4061. return this;
  4062. },
  4063. equals: function ( box ) {
  4064. return box.min.equals( this.min ) && box.max.equals( this.max );
  4065. }
  4066. } );
  4067. /**
  4068. * @author bhouston / http://clara.io
  4069. * @author mrdoob / http://mrdoob.com/
  4070. */
  4071. function Sphere( center, radius ) {
  4072. this.center = ( center !== undefined ) ? center : new Vector3();
  4073. this.radius = ( radius !== undefined ) ? radius : 0;
  4074. }
  4075. Object.assign( Sphere.prototype, {
  4076. set: function ( center, radius ) {
  4077. this.center.copy( center );
  4078. this.radius = radius;
  4079. return this;
  4080. },
  4081. setFromPoints: function () {
  4082. var box = new Box3();
  4083. return function setFromPoints( points, optionalCenter ) {
  4084. var center = this.center;
  4085. if ( optionalCenter !== undefined ) {
  4086. center.copy( optionalCenter );
  4087. } else {
  4088. box.setFromPoints( points ).getCenter( center );
  4089. }
  4090. var maxRadiusSq = 0;
  4091. for ( var i = 0, il = points.length; i < il; i ++ ) {
  4092. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  4093. }
  4094. this.radius = Math.sqrt( maxRadiusSq );
  4095. return this;
  4096. };
  4097. }(),
  4098. clone: function () {
  4099. return new this.constructor().copy( this );
  4100. },
  4101. copy: function ( sphere ) {
  4102. this.center.copy( sphere.center );
  4103. this.radius = sphere.radius;
  4104. return this;
  4105. },
  4106. empty: function () {
  4107. return ( this.radius <= 0 );
  4108. },
  4109. containsPoint: function ( point ) {
  4110. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  4111. },
  4112. distanceToPoint: function ( point ) {
  4113. return ( point.distanceTo( this.center ) - this.radius );
  4114. },
  4115. intersectsSphere: function ( sphere ) {
  4116. var radiusSum = this.radius + sphere.radius;
  4117. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  4118. },
  4119. intersectsBox: function ( box ) {
  4120. return box.intersectsSphere( this );
  4121. },
  4122. intersectsPlane: function ( plane ) {
  4123. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  4124. },
  4125. clampPoint: function ( point, target ) {
  4126. var deltaLengthSq = this.center.distanceToSquared( point );
  4127. if ( target === undefined ) {
  4128. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  4129. target = new Vector3();
  4130. }
  4131. target.copy( point );
  4132. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  4133. target.sub( this.center ).normalize();
  4134. target.multiplyScalar( this.radius ).add( this.center );
  4135. }
  4136. return target;
  4137. },
  4138. getBoundingBox: function ( target ) {
  4139. if ( target === undefined ) {
  4140. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  4141. target = new Box3();
  4142. }
  4143. target.set( this.center, this.center );
  4144. target.expandByScalar( this.radius );
  4145. return target;
  4146. },
  4147. applyMatrix4: function ( matrix ) {
  4148. this.center.applyMatrix4( matrix );
  4149. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  4150. return this;
  4151. },
  4152. translate: function ( offset ) {
  4153. this.center.add( offset );
  4154. return this;
  4155. },
  4156. equals: function ( sphere ) {
  4157. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  4158. }
  4159. } );
  4160. /**
  4161. * @author bhouston / http://clara.io
  4162. */
  4163. function Ray( origin, direction ) {
  4164. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  4165. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  4166. }
  4167. Object.assign( Ray.prototype, {
  4168. set: function ( origin, direction ) {
  4169. this.origin.copy( origin );
  4170. this.direction.copy( direction );
  4171. return this;
  4172. },
  4173. clone: function () {
  4174. return new this.constructor().copy( this );
  4175. },
  4176. copy: function ( ray ) {
  4177. this.origin.copy( ray.origin );
  4178. this.direction.copy( ray.direction );
  4179. return this;
  4180. },
  4181. at: function ( t, target ) {
  4182. if ( target === undefined ) {
  4183. console.warn( 'THREE.Ray: .at() target is now required' );
  4184. target = new Vector3();
  4185. }
  4186. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  4187. },
  4188. lookAt: function ( v ) {
  4189. this.direction.copy( v ).sub( this.origin ).normalize();
  4190. return this;
  4191. },
  4192. recast: function () {
  4193. var v1 = new Vector3();
  4194. return function recast( t ) {
  4195. this.origin.copy( this.at( t, v1 ) );
  4196. return this;
  4197. };
  4198. }(),
  4199. closestPointToPoint: function ( point, target ) {
  4200. if ( target === undefined ) {
  4201. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  4202. target = new Vector3();
  4203. }
  4204. target.subVectors( point, this.origin );
  4205. var directionDistance = target.dot( this.direction );
  4206. if ( directionDistance < 0 ) {
  4207. return target.copy( this.origin );
  4208. }
  4209. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  4210. },
  4211. distanceToPoint: function ( point ) {
  4212. return Math.sqrt( this.distanceSqToPoint( point ) );
  4213. },
  4214. distanceSqToPoint: function () {
  4215. var v1 = new Vector3();
  4216. return function distanceSqToPoint( point ) {
  4217. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  4218. // point behind the ray
  4219. if ( directionDistance < 0 ) {
  4220. return this.origin.distanceToSquared( point );
  4221. }
  4222. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  4223. return v1.distanceToSquared( point );
  4224. };
  4225. }(),
  4226. distanceSqToSegment: function () {
  4227. var segCenter = new Vector3();
  4228. var segDir = new Vector3();
  4229. var diff = new Vector3();
  4230. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  4231. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  4232. // It returns the min distance between the ray and the segment
  4233. // defined by v0 and v1
  4234. // It can also set two optional targets :
  4235. // - The closest point on the ray
  4236. // - The closest point on the segment
  4237. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  4238. segDir.copy( v1 ).sub( v0 ).normalize();
  4239. diff.copy( this.origin ).sub( segCenter );
  4240. var segExtent = v0.distanceTo( v1 ) * 0.5;
  4241. var a01 = - this.direction.dot( segDir );
  4242. var b0 = diff.dot( this.direction );
  4243. var b1 = - diff.dot( segDir );
  4244. var c = diff.lengthSq();
  4245. var det = Math.abs( 1 - a01 * a01 );
  4246. var s0, s1, sqrDist, extDet;
  4247. if ( det > 0 ) {
  4248. // The ray and segment are not parallel.
  4249. s0 = a01 * b1 - b0;
  4250. s1 = a01 * b0 - b1;
  4251. extDet = segExtent * det;
  4252. if ( s0 >= 0 ) {
  4253. if ( s1 >= - extDet ) {
  4254. if ( s1 <= extDet ) {
  4255. // region 0
  4256. // Minimum at interior points of ray and segment.
  4257. var invDet = 1 / det;
  4258. s0 *= invDet;
  4259. s1 *= invDet;
  4260. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  4261. } else {
  4262. // region 1
  4263. s1 = segExtent;
  4264. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4265. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4266. }
  4267. } else {
  4268. // region 5
  4269. s1 = - segExtent;
  4270. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4271. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4272. }
  4273. } else {
  4274. if ( s1 <= - extDet ) {
  4275. // region 4
  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. } else if ( s1 <= extDet ) {
  4280. // region 3
  4281. s0 = 0;
  4282. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4283. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  4284. } else {
  4285. // region 2
  4286. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  4287. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4288. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4289. }
  4290. }
  4291. } else {
  4292. // Ray and segment are parallel.
  4293. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  4294. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4295. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4296. }
  4297. if ( optionalPointOnRay ) {
  4298. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  4299. }
  4300. if ( optionalPointOnSegment ) {
  4301. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  4302. }
  4303. return sqrDist;
  4304. };
  4305. }(),
  4306. intersectSphere: function () {
  4307. var v1 = new Vector3();
  4308. return function intersectSphere( sphere, target ) {
  4309. v1.subVectors( sphere.center, this.origin );
  4310. var tca = v1.dot( this.direction );
  4311. var d2 = v1.dot( v1 ) - tca * tca;
  4312. var radius2 = sphere.radius * sphere.radius;
  4313. if ( d2 > radius2 ) return null;
  4314. var thc = Math.sqrt( radius2 - d2 );
  4315. // t0 = first intersect point - entrance on front of sphere
  4316. var t0 = tca - thc;
  4317. // t1 = second intersect point - exit point on back of sphere
  4318. var t1 = tca + thc;
  4319. // test to see if both t0 and t1 are behind the ray - if so, return null
  4320. if ( t0 < 0 && t1 < 0 ) return null;
  4321. // test to see if t0 is behind the ray:
  4322. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  4323. // in order to always return an intersect point that is in front of the ray.
  4324. if ( t0 < 0 ) return this.at( t1, target );
  4325. // else t0 is in front of the ray, so return the first collision point scaled by t0
  4326. return this.at( t0, target );
  4327. };
  4328. }(),
  4329. intersectsSphere: function ( sphere ) {
  4330. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  4331. },
  4332. distanceToPlane: function ( plane ) {
  4333. var denominator = plane.normal.dot( this.direction );
  4334. if ( denominator === 0 ) {
  4335. // line is coplanar, return origin
  4336. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  4337. return 0;
  4338. }
  4339. // Null is preferable to undefined since undefined means.... it is undefined
  4340. return null;
  4341. }
  4342. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  4343. // Return if the ray never intersects the plane
  4344. return t >= 0 ? t : null;
  4345. },
  4346. intersectPlane: function ( plane, target ) {
  4347. var t = this.distanceToPlane( plane );
  4348. if ( t === null ) {
  4349. return null;
  4350. }
  4351. return this.at( t, target );
  4352. },
  4353. intersectsPlane: function ( plane ) {
  4354. // check if the ray lies on the plane first
  4355. var distToPoint = plane.distanceToPoint( this.origin );
  4356. if ( distToPoint === 0 ) {
  4357. return true;
  4358. }
  4359. var denominator = plane.normal.dot( this.direction );
  4360. if ( denominator * distToPoint < 0 ) {
  4361. return true;
  4362. }
  4363. // ray origin is behind the plane (and is pointing behind it)
  4364. return false;
  4365. },
  4366. intersectBox: function ( box, target ) {
  4367. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  4368. var invdirx = 1 / this.direction.x,
  4369. invdiry = 1 / this.direction.y,
  4370. invdirz = 1 / this.direction.z;
  4371. var origin = this.origin;
  4372. if ( invdirx >= 0 ) {
  4373. tmin = ( box.min.x - origin.x ) * invdirx;
  4374. tmax = ( box.max.x - origin.x ) * invdirx;
  4375. } else {
  4376. tmin = ( box.max.x - origin.x ) * invdirx;
  4377. tmax = ( box.min.x - origin.x ) * invdirx;
  4378. }
  4379. if ( invdiry >= 0 ) {
  4380. tymin = ( box.min.y - origin.y ) * invdiry;
  4381. tymax = ( box.max.y - origin.y ) * invdiry;
  4382. } else {
  4383. tymin = ( box.max.y - origin.y ) * invdiry;
  4384. tymax = ( box.min.y - origin.y ) * invdiry;
  4385. }
  4386. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  4387. // These lines also handle the case where tmin or tmax is NaN
  4388. // (result of 0 * Infinity). x !== x returns true if x is NaN
  4389. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  4390. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  4391. if ( invdirz >= 0 ) {
  4392. tzmin = ( box.min.z - origin.z ) * invdirz;
  4393. tzmax = ( box.max.z - origin.z ) * invdirz;
  4394. } else {
  4395. tzmin = ( box.max.z - origin.z ) * invdirz;
  4396. tzmax = ( box.min.z - origin.z ) * invdirz;
  4397. }
  4398. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  4399. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  4400. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  4401. //return point closest to the ray (positive side)
  4402. if ( tmax < 0 ) return null;
  4403. return this.at( tmin >= 0 ? tmin : tmax, target );
  4404. },
  4405. intersectsBox: ( function () {
  4406. var v = new Vector3();
  4407. return function intersectsBox( box ) {
  4408. return this.intersectBox( box, v ) !== null;
  4409. };
  4410. } )(),
  4411. intersectTriangle: function () {
  4412. // Compute the offset origin, edges, and normal.
  4413. var diff = new Vector3();
  4414. var edge1 = new Vector3();
  4415. var edge2 = new Vector3();
  4416. var normal = new Vector3();
  4417. return function intersectTriangle( a, b, c, backfaceCulling, target ) {
  4418. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  4419. edge1.subVectors( b, a );
  4420. edge2.subVectors( c, a );
  4421. normal.crossVectors( edge1, edge2 );
  4422. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  4423. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  4424. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  4425. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  4426. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  4427. var DdN = this.direction.dot( normal );
  4428. var sign;
  4429. if ( DdN > 0 ) {
  4430. if ( backfaceCulling ) return null;
  4431. sign = 1;
  4432. } else if ( DdN < 0 ) {
  4433. sign = - 1;
  4434. DdN = - DdN;
  4435. } else {
  4436. return null;
  4437. }
  4438. diff.subVectors( this.origin, a );
  4439. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  4440. // b1 < 0, no intersection
  4441. if ( DdQxE2 < 0 ) {
  4442. return null;
  4443. }
  4444. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  4445. // b2 < 0, no intersection
  4446. if ( DdE1xQ < 0 ) {
  4447. return null;
  4448. }
  4449. // b1+b2 > 1, no intersection
  4450. if ( DdQxE2 + DdE1xQ > DdN ) {
  4451. return null;
  4452. }
  4453. // Line intersects triangle, check if ray does.
  4454. var QdN = - sign * diff.dot( normal );
  4455. // t < 0, no intersection
  4456. if ( QdN < 0 ) {
  4457. return null;
  4458. }
  4459. // Ray intersects triangle.
  4460. return this.at( QdN / DdN, target );
  4461. };
  4462. }(),
  4463. applyMatrix4: function ( matrix4 ) {
  4464. this.origin.applyMatrix4( matrix4 );
  4465. this.direction.transformDirection( matrix4 );
  4466. return this;
  4467. },
  4468. equals: function ( ray ) {
  4469. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  4470. }
  4471. } );
  4472. /**
  4473. * @author bhouston / http://clara.io
  4474. * @author mrdoob / http://mrdoob.com/
  4475. */
  4476. function Triangle( a, b, c ) {
  4477. this.a = ( a !== undefined ) ? a : new Vector3();
  4478. this.b = ( b !== undefined ) ? b : new Vector3();
  4479. this.c = ( c !== undefined ) ? c : new Vector3();
  4480. }
  4481. Object.assign( Triangle, {
  4482. getNormal: function () {
  4483. var v0 = new Vector3();
  4484. return function getNormal( a, b, c, target ) {
  4485. if ( target === undefined ) {
  4486. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  4487. target = new Vector3();
  4488. }
  4489. target.subVectors( c, b );
  4490. v0.subVectors( a, b );
  4491. target.cross( v0 );
  4492. var targetLengthSq = target.lengthSq();
  4493. if ( targetLengthSq > 0 ) {
  4494. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  4495. }
  4496. return target.set( 0, 0, 0 );
  4497. };
  4498. }(),
  4499. // static/instance method to calculate barycentric coordinates
  4500. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4501. getBarycoord: function () {
  4502. var v0 = new Vector3();
  4503. var v1 = new Vector3();
  4504. var v2 = new Vector3();
  4505. return function getBarycoord( point, a, b, c, target ) {
  4506. v0.subVectors( c, a );
  4507. v1.subVectors( b, a );
  4508. v2.subVectors( point, a );
  4509. var dot00 = v0.dot( v0 );
  4510. var dot01 = v0.dot( v1 );
  4511. var dot02 = v0.dot( v2 );
  4512. var dot11 = v1.dot( v1 );
  4513. var dot12 = v1.dot( v2 );
  4514. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4515. if ( target === undefined ) {
  4516. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  4517. target = new Vector3();
  4518. }
  4519. // collinear or singular triangle
  4520. if ( denom === 0 ) {
  4521. // arbitrary location outside of triangle?
  4522. // not sure if this is the best idea, maybe should be returning undefined
  4523. return target.set( - 2, - 1, - 1 );
  4524. }
  4525. var invDenom = 1 / denom;
  4526. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4527. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4528. // barycentric coordinates must always sum to 1
  4529. return target.set( 1 - u - v, v, u );
  4530. };
  4531. }(),
  4532. containsPoint: function () {
  4533. var v1 = new Vector3();
  4534. return function containsPoint( point, a, b, c ) {
  4535. Triangle.getBarycoord( point, a, b, c, v1 );
  4536. return ( v1.x >= 0 ) && ( v1.y >= 0 ) && ( ( v1.x + v1.y ) <= 1 );
  4537. };
  4538. }(),
  4539. getUV: function () {
  4540. var barycoord = new Vector3();
  4541. return function getUV( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  4542. this.getBarycoord( point, p1, p2, p3, barycoord );
  4543. target.set( 0, 0 );
  4544. target.addScaledVector( uv1, barycoord.x );
  4545. target.addScaledVector( uv2, barycoord.y );
  4546. target.addScaledVector( uv3, barycoord.z );
  4547. return target;
  4548. };
  4549. }(),
  4550. isFrontFacing: function () {
  4551. var v0 = new Vector3();
  4552. var v1 = new Vector3();
  4553. return function isFrontFacing( a, b, c, direction ) {
  4554. v0.subVectors( c, b );
  4555. v1.subVectors( a, b );
  4556. // strictly front facing
  4557. return ( v0.cross( v1 ).dot( direction ) < 0 ) ? true : false;
  4558. };
  4559. }()
  4560. } );
  4561. Object.assign( Triangle.prototype, {
  4562. set: function ( a, b, c ) {
  4563. this.a.copy( a );
  4564. this.b.copy( b );
  4565. this.c.copy( c );
  4566. return this;
  4567. },
  4568. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4569. this.a.copy( points[ i0 ] );
  4570. this.b.copy( points[ i1 ] );
  4571. this.c.copy( points[ i2 ] );
  4572. return this;
  4573. },
  4574. clone: function () {
  4575. return new this.constructor().copy( this );
  4576. },
  4577. copy: function ( triangle ) {
  4578. this.a.copy( triangle.a );
  4579. this.b.copy( triangle.b );
  4580. this.c.copy( triangle.c );
  4581. return this;
  4582. },
  4583. getArea: function () {
  4584. var v0 = new Vector3();
  4585. var v1 = new Vector3();
  4586. return function getArea() {
  4587. v0.subVectors( this.c, this.b );
  4588. v1.subVectors( this.a, this.b );
  4589. return v0.cross( v1 ).length() * 0.5;
  4590. };
  4591. }(),
  4592. getMidpoint: function ( target ) {
  4593. if ( target === undefined ) {
  4594. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  4595. target = new Vector3();
  4596. }
  4597. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4598. },
  4599. getNormal: function ( target ) {
  4600. return Triangle.getNormal( this.a, this.b, this.c, target );
  4601. },
  4602. getPlane: function ( target ) {
  4603. if ( target === undefined ) {
  4604. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  4605. target = new Vector3();
  4606. }
  4607. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  4608. },
  4609. getBarycoord: function ( point, target ) {
  4610. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  4611. },
  4612. getUV: function ( point, uv1, uv2, uv3, target ) {
  4613. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, target );
  4614. },
  4615. containsPoint: function ( point ) {
  4616. return Triangle.containsPoint( point, this.a, this.b, this.c );
  4617. },
  4618. isFrontFacing: function ( direction ) {
  4619. return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
  4620. },
  4621. intersectsBox: function ( box ) {
  4622. return box.intersectsTriangle( this );
  4623. },
  4624. closestPointToPoint: function () {
  4625. var vab = new Vector3();
  4626. var vac = new Vector3();
  4627. var vbc = new Vector3();
  4628. var vap = new Vector3();
  4629. var vbp = new Vector3();
  4630. var vcp = new Vector3();
  4631. return function closestPointToPoint( p, target ) {
  4632. if ( target === undefined ) {
  4633. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  4634. target = new Vector3();
  4635. }
  4636. var a = this.a, b = this.b, c = this.c;
  4637. var v, w;
  4638. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  4639. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  4640. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  4641. // basically, we're distinguishing which of the voronoi regions of the triangle
  4642. // the point lies in with the minimum amount of redundant computation.
  4643. vab.subVectors( b, a );
  4644. vac.subVectors( c, a );
  4645. vap.subVectors( p, a );
  4646. var d1 = vab.dot( vap );
  4647. var d2 = vac.dot( vap );
  4648. if ( d1 <= 0 && d2 <= 0 ) {
  4649. // vertex region of A; barycentric coords (1, 0, 0)
  4650. return target.copy( a );
  4651. }
  4652. vbp.subVectors( p, b );
  4653. var d3 = vab.dot( vbp );
  4654. var d4 = vac.dot( vbp );
  4655. if ( d3 >= 0 && d4 <= d3 ) {
  4656. // vertex region of B; barycentric coords (0, 1, 0)
  4657. return target.copy( b );
  4658. }
  4659. var vc = d1 * d4 - d3 * d2;
  4660. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  4661. v = d1 / ( d1 - d3 );
  4662. // edge region of AB; barycentric coords (1-v, v, 0)
  4663. return target.copy( a ).addScaledVector( vab, v );
  4664. }
  4665. vcp.subVectors( p, c );
  4666. var d5 = vab.dot( vcp );
  4667. var d6 = vac.dot( vcp );
  4668. if ( d6 >= 0 && d5 <= d6 ) {
  4669. // vertex region of C; barycentric coords (0, 0, 1)
  4670. return target.copy( c );
  4671. }
  4672. var vb = d5 * d2 - d1 * d6;
  4673. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  4674. w = d2 / ( d2 - d6 );
  4675. // edge region of AC; barycentric coords (1-w, 0, w)
  4676. return target.copy( a ).addScaledVector( vac, w );
  4677. }
  4678. var va = d3 * d6 - d5 * d4;
  4679. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  4680. vbc.subVectors( c, b );
  4681. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  4682. // edge region of BC; barycentric coords (0, 1-w, w)
  4683. return target.copy( b ).addScaledVector( vbc, w ); // edge region of BC
  4684. }
  4685. // face region
  4686. var denom = 1 / ( va + vb + vc );
  4687. // u = va * denom
  4688. v = vb * denom;
  4689. w = vc * denom;
  4690. return target.copy( a ).addScaledVector( vab, v ).addScaledVector( vac, w );
  4691. };
  4692. }(),
  4693. equals: function ( triangle ) {
  4694. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4695. }
  4696. } );
  4697. /**
  4698. * @author mrdoob / http://mrdoob.com/
  4699. */
  4700. var ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  4701. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  4702. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  4703. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  4704. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  4705. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  4706. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  4707. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  4708. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  4709. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  4710. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  4711. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  4712. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  4713. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  4714. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  4715. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  4716. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  4717. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  4718. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  4719. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  4720. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  4721. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  4722. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  4723. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  4724. function Color( r, g, b ) {
  4725. if ( g === undefined && b === undefined ) {
  4726. // r is THREE.Color, hex or string
  4727. return this.set( r );
  4728. }
  4729. return this.setRGB( r, g, b );
  4730. }
  4731. function hue2rgb( p, q, t ) {
  4732. if ( t < 0 ) t += 1;
  4733. if ( t > 1 ) t -= 1;
  4734. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  4735. if ( t < 1 / 2 ) return q;
  4736. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  4737. return p;
  4738. }
  4739. function SRGBToLinear( c ) {
  4740. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  4741. }
  4742. function LinearToSRGB( c ) {
  4743. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  4744. }
  4745. Object.assign( Color.prototype, {
  4746. isColor: true,
  4747. r: 1, g: 1, b: 1,
  4748. set: function ( value ) {
  4749. if ( value && value.isColor ) {
  4750. this.copy( value );
  4751. } else if ( typeof value === 'number' ) {
  4752. this.setHex( value );
  4753. } else if ( typeof value === 'string' ) {
  4754. this.setStyle( value );
  4755. }
  4756. return this;
  4757. },
  4758. setScalar: function ( scalar ) {
  4759. this.r = scalar;
  4760. this.g = scalar;
  4761. this.b = scalar;
  4762. return this;
  4763. },
  4764. setHex: function ( hex ) {
  4765. hex = Math.floor( hex );
  4766. this.r = ( hex >> 16 & 255 ) / 255;
  4767. this.g = ( hex >> 8 & 255 ) / 255;
  4768. this.b = ( hex & 255 ) / 255;
  4769. return this;
  4770. },
  4771. setRGB: function ( r, g, b ) {
  4772. this.r = r;
  4773. this.g = g;
  4774. this.b = b;
  4775. return this;
  4776. },
  4777. setHSL: function ( h, s, l ) {
  4778. // h,s,l ranges are in 0.0 - 1.0
  4779. h = _Math.euclideanModulo( h, 1 );
  4780. s = _Math.clamp( s, 0, 1 );
  4781. l = _Math.clamp( l, 0, 1 );
  4782. if ( s === 0 ) {
  4783. this.r = this.g = this.b = l;
  4784. } else {
  4785. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  4786. var q = ( 2 * l ) - p;
  4787. this.r = hue2rgb( q, p, h + 1 / 3 );
  4788. this.g = hue2rgb( q, p, h );
  4789. this.b = hue2rgb( q, p, h - 1 / 3 );
  4790. }
  4791. return this;
  4792. },
  4793. setStyle: function ( style ) {
  4794. function handleAlpha( string ) {
  4795. if ( string === undefined ) return;
  4796. if ( parseFloat( string ) < 1 ) {
  4797. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  4798. }
  4799. }
  4800. var m;
  4801. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  4802. // rgb / hsl
  4803. var color;
  4804. var name = m[ 1 ];
  4805. var components = m[ 2 ];
  4806. switch ( name ) {
  4807. case 'rgb':
  4808. case 'rgba':
  4809. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4810. // rgb(255,0,0) rgba(255,0,0,0.5)
  4811. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  4812. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  4813. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  4814. handleAlpha( color[ 5 ] );
  4815. return this;
  4816. }
  4817. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4818. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  4819. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  4820. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  4821. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  4822. handleAlpha( color[ 5 ] );
  4823. return this;
  4824. }
  4825. break;
  4826. case 'hsl':
  4827. case 'hsla':
  4828. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4829. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  4830. var h = parseFloat( color[ 1 ] ) / 360;
  4831. var s = parseInt( color[ 2 ], 10 ) / 100;
  4832. var l = parseInt( color[ 3 ], 10 ) / 100;
  4833. handleAlpha( color[ 5 ] );
  4834. return this.setHSL( h, s, l );
  4835. }
  4836. break;
  4837. }
  4838. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  4839. // hex color
  4840. var hex = m[ 1 ];
  4841. var size = hex.length;
  4842. if ( size === 3 ) {
  4843. // #ff0
  4844. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  4845. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  4846. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  4847. return this;
  4848. } else if ( size === 6 ) {
  4849. // #ff0000
  4850. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  4851. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  4852. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  4853. return this;
  4854. }
  4855. }
  4856. if ( style && style.length > 0 ) {
  4857. // color keywords
  4858. var hex = ColorKeywords[ style ];
  4859. if ( hex !== undefined ) {
  4860. // red
  4861. this.setHex( hex );
  4862. } else {
  4863. // unknown color
  4864. console.warn( 'THREE.Color: Unknown color ' + style );
  4865. }
  4866. }
  4867. return this;
  4868. },
  4869. clone: function () {
  4870. return new this.constructor( this.r, this.g, this.b );
  4871. },
  4872. copy: function ( color ) {
  4873. this.r = color.r;
  4874. this.g = color.g;
  4875. this.b = color.b;
  4876. return this;
  4877. },
  4878. copyGammaToLinear: function ( color, gammaFactor ) {
  4879. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4880. this.r = Math.pow( color.r, gammaFactor );
  4881. this.g = Math.pow( color.g, gammaFactor );
  4882. this.b = Math.pow( color.b, gammaFactor );
  4883. return this;
  4884. },
  4885. copyLinearToGamma: function ( color, gammaFactor ) {
  4886. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4887. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  4888. this.r = Math.pow( color.r, safeInverse );
  4889. this.g = Math.pow( color.g, safeInverse );
  4890. this.b = Math.pow( color.b, safeInverse );
  4891. return this;
  4892. },
  4893. convertGammaToLinear: function ( gammaFactor ) {
  4894. this.copyGammaToLinear( this, gammaFactor );
  4895. return this;
  4896. },
  4897. convertLinearToGamma: function ( gammaFactor ) {
  4898. this.copyLinearToGamma( this, gammaFactor );
  4899. return this;
  4900. },
  4901. copySRGBToLinear: function ( color ) {
  4902. this.r = SRGBToLinear( color.r );
  4903. this.g = SRGBToLinear( color.g );
  4904. this.b = SRGBToLinear( color.b );
  4905. return this;
  4906. },
  4907. copyLinearToSRGB: function ( color ) {
  4908. this.r = LinearToSRGB( color.r );
  4909. this.g = LinearToSRGB( color.g );
  4910. this.b = LinearToSRGB( color.b );
  4911. return this;
  4912. },
  4913. convertSRGBToLinear: function () {
  4914. this.copySRGBToLinear( this );
  4915. return this;
  4916. },
  4917. convertLinearToSRGB: function () {
  4918. this.copyLinearToSRGB( this );
  4919. return this;
  4920. },
  4921. getHex: function () {
  4922. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  4923. },
  4924. getHexString: function () {
  4925. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  4926. },
  4927. getHSL: function ( target ) {
  4928. // h,s,l ranges are in 0.0 - 1.0
  4929. if ( target === undefined ) {
  4930. console.warn( 'THREE.Color: .getHSL() target is now required' );
  4931. target = { h: 0, s: 0, l: 0 };
  4932. }
  4933. var r = this.r, g = this.g, b = this.b;
  4934. var max = Math.max( r, g, b );
  4935. var min = Math.min( r, g, b );
  4936. var hue, saturation;
  4937. var lightness = ( min + max ) / 2.0;
  4938. if ( min === max ) {
  4939. hue = 0;
  4940. saturation = 0;
  4941. } else {
  4942. var delta = max - min;
  4943. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  4944. switch ( max ) {
  4945. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  4946. case g: hue = ( b - r ) / delta + 2; break;
  4947. case b: hue = ( r - g ) / delta + 4; break;
  4948. }
  4949. hue /= 6;
  4950. }
  4951. target.h = hue;
  4952. target.s = saturation;
  4953. target.l = lightness;
  4954. return target;
  4955. },
  4956. getStyle: function () {
  4957. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  4958. },
  4959. offsetHSL: function () {
  4960. var hsl = {};
  4961. return function ( h, s, l ) {
  4962. this.getHSL( hsl );
  4963. hsl.h += h; hsl.s += s; hsl.l += l;
  4964. this.setHSL( hsl.h, hsl.s, hsl.l );
  4965. return this;
  4966. };
  4967. }(),
  4968. add: function ( color ) {
  4969. this.r += color.r;
  4970. this.g += color.g;
  4971. this.b += color.b;
  4972. return this;
  4973. },
  4974. addColors: function ( color1, color2 ) {
  4975. this.r = color1.r + color2.r;
  4976. this.g = color1.g + color2.g;
  4977. this.b = color1.b + color2.b;
  4978. return this;
  4979. },
  4980. addScalar: function ( s ) {
  4981. this.r += s;
  4982. this.g += s;
  4983. this.b += s;
  4984. return this;
  4985. },
  4986. sub: function ( color ) {
  4987. this.r = Math.max( 0, this.r - color.r );
  4988. this.g = Math.max( 0, this.g - color.g );
  4989. this.b = Math.max( 0, this.b - color.b );
  4990. return this;
  4991. },
  4992. multiply: function ( color ) {
  4993. this.r *= color.r;
  4994. this.g *= color.g;
  4995. this.b *= color.b;
  4996. return this;
  4997. },
  4998. multiplyScalar: function ( s ) {
  4999. this.r *= s;
  5000. this.g *= s;
  5001. this.b *= s;
  5002. return this;
  5003. },
  5004. lerp: function ( color, alpha ) {
  5005. this.r += ( color.r - this.r ) * alpha;
  5006. this.g += ( color.g - this.g ) * alpha;
  5007. this.b += ( color.b - this.b ) * alpha;
  5008. return this;
  5009. },
  5010. lerpHSL: function () {
  5011. var hslA = { h: 0, s: 0, l: 0 };
  5012. var hslB = { h: 0, s: 0, l: 0 };
  5013. return function lerpHSL( color, alpha ) {
  5014. this.getHSL( hslA );
  5015. color.getHSL( hslB );
  5016. var h = _Math.lerp( hslA.h, hslB.h, alpha );
  5017. var s = _Math.lerp( hslA.s, hslB.s, alpha );
  5018. var l = _Math.lerp( hslA.l, hslB.l, alpha );
  5019. this.setHSL( h, s, l );
  5020. return this;
  5021. };
  5022. }(),
  5023. equals: function ( c ) {
  5024. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  5025. },
  5026. fromArray: function ( array, offset ) {
  5027. if ( offset === undefined ) offset = 0;
  5028. this.r = array[ offset ];
  5029. this.g = array[ offset + 1 ];
  5030. this.b = array[ offset + 2 ];
  5031. return this;
  5032. },
  5033. toArray: function ( array, offset ) {
  5034. if ( array === undefined ) array = [];
  5035. if ( offset === undefined ) offset = 0;
  5036. array[ offset ] = this.r;
  5037. array[ offset + 1 ] = this.g;
  5038. array[ offset + 2 ] = this.b;
  5039. return array;
  5040. },
  5041. toJSON: function () {
  5042. return this.getHex();
  5043. }
  5044. } );
  5045. /**
  5046. * @author mrdoob / http://mrdoob.com/
  5047. * @author alteredq / http://alteredqualia.com/
  5048. */
  5049. function Face3( a, b, c, normal, color, materialIndex ) {
  5050. this.a = a;
  5051. this.b = b;
  5052. this.c = c;
  5053. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  5054. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5055. this.color = ( color && color.isColor ) ? color : new Color();
  5056. this.vertexColors = Array.isArray( color ) ? color : [];
  5057. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5058. }
  5059. Object.assign( Face3.prototype, {
  5060. clone: function () {
  5061. return new this.constructor().copy( this );
  5062. },
  5063. copy: function ( source ) {
  5064. this.a = source.a;
  5065. this.b = source.b;
  5066. this.c = source.c;
  5067. this.normal.copy( source.normal );
  5068. this.color.copy( source.color );
  5069. this.materialIndex = source.materialIndex;
  5070. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5071. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5072. }
  5073. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5074. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5075. }
  5076. return this;
  5077. }
  5078. } );
  5079. /**
  5080. * @author mrdoob / http://mrdoob.com/
  5081. * @author alteredq / http://alteredqualia.com/
  5082. */
  5083. var materialId = 0;
  5084. function Material() {
  5085. Object.defineProperty( this, 'id', { value: materialId ++ } );
  5086. this.uuid = _Math.generateUUID();
  5087. this.name = '';
  5088. this.type = 'Material';
  5089. this.fog = true;
  5090. this.lights = true;
  5091. this.blending = NormalBlending;
  5092. this.side = FrontSide;
  5093. this.flatShading = false;
  5094. this.vertexTangents = false;
  5095. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  5096. this.opacity = 1;
  5097. this.transparent = false;
  5098. this.blendSrc = SrcAlphaFactor;
  5099. this.blendDst = OneMinusSrcAlphaFactor;
  5100. this.blendEquation = AddEquation;
  5101. this.blendSrcAlpha = null;
  5102. this.blendDstAlpha = null;
  5103. this.blendEquationAlpha = null;
  5104. this.depthFunc = LessEqualDepth;
  5105. this.depthTest = true;
  5106. this.depthWrite = true;
  5107. this.stencilFunc = AlwaysStencilFunc;
  5108. this.stencilRef = 0;
  5109. this.stencilMask = 0xff;
  5110. this.stencilFail = KeepStencilOp;
  5111. this.stencilZFail = KeepStencilOp;
  5112. this.stencilZPass = KeepStencilOp;
  5113. this.stencilWrite = false;
  5114. this.clippingPlanes = null;
  5115. this.clipIntersection = false;
  5116. this.clipShadows = false;
  5117. this.shadowSide = null;
  5118. this.colorWrite = true;
  5119. this.precision = null; // override the renderer's default precision for this material
  5120. this.polygonOffset = false;
  5121. this.polygonOffsetFactor = 0;
  5122. this.polygonOffsetUnits = 0;
  5123. this.dithering = false;
  5124. this.alphaTest = 0;
  5125. this.premultipliedAlpha = false;
  5126. this.visible = true;
  5127. this.userData = {};
  5128. this.needsUpdate = true;
  5129. }
  5130. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5131. constructor: Material,
  5132. isMaterial: true,
  5133. onBeforeCompile: function () {},
  5134. setValues: function ( values ) {
  5135. if ( values === undefined ) return;
  5136. for ( var key in values ) {
  5137. var newValue = values[ key ];
  5138. if ( newValue === undefined ) {
  5139. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  5140. continue;
  5141. }
  5142. // for backward compatability if shading is set in the constructor
  5143. if ( key === 'shading' ) {
  5144. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  5145. this.flatShading = ( newValue === FlatShading ) ? true : false;
  5146. continue;
  5147. }
  5148. var currentValue = this[ key ];
  5149. if ( currentValue === undefined ) {
  5150. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  5151. continue;
  5152. }
  5153. if ( currentValue && currentValue.isColor ) {
  5154. currentValue.set( newValue );
  5155. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  5156. currentValue.copy( newValue );
  5157. } else {
  5158. this[ key ] = newValue;
  5159. }
  5160. }
  5161. },
  5162. toJSON: function ( meta ) {
  5163. var isRoot = ( meta === undefined || typeof meta === 'string' );
  5164. if ( isRoot ) {
  5165. meta = {
  5166. textures: {},
  5167. images: {}
  5168. };
  5169. }
  5170. var data = {
  5171. metadata: {
  5172. version: 4.5,
  5173. type: 'Material',
  5174. generator: 'Material.toJSON'
  5175. }
  5176. };
  5177. // standard Material serialization
  5178. data.uuid = this.uuid;
  5179. data.type = this.type;
  5180. if ( this.name !== '' ) data.name = this.name;
  5181. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  5182. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  5183. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  5184. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  5185. if ( this.emissiveIntensity && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  5186. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  5187. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  5188. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  5189. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  5190. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  5191. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  5192. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  5193. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  5194. if ( this.aoMap && this.aoMap.isTexture ) {
  5195. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  5196. data.aoMapIntensity = this.aoMapIntensity;
  5197. }
  5198. if ( this.bumpMap && this.bumpMap.isTexture ) {
  5199. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  5200. data.bumpScale = this.bumpScale;
  5201. }
  5202. if ( this.normalMap && this.normalMap.isTexture ) {
  5203. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  5204. data.normalMapType = this.normalMapType;
  5205. data.normalScale = this.normalScale.toArray();
  5206. }
  5207. if ( this.displacementMap && this.displacementMap.isTexture ) {
  5208. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  5209. data.displacementScale = this.displacementScale;
  5210. data.displacementBias = this.displacementBias;
  5211. }
  5212. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  5213. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  5214. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  5215. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  5216. if ( this.envMap && this.envMap.isTexture ) {
  5217. data.envMap = this.envMap.toJSON( meta ).uuid;
  5218. data.reflectivity = this.reflectivity; // Scale behind envMap
  5219. data.refractionRatio = this.refractionRatio;
  5220. if ( this.combine !== undefined ) data.combine = this.combine;
  5221. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  5222. }
  5223. if ( this.gradientMap && this.gradientMap.isTexture ) {
  5224. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  5225. }
  5226. if ( this.size !== undefined ) data.size = this.size;
  5227. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  5228. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  5229. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  5230. if ( this.side !== FrontSide ) data.side = this.side;
  5231. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  5232. if ( this.opacity < 1 ) data.opacity = this.opacity;
  5233. if ( this.transparent === true ) data.transparent = this.transparent;
  5234. data.depthFunc = this.depthFunc;
  5235. data.depthTest = this.depthTest;
  5236. data.depthWrite = this.depthWrite;
  5237. data.stencilWrite = this.stencilWrite;
  5238. data.stencilFunc = this.stencilFunc;
  5239. data.stencilRef = this.stencilRef;
  5240. data.stencilMask = this.stencilMask;
  5241. data.stencilFail = this.stencilFail;
  5242. data.stencilZFail = this.stencilZFail;
  5243. data.stencilZPass = this.stencilZPass;
  5244. // rotation (SpriteMaterial)
  5245. if ( this.rotation && this.rotation !== 0 ) data.rotation = this.rotation;
  5246. if ( this.polygonOffset === true ) data.polygonOffset = true;
  5247. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5248. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5249. if ( this.linewidth && this.linewidth !== 1 ) data.linewidth = this.linewidth;
  5250. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  5251. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  5252. if ( this.scale !== undefined ) data.scale = this.scale;
  5253. if ( this.dithering === true ) data.dithering = true;
  5254. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  5255. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  5256. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  5257. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  5258. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  5259. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  5260. if ( this.morphTargets === true ) data.morphTargets = true;
  5261. if ( this.morphNormals === true ) data.morphNormals = true;
  5262. if ( this.skinning === true ) data.skinning = true;
  5263. if ( this.visible === false ) data.visible = false;
  5264. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  5265. // TODO: Copied from Object3D.toJSON
  5266. function extractFromCache( cache ) {
  5267. var values = [];
  5268. for ( var key in cache ) {
  5269. var data = cache[ key ];
  5270. delete data.metadata;
  5271. values.push( data );
  5272. }
  5273. return values;
  5274. }
  5275. if ( isRoot ) {
  5276. var textures = extractFromCache( meta.textures );
  5277. var images = extractFromCache( meta.images );
  5278. if ( textures.length > 0 ) data.textures = textures;
  5279. if ( images.length > 0 ) data.images = images;
  5280. }
  5281. return data;
  5282. },
  5283. clone: function () {
  5284. return new this.constructor().copy( this );
  5285. },
  5286. copy: function ( source ) {
  5287. this.name = source.name;
  5288. this.fog = source.fog;
  5289. this.lights = source.lights;
  5290. this.blending = source.blending;
  5291. this.side = source.side;
  5292. this.flatShading = source.flatShading;
  5293. this.vertexColors = source.vertexColors;
  5294. this.opacity = source.opacity;
  5295. this.transparent = source.transparent;
  5296. this.blendSrc = source.blendSrc;
  5297. this.blendDst = source.blendDst;
  5298. this.blendEquation = source.blendEquation;
  5299. this.blendSrcAlpha = source.blendSrcAlpha;
  5300. this.blendDstAlpha = source.blendDstAlpha;
  5301. this.blendEquationAlpha = source.blendEquationAlpha;
  5302. this.depthFunc = source.depthFunc;
  5303. this.depthTest = source.depthTest;
  5304. this.depthWrite = source.depthWrite;
  5305. this.stencilWrite = source.stencilWrite;
  5306. this.stencilFunc = source.stencilFunc;
  5307. this.stencilRef = source.stencilRef;
  5308. this.stencilMask = source.stencilMask;
  5309. this.stencilFail = source.stencilFail;
  5310. this.stencilZFail = source.stencilZFail;
  5311. this.stencilZPass = source.stencilZPass;
  5312. this.colorWrite = source.colorWrite;
  5313. this.precision = source.precision;
  5314. this.polygonOffset = source.polygonOffset;
  5315. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5316. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5317. this.dithering = source.dithering;
  5318. this.alphaTest = source.alphaTest;
  5319. this.premultipliedAlpha = source.premultipliedAlpha;
  5320. this.visible = source.visible;
  5321. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5322. this.clipShadows = source.clipShadows;
  5323. this.clipIntersection = source.clipIntersection;
  5324. var srcPlanes = source.clippingPlanes,
  5325. dstPlanes = null;
  5326. if ( srcPlanes !== null ) {
  5327. var n = srcPlanes.length;
  5328. dstPlanes = new Array( n );
  5329. for ( var i = 0; i !== n; ++ i )
  5330. dstPlanes[ i ] = srcPlanes[ i ].clone();
  5331. }
  5332. this.clippingPlanes = dstPlanes;
  5333. this.shadowSide = source.shadowSide;
  5334. return this;
  5335. },
  5336. dispose: function () {
  5337. this.dispatchEvent( { type: 'dispose' } );
  5338. }
  5339. } );
  5340. /**
  5341. * @author mrdoob / http://mrdoob.com/
  5342. * @author alteredq / http://alteredqualia.com/
  5343. *
  5344. * parameters = {
  5345. * color: <hex>,
  5346. * opacity: <float>,
  5347. * map: new THREE.Texture( <Image> ),
  5348. *
  5349. * lightMap: new THREE.Texture( <Image> ),
  5350. * lightMapIntensity: <float>
  5351. *
  5352. * aoMap: new THREE.Texture( <Image> ),
  5353. * aoMapIntensity: <float>
  5354. *
  5355. * specularMap: new THREE.Texture( <Image> ),
  5356. *
  5357. * alphaMap: new THREE.Texture( <Image> ),
  5358. *
  5359. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5360. * combine: THREE.Multiply,
  5361. * reflectivity: <float>,
  5362. * refractionRatio: <float>,
  5363. *
  5364. * depthTest: <bool>,
  5365. * depthWrite: <bool>,
  5366. *
  5367. * wireframe: <boolean>,
  5368. * wireframeLinewidth: <float>,
  5369. *
  5370. * skinning: <bool>,
  5371. * morphTargets: <bool>
  5372. * }
  5373. */
  5374. function MeshBasicMaterial( parameters ) {
  5375. Material.call( this );
  5376. this.type = 'MeshBasicMaterial';
  5377. this.color = new Color( 0xffffff ); // emissive
  5378. this.map = null;
  5379. this.lightMap = null;
  5380. this.lightMapIntensity = 1.0;
  5381. this.aoMap = null;
  5382. this.aoMapIntensity = 1.0;
  5383. this.specularMap = null;
  5384. this.alphaMap = null;
  5385. this.envMap = null;
  5386. this.combine = MultiplyOperation;
  5387. this.reflectivity = 1;
  5388. this.refractionRatio = 0.98;
  5389. this.wireframe = false;
  5390. this.wireframeLinewidth = 1;
  5391. this.wireframeLinecap = 'round';
  5392. this.wireframeLinejoin = 'round';
  5393. this.skinning = false;
  5394. this.morphTargets = false;
  5395. this.lights = false;
  5396. this.setValues( parameters );
  5397. }
  5398. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  5399. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5400. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5401. MeshBasicMaterial.prototype.copy = function ( source ) {
  5402. Material.prototype.copy.call( this, source );
  5403. this.color.copy( source.color );
  5404. this.map = source.map;
  5405. this.lightMap = source.lightMap;
  5406. this.lightMapIntensity = source.lightMapIntensity;
  5407. this.aoMap = source.aoMap;
  5408. this.aoMapIntensity = source.aoMapIntensity;
  5409. this.specularMap = source.specularMap;
  5410. this.alphaMap = source.alphaMap;
  5411. this.envMap = source.envMap;
  5412. this.combine = source.combine;
  5413. this.reflectivity = source.reflectivity;
  5414. this.refractionRatio = source.refractionRatio;
  5415. this.wireframe = source.wireframe;
  5416. this.wireframeLinewidth = source.wireframeLinewidth;
  5417. this.wireframeLinecap = source.wireframeLinecap;
  5418. this.wireframeLinejoin = source.wireframeLinejoin;
  5419. this.skinning = source.skinning;
  5420. this.morphTargets = source.morphTargets;
  5421. return this;
  5422. };
  5423. /**
  5424. * @author mrdoob / http://mrdoob.com/
  5425. */
  5426. function BufferAttribute( array, itemSize, normalized ) {
  5427. if ( Array.isArray( array ) ) {
  5428. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  5429. }
  5430. this.name = '';
  5431. this.array = array;
  5432. this.itemSize = itemSize;
  5433. this.count = array !== undefined ? array.length / itemSize : 0;
  5434. this.normalized = normalized === true;
  5435. this.dynamic = false;
  5436. this.updateRange = { offset: 0, count: - 1 };
  5437. this.version = 0;
  5438. }
  5439. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  5440. set: function ( value ) {
  5441. if ( value === true ) this.version ++;
  5442. }
  5443. } );
  5444. Object.assign( BufferAttribute.prototype, {
  5445. isBufferAttribute: true,
  5446. onUploadCallback: function () {},
  5447. setArray: function ( array ) {
  5448. if ( Array.isArray( array ) ) {
  5449. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  5450. }
  5451. this.count = array !== undefined ? array.length / this.itemSize : 0;
  5452. this.array = array;
  5453. return this;
  5454. },
  5455. setDynamic: function ( value ) {
  5456. this.dynamic = value;
  5457. return this;
  5458. },
  5459. copy: function ( source ) {
  5460. this.name = source.name;
  5461. this.array = new source.array.constructor( source.array );
  5462. this.itemSize = source.itemSize;
  5463. this.count = source.count;
  5464. this.normalized = source.normalized;
  5465. this.dynamic = source.dynamic;
  5466. return this;
  5467. },
  5468. copyAt: function ( index1, attribute, index2 ) {
  5469. index1 *= this.itemSize;
  5470. index2 *= attribute.itemSize;
  5471. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5472. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5473. }
  5474. return this;
  5475. },
  5476. copyArray: function ( array ) {
  5477. this.array.set( array );
  5478. return this;
  5479. },
  5480. copyColorsArray: function ( colors ) {
  5481. var array = this.array, offset = 0;
  5482. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5483. var color = colors[ i ];
  5484. if ( color === undefined ) {
  5485. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5486. color = new Color();
  5487. }
  5488. array[ offset ++ ] = color.r;
  5489. array[ offset ++ ] = color.g;
  5490. array[ offset ++ ] = color.b;
  5491. }
  5492. return this;
  5493. },
  5494. copyVector2sArray: function ( vectors ) {
  5495. var array = this.array, offset = 0;
  5496. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5497. var vector = vectors[ i ];
  5498. if ( vector === undefined ) {
  5499. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5500. vector = new Vector2();
  5501. }
  5502. array[ offset ++ ] = vector.x;
  5503. array[ offset ++ ] = vector.y;
  5504. }
  5505. return this;
  5506. },
  5507. copyVector3sArray: function ( vectors ) {
  5508. var array = this.array, offset = 0;
  5509. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5510. var vector = vectors[ i ];
  5511. if ( vector === undefined ) {
  5512. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5513. vector = new Vector3();
  5514. }
  5515. array[ offset ++ ] = vector.x;
  5516. array[ offset ++ ] = vector.y;
  5517. array[ offset ++ ] = vector.z;
  5518. }
  5519. return this;
  5520. },
  5521. copyVector4sArray: function ( vectors ) {
  5522. var array = this.array, offset = 0;
  5523. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5524. var vector = vectors[ i ];
  5525. if ( vector === undefined ) {
  5526. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5527. vector = new Vector4();
  5528. }
  5529. array[ offset ++ ] = vector.x;
  5530. array[ offset ++ ] = vector.y;
  5531. array[ offset ++ ] = vector.z;
  5532. array[ offset ++ ] = vector.w;
  5533. }
  5534. return this;
  5535. },
  5536. set: function ( value, offset ) {
  5537. if ( offset === undefined ) offset = 0;
  5538. this.array.set( value, offset );
  5539. return this;
  5540. },
  5541. getX: function ( index ) {
  5542. return this.array[ index * this.itemSize ];
  5543. },
  5544. setX: function ( index, x ) {
  5545. this.array[ index * this.itemSize ] = x;
  5546. return this;
  5547. },
  5548. getY: function ( index ) {
  5549. return this.array[ index * this.itemSize + 1 ];
  5550. },
  5551. setY: function ( index, y ) {
  5552. this.array[ index * this.itemSize + 1 ] = y;
  5553. return this;
  5554. },
  5555. getZ: function ( index ) {
  5556. return this.array[ index * this.itemSize + 2 ];
  5557. },
  5558. setZ: function ( index, z ) {
  5559. this.array[ index * this.itemSize + 2 ] = z;
  5560. return this;
  5561. },
  5562. getW: function ( index ) {
  5563. return this.array[ index * this.itemSize + 3 ];
  5564. },
  5565. setW: function ( index, w ) {
  5566. this.array[ index * this.itemSize + 3 ] = w;
  5567. return this;
  5568. },
  5569. setXY: function ( index, x, y ) {
  5570. index *= this.itemSize;
  5571. this.array[ index + 0 ] = x;
  5572. this.array[ index + 1 ] = y;
  5573. return this;
  5574. },
  5575. setXYZ: function ( index, x, y, z ) {
  5576. index *= this.itemSize;
  5577. this.array[ index + 0 ] = x;
  5578. this.array[ index + 1 ] = y;
  5579. this.array[ index + 2 ] = z;
  5580. return this;
  5581. },
  5582. setXYZW: function ( index, x, y, z, w ) {
  5583. index *= this.itemSize;
  5584. this.array[ index + 0 ] = x;
  5585. this.array[ index + 1 ] = y;
  5586. this.array[ index + 2 ] = z;
  5587. this.array[ index + 3 ] = w;
  5588. return this;
  5589. },
  5590. onUpload: function ( callback ) {
  5591. this.onUploadCallback = callback;
  5592. return this;
  5593. },
  5594. clone: function () {
  5595. return new this.constructor( this.array, this.itemSize ).copy( this );
  5596. },
  5597. toJSON: function () {
  5598. return {
  5599. itemSize: this.itemSize,
  5600. type: this.array.constructor.name,
  5601. array: Array.prototype.slice.call( this.array ),
  5602. normalized: this.normalized
  5603. };
  5604. }
  5605. } );
  5606. //
  5607. function Int8BufferAttribute( array, itemSize, normalized ) {
  5608. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  5609. }
  5610. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5611. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  5612. function Uint8BufferAttribute( array, itemSize, normalized ) {
  5613. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  5614. }
  5615. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5616. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  5617. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  5618. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  5619. }
  5620. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5621. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  5622. function Int16BufferAttribute( array, itemSize, normalized ) {
  5623. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  5624. }
  5625. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5626. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  5627. function Uint16BufferAttribute( array, itemSize, normalized ) {
  5628. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  5629. }
  5630. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5631. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  5632. function Int32BufferAttribute( array, itemSize, normalized ) {
  5633. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  5634. }
  5635. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5636. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  5637. function Uint32BufferAttribute( array, itemSize, normalized ) {
  5638. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  5639. }
  5640. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5641. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  5642. function Float32BufferAttribute( array, itemSize, normalized ) {
  5643. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  5644. }
  5645. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5646. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  5647. function Float64BufferAttribute( array, itemSize, normalized ) {
  5648. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  5649. }
  5650. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5651. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  5652. /**
  5653. * @author mrdoob / http://mrdoob.com/
  5654. */
  5655. function DirectGeometry() {
  5656. this.vertices = [];
  5657. this.normals = [];
  5658. this.colors = [];
  5659. this.uvs = [];
  5660. this.uvs2 = [];
  5661. this.groups = [];
  5662. this.morphTargets = {};
  5663. this.skinWeights = [];
  5664. this.skinIndices = [];
  5665. // this.lineDistances = [];
  5666. this.boundingBox = null;
  5667. this.boundingSphere = null;
  5668. // update flags
  5669. this.verticesNeedUpdate = false;
  5670. this.normalsNeedUpdate = false;
  5671. this.colorsNeedUpdate = false;
  5672. this.uvsNeedUpdate = false;
  5673. this.groupsNeedUpdate = false;
  5674. }
  5675. Object.assign( DirectGeometry.prototype, {
  5676. computeGroups: function ( geometry ) {
  5677. var group;
  5678. var groups = [];
  5679. var materialIndex = undefined;
  5680. var faces = geometry.faces;
  5681. for ( var i = 0; i < faces.length; i ++ ) {
  5682. var face = faces[ i ];
  5683. // materials
  5684. if ( face.materialIndex !== materialIndex ) {
  5685. materialIndex = face.materialIndex;
  5686. if ( group !== undefined ) {
  5687. group.count = ( i * 3 ) - group.start;
  5688. groups.push( group );
  5689. }
  5690. group = {
  5691. start: i * 3,
  5692. materialIndex: materialIndex
  5693. };
  5694. }
  5695. }
  5696. if ( group !== undefined ) {
  5697. group.count = ( i * 3 ) - group.start;
  5698. groups.push( group );
  5699. }
  5700. this.groups = groups;
  5701. },
  5702. fromGeometry: function ( geometry ) {
  5703. var faces = geometry.faces;
  5704. var vertices = geometry.vertices;
  5705. var faceVertexUvs = geometry.faceVertexUvs;
  5706. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  5707. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  5708. // morphs
  5709. var morphTargets = geometry.morphTargets;
  5710. var morphTargetsLength = morphTargets.length;
  5711. var morphTargetsPosition;
  5712. if ( morphTargetsLength > 0 ) {
  5713. morphTargetsPosition = [];
  5714. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  5715. morphTargetsPosition[ i ] = {
  5716. name: morphTargets[ i ].name,
  5717. data: []
  5718. };
  5719. }
  5720. this.morphTargets.position = morphTargetsPosition;
  5721. }
  5722. var morphNormals = geometry.morphNormals;
  5723. var morphNormalsLength = morphNormals.length;
  5724. var morphTargetsNormal;
  5725. if ( morphNormalsLength > 0 ) {
  5726. morphTargetsNormal = [];
  5727. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  5728. morphTargetsNormal[ i ] = {
  5729. name: morphNormals[ i ].name,
  5730. data: []
  5731. };
  5732. }
  5733. this.morphTargets.normal = morphTargetsNormal;
  5734. }
  5735. // skins
  5736. var skinIndices = geometry.skinIndices;
  5737. var skinWeights = geometry.skinWeights;
  5738. var hasSkinIndices = skinIndices.length === vertices.length;
  5739. var hasSkinWeights = skinWeights.length === vertices.length;
  5740. //
  5741. if ( vertices.length > 0 && faces.length === 0 ) {
  5742. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  5743. }
  5744. for ( var i = 0; i < faces.length; i ++ ) {
  5745. var face = faces[ i ];
  5746. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  5747. var vertexNormals = face.vertexNormals;
  5748. if ( vertexNormals.length === 3 ) {
  5749. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  5750. } else {
  5751. var normal = face.normal;
  5752. this.normals.push( normal, normal, normal );
  5753. }
  5754. var vertexColors = face.vertexColors;
  5755. if ( vertexColors.length === 3 ) {
  5756. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  5757. } else {
  5758. var color = face.color;
  5759. this.colors.push( color, color, color );
  5760. }
  5761. if ( hasFaceVertexUv === true ) {
  5762. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  5763. if ( vertexUvs !== undefined ) {
  5764. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5765. } else {
  5766. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  5767. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  5768. }
  5769. }
  5770. if ( hasFaceVertexUv2 === true ) {
  5771. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  5772. if ( vertexUvs !== undefined ) {
  5773. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5774. } else {
  5775. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  5776. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  5777. }
  5778. }
  5779. // morphs
  5780. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  5781. var morphTarget = morphTargets[ j ].vertices;
  5782. morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  5783. }
  5784. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  5785. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  5786. morphTargetsNormal[ j ].data.push( morphNormal.a, morphNormal.b, morphNormal.c );
  5787. }
  5788. // skins
  5789. if ( hasSkinIndices ) {
  5790. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  5791. }
  5792. if ( hasSkinWeights ) {
  5793. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  5794. }
  5795. }
  5796. this.computeGroups( geometry );
  5797. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  5798. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  5799. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  5800. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  5801. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  5802. if ( geometry.boundingSphere !== null ) {
  5803. this.boundingSphere = geometry.boundingSphere.clone();
  5804. }
  5805. if ( geometry.boundingBox !== null ) {
  5806. this.boundingBox = geometry.boundingBox.clone();
  5807. }
  5808. return this;
  5809. }
  5810. } );
  5811. /**
  5812. * @author mrdoob / http://mrdoob.com/
  5813. */
  5814. function arrayMax( array ) {
  5815. if ( array.length === 0 ) return - Infinity;
  5816. var max = array[ 0 ];
  5817. for ( var i = 1, l = array.length; i < l; ++ i ) {
  5818. if ( array[ i ] > max ) max = array[ i ];
  5819. }
  5820. return max;
  5821. }
  5822. /**
  5823. * @author alteredq / http://alteredqualia.com/
  5824. * @author mrdoob / http://mrdoob.com/
  5825. */
  5826. var bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  5827. function BufferGeometry() {
  5828. Object.defineProperty( this, 'id', { value: bufferGeometryId += 2 } );
  5829. this.uuid = _Math.generateUUID();
  5830. this.name = '';
  5831. this.type = 'BufferGeometry';
  5832. this.index = null;
  5833. this.attributes = {};
  5834. this.morphAttributes = {};
  5835. this.groups = [];
  5836. this.boundingBox = null;
  5837. this.boundingSphere = null;
  5838. this.drawRange = { start: 0, count: Infinity };
  5839. this.userData = {};
  5840. }
  5841. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5842. constructor: BufferGeometry,
  5843. isBufferGeometry: true,
  5844. getIndex: function () {
  5845. return this.index;
  5846. },
  5847. setIndex: function ( index ) {
  5848. if ( Array.isArray( index ) ) {
  5849. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  5850. } else {
  5851. this.index = index;
  5852. }
  5853. },
  5854. addAttribute: function ( name, attribute ) {
  5855. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  5856. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  5857. return this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  5858. }
  5859. if ( name === 'index' ) {
  5860. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  5861. this.setIndex( attribute );
  5862. return this;
  5863. }
  5864. this.attributes[ name ] = attribute;
  5865. return this;
  5866. },
  5867. getAttribute: function ( name ) {
  5868. return this.attributes[ name ];
  5869. },
  5870. removeAttribute: function ( name ) {
  5871. delete this.attributes[ name ];
  5872. return this;
  5873. },
  5874. addGroup: function ( start, count, materialIndex ) {
  5875. this.groups.push( {
  5876. start: start,
  5877. count: count,
  5878. materialIndex: materialIndex !== undefined ? materialIndex : 0
  5879. } );
  5880. },
  5881. clearGroups: function () {
  5882. this.groups = [];
  5883. },
  5884. setDrawRange: function ( start, count ) {
  5885. this.drawRange.start = start;
  5886. this.drawRange.count = count;
  5887. },
  5888. applyMatrix: function ( matrix ) {
  5889. var position = this.attributes.position;
  5890. if ( position !== undefined ) {
  5891. matrix.applyToBufferAttribute( position );
  5892. position.needsUpdate = true;
  5893. }
  5894. var normal = this.attributes.normal;
  5895. if ( normal !== undefined ) {
  5896. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5897. normalMatrix.applyToBufferAttribute( normal );
  5898. normal.needsUpdate = true;
  5899. }
  5900. var tangent = this.attributes.tangent;
  5901. if ( tangent !== undefined ) {
  5902. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5903. // Tangent is vec4, but the '.w' component is a sign value (+1/-1).
  5904. normalMatrix.applyToBufferAttribute( tangent );
  5905. tangent.needsUpdate = true;
  5906. }
  5907. if ( this.boundingBox !== null ) {
  5908. this.computeBoundingBox();
  5909. }
  5910. if ( this.boundingSphere !== null ) {
  5911. this.computeBoundingSphere();
  5912. }
  5913. return this;
  5914. },
  5915. rotateX: function () {
  5916. // rotate geometry around world x-axis
  5917. var m1 = new Matrix4();
  5918. return function rotateX( angle ) {
  5919. m1.makeRotationX( angle );
  5920. this.applyMatrix( m1 );
  5921. return this;
  5922. };
  5923. }(),
  5924. rotateY: function () {
  5925. // rotate geometry around world y-axis
  5926. var m1 = new Matrix4();
  5927. return function rotateY( angle ) {
  5928. m1.makeRotationY( angle );
  5929. this.applyMatrix( m1 );
  5930. return this;
  5931. };
  5932. }(),
  5933. rotateZ: function () {
  5934. // rotate geometry around world z-axis
  5935. var m1 = new Matrix4();
  5936. return function rotateZ( angle ) {
  5937. m1.makeRotationZ( angle );
  5938. this.applyMatrix( m1 );
  5939. return this;
  5940. };
  5941. }(),
  5942. translate: function () {
  5943. // translate geometry
  5944. var m1 = new Matrix4();
  5945. return function translate( x, y, z ) {
  5946. m1.makeTranslation( x, y, z );
  5947. this.applyMatrix( m1 );
  5948. return this;
  5949. };
  5950. }(),
  5951. scale: function () {
  5952. // scale geometry
  5953. var m1 = new Matrix4();
  5954. return function scale( x, y, z ) {
  5955. m1.makeScale( x, y, z );
  5956. this.applyMatrix( m1 );
  5957. return this;
  5958. };
  5959. }(),
  5960. lookAt: function () {
  5961. var obj = new Object3D();
  5962. return function lookAt( vector ) {
  5963. obj.lookAt( vector );
  5964. obj.updateMatrix();
  5965. this.applyMatrix( obj.matrix );
  5966. };
  5967. }(),
  5968. center: function () {
  5969. var offset = new Vector3();
  5970. return function center() {
  5971. this.computeBoundingBox();
  5972. this.boundingBox.getCenter( offset ).negate();
  5973. this.translate( offset.x, offset.y, offset.z );
  5974. return this;
  5975. };
  5976. }(),
  5977. setFromObject: function ( object ) {
  5978. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  5979. var geometry = object.geometry;
  5980. if ( object.isPoints || object.isLine ) {
  5981. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  5982. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  5983. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  5984. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  5985. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  5986. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  5987. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  5988. }
  5989. if ( geometry.boundingSphere !== null ) {
  5990. this.boundingSphere = geometry.boundingSphere.clone();
  5991. }
  5992. if ( geometry.boundingBox !== null ) {
  5993. this.boundingBox = geometry.boundingBox.clone();
  5994. }
  5995. } else if ( object.isMesh ) {
  5996. if ( geometry && geometry.isGeometry ) {
  5997. this.fromGeometry( geometry );
  5998. }
  5999. }
  6000. return this;
  6001. },
  6002. setFromPoints: function ( points ) {
  6003. var position = [];
  6004. for ( var i = 0, l = points.length; i < l; i ++ ) {
  6005. var point = points[ i ];
  6006. position.push( point.x, point.y, point.z || 0 );
  6007. }
  6008. this.addAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6009. return this;
  6010. },
  6011. updateFromObject: function ( object ) {
  6012. var geometry = object.geometry;
  6013. if ( object.isMesh ) {
  6014. var direct = geometry.__directGeometry;
  6015. if ( geometry.elementsNeedUpdate === true ) {
  6016. direct = undefined;
  6017. geometry.elementsNeedUpdate = false;
  6018. }
  6019. if ( direct === undefined ) {
  6020. return this.fromGeometry( geometry );
  6021. }
  6022. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6023. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6024. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6025. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6026. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6027. geometry.verticesNeedUpdate = false;
  6028. geometry.normalsNeedUpdate = false;
  6029. geometry.colorsNeedUpdate = false;
  6030. geometry.uvsNeedUpdate = false;
  6031. geometry.groupsNeedUpdate = false;
  6032. geometry = direct;
  6033. }
  6034. var attribute;
  6035. if ( geometry.verticesNeedUpdate === true ) {
  6036. attribute = this.attributes.position;
  6037. if ( attribute !== undefined ) {
  6038. attribute.copyVector3sArray( geometry.vertices );
  6039. attribute.needsUpdate = true;
  6040. }
  6041. geometry.verticesNeedUpdate = false;
  6042. }
  6043. if ( geometry.normalsNeedUpdate === true ) {
  6044. attribute = this.attributes.normal;
  6045. if ( attribute !== undefined ) {
  6046. attribute.copyVector3sArray( geometry.normals );
  6047. attribute.needsUpdate = true;
  6048. }
  6049. geometry.normalsNeedUpdate = false;
  6050. }
  6051. if ( geometry.colorsNeedUpdate === true ) {
  6052. attribute = this.attributes.color;
  6053. if ( attribute !== undefined ) {
  6054. attribute.copyColorsArray( geometry.colors );
  6055. attribute.needsUpdate = true;
  6056. }
  6057. geometry.colorsNeedUpdate = false;
  6058. }
  6059. if ( geometry.uvsNeedUpdate ) {
  6060. attribute = this.attributes.uv;
  6061. if ( attribute !== undefined ) {
  6062. attribute.copyVector2sArray( geometry.uvs );
  6063. attribute.needsUpdate = true;
  6064. }
  6065. geometry.uvsNeedUpdate = false;
  6066. }
  6067. if ( geometry.lineDistancesNeedUpdate ) {
  6068. attribute = this.attributes.lineDistance;
  6069. if ( attribute !== undefined ) {
  6070. attribute.copyArray( geometry.lineDistances );
  6071. attribute.needsUpdate = true;
  6072. }
  6073. geometry.lineDistancesNeedUpdate = false;
  6074. }
  6075. if ( geometry.groupsNeedUpdate ) {
  6076. geometry.computeGroups( object.geometry );
  6077. this.groups = geometry.groups;
  6078. geometry.groupsNeedUpdate = false;
  6079. }
  6080. return this;
  6081. },
  6082. fromGeometry: function ( geometry ) {
  6083. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6084. return this.fromDirectGeometry( geometry.__directGeometry );
  6085. },
  6086. fromDirectGeometry: function ( geometry ) {
  6087. var positions = new Float32Array( geometry.vertices.length * 3 );
  6088. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6089. if ( geometry.normals.length > 0 ) {
  6090. var normals = new Float32Array( geometry.normals.length * 3 );
  6091. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6092. }
  6093. if ( geometry.colors.length > 0 ) {
  6094. var colors = new Float32Array( geometry.colors.length * 3 );
  6095. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6096. }
  6097. if ( geometry.uvs.length > 0 ) {
  6098. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6099. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6100. }
  6101. if ( geometry.uvs2.length > 0 ) {
  6102. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6103. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6104. }
  6105. // groups
  6106. this.groups = geometry.groups;
  6107. // morphs
  6108. for ( var name in geometry.morphTargets ) {
  6109. var array = [];
  6110. var morphTargets = geometry.morphTargets[ name ];
  6111. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6112. var morphTarget = morphTargets[ i ];
  6113. var attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 );
  6114. attribute.name = morphTarget.name;
  6115. array.push( attribute.copyVector3sArray( morphTarget.data ) );
  6116. }
  6117. this.morphAttributes[ name ] = array;
  6118. }
  6119. // skinning
  6120. if ( geometry.skinIndices.length > 0 ) {
  6121. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6122. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6123. }
  6124. if ( geometry.skinWeights.length > 0 ) {
  6125. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6126. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6127. }
  6128. //
  6129. if ( geometry.boundingSphere !== null ) {
  6130. this.boundingSphere = geometry.boundingSphere.clone();
  6131. }
  6132. if ( geometry.boundingBox !== null ) {
  6133. this.boundingBox = geometry.boundingBox.clone();
  6134. }
  6135. return this;
  6136. },
  6137. computeBoundingBox: function () {
  6138. var box = new Box3();
  6139. return function computeBoundingBox() {
  6140. if ( this.boundingBox === null ) {
  6141. this.boundingBox = new Box3();
  6142. }
  6143. var position = this.attributes.position;
  6144. var morphAttributesPosition = this.morphAttributes.position;
  6145. if ( position !== undefined ) {
  6146. this.boundingBox.setFromBufferAttribute( position );
  6147. // process morph attributes if present
  6148. if ( morphAttributesPosition ) {
  6149. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6150. var morphAttribute = morphAttributesPosition[ i ];
  6151. box.setFromBufferAttribute( morphAttribute );
  6152. this.boundingBox.expandByPoint( box.min );
  6153. this.boundingBox.expandByPoint( box.max );
  6154. }
  6155. }
  6156. } else {
  6157. this.boundingBox.makeEmpty();
  6158. }
  6159. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6160. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6161. }
  6162. };
  6163. }(),
  6164. computeBoundingSphere: function () {
  6165. var box = new Box3();
  6166. var boxMorphTargets = new Box3();
  6167. var vector = new Vector3();
  6168. return function computeBoundingSphere() {
  6169. if ( this.boundingSphere === null ) {
  6170. this.boundingSphere = new Sphere();
  6171. }
  6172. var position = this.attributes.position;
  6173. var morphAttributesPosition = this.morphAttributes.position;
  6174. if ( position ) {
  6175. // first, find the center of the bounding sphere
  6176. var center = this.boundingSphere.center;
  6177. box.setFromBufferAttribute( position );
  6178. // process morph attributes if present
  6179. if ( morphAttributesPosition ) {
  6180. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6181. var morphAttribute = morphAttributesPosition[ i ];
  6182. boxMorphTargets.setFromBufferAttribute( morphAttribute );
  6183. box.expandByPoint( boxMorphTargets.min );
  6184. box.expandByPoint( boxMorphTargets.max );
  6185. }
  6186. }
  6187. box.getCenter( center );
  6188. // second, try to find a boundingSphere with a radius smaller than the
  6189. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6190. var maxRadiusSq = 0;
  6191. for ( var i = 0, il = position.count; i < il; i ++ ) {
  6192. vector.fromBufferAttribute( position, i );
  6193. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6194. }
  6195. // process morph attributes if present
  6196. if ( morphAttributesPosition ) {
  6197. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6198. var morphAttribute = morphAttributesPosition[ i ];
  6199. for ( var j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  6200. vector.fromBufferAttribute( morphAttribute, j );
  6201. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6202. }
  6203. }
  6204. }
  6205. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6206. if ( isNaN( this.boundingSphere.radius ) ) {
  6207. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6208. }
  6209. }
  6210. };
  6211. }(),
  6212. computeFaceNormals: function () {
  6213. // backwards compatibility
  6214. },
  6215. computeVertexNormals: function () {
  6216. var index = this.index;
  6217. var attributes = this.attributes;
  6218. if ( attributes.position ) {
  6219. var positions = attributes.position.array;
  6220. if ( attributes.normal === undefined ) {
  6221. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6222. } else {
  6223. // reset existing normals to zero
  6224. var array = attributes.normal.array;
  6225. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6226. array[ i ] = 0;
  6227. }
  6228. }
  6229. var normals = attributes.normal.array;
  6230. var vA, vB, vC;
  6231. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6232. var cb = new Vector3(), ab = new Vector3();
  6233. // indexed elements
  6234. if ( index ) {
  6235. var indices = index.array;
  6236. for ( var i = 0, il = index.count; i < il; i += 3 ) {
  6237. vA = indices[ i + 0 ] * 3;
  6238. vB = indices[ i + 1 ] * 3;
  6239. vC = indices[ i + 2 ] * 3;
  6240. pA.fromArray( positions, vA );
  6241. pB.fromArray( positions, vB );
  6242. pC.fromArray( positions, vC );
  6243. cb.subVectors( pC, pB );
  6244. ab.subVectors( pA, pB );
  6245. cb.cross( ab );
  6246. normals[ vA ] += cb.x;
  6247. normals[ vA + 1 ] += cb.y;
  6248. normals[ vA + 2 ] += cb.z;
  6249. normals[ vB ] += cb.x;
  6250. normals[ vB + 1 ] += cb.y;
  6251. normals[ vB + 2 ] += cb.z;
  6252. normals[ vC ] += cb.x;
  6253. normals[ vC + 1 ] += cb.y;
  6254. normals[ vC + 2 ] += cb.z;
  6255. }
  6256. } else {
  6257. // non-indexed elements (unconnected triangle soup)
  6258. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6259. pA.fromArray( positions, i );
  6260. pB.fromArray( positions, i + 3 );
  6261. pC.fromArray( positions, i + 6 );
  6262. cb.subVectors( pC, pB );
  6263. ab.subVectors( pA, pB );
  6264. cb.cross( ab );
  6265. normals[ i ] = cb.x;
  6266. normals[ i + 1 ] = cb.y;
  6267. normals[ i + 2 ] = cb.z;
  6268. normals[ i + 3 ] = cb.x;
  6269. normals[ i + 4 ] = cb.y;
  6270. normals[ i + 5 ] = cb.z;
  6271. normals[ i + 6 ] = cb.x;
  6272. normals[ i + 7 ] = cb.y;
  6273. normals[ i + 8 ] = cb.z;
  6274. }
  6275. }
  6276. this.normalizeNormals();
  6277. attributes.normal.needsUpdate = true;
  6278. }
  6279. },
  6280. merge: function ( geometry, offset ) {
  6281. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  6282. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6283. return;
  6284. }
  6285. if ( offset === undefined ) {
  6286. offset = 0;
  6287. console.warn(
  6288. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  6289. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  6290. );
  6291. }
  6292. var attributes = this.attributes;
  6293. for ( var key in attributes ) {
  6294. if ( geometry.attributes[ key ] === undefined ) continue;
  6295. var attribute1 = attributes[ key ];
  6296. var attributeArray1 = attribute1.array;
  6297. var attribute2 = geometry.attributes[ key ];
  6298. var attributeArray2 = attribute2.array;
  6299. var attributeOffset = attribute2.itemSize * offset;
  6300. var length = Math.min( attributeArray2.length, attributeArray1.length - attributeOffset );
  6301. for ( var i = 0, j = attributeOffset; i < length; i ++, j ++ ) {
  6302. attributeArray1[ j ] = attributeArray2[ i ];
  6303. }
  6304. }
  6305. return this;
  6306. },
  6307. normalizeNormals: function () {
  6308. var vector = new Vector3();
  6309. return function normalizeNormals() {
  6310. var normals = this.attributes.normal;
  6311. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  6312. vector.x = normals.getX( i );
  6313. vector.y = normals.getY( i );
  6314. vector.z = normals.getZ( i );
  6315. vector.normalize();
  6316. normals.setXYZ( i, vector.x, vector.y, vector.z );
  6317. }
  6318. };
  6319. }(),
  6320. toNonIndexed: function () {
  6321. function convertBufferAttribute( attribute, indices ) {
  6322. var array = attribute.array;
  6323. var itemSize = attribute.itemSize;
  6324. var array2 = new array.constructor( indices.length * itemSize );
  6325. var index = 0, index2 = 0;
  6326. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  6327. index = indices[ i ] * itemSize;
  6328. for ( var j = 0; j < itemSize; j ++ ) {
  6329. array2[ index2 ++ ] = array[ index ++ ];
  6330. }
  6331. }
  6332. return new BufferAttribute( array2, itemSize );
  6333. }
  6334. //
  6335. if ( this.index === null ) {
  6336. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  6337. return this;
  6338. }
  6339. var geometry2 = new BufferGeometry();
  6340. var indices = this.index.array;
  6341. var attributes = this.attributes;
  6342. // attributes
  6343. for ( var name in attributes ) {
  6344. var attribute = attributes[ name ];
  6345. var newAttribute = convertBufferAttribute( attribute, indices );
  6346. geometry2.addAttribute( name, newAttribute );
  6347. }
  6348. // morph attributes
  6349. var morphAttributes = this.morphAttributes;
  6350. for ( name in morphAttributes ) {
  6351. var morphArray = [];
  6352. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6353. for ( var i = 0, il = morphAttribute.length; i < il; i ++ ) {
  6354. var attribute = morphAttribute[ i ];
  6355. var newAttribute = convertBufferAttribute( attribute, indices );
  6356. morphArray.push( newAttribute );
  6357. }
  6358. geometry2.morphAttributes[ name ] = morphArray;
  6359. }
  6360. // groups
  6361. var groups = this.groups;
  6362. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  6363. var group = groups[ i ];
  6364. geometry2.addGroup( group.start, group.count, group.materialIndex );
  6365. }
  6366. return geometry2;
  6367. },
  6368. toJSON: function () {
  6369. var data = {
  6370. metadata: {
  6371. version: 4.5,
  6372. type: 'BufferGeometry',
  6373. generator: 'BufferGeometry.toJSON'
  6374. }
  6375. };
  6376. // standard BufferGeometry serialization
  6377. data.uuid = this.uuid;
  6378. data.type = this.type;
  6379. if ( this.name !== '' ) data.name = this.name;
  6380. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  6381. if ( this.parameters !== undefined ) {
  6382. var parameters = this.parameters;
  6383. for ( var key in parameters ) {
  6384. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6385. }
  6386. return data;
  6387. }
  6388. data.data = { attributes: {} };
  6389. var index = this.index;
  6390. if ( index !== null ) {
  6391. data.data.index = {
  6392. type: index.array.constructor.name,
  6393. array: Array.prototype.slice.call( index.array )
  6394. };
  6395. }
  6396. var attributes = this.attributes;
  6397. for ( var key in attributes ) {
  6398. var attribute = attributes[ key ];
  6399. var attributeData = attribute.toJSON();
  6400. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6401. data.data.attributes[ key ] = attributeData;
  6402. }
  6403. var morphAttributes = {};
  6404. var hasMorphAttributes = false;
  6405. for ( var key in this.morphAttributes ) {
  6406. var attributeArray = this.morphAttributes[ key ];
  6407. var array = [];
  6408. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  6409. var attribute = attributeArray[ i ];
  6410. var attributeData = attribute.toJSON();
  6411. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6412. array.push( attributeData );
  6413. }
  6414. if ( array.length > 0 ) {
  6415. morphAttributes[ key ] = array;
  6416. hasMorphAttributes = true;
  6417. }
  6418. }
  6419. if ( hasMorphAttributes ) data.data.morphAttributes = morphAttributes;
  6420. var groups = this.groups;
  6421. if ( groups.length > 0 ) {
  6422. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6423. }
  6424. var boundingSphere = this.boundingSphere;
  6425. if ( boundingSphere !== null ) {
  6426. data.data.boundingSphere = {
  6427. center: boundingSphere.center.toArray(),
  6428. radius: boundingSphere.radius
  6429. };
  6430. }
  6431. return data;
  6432. },
  6433. clone: function () {
  6434. /*
  6435. // Handle primitives
  6436. var parameters = this.parameters;
  6437. if ( parameters !== undefined ) {
  6438. var values = [];
  6439. for ( var key in parameters ) {
  6440. values.push( parameters[ key ] );
  6441. }
  6442. var geometry = Object.create( this.constructor.prototype );
  6443. this.constructor.apply( geometry, values );
  6444. return geometry;
  6445. }
  6446. return new this.constructor().copy( this );
  6447. */
  6448. return new BufferGeometry().copy( this );
  6449. },
  6450. copy: function ( source ) {
  6451. var name, i, l;
  6452. // reset
  6453. this.index = null;
  6454. this.attributes = {};
  6455. this.morphAttributes = {};
  6456. this.groups = [];
  6457. this.boundingBox = null;
  6458. this.boundingSphere = null;
  6459. // name
  6460. this.name = source.name;
  6461. // index
  6462. var index = source.index;
  6463. if ( index !== null ) {
  6464. this.setIndex( index.clone() );
  6465. }
  6466. // attributes
  6467. var attributes = source.attributes;
  6468. for ( name in attributes ) {
  6469. var attribute = attributes[ name ];
  6470. this.addAttribute( name, attribute.clone() );
  6471. }
  6472. // morph attributes
  6473. var morphAttributes = source.morphAttributes;
  6474. for ( name in morphAttributes ) {
  6475. var array = [];
  6476. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6477. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  6478. array.push( morphAttribute[ i ].clone() );
  6479. }
  6480. this.morphAttributes[ name ] = array;
  6481. }
  6482. // groups
  6483. var groups = source.groups;
  6484. for ( i = 0, l = groups.length; i < l; i ++ ) {
  6485. var group = groups[ i ];
  6486. this.addGroup( group.start, group.count, group.materialIndex );
  6487. }
  6488. // bounding box
  6489. var boundingBox = source.boundingBox;
  6490. if ( boundingBox !== null ) {
  6491. this.boundingBox = boundingBox.clone();
  6492. }
  6493. // bounding sphere
  6494. var boundingSphere = source.boundingSphere;
  6495. if ( boundingSphere !== null ) {
  6496. this.boundingSphere = boundingSphere.clone();
  6497. }
  6498. // draw range
  6499. this.drawRange.start = source.drawRange.start;
  6500. this.drawRange.count = source.drawRange.count;
  6501. // user data
  6502. this.userData = source.userData;
  6503. return this;
  6504. },
  6505. dispose: function () {
  6506. this.dispatchEvent( { type: 'dispose' } );
  6507. }
  6508. } );
  6509. /**
  6510. * @author mrdoob / http://mrdoob.com/
  6511. * @author alteredq / http://alteredqualia.com/
  6512. * @author mikael emtinger / http://gomo.se/
  6513. * @author jonobr1 / http://jonobr1.com/
  6514. */
  6515. function Mesh( geometry, material ) {
  6516. Object3D.call( this );
  6517. this.type = 'Mesh';
  6518. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  6519. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  6520. this.drawMode = TrianglesDrawMode;
  6521. this.updateMorphTargets();
  6522. }
  6523. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  6524. constructor: Mesh,
  6525. isMesh: true,
  6526. setDrawMode: function ( value ) {
  6527. this.drawMode = value;
  6528. },
  6529. copy: function ( source ) {
  6530. Object3D.prototype.copy.call( this, source );
  6531. this.drawMode = source.drawMode;
  6532. if ( source.morphTargetInfluences !== undefined ) {
  6533. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  6534. }
  6535. if ( source.morphTargetDictionary !== undefined ) {
  6536. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  6537. }
  6538. return this;
  6539. },
  6540. updateMorphTargets: function () {
  6541. var geometry = this.geometry;
  6542. var m, ml, name;
  6543. if ( geometry.isBufferGeometry ) {
  6544. var morphAttributes = geometry.morphAttributes;
  6545. var keys = Object.keys( morphAttributes );
  6546. if ( keys.length > 0 ) {
  6547. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  6548. if ( morphAttribute !== undefined ) {
  6549. this.morphTargetInfluences = [];
  6550. this.morphTargetDictionary = {};
  6551. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  6552. name = morphAttribute[ m ].name || String( m );
  6553. this.morphTargetInfluences.push( 0 );
  6554. this.morphTargetDictionary[ name ] = m;
  6555. }
  6556. }
  6557. }
  6558. } else {
  6559. var morphTargets = geometry.morphTargets;
  6560. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  6561. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  6562. }
  6563. }
  6564. },
  6565. raycast: ( function () {
  6566. var inverseMatrix = new Matrix4();
  6567. var ray = new Ray();
  6568. var sphere = new Sphere();
  6569. var vA = new Vector3();
  6570. var vB = new Vector3();
  6571. var vC = new Vector3();
  6572. var tempA = new Vector3();
  6573. var tempB = new Vector3();
  6574. var tempC = new Vector3();
  6575. var morphA = new Vector3();
  6576. var morphB = new Vector3();
  6577. var morphC = new Vector3();
  6578. var uvA = new Vector2();
  6579. var uvB = new Vector2();
  6580. var uvC = new Vector2();
  6581. var intersectionPoint = new Vector3();
  6582. var intersectionPointWorld = new Vector3();
  6583. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  6584. var intersect;
  6585. if ( material.side === BackSide ) {
  6586. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  6587. } else {
  6588. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  6589. }
  6590. if ( intersect === null ) return null;
  6591. intersectionPointWorld.copy( point );
  6592. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  6593. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  6594. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  6595. return {
  6596. distance: distance,
  6597. point: intersectionPointWorld.clone(),
  6598. object: object
  6599. };
  6600. }
  6601. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, uv, a, b, c ) {
  6602. vA.fromBufferAttribute( position, a );
  6603. vB.fromBufferAttribute( position, b );
  6604. vC.fromBufferAttribute( position, c );
  6605. var morphInfluences = object.morphTargetInfluences;
  6606. if ( material.morphTargets && morphPosition && morphInfluences ) {
  6607. morphA.set( 0, 0, 0 );
  6608. morphB.set( 0, 0, 0 );
  6609. morphC.set( 0, 0, 0 );
  6610. for ( var i = 0, il = morphPosition.length; i < il; i ++ ) {
  6611. var influence = morphInfluences[ i ];
  6612. var morphAttribute = morphPosition[ i ];
  6613. if ( influence === 0 ) continue;
  6614. tempA.fromBufferAttribute( morphAttribute, a );
  6615. tempB.fromBufferAttribute( morphAttribute, b );
  6616. tempC.fromBufferAttribute( morphAttribute, c );
  6617. morphA.addScaledVector( tempA.sub( vA ), influence );
  6618. morphB.addScaledVector( tempB.sub( vB ), influence );
  6619. morphC.addScaledVector( tempC.sub( vC ), influence );
  6620. }
  6621. vA.add( morphA );
  6622. vB.add( morphB );
  6623. vC.add( morphC );
  6624. }
  6625. var intersection = checkIntersection( object, material, raycaster, ray, vA, vB, vC, intersectionPoint );
  6626. if ( intersection ) {
  6627. if ( uv ) {
  6628. uvA.fromBufferAttribute( uv, a );
  6629. uvB.fromBufferAttribute( uv, b );
  6630. uvC.fromBufferAttribute( uv, c );
  6631. intersection.uv = Triangle.getUV( intersectionPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() );
  6632. }
  6633. var face = new Face3( a, b, c );
  6634. Triangle.getNormal( vA, vB, vC, face.normal );
  6635. intersection.face = face;
  6636. }
  6637. return intersection;
  6638. }
  6639. return function raycast( raycaster, intersects ) {
  6640. var geometry = this.geometry;
  6641. var material = this.material;
  6642. var matrixWorld = this.matrixWorld;
  6643. if ( material === undefined ) return;
  6644. // Checking boundingSphere distance to ray
  6645. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  6646. sphere.copy( geometry.boundingSphere );
  6647. sphere.applyMatrix4( matrixWorld );
  6648. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  6649. //
  6650. inverseMatrix.getInverse( matrixWorld );
  6651. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  6652. // Check boundingBox before continuing
  6653. if ( geometry.boundingBox !== null ) {
  6654. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  6655. }
  6656. var intersection;
  6657. if ( geometry.isBufferGeometry ) {
  6658. var a, b, c;
  6659. var index = geometry.index;
  6660. var position = geometry.attributes.position;
  6661. var morphPosition = geometry.morphAttributes.position;
  6662. var uv = geometry.attributes.uv;
  6663. var groups = geometry.groups;
  6664. var drawRange = geometry.drawRange;
  6665. var i, j, il, jl;
  6666. var group, groupMaterial;
  6667. var start, end;
  6668. if ( index !== null ) {
  6669. // indexed buffer geometry
  6670. if ( Array.isArray( material ) ) {
  6671. for ( i = 0, il = groups.length; i < il; i ++ ) {
  6672. group = groups[ i ];
  6673. groupMaterial = material[ group.materialIndex ];
  6674. start = Math.max( group.start, drawRange.start );
  6675. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6676. for ( j = start, jl = end; j < jl; j += 3 ) {
  6677. a = index.getX( j );
  6678. b = index.getX( j + 1 );
  6679. c = index.getX( j + 2 );
  6680. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, morphPosition, uv, a, b, c );
  6681. if ( intersection ) {
  6682. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  6683. intersection.face.materialIndex = group.materialIndex;
  6684. intersects.push( intersection );
  6685. }
  6686. }
  6687. }
  6688. } else {
  6689. start = Math.max( 0, drawRange.start );
  6690. end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  6691. for ( i = start, il = end; i < il; i += 3 ) {
  6692. a = index.getX( i );
  6693. b = index.getX( i + 1 );
  6694. c = index.getX( i + 2 );
  6695. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, morphPosition, uv, a, b, c );
  6696. if ( intersection ) {
  6697. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  6698. intersects.push( intersection );
  6699. }
  6700. }
  6701. }
  6702. } else if ( position !== undefined ) {
  6703. // non-indexed buffer geometry
  6704. if ( Array.isArray( material ) ) {
  6705. for ( i = 0, il = groups.length; i < il; i ++ ) {
  6706. group = groups[ i ];
  6707. groupMaterial = material[ group.materialIndex ];
  6708. start = Math.max( group.start, drawRange.start );
  6709. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6710. for ( j = start, jl = end; j < jl; j += 3 ) {
  6711. a = j;
  6712. b = j + 1;
  6713. c = j + 2;
  6714. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, morphPosition, uv, a, b, c );
  6715. if ( intersection ) {
  6716. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  6717. intersection.face.materialIndex = group.materialIndex;
  6718. intersects.push( intersection );
  6719. }
  6720. }
  6721. }
  6722. } else {
  6723. start = Math.max( 0, drawRange.start );
  6724. end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  6725. for ( i = start, il = end; i < il; i += 3 ) {
  6726. a = i;
  6727. b = i + 1;
  6728. c = i + 2;
  6729. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, morphPosition, uv, a, b, c );
  6730. if ( intersection ) {
  6731. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  6732. intersects.push( intersection );
  6733. }
  6734. }
  6735. }
  6736. }
  6737. } else if ( geometry.isGeometry ) {
  6738. var fvA, fvB, fvC;
  6739. var isMultiMaterial = Array.isArray( material );
  6740. var vertices = geometry.vertices;
  6741. var faces = geometry.faces;
  6742. var uvs;
  6743. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  6744. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  6745. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  6746. var face = faces[ f ];
  6747. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  6748. if ( faceMaterial === undefined ) continue;
  6749. fvA = vertices[ face.a ];
  6750. fvB = vertices[ face.b ];
  6751. fvC = vertices[ face.c ];
  6752. intersection = checkIntersection( this, faceMaterial, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  6753. if ( intersection ) {
  6754. if ( uvs && uvs[ f ] ) {
  6755. var uvs_f = uvs[ f ];
  6756. uvA.copy( uvs_f[ 0 ] );
  6757. uvB.copy( uvs_f[ 1 ] );
  6758. uvC.copy( uvs_f[ 2 ] );
  6759. intersection.uv = Triangle.getUV( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC, new Vector2() );
  6760. }
  6761. intersection.face = face;
  6762. intersection.faceIndex = f;
  6763. intersects.push( intersection );
  6764. }
  6765. }
  6766. }
  6767. };
  6768. }() ),
  6769. clone: function () {
  6770. return new this.constructor( this.geometry, this.material ).copy( this );
  6771. }
  6772. } );
  6773. /**
  6774. * @author mrdoob / http://mrdoob.com/
  6775. * @author kile / http://kile.stravaganza.org/
  6776. * @author alteredq / http://alteredqualia.com/
  6777. * @author mikael emtinger / http://gomo.se/
  6778. * @author zz85 / http://www.lab4games.net/zz85/blog
  6779. * @author bhouston / http://clara.io
  6780. */
  6781. var geometryId = 0; // Geometry uses even numbers as Id
  6782. function Geometry() {
  6783. Object.defineProperty( this, 'id', { value: geometryId += 2 } );
  6784. this.uuid = _Math.generateUUID();
  6785. this.name = '';
  6786. this.type = 'Geometry';
  6787. this.vertices = [];
  6788. this.colors = [];
  6789. this.faces = [];
  6790. this.faceVertexUvs = [[]];
  6791. this.morphTargets = [];
  6792. this.morphNormals = [];
  6793. this.skinWeights = [];
  6794. this.skinIndices = [];
  6795. this.lineDistances = [];
  6796. this.boundingBox = null;
  6797. this.boundingSphere = null;
  6798. // update flags
  6799. this.elementsNeedUpdate = false;
  6800. this.verticesNeedUpdate = false;
  6801. this.uvsNeedUpdate = false;
  6802. this.normalsNeedUpdate = false;
  6803. this.colorsNeedUpdate = false;
  6804. this.lineDistancesNeedUpdate = false;
  6805. this.groupsNeedUpdate = false;
  6806. }
  6807. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6808. constructor: Geometry,
  6809. isGeometry: true,
  6810. applyMatrix: function ( matrix ) {
  6811. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6812. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  6813. var vertex = this.vertices[ i ];
  6814. vertex.applyMatrix4( matrix );
  6815. }
  6816. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  6817. var face = this.faces[ i ];
  6818. face.normal.applyMatrix3( normalMatrix ).normalize();
  6819. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  6820. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  6821. }
  6822. }
  6823. if ( this.boundingBox !== null ) {
  6824. this.computeBoundingBox();
  6825. }
  6826. if ( this.boundingSphere !== null ) {
  6827. this.computeBoundingSphere();
  6828. }
  6829. this.verticesNeedUpdate = true;
  6830. this.normalsNeedUpdate = true;
  6831. return this;
  6832. },
  6833. rotateX: function () {
  6834. // rotate geometry around world x-axis
  6835. var m1 = new Matrix4();
  6836. return function rotateX( angle ) {
  6837. m1.makeRotationX( angle );
  6838. this.applyMatrix( m1 );
  6839. return this;
  6840. };
  6841. }(),
  6842. rotateY: function () {
  6843. // rotate geometry around world y-axis
  6844. var m1 = new Matrix4();
  6845. return function rotateY( angle ) {
  6846. m1.makeRotationY( angle );
  6847. this.applyMatrix( m1 );
  6848. return this;
  6849. };
  6850. }(),
  6851. rotateZ: function () {
  6852. // rotate geometry around world z-axis
  6853. var m1 = new Matrix4();
  6854. return function rotateZ( angle ) {
  6855. m1.makeRotationZ( angle );
  6856. this.applyMatrix( m1 );
  6857. return this;
  6858. };
  6859. }(),
  6860. translate: function () {
  6861. // translate geometry
  6862. var m1 = new Matrix4();
  6863. return function translate( x, y, z ) {
  6864. m1.makeTranslation( x, y, z );
  6865. this.applyMatrix( m1 );
  6866. return this;
  6867. };
  6868. }(),
  6869. scale: function () {
  6870. // scale geometry
  6871. var m1 = new Matrix4();
  6872. return function scale( x, y, z ) {
  6873. m1.makeScale( x, y, z );
  6874. this.applyMatrix( m1 );
  6875. return this;
  6876. };
  6877. }(),
  6878. lookAt: function () {
  6879. var obj = new Object3D();
  6880. return function lookAt( vector ) {
  6881. obj.lookAt( vector );
  6882. obj.updateMatrix();
  6883. this.applyMatrix( obj.matrix );
  6884. };
  6885. }(),
  6886. fromBufferGeometry: function ( geometry ) {
  6887. var scope = this;
  6888. var indices = geometry.index !== null ? geometry.index.array : undefined;
  6889. var attributes = geometry.attributes;
  6890. var positions = attributes.position.array;
  6891. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  6892. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  6893. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  6894. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  6895. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  6896. for ( var i = 0; i < positions.length; i += 3 ) {
  6897. scope.vertices.push( new Vector3().fromArray( positions, i ) );
  6898. if ( colors !== undefined ) {
  6899. scope.colors.push( new Color().fromArray( colors, i ) );
  6900. }
  6901. }
  6902. function addFace( a, b, c, materialIndex ) {
  6903. var vertexColors = ( colors === undefined ) ? [] : [
  6904. scope.colors[ a ].clone(),
  6905. scope.colors[ b ].clone(),
  6906. scope.colors[ c ].clone() ];
  6907. var vertexNormals = ( normals === undefined ) ? [] : [
  6908. new Vector3().fromArray( normals, a * 3 ),
  6909. new Vector3().fromArray( normals, b * 3 ),
  6910. new Vector3().fromArray( normals, c * 3 )
  6911. ];
  6912. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  6913. scope.faces.push( face );
  6914. if ( uvs !== undefined ) {
  6915. scope.faceVertexUvs[ 0 ].push( [
  6916. new Vector2().fromArray( uvs, a * 2 ),
  6917. new Vector2().fromArray( uvs, b * 2 ),
  6918. new Vector2().fromArray( uvs, c * 2 )
  6919. ] );
  6920. }
  6921. if ( uvs2 !== undefined ) {
  6922. scope.faceVertexUvs[ 1 ].push( [
  6923. new Vector2().fromArray( uvs2, a * 2 ),
  6924. new Vector2().fromArray( uvs2, b * 2 ),
  6925. new Vector2().fromArray( uvs2, c * 2 )
  6926. ] );
  6927. }
  6928. }
  6929. var groups = geometry.groups;
  6930. if ( groups.length > 0 ) {
  6931. for ( var i = 0; i < groups.length; i ++ ) {
  6932. var group = groups[ i ];
  6933. var start = group.start;
  6934. var count = group.count;
  6935. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  6936. if ( indices !== undefined ) {
  6937. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  6938. } else {
  6939. addFace( j, j + 1, j + 2, group.materialIndex );
  6940. }
  6941. }
  6942. }
  6943. } else {
  6944. if ( indices !== undefined ) {
  6945. for ( var i = 0; i < indices.length; i += 3 ) {
  6946. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  6947. }
  6948. } else {
  6949. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  6950. addFace( i, i + 1, i + 2 );
  6951. }
  6952. }
  6953. }
  6954. this.computeFaceNormals();
  6955. if ( geometry.boundingBox !== null ) {
  6956. this.boundingBox = geometry.boundingBox.clone();
  6957. }
  6958. if ( geometry.boundingSphere !== null ) {
  6959. this.boundingSphere = geometry.boundingSphere.clone();
  6960. }
  6961. return this;
  6962. },
  6963. center: function () {
  6964. var offset = new Vector3();
  6965. return function center() {
  6966. this.computeBoundingBox();
  6967. this.boundingBox.getCenter( offset ).negate();
  6968. this.translate( offset.x, offset.y, offset.z );
  6969. return this;
  6970. };
  6971. }(),
  6972. normalize: function () {
  6973. this.computeBoundingSphere();
  6974. var center = this.boundingSphere.center;
  6975. var radius = this.boundingSphere.radius;
  6976. var s = radius === 0 ? 1 : 1.0 / radius;
  6977. var matrix = new Matrix4();
  6978. matrix.set(
  6979. s, 0, 0, - s * center.x,
  6980. 0, s, 0, - s * center.y,
  6981. 0, 0, s, - s * center.z,
  6982. 0, 0, 0, 1
  6983. );
  6984. this.applyMatrix( matrix );
  6985. return this;
  6986. },
  6987. computeFaceNormals: function () {
  6988. var cb = new Vector3(), ab = new Vector3();
  6989. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6990. var face = this.faces[ f ];
  6991. var vA = this.vertices[ face.a ];
  6992. var vB = this.vertices[ face.b ];
  6993. var vC = this.vertices[ face.c ];
  6994. cb.subVectors( vC, vB );
  6995. ab.subVectors( vA, vB );
  6996. cb.cross( ab );
  6997. cb.normalize();
  6998. face.normal.copy( cb );
  6999. }
  7000. },
  7001. computeVertexNormals: function ( areaWeighted ) {
  7002. if ( areaWeighted === undefined ) areaWeighted = true;
  7003. var v, vl, f, fl, face, vertices;
  7004. vertices = new Array( this.vertices.length );
  7005. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7006. vertices[ v ] = new Vector3();
  7007. }
  7008. if ( areaWeighted ) {
  7009. // vertex normals weighted by triangle areas
  7010. // http://www.iquilezles.org/www/articles/normals/normals.htm
  7011. var vA, vB, vC;
  7012. var cb = new Vector3(), ab = new Vector3();
  7013. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7014. face = this.faces[ f ];
  7015. vA = this.vertices[ face.a ];
  7016. vB = this.vertices[ face.b ];
  7017. vC = this.vertices[ face.c ];
  7018. cb.subVectors( vC, vB );
  7019. ab.subVectors( vA, vB );
  7020. cb.cross( ab );
  7021. vertices[ face.a ].add( cb );
  7022. vertices[ face.b ].add( cb );
  7023. vertices[ face.c ].add( cb );
  7024. }
  7025. } else {
  7026. this.computeFaceNormals();
  7027. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7028. face = this.faces[ f ];
  7029. vertices[ face.a ].add( face.normal );
  7030. vertices[ face.b ].add( face.normal );
  7031. vertices[ face.c ].add( face.normal );
  7032. }
  7033. }
  7034. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7035. vertices[ v ].normalize();
  7036. }
  7037. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7038. face = this.faces[ f ];
  7039. var vertexNormals = face.vertexNormals;
  7040. if ( vertexNormals.length === 3 ) {
  7041. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  7042. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  7043. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  7044. } else {
  7045. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  7046. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  7047. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  7048. }
  7049. }
  7050. if ( this.faces.length > 0 ) {
  7051. this.normalsNeedUpdate = true;
  7052. }
  7053. },
  7054. computeFlatVertexNormals: function () {
  7055. var f, fl, face;
  7056. this.computeFaceNormals();
  7057. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7058. face = this.faces[ f ];
  7059. var vertexNormals = face.vertexNormals;
  7060. if ( vertexNormals.length === 3 ) {
  7061. vertexNormals[ 0 ].copy( face.normal );
  7062. vertexNormals[ 1 ].copy( face.normal );
  7063. vertexNormals[ 2 ].copy( face.normal );
  7064. } else {
  7065. vertexNormals[ 0 ] = face.normal.clone();
  7066. vertexNormals[ 1 ] = face.normal.clone();
  7067. vertexNormals[ 2 ] = face.normal.clone();
  7068. }
  7069. }
  7070. if ( this.faces.length > 0 ) {
  7071. this.normalsNeedUpdate = true;
  7072. }
  7073. },
  7074. computeMorphNormals: function () {
  7075. var i, il, f, fl, face;
  7076. // save original normals
  7077. // - create temp variables on first access
  7078. // otherwise just copy (for faster repeated calls)
  7079. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7080. face = this.faces[ f ];
  7081. if ( ! face.__originalFaceNormal ) {
  7082. face.__originalFaceNormal = face.normal.clone();
  7083. } else {
  7084. face.__originalFaceNormal.copy( face.normal );
  7085. }
  7086. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  7087. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  7088. if ( ! face.__originalVertexNormals[ i ] ) {
  7089. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  7090. } else {
  7091. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  7092. }
  7093. }
  7094. }
  7095. // use temp geometry to compute face and vertex normals for each morph
  7096. var tmpGeo = new Geometry();
  7097. tmpGeo.faces = this.faces;
  7098. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  7099. // create on first access
  7100. if ( ! this.morphNormals[ i ] ) {
  7101. this.morphNormals[ i ] = {};
  7102. this.morphNormals[ i ].faceNormals = [];
  7103. this.morphNormals[ i ].vertexNormals = [];
  7104. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  7105. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  7106. var faceNormal, vertexNormals;
  7107. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7108. faceNormal = new Vector3();
  7109. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  7110. dstNormalsFace.push( faceNormal );
  7111. dstNormalsVertex.push( vertexNormals );
  7112. }
  7113. }
  7114. var morphNormals = this.morphNormals[ i ];
  7115. // set vertices to morph target
  7116. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  7117. // compute morph normals
  7118. tmpGeo.computeFaceNormals();
  7119. tmpGeo.computeVertexNormals();
  7120. // store morph normals
  7121. var faceNormal, vertexNormals;
  7122. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7123. face = this.faces[ f ];
  7124. faceNormal = morphNormals.faceNormals[ f ];
  7125. vertexNormals = morphNormals.vertexNormals[ f ];
  7126. faceNormal.copy( face.normal );
  7127. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  7128. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  7129. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  7130. }
  7131. }
  7132. // restore original normals
  7133. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7134. face = this.faces[ f ];
  7135. face.normal = face.__originalFaceNormal;
  7136. face.vertexNormals = face.__originalVertexNormals;
  7137. }
  7138. },
  7139. computeBoundingBox: function () {
  7140. if ( this.boundingBox === null ) {
  7141. this.boundingBox = new Box3();
  7142. }
  7143. this.boundingBox.setFromPoints( this.vertices );
  7144. },
  7145. computeBoundingSphere: function () {
  7146. if ( this.boundingSphere === null ) {
  7147. this.boundingSphere = new Sphere();
  7148. }
  7149. this.boundingSphere.setFromPoints( this.vertices );
  7150. },
  7151. merge: function ( geometry, matrix, materialIndexOffset ) {
  7152. if ( ! ( geometry && geometry.isGeometry ) ) {
  7153. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  7154. return;
  7155. }
  7156. var normalMatrix,
  7157. vertexOffset = this.vertices.length,
  7158. vertices1 = this.vertices,
  7159. vertices2 = geometry.vertices,
  7160. faces1 = this.faces,
  7161. faces2 = geometry.faces,
  7162. colors1 = this.colors,
  7163. colors2 = geometry.colors;
  7164. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  7165. if ( matrix !== undefined ) {
  7166. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  7167. }
  7168. // vertices
  7169. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  7170. var vertex = vertices2[ i ];
  7171. var vertexCopy = vertex.clone();
  7172. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  7173. vertices1.push( vertexCopy );
  7174. }
  7175. // colors
  7176. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  7177. colors1.push( colors2[ i ].clone() );
  7178. }
  7179. // faces
  7180. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  7181. var face = faces2[ i ], faceCopy, normal, color,
  7182. faceVertexNormals = face.vertexNormals,
  7183. faceVertexColors = face.vertexColors;
  7184. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  7185. faceCopy.normal.copy( face.normal );
  7186. if ( normalMatrix !== undefined ) {
  7187. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  7188. }
  7189. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  7190. normal = faceVertexNormals[ j ].clone();
  7191. if ( normalMatrix !== undefined ) {
  7192. normal.applyMatrix3( normalMatrix ).normalize();
  7193. }
  7194. faceCopy.vertexNormals.push( normal );
  7195. }
  7196. faceCopy.color.copy( face.color );
  7197. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  7198. color = faceVertexColors[ j ];
  7199. faceCopy.vertexColors.push( color.clone() );
  7200. }
  7201. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  7202. faces1.push( faceCopy );
  7203. }
  7204. // uvs
  7205. for ( var i = 0, il = geometry.faceVertexUvs.length; i < il; i ++ ) {
  7206. var faceVertexUvs2 = geometry.faceVertexUvs[ i ];
  7207. if ( this.faceVertexUvs[ i ] === undefined ) this.faceVertexUvs[ i ] = [];
  7208. for ( var j = 0, jl = faceVertexUvs2.length; j < jl; j ++ ) {
  7209. var uvs2 = faceVertexUvs2[ j ], uvsCopy = [];
  7210. for ( var k = 0, kl = uvs2.length; k < kl; k ++ ) {
  7211. uvsCopy.push( uvs2[ k ].clone() );
  7212. }
  7213. this.faceVertexUvs[ i ].push( uvsCopy );
  7214. }
  7215. }
  7216. },
  7217. mergeMesh: function ( mesh ) {
  7218. if ( ! ( mesh && mesh.isMesh ) ) {
  7219. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  7220. return;
  7221. }
  7222. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  7223. this.merge( mesh.geometry, mesh.matrix );
  7224. },
  7225. /*
  7226. * Checks for duplicate vertices with hashmap.
  7227. * Duplicated vertices are removed
  7228. * and faces' vertices are updated.
  7229. */
  7230. mergeVertices: function () {
  7231. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  7232. var unique = [], changes = [];
  7233. var v, key;
  7234. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  7235. var precision = Math.pow( 10, precisionPoints );
  7236. var i, il, face;
  7237. var indices, j, jl;
  7238. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  7239. v = this.vertices[ i ];
  7240. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  7241. if ( verticesMap[ key ] === undefined ) {
  7242. verticesMap[ key ] = i;
  7243. unique.push( this.vertices[ i ] );
  7244. changes[ i ] = unique.length - 1;
  7245. } else {
  7246. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  7247. changes[ i ] = changes[ verticesMap[ key ] ];
  7248. }
  7249. }
  7250. // if faces are completely degenerate after merging vertices, we
  7251. // have to remove them from the geometry.
  7252. var faceIndicesToRemove = [];
  7253. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  7254. face = this.faces[ i ];
  7255. face.a = changes[ face.a ];
  7256. face.b = changes[ face.b ];
  7257. face.c = changes[ face.c ];
  7258. indices = [ face.a, face.b, face.c ];
  7259. // if any duplicate vertices are found in a Face3
  7260. // we have to remove the face as nothing can be saved
  7261. for ( var n = 0; n < 3; n ++ ) {
  7262. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  7263. faceIndicesToRemove.push( i );
  7264. break;
  7265. }
  7266. }
  7267. }
  7268. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  7269. var idx = faceIndicesToRemove[ i ];
  7270. this.faces.splice( idx, 1 );
  7271. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  7272. this.faceVertexUvs[ j ].splice( idx, 1 );
  7273. }
  7274. }
  7275. // Use unique set of vertices
  7276. var diff = this.vertices.length - unique.length;
  7277. this.vertices = unique;
  7278. return diff;
  7279. },
  7280. setFromPoints: function ( points ) {
  7281. this.vertices = [];
  7282. for ( var i = 0, l = points.length; i < l; i ++ ) {
  7283. var point = points[ i ];
  7284. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  7285. }
  7286. return this;
  7287. },
  7288. sortFacesByMaterialIndex: function () {
  7289. var faces = this.faces;
  7290. var length = faces.length;
  7291. // tag faces
  7292. for ( var i = 0; i < length; i ++ ) {
  7293. faces[ i ]._id = i;
  7294. }
  7295. // sort faces
  7296. function materialIndexSort( a, b ) {
  7297. return a.materialIndex - b.materialIndex;
  7298. }
  7299. faces.sort( materialIndexSort );
  7300. // sort uvs
  7301. var uvs1 = this.faceVertexUvs[ 0 ];
  7302. var uvs2 = this.faceVertexUvs[ 1 ];
  7303. var newUvs1, newUvs2;
  7304. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  7305. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  7306. for ( var i = 0; i < length; i ++ ) {
  7307. var id = faces[ i ]._id;
  7308. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  7309. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  7310. }
  7311. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  7312. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  7313. },
  7314. toJSON: function () {
  7315. var data = {
  7316. metadata: {
  7317. version: 4.5,
  7318. type: 'Geometry',
  7319. generator: 'Geometry.toJSON'
  7320. }
  7321. };
  7322. // standard Geometry serialization
  7323. data.uuid = this.uuid;
  7324. data.type = this.type;
  7325. if ( this.name !== '' ) data.name = this.name;
  7326. if ( this.parameters !== undefined ) {
  7327. var parameters = this.parameters;
  7328. for ( var key in parameters ) {
  7329. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7330. }
  7331. return data;
  7332. }
  7333. var vertices = [];
  7334. for ( var i = 0; i < this.vertices.length; i ++ ) {
  7335. var vertex = this.vertices[ i ];
  7336. vertices.push( vertex.x, vertex.y, vertex.z );
  7337. }
  7338. var faces = [];
  7339. var normals = [];
  7340. var normalsHash = {};
  7341. var colors = [];
  7342. var colorsHash = {};
  7343. var uvs = [];
  7344. var uvsHash = {};
  7345. for ( var i = 0; i < this.faces.length; i ++ ) {
  7346. var face = this.faces[ i ];
  7347. var hasMaterial = true;
  7348. var hasFaceUv = false; // deprecated
  7349. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  7350. var hasFaceNormal = face.normal.length() > 0;
  7351. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  7352. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  7353. var hasFaceVertexColor = face.vertexColors.length > 0;
  7354. var faceType = 0;
  7355. faceType = setBit( faceType, 0, 0 ); // isQuad
  7356. faceType = setBit( faceType, 1, hasMaterial );
  7357. faceType = setBit( faceType, 2, hasFaceUv );
  7358. faceType = setBit( faceType, 3, hasFaceVertexUv );
  7359. faceType = setBit( faceType, 4, hasFaceNormal );
  7360. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  7361. faceType = setBit( faceType, 6, hasFaceColor );
  7362. faceType = setBit( faceType, 7, hasFaceVertexColor );
  7363. faces.push( faceType );
  7364. faces.push( face.a, face.b, face.c );
  7365. faces.push( face.materialIndex );
  7366. if ( hasFaceVertexUv ) {
  7367. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  7368. faces.push(
  7369. getUvIndex( faceVertexUvs[ 0 ] ),
  7370. getUvIndex( faceVertexUvs[ 1 ] ),
  7371. getUvIndex( faceVertexUvs[ 2 ] )
  7372. );
  7373. }
  7374. if ( hasFaceNormal ) {
  7375. faces.push( getNormalIndex( face.normal ) );
  7376. }
  7377. if ( hasFaceVertexNormal ) {
  7378. var vertexNormals = face.vertexNormals;
  7379. faces.push(
  7380. getNormalIndex( vertexNormals[ 0 ] ),
  7381. getNormalIndex( vertexNormals[ 1 ] ),
  7382. getNormalIndex( vertexNormals[ 2 ] )
  7383. );
  7384. }
  7385. if ( hasFaceColor ) {
  7386. faces.push( getColorIndex( face.color ) );
  7387. }
  7388. if ( hasFaceVertexColor ) {
  7389. var vertexColors = face.vertexColors;
  7390. faces.push(
  7391. getColorIndex( vertexColors[ 0 ] ),
  7392. getColorIndex( vertexColors[ 1 ] ),
  7393. getColorIndex( vertexColors[ 2 ] )
  7394. );
  7395. }
  7396. }
  7397. function setBit( value, position, enabled ) {
  7398. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  7399. }
  7400. function getNormalIndex( normal ) {
  7401. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  7402. if ( normalsHash[ hash ] !== undefined ) {
  7403. return normalsHash[ hash ];
  7404. }
  7405. normalsHash[ hash ] = normals.length / 3;
  7406. normals.push( normal.x, normal.y, normal.z );
  7407. return normalsHash[ hash ];
  7408. }
  7409. function getColorIndex( color ) {
  7410. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  7411. if ( colorsHash[ hash ] !== undefined ) {
  7412. return colorsHash[ hash ];
  7413. }
  7414. colorsHash[ hash ] = colors.length;
  7415. colors.push( color.getHex() );
  7416. return colorsHash[ hash ];
  7417. }
  7418. function getUvIndex( uv ) {
  7419. var hash = uv.x.toString() + uv.y.toString();
  7420. if ( uvsHash[ hash ] !== undefined ) {
  7421. return uvsHash[ hash ];
  7422. }
  7423. uvsHash[ hash ] = uvs.length / 2;
  7424. uvs.push( uv.x, uv.y );
  7425. return uvsHash[ hash ];
  7426. }
  7427. data.data = {};
  7428. data.data.vertices = vertices;
  7429. data.data.normals = normals;
  7430. if ( colors.length > 0 ) data.data.colors = colors;
  7431. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  7432. data.data.faces = faces;
  7433. return data;
  7434. },
  7435. clone: function () {
  7436. /*
  7437. // Handle primitives
  7438. var parameters = this.parameters;
  7439. if ( parameters !== undefined ) {
  7440. var values = [];
  7441. for ( var key in parameters ) {
  7442. values.push( parameters[ key ] );
  7443. }
  7444. var geometry = Object.create( this.constructor.prototype );
  7445. this.constructor.apply( geometry, values );
  7446. return geometry;
  7447. }
  7448. return new this.constructor().copy( this );
  7449. */
  7450. return new Geometry().copy( this );
  7451. },
  7452. copy: function ( source ) {
  7453. var i, il, j, jl, k, kl;
  7454. // reset
  7455. this.vertices = [];
  7456. this.colors = [];
  7457. this.faces = [];
  7458. this.faceVertexUvs = [[]];
  7459. this.morphTargets = [];
  7460. this.morphNormals = [];
  7461. this.skinWeights = [];
  7462. this.skinIndices = [];
  7463. this.lineDistances = [];
  7464. this.boundingBox = null;
  7465. this.boundingSphere = null;
  7466. // name
  7467. this.name = source.name;
  7468. // vertices
  7469. var vertices = source.vertices;
  7470. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  7471. this.vertices.push( vertices[ i ].clone() );
  7472. }
  7473. // colors
  7474. var colors = source.colors;
  7475. for ( i = 0, il = colors.length; i < il; i ++ ) {
  7476. this.colors.push( colors[ i ].clone() );
  7477. }
  7478. // faces
  7479. var faces = source.faces;
  7480. for ( i = 0, il = faces.length; i < il; i ++ ) {
  7481. this.faces.push( faces[ i ].clone() );
  7482. }
  7483. // face vertex uvs
  7484. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  7485. var faceVertexUvs = source.faceVertexUvs[ i ];
  7486. if ( this.faceVertexUvs[ i ] === undefined ) {
  7487. this.faceVertexUvs[ i ] = [];
  7488. }
  7489. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  7490. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  7491. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  7492. var uv = uvs[ k ];
  7493. uvsCopy.push( uv.clone() );
  7494. }
  7495. this.faceVertexUvs[ i ].push( uvsCopy );
  7496. }
  7497. }
  7498. // morph targets
  7499. var morphTargets = source.morphTargets;
  7500. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  7501. var morphTarget = {};
  7502. morphTarget.name = morphTargets[ i ].name;
  7503. // vertices
  7504. if ( morphTargets[ i ].vertices !== undefined ) {
  7505. morphTarget.vertices = [];
  7506. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  7507. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  7508. }
  7509. }
  7510. // normals
  7511. if ( morphTargets[ i ].normals !== undefined ) {
  7512. morphTarget.normals = [];
  7513. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  7514. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  7515. }
  7516. }
  7517. this.morphTargets.push( morphTarget );
  7518. }
  7519. // morph normals
  7520. var morphNormals = source.morphNormals;
  7521. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  7522. var morphNormal = {};
  7523. // vertex normals
  7524. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  7525. morphNormal.vertexNormals = [];
  7526. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  7527. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  7528. var destVertexNormal = {};
  7529. destVertexNormal.a = srcVertexNormal.a.clone();
  7530. destVertexNormal.b = srcVertexNormal.b.clone();
  7531. destVertexNormal.c = srcVertexNormal.c.clone();
  7532. morphNormal.vertexNormals.push( destVertexNormal );
  7533. }
  7534. }
  7535. // face normals
  7536. if ( morphNormals[ i ].faceNormals !== undefined ) {
  7537. morphNormal.faceNormals = [];
  7538. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  7539. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  7540. }
  7541. }
  7542. this.morphNormals.push( morphNormal );
  7543. }
  7544. // skin weights
  7545. var skinWeights = source.skinWeights;
  7546. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  7547. this.skinWeights.push( skinWeights[ i ].clone() );
  7548. }
  7549. // skin indices
  7550. var skinIndices = source.skinIndices;
  7551. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  7552. this.skinIndices.push( skinIndices[ i ].clone() );
  7553. }
  7554. // line distances
  7555. var lineDistances = source.lineDistances;
  7556. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  7557. this.lineDistances.push( lineDistances[ i ] );
  7558. }
  7559. // bounding box
  7560. var boundingBox = source.boundingBox;
  7561. if ( boundingBox !== null ) {
  7562. this.boundingBox = boundingBox.clone();
  7563. }
  7564. // bounding sphere
  7565. var boundingSphere = source.boundingSphere;
  7566. if ( boundingSphere !== null ) {
  7567. this.boundingSphere = boundingSphere.clone();
  7568. }
  7569. // update flags
  7570. this.elementsNeedUpdate = source.elementsNeedUpdate;
  7571. this.verticesNeedUpdate = source.verticesNeedUpdate;
  7572. this.uvsNeedUpdate = source.uvsNeedUpdate;
  7573. this.normalsNeedUpdate = source.normalsNeedUpdate;
  7574. this.colorsNeedUpdate = source.colorsNeedUpdate;
  7575. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  7576. this.groupsNeedUpdate = source.groupsNeedUpdate;
  7577. return this;
  7578. },
  7579. dispose: function () {
  7580. this.dispatchEvent( { type: 'dispose' } );
  7581. }
  7582. } );
  7583. /**
  7584. * @author mrdoob / http://mrdoob.com/
  7585. * @author Mugen87 / https://github.com/Mugen87
  7586. */
  7587. // BoxGeometry
  7588. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7589. Geometry.call( this );
  7590. this.type = 'BoxGeometry';
  7591. this.parameters = {
  7592. width: width,
  7593. height: height,
  7594. depth: depth,
  7595. widthSegments: widthSegments,
  7596. heightSegments: heightSegments,
  7597. depthSegments: depthSegments
  7598. };
  7599. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  7600. this.mergeVertices();
  7601. }
  7602. BoxGeometry.prototype = Object.create( Geometry.prototype );
  7603. BoxGeometry.prototype.constructor = BoxGeometry;
  7604. // BoxBufferGeometry
  7605. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7606. BufferGeometry.call( this );
  7607. this.type = 'BoxBufferGeometry';
  7608. this.parameters = {
  7609. width: width,
  7610. height: height,
  7611. depth: depth,
  7612. widthSegments: widthSegments,
  7613. heightSegments: heightSegments,
  7614. depthSegments: depthSegments
  7615. };
  7616. var scope = this;
  7617. width = width || 1;
  7618. height = height || 1;
  7619. depth = depth || 1;
  7620. // segments
  7621. widthSegments = Math.floor( widthSegments ) || 1;
  7622. heightSegments = Math.floor( heightSegments ) || 1;
  7623. depthSegments = Math.floor( depthSegments ) || 1;
  7624. // buffers
  7625. var indices = [];
  7626. var vertices = [];
  7627. var normals = [];
  7628. var uvs = [];
  7629. // helper variables
  7630. var numberOfVertices = 0;
  7631. var groupStart = 0;
  7632. // build each side of the box geometry
  7633. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7634. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7635. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7636. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7637. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7638. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7639. // build geometry
  7640. this.setIndex( indices );
  7641. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7642. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7643. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7644. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7645. var segmentWidth = width / gridX;
  7646. var segmentHeight = height / gridY;
  7647. var widthHalf = width / 2;
  7648. var heightHalf = height / 2;
  7649. var depthHalf = depth / 2;
  7650. var gridX1 = gridX + 1;
  7651. var gridY1 = gridY + 1;
  7652. var vertexCounter = 0;
  7653. var groupCount = 0;
  7654. var ix, iy;
  7655. var vector = new Vector3();
  7656. // generate vertices, normals and uvs
  7657. for ( iy = 0; iy < gridY1; iy ++ ) {
  7658. var y = iy * segmentHeight - heightHalf;
  7659. for ( ix = 0; ix < gridX1; ix ++ ) {
  7660. var x = ix * segmentWidth - widthHalf;
  7661. // set values to correct vector component
  7662. vector[ u ] = x * udir;
  7663. vector[ v ] = y * vdir;
  7664. vector[ w ] = depthHalf;
  7665. // now apply vector to vertex buffer
  7666. vertices.push( vector.x, vector.y, vector.z );
  7667. // set values to correct vector component
  7668. vector[ u ] = 0;
  7669. vector[ v ] = 0;
  7670. vector[ w ] = depth > 0 ? 1 : - 1;
  7671. // now apply vector to normal buffer
  7672. normals.push( vector.x, vector.y, vector.z );
  7673. // uvs
  7674. uvs.push( ix / gridX );
  7675. uvs.push( 1 - ( iy / gridY ) );
  7676. // counters
  7677. vertexCounter += 1;
  7678. }
  7679. }
  7680. // indices
  7681. // 1. you need three indices to draw a single face
  7682. // 2. a single segment consists of two faces
  7683. // 3. so we need to generate six (2*3) indices per segment
  7684. for ( iy = 0; iy < gridY; iy ++ ) {
  7685. for ( ix = 0; ix < gridX; ix ++ ) {
  7686. var a = numberOfVertices + ix + gridX1 * iy;
  7687. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7688. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7689. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7690. // faces
  7691. indices.push( a, b, d );
  7692. indices.push( b, c, d );
  7693. // increase counter
  7694. groupCount += 6;
  7695. }
  7696. }
  7697. // add a group to the geometry. this will ensure multi material support
  7698. scope.addGroup( groupStart, groupCount, materialIndex );
  7699. // calculate new start value for groups
  7700. groupStart += groupCount;
  7701. // update total number of vertices
  7702. numberOfVertices += vertexCounter;
  7703. }
  7704. }
  7705. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7706. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  7707. /**
  7708. * Uniform Utilities
  7709. */
  7710. function cloneUniforms( src ) {
  7711. var dst = {};
  7712. for ( var u in src ) {
  7713. dst[ u ] = {};
  7714. for ( var p in src[ u ] ) {
  7715. var property = src[ u ][ p ];
  7716. if ( property && ( property.isColor ||
  7717. property.isMatrix3 || property.isMatrix4 ||
  7718. property.isVector2 || property.isVector3 || property.isVector4 ||
  7719. property.isTexture ) ) {
  7720. dst[ u ][ p ] = property.clone();
  7721. } else if ( Array.isArray( property ) ) {
  7722. dst[ u ][ p ] = property.slice();
  7723. } else {
  7724. dst[ u ][ p ] = property;
  7725. }
  7726. }
  7727. }
  7728. return dst;
  7729. }
  7730. function mergeUniforms( uniforms ) {
  7731. var merged = {};
  7732. for ( var u = 0; u < uniforms.length; u ++ ) {
  7733. var tmp = cloneUniforms( uniforms[ u ] );
  7734. for ( var p in tmp ) {
  7735. merged[ p ] = tmp[ p ];
  7736. }
  7737. }
  7738. return merged;
  7739. }
  7740. // Legacy
  7741. var UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  7742. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7743. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7744. /**
  7745. * @author alteredq / http://alteredqualia.com/
  7746. *
  7747. * parameters = {
  7748. * defines: { "label" : "value" },
  7749. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7750. *
  7751. * fragmentShader: <string>,
  7752. * vertexShader: <string>,
  7753. *
  7754. * wireframe: <boolean>,
  7755. * wireframeLinewidth: <float>,
  7756. *
  7757. * lights: <bool>,
  7758. *
  7759. * skinning: <bool>,
  7760. * morphTargets: <bool>,
  7761. * morphNormals: <bool>
  7762. * }
  7763. */
  7764. function ShaderMaterial( parameters ) {
  7765. Material.call( this );
  7766. this.type = 'ShaderMaterial';
  7767. this.defines = {};
  7768. this.uniforms = {};
  7769. this.vertexShader = default_vertex;
  7770. this.fragmentShader = default_fragment;
  7771. this.linewidth = 1;
  7772. this.wireframe = false;
  7773. this.wireframeLinewidth = 1;
  7774. this.fog = false; // set to use scene fog
  7775. this.lights = false; // set to use scene lights
  7776. this.clipping = false; // set to use user-defined clipping planes
  7777. this.skinning = false; // set to use skinning attribute streams
  7778. this.morphTargets = false; // set to use morph targets
  7779. this.morphNormals = false; // set to use morph normals
  7780. this.extensions = {
  7781. derivatives: false, // set to use derivatives
  7782. fragDepth: false, // set to use fragment depth values
  7783. drawBuffers: false, // set to use draw buffers
  7784. shaderTextureLOD: false // set to use shader texture LOD
  7785. };
  7786. // When rendered geometry doesn't include these attributes but the material does,
  7787. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7788. this.defaultAttributeValues = {
  7789. 'color': [ 1, 1, 1 ],
  7790. 'uv': [ 0, 0 ],
  7791. 'uv2': [ 0, 0 ]
  7792. };
  7793. this.index0AttributeName = undefined;
  7794. this.uniformsNeedUpdate = false;
  7795. if ( parameters !== undefined ) {
  7796. if ( parameters.attributes !== undefined ) {
  7797. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  7798. }
  7799. this.setValues( parameters );
  7800. }
  7801. }
  7802. ShaderMaterial.prototype = Object.create( Material.prototype );
  7803. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7804. ShaderMaterial.prototype.isShaderMaterial = true;
  7805. ShaderMaterial.prototype.copy = function ( source ) {
  7806. Material.prototype.copy.call( this, source );
  7807. this.fragmentShader = source.fragmentShader;
  7808. this.vertexShader = source.vertexShader;
  7809. this.uniforms = cloneUniforms( source.uniforms );
  7810. this.defines = Object.assign( {}, source.defines );
  7811. this.wireframe = source.wireframe;
  7812. this.wireframeLinewidth = source.wireframeLinewidth;
  7813. this.lights = source.lights;
  7814. this.clipping = source.clipping;
  7815. this.skinning = source.skinning;
  7816. this.morphTargets = source.morphTargets;
  7817. this.morphNormals = source.morphNormals;
  7818. this.extensions = source.extensions;
  7819. return this;
  7820. };
  7821. ShaderMaterial.prototype.toJSON = function ( meta ) {
  7822. var data = Material.prototype.toJSON.call( this, meta );
  7823. data.uniforms = {};
  7824. for ( var name in this.uniforms ) {
  7825. var uniform = this.uniforms[ name ];
  7826. var value = uniform.value;
  7827. if ( value && value.isTexture ) {
  7828. data.uniforms[ name ] = {
  7829. type: 't',
  7830. value: value.toJSON( meta ).uuid
  7831. };
  7832. } else if ( value && value.isColor ) {
  7833. data.uniforms[ name ] = {
  7834. type: 'c',
  7835. value: value.getHex()
  7836. };
  7837. } else if ( value && value.isVector2 ) {
  7838. data.uniforms[ name ] = {
  7839. type: 'v2',
  7840. value: value.toArray()
  7841. };
  7842. } else if ( value && value.isVector3 ) {
  7843. data.uniforms[ name ] = {
  7844. type: 'v3',
  7845. value: value.toArray()
  7846. };
  7847. } else if ( value && value.isVector4 ) {
  7848. data.uniforms[ name ] = {
  7849. type: 'v4',
  7850. value: value.toArray()
  7851. };
  7852. } else if ( value && value.isMatrix3 ) {
  7853. data.uniforms[ name ] = {
  7854. type: 'm3',
  7855. value: value.toArray()
  7856. };
  7857. } else if ( value && value.isMatrix4 ) {
  7858. data.uniforms[ name ] = {
  7859. type: 'm4',
  7860. value: value.toArray()
  7861. };
  7862. } else {
  7863. data.uniforms[ name ] = {
  7864. value: value
  7865. };
  7866. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7867. }
  7868. }
  7869. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7870. data.vertexShader = this.vertexShader;
  7871. data.fragmentShader = this.fragmentShader;
  7872. var extensions = {};
  7873. for ( var key in this.extensions ) {
  7874. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7875. }
  7876. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7877. return data;
  7878. };
  7879. /**
  7880. * @author mrdoob / http://mrdoob.com/
  7881. * @author mikael emtinger / http://gomo.se/
  7882. * @author WestLangley / http://github.com/WestLangley
  7883. */
  7884. function Camera() {
  7885. Object3D.call( this );
  7886. this.type = 'Camera';
  7887. this.matrixWorldInverse = new Matrix4();
  7888. this.projectionMatrix = new Matrix4();
  7889. this.projectionMatrixInverse = new Matrix4();
  7890. }
  7891. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  7892. constructor: Camera,
  7893. isCamera: true,
  7894. copy: function ( source, recursive ) {
  7895. Object3D.prototype.copy.call( this, source, recursive );
  7896. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  7897. this.projectionMatrix.copy( source.projectionMatrix );
  7898. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  7899. return this;
  7900. },
  7901. getWorldDirection: function ( target ) {
  7902. if ( target === undefined ) {
  7903. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  7904. target = new Vector3();
  7905. }
  7906. this.updateMatrixWorld( true );
  7907. var e = this.matrixWorld.elements;
  7908. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  7909. },
  7910. updateMatrixWorld: function ( force ) {
  7911. Object3D.prototype.updateMatrixWorld.call( this, force );
  7912. this.matrixWorldInverse.getInverse( this.matrixWorld );
  7913. },
  7914. clone: function () {
  7915. return new this.constructor().copy( this );
  7916. }
  7917. } );
  7918. /**
  7919. * @author mrdoob / http://mrdoob.com/
  7920. * @author greggman / http://games.greggman.com/
  7921. * @author zz85 / http://www.lab4games.net/zz85/blog
  7922. * @author tschw
  7923. */
  7924. function PerspectiveCamera( fov, aspect, near, far ) {
  7925. Camera.call( this );
  7926. this.type = 'PerspectiveCamera';
  7927. this.fov = fov !== undefined ? fov : 50;
  7928. this.zoom = 1;
  7929. this.near = near !== undefined ? near : 0.1;
  7930. this.far = far !== undefined ? far : 2000;
  7931. this.focus = 10;
  7932. this.aspect = aspect !== undefined ? aspect : 1;
  7933. this.view = null;
  7934. this.filmGauge = 35; // width of the film (default in millimeters)
  7935. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7936. this.updateProjectionMatrix();
  7937. }
  7938. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  7939. constructor: PerspectiveCamera,
  7940. isPerspectiveCamera: true,
  7941. copy: function ( source, recursive ) {
  7942. Camera.prototype.copy.call( this, source, recursive );
  7943. this.fov = source.fov;
  7944. this.zoom = source.zoom;
  7945. this.near = source.near;
  7946. this.far = source.far;
  7947. this.focus = source.focus;
  7948. this.aspect = source.aspect;
  7949. this.view = source.view === null ? null : Object.assign( {}, source.view );
  7950. this.filmGauge = source.filmGauge;
  7951. this.filmOffset = source.filmOffset;
  7952. return this;
  7953. },
  7954. /**
  7955. * Sets the FOV by focal length in respect to the current .filmGauge.
  7956. *
  7957. * The default film gauge is 35, so that the focal length can be specified for
  7958. * a 35mm (full frame) camera.
  7959. *
  7960. * Values for focal length and film gauge must have the same unit.
  7961. */
  7962. setFocalLength: function ( focalLength ) {
  7963. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  7964. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7965. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  7966. this.updateProjectionMatrix();
  7967. },
  7968. /**
  7969. * Calculates the focal length from the current .fov and .filmGauge.
  7970. */
  7971. getFocalLength: function () {
  7972. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  7973. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7974. },
  7975. getEffectiveFOV: function () {
  7976. return _Math.RAD2DEG * 2 * Math.atan(
  7977. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  7978. },
  7979. getFilmWidth: function () {
  7980. // film not completely covered in portrait format (aspect < 1)
  7981. return this.filmGauge * Math.min( this.aspect, 1 );
  7982. },
  7983. getFilmHeight: function () {
  7984. // film not completely covered in landscape format (aspect > 1)
  7985. return this.filmGauge / Math.max( this.aspect, 1 );
  7986. },
  7987. /**
  7988. * Sets an offset in a larger frustum. This is useful for multi-window or
  7989. * multi-monitor/multi-machine setups.
  7990. *
  7991. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7992. * the monitors are in grid like this
  7993. *
  7994. * +---+---+---+
  7995. * | A | B | C |
  7996. * +---+---+---+
  7997. * | D | E | F |
  7998. * +---+---+---+
  7999. *
  8000. * then for each monitor you would call it like this
  8001. *
  8002. * var w = 1920;
  8003. * var h = 1080;
  8004. * var fullWidth = w * 3;
  8005. * var fullHeight = h * 2;
  8006. *
  8007. * --A--
  8008. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8009. * --B--
  8010. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8011. * --C--
  8012. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8013. * --D--
  8014. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8015. * --E--
  8016. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8017. * --F--
  8018. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8019. *
  8020. * Note there is no reason monitors have to be the same size or in a grid.
  8021. */
  8022. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  8023. this.aspect = fullWidth / fullHeight;
  8024. if ( this.view === null ) {
  8025. this.view = {
  8026. enabled: true,
  8027. fullWidth: 1,
  8028. fullHeight: 1,
  8029. offsetX: 0,
  8030. offsetY: 0,
  8031. width: 1,
  8032. height: 1
  8033. };
  8034. }
  8035. this.view.enabled = true;
  8036. this.view.fullWidth = fullWidth;
  8037. this.view.fullHeight = fullHeight;
  8038. this.view.offsetX = x;
  8039. this.view.offsetY = y;
  8040. this.view.width = width;
  8041. this.view.height = height;
  8042. this.updateProjectionMatrix();
  8043. },
  8044. clearViewOffset: function () {
  8045. if ( this.view !== null ) {
  8046. this.view.enabled = false;
  8047. }
  8048. this.updateProjectionMatrix();
  8049. },
  8050. updateProjectionMatrix: function () {
  8051. var near = this.near,
  8052. top = near * Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  8053. height = 2 * top,
  8054. width = this.aspect * height,
  8055. left = - 0.5 * width,
  8056. view = this.view;
  8057. if ( this.view !== null && this.view.enabled ) {
  8058. var fullWidth = view.fullWidth,
  8059. fullHeight = view.fullHeight;
  8060. left += view.offsetX * width / fullWidth;
  8061. top -= view.offsetY * height / fullHeight;
  8062. width *= view.width / fullWidth;
  8063. height *= view.height / fullHeight;
  8064. }
  8065. var skew = this.filmOffset;
  8066. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  8067. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  8068. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  8069. },
  8070. toJSON: function ( meta ) {
  8071. var data = Object3D.prototype.toJSON.call( this, meta );
  8072. data.object.fov = this.fov;
  8073. data.object.zoom = this.zoom;
  8074. data.object.near = this.near;
  8075. data.object.far = this.far;
  8076. data.object.focus = this.focus;
  8077. data.object.aspect = this.aspect;
  8078. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  8079. data.object.filmGauge = this.filmGauge;
  8080. data.object.filmOffset = this.filmOffset;
  8081. return data;
  8082. }
  8083. } );
  8084. /**
  8085. * Camera for rendering cube maps
  8086. * - renders scene into axis-aligned cube
  8087. *
  8088. * @author alteredq / http://alteredqualia.com/
  8089. */
  8090. var fov = 90, aspect = 1;
  8091. function CubeCamera( near, far, cubeResolution, options ) {
  8092. Object3D.call( this );
  8093. this.type = 'CubeCamera';
  8094. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  8095. cameraPX.up.set( 0, - 1, 0 );
  8096. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  8097. this.add( cameraPX );
  8098. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  8099. cameraNX.up.set( 0, - 1, 0 );
  8100. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  8101. this.add( cameraNX );
  8102. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  8103. cameraPY.up.set( 0, 0, 1 );
  8104. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  8105. this.add( cameraPY );
  8106. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  8107. cameraNY.up.set( 0, 0, - 1 );
  8108. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  8109. this.add( cameraNY );
  8110. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  8111. cameraPZ.up.set( 0, - 1, 0 );
  8112. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  8113. this.add( cameraPZ );
  8114. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  8115. cameraNZ.up.set( 0, - 1, 0 );
  8116. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  8117. this.add( cameraNZ );
  8118. options = options || { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
  8119. this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  8120. this.renderTarget.texture.name = "CubeCamera";
  8121. this.update = function ( renderer, scene ) {
  8122. if ( this.parent === null ) this.updateMatrixWorld();
  8123. var currentRenderTarget = renderer.getRenderTarget();
  8124. var renderTarget = this.renderTarget;
  8125. var generateMipmaps = renderTarget.texture.generateMipmaps;
  8126. renderTarget.texture.generateMipmaps = false;
  8127. renderer.setRenderTarget( renderTarget, 0 );
  8128. renderer.render( scene, cameraPX );
  8129. renderer.setRenderTarget( renderTarget, 1 );
  8130. renderer.render( scene, cameraNX );
  8131. renderer.setRenderTarget( renderTarget, 2 );
  8132. renderer.render( scene, cameraPY );
  8133. renderer.setRenderTarget( renderTarget, 3 );
  8134. renderer.render( scene, cameraNY );
  8135. renderer.setRenderTarget( renderTarget, 4 );
  8136. renderer.render( scene, cameraPZ );
  8137. renderTarget.texture.generateMipmaps = generateMipmaps;
  8138. renderer.setRenderTarget( renderTarget, 5 );
  8139. renderer.render( scene, cameraNZ );
  8140. renderer.setRenderTarget( currentRenderTarget );
  8141. };
  8142. this.clear = function ( renderer, color, depth, stencil ) {
  8143. var currentRenderTarget = renderer.getRenderTarget();
  8144. var renderTarget = this.renderTarget;
  8145. for ( var i = 0; i < 6; i ++ ) {
  8146. renderer.setRenderTarget( renderTarget, i );
  8147. renderer.clear( color, depth, stencil );
  8148. }
  8149. renderer.setRenderTarget( currentRenderTarget );
  8150. };
  8151. }
  8152. CubeCamera.prototype = Object.create( Object3D.prototype );
  8153. CubeCamera.prototype.constructor = CubeCamera;
  8154. /**
  8155. * @author alteredq / http://alteredqualia.com
  8156. * @author WestLangley / http://github.com/WestLangley
  8157. */
  8158. function WebGLRenderTargetCube( width, height, options ) {
  8159. WebGLRenderTarget.call( this, width, height, options );
  8160. }
  8161. WebGLRenderTargetCube.prototype = Object.create( WebGLRenderTarget.prototype );
  8162. WebGLRenderTargetCube.prototype.constructor = WebGLRenderTargetCube;
  8163. WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
  8164. WebGLRenderTargetCube.prototype.fromEquirectangularTexture = function ( renderer, texture ) {
  8165. this.texture.type = texture.type;
  8166. this.texture.format = texture.format;
  8167. this.texture.encoding = texture.encoding;
  8168. var scene = new Scene();
  8169. var shader = {
  8170. uniforms: {
  8171. tEquirect: { value: null },
  8172. },
  8173. vertexShader: [
  8174. "varying vec3 vWorldDirection;",
  8175. "vec3 transformDirection( in vec3 dir, in mat4 matrix ) {",
  8176. " return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );",
  8177. "}",
  8178. "void main() {",
  8179. " vWorldDirection = transformDirection( position, modelMatrix );",
  8180. " #include <begin_vertex>",
  8181. " #include <project_vertex>",
  8182. "}"
  8183. ].join( '\n' ),
  8184. fragmentShader: [
  8185. "uniform sampler2D tEquirect;",
  8186. "varying vec3 vWorldDirection;",
  8187. "#define RECIPROCAL_PI 0.31830988618",
  8188. "#define RECIPROCAL_PI2 0.15915494",
  8189. "void main() {",
  8190. " vec3 direction = normalize( vWorldDirection );",
  8191. " vec2 sampleUV;",
  8192. " sampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;",
  8193. " sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  8194. " gl_FragColor = texture2D( tEquirect, sampleUV );",
  8195. "}"
  8196. ].join( '\n' ),
  8197. };
  8198. var material = new ShaderMaterial( {
  8199. type: 'CubemapFromEquirect',
  8200. uniforms: cloneUniforms( shader.uniforms ),
  8201. vertexShader: shader.vertexShader,
  8202. fragmentShader: shader.fragmentShader,
  8203. side: BackSide,
  8204. blending: NoBlending
  8205. } );
  8206. material.uniforms.tEquirect.value = texture;
  8207. var mesh = new Mesh( new BoxBufferGeometry( 5, 5, 5 ), material );
  8208. scene.add( mesh );
  8209. var camera = new CubeCamera( 1, 10, 1 );
  8210. camera.renderTarget = this;
  8211. camera.renderTarget.texture.name = 'CubeCameraTexture';
  8212. camera.update( renderer, scene );
  8213. mesh.geometry.dispose();
  8214. mesh.material.dispose();
  8215. return this;
  8216. };
  8217. /**
  8218. * @author alteredq / http://alteredqualia.com/
  8219. */
  8220. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  8221. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  8222. this.image = { data: data, width: width, height: height };
  8223. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8224. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8225. this.generateMipmaps = false;
  8226. this.flipY = false;
  8227. this.unpackAlignment = 1;
  8228. }
  8229. DataTexture.prototype = Object.create( Texture.prototype );
  8230. DataTexture.prototype.constructor = DataTexture;
  8231. DataTexture.prototype.isDataTexture = true;
  8232. /**
  8233. * @author bhouston / http://clara.io
  8234. */
  8235. function Plane( normal, constant ) {
  8236. // normal is assumed to be normalized
  8237. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  8238. this.constant = ( constant !== undefined ) ? constant : 0;
  8239. }
  8240. Object.assign( Plane.prototype, {
  8241. isPlane: true,
  8242. set: function ( normal, constant ) {
  8243. this.normal.copy( normal );
  8244. this.constant = constant;
  8245. return this;
  8246. },
  8247. setComponents: function ( x, y, z, w ) {
  8248. this.normal.set( x, y, z );
  8249. this.constant = w;
  8250. return this;
  8251. },
  8252. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  8253. this.normal.copy( normal );
  8254. this.constant = - point.dot( this.normal );
  8255. return this;
  8256. },
  8257. setFromCoplanarPoints: function () {
  8258. var v1 = new Vector3();
  8259. var v2 = new Vector3();
  8260. return function setFromCoplanarPoints( a, b, c ) {
  8261. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  8262. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  8263. this.setFromNormalAndCoplanarPoint( normal, a );
  8264. return this;
  8265. };
  8266. }(),
  8267. clone: function () {
  8268. return new this.constructor().copy( this );
  8269. },
  8270. copy: function ( plane ) {
  8271. this.normal.copy( plane.normal );
  8272. this.constant = plane.constant;
  8273. return this;
  8274. },
  8275. normalize: function () {
  8276. // Note: will lead to a divide by zero if the plane is invalid.
  8277. var inverseNormalLength = 1.0 / this.normal.length();
  8278. this.normal.multiplyScalar( inverseNormalLength );
  8279. this.constant *= inverseNormalLength;
  8280. return this;
  8281. },
  8282. negate: function () {
  8283. this.constant *= - 1;
  8284. this.normal.negate();
  8285. return this;
  8286. },
  8287. distanceToPoint: function ( point ) {
  8288. return this.normal.dot( point ) + this.constant;
  8289. },
  8290. distanceToSphere: function ( sphere ) {
  8291. return this.distanceToPoint( sphere.center ) - sphere.radius;
  8292. },
  8293. projectPoint: function ( point, target ) {
  8294. if ( target === undefined ) {
  8295. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  8296. target = new Vector3();
  8297. }
  8298. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  8299. },
  8300. intersectLine: function () {
  8301. var v1 = new Vector3();
  8302. return function intersectLine( line, target ) {
  8303. if ( target === undefined ) {
  8304. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  8305. target = new Vector3();
  8306. }
  8307. var direction = line.delta( v1 );
  8308. var denominator = this.normal.dot( direction );
  8309. if ( denominator === 0 ) {
  8310. // line is coplanar, return origin
  8311. if ( this.distanceToPoint( line.start ) === 0 ) {
  8312. return target.copy( line.start );
  8313. }
  8314. // Unsure if this is the correct method to handle this case.
  8315. return undefined;
  8316. }
  8317. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  8318. if ( t < 0 || t > 1 ) {
  8319. return undefined;
  8320. }
  8321. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  8322. };
  8323. }(),
  8324. intersectsLine: function ( line ) {
  8325. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  8326. var startSign = this.distanceToPoint( line.start );
  8327. var endSign = this.distanceToPoint( line.end );
  8328. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  8329. },
  8330. intersectsBox: function ( box ) {
  8331. return box.intersectsPlane( this );
  8332. },
  8333. intersectsSphere: function ( sphere ) {
  8334. return sphere.intersectsPlane( this );
  8335. },
  8336. coplanarPoint: function ( target ) {
  8337. if ( target === undefined ) {
  8338. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  8339. target = new Vector3();
  8340. }
  8341. return target.copy( this.normal ).multiplyScalar( - this.constant );
  8342. },
  8343. applyMatrix4: function () {
  8344. var v1 = new Vector3();
  8345. var m1 = new Matrix3();
  8346. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  8347. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  8348. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  8349. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  8350. this.constant = - referencePoint.dot( normal );
  8351. return this;
  8352. };
  8353. }(),
  8354. translate: function ( offset ) {
  8355. this.constant -= offset.dot( this.normal );
  8356. return this;
  8357. },
  8358. equals: function ( plane ) {
  8359. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  8360. }
  8361. } );
  8362. /**
  8363. * @author mrdoob / http://mrdoob.com/
  8364. * @author alteredq / http://alteredqualia.com/
  8365. * @author bhouston / http://clara.io
  8366. */
  8367. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  8368. this.planes = [
  8369. ( p0 !== undefined ) ? p0 : new Plane(),
  8370. ( p1 !== undefined ) ? p1 : new Plane(),
  8371. ( p2 !== undefined ) ? p2 : new Plane(),
  8372. ( p3 !== undefined ) ? p3 : new Plane(),
  8373. ( p4 !== undefined ) ? p4 : new Plane(),
  8374. ( p5 !== undefined ) ? p5 : new Plane()
  8375. ];
  8376. }
  8377. Object.assign( Frustum.prototype, {
  8378. set: function ( p0, p1, p2, p3, p4, p5 ) {
  8379. var planes = this.planes;
  8380. planes[ 0 ].copy( p0 );
  8381. planes[ 1 ].copy( p1 );
  8382. planes[ 2 ].copy( p2 );
  8383. planes[ 3 ].copy( p3 );
  8384. planes[ 4 ].copy( p4 );
  8385. planes[ 5 ].copy( p5 );
  8386. return this;
  8387. },
  8388. clone: function () {
  8389. return new this.constructor().copy( this );
  8390. },
  8391. copy: function ( frustum ) {
  8392. var planes = this.planes;
  8393. for ( var i = 0; i < 6; i ++ ) {
  8394. planes[ i ].copy( frustum.planes[ i ] );
  8395. }
  8396. return this;
  8397. },
  8398. setFromMatrix: function ( m ) {
  8399. var planes = this.planes;
  8400. var me = m.elements;
  8401. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  8402. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  8403. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  8404. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  8405. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  8406. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  8407. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  8408. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  8409. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  8410. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  8411. return this;
  8412. },
  8413. intersectsObject: function () {
  8414. var sphere = new Sphere();
  8415. return function intersectsObject( object ) {
  8416. var geometry = object.geometry;
  8417. if ( geometry.boundingSphere === null )
  8418. geometry.computeBoundingSphere();
  8419. sphere.copy( geometry.boundingSphere )
  8420. .applyMatrix4( object.matrixWorld );
  8421. return this.intersectsSphere( sphere );
  8422. };
  8423. }(),
  8424. intersectsSprite: function () {
  8425. var sphere = new Sphere();
  8426. return function intersectsSprite( sprite ) {
  8427. sphere.center.set( 0, 0, 0 );
  8428. sphere.radius = 0.7071067811865476;
  8429. sphere.applyMatrix4( sprite.matrixWorld );
  8430. return this.intersectsSphere( sphere );
  8431. };
  8432. }(),
  8433. intersectsSphere: function ( sphere ) {
  8434. var planes = this.planes;
  8435. var center = sphere.center;
  8436. var negRadius = - sphere.radius;
  8437. for ( var i = 0; i < 6; i ++ ) {
  8438. var distance = planes[ i ].distanceToPoint( center );
  8439. if ( distance < negRadius ) {
  8440. return false;
  8441. }
  8442. }
  8443. return true;
  8444. },
  8445. intersectsBox: function () {
  8446. var p = new Vector3();
  8447. return function intersectsBox( box ) {
  8448. var planes = this.planes;
  8449. for ( var i = 0; i < 6; i ++ ) {
  8450. var plane = planes[ i ];
  8451. // corner at max distance
  8452. p.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8453. p.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8454. p.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8455. if ( plane.distanceToPoint( p ) < 0 ) {
  8456. return false;
  8457. }
  8458. }
  8459. return true;
  8460. };
  8461. }(),
  8462. containsPoint: function ( point ) {
  8463. var planes = this.planes;
  8464. for ( var i = 0; i < 6; i ++ ) {
  8465. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  8466. return false;
  8467. }
  8468. }
  8469. return true;
  8470. }
  8471. } );
  8472. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8473. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8474. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8475. 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";
  8476. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8477. var begin_vertex = "vec3 transformed = vec3( position );";
  8478. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8479. var bsdfs = /* glsl */ `
  8480. // Analytical approximation of the DFG LUT, one half of the
  8481. // split-sum approximation used in indirect specular lighting.
  8482. // via 'environmentBRDF' from "Physically Based Shading on Mobile"
  8483. // https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile
  8484. vec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {
  8485. const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );
  8486. const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );
  8487. vec4 r = roughness * c0 + c1;
  8488. float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;
  8489. return vec2( -1.04, 1.04 ) * a004 + r.zw;
  8490. }
  8491. float punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {
  8492. #if defined ( PHYSICALLY_CORRECT_LIGHTS )
  8493. // based upon Frostbite 3 Moving to Physically-based Rendering
  8494. // page 32, equation 26: E[window1]
  8495. // https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  8496. // this is intended to be used on spot and point lights who are represented as luminous intensity
  8497. // but who must be converted to luminous irradiance for surface lighting calculation
  8498. float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );
  8499. if( cutoffDistance > 0.0 ) {
  8500. distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );
  8501. }
  8502. return distanceFalloff;
  8503. #else
  8504. if( cutoffDistance > 0.0 && decayExponent > 0.0 ) {
  8505. return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );
  8506. }
  8507. return 1.0;
  8508. #endif
  8509. }
  8510. vec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {
  8511. return RECIPROCAL_PI * diffuseColor;
  8512. } // validated
  8513. vec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {
  8514. // Original approximation by Christophe Schlick '94
  8515. // float fresnel = pow( 1.0 - dotLH, 5.0 );
  8516. // Optimized variant (presented by Epic at SIGGRAPH '13)
  8517. // https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf
  8518. float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );
  8519. return ( 1.0 - specularColor ) * fresnel + specularColor;
  8520. } // validated
  8521. vec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {
  8522. // See F_Schlick
  8523. float fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );
  8524. vec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;
  8525. return Fr * fresnel + F0;
  8526. }
  8527. // Microfacet Models for Refraction through Rough Surfaces - equation (34)
  8528. // http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html
  8529. // alpha is "roughness squared" in Disney’s reparameterization
  8530. float G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {
  8531. // geometry term (normalized) = G(l)⋅G(v) / 4(n⋅l)(n⋅v)
  8532. // also see #12151
  8533. float a2 = pow2( alpha );
  8534. float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
  8535. float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
  8536. return 1.0 / ( gl * gv );
  8537. } // validated
  8538. // Moving Frostbite to Physically Based Rendering 3.0 - page 12, listing 2
  8539. // https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  8540. float G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {
  8541. float a2 = pow2( alpha );
  8542. // dotNL and dotNV are explicitly swapped. This is not a mistake.
  8543. float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
  8544. float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
  8545. return 0.5 / max( gv + gl, EPSILON );
  8546. }
  8547. // Microfacet Models for Refraction through Rough Surfaces - equation (33)
  8548. // http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html
  8549. // alpha is "roughness squared" in Disney’s reparameterization
  8550. float D_GGX( const in float alpha, const in float dotNH ) {
  8551. float a2 = pow2( alpha );
  8552. float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; // avoid alpha = 0 with dotNH = 1
  8553. return RECIPROCAL_PI * a2 / pow2( denom );
  8554. }
  8555. // GGX Distribution, Schlick Fresnel, GGX-Smith Visibility
  8556. vec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
  8557. float alpha = pow2( roughness ); // UE4's roughness
  8558. vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );
  8559. float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );
  8560. float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
  8561. float dotNH = saturate( dot( geometry.normal, halfDir ) );
  8562. float dotLH = saturate( dot( incidentLight.direction, halfDir ) );
  8563. vec3 F = F_Schlick( specularColor, dotLH );
  8564. float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );
  8565. float D = D_GGX( alpha, dotNH );
  8566. return F * ( G * D );
  8567. } // validated
  8568. #ifndef STANDARD
  8569. vec3 BRDF_ClearCoat_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
  8570. float alpha = pow2( roughness ); // UE4's roughness
  8571. vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );
  8572. float dotNL = saturate( dot( geometry.clearCoatNormal, incidentLight.direction ) );
  8573. float dotNV = saturate( dot( geometry.clearCoatNormal, geometry.viewDir ) );
  8574. float dotNH = saturate( dot( geometry.clearCoatNormal, halfDir ) );
  8575. float dotLH = saturate( dot( incidentLight.direction, halfDir ) );
  8576. vec3 F = F_Schlick( specularColor, dotLH );
  8577. float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );
  8578. float D = D_GGX( alpha, dotNH );
  8579. return F * ( G * D );
  8580. }
  8581. #endif
  8582. // Rect Area Light
  8583. // Real-Time Polygonal-Light Shading with Linearly Transformed Cosines
  8584. // by Eric Heitz, Jonathan Dupuy, Stephen Hill and David Neubelt
  8585. // code: https://github.com/selfshadow/ltc_code/
  8586. vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {
  8587. const float LUT_SIZE = 64.0;
  8588. const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;
  8589. const float LUT_BIAS = 0.5 / LUT_SIZE;
  8590. float dotNV = saturate( dot( N, V ) );
  8591. // texture parameterized by sqrt( GGX alpha ) and sqrt( 1 - cos( theta ) )
  8592. vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );
  8593. uv = uv * LUT_SCALE + LUT_BIAS;
  8594. return uv;
  8595. }
  8596. float LTC_ClippedSphereFormFactor( const in vec3 f ) {
  8597. // Real-Time Area Lighting: a Journey from Research to Production (p.102)
  8598. // An approximation of the form factor of a horizon-clipped rectangle.
  8599. float l = length( f );
  8600. return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );
  8601. }
  8602. vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {
  8603. float x = dot( v1, v2 );
  8604. float y = abs( x );
  8605. // rational polynomial approximation to theta / sin( theta ) / 2PI
  8606. float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;
  8607. float b = 3.4175940 + ( 4.1616724 + y ) * y;
  8608. float v = a / b;
  8609. float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;
  8610. return cross( v1, v2 ) * theta_sintheta;
  8611. }
  8612. vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {
  8613. // bail if point is on back side of plane of light
  8614. // assumes ccw winding order of light vertices
  8615. vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];
  8616. vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];
  8617. vec3 lightNormal = cross( v1, v2 );
  8618. if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );
  8619. // construct orthonormal basis around N
  8620. vec3 T1, T2;
  8621. T1 = normalize( V - N * dot( V, N ) );
  8622. T2 = - cross( N, T1 ); // negated from paper; possibly due to a different handedness of world coordinate system
  8623. // compute transform
  8624. mat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );
  8625. // transform rect
  8626. vec3 coords[ 4 ];
  8627. coords[ 0 ] = mat * ( rectCoords[ 0 ] - P );
  8628. coords[ 1 ] = mat * ( rectCoords[ 1 ] - P );
  8629. coords[ 2 ] = mat * ( rectCoords[ 2 ] - P );
  8630. coords[ 3 ] = mat * ( rectCoords[ 3 ] - P );
  8631. // project rect onto sphere
  8632. coords[ 0 ] = normalize( coords[ 0 ] );
  8633. coords[ 1 ] = normalize( coords[ 1 ] );
  8634. coords[ 2 ] = normalize( coords[ 2 ] );
  8635. coords[ 3 ] = normalize( coords[ 3 ] );
  8636. // calculate vector form factor
  8637. vec3 vectorFormFactor = vec3( 0.0 );
  8638. vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );
  8639. vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );
  8640. vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );
  8641. vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );
  8642. // adjust for horizon clipping
  8643. float result = LTC_ClippedSphereFormFactor( vectorFormFactor );
  8644. /*
  8645. // alternate method of adjusting for horizon clipping (see referece)
  8646. // refactoring required
  8647. float len = length( vectorFormFactor );
  8648. float z = vectorFormFactor.z / len;
  8649. const float LUT_SIZE = 64.0;
  8650. const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;
  8651. const float LUT_BIAS = 0.5 / LUT_SIZE;
  8652. // tabulated horizon-clipped sphere, apparently...
  8653. vec2 uv = vec2( z * 0.5 + 0.5, len );
  8654. uv = uv * LUT_SCALE + LUT_BIAS;
  8655. float scale = texture2D( ltc_2, uv ).w;
  8656. float result = len * scale;
  8657. */
  8658. return vec3( result );
  8659. }
  8660. // End Rect Area Light
  8661. // ref: https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile
  8662. vec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
  8663. float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
  8664. vec2 brdf = integrateSpecularBRDF( dotNV, roughness );
  8665. return specularColor * brdf.x + brdf.y;
  8666. } // validated
  8667. #ifndef STANDARD
  8668. vec3 BRDF_ClearCoat_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
  8669. float dotNV = saturate( dot( geometry.clearCoatNormal, geometry.viewDir ) );
  8670. vec2 brdf = integrateSpecularBRDF( dotNV, roughness );
  8671. return specularColor * brdf.x + brdf.y;
  8672. }
  8673. #endif
  8674. // Fdez-Agüera's "Multiple-Scattering Microfacet Model for Real-Time Image Based Lighting"
  8675. // Approximates multiscattering in order to preserve energy.
  8676. // http://www.jcgt.org/published/0008/01/03/
  8677. void BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {
  8678. float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
  8679. vec3 F = F_Schlick_RoughnessDependent( specularColor, dotNV, roughness );
  8680. vec2 brdf = integrateSpecularBRDF( dotNV, roughness );
  8681. vec3 FssEss = F * brdf.x + brdf.y;
  8682. float Ess = brdf.x + brdf.y;
  8683. float Ems = 1.0 - Ess;
  8684. vec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619; // 1/21
  8685. vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );
  8686. singleScatter += FssEss;
  8687. multiScatter += Fms * Ems;
  8688. }
  8689. float G_BlinnPhong_Implicit( /* const in float dotNL, const in float dotNV */ ) {
  8690. // geometry term is (n dot l)(n dot v) / 4(n dot l)(n dot v)
  8691. return 0.25;
  8692. }
  8693. float D_BlinnPhong( const in float shininess, const in float dotNH ) {
  8694. return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );
  8695. }
  8696. vec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {
  8697. vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );
  8698. //float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );
  8699. //float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
  8700. float dotNH = saturate( dot( geometry.normal, halfDir ) );
  8701. float dotLH = saturate( dot( incidentLight.direction, halfDir ) );
  8702. vec3 F = F_Schlick( specularColor, dotLH );
  8703. float G = G_BlinnPhong_Implicit( /* dotNL, dotNV */ );
  8704. float D = D_BlinnPhong( shininess, dotNH );
  8705. return F * ( G * D );
  8706. } // validated
  8707. // source: http://simonstechblog.blogspot.ca/2011/12/microfacet-brdf.html
  8708. float GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {
  8709. return ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );
  8710. }
  8711. float BlinnExponentToGGXRoughness( const in float blinnExponent ) {
  8712. return sqrt( 2.0 / ( blinnExponent + 2.0 ) );
  8713. }
  8714. `;
  8715. 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";
  8716. 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";
  8717. 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";
  8718. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvarying vec3 vViewPosition;\n#endif";
  8719. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif";
  8720. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8721. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8722. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8723. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  8724. var common = /* glsl */ `
  8725. #define PI 3.14159265359
  8726. #define PI2 6.28318530718
  8727. #define PI_HALF 1.5707963267949
  8728. #define RECIPROCAL_PI 0.31830988618
  8729. #define RECIPROCAL_PI2 0.15915494
  8730. #define LOG2 1.442695
  8731. #define EPSILON 1e-6
  8732. #define saturate(a) clamp( a, 0.0, 1.0 )
  8733. #define whiteCompliment(a) ( 1.0 - saturate( a ) )
  8734. float pow2( const in float x ) { return x*x; }
  8735. float pow3( const in float x ) { return x*x*x; }
  8736. float pow4( const in float x ) { float x2 = x*x; return x2*x2; }
  8737. float average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }
  8738. // expects values in the range of [0,1]x[0,1], returns values in the [0,1] range.
  8739. // do not collapse into a single function per: http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/
  8740. highp float rand( const in vec2 uv ) {
  8741. const highp float a = 12.9898, b = 78.233, c = 43758.5453;
  8742. highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );
  8743. return fract(sin(sn) * c);
  8744. }
  8745. struct IncidentLight {
  8746. vec3 color;
  8747. vec3 direction;
  8748. bool visible;
  8749. };
  8750. struct ReflectedLight {
  8751. vec3 directDiffuse;
  8752. vec3 directSpecular;
  8753. vec3 indirectDiffuse;
  8754. vec3 indirectSpecular;
  8755. };
  8756. struct GeometricContext {
  8757. vec3 position;
  8758. vec3 normal;
  8759. vec3 viewDir;
  8760. #ifndef STANDARD
  8761. vec3 clearCoatNormal;
  8762. #endif
  8763. };
  8764. vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
  8765. return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
  8766. }
  8767. // http://en.wikibooks.org/wiki/GLSL_Programming/Applying_Matrix_Transformations
  8768. vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {
  8769. return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );
  8770. }
  8771. vec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
  8772. float distance = dot( planeNormal, point - pointOnPlane );
  8773. return - distance * planeNormal + point;
  8774. }
  8775. float sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
  8776. return sign( dot( point - pointOnPlane, planeNormal ) );
  8777. }
  8778. vec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {
  8779. return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;
  8780. }
  8781. mat3 transposeMat3( const in mat3 m ) {
  8782. mat3 tmp;
  8783. tmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );
  8784. tmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );
  8785. tmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );
  8786. return tmp;
  8787. }
  8788. // https://en.wikipedia.org/wiki/Relative_luminance
  8789. float linearToRelativeLuminance( const in vec3 color ) {
  8790. vec3 weights = vec3( 0.2126, 0.7152, 0.0722 );
  8791. return dot( weights, color.rgb );
  8792. }
  8793. `;
  8794. 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";
  8795. 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";
  8796. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8797. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif";
  8798. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8799. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8800. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8801. 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}";
  8802. var envmap_fragment = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_CLEARCOAT_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";
  8803. 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( USE_CLEARCOAT_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( USE_CLEARCOAT_NORMALMAP ) || defined( PHONG ) || defined( PHYSICAL )\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif";
  8804. var envmap_pars_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_CLEARCOAT_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";
  8805. var envmap_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_CLEARCOAT_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";
  8806. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = -mvPosition.z;\n#endif";
  8807. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8808. 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";
  8809. 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";
  8810. 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";
  8811. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif";
  8812. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8813. 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";
  8814. 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";
  8815. var envmap_physical_pars_fragment = /* glsl */ `
  8816. #if defined( USE_ENVMAP ) && defined( PHYSICAL )
  8817. vec3 getLightProbeIndirectIrradiance( /*const in SpecularLightProbe specularLightProbe,*/ const in GeometricContext geometry, const in int maxMIPLevel ) {
  8818. vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );
  8819. #ifdef ENVMAP_TYPE_CUBE
  8820. vec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );
  8821. // TODO: replace with properly filtered cubemaps and access the irradiance LOD level, be it the last LOD level
  8822. // of a specular cubemap, or just the default level of a specially created irradiance cubemap.
  8823. #ifdef TEXTURE_LOD_EXT
  8824. vec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );
  8825. #else
  8826. // force the bias high to get the last LOD level as it is the most blurred.
  8827. vec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );
  8828. #endif
  8829. envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
  8830. #elif defined( ENVMAP_TYPE_CUBE_UV )
  8831. vec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );
  8832. vec4 envMapColor = textureCubeUV( envMap, queryVec, 1.0 );
  8833. #else
  8834. vec4 envMapColor = vec4( 0.0 );
  8835. #endif
  8836. return PI * envMapColor.rgb * envMapIntensity;
  8837. }
  8838. // taken from here: http://casual-effects.blogspot.ca/2011/08/plausible-environment-lighting-in-two.html
  8839. float getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {
  8840. //float envMapWidth = pow( 2.0, maxMIPLevelScalar );
  8841. //float desiredMIPLevel = log2( envMapWidth * sqrt( 3.0 ) ) - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );
  8842. float maxMIPLevelScalar = float( maxMIPLevel );
  8843. float desiredMIPLevel = maxMIPLevelScalar + 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );
  8844. // clamp to allowable LOD ranges.
  8845. return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );
  8846. }
  8847. vec3 getLightProbeIndirectRadiance( /*const in SpecularLightProbe specularLightProbe,*/ const in vec3 viewDir, const in vec3 normal, const in float blinnShininessExponent, const in int maxMIPLevel ) {
  8848. #ifdef ENVMAP_MODE_REFLECTION
  8849. vec3 reflectVec = reflect( -viewDir, normal );
  8850. #else
  8851. vec3 reflectVec = refract( -viewDir, normal, refractionRatio );
  8852. #endif
  8853. reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
  8854. float specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel );
  8855. #ifdef ENVMAP_TYPE_CUBE
  8856. vec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );
  8857. #ifdef TEXTURE_LOD_EXT
  8858. vec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );
  8859. #else
  8860. vec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );
  8861. #endif
  8862. envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
  8863. #elif defined( ENVMAP_TYPE_CUBE_UV )
  8864. vec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );
  8865. vec4 envMapColor = textureCubeUV( envMap, queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent ));
  8866. #elif defined( ENVMAP_TYPE_EQUIREC )
  8867. vec2 sampleUV;
  8868. sampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
  8869. sampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;
  8870. #ifdef TEXTURE_LOD_EXT
  8871. vec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );
  8872. #else
  8873. vec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );
  8874. #endif
  8875. envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
  8876. #elif defined( ENVMAP_TYPE_SPHERE )
  8877. vec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) );
  8878. #ifdef TEXTURE_LOD_EXT
  8879. vec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );
  8880. #else
  8881. vec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );
  8882. #endif
  8883. envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
  8884. #endif
  8885. return envMapColor.rgb * envMapIntensity;
  8886. }
  8887. #endif
  8888. `;
  8889. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8890. 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)";
  8891. 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";
  8892. var lights_physical_pars_fragment = /* glsl */ `
  8893. struct PhysicalMaterial {
  8894. vec3 diffuseColor;
  8895. float specularRoughness;
  8896. vec3 specularColor;
  8897. #ifndef STANDARD
  8898. float clearCoat;
  8899. float clearCoatRoughness;
  8900. #endif
  8901. };
  8902. #define MAXIMUM_SPECULAR_COEFFICIENT 0.16
  8903. #define DEFAULT_SPECULAR_COEFFICIENT 0.04
  8904. // Clear coat directional hemishperical reflectance (this approximation should be improved)
  8905. float clearCoatDHRApprox( const in float roughness, const in float dotNL ) {
  8906. return DEFAULT_SPECULAR_COEFFICIENT + ( 1.0 - DEFAULT_SPECULAR_COEFFICIENT ) * ( pow( 1.0 - dotNL, 5.0 ) * pow( 1.0 - roughness, 2.0 ) );
  8907. }
  8908. #if NUM_RECT_AREA_LIGHTS > 0
  8909. void RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
  8910. vec3 normal = geometry.normal;
  8911. vec3 viewDir = geometry.viewDir;
  8912. vec3 position = geometry.position;
  8913. vec3 lightPos = rectAreaLight.position;
  8914. vec3 halfWidth = rectAreaLight.halfWidth;
  8915. vec3 halfHeight = rectAreaLight.halfHeight;
  8916. vec3 lightColor = rectAreaLight.color;
  8917. float roughness = material.specularRoughness;
  8918. vec3 rectCoords[ 4 ];
  8919. rectCoords[ 0 ] = lightPos + halfWidth - halfHeight; // counterclockwise; light shines in local neg z direction
  8920. rectCoords[ 1 ] = lightPos - halfWidth - halfHeight;
  8921. rectCoords[ 2 ] = lightPos - halfWidth + halfHeight;
  8922. rectCoords[ 3 ] = lightPos + halfWidth + halfHeight;
  8923. vec2 uv = LTC_Uv( normal, viewDir, roughness );
  8924. vec4 t1 = texture2D( ltc_1, uv );
  8925. vec4 t2 = texture2D( ltc_2, uv );
  8926. mat3 mInv = mat3(
  8927. vec3( t1.x, 0, t1.y ),
  8928. vec3( 0, 1, 0 ),
  8929. vec3( t1.z, 0, t1.w )
  8930. );
  8931. // LTC Fresnel Approximation by Stephen Hill
  8932. // http://blog.selfshadow.com/publications/s2016-advances/s2016_ltc_fresnel.pdf
  8933. vec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );
  8934. reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );
  8935. reflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );
  8936. }
  8937. #endif
  8938. void RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
  8939. float dotNL = saturate( dot( geometry.normal, directLight.direction ) );
  8940. vec3 irradiance = dotNL * directLight.color;
  8941. #ifndef PHYSICALLY_CORRECT_LIGHTS
  8942. irradiance *= PI; // punctual light
  8943. #endif
  8944. #ifndef STANDARD
  8945. float ccDotNV = saturate( dot( geometry.clearCoatNormal, geometry.viewDir ) );
  8946. float ccDotNL = ccDotNV;
  8947. float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, ccDotNL );
  8948. #else
  8949. float clearCoatDHR = 0.0;
  8950. #endif
  8951. reflectedLight.directSpecular += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );
  8952. reflectedLight.directDiffuse += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );
  8953. #ifndef STANDARD
  8954. reflectedLight.directSpecular += irradiance * material.clearCoat * BRDF_ClearCoat_GGX( directLight, geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
  8955. #endif
  8956. }
  8957. void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
  8958. // Defer to the IndirectSpecular function to compute
  8959. // the indirectDiffuse if energy preservation is enabled.
  8960. #ifndef ENVMAP_TYPE_CUBE_UV
  8961. reflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );
  8962. #endif
  8963. }
  8964. void 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) {
  8965. #ifndef STANDARD
  8966. float ccDotNV = saturate( dot( geometry.clearCoatNormal, geometry.viewDir ) );
  8967. float ccDotNL = ccDotNV;
  8968. float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, ccDotNL );
  8969. #else
  8970. float clearCoatDHR = 0.0;
  8971. #endif
  8972. float clearCoatInv = 1.0 - clearCoatDHR;
  8973. // Both indirect specular and diffuse light accumulate here
  8974. // if energy preservation enabled, and PMREM provided.
  8975. #if defined( ENVMAP_TYPE_CUBE_UV )
  8976. vec3 singleScattering = vec3( 0.0 );
  8977. vec3 multiScattering = vec3( 0.0 );
  8978. vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;
  8979. BRDF_Specular_Multiscattering_Environment( geometry, material.specularColor, material.specularRoughness, singleScattering, multiScattering );
  8980. vec3 diffuse = material.diffuseColor * ( 1.0 - ( singleScattering + multiScattering ) );
  8981. reflectedLight.indirectSpecular += clearCoatInv * radiance * singleScattering;
  8982. reflectedLight.indirectDiffuse += multiScattering * cosineWeightedIrradiance;
  8983. reflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;
  8984. #else
  8985. reflectedLight.indirectSpecular += clearCoatInv * radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );
  8986. #endif
  8987. #ifndef STANDARD
  8988. reflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_ClearCoat_GGX_Environment( geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
  8989. #endif
  8990. }
  8991. #define RE_Direct RE_Direct_Physical
  8992. #define RE_Direct_RectArea RE_Direct_RectArea_Physical
  8993. #define RE_IndirectDiffuse RE_IndirectDiffuse_Physical
  8994. #define RE_IndirectSpecular RE_IndirectSpecular_Physical
  8995. #define Material_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.specularRoughness )
  8996. #define Material_ClearCoat_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.clearCoatRoughness )
  8997. // ref: https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  8998. float computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {
  8999. return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );
  9000. }
  9001. `;
  9002. var lights_fragment_begin = /* glsl */ `
  9003. /**
  9004. * This is a template that can be used to light a material, it uses pluggable
  9005. * RenderEquations (RE)for specific lighting scenarios.
  9006. *
  9007. * Instructions for use:
  9008. * - Ensure that both RE_Direct, RE_IndirectDiffuse and RE_IndirectSpecular are defined
  9009. * - If you have defined an RE_IndirectSpecular, you need to also provide a Material_LightProbeLOD. <---- ???
  9010. * - Create a material parameter that is to be passed as the third parameter to your lighting functions.
  9011. *
  9012. * TODO:
  9013. * - Add area light support.
  9014. * - Add sphere light support.
  9015. * - Add diffuse light probe (irradiance cubemap) support.
  9016. */
  9017. GeometricContext geometry;
  9018. geometry.position = - vViewPosition;
  9019. geometry.normal = normal;
  9020. geometry.viewDir = normalize( vViewPosition );
  9021. #ifndef STANDARD
  9022. geometry.clearCoatNormal = clearCoatNormal;
  9023. #endif
  9024. IncidentLight directLight;
  9025. #if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )
  9026. PointLight pointLight;
  9027. #pragma unroll_loop
  9028. for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
  9029. pointLight = pointLights[ i ];
  9030. getPointDirectLightIrradiance( pointLight, geometry, directLight );
  9031. #ifdef USE_SHADOWMAP
  9032. directLight.color *= all( bvec2( pointLight.shadow, directLight.visible ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;
  9033. #endif
  9034. RE_Direct( directLight, geometry, material, reflectedLight );
  9035. }
  9036. #endif
  9037. #if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )
  9038. SpotLight spotLight;
  9039. #pragma unroll_loop
  9040. for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
  9041. spotLight = spotLights[ i ];
  9042. getSpotDirectLightIrradiance( spotLight, geometry, directLight );
  9043. #ifdef USE_SHADOWMAP
  9044. directLight.color *= all( bvec2( spotLight.shadow, directLight.visible ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;
  9045. #endif
  9046. RE_Direct( directLight, geometry, material, reflectedLight );
  9047. }
  9048. #endif
  9049. #if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )
  9050. DirectionalLight directionalLight;
  9051. #pragma unroll_loop
  9052. for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
  9053. directionalLight = directionalLights[ i ];
  9054. getDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );
  9055. #ifdef USE_SHADOWMAP
  9056. directLight.color *= all( bvec2( directionalLight.shadow, directLight.visible ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
  9057. #endif
  9058. RE_Direct( directLight, geometry, material, reflectedLight );
  9059. }
  9060. #endif
  9061. #if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )
  9062. RectAreaLight rectAreaLight;
  9063. #pragma unroll_loop
  9064. for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
  9065. rectAreaLight = rectAreaLights[ i ];
  9066. RE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );
  9067. }
  9068. #endif
  9069. #if defined( RE_IndirectDiffuse )
  9070. vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
  9071. irradiance += getLightProbeIrradiance( lightProbe, geometry );
  9072. #if ( NUM_HEMI_LIGHTS > 0 )
  9073. #pragma unroll_loop
  9074. for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
  9075. irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );
  9076. }
  9077. #endif
  9078. #endif
  9079. #if defined( RE_IndirectSpecular )
  9080. vec3 radiance = vec3( 0.0 );
  9081. vec3 clearCoatRadiance = vec3( 0.0 );
  9082. #endif
  9083. `;
  9084. var lights_fragment_maps = /* glsl */ `
  9085. #if defined( RE_IndirectDiffuse )
  9086. #ifdef USE_LIGHTMAP
  9087. vec3 lightMapIrradiance = texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;
  9088. #ifndef PHYSICALLY_CORRECT_LIGHTS
  9089. lightMapIrradiance *= PI; // factor of PI should not be present; included here to prevent breakage
  9090. #endif
  9091. irradiance += lightMapIrradiance;
  9092. #endif
  9093. #if defined( USE_ENVMAP ) && defined( PHYSICAL ) && defined( ENVMAP_TYPE_CUBE_UV )
  9094. irradiance += getLightProbeIndirectIrradiance( /*lightProbe,*/ geometry, maxMipLevel );
  9095. #endif
  9096. #endif
  9097. #if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
  9098. radiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry.viewDir, geometry.normal, Material_BlinnShininessExponent( material ), maxMipLevel );
  9099. #ifndef STANDARD
  9100. clearCoatRadiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry.viewDir, geometry.clearCoatNormal,Material_ClearCoat_BlinnShininessExponent( material ), maxMipLevel );
  9101. #endif
  9102. #endif
  9103. `;
  9104. 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";
  9105. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  9106. var logdepthbuf_pars_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n#endif";
  9107. 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";
  9108. 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";
  9109. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  9110. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  9111. 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";
  9112. var map_particle_pars_fragment = "#ifdef USE_MAP\n\tuniform mat3 uvTransform;\n\tuniform sampler2D map;\n#endif";
  9113. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  9114. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  9115. 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";
  9116. 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";
  9117. 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";
  9118. var normal_fragment_begin = /* glsl */ `
  9119. #ifdef FLAT_SHADED
  9120. // Workaround for Adreno/Nexus5 not able able to do dFdx( vViewPosition ) ...
  9121. vec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );
  9122. vec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );
  9123. vec3 normal = normalize( cross( fdx, fdy ) );
  9124. #else
  9125. vec3 normal = normalize( vNormal );
  9126. #ifdef DOUBLE_SIDED
  9127. normal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
  9128. #endif
  9129. #ifdef USE_TANGENT
  9130. vec3 tangent = normalize( vTangent );
  9131. vec3 bitangent = normalize( vBitangent );
  9132. #ifdef DOUBLE_SIDED
  9133. tangent = tangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
  9134. bitangent = bitangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
  9135. #endif
  9136. #endif
  9137. #endif
  9138. #ifndef STANDARD
  9139. vec3 geometryNormal = normal;
  9140. #endif
  9141. `;
  9142. 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";
  9143. 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";
  9144. var clearcoat_normal_fragment_begin = /* glsl */ `
  9145. #ifndef STANDARD
  9146. vec3 clearCoatNormal = geometryNormal;
  9147. #endif
  9148. `;
  9149. /*
  9150. vec3 clearCoatNormal = clearCoatGeometryNormals ?
  9151. geometryNormal: // use the unperturbed normal of the geometry
  9152. normal; // Use the (maybe) perturbed normal
  9153. */
  9154. var clearcoat_normal_fragment_maps = /* glsl */ `
  9155. #if defined( USE_NORMALMAP )
  9156. #ifdef USE_TANGENT
  9157. mat3 vTBN = mat3( tangent, bitangent, clearCoatNormal );
  9158. vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
  9159. mapN.xy = clearCoatNormalScale * mapN.xy;
  9160. clearCoatNormal = normalize( vTBN * mapN );
  9161. #else
  9162. clearCoatNormal = perturbClearCoatNormal2Arb( -vViewPosition, clearCoatNormal );
  9163. #endif
  9164. #endif
  9165. `;
  9166. /*
  9167. #if defined( USE_NORMALMAP )
  9168. #ifdef USE_TANGENT
  9169. mat3 vTBN = mat3( tangent, bitangent, normal );
  9170. vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
  9171. mapN.xy = clearCoatnormalScale * mapN.xy;
  9172. clearCoatNormal = normalize( vTBN * mapN );
  9173. #else
  9174. clearCoatNormal = perturbClearCoatNormal2Arb( -vViewPosition, clearCoatNormal );
  9175. #endif
  9176. #endif
  9177. */
  9178. /*
  9179. #if defined( USE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )
  9180. //#ifdef OBJECTSPACE_NORMALMAP
  9181. normal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0; // overrides both flatShading and attribute normals
  9182. #ifdef FLIP_SIDED
  9183. normal = - normal;
  9184. #endif
  9185. #ifdef DOUBLE_SIDED
  9186. normal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
  9187. #endif
  9188. normal = normalize( normalMatrix * normal );
  9189. //#else // tangent-space normal map
  9190. #ifdef USE_TANGENT
  9191. mat3 vTBN = mat3( tangent, bitangent, normal );
  9192. vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
  9193. mapN.xy = normalScale * mapN.xy;
  9194. normal = normalize( vTBN * mapN );
  9195. #else
  9196. normal = perturbNormal2Arb( -vViewPosition, normal );
  9197. #endif
  9198. //#endif
  9199. #elif defined( USE_BUMPMAP )
  9200. normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );
  9201. #endif
  9202. */
  9203. var clearcoat_normalmap_pars_fragment = /* glsl */ `
  9204. #ifdef USE_NORMALMAP
  9205. //uniform sampler2D normalMap;
  9206. uniform vec2 clearCoatNormalScale;
  9207. // Per-Pixel Tangent Space Normal Mapping
  9208. // http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html
  9209. vec3 perturbClearCoatNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {
  9210. // Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988
  9211. vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );
  9212. vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );
  9213. vec2 st0 = dFdx( vUv.st );
  9214. vec2 st1 = dFdy( vUv.st );
  9215. float scale = sign( st1.t * st0.s - st0.t * st1.s ); // we do not care about the magnitude
  9216. vec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );
  9217. vec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );
  9218. vec3 N = normalize( surf_norm );
  9219. mat3 tsn = mat3( S, T, N );
  9220. vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
  9221. mapN.xy *= clearCoatNormalScale;
  9222. mapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );
  9223. return normalize( tsn * mapN );
  9224. }
  9225. #endif
  9226. `;
  9227. /*
  9228. #ifdef USE_NORMALMAP
  9229. uniform sampler2D normalMap;
  9230. uniform vec2 normalScale;
  9231. #ifdef OBJECTSPACE_NORMALMAP
  9232. uniform mat3 normalMatrix;
  9233. #else
  9234. // Per-Pixel Tangent Space Normal Mapping
  9235. // http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html
  9236. vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {
  9237. // Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988
  9238. vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );
  9239. vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );
  9240. vec2 st0 = dFdx( vUv.st );
  9241. vec2 st1 = dFdy( vUv.st );
  9242. float scale = sign( st1.t * st0.s - st0.t * st1.s ); // we do not care about the magnitude
  9243. vec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );
  9244. vec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );
  9245. vec3 N = normalize( surf_norm );
  9246. mat3 tsn = mat3( S, T, N );
  9247. vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
  9248. mapN.xy *= normalScale;
  9249. mapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );
  9250. return normalize( tsn * mapN );
  9251. }
  9252. #endif
  9253. #endif
  9254. */
  9255. 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}";
  9256. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  9257. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = projectionMatrix * mvPosition;";
  9258. var dithering_fragment = "#if defined( DITHERING )\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  9259. 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";
  9260. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  9261. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  9262. 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";
  9263. 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";
  9264. 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";
  9265. 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}";
  9266. 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";
  9267. 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";
  9268. 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";
  9269. 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";
  9270. 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";
  9271. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  9272. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  9273. 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}";
  9274. var uv_pars_fragment = /* glsl */ `
  9275. #if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )
  9276. varying vec2 vUv;
  9277. #endif
  9278. `;
  9279. var uv_pars_vertex = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_CLEARCOAT_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";
  9280. var uv_vertex = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_CLEARCOAT_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";
  9281. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  9282. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  9283. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  9284. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n#endif";
  9285. 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}";
  9286. 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}";
  9287. 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}";
  9288. 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}";
  9289. 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}";
  9290. 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}";
  9291. 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}";
  9292. 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}";
  9293. 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}";
  9294. 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}";
  9295. 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}";
  9296. 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}";
  9297. 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}";
  9298. 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}";
  9299. 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}";
  9300. 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}";
  9301. 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}";
  9302. 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}";
  9303. 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}";
  9304. 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}";
  9305. var meshphysical_frag = /* glsl */ `
  9306. #define PHYSICAL
  9307. uniform vec3 diffuse;
  9308. uniform vec3 emissive;
  9309. uniform float roughness;
  9310. uniform float metalness;
  9311. uniform float opacity;
  9312. #ifndef STANDARD
  9313. uniform float clearCoat;
  9314. uniform float clearCoatRoughness;
  9315. uniform bool clearCoatGeometryNormals;
  9316. #endif
  9317. varying vec3 vViewPosition;
  9318. #ifndef FLAT_SHADED
  9319. varying vec3 vNormal;
  9320. #ifdef USE_TANGENT
  9321. varying vec3 vTangent;
  9322. varying vec3 vBitangent;
  9323. #endif
  9324. #endif
  9325. #include <common>
  9326. #include <packing>
  9327. #include <dithering_pars_fragment>
  9328. #include <color_pars_fragment>
  9329. #include <uv_pars_fragment>
  9330. #include <uv2_pars_fragment>
  9331. #include <map_pars_fragment>
  9332. #include <alphamap_pars_fragment>
  9333. #include <aomap_pars_fragment>
  9334. #include <lightmap_pars_fragment>
  9335. #include <emissivemap_pars_fragment>
  9336. #include <bsdfs>
  9337. #include <cube_uv_reflection_fragment>
  9338. #include <envmap_pars_fragment>
  9339. #include <envmap_physical_pars_fragment>
  9340. #include <fog_pars_fragment>
  9341. #include <lights_pars_begin>
  9342. #include <lights_physical_pars_fragment>
  9343. #include <shadowmap_pars_fragment>
  9344. #include <bumpmap_pars_fragment>
  9345. #include <normalmap_pars_fragment>
  9346. #include <clearcoat_normalmap_pars_fragment>
  9347. #include <roughnessmap_pars_fragment>
  9348. #include <metalnessmap_pars_fragment>
  9349. #include <logdepthbuf_pars_fragment>
  9350. #include <clipping_planes_pars_fragment>
  9351. void main() {
  9352. #include <clipping_planes_fragment>
  9353. vec4 diffuseColor = vec4( diffuse, opacity );
  9354. ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
  9355. vec3 totalEmissiveRadiance = emissive;
  9356. #include <logdepthbuf_fragment>
  9357. #include <map_fragment>
  9358. #include <color_fragment>
  9359. #include <alphamap_fragment>
  9360. #include <alphatest_fragment>
  9361. #include <roughnessmap_fragment>
  9362. #include <metalnessmap_fragment>
  9363. #include <normal_fragment_begin>
  9364. #include <normal_fragment_maps>
  9365. #include <clearcoat_normal_fragment_begin>
  9366. #include <clearcoat_normal_fragment_maps>
  9367. #include <emissivemap_fragment>
  9368. // accumulation
  9369. #include <lights_physical_fragment>
  9370. #include <lights_fragment_begin>
  9371. #include <lights_fragment_maps>
  9372. #include <lights_fragment_end>
  9373. // modulation
  9374. #include <aomap_fragment>
  9375. vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;
  9376. gl_FragColor = vec4( outgoingLight, diffuseColor.a );
  9377. #include <tonemapping_fragment>
  9378. #include <encodings_fragment>
  9379. #include <fog_fragment>
  9380. #include <premultiplied_alpha_fragment>
  9381. #include <dithering_fragment>
  9382. }
  9383. `;
  9384. 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}";
  9385. var normal_frag = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) ) || ( defined( USE_CLEARCOAT_NORMALMAP ) && ! defined( OBJECTSPACE_CLEARCOAT_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}";
  9386. var normal_vert = /* glsl */ `
  9387. #define NORMAL
  9388. #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) ) || ( defined( USE_CLEARCOAT_NORMALMAP ) && ! defined( OBJECTSPACE_CLEARCOAT_NORMALMAP ) )
  9389. varying vec3 vViewPosition;
  9390. #endif
  9391. #ifndef FLAT_SHADED
  9392. varying vec3 vNormal;
  9393. #ifdef USE_TANGENT
  9394. varying vec3 vTangent;
  9395. varying vec3 vBitangent;
  9396. #endif
  9397. #endif
  9398. #include <uv_pars_vertex>
  9399. #include <displacementmap_pars_vertex>
  9400. #include <morphtarget_pars_vertex>
  9401. #include <skinning_pars_vertex>
  9402. #include <logdepthbuf_pars_vertex>
  9403. #include <clipping_planes_pars_vertex>
  9404. void main() {
  9405. #include <uv_vertex>
  9406. #include <beginnormal_vertex>
  9407. #include <morphnormal_vertex>
  9408. #include <skinbase_vertex>
  9409. #include <skinnormal_vertex>
  9410. #include <defaultnormal_vertex>
  9411. #ifndef FLAT_SHADED // Normal computed with derivatives when FLAT_SHADED
  9412. vNormal = normalize( transformedNormal );
  9413. #ifdef USE_TANGENT
  9414. vTangent = normalize( transformedTangent );
  9415. vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );
  9416. #endif
  9417. #endif
  9418. #include <begin_vertex>
  9419. #include <morphtarget_vertex>
  9420. #include <skinning_vertex>
  9421. #include <displacementmap_vertex>
  9422. #include <project_vertex>
  9423. #include <logdepthbuf_vertex>
  9424. #include <clipping_planes_vertex>
  9425. #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) ) || ( defined( USE_CLEARCOAT_NORMALMAP ) && ! defined( OBJECTSPACE_CLEARCOAT_NORMALMAP ) )
  9426. vViewPosition = - mvPosition.xyz;
  9427. #endif
  9428. }
  9429. `;
  9430. 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}";
  9431. 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}";
  9432. 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}";
  9433. 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}";
  9434. 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}";
  9435. 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}";
  9436. var ShaderChunk = {
  9437. alphamap_fragment: alphamap_fragment,
  9438. alphamap_pars_fragment: alphamap_pars_fragment,
  9439. alphatest_fragment: alphatest_fragment,
  9440. aomap_fragment: aomap_fragment,
  9441. aomap_pars_fragment: aomap_pars_fragment,
  9442. begin_vertex: begin_vertex,
  9443. beginnormal_vertex: beginnormal_vertex,
  9444. bsdfs: bsdfs,
  9445. bumpmap_pars_fragment: bumpmap_pars_fragment,
  9446. clipping_planes_fragment: clipping_planes_fragment,
  9447. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  9448. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  9449. clipping_planes_vertex: clipping_planes_vertex,
  9450. color_fragment: color_fragment,
  9451. color_pars_fragment: color_pars_fragment,
  9452. color_pars_vertex: color_pars_vertex,
  9453. color_vertex: color_vertex,
  9454. common: common,
  9455. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  9456. defaultnormal_vertex: defaultnormal_vertex,
  9457. displacementmap_pars_vertex: displacementmap_pars_vertex,
  9458. displacementmap_vertex: displacementmap_vertex,
  9459. emissivemap_fragment: emissivemap_fragment,
  9460. emissivemap_pars_fragment: emissivemap_pars_fragment,
  9461. encodings_fragment: encodings_fragment,
  9462. encodings_pars_fragment: encodings_pars_fragment,
  9463. envmap_fragment: envmap_fragment,
  9464. envmap_pars_fragment: envmap_pars_fragment,
  9465. envmap_pars_vertex: envmap_pars_vertex,
  9466. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  9467. envmap_vertex: envmap_vertex,
  9468. fog_vertex: fog_vertex,
  9469. fog_pars_vertex: fog_pars_vertex,
  9470. fog_fragment: fog_fragment,
  9471. fog_pars_fragment: fog_pars_fragment,
  9472. gradientmap_pars_fragment: gradientmap_pars_fragment,
  9473. lightmap_fragment: lightmap_fragment,
  9474. lightmap_pars_fragment: lightmap_pars_fragment,
  9475. lights_lambert_vertex: lights_lambert_vertex,
  9476. lights_pars_begin: lights_pars_begin,
  9477. lights_phong_fragment: lights_phong_fragment,
  9478. lights_phong_pars_fragment: lights_phong_pars_fragment,
  9479. lights_physical_fragment: lights_physical_fragment,
  9480. lights_physical_pars_fragment: lights_physical_pars_fragment,
  9481. lights_fragment_begin: lights_fragment_begin,
  9482. lights_fragment_maps: lights_fragment_maps,
  9483. lights_fragment_end: lights_fragment_end,
  9484. logdepthbuf_fragment: logdepthbuf_fragment,
  9485. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  9486. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  9487. logdepthbuf_vertex: logdepthbuf_vertex,
  9488. map_fragment: map_fragment,
  9489. map_pars_fragment: map_pars_fragment,
  9490. map_particle_fragment: map_particle_fragment,
  9491. map_particle_pars_fragment: map_particle_pars_fragment,
  9492. metalnessmap_fragment: metalnessmap_fragment,
  9493. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  9494. morphnormal_vertex: morphnormal_vertex,
  9495. morphtarget_pars_vertex: morphtarget_pars_vertex,
  9496. morphtarget_vertex: morphtarget_vertex,
  9497. normal_fragment_begin: normal_fragment_begin,
  9498. normal_fragment_maps: normal_fragment_maps,
  9499. normalmap_pars_fragment: normalmap_pars_fragment,
  9500. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  9501. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  9502. clearcoat_normalmap_pars_fragment: clearcoat_normalmap_pars_fragment,
  9503. packing: packing,
  9504. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  9505. project_vertex: project_vertex,
  9506. dithering_fragment: dithering_fragment,
  9507. dithering_pars_fragment: dithering_pars_fragment,
  9508. roughnessmap_fragment: roughnessmap_fragment,
  9509. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  9510. shadowmap_pars_fragment: shadowmap_pars_fragment,
  9511. shadowmap_pars_vertex: shadowmap_pars_vertex,
  9512. shadowmap_vertex: shadowmap_vertex,
  9513. shadowmask_pars_fragment: shadowmask_pars_fragment,
  9514. skinbase_vertex: skinbase_vertex,
  9515. skinning_pars_vertex: skinning_pars_vertex,
  9516. skinning_vertex: skinning_vertex,
  9517. skinnormal_vertex: skinnormal_vertex,
  9518. specularmap_fragment: specularmap_fragment,
  9519. specularmap_pars_fragment: specularmap_pars_fragment,
  9520. tonemapping_fragment: tonemapping_fragment,
  9521. tonemapping_pars_fragment: tonemapping_pars_fragment,
  9522. uv_pars_fragment: uv_pars_fragment,
  9523. uv_pars_vertex: uv_pars_vertex,
  9524. uv_vertex: uv_vertex,
  9525. uv2_pars_fragment: uv2_pars_fragment,
  9526. uv2_pars_vertex: uv2_pars_vertex,
  9527. uv2_vertex: uv2_vertex,
  9528. worldpos_vertex: worldpos_vertex,
  9529. background_frag: background_frag,
  9530. background_vert: background_vert,
  9531. cube_frag: cube_frag,
  9532. cube_vert: cube_vert,
  9533. depth_frag: depth_frag,
  9534. depth_vert: depth_vert,
  9535. distanceRGBA_frag: distanceRGBA_frag,
  9536. distanceRGBA_vert: distanceRGBA_vert,
  9537. equirect_frag: equirect_frag,
  9538. equirect_vert: equirect_vert,
  9539. linedashed_frag: linedashed_frag,
  9540. linedashed_vert: linedashed_vert,
  9541. meshbasic_frag: meshbasic_frag,
  9542. meshbasic_vert: meshbasic_vert,
  9543. meshlambert_frag: meshlambert_frag,
  9544. meshlambert_vert: meshlambert_vert,
  9545. meshmatcap_frag: meshmatcap_frag,
  9546. meshmatcap_vert: meshmatcap_vert,
  9547. meshphong_frag: meshphong_frag,
  9548. meshphong_vert: meshphong_vert,
  9549. meshphysical_frag: meshphysical_frag,
  9550. meshphysical_vert: meshphysical_vert,
  9551. normal_frag: normal_frag,
  9552. normal_vert: normal_vert,
  9553. points_frag: points_frag,
  9554. points_vert: points_vert,
  9555. shadow_frag: shadow_frag,
  9556. shadow_vert: shadow_vert,
  9557. sprite_frag: sprite_frag,
  9558. sprite_vert: sprite_vert
  9559. };
  9560. /**
  9561. * Uniforms library for shared webgl shaders
  9562. */
  9563. var UniformsLib = {
  9564. common: {
  9565. diffuse: { value: new Color( 0xeeeeee ) },
  9566. opacity: { value: 1.0 },
  9567. map: { value: null },
  9568. uvTransform: { value: new Matrix3() },
  9569. alphaMap: { value: null },
  9570. },
  9571. specularmap: {
  9572. specularMap: { value: null },
  9573. },
  9574. envmap: {
  9575. envMap: { value: null },
  9576. flipEnvMap: { value: - 1 },
  9577. reflectivity: { value: 1.0 },
  9578. refractionRatio: { value: 0.98 },
  9579. maxMipLevel: { value: 0 }
  9580. },
  9581. aomap: {
  9582. aoMap: { value: null },
  9583. aoMapIntensity: { value: 1 }
  9584. },
  9585. lightmap: {
  9586. lightMap: { value: null },
  9587. lightMapIntensity: { value: 1 }
  9588. },
  9589. emissivemap: {
  9590. emissiveMap: { value: null }
  9591. },
  9592. bumpmap: {
  9593. bumpMap: { value: null },
  9594. bumpScale: { value: 1 }
  9595. },
  9596. normalmap: {
  9597. normalMap: { value: null },
  9598. normalScale: { value: new Vector2( 1, 1 ) }
  9599. },
  9600. displacementmap: {
  9601. displacementMap: { value: null },
  9602. displacementScale: { value: 1 },
  9603. displacementBias: { value: 0 }
  9604. },
  9605. roughnessmap: {
  9606. roughnessMap: { value: null }
  9607. },
  9608. metalnessmap: {
  9609. metalnessMap: { value: null }
  9610. },
  9611. gradientmap: {
  9612. gradientMap: { value: null }
  9613. },
  9614. fog: {
  9615. fogDensity: { value: 0.00025 },
  9616. fogNear: { value: 1 },
  9617. fogFar: { value: 2000 },
  9618. fogColor: { value: new Color( 0xffffff ) }
  9619. },
  9620. lights: {
  9621. ambientLightColor: { value: [] },
  9622. lightProbe: { value: [] },
  9623. directionalLights: { value: [], properties: {
  9624. direction: {},
  9625. color: {},
  9626. shadow: {},
  9627. shadowBias: {},
  9628. shadowRadius: {},
  9629. shadowMapSize: {}
  9630. } },
  9631. directionalShadowMap: { value: [] },
  9632. directionalShadowMatrix: { value: [] },
  9633. spotLights: { value: [], properties: {
  9634. color: {},
  9635. position: {},
  9636. direction: {},
  9637. distance: {},
  9638. coneCos: {},
  9639. penumbraCos: {},
  9640. decay: {},
  9641. shadow: {},
  9642. shadowBias: {},
  9643. shadowRadius: {},
  9644. shadowMapSize: {}
  9645. } },
  9646. spotShadowMap: { value: [] },
  9647. spotShadowMatrix: { value: [] },
  9648. pointLights: { value: [], properties: {
  9649. color: {},
  9650. position: {},
  9651. decay: {},
  9652. distance: {},
  9653. shadow: {},
  9654. shadowBias: {},
  9655. shadowRadius: {},
  9656. shadowMapSize: {},
  9657. shadowCameraNear: {},
  9658. shadowCameraFar: {}
  9659. } },
  9660. pointShadowMap: { value: [] },
  9661. pointShadowMatrix: { value: [] },
  9662. hemisphereLights: { value: [], properties: {
  9663. direction: {},
  9664. skyColor: {},
  9665. groundColor: {}
  9666. } },
  9667. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  9668. rectAreaLights: { value: [], properties: {
  9669. color: {},
  9670. position: {},
  9671. width: {},
  9672. height: {}
  9673. } }
  9674. },
  9675. points: {
  9676. diffuse: { value: new Color( 0xeeeeee ) },
  9677. opacity: { value: 1.0 },
  9678. size: { value: 1.0 },
  9679. scale: { value: 1.0 },
  9680. map: { value: null },
  9681. uvTransform: { value: new Matrix3() }
  9682. },
  9683. sprite: {
  9684. diffuse: { value: new Color( 0xeeeeee ) },
  9685. opacity: { value: 1.0 },
  9686. center: { value: new Vector2( 0.5, 0.5 ) },
  9687. rotation: { value: 0.0 },
  9688. map: { value: null },
  9689. uvTransform: { value: new Matrix3() }
  9690. }
  9691. };
  9692. /**
  9693. * @author alteredq / http://alteredqualia.com/
  9694. * @author mrdoob / http://mrdoob.com/
  9695. * @author mikael emtinger / http://gomo.se/
  9696. */
  9697. var ShaderLib = {
  9698. basic: {
  9699. uniforms: mergeUniforms( [
  9700. UniformsLib.common,
  9701. UniformsLib.specularmap,
  9702. UniformsLib.envmap,
  9703. UniformsLib.aomap,
  9704. UniformsLib.lightmap,
  9705. UniformsLib.fog
  9706. ] ),
  9707. vertexShader: ShaderChunk.meshbasic_vert,
  9708. fragmentShader: ShaderChunk.meshbasic_frag
  9709. },
  9710. lambert: {
  9711. uniforms: mergeUniforms( [
  9712. UniformsLib.common,
  9713. UniformsLib.specularmap,
  9714. UniformsLib.envmap,
  9715. UniformsLib.aomap,
  9716. UniformsLib.lightmap,
  9717. UniformsLib.emissivemap,
  9718. UniformsLib.fog,
  9719. UniformsLib.lights,
  9720. {
  9721. emissive: { value: new Color( 0x000000 ) }
  9722. }
  9723. ] ),
  9724. vertexShader: ShaderChunk.meshlambert_vert,
  9725. fragmentShader: ShaderChunk.meshlambert_frag
  9726. },
  9727. phong: {
  9728. uniforms: mergeUniforms( [
  9729. UniformsLib.common,
  9730. UniformsLib.specularmap,
  9731. UniformsLib.envmap,
  9732. UniformsLib.aomap,
  9733. UniformsLib.lightmap,
  9734. UniformsLib.emissivemap,
  9735. UniformsLib.bumpmap,
  9736. UniformsLib.normalmap,
  9737. UniformsLib.displacementmap,
  9738. UniformsLib.gradientmap,
  9739. UniformsLib.fog,
  9740. UniformsLib.lights,
  9741. {
  9742. emissive: { value: new Color( 0x000000 ) },
  9743. specular: { value: new Color( 0x111111 ) },
  9744. shininess: { value: 30 }
  9745. }
  9746. ] ),
  9747. vertexShader: ShaderChunk.meshphong_vert,
  9748. fragmentShader: ShaderChunk.meshphong_frag
  9749. },
  9750. standard: {
  9751. uniforms: mergeUniforms( [
  9752. UniformsLib.common,
  9753. UniformsLib.envmap,
  9754. UniformsLib.aomap,
  9755. UniformsLib.lightmap,
  9756. UniformsLib.emissivemap,
  9757. UniformsLib.bumpmap,
  9758. UniformsLib.normalmap,
  9759. UniformsLib.displacementmap,
  9760. UniformsLib.roughnessmap,
  9761. UniformsLib.metalnessmap,
  9762. UniformsLib.fog,
  9763. UniformsLib.lights,
  9764. {
  9765. emissive: { value: new Color( 0x000000 ) },
  9766. roughness: { value: 0.5 },
  9767. metalness: { value: 0.5 },
  9768. envMapIntensity: { value: 1 } // temporary
  9769. }
  9770. ] ),
  9771. vertexShader: ShaderChunk.meshphysical_vert,
  9772. fragmentShader: ShaderChunk.meshphysical_frag
  9773. },
  9774. matcap: {
  9775. uniforms: mergeUniforms( [
  9776. UniformsLib.common,
  9777. UniformsLib.bumpmap,
  9778. UniformsLib.normalmap,
  9779. UniformsLib.displacementmap,
  9780. UniformsLib.fog,
  9781. {
  9782. matcap: { value: null }
  9783. }
  9784. ] ),
  9785. vertexShader: ShaderChunk.meshmatcap_vert,
  9786. fragmentShader: ShaderChunk.meshmatcap_frag
  9787. },
  9788. points: {
  9789. uniforms: mergeUniforms( [
  9790. UniformsLib.points,
  9791. UniformsLib.fog
  9792. ] ),
  9793. vertexShader: ShaderChunk.points_vert,
  9794. fragmentShader: ShaderChunk.points_frag
  9795. },
  9796. dashed: {
  9797. uniforms: mergeUniforms( [
  9798. UniformsLib.common,
  9799. UniformsLib.fog,
  9800. {
  9801. scale: { value: 1 },
  9802. dashSize: { value: 1 },
  9803. totalSize: { value: 2 }
  9804. }
  9805. ] ),
  9806. vertexShader: ShaderChunk.linedashed_vert,
  9807. fragmentShader: ShaderChunk.linedashed_frag
  9808. },
  9809. depth: {
  9810. uniforms: mergeUniforms( [
  9811. UniformsLib.common,
  9812. UniformsLib.displacementmap
  9813. ] ),
  9814. vertexShader: ShaderChunk.depth_vert,
  9815. fragmentShader: ShaderChunk.depth_frag
  9816. },
  9817. normal: {
  9818. uniforms: mergeUniforms( [
  9819. UniformsLib.common,
  9820. UniformsLib.bumpmap,
  9821. UniformsLib.normalmap,
  9822. UniformsLib.displacementmap,
  9823. {
  9824. opacity: { value: 1.0 }
  9825. }
  9826. ] ),
  9827. vertexShader: ShaderChunk.normal_vert,
  9828. fragmentShader: ShaderChunk.normal_frag
  9829. },
  9830. sprite: {
  9831. uniforms: mergeUniforms( [
  9832. UniformsLib.sprite,
  9833. UniformsLib.fog
  9834. ] ),
  9835. vertexShader: ShaderChunk.sprite_vert,
  9836. fragmentShader: ShaderChunk.sprite_frag
  9837. },
  9838. background: {
  9839. uniforms: {
  9840. uvTransform: { value: new Matrix3() },
  9841. t2D: { value: null },
  9842. },
  9843. vertexShader: ShaderChunk.background_vert,
  9844. fragmentShader: ShaderChunk.background_frag
  9845. },
  9846. /* -------------------------------------------------------------------------
  9847. // Cube map shader
  9848. ------------------------------------------------------------------------- */
  9849. cube: {
  9850. uniforms: {
  9851. tCube: { value: null },
  9852. tFlip: { value: - 1 },
  9853. opacity: { value: 1.0 }
  9854. },
  9855. vertexShader: ShaderChunk.cube_vert,
  9856. fragmentShader: ShaderChunk.cube_frag
  9857. },
  9858. equirect: {
  9859. uniforms: {
  9860. tEquirect: { value: null },
  9861. },
  9862. vertexShader: ShaderChunk.equirect_vert,
  9863. fragmentShader: ShaderChunk.equirect_frag
  9864. },
  9865. distanceRGBA: {
  9866. uniforms: mergeUniforms( [
  9867. UniformsLib.common,
  9868. UniformsLib.displacementmap,
  9869. {
  9870. referencePosition: { value: new Vector3() },
  9871. nearDistance: { value: 1 },
  9872. farDistance: { value: 1000 }
  9873. }
  9874. ] ),
  9875. vertexShader: ShaderChunk.distanceRGBA_vert,
  9876. fragmentShader: ShaderChunk.distanceRGBA_frag
  9877. },
  9878. shadow: {
  9879. uniforms: mergeUniforms( [
  9880. UniformsLib.lights,
  9881. UniformsLib.fog,
  9882. {
  9883. color: { value: new Color( 0x00000 ) },
  9884. opacity: { value: 1.0 }
  9885. },
  9886. ] ),
  9887. vertexShader: ShaderChunk.shadow_vert,
  9888. fragmentShader: ShaderChunk.shadow_frag
  9889. }
  9890. };
  9891. ShaderLib.physical = {
  9892. uniforms: mergeUniforms( [
  9893. ShaderLib.standard.uniforms,
  9894. {
  9895. clearCoat: { value: 0 },
  9896. clearCoatRoughness: { value: 0 },
  9897. clearCoatGeometryNormals: { value: false },
  9898. clearCoatNormalMap: { value: null },
  9899. clearCoatNormalScale: { value: new Vector2( 1, 1 ) }
  9900. }
  9901. ] ),
  9902. vertexShader: ShaderChunk.meshphysical_vert,
  9903. fragmentShader: ShaderChunk.meshphysical_frag
  9904. };
  9905. /**
  9906. * @author mrdoob / http://mrdoob.com/
  9907. */
  9908. function WebGLAnimation() {
  9909. var context = null;
  9910. var isAnimating = false;
  9911. var animationLoop = null;
  9912. function onAnimationFrame( time, frame ) {
  9913. if ( isAnimating === false ) return;
  9914. animationLoop( time, frame );
  9915. context.requestAnimationFrame( onAnimationFrame );
  9916. }
  9917. return {
  9918. start: function () {
  9919. if ( isAnimating === true ) return;
  9920. if ( animationLoop === null ) return;
  9921. context.requestAnimationFrame( onAnimationFrame );
  9922. isAnimating = true;
  9923. },
  9924. stop: function () {
  9925. isAnimating = false;
  9926. },
  9927. setAnimationLoop: function ( callback ) {
  9928. animationLoop = callback;
  9929. },
  9930. setContext: function ( value ) {
  9931. context = value;
  9932. }
  9933. };
  9934. }
  9935. /**
  9936. * @author mrdoob / http://mrdoob.com/
  9937. */
  9938. function WebGLAttributes( gl ) {
  9939. var buffers = new WeakMap();
  9940. function createBuffer( attribute, bufferType ) {
  9941. var array = attribute.array;
  9942. var usage = attribute.dynamic ? 35048 : 35044;
  9943. var buffer = gl.createBuffer();
  9944. gl.bindBuffer( bufferType, buffer );
  9945. gl.bufferData( bufferType, array, usage );
  9946. attribute.onUploadCallback();
  9947. var type = 5126;
  9948. if ( array instanceof Float32Array ) {
  9949. type = 5126;
  9950. } else if ( array instanceof Float64Array ) {
  9951. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  9952. } else if ( array instanceof Uint16Array ) {
  9953. type = 5123;
  9954. } else if ( array instanceof Int16Array ) {
  9955. type = 5122;
  9956. } else if ( array instanceof Uint32Array ) {
  9957. type = 5125;
  9958. } else if ( array instanceof Int32Array ) {
  9959. type = 5124;
  9960. } else if ( array instanceof Int8Array ) {
  9961. type = 5120;
  9962. } else if ( array instanceof Uint8Array ) {
  9963. type = 5121;
  9964. }
  9965. return {
  9966. buffer: buffer,
  9967. type: type,
  9968. bytesPerElement: array.BYTES_PER_ELEMENT,
  9969. version: attribute.version
  9970. };
  9971. }
  9972. function updateBuffer( buffer, attribute, bufferType ) {
  9973. var array = attribute.array;
  9974. var updateRange = attribute.updateRange;
  9975. gl.bindBuffer( bufferType, buffer );
  9976. if ( attribute.dynamic === false ) {
  9977. gl.bufferData( bufferType, array, 35044 );
  9978. } else if ( updateRange.count === - 1 ) {
  9979. // Not using update ranges
  9980. gl.bufferSubData( bufferType, 0, array );
  9981. } else if ( updateRange.count === 0 ) {
  9982. 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.' );
  9983. } else {
  9984. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  9985. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  9986. updateRange.count = - 1; // reset range
  9987. }
  9988. }
  9989. //
  9990. function get( attribute ) {
  9991. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9992. return buffers.get( attribute );
  9993. }
  9994. function remove( attribute ) {
  9995. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9996. var data = buffers.get( attribute );
  9997. if ( data ) {
  9998. gl.deleteBuffer( data.buffer );
  9999. buffers.delete( attribute );
  10000. }
  10001. }
  10002. function update( attribute, bufferType ) {
  10003. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  10004. var data = buffers.get( attribute );
  10005. if ( data === undefined ) {
  10006. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  10007. } else if ( data.version < attribute.version ) {
  10008. updateBuffer( data.buffer, attribute, bufferType );
  10009. data.version = attribute.version;
  10010. }
  10011. }
  10012. return {
  10013. get: get,
  10014. remove: remove,
  10015. update: update
  10016. };
  10017. }
  10018. /**
  10019. * @author mrdoob / http://mrdoob.com/
  10020. * @author Mugen87 / https://github.com/Mugen87
  10021. */
  10022. // PlaneGeometry
  10023. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  10024. Geometry.call( this );
  10025. this.type = 'PlaneGeometry';
  10026. this.parameters = {
  10027. width: width,
  10028. height: height,
  10029. widthSegments: widthSegments,
  10030. heightSegments: heightSegments
  10031. };
  10032. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  10033. this.mergeVertices();
  10034. }
  10035. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  10036. PlaneGeometry.prototype.constructor = PlaneGeometry;
  10037. // PlaneBufferGeometry
  10038. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  10039. BufferGeometry.call( this );
  10040. this.type = 'PlaneBufferGeometry';
  10041. this.parameters = {
  10042. width: width,
  10043. height: height,
  10044. widthSegments: widthSegments,
  10045. heightSegments: heightSegments
  10046. };
  10047. width = width || 1;
  10048. height = height || 1;
  10049. var width_half = width / 2;
  10050. var height_half = height / 2;
  10051. var gridX = Math.floor( widthSegments ) || 1;
  10052. var gridY = Math.floor( heightSegments ) || 1;
  10053. var gridX1 = gridX + 1;
  10054. var gridY1 = gridY + 1;
  10055. var segment_width = width / gridX;
  10056. var segment_height = height / gridY;
  10057. var ix, iy;
  10058. // buffers
  10059. var indices = [];
  10060. var vertices = [];
  10061. var normals = [];
  10062. var uvs = [];
  10063. // generate vertices, normals and uvs
  10064. for ( iy = 0; iy < gridY1; iy ++ ) {
  10065. var y = iy * segment_height - height_half;
  10066. for ( ix = 0; ix < gridX1; ix ++ ) {
  10067. var x = ix * segment_width - width_half;
  10068. vertices.push( x, - y, 0 );
  10069. normals.push( 0, 0, 1 );
  10070. uvs.push( ix / gridX );
  10071. uvs.push( 1 - ( iy / gridY ) );
  10072. }
  10073. }
  10074. // indices
  10075. for ( iy = 0; iy < gridY; iy ++ ) {
  10076. for ( ix = 0; ix < gridX; ix ++ ) {
  10077. var a = ix + gridX1 * iy;
  10078. var b = ix + gridX1 * ( iy + 1 );
  10079. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  10080. var d = ( ix + 1 ) + gridX1 * iy;
  10081. // faces
  10082. indices.push( a, b, d );
  10083. indices.push( b, c, d );
  10084. }
  10085. }
  10086. // build geometry
  10087. this.setIndex( indices );
  10088. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  10089. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  10090. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  10091. }
  10092. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  10093. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  10094. /**
  10095. * @author mrdoob / http://mrdoob.com/
  10096. */
  10097. function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
  10098. var clearColor = new Color( 0x000000 );
  10099. var clearAlpha = 0;
  10100. var planeMesh;
  10101. var boxMesh;
  10102. // Store the current background texture and its `version`
  10103. // so we can recompile the material accordingly.
  10104. var currentBackground = null;
  10105. var currentBackgroundVersion = 0;
  10106. function render( renderList, scene, camera, forceClear ) {
  10107. var background = scene.background;
  10108. // Ignore background in AR
  10109. // TODO: Reconsider this.
  10110. var vr = renderer.vr;
  10111. var session = vr.getSession && vr.getSession();
  10112. if ( session && session.environmentBlendMode === 'additive' ) {
  10113. background = null;
  10114. }
  10115. if ( background === null ) {
  10116. setClear( clearColor, clearAlpha );
  10117. currentBackground = null;
  10118. currentBackgroundVersion = 0;
  10119. } else if ( background && background.isColor ) {
  10120. setClear( background, 1 );
  10121. forceClear = true;
  10122. currentBackground = null;
  10123. currentBackgroundVersion = 0;
  10124. }
  10125. if ( renderer.autoClear || forceClear ) {
  10126. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  10127. }
  10128. if ( background && ( background.isCubeTexture || background.isWebGLRenderTargetCube ) ) {
  10129. if ( boxMesh === undefined ) {
  10130. boxMesh = new Mesh(
  10131. new BoxBufferGeometry( 1, 1, 1 ),
  10132. new ShaderMaterial( {
  10133. type: 'BackgroundCubeMaterial',
  10134. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  10135. vertexShader: ShaderLib.cube.vertexShader,
  10136. fragmentShader: ShaderLib.cube.fragmentShader,
  10137. side: BackSide,
  10138. depthTest: false,
  10139. depthWrite: false,
  10140. fog: false
  10141. } )
  10142. );
  10143. boxMesh.geometry.removeAttribute( 'normal' );
  10144. boxMesh.geometry.removeAttribute( 'uv' );
  10145. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  10146. this.matrixWorld.copyPosition( camera.matrixWorld );
  10147. };
  10148. // enable code injection for non-built-in material
  10149. Object.defineProperty( boxMesh.material, 'map', {
  10150. get: function () {
  10151. return this.uniforms.tCube.value;
  10152. }
  10153. } );
  10154. objects.update( boxMesh );
  10155. }
  10156. var texture = background.isWebGLRenderTargetCube ? background.texture : background;
  10157. boxMesh.material.uniforms.tCube.value = texture;
  10158. boxMesh.material.uniforms.tFlip.value = ( background.isWebGLRenderTargetCube ) ? 1 : - 1;
  10159. if ( currentBackground !== background ||
  10160. currentBackgroundVersion !== texture.version ) {
  10161. boxMesh.material.needsUpdate = true;
  10162. currentBackground = background;
  10163. currentBackgroundVersion = texture.version;
  10164. }
  10165. // push to the pre-sorted opaque render list
  10166. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  10167. } else if ( background && background.isTexture ) {
  10168. if ( planeMesh === undefined ) {
  10169. planeMesh = new Mesh(
  10170. new PlaneBufferGeometry( 2, 2 ),
  10171. new ShaderMaterial( {
  10172. type: 'BackgroundMaterial',
  10173. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  10174. vertexShader: ShaderLib.background.vertexShader,
  10175. fragmentShader: ShaderLib.background.fragmentShader,
  10176. side: FrontSide,
  10177. depthTest: false,
  10178. depthWrite: false,
  10179. fog: false
  10180. } )
  10181. );
  10182. planeMesh.geometry.removeAttribute( 'normal' );
  10183. // enable code injection for non-built-in material
  10184. Object.defineProperty( planeMesh.material, 'map', {
  10185. get: function () {
  10186. return this.uniforms.t2D.value;
  10187. }
  10188. } );
  10189. objects.update( planeMesh );
  10190. }
  10191. planeMesh.material.uniforms.t2D.value = background;
  10192. if ( background.matrixAutoUpdate === true ) {
  10193. background.updateMatrix();
  10194. }
  10195. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  10196. if ( currentBackground !== background ||
  10197. currentBackgroundVersion !== background.version ) {
  10198. planeMesh.material.needsUpdate = true;
  10199. currentBackground = background;
  10200. currentBackgroundVersion = background.version;
  10201. }
  10202. // push to the pre-sorted opaque render list
  10203. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  10204. }
  10205. }
  10206. function setClear( color, alpha ) {
  10207. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  10208. }
  10209. return {
  10210. getClearColor: function () {
  10211. return clearColor;
  10212. },
  10213. setClearColor: function ( color, alpha ) {
  10214. clearColor.set( color );
  10215. clearAlpha = alpha !== undefined ? alpha : 1;
  10216. setClear( clearColor, clearAlpha );
  10217. },
  10218. getClearAlpha: function () {
  10219. return clearAlpha;
  10220. },
  10221. setClearAlpha: function ( alpha ) {
  10222. clearAlpha = alpha;
  10223. setClear( clearColor, clearAlpha );
  10224. },
  10225. render: render
  10226. };
  10227. }
  10228. /**
  10229. * @author mrdoob / http://mrdoob.com/
  10230. */
  10231. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  10232. var mode;
  10233. function setMode( value ) {
  10234. mode = value;
  10235. }
  10236. function render( start, count ) {
  10237. gl.drawArrays( mode, start, count );
  10238. info.update( count, mode );
  10239. }
  10240. function renderInstances( geometry, start, count ) {
  10241. var extension;
  10242. if ( capabilities.isWebGL2 ) {
  10243. extension = gl;
  10244. } else {
  10245. extension = extensions.get( 'ANGLE_instanced_arrays' );
  10246. if ( extension === null ) {
  10247. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  10248. return;
  10249. }
  10250. }
  10251. extension[ capabilities.isWebGL2 ? 'drawArraysInstanced' : 'drawArraysInstancedANGLE' ]( mode, start, count, geometry.maxInstancedCount );
  10252. info.update( count, mode, geometry.maxInstancedCount );
  10253. }
  10254. //
  10255. this.setMode = setMode;
  10256. this.render = render;
  10257. this.renderInstances = renderInstances;
  10258. }
  10259. /**
  10260. * @author mrdoob / http://mrdoob.com/
  10261. */
  10262. function WebGLCapabilities( gl, extensions, parameters ) {
  10263. var maxAnisotropy;
  10264. function getMaxAnisotropy() {
  10265. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  10266. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  10267. if ( extension !== null ) {
  10268. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  10269. } else {
  10270. maxAnisotropy = 0;
  10271. }
  10272. return maxAnisotropy;
  10273. }
  10274. function getMaxPrecision( precision ) {
  10275. if ( precision === 'highp' ) {
  10276. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  10277. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  10278. return 'highp';
  10279. }
  10280. precision = 'mediump';
  10281. }
  10282. if ( precision === 'mediump' ) {
  10283. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  10284. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  10285. return 'mediump';
  10286. }
  10287. }
  10288. return 'lowp';
  10289. }
  10290. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext;
  10291. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  10292. var maxPrecision = getMaxPrecision( precision );
  10293. if ( maxPrecision !== precision ) {
  10294. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  10295. precision = maxPrecision;
  10296. }
  10297. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  10298. var maxTextures = gl.getParameter( 34930 );
  10299. var maxVertexTextures = gl.getParameter( 35660 );
  10300. var maxTextureSize = gl.getParameter( 3379 );
  10301. var maxCubemapSize = gl.getParameter( 34076 );
  10302. var maxAttributes = gl.getParameter( 34921 );
  10303. var maxVertexUniforms = gl.getParameter( 36347 );
  10304. var maxVaryings = gl.getParameter( 36348 );
  10305. var maxFragmentUniforms = gl.getParameter( 36349 );
  10306. var vertexTextures = maxVertexTextures > 0;
  10307. var floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
  10308. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  10309. var maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  10310. return {
  10311. isWebGL2: isWebGL2,
  10312. getMaxAnisotropy: getMaxAnisotropy,
  10313. getMaxPrecision: getMaxPrecision,
  10314. precision: precision,
  10315. logarithmicDepthBuffer: logarithmicDepthBuffer,
  10316. maxTextures: maxTextures,
  10317. maxVertexTextures: maxVertexTextures,
  10318. maxTextureSize: maxTextureSize,
  10319. maxCubemapSize: maxCubemapSize,
  10320. maxAttributes: maxAttributes,
  10321. maxVertexUniforms: maxVertexUniforms,
  10322. maxVaryings: maxVaryings,
  10323. maxFragmentUniforms: maxFragmentUniforms,
  10324. vertexTextures: vertexTextures,
  10325. floatFragmentTextures: floatFragmentTextures,
  10326. floatVertexTextures: floatVertexTextures,
  10327. maxSamples: maxSamples
  10328. };
  10329. }
  10330. /**
  10331. * @author tschw
  10332. */
  10333. function WebGLClipping() {
  10334. var scope = this,
  10335. globalState = null,
  10336. numGlobalPlanes = 0,
  10337. localClippingEnabled = false,
  10338. renderingShadows = false,
  10339. plane = new Plane(),
  10340. viewNormalMatrix = new Matrix3(),
  10341. uniform = { value: null, needsUpdate: false };
  10342. this.uniform = uniform;
  10343. this.numPlanes = 0;
  10344. this.numIntersection = 0;
  10345. this.init = function ( planes, enableLocalClipping, camera ) {
  10346. var enabled =
  10347. planes.length !== 0 ||
  10348. enableLocalClipping ||
  10349. // enable state of previous frame - the clipping code has to
  10350. // run another frame in order to reset the state:
  10351. numGlobalPlanes !== 0 ||
  10352. localClippingEnabled;
  10353. localClippingEnabled = enableLocalClipping;
  10354. globalState = projectPlanes( planes, camera, 0 );
  10355. numGlobalPlanes = planes.length;
  10356. return enabled;
  10357. };
  10358. this.beginShadows = function () {
  10359. renderingShadows = true;
  10360. projectPlanes( null );
  10361. };
  10362. this.endShadows = function () {
  10363. renderingShadows = false;
  10364. resetGlobalState();
  10365. };
  10366. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  10367. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  10368. // there's no local clipping
  10369. if ( renderingShadows ) {
  10370. // there's no global clipping
  10371. projectPlanes( null );
  10372. } else {
  10373. resetGlobalState();
  10374. }
  10375. } else {
  10376. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  10377. lGlobal = nGlobal * 4,
  10378. dstArray = cache.clippingState || null;
  10379. uniform.value = dstArray; // ensure unique state
  10380. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  10381. for ( var i = 0; i !== lGlobal; ++ i ) {
  10382. dstArray[ i ] = globalState[ i ];
  10383. }
  10384. cache.clippingState = dstArray;
  10385. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  10386. this.numPlanes += nGlobal;
  10387. }
  10388. };
  10389. function resetGlobalState() {
  10390. if ( uniform.value !== globalState ) {
  10391. uniform.value = globalState;
  10392. uniform.needsUpdate = numGlobalPlanes > 0;
  10393. }
  10394. scope.numPlanes = numGlobalPlanes;
  10395. scope.numIntersection = 0;
  10396. }
  10397. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  10398. var nPlanes = planes !== null ? planes.length : 0,
  10399. dstArray = null;
  10400. if ( nPlanes !== 0 ) {
  10401. dstArray = uniform.value;
  10402. if ( skipTransform !== true || dstArray === null ) {
  10403. var flatSize = dstOffset + nPlanes * 4,
  10404. viewMatrix = camera.matrixWorldInverse;
  10405. viewNormalMatrix.getNormalMatrix( viewMatrix );
  10406. if ( dstArray === null || dstArray.length < flatSize ) {
  10407. dstArray = new Float32Array( flatSize );
  10408. }
  10409. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  10410. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  10411. plane.normal.toArray( dstArray, i4 );
  10412. dstArray[ i4 + 3 ] = plane.constant;
  10413. }
  10414. }
  10415. uniform.value = dstArray;
  10416. uniform.needsUpdate = true;
  10417. }
  10418. scope.numPlanes = nPlanes;
  10419. return dstArray;
  10420. }
  10421. }
  10422. /**
  10423. * @author mrdoob / http://mrdoob.com/
  10424. */
  10425. function WebGLExtensions( gl ) {
  10426. var extensions = {};
  10427. return {
  10428. get: function ( name ) {
  10429. if ( extensions[ name ] !== undefined ) {
  10430. return extensions[ name ];
  10431. }
  10432. var extension;
  10433. switch ( name ) {
  10434. case 'WEBGL_depth_texture':
  10435. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  10436. break;
  10437. case 'EXT_texture_filter_anisotropic':
  10438. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  10439. break;
  10440. case 'WEBGL_compressed_texture_s3tc':
  10441. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  10442. break;
  10443. case 'WEBGL_compressed_texture_pvrtc':
  10444. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  10445. break;
  10446. default:
  10447. extension = gl.getExtension( name );
  10448. }
  10449. if ( extension === null ) {
  10450. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  10451. }
  10452. extensions[ name ] = extension;
  10453. return extension;
  10454. }
  10455. };
  10456. }
  10457. /**
  10458. * @author mrdoob / http://mrdoob.com/
  10459. */
  10460. function WebGLGeometries( gl, attributes, info ) {
  10461. var geometries = {};
  10462. var wireframeAttributes = {};
  10463. function onGeometryDispose( event ) {
  10464. var geometry = event.target;
  10465. var buffergeometry = geometries[ geometry.id ];
  10466. if ( buffergeometry.index !== null ) {
  10467. attributes.remove( buffergeometry.index );
  10468. }
  10469. for ( var name in buffergeometry.attributes ) {
  10470. attributes.remove( buffergeometry.attributes[ name ] );
  10471. }
  10472. geometry.removeEventListener( 'dispose', onGeometryDispose );
  10473. delete geometries[ geometry.id ];
  10474. var attribute = wireframeAttributes[ buffergeometry.id ];
  10475. if ( attribute ) {
  10476. attributes.remove( attribute );
  10477. delete wireframeAttributes[ buffergeometry.id ];
  10478. }
  10479. //
  10480. info.memory.geometries --;
  10481. }
  10482. function get( object, geometry ) {
  10483. var buffergeometry = geometries[ geometry.id ];
  10484. if ( buffergeometry ) return buffergeometry;
  10485. geometry.addEventListener( 'dispose', onGeometryDispose );
  10486. if ( geometry.isBufferGeometry ) {
  10487. buffergeometry = geometry;
  10488. } else if ( geometry.isGeometry ) {
  10489. if ( geometry._bufferGeometry === undefined ) {
  10490. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  10491. }
  10492. buffergeometry = geometry._bufferGeometry;
  10493. }
  10494. geometries[ geometry.id ] = buffergeometry;
  10495. info.memory.geometries ++;
  10496. return buffergeometry;
  10497. }
  10498. function update( geometry ) {
  10499. var index = geometry.index;
  10500. var geometryAttributes = geometry.attributes;
  10501. if ( index !== null ) {
  10502. attributes.update( index, 34963 );
  10503. }
  10504. for ( var name in geometryAttributes ) {
  10505. attributes.update( geometryAttributes[ name ], 34962 );
  10506. }
  10507. // morph targets
  10508. var morphAttributes = geometry.morphAttributes;
  10509. for ( var name in morphAttributes ) {
  10510. var array = morphAttributes[ name ];
  10511. for ( var i = 0, l = array.length; i < l; i ++ ) {
  10512. attributes.update( array[ i ], 34962 );
  10513. }
  10514. }
  10515. }
  10516. function updateWireframeAttribute( geometry ) {
  10517. var indices = [];
  10518. var geometryIndex = geometry.index;
  10519. var geometryPosition = geometry.attributes.position;
  10520. var version = 0;
  10521. if ( geometryIndex !== null ) {
  10522. var array = geometryIndex.array;
  10523. version = geometryIndex.version;
  10524. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  10525. var a = array[ i + 0 ];
  10526. var b = array[ i + 1 ];
  10527. var c = array[ i + 2 ];
  10528. indices.push( a, b, b, c, c, a );
  10529. }
  10530. } else {
  10531. var array = geometryPosition.array;
  10532. version = geometryPosition.version;
  10533. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  10534. var a = i + 0;
  10535. var b = i + 1;
  10536. var c = i + 2;
  10537. indices.push( a, b, b, c, c, a );
  10538. }
  10539. }
  10540. var attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  10541. attribute.version = version;
  10542. attributes.update( attribute, 34963 );
  10543. //
  10544. var previousAttribute = wireframeAttributes[ geometry.id ];
  10545. if ( previousAttribute ) attributes.remove( previousAttribute );
  10546. //
  10547. wireframeAttributes[ geometry.id ] = attribute;
  10548. }
  10549. function getWireframeAttribute( geometry ) {
  10550. var currentAttribute = wireframeAttributes[ geometry.id ];
  10551. if ( currentAttribute ) {
  10552. var geometryIndex = geometry.index;
  10553. if ( geometryIndex !== null ) {
  10554. // if the attribute is obsolete, create a new one
  10555. if ( currentAttribute.version < geometryIndex.version ) {
  10556. updateWireframeAttribute( geometry );
  10557. }
  10558. }
  10559. } else {
  10560. updateWireframeAttribute( geometry );
  10561. }
  10562. return wireframeAttributes[ geometry.id ];
  10563. }
  10564. return {
  10565. get: get,
  10566. update: update,
  10567. getWireframeAttribute: getWireframeAttribute
  10568. };
  10569. }
  10570. /**
  10571. * @author mrdoob / http://mrdoob.com/
  10572. */
  10573. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  10574. var mode;
  10575. function setMode( value ) {
  10576. mode = value;
  10577. }
  10578. var type, bytesPerElement;
  10579. function setIndex( value ) {
  10580. type = value.type;
  10581. bytesPerElement = value.bytesPerElement;
  10582. }
  10583. function render( start, count ) {
  10584. gl.drawElements( mode, count, type, start * bytesPerElement );
  10585. info.update( count, mode );
  10586. }
  10587. function renderInstances( geometry, start, count ) {
  10588. var extension;
  10589. if ( capabilities.isWebGL2 ) {
  10590. extension = gl;
  10591. } else {
  10592. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  10593. if ( extension === null ) {
  10594. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  10595. return;
  10596. }
  10597. }
  10598. extension[ capabilities.isWebGL2 ? 'drawElementsInstanced' : 'drawElementsInstancedANGLE' ]( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  10599. info.update( count, mode, geometry.maxInstancedCount );
  10600. }
  10601. //
  10602. this.setMode = setMode;
  10603. this.setIndex = setIndex;
  10604. this.render = render;
  10605. this.renderInstances = renderInstances;
  10606. }
  10607. /**
  10608. * @author Mugen87 / https://github.com/Mugen87
  10609. */
  10610. function WebGLInfo( gl ) {
  10611. var memory = {
  10612. geometries: 0,
  10613. textures: 0
  10614. };
  10615. var render = {
  10616. frame: 0,
  10617. calls: 0,
  10618. triangles: 0,
  10619. points: 0,
  10620. lines: 0
  10621. };
  10622. function update( count, mode, instanceCount ) {
  10623. instanceCount = instanceCount || 1;
  10624. render.calls ++;
  10625. switch ( mode ) {
  10626. case 4:
  10627. render.triangles += instanceCount * ( count / 3 );
  10628. break;
  10629. case 5:
  10630. case 6:
  10631. render.triangles += instanceCount * ( count - 2 );
  10632. break;
  10633. case 1:
  10634. render.lines += instanceCount * ( count / 2 );
  10635. break;
  10636. case 3:
  10637. render.lines += instanceCount * ( count - 1 );
  10638. break;
  10639. case 2:
  10640. render.lines += instanceCount * count;
  10641. break;
  10642. case 0:
  10643. render.points += instanceCount * count;
  10644. break;
  10645. default:
  10646. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  10647. break;
  10648. }
  10649. }
  10650. function reset() {
  10651. render.frame ++;
  10652. render.calls = 0;
  10653. render.triangles = 0;
  10654. render.points = 0;
  10655. render.lines = 0;
  10656. }
  10657. return {
  10658. memory: memory,
  10659. render: render,
  10660. programs: null,
  10661. autoReset: true,
  10662. reset: reset,
  10663. update: update
  10664. };
  10665. }
  10666. /**
  10667. * @author mrdoob / http://mrdoob.com/
  10668. */
  10669. function absNumericalSort( a, b ) {
  10670. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  10671. }
  10672. function WebGLMorphtargets( gl ) {
  10673. var influencesList = {};
  10674. var morphInfluences = new Float32Array( 8 );
  10675. function update( object, geometry, material, program ) {
  10676. var objectInfluences = object.morphTargetInfluences;
  10677. var length = objectInfluences.length;
  10678. var influences = influencesList[ geometry.id ];
  10679. if ( influences === undefined ) {
  10680. // initialise list
  10681. influences = [];
  10682. for ( var i = 0; i < length; i ++ ) {
  10683. influences[ i ] = [ i, 0 ];
  10684. }
  10685. influencesList[ geometry.id ] = influences;
  10686. }
  10687. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  10688. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  10689. // Remove current morphAttributes
  10690. for ( var i = 0; i < length; i ++ ) {
  10691. var influence = influences[ i ];
  10692. if ( influence[ 1 ] !== 0 ) {
  10693. if ( morphTargets ) geometry.removeAttribute( 'morphTarget' + i );
  10694. if ( morphNormals ) geometry.removeAttribute( 'morphNormal' + i );
  10695. }
  10696. }
  10697. // Collect influences
  10698. for ( var i = 0; i < length; i ++ ) {
  10699. var influence = influences[ i ];
  10700. influence[ 0 ] = i;
  10701. influence[ 1 ] = objectInfluences[ i ];
  10702. }
  10703. influences.sort( absNumericalSort );
  10704. // Add morphAttributes
  10705. for ( var i = 0; i < 8; i ++ ) {
  10706. var influence = influences[ i ];
  10707. if ( influence ) {
  10708. var index = influence[ 0 ];
  10709. var value = influence[ 1 ];
  10710. if ( value ) {
  10711. if ( morphTargets ) geometry.addAttribute( 'morphTarget' + i, morphTargets[ index ] );
  10712. if ( morphNormals ) geometry.addAttribute( 'morphNormal' + i, morphNormals[ index ] );
  10713. morphInfluences[ i ] = value;
  10714. continue;
  10715. }
  10716. }
  10717. morphInfluences[ i ] = 0;
  10718. }
  10719. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  10720. }
  10721. return {
  10722. update: update
  10723. };
  10724. }
  10725. /**
  10726. * @author mrdoob / http://mrdoob.com/
  10727. */
  10728. function WebGLObjects( geometries, info ) {
  10729. var updateList = {};
  10730. function update( object ) {
  10731. var frame = info.render.frame;
  10732. var geometry = object.geometry;
  10733. var buffergeometry = geometries.get( object, geometry );
  10734. // Update once per frame
  10735. if ( updateList[ buffergeometry.id ] !== frame ) {
  10736. if ( geometry.isGeometry ) {
  10737. buffergeometry.updateFromObject( object );
  10738. }
  10739. geometries.update( buffergeometry );
  10740. updateList[ buffergeometry.id ] = frame;
  10741. }
  10742. return buffergeometry;
  10743. }
  10744. function dispose() {
  10745. updateList = {};
  10746. }
  10747. return {
  10748. update: update,
  10749. dispose: dispose
  10750. };
  10751. }
  10752. /**
  10753. * @author mrdoob / http://mrdoob.com/
  10754. */
  10755. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  10756. images = images !== undefined ? images : [];
  10757. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  10758. format = format !== undefined ? format : RGBFormat;
  10759. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  10760. this.flipY = false;
  10761. }
  10762. CubeTexture.prototype = Object.create( Texture.prototype );
  10763. CubeTexture.prototype.constructor = CubeTexture;
  10764. CubeTexture.prototype.isCubeTexture = true;
  10765. Object.defineProperty( CubeTexture.prototype, 'images', {
  10766. get: function () {
  10767. return this.image;
  10768. },
  10769. set: function ( value ) {
  10770. this.image = value;
  10771. }
  10772. } );
  10773. /**
  10774. * @author Takahiro https://github.com/takahirox
  10775. */
  10776. function DataTexture2DArray( data, width, height, depth ) {
  10777. Texture.call( this, null );
  10778. this.image = { data: data, width: width, height: height, depth: depth };
  10779. this.magFilter = NearestFilter;
  10780. this.minFilter = NearestFilter;
  10781. this.wrapR = ClampToEdgeWrapping;
  10782. this.generateMipmaps = false;
  10783. this.flipY = false;
  10784. }
  10785. DataTexture2DArray.prototype = Object.create( Texture.prototype );
  10786. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  10787. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  10788. /**
  10789. * @author Artur Trzesiok
  10790. */
  10791. function DataTexture3D( data, width, height, depth ) {
  10792. // We're going to add .setXXX() methods for setting properties later.
  10793. // Users can still set in DataTexture3D directly.
  10794. //
  10795. // var texture = new THREE.DataTexture3D( data, width, height, depth );
  10796. // texture.anisotropy = 16;
  10797. //
  10798. // See #14839
  10799. Texture.call( this, null );
  10800. this.image = { data: data, width: width, height: height, depth: depth };
  10801. this.magFilter = NearestFilter;
  10802. this.minFilter = NearestFilter;
  10803. this.wrapR = ClampToEdgeWrapping;
  10804. this.generateMipmaps = false;
  10805. this.flipY = false;
  10806. }
  10807. DataTexture3D.prototype = Object.create( Texture.prototype );
  10808. DataTexture3D.prototype.constructor = DataTexture3D;
  10809. DataTexture3D.prototype.isDataTexture3D = true;
  10810. /**
  10811. * @author tschw
  10812. * @author Mugen87 / https://github.com/Mugen87
  10813. * @author mrdoob / http://mrdoob.com/
  10814. *
  10815. * Uniforms of a program.
  10816. * Those form a tree structure with a special top-level container for the root,
  10817. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10818. *
  10819. *
  10820. * Properties of inner nodes including the top-level container:
  10821. *
  10822. * .seq - array of nested uniforms
  10823. * .map - nested uniforms by name
  10824. *
  10825. *
  10826. * Methods of all nodes except the top-level container:
  10827. *
  10828. * .setValue( gl, value, [textures] )
  10829. *
  10830. * uploads a uniform value(s)
  10831. * the 'textures' parameter is needed for sampler uniforms
  10832. *
  10833. *
  10834. * Static methods of the top-level container (textures factorizations):
  10835. *
  10836. * .upload( gl, seq, values, textures )
  10837. *
  10838. * sets uniforms in 'seq' to 'values[id].value'
  10839. *
  10840. * .seqWithValue( seq, values ) : filteredSeq
  10841. *
  10842. * filters 'seq' entries with corresponding entry in values
  10843. *
  10844. *
  10845. * Methods of the top-level container (textures factorizations):
  10846. *
  10847. * .setValue( gl, name, value, textures )
  10848. *
  10849. * sets uniform with name 'name' to 'value'
  10850. *
  10851. * .setOptional( gl, obj, prop )
  10852. *
  10853. * like .set for an optional property of the object
  10854. *
  10855. */
  10856. var emptyTexture = new Texture();
  10857. var emptyTexture2dArray = new DataTexture2DArray();
  10858. var emptyTexture3d = new DataTexture3D();
  10859. var emptyCubeTexture = new CubeTexture();
  10860. // --- Utilities ---
  10861. // Array Caches (provide typed arrays for temporary by size)
  10862. var arrayCacheF32 = [];
  10863. var arrayCacheI32 = [];
  10864. // Float32Array caches used for uploading Matrix uniforms
  10865. var mat4array = new Float32Array( 16 );
  10866. var mat3array = new Float32Array( 9 );
  10867. var mat2array = new Float32Array( 4 );
  10868. // Flattening for arrays of vectors and matrices
  10869. function flatten( array, nBlocks, blockSize ) {
  10870. var firstElem = array[ 0 ];
  10871. if ( firstElem <= 0 || firstElem > 0 ) return array;
  10872. // unoptimized: ! isNaN( firstElem )
  10873. // see http://jacksondunstan.com/articles/983
  10874. var n = nBlocks * blockSize,
  10875. r = arrayCacheF32[ n ];
  10876. if ( r === undefined ) {
  10877. r = new Float32Array( n );
  10878. arrayCacheF32[ n ] = r;
  10879. }
  10880. if ( nBlocks !== 0 ) {
  10881. firstElem.toArray( r, 0 );
  10882. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  10883. offset += blockSize;
  10884. array[ i ].toArray( r, offset );
  10885. }
  10886. }
  10887. return r;
  10888. }
  10889. function arraysEqual( a, b ) {
  10890. if ( a.length !== b.length ) return false;
  10891. for ( var i = 0, l = a.length; i < l; i ++ ) {
  10892. if ( a[ i ] !== b[ i ] ) return false;
  10893. }
  10894. return true;
  10895. }
  10896. function copyArray( a, b ) {
  10897. for ( var i = 0, l = b.length; i < l; i ++ ) {
  10898. a[ i ] = b[ i ];
  10899. }
  10900. }
  10901. // Texture unit allocation
  10902. function allocTexUnits( textures, n ) {
  10903. var r = arrayCacheI32[ n ];
  10904. if ( r === undefined ) {
  10905. r = new Int32Array( n );
  10906. arrayCacheI32[ n ] = r;
  10907. }
  10908. for ( var i = 0; i !== n; ++ i )
  10909. r[ i ] = textures.allocateTextureUnit();
  10910. return r;
  10911. }
  10912. // --- Setters ---
  10913. // Note: Defining these methods externally, because they come in a bunch
  10914. // and this way their names minify.
  10915. // Single scalar
  10916. function setValueV1f( gl, v ) {
  10917. var cache = this.cache;
  10918. if ( cache[ 0 ] === v ) return;
  10919. gl.uniform1f( this.addr, v );
  10920. cache[ 0 ] = v;
  10921. }
  10922. // Single float vector (from flat array or THREE.VectorN)
  10923. function setValueV2f( gl, v ) {
  10924. var cache = this.cache;
  10925. if ( v.x !== undefined ) {
  10926. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  10927. gl.uniform2f( this.addr, v.x, v.y );
  10928. cache[ 0 ] = v.x;
  10929. cache[ 1 ] = v.y;
  10930. }
  10931. } else {
  10932. if ( arraysEqual( cache, v ) ) return;
  10933. gl.uniform2fv( this.addr, v );
  10934. copyArray( cache, v );
  10935. }
  10936. }
  10937. function setValueV3f( gl, v ) {
  10938. var cache = this.cache;
  10939. if ( v.x !== undefined ) {
  10940. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  10941. gl.uniform3f( this.addr, v.x, v.y, v.z );
  10942. cache[ 0 ] = v.x;
  10943. cache[ 1 ] = v.y;
  10944. cache[ 2 ] = v.z;
  10945. }
  10946. } else if ( v.r !== undefined ) {
  10947. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  10948. gl.uniform3f( this.addr, v.r, v.g, v.b );
  10949. cache[ 0 ] = v.r;
  10950. cache[ 1 ] = v.g;
  10951. cache[ 2 ] = v.b;
  10952. }
  10953. } else {
  10954. if ( arraysEqual( cache, v ) ) return;
  10955. gl.uniform3fv( this.addr, v );
  10956. copyArray( cache, v );
  10957. }
  10958. }
  10959. function setValueV4f( gl, v ) {
  10960. var cache = this.cache;
  10961. if ( v.x !== undefined ) {
  10962. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  10963. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  10964. cache[ 0 ] = v.x;
  10965. cache[ 1 ] = v.y;
  10966. cache[ 2 ] = v.z;
  10967. cache[ 3 ] = v.w;
  10968. }
  10969. } else {
  10970. if ( arraysEqual( cache, v ) ) return;
  10971. gl.uniform4fv( this.addr, v );
  10972. copyArray( cache, v );
  10973. }
  10974. }
  10975. // Single matrix (from flat array or MatrixN)
  10976. function setValueM2( gl, v ) {
  10977. var cache = this.cache;
  10978. var elements = v.elements;
  10979. if ( elements === undefined ) {
  10980. if ( arraysEqual( cache, v ) ) return;
  10981. gl.uniformMatrix2fv( this.addr, false, v );
  10982. copyArray( cache, v );
  10983. } else {
  10984. if ( arraysEqual( cache, elements ) ) return;
  10985. mat2array.set( elements );
  10986. gl.uniformMatrix2fv( this.addr, false, mat2array );
  10987. copyArray( cache, elements );
  10988. }
  10989. }
  10990. function setValueM3( gl, v ) {
  10991. var cache = this.cache;
  10992. var elements = v.elements;
  10993. if ( elements === undefined ) {
  10994. if ( arraysEqual( cache, v ) ) return;
  10995. gl.uniformMatrix3fv( this.addr, false, v );
  10996. copyArray( cache, v );
  10997. } else {
  10998. if ( arraysEqual( cache, elements ) ) return;
  10999. mat3array.set( elements );
  11000. gl.uniformMatrix3fv( this.addr, false, mat3array );
  11001. copyArray( cache, elements );
  11002. }
  11003. }
  11004. function setValueM4( gl, v ) {
  11005. var cache = this.cache;
  11006. var elements = v.elements;
  11007. if ( elements === undefined ) {
  11008. if ( arraysEqual( cache, v ) ) return;
  11009. gl.uniformMatrix4fv( this.addr, false, v );
  11010. copyArray( cache, v );
  11011. } else {
  11012. if ( arraysEqual( cache, elements ) ) return;
  11013. mat4array.set( elements );
  11014. gl.uniformMatrix4fv( this.addr, false, mat4array );
  11015. copyArray( cache, elements );
  11016. }
  11017. }
  11018. // Single texture (2D / Cube)
  11019. function setValueT1( gl, v, textures ) {
  11020. var cache = this.cache;
  11021. var unit = textures.allocateTextureUnit();
  11022. if ( cache[ 0 ] !== unit ) {
  11023. gl.uniform1i( this.addr, unit );
  11024. cache[ 0 ] = unit;
  11025. }
  11026. textures.safeSetTexture2D( v || emptyTexture, unit );
  11027. }
  11028. function setValueT2DArray1( gl, v, textures ) {
  11029. var cache = this.cache;
  11030. var unit = textures.allocateTextureUnit();
  11031. if ( cache[ 0 ] !== unit ) {
  11032. gl.uniform1i( this.addr, unit );
  11033. cache[ 0 ] = unit;
  11034. }
  11035. textures.setTexture2DArray( v || emptyTexture2dArray, unit );
  11036. }
  11037. function setValueT3D1( gl, v, textures ) {
  11038. var cache = this.cache;
  11039. var unit = textures.allocateTextureUnit();
  11040. if ( cache[ 0 ] !== unit ) {
  11041. gl.uniform1i( this.addr, unit );
  11042. cache[ 0 ] = unit;
  11043. }
  11044. textures.setTexture3D( v || emptyTexture3d, unit );
  11045. }
  11046. function setValueT6( gl, v, textures ) {
  11047. var cache = this.cache;
  11048. var unit = textures.allocateTextureUnit();
  11049. if ( cache[ 0 ] !== unit ) {
  11050. gl.uniform1i( this.addr, unit );
  11051. cache[ 0 ] = unit;
  11052. }
  11053. textures.safeSetTextureCube( v || emptyCubeTexture, unit );
  11054. }
  11055. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  11056. function setValueV1i( gl, v ) {
  11057. var cache = this.cache;
  11058. if ( cache[ 0 ] === v ) return;
  11059. gl.uniform1i( this.addr, v );
  11060. cache[ 0 ] = v;
  11061. }
  11062. function setValueV2i( gl, v ) {
  11063. var cache = this.cache;
  11064. if ( arraysEqual( cache, v ) ) return;
  11065. gl.uniform2iv( this.addr, v );
  11066. copyArray( cache, v );
  11067. }
  11068. function setValueV3i( gl, v ) {
  11069. var cache = this.cache;
  11070. if ( arraysEqual( cache, v ) ) return;
  11071. gl.uniform3iv( this.addr, v );
  11072. copyArray( cache, v );
  11073. }
  11074. function setValueV4i( gl, v ) {
  11075. var cache = this.cache;
  11076. if ( arraysEqual( cache, v ) ) return;
  11077. gl.uniform4iv( this.addr, v );
  11078. copyArray( cache, v );
  11079. }
  11080. // Helper to pick the right setter for the singular case
  11081. function getSingularSetter( type ) {
  11082. switch ( type ) {
  11083. case 0x1406: return setValueV1f; // FLOAT
  11084. case 0x8b50: return setValueV2f; // _VEC2
  11085. case 0x8b51: return setValueV3f; // _VEC3
  11086. case 0x8b52: return setValueV4f; // _VEC4
  11087. case 0x8b5a: return setValueM2; // _MAT2
  11088. case 0x8b5b: return setValueM3; // _MAT3
  11089. case 0x8b5c: return setValueM4; // _MAT4
  11090. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  11091. case 0x8b5f: return setValueT3D1; // SAMPLER_3D
  11092. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  11093. case 0x8DC1: return setValueT2DArray1; // SAMPLER_2D_ARRAY
  11094. case 0x1404: case 0x8b56: return setValueV1i; // INT, BOOL
  11095. case 0x8b53: case 0x8b57: return setValueV2i; // _VEC2
  11096. case 0x8b54: case 0x8b58: return setValueV3i; // _VEC3
  11097. case 0x8b55: case 0x8b59: return setValueV4i; // _VEC4
  11098. }
  11099. }
  11100. // Array of scalars
  11101. function setValueV1fArray( gl, v ) {
  11102. gl.uniform1fv( this.addr, v );
  11103. }
  11104. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  11105. function setValueV1iArray( gl, v ) {
  11106. gl.uniform1iv( this.addr, v );
  11107. }
  11108. function setValueV2iArray( gl, v ) {
  11109. gl.uniform2iv( this.addr, v );
  11110. }
  11111. function setValueV3iArray( gl, v ) {
  11112. gl.uniform3iv( this.addr, v );
  11113. }
  11114. function setValueV4iArray( gl, v ) {
  11115. gl.uniform4iv( this.addr, v );
  11116. }
  11117. // Array of vectors (flat or from THREE classes)
  11118. function setValueV2fArray( gl, v ) {
  11119. var data = flatten( v, this.size, 2 );
  11120. gl.uniform2fv( this.addr, data );
  11121. }
  11122. function setValueV3fArray( gl, v ) {
  11123. var data = flatten( v, this.size, 3 );
  11124. gl.uniform3fv( this.addr, data );
  11125. }
  11126. function setValueV4fArray( gl, v ) {
  11127. var data = flatten( v, this.size, 4 );
  11128. gl.uniform4fv( this.addr, data );
  11129. }
  11130. // Array of matrices (flat or from THREE clases)
  11131. function setValueM2Array( gl, v ) {
  11132. var data = flatten( v, this.size, 4 );
  11133. gl.uniformMatrix2fv( this.addr, false, data );
  11134. }
  11135. function setValueM3Array( gl, v ) {
  11136. var data = flatten( v, this.size, 9 );
  11137. gl.uniformMatrix3fv( this.addr, false, data );
  11138. }
  11139. function setValueM4Array( gl, v ) {
  11140. var data = flatten( v, this.size, 16 );
  11141. gl.uniformMatrix4fv( this.addr, false, data );
  11142. }
  11143. // Array of textures (2D / Cube)
  11144. function setValueT1Array( gl, v, textures ) {
  11145. var n = v.length;
  11146. var units = allocTexUnits( textures, n );
  11147. gl.uniform1iv( this.addr, units );
  11148. for ( var i = 0; i !== n; ++ i ) {
  11149. textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] );
  11150. }
  11151. }
  11152. function setValueT6Array( gl, v, textures ) {
  11153. var n = v.length;
  11154. var units = allocTexUnits( textures, n );
  11155. gl.uniform1iv( this.addr, units );
  11156. for ( var i = 0; i !== n; ++ i ) {
  11157. textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  11158. }
  11159. }
  11160. // Helper to pick the right setter for a pure (bottom-level) array
  11161. function getPureArraySetter( type ) {
  11162. switch ( type ) {
  11163. case 0x1406: return setValueV1fArray; // FLOAT
  11164. case 0x8b50: return setValueV2fArray; // _VEC2
  11165. case 0x8b51: return setValueV3fArray; // _VEC3
  11166. case 0x8b52: return setValueV4fArray; // _VEC4
  11167. case 0x8b5a: return setValueM2Array; // _MAT2
  11168. case 0x8b5b: return setValueM3Array; // _MAT3
  11169. case 0x8b5c: return setValueM4Array; // _MAT4
  11170. case 0x8b5e: return setValueT1Array; // SAMPLER_2D
  11171. case 0x8b60: return setValueT6Array; // SAMPLER_CUBE
  11172. case 0x1404: case 0x8b56: return setValueV1iArray; // INT, BOOL
  11173. case 0x8b53: case 0x8b57: return setValueV2iArray; // _VEC2
  11174. case 0x8b54: case 0x8b58: return setValueV3iArray; // _VEC3
  11175. case 0x8b55: case 0x8b59: return setValueV4iArray; // _VEC4
  11176. }
  11177. }
  11178. // --- Uniform Classes ---
  11179. function SingleUniform( id, activeInfo, addr ) {
  11180. this.id = id;
  11181. this.addr = addr;
  11182. this.cache = [];
  11183. this.setValue = getSingularSetter( activeInfo.type );
  11184. // this.path = activeInfo.name; // DEBUG
  11185. }
  11186. function PureArrayUniform( id, activeInfo, addr ) {
  11187. this.id = id;
  11188. this.addr = addr;
  11189. this.cache = [];
  11190. this.size = activeInfo.size;
  11191. this.setValue = getPureArraySetter( activeInfo.type );
  11192. // this.path = activeInfo.name; // DEBUG
  11193. }
  11194. PureArrayUniform.prototype.updateCache = function ( data ) {
  11195. var cache = this.cache;
  11196. if ( data instanceof Float32Array && cache.length !== data.length ) {
  11197. this.cache = new Float32Array( data.length );
  11198. }
  11199. copyArray( cache, data );
  11200. };
  11201. function StructuredUniform( id ) {
  11202. this.id = id;
  11203. this.seq = [];
  11204. this.map = {};
  11205. }
  11206. StructuredUniform.prototype.setValue = function ( gl, value, textures ) {
  11207. var seq = this.seq;
  11208. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  11209. var u = seq[ i ];
  11210. u.setValue( gl, value[ u.id ], textures );
  11211. }
  11212. };
  11213. // --- Top-level ---
  11214. // Parser - builds up the property tree from the path strings
  11215. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  11216. // extracts
  11217. // - the identifier (member name or array index)
  11218. // - followed by an optional right bracket (found when array index)
  11219. // - followed by an optional left bracket or dot (type of subscript)
  11220. //
  11221. // Note: These portions can be read in a non-overlapping fashion and
  11222. // allow straightforward parsing of the hierarchy that WebGL encodes
  11223. // in the uniform names.
  11224. function addUniform( container, uniformObject ) {
  11225. container.seq.push( uniformObject );
  11226. container.map[ uniformObject.id ] = uniformObject;
  11227. }
  11228. function parseUniform( activeInfo, addr, container ) {
  11229. var path = activeInfo.name,
  11230. pathLength = path.length;
  11231. // reset RegExp object, because of the early exit of a previous run
  11232. RePathPart.lastIndex = 0;
  11233. while ( true ) {
  11234. var match = RePathPart.exec( path ),
  11235. matchEnd = RePathPart.lastIndex,
  11236. id = match[ 1 ],
  11237. idIsIndex = match[ 2 ] === ']',
  11238. subscript = match[ 3 ];
  11239. if ( idIsIndex ) id = id | 0; // convert to integer
  11240. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  11241. // bare name or "pure" bottom-level array "[0]" suffix
  11242. addUniform( container, subscript === undefined ?
  11243. new SingleUniform( id, activeInfo, addr ) :
  11244. new PureArrayUniform( id, activeInfo, addr ) );
  11245. break;
  11246. } else {
  11247. // step into inner node / create it in case it doesn't exist
  11248. var map = container.map, next = map[ id ];
  11249. if ( next === undefined ) {
  11250. next = new StructuredUniform( id );
  11251. addUniform( container, next );
  11252. }
  11253. container = next;
  11254. }
  11255. }
  11256. }
  11257. // Root Container
  11258. function WebGLUniforms( gl, program ) {
  11259. this.seq = [];
  11260. this.map = {};
  11261. var n = gl.getProgramParameter( program, 35718 );
  11262. for ( var i = 0; i < n; ++ i ) {
  11263. var info = gl.getActiveUniform( program, i ),
  11264. addr = gl.getUniformLocation( program, info.name );
  11265. parseUniform( info, addr, this );
  11266. }
  11267. }
  11268. WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) {
  11269. var u = this.map[ name ];
  11270. if ( u !== undefined ) u.setValue( gl, value, textures );
  11271. };
  11272. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  11273. var v = object[ name ];
  11274. if ( v !== undefined ) this.setValue( gl, name, v );
  11275. };
  11276. // Static interface
  11277. WebGLUniforms.upload = function ( gl, seq, values, textures ) {
  11278. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  11279. var u = seq[ i ],
  11280. v = values[ u.id ];
  11281. if ( v.needsUpdate !== false ) {
  11282. // note: always updating when .needsUpdate is undefined
  11283. u.setValue( gl, v.value, textures );
  11284. }
  11285. }
  11286. };
  11287. WebGLUniforms.seqWithValue = function ( seq, values ) {
  11288. var r = [];
  11289. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  11290. var u = seq[ i ];
  11291. if ( u.id in values ) r.push( u );
  11292. }
  11293. return r;
  11294. };
  11295. /**
  11296. * @author mrdoob / http://mrdoob.com/
  11297. */
  11298. function WebGLShader( gl, type, string ) {
  11299. var shader = gl.createShader( type );
  11300. gl.shaderSource( shader, string );
  11301. gl.compileShader( shader );
  11302. return shader;
  11303. }
  11304. /**
  11305. * @author mrdoob / http://mrdoob.com/
  11306. */
  11307. var programIdCount = 0;
  11308. function addLineNumbers( string ) {
  11309. var lines = string.split( '\n' );
  11310. for ( var i = 0; i < lines.length; i ++ ) {
  11311. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  11312. }
  11313. return lines.join( '\n' );
  11314. }
  11315. function getEncodingComponents( encoding ) {
  11316. switch ( encoding ) {
  11317. case LinearEncoding:
  11318. return [ 'Linear', '( value )' ];
  11319. case sRGBEncoding:
  11320. return [ 'sRGB', '( value )' ];
  11321. case RGBEEncoding:
  11322. return [ 'RGBE', '( value )' ];
  11323. case RGBM7Encoding:
  11324. return [ 'RGBM', '( value, 7.0 )' ];
  11325. case RGBM16Encoding:
  11326. return [ 'RGBM', '( value, 16.0 )' ];
  11327. case RGBDEncoding:
  11328. return [ 'RGBD', '( value, 256.0 )' ];
  11329. case GammaEncoding:
  11330. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  11331. default:
  11332. throw new Error( 'unsupported encoding: ' + encoding );
  11333. }
  11334. }
  11335. function getShaderErrors( gl, shader, type ) {
  11336. var status = gl.getShaderParameter( shader, 35713 );
  11337. var log = gl.getShaderInfoLog( shader ).trim();
  11338. if ( status && log === '' ) return '';
  11339. // --enable-privileged-webgl-extension
  11340. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  11341. var source = gl.getShaderSource( shader );
  11342. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers( source );
  11343. }
  11344. function getTexelDecodingFunction( functionName, encoding ) {
  11345. var components = getEncodingComponents( encoding );
  11346. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  11347. }
  11348. function getTexelEncodingFunction( functionName, encoding ) {
  11349. var components = getEncodingComponents( encoding );
  11350. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  11351. }
  11352. function getToneMappingFunction( functionName, toneMapping ) {
  11353. var toneMappingName;
  11354. switch ( toneMapping ) {
  11355. case LinearToneMapping:
  11356. toneMappingName = 'Linear';
  11357. break;
  11358. case ReinhardToneMapping:
  11359. toneMappingName = 'Reinhard';
  11360. break;
  11361. case Uncharted2ToneMapping:
  11362. toneMappingName = 'Uncharted2';
  11363. break;
  11364. case CineonToneMapping:
  11365. toneMappingName = 'OptimizedCineon';
  11366. break;
  11367. case ACESFilmicToneMapping:
  11368. toneMappingName = 'ACESFilmic';
  11369. break;
  11370. default:
  11371. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  11372. }
  11373. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  11374. }
  11375. function generateExtensions( extensions, parameters, rendererExtensions ) {
  11376. extensions = extensions || {};
  11377. var chunks = [
  11378. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || ( parameters.normalMap && ! parameters.objectSpaceNormalMap ) || ( parameters.clearCoatNormalMap && ! parameters.objectSpaceclearCoatNormalMap ) || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  11379. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  11380. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  11381. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  11382. ];
  11383. return chunks.filter( filterEmptyLine ).join( '\n' );
  11384. }
  11385. function generateDefines( defines ) {
  11386. var chunks = [];
  11387. for ( var name in defines ) {
  11388. var value = defines[ name ];
  11389. if ( value === false ) continue;
  11390. chunks.push( '#define ' + name + ' ' + value );
  11391. }
  11392. return chunks.join( '\n' );
  11393. }
  11394. function fetchAttributeLocations( gl, program ) {
  11395. var attributes = {};
  11396. var n = gl.getProgramParameter( program, 35721 );
  11397. for ( var i = 0; i < n; i ++ ) {
  11398. var info = gl.getActiveAttrib( program, i );
  11399. var name = info.name;
  11400. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  11401. attributes[ name ] = gl.getAttribLocation( program, name );
  11402. }
  11403. return attributes;
  11404. }
  11405. function filterEmptyLine( string ) {
  11406. return string !== '';
  11407. }
  11408. function replaceLightNums( string, parameters ) {
  11409. return string
  11410. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  11411. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  11412. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  11413. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  11414. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  11415. }
  11416. function replaceClippingPlaneNums( string, parameters ) {
  11417. return string
  11418. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  11419. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  11420. }
  11421. function parseIncludes( string ) {
  11422. var pattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  11423. function replace( match, include ) {
  11424. var replace = ShaderChunk[ include ];
  11425. if ( replace === undefined ) {
  11426. throw new Error( 'Can not resolve #include <' + include + '>' );
  11427. }
  11428. return parseIncludes( replace );
  11429. }
  11430. return string.replace( pattern, replace );
  11431. }
  11432. function unrollLoops( string ) {
  11433. var pattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  11434. function replace( match, start, end, snippet ) {
  11435. var unroll = '';
  11436. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  11437. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  11438. }
  11439. return unroll;
  11440. }
  11441. return string.replace( pattern, replace );
  11442. }
  11443. function WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities ) {
  11444. var gl = renderer.getContext();
  11445. var defines = material.defines;
  11446. var vertexShader = shader.vertexShader;
  11447. var fragmentShader = shader.fragmentShader;
  11448. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  11449. if ( parameters.shadowMapType === PCFShadowMap ) {
  11450. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  11451. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  11452. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  11453. }
  11454. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11455. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  11456. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  11457. if ( parameters.envMap ) {
  11458. switch ( material.envMap.mapping ) {
  11459. case CubeReflectionMapping:
  11460. case CubeRefractionMapping:
  11461. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11462. break;
  11463. case CubeUVReflectionMapping:
  11464. case CubeUVRefractionMapping:
  11465. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  11466. break;
  11467. case EquirectangularReflectionMapping:
  11468. case EquirectangularRefractionMapping:
  11469. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  11470. break;
  11471. case SphericalReflectionMapping:
  11472. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  11473. break;
  11474. }
  11475. switch ( material.envMap.mapping ) {
  11476. case CubeRefractionMapping:
  11477. case EquirectangularRefractionMapping:
  11478. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  11479. break;
  11480. }
  11481. switch ( material.combine ) {
  11482. case MultiplyOperation:
  11483. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  11484. break;
  11485. case MixOperation:
  11486. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  11487. break;
  11488. case AddOperation:
  11489. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  11490. break;
  11491. }
  11492. }
  11493. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  11494. // console.log( 'building new program ' );
  11495. //
  11496. var customExtensions = capabilities.isWebGL2 ? '' : generateExtensions( material.extensions, parameters, extensions );
  11497. var customDefines = generateDefines( defines );
  11498. //
  11499. var program = gl.createProgram();
  11500. var prefixVertex, prefixFragment;
  11501. if ( material.isRawShaderMaterial ) {
  11502. prefixVertex = [
  11503. customDefines
  11504. ].filter( filterEmptyLine ).join( '\n' );
  11505. if ( prefixVertex.length > 0 ) {
  11506. prefixVertex += '\n';
  11507. }
  11508. prefixFragment = [
  11509. customExtensions,
  11510. customDefines
  11511. ].filter( filterEmptyLine ).join( '\n' );
  11512. if ( prefixFragment.length > 0 ) {
  11513. prefixFragment += '\n';
  11514. }
  11515. } else {
  11516. prefixVertex = [
  11517. 'precision ' + parameters.precision + ' float;',
  11518. 'precision ' + parameters.precision + ' int;',
  11519. '#define SHADER_NAME ' + shader.name,
  11520. customDefines,
  11521. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  11522. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  11523. '#define MAX_BONES ' + parameters.maxBones,
  11524. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  11525. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  11526. parameters.map ? '#define USE_MAP' : '',
  11527. parameters.envMap ? '#define USE_ENVMAP' : '',
  11528. parameters.envMap ? '#define ' + envMapModeDefine : '',
  11529. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  11530. parameters.aoMap ? '#define USE_AOMAP' : '',
  11531. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  11532. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  11533. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  11534. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  11535. parameters.clearCoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  11536. ( parameters.clearCoatNormalMap && parameters.objectSpaceClearCoatNormalMap ) ? '#define OBJECTSPACE_CLEARCOAT_NORMALMAP' : '',
  11537. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  11538. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  11539. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  11540. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  11541. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  11542. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  11543. parameters.vertexColors ? '#define USE_COLOR' : '',
  11544. parameters.flatShading ? '#define FLAT_SHADED' : '',
  11545. parameters.skinning ? '#define USE_SKINNING' : '',
  11546. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  11547. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  11548. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  11549. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  11550. parameters.flipSided ? '#define FLIP_SIDED' : '',
  11551. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  11552. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  11553. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  11554. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  11555. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  11556. 'uniform mat4 modelMatrix;',
  11557. 'uniform mat4 modelViewMatrix;',
  11558. 'uniform mat4 projectionMatrix;',
  11559. 'uniform mat4 viewMatrix;',
  11560. 'uniform mat3 normalMatrix;',
  11561. 'uniform vec3 cameraPosition;',
  11562. 'attribute vec3 position;',
  11563. 'attribute vec3 normal;',
  11564. 'attribute vec2 uv;',
  11565. '#ifdef USE_TANGENT',
  11566. ' attribute vec4 tangent;',
  11567. '#endif',
  11568. '#ifdef USE_COLOR',
  11569. ' attribute vec3 color;',
  11570. '#endif',
  11571. '#ifdef USE_MORPHTARGETS',
  11572. ' attribute vec3 morphTarget0;',
  11573. ' attribute vec3 morphTarget1;',
  11574. ' attribute vec3 morphTarget2;',
  11575. ' attribute vec3 morphTarget3;',
  11576. ' #ifdef USE_MORPHNORMALS',
  11577. ' attribute vec3 morphNormal0;',
  11578. ' attribute vec3 morphNormal1;',
  11579. ' attribute vec3 morphNormal2;',
  11580. ' attribute vec3 morphNormal3;',
  11581. ' #else',
  11582. ' attribute vec3 morphTarget4;',
  11583. ' attribute vec3 morphTarget5;',
  11584. ' attribute vec3 morphTarget6;',
  11585. ' attribute vec3 morphTarget7;',
  11586. ' #endif',
  11587. '#endif',
  11588. '#ifdef USE_SKINNING',
  11589. ' attribute vec4 skinIndex;',
  11590. ' attribute vec4 skinWeight;',
  11591. '#endif',
  11592. '\n'
  11593. ].filter( filterEmptyLine ).join( '\n' );
  11594. prefixFragment = [
  11595. customExtensions,
  11596. 'precision ' + parameters.precision + ' float;',
  11597. 'precision ' + parameters.precision + ' int;',
  11598. '#define SHADER_NAME ' + shader.name,
  11599. customDefines,
  11600. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  11601. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  11602. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  11603. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  11604. parameters.map ? '#define USE_MAP' : '',
  11605. parameters.matcap ? '#define USE_MATCAP' : '',
  11606. parameters.envMap ? '#define USE_ENVMAP' : '',
  11607. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  11608. parameters.envMap ? '#define ' + envMapModeDefine : '',
  11609. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  11610. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  11611. parameters.aoMap ? '#define USE_AOMAP' : '',
  11612. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  11613. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  11614. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  11615. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  11616. parameters.clearCoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  11617. ( parameters.clearCoatNormalMap && parameters.objectSpaceClearCoatNormalMap ) ? '#define OBJECTSPACE_CLEARCOAT_NORMALMAP' : '',
  11618. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  11619. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  11620. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  11621. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  11622. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  11623. parameters.vertexColors ? '#define USE_COLOR' : '',
  11624. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  11625. parameters.flatShading ? '#define FLAT_SHADED' : '',
  11626. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  11627. parameters.flipSided ? '#define FLIP_SIDED' : '',
  11628. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  11629. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  11630. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  11631. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  11632. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  11633. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  11634. parameters.envMap && ( capabilities.isWebGL2 || extensions.get( 'EXT_shader_texture_lod' ) ) ? '#define TEXTURE_LOD_EXT' : '',
  11635. 'uniform mat4 viewMatrix;',
  11636. 'uniform vec3 cameraPosition;',
  11637. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  11638. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  11639. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  11640. parameters.dithering ? '#define DITHERING' : '',
  11641. ( parameters.outputEncoding || parameters.mapEncoding || parameters.matcapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ?
  11642. ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  11643. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  11644. parameters.matcapEncoding ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  11645. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  11646. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  11647. parameters.outputEncoding ? getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ) : '',
  11648. parameters.depthPacking ? '#define DEPTH_PACKING ' + material.depthPacking : '',
  11649. '\n'
  11650. ].filter( filterEmptyLine ).join( '\n' );
  11651. }
  11652. vertexShader = parseIncludes( vertexShader );
  11653. vertexShader = replaceLightNums( vertexShader, parameters );
  11654. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  11655. fragmentShader = parseIncludes( fragmentShader );
  11656. fragmentShader = replaceLightNums( fragmentShader, parameters );
  11657. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  11658. vertexShader = unrollLoops( vertexShader );
  11659. fragmentShader = unrollLoops( fragmentShader );
  11660. if ( capabilities.isWebGL2 && ! material.isRawShaderMaterial ) {
  11661. var isGLSL3ShaderMaterial = false;
  11662. var versionRegex = /^\s*#version\s+300\s+es\s*\n/;
  11663. if ( material.isShaderMaterial &&
  11664. vertexShader.match( versionRegex ) !== null &&
  11665. fragmentShader.match( versionRegex ) !== null ) {
  11666. isGLSL3ShaderMaterial = true;
  11667. vertexShader = vertexShader.replace( versionRegex, '' );
  11668. fragmentShader = fragmentShader.replace( versionRegex, '' );
  11669. }
  11670. // GLSL 3.0 conversion
  11671. prefixVertex = [
  11672. '#version 300 es\n',
  11673. '#define attribute in',
  11674. '#define varying out',
  11675. '#define texture2D texture'
  11676. ].join( '\n' ) + '\n' + prefixVertex;
  11677. prefixFragment = [
  11678. '#version 300 es\n',
  11679. '#define varying in',
  11680. isGLSL3ShaderMaterial ? '' : 'out highp vec4 pc_fragColor;',
  11681. isGLSL3ShaderMaterial ? '' : '#define gl_FragColor pc_fragColor',
  11682. '#define gl_FragDepthEXT gl_FragDepth',
  11683. '#define texture2D texture',
  11684. '#define textureCube texture',
  11685. '#define texture2DProj textureProj',
  11686. '#define texture2DLodEXT textureLod',
  11687. '#define texture2DProjLodEXT textureProjLod',
  11688. '#define textureCubeLodEXT textureLod',
  11689. '#define texture2DGradEXT textureGrad',
  11690. '#define texture2DProjGradEXT textureProjGrad',
  11691. '#define textureCubeGradEXT textureGrad'
  11692. ].join( '\n' ) + '\n' + prefixFragment;
  11693. }
  11694. var vertexGlsl = prefixVertex + vertexShader;
  11695. var fragmentGlsl = prefixFragment + fragmentShader;
  11696. // console.log( '*VERTEX*', vertexGlsl );
  11697. // console.log( '*FRAGMENT*', fragmentGlsl );
  11698. var glVertexShader = WebGLShader( gl, 35633, vertexGlsl );
  11699. var glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl );
  11700. gl.attachShader( program, glVertexShader );
  11701. gl.attachShader( program, glFragmentShader );
  11702. // Force a particular attribute to index 0.
  11703. if ( material.index0AttributeName !== undefined ) {
  11704. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  11705. } else if ( parameters.morphTargets === true ) {
  11706. // programs with morphTargets displace position out of attribute 0
  11707. gl.bindAttribLocation( program, 0, 'position' );
  11708. }
  11709. gl.linkProgram( program );
  11710. // check for link errors
  11711. if ( renderer.debug.checkShaderErrors ) {
  11712. var programLog = gl.getProgramInfoLog( program ).trim();
  11713. var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  11714. var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  11715. var runnable = true;
  11716. var haveDiagnostics = true;
  11717. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  11718. runnable = false;
  11719. var vertexErrors = getShaderErrors( gl, glVertexShader, 'vertex' );
  11720. var fragmentErrors = getShaderErrors( gl, glFragmentShader, 'fragment' );
  11721. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors );
  11722. } else if ( programLog !== '' ) {
  11723. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  11724. } else if ( vertexLog === '' || fragmentLog === '' ) {
  11725. haveDiagnostics = false;
  11726. }
  11727. if ( haveDiagnostics ) {
  11728. this.diagnostics = {
  11729. runnable: runnable,
  11730. material: material,
  11731. programLog: programLog,
  11732. vertexShader: {
  11733. log: vertexLog,
  11734. prefix: prefixVertex
  11735. },
  11736. fragmentShader: {
  11737. log: fragmentLog,
  11738. prefix: prefixFragment
  11739. }
  11740. };
  11741. }
  11742. }
  11743. // clean up
  11744. gl.deleteShader( glVertexShader );
  11745. gl.deleteShader( glFragmentShader );
  11746. // set up caching for uniform locations
  11747. var cachedUniforms;
  11748. this.getUniforms = function () {
  11749. if ( cachedUniforms === undefined ) {
  11750. cachedUniforms = new WebGLUniforms( gl, program );
  11751. }
  11752. return cachedUniforms;
  11753. };
  11754. // set up caching for attribute locations
  11755. var cachedAttributes;
  11756. this.getAttributes = function () {
  11757. if ( cachedAttributes === undefined ) {
  11758. cachedAttributes = fetchAttributeLocations( gl, program );
  11759. }
  11760. return cachedAttributes;
  11761. };
  11762. // free resource
  11763. this.destroy = function () {
  11764. gl.deleteProgram( program );
  11765. this.program = undefined;
  11766. };
  11767. //
  11768. this.name = shader.name;
  11769. this.id = programIdCount ++;
  11770. this.code = code;
  11771. this.usedTimes = 1;
  11772. this.program = program;
  11773. this.vertexShader = glVertexShader;
  11774. this.fragmentShader = glFragmentShader;
  11775. return this;
  11776. }
  11777. /**
  11778. * @author mrdoob / http://mrdoob.com/
  11779. */
  11780. function WebGLPrograms( renderer, extensions, capabilities ) {
  11781. var programs = [];
  11782. var shaderIDs = {
  11783. MeshDepthMaterial: 'depth',
  11784. MeshDistanceMaterial: 'distanceRGBA',
  11785. MeshNormalMaterial: 'normal',
  11786. MeshBasicMaterial: 'basic',
  11787. MeshLambertMaterial: 'lambert',
  11788. MeshPhongMaterial: 'phong',
  11789. MeshToonMaterial: 'phong',
  11790. MeshStandardMaterial: 'physical',
  11791. MeshPhysicalMaterial: 'physical',
  11792. MeshMatcapMaterial: 'matcap',
  11793. LineBasicMaterial: 'basic',
  11794. LineDashedMaterial: 'dashed',
  11795. PointsMaterial: 'points',
  11796. ShadowMaterial: 'shadow',
  11797. SpriteMaterial: 'sprite'
  11798. };
  11799. var parameterNames = [
  11800. "precision", "supportsVertexTextures", "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding",
  11801. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "clearCoatNormalMap", "objectSpaceClearCoatNormalMap",, "displacementMap", "specularMap",
  11802. "roughnessMap", "metalnessMap", "gradientMap",
  11803. "alphaMap", "combine", "vertexColors", "vertexTangents", "fog", "useFog", "fogExp",
  11804. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  11805. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  11806. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  11807. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  11808. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  11809. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  11810. ];
  11811. function allocateBones( object ) {
  11812. var skeleton = object.skeleton;
  11813. var bones = skeleton.bones;
  11814. if ( capabilities.floatVertexTextures ) {
  11815. return 1024;
  11816. } else {
  11817. // default for when object is not specified
  11818. // ( for example when prebuilding shader to be used with multiple objects )
  11819. //
  11820. // - leave some extra space for other uniforms
  11821. // - limit here is ANGLE's 254 max uniform vectors
  11822. // (up to 54 should be safe)
  11823. var nVertexUniforms = capabilities.maxVertexUniforms;
  11824. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  11825. var maxBones = Math.min( nVertexMatrices, bones.length );
  11826. if ( maxBones < bones.length ) {
  11827. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  11828. return 0;
  11829. }
  11830. return maxBones;
  11831. }
  11832. }
  11833. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  11834. var encoding;
  11835. if ( ! map ) {
  11836. encoding = LinearEncoding;
  11837. } else if ( map.isTexture ) {
  11838. encoding = map.encoding;
  11839. } else if ( map.isWebGLRenderTarget ) {
  11840. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  11841. encoding = map.texture.encoding;
  11842. }
  11843. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  11844. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  11845. encoding = GammaEncoding;
  11846. }
  11847. return encoding;
  11848. }
  11849. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  11850. var shaderID = shaderIDs[ material.type ];
  11851. // heuristics to create shader parameters according to lights in the scene
  11852. // (not to blow over maxLights budget)
  11853. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  11854. var precision = capabilities.precision;
  11855. if ( material.precision !== null ) {
  11856. precision = capabilities.getMaxPrecision( material.precision );
  11857. if ( precision !== material.precision ) {
  11858. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  11859. }
  11860. }
  11861. var currentRenderTarget = renderer.getRenderTarget();
  11862. var parameters = {
  11863. shaderID: shaderID,
  11864. precision: precision,
  11865. supportsVertexTextures: capabilities.vertexTextures,
  11866. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  11867. map: !! material.map,
  11868. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  11869. matcap: !! material.matcap,
  11870. matcapEncoding: getTextureEncodingFromMap( material.matcap, renderer.gammaInput ),
  11871. envMap: !! material.envMap,
  11872. envMapMode: material.envMap && material.envMap.mapping,
  11873. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  11874. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  11875. lightMap: !! material.lightMap,
  11876. aoMap: !! material.aoMap,
  11877. emissiveMap: !! material.emissiveMap,
  11878. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  11879. bumpMap: !! material.bumpMap,
  11880. normalMap: !! material.normalMap,
  11881. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11882. clearCoatNormalMap: !! material.clearCoatNormalMap,
  11883. objectSpaceClearCoatNormalMap: material.clearCoatNormalMapType === ObjectSpaceNormalMap,
  11884. displacementMap: !! material.displacementMap,
  11885. roughnessMap: !! material.roughnessMap,
  11886. metalnessMap: !! material.metalnessMap,
  11887. specularMap: !! material.specularMap,
  11888. alphaMap: !! material.alphaMap,
  11889. gradientMap: !! material.gradientMap,
  11890. combine: material.combine,
  11891. vertexTangents: ( material.normalMap && material.vertexTangents ),
  11892. vertexColors: material.vertexColors,
  11893. fog: !! fog,
  11894. useFog: material.fog,
  11895. fogExp: ( fog && fog.isFogExp2 ),
  11896. flatShading: material.flatShading,
  11897. sizeAttenuation: material.sizeAttenuation,
  11898. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  11899. skinning: material.skinning && maxBones > 0,
  11900. maxBones: maxBones,
  11901. useVertexTexture: capabilities.floatVertexTextures,
  11902. morphTargets: material.morphTargets,
  11903. morphNormals: material.morphNormals,
  11904. maxMorphTargets: renderer.maxMorphTargets,
  11905. maxMorphNormals: renderer.maxMorphNormals,
  11906. numDirLights: lights.directional.length,
  11907. numPointLights: lights.point.length,
  11908. numSpotLights: lights.spot.length,
  11909. numRectAreaLights: lights.rectArea.length,
  11910. numHemiLights: lights.hemi.length,
  11911. numClippingPlanes: nClipPlanes,
  11912. numClipIntersection: nClipIntersection,
  11913. dithering: material.dithering,
  11914. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && shadows.length > 0,
  11915. shadowMapType: renderer.shadowMap.type,
  11916. toneMapping: renderer.toneMapping,
  11917. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11918. premultipliedAlpha: material.premultipliedAlpha,
  11919. alphaTest: material.alphaTest,
  11920. doubleSided: material.side === DoubleSide,
  11921. flipSided: material.side === BackSide,
  11922. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  11923. };
  11924. return parameters;
  11925. };
  11926. this.getProgramCode = function ( material, parameters ) {
  11927. var array = [];
  11928. if ( parameters.shaderID ) {
  11929. array.push( parameters.shaderID );
  11930. } else {
  11931. array.push( material.fragmentShader );
  11932. array.push( material.vertexShader );
  11933. }
  11934. if ( material.defines !== undefined ) {
  11935. for ( var name in material.defines ) {
  11936. array.push( name );
  11937. array.push( material.defines[ name ] );
  11938. }
  11939. }
  11940. for ( var i = 0; i < parameterNames.length; i ++ ) {
  11941. array.push( parameters[ parameterNames[ i ] ] );
  11942. }
  11943. array.push( material.onBeforeCompile.toString() );
  11944. array.push( renderer.gammaOutput );
  11945. array.push( renderer.gammaFactor );
  11946. return array.join();
  11947. };
  11948. this.acquireProgram = function ( material, shader, parameters, code ) {
  11949. var program;
  11950. // Check if code has been already compiled
  11951. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  11952. var programInfo = programs[ p ];
  11953. if ( programInfo.code === code ) {
  11954. program = programInfo;
  11955. ++ program.usedTimes;
  11956. break;
  11957. }
  11958. }
  11959. if ( program === undefined ) {
  11960. program = new WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities );
  11961. programs.push( program );
  11962. }
  11963. return program;
  11964. };
  11965. this.releaseProgram = function ( program ) {
  11966. if ( -- program.usedTimes === 0 ) {
  11967. // Remove from unordered set
  11968. var i = programs.indexOf( program );
  11969. programs[ i ] = programs[ programs.length - 1 ];
  11970. programs.pop();
  11971. // Free WebGL resources
  11972. program.destroy();
  11973. }
  11974. };
  11975. // Exposed for resource monitoring & error feedback via renderer.info:
  11976. this.programs = programs;
  11977. }
  11978. /**
  11979. * @author fordacious / fordacious.github.io
  11980. */
  11981. function WebGLProperties() {
  11982. var properties = new WeakMap();
  11983. function get( object ) {
  11984. var map = properties.get( object );
  11985. if ( map === undefined ) {
  11986. map = {};
  11987. properties.set( object, map );
  11988. }
  11989. return map;
  11990. }
  11991. function remove( object ) {
  11992. properties.delete( object );
  11993. }
  11994. function update( object, key, value ) {
  11995. properties.get( object )[ key ] = value;
  11996. }
  11997. function dispose() {
  11998. properties = new WeakMap();
  11999. }
  12000. return {
  12001. get: get,
  12002. remove: remove,
  12003. update: update,
  12004. dispose: dispose
  12005. };
  12006. }
  12007. /**
  12008. * @author mrdoob / http://mrdoob.com/
  12009. */
  12010. function painterSortStable( a, b ) {
  12011. if ( a.groupOrder !== b.groupOrder ) {
  12012. return a.groupOrder - b.groupOrder;
  12013. } else if ( a.renderOrder !== b.renderOrder ) {
  12014. return a.renderOrder - b.renderOrder;
  12015. } else if ( a.program !== b.program ) {
  12016. return a.program.id - b.program.id;
  12017. } else if ( a.material.id !== b.material.id ) {
  12018. return a.material.id - b.material.id;
  12019. } else if ( a.z !== b.z ) {
  12020. return a.z - b.z;
  12021. } else {
  12022. return a.id - b.id;
  12023. }
  12024. }
  12025. function reversePainterSortStable( a, b ) {
  12026. if ( a.groupOrder !== b.groupOrder ) {
  12027. return a.groupOrder - b.groupOrder;
  12028. } else if ( a.renderOrder !== b.renderOrder ) {
  12029. return a.renderOrder - b.renderOrder;
  12030. } else if ( a.z !== b.z ) {
  12031. return b.z - a.z;
  12032. } else {
  12033. return a.id - b.id;
  12034. }
  12035. }
  12036. function WebGLRenderList() {
  12037. var renderItems = [];
  12038. var renderItemsIndex = 0;
  12039. var opaque = [];
  12040. var transparent = [];
  12041. var defaultProgram = { id: - 1 };
  12042. function init() {
  12043. renderItemsIndex = 0;
  12044. opaque.length = 0;
  12045. transparent.length = 0;
  12046. }
  12047. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  12048. var renderItem = renderItems[ renderItemsIndex ];
  12049. if ( renderItem === undefined ) {
  12050. renderItem = {
  12051. id: object.id,
  12052. object: object,
  12053. geometry: geometry,
  12054. material: material,
  12055. program: material.program || defaultProgram,
  12056. groupOrder: groupOrder,
  12057. renderOrder: object.renderOrder,
  12058. z: z,
  12059. group: group
  12060. };
  12061. renderItems[ renderItemsIndex ] = renderItem;
  12062. } else {
  12063. renderItem.id = object.id;
  12064. renderItem.object = object;
  12065. renderItem.geometry = geometry;
  12066. renderItem.material = material;
  12067. renderItem.program = material.program || defaultProgram;
  12068. renderItem.groupOrder = groupOrder;
  12069. renderItem.renderOrder = object.renderOrder;
  12070. renderItem.z = z;
  12071. renderItem.group = group;
  12072. }
  12073. renderItemsIndex ++;
  12074. return renderItem;
  12075. }
  12076. function push( object, geometry, material, groupOrder, z, group ) {
  12077. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  12078. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  12079. }
  12080. function unshift( object, geometry, material, groupOrder, z, group ) {
  12081. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  12082. ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
  12083. }
  12084. function sort() {
  12085. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  12086. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  12087. }
  12088. return {
  12089. opaque: opaque,
  12090. transparent: transparent,
  12091. init: init,
  12092. push: push,
  12093. unshift: unshift,
  12094. sort: sort
  12095. };
  12096. }
  12097. function WebGLRenderLists() {
  12098. var lists = {};
  12099. function onSceneDispose( event ) {
  12100. var scene = event.target;
  12101. scene.removeEventListener( 'dispose', onSceneDispose );
  12102. delete lists[ scene.id ];
  12103. }
  12104. function get( scene, camera ) {
  12105. var cameras = lists[ scene.id ];
  12106. var list;
  12107. if ( cameras === undefined ) {
  12108. list = new WebGLRenderList();
  12109. lists[ scene.id ] = {};
  12110. lists[ scene.id ][ camera.id ] = list;
  12111. scene.addEventListener( 'dispose', onSceneDispose );
  12112. } else {
  12113. list = cameras[ camera.id ];
  12114. if ( list === undefined ) {
  12115. list = new WebGLRenderList();
  12116. cameras[ camera.id ] = list;
  12117. }
  12118. }
  12119. return list;
  12120. }
  12121. function dispose() {
  12122. lists = {};
  12123. }
  12124. return {
  12125. get: get,
  12126. dispose: dispose
  12127. };
  12128. }
  12129. /**
  12130. * @author mrdoob / http://mrdoob.com/
  12131. */
  12132. function UniformsCache() {
  12133. var lights = {};
  12134. return {
  12135. get: function ( light ) {
  12136. if ( lights[ light.id ] !== undefined ) {
  12137. return lights[ light.id ];
  12138. }
  12139. var uniforms;
  12140. switch ( light.type ) {
  12141. case 'DirectionalLight':
  12142. uniforms = {
  12143. direction: new Vector3(),
  12144. color: new Color(),
  12145. shadow: false,
  12146. shadowBias: 0,
  12147. shadowRadius: 1,
  12148. shadowMapSize: new Vector2()
  12149. };
  12150. break;
  12151. case 'SpotLight':
  12152. uniforms = {
  12153. position: new Vector3(),
  12154. direction: new Vector3(),
  12155. color: new Color(),
  12156. distance: 0,
  12157. coneCos: 0,
  12158. penumbraCos: 0,
  12159. decay: 0,
  12160. shadow: false,
  12161. shadowBias: 0,
  12162. shadowRadius: 1,
  12163. shadowMapSize: new Vector2()
  12164. };
  12165. break;
  12166. case 'PointLight':
  12167. uniforms = {
  12168. position: new Vector3(),
  12169. color: new Color(),
  12170. distance: 0,
  12171. decay: 0,
  12172. shadow: false,
  12173. shadowBias: 0,
  12174. shadowRadius: 1,
  12175. shadowMapSize: new Vector2(),
  12176. shadowCameraNear: 1,
  12177. shadowCameraFar: 1000
  12178. };
  12179. break;
  12180. case 'HemisphereLight':
  12181. uniforms = {
  12182. direction: new Vector3(),
  12183. skyColor: new Color(),
  12184. groundColor: new Color()
  12185. };
  12186. break;
  12187. case 'RectAreaLight':
  12188. uniforms = {
  12189. color: new Color(),
  12190. position: new Vector3(),
  12191. halfWidth: new Vector3(),
  12192. halfHeight: new Vector3()
  12193. // TODO (abelnation): set RectAreaLight shadow uniforms
  12194. };
  12195. break;
  12196. }
  12197. lights[ light.id ] = uniforms;
  12198. return uniforms;
  12199. }
  12200. };
  12201. }
  12202. var nextVersion = 0;
  12203. function WebGLLights() {
  12204. var cache = new UniformsCache();
  12205. var state = {
  12206. version: 0,
  12207. hash: {
  12208. directionalLength: - 1,
  12209. pointLength: - 1,
  12210. spotLength: - 1,
  12211. rectAreaLength: - 1,
  12212. hemiLength: - 1,
  12213. shadowsLength: - 1,
  12214. },
  12215. ambient: [ 0, 0, 0 ],
  12216. probe: [],
  12217. directional: [],
  12218. directionalShadowMap: [],
  12219. directionalShadowMatrix: [],
  12220. spot: [],
  12221. spotShadowMap: [],
  12222. spotShadowMatrix: [],
  12223. rectArea: [],
  12224. point: [],
  12225. pointShadowMap: [],
  12226. pointShadowMatrix: [],
  12227. hemi: []
  12228. };
  12229. for ( var i = 0; i < 9; i ++ ) state.probe.push( new Vector3() );
  12230. var vector3 = new Vector3();
  12231. var matrix4 = new Matrix4();
  12232. var matrix42 = new Matrix4();
  12233. function setup( lights, shadows, camera ) {
  12234. var r = 0, g = 0, b = 0;
  12235. for ( var i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 );
  12236. var directionalLength = 0;
  12237. var pointLength = 0;
  12238. var spotLength = 0;
  12239. var rectAreaLength = 0;
  12240. var hemiLength = 0;
  12241. var viewMatrix = camera.matrixWorldInverse;
  12242. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  12243. var light = lights[ i ];
  12244. var color = light.color;
  12245. var intensity = light.intensity;
  12246. var distance = light.distance;
  12247. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  12248. if ( light.isAmbientLight ) {
  12249. r += color.r * intensity;
  12250. g += color.g * intensity;
  12251. b += color.b * intensity;
  12252. } else if ( light.isLightProbe ) {
  12253. for ( var j = 0; j < 9; j ++ ) {
  12254. state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity );
  12255. }
  12256. } else if ( light.isDirectionalLight ) {
  12257. var uniforms = cache.get( light );
  12258. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  12259. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  12260. vector3.setFromMatrixPosition( light.target.matrixWorld );
  12261. uniforms.direction.sub( vector3 );
  12262. uniforms.direction.transformDirection( viewMatrix );
  12263. uniforms.shadow = light.castShadow;
  12264. if ( light.castShadow ) {
  12265. var shadow = light.shadow;
  12266. uniforms.shadowBias = shadow.bias;
  12267. uniforms.shadowRadius = shadow.radius;
  12268. uniforms.shadowMapSize = shadow.mapSize;
  12269. }
  12270. state.directionalShadowMap[ directionalLength ] = shadowMap;
  12271. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  12272. state.directional[ directionalLength ] = uniforms;
  12273. directionalLength ++;
  12274. } else if ( light.isSpotLight ) {
  12275. var uniforms = cache.get( light );
  12276. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  12277. uniforms.position.applyMatrix4( viewMatrix );
  12278. uniforms.color.copy( color ).multiplyScalar( intensity );
  12279. uniforms.distance = distance;
  12280. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  12281. vector3.setFromMatrixPosition( light.target.matrixWorld );
  12282. uniforms.direction.sub( vector3 );
  12283. uniforms.direction.transformDirection( viewMatrix );
  12284. uniforms.coneCos = Math.cos( light.angle );
  12285. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  12286. uniforms.decay = light.decay;
  12287. uniforms.shadow = light.castShadow;
  12288. if ( light.castShadow ) {
  12289. var shadow = light.shadow;
  12290. uniforms.shadowBias = shadow.bias;
  12291. uniforms.shadowRadius = shadow.radius;
  12292. uniforms.shadowMapSize = shadow.mapSize;
  12293. }
  12294. state.spotShadowMap[ spotLength ] = shadowMap;
  12295. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  12296. state.spot[ spotLength ] = uniforms;
  12297. spotLength ++;
  12298. } else if ( light.isRectAreaLight ) {
  12299. var uniforms = cache.get( light );
  12300. // (a) intensity is the total visible light emitted
  12301. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  12302. // (b) intensity is the brightness of the light
  12303. uniforms.color.copy( color ).multiplyScalar( intensity );
  12304. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  12305. uniforms.position.applyMatrix4( viewMatrix );
  12306. // extract local rotation of light to derive width/height half vectors
  12307. matrix42.identity();
  12308. matrix4.copy( light.matrixWorld );
  12309. matrix4.premultiply( viewMatrix );
  12310. matrix42.extractRotation( matrix4 );
  12311. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  12312. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  12313. uniforms.halfWidth.applyMatrix4( matrix42 );
  12314. uniforms.halfHeight.applyMatrix4( matrix42 );
  12315. // TODO (abelnation): RectAreaLight distance?
  12316. // uniforms.distance = distance;
  12317. state.rectArea[ rectAreaLength ] = uniforms;
  12318. rectAreaLength ++;
  12319. } else if ( light.isPointLight ) {
  12320. var uniforms = cache.get( light );
  12321. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  12322. uniforms.position.applyMatrix4( viewMatrix );
  12323. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  12324. uniforms.distance = light.distance;
  12325. uniforms.decay = light.decay;
  12326. uniforms.shadow = light.castShadow;
  12327. if ( light.castShadow ) {
  12328. var shadow = light.shadow;
  12329. uniforms.shadowBias = shadow.bias;
  12330. uniforms.shadowRadius = shadow.radius;
  12331. uniforms.shadowMapSize = shadow.mapSize;
  12332. uniforms.shadowCameraNear = shadow.camera.near;
  12333. uniforms.shadowCameraFar = shadow.camera.far;
  12334. }
  12335. state.pointShadowMap[ pointLength ] = shadowMap;
  12336. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  12337. state.point[ pointLength ] = uniforms;
  12338. pointLength ++;
  12339. } else if ( light.isHemisphereLight ) {
  12340. var uniforms = cache.get( light );
  12341. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  12342. uniforms.direction.transformDirection( viewMatrix );
  12343. uniforms.direction.normalize();
  12344. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  12345. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  12346. state.hemi[ hemiLength ] = uniforms;
  12347. hemiLength ++;
  12348. }
  12349. }
  12350. state.ambient[ 0 ] = r;
  12351. state.ambient[ 1 ] = g;
  12352. state.ambient[ 2 ] = b;
  12353. var hash = state.hash;
  12354. if ( hash.directionalLength !== directionalLength ||
  12355. hash.pointLength !== pointLength ||
  12356. hash.spotLength !== spotLength ||
  12357. hash.rectAreaLength !== rectAreaLength ||
  12358. hash.hemiLength !== hemiLength ||
  12359. hash.shadowsLength !== shadows.length ) {
  12360. state.directional.length = directionalLength;
  12361. state.spot.length = spotLength;
  12362. state.rectArea.length = rectAreaLength;
  12363. state.point.length = pointLength;
  12364. state.hemi.length = hemiLength;
  12365. hash.directionalLength = directionalLength;
  12366. hash.pointLength = pointLength;
  12367. hash.spotLength = spotLength;
  12368. hash.rectAreaLength = rectAreaLength;
  12369. hash.hemiLength = hemiLength;
  12370. hash.shadowsLength = shadows.length;
  12371. state.version = nextVersion ++;
  12372. }
  12373. }
  12374. return {
  12375. setup: setup,
  12376. state: state
  12377. };
  12378. }
  12379. /**
  12380. * @author Mugen87 / https://github.com/Mugen87
  12381. */
  12382. function WebGLRenderState() {
  12383. var lights = new WebGLLights();
  12384. var lightsArray = [];
  12385. var shadowsArray = [];
  12386. function init() {
  12387. lightsArray.length = 0;
  12388. shadowsArray.length = 0;
  12389. }
  12390. function pushLight( light ) {
  12391. lightsArray.push( light );
  12392. }
  12393. function pushShadow( shadowLight ) {
  12394. shadowsArray.push( shadowLight );
  12395. }
  12396. function setupLights( camera ) {
  12397. lights.setup( lightsArray, shadowsArray, camera );
  12398. }
  12399. var state = {
  12400. lightsArray: lightsArray,
  12401. shadowsArray: shadowsArray,
  12402. lights: lights
  12403. };
  12404. return {
  12405. init: init,
  12406. state: state,
  12407. setupLights: setupLights,
  12408. pushLight: pushLight,
  12409. pushShadow: pushShadow
  12410. };
  12411. }
  12412. function WebGLRenderStates() {
  12413. var renderStates = {};
  12414. function onSceneDispose( event ) {
  12415. var scene = event.target;
  12416. scene.removeEventListener( 'dispose', onSceneDispose );
  12417. delete renderStates[ scene.id ];
  12418. }
  12419. function get( scene, camera ) {
  12420. var renderState;
  12421. if ( renderStates[ scene.id ] === undefined ) {
  12422. renderState = new WebGLRenderState();
  12423. renderStates[ scene.id ] = {};
  12424. renderStates[ scene.id ][ camera.id ] = renderState;
  12425. scene.addEventListener( 'dispose', onSceneDispose );
  12426. } else {
  12427. if ( renderStates[ scene.id ][ camera.id ] === undefined ) {
  12428. renderState = new WebGLRenderState();
  12429. renderStates[ scene.id ][ camera.id ] = renderState;
  12430. } else {
  12431. renderState = renderStates[ scene.id ][ camera.id ];
  12432. }
  12433. }
  12434. return renderState;
  12435. }
  12436. function dispose() {
  12437. renderStates = {};
  12438. }
  12439. return {
  12440. get: get,
  12441. dispose: dispose
  12442. };
  12443. }
  12444. /**
  12445. * @author mrdoob / http://mrdoob.com/
  12446. * @author alteredq / http://alteredqualia.com/
  12447. * @author bhouston / https://clara.io
  12448. * @author WestLangley / http://github.com/WestLangley
  12449. *
  12450. * parameters = {
  12451. *
  12452. * opacity: <float>,
  12453. *
  12454. * map: new THREE.Texture( <Image> ),
  12455. *
  12456. * alphaMap: new THREE.Texture( <Image> ),
  12457. *
  12458. * displacementMap: new THREE.Texture( <Image> ),
  12459. * displacementScale: <float>,
  12460. * displacementBias: <float>,
  12461. *
  12462. * wireframe: <boolean>,
  12463. * wireframeLinewidth: <float>
  12464. * }
  12465. */
  12466. function MeshDepthMaterial( parameters ) {
  12467. Material.call( this );
  12468. this.type = 'MeshDepthMaterial';
  12469. this.depthPacking = BasicDepthPacking;
  12470. this.skinning = false;
  12471. this.morphTargets = false;
  12472. this.map = null;
  12473. this.alphaMap = null;
  12474. this.displacementMap = null;
  12475. this.displacementScale = 1;
  12476. this.displacementBias = 0;
  12477. this.wireframe = false;
  12478. this.wireframeLinewidth = 1;
  12479. this.fog = false;
  12480. this.lights = false;
  12481. this.setValues( parameters );
  12482. }
  12483. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  12484. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  12485. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  12486. MeshDepthMaterial.prototype.copy = function ( source ) {
  12487. Material.prototype.copy.call( this, source );
  12488. this.depthPacking = source.depthPacking;
  12489. this.skinning = source.skinning;
  12490. this.morphTargets = source.morphTargets;
  12491. this.map = source.map;
  12492. this.alphaMap = source.alphaMap;
  12493. this.displacementMap = source.displacementMap;
  12494. this.displacementScale = source.displacementScale;
  12495. this.displacementBias = source.displacementBias;
  12496. this.wireframe = source.wireframe;
  12497. this.wireframeLinewidth = source.wireframeLinewidth;
  12498. return this;
  12499. };
  12500. /**
  12501. * @author WestLangley / http://github.com/WestLangley
  12502. *
  12503. * parameters = {
  12504. *
  12505. * referencePosition: <float>,
  12506. * nearDistance: <float>,
  12507. * farDistance: <float>,
  12508. *
  12509. * skinning: <bool>,
  12510. * morphTargets: <bool>,
  12511. *
  12512. * map: new THREE.Texture( <Image> ),
  12513. *
  12514. * alphaMap: new THREE.Texture( <Image> ),
  12515. *
  12516. * displacementMap: new THREE.Texture( <Image> ),
  12517. * displacementScale: <float>,
  12518. * displacementBias: <float>
  12519. *
  12520. * }
  12521. */
  12522. function MeshDistanceMaterial( parameters ) {
  12523. Material.call( this );
  12524. this.type = 'MeshDistanceMaterial';
  12525. this.referencePosition = new Vector3();
  12526. this.nearDistance = 1;
  12527. this.farDistance = 1000;
  12528. this.skinning = false;
  12529. this.morphTargets = false;
  12530. this.map = null;
  12531. this.alphaMap = null;
  12532. this.displacementMap = null;
  12533. this.displacementScale = 1;
  12534. this.displacementBias = 0;
  12535. this.fog = false;
  12536. this.lights = false;
  12537. this.setValues( parameters );
  12538. }
  12539. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  12540. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  12541. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  12542. MeshDistanceMaterial.prototype.copy = function ( source ) {
  12543. Material.prototype.copy.call( this, source );
  12544. this.referencePosition.copy( source.referencePosition );
  12545. this.nearDistance = source.nearDistance;
  12546. this.farDistance = source.farDistance;
  12547. this.skinning = source.skinning;
  12548. this.morphTargets = source.morphTargets;
  12549. this.map = source.map;
  12550. this.alphaMap = source.alphaMap;
  12551. this.displacementMap = source.displacementMap;
  12552. this.displacementScale = source.displacementScale;
  12553. this.displacementBias = source.displacementBias;
  12554. return this;
  12555. };
  12556. /**
  12557. * @author alteredq / http://alteredqualia.com/
  12558. * @author mrdoob / http://mrdoob.com/
  12559. */
  12560. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  12561. var _frustum = new Frustum(),
  12562. _projScreenMatrix = new Matrix4(),
  12563. _shadowMapSize = new Vector2(),
  12564. _maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize ),
  12565. _lookTarget = new Vector3(),
  12566. _lightPositionWorld = new Vector3(),
  12567. _MorphingFlag = 1,
  12568. _SkinningFlag = 2,
  12569. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  12570. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  12571. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  12572. _materialCache = {};
  12573. var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  12574. var cubeDirections = [
  12575. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  12576. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  12577. ];
  12578. var cubeUps = [
  12579. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  12580. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  12581. ];
  12582. var cube2DViewPorts = [
  12583. new Vector4(), new Vector4(), new Vector4(),
  12584. new Vector4(), new Vector4(), new Vector4()
  12585. ];
  12586. // init
  12587. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  12588. var useMorphing = ( i & _MorphingFlag ) !== 0;
  12589. var useSkinning = ( i & _SkinningFlag ) !== 0;
  12590. var depthMaterial = new MeshDepthMaterial( {
  12591. depthPacking: RGBADepthPacking,
  12592. morphTargets: useMorphing,
  12593. skinning: useSkinning
  12594. } );
  12595. _depthMaterials[ i ] = depthMaterial;
  12596. //
  12597. var distanceMaterial = new MeshDistanceMaterial( {
  12598. morphTargets: useMorphing,
  12599. skinning: useSkinning
  12600. } );
  12601. _distanceMaterials[ i ] = distanceMaterial;
  12602. }
  12603. //
  12604. var scope = this;
  12605. this.enabled = false;
  12606. this.autoUpdate = true;
  12607. this.needsUpdate = false;
  12608. this.type = PCFShadowMap;
  12609. this.render = function ( lights, scene, camera ) {
  12610. if ( scope.enabled === false ) return;
  12611. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  12612. if ( lights.length === 0 ) return;
  12613. var currentRenderTarget = _renderer.getRenderTarget();
  12614. var activeCubeFace = _renderer.getActiveCubeFace();
  12615. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  12616. var _state = _renderer.state;
  12617. // Set GL state for depth map.
  12618. _state.setBlending( NoBlending );
  12619. _state.buffers.color.setClear( 1, 1, 1, 1 );
  12620. _state.buffers.depth.setTest( true );
  12621. _state.setScissorTest( false );
  12622. // render depth map
  12623. var faceCount;
  12624. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  12625. var light = lights[ i ];
  12626. var shadow = light.shadow;
  12627. var isPointLight = light && light.isPointLight;
  12628. if ( shadow === undefined ) {
  12629. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  12630. continue;
  12631. }
  12632. var shadowCamera = shadow.camera;
  12633. _shadowMapSize.copy( shadow.mapSize );
  12634. _shadowMapSize.min( _maxShadowMapSize );
  12635. if ( isPointLight ) {
  12636. var vpWidth = _shadowMapSize.x;
  12637. var vpHeight = _shadowMapSize.y;
  12638. // These viewports map a cube-map onto a 2D texture with the
  12639. // following orientation:
  12640. //
  12641. // xzXZ
  12642. // y Y
  12643. //
  12644. // X - Positive x direction
  12645. // x - Negative x direction
  12646. // Y - Positive y direction
  12647. // y - Negative y direction
  12648. // Z - Positive z direction
  12649. // z - Negative z direction
  12650. // positive X
  12651. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  12652. // negative X
  12653. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  12654. // positive Z
  12655. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  12656. // negative Z
  12657. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  12658. // positive Y
  12659. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  12660. // negative Y
  12661. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  12662. _shadowMapSize.x *= 4.0;
  12663. _shadowMapSize.y *= 2.0;
  12664. }
  12665. if ( shadow.map === null ) {
  12666. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  12667. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  12668. shadow.map.texture.name = light.name + ".shadowMap";
  12669. shadowCamera.updateProjectionMatrix();
  12670. }
  12671. if ( shadow.isSpotLightShadow ) {
  12672. shadow.update( light );
  12673. }
  12674. var shadowMap = shadow.map;
  12675. var shadowMatrix = shadow.matrix;
  12676. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  12677. shadowCamera.position.copy( _lightPositionWorld );
  12678. if ( isPointLight ) {
  12679. faceCount = 6;
  12680. // for point lights we set the shadow matrix to be a translation-only matrix
  12681. // equal to inverse of the light's position
  12682. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  12683. } else {
  12684. faceCount = 1;
  12685. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  12686. shadowCamera.lookAt( _lookTarget );
  12687. shadowCamera.updateMatrixWorld();
  12688. // compute shadow matrix
  12689. shadowMatrix.set(
  12690. 0.5, 0.0, 0.0, 0.5,
  12691. 0.0, 0.5, 0.0, 0.5,
  12692. 0.0, 0.0, 0.5, 0.5,
  12693. 0.0, 0.0, 0.0, 1.0
  12694. );
  12695. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  12696. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  12697. }
  12698. _renderer.setRenderTarget( shadowMap );
  12699. _renderer.clear();
  12700. // render shadow map for each cube face (if omni-directional) or
  12701. // run a single pass if not
  12702. for ( var face = 0; face < faceCount; face ++ ) {
  12703. if ( isPointLight ) {
  12704. _lookTarget.copy( shadowCamera.position );
  12705. _lookTarget.add( cubeDirections[ face ] );
  12706. shadowCamera.up.copy( cubeUps[ face ] );
  12707. shadowCamera.lookAt( _lookTarget );
  12708. shadowCamera.updateMatrixWorld();
  12709. var vpDimensions = cube2DViewPorts[ face ];
  12710. _state.viewport( vpDimensions );
  12711. }
  12712. // update camera matrices and frustum
  12713. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  12714. _frustum.setFromMatrix( _projScreenMatrix );
  12715. // set object matrices & frustum culling
  12716. renderObject( scene, camera, shadowCamera, isPointLight );
  12717. }
  12718. }
  12719. scope.needsUpdate = false;
  12720. _renderer.setRenderTarget( currentRenderTarget, activeCubeFace, activeMipmapLevel );
  12721. };
  12722. function getDepthMaterial( object, material, isPointLight, lightPositionWorld, shadowCameraNear, shadowCameraFar ) {
  12723. var geometry = object.geometry;
  12724. var result = null;
  12725. var materialVariants = _depthMaterials;
  12726. var customMaterial = object.customDepthMaterial;
  12727. if ( isPointLight ) {
  12728. materialVariants = _distanceMaterials;
  12729. customMaterial = object.customDistanceMaterial;
  12730. }
  12731. if ( ! customMaterial ) {
  12732. var useMorphing = false;
  12733. if ( material.morphTargets ) {
  12734. if ( geometry && geometry.isBufferGeometry ) {
  12735. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  12736. } else if ( geometry && geometry.isGeometry ) {
  12737. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  12738. }
  12739. }
  12740. if ( object.isSkinnedMesh && material.skinning === false ) {
  12741. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  12742. }
  12743. var useSkinning = object.isSkinnedMesh && material.skinning;
  12744. var variantIndex = 0;
  12745. if ( useMorphing ) variantIndex |= _MorphingFlag;
  12746. if ( useSkinning ) variantIndex |= _SkinningFlag;
  12747. result = materialVariants[ variantIndex ];
  12748. } else {
  12749. result = customMaterial;
  12750. }
  12751. if ( _renderer.localClippingEnabled &&
  12752. material.clipShadows === true &&
  12753. material.clippingPlanes.length !== 0 ) {
  12754. // in this case we need a unique material instance reflecting the
  12755. // appropriate state
  12756. var keyA = result.uuid, keyB = material.uuid;
  12757. var materialsForVariant = _materialCache[ keyA ];
  12758. if ( materialsForVariant === undefined ) {
  12759. materialsForVariant = {};
  12760. _materialCache[ keyA ] = materialsForVariant;
  12761. }
  12762. var cachedMaterial = materialsForVariant[ keyB ];
  12763. if ( cachedMaterial === undefined ) {
  12764. cachedMaterial = result.clone();
  12765. materialsForVariant[ keyB ] = cachedMaterial;
  12766. }
  12767. result = cachedMaterial;
  12768. }
  12769. result.visible = material.visible;
  12770. result.wireframe = material.wireframe;
  12771. result.side = ( material.shadowSide != null ) ? material.shadowSide : shadowSide[ material.side ];
  12772. result.clipShadows = material.clipShadows;
  12773. result.clippingPlanes = material.clippingPlanes;
  12774. result.clipIntersection = material.clipIntersection;
  12775. result.wireframeLinewidth = material.wireframeLinewidth;
  12776. result.linewidth = material.linewidth;
  12777. if ( isPointLight && result.isMeshDistanceMaterial ) {
  12778. result.referencePosition.copy( lightPositionWorld );
  12779. result.nearDistance = shadowCameraNear;
  12780. result.farDistance = shadowCameraFar;
  12781. }
  12782. return result;
  12783. }
  12784. function renderObject( object, camera, shadowCamera, isPointLight ) {
  12785. if ( object.visible === false ) return;
  12786. var visible = object.layers.test( camera.layers );
  12787. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  12788. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  12789. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  12790. var geometry = _objects.update( object );
  12791. var material = object.material;
  12792. if ( Array.isArray( material ) ) {
  12793. var groups = geometry.groups;
  12794. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  12795. var group = groups[ k ];
  12796. var groupMaterial = material[ group.materialIndex ];
  12797. if ( groupMaterial && groupMaterial.visible ) {
  12798. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  12799. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  12800. }
  12801. }
  12802. } else if ( material.visible ) {
  12803. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  12804. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  12805. }
  12806. }
  12807. }
  12808. var children = object.children;
  12809. for ( var i = 0, l = children.length; i < l; i ++ ) {
  12810. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  12811. }
  12812. }
  12813. }
  12814. /**
  12815. * @author mrdoob / http://mrdoob.com/
  12816. */
  12817. function WebGLState( gl, extensions, utils, capabilities ) {
  12818. function ColorBuffer() {
  12819. var locked = false;
  12820. var color = new Vector4();
  12821. var currentColorMask = null;
  12822. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  12823. return {
  12824. setMask: function ( colorMask ) {
  12825. if ( currentColorMask !== colorMask && ! locked ) {
  12826. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  12827. currentColorMask = colorMask;
  12828. }
  12829. },
  12830. setLocked: function ( lock ) {
  12831. locked = lock;
  12832. },
  12833. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  12834. if ( premultipliedAlpha === true ) {
  12835. r *= a; g *= a; b *= a;
  12836. }
  12837. color.set( r, g, b, a );
  12838. if ( currentColorClear.equals( color ) === false ) {
  12839. gl.clearColor( r, g, b, a );
  12840. currentColorClear.copy( color );
  12841. }
  12842. },
  12843. reset: function () {
  12844. locked = false;
  12845. currentColorMask = null;
  12846. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  12847. }
  12848. };
  12849. }
  12850. function DepthBuffer() {
  12851. var locked = false;
  12852. var currentDepthMask = null;
  12853. var currentDepthFunc = null;
  12854. var currentDepthClear = null;
  12855. return {
  12856. setTest: function ( depthTest ) {
  12857. if ( depthTest ) {
  12858. enable( 2929 );
  12859. } else {
  12860. disable( 2929 );
  12861. }
  12862. },
  12863. setMask: function ( depthMask ) {
  12864. if ( currentDepthMask !== depthMask && ! locked ) {
  12865. gl.depthMask( depthMask );
  12866. currentDepthMask = depthMask;
  12867. }
  12868. },
  12869. setFunc: function ( depthFunc ) {
  12870. if ( currentDepthFunc !== depthFunc ) {
  12871. if ( depthFunc ) {
  12872. switch ( depthFunc ) {
  12873. case NeverDepth:
  12874. gl.depthFunc( 512 );
  12875. break;
  12876. case AlwaysDepth:
  12877. gl.depthFunc( 519 );
  12878. break;
  12879. case LessDepth:
  12880. gl.depthFunc( 513 );
  12881. break;
  12882. case LessEqualDepth:
  12883. gl.depthFunc( 515 );
  12884. break;
  12885. case EqualDepth:
  12886. gl.depthFunc( 514 );
  12887. break;
  12888. case GreaterEqualDepth:
  12889. gl.depthFunc( 518 );
  12890. break;
  12891. case GreaterDepth:
  12892. gl.depthFunc( 516 );
  12893. break;
  12894. case NotEqualDepth:
  12895. gl.depthFunc( 517 );
  12896. break;
  12897. default:
  12898. gl.depthFunc( 515 );
  12899. }
  12900. } else {
  12901. gl.depthFunc( 515 );
  12902. }
  12903. currentDepthFunc = depthFunc;
  12904. }
  12905. },
  12906. setLocked: function ( lock ) {
  12907. locked = lock;
  12908. },
  12909. setClear: function ( depth ) {
  12910. if ( currentDepthClear !== depth ) {
  12911. gl.clearDepth( depth );
  12912. currentDepthClear = depth;
  12913. }
  12914. },
  12915. reset: function () {
  12916. locked = false;
  12917. currentDepthMask = null;
  12918. currentDepthFunc = null;
  12919. currentDepthClear = null;
  12920. }
  12921. };
  12922. }
  12923. function StencilBuffer() {
  12924. var locked = false;
  12925. var currentStencilMask = null;
  12926. var currentStencilFunc = null;
  12927. var currentStencilRef = null;
  12928. var currentStencilFuncMask = null;
  12929. var currentStencilFail = null;
  12930. var currentStencilZFail = null;
  12931. var currentStencilZPass = null;
  12932. var currentStencilClear = null;
  12933. return {
  12934. setTest: function ( stencilTest ) {
  12935. if ( stencilTest ) {
  12936. enable( 2960 );
  12937. } else {
  12938. disable( 2960 );
  12939. }
  12940. },
  12941. setMask: function ( stencilMask ) {
  12942. if ( currentStencilMask !== stencilMask && ! locked ) {
  12943. gl.stencilMask( stencilMask );
  12944. currentStencilMask = stencilMask;
  12945. }
  12946. },
  12947. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  12948. if ( currentStencilFunc !== stencilFunc ||
  12949. currentStencilRef !== stencilRef ||
  12950. currentStencilFuncMask !== stencilMask ) {
  12951. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  12952. currentStencilFunc = stencilFunc;
  12953. currentStencilRef = stencilRef;
  12954. currentStencilFuncMask = stencilMask;
  12955. }
  12956. },
  12957. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  12958. if ( currentStencilFail !== stencilFail ||
  12959. currentStencilZFail !== stencilZFail ||
  12960. currentStencilZPass !== stencilZPass ) {
  12961. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  12962. currentStencilFail = stencilFail;
  12963. currentStencilZFail = stencilZFail;
  12964. currentStencilZPass = stencilZPass;
  12965. }
  12966. },
  12967. setLocked: function ( lock ) {
  12968. locked = lock;
  12969. },
  12970. setClear: function ( stencil ) {
  12971. if ( currentStencilClear !== stencil ) {
  12972. gl.clearStencil( stencil );
  12973. currentStencilClear = stencil;
  12974. }
  12975. },
  12976. reset: function () {
  12977. locked = false;
  12978. currentStencilMask = null;
  12979. currentStencilFunc = null;
  12980. currentStencilRef = null;
  12981. currentStencilFuncMask = null;
  12982. currentStencilFail = null;
  12983. currentStencilZFail = null;
  12984. currentStencilZPass = null;
  12985. currentStencilClear = null;
  12986. }
  12987. };
  12988. }
  12989. //
  12990. var colorBuffer = new ColorBuffer();
  12991. var depthBuffer = new DepthBuffer();
  12992. var stencilBuffer = new StencilBuffer();
  12993. var maxVertexAttributes = gl.getParameter( 34921 );
  12994. var newAttributes = new Uint8Array( maxVertexAttributes );
  12995. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  12996. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  12997. var enabledCapabilities = {};
  12998. var compressedTextureFormats = null;
  12999. var currentProgram = null;
  13000. var currentBlendingEnabled = null;
  13001. var currentBlending = null;
  13002. var currentBlendEquation = null;
  13003. var currentBlendSrc = null;
  13004. var currentBlendDst = null;
  13005. var currentBlendEquationAlpha = null;
  13006. var currentBlendSrcAlpha = null;
  13007. var currentBlendDstAlpha = null;
  13008. var currentPremultipledAlpha = false;
  13009. var currentFlipSided = null;
  13010. var currentCullFace = null;
  13011. var currentLineWidth = null;
  13012. var currentPolygonOffsetFactor = null;
  13013. var currentPolygonOffsetUnits = null;
  13014. var maxTextures = gl.getParameter( 35661 );
  13015. var lineWidthAvailable = false;
  13016. var version = 0;
  13017. var glVersion = gl.getParameter( 7938 );
  13018. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  13019. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  13020. lineWidthAvailable = ( version >= 1.0 );
  13021. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  13022. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  13023. lineWidthAvailable = ( version >= 2.0 );
  13024. }
  13025. var currentTextureSlot = null;
  13026. var currentBoundTextures = {};
  13027. var currentScissor = new Vector4();
  13028. var currentViewport = new Vector4();
  13029. function createTexture( type, target, count ) {
  13030. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  13031. var texture = gl.createTexture();
  13032. gl.bindTexture( type, texture );
  13033. gl.texParameteri( type, 10241, 9728 );
  13034. gl.texParameteri( type, 10240, 9728 );
  13035. for ( var i = 0; i < count; i ++ ) {
  13036. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  13037. }
  13038. return texture;
  13039. }
  13040. var emptyTextures = {};
  13041. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  13042. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  13043. // init
  13044. colorBuffer.setClear( 0, 0, 0, 1 );
  13045. depthBuffer.setClear( 1 );
  13046. stencilBuffer.setClear( 0 );
  13047. enable( 2929 );
  13048. depthBuffer.setFunc( LessEqualDepth );
  13049. setFlipSided( false );
  13050. setCullFace( CullFaceBack );
  13051. enable( 2884 );
  13052. setBlending( NoBlending );
  13053. //
  13054. function initAttributes() {
  13055. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  13056. newAttributes[ i ] = 0;
  13057. }
  13058. }
  13059. function enableAttribute( attribute ) {
  13060. enableAttributeAndDivisor( attribute, 0 );
  13061. }
  13062. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  13063. newAttributes[ attribute ] = 1;
  13064. if ( enabledAttributes[ attribute ] === 0 ) {
  13065. gl.enableVertexAttribArray( attribute );
  13066. enabledAttributes[ attribute ] = 1;
  13067. }
  13068. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  13069. var extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  13070. extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  13071. attributeDivisors[ attribute ] = meshPerAttribute;
  13072. }
  13073. }
  13074. function disableUnusedAttributes() {
  13075. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  13076. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  13077. gl.disableVertexAttribArray( i );
  13078. enabledAttributes[ i ] = 0;
  13079. }
  13080. }
  13081. }
  13082. function enable( id ) {
  13083. if ( enabledCapabilities[ id ] !== true ) {
  13084. gl.enable( id );
  13085. enabledCapabilities[ id ] = true;
  13086. }
  13087. }
  13088. function disable( id ) {
  13089. if ( enabledCapabilities[ id ] !== false ) {
  13090. gl.disable( id );
  13091. enabledCapabilities[ id ] = false;
  13092. }
  13093. }
  13094. function getCompressedTextureFormats() {
  13095. if ( compressedTextureFormats === null ) {
  13096. compressedTextureFormats = [];
  13097. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  13098. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  13099. extensions.get( 'WEBGL_compressed_texture_etc1' ) ||
  13100. extensions.get( 'WEBGL_compressed_texture_astc' ) ) {
  13101. var formats = gl.getParameter( 34467 );
  13102. for ( var i = 0; i < formats.length; i ++ ) {
  13103. compressedTextureFormats.push( formats[ i ] );
  13104. }
  13105. }
  13106. }
  13107. return compressedTextureFormats;
  13108. }
  13109. function useProgram( program ) {
  13110. if ( currentProgram !== program ) {
  13111. gl.useProgram( program );
  13112. currentProgram = program;
  13113. return true;
  13114. }
  13115. return false;
  13116. }
  13117. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  13118. if ( blending === NoBlending ) {
  13119. if ( currentBlendingEnabled ) {
  13120. disable( 3042 );
  13121. currentBlendingEnabled = false;
  13122. }
  13123. return;
  13124. }
  13125. if ( ! currentBlendingEnabled ) {
  13126. enable( 3042 );
  13127. currentBlendingEnabled = true;
  13128. }
  13129. if ( blending !== CustomBlending ) {
  13130. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  13131. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  13132. gl.blendEquation( 32774 );
  13133. currentBlendEquation = AddEquation;
  13134. currentBlendEquationAlpha = AddEquation;
  13135. }
  13136. if ( premultipliedAlpha ) {
  13137. switch ( blending ) {
  13138. case NormalBlending:
  13139. gl.blendFuncSeparate( 1, 771, 1, 771 );
  13140. break;
  13141. case AdditiveBlending:
  13142. gl.blendFunc( 1, 1 );
  13143. break;
  13144. case SubtractiveBlending:
  13145. gl.blendFuncSeparate( 0, 0, 769, 771 );
  13146. break;
  13147. case MultiplyBlending:
  13148. gl.blendFuncSeparate( 0, 768, 0, 770 );
  13149. break;
  13150. default:
  13151. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  13152. break;
  13153. }
  13154. } else {
  13155. switch ( blending ) {
  13156. case NormalBlending:
  13157. gl.blendFuncSeparate( 770, 771, 1, 771 );
  13158. break;
  13159. case AdditiveBlending:
  13160. gl.blendFunc( 770, 1 );
  13161. break;
  13162. case SubtractiveBlending:
  13163. gl.blendFunc( 0, 769 );
  13164. break;
  13165. case MultiplyBlending:
  13166. gl.blendFunc( 0, 768 );
  13167. break;
  13168. default:
  13169. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  13170. break;
  13171. }
  13172. }
  13173. currentBlendSrc = null;
  13174. currentBlendDst = null;
  13175. currentBlendSrcAlpha = null;
  13176. currentBlendDstAlpha = null;
  13177. currentBlending = blending;
  13178. currentPremultipledAlpha = premultipliedAlpha;
  13179. }
  13180. return;
  13181. }
  13182. // custom blending
  13183. blendEquationAlpha = blendEquationAlpha || blendEquation;
  13184. blendSrcAlpha = blendSrcAlpha || blendSrc;
  13185. blendDstAlpha = blendDstAlpha || blendDst;
  13186. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  13187. gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
  13188. currentBlendEquation = blendEquation;
  13189. currentBlendEquationAlpha = blendEquationAlpha;
  13190. }
  13191. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  13192. gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
  13193. currentBlendSrc = blendSrc;
  13194. currentBlendDst = blendDst;
  13195. currentBlendSrcAlpha = blendSrcAlpha;
  13196. currentBlendDstAlpha = blendDstAlpha;
  13197. }
  13198. currentBlending = blending;
  13199. currentPremultipledAlpha = null;
  13200. }
  13201. function setMaterial( material, frontFaceCW ) {
  13202. material.side === DoubleSide
  13203. ? disable( 2884 )
  13204. : enable( 2884 );
  13205. var flipSided = ( material.side === BackSide );
  13206. if ( frontFaceCW ) flipSided = ! flipSided;
  13207. setFlipSided( flipSided );
  13208. ( material.blending === NormalBlending && material.transparent === false )
  13209. ? setBlending( NoBlending )
  13210. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  13211. depthBuffer.setFunc( material.depthFunc );
  13212. depthBuffer.setTest( material.depthTest );
  13213. depthBuffer.setMask( material.depthWrite );
  13214. colorBuffer.setMask( material.colorWrite );
  13215. var stencilWrite = material.stencilWrite;
  13216. stencilBuffer.setTest( stencilWrite );
  13217. if ( stencilWrite ) {
  13218. stencilBuffer.setFunc( material.stencilFunc, material.stencilRef, material.stencilMask );
  13219. stencilBuffer.setOp( material.stencilFail, material.stencilZFail, material.stencilZPass );
  13220. }
  13221. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  13222. }
  13223. //
  13224. function setFlipSided( flipSided ) {
  13225. if ( currentFlipSided !== flipSided ) {
  13226. if ( flipSided ) {
  13227. gl.frontFace( 2304 );
  13228. } else {
  13229. gl.frontFace( 2305 );
  13230. }
  13231. currentFlipSided = flipSided;
  13232. }
  13233. }
  13234. function setCullFace( cullFace ) {
  13235. if ( cullFace !== CullFaceNone ) {
  13236. enable( 2884 );
  13237. if ( cullFace !== currentCullFace ) {
  13238. if ( cullFace === CullFaceBack ) {
  13239. gl.cullFace( 1029 );
  13240. } else if ( cullFace === CullFaceFront ) {
  13241. gl.cullFace( 1028 );
  13242. } else {
  13243. gl.cullFace( 1032 );
  13244. }
  13245. }
  13246. } else {
  13247. disable( 2884 );
  13248. }
  13249. currentCullFace = cullFace;
  13250. }
  13251. function setLineWidth( width ) {
  13252. if ( width !== currentLineWidth ) {
  13253. if ( lineWidthAvailable ) gl.lineWidth( width );
  13254. currentLineWidth = width;
  13255. }
  13256. }
  13257. function setPolygonOffset( polygonOffset, factor, units ) {
  13258. if ( polygonOffset ) {
  13259. enable( 32823 );
  13260. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  13261. gl.polygonOffset( factor, units );
  13262. currentPolygonOffsetFactor = factor;
  13263. currentPolygonOffsetUnits = units;
  13264. }
  13265. } else {
  13266. disable( 32823 );
  13267. }
  13268. }
  13269. function setScissorTest( scissorTest ) {
  13270. if ( scissorTest ) {
  13271. enable( 3089 );
  13272. } else {
  13273. disable( 3089 );
  13274. }
  13275. }
  13276. // texture
  13277. function activeTexture( webglSlot ) {
  13278. if ( webglSlot === undefined ) webglSlot = 33984 + maxTextures - 1;
  13279. if ( currentTextureSlot !== webglSlot ) {
  13280. gl.activeTexture( webglSlot );
  13281. currentTextureSlot = webglSlot;
  13282. }
  13283. }
  13284. function bindTexture( webglType, webglTexture ) {
  13285. if ( currentTextureSlot === null ) {
  13286. activeTexture();
  13287. }
  13288. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  13289. if ( boundTexture === undefined ) {
  13290. boundTexture = { type: undefined, texture: undefined };
  13291. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  13292. }
  13293. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  13294. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  13295. boundTexture.type = webglType;
  13296. boundTexture.texture = webglTexture;
  13297. }
  13298. }
  13299. function compressedTexImage2D() {
  13300. try {
  13301. gl.compressedTexImage2D.apply( gl, arguments );
  13302. } catch ( error ) {
  13303. console.error( 'THREE.WebGLState:', error );
  13304. }
  13305. }
  13306. function texImage2D() {
  13307. try {
  13308. gl.texImage2D.apply( gl, arguments );
  13309. } catch ( error ) {
  13310. console.error( 'THREE.WebGLState:', error );
  13311. }
  13312. }
  13313. function texImage3D() {
  13314. try {
  13315. gl.texImage3D.apply( gl, arguments );
  13316. } catch ( error ) {
  13317. console.error( 'THREE.WebGLState:', error );
  13318. }
  13319. }
  13320. //
  13321. function scissor( scissor ) {
  13322. if ( currentScissor.equals( scissor ) === false ) {
  13323. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  13324. currentScissor.copy( scissor );
  13325. }
  13326. }
  13327. function viewport( viewport ) {
  13328. if ( currentViewport.equals( viewport ) === false ) {
  13329. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  13330. currentViewport.copy( viewport );
  13331. }
  13332. }
  13333. //
  13334. function reset() {
  13335. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  13336. if ( enabledAttributes[ i ] === 1 ) {
  13337. gl.disableVertexAttribArray( i );
  13338. enabledAttributes[ i ] = 0;
  13339. }
  13340. }
  13341. enabledCapabilities = {};
  13342. compressedTextureFormats = null;
  13343. currentTextureSlot = null;
  13344. currentBoundTextures = {};
  13345. currentProgram = null;
  13346. currentBlending = null;
  13347. currentFlipSided = null;
  13348. currentCullFace = null;
  13349. colorBuffer.reset();
  13350. depthBuffer.reset();
  13351. stencilBuffer.reset();
  13352. }
  13353. return {
  13354. buffers: {
  13355. color: colorBuffer,
  13356. depth: depthBuffer,
  13357. stencil: stencilBuffer
  13358. },
  13359. initAttributes: initAttributes,
  13360. enableAttribute: enableAttribute,
  13361. enableAttributeAndDivisor: enableAttributeAndDivisor,
  13362. disableUnusedAttributes: disableUnusedAttributes,
  13363. enable: enable,
  13364. disable: disable,
  13365. getCompressedTextureFormats: getCompressedTextureFormats,
  13366. useProgram: useProgram,
  13367. setBlending: setBlending,
  13368. setMaterial: setMaterial,
  13369. setFlipSided: setFlipSided,
  13370. setCullFace: setCullFace,
  13371. setLineWidth: setLineWidth,
  13372. setPolygonOffset: setPolygonOffset,
  13373. setScissorTest: setScissorTest,
  13374. activeTexture: activeTexture,
  13375. bindTexture: bindTexture,
  13376. compressedTexImage2D: compressedTexImage2D,
  13377. texImage2D: texImage2D,
  13378. texImage3D: texImage3D,
  13379. scissor: scissor,
  13380. viewport: viewport,
  13381. reset: reset
  13382. };
  13383. }
  13384. /**
  13385. * @author mrdoob / http://mrdoob.com/
  13386. */
  13387. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  13388. var _videoTextures = {};
  13389. var _canvas;
  13390. //
  13391. var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined';
  13392. function createCanvas( width, height ) {
  13393. // Use OffscreenCanvas when available. Specially needed in web workers
  13394. return useOffscreenCanvas ?
  13395. new OffscreenCanvas( width, height ) :
  13396. document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  13397. }
  13398. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  13399. var scale = 1;
  13400. // handle case if texture exceeds max size
  13401. if ( image.width > maxSize || image.height > maxSize ) {
  13402. scale = maxSize / Math.max( image.width, image.height );
  13403. }
  13404. // only perform resize if necessary
  13405. if ( scale < 1 || needsPowerOfTwo === true ) {
  13406. // only perform resize for certain image types
  13407. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  13408. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  13409. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  13410. var floor = needsPowerOfTwo ? _Math.floorPowerOfTwo : Math.floor;
  13411. var width = floor( scale * image.width );
  13412. var height = floor( scale * image.height );
  13413. if ( _canvas === undefined ) _canvas = createCanvas( width, height );
  13414. // cube textures can't reuse the same canvas
  13415. var canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
  13416. canvas.width = width;
  13417. canvas.height = height;
  13418. var context = canvas.getContext( '2d' );
  13419. context.drawImage( image, 0, 0, width, height );
  13420. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
  13421. return canvas;
  13422. } else {
  13423. if ( 'data' in image ) {
  13424. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  13425. }
  13426. return image;
  13427. }
  13428. }
  13429. return image;
  13430. }
  13431. function isPowerOfTwo( image ) {
  13432. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  13433. }
  13434. function textureNeedsPowerOfTwo( texture ) {
  13435. if ( capabilities.isWebGL2 ) return false;
  13436. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  13437. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  13438. }
  13439. function textureNeedsGenerateMipmaps( texture, supportsMips ) {
  13440. return texture.generateMipmaps && supportsMips &&
  13441. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13442. }
  13443. function generateMipmap( target, texture, width, height ) {
  13444. _gl.generateMipmap( target );
  13445. var textureProperties = properties.get( texture );
  13446. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  13447. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  13448. }
  13449. function getInternalFormat( glFormat, glType ) {
  13450. if ( ! capabilities.isWebGL2 ) return glFormat;
  13451. var internalFormat = glFormat;
  13452. if ( glFormat === 6403 ) {
  13453. if ( glType === 5126 ) internalFormat = 33326;
  13454. if ( glType === 5131 ) internalFormat = 33325;
  13455. if ( glType === 5121 ) internalFormat = 33321;
  13456. }
  13457. if ( glFormat === 6407 ) {
  13458. if ( glType === 5126 ) internalFormat = 34837;
  13459. if ( glType === 5131 ) internalFormat = 34843;
  13460. if ( glType === 5121 ) internalFormat = 32849;
  13461. }
  13462. if ( glFormat === 6408 ) {
  13463. if ( glType === 5126 ) internalFormat = 34836;
  13464. if ( glType === 5131 ) internalFormat = 34842;
  13465. if ( glType === 5121 ) internalFormat = 32856;
  13466. }
  13467. if ( internalFormat === 33325 || internalFormat === 33326 ||
  13468. internalFormat === 34842 || internalFormat === 34836 ) {
  13469. extensions.get( 'EXT_color_buffer_float' );
  13470. } else if ( internalFormat === 34843 || internalFormat === 34837 ) {
  13471. console.warn( 'THREE.WebGLRenderer: Floating point textures with RGB format not supported. Please use RGBA instead.' );
  13472. }
  13473. return internalFormat;
  13474. }
  13475. // Fallback filters for non-power-of-2 textures
  13476. function filterFallback( f ) {
  13477. if ( f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter ) {
  13478. return 9728;
  13479. }
  13480. return 9729;
  13481. }
  13482. //
  13483. function onTextureDispose( event ) {
  13484. var texture = event.target;
  13485. texture.removeEventListener( 'dispose', onTextureDispose );
  13486. deallocateTexture( texture );
  13487. if ( texture.isVideoTexture ) {
  13488. delete _videoTextures[ texture.id ];
  13489. }
  13490. info.memory.textures --;
  13491. }
  13492. function onRenderTargetDispose( event ) {
  13493. var renderTarget = event.target;
  13494. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  13495. deallocateRenderTarget( renderTarget );
  13496. info.memory.textures --;
  13497. }
  13498. //
  13499. function deallocateTexture( texture ) {
  13500. var textureProperties = properties.get( texture );
  13501. if ( textureProperties.__webglInit === undefined ) return;
  13502. _gl.deleteTexture( textureProperties.__webglTexture );
  13503. properties.remove( texture );
  13504. }
  13505. function deallocateRenderTarget( renderTarget ) {
  13506. var renderTargetProperties = properties.get( renderTarget );
  13507. var textureProperties = properties.get( renderTarget.texture );
  13508. if ( ! renderTarget ) return;
  13509. if ( textureProperties.__webglTexture !== undefined ) {
  13510. _gl.deleteTexture( textureProperties.__webglTexture );
  13511. }
  13512. if ( renderTarget.depthTexture ) {
  13513. renderTarget.depthTexture.dispose();
  13514. }
  13515. if ( renderTarget.isWebGLRenderTargetCube ) {
  13516. for ( var i = 0; i < 6; i ++ ) {
  13517. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  13518. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  13519. }
  13520. } else {
  13521. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  13522. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  13523. }
  13524. properties.remove( renderTarget.texture );
  13525. properties.remove( renderTarget );
  13526. }
  13527. //
  13528. var textureUnits = 0;
  13529. function resetTextureUnits() {
  13530. textureUnits = 0;
  13531. }
  13532. function allocateTextureUnit() {
  13533. var textureUnit = textureUnits;
  13534. if ( textureUnit >= capabilities.maxTextures ) {
  13535. console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  13536. }
  13537. textureUnits += 1;
  13538. return textureUnit;
  13539. }
  13540. //
  13541. function setTexture2D( texture, slot ) {
  13542. var textureProperties = properties.get( texture );
  13543. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  13544. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13545. var image = texture.image;
  13546. if ( image === undefined ) {
  13547. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  13548. } else if ( image.complete === false ) {
  13549. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  13550. } else {
  13551. uploadTexture( textureProperties, texture, slot );
  13552. return;
  13553. }
  13554. }
  13555. state.activeTexture( 33984 + slot );
  13556. state.bindTexture( 3553, textureProperties.__webglTexture );
  13557. }
  13558. function setTexture2DArray( texture, slot ) {
  13559. var textureProperties = properties.get( texture );
  13560. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13561. uploadTexture( textureProperties, texture, slot );
  13562. return;
  13563. }
  13564. state.activeTexture( 33984 + slot );
  13565. state.bindTexture( 35866, textureProperties.__webglTexture );
  13566. }
  13567. function setTexture3D( texture, slot ) {
  13568. var textureProperties = properties.get( texture );
  13569. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13570. uploadTexture( textureProperties, texture, slot );
  13571. return;
  13572. }
  13573. state.activeTexture( 33984 + slot );
  13574. state.bindTexture( 32879, textureProperties.__webglTexture );
  13575. }
  13576. function setTextureCube( texture, slot ) {
  13577. var textureProperties = properties.get( texture );
  13578. if ( texture.image.length === 6 ) {
  13579. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13580. initTexture( textureProperties, texture );
  13581. state.activeTexture( 33984 + slot );
  13582. state.bindTexture( 34067, textureProperties.__webglTexture );
  13583. _gl.pixelStorei( 37440, texture.flipY );
  13584. var isCompressed = ( texture && texture.isCompressedTexture );
  13585. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  13586. var cubeImage = [];
  13587. for ( var i = 0; i < 6; i ++ ) {
  13588. if ( ! isCompressed && ! isDataTexture ) {
  13589. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, capabilities.maxCubemapSize );
  13590. } else {
  13591. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  13592. }
  13593. }
  13594. var image = cubeImage[ 0 ],
  13595. supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  13596. glFormat = utils.convert( texture.format ),
  13597. glType = utils.convert( texture.type ),
  13598. glInternalFormat = getInternalFormat( glFormat, glType );
  13599. setTextureParameters( 34067, texture, supportsMips );
  13600. for ( var i = 0; i < 6; i ++ ) {
  13601. if ( ! isCompressed ) {
  13602. if ( isDataTexture ) {
  13603. state.texImage2D( 34069 + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  13604. } else {
  13605. state.texImage2D( 34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
  13606. }
  13607. } else {
  13608. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  13609. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  13610. mipmap = mipmaps[ j ];
  13611. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  13612. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  13613. state.compressedTexImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13614. } else {
  13615. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  13616. }
  13617. } else {
  13618. state.texImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13619. }
  13620. }
  13621. }
  13622. }
  13623. if ( ! isCompressed ) {
  13624. textureProperties.__maxMipLevel = 0;
  13625. } else {
  13626. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13627. }
  13628. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13629. // We assume images for cube map have the same size.
  13630. generateMipmap( 34067, texture, image.width, image.height );
  13631. }
  13632. textureProperties.__version = texture.version;
  13633. if ( texture.onUpdate ) texture.onUpdate( texture );
  13634. } else {
  13635. state.activeTexture( 33984 + slot );
  13636. state.bindTexture( 34067, textureProperties.__webglTexture );
  13637. }
  13638. }
  13639. }
  13640. function setTextureCubeDynamic( texture, slot ) {
  13641. state.activeTexture( 33984 + slot );
  13642. state.bindTexture( 34067, properties.get( texture ).__webglTexture );
  13643. }
  13644. function setTextureParameters( textureType, texture, supportsMips ) {
  13645. var extension;
  13646. if ( supportsMips ) {
  13647. _gl.texParameteri( textureType, 10242, utils.convert( texture.wrapS ) );
  13648. _gl.texParameteri( textureType, 10243, utils.convert( texture.wrapT ) );
  13649. if ( textureType === 32879 || textureType === 35866 ) {
  13650. _gl.texParameteri( textureType, 32882, utils.convert( texture.wrapR ) );
  13651. }
  13652. _gl.texParameteri( textureType, 10240, utils.convert( texture.magFilter ) );
  13653. _gl.texParameteri( textureType, 10241, utils.convert( texture.minFilter ) );
  13654. } else {
  13655. _gl.texParameteri( textureType, 10242, 33071 );
  13656. _gl.texParameteri( textureType, 10243, 33071 );
  13657. if ( textureType === 32879 || textureType === 35866 ) {
  13658. _gl.texParameteri( textureType, 32882, 33071 );
  13659. }
  13660. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  13661. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  13662. }
  13663. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  13664. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  13665. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  13666. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  13667. }
  13668. }
  13669. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  13670. if ( extension ) {
  13671. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  13672. if ( texture.type === HalfFloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
  13673. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  13674. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  13675. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  13676. }
  13677. }
  13678. }
  13679. function initTexture( textureProperties, texture ) {
  13680. if ( textureProperties.__webglInit === undefined ) {
  13681. textureProperties.__webglInit = true;
  13682. texture.addEventListener( 'dispose', onTextureDispose );
  13683. textureProperties.__webglTexture = _gl.createTexture();
  13684. info.memory.textures ++;
  13685. }
  13686. }
  13687. function uploadTexture( textureProperties, texture, slot ) {
  13688. var textureType = 3553;
  13689. if ( texture.isDataTexture2DArray ) textureType = 35866;
  13690. if ( texture.isDataTexture3D ) textureType = 32879;
  13691. initTexture( textureProperties, texture );
  13692. state.activeTexture( 33984 + slot );
  13693. state.bindTexture( textureType, textureProperties.__webglTexture );
  13694. _gl.pixelStorei( 37440, texture.flipY );
  13695. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  13696. _gl.pixelStorei( 3317, texture.unpackAlignment );
  13697. var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
  13698. var image = resizeImage( texture.image, needsPowerOfTwo, false, capabilities.maxTextureSize );
  13699. var supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  13700. glFormat = utils.convert( texture.format ),
  13701. glType = utils.convert( texture.type ),
  13702. glInternalFormat = getInternalFormat( glFormat, glType );
  13703. setTextureParameters( textureType, texture, supportsMips );
  13704. var mipmap, mipmaps = texture.mipmaps;
  13705. if ( texture.isDepthTexture ) {
  13706. // populate depth texture with dummy data
  13707. glInternalFormat = 6402;
  13708. if ( texture.type === FloatType ) {
  13709. if ( ! capabilities.isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  13710. glInternalFormat = 36012;
  13711. } else if ( capabilities.isWebGL2 ) {
  13712. // WebGL 2.0 requires signed internalformat for glTexImage2D
  13713. glInternalFormat = 33189;
  13714. }
  13715. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  13716. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13717. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  13718. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13719. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  13720. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  13721. texture.type = UnsignedShortType;
  13722. glType = utils.convert( texture.type );
  13723. }
  13724. }
  13725. // Depth stencil textures need the DEPTH_STENCIL internal format
  13726. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13727. if ( texture.format === DepthStencilFormat ) {
  13728. glInternalFormat = 34041;
  13729. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13730. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  13731. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13732. if ( texture.type !== UnsignedInt248Type ) {
  13733. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  13734. texture.type = UnsignedInt248Type;
  13735. glType = utils.convert( texture.type );
  13736. }
  13737. }
  13738. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  13739. } else if ( texture.isDataTexture ) {
  13740. // use manually created mipmaps if available
  13741. // if there are no manual mipmaps
  13742. // set 0 level mipmap and then use GL to generate other mipmap levels
  13743. if ( mipmaps.length > 0 && supportsMips ) {
  13744. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13745. mipmap = mipmaps[ i ];
  13746. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13747. }
  13748. texture.generateMipmaps = false;
  13749. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13750. } else {
  13751. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  13752. textureProperties.__maxMipLevel = 0;
  13753. }
  13754. } else if ( texture.isCompressedTexture ) {
  13755. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13756. mipmap = mipmaps[ i ];
  13757. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  13758. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  13759. state.compressedTexImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13760. } else {
  13761. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  13762. }
  13763. } else {
  13764. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13765. }
  13766. }
  13767. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13768. } else if ( texture.isDataTexture2DArray ) {
  13769. state.texImage3D( 35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  13770. textureProperties.__maxMipLevel = 0;
  13771. } else if ( texture.isDataTexture3D ) {
  13772. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  13773. textureProperties.__maxMipLevel = 0;
  13774. } else {
  13775. // regular Texture (image, video, canvas)
  13776. // use manually created mipmaps if available
  13777. // if there are no manual mipmaps
  13778. // set 0 level mipmap and then use GL to generate other mipmap levels
  13779. if ( mipmaps.length > 0 && supportsMips ) {
  13780. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13781. mipmap = mipmaps[ i ];
  13782. state.texImage2D( 3553, i, glInternalFormat, glFormat, glType, mipmap );
  13783. }
  13784. texture.generateMipmaps = false;
  13785. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13786. } else {
  13787. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  13788. textureProperties.__maxMipLevel = 0;
  13789. }
  13790. }
  13791. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13792. generateMipmap( 3553, texture, image.width, image.height );
  13793. }
  13794. textureProperties.__version = texture.version;
  13795. if ( texture.onUpdate ) texture.onUpdate( texture );
  13796. }
  13797. // Render targets
  13798. // Setup storage for target texture and bind it to correct framebuffer
  13799. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  13800. var glFormat = utils.convert( renderTarget.texture.format );
  13801. var glType = utils.convert( renderTarget.texture.type );
  13802. var glInternalFormat = getInternalFormat( glFormat, glType );
  13803. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13804. _gl.bindFramebuffer( 36160, framebuffer );
  13805. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  13806. _gl.bindFramebuffer( 36160, null );
  13807. }
  13808. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13809. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  13810. _gl.bindRenderbuffer( 36161, renderbuffer );
  13811. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13812. if ( isMultisample ) {
  13813. var samples = getRenderTargetSamples( renderTarget );
  13814. _gl.renderbufferStorageMultisample( 36161, samples, 33189, renderTarget.width, renderTarget.height );
  13815. } else {
  13816. _gl.renderbufferStorage( 36161, 33189, renderTarget.width, renderTarget.height );
  13817. }
  13818. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  13819. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13820. if ( isMultisample ) {
  13821. var samples = getRenderTargetSamples( renderTarget );
  13822. _gl.renderbufferStorageMultisample( 36161, samples, 35056, renderTarget.width, renderTarget.height );
  13823. } else {
  13824. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  13825. }
  13826. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  13827. } else {
  13828. var glFormat = utils.convert( renderTarget.texture.format );
  13829. var glType = utils.convert( renderTarget.texture.type );
  13830. var glInternalFormat = getInternalFormat( glFormat, glType );
  13831. if ( isMultisample ) {
  13832. var samples = getRenderTargetSamples( renderTarget );
  13833. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  13834. } else {
  13835. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  13836. }
  13837. }
  13838. _gl.bindRenderbuffer( 36161, null );
  13839. }
  13840. // Setup resources for a Depth Texture for a FBO (needs an extension)
  13841. function setupDepthTexture( framebuffer, renderTarget ) {
  13842. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  13843. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  13844. _gl.bindFramebuffer( 36160, framebuffer );
  13845. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  13846. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  13847. }
  13848. // upload an empty depth texture with framebuffer size
  13849. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  13850. renderTarget.depthTexture.image.width !== renderTarget.width ||
  13851. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  13852. renderTarget.depthTexture.image.width = renderTarget.width;
  13853. renderTarget.depthTexture.image.height = renderTarget.height;
  13854. renderTarget.depthTexture.needsUpdate = true;
  13855. }
  13856. setTexture2D( renderTarget.depthTexture, 0 );
  13857. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  13858. if ( renderTarget.depthTexture.format === DepthFormat ) {
  13859. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  13860. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  13861. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  13862. } else {
  13863. throw new Error( 'Unknown depthTexture format' );
  13864. }
  13865. }
  13866. // Setup GL resources for a non-texture depth buffer
  13867. function setupDepthRenderbuffer( renderTarget ) {
  13868. var renderTargetProperties = properties.get( renderTarget );
  13869. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  13870. if ( renderTarget.depthTexture ) {
  13871. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  13872. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  13873. } else {
  13874. if ( isCube ) {
  13875. renderTargetProperties.__webglDepthbuffer = [];
  13876. for ( var i = 0; i < 6; i ++ ) {
  13877. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  13878. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  13879. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  13880. }
  13881. } else {
  13882. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  13883. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13884. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  13885. }
  13886. }
  13887. _gl.bindFramebuffer( 36160, null );
  13888. }
  13889. // Set up GL resources for the render target
  13890. function setupRenderTarget( renderTarget ) {
  13891. var renderTargetProperties = properties.get( renderTarget );
  13892. var textureProperties = properties.get( renderTarget.texture );
  13893. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  13894. textureProperties.__webglTexture = _gl.createTexture();
  13895. info.memory.textures ++;
  13896. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  13897. var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  13898. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  13899. // Setup framebuffer
  13900. if ( isCube ) {
  13901. renderTargetProperties.__webglFramebuffer = [];
  13902. for ( var i = 0; i < 6; i ++ ) {
  13903. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  13904. }
  13905. } else {
  13906. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13907. if ( isMultisample ) {
  13908. if ( capabilities.isWebGL2 ) {
  13909. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13910. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13911. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  13912. var glFormat = utils.convert( renderTarget.texture.format );
  13913. var glType = utils.convert( renderTarget.texture.type );
  13914. var glInternalFormat = getInternalFormat( glFormat, glType );
  13915. var samples = getRenderTargetSamples( renderTarget );
  13916. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  13917. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  13918. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  13919. _gl.bindRenderbuffer( 36161, null );
  13920. if ( renderTarget.depthBuffer ) {
  13921. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13922. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  13923. }
  13924. _gl.bindFramebuffer( 36160, null );
  13925. } else {
  13926. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13927. }
  13928. }
  13929. }
  13930. // Setup color buffer
  13931. if ( isCube ) {
  13932. state.bindTexture( 34067, textureProperties.__webglTexture );
  13933. setTextureParameters( 34067, renderTarget.texture, supportsMips );
  13934. for ( var i = 0; i < 6; i ++ ) {
  13935. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, 36064, 34069 + i );
  13936. }
  13937. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  13938. generateMipmap( 34067, renderTarget.texture, renderTarget.width, renderTarget.height );
  13939. }
  13940. state.bindTexture( 34067, null );
  13941. } else {
  13942. state.bindTexture( 3553, textureProperties.__webglTexture );
  13943. setTextureParameters( 3553, renderTarget.texture, supportsMips );
  13944. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553 );
  13945. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  13946. generateMipmap( 3553, renderTarget.texture, renderTarget.width, renderTarget.height );
  13947. }
  13948. state.bindTexture( 3553, null );
  13949. }
  13950. // Setup depth and stencil buffers
  13951. if ( renderTarget.depthBuffer ) {
  13952. setupDepthRenderbuffer( renderTarget );
  13953. }
  13954. }
  13955. function updateRenderTargetMipmap( renderTarget ) {
  13956. var texture = renderTarget.texture;
  13957. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  13958. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13959. var target = renderTarget.isWebGLRenderTargetCube ? 34067 : 3553;
  13960. var webglTexture = properties.get( texture ).__webglTexture;
  13961. state.bindTexture( target, webglTexture );
  13962. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  13963. state.bindTexture( target, null );
  13964. }
  13965. }
  13966. function updateMultisampleRenderTarget( renderTarget ) {
  13967. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  13968. if ( capabilities.isWebGL2 ) {
  13969. var renderTargetProperties = properties.get( renderTarget );
  13970. _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  13971. _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  13972. var width = renderTarget.width;
  13973. var height = renderTarget.height;
  13974. var mask = 16384;
  13975. if ( renderTarget.depthBuffer ) mask |= 256;
  13976. if ( renderTarget.stencilBuffer ) mask |= 1024;
  13977. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  13978. } else {
  13979. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13980. }
  13981. }
  13982. }
  13983. function getRenderTargetSamples( renderTarget ) {
  13984. return ( capabilities.isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  13985. Math.min( capabilities.maxSamples, renderTarget.samples ) : 0;
  13986. }
  13987. function updateVideoTexture( texture ) {
  13988. var id = texture.id;
  13989. var frame = info.render.frame;
  13990. // Check the last frame we updated the VideoTexture
  13991. if ( _videoTextures[ id ] !== frame ) {
  13992. _videoTextures[ id ] = frame;
  13993. texture.update();
  13994. }
  13995. }
  13996. // backwards compatibility
  13997. var warnedTexture2D = false;
  13998. var warnedTextureCube = false;
  13999. function safeSetTexture2D( texture, slot ) {
  14000. if ( texture && texture.isWebGLRenderTarget ) {
  14001. if ( warnedTexture2D === false ) {
  14002. console.warn( "THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead." );
  14003. warnedTexture2D = true;
  14004. }
  14005. texture = texture.texture;
  14006. }
  14007. setTexture2D( texture, slot );
  14008. }
  14009. function safeSetTextureCube( texture, slot ) {
  14010. if ( texture && texture.isWebGLRenderTargetCube ) {
  14011. if ( warnedTextureCube === false ) {
  14012. console.warn( "THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  14013. warnedTextureCube = true;
  14014. }
  14015. texture = texture.texture;
  14016. }
  14017. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  14018. // TODO: unify these code paths
  14019. if ( ( texture && texture.isCubeTexture ) ||
  14020. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  14021. // CompressedTexture can have Array in image :/
  14022. // this function alone should take care of cube textures
  14023. setTextureCube( texture, slot );
  14024. } else {
  14025. // assumed: texture property of THREE.WebGLRenderTargetCube
  14026. setTextureCubeDynamic( texture, slot );
  14027. }
  14028. }
  14029. //
  14030. this.allocateTextureUnit = allocateTextureUnit;
  14031. this.resetTextureUnits = resetTextureUnits;
  14032. this.setTexture2D = setTexture2D;
  14033. this.setTexture2DArray = setTexture2DArray;
  14034. this.setTexture3D = setTexture3D;
  14035. this.setTextureCube = setTextureCube;
  14036. this.setTextureCubeDynamic = setTextureCubeDynamic;
  14037. this.setupRenderTarget = setupRenderTarget;
  14038. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  14039. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  14040. this.safeSetTexture2D = safeSetTexture2D;
  14041. this.safeSetTextureCube = safeSetTextureCube;
  14042. }
  14043. /**
  14044. * @author thespite / http://www.twitter.com/thespite
  14045. */
  14046. function WebGLUtils( gl, extensions, capabilities ) {
  14047. function convert( p ) {
  14048. var extension;
  14049. if ( p === RepeatWrapping ) return 10497;
  14050. if ( p === ClampToEdgeWrapping ) return 33071;
  14051. if ( p === MirroredRepeatWrapping ) return 33648;
  14052. if ( p === NearestFilter ) return 9728;
  14053. if ( p === NearestMipmapNearestFilter ) return 9984;
  14054. if ( p === NearestMipmapLinearFilter ) return 9986;
  14055. if ( p === LinearFilter ) return 9729;
  14056. if ( p === LinearMipmapNearestFilter ) return 9985;
  14057. if ( p === LinearMipmapLinearFilter ) return 9987;
  14058. if ( p === UnsignedByteType ) return 5121;
  14059. if ( p === UnsignedShort4444Type ) return 32819;
  14060. if ( p === UnsignedShort5551Type ) return 32820;
  14061. if ( p === UnsignedShort565Type ) return 33635;
  14062. if ( p === ByteType ) return 5120;
  14063. if ( p === ShortType ) return 5122;
  14064. if ( p === UnsignedShortType ) return 5123;
  14065. if ( p === IntType ) return 5124;
  14066. if ( p === UnsignedIntType ) return 5125;
  14067. if ( p === FloatType ) return 5126;
  14068. if ( p === HalfFloatType ) {
  14069. if ( capabilities.isWebGL2 ) return 5131;
  14070. extension = extensions.get( 'OES_texture_half_float' );
  14071. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  14072. }
  14073. if ( p === AlphaFormat ) return 6406;
  14074. if ( p === RGBFormat ) return 6407;
  14075. if ( p === RGBAFormat ) return 6408;
  14076. if ( p === LuminanceFormat ) return 6409;
  14077. if ( p === LuminanceAlphaFormat ) return 6410;
  14078. if ( p === DepthFormat ) return 6402;
  14079. if ( p === DepthStencilFormat ) return 34041;
  14080. if ( p === RedFormat ) return 6403;
  14081. if ( p === AddEquation ) return 32774;
  14082. if ( p === SubtractEquation ) return 32778;
  14083. if ( p === ReverseSubtractEquation ) return 32779;
  14084. if ( p === ZeroFactor ) return 0;
  14085. if ( p === OneFactor ) return 1;
  14086. if ( p === SrcColorFactor ) return 768;
  14087. if ( p === OneMinusSrcColorFactor ) return 769;
  14088. if ( p === SrcAlphaFactor ) return 770;
  14089. if ( p === OneMinusSrcAlphaFactor ) return 771;
  14090. if ( p === DstAlphaFactor ) return 772;
  14091. if ( p === OneMinusDstAlphaFactor ) return 773;
  14092. if ( p === DstColorFactor ) return 774;
  14093. if ( p === OneMinusDstColorFactor ) return 775;
  14094. if ( p === SrcAlphaSaturateFactor ) return 776;
  14095. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  14096. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  14097. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  14098. if ( extension !== null ) {
  14099. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  14100. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  14101. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  14102. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  14103. }
  14104. }
  14105. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  14106. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  14107. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  14108. if ( extension !== null ) {
  14109. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  14110. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  14111. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  14112. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  14113. }
  14114. }
  14115. if ( p === RGB_ETC1_Format ) {
  14116. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  14117. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  14118. }
  14119. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  14120. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  14121. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  14122. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  14123. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) {
  14124. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  14125. if ( extension !== null ) {
  14126. return p;
  14127. }
  14128. }
  14129. if ( p === MinEquation || p === MaxEquation ) {
  14130. if ( capabilities.isWebGL2 ) {
  14131. if ( p === MinEquation ) return 32775;
  14132. if ( p === MaxEquation ) return 32776;
  14133. }
  14134. extension = extensions.get( 'EXT_blend_minmax' );
  14135. if ( extension !== null ) {
  14136. if ( p === MinEquation ) return extension.MIN_EXT;
  14137. if ( p === MaxEquation ) return extension.MAX_EXT;
  14138. }
  14139. }
  14140. if ( p === UnsignedInt248Type ) {
  14141. if ( capabilities.isWebGL2 ) return 34042;
  14142. extension = extensions.get( 'WEBGL_depth_texture' );
  14143. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  14144. }
  14145. return 0;
  14146. }
  14147. return { convert: convert };
  14148. }
  14149. /**
  14150. * @author mrdoob / http://mrdoob.com/
  14151. */
  14152. function Group() {
  14153. Object3D.call( this );
  14154. this.type = 'Group';
  14155. }
  14156. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14157. constructor: Group,
  14158. isGroup: true
  14159. } );
  14160. /**
  14161. * @author mrdoob / http://mrdoob.com/
  14162. */
  14163. function ArrayCamera( array ) {
  14164. PerspectiveCamera.call( this );
  14165. this.cameras = array || [];
  14166. }
  14167. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  14168. constructor: ArrayCamera,
  14169. isArrayCamera: true
  14170. } );
  14171. /**
  14172. * @author jsantell / https://www.jsantell.com/
  14173. * @author mrdoob / http://mrdoob.com/
  14174. */
  14175. var cameraLPos = new Vector3();
  14176. var cameraRPos = new Vector3();
  14177. /**
  14178. * Assumes 2 cameras that are parallel and share an X-axis, and that
  14179. * the cameras' projection and world matrices have already been set.
  14180. * And that near and far planes are identical for both cameras.
  14181. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  14182. */
  14183. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  14184. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  14185. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  14186. var ipd = cameraLPos.distanceTo( cameraRPos );
  14187. var projL = cameraL.projectionMatrix.elements;
  14188. var projR = cameraR.projectionMatrix.elements;
  14189. // VR systems will have identical far and near planes, and
  14190. // most likely identical top and bottom frustum extents.
  14191. // Use the left camera for these values.
  14192. var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  14193. var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  14194. var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  14195. var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  14196. var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  14197. var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  14198. var left = near * leftFov;
  14199. var right = near * rightFov;
  14200. // Calculate the new camera's position offset from the
  14201. // left camera. xOffset should be roughly half `ipd`.
  14202. var zOffset = ipd / ( - leftFov + rightFov );
  14203. var xOffset = zOffset * - leftFov;
  14204. // TODO: Better way to apply this offset?
  14205. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  14206. camera.translateX( xOffset );
  14207. camera.translateZ( zOffset );
  14208. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  14209. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  14210. // Find the union of the frustum values of the cameras and scale
  14211. // the values so that the near plane's position does not change in world space,
  14212. // although must now be relative to the new union camera.
  14213. var near2 = near + zOffset;
  14214. var far2 = far + zOffset;
  14215. var left2 = left - xOffset;
  14216. var right2 = right + ( ipd - xOffset );
  14217. var top2 = topFov * far / far2 * near2;
  14218. var bottom2 = bottomFov * far / far2 * near2;
  14219. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  14220. }
  14221. /**
  14222. * @author mrdoob / http://mrdoob.com/
  14223. */
  14224. function WebVRManager( renderer ) {
  14225. var renderWidth, renderHeight;
  14226. var scope = this;
  14227. var device = null;
  14228. var frameData = null;
  14229. var poseTarget = null;
  14230. var controllers = [];
  14231. var standingMatrix = new Matrix4();
  14232. var standingMatrixInverse = new Matrix4();
  14233. var framebufferScaleFactor = 1.0;
  14234. var referenceSpaceType = 'local-floor';
  14235. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  14236. frameData = new window.VRFrameData();
  14237. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  14238. }
  14239. var matrixWorldInverse = new Matrix4();
  14240. var tempQuaternion = new Quaternion();
  14241. var tempPosition = new Vector3();
  14242. var cameraL = new PerspectiveCamera();
  14243. cameraL.viewport = new Vector4();
  14244. cameraL.layers.enable( 1 );
  14245. var cameraR = new PerspectiveCamera();
  14246. cameraR.viewport = new Vector4();
  14247. cameraR.layers.enable( 2 );
  14248. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  14249. cameraVR.layers.enable( 1 );
  14250. cameraVR.layers.enable( 2 );
  14251. //
  14252. function isPresenting() {
  14253. return device !== null && device.isPresenting === true;
  14254. }
  14255. var currentSize = new Vector2(), currentPixelRatio;
  14256. function onVRDisplayPresentChange() {
  14257. if ( isPresenting() ) {
  14258. var eyeParameters = device.getEyeParameters( 'left' );
  14259. renderWidth = 2 * eyeParameters.renderWidth * framebufferScaleFactor;
  14260. renderHeight = eyeParameters.renderHeight * framebufferScaleFactor;
  14261. currentPixelRatio = renderer.getPixelRatio();
  14262. renderer.getSize( currentSize );
  14263. renderer.setDrawingBufferSize( renderWidth, renderHeight, 1 );
  14264. cameraL.viewport.set( 0, 0, renderWidth / 2, renderHeight );
  14265. cameraR.viewport.set( renderWidth / 2, 0, renderWidth / 2, renderHeight );
  14266. animation.start();
  14267. scope.dispatchEvent( { type: 'sessionstart' } );
  14268. } else {
  14269. if ( scope.enabled ) {
  14270. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  14271. }
  14272. animation.stop();
  14273. scope.dispatchEvent( { type: 'sessionend' } );
  14274. }
  14275. }
  14276. //
  14277. var triggers = [];
  14278. function findGamepad( id ) {
  14279. var gamepads = navigator.getGamepads && navigator.getGamepads();
  14280. for ( var i = 0, j = 0, l = gamepads.length; i < l; i ++ ) {
  14281. var gamepad = gamepads[ i ];
  14282. if ( gamepad && ( gamepad.id === 'Daydream Controller' ||
  14283. gamepad.id === 'Gear VR Controller' || gamepad.id === 'Oculus Go Controller' ||
  14284. gamepad.id === 'OpenVR Gamepad' || gamepad.id.startsWith( 'Oculus Touch' ) ||
  14285. gamepad.id.startsWith( 'HTC Vive Focus' ) ||
  14286. gamepad.id.startsWith( 'Spatial Controller' ) ) ) {
  14287. if ( j === id ) return gamepad;
  14288. j ++;
  14289. }
  14290. }
  14291. }
  14292. function updateControllers() {
  14293. for ( var i = 0; i < controllers.length; i ++ ) {
  14294. var controller = controllers[ i ];
  14295. var gamepad = findGamepad( i );
  14296. if ( gamepad !== undefined && gamepad.pose !== undefined ) {
  14297. if ( gamepad.pose === null ) return;
  14298. // Pose
  14299. var pose = gamepad.pose;
  14300. if ( pose.hasPosition === false ) controller.position.set( 0.2, - 0.6, - 0.05 );
  14301. if ( pose.position !== null ) controller.position.fromArray( pose.position );
  14302. if ( pose.orientation !== null ) controller.quaternion.fromArray( pose.orientation );
  14303. controller.matrix.compose( controller.position, controller.quaternion, controller.scale );
  14304. controller.matrix.premultiply( standingMatrix );
  14305. controller.matrix.decompose( controller.position, controller.quaternion, controller.scale );
  14306. controller.matrixWorldNeedsUpdate = true;
  14307. controller.visible = true;
  14308. // Trigger
  14309. var buttonId = gamepad.id === 'Daydream Controller' ? 0 : 1;
  14310. if ( triggers[ i ] === undefined ) triggers[ i ] = false;
  14311. if ( triggers[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
  14312. triggers[ i ] = gamepad.buttons[ buttonId ].pressed;
  14313. if ( triggers[ i ] === true ) {
  14314. controller.dispatchEvent( { type: 'selectstart' } );
  14315. } else {
  14316. controller.dispatchEvent( { type: 'selectend' } );
  14317. controller.dispatchEvent( { type: 'select' } );
  14318. }
  14319. }
  14320. } else {
  14321. controller.visible = false;
  14322. }
  14323. }
  14324. }
  14325. function updateViewportFromBounds( viewport, bounds ) {
  14326. if ( bounds !== null && bounds.length === 4 ) {
  14327. viewport.set( bounds[ 0 ] * renderWidth, bounds[ 1 ] * renderHeight, bounds[ 2 ] * renderWidth, bounds[ 3 ] * renderHeight );
  14328. }
  14329. }
  14330. //
  14331. this.enabled = false;
  14332. this.getController = function ( id ) {
  14333. var controller = controllers[ id ];
  14334. if ( controller === undefined ) {
  14335. controller = new Group();
  14336. controller.matrixAutoUpdate = false;
  14337. controller.visible = false;
  14338. controllers[ id ] = controller;
  14339. }
  14340. return controller;
  14341. };
  14342. this.getDevice = function () {
  14343. return device;
  14344. };
  14345. this.setDevice = function ( value ) {
  14346. if ( value !== undefined ) device = value;
  14347. animation.setContext( value );
  14348. };
  14349. this.setFramebufferScaleFactor = function ( value ) {
  14350. framebufferScaleFactor = value;
  14351. };
  14352. this.setReferenceSpaceType = function ( value ) {
  14353. referenceSpaceType = value;
  14354. };
  14355. this.setPoseTarget = function ( object ) {
  14356. if ( object !== undefined ) poseTarget = object;
  14357. };
  14358. this.getCamera = function ( camera ) {
  14359. var userHeight = referenceSpaceType === 'local-floor' ? 1.6 : 0;
  14360. if ( isPresenting() === false ) {
  14361. camera.position.set( 0, userHeight, 0 );
  14362. camera.rotation.set( 0, 0, 0 );
  14363. return camera;
  14364. }
  14365. device.depthNear = camera.near;
  14366. device.depthFar = camera.far;
  14367. device.getFrameData( frameData );
  14368. //
  14369. if ( referenceSpaceType === 'local-floor' ) {
  14370. var stageParameters = device.stageParameters;
  14371. if ( stageParameters ) {
  14372. standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
  14373. } else {
  14374. standingMatrix.makeTranslation( 0, userHeight, 0 );
  14375. }
  14376. }
  14377. var pose = frameData.pose;
  14378. var poseObject = poseTarget !== null ? poseTarget : camera;
  14379. // We want to manipulate poseObject by its position and quaternion components since users may rely on them.
  14380. poseObject.matrix.copy( standingMatrix );
  14381. poseObject.matrix.decompose( poseObject.position, poseObject.quaternion, poseObject.scale );
  14382. if ( pose.orientation !== null ) {
  14383. tempQuaternion.fromArray( pose.orientation );
  14384. poseObject.quaternion.multiply( tempQuaternion );
  14385. }
  14386. if ( pose.position !== null ) {
  14387. tempQuaternion.setFromRotationMatrix( standingMatrix );
  14388. tempPosition.fromArray( pose.position );
  14389. tempPosition.applyQuaternion( tempQuaternion );
  14390. poseObject.position.add( tempPosition );
  14391. }
  14392. poseObject.updateMatrixWorld();
  14393. //
  14394. cameraL.near = camera.near;
  14395. cameraR.near = camera.near;
  14396. cameraL.far = camera.far;
  14397. cameraR.far = camera.far;
  14398. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  14399. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  14400. // TODO (mrdoob) Double check this code
  14401. standingMatrixInverse.getInverse( standingMatrix );
  14402. if ( referenceSpaceType === 'local-floor' ) {
  14403. cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
  14404. cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
  14405. }
  14406. var parent = poseObject.parent;
  14407. if ( parent !== null ) {
  14408. matrixWorldInverse.getInverse( parent.matrixWorld );
  14409. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  14410. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  14411. }
  14412. // envMap and Mirror needs camera.matrixWorld
  14413. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  14414. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  14415. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  14416. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  14417. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  14418. //
  14419. var layers = device.getLayers();
  14420. if ( layers.length ) {
  14421. var layer = layers[ 0 ];
  14422. updateViewportFromBounds( cameraL.viewport, layer.leftBounds );
  14423. updateViewportFromBounds( cameraR.viewport, layer.rightBounds );
  14424. }
  14425. updateControllers();
  14426. return cameraVR;
  14427. };
  14428. this.getStandingMatrix = function () {
  14429. return standingMatrix;
  14430. };
  14431. this.isPresenting = isPresenting;
  14432. // Animation Loop
  14433. var animation = new WebGLAnimation();
  14434. this.setAnimationLoop = function ( callback ) {
  14435. animation.setAnimationLoop( callback );
  14436. if ( isPresenting() ) animation.start();
  14437. };
  14438. this.submitFrame = function () {
  14439. if ( isPresenting() ) device.submitFrame();
  14440. };
  14441. this.dispose = function () {
  14442. if ( typeof window !== 'undefined' ) {
  14443. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  14444. }
  14445. };
  14446. // DEPRECATED
  14447. this.setFrameOfReferenceType = function () {
  14448. console.warn( 'THREE.WebVRManager: setFrameOfReferenceType() has been deprecated.' );
  14449. };
  14450. }
  14451. Object.assign( WebVRManager.prototype, EventDispatcher.prototype );
  14452. /**
  14453. * @author mrdoob / http://mrdoob.com/
  14454. */
  14455. function WebXRManager( renderer, gl ) {
  14456. var scope = this;
  14457. var session = null;
  14458. var referenceSpace = null;
  14459. var referenceSpaceType = 'local-floor';
  14460. var pose = null;
  14461. var controllers = [];
  14462. var inputSources = [];
  14463. function isPresenting() {
  14464. return session !== null && referenceSpace !== null;
  14465. }
  14466. //
  14467. var cameraL = new PerspectiveCamera();
  14468. cameraL.layers.enable( 1 );
  14469. cameraL.viewport = new Vector4();
  14470. var cameraR = new PerspectiveCamera();
  14471. cameraR.layers.enable( 2 );
  14472. cameraR.viewport = new Vector4();
  14473. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  14474. cameraVR.layers.enable( 1 );
  14475. cameraVR.layers.enable( 2 );
  14476. //
  14477. this.enabled = false;
  14478. this.getController = function ( id ) {
  14479. var controller = controllers[ id ];
  14480. if ( controller === undefined ) {
  14481. controller = new Group();
  14482. controller.matrixAutoUpdate = false;
  14483. controller.visible = false;
  14484. controllers[ id ] = controller;
  14485. }
  14486. return controller;
  14487. };
  14488. //
  14489. function onSessionEvent( event ) {
  14490. for ( var i = 0; i < controllers.length; i ++ ) {
  14491. if ( inputSources[ i ] === event.inputSource ) {
  14492. controllers[ i ].dispatchEvent( { type: event.type } );
  14493. }
  14494. }
  14495. }
  14496. function onSessionEnd() {
  14497. renderer.setFramebuffer( null );
  14498. renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
  14499. animation.stop();
  14500. scope.dispatchEvent( { type: 'sessionend' } );
  14501. }
  14502. function onRequestReferenceSpace( value ) {
  14503. referenceSpace = value;
  14504. animation.setContext( session );
  14505. animation.start();
  14506. scope.dispatchEvent( { type: 'sessionstart' } );
  14507. }
  14508. this.setFramebufferScaleFactor = function ( value ) {
  14509. };
  14510. this.setReferenceSpaceType = function ( value ) {
  14511. referenceSpaceType = value;
  14512. };
  14513. this.getSession = function () {
  14514. return session;
  14515. };
  14516. this.setSession = function ( value ) {
  14517. session = value;
  14518. if ( session !== null ) {
  14519. session.addEventListener( 'select', onSessionEvent );
  14520. session.addEventListener( 'selectstart', onSessionEvent );
  14521. session.addEventListener( 'selectend', onSessionEvent );
  14522. session.addEventListener( 'end', onSessionEnd );
  14523. session.updateRenderState( { baseLayer: new XRWebGLLayer( session, gl ) } );
  14524. session.requestReferenceSpace( referenceSpaceType ).then( onRequestReferenceSpace );
  14525. //
  14526. inputSources = session.inputSources;
  14527. session.addEventListener( 'inputsourceschange', function () {
  14528. inputSources = session.inputSources;
  14529. console.log( inputSources );
  14530. for ( var i = 0; i < controllers.length; i ++ ) {
  14531. var controller = controllers[ i ];
  14532. controller.userData.inputSource = inputSources[ i ];
  14533. }
  14534. } );
  14535. }
  14536. };
  14537. function updateCamera( camera, parent ) {
  14538. if ( parent === null ) {
  14539. camera.matrixWorld.copy( camera.matrix );
  14540. } else {
  14541. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  14542. }
  14543. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  14544. }
  14545. this.getCamera = function ( camera ) {
  14546. if ( isPresenting() ) {
  14547. var parent = camera.parent;
  14548. var cameras = cameraVR.cameras;
  14549. updateCamera( cameraVR, parent );
  14550. for ( var i = 0; i < cameras.length; i ++ ) {
  14551. updateCamera( cameras[ i ], parent );
  14552. }
  14553. // update camera and its children
  14554. camera.matrixWorld.copy( cameraVR.matrixWorld );
  14555. var children = camera.children;
  14556. for ( var i = 0, l = children.length; i < l; i ++ ) {
  14557. children[ i ].updateMatrixWorld( true );
  14558. }
  14559. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  14560. return cameraVR;
  14561. }
  14562. return camera;
  14563. };
  14564. this.isPresenting = isPresenting;
  14565. // Animation Loop
  14566. var onAnimationFrameCallback = null;
  14567. function onAnimationFrame( time, frame ) {
  14568. pose = frame.getViewerPose( referenceSpace );
  14569. if ( pose !== null ) {
  14570. var views = pose.views;
  14571. var baseLayer = session.renderState.baseLayer;
  14572. renderer.setFramebuffer( baseLayer.framebuffer );
  14573. for ( var i = 0; i < views.length; i ++ ) {
  14574. var view = views[ i ];
  14575. var viewport = baseLayer.getViewport( view );
  14576. var viewMatrix = view.transform.inverse.matrix;
  14577. var camera = cameraVR.cameras[ i ];
  14578. camera.matrix.fromArray( viewMatrix ).getInverse( camera.matrix );
  14579. camera.projectionMatrix.fromArray( view.projectionMatrix );
  14580. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  14581. if ( i === 0 ) {
  14582. cameraVR.matrix.copy( camera.matrix );
  14583. }
  14584. }
  14585. }
  14586. //
  14587. for ( var i = 0; i < controllers.length; i ++ ) {
  14588. var controller = controllers[ i ];
  14589. var inputSource = inputSources[ i ];
  14590. if ( inputSource ) {
  14591. var inputPose = frame.getPose( inputSource.targetRaySpace, referenceSpace );
  14592. if ( inputPose !== null ) {
  14593. controller.matrix.fromArray( inputPose.transform.matrix );
  14594. controller.matrix.decompose( controller.position, controller.rotation, controller.scale );
  14595. controller.visible = true;
  14596. continue;
  14597. }
  14598. }
  14599. controller.visible = false;
  14600. }
  14601. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  14602. }
  14603. var animation = new WebGLAnimation();
  14604. animation.setAnimationLoop( onAnimationFrame );
  14605. this.setAnimationLoop = function ( callback ) {
  14606. onAnimationFrameCallback = callback;
  14607. };
  14608. this.dispose = function () {};
  14609. // DEPRECATED
  14610. this.getStandingMatrix = function () {
  14611. console.warn( 'THREE.WebXRManager: getStandingMatrix() is no longer needed.' );
  14612. return new Matrix4();
  14613. };
  14614. this.getDevice = function () {
  14615. console.warn( 'THREE.WebXRManager: getDevice() has been deprecated.' );
  14616. };
  14617. this.setDevice = function () {
  14618. console.warn( 'THREE.WebXRManager: setDevice() has been deprecated.' );
  14619. };
  14620. this.setFrameOfReferenceType = function () {
  14621. console.warn( 'THREE.WebXRManager: setFrameOfReferenceType() has been deprecated.' );
  14622. };
  14623. this.submitFrame = function () {};
  14624. }
  14625. Object.assign( WebXRManager.prototype, EventDispatcher.prototype );
  14626. /**
  14627. * @author supereggbert / http://www.paulbrunt.co.uk/
  14628. * @author mrdoob / http://mrdoob.com/
  14629. * @author alteredq / http://alteredqualia.com/
  14630. * @author szimek / https://github.com/szimek/
  14631. * @author tschw
  14632. */
  14633. function WebGLRenderer( parameters ) {
  14634. console.log( 'THREE.WebGLRenderer', REVISION );
  14635. parameters = parameters || {};
  14636. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  14637. _context = parameters.context !== undefined ? parameters.context : null,
  14638. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14639. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14640. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14641. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14642. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14643. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14644. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14645. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14646. var currentRenderList = null;
  14647. var currentRenderState = null;
  14648. // public properties
  14649. this.domElement = _canvas;
  14650. // Debug configuration container
  14651. this.debug = {
  14652. /**
  14653. * Enables error checking and reporting when shader programs are being compiled
  14654. * @type {boolean}
  14655. */
  14656. checkShaderErrors: true
  14657. };
  14658. // clearing
  14659. this.autoClear = true;
  14660. this.autoClearColor = true;
  14661. this.autoClearDepth = true;
  14662. this.autoClearStencil = true;
  14663. // scene graph
  14664. this.sortObjects = true;
  14665. // user-defined clipping
  14666. this.clippingPlanes = [];
  14667. this.localClippingEnabled = false;
  14668. // physically based shading
  14669. this.gammaFactor = 2.0; // for backwards compatibility
  14670. this.gammaInput = false;
  14671. this.gammaOutput = false;
  14672. // physical lights
  14673. this.physicallyCorrectLights = false;
  14674. // tone mapping
  14675. this.toneMapping = LinearToneMapping;
  14676. this.toneMappingExposure = 1.0;
  14677. this.toneMappingWhitePoint = 1.0;
  14678. // morphs
  14679. this.maxMorphTargets = 8;
  14680. this.maxMorphNormals = 4;
  14681. // internal properties
  14682. var _this = this,
  14683. _isContextLost = false,
  14684. // internal state cache
  14685. _framebuffer = null,
  14686. _currentActiveCubeFace = 0,
  14687. _currentActiveMipmapLevel = 0,
  14688. _currentRenderTarget = null,
  14689. _currentFramebuffer = null,
  14690. _currentMaterialId = - 1,
  14691. // geometry and program caching
  14692. _currentGeometryProgram = {
  14693. geometry: null,
  14694. program: null,
  14695. wireframe: false
  14696. },
  14697. _currentCamera = null,
  14698. _currentArrayCamera = null,
  14699. _currentViewport = new Vector4(),
  14700. _currentScissor = new Vector4(),
  14701. _currentScissorTest = null,
  14702. //
  14703. _width = _canvas.width,
  14704. _height = _canvas.height,
  14705. _pixelRatio = 1,
  14706. _viewport = new Vector4( 0, 0, _width, _height ),
  14707. _scissor = new Vector4( 0, 0, _width, _height ),
  14708. _scissorTest = false,
  14709. // frustum
  14710. _frustum = new Frustum(),
  14711. // clipping
  14712. _clipping = new WebGLClipping(),
  14713. _clippingEnabled = false,
  14714. _localClippingEnabled = false,
  14715. // camera matrices cache
  14716. _projScreenMatrix = new Matrix4(),
  14717. _vector3 = new Vector3();
  14718. function getTargetPixelRatio() {
  14719. return _currentRenderTarget === null ? _pixelRatio : 1;
  14720. }
  14721. // initialize
  14722. var _gl;
  14723. try {
  14724. var contextAttributes = {
  14725. alpha: _alpha,
  14726. depth: _depth,
  14727. stencil: _stencil,
  14728. antialias: _antialias,
  14729. premultipliedAlpha: _premultipliedAlpha,
  14730. preserveDrawingBuffer: _preserveDrawingBuffer,
  14731. powerPreference: _powerPreference,
  14732. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat,
  14733. xrCompatible: true
  14734. };
  14735. // event listeners must be registered before WebGL context is created, see #12753
  14736. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  14737. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  14738. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  14739. if ( _gl === null ) {
  14740. if ( _canvas.getContext( 'webgl' ) !== null ) {
  14741. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  14742. } else {
  14743. throw new Error( 'Error creating WebGL context.' );
  14744. }
  14745. }
  14746. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14747. if ( _gl.getShaderPrecisionFormat === undefined ) {
  14748. _gl.getShaderPrecisionFormat = function () {
  14749. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  14750. };
  14751. }
  14752. } catch ( error ) {
  14753. console.error( 'THREE.WebGLRenderer: ' + error.message );
  14754. throw error;
  14755. }
  14756. var extensions, capabilities, state, info;
  14757. var properties, textures, attributes, geometries, objects;
  14758. var programCache, renderLists, renderStates;
  14759. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14760. var utils;
  14761. function initGLContext() {
  14762. extensions = new WebGLExtensions( _gl );
  14763. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  14764. if ( ! capabilities.isWebGL2 ) {
  14765. extensions.get( 'WEBGL_depth_texture' );
  14766. extensions.get( 'OES_texture_float' );
  14767. extensions.get( 'OES_texture_half_float' );
  14768. extensions.get( 'OES_texture_half_float_linear' );
  14769. extensions.get( 'OES_standard_derivatives' );
  14770. extensions.get( 'OES_element_index_uint' );
  14771. extensions.get( 'ANGLE_instanced_arrays' );
  14772. }
  14773. extensions.get( 'OES_texture_float_linear' );
  14774. utils = new WebGLUtils( _gl, extensions, capabilities );
  14775. state = new WebGLState( _gl, extensions, utils, capabilities );
  14776. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  14777. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  14778. info = new WebGLInfo( _gl );
  14779. properties = new WebGLProperties();
  14780. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  14781. attributes = new WebGLAttributes( _gl );
  14782. geometries = new WebGLGeometries( _gl, attributes, info );
  14783. objects = new WebGLObjects( geometries, info );
  14784. morphtargets = new WebGLMorphtargets( _gl );
  14785. programCache = new WebGLPrograms( _this, extensions, capabilities );
  14786. renderLists = new WebGLRenderLists();
  14787. renderStates = new WebGLRenderStates();
  14788. background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
  14789. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  14790. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  14791. info.programs = programCache.programs;
  14792. _this.capabilities = capabilities;
  14793. _this.extensions = extensions;
  14794. _this.properties = properties;
  14795. _this.renderLists = renderLists;
  14796. _this.state = state;
  14797. _this.info = info;
  14798. }
  14799. initGLContext();
  14800. // vr
  14801. var vr = ( typeof navigator !== 'undefined' && 'xr' in navigator && 'supportsSession' in navigator.xr ) ? new WebXRManager( _this, _gl ) : new WebVRManager( _this );
  14802. this.vr = vr;
  14803. // shadow map
  14804. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  14805. this.shadowMap = shadowMap;
  14806. // API
  14807. this.getContext = function () {
  14808. return _gl;
  14809. };
  14810. this.getContextAttributes = function () {
  14811. return _gl.getContextAttributes();
  14812. };
  14813. this.forceContextLoss = function () {
  14814. var extension = extensions.get( 'WEBGL_lose_context' );
  14815. if ( extension ) extension.loseContext();
  14816. };
  14817. this.forceContextRestore = function () {
  14818. var extension = extensions.get( 'WEBGL_lose_context' );
  14819. if ( extension ) extension.restoreContext();
  14820. };
  14821. this.getPixelRatio = function () {
  14822. return _pixelRatio;
  14823. };
  14824. this.setPixelRatio = function ( value ) {
  14825. if ( value === undefined ) return;
  14826. _pixelRatio = value;
  14827. this.setSize( _width, _height, false );
  14828. };
  14829. this.getSize = function ( target ) {
  14830. if ( target === undefined ) {
  14831. console.warn( 'WebGLRenderer: .getsize() now requires a Vector2 as an argument' );
  14832. target = new Vector2();
  14833. }
  14834. return target.set( _width, _height );
  14835. };
  14836. this.setSize = function ( width, height, updateStyle ) {
  14837. if ( vr.isPresenting() ) {
  14838. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  14839. return;
  14840. }
  14841. _width = width;
  14842. _height = height;
  14843. _canvas.width = Math.floor( width * _pixelRatio );
  14844. _canvas.height = Math.floor( height * _pixelRatio );
  14845. if ( updateStyle !== false ) {
  14846. _canvas.style.width = width + 'px';
  14847. _canvas.style.height = height + 'px';
  14848. }
  14849. this.setViewport( 0, 0, width, height );
  14850. };
  14851. this.getDrawingBufferSize = function ( target ) {
  14852. if ( target === undefined ) {
  14853. console.warn( 'WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument' );
  14854. target = new Vector2();
  14855. }
  14856. return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor();
  14857. };
  14858. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  14859. _width = width;
  14860. _height = height;
  14861. _pixelRatio = pixelRatio;
  14862. _canvas.width = Math.floor( width * pixelRatio );
  14863. _canvas.height = Math.floor( height * pixelRatio );
  14864. this.setViewport( 0, 0, width, height );
  14865. };
  14866. this.getCurrentViewport = function ( target ) {
  14867. if ( target === undefined ) {
  14868. console.warn( 'WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument' );
  14869. target = new Vector4();
  14870. }
  14871. return target.copy( _currentViewport );
  14872. };
  14873. this.getViewport = function ( target ) {
  14874. return target.copy( _viewport );
  14875. };
  14876. this.setViewport = function ( x, y, width, height ) {
  14877. if ( x.isVector4 ) {
  14878. _viewport.set( x.x, x.y, x.z, x.w );
  14879. } else {
  14880. _viewport.set( x, y, width, height );
  14881. }
  14882. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  14883. };
  14884. this.getScissor = function ( target ) {
  14885. return target.copy( _scissor );
  14886. };
  14887. this.setScissor = function ( x, y, width, height ) {
  14888. if ( x.isVector4 ) {
  14889. _scissor.set( x.x, x.y, x.z, x.w );
  14890. } else {
  14891. _scissor.set( x, y, width, height );
  14892. }
  14893. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  14894. };
  14895. this.getScissorTest = function () {
  14896. return _scissorTest;
  14897. };
  14898. this.setScissorTest = function ( boolean ) {
  14899. state.setScissorTest( _scissorTest = boolean );
  14900. };
  14901. // Clearing
  14902. this.getClearColor = function () {
  14903. return background.getClearColor();
  14904. };
  14905. this.setClearColor = function () {
  14906. background.setClearColor.apply( background, arguments );
  14907. };
  14908. this.getClearAlpha = function () {
  14909. return background.getClearAlpha();
  14910. };
  14911. this.setClearAlpha = function () {
  14912. background.setClearAlpha.apply( background, arguments );
  14913. };
  14914. this.clear = function ( color, depth, stencil ) {
  14915. var bits = 0;
  14916. if ( color === undefined || color ) bits |= 16384;
  14917. if ( depth === undefined || depth ) bits |= 256;
  14918. if ( stencil === undefined || stencil ) bits |= 1024;
  14919. _gl.clear( bits );
  14920. };
  14921. this.clearColor = function () {
  14922. this.clear( true, false, false );
  14923. };
  14924. this.clearDepth = function () {
  14925. this.clear( false, true, false );
  14926. };
  14927. this.clearStencil = function () {
  14928. this.clear( false, false, true );
  14929. };
  14930. //
  14931. this.dispose = function () {
  14932. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14933. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  14934. renderLists.dispose();
  14935. renderStates.dispose();
  14936. properties.dispose();
  14937. objects.dispose();
  14938. vr.dispose();
  14939. animation.stop();
  14940. };
  14941. // Events
  14942. function onContextLost( event ) {
  14943. event.preventDefault();
  14944. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  14945. _isContextLost = true;
  14946. }
  14947. function onContextRestore( /* event */ ) {
  14948. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  14949. _isContextLost = false;
  14950. initGLContext();
  14951. }
  14952. function onMaterialDispose( event ) {
  14953. var material = event.target;
  14954. material.removeEventListener( 'dispose', onMaterialDispose );
  14955. deallocateMaterial( material );
  14956. }
  14957. // Buffer deallocation
  14958. function deallocateMaterial( material ) {
  14959. releaseMaterialProgramReference( material );
  14960. properties.remove( material );
  14961. }
  14962. function releaseMaterialProgramReference( material ) {
  14963. var programInfo = properties.get( material ).program;
  14964. material.program = undefined;
  14965. if ( programInfo !== undefined ) {
  14966. programCache.releaseProgram( programInfo );
  14967. }
  14968. }
  14969. // Buffer rendering
  14970. function renderObjectImmediate( object, program ) {
  14971. object.render( function ( object ) {
  14972. _this.renderBufferImmediate( object, program );
  14973. } );
  14974. }
  14975. this.renderBufferImmediate = function ( object, program ) {
  14976. state.initAttributes();
  14977. var buffers = properties.get( object );
  14978. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  14979. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  14980. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  14981. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  14982. var programAttributes = program.getAttributes();
  14983. if ( object.hasPositions ) {
  14984. _gl.bindBuffer( 34962, buffers.position );
  14985. _gl.bufferData( 34962, object.positionArray, 35048 );
  14986. state.enableAttribute( programAttributes.position );
  14987. _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 );
  14988. }
  14989. if ( object.hasNormals ) {
  14990. _gl.bindBuffer( 34962, buffers.normal );
  14991. _gl.bufferData( 34962, object.normalArray, 35048 );
  14992. state.enableAttribute( programAttributes.normal );
  14993. _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 );
  14994. }
  14995. if ( object.hasUvs ) {
  14996. _gl.bindBuffer( 34962, buffers.uv );
  14997. _gl.bufferData( 34962, object.uvArray, 35048 );
  14998. state.enableAttribute( programAttributes.uv );
  14999. _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 );
  15000. }
  15001. if ( object.hasColors ) {
  15002. _gl.bindBuffer( 34962, buffers.color );
  15003. _gl.bufferData( 34962, object.colorArray, 35048 );
  15004. state.enableAttribute( programAttributes.color );
  15005. _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 );
  15006. }
  15007. state.disableUnusedAttributes();
  15008. _gl.drawArrays( 4, 0, object.count );
  15009. object.count = 0;
  15010. };
  15011. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  15012. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  15013. state.setMaterial( material, frontFaceCW );
  15014. var program = setProgram( camera, fog, material, object );
  15015. var updateBuffers = false;
  15016. if ( _currentGeometryProgram.geometry !== geometry.id ||
  15017. _currentGeometryProgram.program !== program.id ||
  15018. _currentGeometryProgram.wireframe !== ( material.wireframe === true ) ) {
  15019. _currentGeometryProgram.geometry = geometry.id;
  15020. _currentGeometryProgram.program = program.id;
  15021. _currentGeometryProgram.wireframe = material.wireframe === true;
  15022. updateBuffers = true;
  15023. }
  15024. if ( object.morphTargetInfluences ) {
  15025. morphtargets.update( object, geometry, material, program );
  15026. updateBuffers = true;
  15027. }
  15028. //
  15029. var index = geometry.index;
  15030. var position = geometry.attributes.position;
  15031. var rangeFactor = 1;
  15032. if ( material.wireframe === true ) {
  15033. index = geometries.getWireframeAttribute( geometry );
  15034. rangeFactor = 2;
  15035. }
  15036. var attribute;
  15037. var renderer = bufferRenderer;
  15038. if ( index !== null ) {
  15039. attribute = attributes.get( index );
  15040. renderer = indexedBufferRenderer;
  15041. renderer.setIndex( attribute );
  15042. }
  15043. if ( updateBuffers ) {
  15044. setupVertexAttributes( material, program, geometry );
  15045. if ( index !== null ) {
  15046. _gl.bindBuffer( 34963, attribute.buffer );
  15047. }
  15048. }
  15049. //
  15050. var dataCount = Infinity;
  15051. if ( index !== null ) {
  15052. dataCount = index.count;
  15053. } else if ( position !== undefined ) {
  15054. dataCount = position.count;
  15055. }
  15056. var rangeStart = geometry.drawRange.start * rangeFactor;
  15057. var rangeCount = geometry.drawRange.count * rangeFactor;
  15058. var groupStart = group !== null ? group.start * rangeFactor : 0;
  15059. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  15060. var drawStart = Math.max( rangeStart, groupStart );
  15061. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  15062. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  15063. if ( drawCount === 0 ) return;
  15064. //
  15065. if ( object.isMesh ) {
  15066. if ( material.wireframe === true ) {
  15067. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  15068. renderer.setMode( 1 );
  15069. } else {
  15070. switch ( object.drawMode ) {
  15071. case TrianglesDrawMode:
  15072. renderer.setMode( 4 );
  15073. break;
  15074. case TriangleStripDrawMode:
  15075. renderer.setMode( 5 );
  15076. break;
  15077. case TriangleFanDrawMode:
  15078. renderer.setMode( 6 );
  15079. break;
  15080. }
  15081. }
  15082. } else if ( object.isLine ) {
  15083. var lineWidth = material.linewidth;
  15084. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  15085. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  15086. if ( object.isLineSegments ) {
  15087. renderer.setMode( 1 );
  15088. } else if ( object.isLineLoop ) {
  15089. renderer.setMode( 2 );
  15090. } else {
  15091. renderer.setMode( 3 );
  15092. }
  15093. } else if ( object.isPoints ) {
  15094. renderer.setMode( 0 );
  15095. } else if ( object.isSprite ) {
  15096. renderer.setMode( 4 );
  15097. }
  15098. if ( geometry && geometry.isInstancedBufferGeometry ) {
  15099. if ( geometry.maxInstancedCount > 0 ) {
  15100. renderer.renderInstances( geometry, drawStart, drawCount );
  15101. }
  15102. } else {
  15103. renderer.render( drawStart, drawCount );
  15104. }
  15105. };
  15106. function setupVertexAttributes( material, program, geometry ) {
  15107. if ( geometry && geometry.isInstancedBufferGeometry && ! capabilities.isWebGL2 ) {
  15108. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  15109. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  15110. return;
  15111. }
  15112. }
  15113. state.initAttributes();
  15114. var geometryAttributes = geometry.attributes;
  15115. var programAttributes = program.getAttributes();
  15116. var materialDefaultAttributeValues = material.defaultAttributeValues;
  15117. for ( var name in programAttributes ) {
  15118. var programAttribute = programAttributes[ name ];
  15119. if ( programAttribute >= 0 ) {
  15120. var geometryAttribute = geometryAttributes[ name ];
  15121. if ( geometryAttribute !== undefined ) {
  15122. var normalized = geometryAttribute.normalized;
  15123. var size = geometryAttribute.itemSize;
  15124. var attribute = attributes.get( geometryAttribute );
  15125. // TODO Attribute may not be available on context restore
  15126. if ( attribute === undefined ) continue;
  15127. var buffer = attribute.buffer;
  15128. var type = attribute.type;
  15129. var bytesPerElement = attribute.bytesPerElement;
  15130. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  15131. var data = geometryAttribute.data;
  15132. var stride = data.stride;
  15133. var offset = geometryAttribute.offset;
  15134. if ( data && data.isInstancedInterleavedBuffer ) {
  15135. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  15136. if ( geometry.maxInstancedCount === undefined ) {
  15137. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  15138. }
  15139. } else {
  15140. state.enableAttribute( programAttribute );
  15141. }
  15142. _gl.bindBuffer( 34962, buffer );
  15143. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  15144. } else {
  15145. if ( geometryAttribute.isInstancedBufferAttribute ) {
  15146. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  15147. if ( geometry.maxInstancedCount === undefined ) {
  15148. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  15149. }
  15150. } else {
  15151. state.enableAttribute( programAttribute );
  15152. }
  15153. _gl.bindBuffer( 34962, buffer );
  15154. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  15155. }
  15156. } else if ( materialDefaultAttributeValues !== undefined ) {
  15157. var value = materialDefaultAttributeValues[ name ];
  15158. if ( value !== undefined ) {
  15159. switch ( value.length ) {
  15160. case 2:
  15161. _gl.vertexAttrib2fv( programAttribute, value );
  15162. break;
  15163. case 3:
  15164. _gl.vertexAttrib3fv( programAttribute, value );
  15165. break;
  15166. case 4:
  15167. _gl.vertexAttrib4fv( programAttribute, value );
  15168. break;
  15169. default:
  15170. _gl.vertexAttrib1fv( programAttribute, value );
  15171. }
  15172. }
  15173. }
  15174. }
  15175. }
  15176. state.disableUnusedAttributes();
  15177. }
  15178. // Compile
  15179. this.compile = function ( scene, camera ) {
  15180. currentRenderState = renderStates.get( scene, camera );
  15181. currentRenderState.init();
  15182. scene.traverse( function ( object ) {
  15183. if ( object.isLight ) {
  15184. currentRenderState.pushLight( object );
  15185. if ( object.castShadow ) {
  15186. currentRenderState.pushShadow( object );
  15187. }
  15188. }
  15189. } );
  15190. currentRenderState.setupLights( camera );
  15191. scene.traverse( function ( object ) {
  15192. if ( object.material ) {
  15193. if ( Array.isArray( object.material ) ) {
  15194. for ( var i = 0; i < object.material.length; i ++ ) {
  15195. initMaterial( object.material[ i ], scene.fog, object );
  15196. }
  15197. } else {
  15198. initMaterial( object.material, scene.fog, object );
  15199. }
  15200. }
  15201. } );
  15202. };
  15203. // Animation Loop
  15204. var onAnimationFrameCallback = null;
  15205. function onAnimationFrame( time ) {
  15206. if ( vr.isPresenting() ) return;
  15207. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  15208. }
  15209. var animation = new WebGLAnimation();
  15210. animation.setAnimationLoop( onAnimationFrame );
  15211. if ( typeof window !== 'undefined' ) animation.setContext( window );
  15212. this.setAnimationLoop = function ( callback ) {
  15213. onAnimationFrameCallback = callback;
  15214. vr.setAnimationLoop( callback );
  15215. animation.start();
  15216. };
  15217. // Rendering
  15218. this.render = function ( scene, camera ) {
  15219. var renderTarget, forceClear;
  15220. if ( arguments[ 2 ] !== undefined ) {
  15221. console.warn( 'THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.' );
  15222. renderTarget = arguments[ 2 ];
  15223. }
  15224. if ( arguments[ 3 ] !== undefined ) {
  15225. console.warn( 'THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.' );
  15226. forceClear = arguments[ 3 ];
  15227. }
  15228. if ( ! ( camera && camera.isCamera ) ) {
  15229. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  15230. return;
  15231. }
  15232. if ( _isContextLost ) return;
  15233. // reset caching for this frame
  15234. _currentGeometryProgram.geometry = null;
  15235. _currentGeometryProgram.program = null;
  15236. _currentGeometryProgram.wireframe = false;
  15237. _currentMaterialId = - 1;
  15238. _currentCamera = null;
  15239. // update scene graph
  15240. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15241. // update camera matrices and frustum
  15242. if ( camera.parent === null ) camera.updateMatrixWorld();
  15243. if ( vr.enabled ) {
  15244. camera = vr.getCamera( camera );
  15245. }
  15246. //
  15247. currentRenderState = renderStates.get( scene, camera );
  15248. currentRenderState.init();
  15249. scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget );
  15250. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  15251. _frustum.setFromMatrix( _projScreenMatrix );
  15252. _localClippingEnabled = this.localClippingEnabled;
  15253. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  15254. currentRenderList = renderLists.get( scene, camera );
  15255. currentRenderList.init();
  15256. projectObject( scene, camera, 0, _this.sortObjects );
  15257. if ( _this.sortObjects === true ) {
  15258. currentRenderList.sort();
  15259. }
  15260. //
  15261. if ( _clippingEnabled ) _clipping.beginShadows();
  15262. var shadowsArray = currentRenderState.state.shadowsArray;
  15263. shadowMap.render( shadowsArray, scene, camera );
  15264. currentRenderState.setupLights( camera );
  15265. if ( _clippingEnabled ) _clipping.endShadows();
  15266. //
  15267. if ( this.info.autoReset ) this.info.reset();
  15268. if ( renderTarget !== undefined ) {
  15269. this.setRenderTarget( renderTarget );
  15270. }
  15271. //
  15272. background.render( currentRenderList, scene, camera, forceClear );
  15273. // render scene
  15274. var opaqueObjects = currentRenderList.opaque;
  15275. var transparentObjects = currentRenderList.transparent;
  15276. if ( scene.overrideMaterial ) {
  15277. var overrideMaterial = scene.overrideMaterial;
  15278. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  15279. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  15280. } else {
  15281. // opaque pass (front-to-back order)
  15282. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  15283. // transparent pass (back-to-front order)
  15284. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  15285. }
  15286. //
  15287. scene.onAfterRender( _this, scene, camera );
  15288. //
  15289. if ( _currentRenderTarget !== null ) {
  15290. // Generate mipmap if we're using any kind of mipmap filtering
  15291. textures.updateRenderTargetMipmap( _currentRenderTarget );
  15292. // resolve multisample renderbuffers to a single-sample texture if necessary
  15293. textures.updateMultisampleRenderTarget( _currentRenderTarget );
  15294. }
  15295. // Ensure depth buffer writing is enabled so it can be cleared on next render
  15296. state.buffers.depth.setTest( true );
  15297. state.buffers.depth.setMask( true );
  15298. state.buffers.color.setMask( true );
  15299. state.setPolygonOffset( false );
  15300. if ( vr.enabled ) {
  15301. vr.submitFrame();
  15302. }
  15303. // _gl.finish();
  15304. currentRenderList = null;
  15305. currentRenderState = null;
  15306. };
  15307. function projectObject( object, camera, groupOrder, sortObjects ) {
  15308. if ( object.visible === false ) return;
  15309. var visible = object.layers.test( camera.layers );
  15310. if ( visible ) {
  15311. if ( object.isGroup ) {
  15312. groupOrder = object.renderOrder;
  15313. } else if ( object.isLOD ) {
  15314. if ( object.autoUpdate === true ) object.update( camera );
  15315. } else if ( object.isLight ) {
  15316. currentRenderState.pushLight( object );
  15317. if ( object.castShadow ) {
  15318. currentRenderState.pushShadow( object );
  15319. }
  15320. } else if ( object.isSprite ) {
  15321. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  15322. if ( sortObjects ) {
  15323. _vector3.setFromMatrixPosition( object.matrixWorld )
  15324. .applyMatrix4( _projScreenMatrix );
  15325. }
  15326. var geometry = objects.update( object );
  15327. var material = object.material;
  15328. if ( material.visible ) {
  15329. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  15330. }
  15331. }
  15332. } else if ( object.isImmediateRenderObject ) {
  15333. if ( sortObjects ) {
  15334. _vector3.setFromMatrixPosition( object.matrixWorld )
  15335. .applyMatrix4( _projScreenMatrix );
  15336. }
  15337. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  15338. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  15339. if ( object.isSkinnedMesh ) {
  15340. object.skeleton.update();
  15341. }
  15342. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  15343. if ( sortObjects ) {
  15344. _vector3.setFromMatrixPosition( object.matrixWorld )
  15345. .applyMatrix4( _projScreenMatrix );
  15346. }
  15347. var geometry = objects.update( object );
  15348. var material = object.material;
  15349. if ( Array.isArray( material ) ) {
  15350. var groups = geometry.groups;
  15351. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  15352. var group = groups[ i ];
  15353. var groupMaterial = material[ group.materialIndex ];
  15354. if ( groupMaterial && groupMaterial.visible ) {
  15355. currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  15356. }
  15357. }
  15358. } else if ( material.visible ) {
  15359. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  15360. }
  15361. }
  15362. }
  15363. }
  15364. var children = object.children;
  15365. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15366. projectObject( children[ i ], camera, groupOrder, sortObjects );
  15367. }
  15368. }
  15369. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  15370. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  15371. var renderItem = renderList[ i ];
  15372. var object = renderItem.object;
  15373. var geometry = renderItem.geometry;
  15374. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  15375. var group = renderItem.group;
  15376. if ( camera.isArrayCamera ) {
  15377. _currentArrayCamera = camera;
  15378. var cameras = camera.cameras;
  15379. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  15380. var camera2 = cameras[ j ];
  15381. if ( object.layers.test( camera2.layers ) ) {
  15382. state.viewport( _currentViewport.copy( camera2.viewport ) );
  15383. currentRenderState.setupLights( camera2 );
  15384. renderObject( object, scene, camera2, geometry, material, group );
  15385. }
  15386. }
  15387. } else {
  15388. _currentArrayCamera = null;
  15389. renderObject( object, scene, camera, geometry, material, group );
  15390. }
  15391. }
  15392. }
  15393. function renderObject( object, scene, camera, geometry, material, group ) {
  15394. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  15395. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  15396. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15397. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  15398. if ( object.isImmediateRenderObject ) {
  15399. state.setMaterial( material );
  15400. var program = setProgram( camera, scene.fog, material, object );
  15401. _currentGeometryProgram.geometry = null;
  15402. _currentGeometryProgram.program = null;
  15403. _currentGeometryProgram.wireframe = false;
  15404. renderObjectImmediate( object, program );
  15405. } else {
  15406. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  15407. }
  15408. object.onAfterRender( _this, scene, camera, geometry, material, group );
  15409. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  15410. }
  15411. function initMaterial( material, fog, object ) {
  15412. var materialProperties = properties.get( material );
  15413. var lights = currentRenderState.state.lights;
  15414. var shadowsArray = currentRenderState.state.shadowsArray;
  15415. var lightsStateVersion = lights.state.version;
  15416. var parameters = programCache.getParameters(
  15417. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  15418. var code = programCache.getProgramCode( material, parameters );
  15419. var program = materialProperties.program;
  15420. var programChange = true;
  15421. if ( program === undefined ) {
  15422. // new material
  15423. material.addEventListener( 'dispose', onMaterialDispose );
  15424. } else if ( program.code !== code ) {
  15425. // changed glsl or parameters
  15426. releaseMaterialProgramReference( material );
  15427. } else if ( materialProperties.lightsStateVersion !== lightsStateVersion ) {
  15428. materialProperties.lightsStateVersion = lightsStateVersion;
  15429. programChange = false;
  15430. } else if ( parameters.shaderID !== undefined ) {
  15431. // same glsl and uniform list
  15432. return;
  15433. } else {
  15434. // only rebuild uniform list
  15435. programChange = false;
  15436. }
  15437. if ( programChange ) {
  15438. if ( parameters.shaderID ) {
  15439. var shader = ShaderLib[ parameters.shaderID ];
  15440. materialProperties.shader = {
  15441. name: material.type,
  15442. uniforms: cloneUniforms( shader.uniforms ),
  15443. vertexShader: shader.vertexShader,
  15444. fragmentShader: shader.fragmentShader
  15445. };
  15446. } else {
  15447. materialProperties.shader = {
  15448. name: material.type,
  15449. uniforms: material.uniforms,
  15450. vertexShader: material.vertexShader,
  15451. fragmentShader: material.fragmentShader
  15452. };
  15453. }
  15454. material.onBeforeCompile( materialProperties.shader, _this );
  15455. // Computing code again as onBeforeCompile may have changed the shaders
  15456. code = programCache.getProgramCode( material, parameters );
  15457. program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
  15458. materialProperties.program = program;
  15459. material.program = program;
  15460. }
  15461. var programAttributes = program.getAttributes();
  15462. if ( material.morphTargets ) {
  15463. material.numSupportedMorphTargets = 0;
  15464. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  15465. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  15466. material.numSupportedMorphTargets ++;
  15467. }
  15468. }
  15469. }
  15470. if ( material.morphNormals ) {
  15471. material.numSupportedMorphNormals = 0;
  15472. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  15473. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  15474. material.numSupportedMorphNormals ++;
  15475. }
  15476. }
  15477. }
  15478. var uniforms = materialProperties.shader.uniforms;
  15479. if ( ! material.isShaderMaterial &&
  15480. ! material.isRawShaderMaterial ||
  15481. material.clipping === true ) {
  15482. materialProperties.numClippingPlanes = _clipping.numPlanes;
  15483. materialProperties.numIntersection = _clipping.numIntersection;
  15484. uniforms.clippingPlanes = _clipping.uniform;
  15485. }
  15486. materialProperties.fog = fog;
  15487. // store the light setup it was created for
  15488. materialProperties.lightsStateVersion = lightsStateVersion;
  15489. if ( material.lights ) {
  15490. // wire up the material to this renderer's lighting state
  15491. uniforms.ambientLightColor.value = lights.state.ambient;
  15492. uniforms.lightProbe.value = lights.state.probe;
  15493. uniforms.directionalLights.value = lights.state.directional;
  15494. uniforms.spotLights.value = lights.state.spot;
  15495. uniforms.rectAreaLights.value = lights.state.rectArea;
  15496. uniforms.pointLights.value = lights.state.point;
  15497. uniforms.hemisphereLights.value = lights.state.hemi;
  15498. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  15499. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  15500. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  15501. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  15502. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  15503. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  15504. // TODO (abelnation): add area lights shadow info to uniforms
  15505. }
  15506. var progUniforms = materialProperties.program.getUniforms(),
  15507. uniformsList =
  15508. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  15509. materialProperties.uniformsList = uniformsList;
  15510. }
  15511. function setProgram( camera, fog, material, object ) {
  15512. textures.resetTextureUnits();
  15513. var materialProperties = properties.get( material );
  15514. var lights = currentRenderState.state.lights;
  15515. if ( _clippingEnabled ) {
  15516. if ( _localClippingEnabled || camera !== _currentCamera ) {
  15517. var useCache =
  15518. camera === _currentCamera &&
  15519. material.id === _currentMaterialId;
  15520. // we might want to call this function with some ClippingGroup
  15521. // object instead of the material, once it becomes feasible
  15522. // (#8465, #8379)
  15523. _clipping.setState(
  15524. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  15525. camera, materialProperties, useCache );
  15526. }
  15527. }
  15528. if ( material.needsUpdate === false ) {
  15529. if ( materialProperties.program === undefined ) {
  15530. material.needsUpdate = true;
  15531. } else if ( material.fog && materialProperties.fog !== fog ) {
  15532. material.needsUpdate = true;
  15533. } else if ( material.lights && materialProperties.lightsStateVersion !== lights.state.version ) {
  15534. material.needsUpdate = true;
  15535. } else if ( materialProperties.numClippingPlanes !== undefined &&
  15536. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  15537. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  15538. material.needsUpdate = true;
  15539. }
  15540. }
  15541. if ( material.needsUpdate ) {
  15542. initMaterial( material, fog, object );
  15543. material.needsUpdate = false;
  15544. }
  15545. var refreshProgram = false;
  15546. var refreshMaterial = false;
  15547. var refreshLights = false;
  15548. var program = materialProperties.program,
  15549. p_uniforms = program.getUniforms(),
  15550. m_uniforms = materialProperties.shader.uniforms;
  15551. if ( state.useProgram( program.program ) ) {
  15552. refreshProgram = true;
  15553. refreshMaterial = true;
  15554. refreshLights = true;
  15555. }
  15556. if ( material.id !== _currentMaterialId ) {
  15557. _currentMaterialId = material.id;
  15558. refreshMaterial = true;
  15559. }
  15560. if ( refreshProgram || _currentCamera !== camera ) {
  15561. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  15562. if ( capabilities.logarithmicDepthBuffer ) {
  15563. p_uniforms.setValue( _gl, 'logDepthBufFC',
  15564. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  15565. }
  15566. if ( _currentCamera !== camera ) {
  15567. _currentCamera = camera;
  15568. // lighting uniforms depend on the camera so enforce an update
  15569. // now, in case this material supports lights - or later, when
  15570. // the next material that does gets activated:
  15571. refreshMaterial = true; // set to true on material change
  15572. refreshLights = true; // remains set until update done
  15573. }
  15574. // load material specific uniforms
  15575. // (shader material also gets them for the sake of genericity)
  15576. if ( material.isShaderMaterial ||
  15577. material.isMeshPhongMaterial ||
  15578. material.isMeshStandardMaterial ||
  15579. material.envMap ) {
  15580. var uCamPos = p_uniforms.map.cameraPosition;
  15581. if ( uCamPos !== undefined ) {
  15582. uCamPos.setValue( _gl,
  15583. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  15584. }
  15585. }
  15586. if ( material.isMeshPhongMaterial ||
  15587. material.isMeshLambertMaterial ||
  15588. material.isMeshBasicMaterial ||
  15589. material.isMeshStandardMaterial ||
  15590. material.isShaderMaterial ||
  15591. material.skinning ) {
  15592. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  15593. }
  15594. }
  15595. // skinning uniforms must be set even if material didn't change
  15596. // auto-setting of texture unit for bone texture must go before other textures
  15597. // not sure why, but otherwise weird things happen
  15598. if ( material.skinning ) {
  15599. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  15600. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  15601. var skeleton = object.skeleton;
  15602. if ( skeleton ) {
  15603. var bones = skeleton.bones;
  15604. if ( capabilities.floatVertexTextures ) {
  15605. if ( skeleton.boneTexture === undefined ) {
  15606. // layout (1 matrix = 4 pixels)
  15607. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15608. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15609. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15610. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15611. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15612. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  15613. size = _Math.ceilPowerOfTwo( size );
  15614. size = Math.max( size, 4 );
  15615. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  15616. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  15617. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  15618. boneTexture.needsUpdate = true;
  15619. skeleton.boneMatrices = boneMatrices;
  15620. skeleton.boneTexture = boneTexture;
  15621. skeleton.boneTextureSize = size;
  15622. }
  15623. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );
  15624. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  15625. } else {
  15626. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  15627. }
  15628. }
  15629. }
  15630. if ( refreshMaterial ) {
  15631. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  15632. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  15633. if ( material.lights ) {
  15634. // the current material requires lighting info
  15635. // note: all lighting uniforms are always set correctly
  15636. // they simply reference the renderer's state for their
  15637. // values
  15638. //
  15639. // use the current material's .needsUpdate flags to set
  15640. // the GL state when required
  15641. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  15642. }
  15643. // refresh uniforms common to several materials
  15644. if ( fog && material.fog ) {
  15645. refreshUniformsFog( m_uniforms, fog );
  15646. }
  15647. if ( material.isMeshBasicMaterial ) {
  15648. refreshUniformsCommon( m_uniforms, material );
  15649. } else if ( material.isMeshLambertMaterial ) {
  15650. refreshUniformsCommon( m_uniforms, material );
  15651. refreshUniformsLambert( m_uniforms, material );
  15652. } else if ( material.isMeshPhongMaterial ) {
  15653. refreshUniformsCommon( m_uniforms, material );
  15654. if ( material.isMeshToonMaterial ) {
  15655. refreshUniformsToon( m_uniforms, material );
  15656. } else {
  15657. refreshUniformsPhong( m_uniforms, material );
  15658. }
  15659. } else if ( material.isMeshStandardMaterial ) {
  15660. refreshUniformsCommon( m_uniforms, material );
  15661. if ( material.isMeshPhysicalMaterial ) {
  15662. refreshUniformsPhysical( m_uniforms, material );
  15663. } else {
  15664. refreshUniformsStandard( m_uniforms, material );
  15665. }
  15666. } else if ( material.isMeshMatcapMaterial ) {
  15667. refreshUniformsCommon( m_uniforms, material );
  15668. refreshUniformsMatcap( m_uniforms, material );
  15669. } else if ( material.isMeshDepthMaterial ) {
  15670. refreshUniformsCommon( m_uniforms, material );
  15671. refreshUniformsDepth( m_uniforms, material );
  15672. } else if ( material.isMeshDistanceMaterial ) {
  15673. refreshUniformsCommon( m_uniforms, material );
  15674. refreshUniformsDistance( m_uniforms, material );
  15675. } else if ( material.isMeshNormalMaterial ) {
  15676. refreshUniformsCommon( m_uniforms, material );
  15677. refreshUniformsNormal( m_uniforms, material );
  15678. } else if ( material.isLineBasicMaterial ) {
  15679. refreshUniformsLine( m_uniforms, material );
  15680. if ( material.isLineDashedMaterial ) {
  15681. refreshUniformsDash( m_uniforms, material );
  15682. }
  15683. } else if ( material.isPointsMaterial ) {
  15684. refreshUniformsPoints( m_uniforms, material );
  15685. } else if ( material.isSpriteMaterial ) {
  15686. refreshUniformsSprites( m_uniforms, material );
  15687. } else if ( material.isShadowMaterial ) {
  15688. m_uniforms.color.value.copy( material.color );
  15689. m_uniforms.opacity.value = material.opacity;
  15690. }
  15691. // RectAreaLight Texture
  15692. // TODO (mrdoob): Find a nicer implementation
  15693. if ( m_uniforms.ltc_1 !== undefined ) m_uniforms.ltc_1.value = UniformsLib.LTC_1;
  15694. if ( m_uniforms.ltc_2 !== undefined ) m_uniforms.ltc_2.value = UniformsLib.LTC_2;
  15695. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  15696. }
  15697. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  15698. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  15699. material.uniformsNeedUpdate = false;
  15700. }
  15701. if ( material.isSpriteMaterial ) {
  15702. p_uniforms.setValue( _gl, 'center', object.center );
  15703. }
  15704. // common matrices
  15705. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  15706. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  15707. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  15708. return program;
  15709. }
  15710. // Uniforms (refresh uniforms objects)
  15711. function refreshUniformsCommon( uniforms, material ) {
  15712. uniforms.opacity.value = material.opacity;
  15713. if ( material.color ) {
  15714. uniforms.diffuse.value.copy( material.color );
  15715. }
  15716. if ( material.emissive ) {
  15717. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  15718. }
  15719. if ( material.map ) {
  15720. uniforms.map.value = material.map;
  15721. }
  15722. if ( material.alphaMap ) {
  15723. uniforms.alphaMap.value = material.alphaMap;
  15724. }
  15725. if ( material.specularMap ) {
  15726. uniforms.specularMap.value = material.specularMap;
  15727. }
  15728. if ( material.envMap ) {
  15729. uniforms.envMap.value = material.envMap;
  15730. // don't flip CubeTexture envMaps, flip everything else:
  15731. // WebGLRenderTargetCube will be flipped for backwards compatibility
  15732. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  15733. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  15734. uniforms.flipEnvMap.value = material.envMap.isCubeTexture ? - 1 : 1;
  15735. uniforms.reflectivity.value = material.reflectivity;
  15736. uniforms.refractionRatio.value = material.refractionRatio;
  15737. uniforms.maxMipLevel.value = properties.get( material.envMap ).__maxMipLevel;
  15738. }
  15739. if ( material.lightMap ) {
  15740. uniforms.lightMap.value = material.lightMap;
  15741. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15742. }
  15743. if ( material.aoMap ) {
  15744. uniforms.aoMap.value = material.aoMap;
  15745. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  15746. }
  15747. // uv repeat and offset setting priorities
  15748. // 1. color map
  15749. // 2. specular map
  15750. // 3. normal map
  15751. // 4. bump map
  15752. // 5. alpha map
  15753. // 6. emissive map
  15754. var uvScaleMap;
  15755. if ( material.map ) {
  15756. uvScaleMap = material.map;
  15757. } else if ( material.specularMap ) {
  15758. uvScaleMap = material.specularMap;
  15759. } else if ( material.displacementMap ) {
  15760. uvScaleMap = material.displacementMap;
  15761. } else if ( material.normalMap ) {
  15762. uvScaleMap = material.normalMap;
  15763. } else if ( material.bumpMap ) {
  15764. uvScaleMap = material.bumpMap;
  15765. } else if ( material.roughnessMap ) {
  15766. uvScaleMap = material.roughnessMap;
  15767. } else if ( material.metalnessMap ) {
  15768. uvScaleMap = material.metalnessMap;
  15769. } else if ( material.alphaMap ) {
  15770. uvScaleMap = material.alphaMap;
  15771. } else if ( material.emissiveMap ) {
  15772. uvScaleMap = material.emissiveMap;
  15773. }
  15774. if ( uvScaleMap !== undefined ) {
  15775. // backwards compatibility
  15776. if ( uvScaleMap.isWebGLRenderTarget ) {
  15777. uvScaleMap = uvScaleMap.texture;
  15778. }
  15779. if ( uvScaleMap.matrixAutoUpdate === true ) {
  15780. uvScaleMap.updateMatrix();
  15781. }
  15782. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  15783. }
  15784. }
  15785. function refreshUniformsLine( uniforms, material ) {
  15786. uniforms.diffuse.value.copy( material.color );
  15787. uniforms.opacity.value = material.opacity;
  15788. }
  15789. function refreshUniformsDash( uniforms, material ) {
  15790. uniforms.dashSize.value = material.dashSize;
  15791. uniforms.totalSize.value = material.dashSize + material.gapSize;
  15792. uniforms.scale.value = material.scale;
  15793. }
  15794. function refreshUniformsPoints( uniforms, material ) {
  15795. uniforms.diffuse.value.copy( material.color );
  15796. uniforms.opacity.value = material.opacity;
  15797. uniforms.size.value = material.size * _pixelRatio;
  15798. uniforms.scale.value = _height * 0.5;
  15799. uniforms.map.value = material.map;
  15800. if ( material.map !== null ) {
  15801. if ( material.map.matrixAutoUpdate === true ) {
  15802. material.map.updateMatrix();
  15803. }
  15804. uniforms.uvTransform.value.copy( material.map.matrix );
  15805. }
  15806. }
  15807. function refreshUniformsSprites( uniforms, material ) {
  15808. uniforms.diffuse.value.copy( material.color );
  15809. uniforms.opacity.value = material.opacity;
  15810. uniforms.rotation.value = material.rotation;
  15811. uniforms.map.value = material.map;
  15812. if ( material.map !== null ) {
  15813. if ( material.map.matrixAutoUpdate === true ) {
  15814. material.map.updateMatrix();
  15815. }
  15816. uniforms.uvTransform.value.copy( material.map.matrix );
  15817. }
  15818. }
  15819. function refreshUniformsFog( uniforms, fog ) {
  15820. uniforms.fogColor.value.copy( fog.color );
  15821. if ( fog.isFog ) {
  15822. uniforms.fogNear.value = fog.near;
  15823. uniforms.fogFar.value = fog.far;
  15824. } else if ( fog.isFogExp2 ) {
  15825. uniforms.fogDensity.value = fog.density;
  15826. }
  15827. }
  15828. function refreshUniformsLambert( uniforms, material ) {
  15829. if ( material.emissiveMap ) {
  15830. uniforms.emissiveMap.value = material.emissiveMap;
  15831. }
  15832. }
  15833. function refreshUniformsPhong( uniforms, material ) {
  15834. uniforms.specular.value.copy( material.specular );
  15835. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  15836. if ( material.emissiveMap ) {
  15837. uniforms.emissiveMap.value = material.emissiveMap;
  15838. }
  15839. if ( material.bumpMap ) {
  15840. uniforms.bumpMap.value = material.bumpMap;
  15841. uniforms.bumpScale.value = material.bumpScale;
  15842. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15843. }
  15844. if ( material.normalMap ) {
  15845. uniforms.normalMap.value = material.normalMap;
  15846. uniforms.normalScale.value.copy( material.normalScale );
  15847. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15848. }
  15849. if ( material.displacementMap ) {
  15850. uniforms.displacementMap.value = material.displacementMap;
  15851. uniforms.displacementScale.value = material.displacementScale;
  15852. uniforms.displacementBias.value = material.displacementBias;
  15853. }
  15854. }
  15855. function refreshUniformsToon( uniforms, material ) {
  15856. refreshUniformsPhong( uniforms, material );
  15857. if ( material.gradientMap ) {
  15858. uniforms.gradientMap.value = material.gradientMap;
  15859. }
  15860. }
  15861. function refreshUniformsStandard( uniforms, material ) {
  15862. uniforms.roughness.value = material.roughness;
  15863. uniforms.metalness.value = material.metalness;
  15864. if ( material.roughnessMap ) {
  15865. uniforms.roughnessMap.value = material.roughnessMap;
  15866. }
  15867. if ( material.metalnessMap ) {
  15868. uniforms.metalnessMap.value = material.metalnessMap;
  15869. }
  15870. if ( material.emissiveMap ) {
  15871. uniforms.emissiveMap.value = material.emissiveMap;
  15872. }
  15873. if ( material.bumpMap ) {
  15874. uniforms.bumpMap.value = material.bumpMap;
  15875. uniforms.bumpScale.value = material.bumpScale;
  15876. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15877. }
  15878. if ( material.normalMap ) {
  15879. uniforms.normalMap.value = material.normalMap;
  15880. uniforms.normalScale.value.copy( material.normalScale );
  15881. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15882. }
  15883. if ( material.displacementMap ) {
  15884. uniforms.displacementMap.value = material.displacementMap;
  15885. uniforms.displacementScale.value = material.displacementScale;
  15886. uniforms.displacementBias.value = material.displacementBias;
  15887. }
  15888. if ( material.envMap ) {
  15889. //uniforms.envMap.value = material.envMap; // part of uniforms common
  15890. uniforms.envMapIntensity.value = material.envMapIntensity;
  15891. }
  15892. }
  15893. function refreshUniformsPhysical( uniforms, material ) {
  15894. refreshUniformsStandard( uniforms, material );
  15895. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  15896. uniforms.clearCoat.value = material.clearCoat;
  15897. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  15898. if ( material.normalMap || material.clearCoatNormalMap) {
  15899. if(material.clearCoatNormalMap){
  15900. uniforms.clearCoatNormalMap.value = material.clearCoatNormalMap;
  15901. }
  15902. uniforms.clearCoatNormalScale.value.copy( material.clearCoatNormalScale );
  15903. if ( material.side === BackSide ) uniforms.clearCoatNormalScale.value.negate();
  15904. }
  15905. uniforms.clearCoatGeometryNormals.value = material.clearCoatGeometryNormals;
  15906. }
  15907. function refreshUniformsMatcap( uniforms, material ) {
  15908. if ( material.matcap ) {
  15909. uniforms.matcap.value = material.matcap;
  15910. }
  15911. if ( material.bumpMap ) {
  15912. uniforms.bumpMap.value = material.bumpMap;
  15913. uniforms.bumpScale.value = material.bumpScale;
  15914. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15915. }
  15916. if ( material.normalMap ) {
  15917. uniforms.normalMap.value = material.normalMap;
  15918. uniforms.normalScale.value.copy( material.normalScale );
  15919. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15920. }
  15921. if ( material.displacementMap ) {
  15922. uniforms.displacementMap.value = material.displacementMap;
  15923. uniforms.displacementScale.value = material.displacementScale;
  15924. uniforms.displacementBias.value = material.displacementBias;
  15925. }
  15926. }
  15927. function refreshUniformsDepth( uniforms, material ) {
  15928. if ( material.displacementMap ) {
  15929. uniforms.displacementMap.value = material.displacementMap;
  15930. uniforms.displacementScale.value = material.displacementScale;
  15931. uniforms.displacementBias.value = material.displacementBias;
  15932. }
  15933. }
  15934. function refreshUniformsDistance( uniforms, material ) {
  15935. if ( material.displacementMap ) {
  15936. uniforms.displacementMap.value = material.displacementMap;
  15937. uniforms.displacementScale.value = material.displacementScale;
  15938. uniforms.displacementBias.value = material.displacementBias;
  15939. }
  15940. uniforms.referencePosition.value.copy( material.referencePosition );
  15941. uniforms.nearDistance.value = material.nearDistance;
  15942. uniforms.farDistance.value = material.farDistance;
  15943. }
  15944. function refreshUniformsNormal( uniforms, material ) {
  15945. if ( material.bumpMap ) {
  15946. uniforms.bumpMap.value = material.bumpMap;
  15947. uniforms.bumpScale.value = material.bumpScale;
  15948. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15949. }
  15950. if ( material.normalMap ) {
  15951. uniforms.normalMap.value = material.normalMap;
  15952. uniforms.normalScale.value.copy( material.normalScale );
  15953. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15954. }
  15955. if ( material.displacementMap ) {
  15956. uniforms.displacementMap.value = material.displacementMap;
  15957. uniforms.displacementScale.value = material.displacementScale;
  15958. uniforms.displacementBias.value = material.displacementBias;
  15959. }
  15960. }
  15961. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15962. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  15963. uniforms.ambientLightColor.needsUpdate = value;
  15964. uniforms.lightProbe.needsUpdate = value;
  15965. uniforms.directionalLights.needsUpdate = value;
  15966. uniforms.pointLights.needsUpdate = value;
  15967. uniforms.spotLights.needsUpdate = value;
  15968. uniforms.rectAreaLights.needsUpdate = value;
  15969. uniforms.hemisphereLights.needsUpdate = value;
  15970. }
  15971. //
  15972. this.setFramebuffer = function ( value ) {
  15973. if ( _framebuffer !== value ) _gl.bindFramebuffer( 36160, value );
  15974. _framebuffer = value;
  15975. };
  15976. this.getActiveCubeFace = function () {
  15977. return _currentActiveCubeFace;
  15978. };
  15979. this.getActiveMipmapLevel = function () {
  15980. return _currentActiveMipmapLevel;
  15981. };
  15982. this.getRenderTarget = function () {
  15983. return _currentRenderTarget;
  15984. };
  15985. this.setRenderTarget = function ( renderTarget, activeCubeFace, activeMipmapLevel ) {
  15986. _currentRenderTarget = renderTarget;
  15987. _currentActiveCubeFace = activeCubeFace;
  15988. _currentActiveMipmapLevel = activeMipmapLevel;
  15989. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  15990. textures.setupRenderTarget( renderTarget );
  15991. }
  15992. var framebuffer = _framebuffer;
  15993. var isCube = false;
  15994. if ( renderTarget ) {
  15995. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  15996. if ( renderTarget.isWebGLRenderTargetCube ) {
  15997. framebuffer = __webglFramebuffer[ activeCubeFace || 0 ];
  15998. isCube = true;
  15999. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  16000. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  16001. } else {
  16002. framebuffer = __webglFramebuffer;
  16003. }
  16004. _currentViewport.copy( renderTarget.viewport );
  16005. _currentScissor.copy( renderTarget.scissor );
  16006. _currentScissorTest = renderTarget.scissorTest;
  16007. } else {
  16008. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor();
  16009. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor();
  16010. _currentScissorTest = _scissorTest;
  16011. }
  16012. if ( _currentFramebuffer !== framebuffer ) {
  16013. _gl.bindFramebuffer( 36160, framebuffer );
  16014. _currentFramebuffer = framebuffer;
  16015. }
  16016. state.viewport( _currentViewport );
  16017. state.scissor( _currentScissor );
  16018. state.setScissorTest( _currentScissorTest );
  16019. if ( isCube ) {
  16020. var textureProperties = properties.get( renderTarget.texture );
  16021. _gl.framebufferTexture2D( 36160, 36064, 34069 + ( activeCubeFace || 0 ), textureProperties.__webglTexture, activeMipmapLevel || 0 );
  16022. }
  16023. };
  16024. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
  16025. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  16026. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  16027. return;
  16028. }
  16029. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  16030. if ( renderTarget.isWebGLRenderTargetCube && activeCubeFaceIndex !== undefined ) {
  16031. framebuffer = framebuffer[ activeCubeFaceIndex ];
  16032. }
  16033. if ( framebuffer ) {
  16034. var restore = false;
  16035. if ( framebuffer !== _currentFramebuffer ) {
  16036. _gl.bindFramebuffer( 36160, framebuffer );
  16037. restore = true;
  16038. }
  16039. try {
  16040. var texture = renderTarget.texture;
  16041. var textureFormat = texture.format;
  16042. var textureType = texture.type;
  16043. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  16044. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  16045. return;
  16046. }
  16047. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  16048. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  16049. ! ( textureType === HalfFloatType && ( capabilities.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) {
  16050. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  16051. return;
  16052. }
  16053. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  16054. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  16055. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  16056. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  16057. }
  16058. } else {
  16059. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  16060. }
  16061. } finally {
  16062. if ( restore ) {
  16063. _gl.bindFramebuffer( 36160, _currentFramebuffer );
  16064. }
  16065. }
  16066. }
  16067. };
  16068. this.copyFramebufferToTexture = function ( position, texture, level ) {
  16069. var width = texture.image.width;
  16070. var height = texture.image.height;
  16071. var glFormat = utils.convert( texture.format );
  16072. textures.setTexture2D( texture, 0 );
  16073. _gl.copyTexImage2D( 3553, level || 0, glFormat, position.x, position.y, width, height, 0 );
  16074. };
  16075. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) {
  16076. var width = srcTexture.image.width;
  16077. var height = srcTexture.image.height;
  16078. var glFormat = utils.convert( dstTexture.format );
  16079. var glType = utils.convert( dstTexture.type );
  16080. textures.setTexture2D( dstTexture, 0 );
  16081. if ( srcTexture.isDataTexture ) {
  16082. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  16083. } else {
  16084. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, glFormat, glType, srcTexture.image );
  16085. }
  16086. };
  16087. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  16088. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  16089. }
  16090. }
  16091. /**
  16092. * @author mrdoob / http://mrdoob.com/
  16093. * @author alteredq / http://alteredqualia.com/
  16094. */
  16095. function FogExp2( color, density ) {
  16096. this.name = '';
  16097. this.color = new Color( color );
  16098. this.density = ( density !== undefined ) ? density : 0.00025;
  16099. }
  16100. Object.assign( FogExp2.prototype, {
  16101. isFogExp2: true,
  16102. clone: function () {
  16103. return new FogExp2( this.color, this.density );
  16104. },
  16105. toJSON: function ( /* meta */ ) {
  16106. return {
  16107. type: 'FogExp2',
  16108. color: this.color.getHex(),
  16109. density: this.density
  16110. };
  16111. }
  16112. } );
  16113. /**
  16114. * @author mrdoob / http://mrdoob.com/
  16115. * @author alteredq / http://alteredqualia.com/
  16116. */
  16117. function Fog( color, near, far ) {
  16118. this.name = '';
  16119. this.color = new Color( color );
  16120. this.near = ( near !== undefined ) ? near : 1;
  16121. this.far = ( far !== undefined ) ? far : 1000;
  16122. }
  16123. Object.assign( Fog.prototype, {
  16124. isFog: true,
  16125. clone: function () {
  16126. return new Fog( this.color, this.near, this.far );
  16127. },
  16128. toJSON: function ( /* meta */ ) {
  16129. return {
  16130. type: 'Fog',
  16131. color: this.color.getHex(),
  16132. near: this.near,
  16133. far: this.far
  16134. };
  16135. }
  16136. } );
  16137. /**
  16138. * @author benaadams / https://twitter.com/ben_a_adams
  16139. */
  16140. function InterleavedBuffer( array, stride ) {
  16141. this.array = array;
  16142. this.stride = stride;
  16143. this.count = array !== undefined ? array.length / stride : 0;
  16144. this.dynamic = false;
  16145. this.updateRange = { offset: 0, count: - 1 };
  16146. this.version = 0;
  16147. }
  16148. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  16149. set: function ( value ) {
  16150. if ( value === true ) this.version ++;
  16151. }
  16152. } );
  16153. Object.assign( InterleavedBuffer.prototype, {
  16154. isInterleavedBuffer: true,
  16155. onUploadCallback: function () {},
  16156. setArray: function ( array ) {
  16157. if ( Array.isArray( array ) ) {
  16158. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  16159. }
  16160. this.count = array !== undefined ? array.length / this.stride : 0;
  16161. this.array = array;
  16162. return this;
  16163. },
  16164. setDynamic: function ( value ) {
  16165. this.dynamic = value;
  16166. return this;
  16167. },
  16168. copy: function ( source ) {
  16169. this.array = new source.array.constructor( source.array );
  16170. this.count = source.count;
  16171. this.stride = source.stride;
  16172. this.dynamic = source.dynamic;
  16173. return this;
  16174. },
  16175. copyAt: function ( index1, attribute, index2 ) {
  16176. index1 *= this.stride;
  16177. index2 *= attribute.stride;
  16178. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  16179. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  16180. }
  16181. return this;
  16182. },
  16183. set: function ( value, offset ) {
  16184. if ( offset === undefined ) offset = 0;
  16185. this.array.set( value, offset );
  16186. return this;
  16187. },
  16188. clone: function () {
  16189. return new this.constructor().copy( this );
  16190. },
  16191. onUpload: function ( callback ) {
  16192. this.onUploadCallback = callback;
  16193. return this;
  16194. }
  16195. } );
  16196. /**
  16197. * @author benaadams / https://twitter.com/ben_a_adams
  16198. */
  16199. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  16200. this.data = interleavedBuffer;
  16201. this.itemSize = itemSize;
  16202. this.offset = offset;
  16203. this.normalized = normalized === true;
  16204. }
  16205. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  16206. count: {
  16207. get: function () {
  16208. return this.data.count;
  16209. }
  16210. },
  16211. array: {
  16212. get: function () {
  16213. return this.data.array;
  16214. }
  16215. }
  16216. } );
  16217. Object.assign( InterleavedBufferAttribute.prototype, {
  16218. isInterleavedBufferAttribute: true,
  16219. setX: function ( index, x ) {
  16220. this.data.array[ index * this.data.stride + this.offset ] = x;
  16221. return this;
  16222. },
  16223. setY: function ( index, y ) {
  16224. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  16225. return this;
  16226. },
  16227. setZ: function ( index, z ) {
  16228. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  16229. return this;
  16230. },
  16231. setW: function ( index, w ) {
  16232. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  16233. return this;
  16234. },
  16235. getX: function ( index ) {
  16236. return this.data.array[ index * this.data.stride + this.offset ];
  16237. },
  16238. getY: function ( index ) {
  16239. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  16240. },
  16241. getZ: function ( index ) {
  16242. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  16243. },
  16244. getW: function ( index ) {
  16245. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  16246. },
  16247. setXY: function ( index, x, y ) {
  16248. index = index * this.data.stride + this.offset;
  16249. this.data.array[ index + 0 ] = x;
  16250. this.data.array[ index + 1 ] = y;
  16251. return this;
  16252. },
  16253. setXYZ: function ( index, x, y, z ) {
  16254. index = index * this.data.stride + this.offset;
  16255. this.data.array[ index + 0 ] = x;
  16256. this.data.array[ index + 1 ] = y;
  16257. this.data.array[ index + 2 ] = z;
  16258. return this;
  16259. },
  16260. setXYZW: function ( index, x, y, z, w ) {
  16261. index = index * this.data.stride + this.offset;
  16262. this.data.array[ index + 0 ] = x;
  16263. this.data.array[ index + 1 ] = y;
  16264. this.data.array[ index + 2 ] = z;
  16265. this.data.array[ index + 3 ] = w;
  16266. return this;
  16267. }
  16268. } );
  16269. /**
  16270. * @author alteredq / http://alteredqualia.com/
  16271. *
  16272. * parameters = {
  16273. * color: <hex>,
  16274. * map: new THREE.Texture( <Image> ),
  16275. * rotation: <float>,
  16276. * sizeAttenuation: <bool>
  16277. * }
  16278. */
  16279. function SpriteMaterial( parameters ) {
  16280. Material.call( this );
  16281. this.type = 'SpriteMaterial';
  16282. this.color = new Color( 0xffffff );
  16283. this.map = null;
  16284. this.rotation = 0;
  16285. this.sizeAttenuation = true;
  16286. this.lights = false;
  16287. this.transparent = true;
  16288. this.setValues( parameters );
  16289. }
  16290. SpriteMaterial.prototype = Object.create( Material.prototype );
  16291. SpriteMaterial.prototype.constructor = SpriteMaterial;
  16292. SpriteMaterial.prototype.isSpriteMaterial = true;
  16293. SpriteMaterial.prototype.copy = function ( source ) {
  16294. Material.prototype.copy.call( this, source );
  16295. this.color.copy( source.color );
  16296. this.map = source.map;
  16297. this.rotation = source.rotation;
  16298. this.sizeAttenuation = source.sizeAttenuation;
  16299. return this;
  16300. };
  16301. /**
  16302. * @author mikael emtinger / http://gomo.se/
  16303. * @author alteredq / http://alteredqualia.com/
  16304. */
  16305. var geometry;
  16306. function Sprite( material ) {
  16307. Object3D.call( this );
  16308. this.type = 'Sprite';
  16309. if ( geometry === undefined ) {
  16310. geometry = new BufferGeometry();
  16311. var float32Array = new Float32Array( [
  16312. - 0.5, - 0.5, 0, 0, 0,
  16313. 0.5, - 0.5, 0, 1, 0,
  16314. 0.5, 0.5, 0, 1, 1,
  16315. - 0.5, 0.5, 0, 0, 1
  16316. ] );
  16317. var interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  16318. geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  16319. geometry.addAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  16320. geometry.addAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  16321. }
  16322. this.geometry = geometry;
  16323. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  16324. this.center = new Vector2( 0.5, 0.5 );
  16325. }
  16326. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16327. constructor: Sprite,
  16328. isSprite: true,
  16329. raycast: ( function () {
  16330. var intersectPoint = new Vector3();
  16331. var worldScale = new Vector3();
  16332. var mvPosition = new Vector3();
  16333. var alignedPosition = new Vector2();
  16334. var rotatedPosition = new Vector2();
  16335. var viewWorldMatrix = new Matrix4();
  16336. var vA = new Vector3();
  16337. var vB = new Vector3();
  16338. var vC = new Vector3();
  16339. var uvA = new Vector2();
  16340. var uvB = new Vector2();
  16341. var uvC = new Vector2();
  16342. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  16343. // compute position in camera space
  16344. alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  16345. // to check if rotation is not zero
  16346. if ( sin !== undefined ) {
  16347. rotatedPosition.x = ( cos * alignedPosition.x ) - ( sin * alignedPosition.y );
  16348. rotatedPosition.y = ( sin * alignedPosition.x ) + ( cos * alignedPosition.y );
  16349. } else {
  16350. rotatedPosition.copy( alignedPosition );
  16351. }
  16352. vertexPosition.copy( mvPosition );
  16353. vertexPosition.x += rotatedPosition.x;
  16354. vertexPosition.y += rotatedPosition.y;
  16355. // transform to world space
  16356. vertexPosition.applyMatrix4( viewWorldMatrix );
  16357. }
  16358. return function raycast( raycaster, intersects ) {
  16359. worldScale.setFromMatrixScale( this.matrixWorld );
  16360. viewWorldMatrix.copy( raycaster._camera.matrixWorld );
  16361. this.modelViewMatrix.multiplyMatrices( raycaster._camera.matrixWorldInverse, this.matrixWorld );
  16362. mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  16363. if ( raycaster._camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
  16364. worldScale.multiplyScalar( - mvPosition.z );
  16365. }
  16366. var rotation = this.material.rotation;
  16367. var sin, cos;
  16368. if ( rotation !== 0 ) {
  16369. cos = Math.cos( rotation );
  16370. sin = Math.sin( rotation );
  16371. }
  16372. var center = this.center;
  16373. transformVertex( vA.set( - 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  16374. transformVertex( vB.set( 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  16375. transformVertex( vC.set( 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  16376. uvA.set( 0, 0 );
  16377. uvB.set( 1, 0 );
  16378. uvC.set( 1, 1 );
  16379. // check first triangle
  16380. var intersect = raycaster.ray.intersectTriangle( vA, vB, vC, false, intersectPoint );
  16381. if ( intersect === null ) {
  16382. // check second triangle
  16383. transformVertex( vB.set( - 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  16384. uvB.set( 0, 1 );
  16385. intersect = raycaster.ray.intersectTriangle( vA, vC, vB, false, intersectPoint );
  16386. if ( intersect === null ) {
  16387. return;
  16388. }
  16389. }
  16390. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  16391. if ( distance < raycaster.near || distance > raycaster.far ) return;
  16392. intersects.push( {
  16393. distance: distance,
  16394. point: intersectPoint.clone(),
  16395. uv: Triangle.getUV( intersectPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() ),
  16396. face: null,
  16397. object: this
  16398. } );
  16399. };
  16400. }() ),
  16401. clone: function () {
  16402. return new this.constructor( this.material ).copy( this );
  16403. },
  16404. copy: function ( source ) {
  16405. Object3D.prototype.copy.call( this, source );
  16406. if ( source.center !== undefined ) this.center.copy( source.center );
  16407. return this;
  16408. }
  16409. } );
  16410. /**
  16411. * @author mikael emtinger / http://gomo.se/
  16412. * @author alteredq / http://alteredqualia.com/
  16413. * @author mrdoob / http://mrdoob.com/
  16414. */
  16415. function LOD() {
  16416. Object3D.call( this );
  16417. this.type = 'LOD';
  16418. Object.defineProperties( this, {
  16419. levels: {
  16420. enumerable: true,
  16421. value: []
  16422. }
  16423. } );
  16424. this.autoUpdate = true;
  16425. }
  16426. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16427. constructor: LOD,
  16428. isLOD: true,
  16429. copy: function ( source ) {
  16430. Object3D.prototype.copy.call( this, source, false );
  16431. var levels = source.levels;
  16432. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  16433. var level = levels[ i ];
  16434. this.addLevel( level.object.clone(), level.distance );
  16435. }
  16436. return this;
  16437. },
  16438. addLevel: function ( object, distance ) {
  16439. if ( distance === undefined ) distance = 0;
  16440. distance = Math.abs( distance );
  16441. var levels = this.levels;
  16442. for ( var l = 0; l < levels.length; l ++ ) {
  16443. if ( distance < levels[ l ].distance ) {
  16444. break;
  16445. }
  16446. }
  16447. levels.splice( l, 0, { distance: distance, object: object } );
  16448. this.add( object );
  16449. return this;
  16450. },
  16451. getObjectForDistance: function ( distance ) {
  16452. var levels = this.levels;
  16453. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  16454. if ( distance < levels[ i ].distance ) {
  16455. break;
  16456. }
  16457. }
  16458. return levels[ i - 1 ].object;
  16459. },
  16460. raycast: ( function () {
  16461. var matrixPosition = new Vector3();
  16462. return function raycast( raycaster, intersects ) {
  16463. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  16464. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  16465. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  16466. };
  16467. }() ),
  16468. update: function () {
  16469. var v1 = new Vector3();
  16470. var v2 = new Vector3();
  16471. return function update( camera ) {
  16472. var levels = this.levels;
  16473. if ( levels.length > 1 ) {
  16474. v1.setFromMatrixPosition( camera.matrixWorld );
  16475. v2.setFromMatrixPosition( this.matrixWorld );
  16476. var distance = v1.distanceTo( v2 );
  16477. levels[ 0 ].object.visible = true;
  16478. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  16479. if ( distance >= levels[ i ].distance ) {
  16480. levels[ i - 1 ].object.visible = false;
  16481. levels[ i ].object.visible = true;
  16482. } else {
  16483. break;
  16484. }
  16485. }
  16486. for ( ; i < l; i ++ ) {
  16487. levels[ i ].object.visible = false;
  16488. }
  16489. }
  16490. };
  16491. }(),
  16492. toJSON: function ( meta ) {
  16493. var data = Object3D.prototype.toJSON.call( this, meta );
  16494. data.object.levels = [];
  16495. var levels = this.levels;
  16496. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  16497. var level = levels[ i ];
  16498. data.object.levels.push( {
  16499. object: level.object.uuid,
  16500. distance: level.distance
  16501. } );
  16502. }
  16503. return data;
  16504. }
  16505. } );
  16506. /**
  16507. * @author mikael emtinger / http://gomo.se/
  16508. * @author alteredq / http://alteredqualia.com/
  16509. * @author ikerr / http://verold.com
  16510. */
  16511. function SkinnedMesh( geometry, material ) {
  16512. if ( geometry && geometry.isGeometry ) {
  16513. console.error( 'THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16514. }
  16515. Mesh.call( this, geometry, material );
  16516. this.type = 'SkinnedMesh';
  16517. this.bindMode = 'attached';
  16518. this.bindMatrix = new Matrix4();
  16519. this.bindMatrixInverse = new Matrix4();
  16520. }
  16521. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  16522. constructor: SkinnedMesh,
  16523. isSkinnedMesh: true,
  16524. bind: function ( skeleton, bindMatrix ) {
  16525. this.skeleton = skeleton;
  16526. if ( bindMatrix === undefined ) {
  16527. this.updateMatrixWorld( true );
  16528. this.skeleton.calculateInverses();
  16529. bindMatrix = this.matrixWorld;
  16530. }
  16531. this.bindMatrix.copy( bindMatrix );
  16532. this.bindMatrixInverse.getInverse( bindMatrix );
  16533. },
  16534. pose: function () {
  16535. this.skeleton.pose();
  16536. },
  16537. normalizeSkinWeights: function () {
  16538. var vector = new Vector4();
  16539. var skinWeight = this.geometry.attributes.skinWeight;
  16540. for ( var i = 0, l = skinWeight.count; i < l; i ++ ) {
  16541. vector.x = skinWeight.getX( i );
  16542. vector.y = skinWeight.getY( i );
  16543. vector.z = skinWeight.getZ( i );
  16544. vector.w = skinWeight.getW( i );
  16545. var scale = 1.0 / vector.manhattanLength();
  16546. if ( scale !== Infinity ) {
  16547. vector.multiplyScalar( scale );
  16548. } else {
  16549. vector.set( 1, 0, 0, 0 ); // do something reasonable
  16550. }
  16551. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  16552. }
  16553. },
  16554. updateMatrixWorld: function ( force ) {
  16555. Mesh.prototype.updateMatrixWorld.call( this, force );
  16556. if ( this.bindMode === 'attached' ) {
  16557. this.bindMatrixInverse.getInverse( this.matrixWorld );
  16558. } else if ( this.bindMode === 'detached' ) {
  16559. this.bindMatrixInverse.getInverse( this.bindMatrix );
  16560. } else {
  16561. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  16562. }
  16563. },
  16564. clone: function () {
  16565. return new this.constructor( this.geometry, this.material ).copy( this );
  16566. }
  16567. } );
  16568. /**
  16569. * @author mikael emtinger / http://gomo.se/
  16570. * @author alteredq / http://alteredqualia.com/
  16571. * @author michael guerrero / http://realitymeltdown.com
  16572. * @author ikerr / http://verold.com
  16573. */
  16574. function Skeleton( bones, boneInverses ) {
  16575. // copy the bone array
  16576. bones = bones || [];
  16577. this.bones = bones.slice( 0 );
  16578. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  16579. // use the supplied bone inverses or calculate the inverses
  16580. if ( boneInverses === undefined ) {
  16581. this.calculateInverses();
  16582. } else {
  16583. if ( this.bones.length === boneInverses.length ) {
  16584. this.boneInverses = boneInverses.slice( 0 );
  16585. } else {
  16586. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  16587. this.boneInverses = [];
  16588. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  16589. this.boneInverses.push( new Matrix4() );
  16590. }
  16591. }
  16592. }
  16593. }
  16594. Object.assign( Skeleton.prototype, {
  16595. calculateInverses: function () {
  16596. this.boneInverses = [];
  16597. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  16598. var inverse = new Matrix4();
  16599. if ( this.bones[ i ] ) {
  16600. inverse.getInverse( this.bones[ i ].matrixWorld );
  16601. }
  16602. this.boneInverses.push( inverse );
  16603. }
  16604. },
  16605. pose: function () {
  16606. var bone, i, il;
  16607. // recover the bind-time world matrices
  16608. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  16609. bone = this.bones[ i ];
  16610. if ( bone ) {
  16611. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  16612. }
  16613. }
  16614. // compute the local matrices, positions, rotations and scales
  16615. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  16616. bone = this.bones[ i ];
  16617. if ( bone ) {
  16618. if ( bone.parent && bone.parent.isBone ) {
  16619. bone.matrix.getInverse( bone.parent.matrixWorld );
  16620. bone.matrix.multiply( bone.matrixWorld );
  16621. } else {
  16622. bone.matrix.copy( bone.matrixWorld );
  16623. }
  16624. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  16625. }
  16626. }
  16627. },
  16628. update: ( function () {
  16629. var offsetMatrix = new Matrix4();
  16630. var identityMatrix = new Matrix4();
  16631. return function update() {
  16632. var bones = this.bones;
  16633. var boneInverses = this.boneInverses;
  16634. var boneMatrices = this.boneMatrices;
  16635. var boneTexture = this.boneTexture;
  16636. // flatten bone matrices to array
  16637. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  16638. // compute the offset between the current and the original transform
  16639. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  16640. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  16641. offsetMatrix.toArray( boneMatrices, i * 16 );
  16642. }
  16643. if ( boneTexture !== undefined ) {
  16644. boneTexture.needsUpdate = true;
  16645. }
  16646. };
  16647. } )(),
  16648. clone: function () {
  16649. return new Skeleton( this.bones, this.boneInverses );
  16650. },
  16651. getBoneByName: function ( name ) {
  16652. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  16653. var bone = this.bones[ i ];
  16654. if ( bone.name === name ) {
  16655. return bone;
  16656. }
  16657. }
  16658. return undefined;
  16659. }
  16660. } );
  16661. /**
  16662. * @author mikael emtinger / http://gomo.se/
  16663. * @author alteredq / http://alteredqualia.com/
  16664. * @author ikerr / http://verold.com
  16665. */
  16666. function Bone() {
  16667. Object3D.call( this );
  16668. this.type = 'Bone';
  16669. }
  16670. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16671. constructor: Bone,
  16672. isBone: true
  16673. } );
  16674. /**
  16675. * @author mrdoob / http://mrdoob.com/
  16676. * @author alteredq / http://alteredqualia.com/
  16677. *
  16678. * parameters = {
  16679. * color: <hex>,
  16680. * opacity: <float>,
  16681. *
  16682. * linewidth: <float>,
  16683. * linecap: "round",
  16684. * linejoin: "round"
  16685. * }
  16686. */
  16687. function LineBasicMaterial( parameters ) {
  16688. Material.call( this );
  16689. this.type = 'LineBasicMaterial';
  16690. this.color = new Color( 0xffffff );
  16691. this.linewidth = 1;
  16692. this.linecap = 'round';
  16693. this.linejoin = 'round';
  16694. this.lights = false;
  16695. this.setValues( parameters );
  16696. }
  16697. LineBasicMaterial.prototype = Object.create( Material.prototype );
  16698. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  16699. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16700. LineBasicMaterial.prototype.copy = function ( source ) {
  16701. Material.prototype.copy.call( this, source );
  16702. this.color.copy( source.color );
  16703. this.linewidth = source.linewidth;
  16704. this.linecap = source.linecap;
  16705. this.linejoin = source.linejoin;
  16706. return this;
  16707. };
  16708. /**
  16709. * @author mrdoob / http://mrdoob.com/
  16710. */
  16711. function Line( geometry, material, mode ) {
  16712. if ( mode === 1 ) {
  16713. console.error( 'THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.' );
  16714. }
  16715. Object3D.call( this );
  16716. this.type = 'Line';
  16717. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16718. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  16719. }
  16720. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16721. constructor: Line,
  16722. isLine: true,
  16723. computeLineDistances: ( function () {
  16724. var start = new Vector3();
  16725. var end = new Vector3();
  16726. return function computeLineDistances() {
  16727. var geometry = this.geometry;
  16728. if ( geometry.isBufferGeometry ) {
  16729. // we assume non-indexed geometry
  16730. if ( geometry.index === null ) {
  16731. var positionAttribute = geometry.attributes.position;
  16732. var lineDistances = [ 0 ];
  16733. for ( var i = 1, l = positionAttribute.count; i < l; i ++ ) {
  16734. start.fromBufferAttribute( positionAttribute, i - 1 );
  16735. end.fromBufferAttribute( positionAttribute, i );
  16736. lineDistances[ i ] = lineDistances[ i - 1 ];
  16737. lineDistances[ i ] += start.distanceTo( end );
  16738. }
  16739. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  16740. } else {
  16741. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  16742. }
  16743. } else if ( geometry.isGeometry ) {
  16744. var vertices = geometry.vertices;
  16745. var lineDistances = geometry.lineDistances;
  16746. lineDistances[ 0 ] = 0;
  16747. for ( var i = 1, l = vertices.length; i < l; i ++ ) {
  16748. lineDistances[ i ] = lineDistances[ i - 1 ];
  16749. lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
  16750. }
  16751. }
  16752. return this;
  16753. };
  16754. }() ),
  16755. raycast: ( function () {
  16756. var inverseMatrix = new Matrix4();
  16757. var ray = new Ray();
  16758. var sphere = new Sphere();
  16759. return function raycast( raycaster, intersects ) {
  16760. var precision = raycaster.linePrecision;
  16761. var geometry = this.geometry;
  16762. var matrixWorld = this.matrixWorld;
  16763. // Checking boundingSphere distance to ray
  16764. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  16765. sphere.copy( geometry.boundingSphere );
  16766. sphere.applyMatrix4( matrixWorld );
  16767. sphere.radius += precision;
  16768. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  16769. //
  16770. inverseMatrix.getInverse( matrixWorld );
  16771. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  16772. var localPrecision = precision / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  16773. var localPrecisionSq = localPrecision * localPrecision;
  16774. var vStart = new Vector3();
  16775. var vEnd = new Vector3();
  16776. var interSegment = new Vector3();
  16777. var interRay = new Vector3();
  16778. var step = ( this && this.isLineSegments ) ? 2 : 1;
  16779. if ( geometry.isBufferGeometry ) {
  16780. var index = geometry.index;
  16781. var attributes = geometry.attributes;
  16782. var positions = attributes.position.array;
  16783. if ( index !== null ) {
  16784. var indices = index.array;
  16785. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  16786. var a = indices[ i ];
  16787. var b = indices[ i + 1 ];
  16788. vStart.fromArray( positions, a * 3 );
  16789. vEnd.fromArray( positions, b * 3 );
  16790. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  16791. if ( distSq > localPrecisionSq ) continue;
  16792. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  16793. var distance = raycaster.ray.origin.distanceTo( interRay );
  16794. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  16795. intersects.push( {
  16796. distance: distance,
  16797. // What do we want? intersection point on the ray or on the segment??
  16798. // point: raycaster.ray.at( distance ),
  16799. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  16800. index: i,
  16801. face: null,
  16802. faceIndex: null,
  16803. object: this
  16804. } );
  16805. }
  16806. } else {
  16807. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  16808. vStart.fromArray( positions, 3 * i );
  16809. vEnd.fromArray( positions, 3 * i + 3 );
  16810. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  16811. if ( distSq > localPrecisionSq ) continue;
  16812. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  16813. var distance = raycaster.ray.origin.distanceTo( interRay );
  16814. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  16815. intersects.push( {
  16816. distance: distance,
  16817. // What do we want? intersection point on the ray or on the segment??
  16818. // point: raycaster.ray.at( distance ),
  16819. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  16820. index: i,
  16821. face: null,
  16822. faceIndex: null,
  16823. object: this
  16824. } );
  16825. }
  16826. }
  16827. } else if ( geometry.isGeometry ) {
  16828. var vertices = geometry.vertices;
  16829. var nbVertices = vertices.length;
  16830. for ( var i = 0; i < nbVertices - 1; i += step ) {
  16831. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  16832. if ( distSq > localPrecisionSq ) continue;
  16833. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  16834. var distance = raycaster.ray.origin.distanceTo( interRay );
  16835. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  16836. intersects.push( {
  16837. distance: distance,
  16838. // What do we want? intersection point on the ray or on the segment??
  16839. // point: raycaster.ray.at( distance ),
  16840. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  16841. index: i,
  16842. face: null,
  16843. faceIndex: null,
  16844. object: this
  16845. } );
  16846. }
  16847. }
  16848. };
  16849. }() ),
  16850. clone: function () {
  16851. return new this.constructor( this.geometry, this.material ).copy( this );
  16852. }
  16853. } );
  16854. /**
  16855. * @author mrdoob / http://mrdoob.com/
  16856. */
  16857. function LineSegments( geometry, material ) {
  16858. Line.call( this, geometry, material );
  16859. this.type = 'LineSegments';
  16860. }
  16861. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  16862. constructor: LineSegments,
  16863. isLineSegments: true,
  16864. computeLineDistances: ( function () {
  16865. var start = new Vector3();
  16866. var end = new Vector3();
  16867. return function computeLineDistances() {
  16868. var geometry = this.geometry;
  16869. if ( geometry.isBufferGeometry ) {
  16870. // we assume non-indexed geometry
  16871. if ( geometry.index === null ) {
  16872. var positionAttribute = geometry.attributes.position;
  16873. var lineDistances = [];
  16874. for ( var i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  16875. start.fromBufferAttribute( positionAttribute, i );
  16876. end.fromBufferAttribute( positionAttribute, i + 1 );
  16877. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16878. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  16879. }
  16880. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  16881. } else {
  16882. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  16883. }
  16884. } else if ( geometry.isGeometry ) {
  16885. var vertices = geometry.vertices;
  16886. var lineDistances = geometry.lineDistances;
  16887. for ( var i = 0, l = vertices.length; i < l; i += 2 ) {
  16888. start.copy( vertices[ i ] );
  16889. end.copy( vertices[ i + 1 ] );
  16890. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16891. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  16892. }
  16893. }
  16894. return this;
  16895. };
  16896. }() )
  16897. } );
  16898. /**
  16899. * @author mgreter / http://github.com/mgreter
  16900. */
  16901. function LineLoop( geometry, material ) {
  16902. Line.call( this, geometry, material );
  16903. this.type = 'LineLoop';
  16904. }
  16905. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  16906. constructor: LineLoop,
  16907. isLineLoop: true,
  16908. } );
  16909. /**
  16910. * @author mrdoob / http://mrdoob.com/
  16911. * @author alteredq / http://alteredqualia.com/
  16912. *
  16913. * parameters = {
  16914. * color: <hex>,
  16915. * opacity: <float>,
  16916. * map: new THREE.Texture( <Image> ),
  16917. *
  16918. * size: <float>,
  16919. * sizeAttenuation: <bool>
  16920. *
  16921. * morphTargets: <bool>
  16922. * }
  16923. */
  16924. function PointsMaterial( parameters ) {
  16925. Material.call( this );
  16926. this.type = 'PointsMaterial';
  16927. this.color = new Color( 0xffffff );
  16928. this.map = null;
  16929. this.size = 1;
  16930. this.sizeAttenuation = true;
  16931. this.morphTargets = false;
  16932. this.lights = false;
  16933. this.setValues( parameters );
  16934. }
  16935. PointsMaterial.prototype = Object.create( Material.prototype );
  16936. PointsMaterial.prototype.constructor = PointsMaterial;
  16937. PointsMaterial.prototype.isPointsMaterial = true;
  16938. PointsMaterial.prototype.copy = function ( source ) {
  16939. Material.prototype.copy.call( this, source );
  16940. this.color.copy( source.color );
  16941. this.map = source.map;
  16942. this.size = source.size;
  16943. this.sizeAttenuation = source.sizeAttenuation;
  16944. this.morphTargets = source.morphTargets;
  16945. return this;
  16946. };
  16947. /**
  16948. * @author alteredq / http://alteredqualia.com/
  16949. */
  16950. function Points( geometry, material ) {
  16951. Object3D.call( this );
  16952. this.type = 'Points';
  16953. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16954. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  16955. this.updateMorphTargets();
  16956. }
  16957. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16958. constructor: Points,
  16959. isPoints: true,
  16960. raycast: ( function () {
  16961. var inverseMatrix = new Matrix4();
  16962. var ray = new Ray();
  16963. var sphere = new Sphere();
  16964. return function raycast( raycaster, intersects ) {
  16965. var object = this;
  16966. var geometry = this.geometry;
  16967. var matrixWorld = this.matrixWorld;
  16968. var threshold = raycaster.params.Points.threshold;
  16969. // Checking boundingSphere distance to ray
  16970. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  16971. sphere.copy( geometry.boundingSphere );
  16972. sphere.applyMatrix4( matrixWorld );
  16973. sphere.radius += threshold;
  16974. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  16975. //
  16976. inverseMatrix.getInverse( matrixWorld );
  16977. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  16978. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  16979. var localThresholdSq = localThreshold * localThreshold;
  16980. var position = new Vector3();
  16981. var intersectPoint = new Vector3();
  16982. function testPoint( point, index ) {
  16983. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  16984. if ( rayPointDistanceSq < localThresholdSq ) {
  16985. ray.closestPointToPoint( point, intersectPoint );
  16986. intersectPoint.applyMatrix4( matrixWorld );
  16987. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  16988. if ( distance < raycaster.near || distance > raycaster.far ) return;
  16989. intersects.push( {
  16990. distance: distance,
  16991. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  16992. point: intersectPoint.clone(),
  16993. index: index,
  16994. face: null,
  16995. object: object
  16996. } );
  16997. }
  16998. }
  16999. if ( geometry.isBufferGeometry ) {
  17000. var index = geometry.index;
  17001. var attributes = geometry.attributes;
  17002. var positions = attributes.position.array;
  17003. if ( index !== null ) {
  17004. var indices = index.array;
  17005. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  17006. var a = indices[ i ];
  17007. position.fromArray( positions, a * 3 );
  17008. testPoint( position, a );
  17009. }
  17010. } else {
  17011. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  17012. position.fromArray( positions, i * 3 );
  17013. testPoint( position, i );
  17014. }
  17015. }
  17016. } else {
  17017. var vertices = geometry.vertices;
  17018. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  17019. testPoint( vertices[ i ], i );
  17020. }
  17021. }
  17022. };
  17023. }() ),
  17024. updateMorphTargets: function () {
  17025. var geometry = this.geometry;
  17026. var m, ml, name;
  17027. if ( geometry.isBufferGeometry ) {
  17028. var morphAttributes = geometry.morphAttributes;
  17029. var keys = Object.keys( morphAttributes );
  17030. if ( keys.length > 0 ) {
  17031. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  17032. if ( morphAttribute !== undefined ) {
  17033. this.morphTargetInfluences = [];
  17034. this.morphTargetDictionary = {};
  17035. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  17036. name = morphAttribute[ m ].name || String( m );
  17037. this.morphTargetInfluences.push( 0 );
  17038. this.morphTargetDictionary[ name ] = m;
  17039. }
  17040. }
  17041. }
  17042. } else {
  17043. var morphTargets = geometry.morphTargets;
  17044. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  17045. console.error( 'THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  17046. }
  17047. }
  17048. },
  17049. clone: function () {
  17050. return new this.constructor( this.geometry, this.material ).copy( this );
  17051. }
  17052. } );
  17053. /**
  17054. * @author mrdoob / http://mrdoob.com/
  17055. */
  17056. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  17057. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  17058. this.format = format !== undefined ? format : RGBFormat;
  17059. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  17060. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  17061. this.generateMipmaps = false;
  17062. }
  17063. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  17064. constructor: VideoTexture,
  17065. isVideoTexture: true,
  17066. update: function () {
  17067. var video = this.image;
  17068. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  17069. this.needsUpdate = true;
  17070. }
  17071. }
  17072. } );
  17073. /**
  17074. * @author alteredq / http://alteredqualia.com/
  17075. */
  17076. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  17077. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  17078. this.image = { width: width, height: height };
  17079. this.mipmaps = mipmaps;
  17080. // no flipping for cube textures
  17081. // (also flipping doesn't work for compressed textures )
  17082. this.flipY = false;
  17083. // can't generate mipmaps for compressed textures
  17084. // mips must be embedded in DDS files
  17085. this.generateMipmaps = false;
  17086. }
  17087. CompressedTexture.prototype = Object.create( Texture.prototype );
  17088. CompressedTexture.prototype.constructor = CompressedTexture;
  17089. CompressedTexture.prototype.isCompressedTexture = true;
  17090. /**
  17091. * @author mrdoob / http://mrdoob.com/
  17092. */
  17093. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  17094. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  17095. this.needsUpdate = true;
  17096. }
  17097. CanvasTexture.prototype = Object.create( Texture.prototype );
  17098. CanvasTexture.prototype.constructor = CanvasTexture;
  17099. CanvasTexture.prototype.isCanvasTexture = true;
  17100. /**
  17101. * @author Matt DesLauriers / @mattdesl
  17102. * @author atix / arthursilber.de
  17103. */
  17104. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  17105. format = format !== undefined ? format : DepthFormat;
  17106. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  17107. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  17108. }
  17109. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  17110. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  17111. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  17112. this.image = { width: width, height: height };
  17113. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  17114. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  17115. this.flipY = false;
  17116. this.generateMipmaps = false;
  17117. }
  17118. DepthTexture.prototype = Object.create( Texture.prototype );
  17119. DepthTexture.prototype.constructor = DepthTexture;
  17120. DepthTexture.prototype.isDepthTexture = true;
  17121. /**
  17122. * @author mrdoob / http://mrdoob.com/
  17123. * @author Mugen87 / https://github.com/Mugen87
  17124. */
  17125. function WireframeGeometry( geometry ) {
  17126. BufferGeometry.call( this );
  17127. this.type = 'WireframeGeometry';
  17128. // buffer
  17129. var vertices = [];
  17130. // helper variables
  17131. var i, j, l, o, ol;
  17132. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  17133. var key, keys = [ 'a', 'b', 'c' ];
  17134. var vertex;
  17135. // different logic for Geometry and BufferGeometry
  17136. if ( geometry && geometry.isGeometry ) {
  17137. // create a data structure that contains all edges without duplicates
  17138. var faces = geometry.faces;
  17139. for ( i = 0, l = faces.length; i < l; i ++ ) {
  17140. var face = faces[ i ];
  17141. for ( j = 0; j < 3; j ++ ) {
  17142. edge1 = face[ keys[ j ] ];
  17143. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  17144. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  17145. edge[ 1 ] = Math.max( edge1, edge2 );
  17146. key = edge[ 0 ] + ',' + edge[ 1 ];
  17147. if ( edges[ key ] === undefined ) {
  17148. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  17149. }
  17150. }
  17151. }
  17152. // generate vertices
  17153. for ( key in edges ) {
  17154. e = edges[ key ];
  17155. vertex = geometry.vertices[ e.index1 ];
  17156. vertices.push( vertex.x, vertex.y, vertex.z );
  17157. vertex = geometry.vertices[ e.index2 ];
  17158. vertices.push( vertex.x, vertex.y, vertex.z );
  17159. }
  17160. } else if ( geometry && geometry.isBufferGeometry ) {
  17161. var position, indices, groups;
  17162. var group, start, count;
  17163. var index1, index2;
  17164. vertex = new Vector3();
  17165. if ( geometry.index !== null ) {
  17166. // indexed BufferGeometry
  17167. position = geometry.attributes.position;
  17168. indices = geometry.index;
  17169. groups = geometry.groups;
  17170. if ( groups.length === 0 ) {
  17171. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  17172. }
  17173. // create a data structure that contains all eges without duplicates
  17174. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  17175. group = groups[ o ];
  17176. start = group.start;
  17177. count = group.count;
  17178. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  17179. for ( j = 0; j < 3; j ++ ) {
  17180. edge1 = indices.getX( i + j );
  17181. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  17182. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  17183. edge[ 1 ] = Math.max( edge1, edge2 );
  17184. key = edge[ 0 ] + ',' + edge[ 1 ];
  17185. if ( edges[ key ] === undefined ) {
  17186. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  17187. }
  17188. }
  17189. }
  17190. }
  17191. // generate vertices
  17192. for ( key in edges ) {
  17193. e = edges[ key ];
  17194. vertex.fromBufferAttribute( position, e.index1 );
  17195. vertices.push( vertex.x, vertex.y, vertex.z );
  17196. vertex.fromBufferAttribute( position, e.index2 );
  17197. vertices.push( vertex.x, vertex.y, vertex.z );
  17198. }
  17199. } else {
  17200. // non-indexed BufferGeometry
  17201. position = geometry.attributes.position;
  17202. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  17203. for ( j = 0; j < 3; j ++ ) {
  17204. // three edges per triangle, an edge is represented as (index1, index2)
  17205. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  17206. index1 = 3 * i + j;
  17207. vertex.fromBufferAttribute( position, index1 );
  17208. vertices.push( vertex.x, vertex.y, vertex.z );
  17209. index2 = 3 * i + ( ( j + 1 ) % 3 );
  17210. vertex.fromBufferAttribute( position, index2 );
  17211. vertices.push( vertex.x, vertex.y, vertex.z );
  17212. }
  17213. }
  17214. }
  17215. }
  17216. // build geometry
  17217. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17218. }
  17219. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  17220. WireframeGeometry.prototype.constructor = WireframeGeometry;
  17221. /**
  17222. * @author zz85 / https://github.com/zz85
  17223. * @author Mugen87 / https://github.com/Mugen87
  17224. *
  17225. * Parametric Surfaces Geometry
  17226. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  17227. */
  17228. // ParametricGeometry
  17229. function ParametricGeometry( func, slices, stacks ) {
  17230. Geometry.call( this );
  17231. this.type = 'ParametricGeometry';
  17232. this.parameters = {
  17233. func: func,
  17234. slices: slices,
  17235. stacks: stacks
  17236. };
  17237. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  17238. this.mergeVertices();
  17239. }
  17240. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  17241. ParametricGeometry.prototype.constructor = ParametricGeometry;
  17242. // ParametricBufferGeometry
  17243. function ParametricBufferGeometry( func, slices, stacks ) {
  17244. BufferGeometry.call( this );
  17245. this.type = 'ParametricBufferGeometry';
  17246. this.parameters = {
  17247. func: func,
  17248. slices: slices,
  17249. stacks: stacks
  17250. };
  17251. // buffers
  17252. var indices = [];
  17253. var vertices = [];
  17254. var normals = [];
  17255. var uvs = [];
  17256. var EPS = 0.00001;
  17257. var normal = new Vector3();
  17258. var p0 = new Vector3(), p1 = new Vector3();
  17259. var pu = new Vector3(), pv = new Vector3();
  17260. var i, j;
  17261. if ( func.length < 3 ) {
  17262. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  17263. }
  17264. // generate vertices, normals and uvs
  17265. var sliceCount = slices + 1;
  17266. for ( i = 0; i <= stacks; i ++ ) {
  17267. var v = i / stacks;
  17268. for ( j = 0; j <= slices; j ++ ) {
  17269. var u = j / slices;
  17270. // vertex
  17271. func( u, v, p0 );
  17272. vertices.push( p0.x, p0.y, p0.z );
  17273. // normal
  17274. // approximate tangent vectors via finite differences
  17275. if ( u - EPS >= 0 ) {
  17276. func( u - EPS, v, p1 );
  17277. pu.subVectors( p0, p1 );
  17278. } else {
  17279. func( u + EPS, v, p1 );
  17280. pu.subVectors( p1, p0 );
  17281. }
  17282. if ( v - EPS >= 0 ) {
  17283. func( u, v - EPS, p1 );
  17284. pv.subVectors( p0, p1 );
  17285. } else {
  17286. func( u, v + EPS, p1 );
  17287. pv.subVectors( p1, p0 );
  17288. }
  17289. // cross product of tangent vectors returns surface normal
  17290. normal.crossVectors( pu, pv ).normalize();
  17291. normals.push( normal.x, normal.y, normal.z );
  17292. // uv
  17293. uvs.push( u, v );
  17294. }
  17295. }
  17296. // generate indices
  17297. for ( i = 0; i < stacks; i ++ ) {
  17298. for ( j = 0; j < slices; j ++ ) {
  17299. var a = i * sliceCount + j;
  17300. var b = i * sliceCount + j + 1;
  17301. var c = ( i + 1 ) * sliceCount + j + 1;
  17302. var d = ( i + 1 ) * sliceCount + j;
  17303. // faces one and two
  17304. indices.push( a, b, d );
  17305. indices.push( b, c, d );
  17306. }
  17307. }
  17308. // build geometry
  17309. this.setIndex( indices );
  17310. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17311. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17312. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17313. }
  17314. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17315. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  17316. /**
  17317. * @author clockworkgeek / https://github.com/clockworkgeek
  17318. * @author timothypratley / https://github.com/timothypratley
  17319. * @author WestLangley / http://github.com/WestLangley
  17320. * @author Mugen87 / https://github.com/Mugen87
  17321. */
  17322. // PolyhedronGeometry
  17323. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  17324. Geometry.call( this );
  17325. this.type = 'PolyhedronGeometry';
  17326. this.parameters = {
  17327. vertices: vertices,
  17328. indices: indices,
  17329. radius: radius,
  17330. detail: detail
  17331. };
  17332. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  17333. this.mergeVertices();
  17334. }
  17335. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  17336. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  17337. // PolyhedronBufferGeometry
  17338. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  17339. BufferGeometry.call( this );
  17340. this.type = 'PolyhedronBufferGeometry';
  17341. this.parameters = {
  17342. vertices: vertices,
  17343. indices: indices,
  17344. radius: radius,
  17345. detail: detail
  17346. };
  17347. radius = radius || 1;
  17348. detail = detail || 0;
  17349. // default buffer data
  17350. var vertexBuffer = [];
  17351. var uvBuffer = [];
  17352. // the subdivision creates the vertex buffer data
  17353. subdivide( detail );
  17354. // all vertices should lie on a conceptual sphere with a given radius
  17355. appplyRadius( radius );
  17356. // finally, create the uv data
  17357. generateUVs();
  17358. // build non-indexed geometry
  17359. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  17360. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  17361. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  17362. if ( detail === 0 ) {
  17363. this.computeVertexNormals(); // flat normals
  17364. } else {
  17365. this.normalizeNormals(); // smooth normals
  17366. }
  17367. // helper functions
  17368. function subdivide( detail ) {
  17369. var a = new Vector3();
  17370. var b = new Vector3();
  17371. var c = new Vector3();
  17372. // iterate over all faces and apply a subdivison with the given detail value
  17373. for ( var i = 0; i < indices.length; i += 3 ) {
  17374. // get the vertices of the face
  17375. getVertexByIndex( indices[ i + 0 ], a );
  17376. getVertexByIndex( indices[ i + 1 ], b );
  17377. getVertexByIndex( indices[ i + 2 ], c );
  17378. // perform subdivision
  17379. subdivideFace( a, b, c, detail );
  17380. }
  17381. }
  17382. function subdivideFace( a, b, c, detail ) {
  17383. var cols = Math.pow( 2, detail );
  17384. // we use this multidimensional array as a data structure for creating the subdivision
  17385. var v = [];
  17386. var i, j;
  17387. // construct all of the vertices for this subdivision
  17388. for ( i = 0; i <= cols; i ++ ) {
  17389. v[ i ] = [];
  17390. var aj = a.clone().lerp( c, i / cols );
  17391. var bj = b.clone().lerp( c, i / cols );
  17392. var rows = cols - i;
  17393. for ( j = 0; j <= rows; j ++ ) {
  17394. if ( j === 0 && i === cols ) {
  17395. v[ i ][ j ] = aj;
  17396. } else {
  17397. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  17398. }
  17399. }
  17400. }
  17401. // construct all of the faces
  17402. for ( i = 0; i < cols; i ++ ) {
  17403. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  17404. var k = Math.floor( j / 2 );
  17405. if ( j % 2 === 0 ) {
  17406. pushVertex( v[ i ][ k + 1 ] );
  17407. pushVertex( v[ i + 1 ][ k ] );
  17408. pushVertex( v[ i ][ k ] );
  17409. } else {
  17410. pushVertex( v[ i ][ k + 1 ] );
  17411. pushVertex( v[ i + 1 ][ k + 1 ] );
  17412. pushVertex( v[ i + 1 ][ k ] );
  17413. }
  17414. }
  17415. }
  17416. }
  17417. function appplyRadius( radius ) {
  17418. var vertex = new Vector3();
  17419. // iterate over the entire buffer and apply the radius to each vertex
  17420. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  17421. vertex.x = vertexBuffer[ i + 0 ];
  17422. vertex.y = vertexBuffer[ i + 1 ];
  17423. vertex.z = vertexBuffer[ i + 2 ];
  17424. vertex.normalize().multiplyScalar( radius );
  17425. vertexBuffer[ i + 0 ] = vertex.x;
  17426. vertexBuffer[ i + 1 ] = vertex.y;
  17427. vertexBuffer[ i + 2 ] = vertex.z;
  17428. }
  17429. }
  17430. function generateUVs() {
  17431. var vertex = new Vector3();
  17432. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  17433. vertex.x = vertexBuffer[ i + 0 ];
  17434. vertex.y = vertexBuffer[ i + 1 ];
  17435. vertex.z = vertexBuffer[ i + 2 ];
  17436. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  17437. var v = inclination( vertex ) / Math.PI + 0.5;
  17438. uvBuffer.push( u, 1 - v );
  17439. }
  17440. correctUVs();
  17441. correctSeam();
  17442. }
  17443. function correctSeam() {
  17444. // handle case when face straddles the seam, see #3269
  17445. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  17446. // uv data of a single face
  17447. var x0 = uvBuffer[ i + 0 ];
  17448. var x1 = uvBuffer[ i + 2 ];
  17449. var x2 = uvBuffer[ i + 4 ];
  17450. var max = Math.max( x0, x1, x2 );
  17451. var min = Math.min( x0, x1, x2 );
  17452. // 0.9 is somewhat arbitrary
  17453. if ( max > 0.9 && min < 0.1 ) {
  17454. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  17455. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  17456. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  17457. }
  17458. }
  17459. }
  17460. function pushVertex( vertex ) {
  17461. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  17462. }
  17463. function getVertexByIndex( index, vertex ) {
  17464. var stride = index * 3;
  17465. vertex.x = vertices[ stride + 0 ];
  17466. vertex.y = vertices[ stride + 1 ];
  17467. vertex.z = vertices[ stride + 2 ];
  17468. }
  17469. function correctUVs() {
  17470. var a = new Vector3();
  17471. var b = new Vector3();
  17472. var c = new Vector3();
  17473. var centroid = new Vector3();
  17474. var uvA = new Vector2();
  17475. var uvB = new Vector2();
  17476. var uvC = new Vector2();
  17477. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  17478. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  17479. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  17480. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  17481. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  17482. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  17483. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  17484. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  17485. var azi = azimuth( centroid );
  17486. correctUV( uvA, j + 0, a, azi );
  17487. correctUV( uvB, j + 2, b, azi );
  17488. correctUV( uvC, j + 4, c, azi );
  17489. }
  17490. }
  17491. function correctUV( uv, stride, vector, azimuth ) {
  17492. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  17493. uvBuffer[ stride ] = uv.x - 1;
  17494. }
  17495. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  17496. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  17497. }
  17498. }
  17499. // Angle around the Y axis, counter-clockwise when looking from above.
  17500. function azimuth( vector ) {
  17501. return Math.atan2( vector.z, - vector.x );
  17502. }
  17503. // Angle above the XZ plane.
  17504. function inclination( vector ) {
  17505. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  17506. }
  17507. }
  17508. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17509. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  17510. /**
  17511. * @author timothypratley / https://github.com/timothypratley
  17512. * @author Mugen87 / https://github.com/Mugen87
  17513. */
  17514. // TetrahedronGeometry
  17515. function TetrahedronGeometry( radius, detail ) {
  17516. Geometry.call( this );
  17517. this.type = 'TetrahedronGeometry';
  17518. this.parameters = {
  17519. radius: radius,
  17520. detail: detail
  17521. };
  17522. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  17523. this.mergeVertices();
  17524. }
  17525. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  17526. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  17527. // TetrahedronBufferGeometry
  17528. function TetrahedronBufferGeometry( radius, detail ) {
  17529. var vertices = [
  17530. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  17531. ];
  17532. var indices = [
  17533. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  17534. ];
  17535. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17536. this.type = 'TetrahedronBufferGeometry';
  17537. this.parameters = {
  17538. radius: radius,
  17539. detail: detail
  17540. };
  17541. }
  17542. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17543. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  17544. /**
  17545. * @author timothypratley / https://github.com/timothypratley
  17546. * @author Mugen87 / https://github.com/Mugen87
  17547. */
  17548. // OctahedronGeometry
  17549. function OctahedronGeometry( radius, detail ) {
  17550. Geometry.call( this );
  17551. this.type = 'OctahedronGeometry';
  17552. this.parameters = {
  17553. radius: radius,
  17554. detail: detail
  17555. };
  17556. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  17557. this.mergeVertices();
  17558. }
  17559. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  17560. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  17561. // OctahedronBufferGeometry
  17562. function OctahedronBufferGeometry( radius, detail ) {
  17563. var vertices = [
  17564. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  17565. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  17566. ];
  17567. var indices = [
  17568. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  17569. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  17570. 1, 3, 4, 1, 4, 2
  17571. ];
  17572. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17573. this.type = 'OctahedronBufferGeometry';
  17574. this.parameters = {
  17575. radius: radius,
  17576. detail: detail
  17577. };
  17578. }
  17579. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17580. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  17581. /**
  17582. * @author timothypratley / https://github.com/timothypratley
  17583. * @author Mugen87 / https://github.com/Mugen87
  17584. */
  17585. // IcosahedronGeometry
  17586. function IcosahedronGeometry( radius, detail ) {
  17587. Geometry.call( this );
  17588. this.type = 'IcosahedronGeometry';
  17589. this.parameters = {
  17590. radius: radius,
  17591. detail: detail
  17592. };
  17593. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  17594. this.mergeVertices();
  17595. }
  17596. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  17597. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  17598. // IcosahedronBufferGeometry
  17599. function IcosahedronBufferGeometry( radius, detail ) {
  17600. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  17601. var vertices = [
  17602. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  17603. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  17604. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  17605. ];
  17606. var indices = [
  17607. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  17608. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  17609. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  17610. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  17611. ];
  17612. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17613. this.type = 'IcosahedronBufferGeometry';
  17614. this.parameters = {
  17615. radius: radius,
  17616. detail: detail
  17617. };
  17618. }
  17619. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17620. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  17621. /**
  17622. * @author Abe Pazos / https://hamoid.com
  17623. * @author Mugen87 / https://github.com/Mugen87
  17624. */
  17625. // DodecahedronGeometry
  17626. function DodecahedronGeometry( radius, detail ) {
  17627. Geometry.call( this );
  17628. this.type = 'DodecahedronGeometry';
  17629. this.parameters = {
  17630. radius: radius,
  17631. detail: detail
  17632. };
  17633. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  17634. this.mergeVertices();
  17635. }
  17636. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  17637. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  17638. // DodecahedronBufferGeometry
  17639. function DodecahedronBufferGeometry( radius, detail ) {
  17640. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  17641. var r = 1 / t;
  17642. var vertices = [
  17643. // (±1, ±1, ±1)
  17644. - 1, - 1, - 1, - 1, - 1, 1,
  17645. - 1, 1, - 1, - 1, 1, 1,
  17646. 1, - 1, - 1, 1, - 1, 1,
  17647. 1, 1, - 1, 1, 1, 1,
  17648. // (0, ±1/φ, ±φ)
  17649. 0, - r, - t, 0, - r, t,
  17650. 0, r, - t, 0, r, t,
  17651. // (±1/φ, ±φ, 0)
  17652. - r, - t, 0, - r, t, 0,
  17653. r, - t, 0, r, t, 0,
  17654. // (±φ, 0, ±1/φ)
  17655. - t, 0, - r, t, 0, - r,
  17656. - t, 0, r, t, 0, r
  17657. ];
  17658. var indices = [
  17659. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  17660. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  17661. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  17662. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  17663. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  17664. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  17665. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  17666. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  17667. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  17668. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  17669. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  17670. 1, 12, 14, 1, 14, 5, 1, 5, 9
  17671. ];
  17672. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17673. this.type = 'DodecahedronBufferGeometry';
  17674. this.parameters = {
  17675. radius: radius,
  17676. detail: detail
  17677. };
  17678. }
  17679. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17680. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  17681. /**
  17682. * @author oosmoxiecode / https://github.com/oosmoxiecode
  17683. * @author WestLangley / https://github.com/WestLangley
  17684. * @author zz85 / https://github.com/zz85
  17685. * @author miningold / https://github.com/miningold
  17686. * @author jonobr1 / https://github.com/jonobr1
  17687. * @author Mugen87 / https://github.com/Mugen87
  17688. *
  17689. */
  17690. // TubeGeometry
  17691. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  17692. Geometry.call( this );
  17693. this.type = 'TubeGeometry';
  17694. this.parameters = {
  17695. path: path,
  17696. tubularSegments: tubularSegments,
  17697. radius: radius,
  17698. radialSegments: radialSegments,
  17699. closed: closed
  17700. };
  17701. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  17702. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  17703. // expose internals
  17704. this.tangents = bufferGeometry.tangents;
  17705. this.normals = bufferGeometry.normals;
  17706. this.binormals = bufferGeometry.binormals;
  17707. // create geometry
  17708. this.fromBufferGeometry( bufferGeometry );
  17709. this.mergeVertices();
  17710. }
  17711. TubeGeometry.prototype = Object.create( Geometry.prototype );
  17712. TubeGeometry.prototype.constructor = TubeGeometry;
  17713. // TubeBufferGeometry
  17714. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  17715. BufferGeometry.call( this );
  17716. this.type = 'TubeBufferGeometry';
  17717. this.parameters = {
  17718. path: path,
  17719. tubularSegments: tubularSegments,
  17720. radius: radius,
  17721. radialSegments: radialSegments,
  17722. closed: closed
  17723. };
  17724. tubularSegments = tubularSegments || 64;
  17725. radius = radius || 1;
  17726. radialSegments = radialSegments || 8;
  17727. closed = closed || false;
  17728. var frames = path.computeFrenetFrames( tubularSegments, closed );
  17729. // expose internals
  17730. this.tangents = frames.tangents;
  17731. this.normals = frames.normals;
  17732. this.binormals = frames.binormals;
  17733. // helper variables
  17734. var vertex = new Vector3();
  17735. var normal = new Vector3();
  17736. var uv = new Vector2();
  17737. var P = new Vector3();
  17738. var i, j;
  17739. // buffer
  17740. var vertices = [];
  17741. var normals = [];
  17742. var uvs = [];
  17743. var indices = [];
  17744. // create buffer data
  17745. generateBufferData();
  17746. // build geometry
  17747. this.setIndex( indices );
  17748. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17749. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17750. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17751. // functions
  17752. function generateBufferData() {
  17753. for ( i = 0; i < tubularSegments; i ++ ) {
  17754. generateSegment( i );
  17755. }
  17756. // if the geometry is not closed, generate the last row of vertices and normals
  17757. // at the regular position on the given path
  17758. //
  17759. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  17760. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  17761. // uvs are generated in a separate function.
  17762. // this makes it easy compute correct values for closed geometries
  17763. generateUVs();
  17764. // finally create faces
  17765. generateIndices();
  17766. }
  17767. function generateSegment( i ) {
  17768. // we use getPointAt to sample evenly distributed points from the given path
  17769. P = path.getPointAt( i / tubularSegments, P );
  17770. // retrieve corresponding normal and binormal
  17771. var N = frames.normals[ i ];
  17772. var B = frames.binormals[ i ];
  17773. // generate normals and vertices for the current segment
  17774. for ( j = 0; j <= radialSegments; j ++ ) {
  17775. var v = j / radialSegments * Math.PI * 2;
  17776. var sin = Math.sin( v );
  17777. var cos = - Math.cos( v );
  17778. // normal
  17779. normal.x = ( cos * N.x + sin * B.x );
  17780. normal.y = ( cos * N.y + sin * B.y );
  17781. normal.z = ( cos * N.z + sin * B.z );
  17782. normal.normalize();
  17783. normals.push( normal.x, normal.y, normal.z );
  17784. // vertex
  17785. vertex.x = P.x + radius * normal.x;
  17786. vertex.y = P.y + radius * normal.y;
  17787. vertex.z = P.z + radius * normal.z;
  17788. vertices.push( vertex.x, vertex.y, vertex.z );
  17789. }
  17790. }
  17791. function generateIndices() {
  17792. for ( j = 1; j <= tubularSegments; j ++ ) {
  17793. for ( i = 1; i <= radialSegments; i ++ ) {
  17794. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  17795. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  17796. var c = ( radialSegments + 1 ) * j + i;
  17797. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  17798. // faces
  17799. indices.push( a, b, d );
  17800. indices.push( b, c, d );
  17801. }
  17802. }
  17803. }
  17804. function generateUVs() {
  17805. for ( i = 0; i <= tubularSegments; i ++ ) {
  17806. for ( j = 0; j <= radialSegments; j ++ ) {
  17807. uv.x = i / tubularSegments;
  17808. uv.y = j / radialSegments;
  17809. uvs.push( uv.x, uv.y );
  17810. }
  17811. }
  17812. }
  17813. }
  17814. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17815. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  17816. TubeBufferGeometry.prototype.toJSON = function () {
  17817. var data = BufferGeometry.prototype.toJSON.call( this );
  17818. data.path = this.parameters.path.toJSON();
  17819. return data;
  17820. };
  17821. /**
  17822. * @author oosmoxiecode
  17823. * @author Mugen87 / https://github.com/Mugen87
  17824. *
  17825. * based on http://www.blackpawn.com/texts/pqtorus/
  17826. */
  17827. // TorusKnotGeometry
  17828. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  17829. Geometry.call( this );
  17830. this.type = 'TorusKnotGeometry';
  17831. this.parameters = {
  17832. radius: radius,
  17833. tube: tube,
  17834. tubularSegments: tubularSegments,
  17835. radialSegments: radialSegments,
  17836. p: p,
  17837. q: q
  17838. };
  17839. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  17840. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  17841. this.mergeVertices();
  17842. }
  17843. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  17844. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  17845. // TorusKnotBufferGeometry
  17846. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  17847. BufferGeometry.call( this );
  17848. this.type = 'TorusKnotBufferGeometry';
  17849. this.parameters = {
  17850. radius: radius,
  17851. tube: tube,
  17852. tubularSegments: tubularSegments,
  17853. radialSegments: radialSegments,
  17854. p: p,
  17855. q: q
  17856. };
  17857. radius = radius || 1;
  17858. tube = tube || 0.4;
  17859. tubularSegments = Math.floor( tubularSegments ) || 64;
  17860. radialSegments = Math.floor( radialSegments ) || 8;
  17861. p = p || 2;
  17862. q = q || 3;
  17863. // buffers
  17864. var indices = [];
  17865. var vertices = [];
  17866. var normals = [];
  17867. var uvs = [];
  17868. // helper variables
  17869. var i, j;
  17870. var vertex = new Vector3();
  17871. var normal = new Vector3();
  17872. var P1 = new Vector3();
  17873. var P2 = new Vector3();
  17874. var B = new Vector3();
  17875. var T = new Vector3();
  17876. var N = new Vector3();
  17877. // generate vertices, normals and uvs
  17878. for ( i = 0; i <= tubularSegments; ++ i ) {
  17879. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  17880. var u = i / tubularSegments * p * Math.PI * 2;
  17881. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  17882. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  17883. calculatePositionOnCurve( u, p, q, radius, P1 );
  17884. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  17885. // calculate orthonormal basis
  17886. T.subVectors( P2, P1 );
  17887. N.addVectors( P2, P1 );
  17888. B.crossVectors( T, N );
  17889. N.crossVectors( B, T );
  17890. // normalize B, N. T can be ignored, we don't use it
  17891. B.normalize();
  17892. N.normalize();
  17893. for ( j = 0; j <= radialSegments; ++ j ) {
  17894. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  17895. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  17896. var v = j / radialSegments * Math.PI * 2;
  17897. var cx = - tube * Math.cos( v );
  17898. var cy = tube * Math.sin( v );
  17899. // now calculate the final vertex position.
  17900. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  17901. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  17902. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  17903. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  17904. vertices.push( vertex.x, vertex.y, vertex.z );
  17905. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  17906. normal.subVectors( vertex, P1 ).normalize();
  17907. normals.push( normal.x, normal.y, normal.z );
  17908. // uv
  17909. uvs.push( i / tubularSegments );
  17910. uvs.push( j / radialSegments );
  17911. }
  17912. }
  17913. // generate indices
  17914. for ( j = 1; j <= tubularSegments; j ++ ) {
  17915. for ( i = 1; i <= radialSegments; i ++ ) {
  17916. // indices
  17917. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  17918. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  17919. var c = ( radialSegments + 1 ) * j + i;
  17920. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  17921. // faces
  17922. indices.push( a, b, d );
  17923. indices.push( b, c, d );
  17924. }
  17925. }
  17926. // build geometry
  17927. this.setIndex( indices );
  17928. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17929. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17930. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17931. // this function calculates the current position on the torus curve
  17932. function calculatePositionOnCurve( u, p, q, radius, position ) {
  17933. var cu = Math.cos( u );
  17934. var su = Math.sin( u );
  17935. var quOverP = q / p * u;
  17936. var cs = Math.cos( quOverP );
  17937. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  17938. position.y = radius * ( 2 + cs ) * su * 0.5;
  17939. position.z = radius * Math.sin( quOverP ) * 0.5;
  17940. }
  17941. }
  17942. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17943. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  17944. /**
  17945. * @author oosmoxiecode
  17946. * @author mrdoob / http://mrdoob.com/
  17947. * @author Mugen87 / https://github.com/Mugen87
  17948. */
  17949. // TorusGeometry
  17950. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  17951. Geometry.call( this );
  17952. this.type = 'TorusGeometry';
  17953. this.parameters = {
  17954. radius: radius,
  17955. tube: tube,
  17956. radialSegments: radialSegments,
  17957. tubularSegments: tubularSegments,
  17958. arc: arc
  17959. };
  17960. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  17961. this.mergeVertices();
  17962. }
  17963. TorusGeometry.prototype = Object.create( Geometry.prototype );
  17964. TorusGeometry.prototype.constructor = TorusGeometry;
  17965. // TorusBufferGeometry
  17966. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  17967. BufferGeometry.call( this );
  17968. this.type = 'TorusBufferGeometry';
  17969. this.parameters = {
  17970. radius: radius,
  17971. tube: tube,
  17972. radialSegments: radialSegments,
  17973. tubularSegments: tubularSegments,
  17974. arc: arc
  17975. };
  17976. radius = radius || 1;
  17977. tube = tube || 0.4;
  17978. radialSegments = Math.floor( radialSegments ) || 8;
  17979. tubularSegments = Math.floor( tubularSegments ) || 6;
  17980. arc = arc || Math.PI * 2;
  17981. // buffers
  17982. var indices = [];
  17983. var vertices = [];
  17984. var normals = [];
  17985. var uvs = [];
  17986. // helper variables
  17987. var center = new Vector3();
  17988. var vertex = new Vector3();
  17989. var normal = new Vector3();
  17990. var j, i;
  17991. // generate vertices, normals and uvs
  17992. for ( j = 0; j <= radialSegments; j ++ ) {
  17993. for ( i = 0; i <= tubularSegments; i ++ ) {
  17994. var u = i / tubularSegments * arc;
  17995. var v = j / radialSegments * Math.PI * 2;
  17996. // vertex
  17997. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  17998. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  17999. vertex.z = tube * Math.sin( v );
  18000. vertices.push( vertex.x, vertex.y, vertex.z );
  18001. // normal
  18002. center.x = radius * Math.cos( u );
  18003. center.y = radius * Math.sin( u );
  18004. normal.subVectors( vertex, center ).normalize();
  18005. normals.push( normal.x, normal.y, normal.z );
  18006. // uv
  18007. uvs.push( i / tubularSegments );
  18008. uvs.push( j / radialSegments );
  18009. }
  18010. }
  18011. // generate indices
  18012. for ( j = 1; j <= radialSegments; j ++ ) {
  18013. for ( i = 1; i <= tubularSegments; i ++ ) {
  18014. // indices
  18015. var a = ( tubularSegments + 1 ) * j + i - 1;
  18016. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  18017. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  18018. var d = ( tubularSegments + 1 ) * j + i;
  18019. // faces
  18020. indices.push( a, b, d );
  18021. indices.push( b, c, d );
  18022. }
  18023. }
  18024. // build geometry
  18025. this.setIndex( indices );
  18026. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18027. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18028. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18029. }
  18030. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18031. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  18032. /**
  18033. * @author Mugen87 / https://github.com/Mugen87
  18034. * Port from https://github.com/mapbox/earcut (v2.1.5)
  18035. */
  18036. var Earcut = {
  18037. triangulate: function ( data, holeIndices, dim ) {
  18038. dim = dim || 2;
  18039. var hasHoles = holeIndices && holeIndices.length,
  18040. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  18041. outerNode = linkedList( data, 0, outerLen, dim, true ),
  18042. triangles = [];
  18043. if ( ! outerNode || outerNode.next === outerNode.prev ) return triangles;
  18044. var minX, minY, maxX, maxY, x, y, invSize;
  18045. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  18046. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  18047. if ( data.length > 80 * dim ) {
  18048. minX = maxX = data[ 0 ];
  18049. minY = maxY = data[ 1 ];
  18050. for ( var i = dim; i < outerLen; i += dim ) {
  18051. x = data[ i ];
  18052. y = data[ i + 1 ];
  18053. if ( x < minX ) minX = x;
  18054. if ( y < minY ) minY = y;
  18055. if ( x > maxX ) maxX = x;
  18056. if ( y > maxY ) maxY = y;
  18057. }
  18058. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  18059. invSize = Math.max( maxX - minX, maxY - minY );
  18060. invSize = invSize !== 0 ? 1 / invSize : 0;
  18061. }
  18062. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  18063. return triangles;
  18064. }
  18065. };
  18066. // create a circular doubly linked list from polygon points in the specified winding order
  18067. function linkedList( data, start, end, dim, clockwise ) {
  18068. var i, last;
  18069. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  18070. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  18071. } else {
  18072. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  18073. }
  18074. if ( last && equals( last, last.next ) ) {
  18075. removeNode( last );
  18076. last = last.next;
  18077. }
  18078. return last;
  18079. }
  18080. // eliminate colinear or duplicate points
  18081. function filterPoints( start, end ) {
  18082. if ( ! start ) return start;
  18083. if ( ! end ) end = start;
  18084. var p = start,
  18085. again;
  18086. do {
  18087. again = false;
  18088. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  18089. removeNode( p );
  18090. p = end = p.prev;
  18091. if ( p === p.next ) break;
  18092. again = true;
  18093. } else {
  18094. p = p.next;
  18095. }
  18096. } while ( again || p !== end );
  18097. return end;
  18098. }
  18099. // main ear slicing loop which triangulates a polygon (given as a linked list)
  18100. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  18101. if ( ! ear ) return;
  18102. // interlink polygon nodes in z-order
  18103. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  18104. var stop = ear,
  18105. prev, next;
  18106. // iterate through ears, slicing them one by one
  18107. while ( ear.prev !== ear.next ) {
  18108. prev = ear.prev;
  18109. next = ear.next;
  18110. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  18111. // cut off the triangle
  18112. triangles.push( prev.i / dim );
  18113. triangles.push( ear.i / dim );
  18114. triangles.push( next.i / dim );
  18115. removeNode( ear );
  18116. // skipping the next vertex leads to less sliver triangles
  18117. ear = next.next;
  18118. stop = next.next;
  18119. continue;
  18120. }
  18121. ear = next;
  18122. // if we looped through the whole remaining polygon and can't find any more ears
  18123. if ( ear === stop ) {
  18124. // try filtering points and slicing again
  18125. if ( ! pass ) {
  18126. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  18127. // if this didn't work, try curing all small self-intersections locally
  18128. } else if ( pass === 1 ) {
  18129. ear = cureLocalIntersections( ear, triangles, dim );
  18130. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  18131. // as a last resort, try splitting the remaining polygon into two
  18132. } else if ( pass === 2 ) {
  18133. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  18134. }
  18135. break;
  18136. }
  18137. }
  18138. }
  18139. // check whether a polygon node forms a valid ear with adjacent nodes
  18140. function isEar( ear ) {
  18141. var a = ear.prev,
  18142. b = ear,
  18143. c = ear.next;
  18144. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  18145. // now make sure we don't have other points inside the potential ear
  18146. var p = ear.next.next;
  18147. while ( p !== ear.prev ) {
  18148. if ( pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  18149. area( p.prev, p, p.next ) >= 0 ) return false;
  18150. p = p.next;
  18151. }
  18152. return true;
  18153. }
  18154. function isEarHashed( ear, minX, minY, invSize ) {
  18155. var a = ear.prev,
  18156. b = ear,
  18157. c = ear.next;
  18158. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  18159. // triangle bbox; min & max are calculated like this for speed
  18160. var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  18161. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  18162. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  18163. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  18164. // z-order range for the current triangle bbox;
  18165. var minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  18166. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  18167. var p = ear.prevZ,
  18168. n = ear.nextZ;
  18169. // look for points inside the triangle in both directions
  18170. while ( p && p.z >= minZ && n && n.z <= maxZ ) {
  18171. if ( p !== ear.prev && p !== ear.next &&
  18172. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  18173. area( p.prev, p, p.next ) >= 0 ) return false;
  18174. p = p.prevZ;
  18175. if ( n !== ear.prev && n !== ear.next &&
  18176. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  18177. area( n.prev, n, n.next ) >= 0 ) return false;
  18178. n = n.nextZ;
  18179. }
  18180. // look for remaining points in decreasing z-order
  18181. while ( p && p.z >= minZ ) {
  18182. if ( p !== ear.prev && p !== ear.next &&
  18183. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  18184. area( p.prev, p, p.next ) >= 0 ) return false;
  18185. p = p.prevZ;
  18186. }
  18187. // look for remaining points in increasing z-order
  18188. while ( n && n.z <= maxZ ) {
  18189. if ( n !== ear.prev && n !== ear.next &&
  18190. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  18191. area( n.prev, n, n.next ) >= 0 ) return false;
  18192. n = n.nextZ;
  18193. }
  18194. return true;
  18195. }
  18196. // go through all polygon nodes and cure small local self-intersections
  18197. function cureLocalIntersections( start, triangles, dim ) {
  18198. var p = start;
  18199. do {
  18200. var a = p.prev,
  18201. b = p.next.next;
  18202. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  18203. triangles.push( a.i / dim );
  18204. triangles.push( p.i / dim );
  18205. triangles.push( b.i / dim );
  18206. // remove two nodes involved
  18207. removeNode( p );
  18208. removeNode( p.next );
  18209. p = start = b;
  18210. }
  18211. p = p.next;
  18212. } while ( p !== start );
  18213. return p;
  18214. }
  18215. // try splitting polygon into two and triangulate them independently
  18216. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  18217. // look for a valid diagonal that divides the polygon into two
  18218. var a = start;
  18219. do {
  18220. var b = a.next.next;
  18221. while ( b !== a.prev ) {
  18222. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  18223. // split the polygon in two by the diagonal
  18224. var c = splitPolygon( a, b );
  18225. // filter colinear points around the cuts
  18226. a = filterPoints( a, a.next );
  18227. c = filterPoints( c, c.next );
  18228. // run earcut on each half
  18229. earcutLinked( a, triangles, dim, minX, minY, invSize );
  18230. earcutLinked( c, triangles, dim, minX, minY, invSize );
  18231. return;
  18232. }
  18233. b = b.next;
  18234. }
  18235. a = a.next;
  18236. } while ( a !== start );
  18237. }
  18238. // link every hole into the outer loop, producing a single-ring polygon without holes
  18239. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  18240. var queue = [],
  18241. i, len, start, end, list;
  18242. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  18243. start = holeIndices[ i ] * dim;
  18244. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  18245. list = linkedList( data, start, end, dim, false );
  18246. if ( list === list.next ) list.steiner = true;
  18247. queue.push( getLeftmost( list ) );
  18248. }
  18249. queue.sort( compareX );
  18250. // process holes from left to right
  18251. for ( i = 0; i < queue.length; i ++ ) {
  18252. eliminateHole( queue[ i ], outerNode );
  18253. outerNode = filterPoints( outerNode, outerNode.next );
  18254. }
  18255. return outerNode;
  18256. }
  18257. function compareX( a, b ) {
  18258. return a.x - b.x;
  18259. }
  18260. // find a bridge between vertices that connects hole with an outer ring and and link it
  18261. function eliminateHole( hole, outerNode ) {
  18262. outerNode = findHoleBridge( hole, outerNode );
  18263. if ( outerNode ) {
  18264. var b = splitPolygon( outerNode, hole );
  18265. filterPoints( b, b.next );
  18266. }
  18267. }
  18268. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  18269. function findHoleBridge( hole, outerNode ) {
  18270. var p = outerNode,
  18271. hx = hole.x,
  18272. hy = hole.y,
  18273. qx = - Infinity,
  18274. m;
  18275. // find a segment intersected by a ray from the hole's leftmost point to the left;
  18276. // segment's endpoint with lesser x will be potential connection point
  18277. do {
  18278. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  18279. var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  18280. if ( x <= hx && x > qx ) {
  18281. qx = x;
  18282. if ( x === hx ) {
  18283. if ( hy === p.y ) return p;
  18284. if ( hy === p.next.y ) return p.next;
  18285. }
  18286. m = p.x < p.next.x ? p : p.next;
  18287. }
  18288. }
  18289. p = p.next;
  18290. } while ( p !== outerNode );
  18291. if ( ! m ) return null;
  18292. if ( hx === qx ) return m.prev; // hole touches outer segment; pick lower endpoint
  18293. // look for points inside the triangle of hole point, segment intersection and endpoint;
  18294. // if there are no points found, we have a valid connection;
  18295. // otherwise choose the point of the minimum angle with the ray as connection point
  18296. var stop = m,
  18297. mx = m.x,
  18298. my = m.y,
  18299. tanMin = Infinity,
  18300. tan;
  18301. p = m.next;
  18302. while ( p !== stop ) {
  18303. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  18304. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  18305. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  18306. if ( ( tan < tanMin || ( tan === tanMin && p.x > m.x ) ) && locallyInside( p, hole ) ) {
  18307. m = p;
  18308. tanMin = tan;
  18309. }
  18310. }
  18311. p = p.next;
  18312. }
  18313. return m;
  18314. }
  18315. // interlink polygon nodes in z-order
  18316. function indexCurve( start, minX, minY, invSize ) {
  18317. var p = start;
  18318. do {
  18319. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  18320. p.prevZ = p.prev;
  18321. p.nextZ = p.next;
  18322. p = p.next;
  18323. } while ( p !== start );
  18324. p.prevZ.nextZ = null;
  18325. p.prevZ = null;
  18326. sortLinked( p );
  18327. }
  18328. // Simon Tatham's linked list merge sort algorithm
  18329. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  18330. function sortLinked( list ) {
  18331. var i, p, q, e, tail, numMerges, pSize, qSize,
  18332. inSize = 1;
  18333. do {
  18334. p = list;
  18335. list = null;
  18336. tail = null;
  18337. numMerges = 0;
  18338. while ( p ) {
  18339. numMerges ++;
  18340. q = p;
  18341. pSize = 0;
  18342. for ( i = 0; i < inSize; i ++ ) {
  18343. pSize ++;
  18344. q = q.nextZ;
  18345. if ( ! q ) break;
  18346. }
  18347. qSize = inSize;
  18348. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  18349. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  18350. e = p;
  18351. p = p.nextZ;
  18352. pSize --;
  18353. } else {
  18354. e = q;
  18355. q = q.nextZ;
  18356. qSize --;
  18357. }
  18358. if ( tail ) tail.nextZ = e;
  18359. else list = e;
  18360. e.prevZ = tail;
  18361. tail = e;
  18362. }
  18363. p = q;
  18364. }
  18365. tail.nextZ = null;
  18366. inSize *= 2;
  18367. } while ( numMerges > 1 );
  18368. return list;
  18369. }
  18370. // z-order of a point given coords and inverse of the longer side of data bbox
  18371. function zOrder( x, y, minX, minY, invSize ) {
  18372. // coords are transformed into non-negative 15-bit integer range
  18373. x = 32767 * ( x - minX ) * invSize;
  18374. y = 32767 * ( y - minY ) * invSize;
  18375. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  18376. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  18377. x = ( x | ( x << 2 ) ) & 0x33333333;
  18378. x = ( x | ( x << 1 ) ) & 0x55555555;
  18379. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  18380. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  18381. y = ( y | ( y << 2 ) ) & 0x33333333;
  18382. y = ( y | ( y << 1 ) ) & 0x55555555;
  18383. return x | ( y << 1 );
  18384. }
  18385. // find the leftmost node of a polygon ring
  18386. function getLeftmost( start ) {
  18387. var p = start,
  18388. leftmost = start;
  18389. do {
  18390. if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) leftmost = p;
  18391. p = p.next;
  18392. } while ( p !== start );
  18393. return leftmost;
  18394. }
  18395. // check if a point lies within a convex triangle
  18396. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  18397. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  18398. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  18399. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  18400. }
  18401. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18402. function isValidDiagonal( a, b ) {
  18403. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) &&
  18404. locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b );
  18405. }
  18406. // signed area of a triangle
  18407. function area( p, q, r ) {
  18408. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  18409. }
  18410. // check if two points are equal
  18411. function equals( p1, p2 ) {
  18412. return p1.x === p2.x && p1.y === p2.y;
  18413. }
  18414. // check if two segments intersect
  18415. function intersects( p1, q1, p2, q2 ) {
  18416. if ( ( equals( p1, p2 ) && equals( q1, q2 ) ) ||
  18417. ( equals( p1, q2 ) && equals( p2, q1 ) ) ) return true;
  18418. return area( p1, q1, p2 ) > 0 !== area( p1, q1, q2 ) > 0 &&
  18419. area( p2, q2, p1 ) > 0 !== area( p2, q2, q1 ) > 0;
  18420. }
  18421. // check if a polygon diagonal intersects any polygon segments
  18422. function intersectsPolygon( a, b ) {
  18423. var p = a;
  18424. do {
  18425. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  18426. intersects( p, p.next, a, b ) ) return true;
  18427. p = p.next;
  18428. } while ( p !== a );
  18429. return false;
  18430. }
  18431. // check if a polygon diagonal is locally inside the polygon
  18432. function locallyInside( a, b ) {
  18433. return area( a.prev, a, a.next ) < 0 ?
  18434. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  18435. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  18436. }
  18437. // check if the middle point of a polygon diagonal is inside the polygon
  18438. function middleInside( a, b ) {
  18439. var p = a,
  18440. inside = false,
  18441. px = ( a.x + b.x ) / 2,
  18442. py = ( a.y + b.y ) / 2;
  18443. do {
  18444. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  18445. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) )
  18446. inside = ! inside;
  18447. p = p.next;
  18448. } while ( p !== a );
  18449. return inside;
  18450. }
  18451. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18452. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18453. function splitPolygon( a, b ) {
  18454. var a2 = new Node( a.i, a.x, a.y ),
  18455. b2 = new Node( b.i, b.x, b.y ),
  18456. an = a.next,
  18457. bp = b.prev;
  18458. a.next = b;
  18459. b.prev = a;
  18460. a2.next = an;
  18461. an.prev = a2;
  18462. b2.next = a2;
  18463. a2.prev = b2;
  18464. bp.next = b2;
  18465. b2.prev = bp;
  18466. return b2;
  18467. }
  18468. // create a node and optionally link it with previous one (in a circular doubly linked list)
  18469. function insertNode( i, x, y, last ) {
  18470. var p = new Node( i, x, y );
  18471. if ( ! last ) {
  18472. p.prev = p;
  18473. p.next = p;
  18474. } else {
  18475. p.next = last.next;
  18476. p.prev = last;
  18477. last.next.prev = p;
  18478. last.next = p;
  18479. }
  18480. return p;
  18481. }
  18482. function removeNode( p ) {
  18483. p.next.prev = p.prev;
  18484. p.prev.next = p.next;
  18485. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  18486. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  18487. }
  18488. function Node( i, x, y ) {
  18489. // vertex index in coordinates array
  18490. this.i = i;
  18491. // vertex coordinates
  18492. this.x = x;
  18493. this.y = y;
  18494. // previous and next vertex nodes in a polygon ring
  18495. this.prev = null;
  18496. this.next = null;
  18497. // z-order curve value
  18498. this.z = null;
  18499. // previous and next nodes in z-order
  18500. this.prevZ = null;
  18501. this.nextZ = null;
  18502. // indicates whether this is a steiner point
  18503. this.steiner = false;
  18504. }
  18505. function signedArea( data, start, end, dim ) {
  18506. var sum = 0;
  18507. for ( var i = start, j = end - dim; i < end; i += dim ) {
  18508. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  18509. j = i;
  18510. }
  18511. return sum;
  18512. }
  18513. /**
  18514. * @author zz85 / http://www.lab4games.net/zz85/blog
  18515. */
  18516. var ShapeUtils = {
  18517. // calculate area of the contour polygon
  18518. area: function ( contour ) {
  18519. var n = contour.length;
  18520. var a = 0.0;
  18521. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  18522. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  18523. }
  18524. return a * 0.5;
  18525. },
  18526. isClockWise: function ( pts ) {
  18527. return ShapeUtils.area( pts ) < 0;
  18528. },
  18529. triangulateShape: function ( contour, holes ) {
  18530. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18531. var holeIndices = []; // array of hole indices
  18532. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18533. removeDupEndPts( contour );
  18534. addContour( vertices, contour );
  18535. //
  18536. var holeIndex = contour.length;
  18537. holes.forEach( removeDupEndPts );
  18538. for ( var i = 0; i < holes.length; i ++ ) {
  18539. holeIndices.push( holeIndex );
  18540. holeIndex += holes[ i ].length;
  18541. addContour( vertices, holes[ i ] );
  18542. }
  18543. //
  18544. var triangles = Earcut.triangulate( vertices, holeIndices );
  18545. //
  18546. for ( var i = 0; i < triangles.length; i += 3 ) {
  18547. faces.push( triangles.slice( i, i + 3 ) );
  18548. }
  18549. return faces;
  18550. }
  18551. };
  18552. function removeDupEndPts( points ) {
  18553. var l = points.length;
  18554. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  18555. points.pop();
  18556. }
  18557. }
  18558. function addContour( vertices, contour ) {
  18559. for ( var i = 0; i < contour.length; i ++ ) {
  18560. vertices.push( contour[ i ].x );
  18561. vertices.push( contour[ i ].y );
  18562. }
  18563. }
  18564. /**
  18565. * @author zz85 / http://www.lab4games.net/zz85/blog
  18566. *
  18567. * Creates extruded geometry from a path shape.
  18568. *
  18569. * parameters = {
  18570. *
  18571. * curveSegments: <int>, // number of points on the curves
  18572. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  18573. * depth: <float>, // Depth to extrude the shape
  18574. *
  18575. * bevelEnabled: <bool>, // turn on bevel
  18576. * bevelThickness: <float>, // how deep into the original shape bevel goes
  18577. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  18578. * bevelOffset: <float>, // how far from shape outline does bevel start
  18579. * bevelSegments: <int>, // number of bevel layers
  18580. *
  18581. * extrudePath: <THREE.Curve> // curve to extrude shape along
  18582. *
  18583. * UVGenerator: <Object> // object that provides UV generator functions
  18584. *
  18585. * }
  18586. */
  18587. // ExtrudeGeometry
  18588. function ExtrudeGeometry( shapes, options ) {
  18589. Geometry.call( this );
  18590. this.type = 'ExtrudeGeometry';
  18591. this.parameters = {
  18592. shapes: shapes,
  18593. options: options
  18594. };
  18595. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  18596. this.mergeVertices();
  18597. }
  18598. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  18599. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  18600. ExtrudeGeometry.prototype.toJSON = function () {
  18601. var data = Geometry.prototype.toJSON.call( this );
  18602. var shapes = this.parameters.shapes;
  18603. var options = this.parameters.options;
  18604. return toJSON( shapes, options, data );
  18605. };
  18606. // ExtrudeBufferGeometry
  18607. function ExtrudeBufferGeometry( shapes, options ) {
  18608. BufferGeometry.call( this );
  18609. this.type = 'ExtrudeBufferGeometry';
  18610. this.parameters = {
  18611. shapes: shapes,
  18612. options: options
  18613. };
  18614. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  18615. var scope = this;
  18616. var verticesArray = [];
  18617. var uvArray = [];
  18618. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18619. var shape = shapes[ i ];
  18620. addShape( shape );
  18621. }
  18622. // build geometry
  18623. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  18624. this.addAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  18625. this.computeVertexNormals();
  18626. // functions
  18627. function addShape( shape ) {
  18628. var placeholder = [];
  18629. // options
  18630. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18631. var steps = options.steps !== undefined ? options.steps : 1;
  18632. var depth = options.depth !== undefined ? options.depth : 100;
  18633. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18634. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18635. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18636. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18637. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18638. var extrudePath = options.extrudePath;
  18639. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  18640. // deprecated options
  18641. if ( options.amount !== undefined ) {
  18642. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  18643. depth = options.amount;
  18644. }
  18645. //
  18646. var extrudePts, extrudeByPath = false;
  18647. var splineTube, binormal, normal, position2;
  18648. if ( extrudePath ) {
  18649. extrudePts = extrudePath.getSpacedPoints( steps );
  18650. extrudeByPath = true;
  18651. bevelEnabled = false; // bevels not supported for path extrusion
  18652. // SETUP TNB variables
  18653. // TODO1 - have a .isClosed in spline?
  18654. splineTube = extrudePath.computeFrenetFrames( steps, false );
  18655. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18656. binormal = new Vector3();
  18657. normal = new Vector3();
  18658. position2 = new Vector3();
  18659. }
  18660. // Safeguards if bevels are not enabled
  18661. if ( ! bevelEnabled ) {
  18662. bevelSegments = 0;
  18663. bevelThickness = 0;
  18664. bevelSize = 0;
  18665. bevelOffset = 0;
  18666. }
  18667. // Variables initialization
  18668. var ahole, h, hl; // looping of holes
  18669. var shapePoints = shape.extractPoints( curveSegments );
  18670. var vertices = shapePoints.shape;
  18671. var holes = shapePoints.holes;
  18672. var reverse = ! ShapeUtils.isClockWise( vertices );
  18673. if ( reverse ) {
  18674. vertices = vertices.reverse();
  18675. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18676. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18677. ahole = holes[ h ];
  18678. if ( ShapeUtils.isClockWise( ahole ) ) {
  18679. holes[ h ] = ahole.reverse();
  18680. }
  18681. }
  18682. }
  18683. var faces = ShapeUtils.triangulateShape( vertices, holes );
  18684. /* Vertices */
  18685. var contour = vertices; // vertices has all points but contour has only points of circumference
  18686. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18687. ahole = holes[ h ];
  18688. vertices = vertices.concat( ahole );
  18689. }
  18690. function scalePt2( pt, vec, size ) {
  18691. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  18692. return vec.clone().multiplyScalar( size ).add( pt );
  18693. }
  18694. var b, bs, t, z,
  18695. vert, vlen = vertices.length,
  18696. face, flen = faces.length;
  18697. // Find directions for point movement
  18698. function getBevelVec( inPt, inPrev, inNext ) {
  18699. // computes for inPt the corresponding point inPt' on a new contour
  18700. // shifted by 1 unit (length of normalized vector) to the left
  18701. // if we walk along contour clockwise, this new contour is outside the old one
  18702. //
  18703. // inPt' is the intersection of the two lines parallel to the two
  18704. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18705. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18706. // good reading for geometry algorithms (here: line-line intersection)
  18707. // http://geomalgorithms.com/a05-_intersect-1.html
  18708. var v_prev_x = inPt.x - inPrev.x,
  18709. v_prev_y = inPt.y - inPrev.y;
  18710. var v_next_x = inNext.x - inPt.x,
  18711. v_next_y = inNext.y - inPt.y;
  18712. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  18713. // check for collinear edges
  18714. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18715. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  18716. // not collinear
  18717. // length of vectors for normalizing
  18718. var v_prev_len = Math.sqrt( v_prev_lensq );
  18719. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  18720. // shift adjacent points by unit vectors to the left
  18721. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  18722. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  18723. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  18724. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  18725. // scaling factor for v_prev to intersection point
  18726. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  18727. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  18728. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18729. // vector from inPt to intersection point
  18730. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  18731. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  18732. // Don't normalize!, otherwise sharp corners become ugly
  18733. // but prevent crazy spikes
  18734. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  18735. if ( v_trans_lensq <= 2 ) {
  18736. return new Vector2( v_trans_x, v_trans_y );
  18737. } else {
  18738. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  18739. }
  18740. } else {
  18741. // handle special case of collinear edges
  18742. var direction_eq = false; // assumes: opposite
  18743. if ( v_prev_x > Number.EPSILON ) {
  18744. if ( v_next_x > Number.EPSILON ) {
  18745. direction_eq = true;
  18746. }
  18747. } else {
  18748. if ( v_prev_x < - Number.EPSILON ) {
  18749. if ( v_next_x < - Number.EPSILON ) {
  18750. direction_eq = true;
  18751. }
  18752. } else {
  18753. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  18754. direction_eq = true;
  18755. }
  18756. }
  18757. }
  18758. if ( direction_eq ) {
  18759. // console.log("Warning: lines are a straight sequence");
  18760. v_trans_x = - v_prev_y;
  18761. v_trans_y = v_prev_x;
  18762. shrink_by = Math.sqrt( v_prev_lensq );
  18763. } else {
  18764. // console.log("Warning: lines are a straight spike");
  18765. v_trans_x = v_prev_x;
  18766. v_trans_y = v_prev_y;
  18767. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  18768. }
  18769. }
  18770. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  18771. }
  18772. var contourMovements = [];
  18773. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18774. if ( j === il ) j = 0;
  18775. if ( k === il ) k = 0;
  18776. // (j)---(i)---(k)
  18777. // console.log('i,j,k', i, j , k)
  18778. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  18779. }
  18780. var holesMovements = [],
  18781. oneHoleMovements, verticesMovements = contourMovements.concat();
  18782. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18783. ahole = holes[ h ];
  18784. oneHoleMovements = [];
  18785. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18786. if ( j === il ) j = 0;
  18787. if ( k === il ) k = 0;
  18788. // (j)---(i)---(k)
  18789. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  18790. }
  18791. holesMovements.push( oneHoleMovements );
  18792. verticesMovements = verticesMovements.concat( oneHoleMovements );
  18793. }
  18794. // Loop bevelSegments, 1 for the front, 1 for the back
  18795. for ( b = 0; b < bevelSegments; b ++ ) {
  18796. //for ( b = bevelSegments; b > 0; b -- ) {
  18797. t = b / bevelSegments;
  18798. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  18799. bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  18800. // contract shape
  18801. for ( i = 0, il = contour.length; i < il; i ++ ) {
  18802. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18803. v( vert.x, vert.y, - z );
  18804. }
  18805. // expand holes
  18806. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18807. ahole = holes[ h ];
  18808. oneHoleMovements = holesMovements[ h ];
  18809. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  18810. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18811. v( vert.x, vert.y, - z );
  18812. }
  18813. }
  18814. }
  18815. bs = bevelSize + bevelOffset;
  18816. // Back facing vertices
  18817. for ( i = 0; i < vlen; i ++ ) {
  18818. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18819. if ( ! extrudeByPath ) {
  18820. v( vert.x, vert.y, 0 );
  18821. } else {
  18822. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18823. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  18824. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  18825. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  18826. v( position2.x, position2.y, position2.z );
  18827. }
  18828. }
  18829. // Add stepped vertices...
  18830. // Including front facing vertices
  18831. var s;
  18832. for ( s = 1; s <= steps; s ++ ) {
  18833. for ( i = 0; i < vlen; i ++ ) {
  18834. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18835. if ( ! extrudeByPath ) {
  18836. v( vert.x, vert.y, depth / steps * s );
  18837. } else {
  18838. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18839. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  18840. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  18841. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  18842. v( position2.x, position2.y, position2.z );
  18843. }
  18844. }
  18845. }
  18846. // Add bevel segments planes
  18847. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18848. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  18849. t = b / bevelSegments;
  18850. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  18851. bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  18852. // contract shape
  18853. for ( i = 0, il = contour.length; i < il; i ++ ) {
  18854. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18855. v( vert.x, vert.y, depth + z );
  18856. }
  18857. // expand holes
  18858. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18859. ahole = holes[ h ];
  18860. oneHoleMovements = holesMovements[ h ];
  18861. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  18862. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18863. if ( ! extrudeByPath ) {
  18864. v( vert.x, vert.y, depth + z );
  18865. } else {
  18866. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  18867. }
  18868. }
  18869. }
  18870. }
  18871. /* Faces */
  18872. // Top and bottom faces
  18873. buildLidFaces();
  18874. // Sides faces
  18875. buildSideFaces();
  18876. ///// Internal functions
  18877. function buildLidFaces() {
  18878. var start = verticesArray.length / 3;
  18879. if ( bevelEnabled ) {
  18880. var layer = 0; // steps + 1
  18881. var offset = vlen * layer;
  18882. // Bottom faces
  18883. for ( i = 0; i < flen; i ++ ) {
  18884. face = faces[ i ];
  18885. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  18886. }
  18887. layer = steps + bevelSegments * 2;
  18888. offset = vlen * layer;
  18889. // Top faces
  18890. for ( i = 0; i < flen; i ++ ) {
  18891. face = faces[ i ];
  18892. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  18893. }
  18894. } else {
  18895. // Bottom faces
  18896. for ( i = 0; i < flen; i ++ ) {
  18897. face = faces[ i ];
  18898. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  18899. }
  18900. // Top faces
  18901. for ( i = 0; i < flen; i ++ ) {
  18902. face = faces[ i ];
  18903. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  18904. }
  18905. }
  18906. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  18907. }
  18908. // Create faces for the z-sides of the shape
  18909. function buildSideFaces() {
  18910. var start = verticesArray.length / 3;
  18911. var layeroffset = 0;
  18912. sidewalls( contour, layeroffset );
  18913. layeroffset += contour.length;
  18914. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18915. ahole = holes[ h ];
  18916. sidewalls( ahole, layeroffset );
  18917. //, true
  18918. layeroffset += ahole.length;
  18919. }
  18920. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  18921. }
  18922. function sidewalls( contour, layeroffset ) {
  18923. var j, k;
  18924. i = contour.length;
  18925. while ( -- i >= 0 ) {
  18926. j = i;
  18927. k = i - 1;
  18928. if ( k < 0 ) k = contour.length - 1;
  18929. //console.log('b', i,j, i-1, k,vertices.length);
  18930. var s = 0,
  18931. sl = steps + bevelSegments * 2;
  18932. for ( s = 0; s < sl; s ++ ) {
  18933. var slen1 = vlen * s;
  18934. var slen2 = vlen * ( s + 1 );
  18935. var a = layeroffset + j + slen1,
  18936. b = layeroffset + k + slen1,
  18937. c = layeroffset + k + slen2,
  18938. d = layeroffset + j + slen2;
  18939. f4( a, b, c, d );
  18940. }
  18941. }
  18942. }
  18943. function v( x, y, z ) {
  18944. placeholder.push( x );
  18945. placeholder.push( y );
  18946. placeholder.push( z );
  18947. }
  18948. function f3( a, b, c ) {
  18949. addVertex( a );
  18950. addVertex( b );
  18951. addVertex( c );
  18952. var nextIndex = verticesArray.length / 3;
  18953. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  18954. addUV( uvs[ 0 ] );
  18955. addUV( uvs[ 1 ] );
  18956. addUV( uvs[ 2 ] );
  18957. }
  18958. function f4( a, b, c, d ) {
  18959. addVertex( a );
  18960. addVertex( b );
  18961. addVertex( d );
  18962. addVertex( b );
  18963. addVertex( c );
  18964. addVertex( d );
  18965. var nextIndex = verticesArray.length / 3;
  18966. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  18967. addUV( uvs[ 0 ] );
  18968. addUV( uvs[ 1 ] );
  18969. addUV( uvs[ 3 ] );
  18970. addUV( uvs[ 1 ] );
  18971. addUV( uvs[ 2 ] );
  18972. addUV( uvs[ 3 ] );
  18973. }
  18974. function addVertex( index ) {
  18975. verticesArray.push( placeholder[ index * 3 + 0 ] );
  18976. verticesArray.push( placeholder[ index * 3 + 1 ] );
  18977. verticesArray.push( placeholder[ index * 3 + 2 ] );
  18978. }
  18979. function addUV( vector2 ) {
  18980. uvArray.push( vector2.x );
  18981. uvArray.push( vector2.y );
  18982. }
  18983. }
  18984. }
  18985. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18986. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  18987. ExtrudeBufferGeometry.prototype.toJSON = function () {
  18988. var data = BufferGeometry.prototype.toJSON.call( this );
  18989. var shapes = this.parameters.shapes;
  18990. var options = this.parameters.options;
  18991. return toJSON( shapes, options, data );
  18992. };
  18993. //
  18994. var WorldUVGenerator = {
  18995. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  18996. var a_x = vertices[ indexA * 3 ];
  18997. var a_y = vertices[ indexA * 3 + 1 ];
  18998. var b_x = vertices[ indexB * 3 ];
  18999. var b_y = vertices[ indexB * 3 + 1 ];
  19000. var c_x = vertices[ indexC * 3 ];
  19001. var c_y = vertices[ indexC * 3 + 1 ];
  19002. return [
  19003. new Vector2( a_x, a_y ),
  19004. new Vector2( b_x, b_y ),
  19005. new Vector2( c_x, c_y )
  19006. ];
  19007. },
  19008. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  19009. var a_x = vertices[ indexA * 3 ];
  19010. var a_y = vertices[ indexA * 3 + 1 ];
  19011. var a_z = vertices[ indexA * 3 + 2 ];
  19012. var b_x = vertices[ indexB * 3 ];
  19013. var b_y = vertices[ indexB * 3 + 1 ];
  19014. var b_z = vertices[ indexB * 3 + 2 ];
  19015. var c_x = vertices[ indexC * 3 ];
  19016. var c_y = vertices[ indexC * 3 + 1 ];
  19017. var c_z = vertices[ indexC * 3 + 2 ];
  19018. var d_x = vertices[ indexD * 3 ];
  19019. var d_y = vertices[ indexD * 3 + 1 ];
  19020. var d_z = vertices[ indexD * 3 + 2 ];
  19021. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  19022. return [
  19023. new Vector2( a_x, 1 - a_z ),
  19024. new Vector2( b_x, 1 - b_z ),
  19025. new Vector2( c_x, 1 - c_z ),
  19026. new Vector2( d_x, 1 - d_z )
  19027. ];
  19028. } else {
  19029. return [
  19030. new Vector2( a_y, 1 - a_z ),
  19031. new Vector2( b_y, 1 - b_z ),
  19032. new Vector2( c_y, 1 - c_z ),
  19033. new Vector2( d_y, 1 - d_z )
  19034. ];
  19035. }
  19036. }
  19037. };
  19038. function toJSON( shapes, options, data ) {
  19039. //
  19040. data.shapes = [];
  19041. if ( Array.isArray( shapes ) ) {
  19042. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  19043. var shape = shapes[ i ];
  19044. data.shapes.push( shape.uuid );
  19045. }
  19046. } else {
  19047. data.shapes.push( shapes.uuid );
  19048. }
  19049. //
  19050. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  19051. return data;
  19052. }
  19053. /**
  19054. * @author zz85 / http://www.lab4games.net/zz85/blog
  19055. * @author alteredq / http://alteredqualia.com/
  19056. *
  19057. * Text = 3D Text
  19058. *
  19059. * parameters = {
  19060. * font: <THREE.Font>, // font
  19061. *
  19062. * size: <float>, // size of the text
  19063. * height: <float>, // thickness to extrude text
  19064. * curveSegments: <int>, // number of points on the curves
  19065. *
  19066. * bevelEnabled: <bool>, // turn on bevel
  19067. * bevelThickness: <float>, // how deep into text bevel goes
  19068. * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
  19069. * bevelOffset: <float> // how far from text outline does bevel start
  19070. * }
  19071. */
  19072. // TextGeometry
  19073. function TextGeometry( text, parameters ) {
  19074. Geometry.call( this );
  19075. this.type = 'TextGeometry';
  19076. this.parameters = {
  19077. text: text,
  19078. parameters: parameters
  19079. };
  19080. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  19081. this.mergeVertices();
  19082. }
  19083. TextGeometry.prototype = Object.create( Geometry.prototype );
  19084. TextGeometry.prototype.constructor = TextGeometry;
  19085. // TextBufferGeometry
  19086. function TextBufferGeometry( text, parameters ) {
  19087. parameters = parameters || {};
  19088. var font = parameters.font;
  19089. if ( ! ( font && font.isFont ) ) {
  19090. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  19091. return new Geometry();
  19092. }
  19093. var shapes = font.generateShapes( text, parameters.size );
  19094. // translate parameters to ExtrudeGeometry API
  19095. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  19096. // defaults
  19097. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  19098. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  19099. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  19100. ExtrudeBufferGeometry.call( this, shapes, parameters );
  19101. this.type = 'TextBufferGeometry';
  19102. }
  19103. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  19104. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  19105. /**
  19106. * @author mrdoob / http://mrdoob.com/
  19107. * @author benaadams / https://twitter.com/ben_a_adams
  19108. * @author Mugen87 / https://github.com/Mugen87
  19109. */
  19110. // SphereGeometry
  19111. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19112. Geometry.call( this );
  19113. this.type = 'SphereGeometry';
  19114. this.parameters = {
  19115. radius: radius,
  19116. widthSegments: widthSegments,
  19117. heightSegments: heightSegments,
  19118. phiStart: phiStart,
  19119. phiLength: phiLength,
  19120. thetaStart: thetaStart,
  19121. thetaLength: thetaLength
  19122. };
  19123. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  19124. this.mergeVertices();
  19125. }
  19126. SphereGeometry.prototype = Object.create( Geometry.prototype );
  19127. SphereGeometry.prototype.constructor = SphereGeometry;
  19128. // SphereBufferGeometry
  19129. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19130. BufferGeometry.call( this );
  19131. this.type = 'SphereBufferGeometry';
  19132. this.parameters = {
  19133. radius: radius,
  19134. widthSegments: widthSegments,
  19135. heightSegments: heightSegments,
  19136. phiStart: phiStart,
  19137. phiLength: phiLength,
  19138. thetaStart: thetaStart,
  19139. thetaLength: thetaLength
  19140. };
  19141. radius = radius || 1;
  19142. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  19143. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  19144. phiStart = phiStart !== undefined ? phiStart : 0;
  19145. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19146. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19147. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19148. var thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
  19149. var ix, iy;
  19150. var index = 0;
  19151. var grid = [];
  19152. var vertex = new Vector3();
  19153. var normal = new Vector3();
  19154. // buffers
  19155. var indices = [];
  19156. var vertices = [];
  19157. var normals = [];
  19158. var uvs = [];
  19159. // generate vertices, normals and uvs
  19160. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  19161. var verticesRow = [];
  19162. var v = iy / heightSegments;
  19163. // special case for the poles
  19164. var uOffset = 0;
  19165. if ( iy == 0 && thetaStart == 0 ) {
  19166. uOffset = 0.5 / widthSegments;
  19167. } else if ( iy == heightSegments && thetaEnd == Math.PI ) {
  19168. uOffset = - 0.5 / widthSegments;
  19169. }
  19170. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  19171. var u = ix / widthSegments;
  19172. // vertex
  19173. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19174. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  19175. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19176. vertices.push( vertex.x, vertex.y, vertex.z );
  19177. // normal
  19178. normal.copy( vertex ).normalize();
  19179. normals.push( normal.x, normal.y, normal.z );
  19180. // uv
  19181. uvs.push( u + uOffset, 1 - v );
  19182. verticesRow.push( index ++ );
  19183. }
  19184. grid.push( verticesRow );
  19185. }
  19186. // indices
  19187. for ( iy = 0; iy < heightSegments; iy ++ ) {
  19188. for ( ix = 0; ix < widthSegments; ix ++ ) {
  19189. var a = grid[ iy ][ ix + 1 ];
  19190. var b = grid[ iy ][ ix ];
  19191. var c = grid[ iy + 1 ][ ix ];
  19192. var d = grid[ iy + 1 ][ ix + 1 ];
  19193. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  19194. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  19195. }
  19196. }
  19197. // build geometry
  19198. this.setIndex( indices );
  19199. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19200. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19201. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19202. }
  19203. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19204. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  19205. /**
  19206. * @author Kaleb Murphy
  19207. * @author Mugen87 / https://github.com/Mugen87
  19208. */
  19209. // RingGeometry
  19210. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  19211. Geometry.call( this );
  19212. this.type = 'RingGeometry';
  19213. this.parameters = {
  19214. innerRadius: innerRadius,
  19215. outerRadius: outerRadius,
  19216. thetaSegments: thetaSegments,
  19217. phiSegments: phiSegments,
  19218. thetaStart: thetaStart,
  19219. thetaLength: thetaLength
  19220. };
  19221. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  19222. this.mergeVertices();
  19223. }
  19224. RingGeometry.prototype = Object.create( Geometry.prototype );
  19225. RingGeometry.prototype.constructor = RingGeometry;
  19226. // RingBufferGeometry
  19227. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  19228. BufferGeometry.call( this );
  19229. this.type = 'RingBufferGeometry';
  19230. this.parameters = {
  19231. innerRadius: innerRadius,
  19232. outerRadius: outerRadius,
  19233. thetaSegments: thetaSegments,
  19234. phiSegments: phiSegments,
  19235. thetaStart: thetaStart,
  19236. thetaLength: thetaLength
  19237. };
  19238. innerRadius = innerRadius || 0.5;
  19239. outerRadius = outerRadius || 1;
  19240. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19241. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19242. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  19243. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  19244. // buffers
  19245. var indices = [];
  19246. var vertices = [];
  19247. var normals = [];
  19248. var uvs = [];
  19249. // some helper variables
  19250. var segment;
  19251. var radius = innerRadius;
  19252. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  19253. var vertex = new Vector3();
  19254. var uv = new Vector2();
  19255. var j, i;
  19256. // generate vertices, normals and uvs
  19257. for ( j = 0; j <= phiSegments; j ++ ) {
  19258. for ( i = 0; i <= thetaSegments; i ++ ) {
  19259. // values are generate from the inside of the ring to the outside
  19260. segment = thetaStart + i / thetaSegments * thetaLength;
  19261. // vertex
  19262. vertex.x = radius * Math.cos( segment );
  19263. vertex.y = radius * Math.sin( segment );
  19264. vertices.push( vertex.x, vertex.y, vertex.z );
  19265. // normal
  19266. normals.push( 0, 0, 1 );
  19267. // uv
  19268. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  19269. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  19270. uvs.push( uv.x, uv.y );
  19271. }
  19272. // increase the radius for next row of vertices
  19273. radius += radiusStep;
  19274. }
  19275. // indices
  19276. for ( j = 0; j < phiSegments; j ++ ) {
  19277. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  19278. for ( i = 0; i < thetaSegments; i ++ ) {
  19279. segment = i + thetaSegmentLevel;
  19280. var a = segment;
  19281. var b = segment + thetaSegments + 1;
  19282. var c = segment + thetaSegments + 2;
  19283. var d = segment + 1;
  19284. // faces
  19285. indices.push( a, b, d );
  19286. indices.push( b, c, d );
  19287. }
  19288. }
  19289. // build geometry
  19290. this.setIndex( indices );
  19291. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19292. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19293. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19294. }
  19295. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19296. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  19297. /**
  19298. * @author zz85 / https://github.com/zz85
  19299. * @author bhouston / http://clara.io
  19300. * @author Mugen87 / https://github.com/Mugen87
  19301. */
  19302. // LatheGeometry
  19303. function LatheGeometry( points, segments, phiStart, phiLength ) {
  19304. Geometry.call( this );
  19305. this.type = 'LatheGeometry';
  19306. this.parameters = {
  19307. points: points,
  19308. segments: segments,
  19309. phiStart: phiStart,
  19310. phiLength: phiLength
  19311. };
  19312. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  19313. this.mergeVertices();
  19314. }
  19315. LatheGeometry.prototype = Object.create( Geometry.prototype );
  19316. LatheGeometry.prototype.constructor = LatheGeometry;
  19317. // LatheBufferGeometry
  19318. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  19319. BufferGeometry.call( this );
  19320. this.type = 'LatheBufferGeometry';
  19321. this.parameters = {
  19322. points: points,
  19323. segments: segments,
  19324. phiStart: phiStart,
  19325. phiLength: phiLength
  19326. };
  19327. segments = Math.floor( segments ) || 12;
  19328. phiStart = phiStart || 0;
  19329. phiLength = phiLength || Math.PI * 2;
  19330. // clamp phiLength so it's in range of [ 0, 2PI ]
  19331. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  19332. // buffers
  19333. var indices = [];
  19334. var vertices = [];
  19335. var uvs = [];
  19336. // helper variables
  19337. var base;
  19338. var inverseSegments = 1.0 / segments;
  19339. var vertex = new Vector3();
  19340. var uv = new Vector2();
  19341. var i, j;
  19342. // generate vertices and uvs
  19343. for ( i = 0; i <= segments; i ++ ) {
  19344. var phi = phiStart + i * inverseSegments * phiLength;
  19345. var sin = Math.sin( phi );
  19346. var cos = Math.cos( phi );
  19347. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  19348. // vertex
  19349. vertex.x = points[ j ].x * sin;
  19350. vertex.y = points[ j ].y;
  19351. vertex.z = points[ j ].x * cos;
  19352. vertices.push( vertex.x, vertex.y, vertex.z );
  19353. // uv
  19354. uv.x = i / segments;
  19355. uv.y = j / ( points.length - 1 );
  19356. uvs.push( uv.x, uv.y );
  19357. }
  19358. }
  19359. // indices
  19360. for ( i = 0; i < segments; i ++ ) {
  19361. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  19362. base = j + i * points.length;
  19363. var a = base;
  19364. var b = base + points.length;
  19365. var c = base + points.length + 1;
  19366. var d = base + 1;
  19367. // faces
  19368. indices.push( a, b, d );
  19369. indices.push( b, c, d );
  19370. }
  19371. }
  19372. // build geometry
  19373. this.setIndex( indices );
  19374. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19375. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19376. // generate normals
  19377. this.computeVertexNormals();
  19378. // if the geometry is closed, we need to average the normals along the seam.
  19379. // because the corresponding vertices are identical (but still have different UVs).
  19380. if ( phiLength === Math.PI * 2 ) {
  19381. var normals = this.attributes.normal.array;
  19382. var n1 = new Vector3();
  19383. var n2 = new Vector3();
  19384. var n = new Vector3();
  19385. // this is the buffer offset for the last line of vertices
  19386. base = segments * points.length * 3;
  19387. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  19388. // select the normal of the vertex in the first line
  19389. n1.x = normals[ j + 0 ];
  19390. n1.y = normals[ j + 1 ];
  19391. n1.z = normals[ j + 2 ];
  19392. // select the normal of the vertex in the last line
  19393. n2.x = normals[ base + j + 0 ];
  19394. n2.y = normals[ base + j + 1 ];
  19395. n2.z = normals[ base + j + 2 ];
  19396. // average normals
  19397. n.addVectors( n1, n2 ).normalize();
  19398. // assign the new values to both normals
  19399. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  19400. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  19401. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  19402. }
  19403. }
  19404. }
  19405. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19406. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  19407. /**
  19408. * @author jonobr1 / http://jonobr1.com
  19409. * @author Mugen87 / https://github.com/Mugen87
  19410. */
  19411. // ShapeGeometry
  19412. function ShapeGeometry( shapes, curveSegments ) {
  19413. Geometry.call( this );
  19414. this.type = 'ShapeGeometry';
  19415. if ( typeof curveSegments === 'object' ) {
  19416. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  19417. curveSegments = curveSegments.curveSegments;
  19418. }
  19419. this.parameters = {
  19420. shapes: shapes,
  19421. curveSegments: curveSegments
  19422. };
  19423. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  19424. this.mergeVertices();
  19425. }
  19426. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  19427. ShapeGeometry.prototype.constructor = ShapeGeometry;
  19428. ShapeGeometry.prototype.toJSON = function () {
  19429. var data = Geometry.prototype.toJSON.call( this );
  19430. var shapes = this.parameters.shapes;
  19431. return toJSON$1( shapes, data );
  19432. };
  19433. // ShapeBufferGeometry
  19434. function ShapeBufferGeometry( shapes, curveSegments ) {
  19435. BufferGeometry.call( this );
  19436. this.type = 'ShapeBufferGeometry';
  19437. this.parameters = {
  19438. shapes: shapes,
  19439. curveSegments: curveSegments
  19440. };
  19441. curveSegments = curveSegments || 12;
  19442. // buffers
  19443. var indices = [];
  19444. var vertices = [];
  19445. var normals = [];
  19446. var uvs = [];
  19447. // helper variables
  19448. var groupStart = 0;
  19449. var groupCount = 0;
  19450. // allow single and array values for "shapes" parameter
  19451. if ( Array.isArray( shapes ) === false ) {
  19452. addShape( shapes );
  19453. } else {
  19454. for ( var i = 0; i < shapes.length; i ++ ) {
  19455. addShape( shapes[ i ] );
  19456. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  19457. groupStart += groupCount;
  19458. groupCount = 0;
  19459. }
  19460. }
  19461. // build geometry
  19462. this.setIndex( indices );
  19463. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19464. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19465. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19466. // helper functions
  19467. function addShape( shape ) {
  19468. var i, l, shapeHole;
  19469. var indexOffset = vertices.length / 3;
  19470. var points = shape.extractPoints( curveSegments );
  19471. var shapeVertices = points.shape;
  19472. var shapeHoles = points.holes;
  19473. // check direction of vertices
  19474. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  19475. shapeVertices = shapeVertices.reverse();
  19476. }
  19477. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  19478. shapeHole = shapeHoles[ i ];
  19479. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  19480. shapeHoles[ i ] = shapeHole.reverse();
  19481. }
  19482. }
  19483. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  19484. // join vertices of inner and outer paths to a single array
  19485. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  19486. shapeHole = shapeHoles[ i ];
  19487. shapeVertices = shapeVertices.concat( shapeHole );
  19488. }
  19489. // vertices, normals, uvs
  19490. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  19491. var vertex = shapeVertices[ i ];
  19492. vertices.push( vertex.x, vertex.y, 0 );
  19493. normals.push( 0, 0, 1 );
  19494. uvs.push( vertex.x, vertex.y ); // world uvs
  19495. }
  19496. // incides
  19497. for ( i = 0, l = faces.length; i < l; i ++ ) {
  19498. var face = faces[ i ];
  19499. var a = face[ 0 ] + indexOffset;
  19500. var b = face[ 1 ] + indexOffset;
  19501. var c = face[ 2 ] + indexOffset;
  19502. indices.push( a, b, c );
  19503. groupCount += 3;
  19504. }
  19505. }
  19506. }
  19507. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19508. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  19509. ShapeBufferGeometry.prototype.toJSON = function () {
  19510. var data = BufferGeometry.prototype.toJSON.call( this );
  19511. var shapes = this.parameters.shapes;
  19512. return toJSON$1( shapes, data );
  19513. };
  19514. //
  19515. function toJSON$1( shapes, data ) {
  19516. data.shapes = [];
  19517. if ( Array.isArray( shapes ) ) {
  19518. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  19519. var shape = shapes[ i ];
  19520. data.shapes.push( shape.uuid );
  19521. }
  19522. } else {
  19523. data.shapes.push( shapes.uuid );
  19524. }
  19525. return data;
  19526. }
  19527. /**
  19528. * @author WestLangley / http://github.com/WestLangley
  19529. * @author Mugen87 / https://github.com/Mugen87
  19530. */
  19531. function EdgesGeometry( geometry, thresholdAngle ) {
  19532. BufferGeometry.call( this );
  19533. this.type = 'EdgesGeometry';
  19534. this.parameters = {
  19535. thresholdAngle: thresholdAngle
  19536. };
  19537. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  19538. // buffer
  19539. var vertices = [];
  19540. // helper variables
  19541. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  19542. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  19543. var key, keys = [ 'a', 'b', 'c' ];
  19544. // prepare source geometry
  19545. var geometry2;
  19546. if ( geometry.isBufferGeometry ) {
  19547. geometry2 = new Geometry();
  19548. geometry2.fromBufferGeometry( geometry );
  19549. } else {
  19550. geometry2 = geometry.clone();
  19551. }
  19552. geometry2.mergeVertices();
  19553. geometry2.computeFaceNormals();
  19554. var sourceVertices = geometry2.vertices;
  19555. var faces = geometry2.faces;
  19556. // now create a data structure where each entry represents an edge with its adjoining faces
  19557. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  19558. var face = faces[ i ];
  19559. for ( var j = 0; j < 3; j ++ ) {
  19560. edge1 = face[ keys[ j ] ];
  19561. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  19562. edge[ 0 ] = Math.min( edge1, edge2 );
  19563. edge[ 1 ] = Math.max( edge1, edge2 );
  19564. key = edge[ 0 ] + ',' + edge[ 1 ];
  19565. if ( edges[ key ] === undefined ) {
  19566. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  19567. } else {
  19568. edges[ key ].face2 = i;
  19569. }
  19570. }
  19571. }
  19572. // generate vertices
  19573. for ( key in edges ) {
  19574. var e = edges[ key ];
  19575. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  19576. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  19577. var vertex = sourceVertices[ e.index1 ];
  19578. vertices.push( vertex.x, vertex.y, vertex.z );
  19579. vertex = sourceVertices[ e.index2 ];
  19580. vertices.push( vertex.x, vertex.y, vertex.z );
  19581. }
  19582. }
  19583. // build geometry
  19584. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19585. }
  19586. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  19587. EdgesGeometry.prototype.constructor = EdgesGeometry;
  19588. /**
  19589. * @author mrdoob / http://mrdoob.com/
  19590. * @author Mugen87 / https://github.com/Mugen87
  19591. */
  19592. // CylinderGeometry
  19593. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19594. Geometry.call( this );
  19595. this.type = 'CylinderGeometry';
  19596. this.parameters = {
  19597. radiusTop: radiusTop,
  19598. radiusBottom: radiusBottom,
  19599. height: height,
  19600. radialSegments: radialSegments,
  19601. heightSegments: heightSegments,
  19602. openEnded: openEnded,
  19603. thetaStart: thetaStart,
  19604. thetaLength: thetaLength
  19605. };
  19606. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  19607. this.mergeVertices();
  19608. }
  19609. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  19610. CylinderGeometry.prototype.constructor = CylinderGeometry;
  19611. // CylinderBufferGeometry
  19612. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19613. BufferGeometry.call( this );
  19614. this.type = 'CylinderBufferGeometry';
  19615. this.parameters = {
  19616. radiusTop: radiusTop,
  19617. radiusBottom: radiusBottom,
  19618. height: height,
  19619. radialSegments: radialSegments,
  19620. heightSegments: heightSegments,
  19621. openEnded: openEnded,
  19622. thetaStart: thetaStart,
  19623. thetaLength: thetaLength
  19624. };
  19625. var scope = this;
  19626. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  19627. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  19628. height = height || 1;
  19629. radialSegments = Math.floor( radialSegments ) || 8;
  19630. heightSegments = Math.floor( heightSegments ) || 1;
  19631. openEnded = openEnded !== undefined ? openEnded : false;
  19632. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  19633. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19634. // buffers
  19635. var indices = [];
  19636. var vertices = [];
  19637. var normals = [];
  19638. var uvs = [];
  19639. // helper variables
  19640. var index = 0;
  19641. var indexArray = [];
  19642. var halfHeight = height / 2;
  19643. var groupStart = 0;
  19644. // generate geometry
  19645. generateTorso();
  19646. if ( openEnded === false ) {
  19647. if ( radiusTop > 0 ) generateCap( true );
  19648. if ( radiusBottom > 0 ) generateCap( false );
  19649. }
  19650. // build geometry
  19651. this.setIndex( indices );
  19652. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19653. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19654. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19655. function generateTorso() {
  19656. var x, y;
  19657. var normal = new Vector3();
  19658. var vertex = new Vector3();
  19659. var groupCount = 0;
  19660. // this will be used to calculate the normal
  19661. var slope = ( radiusBottom - radiusTop ) / height;
  19662. // generate vertices, normals and uvs
  19663. for ( y = 0; y <= heightSegments; y ++ ) {
  19664. var indexRow = [];
  19665. var v = y / heightSegments;
  19666. // calculate the radius of the current row
  19667. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  19668. for ( x = 0; x <= radialSegments; x ++ ) {
  19669. var u = x / radialSegments;
  19670. var theta = u * thetaLength + thetaStart;
  19671. var sinTheta = Math.sin( theta );
  19672. var cosTheta = Math.cos( theta );
  19673. // vertex
  19674. vertex.x = radius * sinTheta;
  19675. vertex.y = - v * height + halfHeight;
  19676. vertex.z = radius * cosTheta;
  19677. vertices.push( vertex.x, vertex.y, vertex.z );
  19678. // normal
  19679. normal.set( sinTheta, slope, cosTheta ).normalize();
  19680. normals.push( normal.x, normal.y, normal.z );
  19681. // uv
  19682. uvs.push( u, 1 - v );
  19683. // save index of vertex in respective row
  19684. indexRow.push( index ++ );
  19685. }
  19686. // now save vertices of the row in our index array
  19687. indexArray.push( indexRow );
  19688. }
  19689. // generate indices
  19690. for ( x = 0; x < radialSegments; x ++ ) {
  19691. for ( y = 0; y < heightSegments; y ++ ) {
  19692. // we use the index array to access the correct indices
  19693. var a = indexArray[ y ][ x ];
  19694. var b = indexArray[ y + 1 ][ x ];
  19695. var c = indexArray[ y + 1 ][ x + 1 ];
  19696. var d = indexArray[ y ][ x + 1 ];
  19697. // faces
  19698. indices.push( a, b, d );
  19699. indices.push( b, c, d );
  19700. // update group counter
  19701. groupCount += 6;
  19702. }
  19703. }
  19704. // add a group to the geometry. this will ensure multi material support
  19705. scope.addGroup( groupStart, groupCount, 0 );
  19706. // calculate new start value for groups
  19707. groupStart += groupCount;
  19708. }
  19709. function generateCap( top ) {
  19710. var x, centerIndexStart, centerIndexEnd;
  19711. var uv = new Vector2();
  19712. var vertex = new Vector3();
  19713. var groupCount = 0;
  19714. var radius = ( top === true ) ? radiusTop : radiusBottom;
  19715. var sign = ( top === true ) ? 1 : - 1;
  19716. // save the index of the first center vertex
  19717. centerIndexStart = index;
  19718. // first we generate the center vertex data of the cap.
  19719. // because the geometry needs one set of uvs per face,
  19720. // we must generate a center vertex per face/segment
  19721. for ( x = 1; x <= radialSegments; x ++ ) {
  19722. // vertex
  19723. vertices.push( 0, halfHeight * sign, 0 );
  19724. // normal
  19725. normals.push( 0, sign, 0 );
  19726. // uv
  19727. uvs.push( 0.5, 0.5 );
  19728. // increase index
  19729. index ++;
  19730. }
  19731. // save the index of the last center vertex
  19732. centerIndexEnd = index;
  19733. // now we generate the surrounding vertices, normals and uvs
  19734. for ( x = 0; x <= radialSegments; x ++ ) {
  19735. var u = x / radialSegments;
  19736. var theta = u * thetaLength + thetaStart;
  19737. var cosTheta = Math.cos( theta );
  19738. var sinTheta = Math.sin( theta );
  19739. // vertex
  19740. vertex.x = radius * sinTheta;
  19741. vertex.y = halfHeight * sign;
  19742. vertex.z = radius * cosTheta;
  19743. vertices.push( vertex.x, vertex.y, vertex.z );
  19744. // normal
  19745. normals.push( 0, sign, 0 );
  19746. // uv
  19747. uv.x = ( cosTheta * 0.5 ) + 0.5;
  19748. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  19749. uvs.push( uv.x, uv.y );
  19750. // increase index
  19751. index ++;
  19752. }
  19753. // generate indices
  19754. for ( x = 0; x < radialSegments; x ++ ) {
  19755. var c = centerIndexStart + x;
  19756. var i = centerIndexEnd + x;
  19757. if ( top === true ) {
  19758. // face top
  19759. indices.push( i, i + 1, c );
  19760. } else {
  19761. // face bottom
  19762. indices.push( i + 1, i, c );
  19763. }
  19764. groupCount += 3;
  19765. }
  19766. // add a group to the geometry. this will ensure multi material support
  19767. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  19768. // calculate new start value for groups
  19769. groupStart += groupCount;
  19770. }
  19771. }
  19772. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19773. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  19774. /**
  19775. * @author abelnation / http://github.com/abelnation
  19776. */
  19777. // ConeGeometry
  19778. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19779. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  19780. this.type = 'ConeGeometry';
  19781. this.parameters = {
  19782. radius: radius,
  19783. height: height,
  19784. radialSegments: radialSegments,
  19785. heightSegments: heightSegments,
  19786. openEnded: openEnded,
  19787. thetaStart: thetaStart,
  19788. thetaLength: thetaLength
  19789. };
  19790. }
  19791. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  19792. ConeGeometry.prototype.constructor = ConeGeometry;
  19793. // ConeBufferGeometry
  19794. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19795. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  19796. this.type = 'ConeBufferGeometry';
  19797. this.parameters = {
  19798. radius: radius,
  19799. height: height,
  19800. radialSegments: radialSegments,
  19801. heightSegments: heightSegments,
  19802. openEnded: openEnded,
  19803. thetaStart: thetaStart,
  19804. thetaLength: thetaLength
  19805. };
  19806. }
  19807. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  19808. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  19809. /**
  19810. * @author benaadams / https://twitter.com/ben_a_adams
  19811. * @author Mugen87 / https://github.com/Mugen87
  19812. * @author hughes
  19813. */
  19814. // CircleGeometry
  19815. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  19816. Geometry.call( this );
  19817. this.type = 'CircleGeometry';
  19818. this.parameters = {
  19819. radius: radius,
  19820. segments: segments,
  19821. thetaStart: thetaStart,
  19822. thetaLength: thetaLength
  19823. };
  19824. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  19825. this.mergeVertices();
  19826. }
  19827. CircleGeometry.prototype = Object.create( Geometry.prototype );
  19828. CircleGeometry.prototype.constructor = CircleGeometry;
  19829. // CircleBufferGeometry
  19830. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  19831. BufferGeometry.call( this );
  19832. this.type = 'CircleBufferGeometry';
  19833. this.parameters = {
  19834. radius: radius,
  19835. segments: segments,
  19836. thetaStart: thetaStart,
  19837. thetaLength: thetaLength
  19838. };
  19839. radius = radius || 1;
  19840. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  19841. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19842. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19843. // buffers
  19844. var indices = [];
  19845. var vertices = [];
  19846. var normals = [];
  19847. var uvs = [];
  19848. // helper variables
  19849. var i, s;
  19850. var vertex = new Vector3();
  19851. var uv = new Vector2();
  19852. // center point
  19853. vertices.push( 0, 0, 0 );
  19854. normals.push( 0, 0, 1 );
  19855. uvs.push( 0.5, 0.5 );
  19856. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  19857. var segment = thetaStart + s / segments * thetaLength;
  19858. // vertex
  19859. vertex.x = radius * Math.cos( segment );
  19860. vertex.y = radius * Math.sin( segment );
  19861. vertices.push( vertex.x, vertex.y, vertex.z );
  19862. // normal
  19863. normals.push( 0, 0, 1 );
  19864. // uvs
  19865. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  19866. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  19867. uvs.push( uv.x, uv.y );
  19868. }
  19869. // indices
  19870. for ( i = 1; i <= segments; i ++ ) {
  19871. indices.push( i, i + 1, 0 );
  19872. }
  19873. // build geometry
  19874. this.setIndex( indices );
  19875. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19876. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19877. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19878. }
  19879. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19880. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  19881. var Geometries = /*#__PURE__*/Object.freeze({
  19882. WireframeGeometry: WireframeGeometry,
  19883. ParametricGeometry: ParametricGeometry,
  19884. ParametricBufferGeometry: ParametricBufferGeometry,
  19885. TetrahedronGeometry: TetrahedronGeometry,
  19886. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  19887. OctahedronGeometry: OctahedronGeometry,
  19888. OctahedronBufferGeometry: OctahedronBufferGeometry,
  19889. IcosahedronGeometry: IcosahedronGeometry,
  19890. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  19891. DodecahedronGeometry: DodecahedronGeometry,
  19892. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  19893. PolyhedronGeometry: PolyhedronGeometry,
  19894. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  19895. TubeGeometry: TubeGeometry,
  19896. TubeBufferGeometry: TubeBufferGeometry,
  19897. TorusKnotGeometry: TorusKnotGeometry,
  19898. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  19899. TorusGeometry: TorusGeometry,
  19900. TorusBufferGeometry: TorusBufferGeometry,
  19901. TextGeometry: TextGeometry,
  19902. TextBufferGeometry: TextBufferGeometry,
  19903. SphereGeometry: SphereGeometry,
  19904. SphereBufferGeometry: SphereBufferGeometry,
  19905. RingGeometry: RingGeometry,
  19906. RingBufferGeometry: RingBufferGeometry,
  19907. PlaneGeometry: PlaneGeometry,
  19908. PlaneBufferGeometry: PlaneBufferGeometry,
  19909. LatheGeometry: LatheGeometry,
  19910. LatheBufferGeometry: LatheBufferGeometry,
  19911. ShapeGeometry: ShapeGeometry,
  19912. ShapeBufferGeometry: ShapeBufferGeometry,
  19913. ExtrudeGeometry: ExtrudeGeometry,
  19914. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  19915. EdgesGeometry: EdgesGeometry,
  19916. ConeGeometry: ConeGeometry,
  19917. ConeBufferGeometry: ConeBufferGeometry,
  19918. CylinderGeometry: CylinderGeometry,
  19919. CylinderBufferGeometry: CylinderBufferGeometry,
  19920. CircleGeometry: CircleGeometry,
  19921. CircleBufferGeometry: CircleBufferGeometry,
  19922. BoxGeometry: BoxGeometry,
  19923. BoxBufferGeometry: BoxBufferGeometry
  19924. });
  19925. /**
  19926. * @author mrdoob / http://mrdoob.com/
  19927. *
  19928. * parameters = {
  19929. * color: <THREE.Color>
  19930. * }
  19931. */
  19932. function ShadowMaterial( parameters ) {
  19933. Material.call( this );
  19934. this.type = 'ShadowMaterial';
  19935. this.color = new Color( 0x000000 );
  19936. this.transparent = true;
  19937. this.setValues( parameters );
  19938. }
  19939. ShadowMaterial.prototype = Object.create( Material.prototype );
  19940. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19941. ShadowMaterial.prototype.isShadowMaterial = true;
  19942. ShadowMaterial.prototype.copy = function ( source ) {
  19943. Material.prototype.copy.call( this, source );
  19944. this.color.copy( source.color );
  19945. return this;
  19946. };
  19947. /**
  19948. * @author mrdoob / http://mrdoob.com/
  19949. */
  19950. function RawShaderMaterial( parameters ) {
  19951. ShaderMaterial.call( this, parameters );
  19952. this.type = 'RawShaderMaterial';
  19953. }
  19954. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  19955. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19956. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19957. /**
  19958. * @author WestLangley / http://github.com/WestLangley
  19959. *
  19960. * parameters = {
  19961. * color: <hex>,
  19962. * roughness: <float>,
  19963. * metalness: <float>,
  19964. * opacity: <float>,
  19965. *
  19966. * map: new THREE.Texture( <Image> ),
  19967. *
  19968. * lightMap: new THREE.Texture( <Image> ),
  19969. * lightMapIntensity: <float>
  19970. *
  19971. * aoMap: new THREE.Texture( <Image> ),
  19972. * aoMapIntensity: <float>
  19973. *
  19974. * emissive: <hex>,
  19975. * emissiveIntensity: <float>
  19976. * emissiveMap: new THREE.Texture( <Image> ),
  19977. *
  19978. * bumpMap: new THREE.Texture( <Image> ),
  19979. * bumpScale: <float>,
  19980. *
  19981. * normalMap: new THREE.Texture( <Image> ),
  19982. * normalMapType: THREE.TangentSpaceNormalMap,
  19983. * normalScale: <Vector2>,
  19984. *
  19985. * displacementMap: new THREE.Texture( <Image> ),
  19986. * displacementScale: <float>,
  19987. * displacementBias: <float>,
  19988. *
  19989. * roughnessMap: new THREE.Texture( <Image> ),
  19990. *
  19991. * metalnessMap: new THREE.Texture( <Image> ),
  19992. *
  19993. * alphaMap: new THREE.Texture( <Image> ),
  19994. *
  19995. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19996. * envMapIntensity: <float>
  19997. *
  19998. * refractionRatio: <float>,
  19999. *
  20000. * wireframe: <boolean>,
  20001. * wireframeLinewidth: <float>,
  20002. *
  20003. * skinning: <bool>,
  20004. * morphTargets: <bool>,
  20005. * morphNormals: <bool>
  20006. * }
  20007. */
  20008. function MeshStandardMaterial( parameters ) {
  20009. Material.call( this );
  20010. this.defines = { 'STANDARD': '' };
  20011. this.type = 'MeshStandardMaterial';
  20012. this.color = new Color( 0xffffff ); // diffuse
  20013. this.roughness = 0.5;
  20014. this.metalness = 0.5;
  20015. this.map = null;
  20016. this.lightMap = null;
  20017. this.lightMapIntensity = 1.0;
  20018. this.aoMap = null;
  20019. this.aoMapIntensity = 1.0;
  20020. this.emissive = new Color( 0x000000 );
  20021. this.emissiveIntensity = 1.0;
  20022. this.emissiveMap = null;
  20023. this.bumpMap = null;
  20024. this.bumpScale = 1;
  20025. this.normalMap = null;
  20026. this.normalMapType = TangentSpaceNormalMap;
  20027. this.normalScale = new Vector2( 1, 1 );
  20028. this.displacementMap = null;
  20029. this.displacementScale = 1;
  20030. this.displacementBias = 0;
  20031. this.roughnessMap = null;
  20032. this.metalnessMap = null;
  20033. this.alphaMap = null;
  20034. this.envMap = null;
  20035. this.envMapIntensity = 1.0;
  20036. this.refractionRatio = 0.98;
  20037. this.wireframe = false;
  20038. this.wireframeLinewidth = 1;
  20039. this.wireframeLinecap = 'round';
  20040. this.wireframeLinejoin = 'round';
  20041. this.skinning = false;
  20042. this.morphTargets = false;
  20043. this.morphNormals = false;
  20044. this.setValues( parameters );
  20045. }
  20046. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  20047. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  20048. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  20049. MeshStandardMaterial.prototype.copy = function ( source ) {
  20050. Material.prototype.copy.call( this, source );
  20051. this.defines = { 'STANDARD': '' };
  20052. this.color.copy( source.color );
  20053. this.roughness = source.roughness;
  20054. this.metalness = source.metalness;
  20055. this.map = source.map;
  20056. this.lightMap = source.lightMap;
  20057. this.lightMapIntensity = source.lightMapIntensity;
  20058. this.aoMap = source.aoMap;
  20059. this.aoMapIntensity = source.aoMapIntensity;
  20060. this.emissive.copy( source.emissive );
  20061. this.emissiveMap = source.emissiveMap;
  20062. this.emissiveIntensity = source.emissiveIntensity;
  20063. this.bumpMap = source.bumpMap;
  20064. this.bumpScale = source.bumpScale;
  20065. this.normalMap = source.normalMap;
  20066. this.normalMapType = source.normalMapType;
  20067. this.normalScale.copy( source.normalScale );
  20068. this.displacementMap = source.displacementMap;
  20069. this.displacementScale = source.displacementScale;
  20070. this.displacementBias = source.displacementBias;
  20071. this.roughnessMap = source.roughnessMap;
  20072. this.metalnessMap = source.metalnessMap;
  20073. this.alphaMap = source.alphaMap;
  20074. this.envMap = source.envMap;
  20075. this.envMapIntensity = source.envMapIntensity;
  20076. this.refractionRatio = source.refractionRatio;
  20077. this.wireframe = source.wireframe;
  20078. this.wireframeLinewidth = source.wireframeLinewidth;
  20079. this.wireframeLinecap = source.wireframeLinecap;
  20080. this.wireframeLinejoin = source.wireframeLinejoin;
  20081. this.skinning = source.skinning;
  20082. this.morphTargets = source.morphTargets;
  20083. this.morphNormals = source.morphNormals;
  20084. return this;
  20085. };
  20086. /**
  20087. * @author WestLangley / http://github.com/WestLangley
  20088. *
  20089. * parameters = {
  20090. * reflectivity: <float>
  20091. * clearCoat: <float>
  20092. * clearCoatRoughness: <float>
  20093. * clearCoatGeometryNormals: <boolean>
  20094. * clearCoatNormalMap: new THREE.Texture( <Image> ),
  20095. * clearCoatNormalMapType: THREE.TangentSpaceNormalMap,
  20096. * clearCoatNormalScale: <Vector2>,
  20097. * }
  20098. */
  20099. function MeshPhysicalMaterial( parameters ) {
  20100. MeshStandardMaterial.call( this );
  20101. this.defines = { 'PHYSICAL': '' };
  20102. this.type = 'MeshPhysicalMaterial';
  20103. this.reflectivity = 0.5; // maps to F0 = 0.04
  20104. this.clearCoat = 0.0;
  20105. this.clearCoatRoughness = 0.0;
  20106. this.clearCoatGeometryNormals = false;
  20107. this.clearCoatNormalMap = null;
  20108. this.clearCoatNormalMapType = TangentSpaceNormalMap;
  20109. this.clearCoatNormalScale = new Vector2(1, 1);
  20110. this.setValues( parameters );
  20111. }
  20112. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  20113. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  20114. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  20115. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  20116. MeshStandardMaterial.prototype.copy.call( this, source );
  20117. this.defines = { 'PHYSICAL': '' };
  20118. this.reflectivity = source.reflectivity;
  20119. this.clearCoat = source.clearCoat;
  20120. this.clearCoatRoughness = source.clearCoatRoughness;
  20121. this.clearCoatGeometryNormals = source.clearCoatGeometryNormals;
  20122. this.clearCoatNormalMap = source.clearCoatNormalMap;
  20123. this.clearCoatNormalMapType = source.clearCoatNormalMapType;
  20124. this.clearCoatNormalScale.copy(source.clearCoatNormalScale);
  20125. return this;
  20126. };
  20127. /**
  20128. * @author mrdoob / http://mrdoob.com/
  20129. * @author alteredq / http://alteredqualia.com/
  20130. *
  20131. * parameters = {
  20132. * color: <hex>,
  20133. * specular: <hex>,
  20134. * shininess: <float>,
  20135. * opacity: <float>,
  20136. *
  20137. * map: new THREE.Texture( <Image> ),
  20138. *
  20139. * lightMap: new THREE.Texture( <Image> ),
  20140. * lightMapIntensity: <float>
  20141. *
  20142. * aoMap: new THREE.Texture( <Image> ),
  20143. * aoMapIntensity: <float>
  20144. *
  20145. * emissive: <hex>,
  20146. * emissiveIntensity: <float>
  20147. * emissiveMap: new THREE.Texture( <Image> ),
  20148. *
  20149. * bumpMap: new THREE.Texture( <Image> ),
  20150. * bumpScale: <float>,
  20151. *
  20152. * normalMap: new THREE.Texture( <Image> ),
  20153. * normalMapType: THREE.TangentSpaceNormalMap,
  20154. * normalScale: <Vector2>,
  20155. *
  20156. * displacementMap: new THREE.Texture( <Image> ),
  20157. * displacementScale: <float>,
  20158. * displacementBias: <float>,
  20159. *
  20160. * specularMap: new THREE.Texture( <Image> ),
  20161. *
  20162. * alphaMap: new THREE.Texture( <Image> ),
  20163. *
  20164. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20165. * combine: THREE.Multiply,
  20166. * reflectivity: <float>,
  20167. * refractionRatio: <float>,
  20168. *
  20169. * wireframe: <boolean>,
  20170. * wireframeLinewidth: <float>,
  20171. *
  20172. * skinning: <bool>,
  20173. * morphTargets: <bool>,
  20174. * morphNormals: <bool>
  20175. * }
  20176. */
  20177. function MeshPhongMaterial( parameters ) {
  20178. Material.call( this );
  20179. this.type = 'MeshPhongMaterial';
  20180. this.color = new Color( 0xffffff ); // diffuse
  20181. this.specular = new Color( 0x111111 );
  20182. this.shininess = 30;
  20183. this.map = null;
  20184. this.lightMap = null;
  20185. this.lightMapIntensity = 1.0;
  20186. this.aoMap = null;
  20187. this.aoMapIntensity = 1.0;
  20188. this.emissive = new Color( 0x000000 );
  20189. this.emissiveIntensity = 1.0;
  20190. this.emissiveMap = null;
  20191. this.bumpMap = null;
  20192. this.bumpScale = 1;
  20193. this.normalMap = null;
  20194. this.normalMapType = TangentSpaceNormalMap;
  20195. this.normalScale = new Vector2( 1, 1 );
  20196. this.displacementMap = null;
  20197. this.displacementScale = 1;
  20198. this.displacementBias = 0;
  20199. this.specularMap = null;
  20200. this.alphaMap = null;
  20201. this.envMap = null;
  20202. this.combine = MultiplyOperation;
  20203. this.reflectivity = 1;
  20204. this.refractionRatio = 0.98;
  20205. this.wireframe = false;
  20206. this.wireframeLinewidth = 1;
  20207. this.wireframeLinecap = 'round';
  20208. this.wireframeLinejoin = 'round';
  20209. this.skinning = false;
  20210. this.morphTargets = false;
  20211. this.morphNormals = false;
  20212. this.setValues( parameters );
  20213. }
  20214. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  20215. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  20216. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  20217. MeshPhongMaterial.prototype.copy = function ( source ) {
  20218. Material.prototype.copy.call( this, source );
  20219. this.color.copy( source.color );
  20220. this.specular.copy( source.specular );
  20221. this.shininess = source.shininess;
  20222. this.map = source.map;
  20223. this.lightMap = source.lightMap;
  20224. this.lightMapIntensity = source.lightMapIntensity;
  20225. this.aoMap = source.aoMap;
  20226. this.aoMapIntensity = source.aoMapIntensity;
  20227. this.emissive.copy( source.emissive );
  20228. this.emissiveMap = source.emissiveMap;
  20229. this.emissiveIntensity = source.emissiveIntensity;
  20230. this.bumpMap = source.bumpMap;
  20231. this.bumpScale = source.bumpScale;
  20232. this.normalMap = source.normalMap;
  20233. this.normalMapType = source.normalMapType;
  20234. this.normalScale.copy( source.normalScale );
  20235. this.displacementMap = source.displacementMap;
  20236. this.displacementScale = source.displacementScale;
  20237. this.displacementBias = source.displacementBias;
  20238. this.specularMap = source.specularMap;
  20239. this.alphaMap = source.alphaMap;
  20240. this.envMap = source.envMap;
  20241. this.combine = source.combine;
  20242. this.reflectivity = source.reflectivity;
  20243. this.refractionRatio = source.refractionRatio;
  20244. this.wireframe = source.wireframe;
  20245. this.wireframeLinewidth = source.wireframeLinewidth;
  20246. this.wireframeLinecap = source.wireframeLinecap;
  20247. this.wireframeLinejoin = source.wireframeLinejoin;
  20248. this.skinning = source.skinning;
  20249. this.morphTargets = source.morphTargets;
  20250. this.morphNormals = source.morphNormals;
  20251. return this;
  20252. };
  20253. /**
  20254. * @author takahirox / http://github.com/takahirox
  20255. *
  20256. * parameters = {
  20257. * gradientMap: new THREE.Texture( <Image> )
  20258. * }
  20259. */
  20260. function MeshToonMaterial( parameters ) {
  20261. MeshPhongMaterial.call( this );
  20262. this.defines = { 'TOON': '' };
  20263. this.type = 'MeshToonMaterial';
  20264. this.gradientMap = null;
  20265. this.setValues( parameters );
  20266. }
  20267. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  20268. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  20269. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  20270. MeshToonMaterial.prototype.copy = function ( source ) {
  20271. MeshPhongMaterial.prototype.copy.call( this, source );
  20272. this.gradientMap = source.gradientMap;
  20273. return this;
  20274. };
  20275. /**
  20276. * @author mrdoob / http://mrdoob.com/
  20277. * @author WestLangley / http://github.com/WestLangley
  20278. *
  20279. * parameters = {
  20280. * opacity: <float>,
  20281. *
  20282. * bumpMap: new THREE.Texture( <Image> ),
  20283. * bumpScale: <float>,
  20284. *
  20285. * normalMap: new THREE.Texture( <Image> ),
  20286. * normalMapType: THREE.TangentSpaceNormalMap,
  20287. * normalScale: <Vector2>,
  20288. *
  20289. * displacementMap: new THREE.Texture( <Image> ),
  20290. * displacementScale: <float>,
  20291. * displacementBias: <float>,
  20292. *
  20293. * wireframe: <boolean>,
  20294. * wireframeLinewidth: <float>
  20295. *
  20296. * skinning: <bool>,
  20297. * morphTargets: <bool>,
  20298. * morphNormals: <bool>
  20299. * }
  20300. */
  20301. function MeshNormalMaterial( parameters ) {
  20302. Material.call( this );
  20303. this.type = 'MeshNormalMaterial';
  20304. this.bumpMap = null;
  20305. this.bumpScale = 1;
  20306. this.normalMap = null;
  20307. this.normalMapType = TangentSpaceNormalMap;
  20308. this.normalScale = new Vector2( 1, 1 );
  20309. this.displacementMap = null;
  20310. this.displacementScale = 1;
  20311. this.displacementBias = 0;
  20312. this.wireframe = false;
  20313. this.wireframeLinewidth = 1;
  20314. this.fog = false;
  20315. this.lights = false;
  20316. this.skinning = false;
  20317. this.morphTargets = false;
  20318. this.morphNormals = false;
  20319. this.setValues( parameters );
  20320. }
  20321. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  20322. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  20323. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20324. MeshNormalMaterial.prototype.copy = function ( source ) {
  20325. Material.prototype.copy.call( this, source );
  20326. this.bumpMap = source.bumpMap;
  20327. this.bumpScale = source.bumpScale;
  20328. this.normalMap = source.normalMap;
  20329. this.normalMapType = source.normalMapType;
  20330. this.normalScale.copy( source.normalScale );
  20331. this.displacementMap = source.displacementMap;
  20332. this.displacementScale = source.displacementScale;
  20333. this.displacementBias = source.displacementBias;
  20334. this.wireframe = source.wireframe;
  20335. this.wireframeLinewidth = source.wireframeLinewidth;
  20336. this.skinning = source.skinning;
  20337. this.morphTargets = source.morphTargets;
  20338. this.morphNormals = source.morphNormals;
  20339. return this;
  20340. };
  20341. /**
  20342. * @author mrdoob / http://mrdoob.com/
  20343. * @author alteredq / http://alteredqualia.com/
  20344. *
  20345. * parameters = {
  20346. * color: <hex>,
  20347. * opacity: <float>,
  20348. *
  20349. * map: new THREE.Texture( <Image> ),
  20350. *
  20351. * lightMap: new THREE.Texture( <Image> ),
  20352. * lightMapIntensity: <float>
  20353. *
  20354. * aoMap: new THREE.Texture( <Image> ),
  20355. * aoMapIntensity: <float>
  20356. *
  20357. * emissive: <hex>,
  20358. * emissiveIntensity: <float>
  20359. * emissiveMap: new THREE.Texture( <Image> ),
  20360. *
  20361. * specularMap: new THREE.Texture( <Image> ),
  20362. *
  20363. * alphaMap: new THREE.Texture( <Image> ),
  20364. *
  20365. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20366. * combine: THREE.Multiply,
  20367. * reflectivity: <float>,
  20368. * refractionRatio: <float>,
  20369. *
  20370. * wireframe: <boolean>,
  20371. * wireframeLinewidth: <float>,
  20372. *
  20373. * skinning: <bool>,
  20374. * morphTargets: <bool>,
  20375. * morphNormals: <bool>
  20376. * }
  20377. */
  20378. function MeshLambertMaterial( parameters ) {
  20379. Material.call( this );
  20380. this.type = 'MeshLambertMaterial';
  20381. this.color = new Color( 0xffffff ); // diffuse
  20382. this.map = null;
  20383. this.lightMap = null;
  20384. this.lightMapIntensity = 1.0;
  20385. this.aoMap = null;
  20386. this.aoMapIntensity = 1.0;
  20387. this.emissive = new Color( 0x000000 );
  20388. this.emissiveIntensity = 1.0;
  20389. this.emissiveMap = null;
  20390. this.specularMap = null;
  20391. this.alphaMap = null;
  20392. this.envMap = null;
  20393. this.combine = MultiplyOperation;
  20394. this.reflectivity = 1;
  20395. this.refractionRatio = 0.98;
  20396. this.wireframe = false;
  20397. this.wireframeLinewidth = 1;
  20398. this.wireframeLinecap = 'round';
  20399. this.wireframeLinejoin = 'round';
  20400. this.skinning = false;
  20401. this.morphTargets = false;
  20402. this.morphNormals = false;
  20403. this.setValues( parameters );
  20404. }
  20405. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  20406. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20407. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20408. MeshLambertMaterial.prototype.copy = function ( source ) {
  20409. Material.prototype.copy.call( this, source );
  20410. this.color.copy( source.color );
  20411. this.map = source.map;
  20412. this.lightMap = source.lightMap;
  20413. this.lightMapIntensity = source.lightMapIntensity;
  20414. this.aoMap = source.aoMap;
  20415. this.aoMapIntensity = source.aoMapIntensity;
  20416. this.emissive.copy( source.emissive );
  20417. this.emissiveMap = source.emissiveMap;
  20418. this.emissiveIntensity = source.emissiveIntensity;
  20419. this.specularMap = source.specularMap;
  20420. this.alphaMap = source.alphaMap;
  20421. this.envMap = source.envMap;
  20422. this.combine = source.combine;
  20423. this.reflectivity = source.reflectivity;
  20424. this.refractionRatio = source.refractionRatio;
  20425. this.wireframe = source.wireframe;
  20426. this.wireframeLinewidth = source.wireframeLinewidth;
  20427. this.wireframeLinecap = source.wireframeLinecap;
  20428. this.wireframeLinejoin = source.wireframeLinejoin;
  20429. this.skinning = source.skinning;
  20430. this.morphTargets = source.morphTargets;
  20431. this.morphNormals = source.morphNormals;
  20432. return this;
  20433. };
  20434. /**
  20435. * @author WestLangley / http://github.com/WestLangley
  20436. *
  20437. * parameters = {
  20438. * color: <hex>,
  20439. * opacity: <float>,
  20440. *
  20441. * matcap: new THREE.Texture( <Image> ),
  20442. *
  20443. * map: new THREE.Texture( <Image> ),
  20444. *
  20445. * bumpMap: new THREE.Texture( <Image> ),
  20446. * bumpScale: <float>,
  20447. *
  20448. * normalMap: new THREE.Texture( <Image> ),
  20449. * normalMapType: THREE.TangentSpaceNormalMap,
  20450. * normalScale: <Vector2>,
  20451. *
  20452. * displacementMap: new THREE.Texture( <Image> ),
  20453. * displacementScale: <float>,
  20454. * displacementBias: <float>,
  20455. *
  20456. * alphaMap: new THREE.Texture( <Image> ),
  20457. *
  20458. * skinning: <bool>,
  20459. * morphTargets: <bool>,
  20460. * morphNormals: <bool>
  20461. * }
  20462. */
  20463. function MeshMatcapMaterial( parameters ) {
  20464. Material.call( this );
  20465. this.defines = { 'MATCAP': '' };
  20466. this.type = 'MeshMatcapMaterial';
  20467. this.color = new Color( 0xffffff ); // diffuse
  20468. this.matcap = null;
  20469. this.map = null;
  20470. this.bumpMap = null;
  20471. this.bumpScale = 1;
  20472. this.normalMap = null;
  20473. this.normalMapType = TangentSpaceNormalMap;
  20474. this.normalScale = new Vector2( 1, 1 );
  20475. this.displacementMap = null;
  20476. this.displacementScale = 1;
  20477. this.displacementBias = 0;
  20478. this.alphaMap = null;
  20479. this.skinning = false;
  20480. this.morphTargets = false;
  20481. this.morphNormals = false;
  20482. this.lights = false;
  20483. this.setValues( parameters );
  20484. }
  20485. MeshMatcapMaterial.prototype = Object.create( Material.prototype );
  20486. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20487. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20488. MeshMatcapMaterial.prototype.copy = function ( source ) {
  20489. Material.prototype.copy.call( this, source );
  20490. this.defines = { 'MATCAP': '' };
  20491. this.color.copy( source.color );
  20492. this.matcap = source.matcap;
  20493. this.map = source.map;
  20494. this.bumpMap = source.bumpMap;
  20495. this.bumpScale = source.bumpScale;
  20496. this.normalMap = source.normalMap;
  20497. this.normalMapType = source.normalMapType;
  20498. this.normalScale.copy( source.normalScale );
  20499. this.displacementMap = source.displacementMap;
  20500. this.displacementScale = source.displacementScale;
  20501. this.displacementBias = source.displacementBias;
  20502. this.alphaMap = source.alphaMap;
  20503. this.skinning = source.skinning;
  20504. this.morphTargets = source.morphTargets;
  20505. this.morphNormals = source.morphNormals;
  20506. return this;
  20507. };
  20508. /**
  20509. * @author alteredq / http://alteredqualia.com/
  20510. *
  20511. * parameters = {
  20512. * color: <hex>,
  20513. * opacity: <float>,
  20514. *
  20515. * linewidth: <float>,
  20516. *
  20517. * scale: <float>,
  20518. * dashSize: <float>,
  20519. * gapSize: <float>
  20520. * }
  20521. */
  20522. function LineDashedMaterial( parameters ) {
  20523. LineBasicMaterial.call( this );
  20524. this.type = 'LineDashedMaterial';
  20525. this.scale = 1;
  20526. this.dashSize = 3;
  20527. this.gapSize = 1;
  20528. this.setValues( parameters );
  20529. }
  20530. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  20531. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20532. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20533. LineDashedMaterial.prototype.copy = function ( source ) {
  20534. LineBasicMaterial.prototype.copy.call( this, source );
  20535. this.scale = source.scale;
  20536. this.dashSize = source.dashSize;
  20537. this.gapSize = source.gapSize;
  20538. return this;
  20539. };
  20540. var Materials = /*#__PURE__*/Object.freeze({
  20541. ShadowMaterial: ShadowMaterial,
  20542. SpriteMaterial: SpriteMaterial,
  20543. RawShaderMaterial: RawShaderMaterial,
  20544. ShaderMaterial: ShaderMaterial,
  20545. PointsMaterial: PointsMaterial,
  20546. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20547. MeshStandardMaterial: MeshStandardMaterial,
  20548. MeshPhongMaterial: MeshPhongMaterial,
  20549. MeshToonMaterial: MeshToonMaterial,
  20550. MeshNormalMaterial: MeshNormalMaterial,
  20551. MeshLambertMaterial: MeshLambertMaterial,
  20552. MeshDepthMaterial: MeshDepthMaterial,
  20553. MeshDistanceMaterial: MeshDistanceMaterial,
  20554. MeshBasicMaterial: MeshBasicMaterial,
  20555. MeshMatcapMaterial: MeshMatcapMaterial,
  20556. LineDashedMaterial: LineDashedMaterial,
  20557. LineBasicMaterial: LineBasicMaterial,
  20558. Material: Material
  20559. });
  20560. /**
  20561. * @author tschw
  20562. * @author Ben Houston / http://clara.io/
  20563. * @author David Sarno / http://lighthaus.us/
  20564. */
  20565. var AnimationUtils = {
  20566. // same as Array.prototype.slice, but also works on typed arrays
  20567. arraySlice: function ( array, from, to ) {
  20568. if ( AnimationUtils.isTypedArray( array ) ) {
  20569. // in ios9 array.subarray(from, undefined) will return empty array
  20570. // but array.subarray(from) or array.subarray(from, len) is correct
  20571. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  20572. }
  20573. return array.slice( from, to );
  20574. },
  20575. // converts an array to a specific type
  20576. convertArray: function ( array, type, forceClone ) {
  20577. if ( ! array || // let 'undefined' and 'null' pass
  20578. ! forceClone && array.constructor === type ) return array;
  20579. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  20580. return new type( array ); // create typed array
  20581. }
  20582. return Array.prototype.slice.call( array ); // create Array
  20583. },
  20584. isTypedArray: function ( object ) {
  20585. return ArrayBuffer.isView( object ) &&
  20586. ! ( object instanceof DataView );
  20587. },
  20588. // returns an array by which times and values can be sorted
  20589. getKeyframeOrder: function ( times ) {
  20590. function compareTime( i, j ) {
  20591. return times[ i ] - times[ j ];
  20592. }
  20593. var n = times.length;
  20594. var result = new Array( n );
  20595. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  20596. result.sort( compareTime );
  20597. return result;
  20598. },
  20599. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20600. sortedArray: function ( values, stride, order ) {
  20601. var nValues = values.length;
  20602. var result = new values.constructor( nValues );
  20603. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  20604. var srcOffset = order[ i ] * stride;
  20605. for ( var j = 0; j !== stride; ++ j ) {
  20606. result[ dstOffset ++ ] = values[ srcOffset + j ];
  20607. }
  20608. }
  20609. return result;
  20610. },
  20611. // function for parsing AOS keyframe formats
  20612. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  20613. var i = 1, key = jsonKeys[ 0 ];
  20614. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  20615. key = jsonKeys[ i ++ ];
  20616. }
  20617. if ( key === undefined ) return; // no data
  20618. var value = key[ valuePropertyName ];
  20619. if ( value === undefined ) return; // no data
  20620. if ( Array.isArray( value ) ) {
  20621. do {
  20622. value = key[ valuePropertyName ];
  20623. if ( value !== undefined ) {
  20624. times.push( key.time );
  20625. values.push.apply( values, value ); // push all elements
  20626. }
  20627. key = jsonKeys[ i ++ ];
  20628. } while ( key !== undefined );
  20629. } else if ( value.toArray !== undefined ) {
  20630. // ...assume THREE.Math-ish
  20631. do {
  20632. value = key[ valuePropertyName ];
  20633. if ( value !== undefined ) {
  20634. times.push( key.time );
  20635. value.toArray( values, values.length );
  20636. }
  20637. key = jsonKeys[ i ++ ];
  20638. } while ( key !== undefined );
  20639. } else {
  20640. // otherwise push as-is
  20641. do {
  20642. value = key[ valuePropertyName ];
  20643. if ( value !== undefined ) {
  20644. times.push( key.time );
  20645. values.push( value );
  20646. }
  20647. key = jsonKeys[ i ++ ];
  20648. } while ( key !== undefined );
  20649. }
  20650. }
  20651. };
  20652. /**
  20653. * Abstract base class of interpolants over parametric samples.
  20654. *
  20655. * The parameter domain is one dimensional, typically the time or a path
  20656. * along a curve defined by the data.
  20657. *
  20658. * The sample values can have any dimensionality and derived classes may
  20659. * apply special interpretations to the data.
  20660. *
  20661. * This class provides the interval seek in a Template Method, deferring
  20662. * the actual interpolation to derived classes.
  20663. *
  20664. * Time complexity is O(1) for linear access crossing at most two points
  20665. * and O(log N) for random access, where N is the number of positions.
  20666. *
  20667. * References:
  20668. *
  20669. * http://www.oodesign.com/template-method-pattern.html
  20670. *
  20671. * @author tschw
  20672. */
  20673. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20674. this.parameterPositions = parameterPositions;
  20675. this._cachedIndex = 0;
  20676. this.resultBuffer = resultBuffer !== undefined ?
  20677. resultBuffer : new sampleValues.constructor( sampleSize );
  20678. this.sampleValues = sampleValues;
  20679. this.valueSize = sampleSize;
  20680. }
  20681. Object.assign( Interpolant.prototype, {
  20682. evaluate: function ( t ) {
  20683. var pp = this.parameterPositions,
  20684. i1 = this._cachedIndex,
  20685. t1 = pp[ i1 ],
  20686. t0 = pp[ i1 - 1 ];
  20687. validate_interval: {
  20688. seek: {
  20689. var right;
  20690. linear_scan: {
  20691. //- See http://jsperf.com/comparison-to-undefined/3
  20692. //- slower code:
  20693. //-
  20694. //- if ( t >= t1 || t1 === undefined ) {
  20695. forward_scan: if ( ! ( t < t1 ) ) {
  20696. for ( var giveUpAt = i1 + 2; ; ) {
  20697. if ( t1 === undefined ) {
  20698. if ( t < t0 ) break forward_scan;
  20699. // after end
  20700. i1 = pp.length;
  20701. this._cachedIndex = i1;
  20702. return this.afterEnd_( i1 - 1, t, t0 );
  20703. }
  20704. if ( i1 === giveUpAt ) break; // this loop
  20705. t0 = t1;
  20706. t1 = pp[ ++ i1 ];
  20707. if ( t < t1 ) {
  20708. // we have arrived at the sought interval
  20709. break seek;
  20710. }
  20711. }
  20712. // prepare binary search on the right side of the index
  20713. right = pp.length;
  20714. break linear_scan;
  20715. }
  20716. //- slower code:
  20717. //- if ( t < t0 || t0 === undefined ) {
  20718. if ( ! ( t >= t0 ) ) {
  20719. // looping?
  20720. var t1global = pp[ 1 ];
  20721. if ( t < t1global ) {
  20722. i1 = 2; // + 1, using the scan for the details
  20723. t0 = t1global;
  20724. }
  20725. // linear reverse scan
  20726. for ( var giveUpAt = i1 - 2; ; ) {
  20727. if ( t0 === undefined ) {
  20728. // before start
  20729. this._cachedIndex = 0;
  20730. return this.beforeStart_( 0, t, t1 );
  20731. }
  20732. if ( i1 === giveUpAt ) break; // this loop
  20733. t1 = t0;
  20734. t0 = pp[ -- i1 - 1 ];
  20735. if ( t >= t0 ) {
  20736. // we have arrived at the sought interval
  20737. break seek;
  20738. }
  20739. }
  20740. // prepare binary search on the left side of the index
  20741. right = i1;
  20742. i1 = 0;
  20743. break linear_scan;
  20744. }
  20745. // the interval is valid
  20746. break validate_interval;
  20747. } // linear scan
  20748. // binary search
  20749. while ( i1 < right ) {
  20750. var mid = ( i1 + right ) >>> 1;
  20751. if ( t < pp[ mid ] ) {
  20752. right = mid;
  20753. } else {
  20754. i1 = mid + 1;
  20755. }
  20756. }
  20757. t1 = pp[ i1 ];
  20758. t0 = pp[ i1 - 1 ];
  20759. // check boundary cases, again
  20760. if ( t0 === undefined ) {
  20761. this._cachedIndex = 0;
  20762. return this.beforeStart_( 0, t, t1 );
  20763. }
  20764. if ( t1 === undefined ) {
  20765. i1 = pp.length;
  20766. this._cachedIndex = i1;
  20767. return this.afterEnd_( i1 - 1, t0, t );
  20768. }
  20769. } // seek
  20770. this._cachedIndex = i1;
  20771. this.intervalChanged_( i1, t0, t1 );
  20772. } // validate_interval
  20773. return this.interpolate_( i1, t0, t, t1 );
  20774. },
  20775. settings: null, // optional, subclass-specific settings structure
  20776. // Note: The indirection allows central control of many interpolants.
  20777. // --- Protected interface
  20778. DefaultSettings_: {},
  20779. getSettings_: function () {
  20780. return this.settings || this.DefaultSettings_;
  20781. },
  20782. copySampleValue_: function ( index ) {
  20783. // copies a sample value to the result buffer
  20784. var result = this.resultBuffer,
  20785. values = this.sampleValues,
  20786. stride = this.valueSize,
  20787. offset = index * stride;
  20788. for ( var i = 0; i !== stride; ++ i ) {
  20789. result[ i ] = values[ offset + i ];
  20790. }
  20791. return result;
  20792. },
  20793. // Template methods for derived classes:
  20794. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  20795. throw new Error( 'call to abstract method' );
  20796. // implementations shall return this.resultBuffer
  20797. },
  20798. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  20799. // empty
  20800. }
  20801. } );
  20802. //!\ DECLARE ALIAS AFTER assign prototype !
  20803. Object.assign( Interpolant.prototype, {
  20804. //( 0, t, t0 ), returns this.resultBuffer
  20805. beforeStart_: Interpolant.prototype.copySampleValue_,
  20806. //( N-1, tN-1, t ), returns this.resultBuffer
  20807. afterEnd_: Interpolant.prototype.copySampleValue_,
  20808. } );
  20809. /**
  20810. * Fast and simple cubic spline interpolant.
  20811. *
  20812. * It was derived from a Hermitian construction setting the first derivative
  20813. * at each sample position to the linear slope between neighboring positions
  20814. * over their parameter interval.
  20815. *
  20816. * @author tschw
  20817. */
  20818. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20819. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20820. this._weightPrev = - 0;
  20821. this._offsetPrev = - 0;
  20822. this._weightNext = - 0;
  20823. this._offsetNext = - 0;
  20824. }
  20825. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20826. constructor: CubicInterpolant,
  20827. DefaultSettings_: {
  20828. endingStart: ZeroCurvatureEnding,
  20829. endingEnd: ZeroCurvatureEnding
  20830. },
  20831. intervalChanged_: function ( i1, t0, t1 ) {
  20832. var pp = this.parameterPositions,
  20833. iPrev = i1 - 2,
  20834. iNext = i1 + 1,
  20835. tPrev = pp[ iPrev ],
  20836. tNext = pp[ iNext ];
  20837. if ( tPrev === undefined ) {
  20838. switch ( this.getSettings_().endingStart ) {
  20839. case ZeroSlopeEnding:
  20840. // f'(t0) = 0
  20841. iPrev = i1;
  20842. tPrev = 2 * t0 - t1;
  20843. break;
  20844. case WrapAroundEnding:
  20845. // use the other end of the curve
  20846. iPrev = pp.length - 2;
  20847. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  20848. break;
  20849. default: // ZeroCurvatureEnding
  20850. // f''(t0) = 0 a.k.a. Natural Spline
  20851. iPrev = i1;
  20852. tPrev = t1;
  20853. }
  20854. }
  20855. if ( tNext === undefined ) {
  20856. switch ( this.getSettings_().endingEnd ) {
  20857. case ZeroSlopeEnding:
  20858. // f'(tN) = 0
  20859. iNext = i1;
  20860. tNext = 2 * t1 - t0;
  20861. break;
  20862. case WrapAroundEnding:
  20863. // use the other end of the curve
  20864. iNext = 1;
  20865. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  20866. break;
  20867. default: // ZeroCurvatureEnding
  20868. // f''(tN) = 0, a.k.a. Natural Spline
  20869. iNext = i1 - 1;
  20870. tNext = t0;
  20871. }
  20872. }
  20873. var halfDt = ( t1 - t0 ) * 0.5,
  20874. stride = this.valueSize;
  20875. this._weightPrev = halfDt / ( t0 - tPrev );
  20876. this._weightNext = halfDt / ( tNext - t1 );
  20877. this._offsetPrev = iPrev * stride;
  20878. this._offsetNext = iNext * stride;
  20879. },
  20880. interpolate_: function ( i1, t0, t, t1 ) {
  20881. var result = this.resultBuffer,
  20882. values = this.sampleValues,
  20883. stride = this.valueSize,
  20884. o1 = i1 * stride, o0 = o1 - stride,
  20885. oP = this._offsetPrev, oN = this._offsetNext,
  20886. wP = this._weightPrev, wN = this._weightNext,
  20887. p = ( t - t0 ) / ( t1 - t0 ),
  20888. pp = p * p,
  20889. ppp = pp * p;
  20890. // evaluate polynomials
  20891. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  20892. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  20893. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  20894. var sN = wN * ppp - wN * pp;
  20895. // combine data linearly
  20896. for ( var i = 0; i !== stride; ++ i ) {
  20897. result[ i ] =
  20898. sP * values[ oP + i ] +
  20899. s0 * values[ o0 + i ] +
  20900. s1 * values[ o1 + i ] +
  20901. sN * values[ oN + i ];
  20902. }
  20903. return result;
  20904. }
  20905. } );
  20906. /**
  20907. * @author tschw
  20908. */
  20909. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20910. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20911. }
  20912. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20913. constructor: LinearInterpolant,
  20914. interpolate_: function ( i1, t0, t, t1 ) {
  20915. var result = this.resultBuffer,
  20916. values = this.sampleValues,
  20917. stride = this.valueSize,
  20918. offset1 = i1 * stride,
  20919. offset0 = offset1 - stride,
  20920. weight1 = ( t - t0 ) / ( t1 - t0 ),
  20921. weight0 = 1 - weight1;
  20922. for ( var i = 0; i !== stride; ++ i ) {
  20923. result[ i ] =
  20924. values[ offset0 + i ] * weight0 +
  20925. values[ offset1 + i ] * weight1;
  20926. }
  20927. return result;
  20928. }
  20929. } );
  20930. /**
  20931. *
  20932. * Interpolant that evaluates to the sample value at the position preceeding
  20933. * the parameter.
  20934. *
  20935. * @author tschw
  20936. */
  20937. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20938. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20939. }
  20940. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20941. constructor: DiscreteInterpolant,
  20942. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  20943. return this.copySampleValue_( i1 - 1 );
  20944. }
  20945. } );
  20946. /**
  20947. *
  20948. * A timed sequence of keyframes for a specific property.
  20949. *
  20950. *
  20951. * @author Ben Houston / http://clara.io/
  20952. * @author David Sarno / http://lighthaus.us/
  20953. * @author tschw
  20954. */
  20955. function KeyframeTrack( name, times, values, interpolation ) {
  20956. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  20957. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  20958. this.name = name;
  20959. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  20960. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  20961. this.setInterpolation( interpolation || this.DefaultInterpolation );
  20962. }
  20963. // Static methods
  20964. Object.assign( KeyframeTrack, {
  20965. // Serialization (in static context, because of constructor invocation
  20966. // and automatic invocation of .toJSON):
  20967. toJSON: function ( track ) {
  20968. var trackType = track.constructor;
  20969. var json;
  20970. // derived classes can define a static toJSON method
  20971. if ( trackType.toJSON !== undefined ) {
  20972. json = trackType.toJSON( track );
  20973. } else {
  20974. // by default, we assume the data can be serialized as-is
  20975. json = {
  20976. 'name': track.name,
  20977. 'times': AnimationUtils.convertArray( track.times, Array ),
  20978. 'values': AnimationUtils.convertArray( track.values, Array )
  20979. };
  20980. var interpolation = track.getInterpolation();
  20981. if ( interpolation !== track.DefaultInterpolation ) {
  20982. json.interpolation = interpolation;
  20983. }
  20984. }
  20985. json.type = track.ValueTypeName; // mandatory
  20986. return json;
  20987. }
  20988. } );
  20989. Object.assign( KeyframeTrack.prototype, {
  20990. constructor: KeyframeTrack,
  20991. TimeBufferType: Float32Array,
  20992. ValueBufferType: Float32Array,
  20993. DefaultInterpolation: InterpolateLinear,
  20994. InterpolantFactoryMethodDiscrete: function ( result ) {
  20995. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  20996. },
  20997. InterpolantFactoryMethodLinear: function ( result ) {
  20998. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20999. },
  21000. InterpolantFactoryMethodSmooth: function ( result ) {
  21001. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  21002. },
  21003. setInterpolation: function ( interpolation ) {
  21004. var factoryMethod;
  21005. switch ( interpolation ) {
  21006. case InterpolateDiscrete:
  21007. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  21008. break;
  21009. case InterpolateLinear:
  21010. factoryMethod = this.InterpolantFactoryMethodLinear;
  21011. break;
  21012. case InterpolateSmooth:
  21013. factoryMethod = this.InterpolantFactoryMethodSmooth;
  21014. break;
  21015. }
  21016. if ( factoryMethod === undefined ) {
  21017. var message = "unsupported interpolation for " +
  21018. this.ValueTypeName + " keyframe track named " + this.name;
  21019. if ( this.createInterpolant === undefined ) {
  21020. // fall back to default, unless the default itself is messed up
  21021. if ( interpolation !== this.DefaultInterpolation ) {
  21022. this.setInterpolation( this.DefaultInterpolation );
  21023. } else {
  21024. throw new Error( message ); // fatal, in this case
  21025. }
  21026. }
  21027. console.warn( 'THREE.KeyframeTrack:', message );
  21028. return this;
  21029. }
  21030. this.createInterpolant = factoryMethod;
  21031. return this;
  21032. },
  21033. getInterpolation: function () {
  21034. switch ( this.createInterpolant ) {
  21035. case this.InterpolantFactoryMethodDiscrete:
  21036. return InterpolateDiscrete;
  21037. case this.InterpolantFactoryMethodLinear:
  21038. return InterpolateLinear;
  21039. case this.InterpolantFactoryMethodSmooth:
  21040. return InterpolateSmooth;
  21041. }
  21042. },
  21043. getValueSize: function () {
  21044. return this.values.length / this.times.length;
  21045. },
  21046. // move all keyframes either forwards or backwards in time
  21047. shift: function ( timeOffset ) {
  21048. if ( timeOffset !== 0.0 ) {
  21049. var times = this.times;
  21050. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  21051. times[ i ] += timeOffset;
  21052. }
  21053. }
  21054. return this;
  21055. },
  21056. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  21057. scale: function ( timeScale ) {
  21058. if ( timeScale !== 1.0 ) {
  21059. var times = this.times;
  21060. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  21061. times[ i ] *= timeScale;
  21062. }
  21063. }
  21064. return this;
  21065. },
  21066. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  21067. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  21068. trim: function ( startTime, endTime ) {
  21069. var times = this.times,
  21070. nKeys = times.length,
  21071. from = 0,
  21072. to = nKeys - 1;
  21073. while ( from !== nKeys && times[ from ] < startTime ) {
  21074. ++ from;
  21075. }
  21076. while ( to !== - 1 && times[ to ] > endTime ) {
  21077. -- to;
  21078. }
  21079. ++ to; // inclusive -> exclusive bound
  21080. if ( from !== 0 || to !== nKeys ) {
  21081. // empty tracks are forbidden, so keep at least one keyframe
  21082. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  21083. var stride = this.getValueSize();
  21084. this.times = AnimationUtils.arraySlice( times, from, to );
  21085. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  21086. }
  21087. return this;
  21088. },
  21089. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  21090. validate: function () {
  21091. var valid = true;
  21092. var valueSize = this.getValueSize();
  21093. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  21094. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  21095. valid = false;
  21096. }
  21097. var times = this.times,
  21098. values = this.values,
  21099. nKeys = times.length;
  21100. if ( nKeys === 0 ) {
  21101. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  21102. valid = false;
  21103. }
  21104. var prevTime = null;
  21105. for ( var i = 0; i !== nKeys; i ++ ) {
  21106. var currTime = times[ i ];
  21107. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  21108. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  21109. valid = false;
  21110. break;
  21111. }
  21112. if ( prevTime !== null && prevTime > currTime ) {
  21113. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  21114. valid = false;
  21115. break;
  21116. }
  21117. prevTime = currTime;
  21118. }
  21119. if ( values !== undefined ) {
  21120. if ( AnimationUtils.isTypedArray( values ) ) {
  21121. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  21122. var value = values[ i ];
  21123. if ( isNaN( value ) ) {
  21124. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  21125. valid = false;
  21126. break;
  21127. }
  21128. }
  21129. }
  21130. }
  21131. return valid;
  21132. },
  21133. // removes equivalent sequential keys as common in morph target sequences
  21134. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21135. optimize: function () {
  21136. var times = this.times,
  21137. values = this.values,
  21138. stride = this.getValueSize(),
  21139. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21140. writeIndex = 1,
  21141. lastIndex = times.length - 1;
  21142. for ( var i = 1; i < lastIndex; ++ i ) {
  21143. var keep = false;
  21144. var time = times[ i ];
  21145. var timeNext = times[ i + 1 ];
  21146. // remove adjacent keyframes scheduled at the same time
  21147. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  21148. if ( ! smoothInterpolation ) {
  21149. // remove unnecessary keyframes same as their neighbors
  21150. var offset = i * stride,
  21151. offsetP = offset - stride,
  21152. offsetN = offset + stride;
  21153. for ( var j = 0; j !== stride; ++ j ) {
  21154. var value = values[ offset + j ];
  21155. if ( value !== values[ offsetP + j ] ||
  21156. value !== values[ offsetN + j ] ) {
  21157. keep = true;
  21158. break;
  21159. }
  21160. }
  21161. } else {
  21162. keep = true;
  21163. }
  21164. }
  21165. // in-place compaction
  21166. if ( keep ) {
  21167. if ( i !== writeIndex ) {
  21168. times[ writeIndex ] = times[ i ];
  21169. var readOffset = i * stride,
  21170. writeOffset = writeIndex * stride;
  21171. for ( var j = 0; j !== stride; ++ j ) {
  21172. values[ writeOffset + j ] = values[ readOffset + j ];
  21173. }
  21174. }
  21175. ++ writeIndex;
  21176. }
  21177. }
  21178. // flush last keyframe (compaction looks ahead)
  21179. if ( lastIndex > 0 ) {
  21180. times[ writeIndex ] = times[ lastIndex ];
  21181. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  21182. values[ writeOffset + j ] = values[ readOffset + j ];
  21183. }
  21184. ++ writeIndex;
  21185. }
  21186. if ( writeIndex !== times.length ) {
  21187. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  21188. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  21189. }
  21190. return this;
  21191. },
  21192. clone: function () {
  21193. var times = AnimationUtils.arraySlice( this.times, 0 );
  21194. var values = AnimationUtils.arraySlice( this.values, 0 );
  21195. var TypedKeyframeTrack = this.constructor;
  21196. var track = new TypedKeyframeTrack( this.name, times, values );
  21197. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21198. track.createInterpolant = this.createInterpolant;
  21199. return track;
  21200. }
  21201. } );
  21202. /**
  21203. *
  21204. * A Track of Boolean keyframe values.
  21205. *
  21206. *
  21207. * @author Ben Houston / http://clara.io/
  21208. * @author David Sarno / http://lighthaus.us/
  21209. * @author tschw
  21210. */
  21211. function BooleanKeyframeTrack( name, times, values ) {
  21212. KeyframeTrack.call( this, name, times, values );
  21213. }
  21214. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21215. constructor: BooleanKeyframeTrack,
  21216. ValueTypeName: 'bool',
  21217. ValueBufferType: Array,
  21218. DefaultInterpolation: InterpolateDiscrete,
  21219. InterpolantFactoryMethodLinear: undefined,
  21220. InterpolantFactoryMethodSmooth: undefined
  21221. // Note: Actually this track could have a optimized / compressed
  21222. // representation of a single value and a custom interpolant that
  21223. // computes "firstValue ^ isOdd( index )".
  21224. } );
  21225. /**
  21226. *
  21227. * A Track of keyframe values that represent color.
  21228. *
  21229. *
  21230. * @author Ben Houston / http://clara.io/
  21231. * @author David Sarno / http://lighthaus.us/
  21232. * @author tschw
  21233. */
  21234. function ColorKeyframeTrack( name, times, values, interpolation ) {
  21235. KeyframeTrack.call( this, name, times, values, interpolation );
  21236. }
  21237. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21238. constructor: ColorKeyframeTrack,
  21239. ValueTypeName: 'color'
  21240. // ValueBufferType is inherited
  21241. // DefaultInterpolation is inherited
  21242. // Note: Very basic implementation and nothing special yet.
  21243. // However, this is the place for color space parameterization.
  21244. } );
  21245. /**
  21246. *
  21247. * A Track of numeric keyframe values.
  21248. *
  21249. * @author Ben Houston / http://clara.io/
  21250. * @author David Sarno / http://lighthaus.us/
  21251. * @author tschw
  21252. */
  21253. function NumberKeyframeTrack( name, times, values, interpolation ) {
  21254. KeyframeTrack.call( this, name, times, values, interpolation );
  21255. }
  21256. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21257. constructor: NumberKeyframeTrack,
  21258. ValueTypeName: 'number'
  21259. // ValueBufferType is inherited
  21260. // DefaultInterpolation is inherited
  21261. } );
  21262. /**
  21263. * Spherical linear unit quaternion interpolant.
  21264. *
  21265. * @author tschw
  21266. */
  21267. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  21268. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  21269. }
  21270. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  21271. constructor: QuaternionLinearInterpolant,
  21272. interpolate_: function ( i1, t0, t, t1 ) {
  21273. var result = this.resultBuffer,
  21274. values = this.sampleValues,
  21275. stride = this.valueSize,
  21276. offset = i1 * stride,
  21277. alpha = ( t - t0 ) / ( t1 - t0 );
  21278. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  21279. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  21280. }
  21281. return result;
  21282. }
  21283. } );
  21284. /**
  21285. *
  21286. * A Track of quaternion keyframe values.
  21287. *
  21288. * @author Ben Houston / http://clara.io/
  21289. * @author David Sarno / http://lighthaus.us/
  21290. * @author tschw
  21291. */
  21292. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  21293. KeyframeTrack.call( this, name, times, values, interpolation );
  21294. }
  21295. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21296. constructor: QuaternionKeyframeTrack,
  21297. ValueTypeName: 'quaternion',
  21298. // ValueBufferType is inherited
  21299. DefaultInterpolation: InterpolateLinear,
  21300. InterpolantFactoryMethodLinear: function ( result ) {
  21301. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  21302. },
  21303. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21304. } );
  21305. /**
  21306. *
  21307. * A Track that interpolates Strings
  21308. *
  21309. *
  21310. * @author Ben Houston / http://clara.io/
  21311. * @author David Sarno / http://lighthaus.us/
  21312. * @author tschw
  21313. */
  21314. function StringKeyframeTrack( name, times, values, interpolation ) {
  21315. KeyframeTrack.call( this, name, times, values, interpolation );
  21316. }
  21317. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21318. constructor: StringKeyframeTrack,
  21319. ValueTypeName: 'string',
  21320. ValueBufferType: Array,
  21321. DefaultInterpolation: InterpolateDiscrete,
  21322. InterpolantFactoryMethodLinear: undefined,
  21323. InterpolantFactoryMethodSmooth: undefined
  21324. } );
  21325. /**
  21326. *
  21327. * A Track of vectored keyframe values.
  21328. *
  21329. *
  21330. * @author Ben Houston / http://clara.io/
  21331. * @author David Sarno / http://lighthaus.us/
  21332. * @author tschw
  21333. */
  21334. function VectorKeyframeTrack( name, times, values, interpolation ) {
  21335. KeyframeTrack.call( this, name, times, values, interpolation );
  21336. }
  21337. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21338. constructor: VectorKeyframeTrack,
  21339. ValueTypeName: 'vector'
  21340. // ValueBufferType is inherited
  21341. // DefaultInterpolation is inherited
  21342. } );
  21343. /**
  21344. *
  21345. * Reusable set of Tracks that represent an animation.
  21346. *
  21347. * @author Ben Houston / http://clara.io/
  21348. * @author David Sarno / http://lighthaus.us/
  21349. */
  21350. function AnimationClip( name, duration, tracks ) {
  21351. this.name = name;
  21352. this.tracks = tracks;
  21353. this.duration = ( duration !== undefined ) ? duration : - 1;
  21354. this.uuid = _Math.generateUUID();
  21355. // this means it should figure out its duration by scanning the tracks
  21356. if ( this.duration < 0 ) {
  21357. this.resetDuration();
  21358. }
  21359. }
  21360. function getTrackTypeForValueTypeName( typeName ) {
  21361. switch ( typeName.toLowerCase() ) {
  21362. case 'scalar':
  21363. case 'double':
  21364. case 'float':
  21365. case 'number':
  21366. case 'integer':
  21367. return NumberKeyframeTrack;
  21368. case 'vector':
  21369. case 'vector2':
  21370. case 'vector3':
  21371. case 'vector4':
  21372. return VectorKeyframeTrack;
  21373. case 'color':
  21374. return ColorKeyframeTrack;
  21375. case 'quaternion':
  21376. return QuaternionKeyframeTrack;
  21377. case 'bool':
  21378. case 'boolean':
  21379. return BooleanKeyframeTrack;
  21380. case 'string':
  21381. return StringKeyframeTrack;
  21382. }
  21383. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  21384. }
  21385. function parseKeyframeTrack( json ) {
  21386. if ( json.type === undefined ) {
  21387. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  21388. }
  21389. var trackType = getTrackTypeForValueTypeName( json.type );
  21390. if ( json.times === undefined ) {
  21391. var times = [], values = [];
  21392. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  21393. json.times = times;
  21394. json.values = values;
  21395. }
  21396. // derived classes can define a static parse method
  21397. if ( trackType.parse !== undefined ) {
  21398. return trackType.parse( json );
  21399. } else {
  21400. // by default, we assume a constructor compatible with the base
  21401. return new trackType( json.name, json.times, json.values, json.interpolation );
  21402. }
  21403. }
  21404. Object.assign( AnimationClip, {
  21405. parse: function ( json ) {
  21406. var tracks = [],
  21407. jsonTracks = json.tracks,
  21408. frameTime = 1.0 / ( json.fps || 1.0 );
  21409. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  21410. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  21411. }
  21412. return new AnimationClip( json.name, json.duration, tracks );
  21413. },
  21414. toJSON: function ( clip ) {
  21415. var tracks = [],
  21416. clipTracks = clip.tracks;
  21417. var json = {
  21418. 'name': clip.name,
  21419. 'duration': clip.duration,
  21420. 'tracks': tracks,
  21421. 'uuid': clip.uuid
  21422. };
  21423. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  21424. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  21425. }
  21426. return json;
  21427. },
  21428. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  21429. var numMorphTargets = morphTargetSequence.length;
  21430. var tracks = [];
  21431. for ( var i = 0; i < numMorphTargets; i ++ ) {
  21432. var times = [];
  21433. var values = [];
  21434. times.push(
  21435. ( i + numMorphTargets - 1 ) % numMorphTargets,
  21436. i,
  21437. ( i + 1 ) % numMorphTargets );
  21438. values.push( 0, 1, 0 );
  21439. var order = AnimationUtils.getKeyframeOrder( times );
  21440. times = AnimationUtils.sortedArray( times, 1, order );
  21441. values = AnimationUtils.sortedArray( values, 1, order );
  21442. // if there is a key at the first frame, duplicate it as the
  21443. // last frame as well for perfect loop.
  21444. if ( ! noLoop && times[ 0 ] === 0 ) {
  21445. times.push( numMorphTargets );
  21446. values.push( values[ 0 ] );
  21447. }
  21448. tracks.push(
  21449. new NumberKeyframeTrack(
  21450. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  21451. times, values
  21452. ).scale( 1.0 / fps ) );
  21453. }
  21454. return new AnimationClip( name, - 1, tracks );
  21455. },
  21456. findByName: function ( objectOrClipArray, name ) {
  21457. var clipArray = objectOrClipArray;
  21458. if ( ! Array.isArray( objectOrClipArray ) ) {
  21459. var o = objectOrClipArray;
  21460. clipArray = o.geometry && o.geometry.animations || o.animations;
  21461. }
  21462. for ( var i = 0; i < clipArray.length; i ++ ) {
  21463. if ( clipArray[ i ].name === name ) {
  21464. return clipArray[ i ];
  21465. }
  21466. }
  21467. return null;
  21468. },
  21469. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  21470. var animationToMorphTargets = {};
  21471. // tested with https://regex101.com/ on trick sequences
  21472. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21473. var pattern = /^([\w-]*?)([\d]+)$/;
  21474. // sort morph target names into animation groups based
  21475. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21476. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  21477. var morphTarget = morphTargets[ i ];
  21478. var parts = morphTarget.name.match( pattern );
  21479. if ( parts && parts.length > 1 ) {
  21480. var name = parts[ 1 ];
  21481. var animationMorphTargets = animationToMorphTargets[ name ];
  21482. if ( ! animationMorphTargets ) {
  21483. animationToMorphTargets[ name ] = animationMorphTargets = [];
  21484. }
  21485. animationMorphTargets.push( morphTarget );
  21486. }
  21487. }
  21488. var clips = [];
  21489. for ( var name in animationToMorphTargets ) {
  21490. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  21491. }
  21492. return clips;
  21493. },
  21494. // parse the animation.hierarchy format
  21495. parseAnimation: function ( animation, bones ) {
  21496. if ( ! animation ) {
  21497. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  21498. return null;
  21499. }
  21500. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  21501. // only return track if there are actually keys.
  21502. if ( animationKeys.length !== 0 ) {
  21503. var times = [];
  21504. var values = [];
  21505. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  21506. // empty keys are filtered out, so check again
  21507. if ( times.length !== 0 ) {
  21508. destTracks.push( new trackType( trackName, times, values ) );
  21509. }
  21510. }
  21511. };
  21512. var tracks = [];
  21513. var clipName = animation.name || 'default';
  21514. // automatic length determination in AnimationClip.
  21515. var duration = animation.length || - 1;
  21516. var fps = animation.fps || 30;
  21517. var hierarchyTracks = animation.hierarchy || [];
  21518. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  21519. var animationKeys = hierarchyTracks[ h ].keys;
  21520. // skip empty tracks
  21521. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  21522. // process morph targets
  21523. if ( animationKeys[ 0 ].morphTargets ) {
  21524. // figure out all morph targets used in this track
  21525. var morphTargetNames = {};
  21526. for ( var k = 0; k < animationKeys.length; k ++ ) {
  21527. if ( animationKeys[ k ].morphTargets ) {
  21528. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  21529. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  21530. }
  21531. }
  21532. }
  21533. // create a track for each morph target with all zero
  21534. // morphTargetInfluences except for the keys in which
  21535. // the morphTarget is named.
  21536. for ( var morphTargetName in morphTargetNames ) {
  21537. var times = [];
  21538. var values = [];
  21539. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  21540. var animationKey = animationKeys[ k ];
  21541. times.push( animationKey.time );
  21542. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  21543. }
  21544. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  21545. }
  21546. duration = morphTargetNames.length * ( fps || 1.0 );
  21547. } else {
  21548. // ...assume skeletal animation
  21549. var boneName = '.bones[' + bones[ h ].name + ']';
  21550. addNonemptyTrack(
  21551. VectorKeyframeTrack, boneName + '.position',
  21552. animationKeys, 'pos', tracks );
  21553. addNonemptyTrack(
  21554. QuaternionKeyframeTrack, boneName + '.quaternion',
  21555. animationKeys, 'rot', tracks );
  21556. addNonemptyTrack(
  21557. VectorKeyframeTrack, boneName + '.scale',
  21558. animationKeys, 'scl', tracks );
  21559. }
  21560. }
  21561. if ( tracks.length === 0 ) {
  21562. return null;
  21563. }
  21564. var clip = new AnimationClip( clipName, duration, tracks );
  21565. return clip;
  21566. }
  21567. } );
  21568. Object.assign( AnimationClip.prototype, {
  21569. resetDuration: function () {
  21570. var tracks = this.tracks, duration = 0;
  21571. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  21572. var track = this.tracks[ i ];
  21573. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  21574. }
  21575. this.duration = duration;
  21576. return this;
  21577. },
  21578. trim: function () {
  21579. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21580. this.tracks[ i ].trim( 0, this.duration );
  21581. }
  21582. return this;
  21583. },
  21584. validate: function () {
  21585. var valid = true;
  21586. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21587. valid = valid && this.tracks[ i ].validate();
  21588. }
  21589. return valid;
  21590. },
  21591. optimize: function () {
  21592. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21593. this.tracks[ i ].optimize();
  21594. }
  21595. return this;
  21596. },
  21597. clone: function () {
  21598. var tracks = [];
  21599. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21600. tracks.push( this.tracks[ i ].clone() );
  21601. }
  21602. return new AnimationClip( this.name, this.duration, tracks );
  21603. }
  21604. } );
  21605. /**
  21606. * @author mrdoob / http://mrdoob.com/
  21607. */
  21608. var Cache = {
  21609. enabled: false,
  21610. files: {},
  21611. add: function ( key, file ) {
  21612. if ( this.enabled === false ) return;
  21613. // console.log( 'THREE.Cache', 'Adding key:', key );
  21614. this.files[ key ] = file;
  21615. },
  21616. get: function ( key ) {
  21617. if ( this.enabled === false ) return;
  21618. // console.log( 'THREE.Cache', 'Checking key:', key );
  21619. return this.files[ key ];
  21620. },
  21621. remove: function ( key ) {
  21622. delete this.files[ key ];
  21623. },
  21624. clear: function () {
  21625. this.files = {};
  21626. }
  21627. };
  21628. /**
  21629. * @author mrdoob / http://mrdoob.com/
  21630. */
  21631. function LoadingManager( onLoad, onProgress, onError ) {
  21632. var scope = this;
  21633. var isLoading = false;
  21634. var itemsLoaded = 0;
  21635. var itemsTotal = 0;
  21636. var urlModifier = undefined;
  21637. // Refer to #5689 for the reason why we don't set .onStart
  21638. // in the constructor
  21639. this.onStart = undefined;
  21640. this.onLoad = onLoad;
  21641. this.onProgress = onProgress;
  21642. this.onError = onError;
  21643. this.itemStart = function ( url ) {
  21644. itemsTotal ++;
  21645. if ( isLoading === false ) {
  21646. if ( scope.onStart !== undefined ) {
  21647. scope.onStart( url, itemsLoaded, itemsTotal );
  21648. }
  21649. }
  21650. isLoading = true;
  21651. };
  21652. this.itemEnd = function ( url ) {
  21653. itemsLoaded ++;
  21654. if ( scope.onProgress !== undefined ) {
  21655. scope.onProgress( url, itemsLoaded, itemsTotal );
  21656. }
  21657. if ( itemsLoaded === itemsTotal ) {
  21658. isLoading = false;
  21659. if ( scope.onLoad !== undefined ) {
  21660. scope.onLoad();
  21661. }
  21662. }
  21663. };
  21664. this.itemError = function ( url ) {
  21665. if ( scope.onError !== undefined ) {
  21666. scope.onError( url );
  21667. }
  21668. };
  21669. this.resolveURL = function ( url ) {
  21670. if ( urlModifier ) {
  21671. return urlModifier( url );
  21672. }
  21673. return url;
  21674. };
  21675. this.setURLModifier = function ( transform ) {
  21676. urlModifier = transform;
  21677. return this;
  21678. };
  21679. }
  21680. var DefaultLoadingManager = new LoadingManager();
  21681. /**
  21682. * @author mrdoob / http://mrdoob.com/
  21683. */
  21684. var loading = {};
  21685. function FileLoader( manager ) {
  21686. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21687. }
  21688. Object.assign( FileLoader.prototype, {
  21689. load: function ( url, onLoad, onProgress, onError ) {
  21690. if ( url === undefined ) url = '';
  21691. if ( this.path !== undefined ) url = this.path + url;
  21692. url = this.manager.resolveURL( url );
  21693. var scope = this;
  21694. var cached = Cache.get( url );
  21695. if ( cached !== undefined ) {
  21696. scope.manager.itemStart( url );
  21697. setTimeout( function () {
  21698. if ( onLoad ) onLoad( cached );
  21699. scope.manager.itemEnd( url );
  21700. }, 0 );
  21701. return cached;
  21702. }
  21703. // Check if request is duplicate
  21704. if ( loading[ url ] !== undefined ) {
  21705. loading[ url ].push( {
  21706. onLoad: onLoad,
  21707. onProgress: onProgress,
  21708. onError: onError
  21709. } );
  21710. return;
  21711. }
  21712. // Check for data: URI
  21713. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  21714. var dataUriRegexResult = url.match( dataUriRegex );
  21715. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  21716. if ( dataUriRegexResult ) {
  21717. var mimeType = dataUriRegexResult[ 1 ];
  21718. var isBase64 = !! dataUriRegexResult[ 2 ];
  21719. var data = dataUriRegexResult[ 3 ];
  21720. data = decodeURIComponent( data );
  21721. if ( isBase64 ) data = atob( data );
  21722. try {
  21723. var response;
  21724. var responseType = ( this.responseType || '' ).toLowerCase();
  21725. switch ( responseType ) {
  21726. case 'arraybuffer':
  21727. case 'blob':
  21728. var view = new Uint8Array( data.length );
  21729. for ( var i = 0; i < data.length; i ++ ) {
  21730. view[ i ] = data.charCodeAt( i );
  21731. }
  21732. if ( responseType === 'blob' ) {
  21733. response = new Blob( [ view.buffer ], { type: mimeType } );
  21734. } else {
  21735. response = view.buffer;
  21736. }
  21737. break;
  21738. case 'document':
  21739. var parser = new DOMParser();
  21740. response = parser.parseFromString( data, mimeType );
  21741. break;
  21742. case 'json':
  21743. response = JSON.parse( data );
  21744. break;
  21745. default: // 'text' or other
  21746. response = data;
  21747. break;
  21748. }
  21749. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21750. setTimeout( function () {
  21751. if ( onLoad ) onLoad( response );
  21752. scope.manager.itemEnd( url );
  21753. }, 0 );
  21754. } catch ( error ) {
  21755. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21756. setTimeout( function () {
  21757. if ( onError ) onError( error );
  21758. scope.manager.itemError( url );
  21759. scope.manager.itemEnd( url );
  21760. }, 0 );
  21761. }
  21762. } else {
  21763. // Initialise array for duplicate requests
  21764. loading[ url ] = [];
  21765. loading[ url ].push( {
  21766. onLoad: onLoad,
  21767. onProgress: onProgress,
  21768. onError: onError
  21769. } );
  21770. var request = new XMLHttpRequest();
  21771. request.open( 'GET', url, true );
  21772. request.addEventListener( 'load', function ( event ) {
  21773. var response = this.response;
  21774. Cache.add( url, response );
  21775. var callbacks = loading[ url ];
  21776. delete loading[ url ];
  21777. if ( this.status === 200 || this.status === 0 ) {
  21778. // Some browsers return HTTP Status 0 when using non-http protocol
  21779. // e.g. 'file://' or 'data://'. Handle as success.
  21780. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  21781. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  21782. var callback = callbacks[ i ];
  21783. if ( callback.onLoad ) callback.onLoad( response );
  21784. }
  21785. scope.manager.itemEnd( url );
  21786. } else {
  21787. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  21788. var callback = callbacks[ i ];
  21789. if ( callback.onError ) callback.onError( event );
  21790. }
  21791. scope.manager.itemError( url );
  21792. scope.manager.itemEnd( url );
  21793. }
  21794. }, false );
  21795. request.addEventListener( 'progress', function ( event ) {
  21796. var callbacks = loading[ url ];
  21797. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  21798. var callback = callbacks[ i ];
  21799. if ( callback.onProgress ) callback.onProgress( event );
  21800. }
  21801. }, false );
  21802. request.addEventListener( 'error', function ( event ) {
  21803. var callbacks = loading[ url ];
  21804. delete loading[ url ];
  21805. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  21806. var callback = callbacks[ i ];
  21807. if ( callback.onError ) callback.onError( event );
  21808. }
  21809. scope.manager.itemError( url );
  21810. scope.manager.itemEnd( url );
  21811. }, false );
  21812. request.addEventListener( 'abort', function ( event ) {
  21813. var callbacks = loading[ url ];
  21814. delete loading[ url ];
  21815. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  21816. var callback = callbacks[ i ];
  21817. if ( callback.onError ) callback.onError( event );
  21818. }
  21819. scope.manager.itemError( url );
  21820. scope.manager.itemEnd( url );
  21821. }, false );
  21822. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  21823. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  21824. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  21825. for ( var header in this.requestHeader ) {
  21826. request.setRequestHeader( header, this.requestHeader[ header ] );
  21827. }
  21828. request.send( null );
  21829. }
  21830. scope.manager.itemStart( url );
  21831. return request;
  21832. },
  21833. setPath: function ( value ) {
  21834. this.path = value;
  21835. return this;
  21836. },
  21837. setResponseType: function ( value ) {
  21838. this.responseType = value;
  21839. return this;
  21840. },
  21841. setWithCredentials: function ( value ) {
  21842. this.withCredentials = value;
  21843. return this;
  21844. },
  21845. setMimeType: function ( value ) {
  21846. this.mimeType = value;
  21847. return this;
  21848. },
  21849. setRequestHeader: function ( value ) {
  21850. this.requestHeader = value;
  21851. return this;
  21852. }
  21853. } );
  21854. /**
  21855. * @author bhouston / http://clara.io/
  21856. */
  21857. function AnimationLoader( manager ) {
  21858. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21859. }
  21860. Object.assign( AnimationLoader.prototype, {
  21861. load: function ( url, onLoad, onProgress, onError ) {
  21862. var scope = this;
  21863. var loader = new FileLoader( scope.manager );
  21864. loader.setPath( scope.path );
  21865. loader.load( url, function ( text ) {
  21866. onLoad( scope.parse( JSON.parse( text ) ) );
  21867. }, onProgress, onError );
  21868. },
  21869. parse: function ( json ) {
  21870. var animations = [];
  21871. for ( var i = 0; i < json.length; i ++ ) {
  21872. var clip = AnimationClip.parse( json[ i ] );
  21873. animations.push( clip );
  21874. }
  21875. return animations;
  21876. },
  21877. setPath: function ( value ) {
  21878. this.path = value;
  21879. return this;
  21880. }
  21881. } );
  21882. /**
  21883. * @author mrdoob / http://mrdoob.com/
  21884. *
  21885. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21886. */
  21887. function CompressedTextureLoader( manager ) {
  21888. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21889. // override in sub classes
  21890. this._parser = null;
  21891. }
  21892. Object.assign( CompressedTextureLoader.prototype, {
  21893. load: function ( url, onLoad, onProgress, onError ) {
  21894. var scope = this;
  21895. var images = [];
  21896. var texture = new CompressedTexture();
  21897. texture.image = images;
  21898. var loader = new FileLoader( this.manager );
  21899. loader.setPath( this.path );
  21900. loader.setResponseType( 'arraybuffer' );
  21901. function loadTexture( i ) {
  21902. loader.load( url[ i ], function ( buffer ) {
  21903. var texDatas = scope._parser( buffer, true );
  21904. images[ i ] = {
  21905. width: texDatas.width,
  21906. height: texDatas.height,
  21907. format: texDatas.format,
  21908. mipmaps: texDatas.mipmaps
  21909. };
  21910. loaded += 1;
  21911. if ( loaded === 6 ) {
  21912. if ( texDatas.mipmapCount === 1 )
  21913. texture.minFilter = LinearFilter;
  21914. texture.format = texDatas.format;
  21915. texture.needsUpdate = true;
  21916. if ( onLoad ) onLoad( texture );
  21917. }
  21918. }, onProgress, onError );
  21919. }
  21920. if ( Array.isArray( url ) ) {
  21921. var loaded = 0;
  21922. for ( var i = 0, il = url.length; i < il; ++ i ) {
  21923. loadTexture( i );
  21924. }
  21925. } else {
  21926. // compressed cubemap texture stored in a single DDS file
  21927. loader.load( url, function ( buffer ) {
  21928. var texDatas = scope._parser( buffer, true );
  21929. if ( texDatas.isCubemap ) {
  21930. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21931. for ( var f = 0; f < faces; f ++ ) {
  21932. images[ f ] = { mipmaps: [] };
  21933. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  21934. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  21935. images[ f ].format = texDatas.format;
  21936. images[ f ].width = texDatas.width;
  21937. images[ f ].height = texDatas.height;
  21938. }
  21939. }
  21940. } else {
  21941. texture.image.width = texDatas.width;
  21942. texture.image.height = texDatas.height;
  21943. texture.mipmaps = texDatas.mipmaps;
  21944. }
  21945. if ( texDatas.mipmapCount === 1 ) {
  21946. texture.minFilter = LinearFilter;
  21947. }
  21948. texture.format = texDatas.format;
  21949. texture.needsUpdate = true;
  21950. if ( onLoad ) onLoad( texture );
  21951. }, onProgress, onError );
  21952. }
  21953. return texture;
  21954. },
  21955. setPath: function ( value ) {
  21956. this.path = value;
  21957. return this;
  21958. }
  21959. } );
  21960. /**
  21961. * @author Nikos M. / https://github.com/foo123/
  21962. *
  21963. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  21964. */
  21965. function DataTextureLoader( manager ) {
  21966. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21967. // override in sub classes
  21968. this._parser = null;
  21969. }
  21970. Object.assign( DataTextureLoader.prototype, {
  21971. load: function ( url, onLoad, onProgress, onError ) {
  21972. var scope = this;
  21973. var texture = new DataTexture();
  21974. var loader = new FileLoader( this.manager );
  21975. loader.setResponseType( 'arraybuffer' );
  21976. loader.setPath( this.path );
  21977. loader.load( url, function ( buffer ) {
  21978. var texData = scope._parser( buffer );
  21979. if ( ! texData ) return;
  21980. if ( texData.image !== undefined ) {
  21981. texture.image = texData.image;
  21982. } else if ( texData.data !== undefined ) {
  21983. texture.image.width = texData.width;
  21984. texture.image.height = texData.height;
  21985. texture.image.data = texData.data;
  21986. }
  21987. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  21988. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  21989. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  21990. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearMipmapLinearFilter;
  21991. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  21992. if ( texData.format !== undefined ) {
  21993. texture.format = texData.format;
  21994. }
  21995. if ( texData.type !== undefined ) {
  21996. texture.type = texData.type;
  21997. }
  21998. if ( texData.mipmaps !== undefined ) {
  21999. texture.mipmaps = texData.mipmaps;
  22000. }
  22001. if ( texData.mipmapCount === 1 ) {
  22002. texture.minFilter = LinearFilter;
  22003. }
  22004. texture.needsUpdate = true;
  22005. if ( onLoad ) onLoad( texture, texData );
  22006. }, onProgress, onError );
  22007. return texture;
  22008. },
  22009. setPath: function ( value ) {
  22010. this.path = value;
  22011. return this;
  22012. }
  22013. } );
  22014. /**
  22015. * @author mrdoob / http://mrdoob.com/
  22016. */
  22017. function ImageLoader( manager ) {
  22018. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22019. }
  22020. Object.assign( ImageLoader.prototype, {
  22021. crossOrigin: 'anonymous',
  22022. load: function ( url, onLoad, onProgress, onError ) {
  22023. if ( url === undefined ) url = '';
  22024. if ( this.path !== undefined ) url = this.path + url;
  22025. url = this.manager.resolveURL( url );
  22026. var scope = this;
  22027. var cached = Cache.get( url );
  22028. if ( cached !== undefined ) {
  22029. scope.manager.itemStart( url );
  22030. setTimeout( function () {
  22031. if ( onLoad ) onLoad( cached );
  22032. scope.manager.itemEnd( url );
  22033. }, 0 );
  22034. return cached;
  22035. }
  22036. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  22037. function onImageLoad() {
  22038. image.removeEventListener( 'load', onImageLoad, false );
  22039. image.removeEventListener( 'error', onImageError, false );
  22040. Cache.add( url, this );
  22041. if ( onLoad ) onLoad( this );
  22042. scope.manager.itemEnd( url );
  22043. }
  22044. function onImageError( event ) {
  22045. image.removeEventListener( 'load', onImageLoad, false );
  22046. image.removeEventListener( 'error', onImageError, false );
  22047. if ( onError ) onError( event );
  22048. scope.manager.itemError( url );
  22049. scope.manager.itemEnd( url );
  22050. }
  22051. image.addEventListener( 'load', onImageLoad, false );
  22052. image.addEventListener( 'error', onImageError, false );
  22053. if ( url.substr( 0, 5 ) !== 'data:' ) {
  22054. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  22055. }
  22056. scope.manager.itemStart( url );
  22057. image.src = url;
  22058. return image;
  22059. },
  22060. setCrossOrigin: function ( value ) {
  22061. this.crossOrigin = value;
  22062. return this;
  22063. },
  22064. setPath: function ( value ) {
  22065. this.path = value;
  22066. return this;
  22067. }
  22068. } );
  22069. /**
  22070. * @author mrdoob / http://mrdoob.com/
  22071. */
  22072. function CubeTextureLoader( manager ) {
  22073. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22074. }
  22075. Object.assign( CubeTextureLoader.prototype, {
  22076. crossOrigin: 'anonymous',
  22077. load: function ( urls, onLoad, onProgress, onError ) {
  22078. var texture = new CubeTexture();
  22079. var loader = new ImageLoader( this.manager );
  22080. loader.setCrossOrigin( this.crossOrigin );
  22081. loader.setPath( this.path );
  22082. var loaded = 0;
  22083. function loadTexture( i ) {
  22084. loader.load( urls[ i ], function ( image ) {
  22085. texture.images[ i ] = image;
  22086. loaded ++;
  22087. if ( loaded === 6 ) {
  22088. texture.needsUpdate = true;
  22089. if ( onLoad ) onLoad( texture );
  22090. }
  22091. }, undefined, onError );
  22092. }
  22093. for ( var i = 0; i < urls.length; ++ i ) {
  22094. loadTexture( i );
  22095. }
  22096. return texture;
  22097. },
  22098. setCrossOrigin: function ( value ) {
  22099. this.crossOrigin = value;
  22100. return this;
  22101. },
  22102. setPath: function ( value ) {
  22103. this.path = value;
  22104. return this;
  22105. }
  22106. } );
  22107. /**
  22108. * @author mrdoob / http://mrdoob.com/
  22109. */
  22110. function TextureLoader( manager ) {
  22111. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22112. }
  22113. Object.assign( TextureLoader.prototype, {
  22114. crossOrigin: 'anonymous',
  22115. load: function ( url, onLoad, onProgress, onError ) {
  22116. var texture = new Texture();
  22117. var loader = new ImageLoader( this.manager );
  22118. loader.setCrossOrigin( this.crossOrigin );
  22119. loader.setPath( this.path );
  22120. loader.load( url, function ( image ) {
  22121. texture.image = image;
  22122. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  22123. var isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  22124. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  22125. texture.needsUpdate = true;
  22126. if ( onLoad !== undefined ) {
  22127. onLoad( texture );
  22128. }
  22129. }, onProgress, onError );
  22130. return texture;
  22131. },
  22132. setCrossOrigin: function ( value ) {
  22133. this.crossOrigin = value;
  22134. return this;
  22135. },
  22136. setPath: function ( value ) {
  22137. this.path = value;
  22138. return this;
  22139. }
  22140. } );
  22141. /**
  22142. * @author zz85 / http://www.lab4games.net/zz85/blog
  22143. * Extensible curve object
  22144. *
  22145. * Some common of curve methods:
  22146. * .getPoint( t, optionalTarget ), .getTangent( t )
  22147. * .getPointAt( u, optionalTarget ), .getTangentAt( u )
  22148. * .getPoints(), .getSpacedPoints()
  22149. * .getLength()
  22150. * .updateArcLengths()
  22151. *
  22152. * This following curves inherit from THREE.Curve:
  22153. *
  22154. * -- 2D curves --
  22155. * THREE.ArcCurve
  22156. * THREE.CubicBezierCurve
  22157. * THREE.EllipseCurve
  22158. * THREE.LineCurve
  22159. * THREE.QuadraticBezierCurve
  22160. * THREE.SplineCurve
  22161. *
  22162. * -- 3D curves --
  22163. * THREE.CatmullRomCurve3
  22164. * THREE.CubicBezierCurve3
  22165. * THREE.LineCurve3
  22166. * THREE.QuadraticBezierCurve3
  22167. *
  22168. * A series of curves can be represented as a THREE.CurvePath.
  22169. *
  22170. **/
  22171. /**************************************************************
  22172. * Abstract Curve base class
  22173. **************************************************************/
  22174. function Curve() {
  22175. this.type = 'Curve';
  22176. this.arcLengthDivisions = 200;
  22177. }
  22178. Object.assign( Curve.prototype, {
  22179. // Virtual base class method to overwrite and implement in subclasses
  22180. // - t [0 .. 1]
  22181. getPoint: function ( /* t, optionalTarget */ ) {
  22182. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  22183. return null;
  22184. },
  22185. // Get point at relative position in curve according to arc length
  22186. // - u [0 .. 1]
  22187. getPointAt: function ( u, optionalTarget ) {
  22188. var t = this.getUtoTmapping( u );
  22189. return this.getPoint( t, optionalTarget );
  22190. },
  22191. // Get sequence of points using getPoint( t )
  22192. getPoints: function ( divisions ) {
  22193. if ( divisions === undefined ) divisions = 5;
  22194. var points = [];
  22195. for ( var d = 0; d <= divisions; d ++ ) {
  22196. points.push( this.getPoint( d / divisions ) );
  22197. }
  22198. return points;
  22199. },
  22200. // Get sequence of points using getPointAt( u )
  22201. getSpacedPoints: function ( divisions ) {
  22202. if ( divisions === undefined ) divisions = 5;
  22203. var points = [];
  22204. for ( var d = 0; d <= divisions; d ++ ) {
  22205. points.push( this.getPointAt( d / divisions ) );
  22206. }
  22207. return points;
  22208. },
  22209. // Get total curve arc length
  22210. getLength: function () {
  22211. var lengths = this.getLengths();
  22212. return lengths[ lengths.length - 1 ];
  22213. },
  22214. // Get list of cumulative segment lengths
  22215. getLengths: function ( divisions ) {
  22216. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  22217. if ( this.cacheArcLengths &&
  22218. ( this.cacheArcLengths.length === divisions + 1 ) &&
  22219. ! this.needsUpdate ) {
  22220. return this.cacheArcLengths;
  22221. }
  22222. this.needsUpdate = false;
  22223. var cache = [];
  22224. var current, last = this.getPoint( 0 );
  22225. var p, sum = 0;
  22226. cache.push( 0 );
  22227. for ( p = 1; p <= divisions; p ++ ) {
  22228. current = this.getPoint( p / divisions );
  22229. sum += current.distanceTo( last );
  22230. cache.push( sum );
  22231. last = current;
  22232. }
  22233. this.cacheArcLengths = cache;
  22234. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22235. },
  22236. updateArcLengths: function () {
  22237. this.needsUpdate = true;
  22238. this.getLengths();
  22239. },
  22240. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22241. getUtoTmapping: function ( u, distance ) {
  22242. var arcLengths = this.getLengths();
  22243. var i = 0, il = arcLengths.length;
  22244. var targetArcLength; // The targeted u distance value to get
  22245. if ( distance ) {
  22246. targetArcLength = distance;
  22247. } else {
  22248. targetArcLength = u * arcLengths[ il - 1 ];
  22249. }
  22250. // binary search for the index with largest value smaller than target u distance
  22251. var low = 0, high = il - 1, comparison;
  22252. while ( low <= high ) {
  22253. 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
  22254. comparison = arcLengths[ i ] - targetArcLength;
  22255. if ( comparison < 0 ) {
  22256. low = i + 1;
  22257. } else if ( comparison > 0 ) {
  22258. high = i - 1;
  22259. } else {
  22260. high = i;
  22261. break;
  22262. // DONE
  22263. }
  22264. }
  22265. i = high;
  22266. if ( arcLengths[ i ] === targetArcLength ) {
  22267. return i / ( il - 1 );
  22268. }
  22269. // we could get finer grain at lengths, or use simple interpolation between two points
  22270. var lengthBefore = arcLengths[ i ];
  22271. var lengthAfter = arcLengths[ i + 1 ];
  22272. var segmentLength = lengthAfter - lengthBefore;
  22273. // determine where we are between the 'before' and 'after' points
  22274. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  22275. // add that fractional amount to t
  22276. var t = ( i + segmentFraction ) / ( il - 1 );
  22277. return t;
  22278. },
  22279. // Returns a unit vector tangent at t
  22280. // In case any sub curve does not implement its tangent derivation,
  22281. // 2 points a small delta apart will be used to find its gradient
  22282. // which seems to give a reasonable approximation
  22283. getTangent: function ( t ) {
  22284. var delta = 0.0001;
  22285. var t1 = t - delta;
  22286. var t2 = t + delta;
  22287. // Capping in case of danger
  22288. if ( t1 < 0 ) t1 = 0;
  22289. if ( t2 > 1 ) t2 = 1;
  22290. var pt1 = this.getPoint( t1 );
  22291. var pt2 = this.getPoint( t2 );
  22292. var vec = pt2.clone().sub( pt1 );
  22293. return vec.normalize();
  22294. },
  22295. getTangentAt: function ( u ) {
  22296. var t = this.getUtoTmapping( u );
  22297. return this.getTangent( t );
  22298. },
  22299. computeFrenetFrames: function ( segments, closed ) {
  22300. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22301. var normal = new Vector3();
  22302. var tangents = [];
  22303. var normals = [];
  22304. var binormals = [];
  22305. var vec = new Vector3();
  22306. var mat = new Matrix4();
  22307. var i, u, theta;
  22308. // compute the tangent vectors for each segment on the curve
  22309. for ( i = 0; i <= segments; i ++ ) {
  22310. u = i / segments;
  22311. tangents[ i ] = this.getTangentAt( u );
  22312. tangents[ i ].normalize();
  22313. }
  22314. // select an initial normal vector perpendicular to the first tangent vector,
  22315. // and in the direction of the minimum tangent xyz component
  22316. normals[ 0 ] = new Vector3();
  22317. binormals[ 0 ] = new Vector3();
  22318. var min = Number.MAX_VALUE;
  22319. var tx = Math.abs( tangents[ 0 ].x );
  22320. var ty = Math.abs( tangents[ 0 ].y );
  22321. var tz = Math.abs( tangents[ 0 ].z );
  22322. if ( tx <= min ) {
  22323. min = tx;
  22324. normal.set( 1, 0, 0 );
  22325. }
  22326. if ( ty <= min ) {
  22327. min = ty;
  22328. normal.set( 0, 1, 0 );
  22329. }
  22330. if ( tz <= min ) {
  22331. normal.set( 0, 0, 1 );
  22332. }
  22333. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  22334. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  22335. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  22336. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22337. for ( i = 1; i <= segments; i ++ ) {
  22338. normals[ i ] = normals[ i - 1 ].clone();
  22339. binormals[ i ] = binormals[ i - 1 ].clone();
  22340. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  22341. if ( vec.length() > Number.EPSILON ) {
  22342. vec.normalize();
  22343. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  22344. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  22345. }
  22346. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  22347. }
  22348. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22349. if ( closed === true ) {
  22350. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  22351. theta /= segments;
  22352. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  22353. theta = - theta;
  22354. }
  22355. for ( i = 1; i <= segments; i ++ ) {
  22356. // twist a little...
  22357. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  22358. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  22359. }
  22360. }
  22361. return {
  22362. tangents: tangents,
  22363. normals: normals,
  22364. binormals: binormals
  22365. };
  22366. },
  22367. clone: function () {
  22368. return new this.constructor().copy( this );
  22369. },
  22370. copy: function ( source ) {
  22371. this.arcLengthDivisions = source.arcLengthDivisions;
  22372. return this;
  22373. },
  22374. toJSON: function () {
  22375. var data = {
  22376. metadata: {
  22377. version: 4.5,
  22378. type: 'Curve',
  22379. generator: 'Curve.toJSON'
  22380. }
  22381. };
  22382. data.arcLengthDivisions = this.arcLengthDivisions;
  22383. data.type = this.type;
  22384. return data;
  22385. },
  22386. fromJSON: function ( json ) {
  22387. this.arcLengthDivisions = json.arcLengthDivisions;
  22388. return this;
  22389. }
  22390. } );
  22391. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22392. Curve.call( this );
  22393. this.type = 'EllipseCurve';
  22394. this.aX = aX || 0;
  22395. this.aY = aY || 0;
  22396. this.xRadius = xRadius || 1;
  22397. this.yRadius = yRadius || 1;
  22398. this.aStartAngle = aStartAngle || 0;
  22399. this.aEndAngle = aEndAngle || 2 * Math.PI;
  22400. this.aClockwise = aClockwise || false;
  22401. this.aRotation = aRotation || 0;
  22402. }
  22403. EllipseCurve.prototype = Object.create( Curve.prototype );
  22404. EllipseCurve.prototype.constructor = EllipseCurve;
  22405. EllipseCurve.prototype.isEllipseCurve = true;
  22406. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22407. var point = optionalTarget || new Vector2();
  22408. var twoPi = Math.PI * 2;
  22409. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22410. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  22411. // ensures that deltaAngle is 0 .. 2 PI
  22412. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  22413. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  22414. if ( deltaAngle < Number.EPSILON ) {
  22415. if ( samePoints ) {
  22416. deltaAngle = 0;
  22417. } else {
  22418. deltaAngle = twoPi;
  22419. }
  22420. }
  22421. if ( this.aClockwise === true && ! samePoints ) {
  22422. if ( deltaAngle === twoPi ) {
  22423. deltaAngle = - twoPi;
  22424. } else {
  22425. deltaAngle = deltaAngle - twoPi;
  22426. }
  22427. }
  22428. var angle = this.aStartAngle + t * deltaAngle;
  22429. var x = this.aX + this.xRadius * Math.cos( angle );
  22430. var y = this.aY + this.yRadius * Math.sin( angle );
  22431. if ( this.aRotation !== 0 ) {
  22432. var cos = Math.cos( this.aRotation );
  22433. var sin = Math.sin( this.aRotation );
  22434. var tx = x - this.aX;
  22435. var ty = y - this.aY;
  22436. // Rotate the point about the center of the ellipse.
  22437. x = tx * cos - ty * sin + this.aX;
  22438. y = tx * sin + ty * cos + this.aY;
  22439. }
  22440. return point.set( x, y );
  22441. };
  22442. EllipseCurve.prototype.copy = function ( source ) {
  22443. Curve.prototype.copy.call( this, source );
  22444. this.aX = source.aX;
  22445. this.aY = source.aY;
  22446. this.xRadius = source.xRadius;
  22447. this.yRadius = source.yRadius;
  22448. this.aStartAngle = source.aStartAngle;
  22449. this.aEndAngle = source.aEndAngle;
  22450. this.aClockwise = source.aClockwise;
  22451. this.aRotation = source.aRotation;
  22452. return this;
  22453. };
  22454. EllipseCurve.prototype.toJSON = function () {
  22455. var data = Curve.prototype.toJSON.call( this );
  22456. data.aX = this.aX;
  22457. data.aY = this.aY;
  22458. data.xRadius = this.xRadius;
  22459. data.yRadius = this.yRadius;
  22460. data.aStartAngle = this.aStartAngle;
  22461. data.aEndAngle = this.aEndAngle;
  22462. data.aClockwise = this.aClockwise;
  22463. data.aRotation = this.aRotation;
  22464. return data;
  22465. };
  22466. EllipseCurve.prototype.fromJSON = function ( json ) {
  22467. Curve.prototype.fromJSON.call( this, json );
  22468. this.aX = json.aX;
  22469. this.aY = json.aY;
  22470. this.xRadius = json.xRadius;
  22471. this.yRadius = json.yRadius;
  22472. this.aStartAngle = json.aStartAngle;
  22473. this.aEndAngle = json.aEndAngle;
  22474. this.aClockwise = json.aClockwise;
  22475. this.aRotation = json.aRotation;
  22476. return this;
  22477. };
  22478. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22479. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  22480. this.type = 'ArcCurve';
  22481. }
  22482. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  22483. ArcCurve.prototype.constructor = ArcCurve;
  22484. ArcCurve.prototype.isArcCurve = true;
  22485. /**
  22486. * @author zz85 https://github.com/zz85
  22487. *
  22488. * Centripetal CatmullRom Curve - which is useful for avoiding
  22489. * cusps and self-intersections in non-uniform catmull rom curves.
  22490. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22491. *
  22492. * curve.type accepts centripetal(default), chordal and catmullrom
  22493. * curve.tension is used for catmullrom which defaults to 0.5
  22494. */
  22495. /*
  22496. Based on an optimized c++ solution in
  22497. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22498. - http://ideone.com/NoEbVM
  22499. This CubicPoly class could be used for reusing some variables and calculations,
  22500. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22501. which can be placed in CurveUtils.
  22502. */
  22503. function CubicPoly() {
  22504. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  22505. /*
  22506. * Compute coefficients for a cubic polynomial
  22507. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22508. * such that
  22509. * p(0) = x0, p(1) = x1
  22510. * and
  22511. * p'(0) = t0, p'(1) = t1.
  22512. */
  22513. function init( x0, x1, t0, t1 ) {
  22514. c0 = x0;
  22515. c1 = t0;
  22516. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  22517. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22518. }
  22519. return {
  22520. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  22521. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  22522. },
  22523. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  22524. // compute tangents when parameterized in [t1,t2]
  22525. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  22526. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  22527. // rescale tangents for parametrization in [0,1]
  22528. t1 *= dt1;
  22529. t2 *= dt1;
  22530. init( x1, x2, t1, t2 );
  22531. },
  22532. calc: function ( t ) {
  22533. var t2 = t * t;
  22534. var t3 = t2 * t;
  22535. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22536. }
  22537. };
  22538. }
  22539. //
  22540. var tmp = new Vector3();
  22541. var px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  22542. function CatmullRomCurve3( points, closed, curveType, tension ) {
  22543. Curve.call( this );
  22544. this.type = 'CatmullRomCurve3';
  22545. this.points = points || [];
  22546. this.closed = closed || false;
  22547. this.curveType = curveType || 'centripetal';
  22548. this.tension = tension || 0.5;
  22549. }
  22550. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  22551. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  22552. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22553. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  22554. var point = optionalTarget || new Vector3();
  22555. var points = this.points;
  22556. var l = points.length;
  22557. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  22558. var intPoint = Math.floor( p );
  22559. var weight = p - intPoint;
  22560. if ( this.closed ) {
  22561. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  22562. } else if ( weight === 0 && intPoint === l - 1 ) {
  22563. intPoint = l - 2;
  22564. weight = 1;
  22565. }
  22566. var p0, p1, p2, p3; // 4 points
  22567. if ( this.closed || intPoint > 0 ) {
  22568. p0 = points[ ( intPoint - 1 ) % l ];
  22569. } else {
  22570. // extrapolate first point
  22571. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  22572. p0 = tmp;
  22573. }
  22574. p1 = points[ intPoint % l ];
  22575. p2 = points[ ( intPoint + 1 ) % l ];
  22576. if ( this.closed || intPoint + 2 < l ) {
  22577. p3 = points[ ( intPoint + 2 ) % l ];
  22578. } else {
  22579. // extrapolate last point
  22580. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  22581. p3 = tmp;
  22582. }
  22583. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  22584. // init Centripetal / Chordal Catmull-Rom
  22585. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22586. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  22587. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  22588. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  22589. // safety check for repeated points
  22590. if ( dt1 < 1e-4 ) dt1 = 1.0;
  22591. if ( dt0 < 1e-4 ) dt0 = dt1;
  22592. if ( dt2 < 1e-4 ) dt2 = dt1;
  22593. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  22594. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  22595. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  22596. } else if ( this.curveType === 'catmullrom' ) {
  22597. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  22598. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  22599. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  22600. }
  22601. point.set(
  22602. px.calc( weight ),
  22603. py.calc( weight ),
  22604. pz.calc( weight )
  22605. );
  22606. return point;
  22607. };
  22608. CatmullRomCurve3.prototype.copy = function ( source ) {
  22609. Curve.prototype.copy.call( this, source );
  22610. this.points = [];
  22611. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  22612. var point = source.points[ i ];
  22613. this.points.push( point.clone() );
  22614. }
  22615. this.closed = source.closed;
  22616. this.curveType = source.curveType;
  22617. this.tension = source.tension;
  22618. return this;
  22619. };
  22620. CatmullRomCurve3.prototype.toJSON = function () {
  22621. var data = Curve.prototype.toJSON.call( this );
  22622. data.points = [];
  22623. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  22624. var point = this.points[ i ];
  22625. data.points.push( point.toArray() );
  22626. }
  22627. data.closed = this.closed;
  22628. data.curveType = this.curveType;
  22629. data.tension = this.tension;
  22630. return data;
  22631. };
  22632. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  22633. Curve.prototype.fromJSON.call( this, json );
  22634. this.points = [];
  22635. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  22636. var point = json.points[ i ];
  22637. this.points.push( new Vector3().fromArray( point ) );
  22638. }
  22639. this.closed = json.closed;
  22640. this.curveType = json.curveType;
  22641. this.tension = json.tension;
  22642. return this;
  22643. };
  22644. /**
  22645. * @author zz85 / http://www.lab4games.net/zz85/blog
  22646. *
  22647. * Bezier Curves formulas obtained from
  22648. * http://en.wikipedia.org/wiki/Bézier_curve
  22649. */
  22650. function CatmullRom( t, p0, p1, p2, p3 ) {
  22651. var v0 = ( p2 - p0 ) * 0.5;
  22652. var v1 = ( p3 - p1 ) * 0.5;
  22653. var t2 = t * t;
  22654. var t3 = t * t2;
  22655. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  22656. }
  22657. //
  22658. function QuadraticBezierP0( t, p ) {
  22659. var k = 1 - t;
  22660. return k * k * p;
  22661. }
  22662. function QuadraticBezierP1( t, p ) {
  22663. return 2 * ( 1 - t ) * t * p;
  22664. }
  22665. function QuadraticBezierP2( t, p ) {
  22666. return t * t * p;
  22667. }
  22668. function QuadraticBezier( t, p0, p1, p2 ) {
  22669. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  22670. QuadraticBezierP2( t, p2 );
  22671. }
  22672. //
  22673. function CubicBezierP0( t, p ) {
  22674. var k = 1 - t;
  22675. return k * k * k * p;
  22676. }
  22677. function CubicBezierP1( t, p ) {
  22678. var k = 1 - t;
  22679. return 3 * k * k * t * p;
  22680. }
  22681. function CubicBezierP2( t, p ) {
  22682. return 3 * ( 1 - t ) * t * t * p;
  22683. }
  22684. function CubicBezierP3( t, p ) {
  22685. return t * t * t * p;
  22686. }
  22687. function CubicBezier( t, p0, p1, p2, p3 ) {
  22688. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  22689. CubicBezierP3( t, p3 );
  22690. }
  22691. function CubicBezierCurve( v0, v1, v2, v3 ) {
  22692. Curve.call( this );
  22693. this.type = 'CubicBezierCurve';
  22694. this.v0 = v0 || new Vector2();
  22695. this.v1 = v1 || new Vector2();
  22696. this.v2 = v2 || new Vector2();
  22697. this.v3 = v3 || new Vector2();
  22698. }
  22699. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  22700. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  22701. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  22702. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22703. var point = optionalTarget || new Vector2();
  22704. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  22705. point.set(
  22706. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  22707. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  22708. );
  22709. return point;
  22710. };
  22711. CubicBezierCurve.prototype.copy = function ( source ) {
  22712. Curve.prototype.copy.call( this, source );
  22713. this.v0.copy( source.v0 );
  22714. this.v1.copy( source.v1 );
  22715. this.v2.copy( source.v2 );
  22716. this.v3.copy( source.v3 );
  22717. return this;
  22718. };
  22719. CubicBezierCurve.prototype.toJSON = function () {
  22720. var data = Curve.prototype.toJSON.call( this );
  22721. data.v0 = this.v0.toArray();
  22722. data.v1 = this.v1.toArray();
  22723. data.v2 = this.v2.toArray();
  22724. data.v3 = this.v3.toArray();
  22725. return data;
  22726. };
  22727. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  22728. Curve.prototype.fromJSON.call( this, json );
  22729. this.v0.fromArray( json.v0 );
  22730. this.v1.fromArray( json.v1 );
  22731. this.v2.fromArray( json.v2 );
  22732. this.v3.fromArray( json.v3 );
  22733. return this;
  22734. };
  22735. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  22736. Curve.call( this );
  22737. this.type = 'CubicBezierCurve3';
  22738. this.v0 = v0 || new Vector3();
  22739. this.v1 = v1 || new Vector3();
  22740. this.v2 = v2 || new Vector3();
  22741. this.v3 = v3 || new Vector3();
  22742. }
  22743. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  22744. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  22745. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  22746. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  22747. var point = optionalTarget || new Vector3();
  22748. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  22749. point.set(
  22750. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  22751. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  22752. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  22753. );
  22754. return point;
  22755. };
  22756. CubicBezierCurve3.prototype.copy = function ( source ) {
  22757. Curve.prototype.copy.call( this, source );
  22758. this.v0.copy( source.v0 );
  22759. this.v1.copy( source.v1 );
  22760. this.v2.copy( source.v2 );
  22761. this.v3.copy( source.v3 );
  22762. return this;
  22763. };
  22764. CubicBezierCurve3.prototype.toJSON = function () {
  22765. var data = Curve.prototype.toJSON.call( this );
  22766. data.v0 = this.v0.toArray();
  22767. data.v1 = this.v1.toArray();
  22768. data.v2 = this.v2.toArray();
  22769. data.v3 = this.v3.toArray();
  22770. return data;
  22771. };
  22772. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  22773. Curve.prototype.fromJSON.call( this, json );
  22774. this.v0.fromArray( json.v0 );
  22775. this.v1.fromArray( json.v1 );
  22776. this.v2.fromArray( json.v2 );
  22777. this.v3.fromArray( json.v3 );
  22778. return this;
  22779. };
  22780. function LineCurve( v1, v2 ) {
  22781. Curve.call( this );
  22782. this.type = 'LineCurve';
  22783. this.v1 = v1 || new Vector2();
  22784. this.v2 = v2 || new Vector2();
  22785. }
  22786. LineCurve.prototype = Object.create( Curve.prototype );
  22787. LineCurve.prototype.constructor = LineCurve;
  22788. LineCurve.prototype.isLineCurve = true;
  22789. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22790. var point = optionalTarget || new Vector2();
  22791. if ( t === 1 ) {
  22792. point.copy( this.v2 );
  22793. } else {
  22794. point.copy( this.v2 ).sub( this.v1 );
  22795. point.multiplyScalar( t ).add( this.v1 );
  22796. }
  22797. return point;
  22798. };
  22799. // Line curve is linear, so we can overwrite default getPointAt
  22800. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  22801. return this.getPoint( u, optionalTarget );
  22802. };
  22803. LineCurve.prototype.getTangent = function ( /* t */ ) {
  22804. var tangent = this.v2.clone().sub( this.v1 );
  22805. return tangent.normalize();
  22806. };
  22807. LineCurve.prototype.copy = function ( source ) {
  22808. Curve.prototype.copy.call( this, source );
  22809. this.v1.copy( source.v1 );
  22810. this.v2.copy( source.v2 );
  22811. return this;
  22812. };
  22813. LineCurve.prototype.toJSON = function () {
  22814. var data = Curve.prototype.toJSON.call( this );
  22815. data.v1 = this.v1.toArray();
  22816. data.v2 = this.v2.toArray();
  22817. return data;
  22818. };
  22819. LineCurve.prototype.fromJSON = function ( json ) {
  22820. Curve.prototype.fromJSON.call( this, json );
  22821. this.v1.fromArray( json.v1 );
  22822. this.v2.fromArray( json.v2 );
  22823. return this;
  22824. };
  22825. function LineCurve3( v1, v2 ) {
  22826. Curve.call( this );
  22827. this.type = 'LineCurve3';
  22828. this.v1 = v1 || new Vector3();
  22829. this.v2 = v2 || new Vector3();
  22830. }
  22831. LineCurve3.prototype = Object.create( Curve.prototype );
  22832. LineCurve3.prototype.constructor = LineCurve3;
  22833. LineCurve3.prototype.isLineCurve3 = true;
  22834. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  22835. var point = optionalTarget || new Vector3();
  22836. if ( t === 1 ) {
  22837. point.copy( this.v2 );
  22838. } else {
  22839. point.copy( this.v2 ).sub( this.v1 );
  22840. point.multiplyScalar( t ).add( this.v1 );
  22841. }
  22842. return point;
  22843. };
  22844. // Line curve is linear, so we can overwrite default getPointAt
  22845. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  22846. return this.getPoint( u, optionalTarget );
  22847. };
  22848. LineCurve3.prototype.copy = function ( source ) {
  22849. Curve.prototype.copy.call( this, source );
  22850. this.v1.copy( source.v1 );
  22851. this.v2.copy( source.v2 );
  22852. return this;
  22853. };
  22854. LineCurve3.prototype.toJSON = function () {
  22855. var data = Curve.prototype.toJSON.call( this );
  22856. data.v1 = this.v1.toArray();
  22857. data.v2 = this.v2.toArray();
  22858. return data;
  22859. };
  22860. LineCurve3.prototype.fromJSON = function ( json ) {
  22861. Curve.prototype.fromJSON.call( this, json );
  22862. this.v1.fromArray( json.v1 );
  22863. this.v2.fromArray( json.v2 );
  22864. return this;
  22865. };
  22866. function QuadraticBezierCurve( v0, v1, v2 ) {
  22867. Curve.call( this );
  22868. this.type = 'QuadraticBezierCurve';
  22869. this.v0 = v0 || new Vector2();
  22870. this.v1 = v1 || new Vector2();
  22871. this.v2 = v2 || new Vector2();
  22872. }
  22873. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  22874. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  22875. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  22876. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22877. var point = optionalTarget || new Vector2();
  22878. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  22879. point.set(
  22880. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  22881. QuadraticBezier( t, v0.y, v1.y, v2.y )
  22882. );
  22883. return point;
  22884. };
  22885. QuadraticBezierCurve.prototype.copy = function ( source ) {
  22886. Curve.prototype.copy.call( this, source );
  22887. this.v0.copy( source.v0 );
  22888. this.v1.copy( source.v1 );
  22889. this.v2.copy( source.v2 );
  22890. return this;
  22891. };
  22892. QuadraticBezierCurve.prototype.toJSON = function () {
  22893. var data = Curve.prototype.toJSON.call( this );
  22894. data.v0 = this.v0.toArray();
  22895. data.v1 = this.v1.toArray();
  22896. data.v2 = this.v2.toArray();
  22897. return data;
  22898. };
  22899. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  22900. Curve.prototype.fromJSON.call( this, json );
  22901. this.v0.fromArray( json.v0 );
  22902. this.v1.fromArray( json.v1 );
  22903. this.v2.fromArray( json.v2 );
  22904. return this;
  22905. };
  22906. function QuadraticBezierCurve3( v0, v1, v2 ) {
  22907. Curve.call( this );
  22908. this.type = 'QuadraticBezierCurve3';
  22909. this.v0 = v0 || new Vector3();
  22910. this.v1 = v1 || new Vector3();
  22911. this.v2 = v2 || new Vector3();
  22912. }
  22913. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  22914. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  22915. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  22916. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  22917. var point = optionalTarget || new Vector3();
  22918. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  22919. point.set(
  22920. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  22921. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  22922. QuadraticBezier( t, v0.z, v1.z, v2.z )
  22923. );
  22924. return point;
  22925. };
  22926. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  22927. Curve.prototype.copy.call( this, source );
  22928. this.v0.copy( source.v0 );
  22929. this.v1.copy( source.v1 );
  22930. this.v2.copy( source.v2 );
  22931. return this;
  22932. };
  22933. QuadraticBezierCurve3.prototype.toJSON = function () {
  22934. var data = Curve.prototype.toJSON.call( this );
  22935. data.v0 = this.v0.toArray();
  22936. data.v1 = this.v1.toArray();
  22937. data.v2 = this.v2.toArray();
  22938. return data;
  22939. };
  22940. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  22941. Curve.prototype.fromJSON.call( this, json );
  22942. this.v0.fromArray( json.v0 );
  22943. this.v1.fromArray( json.v1 );
  22944. this.v2.fromArray( json.v2 );
  22945. return this;
  22946. };
  22947. function SplineCurve( points /* array of Vector2 */ ) {
  22948. Curve.call( this );
  22949. this.type = 'SplineCurve';
  22950. this.points = points || [];
  22951. }
  22952. SplineCurve.prototype = Object.create( Curve.prototype );
  22953. SplineCurve.prototype.constructor = SplineCurve;
  22954. SplineCurve.prototype.isSplineCurve = true;
  22955. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22956. var point = optionalTarget || new Vector2();
  22957. var points = this.points;
  22958. var p = ( points.length - 1 ) * t;
  22959. var intPoint = Math.floor( p );
  22960. var weight = p - intPoint;
  22961. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  22962. var p1 = points[ intPoint ];
  22963. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  22964. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  22965. point.set(
  22966. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  22967. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  22968. );
  22969. return point;
  22970. };
  22971. SplineCurve.prototype.copy = function ( source ) {
  22972. Curve.prototype.copy.call( this, source );
  22973. this.points = [];
  22974. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  22975. var point = source.points[ i ];
  22976. this.points.push( point.clone() );
  22977. }
  22978. return this;
  22979. };
  22980. SplineCurve.prototype.toJSON = function () {
  22981. var data = Curve.prototype.toJSON.call( this );
  22982. data.points = [];
  22983. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  22984. var point = this.points[ i ];
  22985. data.points.push( point.toArray() );
  22986. }
  22987. return data;
  22988. };
  22989. SplineCurve.prototype.fromJSON = function ( json ) {
  22990. Curve.prototype.fromJSON.call( this, json );
  22991. this.points = [];
  22992. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  22993. var point = json.points[ i ];
  22994. this.points.push( new Vector2().fromArray( point ) );
  22995. }
  22996. return this;
  22997. };
  22998. var Curves = /*#__PURE__*/Object.freeze({
  22999. ArcCurve: ArcCurve,
  23000. CatmullRomCurve3: CatmullRomCurve3,
  23001. CubicBezierCurve: CubicBezierCurve,
  23002. CubicBezierCurve3: CubicBezierCurve3,
  23003. EllipseCurve: EllipseCurve,
  23004. LineCurve: LineCurve,
  23005. LineCurve3: LineCurve3,
  23006. QuadraticBezierCurve: QuadraticBezierCurve,
  23007. QuadraticBezierCurve3: QuadraticBezierCurve3,
  23008. SplineCurve: SplineCurve
  23009. });
  23010. /**
  23011. * @author zz85 / http://www.lab4games.net/zz85/blog
  23012. *
  23013. **/
  23014. /**************************************************************
  23015. * Curved Path - a curve path is simply a array of connected
  23016. * curves, but retains the api of a curve
  23017. **************************************************************/
  23018. function CurvePath() {
  23019. Curve.call( this );
  23020. this.type = 'CurvePath';
  23021. this.curves = [];
  23022. this.autoClose = false; // Automatically closes the path
  23023. }
  23024. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  23025. constructor: CurvePath,
  23026. add: function ( curve ) {
  23027. this.curves.push( curve );
  23028. },
  23029. closePath: function () {
  23030. // Add a line curve if start and end of lines are not connected
  23031. var startPoint = this.curves[ 0 ].getPoint( 0 );
  23032. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  23033. if ( ! startPoint.equals( endPoint ) ) {
  23034. this.curves.push( new LineCurve( endPoint, startPoint ) );
  23035. }
  23036. },
  23037. // To get accurate point with reference to
  23038. // entire path distance at time t,
  23039. // following has to be done:
  23040. // 1. Length of each sub path have to be known
  23041. // 2. Locate and identify type of curve
  23042. // 3. Get t for the curve
  23043. // 4. Return curve.getPointAt(t')
  23044. getPoint: function ( t ) {
  23045. var d = t * this.getLength();
  23046. var curveLengths = this.getCurveLengths();
  23047. var i = 0;
  23048. // To think about boundaries points.
  23049. while ( i < curveLengths.length ) {
  23050. if ( curveLengths[ i ] >= d ) {
  23051. var diff = curveLengths[ i ] - d;
  23052. var curve = this.curves[ i ];
  23053. var segmentLength = curve.getLength();
  23054. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  23055. return curve.getPointAt( u );
  23056. }
  23057. i ++;
  23058. }
  23059. return null;
  23060. // loop where sum != 0, sum > d , sum+1 <d
  23061. },
  23062. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  23063. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  23064. // getPoint() depends on getLength
  23065. getLength: function () {
  23066. var lens = this.getCurveLengths();
  23067. return lens[ lens.length - 1 ];
  23068. },
  23069. // cacheLengths must be recalculated.
  23070. updateArcLengths: function () {
  23071. this.needsUpdate = true;
  23072. this.cacheLengths = null;
  23073. this.getCurveLengths();
  23074. },
  23075. // Compute lengths and cache them
  23076. // We cannot overwrite getLengths() because UtoT mapping uses it.
  23077. getCurveLengths: function () {
  23078. // We use cache values if curves and cache array are same length
  23079. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  23080. return this.cacheLengths;
  23081. }
  23082. // Get length of sub-curve
  23083. // Push sums into cached array
  23084. var lengths = [], sums = 0;
  23085. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  23086. sums += this.curves[ i ].getLength();
  23087. lengths.push( sums );
  23088. }
  23089. this.cacheLengths = lengths;
  23090. return lengths;
  23091. },
  23092. getSpacedPoints: function ( divisions ) {
  23093. if ( divisions === undefined ) divisions = 40;
  23094. var points = [];
  23095. for ( var i = 0; i <= divisions; i ++ ) {
  23096. points.push( this.getPoint( i / divisions ) );
  23097. }
  23098. if ( this.autoClose ) {
  23099. points.push( points[ 0 ] );
  23100. }
  23101. return points;
  23102. },
  23103. getPoints: function ( divisions ) {
  23104. divisions = divisions || 12;
  23105. var points = [], last;
  23106. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  23107. var curve = curves[ i ];
  23108. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  23109. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  23110. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  23111. : divisions;
  23112. var pts = curve.getPoints( resolution );
  23113. for ( var j = 0; j < pts.length; j ++ ) {
  23114. var point = pts[ j ];
  23115. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  23116. points.push( point );
  23117. last = point;
  23118. }
  23119. }
  23120. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  23121. points.push( points[ 0 ] );
  23122. }
  23123. return points;
  23124. },
  23125. copy: function ( source ) {
  23126. Curve.prototype.copy.call( this, source );
  23127. this.curves = [];
  23128. for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
  23129. var curve = source.curves[ i ];
  23130. this.curves.push( curve.clone() );
  23131. }
  23132. this.autoClose = source.autoClose;
  23133. return this;
  23134. },
  23135. toJSON: function () {
  23136. var data = Curve.prototype.toJSON.call( this );
  23137. data.autoClose = this.autoClose;
  23138. data.curves = [];
  23139. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  23140. var curve = this.curves[ i ];
  23141. data.curves.push( curve.toJSON() );
  23142. }
  23143. return data;
  23144. },
  23145. fromJSON: function ( json ) {
  23146. Curve.prototype.fromJSON.call( this, json );
  23147. this.autoClose = json.autoClose;
  23148. this.curves = [];
  23149. for ( var i = 0, l = json.curves.length; i < l; i ++ ) {
  23150. var curve = json.curves[ i ];
  23151. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  23152. }
  23153. return this;
  23154. }
  23155. } );
  23156. /**
  23157. * @author zz85 / http://www.lab4games.net/zz85/blog
  23158. * Creates free form 2d path using series of points, lines or curves.
  23159. **/
  23160. function Path( points ) {
  23161. CurvePath.call( this );
  23162. this.type = 'Path';
  23163. this.currentPoint = new Vector2();
  23164. if ( points ) {
  23165. this.setFromPoints( points );
  23166. }
  23167. }
  23168. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  23169. constructor: Path,
  23170. setFromPoints: function ( points ) {
  23171. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  23172. for ( var i = 1, l = points.length; i < l; i ++ ) {
  23173. this.lineTo( points[ i ].x, points[ i ].y );
  23174. }
  23175. },
  23176. moveTo: function ( x, y ) {
  23177. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  23178. },
  23179. lineTo: function ( x, y ) {
  23180. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  23181. this.curves.push( curve );
  23182. this.currentPoint.set( x, y );
  23183. },
  23184. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  23185. var curve = new QuadraticBezierCurve(
  23186. this.currentPoint.clone(),
  23187. new Vector2( aCPx, aCPy ),
  23188. new Vector2( aX, aY )
  23189. );
  23190. this.curves.push( curve );
  23191. this.currentPoint.set( aX, aY );
  23192. },
  23193. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  23194. var curve = new CubicBezierCurve(
  23195. this.currentPoint.clone(),
  23196. new Vector2( aCP1x, aCP1y ),
  23197. new Vector2( aCP2x, aCP2y ),
  23198. new Vector2( aX, aY )
  23199. );
  23200. this.curves.push( curve );
  23201. this.currentPoint.set( aX, aY );
  23202. },
  23203. splineThru: function ( pts /*Array of Vector*/ ) {
  23204. var npts = [ this.currentPoint.clone() ].concat( pts );
  23205. var curve = new SplineCurve( npts );
  23206. this.curves.push( curve );
  23207. this.currentPoint.copy( pts[ pts.length - 1 ] );
  23208. },
  23209. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  23210. var x0 = this.currentPoint.x;
  23211. var y0 = this.currentPoint.y;
  23212. this.absarc( aX + x0, aY + y0, aRadius,
  23213. aStartAngle, aEndAngle, aClockwise );
  23214. },
  23215. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  23216. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  23217. },
  23218. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  23219. var x0 = this.currentPoint.x;
  23220. var y0 = this.currentPoint.y;
  23221. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  23222. },
  23223. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  23224. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  23225. if ( this.curves.length > 0 ) {
  23226. // if a previous curve is present, attempt to join
  23227. var firstPoint = curve.getPoint( 0 );
  23228. if ( ! firstPoint.equals( this.currentPoint ) ) {
  23229. this.lineTo( firstPoint.x, firstPoint.y );
  23230. }
  23231. }
  23232. this.curves.push( curve );
  23233. var lastPoint = curve.getPoint( 1 );
  23234. this.currentPoint.copy( lastPoint );
  23235. },
  23236. copy: function ( source ) {
  23237. CurvePath.prototype.copy.call( this, source );
  23238. this.currentPoint.copy( source.currentPoint );
  23239. return this;
  23240. },
  23241. toJSON: function () {
  23242. var data = CurvePath.prototype.toJSON.call( this );
  23243. data.currentPoint = this.currentPoint.toArray();
  23244. return data;
  23245. },
  23246. fromJSON: function ( json ) {
  23247. CurvePath.prototype.fromJSON.call( this, json );
  23248. this.currentPoint.fromArray( json.currentPoint );
  23249. return this;
  23250. }
  23251. } );
  23252. /**
  23253. * @author zz85 / http://www.lab4games.net/zz85/blog
  23254. * Defines a 2d shape plane using paths.
  23255. **/
  23256. // STEP 1 Create a path.
  23257. // STEP 2 Turn path into shape.
  23258. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  23259. // STEP 3a - Extract points from each shape, turn to vertices
  23260. // STEP 3b - Triangulate each shape, add faces.
  23261. function Shape( points ) {
  23262. Path.call( this, points );
  23263. this.uuid = _Math.generateUUID();
  23264. this.type = 'Shape';
  23265. this.holes = [];
  23266. }
  23267. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  23268. constructor: Shape,
  23269. getPointsHoles: function ( divisions ) {
  23270. var holesPts = [];
  23271. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  23272. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  23273. }
  23274. return holesPts;
  23275. },
  23276. // get points of shape and holes (keypoints based on segments parameter)
  23277. extractPoints: function ( divisions ) {
  23278. return {
  23279. shape: this.getPoints( divisions ),
  23280. holes: this.getPointsHoles( divisions )
  23281. };
  23282. },
  23283. copy: function ( source ) {
  23284. Path.prototype.copy.call( this, source );
  23285. this.holes = [];
  23286. for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
  23287. var hole = source.holes[ i ];
  23288. this.holes.push( hole.clone() );
  23289. }
  23290. return this;
  23291. },
  23292. toJSON: function () {
  23293. var data = Path.prototype.toJSON.call( this );
  23294. data.uuid = this.uuid;
  23295. data.holes = [];
  23296. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  23297. var hole = this.holes[ i ];
  23298. data.holes.push( hole.toJSON() );
  23299. }
  23300. return data;
  23301. },
  23302. fromJSON: function ( json ) {
  23303. Path.prototype.fromJSON.call( this, json );
  23304. this.uuid = json.uuid;
  23305. this.holes = [];
  23306. for ( var i = 0, l = json.holes.length; i < l; i ++ ) {
  23307. var hole = json.holes[ i ];
  23308. this.holes.push( new Path().fromJSON( hole ) );
  23309. }
  23310. return this;
  23311. }
  23312. } );
  23313. /**
  23314. * @author mrdoob / http://mrdoob.com/
  23315. * @author alteredq / http://alteredqualia.com/
  23316. */
  23317. function Light( color, intensity ) {
  23318. Object3D.call( this );
  23319. this.type = 'Light';
  23320. this.color = new Color( color );
  23321. this.intensity = intensity !== undefined ? intensity : 1;
  23322. this.receiveShadow = undefined;
  23323. }
  23324. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  23325. constructor: Light,
  23326. isLight: true,
  23327. copy: function ( source ) {
  23328. Object3D.prototype.copy.call( this, source );
  23329. this.color.copy( source.color );
  23330. this.intensity = source.intensity;
  23331. return this;
  23332. },
  23333. toJSON: function ( meta ) {
  23334. var data = Object3D.prototype.toJSON.call( this, meta );
  23335. data.object.color = this.color.getHex();
  23336. data.object.intensity = this.intensity;
  23337. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  23338. if ( this.distance !== undefined ) data.object.distance = this.distance;
  23339. if ( this.angle !== undefined ) data.object.angle = this.angle;
  23340. if ( this.decay !== undefined ) data.object.decay = this.decay;
  23341. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  23342. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  23343. return data;
  23344. }
  23345. } );
  23346. /**
  23347. * @author alteredq / http://alteredqualia.com/
  23348. */
  23349. function HemisphereLight( skyColor, groundColor, intensity ) {
  23350. Light.call( this, skyColor, intensity );
  23351. this.type = 'HemisphereLight';
  23352. this.castShadow = undefined;
  23353. this.position.copy( Object3D.DefaultUp );
  23354. this.updateMatrix();
  23355. this.groundColor = new Color( groundColor );
  23356. }
  23357. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23358. constructor: HemisphereLight,
  23359. isHemisphereLight: true,
  23360. copy: function ( source ) {
  23361. Light.prototype.copy.call( this, source );
  23362. this.groundColor.copy( source.groundColor );
  23363. return this;
  23364. }
  23365. } );
  23366. /**
  23367. * @author mrdoob / http://mrdoob.com/
  23368. */
  23369. function LightShadow( camera ) {
  23370. this.camera = camera;
  23371. this.bias = 0;
  23372. this.radius = 1;
  23373. this.mapSize = new Vector2( 512, 512 );
  23374. this.map = null;
  23375. this.matrix = new Matrix4();
  23376. }
  23377. Object.assign( LightShadow.prototype, {
  23378. copy: function ( source ) {
  23379. this.camera = source.camera.clone();
  23380. this.bias = source.bias;
  23381. this.radius = source.radius;
  23382. this.mapSize.copy( source.mapSize );
  23383. return this;
  23384. },
  23385. clone: function () {
  23386. return new this.constructor().copy( this );
  23387. },
  23388. toJSON: function () {
  23389. var object = {};
  23390. if ( this.bias !== 0 ) object.bias = this.bias;
  23391. if ( this.radius !== 1 ) object.radius = this.radius;
  23392. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  23393. object.camera = this.camera.toJSON( false ).object;
  23394. delete object.camera.matrix;
  23395. return object;
  23396. }
  23397. } );
  23398. /**
  23399. * @author mrdoob / http://mrdoob.com/
  23400. */
  23401. function SpotLightShadow() {
  23402. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  23403. }
  23404. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  23405. constructor: SpotLightShadow,
  23406. isSpotLightShadow: true,
  23407. update: function ( light ) {
  23408. var camera = this.camera;
  23409. var fov = _Math.RAD2DEG * 2 * light.angle;
  23410. var aspect = this.mapSize.width / this.mapSize.height;
  23411. var far = light.distance || camera.far;
  23412. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  23413. camera.fov = fov;
  23414. camera.aspect = aspect;
  23415. camera.far = far;
  23416. camera.updateProjectionMatrix();
  23417. }
  23418. }
  23419. } );
  23420. /**
  23421. * @author alteredq / http://alteredqualia.com/
  23422. */
  23423. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  23424. Light.call( this, color, intensity );
  23425. this.type = 'SpotLight';
  23426. this.position.copy( Object3D.DefaultUp );
  23427. this.updateMatrix();
  23428. this.target = new Object3D();
  23429. Object.defineProperty( this, 'power', {
  23430. get: function () {
  23431. // intensity = power per solid angle.
  23432. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23433. return this.intensity * Math.PI;
  23434. },
  23435. set: function ( power ) {
  23436. // intensity = power per solid angle.
  23437. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23438. this.intensity = power / Math.PI;
  23439. }
  23440. } );
  23441. this.distance = ( distance !== undefined ) ? distance : 0;
  23442. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  23443. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  23444. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  23445. this.shadow = new SpotLightShadow();
  23446. }
  23447. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23448. constructor: SpotLight,
  23449. isSpotLight: true,
  23450. copy: function ( source ) {
  23451. Light.prototype.copy.call( this, source );
  23452. this.distance = source.distance;
  23453. this.angle = source.angle;
  23454. this.penumbra = source.penumbra;
  23455. this.decay = source.decay;
  23456. this.target = source.target.clone();
  23457. this.shadow = source.shadow.clone();
  23458. return this;
  23459. }
  23460. } );
  23461. /**
  23462. * @author mrdoob / http://mrdoob.com/
  23463. */
  23464. function PointLight( color, intensity, distance, decay ) {
  23465. Light.call( this, color, intensity );
  23466. this.type = 'PointLight';
  23467. Object.defineProperty( this, 'power', {
  23468. get: function () {
  23469. // intensity = power per solid angle.
  23470. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23471. return this.intensity * 4 * Math.PI;
  23472. },
  23473. set: function ( power ) {
  23474. // intensity = power per solid angle.
  23475. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23476. this.intensity = power / ( 4 * Math.PI );
  23477. }
  23478. } );
  23479. this.distance = ( distance !== undefined ) ? distance : 0;
  23480. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  23481. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  23482. }
  23483. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23484. constructor: PointLight,
  23485. isPointLight: true,
  23486. copy: function ( source ) {
  23487. Light.prototype.copy.call( this, source );
  23488. this.distance = source.distance;
  23489. this.decay = source.decay;
  23490. this.shadow = source.shadow.clone();
  23491. return this;
  23492. }
  23493. } );
  23494. /**
  23495. * @author alteredq / http://alteredqualia.com/
  23496. * @author arose / http://github.com/arose
  23497. */
  23498. function OrthographicCamera( left, right, top, bottom, near, far ) {
  23499. Camera.call( this );
  23500. this.type = 'OrthographicCamera';
  23501. this.zoom = 1;
  23502. this.view = null;
  23503. this.left = ( left !== undefined ) ? left : - 1;
  23504. this.right = ( right !== undefined ) ? right : 1;
  23505. this.top = ( top !== undefined ) ? top : 1;
  23506. this.bottom = ( bottom !== undefined ) ? bottom : - 1;
  23507. this.near = ( near !== undefined ) ? near : 0.1;
  23508. this.far = ( far !== undefined ) ? far : 2000;
  23509. this.updateProjectionMatrix();
  23510. }
  23511. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  23512. constructor: OrthographicCamera,
  23513. isOrthographicCamera: true,
  23514. copy: function ( source, recursive ) {
  23515. Camera.prototype.copy.call( this, source, recursive );
  23516. this.left = source.left;
  23517. this.right = source.right;
  23518. this.top = source.top;
  23519. this.bottom = source.bottom;
  23520. this.near = source.near;
  23521. this.far = source.far;
  23522. this.zoom = source.zoom;
  23523. this.view = source.view === null ? null : Object.assign( {}, source.view );
  23524. return this;
  23525. },
  23526. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  23527. if ( this.view === null ) {
  23528. this.view = {
  23529. enabled: true,
  23530. fullWidth: 1,
  23531. fullHeight: 1,
  23532. offsetX: 0,
  23533. offsetY: 0,
  23534. width: 1,
  23535. height: 1
  23536. };
  23537. }
  23538. this.view.enabled = true;
  23539. this.view.fullWidth = fullWidth;
  23540. this.view.fullHeight = fullHeight;
  23541. this.view.offsetX = x;
  23542. this.view.offsetY = y;
  23543. this.view.width = width;
  23544. this.view.height = height;
  23545. this.updateProjectionMatrix();
  23546. },
  23547. clearViewOffset: function () {
  23548. if ( this.view !== null ) {
  23549. this.view.enabled = false;
  23550. }
  23551. this.updateProjectionMatrix();
  23552. },
  23553. updateProjectionMatrix: function () {
  23554. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  23555. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  23556. var cx = ( this.right + this.left ) / 2;
  23557. var cy = ( this.top + this.bottom ) / 2;
  23558. var left = cx - dx;
  23559. var right = cx + dx;
  23560. var top = cy + dy;
  23561. var bottom = cy - dy;
  23562. if ( this.view !== null && this.view.enabled ) {
  23563. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  23564. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  23565. var scaleW = ( this.right - this.left ) / this.view.width;
  23566. var scaleH = ( this.top - this.bottom ) / this.view.height;
  23567. left += scaleW * ( this.view.offsetX / zoomW );
  23568. right = left + scaleW * ( this.view.width / zoomW );
  23569. top -= scaleH * ( this.view.offsetY / zoomH );
  23570. bottom = top - scaleH * ( this.view.height / zoomH );
  23571. }
  23572. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  23573. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  23574. },
  23575. toJSON: function ( meta ) {
  23576. var data = Object3D.prototype.toJSON.call( this, meta );
  23577. data.object.zoom = this.zoom;
  23578. data.object.left = this.left;
  23579. data.object.right = this.right;
  23580. data.object.top = this.top;
  23581. data.object.bottom = this.bottom;
  23582. data.object.near = this.near;
  23583. data.object.far = this.far;
  23584. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  23585. return data;
  23586. }
  23587. } );
  23588. /**
  23589. * @author mrdoob / http://mrdoob.com/
  23590. */
  23591. function DirectionalLightShadow( ) {
  23592. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  23593. }
  23594. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  23595. constructor: DirectionalLightShadow
  23596. } );
  23597. /**
  23598. * @author mrdoob / http://mrdoob.com/
  23599. * @author alteredq / http://alteredqualia.com/
  23600. */
  23601. function DirectionalLight( color, intensity ) {
  23602. Light.call( this, color, intensity );
  23603. this.type = 'DirectionalLight';
  23604. this.position.copy( Object3D.DefaultUp );
  23605. this.updateMatrix();
  23606. this.target = new Object3D();
  23607. this.shadow = new DirectionalLightShadow();
  23608. }
  23609. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23610. constructor: DirectionalLight,
  23611. isDirectionalLight: true,
  23612. copy: function ( source ) {
  23613. Light.prototype.copy.call( this, source );
  23614. this.target = source.target.clone();
  23615. this.shadow = source.shadow.clone();
  23616. return this;
  23617. }
  23618. } );
  23619. /**
  23620. * @author mrdoob / http://mrdoob.com/
  23621. */
  23622. function AmbientLight( color, intensity ) {
  23623. Light.call( this, color, intensity );
  23624. this.type = 'AmbientLight';
  23625. this.castShadow = undefined;
  23626. }
  23627. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23628. constructor: AmbientLight,
  23629. isAmbientLight: true
  23630. } );
  23631. /**
  23632. * @author abelnation / http://github.com/abelnation
  23633. */
  23634. function RectAreaLight( color, intensity, width, height ) {
  23635. Light.call( this, color, intensity );
  23636. this.type = 'RectAreaLight';
  23637. this.width = ( width !== undefined ) ? width : 10;
  23638. this.height = ( height !== undefined ) ? height : 10;
  23639. }
  23640. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23641. constructor: RectAreaLight,
  23642. isRectAreaLight: true,
  23643. copy: function ( source ) {
  23644. Light.prototype.copy.call( this, source );
  23645. this.width = source.width;
  23646. this.height = source.height;
  23647. return this;
  23648. },
  23649. toJSON: function ( meta ) {
  23650. var data = Light.prototype.toJSON.call( this, meta );
  23651. data.object.width = this.width;
  23652. data.object.height = this.height;
  23653. return data;
  23654. }
  23655. } );
  23656. /**
  23657. * @author mrdoob / http://mrdoob.com/
  23658. */
  23659. function MaterialLoader( manager ) {
  23660. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23661. this.textures = {};
  23662. }
  23663. Object.assign( MaterialLoader.prototype, {
  23664. load: function ( url, onLoad, onProgress, onError ) {
  23665. var scope = this;
  23666. var loader = new FileLoader( scope.manager );
  23667. loader.setPath( scope.path );
  23668. loader.load( url, function ( text ) {
  23669. onLoad( scope.parse( JSON.parse( text ) ) );
  23670. }, onProgress, onError );
  23671. },
  23672. parse: function ( json ) {
  23673. var textures = this.textures;
  23674. function getTexture( name ) {
  23675. if ( textures[ name ] === undefined ) {
  23676. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  23677. }
  23678. return textures[ name ];
  23679. }
  23680. var material = new Materials[ json.type ]();
  23681. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  23682. if ( json.name !== undefined ) material.name = json.name;
  23683. if ( json.color !== undefined ) material.color.setHex( json.color );
  23684. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  23685. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  23686. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  23687. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  23688. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  23689. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  23690. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  23691. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  23692. if ( json.fog !== undefined ) material.fog = json.fog;
  23693. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  23694. if ( json.blending !== undefined ) material.blending = json.blending;
  23695. if ( json.combine !== undefined ) material.combine = json.combine;
  23696. if ( json.side !== undefined ) material.side = json.side;
  23697. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  23698. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  23699. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  23700. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  23701. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  23702. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  23703. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  23704. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  23705. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  23706. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  23707. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  23708. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  23709. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  23710. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  23711. if ( json.scale !== undefined ) material.scale = json.scale;
  23712. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  23713. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  23714. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  23715. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  23716. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  23717. if ( json.morphNormals !== undefined ) material.morphNormals = json.morphNormals;
  23718. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  23719. if ( json.visible !== undefined ) material.visible = json.visible;
  23720. if ( json.userData !== undefined ) material.userData = json.userData;
  23721. // Shader Material
  23722. if ( json.uniforms !== undefined ) {
  23723. for ( var name in json.uniforms ) {
  23724. var uniform = json.uniforms[ name ];
  23725. material.uniforms[ name ] = {};
  23726. switch ( uniform.type ) {
  23727. case 't':
  23728. material.uniforms[ name ].value = getTexture( uniform.value );
  23729. break;
  23730. case 'c':
  23731. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  23732. break;
  23733. case 'v2':
  23734. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  23735. break;
  23736. case 'v3':
  23737. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  23738. break;
  23739. case 'v4':
  23740. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  23741. break;
  23742. case 'm3':
  23743. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  23744. case 'm4':
  23745. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  23746. break;
  23747. default:
  23748. material.uniforms[ name ].value = uniform.value;
  23749. }
  23750. }
  23751. }
  23752. if ( json.defines !== undefined ) material.defines = json.defines;
  23753. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  23754. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  23755. if ( json.extensions !== undefined ) {
  23756. for ( var key in json.extensions ) {
  23757. material.extensions[ key ] = json.extensions[ key ];
  23758. }
  23759. }
  23760. // Deprecated
  23761. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  23762. // for PointsMaterial
  23763. if ( json.size !== undefined ) material.size = json.size;
  23764. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  23765. // maps
  23766. if ( json.map !== undefined ) material.map = getTexture( json.map );
  23767. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  23768. if ( json.alphaMap !== undefined ) {
  23769. material.alphaMap = getTexture( json.alphaMap );
  23770. material.transparent = true;
  23771. }
  23772. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  23773. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  23774. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  23775. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  23776. if ( json.normalScale !== undefined ) {
  23777. var normalScale = json.normalScale;
  23778. if ( Array.isArray( normalScale ) === false ) {
  23779. // Blender exporter used to export a scalar. See #7459
  23780. normalScale = [ normalScale, normalScale ];
  23781. }
  23782. material.normalScale = new Vector2().fromArray( normalScale );
  23783. }
  23784. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  23785. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  23786. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  23787. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  23788. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  23789. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  23790. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  23791. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  23792. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  23793. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  23794. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  23795. if ( json.refractionRatio !== undefined ) material.refractionRatio = json.refractionRatio;
  23796. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  23797. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  23798. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  23799. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  23800. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  23801. return material;
  23802. },
  23803. setPath: function ( value ) {
  23804. this.path = value;
  23805. return this;
  23806. },
  23807. setTextures: function ( value ) {
  23808. this.textures = value;
  23809. return this;
  23810. }
  23811. } );
  23812. /**
  23813. * @author Don McCurdy / https://www.donmccurdy.com
  23814. */
  23815. var LoaderUtils = {
  23816. decodeText: function ( array ) {
  23817. if ( typeof TextDecoder !== 'undefined' ) {
  23818. return new TextDecoder().decode( array );
  23819. }
  23820. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  23821. // throws a "maximum call stack size exceeded" error for large arrays.
  23822. var s = '';
  23823. for ( var i = 0, il = array.length; i < il; i ++ ) {
  23824. // Implicitly assumes little-endian.
  23825. s += String.fromCharCode( array[ i ] );
  23826. }
  23827. try {
  23828. // merges multi-byte utf-8 characters.
  23829. return decodeURIComponent( escape( s ) );
  23830. } catch ( e ) { // see #16358
  23831. return s;
  23832. }
  23833. },
  23834. extractUrlBase: function ( url ) {
  23835. var index = url.lastIndexOf( '/' );
  23836. if ( index === - 1 ) return './';
  23837. return url.substr( 0, index + 1 );
  23838. }
  23839. };
  23840. /**
  23841. * @author benaadams / https://twitter.com/ben_a_adams
  23842. */
  23843. function InstancedBufferGeometry() {
  23844. BufferGeometry.call( this );
  23845. this.type = 'InstancedBufferGeometry';
  23846. this.maxInstancedCount = undefined;
  23847. }
  23848. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  23849. constructor: InstancedBufferGeometry,
  23850. isInstancedBufferGeometry: true,
  23851. copy: function ( source ) {
  23852. BufferGeometry.prototype.copy.call( this, source );
  23853. this.maxInstancedCount = source.maxInstancedCount;
  23854. return this;
  23855. },
  23856. clone: function () {
  23857. return new this.constructor().copy( this );
  23858. },
  23859. toJSON: function () {
  23860. var data = BufferGeometry.prototype.toJSON.call( this );
  23861. data.maxInstancedCount = this.maxInstancedCount;
  23862. data.isInstancedBufferGeometry = true;
  23863. return data;
  23864. }
  23865. } );
  23866. /**
  23867. * @author benaadams / https://twitter.com/ben_a_adams
  23868. */
  23869. function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
  23870. if ( typeof ( normalized ) === 'number' ) {
  23871. meshPerAttribute = normalized;
  23872. normalized = false;
  23873. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  23874. }
  23875. BufferAttribute.call( this, array, itemSize, normalized );
  23876. this.meshPerAttribute = meshPerAttribute || 1;
  23877. }
  23878. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  23879. constructor: InstancedBufferAttribute,
  23880. isInstancedBufferAttribute: true,
  23881. copy: function ( source ) {
  23882. BufferAttribute.prototype.copy.call( this, source );
  23883. this.meshPerAttribute = source.meshPerAttribute;
  23884. return this;
  23885. },
  23886. toJSON: function () {
  23887. var data = BufferAttribute.prototype.toJSON.call( this );
  23888. data.meshPerAttribute = this.meshPerAttribute;
  23889. data.isInstancedBufferAttribute = true;
  23890. return data;
  23891. }
  23892. } );
  23893. /**
  23894. * @author mrdoob / http://mrdoob.com/
  23895. */
  23896. function BufferGeometryLoader( manager ) {
  23897. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23898. }
  23899. Object.assign( BufferGeometryLoader.prototype, {
  23900. load: function ( url, onLoad, onProgress, onError ) {
  23901. var scope = this;
  23902. var loader = new FileLoader( scope.manager );
  23903. loader.setPath( scope.path );
  23904. loader.load( url, function ( text ) {
  23905. onLoad( scope.parse( JSON.parse( text ) ) );
  23906. }, onProgress, onError );
  23907. },
  23908. parse: function ( json ) {
  23909. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  23910. var index = json.data.index;
  23911. if ( index !== undefined ) {
  23912. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  23913. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  23914. }
  23915. var attributes = json.data.attributes;
  23916. for ( var key in attributes ) {
  23917. var attribute = attributes[ key ];
  23918. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  23919. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  23920. var bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
  23921. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  23922. geometry.addAttribute( key, bufferAttribute );
  23923. }
  23924. var morphAttributes = json.data.morphAttributes;
  23925. if ( morphAttributes ) {
  23926. for ( var key in morphAttributes ) {
  23927. var attributeArray = morphAttributes[ key ];
  23928. var array = [];
  23929. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  23930. var attribute = attributeArray[ i ];
  23931. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  23932. var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  23933. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  23934. array.push( bufferAttribute );
  23935. }
  23936. geometry.morphAttributes[ key ] = array;
  23937. }
  23938. }
  23939. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  23940. if ( groups !== undefined ) {
  23941. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  23942. var group = groups[ i ];
  23943. geometry.addGroup( group.start, group.count, group.materialIndex );
  23944. }
  23945. }
  23946. var boundingSphere = json.data.boundingSphere;
  23947. if ( boundingSphere !== undefined ) {
  23948. var center = new Vector3();
  23949. if ( boundingSphere.center !== undefined ) {
  23950. center.fromArray( boundingSphere.center );
  23951. }
  23952. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  23953. }
  23954. if ( json.name ) geometry.name = json.name;
  23955. if ( json.userData ) geometry.userData = json.userData;
  23956. return geometry;
  23957. },
  23958. setPath: function ( value ) {
  23959. this.path = value;
  23960. return this;
  23961. }
  23962. } );
  23963. var TYPED_ARRAYS = {
  23964. Int8Array: Int8Array,
  23965. Uint8Array: Uint8Array,
  23966. // Workaround for IE11 pre KB2929437. See #11440
  23967. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  23968. Int16Array: Int16Array,
  23969. Uint16Array: Uint16Array,
  23970. Int32Array: Int32Array,
  23971. Uint32Array: Uint32Array,
  23972. Float32Array: Float32Array,
  23973. Float64Array: Float64Array
  23974. };
  23975. /**
  23976. * @author mrdoob / http://mrdoob.com/
  23977. */
  23978. function ObjectLoader( manager ) {
  23979. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23980. this.resourcePath = '';
  23981. }
  23982. Object.assign( ObjectLoader.prototype, {
  23983. crossOrigin: 'anonymous',
  23984. load: function ( url, onLoad, onProgress, onError ) {
  23985. var scope = this;
  23986. var path = ( this.path === undefined ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  23987. this.resourcePath = this.resourcePath || path;
  23988. var loader = new FileLoader( scope.manager );
  23989. loader.setPath( this.path );
  23990. loader.load( url, function ( text ) {
  23991. var json = null;
  23992. try {
  23993. json = JSON.parse( text );
  23994. } catch ( error ) {
  23995. if ( onError !== undefined ) onError( error );
  23996. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  23997. return;
  23998. }
  23999. var metadata = json.metadata;
  24000. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  24001. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  24002. return;
  24003. }
  24004. scope.parse( json, onLoad );
  24005. }, onProgress, onError );
  24006. },
  24007. setPath: function ( value ) {
  24008. this.path = value;
  24009. return this;
  24010. },
  24011. setResourcePath: function ( value ) {
  24012. this.resourcePath = value;
  24013. return this;
  24014. },
  24015. setCrossOrigin: function ( value ) {
  24016. this.crossOrigin = value;
  24017. return this;
  24018. },
  24019. parse: function ( json, onLoad ) {
  24020. var shapes = this.parseShape( json.shapes );
  24021. var geometries = this.parseGeometries( json.geometries, shapes );
  24022. var images = this.parseImages( json.images, function () {
  24023. if ( onLoad !== undefined ) onLoad( object );
  24024. } );
  24025. var textures = this.parseTextures( json.textures, images );
  24026. var materials = this.parseMaterials( json.materials, textures );
  24027. var object = this.parseObject( json.object, geometries, materials );
  24028. if ( json.animations ) {
  24029. object.animations = this.parseAnimations( json.animations );
  24030. }
  24031. if ( json.images === undefined || json.images.length === 0 ) {
  24032. if ( onLoad !== undefined ) onLoad( object );
  24033. }
  24034. return object;
  24035. },
  24036. parseShape: function ( json ) {
  24037. var shapes = {};
  24038. if ( json !== undefined ) {
  24039. for ( var i = 0, l = json.length; i < l; i ++ ) {
  24040. var shape = new Shape().fromJSON( json[ i ] );
  24041. shapes[ shape.uuid ] = shape;
  24042. }
  24043. }
  24044. return shapes;
  24045. },
  24046. parseGeometries: function ( json, shapes ) {
  24047. var geometries = {};
  24048. if ( json !== undefined ) {
  24049. var bufferGeometryLoader = new BufferGeometryLoader();
  24050. for ( var i = 0, l = json.length; i < l; i ++ ) {
  24051. var geometry;
  24052. var data = json[ i ];
  24053. switch ( data.type ) {
  24054. case 'PlaneGeometry':
  24055. case 'PlaneBufferGeometry':
  24056. geometry = new Geometries[ data.type ](
  24057. data.width,
  24058. data.height,
  24059. data.widthSegments,
  24060. data.heightSegments
  24061. );
  24062. break;
  24063. case 'BoxGeometry':
  24064. case 'BoxBufferGeometry':
  24065. case 'CubeGeometry': // backwards compatible
  24066. geometry = new Geometries[ data.type ](
  24067. data.width,
  24068. data.height,
  24069. data.depth,
  24070. data.widthSegments,
  24071. data.heightSegments,
  24072. data.depthSegments
  24073. );
  24074. break;
  24075. case 'CircleGeometry':
  24076. case 'CircleBufferGeometry':
  24077. geometry = new Geometries[ data.type ](
  24078. data.radius,
  24079. data.segments,
  24080. data.thetaStart,
  24081. data.thetaLength
  24082. );
  24083. break;
  24084. case 'CylinderGeometry':
  24085. case 'CylinderBufferGeometry':
  24086. geometry = new Geometries[ data.type ](
  24087. data.radiusTop,
  24088. data.radiusBottom,
  24089. data.height,
  24090. data.radialSegments,
  24091. data.heightSegments,
  24092. data.openEnded,
  24093. data.thetaStart,
  24094. data.thetaLength
  24095. );
  24096. break;
  24097. case 'ConeGeometry':
  24098. case 'ConeBufferGeometry':
  24099. geometry = new Geometries[ data.type ](
  24100. data.radius,
  24101. data.height,
  24102. data.radialSegments,
  24103. data.heightSegments,
  24104. data.openEnded,
  24105. data.thetaStart,
  24106. data.thetaLength
  24107. );
  24108. break;
  24109. case 'SphereGeometry':
  24110. case 'SphereBufferGeometry':
  24111. geometry = new Geometries[ data.type ](
  24112. data.radius,
  24113. data.widthSegments,
  24114. data.heightSegments,
  24115. data.phiStart,
  24116. data.phiLength,
  24117. data.thetaStart,
  24118. data.thetaLength
  24119. );
  24120. break;
  24121. case 'DodecahedronGeometry':
  24122. case 'DodecahedronBufferGeometry':
  24123. case 'IcosahedronGeometry':
  24124. case 'IcosahedronBufferGeometry':
  24125. case 'OctahedronGeometry':
  24126. case 'OctahedronBufferGeometry':
  24127. case 'TetrahedronGeometry':
  24128. case 'TetrahedronBufferGeometry':
  24129. geometry = new Geometries[ data.type ](
  24130. data.radius,
  24131. data.detail
  24132. );
  24133. break;
  24134. case 'RingGeometry':
  24135. case 'RingBufferGeometry':
  24136. geometry = new Geometries[ data.type ](
  24137. data.innerRadius,
  24138. data.outerRadius,
  24139. data.thetaSegments,
  24140. data.phiSegments,
  24141. data.thetaStart,
  24142. data.thetaLength
  24143. );
  24144. break;
  24145. case 'TorusGeometry':
  24146. case 'TorusBufferGeometry':
  24147. geometry = new Geometries[ data.type ](
  24148. data.radius,
  24149. data.tube,
  24150. data.radialSegments,
  24151. data.tubularSegments,
  24152. data.arc
  24153. );
  24154. break;
  24155. case 'TorusKnotGeometry':
  24156. case 'TorusKnotBufferGeometry':
  24157. geometry = new Geometries[ data.type ](
  24158. data.radius,
  24159. data.tube,
  24160. data.tubularSegments,
  24161. data.radialSegments,
  24162. data.p,
  24163. data.q
  24164. );
  24165. break;
  24166. case 'TubeGeometry':
  24167. case 'TubeBufferGeometry':
  24168. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24169. // User defined curves or instances of CurvePath will not be deserialized.
  24170. geometry = new Geometries[ data.type ](
  24171. new Curves[ data.path.type ]().fromJSON( data.path ),
  24172. data.tubularSegments,
  24173. data.radius,
  24174. data.radialSegments,
  24175. data.closed
  24176. );
  24177. break;
  24178. case 'LatheGeometry':
  24179. case 'LatheBufferGeometry':
  24180. geometry = new Geometries[ data.type ](
  24181. data.points,
  24182. data.segments,
  24183. data.phiStart,
  24184. data.phiLength
  24185. );
  24186. break;
  24187. case 'PolyhedronGeometry':
  24188. case 'PolyhedronBufferGeometry':
  24189. geometry = new Geometries[ data.type ](
  24190. data.vertices,
  24191. data.indices,
  24192. data.radius,
  24193. data.details
  24194. );
  24195. break;
  24196. case 'ShapeGeometry':
  24197. case 'ShapeBufferGeometry':
  24198. var geometryShapes = [];
  24199. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  24200. var shape = shapes[ data.shapes[ j ] ];
  24201. geometryShapes.push( shape );
  24202. }
  24203. geometry = new Geometries[ data.type ](
  24204. geometryShapes,
  24205. data.curveSegments
  24206. );
  24207. break;
  24208. case 'ExtrudeGeometry':
  24209. case 'ExtrudeBufferGeometry':
  24210. var geometryShapes = [];
  24211. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  24212. var shape = shapes[ data.shapes[ j ] ];
  24213. geometryShapes.push( shape );
  24214. }
  24215. var extrudePath = data.options.extrudePath;
  24216. if ( extrudePath !== undefined ) {
  24217. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  24218. }
  24219. geometry = new Geometries[ data.type ](
  24220. geometryShapes,
  24221. data.options
  24222. );
  24223. break;
  24224. case 'BufferGeometry':
  24225. case 'InstancedBufferGeometry':
  24226. geometry = bufferGeometryLoader.parse( data );
  24227. break;
  24228. case 'Geometry':
  24229. if ( 'THREE' in window && 'LegacyJSONLoader' in THREE ) {
  24230. var geometryLoader = new THREE.LegacyJSONLoader();
  24231. geometry = geometryLoader.parse( data, this.resourcePath ).geometry;
  24232. } else {
  24233. console.error( 'THREE.ObjectLoader: You have to import LegacyJSONLoader in order load geometry data of type "Geometry".' );
  24234. }
  24235. break;
  24236. default:
  24237. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  24238. continue;
  24239. }
  24240. geometry.uuid = data.uuid;
  24241. if ( data.name !== undefined ) geometry.name = data.name;
  24242. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  24243. geometries[ data.uuid ] = geometry;
  24244. }
  24245. }
  24246. return geometries;
  24247. },
  24248. parseMaterials: function ( json, textures ) {
  24249. var cache = {}; // MultiMaterial
  24250. var materials = {};
  24251. if ( json !== undefined ) {
  24252. var loader = new MaterialLoader();
  24253. loader.setTextures( textures );
  24254. for ( var i = 0, l = json.length; i < l; i ++ ) {
  24255. var data = json[ i ];
  24256. if ( data.type === 'MultiMaterial' ) {
  24257. // Deprecated
  24258. var array = [];
  24259. for ( var j = 0; j < data.materials.length; j ++ ) {
  24260. var material = data.materials[ j ];
  24261. if ( cache[ material.uuid ] === undefined ) {
  24262. cache[ material.uuid ] = loader.parse( material );
  24263. }
  24264. array.push( cache[ material.uuid ] );
  24265. }
  24266. materials[ data.uuid ] = array;
  24267. } else {
  24268. if ( cache[ data.uuid ] === undefined ) {
  24269. cache[ data.uuid ] = loader.parse( data );
  24270. }
  24271. materials[ data.uuid ] = cache[ data.uuid ];
  24272. }
  24273. }
  24274. }
  24275. return materials;
  24276. },
  24277. parseAnimations: function ( json ) {
  24278. var animations = [];
  24279. for ( var i = 0; i < json.length; i ++ ) {
  24280. var data = json[ i ];
  24281. var clip = AnimationClip.parse( data );
  24282. if ( data.uuid !== undefined ) clip.uuid = data.uuid;
  24283. animations.push( clip );
  24284. }
  24285. return animations;
  24286. },
  24287. parseImages: function ( json, onLoad ) {
  24288. var scope = this;
  24289. var images = {};
  24290. function loadImage( url ) {
  24291. scope.manager.itemStart( url );
  24292. return loader.load( url, function () {
  24293. scope.manager.itemEnd( url );
  24294. }, undefined, function () {
  24295. scope.manager.itemError( url );
  24296. scope.manager.itemEnd( url );
  24297. } );
  24298. }
  24299. if ( json !== undefined && json.length > 0 ) {
  24300. var manager = new LoadingManager( onLoad );
  24301. var loader = new ImageLoader( manager );
  24302. loader.setCrossOrigin( this.crossOrigin );
  24303. for ( var i = 0, il = json.length; i < il; i ++ ) {
  24304. var image = json[ i ];
  24305. var url = image.url;
  24306. if ( Array.isArray( url ) ) {
  24307. // load array of images e.g CubeTexture
  24308. images[ image.uuid ] = [];
  24309. for ( var j = 0, jl = url.length; j < jl; j ++ ) {
  24310. var currentUrl = url[ j ];
  24311. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
  24312. images[ image.uuid ].push( loadImage( path ) );
  24313. }
  24314. } else {
  24315. // load single image
  24316. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
  24317. images[ image.uuid ] = loadImage( path );
  24318. }
  24319. }
  24320. }
  24321. return images;
  24322. },
  24323. parseTextures: function ( json, images ) {
  24324. function parseConstant( value, type ) {
  24325. if ( typeof value === 'number' ) return value;
  24326. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  24327. return type[ value ];
  24328. }
  24329. var textures = {};
  24330. if ( json !== undefined ) {
  24331. for ( var i = 0, l = json.length; i < l; i ++ ) {
  24332. var data = json[ i ];
  24333. if ( data.image === undefined ) {
  24334. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  24335. }
  24336. if ( images[ data.image ] === undefined ) {
  24337. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  24338. }
  24339. var texture;
  24340. if ( Array.isArray( images[ data.image ] ) ) {
  24341. texture = new CubeTexture( images[ data.image ] );
  24342. } else {
  24343. texture = new Texture( images[ data.image ] );
  24344. }
  24345. texture.needsUpdate = true;
  24346. texture.uuid = data.uuid;
  24347. if ( data.name !== undefined ) texture.name = data.name;
  24348. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  24349. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  24350. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  24351. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  24352. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  24353. if ( data.wrap !== undefined ) {
  24354. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  24355. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  24356. }
  24357. if ( data.format !== undefined ) texture.format = data.format;
  24358. if ( data.type !== undefined ) texture.type = data.type;
  24359. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  24360. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  24361. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  24362. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  24363. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  24364. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  24365. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  24366. textures[ data.uuid ] = texture;
  24367. }
  24368. }
  24369. return textures;
  24370. },
  24371. parseObject: function ( data, geometries, materials ) {
  24372. var object;
  24373. function getGeometry( name ) {
  24374. if ( geometries[ name ] === undefined ) {
  24375. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  24376. }
  24377. return geometries[ name ];
  24378. }
  24379. function getMaterial( name ) {
  24380. if ( name === undefined ) return undefined;
  24381. if ( Array.isArray( name ) ) {
  24382. var array = [];
  24383. for ( var i = 0, l = name.length; i < l; i ++ ) {
  24384. var uuid = name[ i ];
  24385. if ( materials[ uuid ] === undefined ) {
  24386. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  24387. }
  24388. array.push( materials[ uuid ] );
  24389. }
  24390. return array;
  24391. }
  24392. if ( materials[ name ] === undefined ) {
  24393. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  24394. }
  24395. return materials[ name ];
  24396. }
  24397. switch ( data.type ) {
  24398. case 'Scene':
  24399. object = new Scene();
  24400. if ( data.background !== undefined ) {
  24401. if ( Number.isInteger( data.background ) ) {
  24402. object.background = new Color( data.background );
  24403. }
  24404. }
  24405. if ( data.fog !== undefined ) {
  24406. if ( data.fog.type === 'Fog' ) {
  24407. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  24408. } else if ( data.fog.type === 'FogExp2' ) {
  24409. object.fog = new FogExp2( data.fog.color, data.fog.density );
  24410. }
  24411. }
  24412. break;
  24413. case 'PerspectiveCamera':
  24414. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  24415. if ( data.focus !== undefined ) object.focus = data.focus;
  24416. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  24417. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  24418. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  24419. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  24420. break;
  24421. case 'OrthographicCamera':
  24422. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  24423. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  24424. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  24425. break;
  24426. case 'AmbientLight':
  24427. object = new AmbientLight( data.color, data.intensity );
  24428. break;
  24429. case 'DirectionalLight':
  24430. object = new DirectionalLight( data.color, data.intensity );
  24431. break;
  24432. case 'PointLight':
  24433. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  24434. break;
  24435. case 'RectAreaLight':
  24436. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  24437. break;
  24438. case 'SpotLight':
  24439. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  24440. break;
  24441. case 'HemisphereLight':
  24442. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  24443. break;
  24444. case 'SkinnedMesh':
  24445. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  24446. case 'Mesh':
  24447. var geometry = getGeometry( data.geometry );
  24448. var material = getMaterial( data.material );
  24449. if ( geometry.bones && geometry.bones.length > 0 ) {
  24450. object = new SkinnedMesh( geometry, material );
  24451. } else {
  24452. object = new Mesh( geometry, material );
  24453. }
  24454. if ( data.drawMode !== undefined ) object.setDrawMode( data.drawMode );
  24455. break;
  24456. case 'LOD':
  24457. object = new LOD();
  24458. break;
  24459. case 'Line':
  24460. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  24461. break;
  24462. case 'LineLoop':
  24463. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  24464. break;
  24465. case 'LineSegments':
  24466. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  24467. break;
  24468. case 'PointCloud':
  24469. case 'Points':
  24470. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  24471. break;
  24472. case 'Sprite':
  24473. object = new Sprite( getMaterial( data.material ) );
  24474. break;
  24475. case 'Group':
  24476. object = new Group();
  24477. break;
  24478. default:
  24479. object = new Object3D();
  24480. }
  24481. object.uuid = data.uuid;
  24482. if ( data.name !== undefined ) object.name = data.name;
  24483. if ( data.matrix !== undefined ) {
  24484. object.matrix.fromArray( data.matrix );
  24485. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24486. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  24487. } else {
  24488. if ( data.position !== undefined ) object.position.fromArray( data.position );
  24489. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  24490. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  24491. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  24492. }
  24493. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  24494. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  24495. if ( data.shadow ) {
  24496. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  24497. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  24498. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  24499. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  24500. }
  24501. if ( data.visible !== undefined ) object.visible = data.visible;
  24502. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  24503. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  24504. if ( data.userData !== undefined ) object.userData = data.userData;
  24505. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  24506. if ( data.children !== undefined ) {
  24507. var children = data.children;
  24508. for ( var i = 0; i < children.length; i ++ ) {
  24509. object.add( this.parseObject( children[ i ], geometries, materials ) );
  24510. }
  24511. }
  24512. if ( data.type === 'LOD' ) {
  24513. var levels = data.levels;
  24514. for ( var l = 0; l < levels.length; l ++ ) {
  24515. var level = levels[ l ];
  24516. var child = object.getObjectByProperty( 'uuid', level.object );
  24517. if ( child !== undefined ) {
  24518. object.addLevel( child, level.distance );
  24519. }
  24520. }
  24521. }
  24522. return object;
  24523. }
  24524. } );
  24525. var TEXTURE_MAPPING = {
  24526. UVMapping: UVMapping,
  24527. CubeReflectionMapping: CubeReflectionMapping,
  24528. CubeRefractionMapping: CubeRefractionMapping,
  24529. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  24530. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  24531. SphericalReflectionMapping: SphericalReflectionMapping,
  24532. CubeUVReflectionMapping: CubeUVReflectionMapping,
  24533. CubeUVRefractionMapping: CubeUVRefractionMapping
  24534. };
  24535. var TEXTURE_WRAPPING = {
  24536. RepeatWrapping: RepeatWrapping,
  24537. ClampToEdgeWrapping: ClampToEdgeWrapping,
  24538. MirroredRepeatWrapping: MirroredRepeatWrapping
  24539. };
  24540. var TEXTURE_FILTER = {
  24541. NearestFilter: NearestFilter,
  24542. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  24543. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  24544. LinearFilter: LinearFilter,
  24545. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  24546. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  24547. };
  24548. /**
  24549. * @author thespite / http://clicktorelease.com/
  24550. */
  24551. function ImageBitmapLoader( manager ) {
  24552. if ( typeof createImageBitmap === 'undefined' ) {
  24553. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  24554. }
  24555. if ( typeof fetch === 'undefined' ) {
  24556. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  24557. }
  24558. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  24559. this.options = undefined;
  24560. }
  24561. ImageBitmapLoader.prototype = {
  24562. constructor: ImageBitmapLoader,
  24563. setOptions: function setOptions( options ) {
  24564. this.options = options;
  24565. return this;
  24566. },
  24567. load: function ( url, onLoad, onProgress, onError ) {
  24568. if ( url === undefined ) url = '';
  24569. if ( this.path !== undefined ) url = this.path + url;
  24570. url = this.manager.resolveURL( url );
  24571. var scope = this;
  24572. var cached = Cache.get( url );
  24573. if ( cached !== undefined ) {
  24574. scope.manager.itemStart( url );
  24575. setTimeout( function () {
  24576. if ( onLoad ) onLoad( cached );
  24577. scope.manager.itemEnd( url );
  24578. }, 0 );
  24579. return cached;
  24580. }
  24581. fetch( url ).then( function ( res ) {
  24582. return res.blob();
  24583. } ).then( function ( blob ) {
  24584. if ( scope.options === undefined ) {
  24585. // Workaround for FireFox. It causes an error if you pass options.
  24586. return createImageBitmap( blob );
  24587. } else {
  24588. return createImageBitmap( blob, scope.options );
  24589. }
  24590. } ).then( function ( imageBitmap ) {
  24591. Cache.add( url, imageBitmap );
  24592. if ( onLoad ) onLoad( imageBitmap );
  24593. scope.manager.itemEnd( url );
  24594. } ).catch( function ( e ) {
  24595. if ( onError ) onError( e );
  24596. scope.manager.itemError( url );
  24597. scope.manager.itemEnd( url );
  24598. } );
  24599. scope.manager.itemStart( url );
  24600. },
  24601. setCrossOrigin: function ( /* value */ ) {
  24602. return this;
  24603. },
  24604. setPath: function ( value ) {
  24605. this.path = value;
  24606. return this;
  24607. }
  24608. };
  24609. /**
  24610. * @author zz85 / http://www.lab4games.net/zz85/blog
  24611. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  24612. **/
  24613. function ShapePath() {
  24614. this.type = 'ShapePath';
  24615. this.color = new Color();
  24616. this.subPaths = [];
  24617. this.currentPath = null;
  24618. }
  24619. Object.assign( ShapePath.prototype, {
  24620. moveTo: function ( x, y ) {
  24621. this.currentPath = new Path();
  24622. this.subPaths.push( this.currentPath );
  24623. this.currentPath.moveTo( x, y );
  24624. },
  24625. lineTo: function ( x, y ) {
  24626. this.currentPath.lineTo( x, y );
  24627. },
  24628. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  24629. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  24630. },
  24631. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  24632. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  24633. },
  24634. splineThru: function ( pts ) {
  24635. this.currentPath.splineThru( pts );
  24636. },
  24637. toShapes: function ( isCCW, noHoles ) {
  24638. function toShapesNoHoles( inSubpaths ) {
  24639. var shapes = [];
  24640. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  24641. var tmpPath = inSubpaths[ i ];
  24642. var tmpShape = new Shape();
  24643. tmpShape.curves = tmpPath.curves;
  24644. shapes.push( tmpShape );
  24645. }
  24646. return shapes;
  24647. }
  24648. function isPointInsidePolygon( inPt, inPolygon ) {
  24649. var polyLen = inPolygon.length;
  24650. // inPt on polygon contour => immediate success or
  24651. // toggling of inside/outside at every single! intersection point of an edge
  24652. // with the horizontal line through inPt, left of inPt
  24653. // not counting lowerY endpoints of edges and whole edges on that line
  24654. var inside = false;
  24655. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  24656. var edgeLowPt = inPolygon[ p ];
  24657. var edgeHighPt = inPolygon[ q ];
  24658. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  24659. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  24660. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  24661. // not parallel
  24662. if ( edgeDy < 0 ) {
  24663. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  24664. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  24665. }
  24666. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  24667. if ( inPt.y === edgeLowPt.y ) {
  24668. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  24669. // continue; // no intersection or edgeLowPt => doesn't count !!!
  24670. } else {
  24671. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  24672. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  24673. if ( perpEdge < 0 ) continue;
  24674. inside = ! inside; // true intersection left of inPt
  24675. }
  24676. } else {
  24677. // parallel or collinear
  24678. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  24679. // edge lies on the same horizontal line as inPt
  24680. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  24681. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  24682. // continue;
  24683. }
  24684. }
  24685. return inside;
  24686. }
  24687. var isClockWise = ShapeUtils.isClockWise;
  24688. var subPaths = this.subPaths;
  24689. if ( subPaths.length === 0 ) return [];
  24690. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  24691. var solid, tmpPath, tmpShape, shapes = [];
  24692. if ( subPaths.length === 1 ) {
  24693. tmpPath = subPaths[ 0 ];
  24694. tmpShape = new Shape();
  24695. tmpShape.curves = tmpPath.curves;
  24696. shapes.push( tmpShape );
  24697. return shapes;
  24698. }
  24699. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  24700. holesFirst = isCCW ? ! holesFirst : holesFirst;
  24701. // console.log("Holes first", holesFirst);
  24702. var betterShapeHoles = [];
  24703. var newShapes = [];
  24704. var newShapeHoles = [];
  24705. var mainIdx = 0;
  24706. var tmpPoints;
  24707. newShapes[ mainIdx ] = undefined;
  24708. newShapeHoles[ mainIdx ] = [];
  24709. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  24710. tmpPath = subPaths[ i ];
  24711. tmpPoints = tmpPath.getPoints();
  24712. solid = isClockWise( tmpPoints );
  24713. solid = isCCW ? ! solid : solid;
  24714. if ( solid ) {
  24715. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  24716. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  24717. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  24718. if ( holesFirst ) mainIdx ++;
  24719. newShapeHoles[ mainIdx ] = [];
  24720. //console.log('cw', i);
  24721. } else {
  24722. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  24723. //console.log('ccw', i);
  24724. }
  24725. }
  24726. // only Holes? -> probably all Shapes with wrong orientation
  24727. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  24728. if ( newShapes.length > 1 ) {
  24729. var ambiguous = false;
  24730. var toChange = [];
  24731. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  24732. betterShapeHoles[ sIdx ] = [];
  24733. }
  24734. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  24735. var sho = newShapeHoles[ sIdx ];
  24736. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  24737. var ho = sho[ hIdx ];
  24738. var hole_unassigned = true;
  24739. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  24740. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  24741. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  24742. if ( hole_unassigned ) {
  24743. hole_unassigned = false;
  24744. betterShapeHoles[ s2Idx ].push( ho );
  24745. } else {
  24746. ambiguous = true;
  24747. }
  24748. }
  24749. }
  24750. if ( hole_unassigned ) {
  24751. betterShapeHoles[ sIdx ].push( ho );
  24752. }
  24753. }
  24754. }
  24755. // console.log("ambiguous: ", ambiguous);
  24756. if ( toChange.length > 0 ) {
  24757. // console.log("to change: ", toChange);
  24758. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  24759. }
  24760. }
  24761. var tmpHoles;
  24762. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  24763. tmpShape = newShapes[ i ].s;
  24764. shapes.push( tmpShape );
  24765. tmpHoles = newShapeHoles[ i ];
  24766. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  24767. tmpShape.holes.push( tmpHoles[ j ].h );
  24768. }
  24769. }
  24770. //console.log("shape", shapes);
  24771. return shapes;
  24772. }
  24773. } );
  24774. /**
  24775. * @author zz85 / http://www.lab4games.net/zz85/blog
  24776. * @author mrdoob / http://mrdoob.com/
  24777. */
  24778. function Font( data ) {
  24779. this.type = 'Font';
  24780. this.data = data;
  24781. }
  24782. Object.assign( Font.prototype, {
  24783. isFont: true,
  24784. generateShapes: function ( text, size ) {
  24785. if ( size === undefined ) size = 100;
  24786. var shapes = [];
  24787. var paths = createPaths( text, size, this.data );
  24788. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  24789. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  24790. }
  24791. return shapes;
  24792. }
  24793. } );
  24794. function createPaths( text, size, data ) {
  24795. var chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // see #13988
  24796. var scale = size / data.resolution;
  24797. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  24798. var paths = [];
  24799. var offsetX = 0, offsetY = 0;
  24800. for ( var i = 0; i < chars.length; i ++ ) {
  24801. var char = chars[ i ];
  24802. if ( char === '\n' ) {
  24803. offsetX = 0;
  24804. offsetY -= line_height;
  24805. } else {
  24806. var ret = createPath( char, scale, offsetX, offsetY, data );
  24807. offsetX += ret.offsetX;
  24808. paths.push( ret.path );
  24809. }
  24810. }
  24811. return paths;
  24812. }
  24813. function createPath( char, scale, offsetX, offsetY, data ) {
  24814. var glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  24815. if ( ! glyph ) return;
  24816. var path = new ShapePath();
  24817. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  24818. if ( glyph.o ) {
  24819. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  24820. for ( var i = 0, l = outline.length; i < l; ) {
  24821. var action = outline[ i ++ ];
  24822. switch ( action ) {
  24823. case 'm': // moveTo
  24824. x = outline[ i ++ ] * scale + offsetX;
  24825. y = outline[ i ++ ] * scale + offsetY;
  24826. path.moveTo( x, y );
  24827. break;
  24828. case 'l': // lineTo
  24829. x = outline[ i ++ ] * scale + offsetX;
  24830. y = outline[ i ++ ] * scale + offsetY;
  24831. path.lineTo( x, y );
  24832. break;
  24833. case 'q': // quadraticCurveTo
  24834. cpx = outline[ i ++ ] * scale + offsetX;
  24835. cpy = outline[ i ++ ] * scale + offsetY;
  24836. cpx1 = outline[ i ++ ] * scale + offsetX;
  24837. cpy1 = outline[ i ++ ] * scale + offsetY;
  24838. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  24839. break;
  24840. case 'b': // bezierCurveTo
  24841. cpx = outline[ i ++ ] * scale + offsetX;
  24842. cpy = outline[ i ++ ] * scale + offsetY;
  24843. cpx1 = outline[ i ++ ] * scale + offsetX;
  24844. cpy1 = outline[ i ++ ] * scale + offsetY;
  24845. cpx2 = outline[ i ++ ] * scale + offsetX;
  24846. cpy2 = outline[ i ++ ] * scale + offsetY;
  24847. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  24848. break;
  24849. }
  24850. }
  24851. }
  24852. return { offsetX: glyph.ha * scale, path: path };
  24853. }
  24854. /**
  24855. * @author mrdoob / http://mrdoob.com/
  24856. */
  24857. function FontLoader( manager ) {
  24858. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  24859. }
  24860. Object.assign( FontLoader.prototype, {
  24861. load: function ( url, onLoad, onProgress, onError ) {
  24862. var scope = this;
  24863. var loader = new FileLoader( this.manager );
  24864. loader.setPath( this.path );
  24865. loader.load( url, function ( text ) {
  24866. var json;
  24867. try {
  24868. json = JSON.parse( text );
  24869. } catch ( e ) {
  24870. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  24871. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  24872. }
  24873. var font = scope.parse( json );
  24874. if ( onLoad ) onLoad( font );
  24875. }, onProgress, onError );
  24876. },
  24877. parse: function ( json ) {
  24878. return new Font( json );
  24879. },
  24880. setPath: function ( value ) {
  24881. this.path = value;
  24882. return this;
  24883. }
  24884. } );
  24885. /**
  24886. * @author alteredq / http://alteredqualia.com/
  24887. */
  24888. function Loader() {}
  24889. Loader.Handlers = {
  24890. handlers: [],
  24891. add: function ( regex, loader ) {
  24892. this.handlers.push( regex, loader );
  24893. },
  24894. get: function ( file ) {
  24895. var handlers = this.handlers;
  24896. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  24897. var regex = handlers[ i ];
  24898. var loader = handlers[ i + 1 ];
  24899. if ( regex.test( file ) ) {
  24900. return loader;
  24901. }
  24902. }
  24903. return null;
  24904. }
  24905. };
  24906. Object.assign( Loader.prototype, {
  24907. crossOrigin: 'anonymous',
  24908. onLoadStart: function () {},
  24909. onLoadProgress: function () {},
  24910. onLoadComplete: function () {},
  24911. initMaterials: function ( materials, texturePath, crossOrigin ) {
  24912. var array = [];
  24913. for ( var i = 0; i < materials.length; ++ i ) {
  24914. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  24915. }
  24916. return array;
  24917. },
  24918. createMaterial: ( function () {
  24919. var BlendingMode = {
  24920. NoBlending: NoBlending,
  24921. NormalBlending: NormalBlending,
  24922. AdditiveBlending: AdditiveBlending,
  24923. SubtractiveBlending: SubtractiveBlending,
  24924. MultiplyBlending: MultiplyBlending,
  24925. CustomBlending: CustomBlending
  24926. };
  24927. var color = new Color();
  24928. var textureLoader = new TextureLoader();
  24929. var materialLoader = new MaterialLoader();
  24930. return function createMaterial( m, texturePath, crossOrigin ) {
  24931. // convert from old material format
  24932. var textures = {};
  24933. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  24934. var fullPath = texturePath + path;
  24935. var loader = Loader.Handlers.get( fullPath );
  24936. var texture;
  24937. if ( loader !== null ) {
  24938. texture = loader.load( fullPath );
  24939. } else {
  24940. textureLoader.setCrossOrigin( crossOrigin );
  24941. texture = textureLoader.load( fullPath );
  24942. }
  24943. if ( repeat !== undefined ) {
  24944. texture.repeat.fromArray( repeat );
  24945. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  24946. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  24947. }
  24948. if ( offset !== undefined ) {
  24949. texture.offset.fromArray( offset );
  24950. }
  24951. if ( wrap !== undefined ) {
  24952. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  24953. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  24954. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  24955. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  24956. }
  24957. if ( anisotropy !== undefined ) {
  24958. texture.anisotropy = anisotropy;
  24959. }
  24960. var uuid = _Math.generateUUID();
  24961. textures[ uuid ] = texture;
  24962. return uuid;
  24963. }
  24964. //
  24965. var json = {
  24966. uuid: _Math.generateUUID(),
  24967. type: 'MeshLambertMaterial'
  24968. };
  24969. for ( var name in m ) {
  24970. var value = m[ name ];
  24971. switch ( name ) {
  24972. case 'DbgColor':
  24973. case 'DbgIndex':
  24974. case 'opticalDensity':
  24975. case 'illumination':
  24976. break;
  24977. case 'DbgName':
  24978. json.name = value;
  24979. break;
  24980. case 'blending':
  24981. json.blending = BlendingMode[ value ];
  24982. break;
  24983. case 'colorAmbient':
  24984. case 'mapAmbient':
  24985. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  24986. break;
  24987. case 'colorDiffuse':
  24988. json.color = color.fromArray( value ).getHex();
  24989. break;
  24990. case 'colorSpecular':
  24991. json.specular = color.fromArray( value ).getHex();
  24992. break;
  24993. case 'colorEmissive':
  24994. json.emissive = color.fromArray( value ).getHex();
  24995. break;
  24996. case 'specularCoef':
  24997. json.shininess = value;
  24998. break;
  24999. case 'shading':
  25000. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  25001. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  25002. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  25003. break;
  25004. case 'mapDiffuse':
  25005. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  25006. break;
  25007. case 'mapDiffuseRepeat':
  25008. case 'mapDiffuseOffset':
  25009. case 'mapDiffuseWrap':
  25010. case 'mapDiffuseAnisotropy':
  25011. break;
  25012. case 'mapEmissive':
  25013. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  25014. break;
  25015. case 'mapEmissiveRepeat':
  25016. case 'mapEmissiveOffset':
  25017. case 'mapEmissiveWrap':
  25018. case 'mapEmissiveAnisotropy':
  25019. break;
  25020. case 'mapLight':
  25021. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  25022. break;
  25023. case 'mapLightRepeat':
  25024. case 'mapLightOffset':
  25025. case 'mapLightWrap':
  25026. case 'mapLightAnisotropy':
  25027. break;
  25028. case 'mapAO':
  25029. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  25030. break;
  25031. case 'mapAORepeat':
  25032. case 'mapAOOffset':
  25033. case 'mapAOWrap':
  25034. case 'mapAOAnisotropy':
  25035. break;
  25036. case 'mapBump':
  25037. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  25038. break;
  25039. case 'mapBumpScale':
  25040. json.bumpScale = value;
  25041. break;
  25042. case 'mapBumpRepeat':
  25043. case 'mapBumpOffset':
  25044. case 'mapBumpWrap':
  25045. case 'mapBumpAnisotropy':
  25046. break;
  25047. case 'mapNormal':
  25048. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  25049. break;
  25050. case 'mapNormalFactor':
  25051. json.normalScale = value;
  25052. break;
  25053. case 'mapNormalRepeat':
  25054. case 'mapNormalOffset':
  25055. case 'mapNormalWrap':
  25056. case 'mapNormalAnisotropy':
  25057. break;
  25058. case 'mapSpecular':
  25059. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  25060. break;
  25061. case 'mapSpecularRepeat':
  25062. case 'mapSpecularOffset':
  25063. case 'mapSpecularWrap':
  25064. case 'mapSpecularAnisotropy':
  25065. break;
  25066. case 'mapMetalness':
  25067. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  25068. break;
  25069. case 'mapMetalnessRepeat':
  25070. case 'mapMetalnessOffset':
  25071. case 'mapMetalnessWrap':
  25072. case 'mapMetalnessAnisotropy':
  25073. break;
  25074. case 'mapRoughness':
  25075. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  25076. break;
  25077. case 'mapRoughnessRepeat':
  25078. case 'mapRoughnessOffset':
  25079. case 'mapRoughnessWrap':
  25080. case 'mapRoughnessAnisotropy':
  25081. break;
  25082. case 'mapAlpha':
  25083. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  25084. break;
  25085. case 'mapAlphaRepeat':
  25086. case 'mapAlphaOffset':
  25087. case 'mapAlphaWrap':
  25088. case 'mapAlphaAnisotropy':
  25089. break;
  25090. case 'flipSided':
  25091. json.side = BackSide;
  25092. break;
  25093. case 'doubleSided':
  25094. json.side = DoubleSide;
  25095. break;
  25096. case 'transparency':
  25097. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  25098. json.opacity = value;
  25099. break;
  25100. case 'depthTest':
  25101. case 'depthWrite':
  25102. case 'colorWrite':
  25103. case 'opacity':
  25104. case 'reflectivity':
  25105. case 'transparent':
  25106. case 'visible':
  25107. case 'wireframe':
  25108. json[ name ] = value;
  25109. break;
  25110. case 'vertexColors':
  25111. if ( value === true ) json.vertexColors = VertexColors;
  25112. if ( value === 'face' ) json.vertexColors = FaceColors;
  25113. break;
  25114. default:
  25115. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  25116. break;
  25117. }
  25118. }
  25119. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  25120. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  25121. if ( json.opacity < 1 ) json.transparent = true;
  25122. materialLoader.setTextures( textures );
  25123. return materialLoader.parse( json );
  25124. };
  25125. } )()
  25126. } );
  25127. /**
  25128. * @author mrdoob / http://mrdoob.com/
  25129. */
  25130. var context;
  25131. var AudioContext = {
  25132. getContext: function () {
  25133. if ( context === undefined ) {
  25134. context = new ( window.AudioContext || window.webkitAudioContext )();
  25135. }
  25136. return context;
  25137. },
  25138. setContext: function ( value ) {
  25139. context = value;
  25140. }
  25141. };
  25142. /**
  25143. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  25144. */
  25145. function AudioLoader( manager ) {
  25146. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  25147. }
  25148. Object.assign( AudioLoader.prototype, {
  25149. load: function ( url, onLoad, onProgress, onError ) {
  25150. var loader = new FileLoader( this.manager );
  25151. loader.setResponseType( 'arraybuffer' );
  25152. loader.setPath( this.path );
  25153. loader.load( url, function ( buffer ) {
  25154. // Create a copy of the buffer. The `decodeAudioData` method
  25155. // detaches the buffer when complete, preventing reuse.
  25156. var bufferCopy = buffer.slice( 0 );
  25157. var context = AudioContext.getContext();
  25158. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  25159. onLoad( audioBuffer );
  25160. } );
  25161. }, onProgress, onError );
  25162. },
  25163. setPath: function ( value ) {
  25164. this.path = value;
  25165. return this;
  25166. }
  25167. } );
  25168. /**
  25169. * @author bhouston / http://clara.io
  25170. * @author WestLangley / http://github.com/WestLangley
  25171. *
  25172. * Primary reference:
  25173. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  25174. *
  25175. * Secondary reference:
  25176. * https://www.ppsloan.org/publications/StupidSH36.pdf
  25177. */
  25178. // 3-band SH defined by 9 coefficients
  25179. function SphericalHarmonics3() {
  25180. this.coefficients = [];
  25181. for ( var i = 0; i < 9; i ++ ) {
  25182. this.coefficients.push( new Vector3() );
  25183. }
  25184. }
  25185. Object.assign( SphericalHarmonics3.prototype, {
  25186. isSphericalHarmonics3: true,
  25187. set: function ( coefficients ) {
  25188. for ( var i = 0; i < 9; i ++ ) {
  25189. this.coefficients[ i ].copy( coefficients[ i ] );
  25190. }
  25191. return this;
  25192. },
  25193. zero: function () {
  25194. for ( var i = 0; i < 9; i ++ ) {
  25195. this.coefficients[ i ].set( 0, 0, 0 );
  25196. }
  25197. return this;
  25198. },
  25199. // get the radiance in the direction of the normal
  25200. // target is a Vector3
  25201. getAt: function ( normal, target ) {
  25202. // normal is assumed to be unit length
  25203. var x = normal.x, y = normal.y, z = normal.z;
  25204. var coeff = this.coefficients;
  25205. // band 0
  25206. target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 );
  25207. // band 1
  25208. target.addScale( coeff[ 1 ], 0.488603 * y );
  25209. target.addScale( coeff[ 2 ], 0.488603 * z );
  25210. target.addScale( coeff[ 3 ], 0.488603 * x );
  25211. // band 2
  25212. target.addScale( coeff[ 4 ], 1.092548 * ( x * y ) );
  25213. target.addScale( coeff[ 5 ], 1.092548 * ( y * z ) );
  25214. target.addScale( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) );
  25215. target.addScale( coeff[ 7 ], 1.092548 * ( x * z ) );
  25216. target.addScale( coeff[ 8 ], 0.546274 * ( x * x - y * y ) );
  25217. return target;
  25218. },
  25219. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  25220. // target is a Vector3
  25221. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  25222. getIrradianceAt: function ( normal, target ) {
  25223. // normal is assumed to be unit length
  25224. var x = normal.x, y = normal.y, z = normal.z;
  25225. var coeff = this.coefficients;
  25226. // band 0
  25227. target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095
  25228. // band 1
  25229. target.addScale( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603
  25230. target.addScale( coeff[ 2 ], 2.0 * 0.511664 * z );
  25231. target.addScale( coeff[ 3 ], 2.0 * 0.511664 * x );
  25232. // band 2
  25233. target.addScale( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548
  25234. target.addScale( coeff[ 5 ], 2.0 * 0.429043 * y * z );
  25235. target.addScale( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  25236. target.addScale( coeff[ 7 ], 2.0 * 0.429043 * x * z );
  25237. target.addScale( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274
  25238. return target;
  25239. },
  25240. add: function ( sh ) {
  25241. for ( var i = 0; i < 9; i ++ ) {
  25242. this.coefficients[ i ].add( sh.coefficients[ i ] );
  25243. }
  25244. return this;
  25245. },
  25246. scale: function ( s ) {
  25247. for ( var i = 0; i < 9; i ++ ) {
  25248. this.coefficients[ i ].multiplyScalar( s );
  25249. }
  25250. return this;
  25251. },
  25252. lerp: function ( sh, alpha ) {
  25253. for ( var i = 0; i < 9; i ++ ) {
  25254. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  25255. }
  25256. return this;
  25257. },
  25258. equals: function ( sh ) {
  25259. for ( var i = 0; i < 9; i ++ ) {
  25260. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  25261. return false;
  25262. }
  25263. }
  25264. return true;
  25265. },
  25266. copy: function ( sh ) {
  25267. return this.set( sh.coefficients );
  25268. },
  25269. clone: function () {
  25270. return new this.constructor().copy( this );
  25271. },
  25272. fromArray: function ( array ) {
  25273. var coefficients = this.coefficients;
  25274. for ( var i = 0; i < 9; i ++ ) {
  25275. coefficients[ i ].fromArray( array, i * 3 );
  25276. }
  25277. return this;
  25278. },
  25279. toArray: function () {
  25280. var array = [];
  25281. var coefficients = this.coefficients;
  25282. for ( var i = 0; i < 9; i ++ ) {
  25283. coefficients[ i ].toArray( array, i * 3 );
  25284. }
  25285. return array;
  25286. }
  25287. } );
  25288. Object.assign( SphericalHarmonics3, {
  25289. // evaluate the basis functions
  25290. // shBasis is an Array[ 9 ]
  25291. getBasisAt: function ( normal, shBasis ) {
  25292. // normal is assumed to be unit length
  25293. var x = normal.x, y = normal.y, z = normal.z;
  25294. // band 0
  25295. shBasis[ 0 ] = 0.282095;
  25296. // band 1
  25297. shBasis[ 1 ] = 0.488603 * y;
  25298. shBasis[ 2 ] = 0.488603 * z;
  25299. shBasis[ 3 ] = 0.488603 * x;
  25300. // band 2
  25301. shBasis[ 4 ] = 1.092548 * x * y;
  25302. shBasis[ 5 ] = 1.092548 * y * z;
  25303. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  25304. shBasis[ 7 ] = 1.092548 * x * z;
  25305. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  25306. }
  25307. } );
  25308. /**
  25309. * @author WestLangley / http://github.com/WestLangley
  25310. *
  25311. * A LightProbe is a source of indirect-diffuse light
  25312. */
  25313. function LightProbe( sh, intensity ) {
  25314. Light.call( this, undefined, intensity );
  25315. this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3();
  25316. }
  25317. LightProbe.prototype = Object.assign( Object.create( Light.prototype ), {
  25318. constructor: LightProbe,
  25319. isLightProbe: true,
  25320. copy: function ( source ) {
  25321. Light.prototype.copy.call( this, source );
  25322. this.sh.copy( source.sh );
  25323. this.intensity = source.intensity;
  25324. return this;
  25325. },
  25326. toJSON: function ( meta ) {
  25327. var data = Light.prototype.toJSON.call( this, meta );
  25328. // data.sh = this.sh.toArray(); // todo
  25329. return data;
  25330. }
  25331. } );
  25332. /**
  25333. * @author WestLangley / http://github.com/WestLangley
  25334. */
  25335. function HemisphereLightProbe( skyColor, groundColor, intensity ) {
  25336. LightProbe.call( this, undefined, intensity );
  25337. var color1 = new Color().set( skyColor );
  25338. var color2 = new Color().set( groundColor );
  25339. var sky = new Vector3( color1.r, color1.g, color1.b );
  25340. var ground = new Vector3( color2.r, color2.g, color2.b );
  25341. // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25342. var c0 = Math.sqrt( Math.PI );
  25343. var c1 = c0 * Math.sqrt( 0.75 );
  25344. this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
  25345. this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
  25346. }
  25347. HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  25348. constructor: HemisphereLightProbe,
  25349. isHemisphereLightProbe: true,
  25350. copy: function ( source ) { // modifying colors not currently supported
  25351. LightProbe.prototype.copy.call( this, source );
  25352. return this;
  25353. },
  25354. toJSON: function ( meta ) {
  25355. var data = LightProbe.prototype.toJSON.call( this, meta );
  25356. // data.sh = this.sh.toArray(); // todo
  25357. return data;
  25358. }
  25359. } );
  25360. /**
  25361. * @author WestLangley / http://github.com/WestLangley
  25362. */
  25363. function AmbientLightProbe( color, intensity ) {
  25364. LightProbe.call( this, undefined, intensity );
  25365. var color1 = new Color().set( color );
  25366. // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25367. this.sh.coefficients[ 0 ].set( color1.r, color1.g, color1.b ).multiplyScalar( 2 * Math.sqrt( Math.PI ) );
  25368. }
  25369. AmbientLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  25370. constructor: AmbientLightProbe,
  25371. isAmbientLightProbe: true,
  25372. copy: function ( source ) { // modifying color not currently supported
  25373. LightProbe.prototype.copy.call( this, source );
  25374. return this;
  25375. },
  25376. toJSON: function ( meta ) {
  25377. var data = LightProbe.prototype.toJSON.call( this, meta );
  25378. // data.sh = this.sh.toArray(); // todo
  25379. return data;
  25380. }
  25381. } );
  25382. /**
  25383. * @author mrdoob / http://mrdoob.com/
  25384. */
  25385. function StereoCamera() {
  25386. this.type = 'StereoCamera';
  25387. this.aspect = 1;
  25388. this.eyeSep = 0.064;
  25389. this.cameraL = new PerspectiveCamera();
  25390. this.cameraL.layers.enable( 1 );
  25391. this.cameraL.matrixAutoUpdate = false;
  25392. this.cameraR = new PerspectiveCamera();
  25393. this.cameraR.layers.enable( 2 );
  25394. this.cameraR.matrixAutoUpdate = false;
  25395. }
  25396. Object.assign( StereoCamera.prototype, {
  25397. update: ( function () {
  25398. var instance, focus, fov, aspect, near, far, zoom, eyeSep;
  25399. var eyeRight = new Matrix4();
  25400. var eyeLeft = new Matrix4();
  25401. return function update( camera ) {
  25402. var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
  25403. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  25404. far !== camera.far || zoom !== camera.zoom || eyeSep !== this.eyeSep;
  25405. if ( needsUpdate ) {
  25406. instance = this;
  25407. focus = camera.focus;
  25408. fov = camera.fov;
  25409. aspect = camera.aspect * this.aspect;
  25410. near = camera.near;
  25411. far = camera.far;
  25412. zoom = camera.zoom;
  25413. // Off-axis stereoscopic effect based on
  25414. // http://paulbourke.net/stereographics/stereorender/
  25415. var projectionMatrix = camera.projectionMatrix.clone();
  25416. eyeSep = this.eyeSep / 2;
  25417. var eyeSepOnProjection = eyeSep * near / focus;
  25418. var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
  25419. var xmin, xmax;
  25420. // translate xOffset
  25421. eyeLeft.elements[ 12 ] = - eyeSep;
  25422. eyeRight.elements[ 12 ] = eyeSep;
  25423. // for left eye
  25424. xmin = - ymax * aspect + eyeSepOnProjection;
  25425. xmax = ymax * aspect + eyeSepOnProjection;
  25426. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  25427. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  25428. this.cameraL.projectionMatrix.copy( projectionMatrix );
  25429. // for right eye
  25430. xmin = - ymax * aspect - eyeSepOnProjection;
  25431. xmax = ymax * aspect - eyeSepOnProjection;
  25432. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  25433. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  25434. this.cameraR.projectionMatrix.copy( projectionMatrix );
  25435. }
  25436. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  25437. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  25438. };
  25439. } )()
  25440. } );
  25441. /**
  25442. * @author alteredq / http://alteredqualia.com/
  25443. */
  25444. function Clock( autoStart ) {
  25445. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  25446. this.startTime = 0;
  25447. this.oldTime = 0;
  25448. this.elapsedTime = 0;
  25449. this.running = false;
  25450. }
  25451. Object.assign( Clock.prototype, {
  25452. start: function () {
  25453. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  25454. this.oldTime = this.startTime;
  25455. this.elapsedTime = 0;
  25456. this.running = true;
  25457. },
  25458. stop: function () {
  25459. this.getElapsedTime();
  25460. this.running = false;
  25461. this.autoStart = false;
  25462. },
  25463. getElapsedTime: function () {
  25464. this.getDelta();
  25465. return this.elapsedTime;
  25466. },
  25467. getDelta: function () {
  25468. var diff = 0;
  25469. if ( this.autoStart && ! this.running ) {
  25470. this.start();
  25471. return 0;
  25472. }
  25473. if ( this.running ) {
  25474. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  25475. diff = ( newTime - this.oldTime ) / 1000;
  25476. this.oldTime = newTime;
  25477. this.elapsedTime += diff;
  25478. }
  25479. return diff;
  25480. }
  25481. } );
  25482. /**
  25483. * @author mrdoob / http://mrdoob.com/
  25484. */
  25485. function AudioListener() {
  25486. Object3D.call( this );
  25487. this.type = 'AudioListener';
  25488. this.context = AudioContext.getContext();
  25489. this.gain = this.context.createGain();
  25490. this.gain.connect( this.context.destination );
  25491. this.filter = null;
  25492. this.timeDelta = 0;
  25493. }
  25494. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  25495. constructor: AudioListener,
  25496. getInput: function () {
  25497. return this.gain;
  25498. },
  25499. removeFilter: function ( ) {
  25500. if ( this.filter !== null ) {
  25501. this.gain.disconnect( this.filter );
  25502. this.filter.disconnect( this.context.destination );
  25503. this.gain.connect( this.context.destination );
  25504. this.filter = null;
  25505. }
  25506. return this;
  25507. },
  25508. getFilter: function () {
  25509. return this.filter;
  25510. },
  25511. setFilter: function ( value ) {
  25512. if ( this.filter !== null ) {
  25513. this.gain.disconnect( this.filter );
  25514. this.filter.disconnect( this.context.destination );
  25515. } else {
  25516. this.gain.disconnect( this.context.destination );
  25517. }
  25518. this.filter = value;
  25519. this.gain.connect( this.filter );
  25520. this.filter.connect( this.context.destination );
  25521. return this;
  25522. },
  25523. getMasterVolume: function () {
  25524. return this.gain.gain.value;
  25525. },
  25526. setMasterVolume: function ( value ) {
  25527. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  25528. return this;
  25529. },
  25530. updateMatrixWorld: ( function () {
  25531. var position = new Vector3();
  25532. var quaternion = new Quaternion();
  25533. var scale = new Vector3();
  25534. var orientation = new Vector3();
  25535. var clock = new Clock();
  25536. return function updateMatrixWorld( force ) {
  25537. Object3D.prototype.updateMatrixWorld.call( this, force );
  25538. var listener = this.context.listener;
  25539. var up = this.up;
  25540. this.timeDelta = clock.getDelta();
  25541. this.matrixWorld.decompose( position, quaternion, scale );
  25542. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  25543. if ( listener.positionX ) {
  25544. // code path for Chrome (see #14393)
  25545. var endTime = this.context.currentTime + this.timeDelta;
  25546. listener.positionX.linearRampToValueAtTime( position.x, endTime );
  25547. listener.positionY.linearRampToValueAtTime( position.y, endTime );
  25548. listener.positionZ.linearRampToValueAtTime( position.z, endTime );
  25549. listener.forwardX.linearRampToValueAtTime( orientation.x, endTime );
  25550. listener.forwardY.linearRampToValueAtTime( orientation.y, endTime );
  25551. listener.forwardZ.linearRampToValueAtTime( orientation.z, endTime );
  25552. listener.upX.linearRampToValueAtTime( up.x, endTime );
  25553. listener.upY.linearRampToValueAtTime( up.y, endTime );
  25554. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  25555. } else {
  25556. listener.setPosition( position.x, position.y, position.z );
  25557. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  25558. }
  25559. };
  25560. } )()
  25561. } );
  25562. /**
  25563. * @author mrdoob / http://mrdoob.com/
  25564. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  25565. */
  25566. function Audio( listener ) {
  25567. Object3D.call( this );
  25568. this.type = 'Audio';
  25569. this.listener = listener;
  25570. this.context = listener.context;
  25571. this.gain = this.context.createGain();
  25572. this.gain.connect( listener.getInput() );
  25573. this.autoplay = false;
  25574. this.buffer = null;
  25575. this.detune = 0;
  25576. this.loop = false;
  25577. this.startTime = 0;
  25578. this.offset = 0;
  25579. this.playbackRate = 1;
  25580. this.isPlaying = false;
  25581. this.hasPlaybackControl = true;
  25582. this.sourceType = 'empty';
  25583. this.filters = [];
  25584. }
  25585. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  25586. constructor: Audio,
  25587. getOutput: function () {
  25588. return this.gain;
  25589. },
  25590. setNodeSource: function ( audioNode ) {
  25591. this.hasPlaybackControl = false;
  25592. this.sourceType = 'audioNode';
  25593. this.source = audioNode;
  25594. this.connect();
  25595. return this;
  25596. },
  25597. setMediaElementSource: function ( mediaElement ) {
  25598. this.hasPlaybackControl = false;
  25599. this.sourceType = 'mediaNode';
  25600. this.source = this.context.createMediaElementSource( mediaElement );
  25601. this.connect();
  25602. return this;
  25603. },
  25604. setBuffer: function ( audioBuffer ) {
  25605. this.buffer = audioBuffer;
  25606. this.sourceType = 'buffer';
  25607. if ( this.autoplay ) this.play();
  25608. return this;
  25609. },
  25610. play: function () {
  25611. if ( this.isPlaying === true ) {
  25612. console.warn( 'THREE.Audio: Audio is already playing.' );
  25613. return;
  25614. }
  25615. if ( this.hasPlaybackControl === false ) {
  25616. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25617. return;
  25618. }
  25619. var source = this.context.createBufferSource();
  25620. source.buffer = this.buffer;
  25621. source.loop = this.loop;
  25622. source.onended = this.onEnded.bind( this );
  25623. this.startTime = this.context.currentTime;
  25624. source.start( this.startTime, this.offset );
  25625. this.isPlaying = true;
  25626. this.source = source;
  25627. this.setDetune( this.detune );
  25628. this.setPlaybackRate( this.playbackRate );
  25629. return this.connect();
  25630. },
  25631. pause: function () {
  25632. if ( this.hasPlaybackControl === false ) {
  25633. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25634. return;
  25635. }
  25636. if ( this.isPlaying === true ) {
  25637. this.source.stop();
  25638. this.source.onended = null;
  25639. this.offset += ( this.context.currentTime - this.startTime ) * this.playbackRate;
  25640. this.isPlaying = false;
  25641. }
  25642. return this;
  25643. },
  25644. stop: function () {
  25645. if ( this.hasPlaybackControl === false ) {
  25646. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25647. return;
  25648. }
  25649. this.source.stop();
  25650. this.source.onended = null;
  25651. this.offset = 0;
  25652. this.isPlaying = false;
  25653. return this;
  25654. },
  25655. connect: function () {
  25656. if ( this.filters.length > 0 ) {
  25657. this.source.connect( this.filters[ 0 ] );
  25658. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  25659. this.filters[ i - 1 ].connect( this.filters[ i ] );
  25660. }
  25661. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  25662. } else {
  25663. this.source.connect( this.getOutput() );
  25664. }
  25665. return this;
  25666. },
  25667. disconnect: function () {
  25668. if ( this.filters.length > 0 ) {
  25669. this.source.disconnect( this.filters[ 0 ] );
  25670. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  25671. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  25672. }
  25673. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  25674. } else {
  25675. this.source.disconnect( this.getOutput() );
  25676. }
  25677. return this;
  25678. },
  25679. getFilters: function () {
  25680. return this.filters;
  25681. },
  25682. setFilters: function ( value ) {
  25683. if ( ! value ) value = [];
  25684. if ( this.isPlaying === true ) {
  25685. this.disconnect();
  25686. this.filters = value;
  25687. this.connect();
  25688. } else {
  25689. this.filters = value;
  25690. }
  25691. return this;
  25692. },
  25693. setDetune: function ( value ) {
  25694. this.detune = value;
  25695. if ( this.source.detune === undefined ) return; // only set detune when available
  25696. if ( this.isPlaying === true ) {
  25697. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  25698. }
  25699. return this;
  25700. },
  25701. getDetune: function () {
  25702. return this.detune;
  25703. },
  25704. getFilter: function () {
  25705. return this.getFilters()[ 0 ];
  25706. },
  25707. setFilter: function ( filter ) {
  25708. return this.setFilters( filter ? [ filter ] : [] );
  25709. },
  25710. setPlaybackRate: function ( value ) {
  25711. if ( this.hasPlaybackControl === false ) {
  25712. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25713. return;
  25714. }
  25715. this.playbackRate = value;
  25716. if ( this.isPlaying === true ) {
  25717. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  25718. }
  25719. return this;
  25720. },
  25721. getPlaybackRate: function () {
  25722. return this.playbackRate;
  25723. },
  25724. onEnded: function () {
  25725. this.isPlaying = false;
  25726. },
  25727. getLoop: function () {
  25728. if ( this.hasPlaybackControl === false ) {
  25729. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25730. return false;
  25731. }
  25732. return this.loop;
  25733. },
  25734. setLoop: function ( value ) {
  25735. if ( this.hasPlaybackControl === false ) {
  25736. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25737. return;
  25738. }
  25739. this.loop = value;
  25740. if ( this.isPlaying === true ) {
  25741. this.source.loop = this.loop;
  25742. }
  25743. return this;
  25744. },
  25745. getVolume: function () {
  25746. return this.gain.gain.value;
  25747. },
  25748. setVolume: function ( value ) {
  25749. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  25750. return this;
  25751. }
  25752. } );
  25753. /**
  25754. * @author mrdoob / http://mrdoob.com/
  25755. */
  25756. function PositionalAudio( listener ) {
  25757. Audio.call( this, listener );
  25758. this.panner = this.context.createPanner();
  25759. this.panner.panningModel = 'HRTF';
  25760. this.panner.connect( this.gain );
  25761. }
  25762. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  25763. constructor: PositionalAudio,
  25764. getOutput: function () {
  25765. return this.panner;
  25766. },
  25767. getRefDistance: function () {
  25768. return this.panner.refDistance;
  25769. },
  25770. setRefDistance: function ( value ) {
  25771. this.panner.refDistance = value;
  25772. return this;
  25773. },
  25774. getRolloffFactor: function () {
  25775. return this.panner.rolloffFactor;
  25776. },
  25777. setRolloffFactor: function ( value ) {
  25778. this.panner.rolloffFactor = value;
  25779. return this;
  25780. },
  25781. getDistanceModel: function () {
  25782. return this.panner.distanceModel;
  25783. },
  25784. setDistanceModel: function ( value ) {
  25785. this.panner.distanceModel = value;
  25786. return this;
  25787. },
  25788. getMaxDistance: function () {
  25789. return this.panner.maxDistance;
  25790. },
  25791. setMaxDistance: function ( value ) {
  25792. this.panner.maxDistance = value;
  25793. return this;
  25794. },
  25795. setDirectionalCone: function ( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  25796. this.panner.coneInnerAngle = coneInnerAngle;
  25797. this.panner.coneOuterAngle = coneOuterAngle;
  25798. this.panner.coneOuterGain = coneOuterGain;
  25799. return this;
  25800. },
  25801. updateMatrixWorld: ( function () {
  25802. var position = new Vector3();
  25803. var quaternion = new Quaternion();
  25804. var scale = new Vector3();
  25805. var orientation = new Vector3();
  25806. return function updateMatrixWorld( force ) {
  25807. Object3D.prototype.updateMatrixWorld.call( this, force );
  25808. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  25809. this.matrixWorld.decompose( position, quaternion, scale );
  25810. orientation.set( 0, 0, 1 ).applyQuaternion( quaternion );
  25811. var panner = this.panner;
  25812. if ( panner.positionX ) {
  25813. // code path for Chrome and Firefox (see #14393)
  25814. var endTime = this.context.currentTime + this.listener.timeDelta;
  25815. panner.positionX.linearRampToValueAtTime( position.x, endTime );
  25816. panner.positionY.linearRampToValueAtTime( position.y, endTime );
  25817. panner.positionZ.linearRampToValueAtTime( position.z, endTime );
  25818. panner.orientationX.linearRampToValueAtTime( orientation.x, endTime );
  25819. panner.orientationY.linearRampToValueAtTime( orientation.y, endTime );
  25820. panner.orientationZ.linearRampToValueAtTime( orientation.z, endTime );
  25821. } else {
  25822. panner.setPosition( position.x, position.y, position.z );
  25823. panner.setOrientation( orientation.x, orientation.y, orientation.z );
  25824. }
  25825. };
  25826. } )()
  25827. } );
  25828. /**
  25829. * @author mrdoob / http://mrdoob.com/
  25830. */
  25831. function AudioAnalyser( audio, fftSize ) {
  25832. this.analyser = audio.context.createAnalyser();
  25833. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  25834. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  25835. audio.getOutput().connect( this.analyser );
  25836. }
  25837. Object.assign( AudioAnalyser.prototype, {
  25838. getFrequencyData: function () {
  25839. this.analyser.getByteFrequencyData( this.data );
  25840. return this.data;
  25841. },
  25842. getAverageFrequency: function () {
  25843. var value = 0, data = this.getFrequencyData();
  25844. for ( var i = 0; i < data.length; i ++ ) {
  25845. value += data[ i ];
  25846. }
  25847. return value / data.length;
  25848. }
  25849. } );
  25850. /**
  25851. *
  25852. * Buffered scene graph property that allows weighted accumulation.
  25853. *
  25854. *
  25855. * @author Ben Houston / http://clara.io/
  25856. * @author David Sarno / http://lighthaus.us/
  25857. * @author tschw
  25858. */
  25859. function PropertyMixer( binding, typeName, valueSize ) {
  25860. this.binding = binding;
  25861. this.valueSize = valueSize;
  25862. var bufferType = Float64Array,
  25863. mixFunction;
  25864. switch ( typeName ) {
  25865. case 'quaternion':
  25866. mixFunction = this._slerp;
  25867. break;
  25868. case 'string':
  25869. case 'bool':
  25870. bufferType = Array;
  25871. mixFunction = this._select;
  25872. break;
  25873. default:
  25874. mixFunction = this._lerp;
  25875. }
  25876. this.buffer = new bufferType( valueSize * 4 );
  25877. // layout: [ incoming | accu0 | accu1 | orig ]
  25878. //
  25879. // interpolators can use .buffer as their .result
  25880. // the data then goes to 'incoming'
  25881. //
  25882. // 'accu0' and 'accu1' are used frame-interleaved for
  25883. // the cumulative result and are compared to detect
  25884. // changes
  25885. //
  25886. // 'orig' stores the original state of the property
  25887. this._mixBufferRegion = mixFunction;
  25888. this.cumulativeWeight = 0;
  25889. this.useCount = 0;
  25890. this.referenceCount = 0;
  25891. }
  25892. Object.assign( PropertyMixer.prototype, {
  25893. // accumulate data in the 'incoming' region into 'accu<i>'
  25894. accumulate: function ( accuIndex, weight ) {
  25895. // note: happily accumulating nothing when weight = 0, the caller knows
  25896. // the weight and shouldn't have made the call in the first place
  25897. var buffer = this.buffer,
  25898. stride = this.valueSize,
  25899. offset = accuIndex * stride + stride,
  25900. currentWeight = this.cumulativeWeight;
  25901. if ( currentWeight === 0 ) {
  25902. // accuN := incoming * weight
  25903. for ( var i = 0; i !== stride; ++ i ) {
  25904. buffer[ offset + i ] = buffer[ i ];
  25905. }
  25906. currentWeight = weight;
  25907. } else {
  25908. // accuN := accuN + incoming * weight
  25909. currentWeight += weight;
  25910. var mix = weight / currentWeight;
  25911. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  25912. }
  25913. this.cumulativeWeight = currentWeight;
  25914. },
  25915. // apply the state of 'accu<i>' to the binding when accus differ
  25916. apply: function ( accuIndex ) {
  25917. var stride = this.valueSize,
  25918. buffer = this.buffer,
  25919. offset = accuIndex * stride + stride,
  25920. weight = this.cumulativeWeight,
  25921. binding = this.binding;
  25922. this.cumulativeWeight = 0;
  25923. if ( weight < 1 ) {
  25924. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25925. var originalValueOffset = stride * 3;
  25926. this._mixBufferRegion(
  25927. buffer, offset, originalValueOffset, 1 - weight, stride );
  25928. }
  25929. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  25930. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  25931. // value has changed -> update scene graph
  25932. binding.setValue( buffer, offset );
  25933. break;
  25934. }
  25935. }
  25936. },
  25937. // remember the state of the bound property and copy it to both accus
  25938. saveOriginalState: function () {
  25939. var binding = this.binding;
  25940. var buffer = this.buffer,
  25941. stride = this.valueSize,
  25942. originalValueOffset = stride * 3;
  25943. binding.getValue( buffer, originalValueOffset );
  25944. // accu[0..1] := orig -- initially detect changes against the original
  25945. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  25946. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  25947. }
  25948. this.cumulativeWeight = 0;
  25949. },
  25950. // apply the state previously taken via 'saveOriginalState' to the binding
  25951. restoreOriginalState: function () {
  25952. var originalValueOffset = this.valueSize * 3;
  25953. this.binding.setValue( this.buffer, originalValueOffset );
  25954. },
  25955. // mix functions
  25956. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  25957. if ( t >= 0.5 ) {
  25958. for ( var i = 0; i !== stride; ++ i ) {
  25959. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  25960. }
  25961. }
  25962. },
  25963. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  25964. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  25965. },
  25966. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  25967. var s = 1 - t;
  25968. for ( var i = 0; i !== stride; ++ i ) {
  25969. var j = dstOffset + i;
  25970. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  25971. }
  25972. }
  25973. } );
  25974. /**
  25975. *
  25976. * A reference to a real property in the scene graph.
  25977. *
  25978. *
  25979. * @author Ben Houston / http://clara.io/
  25980. * @author David Sarno / http://lighthaus.us/
  25981. * @author tschw
  25982. */
  25983. // Characters [].:/ are reserved for track binding syntax.
  25984. var RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  25985. function Composite( targetGroup, path, optionalParsedPath ) {
  25986. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  25987. this._targetGroup = targetGroup;
  25988. this._bindings = targetGroup.subscribe_( path, parsedPath );
  25989. }
  25990. Object.assign( Composite.prototype, {
  25991. getValue: function ( array, offset ) {
  25992. this.bind(); // bind all binding
  25993. var firstValidIndex = this._targetGroup.nCachedObjects_,
  25994. binding = this._bindings[ firstValidIndex ];
  25995. // and only call .getValue on the first
  25996. if ( binding !== undefined ) binding.getValue( array, offset );
  25997. },
  25998. setValue: function ( array, offset ) {
  25999. var bindings = this._bindings;
  26000. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  26001. bindings[ i ].setValue( array, offset );
  26002. }
  26003. },
  26004. bind: function () {
  26005. var bindings = this._bindings;
  26006. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  26007. bindings[ i ].bind();
  26008. }
  26009. },
  26010. unbind: function () {
  26011. var bindings = this._bindings;
  26012. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  26013. bindings[ i ].unbind();
  26014. }
  26015. }
  26016. } );
  26017. function PropertyBinding( rootNode, path, parsedPath ) {
  26018. this.path = path;
  26019. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  26020. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  26021. this.rootNode = rootNode;
  26022. }
  26023. Object.assign( PropertyBinding, {
  26024. Composite: Composite,
  26025. create: function ( root, path, parsedPath ) {
  26026. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  26027. return new PropertyBinding( root, path, parsedPath );
  26028. } else {
  26029. return new PropertyBinding.Composite( root, path, parsedPath );
  26030. }
  26031. },
  26032. /**
  26033. * Replaces spaces with underscores and removes unsupported characters from
  26034. * node names, to ensure compatibility with parseTrackName().
  26035. *
  26036. * @param {string} name Node name to be sanitized.
  26037. * @return {string}
  26038. */
  26039. sanitizeNodeName: ( function () {
  26040. var reservedRe = new RegExp( '[' + RESERVED_CHARS_RE + ']', 'g' );
  26041. return function sanitizeNodeName( name ) {
  26042. return name.replace( /\s/g, '_' ).replace( reservedRe, '' );
  26043. };
  26044. }() ),
  26045. parseTrackName: function () {
  26046. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  26047. // only latin characters, and the unicode \p{L} is not yet supported. So
  26048. // instead, we exclude reserved characters and match everything else.
  26049. var wordChar = '[^' + RESERVED_CHARS_RE + ']';
  26050. var wordCharOrDot = '[^' + RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  26051. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  26052. // be matched to parse the rest of the track name.
  26053. var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );
  26054. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  26055. var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
  26056. // Object on target node, and accessor. May not contain reserved
  26057. // characters. Accessor may contain any character except closing bracket.
  26058. var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );
  26059. // Property and accessor. May not contain reserved characters. Accessor may
  26060. // contain any non-bracket characters.
  26061. var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
  26062. var trackRe = new RegExp( ''
  26063. + '^'
  26064. + directoryRe
  26065. + nodeRe
  26066. + objectRe
  26067. + propertyRe
  26068. + '$'
  26069. );
  26070. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  26071. return function parseTrackName( trackName ) {
  26072. var matches = trackRe.exec( trackName );
  26073. if ( ! matches ) {
  26074. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  26075. }
  26076. var results = {
  26077. // directoryName: matches[ 1 ], // (tschw) currently unused
  26078. nodeName: matches[ 2 ],
  26079. objectName: matches[ 3 ],
  26080. objectIndex: matches[ 4 ],
  26081. propertyName: matches[ 5 ], // required
  26082. propertyIndex: matches[ 6 ]
  26083. };
  26084. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  26085. if ( lastDot !== undefined && lastDot !== - 1 ) {
  26086. var objectName = results.nodeName.substring( lastDot + 1 );
  26087. // Object names must be checked against a whitelist. Otherwise, there
  26088. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  26089. // 'bar' could be the objectName, or part of a nodeName (which can
  26090. // include '.' characters).
  26091. if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  26092. results.nodeName = results.nodeName.substring( 0, lastDot );
  26093. results.objectName = objectName;
  26094. }
  26095. }
  26096. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  26097. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  26098. }
  26099. return results;
  26100. };
  26101. }(),
  26102. findNode: function ( root, nodeName ) {
  26103. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  26104. return root;
  26105. }
  26106. // search into skeleton bones.
  26107. if ( root.skeleton ) {
  26108. var bone = root.skeleton.getBoneByName( nodeName );
  26109. if ( bone !== undefined ) {
  26110. return bone;
  26111. }
  26112. }
  26113. // search into node subtree.
  26114. if ( root.children ) {
  26115. var searchNodeSubtree = function ( children ) {
  26116. for ( var i = 0; i < children.length; i ++ ) {
  26117. var childNode = children[ i ];
  26118. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  26119. return childNode;
  26120. }
  26121. var result = searchNodeSubtree( childNode.children );
  26122. if ( result ) return result;
  26123. }
  26124. return null;
  26125. };
  26126. var subTreeNode = searchNodeSubtree( root.children );
  26127. if ( subTreeNode ) {
  26128. return subTreeNode;
  26129. }
  26130. }
  26131. return null;
  26132. }
  26133. } );
  26134. Object.assign( PropertyBinding.prototype, { // prototype, continued
  26135. // these are used to "bind" a nonexistent property
  26136. _getValue_unavailable: function () {},
  26137. _setValue_unavailable: function () {},
  26138. BindingType: {
  26139. Direct: 0,
  26140. EntireArray: 1,
  26141. ArrayElement: 2,
  26142. HasFromToArray: 3
  26143. },
  26144. Versioning: {
  26145. None: 0,
  26146. NeedsUpdate: 1,
  26147. MatrixWorldNeedsUpdate: 2
  26148. },
  26149. GetterByBindingType: [
  26150. function getValue_direct( buffer, offset ) {
  26151. buffer[ offset ] = this.node[ this.propertyName ];
  26152. },
  26153. function getValue_array( buffer, offset ) {
  26154. var source = this.resolvedProperty;
  26155. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  26156. buffer[ offset ++ ] = source[ i ];
  26157. }
  26158. },
  26159. function getValue_arrayElement( buffer, offset ) {
  26160. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  26161. },
  26162. function getValue_toArray( buffer, offset ) {
  26163. this.resolvedProperty.toArray( buffer, offset );
  26164. }
  26165. ],
  26166. SetterByBindingTypeAndVersioning: [
  26167. [
  26168. // Direct
  26169. function setValue_direct( buffer, offset ) {
  26170. this.targetObject[ this.propertyName ] = buffer[ offset ];
  26171. },
  26172. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  26173. this.targetObject[ this.propertyName ] = buffer[ offset ];
  26174. this.targetObject.needsUpdate = true;
  26175. },
  26176. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26177. this.targetObject[ this.propertyName ] = buffer[ offset ];
  26178. this.targetObject.matrixWorldNeedsUpdate = true;
  26179. }
  26180. ], [
  26181. // EntireArray
  26182. function setValue_array( buffer, offset ) {
  26183. var dest = this.resolvedProperty;
  26184. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  26185. dest[ i ] = buffer[ offset ++ ];
  26186. }
  26187. },
  26188. function setValue_array_setNeedsUpdate( buffer, offset ) {
  26189. var dest = this.resolvedProperty;
  26190. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  26191. dest[ i ] = buffer[ offset ++ ];
  26192. }
  26193. this.targetObject.needsUpdate = true;
  26194. },
  26195. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26196. var dest = this.resolvedProperty;
  26197. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  26198. dest[ i ] = buffer[ offset ++ ];
  26199. }
  26200. this.targetObject.matrixWorldNeedsUpdate = true;
  26201. }
  26202. ], [
  26203. // ArrayElement
  26204. function setValue_arrayElement( buffer, offset ) {
  26205. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  26206. },
  26207. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  26208. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  26209. this.targetObject.needsUpdate = true;
  26210. },
  26211. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26212. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  26213. this.targetObject.matrixWorldNeedsUpdate = true;
  26214. }
  26215. ], [
  26216. // HasToFromArray
  26217. function setValue_fromArray( buffer, offset ) {
  26218. this.resolvedProperty.fromArray( buffer, offset );
  26219. },
  26220. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  26221. this.resolvedProperty.fromArray( buffer, offset );
  26222. this.targetObject.needsUpdate = true;
  26223. },
  26224. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26225. this.resolvedProperty.fromArray( buffer, offset );
  26226. this.targetObject.matrixWorldNeedsUpdate = true;
  26227. }
  26228. ]
  26229. ],
  26230. getValue: function getValue_unbound( targetArray, offset ) {
  26231. this.bind();
  26232. this.getValue( targetArray, offset );
  26233. // Note: This class uses a State pattern on a per-method basis:
  26234. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  26235. // prototype version of these methods with one that represents
  26236. // the bound state. When the property is not found, the methods
  26237. // become no-ops.
  26238. },
  26239. setValue: function getValue_unbound( sourceArray, offset ) {
  26240. this.bind();
  26241. this.setValue( sourceArray, offset );
  26242. },
  26243. // create getter / setter pair for a property in the scene graph
  26244. bind: function () {
  26245. var targetObject = this.node,
  26246. parsedPath = this.parsedPath,
  26247. objectName = parsedPath.objectName,
  26248. propertyName = parsedPath.propertyName,
  26249. propertyIndex = parsedPath.propertyIndex;
  26250. if ( ! targetObject ) {
  26251. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  26252. this.node = targetObject;
  26253. }
  26254. // set fail state so we can just 'return' on error
  26255. this.getValue = this._getValue_unavailable;
  26256. this.setValue = this._setValue_unavailable;
  26257. // ensure there is a value node
  26258. if ( ! targetObject ) {
  26259. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  26260. return;
  26261. }
  26262. if ( objectName ) {
  26263. var objectIndex = parsedPath.objectIndex;
  26264. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  26265. switch ( objectName ) {
  26266. case 'materials':
  26267. if ( ! targetObject.material ) {
  26268. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  26269. return;
  26270. }
  26271. if ( ! targetObject.material.materials ) {
  26272. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  26273. return;
  26274. }
  26275. targetObject = targetObject.material.materials;
  26276. break;
  26277. case 'bones':
  26278. if ( ! targetObject.skeleton ) {
  26279. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  26280. return;
  26281. }
  26282. // potential future optimization: skip this if propertyIndex is already an integer
  26283. // and convert the integer string to a true integer.
  26284. targetObject = targetObject.skeleton.bones;
  26285. // support resolving morphTarget names into indices.
  26286. for ( var i = 0; i < targetObject.length; i ++ ) {
  26287. if ( targetObject[ i ].name === objectIndex ) {
  26288. objectIndex = i;
  26289. break;
  26290. }
  26291. }
  26292. break;
  26293. default:
  26294. if ( targetObject[ objectName ] === undefined ) {
  26295. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  26296. return;
  26297. }
  26298. targetObject = targetObject[ objectName ];
  26299. }
  26300. if ( objectIndex !== undefined ) {
  26301. if ( targetObject[ objectIndex ] === undefined ) {
  26302. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  26303. return;
  26304. }
  26305. targetObject = targetObject[ objectIndex ];
  26306. }
  26307. }
  26308. // resolve property
  26309. var nodeProperty = targetObject[ propertyName ];
  26310. if ( nodeProperty === undefined ) {
  26311. var nodeName = parsedPath.nodeName;
  26312. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  26313. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  26314. return;
  26315. }
  26316. // determine versioning scheme
  26317. var versioning = this.Versioning.None;
  26318. this.targetObject = targetObject;
  26319. if ( targetObject.needsUpdate !== undefined ) { // material
  26320. versioning = this.Versioning.NeedsUpdate;
  26321. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  26322. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26323. }
  26324. // determine how the property gets bound
  26325. var bindingType = this.BindingType.Direct;
  26326. if ( propertyIndex !== undefined ) {
  26327. // access a sub element of the property array (only primitives are supported right now)
  26328. if ( propertyName === "morphTargetInfluences" ) {
  26329. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26330. // support resolving morphTarget names into indices.
  26331. if ( ! targetObject.geometry ) {
  26332. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  26333. return;
  26334. }
  26335. if ( targetObject.geometry.isBufferGeometry ) {
  26336. if ( ! targetObject.geometry.morphAttributes ) {
  26337. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  26338. return;
  26339. }
  26340. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  26341. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  26342. propertyIndex = i;
  26343. break;
  26344. }
  26345. }
  26346. } else {
  26347. if ( ! targetObject.geometry.morphTargets ) {
  26348. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  26349. return;
  26350. }
  26351. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  26352. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  26353. propertyIndex = i;
  26354. break;
  26355. }
  26356. }
  26357. }
  26358. }
  26359. bindingType = this.BindingType.ArrayElement;
  26360. this.resolvedProperty = nodeProperty;
  26361. this.propertyIndex = propertyIndex;
  26362. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  26363. // must use copy for Object3D.Euler/Quaternion
  26364. bindingType = this.BindingType.HasFromToArray;
  26365. this.resolvedProperty = nodeProperty;
  26366. } else if ( Array.isArray( nodeProperty ) ) {
  26367. bindingType = this.BindingType.EntireArray;
  26368. this.resolvedProperty = nodeProperty;
  26369. } else {
  26370. this.propertyName = propertyName;
  26371. }
  26372. // select getter / setter
  26373. this.getValue = this.GetterByBindingType[ bindingType ];
  26374. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  26375. },
  26376. unbind: function () {
  26377. this.node = null;
  26378. // back to the prototype version of getValue / setValue
  26379. // note: avoiding to mutate the shape of 'this' via 'delete'
  26380. this.getValue = this._getValue_unbound;
  26381. this.setValue = this._setValue_unbound;
  26382. }
  26383. } );
  26384. //!\ DECLARE ALIAS AFTER assign prototype !
  26385. Object.assign( PropertyBinding.prototype, {
  26386. // initial state of these methods that calls 'bind'
  26387. _getValue_unbound: PropertyBinding.prototype.getValue,
  26388. _setValue_unbound: PropertyBinding.prototype.setValue,
  26389. } );
  26390. /**
  26391. *
  26392. * A group of objects that receives a shared animation state.
  26393. *
  26394. * Usage:
  26395. *
  26396. * - Add objects you would otherwise pass as 'root' to the
  26397. * constructor or the .clipAction method of AnimationMixer.
  26398. *
  26399. * - Instead pass this object as 'root'.
  26400. *
  26401. * - You can also add and remove objects later when the mixer
  26402. * is running.
  26403. *
  26404. * Note:
  26405. *
  26406. * Objects of this class appear as one object to the mixer,
  26407. * so cache control of the individual objects must be done
  26408. * on the group.
  26409. *
  26410. * Limitation:
  26411. *
  26412. * - The animated properties must be compatible among the
  26413. * all objects in the group.
  26414. *
  26415. * - A single property can either be controlled through a
  26416. * target group or directly, but not both.
  26417. *
  26418. * @author tschw
  26419. */
  26420. function AnimationObjectGroup() {
  26421. this.uuid = _Math.generateUUID();
  26422. // cached objects followed by the active ones
  26423. this._objects = Array.prototype.slice.call( arguments );
  26424. this.nCachedObjects_ = 0; // threshold
  26425. // note: read by PropertyBinding.Composite
  26426. var indices = {};
  26427. this._indicesByUUID = indices; // for bookkeeping
  26428. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  26429. indices[ arguments[ i ].uuid ] = i;
  26430. }
  26431. this._paths = []; // inside: string
  26432. this._parsedPaths = []; // inside: { we don't care, here }
  26433. this._bindings = []; // inside: Array< PropertyBinding >
  26434. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26435. var scope = this;
  26436. this.stats = {
  26437. objects: {
  26438. get total() {
  26439. return scope._objects.length;
  26440. },
  26441. get inUse() {
  26442. return this.total - scope.nCachedObjects_;
  26443. }
  26444. },
  26445. get bindingsPerObject() {
  26446. return scope._bindings.length;
  26447. }
  26448. };
  26449. }
  26450. Object.assign( AnimationObjectGroup.prototype, {
  26451. isAnimationObjectGroup: true,
  26452. add: function () {
  26453. var objects = this._objects,
  26454. nObjects = objects.length,
  26455. nCachedObjects = this.nCachedObjects_,
  26456. indicesByUUID = this._indicesByUUID,
  26457. paths = this._paths,
  26458. parsedPaths = this._parsedPaths,
  26459. bindings = this._bindings,
  26460. nBindings = bindings.length,
  26461. knownObject = undefined;
  26462. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  26463. var object = arguments[ i ],
  26464. uuid = object.uuid,
  26465. index = indicesByUUID[ uuid ];
  26466. if ( index === undefined ) {
  26467. // unknown object -> add it to the ACTIVE region
  26468. index = nObjects ++;
  26469. indicesByUUID[ uuid ] = index;
  26470. objects.push( object );
  26471. // accounting is done, now do the same for all bindings
  26472. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  26473. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  26474. }
  26475. } else if ( index < nCachedObjects ) {
  26476. knownObject = objects[ index ];
  26477. // move existing object to the ACTIVE region
  26478. var firstActiveIndex = -- nCachedObjects,
  26479. lastCachedObject = objects[ firstActiveIndex ];
  26480. indicesByUUID[ lastCachedObject.uuid ] = index;
  26481. objects[ index ] = lastCachedObject;
  26482. indicesByUUID[ uuid ] = firstActiveIndex;
  26483. objects[ firstActiveIndex ] = object;
  26484. // accounting is done, now do the same for all bindings
  26485. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  26486. var bindingsForPath = bindings[ j ],
  26487. lastCached = bindingsForPath[ firstActiveIndex ],
  26488. binding = bindingsForPath[ index ];
  26489. bindingsForPath[ index ] = lastCached;
  26490. if ( binding === undefined ) {
  26491. // since we do not bother to create new bindings
  26492. // for objects that are cached, the binding may
  26493. // or may not exist
  26494. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  26495. }
  26496. bindingsForPath[ firstActiveIndex ] = binding;
  26497. }
  26498. } else if ( objects[ index ] !== knownObject ) {
  26499. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  26500. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  26501. } // else the object is already where we want it to be
  26502. } // for arguments
  26503. this.nCachedObjects_ = nCachedObjects;
  26504. },
  26505. remove: function () {
  26506. var objects = this._objects,
  26507. nCachedObjects = this.nCachedObjects_,
  26508. indicesByUUID = this._indicesByUUID,
  26509. bindings = this._bindings,
  26510. nBindings = bindings.length;
  26511. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  26512. var object = arguments[ i ],
  26513. uuid = object.uuid,
  26514. index = indicesByUUID[ uuid ];
  26515. if ( index !== undefined && index >= nCachedObjects ) {
  26516. // move existing object into the CACHED region
  26517. var lastCachedIndex = nCachedObjects ++,
  26518. firstActiveObject = objects[ lastCachedIndex ];
  26519. indicesByUUID[ firstActiveObject.uuid ] = index;
  26520. objects[ index ] = firstActiveObject;
  26521. indicesByUUID[ uuid ] = lastCachedIndex;
  26522. objects[ lastCachedIndex ] = object;
  26523. // accounting is done, now do the same for all bindings
  26524. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  26525. var bindingsForPath = bindings[ j ],
  26526. firstActive = bindingsForPath[ lastCachedIndex ],
  26527. binding = bindingsForPath[ index ];
  26528. bindingsForPath[ index ] = firstActive;
  26529. bindingsForPath[ lastCachedIndex ] = binding;
  26530. }
  26531. }
  26532. } // for arguments
  26533. this.nCachedObjects_ = nCachedObjects;
  26534. },
  26535. // remove & forget
  26536. uncache: function () {
  26537. var objects = this._objects,
  26538. nObjects = objects.length,
  26539. nCachedObjects = this.nCachedObjects_,
  26540. indicesByUUID = this._indicesByUUID,
  26541. bindings = this._bindings,
  26542. nBindings = bindings.length;
  26543. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  26544. var object = arguments[ i ],
  26545. uuid = object.uuid,
  26546. index = indicesByUUID[ uuid ];
  26547. if ( index !== undefined ) {
  26548. delete indicesByUUID[ uuid ];
  26549. if ( index < nCachedObjects ) {
  26550. // object is cached, shrink the CACHED region
  26551. var firstActiveIndex = -- nCachedObjects,
  26552. lastCachedObject = objects[ firstActiveIndex ],
  26553. lastIndex = -- nObjects,
  26554. lastObject = objects[ lastIndex ];
  26555. // last cached object takes this object's place
  26556. indicesByUUID[ lastCachedObject.uuid ] = index;
  26557. objects[ index ] = lastCachedObject;
  26558. // last object goes to the activated slot and pop
  26559. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  26560. objects[ firstActiveIndex ] = lastObject;
  26561. objects.pop();
  26562. // accounting is done, now do the same for all bindings
  26563. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  26564. var bindingsForPath = bindings[ j ],
  26565. lastCached = bindingsForPath[ firstActiveIndex ],
  26566. last = bindingsForPath[ lastIndex ];
  26567. bindingsForPath[ index ] = lastCached;
  26568. bindingsForPath[ firstActiveIndex ] = last;
  26569. bindingsForPath.pop();
  26570. }
  26571. } else {
  26572. // object is active, just swap with the last and pop
  26573. var lastIndex = -- nObjects,
  26574. lastObject = objects[ lastIndex ];
  26575. indicesByUUID[ lastObject.uuid ] = index;
  26576. objects[ index ] = lastObject;
  26577. objects.pop();
  26578. // accounting is done, now do the same for all bindings
  26579. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  26580. var bindingsForPath = bindings[ j ];
  26581. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  26582. bindingsForPath.pop();
  26583. }
  26584. } // cached or active
  26585. } // if object is known
  26586. } // for arguments
  26587. this.nCachedObjects_ = nCachedObjects;
  26588. },
  26589. // Internal interface used by befriended PropertyBinding.Composite:
  26590. subscribe_: function ( path, parsedPath ) {
  26591. // returns an array of bindings for the given path that is changed
  26592. // according to the contained objects in the group
  26593. var indicesByPath = this._bindingsIndicesByPath,
  26594. index = indicesByPath[ path ],
  26595. bindings = this._bindings;
  26596. if ( index !== undefined ) return bindings[ index ];
  26597. var paths = this._paths,
  26598. parsedPaths = this._parsedPaths,
  26599. objects = this._objects,
  26600. nObjects = objects.length,
  26601. nCachedObjects = this.nCachedObjects_,
  26602. bindingsForPath = new Array( nObjects );
  26603. index = bindings.length;
  26604. indicesByPath[ path ] = index;
  26605. paths.push( path );
  26606. parsedPaths.push( parsedPath );
  26607. bindings.push( bindingsForPath );
  26608. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  26609. var object = objects[ i ];
  26610. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  26611. }
  26612. return bindingsForPath;
  26613. },
  26614. unsubscribe_: function ( path ) {
  26615. // tells the group to forget about a property path and no longer
  26616. // update the array previously obtained with 'subscribe_'
  26617. var indicesByPath = this._bindingsIndicesByPath,
  26618. index = indicesByPath[ path ];
  26619. if ( index !== undefined ) {
  26620. var paths = this._paths,
  26621. parsedPaths = this._parsedPaths,
  26622. bindings = this._bindings,
  26623. lastBindingsIndex = bindings.length - 1,
  26624. lastBindings = bindings[ lastBindingsIndex ],
  26625. lastBindingsPath = path[ lastBindingsIndex ];
  26626. indicesByPath[ lastBindingsPath ] = index;
  26627. bindings[ index ] = lastBindings;
  26628. bindings.pop();
  26629. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  26630. parsedPaths.pop();
  26631. paths[ index ] = paths[ lastBindingsIndex ];
  26632. paths.pop();
  26633. }
  26634. }
  26635. } );
  26636. /**
  26637. *
  26638. * Action provided by AnimationMixer for scheduling clip playback on specific
  26639. * objects.
  26640. *
  26641. * @author Ben Houston / http://clara.io/
  26642. * @author David Sarno / http://lighthaus.us/
  26643. * @author tschw
  26644. *
  26645. */
  26646. function AnimationAction( mixer, clip, localRoot ) {
  26647. this._mixer = mixer;
  26648. this._clip = clip;
  26649. this._localRoot = localRoot || null;
  26650. var tracks = clip.tracks,
  26651. nTracks = tracks.length,
  26652. interpolants = new Array( nTracks );
  26653. var interpolantSettings = {
  26654. endingStart: ZeroCurvatureEnding,
  26655. endingEnd: ZeroCurvatureEnding
  26656. };
  26657. for ( var i = 0; i !== nTracks; ++ i ) {
  26658. var interpolant = tracks[ i ].createInterpolant( null );
  26659. interpolants[ i ] = interpolant;
  26660. interpolant.settings = interpolantSettings;
  26661. }
  26662. this._interpolantSettings = interpolantSettings;
  26663. this._interpolants = interpolants; // bound by the mixer
  26664. // inside: PropertyMixer (managed by the mixer)
  26665. this._propertyBindings = new Array( nTracks );
  26666. this._cacheIndex = null; // for the memory manager
  26667. this._byClipCacheIndex = null; // for the memory manager
  26668. this._timeScaleInterpolant = null;
  26669. this._weightInterpolant = null;
  26670. this.loop = LoopRepeat;
  26671. this._loopCount = - 1;
  26672. // global mixer time when the action is to be started
  26673. // it's set back to 'null' upon start of the action
  26674. this._startTime = null;
  26675. // scaled local time of the action
  26676. // gets clamped or wrapped to 0..clip.duration according to loop
  26677. this.time = 0;
  26678. this.timeScale = 1;
  26679. this._effectiveTimeScale = 1;
  26680. this.weight = 1;
  26681. this._effectiveWeight = 1;
  26682. this.repetitions = Infinity; // no. of repetitions when looping
  26683. this.paused = false; // true -> zero effective time scale
  26684. this.enabled = true; // false -> zero effective weight
  26685. this.clampWhenFinished = false;// keep feeding the last frame?
  26686. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  26687. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  26688. }
  26689. Object.assign( AnimationAction.prototype, {
  26690. // State & Scheduling
  26691. play: function () {
  26692. this._mixer._activateAction( this );
  26693. return this;
  26694. },
  26695. stop: function () {
  26696. this._mixer._deactivateAction( this );
  26697. return this.reset();
  26698. },
  26699. reset: function () {
  26700. this.paused = false;
  26701. this.enabled = true;
  26702. this.time = 0; // restart clip
  26703. this._loopCount = - 1;// forget previous loops
  26704. this._startTime = null;// forget scheduling
  26705. return this.stopFading().stopWarping();
  26706. },
  26707. isRunning: function () {
  26708. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  26709. this._startTime === null && this._mixer._isActiveAction( this );
  26710. },
  26711. // return true when play has been called
  26712. isScheduled: function () {
  26713. return this._mixer._isActiveAction( this );
  26714. },
  26715. startAt: function ( time ) {
  26716. this._startTime = time;
  26717. return this;
  26718. },
  26719. setLoop: function ( mode, repetitions ) {
  26720. this.loop = mode;
  26721. this.repetitions = repetitions;
  26722. return this;
  26723. },
  26724. // Weight
  26725. // set the weight stopping any scheduled fading
  26726. // although .enabled = false yields an effective weight of zero, this
  26727. // method does *not* change .enabled, because it would be confusing
  26728. setEffectiveWeight: function ( weight ) {
  26729. this.weight = weight;
  26730. // note: same logic as when updated at runtime
  26731. this._effectiveWeight = this.enabled ? weight : 0;
  26732. return this.stopFading();
  26733. },
  26734. // return the weight considering fading and .enabled
  26735. getEffectiveWeight: function () {
  26736. return this._effectiveWeight;
  26737. },
  26738. fadeIn: function ( duration ) {
  26739. return this._scheduleFading( duration, 0, 1 );
  26740. },
  26741. fadeOut: function ( duration ) {
  26742. return this._scheduleFading( duration, 1, 0 );
  26743. },
  26744. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  26745. fadeOutAction.fadeOut( duration );
  26746. this.fadeIn( duration );
  26747. if ( warp ) {
  26748. var fadeInDuration = this._clip.duration,
  26749. fadeOutDuration = fadeOutAction._clip.duration,
  26750. startEndRatio = fadeOutDuration / fadeInDuration,
  26751. endStartRatio = fadeInDuration / fadeOutDuration;
  26752. fadeOutAction.warp( 1.0, startEndRatio, duration );
  26753. this.warp( endStartRatio, 1.0, duration );
  26754. }
  26755. return this;
  26756. },
  26757. crossFadeTo: function ( fadeInAction, duration, warp ) {
  26758. return fadeInAction.crossFadeFrom( this, duration, warp );
  26759. },
  26760. stopFading: function () {
  26761. var weightInterpolant = this._weightInterpolant;
  26762. if ( weightInterpolant !== null ) {
  26763. this._weightInterpolant = null;
  26764. this._mixer._takeBackControlInterpolant( weightInterpolant );
  26765. }
  26766. return this;
  26767. },
  26768. // Time Scale Control
  26769. // set the time scale stopping any scheduled warping
  26770. // although .paused = true yields an effective time scale of zero, this
  26771. // method does *not* change .paused, because it would be confusing
  26772. setEffectiveTimeScale: function ( timeScale ) {
  26773. this.timeScale = timeScale;
  26774. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26775. return this.stopWarping();
  26776. },
  26777. // return the time scale considering warping and .paused
  26778. getEffectiveTimeScale: function () {
  26779. return this._effectiveTimeScale;
  26780. },
  26781. setDuration: function ( duration ) {
  26782. this.timeScale = this._clip.duration / duration;
  26783. return this.stopWarping();
  26784. },
  26785. syncWith: function ( action ) {
  26786. this.time = action.time;
  26787. this.timeScale = action.timeScale;
  26788. return this.stopWarping();
  26789. },
  26790. halt: function ( duration ) {
  26791. return this.warp( this._effectiveTimeScale, 0, duration );
  26792. },
  26793. warp: function ( startTimeScale, endTimeScale, duration ) {
  26794. var mixer = this._mixer, now = mixer.time,
  26795. interpolant = this._timeScaleInterpolant,
  26796. timeScale = this.timeScale;
  26797. if ( interpolant === null ) {
  26798. interpolant = mixer._lendControlInterpolant();
  26799. this._timeScaleInterpolant = interpolant;
  26800. }
  26801. var times = interpolant.parameterPositions,
  26802. values = interpolant.sampleValues;
  26803. times[ 0 ] = now;
  26804. times[ 1 ] = now + duration;
  26805. values[ 0 ] = startTimeScale / timeScale;
  26806. values[ 1 ] = endTimeScale / timeScale;
  26807. return this;
  26808. },
  26809. stopWarping: function () {
  26810. var timeScaleInterpolant = this._timeScaleInterpolant;
  26811. if ( timeScaleInterpolant !== null ) {
  26812. this._timeScaleInterpolant = null;
  26813. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  26814. }
  26815. return this;
  26816. },
  26817. // Object Accessors
  26818. getMixer: function () {
  26819. return this._mixer;
  26820. },
  26821. getClip: function () {
  26822. return this._clip;
  26823. },
  26824. getRoot: function () {
  26825. return this._localRoot || this._mixer._root;
  26826. },
  26827. // Interna
  26828. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  26829. // called by the mixer
  26830. if ( ! this.enabled ) {
  26831. // call ._updateWeight() to update ._effectiveWeight
  26832. this._updateWeight( time );
  26833. return;
  26834. }
  26835. var startTime = this._startTime;
  26836. if ( startTime !== null ) {
  26837. // check for scheduled start of action
  26838. var timeRunning = ( time - startTime ) * timeDirection;
  26839. if ( timeRunning < 0 || timeDirection === 0 ) {
  26840. return; // yet to come / don't decide when delta = 0
  26841. }
  26842. // start
  26843. this._startTime = null; // unschedule
  26844. deltaTime = timeDirection * timeRunning;
  26845. }
  26846. // apply time scale and advance time
  26847. deltaTime *= this._updateTimeScale( time );
  26848. var clipTime = this._updateTime( deltaTime );
  26849. // note: _updateTime may disable the action resulting in
  26850. // an effective weight of 0
  26851. var weight = this._updateWeight( time );
  26852. if ( weight > 0 ) {
  26853. var interpolants = this._interpolants;
  26854. var propertyMixers = this._propertyBindings;
  26855. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  26856. interpolants[ j ].evaluate( clipTime );
  26857. propertyMixers[ j ].accumulate( accuIndex, weight );
  26858. }
  26859. }
  26860. },
  26861. _updateWeight: function ( time ) {
  26862. var weight = 0;
  26863. if ( this.enabled ) {
  26864. weight = this.weight;
  26865. var interpolant = this._weightInterpolant;
  26866. if ( interpolant !== null ) {
  26867. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  26868. weight *= interpolantValue;
  26869. if ( time > interpolant.parameterPositions[ 1 ] ) {
  26870. this.stopFading();
  26871. if ( interpolantValue === 0 ) {
  26872. // faded out, disable
  26873. this.enabled = false;
  26874. }
  26875. }
  26876. }
  26877. }
  26878. this._effectiveWeight = weight;
  26879. return weight;
  26880. },
  26881. _updateTimeScale: function ( time ) {
  26882. var timeScale = 0;
  26883. if ( ! this.paused ) {
  26884. timeScale = this.timeScale;
  26885. var interpolant = this._timeScaleInterpolant;
  26886. if ( interpolant !== null ) {
  26887. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  26888. timeScale *= interpolantValue;
  26889. if ( time > interpolant.parameterPositions[ 1 ] ) {
  26890. this.stopWarping();
  26891. if ( timeScale === 0 ) {
  26892. // motion has halted, pause
  26893. this.paused = true;
  26894. } else {
  26895. // warp done - apply final time scale
  26896. this.timeScale = timeScale;
  26897. }
  26898. }
  26899. }
  26900. }
  26901. this._effectiveTimeScale = timeScale;
  26902. return timeScale;
  26903. },
  26904. _updateTime: function ( deltaTime ) {
  26905. var time = this.time + deltaTime;
  26906. var duration = this._clip.duration;
  26907. var loop = this.loop;
  26908. var loopCount = this._loopCount;
  26909. var pingPong = ( loop === LoopPingPong );
  26910. if ( deltaTime === 0 ) {
  26911. if ( loopCount === - 1 ) return time;
  26912. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  26913. }
  26914. if ( loop === LoopOnce ) {
  26915. if ( loopCount === - 1 ) {
  26916. // just started
  26917. this._loopCount = 0;
  26918. this._setEndings( true, true, false );
  26919. }
  26920. handle_stop: {
  26921. if ( time >= duration ) {
  26922. time = duration;
  26923. } else if ( time < 0 ) {
  26924. time = 0;
  26925. } else {
  26926. this.time = time;
  26927. break handle_stop;
  26928. }
  26929. if ( this.clampWhenFinished ) this.paused = true;
  26930. else this.enabled = false;
  26931. this.time = time;
  26932. this._mixer.dispatchEvent( {
  26933. type: 'finished', action: this,
  26934. direction: deltaTime < 0 ? - 1 : 1
  26935. } );
  26936. }
  26937. } else { // repetitive Repeat or PingPong
  26938. if ( loopCount === - 1 ) {
  26939. // just started
  26940. if ( deltaTime >= 0 ) {
  26941. loopCount = 0;
  26942. this._setEndings( true, this.repetitions === 0, pingPong );
  26943. } else {
  26944. // when looping in reverse direction, the initial
  26945. // transition through zero counts as a repetition,
  26946. // so leave loopCount at -1
  26947. this._setEndings( this.repetitions === 0, true, pingPong );
  26948. }
  26949. }
  26950. if ( time >= duration || time < 0 ) {
  26951. // wrap around
  26952. var loopDelta = Math.floor( time / duration ); // signed
  26953. time -= duration * loopDelta;
  26954. loopCount += Math.abs( loopDelta );
  26955. var pending = this.repetitions - loopCount;
  26956. if ( pending <= 0 ) {
  26957. // have to stop (switch state, clamp time, fire event)
  26958. if ( this.clampWhenFinished ) this.paused = true;
  26959. else this.enabled = false;
  26960. time = deltaTime > 0 ? duration : 0;
  26961. this.time = time;
  26962. this._mixer.dispatchEvent( {
  26963. type: 'finished', action: this,
  26964. direction: deltaTime > 0 ? 1 : - 1
  26965. } );
  26966. } else {
  26967. // keep running
  26968. if ( pending === 1 ) {
  26969. // entering the last round
  26970. var atStart = deltaTime < 0;
  26971. this._setEndings( atStart, ! atStart, pingPong );
  26972. } else {
  26973. this._setEndings( false, false, pingPong );
  26974. }
  26975. this._loopCount = loopCount;
  26976. this.time = time;
  26977. this._mixer.dispatchEvent( {
  26978. type: 'loop', action: this, loopDelta: loopDelta
  26979. } );
  26980. }
  26981. } else {
  26982. this.time = time;
  26983. }
  26984. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  26985. // invert time for the "pong round"
  26986. return duration - time;
  26987. }
  26988. }
  26989. return time;
  26990. },
  26991. _setEndings: function ( atStart, atEnd, pingPong ) {
  26992. var settings = this._interpolantSettings;
  26993. if ( pingPong ) {
  26994. settings.endingStart = ZeroSlopeEnding;
  26995. settings.endingEnd = ZeroSlopeEnding;
  26996. } else {
  26997. // assuming for LoopOnce atStart == atEnd == true
  26998. if ( atStart ) {
  26999. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27000. } else {
  27001. settings.endingStart = WrapAroundEnding;
  27002. }
  27003. if ( atEnd ) {
  27004. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27005. } else {
  27006. settings.endingEnd = WrapAroundEnding;
  27007. }
  27008. }
  27009. },
  27010. _scheduleFading: function ( duration, weightNow, weightThen ) {
  27011. var mixer = this._mixer, now = mixer.time,
  27012. interpolant = this._weightInterpolant;
  27013. if ( interpolant === null ) {
  27014. interpolant = mixer._lendControlInterpolant();
  27015. this._weightInterpolant = interpolant;
  27016. }
  27017. var times = interpolant.parameterPositions,
  27018. values = interpolant.sampleValues;
  27019. times[ 0 ] = now;
  27020. values[ 0 ] = weightNow;
  27021. times[ 1 ] = now + duration;
  27022. values[ 1 ] = weightThen;
  27023. return this;
  27024. }
  27025. } );
  27026. /**
  27027. *
  27028. * Player for AnimationClips.
  27029. *
  27030. *
  27031. * @author Ben Houston / http://clara.io/
  27032. * @author David Sarno / http://lighthaus.us/
  27033. * @author tschw
  27034. */
  27035. function AnimationMixer( root ) {
  27036. this._root = root;
  27037. this._initMemoryManager();
  27038. this._accuIndex = 0;
  27039. this.time = 0;
  27040. this.timeScale = 1.0;
  27041. }
  27042. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  27043. constructor: AnimationMixer,
  27044. _bindAction: function ( action, prototypeAction ) {
  27045. var root = action._localRoot || this._root,
  27046. tracks = action._clip.tracks,
  27047. nTracks = tracks.length,
  27048. bindings = action._propertyBindings,
  27049. interpolants = action._interpolants,
  27050. rootUuid = root.uuid,
  27051. bindingsByRoot = this._bindingsByRootAndName,
  27052. bindingsByName = bindingsByRoot[ rootUuid ];
  27053. if ( bindingsByName === undefined ) {
  27054. bindingsByName = {};
  27055. bindingsByRoot[ rootUuid ] = bindingsByName;
  27056. }
  27057. for ( var i = 0; i !== nTracks; ++ i ) {
  27058. var track = tracks[ i ],
  27059. trackName = track.name,
  27060. binding = bindingsByName[ trackName ];
  27061. if ( binding !== undefined ) {
  27062. bindings[ i ] = binding;
  27063. } else {
  27064. binding = bindings[ i ];
  27065. if ( binding !== undefined ) {
  27066. // existing binding, make sure the cache knows
  27067. if ( binding._cacheIndex === null ) {
  27068. ++ binding.referenceCount;
  27069. this._addInactiveBinding( binding, rootUuid, trackName );
  27070. }
  27071. continue;
  27072. }
  27073. var path = prototypeAction && prototypeAction.
  27074. _propertyBindings[ i ].binding.parsedPath;
  27075. binding = new PropertyMixer(
  27076. PropertyBinding.create( root, trackName, path ),
  27077. track.ValueTypeName, track.getValueSize() );
  27078. ++ binding.referenceCount;
  27079. this._addInactiveBinding( binding, rootUuid, trackName );
  27080. bindings[ i ] = binding;
  27081. }
  27082. interpolants[ i ].resultBuffer = binding.buffer;
  27083. }
  27084. },
  27085. _activateAction: function ( action ) {
  27086. if ( ! this._isActiveAction( action ) ) {
  27087. if ( action._cacheIndex === null ) {
  27088. // this action has been forgotten by the cache, but the user
  27089. // appears to be still using it -> rebind
  27090. var rootUuid = ( action._localRoot || this._root ).uuid,
  27091. clipUuid = action._clip.uuid,
  27092. actionsForClip = this._actionsByClip[ clipUuid ];
  27093. this._bindAction( action,
  27094. actionsForClip && actionsForClip.knownActions[ 0 ] );
  27095. this._addInactiveAction( action, clipUuid, rootUuid );
  27096. }
  27097. var bindings = action._propertyBindings;
  27098. // increment reference counts / sort out state
  27099. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  27100. var binding = bindings[ i ];
  27101. if ( binding.useCount ++ === 0 ) {
  27102. this._lendBinding( binding );
  27103. binding.saveOriginalState();
  27104. }
  27105. }
  27106. this._lendAction( action );
  27107. }
  27108. },
  27109. _deactivateAction: function ( action ) {
  27110. if ( this._isActiveAction( action ) ) {
  27111. var bindings = action._propertyBindings;
  27112. // decrement reference counts / sort out state
  27113. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  27114. var binding = bindings[ i ];
  27115. if ( -- binding.useCount === 0 ) {
  27116. binding.restoreOriginalState();
  27117. this._takeBackBinding( binding );
  27118. }
  27119. }
  27120. this._takeBackAction( action );
  27121. }
  27122. },
  27123. // Memory manager
  27124. _initMemoryManager: function () {
  27125. this._actions = []; // 'nActiveActions' followed by inactive ones
  27126. this._nActiveActions = 0;
  27127. this._actionsByClip = {};
  27128. // inside:
  27129. // {
  27130. // knownActions: Array< AnimationAction > - used as prototypes
  27131. // actionByRoot: AnimationAction - lookup
  27132. // }
  27133. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  27134. this._nActiveBindings = 0;
  27135. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  27136. this._controlInterpolants = []; // same game as above
  27137. this._nActiveControlInterpolants = 0;
  27138. var scope = this;
  27139. this.stats = {
  27140. actions: {
  27141. get total() {
  27142. return scope._actions.length;
  27143. },
  27144. get inUse() {
  27145. return scope._nActiveActions;
  27146. }
  27147. },
  27148. bindings: {
  27149. get total() {
  27150. return scope._bindings.length;
  27151. },
  27152. get inUse() {
  27153. return scope._nActiveBindings;
  27154. }
  27155. },
  27156. controlInterpolants: {
  27157. get total() {
  27158. return scope._controlInterpolants.length;
  27159. },
  27160. get inUse() {
  27161. return scope._nActiveControlInterpolants;
  27162. }
  27163. }
  27164. };
  27165. },
  27166. // Memory management for AnimationAction objects
  27167. _isActiveAction: function ( action ) {
  27168. var index = action._cacheIndex;
  27169. return index !== null && index < this._nActiveActions;
  27170. },
  27171. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  27172. var actions = this._actions,
  27173. actionsByClip = this._actionsByClip,
  27174. actionsForClip = actionsByClip[ clipUuid ];
  27175. if ( actionsForClip === undefined ) {
  27176. actionsForClip = {
  27177. knownActions: [ action ],
  27178. actionByRoot: {}
  27179. };
  27180. action._byClipCacheIndex = 0;
  27181. actionsByClip[ clipUuid ] = actionsForClip;
  27182. } else {
  27183. var knownActions = actionsForClip.knownActions;
  27184. action._byClipCacheIndex = knownActions.length;
  27185. knownActions.push( action );
  27186. }
  27187. action._cacheIndex = actions.length;
  27188. actions.push( action );
  27189. actionsForClip.actionByRoot[ rootUuid ] = action;
  27190. },
  27191. _removeInactiveAction: function ( action ) {
  27192. var actions = this._actions,
  27193. lastInactiveAction = actions[ actions.length - 1 ],
  27194. cacheIndex = action._cacheIndex;
  27195. lastInactiveAction._cacheIndex = cacheIndex;
  27196. actions[ cacheIndex ] = lastInactiveAction;
  27197. actions.pop();
  27198. action._cacheIndex = null;
  27199. var clipUuid = action._clip.uuid,
  27200. actionsByClip = this._actionsByClip,
  27201. actionsForClip = actionsByClip[ clipUuid ],
  27202. knownActionsForClip = actionsForClip.knownActions,
  27203. lastKnownAction =
  27204. knownActionsForClip[ knownActionsForClip.length - 1 ],
  27205. byClipCacheIndex = action._byClipCacheIndex;
  27206. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  27207. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  27208. knownActionsForClip.pop();
  27209. action._byClipCacheIndex = null;
  27210. var actionByRoot = actionsForClip.actionByRoot,
  27211. rootUuid = ( action._localRoot || this._root ).uuid;
  27212. delete actionByRoot[ rootUuid ];
  27213. if ( knownActionsForClip.length === 0 ) {
  27214. delete actionsByClip[ clipUuid ];
  27215. }
  27216. this._removeInactiveBindingsForAction( action );
  27217. },
  27218. _removeInactiveBindingsForAction: function ( action ) {
  27219. var bindings = action._propertyBindings;
  27220. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  27221. var binding = bindings[ i ];
  27222. if ( -- binding.referenceCount === 0 ) {
  27223. this._removeInactiveBinding( binding );
  27224. }
  27225. }
  27226. },
  27227. _lendAction: function ( action ) {
  27228. // [ active actions | inactive actions ]
  27229. // [ active actions >| inactive actions ]
  27230. // s a
  27231. // <-swap->
  27232. // a s
  27233. var actions = this._actions,
  27234. prevIndex = action._cacheIndex,
  27235. lastActiveIndex = this._nActiveActions ++,
  27236. firstInactiveAction = actions[ lastActiveIndex ];
  27237. action._cacheIndex = lastActiveIndex;
  27238. actions[ lastActiveIndex ] = action;
  27239. firstInactiveAction._cacheIndex = prevIndex;
  27240. actions[ prevIndex ] = firstInactiveAction;
  27241. },
  27242. _takeBackAction: function ( action ) {
  27243. // [ active actions | inactive actions ]
  27244. // [ active actions |< inactive actions ]
  27245. // a s
  27246. // <-swap->
  27247. // s a
  27248. var actions = this._actions,
  27249. prevIndex = action._cacheIndex,
  27250. firstInactiveIndex = -- this._nActiveActions,
  27251. lastActiveAction = actions[ firstInactiveIndex ];
  27252. action._cacheIndex = firstInactiveIndex;
  27253. actions[ firstInactiveIndex ] = action;
  27254. lastActiveAction._cacheIndex = prevIndex;
  27255. actions[ prevIndex ] = lastActiveAction;
  27256. },
  27257. // Memory management for PropertyMixer objects
  27258. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  27259. var bindingsByRoot = this._bindingsByRootAndName,
  27260. bindingByName = bindingsByRoot[ rootUuid ],
  27261. bindings = this._bindings;
  27262. if ( bindingByName === undefined ) {
  27263. bindingByName = {};
  27264. bindingsByRoot[ rootUuid ] = bindingByName;
  27265. }
  27266. bindingByName[ trackName ] = binding;
  27267. binding._cacheIndex = bindings.length;
  27268. bindings.push( binding );
  27269. },
  27270. _removeInactiveBinding: function ( binding ) {
  27271. var bindings = this._bindings,
  27272. propBinding = binding.binding,
  27273. rootUuid = propBinding.rootNode.uuid,
  27274. trackName = propBinding.path,
  27275. bindingsByRoot = this._bindingsByRootAndName,
  27276. bindingByName = bindingsByRoot[ rootUuid ],
  27277. lastInactiveBinding = bindings[ bindings.length - 1 ],
  27278. cacheIndex = binding._cacheIndex;
  27279. lastInactiveBinding._cacheIndex = cacheIndex;
  27280. bindings[ cacheIndex ] = lastInactiveBinding;
  27281. bindings.pop();
  27282. delete bindingByName[ trackName ];
  27283. if ( Object.keys( bindingByName ).length === 0 ) {
  27284. delete bindingsByRoot[ rootUuid ];
  27285. }
  27286. },
  27287. _lendBinding: function ( binding ) {
  27288. var bindings = this._bindings,
  27289. prevIndex = binding._cacheIndex,
  27290. lastActiveIndex = this._nActiveBindings ++,
  27291. firstInactiveBinding = bindings[ lastActiveIndex ];
  27292. binding._cacheIndex = lastActiveIndex;
  27293. bindings[ lastActiveIndex ] = binding;
  27294. firstInactiveBinding._cacheIndex = prevIndex;
  27295. bindings[ prevIndex ] = firstInactiveBinding;
  27296. },
  27297. _takeBackBinding: function ( binding ) {
  27298. var bindings = this._bindings,
  27299. prevIndex = binding._cacheIndex,
  27300. firstInactiveIndex = -- this._nActiveBindings,
  27301. lastActiveBinding = bindings[ firstInactiveIndex ];
  27302. binding._cacheIndex = firstInactiveIndex;
  27303. bindings[ firstInactiveIndex ] = binding;
  27304. lastActiveBinding._cacheIndex = prevIndex;
  27305. bindings[ prevIndex ] = lastActiveBinding;
  27306. },
  27307. // Memory management of Interpolants for weight and time scale
  27308. _lendControlInterpolant: function () {
  27309. var interpolants = this._controlInterpolants,
  27310. lastActiveIndex = this._nActiveControlInterpolants ++,
  27311. interpolant = interpolants[ lastActiveIndex ];
  27312. if ( interpolant === undefined ) {
  27313. interpolant = new LinearInterpolant(
  27314. new Float32Array( 2 ), new Float32Array( 2 ),
  27315. 1, this._controlInterpolantsResultBuffer );
  27316. interpolant.__cacheIndex = lastActiveIndex;
  27317. interpolants[ lastActiveIndex ] = interpolant;
  27318. }
  27319. return interpolant;
  27320. },
  27321. _takeBackControlInterpolant: function ( interpolant ) {
  27322. var interpolants = this._controlInterpolants,
  27323. prevIndex = interpolant.__cacheIndex,
  27324. firstInactiveIndex = -- this._nActiveControlInterpolants,
  27325. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  27326. interpolant.__cacheIndex = firstInactiveIndex;
  27327. interpolants[ firstInactiveIndex ] = interpolant;
  27328. lastActiveInterpolant.__cacheIndex = prevIndex;
  27329. interpolants[ prevIndex ] = lastActiveInterpolant;
  27330. },
  27331. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  27332. // return an action for a clip optionally using a custom root target
  27333. // object (this method allocates a lot of dynamic memory in case a
  27334. // previously unknown clip/root combination is specified)
  27335. clipAction: function ( clip, optionalRoot ) {
  27336. var root = optionalRoot || this._root,
  27337. rootUuid = root.uuid,
  27338. clipObject = typeof clip === 'string' ?
  27339. AnimationClip.findByName( root, clip ) : clip,
  27340. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  27341. actionsForClip = this._actionsByClip[ clipUuid ],
  27342. prototypeAction = null;
  27343. if ( actionsForClip !== undefined ) {
  27344. var existingAction =
  27345. actionsForClip.actionByRoot[ rootUuid ];
  27346. if ( existingAction !== undefined ) {
  27347. return existingAction;
  27348. }
  27349. // we know the clip, so we don't have to parse all
  27350. // the bindings again but can just copy
  27351. prototypeAction = actionsForClip.knownActions[ 0 ];
  27352. // also, take the clip from the prototype action
  27353. if ( clipObject === null )
  27354. clipObject = prototypeAction._clip;
  27355. }
  27356. // clip must be known when specified via string
  27357. if ( clipObject === null ) return null;
  27358. // allocate all resources required to run it
  27359. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  27360. this._bindAction( newAction, prototypeAction );
  27361. // and make the action known to the memory manager
  27362. this._addInactiveAction( newAction, clipUuid, rootUuid );
  27363. return newAction;
  27364. },
  27365. // get an existing action
  27366. existingAction: function ( clip, optionalRoot ) {
  27367. var root = optionalRoot || this._root,
  27368. rootUuid = root.uuid,
  27369. clipObject = typeof clip === 'string' ?
  27370. AnimationClip.findByName( root, clip ) : clip,
  27371. clipUuid = clipObject ? clipObject.uuid : clip,
  27372. actionsForClip = this._actionsByClip[ clipUuid ];
  27373. if ( actionsForClip !== undefined ) {
  27374. return actionsForClip.actionByRoot[ rootUuid ] || null;
  27375. }
  27376. return null;
  27377. },
  27378. // deactivates all previously scheduled actions
  27379. stopAllAction: function () {
  27380. var actions = this._actions,
  27381. nActions = this._nActiveActions,
  27382. bindings = this._bindings,
  27383. nBindings = this._nActiveBindings;
  27384. this._nActiveActions = 0;
  27385. this._nActiveBindings = 0;
  27386. for ( var i = 0; i !== nActions; ++ i ) {
  27387. actions[ i ].reset();
  27388. }
  27389. for ( var i = 0; i !== nBindings; ++ i ) {
  27390. bindings[ i ].useCount = 0;
  27391. }
  27392. return this;
  27393. },
  27394. // advance the time and update apply the animation
  27395. update: function ( deltaTime ) {
  27396. deltaTime *= this.timeScale;
  27397. var actions = this._actions,
  27398. nActions = this._nActiveActions,
  27399. time = this.time += deltaTime,
  27400. timeDirection = Math.sign( deltaTime ),
  27401. accuIndex = this._accuIndex ^= 1;
  27402. // run active actions
  27403. for ( var i = 0; i !== nActions; ++ i ) {
  27404. var action = actions[ i ];
  27405. action._update( time, deltaTime, timeDirection, accuIndex );
  27406. }
  27407. // update scene graph
  27408. var bindings = this._bindings,
  27409. nBindings = this._nActiveBindings;
  27410. for ( var i = 0; i !== nBindings; ++ i ) {
  27411. bindings[ i ].apply( accuIndex );
  27412. }
  27413. return this;
  27414. },
  27415. // return this mixer's root target object
  27416. getRoot: function () {
  27417. return this._root;
  27418. },
  27419. // free all resources specific to a particular clip
  27420. uncacheClip: function ( clip ) {
  27421. var actions = this._actions,
  27422. clipUuid = clip.uuid,
  27423. actionsByClip = this._actionsByClip,
  27424. actionsForClip = actionsByClip[ clipUuid ];
  27425. if ( actionsForClip !== undefined ) {
  27426. // note: just calling _removeInactiveAction would mess up the
  27427. // iteration state and also require updating the state we can
  27428. // just throw away
  27429. var actionsToRemove = actionsForClip.knownActions;
  27430. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  27431. var action = actionsToRemove[ i ];
  27432. this._deactivateAction( action );
  27433. var cacheIndex = action._cacheIndex,
  27434. lastInactiveAction = actions[ actions.length - 1 ];
  27435. action._cacheIndex = null;
  27436. action._byClipCacheIndex = null;
  27437. lastInactiveAction._cacheIndex = cacheIndex;
  27438. actions[ cacheIndex ] = lastInactiveAction;
  27439. actions.pop();
  27440. this._removeInactiveBindingsForAction( action );
  27441. }
  27442. delete actionsByClip[ clipUuid ];
  27443. }
  27444. },
  27445. // free all resources specific to a particular root target object
  27446. uncacheRoot: function ( root ) {
  27447. var rootUuid = root.uuid,
  27448. actionsByClip = this._actionsByClip;
  27449. for ( var clipUuid in actionsByClip ) {
  27450. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  27451. action = actionByRoot[ rootUuid ];
  27452. if ( action !== undefined ) {
  27453. this._deactivateAction( action );
  27454. this._removeInactiveAction( action );
  27455. }
  27456. }
  27457. var bindingsByRoot = this._bindingsByRootAndName,
  27458. bindingByName = bindingsByRoot[ rootUuid ];
  27459. if ( bindingByName !== undefined ) {
  27460. for ( var trackName in bindingByName ) {
  27461. var binding = bindingByName[ trackName ];
  27462. binding.restoreOriginalState();
  27463. this._removeInactiveBinding( binding );
  27464. }
  27465. }
  27466. },
  27467. // remove a targeted clip from the cache
  27468. uncacheAction: function ( clip, optionalRoot ) {
  27469. var action = this.existingAction( clip, optionalRoot );
  27470. if ( action !== null ) {
  27471. this._deactivateAction( action );
  27472. this._removeInactiveAction( action );
  27473. }
  27474. }
  27475. } );
  27476. /**
  27477. * @author mrdoob / http://mrdoob.com/
  27478. */
  27479. function Uniform( value ) {
  27480. if ( typeof value === 'string' ) {
  27481. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  27482. value = arguments[ 1 ];
  27483. }
  27484. this.value = value;
  27485. }
  27486. Uniform.prototype.clone = function () {
  27487. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  27488. };
  27489. /**
  27490. * @author benaadams / https://twitter.com/ben_a_adams
  27491. */
  27492. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  27493. InterleavedBuffer.call( this, array, stride );
  27494. this.meshPerAttribute = meshPerAttribute || 1;
  27495. }
  27496. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  27497. constructor: InstancedInterleavedBuffer,
  27498. isInstancedInterleavedBuffer: true,
  27499. copy: function ( source ) {
  27500. InterleavedBuffer.prototype.copy.call( this, source );
  27501. this.meshPerAttribute = source.meshPerAttribute;
  27502. return this;
  27503. }
  27504. } );
  27505. /**
  27506. * @author mrdoob / http://mrdoob.com/
  27507. * @author bhouston / http://clara.io/
  27508. * @author stephomi / http://stephaneginier.com/
  27509. */
  27510. function Raycaster( origin, direction, near, far ) {
  27511. this.ray = new Ray( origin, direction );
  27512. // direction is assumed to be normalized (for accurate distance calculations)
  27513. this.near = near || 0;
  27514. this.far = far || Infinity;
  27515. this.params = {
  27516. Mesh: {},
  27517. Line: {},
  27518. LOD: {},
  27519. Points: { threshold: 1 },
  27520. Sprite: {}
  27521. };
  27522. Object.defineProperties( this.params, {
  27523. PointCloud: {
  27524. get: function () {
  27525. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  27526. return this.Points;
  27527. }
  27528. }
  27529. } );
  27530. }
  27531. function ascSort( a, b ) {
  27532. return a.distance - b.distance;
  27533. }
  27534. function intersectObject( object, raycaster, intersects, recursive ) {
  27535. if ( object.visible === false ) return;
  27536. object.raycast( raycaster, intersects );
  27537. if ( recursive === true ) {
  27538. var children = object.children;
  27539. for ( var i = 0, l = children.length; i < l; i ++ ) {
  27540. intersectObject( children[ i ], raycaster, intersects, true );
  27541. }
  27542. }
  27543. }
  27544. Object.assign( Raycaster.prototype, {
  27545. linePrecision: 1,
  27546. set: function ( origin, direction ) {
  27547. // direction is assumed to be normalized (for accurate distance calculations)
  27548. this.ray.set( origin, direction );
  27549. },
  27550. setFromCamera: function ( coords, camera ) {
  27551. if ( ( camera && camera.isPerspectiveCamera ) ) {
  27552. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  27553. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  27554. this._camera = camera;
  27555. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  27556. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  27557. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  27558. this._camera = camera;
  27559. } else {
  27560. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  27561. }
  27562. },
  27563. intersectObject: function ( object, recursive, optionalTarget ) {
  27564. var intersects = optionalTarget || [];
  27565. intersectObject( object, this, intersects, recursive );
  27566. intersects.sort( ascSort );
  27567. return intersects;
  27568. },
  27569. intersectObjects: function ( objects, recursive, optionalTarget ) {
  27570. var intersects = optionalTarget || [];
  27571. if ( Array.isArray( objects ) === false ) {
  27572. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  27573. return intersects;
  27574. }
  27575. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  27576. intersectObject( objects[ i ], this, intersects, recursive );
  27577. }
  27578. intersects.sort( ascSort );
  27579. return intersects;
  27580. }
  27581. } );
  27582. /**
  27583. * @author bhouston / http://clara.io
  27584. * @author WestLangley / http://github.com/WestLangley
  27585. *
  27586. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27587. *
  27588. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27589. * The azimuthal angle (theta) is measured from the positive z-axiz.
  27590. */
  27591. function Spherical( radius, phi, theta ) {
  27592. this.radius = ( radius !== undefined ) ? radius : 1.0;
  27593. this.phi = ( phi !== undefined ) ? phi : 0; // polar angle
  27594. this.theta = ( theta !== undefined ) ? theta : 0; // azimuthal angle
  27595. return this;
  27596. }
  27597. Object.assign( Spherical.prototype, {
  27598. set: function ( radius, phi, theta ) {
  27599. this.radius = radius;
  27600. this.phi = phi;
  27601. this.theta = theta;
  27602. return this;
  27603. },
  27604. clone: function () {
  27605. return new this.constructor().copy( this );
  27606. },
  27607. copy: function ( other ) {
  27608. this.radius = other.radius;
  27609. this.phi = other.phi;
  27610. this.theta = other.theta;
  27611. return this;
  27612. },
  27613. // restrict phi to be betwee EPS and PI-EPS
  27614. makeSafe: function () {
  27615. var EPS = 0.000001;
  27616. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  27617. return this;
  27618. },
  27619. setFromVector3: function ( v ) {
  27620. return this.setFromCartesianCoords( v.x, v.y, v.z );
  27621. },
  27622. setFromCartesianCoords: function ( x, y, z ) {
  27623. this.radius = Math.sqrt( x * x + y * y + z * z );
  27624. if ( this.radius === 0 ) {
  27625. this.theta = 0;
  27626. this.phi = 0;
  27627. } else {
  27628. this.theta = Math.atan2( x, z );
  27629. this.phi = Math.acos( _Math.clamp( y / this.radius, - 1, 1 ) );
  27630. }
  27631. return this;
  27632. }
  27633. } );
  27634. /**
  27635. * @author Mugen87 / https://github.com/Mugen87
  27636. *
  27637. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27638. *
  27639. */
  27640. function Cylindrical( radius, theta, y ) {
  27641. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  27642. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27643. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  27644. return this;
  27645. }
  27646. Object.assign( Cylindrical.prototype, {
  27647. set: function ( radius, theta, y ) {
  27648. this.radius = radius;
  27649. this.theta = theta;
  27650. this.y = y;
  27651. return this;
  27652. },
  27653. clone: function () {
  27654. return new this.constructor().copy( this );
  27655. },
  27656. copy: function ( other ) {
  27657. this.radius = other.radius;
  27658. this.theta = other.theta;
  27659. this.y = other.y;
  27660. return this;
  27661. },
  27662. setFromVector3: function ( v ) {
  27663. return this.setFromCartesianCoords( v.x, v.y, v.z );
  27664. },
  27665. setFromCartesianCoords: function ( x, y, z ) {
  27666. this.radius = Math.sqrt( x * x + z * z );
  27667. this.theta = Math.atan2( x, z );
  27668. this.y = y;
  27669. return this;
  27670. }
  27671. } );
  27672. /**
  27673. * @author bhouston / http://clara.io
  27674. */
  27675. function Box2( min, max ) {
  27676. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  27677. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  27678. }
  27679. Object.assign( Box2.prototype, {
  27680. set: function ( min, max ) {
  27681. this.min.copy( min );
  27682. this.max.copy( max );
  27683. return this;
  27684. },
  27685. setFromPoints: function ( points ) {
  27686. this.makeEmpty();
  27687. for ( var i = 0, il = points.length; i < il; i ++ ) {
  27688. this.expandByPoint( points[ i ] );
  27689. }
  27690. return this;
  27691. },
  27692. setFromCenterAndSize: function () {
  27693. var v1 = new Vector2();
  27694. return function setFromCenterAndSize( center, size ) {
  27695. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  27696. this.min.copy( center ).sub( halfSize );
  27697. this.max.copy( center ).add( halfSize );
  27698. return this;
  27699. };
  27700. }(),
  27701. clone: function () {
  27702. return new this.constructor().copy( this );
  27703. },
  27704. copy: function ( box ) {
  27705. this.min.copy( box.min );
  27706. this.max.copy( box.max );
  27707. return this;
  27708. },
  27709. makeEmpty: function () {
  27710. this.min.x = this.min.y = + Infinity;
  27711. this.max.x = this.max.y = - Infinity;
  27712. return this;
  27713. },
  27714. isEmpty: function () {
  27715. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27716. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  27717. },
  27718. getCenter: function ( target ) {
  27719. if ( target === undefined ) {
  27720. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  27721. target = new Vector2();
  27722. }
  27723. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  27724. },
  27725. getSize: function ( target ) {
  27726. if ( target === undefined ) {
  27727. console.warn( 'THREE.Box2: .getSize() target is now required' );
  27728. target = new Vector2();
  27729. }
  27730. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  27731. },
  27732. expandByPoint: function ( point ) {
  27733. this.min.min( point );
  27734. this.max.max( point );
  27735. return this;
  27736. },
  27737. expandByVector: function ( vector ) {
  27738. this.min.sub( vector );
  27739. this.max.add( vector );
  27740. return this;
  27741. },
  27742. expandByScalar: function ( scalar ) {
  27743. this.min.addScalar( - scalar );
  27744. this.max.addScalar( scalar );
  27745. return this;
  27746. },
  27747. containsPoint: function ( point ) {
  27748. return point.x < this.min.x || point.x > this.max.x ||
  27749. point.y < this.min.y || point.y > this.max.y ? false : true;
  27750. },
  27751. containsBox: function ( box ) {
  27752. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  27753. this.min.y <= box.min.y && box.max.y <= this.max.y;
  27754. },
  27755. getParameter: function ( point, target ) {
  27756. // This can potentially have a divide by zero if the box
  27757. // has a size dimension of 0.
  27758. if ( target === undefined ) {
  27759. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  27760. target = new Vector2();
  27761. }
  27762. return target.set(
  27763. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  27764. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  27765. );
  27766. },
  27767. intersectsBox: function ( box ) {
  27768. // using 4 splitting planes to rule out intersections
  27769. return box.max.x < this.min.x || box.min.x > this.max.x ||
  27770. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  27771. },
  27772. clampPoint: function ( point, target ) {
  27773. if ( target === undefined ) {
  27774. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  27775. target = new Vector2();
  27776. }
  27777. return target.copy( point ).clamp( this.min, this.max );
  27778. },
  27779. distanceToPoint: function () {
  27780. var v1 = new Vector2();
  27781. return function distanceToPoint( point ) {
  27782. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  27783. return clampedPoint.sub( point ).length();
  27784. };
  27785. }(),
  27786. intersect: function ( box ) {
  27787. this.min.max( box.min );
  27788. this.max.min( box.max );
  27789. return this;
  27790. },
  27791. union: function ( box ) {
  27792. this.min.min( box.min );
  27793. this.max.max( box.max );
  27794. return this;
  27795. },
  27796. translate: function ( offset ) {
  27797. this.min.add( offset );
  27798. this.max.add( offset );
  27799. return this;
  27800. },
  27801. equals: function ( box ) {
  27802. return box.min.equals( this.min ) && box.max.equals( this.max );
  27803. }
  27804. } );
  27805. /**
  27806. * @author bhouston / http://clara.io
  27807. */
  27808. function Line3( start, end ) {
  27809. this.start = ( start !== undefined ) ? start : new Vector3();
  27810. this.end = ( end !== undefined ) ? end : new Vector3();
  27811. }
  27812. Object.assign( Line3.prototype, {
  27813. set: function ( start, end ) {
  27814. this.start.copy( start );
  27815. this.end.copy( end );
  27816. return this;
  27817. },
  27818. clone: function () {
  27819. return new this.constructor().copy( this );
  27820. },
  27821. copy: function ( line ) {
  27822. this.start.copy( line.start );
  27823. this.end.copy( line.end );
  27824. return this;
  27825. },
  27826. getCenter: function ( target ) {
  27827. if ( target === undefined ) {
  27828. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  27829. target = new Vector3();
  27830. }
  27831. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  27832. },
  27833. delta: function ( target ) {
  27834. if ( target === undefined ) {
  27835. console.warn( 'THREE.Line3: .delta() target is now required' );
  27836. target = new Vector3();
  27837. }
  27838. return target.subVectors( this.end, this.start );
  27839. },
  27840. distanceSq: function () {
  27841. return this.start.distanceToSquared( this.end );
  27842. },
  27843. distance: function () {
  27844. return this.start.distanceTo( this.end );
  27845. },
  27846. at: function ( t, target ) {
  27847. if ( target === undefined ) {
  27848. console.warn( 'THREE.Line3: .at() target is now required' );
  27849. target = new Vector3();
  27850. }
  27851. return this.delta( target ).multiplyScalar( t ).add( this.start );
  27852. },
  27853. closestPointToPointParameter: function () {
  27854. var startP = new Vector3();
  27855. var startEnd = new Vector3();
  27856. return function closestPointToPointParameter( point, clampToLine ) {
  27857. startP.subVectors( point, this.start );
  27858. startEnd.subVectors( this.end, this.start );
  27859. var startEnd2 = startEnd.dot( startEnd );
  27860. var startEnd_startP = startEnd.dot( startP );
  27861. var t = startEnd_startP / startEnd2;
  27862. if ( clampToLine ) {
  27863. t = _Math.clamp( t, 0, 1 );
  27864. }
  27865. return t;
  27866. };
  27867. }(),
  27868. closestPointToPoint: function ( point, clampToLine, target ) {
  27869. var t = this.closestPointToPointParameter( point, clampToLine );
  27870. if ( target === undefined ) {
  27871. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  27872. target = new Vector3();
  27873. }
  27874. return this.delta( target ).multiplyScalar( t ).add( this.start );
  27875. },
  27876. applyMatrix4: function ( matrix ) {
  27877. this.start.applyMatrix4( matrix );
  27878. this.end.applyMatrix4( matrix );
  27879. return this;
  27880. },
  27881. equals: function ( line ) {
  27882. return line.start.equals( this.start ) && line.end.equals( this.end );
  27883. }
  27884. } );
  27885. /**
  27886. * @author alteredq / http://alteredqualia.com/
  27887. */
  27888. function ImmediateRenderObject( material ) {
  27889. Object3D.call( this );
  27890. this.material = material;
  27891. this.render = function ( /* renderCallback */ ) {};
  27892. }
  27893. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  27894. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27895. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27896. /**
  27897. * @author mrdoob / http://mrdoob.com/
  27898. * @author WestLangley / http://github.com/WestLangley
  27899. */
  27900. function VertexNormalsHelper( object, size, hex, linewidth ) {
  27901. this.object = object;
  27902. this.size = ( size !== undefined ) ? size : 1;
  27903. var color = ( hex !== undefined ) ? hex : 0xff0000;
  27904. var width = ( linewidth !== undefined ) ? linewidth : 1;
  27905. //
  27906. var nNormals = 0;
  27907. var objGeometry = this.object.geometry;
  27908. if ( objGeometry && objGeometry.isGeometry ) {
  27909. nNormals = objGeometry.faces.length * 3;
  27910. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  27911. nNormals = objGeometry.attributes.normal.count;
  27912. }
  27913. //
  27914. var geometry = new BufferGeometry();
  27915. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  27916. geometry.addAttribute( 'position', positions );
  27917. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  27918. //
  27919. this.matrixAutoUpdate = false;
  27920. this.update();
  27921. }
  27922. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  27923. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  27924. VertexNormalsHelper.prototype.update = ( function () {
  27925. var v1 = new Vector3();
  27926. var v2 = new Vector3();
  27927. var normalMatrix = new Matrix3();
  27928. return function update() {
  27929. var keys = [ 'a', 'b', 'c' ];
  27930. this.object.updateMatrixWorld( true );
  27931. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  27932. var matrixWorld = this.object.matrixWorld;
  27933. var position = this.geometry.attributes.position;
  27934. //
  27935. var objGeometry = this.object.geometry;
  27936. if ( objGeometry && objGeometry.isGeometry ) {
  27937. var vertices = objGeometry.vertices;
  27938. var faces = objGeometry.faces;
  27939. var idx = 0;
  27940. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  27941. var face = faces[ i ];
  27942. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  27943. var vertex = vertices[ face[ keys[ j ] ] ];
  27944. var normal = face.vertexNormals[ j ];
  27945. v1.copy( vertex ).applyMatrix4( matrixWorld );
  27946. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  27947. position.setXYZ( idx, v1.x, v1.y, v1.z );
  27948. idx = idx + 1;
  27949. position.setXYZ( idx, v2.x, v2.y, v2.z );
  27950. idx = idx + 1;
  27951. }
  27952. }
  27953. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  27954. var objPos = objGeometry.attributes.position;
  27955. var objNorm = objGeometry.attributes.normal;
  27956. var idx = 0;
  27957. // for simplicity, ignore index and drawcalls, and render every normal
  27958. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  27959. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  27960. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  27961. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  27962. position.setXYZ( idx, v1.x, v1.y, v1.z );
  27963. idx = idx + 1;
  27964. position.setXYZ( idx, v2.x, v2.y, v2.z );
  27965. idx = idx + 1;
  27966. }
  27967. }
  27968. position.needsUpdate = true;
  27969. };
  27970. }() );
  27971. /**
  27972. * @author alteredq / http://alteredqualia.com/
  27973. * @author mrdoob / http://mrdoob.com/
  27974. * @author WestLangley / http://github.com/WestLangley
  27975. */
  27976. function SpotLightHelper( light, color ) {
  27977. Object3D.call( this );
  27978. this.light = light;
  27979. this.light.updateMatrixWorld();
  27980. this.matrix = light.matrixWorld;
  27981. this.matrixAutoUpdate = false;
  27982. this.color = color;
  27983. var geometry = new BufferGeometry();
  27984. var positions = [
  27985. 0, 0, 0, 0, 0, 1,
  27986. 0, 0, 0, 1, 0, 1,
  27987. 0, 0, 0, - 1, 0, 1,
  27988. 0, 0, 0, 0, 1, 1,
  27989. 0, 0, 0, 0, - 1, 1
  27990. ];
  27991. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  27992. var p1 = ( i / l ) * Math.PI * 2;
  27993. var p2 = ( j / l ) * Math.PI * 2;
  27994. positions.push(
  27995. Math.cos( p1 ), Math.sin( p1 ), 1,
  27996. Math.cos( p2 ), Math.sin( p2 ), 1
  27997. );
  27998. }
  27999. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28000. var material = new LineBasicMaterial( { fog: false } );
  28001. this.cone = new LineSegments( geometry, material );
  28002. this.add( this.cone );
  28003. this.update();
  28004. }
  28005. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  28006. SpotLightHelper.prototype.constructor = SpotLightHelper;
  28007. SpotLightHelper.prototype.dispose = function () {
  28008. this.cone.geometry.dispose();
  28009. this.cone.material.dispose();
  28010. };
  28011. SpotLightHelper.prototype.update = function () {
  28012. var vector = new Vector3();
  28013. return function update() {
  28014. this.light.updateMatrixWorld();
  28015. var coneLength = this.light.distance ? this.light.distance : 1000;
  28016. var coneWidth = coneLength * Math.tan( this.light.angle );
  28017. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  28018. vector.setFromMatrixPosition( this.light.target.matrixWorld );
  28019. this.cone.lookAt( vector );
  28020. if ( this.color !== undefined ) {
  28021. this.cone.material.color.set( this.color );
  28022. } else {
  28023. this.cone.material.color.copy( this.light.color );
  28024. }
  28025. };
  28026. }();
  28027. /**
  28028. * @author Sean Griffin / http://twitter.com/sgrif
  28029. * @author Michael Guerrero / http://realitymeltdown.com
  28030. * @author mrdoob / http://mrdoob.com/
  28031. * @author ikerr / http://verold.com
  28032. * @author Mugen87 / https://github.com/Mugen87
  28033. */
  28034. function getBoneList( object ) {
  28035. var boneList = [];
  28036. if ( object && object.isBone ) {
  28037. boneList.push( object );
  28038. }
  28039. for ( var i = 0; i < object.children.length; i ++ ) {
  28040. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  28041. }
  28042. return boneList;
  28043. }
  28044. function SkeletonHelper( object ) {
  28045. var bones = getBoneList( object );
  28046. var geometry = new BufferGeometry();
  28047. var vertices = [];
  28048. var colors = [];
  28049. var color1 = new Color( 0, 0, 1 );
  28050. var color2 = new Color( 0, 1, 0 );
  28051. for ( var i = 0; i < bones.length; i ++ ) {
  28052. var bone = bones[ i ];
  28053. if ( bone.parent && bone.parent.isBone ) {
  28054. vertices.push( 0, 0, 0 );
  28055. vertices.push( 0, 0, 0 );
  28056. colors.push( color1.r, color1.g, color1.b );
  28057. colors.push( color2.r, color2.g, color2.b );
  28058. }
  28059. }
  28060. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28061. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28062. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  28063. LineSegments.call( this, geometry, material );
  28064. this.root = object;
  28065. this.bones = bones;
  28066. this.matrix = object.matrixWorld;
  28067. this.matrixAutoUpdate = false;
  28068. }
  28069. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  28070. SkeletonHelper.prototype.constructor = SkeletonHelper;
  28071. SkeletonHelper.prototype.updateMatrixWorld = function () {
  28072. var vector = new Vector3();
  28073. var boneMatrix = new Matrix4();
  28074. var matrixWorldInv = new Matrix4();
  28075. return function updateMatrixWorld( force ) {
  28076. var bones = this.bones;
  28077. var geometry = this.geometry;
  28078. var position = geometry.getAttribute( 'position' );
  28079. matrixWorldInv.getInverse( this.root.matrixWorld );
  28080. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  28081. var bone = bones[ i ];
  28082. if ( bone.parent && bone.parent.isBone ) {
  28083. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  28084. vector.setFromMatrixPosition( boneMatrix );
  28085. position.setXYZ( j, vector.x, vector.y, vector.z );
  28086. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  28087. vector.setFromMatrixPosition( boneMatrix );
  28088. position.setXYZ( j + 1, vector.x, vector.y, vector.z );
  28089. j += 2;
  28090. }
  28091. }
  28092. geometry.getAttribute( 'position' ).needsUpdate = true;
  28093. Object3D.prototype.updateMatrixWorld.call( this, force );
  28094. };
  28095. }();
  28096. /**
  28097. * @author alteredq / http://alteredqualia.com/
  28098. * @author mrdoob / http://mrdoob.com/
  28099. */
  28100. function PointLightHelper( light, sphereSize, color ) {
  28101. this.light = light;
  28102. this.light.updateMatrixWorld();
  28103. this.color = color;
  28104. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  28105. var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  28106. Mesh.call( this, geometry, material );
  28107. this.matrix = this.light.matrixWorld;
  28108. this.matrixAutoUpdate = false;
  28109. this.update();
  28110. /*
  28111. var distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  28112. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  28113. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  28114. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  28115. var d = light.distance;
  28116. if ( d === 0.0 ) {
  28117. this.lightDistance.visible = false;
  28118. } else {
  28119. this.lightDistance.scale.set( d, d, d );
  28120. }
  28121. this.add( this.lightDistance );
  28122. */
  28123. }
  28124. PointLightHelper.prototype = Object.create( Mesh.prototype );
  28125. PointLightHelper.prototype.constructor = PointLightHelper;
  28126. PointLightHelper.prototype.dispose = function () {
  28127. this.geometry.dispose();
  28128. this.material.dispose();
  28129. };
  28130. PointLightHelper.prototype.update = function () {
  28131. if ( this.color !== undefined ) {
  28132. this.material.color.set( this.color );
  28133. } else {
  28134. this.material.color.copy( this.light.color );
  28135. }
  28136. /*
  28137. var d = this.light.distance;
  28138. if ( d === 0.0 ) {
  28139. this.lightDistance.visible = false;
  28140. } else {
  28141. this.lightDistance.visible = true;
  28142. this.lightDistance.scale.set( d, d, d );
  28143. }
  28144. */
  28145. };
  28146. /**
  28147. * @author abelnation / http://github.com/abelnation
  28148. * @author Mugen87 / http://github.com/Mugen87
  28149. * @author WestLangley / http://github.com/WestLangley
  28150. *
  28151. * This helper must be added as a child of the light
  28152. */
  28153. function RectAreaLightHelper( light, color ) {
  28154. this.type = 'RectAreaLightHelper';
  28155. this.light = light;
  28156. this.color = color; // optional hardwired color for the helper
  28157. var positions = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, - 1, 0, 1, 1, 0 ];
  28158. var geometry = new BufferGeometry();
  28159. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28160. geometry.computeBoundingSphere();
  28161. var material = new LineBasicMaterial( { fog: false } );
  28162. Line.call( this, geometry, material );
  28163. //
  28164. var positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
  28165. var geometry2 = new BufferGeometry();
  28166. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  28167. geometry2.computeBoundingSphere();
  28168. this.add( new Mesh( geometry2, new MeshBasicMaterial( { side: BackSide, fog: false } ) ) );
  28169. this.update();
  28170. }
  28171. RectAreaLightHelper.prototype = Object.create( Line.prototype );
  28172. RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
  28173. RectAreaLightHelper.prototype.update = function () {
  28174. this.scale.set( 0.5 * this.light.width, 0.5 * this.light.height, 1 );
  28175. if ( this.color !== undefined ) {
  28176. this.material.color.set( this.color );
  28177. this.children[ 0 ].material.color.set( this.color );
  28178. } else {
  28179. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  28180. // prevent hue shift
  28181. var c = this.material.color;
  28182. var max = Math.max( c.r, c.g, c.b );
  28183. if ( max > 1 ) c.multiplyScalar( 1 / max );
  28184. this.children[ 0 ].material.color.copy( this.material.color );
  28185. }
  28186. };
  28187. RectAreaLightHelper.prototype.dispose = function () {
  28188. this.geometry.dispose();
  28189. this.material.dispose();
  28190. this.children[ 0 ].geometry.dispose();
  28191. this.children[ 0 ].material.dispose();
  28192. };
  28193. /**
  28194. * @author alteredq / http://alteredqualia.com/
  28195. * @author mrdoob / http://mrdoob.com/
  28196. * @author Mugen87 / https://github.com/Mugen87
  28197. */
  28198. function HemisphereLightHelper( light, size, color ) {
  28199. Object3D.call( this );
  28200. this.light = light;
  28201. this.light.updateMatrixWorld();
  28202. this.matrix = light.matrixWorld;
  28203. this.matrixAutoUpdate = false;
  28204. this.color = color;
  28205. var geometry = new OctahedronBufferGeometry( size );
  28206. geometry.rotateY( Math.PI * 0.5 );
  28207. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  28208. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  28209. var position = geometry.getAttribute( 'position' );
  28210. var colors = new Float32Array( position.count * 3 );
  28211. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  28212. this.add( new Mesh( geometry, this.material ) );
  28213. this.update();
  28214. }
  28215. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  28216. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  28217. HemisphereLightHelper.prototype.dispose = function () {
  28218. this.children[ 0 ].geometry.dispose();
  28219. this.children[ 0 ].material.dispose();
  28220. };
  28221. HemisphereLightHelper.prototype.update = function () {
  28222. var vector = new Vector3();
  28223. var color1 = new Color();
  28224. var color2 = new Color();
  28225. return function update() {
  28226. var mesh = this.children[ 0 ];
  28227. if ( this.color !== undefined ) {
  28228. this.material.color.set( this.color );
  28229. } else {
  28230. var colors = mesh.geometry.getAttribute( 'color' );
  28231. color1.copy( this.light.color );
  28232. color2.copy( this.light.groundColor );
  28233. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  28234. var color = ( i < ( l / 2 ) ) ? color1 : color2;
  28235. colors.setXYZ( i, color.r, color.g, color.b );
  28236. }
  28237. colors.needsUpdate = true;
  28238. }
  28239. mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  28240. };
  28241. }();
  28242. /**
  28243. * @author WestLangley / http://github.com/WestLangley
  28244. */
  28245. function LightProbeHelper( lightProbe, size ) {
  28246. this.lightProbe = lightProbe;
  28247. this.size = size;
  28248. var defines = {};
  28249. defines[ 'GAMMA_OUTPUT' ] = "";
  28250. // material
  28251. var material = new ShaderMaterial( {
  28252. defines: defines,
  28253. uniforms: {
  28254. sh: { value: this.lightProbe.sh.coefficients }, // by reference
  28255. intensity: { value: this.lightProbe.intensity }
  28256. },
  28257. vertexShader: [
  28258. 'varying vec3 vNormal;',
  28259. 'void main() {',
  28260. ' vNormal = normalize( normalMatrix * normal );',
  28261. ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
  28262. '}',
  28263. ].join( '\n' ),
  28264. fragmentShader: [
  28265. '#define RECIPROCAL_PI 0.318309886',
  28266. 'vec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {',
  28267. ' // matrix is assumed to be orthogonal',
  28268. ' return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );',
  28269. '}',
  28270. 'vec3 linearToOutput( in vec3 a ) {',
  28271. ' #ifdef GAMMA_OUTPUT',
  28272. ' return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );',
  28273. ' #else',
  28274. ' return a;',
  28275. ' #endif',
  28276. '}',
  28277. '// source: https://graphics.stanford.edu/papers/envmap/envmap.pdf',
  28278. 'vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {',
  28279. ' // normal is assumed to have unit length',
  28280. ' float x = normal.x, y = normal.y, z = normal.z;',
  28281. ' // band 0',
  28282. ' vec3 result = shCoefficients[ 0 ] * 0.886227;',
  28283. ' // band 1',
  28284. ' result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;',
  28285. ' result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;',
  28286. ' result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;',
  28287. ' // band 2',
  28288. ' result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;',
  28289. ' result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;',
  28290. ' result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );',
  28291. ' result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;',
  28292. ' result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );',
  28293. ' return result;',
  28294. '}',
  28295. 'uniform vec3 sh[ 9 ]; // sh coefficients',
  28296. 'uniform float intensity; // light probe intensity',
  28297. 'varying vec3 vNormal;',
  28298. 'void main() {',
  28299. ' vec3 normal = normalize( vNormal );',
  28300. ' vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );',
  28301. ' vec3 irradiance = shGetIrradianceAt( worldNormal, sh );',
  28302. ' vec3 outgoingLight = RECIPROCAL_PI * irradiance * intensity;',
  28303. ' outgoingLight = linearToOutput( outgoingLight );',
  28304. ' gl_FragColor = vec4( outgoingLight, 1.0 );',
  28305. '}'
  28306. ].join( '\n' )
  28307. } );
  28308. var geometry = new SphereBufferGeometry( 1, 32, 16 );
  28309. Mesh.call( this, geometry, material );
  28310. this.onBeforeRender();
  28311. }
  28312. LightProbeHelper.prototype = Object.create( Mesh.prototype );
  28313. LightProbeHelper.prototype.constructor = LightProbeHelper;
  28314. LightProbeHelper.prototype.dispose = function () {
  28315. this.geometry.dispose();
  28316. this.material.dispose();
  28317. };
  28318. LightProbeHelper.prototype.onBeforeRender = function () {
  28319. return function update() {
  28320. this.position.copy( this.lightProbe.position );
  28321. this.scale.set( 1, 1, 1 ).multiplyScalar( this.size );
  28322. this.material.uniforms.intensity.value = this.lightProbe.intensity;
  28323. };
  28324. }();
  28325. /**
  28326. * @author mrdoob / http://mrdoob.com/
  28327. */
  28328. function GridHelper( size, divisions, color1, color2 ) {
  28329. size = size || 10;
  28330. divisions = divisions || 10;
  28331. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  28332. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  28333. var center = divisions / 2;
  28334. var step = size / divisions;
  28335. var halfSize = size / 2;
  28336. var vertices = [], colors = [];
  28337. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  28338. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  28339. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  28340. var color = i === center ? color1 : color2;
  28341. color.toArray( colors, j ); j += 3;
  28342. color.toArray( colors, j ); j += 3;
  28343. color.toArray( colors, j ); j += 3;
  28344. color.toArray( colors, j ); j += 3;
  28345. }
  28346. var geometry = new BufferGeometry();
  28347. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28348. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28349. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  28350. LineSegments.call( this, geometry, material );
  28351. }
  28352. GridHelper.prototype = Object.assign( Object.create( LineSegments.prototype ), {
  28353. constructor: GridHelper,
  28354. copy: function ( source ) {
  28355. LineSegments.prototype.copy.call( this, source );
  28356. this.geometry.copy( source.geometry );
  28357. this.material.copy( source.material );
  28358. return this;
  28359. },
  28360. clone: function () {
  28361. return new this.constructor().copy( this );
  28362. }
  28363. } );
  28364. /**
  28365. * @author mrdoob / http://mrdoob.com/
  28366. * @author Mugen87 / http://github.com/Mugen87
  28367. * @author Hectate / http://www.github.com/Hectate
  28368. */
  28369. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  28370. radius = radius || 10;
  28371. radials = radials || 16;
  28372. circles = circles || 8;
  28373. divisions = divisions || 64;
  28374. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  28375. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  28376. var vertices = [];
  28377. var colors = [];
  28378. var x, z;
  28379. var v, i, j, r, color;
  28380. // create the radials
  28381. for ( i = 0; i <= radials; i ++ ) {
  28382. v = ( i / radials ) * ( Math.PI * 2 );
  28383. x = Math.sin( v ) * radius;
  28384. z = Math.cos( v ) * radius;
  28385. vertices.push( 0, 0, 0 );
  28386. vertices.push( x, 0, z );
  28387. color = ( i & 1 ) ? color1 : color2;
  28388. colors.push( color.r, color.g, color.b );
  28389. colors.push( color.r, color.g, color.b );
  28390. }
  28391. // create the circles
  28392. for ( i = 0; i <= circles; i ++ ) {
  28393. color = ( i & 1 ) ? color1 : color2;
  28394. r = radius - ( radius / circles * i );
  28395. for ( j = 0; j < divisions; j ++ ) {
  28396. // first vertex
  28397. v = ( j / divisions ) * ( Math.PI * 2 );
  28398. x = Math.sin( v ) * r;
  28399. z = Math.cos( v ) * r;
  28400. vertices.push( x, 0, z );
  28401. colors.push( color.r, color.g, color.b );
  28402. // second vertex
  28403. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  28404. x = Math.sin( v ) * r;
  28405. z = Math.cos( v ) * r;
  28406. vertices.push( x, 0, z );
  28407. colors.push( color.r, color.g, color.b );
  28408. }
  28409. }
  28410. var geometry = new BufferGeometry();
  28411. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28412. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28413. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  28414. LineSegments.call( this, geometry, material );
  28415. }
  28416. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  28417. PolarGridHelper.prototype.constructor = PolarGridHelper;
  28418. /**
  28419. * @author Mugen87 / http://github.com/Mugen87
  28420. */
  28421. function PositionalAudioHelper( audio, range, divisionsInnerAngle, divisionsOuterAngle ) {
  28422. this.audio = audio;
  28423. this.range = range || 1;
  28424. this.divisionsInnerAngle = divisionsInnerAngle || 16;
  28425. this.divisionsOuterAngle = divisionsOuterAngle || 2;
  28426. var geometry = new BufferGeometry();
  28427. var divisions = this.divisionsInnerAngle + this.divisionsOuterAngle * 2;
  28428. var positions = new Float32Array( ( divisions * 3 + 3 ) * 3 );
  28429. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  28430. var materialInnerAngle = new LineBasicMaterial( { color: 0x00ff00 } );
  28431. var materialOuterAngle = new LineBasicMaterial( { color: 0xffff00 } );
  28432. Line.call( this, geometry, [ materialOuterAngle, materialInnerAngle ] );
  28433. this.update();
  28434. }
  28435. PositionalAudioHelper.prototype = Object.create( Line.prototype );
  28436. PositionalAudioHelper.prototype.constructor = PositionalAudioHelper;
  28437. PositionalAudioHelper.prototype.update = function () {
  28438. var audio = this.audio;
  28439. var range = this.range;
  28440. var divisionsInnerAngle = this.divisionsInnerAngle;
  28441. var divisionsOuterAngle = this.divisionsOuterAngle;
  28442. var coneInnerAngle = _Math.degToRad( audio.panner.coneInnerAngle );
  28443. var coneOuterAngle = _Math.degToRad( audio.panner.coneOuterAngle );
  28444. var halfConeInnerAngle = coneInnerAngle / 2;
  28445. var halfConeOuterAngle = coneOuterAngle / 2;
  28446. var start = 0;
  28447. var count = 0;
  28448. var i, stride;
  28449. var geometry = this.geometry;
  28450. var positionAttribute = geometry.attributes.position;
  28451. geometry.clearGroups();
  28452. //
  28453. function generateSegment( from, to, divisions, materialIndex ) {
  28454. var step = ( to - from ) / divisions;
  28455. positionAttribute.setXYZ( start, 0, 0, 0 );
  28456. count ++;
  28457. for ( i = from; i < to; i += step ) {
  28458. stride = start + count;
  28459. positionAttribute.setXYZ( stride, Math.sin( i ) * range, 0, Math.cos( i ) * range );
  28460. positionAttribute.setXYZ( stride + 1, Math.sin( Math.min( i + step, to ) ) * range, 0, Math.cos( Math.min( i + step, to ) ) * range );
  28461. positionAttribute.setXYZ( stride + 2, 0, 0, 0 );
  28462. count += 3;
  28463. }
  28464. geometry.addGroup( start, count, materialIndex );
  28465. start += count;
  28466. count = 0;
  28467. }
  28468. //
  28469. generateSegment( - halfConeOuterAngle, - halfConeInnerAngle, divisionsOuterAngle, 0 );
  28470. generateSegment( - halfConeInnerAngle, halfConeInnerAngle, divisionsInnerAngle, 1 );
  28471. generateSegment( halfConeInnerAngle, halfConeOuterAngle, divisionsOuterAngle, 0 );
  28472. //
  28473. positionAttribute.needsUpdate = true;
  28474. if ( coneInnerAngle === coneOuterAngle ) this.material[ 0 ].visible = false;
  28475. };
  28476. PositionalAudioHelper.prototype.dispose = function () {
  28477. this.geometry.dispose();
  28478. this.material[ 0 ].dispose();
  28479. this.material[ 1 ].dispose();
  28480. };
  28481. /**
  28482. * @author mrdoob / http://mrdoob.com/
  28483. * @author WestLangley / http://github.com/WestLangley
  28484. */
  28485. function FaceNormalsHelper( object, size, hex, linewidth ) {
  28486. // FaceNormalsHelper only supports THREE.Geometry
  28487. this.object = object;
  28488. this.size = ( size !== undefined ) ? size : 1;
  28489. var color = ( hex !== undefined ) ? hex : 0xffff00;
  28490. var width = ( linewidth !== undefined ) ? linewidth : 1;
  28491. //
  28492. var nNormals = 0;
  28493. var objGeometry = this.object.geometry;
  28494. if ( objGeometry && objGeometry.isGeometry ) {
  28495. nNormals = objGeometry.faces.length;
  28496. } else {
  28497. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  28498. }
  28499. //
  28500. var geometry = new BufferGeometry();
  28501. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  28502. geometry.addAttribute( 'position', positions );
  28503. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  28504. //
  28505. this.matrixAutoUpdate = false;
  28506. this.update();
  28507. }
  28508. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  28509. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  28510. FaceNormalsHelper.prototype.update = ( function () {
  28511. var v1 = new Vector3();
  28512. var v2 = new Vector3();
  28513. var normalMatrix = new Matrix3();
  28514. return function update() {
  28515. this.object.updateMatrixWorld( true );
  28516. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  28517. var matrixWorld = this.object.matrixWorld;
  28518. var position = this.geometry.attributes.position;
  28519. //
  28520. var objGeometry = this.object.geometry;
  28521. var vertices = objGeometry.vertices;
  28522. var faces = objGeometry.faces;
  28523. var idx = 0;
  28524. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  28525. var face = faces[ i ];
  28526. var normal = face.normal;
  28527. v1.copy( vertices[ face.a ] )
  28528. .add( vertices[ face.b ] )
  28529. .add( vertices[ face.c ] )
  28530. .divideScalar( 3 )
  28531. .applyMatrix4( matrixWorld );
  28532. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  28533. position.setXYZ( idx, v1.x, v1.y, v1.z );
  28534. idx = idx + 1;
  28535. position.setXYZ( idx, v2.x, v2.y, v2.z );
  28536. idx = idx + 1;
  28537. }
  28538. position.needsUpdate = true;
  28539. };
  28540. }() );
  28541. /**
  28542. * @author alteredq / http://alteredqualia.com/
  28543. * @author mrdoob / http://mrdoob.com/
  28544. * @author WestLangley / http://github.com/WestLangley
  28545. */
  28546. function DirectionalLightHelper( light, size, color ) {
  28547. Object3D.call( this );
  28548. this.light = light;
  28549. this.light.updateMatrixWorld();
  28550. this.matrix = light.matrixWorld;
  28551. this.matrixAutoUpdate = false;
  28552. this.color = color;
  28553. if ( size === undefined ) size = 1;
  28554. var geometry = new BufferGeometry();
  28555. geometry.addAttribute( 'position', new Float32BufferAttribute( [
  28556. - size, size, 0,
  28557. size, size, 0,
  28558. size, - size, 0,
  28559. - size, - size, 0,
  28560. - size, size, 0
  28561. ], 3 ) );
  28562. var material = new LineBasicMaterial( { fog: false } );
  28563. this.lightPlane = new Line( geometry, material );
  28564. this.add( this.lightPlane );
  28565. geometry = new BufferGeometry();
  28566. geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  28567. this.targetLine = new Line( geometry, material );
  28568. this.add( this.targetLine );
  28569. this.update();
  28570. }
  28571. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  28572. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  28573. DirectionalLightHelper.prototype.dispose = function () {
  28574. this.lightPlane.geometry.dispose();
  28575. this.lightPlane.material.dispose();
  28576. this.targetLine.geometry.dispose();
  28577. this.targetLine.material.dispose();
  28578. };
  28579. DirectionalLightHelper.prototype.update = function () {
  28580. var v1 = new Vector3();
  28581. var v2 = new Vector3();
  28582. var v3 = new Vector3();
  28583. return function update() {
  28584. v1.setFromMatrixPosition( this.light.matrixWorld );
  28585. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  28586. v3.subVectors( v2, v1 );
  28587. this.lightPlane.lookAt( v2 );
  28588. if ( this.color !== undefined ) {
  28589. this.lightPlane.material.color.set( this.color );
  28590. this.targetLine.material.color.set( this.color );
  28591. } else {
  28592. this.lightPlane.material.color.copy( this.light.color );
  28593. this.targetLine.material.color.copy( this.light.color );
  28594. }
  28595. this.targetLine.lookAt( v2 );
  28596. this.targetLine.scale.z = v3.length();
  28597. };
  28598. }();
  28599. /**
  28600. * @author alteredq / http://alteredqualia.com/
  28601. * @author Mugen87 / https://github.com/Mugen87
  28602. *
  28603. * - shows frustum, line of sight and up of the camera
  28604. * - suitable for fast updates
  28605. * - based on frustum visualization in lightgl.js shadowmap example
  28606. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28607. */
  28608. function CameraHelper( camera ) {
  28609. var geometry = new BufferGeometry();
  28610. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  28611. var vertices = [];
  28612. var colors = [];
  28613. var pointMap = {};
  28614. // colors
  28615. var colorFrustum = new Color( 0xffaa00 );
  28616. var colorCone = new Color( 0xff0000 );
  28617. var colorUp = new Color( 0x00aaff );
  28618. var colorTarget = new Color( 0xffffff );
  28619. var colorCross = new Color( 0x333333 );
  28620. // near
  28621. addLine( 'n1', 'n2', colorFrustum );
  28622. addLine( 'n2', 'n4', colorFrustum );
  28623. addLine( 'n4', 'n3', colorFrustum );
  28624. addLine( 'n3', 'n1', colorFrustum );
  28625. // far
  28626. addLine( 'f1', 'f2', colorFrustum );
  28627. addLine( 'f2', 'f4', colorFrustum );
  28628. addLine( 'f4', 'f3', colorFrustum );
  28629. addLine( 'f3', 'f1', colorFrustum );
  28630. // sides
  28631. addLine( 'n1', 'f1', colorFrustum );
  28632. addLine( 'n2', 'f2', colorFrustum );
  28633. addLine( 'n3', 'f3', colorFrustum );
  28634. addLine( 'n4', 'f4', colorFrustum );
  28635. // cone
  28636. addLine( 'p', 'n1', colorCone );
  28637. addLine( 'p', 'n2', colorCone );
  28638. addLine( 'p', 'n3', colorCone );
  28639. addLine( 'p', 'n4', colorCone );
  28640. // up
  28641. addLine( 'u1', 'u2', colorUp );
  28642. addLine( 'u2', 'u3', colorUp );
  28643. addLine( 'u3', 'u1', colorUp );
  28644. // target
  28645. addLine( 'c', 't', colorTarget );
  28646. addLine( 'p', 'c', colorCross );
  28647. // cross
  28648. addLine( 'cn1', 'cn2', colorCross );
  28649. addLine( 'cn3', 'cn4', colorCross );
  28650. addLine( 'cf1', 'cf2', colorCross );
  28651. addLine( 'cf3', 'cf4', colorCross );
  28652. function addLine( a, b, color ) {
  28653. addPoint( a, color );
  28654. addPoint( b, color );
  28655. }
  28656. function addPoint( id, color ) {
  28657. vertices.push( 0, 0, 0 );
  28658. colors.push( color.r, color.g, color.b );
  28659. if ( pointMap[ id ] === undefined ) {
  28660. pointMap[ id ] = [];
  28661. }
  28662. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  28663. }
  28664. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28665. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28666. LineSegments.call( this, geometry, material );
  28667. this.camera = camera;
  28668. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  28669. this.matrix = camera.matrixWorld;
  28670. this.matrixAutoUpdate = false;
  28671. this.pointMap = pointMap;
  28672. this.update();
  28673. }
  28674. CameraHelper.prototype = Object.create( LineSegments.prototype );
  28675. CameraHelper.prototype.constructor = CameraHelper;
  28676. CameraHelper.prototype.update = function () {
  28677. var geometry, pointMap;
  28678. var vector = new Vector3();
  28679. var camera = new Camera();
  28680. function setPoint( point, x, y, z ) {
  28681. vector.set( x, y, z ).unproject( camera );
  28682. var points = pointMap[ point ];
  28683. if ( points !== undefined ) {
  28684. var position = geometry.getAttribute( 'position' );
  28685. for ( var i = 0, l = points.length; i < l; i ++ ) {
  28686. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  28687. }
  28688. }
  28689. }
  28690. return function update() {
  28691. geometry = this.geometry;
  28692. pointMap = this.pointMap;
  28693. var w = 1, h = 1;
  28694. // we need just camera projection matrix inverse
  28695. // world matrix must be identity
  28696. camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  28697. // center / target
  28698. setPoint( 'c', 0, 0, - 1 );
  28699. setPoint( 't', 0, 0, 1 );
  28700. // near
  28701. setPoint( 'n1', - w, - h, - 1 );
  28702. setPoint( 'n2', w, - h, - 1 );
  28703. setPoint( 'n3', - w, h, - 1 );
  28704. setPoint( 'n4', w, h, - 1 );
  28705. // far
  28706. setPoint( 'f1', - w, - h, 1 );
  28707. setPoint( 'f2', w, - h, 1 );
  28708. setPoint( 'f3', - w, h, 1 );
  28709. setPoint( 'f4', w, h, 1 );
  28710. // up
  28711. setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
  28712. setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
  28713. setPoint( 'u3', 0, h * 2, - 1 );
  28714. // cross
  28715. setPoint( 'cf1', - w, 0, 1 );
  28716. setPoint( 'cf2', w, 0, 1 );
  28717. setPoint( 'cf3', 0, - h, 1 );
  28718. setPoint( 'cf4', 0, h, 1 );
  28719. setPoint( 'cn1', - w, 0, - 1 );
  28720. setPoint( 'cn2', w, 0, - 1 );
  28721. setPoint( 'cn3', 0, - h, - 1 );
  28722. setPoint( 'cn4', 0, h, - 1 );
  28723. geometry.getAttribute( 'position' ).needsUpdate = true;
  28724. };
  28725. }();
  28726. /**
  28727. * @author mrdoob / http://mrdoob.com/
  28728. * @author Mugen87 / http://github.com/Mugen87
  28729. */
  28730. function BoxHelper( object, color ) {
  28731. this.object = object;
  28732. if ( color === undefined ) color = 0xffff00;
  28733. 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 ] );
  28734. var positions = new Float32Array( 8 * 3 );
  28735. var geometry = new BufferGeometry();
  28736. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  28737. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  28738. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  28739. this.matrixAutoUpdate = false;
  28740. this.update();
  28741. }
  28742. BoxHelper.prototype = Object.create( LineSegments.prototype );
  28743. BoxHelper.prototype.constructor = BoxHelper;
  28744. BoxHelper.prototype.update = ( function () {
  28745. var box = new Box3();
  28746. return function update( object ) {
  28747. if ( object !== undefined ) {
  28748. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  28749. }
  28750. if ( this.object !== undefined ) {
  28751. box.setFromObject( this.object );
  28752. }
  28753. if ( box.isEmpty() ) return;
  28754. var min = box.min;
  28755. var max = box.max;
  28756. /*
  28757. 5____4
  28758. 1/___0/|
  28759. | 6__|_7
  28760. 2/___3/
  28761. 0: max.x, max.y, max.z
  28762. 1: min.x, max.y, max.z
  28763. 2: min.x, min.y, max.z
  28764. 3: max.x, min.y, max.z
  28765. 4: max.x, max.y, min.z
  28766. 5: min.x, max.y, min.z
  28767. 6: min.x, min.y, min.z
  28768. 7: max.x, min.y, min.z
  28769. */
  28770. var position = this.geometry.attributes.position;
  28771. var array = position.array;
  28772. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  28773. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  28774. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  28775. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  28776. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  28777. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  28778. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  28779. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  28780. position.needsUpdate = true;
  28781. this.geometry.computeBoundingSphere();
  28782. };
  28783. } )();
  28784. BoxHelper.prototype.setFromObject = function ( object ) {
  28785. this.object = object;
  28786. this.update();
  28787. return this;
  28788. };
  28789. BoxHelper.prototype.copy = function ( source ) {
  28790. LineSegments.prototype.copy.call( this, source );
  28791. this.object = source.object;
  28792. return this;
  28793. };
  28794. BoxHelper.prototype.clone = function () {
  28795. return new this.constructor().copy( this );
  28796. };
  28797. /**
  28798. * @author WestLangley / http://github.com/WestLangley
  28799. */
  28800. function Box3Helper( box, color ) {
  28801. this.type = 'Box3Helper';
  28802. this.box = box;
  28803. color = color || 0xffff00;
  28804. 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 ] );
  28805. 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 ];
  28806. var geometry = new BufferGeometry();
  28807. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  28808. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28809. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  28810. this.geometry.computeBoundingSphere();
  28811. }
  28812. Box3Helper.prototype = Object.create( LineSegments.prototype );
  28813. Box3Helper.prototype.constructor = Box3Helper;
  28814. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  28815. var box = this.box;
  28816. if ( box.isEmpty() ) return;
  28817. box.getCenter( this.position );
  28818. box.getSize( this.scale );
  28819. this.scale.multiplyScalar( 0.5 );
  28820. Object3D.prototype.updateMatrixWorld.call( this, force );
  28821. };
  28822. /**
  28823. * @author WestLangley / http://github.com/WestLangley
  28824. */
  28825. function PlaneHelper( plane, size, hex ) {
  28826. this.type = 'PlaneHelper';
  28827. this.plane = plane;
  28828. this.size = ( size === undefined ) ? 1 : size;
  28829. var color = ( hex !== undefined ) ? hex : 0xffff00;
  28830. 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 ];
  28831. var geometry = new BufferGeometry();
  28832. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28833. geometry.computeBoundingSphere();
  28834. Line.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  28835. //
  28836. var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  28837. var geometry2 = new BufferGeometry();
  28838. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  28839. geometry2.computeBoundingSphere();
  28840. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) ) );
  28841. }
  28842. PlaneHelper.prototype = Object.create( Line.prototype );
  28843. PlaneHelper.prototype.constructor = PlaneHelper;
  28844. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  28845. var scale = - this.plane.constant;
  28846. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  28847. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  28848. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28849. this.lookAt( this.plane.normal );
  28850. Object3D.prototype.updateMatrixWorld.call( this, force );
  28851. };
  28852. /**
  28853. * @author WestLangley / http://github.com/WestLangley
  28854. * @author zz85 / http://github.com/zz85
  28855. * @author bhouston / http://clara.io
  28856. *
  28857. * Creates an arrow for visualizing directions
  28858. *
  28859. * Parameters:
  28860. * dir - Vector3
  28861. * origin - Vector3
  28862. * length - Number
  28863. * color - color in hex value
  28864. * headLength - Number
  28865. * headWidth - Number
  28866. */
  28867. var lineGeometry, coneGeometry;
  28868. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  28869. // dir is assumed to be normalized
  28870. Object3D.call( this );
  28871. if ( dir === undefined ) dir = new Vector3( 0, 0, 1 );
  28872. if ( origin === undefined ) origin = new Vector3( 0, 0, 0 );
  28873. if ( length === undefined ) length = 1;
  28874. if ( color === undefined ) color = 0xffff00;
  28875. if ( headLength === undefined ) headLength = 0.2 * length;
  28876. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28877. if ( lineGeometry === undefined ) {
  28878. lineGeometry = new BufferGeometry();
  28879. lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  28880. coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  28881. coneGeometry.translate( 0, - 0.5, 0 );
  28882. }
  28883. this.position.copy( origin );
  28884. this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );
  28885. this.line.matrixAutoUpdate = false;
  28886. this.add( this.line );
  28887. this.cone = new Mesh( coneGeometry, new MeshBasicMaterial( { color: color } ) );
  28888. this.cone.matrixAutoUpdate = false;
  28889. this.add( this.cone );
  28890. this.setDirection( dir );
  28891. this.setLength( length, headLength, headWidth );
  28892. }
  28893. ArrowHelper.prototype = Object.create( Object3D.prototype );
  28894. ArrowHelper.prototype.constructor = ArrowHelper;
  28895. ArrowHelper.prototype.setDirection = ( function () {
  28896. var axis = new Vector3();
  28897. var radians;
  28898. return function setDirection( dir ) {
  28899. // dir is assumed to be normalized
  28900. if ( dir.y > 0.99999 ) {
  28901. this.quaternion.set( 0, 0, 0, 1 );
  28902. } else if ( dir.y < - 0.99999 ) {
  28903. this.quaternion.set( 1, 0, 0, 0 );
  28904. } else {
  28905. axis.set( dir.z, 0, - dir.x ).normalize();
  28906. radians = Math.acos( dir.y );
  28907. this.quaternion.setFromAxisAngle( axis, radians );
  28908. }
  28909. };
  28910. }() );
  28911. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  28912. if ( headLength === undefined ) headLength = 0.2 * length;
  28913. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28914. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  28915. this.line.updateMatrix();
  28916. this.cone.scale.set( headWidth, headLength, headWidth );
  28917. this.cone.position.y = length;
  28918. this.cone.updateMatrix();
  28919. };
  28920. ArrowHelper.prototype.setColor = function ( color ) {
  28921. this.line.material.color.set( color );
  28922. this.cone.material.color.set( color );
  28923. };
  28924. ArrowHelper.prototype.copy = function ( source ) {
  28925. Object3D.prototype.copy.call( this, source, false );
  28926. this.line.copy( source.line );
  28927. this.cone.copy( source.cone );
  28928. return this;
  28929. };
  28930. ArrowHelper.prototype.clone = function () {
  28931. return new this.constructor().copy( this );
  28932. };
  28933. /**
  28934. * @author sroucheray / http://sroucheray.org/
  28935. * @author mrdoob / http://mrdoob.com/
  28936. */
  28937. function AxesHelper( size ) {
  28938. size = size || 1;
  28939. var vertices = [
  28940. 0, 0, 0, size, 0, 0,
  28941. 0, 0, 0, 0, size, 0,
  28942. 0, 0, 0, 0, 0, size
  28943. ];
  28944. var colors = [
  28945. 1, 0, 0, 1, 0.6, 0,
  28946. 0, 1, 0, 0.6, 1, 0,
  28947. 0, 0, 1, 0, 0.6, 1
  28948. ];
  28949. var geometry = new BufferGeometry();
  28950. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28951. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28952. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  28953. LineSegments.call( this, geometry, material );
  28954. }
  28955. AxesHelper.prototype = Object.create( LineSegments.prototype );
  28956. AxesHelper.prototype.constructor = AxesHelper;
  28957. /**
  28958. * @author mrdoob / http://mrdoob.com/
  28959. */
  28960. function Face4( a, b, c, d, normal, color, materialIndex ) {
  28961. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  28962. return new Face3( a, b, c, normal, color, materialIndex );
  28963. }
  28964. var LineStrip = 0;
  28965. var LinePieces = 1;
  28966. function MeshFaceMaterial( materials ) {
  28967. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  28968. return materials;
  28969. }
  28970. function MultiMaterial( materials ) {
  28971. if ( materials === undefined ) materials = [];
  28972. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  28973. materials.isMultiMaterial = true;
  28974. materials.materials = materials;
  28975. materials.clone = function () {
  28976. return materials.slice();
  28977. };
  28978. return materials;
  28979. }
  28980. function PointCloud( geometry, material ) {
  28981. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  28982. return new Points( geometry, material );
  28983. }
  28984. function Particle( material ) {
  28985. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  28986. return new Sprite( material );
  28987. }
  28988. function ParticleSystem( geometry, material ) {
  28989. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  28990. return new Points( geometry, material );
  28991. }
  28992. function PointCloudMaterial( parameters ) {
  28993. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  28994. return new PointsMaterial( parameters );
  28995. }
  28996. function ParticleBasicMaterial( parameters ) {
  28997. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  28998. return new PointsMaterial( parameters );
  28999. }
  29000. function ParticleSystemMaterial( parameters ) {
  29001. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  29002. return new PointsMaterial( parameters );
  29003. }
  29004. function Vertex( x, y, z ) {
  29005. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  29006. return new Vector3( x, y, z );
  29007. }
  29008. //
  29009. function DynamicBufferAttribute( array, itemSize ) {
  29010. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  29011. return new BufferAttribute( array, itemSize ).setDynamic( true );
  29012. }
  29013. function Int8Attribute( array, itemSize ) {
  29014. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  29015. return new Int8BufferAttribute( array, itemSize );
  29016. }
  29017. function Uint8Attribute( array, itemSize ) {
  29018. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  29019. return new Uint8BufferAttribute( array, itemSize );
  29020. }
  29021. function Uint8ClampedAttribute( array, itemSize ) {
  29022. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  29023. return new Uint8ClampedBufferAttribute( array, itemSize );
  29024. }
  29025. function Int16Attribute( array, itemSize ) {
  29026. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  29027. return new Int16BufferAttribute( array, itemSize );
  29028. }
  29029. function Uint16Attribute( array, itemSize ) {
  29030. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  29031. return new Uint16BufferAttribute( array, itemSize );
  29032. }
  29033. function Int32Attribute( array, itemSize ) {
  29034. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  29035. return new Int32BufferAttribute( array, itemSize );
  29036. }
  29037. function Uint32Attribute( array, itemSize ) {
  29038. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  29039. return new Uint32BufferAttribute( array, itemSize );
  29040. }
  29041. function Float32Attribute( array, itemSize ) {
  29042. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  29043. return new Float32BufferAttribute( array, itemSize );
  29044. }
  29045. function Float64Attribute( array, itemSize ) {
  29046. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  29047. return new Float64BufferAttribute( array, itemSize );
  29048. }
  29049. //
  29050. Curve.create = function ( construct, getPoint ) {
  29051. console.log( 'THREE.Curve.create() has been deprecated' );
  29052. construct.prototype = Object.create( Curve.prototype );
  29053. construct.prototype.constructor = construct;
  29054. construct.prototype.getPoint = getPoint;
  29055. return construct;
  29056. };
  29057. //
  29058. Object.assign( CurvePath.prototype, {
  29059. createPointsGeometry: function ( divisions ) {
  29060. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  29061. // generate geometry from path points (for Line or Points objects)
  29062. var pts = this.getPoints( divisions );
  29063. return this.createGeometry( pts );
  29064. },
  29065. createSpacedPointsGeometry: function ( divisions ) {
  29066. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  29067. // generate geometry from equidistant sampling along the path
  29068. var pts = this.getSpacedPoints( divisions );
  29069. return this.createGeometry( pts );
  29070. },
  29071. createGeometry: function ( points ) {
  29072. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  29073. var geometry = new Geometry();
  29074. for ( var i = 0, l = points.length; i < l; i ++ ) {
  29075. var point = points[ i ];
  29076. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  29077. }
  29078. return geometry;
  29079. }
  29080. } );
  29081. //
  29082. Object.assign( Path.prototype, {
  29083. fromPoints: function ( points ) {
  29084. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  29085. this.setFromPoints( points );
  29086. }
  29087. } );
  29088. //
  29089. function ClosedSplineCurve3( points ) {
  29090. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  29091. CatmullRomCurve3.call( this, points );
  29092. this.type = 'catmullrom';
  29093. this.closed = true;
  29094. }
  29095. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  29096. //
  29097. function SplineCurve3( points ) {
  29098. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  29099. CatmullRomCurve3.call( this, points );
  29100. this.type = 'catmullrom';
  29101. }
  29102. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  29103. //
  29104. function Spline( points ) {
  29105. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  29106. CatmullRomCurve3.call( this, points );
  29107. this.type = 'catmullrom';
  29108. }
  29109. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  29110. Object.assign( Spline.prototype, {
  29111. initFromArray: function ( /* a */ ) {
  29112. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  29113. },
  29114. getControlPointsArray: function ( /* optionalTarget */ ) {
  29115. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  29116. },
  29117. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  29118. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  29119. }
  29120. } );
  29121. //
  29122. function AxisHelper( size ) {
  29123. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  29124. return new AxesHelper( size );
  29125. }
  29126. function BoundingBoxHelper( object, color ) {
  29127. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  29128. return new BoxHelper( object, color );
  29129. }
  29130. function EdgesHelper( object, hex ) {
  29131. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  29132. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  29133. }
  29134. GridHelper.prototype.setColors = function () {
  29135. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  29136. };
  29137. SkeletonHelper.prototype.update = function () {
  29138. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  29139. };
  29140. function WireframeHelper( object, hex ) {
  29141. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  29142. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  29143. }
  29144. //
  29145. Object.assign( Loader.prototype, {
  29146. extractUrlBase: function ( url ) {
  29147. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  29148. return LoaderUtils.extractUrlBase( url );
  29149. }
  29150. } );
  29151. function XHRLoader( manager ) {
  29152. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  29153. return new FileLoader( manager );
  29154. }
  29155. function BinaryTextureLoader( manager ) {
  29156. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  29157. return new DataTextureLoader( manager );
  29158. }
  29159. Object.assign( ObjectLoader.prototype, {
  29160. setTexturePath: function ( value ) {
  29161. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  29162. return this.setResourcePath( value );
  29163. }
  29164. } );
  29165. //
  29166. Object.assign( Box2.prototype, {
  29167. center: function ( optionalTarget ) {
  29168. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  29169. return this.getCenter( optionalTarget );
  29170. },
  29171. empty: function () {
  29172. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  29173. return this.isEmpty();
  29174. },
  29175. isIntersectionBox: function ( box ) {
  29176. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  29177. return this.intersectsBox( box );
  29178. },
  29179. size: function ( optionalTarget ) {
  29180. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  29181. return this.getSize( optionalTarget );
  29182. }
  29183. } );
  29184. Object.assign( Box3.prototype, {
  29185. center: function ( optionalTarget ) {
  29186. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  29187. return this.getCenter( optionalTarget );
  29188. },
  29189. empty: function () {
  29190. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  29191. return this.isEmpty();
  29192. },
  29193. isIntersectionBox: function ( box ) {
  29194. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  29195. return this.intersectsBox( box );
  29196. },
  29197. isIntersectionSphere: function ( sphere ) {
  29198. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  29199. return this.intersectsSphere( sphere );
  29200. },
  29201. size: function ( optionalTarget ) {
  29202. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  29203. return this.getSize( optionalTarget );
  29204. }
  29205. } );
  29206. Line3.prototype.center = function ( optionalTarget ) {
  29207. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  29208. return this.getCenter( optionalTarget );
  29209. };
  29210. Object.assign( _Math, {
  29211. random16: function () {
  29212. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  29213. return Math.random();
  29214. },
  29215. nearestPowerOfTwo: function ( value ) {
  29216. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  29217. return _Math.floorPowerOfTwo( value );
  29218. },
  29219. nextPowerOfTwo: function ( value ) {
  29220. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  29221. return _Math.ceilPowerOfTwo( value );
  29222. }
  29223. } );
  29224. Object.assign( Matrix3.prototype, {
  29225. flattenToArrayOffset: function ( array, offset ) {
  29226. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  29227. return this.toArray( array, offset );
  29228. },
  29229. multiplyVector3: function ( vector ) {
  29230. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  29231. return vector.applyMatrix3( this );
  29232. },
  29233. multiplyVector3Array: function ( /* a */ ) {
  29234. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  29235. },
  29236. applyToBuffer: function ( buffer /*, offset, length */ ) {
  29237. console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  29238. return this.applyToBufferAttribute( buffer );
  29239. },
  29240. applyToVector3Array: function ( /* array, offset, length */ ) {
  29241. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  29242. }
  29243. } );
  29244. Object.assign( Matrix4.prototype, {
  29245. extractPosition: function ( m ) {
  29246. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  29247. return this.copyPosition( m );
  29248. },
  29249. flattenToArrayOffset: function ( array, offset ) {
  29250. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  29251. return this.toArray( array, offset );
  29252. },
  29253. getPosition: function () {
  29254. var v1;
  29255. return function getPosition() {
  29256. if ( v1 === undefined ) v1 = new Vector3();
  29257. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  29258. return v1.setFromMatrixColumn( this, 3 );
  29259. };
  29260. }(),
  29261. setRotationFromQuaternion: function ( q ) {
  29262. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  29263. return this.makeRotationFromQuaternion( q );
  29264. },
  29265. multiplyToArray: function () {
  29266. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  29267. },
  29268. multiplyVector3: function ( vector ) {
  29269. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  29270. return vector.applyMatrix4( this );
  29271. },
  29272. multiplyVector4: function ( vector ) {
  29273. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  29274. return vector.applyMatrix4( this );
  29275. },
  29276. multiplyVector3Array: function ( /* a */ ) {
  29277. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  29278. },
  29279. rotateAxis: function ( v ) {
  29280. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  29281. v.transformDirection( this );
  29282. },
  29283. crossVector: function ( vector ) {
  29284. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  29285. return vector.applyMatrix4( this );
  29286. },
  29287. translate: function () {
  29288. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  29289. },
  29290. rotateX: function () {
  29291. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  29292. },
  29293. rotateY: function () {
  29294. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  29295. },
  29296. rotateZ: function () {
  29297. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  29298. },
  29299. rotateByAxis: function () {
  29300. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  29301. },
  29302. applyToBuffer: function ( buffer /*, offset, length */ ) {
  29303. console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  29304. return this.applyToBufferAttribute( buffer );
  29305. },
  29306. applyToVector3Array: function ( /* array, offset, length */ ) {
  29307. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  29308. },
  29309. makeFrustum: function ( left, right, bottom, top, near, far ) {
  29310. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  29311. return this.makePerspective( left, right, top, bottom, near, far );
  29312. }
  29313. } );
  29314. Plane.prototype.isIntersectionLine = function ( line ) {
  29315. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  29316. return this.intersectsLine( line );
  29317. };
  29318. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  29319. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  29320. return vector.applyQuaternion( this );
  29321. };
  29322. Object.assign( Ray.prototype, {
  29323. isIntersectionBox: function ( box ) {
  29324. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  29325. return this.intersectsBox( box );
  29326. },
  29327. isIntersectionPlane: function ( plane ) {
  29328. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  29329. return this.intersectsPlane( plane );
  29330. },
  29331. isIntersectionSphere: function ( sphere ) {
  29332. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  29333. return this.intersectsSphere( sphere );
  29334. }
  29335. } );
  29336. Object.assign( Triangle.prototype, {
  29337. area: function () {
  29338. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  29339. return this.getArea();
  29340. },
  29341. barycoordFromPoint: function ( point, target ) {
  29342. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  29343. return this.getBarycoord( point, target );
  29344. },
  29345. midpoint: function ( target ) {
  29346. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  29347. return this.getMidpoint( target );
  29348. },
  29349. normal: function ( target ) {
  29350. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  29351. return this.getNormal( target );
  29352. },
  29353. plane: function ( target ) {
  29354. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  29355. return this.getPlane( target );
  29356. }
  29357. } );
  29358. Object.assign( Triangle, {
  29359. barycoordFromPoint: function ( point, a, b, c, target ) {
  29360. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  29361. return Triangle.getBarycoord( point, a, b, c, target );
  29362. },
  29363. normal: function ( a, b, c, target ) {
  29364. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  29365. return Triangle.getNormal( a, b, c, target );
  29366. }
  29367. } );
  29368. Object.assign( Shape.prototype, {
  29369. extractAllPoints: function ( divisions ) {
  29370. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  29371. return this.extractPoints( divisions );
  29372. },
  29373. extrude: function ( options ) {
  29374. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  29375. return new ExtrudeGeometry( this, options );
  29376. },
  29377. makeGeometry: function ( options ) {
  29378. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  29379. return new ShapeGeometry( this, options );
  29380. }
  29381. } );
  29382. Object.assign( Vector2.prototype, {
  29383. fromAttribute: function ( attribute, index, offset ) {
  29384. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  29385. return this.fromBufferAttribute( attribute, index, offset );
  29386. },
  29387. distanceToManhattan: function ( v ) {
  29388. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  29389. return this.manhattanDistanceTo( v );
  29390. },
  29391. lengthManhattan: function () {
  29392. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  29393. return this.manhattanLength();
  29394. }
  29395. } );
  29396. Object.assign( Vector3.prototype, {
  29397. setEulerFromRotationMatrix: function () {
  29398. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  29399. },
  29400. setEulerFromQuaternion: function () {
  29401. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  29402. },
  29403. getPositionFromMatrix: function ( m ) {
  29404. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  29405. return this.setFromMatrixPosition( m );
  29406. },
  29407. getScaleFromMatrix: function ( m ) {
  29408. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  29409. return this.setFromMatrixScale( m );
  29410. },
  29411. getColumnFromMatrix: function ( index, matrix ) {
  29412. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  29413. return this.setFromMatrixColumn( matrix, index );
  29414. },
  29415. applyProjection: function ( m ) {
  29416. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  29417. return this.applyMatrix4( m );
  29418. },
  29419. fromAttribute: function ( attribute, index, offset ) {
  29420. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  29421. return this.fromBufferAttribute( attribute, index, offset );
  29422. },
  29423. distanceToManhattan: function ( v ) {
  29424. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  29425. return this.manhattanDistanceTo( v );
  29426. },
  29427. lengthManhattan: function () {
  29428. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  29429. return this.manhattanLength();
  29430. }
  29431. } );
  29432. Object.assign( Vector4.prototype, {
  29433. fromAttribute: function ( attribute, index, offset ) {
  29434. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  29435. return this.fromBufferAttribute( attribute, index, offset );
  29436. },
  29437. lengthManhattan: function () {
  29438. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  29439. return this.manhattanLength();
  29440. }
  29441. } );
  29442. //
  29443. Object.assign( Geometry.prototype, {
  29444. computeTangents: function () {
  29445. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  29446. },
  29447. computeLineDistances: function () {
  29448. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  29449. }
  29450. } );
  29451. Object.assign( Object3D.prototype, {
  29452. getChildByName: function ( name ) {
  29453. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  29454. return this.getObjectByName( name );
  29455. },
  29456. renderDepth: function () {
  29457. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  29458. },
  29459. translate: function ( distance, axis ) {
  29460. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  29461. return this.translateOnAxis( axis, distance );
  29462. },
  29463. getWorldRotation: function () {
  29464. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  29465. }
  29466. } );
  29467. Object.defineProperties( Object3D.prototype, {
  29468. eulerOrder: {
  29469. get: function () {
  29470. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  29471. return this.rotation.order;
  29472. },
  29473. set: function ( value ) {
  29474. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  29475. this.rotation.order = value;
  29476. }
  29477. },
  29478. useQuaternion: {
  29479. get: function () {
  29480. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  29481. },
  29482. set: function () {
  29483. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  29484. }
  29485. }
  29486. } );
  29487. Object.defineProperties( LOD.prototype, {
  29488. objects: {
  29489. get: function () {
  29490. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  29491. return this.levels;
  29492. }
  29493. }
  29494. } );
  29495. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  29496. get: function () {
  29497. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  29498. },
  29499. set: function () {
  29500. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  29501. }
  29502. } );
  29503. SkinnedMesh.prototype.initBones = function () {
  29504. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  29505. };
  29506. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  29507. get: function () {
  29508. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  29509. return this.arcLengthDivisions;
  29510. },
  29511. set: function ( value ) {
  29512. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  29513. this.arcLengthDivisions = value;
  29514. }
  29515. } );
  29516. //
  29517. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  29518. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  29519. "Use .setFocalLength and .filmGauge for a photographic setup." );
  29520. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  29521. this.setFocalLength( focalLength );
  29522. };
  29523. //
  29524. Object.defineProperties( Light.prototype, {
  29525. onlyShadow: {
  29526. set: function () {
  29527. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  29528. }
  29529. },
  29530. shadowCameraFov: {
  29531. set: function ( value ) {
  29532. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  29533. this.shadow.camera.fov = value;
  29534. }
  29535. },
  29536. shadowCameraLeft: {
  29537. set: function ( value ) {
  29538. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  29539. this.shadow.camera.left = value;
  29540. }
  29541. },
  29542. shadowCameraRight: {
  29543. set: function ( value ) {
  29544. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  29545. this.shadow.camera.right = value;
  29546. }
  29547. },
  29548. shadowCameraTop: {
  29549. set: function ( value ) {
  29550. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  29551. this.shadow.camera.top = value;
  29552. }
  29553. },
  29554. shadowCameraBottom: {
  29555. set: function ( value ) {
  29556. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  29557. this.shadow.camera.bottom = value;
  29558. }
  29559. },
  29560. shadowCameraNear: {
  29561. set: function ( value ) {
  29562. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  29563. this.shadow.camera.near = value;
  29564. }
  29565. },
  29566. shadowCameraFar: {
  29567. set: function ( value ) {
  29568. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  29569. this.shadow.camera.far = value;
  29570. }
  29571. },
  29572. shadowCameraVisible: {
  29573. set: function () {
  29574. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  29575. }
  29576. },
  29577. shadowBias: {
  29578. set: function ( value ) {
  29579. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  29580. this.shadow.bias = value;
  29581. }
  29582. },
  29583. shadowDarkness: {
  29584. set: function () {
  29585. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  29586. }
  29587. },
  29588. shadowMapWidth: {
  29589. set: function ( value ) {
  29590. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  29591. this.shadow.mapSize.width = value;
  29592. }
  29593. },
  29594. shadowMapHeight: {
  29595. set: function ( value ) {
  29596. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  29597. this.shadow.mapSize.height = value;
  29598. }
  29599. }
  29600. } );
  29601. //
  29602. Object.defineProperties( BufferAttribute.prototype, {
  29603. length: {
  29604. get: function () {
  29605. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  29606. return this.array.length;
  29607. }
  29608. },
  29609. copyIndicesArray: function ( /* indices */ ) {
  29610. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  29611. }
  29612. } );
  29613. Object.assign( BufferGeometry.prototype, {
  29614. addIndex: function ( index ) {
  29615. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  29616. this.setIndex( index );
  29617. },
  29618. addDrawCall: function ( start, count, indexOffset ) {
  29619. if ( indexOffset !== undefined ) {
  29620. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  29621. }
  29622. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  29623. this.addGroup( start, count );
  29624. },
  29625. clearDrawCalls: function () {
  29626. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  29627. this.clearGroups();
  29628. },
  29629. computeTangents: function () {
  29630. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  29631. },
  29632. computeOffsets: function () {
  29633. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  29634. }
  29635. } );
  29636. Object.defineProperties( BufferGeometry.prototype, {
  29637. drawcalls: {
  29638. get: function () {
  29639. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  29640. return this.groups;
  29641. }
  29642. },
  29643. offsets: {
  29644. get: function () {
  29645. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  29646. return this.groups;
  29647. }
  29648. }
  29649. } );
  29650. //
  29651. Object.assign( ExtrudeBufferGeometry.prototype, {
  29652. getArrays: function () {
  29653. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  29654. },
  29655. addShapeList: function () {
  29656. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  29657. },
  29658. addShape: function () {
  29659. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  29660. }
  29661. } );
  29662. //
  29663. Object.defineProperties( Uniform.prototype, {
  29664. dynamic: {
  29665. set: function () {
  29666. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  29667. }
  29668. },
  29669. onUpdate: {
  29670. value: function () {
  29671. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  29672. return this;
  29673. }
  29674. }
  29675. } );
  29676. //
  29677. Object.defineProperties( Material.prototype, {
  29678. wrapAround: {
  29679. get: function () {
  29680. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  29681. },
  29682. set: function () {
  29683. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  29684. }
  29685. },
  29686. overdraw: {
  29687. get: function () {
  29688. console.warn( 'THREE.Material: .overdraw has been removed.' );
  29689. },
  29690. set: function () {
  29691. console.warn( 'THREE.Material: .overdraw has been removed.' );
  29692. }
  29693. },
  29694. wrapRGB: {
  29695. get: function () {
  29696. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  29697. return new Color();
  29698. }
  29699. },
  29700. shading: {
  29701. get: function () {
  29702. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  29703. },
  29704. set: function ( value ) {
  29705. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  29706. this.flatShading = ( value === FlatShading );
  29707. }
  29708. }
  29709. } );
  29710. Object.defineProperties( MeshPhongMaterial.prototype, {
  29711. metal: {
  29712. get: function () {
  29713. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  29714. return false;
  29715. },
  29716. set: function () {
  29717. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  29718. }
  29719. }
  29720. } );
  29721. Object.defineProperties( ShaderMaterial.prototype, {
  29722. derivatives: {
  29723. get: function () {
  29724. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  29725. return this.extensions.derivatives;
  29726. },
  29727. set: function ( value ) {
  29728. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  29729. this.extensions.derivatives = value;
  29730. }
  29731. }
  29732. } );
  29733. //
  29734. Object.assign( WebGLRenderer.prototype, {
  29735. clearTarget: function ( renderTarget, color, depth, stencil ) {
  29736. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  29737. this.setRenderTarget( renderTarget );
  29738. this.clear( color, depth, stencil );
  29739. },
  29740. animate: function ( callback ) {
  29741. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  29742. this.setAnimationLoop( callback );
  29743. },
  29744. getCurrentRenderTarget: function () {
  29745. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  29746. return this.getRenderTarget();
  29747. },
  29748. getMaxAnisotropy: function () {
  29749. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  29750. return this.capabilities.getMaxAnisotropy();
  29751. },
  29752. getPrecision: function () {
  29753. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  29754. return this.capabilities.precision;
  29755. },
  29756. resetGLState: function () {
  29757. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  29758. return this.state.reset();
  29759. },
  29760. supportsFloatTextures: function () {
  29761. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  29762. return this.extensions.get( 'OES_texture_float' );
  29763. },
  29764. supportsHalfFloatTextures: function () {
  29765. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  29766. return this.extensions.get( 'OES_texture_half_float' );
  29767. },
  29768. supportsStandardDerivatives: function () {
  29769. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  29770. return this.extensions.get( 'OES_standard_derivatives' );
  29771. },
  29772. supportsCompressedTextureS3TC: function () {
  29773. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  29774. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  29775. },
  29776. supportsCompressedTexturePVRTC: function () {
  29777. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  29778. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  29779. },
  29780. supportsBlendMinMax: function () {
  29781. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  29782. return this.extensions.get( 'EXT_blend_minmax' );
  29783. },
  29784. supportsVertexTextures: function () {
  29785. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  29786. return this.capabilities.vertexTextures;
  29787. },
  29788. supportsInstancedArrays: function () {
  29789. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  29790. return this.extensions.get( 'ANGLE_instanced_arrays' );
  29791. },
  29792. enableScissorTest: function ( boolean ) {
  29793. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  29794. this.setScissorTest( boolean );
  29795. },
  29796. initMaterial: function () {
  29797. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  29798. },
  29799. addPrePlugin: function () {
  29800. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  29801. },
  29802. addPostPlugin: function () {
  29803. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  29804. },
  29805. updateShadowMap: function () {
  29806. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  29807. },
  29808. setFaceCulling: function () {
  29809. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  29810. },
  29811. allocTextureUnit: function () {
  29812. console.warn( 'THREE.WebGLRenderer: .allocTextureUnit() has been removed.' );
  29813. },
  29814. setTexture: function () {
  29815. console.warn( 'THREE.WebGLRenderer: .setTexture() has been removed.' );
  29816. },
  29817. setTexture2D: function () {
  29818. console.warn( 'THREE.WebGLRenderer: .setTexture2D() has been removed.' );
  29819. },
  29820. setTextureCube: function () {
  29821. console.warn( 'THREE.WebGLRenderer: .setTextureCube() has been removed.' );
  29822. },
  29823. getActiveMipMapLevel: function () {
  29824. console.warn( 'THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().' );
  29825. return this.getActiveMipmapLevel();
  29826. }
  29827. } );
  29828. Object.defineProperties( WebGLRenderer.prototype, {
  29829. shadowMapEnabled: {
  29830. get: function () {
  29831. return this.shadowMap.enabled;
  29832. },
  29833. set: function ( value ) {
  29834. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  29835. this.shadowMap.enabled = value;
  29836. }
  29837. },
  29838. shadowMapType: {
  29839. get: function () {
  29840. return this.shadowMap.type;
  29841. },
  29842. set: function ( value ) {
  29843. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  29844. this.shadowMap.type = value;
  29845. }
  29846. },
  29847. shadowMapCullFace: {
  29848. get: function () {
  29849. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  29850. return undefined;
  29851. },
  29852. set: function ( /* value */ ) {
  29853. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  29854. }
  29855. },
  29856. context: {
  29857. get: function () {
  29858. console.warn( 'THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.' );
  29859. return this.getContext();
  29860. }
  29861. }
  29862. } );
  29863. Object.defineProperties( WebGLShadowMap.prototype, {
  29864. cullFace: {
  29865. get: function () {
  29866. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  29867. return undefined;
  29868. },
  29869. set: function ( /* cullFace */ ) {
  29870. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  29871. }
  29872. },
  29873. renderReverseSided: {
  29874. get: function () {
  29875. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  29876. return undefined;
  29877. },
  29878. set: function () {
  29879. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  29880. }
  29881. },
  29882. renderSingleSided: {
  29883. get: function () {
  29884. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  29885. return undefined;
  29886. },
  29887. set: function () {
  29888. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  29889. }
  29890. }
  29891. } );
  29892. //
  29893. Object.defineProperties( WebGLRenderTargetCube.prototype, {
  29894. activeCubeFace: {
  29895. set: function ( /* value */ ) {
  29896. console.warn( 'THREE.WebGLRenderTargetCube: .activeCubeFace has been removed. It is now the second parameter of WebGLRenderer.setRenderTarget().' );
  29897. }
  29898. },
  29899. activeMipMapLevel: {
  29900. set: function ( /* value */ ) {
  29901. console.warn( 'THREE.WebGLRenderTargetCube: .activeMipMapLevel has been removed. It is now the third parameter of WebGLRenderer.setRenderTarget().' );
  29902. }
  29903. }
  29904. } );
  29905. //
  29906. Object.defineProperties( WebGLRenderTarget.prototype, {
  29907. wrapS: {
  29908. get: function () {
  29909. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  29910. return this.texture.wrapS;
  29911. },
  29912. set: function ( value ) {
  29913. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  29914. this.texture.wrapS = value;
  29915. }
  29916. },
  29917. wrapT: {
  29918. get: function () {
  29919. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  29920. return this.texture.wrapT;
  29921. },
  29922. set: function ( value ) {
  29923. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  29924. this.texture.wrapT = value;
  29925. }
  29926. },
  29927. magFilter: {
  29928. get: function () {
  29929. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  29930. return this.texture.magFilter;
  29931. },
  29932. set: function ( value ) {
  29933. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  29934. this.texture.magFilter = value;
  29935. }
  29936. },
  29937. minFilter: {
  29938. get: function () {
  29939. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  29940. return this.texture.minFilter;
  29941. },
  29942. set: function ( value ) {
  29943. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  29944. this.texture.minFilter = value;
  29945. }
  29946. },
  29947. anisotropy: {
  29948. get: function () {
  29949. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  29950. return this.texture.anisotropy;
  29951. },
  29952. set: function ( value ) {
  29953. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  29954. this.texture.anisotropy = value;
  29955. }
  29956. },
  29957. offset: {
  29958. get: function () {
  29959. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  29960. return this.texture.offset;
  29961. },
  29962. set: function ( value ) {
  29963. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  29964. this.texture.offset = value;
  29965. }
  29966. },
  29967. repeat: {
  29968. get: function () {
  29969. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  29970. return this.texture.repeat;
  29971. },
  29972. set: function ( value ) {
  29973. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  29974. this.texture.repeat = value;
  29975. }
  29976. },
  29977. format: {
  29978. get: function () {
  29979. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  29980. return this.texture.format;
  29981. },
  29982. set: function ( value ) {
  29983. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  29984. this.texture.format = value;
  29985. }
  29986. },
  29987. type: {
  29988. get: function () {
  29989. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  29990. return this.texture.type;
  29991. },
  29992. set: function ( value ) {
  29993. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  29994. this.texture.type = value;
  29995. }
  29996. },
  29997. generateMipmaps: {
  29998. get: function () {
  29999. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  30000. return this.texture.generateMipmaps;
  30001. },
  30002. set: function ( value ) {
  30003. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  30004. this.texture.generateMipmaps = value;
  30005. }
  30006. }
  30007. } );
  30008. //
  30009. Object.defineProperties( WebVRManager.prototype, {
  30010. standing: {
  30011. set: function ( /* value */ ) {
  30012. console.warn( 'THREE.WebVRManager: .standing has been removed.' );
  30013. }
  30014. },
  30015. userHeight: {
  30016. set: function ( /* value */ ) {
  30017. console.warn( 'THREE.WebVRManager: .userHeight has been removed.' );
  30018. }
  30019. }
  30020. } );
  30021. //
  30022. Audio.prototype.load = function ( file ) {
  30023. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  30024. var scope = this;
  30025. var audioLoader = new AudioLoader();
  30026. audioLoader.load( file, function ( buffer ) {
  30027. scope.setBuffer( buffer );
  30028. } );
  30029. return this;
  30030. };
  30031. AudioAnalyser.prototype.getData = function () {
  30032. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  30033. return this.getFrequencyData();
  30034. };
  30035. //
  30036. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  30037. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  30038. return this.update( renderer, scene );
  30039. };
  30040. //
  30041. var GeometryUtils = {
  30042. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  30043. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  30044. var matrix;
  30045. if ( geometry2.isMesh ) {
  30046. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  30047. matrix = geometry2.matrix;
  30048. geometry2 = geometry2.geometry;
  30049. }
  30050. geometry1.merge( geometry2, matrix, materialIndexOffset );
  30051. },
  30052. center: function ( geometry ) {
  30053. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  30054. return geometry.center();
  30055. }
  30056. };
  30057. ImageUtils.crossOrigin = undefined;
  30058. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  30059. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  30060. var loader = new TextureLoader();
  30061. loader.setCrossOrigin( this.crossOrigin );
  30062. var texture = loader.load( url, onLoad, undefined, onError );
  30063. if ( mapping ) texture.mapping = mapping;
  30064. return texture;
  30065. };
  30066. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  30067. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  30068. var loader = new CubeTextureLoader();
  30069. loader.setCrossOrigin( this.crossOrigin );
  30070. var texture = loader.load( urls, onLoad, undefined, onError );
  30071. if ( mapping ) texture.mapping = mapping;
  30072. return texture;
  30073. };
  30074. ImageUtils.loadCompressedTexture = function () {
  30075. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  30076. };
  30077. ImageUtils.loadCompressedTextureCube = function () {
  30078. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  30079. };
  30080. //
  30081. function CanvasRenderer() {
  30082. console.error( 'THREE.CanvasRenderer has been removed' );
  30083. }
  30084. //
  30085. function JSONLoader() {
  30086. console.error( 'THREE.JSONLoader has been removed.' );
  30087. }
  30088. //
  30089. var SceneUtils = {
  30090. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  30091. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  30092. },
  30093. detach: function ( /* child, parent, scene */ ) {
  30094. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  30095. },
  30096. attach: function ( /* child, scene, parent */ ) {
  30097. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  30098. }
  30099. };
  30100. //
  30101. function LensFlare() {
  30102. console.error( 'THREE.LensFlare has been moved to /examples/js/objects/Lensflare.js' );
  30103. }
  30104. 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 };