echartsgl.js 2.6 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536515375153851539515405154151542515435154451545515465154751548515495155051551515525155351554515555155651557515585155951560515615156251563515645156551566515675156851569515705157151572515735157451575515765157751578515795158051581515825158351584515855158651587515885158951590515915159251593515945159551596515975159851599516005160151602516035160451605516065160751608516095161051611516125161351614516155161651617516185161951620516215162251623516245162551626516275162851629516305163151632516335163451635516365163751638516395164051641516425164351644516455164651647516485164951650516515165251653516545165551656516575165851659516605166151662516635166451665516665166751668516695167051671516725167351674516755167651677516785167951680516815168251683516845168551686516875168851689516905169151692516935169451695516965169751698516995170051701517025170351704517055170651707517085170951710517115171251713517145171551716517175171851719517205172151722517235172451725517265172751728517295173051731517325173351734517355173651737517385173951740517415174251743517445174551746517475174851749517505175151752517535175451755517565175751758517595176051761517625176351764517655176651767517685176951770517715177251773517745177551776517775177851779517805178151782517835178451785517865178751788517895179051791517925179351794517955179651797517985179951800518015180251803518045180551806518075180851809518105181151812518135181451815518165181751818518195182051821518225182351824518255182651827518285182951830518315183251833518345183551836518375183851839518405184151842518435184451845518465184751848518495185051851518525185351854518555185651857518585185951860518615186251863518645186551866518675186851869518705187151872518735187451875518765187751878518795188051881518825188351884518855188651887518885188951890518915189251893518945189551896518975189851899519005190151902519035190451905519065190751908519095191051911519125191351914519155191651917519185191951920519215192251923519245192551926519275192851929519305193151932519335193451935519365193751938519395194051941519425194351944519455194651947519485194951950519515195251953519545195551956519575195851959519605196151962519635196451965519665196751968519695197051971519725197351974519755197651977519785197951980519815198251983519845198551986519875198851989519905199151992519935199451995519965199751998519995200052001520025200352004520055200652007520085200952010520115201252013520145201552016520175201852019520205202152022520235202452025520265202752028520295203052031520325203352034520355203652037520385203952040520415204252043520445204552046520475204852049520505205152052520535205452055520565205752058520595206052061520625206352064520655206652067520685206952070520715207252073520745207552076520775207852079520805208152082520835208452085520865208752088520895209052091520925209352094520955209652097520985209952100521015210252103521045210552106521075210852109521105211152112521135211452115521165211752118521195212052121521225212352124521255212652127521285212952130521315213252133521345213552136521375213852139521405214152142521435214452145521465214752148521495215052151521525215352154521555215652157521585215952160521615216252163521645216552166521675216852169521705217152172521735217452175521765217752178521795218052181521825218352184521855218652187521885218952190521915219252193521945219552196521975219852199522005220152202522035220452205522065220752208522095221052211522125221352214522155221652217522185221952220522215222252223522245222552226522275222852229522305223152232522335223452235522365223752238522395224052241522425224352244522455224652247522485224952250522515225252253522545225552256522575225852259522605226152262522635226452265522665226752268522695227052271522725227352274522755227652277522785227952280522815228252283522845228552286522875228852289522905229152292522935229452295522965229752298522995230052301523025230352304523055230652307523085230952310523115231252313523145231552316523175231852319523205232152322523235232452325523265232752328523295233052331523325233352334523355233652337523385233952340523415234252343523445234552346523475234852349523505235152352523535235452355523565235752358523595236052361523625236352364523655236652367523685236952370523715237252373523745237552376523775237852379523805238152382523835238452385523865238752388523895239052391523925239352394523955239652397523985239952400524015240252403524045240552406524075240852409524105241152412524135241452415524165241752418524195242052421524225242352424524255242652427524285242952430524315243252433524345243552436524375243852439524405244152442524435244452445524465244752448524495245052451524525245352454524555245652457524585245952460524615246252463524645246552466524675246852469524705247152472524735247452475524765247752478524795248052481524825248352484524855248652487524885248952490524915249252493524945249552496524975249852499525005250152502525035250452505525065250752508525095251052511525125251352514525155251652517525185251952520525215252252523525245252552526525275252852529525305253152532525335253452535525365253752538525395254052541525425254352544525455254652547525485254952550525515255252553525545255552556525575255852559525605256152562525635256452565525665256752568525695257052571525725257352574525755257652577525785257952580525815258252583525845258552586525875258852589525905259152592525935259452595525965259752598525995260052601526025260352604526055260652607526085260952610526115261252613526145261552616526175261852619526205262152622526235262452625526265262752628526295263052631526325263352634526355263652637526385263952640526415264252643526445264552646526475264852649526505265152652526535265452655526565265752658526595266052661526625266352664526655266652667526685266952670526715267252673526745267552676526775267852679526805268152682526835268452685526865268752688526895269052691526925269352694526955269652697526985269952700527015270252703527045270552706527075270852709527105271152712527135271452715527165271752718527195272052721527225272352724527255272652727527285272952730527315273252733527345273552736527375273852739527405274152742527435274452745527465274752748527495275052751527525275352754527555275652757527585275952760527615276252763527645276552766527675276852769527705277152772527735277452775527765277752778527795278052781527825278352784527855278652787527885278952790527915279252793527945279552796527975279852799528005280152802528035280452805528065280752808528095281052811528125281352814528155281652817528185281952820528215282252823528245282552826528275282852829528305283152832528335283452835528365283752838528395284052841528425284352844528455284652847528485284952850528515285252853528545285552856528575285852859528605286152862528635286452865528665286752868528695287052871528725287352874528755287652877528785287952880528815288252883528845288552886528875288852889528905289152892528935289452895528965289752898528995290052901529025290352904529055290652907529085290952910529115291252913529145291552916529175291852919529205292152922529235292452925529265292752928529295293052931529325293352934529355293652937529385293952940529415294252943529445294552946529475294852949529505295152952529535295452955529565295752958529595296052961529625296352964529655296652967529685296952970529715297252973529745297552976529775297852979529805298152982529835298452985529865298752988529895299052991529925299352994529955299652997529985299953000530015300253003530045300553006530075300853009530105301153012530135301453015530165301753018530195302053021530225302353024530255302653027530285302953030530315303253033530345303553036530375303853039530405304153042530435304453045530465304753048530495305053051530525305353054530555305653057530585305953060530615306253063530645306553066530675306853069530705307153072530735307453075530765307753078530795308053081530825308353084530855308653087530885308953090530915309253093530945309553096530975309853099531005310153102531035310453105531065310753108531095311053111531125311353114531155311653117531185311953120531215312253123531245312553126531275312853129531305313153132531335313453135531365313753138531395314053141531425314353144531455314653147531485314953150531515315253153531545315553156531575315853159531605316153162531635316453165531665316753168531695317053171531725317353174531755317653177531785317953180531815318253183531845318553186531875318853189531905319153192531935319453195531965319753198531995320053201532025320353204532055320653207532085320953210532115321253213532145321553216532175321853219532205322153222532235322453225532265322753228532295323053231532325323353234532355323653237532385323953240532415324253243532445324553246532475324853249532505325153252532535325453255532565325753258532595326053261532625326353264532655326653267532685326953270532715327253273532745327553276532775327853279532805328153282532835328453285532865328753288532895329053291532925329353294532955329653297532985329953300533015330253303533045330553306533075330853309533105331153312533135331453315533165331753318533195332053321533225332353324533255332653327533285332953330533315333253333533345333553336533375333853339533405334153342533435334453345533465334753348533495335053351533525335353354533555335653357533585335953360533615336253363533645336553366533675336853369533705337153372533735337453375533765337753378533795338053381533825338353384533855338653387533885338953390533915339253393533945339553396533975339853399534005340153402534035340453405534065340753408534095341053411534125341353414534155341653417534185341953420534215342253423534245342553426534275342853429534305343153432534335343453435534365343753438534395344053441534425344353444534455344653447534485344953450534515345253453534545345553456534575345853459534605346153462534635346453465534665346753468534695347053471534725347353474534755347653477534785347953480534815348253483534845348553486534875348853489534905349153492534935349453495534965349753498534995350053501535025350353504535055350653507535085350953510535115351253513535145351553516535175351853519535205352153522535235352453525535265352753528535295353053531535325353353534535355353653537535385353953540535415354253543535445354553546535475354853549535505355153552535535355453555535565355753558535595356053561535625356353564535655356653567535685356953570535715357253573535745357553576535775357853579535805358153582535835358453585535865358753588535895359053591535925359353594535955359653597535985359953600536015360253603536045360553606536075360853609536105361153612536135361453615536165361753618536195362053621536225362353624536255362653627536285362953630536315363253633536345363553636536375363853639536405364153642536435364453645536465364753648536495365053651536525365353654536555365653657536585365953660536615366253663536645366553666536675366853669536705367153672536735367453675536765367753678536795368053681536825368353684536855368653687536885368953690536915369253693536945369553696536975369853699537005370153702537035370453705537065370753708537095371053711537125371353714537155371653717537185371953720537215372253723537245372553726537275372853729537305373153732537335373453735537365373753738537395374053741537425374353744537455374653747537485374953750537515375253753537545375553756537575375853759537605376153762537635376453765537665376753768537695377053771537725377353774537755377653777537785377953780537815378253783537845378553786537875378853789537905379153792537935379453795537965379753798537995380053801538025380353804538055380653807538085380953810538115381253813538145381553816538175381853819538205382153822538235382453825538265382753828538295383053831538325383353834538355383653837538385383953840538415384253843538445384553846538475384853849538505385153852538535385453855538565385753858538595386053861538625386353864538655386653867538685386953870538715387253873538745387553876538775387853879538805388153882538835388453885538865388753888538895389053891538925389353894538955389653897538985389953900539015390253903539045390553906539075390853909539105391153912539135391453915539165391753918539195392053921539225392353924539255392653927539285392953930539315393253933539345393553936539375393853939539405394153942539435394453945539465394753948539495395053951539525395353954539555395653957539585395953960539615396253963539645396553966539675396853969539705397153972539735397453975539765397753978539795398053981539825398353984539855398653987539885398953990539915399253993539945399553996539975399853999540005400154002540035400454005540065400754008540095401054011540125401354014540155401654017540185401954020540215402254023540245402554026540275402854029540305403154032540335403454035540365403754038540395404054041540425404354044540455404654047540485404954050540515405254053540545405554056540575405854059540605406154062540635406454065540665406754068540695407054071540725407354074540755407654077540785407954080540815408254083540845408554086540875408854089540905409154092540935409454095540965409754098540995410054101541025410354104541055410654107541085410954110541115411254113541145411554116541175411854119541205412154122541235412454125541265412754128541295413054131541325413354134541355413654137541385413954140541415414254143541445414554146541475414854149541505415154152541535415454155541565415754158541595416054161541625416354164541655416654167541685416954170541715417254173541745417554176541775417854179541805418154182541835418454185541865418754188541895419054191541925419354194541955419654197541985419954200542015420254203542045420554206542075420854209542105421154212542135421454215542165421754218542195422054221542225422354224542255422654227542285422954230542315423254233542345423554236542375423854239542405424154242542435424454245542465424754248542495425054251542525425354254542555425654257542585425954260542615426254263542645426554266542675426854269542705427154272542735427454275542765427754278542795428054281542825428354284542855428654287542885428954290542915429254293542945429554296542975429854299543005430154302543035430454305543065430754308543095431054311543125431354314543155431654317543185431954320543215432254323543245432554326543275432854329543305433154332543335433454335543365433754338543395434054341543425434354344543455434654347543485434954350543515435254353543545435554356543575435854359543605436154362543635436454365543665436754368543695437054371543725437354374543755437654377543785437954380543815438254383543845438554386543875438854389543905439154392543935439454395543965439754398543995440054401544025440354404544055440654407544085440954410544115441254413544145441554416544175441854419544205442154422544235442454425544265442754428544295443054431544325443354434544355443654437544385443954440544415444254443544445444554446544475444854449544505445154452544535445454455544565445754458544595446054461544625446354464544655446654467544685446954470544715447254473544745447554476544775447854479544805448154482544835448454485544865448754488544895449054491544925449354494544955449654497544985449954500545015450254503545045450554506545075450854509545105451154512545135451454515545165451754518545195452054521545225452354524545255452654527545285452954530545315453254533545345453554536545375453854539545405454154542545435454454545545465454754548545495455054551545525455354554545555455654557545585455954560545615456254563545645456554566545675456854569545705457154572545735457454575545765457754578545795458054581545825458354584545855458654587545885458954590545915459254593545945459554596545975459854599546005460154602546035460454605546065460754608546095461054611546125461354614546155461654617546185461954620546215462254623546245462554626546275462854629546305463154632546335463454635546365463754638546395464054641546425464354644546455464654647546485464954650546515465254653546545465554656546575465854659546605466154662546635466454665546665466754668546695467054671546725467354674546755467654677546785467954680546815468254683546845468554686546875468854689546905469154692546935469454695546965469754698546995470054701547025470354704547055470654707547085470954710547115471254713547145471554716547175471854719547205472154722547235472454725547265472754728547295473054731547325473354734547355473654737547385473954740547415474254743547445474554746547475474854749547505475154752547535475454755547565475754758547595476054761547625476354764547655476654767547685476954770547715477254773547745477554776547775477854779547805478154782547835478454785547865478754788547895479054791547925479354794547955479654797547985479954800548015480254803548045480554806548075480854809548105481154812548135481454815548165481754818548195482054821548225482354824548255482654827548285482954830548315483254833548345483554836548375483854839548405484154842548435484454845548465484754848548495485054851548525485354854548555485654857548585485954860548615486254863548645486554866548675486854869548705487154872548735487454875548765487754878548795488054881548825488354884548855488654887548885488954890548915489254893548945489554896548975489854899549005490154902549035490454905549065490754908549095491054911549125491354914549155491654917549185491954920549215492254923549245492554926549275492854929549305493154932549335493454935549365493754938549395494054941549425494354944549455494654947549485494954950549515495254953549545495554956549575495854959549605496154962549635496454965549665496754968549695497054971549725497354974549755497654977549785497954980549815498254983549845498554986549875498854989549905499154992549935499454995549965499754998549995500055001550025500355004550055500655007550085500955010550115501255013550145501555016550175501855019550205502155022550235502455025550265502755028550295503055031550325503355034550355503655037550385503955040550415504255043550445504555046550475504855049550505505155052550535505455055550565505755058550595506055061550625506355064550655506655067550685506955070550715507255073550745507555076550775507855079550805508155082550835508455085550865508755088550895509055091550925509355094550955509655097550985509955100551015510255103551045510555106551075510855109551105511155112551135511455115551165511755118551195512055121551225512355124551255512655127551285512955130551315513255133551345513555136551375513855139551405514155142551435514455145551465514755148551495515055151551525515355154551555515655157551585515955160551615516255163551645516555166551675516855169551705517155172551735517455175551765517755178551795518055181551825518355184551855518655187551885518955190551915519255193551945519555196551975519855199552005520155202552035520455205552065520755208552095521055211552125521355214552155521655217552185521955220552215522255223552245522555226552275522855229552305523155232552335523455235552365523755238552395524055241552425524355244552455524655247552485524955250552515525255253552545525555256552575525855259552605526155262552635526455265552665526755268552695527055271552725527355274552755527655277552785527955280552815528255283552845528555286552875528855289552905529155292552935529455295552965529755298552995530055301553025530355304553055530655307553085530955310553115531255313553145531555316553175531855319553205532155322553235532455325553265532755328553295533055331553325533355334553355533655337553385533955340553415534255343553445534555346553475534855349553505535155352553535535455355553565535755358553595536055361553625536355364553655536655367553685536955370553715537255373553745537555376553775537855379553805538155382553835538455385553865538755388553895539055391553925539355394553955539655397553985539955400554015540255403554045540555406554075540855409554105541155412554135541455415554165541755418554195542055421554225542355424554255542655427554285542955430554315543255433554345543555436554375543855439554405544155442554435544455445554465544755448554495545055451554525545355454554555545655457554585545955460554615546255463554645546555466554675546855469554705547155472554735547455475554765547755478554795548055481554825548355484554855548655487554885548955490554915549255493554945549555496554975549855499555005550155502555035550455505555065550755508555095551055511555125551355514555155551655517555185551955520555215552255523555245552555526555275552855529555305553155532555335553455535555365553755538555395554055541555425554355544555455554655547555485554955550555515555255553555545555555556555575555855559555605556155562555635556455565555665556755568555695557055571555725557355574555755557655577555785557955580555815558255583555845558555586555875558855589555905559155592555935559455595555965559755598555995560055601556025560355604556055560655607556085560955610556115561255613556145561555616556175561855619556205562155622556235562455625556265562755628556295563055631556325563355634556355563655637556385563955640556415564255643556445564555646556475564855649556505565155652556535565455655556565565755658556595566055661556625566355664556655566655667556685566955670556715567255673556745567555676556775567855679556805568155682556835568455685556865568755688556895569055691556925569355694556955569655697556985569955700557015570255703557045570555706557075570855709557105571155712557135571455715557165571755718557195572055721557225572355724557255572655727557285572955730557315573255733557345573555736557375573855739557405574155742557435574455745557465574755748557495575055751557525575355754557555575655757557585575955760557615576255763557645576555766557675576855769557705577155772557735577455775557765577755778557795578055781557825578355784557855578655787557885578955790557915579255793557945579555796557975579855799558005580155802558035580455805558065580755808558095581055811558125581355814558155581655817558185581955820558215582255823558245582555826558275582855829558305583155832558335583455835558365583755838558395584055841558425584355844558455584655847558485584955850558515585255853558545585555856558575585855859558605586155862558635586455865558665586755868558695587055871558725587355874558755587655877558785587955880558815588255883558845588555886558875588855889558905589155892558935589455895558965589755898558995590055901559025590355904559055590655907559085590955910559115591255913559145591555916559175591855919559205592155922559235592455925559265592755928559295593055931559325593355934559355593655937559385593955940559415594255943559445594555946559475594855949559505595155952559535595455955559565595755958559595596055961559625596355964559655596655967559685596955970559715597255973559745597555976559775597855979559805598155982559835598455985559865598755988559895599055991559925599355994559955599655997559985599956000560015600256003560045600556006560075600856009560105601156012560135601456015560165601756018560195602056021560225602356024560255602656027560285602956030560315603256033560345603556036560375603856039560405604156042560435604456045560465604756048560495605056051560525605356054560555605656057560585605956060560615606256063560645606556066560675606856069560705607156072560735607456075560765607756078560795608056081560825608356084560855608656087560885608956090560915609256093560945609556096560975609856099561005610156102561035610456105561065610756108561095611056111561125611356114561155611656117561185611956120561215612256123561245612556126561275612856129561305613156132561335613456135561365613756138561395614056141561425614356144561455614656147561485614956150561515615256153561545615556156561575615856159561605616156162561635616456165561665616756168561695617056171561725617356174561755617656177561785617956180561815618256183561845618556186561875618856189561905619156192561935619456195561965619756198561995620056201562025620356204562055620656207562085620956210562115621256213562145621556216562175621856219562205622156222562235622456225562265622756228562295623056231562325623356234562355623656237562385623956240562415624256243562445624556246562475624856249562505625156252562535625456255562565625756258562595626056261562625626356264562655626656267562685626956270562715627256273562745627556276562775627856279562805628156282562835628456285562865628756288562895629056291562925629356294562955629656297562985629956300563015630256303563045630556306563075630856309563105631156312563135631456315563165631756318563195632056321563225632356324563255632656327563285632956330563315633256333563345633556336563375633856339563405634156342563435634456345563465634756348563495635056351563525635356354563555635656357563585635956360563615636256363563645636556366563675636856369563705637156372563735637456375563765637756378563795638056381563825638356384563855638656387563885638956390563915639256393563945639556396563975639856399564005640156402564035640456405564065640756408564095641056411564125641356414564155641656417564185641956420564215642256423564245642556426564275642856429564305643156432564335643456435564365643756438564395644056441564425644356444564455644656447564485644956450564515645256453564545645556456564575645856459564605646156462564635646456465564665646756468564695647056471564725647356474564755647656477564785647956480564815648256483564845648556486564875648856489564905649156492564935649456495564965649756498564995650056501565025650356504565055650656507565085650956510565115651256513565145651556516565175651856519565205652156522565235652456525565265652756528565295653056531565325653356534565355653656537565385653956540565415654256543565445654556546565475654856549565505655156552565535655456555565565655756558565595656056561565625656356564565655656656567565685656956570565715657256573565745657556576565775657856579565805658156582565835658456585565865658756588565895659056591565925659356594565955659656597565985659956600566015660256603566045660556606566075660856609566105661156612566135661456615566165661756618566195662056621566225662356624566255662656627566285662956630566315663256633566345663556636566375663856639566405664156642566435664456645566465664756648566495665056651566525665356654566555665656657566585665956660566615666256663566645666556666566675666856669566705667156672566735667456675566765667756678566795668056681566825668356684566855668656687566885668956690566915669256693566945669556696566975669856699567005670156702567035670456705567065670756708567095671056711567125671356714567155671656717567185671956720567215672256723567245672556726567275672856729567305673156732567335673456735567365673756738567395674056741567425674356744567455674656747567485674956750567515675256753567545675556756567575675856759567605676156762567635676456765567665676756768567695677056771567725677356774567755677656777567785677956780567815678256783567845678556786567875678856789567905679156792567935679456795567965679756798567995680056801568025680356804568055680656807568085680956810568115681256813568145681556816568175681856819568205682156822568235682456825568265682756828568295683056831568325683356834568355683656837568385683956840568415684256843568445684556846568475684856849568505685156852568535685456855568565685756858568595686056861568625686356864568655686656867568685686956870568715687256873568745687556876568775687856879568805688156882568835688456885568865688756888568895689056891568925689356894568955689656897568985689956900569015690256903569045690556906569075690856909569105691156912569135691456915569165691756918569195692056921569225692356924569255692656927569285692956930569315693256933569345693556936569375693856939569405694156942569435694456945569465694756948569495695056951569525695356954569555695656957569585695956960569615696256963569645696556966569675696856969569705697156972569735697456975569765697756978569795698056981569825698356984569855698656987569885698956990569915699256993569945699556996569975699856999570005700157002570035700457005570065700757008570095701057011570125701357014570155701657017570185701957020570215702257023570245702557026570275702857029570305703157032570335703457035570365703757038570395704057041570425704357044570455704657047570485704957050570515705257053570545705557056570575705857059570605706157062570635706457065570665706757068570695707057071570725707357074570755707657077570785707957080570815708257083570845708557086570875708857089570905709157092570935709457095570965709757098570995710057101571025710357104571055710657107571085710957110571115711257113571145711557116571175711857119571205712157122571235712457125571265712757128571295713057131571325713357134571355713657137571385713957140571415714257143571445714557146571475714857149571505715157152571535715457155571565715757158571595716057161571625716357164571655716657167571685716957170571715717257173571745717557176571775717857179571805718157182571835718457185571865718757188571895719057191571925719357194571955719657197571985719957200572015720257203572045720557206572075720857209572105721157212572135721457215572165721757218572195722057221572225722357224572255722657227572285722957230572315723257233572345723557236572375723857239572405724157242572435724457245572465724757248572495725057251572525725357254572555725657257572585725957260572615726257263572645726557266572675726857269572705727157272572735727457275572765727757278572795728057281572825728357284
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if (typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("echarts"));
  4. else if (typeof define === 'function' && define.amd)
  5. define(["echarts"], factory);
  6. else if (typeof exports === 'object')
  7. exports["echarts-gl"] = factory(require("echarts"));
  8. else
  9. root["echarts-gl"] = factory(root["echarts"]);
  10. })(this, function (__WEBPACK_EXTERNAL_MODULE_0__) {
  11. return /******/ (function (modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if (installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/
  22. }
  23. /******/ // Create a new module (and put it into the cache)
  24. /******/ var module = installedModules[moduleId] = {
  25. /******/ i: moduleId,
  26. /******/ l: false,
  27. /******/ exports: {}
  28. /******/
  29. };
  30. /******/
  31. /******/ // Execute the module function
  32. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  33. /******/
  34. /******/ // Flag the module as loaded
  35. /******/ module.l = true;
  36. /******/
  37. /******/ // Return the exports of the module
  38. /******/ return module.exports;
  39. /******/
  40. }
  41. /******/
  42. /******/
  43. /******/ // expose the modules object (__webpack_modules__)
  44. /******/ __webpack_require__.m = modules;
  45. /******/
  46. /******/ // expose the module cache
  47. /******/ __webpack_require__.c = installedModules;
  48. /******/
  49. /******/ // define getter function for harmony exports
  50. /******/ __webpack_require__.d = function (exports, name, getter) {
  51. /******/ if (!__webpack_require__.o(exports, name)) {
  52. /******/ Object.defineProperty(exports, name, {
  53. /******/ configurable: false,
  54. /******/ enumerable: true,
  55. /******/ get: getter
  56. /******/
  57. });
  58. /******/
  59. }
  60. /******/
  61. };
  62. /******/
  63. /******/ // getDefaultExport function for compatibility with non-harmony modules
  64. /******/ __webpack_require__.n = function (module) {
  65. /******/ var getter = module && module.__esModule ?
  66. /******/ function getDefault() { return module['default']; } :
  67. /******/ function getModuleExports() { return module; };
  68. /******/ __webpack_require__.d(getter, 'a', getter);
  69. /******/ return getter;
  70. /******/
  71. };
  72. /******/
  73. /******/ // Object.prototype.hasOwnProperty.call
  74. /******/ __webpack_require__.o = function (object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  75. /******/
  76. /******/ // __webpack_public_path__
  77. /******/ __webpack_require__.p = "";
  78. /******/
  79. /******/ // Load entry module and return exports
  80. /******/ return __webpack_require__(__webpack_require__.s = 106);
  81. /******/
  82. })
  83. /************************************************************************/
  84. /******/([
  85. /* 0 */
  86. /***/ (function (module, exports) {
  87. module.exports = __WEBPACK_EXTERNAL_MODULE_0__;
  88. /***/
  89. }),
  90. /* 1 */
  91. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  92. "use strict";
  93. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_claygl_src_Mesh__ = __webpack_require__(40);
  94. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_Renderer__ = __webpack_require__(52);
  95. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_claygl_src_Texture2D__ = __webpack_require__(5);
  96. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture__ = __webpack_require__(4);
  97. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__ = __webpack_require__(8);
  98. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_claygl_src_Material__ = __webpack_require__(19);
  99. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_claygl_src_Node__ = __webpack_require__(35);
  100. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7_claygl_src_Geometry__ = __webpack_require__(15);
  101. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8_echarts_lib_echarts__ = __webpack_require__(0);
  102. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_8_echarts_lib_echarts__);
  103. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_9_claygl_src_Scene__ = __webpack_require__(36);
  104. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_10_zrender_lib_core_LRU__ = __webpack_require__(60);
  105. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_10_zrender_lib_core_LRU___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_10_zrender_lib_core_LRU__);
  106. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_11_claygl_src_util_texture__ = __webpack_require__(61);
  107. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_12__EChartsSurface__ = __webpack_require__(124);
  108. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_13_claygl_src_light_AmbientCubemap__ = __webpack_require__(125);
  109. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_14_claygl_src_light_AmbientSH__ = __webpack_require__(129);
  110. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_15_claygl_src_util_sh__ = __webpack_require__(130);
  111. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_16__retrieve__ = __webpack_require__(2);
  112. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_17_claygl_src_geometry_Sphere__ = __webpack_require__(132);
  113. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_18_claygl_src_geometry_Plane__ = __webpack_require__(43);
  114. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_19_claygl_src_geometry_Cube__ = __webpack_require__(76);
  115. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_20_claygl_src_light_Ambient__ = __webpack_require__(133);
  116. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_21_claygl_src_light_Directional__ = __webpack_require__(134);
  117. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_22_claygl_src_light_Point__ = __webpack_require__(135);
  118. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_23_claygl_src_light_Spot__ = __webpack_require__(136);
  119. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_24_claygl_src_camera_Perspective__ = __webpack_require__(41);
  120. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_25_claygl_src_camera_Orthographic__ = __webpack_require__(37);
  121. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_26_claygl_src_math_Vector2__ = __webpack_require__(26);
  122. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_27_claygl_src_math_Vector3__ = __webpack_require__(3);
  123. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_28_claygl_src_math_Vector4__ = __webpack_require__(137);
  124. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_29_claygl_src_math_Quaternion__ = __webpack_require__(56);
  125. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_30_claygl_src_math_Matrix2__ = __webpack_require__(138);
  126. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_31_claygl_src_math_Matrix2d__ = __webpack_require__(139);
  127. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_32_claygl_src_math_Matrix3__ = __webpack_require__(140);
  128. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_33_claygl_src_math_Matrix4__ = __webpack_require__(9);
  129. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_34_claygl_src_math_Plane__ = __webpack_require__(74);
  130. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_35_claygl_src_math_Ray__ = __webpack_require__(54);
  131. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_36_claygl_src_math_BoundingBox__ = __webpack_require__(18);
  132. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_37_claygl_src_math_Frustum__ = __webpack_require__(59);
  133. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_38__animatableMixin__ = __webpack_require__(141);
  134. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_39_claygl_src_shader_source_util_glsl_js__ = __webpack_require__(146);
  135. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_40_claygl_src_shader_source_prez_glsl_js__ = __webpack_require__(71);
  136. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_41__shader_common_glsl_js__ = __webpack_require__(147);
  137. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_42__shader_color_glsl_js__ = __webpack_require__(148);
  138. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_43__shader_lambert_glsl_js__ = __webpack_require__(149);
  139. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_44__shader_realistic_glsl_js__ = __webpack_require__(150);
  140. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_45__shader_hatching_glsl_js__ = __webpack_require__(151);
  141. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_46__shader_shadow_glsl_js__ = __webpack_require__(152);
  142. // Math
  143. // Some common shaders
  144. __WEBPACK_IMPORTED_MODULE_8_echarts_lib_echarts___default.a.util.extend(__WEBPACK_IMPORTED_MODULE_6_claygl_src_Node__["a" /* default */].prototype, __WEBPACK_IMPORTED_MODULE_38__animatableMixin__["a" /* default */]);
  145. __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].import(__WEBPACK_IMPORTED_MODULE_39_claygl_src_shader_source_util_glsl_js__["a" /* default */]);
  146. __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].import(__WEBPACK_IMPORTED_MODULE_40_claygl_src_shader_source_prez_glsl_js__["a" /* default */]);
  147. __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].import(__WEBPACK_IMPORTED_MODULE_41__shader_common_glsl_js__["a" /* default */]);
  148. __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].import(__WEBPACK_IMPORTED_MODULE_42__shader_color_glsl_js__["a" /* default */]);
  149. __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].import(__WEBPACK_IMPORTED_MODULE_43__shader_lambert_glsl_js__["a" /* default */]);
  150. __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].import(__WEBPACK_IMPORTED_MODULE_44__shader_realistic_glsl_js__["a" /* default */]);
  151. __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].import(__WEBPACK_IMPORTED_MODULE_45__shader_hatching_glsl_js__["a" /* default */]);
  152. __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].import(__WEBPACK_IMPORTED_MODULE_46__shader_shadow_glsl_js__["a" /* default */]);
  153. function isValueNone(value) {
  154. return !value || value === 'none';
  155. }
  156. function isValueImage(value) {
  157. return value instanceof HTMLCanvasElement
  158. || value instanceof HTMLImageElement
  159. || value instanceof Image;
  160. }
  161. function isECharts(value) {
  162. return value.getZr && value.setOption;
  163. }
  164. // Overwrite addToScene and removeFromScene
  165. var oldAddToScene = __WEBPACK_IMPORTED_MODULE_9_claygl_src_Scene__["a" /* default */].prototype.addToScene;
  166. var oldRemoveFromScene = __WEBPACK_IMPORTED_MODULE_9_claygl_src_Scene__["a" /* default */].prototype.removeFromScene;
  167. __WEBPACK_IMPORTED_MODULE_9_claygl_src_Scene__["a" /* default */].prototype.addToScene = function (node) {
  168. oldAddToScene.call(this, node);
  169. if (this.__zr) {
  170. var zr = this.__zr;
  171. node.traverse(function (child) {
  172. child.__zr = zr;
  173. if (child.addAnimatorsToZr) {
  174. child.addAnimatorsToZr(zr);
  175. }
  176. });
  177. }
  178. };
  179. __WEBPACK_IMPORTED_MODULE_9_claygl_src_Scene__["a" /* default */].prototype.removeFromScene = function (node) {
  180. oldRemoveFromScene.call(this, node);
  181. node.traverse(function (child) {
  182. var zr = child.__zr;
  183. child.__zr = null;
  184. if (zr && child.removeAnimatorsFromZr) {
  185. child.removeAnimatorsFromZr(zr);
  186. }
  187. });
  188. };
  189. /**
  190. * @param {string} textureName
  191. * @param {string|HTMLImageElement|HTMLCanvasElement} imgValue
  192. * @param {module:echarts/ExtensionAPI} api
  193. * @param {Object} [textureOpts]
  194. */
  195. __WEBPACK_IMPORTED_MODULE_5_claygl_src_Material__["a" /* default */].prototype.setTextureImage = function (textureName, imgValue, api, textureOpts) {
  196. if (!this.shader) {
  197. return;
  198. }
  199. var zr = api.getZr();
  200. var material = this;
  201. var texture;
  202. material.autoUpdateTextureStatus = false;
  203. // disableTexture first
  204. material.disableTexture(textureName);
  205. if (!isValueNone(imgValue)) {
  206. texture = graphicGL.loadTexture(imgValue, api, textureOpts, function (texture) {
  207. material.enableTexture(textureName);
  208. zr && zr.refresh();
  209. });
  210. // Set texture immediately for other code to verify if have this texture.
  211. material.set(textureName, texture);
  212. }
  213. return texture;
  214. };
  215. var graphicGL = {};
  216. graphicGL.Renderer = __WEBPACK_IMPORTED_MODULE_1_claygl_src_Renderer__["a" /* default */];
  217. graphicGL.Node = __WEBPACK_IMPORTED_MODULE_6_claygl_src_Node__["a" /* default */];
  218. graphicGL.Mesh = __WEBPACK_IMPORTED_MODULE_0_claygl_src_Mesh__["a" /* default */];
  219. graphicGL.Shader = __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */];
  220. graphicGL.Material = __WEBPACK_IMPORTED_MODULE_5_claygl_src_Material__["a" /* default */];
  221. graphicGL.Texture = __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture__["a" /* default */];
  222. graphicGL.Texture2D = __WEBPACK_IMPORTED_MODULE_2_claygl_src_Texture2D__["a" /* default */];
  223. // Geometries
  224. graphicGL.Geometry = __WEBPACK_IMPORTED_MODULE_7_claygl_src_Geometry__["a" /* default */];
  225. graphicGL.SphereGeometry = __WEBPACK_IMPORTED_MODULE_17_claygl_src_geometry_Sphere__["a" /* default */];
  226. graphicGL.PlaneGeometry = __WEBPACK_IMPORTED_MODULE_18_claygl_src_geometry_Plane__["a" /* default */];
  227. graphicGL.CubeGeometry = __WEBPACK_IMPORTED_MODULE_19_claygl_src_geometry_Cube__["a" /* default */];
  228. // Lights
  229. graphicGL.AmbientLight = __WEBPACK_IMPORTED_MODULE_20_claygl_src_light_Ambient__["a" /* default */];
  230. graphicGL.DirectionalLight = __WEBPACK_IMPORTED_MODULE_21_claygl_src_light_Directional__["a" /* default */];
  231. graphicGL.PointLight = __WEBPACK_IMPORTED_MODULE_22_claygl_src_light_Point__["a" /* default */];
  232. graphicGL.SpotLight = __WEBPACK_IMPORTED_MODULE_23_claygl_src_light_Spot__["a" /* default */];
  233. // Cameras
  234. graphicGL.PerspectiveCamera = __WEBPACK_IMPORTED_MODULE_24_claygl_src_camera_Perspective__["a" /* default */];
  235. graphicGL.OrthographicCamera = __WEBPACK_IMPORTED_MODULE_25_claygl_src_camera_Orthographic__["a" /* default */];
  236. // Math
  237. graphicGL.Vector2 = __WEBPACK_IMPORTED_MODULE_26_claygl_src_math_Vector2__["a" /* default */];
  238. graphicGL.Vector3 = __WEBPACK_IMPORTED_MODULE_27_claygl_src_math_Vector3__["a" /* default */];
  239. graphicGL.Vector4 = __WEBPACK_IMPORTED_MODULE_28_claygl_src_math_Vector4__["a" /* default */];
  240. graphicGL.Quaternion = __WEBPACK_IMPORTED_MODULE_29_claygl_src_math_Quaternion__["a" /* default */];
  241. graphicGL.Matrix2 = __WEBPACK_IMPORTED_MODULE_30_claygl_src_math_Matrix2__["a" /* default */];
  242. graphicGL.Matrix2d = __WEBPACK_IMPORTED_MODULE_31_claygl_src_math_Matrix2d__["a" /* default */];
  243. graphicGL.Matrix3 = __WEBPACK_IMPORTED_MODULE_32_claygl_src_math_Matrix3__["a" /* default */];
  244. graphicGL.Matrix4 = __WEBPACK_IMPORTED_MODULE_33_claygl_src_math_Matrix4__["a" /* default */];
  245. graphicGL.Plane = __WEBPACK_IMPORTED_MODULE_34_claygl_src_math_Plane__["a" /* default */];
  246. graphicGL.Ray = __WEBPACK_IMPORTED_MODULE_35_claygl_src_math_Ray__["a" /* default */];
  247. graphicGL.BoundingBox = __WEBPACK_IMPORTED_MODULE_36_claygl_src_math_BoundingBox__["a" /* default */];
  248. graphicGL.Frustum = __WEBPACK_IMPORTED_MODULE_37_claygl_src_math_Frustum__["a" /* default */];
  249. // Texture utilities
  250. var blankImage = __WEBPACK_IMPORTED_MODULE_11_claygl_src_util_texture__["a" /* default */].createBlank('rgba(255,255,255,0)').image;
  251. function nearestPowerOfTwo(val) {
  252. return Math.pow(2, Math.round(Math.log(val) / Math.LN2));
  253. }
  254. function convertTextureToPowerOfTwo(texture) {
  255. if ((texture.wrapS === __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture__["a" /* default */].REPEAT || texture.wrapT === __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture__["a" /* default */].REPEAT)
  256. && texture.image
  257. ) {
  258. // var canvas = document.createElement('canvas');
  259. var width = nearestPowerOfTwo(texture.width);
  260. var height = nearestPowerOfTwo(texture.height);
  261. if (width !== texture.width || height !== texture.height) {
  262. var canvas = document.createElement('canvas');
  263. canvas.width = width;
  264. canvas.height = height;
  265. var ctx = canvas.getContext('2d');
  266. ctx.drawImage(texture.image, 0, 0, width, height);
  267. texture.image = canvas;
  268. }
  269. }
  270. }
  271. /**
  272. * @param {string|HTMLImageElement|HTMLCanvasElement} imgValue
  273. * @param {module:echarts/ExtensionAPI} api
  274. * @param {Object} [textureOpts]
  275. * @param {Function} cb
  276. */
  277. // TODO Promise, test
  278. graphicGL.loadTexture = function (imgValue, api, textureOpts, cb) {
  279. if (typeof textureOpts === 'function') {
  280. cb = textureOpts;
  281. textureOpts = {};
  282. }
  283. textureOpts = textureOpts || {};
  284. var keys = Object.keys(textureOpts).sort();
  285. var prefix = '';
  286. for (var i = 0; i < keys.length; i++) {
  287. prefix += keys[i] + '_' + textureOpts[keys[i]] + '_';
  288. }
  289. var textureCache = api.__textureCache = api.__textureCache || new __WEBPACK_IMPORTED_MODULE_10_zrender_lib_core_LRU___default.a(20);
  290. if (isECharts(imgValue)) {
  291. var id = imgValue.__textureid__;
  292. var textureObj = textureCache.get(prefix + id);
  293. if (!textureObj) {
  294. var surface = new __WEBPACK_IMPORTED_MODULE_12__EChartsSurface__["a" /* default */](imgValue);
  295. surface.onupdate = function () {
  296. api.getZr().refresh();
  297. };
  298. textureObj = {
  299. texture: surface.getTexture()
  300. };
  301. for (var i = 0; i < keys.length; i++) {
  302. textureObj.texture[keys[i]] = textureOpts[keys[i]];
  303. }
  304. id = imgValue.__textureid__ || '__ecgl_ec__' + textureObj.texture.__uid__;
  305. imgValue.__textureid__ = id;
  306. textureCache.put(prefix + id, textureObj);
  307. cb && cb(textureObj.texture);
  308. }
  309. else {
  310. textureObj.texture.surface.setECharts(imgValue);
  311. cb && cb(textureObj.texture);
  312. }
  313. return textureObj.texture;
  314. }
  315. else if (isValueImage(imgValue)) {
  316. var id = imgValue.__textureid__;
  317. var textureObj = textureCache.get(prefix + id);
  318. if (!textureObj) {
  319. textureObj = {
  320. texture: new graphicGL.Texture2D({
  321. image: imgValue
  322. })
  323. };
  324. for (var i = 0; i < keys.length; i++) {
  325. textureObj.texture[keys[i]] = textureOpts[keys[i]];
  326. }
  327. id = imgValue.__textureid__ || '__ecgl_image__' + textureObj.texture.__uid__;
  328. imgValue.__textureid__ = id;
  329. textureCache.put(prefix + id, textureObj);
  330. convertTextureToPowerOfTwo(textureObj.texture);
  331. // TODO Next tick?
  332. cb && cb(textureObj.texture);
  333. }
  334. return textureObj.texture;
  335. }
  336. else {
  337. var textureObj = textureCache.get(prefix + imgValue);
  338. if (textureObj) {
  339. if (textureObj.callbacks) {
  340. // Add to pending callbacks
  341. textureObj.callbacks.push(cb);
  342. }
  343. else {
  344. // TODO Next tick?
  345. cb && cb(textureObj.texture);
  346. }
  347. }
  348. else {
  349. // Maybe base64
  350. if (imgValue.match(/.hdr$|^data:application\/octet-stream/)) {
  351. textureObj = {
  352. callbacks: [cb]
  353. };
  354. var texture = __WEBPACK_IMPORTED_MODULE_11_claygl_src_util_texture__["a" /* default */].loadTexture(imgValue, {
  355. exposure: textureOpts.exposure,
  356. fileType: 'hdr'
  357. }, function () {
  358. texture.dirty();
  359. textureObj.callbacks.forEach(function (cb) {
  360. cb && cb(texture);
  361. });
  362. textureObj.callbacks = null;
  363. });
  364. textureObj.texture = texture;
  365. textureCache.put(prefix + imgValue, textureObj);
  366. }
  367. else {
  368. var texture = new graphicGL.Texture2D({
  369. image: new Image()
  370. });
  371. for (var i = 0; i < keys.length; i++) {
  372. texture[keys[i]] = textureOpts[keys[i]];
  373. }
  374. textureObj = {
  375. texture: texture,
  376. callbacks: [cb]
  377. };
  378. var originalImage = texture.image;
  379. originalImage.onload = function () {
  380. texture.image = originalImage;
  381. convertTextureToPowerOfTwo(texture);
  382. texture.dirty();
  383. textureObj.callbacks.forEach(function (cb) {
  384. cb && cb(texture);
  385. });
  386. textureObj.callbacks = null;
  387. };
  388. originalImage.src = imgValue;
  389. // Use blank image as place holder.
  390. texture.image = blankImage;
  391. textureCache.put(prefix + imgValue, textureObj);
  392. }
  393. }
  394. return textureObj.texture;
  395. }
  396. };
  397. /**
  398. * Create ambientCubemap and ambientSH light. respectively to have specular and diffuse light
  399. * @return {Object} { specular, diffuse }
  400. */
  401. graphicGL.createAmbientCubemap = function (opt, renderer, api, cb) {
  402. opt = opt || {};
  403. var textureUrl = opt.texture;
  404. var exposure = __WEBPACK_IMPORTED_MODULE_16__retrieve__["a" /* default */].firstNotNull(opt.exposure, 1.0);
  405. var ambientCubemap = new __WEBPACK_IMPORTED_MODULE_13_claygl_src_light_AmbientCubemap__["a" /* default */]({
  406. intensity: __WEBPACK_IMPORTED_MODULE_16__retrieve__["a" /* default */].firstNotNull(opt.specularIntensity, 1.0)
  407. });
  408. var ambientSH = new __WEBPACK_IMPORTED_MODULE_14_claygl_src_light_AmbientSH__["a" /* default */]({
  409. intensity: __WEBPACK_IMPORTED_MODULE_16__retrieve__["a" /* default */].firstNotNull(opt.diffuseIntensity, 1.0),
  410. coefficients: [0.844, 0.712, 0.691, -0.037, 0.083, 0.167, 0.343, 0.288, 0.299, -0.041, -0.021, -0.009, -0.003, -0.041, -0.064, -0.011, -0.007, -0.004, -0.031, 0.034, 0.081, -0.060, -0.049, -0.060, 0.046, 0.056, 0.050]
  411. });
  412. ambientCubemap.cubemap = graphicGL.loadTexture(textureUrl, api, {
  413. exposure: exposure
  414. }, function () {
  415. // TODO Performance when multiple view
  416. ambientCubemap.cubemap.flipY = false;
  417. if (true) {
  418. var time = Date.now();
  419. }
  420. ambientCubemap.prefilter(renderer, 32);
  421. if (true) {
  422. var dTime = Date.now() - time;
  423. console.log('Prefilter environment map: ' + dTime + 'ms');
  424. }
  425. ambientSH.coefficients = __WEBPACK_IMPORTED_MODULE_15_claygl_src_util_sh__["a" /* default */].projectEnvironmentMap(renderer, ambientCubemap.cubemap, {
  426. lod: 1
  427. });
  428. cb && cb();
  429. // TODO Refresh ?
  430. });
  431. return {
  432. specular: ambientCubemap,
  433. diffuse: ambientSH
  434. };
  435. };
  436. /**
  437. * Create a blank texture for placeholder
  438. */
  439. graphicGL.createBlankTexture = __WEBPACK_IMPORTED_MODULE_11_claygl_src_util_texture__["a" /* default */].createBlank;
  440. /**
  441. * If value is image
  442. * @param {*}
  443. * @return {boolean}
  444. */
  445. graphicGL.isImage = isValueImage;
  446. graphicGL.additiveBlend = function (gl) {
  447. gl.blendEquation(gl.FUNC_ADD);
  448. gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
  449. };
  450. /**
  451. * @param {string|Array.<number>} colorStr
  452. * @param {Array.<number>} [rgba]
  453. * @return {Array.<number>} rgba
  454. */
  455. graphicGL.parseColor = function (colorStr, rgba) {
  456. if (colorStr instanceof Array) {
  457. if (!rgba) {
  458. rgba = [];
  459. }
  460. // Color has been parsed.
  461. rgba[0] = colorStr[0];
  462. rgba[1] = colorStr[1];
  463. rgba[2] = colorStr[2];
  464. if (colorStr.length > 3) {
  465. rgba[3] = colorStr[3];
  466. }
  467. else {
  468. rgba[3] = 1;
  469. }
  470. return rgba;
  471. }
  472. rgba = __WEBPACK_IMPORTED_MODULE_8_echarts_lib_echarts___default.a.color.parse(colorStr || '#000', rgba) || [0, 0, 0, 0];
  473. rgba[0] /= 255;
  474. rgba[1] /= 255;
  475. rgba[2] /= 255;
  476. return rgba;
  477. };
  478. /**
  479. * Convert alpha beta rotation to direction.
  480. * @param {number} alpha
  481. * @param {number} beta
  482. * @return {Array.<number>}
  483. */
  484. graphicGL.directionFromAlphaBeta = function (alpha, beta) {
  485. var theta = alpha / 180 * Math.PI + Math.PI / 2;
  486. var phi = -beta / 180 * Math.PI + Math.PI / 2;
  487. var dir = [];
  488. var r = Math.sin(theta);
  489. dir[0] = r * Math.cos(phi);
  490. dir[1] = -Math.cos(theta);
  491. dir[2] = r * Math.sin(phi);
  492. return dir;
  493. };
  494. /**
  495. * Get shadow resolution from shadowQuality configuration
  496. */
  497. graphicGL.getShadowResolution = function (shadowQuality) {
  498. var shadowResolution = 1024;
  499. switch (shadowQuality) {
  500. case 'low':
  501. shadowResolution = 512;
  502. break;
  503. case 'medium':
  504. break;
  505. case 'high':
  506. shadowResolution = 2048;
  507. break;
  508. case 'ultra':
  509. shadowResolution = 4096;
  510. break;
  511. }
  512. return shadowResolution;
  513. };
  514. /**
  515. * Shading utilities
  516. */
  517. graphicGL.COMMON_SHADERS = ['lambert', 'color', 'realistic', 'hatching'];
  518. /**
  519. * Create shader including vertex and fragment
  520. * @param {string} prefix.
  521. */
  522. graphicGL.createShader = function (prefix) {
  523. var vertexShaderStr = __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].source(prefix + '.vertex');
  524. var fragmentShaderStr = __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].source(prefix + '.fragment');
  525. if (!vertexShaderStr) {
  526. console.error('Vertex shader of \'%s\' not exits', prefix);
  527. }
  528. if (!fragmentShaderStr) {
  529. console.error('Fragment shader of \'%s\' not exits', prefix);
  530. }
  531. var shader = new __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */](vertexShaderStr, fragmentShaderStr);
  532. shader.name = prefix;
  533. return shader;
  534. };
  535. graphicGL.createMaterial = function (prefix, defines) {
  536. if (!(defines instanceof Array)) {
  537. defines = [defines];
  538. }
  539. var shader = graphicGL.createShader(prefix);
  540. var material = new __WEBPACK_IMPORTED_MODULE_5_claygl_src_Material__["a" /* default */]({
  541. shader: shader
  542. });
  543. defines.forEach(function (defineName) {
  544. if (typeof defineName === 'string') {
  545. material.define(defineName);
  546. }
  547. });
  548. return material;
  549. };
  550. /**
  551. * Set material from model.
  552. * @param {clay.Material} material
  553. * @param {module:echarts/model/Model} model
  554. * @param {module:echarts/ExtensionAPI} api
  555. */
  556. graphicGL.setMaterialFromModel = function (shading, material, model, api) {
  557. material.autoUpdateTextureStatus = false;
  558. var materialModel = model.getModel(shading + 'Material');
  559. var detailTexture = materialModel.get('detailTexture');
  560. var uvRepeat = __WEBPACK_IMPORTED_MODULE_16__retrieve__["a" /* default */].firstNotNull(materialModel.get('textureTiling'), 1.0);
  561. var uvOffset = __WEBPACK_IMPORTED_MODULE_16__retrieve__["a" /* default */].firstNotNull(materialModel.get('textureOffset'), 0.0);
  562. if (typeof uvRepeat === 'number') {
  563. uvRepeat = [uvRepeat, uvRepeat];
  564. }
  565. if (typeof uvOffset === 'number') {
  566. uvOffset = [uvOffset, uvOffset];
  567. }
  568. var repeatParam = (uvRepeat[0] > 1 || uvRepeat[1] > 1) ? graphicGL.Texture.REPEAT : graphicGL.Texture.CLAMP_TO_EDGE;
  569. var textureOpt = {
  570. anisotropic: 8,
  571. wrapS: repeatParam,
  572. wrapT: repeatParam
  573. };
  574. if (shading === 'realistic') {
  575. var roughness = materialModel.get('roughness');
  576. var metalness = materialModel.get('metalness');
  577. if (metalness != null) {
  578. // Try to treat as a texture, TODO More check
  579. if (isNaN(metalness)) {
  580. material.setTextureImage('metalnessMap', metalness, api, textureOpt);
  581. metalness = __WEBPACK_IMPORTED_MODULE_16__retrieve__["a" /* default */].firstNotNull(materialModel.get('metalnessAdjust'), 0.5);
  582. }
  583. }
  584. else {
  585. // Default metalness.
  586. metalness = 0;
  587. }
  588. if (roughness != null) {
  589. // Try to treat as a texture, TODO More check
  590. if (isNaN(roughness)) {
  591. material.setTextureImage('roughnessMap', roughness, api, textureOpt);
  592. roughness = __WEBPACK_IMPORTED_MODULE_16__retrieve__["a" /* default */].firstNotNull(materialModel.get('roughnessAdjust'), 0.5);
  593. }
  594. }
  595. else {
  596. // Default roughness.
  597. roughness = 0.5;
  598. }
  599. var normalTextureVal = materialModel.get('normalTexture');
  600. material.setTextureImage('detailMap', detailTexture, api, textureOpt);
  601. material.setTextureImage('normalMap', normalTextureVal, api, textureOpt);
  602. material.set({
  603. roughness: roughness,
  604. metalness: metalness,
  605. detailUvRepeat: uvRepeat,
  606. detailUvOffset: uvOffset
  607. });
  608. // var normalTexture = material.get('normalMap');
  609. // if (normalTexture) {
  610. // PENDING
  611. // normalTexture.format = Texture.SRGB;
  612. // }
  613. }
  614. else if (shading === 'lambert') {
  615. material.setTextureImage('detailMap', detailTexture, api, textureOpt);
  616. material.set({
  617. detailUvRepeat: uvRepeat,
  618. detailUvOffset: uvOffset
  619. });
  620. }
  621. else if (shading === 'color') {
  622. material.setTextureImage('detailMap', detailTexture, api, textureOpt);
  623. material.set({
  624. detailUvRepeat: uvRepeat,
  625. detailUvOffset: uvOffset
  626. });
  627. }
  628. else if (shading === 'hatching') {
  629. var tams = materialModel.get('hatchingTextures') || [];
  630. if (tams.length < 6) {
  631. if (true) {
  632. console.error('Invalid hatchingTextures.');
  633. }
  634. }
  635. for (var i = 0; i < 6; i++) {
  636. material.setTextureImage('hatch' + (i + 1), tams[i], api, {
  637. anisotropic: 8,
  638. wrapS: graphicGL.Texture.REPEAT,
  639. wrapT: graphicGL.Texture.REPEAT
  640. });
  641. }
  642. material.set({
  643. detailUvRepeat: uvRepeat,
  644. detailUvOffset: uvOffset
  645. });
  646. }
  647. };
  648. graphicGL.updateVertexAnimation = function (
  649. mappingAttributes, previousMesh, currentMesh, seriesModel
  650. ) {
  651. var enableAnimation = seriesModel.get('animation');
  652. var duration = seriesModel.get('animationDurationUpdate');
  653. var easing = seriesModel.get('animationEasingUpdate');
  654. var shadowDepthMaterial = currentMesh.shadowDepthMaterial;
  655. if (enableAnimation && previousMesh && duration > 0
  656. // Only animate when bar count are not changed
  657. && previousMesh.geometry.vertexCount === currentMesh.geometry.vertexCount
  658. ) {
  659. currentMesh.material.define('vertex', 'VERTEX_ANIMATION');
  660. currentMesh.ignorePreZ = true;
  661. if (shadowDepthMaterial) {
  662. shadowDepthMaterial.define('vertex', 'VERTEX_ANIMATION');
  663. }
  664. for (var i = 0; i < mappingAttributes.length; i++) {
  665. currentMesh.geometry.attributes[mappingAttributes[i][0]].value =
  666. previousMesh.geometry.attributes[mappingAttributes[i][1]].value;
  667. }
  668. currentMesh.geometry.dirty();
  669. currentMesh.__percent = 0;
  670. currentMesh.material.set('percent', 0);
  671. currentMesh.stopAnimation();
  672. currentMesh.animate()
  673. .when(duration, {
  674. __percent: 1
  675. })
  676. .during(function () {
  677. currentMesh.material.set('percent', currentMesh.__percent);
  678. if (shadowDepthMaterial) {
  679. shadowDepthMaterial.set('percent', currentMesh.__percent);
  680. }
  681. })
  682. .done(function () {
  683. currentMesh.ignorePreZ = false;
  684. currentMesh.material.undefine('vertex', 'VERTEX_ANIMATION');
  685. if (shadowDepthMaterial) {
  686. shadowDepthMaterial.undefine('vertex', 'VERTEX_ANIMATION');
  687. }
  688. })
  689. .start(easing);
  690. }
  691. else {
  692. currentMesh.material.undefine('vertex', 'VERTEX_ANIMATION');
  693. if (shadowDepthMaterial) {
  694. shadowDepthMaterial.undefine('vertex', 'VERTEX_ANIMATION');
  695. }
  696. }
  697. };
  698. /* harmony default export */ __webpack_exports__["a"] = (graphicGL);
  699. /***/
  700. }),
  701. /* 2 */
  702. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  703. "use strict";
  704. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  705. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  706. var retrieve = {
  707. firstNotNull: function () {
  708. for (var i = 0, len = arguments.length; i < len; i++) {
  709. if (arguments[i] != null) {
  710. return arguments[i];
  711. }
  712. }
  713. },
  714. /**
  715. * @param {module:echarts/data/List} data
  716. * @param {Object} payload Contains dataIndex (means rawIndex) / dataIndexInside / name
  717. * each of which can be Array or primary type.
  718. * @return {number|Array.<number>} dataIndex If not found, return undefined/null.
  719. */
  720. queryDataIndex: function (data, payload) {
  721. if (payload.dataIndexInside != null) {
  722. return payload.dataIndexInside;
  723. }
  724. else if (payload.dataIndex != null) {
  725. return __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.isArray(payload.dataIndex)
  726. ? __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.map(payload.dataIndex, function (value) {
  727. return data.indexOfRawIndex(value);
  728. })
  729. : data.indexOfRawIndex(payload.dataIndex);
  730. }
  731. else if (payload.name != null) {
  732. return __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.isArray(payload.name)
  733. ? __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.map(payload.name, function (value) {
  734. return data.indexOfName(value);
  735. })
  736. : data.indexOfName(payload.name);
  737. }
  738. }
  739. };
  740. /* harmony default export */ __webpack_exports__["a"] = (retrieve);
  741. /***/
  742. }),
  743. /* 3 */
  744. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  745. "use strict";
  746. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__ = __webpack_require__(12);
  747. /**
  748. * @constructor
  749. * @alias clay.Vector3
  750. * @param {number} x
  751. * @param {number} y
  752. * @param {number} z
  753. */
  754. var Vector3 = function (x, y, z) {
  755. x = x || 0;
  756. y = y || 0;
  757. z = z || 0;
  758. /**
  759. * Storage of Vector3, read and write of x, y, z will change the values in array
  760. * All methods also operate on the array instead of x, y, z components
  761. * @name array
  762. * @type {Float32Array}
  763. * @memberOf clay.Vector3#
  764. */
  765. this.array = __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].fromValues(x, y, z);
  766. /**
  767. * Dirty flag is used by the Node to determine
  768. * if the matrix is updated to latest
  769. * @name _dirty
  770. * @type {boolean}
  771. * @memberOf clay.Vector3#
  772. */
  773. this._dirty = true;
  774. };
  775. Vector3.prototype = {
  776. constructor: Vector3,
  777. /**
  778. * Add b to self
  779. * @param {clay.Vector3} b
  780. * @return {clay.Vector3}
  781. */
  782. add: function (b) {
  783. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].add(this.array, this.array, b.array);
  784. this._dirty = true;
  785. return this;
  786. },
  787. /**
  788. * Set x, y and z components
  789. * @param {number} x
  790. * @param {number} y
  791. * @param {number} z
  792. * @return {clay.Vector3}
  793. */
  794. set: function (x, y, z) {
  795. this.array[0] = x;
  796. this.array[1] = y;
  797. this.array[2] = z;
  798. this._dirty = true;
  799. return this;
  800. },
  801. /**
  802. * Set x, y and z components from array
  803. * @param {Float32Array|number[]} arr
  804. * @return {clay.Vector3}
  805. */
  806. setArray: function (arr) {
  807. this.array[0] = arr[0];
  808. this.array[1] = arr[1];
  809. this.array[2] = arr[2];
  810. this._dirty = true;
  811. return this;
  812. },
  813. /**
  814. * Clone a new Vector3
  815. * @return {clay.Vector3}
  816. */
  817. clone: function () {
  818. return new Vector3(this.x, this.y, this.z);
  819. },
  820. /**
  821. * Copy from b
  822. * @param {clay.Vector3} b
  823. * @return {clay.Vector3}
  824. */
  825. copy: function (b) {
  826. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].copy(this.array, b.array);
  827. this._dirty = true;
  828. return this;
  829. },
  830. /**
  831. * Cross product of self and b, written to a Vector3 out
  832. * @param {clay.Vector3} a
  833. * @param {clay.Vector3} b
  834. * @return {clay.Vector3}
  835. */
  836. cross: function (a, b) {
  837. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].cross(this.array, a.array, b.array);
  838. this._dirty = true;
  839. return this;
  840. },
  841. /**
  842. * Alias for distance
  843. * @param {clay.Vector3} b
  844. * @return {number}
  845. */
  846. dist: function (b) {
  847. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].dist(this.array, b.array);
  848. },
  849. /**
  850. * Distance between self and b
  851. * @param {clay.Vector3} b
  852. * @return {number}
  853. */
  854. distance: function (b) {
  855. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].distance(this.array, b.array);
  856. },
  857. /**
  858. * Alias for divide
  859. * @param {clay.Vector3} b
  860. * @return {clay.Vector3}
  861. */
  862. div: function (b) {
  863. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].div(this.array, this.array, b.array);
  864. this._dirty = true;
  865. return this;
  866. },
  867. /**
  868. * Divide self by b
  869. * @param {clay.Vector3} b
  870. * @return {clay.Vector3}
  871. */
  872. divide: function (b) {
  873. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].divide(this.array, this.array, b.array);
  874. this._dirty = true;
  875. return this;
  876. },
  877. /**
  878. * Dot product of self and b
  879. * @param {clay.Vector3} b
  880. * @return {number}
  881. */
  882. dot: function (b) {
  883. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].dot(this.array, b.array);
  884. },
  885. /**
  886. * Alias of length
  887. * @return {number}
  888. */
  889. len: function () {
  890. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].len(this.array);
  891. },
  892. /**
  893. * Calculate the length
  894. * @return {number}
  895. */
  896. length: function () {
  897. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].length(this.array);
  898. },
  899. /**
  900. * Linear interpolation between a and b
  901. * @param {clay.Vector3} a
  902. * @param {clay.Vector3} b
  903. * @param {number} t
  904. * @return {clay.Vector3}
  905. */
  906. lerp: function (a, b, t) {
  907. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].lerp(this.array, a.array, b.array, t);
  908. this._dirty = true;
  909. return this;
  910. },
  911. /**
  912. * Minimum of self and b
  913. * @param {clay.Vector3} b
  914. * @return {clay.Vector3}
  915. */
  916. min: function (b) {
  917. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].min(this.array, this.array, b.array);
  918. this._dirty = true;
  919. return this;
  920. },
  921. /**
  922. * Maximum of self and b
  923. * @param {clay.Vector3} b
  924. * @return {clay.Vector3}
  925. */
  926. max: function (b) {
  927. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].max(this.array, this.array, b.array);
  928. this._dirty = true;
  929. return this;
  930. },
  931. /**
  932. * Alias for multiply
  933. * @param {clay.Vector3} b
  934. * @return {clay.Vector3}
  935. */
  936. mul: function (b) {
  937. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].mul(this.array, this.array, b.array);
  938. this._dirty = true;
  939. return this;
  940. },
  941. /**
  942. * Mutiply self and b
  943. * @param {clay.Vector3} b
  944. * @return {clay.Vector3}
  945. */
  946. multiply: function (b) {
  947. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].multiply(this.array, this.array, b.array);
  948. this._dirty = true;
  949. return this;
  950. },
  951. /**
  952. * Negate self
  953. * @return {clay.Vector3}
  954. */
  955. negate: function () {
  956. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].negate(this.array, this.array);
  957. this._dirty = true;
  958. return this;
  959. },
  960. /**
  961. * Normalize self
  962. * @return {clay.Vector3}
  963. */
  964. normalize: function () {
  965. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].normalize(this.array, this.array);
  966. this._dirty = true;
  967. return this;
  968. },
  969. /**
  970. * Generate random x, y, z components with a given scale
  971. * @param {number} scale
  972. * @return {clay.Vector3}
  973. */
  974. random: function (scale) {
  975. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].random(this.array, scale);
  976. this._dirty = true;
  977. return this;
  978. },
  979. /**
  980. * Scale self
  981. * @param {number} scale
  982. * @return {clay.Vector3}
  983. */
  984. scale: function (s) {
  985. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].scale(this.array, this.array, s);
  986. this._dirty = true;
  987. return this;
  988. },
  989. /**
  990. * Scale b and add to self
  991. * @param {clay.Vector3} b
  992. * @param {number} scale
  993. * @return {clay.Vector3}
  994. */
  995. scaleAndAdd: function (b, s) {
  996. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].scaleAndAdd(this.array, this.array, b.array, s);
  997. this._dirty = true;
  998. return this;
  999. },
  1000. /**
  1001. * Alias for squaredDistance
  1002. * @param {clay.Vector3} b
  1003. * @return {number}
  1004. */
  1005. sqrDist: function (b) {
  1006. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].sqrDist(this.array, b.array);
  1007. },
  1008. /**
  1009. * Squared distance between self and b
  1010. * @param {clay.Vector3} b
  1011. * @return {number}
  1012. */
  1013. squaredDistance: function (b) {
  1014. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].squaredDistance(this.array, b.array);
  1015. },
  1016. /**
  1017. * Alias for squaredLength
  1018. * @return {number}
  1019. */
  1020. sqrLen: function () {
  1021. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].sqrLen(this.array);
  1022. },
  1023. /**
  1024. * Squared length of self
  1025. * @return {number}
  1026. */
  1027. squaredLength: function () {
  1028. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].squaredLength(this.array);
  1029. },
  1030. /**
  1031. * Alias for subtract
  1032. * @param {clay.Vector3} b
  1033. * @return {clay.Vector3}
  1034. */
  1035. sub: function (b) {
  1036. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].sub(this.array, this.array, b.array);
  1037. this._dirty = true;
  1038. return this;
  1039. },
  1040. /**
  1041. * Subtract b from self
  1042. * @param {clay.Vector3} b
  1043. * @return {clay.Vector3}
  1044. */
  1045. subtract: function (b) {
  1046. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].subtract(this.array, this.array, b.array);
  1047. this._dirty = true;
  1048. return this;
  1049. },
  1050. /**
  1051. * Transform self with a Matrix3 m
  1052. * @param {clay.Matrix3} m
  1053. * @return {clay.Vector3}
  1054. */
  1055. transformMat3: function (m) {
  1056. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].transformMat3(this.array, this.array, m.array);
  1057. this._dirty = true;
  1058. return this;
  1059. },
  1060. /**
  1061. * Transform self with a Matrix4 m
  1062. * @param {clay.Matrix4} m
  1063. * @return {clay.Vector3}
  1064. */
  1065. transformMat4: function (m) {
  1066. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].transformMat4(this.array, this.array, m.array);
  1067. this._dirty = true;
  1068. return this;
  1069. },
  1070. /**
  1071. * Transform self with a Quaternion q
  1072. * @param {clay.Quaternion} q
  1073. * @return {clay.Vector3}
  1074. */
  1075. transformQuat: function (q) {
  1076. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].transformQuat(this.array, this.array, q.array);
  1077. this._dirty = true;
  1078. return this;
  1079. },
  1080. /**
  1081. * Trasnform self into projection space with m
  1082. * @param {clay.Matrix4} m
  1083. * @return {clay.Vector3}
  1084. */
  1085. applyProjection: function (m) {
  1086. var v = this.array;
  1087. m = m.array;
  1088. // Perspective projection
  1089. if (m[15] === 0) {
  1090. var w = -1 / v[2];
  1091. v[0] = m[0] * v[0] * w;
  1092. v[1] = m[5] * v[1] * w;
  1093. v[2] = (m[10] * v[2] + m[14]) * w;
  1094. }
  1095. else {
  1096. v[0] = m[0] * v[0] + m[12];
  1097. v[1] = m[5] * v[1] + m[13];
  1098. v[2] = m[10] * v[2] + m[14];
  1099. }
  1100. this._dirty = true;
  1101. return this;
  1102. },
  1103. eulerFromQuat: function (q, order) {
  1104. Vector3.eulerFromQuat(this, q, order);
  1105. },
  1106. eulerFromMat3: function (m, order) {
  1107. Vector3.eulerFromMat3(this, m, order);
  1108. },
  1109. toString: function () {
  1110. return '[' + Array.prototype.join.call(this.array, ',') + ']';
  1111. },
  1112. toArray: function () {
  1113. return Array.prototype.slice.call(this.array);
  1114. }
  1115. };
  1116. var defineProperty = Object.defineProperty;
  1117. // Getter and Setter
  1118. if (defineProperty) {
  1119. var proto = Vector3.prototype;
  1120. /**
  1121. * @name x
  1122. * @type {number}
  1123. * @memberOf clay.Vector3
  1124. * @instance
  1125. */
  1126. defineProperty(proto, 'x', {
  1127. get: function () {
  1128. return this.array[0];
  1129. },
  1130. set: function (value) {
  1131. this.array[0] = value;
  1132. this._dirty = true;
  1133. }
  1134. });
  1135. /**
  1136. * @name y
  1137. * @type {number}
  1138. * @memberOf clay.Vector3
  1139. * @instance
  1140. */
  1141. defineProperty(proto, 'y', {
  1142. get: function () {
  1143. return this.array[1];
  1144. },
  1145. set: function (value) {
  1146. this.array[1] = value;
  1147. this._dirty = true;
  1148. }
  1149. });
  1150. /**
  1151. * @name z
  1152. * @type {number}
  1153. * @memberOf clay.Vector3
  1154. * @instance
  1155. */
  1156. defineProperty(proto, 'z', {
  1157. get: function () {
  1158. return this.array[2];
  1159. },
  1160. set: function (value) {
  1161. this.array[2] = value;
  1162. this._dirty = true;
  1163. }
  1164. });
  1165. }
  1166. // Supply methods that are not in place
  1167. /**
  1168. * @param {clay.Vector3} out
  1169. * @param {clay.Vector3} a
  1170. * @param {clay.Vector3} b
  1171. * @return {clay.Vector3}
  1172. */
  1173. Vector3.add = function (out, a, b) {
  1174. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].add(out.array, a.array, b.array);
  1175. out._dirty = true;
  1176. return out;
  1177. };
  1178. /**
  1179. * @param {clay.Vector3} out
  1180. * @param {number} x
  1181. * @param {number} y
  1182. * @param {number} z
  1183. * @return {clay.Vector3}
  1184. */
  1185. Vector3.set = function (out, x, y, z) {
  1186. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].set(out.array, x, y, z);
  1187. out._dirty = true;
  1188. };
  1189. /**
  1190. * @param {clay.Vector3} out
  1191. * @param {clay.Vector3} b
  1192. * @return {clay.Vector3}
  1193. */
  1194. Vector3.copy = function (out, b) {
  1195. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].copy(out.array, b.array);
  1196. out._dirty = true;
  1197. return out;
  1198. };
  1199. /**
  1200. * @param {clay.Vector3} out
  1201. * @param {clay.Vector3} a
  1202. * @param {clay.Vector3} b
  1203. * @return {clay.Vector3}
  1204. */
  1205. Vector3.cross = function (out, a, b) {
  1206. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].cross(out.array, a.array, b.array);
  1207. out._dirty = true;
  1208. return out;
  1209. };
  1210. /**
  1211. * @param {clay.Vector3} a
  1212. * @param {clay.Vector3} b
  1213. * @return {number}
  1214. */
  1215. Vector3.dist = function (a, b) {
  1216. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].distance(a.array, b.array);
  1217. };
  1218. /**
  1219. * @function
  1220. * @param {clay.Vector3} a
  1221. * @param {clay.Vector3} b
  1222. * @return {number}
  1223. */
  1224. Vector3.distance = Vector3.dist;
  1225. /**
  1226. * @param {clay.Vector3} out
  1227. * @param {clay.Vector3} a
  1228. * @param {clay.Vector3} b
  1229. * @return {clay.Vector3}
  1230. */
  1231. Vector3.div = function (out, a, b) {
  1232. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].divide(out.array, a.array, b.array);
  1233. out._dirty = true;
  1234. return out;
  1235. };
  1236. /**
  1237. * @function
  1238. * @param {clay.Vector3} out
  1239. * @param {clay.Vector3} a
  1240. * @param {clay.Vector3} b
  1241. * @return {clay.Vector3}
  1242. */
  1243. Vector3.divide = Vector3.div;
  1244. /**
  1245. * @param {clay.Vector3} a
  1246. * @param {clay.Vector3} b
  1247. * @return {number}
  1248. */
  1249. Vector3.dot = function (a, b) {
  1250. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].dot(a.array, b.array);
  1251. };
  1252. /**
  1253. * @param {clay.Vector3} a
  1254. * @return {number}
  1255. */
  1256. Vector3.len = function (b) {
  1257. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].length(b.array);
  1258. };
  1259. // Vector3.length = Vector3.len;
  1260. /**
  1261. * @param {clay.Vector3} out
  1262. * @param {clay.Vector3} a
  1263. * @param {clay.Vector3} b
  1264. * @param {number} t
  1265. * @return {clay.Vector3}
  1266. */
  1267. Vector3.lerp = function (out, a, b, t) {
  1268. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].lerp(out.array, a.array, b.array, t);
  1269. out._dirty = true;
  1270. return out;
  1271. };
  1272. /**
  1273. * @param {clay.Vector3} out
  1274. * @param {clay.Vector3} a
  1275. * @param {clay.Vector3} b
  1276. * @return {clay.Vector3}
  1277. */
  1278. Vector3.min = function (out, a, b) {
  1279. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].min(out.array, a.array, b.array);
  1280. out._dirty = true;
  1281. return out;
  1282. };
  1283. /**
  1284. * @param {clay.Vector3} out
  1285. * @param {clay.Vector3} a
  1286. * @param {clay.Vector3} b
  1287. * @return {clay.Vector3}
  1288. */
  1289. Vector3.max = function (out, a, b) {
  1290. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].max(out.array, a.array, b.array);
  1291. out._dirty = true;
  1292. return out;
  1293. };
  1294. /**
  1295. * @param {clay.Vector3} out
  1296. * @param {clay.Vector3} a
  1297. * @param {clay.Vector3} b
  1298. * @return {clay.Vector3}
  1299. */
  1300. Vector3.mul = function (out, a, b) {
  1301. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].multiply(out.array, a.array, b.array);
  1302. out._dirty = true;
  1303. return out;
  1304. };
  1305. /**
  1306. * @function
  1307. * @param {clay.Vector3} out
  1308. * @param {clay.Vector3} a
  1309. * @param {clay.Vector3} b
  1310. * @return {clay.Vector3}
  1311. */
  1312. Vector3.multiply = Vector3.mul;
  1313. /**
  1314. * @param {clay.Vector3} out
  1315. * @param {clay.Vector3} a
  1316. * @return {clay.Vector3}
  1317. */
  1318. Vector3.negate = function (out, a) {
  1319. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].negate(out.array, a.array);
  1320. out._dirty = true;
  1321. return out;
  1322. };
  1323. /**
  1324. * @param {clay.Vector3} out
  1325. * @param {clay.Vector3} a
  1326. * @return {clay.Vector3}
  1327. */
  1328. Vector3.normalize = function (out, a) {
  1329. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].normalize(out.array, a.array);
  1330. out._dirty = true;
  1331. return out;
  1332. };
  1333. /**
  1334. * @param {clay.Vector3} out
  1335. * @param {number} scale
  1336. * @return {clay.Vector3}
  1337. */
  1338. Vector3.random = function (out, scale) {
  1339. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].random(out.array, scale);
  1340. out._dirty = true;
  1341. return out;
  1342. };
  1343. /**
  1344. * @param {clay.Vector3} out
  1345. * @param {clay.Vector3} a
  1346. * @param {number} scale
  1347. * @return {clay.Vector3}
  1348. */
  1349. Vector3.scale = function (out, a, scale) {
  1350. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].scale(out.array, a.array, scale);
  1351. out._dirty = true;
  1352. return out;
  1353. };
  1354. /**
  1355. * @param {clay.Vector3} out
  1356. * @param {clay.Vector3} a
  1357. * @param {clay.Vector3} b
  1358. * @param {number} scale
  1359. * @return {clay.Vector3}
  1360. */
  1361. Vector3.scaleAndAdd = function (out, a, b, scale) {
  1362. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].scaleAndAdd(out.array, a.array, b.array, scale);
  1363. out._dirty = true;
  1364. return out;
  1365. };
  1366. /**
  1367. * @param {clay.Vector3} a
  1368. * @param {clay.Vector3} b
  1369. * @return {number}
  1370. */
  1371. Vector3.sqrDist = function (a, b) {
  1372. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].sqrDist(a.array, b.array);
  1373. };
  1374. /**
  1375. * @function
  1376. * @param {clay.Vector3} a
  1377. * @param {clay.Vector3} b
  1378. * @return {number}
  1379. */
  1380. Vector3.squaredDistance = Vector3.sqrDist;
  1381. /**
  1382. * @param {clay.Vector3} a
  1383. * @return {number}
  1384. */
  1385. Vector3.sqrLen = function (a) {
  1386. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].sqrLen(a.array);
  1387. };
  1388. /**
  1389. * @function
  1390. * @param {clay.Vector3} a
  1391. * @return {number}
  1392. */
  1393. Vector3.squaredLength = Vector3.sqrLen;
  1394. /**
  1395. * @param {clay.Vector3} out
  1396. * @param {clay.Vector3} a
  1397. * @param {clay.Vector3} b
  1398. * @return {clay.Vector3}
  1399. */
  1400. Vector3.sub = function (out, a, b) {
  1401. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].subtract(out.array, a.array, b.array);
  1402. out._dirty = true;
  1403. return out;
  1404. };
  1405. /**
  1406. * @function
  1407. * @param {clay.Vector3} out
  1408. * @param {clay.Vector3} a
  1409. * @param {clay.Vector3} b
  1410. * @return {clay.Vector3}
  1411. */
  1412. Vector3.subtract = Vector3.sub;
  1413. /**
  1414. * @param {clay.Vector3} out
  1415. * @param {clay.Vector3} a
  1416. * @param {Matrix3} m
  1417. * @return {clay.Vector3}
  1418. */
  1419. Vector3.transformMat3 = function (out, a, m) {
  1420. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].transformMat3(out.array, a.array, m.array);
  1421. out._dirty = true;
  1422. return out;
  1423. };
  1424. /**
  1425. * @param {clay.Vector3} out
  1426. * @param {clay.Vector3} a
  1427. * @param {clay.Matrix4} m
  1428. * @return {clay.Vector3}
  1429. */
  1430. Vector3.transformMat4 = function (out, a, m) {
  1431. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].transformMat4(out.array, a.array, m.array);
  1432. out._dirty = true;
  1433. return out;
  1434. };
  1435. /**
  1436. * @param {clay.Vector3} out
  1437. * @param {clay.Vector3} a
  1438. * @param {clay.Quaternion} q
  1439. * @return {clay.Vector3}
  1440. */
  1441. Vector3.transformQuat = function (out, a, q) {
  1442. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec3__["a" /* default */].transformQuat(out.array, a.array, q.array);
  1443. out._dirty = true;
  1444. return out;
  1445. };
  1446. function clamp(val, min, max) {
  1447. return val < min ? min : (val > max ? max : val);
  1448. }
  1449. var atan2 = Math.atan2;
  1450. var asin = Math.asin;
  1451. var abs = Math.abs;
  1452. /**
  1453. * Convert quaternion to euler angle
  1454. * Quaternion must be normalized
  1455. * From three.js
  1456. */
  1457. Vector3.eulerFromQuat = function (out, q, order) {
  1458. out._dirty = true;
  1459. q = q.array;
  1460. var target = out.array;
  1461. var x = q[0], y = q[1], z = q[2], w = q[3];
  1462. var x2 = x * x;
  1463. var y2 = y * y;
  1464. var z2 = z * z;
  1465. var w2 = w * w;
  1466. var order = (order || 'XYZ').toUpperCase();
  1467. switch (order) {
  1468. case 'XYZ':
  1469. target[0] = atan2(2 * (x * w - y * z), (w2 - x2 - y2 + z2));
  1470. target[1] = asin(clamp(2 * (x * z + y * w), - 1, 1));
  1471. target[2] = atan2(2 * (z * w - x * y), (w2 + x2 - y2 - z2));
  1472. break;
  1473. case 'YXZ':
  1474. target[0] = asin(clamp(2 * (x * w - y * z), - 1, 1));
  1475. target[1] = atan2(2 * (x * z + y * w), (w2 - x2 - y2 + z2));
  1476. target[2] = atan2(2 * (x * y + z * w), (w2 - x2 + y2 - z2));
  1477. break;
  1478. case 'ZXY':
  1479. target[0] = asin(clamp(2 * (x * w + y * z), - 1, 1));
  1480. target[1] = atan2(2 * (y * w - z * x), (w2 - x2 - y2 + z2));
  1481. target[2] = atan2(2 * (z * w - x * y), (w2 - x2 + y2 - z2));
  1482. break;
  1483. case 'ZYX':
  1484. target[0] = atan2(2 * (x * w + z * y), (w2 - x2 - y2 + z2));
  1485. target[1] = asin(clamp(2 * (y * w - x * z), - 1, 1));
  1486. target[2] = atan2(2 * (x * y + z * w), (w2 + x2 - y2 - z2));
  1487. break;
  1488. case 'YZX':
  1489. target[0] = atan2(2 * (x * w - z * y), (w2 - x2 + y2 - z2));
  1490. target[1] = atan2(2 * (y * w - x * z), (w2 + x2 - y2 - z2));
  1491. target[2] = asin(clamp(2 * (x * y + z * w), - 1, 1));
  1492. break;
  1493. case 'XZY':
  1494. target[0] = atan2(2 * (x * w + y * z), (w2 - x2 + y2 - z2));
  1495. target[1] = atan2(2 * (x * z + y * w), (w2 + x2 - y2 - z2));
  1496. target[2] = asin(clamp(2 * (z * w - x * y), - 1, 1));
  1497. break;
  1498. default:
  1499. console.warn('Unkown order: ' + order);
  1500. }
  1501. return out;
  1502. };
  1503. /**
  1504. * Convert rotation matrix to euler angle
  1505. * from three.js
  1506. */
  1507. Vector3.eulerFromMat3 = function (out, m, order) {
  1508. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1509. var te = m.array;
  1510. var m11 = te[0], m12 = te[3], m13 = te[6];
  1511. var m21 = te[1], m22 = te[4], m23 = te[7];
  1512. var m31 = te[2], m32 = te[5], m33 = te[8];
  1513. var target = out.array;
  1514. var order = (order || 'XYZ').toUpperCase();
  1515. switch (order) {
  1516. case 'XYZ':
  1517. target[1] = asin(clamp(m13, -1, 1));
  1518. if (abs(m13) < 0.99999) {
  1519. target[0] = atan2(-m23, m33);
  1520. target[2] = atan2(-m12, m11);
  1521. }
  1522. else {
  1523. target[0] = atan2(m32, m22);
  1524. target[2] = 0;
  1525. }
  1526. break;
  1527. case 'YXZ':
  1528. target[0] = asin(-clamp(m23, -1, 1));
  1529. if (abs(m23) < 0.99999) {
  1530. target[1] = atan2(m13, m33);
  1531. target[2] = atan2(m21, m22);
  1532. }
  1533. else {
  1534. target[1] = atan2(-m31, m11);
  1535. target[2] = 0;
  1536. }
  1537. break;
  1538. case 'ZXY':
  1539. target[0] = asin(clamp(m32, -1, 1));
  1540. if (abs(m32) < 0.99999) {
  1541. target[1] = atan2(-m31, m33);
  1542. target[2] = atan2(-m12, m22);
  1543. }
  1544. else {
  1545. target[1] = 0;
  1546. target[2] = atan2(m21, m11);
  1547. }
  1548. break;
  1549. case 'ZYX':
  1550. target[1] = asin(-clamp(m31, -1, 1));
  1551. if (abs(m31) < 0.99999) {
  1552. target[0] = atan2(m32, m33);
  1553. target[2] = atan2(m21, m11);
  1554. }
  1555. else {
  1556. target[0] = 0;
  1557. target[2] = atan2(-m12, m22);
  1558. }
  1559. break;
  1560. case 'YZX':
  1561. target[2] = asin(clamp(m21, -1, 1));
  1562. if (abs(m21) < 0.99999) {
  1563. target[0] = atan2(-m23, m22);
  1564. target[1] = atan2(-m31, m11);
  1565. }
  1566. else {
  1567. target[0] = 0;
  1568. target[1] = atan2(m13, m33);
  1569. }
  1570. break;
  1571. case 'XZY':
  1572. target[2] = asin(-clamp(m12, -1, 1));
  1573. if (abs(m12) < 0.99999) {
  1574. target[0] = atan2(m32, m22);
  1575. target[1] = atan2(m13, m11);
  1576. }
  1577. else {
  1578. target[0] = atan2(-m23, m33);
  1579. target[1] = 0;
  1580. }
  1581. break;
  1582. default:
  1583. console.warn('Unkown order: ' + order);
  1584. }
  1585. out._dirty = true;
  1586. return out;
  1587. };
  1588. Object.defineProperties(Vector3, {
  1589. /**
  1590. * @type {clay.Vector3}
  1591. * @readOnly
  1592. * @memberOf clay.Vector3
  1593. */
  1594. POSITIVE_X: {
  1595. get: function () {
  1596. return new Vector3(1, 0, 0);
  1597. }
  1598. },
  1599. /**
  1600. * @type {clay.Vector3}
  1601. * @readOnly
  1602. * @memberOf clay.Vector3
  1603. */
  1604. NEGATIVE_X: {
  1605. get: function () {
  1606. return new Vector3(-1, 0, 0);
  1607. }
  1608. },
  1609. /**
  1610. * @type {clay.Vector3}
  1611. * @readOnly
  1612. * @memberOf clay.Vector3
  1613. */
  1614. POSITIVE_Y: {
  1615. get: function () {
  1616. return new Vector3(0, 1, 0);
  1617. }
  1618. },
  1619. /**
  1620. * @type {clay.Vector3}
  1621. * @readOnly
  1622. * @memberOf clay.Vector3
  1623. */
  1624. NEGATIVE_Y: {
  1625. get: function () {
  1626. return new Vector3(0, -1, 0);
  1627. }
  1628. },
  1629. /**
  1630. * @type {clay.Vector3}
  1631. * @readOnly
  1632. * @memberOf clay.Vector3
  1633. */
  1634. POSITIVE_Z: {
  1635. get: function () {
  1636. return new Vector3(0, 0, 1);
  1637. }
  1638. },
  1639. /**
  1640. * @type {clay.Vector3}
  1641. * @readOnly
  1642. */
  1643. NEGATIVE_Z: {
  1644. get: function () {
  1645. return new Vector3(0, 0, -1);
  1646. }
  1647. },
  1648. /**
  1649. * @type {clay.Vector3}
  1650. * @readOnly
  1651. * @memberOf clay.Vector3
  1652. */
  1653. UP: {
  1654. get: function () {
  1655. return new Vector3(0, 1, 0);
  1656. }
  1657. },
  1658. /**
  1659. * @type {clay.Vector3}
  1660. * @readOnly
  1661. * @memberOf clay.Vector3
  1662. */
  1663. ZERO: {
  1664. get: function () {
  1665. return new Vector3();
  1666. }
  1667. }
  1668. });
  1669. /* harmony default export */ __webpack_exports__["a"] = (Vector3);
  1670. /***/
  1671. }),
  1672. /* 4 */
  1673. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  1674. "use strict";
  1675. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__core_Base__ = __webpack_require__(7);
  1676. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__core_glenum__ = __webpack_require__(11);
  1677. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__core_Cache__ = __webpack_require__(57);
  1678. /**
  1679. * Base class for all textures like compressed texture, texture2d, texturecube
  1680. * TODO mapping
  1681. */
  1682. /**
  1683. * @constructor
  1684. * @alias clay.Texture
  1685. * @extends clay.core.Base
  1686. */
  1687. var Texture = __WEBPACK_IMPORTED_MODULE_0__core_Base__["a" /* default */].extend( /** @lends clay.Texture# */ {
  1688. /**
  1689. * Texture width, readonly when the texture source is image
  1690. * @type {number}
  1691. */
  1692. width: 512,
  1693. /**
  1694. * Texture height, readonly when the texture source is image
  1695. * @type {number}
  1696. */
  1697. height: 512,
  1698. /**
  1699. * Texel data type.
  1700. * Possible values:
  1701. * + {@link clay.Texture.UNSIGNED_BYTE}
  1702. * + {@link clay.Texture.HALF_FLOAT}
  1703. * + {@link clay.Texture.FLOAT}
  1704. * + {@link clay.Texture.UNSIGNED_INT_24_8_WEBGL}
  1705. * + {@link clay.Texture.UNSIGNED_INT}
  1706. * @type {number}
  1707. */
  1708. type: __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].UNSIGNED_BYTE,
  1709. /**
  1710. * Format of texel data
  1711. * Possible values:
  1712. * + {@link clay.Texture.RGBA}
  1713. * + {@link clay.Texture.DEPTH_COMPONENT}
  1714. * + {@link clay.Texture.DEPTH_STENCIL}
  1715. * @type {number}
  1716. */
  1717. format: __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].RGBA,
  1718. /**
  1719. * Texture wrap. Default to be REPEAT.
  1720. * Possible values:
  1721. * + {@link clay.Texture.CLAMP_TO_EDGE}
  1722. * + {@link clay.Texture.REPEAT}
  1723. * + {@link clay.Texture.MIRRORED_REPEAT}
  1724. * @type {number}
  1725. */
  1726. wrapS: __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].REPEAT,
  1727. /**
  1728. * Texture wrap. Default to be REPEAT.
  1729. * Possible values:
  1730. * + {@link clay.Texture.CLAMP_TO_EDGE}
  1731. * + {@link clay.Texture.REPEAT}
  1732. * + {@link clay.Texture.MIRRORED_REPEAT}
  1733. * @type {number}
  1734. */
  1735. wrapT: __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].REPEAT,
  1736. /**
  1737. * Possible values:
  1738. * + {@link clay.Texture.NEAREST}
  1739. * + {@link clay.Texture.LINEAR}
  1740. * + {@link clay.Texture.NEAREST_MIPMAP_NEAREST}
  1741. * + {@link clay.Texture.LINEAR_MIPMAP_NEAREST}
  1742. * + {@link clay.Texture.NEAREST_MIPMAP_LINEAR}
  1743. * + {@link clay.Texture.LINEAR_MIPMAP_LINEAR}
  1744. * @type {number}
  1745. */
  1746. minFilter: __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LINEAR_MIPMAP_LINEAR,
  1747. /**
  1748. * Possible values:
  1749. * + {@link clay.Texture.NEAREST}
  1750. * + {@link clay.Texture.LINEAR}
  1751. * @type {number}
  1752. */
  1753. magFilter: __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LINEAR,
  1754. /**
  1755. * If enable mimap.
  1756. * @type {boolean}
  1757. */
  1758. useMipmap: true,
  1759. /**
  1760. * Anisotropic filtering, enabled if value is larger than 1
  1761. * @see https://developer.mozilla.org/en-US/docs/Web/API/EXT_texture_filter_anisotropic
  1762. * @type {number}
  1763. */
  1764. anisotropic: 1,
  1765. // pixelStorei parameters, not available when texture is used as render target
  1766. // http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml
  1767. /**
  1768. * If flip in y axis for given image source
  1769. * @type {boolean}
  1770. * @default true
  1771. */
  1772. flipY: true,
  1773. /**
  1774. * A flag to indicate if texture source is sRGB
  1775. */
  1776. sRGB: true,
  1777. /**
  1778. * @type {number}
  1779. * @default 4
  1780. */
  1781. unpackAlignment: 4,
  1782. /**
  1783. * @type {boolean}
  1784. * @default false
  1785. */
  1786. premultiplyAlpha: false,
  1787. /**
  1788. * Dynamic option for texture like video
  1789. * @type {boolean}
  1790. */
  1791. dynamic: false,
  1792. NPOT: false,
  1793. // PENDING
  1794. // Init it here to avoid deoptimization when it's assigned in application dynamically
  1795. __used: 0
  1796. }, function () {
  1797. this._cache = new __WEBPACK_IMPORTED_MODULE_2__core_Cache__["a" /* default */]();
  1798. },
  1799. /** @lends clay.Texture.prototype */
  1800. {
  1801. getWebGLTexture: function (renderer) {
  1802. var _gl = renderer.gl;
  1803. var cache = this._cache;
  1804. cache.use(renderer.__uid__);
  1805. if (cache.miss('webgl_texture')) {
  1806. // In a new gl context, create new texture and set dirty true
  1807. cache.put('webgl_texture', _gl.createTexture());
  1808. }
  1809. if (this.dynamic) {
  1810. this.update(renderer);
  1811. }
  1812. else if (cache.isDirty()) {
  1813. this.update(renderer);
  1814. cache.fresh();
  1815. }
  1816. return cache.get('webgl_texture');
  1817. },
  1818. bind: function () { },
  1819. unbind: function () { },
  1820. /**
  1821. * Mark texture is dirty and update in the next frame
  1822. */
  1823. dirty: function () {
  1824. if (this._cache) {
  1825. this._cache.dirtyAll();
  1826. }
  1827. },
  1828. update: function (renderer) { },
  1829. // Update the common parameters of texture
  1830. updateCommon: function (renderer) {
  1831. var _gl = renderer.gl;
  1832. _gl.pixelStorei(_gl.UNPACK_FLIP_Y_WEBGL, this.flipY);
  1833. _gl.pixelStorei(_gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this.premultiplyAlpha);
  1834. _gl.pixelStorei(_gl.UNPACK_ALIGNMENT, this.unpackAlignment);
  1835. // Use of none-power of two texture
  1836. // http://www.khronos.org/webgl/wiki/WebGL_and_OpenGL_Differences
  1837. if (this.format === __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].DEPTH_COMPONENT) {
  1838. this.useMipmap = false;
  1839. }
  1840. var sRGBExt = renderer.getGLExtension('EXT_sRGB');
  1841. // Fallback
  1842. if (this.format === Texture.SRGB && !sRGBExt) {
  1843. this.format = Texture.RGB;
  1844. }
  1845. if (this.format === Texture.SRGB_ALPHA && !sRGBExt) {
  1846. this.format = Texture.RGBA;
  1847. }
  1848. this.NPOT = !this.isPowerOfTwo();
  1849. },
  1850. getAvailableWrapS: function () {
  1851. if (this.NPOT) {
  1852. return __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].CLAMP_TO_EDGE;
  1853. }
  1854. return this.wrapS;
  1855. },
  1856. getAvailableWrapT: function () {
  1857. if (this.NPOT) {
  1858. return __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].CLAMP_TO_EDGE;
  1859. }
  1860. return this.wrapT;
  1861. },
  1862. getAvailableMinFilter: function () {
  1863. var minFilter = this.minFilter;
  1864. if (this.NPOT || !this.useMipmap) {
  1865. if (minFilter === __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].NEAREST_MIPMAP_NEAREST ||
  1866. minFilter === __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].NEAREST_MIPMAP_LINEAR
  1867. ) {
  1868. return __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].NEAREST;
  1869. }
  1870. else if (minFilter === __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LINEAR_MIPMAP_LINEAR ||
  1871. minFilter === __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LINEAR_MIPMAP_NEAREST
  1872. ) {
  1873. return __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LINEAR;
  1874. }
  1875. else {
  1876. return minFilter;
  1877. }
  1878. }
  1879. else {
  1880. return minFilter;
  1881. }
  1882. },
  1883. getAvailableMagFilter: function () {
  1884. return this.magFilter;
  1885. },
  1886. nextHighestPowerOfTwo: function (x) {
  1887. --x;
  1888. for (var i = 1; i < 32; i <<= 1) {
  1889. x = x | x >> i;
  1890. }
  1891. return x + 1;
  1892. },
  1893. /**
  1894. * @param {clay.Renderer} renderer
  1895. */
  1896. dispose: function (renderer) {
  1897. var cache = this._cache;
  1898. cache.use(renderer.__uid__);
  1899. var webglTexture = cache.get('webgl_texture');
  1900. if (webglTexture) {
  1901. renderer.gl.deleteTexture(webglTexture);
  1902. }
  1903. cache.deleteContext(renderer.__uid__);
  1904. },
  1905. /**
  1906. * Test if image of texture is valid and loaded.
  1907. * @return {boolean}
  1908. */
  1909. isRenderable: function () { },
  1910. /**
  1911. * Test if texture size is power of two
  1912. * @return {boolean}
  1913. */
  1914. isPowerOfTwo: function () { }
  1915. });
  1916. Object.defineProperty(Texture.prototype, 'width', {
  1917. get: function () {
  1918. return this._width;
  1919. },
  1920. set: function (value) {
  1921. this._width = value;
  1922. }
  1923. });
  1924. Object.defineProperty(Texture.prototype, 'height', {
  1925. get: function () {
  1926. return this._height;
  1927. },
  1928. set: function (value) {
  1929. this._height = value;
  1930. }
  1931. });
  1932. /* DataType */
  1933. /**
  1934. * @type {number}
  1935. */
  1936. Texture.BYTE = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].BYTE;
  1937. /**
  1938. * @type {number}
  1939. */
  1940. Texture.UNSIGNED_BYTE = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].UNSIGNED_BYTE;
  1941. /**
  1942. * @type {number}
  1943. */
  1944. Texture.SHORT = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].SHORT;
  1945. /**
  1946. * @type {number}
  1947. */
  1948. Texture.UNSIGNED_SHORT = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].UNSIGNED_SHORT;
  1949. /**
  1950. * @type {number}
  1951. */
  1952. Texture.INT = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].INT;
  1953. /**
  1954. * @type {number}
  1955. */
  1956. Texture.UNSIGNED_INT = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].UNSIGNED_INT;
  1957. /**
  1958. * @type {number}
  1959. */
  1960. Texture.FLOAT = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].FLOAT;
  1961. /**
  1962. * @type {number}
  1963. */
  1964. Texture.HALF_FLOAT = 0x8D61;
  1965. /**
  1966. * UNSIGNED_INT_24_8_WEBGL for WEBGL_depth_texture extension
  1967. * @type {number}
  1968. */
  1969. Texture.UNSIGNED_INT_24_8_WEBGL = 34042;
  1970. /* PixelFormat */
  1971. /**
  1972. * @type {number}
  1973. */
  1974. Texture.DEPTH_COMPONENT = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].DEPTH_COMPONENT;
  1975. /**
  1976. * @type {number}
  1977. */
  1978. Texture.DEPTH_STENCIL = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].DEPTH_STENCIL;
  1979. /**
  1980. * @type {number}
  1981. */
  1982. Texture.ALPHA = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].ALPHA;
  1983. /**
  1984. * @type {number}
  1985. */
  1986. Texture.RGB = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].RGB;
  1987. /**
  1988. * @type {number}
  1989. */
  1990. Texture.RGBA = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].RGBA;
  1991. /**
  1992. * @type {number}
  1993. */
  1994. Texture.LUMINANCE = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LUMINANCE;
  1995. /**
  1996. * @type {number}
  1997. */
  1998. Texture.LUMINANCE_ALPHA = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LUMINANCE_ALPHA;
  1999. /**
  2000. * @see https://www.khronos.org/registry/webgl/extensions/EXT_sRGB/
  2001. * @type {number}
  2002. */
  2003. Texture.SRGB = 0x8C40;
  2004. /**
  2005. * @see https://www.khronos.org/registry/webgl/extensions/EXT_sRGB/
  2006. * @type {number}
  2007. */
  2008. Texture.SRGB_ALPHA = 0x8C42;
  2009. /* Compressed Texture */
  2010. Texture.COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0;
  2011. Texture.COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83F1;
  2012. Texture.COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2;
  2013. Texture.COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3;
  2014. /* TextureMagFilter */
  2015. /**
  2016. * @type {number}
  2017. */
  2018. Texture.NEAREST = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].NEAREST;
  2019. /**
  2020. * @type {number}
  2021. */
  2022. Texture.LINEAR = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LINEAR;
  2023. /* TextureMinFilter */
  2024. /**
  2025. * @type {number}
  2026. */
  2027. Texture.NEAREST_MIPMAP_NEAREST = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].NEAREST_MIPMAP_NEAREST;
  2028. /**
  2029. * @type {number}
  2030. */
  2031. Texture.LINEAR_MIPMAP_NEAREST = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LINEAR_MIPMAP_NEAREST;
  2032. /**
  2033. * @type {number}
  2034. */
  2035. Texture.NEAREST_MIPMAP_LINEAR = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].NEAREST_MIPMAP_LINEAR;
  2036. /**
  2037. * @type {number}
  2038. */
  2039. Texture.LINEAR_MIPMAP_LINEAR = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LINEAR_MIPMAP_LINEAR;
  2040. /* TextureWrapMode */
  2041. /**
  2042. * @type {number}
  2043. */
  2044. Texture.REPEAT = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].REPEAT;
  2045. /**
  2046. * @type {number}
  2047. */
  2048. Texture.CLAMP_TO_EDGE = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].CLAMP_TO_EDGE;
  2049. /**
  2050. * @type {number}
  2051. */
  2052. Texture.MIRRORED_REPEAT = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].MIRRORED_REPEAT;
  2053. /* harmony default export */ __webpack_exports__["a"] = (Texture);
  2054. /***/
  2055. }),
  2056. /* 5 */
  2057. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  2058. "use strict";
  2059. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Texture__ = __webpack_require__(4);
  2060. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__core_glenum__ = __webpack_require__(11);
  2061. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__core_vendor__ = __webpack_require__(14);
  2062. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__math_util__ = __webpack_require__(73);
  2063. var isPowerOfTwo = __WEBPACK_IMPORTED_MODULE_3__math_util__["a" /* default */].isPowerOfTwo;
  2064. function nearestPowerOfTwo(val) {
  2065. return Math.pow(2, Math.round(Math.log(val) / Math.LN2));
  2066. }
  2067. function convertTextureToPowerOfTwo(texture, canvas) {
  2068. // var canvas = document.createElement('canvas');
  2069. var width = nearestPowerOfTwo(texture.width);
  2070. var height = nearestPowerOfTwo(texture.height);
  2071. canvas = canvas || document.createElement('canvas');
  2072. canvas.width = width;
  2073. canvas.height = height;
  2074. var ctx = canvas.getContext('2d');
  2075. ctx.drawImage(texture.image, 0, 0, width, height);
  2076. return canvas;
  2077. }
  2078. /**
  2079. * @constructor clay.Texture2D
  2080. * @extends clay.Texture
  2081. *
  2082. * @example
  2083. * ...
  2084. * var mat = new clay.Material({
  2085. * shader: clay.shader.library.get('clay.phong', 'diffuseMap')
  2086. * });
  2087. * var diffuseMap = new clay.Texture2D();
  2088. * diffuseMap.load('assets/textures/diffuse.jpg');
  2089. * mat.set('diffuseMap', diffuseMap);
  2090. * ...
  2091. * diffuseMap.success(function () {
  2092. * // Wait for the diffuse texture loaded
  2093. * animation.on('frame', function (frameTime) {
  2094. * renderer.render(scene, camera);
  2095. * });
  2096. * });
  2097. */
  2098. var Texture2D = __WEBPACK_IMPORTED_MODULE_0__Texture__["a" /* default */].extend(function () {
  2099. return /** @lends clay.Texture2D# */ {
  2100. /**
  2101. * @type {?HTMLImageElement|HTMLCanvasElemnet}
  2102. */
  2103. // TODO mark dirty when assigned.
  2104. image: null,
  2105. /**
  2106. * Pixels data. Will be ignored if image is set.
  2107. * @type {?Uint8Array|Float32Array}
  2108. */
  2109. pixels: null,
  2110. /**
  2111. * @type {Array.<Object>}
  2112. * @example
  2113. * [{
  2114. * image: mipmap0,
  2115. * pixels: null
  2116. * }, {
  2117. * image: mipmap1,
  2118. * pixels: null
  2119. * }, ....]
  2120. */
  2121. mipmaps: [],
  2122. /**
  2123. * If convert texture to power-of-two
  2124. * @type {boolean}
  2125. */
  2126. convertToPOT: false
  2127. };
  2128. }, {
  2129. textureType: 'texture2D',
  2130. update: function (renderer) {
  2131. var _gl = renderer.gl;
  2132. _gl.bindTexture(_gl.TEXTURE_2D, this._cache.get('webgl_texture'));
  2133. this.updateCommon(renderer);
  2134. var glFormat = this.format;
  2135. var glType = this.type;
  2136. // Convert to pot is only available when using image/canvas/video element.
  2137. var convertToPOT = !!(this.convertToPOT
  2138. && !this.mipmaps.length && this.image
  2139. && (this.wrapS === __WEBPACK_IMPORTED_MODULE_0__Texture__["a" /* default */].REPEAT || this.wrapT === __WEBPACK_IMPORTED_MODULE_0__Texture__["a" /* default */].REPEAT)
  2140. && this.NPOT
  2141. );
  2142. _gl.texParameteri(_gl.TEXTURE_2D, _gl.TEXTURE_WRAP_S, convertToPOT ? this.wrapS : this.getAvailableWrapS());
  2143. _gl.texParameteri(_gl.TEXTURE_2D, _gl.TEXTURE_WRAP_T, convertToPOT ? this.wrapT : this.getAvailableWrapT());
  2144. _gl.texParameteri(_gl.TEXTURE_2D, _gl.TEXTURE_MAG_FILTER, convertToPOT ? this.magFilter : this.getAvailableMagFilter());
  2145. _gl.texParameteri(_gl.TEXTURE_2D, _gl.TEXTURE_MIN_FILTER, convertToPOT ? this.minFilter : this.getAvailableMinFilter());
  2146. var anisotropicExt = renderer.getGLExtension('EXT_texture_filter_anisotropic');
  2147. if (anisotropicExt && this.anisotropic > 1) {
  2148. _gl.texParameterf(_gl.TEXTURE_2D, anisotropicExt.TEXTURE_MAX_ANISOTROPY_EXT, this.anisotropic);
  2149. }
  2150. // Fallback to float type if browser don't have half float extension
  2151. if (glType === 36193) {
  2152. var halfFloatExt = renderer.getGLExtension('OES_texture_half_float');
  2153. if (!halfFloatExt) {
  2154. glType = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].FLOAT;
  2155. }
  2156. }
  2157. if (this.mipmaps.length) {
  2158. var width = this.width;
  2159. var height = this.height;
  2160. for (var i = 0; i < this.mipmaps.length; i++) {
  2161. var mipmap = this.mipmaps[i];
  2162. this._updateTextureData(_gl, mipmap, i, width, height, glFormat, glType, false);
  2163. width /= 2;
  2164. height /= 2;
  2165. }
  2166. }
  2167. else {
  2168. this._updateTextureData(_gl, this, 0, this.width, this.height, glFormat, glType, convertToPOT);
  2169. if (this.useMipmap && (!this.NPOT || convertToPOT)) {
  2170. _gl.generateMipmap(_gl.TEXTURE_2D);
  2171. }
  2172. }
  2173. _gl.bindTexture(_gl.TEXTURE_2D, null);
  2174. },
  2175. _updateTextureData: function (_gl, data, level, width, height, glFormat, glType, convertToPOT) {
  2176. if (data.image) {
  2177. var imgData = data.image;
  2178. if (convertToPOT) {
  2179. this._potCanvas = convertTextureToPowerOfTwo(this, this._potCanvas);
  2180. imgData = this._potCanvas;
  2181. }
  2182. _gl.texImage2D(_gl.TEXTURE_2D, level, glFormat, glFormat, glType, imgData);
  2183. }
  2184. else {
  2185. // Can be used as a blank texture when writing render to texture(RTT)
  2186. if (
  2187. glFormat <= __WEBPACK_IMPORTED_MODULE_0__Texture__["a" /* default */].COMPRESSED_RGBA_S3TC_DXT5_EXT
  2188. && glFormat >= __WEBPACK_IMPORTED_MODULE_0__Texture__["a" /* default */].COMPRESSED_RGB_S3TC_DXT1_EXT
  2189. ) {
  2190. _gl.compressedTexImage2D(_gl.TEXTURE_2D, level, glFormat, width, height, 0, data.pixels);
  2191. }
  2192. else {
  2193. // Is a render target if pixels is null
  2194. _gl.texImage2D(_gl.TEXTURE_2D, level, glFormat, width, height, 0, glFormat, glType, data.pixels);
  2195. }
  2196. }
  2197. },
  2198. /**
  2199. * @param {clay.Renderer} renderer
  2200. * @memberOf clay.Texture2D.prototype
  2201. */
  2202. generateMipmap: function (renderer) {
  2203. var _gl = renderer.gl;
  2204. if (this.useMipmap && !this.NPOT) {
  2205. _gl.bindTexture(_gl.TEXTURE_2D, this._cache.get('webgl_texture'));
  2206. _gl.generateMipmap(_gl.TEXTURE_2D);
  2207. }
  2208. },
  2209. isPowerOfTwo: function () {
  2210. return isPowerOfTwo(this.width) && isPowerOfTwo(this.height);
  2211. },
  2212. isRenderable: function () {
  2213. if (this.image) {
  2214. return this.image.nodeName === 'CANVAS'
  2215. || this.image.nodeName === 'VIDEO'
  2216. || this.image.complete;
  2217. }
  2218. else {
  2219. return !!(this.width && this.height);
  2220. }
  2221. },
  2222. bind: function (renderer) {
  2223. renderer.gl.bindTexture(renderer.gl.TEXTURE_2D, this.getWebGLTexture(renderer));
  2224. },
  2225. unbind: function (renderer) {
  2226. renderer.gl.bindTexture(renderer.gl.TEXTURE_2D, null);
  2227. },
  2228. load: function (src, crossOrigin) {
  2229. var image = __WEBPACK_IMPORTED_MODULE_2__core_vendor__["a" /* default */].createImage();
  2230. if (crossOrigin) {
  2231. image.crossOrigin = crossOrigin;
  2232. }
  2233. var self = this;
  2234. image.onload = function () {
  2235. self.dirty();
  2236. self.trigger('success', self);
  2237. image.onload = null;
  2238. };
  2239. image.onerror = function () {
  2240. self.trigger('error', self);
  2241. image.onerror = null;
  2242. };
  2243. image.src = src;
  2244. this.image = image;
  2245. return this;
  2246. }
  2247. });
  2248. Object.defineProperty(Texture2D.prototype, 'width', {
  2249. get: function () {
  2250. if (this.image) {
  2251. return this.image.width;
  2252. }
  2253. return this._width;
  2254. },
  2255. set: function (value) {
  2256. if (this.image) {
  2257. console.warn('Texture from image can\'t set width');
  2258. }
  2259. else {
  2260. if (this._width !== value) {
  2261. this.dirty();
  2262. }
  2263. this._width = value;
  2264. }
  2265. }
  2266. });
  2267. Object.defineProperty(Texture2D.prototype, 'height', {
  2268. get: function () {
  2269. if (this.image) {
  2270. return this.image.height;
  2271. }
  2272. return this._height;
  2273. },
  2274. set: function (value) {
  2275. if (this.image) {
  2276. console.warn('Texture from image can\'t set height');
  2277. }
  2278. else {
  2279. if (this._height !== value) {
  2280. this.dirty();
  2281. }
  2282. this._height = value;
  2283. }
  2284. }
  2285. });
  2286. /* harmony default export */ __webpack_exports__["a"] = (Texture2D);
  2287. /***/
  2288. }),
  2289. /* 6 */
  2290. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  2291. "use strict";
  2292. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__glmatrix__ = __webpack_require__(161);
  2293. // DEPRECATED
  2294. /* harmony default export */ __webpack_exports__["a"] = (__WEBPACK_IMPORTED_MODULE_0__glmatrix__["a" /* default */]);
  2295. /***/
  2296. }),
  2297. /* 7 */
  2298. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  2299. "use strict";
  2300. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__mixin_extend__ = __webpack_require__(110);
  2301. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__mixin_notifier__ = __webpack_require__(53);
  2302. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util__ = __webpack_require__(23);
  2303. /**
  2304. * Base class of all objects
  2305. * @constructor
  2306. * @alias clay.core.Base
  2307. * @mixes clay.core.mixin.notifier
  2308. */
  2309. var Base = function () {
  2310. /**
  2311. * @type {number}
  2312. */
  2313. this.__uid__ = __WEBPACK_IMPORTED_MODULE_2__util__["a" /* default */].genGUID();
  2314. };
  2315. Base.__initializers__ = [
  2316. function (opts) {
  2317. __WEBPACK_IMPORTED_MODULE_2__util__["a" /* default */].extend(this, opts);
  2318. }
  2319. ];
  2320. __WEBPACK_IMPORTED_MODULE_2__util__["a" /* default */].extend(Base, __WEBPACK_IMPORTED_MODULE_0__mixin_extend__["a" /* default */]);
  2321. __WEBPACK_IMPORTED_MODULE_2__util__["a" /* default */].extend(Base.prototype, __WEBPACK_IMPORTED_MODULE_1__mixin_notifier__["a" /* default */]);
  2322. /* harmony default export */ __webpack_exports__["a"] = (Base);
  2323. /***/
  2324. }),
  2325. /* 8 */
  2326. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  2327. "use strict";
  2328. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__core_util__ = __webpack_require__(23);
  2329. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__core_vendor__ = __webpack_require__(14);
  2330. /**
  2331. * Mainly do the parse and compile of shader string
  2332. * Support shader code chunk import and export
  2333. * Support shader semantics
  2334. * http://www.nvidia.com/object/using_sas.html
  2335. * https://github.com/KhronosGroup/collada2json/issues/45
  2336. */
  2337. var uniformRegex = /uniform\s+(bool|float|int|vec2|vec3|vec4|ivec2|ivec3|ivec4|mat2|mat3|mat4|sampler2D|samplerCube)\s+([\s\S]*?);/g;
  2338. var attributeRegex = /attribute\s+(float|int|vec2|vec3|vec4)\s+([\s\S]*?);/g;
  2339. // Only parse number define.
  2340. var defineRegex = /#define\s+(\w+)?(\s+[\d-.]+)?\s*;?\s*\n/g;
  2341. var uniformTypeMap = {
  2342. 'bool': '1i',
  2343. 'int': '1i',
  2344. 'sampler2D': 't',
  2345. 'samplerCube': 't',
  2346. 'float': '1f',
  2347. 'vec2': '2f',
  2348. 'vec3': '3f',
  2349. 'vec4': '4f',
  2350. 'ivec2': '2i',
  2351. 'ivec3': '3i',
  2352. 'ivec4': '4i',
  2353. 'mat2': 'm2',
  2354. 'mat3': 'm3',
  2355. 'mat4': 'm4'
  2356. };
  2357. function createZeroArray(len) {
  2358. var arr = [];
  2359. for (var i = 0; i < len; i++) {
  2360. arr[i] = 0;
  2361. }
  2362. return arr;
  2363. }
  2364. var uniformValueConstructor = {
  2365. 'bool': function () { return true; },
  2366. 'int': function () { return 0; },
  2367. 'float': function () { return 0; },
  2368. 'sampler2D': function () { return null; },
  2369. 'samplerCube': function () { return null; },
  2370. 'vec2': function () { return createZeroArray(2); },
  2371. 'vec3': function () { return createZeroArray(3); },
  2372. 'vec4': function () { return createZeroArray(4); },
  2373. 'ivec2': function () { return createZeroArray(2); },
  2374. 'ivec3': function () { return createZeroArray(3); },
  2375. 'ivec4': function () { return createZeroArray(4); },
  2376. 'mat2': function () { return createZeroArray(4); },
  2377. 'mat3': function () { return createZeroArray(9); },
  2378. 'mat4': function () { return createZeroArray(16); },
  2379. 'array': function () { return []; }
  2380. };
  2381. var attributeSemantics = [
  2382. 'POSITION',
  2383. 'NORMAL',
  2384. 'BINORMAL',
  2385. 'TANGENT',
  2386. 'TEXCOORD',
  2387. 'TEXCOORD_0',
  2388. 'TEXCOORD_1',
  2389. 'COLOR',
  2390. // Skinning
  2391. // https://github.com/KhronosGroup/glTF/blob/master/specification/README.md#semantics
  2392. 'JOINT',
  2393. 'WEIGHT'
  2394. ];
  2395. var uniformSemantics = [
  2396. 'SKIN_MATRIX',
  2397. // Information about viewport
  2398. 'VIEWPORT_SIZE',
  2399. 'VIEWPORT',
  2400. 'DEVICEPIXELRATIO',
  2401. // Window size for window relative coordinate
  2402. // https://www.opengl.org/sdk/docs/man/html/gl_FragCoord.xhtml
  2403. 'WINDOW_SIZE',
  2404. // Infomation about camera
  2405. 'NEAR',
  2406. 'FAR',
  2407. // Time
  2408. 'TIME'
  2409. ];
  2410. var matrixSemantics = [
  2411. 'WORLD',
  2412. 'VIEW',
  2413. 'PROJECTION',
  2414. 'WORLDVIEW',
  2415. 'VIEWPROJECTION',
  2416. 'WORLDVIEWPROJECTION',
  2417. 'WORLDINVERSE',
  2418. 'VIEWINVERSE',
  2419. 'PROJECTIONINVERSE',
  2420. 'WORLDVIEWINVERSE',
  2421. 'VIEWPROJECTIONINVERSE',
  2422. 'WORLDVIEWPROJECTIONINVERSE',
  2423. 'WORLDTRANSPOSE',
  2424. 'VIEWTRANSPOSE',
  2425. 'PROJECTIONTRANSPOSE',
  2426. 'WORLDVIEWTRANSPOSE',
  2427. 'VIEWPROJECTIONTRANSPOSE',
  2428. 'WORLDVIEWPROJECTIONTRANSPOSE',
  2429. 'WORLDINVERSETRANSPOSE',
  2430. 'VIEWINVERSETRANSPOSE',
  2431. 'PROJECTIONINVERSETRANSPOSE',
  2432. 'WORLDVIEWINVERSETRANSPOSE',
  2433. 'VIEWPROJECTIONINVERSETRANSPOSE',
  2434. 'WORLDVIEWPROJECTIONINVERSETRANSPOSE'
  2435. ];
  2436. var attributeSizeMap = {
  2437. // WebGL does not support integer attributes
  2438. 'vec4': 4,
  2439. 'vec3': 3,
  2440. 'vec2': 2,
  2441. 'float': 1
  2442. };
  2443. var shaderIDCache = {};
  2444. var shaderCodeCache = {};
  2445. function getShaderID(vertex, fragment) {
  2446. var key = 'vertex:' + vertex + 'fragment:' + fragment;
  2447. if (shaderIDCache[key]) {
  2448. return shaderIDCache[key];
  2449. }
  2450. var id = __WEBPACK_IMPORTED_MODULE_0__core_util__["a" /* default */].genGUID();
  2451. shaderIDCache[key] = id;
  2452. shaderCodeCache[id] = {
  2453. vertex: vertex,
  2454. fragment: fragment
  2455. };
  2456. return id;
  2457. }
  2458. function removeComment(code) {
  2459. return code.replace(/[ \t]*\/\/.*\n/g, '') // remove //
  2460. .replace(/[ \t]*\/\*[\s\S]*?\*\//g, ''); // remove /* */
  2461. }
  2462. function logSyntaxError() {
  2463. console.error('Wrong uniform/attributes syntax');
  2464. }
  2465. function parseDeclarations(type, line) {
  2466. var speratorsRegexp = /[,=\(\):]/;
  2467. var tokens = line
  2468. // Convert `symbol: [1,2,3]` to `symbol: vec3(1,2,3)`
  2469. .replace(/:\s*\[\s*(.*)\s*\]/g, '=' + type + '($1)')
  2470. .replace(/\s+/g, '')
  2471. .split(/(?=[,=\(\):])/g);
  2472. var newTokens = [];
  2473. for (var i = 0; i < tokens.length; i++) {
  2474. if (tokens[i].match(speratorsRegexp)) {
  2475. newTokens.push(
  2476. tokens[i].charAt(0),
  2477. tokens[i].slice(1)
  2478. );
  2479. }
  2480. else {
  2481. newTokens.push(tokens[i]);
  2482. }
  2483. }
  2484. tokens = newTokens;
  2485. var TYPE_SYMBOL = 0;
  2486. var TYPE_ASSIGN = 1;
  2487. var TYPE_VEC = 2;
  2488. var TYPE_ARR = 3;
  2489. var TYPE_SEMANTIC = 4;
  2490. var TYPE_NORMAL = 5;
  2491. var opType = TYPE_SYMBOL;
  2492. var declarations = {};
  2493. var declarationValue = null;
  2494. var currentDeclaration;
  2495. addSymbol(tokens[0]);
  2496. function addSymbol(symbol) {
  2497. if (!symbol) {
  2498. logSyntaxError();
  2499. }
  2500. var arrResult = symbol.match(/\[(.*?)\]/);
  2501. currentDeclaration = symbol.replace(/\[(.*?)\]/, '');
  2502. declarations[currentDeclaration] = {};
  2503. if (arrResult) {
  2504. declarations[currentDeclaration].isArray = true;
  2505. declarations[currentDeclaration].arraySize = arrResult[1];
  2506. }
  2507. }
  2508. for (var i = 1; i < tokens.length; i++) {
  2509. var token = tokens[i];
  2510. if (!token) { // Empty token;
  2511. continue;
  2512. }
  2513. if (token === '=') {
  2514. if (opType !== TYPE_SYMBOL
  2515. && opType !== TYPE_ARR) {
  2516. logSyntaxError();
  2517. break;
  2518. }
  2519. opType = TYPE_ASSIGN;
  2520. continue;
  2521. }
  2522. else if (token === ':') {
  2523. opType = TYPE_SEMANTIC;
  2524. continue;
  2525. }
  2526. else if (token === ',') {
  2527. if (opType === TYPE_VEC) {
  2528. if (!(declarationValue instanceof Array)) {
  2529. logSyntaxError();
  2530. break;
  2531. }
  2532. declarationValue.push(+tokens[++i]);
  2533. }
  2534. else {
  2535. opType = TYPE_NORMAL;
  2536. }
  2537. continue;
  2538. }
  2539. else if (token === ')') {
  2540. declarations[currentDeclaration].value = new __WEBPACK_IMPORTED_MODULE_1__core_vendor__["a" /* default */].Float32Array(declarationValue);
  2541. declarationValue = null;
  2542. opType = TYPE_NORMAL;
  2543. continue;
  2544. }
  2545. else if (token === '(') {
  2546. if (opType !== TYPE_VEC) {
  2547. logSyntaxError();
  2548. break;
  2549. }
  2550. if (!(declarationValue instanceof Array)) {
  2551. logSyntaxError();
  2552. break;
  2553. }
  2554. declarationValue.push(+tokens[++i]);
  2555. continue;
  2556. }
  2557. else if (token.indexOf('vec') >= 0) {
  2558. if (opType !== TYPE_ASSIGN
  2559. // Compatitable with old syntax `symbol: [1,2,3]`
  2560. && opType !== TYPE_SEMANTIC) {
  2561. logSyntaxError();
  2562. break;
  2563. }
  2564. opType = TYPE_VEC;
  2565. declarationValue = [];
  2566. continue;
  2567. }
  2568. else if (opType === TYPE_ASSIGN) {
  2569. if (type === 'bool') {
  2570. declarations[currentDeclaration].value = token === 'true';
  2571. }
  2572. else {
  2573. declarations[currentDeclaration].value = parseFloat(token);
  2574. }
  2575. declarationValue = null;
  2576. continue;
  2577. }
  2578. else if (opType === TYPE_SEMANTIC) {
  2579. var semantic = token;
  2580. if (attributeSemantics.indexOf(semantic) >= 0
  2581. || uniformSemantics.indexOf(semantic) >= 0
  2582. || matrixSemantics.indexOf(semantic) >= 0
  2583. ) {
  2584. declarations[currentDeclaration].semantic = semantic;
  2585. }
  2586. else if (semantic === 'ignore' || semantic === 'unconfigurable') {
  2587. declarations[currentDeclaration].ignore = true;
  2588. }
  2589. else {
  2590. // Try to parse as a default tvalue.
  2591. if (type === 'bool') {
  2592. declarations[currentDeclaration].value = semantic === 'true';
  2593. }
  2594. else {
  2595. declarations[currentDeclaration].value = parseFloat(semantic);
  2596. }
  2597. }
  2598. continue;
  2599. }
  2600. // treat as symbol.
  2601. addSymbol(token);
  2602. opType = TYPE_SYMBOL;
  2603. }
  2604. return declarations;
  2605. }
  2606. /**
  2607. * @constructor
  2608. * @extends clay.core.Base
  2609. * @alias clay.Shader
  2610. * @param {string} vertex
  2611. * @param {string} fragment
  2612. * @example
  2613. * // Create a phong shader
  2614. * var shader = new clay.Shader(
  2615. * clay.Shader.source('clay.standard.vertex'),
  2616. * clay.Shader.source('clay.standard.fragment')
  2617. * );
  2618. */
  2619. function Shader(vertex, fragment) {
  2620. // First argument can be { vertex, fragment }
  2621. if (typeof vertex === 'object') {
  2622. fragment = vertex.fragment;
  2623. vertex = vertex.vertex;
  2624. }
  2625. vertex = removeComment(vertex);
  2626. fragment = removeComment(fragment);
  2627. this._shaderID = getShaderID(vertex, fragment);
  2628. this._vertexCode = Shader.parseImport(vertex);
  2629. this._fragmentCode = Shader.parseImport(fragment);
  2630. /**
  2631. * @readOnly
  2632. */
  2633. this.attributeSemantics = {};
  2634. /**
  2635. * @readOnly
  2636. */
  2637. this.matrixSemantics = {};
  2638. /**
  2639. * @readOnly
  2640. */
  2641. this.uniformSemantics = {};
  2642. /**
  2643. * @readOnly
  2644. */
  2645. this.matrixSemanticKeys = [];
  2646. /**
  2647. * @readOnly
  2648. */
  2649. this.uniformTemplates = {};
  2650. /**
  2651. * @readOnly
  2652. */
  2653. this.attributes = {};
  2654. /**
  2655. * @readOnly
  2656. */
  2657. this.textures = {};
  2658. /**
  2659. * @readOnly
  2660. */
  2661. this.vertexDefines = {};
  2662. /**
  2663. * @readOnly
  2664. */
  2665. this.fragmentDefines = {};
  2666. this._parseAttributes();
  2667. this._parseUniforms();
  2668. this._parseDefines();
  2669. }
  2670. Shader.prototype = {
  2671. constructor: Shader,
  2672. // Create a new uniform instance for material
  2673. createUniforms: function () {
  2674. var uniforms = {};
  2675. for (var symbol in this.uniformTemplates) {
  2676. var uniformTpl = this.uniformTemplates[symbol];
  2677. uniforms[symbol] = {
  2678. type: uniformTpl.type,
  2679. value: uniformTpl.value()
  2680. };
  2681. }
  2682. return uniforms;
  2683. },
  2684. _parseImport: function () {
  2685. this._vertexCode = Shader.parseImport(this.vertex);
  2686. this._fragmentCode = Shader.parseImport(this.fragment);
  2687. },
  2688. _addSemanticUniform: function (symbol, uniformType, semantic) {
  2689. // This case is only for SKIN_MATRIX
  2690. // TODO
  2691. if (attributeSemantics.indexOf(semantic) >= 0) {
  2692. this.attributeSemantics[semantic] = {
  2693. symbol: symbol,
  2694. type: uniformType
  2695. };
  2696. }
  2697. else if (matrixSemantics.indexOf(semantic) >= 0) {
  2698. var isTranspose = false;
  2699. var semanticNoTranspose = semantic;
  2700. if (semantic.match(/TRANSPOSE$/)) {
  2701. isTranspose = true;
  2702. semanticNoTranspose = semantic.slice(0, -9);
  2703. }
  2704. this.matrixSemantics[semantic] = {
  2705. symbol: symbol,
  2706. type: uniformType,
  2707. isTranspose: isTranspose,
  2708. semanticNoTranspose: semanticNoTranspose
  2709. };
  2710. }
  2711. else if (uniformSemantics.indexOf(semantic) >= 0) {
  2712. this.uniformSemantics[semantic] = {
  2713. symbol: symbol,
  2714. type: uniformType
  2715. };
  2716. }
  2717. },
  2718. _addMaterialUniform: function (symbol, type, uniformType, defaultValueFunc, isArray, materialUniforms) {
  2719. materialUniforms[symbol] = {
  2720. type: uniformType,
  2721. value: isArray ? uniformValueConstructor['array'] : (defaultValueFunc || uniformValueConstructor[type]),
  2722. semantic: null
  2723. };
  2724. },
  2725. _parseUniforms: function () {
  2726. var uniforms = {};
  2727. var self = this;
  2728. var shaderType = 'vertex';
  2729. this._uniformList = [];
  2730. this._vertexCode = this._vertexCode.replace(uniformRegex, _uniformParser);
  2731. shaderType = 'fragment';
  2732. this._fragmentCode = this._fragmentCode.replace(uniformRegex, _uniformParser);
  2733. self.matrixSemanticKeys = Object.keys(this.matrixSemantics);
  2734. function makeDefaultValueFunc(value) {
  2735. return value != null ? function () { return value; } : null;
  2736. }
  2737. function _uniformParser(str, type, content) {
  2738. var declaredUniforms = parseDeclarations(type, content);
  2739. var uniformMainStr = [];
  2740. for (var symbol in declaredUniforms) {
  2741. var uniformInfo = declaredUniforms[symbol];
  2742. var semantic = uniformInfo.semantic;
  2743. var tmpStr = symbol;
  2744. var uniformType = uniformTypeMap[type];
  2745. var defaultValueFunc = makeDefaultValueFunc(declaredUniforms[symbol].value);
  2746. if (declaredUniforms[symbol].isArray) {
  2747. tmpStr += '[' + declaredUniforms[symbol].arraySize + ']';
  2748. uniformType += 'v';
  2749. }
  2750. uniformMainStr.push(tmpStr);
  2751. self._uniformList.push(symbol);
  2752. if (!uniformInfo.ignore) {
  2753. if (type === 'sampler2D' || type === 'samplerCube') {
  2754. // Texture is default disabled
  2755. self.textures[symbol] = {
  2756. shaderType: shaderType,
  2757. type: type
  2758. };
  2759. }
  2760. if (semantic) {
  2761. // TODO Should not declare multiple symbols if have semantic.
  2762. self._addSemanticUniform(symbol, uniformType, semantic);
  2763. }
  2764. else {
  2765. self._addMaterialUniform(
  2766. symbol, type, uniformType, defaultValueFunc,
  2767. declaredUniforms[symbol].isArray, uniforms
  2768. );
  2769. }
  2770. }
  2771. }
  2772. return uniformMainStr.length > 0
  2773. ? 'uniform ' + type + ' ' + uniformMainStr.join(',') + ';\n' : '';
  2774. }
  2775. this.uniformTemplates = uniforms;
  2776. },
  2777. _parseAttributes: function () {
  2778. var attributes = {};
  2779. var self = this;
  2780. this._vertexCode = this._vertexCode.replace(attributeRegex, _attributeParser);
  2781. function _attributeParser(str, type, content) {
  2782. var declaredAttributes = parseDeclarations(type, content);
  2783. var size = attributeSizeMap[type] || 1;
  2784. var attributeMainStr = [];
  2785. for (var symbol in declaredAttributes) {
  2786. var semantic = declaredAttributes[symbol].semantic;
  2787. attributes[symbol] = {
  2788. // TODO Can only be float
  2789. type: 'float',
  2790. size: size,
  2791. semantic: semantic || null
  2792. };
  2793. // TODO Should not declare multiple symbols if have semantic.
  2794. if (semantic) {
  2795. if (attributeSemantics.indexOf(semantic) < 0) {
  2796. throw new Error('Unkown semantic "' + semantic + '"');
  2797. }
  2798. else {
  2799. self.attributeSemantics[semantic] = {
  2800. symbol: symbol,
  2801. type: type
  2802. };
  2803. }
  2804. }
  2805. attributeMainStr.push(symbol);
  2806. }
  2807. return 'attribute ' + type + ' ' + attributeMainStr.join(',') + ';\n';
  2808. }
  2809. this.attributes = attributes;
  2810. },
  2811. _parseDefines: function () {
  2812. var self = this;
  2813. var shaderType = 'vertex';
  2814. this._vertexCode = this._vertexCode.replace(defineRegex, _defineParser);
  2815. shaderType = 'fragment';
  2816. this._fragmentCode = this._fragmentCode.replace(defineRegex, _defineParser);
  2817. function _defineParser(str, symbol, value) {
  2818. var defines = shaderType === 'vertex' ? self.vertexDefines : self.fragmentDefines;
  2819. if (!defines[symbol]) { // Haven't been defined by user
  2820. if (value === 'false') {
  2821. defines[symbol] = false;
  2822. }
  2823. else if (value === 'true') {
  2824. defines[symbol] = true;
  2825. }
  2826. else {
  2827. defines[symbol] = value
  2828. // If can parse to float
  2829. ? (isNaN(parseFloat(value)) ? value.trim() : parseFloat(value))
  2830. : null;
  2831. }
  2832. }
  2833. return '';
  2834. }
  2835. },
  2836. /**
  2837. * Clone a new shader
  2838. * @return {clay.Shader}
  2839. */
  2840. clone: function () {
  2841. var code = shaderCodeCache[this._shaderID];
  2842. var shader = new Shader(code.vertex, code.fragment);
  2843. return shader;
  2844. }
  2845. };
  2846. if (Object.defineProperty) {
  2847. Object.defineProperty(Shader.prototype, 'shaderID', {
  2848. get: function () {
  2849. return this._shaderID;
  2850. }
  2851. });
  2852. Object.defineProperty(Shader.prototype, 'vertex', {
  2853. get: function () {
  2854. return this._vertexCode;
  2855. }
  2856. });
  2857. Object.defineProperty(Shader.prototype, 'fragment', {
  2858. get: function () {
  2859. return this._fragmentCode;
  2860. }
  2861. });
  2862. Object.defineProperty(Shader.prototype, 'uniforms', {
  2863. get: function () {
  2864. return this._uniformList;
  2865. }
  2866. });
  2867. }
  2868. var importRegex = /(@import)\s*([0-9a-zA-Z_\-\.]*)/g;
  2869. Shader.parseImport = function (shaderStr) {
  2870. shaderStr = shaderStr.replace(importRegex, function (str, importSymbol, importName) {
  2871. var str = Shader.source(importName);
  2872. if (str) {
  2873. // Recursively parse
  2874. return Shader.parseImport(str);
  2875. }
  2876. else {
  2877. console.error('Shader chunk "' + importName + '" not existed in library');
  2878. return '';
  2879. }
  2880. });
  2881. return shaderStr;
  2882. };
  2883. var exportRegex = /(@export)\s*([0-9a-zA-Z_\-\.]*)\s*\n([\s\S]*?)@end/g;
  2884. /**
  2885. * Import shader source
  2886. * @param {string} shaderStr
  2887. * @memberOf clay.Shader
  2888. */
  2889. Shader['import'] = function (shaderStr) {
  2890. shaderStr.replace(exportRegex, function (str, exportSymbol, exportName, code) {
  2891. var code = code.replace(/(^[\s\t\xa0\u3000]+)|([\u3000\xa0\s\t]+\x24)/g, '');
  2892. if (code) {
  2893. var parts = exportName.split('.');
  2894. var obj = Shader.codes;
  2895. var i = 0;
  2896. var key;
  2897. while (i < parts.length - 1) {
  2898. key = parts[i++];
  2899. if (!obj[key]) {
  2900. obj[key] = {};
  2901. }
  2902. obj = obj[key];
  2903. }
  2904. key = parts[i];
  2905. obj[key] = code;
  2906. }
  2907. return code;
  2908. });
  2909. };
  2910. /**
  2911. * Library to store all the loaded shader codes
  2912. * @type {Object}
  2913. * @readOnly
  2914. * @memberOf clay.Shader
  2915. */
  2916. Shader.codes = {};
  2917. /**
  2918. * Get shader source
  2919. * @param {string} name
  2920. * @return {string}
  2921. */
  2922. Shader.source = function (name) {
  2923. var parts = name.split('.');
  2924. var obj = Shader.codes;
  2925. var i = 0;
  2926. while (obj && i < parts.length) {
  2927. var key = parts[i++];
  2928. obj = obj[key];
  2929. }
  2930. if (typeof obj !== 'string') {
  2931. // FIXME Use default instead
  2932. console.error('Shader "' + name + '" not existed in library');
  2933. return '';
  2934. }
  2935. return obj;
  2936. };
  2937. /* harmony default export */ __webpack_exports__["a"] = (Shader);
  2938. /***/
  2939. }),
  2940. /* 9 */
  2941. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  2942. "use strict";
  2943. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__ = __webpack_require__(21);
  2944. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__ = __webpack_require__(12);
  2945. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__glmatrix_quat__ = __webpack_require__(55);
  2946. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__glmatrix_mat3__ = __webpack_require__(34);
  2947. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__Vector3__ = __webpack_require__(3);
  2948. /**
  2949. * @constructor
  2950. * @alias clay.Matrix4
  2951. */
  2952. var Matrix4 = function () {
  2953. this._axisX = new __WEBPACK_IMPORTED_MODULE_4__Vector3__["a" /* default */]();
  2954. this._axisY = new __WEBPACK_IMPORTED_MODULE_4__Vector3__["a" /* default */]();
  2955. this._axisZ = new __WEBPACK_IMPORTED_MODULE_4__Vector3__["a" /* default */]();
  2956. /**
  2957. * Storage of Matrix4
  2958. * @name array
  2959. * @type {Float32Array}
  2960. * @memberOf clay.Matrix4#
  2961. */
  2962. this.array = __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].create();
  2963. /**
  2964. * @name _dirty
  2965. * @type {boolean}
  2966. * @memberOf clay.Matrix4#
  2967. */
  2968. this._dirty = true;
  2969. };
  2970. Matrix4.prototype = {
  2971. constructor: Matrix4,
  2972. /**
  2973. * Set components from array
  2974. * @param {Float32Array|number[]} arr
  2975. */
  2976. setArray: function (arr) {
  2977. for (var i = 0; i < this.array.length; i++) {
  2978. this.array[i] = arr[i];
  2979. }
  2980. this._dirty = true;
  2981. return this;
  2982. },
  2983. /**
  2984. * Calculate the adjugate of self, in-place
  2985. * @return {clay.Matrix4}
  2986. */
  2987. adjoint: function () {
  2988. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].adjoint(this.array, this.array);
  2989. this._dirty = true;
  2990. return this;
  2991. },
  2992. /**
  2993. * Clone a new Matrix4
  2994. * @return {clay.Matrix4}
  2995. */
  2996. clone: function () {
  2997. return (new Matrix4()).copy(this);
  2998. },
  2999. /**
  3000. * Copy from b
  3001. * @param {clay.Matrix4} b
  3002. * @return {clay.Matrix4}
  3003. */
  3004. copy: function (a) {
  3005. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].copy(this.array, a.array);
  3006. this._dirty = true;
  3007. return this;
  3008. },
  3009. /**
  3010. * Calculate matrix determinant
  3011. * @return {number}
  3012. */
  3013. determinant: function () {
  3014. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].determinant(this.array);
  3015. },
  3016. /**
  3017. * Set upper 3x3 part from quaternion
  3018. * @param {clay.Quaternion} q
  3019. * @return {clay.Matrix4}
  3020. */
  3021. fromQuat: function (q) {
  3022. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].fromQuat(this.array, q.array);
  3023. this._dirty = true;
  3024. return this;
  3025. },
  3026. /**
  3027. * Set from a quaternion rotation and a vector translation
  3028. * @param {clay.Quaternion} q
  3029. * @param {clay.Vector3} v
  3030. * @return {clay.Matrix4}
  3031. */
  3032. fromRotationTranslation: function (q, v) {
  3033. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].fromRotationTranslation(this.array, q.array, v.array);
  3034. this._dirty = true;
  3035. return this;
  3036. },
  3037. /**
  3038. * Set from Matrix2d, it is used when converting a 2d shape to 3d space.
  3039. * In 3d space it is equivalent to ranslate on xy plane and rotate about z axis
  3040. * @param {clay.Matrix2d} m2d
  3041. * @return {clay.Matrix4}
  3042. */
  3043. fromMat2d: function (m2d) {
  3044. Matrix4.fromMat2d(this, m2d);
  3045. return this;
  3046. },
  3047. /**
  3048. * Set from frustum bounds
  3049. * @param {number} left
  3050. * @param {number} right
  3051. * @param {number} bottom
  3052. * @param {number} top
  3053. * @param {number} near
  3054. * @param {number} far
  3055. * @return {clay.Matrix4}
  3056. */
  3057. frustum: function (left, right, bottom, top, near, far) {
  3058. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].frustum(this.array, left, right, bottom, top, near, far);
  3059. this._dirty = true;
  3060. return this;
  3061. },
  3062. /**
  3063. * Set to a identity matrix
  3064. * @return {clay.Matrix4}
  3065. */
  3066. identity: function () {
  3067. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].identity(this.array);
  3068. this._dirty = true;
  3069. return this;
  3070. },
  3071. /**
  3072. * Invert self
  3073. * @return {clay.Matrix4}
  3074. */
  3075. invert: function () {
  3076. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].invert(this.array, this.array);
  3077. this._dirty = true;
  3078. return this;
  3079. },
  3080. /**
  3081. * Set as a matrix with the given eye position, focal point, and up axis
  3082. * @param {clay.Vector3} eye
  3083. * @param {clay.Vector3} center
  3084. * @param {clay.Vector3} up
  3085. * @return {clay.Matrix4}
  3086. */
  3087. lookAt: function (eye, center, up) {
  3088. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].lookAt(this.array, eye.array, center.array, up.array);
  3089. this._dirty = true;
  3090. return this;
  3091. },
  3092. /**
  3093. * Alias for mutiply
  3094. * @param {clay.Matrix4} b
  3095. * @return {clay.Matrix4}
  3096. */
  3097. mul: function (b) {
  3098. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].mul(this.array, this.array, b.array);
  3099. this._dirty = true;
  3100. return this;
  3101. },
  3102. /**
  3103. * Alias for multiplyLeft
  3104. * @param {clay.Matrix4} a
  3105. * @return {clay.Matrix4}
  3106. */
  3107. mulLeft: function (a) {
  3108. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].mul(this.array, a.array, this.array);
  3109. this._dirty = true;
  3110. return this;
  3111. },
  3112. /**
  3113. * Multiply self and b
  3114. * @param {clay.Matrix4} b
  3115. * @return {clay.Matrix4}
  3116. */
  3117. multiply: function (b) {
  3118. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].multiply(this.array, this.array, b.array);
  3119. this._dirty = true;
  3120. return this;
  3121. },
  3122. /**
  3123. * Multiply a and self, a is on the left
  3124. * @param {clay.Matrix3} a
  3125. * @return {clay.Matrix3}
  3126. */
  3127. multiplyLeft: function (a) {
  3128. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].multiply(this.array, a.array, this.array);
  3129. this._dirty = true;
  3130. return this;
  3131. },
  3132. /**
  3133. * Set as a orthographic projection matrix
  3134. * @param {number} left
  3135. * @param {number} right
  3136. * @param {number} bottom
  3137. * @param {number} top
  3138. * @param {number} near
  3139. * @param {number} far
  3140. * @return {clay.Matrix4}
  3141. */
  3142. ortho: function (left, right, bottom, top, near, far) {
  3143. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].ortho(this.array, left, right, bottom, top, near, far);
  3144. this._dirty = true;
  3145. return this;
  3146. },
  3147. /**
  3148. * Set as a perspective projection matrix
  3149. * @param {number} fovy
  3150. * @param {number} aspect
  3151. * @param {number} near
  3152. * @param {number} far
  3153. * @return {clay.Matrix4}
  3154. */
  3155. perspective: function (fovy, aspect, near, far) {
  3156. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].perspective(this.array, fovy, aspect, near, far);
  3157. this._dirty = true;
  3158. return this;
  3159. },
  3160. /**
  3161. * Rotate self by rad about axis.
  3162. * Equal to right-multiply a rotaion matrix
  3163. * @param {number} rad
  3164. * @param {clay.Vector3} axis
  3165. * @return {clay.Matrix4}
  3166. */
  3167. rotate: function (rad, axis) {
  3168. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].rotate(this.array, this.array, rad, axis.array);
  3169. this._dirty = true;
  3170. return this;
  3171. },
  3172. /**
  3173. * Rotate self by a given radian about X axis.
  3174. * Equal to right-multiply a rotaion matrix
  3175. * @param {number} rad
  3176. * @return {clay.Matrix4}
  3177. */
  3178. rotateX: function (rad) {
  3179. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].rotateX(this.array, this.array, rad);
  3180. this._dirty = true;
  3181. return this;
  3182. },
  3183. /**
  3184. * Rotate self by a given radian about Y axis.
  3185. * Equal to right-multiply a rotaion matrix
  3186. * @param {number} rad
  3187. * @return {clay.Matrix4}
  3188. */
  3189. rotateY: function (rad) {
  3190. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].rotateY(this.array, this.array, rad);
  3191. this._dirty = true;
  3192. return this;
  3193. },
  3194. /**
  3195. * Rotate self by a given radian about Z axis.
  3196. * Equal to right-multiply a rotaion matrix
  3197. * @param {number} rad
  3198. * @return {clay.Matrix4}
  3199. */
  3200. rotateZ: function (rad) {
  3201. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].rotateZ(this.array, this.array, rad);
  3202. this._dirty = true;
  3203. return this;
  3204. },
  3205. /**
  3206. * Scale self by s
  3207. * Equal to right-multiply a scale matrix
  3208. * @param {clay.Vector3} s
  3209. * @return {clay.Matrix4}
  3210. */
  3211. scale: function (v) {
  3212. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].scale(this.array, this.array, v.array);
  3213. this._dirty = true;
  3214. return this;
  3215. },
  3216. /**
  3217. * Translate self by v.
  3218. * Equal to right-multiply a translate matrix
  3219. * @param {clay.Vector3} v
  3220. * @return {clay.Matrix4}
  3221. */
  3222. translate: function (v) {
  3223. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].translate(this.array, this.array, v.array);
  3224. this._dirty = true;
  3225. return this;
  3226. },
  3227. /**
  3228. * Transpose self, in-place.
  3229. * @return {clay.Matrix2}
  3230. */
  3231. transpose: function () {
  3232. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].transpose(this.array, this.array);
  3233. this._dirty = true;
  3234. return this;
  3235. },
  3236. /**
  3237. * Decompose a matrix to SRT
  3238. * @param {clay.Vector3} [scale]
  3239. * @param {clay.Quaternion} rotation
  3240. * @param {clay.Vector} position
  3241. * @see http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.matrix.decompose.aspx
  3242. */
  3243. decomposeMatrix: (function () {
  3244. var x = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].create();
  3245. var y = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].create();
  3246. var z = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].create();
  3247. var m3 = __WEBPACK_IMPORTED_MODULE_3__glmatrix_mat3__["a" /* default */].create();
  3248. return function (scale, rotation, position) {
  3249. var el = this.array;
  3250. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].set(x, el[0], el[1], el[2]);
  3251. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].set(y, el[4], el[5], el[6]);
  3252. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].set(z, el[8], el[9], el[10]);
  3253. var sx = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].length(x);
  3254. var sy = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].length(y);
  3255. var sz = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].length(z);
  3256. // if determine is negative, we need to invert one scale
  3257. var det = this.determinant();
  3258. if (det < 0) {
  3259. sx = -sx;
  3260. }
  3261. if (scale) {
  3262. scale.set(sx, sy, sz);
  3263. }
  3264. position.set(el[12], el[13], el[14]);
  3265. __WEBPACK_IMPORTED_MODULE_3__glmatrix_mat3__["a" /* default */].fromMat4(m3, el);
  3266. // Not like mat4, mat3 in glmatrix seems to be row-based
  3267. // Seems fixed in gl-matrix 2.2.2
  3268. // https://github.com/toji/gl-matrix/issues/114
  3269. // mat3.transpose(m3, m3);
  3270. m3[0] /= sx;
  3271. m3[1] /= sx;
  3272. m3[2] /= sx;
  3273. m3[3] /= sy;
  3274. m3[4] /= sy;
  3275. m3[5] /= sy;
  3276. m3[6] /= sz;
  3277. m3[7] /= sz;
  3278. m3[8] /= sz;
  3279. __WEBPACK_IMPORTED_MODULE_2__glmatrix_quat__["a" /* default */].fromMat3(rotation.array, m3);
  3280. __WEBPACK_IMPORTED_MODULE_2__glmatrix_quat__["a" /* default */].normalize(rotation.array, rotation.array);
  3281. rotation._dirty = true;
  3282. position._dirty = true;
  3283. };
  3284. })(),
  3285. toString: function () {
  3286. return '[' + Array.prototype.join.call(this.array, ',') + ']';
  3287. },
  3288. toArray: function () {
  3289. return Array.prototype.slice.call(this.array);
  3290. }
  3291. };
  3292. var defineProperty = Object.defineProperty;
  3293. if (defineProperty) {
  3294. var proto = Matrix4.prototype;
  3295. /**
  3296. * Z Axis of local transform
  3297. * @name z
  3298. * @type {clay.Vector3}
  3299. * @memberOf clay.Matrix4
  3300. * @instance
  3301. */
  3302. defineProperty(proto, 'z', {
  3303. get: function () {
  3304. var el = this.array;
  3305. this._axisZ.set(el[8], el[9], el[10]);
  3306. return this._axisZ;
  3307. },
  3308. set: function (v) {
  3309. // TODO Here has a problem
  3310. // If only set an item of vector will not work
  3311. var el = this.array;
  3312. v = v.array;
  3313. el[8] = v[0];
  3314. el[9] = v[1];
  3315. el[10] = v[2];
  3316. this._dirty = true;
  3317. }
  3318. });
  3319. /**
  3320. * Y Axis of local transform
  3321. * @name y
  3322. * @type {clay.Vector3}
  3323. * @memberOf clay.Matrix4
  3324. * @instance
  3325. */
  3326. defineProperty(proto, 'y', {
  3327. get: function () {
  3328. var el = this.array;
  3329. this._axisY.set(el[4], el[5], el[6]);
  3330. return this._axisY;
  3331. },
  3332. set: function (v) {
  3333. var el = this.array;
  3334. v = v.array;
  3335. el[4] = v[0];
  3336. el[5] = v[1];
  3337. el[6] = v[2];
  3338. this._dirty = true;
  3339. }
  3340. });
  3341. /**
  3342. * X Axis of local transform
  3343. * @name x
  3344. * @type {clay.Vector3}
  3345. * @memberOf clay.Matrix4
  3346. * @instance
  3347. */
  3348. defineProperty(proto, 'x', {
  3349. get: function () {
  3350. var el = this.array;
  3351. this._axisX.set(el[0], el[1], el[2]);
  3352. return this._axisX;
  3353. },
  3354. set: function (v) {
  3355. var el = this.array;
  3356. v = v.array;
  3357. el[0] = v[0];
  3358. el[1] = v[1];
  3359. el[2] = v[2];
  3360. this._dirty = true;
  3361. }
  3362. })
  3363. }
  3364. /**
  3365. * @param {clay.Matrix4} out
  3366. * @param {clay.Matrix4} a
  3367. * @return {clay.Matrix4}
  3368. */
  3369. Matrix4.adjoint = function (out, a) {
  3370. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].adjoint(out.array, a.array);
  3371. out._dirty = true;
  3372. return out;
  3373. };
  3374. /**
  3375. * @param {clay.Matrix4} out
  3376. * @param {clay.Matrix4} a
  3377. * @return {clay.Matrix4}
  3378. */
  3379. Matrix4.copy = function (out, a) {
  3380. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].copy(out.array, a.array);
  3381. out._dirty = true;
  3382. return out;
  3383. };
  3384. /**
  3385. * @param {clay.Matrix4} a
  3386. * @return {number}
  3387. */
  3388. Matrix4.determinant = function (a) {
  3389. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].determinant(a.array);
  3390. };
  3391. /**
  3392. * @param {clay.Matrix4} out
  3393. * @return {clay.Matrix4}
  3394. */
  3395. Matrix4.identity = function (out) {
  3396. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].identity(out.array);
  3397. out._dirty = true;
  3398. return out;
  3399. };
  3400. /**
  3401. * @param {clay.Matrix4} out
  3402. * @param {number} left
  3403. * @param {number} right
  3404. * @param {number} bottom
  3405. * @param {number} top
  3406. * @param {number} near
  3407. * @param {number} far
  3408. * @return {clay.Matrix4}
  3409. */
  3410. Matrix4.ortho = function (out, left, right, bottom, top, near, far) {
  3411. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].ortho(out.array, left, right, bottom, top, near, far);
  3412. out._dirty = true;
  3413. return out;
  3414. };
  3415. /**
  3416. * @param {clay.Matrix4} out
  3417. * @param {number} fovy
  3418. * @param {number} aspect
  3419. * @param {number} near
  3420. * @param {number} far
  3421. * @return {clay.Matrix4}
  3422. */
  3423. Matrix4.perspective = function (out, fovy, aspect, near, far) {
  3424. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].perspective(out.array, fovy, aspect, near, far);
  3425. out._dirty = true;
  3426. return out;
  3427. };
  3428. /**
  3429. * @param {clay.Matrix4} out
  3430. * @param {clay.Vector3} eye
  3431. * @param {clay.Vector3} center
  3432. * @param {clay.Vector3} up
  3433. * @return {clay.Matrix4}
  3434. */
  3435. Matrix4.lookAt = function (out, eye, center, up) {
  3436. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].lookAt(out.array, eye.array, center.array, up.array);
  3437. out._dirty = true;
  3438. return out;
  3439. };
  3440. /**
  3441. * @param {clay.Matrix4} out
  3442. * @param {clay.Matrix4} a
  3443. * @return {clay.Matrix4}
  3444. */
  3445. Matrix4.invert = function (out, a) {
  3446. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].invert(out.array, a.array);
  3447. out._dirty = true;
  3448. return out;
  3449. };
  3450. /**
  3451. * @param {clay.Matrix4} out
  3452. * @param {clay.Matrix4} a
  3453. * @param {clay.Matrix4} b
  3454. * @return {clay.Matrix4}
  3455. */
  3456. Matrix4.mul = function (out, a, b) {
  3457. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].mul(out.array, a.array, b.array);
  3458. out._dirty = true;
  3459. return out;
  3460. };
  3461. /**
  3462. * @function
  3463. * @param {clay.Matrix4} out
  3464. * @param {clay.Matrix4} a
  3465. * @param {clay.Matrix4} b
  3466. * @return {clay.Matrix4}
  3467. */
  3468. Matrix4.multiply = Matrix4.mul;
  3469. /**
  3470. * @param {clay.Matrix4} out
  3471. * @param {clay.Quaternion} q
  3472. * @return {clay.Matrix4}
  3473. */
  3474. Matrix4.fromQuat = function (out, q) {
  3475. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].fromQuat(out.array, q.array);
  3476. out._dirty = true;
  3477. return out;
  3478. };
  3479. /**
  3480. * @param {clay.Matrix4} out
  3481. * @param {clay.Quaternion} q
  3482. * @param {clay.Vector3} v
  3483. * @return {clay.Matrix4}
  3484. */
  3485. Matrix4.fromRotationTranslation = function (out, q, v) {
  3486. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].fromRotationTranslation(out.array, q.array, v.array);
  3487. out._dirty = true;
  3488. return out;
  3489. };
  3490. /**
  3491. * @param {clay.Matrix4} m4
  3492. * @param {clay.Matrix2d} m2d
  3493. * @return {clay.Matrix4}
  3494. */
  3495. Matrix4.fromMat2d = function (m4, m2d) {
  3496. m4._dirty = true;
  3497. var m2d = m2d.array;
  3498. var m4 = m4.array;
  3499. m4[0] = m2d[0];
  3500. m4[4] = m2d[2];
  3501. m4[12] = m2d[4];
  3502. m4[1] = m2d[1];
  3503. m4[5] = m2d[3];
  3504. m4[13] = m2d[5];
  3505. return m4;
  3506. };
  3507. /**
  3508. * @param {clay.Matrix4} out
  3509. * @param {clay.Matrix4} a
  3510. * @param {number} rad
  3511. * @param {clay.Vector3} axis
  3512. * @return {clay.Matrix4}
  3513. */
  3514. Matrix4.rotate = function (out, a, rad, axis) {
  3515. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].rotate(out.array, a.array, rad, axis.array);
  3516. out._dirty = true;
  3517. return out;
  3518. };
  3519. /**
  3520. * @param {clay.Matrix4} out
  3521. * @param {clay.Matrix4} a
  3522. * @param {number} rad
  3523. * @return {clay.Matrix4}
  3524. */
  3525. Matrix4.rotateX = function (out, a, rad) {
  3526. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].rotateX(out.array, a.array, rad);
  3527. out._dirty = true;
  3528. return out;
  3529. };
  3530. /**
  3531. * @param {clay.Matrix4} out
  3532. * @param {clay.Matrix4} a
  3533. * @param {number} rad
  3534. * @return {clay.Matrix4}
  3535. */
  3536. Matrix4.rotateY = function (out, a, rad) {
  3537. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].rotateY(out.array, a.array, rad);
  3538. out._dirty = true;
  3539. return out;
  3540. };
  3541. /**
  3542. * @param {clay.Matrix4} out
  3543. * @param {clay.Matrix4} a
  3544. * @param {number} rad
  3545. * @return {clay.Matrix4}
  3546. */
  3547. Matrix4.rotateZ = function (out, a, rad) {
  3548. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].rotateZ(out.array, a.array, rad);
  3549. out._dirty = true;
  3550. return out;
  3551. };
  3552. /**
  3553. * @param {clay.Matrix4} out
  3554. * @param {clay.Matrix4} a
  3555. * @param {clay.Vector3} v
  3556. * @return {clay.Matrix4}
  3557. */
  3558. Matrix4.scale = function (out, a, v) {
  3559. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].scale(out.array, a.array, v.array);
  3560. out._dirty = true;
  3561. return out;
  3562. };
  3563. /**
  3564. * @param {clay.Matrix4} out
  3565. * @param {clay.Matrix4} a
  3566. * @return {clay.Matrix4}
  3567. */
  3568. Matrix4.transpose = function (out, a) {
  3569. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].transpose(out.array, a.array);
  3570. out._dirty = true;
  3571. return out;
  3572. };
  3573. /**
  3574. * @param {clay.Matrix4} out
  3575. * @param {clay.Matrix4} a
  3576. * @param {clay.Vector3} v
  3577. * @return {clay.Matrix4}
  3578. */
  3579. Matrix4.translate = function (out, a, v) {
  3580. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat4__["a" /* default */].translate(out.array, a.array, v.array);
  3581. out._dirty = true;
  3582. return out;
  3583. };
  3584. /* harmony default export */ __webpack_exports__["a"] = (Matrix4);
  3585. /***/
  3586. }),
  3587. /* 10 */
  3588. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  3589. "use strict";
  3590. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__core_Base__ = __webpack_require__(7);
  3591. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__Texture__ = __webpack_require__(4);
  3592. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__TextureCube__ = __webpack_require__(27);
  3593. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__core_glenum__ = __webpack_require__(11);
  3594. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__core_Cache__ = __webpack_require__(57);
  3595. var KEY_FRAMEBUFFER = 'framebuffer';
  3596. var KEY_RENDERBUFFER = 'renderbuffer';
  3597. var KEY_RENDERBUFFER_WIDTH = KEY_RENDERBUFFER + '_width';
  3598. var KEY_RENDERBUFFER_HEIGHT = KEY_RENDERBUFFER + '_height';
  3599. var KEY_RENDERBUFFER_ATTACHED = KEY_RENDERBUFFER + '_attached';
  3600. var KEY_DEPTHTEXTURE_ATTACHED = 'depthtexture_attached';
  3601. var GL_FRAMEBUFFER = __WEBPACK_IMPORTED_MODULE_3__core_glenum__["a" /* default */].FRAMEBUFFER;
  3602. var GL_RENDERBUFFER = __WEBPACK_IMPORTED_MODULE_3__core_glenum__["a" /* default */].RENDERBUFFER;
  3603. var GL_DEPTH_ATTACHMENT = __WEBPACK_IMPORTED_MODULE_3__core_glenum__["a" /* default */].DEPTH_ATTACHMENT;
  3604. var GL_COLOR_ATTACHMENT0 = __WEBPACK_IMPORTED_MODULE_3__core_glenum__["a" /* default */].COLOR_ATTACHMENT0;
  3605. /**
  3606. * @constructor clay.FrameBuffer
  3607. * @extends clay.core.Base
  3608. */
  3609. var FrameBuffer = __WEBPACK_IMPORTED_MODULE_0__core_Base__["a" /* default */].extend(
  3610. /** @lends clay.FrameBuffer# */
  3611. {
  3612. /**
  3613. * If use depth buffer
  3614. * @type {boolean}
  3615. */
  3616. depthBuffer: true,
  3617. /**
  3618. * @type {Object}
  3619. */
  3620. viewport: null,
  3621. _width: 0,
  3622. _height: 0,
  3623. _textures: null,
  3624. _boundRenderer: null,
  3625. }, function () {
  3626. // Use cache
  3627. this._cache = new __WEBPACK_IMPORTED_MODULE_4__core_Cache__["a" /* default */]();
  3628. this._textures = {};
  3629. },
  3630. /**@lends clay.FrameBuffer.prototype. */
  3631. {
  3632. /**
  3633. * Get attached texture width
  3634. * {number}
  3635. */
  3636. // FIXME Can't use before #bind
  3637. getTextureWidth: function () {
  3638. return this._width;
  3639. },
  3640. /**
  3641. * Get attached texture height
  3642. * {number}
  3643. */
  3644. getTextureHeight: function () {
  3645. return this._height;
  3646. },
  3647. /**
  3648. * Bind the framebuffer to given renderer before rendering
  3649. * @param {clay.Renderer} renderer
  3650. */
  3651. bind: function (renderer) {
  3652. if (renderer.__currentFrameBuffer) {
  3653. // Already bound
  3654. if (renderer.__currentFrameBuffer === this) {
  3655. return;
  3656. }
  3657. console.warn('Renderer already bound with another framebuffer. Unbind it first');
  3658. }
  3659. renderer.__currentFrameBuffer = this;
  3660. var _gl = renderer.gl;
  3661. _gl.bindFramebuffer(GL_FRAMEBUFFER, this._getFrameBufferGL(renderer));
  3662. this._boundRenderer = renderer;
  3663. var cache = this._cache;
  3664. cache.put('viewport', renderer.viewport);
  3665. var hasTextureAttached = false;
  3666. var width;
  3667. var height;
  3668. for (var attachment in this._textures) {
  3669. hasTextureAttached = true;
  3670. var obj = this._textures[attachment];
  3671. if (obj) {
  3672. // TODO Do width, height checking, make sure size are same
  3673. width = obj.texture.width;
  3674. height = obj.texture.height;
  3675. // Attach textures
  3676. this._doAttach(renderer, obj.texture, attachment, obj.target);
  3677. }
  3678. }
  3679. this._width = width;
  3680. this._height = height;
  3681. if (!hasTextureAttached && this.depthBuffer) {
  3682. console.error('Must attach texture before bind, or renderbuffer may have incorrect width and height.')
  3683. }
  3684. if (this.viewport) {
  3685. renderer.setViewport(this.viewport);
  3686. }
  3687. else {
  3688. renderer.setViewport(0, 0, width, height, 1);
  3689. }
  3690. var attachedTextures = cache.get('attached_textures');
  3691. if (attachedTextures) {
  3692. for (var attachment in attachedTextures) {
  3693. if (!this._textures[attachment]) {
  3694. var target = attachedTextures[attachment];
  3695. this._doDetach(_gl, attachment, target);
  3696. }
  3697. }
  3698. }
  3699. if (!cache.get(KEY_DEPTHTEXTURE_ATTACHED) && this.depthBuffer) {
  3700. // Create a new render buffer
  3701. if (cache.miss(KEY_RENDERBUFFER)) {
  3702. cache.put(KEY_RENDERBUFFER, _gl.createRenderbuffer());
  3703. }
  3704. var renderbuffer = cache.get(KEY_RENDERBUFFER);
  3705. if (width !== cache.get(KEY_RENDERBUFFER_WIDTH)
  3706. || height !== cache.get(KEY_RENDERBUFFER_HEIGHT)) {
  3707. _gl.bindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
  3708. _gl.renderbufferStorage(GL_RENDERBUFFER, _gl.DEPTH_COMPONENT16, width, height);
  3709. cache.put(KEY_RENDERBUFFER_WIDTH, width);
  3710. cache.put(KEY_RENDERBUFFER_HEIGHT, height);
  3711. _gl.bindRenderbuffer(GL_RENDERBUFFER, null);
  3712. }
  3713. if (!cache.get(KEY_RENDERBUFFER_ATTACHED)) {
  3714. _gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
  3715. cache.put(KEY_RENDERBUFFER_ATTACHED, true);
  3716. }
  3717. }
  3718. },
  3719. /**
  3720. * Unbind the frame buffer after rendering
  3721. * @param {clay.Renderer} renderer
  3722. */
  3723. unbind: function (renderer) {
  3724. // Remove status record on renderer
  3725. renderer.__currentFrameBuffer = null;
  3726. var _gl = renderer.gl;
  3727. _gl.bindFramebuffer(GL_FRAMEBUFFER, null);
  3728. this._boundRenderer = null;
  3729. this._cache.use(renderer.__uid__);
  3730. var viewport = this._cache.get('viewport');
  3731. // Reset viewport;
  3732. if (viewport) {
  3733. renderer.setViewport(viewport);
  3734. }
  3735. this.updateMipmap(renderer);
  3736. },
  3737. // Because the data of texture is changed over time,
  3738. // Here update the mipmaps of texture each time after rendered;
  3739. updateMipmap: function (renderer) {
  3740. var _gl = renderer.gl;
  3741. for (var attachment in this._textures) {
  3742. var obj = this._textures[attachment];
  3743. if (obj) {
  3744. var texture = obj.texture;
  3745. // FIXME some texture format can't generate mipmap
  3746. if (!texture.NPOT && texture.useMipmap
  3747. && texture.minFilter === __WEBPACK_IMPORTED_MODULE_1__Texture__["a" /* default */].LINEAR_MIPMAP_LINEAR) {
  3748. var target = texture.textureType === 'textureCube' ? __WEBPACK_IMPORTED_MODULE_3__core_glenum__["a" /* default */].TEXTURE_CUBE_MAP : __WEBPACK_IMPORTED_MODULE_3__core_glenum__["a" /* default */].TEXTURE_2D;
  3749. _gl.bindTexture(target, texture.getWebGLTexture(renderer));
  3750. _gl.generateMipmap(target);
  3751. _gl.bindTexture(target, null);
  3752. }
  3753. }
  3754. }
  3755. },
  3756. // 0x8CD5, 36053, FRAMEBUFFER_COMPLETE
  3757. // 0x8CD6, 36054, FRAMEBUFFER_INCOMPLETE_ATTACHMENT
  3758. // 0x8CD7, 36055, FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
  3759. // 0x8CD9, 36057, FRAMEBUFFER_INCOMPLETE_DIMENSIONS
  3760. // 0x8CDD, 36061, FRAMEBUFFER_UNSUPPORTED
  3761. checkStatus: function (_gl) {
  3762. return _gl.checkFramebufferStatus(GL_FRAMEBUFFER);
  3763. },
  3764. _getFrameBufferGL: function (renderer) {
  3765. var cache = this._cache;
  3766. cache.use(renderer.__uid__);
  3767. if (cache.miss(KEY_FRAMEBUFFER)) {
  3768. cache.put(KEY_FRAMEBUFFER, renderer.gl.createFramebuffer());
  3769. }
  3770. return cache.get(KEY_FRAMEBUFFER);
  3771. },
  3772. /**
  3773. * Attach a texture(RTT) to the framebuffer
  3774. * @param {clay.Texture} texture
  3775. * @param {number} [attachment=gl.COLOR_ATTACHMENT0]
  3776. * @param {number} [target=gl.TEXTURE_2D]
  3777. */
  3778. attach: function (texture, attachment, target) {
  3779. if (!texture.width) {
  3780. throw new Error('The texture attached to color buffer is not a valid.');
  3781. }
  3782. // TODO width and height check
  3783. // If the depth_texture extension is enabled, developers
  3784. // Can attach a depth texture to the depth buffer
  3785. // http://blog.tojicode.com/2012/07/using-webgldepthtexture.html
  3786. attachment = attachment || GL_COLOR_ATTACHMENT0;
  3787. target = target || __WEBPACK_IMPORTED_MODULE_3__core_glenum__["a" /* default */].TEXTURE_2D;
  3788. var boundRenderer = this._boundRenderer;
  3789. var _gl = boundRenderer && boundRenderer.gl;
  3790. var attachedTextures;
  3791. if (_gl) {
  3792. var cache = this._cache;
  3793. cache.use(boundRenderer.__uid__);
  3794. attachedTextures = cache.get('attached_textures');
  3795. }
  3796. // Check if texture attached
  3797. var previous = this._textures[attachment];
  3798. if (previous && previous.target === target
  3799. && previous.texture === texture
  3800. && (attachedTextures && attachedTextures[attachment] != null)
  3801. ) {
  3802. return;
  3803. }
  3804. var canAttach = true;
  3805. if (boundRenderer) {
  3806. canAttach = this._doAttach(boundRenderer, texture, attachment, target);
  3807. // Set viewport again incase attached to different size textures.
  3808. if (!this.viewport) {
  3809. boundRenderer.setViewport(0, 0, texture.width, texture.height, 1);
  3810. }
  3811. }
  3812. if (canAttach) {
  3813. this._textures[attachment] = this._textures[attachment] || {};
  3814. this._textures[attachment].texture = texture;
  3815. this._textures[attachment].target = target;
  3816. }
  3817. },
  3818. _doAttach: function (renderer, texture, attachment, target) {
  3819. var _gl = renderer.gl;
  3820. // Make sure texture is always updated
  3821. // Because texture width or height may be changed and in this we can't be notified
  3822. // FIXME awkward;
  3823. var webglTexture = texture.getWebGLTexture(renderer);
  3824. // Assume cache has been used.
  3825. var attachedTextures = this._cache.get('attached_textures');
  3826. if (attachedTextures && attachedTextures[attachment]) {
  3827. var obj = attachedTextures[attachment];
  3828. // Check if texture and target not changed
  3829. if (obj.texture === texture && obj.target === target) {
  3830. return;
  3831. }
  3832. }
  3833. attachment = +attachment;
  3834. var canAttach = true;
  3835. if (attachment === GL_DEPTH_ATTACHMENT || attachment === __WEBPACK_IMPORTED_MODULE_3__core_glenum__["a" /* default */].DEPTH_STENCIL_ATTACHMENT) {
  3836. var extension = renderer.getGLExtension('WEBGL_depth_texture');
  3837. if (!extension) {
  3838. console.error('Depth texture is not supported by the browser');
  3839. canAttach = false;
  3840. }
  3841. if (texture.format !== __WEBPACK_IMPORTED_MODULE_3__core_glenum__["a" /* default */].DEPTH_COMPONENT
  3842. && texture.format !== __WEBPACK_IMPORTED_MODULE_3__core_glenum__["a" /* default */].DEPTH_STENCIL
  3843. ) {
  3844. console.error('The texture attached to depth buffer is not a valid.');
  3845. canAttach = false;
  3846. }
  3847. // Dispose render buffer created previous
  3848. if (canAttach) {
  3849. var renderbuffer = this._cache.get(KEY_RENDERBUFFER);
  3850. if (renderbuffer) {
  3851. _gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, null);
  3852. _gl.deleteRenderbuffer(renderbuffer);
  3853. this._cache.put(KEY_RENDERBUFFER, false);
  3854. }
  3855. this._cache.put(KEY_RENDERBUFFER_ATTACHED, false);
  3856. this._cache.put(KEY_DEPTHTEXTURE_ATTACHED, true);
  3857. }
  3858. }
  3859. // Mipmap level can only be 0
  3860. _gl.framebufferTexture2D(GL_FRAMEBUFFER, attachment, target, webglTexture, 0);
  3861. if (!attachedTextures) {
  3862. attachedTextures = {};
  3863. this._cache.put('attached_textures', attachedTextures);
  3864. }
  3865. attachedTextures[attachment] = attachedTextures[attachment] || {};
  3866. attachedTextures[attachment].texture = texture;
  3867. attachedTextures[attachment].target = target;
  3868. return canAttach;
  3869. },
  3870. _doDetach: function (_gl, attachment, target) {
  3871. // Detach a texture from framebuffer
  3872. // https://github.com/KhronosGroup/WebGL/blob/master/conformance-suites/1.0.0/conformance/framebuffer-test.html#L145
  3873. _gl.framebufferTexture2D(GL_FRAMEBUFFER, attachment, target, null, 0);
  3874. // Assume cache has been used.
  3875. var attachedTextures = this._cache.get('attached_textures');
  3876. if (attachedTextures && attachedTextures[attachment]) {
  3877. attachedTextures[attachment] = null;
  3878. }
  3879. if (attachment === GL_DEPTH_ATTACHMENT || attachment === __WEBPACK_IMPORTED_MODULE_3__core_glenum__["a" /* default */].DEPTH_STENCIL_ATTACHMENT) {
  3880. this._cache.put(KEY_DEPTHTEXTURE_ATTACHED, false);
  3881. }
  3882. },
  3883. /**
  3884. * Detach a texture
  3885. * @param {number} [attachment=gl.COLOR_ATTACHMENT0]
  3886. * @param {number} [target=gl.TEXTURE_2D]
  3887. */
  3888. detach: function (attachment, target) {
  3889. // TODO depth extension check ?
  3890. this._textures[attachment] = null;
  3891. if (this._boundRenderer) {
  3892. var cache = this._cache;
  3893. cache.use(this._boundRenderer.__uid__);
  3894. this._doDetach(this._boundRenderer.gl, attachment, target);
  3895. }
  3896. },
  3897. /**
  3898. * Dispose
  3899. * @param {WebGLRenderingContext} _gl
  3900. */
  3901. dispose: function (renderer) {
  3902. var _gl = renderer.gl;
  3903. var cache = this._cache;
  3904. cache.use(renderer.__uid__);
  3905. var renderBuffer = cache.get(KEY_RENDERBUFFER);
  3906. if (renderBuffer) {
  3907. _gl.deleteRenderbuffer(renderBuffer);
  3908. }
  3909. var frameBuffer = cache.get(KEY_FRAMEBUFFER);
  3910. if (frameBuffer) {
  3911. _gl.deleteFramebuffer(frameBuffer);
  3912. }
  3913. cache.deleteContext(renderer.__uid__);
  3914. // Clear cache for reusing
  3915. this._textures = {};
  3916. }
  3917. });
  3918. FrameBuffer.DEPTH_ATTACHMENT = GL_DEPTH_ATTACHMENT;
  3919. FrameBuffer.COLOR_ATTACHMENT0 = GL_COLOR_ATTACHMENT0;
  3920. FrameBuffer.STENCIL_ATTACHMENT = __WEBPACK_IMPORTED_MODULE_3__core_glenum__["a" /* default */].STENCIL_ATTACHMENT;
  3921. FrameBuffer.DEPTH_STENCIL_ATTACHMENT = __WEBPACK_IMPORTED_MODULE_3__core_glenum__["a" /* default */].DEPTH_STENCIL_ATTACHMENT;
  3922. /* harmony default export */ __webpack_exports__["a"] = (FrameBuffer);
  3923. /***/
  3924. }),
  3925. /* 11 */
  3926. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  3927. "use strict";
  3928. /**
  3929. * @namespace clay.core.glenum
  3930. * @see http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14
  3931. */
  3932. /* harmony default export */ __webpack_exports__["a"] = ({
  3933. /* ClearBufferMask */
  3934. DEPTH_BUFFER_BIT: 0x00000100,
  3935. STENCIL_BUFFER_BIT: 0x00000400,
  3936. COLOR_BUFFER_BIT: 0x00004000,
  3937. /* BeginMode */
  3938. POINTS: 0x0000,
  3939. LINES: 0x0001,
  3940. LINE_LOOP: 0x0002,
  3941. LINE_STRIP: 0x0003,
  3942. TRIANGLES: 0x0004,
  3943. TRIANGLE_STRIP: 0x0005,
  3944. TRIANGLE_FAN: 0x0006,
  3945. /* AlphaFunction (not supported in ES20) */
  3946. /* NEVER */
  3947. /* LESS */
  3948. /* EQUAL */
  3949. /* LEQUAL */
  3950. /* GREATER */
  3951. /* NOTEQUAL */
  3952. /* GEQUAL */
  3953. /* ALWAYS */
  3954. /* BlendingFactorDest */
  3955. ZERO: 0,
  3956. ONE: 1,
  3957. SRC_COLOR: 0x0300,
  3958. ONE_MINUS_SRC_COLOR: 0x0301,
  3959. SRC_ALPHA: 0x0302,
  3960. ONE_MINUS_SRC_ALPHA: 0x0303,
  3961. DST_ALPHA: 0x0304,
  3962. ONE_MINUS_DST_ALPHA: 0x0305,
  3963. /* BlendingFactorSrc */
  3964. /* ZERO */
  3965. /* ONE */
  3966. DST_COLOR: 0x0306,
  3967. ONE_MINUS_DST_COLOR: 0x0307,
  3968. SRC_ALPHA_SATURATE: 0x0308,
  3969. /* SRC_ALPHA */
  3970. /* ONE_MINUS_SRC_ALPHA */
  3971. /* DST_ALPHA */
  3972. /* ONE_MINUS_DST_ALPHA */
  3973. /* BlendEquationSeparate */
  3974. FUNC_ADD: 0x8006,
  3975. BLEND_EQUATION: 0x8009,
  3976. BLEND_EQUATION_RGB: 0x8009, /* same as BLEND_EQUATION */
  3977. BLEND_EQUATION_ALPHA: 0x883D,
  3978. /* BlendSubtract */
  3979. FUNC_SUBTRACT: 0x800A,
  3980. FUNC_REVERSE_SUBTRACT: 0x800B,
  3981. /* Separate Blend Functions */
  3982. BLEND_DST_RGB: 0x80C8,
  3983. BLEND_SRC_RGB: 0x80C9,
  3984. BLEND_DST_ALPHA: 0x80CA,
  3985. BLEND_SRC_ALPHA: 0x80CB,
  3986. CONSTANT_COLOR: 0x8001,
  3987. ONE_MINUS_CONSTANT_COLOR: 0x8002,
  3988. CONSTANT_ALPHA: 0x8003,
  3989. ONE_MINUS_CONSTANT_ALPHA: 0x8004,
  3990. BLEND_COLOR: 0x8005,
  3991. /* Buffer Objects */
  3992. ARRAY_BUFFER: 0x8892,
  3993. ELEMENT_ARRAY_BUFFER: 0x8893,
  3994. ARRAY_BUFFER_BINDING: 0x8894,
  3995. ELEMENT_ARRAY_BUFFER_BINDING: 0x8895,
  3996. STREAM_DRAW: 0x88E0,
  3997. STATIC_DRAW: 0x88E4,
  3998. DYNAMIC_DRAW: 0x88E8,
  3999. BUFFER_SIZE: 0x8764,
  4000. BUFFER_USAGE: 0x8765,
  4001. CURRENT_VERTEX_ATTRIB: 0x8626,
  4002. /* CullFaceMode */
  4003. FRONT: 0x0404,
  4004. BACK: 0x0405,
  4005. FRONT_AND_BACK: 0x0408,
  4006. /* DepthFunction */
  4007. /* NEVER */
  4008. /* LESS */
  4009. /* EQUAL */
  4010. /* LEQUAL */
  4011. /* GREATER */
  4012. /* NOTEQUAL */
  4013. /* GEQUAL */
  4014. /* ALWAYS */
  4015. /* EnableCap */
  4016. /* TEXTURE_2D */
  4017. CULL_FACE: 0x0B44,
  4018. BLEND: 0x0BE2,
  4019. DITHER: 0x0BD0,
  4020. STENCIL_TEST: 0x0B90,
  4021. DEPTH_TEST: 0x0B71,
  4022. SCISSOR_TEST: 0x0C11,
  4023. POLYGON_OFFSET_FILL: 0x8037,
  4024. SAMPLE_ALPHA_TO_COVERAGE: 0x809E,
  4025. SAMPLE_COVERAGE: 0x80A0,
  4026. /* ErrorCode */
  4027. NO_ERROR: 0,
  4028. INVALID_ENUM: 0x0500,
  4029. INVALID_VALUE: 0x0501,
  4030. INVALID_OPERATION: 0x0502,
  4031. OUT_OF_MEMORY: 0x0505,
  4032. /* FrontFaceDirection */
  4033. CW: 0x0900,
  4034. CCW: 0x0901,
  4035. /* GetPName */
  4036. LINE_WIDTH: 0x0B21,
  4037. ALIASED_POINT_SIZE_RANGE: 0x846D,
  4038. ALIASED_LINE_WIDTH_RANGE: 0x846E,
  4039. CULL_FACE_MODE: 0x0B45,
  4040. FRONT_FACE: 0x0B46,
  4041. DEPTH_RANGE: 0x0B70,
  4042. DEPTH_WRITEMASK: 0x0B72,
  4043. DEPTH_CLEAR_VALUE: 0x0B73,
  4044. DEPTH_FUNC: 0x0B74,
  4045. STENCIL_CLEAR_VALUE: 0x0B91,
  4046. STENCIL_FUNC: 0x0B92,
  4047. STENCIL_FAIL: 0x0B94,
  4048. STENCIL_PASS_DEPTH_FAIL: 0x0B95,
  4049. STENCIL_PASS_DEPTH_PASS: 0x0B96,
  4050. STENCIL_REF: 0x0B97,
  4051. STENCIL_VALUE_MASK: 0x0B93,
  4052. STENCIL_WRITEMASK: 0x0B98,
  4053. STENCIL_BACK_FUNC: 0x8800,
  4054. STENCIL_BACK_FAIL: 0x8801,
  4055. STENCIL_BACK_PASS_DEPTH_FAIL: 0x8802,
  4056. STENCIL_BACK_PASS_DEPTH_PASS: 0x8803,
  4057. STENCIL_BACK_REF: 0x8CA3,
  4058. STENCIL_BACK_VALUE_MASK: 0x8CA4,
  4059. STENCIL_BACK_WRITEMASK: 0x8CA5,
  4060. VIEWPORT: 0x0BA2,
  4061. SCISSOR_BOX: 0x0C10,
  4062. /* SCISSOR_TEST */
  4063. COLOR_CLEAR_VALUE: 0x0C22,
  4064. COLOR_WRITEMASK: 0x0C23,
  4065. UNPACK_ALIGNMENT: 0x0CF5,
  4066. PACK_ALIGNMENT: 0x0D05,
  4067. MAX_TEXTURE_SIZE: 0x0D33,
  4068. MAX_VIEWPORT_DIMS: 0x0D3A,
  4069. SUBPIXEL_BITS: 0x0D50,
  4070. RED_BITS: 0x0D52,
  4071. GREEN_BITS: 0x0D53,
  4072. BLUE_BITS: 0x0D54,
  4073. ALPHA_BITS: 0x0D55,
  4074. DEPTH_BITS: 0x0D56,
  4075. STENCIL_BITS: 0x0D57,
  4076. POLYGON_OFFSET_UNITS: 0x2A00,
  4077. /* POLYGON_OFFSET_FILL */
  4078. POLYGON_OFFSET_FACTOR: 0x8038,
  4079. TEXTURE_BINDING_2D: 0x8069,
  4080. SAMPLE_BUFFERS: 0x80A8,
  4081. SAMPLES: 0x80A9,
  4082. SAMPLE_COVERAGE_VALUE: 0x80AA,
  4083. SAMPLE_COVERAGE_INVERT: 0x80AB,
  4084. /* GetTextureParameter */
  4085. /* TEXTURE_MAG_FILTER */
  4086. /* TEXTURE_MIN_FILTER */
  4087. /* TEXTURE_WRAP_S */
  4088. /* TEXTURE_WRAP_T */
  4089. COMPRESSED_TEXTURE_FORMATS: 0x86A3,
  4090. /* HintMode */
  4091. DONT_CARE: 0x1100,
  4092. FASTEST: 0x1101,
  4093. NICEST: 0x1102,
  4094. /* HintTarget */
  4095. GENERATE_MIPMAP_HINT: 0x8192,
  4096. /* DataType */
  4097. BYTE: 0x1400,
  4098. UNSIGNED_BYTE: 0x1401,
  4099. SHORT: 0x1402,
  4100. UNSIGNED_SHORT: 0x1403,
  4101. INT: 0x1404,
  4102. UNSIGNED_INT: 0x1405,
  4103. FLOAT: 0x1406,
  4104. /* PixelFormat */
  4105. DEPTH_COMPONENT: 0x1902,
  4106. ALPHA: 0x1906,
  4107. RGB: 0x1907,
  4108. RGBA: 0x1908,
  4109. LUMINANCE: 0x1909,
  4110. LUMINANCE_ALPHA: 0x190A,
  4111. /* PixelType */
  4112. /* UNSIGNED_BYTE */
  4113. UNSIGNED_SHORT_4_4_4_4: 0x8033,
  4114. UNSIGNED_SHORT_5_5_5_1: 0x8034,
  4115. UNSIGNED_SHORT_5_6_5: 0x8363,
  4116. /* Shaders */
  4117. FRAGMENT_SHADER: 0x8B30,
  4118. VERTEX_SHADER: 0x8B31,
  4119. MAX_VERTEX_ATTRIBS: 0x8869,
  4120. MAX_VERTEX_UNIFORM_VECTORS: 0x8DFB,
  4121. MAX_VARYING_VECTORS: 0x8DFC,
  4122. MAX_COMBINED_TEXTURE_IMAGE_UNITS: 0x8B4D,
  4123. MAX_VERTEX_TEXTURE_IMAGE_UNITS: 0x8B4C,
  4124. MAX_TEXTURE_IMAGE_UNITS: 0x8872,
  4125. MAX_FRAGMENT_UNIFORM_VECTORS: 0x8DFD,
  4126. SHADER_TYPE: 0x8B4F,
  4127. DELETE_STATUS: 0x8B80,
  4128. LINK_STATUS: 0x8B82,
  4129. VALIDATE_STATUS: 0x8B83,
  4130. ATTACHED_SHADERS: 0x8B85,
  4131. ACTIVE_UNIFORMS: 0x8B86,
  4132. ACTIVE_ATTRIBUTES: 0x8B89,
  4133. SHADING_LANGUAGE_VERSION: 0x8B8C,
  4134. CURRENT_PROGRAM: 0x8B8D,
  4135. /* StencilFunction */
  4136. NEVER: 0x0200,
  4137. LESS: 0x0201,
  4138. EQUAL: 0x0202,
  4139. LEQUAL: 0x0203,
  4140. GREATER: 0x0204,
  4141. NOTEQUAL: 0x0205,
  4142. GEQUAL: 0x0206,
  4143. ALWAYS: 0x0207,
  4144. /* StencilOp */
  4145. /* ZERO */
  4146. KEEP: 0x1E00,
  4147. REPLACE: 0x1E01,
  4148. INCR: 0x1E02,
  4149. DECR: 0x1E03,
  4150. INVERT: 0x150A,
  4151. INCR_WRAP: 0x8507,
  4152. DECR_WRAP: 0x8508,
  4153. /* StringName */
  4154. VENDOR: 0x1F00,
  4155. RENDERER: 0x1F01,
  4156. VERSION: 0x1F02,
  4157. /* TextureMagFilter */
  4158. NEAREST: 0x2600,
  4159. LINEAR: 0x2601,
  4160. /* TextureMinFilter */
  4161. /* NEAREST */
  4162. /* LINEAR */
  4163. NEAREST_MIPMAP_NEAREST: 0x2700,
  4164. LINEAR_MIPMAP_NEAREST: 0x2701,
  4165. NEAREST_MIPMAP_LINEAR: 0x2702,
  4166. LINEAR_MIPMAP_LINEAR: 0x2703,
  4167. /* TextureParameterName */
  4168. TEXTURE_MAG_FILTER: 0x2800,
  4169. TEXTURE_MIN_FILTER: 0x2801,
  4170. TEXTURE_WRAP_S: 0x2802,
  4171. TEXTURE_WRAP_T: 0x2803,
  4172. /* TextureTarget */
  4173. TEXTURE_2D: 0x0DE1,
  4174. TEXTURE: 0x1702,
  4175. TEXTURE_CUBE_MAP: 0x8513,
  4176. TEXTURE_BINDING_CUBE_MAP: 0x8514,
  4177. TEXTURE_CUBE_MAP_POSITIVE_X: 0x8515,
  4178. TEXTURE_CUBE_MAP_NEGATIVE_X: 0x8516,
  4179. TEXTURE_CUBE_MAP_POSITIVE_Y: 0x8517,
  4180. TEXTURE_CUBE_MAP_NEGATIVE_Y: 0x8518,
  4181. TEXTURE_CUBE_MAP_POSITIVE_Z: 0x8519,
  4182. TEXTURE_CUBE_MAP_NEGATIVE_Z: 0x851A,
  4183. MAX_CUBE_MAP_TEXTURE_SIZE: 0x851C,
  4184. /* TextureUnit */
  4185. TEXTURE0: 0x84C0,
  4186. TEXTURE1: 0x84C1,
  4187. TEXTURE2: 0x84C2,
  4188. TEXTURE3: 0x84C3,
  4189. TEXTURE4: 0x84C4,
  4190. TEXTURE5: 0x84C5,
  4191. TEXTURE6: 0x84C6,
  4192. TEXTURE7: 0x84C7,
  4193. TEXTURE8: 0x84C8,
  4194. TEXTURE9: 0x84C9,
  4195. TEXTURE10: 0x84CA,
  4196. TEXTURE11: 0x84CB,
  4197. TEXTURE12: 0x84CC,
  4198. TEXTURE13: 0x84CD,
  4199. TEXTURE14: 0x84CE,
  4200. TEXTURE15: 0x84CF,
  4201. TEXTURE16: 0x84D0,
  4202. TEXTURE17: 0x84D1,
  4203. TEXTURE18: 0x84D2,
  4204. TEXTURE19: 0x84D3,
  4205. TEXTURE20: 0x84D4,
  4206. TEXTURE21: 0x84D5,
  4207. TEXTURE22: 0x84D6,
  4208. TEXTURE23: 0x84D7,
  4209. TEXTURE24: 0x84D8,
  4210. TEXTURE25: 0x84D9,
  4211. TEXTURE26: 0x84DA,
  4212. TEXTURE27: 0x84DB,
  4213. TEXTURE28: 0x84DC,
  4214. TEXTURE29: 0x84DD,
  4215. TEXTURE30: 0x84DE,
  4216. TEXTURE31: 0x84DF,
  4217. ACTIVE_TEXTURE: 0x84E0,
  4218. /* TextureWrapMode */
  4219. REPEAT: 0x2901,
  4220. CLAMP_TO_EDGE: 0x812F,
  4221. MIRRORED_REPEAT: 0x8370,
  4222. /* Uniform Types */
  4223. FLOAT_VEC2: 0x8B50,
  4224. FLOAT_VEC3: 0x8B51,
  4225. FLOAT_VEC4: 0x8B52,
  4226. INT_VEC2: 0x8B53,
  4227. INT_VEC3: 0x8B54,
  4228. INT_VEC4: 0x8B55,
  4229. BOOL: 0x8B56,
  4230. BOOL_VEC2: 0x8B57,
  4231. BOOL_VEC3: 0x8B58,
  4232. BOOL_VEC4: 0x8B59,
  4233. FLOAT_MAT2: 0x8B5A,
  4234. FLOAT_MAT3: 0x8B5B,
  4235. FLOAT_MAT4: 0x8B5C,
  4236. SAMPLER_2D: 0x8B5E,
  4237. SAMPLER_CUBE: 0x8B60,
  4238. /* Vertex Arrays */
  4239. VERTEX_ATTRIB_ARRAY_ENABLED: 0x8622,
  4240. VERTEX_ATTRIB_ARRAY_SIZE: 0x8623,
  4241. VERTEX_ATTRIB_ARRAY_STRIDE: 0x8624,
  4242. VERTEX_ATTRIB_ARRAY_TYPE: 0x8625,
  4243. VERTEX_ATTRIB_ARRAY_NORMALIZED: 0x886A,
  4244. VERTEX_ATTRIB_ARRAY_POINTER: 0x8645,
  4245. VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: 0x889F,
  4246. /* Shader Source */
  4247. COMPILE_STATUS: 0x8B81,
  4248. /* Shader Precision-Specified Types */
  4249. LOW_FLOAT: 0x8DF0,
  4250. MEDIUM_FLOAT: 0x8DF1,
  4251. HIGH_FLOAT: 0x8DF2,
  4252. LOW_INT: 0x8DF3,
  4253. MEDIUM_INT: 0x8DF4,
  4254. HIGH_INT: 0x8DF5,
  4255. /* Framebuffer Object. */
  4256. FRAMEBUFFER: 0x8D40,
  4257. RENDERBUFFER: 0x8D41,
  4258. RGBA4: 0x8056,
  4259. RGB5_A1: 0x8057,
  4260. RGB565: 0x8D62,
  4261. DEPTH_COMPONENT16: 0x81A5,
  4262. STENCIL_INDEX: 0x1901,
  4263. STENCIL_INDEX8: 0x8D48,
  4264. DEPTH_STENCIL: 0x84F9,
  4265. RENDERBUFFER_WIDTH: 0x8D42,
  4266. RENDERBUFFER_HEIGHT: 0x8D43,
  4267. RENDERBUFFER_INTERNAL_FORMAT: 0x8D44,
  4268. RENDERBUFFER_RED_SIZE: 0x8D50,
  4269. RENDERBUFFER_GREEN_SIZE: 0x8D51,
  4270. RENDERBUFFER_BLUE_SIZE: 0x8D52,
  4271. RENDERBUFFER_ALPHA_SIZE: 0x8D53,
  4272. RENDERBUFFER_DEPTH_SIZE: 0x8D54,
  4273. RENDERBUFFER_STENCIL_SIZE: 0x8D55,
  4274. FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: 0x8CD0,
  4275. FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: 0x8CD1,
  4276. FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: 0x8CD2,
  4277. FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: 0x8CD3,
  4278. COLOR_ATTACHMENT0: 0x8CE0,
  4279. DEPTH_ATTACHMENT: 0x8D00,
  4280. STENCIL_ATTACHMENT: 0x8D20,
  4281. DEPTH_STENCIL_ATTACHMENT: 0x821A,
  4282. NONE: 0,
  4283. FRAMEBUFFER_COMPLETE: 0x8CD5,
  4284. FRAMEBUFFER_INCOMPLETE_ATTACHMENT: 0x8CD6,
  4285. FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: 0x8CD7,
  4286. FRAMEBUFFER_INCOMPLETE_DIMENSIONS: 0x8CD9,
  4287. FRAMEBUFFER_UNSUPPORTED: 0x8CDD,
  4288. FRAMEBUFFER_BINDING: 0x8CA6,
  4289. RENDERBUFFER_BINDING: 0x8CA7,
  4290. MAX_RENDERBUFFER_SIZE: 0x84E8,
  4291. INVALID_FRAMEBUFFER_OPERATION: 0x0506,
  4292. /* WebGL-specific enums */
  4293. UNPACK_FLIP_Y_WEBGL: 0x9240,
  4294. UNPACK_PREMULTIPLY_ALPHA_WEBGL: 0x9241,
  4295. CONTEXT_LOST_WEBGL: 0x9242,
  4296. UNPACK_COLORSPACE_CONVERSION_WEBGL: 0x9243,
  4297. BROWSER_DEFAULT_WEBGL: 0x9244,
  4298. });
  4299. /***/
  4300. }),
  4301. /* 12 */
  4302. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  4303. "use strict";
  4304. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__common__ = __webpack_require__(20);
  4305. /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
  4306. Redistribution and use in source and binary forms, with or without modification,
  4307. are permitted provided that the following conditions are met:
  4308. * Redistributions of source code must retain the above copyright notice, this
  4309. list of conditions and the following disclaimer.
  4310. * Redistributions in binary form must reproduce the above copyright notice,
  4311. this list of conditions and the following disclaimer in the documentation
  4312. and/or other materials provided with the distribution.
  4313. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  4314. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  4315. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  4316. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  4317. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  4318. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  4319. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  4320. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  4321. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  4322. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
  4323. /**
  4324. * @class 3 Dimensional Vector
  4325. * @name vec3
  4326. */
  4327. var vec3 = {};
  4328. /**
  4329. * Creates a new, empty vec3
  4330. *
  4331. * @returns {vec3} a new 3D vector
  4332. */
  4333. vec3.create = function () {
  4334. var out = new __WEBPACK_IMPORTED_MODULE_0__common__["a" /* GLMAT_ARRAY_TYPE */](3);
  4335. out[0] = 0;
  4336. out[1] = 0;
  4337. out[2] = 0;
  4338. return out;
  4339. };
  4340. /**
  4341. * Creates a new vec3 initialized with values from an existing vector
  4342. *
  4343. * @param {vec3} a vector to clone
  4344. * @returns {vec3} a new 3D vector
  4345. */
  4346. vec3.clone = function (a) {
  4347. var out = new __WEBPACK_IMPORTED_MODULE_0__common__["a" /* GLMAT_ARRAY_TYPE */](3);
  4348. out[0] = a[0];
  4349. out[1] = a[1];
  4350. out[2] = a[2];
  4351. return out;
  4352. };
  4353. /**
  4354. * Creates a new vec3 initialized with the given values
  4355. *
  4356. * @param {Number} x X component
  4357. * @param {Number} y Y component
  4358. * @param {Number} z Z component
  4359. * @returns {vec3} a new 3D vector
  4360. */
  4361. vec3.fromValues = function (x, y, z) {
  4362. var out = new __WEBPACK_IMPORTED_MODULE_0__common__["a" /* GLMAT_ARRAY_TYPE */](3);
  4363. out[0] = x;
  4364. out[1] = y;
  4365. out[2] = z;
  4366. return out;
  4367. };
  4368. /**
  4369. * Copy the values from one vec3 to another
  4370. *
  4371. * @param {vec3} out the receiving vector
  4372. * @param {vec3} a the source vector
  4373. * @returns {vec3} out
  4374. */
  4375. vec3.copy = function (out, a) {
  4376. out[0] = a[0];
  4377. out[1] = a[1];
  4378. out[2] = a[2];
  4379. return out;
  4380. };
  4381. /**
  4382. * Set the components of a vec3 to the given values
  4383. *
  4384. * @param {vec3} out the receiving vector
  4385. * @param {Number} x X component
  4386. * @param {Number} y Y component
  4387. * @param {Number} z Z component
  4388. * @returns {vec3} out
  4389. */
  4390. vec3.set = function (out, x, y, z) {
  4391. out[0] = x;
  4392. out[1] = y;
  4393. out[2] = z;
  4394. return out;
  4395. };
  4396. /**
  4397. * Adds two vec3's
  4398. *
  4399. * @param {vec3} out the receiving vector
  4400. * @param {vec3} a the first operand
  4401. * @param {vec3} b the second operand
  4402. * @returns {vec3} out
  4403. */
  4404. vec3.add = function (out, a, b) {
  4405. out[0] = a[0] + b[0];
  4406. out[1] = a[1] + b[1];
  4407. out[2] = a[2] + b[2];
  4408. return out;
  4409. };
  4410. /**
  4411. * Subtracts vector b from vector a
  4412. *
  4413. * @param {vec3} out the receiving vector
  4414. * @param {vec3} a the first operand
  4415. * @param {vec3} b the second operand
  4416. * @returns {vec3} out
  4417. */
  4418. vec3.subtract = function (out, a, b) {
  4419. out[0] = a[0] - b[0];
  4420. out[1] = a[1] - b[1];
  4421. out[2] = a[2] - b[2];
  4422. return out;
  4423. };
  4424. /**
  4425. * Alias for {@link vec3.subtract}
  4426. * @function
  4427. */
  4428. vec3.sub = vec3.subtract;
  4429. /**
  4430. * Multiplies two vec3's
  4431. *
  4432. * @param {vec3} out the receiving vector
  4433. * @param {vec3} a the first operand
  4434. * @param {vec3} b the second operand
  4435. * @returns {vec3} out
  4436. */
  4437. vec3.multiply = function (out, a, b) {
  4438. out[0] = a[0] * b[0];
  4439. out[1] = a[1] * b[1];
  4440. out[2] = a[2] * b[2];
  4441. return out;
  4442. };
  4443. /**
  4444. * Alias for {@link vec3.multiply}
  4445. * @function
  4446. */
  4447. vec3.mul = vec3.multiply;
  4448. /**
  4449. * Divides two vec3's
  4450. *
  4451. * @param {vec3} out the receiving vector
  4452. * @param {vec3} a the first operand
  4453. * @param {vec3} b the second operand
  4454. * @returns {vec3} out
  4455. */
  4456. vec3.divide = function (out, a, b) {
  4457. out[0] = a[0] / b[0];
  4458. out[1] = a[1] / b[1];
  4459. out[2] = a[2] / b[2];
  4460. return out;
  4461. };
  4462. /**
  4463. * Alias for {@link vec3.divide}
  4464. * @function
  4465. */
  4466. vec3.div = vec3.divide;
  4467. /**
  4468. * Returns the minimum of two vec3's
  4469. *
  4470. * @param {vec3} out the receiving vector
  4471. * @param {vec3} a the first operand
  4472. * @param {vec3} b the second operand
  4473. * @returns {vec3} out
  4474. */
  4475. vec3.min = function (out, a, b) {
  4476. out[0] = Math.min(a[0], b[0]);
  4477. out[1] = Math.min(a[1], b[1]);
  4478. out[2] = Math.min(a[2], b[2]);
  4479. return out;
  4480. };
  4481. /**
  4482. * Returns the maximum of two vec3's
  4483. *
  4484. * @param {vec3} out the receiving vector
  4485. * @param {vec3} a the first operand
  4486. * @param {vec3} b the second operand
  4487. * @returns {vec3} out
  4488. */
  4489. vec3.max = function (out, a, b) {
  4490. out[0] = Math.max(a[0], b[0]);
  4491. out[1] = Math.max(a[1], b[1]);
  4492. out[2] = Math.max(a[2], b[2]);
  4493. return out;
  4494. };
  4495. /**
  4496. * Scales a vec3 by a scalar number
  4497. *
  4498. * @param {vec3} out the receiving vector
  4499. * @param {vec3} a the vector to scale
  4500. * @param {Number} b amount to scale the vector by
  4501. * @returns {vec3} out
  4502. */
  4503. vec3.scale = function (out, a, b) {
  4504. out[0] = a[0] * b;
  4505. out[1] = a[1] * b;
  4506. out[2] = a[2] * b;
  4507. return out;
  4508. };
  4509. /**
  4510. * Adds two vec3's after scaling the second operand by a scalar value
  4511. *
  4512. * @param {vec3} out the receiving vector
  4513. * @param {vec3} a the first operand
  4514. * @param {vec3} b the second operand
  4515. * @param {Number} scale the amount to scale b by before adding
  4516. * @returns {vec3} out
  4517. */
  4518. vec3.scaleAndAdd = function (out, a, b, scale) {
  4519. out[0] = a[0] + (b[0] * scale);
  4520. out[1] = a[1] + (b[1] * scale);
  4521. out[2] = a[2] + (b[2] * scale);
  4522. return out;
  4523. };
  4524. /**
  4525. * Calculates the euclidian distance between two vec3's
  4526. *
  4527. * @param {vec3} a the first operand
  4528. * @param {vec3} b the second operand
  4529. * @returns {Number} distance between a and b
  4530. */
  4531. vec3.distance = function (a, b) {
  4532. var x = b[0] - a[0],
  4533. y = b[1] - a[1],
  4534. z = b[2] - a[2];
  4535. return Math.sqrt(x * x + y * y + z * z);
  4536. };
  4537. /**
  4538. * Alias for {@link vec3.distance}
  4539. * @function
  4540. */
  4541. vec3.dist = vec3.distance;
  4542. /**
  4543. * Calculates the squared euclidian distance between two vec3's
  4544. *
  4545. * @param {vec3} a the first operand
  4546. * @param {vec3} b the second operand
  4547. * @returns {Number} squared distance between a and b
  4548. */
  4549. vec3.squaredDistance = function (a, b) {
  4550. var x = b[0] - a[0],
  4551. y = b[1] - a[1],
  4552. z = b[2] - a[2];
  4553. return x * x + y * y + z * z;
  4554. };
  4555. /**
  4556. * Alias for {@link vec3.squaredDistance}
  4557. * @function
  4558. */
  4559. vec3.sqrDist = vec3.squaredDistance;
  4560. /**
  4561. * Calculates the length of a vec3
  4562. *
  4563. * @param {vec3} a vector to calculate length of
  4564. * @returns {Number} length of a
  4565. */
  4566. vec3.length = function (a) {
  4567. var x = a[0],
  4568. y = a[1],
  4569. z = a[2];
  4570. return Math.sqrt(x * x + y * y + z * z);
  4571. };
  4572. /**
  4573. * Alias for {@link vec3.length}
  4574. * @function
  4575. */
  4576. vec3.len = vec3.length;
  4577. /**
  4578. * Calculates the squared length of a vec3
  4579. *
  4580. * @param {vec3} a vector to calculate squared length of
  4581. * @returns {Number} squared length of a
  4582. */
  4583. vec3.squaredLength = function (a) {
  4584. var x = a[0],
  4585. y = a[1],
  4586. z = a[2];
  4587. return x * x + y * y + z * z;
  4588. };
  4589. /**
  4590. * Alias for {@link vec3.squaredLength}
  4591. * @function
  4592. */
  4593. vec3.sqrLen = vec3.squaredLength;
  4594. /**
  4595. * Negates the components of a vec3
  4596. *
  4597. * @param {vec3} out the receiving vector
  4598. * @param {vec3} a vector to negate
  4599. * @returns {vec3} out
  4600. */
  4601. vec3.negate = function (out, a) {
  4602. out[0] = -a[0];
  4603. out[1] = -a[1];
  4604. out[2] = -a[2];
  4605. return out;
  4606. };
  4607. /**
  4608. * Returns the inverse of the components of a vec3
  4609. *
  4610. * @param {vec3} out the receiving vector
  4611. * @param {vec3} a vector to invert
  4612. * @returns {vec3} out
  4613. */
  4614. vec3.inverse = function (out, a) {
  4615. out[0] = 1.0 / a[0];
  4616. out[1] = 1.0 / a[1];
  4617. out[2] = 1.0 / a[2];
  4618. return out;
  4619. };
  4620. /**
  4621. * Normalize a vec3
  4622. *
  4623. * @param {vec3} out the receiving vector
  4624. * @param {vec3} a vector to normalize
  4625. * @returns {vec3} out
  4626. */
  4627. vec3.normalize = function (out, a) {
  4628. var x = a[0],
  4629. y = a[1],
  4630. z = a[2];
  4631. var len = x * x + y * y + z * z;
  4632. if (len > 0) {
  4633. //TODO: evaluate use of glm_invsqrt here?
  4634. len = 1 / Math.sqrt(len);
  4635. out[0] = a[0] * len;
  4636. out[1] = a[1] * len;
  4637. out[2] = a[2] * len;
  4638. }
  4639. return out;
  4640. };
  4641. /**
  4642. * Calculates the dot product of two vec3's
  4643. *
  4644. * @param {vec3} a the first operand
  4645. * @param {vec3} b the second operand
  4646. * @returns {Number} dot product of a and b
  4647. */
  4648. vec3.dot = function (a, b) {
  4649. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  4650. };
  4651. /**
  4652. * Computes the cross product of two vec3's
  4653. *
  4654. * @param {vec3} out the receiving vector
  4655. * @param {vec3} a the first operand
  4656. * @param {vec3} b the second operand
  4657. * @returns {vec3} out
  4658. */
  4659. vec3.cross = function (out, a, b) {
  4660. var ax = a[0], ay = a[1], az = a[2],
  4661. bx = b[0], by = b[1], bz = b[2];
  4662. out[0] = ay * bz - az * by;
  4663. out[1] = az * bx - ax * bz;
  4664. out[2] = ax * by - ay * bx;
  4665. return out;
  4666. };
  4667. /**
  4668. * Performs a linear interpolation between two vec3's
  4669. *
  4670. * @param {vec3} out the receiving vector
  4671. * @param {vec3} a the first operand
  4672. * @param {vec3} b the second operand
  4673. * @param {Number} t interpolation amount between the two inputs
  4674. * @returns {vec3} out
  4675. */
  4676. vec3.lerp = function (out, a, b, t) {
  4677. var ax = a[0],
  4678. ay = a[1],
  4679. az = a[2];
  4680. out[0] = ax + t * (b[0] - ax);
  4681. out[1] = ay + t * (b[1] - ay);
  4682. out[2] = az + t * (b[2] - az);
  4683. return out;
  4684. };
  4685. /**
  4686. * Generates a random vector with the given scale
  4687. *
  4688. * @param {vec3} out the receiving vector
  4689. * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned
  4690. * @returns {vec3} out
  4691. */
  4692. vec3.random = function (out, scale) {
  4693. scale = scale || 1.0;
  4694. var r = Object(__WEBPACK_IMPORTED_MODULE_0__common__["c" /* GLMAT_RANDOM */])() * 2.0 * Math.PI;
  4695. var z = (Object(__WEBPACK_IMPORTED_MODULE_0__common__["c" /* GLMAT_RANDOM */])() * 2.0) - 1.0;
  4696. var zScale = Math.sqrt(1.0 - z * z) * scale;
  4697. out[0] = Math.cos(r) * zScale;
  4698. out[1] = Math.sin(r) * zScale;
  4699. out[2] = z * scale;
  4700. return out;
  4701. };
  4702. /**
  4703. * Transforms the vec3 with a mat4.
  4704. * 4th vector component is implicitly '1'
  4705. *
  4706. * @param {vec3} out the receiving vector
  4707. * @param {vec3} a the vector to transform
  4708. * @param {mat4} m matrix to transform with
  4709. * @returns {vec3} out
  4710. */
  4711. vec3.transformMat4 = function (out, a, m) {
  4712. var x = a[0], y = a[1], z = a[2],
  4713. w = m[3] * x + m[7] * y + m[11] * z + m[15];
  4714. w = w || 1.0;
  4715. out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
  4716. out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
  4717. out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
  4718. return out;
  4719. };
  4720. /**
  4721. * Transforms the vec3 with a mat3.
  4722. *
  4723. * @param {vec3} out the receiving vector
  4724. * @param {vec3} a the vector to transform
  4725. * @param {mat4} m the 3x3 matrix to transform with
  4726. * @returns {vec3} out
  4727. */
  4728. vec3.transformMat3 = function (out, a, m) {
  4729. var x = a[0], y = a[1], z = a[2];
  4730. out[0] = x * m[0] + y * m[3] + z * m[6];
  4731. out[1] = x * m[1] + y * m[4] + z * m[7];
  4732. out[2] = x * m[2] + y * m[5] + z * m[8];
  4733. return out;
  4734. };
  4735. /**
  4736. * Transforms the vec3 with a quat
  4737. *
  4738. * @param {vec3} out the receiving vector
  4739. * @param {vec3} a the vector to transform
  4740. * @param {quat} q quaternion to transform with
  4741. * @returns {vec3} out
  4742. */
  4743. vec3.transformQuat = function (out, a, q) {
  4744. // benchmarks: http://jsperf.com/quaternion-transform-vec3-implementations
  4745. var x = a[0], y = a[1], z = a[2],
  4746. qx = q[0], qy = q[1], qz = q[2], qw = q[3],
  4747. // calculate quat * vec
  4748. ix = qw * x + qy * z - qz * y,
  4749. iy = qw * y + qz * x - qx * z,
  4750. iz = qw * z + qx * y - qy * x,
  4751. iw = -qx * x - qy * y - qz * z;
  4752. // calculate result * inverse quat
  4753. out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  4754. out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  4755. out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  4756. return out;
  4757. };
  4758. /**
  4759. * Rotate a 3D vector around the x-axis
  4760. * @param {vec3} out The receiving vec3
  4761. * @param {vec3} a The vec3 point to rotate
  4762. * @param {vec3} b The origin of the rotation
  4763. * @param {Number} c The angle of rotation
  4764. * @returns {vec3} out
  4765. */
  4766. vec3.rotateX = function (out, a, b, c) {
  4767. var p = [], r = [];
  4768. //Translate point to the origin
  4769. p[0] = a[0] - b[0];
  4770. p[1] = a[1] - b[1];
  4771. p[2] = a[2] - b[2];
  4772. //perform rotation
  4773. r[0] = p[0];
  4774. r[1] = p[1] * Math.cos(c) - p[2] * Math.sin(c);
  4775. r[2] = p[1] * Math.sin(c) + p[2] * Math.cos(c);
  4776. //translate to correct position
  4777. out[0] = r[0] + b[0];
  4778. out[1] = r[1] + b[1];
  4779. out[2] = r[2] + b[2];
  4780. return out;
  4781. };
  4782. /**
  4783. * Rotate a 3D vector around the y-axis
  4784. * @param {vec3} out The receiving vec3
  4785. * @param {vec3} a The vec3 point to rotate
  4786. * @param {vec3} b The origin of the rotation
  4787. * @param {Number} c The angle of rotation
  4788. * @returns {vec3} out
  4789. */
  4790. vec3.rotateY = function (out, a, b, c) {
  4791. var p = [], r = [];
  4792. //Translate point to the origin
  4793. p[0] = a[0] - b[0];
  4794. p[1] = a[1] - b[1];
  4795. p[2] = a[2] - b[2];
  4796. //perform rotation
  4797. r[0] = p[2] * Math.sin(c) + p[0] * Math.cos(c);
  4798. r[1] = p[1];
  4799. r[2] = p[2] * Math.cos(c) - p[0] * Math.sin(c);
  4800. //translate to correct position
  4801. out[0] = r[0] + b[0];
  4802. out[1] = r[1] + b[1];
  4803. out[2] = r[2] + b[2];
  4804. return out;
  4805. };
  4806. /**
  4807. * Rotate a 3D vector around the z-axis
  4808. * @param {vec3} out The receiving vec3
  4809. * @param {vec3} a The vec3 point to rotate
  4810. * @param {vec3} b The origin of the rotation
  4811. * @param {Number} c The angle of rotation
  4812. * @returns {vec3} out
  4813. */
  4814. vec3.rotateZ = function (out, a, b, c) {
  4815. var p = [], r = [];
  4816. //Translate point to the origin
  4817. p[0] = a[0] - b[0];
  4818. p[1] = a[1] - b[1];
  4819. p[2] = a[2] - b[2];
  4820. //perform rotation
  4821. r[0] = p[0] * Math.cos(c) - p[1] * Math.sin(c);
  4822. r[1] = p[0] * Math.sin(c) + p[1] * Math.cos(c);
  4823. r[2] = p[2];
  4824. //translate to correct position
  4825. out[0] = r[0] + b[0];
  4826. out[1] = r[1] + b[1];
  4827. out[2] = r[2] + b[2];
  4828. return out;
  4829. };
  4830. /**
  4831. * Perform some operation over an array of vec3s.
  4832. *
  4833. * @param {Array} a the array of vectors to iterate over
  4834. * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
  4835. * @param {Number} offset Number of elements to skip at the beginning of the array
  4836. * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
  4837. * @param {Function} fn Function to call for each vector in the array
  4838. * @param {Object} [arg] additional argument to pass to fn
  4839. * @returns {Array} a
  4840. * @function
  4841. */
  4842. vec3.forEach = (function () {
  4843. var vec = vec3.create();
  4844. return function (a, stride, offset, count, fn, arg) {
  4845. var i, l;
  4846. if (!stride) {
  4847. stride = 3;
  4848. }
  4849. if (!offset) {
  4850. offset = 0;
  4851. }
  4852. if (count) {
  4853. l = Math.min((count * stride) + offset, a.length);
  4854. } else {
  4855. l = a.length;
  4856. }
  4857. for (i = offset; i < l; i += stride) {
  4858. vec[0] = a[i]; vec[1] = a[i + 1]; vec[2] = a[i + 2];
  4859. fn(vec, vec, arg);
  4860. a[i] = vec[0]; a[i + 1] = vec[1]; a[i + 2] = vec[2];
  4861. }
  4862. return a;
  4863. };
  4864. })();
  4865. /**
  4866. * Get the angle between two 3D vectors
  4867. * @param {vec3} a The first operand
  4868. * @param {vec3} b The second operand
  4869. * @returns {Number} The angle in radians
  4870. */
  4871. vec3.angle = function (a, b) {
  4872. var tempA = vec3.fromValues(a[0], a[1], a[2]);
  4873. var tempB = vec3.fromValues(b[0], b[1], b[2]);
  4874. vec3.normalize(tempA, tempA);
  4875. vec3.normalize(tempB, tempB);
  4876. var cosine = vec3.dot(tempA, tempB);
  4877. if (cosine > 1.0) {
  4878. return 0;
  4879. } else {
  4880. return Math.acos(cosine);
  4881. }
  4882. };
  4883. /* harmony default export */ __webpack_exports__["a"] = (vec3);
  4884. /***/
  4885. }),
  4886. /* 13 */
  4887. /***/ (function (module, exports) {
  4888. /**
  4889. * @module zrender/core/util
  4890. */
  4891. // 用于处理mergeæ—¶æ— æ³•éåŽ†Date等对象的问题
  4892. var BUILTIN_OBJECT = {
  4893. '[object Function]': 1,
  4894. '[object RegExp]': 1,
  4895. '[object Date]': 1,
  4896. '[object Error]': 1,
  4897. '[object CanvasGradient]': 1,
  4898. '[object CanvasPattern]': 1,
  4899. // For node-canvas
  4900. '[object Image]': 1,
  4901. '[object Canvas]': 1
  4902. };
  4903. var TYPED_ARRAY = {
  4904. '[object Int8Array]': 1,
  4905. '[object Uint8Array]': 1,
  4906. '[object Uint8ClampedArray]': 1,
  4907. '[object Int16Array]': 1,
  4908. '[object Uint16Array]': 1,
  4909. '[object Int32Array]': 1,
  4910. '[object Uint32Array]': 1,
  4911. '[object Float32Array]': 1,
  4912. '[object Float64Array]': 1
  4913. };
  4914. var objToString = Object.prototype.toString;
  4915. var arrayProto = Array.prototype;
  4916. var nativeForEach = arrayProto.forEach;
  4917. var nativeFilter = arrayProto.filter;
  4918. var nativeSlice = arrayProto.slice;
  4919. var nativeMap = arrayProto.map;
  4920. var nativeReduce = arrayProto.reduce; // Avoid assign to an exported variable, for transforming to cjs.
  4921. var methods = {};
  4922. function $override(name, fn) {
  4923. // Clear ctx instance for different environment
  4924. if (name === 'createCanvas') {
  4925. _ctx = null;
  4926. }
  4927. methods[name] = fn;
  4928. }
  4929. /**
  4930. * Those data types can be cloned:
  4931. * Plain object, Array, TypedArray, number, string, null, undefined.
  4932. * Those data types will be assgined using the orginal data:
  4933. * BUILTIN_OBJECT
  4934. * Instance of user defined class will be cloned to a plain object, without
  4935. * properties in prototype.
  4936. * Other data types is not supported (not sure what will happen).
  4937. *
  4938. * Caution: do not support clone Date, for performance consideration.
  4939. * (There might be a large number of date in `series.data`).
  4940. * So date should not be modified in and out of echarts.
  4941. *
  4942. * @param {*} source
  4943. * @return {*} new
  4944. */
  4945. function clone(source) {
  4946. if (source == null || typeof source != 'object') {
  4947. return source;
  4948. }
  4949. var result = source;
  4950. var typeStr = objToString.call(source);
  4951. if (typeStr === '[object Array]') {
  4952. if (!isPrimitive(source)) {
  4953. result = [];
  4954. for (var i = 0, len = source.length; i < len; i++) {
  4955. result[i] = clone(source[i]);
  4956. }
  4957. }
  4958. } else if (TYPED_ARRAY[typeStr]) {
  4959. if (!isPrimitive(source)) {
  4960. var Ctor = source.constructor;
  4961. if (source.constructor.from) {
  4962. result = Ctor.from(source);
  4963. } else {
  4964. result = new Ctor(source.length);
  4965. for (var i = 0, len = source.length; i < len; i++) {
  4966. result[i] = clone(source[i]);
  4967. }
  4968. }
  4969. }
  4970. } else if (!BUILTIN_OBJECT[typeStr] && !isPrimitive(source) && !isDom(source)) {
  4971. result = {};
  4972. for (var key in source) {
  4973. if (source.hasOwnProperty(key)) {
  4974. result[key] = clone(source[key]);
  4975. }
  4976. }
  4977. }
  4978. return result;
  4979. }
  4980. /**
  4981. * @memberOf module:zrender/core/util
  4982. * @param {*} target
  4983. * @param {*} source
  4984. * @param {boolean} [overwrite=false]
  4985. */
  4986. function merge(target, source, overwrite) {
  4987. // We should escapse that source is string
  4988. // and enter for ... in ...
  4989. if (!isObject(source) || !isObject(target)) {
  4990. return overwrite ? clone(source) : target;
  4991. }
  4992. for (var key in source) {
  4993. if (source.hasOwnProperty(key)) {
  4994. var targetProp = target[key];
  4995. var sourceProp = source[key];
  4996. if (isObject(sourceProp) && isObject(targetProp) && !isArray(sourceProp) && !isArray(targetProp) && !isDom(sourceProp) && !isDom(targetProp) && !isBuiltInObject(sourceProp) && !isBuiltInObject(targetProp) && !isPrimitive(sourceProp) && !isPrimitive(targetProp)) {
  4997. // 如果需要递归覆盖,就递归调用merge
  4998. merge(targetProp, sourceProp, overwrite);
  4999. } else if (overwrite || !(key in target)) {
  5000. // 否则只处理overwrite为trueï¼Œæˆ–è€…åœ¨ç›®æ ‡å¯¹è±¡ä¸­æ²¡æœ‰æ­¤å±žæ€§çš„æƒ…å†µ
  5001. // NOTE,在 target[key] 不存在的时候也是直接覆盖
  5002. target[key] = clone(source[key], true);
  5003. }
  5004. }
  5005. }
  5006. return target;
  5007. }
  5008. /**
  5009. * @param {Array} targetAndSources The first item is target, and the rests are source.
  5010. * @param {boolean} [overwrite=false]
  5011. * @return {*} target
  5012. */
  5013. function mergeAll(targetAndSources, overwrite) {
  5014. var result = targetAndSources[0];
  5015. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  5016. result = merge(result, targetAndSources[i], overwrite);
  5017. }
  5018. return result;
  5019. }
  5020. /**
  5021. * @param {*} target
  5022. * @param {*} source
  5023. * @memberOf module:zrender/core/util
  5024. */
  5025. function extend(target, source) {
  5026. for (var key in source) {
  5027. if (source.hasOwnProperty(key)) {
  5028. target[key] = source[key];
  5029. }
  5030. }
  5031. return target;
  5032. }
  5033. /**
  5034. * @param {*} target
  5035. * @param {*} source
  5036. * @param {boolean} [overlay=false]
  5037. * @memberOf module:zrender/core/util
  5038. */
  5039. function defaults(target, source, overlay) {
  5040. for (var key in source) {
  5041. if (source.hasOwnProperty(key) && (overlay ? source[key] != null : target[key] == null)) {
  5042. target[key] = source[key];
  5043. }
  5044. }
  5045. return target;
  5046. }
  5047. var createCanvas = function () {
  5048. return methods.createCanvas();
  5049. };
  5050. methods.createCanvas = function () {
  5051. return document.createElement('canvas');
  5052. }; // FIXME
  5053. var _ctx;
  5054. function getContext() {
  5055. if (!_ctx) {
  5056. // Use util.createCanvas instead of createCanvas
  5057. // because createCanvas may be overwritten in different environment
  5058. _ctx = createCanvas().getContext('2d');
  5059. }
  5060. return _ctx;
  5061. }
  5062. /**
  5063. * æŸ¥è¯¢æ•°ç»„ä¸­å…ƒç´ çš„index
  5064. * @memberOf module:zrender/core/util
  5065. */
  5066. function indexOf(array, value) {
  5067. if (array) {
  5068. if (array.indexOf) {
  5069. return array.indexOf(value);
  5070. }
  5071. for (var i = 0, len = array.length; i < len; i++) {
  5072. if (array[i] === value) {
  5073. return i;
  5074. }
  5075. }
  5076. }
  5077. return -1;
  5078. }
  5079. /**
  5080. * æž„é€ ç±»ç»§æ‰¿å…³ç³»
  5081. *
  5082. * @memberOf module:zrender/core/util
  5083. * @param {Function} clazz 源类
  5084. * @param {Function} baseClazz 基类
  5085. */
  5086. function inherits(clazz, baseClazz) {
  5087. var clazzPrototype = clazz.prototype;
  5088. function F() { }
  5089. F.prototype = baseClazz.prototype;
  5090. clazz.prototype = new F();
  5091. for (var prop in clazzPrototype) {
  5092. clazz.prototype[prop] = clazzPrototype[prop];
  5093. }
  5094. clazz.prototype.constructor = clazz;
  5095. clazz.superClass = baseClazz;
  5096. }
  5097. /**
  5098. * @memberOf module:zrender/core/util
  5099. * @param {Object|Function} target
  5100. * @param {Object|Function} sorce
  5101. * @param {boolean} overlay
  5102. */
  5103. function mixin(target, source, overlay) {
  5104. target = 'prototype' in target ? target.prototype : target;
  5105. source = 'prototype' in source ? source.prototype : source;
  5106. defaults(target, source, overlay);
  5107. }
  5108. /**
  5109. * Consider typed array.
  5110. * @param {Array|TypedArray} data
  5111. */
  5112. function isArrayLike(data) {
  5113. if (!data) {
  5114. return;
  5115. }
  5116. if (typeof data == 'string') {
  5117. return false;
  5118. }
  5119. return typeof data.length == 'number';
  5120. }
  5121. /**
  5122. * 数组或对象遍历
  5123. * @memberOf module:zrender/core/util
  5124. * @param {Object|Array} obj
  5125. * @param {Function} cb
  5126. * @param {*} [context]
  5127. */
  5128. function each(obj, cb, context) {
  5129. if (!(obj && cb)) {
  5130. return;
  5131. }
  5132. if (obj.forEach && obj.forEach === nativeForEach) {
  5133. obj.forEach(cb, context);
  5134. } else if (obj.length === +obj.length) {
  5135. for (var i = 0, len = obj.length; i < len; i++) {
  5136. cb.call(context, obj[i], i, obj);
  5137. }
  5138. } else {
  5139. for (var key in obj) {
  5140. if (obj.hasOwnProperty(key)) {
  5141. cb.call(context, obj[key], key, obj);
  5142. }
  5143. }
  5144. }
  5145. }
  5146. /**
  5147. * æ•°ç»„æ˜ å°„
  5148. * @memberOf module:zrender/core/util
  5149. * @param {Array} obj
  5150. * @param {Function} cb
  5151. * @param {*} [context]
  5152. * @return {Array}
  5153. */
  5154. function map(obj, cb, context) {
  5155. if (!(obj && cb)) {
  5156. return;
  5157. }
  5158. if (obj.map && obj.map === nativeMap) {
  5159. return obj.map(cb, context);
  5160. } else {
  5161. var result = [];
  5162. for (var i = 0, len = obj.length; i < len; i++) {
  5163. result.push(cb.call(context, obj[i], i, obj));
  5164. }
  5165. return result;
  5166. }
  5167. }
  5168. /**
  5169. * @memberOf module:zrender/core/util
  5170. * @param {Array} obj
  5171. * @param {Function} cb
  5172. * @param {Object} [memo]
  5173. * @param {*} [context]
  5174. * @return {Array}
  5175. */
  5176. function reduce(obj, cb, memo, context) {
  5177. if (!(obj && cb)) {
  5178. return;
  5179. }
  5180. if (obj.reduce && obj.reduce === nativeReduce) {
  5181. return obj.reduce(cb, memo, context);
  5182. } else {
  5183. for (var i = 0, len = obj.length; i < len; i++) {
  5184. memo = cb.call(context, memo, obj[i], i, obj);
  5185. }
  5186. return memo;
  5187. }
  5188. }
  5189. /**
  5190. * 数组过滤
  5191. * @memberOf module:zrender/core/util
  5192. * @param {Array} obj
  5193. * @param {Function} cb
  5194. * @param {*} [context]
  5195. * @return {Array}
  5196. */
  5197. function filter(obj, cb, context) {
  5198. if (!(obj && cb)) {
  5199. return;
  5200. }
  5201. if (obj.filter && obj.filter === nativeFilter) {
  5202. return obj.filter(cb, context);
  5203. } else {
  5204. var result = [];
  5205. for (var i = 0, len = obj.length; i < len; i++) {
  5206. if (cb.call(context, obj[i], i, obj)) {
  5207. result.push(obj[i]);
  5208. }
  5209. }
  5210. return result;
  5211. }
  5212. }
  5213. /**
  5214. * 数组项查找
  5215. * @memberOf module:zrender/core/util
  5216. * @param {Array} obj
  5217. * @param {Function} cb
  5218. * @param {*} [context]
  5219. * @return {*}
  5220. */
  5221. function find(obj, cb, context) {
  5222. if (!(obj && cb)) {
  5223. return;
  5224. }
  5225. for (var i = 0, len = obj.length; i < len; i++) {
  5226. if (cb.call(context, obj[i], i, obj)) {
  5227. return obj[i];
  5228. }
  5229. }
  5230. }
  5231. /**
  5232. * @memberOf module:zrender/core/util
  5233. * @param {Function} func
  5234. * @param {*} context
  5235. * @return {Function}
  5236. */
  5237. function bind(func, context) {
  5238. var args = nativeSlice.call(arguments, 2);
  5239. return function () {
  5240. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  5241. };
  5242. }
  5243. /**
  5244. * @memberOf module:zrender/core/util
  5245. * @param {Function} func
  5246. * @return {Function}
  5247. */
  5248. function curry(func) {
  5249. var args = nativeSlice.call(arguments, 1);
  5250. return function () {
  5251. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  5252. };
  5253. }
  5254. /**
  5255. * @memberOf module:zrender/core/util
  5256. * @param {*} value
  5257. * @return {boolean}
  5258. */
  5259. function isArray(value) {
  5260. return objToString.call(value) === '[object Array]';
  5261. }
  5262. /**
  5263. * @memberOf module:zrender/core/util
  5264. * @param {*} value
  5265. * @return {boolean}
  5266. */
  5267. function isFunction(value) {
  5268. return typeof value === 'function';
  5269. }
  5270. /**
  5271. * @memberOf module:zrender/core/util
  5272. * @param {*} value
  5273. * @return {boolean}
  5274. */
  5275. function isString(value) {
  5276. return objToString.call(value) === '[object String]';
  5277. }
  5278. /**
  5279. * @memberOf module:zrender/core/util
  5280. * @param {*} value
  5281. * @return {boolean}
  5282. */
  5283. function isObject(value) {
  5284. // Avoid a V8 JIT bug in Chrome 19-20.
  5285. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  5286. var type = typeof value;
  5287. return type === 'function' || !!value && type == 'object';
  5288. }
  5289. /**
  5290. * @memberOf module:zrender/core/util
  5291. * @param {*} value
  5292. * @return {boolean}
  5293. */
  5294. function isBuiltInObject(value) {
  5295. return !!BUILTIN_OBJECT[objToString.call(value)];
  5296. }
  5297. /**
  5298. * @memberOf module:zrender/core/util
  5299. * @param {*} value
  5300. * @return {boolean}
  5301. */
  5302. function isTypedArray(value) {
  5303. return !!TYPED_ARRAY[objToString.call(value)];
  5304. }
  5305. /**
  5306. * @memberOf module:zrender/core/util
  5307. * @param {*} value
  5308. * @return {boolean}
  5309. */
  5310. function isDom(value) {
  5311. return typeof value === 'object' && typeof value.nodeType === 'number' && typeof value.ownerDocument === 'object';
  5312. }
  5313. /**
  5314. * Whether is exactly NaN. Notice isNaN('a') returns true.
  5315. * @param {*} value
  5316. * @return {boolean}
  5317. */
  5318. function eqNaN(value) {
  5319. return value !== value;
  5320. }
  5321. /**
  5322. * If value1 is not null, then return value1, otherwise judget rest of values.
  5323. * Low performance.
  5324. * @memberOf module:zrender/core/util
  5325. * @return {*} Final value
  5326. */
  5327. function retrieve(values) {
  5328. for (var i = 0, len = arguments.length; i < len; i++) {
  5329. if (arguments[i] != null) {
  5330. return arguments[i];
  5331. }
  5332. }
  5333. }
  5334. function retrieve2(value0, value1) {
  5335. return value0 != null ? value0 : value1;
  5336. }
  5337. function retrieve3(value0, value1, value2) {
  5338. return value0 != null ? value0 : value1 != null ? value1 : value2;
  5339. }
  5340. /**
  5341. * @memberOf module:zrender/core/util
  5342. * @param {Array} arr
  5343. * @param {number} startIndex
  5344. * @param {number} endIndex
  5345. * @return {Array}
  5346. */
  5347. function slice() {
  5348. return Function.call.apply(nativeSlice, arguments);
  5349. }
  5350. /**
  5351. * Normalize css liked array configuration
  5352. * e.g.
  5353. * 3 => [3, 3, 3, 3]
  5354. * [4, 2] => [4, 2, 4, 2]
  5355. * [4, 3, 2] => [4, 3, 2, 3]
  5356. * @param {number|Array.<number>} val
  5357. * @return {Array.<number>}
  5358. */
  5359. function normalizeCssArray(val) {
  5360. if (typeof val === 'number') {
  5361. return [val, val, val, val];
  5362. }
  5363. var len = val.length;
  5364. if (len === 2) {
  5365. // vertical | horizontal
  5366. return [val[0], val[1], val[0], val[1]];
  5367. } else if (len === 3) {
  5368. // top | horizontal | bottom
  5369. return [val[0], val[1], val[2], val[1]];
  5370. }
  5371. return val;
  5372. }
  5373. /**
  5374. * @memberOf module:zrender/core/util
  5375. * @param {boolean} condition
  5376. * @param {string} message
  5377. */
  5378. function assert(condition, message) {
  5379. if (!condition) {
  5380. throw new Error(message);
  5381. }
  5382. }
  5383. /**
  5384. * @memberOf module:zrender/core/util
  5385. * @param {string} str string to be trimed
  5386. * @return {string} trimed string
  5387. */
  5388. function trim(str) {
  5389. if (str == null) {
  5390. return null;
  5391. } else if (typeof str.trim === 'function') {
  5392. return str.trim();
  5393. } else {
  5394. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  5395. }
  5396. }
  5397. var primitiveKey = '__ec_primitive__';
  5398. /**
  5399. * Set an object as primitive to be ignored traversing children in clone or merge
  5400. */
  5401. function setAsPrimitive(obj) {
  5402. obj[primitiveKey] = true;
  5403. }
  5404. function isPrimitive(obj) {
  5405. return obj[primitiveKey];
  5406. }
  5407. /**
  5408. * @constructor
  5409. * @param {Object} obj Only apply `ownProperty`.
  5410. */
  5411. function HashMap(obj) {
  5412. var isArr = isArray(obj);
  5413. var thisMap = this;
  5414. obj instanceof HashMap ? obj.each(visit) : obj && each(obj, visit);
  5415. function visit(value, key) {
  5416. isArr ? thisMap.set(value, key) : thisMap.set(key, value);
  5417. }
  5418. } // Add prefix to avoid conflict with Object.prototype.
  5419. HashMap.prototype = {
  5420. constructor: HashMap,
  5421. // Do not provide `has` method to avoid defining what is `has`.
  5422. // (We usually treat `null` and `undefined` as the same, different
  5423. // from ES6 Map).
  5424. get: function (key) {
  5425. return this.hasOwnProperty(key) ? this[key] : null;
  5426. },
  5427. set: function (key, value) {
  5428. // Comparing with invocation chaining, `return value` is more commonly
  5429. // used in this case: `var someVal = map.set('a', genVal());`
  5430. return this[key] = value;
  5431. },
  5432. // Although util.each can be performed on this hashMap directly, user
  5433. // should not use the exposed keys, who are prefixed.
  5434. each: function (cb, context) {
  5435. context !== void 0 && (cb = bind(cb, context));
  5436. for (var key in this) {
  5437. this.hasOwnProperty(key) && cb(this[key], key);
  5438. }
  5439. },
  5440. // Do not use this method if performance sensitive.
  5441. removeKey: function (key) {
  5442. delete this[key];
  5443. }
  5444. };
  5445. function createHashMap(obj) {
  5446. return new HashMap(obj);
  5447. }
  5448. function concatArray(a, b) {
  5449. var newArray = new a.constructor(a.length + b.length);
  5450. for (var i = 0; i < a.length; i++) {
  5451. newArray[i] = a[i];
  5452. }
  5453. var offset = a.length;
  5454. for (i = 0; i < b.length; i++) {
  5455. newArray[i + offset] = b[i];
  5456. }
  5457. return newArray;
  5458. }
  5459. function noop() { }
  5460. exports.$override = $override;
  5461. exports.clone = clone;
  5462. exports.merge = merge;
  5463. exports.mergeAll = mergeAll;
  5464. exports.extend = extend;
  5465. exports.defaults = defaults;
  5466. exports.createCanvas = createCanvas;
  5467. exports.getContext = getContext;
  5468. exports.indexOf = indexOf;
  5469. exports.inherits = inherits;
  5470. exports.mixin = mixin;
  5471. exports.isArrayLike = isArrayLike;
  5472. exports.each = each;
  5473. exports.map = map;
  5474. exports.reduce = reduce;
  5475. exports.filter = filter;
  5476. exports.find = find;
  5477. exports.bind = bind;
  5478. exports.curry = curry;
  5479. exports.isArray = isArray;
  5480. exports.isFunction = isFunction;
  5481. exports.isString = isString;
  5482. exports.isObject = isObject;
  5483. exports.isBuiltInObject = isBuiltInObject;
  5484. exports.isTypedArray = isTypedArray;
  5485. exports.isDom = isDom;
  5486. exports.eqNaN = eqNaN;
  5487. exports.retrieve = retrieve;
  5488. exports.retrieve2 = retrieve2;
  5489. exports.retrieve3 = retrieve3;
  5490. exports.slice = slice;
  5491. exports.normalizeCssArray = normalizeCssArray;
  5492. exports.assert = assert;
  5493. exports.trim = trim;
  5494. exports.setAsPrimitive = setAsPrimitive;
  5495. exports.isPrimitive = isPrimitive;
  5496. exports.createHashMap = createHashMap;
  5497. exports.concatArray = concatArray;
  5498. exports.noop = noop;
  5499. /***/
  5500. }),
  5501. /* 14 */
  5502. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  5503. "use strict";
  5504. /* WEBPACK VAR INJECTION */(function (global) {/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__request__ = __webpack_require__(112);
  5505. var supportWebGL;
  5506. var vendor = {};
  5507. /**
  5508. * If support WebGL
  5509. * @return {boolean}
  5510. */
  5511. vendor.supportWebGL = function () {
  5512. if (supportWebGL == null) {
  5513. try {
  5514. var canvas = document.createElement('canvas');
  5515. var gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
  5516. if (!gl) {
  5517. throw new Error();
  5518. }
  5519. }
  5520. catch (e) {
  5521. supportWebGL = false;
  5522. }
  5523. }
  5524. return supportWebGL;
  5525. };
  5526. vendor.Int8Array = typeof Int8Array === 'undefined' ? Array : Int8Array;
  5527. vendor.Uint8Array = typeof Uint8Array === 'undefined' ? Array : Uint8Array;
  5528. vendor.Uint16Array = typeof Uint16Array === 'undefined' ? Array : Uint16Array;
  5529. vendor.Uint32Array = typeof Uint32Array === 'undefined' ? Array : Uint32Array;
  5530. vendor.Int16Array = typeof Int16Array === 'undefined' ? Array : Int16Array;
  5531. vendor.Float32Array = typeof Float32Array === 'undefined' ? Array : Float32Array;
  5532. vendor.Float64Array = typeof Float64Array === 'undefined' ? Array : Float64Array;
  5533. var g = {};
  5534. if (typeof window !== 'undefined') {
  5535. g = window;
  5536. }
  5537. else if (typeof global !== 'undefined') {
  5538. g = global;
  5539. }
  5540. vendor.requestAnimationFrame = g.requestAnimationFrame
  5541. || g.msRequestAnimationFrame
  5542. || g.mozRequestAnimationFrame
  5543. || g.webkitRequestAnimationFrame
  5544. || function (func) { setTimeout(func, 16); };
  5545. vendor.createCanvas = function () {
  5546. return document.createElement('canvas');
  5547. };
  5548. vendor.createImage = function () {
  5549. return new g.Image();
  5550. };
  5551. vendor.request = {
  5552. get: __WEBPACK_IMPORTED_MODULE_0__request__["a" /* default */].get
  5553. };
  5554. /* harmony default export */ __webpack_exports__["a"] = (vendor);
  5555. /* WEBPACK VAR INJECTION */
  5556. }.call(__webpack_exports__, __webpack_require__(68)))
  5557. /***/
  5558. }),
  5559. /* 15 */
  5560. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  5561. "use strict";
  5562. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__core_vendor__ = __webpack_require__(14);
  5563. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__ = __webpack_require__(12);
  5564. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__glmatrix_mat4__ = __webpack_require__(21);
  5565. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__math_BoundingBox__ = __webpack_require__(18);
  5566. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__GeometryBase__ = __webpack_require__(118);
  5567. var vec3Create = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].create;
  5568. var vec3Add = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].add;
  5569. var vec3Set = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].set;
  5570. var Attribute = __WEBPACK_IMPORTED_MODULE_4__GeometryBase__["a" /* default */].Attribute;
  5571. /**
  5572. * Geometry in ClayGL contains vertex attributes of mesh. These vertex attributes will be finally provided to the {@link clay.Shader}.
  5573. * Different {@link clay.Shader} needs different attributes. Here is a list of attributes used in the builtin shaders.
  5574. *
  5575. * + position: `clay.basic`, `clay.lambert`, `clay.standard`
  5576. * + texcoord0: `clay.basic`, `clay.lambert`, `clay.standard`
  5577. * + color: `clay.basic`, `clay.lambert`, `clay.standard`
  5578. * + weight: `clay.basic`, `clay.lambert`, `clay.standard`
  5579. * + joint: `clay.basic`, `clay.lambert`, `clay.standard`
  5580. * + normal: `clay.lambert`, `clay.standard`
  5581. * + tangent: `clay.standard`
  5582. *
  5583. * #### Create a procedural geometry
  5584. *
  5585. * ClayGL provides a couple of builtin procedural geometries. Inlcuding:
  5586. *
  5587. * + {@link clay.geometry.Cube}
  5588. * + {@link clay.geometry.Sphere}
  5589. * + {@link clay.geometry.Plane}
  5590. * + {@link clay.geometry.Cylinder}
  5591. * + {@link clay.geometry.Cone}
  5592. * + {@link clay.geometry.ParametricSurface}
  5593. *
  5594. * It's simple to create a basic geometry with these classes.
  5595. *
  5596. ```js
  5597. var sphere = new clay.geometry.Sphere({
  5598. radius: 2
  5599. });
  5600. ```
  5601. *
  5602. * #### Create the geometry data by yourself
  5603. *
  5604. * Usually the vertex attributes data are created by the {@link clay.loader.GLTF} or procedural geometries like {@link clay.geometry.Sphere}.
  5605. * Besides these, you can create the data manually. Here is a simple example to create a triangle.
  5606. ```js
  5607. var TRIANGLE_POSITIONS = [
  5608. [-0.5, -0.5, 0],
  5609. [0.5, -0.5, 0],
  5610. [0, 0.5, 0]
  5611. ];
  5612. var geometry = new clay.StaticGeometryBase();
  5613. // Add triangle vertices to position attribute.
  5614. geometry.attributes.position.fromArray(TRIANGLE_POSITIONS);
  5615. ```
  5616. * Then you can use the utility methods like `generateVertexNormals`, `generateTangents` to create the remaining necessary attributes.
  5617. *
  5618. *
  5619. * #### Use with custom shaders
  5620. *
  5621. * If you wan't to write custom shaders. Don't forget to add SEMANTICS to these attributes. For example
  5622. *
  5623. ```glsl
  5624. uniform mat4 worldViewProjection : WORLDVIEWPROJECTION;
  5625. uniform mat4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
  5626. uniform mat4 world : WORLD;
  5627. attribute vec3 position : POSITION;
  5628. attribute vec2 texcoord : TEXCOORD_0;
  5629. attribute vec3 normal : NORMAL;
  5630. ```
  5631. * These `POSITION`, `TEXCOORD_0`, `NORMAL` are SEMANTICS which will map the attributes in shader to the attributes in the GeometryBase
  5632. *
  5633. * Available attributes SEMANTICS includes `POSITION`, `TEXCOORD_0`, `TEXCOORD_1` `NORMAL`, `TANGENT`, `COLOR`, `WEIGHT`, `JOINT`.
  5634. *
  5635. *
  5636. * @constructor clay.Geometry
  5637. * @extends clay.GeometryBase
  5638. */
  5639. var Geometry = __WEBPACK_IMPORTED_MODULE_4__GeometryBase__["a" /* default */].extend(function () {
  5640. return /** @lends clay.Geometry# */ {
  5641. /**
  5642. * Attributes of geometry. Including:
  5643. * + `position`
  5644. * + `texcoord0`
  5645. * + `texcoord1`
  5646. * + `normal`
  5647. * + `tangent`
  5648. * + `color`
  5649. * + `weight`
  5650. * + `joint`
  5651. * + `barycentric`
  5652. *
  5653. * @type {Object.<string, clay.Geometry.Attribute>}
  5654. */
  5655. attributes: {
  5656. position: new Attribute('position', 'float', 3, 'POSITION'),
  5657. texcoord0: new Attribute('texcoord0', 'float', 2, 'TEXCOORD_0'),
  5658. texcoord1: new Attribute('texcoord1', 'float', 2, 'TEXCOORD_1'),
  5659. normal: new Attribute('normal', 'float', 3, 'NORMAL'),
  5660. tangent: new Attribute('tangent', 'float', 4, 'TANGENT'),
  5661. color: new Attribute('color', 'float', 4, 'COLOR'),
  5662. // Skinning attributes
  5663. // Each vertex can be bind to 4 bones, because the
  5664. // sum of weights is 1, so the weights is stored in vec3 and the last
  5665. // can be calculated by 1-w.x-w.y-w.z
  5666. weight: new Attribute('weight', 'float', 3, 'WEIGHT'),
  5667. joint: new Attribute('joint', 'float', 4, 'JOINT'),
  5668. // For wireframe display
  5669. // http://codeflow.org/entries/2012/aug/02/easy-wireframe-display-with-barycentric-coordinates/
  5670. barycentric: new Attribute('barycentric', 'float', 3, null),
  5671. },
  5672. /**
  5673. * Calculated bounding box of geometry.
  5674. * @type {clay.BoundingBox}
  5675. */
  5676. boundingBox: null
  5677. };
  5678. },
  5679. /** @lends clay.Geometry.prototype */
  5680. {
  5681. mainAttribute: 'position',
  5682. /**
  5683. * Update boundingBox of Geometry
  5684. */
  5685. updateBoundingBox: function () {
  5686. var bbox = this.boundingBox;
  5687. if (!bbox) {
  5688. bbox = this.boundingBox = new __WEBPACK_IMPORTED_MODULE_3__math_BoundingBox__["a" /* default */]();
  5689. }
  5690. var posArr = this.attributes.position.value;
  5691. if (posArr && posArr.length) {
  5692. var min = bbox.min;
  5693. var max = bbox.max;
  5694. var minArr = min.array;
  5695. var maxArr = max.array;
  5696. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].set(minArr, posArr[0], posArr[1], posArr[2]);
  5697. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].set(maxArr, posArr[0], posArr[1], posArr[2]);
  5698. for (var i = 3; i < posArr.length;) {
  5699. var x = posArr[i++];
  5700. var y = posArr[i++];
  5701. var z = posArr[i++];
  5702. if (x < minArr[0]) { minArr[0] = x; }
  5703. if (y < minArr[1]) { minArr[1] = y; }
  5704. if (z < minArr[2]) { minArr[2] = z; }
  5705. if (x > maxArr[0]) { maxArr[0] = x; }
  5706. if (y > maxArr[1]) { maxArr[1] = y; }
  5707. if (z > maxArr[2]) { maxArr[2] = z; }
  5708. }
  5709. min._dirty = true;
  5710. max._dirty = true;
  5711. }
  5712. },
  5713. /**
  5714. * Generate normals per vertex.
  5715. */
  5716. generateVertexNormals: function () {
  5717. if (!this.vertexCount) {
  5718. return;
  5719. }
  5720. var indices = this.indices;
  5721. var attributes = this.attributes;
  5722. var positions = attributes.position.value;
  5723. var normals = attributes.normal.value;
  5724. if (!normals || normals.length !== positions.length) {
  5725. normals = attributes.normal.value = new __WEBPACK_IMPORTED_MODULE_0__core_vendor__["a" /* default */].Float32Array(positions.length);
  5726. }
  5727. else {
  5728. // Reset
  5729. for (var i = 0; i < normals.length; i++) {
  5730. normals[i] = 0;
  5731. }
  5732. }
  5733. var p1 = vec3Create();
  5734. var p2 = vec3Create();
  5735. var p3 = vec3Create();
  5736. var v21 = vec3Create();
  5737. var v32 = vec3Create();
  5738. var n = vec3Create();
  5739. var len = indices ? indices.length : this.vertexCount;
  5740. var i1, i2, i3;
  5741. for (var f = 0; f < len;) {
  5742. if (indices) {
  5743. i1 = indices[f++];
  5744. i2 = indices[f++];
  5745. i3 = indices[f++];
  5746. }
  5747. else {
  5748. i1 = f++;
  5749. i2 = f++;
  5750. i3 = f++;
  5751. }
  5752. vec3Set(p1, positions[i1 * 3], positions[i1 * 3 + 1], positions[i1 * 3 + 2]);
  5753. vec3Set(p2, positions[i2 * 3], positions[i2 * 3 + 1], positions[i2 * 3 + 2]);
  5754. vec3Set(p3, positions[i3 * 3], positions[i3 * 3 + 1], positions[i3 * 3 + 2]);
  5755. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].sub(v21, p1, p2);
  5756. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].sub(v32, p2, p3);
  5757. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].cross(n, v21, v32);
  5758. // Already be weighted by the triangle area
  5759. for (var i = 0; i < 3; i++) {
  5760. normals[i1 * 3 + i] = normals[i1 * 3 + i] + n[i];
  5761. normals[i2 * 3 + i] = normals[i2 * 3 + i] + n[i];
  5762. normals[i3 * 3 + i] = normals[i3 * 3 + i] + n[i];
  5763. }
  5764. }
  5765. for (var i = 0; i < normals.length;) {
  5766. vec3Set(n, normals[i], normals[i + 1], normals[i + 2]);
  5767. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].normalize(n, n);
  5768. normals[i++] = n[0];
  5769. normals[i++] = n[1];
  5770. normals[i++] = n[2];
  5771. }
  5772. this.dirty();
  5773. },
  5774. /**
  5775. * Generate normals per face.
  5776. */
  5777. generateFaceNormals: function () {
  5778. if (!this.vertexCount) {
  5779. return;
  5780. }
  5781. if (!this.isUniqueVertex()) {
  5782. this.generateUniqueVertex();
  5783. }
  5784. var indices = this.indices;
  5785. var attributes = this.attributes;
  5786. var positions = attributes.position.value;
  5787. var normals = attributes.normal.value;
  5788. var p1 = vec3Create();
  5789. var p2 = vec3Create();
  5790. var p3 = vec3Create();
  5791. var v21 = vec3Create();
  5792. var v32 = vec3Create();
  5793. var n = vec3Create();
  5794. if (!normals) {
  5795. normals = attributes.normal.value = new Float32Array(positions.length);
  5796. }
  5797. var len = indices ? indices.length : this.vertexCount;
  5798. var i1, i2, i3;
  5799. for (var f = 0; f < len;) {
  5800. if (indices) {
  5801. i1 = indices[f++];
  5802. i2 = indices[f++];
  5803. i3 = indices[f++];
  5804. }
  5805. else {
  5806. i1 = f++;
  5807. i2 = f++;
  5808. i3 = f++;
  5809. }
  5810. vec3Set(p1, positions[i1 * 3], positions[i1 * 3 + 1], positions[i1 * 3 + 2]);
  5811. vec3Set(p2, positions[i2 * 3], positions[i2 * 3 + 1], positions[i2 * 3 + 2]);
  5812. vec3Set(p3, positions[i3 * 3], positions[i3 * 3 + 1], positions[i3 * 3 + 2]);
  5813. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].sub(v21, p1, p2);
  5814. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].sub(v32, p2, p3);
  5815. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].cross(n, v21, v32);
  5816. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].normalize(n, n);
  5817. for (var i = 0; i < 3; i++) {
  5818. normals[i1 * 3 + i] = n[i];
  5819. normals[i2 * 3 + i] = n[i];
  5820. normals[i3 * 3 + i] = n[i];
  5821. }
  5822. }
  5823. this.dirty();
  5824. },
  5825. /**
  5826. * Generate tangents attributes.
  5827. */
  5828. generateTangents: function () {
  5829. if (!this.vertexCount) {
  5830. return;
  5831. }
  5832. var nVertex = this.vertexCount;
  5833. var attributes = this.attributes;
  5834. if (!attributes.tangent.value) {
  5835. attributes.tangent.value = new Float32Array(nVertex * 4);
  5836. }
  5837. var texcoords = attributes.texcoord0.value;
  5838. var positions = attributes.position.value;
  5839. var tangents = attributes.tangent.value;
  5840. var normals = attributes.normal.value;
  5841. if (!texcoords) {
  5842. console.warn('Geometry without texcoords can\'t generate tangents.');
  5843. return;
  5844. }
  5845. var tan1 = [];
  5846. var tan2 = [];
  5847. for (var i = 0; i < nVertex; i++) {
  5848. tan1[i] = [0.0, 0.0, 0.0];
  5849. tan2[i] = [0.0, 0.0, 0.0];
  5850. }
  5851. var sdir = [0.0, 0.0, 0.0];
  5852. var tdir = [0.0, 0.0, 0.0];
  5853. var indices = this.indices;
  5854. var len = indices ? indices.length : this.vertexCount;
  5855. var i1, i2, i3;
  5856. for (var i = 0; i < len;) {
  5857. if (indices) {
  5858. i1 = indices[i++];
  5859. i2 = indices[i++];
  5860. i3 = indices[i++];
  5861. }
  5862. else {
  5863. i1 = i++;
  5864. i2 = i++;
  5865. i3 = i++;
  5866. }
  5867. var st1s = texcoords[i1 * 2],
  5868. st2s = texcoords[i2 * 2],
  5869. st3s = texcoords[i3 * 2],
  5870. st1t = texcoords[i1 * 2 + 1],
  5871. st2t = texcoords[i2 * 2 + 1],
  5872. st3t = texcoords[i3 * 2 + 1],
  5873. p1x = positions[i1 * 3],
  5874. p2x = positions[i2 * 3],
  5875. p3x = positions[i3 * 3],
  5876. p1y = positions[i1 * 3 + 1],
  5877. p2y = positions[i2 * 3 + 1],
  5878. p3y = positions[i3 * 3 + 1],
  5879. p1z = positions[i1 * 3 + 2],
  5880. p2z = positions[i2 * 3 + 2],
  5881. p3z = positions[i3 * 3 + 2];
  5882. var x1 = p2x - p1x,
  5883. x2 = p3x - p1x,
  5884. y1 = p2y - p1y,
  5885. y2 = p3y - p1y,
  5886. z1 = p2z - p1z,
  5887. z2 = p3z - p1z;
  5888. var s1 = st2s - st1s,
  5889. s2 = st3s - st1s,
  5890. t1 = st2t - st1t,
  5891. t2 = st3t - st1t;
  5892. var r = 1.0 / (s1 * t2 - t1 * s2);
  5893. sdir[0] = (t2 * x1 - t1 * x2) * r;
  5894. sdir[1] = (t2 * y1 - t1 * y2) * r;
  5895. sdir[2] = (t2 * z1 - t1 * z2) * r;
  5896. tdir[0] = (s1 * x2 - s2 * x1) * r;
  5897. tdir[1] = (s1 * y2 - s2 * y1) * r;
  5898. tdir[2] = (s1 * z2 - s2 * z1) * r;
  5899. vec3Add(tan1[i1], tan1[i1], sdir);
  5900. vec3Add(tan1[i2], tan1[i2], sdir);
  5901. vec3Add(tan1[i3], tan1[i3], sdir);
  5902. vec3Add(tan2[i1], tan2[i1], tdir);
  5903. vec3Add(tan2[i2], tan2[i2], tdir);
  5904. vec3Add(tan2[i3], tan2[i3], tdir);
  5905. }
  5906. var tmp = vec3Create();
  5907. var nCrossT = vec3Create();
  5908. var n = vec3Create();
  5909. for (var i = 0; i < nVertex; i++) {
  5910. n[0] = normals[i * 3];
  5911. n[1] = normals[i * 3 + 1];
  5912. n[2] = normals[i * 3 + 2];
  5913. var t = tan1[i];
  5914. // Gram-Schmidt orthogonalize
  5915. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].scale(tmp, n, __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].dot(n, t));
  5916. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].sub(tmp, t, tmp);
  5917. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].normalize(tmp, tmp);
  5918. // Calculate handedness.
  5919. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].cross(nCrossT, n, t);
  5920. tangents[i * 4] = tmp[0];
  5921. tangents[i * 4 + 1] = tmp[1];
  5922. tangents[i * 4 + 2] = tmp[2];
  5923. // PENDING can config ?
  5924. tangents[i * 4 + 3] = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].dot(nCrossT, tan2[i]) < 0.0 ? -1.0 : 1.0;
  5925. }
  5926. this.dirty();
  5927. },
  5928. /**
  5929. * If vertices are not shared by different indices.
  5930. */
  5931. isUniqueVertex: function () {
  5932. if (this.isUseIndices()) {
  5933. return this.vertexCount === this.indices.length;
  5934. }
  5935. else {
  5936. return true;
  5937. }
  5938. },
  5939. /**
  5940. * Create a unique vertex for each index.
  5941. */
  5942. generateUniqueVertex: function () {
  5943. if (!this.vertexCount || !this.indices) {
  5944. return;
  5945. }
  5946. if (this.indices.length > 0xffff) {
  5947. this.indices = new __WEBPACK_IMPORTED_MODULE_0__core_vendor__["a" /* default */].Uint32Array(this.indices);
  5948. }
  5949. var attributes = this.attributes;
  5950. var indices = this.indices;
  5951. var attributeNameList = this.getEnabledAttributes();
  5952. var oldAttrValues = {};
  5953. for (var a = 0; a < attributeNameList.length; a++) {
  5954. var name = attributeNameList[a];
  5955. oldAttrValues[name] = attributes[name].value;
  5956. attributes[name].init(this.indices.length);
  5957. }
  5958. var cursor = 0;
  5959. for (var i = 0; i < indices.length; i++) {
  5960. var ii = indices[i];
  5961. for (var a = 0; a < attributeNameList.length; a++) {
  5962. var name = attributeNameList[a];
  5963. var array = attributes[name].value;
  5964. var size = attributes[name].size;
  5965. for (var k = 0; k < size; k++) {
  5966. array[cursor * size + k] = oldAttrValues[name][ii * size + k];
  5967. }
  5968. }
  5969. indices[i] = cursor;
  5970. cursor++;
  5971. }
  5972. this.dirty();
  5973. },
  5974. /**
  5975. * Generate barycentric coordinates for wireframe draw.
  5976. */
  5977. generateBarycentric: function () {
  5978. if (!this.vertexCount) {
  5979. return;
  5980. }
  5981. if (!this.isUniqueVertex()) {
  5982. this.generateUniqueVertex();
  5983. }
  5984. var attributes = this.attributes;
  5985. var array = attributes.barycentric.value;
  5986. var indices = this.indices;
  5987. // Already existed;
  5988. if (array && array.length === indices.length * 3) {
  5989. return;
  5990. }
  5991. array = attributes.barycentric.value = new Float32Array(indices.length * 3);
  5992. for (var i = 0; i < (indices ? indices.length : this.vertexCount / 3);) {
  5993. for (var j = 0; j < 3; j++) {
  5994. var ii = indices ? indices[i++] : (i * 3 + j);
  5995. array[ii * 3 + j] = 1;
  5996. }
  5997. }
  5998. this.dirty();
  5999. },
  6000. /**
  6001. * Apply transform to geometry attributes.
  6002. * @param {clay.Matrix4} matrix
  6003. */
  6004. applyTransform: function (matrix) {
  6005. var attributes = this.attributes;
  6006. var positions = attributes.position.value;
  6007. var normals = attributes.normal.value;
  6008. var tangents = attributes.tangent.value;
  6009. matrix = matrix.array;
  6010. // Normal Matrix
  6011. var inverseTransposeMatrix = __WEBPACK_IMPORTED_MODULE_2__glmatrix_mat4__["a" /* default */].create();
  6012. __WEBPACK_IMPORTED_MODULE_2__glmatrix_mat4__["a" /* default */].invert(inverseTransposeMatrix, matrix);
  6013. __WEBPACK_IMPORTED_MODULE_2__glmatrix_mat4__["a" /* default */].transpose(inverseTransposeMatrix, inverseTransposeMatrix);
  6014. var vec3TransformMat4 = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].transformMat4;
  6015. var vec3ForEach = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].forEach;
  6016. vec3ForEach(positions, 3, 0, null, vec3TransformMat4, matrix);
  6017. if (normals) {
  6018. vec3ForEach(normals, 3, 0, null, vec3TransformMat4, inverseTransposeMatrix);
  6019. }
  6020. if (tangents) {
  6021. vec3ForEach(tangents, 4, 0, null, vec3TransformMat4, inverseTransposeMatrix);
  6022. }
  6023. if (this.boundingBox) {
  6024. this.updateBoundingBox();
  6025. }
  6026. },
  6027. /**
  6028. * Dispose geometry data in GL context.
  6029. * @param {clay.Renderer} renderer
  6030. */
  6031. dispose: function (renderer) {
  6032. var cache = this._cache;
  6033. cache.use(renderer.__uid__);
  6034. var chunks = cache.get('chunks');
  6035. if (chunks) {
  6036. for (var c = 0; c < chunks.length; c++) {
  6037. var chunk = chunks[c];
  6038. for (var k = 0; k < chunk.attributeBuffers.length; k++) {
  6039. var attribs = chunk.attributeBuffers[k];
  6040. renderer.gl.deleteBuffer(attribs.buffer);
  6041. }
  6042. if (chunk.indicesBuffer) {
  6043. renderer.gl.deleteBuffer(chunk.indicesBuffer.buffer);
  6044. }
  6045. }
  6046. }
  6047. if (this.__vaoCache) {
  6048. var vaoExt = renderer.getGLExtension('OES_vertex_array_object');
  6049. for (var id in this.__vaoCache) {
  6050. var vao = this.__vaoCache[id].vao;
  6051. if (vao) {
  6052. vaoExt.deleteVertexArrayOES(vao);
  6053. }
  6054. }
  6055. }
  6056. this.__vaoCache = {};
  6057. cache.deleteContext(renderer.__uid__);
  6058. }
  6059. });
  6060. Geometry.STATIC_DRAW = __WEBPACK_IMPORTED_MODULE_4__GeometryBase__["a" /* default */].STATIC_DRAW;
  6061. Geometry.DYNAMIC_DRAW = __WEBPACK_IMPORTED_MODULE_4__GeometryBase__["a" /* default */].DYNAMIC_DRAW;
  6062. Geometry.STREAM_DRAW = __WEBPACK_IMPORTED_MODULE_4__GeometryBase__["a" /* default */].STREAM_DRAW;
  6063. Geometry.AttributeBuffer = __WEBPACK_IMPORTED_MODULE_4__GeometryBase__["a" /* default */].AttributeBuffer;
  6064. Geometry.IndicesBuffer = __WEBPACK_IMPORTED_MODULE_4__GeometryBase__["a" /* default */].IndicesBuffer;
  6065. Geometry.Attribute = Attribute;
  6066. /* harmony default export */ __webpack_exports__["a"] = (Geometry);
  6067. /***/
  6068. }),
  6069. /* 16 */
  6070. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  6071. "use strict";
  6072. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__core_Base__ = __webpack_require__(7);
  6073. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__camera_Orthographic__ = __webpack_require__(37);
  6074. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__geometry_Plane__ = __webpack_require__(43);
  6075. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__Shader__ = __webpack_require__(8);
  6076. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__Material__ = __webpack_require__(19);
  6077. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__Mesh__ = __webpack_require__(40);
  6078. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__core_glenum__ = __webpack_require__(11);
  6079. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__shader_source_compositor_vertex_glsl_js__ = __webpack_require__(126);
  6080. __WEBPACK_IMPORTED_MODULE_3__Shader__["a" /* default */]['import'](__WEBPACK_IMPORTED_MODULE_7__shader_source_compositor_vertex_glsl_js__["a" /* default */]);
  6081. var planeGeo = new __WEBPACK_IMPORTED_MODULE_2__geometry_Plane__["a" /* default */]();
  6082. var mesh = new __WEBPACK_IMPORTED_MODULE_5__Mesh__["a" /* default */]({
  6083. geometry: planeGeo,
  6084. frustumCulling: false
  6085. });
  6086. var camera = new __WEBPACK_IMPORTED_MODULE_1__camera_Orthographic__["a" /* default */]();
  6087. /**
  6088. * @constructor clay.compositor.Pass
  6089. * @extends clay.core.Base
  6090. */
  6091. var Pass = __WEBPACK_IMPORTED_MODULE_0__core_Base__["a" /* default */].extend(function () {
  6092. return /** @lends clay.compositor.Pass# */ {
  6093. /**
  6094. * Fragment shader string
  6095. * @type {string}
  6096. */
  6097. // PENDING shader or fragment ?
  6098. fragment: '',
  6099. /**
  6100. * @type {Object}
  6101. */
  6102. outputs: null,
  6103. /**
  6104. * @type {clay.Material}
  6105. */
  6106. material: null,
  6107. /**
  6108. * @type {Boolean}
  6109. */
  6110. blendWithPrevious: false,
  6111. /**
  6112. * @type {Boolean}
  6113. */
  6114. clearColor: false,
  6115. /**
  6116. * @type {Boolean}
  6117. */
  6118. clearDepth: true
  6119. };
  6120. }, function () {
  6121. var shader = new __WEBPACK_IMPORTED_MODULE_3__Shader__["a" /* default */](__WEBPACK_IMPORTED_MODULE_3__Shader__["a" /* default */].source('clay.compositor.vertex'), this.fragment);
  6122. var material = new __WEBPACK_IMPORTED_MODULE_4__Material__["a" /* default */]({
  6123. shader: shader
  6124. });
  6125. material.enableTexturesAll();
  6126. this.material = material;
  6127. },
  6128. /** @lends clay.compositor.Pass.prototype */
  6129. {
  6130. /**
  6131. * @param {string} name
  6132. * @param {} value
  6133. */
  6134. setUniform: function (name, value) {
  6135. this.material.setUniform(name, value);
  6136. },
  6137. /**
  6138. * @param {string} name
  6139. * @return {}
  6140. */
  6141. getUniform: function (name) {
  6142. var uniform = this.material.uniforms[name];
  6143. if (uniform) {
  6144. return uniform.value;
  6145. }
  6146. },
  6147. /**
  6148. * @param {clay.Texture} texture
  6149. * @param {number} attachment
  6150. */
  6151. attachOutput: function (texture, attachment) {
  6152. if (!this.outputs) {
  6153. this.outputs = {};
  6154. }
  6155. attachment = attachment || __WEBPACK_IMPORTED_MODULE_6__core_glenum__["a" /* default */].COLOR_ATTACHMENT0;
  6156. this.outputs[attachment] = texture;
  6157. },
  6158. /**
  6159. * @param {clay.Texture} texture
  6160. */
  6161. detachOutput: function (texture) {
  6162. for (var attachment in this.outputs) {
  6163. if (this.outputs[attachment] === texture) {
  6164. this.outputs[attachment] = null;
  6165. }
  6166. }
  6167. },
  6168. bind: function (renderer, frameBuffer) {
  6169. if (this.outputs) {
  6170. for (var attachment in this.outputs) {
  6171. var texture = this.outputs[attachment];
  6172. if (texture) {
  6173. frameBuffer.attach(texture, attachment);
  6174. }
  6175. }
  6176. }
  6177. if (frameBuffer) {
  6178. frameBuffer.bind(renderer);
  6179. }
  6180. },
  6181. unbind: function (renderer, frameBuffer) {
  6182. frameBuffer.unbind(renderer);
  6183. },
  6184. /**
  6185. * @param {clay.Renderer} renderer
  6186. * @param {clay.FrameBuffer} [frameBuffer]
  6187. */
  6188. render: function (renderer, frameBuffer) {
  6189. var _gl = renderer.gl;
  6190. if (frameBuffer) {
  6191. this.bind(renderer, frameBuffer);
  6192. // MRT Support in chrome
  6193. // https://www.khronos.org/registry/webgl/sdk/tests/conformance/extensions/ext-draw-buffers.html
  6194. var ext = renderer.getGLExtension('EXT_draw_buffers');
  6195. if (ext && this.outputs) {
  6196. var bufs = [];
  6197. for (var attachment in this.outputs) {
  6198. attachment = +attachment;
  6199. if (attachment >= _gl.COLOR_ATTACHMENT0 && attachment <= _gl.COLOR_ATTACHMENT0 + 8) {
  6200. bufs.push(attachment);
  6201. }
  6202. }
  6203. ext.drawBuffersEXT(bufs);
  6204. }
  6205. }
  6206. this.trigger('beforerender', this, renderer);
  6207. // FIXME Don't clear in each pass in default, let the color overwrite the buffer
  6208. // FIXME pixels may be discard
  6209. var clearBit = this.clearDepth ? _gl.DEPTH_BUFFER_BIT : 0;
  6210. _gl.depthMask(true);
  6211. if (this.clearColor) {
  6212. clearBit = clearBit | _gl.COLOR_BUFFER_BIT;
  6213. _gl.colorMask(true, true, true, true);
  6214. var cc = this.clearColor;
  6215. if (Array.isArray(cc)) {
  6216. _gl.clearColor(cc[0], cc[1], cc[2], cc[3]);
  6217. }
  6218. }
  6219. _gl.clear(clearBit);
  6220. if (this.blendWithPrevious) {
  6221. // Blend with previous rendered scene in the final output
  6222. // FIXME Configure blend.
  6223. // FIXME It will cause screen blink?
  6224. _gl.enable(_gl.BLEND);
  6225. this.material.transparent = true;
  6226. }
  6227. else {
  6228. _gl.disable(_gl.BLEND);
  6229. this.material.transparent = false;
  6230. }
  6231. this.renderQuad(renderer);
  6232. this.trigger('afterrender', this, renderer);
  6233. if (frameBuffer) {
  6234. this.unbind(renderer, frameBuffer);
  6235. }
  6236. },
  6237. /**
  6238. * Simply do quad rendering
  6239. */
  6240. renderQuad: function (renderer) {
  6241. mesh.material = this.material;
  6242. renderer.renderPass([mesh], camera);
  6243. },
  6244. /**
  6245. * @param {clay.Renderer} renderer
  6246. */
  6247. dispose: function (renderer) { }
  6248. });
  6249. /* harmony default export */ __webpack_exports__["a"] = (Pass);
  6250. /***/
  6251. }),
  6252. /* 17 */
  6253. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  6254. "use strict";
  6255. /* harmony default export */ __webpack_exports__["a"] = (function (seriesType, ecModel, api) {
  6256. return {
  6257. seriesType: seriesType,
  6258. reset: function (seriesModel, ecModel) {
  6259. var data = seriesModel.getData();
  6260. var opacityAccessPath = seriesModel.visualColorAccessPath.split('.');
  6261. opacityAccessPath[opacityAccessPath.length - 1] = 'opacity';
  6262. var opacity = seriesModel.get(opacityAccessPath);
  6263. data.setVisual('opacity', opacity == null ? 1 : opacity);
  6264. function dataEach(data, idx) {
  6265. var itemModel = data.getItemModel(idx);
  6266. var opacity = itemModel.get(opacityAccessPath, true);
  6267. if (opacity != null) {
  6268. data.setItemVisual(idx, 'opacity', opacity);
  6269. }
  6270. }
  6271. return {
  6272. dataEach: data.hasItemOption ? dataEach : null
  6273. };
  6274. }
  6275. };
  6276. });
  6277. /***/
  6278. }),
  6279. /* 18 */
  6280. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  6281. "use strict";
  6282. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Vector3__ = __webpack_require__(3);
  6283. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__ = __webpack_require__(12);
  6284. var vec3Set = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].set;
  6285. var vec3Copy = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].copy;
  6286. /**
  6287. * Axis aligned bounding box
  6288. * @constructor
  6289. * @alias clay.BoundingBox
  6290. * @param {clay.Vector3} [min]
  6291. * @param {clay.Vector3} [max]
  6292. */
  6293. var BoundingBox = function (min, max) {
  6294. /**
  6295. * Minimum coords of bounding box
  6296. * @type {clay.Vector3}
  6297. */
  6298. this.min = min || new __WEBPACK_IMPORTED_MODULE_0__Vector3__["a" /* default */](Infinity, Infinity, Infinity);
  6299. /**
  6300. * Maximum coords of bounding box
  6301. * @type {clay.Vector3}
  6302. */
  6303. this.max = max || new __WEBPACK_IMPORTED_MODULE_0__Vector3__["a" /* default */](-Infinity, -Infinity, -Infinity);
  6304. this.vertices = null;
  6305. };
  6306. BoundingBox.prototype = {
  6307. constructor: BoundingBox,
  6308. /**
  6309. * Update min and max coords from a vertices array
  6310. * @param {array} vertices
  6311. */
  6312. updateFromVertices: function (vertices) {
  6313. if (vertices.length > 0) {
  6314. var min = this.min;
  6315. var max = this.max;
  6316. var minArr = min.array;
  6317. var maxArr = max.array;
  6318. vec3Copy(minArr, vertices[0]);
  6319. vec3Copy(maxArr, vertices[0]);
  6320. for (var i = 1; i < vertices.length; i++) {
  6321. var vertex = vertices[i];
  6322. if (vertex[0] < minArr[0]) { minArr[0] = vertex[0]; }
  6323. if (vertex[1] < minArr[1]) { minArr[1] = vertex[1]; }
  6324. if (vertex[2] < minArr[2]) { minArr[2] = vertex[2]; }
  6325. if (vertex[0] > maxArr[0]) { maxArr[0] = vertex[0]; }
  6326. if (vertex[1] > maxArr[1]) { maxArr[1] = vertex[1]; }
  6327. if (vertex[2] > maxArr[2]) { maxArr[2] = vertex[2]; }
  6328. }
  6329. min._dirty = true;
  6330. max._dirty = true;
  6331. }
  6332. },
  6333. /**
  6334. * Union operation with another bounding box
  6335. * @param {clay.BoundingBox} bbox
  6336. */
  6337. union: function (bbox) {
  6338. var min = this.min;
  6339. var max = this.max;
  6340. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].min(min.array, min.array, bbox.min.array);
  6341. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].max(max.array, max.array, bbox.max.array);
  6342. min._dirty = true;
  6343. max._dirty = true;
  6344. return this;
  6345. },
  6346. /**
  6347. * Intersection operation with another bounding box
  6348. * @param {clay.BoundingBox} bbox
  6349. */
  6350. intersection: function (bbox) {
  6351. var min = this.min;
  6352. var max = this.max;
  6353. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].max(min.array, min.array, bbox.min.array);
  6354. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].min(max.array, max.array, bbox.max.array);
  6355. min._dirty = true;
  6356. max._dirty = true;
  6357. return this;
  6358. },
  6359. /**
  6360. * If intersect with another bounding box
  6361. * @param {clay.BoundingBox} bbox
  6362. * @return {boolean}
  6363. */
  6364. intersectBoundingBox: function (bbox) {
  6365. var _min = this.min.array;
  6366. var _max = this.max.array;
  6367. var _min2 = bbox.min.array;
  6368. var _max2 = bbox.max.array;
  6369. return !(_min[0] > _max2[0] || _min[1] > _max2[1] || _min[2] > _max2[2]
  6370. || _max[0] < _min2[0] || _max[1] < _min2[1] || _max[2] < _min2[2]);
  6371. },
  6372. /**
  6373. * If contain another bounding box entirely
  6374. * @param {clay.BoundingBox} bbox
  6375. * @return {boolean}
  6376. */
  6377. containBoundingBox: function (bbox) {
  6378. var _min = this.min.array;
  6379. var _max = this.max.array;
  6380. var _min2 = bbox.min.array;
  6381. var _max2 = bbox.max.array;
  6382. return _min[0] <= _min2[0] && _min[1] <= _min2[1] && _min[2] <= _min2[2]
  6383. && _max[0] >= _max2[0] && _max[1] >= _max2[1] && _max[2] >= _max2[2];
  6384. },
  6385. /**
  6386. * If contain point entirely
  6387. * @param {clay.Vector3} point
  6388. * @return {boolean}
  6389. */
  6390. containPoint: function (p) {
  6391. var _min = this.min.array;
  6392. var _max = this.max.array;
  6393. var _p = p.array;
  6394. return _min[0] <= _p[0] && _min[1] <= _p[1] && _min[2] <= _p[2]
  6395. && _max[0] >= _p[0] && _max[1] >= _p[1] && _max[2] >= _p[2];
  6396. },
  6397. /**
  6398. * If bounding box is finite
  6399. */
  6400. isFinite: function () {
  6401. var _min = this.min.array;
  6402. var _max = this.max.array;
  6403. return isFinite(_min[0]) && isFinite(_min[1]) && isFinite(_min[2])
  6404. && isFinite(_max[0]) && isFinite(_max[1]) && isFinite(_max[2]);
  6405. },
  6406. /**
  6407. * Apply an affine transform matrix to the bounding box
  6408. * @param {clay.Matrix4} matrix
  6409. */
  6410. applyTransform: function (matrix) {
  6411. this.transformFrom(this, matrix);
  6412. },
  6413. /**
  6414. * Get from another bounding box and an affine transform matrix.
  6415. * @param {clay.BoundingBox} source
  6416. * @param {clay.Matrix4} matrix
  6417. */
  6418. transformFrom: (function () {
  6419. // http://dev.theomader.com/transform-bounding-boxes/
  6420. var xa = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].create();
  6421. var xb = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].create();
  6422. var ya = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].create();
  6423. var yb = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].create();
  6424. var za = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].create();
  6425. var zb = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].create();
  6426. return function (source, matrix) {
  6427. var min = source.min.array;
  6428. var max = source.max.array;
  6429. var m = matrix.array;
  6430. xa[0] = m[0] * min[0]; xa[1] = m[1] * min[0]; xa[2] = m[2] * min[0];
  6431. xb[0] = m[0] * max[0]; xb[1] = m[1] * max[0]; xb[2] = m[2] * max[0];
  6432. ya[0] = m[4] * min[1]; ya[1] = m[5] * min[1]; ya[2] = m[6] * min[1];
  6433. yb[0] = m[4] * max[1]; yb[1] = m[5] * max[1]; yb[2] = m[6] * max[1];
  6434. za[0] = m[8] * min[2]; za[1] = m[9] * min[2]; za[2] = m[10] * min[2];
  6435. zb[0] = m[8] * max[2]; zb[1] = m[9] * max[2]; zb[2] = m[10] * max[2];
  6436. min = this.min.array;
  6437. max = this.max.array;
  6438. min[0] = Math.min(xa[0], xb[0]) + Math.min(ya[0], yb[0]) + Math.min(za[0], zb[0]) + m[12];
  6439. min[1] = Math.min(xa[1], xb[1]) + Math.min(ya[1], yb[1]) + Math.min(za[1], zb[1]) + m[13];
  6440. min[2] = Math.min(xa[2], xb[2]) + Math.min(ya[2], yb[2]) + Math.min(za[2], zb[2]) + m[14];
  6441. max[0] = Math.max(xa[0], xb[0]) + Math.max(ya[0], yb[0]) + Math.max(za[0], zb[0]) + m[12];
  6442. max[1] = Math.max(xa[1], xb[1]) + Math.max(ya[1], yb[1]) + Math.max(za[1], zb[1]) + m[13];
  6443. max[2] = Math.max(xa[2], xb[2]) + Math.max(ya[2], yb[2]) + Math.max(za[2], zb[2]) + m[14];
  6444. this.min._dirty = true;
  6445. this.max._dirty = true;
  6446. return this;
  6447. };
  6448. })(),
  6449. /**
  6450. * Apply a projection matrix to the bounding box
  6451. * @param {clay.Matrix4} matrix
  6452. */
  6453. applyProjection: function (matrix) {
  6454. var min = this.min.array;
  6455. var max = this.max.array;
  6456. var m = matrix.array;
  6457. // min in min z
  6458. var v10 = min[0];
  6459. var v11 = min[1];
  6460. var v12 = min[2];
  6461. // max in min z
  6462. var v20 = max[0];
  6463. var v21 = max[1];
  6464. var v22 = min[2];
  6465. // max in max z
  6466. var v30 = max[0];
  6467. var v31 = max[1];
  6468. var v32 = max[2];
  6469. if (m[15] === 1) { // Orthographic projection
  6470. min[0] = m[0] * v10 + m[12];
  6471. min[1] = m[5] * v11 + m[13];
  6472. max[2] = m[10] * v12 + m[14];
  6473. max[0] = m[0] * v30 + m[12];
  6474. max[1] = m[5] * v31 + m[13];
  6475. min[2] = m[10] * v32 + m[14];
  6476. }
  6477. else {
  6478. var w = -1 / v12;
  6479. min[0] = m[0] * v10 * w;
  6480. min[1] = m[5] * v11 * w;
  6481. max[2] = (m[10] * v12 + m[14]) * w;
  6482. w = -1 / v22;
  6483. max[0] = m[0] * v20 * w;
  6484. max[1] = m[5] * v21 * w;
  6485. w = -1 / v32;
  6486. min[2] = (m[10] * v32 + m[14]) * w;
  6487. }
  6488. this.min._dirty = true;
  6489. this.max._dirty = true;
  6490. return this;
  6491. },
  6492. updateVertices: function () {
  6493. var vertices = this.vertices;
  6494. if (!vertices) {
  6495. // Cube vertices
  6496. vertices = [];
  6497. for (var i = 0; i < 8; i++) {
  6498. vertices[i] = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].fromValues(0, 0, 0);
  6499. }
  6500. /**
  6501. * Eight coords of bounding box
  6502. * @type {Float32Array[]}
  6503. */
  6504. this.vertices = vertices;
  6505. }
  6506. var min = this.min.array;
  6507. var max = this.max.array;
  6508. //--- min z
  6509. // min x
  6510. vec3Set(vertices[0], min[0], min[1], min[2]);
  6511. vec3Set(vertices[1], min[0], max[1], min[2]);
  6512. // max x
  6513. vec3Set(vertices[2], max[0], min[1], min[2]);
  6514. vec3Set(vertices[3], max[0], max[1], min[2]);
  6515. //-- max z
  6516. vec3Set(vertices[4], min[0], min[1], max[2]);
  6517. vec3Set(vertices[5], min[0], max[1], max[2]);
  6518. vec3Set(vertices[6], max[0], min[1], max[2]);
  6519. vec3Set(vertices[7], max[0], max[1], max[2]);
  6520. return this;
  6521. },
  6522. /**
  6523. * Copy values from another bounding box
  6524. * @param {clay.BoundingBox} bbox
  6525. */
  6526. copy: function (bbox) {
  6527. var min = this.min;
  6528. var max = this.max;
  6529. vec3Copy(min.array, bbox.min.array);
  6530. vec3Copy(max.array, bbox.max.array);
  6531. min._dirty = true;
  6532. max._dirty = true;
  6533. return this;
  6534. },
  6535. /**
  6536. * Clone a new bounding box
  6537. * @return {clay.BoundingBox}
  6538. */
  6539. clone: function () {
  6540. var boundingBox = new BoundingBox();
  6541. boundingBox.copy(this);
  6542. return boundingBox;
  6543. }
  6544. };
  6545. /* harmony default export */ __webpack_exports__["a"] = (BoundingBox);
  6546. /***/
  6547. }),
  6548. /* 19 */
  6549. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  6550. "use strict";
  6551. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__core_Base__ = __webpack_require__(7);
  6552. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__core_util__ = __webpack_require__(23);
  6553. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__core_color__ = __webpack_require__(113);
  6554. var parseColor = __WEBPACK_IMPORTED_MODULE_2__core_color__["a" /* default */].parseToFloat;
  6555. var programKeyCache = {};
  6556. function getDefineCode(defines) {
  6557. var defineKeys = Object.keys(defines);
  6558. defineKeys.sort();
  6559. var defineStr = [];
  6560. // Custom Defines
  6561. for (var i = 0; i < defineKeys.length; i++) {
  6562. var key = defineKeys[i];
  6563. var value = defines[key];
  6564. if (value === null) {
  6565. defineStr.push(key);
  6566. }
  6567. else {
  6568. defineStr.push(key + ' ' + value.toString());
  6569. }
  6570. }
  6571. return defineStr.join('\n');
  6572. }
  6573. function getProgramKey(vertexDefines, fragmentDefines, enabledTextures) {
  6574. enabledTextures.sort();
  6575. var defineStr = [];
  6576. for (var i = 0; i < enabledTextures.length; i++) {
  6577. var symbol = enabledTextures[i];
  6578. defineStr.push(symbol);
  6579. }
  6580. var key = getDefineCode(vertexDefines) + '\n'
  6581. + getDefineCode(fragmentDefines) + '\n'
  6582. + defineStr.join('\n');
  6583. if (programKeyCache[key]) {
  6584. return programKeyCache[key];
  6585. }
  6586. var id = __WEBPACK_IMPORTED_MODULE_1__core_util__["a" /* default */].genGUID();
  6587. programKeyCache[key] = id;
  6588. return id;
  6589. }
  6590. /**
  6591. * Material defines the appearance of mesh surface, like `color`, `roughness`, `metalness`, etc.
  6592. * It contains a {@link clay.Shader} and corresponding uniforms.
  6593. *
  6594. * Here is a basic example to create a standard material
  6595. ```js
  6596. var material = new clay.Material({
  6597. shader: new clay.Shader(
  6598. clay.Shader.source('clay.vertex'),
  6599. clay.Shader.source('clay.fragment')
  6600. )
  6601. });
  6602. ```
  6603. * @constructor clay.Material
  6604. * @extends clay.core.Base
  6605. */
  6606. var Material = __WEBPACK_IMPORTED_MODULE_0__core_Base__["a" /* default */].extend(function () {
  6607. return /** @lends clay.Material# */ {
  6608. /**
  6609. * @type {string}
  6610. */
  6611. name: '',
  6612. /**
  6613. * @type {Object}
  6614. */
  6615. // uniforms: null,
  6616. /**
  6617. * @type {clay.Shader}
  6618. */
  6619. // shader: null,
  6620. /**
  6621. * @type {boolean}
  6622. */
  6623. depthTest: true,
  6624. /**
  6625. * @type {boolean}
  6626. */
  6627. depthMask: true,
  6628. /**
  6629. * @type {boolean}
  6630. */
  6631. transparent: false,
  6632. /**
  6633. * Blend func is a callback function when the material
  6634. * have custom blending
  6635. * The gl context will be the only argument passed in tho the
  6636. * blend function
  6637. * Detail of blend function in WebGL:
  6638. * http://www.khronos.org/registry/gles/specs/2.0/es_full_spec_2.0.25.pdf
  6639. *
  6640. * Example :
  6641. * function(_gl) {
  6642. * _gl.blendEquation(_gl.FUNC_ADD);
  6643. * _gl.blendFunc(_gl.SRC_ALPHA, _gl.ONE_MINUS_SRC_ALPHA);
  6644. * }
  6645. */
  6646. blend: null,
  6647. /**
  6648. * If update texture status automatically.
  6649. */
  6650. autoUpdateTextureStatus: true,
  6651. uniforms: {},
  6652. vertexDefines: {},
  6653. fragmentDefines: {},
  6654. _textureStatus: {},
  6655. // shadowTransparentMap : null
  6656. // PENDING enable the uniform that only used in shader.
  6657. _enabledUniforms: null,
  6658. };
  6659. }, function () {
  6660. if (!this.name) {
  6661. this.name = 'MATERIAL_' + this.__uid__;
  6662. }
  6663. if (this.shader) {
  6664. // Keep status, mainly preset uniforms, vertexDefines and fragmentDefines
  6665. this.attachShader(this.shader, true);
  6666. }
  6667. },
  6668. /** @lends clay.Material.prototype */
  6669. {
  6670. precision: 'highp',
  6671. /**
  6672. * Set material uniform
  6673. * @example
  6674. * mat.setUniform('color', [1, 1, 1, 1]);
  6675. * @param {string} symbol
  6676. * @param {number|array|clay.Texture|ArrayBufferView} value
  6677. */
  6678. setUniform: function (symbol, value) {
  6679. if (value === undefined) {
  6680. console.warn('Uniform value "' + symbol + '" is undefined');
  6681. }
  6682. var uniform = this.uniforms[symbol];
  6683. if (uniform) {
  6684. if (typeof value === 'string') {
  6685. // Try to parse as a color. Invalid color string will return null.
  6686. value = parseColor(value) || value;
  6687. }
  6688. uniform.value = value;
  6689. if (this.autoUpdateTextureStatus && uniform.type === 't') {
  6690. if (value) {
  6691. this.enableTexture(symbol);
  6692. }
  6693. else {
  6694. this.disableTexture(symbol);
  6695. }
  6696. }
  6697. }
  6698. },
  6699. /**
  6700. * @param {Object} obj
  6701. */
  6702. setUniforms: function (obj) {
  6703. for (var key in obj) {
  6704. var val = obj[key];
  6705. this.setUniform(key, val);
  6706. }
  6707. },
  6708. /**
  6709. * @param {string} symbol
  6710. * @return {boolean}
  6711. */
  6712. isUniformEnabled: function (symbol) {
  6713. return this._enabledUniforms.indexOf(symbol) >= 0;
  6714. },
  6715. getEnabledUniforms: function () {
  6716. return this._enabledUniforms;
  6717. },
  6718. getTextureUniforms: function () {
  6719. return this._textureUniforms;
  6720. },
  6721. /**
  6722. * Alias of setUniform and setUniforms
  6723. * @param {object|string} symbol
  6724. * @param {number|array|clay.Texture|ArrayBufferView} [value]
  6725. */
  6726. set: function (symbol, value) {
  6727. if (typeof (symbol) === 'object') {
  6728. for (var key in symbol) {
  6729. var val = symbol[key];
  6730. this.setUniform(key, val);
  6731. }
  6732. }
  6733. else {
  6734. this.setUniform(symbol, value);
  6735. }
  6736. },
  6737. /**
  6738. * Get uniform value
  6739. * @param {string} symbol
  6740. * @return {number|array|clay.Texture|ArrayBufferView}
  6741. */
  6742. get: function (symbol) {
  6743. var uniform = this.uniforms[symbol];
  6744. if (uniform) {
  6745. return uniform.value;
  6746. }
  6747. },
  6748. /**
  6749. * Attach a shader instance
  6750. * @param {clay.Shader} shader
  6751. * @param {boolean} keepStatus If try to keep uniform and texture
  6752. */
  6753. attachShader: function (shader, keepStatus) {
  6754. var originalUniforms = this.uniforms;
  6755. // Ignore if uniform can use in shader.
  6756. this.uniforms = shader.createUniforms();
  6757. this.shader = shader;
  6758. var uniforms = this.uniforms;
  6759. this._enabledUniforms = Object.keys(uniforms);
  6760. // Make sure uniforms are set in same order to avoid texture slot wrong
  6761. this._enabledUniforms.sort();
  6762. this._textureUniforms = this._enabledUniforms.filter(function (uniformName) {
  6763. var type = this.uniforms[uniformName].type;
  6764. return type === 't' || type === 'tv';
  6765. }, this);
  6766. var originalVertexDefines = this.vertexDefines;
  6767. var originalFragmentDefines = this.fragmentDefines;
  6768. this.vertexDefines = __WEBPACK_IMPORTED_MODULE_1__core_util__["a" /* default */].clone(shader.vertexDefines);
  6769. this.fragmentDefines = __WEBPACK_IMPORTED_MODULE_1__core_util__["a" /* default */].clone(shader.fragmentDefines);
  6770. if (keepStatus) {
  6771. for (var symbol in originalUniforms) {
  6772. if (uniforms[symbol]) {
  6773. uniforms[symbol].value = originalUniforms[symbol].value;
  6774. }
  6775. }
  6776. __WEBPACK_IMPORTED_MODULE_1__core_util__["a" /* default */].defaults(this.vertexDefines, originalVertexDefines);
  6777. __WEBPACK_IMPORTED_MODULE_1__core_util__["a" /* default */].defaults(this.fragmentDefines, originalFragmentDefines);
  6778. }
  6779. var textureStatus = {};
  6780. for (var key in shader.textures) {
  6781. textureStatus[key] = {
  6782. shaderType: shader.textures[key].shaderType,
  6783. type: shader.textures[key].type,
  6784. enabled: (keepStatus && this._textureStatus[key]) ? this._textureStatus[key].enabled : false
  6785. };
  6786. }
  6787. this._textureStatus = textureStatus;
  6788. this._programKey = '';
  6789. },
  6790. /**
  6791. * Clone a new material and keep uniforms, shader will not be cloned
  6792. * @return {clay.Material}
  6793. */
  6794. clone: function () {
  6795. var material = new this.constructor({
  6796. name: this.name,
  6797. shader: this.shader
  6798. });
  6799. for (var symbol in this.uniforms) {
  6800. material.uniforms[symbol].value = this.uniforms[symbol].value;
  6801. }
  6802. material.depthTest = this.depthTest;
  6803. material.depthMask = this.depthMask;
  6804. material.transparent = this.transparent;
  6805. material.blend = this.blend;
  6806. material.vertexDefines = __WEBPACK_IMPORTED_MODULE_1__core_util__["a" /* default */].clone(this.vertexDefines);
  6807. material.fragmentDefines = __WEBPACK_IMPORTED_MODULE_1__core_util__["a" /* default */].clone(this.fragmentDefines);
  6808. material.enableTexture(this.getEnabledTextures());
  6809. material.precision = this.precision;
  6810. return material;
  6811. },
  6812. /**
  6813. * Add a #define macro in shader code
  6814. * @param {string} shaderType Can be vertex, fragment or both
  6815. * @param {string} symbol
  6816. * @param {number} [val]
  6817. */
  6818. define: function (shaderType, symbol, val) {
  6819. var vertexDefines = this.vertexDefines;
  6820. var fragmentDefines = this.fragmentDefines;
  6821. if (shaderType !== 'vertex' && shaderType !== 'fragment' && shaderType !== 'both'
  6822. && arguments.length < 3
  6823. ) {
  6824. // shaderType default to be 'both'
  6825. val = symbol;
  6826. symbol = shaderType;
  6827. shaderType = 'both';
  6828. }
  6829. val = val != null ? val : null;
  6830. if (shaderType === 'vertex' || shaderType === 'both') {
  6831. if (vertexDefines[symbol] !== val) {
  6832. vertexDefines[symbol] = val;
  6833. // Mark as dirty
  6834. this._programKey = '';
  6835. }
  6836. }
  6837. if (shaderType === 'fragment' || shaderType === 'both') {
  6838. if (fragmentDefines[symbol] !== val) {
  6839. fragmentDefines[symbol] = val;
  6840. if (shaderType !== 'both') {
  6841. this._programKey = '';
  6842. }
  6843. }
  6844. }
  6845. },
  6846. /**
  6847. * Remove a #define macro in shader code
  6848. * @param {string} shaderType Can be vertex, fragment or both
  6849. * @param {string} symbol
  6850. */
  6851. undefine: function (shaderType, symbol) {
  6852. if (shaderType !== 'vertex' && shaderType !== 'fragment' && shaderType !== 'both'
  6853. && arguments.length < 2
  6854. ) {
  6855. // shaderType default to be 'both'
  6856. symbol = shaderType;
  6857. shaderType = 'both';
  6858. }
  6859. if (shaderType === 'vertex' || shaderType === 'both') {
  6860. if (this.isDefined('vertex', symbol)) {
  6861. delete this.vertexDefines[symbol];
  6862. // Mark as dirty
  6863. this._programKey = '';
  6864. }
  6865. }
  6866. if (shaderType === 'fragment' || shaderType === 'both') {
  6867. if (this.isDefined('fragment', symbol)) {
  6868. delete this.fragmentDefines[symbol];
  6869. if (shaderType !== 'both') {
  6870. this._programKey = '';
  6871. }
  6872. }
  6873. }
  6874. },
  6875. /**
  6876. * If macro is defined in shader.
  6877. * @param {string} shaderType Can be vertex, fragment or both
  6878. * @param {string} symbol
  6879. */
  6880. isDefined: function (shaderType, symbol) {
  6881. // PENDING hasOwnProperty ?
  6882. switch (shaderType) {
  6883. case 'vertex':
  6884. return this.vertexDefines[symbol] !== undefined;
  6885. case 'fragment':
  6886. return this.fragmentDefines[symbol] !== undefined;
  6887. }
  6888. },
  6889. /**
  6890. * Get macro value defined in shader.
  6891. * @param {string} shaderType Can be vertex, fragment or both
  6892. * @param {string} symbol
  6893. */
  6894. getDefine: function (shaderType, symbol) {
  6895. switch (shaderType) {
  6896. case 'vertex':
  6897. return this.vertexDefines[symbol];
  6898. case 'fragment':
  6899. return this.fragmentDefines[symbol];
  6900. }
  6901. },
  6902. /**
  6903. * Enable a texture, actually it will add a #define macro in the shader code
  6904. * For example, if texture symbol is diffuseMap, it will add a line `#define DIFFUSEMAP_ENABLED` in the shader code
  6905. * @param {string} symbol
  6906. */
  6907. enableTexture: function (symbol) {
  6908. if (Array.isArray(symbol)) {
  6909. for (var i = 0; i < symbol.length; i++) {
  6910. this.enableTexture(symbol[i]);
  6911. }
  6912. return;
  6913. }
  6914. var status = this._textureStatus[symbol];
  6915. if (status) {
  6916. var isEnabled = status.enabled;
  6917. if (!isEnabled) {
  6918. status.enabled = true;
  6919. this._programKey = '';
  6920. }
  6921. }
  6922. },
  6923. /**
  6924. * Enable all textures used in the shader
  6925. */
  6926. enableTexturesAll: function () {
  6927. var textureStatus = this._textureStatus;
  6928. for (var symbol in textureStatus) {
  6929. textureStatus[symbol].enabled = true;
  6930. }
  6931. this._programKey = '';
  6932. },
  6933. /**
  6934. * Disable a texture, it remove a #define macro in the shader
  6935. * @param {string} symbol
  6936. */
  6937. disableTexture: function (symbol) {
  6938. if (Array.isArray(symbol)) {
  6939. for (var i = 0; i < symbol.length; i++) {
  6940. this.disableTexture(symbol[i]);
  6941. }
  6942. return;
  6943. }
  6944. var status = this._textureStatus[symbol];
  6945. if (status) {
  6946. var isDisabled = !status.enabled;
  6947. if (!isDisabled) {
  6948. status.enabled = false;
  6949. this._programKey = '';
  6950. }
  6951. }
  6952. },
  6953. /**
  6954. * Disable all textures used in the shader
  6955. */
  6956. disableTexturesAll: function () {
  6957. var textureStatus = this._textureStatus;
  6958. for (var symbol in textureStatus) {
  6959. textureStatus[symbol].enabled = false;
  6960. }
  6961. this._programKey = '';
  6962. },
  6963. /**
  6964. * If texture of given type is enabled.
  6965. * @param {string} symbol
  6966. * @return {boolean}
  6967. */
  6968. isTextureEnabled: function (symbol) {
  6969. var textureStatus = this._textureStatus;
  6970. return !!textureStatus[symbol]
  6971. && textureStatus[symbol].enabled;
  6972. },
  6973. /**
  6974. * Get all enabled textures
  6975. * @return {string[]}
  6976. */
  6977. getEnabledTextures: function () {
  6978. var enabledTextures = [];
  6979. var textureStatus = this._textureStatus;
  6980. for (var symbol in textureStatus) {
  6981. if (textureStatus[symbol].enabled) {
  6982. enabledTextures.push(symbol);
  6983. }
  6984. }
  6985. return enabledTextures;
  6986. },
  6987. /**
  6988. * Mark defines are updated.
  6989. */
  6990. dirtyDefines: function () {
  6991. this._programKey = '';
  6992. },
  6993. getProgramKey: function () {
  6994. if (!this._programKey) {
  6995. this._programKey = getProgramKey(
  6996. this.vertexDefines, this.fragmentDefines, this.getEnabledTextures()
  6997. );
  6998. }
  6999. return this._programKey;
  7000. }
  7001. });
  7002. /* harmony default export */ __webpack_exports__["a"] = (Material);
  7003. /***/
  7004. }),
  7005. /* 20 */
  7006. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  7007. "use strict";
  7008. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function () { return GLMAT_EPSILON; });
  7009. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function () { return GLMAT_ARRAY_TYPE; });
  7010. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function () { return GLMAT_RANDOM; });
  7011. var GLMAT_EPSILON = 0.000001;
  7012. // Use Array instead of Float32Array. It seems to be much faster and higher precision.
  7013. var GLMAT_ARRAY_TYPE = Array;
  7014. // if(!GLMAT_ARRAY_TYPE) {
  7015. // GLMAT_ARRAY_TYPE = (typeof Float32Array !== 'undefined') ? Float32Array : Array;
  7016. // }
  7017. var GLMAT_RANDOM = Math.random;
  7018. /***/
  7019. }),
  7020. /* 21 */
  7021. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  7022. "use strict";
  7023. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__common__ = __webpack_require__(20);
  7024. /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
  7025. Redistribution and use in source and binary forms, with or without modification,
  7026. are permitted provided that the following conditions are met:
  7027. * Redistributions of source code must retain the above copyright notice, this
  7028. list of conditions and the following disclaimer.
  7029. * Redistributions in binary form must reproduce the above copyright notice,
  7030. this list of conditions and the following disclaimer in the documentation
  7031. and/or other materials provided with the distribution.
  7032. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  7033. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  7034. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  7035. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  7036. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7037. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7038. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  7039. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7040. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  7041. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
  7042. /**
  7043. * @class 4x4 Matrix
  7044. * @name mat4
  7045. */
  7046. var mat4 = {};
  7047. /**
  7048. * Creates a new identity mat4
  7049. *
  7050. * @returns {mat4} a new 4x4 matrix
  7051. */
  7052. mat4.create = function () {
  7053. var out = new __WEBPACK_IMPORTED_MODULE_0__common__["a" /* GLMAT_ARRAY_TYPE */](16);
  7054. out[0] = 1;
  7055. out[1] = 0;
  7056. out[2] = 0;
  7057. out[3] = 0;
  7058. out[4] = 0;
  7059. out[5] = 1;
  7060. out[6] = 0;
  7061. out[7] = 0;
  7062. out[8] = 0;
  7063. out[9] = 0;
  7064. out[10] = 1;
  7065. out[11] = 0;
  7066. out[12] = 0;
  7067. out[13] = 0;
  7068. out[14] = 0;
  7069. out[15] = 1;
  7070. return out;
  7071. };
  7072. /**
  7073. * Creates a new mat4 initialized with values from an existing matrix
  7074. *
  7075. * @param {mat4} a matrix to clone
  7076. * @returns {mat4} a new 4x4 matrix
  7077. */
  7078. mat4.clone = function (a) {
  7079. var out = new __WEBPACK_IMPORTED_MODULE_0__common__["a" /* GLMAT_ARRAY_TYPE */](16);
  7080. out[0] = a[0];
  7081. out[1] = a[1];
  7082. out[2] = a[2];
  7083. out[3] = a[3];
  7084. out[4] = a[4];
  7085. out[5] = a[5];
  7086. out[6] = a[6];
  7087. out[7] = a[7];
  7088. out[8] = a[8];
  7089. out[9] = a[9];
  7090. out[10] = a[10];
  7091. out[11] = a[11];
  7092. out[12] = a[12];
  7093. out[13] = a[13];
  7094. out[14] = a[14];
  7095. out[15] = a[15];
  7096. return out;
  7097. };
  7098. /**
  7099. * Copy the values from one mat4 to another
  7100. *
  7101. * @param {mat4} out the receiving matrix
  7102. * @param {mat4} a the source matrix
  7103. * @returns {mat4} out
  7104. */
  7105. mat4.copy = function (out, a) {
  7106. out[0] = a[0];
  7107. out[1] = a[1];
  7108. out[2] = a[2];
  7109. out[3] = a[3];
  7110. out[4] = a[4];
  7111. out[5] = a[5];
  7112. out[6] = a[6];
  7113. out[7] = a[7];
  7114. out[8] = a[8];
  7115. out[9] = a[9];
  7116. out[10] = a[10];
  7117. out[11] = a[11];
  7118. out[12] = a[12];
  7119. out[13] = a[13];
  7120. out[14] = a[14];
  7121. out[15] = a[15];
  7122. return out;
  7123. };
  7124. /**
  7125. * Set a mat4 to the identity matrix
  7126. *
  7127. * @param {mat4} out the receiving matrix
  7128. * @returns {mat4} out
  7129. */
  7130. mat4.identity = function (out) {
  7131. out[0] = 1;
  7132. out[1] = 0;
  7133. out[2] = 0;
  7134. out[3] = 0;
  7135. out[4] = 0;
  7136. out[5] = 1;
  7137. out[6] = 0;
  7138. out[7] = 0;
  7139. out[8] = 0;
  7140. out[9] = 0;
  7141. out[10] = 1;
  7142. out[11] = 0;
  7143. out[12] = 0;
  7144. out[13] = 0;
  7145. out[14] = 0;
  7146. out[15] = 1;
  7147. return out;
  7148. };
  7149. /**
  7150. * Transpose the values of a mat4
  7151. *
  7152. * @param {mat4} out the receiving matrix
  7153. * @param {mat4} a the source matrix
  7154. * @returns {mat4} out
  7155. */
  7156. mat4.transpose = function (out, a) {
  7157. // If we are transposing ourselves we can skip a few steps but have to cache some values
  7158. if (out === a) {
  7159. var a01 = a[1], a02 = a[2], a03 = a[3],
  7160. a12 = a[6], a13 = a[7],
  7161. a23 = a[11];
  7162. out[1] = a[4];
  7163. out[2] = a[8];
  7164. out[3] = a[12];
  7165. out[4] = a01;
  7166. out[6] = a[9];
  7167. out[7] = a[13];
  7168. out[8] = a02;
  7169. out[9] = a12;
  7170. out[11] = a[14];
  7171. out[12] = a03;
  7172. out[13] = a13;
  7173. out[14] = a23;
  7174. } else {
  7175. out[0] = a[0];
  7176. out[1] = a[4];
  7177. out[2] = a[8];
  7178. out[3] = a[12];
  7179. out[4] = a[1];
  7180. out[5] = a[5];
  7181. out[6] = a[9];
  7182. out[7] = a[13];
  7183. out[8] = a[2];
  7184. out[9] = a[6];
  7185. out[10] = a[10];
  7186. out[11] = a[14];
  7187. out[12] = a[3];
  7188. out[13] = a[7];
  7189. out[14] = a[11];
  7190. out[15] = a[15];
  7191. }
  7192. return out;
  7193. };
  7194. /**
  7195. * Inverts a mat4
  7196. *
  7197. * @param {mat4} out the receiving matrix
  7198. * @param {mat4} a the source matrix
  7199. * @returns {mat4} out
  7200. */
  7201. mat4.invert = function (out, a) {
  7202. var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
  7203. a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
  7204. a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
  7205. a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],
  7206. b00 = a00 * a11 - a01 * a10,
  7207. b01 = a00 * a12 - a02 * a10,
  7208. b02 = a00 * a13 - a03 * a10,
  7209. b03 = a01 * a12 - a02 * a11,
  7210. b04 = a01 * a13 - a03 * a11,
  7211. b05 = a02 * a13 - a03 * a12,
  7212. b06 = a20 * a31 - a21 * a30,
  7213. b07 = a20 * a32 - a22 * a30,
  7214. b08 = a20 * a33 - a23 * a30,
  7215. b09 = a21 * a32 - a22 * a31,
  7216. b10 = a21 * a33 - a23 * a31,
  7217. b11 = a22 * a33 - a23 * a32,
  7218. // Calculate the determinant
  7219. det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
  7220. if (!det) {
  7221. return null;
  7222. }
  7223. det = 1.0 / det;
  7224. out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
  7225. out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
  7226. out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
  7227. out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
  7228. out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
  7229. out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
  7230. out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
  7231. out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
  7232. out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
  7233. out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
  7234. out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
  7235. out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
  7236. out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
  7237. out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
  7238. out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
  7239. out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
  7240. return out;
  7241. };
  7242. /**
  7243. * Calculates the adjugate of a mat4
  7244. *
  7245. * @param {mat4} out the receiving matrix
  7246. * @param {mat4} a the source matrix
  7247. * @returns {mat4} out
  7248. */
  7249. mat4.adjoint = function (out, a) {
  7250. var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
  7251. a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
  7252. a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
  7253. a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
  7254. out[0] = (a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22));
  7255. out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22));
  7256. out[2] = (a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12));
  7257. out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12));
  7258. out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22));
  7259. out[5] = (a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22));
  7260. out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12));
  7261. out[7] = (a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12));
  7262. out[8] = (a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21));
  7263. out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21));
  7264. out[10] = (a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11));
  7265. out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11));
  7266. out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21));
  7267. out[13] = (a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21));
  7268. out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11));
  7269. out[15] = (a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11));
  7270. return out;
  7271. };
  7272. /**
  7273. * Calculates the determinant of a mat4
  7274. *
  7275. * @param {mat4} a the source matrix
  7276. * @returns {Number} determinant of a
  7277. */
  7278. mat4.determinant = function (a) {
  7279. var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
  7280. a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
  7281. a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
  7282. a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],
  7283. b00 = a00 * a11 - a01 * a10,
  7284. b01 = a00 * a12 - a02 * a10,
  7285. b02 = a00 * a13 - a03 * a10,
  7286. b03 = a01 * a12 - a02 * a11,
  7287. b04 = a01 * a13 - a03 * a11,
  7288. b05 = a02 * a13 - a03 * a12,
  7289. b06 = a20 * a31 - a21 * a30,
  7290. b07 = a20 * a32 - a22 * a30,
  7291. b08 = a20 * a33 - a23 * a30,
  7292. b09 = a21 * a32 - a22 * a31,
  7293. b10 = a21 * a33 - a23 * a31,
  7294. b11 = a22 * a33 - a23 * a32;
  7295. // Calculate the determinant
  7296. return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
  7297. };
  7298. /**
  7299. * Multiplies two mat4's
  7300. *
  7301. * @param {mat4} out the receiving matrix
  7302. * @param {mat4} a the first operand
  7303. * @param {mat4} b the second operand
  7304. * @returns {mat4} out
  7305. */
  7306. mat4.multiply = function (out, a, b) {
  7307. var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
  7308. a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
  7309. a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
  7310. a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
  7311. // Cache only the current line of the second matrix
  7312. var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
  7313. out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
  7314. out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
  7315. out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
  7316. out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
  7317. b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7];
  7318. out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
  7319. out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
  7320. out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
  7321. out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
  7322. b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11];
  7323. out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
  7324. out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
  7325. out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
  7326. out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
  7327. b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15];
  7328. out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
  7329. out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
  7330. out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
  7331. out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
  7332. return out;
  7333. };
  7334. /**
  7335. * Multiplies two affine mat4's
  7336. * Add by https://github.com/pissang
  7337. * @param {mat4} out the receiving matrix
  7338. * @param {mat4} a the first operand
  7339. * @param {mat4} b the second operand
  7340. * @returns {mat4} out
  7341. */
  7342. mat4.multiplyAffine = function (out, a, b) {
  7343. var a00 = a[0], a01 = a[1], a02 = a[2],
  7344. a10 = a[4], a11 = a[5], a12 = a[6],
  7345. a20 = a[8], a21 = a[9], a22 = a[10],
  7346. a30 = a[12], a31 = a[13], a32 = a[14];
  7347. // Cache only the current line of the second matrix
  7348. var b0 = b[0], b1 = b[1], b2 = b[2];
  7349. out[0] = b0 * a00 + b1 * a10 + b2 * a20;
  7350. out[1] = b0 * a01 + b1 * a11 + b2 * a21;
  7351. out[2] = b0 * a02 + b1 * a12 + b2 * a22;
  7352. // out[3] = 0;
  7353. b0 = b[4]; b1 = b[5]; b2 = b[6];
  7354. out[4] = b0 * a00 + b1 * a10 + b2 * a20;
  7355. out[5] = b0 * a01 + b1 * a11 + b2 * a21;
  7356. out[6] = b0 * a02 + b1 * a12 + b2 * a22;
  7357. // out[7] = 0;
  7358. b0 = b[8]; b1 = b[9]; b2 = b[10];
  7359. out[8] = b0 * a00 + b1 * a10 + b2 * a20;
  7360. out[9] = b0 * a01 + b1 * a11 + b2 * a21;
  7361. out[10] = b0 * a02 + b1 * a12 + b2 * a22;
  7362. // out[11] = 0;
  7363. b0 = b[12]; b1 = b[13]; b2 = b[14];
  7364. out[12] = b0 * a00 + b1 * a10 + b2 * a20 + a30;
  7365. out[13] = b0 * a01 + b1 * a11 + b2 * a21 + a31;
  7366. out[14] = b0 * a02 + b1 * a12 + b2 * a22 + a32;
  7367. // out[15] = 1;
  7368. return out;
  7369. };
  7370. /**
  7371. * Alias for {@link mat4.multiply}
  7372. * @function
  7373. */
  7374. mat4.mul = mat4.multiply;
  7375. /**
  7376. * Alias for {@link mat4.multiplyAffine}
  7377. * @function
  7378. */
  7379. mat4.mulAffine = mat4.multiplyAffine;
  7380. /**
  7381. * Translate a mat4 by the given vector
  7382. *
  7383. * @param {mat4} out the receiving matrix
  7384. * @param {mat4} a the matrix to translate
  7385. * @param {vec3} v vector to translate by
  7386. * @returns {mat4} out
  7387. */
  7388. mat4.translate = function (out, a, v) {
  7389. var x = v[0], y = v[1], z = v[2],
  7390. a00, a01, a02, a03,
  7391. a10, a11, a12, a13,
  7392. a20, a21, a22, a23;
  7393. if (a === out) {
  7394. out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
  7395. out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
  7396. out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
  7397. out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
  7398. } else {
  7399. a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3];
  7400. a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7];
  7401. a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11];
  7402. out[0] = a00; out[1] = a01; out[2] = a02; out[3] = a03;
  7403. out[4] = a10; out[5] = a11; out[6] = a12; out[7] = a13;
  7404. out[8] = a20; out[9] = a21; out[10] = a22; out[11] = a23;
  7405. out[12] = a00 * x + a10 * y + a20 * z + a[12];
  7406. out[13] = a01 * x + a11 * y + a21 * z + a[13];
  7407. out[14] = a02 * x + a12 * y + a22 * z + a[14];
  7408. out[15] = a03 * x + a13 * y + a23 * z + a[15];
  7409. }
  7410. return out;
  7411. };
  7412. /**
  7413. * Scales the mat4 by the dimensions in the given vec3
  7414. *
  7415. * @param {mat4} out the receiving matrix
  7416. * @param {mat4} a the matrix to scale
  7417. * @param {vec3} v the vec3 to scale the matrix by
  7418. * @returns {mat4} out
  7419. **/
  7420. mat4.scale = function (out, a, v) {
  7421. var x = v[0], y = v[1], z = v[2];
  7422. out[0] = a[0] * x;
  7423. out[1] = a[1] * x;
  7424. out[2] = a[2] * x;
  7425. out[3] = a[3] * x;
  7426. out[4] = a[4] * y;
  7427. out[5] = a[5] * y;
  7428. out[6] = a[6] * y;
  7429. out[7] = a[7] * y;
  7430. out[8] = a[8] * z;
  7431. out[9] = a[9] * z;
  7432. out[10] = a[10] * z;
  7433. out[11] = a[11] * z;
  7434. out[12] = a[12];
  7435. out[13] = a[13];
  7436. out[14] = a[14];
  7437. out[15] = a[15];
  7438. return out;
  7439. };
  7440. /**
  7441. * Rotates a mat4 by the given angle
  7442. *
  7443. * @param {mat4} out the receiving matrix
  7444. * @param {mat4} a the matrix to rotate
  7445. * @param {Number} rad the angle to rotate the matrix by
  7446. * @param {vec3} axis the axis to rotate around
  7447. * @returns {mat4} out
  7448. */
  7449. mat4.rotate = function (out, a, rad, axis) {
  7450. var x = axis[0], y = axis[1], z = axis[2],
  7451. len = Math.sqrt(x * x + y * y + z * z),
  7452. s, c, t,
  7453. a00, a01, a02, a03,
  7454. a10, a11, a12, a13,
  7455. a20, a21, a22, a23,
  7456. b00, b01, b02,
  7457. b10, b11, b12,
  7458. b20, b21, b22;
  7459. if (Math.abs(len) < __WEBPACK_IMPORTED_MODULE_0__common__["b" /* GLMAT_EPSILON */]) { return null; }
  7460. len = 1 / len;
  7461. x *= len;
  7462. y *= len;
  7463. z *= len;
  7464. s = Math.sin(rad);
  7465. c = Math.cos(rad);
  7466. t = 1 - c;
  7467. a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3];
  7468. a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7];
  7469. a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11];
  7470. // Construct the elements of the rotation matrix
  7471. b00 = x * x * t + c; b01 = y * x * t + z * s; b02 = z * x * t - y * s;
  7472. b10 = x * y * t - z * s; b11 = y * y * t + c; b12 = z * y * t + x * s;
  7473. b20 = x * z * t + y * s; b21 = y * z * t - x * s; b22 = z * z * t + c;
  7474. // Perform rotation-specific matrix multiplication
  7475. out[0] = a00 * b00 + a10 * b01 + a20 * b02;
  7476. out[1] = a01 * b00 + a11 * b01 + a21 * b02;
  7477. out[2] = a02 * b00 + a12 * b01 + a22 * b02;
  7478. out[3] = a03 * b00 + a13 * b01 + a23 * b02;
  7479. out[4] = a00 * b10 + a10 * b11 + a20 * b12;
  7480. out[5] = a01 * b10 + a11 * b11 + a21 * b12;
  7481. out[6] = a02 * b10 + a12 * b11 + a22 * b12;
  7482. out[7] = a03 * b10 + a13 * b11 + a23 * b12;
  7483. out[8] = a00 * b20 + a10 * b21 + a20 * b22;
  7484. out[9] = a01 * b20 + a11 * b21 + a21 * b22;
  7485. out[10] = a02 * b20 + a12 * b21 + a22 * b22;
  7486. out[11] = a03 * b20 + a13 * b21 + a23 * b22;
  7487. if (a !== out) { // If the source and destination differ, copy the unchanged last row
  7488. out[12] = a[12];
  7489. out[13] = a[13];
  7490. out[14] = a[14];
  7491. out[15] = a[15];
  7492. }
  7493. return out;
  7494. };
  7495. /**
  7496. * Rotates a matrix by the given angle around the X axis
  7497. *
  7498. * @param {mat4} out the receiving matrix
  7499. * @param {mat4} a the matrix to rotate
  7500. * @param {Number} rad the angle to rotate the matrix by
  7501. * @returns {mat4} out
  7502. */
  7503. mat4.rotateX = function (out, a, rad) {
  7504. var s = Math.sin(rad),
  7505. c = Math.cos(rad),
  7506. a10 = a[4],
  7507. a11 = a[5],
  7508. a12 = a[6],
  7509. a13 = a[7],
  7510. a20 = a[8],
  7511. a21 = a[9],
  7512. a22 = a[10],
  7513. a23 = a[11];
  7514. if (a !== out) { // If the source and destination differ, copy the unchanged rows
  7515. out[0] = a[0];
  7516. out[1] = a[1];
  7517. out[2] = a[2];
  7518. out[3] = a[3];
  7519. out[12] = a[12];
  7520. out[13] = a[13];
  7521. out[14] = a[14];
  7522. out[15] = a[15];
  7523. }
  7524. // Perform axis-specific matrix multiplication
  7525. out[4] = a10 * c + a20 * s;
  7526. out[5] = a11 * c + a21 * s;
  7527. out[6] = a12 * c + a22 * s;
  7528. out[7] = a13 * c + a23 * s;
  7529. out[8] = a20 * c - a10 * s;
  7530. out[9] = a21 * c - a11 * s;
  7531. out[10] = a22 * c - a12 * s;
  7532. out[11] = a23 * c - a13 * s;
  7533. return out;
  7534. };
  7535. /**
  7536. * Rotates a matrix by the given angle around the Y axis
  7537. *
  7538. * @param {mat4} out the receiving matrix
  7539. * @param {mat4} a the matrix to rotate
  7540. * @param {Number} rad the angle to rotate the matrix by
  7541. * @returns {mat4} out
  7542. */
  7543. mat4.rotateY = function (out, a, rad) {
  7544. var s = Math.sin(rad),
  7545. c = Math.cos(rad),
  7546. a00 = a[0],
  7547. a01 = a[1],
  7548. a02 = a[2],
  7549. a03 = a[3],
  7550. a20 = a[8],
  7551. a21 = a[9],
  7552. a22 = a[10],
  7553. a23 = a[11];
  7554. if (a !== out) { // If the source and destination differ, copy the unchanged rows
  7555. out[4] = a[4];
  7556. out[5] = a[5];
  7557. out[6] = a[6];
  7558. out[7] = a[7];
  7559. out[12] = a[12];
  7560. out[13] = a[13];
  7561. out[14] = a[14];
  7562. out[15] = a[15];
  7563. }
  7564. // Perform axis-specific matrix multiplication
  7565. out[0] = a00 * c - a20 * s;
  7566. out[1] = a01 * c - a21 * s;
  7567. out[2] = a02 * c - a22 * s;
  7568. out[3] = a03 * c - a23 * s;
  7569. out[8] = a00 * s + a20 * c;
  7570. out[9] = a01 * s + a21 * c;
  7571. out[10] = a02 * s + a22 * c;
  7572. out[11] = a03 * s + a23 * c;
  7573. return out;
  7574. };
  7575. /**
  7576. * Rotates a matrix by the given angle around the Z axis
  7577. *
  7578. * @param {mat4} out the receiving matrix
  7579. * @param {mat4} a the matrix to rotate
  7580. * @param {Number} rad the angle to rotate the matrix by
  7581. * @returns {mat4} out
  7582. */
  7583. mat4.rotateZ = function (out, a, rad) {
  7584. var s = Math.sin(rad),
  7585. c = Math.cos(rad),
  7586. a00 = a[0],
  7587. a01 = a[1],
  7588. a02 = a[2],
  7589. a03 = a[3],
  7590. a10 = a[4],
  7591. a11 = a[5],
  7592. a12 = a[6],
  7593. a13 = a[7];
  7594. if (a !== out) { // If the source and destination differ, copy the unchanged last row
  7595. out[8] = a[8];
  7596. out[9] = a[9];
  7597. out[10] = a[10];
  7598. out[11] = a[11];
  7599. out[12] = a[12];
  7600. out[13] = a[13];
  7601. out[14] = a[14];
  7602. out[15] = a[15];
  7603. }
  7604. // Perform axis-specific matrix multiplication
  7605. out[0] = a00 * c + a10 * s;
  7606. out[1] = a01 * c + a11 * s;
  7607. out[2] = a02 * c + a12 * s;
  7608. out[3] = a03 * c + a13 * s;
  7609. out[4] = a10 * c - a00 * s;
  7610. out[5] = a11 * c - a01 * s;
  7611. out[6] = a12 * c - a02 * s;
  7612. out[7] = a13 * c - a03 * s;
  7613. return out;
  7614. };
  7615. /**
  7616. * Creates a matrix from a quaternion rotation and vector translation
  7617. * This is equivalent to (but much faster than):
  7618. *
  7619. * mat4.identity(dest);
  7620. * mat4.translate(dest, vec);
  7621. * var quatMat = mat4.create();
  7622. * quat4.toMat4(quat, quatMat);
  7623. * mat4.multiply(dest, quatMat);
  7624. *
  7625. * @param {mat4} out mat4 receiving operation result
  7626. * @param {quat4} q Rotation quaternion
  7627. * @param {vec3} v Translation vector
  7628. * @returns {mat4} out
  7629. */
  7630. mat4.fromRotationTranslation = function (out, q, v) {
  7631. // Quaternion math
  7632. var x = q[0], y = q[1], z = q[2], w = q[3],
  7633. x2 = x + x,
  7634. y2 = y + y,
  7635. z2 = z + z,
  7636. xx = x * x2,
  7637. xy = x * y2,
  7638. xz = x * z2,
  7639. yy = y * y2,
  7640. yz = y * z2,
  7641. zz = z * z2,
  7642. wx = w * x2,
  7643. wy = w * y2,
  7644. wz = w * z2;
  7645. out[0] = 1 - (yy + zz);
  7646. out[1] = xy + wz;
  7647. out[2] = xz - wy;
  7648. out[3] = 0;
  7649. out[4] = xy - wz;
  7650. out[5] = 1 - (xx + zz);
  7651. out[6] = yz + wx;
  7652. out[7] = 0;
  7653. out[8] = xz + wy;
  7654. out[9] = yz - wx;
  7655. out[10] = 1 - (xx + yy);
  7656. out[11] = 0;
  7657. out[12] = v[0];
  7658. out[13] = v[1];
  7659. out[14] = v[2];
  7660. out[15] = 1;
  7661. return out;
  7662. };
  7663. mat4.fromQuat = function (out, q) {
  7664. var x = q[0], y = q[1], z = q[2], w = q[3],
  7665. x2 = x + x,
  7666. y2 = y + y,
  7667. z2 = z + z,
  7668. xx = x * x2,
  7669. yx = y * x2,
  7670. yy = y * y2,
  7671. zx = z * x2,
  7672. zy = z * y2,
  7673. zz = z * z2,
  7674. wx = w * x2,
  7675. wy = w * y2,
  7676. wz = w * z2;
  7677. out[0] = 1 - yy - zz;
  7678. out[1] = yx + wz;
  7679. out[2] = zx - wy;
  7680. out[3] = 0;
  7681. out[4] = yx - wz;
  7682. out[5] = 1 - xx - zz;
  7683. out[6] = zy + wx;
  7684. out[7] = 0;
  7685. out[8] = zx + wy;
  7686. out[9] = zy - wx;
  7687. out[10] = 1 - xx - yy;
  7688. out[11] = 0;
  7689. out[12] = 0;
  7690. out[13] = 0;
  7691. out[14] = 0;
  7692. out[15] = 1;
  7693. return out;
  7694. };
  7695. /**
  7696. * Generates a frustum matrix with the given bounds
  7697. *
  7698. * @param {mat4} out mat4 frustum matrix will be written into
  7699. * @param {Number} left Left bound of the frustum
  7700. * @param {Number} right Right bound of the frustum
  7701. * @param {Number} bottom Bottom bound of the frustum
  7702. * @param {Number} top Top bound of the frustum
  7703. * @param {Number} near Near bound of the frustum
  7704. * @param {Number} far Far bound of the frustum
  7705. * @returns {mat4} out
  7706. */
  7707. mat4.frustum = function (out, left, right, bottom, top, near, far) {
  7708. var rl = 1 / (right - left),
  7709. tb = 1 / (top - bottom),
  7710. nf = 1 / (near - far);
  7711. out[0] = (near * 2) * rl;
  7712. out[1] = 0;
  7713. out[2] = 0;
  7714. out[3] = 0;
  7715. out[4] = 0;
  7716. out[5] = (near * 2) * tb;
  7717. out[6] = 0;
  7718. out[7] = 0;
  7719. out[8] = (right + left) * rl;
  7720. out[9] = (top + bottom) * tb;
  7721. out[10] = (far + near) * nf;
  7722. out[11] = -1;
  7723. out[12] = 0;
  7724. out[13] = 0;
  7725. out[14] = (far * near * 2) * nf;
  7726. out[15] = 0;
  7727. return out;
  7728. };
  7729. /**
  7730. * Generates a perspective projection matrix with the given bounds
  7731. *
  7732. * @param {mat4} out mat4 frustum matrix will be written into
  7733. * @param {number} fovy Vertical field of view in radians
  7734. * @param {number} aspect Aspect ratio. typically viewport width/height
  7735. * @param {number} near Near bound of the frustum
  7736. * @param {number} far Far bound of the frustum
  7737. * @returns {mat4} out
  7738. */
  7739. mat4.perspective = function (out, fovy, aspect, near, far) {
  7740. var f = 1.0 / Math.tan(fovy / 2),
  7741. nf = 1 / (near - far);
  7742. out[0] = f / aspect;
  7743. out[1] = 0;
  7744. out[2] = 0;
  7745. out[3] = 0;
  7746. out[4] = 0;
  7747. out[5] = f;
  7748. out[6] = 0;
  7749. out[7] = 0;
  7750. out[8] = 0;
  7751. out[9] = 0;
  7752. out[10] = (far + near) * nf;
  7753. out[11] = -1;
  7754. out[12] = 0;
  7755. out[13] = 0;
  7756. out[14] = (2 * far * near) * nf;
  7757. out[15] = 0;
  7758. return out;
  7759. };
  7760. /**
  7761. * Generates a orthogonal projection matrix with the given bounds
  7762. *
  7763. * @param {mat4} out mat4 frustum matrix will be written into
  7764. * @param {number} left Left bound of the frustum
  7765. * @param {number} right Right bound of the frustum
  7766. * @param {number} bottom Bottom bound of the frustum
  7767. * @param {number} top Top bound of the frustum
  7768. * @param {number} near Near bound of the frustum
  7769. * @param {number} far Far bound of the frustum
  7770. * @returns {mat4} out
  7771. */
  7772. mat4.ortho = function (out, left, right, bottom, top, near, far) {
  7773. var lr = 1 / (left - right),
  7774. bt = 1 / (bottom - top),
  7775. nf = 1 / (near - far);
  7776. out[0] = -2 * lr;
  7777. out[1] = 0;
  7778. out[2] = 0;
  7779. out[3] = 0;
  7780. out[4] = 0;
  7781. out[5] = -2 * bt;
  7782. out[6] = 0;
  7783. out[7] = 0;
  7784. out[8] = 0;
  7785. out[9] = 0;
  7786. out[10] = 2 * nf;
  7787. out[11] = 0;
  7788. out[12] = (left + right) * lr;
  7789. out[13] = (top + bottom) * bt;
  7790. out[14] = (far + near) * nf;
  7791. out[15] = 1;
  7792. return out;
  7793. };
  7794. /**
  7795. * Generates a look-at matrix with the given eye position, focal point, and up axis
  7796. *
  7797. * @param {mat4} out mat4 frustum matrix will be written into
  7798. * @param {vec3} eye Position of the viewer
  7799. * @param {vec3} center Point the viewer is looking at
  7800. * @param {vec3} up vec3 pointing up
  7801. * @returns {mat4} out
  7802. */
  7803. mat4.lookAt = function (out, eye, center, up) {
  7804. var x0, x1, x2, y0, y1, y2, z0, z1, z2, len,
  7805. eyex = eye[0],
  7806. eyey = eye[1],
  7807. eyez = eye[2],
  7808. upx = up[0],
  7809. upy = up[1],
  7810. upz = up[2],
  7811. centerx = center[0],
  7812. centery = center[1],
  7813. centerz = center[2];
  7814. if (Math.abs(eyex - centerx) < __WEBPACK_IMPORTED_MODULE_0__common__["b" /* GLMAT_EPSILON */] &&
  7815. Math.abs(eyey - centery) < __WEBPACK_IMPORTED_MODULE_0__common__["b" /* GLMAT_EPSILON */] &&
  7816. Math.abs(eyez - centerz) < __WEBPACK_IMPORTED_MODULE_0__common__["b" /* GLMAT_EPSILON */]) {
  7817. return mat4.identity(out);
  7818. }
  7819. z0 = eyex - centerx;
  7820. z1 = eyey - centery;
  7821. z2 = eyez - centerz;
  7822. len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);
  7823. z0 *= len;
  7824. z1 *= len;
  7825. z2 *= len;
  7826. x0 = upy * z2 - upz * z1;
  7827. x1 = upz * z0 - upx * z2;
  7828. x2 = upx * z1 - upy * z0;
  7829. len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);
  7830. if (!len) {
  7831. x0 = 0;
  7832. x1 = 0;
  7833. x2 = 0;
  7834. } else {
  7835. len = 1 / len;
  7836. x0 *= len;
  7837. x1 *= len;
  7838. x2 *= len;
  7839. }
  7840. y0 = z1 * x2 - z2 * x1;
  7841. y1 = z2 * x0 - z0 * x2;
  7842. y2 = z0 * x1 - z1 * x0;
  7843. len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);
  7844. if (!len) {
  7845. y0 = 0;
  7846. y1 = 0;
  7847. y2 = 0;
  7848. } else {
  7849. len = 1 / len;
  7850. y0 *= len;
  7851. y1 *= len;
  7852. y2 *= len;
  7853. }
  7854. out[0] = x0;
  7855. out[1] = y0;
  7856. out[2] = z0;
  7857. out[3] = 0;
  7858. out[4] = x1;
  7859. out[5] = y1;
  7860. out[6] = z1;
  7861. out[7] = 0;
  7862. out[8] = x2;
  7863. out[9] = y2;
  7864. out[10] = z2;
  7865. out[11] = 0;
  7866. out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);
  7867. out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);
  7868. out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);
  7869. out[15] = 1;
  7870. return out;
  7871. };
  7872. /**
  7873. * Returns Frobenius norm of a mat4
  7874. *
  7875. * @param {mat4} a the matrix to calculate Frobenius norm of
  7876. * @returns {Number} Frobenius norm
  7877. */
  7878. mat4.frob = function (a) {
  7879. return (Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2) + Math.pow(a[9], 2) + Math.pow(a[10], 2) + Math.pow(a[11], 2) + Math.pow(a[12], 2) + Math.pow(a[13], 2) + Math.pow(a[14], 2) + Math.pow(a[15], 2)))
  7880. };
  7881. /* harmony default export */ __webpack_exports__["a"] = (mat4);
  7882. /***/
  7883. }),
  7884. /* 22 */
  7885. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  7886. "use strict";
  7887. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  7888. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  7889. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_Scene__ = __webpack_require__(36);
  7890. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_claygl_src_prePass_ShadowMap__ = __webpack_require__(174);
  7891. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_claygl_src_camera_Perspective__ = __webpack_require__(41);
  7892. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_claygl_src_camera_Orthographic__ = __webpack_require__(37);
  7893. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_claygl_src_math_Matrix4__ = __webpack_require__(9);
  7894. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_claygl_src_math_Vector3__ = __webpack_require__(3);
  7895. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7_claygl_src_math_Vector2__ = __webpack_require__(26);
  7896. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8_claygl_src_core_mixin_notifier__ = __webpack_require__(53);
  7897. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_9__effect_EffectCompositor__ = __webpack_require__(176);
  7898. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_10__effect_TemporalSuperSampling__ = __webpack_require__(200);
  7899. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_11__effect_halton__ = __webpack_require__(49);
  7900. /*
  7901. * @module echarts-gl/core/ViewGL
  7902. * @author Yi Shen(http://github.com/pissang)
  7903. */
  7904. /**
  7905. * @constructor
  7906. * @alias module:echarts-gl/core/ViewGL
  7907. * @param {string} [projection='perspective']
  7908. */
  7909. function ViewGL(projection) {
  7910. projection = projection || 'perspective';
  7911. /**
  7912. * @type {module:echarts-gl/core/LayerGL}
  7913. */
  7914. this.layer = null;
  7915. /**
  7916. * @type {clay.Scene}
  7917. */
  7918. this.scene = new __WEBPACK_IMPORTED_MODULE_1_claygl_src_Scene__["a" /* default */]();
  7919. /**
  7920. * @type {clay.Node}
  7921. */
  7922. this.rootNode = this.scene;
  7923. this.viewport = {
  7924. x: 0, y: 0, width: 0, height: 0
  7925. };
  7926. this.setProjection(projection);
  7927. this._compositor = new __WEBPACK_IMPORTED_MODULE_9__effect_EffectCompositor__["a" /* default */]();
  7928. this._temporalSS = new __WEBPACK_IMPORTED_MODULE_10__effect_TemporalSuperSampling__["a" /* default */]();
  7929. this._shadowMapPass = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_prePass_ShadowMap__["a" /* default */]();
  7930. var pcfKernels = [];
  7931. var off = 0;
  7932. for (var i = 0; i < 30; i++) {
  7933. var pcfKernel = [];
  7934. for (var k = 0; k < 6; k++) {
  7935. pcfKernel.push(Object(__WEBPACK_IMPORTED_MODULE_11__effect_halton__["a" /* default */])(off, 2) * 4.0 - 2.0);
  7936. pcfKernel.push(Object(__WEBPACK_IMPORTED_MODULE_11__effect_halton__["a" /* default */])(off, 3) * 4.0 - 2.0);
  7937. off++;
  7938. }
  7939. pcfKernels.push(pcfKernel);
  7940. }
  7941. this._pcfKernels = pcfKernels;
  7942. this.scene.on('beforerender', function (renderer, scene, camera) {
  7943. if (this.needsTemporalSS()) {
  7944. this._temporalSS.jitterProjection(renderer, camera);
  7945. }
  7946. }, this);
  7947. }
  7948. /**
  7949. * Set camera type of group
  7950. * @param {string} cameraType 'perspective' | 'orthographic'
  7951. */
  7952. ViewGL.prototype.setProjection = function (projection) {
  7953. var oldCamera = this.camera;
  7954. oldCamera && oldCamera.update();
  7955. if (projection === 'perspective') {
  7956. if (!(this.camera instanceof __WEBPACK_IMPORTED_MODULE_3_claygl_src_camera_Perspective__["a" /* default */])) {
  7957. this.camera = new __WEBPACK_IMPORTED_MODULE_3_claygl_src_camera_Perspective__["a" /* default */]();
  7958. if (oldCamera) {
  7959. this.camera.setLocalTransform(oldCamera.localTransform);
  7960. }
  7961. }
  7962. }
  7963. else {
  7964. if (!(this.camera instanceof __WEBPACK_IMPORTED_MODULE_4_claygl_src_camera_Orthographic__["a" /* default */])) {
  7965. this.camera = new __WEBPACK_IMPORTED_MODULE_4_claygl_src_camera_Orthographic__["a" /* default */]();
  7966. if (oldCamera) {
  7967. this.camera.setLocalTransform(oldCamera.localTransform);
  7968. }
  7969. }
  7970. }
  7971. // PENDING
  7972. this.camera.near = 0.1;
  7973. this.camera.far = 2000;
  7974. };
  7975. /**
  7976. * Set viewport of group
  7977. * @param {number} x Viewport left bottom x
  7978. * @param {number} y Viewport left bottom y
  7979. * @param {number} width Viewport height
  7980. * @param {number} height Viewport height
  7981. * @param {number} [dpr=1]
  7982. */
  7983. ViewGL.prototype.setViewport = function (x, y, width, height, dpr) {
  7984. if (this.camera instanceof __WEBPACK_IMPORTED_MODULE_3_claygl_src_camera_Perspective__["a" /* default */]) {
  7985. this.camera.aspect = width / height;
  7986. }
  7987. dpr = dpr || 1;
  7988. this.viewport.x = x;
  7989. this.viewport.y = y;
  7990. this.viewport.width = width;
  7991. this.viewport.height = height;
  7992. this.viewport.devicePixelRatio = dpr;
  7993. // Source and output of compositor use high dpr texture.
  7994. // But the intermediate texture of bloom, dof effects use fixed 1.0 dpr
  7995. this._compositor.resize(width * dpr, height * dpr);
  7996. this._temporalSS.resize(width * dpr, height * dpr);
  7997. };
  7998. /**
  7999. * If contain screen point x, y
  8000. * @param {number} x offsetX
  8001. * @param {number} y offsetY
  8002. * @return {boolean}
  8003. */
  8004. ViewGL.prototype.containPoint = function (x, y) {
  8005. var viewport = this.viewport;
  8006. var height = this.layer.renderer.getHeight();
  8007. // Flip y;
  8008. y = height - y;
  8009. return x >= viewport.x && y >= viewport.y
  8010. && x <= viewport.x + viewport.width && y <= viewport.y + viewport.height;
  8011. };
  8012. /**
  8013. * Cast a ray
  8014. * @param {number} x offsetX
  8015. * @param {number} y offsetY
  8016. * @param {clay.math.Ray} out
  8017. * @return {clay.math.Ray}
  8018. */
  8019. var ndc = new __WEBPACK_IMPORTED_MODULE_7_claygl_src_math_Vector2__["a" /* default */]();
  8020. ViewGL.prototype.castRay = function (x, y, out) {
  8021. var renderer = this.layer.renderer;
  8022. var oldViewport = renderer.viewport;
  8023. renderer.viewport = this.viewport;
  8024. renderer.screenToNDC(x, y, ndc);
  8025. this.camera.castRay(ndc, out);
  8026. renderer.viewport = oldViewport;
  8027. return out;
  8028. };
  8029. /**
  8030. * Prepare and update scene before render
  8031. */
  8032. ViewGL.prototype.prepareRender = function () {
  8033. this.scene.update();
  8034. this.camera.update();
  8035. this.scene.updateLights();
  8036. var renderList = this.scene.updateRenderList(this.camera);
  8037. this._needsSortProgressively = false;
  8038. // If has any transparent mesh needs sort triangles progressively.
  8039. for (var i = 0; i < renderList.transparent.length; i++) {
  8040. var renderable = renderList.transparent[i];
  8041. var geometry = renderable.geometry;
  8042. if (geometry.needsSortVerticesProgressively && geometry.needsSortVerticesProgressively()) {
  8043. this._needsSortProgressively = true;
  8044. }
  8045. if (geometry.needsSortTrianglesProgressively && geometry.needsSortTrianglesProgressively()) {
  8046. this._needsSortProgressively = true;
  8047. }
  8048. }
  8049. this._frame = 0;
  8050. this._temporalSS.resetFrame();
  8051. // var lights = this.scene.getLights();
  8052. // for (var i = 0; i < lights.length; i++) {
  8053. // if (lights[i].cubemap) {
  8054. // if (this._compositor && this._compositor.isSSREnabled()) {
  8055. // lights[i].invisible = true;
  8056. // }
  8057. // else {
  8058. // lights[i].invisible = false;
  8059. // }
  8060. // }
  8061. // }
  8062. };
  8063. ViewGL.prototype.render = function (renderer, accumulating) {
  8064. this._doRender(renderer, accumulating, this._frame);
  8065. this._frame++;
  8066. };
  8067. ViewGL.prototype.needsAccumulate = function () {
  8068. return this.needsTemporalSS() || this._needsSortProgressively;
  8069. };
  8070. ViewGL.prototype.needsTemporalSS = function () {
  8071. var enableTemporalSS = this._enableTemporalSS;
  8072. if (enableTemporalSS === 'auto') {
  8073. enableTemporalSS = this._enablePostEffect;
  8074. }
  8075. return enableTemporalSS;
  8076. };
  8077. ViewGL.prototype.hasDOF = function () {
  8078. return this._enableDOF;
  8079. };
  8080. ViewGL.prototype.isAccumulateFinished = function () {
  8081. return this.needsTemporalSS() ? this._temporalSS.isFinished()
  8082. : (this._frame > 30);
  8083. };
  8084. ViewGL.prototype._doRender = function (renderer, accumulating, accumFrame) {
  8085. var scene = this.scene;
  8086. var camera = this.camera;
  8087. accumFrame = accumFrame || 0;
  8088. this._updateTransparent(renderer, scene, camera, accumFrame);
  8089. if (!accumulating) {
  8090. this._shadowMapPass.kernelPCF = this._pcfKernels[0];
  8091. // Not render shadowmap pass in accumulating frame.
  8092. this._shadowMapPass.render(renderer, scene, camera, true);
  8093. }
  8094. this._updateShadowPCFKernel(accumFrame);
  8095. // Shadowmap will set clear color.
  8096. var bgColor = renderer.clearColor;
  8097. renderer.gl.clearColor(bgColor[0], bgColor[1], bgColor[2], bgColor[3]);
  8098. if (this._enablePostEffect) {
  8099. // normal render also needs to be jittered when have edge pass.
  8100. if (this.needsTemporalSS()) {
  8101. this._temporalSS.jitterProjection(renderer, camera);
  8102. }
  8103. this._compositor.updateNormal(renderer, scene, camera, this._temporalSS.getFrame());
  8104. }
  8105. // Always update SSAO to make sure have correct ssaoMap status
  8106. this._updateSSAO(renderer, scene, camera, this._temporalSS.getFrame());
  8107. if (this._enablePostEffect) {
  8108. var frameBuffer = this._compositor.getSourceFrameBuffer();
  8109. frameBuffer.bind(renderer);
  8110. renderer.gl.clear(renderer.gl.DEPTH_BUFFER_BIT | renderer.gl.COLOR_BUFFER_BIT);
  8111. renderer.render(scene, camera, true, true);
  8112. frameBuffer.unbind(renderer);
  8113. if (this.needsTemporalSS() && accumulating) {
  8114. this._compositor.composite(renderer, scene, camera, this._temporalSS.getSourceFrameBuffer(), this._temporalSS.getFrame());
  8115. renderer.setViewport(this.viewport);
  8116. this._temporalSS.render(renderer);
  8117. }
  8118. else {
  8119. renderer.setViewport(this.viewport);
  8120. this._compositor.composite(renderer, scene, camera, null, 0);
  8121. }
  8122. }
  8123. else {
  8124. if (this.needsTemporalSS() && accumulating) {
  8125. var frameBuffer = this._temporalSS.getSourceFrameBuffer();
  8126. frameBuffer.bind(renderer);
  8127. renderer.saveClear();
  8128. renderer.clearBit = renderer.gl.DEPTH_BUFFER_BIT | renderer.gl.COLOR_BUFFER_BIT;
  8129. renderer.render(scene, camera, true, true);
  8130. renderer.restoreClear();
  8131. frameBuffer.unbind(renderer);
  8132. renderer.setViewport(this.viewport);
  8133. this._temporalSS.render(renderer);
  8134. }
  8135. else {
  8136. renderer.setViewport(this.viewport);
  8137. renderer.render(scene, camera, true, true);
  8138. }
  8139. }
  8140. // this._shadowMapPass.renderDebug(renderer);
  8141. // this._compositor._normalPass.renderDebug(renderer);
  8142. };
  8143. ViewGL.prototype._updateTransparent = function (renderer, scene, camera, frame) {
  8144. var v3 = new __WEBPACK_IMPORTED_MODULE_6_claygl_src_math_Vector3__["a" /* default */]();
  8145. var invWorldTransform = new __WEBPACK_IMPORTED_MODULE_5_claygl_src_math_Matrix4__["a" /* default */]();
  8146. var cameraWorldPosition = camera.getWorldPosition();
  8147. var transparentList = scene.getRenderList(camera).transparent;
  8148. // Sort transparent object.
  8149. for (var i = 0; i < transparentList.length; i++) {
  8150. var renderable = transparentList[i];
  8151. var geometry = renderable.geometry;
  8152. __WEBPACK_IMPORTED_MODULE_5_claygl_src_math_Matrix4__["a" /* default */].invert(invWorldTransform, renderable.worldTransform);
  8153. __WEBPACK_IMPORTED_MODULE_6_claygl_src_math_Vector3__["a" /* default */].transformMat4(v3, cameraWorldPosition, invWorldTransform);
  8154. if (geometry.needsSortTriangles && geometry.needsSortTriangles()) {
  8155. geometry.doSortTriangles(v3, frame);
  8156. }
  8157. if (geometry.needsSortVertices && geometry.needsSortVertices()) {
  8158. geometry.doSortVertices(v3, frame);
  8159. }
  8160. }
  8161. };
  8162. ViewGL.prototype._updateSSAO = function (renderer, scene, camera) {
  8163. var ifEnableSSAO = this._enableSSAO && this._enablePostEffect;
  8164. if (ifEnableSSAO) {
  8165. this._compositor.updateSSAO(renderer, scene, camera, this._temporalSS.getFrame());
  8166. }
  8167. var renderList = scene.getRenderList(camera);
  8168. for (var i = 0; i < renderList.opaque.length; i++) {
  8169. var renderable = renderList.opaque[i];
  8170. // PENDING
  8171. if (renderable.renderNormal) {
  8172. renderable.material[ifEnableSSAO ? 'enableTexture' : 'disableTexture']('ssaoMap');
  8173. }
  8174. if (ifEnableSSAO) {
  8175. renderable.material.set('ssaoMap', this._compositor.getSSAOTexture());
  8176. }
  8177. }
  8178. };
  8179. ViewGL.prototype._updateShadowPCFKernel = function (frame) {
  8180. var pcfKernel = this._pcfKernels[frame % this._pcfKernels.length];
  8181. var renderList = this.scene.getRenderList(this.camera);
  8182. var opaqueList = renderList.opaque;
  8183. for (var i = 0; i < opaqueList.length; i++) {
  8184. if (opaqueList[i].receiveShadow) {
  8185. opaqueList[i].material.set('pcfKernel', pcfKernel);
  8186. opaqueList[i].material.define('fragment', 'PCF_KERNEL_SIZE', pcfKernel.length / 2);
  8187. }
  8188. }
  8189. };
  8190. ViewGL.prototype.dispose = function (renderer) {
  8191. this._compositor.dispose(renderer.gl);
  8192. this._temporalSS.dispose(renderer.gl);
  8193. this._shadowMapPass.dispose(renderer);
  8194. };
  8195. /**
  8196. * @param {module:echarts/Model} Post effect model
  8197. */
  8198. ViewGL.prototype.setPostEffect = function (postEffectModel, api) {
  8199. var compositor = this._compositor;
  8200. this._enablePostEffect = postEffectModel.get('enable');
  8201. var bloomModel = postEffectModel.getModel('bloom');
  8202. var edgeModel = postEffectModel.getModel('edge');
  8203. var dofModel = postEffectModel.getModel('DOF', postEffectModel.getModel('depthOfField'));
  8204. var ssaoModel = postEffectModel.getModel('SSAO', postEffectModel.getModel('screenSpaceAmbientOcclusion'));
  8205. var ssrModel = postEffectModel.getModel('SSR', postEffectModel.getModel('screenSpaceReflection'));
  8206. var fxaaModel = postEffectModel.getModel('FXAA');
  8207. var colorCorrModel = postEffectModel.getModel('colorCorrection');
  8208. bloomModel.get('enable') ? compositor.enableBloom() : compositor.disableBloom();
  8209. dofModel.get('enable') ? compositor.enableDOF() : compositor.disableDOF();
  8210. ssrModel.get('enable') ? compositor.enableSSR() : compositor.disableSSR();
  8211. colorCorrModel.get('enable') ? compositor.enableColorCorrection() : compositor.disableColorCorrection();
  8212. edgeModel.get('enable') ? compositor.enableEdge() : compositor.disableEdge();
  8213. fxaaModel.get('enable') ? compositor.enableFXAA() : compositor.disableFXAA();
  8214. this._enableDOF = dofModel.get('enable');
  8215. this._enableSSAO = ssaoModel.get('enable');
  8216. this._enableSSAO ? compositor.enableSSAO() : compositor.disableSSAO();
  8217. compositor.setBloomIntensity(bloomModel.get('intensity'));
  8218. compositor.setEdgeColor(edgeModel.get('color'));
  8219. compositor.setColorLookupTexture(colorCorrModel.get('lookupTexture'), api);
  8220. compositor.setExposure(colorCorrModel.get('exposure'));
  8221. ['radius', 'quality', 'intensity'].forEach(function (name) {
  8222. compositor.setSSAOParameter(name, ssaoModel.get(name));
  8223. });
  8224. ['quality', 'maxRoughness', 'physical'].forEach(function (name) {
  8225. compositor.setSSRParameter(name, ssrModel.get(name));
  8226. });
  8227. ['quality', 'focalDistance', 'focalRange', 'blurRadius', 'fstop'].forEach(function (name) {
  8228. compositor.setDOFParameter(name, dofModel.get(name));
  8229. });
  8230. ['brightness', 'contrast', 'saturation'].forEach(function (name) {
  8231. compositor.setColorCorrection(name, colorCorrModel.get(name));
  8232. });
  8233. };
  8234. ViewGL.prototype.setDOFFocusOnPoint = function (depth) {
  8235. if (this._enablePostEffect) {
  8236. if (depth > this.camera.far || depth < this.camera.near) {
  8237. return;
  8238. }
  8239. this._compositor.setDOFParameter('focalDistance', depth);
  8240. return true;
  8241. }
  8242. };
  8243. ViewGL.prototype.setTemporalSuperSampling = function (temporalSuperSamplingModel) {
  8244. this._enableTemporalSS = temporalSuperSamplingModel.get('enable');
  8245. };
  8246. ViewGL.prototype.isLinearSpace = function () {
  8247. return this._enablePostEffect;
  8248. };
  8249. ViewGL.prototype.setRootNode = function (rootNode) {
  8250. if (this.rootNode === rootNode) {
  8251. return;
  8252. }
  8253. var children = this.rootNode.children();
  8254. for (var i = 0; i < children.length; i++) {
  8255. rootNode.add(children[i]);
  8256. }
  8257. if (rootNode !== this.scene) {
  8258. this.scene.add(rootNode);
  8259. }
  8260. this.rootNode = rootNode;
  8261. };
  8262. // Proxies
  8263. ViewGL.prototype.add = function (node3D) {
  8264. this.rootNode.add(node3D);
  8265. };
  8266. ViewGL.prototype.remove = function (node3D) {
  8267. this.rootNode.remove(node3D);
  8268. };
  8269. ViewGL.prototype.removeAll = function (node3D) {
  8270. this.rootNode.removeAll(node3D);
  8271. };
  8272. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.extend(ViewGL.prototype, __WEBPACK_IMPORTED_MODULE_8_claygl_src_core_mixin_notifier__["a" /* default */]);
  8273. /* harmony default export */ __webpack_exports__["a"] = (ViewGL);
  8274. /***/
  8275. }),
  8276. /* 23 */
  8277. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  8278. "use strict";
  8279. var guid = 0;
  8280. var ArrayProto = Array.prototype;
  8281. var nativeForEach = ArrayProto.forEach;
  8282. /**
  8283. * Util functions
  8284. * @namespace clay.core.util
  8285. */
  8286. var util = {
  8287. /**
  8288. * Generate GUID
  8289. * @return {number}
  8290. * @memberOf clay.core.util
  8291. */
  8292. genGUID: function () {
  8293. return ++guid;
  8294. },
  8295. /**
  8296. * Relative path to absolute path
  8297. * @param {string} path
  8298. * @param {string} basePath
  8299. * @return {string}
  8300. * @memberOf clay.core.util
  8301. */
  8302. relative2absolute: function (path, basePath) {
  8303. if (!basePath || path.match(/^\//)) {
  8304. return path;
  8305. }
  8306. var pathParts = path.split('/');
  8307. var basePathParts = basePath.split('/');
  8308. var item = pathParts[0];
  8309. while (item === '.' || item === '..') {
  8310. if (item === '..') {
  8311. basePathParts.pop();
  8312. }
  8313. pathParts.shift();
  8314. item = pathParts[0];
  8315. }
  8316. return basePathParts.join('/') + '/' + pathParts.join('/');
  8317. },
  8318. /**
  8319. * Extend target with source
  8320. * @param {Object} target
  8321. * @param {Object} source
  8322. * @return {Object}
  8323. * @memberOf clay.core.util
  8324. */
  8325. extend: function (target, source) {
  8326. if (source) {
  8327. for (var name in source) {
  8328. if (source.hasOwnProperty(name)) {
  8329. target[name] = source[name];
  8330. }
  8331. }
  8332. }
  8333. return target;
  8334. },
  8335. /**
  8336. * Extend properties to target if not exist.
  8337. * @param {Object} target
  8338. * @param {Object} source
  8339. * @return {Object}
  8340. * @memberOf clay.core.util
  8341. */
  8342. defaults: function (target, source) {
  8343. if (source) {
  8344. for (var propName in source) {
  8345. if (target[propName] === undefined) {
  8346. target[propName] = source[propName];
  8347. }
  8348. }
  8349. }
  8350. return target;
  8351. },
  8352. /**
  8353. * Extend properties with a given property list to avoid for..in.. iteration.
  8354. * @param {Object} target
  8355. * @param {Object} source
  8356. * @param {Array.<string>} propList
  8357. * @return {Object}
  8358. * @memberOf clay.core.util
  8359. */
  8360. extendWithPropList: function (target, source, propList) {
  8361. if (source) {
  8362. for (var i = 0; i < propList.length; i++) {
  8363. var propName = propList[i];
  8364. target[propName] = source[propName];
  8365. }
  8366. }
  8367. return target;
  8368. },
  8369. /**
  8370. * Extend properties to target if not exist. With a given property list avoid for..in.. iteration.
  8371. * @param {Object} target
  8372. * @param {Object} source
  8373. * @param {Array.<string>} propList
  8374. * @return {Object}
  8375. * @memberOf clay.core.util
  8376. */
  8377. defaultsWithPropList: function (target, source, propList) {
  8378. if (source) {
  8379. for (var i = 0; i < propList.length; i++) {
  8380. var propName = propList[i];
  8381. if (target[propName] == null) {
  8382. target[propName] = source[propName];
  8383. }
  8384. }
  8385. }
  8386. return target;
  8387. },
  8388. /**
  8389. * @param {Object|Array} obj
  8390. * @param {Function} iterator
  8391. * @param {Object} [context]
  8392. * @memberOf clay.core.util
  8393. */
  8394. each: function (obj, iterator, context) {
  8395. if (!(obj && iterator)) {
  8396. return;
  8397. }
  8398. if (obj.forEach && obj.forEach === nativeForEach) {
  8399. obj.forEach(iterator, context);
  8400. }
  8401. else if (obj.length === + obj.length) {
  8402. for (var i = 0, len = obj.length; i < len; i++) {
  8403. iterator.call(context, obj[i], i, obj);
  8404. }
  8405. }
  8406. else {
  8407. for (var key in obj) {
  8408. if (obj.hasOwnProperty(key)) {
  8409. iterator.call(context, obj[key], key, obj);
  8410. }
  8411. }
  8412. }
  8413. },
  8414. /**
  8415. * Is object
  8416. * @param {} obj
  8417. * @return {boolean}
  8418. * @memberOf clay.core.util
  8419. */
  8420. isObject: function (obj) {
  8421. return obj === Object(obj);
  8422. },
  8423. /**
  8424. * Is array ?
  8425. * @param {} obj
  8426. * @return {boolean}
  8427. * @memberOf clay.core.util
  8428. */
  8429. isArray: function (obj) {
  8430. return Array.isArray(obj);
  8431. },
  8432. /**
  8433. * Is array like, which have a length property
  8434. * @param {} obj
  8435. * @return {boolean}
  8436. * @memberOf clay.core.util
  8437. */
  8438. isArrayLike: function (obj) {
  8439. if (!obj) {
  8440. return false;
  8441. }
  8442. else {
  8443. return obj.length === + obj.length;
  8444. }
  8445. },
  8446. /**
  8447. * @param {} obj
  8448. * @return {}
  8449. * @memberOf clay.core.util
  8450. */
  8451. clone: function (obj) {
  8452. if (!util.isObject(obj)) {
  8453. return obj;
  8454. }
  8455. else if (util.isArray(obj)) {
  8456. return obj.slice();
  8457. }
  8458. else if (util.isArrayLike(obj)) { // is typed array
  8459. var ret = new obj.constructor(obj.length);
  8460. for (var i = 0; i < obj.length; i++) {
  8461. ret[i] = obj[i];
  8462. }
  8463. return ret;
  8464. }
  8465. else {
  8466. return util.extend({}, obj);
  8467. }
  8468. }
  8469. };
  8470. /* harmony default export */ __webpack_exports__["a"] = (util);
  8471. /***/
  8472. }),
  8473. /* 24 */
  8474. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  8475. "use strict";
  8476. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Node__ = __webpack_require__(35);
  8477. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__Shader__ = __webpack_require__(8);
  8478. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__shader_source_header_light__ = __webpack_require__(119);
  8479. __WEBPACK_IMPORTED_MODULE_1__Shader__["a" /* default */]['import'](__WEBPACK_IMPORTED_MODULE_2__shader_source_header_light__["a" /* default */]);
  8480. /**
  8481. * @constructor clay.Light
  8482. * @extends clay.Node
  8483. */
  8484. var Light = __WEBPACK_IMPORTED_MODULE_0__Node__["a" /* default */].extend(function () {
  8485. return /** @lends clay.Light# */ {
  8486. /**
  8487. * Light RGB color
  8488. * @type {number[]}
  8489. */
  8490. color: [1, 1, 1],
  8491. /**
  8492. * Light intensity
  8493. * @type {number}
  8494. */
  8495. intensity: 1.0,
  8496. // Config for shadow map
  8497. /**
  8498. * If light cast shadow
  8499. * @type {boolean}
  8500. */
  8501. castShadow: true,
  8502. /**
  8503. * Shadow map size
  8504. * @type {number}
  8505. */
  8506. shadowResolution: 512,
  8507. /**
  8508. * Light group, shader with same `lightGroup` will be affected
  8509. *
  8510. * Only useful in forward rendering
  8511. * @type {number}
  8512. */
  8513. group: 0
  8514. };
  8515. },
  8516. /** @lends clay.Light.prototype. */
  8517. {
  8518. /**
  8519. * Light type
  8520. * @type {string}
  8521. * @memberOf clay.Light#
  8522. */
  8523. type: '',
  8524. /**
  8525. * @return {clay.Light}
  8526. * @memberOf clay.Light.prototype
  8527. */
  8528. clone: function () {
  8529. var light = __WEBPACK_IMPORTED_MODULE_0__Node__["a" /* default */].prototype.clone.call(this);
  8530. light.color = Array.prototype.slice.call(this.color);
  8531. light.intensity = this.intensity;
  8532. light.castShadow = this.castShadow;
  8533. light.shadowResolution = this.shadowResolution;
  8534. return light;
  8535. }
  8536. });
  8537. /* harmony default export */ __webpack_exports__["a"] = (Light);
  8538. /***/
  8539. }),
  8540. /* 25 */
  8541. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  8542. "use strict";
  8543. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__ = __webpack_require__(15);
  8544. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts__ = __webpack_require__(0);
  8545. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts__);
  8546. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__dynamicConvertMixin__ = __webpack_require__(38);
  8547. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_claygl_src_dep_glmatrix__ = __webpack_require__(6);
  8548. /**
  8549. * Lines geometry
  8550. * Use screen space projected lines lineWidth > MAX_LINE_WIDTH
  8551. * https://mattdesl.svbtle.com/drawing-lines-is-hard
  8552. * @module echarts-gl/util/geometry/LinesGeometry
  8553. * @author Yi Shen(http://github.com/pissang)
  8554. */
  8555. var vec3 = __WEBPACK_IMPORTED_MODULE_3_claygl_src_dep_glmatrix__["a" /* default */].vec3;
  8556. // var CURVE_RECURSION_LIMIT = 8;
  8557. // var CURVE_COLLINEAR_EPSILON = 40;
  8558. var sampleLinePoints = [[0, 0], [1, 1]];
  8559. /**
  8560. * @constructor
  8561. * @alias module:echarts-gl/util/geometry/LinesGeometry
  8562. * @extends clay.Geometry
  8563. */
  8564. var LinesGeometry = __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].extend(function () {
  8565. return {
  8566. segmentScale: 1,
  8567. dynamic: true,
  8568. /**
  8569. * Need to use mesh to expand lines if lineWidth > MAX_LINE_WIDTH
  8570. */
  8571. useNativeLine: true,
  8572. attributes: {
  8573. position: new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].Attribute('position', 'float', 3, 'POSITION'),
  8574. positionPrev: new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].Attribute('positionPrev', 'float', 3),
  8575. positionNext: new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].Attribute('positionNext', 'float', 3),
  8576. prevPositionPrev: new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].Attribute('prevPositionPrev', 'float', 3),
  8577. prevPosition: new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].Attribute('prevPosition', 'float', 3),
  8578. prevPositionNext: new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].Attribute('prevPositionNext', 'float', 3),
  8579. offset: new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].Attribute('offset', 'float', 1),
  8580. color: new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].Attribute('color', 'float', 4, 'COLOR')
  8581. }
  8582. };
  8583. },
  8584. /** @lends module: echarts-gl/util/geometry/LinesGeometry.prototype */
  8585. {
  8586. /**
  8587. * Reset offset
  8588. */
  8589. resetOffset: function () {
  8590. this._vertexOffset = 0;
  8591. this._triangleOffset = 0;
  8592. this._itemVertexOffsets = [];
  8593. },
  8594. /**
  8595. * @param {number} nVertex
  8596. */
  8597. setVertexCount: function (nVertex) {
  8598. var attributes = this.attributes;
  8599. if (this.vertexCount !== nVertex) {
  8600. attributes.position.init(nVertex);
  8601. attributes.color.init(nVertex);
  8602. if (!this.useNativeLine) {
  8603. attributes.positionPrev.init(nVertex);
  8604. attributes.positionNext.init(nVertex);
  8605. attributes.offset.init(nVertex);
  8606. }
  8607. if (nVertex > 0xffff) {
  8608. if (this.indices instanceof Uint16Array) {
  8609. this.indices = new Uint32Array(this.indices);
  8610. }
  8611. }
  8612. else {
  8613. if (this.indices instanceof Uint32Array) {
  8614. this.indices = new Uint16Array(this.indices);
  8615. }
  8616. }
  8617. }
  8618. },
  8619. /**
  8620. * @param {number} nTriangle
  8621. */
  8622. setTriangleCount: function (nTriangle) {
  8623. if (this.triangleCount !== nTriangle) {
  8624. if (nTriangle === 0) {
  8625. this.indices = null;
  8626. }
  8627. else {
  8628. this.indices = this.vertexCount > 0xffff ? new Uint32Array(nTriangle * 3) : new Uint16Array(nTriangle * 3);
  8629. }
  8630. }
  8631. },
  8632. _getCubicCurveApproxStep: function (p0, p1, p2, p3) {
  8633. var len = vec3.dist(p0, p1) + vec3.dist(p2, p1) + vec3.dist(p3, p2);
  8634. var step = 1 / (len + 1) * this.segmentScale;
  8635. return step;
  8636. },
  8637. /**
  8638. * Get vertex count of cubic curve
  8639. * @param {Array.<number>} p0
  8640. * @param {Array.<number>} p1
  8641. * @param {Array.<number>} p2
  8642. * @param {Array.<number>} p3
  8643. * @return number
  8644. */
  8645. getCubicCurveVertexCount: function (p0, p1, p2, p3) {
  8646. var step = this._getCubicCurveApproxStep(p0, p1, p2, p3);
  8647. var segCount = Math.ceil(1 / step);
  8648. if (!this.useNativeLine) {
  8649. return segCount * 2 + 2;
  8650. }
  8651. else {
  8652. return segCount * 2;
  8653. }
  8654. },
  8655. /**
  8656. * Get face count of cubic curve
  8657. * @param {Array.<number>} p0
  8658. * @param {Array.<number>} p1
  8659. * @param {Array.<number>} p2
  8660. * @param {Array.<number>} p3
  8661. * @return number
  8662. */
  8663. getCubicCurveTriangleCount: function (p0, p1, p2, p3) {
  8664. var step = this._getCubicCurveApproxStep(p0, p1, p2, p3);
  8665. var segCount = Math.ceil(1 / step);
  8666. if (!this.useNativeLine) {
  8667. return segCount * 2;
  8668. }
  8669. else {
  8670. return 0;
  8671. }
  8672. },
  8673. /**
  8674. * Get vertex count of line
  8675. * @return {number}
  8676. */
  8677. getLineVertexCount: function () {
  8678. return this.getPolylineVertexCount(sampleLinePoints);
  8679. },
  8680. /**
  8681. * Get face count of line
  8682. * @return {number}
  8683. */
  8684. getLineTriangleCount: function () {
  8685. return this.getPolylineTriangleCount(sampleLinePoints);
  8686. },
  8687. /**
  8688. * Get how many vertices will polyline take.
  8689. * @type {number|Array} points Can be a 1d/2d list of points, or a number of points amount.
  8690. * @return {number}
  8691. */
  8692. getPolylineVertexCount: function (points) {
  8693. var pointsLen;
  8694. if (typeof points === 'number') {
  8695. pointsLen = points;
  8696. }
  8697. else {
  8698. var is2DArray = typeof points[0] !== 'number';
  8699. pointsLen = is2DArray ? points.length : (points.length / 3);
  8700. }
  8701. return !this.useNativeLine ? ((pointsLen - 1) * 2 + 2) : (pointsLen - 1) * 2;
  8702. },
  8703. /**
  8704. * Get how many triangles will polyline take.
  8705. * @type {number|Array} points Can be a 1d/2d list of points, or a number of points amount.
  8706. * @return {number}
  8707. */
  8708. getPolylineTriangleCount: function (points) {
  8709. var pointsLen;
  8710. if (typeof points === 'number') {
  8711. pointsLen = points;
  8712. }
  8713. else {
  8714. var is2DArray = typeof points[0] !== 'number';
  8715. pointsLen = is2DArray ? points.length : (points.length / 3);
  8716. }
  8717. return !this.useNativeLine ? Math.max(pointsLen - 1, 0) * 2 : 0;
  8718. },
  8719. /**
  8720. * Add a cubic curve
  8721. * @param {Array.<number>} p0
  8722. * @param {Array.<number>} p1
  8723. * @param {Array.<number>} p2
  8724. * @param {Array.<number>} p3
  8725. * @param {Array.<number>} color
  8726. * @param {number} [lineWidth=1]
  8727. */
  8728. addCubicCurve: function (p0, p1, p2, p3, color, lineWidth) {
  8729. if (lineWidth == null) {
  8730. lineWidth = 1;
  8731. }
  8732. // incremental interpolation
  8733. // http://antigrain.com/research/bezier_interpolation/index.html#PAGE_BEZIER_INTERPOLATION
  8734. var x0 = p0[0], y0 = p0[1], z0 = p0[2];
  8735. var x1 = p1[0], y1 = p1[1], z1 = p1[2];
  8736. var x2 = p2[0], y2 = p2[1], z2 = p2[2];
  8737. var x3 = p3[0], y3 = p3[1], z3 = p3[2];
  8738. var step = this._getCubicCurveApproxStep(p0, p1, p2, p3);
  8739. var step2 = step * step;
  8740. var step3 = step2 * step;
  8741. var pre1 = 3.0 * step;
  8742. var pre2 = 3.0 * step2;
  8743. var pre4 = 6.0 * step2;
  8744. var pre5 = 6.0 * step3;
  8745. var tmp1x = x0 - x1 * 2.0 + x2;
  8746. var tmp1y = y0 - y1 * 2.0 + y2;
  8747. var tmp1z = z0 - z1 * 2.0 + z2;
  8748. var tmp2x = (x1 - x2) * 3.0 - x0 + x3;
  8749. var tmp2y = (y1 - y2) * 3.0 - y0 + y3;
  8750. var tmp2z = (z1 - z2) * 3.0 - z0 + z3;
  8751. var fx = x0;
  8752. var fy = y0;
  8753. var fz = z0;
  8754. var dfx = (x1 - x0) * pre1 + tmp1x * pre2 + tmp2x * step3;
  8755. var dfy = (y1 - y0) * pre1 + tmp1y * pre2 + tmp2y * step3;
  8756. var dfz = (z1 - z0) * pre1 + tmp1z * pre2 + tmp2z * step3;
  8757. var ddfx = tmp1x * pre4 + tmp2x * pre5;
  8758. var ddfy = tmp1y * pre4 + tmp2y * pre5;
  8759. var ddfz = tmp1z * pre4 + tmp2z * pre5;
  8760. var dddfx = tmp2x * pre5;
  8761. var dddfy = tmp2y * pre5;
  8762. var dddfz = tmp2z * pre5;
  8763. var t = 0;
  8764. var k = 0;
  8765. var segCount = Math.ceil(1 / step);
  8766. var points = new Float32Array((segCount + 1) * 3);
  8767. var points = [];
  8768. var offset = 0;
  8769. for (var k = 0; k < segCount + 1; k++) {
  8770. points[offset++] = fx;
  8771. points[offset++] = fy;
  8772. points[offset++] = fz;
  8773. fx += dfx; fy += dfy; fz += dfz;
  8774. dfx += ddfx; dfy += ddfy; dfz += ddfz;
  8775. ddfx += dddfx; ddfy += dddfy; ddfz += dddfz;
  8776. t += step;
  8777. if (t > 1) {
  8778. fx = dfx > 0 ? Math.min(fx, x3) : Math.max(fx, x3);
  8779. fy = dfy > 0 ? Math.min(fy, y3) : Math.max(fy, y3);
  8780. fz = dfz > 0 ? Math.min(fz, z3) : Math.max(fz, z3);
  8781. }
  8782. }
  8783. return this.addPolyline(points, color, lineWidth);
  8784. },
  8785. /**
  8786. * Add a straight line
  8787. * @param {Array.<number>} p0
  8788. * @param {Array.<number>} p1
  8789. * @param {Array.<number>} color
  8790. * @param {number} [lineWidth=1]
  8791. */
  8792. addLine: function (p0, p1, color, lineWidth) {
  8793. return this.addPolyline([p0, p1], color, lineWidth);
  8794. },
  8795. /**
  8796. * Add a straight line
  8797. * @param {Array.<Array> | Array.<number>} points
  8798. * @param {Array.<number> | Array.<Array>} color
  8799. * @param {number} [lineWidth=1]
  8800. * @param {number} [startOffset=0]
  8801. * @param {number} [pointsCount] Default to be amount of points in the first argument
  8802. */
  8803. addPolyline: function (points, color, lineWidth, startOffset, pointsCount) {
  8804. if (!points.length) {
  8805. return;
  8806. }
  8807. var is2DArray = typeof points[0] !== 'number';
  8808. if (pointsCount == null) {
  8809. pointsCount = is2DArray ? points.length : points.length / 3;
  8810. }
  8811. if (pointsCount < 2) {
  8812. return;
  8813. }
  8814. if (startOffset == null) {
  8815. startOffset = 0;
  8816. }
  8817. if (lineWidth == null) {
  8818. lineWidth = 1;
  8819. }
  8820. this._itemVertexOffsets.push(this._vertexOffset);
  8821. var is2DArray = typeof points[0] !== 'number';
  8822. var notSharingColor = is2DArray
  8823. ? typeof color[0] !== 'number'
  8824. : color.length / 4 === pointsCount;
  8825. var positionAttr = this.attributes.position;
  8826. var positionPrevAttr = this.attributes.positionPrev;
  8827. var positionNextAttr = this.attributes.positionNext;
  8828. var colorAttr = this.attributes.color;
  8829. var offsetAttr = this.attributes.offset;
  8830. var indices = this.indices;
  8831. var vertexOffset = this._vertexOffset;
  8832. var point;
  8833. var pointColor;
  8834. lineWidth = Math.max(lineWidth, 0.01);
  8835. for (var k = startOffset; k < pointsCount; k++) {
  8836. if (is2DArray) {
  8837. point = points[k];
  8838. if (notSharingColor) {
  8839. pointColor = color[k];
  8840. }
  8841. else {
  8842. pointColor = color;
  8843. }
  8844. }
  8845. else {
  8846. var k3 = k * 3;
  8847. point = point || [];
  8848. point[0] = points[k3];
  8849. point[1] = points[k3 + 1];
  8850. point[2] = points[k3 + 2];
  8851. if (notSharingColor) {
  8852. var k4 = k * 4;
  8853. pointColor = pointColor || [];
  8854. pointColor[0] = color[k4];
  8855. pointColor[1] = color[k4 + 1];
  8856. pointColor[2] = color[k4 + 2];
  8857. pointColor[3] = color[k4 + 3];
  8858. }
  8859. else {
  8860. pointColor = color;
  8861. }
  8862. }
  8863. if (!this.useNativeLine) {
  8864. if (k < pointsCount - 1) {
  8865. // Set to next two points
  8866. positionPrevAttr.set(vertexOffset + 2, point);
  8867. positionPrevAttr.set(vertexOffset + 3, point);
  8868. }
  8869. if (k > 0) {
  8870. // Set to previous two points
  8871. positionNextAttr.set(vertexOffset - 2, point);
  8872. positionNextAttr.set(vertexOffset - 1, point);
  8873. }
  8874. positionAttr.set(vertexOffset, point);
  8875. positionAttr.set(vertexOffset + 1, point);
  8876. colorAttr.set(vertexOffset, pointColor);
  8877. colorAttr.set(vertexOffset + 1, pointColor);
  8878. offsetAttr.set(vertexOffset, lineWidth / 2);
  8879. offsetAttr.set(vertexOffset + 1, -lineWidth / 2);
  8880. vertexOffset += 2;
  8881. }
  8882. else {
  8883. if (k > 1) {
  8884. positionAttr.copy(vertexOffset, vertexOffset - 1);
  8885. colorAttr.copy(vertexOffset, vertexOffset - 1);
  8886. vertexOffset++;
  8887. }
  8888. }
  8889. if (!this.useNativeLine) {
  8890. if (k > 0) {
  8891. var idx3 = this._triangleOffset * 3;
  8892. var indices = this.indices;
  8893. // 0-----2
  8894. // 1-----3
  8895. // 0->1->2, 1->3->2
  8896. indices[idx3] = vertexOffset - 4;
  8897. indices[idx3 + 1] = vertexOffset - 3;
  8898. indices[idx3 + 2] = vertexOffset - 2;
  8899. indices[idx3 + 3] = vertexOffset - 3;
  8900. indices[idx3 + 4] = vertexOffset - 1;
  8901. indices[idx3 + 5] = vertexOffset - 2;
  8902. this._triangleOffset += 2;
  8903. }
  8904. }
  8905. else {
  8906. colorAttr.set(vertexOffset, pointColor);
  8907. positionAttr.set(vertexOffset, point);
  8908. vertexOffset++;
  8909. }
  8910. }
  8911. if (!this.useNativeLine) {
  8912. var start = this._vertexOffset;
  8913. var end = this._vertexOffset + pointsCount * 2;
  8914. positionPrevAttr.copy(start, start + 2);
  8915. positionPrevAttr.copy(start + 1, start + 3);
  8916. positionNextAttr.copy(end - 1, end - 3);
  8917. positionNextAttr.copy(end - 2, end - 4);
  8918. }
  8919. this._vertexOffset = vertexOffset;
  8920. return this._vertexOffset;
  8921. },
  8922. /**
  8923. * Set color of single line.
  8924. */
  8925. setItemColor: function (idx, color) {
  8926. var startOffset = this._itemVertexOffsets[idx];
  8927. var endOffset = idx < this._itemVertexOffsets.length - 1 ? this._itemVertexOffsets[idx + 1] : this._vertexOffset;
  8928. for (var i = startOffset; i < endOffset; i++) {
  8929. this.attributes.color.set(i, color);
  8930. }
  8931. this.dirty('color');
  8932. },
  8933. /**
  8934. * @return {number}
  8935. */
  8936. currentTriangleOffset: function () {
  8937. return this._triangleOffset;
  8938. },
  8939. /**
  8940. * @return {number}
  8941. */
  8942. currentVertexOffset: function () {
  8943. return this._vertexOffset;
  8944. }
  8945. });
  8946. __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default.a.util.defaults(LinesGeometry.prototype, __WEBPACK_IMPORTED_MODULE_2__dynamicConvertMixin__["a" /* default */]);
  8947. /* harmony default export */ __webpack_exports__["a"] = (LinesGeometry);
  8948. /***/
  8949. }),
  8950. /* 26 */
  8951. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  8952. "use strict";
  8953. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__ = __webpack_require__(70);
  8954. /**
  8955. * @constructor
  8956. * @alias clay.Vector2
  8957. * @param {number} x
  8958. * @param {number} y
  8959. */
  8960. var Vector2 = function (x, y) {
  8961. x = x || 0;
  8962. y = y || 0;
  8963. /**
  8964. * Storage of Vector2, read and write of x, y will change the values in array
  8965. * All methods also operate on the array instead of x, y components
  8966. * @name array
  8967. * @type {Float32Array}
  8968. * @memberOf clay.Vector2#
  8969. */
  8970. this.array = __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].fromValues(x, y);
  8971. /**
  8972. * Dirty flag is used by the Node to determine
  8973. * if the matrix is updated to latest
  8974. * @name _dirty
  8975. * @type {boolean}
  8976. * @memberOf clay.Vector2#
  8977. */
  8978. this._dirty = true;
  8979. };
  8980. Vector2.prototype = {
  8981. constructor: Vector2,
  8982. /**
  8983. * Add b to self
  8984. * @param {clay.Vector2} b
  8985. * @return {clay.Vector2}
  8986. */
  8987. add: function (b) {
  8988. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].add(this.array, this.array, b.array);
  8989. this._dirty = true;
  8990. return this;
  8991. },
  8992. /**
  8993. * Set x and y components
  8994. * @param {number} x
  8995. * @param {number} y
  8996. * @return {clay.Vector2}
  8997. */
  8998. set: function (x, y) {
  8999. this.array[0] = x;
  9000. this.array[1] = y;
  9001. this._dirty = true;
  9002. return this;
  9003. },
  9004. /**
  9005. * Set x and y components from array
  9006. * @param {Float32Array|number[]} arr
  9007. * @return {clay.Vector2}
  9008. */
  9009. setArray: function (arr) {
  9010. this.array[0] = arr[0];
  9011. this.array[1] = arr[1];
  9012. this._dirty = true;
  9013. return this;
  9014. },
  9015. /**
  9016. * Clone a new Vector2
  9017. * @return {clay.Vector2}
  9018. */
  9019. clone: function () {
  9020. return new Vector2(this.x, this.y);
  9021. },
  9022. /**
  9023. * Copy x, y from b
  9024. * @param {clay.Vector2} b
  9025. * @return {clay.Vector2}
  9026. */
  9027. copy: function (b) {
  9028. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].copy(this.array, b.array);
  9029. this._dirty = true;
  9030. return this;
  9031. },
  9032. /**
  9033. * Cross product of self and b, written to a Vector3 out
  9034. * @param {clay.Vector3} out
  9035. * @param {clay.Vector2} b
  9036. * @return {clay.Vector2}
  9037. */
  9038. cross: function (out, b) {
  9039. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].cross(out.array, this.array, b.array);
  9040. out._dirty = true;
  9041. return this;
  9042. },
  9043. /**
  9044. * Alias for distance
  9045. * @param {clay.Vector2} b
  9046. * @return {number}
  9047. */
  9048. dist: function (b) {
  9049. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].dist(this.array, b.array);
  9050. },
  9051. /**
  9052. * Distance between self and b
  9053. * @param {clay.Vector2} b
  9054. * @return {number}
  9055. */
  9056. distance: function (b) {
  9057. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].distance(this.array, b.array);
  9058. },
  9059. /**
  9060. * Alias for divide
  9061. * @param {clay.Vector2} b
  9062. * @return {clay.Vector2}
  9063. */
  9064. div: function (b) {
  9065. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].div(this.array, this.array, b.array);
  9066. this._dirty = true;
  9067. return this;
  9068. },
  9069. /**
  9070. * Divide self by b
  9071. * @param {clay.Vector2} b
  9072. * @return {clay.Vector2}
  9073. */
  9074. divide: function (b) {
  9075. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].divide(this.array, this.array, b.array);
  9076. this._dirty = true;
  9077. return this;
  9078. },
  9079. /**
  9080. * Dot product of self and b
  9081. * @param {clay.Vector2} b
  9082. * @return {number}
  9083. */
  9084. dot: function (b) {
  9085. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].dot(this.array, b.array);
  9086. },
  9087. /**
  9088. * Alias of length
  9089. * @return {number}
  9090. */
  9091. len: function () {
  9092. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].len(this.array);
  9093. },
  9094. /**
  9095. * Calculate the length
  9096. * @return {number}
  9097. */
  9098. length: function () {
  9099. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].length(this.array);
  9100. },
  9101. /**
  9102. * Linear interpolation between a and b
  9103. * @param {clay.Vector2} a
  9104. * @param {clay.Vector2} b
  9105. * @param {number} t
  9106. * @return {clay.Vector2}
  9107. */
  9108. lerp: function (a, b, t) {
  9109. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].lerp(this.array, a.array, b.array, t);
  9110. this._dirty = true;
  9111. return this;
  9112. },
  9113. /**
  9114. * Minimum of self and b
  9115. * @param {clay.Vector2} b
  9116. * @return {clay.Vector2}
  9117. */
  9118. min: function (b) {
  9119. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].min(this.array, this.array, b.array);
  9120. this._dirty = true;
  9121. return this;
  9122. },
  9123. /**
  9124. * Maximum of self and b
  9125. * @param {clay.Vector2} b
  9126. * @return {clay.Vector2}
  9127. */
  9128. max: function (b) {
  9129. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].max(this.array, this.array, b.array);
  9130. this._dirty = true;
  9131. return this;
  9132. },
  9133. /**
  9134. * Alias for multiply
  9135. * @param {clay.Vector2} b
  9136. * @return {clay.Vector2}
  9137. */
  9138. mul: function (b) {
  9139. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].mul(this.array, this.array, b.array);
  9140. this._dirty = true;
  9141. return this;
  9142. },
  9143. /**
  9144. * Mutiply self and b
  9145. * @param {clay.Vector2} b
  9146. * @return {clay.Vector2}
  9147. */
  9148. multiply: function (b) {
  9149. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].multiply(this.array, this.array, b.array);
  9150. this._dirty = true;
  9151. return this;
  9152. },
  9153. /**
  9154. * Negate self
  9155. * @return {clay.Vector2}
  9156. */
  9157. negate: function () {
  9158. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].negate(this.array, this.array);
  9159. this._dirty = true;
  9160. return this;
  9161. },
  9162. /**
  9163. * Normalize self
  9164. * @return {clay.Vector2}
  9165. */
  9166. normalize: function () {
  9167. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].normalize(this.array, this.array);
  9168. this._dirty = true;
  9169. return this;
  9170. },
  9171. /**
  9172. * Generate random x, y components with a given scale
  9173. * @param {number} scale
  9174. * @return {clay.Vector2}
  9175. */
  9176. random: function (scale) {
  9177. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].random(this.array, scale);
  9178. this._dirty = true;
  9179. return this;
  9180. },
  9181. /**
  9182. * Scale self
  9183. * @param {number} scale
  9184. * @return {clay.Vector2}
  9185. */
  9186. scale: function (s) {
  9187. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].scale(this.array, this.array, s);
  9188. this._dirty = true;
  9189. return this;
  9190. },
  9191. /**
  9192. * Scale b and add to self
  9193. * @param {clay.Vector2} b
  9194. * @param {number} scale
  9195. * @return {clay.Vector2}
  9196. */
  9197. scaleAndAdd: function (b, s) {
  9198. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].scaleAndAdd(this.array, this.array, b.array, s);
  9199. this._dirty = true;
  9200. return this;
  9201. },
  9202. /**
  9203. * Alias for squaredDistance
  9204. * @param {clay.Vector2} b
  9205. * @return {number}
  9206. */
  9207. sqrDist: function (b) {
  9208. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].sqrDist(this.array, b.array);
  9209. },
  9210. /**
  9211. * Squared distance between self and b
  9212. * @param {clay.Vector2} b
  9213. * @return {number}
  9214. */
  9215. squaredDistance: function (b) {
  9216. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].squaredDistance(this.array, b.array);
  9217. },
  9218. /**
  9219. * Alias for squaredLength
  9220. * @return {number}
  9221. */
  9222. sqrLen: function () {
  9223. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].sqrLen(this.array);
  9224. },
  9225. /**
  9226. * Squared length of self
  9227. * @return {number}
  9228. */
  9229. squaredLength: function () {
  9230. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].squaredLength(this.array);
  9231. },
  9232. /**
  9233. * Alias for subtract
  9234. * @param {clay.Vector2} b
  9235. * @return {clay.Vector2}
  9236. */
  9237. sub: function (b) {
  9238. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].sub(this.array, this.array, b.array);
  9239. this._dirty = true;
  9240. return this;
  9241. },
  9242. /**
  9243. * Subtract b from self
  9244. * @param {clay.Vector2} b
  9245. * @return {clay.Vector2}
  9246. */
  9247. subtract: function (b) {
  9248. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].subtract(this.array, this.array, b.array);
  9249. this._dirty = true;
  9250. return this;
  9251. },
  9252. /**
  9253. * Transform self with a Matrix2 m
  9254. * @param {clay.Matrix2} m
  9255. * @return {clay.Vector2}
  9256. */
  9257. transformMat2: function (m) {
  9258. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].transformMat2(this.array, this.array, m.array);
  9259. this._dirty = true;
  9260. return this;
  9261. },
  9262. /**
  9263. * Transform self with a Matrix2d m
  9264. * @param {clay.Matrix2d} m
  9265. * @return {clay.Vector2}
  9266. */
  9267. transformMat2d: function (m) {
  9268. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].transformMat2d(this.array, this.array, m.array);
  9269. this._dirty = true;
  9270. return this;
  9271. },
  9272. /**
  9273. * Transform self with a Matrix3 m
  9274. * @param {clay.Matrix3} m
  9275. * @return {clay.Vector2}
  9276. */
  9277. transformMat3: function (m) {
  9278. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].transformMat3(this.array, this.array, m.array);
  9279. this._dirty = true;
  9280. return this;
  9281. },
  9282. /**
  9283. * Transform self with a Matrix4 m
  9284. * @param {clay.Matrix4} m
  9285. * @return {clay.Vector2}
  9286. */
  9287. transformMat4: function (m) {
  9288. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].transformMat4(this.array, this.array, m.array);
  9289. this._dirty = true;
  9290. return this;
  9291. },
  9292. toString: function () {
  9293. return '[' + Array.prototype.join.call(this.array, ',') + ']';
  9294. },
  9295. toArray: function () {
  9296. return Array.prototype.slice.call(this.array);
  9297. }
  9298. };
  9299. // Getter and Setter
  9300. if (Object.defineProperty) {
  9301. var proto = Vector2.prototype;
  9302. /**
  9303. * @name x
  9304. * @type {number}
  9305. * @memberOf clay.Vector2
  9306. * @instance
  9307. */
  9308. Object.defineProperty(proto, 'x', {
  9309. get: function () {
  9310. return this.array[0];
  9311. },
  9312. set: function (value) {
  9313. this.array[0] = value;
  9314. this._dirty = true;
  9315. }
  9316. });
  9317. /**
  9318. * @name y
  9319. * @type {number}
  9320. * @memberOf clay.Vector2
  9321. * @instance
  9322. */
  9323. Object.defineProperty(proto, 'y', {
  9324. get: function () {
  9325. return this.array[1];
  9326. },
  9327. set: function (value) {
  9328. this.array[1] = value;
  9329. this._dirty = true;
  9330. }
  9331. });
  9332. }
  9333. // Supply methods that are not in place
  9334. /**
  9335. * @param {clay.Vector2} out
  9336. * @param {clay.Vector2} a
  9337. * @param {clay.Vector2} b
  9338. * @return {clay.Vector2}
  9339. */
  9340. Vector2.add = function (out, a, b) {
  9341. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].add(out.array, a.array, b.array);
  9342. out._dirty = true;
  9343. return out;
  9344. };
  9345. /**
  9346. * @param {clay.Vector2} out
  9347. * @param {number} x
  9348. * @param {number} y
  9349. * @return {clay.Vector2}
  9350. */
  9351. Vector2.set = function (out, x, y) {
  9352. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].set(out.array, x, y);
  9353. out._dirty = true;
  9354. return out;
  9355. };
  9356. /**
  9357. * @param {clay.Vector2} out
  9358. * @param {clay.Vector2} b
  9359. * @return {clay.Vector2}
  9360. */
  9361. Vector2.copy = function (out, b) {
  9362. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].copy(out.array, b.array);
  9363. out._dirty = true;
  9364. return out;
  9365. };
  9366. /**
  9367. * @param {clay.Vector3} out
  9368. * @param {clay.Vector2} a
  9369. * @param {clay.Vector2} b
  9370. * @return {clay.Vector2}
  9371. */
  9372. Vector2.cross = function (out, a, b) {
  9373. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].cross(out.array, a.array, b.array);
  9374. out._dirty = true;
  9375. return out;
  9376. };
  9377. /**
  9378. * @param {clay.Vector2} a
  9379. * @param {clay.Vector2} b
  9380. * @return {number}
  9381. */
  9382. Vector2.dist = function (a, b) {
  9383. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].distance(a.array, b.array);
  9384. };
  9385. /**
  9386. * @function
  9387. * @param {clay.Vector2} a
  9388. * @param {clay.Vector2} b
  9389. * @return {number}
  9390. */
  9391. Vector2.distance = Vector2.dist;
  9392. /**
  9393. * @param {clay.Vector2} out
  9394. * @param {clay.Vector2} a
  9395. * @param {clay.Vector2} b
  9396. * @return {clay.Vector2}
  9397. */
  9398. Vector2.div = function (out, a, b) {
  9399. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].divide(out.array, a.array, b.array);
  9400. out._dirty = true;
  9401. return out;
  9402. };
  9403. /**
  9404. * @function
  9405. * @param {clay.Vector2} out
  9406. * @param {clay.Vector2} a
  9407. * @param {clay.Vector2} b
  9408. * @return {clay.Vector2}
  9409. */
  9410. Vector2.divide = Vector2.div;
  9411. /**
  9412. * @param {clay.Vector2} a
  9413. * @param {clay.Vector2} b
  9414. * @return {number}
  9415. */
  9416. Vector2.dot = function (a, b) {
  9417. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].dot(a.array, b.array);
  9418. };
  9419. /**
  9420. * @param {clay.Vector2} a
  9421. * @return {number}
  9422. */
  9423. Vector2.len = function (b) {
  9424. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].length(b.array);
  9425. };
  9426. // Vector2.length = Vector2.len;
  9427. /**
  9428. * @param {clay.Vector2} out
  9429. * @param {clay.Vector2} a
  9430. * @param {clay.Vector2} b
  9431. * @param {number} t
  9432. * @return {clay.Vector2}
  9433. */
  9434. Vector2.lerp = function (out, a, b, t) {
  9435. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].lerp(out.array, a.array, b.array, t);
  9436. out._dirty = true;
  9437. return out;
  9438. };
  9439. /**
  9440. * @param {clay.Vector2} out
  9441. * @param {clay.Vector2} a
  9442. * @param {clay.Vector2} b
  9443. * @return {clay.Vector2}
  9444. */
  9445. Vector2.min = function (out, a, b) {
  9446. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].min(out.array, a.array, b.array);
  9447. out._dirty = true;
  9448. return out;
  9449. };
  9450. /**
  9451. * @param {clay.Vector2} out
  9452. * @param {clay.Vector2} a
  9453. * @param {clay.Vector2} b
  9454. * @return {clay.Vector2}
  9455. */
  9456. Vector2.max = function (out, a, b) {
  9457. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].max(out.array, a.array, b.array);
  9458. out._dirty = true;
  9459. return out;
  9460. };
  9461. /**
  9462. * @param {clay.Vector2} out
  9463. * @param {clay.Vector2} a
  9464. * @param {clay.Vector2} b
  9465. * @return {clay.Vector2}
  9466. */
  9467. Vector2.mul = function (out, a, b) {
  9468. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].multiply(out.array, a.array, b.array);
  9469. out._dirty = true;
  9470. return out;
  9471. };
  9472. /**
  9473. * @function
  9474. * @param {clay.Vector2} out
  9475. * @param {clay.Vector2} a
  9476. * @param {clay.Vector2} b
  9477. * @return {clay.Vector2}
  9478. */
  9479. Vector2.multiply = Vector2.mul;
  9480. /**
  9481. * @param {clay.Vector2} out
  9482. * @param {clay.Vector2} a
  9483. * @return {clay.Vector2}
  9484. */
  9485. Vector2.negate = function (out, a) {
  9486. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].negate(out.array, a.array);
  9487. out._dirty = true;
  9488. return out;
  9489. };
  9490. /**
  9491. * @param {clay.Vector2} out
  9492. * @param {clay.Vector2} a
  9493. * @return {clay.Vector2}
  9494. */
  9495. Vector2.normalize = function (out, a) {
  9496. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].normalize(out.array, a.array);
  9497. out._dirty = true;
  9498. return out;
  9499. };
  9500. /**
  9501. * @param {clay.Vector2} out
  9502. * @param {number} scale
  9503. * @return {clay.Vector2}
  9504. */
  9505. Vector2.random = function (out, scale) {
  9506. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].random(out.array, scale);
  9507. out._dirty = true;
  9508. return out;
  9509. };
  9510. /**
  9511. * @param {clay.Vector2} out
  9512. * @param {clay.Vector2} a
  9513. * @param {number} scale
  9514. * @return {clay.Vector2}
  9515. */
  9516. Vector2.scale = function (out, a, scale) {
  9517. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].scale(out.array, a.array, scale);
  9518. out._dirty = true;
  9519. return out;
  9520. };
  9521. /**
  9522. * @param {clay.Vector2} out
  9523. * @param {clay.Vector2} a
  9524. * @param {clay.Vector2} b
  9525. * @param {number} scale
  9526. * @return {clay.Vector2}
  9527. */
  9528. Vector2.scaleAndAdd = function (out, a, b, scale) {
  9529. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].scaleAndAdd(out.array, a.array, b.array, scale);
  9530. out._dirty = true;
  9531. return out;
  9532. };
  9533. /**
  9534. * @param {clay.Vector2} a
  9535. * @param {clay.Vector2} b
  9536. * @return {number}
  9537. */
  9538. Vector2.sqrDist = function (a, b) {
  9539. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].sqrDist(a.array, b.array);
  9540. };
  9541. /**
  9542. * @function
  9543. * @param {clay.Vector2} a
  9544. * @param {clay.Vector2} b
  9545. * @return {number}
  9546. */
  9547. Vector2.squaredDistance = Vector2.sqrDist;
  9548. /**
  9549. * @param {clay.Vector2} a
  9550. * @return {number}
  9551. */
  9552. Vector2.sqrLen = function (a) {
  9553. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].sqrLen(a.array);
  9554. };
  9555. /**
  9556. * @function
  9557. * @param {clay.Vector2} a
  9558. * @return {number}
  9559. */
  9560. Vector2.squaredLength = Vector2.sqrLen;
  9561. /**
  9562. * @param {clay.Vector2} out
  9563. * @param {clay.Vector2} a
  9564. * @param {clay.Vector2} b
  9565. * @return {clay.Vector2}
  9566. */
  9567. Vector2.sub = function (out, a, b) {
  9568. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].subtract(out.array, a.array, b.array);
  9569. out._dirty = true;
  9570. return out;
  9571. };
  9572. /**
  9573. * @function
  9574. * @param {clay.Vector2} out
  9575. * @param {clay.Vector2} a
  9576. * @param {clay.Vector2} b
  9577. * @return {clay.Vector2}
  9578. */
  9579. Vector2.subtract = Vector2.sub;
  9580. /**
  9581. * @param {clay.Vector2} out
  9582. * @param {clay.Vector2} a
  9583. * @param {clay.Matrix2} m
  9584. * @return {clay.Vector2}
  9585. */
  9586. Vector2.transformMat2 = function (out, a, m) {
  9587. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].transformMat2(out.array, a.array, m.array);
  9588. out._dirty = true;
  9589. return out;
  9590. };
  9591. /**
  9592. * @param {clay.Vector2} out
  9593. * @param {clay.Vector2} a
  9594. * @param {clay.Matrix2d} m
  9595. * @return {clay.Vector2}
  9596. */
  9597. Vector2.transformMat2d = function (out, a, m) {
  9598. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].transformMat2d(out.array, a.array, m.array);
  9599. out._dirty = true;
  9600. return out;
  9601. };
  9602. /**
  9603. * @param {clay.Vector2} out
  9604. * @param {clay.Vector2} a
  9605. * @param {Matrix3} m
  9606. * @return {clay.Vector2}
  9607. */
  9608. Vector2.transformMat3 = function (out, a, m) {
  9609. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].transformMat3(out.array, a.array, m.array);
  9610. out._dirty = true;
  9611. return out;
  9612. };
  9613. /**
  9614. * @param {clay.Vector2} out
  9615. * @param {clay.Vector2} a
  9616. * @param {clay.Matrix4} m
  9617. * @return {clay.Vector2}
  9618. */
  9619. Vector2.transformMat4 = function (out, a, m) {
  9620. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec2__["a" /* default */].transformMat4(out.array, a.array, m.array);
  9621. out._dirty = true;
  9622. return out;
  9623. };
  9624. /* harmony default export */ __webpack_exports__["a"] = (Vector2);
  9625. /***/
  9626. }),
  9627. /* 27 */
  9628. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  9629. "use strict";
  9630. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Texture__ = __webpack_require__(4);
  9631. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__core_glenum__ = __webpack_require__(11);
  9632. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__core_util__ = __webpack_require__(23);
  9633. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__math_util__ = __webpack_require__(73);
  9634. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__core_vendor__ = __webpack_require__(14);
  9635. var isPowerOfTwo = __WEBPACK_IMPORTED_MODULE_3__math_util__["a" /* default */].isPowerOfTwo;
  9636. var targetList = ['px', 'nx', 'py', 'ny', 'pz', 'nz'];
  9637. /**
  9638. * @constructor clay.TextureCube
  9639. * @extends clay.Texture
  9640. *
  9641. * @example
  9642. * ...
  9643. * var mat = new clay.Material({
  9644. * shader: clay.shader.library.get('clay.phong', 'environmentMap')
  9645. * });
  9646. * var envMap = new clay.TextureCube();
  9647. * envMap.load({
  9648. * 'px': 'assets/textures/sky/px.jpg',
  9649. * 'nx': 'assets/textures/sky/nx.jpg'
  9650. * 'py': 'assets/textures/sky/py.jpg'
  9651. * 'ny': 'assets/textures/sky/ny.jpg'
  9652. * 'pz': 'assets/textures/sky/pz.jpg'
  9653. * 'nz': 'assets/textures/sky/nz.jpg'
  9654. * });
  9655. * mat.set('environmentMap', envMap);
  9656. * ...
  9657. * envMap.success(function () {
  9658. * // Wait for the sky texture loaded
  9659. * animation.on('frame', function (frameTime) {
  9660. * renderer.render(scene, camera);
  9661. * });
  9662. * });
  9663. */
  9664. var TextureCube = __WEBPACK_IMPORTED_MODULE_0__Texture__["a" /* default */].extend(function () {
  9665. return /** @lends clay.TextureCube# */{
  9666. /**
  9667. * @type {boolean}
  9668. * @default false
  9669. */
  9670. // PENDING cubemap should not flipY in default.
  9671. // flipY: false,
  9672. /**
  9673. * @type {Object}
  9674. * @property {?HTMLImageElement|HTMLCanvasElemnet} px
  9675. * @property {?HTMLImageElement|HTMLCanvasElemnet} nx
  9676. * @property {?HTMLImageElement|HTMLCanvasElemnet} py
  9677. * @property {?HTMLImageElement|HTMLCanvasElemnet} ny
  9678. * @property {?HTMLImageElement|HTMLCanvasElemnet} pz
  9679. * @property {?HTMLImageElement|HTMLCanvasElemnet} nz
  9680. */
  9681. image: {
  9682. px: null,
  9683. nx: null,
  9684. py: null,
  9685. ny: null,
  9686. pz: null,
  9687. nz: null
  9688. },
  9689. /**
  9690. * Pixels data of each side. Will be ignored if images are set.
  9691. * @type {Object}
  9692. * @property {?Uint8Array} px
  9693. * @property {?Uint8Array} nx
  9694. * @property {?Uint8Array} py
  9695. * @property {?Uint8Array} ny
  9696. * @property {?Uint8Array} pz
  9697. * @property {?Uint8Array} nz
  9698. */
  9699. pixels: {
  9700. px: null,
  9701. nx: null,
  9702. py: null,
  9703. ny: null,
  9704. pz: null,
  9705. nz: null
  9706. },
  9707. /**
  9708. * @type {Array.<Object>}
  9709. */
  9710. mipmaps: []
  9711. };
  9712. }, {
  9713. textureType: 'textureCube',
  9714. update: function (renderer) {
  9715. var _gl = renderer.gl;
  9716. _gl.bindTexture(_gl.TEXTURE_CUBE_MAP, this._cache.get('webgl_texture'));
  9717. this.updateCommon(renderer);
  9718. var glFormat = this.format;
  9719. var glType = this.type;
  9720. _gl.texParameteri(_gl.TEXTURE_CUBE_MAP, _gl.TEXTURE_WRAP_S, this.getAvailableWrapS());
  9721. _gl.texParameteri(_gl.TEXTURE_CUBE_MAP, _gl.TEXTURE_WRAP_T, this.getAvailableWrapT());
  9722. _gl.texParameteri(_gl.TEXTURE_CUBE_MAP, _gl.TEXTURE_MAG_FILTER, this.getAvailableMagFilter());
  9723. _gl.texParameteri(_gl.TEXTURE_CUBE_MAP, _gl.TEXTURE_MIN_FILTER, this.getAvailableMinFilter());
  9724. var anisotropicExt = renderer.getGLExtension('EXT_texture_filter_anisotropic');
  9725. if (anisotropicExt && this.anisotropic > 1) {
  9726. _gl.texParameterf(_gl.TEXTURE_CUBE_MAP, anisotropicExt.TEXTURE_MAX_ANISOTROPY_EXT, this.anisotropic);
  9727. }
  9728. // Fallback to float type if browser don't have half float extension
  9729. if (glType === 36193) {
  9730. var halfFloatExt = renderer.getGLExtension('OES_texture_half_float');
  9731. if (!halfFloatExt) {
  9732. glType = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].FLOAT;
  9733. }
  9734. }
  9735. if (this.mipmaps.length) {
  9736. var width = this.width;
  9737. var height = this.height;
  9738. for (var i = 0; i < this.mipmaps.length; i++) {
  9739. var mipmap = this.mipmaps[i];
  9740. this._updateTextureData(_gl, mipmap, i, width, height, glFormat, glType);
  9741. width /= 2;
  9742. height /= 2;
  9743. }
  9744. }
  9745. else {
  9746. this._updateTextureData(_gl, this, 0, this.width, this.height, glFormat, glType);
  9747. if (!this.NPOT && this.useMipmap) {
  9748. _gl.generateMipmap(_gl.TEXTURE_CUBE_MAP);
  9749. }
  9750. }
  9751. _gl.bindTexture(_gl.TEXTURE_CUBE_MAP, null);
  9752. },
  9753. _updateTextureData: function (_gl, data, level, width, height, glFormat, glType) {
  9754. for (var i = 0; i < 6; i++) {
  9755. var target = targetList[i];
  9756. var img = data.image && data.image[target];
  9757. if (img) {
  9758. _gl.texImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, level, glFormat, glFormat, glType, img);
  9759. }
  9760. else {
  9761. _gl.texImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, level, glFormat, width, height, 0, glFormat, glType, data.pixels && data.pixels[target]);
  9762. }
  9763. }
  9764. },
  9765. /**
  9766. * @param {clay.Renderer} renderer
  9767. * @memberOf clay.TextureCube.prototype
  9768. */
  9769. generateMipmap: function (renderer) {
  9770. var _gl = renderer.gl;
  9771. if (this.useMipmap && !this.NPOT) {
  9772. _gl.bindTexture(_gl.TEXTURE_CUBE_MAP, this._cache.get('webgl_texture'));
  9773. _gl.generateMipmap(_gl.TEXTURE_CUBE_MAP);
  9774. }
  9775. },
  9776. bind: function (renderer) {
  9777. renderer.gl.bindTexture(renderer.gl.TEXTURE_CUBE_MAP, this.getWebGLTexture(renderer));
  9778. },
  9779. unbind: function (renderer) {
  9780. renderer.gl.bindTexture(renderer.gl.TEXTURE_CUBE_MAP, null);
  9781. },
  9782. // Overwrite the isPowerOfTwo method
  9783. isPowerOfTwo: function () {
  9784. if (this.image.px) {
  9785. return isPowerOfTwo(this.image.px.width)
  9786. && isPowerOfTwo(this.image.px.height);
  9787. }
  9788. else {
  9789. return isPowerOfTwo(this.width)
  9790. && isPowerOfTwo(this.height);
  9791. }
  9792. },
  9793. isRenderable: function () {
  9794. if (this.image.px) {
  9795. return isImageRenderable(this.image.px)
  9796. && isImageRenderable(this.image.nx)
  9797. && isImageRenderable(this.image.py)
  9798. && isImageRenderable(this.image.ny)
  9799. && isImageRenderable(this.image.pz)
  9800. && isImageRenderable(this.image.nz);
  9801. }
  9802. else {
  9803. return !!(this.width && this.height);
  9804. }
  9805. },
  9806. load: function (imageList, crossOrigin) {
  9807. var loading = 0;
  9808. var self = this;
  9809. __WEBPACK_IMPORTED_MODULE_2__core_util__["a" /* default */].each(imageList, function (src, target) {
  9810. var image = __WEBPACK_IMPORTED_MODULE_4__core_vendor__["a" /* default */].createImage();
  9811. if (crossOrigin) {
  9812. image.crossOrigin = crossOrigin;
  9813. }
  9814. image.onload = function () {
  9815. loading--;
  9816. if (loading === 0) {
  9817. self.dirty();
  9818. self.trigger('success', self);
  9819. }
  9820. image.onload = null;
  9821. };
  9822. image.onerror = function () {
  9823. loading--;
  9824. image.onerror = null;
  9825. };
  9826. loading++;
  9827. image.src = src;
  9828. self.image[target] = image;
  9829. });
  9830. return this;
  9831. }
  9832. });
  9833. Object.defineProperty(TextureCube.prototype, 'width', {
  9834. get: function () {
  9835. if (this.image && this.image.px) {
  9836. return this.image.px.width;
  9837. }
  9838. return this._width;
  9839. },
  9840. set: function (value) {
  9841. if (this.image && this.image.px) {
  9842. console.warn('Texture from image can\'t set width');
  9843. }
  9844. else {
  9845. if (this._width !== value) {
  9846. this.dirty();
  9847. }
  9848. this._width = value;
  9849. }
  9850. }
  9851. });
  9852. Object.defineProperty(TextureCube.prototype, 'height', {
  9853. get: function () {
  9854. if (this.image && this.image.px) {
  9855. return this.image.px.height;
  9856. }
  9857. return this._height;
  9858. },
  9859. set: function (value) {
  9860. if (this.image && this.image.px) {
  9861. console.warn('Texture from image can\'t set height');
  9862. }
  9863. else {
  9864. if (this._height !== value) {
  9865. this.dirty();
  9866. }
  9867. this._height = value;
  9868. }
  9869. }
  9870. });
  9871. function isImageRenderable(image) {
  9872. return image.nodeName === 'CANVAS' ||
  9873. image.nodeName === 'VIDEO' ||
  9874. image.complete;
  9875. }
  9876. /* harmony default export */ __webpack_exports__["a"] = (TextureCube);
  9877. /***/
  9878. }),
  9879. /* 28 */
  9880. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  9881. "use strict";
  9882. /* harmony default export */ __webpack_exports__["a"] = ({
  9883. defaultOption: {
  9884. // Post effect
  9885. postEffect: {
  9886. enable: false,
  9887. bloom: {
  9888. enable: true,
  9889. intensity: 0.1
  9890. },
  9891. depthOfField: {
  9892. enable: false,
  9893. focalRange: 20,
  9894. focalDistance: 50,
  9895. blurRadius: 10,
  9896. fstop: 2.8,
  9897. quality: 'medium'
  9898. },
  9899. screenSpaceAmbientOcclusion: {
  9900. enable: false,
  9901. radius: 2,
  9902. // low, medium, high, ultra
  9903. quality: 'medium',
  9904. intensity: 1
  9905. },
  9906. screenSpaceReflection: {
  9907. enable: false,
  9908. quality: 'medium',
  9909. maxRoughness: 0.8
  9910. },
  9911. colorCorrection: {
  9912. enable: true,
  9913. exposure: 0,
  9914. brightness: 0,
  9915. contrast: 1,
  9916. saturation: 1,
  9917. lookupTexture: ''
  9918. },
  9919. edge: {
  9920. enable: false
  9921. },
  9922. FXAA: {
  9923. enable: false
  9924. }
  9925. },
  9926. // Temporal super sampling when the picture is still.
  9927. temporalSuperSampling: {
  9928. // Only enabled when postEffect is enabled
  9929. enable: 'auto'
  9930. }
  9931. }
  9932. });
  9933. /***/
  9934. }),
  9935. /* 29 */
  9936. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  9937. "use strict";
  9938. /* harmony default export */ __webpack_exports__["a"] = ({
  9939. defaultOption: {
  9940. // Light is available when material.shading is not color
  9941. light: {
  9942. // Main light
  9943. main: {
  9944. shadow: false,
  9945. // low, medium, high, ultra
  9946. shadowQuality: 'high',
  9947. color: '#fff',
  9948. intensity: 1,
  9949. alpha: 0,
  9950. beta: 0
  9951. },
  9952. ambient: {
  9953. color: '#fff',
  9954. intensity: 0.2
  9955. },
  9956. ambientCubemap: {
  9957. // Panorama environment texture,
  9958. // Support .hdr and commmon web formats.
  9959. texture: null,
  9960. // Available when texture is hdr.
  9961. exposure: 1,
  9962. // Intensity for diffuse term
  9963. diffuseIntensity: 0.5,
  9964. // Intensity for specular term, only available when shading is realastic
  9965. specularIntensity: 0.5
  9966. }
  9967. }
  9968. }
  9969. });
  9970. /***/
  9971. }),
  9972. /* 30 */
  9973. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  9974. "use strict";
  9975. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__ = __webpack_require__(1);
  9976. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_plugin_Skybox__ = __webpack_require__(42);
  9977. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_echarts_lib_echarts__ = __webpack_require__(0);
  9978. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_echarts_lib_echarts__);
  9979. function SceneHelper() {
  9980. }
  9981. SceneHelper.prototype = {
  9982. constructor: SceneHelper,
  9983. setScene: function (scene) {
  9984. this._scene = scene;
  9985. if (this._skybox) {
  9986. this._skybox.attachScene(this._scene);
  9987. }
  9988. },
  9989. initLight: function (rootNode) {
  9990. this._lightRoot = rootNode;
  9991. /**
  9992. * @type {clay.light.Directional}
  9993. */
  9994. this.mainLight = new __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].DirectionalLight({
  9995. shadowBias: 0.005
  9996. });
  9997. /**
  9998. * @type {clay.light.Ambient}
  9999. */
  10000. this.ambientLight = new __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].AmbientLight();
  10001. rootNode.add(this.mainLight);
  10002. rootNode.add(this.ambientLight);
  10003. },
  10004. dispose: function () {
  10005. if (this._lightRoot) {
  10006. this._lightRoot.remove(this.mainLight);
  10007. this._lightRoot.remove(this.ambientLight);
  10008. }
  10009. },
  10010. updateLight: function (componentModel) {
  10011. var mainLight = this.mainLight;
  10012. var ambientLight = this.ambientLight;
  10013. var lightModel = componentModel.getModel('light');
  10014. var mainLightModel = lightModel.getModel('main');
  10015. var ambientLightModel = lightModel.getModel('ambient');
  10016. mainLight.intensity = mainLightModel.get('intensity');
  10017. ambientLight.intensity = ambientLightModel.get('intensity');
  10018. mainLight.color = __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].parseColor(mainLightModel.get('color')).slice(0, 3);
  10019. ambientLight.color = __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].parseColor(ambientLightModel.get('color')).slice(0, 3);
  10020. var alpha = mainLightModel.get('alpha') || 0;
  10021. var beta = mainLightModel.get('beta') || 0;
  10022. mainLight.position.setArray(__WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].directionFromAlphaBeta(alpha, beta));
  10023. mainLight.lookAt(__WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].Vector3.ZERO);
  10024. mainLight.castShadow = mainLightModel.get('shadow');
  10025. mainLight.shadowResolution = __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].getShadowResolution(mainLightModel.get('shadowQuality'));
  10026. },
  10027. updateAmbientCubemap: function (renderer, componentModel, api) {
  10028. var ambientCubemapModel = componentModel.getModel('light.ambientCubemap');
  10029. var textureUrl = ambientCubemapModel.get('texture');
  10030. if (textureUrl) {
  10031. this._cubemapLightsCache = this._cubemapLightsCache || {};
  10032. var lights = this._cubemapLightsCache[textureUrl];
  10033. if (!lights) {
  10034. var self = this;
  10035. lights = this._cubemapLightsCache[textureUrl]
  10036. = __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].createAmbientCubemap(ambientCubemapModel.option, renderer, api, function () {
  10037. // Use prefitered cubemap
  10038. if (self._isSkyboxFromAmbientCubemap) {
  10039. self._skybox.setEnvironmentMap(lights.specular.cubemap);
  10040. }
  10041. api.getZr().refresh();
  10042. });
  10043. }
  10044. this._lightRoot.add(lights.diffuse);
  10045. this._lightRoot.add(lights.specular);
  10046. this._currentCubemapLights = lights;
  10047. }
  10048. else if (this._currentCubemapLights) {
  10049. this._lightRoot.remove(this._currentCubemapLights.diffuse);
  10050. this._lightRoot.remove(this._currentCubemapLights.specular);
  10051. this._currentCubemapLights = null;
  10052. }
  10053. },
  10054. updateSkybox: function (renderer, componentModel, api) {
  10055. var environmentUrl = componentModel.get('environment');
  10056. var self = this;
  10057. function getSkybox() {
  10058. self._skybox = self._skybox || new __WEBPACK_IMPORTED_MODULE_1_claygl_src_plugin_Skybox__["a" /* default */]();
  10059. return self._skybox;
  10060. }
  10061. var skybox = getSkybox();
  10062. if (environmentUrl && environmentUrl !== 'none') {
  10063. if (environmentUrl === 'auto') {
  10064. this._isSkyboxFromAmbientCubemap = true;
  10065. // Use environment in ambient cubemap
  10066. if (this._currentCubemapLights) {
  10067. var cubemap = this._currentCubemapLights.specular.cubemap;
  10068. skybox.setEnvironmentMap(cubemap);
  10069. if (this._scene) {
  10070. skybox.attachScene(this._scene);
  10071. }
  10072. skybox.material.set('lod', 3);
  10073. }
  10074. else if (this._skybox) {
  10075. this._skybox.detachScene();
  10076. }
  10077. }
  10078. // Is gradient or color string
  10079. else if ((typeof environmentUrl === 'object' && environmentUrl.colorStops)
  10080. || (typeof environmentUrl === 'string' && __WEBPACK_IMPORTED_MODULE_2_echarts_lib_echarts___default.a.color.parse(environmentUrl))
  10081. ) {
  10082. this._isSkyboxFromAmbientCubemap = false;
  10083. var texture = new __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].Texture2D({
  10084. anisotropic: 8,
  10085. flipY: false
  10086. });
  10087. skybox.setEnvironmentMap(texture);
  10088. var canvas = texture.image = document.createElement('canvas');
  10089. canvas.width = canvas.height = 16;
  10090. var ctx = canvas.getContext('2d');
  10091. var rect = new __WEBPACK_IMPORTED_MODULE_2_echarts_lib_echarts___default.a.graphic.Rect({
  10092. shape: { x: 0, y: 0, width: 16, height: 16 },
  10093. style: { fill: environmentUrl }
  10094. });
  10095. rect.brush(ctx);
  10096. skybox.attachScene(this._scene);
  10097. }
  10098. else {
  10099. this._isSkyboxFromAmbientCubemap = false;
  10100. // Panorama
  10101. var texture = __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].loadTexture(environmentUrl, api, {
  10102. anisotropic: 8,
  10103. flipY: false
  10104. });
  10105. skybox.setEnvironmentMap(texture);
  10106. skybox.attachScene(this._scene);
  10107. }
  10108. }
  10109. else {
  10110. if (this._skybox) {
  10111. this._skybox.detachScene(this._scene);
  10112. }
  10113. this._skybox = null;
  10114. }
  10115. var coordSys = componentModel.coordinateSystem;
  10116. if (this._skybox) {
  10117. if (coordSys && coordSys.viewGL
  10118. && environmentUrl !== 'auto'
  10119. && !(environmentUrl.match && environmentUrl.match(/.hdr$/))
  10120. ) {
  10121. var srgbDefineMethod = coordSys.viewGL.isLinearSpace() ? 'define' : 'undefine';
  10122. this._skybox.material[srgbDefineMethod]('fragment', 'SRGB_DECODE');
  10123. }
  10124. else {
  10125. this._skybox.material.undefine('fragment', 'SRGB_DECODE');
  10126. }
  10127. // var ambientCubemapUrl = environmentUrl === 'auto'
  10128. // ? componentModel.get('light.ambientCubemap.texture')
  10129. // : environmentUrl;
  10130. }
  10131. }
  10132. };
  10133. /* harmony default export */ __webpack_exports__["a"] = (SceneHelper);
  10134. /***/
  10135. }),
  10136. /* 31 */
  10137. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  10138. "use strict";
  10139. /* harmony default export */ __webpack_exports__["a"] = ({
  10140. defaultOption: {
  10141. shading: null,
  10142. realisticMaterial: {
  10143. textureTiling: 1,
  10144. textureOffset: 0,
  10145. detailTexture: null
  10146. },
  10147. lambertMaterial: {
  10148. textureTiling: 1,
  10149. textureOffset: 0,
  10150. detailTexture: null
  10151. },
  10152. colorMaterial: {
  10153. textureTiling: 1,
  10154. textureOffset: 0,
  10155. detailTexture: null
  10156. },
  10157. hatchingMaterial: {
  10158. textureTiling: 1,
  10159. textureOffset: 0,
  10160. paperColor: '#fff'
  10161. }
  10162. }
  10163. });
  10164. /***/
  10165. }),
  10166. /* 32 */
  10167. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  10168. "use strict";
  10169. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  10170. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  10171. var formatUtil = {};
  10172. formatUtil.getFormattedLabel = function (seriesModel, dataIndex, status, dataType, dimIndex) {
  10173. status = status || 'normal';
  10174. var data = seriesModel.getData(dataType);
  10175. var itemModel = data.getItemModel(dataIndex);
  10176. var params = seriesModel.getDataParams(dataIndex, dataType);
  10177. if (dimIndex != null && (params.value instanceof Array)) {
  10178. params.value = params.value[dimIndex];
  10179. }
  10180. var formatter = itemModel.get(status === 'normal' ? ['label', 'formatter'] : ['emphasis', 'label', 'formatter']);
  10181. if (formatter == null) {
  10182. formatter = itemModel.get(['label', 'formatter']);
  10183. }
  10184. var text;
  10185. if (typeof formatter === 'function') {
  10186. params.status = status;
  10187. text = formatter(params);
  10188. }
  10189. else if (typeof formatter === 'string') {
  10190. text = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.format.formatTpl(formatter, params);
  10191. }
  10192. return text;
  10193. };
  10194. /**
  10195. * If value is not array, then convert it to array.
  10196. * @param {*} value
  10197. * @return {Array} [value] or value
  10198. */
  10199. formatUtil.normalizeToArray = function (value) {
  10200. return value instanceof Array
  10201. ? value
  10202. : value == null
  10203. ? []
  10204. : [value];
  10205. };
  10206. /* harmony default export */ __webpack_exports__["a"] = (formatUtil);
  10207. /***/
  10208. }),
  10209. /* 33 */
  10210. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  10211. "use strict";
  10212. /* unused harmony export vec4 */
  10213. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__common__ = __webpack_require__(20);
  10214. /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
  10215. Redistribution and use in source and binary forms, with or without modification,
  10216. are permitted provided that the following conditions are met:
  10217. * Redistributions of source code must retain the above copyright notice, this
  10218. list of conditions and the following disclaimer.
  10219. * Redistributions in binary form must reproduce the above copyright notice,
  10220. this list of conditions and the following disclaimer in the documentation
  10221. and/or other materials provided with the distribution.
  10222. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  10223. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  10224. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  10225. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  10226. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  10227. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  10228. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  10229. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  10230. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  10231. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
  10232. /**
  10233. * @class 4 Dimensional Vector
  10234. * @name vec4
  10235. */
  10236. var vec4 = {};
  10237. /**
  10238. * Creates a new, empty vec4
  10239. *
  10240. * @returns {vec4} a new 4D vector
  10241. */
  10242. vec4.create = function () {
  10243. var out = new __WEBPACK_IMPORTED_MODULE_0__common__["a" /* GLMAT_ARRAY_TYPE */](4);
  10244. out[0] = 0;
  10245. out[1] = 0;
  10246. out[2] = 0;
  10247. out[3] = 0;
  10248. return out;
  10249. };
  10250. /**
  10251. * Creates a new vec4 initialized with values from an existing vector
  10252. *
  10253. * @param {vec4} a vector to clone
  10254. * @returns {vec4} a new 4D vector
  10255. */
  10256. vec4.clone = function (a) {
  10257. var out = new __WEBPACK_IMPORTED_MODULE_0__common__["a" /* GLMAT_ARRAY_TYPE */](4);
  10258. out[0] = a[0];
  10259. out[1] = a[1];
  10260. out[2] = a[2];
  10261. out[3] = a[3];
  10262. return out;
  10263. };
  10264. /**
  10265. * Creates a new vec4 initialized with the given values
  10266. *
  10267. * @param {Number} x X component
  10268. * @param {Number} y Y component
  10269. * @param {Number} z Z component
  10270. * @param {Number} w W component
  10271. * @returns {vec4} a new 4D vector
  10272. */
  10273. vec4.fromValues = function (x, y, z, w) {
  10274. var out = new __WEBPACK_IMPORTED_MODULE_0__common__["a" /* GLMAT_ARRAY_TYPE */](4);
  10275. out[0] = x;
  10276. out[1] = y;
  10277. out[2] = z;
  10278. out[3] = w;
  10279. return out;
  10280. };
  10281. /**
  10282. * Copy the values from one vec4 to another
  10283. *
  10284. * @param {vec4} out the receiving vector
  10285. * @param {vec4} a the source vector
  10286. * @returns {vec4} out
  10287. */
  10288. vec4.copy = function (out, a) {
  10289. out[0] = a[0];
  10290. out[1] = a[1];
  10291. out[2] = a[2];
  10292. out[3] = a[3];
  10293. return out;
  10294. };
  10295. /**
  10296. * Set the components of a vec4 to the given values
  10297. *
  10298. * @param {vec4} out the receiving vector
  10299. * @param {Number} x X component
  10300. * @param {Number} y Y component
  10301. * @param {Number} z Z component
  10302. * @param {Number} w W component
  10303. * @returns {vec4} out
  10304. */
  10305. vec4.set = function (out, x, y, z, w) {
  10306. out[0] = x;
  10307. out[1] = y;
  10308. out[2] = z;
  10309. out[3] = w;
  10310. return out;
  10311. };
  10312. /**
  10313. * Adds two vec4's
  10314. *
  10315. * @param {vec4} out the receiving vector
  10316. * @param {vec4} a the first operand
  10317. * @param {vec4} b the second operand
  10318. * @returns {vec4} out
  10319. */
  10320. vec4.add = function (out, a, b) {
  10321. out[0] = a[0] + b[0];
  10322. out[1] = a[1] + b[1];
  10323. out[2] = a[2] + b[2];
  10324. out[3] = a[3] + b[3];
  10325. return out;
  10326. };
  10327. /**
  10328. * Subtracts vector b from vector a
  10329. *
  10330. * @param {vec4} out the receiving vector
  10331. * @param {vec4} a the first operand
  10332. * @param {vec4} b the second operand
  10333. * @returns {vec4} out
  10334. */
  10335. vec4.subtract = function (out, a, b) {
  10336. out[0] = a[0] - b[0];
  10337. out[1] = a[1] - b[1];
  10338. out[2] = a[2] - b[2];
  10339. out[3] = a[3] - b[3];
  10340. return out;
  10341. };
  10342. /**
  10343. * Alias for {@link vec4.subtract}
  10344. * @function
  10345. */
  10346. vec4.sub = vec4.subtract;
  10347. /**
  10348. * Multiplies two vec4's
  10349. *
  10350. * @param {vec4} out the receiving vector
  10351. * @param {vec4} a the first operand
  10352. * @param {vec4} b the second operand
  10353. * @returns {vec4} out
  10354. */
  10355. vec4.multiply = function (out, a, b) {
  10356. out[0] = a[0] * b[0];
  10357. out[1] = a[1] * b[1];
  10358. out[2] = a[2] * b[2];
  10359. out[3] = a[3] * b[3];
  10360. return out;
  10361. };
  10362. /**
  10363. * Alias for {@link vec4.multiply}
  10364. * @function
  10365. */
  10366. vec4.mul = vec4.multiply;
  10367. /**
  10368. * Divides two vec4's
  10369. *
  10370. * @param {vec4} out the receiving vector
  10371. * @param {vec4} a the first operand
  10372. * @param {vec4} b the second operand
  10373. * @returns {vec4} out
  10374. */
  10375. vec4.divide = function (out, a, b) {
  10376. out[0] = a[0] / b[0];
  10377. out[1] = a[1] / b[1];
  10378. out[2] = a[2] / b[2];
  10379. out[3] = a[3] / b[3];
  10380. return out;
  10381. };
  10382. /**
  10383. * Alias for {@link vec4.divide}
  10384. * @function
  10385. */
  10386. vec4.div = vec4.divide;
  10387. /**
  10388. * Returns the minimum of two vec4's
  10389. *
  10390. * @param {vec4} out the receiving vector
  10391. * @param {vec4} a the first operand
  10392. * @param {vec4} b the second operand
  10393. * @returns {vec4} out
  10394. */
  10395. vec4.min = function (out, a, b) {
  10396. out[0] = Math.min(a[0], b[0]);
  10397. out[1] = Math.min(a[1], b[1]);
  10398. out[2] = Math.min(a[2], b[2]);
  10399. out[3] = Math.min(a[3], b[3]);
  10400. return out;
  10401. };
  10402. /**
  10403. * Returns the maximum of two vec4's
  10404. *
  10405. * @param {vec4} out the receiving vector
  10406. * @param {vec4} a the first operand
  10407. * @param {vec4} b the second operand
  10408. * @returns {vec4} out
  10409. */
  10410. vec4.max = function (out, a, b) {
  10411. out[0] = Math.max(a[0], b[0]);
  10412. out[1] = Math.max(a[1], b[1]);
  10413. out[2] = Math.max(a[2], b[2]);
  10414. out[3] = Math.max(a[3], b[3]);
  10415. return out;
  10416. };
  10417. /**
  10418. * Scales a vec4 by a scalar number
  10419. *
  10420. * @param {vec4} out the receiving vector
  10421. * @param {vec4} a the vector to scale
  10422. * @param {Number} b amount to scale the vector by
  10423. * @returns {vec4} out
  10424. */
  10425. vec4.scale = function (out, a, b) {
  10426. out[0] = a[0] * b;
  10427. out[1] = a[1] * b;
  10428. out[2] = a[2] * b;
  10429. out[3] = a[3] * b;
  10430. return out;
  10431. };
  10432. /**
  10433. * Adds two vec4's after scaling the second operand by a scalar value
  10434. *
  10435. * @param {vec4} out the receiving vector
  10436. * @param {vec4} a the first operand
  10437. * @param {vec4} b the second operand
  10438. * @param {Number} scale the amount to scale b by before adding
  10439. * @returns {vec4} out
  10440. */
  10441. vec4.scaleAndAdd = function (out, a, b, scale) {
  10442. out[0] = a[0] + (b[0] * scale);
  10443. out[1] = a[1] + (b[1] * scale);
  10444. out[2] = a[2] + (b[2] * scale);
  10445. out[3] = a[3] + (b[3] * scale);
  10446. return out;
  10447. };
  10448. /**
  10449. * Calculates the euclidian distance between two vec4's
  10450. *
  10451. * @param {vec4} a the first operand
  10452. * @param {vec4} b the second operand
  10453. * @returns {Number} distance between a and b
  10454. */
  10455. vec4.distance = function (a, b) {
  10456. var x = b[0] - a[0],
  10457. y = b[1] - a[1],
  10458. z = b[2] - a[2],
  10459. w = b[3] - a[3];
  10460. return Math.sqrt(x * x + y * y + z * z + w * w);
  10461. };
  10462. /**
  10463. * Alias for {@link vec4.distance}
  10464. * @function
  10465. */
  10466. vec4.dist = vec4.distance;
  10467. /**
  10468. * Calculates the squared euclidian distance between two vec4's
  10469. *
  10470. * @param {vec4} a the first operand
  10471. * @param {vec4} b the second operand
  10472. * @returns {Number} squared distance between a and b
  10473. */
  10474. vec4.squaredDistance = function (a, b) {
  10475. var x = b[0] - a[0],
  10476. y = b[1] - a[1],
  10477. z = b[2] - a[2],
  10478. w = b[3] - a[3];
  10479. return x * x + y * y + z * z + w * w;
  10480. };
  10481. /**
  10482. * Alias for {@link vec4.squaredDistance}
  10483. * @function
  10484. */
  10485. vec4.sqrDist = vec4.squaredDistance;
  10486. /**
  10487. * Calculates the length of a vec4
  10488. *
  10489. * @param {vec4} a vector to calculate length of
  10490. * @returns {Number} length of a
  10491. */
  10492. vec4.length = function (a) {
  10493. var x = a[0],
  10494. y = a[1],
  10495. z = a[2],
  10496. w = a[3];
  10497. return Math.sqrt(x * x + y * y + z * z + w * w);
  10498. };
  10499. /**
  10500. * Alias for {@link vec4.length}
  10501. * @function
  10502. */
  10503. vec4.len = vec4.length;
  10504. /**
  10505. * Calculates the squared length of a vec4
  10506. *
  10507. * @param {vec4} a vector to calculate squared length of
  10508. * @returns {Number} squared length of a
  10509. */
  10510. vec4.squaredLength = function (a) {
  10511. var x = a[0],
  10512. y = a[1],
  10513. z = a[2],
  10514. w = a[3];
  10515. return x * x + y * y + z * z + w * w;
  10516. };
  10517. /**
  10518. * Alias for {@link vec4.squaredLength}
  10519. * @function
  10520. */
  10521. vec4.sqrLen = vec4.squaredLength;
  10522. /**
  10523. * Negates the components of a vec4
  10524. *
  10525. * @param {vec4} out the receiving vector
  10526. * @param {vec4} a vector to negate
  10527. * @returns {vec4} out
  10528. */
  10529. vec4.negate = function (out, a) {
  10530. out[0] = -a[0];
  10531. out[1] = -a[1];
  10532. out[2] = -a[2];
  10533. out[3] = -a[3];
  10534. return out;
  10535. };
  10536. /**
  10537. * Returns the inverse of the components of a vec4
  10538. *
  10539. * @param {vec4} out the receiving vector
  10540. * @param {vec4} a vector to invert
  10541. * @returns {vec4} out
  10542. */
  10543. vec4.inverse = function (out, a) {
  10544. out[0] = 1.0 / a[0];
  10545. out[1] = 1.0 / a[1];
  10546. out[2] = 1.0 / a[2];
  10547. out[3] = 1.0 / a[3];
  10548. return out;
  10549. };
  10550. /**
  10551. * Normalize a vec4
  10552. *
  10553. * @param {vec4} out the receiving vector
  10554. * @param {vec4} a vector to normalize
  10555. * @returns {vec4} out
  10556. */
  10557. vec4.normalize = function (out, a) {
  10558. var x = a[0],
  10559. y = a[1],
  10560. z = a[2],
  10561. w = a[3];
  10562. var len = x * x + y * y + z * z + w * w;
  10563. if (len > 0) {
  10564. len = 1 / Math.sqrt(len);
  10565. out[0] = a[0] * len;
  10566. out[1] = a[1] * len;
  10567. out[2] = a[2] * len;
  10568. out[3] = a[3] * len;
  10569. }
  10570. return out;
  10571. };
  10572. /**
  10573. * Calculates the dot product of two vec4's
  10574. *
  10575. * @param {vec4} a the first operand
  10576. * @param {vec4} b the second operand
  10577. * @returns {Number} dot product of a and b
  10578. */
  10579. vec4.dot = function (a, b) {
  10580. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
  10581. };
  10582. /**
  10583. * Performs a linear interpolation between two vec4's
  10584. *
  10585. * @param {vec4} out the receiving vector
  10586. * @param {vec4} a the first operand
  10587. * @param {vec4} b the second operand
  10588. * @param {Number} t interpolation amount between the two inputs
  10589. * @returns {vec4} out
  10590. */
  10591. vec4.lerp = function (out, a, b, t) {
  10592. var ax = a[0],
  10593. ay = a[1],
  10594. az = a[2],
  10595. aw = a[3];
  10596. out[0] = ax + t * (b[0] - ax);
  10597. out[1] = ay + t * (b[1] - ay);
  10598. out[2] = az + t * (b[2] - az);
  10599. out[3] = aw + t * (b[3] - aw);
  10600. return out;
  10601. };
  10602. /**
  10603. * Generates a random vector with the given scale
  10604. *
  10605. * @param {vec4} out the receiving vector
  10606. * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned
  10607. * @returns {vec4} out
  10608. */
  10609. vec4.random = function (out, scale) {
  10610. scale = scale || 1.0;
  10611. //TODO: This is a pretty awful way of doing this. Find something better.
  10612. out[0] = Object(__WEBPACK_IMPORTED_MODULE_0__common__["c" /* GLMAT_RANDOM */])();
  10613. out[1] = Object(__WEBPACK_IMPORTED_MODULE_0__common__["c" /* GLMAT_RANDOM */])();
  10614. out[2] = Object(__WEBPACK_IMPORTED_MODULE_0__common__["c" /* GLMAT_RANDOM */])();
  10615. out[3] = Object(__WEBPACK_IMPORTED_MODULE_0__common__["c" /* GLMAT_RANDOM */])();
  10616. vec4.normalize(out, out);
  10617. vec4.scale(out, out, scale);
  10618. return out;
  10619. };
  10620. /**
  10621. * Transforms the vec4 with a mat4.
  10622. *
  10623. * @param {vec4} out the receiving vector
  10624. * @param {vec4} a the vector to transform
  10625. * @param {mat4} m matrix to transform with
  10626. * @returns {vec4} out
  10627. */
  10628. vec4.transformMat4 = function (out, a, m) {
  10629. var x = a[0], y = a[1], z = a[2], w = a[3];
  10630. out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
  10631. out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;
  10632. out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;
  10633. out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;
  10634. return out;
  10635. };
  10636. /**
  10637. * Transforms the vec4 with a quat
  10638. *
  10639. * @param {vec4} out the receiving vector
  10640. * @param {vec4} a the vector to transform
  10641. * @param {quat} q quaternion to transform with
  10642. * @returns {vec4} out
  10643. */
  10644. vec4.transformQuat = function (out, a, q) {
  10645. var x = a[0], y = a[1], z = a[2],
  10646. qx = q[0], qy = q[1], qz = q[2], qw = q[3],
  10647. // calculate quat * vec
  10648. ix = qw * x + qy * z - qz * y,
  10649. iy = qw * y + qz * x - qx * z,
  10650. iz = qw * z + qx * y - qy * x,
  10651. iw = -qx * x - qy * y - qz * z;
  10652. // calculate result * inverse quat
  10653. out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  10654. out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  10655. out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  10656. return out;
  10657. };
  10658. /**
  10659. * Perform some operation over an array of vec4s.
  10660. *
  10661. * @param {Array} a the array of vectors to iterate over
  10662. * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed
  10663. * @param {Number} offset Number of elements to skip at the beginning of the array
  10664. * @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array
  10665. * @param {Function} fn Function to call for each vector in the array
  10666. * @param {Object} [arg] additional argument to pass to fn
  10667. * @returns {Array} a
  10668. * @function
  10669. */
  10670. vec4.forEach = (function () {
  10671. var vec = vec4.create();
  10672. return function (a, stride, offset, count, fn, arg) {
  10673. var i, l;
  10674. if (!stride) {
  10675. stride = 4;
  10676. }
  10677. if (!offset) {
  10678. offset = 0;
  10679. }
  10680. if (count) {
  10681. l = Math.min((count * stride) + offset, a.length);
  10682. } else {
  10683. l = a.length;
  10684. }
  10685. for (i = offset; i < l; i += stride) {
  10686. vec[0] = a[i]; vec[1] = a[i + 1]; vec[2] = a[i + 2]; vec[3] = a[i + 3];
  10687. fn(vec, vec, arg);
  10688. a[i] = vec[0]; a[i + 1] = vec[1]; a[i + 2] = vec[2]; a[i + 3] = vec[3];
  10689. }
  10690. return a;
  10691. };
  10692. })();
  10693. /* harmony default export */ __webpack_exports__["a"] = (vec4);
  10694. /***/
  10695. }),
  10696. /* 34 */
  10697. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  10698. "use strict";
  10699. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__common__ = __webpack_require__(20);
  10700. /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
  10701. Redistribution and use in source and binary forms, with or without modification,
  10702. are permitted provided that the following conditions are met:
  10703. * Redistributions of source code must retain the above copyright notice, this
  10704. list of conditions and the following disclaimer.
  10705. * Redistributions in binary form must reproduce the above copyright notice,
  10706. this list of conditions and the following disclaimer in the documentation
  10707. and/or other materials provided with the distribution.
  10708. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  10709. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  10710. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  10711. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  10712. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  10713. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  10714. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  10715. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  10716. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  10717. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
  10718. /**
  10719. * @class 3x3 Matrix
  10720. * @name mat3
  10721. */
  10722. var mat3 = {};
  10723. /**
  10724. * Creates a new identity mat3
  10725. *
  10726. * @returns {mat3} a new 3x3 matrix
  10727. */
  10728. mat3.create = function () {
  10729. var out = new __WEBPACK_IMPORTED_MODULE_0__common__["a" /* GLMAT_ARRAY_TYPE */](9);
  10730. out[0] = 1;
  10731. out[1] = 0;
  10732. out[2] = 0;
  10733. out[3] = 0;
  10734. out[4] = 1;
  10735. out[5] = 0;
  10736. out[6] = 0;
  10737. out[7] = 0;
  10738. out[8] = 1;
  10739. return out;
  10740. };
  10741. /**
  10742. * Copies the upper-left 3x3 values into the given mat3.
  10743. *
  10744. * @param {mat3} out the receiving 3x3 matrix
  10745. * @param {mat4} a the source 4x4 matrix
  10746. * @returns {mat3} out
  10747. */
  10748. mat3.fromMat4 = function (out, a) {
  10749. out[0] = a[0];
  10750. out[1] = a[1];
  10751. out[2] = a[2];
  10752. out[3] = a[4];
  10753. out[4] = a[5];
  10754. out[5] = a[6];
  10755. out[6] = a[8];
  10756. out[7] = a[9];
  10757. out[8] = a[10];
  10758. return out;
  10759. };
  10760. /**
  10761. * Creates a new mat3 initialized with values from an existing matrix
  10762. *
  10763. * @param {mat3} a matrix to clone
  10764. * @returns {mat3} a new 3x3 matrix
  10765. */
  10766. mat3.clone = function (a) {
  10767. var out = new __WEBPACK_IMPORTED_MODULE_0__common__["a" /* GLMAT_ARRAY_TYPE */](9);
  10768. out[0] = a[0];
  10769. out[1] = a[1];
  10770. out[2] = a[2];
  10771. out[3] = a[3];
  10772. out[4] = a[4];
  10773. out[5] = a[5];
  10774. out[6] = a[6];
  10775. out[7] = a[7];
  10776. out[8] = a[8];
  10777. return out;
  10778. };
  10779. /**
  10780. * Copy the values from one mat3 to another
  10781. *
  10782. * @param {mat3} out the receiving matrix
  10783. * @param {mat3} a the source matrix
  10784. * @returns {mat3} out
  10785. */
  10786. mat3.copy = function (out, a) {
  10787. out[0] = a[0];
  10788. out[1] = a[1];
  10789. out[2] = a[2];
  10790. out[3] = a[3];
  10791. out[4] = a[4];
  10792. out[5] = a[5];
  10793. out[6] = a[6];
  10794. out[7] = a[7];
  10795. out[8] = a[8];
  10796. return out;
  10797. };
  10798. /**
  10799. * Set a mat3 to the identity matrix
  10800. *
  10801. * @param {mat3} out the receiving matrix
  10802. * @returns {mat3} out
  10803. */
  10804. mat3.identity = function (out) {
  10805. out[0] = 1;
  10806. out[1] = 0;
  10807. out[2] = 0;
  10808. out[3] = 0;
  10809. out[4] = 1;
  10810. out[5] = 0;
  10811. out[6] = 0;
  10812. out[7] = 0;
  10813. out[8] = 1;
  10814. return out;
  10815. };
  10816. /**
  10817. * Transpose the values of a mat3
  10818. *
  10819. * @param {mat3} out the receiving matrix
  10820. * @param {mat3} a the source matrix
  10821. * @returns {mat3} out
  10822. */
  10823. mat3.transpose = function (out, a) {
  10824. // If we are transposing ourselves we can skip a few steps but have to cache some values
  10825. if (out === a) {
  10826. var a01 = a[1], a02 = a[2], a12 = a[5];
  10827. out[1] = a[3];
  10828. out[2] = a[6];
  10829. out[3] = a01;
  10830. out[5] = a[7];
  10831. out[6] = a02;
  10832. out[7] = a12;
  10833. } else {
  10834. out[0] = a[0];
  10835. out[1] = a[3];
  10836. out[2] = a[6];
  10837. out[3] = a[1];
  10838. out[4] = a[4];
  10839. out[5] = a[7];
  10840. out[6] = a[2];
  10841. out[7] = a[5];
  10842. out[8] = a[8];
  10843. }
  10844. return out;
  10845. };
  10846. /**
  10847. * Inverts a mat3
  10848. *
  10849. * @param {mat3} out the receiving matrix
  10850. * @param {mat3} a the source matrix
  10851. * @returns {mat3} out
  10852. */
  10853. mat3.invert = function (out, a) {
  10854. var a00 = a[0], a01 = a[1], a02 = a[2],
  10855. a10 = a[3], a11 = a[4], a12 = a[5],
  10856. a20 = a[6], a21 = a[7], a22 = a[8],
  10857. b01 = a22 * a11 - a12 * a21,
  10858. b11 = -a22 * a10 + a12 * a20,
  10859. b21 = a21 * a10 - a11 * a20,
  10860. // Calculate the determinant
  10861. det = a00 * b01 + a01 * b11 + a02 * b21;
  10862. if (!det) {
  10863. return null;
  10864. }
  10865. det = 1.0 / det;
  10866. out[0] = b01 * det;
  10867. out[1] = (-a22 * a01 + a02 * a21) * det;
  10868. out[2] = (a12 * a01 - a02 * a11) * det;
  10869. out[3] = b11 * det;
  10870. out[4] = (a22 * a00 - a02 * a20) * det;
  10871. out[5] = (-a12 * a00 + a02 * a10) * det;
  10872. out[6] = b21 * det;
  10873. out[7] = (-a21 * a00 + a01 * a20) * det;
  10874. out[8] = (a11 * a00 - a01 * a10) * det;
  10875. return out;
  10876. };
  10877. /**
  10878. * Calculates the adjugate of a mat3
  10879. *
  10880. * @param {mat3} out the receiving matrix
  10881. * @param {mat3} a the source matrix
  10882. * @returns {mat3} out
  10883. */
  10884. mat3.adjoint = function (out, a) {
  10885. var a00 = a[0], a01 = a[1], a02 = a[2],
  10886. a10 = a[3], a11 = a[4], a12 = a[5],
  10887. a20 = a[6], a21 = a[7], a22 = a[8];
  10888. out[0] = (a11 * a22 - a12 * a21);
  10889. out[1] = (a02 * a21 - a01 * a22);
  10890. out[2] = (a01 * a12 - a02 * a11);
  10891. out[3] = (a12 * a20 - a10 * a22);
  10892. out[4] = (a00 * a22 - a02 * a20);
  10893. out[5] = (a02 * a10 - a00 * a12);
  10894. out[6] = (a10 * a21 - a11 * a20);
  10895. out[7] = (a01 * a20 - a00 * a21);
  10896. out[8] = (a00 * a11 - a01 * a10);
  10897. return out;
  10898. };
  10899. /**
  10900. * Calculates the determinant of a mat3
  10901. *
  10902. * @param {mat3} a the source matrix
  10903. * @returns {Number} determinant of a
  10904. */
  10905. mat3.determinant = function (a) {
  10906. var a00 = a[0], a01 = a[1], a02 = a[2],
  10907. a10 = a[3], a11 = a[4], a12 = a[5],
  10908. a20 = a[6], a21 = a[7], a22 = a[8];
  10909. return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);
  10910. };
  10911. /**
  10912. * Multiplies two mat3's
  10913. *
  10914. * @param {mat3} out the receiving matrix
  10915. * @param {mat3} a the first operand
  10916. * @param {mat3} b the second operand
  10917. * @returns {mat3} out
  10918. */
  10919. mat3.multiply = function (out, a, b) {
  10920. var a00 = a[0], a01 = a[1], a02 = a[2],
  10921. a10 = a[3], a11 = a[4], a12 = a[5],
  10922. a20 = a[6], a21 = a[7], a22 = a[8],
  10923. b00 = b[0], b01 = b[1], b02 = b[2],
  10924. b10 = b[3], b11 = b[4], b12 = b[5],
  10925. b20 = b[6], b21 = b[7], b22 = b[8];
  10926. out[0] = b00 * a00 + b01 * a10 + b02 * a20;
  10927. out[1] = b00 * a01 + b01 * a11 + b02 * a21;
  10928. out[2] = b00 * a02 + b01 * a12 + b02 * a22;
  10929. out[3] = b10 * a00 + b11 * a10 + b12 * a20;
  10930. out[4] = b10 * a01 + b11 * a11 + b12 * a21;
  10931. out[5] = b10 * a02 + b11 * a12 + b12 * a22;
  10932. out[6] = b20 * a00 + b21 * a10 + b22 * a20;
  10933. out[7] = b20 * a01 + b21 * a11 + b22 * a21;
  10934. out[8] = b20 * a02 + b21 * a12 + b22 * a22;
  10935. return out;
  10936. };
  10937. /**
  10938. * Alias for {@link mat3.multiply}
  10939. * @function
  10940. */
  10941. mat3.mul = mat3.multiply;
  10942. /**
  10943. * Translate a mat3 by the given vector
  10944. *
  10945. * @param {mat3} out the receiving matrix
  10946. * @param {mat3} a the matrix to translate
  10947. * @param {vec2} v vector to translate by
  10948. * @returns {mat3} out
  10949. */
  10950. mat3.translate = function (out, a, v) {
  10951. var a00 = a[0], a01 = a[1], a02 = a[2],
  10952. a10 = a[3], a11 = a[4], a12 = a[5],
  10953. a20 = a[6], a21 = a[7], a22 = a[8],
  10954. x = v[0], y = v[1];
  10955. out[0] = a00;
  10956. out[1] = a01;
  10957. out[2] = a02;
  10958. out[3] = a10;
  10959. out[4] = a11;
  10960. out[5] = a12;
  10961. out[6] = x * a00 + y * a10 + a20;
  10962. out[7] = x * a01 + y * a11 + a21;
  10963. out[8] = x * a02 + y * a12 + a22;
  10964. return out;
  10965. };
  10966. /**
  10967. * Rotates a mat3 by the given angle
  10968. *
  10969. * @param {mat3} out the receiving matrix
  10970. * @param {mat3} a the matrix to rotate
  10971. * @param {Number} rad the angle to rotate the matrix by
  10972. * @returns {mat3} out
  10973. */
  10974. mat3.rotate = function (out, a, rad) {
  10975. var a00 = a[0], a01 = a[1], a02 = a[2],
  10976. a10 = a[3], a11 = a[4], a12 = a[5],
  10977. a20 = a[6], a21 = a[7], a22 = a[8],
  10978. s = Math.sin(rad),
  10979. c = Math.cos(rad);
  10980. out[0] = c * a00 + s * a10;
  10981. out[1] = c * a01 + s * a11;
  10982. out[2] = c * a02 + s * a12;
  10983. out[3] = c * a10 - s * a00;
  10984. out[4] = c * a11 - s * a01;
  10985. out[5] = c * a12 - s * a02;
  10986. out[6] = a20;
  10987. out[7] = a21;
  10988. out[8] = a22;
  10989. return out;
  10990. };
  10991. /**
  10992. * Scales the mat3 by the dimensions in the given vec2
  10993. *
  10994. * @param {mat3} out the receiving matrix
  10995. * @param {mat3} a the matrix to rotate
  10996. * @param {vec2} v the vec2 to scale the matrix by
  10997. * @returns {mat3} out
  10998. **/
  10999. mat3.scale = function (out, a, v) {
  11000. var x = v[0], y = v[1];
  11001. out[0] = x * a[0];
  11002. out[1] = x * a[1];
  11003. out[2] = x * a[2];
  11004. out[3] = y * a[3];
  11005. out[4] = y * a[4];
  11006. out[5] = y * a[5];
  11007. out[6] = a[6];
  11008. out[7] = a[7];
  11009. out[8] = a[8];
  11010. return out;
  11011. };
  11012. /**
  11013. * Copies the values from a mat2d into a mat3
  11014. *
  11015. * @param {mat3} out the receiving matrix
  11016. * @param {mat2d} a the matrix to copy
  11017. * @returns {mat3} out
  11018. **/
  11019. mat3.fromMat2d = function (out, a) {
  11020. out[0] = a[0];
  11021. out[1] = a[1];
  11022. out[2] = 0;
  11023. out[3] = a[2];
  11024. out[4] = a[3];
  11025. out[5] = 0;
  11026. out[6] = a[4];
  11027. out[7] = a[5];
  11028. out[8] = 1;
  11029. return out;
  11030. };
  11031. /**
  11032. * Calculates a 3x3 matrix from the given quaternion
  11033. *
  11034. * @param {mat3} out mat3 receiving operation result
  11035. * @param {quat} q Quaternion to create matrix from
  11036. *
  11037. * @returns {mat3} out
  11038. */
  11039. mat3.fromQuat = function (out, q) {
  11040. var x = q[0], y = q[1], z = q[2], w = q[3],
  11041. x2 = x + x,
  11042. y2 = y + y,
  11043. z2 = z + z,
  11044. xx = x * x2,
  11045. yx = y * x2,
  11046. yy = y * y2,
  11047. zx = z * x2,
  11048. zy = z * y2,
  11049. zz = z * z2,
  11050. wx = w * x2,
  11051. wy = w * y2,
  11052. wz = w * z2;
  11053. out[0] = 1 - yy - zz;
  11054. out[3] = yx - wz;
  11055. out[6] = zx + wy;
  11056. out[1] = yx + wz;
  11057. out[4] = 1 - xx - zz;
  11058. out[7] = zy - wx;
  11059. out[2] = zx - wy;
  11060. out[5] = zy + wx;
  11061. out[8] = 1 - xx - yy;
  11062. return out;
  11063. };
  11064. /**
  11065. * Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix
  11066. *
  11067. * @param {mat3} out mat3 receiving operation result
  11068. * @param {mat4} a Mat4 to derive the normal matrix from
  11069. *
  11070. * @returns {mat3} out
  11071. */
  11072. mat3.normalFromMat4 = function (out, a) {
  11073. var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
  11074. a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
  11075. a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
  11076. a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],
  11077. b00 = a00 * a11 - a01 * a10,
  11078. b01 = a00 * a12 - a02 * a10,
  11079. b02 = a00 * a13 - a03 * a10,
  11080. b03 = a01 * a12 - a02 * a11,
  11081. b04 = a01 * a13 - a03 * a11,
  11082. b05 = a02 * a13 - a03 * a12,
  11083. b06 = a20 * a31 - a21 * a30,
  11084. b07 = a20 * a32 - a22 * a30,
  11085. b08 = a20 * a33 - a23 * a30,
  11086. b09 = a21 * a32 - a22 * a31,
  11087. b10 = a21 * a33 - a23 * a31,
  11088. b11 = a22 * a33 - a23 * a32,
  11089. // Calculate the determinant
  11090. det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
  11091. if (!det) {
  11092. return null;
  11093. }
  11094. det = 1.0 / det;
  11095. out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
  11096. out[1] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
  11097. out[2] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
  11098. out[3] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
  11099. out[4] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
  11100. out[5] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
  11101. out[6] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
  11102. out[7] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
  11103. out[8] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
  11104. return out;
  11105. };
  11106. /**
  11107. * Returns Frobenius norm of a mat3
  11108. *
  11109. * @param {mat3} a the matrix to calculate Frobenius norm of
  11110. * @returns {Number} Frobenius norm
  11111. */
  11112. mat3.frob = function (a) {
  11113. return (Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2)))
  11114. };
  11115. /* harmony default export */ __webpack_exports__["a"] = (mat3);
  11116. /***/
  11117. }),
  11118. /* 35 */
  11119. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  11120. "use strict";
  11121. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__core_Base__ = __webpack_require__(7);
  11122. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__math_Vector3__ = __webpack_require__(3);
  11123. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__math_Quaternion__ = __webpack_require__(56);
  11124. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__math_Matrix4__ = __webpack_require__(9);
  11125. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__glmatrix_mat4__ = __webpack_require__(21);
  11126. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__math_BoundingBox__ = __webpack_require__(18);
  11127. var nameId = 0;
  11128. /**
  11129. * @constructor clay.Node
  11130. * @extends clay.core.Base
  11131. */
  11132. var Node = __WEBPACK_IMPORTED_MODULE_0__core_Base__["a" /* default */].extend(/** @lends clay.Node# */{
  11133. /**
  11134. * Scene node name
  11135. * @type {string}
  11136. */
  11137. name: '',
  11138. /**
  11139. * Position relative to its parent node. aka translation.
  11140. * @type {clay.Vector3}
  11141. */
  11142. position: null,
  11143. /**
  11144. * Rotation relative to its parent node. Represented by a quaternion
  11145. * @type {clay.Quaternion}
  11146. */
  11147. rotation: null,
  11148. /**
  11149. * Scale relative to its parent node
  11150. * @type {clay.Vector3}
  11151. */
  11152. scale: null,
  11153. /**
  11154. * Affine transform matrix relative to its root scene.
  11155. * @type {clay.Matrix4}
  11156. */
  11157. worldTransform: null,
  11158. /**
  11159. * Affine transform matrix relative to its parent node.
  11160. * Composited with position, rotation and scale.
  11161. * @type {clay.Matrix4}
  11162. */
  11163. localTransform: null,
  11164. /**
  11165. * If the local transform is update from SRT(scale, rotation, translation, which is position here) each frame
  11166. * @type {boolean}
  11167. */
  11168. autoUpdateLocalTransform: true,
  11169. /**
  11170. * Parent of current scene node
  11171. * @type {?clay.Node}
  11172. * @private
  11173. */
  11174. _parent: null,
  11175. /**
  11176. * The root scene mounted. Null if it is a isolated node
  11177. * @type {?clay.Scene}
  11178. * @private
  11179. */
  11180. _scene: null,
  11181. /**
  11182. * @type {boolean}
  11183. * @private
  11184. */
  11185. _needsUpdateWorldTransform: true,
  11186. /**
  11187. * @type {boolean}
  11188. * @private
  11189. */
  11190. _inIterating: false,
  11191. // Depth for transparent list sorting
  11192. __depth: 0
  11193. }, function () {
  11194. if (!this.name) {
  11195. this.name = (this.type || 'NODE') + '_' + (nameId++);
  11196. }
  11197. if (!this.position) {
  11198. this.position = new __WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */]();
  11199. }
  11200. if (!this.rotation) {
  11201. this.rotation = new __WEBPACK_IMPORTED_MODULE_2__math_Quaternion__["a" /* default */]();
  11202. }
  11203. if (!this.scale) {
  11204. this.scale = new __WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */](1, 1, 1);
  11205. }
  11206. this.worldTransform = new __WEBPACK_IMPORTED_MODULE_3__math_Matrix4__["a" /* default */]();
  11207. this.localTransform = new __WEBPACK_IMPORTED_MODULE_3__math_Matrix4__["a" /* default */]();
  11208. this._children = [];
  11209. },
  11210. /**@lends clay.Node.prototype. */
  11211. {
  11212. /**
  11213. * @type {?clay.Vector3}
  11214. * @instance
  11215. */
  11216. target: null,
  11217. /**
  11218. * If node and its chilren invisible
  11219. * @type {boolean}
  11220. * @instance
  11221. */
  11222. invisible: false,
  11223. /**
  11224. * If Node is a skinned mesh
  11225. * @return {boolean}
  11226. */
  11227. isSkinnedMesh: function () {
  11228. return false;
  11229. },
  11230. /**
  11231. * Return true if it is a renderable scene node, like Mesh and ParticleSystem
  11232. * @return {boolean}
  11233. */
  11234. isRenderable: function () {
  11235. return false;
  11236. },
  11237. /**
  11238. * Set the name of the scene node
  11239. * @param {string} name
  11240. */
  11241. setName: function (name) {
  11242. var scene = this._scene;
  11243. if (scene) {
  11244. var nodeRepository = scene._nodeRepository;
  11245. delete nodeRepository[this.name];
  11246. nodeRepository[name] = this;
  11247. }
  11248. this.name = name;
  11249. },
  11250. /**
  11251. * Add a child node
  11252. * @param {clay.Node} node
  11253. */
  11254. add: function (node) {
  11255. var originalParent = node._parent;
  11256. if (originalParent === this) {
  11257. return;
  11258. }
  11259. if (originalParent) {
  11260. originalParent.remove(node);
  11261. }
  11262. node._parent = this;
  11263. this._children.push(node);
  11264. var scene = this._scene;
  11265. if (scene && scene !== node.scene) {
  11266. node.traverse(this._addSelfToScene, this);
  11267. }
  11268. // Mark children needs update transform
  11269. // In case child are remove and added again after parent moved
  11270. node._needsUpdateWorldTransform = true;
  11271. },
  11272. /**
  11273. * Remove the given child scene node
  11274. * @param {clay.Node} node
  11275. */
  11276. remove: function (node) {
  11277. var children = this._children;
  11278. var idx = children.indexOf(node);
  11279. if (idx < 0) {
  11280. return;
  11281. }
  11282. children.splice(idx, 1);
  11283. node._parent = null;
  11284. if (this._scene) {
  11285. node.traverse(this._removeSelfFromScene, this);
  11286. }
  11287. },
  11288. /**
  11289. * Remove all children
  11290. */
  11291. removeAll: function () {
  11292. var children = this._children;
  11293. for (var idx = 0; idx < children.length; idx++) {
  11294. children[idx]._parent = null;
  11295. if (this._scene) {
  11296. children[idx].traverse(this._removeSelfFromScene, this);
  11297. }
  11298. }
  11299. this._children = [];
  11300. },
  11301. /**
  11302. * Get the scene mounted
  11303. * @return {clay.Scene}
  11304. */
  11305. getScene: function () {
  11306. return this._scene;
  11307. },
  11308. /**
  11309. * Get parent node
  11310. * @return {clay.Scene}
  11311. */
  11312. getParent: function () {
  11313. return this._parent;
  11314. },
  11315. _removeSelfFromScene: function (descendant) {
  11316. descendant._scene.removeFromScene(descendant);
  11317. descendant._scene = null;
  11318. },
  11319. _addSelfToScene: function (descendant) {
  11320. this._scene.addToScene(descendant);
  11321. descendant._scene = this._scene;
  11322. },
  11323. /**
  11324. * Return true if it is ancestor of the given scene node
  11325. * @param {clay.Node} node
  11326. */
  11327. isAncestor: function (node) {
  11328. var parent = node._parent;
  11329. while (parent) {
  11330. if (parent === this) {
  11331. return true;
  11332. }
  11333. parent = parent._parent;
  11334. }
  11335. return false;
  11336. },
  11337. /**
  11338. * Get a new created array of all children nodes
  11339. * @return {clay.Node[]}
  11340. */
  11341. children: function () {
  11342. return this._children.slice();
  11343. },
  11344. /**
  11345. * Get child scene node at given index.
  11346. * @param {number} idx
  11347. * @return {clay.Node}
  11348. */
  11349. childAt: function (idx) {
  11350. return this._children[idx];
  11351. },
  11352. /**
  11353. * Get first child with the given name
  11354. * @param {string} name
  11355. * @return {clay.Node}
  11356. */
  11357. getChildByName: function (name) {
  11358. var children = this._children;
  11359. for (var i = 0; i < children.length; i++) {
  11360. if (children[i].name === name) {
  11361. return children[i];
  11362. }
  11363. }
  11364. },
  11365. /**
  11366. * Get first descendant have the given name
  11367. * @param {string} name
  11368. * @return {clay.Node}
  11369. */
  11370. getDescendantByName: function (name) {
  11371. var children = this._children;
  11372. for (var i = 0; i < children.length; i++) {
  11373. var child = children[i];
  11374. if (child.name === name) {
  11375. return child;
  11376. } else {
  11377. var res = child.getDescendantByName(name);
  11378. if (res) {
  11379. return res;
  11380. }
  11381. }
  11382. }
  11383. },
  11384. /**
  11385. * Query descendant node by path
  11386. * @param {string} path
  11387. * @return {clay.Node}
  11388. * @example
  11389. * node.queryNode('root/parent/child');
  11390. */
  11391. queryNode: function (path) {
  11392. if (!path) {
  11393. return;
  11394. }
  11395. // TODO Name have slash ?
  11396. var pathArr = path.split('/');
  11397. var current = this;
  11398. for (var i = 0; i < pathArr.length; i++) {
  11399. var name = pathArr[i];
  11400. // Skip empty
  11401. if (!name) {
  11402. continue;
  11403. }
  11404. var found = false;
  11405. var children = current._children;
  11406. for (var j = 0; j < children.length; j++) {
  11407. var child = children[j];
  11408. if (child.name === name) {
  11409. current = child;
  11410. found = true;
  11411. break;
  11412. }
  11413. }
  11414. // Early return if not found
  11415. if (!found) {
  11416. return;
  11417. }
  11418. }
  11419. return current;
  11420. },
  11421. /**
  11422. * Get query path, relative to rootNode(default is scene)
  11423. * @param {clay.Node} [rootNode]
  11424. * @return {string}
  11425. */
  11426. getPath: function (rootNode) {
  11427. if (!this._parent) {
  11428. return '/';
  11429. }
  11430. var current = this._parent;
  11431. var path = this.name;
  11432. while (current._parent) {
  11433. path = current.name + '/' + path;
  11434. if (current._parent == rootNode) {
  11435. break;
  11436. }
  11437. current = current._parent;
  11438. }
  11439. if (!current._parent && rootNode) {
  11440. return null;
  11441. }
  11442. return path;
  11443. },
  11444. /**
  11445. * Depth first traverse all its descendant scene nodes.
  11446. *
  11447. * **WARN** Don't do `add`, `remove` operation in the callback during traverse.
  11448. * @param {Function} callback
  11449. * @param {Node} [context]
  11450. */
  11451. traverse: function (callback, context) {
  11452. callback.call(context, this);
  11453. var _children = this._children;
  11454. for (var i = 0, len = _children.length; i < len; i++) {
  11455. _children[i].traverse(callback, context);
  11456. }
  11457. },
  11458. /**
  11459. * Traverse all children nodes.
  11460. *
  11461. * **WARN** DON'T do `add`, `remove` operation in the callback during iteration.
  11462. *
  11463. * @param {Function} callback
  11464. * @param {Node} [context]
  11465. */
  11466. eachChild: function (callback, context) {
  11467. var _children = this._children;
  11468. for (var i = 0, len = _children.length; i < len; i++) {
  11469. var child = _children[i];
  11470. callback.call(context, child, i);
  11471. }
  11472. },
  11473. /**
  11474. * Set the local transform and decompose to SRT
  11475. * @param {clay.Matrix4} matrix
  11476. */
  11477. setLocalTransform: function (matrix) {
  11478. __WEBPACK_IMPORTED_MODULE_4__glmatrix_mat4__["a" /* default */].copy(this.localTransform.array, matrix.array);
  11479. this.decomposeLocalTransform();
  11480. },
  11481. /**
  11482. * Decompose the local transform to SRT
  11483. */
  11484. decomposeLocalTransform: function (keepScale) {
  11485. var scale = !keepScale ? this.scale : null;
  11486. this.localTransform.decomposeMatrix(scale, this.rotation, this.position);
  11487. },
  11488. /**
  11489. * Set the world transform and decompose to SRT
  11490. * @param {clay.Matrix4} matrix
  11491. */
  11492. setWorldTransform: function (matrix) {
  11493. __WEBPACK_IMPORTED_MODULE_4__glmatrix_mat4__["a" /* default */].copy(this.worldTransform.array, matrix.array);
  11494. this.decomposeWorldTransform();
  11495. },
  11496. /**
  11497. * Decompose the world transform to SRT
  11498. * @function
  11499. */
  11500. decomposeWorldTransform: (function () {
  11501. var tmp = __WEBPACK_IMPORTED_MODULE_4__glmatrix_mat4__["a" /* default */].create();
  11502. return function (keepScale) {
  11503. var localTransform = this.localTransform;
  11504. var worldTransform = this.worldTransform;
  11505. // Assume world transform is updated
  11506. if (this._parent) {
  11507. __WEBPACK_IMPORTED_MODULE_4__glmatrix_mat4__["a" /* default */].invert(tmp, this._parent.worldTransform.array);
  11508. __WEBPACK_IMPORTED_MODULE_4__glmatrix_mat4__["a" /* default */].multiply(localTransform.array, tmp, worldTransform.array);
  11509. } else {
  11510. __WEBPACK_IMPORTED_MODULE_4__glmatrix_mat4__["a" /* default */].copy(localTransform.array, worldTransform.array);
  11511. }
  11512. var scale = !keepScale ? this.scale : null;
  11513. localTransform.decomposeMatrix(scale, this.rotation, this.position);
  11514. };
  11515. })(),
  11516. transformNeedsUpdate: function () {
  11517. return this.position._dirty
  11518. || this.rotation._dirty
  11519. || this.scale._dirty;
  11520. },
  11521. /**
  11522. * Update local transform from SRT
  11523. * Notice that local transform will not be updated if _dirty mark of position, rotation, scale is all false
  11524. */
  11525. updateLocalTransform: function () {
  11526. var position = this.position;
  11527. var rotation = this.rotation;
  11528. var scale = this.scale;
  11529. if (this.transformNeedsUpdate()) {
  11530. var m = this.localTransform.array;
  11531. // Transform order, scale->rotation->position
  11532. __WEBPACK_IMPORTED_MODULE_4__glmatrix_mat4__["a" /* default */].fromRotationTranslation(m, rotation.array, position.array);
  11533. __WEBPACK_IMPORTED_MODULE_4__glmatrix_mat4__["a" /* default */].scale(m, m, scale.array);
  11534. rotation._dirty = false;
  11535. scale._dirty = false;
  11536. position._dirty = false;
  11537. this._needsUpdateWorldTransform = true;
  11538. }
  11539. },
  11540. /**
  11541. * Update world transform, assume its parent world transform have been updated
  11542. * @private
  11543. */
  11544. _updateWorldTransformTopDown: function () {
  11545. var localTransform = this.localTransform.array;
  11546. var worldTransform = this.worldTransform.array;
  11547. if (this._parent) {
  11548. __WEBPACK_IMPORTED_MODULE_4__glmatrix_mat4__["a" /* default */].multiplyAffine(
  11549. worldTransform,
  11550. this._parent.worldTransform.array,
  11551. localTransform
  11552. );
  11553. }
  11554. else {
  11555. __WEBPACK_IMPORTED_MODULE_4__glmatrix_mat4__["a" /* default */].copy(worldTransform, localTransform);
  11556. }
  11557. },
  11558. /**
  11559. * Update world transform before whole scene is updated.
  11560. */
  11561. updateWorldTransform: function () {
  11562. // Find the root node which transform needs update;
  11563. var rootNodeIsDirty = this;
  11564. while (rootNodeIsDirty && rootNodeIsDirty.getParent()
  11565. && rootNodeIsDirty.getParent().transformNeedsUpdate()
  11566. ) {
  11567. rootNodeIsDirty = rootNodeIsDirty.getParent();
  11568. }
  11569. rootNodeIsDirty.update();
  11570. },
  11571. /**
  11572. * Update local transform and world transform recursively
  11573. * @param {boolean} forceUpdateWorld
  11574. */
  11575. update: function (forceUpdateWorld) {
  11576. if (this.autoUpdateLocalTransform) {
  11577. this.updateLocalTransform();
  11578. }
  11579. else {
  11580. // Transform is manually setted
  11581. forceUpdateWorld = true;
  11582. }
  11583. if (forceUpdateWorld || this._needsUpdateWorldTransform) {
  11584. this._updateWorldTransformTopDown();
  11585. forceUpdateWorld = true;
  11586. this._needsUpdateWorldTransform = false;
  11587. }
  11588. var children = this._children;
  11589. for (var i = 0, len = children.length; i < len; i++) {
  11590. children[i].update(forceUpdateWorld);
  11591. }
  11592. },
  11593. /**
  11594. * Get bounding box of node
  11595. * @param {Function} [filter]
  11596. * @param {clay.BoundingBox} [out]
  11597. * @return {clay.BoundingBox}
  11598. */
  11599. // TODO Skinning
  11600. getBoundingBox: (function () {
  11601. function defaultFilter(el) {
  11602. return !el.invisible && el.geometry;
  11603. }
  11604. var tmpBBox = new __WEBPACK_IMPORTED_MODULE_5__math_BoundingBox__["a" /* default */]();
  11605. var tmpMat4 = new __WEBPACK_IMPORTED_MODULE_3__math_Matrix4__["a" /* default */]();
  11606. var invWorldTransform = new __WEBPACK_IMPORTED_MODULE_3__math_Matrix4__["a" /* default */]();
  11607. return function (filter, out) {
  11608. out = out || new __WEBPACK_IMPORTED_MODULE_5__math_BoundingBox__["a" /* default */]();
  11609. filter = filter || defaultFilter;
  11610. if (this._parent) {
  11611. __WEBPACK_IMPORTED_MODULE_3__math_Matrix4__["a" /* default */].invert(invWorldTransform, this._parent.worldTransform);
  11612. }
  11613. else {
  11614. __WEBPACK_IMPORTED_MODULE_3__math_Matrix4__["a" /* default */].identity(invWorldTransform);
  11615. }
  11616. this.traverse(function (mesh) {
  11617. if (mesh.geometry && mesh.geometry.boundingBox) {
  11618. tmpBBox.copy(mesh.geometry.boundingBox);
  11619. __WEBPACK_IMPORTED_MODULE_3__math_Matrix4__["a" /* default */].multiply(tmpMat4, invWorldTransform, mesh.worldTransform);
  11620. tmpBBox.applyTransform(tmpMat4);
  11621. out.union(tmpBBox);
  11622. }
  11623. }, this, defaultFilter);
  11624. return out;
  11625. };
  11626. })(),
  11627. /**
  11628. * Get world position, extracted from world transform
  11629. * @param {clay.Vector3} [out]
  11630. * @return {clay.Vector3}
  11631. */
  11632. getWorldPosition: function (out) {
  11633. // PENDING
  11634. if (this.transformNeedsUpdate()) {
  11635. this.updateWorldTransform();
  11636. }
  11637. var m = this.worldTransform.array;
  11638. if (out) {
  11639. var arr = out.array;
  11640. arr[0] = m[12];
  11641. arr[1] = m[13];
  11642. arr[2] = m[14];
  11643. return out;
  11644. }
  11645. else {
  11646. return new __WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */](m[12], m[13], m[14]);
  11647. }
  11648. },
  11649. /**
  11650. * Clone a new node
  11651. * @return {Node}
  11652. */
  11653. clone: function () {
  11654. var node = new this.constructor();
  11655. var children = this._children;
  11656. node.setName(this.name);
  11657. node.position.copy(this.position);
  11658. node.rotation.copy(this.rotation);
  11659. node.scale.copy(this.scale);
  11660. for (var i = 0; i < children.length; i++) {
  11661. node.add(children[i].clone());
  11662. }
  11663. return node;
  11664. },
  11665. /**
  11666. * Rotate the node around a axis by angle degrees, axis passes through point
  11667. * @param {clay.Vector3} point Center point
  11668. * @param {clay.Vector3} axis Center axis
  11669. * @param {number} angle Rotation angle
  11670. * @see http://docs.unity3d.com/Documentation/ScriptReference/Transform.RotateAround.html
  11671. * @function
  11672. */
  11673. rotateAround: (function () {
  11674. var v = new __WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */]();
  11675. var RTMatrix = new __WEBPACK_IMPORTED_MODULE_3__math_Matrix4__["a" /* default */]();
  11676. // TODO improve performance
  11677. return function (point, axis, angle) {
  11678. v.copy(this.position).subtract(point);
  11679. var localTransform = this.localTransform;
  11680. localTransform.identity();
  11681. // parent node
  11682. localTransform.translate(point);
  11683. localTransform.rotate(angle, axis);
  11684. RTMatrix.fromRotationTranslation(this.rotation, v);
  11685. localTransform.multiply(RTMatrix);
  11686. localTransform.scale(this.scale);
  11687. this.decomposeLocalTransform();
  11688. this._needsUpdateWorldTransform = true;
  11689. };
  11690. })(),
  11691. /**
  11692. * @param {clay.Vector3} target
  11693. * @param {clay.Vector3} [up]
  11694. * @see http://www.opengl.org/sdk/docs/man2/xhtml/gluLookAt.xml
  11695. * @function
  11696. */
  11697. lookAt: (function () {
  11698. var m = new __WEBPACK_IMPORTED_MODULE_3__math_Matrix4__["a" /* default */]();
  11699. return function (target, up) {
  11700. m.lookAt(this.position, target, up || this.localTransform.y).invert();
  11701. this.setLocalTransform(m);
  11702. this.target = target;
  11703. };
  11704. })()
  11705. });
  11706. /* harmony default export */ __webpack_exports__["a"] = (Node);
  11707. /***/
  11708. }),
  11709. /* 36 */
  11710. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  11711. "use strict";
  11712. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Node__ = __webpack_require__(35);
  11713. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__Light__ = __webpack_require__(24);
  11714. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__Camera__ = __webpack_require__(58);
  11715. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__math_BoundingBox__ = __webpack_require__(18);
  11716. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__core_util__ = __webpack_require__(23);
  11717. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__glmatrix_mat4__ = __webpack_require__(21);
  11718. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__core_LRU__ = __webpack_require__(69);
  11719. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__math_Matrix4__ = __webpack_require__(9);
  11720. var IDENTITY = __WEBPACK_IMPORTED_MODULE_5__glmatrix_mat4__["a" /* default */].create();
  11721. var WORLDVIEW = __WEBPACK_IMPORTED_MODULE_5__glmatrix_mat4__["a" /* default */].create();
  11722. var programKeyCache = {};
  11723. function getProgramKey(lightNumbers) {
  11724. var defineStr = [];
  11725. var lightTypes = Object.keys(lightNumbers);
  11726. lightTypes.sort();
  11727. for (var i = 0; i < lightTypes.length; i++) {
  11728. var lightType = lightTypes[i];
  11729. defineStr.push(lightType + ' ' + lightNumbers[lightType]);
  11730. }
  11731. var key = defineStr.join('\n');
  11732. if (programKeyCache[key]) {
  11733. return programKeyCache[key];
  11734. }
  11735. var id = __WEBPACK_IMPORTED_MODULE_4__core_util__["a" /* default */].genGUID();
  11736. programKeyCache[key] = id;
  11737. return id;
  11738. }
  11739. function RenderList() {
  11740. this.opaque = [];
  11741. this.transparent = [];
  11742. this._opaqueCount = 0;
  11743. this._transparentCount = 0;
  11744. }
  11745. RenderList.prototype.startCount = function () {
  11746. this._opaqueCount = 0;
  11747. this._transparentCount = 0;
  11748. };
  11749. RenderList.prototype.add = function (object, isTransparent) {
  11750. if (isTransparent) {
  11751. this.transparent[this._transparentCount++] = object;
  11752. }
  11753. else {
  11754. this.opaque[this._opaqueCount++] = object;
  11755. }
  11756. };
  11757. RenderList.prototype.endCount = function () {
  11758. this.transparent.length = this._transparentCount;
  11759. this.opaque.length = this._opaqueCount;
  11760. };
  11761. /**
  11762. * @typedef {Object} clay.Scene.RenderList
  11763. * @property {Array.<clay.Renderable>} opaque
  11764. * @property {Array.<clay.Renderable>} transparent
  11765. */
  11766. /**
  11767. * @constructor clay.Scene
  11768. * @extends clay.Node
  11769. */
  11770. var Scene = __WEBPACK_IMPORTED_MODULE_0__Node__["a" /* default */].extend(function () {
  11771. return /** @lends clay.Scene# */ {
  11772. /**
  11773. * Global material of scene
  11774. * @type {clay.Material}
  11775. */
  11776. material: null,
  11777. lights: [],
  11778. /**
  11779. * Scene bounding box in view space.
  11780. * Used when camera needs to adujst the near and far plane automatically
  11781. * so that the view frustum contains the visible objects as tightly as possible.
  11782. * Notice:
  11783. * It is updated after rendering (in the step of frustum culling passingly). So may be not so accurate, but saves a lot of calculation
  11784. *
  11785. * @type {clay.BoundingBox}
  11786. */
  11787. viewBoundingBoxLastFrame: new __WEBPACK_IMPORTED_MODULE_3__math_BoundingBox__["a" /* default */](),
  11788. // Uniforms for shadow map.
  11789. shadowUniforms: {},
  11790. _cameraList: [],
  11791. // Properties to save the light information in the scene
  11792. // Will be set in the render function
  11793. _lightUniforms: {},
  11794. _previousLightNumber: {},
  11795. _lightNumber: {
  11796. // groupId: {
  11797. // POINT_LIGHT: 0,
  11798. // DIRECTIONAL_LIGHT: 0,
  11799. // SPOT_LIGHT: 0,
  11800. // AMBIENT_LIGHT: 0,
  11801. // AMBIENT_SH_LIGHT: 0
  11802. // }
  11803. },
  11804. _lightProgramKeys: {},
  11805. _nodeRepository: {},
  11806. _renderLists: new __WEBPACK_IMPORTED_MODULE_6__core_LRU__["a" /* default */](20)
  11807. };
  11808. }, function () {
  11809. this._scene = this;
  11810. },
  11811. /** @lends clay.Scene.prototype. */
  11812. {
  11813. // Add node to scene
  11814. addToScene: function (node) {
  11815. if (node instanceof __WEBPACK_IMPORTED_MODULE_2__Camera__["a" /* default */]) {
  11816. if (this._cameraList.length > 0) {
  11817. console.warn('Found multiple camera in one scene. Use the fist one.');
  11818. }
  11819. this._cameraList.push(node);
  11820. }
  11821. else if (node instanceof __WEBPACK_IMPORTED_MODULE_1__Light__["a" /* default */]) {
  11822. this.lights.push(node);
  11823. }
  11824. if (node.name) {
  11825. this._nodeRepository[node.name] = node;
  11826. }
  11827. },
  11828. // Remove node from scene
  11829. removeFromScene: function (node) {
  11830. var idx;
  11831. if (node instanceof __WEBPACK_IMPORTED_MODULE_2__Camera__["a" /* default */]) {
  11832. idx = this._cameraList.indexOf(node);
  11833. if (idx >= 0) {
  11834. this._cameraList.splice(idx, 1);
  11835. }
  11836. }
  11837. else if (node instanceof __WEBPACK_IMPORTED_MODULE_1__Light__["a" /* default */]) {
  11838. idx = this.lights.indexOf(node);
  11839. if (idx >= 0) {
  11840. this.lights.splice(idx, 1);
  11841. }
  11842. }
  11843. if (node.name) {
  11844. delete this._nodeRepository[node.name];
  11845. }
  11846. },
  11847. /**
  11848. * Get node by name
  11849. * @param {string} name
  11850. * @return {Node}
  11851. * @DEPRECATED
  11852. */
  11853. getNode: function (name) {
  11854. return this._nodeRepository[name];
  11855. },
  11856. /**
  11857. * Set main camera of the scene.
  11858. * @param {claygl.Camera} camera
  11859. */
  11860. setMainCamera: function (camera) {
  11861. var idx = this._cameraList.indexOf(camera);
  11862. if (idx >= 0) {
  11863. this._cameraList.splice(idx, 1);
  11864. }
  11865. this._cameraList.unshift(camera);
  11866. },
  11867. /**
  11868. * Get main camera of the scene.
  11869. */
  11870. getMainCamera: function () {
  11871. return this._cameraList[0];
  11872. },
  11873. getLights: function () {
  11874. return this.lights;
  11875. },
  11876. updateLights: function () {
  11877. var lights = this.lights;
  11878. this._previousLightNumber = this._lightNumber;
  11879. var lightNumber = {};
  11880. for (var i = 0; i < lights.length; i++) {
  11881. var light = lights[i];
  11882. if (light.invisible) {
  11883. continue;
  11884. }
  11885. var group = light.group;
  11886. if (!lightNumber[group]) {
  11887. lightNumber[group] = {};
  11888. }
  11889. // User can use any type of light
  11890. lightNumber[group][light.type] = lightNumber[group][light.type] || 0;
  11891. lightNumber[group][light.type]++;
  11892. }
  11893. this._lightNumber = lightNumber;
  11894. for (var groupId in lightNumber) {
  11895. this._lightProgramKeys[groupId] = getProgramKey(lightNumber[groupId]);
  11896. }
  11897. this._updateLightUniforms();
  11898. },
  11899. /**
  11900. * Clone a node and it's children, including mesh, camera, light, etc.
  11901. * Unlike using `Node#clone`. It will clone skeleton and remap the joints. Material will also be cloned.
  11902. *
  11903. * @param {clay.Node} node
  11904. * @return {clay.Node}
  11905. */
  11906. cloneNode: function (node) {
  11907. var newNode = node.clone();
  11908. var clonedNodesMap = {};
  11909. function buildNodesMap(sNode, tNode) {
  11910. clonedNodesMap[sNode.__uid__] = tNode;
  11911. for (var i = 0; i < sNode._children.length; i++) {
  11912. var sChild = sNode._children[i];
  11913. var tChild = tNode._children[i];
  11914. buildNodesMap(sChild, tChild);
  11915. }
  11916. }
  11917. buildNodesMap(node, newNode);
  11918. newNode.traverse(function (newChild) {
  11919. if (newChild.skeleton) {
  11920. newChild.skeleton = newChild.skeleton.clone(clonedNodesMap);
  11921. }
  11922. if (newChild.material) {
  11923. newChild.material = newChild.material.clone();
  11924. }
  11925. });
  11926. return newNode;
  11927. },
  11928. /**
  11929. * Traverse the scene and add the renderable object to the render list.
  11930. * It needs camera for the frustum culling.
  11931. *
  11932. * @param {clay.Camera} camera
  11933. * @param {boolean} updateSceneBoundingBox
  11934. * @return {clay.Scene.RenderList}
  11935. */
  11936. updateRenderList: function (camera, updateSceneBoundingBox) {
  11937. var id = camera.__uid__;
  11938. var renderList = this._renderLists.get(id);
  11939. if (!renderList) {
  11940. renderList = new RenderList();
  11941. this._renderLists.put(id, renderList);
  11942. }
  11943. renderList.startCount();
  11944. if (updateSceneBoundingBox) {
  11945. this.viewBoundingBoxLastFrame.min.set(Infinity, Infinity, Infinity);
  11946. this.viewBoundingBoxLastFrame.max.set(-Infinity, -Infinity, -Infinity);
  11947. }
  11948. var sceneMaterialTransparent = this.material && this.material.transparent || false;
  11949. this._doUpdateRenderList(this, camera, sceneMaterialTransparent, renderList, updateSceneBoundingBox);
  11950. renderList.endCount();
  11951. return renderList;
  11952. },
  11953. /**
  11954. * Get render list. Used after {@link clay.Scene#updateRenderList}
  11955. * @param {clay.Camera} camera
  11956. * @return {clay.Scene.RenderList}
  11957. */
  11958. getRenderList: function (camera) {
  11959. return this._renderLists.get(camera.__uid__);
  11960. },
  11961. _doUpdateRenderList: function (parent, camera, sceneMaterialTransparent, renderList, updateSceneBoundingBox) {
  11962. if (parent.invisible) {
  11963. return;
  11964. }
  11965. // TODO Optimize
  11966. for (var i = 0; i < parent._children.length; i++) {
  11967. var child = parent._children[i];
  11968. if (child.isRenderable()) {
  11969. // Frustum culling
  11970. var worldM = child.isSkinnedMesh() ? IDENTITY : child.worldTransform.array;
  11971. var geometry = child.geometry;
  11972. __WEBPACK_IMPORTED_MODULE_5__glmatrix_mat4__["a" /* default */].multiplyAffine(WORLDVIEW, camera.viewMatrix.array, worldM);
  11973. if (updateSceneBoundingBox && !geometry.boundingBox || !this.isFrustumCulled(child, camera, WORLDVIEW)) {
  11974. renderList.add(child, child.material.transparent || sceneMaterialTransparent);
  11975. }
  11976. }
  11977. if (child._children.length > 0) {
  11978. this._doUpdateRenderList(child, camera, sceneMaterialTransparent, renderList, updateSceneBoundingBox);
  11979. }
  11980. }
  11981. },
  11982. /**
  11983. * If an scene object is culled by camera frustum
  11984. *
  11985. * Object can be a renderable or a light
  11986. *
  11987. * @param {clay.Node} object
  11988. * @param {clay.Camera} camera
  11989. * @param {Array.<number>} worldViewMat represented with array
  11990. * @param {Array.<number>} projectionMat represented with array
  11991. */
  11992. isFrustumCulled: (function () {
  11993. // Frustum culling
  11994. // http://www.cse.chalmers.se/~uffe/vfc_bbox.pdf
  11995. var cullingBoundingBox = new __WEBPACK_IMPORTED_MODULE_3__math_BoundingBox__["a" /* default */]();
  11996. var cullingMatrix = new __WEBPACK_IMPORTED_MODULE_7__math_Matrix4__["a" /* default */]();
  11997. return function (object, camera, worldViewMat) {
  11998. // Bounding box can be a property of object(like light) or renderable.geometry
  11999. // PENDING
  12000. var geoBBox = object.boundingBox;
  12001. if (!geoBBox) {
  12002. if (object.skeleton && object.skeleton.boundingBox) {
  12003. geoBBox = object.skeleton.boundingBox;
  12004. }
  12005. else {
  12006. geoBBox = object.geometry.boundingBox;
  12007. }
  12008. }
  12009. if (!geoBBox) {
  12010. return false;
  12011. }
  12012. cullingMatrix.array = worldViewMat;
  12013. cullingBoundingBox.transformFrom(geoBBox, cullingMatrix);
  12014. // Passingly update the scene bounding box
  12015. // FIXME exclude very large mesh like ground plane or terrain ?
  12016. // FIXME Only rendererable which cast shadow ?
  12017. // FIXME boundingBox becomes much larger after transformd.
  12018. if (object.castShadow) {
  12019. this.viewBoundingBoxLastFrame.union(cullingBoundingBox);
  12020. }
  12021. // Ignore frustum culling if object is skinned mesh.
  12022. if (object.frustumCulling) {
  12023. if (!cullingBoundingBox.intersectBoundingBox(camera.frustum.boundingBox)) {
  12024. return true;
  12025. }
  12026. cullingMatrix.array = camera.projectionMatrix.array;
  12027. if (
  12028. cullingBoundingBox.max.array[2] > 0 &&
  12029. cullingBoundingBox.min.array[2] < 0
  12030. ) {
  12031. // Clip in the near plane
  12032. cullingBoundingBox.max.array[2] = -1e-20;
  12033. }
  12034. cullingBoundingBox.applyProjection(cullingMatrix);
  12035. var min = cullingBoundingBox.min.array;
  12036. var max = cullingBoundingBox.max.array;
  12037. if (
  12038. max[0] < -1 || min[0] > 1
  12039. || max[1] < -1 || min[1] > 1
  12040. || max[2] < -1 || min[2] > 1
  12041. ) {
  12042. return true;
  12043. }
  12044. }
  12045. return false;
  12046. };
  12047. })(),
  12048. _updateLightUniforms: function () {
  12049. var lights = this.lights;
  12050. // Put the light cast shadow before the light not cast shadow
  12051. lights.sort(lightSortFunc);
  12052. var lightUniforms = this._lightUniforms;
  12053. for (var group in lightUniforms) {
  12054. for (var symbol in lightUniforms[group]) {
  12055. lightUniforms[group][symbol].value.length = 0;
  12056. }
  12057. }
  12058. for (var i = 0; i < lights.length; i++) {
  12059. var light = lights[i];
  12060. if (light.invisible) {
  12061. continue;
  12062. }
  12063. var group = light.group;
  12064. for (var symbol in light.uniformTemplates) {
  12065. var uniformTpl = light.uniformTemplates[symbol];
  12066. var value = uniformTpl.value(light);
  12067. if (value == null) {
  12068. continue;
  12069. }
  12070. if (!lightUniforms[group]) {
  12071. lightUniforms[group] = {};
  12072. }
  12073. if (!lightUniforms[group][symbol]) {
  12074. lightUniforms[group][symbol] = {
  12075. type: '',
  12076. value: []
  12077. };
  12078. }
  12079. var lu = lightUniforms[group][symbol];
  12080. lu.type = uniformTpl.type + 'v';
  12081. switch (uniformTpl.type) {
  12082. case '1i':
  12083. case '1f':
  12084. case 't':
  12085. lu.value.push(value);
  12086. break;
  12087. case '2f':
  12088. case '3f':
  12089. case '4f':
  12090. for (var j = 0; j < value.length; j++) {
  12091. lu.value.push(value[j]);
  12092. }
  12093. break;
  12094. default:
  12095. console.error('Unkown light uniform type ' + uniformTpl.type);
  12096. }
  12097. }
  12098. }
  12099. },
  12100. getLightGroups: function () {
  12101. var lightGroups = [];
  12102. for (var groupId in this._lightNumber) {
  12103. lightGroups.push(groupId);
  12104. }
  12105. return lightGroups;
  12106. },
  12107. getNumberChangedLightGroups: function () {
  12108. var lightGroups = [];
  12109. for (var groupId in this._lightNumber) {
  12110. if (this.isLightNumberChanged(groupId)) {
  12111. lightGroups.push(groupId);
  12112. }
  12113. }
  12114. return lightGroups;
  12115. },
  12116. // Determine if light group is different with since last frame
  12117. // Used to determine whether to update shader and scene's uniforms in Renderer.render
  12118. isLightNumberChanged: function (lightGroup) {
  12119. var prevLightNumber = this._previousLightNumber;
  12120. var currentLightNumber = this._lightNumber;
  12121. // PENDING Performance
  12122. for (var type in currentLightNumber[lightGroup]) {
  12123. if (!prevLightNumber[lightGroup]) {
  12124. return true;
  12125. }
  12126. if (currentLightNumber[lightGroup][type] !== prevLightNumber[lightGroup][type]) {
  12127. return true;
  12128. }
  12129. }
  12130. for (var type in prevLightNumber[lightGroup]) {
  12131. if (!currentLightNumber[lightGroup]) {
  12132. return true;
  12133. }
  12134. if (currentLightNumber[lightGroup][type] !== prevLightNumber[lightGroup][type]) {
  12135. return true;
  12136. }
  12137. }
  12138. return false;
  12139. },
  12140. getLightsNumbers: function (lightGroup) {
  12141. return this._lightNumber[lightGroup];
  12142. },
  12143. getProgramKey: function (lightGroup) {
  12144. return this._lightProgramKeys[lightGroup];
  12145. },
  12146. setLightUniforms: (function () {
  12147. function setUniforms(uniforms, program, renderer) {
  12148. for (var symbol in uniforms) {
  12149. var lu = uniforms[symbol];
  12150. if (lu.type === 'tv') {
  12151. if (!program.hasUniform(symbol)) {
  12152. continue;
  12153. }
  12154. var texSlots = [];
  12155. for (var i = 0; i < lu.value.length; i++) {
  12156. var texture = lu.value[i];
  12157. var slot = program.takeCurrentTextureSlot(renderer, texture);
  12158. texSlots.push(slot);
  12159. }
  12160. program.setUniform(renderer.gl, '1iv', symbol, texSlots);
  12161. }
  12162. else {
  12163. program.setUniform(renderer.gl, lu.type, symbol, lu.value);
  12164. }
  12165. }
  12166. }
  12167. return function (program, lightGroup, renderer) {
  12168. setUniforms(this._lightUniforms[lightGroup], program, renderer);
  12169. // Set shadows
  12170. setUniforms(this.shadowUniforms, program, renderer);
  12171. };
  12172. })(),
  12173. /**
  12174. * Dispose self, clear all the scene objects
  12175. * But resources of gl like texuture, shader will not be disposed.
  12176. * Mostly you should use disposeScene method in Renderer to do dispose.
  12177. */
  12178. dispose: function () {
  12179. this.material = null;
  12180. this._opaqueList = [];
  12181. this._transparentList = [];
  12182. this.lights = [];
  12183. this._lightUniforms = {};
  12184. this._lightNumber = {};
  12185. this._nodeRepository = {};
  12186. }
  12187. });
  12188. function lightSortFunc(a, b) {
  12189. if (b.castShadow && !a.castShadow) {
  12190. return true;
  12191. }
  12192. }
  12193. /* harmony default export */ __webpack_exports__["a"] = (Scene);
  12194. /***/
  12195. }),
  12196. /* 37 */
  12197. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  12198. "use strict";
  12199. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Camera__ = __webpack_require__(58);
  12200. /**
  12201. * @constructor clay.camera.Orthographic
  12202. * @extends clay.Camera
  12203. */
  12204. var Orthographic = __WEBPACK_IMPORTED_MODULE_0__Camera__["a" /* default */].extend(
  12205. /** @lends clay.camera.Orthographic# */
  12206. {
  12207. /**
  12208. * @type {number}
  12209. */
  12210. left: -1,
  12211. /**
  12212. * @type {number}
  12213. */
  12214. right: 1,
  12215. /**
  12216. * @type {number}
  12217. */
  12218. near: -1,
  12219. /**
  12220. * @type {number}
  12221. */
  12222. far: 1,
  12223. /**
  12224. * @type {number}
  12225. */
  12226. top: 1,
  12227. /**
  12228. * @type {number}
  12229. */
  12230. bottom: -1
  12231. },
  12232. /** @lends clay.camera.Orthographic.prototype */
  12233. {
  12234. updateProjectionMatrix: function () {
  12235. this.projectionMatrix.ortho(this.left, this.right, this.bottom, this.top, this.near, this.far);
  12236. },
  12237. decomposeProjectionMatrix: function () {
  12238. var m = this.projectionMatrix.array;
  12239. this.left = (-1 - m[12]) / m[0];
  12240. this.right = (1 - m[12]) / m[0];
  12241. this.top = (1 - m[13]) / m[5];
  12242. this.bottom = (-1 - m[13]) / m[5];
  12243. this.near = -(-1 - m[14]) / m[10];
  12244. this.far = -(1 - m[14]) / m[10];
  12245. },
  12246. /**
  12247. * @return {clay.camera.Orthographic}
  12248. */
  12249. clone: function () {
  12250. var camera = __WEBPACK_IMPORTED_MODULE_0__Camera__["a" /* default */].prototype.clone.call(this);
  12251. camera.left = this.left;
  12252. camera.right = this.right;
  12253. camera.near = this.near;
  12254. camera.far = this.far;
  12255. camera.top = this.top;
  12256. camera.bottom = this.bottom;
  12257. return camera;
  12258. }
  12259. });
  12260. /* harmony default export */ __webpack_exports__["a"] = (Orthographic);
  12261. /***/
  12262. }),
  12263. /* 38 */
  12264. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  12265. "use strict";
  12266. /* harmony default export */ __webpack_exports__["a"] = ({
  12267. convertToDynamicArray: function (clear) {
  12268. if (clear) {
  12269. this.resetOffset();
  12270. }
  12271. var attributes = this.attributes;
  12272. for (var name in attributes) {
  12273. if (clear || !attributes[name].value) {
  12274. attributes[name].value = [];
  12275. }
  12276. else {
  12277. attributes[name].value = Array.prototype.slice.call(attributes[name].value);
  12278. }
  12279. }
  12280. if (clear || !this.indices) {
  12281. this.indices = [];
  12282. }
  12283. else {
  12284. this.indices = Array.prototype.slice.call(this.indices);
  12285. }
  12286. },
  12287. convertToTypedArray: function () {
  12288. var attributes = this.attributes;
  12289. for (var name in attributes) {
  12290. if (attributes[name].value && attributes[name].value.length > 0) {
  12291. attributes[name].value = new Float32Array(attributes[name].value);
  12292. }
  12293. else {
  12294. attributes[name].value = null;
  12295. }
  12296. }
  12297. if (this.indices && this.indices.length > 0) {
  12298. this.indices = this.vertexCount > 0xffff ? new Uint32Array(this.indices) : new Uint16Array(this.indices);
  12299. }
  12300. this.dirty();
  12301. }
  12302. });
  12303. /***/
  12304. }),
  12305. /* 39 */
  12306. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  12307. "use strict";
  12308. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  12309. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  12310. function otherDimToDataDim(data, otherDim) {
  12311. var dataDim = [];
  12312. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.each(data.dimensions, function (dimName) {
  12313. var dimItem = data.getDimensionInfo(dimName);
  12314. var otherDims = dimItem.otherDims;
  12315. var dimIndex = otherDims[otherDim];
  12316. if (dimIndex != null && dimIndex !== false) {
  12317. dataDim[dimIndex] = dimItem.name;
  12318. }
  12319. });
  12320. return dataDim;
  12321. }
  12322. /* harmony default export */ __webpack_exports__["a"] = (function (seriesModel, dataIndex, multipleSeries) {
  12323. function formatArrayValue(value) {
  12324. var vertially = true;
  12325. var result = [];
  12326. var tooltipDims = otherDimToDataDim(data, 'tooltip');
  12327. tooltipDims.length
  12328. ? __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.each(tooltipDims, function (dimIdx) {
  12329. setEachItem(data.get(dimIdx, dataIndex), dimIdx);
  12330. })
  12331. // By default, all dims is used on tooltip.
  12332. : __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.each(value, setEachItem);
  12333. function setEachItem(val, dimIdx) {
  12334. var dimInfo = data.getDimensionInfo(dimIdx);
  12335. // If `dimInfo.tooltip` is not set, show tooltip.
  12336. if (!dimInfo || dimInfo.otherDims.tooltip === false) {
  12337. return;
  12338. }
  12339. var dimType = dimInfo.type;
  12340. var valStr = (vertially ? '- ' + (dimInfo.tooltipName || dimInfo.name) + ': ' : '')
  12341. + (dimType === 'ordinal'
  12342. ? val + ''
  12343. : dimType === 'time'
  12344. ? (multipleSeries ? '' : __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.format.formatTime('yyyy/MM/dd hh:mm:ss', val))
  12345. : __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.format.addCommas(val)
  12346. );
  12347. valStr && result.push(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.format.encodeHTML(valStr));
  12348. }
  12349. return (vertially ? '<br/>' : '') + result.join(vertially ? '<br/>' : ', ');
  12350. }
  12351. var data = seriesModel.getData();
  12352. var value = seriesModel.getRawValue(dataIndex);
  12353. var formattedValue = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.isArray(value)
  12354. ? formatArrayValue(value) : __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.format.encodeHTML(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.format.addCommas(value));
  12355. var name = data.getName(dataIndex);
  12356. var color = data.getItemVisual(dataIndex, 'color');
  12357. if (__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.isObject(color) && color.colorStops) {
  12358. color = (color.colorStops[0] || {}).color;
  12359. }
  12360. color = color || 'transparent';
  12361. var colorEl = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.format.getTooltipMarker(color);
  12362. var seriesName = seriesModel.name;
  12363. // FIXME
  12364. if (seriesName === '\0-') {
  12365. // Not show '-'
  12366. seriesName = '';
  12367. }
  12368. seriesName = seriesName
  12369. ? __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.format.encodeHTML(seriesName) + (!multipleSeries ? '<br/>' : ': ')
  12370. : '';
  12371. return !multipleSeries
  12372. ? seriesName + colorEl
  12373. + (name
  12374. ? __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.format.encodeHTML(name) + ': ' + formattedValue
  12375. : formattedValue
  12376. )
  12377. : colorEl + seriesName + formattedValue;
  12378. });;
  12379. /***/
  12380. }),
  12381. /* 40 */
  12382. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  12383. "use strict";
  12384. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Renderable__ = __webpack_require__(72);
  12385. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__core_glenum__ = __webpack_require__(11);
  12386. /**
  12387. * @constructor clay.Mesh
  12388. * @extends clay.Renderable
  12389. */
  12390. var Mesh = __WEBPACK_IMPORTED_MODULE_0__Renderable__["a" /* default */].extend(/** @lends clay.Mesh# */ {
  12391. /**
  12392. * Used when it is a skinned mesh
  12393. * @type {clay.Skeleton}
  12394. */
  12395. skeleton: null,
  12396. /**
  12397. * Joints indices Meshes can share the one skeleton instance and each mesh can use one part of joints. Joints indices indicate the index of joint in the skeleton instance
  12398. * @type {number[]}
  12399. */
  12400. joints: null,
  12401. /**
  12402. * If store the skin matrices in vertex texture
  12403. * @type {bool}
  12404. */
  12405. useSkinMatricesTexture: false
  12406. }, function () {
  12407. if (!this.joints) {
  12408. this.joints = [];
  12409. }
  12410. }, {
  12411. isSkinnedMesh: function () {
  12412. return !!(this.skeleton && this.joints && this.joints.length > 0);
  12413. },
  12414. clone: function () {
  12415. var mesh = __WEBPACK_IMPORTED_MODULE_0__Renderable__["a" /* default */].prototype.clone.call(this);
  12416. mesh.skeleton = this.skeleton;
  12417. if (this.joints) {
  12418. mesh.joints = this.joints.slice();
  12419. }
  12420. return mesh;
  12421. }
  12422. });
  12423. // Enums
  12424. Mesh.POINTS = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].POINTS;
  12425. Mesh.LINES = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LINES;
  12426. Mesh.LINE_LOOP = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LINE_LOOP;
  12427. Mesh.LINE_STRIP = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LINE_STRIP;
  12428. Mesh.TRIANGLES = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].TRIANGLES;
  12429. Mesh.TRIANGLE_STRIP = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].TRIANGLE_STRIP;
  12430. Mesh.TRIANGLE_FAN = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].TRIANGLE_FAN;
  12431. Mesh.BACK = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].BACK;
  12432. Mesh.FRONT = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].FRONT;
  12433. Mesh.FRONT_AND_BACK = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].FRONT_AND_BACK;
  12434. Mesh.CW = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].CW;
  12435. Mesh.CCW = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].CCW;
  12436. /* harmony default export */ __webpack_exports__["a"] = (Mesh);
  12437. /***/
  12438. }),
  12439. /* 41 */
  12440. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  12441. "use strict";
  12442. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Camera__ = __webpack_require__(58);
  12443. /**
  12444. * @constructor clay.camera.Perspective
  12445. * @extends clay.Camera
  12446. */
  12447. var Perspective = __WEBPACK_IMPORTED_MODULE_0__Camera__["a" /* default */].extend(/** @lends clay.camera.Perspective# */{
  12448. /**
  12449. * Vertical field of view in degrees
  12450. * @type {number}
  12451. */
  12452. fov: 50,
  12453. /**
  12454. * Aspect ratio, typically viewport width / height
  12455. * @type {number}
  12456. */
  12457. aspect: 1,
  12458. /**
  12459. * Near bound of the frustum
  12460. * @type {number}
  12461. */
  12462. near: 0.1,
  12463. /**
  12464. * Far bound of the frustum
  12465. * @type {number}
  12466. */
  12467. far: 2000
  12468. },
  12469. /** @lends clay.camera.Perspective.prototype */
  12470. {
  12471. updateProjectionMatrix: function () {
  12472. var rad = this.fov / 180 * Math.PI;
  12473. this.projectionMatrix.perspective(rad, this.aspect, this.near, this.far);
  12474. },
  12475. decomposeProjectionMatrix: function () {
  12476. var m = this.projectionMatrix.array;
  12477. var rad = Math.atan(1 / m[5]) * 2;
  12478. this.fov = rad / Math.PI * 180;
  12479. this.aspect = m[5] / m[0];
  12480. this.near = m[14] / (m[10] - 1);
  12481. this.far = m[14] / (m[10] + 1);
  12482. },
  12483. /**
  12484. * @return {clay.camera.Perspective}
  12485. */
  12486. clone: function () {
  12487. var camera = __WEBPACK_IMPORTED_MODULE_0__Camera__["a" /* default */].prototype.clone.call(this);
  12488. camera.fov = this.fov;
  12489. camera.aspect = this.aspect;
  12490. camera.near = this.near;
  12491. camera.far = this.far;
  12492. return camera;
  12493. }
  12494. });
  12495. /* harmony default export */ __webpack_exports__["a"] = (Perspective);
  12496. /***/
  12497. }),
  12498. /* 42 */
  12499. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  12500. "use strict";
  12501. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Mesh__ = __webpack_require__(40);
  12502. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__geometry_Cube__ = __webpack_require__(76);
  12503. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__Shader__ = __webpack_require__(8);
  12504. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__Material__ = __webpack_require__(19);
  12505. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__Texture__ = __webpack_require__(4);
  12506. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__shader_source_skybox_glsl_js__ = __webpack_require__(121);
  12507. // TODO Should not derived from mesh?
  12508. __WEBPACK_IMPORTED_MODULE_2__Shader__["a" /* default */].import(__WEBPACK_IMPORTED_MODULE_5__shader_source_skybox_glsl_js__["a" /* default */]);
  12509. /**
  12510. * @constructor clay.plugin.Skybox
  12511. *
  12512. * @example
  12513. * var skyTex = new clay.TextureCube();
  12514. * skyTex.load({
  12515. * 'px': 'assets/textures/sky/px.jpg',
  12516. * 'nx': 'assets/textures/sky/nx.jpg'
  12517. * 'py': 'assets/textures/sky/py.jpg'
  12518. * 'ny': 'assets/textures/sky/ny.jpg'
  12519. * 'pz': 'assets/textures/sky/pz.jpg'
  12520. * 'nz': 'assets/textures/sky/nz.jpg'
  12521. * });
  12522. * var skybox = new clay.plugin.Skybox({
  12523. * scene: scene
  12524. * });
  12525. * skybox.material.set('environmentMap', skyTex);
  12526. */
  12527. var Skybox = __WEBPACK_IMPORTED_MODULE_0__Mesh__["a" /* default */].extend(function () {
  12528. var skyboxShader = new __WEBPACK_IMPORTED_MODULE_2__Shader__["a" /* default */]({
  12529. vertex: __WEBPACK_IMPORTED_MODULE_2__Shader__["a" /* default */].source('clay.skybox.vertex'),
  12530. fragment: __WEBPACK_IMPORTED_MODULE_2__Shader__["a" /* default */].source('clay.skybox.fragment')
  12531. });
  12532. var material = new __WEBPACK_IMPORTED_MODULE_3__Material__["a" /* default */]({
  12533. shader: skyboxShader,
  12534. depthMask: false
  12535. });
  12536. return {
  12537. /**
  12538. * @type {clay.Scene}
  12539. * @memberOf clay.plugin.Skybox.prototype
  12540. */
  12541. scene: null,
  12542. geometry: new __WEBPACK_IMPORTED_MODULE_1__geometry_Cube__["a" /* default */](),
  12543. material: material,
  12544. environmentMap: null,
  12545. culling: false
  12546. };
  12547. }, function () {
  12548. var scene = this.scene;
  12549. if (scene) {
  12550. this.attachScene(scene);
  12551. }
  12552. if (this.environmentMap) {
  12553. this.setEnvironmentMap(this.environmentMap);
  12554. }
  12555. }, /** @lends clay.plugin.Skybox# */ {
  12556. /**
  12557. * Attach the skybox to the scene
  12558. * @param {clay.Scene} scene
  12559. */
  12560. attachScene: function (scene) {
  12561. if (this.scene) {
  12562. this.detachScene();
  12563. }
  12564. scene.skybox = this;
  12565. this.scene = scene;
  12566. scene.on('beforerender', this._beforeRenderScene, this);
  12567. },
  12568. /**
  12569. * Detach from scene
  12570. */
  12571. detachScene: function () {
  12572. if (this.scene) {
  12573. this.scene.off('beforerender', this._beforeRenderScene);
  12574. this.scene.skybox = null;
  12575. }
  12576. this.scene = null;
  12577. },
  12578. /**
  12579. * Dispose skybox
  12580. * @param {clay.Renderer} renderer
  12581. */
  12582. dispose: function (renderer) {
  12583. this.detachScene();
  12584. this.geometry.dispose(renderer);
  12585. },
  12586. /**
  12587. * Set environment map
  12588. * @param {clay.TextureCube} envMap
  12589. */
  12590. setEnvironmentMap: function (envMap) {
  12591. if (envMap.textureType === 'texture2D') {
  12592. this.material.define('EQUIRECTANGULAR');
  12593. // LINEAR filter can remove the artifacts in pole
  12594. envMap.minFilter = __WEBPACK_IMPORTED_MODULE_4__Texture__["a" /* default */].LINEAR;
  12595. }
  12596. else {
  12597. this.material.undefine('EQUIRECTANGULAR');
  12598. }
  12599. this.material.set('environmentMap', envMap);
  12600. },
  12601. /**
  12602. * Get environment map
  12603. * @return {clay.TextureCube}
  12604. */
  12605. getEnvironmentMap: function () {
  12606. return this.material.get('environmentMap');
  12607. },
  12608. _beforeRenderScene: function (renderer, scene, camera) {
  12609. this.renderSkybox(renderer, camera);
  12610. },
  12611. renderSkybox: function (renderer, camera) {
  12612. this.position.copy(camera.getWorldPosition());
  12613. this.update();
  12614. // Don't remember to disable blend
  12615. renderer.gl.disable(renderer.gl.BLEND);
  12616. if (this.material.get('lod') > 0) {
  12617. this.material.define('fragment', 'LOD');
  12618. }
  12619. else {
  12620. this.material.undefine('fragment', 'LOD');
  12621. }
  12622. renderer.renderPass([this], camera);
  12623. }
  12624. });
  12625. /* harmony default export */ __webpack_exports__["a"] = (Skybox);
  12626. /***/
  12627. }),
  12628. /* 43 */
  12629. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  12630. "use strict";
  12631. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Geometry__ = __webpack_require__(15);
  12632. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__math_BoundingBox__ = __webpack_require__(18);
  12633. /**
  12634. * @constructor clay.geometry.Plane
  12635. * @extends clay.Geometry
  12636. * @param {Object} [opt]
  12637. * @param {number} [opt.widthSegments]
  12638. * @param {number} [opt.heightSegments]
  12639. */
  12640. var Plane = __WEBPACK_IMPORTED_MODULE_0__Geometry__["a" /* default */].extend(
  12641. /** @lends clay.geometry.Plane# */
  12642. {
  12643. dynamic: false,
  12644. /**
  12645. * @type {number}
  12646. */
  12647. widthSegments: 1,
  12648. /**
  12649. * @type {number}
  12650. */
  12651. heightSegments: 1
  12652. }, function () {
  12653. this.build();
  12654. },
  12655. /** @lends clay.geometry.Plane.prototype */
  12656. {
  12657. /**
  12658. * Build plane geometry
  12659. */
  12660. build: function () {
  12661. var heightSegments = this.heightSegments;
  12662. var widthSegments = this.widthSegments;
  12663. var attributes = this.attributes;
  12664. var positions = [];
  12665. var texcoords = [];
  12666. var normals = [];
  12667. var faces = [];
  12668. for (var y = 0; y <= heightSegments; y++) {
  12669. var t = y / heightSegments;
  12670. for (var x = 0; x <= widthSegments; x++) {
  12671. var s = x / widthSegments;
  12672. positions.push([2 * s - 1, 2 * t - 1, 0]);
  12673. if (texcoords) {
  12674. texcoords.push([s, t]);
  12675. }
  12676. if (normals) {
  12677. normals.push([0, 0, 1]);
  12678. }
  12679. if (x < widthSegments && y < heightSegments) {
  12680. var i = x + y * (widthSegments + 1);
  12681. faces.push([i, i + 1, i + widthSegments + 1]);
  12682. faces.push([i + widthSegments + 1, i + 1, i + widthSegments + 2]);
  12683. }
  12684. }
  12685. }
  12686. attributes.position.fromArray(positions);
  12687. attributes.texcoord0.fromArray(texcoords);
  12688. attributes.normal.fromArray(normals);
  12689. this.initIndicesFromArray(faces);
  12690. this.boundingBox = new __WEBPACK_IMPORTED_MODULE_1__math_BoundingBox__["a" /* default */]();
  12691. this.boundingBox.min.set(-1, -1, 0);
  12692. this.boundingBox.max.set(1, 1, 0);
  12693. }
  12694. });
  12695. /* harmony default export */ __webpack_exports__["a"] = (Plane);
  12696. /***/
  12697. }),
  12698. /* 44 */
  12699. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  12700. "use strict";
  12701. /* harmony default export */ __webpack_exports__["a"] = ({
  12702. defaultOption: {
  12703. viewControl: {
  12704. // perspective, orthographic.
  12705. // TODO Isometric
  12706. projection: 'perspective',
  12707. // If rotate on on init
  12708. autoRotate: false,
  12709. // cw or ccw
  12710. autoRotateDirection: 'cw',
  12711. // Degree per second
  12712. autoRotateSpeed: 10,
  12713. // Start rotating after still for a given time
  12714. // default is 3 seconds
  12715. autoRotateAfterStill: 3,
  12716. // Rotate, zoom damping.
  12717. damping: 0.8,
  12718. // Sensitivities for operations.
  12719. // Can be array to set x,y respectively
  12720. rotateSensitivity: 1,
  12721. zoomSensitivity: 1,
  12722. // Can be array to set x,y respectively
  12723. panSensitivity: 1,
  12724. // Which mouse button do rotate or pan
  12725. panMouseButton: 'middle',
  12726. rotateMouseButton: 'left',
  12727. // Distance to the target
  12728. // Only available when camera is perspective.
  12729. distance: 150,
  12730. // Min distance mouse can zoom in
  12731. minDistance: 40,
  12732. // Max distance mouse can zoom out
  12733. maxDistance: 400,
  12734. // Size of viewing volume.
  12735. // Only available when camera is orthographic
  12736. orthographicSize: 150,
  12737. maxOrthographicSize: 400,
  12738. minOrthographicSize: 20,
  12739. // Center view point
  12740. center: [0, 0, 0],
  12741. // Alpha angle for top-down rotation
  12742. // Positive to rotate to top.
  12743. alpha: 0,
  12744. // beta angle for left-right rotation
  12745. // Positive to rotate to right.
  12746. beta: 0,
  12747. minAlpha: -90,
  12748. maxAlpha: 90
  12749. // minBeta: -Infinity
  12750. // maxBeta: -Infinity
  12751. }
  12752. },
  12753. setView: function (opts) {
  12754. opts = opts || {};
  12755. this.option.viewControl = this.option.viewControl || {};
  12756. if (opts.alpha != null) {
  12757. this.option.viewControl.alpha = opts.alpha;
  12758. }
  12759. if (opts.beta != null) {
  12760. this.option.viewControl.beta = opts.beta;
  12761. }
  12762. if (opts.distance != null) {
  12763. this.option.viewControl.distance = opts.distance;
  12764. }
  12765. if (opts.center != null) {
  12766. this.option.viewControl.center = opts.center;
  12767. }
  12768. }
  12769. });
  12770. /***/
  12771. }),
  12772. /* 45 */
  12773. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  12774. "use strict";
  12775. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_claygl_src_core_Base__ = __webpack_require__(7);
  12776. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_math_Vector2__ = __webpack_require__(26);
  12777. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_claygl_src_math_Vector3__ = __webpack_require__(3);
  12778. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_claygl_src_math_Quaternion__ = __webpack_require__(56);
  12779. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__retrieve__ = __webpack_require__(2);
  12780. /**
  12781. * Provide orbit control for 3D objects
  12782. *
  12783. * @module echarts-gl/util/OrbitControl
  12784. * @author Yi Shen(http://github.com/pissang)
  12785. */
  12786. // TODO Remove magic numbers on sensitivity
  12787. var firstNotNull = __WEBPACK_IMPORTED_MODULE_4__retrieve__["a" /* default */].firstNotNull;
  12788. var MOUSE_BUTTON_KEY_MAP = {
  12789. left: 0,
  12790. middle: 1,
  12791. right: 2
  12792. };
  12793. function convertToArray(val) {
  12794. if (!(val instanceof Array)) {
  12795. val = [val, val];
  12796. }
  12797. return val;
  12798. }
  12799. /**
  12800. * @alias module:echarts-x/util/OrbitControl
  12801. */
  12802. var OrbitControl = __WEBPACK_IMPORTED_MODULE_0_claygl_src_core_Base__["a" /* default */].extend(function () {
  12803. return {
  12804. /**
  12805. * @type {module:zrender~ZRender}
  12806. */
  12807. zr: null,
  12808. /**
  12809. * @type {module:echarts-gl/core/ViewGL}
  12810. */
  12811. viewGL: null,
  12812. /**
  12813. * @type {clay.math.Vector3}
  12814. */
  12815. _center: new __WEBPACK_IMPORTED_MODULE_2_claygl_src_math_Vector3__["a" /* default */](),
  12816. /**
  12817. * Minimum distance to the center
  12818. * Only available when camera is perspective.
  12819. * @type {number}
  12820. * @default 0.5
  12821. */
  12822. minDistance: 0.5,
  12823. /**
  12824. * Maximum distance to the center
  12825. * Only available when camera is perspective.
  12826. * @type {number}
  12827. * @default 2
  12828. */
  12829. maxDistance: 1.5,
  12830. /**
  12831. * Only available when camera is orthographic
  12832. */
  12833. maxOrthographicSize: 300,
  12834. /**
  12835. * Only available when camera is orthographic
  12836. */
  12837. minOrthographicSize: 30,
  12838. /**
  12839. * Minimum alpha rotation
  12840. */
  12841. minAlpha: -90,
  12842. /**
  12843. * Maximum alpha rotation
  12844. */
  12845. maxAlpha: 90,
  12846. /**
  12847. * Minimum beta rotation
  12848. */
  12849. minBeta: -Infinity,
  12850. /**
  12851. * Maximum beta rotation
  12852. */
  12853. maxBeta: Infinity,
  12854. /**
  12855. * Start auto rotating after still for the given time
  12856. */
  12857. autoRotateAfterStill: 0,
  12858. /**
  12859. * Direction of autoRotate. cw or ccw when looking top down.
  12860. */
  12861. autoRotateDirection: 'cw',
  12862. /**
  12863. * Degree per second
  12864. */
  12865. autoRotateSpeed: 60,
  12866. /**
  12867. * @param {number}
  12868. */
  12869. damping: 0.8,
  12870. /**
  12871. * @param {number}
  12872. */
  12873. rotateSensitivity: 1,
  12874. /**
  12875. * @param {number}
  12876. */
  12877. zoomSensitivity: 1,
  12878. /**
  12879. * @param {number}
  12880. */
  12881. panSensitivity: 1,
  12882. panMouseButton: 'middle',
  12883. rotateMouseButton: 'left',
  12884. /**
  12885. * Pan or rotate
  12886. * @private
  12887. * @type {String}
  12888. */
  12889. _mode: 'rotate',
  12890. /**
  12891. * @private
  12892. * @type {clay.Camera}
  12893. */
  12894. _camera: null,
  12895. _needsUpdate: false,
  12896. _rotating: false,
  12897. // Rotation around yAxis in radian
  12898. _phi: 0,
  12899. // Rotation around xAxis in radian
  12900. _theta: 0,
  12901. _mouseX: 0,
  12902. _mouseY: 0,
  12903. _rotateVelocity: new __WEBPACK_IMPORTED_MODULE_1_claygl_src_math_Vector2__["a" /* default */](),
  12904. _panVelocity: new __WEBPACK_IMPORTED_MODULE_1_claygl_src_math_Vector2__["a" /* default */](),
  12905. _distance: 500,
  12906. _zoomSpeed: 0,
  12907. _stillTimeout: 0,
  12908. _animators: []
  12909. };
  12910. }, function () {
  12911. // Each OrbitControl has it's own handler
  12912. ['_mouseDownHandler', '_mouseWheelHandler', '_mouseMoveHandler', '_mouseUpHandler',
  12913. '_pinchHandler', '_contextMenuHandler', '_update'].forEach(function (hdlName) {
  12914. this[hdlName] = this[hdlName].bind(this);
  12915. }, this);
  12916. }, {
  12917. /**
  12918. * Initialize.
  12919. * Mouse event binding
  12920. */
  12921. init: function () {
  12922. var zr = this.zr;
  12923. if (zr) {
  12924. zr.on('mousedown', this._mouseDownHandler);
  12925. zr.on('globalout', this._mouseUpHandler);
  12926. zr.on('mousewheel', this._mouseWheelHandler);
  12927. zr.on('pinch', this._pinchHandler);
  12928. zr.animation.on('frame', this._update);
  12929. zr.dom.addEventListener('contextmenu', this._contextMenuHandler);
  12930. }
  12931. },
  12932. /**
  12933. * Dispose.
  12934. * Mouse event unbinding
  12935. */
  12936. dispose: function () {
  12937. var zr = this.zr;
  12938. if (zr) {
  12939. zr.off('mousedown', this._mouseDownHandler);
  12940. zr.off('mousemove', this._mouseMoveHandler);
  12941. zr.off('mouseup', this._mouseUpHandler);
  12942. zr.off('mousewheel', this._mouseWheelHandler);
  12943. zr.off('pinch', this._pinchHandler);
  12944. zr.off('globalout', this._mouseUpHandler);
  12945. zr.dom.removeEventListener('contextmenu', this._contextMenuHandler);
  12946. zr.animation.off('frame', this._update);
  12947. }
  12948. this.stopAllAnimation();
  12949. },
  12950. /**
  12951. * Get distance
  12952. * @return {number}
  12953. */
  12954. getDistance: function () {
  12955. return this._distance;
  12956. },
  12957. /**
  12958. * Set distance
  12959. * @param {number} distance
  12960. */
  12961. setDistance: function (distance) {
  12962. this._distance = distance;
  12963. this._needsUpdate = true;
  12964. },
  12965. /**
  12966. * Get size of orthographic viewing volume
  12967. * @return {number}
  12968. */
  12969. getOrthographicSize: function () {
  12970. return this._orthoSize;
  12971. },
  12972. /**
  12973. * Set size of orthographic viewing volume
  12974. * @param {number} size
  12975. */
  12976. setOrthographicSize: function (size) {
  12977. this._orthoSize = size;
  12978. this._needsUpdate = true;
  12979. },
  12980. /**
  12981. * Get alpha rotation
  12982. * Alpha angle for top-down rotation. Positive to rotate to top.
  12983. *
  12984. * Which means camera rotation around x axis.
  12985. */
  12986. getAlpha: function () {
  12987. return this._theta / Math.PI * 180;
  12988. },
  12989. /**
  12990. * Get beta rotation
  12991. * Beta angle for left-right rotation. Positive to rotate to right.
  12992. *
  12993. * Which means camera rotation around y axis.
  12994. */
  12995. getBeta: function () {
  12996. return -this._phi / Math.PI * 180;
  12997. },
  12998. /**
  12999. * Get control center
  13000. * @return {Array.<number>}
  13001. */
  13002. getCenter: function () {
  13003. return this._center.toArray();
  13004. },
  13005. /**
  13006. * Set alpha rotation angle
  13007. * @param {number} alpha
  13008. */
  13009. setAlpha: function (alpha) {
  13010. alpha = Math.max(Math.min(this.maxAlpha, alpha), this.minAlpha);
  13011. this._theta = alpha / 180 * Math.PI;
  13012. this._needsUpdate = true;
  13013. },
  13014. /**
  13015. * Set beta rotation angle
  13016. * @param {number} beta
  13017. */
  13018. setBeta: function (beta) {
  13019. beta = Math.max(Math.min(this.maxBeta, beta), this.minBeta);
  13020. this._phi = -beta / 180 * Math.PI;
  13021. this._needsUpdate = true;
  13022. },
  13023. /**
  13024. * Set control center
  13025. * @param {Array.<number>} center
  13026. */
  13027. setCenter: function (centerArr) {
  13028. this._center.setArray(centerArr);
  13029. },
  13030. /**
  13031. * @param {module:echarts-gl/core/ViewGL} viewGL
  13032. */
  13033. setViewGL: function (viewGL) {
  13034. this.viewGL = viewGL;
  13035. },
  13036. /**
  13037. * @return {clay.Camera}
  13038. */
  13039. getCamera: function () {
  13040. return this.viewGL.camera;
  13041. },
  13042. setFromViewControlModel: function (viewControlModel, extraOpts) {
  13043. extraOpts = extraOpts || {};
  13044. var baseDistance = extraOpts.baseDistance || 0;
  13045. var baseOrthoSize = extraOpts.baseOrthoSize || 1;
  13046. var projection = viewControlModel.get('projection');
  13047. if (projection !== 'perspective' && projection !== 'orthographic' && projection !== 'isometric') {
  13048. if (true) {
  13049. console.error('Unkown projection type %s, use perspective projection instead.', projection);
  13050. }
  13051. projection = 'perspective';
  13052. }
  13053. this._projection = projection;
  13054. this.viewGL.setProjection(projection);
  13055. var targetDistance = viewControlModel.get('distance') + baseDistance;
  13056. var targetOrthographicSize = viewControlModel.get('orthographicSize') + baseOrthoSize;
  13057. [
  13058. ['damping', 0.8],
  13059. ['autoRotate', false],
  13060. ['autoRotateAfterStill', 3],
  13061. ['autoRotateDirection', 'cw'],
  13062. ['autoRotateSpeed', 10],
  13063. ['minDistance', 30],
  13064. ['maxDistance', 400],
  13065. ['minOrthographicSize', 30],
  13066. ['maxOrthographicSize', 300],
  13067. ['minAlpha', -90],
  13068. ['maxAlpha', 90],
  13069. ['minBeta', -Infinity],
  13070. ['maxBeta', Infinity],
  13071. ['rotateSensitivity', 1],
  13072. ['zoomSensitivity', 1],
  13073. ['panSensitivity', 1],
  13074. ['panMouseButton', 'left'],
  13075. ['rotateMouseButton', 'middle'],
  13076. ].forEach(function (prop) {
  13077. this[prop[0]] = firstNotNull(viewControlModel.get(prop[0]), prop[1]);
  13078. }, this);
  13079. this.minDistance += baseDistance;
  13080. this.maxDistance += baseDistance;
  13081. this.minOrthographicSize += baseOrthoSize,
  13082. this.maxOrthographicSize += baseOrthoSize;
  13083. var ecModel = viewControlModel.ecModel;
  13084. var animationOpts = {};
  13085. ['animation', 'animationDurationUpdate', 'animationEasingUpdate'].forEach(function (key) {
  13086. animationOpts[key] = firstNotNull(
  13087. viewControlModel.get(key), ecModel && ecModel.get(key)
  13088. );
  13089. });
  13090. var alpha = firstNotNull(extraOpts.alpha, viewControlModel.get('alpha')) || 0;
  13091. var beta = firstNotNull(extraOpts.beta, viewControlModel.get('beta')) || 0;
  13092. var center = firstNotNull(extraOpts.center, viewControlModel.get('center')) || [0, 0, 0];
  13093. if (animationOpts.animation && animationOpts.animationDurationUpdate > 0 && this._notFirst) {
  13094. this.animateTo({
  13095. alpha: alpha,
  13096. beta: beta,
  13097. center: center,
  13098. distance: targetDistance,
  13099. targetOrthographicSize: targetOrthographicSize,
  13100. easing: animationOpts.animationEasingUpdate,
  13101. duration: animationOpts.animationDurationUpdate
  13102. });
  13103. }
  13104. else {
  13105. this.setDistance(targetDistance);
  13106. this.setAlpha(alpha);
  13107. this.setBeta(beta);
  13108. this.setCenter(center);
  13109. this.setOrthographicSize(targetOrthographicSize);
  13110. }
  13111. this._notFirst = true;
  13112. this._validateProperties();
  13113. },
  13114. _validateProperties: function () {
  13115. if (true) {
  13116. if (MOUSE_BUTTON_KEY_MAP[this.panMouseButton] == null) {
  13117. console.error('Unkown panMouseButton %s. It should be left|middle|right', this.panMouseButton);
  13118. }
  13119. if (MOUSE_BUTTON_KEY_MAP[this.rotateMouseButton] == null) {
  13120. console.error('Unkown rotateMouseButton %s. It should be left|middle|right', this.rotateMouseButton);
  13121. }
  13122. if (this.autoRotateDirection !== 'cw' && this.autoRotateDirection !== 'ccw') {
  13123. console.error('Unkown autoRotateDirection %s. It should be cw|ccw', this.autoRotateDirection);
  13124. }
  13125. }
  13126. },
  13127. /**
  13128. * @param {Object} opts
  13129. * @param {number} opts.distance
  13130. * @param {number} opts.alpha
  13131. * @param {number} opts.beta
  13132. * @param {number} opts.orthographicSize
  13133. * @param {number} [opts.duration=1000]
  13134. * @param {number} [opts.easing='linear']
  13135. */
  13136. animateTo: function (opts) {
  13137. var zr = this.zr;
  13138. var self = this;
  13139. var obj = {};
  13140. var target = {};
  13141. if (opts.distance != null) {
  13142. obj.distance = this.getDistance();
  13143. target.distance = opts.distance;
  13144. }
  13145. if (opts.orthographicSize != null) {
  13146. obj.orthographicSize = this.getOrthographicSize();
  13147. target.orthographicSize = opts.orthographicSize;
  13148. }
  13149. if (opts.alpha != null) {
  13150. obj.alpha = this.getAlpha();
  13151. target.alpha = opts.alpha;
  13152. }
  13153. if (opts.beta != null) {
  13154. obj.beta = this.getBeta();
  13155. target.beta = opts.beta;
  13156. }
  13157. if (opts.center != null) {
  13158. obj.center = this.getCenter();
  13159. target.center = opts.center;
  13160. }
  13161. return this._addAnimator(
  13162. zr.animation.animate(obj)
  13163. .when(opts.duration || 1000, target)
  13164. .during(function () {
  13165. if (obj.alpha != null) {
  13166. self.setAlpha(obj.alpha);
  13167. }
  13168. if (obj.beta != null) {
  13169. self.setBeta(obj.beta);
  13170. }
  13171. if (obj.distance != null) {
  13172. self.setDistance(obj.distance);
  13173. }
  13174. if (obj.center != null) {
  13175. self.setCenter(obj.center);
  13176. }
  13177. if (obj.orthographicSize != null) {
  13178. self.setOrthographicSize(obj.orthographicSize);
  13179. }
  13180. self._needsUpdate = true;
  13181. })
  13182. ).start(opts.easing || 'linear');
  13183. },
  13184. /**
  13185. * Stop all animation
  13186. */
  13187. stopAllAnimation: function () {
  13188. for (var i = 0; i < this._animators.length; i++) {
  13189. this._animators[i].stop();
  13190. }
  13191. this._animators.length = 0;
  13192. },
  13193. update: function () {
  13194. this._needsUpdate = true;
  13195. this._update(20);
  13196. },
  13197. _isAnimating: function () {
  13198. return this._animators.length > 0;
  13199. },
  13200. /**
  13201. * Call update each frame
  13202. * @param {number} deltaTime Frame time
  13203. */
  13204. _update: function (deltaTime) {
  13205. if (this._rotating) {
  13206. var radian = (this.autoRotateDirection === 'cw' ? 1 : -1)
  13207. * this.autoRotateSpeed / 180 * Math.PI;
  13208. this._phi -= radian * deltaTime / 1000;
  13209. this._needsUpdate = true;
  13210. }
  13211. else if (this._rotateVelocity.len() > 0) {
  13212. this._needsUpdate = true;
  13213. }
  13214. if (Math.abs(this._zoomSpeed) > 0.1 || this._panVelocity.len() > 0) {
  13215. this._needsUpdate = true;
  13216. }
  13217. if (!this._needsUpdate) {
  13218. return;
  13219. }
  13220. deltaTime = Math.min(deltaTime, 50);
  13221. this._updateDistanceOrSize(deltaTime);
  13222. this._updatePan(deltaTime);
  13223. this._updateRotate(deltaTime);
  13224. this._updateTransform();
  13225. this.getCamera().update();
  13226. this.zr && this.zr.refresh();
  13227. this.trigger('update');
  13228. this._needsUpdate = false;
  13229. },
  13230. _updateRotate: function (deltaTime) {
  13231. var velocity = this._rotateVelocity;
  13232. this._phi = velocity.y * deltaTime / 20 + this._phi;
  13233. this._theta = velocity.x * deltaTime / 20 + this._theta;
  13234. this.setAlpha(this.getAlpha());
  13235. this.setBeta(this.getBeta());
  13236. this._vectorDamping(velocity, Math.pow(this.damping, deltaTime / 16));
  13237. },
  13238. _updateDistanceOrSize: function (deltaTime) {
  13239. if (this._projection === 'perspective') {
  13240. this._setDistance(this._distance + this._zoomSpeed * deltaTime / 20);
  13241. }
  13242. else {
  13243. this._setOrthoSize(this._orthoSize + this._zoomSpeed * deltaTime / 20);
  13244. }
  13245. this._zoomSpeed *= Math.pow(this.damping, deltaTime / 16);
  13246. },
  13247. _setDistance: function (distance) {
  13248. this._distance = Math.max(Math.min(distance, this.maxDistance), this.minDistance);
  13249. },
  13250. _setOrthoSize: function (size) {
  13251. this._orthoSize = Math.max(Math.min(size, this.maxOrthographicSize), this.minOrthographicSize);
  13252. var camera = this.getCamera();
  13253. var cameraHeight = this._orthoSize;
  13254. var cameraWidth = cameraHeight / this.viewGL.viewport.height * this.viewGL.viewport.width;
  13255. camera.left = -cameraWidth / 2;
  13256. camera.right = cameraWidth / 2;
  13257. camera.top = cameraHeight / 2;
  13258. camera.bottom = -cameraHeight / 2;
  13259. },
  13260. _updatePan: function (deltaTime) {
  13261. var velocity = this._panVelocity;
  13262. var len = this._distance;
  13263. var target = this.getCamera();
  13264. var yAxis = target.worldTransform.y;
  13265. var xAxis = target.worldTransform.x;
  13266. // PENDING
  13267. this._center
  13268. .scaleAndAdd(xAxis, -velocity.x * len / 200)
  13269. .scaleAndAdd(yAxis, -velocity.y * len / 200);
  13270. this._vectorDamping(velocity, 0);
  13271. },
  13272. _updateTransform: function () {
  13273. var camera = this.getCamera();
  13274. var dir = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_math_Vector3__["a" /* default */]();
  13275. var theta = this._theta + Math.PI / 2;
  13276. var phi = this._phi + Math.PI / 2;
  13277. var r = Math.sin(theta);
  13278. dir.x = r * Math.cos(phi);
  13279. dir.y = -Math.cos(theta);
  13280. dir.z = r * Math.sin(phi);
  13281. camera.position.copy(this._center).scaleAndAdd(dir, this._distance);
  13282. camera.rotation.identity()
  13283. // First around y, then around x
  13284. .rotateY(-this._phi)
  13285. .rotateX(-this._theta);
  13286. },
  13287. _startCountingStill: function () {
  13288. clearTimeout(this._stillTimeout);
  13289. var time = this.autoRotateAfterStill;
  13290. var self = this;
  13291. if (!isNaN(time) && time > 0) {
  13292. this._stillTimeout = setTimeout(function () {
  13293. self._rotating = true;
  13294. }, time * 1000);
  13295. }
  13296. },
  13297. _vectorDamping: function (v, damping) {
  13298. var speed = v.len();
  13299. speed = speed * damping;
  13300. if (speed < 1e-4) {
  13301. speed = 0;
  13302. }
  13303. v.normalize().scale(speed);
  13304. },
  13305. _decomposeTransform: function () {
  13306. if (!this.getCamera()) {
  13307. return;
  13308. }
  13309. this.getCamera().updateWorldTransform();
  13310. var forward = this.getCamera().worldTransform.z;
  13311. var alpha = Math.asin(forward.y);
  13312. var beta = Math.atan2(forward.x, forward.z);
  13313. this._theta = alpha;
  13314. this._phi = -beta;
  13315. this.setBeta(this.getBeta());
  13316. this.setAlpha(this.getAlpha());
  13317. // Is perspective
  13318. if (this.getCamera().aspect) {
  13319. this._setDistance(this.getCamera().position.dist(this._center));
  13320. }
  13321. else {
  13322. this._setOrthoSize(this.getCamera().top - this.getCamera().bottom);
  13323. }
  13324. },
  13325. _mouseDownHandler: function (e) {
  13326. if (e.target) {
  13327. // If mouseon some zrender element.
  13328. return;
  13329. }
  13330. if (this._isAnimating()) {
  13331. return;
  13332. }
  13333. var x = e.offsetX;
  13334. var y = e.offsetY;
  13335. if (this.viewGL && !this.viewGL.containPoint(x, y)) {
  13336. return;
  13337. }
  13338. this.zr.on('mousemove', this._mouseMoveHandler);
  13339. this.zr.on('mouseup', this._mouseUpHandler);
  13340. if (e.event.targetTouches) {
  13341. if (e.event.targetTouches.length === 1) {
  13342. this._mode = 'rotate';
  13343. }
  13344. }
  13345. else {
  13346. if (e.event.button === MOUSE_BUTTON_KEY_MAP[this.rotateMouseButton]) {
  13347. this._mode = 'rotate';
  13348. }
  13349. else if (e.event.button === MOUSE_BUTTON_KEY_MAP[this.panMouseButton]) {
  13350. this._mode = 'pan';
  13351. }
  13352. else {
  13353. this._mode = '';
  13354. }
  13355. }
  13356. // Reset rotate velocity
  13357. this._rotateVelocity.set(0, 0);
  13358. this._rotating = false;
  13359. if (this.autoRotate) {
  13360. this._startCountingStill();
  13361. }
  13362. this._mouseX = e.offsetX;
  13363. this._mouseY = e.offsetY;
  13364. },
  13365. _mouseMoveHandler: function (e) {
  13366. if (e.target && e.target.__isGLToZRProxy) {
  13367. return;
  13368. }
  13369. if (this._isAnimating()) {
  13370. return;
  13371. }
  13372. var panSensitivity = convertToArray(this.panSensitivity);
  13373. var rotateSensitivity = convertToArray(this.rotateSensitivity);
  13374. if (this._mode === 'rotate') {
  13375. this._rotateVelocity.y = (e.offsetX - this._mouseX) / this.zr.getHeight() * 2 * rotateSensitivity[0];
  13376. this._rotateVelocity.x = (e.offsetY - this._mouseY) / this.zr.getWidth() * 2 * rotateSensitivity[1];
  13377. }
  13378. else if (this._mode === 'pan') {
  13379. this._panVelocity.x = (e.offsetX - this._mouseX) / this.zr.getWidth() * panSensitivity[0] * 400;
  13380. this._panVelocity.y = (-e.offsetY + this._mouseY) / this.zr.getHeight() * panSensitivity[1] * 400;
  13381. }
  13382. this._mouseX = e.offsetX;
  13383. this._mouseY = e.offsetY;
  13384. e.event.preventDefault();
  13385. },
  13386. _mouseWheelHandler: function (e) {
  13387. if (this._isAnimating()) {
  13388. return;
  13389. }
  13390. var delta = e.event.wheelDelta // Webkit
  13391. || -e.event.detail; // Firefox
  13392. this._zoomHandler(e, delta);
  13393. },
  13394. _pinchHandler: function (e) {
  13395. if (this._isAnimating()) {
  13396. return;
  13397. }
  13398. this._zoomHandler(e, e.pinchScale > 1 ? 1 : -1);
  13399. // Not rotate when pinch
  13400. this._mode = '';
  13401. },
  13402. _zoomHandler: function (e, delta) {
  13403. if (delta === 0) {
  13404. return;
  13405. }
  13406. var x = e.offsetX;
  13407. var y = e.offsetY;
  13408. if (this.viewGL && !this.viewGL.containPoint(x, y)) {
  13409. return;
  13410. }
  13411. var speed;
  13412. if (this._projection === 'perspective') {
  13413. speed = Math.max(Math.max(Math.min(
  13414. this._distance - this.minDistance,
  13415. this.maxDistance - this._distance
  13416. )) / 20, 0.5);
  13417. }
  13418. else {
  13419. speed = Math.max(Math.max(Math.min(
  13420. this._orthoSize - this.minOrthographicSize,
  13421. this.maxOrthographicSize - this._orthoSize
  13422. )) / 20, 0.5);
  13423. }
  13424. this._zoomSpeed = (delta > 0 ? -1 : 1) * speed * this.zoomSensitivity;
  13425. this._rotating = false;
  13426. if (this.autoRotate && this._mode === 'rotate') {
  13427. this._startCountingStill();
  13428. }
  13429. e.event.preventDefault();
  13430. },
  13431. _mouseUpHandler: function () {
  13432. this.zr.off('mousemove', this._mouseMoveHandler);
  13433. this.zr.off('mouseup', this._mouseUpHandler);
  13434. },
  13435. _isRightMouseButtonUsed: function () {
  13436. return this.rotateMouseButton === 'right'
  13437. || this.panMouseButton === 'right';
  13438. },
  13439. _contextMenuHandler: function (e) {
  13440. if (this._isRightMouseButtonUsed()) {
  13441. e.preventDefault();
  13442. }
  13443. },
  13444. _addAnimator: function (animator) {
  13445. var animators = this._animators;
  13446. animators.push(animator);
  13447. animator.done(function () {
  13448. var idx = animators.indexOf(animator);
  13449. if (idx >= 0) {
  13450. animators.splice(idx, 1);
  13451. }
  13452. });
  13453. return animator;
  13454. }
  13455. });
  13456. /**
  13457. * If auto rotate the target
  13458. * @type {boolean}
  13459. * @default false
  13460. */
  13461. Object.defineProperty(OrbitControl.prototype, 'autoRotate', {
  13462. get: function (val) {
  13463. return this._autoRotate;
  13464. },
  13465. set: function (val) {
  13466. this._autoRotate = val;
  13467. this._rotating = val;
  13468. }
  13469. });
  13470. /* harmony default export */ __webpack_exports__["a"] = (OrbitControl);
  13471. /***/
  13472. }),
  13473. /* 46 */
  13474. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  13475. "use strict";
  13476. /* harmony default export */ __webpack_exports__["a"] = ("@export ecgl.lines3D.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position: POSITION;\nattribute vec4 a_Color : COLOR;\nvarying vec4 v_Color;\n\nvoid main()\n{\n gl_Position = worldViewProjection * vec4(position, 1.0);\n v_Color = a_Color;\n}\n\n@end\n\n@export ecgl.lines3D.fragment\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\n\nvarying vec4 v_Color;\n\n@import clay.util.srgb\n\nvoid main()\n{\n#ifdef SRGB_DECODE\n gl_FragColor = sRGBToLinear(color * v_Color);\n#else\n gl_FragColor = color * v_Color;\n#endif\n}\n@end\n\n\n\n@export ecgl.lines3D.clipNear\n\nvec4 clipNear(vec4 p1, vec4 p2) {\n float n = (p1.w - near) / (p1.w - p2.w);\n return vec4(mix(p1.xy, p2.xy, n), -near, near);\n}\n\n@end\n\n@export ecgl.lines3D.expandLine\n#ifdef VERTEX_ANIMATION\n vec4 prevProj = worldViewProjection * vec4(mix(prevPositionPrev, positionPrev, percent), 1.0);\n vec4 currProj = worldViewProjection * vec4(mix(prevPosition, position, percent), 1.0);\n vec4 nextProj = worldViewProjection * vec4(mix(prevPositionNext, positionNext, percent), 1.0);\n#else\n vec4 prevProj = worldViewProjection * vec4(positionPrev, 1.0);\n vec4 currProj = worldViewProjection * vec4(position, 1.0);\n vec4 nextProj = worldViewProjection * vec4(positionNext, 1.0);\n#endif\n\n if (currProj.w < 0.0) {\n if (nextProj.w > 0.0) {\n currProj = clipNear(currProj, nextProj);\n }\n else if (prevProj.w > 0.0) {\n currProj = clipNear(currProj, prevProj);\n }\n }\n\n vec2 prevScreen = (prevProj.xy / abs(prevProj.w) + 1.0) * 0.5 * viewport.zw;\n vec2 currScreen = (currProj.xy / abs(currProj.w) + 1.0) * 0.5 * viewport.zw;\n vec2 nextScreen = (nextProj.xy / abs(nextProj.w) + 1.0) * 0.5 * viewport.zw;\n\n vec2 dir;\n float len = offset;\n if (position == positionPrev) {\n dir = normalize(nextScreen - currScreen);\n }\n else if (position == positionNext) {\n dir = normalize(currScreen - prevScreen);\n }\n else {\n vec2 dirA = normalize(currScreen - prevScreen);\n vec2 dirB = normalize(nextScreen - currScreen);\n\n vec2 tanget = normalize(dirA + dirB);\n\n float miter = 1.0 / max(dot(tanget, dirA), 0.5);\n len *= miter;\n dir = tanget;\n }\n\n dir = vec2(-dir.y, dir.x) * len;\n currScreen += dir;\n\n currProj.xy = (currScreen / viewport.zw - 0.5) * 2.0 * abs(currProj.w);\n@end\n\n\n@export ecgl.meshLines3D.vertex\n\nattribute vec3 position: POSITION;\nattribute vec3 positionPrev;\nattribute vec3 positionNext;\nattribute float offset;\nattribute vec4 a_Color : COLOR;\n\n#ifdef VERTEX_ANIMATION\nattribute vec3 prevPosition;\nattribute vec3 prevPositionPrev;\nattribute vec3 prevPositionNext;\nuniform float percent : 1.0;\n#endif\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform vec4 viewport : VIEWPORT;\nuniform float near : NEAR;\n\nvarying vec4 v_Color;\n\n@import ecgl.common.wireframe.vertexHeader\n\n@import ecgl.lines3D.clipNear\n\nvoid main()\n{\n @import ecgl.lines3D.expandLine\n\n gl_Position = currProj;\n\n v_Color = a_Color;\n\n @import ecgl.common.wireframe.vertexMain\n}\n@end\n\n\n@export ecgl.meshLines3D.fragment\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\n\nvarying vec4 v_Color;\n\n@import ecgl.common.wireframe.fragmentHeader\n\n@import clay.util.srgb\n\nvoid main()\n{\n#ifdef SRGB_DECODE\n gl_FragColor = sRGBToLinear(color * v_Color);\n#else\n gl_FragColor = color * v_Color;\n#endif\n\n @import ecgl.common.wireframe.fragmentMain\n}\n\n@end");
  13477. /***/
  13478. }),
  13479. /* 47 */
  13480. /***/ (function (module, exports, __webpack_require__) {
  13481. var zrUtil = __webpack_require__(13);
  13482. var BoundingRect = __webpack_require__(82);
  13483. var _number = __webpack_require__(85);
  13484. var parsePercent = _number.parsePercent;
  13485. var formatUtil = __webpack_require__(171);
  13486. /*
  13487. * Licensed to the Apache Software Foundation (ASF) under one
  13488. * or more contributor license agreements. See the NOTICE file
  13489. * distributed with this work for additional information
  13490. * regarding copyright ownership. The ASF licenses this file
  13491. * to you under the Apache License, Version 2.0 (the
  13492. * "License"); you may not use this file except in compliance
  13493. * with the License. You may obtain a copy of the License at
  13494. *
  13495. * http://www.apache.org/licenses/LICENSE-2.0
  13496. *
  13497. * Unless required by applicable law or agreed to in writing,
  13498. * software distributed under the License is distributed on an
  13499. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13500. * KIND, either express or implied. See the License for the
  13501. * specific language governing permissions and limitations
  13502. * under the License.
  13503. */
  13504. // Layout helpers for each component positioning
  13505. var each = zrUtil.each;
  13506. /**
  13507. * @public
  13508. */
  13509. var LOCATION_PARAMS = ['left', 'right', 'top', 'bottom', 'width', 'height'];
  13510. /**
  13511. * @public
  13512. */
  13513. var HV_NAMES = [['width', 'left', 'right'], ['height', 'top', 'bottom']];
  13514. function boxLayout(orient, group, gap, maxWidth, maxHeight) {
  13515. var x = 0;
  13516. var y = 0;
  13517. if (maxWidth == null) {
  13518. maxWidth = Infinity;
  13519. }
  13520. if (maxHeight == null) {
  13521. maxHeight = Infinity;
  13522. }
  13523. var currentLineMaxSize = 0;
  13524. group.eachChild(function (child, idx) {
  13525. var position = child.position;
  13526. var rect = child.getBoundingRect();
  13527. var nextChild = group.childAt(idx + 1);
  13528. var nextChildRect = nextChild && nextChild.getBoundingRect();
  13529. var nextX;
  13530. var nextY;
  13531. if (orient === 'horizontal') {
  13532. var moveX = rect.width + (nextChildRect ? -nextChildRect.x + rect.x : 0);
  13533. nextX = x + moveX; // Wrap when width exceeds maxWidth or meet a `newline` group
  13534. // FIXME compare before adding gap?
  13535. if (nextX > maxWidth || child.newline) {
  13536. x = 0;
  13537. nextX = moveX;
  13538. y += currentLineMaxSize + gap;
  13539. currentLineMaxSize = rect.height;
  13540. } else {
  13541. // FIXME: consider rect.y is not `0`?
  13542. currentLineMaxSize = Math.max(currentLineMaxSize, rect.height);
  13543. }
  13544. } else {
  13545. var moveY = rect.height + (nextChildRect ? -nextChildRect.y + rect.y : 0);
  13546. nextY = y + moveY; // Wrap when width exceeds maxHeight or meet a `newline` group
  13547. if (nextY > maxHeight || child.newline) {
  13548. x += currentLineMaxSize + gap;
  13549. y = 0;
  13550. nextY = moveY;
  13551. currentLineMaxSize = rect.width;
  13552. } else {
  13553. currentLineMaxSize = Math.max(currentLineMaxSize, rect.width);
  13554. }
  13555. }
  13556. if (child.newline) {
  13557. return;
  13558. }
  13559. position[0] = x;
  13560. position[1] = y;
  13561. orient === 'horizontal' ? x = nextX + gap : y = nextY + gap;
  13562. });
  13563. }
  13564. /**
  13565. * VBox or HBox layouting
  13566. * @param {string} orient
  13567. * @param {module:zrender/container/Group} group
  13568. * @param {number} gap
  13569. * @param {number} [width=Infinity]
  13570. * @param {number} [height=Infinity]
  13571. */
  13572. var box = boxLayout;
  13573. /**
  13574. * VBox layouting
  13575. * @param {module:zrender/container/Group} group
  13576. * @param {number} gap
  13577. * @param {number} [width=Infinity]
  13578. * @param {number} [height=Infinity]
  13579. */
  13580. var vbox = zrUtil.curry(boxLayout, 'vertical');
  13581. /**
  13582. * HBox layouting
  13583. * @param {module:zrender/container/Group} group
  13584. * @param {number} gap
  13585. * @param {number} [width=Infinity]
  13586. * @param {number} [height=Infinity]
  13587. */
  13588. var hbox = zrUtil.curry(boxLayout, 'horizontal');
  13589. /**
  13590. * If x or x2 is not specified or 'center' 'left' 'right',
  13591. * the width would be as long as possible.
  13592. * If y or y2 is not specified or 'middle' 'top' 'bottom',
  13593. * the height would be as long as possible.
  13594. *
  13595. * @param {Object} positionInfo
  13596. * @param {number|string} [positionInfo.x]
  13597. * @param {number|string} [positionInfo.y]
  13598. * @param {number|string} [positionInfo.x2]
  13599. * @param {number|string} [positionInfo.y2]
  13600. * @param {Object} containerRect {width, height}
  13601. * @param {string|number} margin
  13602. * @return {Object} {width, height}
  13603. */
  13604. function getAvailableSize(positionInfo, containerRect, margin) {
  13605. var containerWidth = containerRect.width;
  13606. var containerHeight = containerRect.height;
  13607. var x = parsePercent(positionInfo.x, containerWidth);
  13608. var y = parsePercent(positionInfo.y, containerHeight);
  13609. var x2 = parsePercent(positionInfo.x2, containerWidth);
  13610. var y2 = parsePercent(positionInfo.y2, containerHeight);
  13611. (isNaN(x) || isNaN(parseFloat(positionInfo.x))) && (x = 0);
  13612. (isNaN(x2) || isNaN(parseFloat(positionInfo.x2))) && (x2 = containerWidth);
  13613. (isNaN(y) || isNaN(parseFloat(positionInfo.y))) && (y = 0);
  13614. (isNaN(y2) || isNaN(parseFloat(positionInfo.y2))) && (y2 = containerHeight);
  13615. margin = formatUtil.normalizeCssArray(margin || 0);
  13616. return {
  13617. width: Math.max(x2 - x - margin[1] - margin[3], 0),
  13618. height: Math.max(y2 - y - margin[0] - margin[2], 0)
  13619. };
  13620. }
  13621. /**
  13622. * Parse position info.
  13623. *
  13624. * @param {Object} positionInfo
  13625. * @param {number|string} [positionInfo.left]
  13626. * @param {number|string} [positionInfo.top]
  13627. * @param {number|string} [positionInfo.right]
  13628. * @param {number|string} [positionInfo.bottom]
  13629. * @param {number|string} [positionInfo.width]
  13630. * @param {number|string} [positionInfo.height]
  13631. * @param {number|string} [positionInfo.aspect] Aspect is width / height
  13632. * @param {Object} containerRect
  13633. * @param {string|number} [margin]
  13634. *
  13635. * @return {module:zrender/core/BoundingRect}
  13636. */
  13637. function getLayoutRect(positionInfo, containerRect, margin) {
  13638. margin = formatUtil.normalizeCssArray(margin || 0);
  13639. var containerWidth = containerRect.width;
  13640. var containerHeight = containerRect.height;
  13641. var left = parsePercent(positionInfo.left, containerWidth);
  13642. var top = parsePercent(positionInfo.top, containerHeight);
  13643. var right = parsePercent(positionInfo.right, containerWidth);
  13644. var bottom = parsePercent(positionInfo.bottom, containerHeight);
  13645. var width = parsePercent(positionInfo.width, containerWidth);
  13646. var height = parsePercent(positionInfo.height, containerHeight);
  13647. var verticalMargin = margin[2] + margin[0];
  13648. var horizontalMargin = margin[1] + margin[3];
  13649. var aspect = positionInfo.aspect; // If width is not specified, calculate width from left and right
  13650. if (isNaN(width)) {
  13651. width = containerWidth - right - horizontalMargin - left;
  13652. }
  13653. if (isNaN(height)) {
  13654. height = containerHeight - bottom - verticalMargin - top;
  13655. }
  13656. if (aspect != null) {
  13657. // If width and height are not given
  13658. // 1. Graph should not exceeds the container
  13659. // 2. Aspect must be keeped
  13660. // 3. Graph should take the space as more as possible
  13661. // FIXME
  13662. // Margin is not considered, because there is no case that both
  13663. // using margin and aspect so far.
  13664. if (isNaN(width) && isNaN(height)) {
  13665. if (aspect > containerWidth / containerHeight) {
  13666. width = containerWidth * 0.8;
  13667. } else {
  13668. height = containerHeight * 0.8;
  13669. }
  13670. } // Calculate width or height with given aspect
  13671. if (isNaN(width)) {
  13672. width = aspect * height;
  13673. }
  13674. if (isNaN(height)) {
  13675. height = width / aspect;
  13676. }
  13677. } // If left is not specified, calculate left from right and width
  13678. if (isNaN(left)) {
  13679. left = containerWidth - right - width - horizontalMargin;
  13680. }
  13681. if (isNaN(top)) {
  13682. top = containerHeight - bottom - height - verticalMargin;
  13683. } // Align left and top
  13684. switch (positionInfo.left || positionInfo.right) {
  13685. case 'center':
  13686. left = containerWidth / 2 - width / 2 - margin[3];
  13687. break;
  13688. case 'right':
  13689. left = containerWidth - width - horizontalMargin;
  13690. break;
  13691. }
  13692. switch (positionInfo.top || positionInfo.bottom) {
  13693. case 'middle':
  13694. case 'center':
  13695. top = containerHeight / 2 - height / 2 - margin[0];
  13696. break;
  13697. case 'bottom':
  13698. top = containerHeight - height - verticalMargin;
  13699. break;
  13700. } // If something is wrong and left, top, width, height are calculated as NaN
  13701. left = left || 0;
  13702. top = top || 0;
  13703. if (isNaN(width)) {
  13704. // Width may be NaN if only one value is given except width
  13705. width = containerWidth - horizontalMargin - left - (right || 0);
  13706. }
  13707. if (isNaN(height)) {
  13708. // Height may be NaN if only one value is given except height
  13709. height = containerHeight - verticalMargin - top - (bottom || 0);
  13710. }
  13711. var rect = new BoundingRect(left + margin[3], top + margin[0], width, height);
  13712. rect.margin = margin;
  13713. return rect;
  13714. }
  13715. /**
  13716. * Position a zr element in viewport
  13717. * Group position is specified by either
  13718. * {left, top}, {right, bottom}
  13719. * If all properties exists, right and bottom will be igonred.
  13720. *
  13721. * Logic:
  13722. * 1. Scale (against origin point in parent coord)
  13723. * 2. Rotate (against origin point in parent coord)
  13724. * 3. Traslate (with el.position by this method)
  13725. * So this method only fixes the last step 'Traslate', which does not affect
  13726. * scaling and rotating.
  13727. *
  13728. * If be called repeatly with the same input el, the same result will be gotten.
  13729. *
  13730. * @param {module:zrender/Element} el Should have `getBoundingRect` method.
  13731. * @param {Object} positionInfo
  13732. * @param {number|string} [positionInfo.left]
  13733. * @param {number|string} [positionInfo.top]
  13734. * @param {number|string} [positionInfo.right]
  13735. * @param {number|string} [positionInfo.bottom]
  13736. * @param {number|string} [positionInfo.width] Only for opt.boundingModel: 'raw'
  13737. * @param {number|string} [positionInfo.height] Only for opt.boundingModel: 'raw'
  13738. * @param {Object} containerRect
  13739. * @param {string|number} margin
  13740. * @param {Object} [opt]
  13741. * @param {Array.<number>} [opt.hv=[1,1]] Only horizontal or only vertical.
  13742. * @param {Array.<number>} [opt.boundingMode='all']
  13743. * Specify how to calculate boundingRect when locating.
  13744. * 'all': Position the boundingRect that is transformed and uioned
  13745. * both itself and its descendants.
  13746. * This mode simplies confine the elements in the bounding
  13747. * of their container (e.g., using 'right: 0').
  13748. * 'raw': Position the boundingRect that is not transformed and only itself.
  13749. * This mode is useful when you want a element can overflow its
  13750. * container. (Consider a rotated circle needs to be located in a corner.)
  13751. * In this mode positionInfo.width/height can only be number.
  13752. */
  13753. function positionElement(el, positionInfo, containerRect, margin, opt) {
  13754. var h = !opt || !opt.hv || opt.hv[0];
  13755. var v = !opt || !opt.hv || opt.hv[1];
  13756. var boundingMode = opt && opt.boundingMode || 'all';
  13757. if (!h && !v) {
  13758. return;
  13759. }
  13760. var rect;
  13761. if (boundingMode === 'raw') {
  13762. rect = el.type === 'group' ? new BoundingRect(0, 0, +positionInfo.width || 0, +positionInfo.height || 0) : el.getBoundingRect();
  13763. } else {
  13764. rect = el.getBoundingRect();
  13765. if (el.needLocalTransform()) {
  13766. var transform = el.getLocalTransform(); // Notice: raw rect may be inner object of el,
  13767. // which should not be modified.
  13768. rect = rect.clone();
  13769. rect.applyTransform(transform);
  13770. }
  13771. } // The real width and height can not be specified but calculated by the given el.
  13772. positionInfo = getLayoutRect(zrUtil.defaults({
  13773. width: rect.width,
  13774. height: rect.height
  13775. }, positionInfo), containerRect, margin); // Because 'tranlate' is the last step in transform
  13776. // (see zrender/core/Transformable#getLocalTransform),
  13777. // we can just only modify el.position to get final result.
  13778. var elPos = el.position;
  13779. var dx = h ? positionInfo.x - rect.x : 0;
  13780. var dy = v ? positionInfo.y - rect.y : 0;
  13781. el.attr('position', boundingMode === 'raw' ? [dx, dy] : [elPos[0] + dx, elPos[1] + dy]);
  13782. }
  13783. /**
  13784. * @param {Object} option Contains some of the properties in HV_NAMES.
  13785. * @param {number} hvIdx 0: horizontal; 1: vertical.
  13786. */
  13787. function sizeCalculable(option, hvIdx) {
  13788. return option[HV_NAMES[hvIdx][0]] != null || option[HV_NAMES[hvIdx][1]] != null && option[HV_NAMES[hvIdx][2]] != null;
  13789. }
  13790. /**
  13791. * Consider Case:
  13792. * When defulat option has {left: 0, width: 100}, and we set {right: 0}
  13793. * through setOption or media query, using normal zrUtil.merge will cause
  13794. * {right: 0} does not take effect.
  13795. *
  13796. * @example
  13797. * ComponentModel.extend({
  13798. * init: function () {
  13799. * ...
  13800. * var inputPositionParams = layout.getLayoutParams(option);
  13801. * this.mergeOption(inputPositionParams);
  13802. * },
  13803. * mergeOption: function (newOption) {
  13804. * newOption && zrUtil.merge(thisOption, newOption, true);
  13805. * layout.mergeLayoutParam(thisOption, newOption);
  13806. * }
  13807. * });
  13808. *
  13809. * @param {Object} targetOption
  13810. * @param {Object} newOption
  13811. * @param {Object|string} [opt]
  13812. * @param {boolean|Array.<boolean>} [opt.ignoreSize=false] Used for the components
  13813. * that width (or height) should not be calculated by left and right (or top and bottom).
  13814. */
  13815. function mergeLayoutParam(targetOption, newOption, opt) {
  13816. !zrUtil.isObject(opt) && (opt = {});
  13817. var ignoreSize = opt.ignoreSize;
  13818. !zrUtil.isArray(ignoreSize) && (ignoreSize = [ignoreSize, ignoreSize]);
  13819. var hResult = merge(HV_NAMES[0], 0);
  13820. var vResult = merge(HV_NAMES[1], 1);
  13821. copy(HV_NAMES[0], targetOption, hResult);
  13822. copy(HV_NAMES[1], targetOption, vResult);
  13823. function merge(names, hvIdx) {
  13824. var newParams = {};
  13825. var newValueCount = 0;
  13826. var merged = {};
  13827. var mergedValueCount = 0;
  13828. var enoughParamNumber = 2;
  13829. each(names, function (name) {
  13830. merged[name] = targetOption[name];
  13831. });
  13832. each(names, function (name) {
  13833. // Consider case: newOption.width is null, which is
  13834. // set by user for removing width setting.
  13835. hasProp(newOption, name) && (newParams[name] = merged[name] = newOption[name]);
  13836. hasValue(newParams, name) && newValueCount++;
  13837. hasValue(merged, name) && mergedValueCount++;
  13838. });
  13839. if (ignoreSize[hvIdx]) {
  13840. // Only one of left/right is premitted to exist.
  13841. if (hasValue(newOption, names[1])) {
  13842. merged[names[2]] = null;
  13843. } else if (hasValue(newOption, names[2])) {
  13844. merged[names[1]] = null;
  13845. }
  13846. return merged;
  13847. } // Case: newOption: {width: ..., right: ...},
  13848. // or targetOption: {right: ...} and newOption: {width: ...},
  13849. // There is no conflict when merged only has params count
  13850. // little than enoughParamNumber.
  13851. if (mergedValueCount === enoughParamNumber || !newValueCount) {
  13852. return merged;
  13853. } // Case: newOption: {width: ..., right: ...},
  13854. // Than we can make sure user only want those two, and ignore
  13855. // all origin params in targetOption.
  13856. else if (newValueCount >= enoughParamNumber) {
  13857. return newParams;
  13858. } else {
  13859. // Chose another param from targetOption by priority.
  13860. for (var i = 0; i < names.length; i++) {
  13861. var name = names[i];
  13862. if (!hasProp(newParams, name) && hasProp(targetOption, name)) {
  13863. newParams[name] = targetOption[name];
  13864. break;
  13865. }
  13866. }
  13867. return newParams;
  13868. }
  13869. }
  13870. function hasProp(obj, name) {
  13871. return obj.hasOwnProperty(name);
  13872. }
  13873. function hasValue(obj, name) {
  13874. return obj[name] != null && obj[name] !== 'auto';
  13875. }
  13876. function copy(names, target, source) {
  13877. each(names, function (name) {
  13878. target[name] = source[name];
  13879. });
  13880. }
  13881. }
  13882. /**
  13883. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  13884. * @param {Object} source
  13885. * @return {Object} Result contains those props.
  13886. */
  13887. function getLayoutParams(source) {
  13888. return copyLayoutParams({}, source);
  13889. }
  13890. /**
  13891. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  13892. * @param {Object} source
  13893. * @return {Object} Result contains those props.
  13894. */
  13895. function copyLayoutParams(target, source) {
  13896. source && target && each(LOCATION_PARAMS, function (name) {
  13897. source.hasOwnProperty(name) && (target[name] = source[name]);
  13898. });
  13899. return target;
  13900. }
  13901. exports.LOCATION_PARAMS = LOCATION_PARAMS;
  13902. exports.HV_NAMES = HV_NAMES;
  13903. exports.box = box;
  13904. exports.vbox = vbox;
  13905. exports.hbox = hbox;
  13906. exports.getAvailableSize = getAvailableSize;
  13907. exports.getLayoutRect = getLayoutRect;
  13908. exports.positionElement = positionElement;
  13909. exports.sizeCalculable = sizeCalculable;
  13910. exports.mergeLayoutParam = mergeLayoutParam;
  13911. exports.getLayoutParams = getLayoutParams;
  13912. exports.copyLayoutParams = copyLayoutParams;
  13913. /***/
  13914. }),
  13915. /* 48 */
  13916. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  13917. "use strict";
  13918. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__core_Base__ = __webpack_require__(7);
  13919. // PENDING
  13920. // Use topological sort ?
  13921. /**
  13922. * Node of graph based post processing.
  13923. *
  13924. * @constructor clay.compositor.CompositorNode
  13925. * @extends clay.core.Base
  13926. *
  13927. */
  13928. var CompositorNode = __WEBPACK_IMPORTED_MODULE_0__core_Base__["a" /* default */].extend(function () {
  13929. return /** @lends clay.compositor.CompositorNode# */ {
  13930. /**
  13931. * @type {string}
  13932. */
  13933. name: '',
  13934. /**
  13935. * Input links, will be updated by the graph
  13936. * @example:
  13937. * inputName: {
  13938. * node: someNode,
  13939. * pin: 'xxxx'
  13940. * }
  13941. * @type {Object}
  13942. */
  13943. inputLinks: {},
  13944. /**
  13945. * Output links, will be updated by the graph
  13946. * @example:
  13947. * outputName: {
  13948. * node: someNode,
  13949. * pin: 'xxxx'
  13950. * }
  13951. * @type {Object}
  13952. */
  13953. outputLinks: {},
  13954. // Save the output texture of previous frame
  13955. // Will be used when there exist a circular reference
  13956. _prevOutputTextures: {},
  13957. _outputTextures: {},
  13958. // Example: { name: 2 }
  13959. _outputReferences: {},
  13960. _rendering: false,
  13961. // If rendered in this frame
  13962. _rendered: false,
  13963. _compositor: null
  13964. };
  13965. },
  13966. /** @lends clay.compositor.CompositorNode.prototype */
  13967. {
  13968. // TODO Remove parameter function callback
  13969. updateParameter: function (outputName, renderer) {
  13970. var outputInfo = this.outputs[outputName];
  13971. var parameters = outputInfo.parameters;
  13972. var parametersCopy = outputInfo._parametersCopy;
  13973. if (!parametersCopy) {
  13974. parametersCopy = outputInfo._parametersCopy = {};
  13975. }
  13976. if (parameters) {
  13977. for (var key in parameters) {
  13978. if (key !== 'width' && key !== 'height') {
  13979. parametersCopy[key] = parameters[key];
  13980. }
  13981. }
  13982. }
  13983. var width, height;
  13984. if (parameters.width instanceof Function) {
  13985. width = parameters.width.call(this, renderer);
  13986. }
  13987. else {
  13988. width = parameters.width;
  13989. }
  13990. if (parameters.height instanceof Function) {
  13991. height = parameters.height.call(this, renderer);
  13992. }
  13993. else {
  13994. height = parameters.height;
  13995. }
  13996. if (
  13997. parametersCopy.width !== width
  13998. || parametersCopy.height !== height
  13999. ) {
  14000. if (this._outputTextures[outputName]) {
  14001. this._outputTextures[outputName].dispose(renderer.gl);
  14002. }
  14003. }
  14004. parametersCopy.width = width;
  14005. parametersCopy.height = height;
  14006. return parametersCopy;
  14007. },
  14008. /**
  14009. * Set parameter
  14010. * @param {string} name
  14011. * @param {} value
  14012. */
  14013. setParameter: function (name, value) { },
  14014. /**
  14015. * Get parameter value
  14016. * @param {string} name
  14017. * @return {}
  14018. */
  14019. getParameter: function (name) { },
  14020. /**
  14021. * Set parameters
  14022. * @param {Object} obj
  14023. */
  14024. setParameters: function (obj) {
  14025. for (var name in obj) {
  14026. this.setParameter(name, obj[name]);
  14027. }
  14028. },
  14029. render: function () { },
  14030. getOutput: function (renderer /*optional*/, name) {
  14031. if (name == null) {
  14032. // Return the output texture without rendering
  14033. name = renderer;
  14034. return this._outputTextures[name];
  14035. }
  14036. var outputInfo = this.outputs[name];
  14037. if (!outputInfo) {
  14038. return;
  14039. }
  14040. // Already been rendered in this frame
  14041. if (this._rendered) {
  14042. // Force return texture in last frame
  14043. if (outputInfo.outputLastFrame) {
  14044. return this._prevOutputTextures[name];
  14045. }
  14046. else {
  14047. return this._outputTextures[name];
  14048. }
  14049. }
  14050. else if (
  14051. // TODO
  14052. this._rendering // Solve Circular Reference
  14053. ) {
  14054. if (!this._prevOutputTextures[name]) {
  14055. // Create a blank texture at first pass
  14056. this._prevOutputTextures[name] = this._compositor.allocateTexture(outputInfo.parameters || {});
  14057. }
  14058. return this._prevOutputTextures[name];
  14059. }
  14060. this.render(renderer);
  14061. return this._outputTextures[name];
  14062. },
  14063. removeReference: function (outputName) {
  14064. this._outputReferences[outputName]--;
  14065. if (this._outputReferences[outputName] === 0) {
  14066. var outputInfo = this.outputs[outputName];
  14067. if (outputInfo.keepLastFrame) {
  14068. if (this._prevOutputTextures[outputName]) {
  14069. this._compositor.releaseTexture(this._prevOutputTextures[outputName]);
  14070. }
  14071. this._prevOutputTextures[outputName] = this._outputTextures[outputName];
  14072. }
  14073. else {
  14074. // Output of this node have alreay been used by all other nodes
  14075. // Put the texture back to the pool.
  14076. this._compositor.releaseTexture(this._outputTextures[outputName]);
  14077. }
  14078. }
  14079. },
  14080. link: function (inputPinName, fromNode, fromPinName) {
  14081. // The relationship from output pin to input pin is one-on-multiple
  14082. this.inputLinks[inputPinName] = {
  14083. node: fromNode,
  14084. pin: fromPinName
  14085. };
  14086. if (!fromNode.outputLinks[fromPinName]) {
  14087. fromNode.outputLinks[fromPinName] = [];
  14088. }
  14089. fromNode.outputLinks[fromPinName].push({
  14090. node: this,
  14091. pin: inputPinName
  14092. });
  14093. // Enabled the pin texture in shader
  14094. this.pass.material.enableTexture(inputPinName);
  14095. },
  14096. clear: function () {
  14097. this.inputLinks = {};
  14098. this.outputLinks = {};
  14099. },
  14100. updateReference: function (outputName) {
  14101. if (!this._rendering) {
  14102. this._rendering = true;
  14103. for (var inputName in this.inputLinks) {
  14104. var link = this.inputLinks[inputName];
  14105. link.node.updateReference(link.pin);
  14106. }
  14107. this._rendering = false;
  14108. }
  14109. if (outputName) {
  14110. this._outputReferences[outputName]++;
  14111. }
  14112. },
  14113. beforeFrame: function () {
  14114. this._rendered = false;
  14115. for (var name in this.outputLinks) {
  14116. this._outputReferences[name] = 0;
  14117. }
  14118. },
  14119. afterFrame: function () {
  14120. // Put back all the textures to pool
  14121. for (var name in this.outputLinks) {
  14122. if (this._outputReferences[name] > 0) {
  14123. var outputInfo = this.outputs[name];
  14124. if (outputInfo.keepLastFrame) {
  14125. if (this._prevOutputTextures[name]) {
  14126. this._compositor.releaseTexture(this._prevOutputTextures[name]);
  14127. }
  14128. this._prevOutputTextures[name] = this._outputTextures[name];
  14129. }
  14130. else {
  14131. this._compositor.releaseTexture(this._outputTextures[name]);
  14132. }
  14133. }
  14134. }
  14135. }
  14136. });
  14137. /* harmony default export */ __webpack_exports__["a"] = (CompositorNode);
  14138. /***/
  14139. }),
  14140. /* 49 */
  14141. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  14142. "use strict";
  14143. // Generate halton sequence
  14144. // https://en.wikipedia.org/wiki/Halton_sequence
  14145. function halton(index, base) {
  14146. var result = 0;
  14147. var f = 1 / base;
  14148. var i = index;
  14149. while (i > 0) {
  14150. result = result + f * (i % base);
  14151. i = Math.floor(i / base);
  14152. f = f / base;
  14153. }
  14154. return result;
  14155. }
  14156. /* harmony default export */ __webpack_exports__["a"] = (halton);
  14157. /***/
  14158. }),
  14159. /* 50 */
  14160. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  14161. "use strict";
  14162. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  14163. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  14164. /* harmony default export */ __webpack_exports__["a"] = (function (seriesModel, dims, source) {
  14165. source = source || seriesModel.getSource();
  14166. var coordSysDimensions = dims || __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.getCoordinateSystemDimensions(seriesModel.get('coordinateSystem')) || ['x', 'y', 'z'];
  14167. var dimensions = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.helper.createDimensions(source, {
  14168. dimensionsDefine: source.dimensionsDefine || seriesModel.get('dimensions'),
  14169. encodeDefine: source.encodeDefine || seriesModel.get('encode'),
  14170. coordDimensions: coordSysDimensions.map(function (dim) {
  14171. var axis3DModel = seriesModel.getReferringComponents(dim + 'Axis3D')[0];
  14172. return {
  14173. type: (axis3DModel && axis3DModel.get('type') === 'category') ? 'ordinal' : 'float',
  14174. name: dim
  14175. // Find stackable dimension. Which will represent value.
  14176. // stackable: dim === 'z'
  14177. };
  14178. })
  14179. });
  14180. if (seriesModel.get('coordinateSystem') === 'cartesian3D') {
  14181. dimensions.forEach(function (dimInfo) {
  14182. if (coordSysDimensions.indexOf(dimInfo.coordDim) >= 0) {
  14183. var axis3DModel = seriesModel.getReferringComponents(dimInfo.coordDim + 'Axis3D')[0];
  14184. if (axis3DModel && axis3DModel.get('type') === 'category') {
  14185. dimInfo.ordinalMeta = axis3DModel.getOrdinalMeta();
  14186. }
  14187. }
  14188. });
  14189. }
  14190. var stackCalculationInfo = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.helper.dataStack.enableDataStack(
  14191. // Only support 'z' and `byIndex` now.
  14192. seriesModel, dimensions, { byIndex: true, stackedCoordDimension: 'z' }
  14193. );
  14194. var data = new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.List(dimensions, seriesModel);
  14195. data.setCalculationInfo(stackCalculationInfo);
  14196. data.initData(source);
  14197. return data;
  14198. });
  14199. /***/
  14200. }),
  14201. /* 51 */
  14202. /***/ (function (module, exports) {
  14203. /*
  14204. * Licensed to the Apache Software Foundation (ASF) under one
  14205. * or more contributor license agreements. See the NOTICE file
  14206. * distributed with this work for additional information
  14207. * regarding copyright ownership. The ASF licenses this file
  14208. * to you under the Apache License, Version 2.0 (the
  14209. * "License"); you may not use this file except in compliance
  14210. * with the License. You may obtain a copy of the License at
  14211. *
  14212. * http://www.apache.org/licenses/LICENSE-2.0
  14213. *
  14214. * Unless required by applicable law or agreed to in writing,
  14215. * software distributed under the License is distributed on an
  14216. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14217. * KIND, either express or implied. See the License for the
  14218. * specific language governing permissions and limitations
  14219. * under the License.
  14220. */
  14221. function _default(seriesType, defaultSymbolType, legendSymbol) {
  14222. // Encoding visual for all series include which is filtered for legend drawing
  14223. return {
  14224. seriesType: seriesType,
  14225. // For legend.
  14226. performRawSeries: true,
  14227. reset: function (seriesModel, ecModel, api) {
  14228. var data = seriesModel.getData();
  14229. var symbolType = seriesModel.get('symbol') || defaultSymbolType;
  14230. var symbolSize = seriesModel.get('symbolSize');
  14231. var keepAspect = seriesModel.get('symbolKeepAspect');
  14232. data.setVisual({
  14233. legendSymbol: legendSymbol || symbolType,
  14234. symbol: symbolType,
  14235. symbolSize: symbolSize,
  14236. symbolKeepAspect: keepAspect
  14237. }); // Only visible series has each data be visual encoded
  14238. if (ecModel.isSeriesFiltered(seriesModel)) {
  14239. return;
  14240. }
  14241. var hasCallback = typeof symbolSize === 'function';
  14242. function dataEach(data, idx) {
  14243. if (typeof symbolSize === 'function') {
  14244. var rawValue = seriesModel.getRawValue(idx); // FIXME
  14245. var params = seriesModel.getDataParams(idx);
  14246. data.setItemVisual(idx, 'symbolSize', symbolSize(rawValue, params));
  14247. }
  14248. if (data.hasItemOption) {
  14249. var itemModel = data.getItemModel(idx);
  14250. var itemSymbolType = itemModel.getShallow('symbol', true);
  14251. var itemSymbolSize = itemModel.getShallow('symbolSize', true);
  14252. var itemSymbolKeepAspect = itemModel.getShallow('symbolKeepAspect', true); // If has item symbol
  14253. if (itemSymbolType != null) {
  14254. data.setItemVisual(idx, 'symbol', itemSymbolType);
  14255. }
  14256. if (itemSymbolSize != null) {
  14257. // PENDING Transform symbolSize ?
  14258. data.setItemVisual(idx, 'symbolSize', itemSymbolSize);
  14259. }
  14260. if (itemSymbolKeepAspect != null) {
  14261. data.setItemVisual(idx, 'symbolKeepAspect', itemSymbolKeepAspect);
  14262. }
  14263. }
  14264. }
  14265. return {
  14266. dataEach: data.hasItemOption || hasCallback ? dataEach : null
  14267. };
  14268. }
  14269. };
  14270. }
  14271. module.exports = _default;
  14272. /***/
  14273. }),
  14274. /* 52 */
  14275. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  14276. "use strict";
  14277. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__core_Base__ = __webpack_require__(7);
  14278. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__core_GLInfo__ = __webpack_require__(111);
  14279. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__core_glenum__ = __webpack_require__(11);
  14280. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__core_vendor__ = __webpack_require__(14);
  14281. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__Material__ = __webpack_require__(19);
  14282. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__math_Vector2__ = __webpack_require__(26);
  14283. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__gpu_ProgramManager__ = __webpack_require__(115);
  14284. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__Shader__ = __webpack_require__(8);
  14285. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__shader_source_prez_glsl_js__ = __webpack_require__(71);
  14286. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_9__glmatrix_mat4__ = __webpack_require__(21);
  14287. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_10__glmatrix_vec3__ = __webpack_require__(12);
  14288. // TODO Resources like shader, texture, geometry reference management
  14289. // Trace and find out which shader, texture, geometry can be destroyed
  14290. // Light header
  14291. __WEBPACK_IMPORTED_MODULE_7__Shader__["a" /* default */]['import'](__WEBPACK_IMPORTED_MODULE_8__shader_source_prez_glsl_js__["a" /* default */]);
  14292. var mat4Create = __WEBPACK_IMPORTED_MODULE_9__glmatrix_mat4__["a" /* default */].create;
  14293. var errorShader = {};
  14294. function defaultGetMaterial(renderable) {
  14295. return renderable.material;
  14296. }
  14297. function defaultGetUniform(renderable, material, symbol) {
  14298. return material.uniforms[symbol].value;
  14299. }
  14300. function defaultIsMaterialChanged(renderabled, prevRenderable, material, prevMaterial) {
  14301. return material !== prevMaterial;
  14302. }
  14303. function defaultIfRender(renderable) {
  14304. return true;
  14305. }
  14306. function noop() { }
  14307. var attributeBufferTypeMap = {
  14308. float: __WEBPACK_IMPORTED_MODULE_2__core_glenum__["a" /* default */].FLOAT,
  14309. byte: __WEBPACK_IMPORTED_MODULE_2__core_glenum__["a" /* default */].BYTE,
  14310. ubyte: __WEBPACK_IMPORTED_MODULE_2__core_glenum__["a" /* default */].UNSIGNED_BYTE,
  14311. short: __WEBPACK_IMPORTED_MODULE_2__core_glenum__["a" /* default */].SHORT,
  14312. ushort: __WEBPACK_IMPORTED_MODULE_2__core_glenum__["a" /* default */].UNSIGNED_SHORT
  14313. };
  14314. function VertexArrayObject(availableAttributes, availableAttributeSymbols, indicesBuffer) {
  14315. this.availableAttributes = availableAttributes;
  14316. this.availableAttributeSymbols = availableAttributeSymbols;
  14317. this.indicesBuffer = indicesBuffer;
  14318. this.vao = null;
  14319. }
  14320. function PlaceHolderTexture(renderer) {
  14321. var blankCanvas;
  14322. var webglTexture;
  14323. this.bind = function (renderer) {
  14324. if (!blankCanvas) {
  14325. // TODO Environment not support createCanvas.
  14326. blankCanvas = __WEBPACK_IMPORTED_MODULE_3__core_vendor__["a" /* default */].createCanvas();
  14327. blankCanvas.width = blankCanvas.height = 1;
  14328. blankCanvas.getContext('2d');
  14329. }
  14330. var gl = renderer.gl;
  14331. var firstBind = !webglTexture;
  14332. if (firstBind) {
  14333. webglTexture = gl.createTexture();
  14334. }
  14335. gl.bindTexture(gl.TEXTURE_2D, webglTexture);
  14336. if (firstBind) {
  14337. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, blankCanvas);
  14338. }
  14339. };
  14340. this.unbind = function (renderer) {
  14341. renderer.gl.bindTexture(renderer.gl.TEXTURE_2D, null);
  14342. };
  14343. this.isRenderable = function () {
  14344. return true;
  14345. };
  14346. }
  14347. /**
  14348. * @constructor clay.Renderer
  14349. * @extends clay.core.Base
  14350. */
  14351. var Renderer = __WEBPACK_IMPORTED_MODULE_0__core_Base__["a" /* default */].extend(function () {
  14352. return /** @lends clay.Renderer# */ {
  14353. /**
  14354. * @type {HTMLCanvasElement}
  14355. * @readonly
  14356. */
  14357. canvas: null,
  14358. /**
  14359. * Canvas width, set by resize method
  14360. * @type {number}
  14361. * @private
  14362. */
  14363. _width: 100,
  14364. /**
  14365. * Canvas width, set by resize method
  14366. * @type {number}
  14367. * @private
  14368. */
  14369. _height: 100,
  14370. /**
  14371. * Device pixel ratio, set by setDevicePixelRatio method
  14372. * Specially for high defination display
  14373. * @see http://www.khronos.org/webgl/wiki/HandlingHighDPI
  14374. * @type {number}
  14375. * @private
  14376. */
  14377. devicePixelRatio: (typeof window !== 'undefined' && window.devicePixelRatio) || 1.0,
  14378. /**
  14379. * Clear color
  14380. * @type {number[]}
  14381. */
  14382. clearColor: [0.0, 0.0, 0.0, 0.0],
  14383. /**
  14384. * Default:
  14385. * _gl.COLOR_BUFFER_BIT | _gl.DEPTH_BUFFER_BIT | _gl.STENCIL_BUFFER_BIT
  14386. * @type {number}
  14387. */
  14388. clearBit: 17664,
  14389. // Settings when getting context
  14390. // http://www.khronos.org/registry/webgl/specs/latest/#2.4
  14391. /**
  14392. * If enable alpha, default true
  14393. * @type {boolean}
  14394. */
  14395. alpha: true,
  14396. /**
  14397. * If enable depth buffer, default true
  14398. * @type {boolean}
  14399. */
  14400. depth: true,
  14401. /**
  14402. * If enable stencil buffer, default false
  14403. * @type {boolean}
  14404. */
  14405. stencil: false,
  14406. /**
  14407. * If enable antialias, default true
  14408. * @type {boolean}
  14409. */
  14410. antialias: true,
  14411. /**
  14412. * If enable premultiplied alpha, default true
  14413. * @type {boolean}
  14414. */
  14415. premultipliedAlpha: true,
  14416. /**
  14417. * If preserve drawing buffer, default false
  14418. * @type {boolean}
  14419. */
  14420. preserveDrawingBuffer: false,
  14421. /**
  14422. * If throw context error, usually turned on in debug mode
  14423. * @type {boolean}
  14424. */
  14425. throwError: true,
  14426. /**
  14427. * WebGL Context created from given canvas
  14428. * @type {WebGLRenderingContext}
  14429. */
  14430. gl: null,
  14431. /**
  14432. * Renderer viewport, read-only, can be set by setViewport method
  14433. * @type {Object}
  14434. */
  14435. viewport: {},
  14436. // Set by FrameBuffer#bind
  14437. __currentFrameBuffer: null,
  14438. _viewportStack: [],
  14439. _clearStack: [],
  14440. _sceneRendering: null
  14441. };
  14442. }, function () {
  14443. if (!this.canvas) {
  14444. this.canvas = __WEBPACK_IMPORTED_MODULE_3__core_vendor__["a" /* default */].createCanvas();
  14445. }
  14446. var canvas = this.canvas;
  14447. try {
  14448. var opts = {
  14449. alpha: this.alpha,
  14450. depth: this.depth,
  14451. stencil: this.stencil,
  14452. antialias: this.antialias,
  14453. premultipliedAlpha: this.premultipliedAlpha,
  14454. preserveDrawingBuffer: this.preserveDrawingBuffer
  14455. };
  14456. this.gl = canvas.getContext('webgl', opts)
  14457. || canvas.getContext('experimental-webgl', opts);
  14458. if (!this.gl) {
  14459. throw new Error();
  14460. }
  14461. this._glinfo = new __WEBPACK_IMPORTED_MODULE_1__core_GLInfo__["a" /* default */](this.gl);
  14462. if (this.gl.targetRenderer) {
  14463. console.error('Already created a renderer');
  14464. }
  14465. this.gl.targetRenderer = this;
  14466. this.resize();
  14467. }
  14468. catch (e) {
  14469. throw 'Error creating WebGL Context ' + e;
  14470. }
  14471. // Init managers
  14472. this._programMgr = new __WEBPACK_IMPORTED_MODULE_6__gpu_ProgramManager__["a" /* default */](this);
  14473. this._placeholderTexture = new PlaceHolderTexture(this);
  14474. },
  14475. /** @lends clay.Renderer.prototype. **/
  14476. {
  14477. /**
  14478. * Resize the canvas
  14479. * @param {number} width
  14480. * @param {number} height
  14481. */
  14482. resize: function (width, height) {
  14483. var canvas = this.canvas;
  14484. // http://www.khronos.org/webgl/wiki/HandlingHighDPI
  14485. // set the display size of the canvas.
  14486. var dpr = this.devicePixelRatio;
  14487. if (width != null) {
  14488. canvas.style.width = width + 'px';
  14489. canvas.style.height = height + 'px';
  14490. // set the size of the drawingBuffer
  14491. canvas.width = width * dpr;
  14492. canvas.height = height * dpr;
  14493. this._width = width;
  14494. this._height = height;
  14495. }
  14496. else {
  14497. this._width = canvas.width / dpr;
  14498. this._height = canvas.height / dpr;
  14499. }
  14500. this.setViewport(0, 0, this._width, this._height);
  14501. },
  14502. /**
  14503. * Get renderer width
  14504. * @return {number}
  14505. */
  14506. getWidth: function () {
  14507. return this._width;
  14508. },
  14509. /**
  14510. * Get renderer height
  14511. * @return {number}
  14512. */
  14513. getHeight: function () {
  14514. return this._height;
  14515. },
  14516. /**
  14517. * Get viewport aspect,
  14518. * @return {number}
  14519. */
  14520. getViewportAspect: function () {
  14521. var viewport = this.viewport;
  14522. return viewport.width / viewport.height;
  14523. },
  14524. /**
  14525. * Set devicePixelRatio
  14526. * @param {number} devicePixelRatio
  14527. */
  14528. setDevicePixelRatio: function (devicePixelRatio) {
  14529. this.devicePixelRatio = devicePixelRatio;
  14530. this.resize(this._width, this._height);
  14531. },
  14532. /**
  14533. * Get devicePixelRatio
  14534. * @param {number} devicePixelRatio
  14535. */
  14536. getDevicePixelRatio: function () {
  14537. return this.devicePixelRatio;
  14538. },
  14539. /**
  14540. * Get WebGL extension
  14541. * @param {string} name
  14542. * @return {object}
  14543. */
  14544. getGLExtension: function (name) {
  14545. return this._glinfo.getExtension(name);
  14546. },
  14547. /**
  14548. * Get WebGL parameter
  14549. * @param {string} name
  14550. * @return {*}
  14551. */
  14552. getGLParameter: function (name) {
  14553. return this._glinfo.getParameter(name);
  14554. },
  14555. /**
  14556. * Set rendering viewport
  14557. * @param {number|Object} x
  14558. * @param {number} [y]
  14559. * @param {number} [width]
  14560. * @param {number} [height]
  14561. * @param {number} [devicePixelRatio]
  14562. * Defaultly use the renderere devicePixelRatio
  14563. * It needs to be 1 when setViewport is called by frameBuffer
  14564. *
  14565. * @example
  14566. * setViewport(0,0,width,height,1)
  14567. * setViewport({
  14568. * x: 0,
  14569. * y: 0,
  14570. * width: width,
  14571. * height: height,
  14572. * devicePixelRatio: 1
  14573. * })
  14574. */
  14575. setViewport: function (x, y, width, height, dpr) {
  14576. if (typeof x === 'object') {
  14577. var obj = x;
  14578. x = obj.x;
  14579. y = obj.y;
  14580. width = obj.width;
  14581. height = obj.height;
  14582. dpr = obj.devicePixelRatio;
  14583. }
  14584. dpr = dpr || this.devicePixelRatio;
  14585. this.gl.viewport(
  14586. x * dpr, y * dpr, width * dpr, height * dpr
  14587. );
  14588. // Use a fresh new object, not write property.
  14589. this.viewport = {
  14590. x: x,
  14591. y: y,
  14592. width: width,
  14593. height: height,
  14594. devicePixelRatio: dpr
  14595. };
  14596. },
  14597. /**
  14598. * Push current viewport into a stack
  14599. */
  14600. saveViewport: function () {
  14601. this._viewportStack.push(this.viewport);
  14602. },
  14603. /**
  14604. * Pop viewport from stack, restore in the renderer
  14605. */
  14606. restoreViewport: function () {
  14607. if (this._viewportStack.length > 0) {
  14608. this.setViewport(this._viewportStack.pop());
  14609. }
  14610. },
  14611. /**
  14612. * Push current clear into a stack
  14613. */
  14614. saveClear: function () {
  14615. this._clearStack.push({
  14616. clearBit: this.clearBit,
  14617. clearColor: this.clearColor
  14618. });
  14619. },
  14620. /**
  14621. * Pop clear from stack, restore in the renderer
  14622. */
  14623. restoreClear: function () {
  14624. if (this._clearStack.length > 0) {
  14625. var opt = this._clearStack.pop();
  14626. this.clearColor = opt.clearColor;
  14627. this.clearBit = opt.clearBit;
  14628. }
  14629. },
  14630. bindSceneRendering: function (scene) {
  14631. this._sceneRendering = scene;
  14632. },
  14633. /**
  14634. * Render the scene in camera to the screen or binded offline framebuffer
  14635. * @param {clay.Scene} scene
  14636. * @param {clay.Camera} camera
  14637. * @param {boolean} [notUpdateScene] If not call the scene.update methods in the rendering, default true
  14638. * @param {boolean} [preZ] If use preZ optimization, default false
  14639. * @return {IRenderInfo}
  14640. */
  14641. render: function (scene, camera, notUpdateScene, preZ) {
  14642. var _gl = this.gl;
  14643. var clearColor = this.clearColor;
  14644. if (this.clearBit) {
  14645. // Must set depth and color mask true before clear
  14646. _gl.colorMask(true, true, true, true);
  14647. _gl.depthMask(true);
  14648. var viewport = this.viewport;
  14649. var needsScissor = false;
  14650. var viewportDpr = viewport.devicePixelRatio;
  14651. if (viewport.width !== this._width || viewport.height !== this._height
  14652. || (viewportDpr && viewportDpr !== this.devicePixelRatio)
  14653. || viewport.x || viewport.y
  14654. ) {
  14655. needsScissor = true;
  14656. // http://stackoverflow.com/questions/11544608/how-to-clear-a-rectangle-area-in-webgl
  14657. // Only clear the viewport
  14658. _gl.enable(_gl.SCISSOR_TEST);
  14659. _gl.scissor(viewport.x * viewportDpr, viewport.y * viewportDpr, viewport.width * viewportDpr, viewport.height * viewportDpr);
  14660. }
  14661. _gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
  14662. _gl.clear(this.clearBit);
  14663. if (needsScissor) {
  14664. _gl.disable(_gl.SCISSOR_TEST);
  14665. }
  14666. }
  14667. // If the scene have been updated in the prepass like shadow map
  14668. // There is no need to update it again
  14669. if (!notUpdateScene) {
  14670. scene.update(false);
  14671. }
  14672. scene.updateLights();
  14673. camera = camera || scene.getMainCamera();
  14674. if (!camera) {
  14675. console.error('Can\'t find camera in the scene.');
  14676. return;
  14677. }
  14678. camera.update();
  14679. var renderList = scene.updateRenderList(camera, true);
  14680. this._sceneRendering = scene;
  14681. var opaqueList = renderList.opaque;
  14682. var transparentList = renderList.transparent;
  14683. var sceneMaterial = scene.material;
  14684. scene.trigger('beforerender', this, scene, camera, renderList);
  14685. // Render pre z
  14686. if (preZ) {
  14687. this.renderPreZ(opaqueList, scene, camera);
  14688. _gl.depthFunc(_gl.LEQUAL);
  14689. }
  14690. else {
  14691. _gl.depthFunc(_gl.LESS);
  14692. }
  14693. // Update the depth of transparent list.
  14694. var worldViewMat = mat4Create();
  14695. var posViewSpace = __WEBPACK_IMPORTED_MODULE_10__glmatrix_vec3__["a" /* default */].create();
  14696. for (var i = 0; i < transparentList.length; i++) {
  14697. var renderable = transparentList[i];
  14698. __WEBPACK_IMPORTED_MODULE_9__glmatrix_mat4__["a" /* default */].multiplyAffine(worldViewMat, camera.viewMatrix.array, renderable.worldTransform.array);
  14699. __WEBPACK_IMPORTED_MODULE_10__glmatrix_vec3__["a" /* default */].transformMat4(posViewSpace, renderable.position.array, worldViewMat);
  14700. renderable.__depth = posViewSpace[2];
  14701. }
  14702. // Render opaque list
  14703. this.renderPass(opaqueList, camera, {
  14704. getMaterial: function (renderable) {
  14705. return sceneMaterial || renderable.material;
  14706. },
  14707. sortCompare: this.opaqueSortCompare
  14708. });
  14709. this.renderPass(transparentList, camera, {
  14710. getMaterial: function (renderable) {
  14711. return sceneMaterial || renderable.material;
  14712. },
  14713. sortCompare: this.transparentSortCompare
  14714. });
  14715. scene.trigger('afterrender', this, scene, camera, renderList);
  14716. // Cleanup
  14717. this._sceneRendering = null;
  14718. },
  14719. getProgram: function (renderable, renderMaterial, scene) {
  14720. renderMaterial = renderMaterial || renderable.material;
  14721. return this._programMgr.getProgram(renderable, renderMaterial, scene);
  14722. },
  14723. validateProgram: function (program) {
  14724. if (program.__error) {
  14725. var errorMsg = program.__error;
  14726. if (errorShader[program.__uid__]) {
  14727. return;
  14728. }
  14729. errorShader[program.__uid__] = true;
  14730. if (this.throwError) {
  14731. throw new Error(errorMsg);
  14732. }
  14733. else {
  14734. this.trigger('error', errorMsg);
  14735. }
  14736. }
  14737. },
  14738. updatePrograms: function (list, scene, passConfig) {
  14739. var getMaterial = (passConfig && passConfig.getMaterial) || defaultGetMaterial;
  14740. scene = scene || null;
  14741. for (var i = 0; i < list.length; i++) {
  14742. var renderable = list[i];
  14743. var renderMaterial = getMaterial.call(this, renderable);
  14744. if (i > 0) {
  14745. var prevRenderable = list[i - 1];
  14746. var prevJointsLen = prevRenderable.joints ? prevRenderable.joints.length : 0;
  14747. var jointsLen = renderable.joints ? renderable.joints.length : 0;
  14748. // Keep program not change if joints, material, lightGroup are same of two renderables.
  14749. if (jointsLen === prevJointsLen
  14750. && renderable.material === prevRenderable.material
  14751. && renderable.lightGroup === prevRenderable.lightGroup
  14752. ) {
  14753. renderable.__program = prevRenderable.__program;
  14754. continue;
  14755. }
  14756. }
  14757. var program = this._programMgr.getProgram(renderable, renderMaterial, scene);
  14758. this.validateProgram(program);
  14759. renderable.__program = program;
  14760. }
  14761. },
  14762. /**
  14763. * Render a single renderable list in camera in sequence
  14764. * @param {clay.Renderable[]} list List of all renderables.
  14765. * @param {clay.Camera} [camera] Camera provide view matrix and porjection matrix. It can be null.
  14766. * @param {Object} [passConfig]
  14767. * @param {Function} [passConfig.getMaterial] Get renderable material.
  14768. * @param {Function} [passConfig.getUniform] Get material uniform value.
  14769. * @param {Function} [passConfig.isMaterialChanged] If material changed.
  14770. * @param {Function} [passConfig.beforeRender] Before render each renderable.
  14771. * @param {Function} [passConfig.afterRender] After render each renderable
  14772. * @param {Function} [passConfig.ifRender] If render the renderable.
  14773. * @param {Function} [passConfig.sortCompare] Sort compare function.
  14774. * @return {IRenderInfo}
  14775. */
  14776. renderPass: function (list, camera, passConfig) {
  14777. this.trigger('beforerenderpass', this, list, camera, passConfig);
  14778. passConfig = passConfig || {};
  14779. passConfig.getMaterial = passConfig.getMaterial || defaultGetMaterial;
  14780. passConfig.getUniform = passConfig.getUniform || defaultGetUniform;
  14781. // PENDING Better solution?
  14782. passConfig.isMaterialChanged = passConfig.isMaterialChanged || defaultIsMaterialChanged;
  14783. passConfig.beforeRender = passConfig.beforeRender || noop;
  14784. passConfig.afterRender = passConfig.afterRender || noop;
  14785. var ifRenderObject = passConfig.ifRender || defaultIfRender;
  14786. this.updatePrograms(list, this._sceneRendering, passConfig);
  14787. if (passConfig.sortCompare) {
  14788. list.sort(passConfig.sortCompare);
  14789. }
  14790. // Some common builtin uniforms
  14791. var viewport = this.viewport;
  14792. var vDpr = viewport.devicePixelRatio;
  14793. var viewportUniform = [
  14794. viewport.x * vDpr, viewport.y * vDpr,
  14795. viewport.width * vDpr, viewport.height * vDpr
  14796. ];
  14797. var windowDpr = this.devicePixelRatio;
  14798. var windowSizeUniform = this.__currentFrameBuffer
  14799. ? [this.__currentFrameBuffer.getTextureWidth(), this.__currentFrameBuffer.getTextureHeight()]
  14800. : [this._width * windowDpr, this._height * windowDpr];
  14801. // DEPRECATED
  14802. var viewportSizeUniform = [
  14803. viewportUniform[2], viewportUniform[3]
  14804. ];
  14805. var time = Date.now();
  14806. // Calculate view and projection matrix
  14807. if (camera) {
  14808. __WEBPACK_IMPORTED_MODULE_9__glmatrix_mat4__["a" /* default */].copy(matrices.VIEW, camera.viewMatrix.array);
  14809. __WEBPACK_IMPORTED_MODULE_9__glmatrix_mat4__["a" /* default */].copy(matrices.PROJECTION, camera.projectionMatrix.array);
  14810. __WEBPACK_IMPORTED_MODULE_9__glmatrix_mat4__["a" /* default */].copy(matrices.VIEWINVERSE, camera.worldTransform.array);
  14811. }
  14812. else {
  14813. __WEBPACK_IMPORTED_MODULE_9__glmatrix_mat4__["a" /* default */].identity(matrices.VIEW);
  14814. __WEBPACK_IMPORTED_MODULE_9__glmatrix_mat4__["a" /* default */].identity(matrices.PROJECTION);
  14815. __WEBPACK_IMPORTED_MODULE_9__glmatrix_mat4__["a" /* default */].identity(matrices.VIEWINVERSE);
  14816. }
  14817. __WEBPACK_IMPORTED_MODULE_9__glmatrix_mat4__["a" /* default */].multiply(matrices.VIEWPROJECTION, matrices.PROJECTION, matrices.VIEW);
  14818. __WEBPACK_IMPORTED_MODULE_9__glmatrix_mat4__["a" /* default */].invert(matrices.PROJECTIONINVERSE, matrices.PROJECTION);
  14819. __WEBPACK_IMPORTED_MODULE_9__glmatrix_mat4__["a" /* default */].invert(matrices.VIEWPROJECTIONINVERSE, matrices.VIEWPROJECTION);
  14820. var _gl = this.gl;
  14821. var scene = this._sceneRendering;
  14822. var prevMaterial;
  14823. var prevProgram;
  14824. var prevRenderable;
  14825. // Status
  14826. var depthTest, depthMask;
  14827. var culling, cullFace, frontFace;
  14828. var transparent;
  14829. var drawID;
  14830. var currentVAO;
  14831. var materialTakesTextureSlot;
  14832. var vaoExt = this.getGLExtension('OES_vertex_array_object');
  14833. for (var i = 0; i < list.length; i++) {
  14834. var renderable = list[i];
  14835. var isSceneNode = renderable.worldTransform != null;
  14836. var worldM;
  14837. if (!ifRenderObject(renderable)) {
  14838. continue;
  14839. }
  14840. // Skinned mesh will transformed to joint space. Ignore the mesh transform
  14841. if (isSceneNode) {
  14842. worldM = (renderable.isSkinnedMesh && renderable.isSkinnedMesh())
  14843. ? matrices.IDENTITY : renderable.worldTransform.array;
  14844. }
  14845. var geometry = renderable.geometry;
  14846. var material = passConfig.getMaterial.call(this, renderable);
  14847. var program = renderable.__program;
  14848. var shader = material.shader;
  14849. var currentDrawID = geometry.__uid__ + '-' + program.__uid__;
  14850. var drawIDChanged = currentDrawID !== drawID;
  14851. drawID = currentDrawID;
  14852. if (drawIDChanged && vaoExt) {
  14853. // TODO Seems need to be bound to null immediately (or before bind another program?) if vao is changed
  14854. vaoExt.bindVertexArrayOES(null);
  14855. }
  14856. if (isSceneNode) {
  14857. __WEBPACK_IMPORTED_MODULE_9__glmatrix_mat4__["a" /* default */].copy(matrices.WORLD, worldM);
  14858. __WEBPACK_IMPORTED_MODULE_9__glmatrix_mat4__["a" /* default */].multiply(matrices.WORLDVIEWPROJECTION, matrices.VIEWPROJECTION, worldM);
  14859. __WEBPACK_IMPORTED_MODULE_9__glmatrix_mat4__["a" /* default */].multiplyAffine(matrices.WORLDVIEW, matrices.VIEW, worldM);
  14860. if (shader.matrixSemantics.WORLDINVERSE ||
  14861. shader.matrixSemantics.WORLDINVERSETRANSPOSE) {
  14862. __WEBPACK_IMPORTED_MODULE_9__glmatrix_mat4__["a" /* default */].invert(matrices.WORLDINVERSE, worldM);
  14863. }
  14864. if (shader.matrixSemantics.WORLDVIEWINVERSE ||
  14865. shader.matrixSemantics.WORLDVIEWINVERSETRANSPOSE) {
  14866. __WEBPACK_IMPORTED_MODULE_9__glmatrix_mat4__["a" /* default */].invert(matrices.WORLDVIEWINVERSE, matrices.WORLDVIEW);
  14867. }
  14868. if (shader.matrixSemantics.WORLDVIEWPROJECTIONINVERSE ||
  14869. shader.matrixSemantics.WORLDVIEWPROJECTIONINVERSETRANSPOSE) {
  14870. __WEBPACK_IMPORTED_MODULE_9__glmatrix_mat4__["a" /* default */].invert(matrices.WORLDVIEWPROJECTIONINVERSE, matrices.WORLDVIEWPROJECTION);
  14871. }
  14872. }
  14873. // Before render hook
  14874. renderable.beforeRender && renderable.beforeRender(this);
  14875. passConfig.beforeRender.call(this, renderable, material, prevMaterial);
  14876. var programChanged = program !== prevProgram;
  14877. if (programChanged) {
  14878. // Set lights number
  14879. program.bind(this);
  14880. // Set some common uniforms
  14881. program.setUniformOfSemantic(_gl, 'VIEWPORT', viewportUniform);
  14882. program.setUniformOfSemantic(_gl, 'WINDOW_SIZE', windowSizeUniform);
  14883. if (camera) {
  14884. program.setUniformOfSemantic(_gl, 'NEAR', camera.near);
  14885. program.setUniformOfSemantic(_gl, 'FAR', camera.far);
  14886. }
  14887. program.setUniformOfSemantic(_gl, 'DEVICEPIXELRATIO', vDpr);
  14888. program.setUniformOfSemantic(_gl, 'TIME', time);
  14889. // DEPRECATED
  14890. program.setUniformOfSemantic(_gl, 'VIEWPORT_SIZE', viewportSizeUniform);
  14891. // Set lights uniforms
  14892. // TODO needs optimized
  14893. if (scene) {
  14894. scene.setLightUniforms(program, renderable.lightGroup, this);
  14895. }
  14896. }
  14897. else {
  14898. program = prevProgram;
  14899. }
  14900. // Program changes also needs reset the materials.
  14901. if (programChanged || passConfig.isMaterialChanged(
  14902. renderable, prevRenderable, material, prevMaterial
  14903. )) {
  14904. if (material.depthTest !== depthTest) {
  14905. material.depthTest ? _gl.enable(_gl.DEPTH_TEST) : _gl.disable(_gl.DEPTH_TEST);
  14906. depthTest = material.depthTest;
  14907. }
  14908. if (material.depthMask !== depthMask) {
  14909. _gl.depthMask(material.depthMask);
  14910. depthMask = material.depthMask;
  14911. }
  14912. if (material.transparent !== transparent) {
  14913. material.transparent ? _gl.enable(_gl.BLEND) : _gl.disable(_gl.BLEND);
  14914. transparent = material.transparent;
  14915. }
  14916. // TODO cache blending
  14917. if (material.transparent) {
  14918. if (material.blend) {
  14919. material.blend(_gl);
  14920. }
  14921. else {
  14922. // Default blend function
  14923. _gl.blendEquationSeparate(_gl.FUNC_ADD, _gl.FUNC_ADD);
  14924. _gl.blendFuncSeparate(_gl.SRC_ALPHA, _gl.ONE_MINUS_SRC_ALPHA, _gl.ONE, _gl.ONE_MINUS_SRC_ALPHA);
  14925. }
  14926. }
  14927. materialTakesTextureSlot = this._bindMaterial(
  14928. renderable, material, program,
  14929. prevRenderable || null, prevMaterial || null, prevProgram || null,
  14930. passConfig.getUniform
  14931. );
  14932. prevMaterial = material;
  14933. }
  14934. var matrixSemanticKeys = shader.matrixSemanticKeys;
  14935. if (isSceneNode) {
  14936. for (var k = 0; k < matrixSemanticKeys.length; k++) {
  14937. var semantic = matrixSemanticKeys[k];
  14938. var semanticInfo = shader.matrixSemantics[semantic];
  14939. var matrix = matrices[semantic];
  14940. if (semanticInfo.isTranspose) {
  14941. var matrixNoTranspose = matrices[semanticInfo.semanticNoTranspose];
  14942. __WEBPACK_IMPORTED_MODULE_9__glmatrix_mat4__["a" /* default */].transpose(matrix, matrixNoTranspose);
  14943. }
  14944. program.setUniform(_gl, semanticInfo.type, semanticInfo.symbol, matrix);
  14945. }
  14946. }
  14947. if (renderable.cullFace !== cullFace) {
  14948. cullFace = renderable.cullFace;
  14949. _gl.cullFace(cullFace);
  14950. }
  14951. if (renderable.frontFace !== frontFace) {
  14952. frontFace = renderable.frontFace;
  14953. _gl.frontFace(frontFace);
  14954. }
  14955. if (renderable.culling !== culling) {
  14956. culling = renderable.culling;
  14957. culling ? _gl.enable(_gl.CULL_FACE) : _gl.disable(_gl.CULL_FACE);
  14958. }
  14959. // TODO Not update skeleton in each renderable.
  14960. this._updateSkeleton(renderable, program, materialTakesTextureSlot);
  14961. if (drawIDChanged) {
  14962. currentVAO = this._bindVAO(vaoExt, shader, geometry, program);
  14963. }
  14964. this._renderObject(renderable, currentVAO);
  14965. // After render hook
  14966. passConfig.afterRender(this, renderable);
  14967. renderable.afterRender && renderable.afterRender(this);
  14968. prevProgram = program;
  14969. prevRenderable = renderable;
  14970. }
  14971. // TODO Seems need to be bound to null immediately if vao is changed?
  14972. if (vaoExt) {
  14973. vaoExt.bindVertexArrayOES(null);
  14974. }
  14975. this.trigger('afterrenderpass', this, list, camera, passConfig);
  14976. },
  14977. getMaxJointNumber: function () {
  14978. return this._glinfo.getMaxJointNumber();
  14979. },
  14980. _updateSkeleton: function (object, program, slot) {
  14981. var _gl = this.gl;
  14982. var skeleton = object.skeleton;
  14983. // Set pose matrices of skinned mesh
  14984. if (skeleton) {
  14985. // TODO Update before culling.
  14986. skeleton.update();
  14987. if (object.joints.length > this._glinfo.getMaxJointNumber()) {
  14988. var skinMatricesTexture = skeleton.getSubSkinMatricesTexture(object.__uid__, object.joints);
  14989. program.useTextureSlot(this, skinMatricesTexture, slot);
  14990. program.setUniform(_gl, '1i', 'skinMatricesTexture', slot);
  14991. program.setUniform(_gl, '1f', 'skinMatricesTextureSize', skinMatricesTexture.width);
  14992. }
  14993. else {
  14994. var skinMatricesArray = skeleton.getSubSkinMatrices(object.__uid__, object.joints);
  14995. program.setUniformOfSemantic(_gl, 'SKIN_MATRIX', skinMatricesArray);
  14996. }
  14997. }
  14998. },
  14999. _renderObject: function (renderable, vao) {
  15000. var _gl = this.gl;
  15001. var geometry = renderable.geometry;
  15002. var glDrawMode = renderable.mode;
  15003. if (glDrawMode == null) {
  15004. glDrawMode = 0x0004;
  15005. }
  15006. // if (glDrawMode === glenum.LINES || glDrawMode === glenum.LINE_STRIP || glDrawMode === glenum.LINE_LOOP) {
  15007. // _gl.lineWidth(this.lineWidth);
  15008. // }
  15009. if (vao.indicesBuffer) {
  15010. var uintExt = this.getGLExtension('OES_element_index_uint');
  15011. var useUintExt = uintExt && (geometry.indices instanceof Uint32Array);
  15012. var indicesType = useUintExt ? _gl.UNSIGNED_INT : _gl.UNSIGNED_SHORT;
  15013. _gl.drawElements(glDrawMode, vao.indicesBuffer.count, indicesType, 0);
  15014. }
  15015. else {
  15016. // FIXME Use vertex number in buffer
  15017. // vertexCount may get the wrong value when geometry forget to mark dirty after update
  15018. _gl.drawArrays(glDrawMode, 0, geometry.vertexCount);
  15019. }
  15020. },
  15021. _bindMaterial: function (renderable, material, program, prevRenderable, prevMaterial, prevProgram, getUniformValue) {
  15022. var _gl = this.gl;
  15023. // PENDING Same texture in different material take different slot?
  15024. // May use shader of other material if shader code are same
  15025. var sameProgram = prevProgram === program;
  15026. var currentTextureSlot = program.currentTextureSlot();
  15027. var enabledUniforms = material.getEnabledUniforms();
  15028. var textureUniforms = material.getTextureUniforms();
  15029. var placeholderTexture = this._placeholderTexture;
  15030. for (var u = 0; u < textureUniforms.length; u++) {
  15031. var symbol = textureUniforms[u];
  15032. var uniformValue = getUniformValue(renderable, material, symbol);
  15033. var uniformType = material.uniforms[symbol].type;
  15034. // Not use `instanceof` to determine if a value is texture in Material#bind.
  15035. // Use type instead, in some case texture may be in different namespaces.
  15036. // TODO Duck type validate.
  15037. if (uniformType === 't' && uniformValue) {
  15038. // Reset slot
  15039. uniformValue.__slot = -1;
  15040. }
  15041. else if (uniformType === 'tv') {
  15042. for (var i = 0; i < uniformValue.length; i++) {
  15043. if (uniformValue[i]) {
  15044. uniformValue[i].__slot = -1;
  15045. }
  15046. }
  15047. }
  15048. }
  15049. placeholderTexture.__slot = -1;
  15050. // Set uniforms
  15051. for (var u = 0; u < enabledUniforms.length; u++) {
  15052. var symbol = enabledUniforms[u];
  15053. var uniform = material.uniforms[symbol];
  15054. var uniformValue = getUniformValue(renderable, material, symbol);
  15055. var uniformType = uniform.type;
  15056. var isTexture = uniformType === 't';
  15057. if (isTexture) {
  15058. if (!uniformValue || !uniformValue.isRenderable()) {
  15059. uniformValue = placeholderTexture;
  15060. }
  15061. }
  15062. // PENDING
  15063. // When binding two materials with the same shader
  15064. // Many uniforms will be be set twice even if they have the same value
  15065. // So add a evaluation to see if the uniform is really needed to be set
  15066. if (prevMaterial && sameProgram) {
  15067. var prevUniformValue = getUniformValue(prevRenderable, prevMaterial, symbol);
  15068. if (isTexture) {
  15069. if (!prevUniformValue || !prevUniformValue.isRenderable()) {
  15070. prevUniformValue = placeholderTexture;
  15071. }
  15072. }
  15073. if (prevUniformValue === uniformValue) {
  15074. if (isTexture) {
  15075. // Still take the slot to make sure same texture in different materials have same slot.
  15076. program.takeCurrentTextureSlot(this, null);
  15077. }
  15078. else if (uniformType === 'tv' && uniformValue) {
  15079. for (var i = 0; i < uniformValue.length; i++) {
  15080. program.takeCurrentTextureSlot(this, null);
  15081. }
  15082. }
  15083. continue;
  15084. }
  15085. }
  15086. if (uniformValue == null) {
  15087. continue;
  15088. }
  15089. else if (isTexture) {
  15090. if (uniformValue.__slot < 0) {
  15091. var slot = program.currentTextureSlot();
  15092. var res = program.setUniform(_gl, '1i', symbol, slot);
  15093. if (res) { // Texture uniform is enabled
  15094. program.takeCurrentTextureSlot(this, uniformValue);
  15095. uniformValue.__slot = slot;
  15096. }
  15097. }
  15098. // Multiple uniform use same texture..
  15099. else {
  15100. program.setUniform(_gl, '1i', symbol, uniformValue.__slot);
  15101. }
  15102. }
  15103. else if (Array.isArray(uniformValue)) {
  15104. if (uniformValue.length === 0) {
  15105. continue;
  15106. }
  15107. // Texture Array
  15108. if (uniformType === 'tv') {
  15109. if (!program.hasUniform(symbol)) {
  15110. continue;
  15111. }
  15112. var arr = [];
  15113. for (var i = 0; i < uniformValue.length; i++) {
  15114. var texture = uniformValue[i];
  15115. if (texture.__slot < 0) {
  15116. var slot = program.currentTextureSlot();
  15117. arr.push(slot);
  15118. program.takeCurrentTextureSlot(this, texture);
  15119. texture.__slot = slot;
  15120. }
  15121. else {
  15122. arr.push(texture.__slot);
  15123. }
  15124. }
  15125. program.setUniform(_gl, '1iv', symbol, arr);
  15126. }
  15127. else {
  15128. program.setUniform(_gl, uniform.type, symbol, uniformValue);
  15129. }
  15130. }
  15131. else {
  15132. program.setUniform(_gl, uniform.type, symbol, uniformValue);
  15133. }
  15134. }
  15135. var newSlot = program.currentTextureSlot();
  15136. // Texture slot maybe used out of material.
  15137. program.resetTextureSlot(currentTextureSlot);
  15138. return newSlot;
  15139. },
  15140. _bindVAO: function (vaoExt, shader, geometry, program) {
  15141. var isStatic = !geometry.dynamic;
  15142. var _gl = this.gl;
  15143. var vaoId = this.__uid__ + '-' + program.__uid__;
  15144. var vao = geometry.__vaoCache[vaoId];
  15145. if (!vao) {
  15146. var chunks = geometry.getBufferChunks(this);
  15147. if (!chunks || !chunks.length) { // Empty mesh
  15148. return;
  15149. }
  15150. var chunk = chunks[0];
  15151. var attributeBuffers = chunk.attributeBuffers;
  15152. var indicesBuffer = chunk.indicesBuffer;
  15153. var availableAttributes = [];
  15154. var availableAttributeSymbols = [];
  15155. for (var a = 0; a < attributeBuffers.length; a++) {
  15156. var attributeBufferInfo = attributeBuffers[a];
  15157. var name = attributeBufferInfo.name;
  15158. var semantic = attributeBufferInfo.semantic;
  15159. var symbol;
  15160. if (semantic) {
  15161. var semanticInfo = shader.attributeSemantics[semantic];
  15162. symbol = semanticInfo && semanticInfo.symbol;
  15163. }
  15164. else {
  15165. symbol = name;
  15166. }
  15167. if (symbol && program.attributes[symbol]) {
  15168. availableAttributes.push(attributeBufferInfo);
  15169. availableAttributeSymbols.push(symbol);
  15170. }
  15171. }
  15172. vao = new VertexArrayObject(
  15173. availableAttributes,
  15174. availableAttributeSymbols,
  15175. indicesBuffer
  15176. );
  15177. if (isStatic) {
  15178. geometry.__vaoCache[vaoId] = vao;
  15179. }
  15180. }
  15181. var needsBindAttributes = true;
  15182. // Create vertex object array cost a lot
  15183. // So we don't use it on the dynamic object
  15184. if (vaoExt && isStatic) {
  15185. // Use vertex array object
  15186. // http://blog.tojicode.com/2012/10/oesvertexarrayobject-extension.html
  15187. if (vao.vao == null) {
  15188. vao.vao = vaoExt.createVertexArrayOES();
  15189. }
  15190. else {
  15191. needsBindAttributes = false;
  15192. }
  15193. vaoExt.bindVertexArrayOES(vao.vao);
  15194. }
  15195. var availableAttributes = vao.availableAttributes;
  15196. var indicesBuffer = vao.indicesBuffer;
  15197. if (needsBindAttributes) {
  15198. var locationList = program.enableAttributes(this, vao.availableAttributeSymbols, (vaoExt && isStatic && vao));
  15199. // Setting attributes;
  15200. for (var a = 0; a < availableAttributes.length; a++) {
  15201. var location = locationList[a];
  15202. if (location === -1) {
  15203. continue;
  15204. }
  15205. var attributeBufferInfo = availableAttributes[a];
  15206. var buffer = attributeBufferInfo.buffer;
  15207. var size = attributeBufferInfo.size;
  15208. var glType = attributeBufferTypeMap[attributeBufferInfo.type] || _gl.FLOAT;
  15209. _gl.bindBuffer(_gl.ARRAY_BUFFER, buffer);
  15210. _gl.vertexAttribPointer(location, size, glType, false, 0, 0);
  15211. }
  15212. if (geometry.isUseIndices()) {
  15213. _gl.bindBuffer(_gl.ELEMENT_ARRAY_BUFFER, indicesBuffer.buffer);
  15214. }
  15215. }
  15216. return vao;
  15217. },
  15218. renderPreZ: function (list, scene, camera) {
  15219. var _gl = this.gl;
  15220. var preZPassMaterial = this._prezMaterial || new __WEBPACK_IMPORTED_MODULE_4__Material__["a" /* default */]({
  15221. shader: new __WEBPACK_IMPORTED_MODULE_7__Shader__["a" /* default */](__WEBPACK_IMPORTED_MODULE_7__Shader__["a" /* default */].source('clay.prez.vertex'), __WEBPACK_IMPORTED_MODULE_7__Shader__["a" /* default */].source('clay.prez.fragment'))
  15222. });
  15223. this._prezMaterial = preZPassMaterial;
  15224. _gl.colorMask(false, false, false, false);
  15225. _gl.depthMask(true);
  15226. // Status
  15227. this.renderPass(list, camera, {
  15228. ifRender: function (renderable) {
  15229. return !renderable.ignorePreZ;
  15230. },
  15231. isMaterialChanged: function (renderable, prevRenderable) {
  15232. var matA = renderable.material;
  15233. var matB = prevRenderable.material;
  15234. return matA.get('diffuseMap') !== matB.get('diffuseMap')
  15235. || (matA.get('alphaCutoff') || 0) !== (matB.get('alphaCutoff') || 0);
  15236. },
  15237. getUniform: function (renderable, depthMaterial, symbol) {
  15238. if (symbol === 'alphaMap') {
  15239. return renderable.material.get('diffuseMap');
  15240. }
  15241. else if (symbol === 'alphaCutoff') {
  15242. if (renderable.material.isDefined('fragment', 'ALPHA_TEST')
  15243. && renderable.material.get('diffuseMap')
  15244. ) {
  15245. var alphaCutoff = renderable.material.get('alphaCutoff');
  15246. return alphaCutoff || 0;
  15247. }
  15248. return 0;
  15249. }
  15250. else {
  15251. return depthMaterial.get(symbol);
  15252. }
  15253. },
  15254. getMaterial: function () {
  15255. return preZPassMaterial;
  15256. },
  15257. sort: this.opaqueSortCompare
  15258. });
  15259. _gl.colorMask(true, true, true, true);
  15260. _gl.depthMask(true);
  15261. },
  15262. /**
  15263. * Dispose given scene, including all geometris, textures and shaders in the scene
  15264. * @param {clay.Scene} scene
  15265. */
  15266. disposeScene: function (scene) {
  15267. this.disposeNode(scene, true, true);
  15268. scene.dispose();
  15269. },
  15270. /**
  15271. * Dispose given node, including all geometries, textures and shaders attached on it or its descendant
  15272. * @param {clay.Node} node
  15273. * @param {boolean} [disposeGeometry=false] If dispose the geometries used in the descendant mesh
  15274. * @param {boolean} [disposeTexture=false] If dispose the textures used in the descendant mesh
  15275. */
  15276. disposeNode: function (root, disposeGeometry, disposeTexture) {
  15277. // Dettached from parent
  15278. if (root.getParent()) {
  15279. root.getParent().remove(root);
  15280. }
  15281. var disposedMap = {};
  15282. root.traverse(function (node) {
  15283. var material = node.material;
  15284. if (node.geometry && disposeGeometry) {
  15285. node.geometry.dispose(this);
  15286. }
  15287. if (disposeTexture && material && !disposedMap[material.__uid__]) {
  15288. var textureUniforms = material.getTextureUniforms();
  15289. for (var u = 0; u < textureUniforms.length; u++) {
  15290. var uniformName = textureUniforms[u];
  15291. var val = material.uniforms[uniformName].value;
  15292. var uniformType = material.uniforms[uniformName].type;
  15293. if (!val) {
  15294. continue;
  15295. }
  15296. if (uniformType === 't') {
  15297. val.dispose && val.dispose(this);
  15298. }
  15299. else if (uniformType === 'tv') {
  15300. for (var k = 0; k < val.length; k++) {
  15301. if (val[k]) {
  15302. val[k].dispose && val[k].dispose(this);
  15303. }
  15304. }
  15305. }
  15306. }
  15307. disposedMap[material.__uid__] = true;
  15308. }
  15309. // Particle system and AmbientCubemap light need to dispose
  15310. if (node.dispose) {
  15311. node.dispose(this);
  15312. }
  15313. }, this);
  15314. },
  15315. /**
  15316. * Dispose given geometry
  15317. * @param {clay.Geometry} geometry
  15318. */
  15319. disposeGeometry: function (geometry) {
  15320. geometry.dispose(this);
  15321. },
  15322. /**
  15323. * Dispose given texture
  15324. * @param {clay.Texture} texture
  15325. */
  15326. disposeTexture: function (texture) {
  15327. texture.dispose(this);
  15328. },
  15329. /**
  15330. * Dispose given frame buffer
  15331. * @param {clay.FrameBuffer} frameBuffer
  15332. */
  15333. disposeFrameBuffer: function (frameBuffer) {
  15334. frameBuffer.dispose(this);
  15335. },
  15336. /**
  15337. * Dispose renderer
  15338. */
  15339. dispose: function () { },
  15340. /**
  15341. * Convert screen coords to normalized device coordinates(NDC)
  15342. * Screen coords can get from mouse event, it is positioned relative to canvas element
  15343. * NDC can be used in ray casting with Camera.prototype.castRay methods
  15344. *
  15345. * @param {number} x
  15346. * @param {number} y
  15347. * @param {clay.Vector2} [out]
  15348. * @return {clay.Vector2}
  15349. */
  15350. screenToNDC: function (x, y, out) {
  15351. if (!out) {
  15352. out = new __WEBPACK_IMPORTED_MODULE_5__math_Vector2__["a" /* default */]();
  15353. }
  15354. // Invert y;
  15355. y = this._height - y;
  15356. var viewport = this.viewport;
  15357. var arr = out.array;
  15358. arr[0] = (x - viewport.x) / viewport.width;
  15359. arr[0] = arr[0] * 2 - 1;
  15360. arr[1] = (y - viewport.y) / viewport.height;
  15361. arr[1] = arr[1] * 2 - 1;
  15362. return out;
  15363. }
  15364. });
  15365. /**
  15366. * Opaque renderables compare function
  15367. * @param {clay.Renderable} x
  15368. * @param {clay.Renderable} y
  15369. * @return {boolean}
  15370. * @static
  15371. */
  15372. Renderer.opaqueSortCompare = Renderer.prototype.opaqueSortCompare = function (x, y) {
  15373. // Priority renderOrder -> program -> material -> geometry
  15374. if (x.renderOrder === y.renderOrder) {
  15375. if (x.__program === y.__program) {
  15376. if (x.material === y.material) {
  15377. return x.geometry.__uid__ - y.geometry.__uid__;
  15378. }
  15379. return x.material.__uid__ - y.material.__uid__;
  15380. }
  15381. if (x.__program && y.__program) {
  15382. return x.__program.__uid__ - y.__program.__uid__;
  15383. }
  15384. return 0;
  15385. }
  15386. return x.renderOrder - y.renderOrder;
  15387. };
  15388. /**
  15389. * Transparent renderables compare function
  15390. * @param {clay.Renderable} a
  15391. * @param {clay.Renderable} b
  15392. * @return {boolean}
  15393. * @static
  15394. */
  15395. Renderer.transparentSortCompare = Renderer.prototype.transparentSortCompare = function (x, y) {
  15396. // Priority renderOrder -> depth -> program -> material -> geometry
  15397. if (x.renderOrder === y.renderOrder) {
  15398. if (x.__depth === y.__depth) {
  15399. if (x.__program === y.__program) {
  15400. if (x.material === y.material) {
  15401. return x.geometry.__uid__ - y.geometry.__uid__;
  15402. }
  15403. return x.material.__uid__ - y.material.__uid__;
  15404. }
  15405. if (x.__program && y.__program) {
  15406. return x.__program.__uid__ - y.__program.__uid__;
  15407. }
  15408. return 0;
  15409. }
  15410. // Depth is negative
  15411. // So farther object has smaller depth value
  15412. return x.__depth - y.__depth;
  15413. }
  15414. return x.renderOrder - y.renderOrder;
  15415. };
  15416. // Temporary variables
  15417. var matrices = {
  15418. IDENTITY: mat4Create(),
  15419. WORLD: mat4Create(),
  15420. VIEW: mat4Create(),
  15421. PROJECTION: mat4Create(),
  15422. WORLDVIEW: mat4Create(),
  15423. VIEWPROJECTION: mat4Create(),
  15424. WORLDVIEWPROJECTION: mat4Create(),
  15425. WORLDINVERSE: mat4Create(),
  15426. VIEWINVERSE: mat4Create(),
  15427. PROJECTIONINVERSE: mat4Create(),
  15428. WORLDVIEWINVERSE: mat4Create(),
  15429. VIEWPROJECTIONINVERSE: mat4Create(),
  15430. WORLDVIEWPROJECTIONINVERSE: mat4Create(),
  15431. WORLDTRANSPOSE: mat4Create(),
  15432. VIEWTRANSPOSE: mat4Create(),
  15433. PROJECTIONTRANSPOSE: mat4Create(),
  15434. WORLDVIEWTRANSPOSE: mat4Create(),
  15435. VIEWPROJECTIONTRANSPOSE: mat4Create(),
  15436. WORLDVIEWPROJECTIONTRANSPOSE: mat4Create(),
  15437. WORLDINVERSETRANSPOSE: mat4Create(),
  15438. VIEWINVERSETRANSPOSE: mat4Create(),
  15439. PROJECTIONINVERSETRANSPOSE: mat4Create(),
  15440. WORLDVIEWINVERSETRANSPOSE: mat4Create(),
  15441. VIEWPROJECTIONINVERSETRANSPOSE: mat4Create(),
  15442. WORLDVIEWPROJECTIONINVERSETRANSPOSE: mat4Create()
  15443. };
  15444. /**
  15445. * @name clay.Renderer.COLOR_BUFFER_BIT
  15446. * @type {number}
  15447. */
  15448. Renderer.COLOR_BUFFER_BIT = __WEBPACK_IMPORTED_MODULE_2__core_glenum__["a" /* default */].COLOR_BUFFER_BIT;
  15449. /**
  15450. * @name clay.Renderer.DEPTH_BUFFER_BIT
  15451. * @type {number}
  15452. */
  15453. Renderer.DEPTH_BUFFER_BIT = __WEBPACK_IMPORTED_MODULE_2__core_glenum__["a" /* default */].DEPTH_BUFFER_BIT;
  15454. /**
  15455. * @name clay.Renderer.STENCIL_BUFFER_BIT
  15456. * @type {number}
  15457. */
  15458. Renderer.STENCIL_BUFFER_BIT = __WEBPACK_IMPORTED_MODULE_2__core_glenum__["a" /* default */].STENCIL_BUFFER_BIT;
  15459. /* harmony default export */ __webpack_exports__["a"] = (Renderer);
  15460. /***/
  15461. }),
  15462. /* 53 */
  15463. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  15464. "use strict";
  15465. function Handler(action, context) {
  15466. this.action = action;
  15467. this.context = context;
  15468. }
  15469. /**
  15470. * @mixin
  15471. * @alias clay.core.mixin.notifier
  15472. */
  15473. var notifier = {
  15474. /**
  15475. * Trigger event
  15476. * @param {string} name
  15477. */
  15478. trigger: function (name) {
  15479. if (!this.hasOwnProperty('__handlers__')) {
  15480. return;
  15481. }
  15482. if (!this.__handlers__.hasOwnProperty(name)) {
  15483. return;
  15484. }
  15485. var hdls = this.__handlers__[name];
  15486. var l = hdls.length, i = -1, args = arguments;
  15487. // Optimize advise from backbone
  15488. switch (args.length) {
  15489. case 1:
  15490. while (++i < l) {
  15491. hdls[i].action.call(hdls[i].context);
  15492. }
  15493. return;
  15494. case 2:
  15495. while (++i < l) {
  15496. hdls[i].action.call(hdls[i].context, args[1]);
  15497. }
  15498. return;
  15499. case 3:
  15500. while (++i < l) {
  15501. hdls[i].action.call(hdls[i].context, args[1], args[2]);
  15502. }
  15503. return;
  15504. case 4:
  15505. while (++i < l) {
  15506. hdls[i].action.call(hdls[i].context, args[1], args[2], args[3]);
  15507. }
  15508. return;
  15509. case 5:
  15510. while (++i < l) {
  15511. hdls[i].action.call(hdls[i].context, args[1], args[2], args[3], args[4]);
  15512. }
  15513. return;
  15514. default:
  15515. while (++i < l) {
  15516. hdls[i].action.apply(hdls[i].context, Array.prototype.slice.call(args, 1));
  15517. }
  15518. return;
  15519. }
  15520. },
  15521. /**
  15522. * Register event handler
  15523. * @param {string} name
  15524. * @param {Function} action
  15525. * @param {Object} [context]
  15526. * @chainable
  15527. */
  15528. on: function (name, action, context) {
  15529. if (!name || !action) {
  15530. return;
  15531. }
  15532. var handlers = this.__handlers__ || (this.__handlers__ = {});
  15533. if (!handlers[name]) {
  15534. handlers[name] = [];
  15535. }
  15536. else {
  15537. if (this.has(name, action)) {
  15538. return;
  15539. }
  15540. }
  15541. var handler = new Handler(action, context || this);
  15542. handlers[name].push(handler);
  15543. return this;
  15544. },
  15545. /**
  15546. * Register event, event will only be triggered once and then removed
  15547. * @param {string} name
  15548. * @param {Function} action
  15549. * @param {Object} [context]
  15550. * @chainable
  15551. */
  15552. once: function (name, action, context) {
  15553. if (!name || !action) {
  15554. return;
  15555. }
  15556. var self = this;
  15557. function wrapper() {
  15558. self.off(name, wrapper);
  15559. action.apply(this, arguments);
  15560. }
  15561. return this.on(name, wrapper, context);
  15562. },
  15563. /**
  15564. * Alias of once('before' + name)
  15565. * @param {string} name
  15566. * @param {Function} action
  15567. * @param {Object} [context]
  15568. * @chainable
  15569. */
  15570. before: function (name, action, context) {
  15571. if (!name || !action) {
  15572. return;
  15573. }
  15574. name = 'before' + name;
  15575. return this.on(name, action, context);
  15576. },
  15577. /**
  15578. * Alias of once('after' + name)
  15579. * @param {string} name
  15580. * @param {Function} action
  15581. * @param {Object} [context]
  15582. * @chainable
  15583. */
  15584. after: function (name, action, context) {
  15585. if (!name || !action) {
  15586. return;
  15587. }
  15588. name = 'after' + name;
  15589. return this.on(name, action, context);
  15590. },
  15591. /**
  15592. * Alias of on('success')
  15593. * @param {Function} action
  15594. * @param {Object} [context]
  15595. * @chainable
  15596. */
  15597. success: function (action, context) {
  15598. return this.once('success', action, context);
  15599. },
  15600. /**
  15601. * Alias of on('error')
  15602. * @param {Function} action
  15603. * @param {Object} [context]
  15604. * @chainable
  15605. */
  15606. error: function (action, context) {
  15607. return this.once('error', action, context);
  15608. },
  15609. /**
  15610. * Remove event listener
  15611. * @param {Function} action
  15612. * @param {Object} [context]
  15613. * @chainable
  15614. */
  15615. off: function (name, action) {
  15616. var handlers = this.__handlers__ || (this.__handlers__ = {});
  15617. if (!action) {
  15618. handlers[name] = [];
  15619. return;
  15620. }
  15621. if (handlers[name]) {
  15622. var hdls = handlers[name];
  15623. var retains = [];
  15624. for (var i = 0; i < hdls.length; i++) {
  15625. if (action && hdls[i].action !== action) {
  15626. retains.push(hdls[i]);
  15627. }
  15628. }
  15629. handlers[name] = retains;
  15630. }
  15631. return this;
  15632. },
  15633. /**
  15634. * If registered the event handler
  15635. * @param {string} name
  15636. * @param {Function} action
  15637. * @return {boolean}
  15638. */
  15639. has: function (name, action) {
  15640. var handlers = this.__handlers__;
  15641. if (!handlers ||
  15642. !handlers[name]) {
  15643. return false;
  15644. }
  15645. var hdls = handlers[name];
  15646. for (var i = 0; i < hdls.length; i++) {
  15647. if (hdls[i].action === action) {
  15648. return true;
  15649. }
  15650. }
  15651. }
  15652. };
  15653. /* harmony default export */ __webpack_exports__["a"] = (notifier);
  15654. /***/
  15655. }),
  15656. /* 54 */
  15657. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  15658. "use strict";
  15659. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Vector3__ = __webpack_require__(3);
  15660. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__ = __webpack_require__(12);
  15661. var EPSILON = 1e-5;
  15662. /**
  15663. * @constructor
  15664. * @alias clay.Ray
  15665. * @param {clay.Vector3} [origin]
  15666. * @param {clay.Vector3} [direction]
  15667. */
  15668. var Ray = function (origin, direction) {
  15669. /**
  15670. * @type {clay.Vector3}
  15671. */
  15672. this.origin = origin || new __WEBPACK_IMPORTED_MODULE_0__Vector3__["a" /* default */]();
  15673. /**
  15674. * @type {clay.Vector3}
  15675. */
  15676. this.direction = direction || new __WEBPACK_IMPORTED_MODULE_0__Vector3__["a" /* default */]();
  15677. };
  15678. Ray.prototype = {
  15679. constructor: Ray,
  15680. // http://www.siggraph.org/education/materials/HyperGraph/raytrace/rayplane_intersection.htm
  15681. /**
  15682. * Calculate intersection point between ray and a give plane
  15683. * @param {clay.Plane} plane
  15684. * @param {clay.Vector3} [out]
  15685. * @return {clay.Vector3}
  15686. */
  15687. intersectPlane: function (plane, out) {
  15688. var pn = plane.normal.array;
  15689. var d = plane.distance;
  15690. var ro = this.origin.array;
  15691. var rd = this.direction.array;
  15692. var divider = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].dot(pn, rd);
  15693. // ray is parallel to the plane
  15694. if (divider === 0) {
  15695. return null;
  15696. }
  15697. if (!out) {
  15698. out = new __WEBPACK_IMPORTED_MODULE_0__Vector3__["a" /* default */]();
  15699. }
  15700. var t = (__WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].dot(pn, ro) - d) / divider;
  15701. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].scaleAndAdd(out.array, ro, rd, -t);
  15702. out._dirty = true;
  15703. return out;
  15704. },
  15705. /**
  15706. * Mirror the ray against plane
  15707. * @param {clay.Plane} plane
  15708. */
  15709. mirrorAgainstPlane: function (plane) {
  15710. // Distance to plane
  15711. var d = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].dot(plane.normal.array, this.direction.array);
  15712. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].scaleAndAdd(this.direction.array, this.direction.array, plane.normal.array, -d * 2);
  15713. this.direction._dirty = true;
  15714. },
  15715. distanceToPoint: (function () {
  15716. var v = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].create();
  15717. return function (point) {
  15718. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].sub(v, point, this.origin.array);
  15719. // Distance from projection point to origin
  15720. var b = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].dot(v, this.direction.array);
  15721. if (b < 0) {
  15722. return __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].distance(this.origin.array, point);
  15723. }
  15724. // Squared distance from center to origin
  15725. var c2 = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].lenSquared(v);
  15726. // Squared distance from center to projection point
  15727. return Math.sqrt(c2 - b * b);
  15728. };
  15729. })(),
  15730. /**
  15731. * Calculate intersection point between ray and sphere
  15732. * @param {clay.Vector3} center
  15733. * @param {number} radius
  15734. * @param {clay.Vector3} out
  15735. * @return {clay.Vector3}
  15736. */
  15737. intersectSphere: (function () {
  15738. var v = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].create();
  15739. return function (center, radius, out) {
  15740. var origin = this.origin.array;
  15741. var direction = this.direction.array;
  15742. center = center.array;
  15743. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].sub(v, center, origin);
  15744. // Distance from projection point to origin
  15745. var b = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].dot(v, direction);
  15746. // Squared distance from center to origin
  15747. var c2 = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].squaredLength(v);
  15748. // Squared distance from center to projection point
  15749. var d2 = c2 - b * b;
  15750. var r2 = radius * radius;
  15751. // No intersection
  15752. if (d2 > r2) {
  15753. return;
  15754. }
  15755. var a = Math.sqrt(r2 - d2);
  15756. // First intersect point
  15757. var t0 = b - a;
  15758. // Second intersect point
  15759. var t1 = b + a;
  15760. if (!out) {
  15761. out = new __WEBPACK_IMPORTED_MODULE_0__Vector3__["a" /* default */]();
  15762. }
  15763. if (t0 < 0) {
  15764. if (t1 < 0) {
  15765. return null;
  15766. }
  15767. else {
  15768. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].scaleAndAdd(out.array, origin, direction, t1);
  15769. return out;
  15770. }
  15771. }
  15772. else {
  15773. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].scaleAndAdd(out.array, origin, direction, t0);
  15774. return out;
  15775. }
  15776. };
  15777. })(),
  15778. // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
  15779. /**
  15780. * Calculate intersection point between ray and bounding box
  15781. * @param {clay.BoundingBox} bbox
  15782. * @param {clay.Vector3}
  15783. * @return {clay.Vector3}
  15784. */
  15785. intersectBoundingBox: function (bbox, out) {
  15786. var dir = this.direction.array;
  15787. var origin = this.origin.array;
  15788. var min = bbox.min.array;
  15789. var max = bbox.max.array;
  15790. var invdirx = 1 / dir[0];
  15791. var invdiry = 1 / dir[1];
  15792. var invdirz = 1 / dir[2];
  15793. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  15794. if (invdirx >= 0) {
  15795. tmin = (min[0] - origin[0]) * invdirx;
  15796. tmax = (max[0] - origin[0]) * invdirx;
  15797. }
  15798. else {
  15799. tmax = (min[0] - origin[0]) * invdirx;
  15800. tmin = (max[0] - origin[0]) * invdirx;
  15801. }
  15802. if (invdiry >= 0) {
  15803. tymin = (min[1] - origin[1]) * invdiry;
  15804. tymax = (max[1] - origin[1]) * invdiry;
  15805. }
  15806. else {
  15807. tymax = (min[1] - origin[1]) * invdiry;
  15808. tymin = (max[1] - origin[1]) * invdiry;
  15809. }
  15810. if ((tmin > tymax) || (tymin > tmax)) {
  15811. return null;
  15812. }
  15813. if (tymin > tmin || tmin !== tmin) {
  15814. tmin = tymin;
  15815. }
  15816. if (tymax < tmax || tmax !== tmax) {
  15817. tmax = tymax;
  15818. }
  15819. if (invdirz >= 0) {
  15820. tzmin = (min[2] - origin[2]) * invdirz;
  15821. tzmax = (max[2] - origin[2]) * invdirz;
  15822. }
  15823. else {
  15824. tzmax = (min[2] - origin[2]) * invdirz;
  15825. tzmin = (max[2] - origin[2]) * invdirz;
  15826. }
  15827. if ((tmin > tzmax) || (tzmin > tmax)) {
  15828. return null;
  15829. }
  15830. if (tzmin > tmin || tmin !== tmin) {
  15831. tmin = tzmin;
  15832. }
  15833. if (tzmax < tmax || tmax !== tmax) {
  15834. tmax = tzmax;
  15835. }
  15836. if (tmax < 0) {
  15837. return null;
  15838. }
  15839. var t = tmin >= 0 ? tmin : tmax;
  15840. if (!out) {
  15841. out = new __WEBPACK_IMPORTED_MODULE_0__Vector3__["a" /* default */]();
  15842. }
  15843. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].scaleAndAdd(out.array, origin, dir, t);
  15844. return out;
  15845. },
  15846. // http://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm
  15847. /**
  15848. * Calculate intersection point between ray and three triangle vertices
  15849. * @param {clay.Vector3} a
  15850. * @param {clay.Vector3} b
  15851. * @param {clay.Vector3} c
  15852. * @param {boolean} singleSided, CW triangle will be ignored
  15853. * @param {clay.Vector3} [out]
  15854. * @param {clay.Vector3} [barycenteric] barycentric coords
  15855. * @return {clay.Vector3}
  15856. */
  15857. intersectTriangle: (function () {
  15858. var eBA = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].create();
  15859. var eCA = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].create();
  15860. var AO = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].create();
  15861. var vCross = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].create();
  15862. return function (a, b, c, singleSided, out, barycenteric) {
  15863. var dir = this.direction.array;
  15864. var origin = this.origin.array;
  15865. a = a.array;
  15866. b = b.array;
  15867. c = c.array;
  15868. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].sub(eBA, b, a);
  15869. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].sub(eCA, c, a);
  15870. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].cross(vCross, eCA, dir);
  15871. var det = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].dot(eBA, vCross);
  15872. if (singleSided) {
  15873. if (det > -EPSILON) {
  15874. return null;
  15875. }
  15876. }
  15877. else {
  15878. if (det > -EPSILON && det < EPSILON) {
  15879. return null;
  15880. }
  15881. }
  15882. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].sub(AO, origin, a);
  15883. var u = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].dot(vCross, AO) / det;
  15884. if (u < 0 || u > 1) {
  15885. return null;
  15886. }
  15887. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].cross(vCross, eBA, AO);
  15888. var v = __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].dot(dir, vCross) / det;
  15889. if (v < 0 || v > 1 || (u + v > 1)) {
  15890. return null;
  15891. }
  15892. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].cross(vCross, eBA, eCA);
  15893. var t = -__WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].dot(AO, vCross) / det;
  15894. if (t < 0) {
  15895. return null;
  15896. }
  15897. if (!out) {
  15898. out = new __WEBPACK_IMPORTED_MODULE_0__Vector3__["a" /* default */]();
  15899. }
  15900. if (barycenteric) {
  15901. __WEBPACK_IMPORTED_MODULE_0__Vector3__["a" /* default */].set(barycenteric, (1 - u - v), u, v);
  15902. }
  15903. __WEBPACK_IMPORTED_MODULE_1__glmatrix_vec3__["a" /* default */].scaleAndAdd(out.array, origin, dir, t);
  15904. return out;
  15905. };
  15906. })(),
  15907. /**
  15908. * Apply an affine transform matrix to the ray
  15909. * @return {clay.Matrix4} matrix
  15910. */
  15911. applyTransform: function (matrix) {
  15912. __WEBPACK_IMPORTED_MODULE_0__Vector3__["a" /* default */].add(this.direction, this.direction, this.origin);
  15913. __WEBPACK_IMPORTED_MODULE_0__Vector3__["a" /* default */].transformMat4(this.origin, this.origin, matrix);
  15914. __WEBPACK_IMPORTED_MODULE_0__Vector3__["a" /* default */].transformMat4(this.direction, this.direction, matrix);
  15915. __WEBPACK_IMPORTED_MODULE_0__Vector3__["a" /* default */].sub(this.direction, this.direction, this.origin);
  15916. __WEBPACK_IMPORTED_MODULE_0__Vector3__["a" /* default */].normalize(this.direction, this.direction);
  15917. },
  15918. /**
  15919. * Copy values from another ray
  15920. * @param {clay.Ray} ray
  15921. */
  15922. copy: function (ray) {
  15923. __WEBPACK_IMPORTED_MODULE_0__Vector3__["a" /* default */].copy(this.origin, ray.origin);
  15924. __WEBPACK_IMPORTED_MODULE_0__Vector3__["a" /* default */].copy(this.direction, ray.direction);
  15925. },
  15926. /**
  15927. * Clone a new ray
  15928. * @return {clay.Ray}
  15929. */
  15930. clone: function () {
  15931. var ray = new Ray();
  15932. ray.copy(this);
  15933. return ray;
  15934. }
  15935. };
  15936. /* harmony default export */ __webpack_exports__["a"] = (Ray);
  15937. /***/
  15938. }),
  15939. /* 55 */
  15940. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  15941. "use strict";
  15942. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__common__ = __webpack_require__(20);
  15943. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__vec3__ = __webpack_require__(12);
  15944. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__vec4__ = __webpack_require__(33);
  15945. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__mat3__ = __webpack_require__(34);
  15946. /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
  15947. Redistribution and use in source and binary forms, with or without modification,
  15948. are permitted provided that the following conditions are met:
  15949. * Redistributions of source code must retain the above copyright notice, this
  15950. list of conditions and the following disclaimer.
  15951. * Redistributions in binary form must reproduce the above copyright notice,
  15952. this list of conditions and the following disclaimer in the documentation
  15953. and/or other materials provided with the distribution.
  15954. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15955. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15956. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  15957. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  15958. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  15959. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  15960. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  15961. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  15962. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  15963. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
  15964. /**
  15965. * @class Quaternion
  15966. * @name quat
  15967. */
  15968. var quat = {};
  15969. /**
  15970. * Creates a new identity quat
  15971. *
  15972. * @returns {quat} a new quaternion
  15973. */
  15974. quat.create = function () {
  15975. var out = new __WEBPACK_IMPORTED_MODULE_0__common__["a" /* GLMAT_ARRAY_TYPE */](4);
  15976. out[0] = 0;
  15977. out[1] = 0;
  15978. out[2] = 0;
  15979. out[3] = 1;
  15980. return out;
  15981. };
  15982. /**
  15983. * Sets a quaternion to represent the shortest rotation from one
  15984. * vector to another.
  15985. *
  15986. * Both vectors are assumed to be unit length.
  15987. *
  15988. * @param {quat} out the receiving quaternion.
  15989. * @param {vec3} a the initial vector
  15990. * @param {vec3} b the destination vector
  15991. * @returns {quat} out
  15992. */
  15993. quat.rotationTo = (function () {
  15994. var tmpvec3 = __WEBPACK_IMPORTED_MODULE_1__vec3__["a" /* default */].create();
  15995. var xUnitVec3 = __WEBPACK_IMPORTED_MODULE_1__vec3__["a" /* default */].fromValues(1, 0, 0);
  15996. var yUnitVec3 = __WEBPACK_IMPORTED_MODULE_1__vec3__["a" /* default */].fromValues(0, 1, 0);
  15997. return function (out, a, b) {
  15998. var dot = __WEBPACK_IMPORTED_MODULE_1__vec3__["a" /* default */].dot(a, b);
  15999. if (dot < -0.999999) {
  16000. __WEBPACK_IMPORTED_MODULE_1__vec3__["a" /* default */].cross(tmpvec3, xUnitVec3, a);
  16001. if (__WEBPACK_IMPORTED_MODULE_1__vec3__["a" /* default */].length(tmpvec3) < 0.000001)
  16002. __WEBPACK_IMPORTED_MODULE_1__vec3__["a" /* default */].cross(tmpvec3, yUnitVec3, a);
  16003. __WEBPACK_IMPORTED_MODULE_1__vec3__["a" /* default */].normalize(tmpvec3, tmpvec3);
  16004. quat.setAxisAngle(out, tmpvec3, Math.PI);
  16005. return out;
  16006. } else if (dot > 0.999999) {
  16007. out[0] = 0;
  16008. out[1] = 0;
  16009. out[2] = 0;
  16010. out[3] = 1;
  16011. return out;
  16012. } else {
  16013. __WEBPACK_IMPORTED_MODULE_1__vec3__["a" /* default */].cross(tmpvec3, a, b);
  16014. out[0] = tmpvec3[0];
  16015. out[1] = tmpvec3[1];
  16016. out[2] = tmpvec3[2];
  16017. out[3] = 1 + dot;
  16018. return quat.normalize(out, out);
  16019. }
  16020. };
  16021. })();
  16022. /**
  16023. * Sets the specified quaternion with values corresponding to the given
  16024. * axes. Each axis is a vec3 and is expected to be unit length and
  16025. * perpendicular to all other specified axes.
  16026. *
  16027. * @param {vec3} view the vector representing the viewing direction
  16028. * @param {vec3} right the vector representing the local "right" direction
  16029. * @param {vec3} up the vector representing the local "up" direction
  16030. * @returns {quat} out
  16031. */
  16032. quat.setAxes = (function () {
  16033. var matr = __WEBPACK_IMPORTED_MODULE_3__mat3__["a" /* default */].create();
  16034. return function (out, view, right, up) {
  16035. matr[0] = right[0];
  16036. matr[3] = right[1];
  16037. matr[6] = right[2];
  16038. matr[1] = up[0];
  16039. matr[4] = up[1];
  16040. matr[7] = up[2];
  16041. matr[2] = -view[0];
  16042. matr[5] = -view[1];
  16043. matr[8] = -view[2];
  16044. return quat.normalize(out, quat.fromMat3(out, matr));
  16045. };
  16046. })();
  16047. /**
  16048. * Creates a new quat initialized with values from an existing quaternion
  16049. *
  16050. * @param {quat} a quaternion to clone
  16051. * @returns {quat} a new quaternion
  16052. * @function
  16053. */
  16054. quat.clone = __WEBPACK_IMPORTED_MODULE_2__vec4__["a" /* default */].clone;
  16055. /**
  16056. * Creates a new quat initialized with the given values
  16057. *
  16058. * @param {Number} x X component
  16059. * @param {Number} y Y component
  16060. * @param {Number} z Z component
  16061. * @param {Number} w W component
  16062. * @returns {quat} a new quaternion
  16063. * @function
  16064. */
  16065. quat.fromValues = __WEBPACK_IMPORTED_MODULE_2__vec4__["a" /* default */].fromValues;
  16066. /**
  16067. * Copy the values from one quat to another
  16068. *
  16069. * @param {quat} out the receiving quaternion
  16070. * @param {quat} a the source quaternion
  16071. * @returns {quat} out
  16072. * @function
  16073. */
  16074. quat.copy = __WEBPACK_IMPORTED_MODULE_2__vec4__["a" /* default */].copy;
  16075. /**
  16076. * Set the components of a quat to the given values
  16077. *
  16078. * @param {quat} out the receiving quaternion
  16079. * @param {Number} x X component
  16080. * @param {Number} y Y component
  16081. * @param {Number} z Z component
  16082. * @param {Number} w W component
  16083. * @returns {quat} out
  16084. * @function
  16085. */
  16086. quat.set = __WEBPACK_IMPORTED_MODULE_2__vec4__["a" /* default */].set;
  16087. /**
  16088. * Set a quat to the identity quaternion
  16089. *
  16090. * @param {quat} out the receiving quaternion
  16091. * @returns {quat} out
  16092. */
  16093. quat.identity = function (out) {
  16094. out[0] = 0;
  16095. out[1] = 0;
  16096. out[2] = 0;
  16097. out[3] = 1;
  16098. return out;
  16099. };
  16100. /**
  16101. * Sets a quat from the given angle and rotation axis,
  16102. * then returns it.
  16103. *
  16104. * @param {quat} out the receiving quaternion
  16105. * @param {vec3} axis the axis around which to rotate
  16106. * @param {Number} rad the angle in radians
  16107. * @returns {quat} out
  16108. **/
  16109. quat.setAxisAngle = function (out, axis, rad) {
  16110. rad = rad * 0.5;
  16111. var s = Math.sin(rad);
  16112. out[0] = s * axis[0];
  16113. out[1] = s * axis[1];
  16114. out[2] = s * axis[2];
  16115. out[3] = Math.cos(rad);
  16116. return out;
  16117. };
  16118. /**
  16119. * Adds two quat's
  16120. *
  16121. * @param {quat} out the receiving quaternion
  16122. * @param {quat} a the first operand
  16123. * @param {quat} b the second operand
  16124. * @returns {quat} out
  16125. * @function
  16126. */
  16127. quat.add = __WEBPACK_IMPORTED_MODULE_2__vec4__["a" /* default */].add;
  16128. /**
  16129. * Multiplies two quat's
  16130. *
  16131. * @param {quat} out the receiving quaternion
  16132. * @param {quat} a the first operand
  16133. * @param {quat} b the second operand
  16134. * @returns {quat} out
  16135. */
  16136. quat.multiply = function (out, a, b) {
  16137. var ax = a[0], ay = a[1], az = a[2], aw = a[3],
  16138. bx = b[0], by = b[1], bz = b[2], bw = b[3];
  16139. out[0] = ax * bw + aw * bx + ay * bz - az * by;
  16140. out[1] = ay * bw + aw * by + az * bx - ax * bz;
  16141. out[2] = az * bw + aw * bz + ax * by - ay * bx;
  16142. out[3] = aw * bw - ax * bx - ay * by - az * bz;
  16143. return out;
  16144. };
  16145. /**
  16146. * Alias for {@link quat.multiply}
  16147. * @function
  16148. */
  16149. quat.mul = quat.multiply;
  16150. /**
  16151. * Scales a quat by a scalar number
  16152. *
  16153. * @param {quat} out the receiving vector
  16154. * @param {quat} a the vector to scale
  16155. * @param {Number} b amount to scale the vector by
  16156. * @returns {quat} out
  16157. * @function
  16158. */
  16159. quat.scale = __WEBPACK_IMPORTED_MODULE_2__vec4__["a" /* default */].scale;
  16160. /**
  16161. * Rotates a quaternion by the given angle about the X axis
  16162. *
  16163. * @param {quat} out quat receiving operation result
  16164. * @param {quat} a quat to rotate
  16165. * @param {number} rad angle (in radians) to rotate
  16166. * @returns {quat} out
  16167. */
  16168. quat.rotateX = function (out, a, rad) {
  16169. rad *= 0.5;
  16170. var ax = a[0], ay = a[1], az = a[2], aw = a[3],
  16171. bx = Math.sin(rad), bw = Math.cos(rad);
  16172. out[0] = ax * bw + aw * bx;
  16173. out[1] = ay * bw + az * bx;
  16174. out[2] = az * bw - ay * bx;
  16175. out[3] = aw * bw - ax * bx;
  16176. return out;
  16177. };
  16178. /**
  16179. * Rotates a quaternion by the given angle about the Y axis
  16180. *
  16181. * @param {quat} out quat receiving operation result
  16182. * @param {quat} a quat to rotate
  16183. * @param {number} rad angle (in radians) to rotate
  16184. * @returns {quat} out
  16185. */
  16186. quat.rotateY = function (out, a, rad) {
  16187. rad *= 0.5;
  16188. var ax = a[0], ay = a[1], az = a[2], aw = a[3],
  16189. by = Math.sin(rad), bw = Math.cos(rad);
  16190. out[0] = ax * bw - az * by;
  16191. out[1] = ay * bw + aw * by;
  16192. out[2] = az * bw + ax * by;
  16193. out[3] = aw * bw - ay * by;
  16194. return out;
  16195. };
  16196. /**
  16197. * Rotates a quaternion by the given angle about the Z axis
  16198. *
  16199. * @param {quat} out quat receiving operation result
  16200. * @param {quat} a quat to rotate
  16201. * @param {number} rad angle (in radians) to rotate
  16202. * @returns {quat} out
  16203. */
  16204. quat.rotateZ = function (out, a, rad) {
  16205. rad *= 0.5;
  16206. var ax = a[0], ay = a[1], az = a[2], aw = a[3],
  16207. bz = Math.sin(rad), bw = Math.cos(rad);
  16208. out[0] = ax * bw + ay * bz;
  16209. out[1] = ay * bw - ax * bz;
  16210. out[2] = az * bw + aw * bz;
  16211. out[3] = aw * bw - az * bz;
  16212. return out;
  16213. };
  16214. /**
  16215. * Calculates the W component of a quat from the X, Y, and Z components.
  16216. * Assumes that quaternion is 1 unit in length.
  16217. * Any existing W component will be ignored.
  16218. *
  16219. * @param {quat} out the receiving quaternion
  16220. * @param {quat} a quat to calculate W component of
  16221. * @returns {quat} out
  16222. */
  16223. quat.calculateW = function (out, a) {
  16224. var x = a[0], y = a[1], z = a[2];
  16225. out[0] = x;
  16226. out[1] = y;
  16227. out[2] = z;
  16228. out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z));
  16229. return out;
  16230. };
  16231. /**
  16232. * Calculates the dot product of two quat's
  16233. *
  16234. * @param {quat} a the first operand
  16235. * @param {quat} b the second operand
  16236. * @returns {Number} dot product of a and b
  16237. * @function
  16238. */
  16239. quat.dot = __WEBPACK_IMPORTED_MODULE_2__vec4__["a" /* default */].dot;
  16240. /**
  16241. * Performs a linear interpolation between two quat's
  16242. *
  16243. * @param {quat} out the receiving quaternion
  16244. * @param {quat} a the first operand
  16245. * @param {quat} b the second operand
  16246. * @param {Number} t interpolation amount between the two inputs
  16247. * @returns {quat} out
  16248. * @function
  16249. */
  16250. quat.lerp = __WEBPACK_IMPORTED_MODULE_2__vec4__["a" /* default */].lerp;
  16251. /**
  16252. * Performs a spherical linear interpolation between two quat
  16253. *
  16254. * @param {quat} out the receiving quaternion
  16255. * @param {quat} a the first operand
  16256. * @param {quat} b the second operand
  16257. * @param {Number} t interpolation amount between the two inputs
  16258. * @returns {quat} out
  16259. */
  16260. quat.slerp = function (out, a, b, t) {
  16261. // benchmarks:
  16262. // http://jsperf.com/quaternion-slerp-implementations
  16263. var ax = a[0], ay = a[1], az = a[2], aw = a[3],
  16264. bx = b[0], by = b[1], bz = b[2], bw = b[3];
  16265. var omega, cosom, sinom, scale0, scale1;
  16266. // calc cosine
  16267. cosom = ax * bx + ay * by + az * bz + aw * bw;
  16268. // adjust signs (if necessary)
  16269. if (cosom < 0.0) {
  16270. cosom = -cosom;
  16271. bx = - bx;
  16272. by = - by;
  16273. bz = - bz;
  16274. bw = - bw;
  16275. }
  16276. // calculate coefficients
  16277. if ((1.0 - cosom) > 0.000001) {
  16278. // standard case (slerp)
  16279. omega = Math.acos(cosom);
  16280. sinom = Math.sin(omega);
  16281. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  16282. scale1 = Math.sin(t * omega) / sinom;
  16283. } else {
  16284. // "from" and "to" quaternions are very close
  16285. // ... so we can do a linear interpolation
  16286. scale0 = 1.0 - t;
  16287. scale1 = t;
  16288. }
  16289. // calculate final values
  16290. out[0] = scale0 * ax + scale1 * bx;
  16291. out[1] = scale0 * ay + scale1 * by;
  16292. out[2] = scale0 * az + scale1 * bz;
  16293. out[3] = scale0 * aw + scale1 * bw;
  16294. return out;
  16295. };
  16296. /**
  16297. * Calculates the inverse of a quat
  16298. *
  16299. * @param {quat} out the receiving quaternion
  16300. * @param {quat} a quat to calculate inverse of
  16301. * @returns {quat} out
  16302. */
  16303. quat.invert = function (out, a) {
  16304. var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
  16305. dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3,
  16306. invDot = dot ? 1.0 / dot : 0;
  16307. // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0
  16308. out[0] = -a0 * invDot;
  16309. out[1] = -a1 * invDot;
  16310. out[2] = -a2 * invDot;
  16311. out[3] = a3 * invDot;
  16312. return out;
  16313. };
  16314. /**
  16315. * Calculates the conjugate of a quat
  16316. * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.
  16317. *
  16318. * @param {quat} out the receiving quaternion
  16319. * @param {quat} a quat to calculate conjugate of
  16320. * @returns {quat} out
  16321. */
  16322. quat.conjugate = function (out, a) {
  16323. out[0] = -a[0];
  16324. out[1] = -a[1];
  16325. out[2] = -a[2];
  16326. out[3] = a[3];
  16327. return out;
  16328. };
  16329. /**
  16330. * Calculates the length of a quat
  16331. *
  16332. * @param {quat} a vector to calculate length of
  16333. * @returns {Number} length of a
  16334. * @function
  16335. */
  16336. quat.length = __WEBPACK_IMPORTED_MODULE_2__vec4__["a" /* default */].length;
  16337. /**
  16338. * Alias for {@link quat.length}
  16339. * @function
  16340. */
  16341. quat.len = quat.length;
  16342. /**
  16343. * Calculates the squared length of a quat
  16344. *
  16345. * @param {quat} a vector to calculate squared length of
  16346. * @returns {Number} squared length of a
  16347. * @function
  16348. */
  16349. quat.squaredLength = __WEBPACK_IMPORTED_MODULE_2__vec4__["a" /* default */].squaredLength;
  16350. /**
  16351. * Alias for {@link quat.squaredLength}
  16352. * @function
  16353. */
  16354. quat.sqrLen = quat.squaredLength;
  16355. /**
  16356. * Normalize a quat
  16357. *
  16358. * @param {quat} out the receiving quaternion
  16359. * @param {quat} a quaternion to normalize
  16360. * @returns {quat} out
  16361. * @function
  16362. */
  16363. quat.normalize = __WEBPACK_IMPORTED_MODULE_2__vec4__["a" /* default */].normalize;
  16364. /**
  16365. * Creates a quaternion from the given 3x3 rotation matrix.
  16366. *
  16367. * NOTE: The resultant quaternion is not normalized, so you should be sure
  16368. * to renormalize the quaternion yourself where necessary.
  16369. *
  16370. * @param {quat} out the receiving quaternion
  16371. * @param {mat3} m rotation matrix
  16372. * @returns {quat} out
  16373. * @function
  16374. */
  16375. quat.fromMat3 = function (out, m) {
  16376. // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
  16377. // article "Quaternion Calculus and Fast Animation".
  16378. var fTrace = m[0] + m[4] + m[8];
  16379. var fRoot;
  16380. if (fTrace > 0.0) {
  16381. // |w| > 1/2, may as well choose w > 1/2
  16382. fRoot = Math.sqrt(fTrace + 1.0); // 2w
  16383. out[3] = 0.5 * fRoot;
  16384. fRoot = 0.5 / fRoot; // 1/(4w)
  16385. out[0] = (m[5] - m[7]) * fRoot;
  16386. out[1] = (m[6] - m[2]) * fRoot;
  16387. out[2] = (m[1] - m[3]) * fRoot;
  16388. } else {
  16389. // |w| <= 1/2
  16390. var i = 0;
  16391. if (m[4] > m[0])
  16392. i = 1;
  16393. if (m[8] > m[i * 3 + i])
  16394. i = 2;
  16395. var j = (i + 1) % 3;
  16396. var k = (i + 2) % 3;
  16397. fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);
  16398. out[i] = 0.5 * fRoot;
  16399. fRoot = 0.5 / fRoot;
  16400. out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;
  16401. out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;
  16402. out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;
  16403. }
  16404. return out;
  16405. };
  16406. /* harmony default export */ __webpack_exports__["a"] = (quat);
  16407. /***/
  16408. }),
  16409. /* 56 */
  16410. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  16411. "use strict";
  16412. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__ = __webpack_require__(55);
  16413. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__glmatrix_mat3__ = __webpack_require__(34);
  16414. /**
  16415. * @constructor
  16416. * @alias clay.Quaternion
  16417. * @param {number} x
  16418. * @param {number} y
  16419. * @param {number} z
  16420. * @param {number} w
  16421. */
  16422. var Quaternion = function (x, y, z, w) {
  16423. x = x || 0;
  16424. y = y || 0;
  16425. z = z || 0;
  16426. w = w === undefined ? 1 : w;
  16427. /**
  16428. * Storage of Quaternion, read and write of x, y, z, w will change the values in array
  16429. * All methods also operate on the array instead of x, y, z, w components
  16430. * @name array
  16431. * @type {Float32Array}
  16432. * @memberOf clay.Quaternion#
  16433. */
  16434. this.array = __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].fromValues(x, y, z, w);
  16435. /**
  16436. * Dirty flag is used by the Node to determine
  16437. * if the matrix is updated to latest
  16438. * @name _dirty
  16439. * @type {boolean}
  16440. * @memberOf clay.Quaternion#
  16441. */
  16442. this._dirty = true;
  16443. };
  16444. Quaternion.prototype = {
  16445. constructor: Quaternion,
  16446. /**
  16447. * Add b to self
  16448. * @param {clay.Quaternion} b
  16449. * @return {clay.Quaternion}
  16450. */
  16451. add: function (b) {
  16452. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].add(this.array, this.array, b.array);
  16453. this._dirty = true;
  16454. return this;
  16455. },
  16456. /**
  16457. * Calculate the w component from x, y, z component
  16458. * @return {clay.Quaternion}
  16459. */
  16460. calculateW: function () {
  16461. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].calculateW(this.array, this.array);
  16462. this._dirty = true;
  16463. return this;
  16464. },
  16465. /**
  16466. * Set x, y and z components
  16467. * @param {number} x
  16468. * @param {number} y
  16469. * @param {number} z
  16470. * @param {number} w
  16471. * @return {clay.Quaternion}
  16472. */
  16473. set: function (x, y, z, w) {
  16474. this.array[0] = x;
  16475. this.array[1] = y;
  16476. this.array[2] = z;
  16477. this.array[3] = w;
  16478. this._dirty = true;
  16479. return this;
  16480. },
  16481. /**
  16482. * Set x, y, z and w components from array
  16483. * @param {Float32Array|number[]} arr
  16484. * @return {clay.Quaternion}
  16485. */
  16486. setArray: function (arr) {
  16487. this.array[0] = arr[0];
  16488. this.array[1] = arr[1];
  16489. this.array[2] = arr[2];
  16490. this.array[3] = arr[3];
  16491. this._dirty = true;
  16492. return this;
  16493. },
  16494. /**
  16495. * Clone a new Quaternion
  16496. * @return {clay.Quaternion}
  16497. */
  16498. clone: function () {
  16499. return new Quaternion(this.x, this.y, this.z, this.w);
  16500. },
  16501. /**
  16502. * Calculates the conjugate of self If the quaternion is normalized,
  16503. * this function is faster than invert and produces the same result.
  16504. *
  16505. * @return {clay.Quaternion}
  16506. */
  16507. conjugate: function () {
  16508. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].conjugate(this.array, this.array);
  16509. this._dirty = true;
  16510. return this;
  16511. },
  16512. /**
  16513. * Copy from b
  16514. * @param {clay.Quaternion} b
  16515. * @return {clay.Quaternion}
  16516. */
  16517. copy: function (b) {
  16518. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].copy(this.array, b.array);
  16519. this._dirty = true;
  16520. return this;
  16521. },
  16522. /**
  16523. * Dot product of self and b
  16524. * @param {clay.Quaternion} b
  16525. * @return {number}
  16526. */
  16527. dot: function (b) {
  16528. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].dot(this.array, b.array);
  16529. },
  16530. /**
  16531. * Set from the given 3x3 rotation matrix
  16532. * @param {clay.Matrix3} m
  16533. * @return {clay.Quaternion}
  16534. */
  16535. fromMat3: function (m) {
  16536. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].fromMat3(this.array, m.array);
  16537. this._dirty = true;
  16538. return this;
  16539. },
  16540. /**
  16541. * Set from the given 4x4 rotation matrix
  16542. * The 4th column and 4th row will be droped
  16543. * @param {clay.Matrix4} m
  16544. * @return {clay.Quaternion}
  16545. */
  16546. fromMat4: (function () {
  16547. var m3 = __WEBPACK_IMPORTED_MODULE_1__glmatrix_mat3__["a" /* default */].create();
  16548. return function (m) {
  16549. __WEBPACK_IMPORTED_MODULE_1__glmatrix_mat3__["a" /* default */].fromMat4(m3, m.array);
  16550. // TODO Not like mat4, mat3 in glmatrix seems to be row-based
  16551. __WEBPACK_IMPORTED_MODULE_1__glmatrix_mat3__["a" /* default */].transpose(m3, m3);
  16552. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].fromMat3(this.array, m3);
  16553. this._dirty = true;
  16554. return this;
  16555. };
  16556. })(),
  16557. /**
  16558. * Set to identity quaternion
  16559. * @return {clay.Quaternion}
  16560. */
  16561. identity: function () {
  16562. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].identity(this.array);
  16563. this._dirty = true;
  16564. return this;
  16565. },
  16566. /**
  16567. * Invert self
  16568. * @return {clay.Quaternion}
  16569. */
  16570. invert: function () {
  16571. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].invert(this.array, this.array);
  16572. this._dirty = true;
  16573. return this;
  16574. },
  16575. /**
  16576. * Alias of length
  16577. * @return {number}
  16578. */
  16579. len: function () {
  16580. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].len(this.array);
  16581. },
  16582. /**
  16583. * Calculate the length
  16584. * @return {number}
  16585. */
  16586. length: function () {
  16587. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].length(this.array);
  16588. },
  16589. /**
  16590. * Linear interpolation between a and b
  16591. * @param {clay.Quaternion} a
  16592. * @param {clay.Quaternion} b
  16593. * @param {number} t
  16594. * @return {clay.Quaternion}
  16595. */
  16596. lerp: function (a, b, t) {
  16597. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].lerp(this.array, a.array, b.array, t);
  16598. this._dirty = true;
  16599. return this;
  16600. },
  16601. /**
  16602. * Alias for multiply
  16603. * @param {clay.Quaternion} b
  16604. * @return {clay.Quaternion}
  16605. */
  16606. mul: function (b) {
  16607. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].mul(this.array, this.array, b.array);
  16608. this._dirty = true;
  16609. return this;
  16610. },
  16611. /**
  16612. * Alias for multiplyLeft
  16613. * @param {clay.Quaternion} a
  16614. * @return {clay.Quaternion}
  16615. */
  16616. mulLeft: function (a) {
  16617. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].multiply(this.array, a.array, this.array);
  16618. this._dirty = true;
  16619. return this;
  16620. },
  16621. /**
  16622. * Mutiply self and b
  16623. * @param {clay.Quaternion} b
  16624. * @return {clay.Quaternion}
  16625. */
  16626. multiply: function (b) {
  16627. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].multiply(this.array, this.array, b.array);
  16628. this._dirty = true;
  16629. return this;
  16630. },
  16631. /**
  16632. * Mutiply a and self
  16633. * Quaternion mutiply is not commutative, so the result of mutiplyLeft is different with multiply.
  16634. * @param {clay.Quaternion} a
  16635. * @return {clay.Quaternion}
  16636. */
  16637. multiplyLeft: function (a) {
  16638. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].multiply(this.array, a.array, this.array);
  16639. this._dirty = true;
  16640. return this;
  16641. },
  16642. /**
  16643. * Normalize self
  16644. * @return {clay.Quaternion}
  16645. */
  16646. normalize: function () {
  16647. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].normalize(this.array, this.array);
  16648. this._dirty = true;
  16649. return this;
  16650. },
  16651. /**
  16652. * Rotate self by a given radian about X axis
  16653. * @param {number} rad
  16654. * @return {clay.Quaternion}
  16655. */
  16656. rotateX: function (rad) {
  16657. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].rotateX(this.array, this.array, rad);
  16658. this._dirty = true;
  16659. return this;
  16660. },
  16661. /**
  16662. * Rotate self by a given radian about Y axis
  16663. * @param {number} rad
  16664. * @return {clay.Quaternion}
  16665. */
  16666. rotateY: function (rad) {
  16667. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].rotateY(this.array, this.array, rad);
  16668. this._dirty = true;
  16669. return this;
  16670. },
  16671. /**
  16672. * Rotate self by a given radian about Z axis
  16673. * @param {number} rad
  16674. * @return {clay.Quaternion}
  16675. */
  16676. rotateZ: function (rad) {
  16677. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].rotateZ(this.array, this.array, rad);
  16678. this._dirty = true;
  16679. return this;
  16680. },
  16681. /**
  16682. * Sets self to represent the shortest rotation from Vector3 a to Vector3 b.
  16683. * a and b needs to be normalized
  16684. * @param {clay.Vector3} a
  16685. * @param {clay.Vector3} b
  16686. * @return {clay.Quaternion}
  16687. */
  16688. rotationTo: function (a, b) {
  16689. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].rotationTo(this.array, a.array, b.array);
  16690. this._dirty = true;
  16691. return this;
  16692. },
  16693. /**
  16694. * Sets self with values corresponding to the given axes
  16695. * @param {clay.Vector3} view
  16696. * @param {clay.Vector3} right
  16697. * @param {clay.Vector3} up
  16698. * @return {clay.Quaternion}
  16699. */
  16700. setAxes: function (view, right, up) {
  16701. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].setAxes(this.array, view.array, right.array, up.array);
  16702. this._dirty = true;
  16703. return this;
  16704. },
  16705. /**
  16706. * Sets self with a rotation axis and rotation angle
  16707. * @param {clay.Vector3} axis
  16708. * @param {number} rad
  16709. * @return {clay.Quaternion}
  16710. */
  16711. setAxisAngle: function (axis, rad) {
  16712. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].setAxisAngle(this.array, axis.array, rad);
  16713. this._dirty = true;
  16714. return this;
  16715. },
  16716. /**
  16717. * Perform spherical linear interpolation between a and b
  16718. * @param {clay.Quaternion} a
  16719. * @param {clay.Quaternion} b
  16720. * @param {number} t
  16721. * @return {clay.Quaternion}
  16722. */
  16723. slerp: function (a, b, t) {
  16724. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].slerp(this.array, a.array, b.array, t);
  16725. this._dirty = true;
  16726. return this;
  16727. },
  16728. /**
  16729. * Alias for squaredLength
  16730. * @return {number}
  16731. */
  16732. sqrLen: function () {
  16733. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].sqrLen(this.array);
  16734. },
  16735. /**
  16736. * Squared length of self
  16737. * @return {number}
  16738. */
  16739. squaredLength: function () {
  16740. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].squaredLength(this.array);
  16741. },
  16742. /**
  16743. * Set from euler
  16744. * @param {clay.Vector3} v
  16745. * @param {String} order
  16746. */
  16747. fromEuler: function (v, order) {
  16748. return Quaternion.fromEuler(this, v, order);
  16749. },
  16750. toString: function () {
  16751. return '[' + Array.prototype.join.call(this.array, ',') + ']';
  16752. },
  16753. toArray: function () {
  16754. return Array.prototype.slice.call(this.array);
  16755. }
  16756. };
  16757. var defineProperty = Object.defineProperty;
  16758. // Getter and Setter
  16759. if (defineProperty) {
  16760. var proto = Quaternion.prototype;
  16761. /**
  16762. * @name x
  16763. * @type {number}
  16764. * @memberOf clay.Quaternion
  16765. * @instance
  16766. */
  16767. defineProperty(proto, 'x', {
  16768. get: function () {
  16769. return this.array[0];
  16770. },
  16771. set: function (value) {
  16772. this.array[0] = value;
  16773. this._dirty = true;
  16774. }
  16775. });
  16776. /**
  16777. * @name y
  16778. * @type {number}
  16779. * @memberOf clay.Quaternion
  16780. * @instance
  16781. */
  16782. defineProperty(proto, 'y', {
  16783. get: function () {
  16784. return this.array[1];
  16785. },
  16786. set: function (value) {
  16787. this.array[1] = value;
  16788. this._dirty = true;
  16789. }
  16790. });
  16791. /**
  16792. * @name z
  16793. * @type {number}
  16794. * @memberOf clay.Quaternion
  16795. * @instance
  16796. */
  16797. defineProperty(proto, 'z', {
  16798. get: function () {
  16799. return this.array[2];
  16800. },
  16801. set: function (value) {
  16802. this.array[2] = value;
  16803. this._dirty = true;
  16804. }
  16805. });
  16806. /**
  16807. * @name w
  16808. * @type {number}
  16809. * @memberOf clay.Quaternion
  16810. * @instance
  16811. */
  16812. defineProperty(proto, 'w', {
  16813. get: function () {
  16814. return this.array[3];
  16815. },
  16816. set: function (value) {
  16817. this.array[3] = value;
  16818. this._dirty = true;
  16819. }
  16820. });
  16821. }
  16822. // Supply methods that are not in place
  16823. /**
  16824. * @param {clay.Quaternion} out
  16825. * @param {clay.Quaternion} a
  16826. * @param {clay.Quaternion} b
  16827. * @return {clay.Quaternion}
  16828. */
  16829. Quaternion.add = function (out, a, b) {
  16830. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].add(out.array, a.array, b.array);
  16831. out._dirty = true;
  16832. return out;
  16833. };
  16834. /**
  16835. * @param {clay.Quaternion} out
  16836. * @param {number} x
  16837. * @param {number} y
  16838. * @param {number} z
  16839. * @param {number} w
  16840. * @return {clay.Quaternion}
  16841. */
  16842. Quaternion.set = function (out, x, y, z, w) {
  16843. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].set(out.array, x, y, z, w);
  16844. out._dirty = true;
  16845. };
  16846. /**
  16847. * @param {clay.Quaternion} out
  16848. * @param {clay.Quaternion} b
  16849. * @return {clay.Quaternion}
  16850. */
  16851. Quaternion.copy = function (out, b) {
  16852. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].copy(out.array, b.array);
  16853. out._dirty = true;
  16854. return out;
  16855. };
  16856. /**
  16857. * @param {clay.Quaternion} out
  16858. * @param {clay.Quaternion} a
  16859. * @return {clay.Quaternion}
  16860. */
  16861. Quaternion.calculateW = function (out, a) {
  16862. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].calculateW(out.array, a.array);
  16863. out._dirty = true;
  16864. return out;
  16865. };
  16866. /**
  16867. * @param {clay.Quaternion} out
  16868. * @param {clay.Quaternion} a
  16869. * @return {clay.Quaternion}
  16870. */
  16871. Quaternion.conjugate = function (out, a) {
  16872. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].conjugate(out.array, a.array);
  16873. out._dirty = true;
  16874. return out;
  16875. };
  16876. /**
  16877. * @param {clay.Quaternion} out
  16878. * @return {clay.Quaternion}
  16879. */
  16880. Quaternion.identity = function (out) {
  16881. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].identity(out.array);
  16882. out._dirty = true;
  16883. return out;
  16884. };
  16885. /**
  16886. * @param {clay.Quaternion} out
  16887. * @param {clay.Quaternion} a
  16888. * @return {clay.Quaternion}
  16889. */
  16890. Quaternion.invert = function (out, a) {
  16891. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].invert(out.array, a.array);
  16892. out._dirty = true;
  16893. return out;
  16894. };
  16895. /**
  16896. * @param {clay.Quaternion} a
  16897. * @param {clay.Quaternion} b
  16898. * @return {number}
  16899. */
  16900. Quaternion.dot = function (a, b) {
  16901. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].dot(a.array, b.array);
  16902. };
  16903. /**
  16904. * @param {clay.Quaternion} a
  16905. * @return {number}
  16906. */
  16907. Quaternion.len = function (a) {
  16908. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].length(a.array);
  16909. };
  16910. // Quaternion.length = Quaternion.len;
  16911. /**
  16912. * @param {clay.Quaternion} out
  16913. * @param {clay.Quaternion} a
  16914. * @param {clay.Quaternion} b
  16915. * @param {number} t
  16916. * @return {clay.Quaternion}
  16917. */
  16918. Quaternion.lerp = function (out, a, b, t) {
  16919. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].lerp(out.array, a.array, b.array, t);
  16920. out._dirty = true;
  16921. return out;
  16922. };
  16923. /**
  16924. * @param {clay.Quaternion} out
  16925. * @param {clay.Quaternion} a
  16926. * @param {clay.Quaternion} b
  16927. * @param {number} t
  16928. * @return {clay.Quaternion}
  16929. */
  16930. Quaternion.slerp = function (out, a, b, t) {
  16931. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].slerp(out.array, a.array, b.array, t);
  16932. out._dirty = true;
  16933. return out;
  16934. };
  16935. /**
  16936. * @param {clay.Quaternion} out
  16937. * @param {clay.Quaternion} a
  16938. * @param {clay.Quaternion} b
  16939. * @return {clay.Quaternion}
  16940. */
  16941. Quaternion.mul = function (out, a, b) {
  16942. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].multiply(out.array, a.array, b.array);
  16943. out._dirty = true;
  16944. return out;
  16945. };
  16946. /**
  16947. * @function
  16948. * @param {clay.Quaternion} out
  16949. * @param {clay.Quaternion} a
  16950. * @param {clay.Quaternion} b
  16951. * @return {clay.Quaternion}
  16952. */
  16953. Quaternion.multiply = Quaternion.mul;
  16954. /**
  16955. * @param {clay.Quaternion} out
  16956. * @param {clay.Quaternion} a
  16957. * @param {number} rad
  16958. * @return {clay.Quaternion}
  16959. */
  16960. Quaternion.rotateX = function (out, a, rad) {
  16961. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].rotateX(out.array, a.array, rad);
  16962. out._dirty = true;
  16963. return out;
  16964. };
  16965. /**
  16966. * @param {clay.Quaternion} out
  16967. * @param {clay.Quaternion} a
  16968. * @param {number} rad
  16969. * @return {clay.Quaternion}
  16970. */
  16971. Quaternion.rotateY = function (out, a, rad) {
  16972. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].rotateY(out.array, a.array, rad);
  16973. out._dirty = true;
  16974. return out;
  16975. };
  16976. /**
  16977. * @param {clay.Quaternion} out
  16978. * @param {clay.Quaternion} a
  16979. * @param {number} rad
  16980. * @return {clay.Quaternion}
  16981. */
  16982. Quaternion.rotateZ = function (out, a, rad) {
  16983. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].rotateZ(out.array, a.array, rad);
  16984. out._dirty = true;
  16985. return out;
  16986. };
  16987. /**
  16988. * @param {clay.Quaternion} out
  16989. * @param {clay.Vector3} axis
  16990. * @param {number} rad
  16991. * @return {clay.Quaternion}
  16992. */
  16993. Quaternion.setAxisAngle = function (out, axis, rad) {
  16994. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].setAxisAngle(out.array, axis.array, rad);
  16995. out._dirty = true;
  16996. return out;
  16997. };
  16998. /**
  16999. * @param {clay.Quaternion} out
  17000. * @param {clay.Quaternion} a
  17001. * @return {clay.Quaternion}
  17002. */
  17003. Quaternion.normalize = function (out, a) {
  17004. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].normalize(out.array, a.array);
  17005. out._dirty = true;
  17006. return out;
  17007. };
  17008. /**
  17009. * @param {clay.Quaternion} a
  17010. * @return {number}
  17011. */
  17012. Quaternion.sqrLen = function (a) {
  17013. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].sqrLen(a.array);
  17014. };
  17015. /**
  17016. * @function
  17017. * @param {clay.Quaternion} a
  17018. * @return {number}
  17019. */
  17020. Quaternion.squaredLength = Quaternion.sqrLen;
  17021. /**
  17022. * @param {clay.Quaternion} out
  17023. * @param {clay.Matrix3} m
  17024. * @return {clay.Quaternion}
  17025. */
  17026. Quaternion.fromMat3 = function (out, m) {
  17027. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].fromMat3(out.array, m.array);
  17028. out._dirty = true;
  17029. return out;
  17030. };
  17031. /**
  17032. * @param {clay.Quaternion} out
  17033. * @param {clay.Vector3} view
  17034. * @param {clay.Vector3} right
  17035. * @param {clay.Vector3} up
  17036. * @return {clay.Quaternion}
  17037. */
  17038. Quaternion.setAxes = function (out, view, right, up) {
  17039. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].setAxes(out.array, view.array, right.array, up.array);
  17040. out._dirty = true;
  17041. return out;
  17042. };
  17043. /**
  17044. * @param {clay.Quaternion} out
  17045. * @param {clay.Vector3} a
  17046. * @param {clay.Vector3} b
  17047. * @return {clay.Quaternion}
  17048. */
  17049. Quaternion.rotationTo = function (out, a, b) {
  17050. __WEBPACK_IMPORTED_MODULE_0__glmatrix_quat__["a" /* default */].rotationTo(out.array, a.array, b.array);
  17051. out._dirty = true;
  17052. return out;
  17053. };
  17054. /**
  17055. * Set quaternion from euler
  17056. * @param {clay.Quaternion} out
  17057. * @param {clay.Vector3} v
  17058. * @param {String} order
  17059. */
  17060. Quaternion.fromEuler = function (out, v, order) {
  17061. out._dirty = true;
  17062. v = v.array;
  17063. var target = out.array;
  17064. var c1 = Math.cos(v[0] / 2);
  17065. var c2 = Math.cos(v[1] / 2);
  17066. var c3 = Math.cos(v[2] / 2);
  17067. var s1 = Math.sin(v[0] / 2);
  17068. var s2 = Math.sin(v[1] / 2);
  17069. var s3 = Math.sin(v[2] / 2);
  17070. var order = (order || 'XYZ').toUpperCase();
  17071. // http://www.mathworks.com/matlabcentral/fileexchange/
  17072. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  17073. // content/SpinCalc.m
  17074. switch (order) {
  17075. case 'XYZ':
  17076. target[0] = s1 * c2 * c3 + c1 * s2 * s3;
  17077. target[1] = c1 * s2 * c3 - s1 * c2 * s3;
  17078. target[2] = c1 * c2 * s3 + s1 * s2 * c3;
  17079. target[3] = c1 * c2 * c3 - s1 * s2 * s3;
  17080. break;
  17081. case 'YXZ':
  17082. target[0] = s1 * c2 * c3 + c1 * s2 * s3;
  17083. target[1] = c1 * s2 * c3 - s1 * c2 * s3;
  17084. target[2] = c1 * c2 * s3 - s1 * s2 * c3;
  17085. target[3] = c1 * c2 * c3 + s1 * s2 * s3;
  17086. break;
  17087. case 'ZXY':
  17088. target[0] = s1 * c2 * c3 - c1 * s2 * s3;
  17089. target[1] = c1 * s2 * c3 + s1 * c2 * s3;
  17090. target[2] = c1 * c2 * s3 + s1 * s2 * c3;
  17091. target[3] = c1 * c2 * c3 - s1 * s2 * s3;
  17092. break;
  17093. case 'ZYX':
  17094. target[0] = s1 * c2 * c3 - c1 * s2 * s3;
  17095. target[1] = c1 * s2 * c3 + s1 * c2 * s3;
  17096. target[2] = c1 * c2 * s3 - s1 * s2 * c3;
  17097. target[3] = c1 * c2 * c3 + s1 * s2 * s3;
  17098. break;
  17099. case 'YZX':
  17100. target[0] = s1 * c2 * c3 + c1 * s2 * s3;
  17101. target[1] = c1 * s2 * c3 + s1 * c2 * s3;
  17102. target[2] = c1 * c2 * s3 - s1 * s2 * c3;
  17103. target[3] = c1 * c2 * c3 - s1 * s2 * s3;
  17104. break;
  17105. case 'XZY':
  17106. target[0] = s1 * c2 * c3 - c1 * s2 * s3;
  17107. target[1] = c1 * s2 * c3 - s1 * c2 * s3;
  17108. target[2] = c1 * c2 * s3 + s1 * s2 * c3;
  17109. target[3] = c1 * c2 * c3 + s1 * s2 * s3;
  17110. break;
  17111. }
  17112. };
  17113. /* harmony default export */ __webpack_exports__["a"] = (Quaternion);
  17114. /***/
  17115. }),
  17116. /* 57 */
  17117. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  17118. "use strict";
  17119. var DIRTY_PREFIX = '__dt__';
  17120. var Cache = function () {
  17121. this._contextId = 0;
  17122. this._caches = [];
  17123. this._context = {};
  17124. };
  17125. Cache.prototype = {
  17126. use: function (contextId, documentSchema) {
  17127. var caches = this._caches;
  17128. if (!caches[contextId]) {
  17129. caches[contextId] = {};
  17130. if (documentSchema) {
  17131. caches[contextId] = documentSchema();
  17132. }
  17133. }
  17134. this._contextId = contextId;
  17135. this._context = caches[contextId];
  17136. },
  17137. put: function (key, value) {
  17138. this._context[key] = value;
  17139. },
  17140. get: function (key) {
  17141. return this._context[key];
  17142. },
  17143. dirty: function (field) {
  17144. field = field || '';
  17145. var key = DIRTY_PREFIX + field;
  17146. this.put(key, true);
  17147. },
  17148. dirtyAll: function (field) {
  17149. field = field || '';
  17150. var key = DIRTY_PREFIX + field;
  17151. var caches = this._caches;
  17152. for (var i = 0; i < caches.length; i++) {
  17153. if (caches[i]) {
  17154. caches[i][key] = true;
  17155. }
  17156. }
  17157. },
  17158. fresh: function (field) {
  17159. field = field || '';
  17160. var key = DIRTY_PREFIX + field;
  17161. this.put(key, false);
  17162. },
  17163. freshAll: function (field) {
  17164. field = field || '';
  17165. var key = DIRTY_PREFIX + field;
  17166. var caches = this._caches;
  17167. for (var i = 0; i < caches.length; i++) {
  17168. if (caches[i]) {
  17169. caches[i][key] = false;
  17170. }
  17171. }
  17172. },
  17173. isDirty: function (field) {
  17174. field = field || '';
  17175. var key = DIRTY_PREFIX + field;
  17176. var context = this._context;
  17177. return !context.hasOwnProperty(key)
  17178. || context[key] === true;
  17179. },
  17180. deleteContext: function (contextId) {
  17181. delete this._caches[contextId];
  17182. this._context = {};
  17183. },
  17184. delete: function (key) {
  17185. delete this._context[key];
  17186. },
  17187. clearAll: function () {
  17188. this._caches = {};
  17189. },
  17190. getContext: function () {
  17191. return this._context;
  17192. },
  17193. eachContext: function (cb, context) {
  17194. var keys = Object.keys(this._caches);
  17195. keys.forEach(function (key) {
  17196. cb && cb.call(context, key);
  17197. });
  17198. },
  17199. miss: function (key) {
  17200. return !this._context.hasOwnProperty(key);
  17201. }
  17202. };
  17203. Cache.prototype.constructor = Cache;
  17204. /* harmony default export */ __webpack_exports__["a"] = (Cache);
  17205. /***/
  17206. }),
  17207. /* 58 */
  17208. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  17209. "use strict";
  17210. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Node__ = __webpack_require__(35);
  17211. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__math_Matrix4__ = __webpack_require__(9);
  17212. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__math_Frustum__ = __webpack_require__(59);
  17213. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__math_Ray__ = __webpack_require__(54);
  17214. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__glmatrix_vec4__ = __webpack_require__(33);
  17215. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__glmatrix_vec3__ = __webpack_require__(12);
  17216. /**
  17217. * @constructor clay.Camera
  17218. * @extends clay.Node
  17219. */
  17220. var Camera = __WEBPACK_IMPORTED_MODULE_0__Node__["a" /* default */].extend(function () {
  17221. return /** @lends clay.Camera# */ {
  17222. /**
  17223. * Camera projection matrix
  17224. * @type {clay.Matrix4}
  17225. */
  17226. projectionMatrix: new __WEBPACK_IMPORTED_MODULE_1__math_Matrix4__["a" /* default */](),
  17227. /**
  17228. * Inverse of camera projection matrix
  17229. * @type {clay.Matrix4}
  17230. */
  17231. invProjectionMatrix: new __WEBPACK_IMPORTED_MODULE_1__math_Matrix4__["a" /* default */](),
  17232. /**
  17233. * View matrix, equal to inverse of camera's world matrix
  17234. * @type {clay.Matrix4}
  17235. */
  17236. viewMatrix: new __WEBPACK_IMPORTED_MODULE_1__math_Matrix4__["a" /* default */](),
  17237. /**
  17238. * Camera frustum in view space
  17239. * @type {clay.Frustum}
  17240. */
  17241. frustum: new __WEBPACK_IMPORTED_MODULE_2__math_Frustum__["a" /* default */]()
  17242. };
  17243. }, function () {
  17244. this.update(true);
  17245. },
  17246. /** @lends clay.Camera.prototype */
  17247. {
  17248. update: function (force) {
  17249. __WEBPACK_IMPORTED_MODULE_0__Node__["a" /* default */].prototype.update.call(this, force);
  17250. __WEBPACK_IMPORTED_MODULE_1__math_Matrix4__["a" /* default */].invert(this.viewMatrix, this.worldTransform);
  17251. this.updateProjectionMatrix();
  17252. __WEBPACK_IMPORTED_MODULE_1__math_Matrix4__["a" /* default */].invert(this.invProjectionMatrix, this.projectionMatrix);
  17253. this.frustum.setFromProjection(this.projectionMatrix);
  17254. },
  17255. /**
  17256. * Set camera view matrix
  17257. */
  17258. setViewMatrix: function (viewMatrix) {
  17259. __WEBPACK_IMPORTED_MODULE_1__math_Matrix4__["a" /* default */].copy(this.viewMatrix, viewMatrix);
  17260. __WEBPACK_IMPORTED_MODULE_1__math_Matrix4__["a" /* default */].invert(this.worldTransform, viewMatrix);
  17261. this.decomposeWorldTransform();
  17262. },
  17263. /**
  17264. * Decompose camera projection matrix
  17265. */
  17266. decomposeProjectionMatrix: function () { },
  17267. /**
  17268. * Set camera projection matrix
  17269. * @param {clay.Matrix4} projectionMatrix
  17270. */
  17271. setProjectionMatrix: function (projectionMatrix) {
  17272. __WEBPACK_IMPORTED_MODULE_1__math_Matrix4__["a" /* default */].copy(this.projectionMatrix, projectionMatrix);
  17273. __WEBPACK_IMPORTED_MODULE_1__math_Matrix4__["a" /* default */].invert(this.invProjectionMatrix, projectionMatrix);
  17274. this.decomposeProjectionMatrix();
  17275. },
  17276. /**
  17277. * Update projection matrix, called after update
  17278. */
  17279. updateProjectionMatrix: function () { },
  17280. /**
  17281. * Cast a picking ray from camera near plane to far plane
  17282. * @function
  17283. * @param {clay.Vector2} ndc
  17284. * @param {clay.Ray} [out]
  17285. * @return {clay.Ray}
  17286. */
  17287. castRay: (function () {
  17288. var v4 = __WEBPACK_IMPORTED_MODULE_4__glmatrix_vec4__["a" /* default */].create();
  17289. return function (ndc, out) {
  17290. var ray = out !== undefined ? out : new __WEBPACK_IMPORTED_MODULE_3__math_Ray__["a" /* default */]();
  17291. var x = ndc.array[0];
  17292. var y = ndc.array[1];
  17293. __WEBPACK_IMPORTED_MODULE_4__glmatrix_vec4__["a" /* default */].set(v4, x, y, -1, 1);
  17294. __WEBPACK_IMPORTED_MODULE_4__glmatrix_vec4__["a" /* default */].transformMat4(v4, v4, this.invProjectionMatrix.array);
  17295. __WEBPACK_IMPORTED_MODULE_4__glmatrix_vec4__["a" /* default */].transformMat4(v4, v4, this.worldTransform.array);
  17296. __WEBPACK_IMPORTED_MODULE_5__glmatrix_vec3__["a" /* default */].scale(ray.origin.array, v4, 1 / v4[3]);
  17297. __WEBPACK_IMPORTED_MODULE_4__glmatrix_vec4__["a" /* default */].set(v4, x, y, 1, 1);
  17298. __WEBPACK_IMPORTED_MODULE_4__glmatrix_vec4__["a" /* default */].transformMat4(v4, v4, this.invProjectionMatrix.array);
  17299. __WEBPACK_IMPORTED_MODULE_4__glmatrix_vec4__["a" /* default */].transformMat4(v4, v4, this.worldTransform.array);
  17300. __WEBPACK_IMPORTED_MODULE_5__glmatrix_vec3__["a" /* default */].scale(v4, v4, 1 / v4[3]);
  17301. __WEBPACK_IMPORTED_MODULE_5__glmatrix_vec3__["a" /* default */].sub(ray.direction.array, v4, ray.origin.array);
  17302. __WEBPACK_IMPORTED_MODULE_5__glmatrix_vec3__["a" /* default */].normalize(ray.direction.array, ray.direction.array);
  17303. ray.direction._dirty = true;
  17304. ray.origin._dirty = true;
  17305. return ray;
  17306. };
  17307. })(),
  17308. /**
  17309. * @function
  17310. * @name clone
  17311. * @return {clay.Camera}
  17312. * @memberOf clay.Camera.prototype
  17313. */
  17314. });
  17315. /* harmony default export */ __webpack_exports__["a"] = (Camera);
  17316. /***/
  17317. }),
  17318. /* 59 */
  17319. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  17320. "use strict";
  17321. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__BoundingBox__ = __webpack_require__(18);
  17322. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__Plane__ = __webpack_require__(74);
  17323. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__ = __webpack_require__(12);
  17324. var vec3Set = __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].set;
  17325. var vec3Copy = __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].copy;
  17326. var vec3TranformMat4 = __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].transformMat4;
  17327. var mathMin = Math.min;
  17328. var mathMax = Math.max;
  17329. /**
  17330. * @constructor
  17331. * @alias clay.Frustum
  17332. */
  17333. var Frustum = function () {
  17334. /**
  17335. * Eight planes to enclose the frustum
  17336. * @type {clay.Plane[]}
  17337. */
  17338. this.planes = [];
  17339. for (var i = 0; i < 6; i++) {
  17340. this.planes.push(new __WEBPACK_IMPORTED_MODULE_1__Plane__["a" /* default */]());
  17341. }
  17342. /**
  17343. * Bounding box of frustum
  17344. * @type {clay.BoundingBox}
  17345. */
  17346. this.boundingBox = new __WEBPACK_IMPORTED_MODULE_0__BoundingBox__["a" /* default */]();
  17347. /**
  17348. * Eight vertices of frustum
  17349. * @type {Float32Array[]}
  17350. */
  17351. this.vertices = [];
  17352. for (var i = 0; i < 8; i++) {
  17353. this.vertices[i] = __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].fromValues(0, 0, 0);
  17354. }
  17355. };
  17356. Frustum.prototype = {
  17357. // http://web.archive.org/web/20120531231005/http://crazyjoke.free.fr/doc/3D/plane%20extraction.pdf
  17358. /**
  17359. * Set frustum from a projection matrix
  17360. * @param {clay.Matrix4} projectionMatrix
  17361. */
  17362. setFromProjection: function (projectionMatrix) {
  17363. var planes = this.planes;
  17364. var m = projectionMatrix.array;
  17365. var m0 = m[0], m1 = m[1], m2 = m[2], m3 = m[3];
  17366. var m4 = m[4], m5 = m[5], m6 = m[6], m7 = m[7];
  17367. var m8 = m[8], m9 = m[9], m10 = m[10], m11 = m[11];
  17368. var m12 = m[12], m13 = m[13], m14 = m[14], m15 = m[15];
  17369. // Update planes
  17370. vec3Set(planes[0].normal.array, m3 - m0, m7 - m4, m11 - m8);
  17371. planes[0].distance = -(m15 - m12);
  17372. planes[0].normalize();
  17373. vec3Set(planes[1].normal.array, m3 + m0, m7 + m4, m11 + m8);
  17374. planes[1].distance = -(m15 + m12);
  17375. planes[1].normalize();
  17376. vec3Set(planes[2].normal.array, m3 + m1, m7 + m5, m11 + m9);
  17377. planes[2].distance = -(m15 + m13);
  17378. planes[2].normalize();
  17379. vec3Set(planes[3].normal.array, m3 - m1, m7 - m5, m11 - m9);
  17380. planes[3].distance = -(m15 - m13);
  17381. planes[3].normalize();
  17382. vec3Set(planes[4].normal.array, m3 - m2, m7 - m6, m11 - m10);
  17383. planes[4].distance = -(m15 - m14);
  17384. planes[4].normalize();
  17385. vec3Set(planes[5].normal.array, m3 + m2, m7 + m6, m11 + m10);
  17386. planes[5].distance = -(m15 + m14);
  17387. planes[5].normalize();
  17388. // Perspective projection
  17389. var boundingBox = this.boundingBox;
  17390. var vertices = this.vertices;
  17391. if (m15 === 0) {
  17392. var aspect = m5 / m0;
  17393. var zNear = -m14 / (m10 - 1);
  17394. var zFar = -m14 / (m10 + 1);
  17395. var farY = -zFar / m5;
  17396. var nearY = -zNear / m5;
  17397. // Update bounding box
  17398. boundingBox.min.set(-farY * aspect, -farY, zFar);
  17399. boundingBox.max.set(farY * aspect, farY, zNear);
  17400. // update vertices
  17401. //--- min z
  17402. // min x
  17403. vec3Set(vertices[0], -farY * aspect, -farY, zFar);
  17404. vec3Set(vertices[1], -farY * aspect, farY, zFar);
  17405. // max x
  17406. vec3Set(vertices[2], farY * aspect, -farY, zFar);
  17407. vec3Set(vertices[3], farY * aspect, farY, zFar);
  17408. //-- max z
  17409. vec3Set(vertices[4], -nearY * aspect, -nearY, zNear);
  17410. vec3Set(vertices[5], -nearY * aspect, nearY, zNear);
  17411. vec3Set(vertices[6], nearY * aspect, -nearY, zNear);
  17412. vec3Set(vertices[7], nearY * aspect, nearY, zNear);
  17413. }
  17414. else { // Orthographic projection
  17415. var left = (-1 - m12) / m0;
  17416. var right = (1 - m12) / m0;
  17417. var top = (1 - m13) / m5;
  17418. var bottom = (-1 - m13) / m5;
  17419. var near = (-1 - m14) / m10;
  17420. var far = (1 - m14) / m10;
  17421. boundingBox.min.set(Math.min(left, right), Math.min(bottom, top), Math.min(far, near));
  17422. boundingBox.max.set(Math.max(right, left), Math.max(top, bottom), Math.max(near, far));
  17423. var min = boundingBox.min.array;
  17424. var max = boundingBox.max.array;
  17425. //--- min z
  17426. // min x
  17427. vec3Set(vertices[0], min[0], min[1], min[2]);
  17428. vec3Set(vertices[1], min[0], max[1], min[2]);
  17429. // max x
  17430. vec3Set(vertices[2], max[0], min[1], min[2]);
  17431. vec3Set(vertices[3], max[0], max[1], min[2]);
  17432. //-- max z
  17433. vec3Set(vertices[4], min[0], min[1], max[2]);
  17434. vec3Set(vertices[5], min[0], max[1], max[2]);
  17435. vec3Set(vertices[6], max[0], min[1], max[2]);
  17436. vec3Set(vertices[7], max[0], max[1], max[2]);
  17437. }
  17438. },
  17439. /**
  17440. * Apply a affine transform matrix and set to the given bounding box
  17441. * @function
  17442. * @param {clay.BoundingBox}
  17443. * @param {clay.Matrix4}
  17444. * @return {clay.BoundingBox}
  17445. */
  17446. getTransformedBoundingBox: (function () {
  17447. var tmpVec3 = __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].create();
  17448. return function (bbox, matrix) {
  17449. var vertices = this.vertices;
  17450. var m4 = matrix.array;
  17451. var min = bbox.min;
  17452. var max = bbox.max;
  17453. var minArr = min.array;
  17454. var maxArr = max.array;
  17455. var v = vertices[0];
  17456. vec3TranformMat4(tmpVec3, v, m4);
  17457. vec3Copy(minArr, tmpVec3);
  17458. vec3Copy(maxArr, tmpVec3);
  17459. for (var i = 1; i < 8; i++) {
  17460. v = vertices[i];
  17461. vec3TranformMat4(tmpVec3, v, m4);
  17462. minArr[0] = mathMin(tmpVec3[0], minArr[0]);
  17463. minArr[1] = mathMin(tmpVec3[1], minArr[1]);
  17464. minArr[2] = mathMin(tmpVec3[2], minArr[2]);
  17465. maxArr[0] = mathMax(tmpVec3[0], maxArr[0]);
  17466. maxArr[1] = mathMax(tmpVec3[1], maxArr[1]);
  17467. maxArr[2] = mathMax(tmpVec3[2], maxArr[2]);
  17468. }
  17469. min._dirty = true;
  17470. max._dirty = true;
  17471. return bbox;
  17472. };
  17473. })()
  17474. };
  17475. /* harmony default export */ __webpack_exports__["a"] = (Frustum);
  17476. /***/
  17477. }),
  17478. /* 60 */
  17479. /***/ (function (module, exports) {
  17480. // Simple LRU cache use doubly linked list
  17481. // @module zrender/core/LRU
  17482. /**
  17483. * Simple double linked list. Compared with array, it has O(1) remove operation.
  17484. * @constructor
  17485. */
  17486. var LinkedList = function () {
  17487. /**
  17488. * @type {module:zrender/core/LRU~Entry}
  17489. */
  17490. this.head = null;
  17491. /**
  17492. * @type {module:zrender/core/LRU~Entry}
  17493. */
  17494. this.tail = null;
  17495. this._len = 0;
  17496. };
  17497. var linkedListProto = LinkedList.prototype;
  17498. /**
  17499. * Insert a new value at the tail
  17500. * @param {} val
  17501. * @return {module:zrender/core/LRU~Entry}
  17502. */
  17503. linkedListProto.insert = function (val) {
  17504. var entry = new Entry(val);
  17505. this.insertEntry(entry);
  17506. return entry;
  17507. };
  17508. /**
  17509. * Insert an entry at the tail
  17510. * @param {module:zrender/core/LRU~Entry} entry
  17511. */
  17512. linkedListProto.insertEntry = function (entry) {
  17513. if (!this.head) {
  17514. this.head = this.tail = entry;
  17515. } else {
  17516. this.tail.next = entry;
  17517. entry.prev = this.tail;
  17518. entry.next = null;
  17519. this.tail = entry;
  17520. }
  17521. this._len++;
  17522. };
  17523. /**
  17524. * Remove entry.
  17525. * @param {module:zrender/core/LRU~Entry} entry
  17526. */
  17527. linkedListProto.remove = function (entry) {
  17528. var prev = entry.prev;
  17529. var next = entry.next;
  17530. if (prev) {
  17531. prev.next = next;
  17532. } else {
  17533. // Is head
  17534. this.head = next;
  17535. }
  17536. if (next) {
  17537. next.prev = prev;
  17538. } else {
  17539. // Is tail
  17540. this.tail = prev;
  17541. }
  17542. entry.next = entry.prev = null;
  17543. this._len--;
  17544. };
  17545. /**
  17546. * @return {number}
  17547. */
  17548. linkedListProto.len = function () {
  17549. return this._len;
  17550. };
  17551. /**
  17552. * Clear list
  17553. */
  17554. linkedListProto.clear = function () {
  17555. this.head = this.tail = null;
  17556. this._len = 0;
  17557. };
  17558. /**
  17559. * @constructor
  17560. * @param {} val
  17561. */
  17562. var Entry = function (val) {
  17563. /**
  17564. * @type {}
  17565. */
  17566. this.value = val;
  17567. /**
  17568. * @type {module:zrender/core/LRU~Entry}
  17569. */
  17570. this.next;
  17571. /**
  17572. * @type {module:zrender/core/LRU~Entry}
  17573. */
  17574. this.prev;
  17575. };
  17576. /**
  17577. * LRU Cache
  17578. * @constructor
  17579. * @alias module:zrender/core/LRU
  17580. */
  17581. var LRU = function (maxSize) {
  17582. this._list = new LinkedList();
  17583. this._map = {};
  17584. this._maxSize = maxSize || 10;
  17585. this._lastRemovedEntry = null;
  17586. };
  17587. var LRUProto = LRU.prototype;
  17588. /**
  17589. * @param {string} key
  17590. * @param {} value
  17591. * @return {} Removed value
  17592. */
  17593. LRUProto.put = function (key, value) {
  17594. var list = this._list;
  17595. var map = this._map;
  17596. var removed = null;
  17597. if (map[key] == null) {
  17598. var len = list.len(); // Reuse last removed entry
  17599. var entry = this._lastRemovedEntry;
  17600. if (len >= this._maxSize && len > 0) {
  17601. // Remove the least recently used
  17602. var leastUsedEntry = list.head;
  17603. list.remove(leastUsedEntry);
  17604. delete map[leastUsedEntry.key];
  17605. removed = leastUsedEntry.value;
  17606. this._lastRemovedEntry = leastUsedEntry;
  17607. }
  17608. if (entry) {
  17609. entry.value = value;
  17610. } else {
  17611. entry = new Entry(value);
  17612. }
  17613. entry.key = key;
  17614. list.insertEntry(entry);
  17615. map[key] = entry;
  17616. }
  17617. return removed;
  17618. };
  17619. /**
  17620. * @param {string} key
  17621. * @return {}
  17622. */
  17623. LRUProto.get = function (key) {
  17624. var entry = this._map[key];
  17625. var list = this._list;
  17626. if (entry != null) {
  17627. // Put the latest used entry in the tail
  17628. if (entry !== list.tail) {
  17629. list.remove(entry);
  17630. list.insertEntry(entry);
  17631. }
  17632. return entry.value;
  17633. }
  17634. };
  17635. /**
  17636. * Clear the cache
  17637. */
  17638. LRUProto.clear = function () {
  17639. this._list.clear();
  17640. this._map = {};
  17641. };
  17642. var _default = LRU;
  17643. module.exports = _default;
  17644. /***/
  17645. }),
  17646. /* 61 */
  17647. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  17648. "use strict";
  17649. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Texture2D__ = __webpack_require__(5);
  17650. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__TextureCube__ = __webpack_require__(27);
  17651. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__core_vendor__ = __webpack_require__(14);
  17652. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__prePass_EnvironmentMap__ = __webpack_require__(62);
  17653. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__plugin_Skydome__ = __webpack_require__(75);
  17654. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__Scene__ = __webpack_require__(36);
  17655. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__dds__ = __webpack_require__(122);
  17656. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__hdr__ = __webpack_require__(123);
  17657. /**
  17658. * @alias clay.util.texture
  17659. */
  17660. var textureUtil = {
  17661. /**
  17662. * @param {string|object} path
  17663. * @param {object} [option]
  17664. * @param {Function} [onsuccess]
  17665. * @param {Function} [onerror]
  17666. * @return {clay.Texture}
  17667. */
  17668. loadTexture: function (path, option, onsuccess, onerror) {
  17669. var texture;
  17670. if (typeof (option) === 'function') {
  17671. onsuccess = option;
  17672. onerror = onsuccess;
  17673. option = {};
  17674. }
  17675. else {
  17676. option = option || {};
  17677. }
  17678. if (typeof (path) === 'string') {
  17679. if (path.match(/.hdr$/) || option.fileType === 'hdr') {
  17680. texture = new __WEBPACK_IMPORTED_MODULE_0__Texture2D__["a" /* default */]({
  17681. width: 0,
  17682. height: 0,
  17683. sRGB: false
  17684. });
  17685. textureUtil._fetchTexture(
  17686. path,
  17687. function (data) {
  17688. __WEBPACK_IMPORTED_MODULE_7__hdr__["a" /* default */].parseRGBE(data, texture, option.exposure);
  17689. texture.dirty();
  17690. onsuccess && onsuccess(texture);
  17691. },
  17692. onerror
  17693. );
  17694. return texture;
  17695. }
  17696. else if (path.match(/.dds$/) || option.fileType === 'dds') {
  17697. texture = new __WEBPACK_IMPORTED_MODULE_0__Texture2D__["a" /* default */]({
  17698. width: 0,
  17699. height: 0
  17700. });
  17701. textureUtil._fetchTexture(
  17702. path,
  17703. function (data) {
  17704. __WEBPACK_IMPORTED_MODULE_6__dds__["a" /* default */].parse(data, texture);
  17705. texture.dirty();
  17706. onsuccess && onsuccess(texture);
  17707. },
  17708. onerror
  17709. );
  17710. }
  17711. else {
  17712. texture = new __WEBPACK_IMPORTED_MODULE_0__Texture2D__["a" /* default */]();
  17713. texture.load(path);
  17714. texture.success(onsuccess);
  17715. texture.error(onerror);
  17716. }
  17717. }
  17718. else if (typeof path === 'object' && typeof (path.px) !== 'undefined') {
  17719. texture = new __WEBPACK_IMPORTED_MODULE_1__TextureCube__["a" /* default */]();
  17720. texture.load(path);
  17721. texture.success(onsuccess);
  17722. texture.error(onerror);
  17723. }
  17724. return texture;
  17725. },
  17726. /**
  17727. * Load a panorama texture and render it to a cube map
  17728. * @param {clay.Renderer} renderer
  17729. * @param {string} path
  17730. * @param {clay.TextureCube} cubeMap
  17731. * @param {object} [option]
  17732. * @param {boolean} [option.encodeRGBM]
  17733. * @param {number} [option.exposure]
  17734. * @param {Function} [onsuccess]
  17735. * @param {Function} [onerror]
  17736. */
  17737. loadPanorama: function (renderer, path, cubeMap, option, onsuccess, onerror) {
  17738. var self = this;
  17739. if (typeof (option) === 'function') {
  17740. onsuccess = option;
  17741. onerror = onsuccess;
  17742. option = {};
  17743. }
  17744. else {
  17745. option = option || {};
  17746. }
  17747. textureUtil.loadTexture(path, option, function (texture) {
  17748. // PENDING
  17749. texture.flipY = option.flipY || false;
  17750. self.panoramaToCubeMap(renderer, texture, cubeMap, option);
  17751. texture.dispose(renderer);
  17752. onsuccess && onsuccess(cubeMap);
  17753. }, onerror);
  17754. },
  17755. /**
  17756. * Render a panorama texture to a cube map
  17757. * @param {clay.Renderer} renderer
  17758. * @param {clay.Texture2D} panoramaMap
  17759. * @param {clay.TextureCube} cubeMap
  17760. * @param {Object} option
  17761. * @param {boolean} [option.encodeRGBM]
  17762. */
  17763. panoramaToCubeMap: function (renderer, panoramaMap, cubeMap, option) {
  17764. var environmentMapPass = new __WEBPACK_IMPORTED_MODULE_3__prePass_EnvironmentMap__["a" /* default */]();
  17765. var skydome = new __WEBPACK_IMPORTED_MODULE_4__plugin_Skydome__["a" /* default */]({
  17766. scene: new __WEBPACK_IMPORTED_MODULE_5__Scene__["a" /* default */]()
  17767. });
  17768. skydome.setEnvironmentMap(panoramaMap);
  17769. option = option || {};
  17770. if (option.encodeRGBM) {
  17771. skydome.material.define('fragment', 'RGBM_ENCODE');
  17772. }
  17773. // Share sRGB
  17774. cubeMap.sRGB = panoramaMap.sRGB;
  17775. environmentMapPass.texture = cubeMap;
  17776. environmentMapPass.render(renderer, skydome.scene);
  17777. environmentMapPass.texture = null;
  17778. environmentMapPass.dispose(renderer);
  17779. return cubeMap;
  17780. },
  17781. /**
  17782. * Convert height map to normal map
  17783. * @param {HTMLImageElement|HTMLCanvasElement} image
  17784. * @param {boolean} [checkBump=false]
  17785. * @return {HTMLCanvasElement}
  17786. */
  17787. heightToNormal: function (image, checkBump) {
  17788. var canvas = document.createElement('canvas');
  17789. var width = canvas.width = image.width;
  17790. var height = canvas.height = image.height;
  17791. var ctx = canvas.getContext('2d');
  17792. ctx.drawImage(image, 0, 0, width, height);
  17793. checkBump = checkBump || false;
  17794. var srcData = ctx.getImageData(0, 0, width, height);
  17795. var dstData = ctx.createImageData(width, height);
  17796. for (var i = 0; i < srcData.data.length; i += 4) {
  17797. if (checkBump) {
  17798. var r = srcData.data[i];
  17799. var g = srcData.data[i + 1];
  17800. var b = srcData.data[i + 2];
  17801. var diff = Math.abs(r - g) + Math.abs(g - b);
  17802. if (diff > 20) {
  17803. console.warn('Given image is not a height map');
  17804. return image;
  17805. }
  17806. }
  17807. // Modified from http://mrdoob.com/lab/javascript/height2normal/
  17808. var x1, y1, x2, y2;
  17809. if (i % (width * 4) === 0) {
  17810. // left edge
  17811. x1 = srcData.data[i];
  17812. x2 = srcData.data[i + 4];
  17813. }
  17814. else if (i % (width * 4) === (width - 1) * 4) {
  17815. // right edge
  17816. x1 = srcData.data[i - 4];
  17817. x2 = srcData.data[i];
  17818. }
  17819. else {
  17820. x1 = srcData.data[i - 4];
  17821. x2 = srcData.data[i + 4];
  17822. }
  17823. if (i < width * 4) {
  17824. // top edge
  17825. y1 = srcData.data[i];
  17826. y2 = srcData.data[i + width * 4];
  17827. }
  17828. else if (i > width * (height - 1) * 4) {
  17829. // bottom edge
  17830. y1 = srcData.data[i - width * 4];
  17831. y2 = srcData.data[i];
  17832. }
  17833. else {
  17834. y1 = srcData.data[i - width * 4];
  17835. y2 = srcData.data[i + width * 4];
  17836. }
  17837. dstData.data[i] = (x1 - x2) + 127;
  17838. dstData.data[i + 1] = (y1 - y2) + 127;
  17839. dstData.data[i + 2] = 255;
  17840. dstData.data[i + 3] = 255;
  17841. }
  17842. ctx.putImageData(dstData, 0, 0);
  17843. return canvas;
  17844. },
  17845. /**
  17846. * Convert height map to normal map
  17847. * @param {HTMLImageElement|HTMLCanvasElement} image
  17848. * @param {boolean} [checkBump=false]
  17849. * @param {number} [threshold=20]
  17850. * @return {HTMLCanvasElement}
  17851. */
  17852. isHeightImage: function (img, downScaleSize, threshold) {
  17853. if (!img || !img.width || !img.height) {
  17854. return false;
  17855. }
  17856. var canvas = document.createElement('canvas');
  17857. var ctx = canvas.getContext('2d');
  17858. var size = downScaleSize || 32;
  17859. threshold = threshold || 20;
  17860. canvas.width = canvas.height = size;
  17861. ctx.drawImage(img, 0, 0, size, size);
  17862. var srcData = ctx.getImageData(0, 0, size, size);
  17863. for (var i = 0; i < srcData.data.length; i += 4) {
  17864. var r = srcData.data[i];
  17865. var g = srcData.data[i + 1];
  17866. var b = srcData.data[i + 2];
  17867. var diff = Math.abs(r - g) + Math.abs(g - b);
  17868. if (diff > threshold) {
  17869. return false;
  17870. }
  17871. }
  17872. return true;
  17873. },
  17874. _fetchTexture: function (path, onsuccess, onerror) {
  17875. __WEBPACK_IMPORTED_MODULE_2__core_vendor__["a" /* default */].request.get({
  17876. url: path,
  17877. responseType: 'arraybuffer',
  17878. onload: onsuccess,
  17879. onerror: onerror
  17880. });
  17881. },
  17882. /**
  17883. * Create a chessboard texture
  17884. * @param {number} [size]
  17885. * @param {number} [unitSize]
  17886. * @param {string} [color1]
  17887. * @param {string} [color2]
  17888. * @return {clay.Texture2D}
  17889. */
  17890. createChessboard: function (size, unitSize, color1, color2) {
  17891. size = size || 512;
  17892. unitSize = unitSize || 64;
  17893. color1 = color1 || 'black';
  17894. color2 = color2 || 'white';
  17895. var repeat = Math.ceil(size / unitSize);
  17896. var canvas = document.createElement('canvas');
  17897. canvas.width = size;
  17898. canvas.height = size;
  17899. var ctx = canvas.getContext('2d');
  17900. ctx.fillStyle = color2;
  17901. ctx.fillRect(0, 0, size, size);
  17902. ctx.fillStyle = color1;
  17903. for (var i = 0; i < repeat; i++) {
  17904. for (var j = 0; j < repeat; j++) {
  17905. var isFill = j % 2 ? (i % 2) : (i % 2 - 1);
  17906. if (isFill) {
  17907. ctx.fillRect(i * unitSize, j * unitSize, unitSize, unitSize);
  17908. }
  17909. }
  17910. }
  17911. var texture = new __WEBPACK_IMPORTED_MODULE_0__Texture2D__["a" /* default */]({
  17912. image: canvas,
  17913. anisotropic: 8
  17914. });
  17915. return texture;
  17916. },
  17917. /**
  17918. * Create a blank pure color 1x1 texture
  17919. * @param {string} color
  17920. * @return {clay.Texture2D}
  17921. */
  17922. createBlank: function (color) {
  17923. var canvas = document.createElement('canvas');
  17924. canvas.width = 1;
  17925. canvas.height = 1;
  17926. var ctx = canvas.getContext('2d');
  17927. ctx.fillStyle = color;
  17928. ctx.fillRect(0, 0, 1, 1);
  17929. var texture = new __WEBPACK_IMPORTED_MODULE_0__Texture2D__["a" /* default */]({
  17930. image: canvas
  17931. });
  17932. return texture;
  17933. }
  17934. };
  17935. /* harmony default export */ __webpack_exports__["a"] = (textureUtil);
  17936. /***/
  17937. }),
  17938. /* 62 */
  17939. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  17940. "use strict";
  17941. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__core_Base__ = __webpack_require__(7);
  17942. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__math_Vector3__ = __webpack_require__(3);
  17943. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__camera_Perspective__ = __webpack_require__(41);
  17944. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__FrameBuffer__ = __webpack_require__(10);
  17945. var targets = ['px', 'nx', 'py', 'ny', 'pz', 'nz'];
  17946. /**
  17947. * Pass rendering scene to a environment cube map
  17948. *
  17949. * @constructor clay.prePass.EnvironmentMap
  17950. * @extends clay.core.Base
  17951. * @example
  17952. * // Example of car reflection
  17953. * var envMap = new clay.TextureCube({
  17954. * width: 256,
  17955. * height: 256
  17956. * });
  17957. * var envPass = new clay.prePass.EnvironmentMap({
  17958. * position: car.position,
  17959. * texture: envMap
  17960. * });
  17961. * var carBody = car.getChildByName('body');
  17962. * carBody.material.enableTexture('environmentMap');
  17963. * carBody.material.set('environmentMap', envMap);
  17964. * ...
  17965. * animation.on('frame', function(frameTime) {
  17966. * envPass.render(renderer, scene);
  17967. * renderer.render(scene, camera);
  17968. * });
  17969. */
  17970. var EnvironmentMapPass = __WEBPACK_IMPORTED_MODULE_0__core_Base__["a" /* default */].extend(function () {
  17971. var ret = /** @lends clay.prePass.EnvironmentMap# */ {
  17972. /**
  17973. * Camera position
  17974. * @type {clay.Vector3}
  17975. * @memberOf clay.prePass.EnvironmentMap#
  17976. */
  17977. position: new __WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */](),
  17978. /**
  17979. * Camera far plane
  17980. * @type {number}
  17981. * @memberOf clay.prePass.EnvironmentMap#
  17982. */
  17983. far: 1000,
  17984. /**
  17985. * Camera near plane
  17986. * @type {number}
  17987. * @memberOf clay.prePass.EnvironmentMap#
  17988. */
  17989. near: 0.1,
  17990. /**
  17991. * Environment cube map
  17992. * @type {clay.TextureCube}
  17993. * @memberOf clay.prePass.EnvironmentMap#
  17994. */
  17995. texture: null,
  17996. /**
  17997. * Used if you wan't have shadow in environment map
  17998. * @type {clay.prePass.ShadowMap}
  17999. */
  18000. shadowMapPass: null,
  18001. };
  18002. var cameras = ret._cameras = {
  18003. px: new __WEBPACK_IMPORTED_MODULE_2__camera_Perspective__["a" /* default */]({ fov: 90 }),
  18004. nx: new __WEBPACK_IMPORTED_MODULE_2__camera_Perspective__["a" /* default */]({ fov: 90 }),
  18005. py: new __WEBPACK_IMPORTED_MODULE_2__camera_Perspective__["a" /* default */]({ fov: 90 }),
  18006. ny: new __WEBPACK_IMPORTED_MODULE_2__camera_Perspective__["a" /* default */]({ fov: 90 }),
  18007. pz: new __WEBPACK_IMPORTED_MODULE_2__camera_Perspective__["a" /* default */]({ fov: 90 }),
  18008. nz: new __WEBPACK_IMPORTED_MODULE_2__camera_Perspective__["a" /* default */]({ fov: 90 })
  18009. };
  18010. cameras.px.lookAt(__WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */].POSITIVE_X, __WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */].NEGATIVE_Y);
  18011. cameras.nx.lookAt(__WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */].NEGATIVE_X, __WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */].NEGATIVE_Y);
  18012. cameras.py.lookAt(__WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */].POSITIVE_Y, __WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */].POSITIVE_Z);
  18013. cameras.ny.lookAt(__WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */].NEGATIVE_Y, __WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */].NEGATIVE_Z);
  18014. cameras.pz.lookAt(__WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */].POSITIVE_Z, __WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */].NEGATIVE_Y);
  18015. cameras.nz.lookAt(__WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */].NEGATIVE_Z, __WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */].NEGATIVE_Y);
  18016. // FIXME In windows, use one framebuffer only renders one side of cubemap
  18017. ret._frameBuffer = new __WEBPACK_IMPORTED_MODULE_3__FrameBuffer__["a" /* default */]();
  18018. return ret;
  18019. }, /** @lends clay.prePass.EnvironmentMap# */ {
  18020. /**
  18021. * @param {string} target
  18022. * @return {clay.Camera}
  18023. */
  18024. getCamera: function (target) {
  18025. return this._cameras[target];
  18026. },
  18027. /**
  18028. * @param {clay.Renderer} renderer
  18029. * @param {clay.Scene} scene
  18030. * @param {boolean} [notUpdateScene=false]
  18031. */
  18032. render: function (renderer, scene, notUpdateScene) {
  18033. var _gl = renderer.gl;
  18034. if (!notUpdateScene) {
  18035. scene.update();
  18036. }
  18037. // Tweak fov
  18038. // http://the-witness.net/news/2012/02/seamless-cube-map-filtering/
  18039. var n = this.texture.width;
  18040. var fov = 2 * Math.atan(n / (n - 0.5)) / Math.PI * 180;
  18041. for (var i = 0; i < 6; i++) {
  18042. var target = targets[i];
  18043. var camera = this._cameras[target];
  18044. __WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */].copy(camera.position, this.position);
  18045. camera.far = this.far;
  18046. camera.near = this.near;
  18047. camera.fov = fov;
  18048. if (this.shadowMapPass) {
  18049. camera.update();
  18050. // update boundingBoxLastFrame
  18051. var bbox = scene.getBoundingBox();
  18052. bbox.applyTransform(camera.viewMatrix);
  18053. scene.viewBoundingBoxLastFrame.copy(bbox);
  18054. this.shadowMapPass.render(renderer, scene, camera, true);
  18055. }
  18056. this._frameBuffer.attach(
  18057. this.texture, _gl.COLOR_ATTACHMENT0,
  18058. _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i
  18059. );
  18060. this._frameBuffer.bind(renderer);
  18061. renderer.render(scene, camera, true);
  18062. this._frameBuffer.unbind(renderer);
  18063. }
  18064. },
  18065. /**
  18066. * @param {clay.Renderer} renderer
  18067. */
  18068. dispose: function (renderer) {
  18069. this._frameBuffer.dispose(renderer);
  18070. }
  18071. });
  18072. /* harmony default export */ __webpack_exports__["a"] = (EnvironmentMapPass);
  18073. /***/
  18074. }),
  18075. /* 63 */
  18076. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  18077. "use strict";
  18078. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__graphicGL__ = __webpack_require__(1);
  18079. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__geometry_Sprites__ = __webpack_require__(165);
  18080. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__shader_labels_glsl_js__ = __webpack_require__(166);
  18081. __WEBPACK_IMPORTED_MODULE_0__graphicGL__["a" /* default */].Shader.import(__WEBPACK_IMPORTED_MODULE_2__shader_labels_glsl_js__["a" /* default */]);
  18082. /* harmony default export */ __webpack_exports__["a"] = (__WEBPACK_IMPORTED_MODULE_0__graphicGL__["a" /* default */].Mesh.extend(function () {
  18083. var geometry = new __WEBPACK_IMPORTED_MODULE_1__geometry_Sprites__["a" /* default */]({
  18084. dynamic: true
  18085. });
  18086. var material = new __WEBPACK_IMPORTED_MODULE_0__graphicGL__["a" /* default */].Material({
  18087. shader: __WEBPACK_IMPORTED_MODULE_0__graphicGL__["a" /* default */].createShader('ecgl.labels'),
  18088. transparent: true,
  18089. depthMask: false
  18090. });
  18091. return {
  18092. geometry: geometry,
  18093. material: material,
  18094. culling: false,
  18095. castShadow: false,
  18096. ignorePicking: true
  18097. };
  18098. }));
  18099. /***/
  18100. }),
  18101. /* 64 */
  18102. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  18103. "use strict";
  18104. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  18105. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  18106. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__ = __webpack_require__(1);
  18107. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_earcut__ = __webpack_require__(204);
  18108. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__util_geometry_Lines3D__ = __webpack_require__(25);
  18109. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__util_retrieve__ = __webpack_require__(2);
  18110. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_claygl_src_dep_glmatrix__ = __webpack_require__(6);
  18111. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__util_geometry_trianglesSortMixin__ = __webpack_require__(65);
  18112. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__LabelsBuilder__ = __webpack_require__(66);
  18113. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__util_shader_lines3D_glsl_js__ = __webpack_require__(46);
  18114. var vec3 = __WEBPACK_IMPORTED_MODULE_5_claygl_src_dep_glmatrix__["a" /* default */].vec3;
  18115. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader.import(__WEBPACK_IMPORTED_MODULE_8__util_shader_lines3D_glsl_js__["a" /* default */]);
  18116. function Geo3DBuilder(api) {
  18117. this.rootNode = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Node();
  18118. // Cache triangulation result
  18119. this._triangulationResults = {};
  18120. this._shadersMap = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].COMMON_SHADERS.reduce(function (obj, shaderName) {
  18121. obj[shaderName] = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].createShader('ecgl.' + shaderName);
  18122. return obj;
  18123. }, {});
  18124. this._linesShader = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].createShader('ecgl.meshLines3D');
  18125. var groundMaterials = {};
  18126. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].COMMON_SHADERS.forEach(function (shading) {
  18127. groundMaterials[shading] = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Material({
  18128. shader: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].createShader('ecgl.' + shading)
  18129. });
  18130. });
  18131. this._groundMaterials = groundMaterials;
  18132. this._groundMesh = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh({
  18133. geometry: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].PlaneGeometry({ dynamic: true }),
  18134. castShadow: false,
  18135. renderNormal: true,
  18136. $ignorePicking: true
  18137. });
  18138. this._groundMesh.rotation.rotateX(-Math.PI / 2);
  18139. this._labelsBuilder = new __WEBPACK_IMPORTED_MODULE_7__LabelsBuilder__["a" /* default */](512, 512, api);
  18140. // Give a large render order.
  18141. this._labelsBuilder.getMesh().renderOrder = 100;
  18142. this._labelsBuilder.getMesh().material.depthTest = false;
  18143. this.rootNode.add(this._labelsBuilder.getMesh());
  18144. this._initMeshes();
  18145. this._api = api;
  18146. }
  18147. Geo3DBuilder.prototype = {
  18148. constructor: Geo3DBuilder,
  18149. // Which dimension to extrude. Y or Z
  18150. extrudeY: true,
  18151. update: function (componentModel, ecModel, api, start, end) {
  18152. var data = componentModel.getData();
  18153. if (start == null) {
  18154. start = 0;
  18155. }
  18156. if (end == null) {
  18157. end = data.count();
  18158. }
  18159. this._startIndex = start;
  18160. this._endIndex = end - 1;
  18161. this._triangulation(componentModel, start, end);
  18162. var shader = this._getShader(componentModel.get('shading'));
  18163. this._prepareMesh(componentModel, shader, api, start, end);
  18164. this.rootNode.updateWorldTransform();
  18165. this._updateRegionMesh(componentModel, api, start, end);
  18166. var coordSys = componentModel.coordinateSystem;
  18167. // PENDING
  18168. if (coordSys.type === 'geo3D') {
  18169. this._updateGroundPlane(componentModel, coordSys, api);
  18170. }
  18171. var self = this;
  18172. this._labelsBuilder.updateData(data, start, end);
  18173. this._labelsBuilder.getLabelPosition = function (dataIndex, positionDesc, distance) {
  18174. var name = data.getName(dataIndex);
  18175. var center;
  18176. var height = distance;
  18177. if (coordSys.type === 'geo3D') {
  18178. var region = coordSys.getRegion(name);
  18179. if (!region) {
  18180. return [NaN, NaN, NaN];
  18181. }
  18182. center = region.center;
  18183. var pos = coordSys.dataToPoint([center[0], center[1], height]);
  18184. return pos;
  18185. }
  18186. else {
  18187. var tmp = self._triangulationResults[dataIndex - self._startIndex];
  18188. var center = self.extrudeY ? [
  18189. (tmp.max[0] + tmp.min[0]) / 2,
  18190. tmp.max[1] + height,
  18191. (tmp.max[2] + tmp.min[2]) / 2
  18192. ] : [
  18193. (tmp.max[0] + tmp.min[0]) / 2,
  18194. (tmp.max[1] + tmp.min[1]) / 2,
  18195. tmp.max[2] + height
  18196. ];
  18197. }
  18198. };
  18199. this._data = data;
  18200. this._labelsBuilder.updateLabels();
  18201. this._updateDebugWireframe(componentModel);
  18202. // Reset some state.
  18203. this._lastHoverDataIndex = 0;
  18204. },
  18205. _initMeshes: function () {
  18206. var self = this;
  18207. function createPolygonMesh() {
  18208. var mesh = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh({
  18209. name: 'Polygon',
  18210. material: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Material({
  18211. shader: self._shadersMap.lambert
  18212. }),
  18213. geometry: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Geometry({
  18214. sortTriangles: true,
  18215. dynamic: true
  18216. }),
  18217. // TODO Disable culling
  18218. culling: false,
  18219. ignorePicking: true,
  18220. // Render normal in normal pass
  18221. renderNormal: true
  18222. });
  18223. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.extend(mesh.geometry, __WEBPACK_IMPORTED_MODULE_6__util_geometry_trianglesSortMixin__["a" /* default */]);
  18224. return mesh;
  18225. }
  18226. var polygonMesh = createPolygonMesh();
  18227. var linesMesh = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh({
  18228. material: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Material({
  18229. shader: this._linesShader
  18230. }),
  18231. castShadow: false,
  18232. ignorePicking: true,
  18233. $ignorePicking: true,
  18234. geometry: new __WEBPACK_IMPORTED_MODULE_3__util_geometry_Lines3D__["a" /* default */]({
  18235. useNativeLine: false
  18236. })
  18237. });
  18238. this.rootNode.add(polygonMesh);
  18239. this.rootNode.add(linesMesh);
  18240. polygonMesh.material.define('both', 'VERTEX_COLOR');
  18241. polygonMesh.material.define('fragment', 'DOUBLE_SIDED');
  18242. this._polygonMesh = polygonMesh;
  18243. this._linesMesh = linesMesh;
  18244. this.rootNode.add(this._groundMesh);
  18245. },
  18246. _getShader: function (shading) {
  18247. var shader = this._shadersMap[shading];
  18248. if (!shader) {
  18249. if (true) {
  18250. console.warn('Unkown shading ' + shading);
  18251. }
  18252. // Default use lambert shader.
  18253. shader = this._shadersMap.lambert;
  18254. }
  18255. shader.__shading = shading;
  18256. return shader;
  18257. },
  18258. _prepareMesh: function (componentModel, shader, api, start, end) {
  18259. var polygonVertexCount = 0;
  18260. var polygonTriangleCount = 0;
  18261. var linesVertexCount = 0;
  18262. var linesTriangleCount = 0;
  18263. // TODO Lines
  18264. for (var idx = start; idx < end; idx++) {
  18265. var polyInfo = this._getRegionPolygonInfo(idx);
  18266. var lineInfo = this._getRegionLinesInfo(idx, componentModel, this._linesMesh.geometry);
  18267. polygonVertexCount += polyInfo.vertexCount;
  18268. polygonTriangleCount += polyInfo.triangleCount;
  18269. linesVertexCount += lineInfo.vertexCount;
  18270. linesTriangleCount += lineInfo.triangleCount;
  18271. }
  18272. var polygonMesh = this._polygonMesh;
  18273. var polygonGeo = polygonMesh.geometry;
  18274. ['position', 'normal', 'texcoord0', 'color'].forEach(function (attrName) {
  18275. polygonGeo.attributes[attrName].init(polygonVertexCount);
  18276. });
  18277. polygonGeo.indices = polygonVertexCount > 0xffff ? new Uint32Array(polygonTriangleCount * 3) : new Uint16Array(polygonTriangleCount * 3);
  18278. if (polygonMesh.material.shader !== shader) {
  18279. polygonMesh.material.attachShader(shader, true);
  18280. }
  18281. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].setMaterialFromModel(shader.__shading, polygonMesh.material, componentModel, api);
  18282. if (linesVertexCount > 0) {
  18283. this._linesMesh.geometry.resetOffset();
  18284. this._linesMesh.geometry.setVertexCount(linesVertexCount);
  18285. this._linesMesh.geometry.setTriangleCount(linesTriangleCount);
  18286. }
  18287. // Indexing data index from vertex index.
  18288. this._dataIndexOfVertex = new Uint32Array(polygonVertexCount);
  18289. // Indexing vertex index range from data index
  18290. this._vertexRangeOfDataIndex = new Uint32Array((end - start) * 2);
  18291. },
  18292. _updateRegionMesh: function (componentModel, api, start, end) {
  18293. var data = componentModel.getData();
  18294. var vertexOffset = 0;
  18295. var triangleOffset = 0;
  18296. // Materials configurations.
  18297. var hasTranparentRegion = false;
  18298. var polygonMesh = this._polygonMesh;
  18299. var linesMesh = this._linesMesh;
  18300. for (var dataIndex = start; dataIndex < end; dataIndex++) {
  18301. // Get bunch of visual properties.
  18302. var regionModel = componentModel.getRegionModel(dataIndex);
  18303. var itemStyleModel = regionModel.getModel('itemStyle');
  18304. var color = itemStyleModel.get('color');
  18305. var opacity = __WEBPACK_IMPORTED_MODULE_4__util_retrieve__["a" /* default */].firstNotNull(itemStyleModel.get('opacity'), 1.0);
  18306. // Use visual color if it is encoded by visualMap component
  18307. var visualColor = data.getItemVisual(dataIndex, 'color', true);
  18308. if (visualColor != null && data.hasValue(dataIndex)) {
  18309. color = visualColor;
  18310. }
  18311. // Set color, opacity to visual for label usage.
  18312. data.setItemVisual(dataIndex, 'color', color);
  18313. data.setItemVisual(dataIndex, 'opacity', opacity);
  18314. color = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(color);
  18315. var borderColor = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(itemStyleModel.get('borderColor'));
  18316. color[3] *= opacity;
  18317. borderColor[3] *= opacity;
  18318. var isTransparent = color[3] < 0.99;
  18319. polygonMesh.material.set('color', [1, 1, 1, 1]);
  18320. hasTranparentRegion = hasTranparentRegion || isTransparent;
  18321. var regionHeight = __WEBPACK_IMPORTED_MODULE_4__util_retrieve__["a" /* default */].firstNotNull(regionModel.get('height', true), componentModel.get('regionHeight'));
  18322. var newOffsets = this._updatePolygonGeometry(
  18323. componentModel, polygonMesh.geometry, dataIndex, regionHeight,
  18324. vertexOffset, triangleOffset, color
  18325. );
  18326. for (var i = vertexOffset; i < newOffsets.vertexOffset; i++) {
  18327. this._dataIndexOfVertex[i] = dataIndex;
  18328. }
  18329. this._vertexRangeOfDataIndex[(dataIndex - start) * 2] = vertexOffset;
  18330. this._vertexRangeOfDataIndex[(dataIndex - start) * 2 + 1] = newOffsets.vertexOffset;
  18331. vertexOffset = newOffsets.vertexOffset;
  18332. triangleOffset = newOffsets.triangleOffset;
  18333. // Update lines.
  18334. var lineWidth = itemStyleModel.get('borderWidth');
  18335. var hasLine = lineWidth > 0;
  18336. if (hasLine) {
  18337. lineWidth *= api.getDevicePixelRatio();
  18338. this._updateLinesGeometry(
  18339. linesMesh.geometry, componentModel, dataIndex, regionHeight, lineWidth,
  18340. componentModel.coordinateSystem.transform
  18341. );
  18342. }
  18343. linesMesh.invisible = !hasLine;
  18344. linesMesh.material.set({
  18345. color: borderColor
  18346. });
  18347. }
  18348. var polygonMesh = this._polygonMesh;
  18349. polygonMesh.material.transparent = hasTranparentRegion;
  18350. polygonMesh.material.depthMask = !hasTranparentRegion;
  18351. polygonMesh.geometry.updateBoundingBox();
  18352. polygonMesh.frontFace = this.extrudeY ? __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh.CCW : __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh.CW;
  18353. // Update tangents
  18354. if (polygonMesh.material.get('normalMap')) {
  18355. polygonMesh.geometry.generateTangents();
  18356. }
  18357. polygonMesh.seriesIndex = componentModel.seriesIndex;
  18358. polygonMesh.on('mousemove', this._onmousemove, this);
  18359. polygonMesh.on('mouseout', this._onmouseout, this);
  18360. },
  18361. _updateDebugWireframe: function (componentModel) {
  18362. var debugWireframeModel = componentModel.getModel('debug.wireframe');
  18363. // TODO Unshow
  18364. if (debugWireframeModel.get('show')) {
  18365. var color = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(
  18366. debugWireframeModel.get('lineStyle.color') || 'rgba(0,0,0,0.5)'
  18367. );
  18368. var width = __WEBPACK_IMPORTED_MODULE_4__util_retrieve__["a" /* default */].firstNotNull(
  18369. debugWireframeModel.get('lineStyle.width'), 1
  18370. );
  18371. // TODO Will cause highlight wrong
  18372. var mesh = this._polygonMesh;
  18373. mesh.geometry.generateBarycentric();
  18374. mesh.material.define('both', 'WIREFRAME_TRIANGLE');
  18375. mesh.material.set('wireframeLineColor', color);
  18376. mesh.material.set('wireframeLineWidth', width);
  18377. }
  18378. },
  18379. _onmousemove: function (e) {
  18380. var dataIndex = this._dataIndexOfVertex[e.triangle[0]];
  18381. if (dataIndex == null) {
  18382. dataIndex = -1;
  18383. }
  18384. if (dataIndex !== this._lastHoverDataIndex) {
  18385. this.downplay(this._lastHoverDataIndex);
  18386. this.highlight(dataIndex);
  18387. this._labelsBuilder.updateLabels([dataIndex]);
  18388. }
  18389. this._lastHoverDataIndex = dataIndex;
  18390. this._polygonMesh.dataIndex = dataIndex;
  18391. },
  18392. _onmouseout: function (e) {
  18393. if (e.target) {
  18394. this.downplay(this._lastHoverDataIndex);
  18395. this._lastHoverDataIndex = -1;
  18396. this._polygonMesh.dataIndex = -1;
  18397. }
  18398. this._labelsBuilder.updateLabels([]);
  18399. },
  18400. _updateGroundPlane: function (componentModel, geo3D, api) {
  18401. var groundModel = componentModel.getModel('groundPlane', componentModel);
  18402. this._groundMesh.invisible = !groundModel.get('show', true);
  18403. if (this._groundMesh.invisible) {
  18404. return;
  18405. }
  18406. var shading = componentModel.get('shading');
  18407. var material = this._groundMaterials[shading];
  18408. if (!material) {
  18409. if (true) {
  18410. console.warn('Unkown shading ' + shading);
  18411. }
  18412. material = this._groundMaterials.lambert;
  18413. }
  18414. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].setMaterialFromModel(shading, material, groundModel, api);
  18415. if (material.get('normalMap')) {
  18416. this._groundMesh.geometry.generateTangents();
  18417. }
  18418. this._groundMesh.material = material;
  18419. this._groundMesh.material.set('color', __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(groundModel.get('color')));
  18420. this._groundMesh.scale.set(geo3D.size[0], geo3D.size[2], 1);
  18421. },
  18422. _triangulation: function (componentModel, start, end) {
  18423. this._triangulationResults = [];
  18424. var minAll = [Infinity, Infinity, Infinity];
  18425. var maxAll = [-Infinity, -Infinity, -Infinity];
  18426. var coordSys = componentModel.coordinateSystem;
  18427. for (var idx = start; idx < end; idx++) {
  18428. var polygons = [];
  18429. var polygonCoords = componentModel.getRegionPolygonCoords(idx);
  18430. for (var i = 0; i < polygonCoords.length; i++) {
  18431. var exterior = polygonCoords[i].exterior;
  18432. var interiors = polygonCoords[i].interiors;
  18433. var points = [];
  18434. var holes = [];
  18435. if (exterior.length < 3) {
  18436. continue;
  18437. }
  18438. var offset = 0;
  18439. for (var j = 0; j < exterior.length; j++) {
  18440. var p = exterior[j];
  18441. points[offset++] = p[0];
  18442. points[offset++] = p[1];
  18443. }
  18444. for (var j = 0; j < interiors.length; j++) {
  18445. if (interiors[j].length < 3) {
  18446. continue;
  18447. }
  18448. var startIdx = points.length / 2;
  18449. for (var k = 0; k < interiors[j].length; k++) {
  18450. var p = interiors[j][k];
  18451. points.push(p[0]);
  18452. points.push(p[1]);
  18453. }
  18454. holes.push(startIdx);
  18455. }
  18456. var triangles = Object(__WEBPACK_IMPORTED_MODULE_2__util_earcut__["a" /* default */])(points, holes);
  18457. var points3 = new Float64Array(points.length / 2 * 3);
  18458. var pos = [];
  18459. var min = [Infinity, Infinity, Infinity];
  18460. var max = [-Infinity, -Infinity, -Infinity];
  18461. var off3 = 0;
  18462. for (var j = 0; j < points.length;) {
  18463. vec3.set(pos, points[j++], 0, points[j++]);
  18464. if (coordSys && coordSys.transform) {
  18465. vec3.transformMat4(pos, pos, coordSys.transform);
  18466. }
  18467. vec3.min(min, min, pos);
  18468. vec3.max(max, max, pos);
  18469. points3[off3++] = pos[0];
  18470. points3[off3++] = pos[1];
  18471. points3[off3++] = pos[2];
  18472. }
  18473. vec3.min(minAll, minAll, min);
  18474. vec3.max(maxAll, maxAll, max);
  18475. polygons.push({
  18476. points: points3,
  18477. indices: triangles,
  18478. min: min,
  18479. max: max
  18480. });
  18481. }
  18482. this._triangulationResults.push(polygons);
  18483. }
  18484. this._geoBoundingBox = [minAll, maxAll];
  18485. },
  18486. /**
  18487. * Get region vertex and triangle count
  18488. */
  18489. _getRegionPolygonInfo: function (idx) {
  18490. var polygons = this._triangulationResults[idx - this._startIndex];
  18491. var sideVertexCount = 0;
  18492. var sideTriangleCount = 0;
  18493. for (var i = 0; i < polygons.length; i++) {
  18494. sideVertexCount += polygons[i].points.length / 3;
  18495. sideTriangleCount += polygons[i].indices.length / 3;
  18496. }
  18497. var vertexCount = sideVertexCount * 2 + sideVertexCount * 4;
  18498. var triangleCount = sideTriangleCount * 2 + sideVertexCount * 2;
  18499. return {
  18500. vertexCount: vertexCount,
  18501. triangleCount: triangleCount
  18502. };
  18503. },
  18504. _updatePolygonGeometry: function (
  18505. componentModel, geometry, dataIndex, regionHeight,
  18506. vertexOffset, triangleOffset, color
  18507. ) {
  18508. // FIXME
  18509. var projectUVOnGround = componentModel.get('projectUVOnGround');
  18510. var positionAttr = geometry.attributes.position;
  18511. var normalAttr = geometry.attributes.normal;
  18512. var texcoordAttr = geometry.attributes.texcoord0;
  18513. var colorAttr = geometry.attributes.color;
  18514. var polygons = this._triangulationResults[dataIndex - this._startIndex];
  18515. var hasColor = colorAttr.value && color;
  18516. var indices = geometry.indices;
  18517. var extrudeCoordIndex = this.extrudeY ? 1 : 2;
  18518. var sideCoordIndex = this.extrudeY ? 2 : 1;
  18519. var scale = [
  18520. this.rootNode.worldTransform.x.len(),
  18521. this.rootNode.worldTransform.y.len(),
  18522. this.rootNode.worldTransform.z.len()
  18523. ];
  18524. var min = vec3.mul([], this._geoBoundingBox[0], scale);
  18525. var max = vec3.mul([], this._geoBoundingBox[1], scale);
  18526. var maxDimSize = Math.max(max[0] - min[0], max[2] - min[2]);
  18527. function addVertices(polygon, y, insideOffset) {
  18528. var points = polygon.points;
  18529. var pointsLen = points.length;
  18530. var currentPosition = [];
  18531. var uv = [];
  18532. for (var k = 0; k < pointsLen; k += 3) {
  18533. currentPosition[0] = points[k];
  18534. currentPosition[extrudeCoordIndex] = y;
  18535. currentPosition[sideCoordIndex] = points[k + 2];
  18536. uv[0] = (points[k] * scale[0] - min[0]) / maxDimSize;
  18537. uv[1] = (points[k + 2] * scale[sideCoordIndex] - min[2]) / maxDimSize;
  18538. positionAttr.set(vertexOffset, currentPosition);
  18539. if (hasColor) {
  18540. colorAttr.set(vertexOffset, color);
  18541. }
  18542. texcoordAttr.set(vertexOffset++, uv);
  18543. }
  18544. }
  18545. function buildTopBottom(polygon, y, insideOffset) {
  18546. var startVertexOffset = vertexOffset;
  18547. addVertices(polygon, y, insideOffset);
  18548. var len = polygon.indices.length;
  18549. for (var k = 0; k < len; k++) {
  18550. indices[triangleOffset * 3 + k] = polygon.indices[k] + startVertexOffset;
  18551. }
  18552. triangleOffset += polygon.indices.length / 3;
  18553. }
  18554. var normalTop = this.extrudeY ? [0, 1, 0] : [0, 0, 1];
  18555. var normalBottom = vec3.negate([], normalTop);
  18556. for (var p = 0; p < polygons.length; p++) {
  18557. var startVertexOffset = vertexOffset;
  18558. var polygon = polygons[p];
  18559. // BOTTOM
  18560. buildTopBottom(polygon, 0, 0);
  18561. // TOP
  18562. buildTopBottom(polygon, regionHeight, 0);
  18563. var ringVertexCount = polygon.points.length / 3;
  18564. for (var v = 0; v < ringVertexCount; v++) {
  18565. normalAttr.set(startVertexOffset + v, normalBottom);
  18566. normalAttr.set(startVertexOffset + v + ringVertexCount, normalTop);
  18567. }
  18568. var quadToTriangle = [0, 3, 1, 1, 3, 2];
  18569. var quadPos = [[], [], [], []];
  18570. var a = [];
  18571. var b = [];
  18572. var normal = [];
  18573. var uv = [];
  18574. var len = 0;
  18575. for (var v = 0; v < ringVertexCount; v++) {
  18576. var next = (v + 1) % ringVertexCount;
  18577. var dx = (polygon.points[next * 3] - polygon.points[v * 3]) * scale[0];
  18578. var dy = (polygon.points[next * 3 + 2] - polygon.points[v * 3 + 2]) * scale[sideCoordIndex];
  18579. var sideLen = Math.sqrt(dx * dx + dy * dy);
  18580. // 0----1
  18581. // 3----2
  18582. for (var k = 0; k < 4; k++) {
  18583. var isCurrent = (k === 0 || k === 3);
  18584. var idx3 = (isCurrent ? v : next) * 3;
  18585. quadPos[k][0] = polygon.points[idx3];
  18586. quadPos[k][extrudeCoordIndex] = k > 1 ? regionHeight : 0;
  18587. quadPos[k][sideCoordIndex] = polygon.points[idx3 + 2];
  18588. positionAttr.set(vertexOffset + k, quadPos[k]);
  18589. if (projectUVOnGround) {
  18590. uv[0] = (polygon.points[idx3] * scale[0] - min[0]) / maxDimSize;
  18591. uv[1] = (polygon.points[idx3 + 2] * scale[sideCoordIndex] - min[sideCoordIndex]) / maxDimSize;
  18592. }
  18593. else {
  18594. uv[0] = (isCurrent ? len : (len + sideLen)) / maxDimSize;
  18595. uv[1] = (quadPos[k][extrudeCoordIndex] * scale[extrudeCoordIndex] - min[extrudeCoordIndex]) / maxDimSize;
  18596. }
  18597. texcoordAttr.set(vertexOffset + k, uv);
  18598. }
  18599. vec3.sub(a, quadPos[1], quadPos[0]);
  18600. vec3.sub(b, quadPos[3], quadPos[0]);
  18601. vec3.cross(normal, a, b);
  18602. vec3.normalize(normal, normal);
  18603. for (var k = 0; k < 4; k++) {
  18604. normalAttr.set(vertexOffset + k, normal);
  18605. if (hasColor) {
  18606. colorAttr.set(vertexOffset + k, color);
  18607. }
  18608. }
  18609. for (var k = 0; k < 6; k++) {
  18610. indices[triangleOffset * 3 + k] = quadToTriangle[k] + vertexOffset;
  18611. }
  18612. vertexOffset += 4;
  18613. triangleOffset += 2;
  18614. len += sideLen;
  18615. }
  18616. }
  18617. geometry.dirty();
  18618. return {
  18619. vertexOffset: vertexOffset,
  18620. triangleOffset: triangleOffset
  18621. };
  18622. },
  18623. _getRegionLinesInfo: function (idx, componentModel, geometry) {
  18624. var vertexCount = 0;
  18625. var triangleCount = 0;
  18626. var regionModel = componentModel.getRegionModel(idx);
  18627. var itemStyleModel = regionModel.getModel('itemStyle');
  18628. var lineWidth = itemStyleModel.get('borderWidth');
  18629. if (lineWidth > 0) {
  18630. var polygonCoords = componentModel.getRegionPolygonCoords(idx);
  18631. polygonCoords.forEach(function (coords) {
  18632. var exterior = coords.exterior;
  18633. var interiors = coords.interiors;
  18634. vertexCount += geometry.getPolylineVertexCount(exterior);
  18635. triangleCount += geometry.getPolylineTriangleCount(exterior);
  18636. for (var i = 0; i < interiors.length; i++) {
  18637. vertexCount += geometry.getPolylineVertexCount(interiors[i]);
  18638. triangleCount += geometry.getPolylineTriangleCount(interiors[i]);
  18639. }
  18640. }, this);
  18641. }
  18642. return {
  18643. vertexCount: vertexCount,
  18644. triangleCount: triangleCount
  18645. };
  18646. },
  18647. _updateLinesGeometry: function (geometry, componentModel, dataIndex, regionHeight, lineWidth, transform) {
  18648. function convertToPoints3(polygon) {
  18649. var points = new Float64Array(polygon.length * 3);
  18650. var offset = 0;
  18651. var pos = [];
  18652. for (var i = 0; i < polygon.length; i++) {
  18653. pos[0] = polygon[i][0];
  18654. // Add a offset to avoid z-fighting
  18655. pos[1] = regionHeight + 0.1;
  18656. pos[2] = polygon[i][1];
  18657. if (transform) {
  18658. vec3.transformMat4(pos, pos, transform);
  18659. }
  18660. points[offset++] = pos[0];
  18661. points[offset++] = pos[1];
  18662. points[offset++] = pos[2];
  18663. }
  18664. return points;
  18665. }
  18666. var whiteColor = [1, 1, 1, 1];
  18667. var coords = componentModel.getRegionPolygonCoords(dataIndex);
  18668. coords.forEach(function (geo) {
  18669. var exterior = geo.exterior;
  18670. var interiors = geo.interiors;
  18671. geometry.addPolyline(convertToPoints3(exterior), whiteColor, lineWidth);
  18672. for (var i = 0; i < interiors.length; i++) {
  18673. geometry.addPolyline(convertToPoints3(interiors[i]), whiteColor, lineWidth);
  18674. }
  18675. });
  18676. },
  18677. highlight: function (dataIndex) {
  18678. var data = this._data;
  18679. if (!data) {
  18680. return;
  18681. }
  18682. var itemModel = data.getItemModel(dataIndex);
  18683. var emphasisItemStyleModel = itemModel.getModel('emphasis.itemStyle');
  18684. var emphasisColor = emphasisItemStyleModel.get('color');
  18685. var emphasisOpacity = __WEBPACK_IMPORTED_MODULE_4__util_retrieve__["a" /* default */].firstNotNull(
  18686. emphasisItemStyleModel.get('opacity'),
  18687. data.getItemVisual(dataIndex, 'opacity'),
  18688. 1
  18689. );
  18690. if (emphasisColor == null) {
  18691. var color = data.getItemVisual(dataIndex, 'color');
  18692. emphasisColor = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.color.lift(color, -0.4);
  18693. }
  18694. if (emphasisOpacity == null) {
  18695. emphasisOpacity = data.getItemVisual(dataIndex, 'opacity');
  18696. }
  18697. var colorArr = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(emphasisColor);
  18698. colorArr[3] *= emphasisOpacity;
  18699. this._setColorOfDataIndex(data, dataIndex, colorArr);
  18700. },
  18701. downplay: function (dataIndex) {
  18702. var data = this._data;
  18703. if (!data) {
  18704. return;
  18705. }
  18706. var color = data.getItemVisual(dataIndex, 'color');
  18707. var opacity = __WEBPACK_IMPORTED_MODULE_4__util_retrieve__["a" /* default */].firstNotNull(data.getItemVisual(dataIndex, 'opacity'), 1);
  18708. var colorArr = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(color);
  18709. colorArr[3] *= opacity;
  18710. this._setColorOfDataIndex(data, dataIndex, colorArr);
  18711. },
  18712. _setColorOfDataIndex: function (data, dataIndex, colorArr) {
  18713. if (dataIndex < this._startIndex && dataIndex > this._endIndex) {
  18714. return;
  18715. }
  18716. dataIndex -= this._startIndex;
  18717. for (var i = this._vertexRangeOfDataIndex[dataIndex * 2]; i < this._vertexRangeOfDataIndex[dataIndex * 2 + 1]; i++) {
  18718. this._polygonMesh.geometry.attributes.color.set(i, colorArr);
  18719. }
  18720. this._polygonMesh.geometry.dirty();
  18721. this._api.getZr().refresh();
  18722. }
  18723. };
  18724. /* harmony default export */ __webpack_exports__["a"] = (Geo3DBuilder);
  18725. /***/
  18726. }),
  18727. /* 65 */
  18728. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  18729. "use strict";
  18730. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__ProgressiveQuickSort__ = __webpack_require__(97);
  18731. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_dep_glmatrix__ = __webpack_require__(6);
  18732. var vec3 = __WEBPACK_IMPORTED_MODULE_1_claygl_src_dep_glmatrix__["a" /* default */].vec3;
  18733. var p0 = vec3.create();
  18734. var p1 = vec3.create();
  18735. var p2 = vec3.create();
  18736. // var cp = vec3.create();
  18737. /* harmony default export */ __webpack_exports__["a"] = ({
  18738. needsSortTriangles: function () {
  18739. return this.indices && this.sortTriangles;
  18740. },
  18741. needsSortTrianglesProgressively: function () {
  18742. return this.needsSortTriangles() && this.triangleCount >= 2e4;
  18743. },
  18744. doSortTriangles: function (cameraPos, frame) {
  18745. var indices = this.indices;
  18746. // Do progressive quick sort.
  18747. if (frame === 0) {
  18748. var posAttr = this.attributes.position;
  18749. var cameraPos = cameraPos.array;
  18750. if (!this._triangleZList || this._triangleZList.length !== this.triangleCount) {
  18751. this._triangleZList = new Float32Array(this.triangleCount);
  18752. this._sortedTriangleIndices = new Uint32Array(this.triangleCount);
  18753. this._indicesTmp = new indices.constructor(indices.length);
  18754. this._triangleZListTmp = new Float32Array(this.triangleCount);
  18755. }
  18756. var cursor = 0;
  18757. var firstZ;
  18758. for (var i = 0; i < indices.length;) {
  18759. posAttr.get(indices[i++], p0);
  18760. posAttr.get(indices[i++], p1);
  18761. posAttr.get(indices[i++], p2);
  18762. // FIXME If use center ?
  18763. // cp[0] = (p0[0] + p1[0] + p2[0]) / 3;
  18764. // cp[1] = (p0[1] + p1[1] + p2[1]) / 3;
  18765. // cp[2] = (p0[2] + p1[2] + p2[2]) / 3;
  18766. // Camera position is in object space
  18767. // Use max of three points, PENDING
  18768. var z0 = vec3.sqrDist(p0, cameraPos);
  18769. var z1 = vec3.sqrDist(p1, cameraPos);
  18770. var z2 = vec3.sqrDist(p2, cameraPos);
  18771. var zMax = Math.min(z0, z1);
  18772. zMax = Math.min(zMax, z2);
  18773. if (i === 3) {
  18774. firstZ = zMax;
  18775. zMax = 0;
  18776. }
  18777. else {
  18778. // Only store the difference to avoid the precision issue.
  18779. zMax = zMax - firstZ;
  18780. }
  18781. this._triangleZList[cursor++] = zMax;
  18782. }
  18783. }
  18784. var sortedTriangleIndices = this._sortedTriangleIndices;
  18785. for (var i = 0; i < sortedTriangleIndices.length; i++) {
  18786. sortedTriangleIndices[i] = i;
  18787. }
  18788. if (this.triangleCount < 2e4) {
  18789. // Use simple timsort for simple geometries.
  18790. if (frame === 0) {
  18791. // Use native sort temporary.
  18792. this._simpleSort(true);
  18793. }
  18794. }
  18795. else {
  18796. for (var i = 0; i < 3; i++) {
  18797. this._progressiveQuickSort(frame * 3 + i);
  18798. }
  18799. }
  18800. var targetIndices = this._indicesTmp;
  18801. var targetTriangleZList = this._triangleZListTmp;
  18802. var faceZList = this._triangleZList;
  18803. for (var i = 0; i < this.triangleCount; i++) {
  18804. var fromIdx3 = sortedTriangleIndices[i] * 3;
  18805. var toIdx3 = i * 3;
  18806. targetIndices[toIdx3++] = indices[fromIdx3++];
  18807. targetIndices[toIdx3++] = indices[fromIdx3++];
  18808. targetIndices[toIdx3] = indices[fromIdx3];
  18809. targetTriangleZList[i] = faceZList[sortedTriangleIndices[i]];
  18810. }
  18811. // Swap indices.
  18812. var tmp = this._indicesTmp;
  18813. this._indicesTmp = this.indices;
  18814. this.indices = tmp;
  18815. var tmp = this._triangleZListTmp;
  18816. this._triangleZListTmp = this._triangleZList;
  18817. this._triangleZList = tmp;
  18818. this.dirtyIndices();
  18819. },
  18820. _simpleSort: function (useNativeQuickSort) {
  18821. var faceZList = this._triangleZList;
  18822. var sortedTriangleIndices = this._sortedTriangleIndices;
  18823. function compare(a, b) {
  18824. // Sort from far to near. which is descending order
  18825. return faceZList[b] - faceZList[a];
  18826. }
  18827. if (useNativeQuickSort) {
  18828. Array.prototype.sort.call(sortedTriangleIndices, compare);
  18829. }
  18830. else {
  18831. __WEBPACK_IMPORTED_MODULE_0__ProgressiveQuickSort__["a" /* default */].sort(sortedTriangleIndices, compare, 0, sortedTriangleIndices.length - 1);
  18832. }
  18833. },
  18834. _progressiveQuickSort: function (frame) {
  18835. var faceZList = this._triangleZList;
  18836. var sortedTriangleIndices = this._sortedTriangleIndices;
  18837. this._quickSort = this._quickSort || new __WEBPACK_IMPORTED_MODULE_0__ProgressiveQuickSort__["a" /* default */]();
  18838. this._quickSort.step(sortedTriangleIndices, function (a, b) {
  18839. return faceZList[b] - faceZList[a];
  18840. }, frame);
  18841. }
  18842. });
  18843. /***/
  18844. }),
  18845. /* 66 */
  18846. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  18847. "use strict";
  18848. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  18849. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  18850. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_ZRTextureAtlasSurface__ = __webpack_require__(81);
  18851. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_mesh_LabelsMesh__ = __webpack_require__(63);
  18852. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__util_retrieve__ = __webpack_require__(2);
  18853. var LABEL_NORMAL_SHOW_BIT = 1;
  18854. var LABEL_EMPHASIS_SHOW_BIT = 2;
  18855. function LabelsBuilder(width, height, api) {
  18856. this._labelsMesh = new __WEBPACK_IMPORTED_MODULE_2__util_mesh_LabelsMesh__["a" /* default */]();
  18857. this._labelTextureSurface = new __WEBPACK_IMPORTED_MODULE_1__util_ZRTextureAtlasSurface__["a" /* default */]({
  18858. width: 512,
  18859. height: 512,
  18860. devicePixelRatio: api.getDevicePixelRatio(),
  18861. onupdate: function () {
  18862. api.getZr().refresh();
  18863. }
  18864. });
  18865. this._api = api;
  18866. this._labelsMesh.material.set('textureAtlas', this._labelTextureSurface.getTexture());
  18867. }
  18868. LabelsBuilder.prototype.getLabelPosition = function (dataIndex, positionDesc, distance) {
  18869. return [0, 0, 0];
  18870. };
  18871. LabelsBuilder.prototype.getLabelDistance = function (dataIndex, positionDesc, distance) {
  18872. return 0;
  18873. };
  18874. LabelsBuilder.prototype.getMesh = function () {
  18875. return this._labelsMesh;
  18876. };
  18877. LabelsBuilder.prototype.updateData = function (data, start, end) {
  18878. if (start == null) {
  18879. start = 0;
  18880. }
  18881. if (end == null) {
  18882. end = data.count();
  18883. }
  18884. if (!this._labelsVisibilitiesBits || this._labelsVisibilitiesBits.length !== (end - start)) {
  18885. this._labelsVisibilitiesBits = new Uint8Array(end - start);
  18886. }
  18887. var normalLabelVisibilityQuery = ['label', 'show'];
  18888. var emphasisLabelVisibilityQuery = ['emphasis', 'label', 'show'];
  18889. for (var idx = start; idx < end; idx++) {
  18890. var itemModel = data.getItemModel(idx);
  18891. var normalVisibility = itemModel.get(normalLabelVisibilityQuery);
  18892. var emphasisVisibility = itemModel.get(emphasisLabelVisibilityQuery);
  18893. if (emphasisVisibility == null) {
  18894. emphasisVisibility = normalVisibility;
  18895. }
  18896. var bit = (normalVisibility ? LABEL_NORMAL_SHOW_BIT : 0)
  18897. | (emphasisVisibility ? LABEL_EMPHASIS_SHOW_BIT : 0);
  18898. this._labelsVisibilitiesBits[idx - start] = bit;
  18899. }
  18900. this._start = start;
  18901. this._end = end;
  18902. this._data = data;
  18903. };
  18904. LabelsBuilder.prototype.updateLabels = function (highlightDataIndices) {
  18905. if (!this._data) {
  18906. return;
  18907. }
  18908. highlightDataIndices = highlightDataIndices || [];
  18909. var hasHighlightData = highlightDataIndices.length > 0;
  18910. var highlightDataIndicesMap = {};
  18911. for (var i = 0; i < highlightDataIndices.length; i++) {
  18912. highlightDataIndicesMap[highlightDataIndices[i]] = true;
  18913. }
  18914. this._labelsMesh.geometry.convertToDynamicArray(true);
  18915. this._labelTextureSurface.clear();
  18916. var normalLabelQuery = ['label'];
  18917. var emphasisLabelQuery = ['emphasis', 'label'];
  18918. var seriesModel = this._data.hostModel;
  18919. var data = this._data;
  18920. var seriesLabelModel = seriesModel.getModel(normalLabelQuery);
  18921. var seriesLabelEmphasisModel = seriesModel.getModel(emphasisLabelQuery, seriesLabelModel);
  18922. var textAlignMap = {
  18923. left: 'right',
  18924. right: 'left',
  18925. top: 'center',
  18926. bottom: 'center'
  18927. };
  18928. var textVerticalAlignMap = {
  18929. left: 'middle',
  18930. right: 'middle',
  18931. top: 'bottom',
  18932. bottom: 'top'
  18933. };
  18934. for (var dataIndex = this._start; dataIndex < this._end; dataIndex++) {
  18935. var isEmphasis = false;
  18936. if (hasHighlightData && highlightDataIndicesMap[dataIndex]) {
  18937. isEmphasis = true;
  18938. }
  18939. var ifShow = this._labelsVisibilitiesBits[dataIndex - this._start]
  18940. & (isEmphasis ? LABEL_EMPHASIS_SHOW_BIT : LABEL_NORMAL_SHOW_BIT);
  18941. if (!ifShow) {
  18942. continue;
  18943. }
  18944. var itemModel = data.getItemModel(dataIndex);
  18945. var labelModel = itemModel.getModel(
  18946. isEmphasis ? emphasisLabelQuery : normalLabelQuery,
  18947. isEmphasis ? seriesLabelEmphasisModel : seriesLabelModel
  18948. );
  18949. var distance = labelModel.get('distance') || 0;
  18950. var position = labelModel.get('position');
  18951. var textStyleModel = labelModel.getModel('textStyle');
  18952. var dpr = this._api.getDevicePixelRatio();
  18953. var text = seriesModel.getFormattedLabel(dataIndex, isEmphasis ? 'emphasis' : 'normal');
  18954. if (text == null || text === '') {
  18955. return;
  18956. }
  18957. // TODO Background.
  18958. var textEl = new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.graphic.Text();
  18959. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.graphic.setTextStyle(textEl.style, textStyleModel, {
  18960. text: text,
  18961. textFill: textStyleModel.get('color') || data.getItemVisual(dataIndex, 'color') || '#000',
  18962. textAlign: 'left',
  18963. textVerticalAlign: 'top',
  18964. opacity: __WEBPACK_IMPORTED_MODULE_3__util_retrieve__["a" /* default */].firstNotNull(textStyleModel.get('opacity'), data.getItemVisual(dataIndex, 'opacity'), 1)
  18965. });
  18966. var rect = textEl.getBoundingRect();
  18967. var lineHeight = 1.2;
  18968. rect.height *= lineHeight;
  18969. var coords = this._labelTextureSurface.add(textEl);
  18970. var textAlign = textAlignMap[position] || 'center';
  18971. var textVerticalAlign = textVerticalAlignMap[position] || 'bottom';
  18972. this._labelsMesh.geometry.addSprite(
  18973. this.getLabelPosition(dataIndex, position, distance),
  18974. [rect.width * dpr, rect.height * dpr], coords,
  18975. textAlign, textVerticalAlign,
  18976. this.getLabelDistance(dataIndex, position, distance) * dpr
  18977. );
  18978. }
  18979. this._labelsMesh.material.set('uvScale', this._labelTextureSurface.getCoordsScale());
  18980. // var canvas = this._labelTextureSurface.getTexture().image;
  18981. // document.body.appendChild(canvas);
  18982. // canvas.style.cssText = 'position:absolute;z-index: 1000';
  18983. // Update image.
  18984. this._labelTextureSurface.getZr().refreshImmediately();
  18985. this._labelsMesh.geometry.convertToTypedArray();
  18986. this._labelsMesh.geometry.dirty();
  18987. };
  18988. /* harmony default export */ __webpack_exports__["a"] = (LabelsBuilder);
  18989. /***/
  18990. }),
  18991. /* 67 */
  18992. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  18993. "use strict";
  18994. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  18995. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  18996. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__ = __webpack_require__(1);
  18997. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_sprite__ = __webpack_require__(239);
  18998. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__PointsMesh__ = __webpack_require__(240);
  18999. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__component_common_LabelsBuilder__ = __webpack_require__(66);
  19000. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_claygl_src_math_Matrix4__ = __webpack_require__(9);
  19001. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__util_retrieve__ = __webpack_require__(2);
  19002. var SDF_RANGE = 20;
  19003. var Z_2D = -10;
  19004. function isSymbolSizeSame(a, b) {
  19005. return a && b && a[0] === b[0] && a[1] === b[1];
  19006. }
  19007. // TODO gl_PointSize has max value.
  19008. function PointsBuilder(is2D, api) {
  19009. this.rootNode = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Node();
  19010. /**
  19011. * @type {boolean}
  19012. */
  19013. this.is2D = is2D;
  19014. this._labelsBuilder = new __WEBPACK_IMPORTED_MODULE_4__component_common_LabelsBuilder__["a" /* default */](256, 256, api);
  19015. // Give a large render order.
  19016. this._labelsBuilder.getMesh().renderOrder = 100;
  19017. this.rootNode.add(this._labelsBuilder.getMesh());
  19018. this._api = api;
  19019. this._spriteImageCanvas = document.createElement('canvas');
  19020. this._startDataIndex = 0;
  19021. this._endDataIndex = 0;
  19022. this._sizeScale = 1;
  19023. }
  19024. PointsBuilder.prototype = {
  19025. constructor: PointsBuilder,
  19026. /**
  19027. * If highlight on over
  19028. */
  19029. highlightOnMouseover: true,
  19030. update: function (seriesModel, ecModel, api, start, end) {
  19031. // Swap barMesh
  19032. var tmp = this._prevMesh;
  19033. this._prevMesh = this._mesh;
  19034. this._mesh = tmp;
  19035. var data = seriesModel.getData();
  19036. if (start == null) {
  19037. start = 0;
  19038. }
  19039. if (end == null) {
  19040. end = data.count();
  19041. }
  19042. this._startDataIndex = start;
  19043. this._endDataIndex = end - 1;
  19044. if (!this._mesh) {
  19045. var material = this._prevMesh && this._prevMesh.material;
  19046. this._mesh = new __WEBPACK_IMPORTED_MODULE_3__PointsMesh__["a" /* default */]({
  19047. // Render after axes
  19048. renderOrder: 10,
  19049. // FIXME
  19050. frustumCulling: false
  19051. });
  19052. if (material) {
  19053. this._mesh.material = material;
  19054. }
  19055. }
  19056. var material = this._mesh.material;
  19057. var geometry = this._mesh.geometry;
  19058. var attributes = geometry.attributes;
  19059. this.rootNode.remove(this._prevMesh);
  19060. this.rootNode.add(this._mesh);
  19061. this._setPositionTextureToMesh(this._mesh, this._positionTexture);
  19062. var symbolInfo = this._getSymbolInfo(seriesModel, start, end);
  19063. var dpr = api.getDevicePixelRatio();
  19064. // TODO image symbol
  19065. var itemStyle = seriesModel.getModel('itemStyle').getItemStyle();
  19066. var largeMode = seriesModel.get('large');
  19067. var pointSizeScale = 1;
  19068. if (symbolInfo.maxSize > 2) {
  19069. pointSizeScale = this._updateSymbolSprite(seriesModel, itemStyle, symbolInfo, dpr);
  19070. material.enableTexture('sprite');
  19071. }
  19072. else {
  19073. material.disableTexture('sprite');
  19074. }
  19075. attributes.position.init(end - start);
  19076. var rgbaArr = [];
  19077. if (largeMode) {
  19078. material.undefine('VERTEX_SIZE');
  19079. material.undefine('VERTEX_COLOR');
  19080. var color = data.getVisual('color');
  19081. var opacity = data.getVisual('opacity');
  19082. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(color, rgbaArr);
  19083. rgbaArr[3] *= opacity;
  19084. material.set({
  19085. color: rgbaArr,
  19086. 'u_Size': symbolInfo.maxSize * this._sizeScale
  19087. });
  19088. }
  19089. else {
  19090. material.set({
  19091. color: [1, 1, 1, 1]
  19092. });
  19093. material.define('VERTEX_SIZE');
  19094. material.define('VERTEX_COLOR');
  19095. attributes.size.init(end - start);
  19096. attributes.color.init(end - start);
  19097. this._originalOpacity = new Float32Array(end - start);
  19098. }
  19099. var points = data.getLayout('points');
  19100. var positionArr = attributes.position.value;
  19101. var hasTransparentPoint = false;
  19102. for (var i = 0; i < end - start; i++) {
  19103. var i3 = i * 3;
  19104. var i2 = i * 2;
  19105. if (this.is2D) {
  19106. positionArr[i3] = points[i2];
  19107. positionArr[i3 + 1] = points[i2 + 1];
  19108. positionArr[i3 + 2] = Z_2D;
  19109. }
  19110. else {
  19111. positionArr[i3] = points[i3];
  19112. positionArr[i3 + 1] = points[i3 + 1];
  19113. positionArr[i3 + 2] = points[i3 + 2];
  19114. }
  19115. if (!largeMode) {
  19116. var color = data.getItemVisual(i, 'color');
  19117. var opacity = data.getItemVisual(i, 'opacity');
  19118. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(color, rgbaArr);
  19119. rgbaArr[3] *= opacity;
  19120. attributes.color.set(i, rgbaArr);
  19121. if (rgbaArr[3] < 0.99) {
  19122. hasTransparentPoint = true;
  19123. }
  19124. var symbolSize = data.getItemVisual(i, 'symbolSize');
  19125. symbolSize = (symbolSize instanceof Array
  19126. ? Math.max(symbolSize[0], symbolSize[1]) : symbolSize);
  19127. // NaN pointSize may have strange result.
  19128. if (isNaN(symbolSize)) {
  19129. symbolSize = 0;
  19130. }
  19131. // Scale point size because canvas has margin.
  19132. attributes.size.value[i] = symbolSize * pointSizeScale * this._sizeScale;
  19133. // Save the original opacity for recover from fadeIn.
  19134. this._originalOpacity[i] = rgbaArr[3];
  19135. }
  19136. }
  19137. this._mesh.sizeScale = pointSizeScale;
  19138. geometry.updateBoundingBox();
  19139. geometry.dirty();
  19140. // Update material.
  19141. this._updateMaterial(seriesModel, itemStyle);
  19142. var coordSys = seriesModel.coordinateSystem;
  19143. if (coordSys && coordSys.viewGL) {
  19144. var methodName = coordSys.viewGL.isLinearSpace() ? 'define' : 'undefine';
  19145. material[methodName]('fragment', 'SRGB_DECODE');
  19146. }
  19147. if (!largeMode) {
  19148. this._updateLabelBuilder(seriesModel, start, end);
  19149. }
  19150. this._updateHandler(seriesModel, ecModel, api);
  19151. this._updateAnimation(seriesModel);
  19152. this._api = api;
  19153. },
  19154. getPointsMesh: function () {
  19155. return this._mesh;
  19156. },
  19157. updateLabels: function (highlightDataIndices) {
  19158. this._labelsBuilder.updateLabels(highlightDataIndices);
  19159. },
  19160. hideLabels: function () {
  19161. this.rootNode.remove(this._labelsBuilder.getMesh());
  19162. },
  19163. showLabels: function () {
  19164. this.rootNode.add(this._labelsBuilder.getMesh());
  19165. },
  19166. _updateSymbolSprite: function (seriesModel, itemStyle, symbolInfo, dpr) {
  19167. symbolInfo.maxSize = Math.min(symbolInfo.maxSize * 2, 200);
  19168. var symbolSize = [];
  19169. if (symbolInfo.aspect > 1) {
  19170. symbolSize[0] = symbolInfo.maxSize;
  19171. symbolSize[1] = symbolInfo.maxSize / symbolInfo.aspect;
  19172. }
  19173. else {
  19174. symbolSize[1] = symbolInfo.maxSize;
  19175. symbolSize[0] = symbolInfo.maxSize * symbolInfo.aspect;
  19176. }
  19177. // In case invalid data.
  19178. symbolSize[0] = symbolSize[0] || 1;
  19179. symbolSize[1] = symbolSize[1] || 1;
  19180. if (this._symbolType !== symbolInfo.type
  19181. || !isSymbolSizeSame(this._symbolSize, symbolSize)
  19182. || this._lineWidth !== itemStyle.lineWidth
  19183. ) {
  19184. __WEBPACK_IMPORTED_MODULE_2__util_sprite__["a" /* default */].createSymbolSprite(symbolInfo.type, symbolSize, {
  19185. fill: '#fff',
  19186. lineWidth: itemStyle.lineWidth,
  19187. stroke: 'transparent',
  19188. shadowColor: 'transparent',
  19189. minMargin: Math.min(symbolSize[0] / 2, 10)
  19190. }, this._spriteImageCanvas);
  19191. __WEBPACK_IMPORTED_MODULE_2__util_sprite__["a" /* default */].createSDFFromCanvas(
  19192. this._spriteImageCanvas, Math.min(this._spriteImageCanvas.width, 32), SDF_RANGE,
  19193. this._mesh.material.get('sprite').image
  19194. );
  19195. this._symbolType = symbolInfo.type;
  19196. this._symbolSize = symbolSize;
  19197. this._lineWidth = itemStyle.lineWidth;
  19198. }
  19199. return this._spriteImageCanvas.width / symbolInfo.maxSize * dpr;
  19200. },
  19201. _updateMaterial: function (seriesModel, itemStyle) {
  19202. var blendFunc = seriesModel.get('blendMode') === 'lighter'
  19203. ? __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].additiveBlend : null;
  19204. var material = this._mesh.material;
  19205. material.blend = blendFunc;
  19206. material.set('lineWidth', itemStyle.lineWidth / SDF_RANGE);
  19207. var strokeColor = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(itemStyle.stroke);
  19208. material.set('strokeColor', strokeColor);
  19209. // Because of symbol texture, we always needs it be transparent.
  19210. material.transparent = true;
  19211. material.depthMask = false;
  19212. material.depthTest = !this.is2D;
  19213. material.sortVertices = !this.is2D;
  19214. },
  19215. _updateLabelBuilder: function (seriesModel, start, end) {
  19216. var data = seriesModel.getData();
  19217. var geometry = this._mesh.geometry;
  19218. var positionArr = geometry.attributes.position.value;
  19219. var start = this._startDataIndex;
  19220. var pointSizeScale = this._mesh.sizeScale;
  19221. this._labelsBuilder.updateData(data, start, end);
  19222. this._labelsBuilder.getLabelPosition = function (dataIndex, positionDesc, distance) {
  19223. var idx3 = (dataIndex - start) * 3;
  19224. return [positionArr[idx3], positionArr[idx3 + 1], positionArr[idx3 + 2]];
  19225. };
  19226. this._labelsBuilder.getLabelDistance = function (dataIndex, positionDesc, distance) {
  19227. var size = geometry.attributes.size.get(dataIndex - start) / pointSizeScale;
  19228. return size / 2 + distance;
  19229. };
  19230. this._labelsBuilder.updateLabels();
  19231. },
  19232. _updateAnimation: function (seriesModel) {
  19233. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].updateVertexAnimation(
  19234. [['prevPosition', 'position'],
  19235. ['prevSize', 'size']],
  19236. this._prevMesh,
  19237. this._mesh,
  19238. seriesModel
  19239. );
  19240. },
  19241. _updateHandler: function (seriesModel, ecModel, api) {
  19242. var data = seriesModel.getData();
  19243. var pointsMesh = this._mesh;
  19244. var self = this;
  19245. var lastDataIndex = -1;
  19246. var isCartesian3D = seriesModel.coordinateSystem
  19247. && seriesModel.coordinateSystem.type === 'cartesian3D';
  19248. var grid3DModel;
  19249. if (isCartesian3D) {
  19250. grid3DModel = seriesModel.coordinateSystem.model;
  19251. }
  19252. pointsMesh.seriesIndex = seriesModel.seriesIndex;
  19253. pointsMesh.off('mousemove');
  19254. pointsMesh.off('mouseout');
  19255. pointsMesh.on('mousemove', function (e) {
  19256. var dataIndex = e.vertexIndex + self._startDataIndex;
  19257. if (dataIndex !== lastDataIndex) {
  19258. if (this.highlightOnMouseover) {
  19259. this.downplay(data, lastDataIndex);
  19260. this.highlight(data, dataIndex);
  19261. this._labelsBuilder.updateLabels([dataIndex]);
  19262. }
  19263. if (isCartesian3D) {
  19264. api.dispatchAction({
  19265. type: 'grid3DShowAxisPointer',
  19266. value: [
  19267. data.get(seriesModel.coordDimToDataDim('x')[0], dataIndex),
  19268. data.get(seriesModel.coordDimToDataDim('y')[0], dataIndex),
  19269. data.get(seriesModel.coordDimToDataDim('z')[0], dataIndex)
  19270. ],
  19271. grid3DIndex: grid3DModel.componentIndex
  19272. });
  19273. }
  19274. }
  19275. pointsMesh.dataIndex = dataIndex;
  19276. lastDataIndex = dataIndex;
  19277. }, this);
  19278. pointsMesh.on('mouseout', function (e) {
  19279. var dataIndex = e.vertexIndex + self._startDataIndex;
  19280. if (this.highlightOnMouseover) {
  19281. this.downplay(data, dataIndex);
  19282. this._labelsBuilder.updateLabels();
  19283. }
  19284. lastDataIndex = -1;
  19285. pointsMesh.dataIndex = -1;
  19286. if (isCartesian3D) {
  19287. api.dispatchAction({
  19288. type: 'grid3DHideAxisPointer',
  19289. grid3DIndex: grid3DModel.componentIndex
  19290. });
  19291. }
  19292. }, this);
  19293. },
  19294. updateLayout: function (seriesModel, ecModel, api) {
  19295. var data = seriesModel.getData();
  19296. if (!this._mesh) {
  19297. return;
  19298. }
  19299. var positionArr = this._mesh.geometry.attributes.position.value;
  19300. var points = data.getLayout('points');
  19301. if (this.is2D) {
  19302. for (var i = 0; i < points.length / 2; i++) {
  19303. var i3 = i * 3;
  19304. var i2 = i * 2;
  19305. positionArr[i3] = points[i2];
  19306. positionArr[i3 + 1] = points[i2 + 1];
  19307. positionArr[i3 + 2] = Z_2D;
  19308. }
  19309. }
  19310. else {
  19311. for (var i = 0; i < points.length; i++) {
  19312. positionArr[i] = points[i];
  19313. }
  19314. }
  19315. this._mesh.geometry.dirty();
  19316. api.getZr().refresh();
  19317. },
  19318. updateView: function (camera) {
  19319. if (!this._mesh) {
  19320. return;
  19321. }
  19322. var worldViewProjection = new __WEBPACK_IMPORTED_MODULE_5_claygl_src_math_Matrix4__["a" /* default */]();
  19323. __WEBPACK_IMPORTED_MODULE_5_claygl_src_math_Matrix4__["a" /* default */].mul(worldViewProjection, camera.viewMatrix, this._mesh.worldTransform);
  19324. __WEBPACK_IMPORTED_MODULE_5_claygl_src_math_Matrix4__["a" /* default */].mul(worldViewProjection, camera.projectionMatrix, worldViewProjection);
  19325. this._mesh.updateNDCPosition(worldViewProjection, this.is2D, this._api);
  19326. },
  19327. highlight: function (data, dataIndex) {
  19328. if (dataIndex > this._endDataIndex || dataIndex < this._startDataIndex) {
  19329. return;
  19330. }
  19331. var itemModel = data.getItemModel(dataIndex);
  19332. var emphasisItemStyleModel = itemModel.getModel('emphasis.itemStyle');
  19333. var emphasisColor = emphasisItemStyleModel.get('color');
  19334. var emphasisOpacity = emphasisItemStyleModel.get('opacity');
  19335. if (emphasisColor == null) {
  19336. var color = data.getItemVisual(dataIndex, 'color');
  19337. emphasisColor = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.color.lift(color, -0.4);
  19338. }
  19339. if (emphasisOpacity == null) {
  19340. emphasisOpacity = data.getItemVisual(dataIndex, 'opacity');
  19341. }
  19342. var colorArr = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(emphasisColor);
  19343. colorArr[3] *= emphasisOpacity;
  19344. this._mesh.geometry.attributes.color.set(dataIndex - this._startDataIndex, colorArr);
  19345. this._mesh.geometry.dirtyAttribute('color');
  19346. this._api.getZr().refresh();
  19347. },
  19348. downplay: function (data, dataIndex) {
  19349. if (dataIndex > this._endDataIndex || dataIndex < this._startDataIndex) {
  19350. return;
  19351. }
  19352. var color = data.getItemVisual(dataIndex, 'color');
  19353. var opacity = data.getItemVisual(dataIndex, 'opacity');
  19354. var colorArr = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(color);
  19355. colorArr[3] *= opacity;
  19356. this._mesh.geometry.attributes.color.set(dataIndex - this._startDataIndex, colorArr);
  19357. this._mesh.geometry.dirtyAttribute('color');
  19358. this._api.getZr().refresh();
  19359. },
  19360. fadeOutAll: function (fadeOutPercent) {
  19361. if (this._originalOpacity) {
  19362. var geo = this._mesh.geometry;
  19363. for (var i = 0; i < geo.vertexCount; i++) {
  19364. var fadeOutOpacity = this._originalOpacity[i] * fadeOutPercent;
  19365. geo.attributes.color.value[i * 4 + 3] = fadeOutOpacity;
  19366. }
  19367. geo.dirtyAttribute('color');
  19368. this._api.getZr().refresh();
  19369. }
  19370. },
  19371. fadeInAll: function () {
  19372. this.fadeOutAll(1);
  19373. },
  19374. setPositionTexture: function (texture) {
  19375. if (this._mesh) {
  19376. this._setPositionTextureToMesh(this._mesh, texture);
  19377. }
  19378. this._positionTexture = texture;
  19379. },
  19380. removePositionTexture: function () {
  19381. this._positionTexture = null;
  19382. if (this._mesh) {
  19383. this._setPositionTextureToMesh(this._mesh, null);
  19384. }
  19385. },
  19386. setSizeScale: function (sizeScale) {
  19387. if (sizeScale !== this._sizeScale) {
  19388. if (this._mesh) {
  19389. var originalSize = this._mesh.material.get('u_Size');
  19390. this._mesh.material.set('u_Size', originalSize / this._sizeScale * sizeScale);
  19391. var attributes = this._mesh.geometry.attributes;
  19392. if (attributes.size.value) {
  19393. for (var i = 0; i < attributes.size.value.length; i++) {
  19394. attributes.size.value[i] = attributes.size.value[i] / this._sizeScale * sizeScale;
  19395. }
  19396. }
  19397. }
  19398. this._sizeScale = sizeScale;
  19399. }
  19400. },
  19401. _setPositionTextureToMesh: function (mesh, texture) {
  19402. if (texture) {
  19403. mesh.material.set('positionTexture', texture);
  19404. }
  19405. mesh.material[
  19406. texture ? 'enableTexture' : 'disableTexture'
  19407. ]('positionTexture');
  19408. },
  19409. _getSymbolInfo: function (seriesModel, start, end) {
  19410. if (seriesModel.get('large')) {
  19411. var symbolSize = __WEBPACK_IMPORTED_MODULE_6__util_retrieve__["a" /* default */].firstNotNull(seriesModel.get('symbolSize'), 1);
  19412. var maxSymbolSize;
  19413. var symbolAspect;
  19414. if (symbolSize instanceof Array) {
  19415. maxSymbolSize = Math.max(symbolSize[0], symbolSize[1]);
  19416. symbolAspect = symbolSize[0] / symbolSize[1];
  19417. }
  19418. else {
  19419. maxSymbolSize = symbolSize;
  19420. symbolAspect = 1;
  19421. }
  19422. return {
  19423. maxSize: symbolSize,
  19424. type: seriesModel.get('symbol'),
  19425. aspect: symbolAspect
  19426. }
  19427. }
  19428. var data = seriesModel.getData();
  19429. var symbolAspect;
  19430. var differentSymbolAspect = false;
  19431. var symbolType = data.getItemVisual(0, 'symbol') || 'circle';
  19432. var differentSymbolType = false;
  19433. var maxSymbolSize = 0;
  19434. for (var idx = start; idx < end; idx++) {
  19435. var symbolSize = data.getItemVisual(idx, 'symbolSize');
  19436. var currentSymbolType = data.getItemVisual(idx, 'symbol');
  19437. var currentSymbolAspect;
  19438. if (!(symbolSize instanceof Array)) {
  19439. // Ignore NaN value.
  19440. if (isNaN(symbolSize)) {
  19441. return;
  19442. }
  19443. currentSymbolAspect = 1;
  19444. maxSymbolSize = Math.max(symbolSize, maxSymbolSize);
  19445. }
  19446. else {
  19447. currentSymbolAspect = symbolSize[0] / symbolSize[1];
  19448. maxSymbolSize = Math.max(Math.max(symbolSize[0], symbolSize[1]), maxSymbolSize);
  19449. }
  19450. if (true) {
  19451. if (symbolAspect != null && Math.abs(currentSymbolAspect - symbolAspect) > 0.05) {
  19452. differentSymbolAspect = true;
  19453. }
  19454. if (currentSymbolType !== symbolType) {
  19455. differentSymbolType = true;
  19456. }
  19457. }
  19458. symbolType = currentSymbolType;
  19459. symbolAspect = currentSymbolAspect;
  19460. }
  19461. if (true) {
  19462. if (differentSymbolAspect) {
  19463. console.warn('Different symbol width / height ratio will be ignored.');
  19464. }
  19465. if (differentSymbolType) {
  19466. console.warn('Different symbol type will be ignored.');
  19467. }
  19468. }
  19469. return {
  19470. maxSize: maxSymbolSize,
  19471. type: symbolType,
  19472. aspect: symbolAspect
  19473. };
  19474. }
  19475. };
  19476. /* harmony default export */ __webpack_exports__["a"] = (PointsBuilder);
  19477. /***/
  19478. }),
  19479. /* 68 */
  19480. /***/ (function (module, exports) {
  19481. var g;
  19482. // This works in non-strict mode
  19483. g = (function () {
  19484. return this;
  19485. })();
  19486. try {
  19487. // This works if eval is allowed (see CSP)
  19488. g = g || Function("return this")() || (1, eval)("this");
  19489. } catch (e) {
  19490. // This works if the window reference is available
  19491. if (typeof window === "object")
  19492. g = window;
  19493. }
  19494. // g can still be undefined, but nothing to do about it...
  19495. // We return undefined, instead of nothing here, so it's
  19496. // easier to handle this case. if(!global) { ...}
  19497. module.exports = g;
  19498. /***/
  19499. }),
  19500. /* 69 */
  19501. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  19502. "use strict";
  19503. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__LinkedList__ = __webpack_require__(114);
  19504. /**
  19505. * LRU Cache
  19506. * @constructor
  19507. * @alias clay.core.LRU
  19508. */
  19509. var LRU = function (maxSize) {
  19510. this._list = new __WEBPACK_IMPORTED_MODULE_0__LinkedList__["a" /* default */]();
  19511. this._map = {};
  19512. this._maxSize = maxSize || 10;
  19513. };
  19514. /**
  19515. * Set cache max size
  19516. * @param {number} size
  19517. */
  19518. LRU.prototype.setMaxSize = function (size) {
  19519. this._maxSize = size;
  19520. };
  19521. /**
  19522. * @param {string} key
  19523. * @param {} value
  19524. */
  19525. LRU.prototype.put = function (key, value) {
  19526. if (!this._map.hasOwnProperty(key)) {
  19527. var len = this._list.length();
  19528. if (len >= this._maxSize && len > 0) {
  19529. // Remove the least recently used
  19530. var leastUsedEntry = this._list.head;
  19531. this._list.remove(leastUsedEntry);
  19532. delete this._map[leastUsedEntry.key];
  19533. }
  19534. var entry = this._list.insert(value);
  19535. entry.key = key;
  19536. this._map[key] = entry;
  19537. }
  19538. };
  19539. /**
  19540. * @param {string} key
  19541. * @return {}
  19542. */
  19543. LRU.prototype.get = function (key) {
  19544. var entry = this._map[key];
  19545. if (this._map.hasOwnProperty(key)) {
  19546. // Put the latest used entry in the tail
  19547. if (entry !== this._list.tail) {
  19548. this._list.remove(entry);
  19549. this._list.insertEntry(entry);
  19550. }
  19551. return entry.value;
  19552. }
  19553. };
  19554. /**
  19555. * @param {string} key
  19556. */
  19557. LRU.prototype.remove = function (key) {
  19558. var entry = this._map[key];
  19559. if (typeof (entry) !== 'undefined') {
  19560. delete this._map[key];
  19561. this._list.remove(entry);
  19562. }
  19563. };
  19564. /**
  19565. * Clear the cache
  19566. */
  19567. LRU.prototype.clear = function () {
  19568. this._list.clear();
  19569. this._map = {};
  19570. };
  19571. /* harmony default export */ __webpack_exports__["a"] = (LRU);
  19572. /***/
  19573. }),
  19574. /* 70 */
  19575. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  19576. "use strict";
  19577. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__common__ = __webpack_require__(20);
  19578. /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
  19579. Redistribution and use in source and binary forms, with or without modification,
  19580. are permitted provided that the following conditions are met:
  19581. * Redistributions of source code must retain the above copyright notice, this
  19582. list of conditions and the following disclaimer.
  19583. * Redistributions in binary form must reproduce the above copyright notice,
  19584. this list of conditions and the following disclaimer in the documentation
  19585. and/or other materials provided with the distribution.
  19586. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19587. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19588. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19589. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  19590. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19591. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19592. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  19593. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  19594. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19595. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
  19596. /**
  19597. * @class 2 Dimensional Vector
  19598. * @name vec2
  19599. */
  19600. var vec2 = {};
  19601. /**
  19602. * Creates a new, empty vec2
  19603. *
  19604. * @returns {vec2} a new 2D vector
  19605. */
  19606. vec2.create = function () {
  19607. var out = new __WEBPACK_IMPORTED_MODULE_0__common__["a" /* GLMAT_ARRAY_TYPE */](2);
  19608. out[0] = 0;
  19609. out[1] = 0;
  19610. return out;
  19611. };
  19612. /**
  19613. * Creates a new vec2 initialized with values from an existing vector
  19614. *
  19615. * @param {vec2} a vector to clone
  19616. * @returns {vec2} a new 2D vector
  19617. */
  19618. vec2.clone = function (a) {
  19619. var out = new __WEBPACK_IMPORTED_MODULE_0__common__["a" /* GLMAT_ARRAY_TYPE */](2);
  19620. out[0] = a[0];
  19621. out[1] = a[1];
  19622. return out;
  19623. };
  19624. /**
  19625. * Creates a new vec2 initialized with the given values
  19626. *
  19627. * @param {Number} x X component
  19628. * @param {Number} y Y component
  19629. * @returns {vec2} a new 2D vector
  19630. */
  19631. vec2.fromValues = function (x, y) {
  19632. var out = new __WEBPACK_IMPORTED_MODULE_0__common__["a" /* GLMAT_ARRAY_TYPE */](2);
  19633. out[0] = x;
  19634. out[1] = y;
  19635. return out;
  19636. };
  19637. /**
  19638. * Copy the values from one vec2 to another
  19639. *
  19640. * @param {vec2} out the receiving vector
  19641. * @param {vec2} a the source vector
  19642. * @returns {vec2} out
  19643. */
  19644. vec2.copy = function (out, a) {
  19645. out[0] = a[0];
  19646. out[1] = a[1];
  19647. return out;
  19648. };
  19649. /**
  19650. * Set the components of a vec2 to the given values
  19651. *
  19652. * @param {vec2} out the receiving vector
  19653. * @param {Number} x X component
  19654. * @param {Number} y Y component
  19655. * @returns {vec2} out
  19656. */
  19657. vec2.set = function (out, x, y) {
  19658. out[0] = x;
  19659. out[1] = y;
  19660. return out;
  19661. };
  19662. /**
  19663. * Adds two vec2's
  19664. *
  19665. * @param {vec2} out the receiving vector
  19666. * @param {vec2} a the first operand
  19667. * @param {vec2} b the second operand
  19668. * @returns {vec2} out
  19669. */
  19670. vec2.add = function (out, a, b) {
  19671. out[0] = a[0] + b[0];
  19672. out[1] = a[1] + b[1];
  19673. return out;
  19674. };
  19675. /**
  19676. * Subtracts vector b from vector a
  19677. *
  19678. * @param {vec2} out the receiving vector
  19679. * @param {vec2} a the first operand
  19680. * @param {vec2} b the second operand
  19681. * @returns {vec2} out
  19682. */
  19683. vec2.subtract = function (out, a, b) {
  19684. out[0] = a[0] - b[0];
  19685. out[1] = a[1] - b[1];
  19686. return out;
  19687. };
  19688. /**
  19689. * Alias for {@link vec2.subtract}
  19690. * @function
  19691. */
  19692. vec2.sub = vec2.subtract;
  19693. /**
  19694. * Multiplies two vec2's
  19695. *
  19696. * @param {vec2} out the receiving vector
  19697. * @param {vec2} a the first operand
  19698. * @param {vec2} b the second operand
  19699. * @returns {vec2} out
  19700. */
  19701. vec2.multiply = function (out, a, b) {
  19702. out[0] = a[0] * b[0];
  19703. out[1] = a[1] * b[1];
  19704. return out;
  19705. };
  19706. /**
  19707. * Alias for {@link vec2.multiply}
  19708. * @function
  19709. */
  19710. vec2.mul = vec2.multiply;
  19711. /**
  19712. * Divides two vec2's
  19713. *
  19714. * @param {vec2} out the receiving vector
  19715. * @param {vec2} a the first operand
  19716. * @param {vec2} b the second operand
  19717. * @returns {vec2} out
  19718. */
  19719. vec2.divide = function (out, a, b) {
  19720. out[0] = a[0] / b[0];
  19721. out[1] = a[1] / b[1];
  19722. return out;
  19723. };
  19724. /**
  19725. * Alias for {@link vec2.divide}
  19726. * @function
  19727. */
  19728. vec2.div = vec2.divide;
  19729. /**
  19730. * Returns the minimum of two vec2's
  19731. *
  19732. * @param {vec2} out the receiving vector
  19733. * @param {vec2} a the first operand
  19734. * @param {vec2} b the second operand
  19735. * @returns {vec2} out
  19736. */
  19737. vec2.min = function (out, a, b) {
  19738. out[0] = Math.min(a[0], b[0]);
  19739. out[1] = Math.min(a[1], b[1]);
  19740. return out;
  19741. };
  19742. /**
  19743. * Returns the maximum of two vec2's
  19744. *
  19745. * @param {vec2} out the receiving vector
  19746. * @param {vec2} a the first operand
  19747. * @param {vec2} b the second operand
  19748. * @returns {vec2} out
  19749. */
  19750. vec2.max = function (out, a, b) {
  19751. out[0] = Math.max(a[0], b[0]);
  19752. out[1] = Math.max(a[1], b[1]);
  19753. return out;
  19754. };
  19755. /**
  19756. * Scales a vec2 by a scalar number
  19757. *
  19758. * @param {vec2} out the receiving vector
  19759. * @param {vec2} a the vector to scale
  19760. * @param {Number} b amount to scale the vector by
  19761. * @returns {vec2} out
  19762. */
  19763. vec2.scale = function (out, a, b) {
  19764. out[0] = a[0] * b;
  19765. out[1] = a[1] * b;
  19766. return out;
  19767. };
  19768. /**
  19769. * Adds two vec2's after scaling the second operand by a scalar value
  19770. *
  19771. * @param {vec2} out the receiving vector
  19772. * @param {vec2} a the first operand
  19773. * @param {vec2} b the second operand
  19774. * @param {Number} scale the amount to scale b by before adding
  19775. * @returns {vec2} out
  19776. */
  19777. vec2.scaleAndAdd = function (out, a, b, scale) {
  19778. out[0] = a[0] + (b[0] * scale);
  19779. out[1] = a[1] + (b[1] * scale);
  19780. return out;
  19781. };
  19782. /**
  19783. * Calculates the euclidian distance between two vec2's
  19784. *
  19785. * @param {vec2} a the first operand
  19786. * @param {vec2} b the second operand
  19787. * @returns {Number} distance between a and b
  19788. */
  19789. vec2.distance = function (a, b) {
  19790. var x = b[0] - a[0],
  19791. y = b[1] - a[1];
  19792. return Math.sqrt(x * x + y * y);
  19793. };
  19794. /**
  19795. * Alias for {@link vec2.distance}
  19796. * @function
  19797. */
  19798. vec2.dist = vec2.distance;
  19799. /**
  19800. * Calculates the squared euclidian distance between two vec2's
  19801. *
  19802. * @param {vec2} a the first operand
  19803. * @param {vec2} b the second operand
  19804. * @returns {Number} squared distance between a and b
  19805. */
  19806. vec2.squaredDistance = function (a, b) {
  19807. var x = b[0] - a[0],
  19808. y = b[1] - a[1];
  19809. return x * x + y * y;
  19810. };
  19811. /**
  19812. * Alias for {@link vec2.squaredDistance}
  19813. * @function
  19814. */
  19815. vec2.sqrDist = vec2.squaredDistance;
  19816. /**
  19817. * Calculates the length of a vec2
  19818. *
  19819. * @param {vec2} a vector to calculate length of
  19820. * @returns {Number} length of a
  19821. */
  19822. vec2.length = function (a) {
  19823. var x = a[0],
  19824. y = a[1];
  19825. return Math.sqrt(x * x + y * y);
  19826. };
  19827. /**
  19828. * Alias for {@link vec2.length}
  19829. * @function
  19830. */
  19831. vec2.len = vec2.length;
  19832. /**
  19833. * Calculates the squared length of a vec2
  19834. *
  19835. * @param {vec2} a vector to calculate squared length of
  19836. * @returns {Number} squared length of a
  19837. */
  19838. vec2.squaredLength = function (a) {
  19839. var x = a[0],
  19840. y = a[1];
  19841. return x * x + y * y;
  19842. };
  19843. /**
  19844. * Alias for {@link vec2.squaredLength}
  19845. * @function
  19846. */
  19847. vec2.sqrLen = vec2.squaredLength;
  19848. /**
  19849. * Negates the components of a vec2
  19850. *
  19851. * @param {vec2} out the receiving vector
  19852. * @param {vec2} a vector to negate
  19853. * @returns {vec2} out
  19854. */
  19855. vec2.negate = function (out, a) {
  19856. out[0] = -a[0];
  19857. out[1] = -a[1];
  19858. return out;
  19859. };
  19860. /**
  19861. * Returns the inverse of the components of a vec2
  19862. *
  19863. * @param {vec2} out the receiving vector
  19864. * @param {vec2} a vector to invert
  19865. * @returns {vec2} out
  19866. */
  19867. vec2.inverse = function (out, a) {
  19868. out[0] = 1.0 / a[0];
  19869. out[1] = 1.0 / a[1];
  19870. return out;
  19871. };
  19872. /**
  19873. * Normalize a vec2
  19874. *
  19875. * @param {vec2} out the receiving vector
  19876. * @param {vec2} a vector to normalize
  19877. * @returns {vec2} out
  19878. */
  19879. vec2.normalize = function (out, a) {
  19880. var x = a[0],
  19881. y = a[1];
  19882. var len = x * x + y * y;
  19883. if (len > 0) {
  19884. //TODO: evaluate use of glm_invsqrt here?
  19885. len = 1 / Math.sqrt(len);
  19886. out[0] = a[0] * len;
  19887. out[1] = a[1] * len;
  19888. }
  19889. return out;
  19890. };
  19891. /**
  19892. * Calculates the dot product of two vec2's
  19893. *
  19894. * @param {vec2} a the first operand
  19895. * @param {vec2} b the second operand
  19896. * @returns {Number} dot product of a and b
  19897. */
  19898. vec2.dot = function (a, b) {
  19899. return a[0] * b[0] + a[1] * b[1];
  19900. };
  19901. /**
  19902. * Computes the cross product of two vec2's
  19903. * Note that the cross product must by definition produce a 3D vector
  19904. *
  19905. * @param {vec3} out the receiving vector
  19906. * @param {vec2} a the first operand
  19907. * @param {vec2} b the second operand
  19908. * @returns {vec3} out
  19909. */
  19910. vec2.cross = function (out, a, b) {
  19911. var z = a[0] * b[1] - a[1] * b[0];
  19912. out[0] = out[1] = 0;
  19913. out[2] = z;
  19914. return out;
  19915. };
  19916. /**
  19917. * Performs a linear interpolation between two vec2's
  19918. *
  19919. * @param {vec2} out the receiving vector
  19920. * @param {vec2} a the first operand
  19921. * @param {vec2} b the second operand
  19922. * @param {Number} t interpolation amount between the two inputs
  19923. * @returns {vec2} out
  19924. */
  19925. vec2.lerp = function (out, a, b, t) {
  19926. var ax = a[0],
  19927. ay = a[1];
  19928. out[0] = ax + t * (b[0] - ax);
  19929. out[1] = ay + t * (b[1] - ay);
  19930. return out;
  19931. };
  19932. /**
  19933. * Generates a random vector with the given scale
  19934. *
  19935. * @param {vec2} out the receiving vector
  19936. * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned
  19937. * @returns {vec2} out
  19938. */
  19939. vec2.random = function (out, scale) {
  19940. scale = scale || 1.0;
  19941. var r = GLMAT_RANDOM() * 2.0 * Math.PI;
  19942. out[0] = Math.cos(r) * scale;
  19943. out[1] = Math.sin(r) * scale;
  19944. return out;
  19945. };
  19946. /**
  19947. * Transforms the vec2 with a mat2
  19948. *
  19949. * @param {vec2} out the receiving vector
  19950. * @param {vec2} a the vector to transform
  19951. * @param {mat2} m matrix to transform with
  19952. * @returns {vec2} out
  19953. */
  19954. vec2.transformMat2 = function (out, a, m) {
  19955. var x = a[0],
  19956. y = a[1];
  19957. out[0] = m[0] * x + m[2] * y;
  19958. out[1] = m[1] * x + m[3] * y;
  19959. return out;
  19960. };
  19961. /**
  19962. * Transforms the vec2 with a mat2d
  19963. *
  19964. * @param {vec2} out the receiving vector
  19965. * @param {vec2} a the vector to transform
  19966. * @param {mat2d} m matrix to transform with
  19967. * @returns {vec2} out
  19968. */
  19969. vec2.transformMat2d = function (out, a, m) {
  19970. var x = a[0],
  19971. y = a[1];
  19972. out[0] = m[0] * x + m[2] * y + m[4];
  19973. out[1] = m[1] * x + m[3] * y + m[5];
  19974. return out;
  19975. };
  19976. /**
  19977. * Transforms the vec2 with a mat3
  19978. * 3rd vector component is implicitly '1'
  19979. *
  19980. * @param {vec2} out the receiving vector
  19981. * @param {vec2} a the vector to transform
  19982. * @param {mat3} m matrix to transform with
  19983. * @returns {vec2} out
  19984. */
  19985. vec2.transformMat3 = function (out, a, m) {
  19986. var x = a[0],
  19987. y = a[1];
  19988. out[0] = m[0] * x + m[3] * y + m[6];
  19989. out[1] = m[1] * x + m[4] * y + m[7];
  19990. return out;
  19991. };
  19992. /**
  19993. * Transforms the vec2 with a mat4
  19994. * 3rd vector component is implicitly '0'
  19995. * 4th vector component is implicitly '1'
  19996. *
  19997. * @param {vec2} out the receiving vector
  19998. * @param {vec2} a the vector to transform
  19999. * @param {mat4} m matrix to transform with
  20000. * @returns {vec2} out
  20001. */
  20002. vec2.transformMat4 = function (out, a, m) {
  20003. var x = a[0],
  20004. y = a[1];
  20005. out[0] = m[0] * x + m[4] * y + m[12];
  20006. out[1] = m[1] * x + m[5] * y + m[13];
  20007. return out;
  20008. };
  20009. /**
  20010. * Perform some operation over an array of vec2s.
  20011. *
  20012. * @param {Array} a the array of vectors to iterate over
  20013. * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed
  20014. * @param {Number} offset Number of elements to skip at the beginning of the array
  20015. * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array
  20016. * @param {Function} fn Function to call for each vector in the array
  20017. * @param {Object} [arg] additional argument to pass to fn
  20018. * @returns {Array} a
  20019. * @function
  20020. */
  20021. vec2.forEach = (function () {
  20022. var vec = vec2.create();
  20023. return function (a, stride, offset, count, fn, arg) {
  20024. var i, l;
  20025. if (!stride) {
  20026. stride = 2;
  20027. }
  20028. if (!offset) {
  20029. offset = 0;
  20030. }
  20031. if (count) {
  20032. l = Math.min((count * stride) + offset, a.length);
  20033. } else {
  20034. l = a.length;
  20035. }
  20036. for (i = offset; i < l; i += stride) {
  20037. vec[0] = a[i]; vec[1] = a[i + 1];
  20038. fn(vec, vec, arg);
  20039. a[i] = vec[0]; a[i + 1] = vec[1];
  20040. }
  20041. return a;
  20042. };
  20043. })();
  20044. /* harmony default export */ __webpack_exports__["a"] = (vec2);
  20045. /***/
  20046. }),
  20047. /* 71 */
  20048. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  20049. "use strict";
  20050. /* harmony default export */ __webpack_exports__["a"] = ("@export clay.prez.vertex\nuniform mat4 WVP : WORLDVIEWPROJECTION;\nattribute vec3 pos : POSITION;\nattribute vec2 uv : TEXCOORD_0;\n@import clay.chunk.skinning_header\nvarying vec2 v_Texcoord;\nvoid main()\n{\n vec3 P = pos;\n#ifdef SKINNING\n @import clay.chunk.skin_matrix\n P = (skinMatrixWS * vec4(pos, 1.0)).xyz;\n#endif\n gl_Position = WVP * vec4(P, 1.0);\n v_Texcoord = uv;\n}\n@end\n@export clay.prez.fragment\nuniform sampler2D alphaMap;\nuniform float alphaCutoff: 0.0;\nvarying vec2 v_Texcoord;\nvoid main()\n{\n if (alphaCutoff > 0.0) {\n if (texture2D(alphaMap, v_Texcoord).a <= alphaCutoff) {\n discard;\n }\n }\n gl_FragColor = vec4(0.0,0.0,0.0,1.0);\n}\n@end");
  20051. /***/
  20052. }),
  20053. /* 72 */
  20054. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  20055. "use strict";
  20056. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Node__ = __webpack_require__(35);
  20057. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__core_glenum__ = __webpack_require__(11);
  20058. /**
  20059. * @constructor
  20060. * @alias clay.Renderable
  20061. * @extends clay.Node
  20062. */
  20063. var Renderable = __WEBPACK_IMPORTED_MODULE_0__Node__["a" /* default */].extend(/** @lends clay.Renderable# */ {
  20064. /**
  20065. * @type {clay.Material}
  20066. */
  20067. material: null,
  20068. /**
  20069. * @type {clay.Geometry}
  20070. */
  20071. geometry: null,
  20072. /**
  20073. * @type {number}
  20074. */
  20075. mode: __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].TRIANGLES,
  20076. _renderInfo: null
  20077. },
  20078. /** @lends clay.Renderable.prototype */
  20079. {
  20080. __program: null,
  20081. /**
  20082. * Group of received light.
  20083. */
  20084. lightGroup: 0,
  20085. /**
  20086. * Render order, Nodes with smaller value renders before nodes with larger values.
  20087. * @type {Number}
  20088. */
  20089. renderOrder: 0,
  20090. /**
  20091. * Used when mode is LINES, LINE_STRIP or LINE_LOOP
  20092. * @type {number}
  20093. */
  20094. // lineWidth: 1,
  20095. /**
  20096. * If enable culling
  20097. * @type {boolean}
  20098. */
  20099. culling: true,
  20100. /**
  20101. * Specify which side of polygon will be culled.
  20102. * Possible values:
  20103. * + {@link clay.Renderable.BACK}
  20104. * + {@link clay.Renderable.FRONT}
  20105. * + {@link clay.Renderable.FRONT_AND_BACK}
  20106. * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/cullFace
  20107. * @type {number}
  20108. */
  20109. cullFace: __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].BACK,
  20110. /**
  20111. * Specify which side is front face.
  20112. * Possible values:
  20113. * + {@link clay.Renderable.CW}
  20114. * + {@link clay.Renderable.CCW}
  20115. * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/frontFace
  20116. * @type {number}
  20117. */
  20118. frontFace: __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].CCW,
  20119. /**
  20120. * If enable software frustum culling
  20121. * @type {boolean}
  20122. */
  20123. frustumCulling: true,
  20124. /**
  20125. * @type {boolean}
  20126. */
  20127. receiveShadow: true,
  20128. /**
  20129. * @type {boolean}
  20130. */
  20131. castShadow: true,
  20132. /**
  20133. * @type {boolean}
  20134. */
  20135. ignorePicking: false,
  20136. /**
  20137. * @type {boolean}
  20138. */
  20139. ignorePreZ: false,
  20140. /**
  20141. * @type {boolean}
  20142. */
  20143. ignoreGBuffer: false,
  20144. /**
  20145. * @return {boolean}
  20146. */
  20147. isRenderable: function () {
  20148. // TODO Shader ?
  20149. return this.geometry && this.material && this.material.shader && !this.invisible
  20150. && this.geometry.vertexCount > 0;
  20151. },
  20152. /**
  20153. * Before render hook
  20154. * @type {Function}
  20155. */
  20156. beforeRender: function (_gl) { },
  20157. /**
  20158. * Before render hook
  20159. * @type {Function}
  20160. */
  20161. afterRender: function (_gl, renderStat) { },
  20162. getBoundingBox: function (filter, out) {
  20163. out = __WEBPACK_IMPORTED_MODULE_0__Node__["a" /* default */].prototype.getBoundingBox.call(this, filter, out);
  20164. if (this.geometry && this.geometry.boundingBox) {
  20165. out.union(this.geometry.boundingBox);
  20166. }
  20167. return out;
  20168. },
  20169. /**
  20170. * Clone a new renderable
  20171. * @function
  20172. * @return {clay.Renderable}
  20173. */
  20174. clone: (function () {
  20175. var properties = [
  20176. 'castShadow', 'receiveShadow',
  20177. 'mode', 'culling', 'cullFace', 'frontFace',
  20178. 'frustumCulling',
  20179. 'renderOrder', 'lineWidth',
  20180. 'ignorePicking', 'ignorePreZ', 'ignoreGBuffer'
  20181. ];
  20182. return function () {
  20183. var renderable = __WEBPACK_IMPORTED_MODULE_0__Node__["a" /* default */].prototype.clone.call(this);
  20184. renderable.geometry = this.geometry;
  20185. renderable.material = this.material;
  20186. for (var i = 0; i < properties.length; i++) {
  20187. var name = properties[i];
  20188. // Try not to overwrite the prototype property
  20189. if (renderable[name] !== this[name]) {
  20190. renderable[name] = this[name];
  20191. }
  20192. }
  20193. return renderable;
  20194. };
  20195. })()
  20196. });
  20197. /**
  20198. * @type {number}
  20199. */
  20200. Renderable.POINTS = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].POINTS;
  20201. /**
  20202. * @type {number}
  20203. */
  20204. Renderable.LINES = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LINES;
  20205. /**
  20206. * @type {number}
  20207. */
  20208. Renderable.LINE_LOOP = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LINE_LOOP;
  20209. /**
  20210. * @type {number}
  20211. */
  20212. Renderable.LINE_STRIP = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LINE_STRIP;
  20213. /**
  20214. * @type {number}
  20215. */
  20216. Renderable.TRIANGLES = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].TRIANGLES;
  20217. /**
  20218. * @type {number}
  20219. */
  20220. Renderable.TRIANGLE_STRIP = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].TRIANGLE_STRIP;
  20221. /**
  20222. * @type {number}
  20223. */
  20224. Renderable.TRIANGLE_FAN = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].TRIANGLE_FAN;
  20225. /**
  20226. * @type {number}
  20227. */
  20228. Renderable.BACK = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].BACK;
  20229. /**
  20230. * @type {number}
  20231. */
  20232. Renderable.FRONT = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].FRONT;
  20233. /**
  20234. * @type {number}
  20235. */
  20236. Renderable.FRONT_AND_BACK = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].FRONT_AND_BACK;
  20237. /**
  20238. * @type {number}
  20239. */
  20240. Renderable.CW = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].CW;
  20241. /**
  20242. * @type {number}
  20243. */
  20244. Renderable.CCW = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].CCW;
  20245. /* harmony default export */ __webpack_exports__["a"] = (Renderable);
  20246. /***/
  20247. }),
  20248. /* 73 */
  20249. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  20250. "use strict";
  20251. var mathUtil = {};
  20252. mathUtil.isPowerOfTwo = function (value) {
  20253. return (value & (value - 1)) === 0;
  20254. };
  20255. mathUtil.nextPowerOfTwo = function (value) {
  20256. value--;
  20257. value |= value >> 1;
  20258. value |= value >> 2;
  20259. value |= value >> 4;
  20260. value |= value >> 8;
  20261. value |= value >> 16;
  20262. value++;
  20263. return value;
  20264. };
  20265. mathUtil.nearestPowerOfTwo = function (value) {
  20266. return Math.pow(2, Math.round(Math.log(value) / Math.LN2));
  20267. };
  20268. /* harmony default export */ __webpack_exports__["a"] = (mathUtil);
  20269. /***/
  20270. }),
  20271. /* 74 */
  20272. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  20273. "use strict";
  20274. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Vector3__ = __webpack_require__(3);
  20275. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__glmatrix_mat4__ = __webpack_require__(21);
  20276. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__ = __webpack_require__(12);
  20277. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__glmatrix_vec4__ = __webpack_require__(33);
  20278. /**
  20279. * @constructor
  20280. * @alias clay.Plane
  20281. * @param {clay.Vector3} [normal]
  20282. * @param {number} [distance]
  20283. */
  20284. var Plane = function (normal, distance) {
  20285. /**
  20286. * Normal of the plane
  20287. * @type {clay.Vector3}
  20288. */
  20289. this.normal = normal || new __WEBPACK_IMPORTED_MODULE_0__Vector3__["a" /* default */](0, 1, 0);
  20290. /**
  20291. * Constant of the plane equation, used as distance to the origin
  20292. * @type {number}
  20293. */
  20294. this.distance = distance || 0;
  20295. };
  20296. Plane.prototype = {
  20297. constructor: Plane,
  20298. /**
  20299. * Distance from a given point to the plane
  20300. * @param {clay.Vector3} point
  20301. * @return {number}
  20302. */
  20303. distanceToPoint: function (point) {
  20304. return __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].dot(point.array, this.normal.array) - this.distance;
  20305. },
  20306. /**
  20307. * Calculate the projection point on the plane
  20308. * @param {clay.Vector3} point
  20309. * @param {clay.Vector3} out
  20310. * @return {clay.Vector3}
  20311. */
  20312. projectPoint: function (point, out) {
  20313. if (!out) {
  20314. out = new __WEBPACK_IMPORTED_MODULE_0__Vector3__["a" /* default */]();
  20315. }
  20316. var d = this.distanceToPoint(point);
  20317. __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].scaleAndAdd(out.array, point.array, this.normal.array, -d);
  20318. out._dirty = true;
  20319. return out;
  20320. },
  20321. /**
  20322. * Normalize the plane's normal and calculate the distance
  20323. */
  20324. normalize: function () {
  20325. var invLen = 1 / __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].len(this.normal.array);
  20326. __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].scale(this.normal.array, invLen);
  20327. this.distance *= invLen;
  20328. },
  20329. /**
  20330. * If the plane intersect a frustum
  20331. * @param {clay.Frustum} Frustum
  20332. * @return {boolean}
  20333. */
  20334. intersectFrustum: function (frustum) {
  20335. // Check if all coords of frustum is on plane all under plane
  20336. var coords = frustum.vertices;
  20337. var normal = this.normal.array;
  20338. var onPlane = __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].dot(coords[0].array, normal) > this.distance;
  20339. for (var i = 1; i < 8; i++) {
  20340. if ((__WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].dot(coords[i].array, normal) > this.distance) != onPlane) {
  20341. return true;
  20342. }
  20343. }
  20344. },
  20345. /**
  20346. * Calculate the intersection point between plane and a given line
  20347. * @function
  20348. * @param {clay.Vector3} start start point of line
  20349. * @param {clay.Vector3} end end point of line
  20350. * @param {clay.Vector3} [out]
  20351. * @return {clay.Vector3}
  20352. */
  20353. intersectLine: (function () {
  20354. var rd = __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].create();
  20355. return function (start, end, out) {
  20356. var d0 = this.distanceToPoint(start);
  20357. var d1 = this.distanceToPoint(end);
  20358. if ((d0 > 0 && d1 > 0) || (d0 < 0 && d1 < 0)) {
  20359. return null;
  20360. }
  20361. // Ray intersection
  20362. var pn = this.normal.array;
  20363. var d = this.distance;
  20364. var ro = start.array;
  20365. // direction
  20366. __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].sub(rd, end.array, start.array);
  20367. __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].normalize(rd, rd);
  20368. var divider = __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].dot(pn, rd);
  20369. // ray is parallel to the plane
  20370. if (divider === 0) {
  20371. return null;
  20372. }
  20373. if (!out) {
  20374. out = new __WEBPACK_IMPORTED_MODULE_0__Vector3__["a" /* default */]();
  20375. }
  20376. var t = (__WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].dot(pn, ro) - d) / divider;
  20377. __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].scaleAndAdd(out.array, ro, rd, -t);
  20378. out._dirty = true;
  20379. return out;
  20380. };
  20381. })(),
  20382. /**
  20383. * Apply an affine transform matrix to plane
  20384. * @function
  20385. * @return {clay.Matrix4}
  20386. */
  20387. applyTransform: (function () {
  20388. var inverseTranspose = __WEBPACK_IMPORTED_MODULE_1__glmatrix_mat4__["a" /* default */].create();
  20389. var normalv4 = __WEBPACK_IMPORTED_MODULE_3__glmatrix_vec4__["a" /* default */].create();
  20390. var pointv4 = __WEBPACK_IMPORTED_MODULE_3__glmatrix_vec4__["a" /* default */].create();
  20391. pointv4[3] = 1;
  20392. return function (m4) {
  20393. m4 = m4.array;
  20394. // Transform point on plane
  20395. __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].scale(pointv4, this.normal.array, this.distance);
  20396. __WEBPACK_IMPORTED_MODULE_3__glmatrix_vec4__["a" /* default */].transformMat4(pointv4, pointv4, m4);
  20397. this.distance = __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].dot(pointv4, this.normal.array);
  20398. // Transform plane normal
  20399. __WEBPACK_IMPORTED_MODULE_1__glmatrix_mat4__["a" /* default */].invert(inverseTranspose, m4);
  20400. __WEBPACK_IMPORTED_MODULE_1__glmatrix_mat4__["a" /* default */].transpose(inverseTranspose, inverseTranspose);
  20401. normalv4[3] = 0;
  20402. __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].copy(normalv4, this.normal.array);
  20403. __WEBPACK_IMPORTED_MODULE_3__glmatrix_vec4__["a" /* default */].transformMat4(normalv4, normalv4, inverseTranspose);
  20404. __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].copy(this.normal.array, normalv4);
  20405. };
  20406. })(),
  20407. /**
  20408. * Copy from another plane
  20409. * @param {clay.Vector3} plane
  20410. */
  20411. copy: function (plane) {
  20412. __WEBPACK_IMPORTED_MODULE_2__glmatrix_vec3__["a" /* default */].copy(this.normal.array, plane.normal.array);
  20413. this.normal._dirty = true;
  20414. this.distance = plane.distance;
  20415. },
  20416. /**
  20417. * Clone a new plane
  20418. * @return {clay.Plane}
  20419. */
  20420. clone: function () {
  20421. var plane = new Plane();
  20422. plane.copy(this);
  20423. return plane;
  20424. }
  20425. };
  20426. /* harmony default export */ __webpack_exports__["a"] = (Plane);
  20427. /***/
  20428. }),
  20429. /* 75 */
  20430. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  20431. "use strict";
  20432. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Skybox__ = __webpack_require__(42);
  20433. /* harmony default export */ __webpack_exports__["a"] = (__WEBPACK_IMPORTED_MODULE_0__Skybox__["a" /* default */]);
  20434. /***/
  20435. }),
  20436. /* 76 */
  20437. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  20438. "use strict";
  20439. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Geometry__ = __webpack_require__(15);
  20440. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__Plane__ = __webpack_require__(43);
  20441. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__math_Matrix4__ = __webpack_require__(9);
  20442. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__math_Vector3__ = __webpack_require__(3);
  20443. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__math_BoundingBox__ = __webpack_require__(18);
  20444. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__core_vendor__ = __webpack_require__(14);
  20445. var planeMatrix = new __WEBPACK_IMPORTED_MODULE_2__math_Matrix4__["a" /* default */]();
  20446. /**
  20447. * @constructor clay.geometry.Cube
  20448. * @extends clay.Geometry
  20449. * @param {Object} [opt]
  20450. * @param {number} [opt.widthSegments]
  20451. * @param {number} [opt.heightSegments]
  20452. * @param {number} [opt.depthSegments]
  20453. * @param {boolean} [opt.inside]
  20454. */
  20455. var Cube = __WEBPACK_IMPORTED_MODULE_0__Geometry__["a" /* default */].extend(
  20456. /**@lends clay.geometry.Cube# */
  20457. {
  20458. dynamic: false,
  20459. /**
  20460. * @type {number}
  20461. */
  20462. widthSegments: 1,
  20463. /**
  20464. * @type {number}
  20465. */
  20466. heightSegments: 1,
  20467. /**
  20468. * @type {number}
  20469. */
  20470. depthSegments: 1,
  20471. /**
  20472. * @type {boolean}
  20473. */
  20474. inside: false
  20475. }, function () {
  20476. this.build();
  20477. },
  20478. /** @lends clay.geometry.Cube.prototype */
  20479. {
  20480. /**
  20481. * Build cube geometry
  20482. */
  20483. build: function () {
  20484. var planes = {
  20485. 'px': createPlane('px', this.depthSegments, this.heightSegments),
  20486. 'nx': createPlane('nx', this.depthSegments, this.heightSegments),
  20487. 'py': createPlane('py', this.widthSegments, this.depthSegments),
  20488. 'ny': createPlane('ny', this.widthSegments, this.depthSegments),
  20489. 'pz': createPlane('pz', this.widthSegments, this.heightSegments),
  20490. 'nz': createPlane('nz', this.widthSegments, this.heightSegments),
  20491. };
  20492. var attrList = ['position', 'texcoord0', 'normal'];
  20493. var vertexNumber = 0;
  20494. var faceNumber = 0;
  20495. for (var pos in planes) {
  20496. vertexNumber += planes[pos].vertexCount;
  20497. faceNumber += planes[pos].indices.length;
  20498. }
  20499. for (var k = 0; k < attrList.length; k++) {
  20500. this.attributes[attrList[k]].init(vertexNumber);
  20501. }
  20502. this.indices = new __WEBPACK_IMPORTED_MODULE_5__core_vendor__["a" /* default */].Uint16Array(faceNumber);
  20503. var faceOffset = 0;
  20504. var vertexOffset = 0;
  20505. for (var pos in planes) {
  20506. var plane = planes[pos];
  20507. for (var k = 0; k < attrList.length; k++) {
  20508. var attrName = attrList[k];
  20509. var attrArray = plane.attributes[attrName].value;
  20510. var attrSize = plane.attributes[attrName].size;
  20511. var isNormal = attrName === 'normal';
  20512. for (var i = 0; i < attrArray.length; i++) {
  20513. var value = attrArray[i];
  20514. if (this.inside && isNormal) {
  20515. value = -value;
  20516. }
  20517. this.attributes[attrName].value[i + attrSize * vertexOffset] = value;
  20518. }
  20519. }
  20520. var len = plane.indices.length;
  20521. for (var i = 0; i < plane.indices.length; i++) {
  20522. this.indices[i + faceOffset] = vertexOffset + plane.indices[this.inside ? (len - i - 1) : i];
  20523. }
  20524. faceOffset += plane.indices.length;
  20525. vertexOffset += plane.vertexCount;
  20526. }
  20527. this.boundingBox = new __WEBPACK_IMPORTED_MODULE_4__math_BoundingBox__["a" /* default */]();
  20528. this.boundingBox.max.set(1, 1, 1);
  20529. this.boundingBox.min.set(-1, -1, -1);
  20530. }
  20531. });
  20532. function createPlane(pos, widthSegments, heightSegments) {
  20533. planeMatrix.identity();
  20534. var plane = new __WEBPACK_IMPORTED_MODULE_1__Plane__["a" /* default */]({
  20535. widthSegments: widthSegments,
  20536. heightSegments: heightSegments
  20537. });
  20538. switch (pos) {
  20539. case 'px':
  20540. __WEBPACK_IMPORTED_MODULE_2__math_Matrix4__["a" /* default */].translate(planeMatrix, planeMatrix, __WEBPACK_IMPORTED_MODULE_3__math_Vector3__["a" /* default */].POSITIVE_X);
  20541. __WEBPACK_IMPORTED_MODULE_2__math_Matrix4__["a" /* default */].rotateY(planeMatrix, planeMatrix, Math.PI / 2);
  20542. break;
  20543. case 'nx':
  20544. __WEBPACK_IMPORTED_MODULE_2__math_Matrix4__["a" /* default */].translate(planeMatrix, planeMatrix, __WEBPACK_IMPORTED_MODULE_3__math_Vector3__["a" /* default */].NEGATIVE_X);
  20545. __WEBPACK_IMPORTED_MODULE_2__math_Matrix4__["a" /* default */].rotateY(planeMatrix, planeMatrix, -Math.PI / 2);
  20546. break;
  20547. case 'py':
  20548. __WEBPACK_IMPORTED_MODULE_2__math_Matrix4__["a" /* default */].translate(planeMatrix, planeMatrix, __WEBPACK_IMPORTED_MODULE_3__math_Vector3__["a" /* default */].POSITIVE_Y);
  20549. __WEBPACK_IMPORTED_MODULE_2__math_Matrix4__["a" /* default */].rotateX(planeMatrix, planeMatrix, -Math.PI / 2);
  20550. break;
  20551. case 'ny':
  20552. __WEBPACK_IMPORTED_MODULE_2__math_Matrix4__["a" /* default */].translate(planeMatrix, planeMatrix, __WEBPACK_IMPORTED_MODULE_3__math_Vector3__["a" /* default */].NEGATIVE_Y);
  20553. __WEBPACK_IMPORTED_MODULE_2__math_Matrix4__["a" /* default */].rotateX(planeMatrix, planeMatrix, Math.PI / 2);
  20554. break;
  20555. case 'pz':
  20556. __WEBPACK_IMPORTED_MODULE_2__math_Matrix4__["a" /* default */].translate(planeMatrix, planeMatrix, __WEBPACK_IMPORTED_MODULE_3__math_Vector3__["a" /* default */].POSITIVE_Z);
  20557. break;
  20558. case 'nz':
  20559. __WEBPACK_IMPORTED_MODULE_2__math_Matrix4__["a" /* default */].translate(planeMatrix, planeMatrix, __WEBPACK_IMPORTED_MODULE_3__math_Vector3__["a" /* default */].NEGATIVE_Z);
  20560. __WEBPACK_IMPORTED_MODULE_2__math_Matrix4__["a" /* default */].rotateY(planeMatrix, planeMatrix, Math.PI);
  20561. break;
  20562. }
  20563. plane.applyTransform(planeMatrix);
  20564. return plane;
  20565. }
  20566. /* harmony default export */ __webpack_exports__["a"] = (Cube);
  20567. /***/
  20568. }),
  20569. /* 77 */
  20570. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  20571. "use strict";
  20572. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Texture2D__ = __webpack_require__(5);
  20573. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__TextureCube__ = __webpack_require__(27);
  20574. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__Texture__ = __webpack_require__(4);
  20575. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__FrameBuffer__ = __webpack_require__(10);
  20576. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__compositor_Pass__ = __webpack_require__(16);
  20577. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__Material__ = __webpack_require__(19);
  20578. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__Shader__ = __webpack_require__(8);
  20579. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__plugin_Skybox__ = __webpack_require__(42);
  20580. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__Scene__ = __webpack_require__(36);
  20581. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_9__prePass_EnvironmentMap__ = __webpack_require__(62);
  20582. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_10__core_vendor__ = __webpack_require__(14);
  20583. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_11__texture__ = __webpack_require__(61);
  20584. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_12__shader_integrateBRDF_glsl_js__ = __webpack_require__(127);
  20585. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_13__shader_prefilter_glsl_js__ = __webpack_require__(128);
  20586. // Cubemap prefilter utility
  20587. // http://www.unrealengine.com/files/downloads/2013SiggraphPresentationsNotes.pdf
  20588. // http://http.developer.nvidia.com/GPUGems3/gpugems3_ch20.html
  20589. var cubemapUtil = {};
  20590. var targets = ['px', 'nx', 'py', 'ny', 'pz', 'nz'];
  20591. // TODO Downsample
  20592. /**
  20593. * @name clay.util.cubemap.prefilterEnvironmentMap
  20594. * @param {clay.Renderer} renderer
  20595. * @param {clay.Texture} envMap
  20596. * @param {Object} [textureOpts]
  20597. * @param {number} [textureOpts.width=64]
  20598. * @param {number} [textureOpts.height=64]
  20599. * @param {number} [textureOpts.type]
  20600. * @param {boolean} [textureOpts.encodeRGBM=false]
  20601. * @param {boolean} [textureOpts.decodeRGBM=false]
  20602. * @param {clay.Texture2D} [normalDistribution]
  20603. * @param {clay.Texture2D} [brdfLookup]
  20604. */
  20605. cubemapUtil.prefilterEnvironmentMap = function (
  20606. renderer, envMap, textureOpts, normalDistribution, brdfLookup
  20607. ) {
  20608. // Not create other renderer, it is easy having issue of cross reference of resources like framebuffer
  20609. // PENDING preserveDrawingBuffer?
  20610. if (!brdfLookup || !normalDistribution) {
  20611. normalDistribution = cubemapUtil.generateNormalDistribution();
  20612. brdfLookup = cubemapUtil.integrateBRDF(renderer, normalDistribution);
  20613. }
  20614. textureOpts = textureOpts || {};
  20615. var width = textureOpts.width || 64;
  20616. var height = textureOpts.height || 64;
  20617. var textureType = textureOpts.type || envMap.type;
  20618. // Use same type with given envMap
  20619. var prefilteredCubeMap = new __WEBPACK_IMPORTED_MODULE_1__TextureCube__["a" /* default */]({
  20620. width: width,
  20621. height: height,
  20622. type: textureType,
  20623. flipY: false,
  20624. mipmaps: []
  20625. });
  20626. if (!prefilteredCubeMap.isPowerOfTwo()) {
  20627. console.warn('Width and height must be power of two to enable mipmap.');
  20628. }
  20629. var size = Math.min(width, height);
  20630. var mipmapNum = Math.log(size) / Math.log(2) + 1;
  20631. var prefilterMaterial = new __WEBPACK_IMPORTED_MODULE_5__Material__["a" /* default */]({
  20632. shader: new __WEBPACK_IMPORTED_MODULE_6__Shader__["a" /* default */]({
  20633. vertex: __WEBPACK_IMPORTED_MODULE_6__Shader__["a" /* default */].source('clay.skybox.vertex'),
  20634. fragment: __WEBPACK_IMPORTED_MODULE_13__shader_prefilter_glsl_js__["a" /* default */]
  20635. })
  20636. });
  20637. prefilterMaterial.set('normalDistribution', normalDistribution);
  20638. textureOpts.encodeRGBM && prefilterMaterial.define('fragment', 'RGBM_ENCODE');
  20639. textureOpts.decodeRGBM && prefilterMaterial.define('fragment', 'RGBM_DECODE');
  20640. var dummyScene = new __WEBPACK_IMPORTED_MODULE_8__Scene__["a" /* default */]();
  20641. var skyEnv;
  20642. if (envMap.textureType === 'texture2D') {
  20643. // Convert panorama to cubemap
  20644. var envCubemap = new __WEBPACK_IMPORTED_MODULE_1__TextureCube__["a" /* default */]({
  20645. width: width,
  20646. height: height,
  20647. // FIXME FLOAT type will cause GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT error on iOS
  20648. type: textureType === __WEBPACK_IMPORTED_MODULE_2__Texture__["a" /* default */].FLOAT ?
  20649. __WEBPACK_IMPORTED_MODULE_2__Texture__["a" /* default */].HALF_FLOAT : textureType
  20650. });
  20651. __WEBPACK_IMPORTED_MODULE_11__texture__["a" /* default */].panoramaToCubeMap(renderer, envMap, envCubemap, {
  20652. // PENDING encodeRGBM so it can be decoded as RGBM
  20653. encodeRGBM: textureOpts.decodeRGBM
  20654. });
  20655. envMap = envCubemap;
  20656. }
  20657. skyEnv = new __WEBPACK_IMPORTED_MODULE_7__plugin_Skybox__["a" /* default */]({
  20658. scene: dummyScene,
  20659. material: prefilterMaterial
  20660. });
  20661. skyEnv.material.set('environmentMap', envMap);
  20662. var envMapPass = new __WEBPACK_IMPORTED_MODULE_9__prePass_EnvironmentMap__["a" /* default */]({
  20663. texture: prefilteredCubeMap
  20664. });
  20665. // Force to be UNSIGNED_BYTE
  20666. if (textureOpts.encodeRGBM) {
  20667. textureType = prefilteredCubeMap.type = __WEBPACK_IMPORTED_MODULE_2__Texture__["a" /* default */].UNSIGNED_BYTE;
  20668. }
  20669. var renderTargetTmp = new __WEBPACK_IMPORTED_MODULE_0__Texture2D__["a" /* default */]({
  20670. width: width,
  20671. height: height,
  20672. type: textureType
  20673. });
  20674. var frameBuffer = new __WEBPACK_IMPORTED_MODULE_3__FrameBuffer__["a" /* default */]({
  20675. depthBuffer: false
  20676. });
  20677. var ArrayCtor = __WEBPACK_IMPORTED_MODULE_10__core_vendor__["a" /* default */][textureType === __WEBPACK_IMPORTED_MODULE_2__Texture__["a" /* default */].UNSIGNED_BYTE ? 'Uint8Array' : 'Float32Array'];
  20678. for (var i = 0; i < mipmapNum; i++) {
  20679. // console.time('prefilter');
  20680. prefilteredCubeMap.mipmaps[i] = {
  20681. pixels: {}
  20682. };
  20683. skyEnv.material.set('roughness', i / (mipmapNum - 1));
  20684. // Tweak fov
  20685. // http://the-witness.net/news/2012/02/seamless-cube-map-filtering/
  20686. var n = renderTargetTmp.width;
  20687. var fov = 2 * Math.atan(n / (n - 0.5)) / Math.PI * 180;
  20688. for (var j = 0; j < targets.length; j++) {
  20689. var pixels = new ArrayCtor(renderTargetTmp.width * renderTargetTmp.height * 4);
  20690. frameBuffer.attach(renderTargetTmp);
  20691. frameBuffer.bind(renderer);
  20692. var camera = envMapPass.getCamera(targets[j]);
  20693. camera.fov = fov;
  20694. renderer.render(dummyScene, camera);
  20695. renderer.gl.readPixels(
  20696. 0, 0, renderTargetTmp.width, renderTargetTmp.height,
  20697. __WEBPACK_IMPORTED_MODULE_2__Texture__["a" /* default */].RGBA, textureType, pixels
  20698. );
  20699. // var canvas = document.createElement('canvas');
  20700. // var ctx = canvas.getContext('2d');
  20701. // canvas.width = renderTargetTmp.width;
  20702. // canvas.height = renderTargetTmp.height;
  20703. // var imageData = ctx.createImageData(renderTargetTmp.width, renderTargetTmp.height);
  20704. // for (var k = 0; k < pixels.length; k++) {
  20705. // imageData.data[k] = pixels[k];
  20706. // }
  20707. // ctx.putImageData(imageData, 0, 0);
  20708. // document.body.appendChild(canvas);
  20709. frameBuffer.unbind(renderer);
  20710. prefilteredCubeMap.mipmaps[i].pixels[targets[j]] = pixels;
  20711. }
  20712. renderTargetTmp.width /= 2;
  20713. renderTargetTmp.height /= 2;
  20714. renderTargetTmp.dirty();
  20715. // console.timeEnd('prefilter');
  20716. }
  20717. frameBuffer.dispose(renderer);
  20718. renderTargetTmp.dispose(renderer);
  20719. skyEnv.dispose(renderer);
  20720. // Remove gpu resource allucated in renderer
  20721. normalDistribution.dispose(renderer);
  20722. // renderer.dispose();
  20723. return {
  20724. environmentMap: prefilteredCubeMap,
  20725. brdfLookup: brdfLookup,
  20726. normalDistribution: normalDistribution,
  20727. maxMipmapLevel: mipmapNum
  20728. };
  20729. };
  20730. cubemapUtil.integrateBRDF = function (renderer, normalDistribution) {
  20731. normalDistribution = normalDistribution || cubemapUtil.generateNormalDistribution();
  20732. var framebuffer = new __WEBPACK_IMPORTED_MODULE_3__FrameBuffer__["a" /* default */]({
  20733. depthBuffer: false
  20734. });
  20735. var pass = new __WEBPACK_IMPORTED_MODULE_4__compositor_Pass__["a" /* default */]({
  20736. fragment: __WEBPACK_IMPORTED_MODULE_12__shader_integrateBRDF_glsl_js__["a" /* default */]
  20737. });
  20738. var texture = new __WEBPACK_IMPORTED_MODULE_0__Texture2D__["a" /* default */]({
  20739. width: 512,
  20740. height: 256,
  20741. type: __WEBPACK_IMPORTED_MODULE_2__Texture__["a" /* default */].HALF_FLOAT,
  20742. wrapS: __WEBPACK_IMPORTED_MODULE_2__Texture__["a" /* default */].CLAMP_TO_EDGE,
  20743. wrapT: __WEBPACK_IMPORTED_MODULE_2__Texture__["a" /* default */].CLAMP_TO_EDGE,
  20744. minFilter: __WEBPACK_IMPORTED_MODULE_2__Texture__["a" /* default */].NEAREST,
  20745. magFilter: __WEBPACK_IMPORTED_MODULE_2__Texture__["a" /* default */].NEAREST,
  20746. useMipmap: false
  20747. });
  20748. pass.setUniform('normalDistribution', normalDistribution);
  20749. pass.setUniform('viewportSize', [512, 256]);
  20750. pass.attachOutput(texture);
  20751. pass.render(renderer, framebuffer);
  20752. // FIXME Only chrome and firefox can readPixels with float type.
  20753. // framebuffer.bind(renderer);
  20754. // var pixels = new Float32Array(512 * 256 * 4);
  20755. // renderer.gl.readPixels(
  20756. // 0, 0, texture.width, texture.height,
  20757. // Texture.RGBA, Texture.FLOAT, pixels
  20758. // );
  20759. // texture.pixels = pixels;
  20760. // texture.flipY = false;
  20761. // texture.dirty();
  20762. // framebuffer.unbind(renderer);
  20763. framebuffer.dispose(renderer);
  20764. return texture;
  20765. };
  20766. cubemapUtil.generateNormalDistribution = function (roughnessLevels, sampleSize) {
  20767. // http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
  20768. // GLSL not support bit operation, use lookup instead
  20769. // V -> i / N, U -> roughness
  20770. var roughnessLevels = roughnessLevels || 256;
  20771. var sampleSize = sampleSize || 1024;
  20772. var normalDistribution = new __WEBPACK_IMPORTED_MODULE_0__Texture2D__["a" /* default */]({
  20773. width: roughnessLevels,
  20774. height: sampleSize,
  20775. type: __WEBPACK_IMPORTED_MODULE_2__Texture__["a" /* default */].FLOAT,
  20776. minFilter: __WEBPACK_IMPORTED_MODULE_2__Texture__["a" /* default */].NEAREST,
  20777. magFilter: __WEBPACK_IMPORTED_MODULE_2__Texture__["a" /* default */].NEAREST,
  20778. wrapS: __WEBPACK_IMPORTED_MODULE_2__Texture__["a" /* default */].CLAMP_TO_EDGE,
  20779. wrapT: __WEBPACK_IMPORTED_MODULE_2__Texture__["a" /* default */].CLAMP_TO_EDGE,
  20780. useMipmap: false
  20781. });
  20782. var pixels = new Float32Array(sampleSize * roughnessLevels * 4);
  20783. var tmp = [];
  20784. // function sortFunc(a, b) {
  20785. // return Math.abs(b) - Math.abs(a);
  20786. // }
  20787. for (var j = 0; j < roughnessLevels; j++) {
  20788. var roughness = j / roughnessLevels;
  20789. var a = roughness * roughness;
  20790. for (var i = 0; i < sampleSize; i++) {
  20791. // http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
  20792. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
  20793. // http://stackoverflow.com/questions/1908492/unsigned-integer-in-javascript
  20794. // http://stackoverflow.com/questions/1822350/what-is-the-javascript-operator-and-how-do-you-use-it
  20795. var y = (i << 16 | i >>> 16) >>> 0;
  20796. y = ((y & 1431655765) << 1 | (y & 2863311530) >>> 1) >>> 0;
  20797. y = ((y & 858993459) << 2 | (y & 3435973836) >>> 2) >>> 0;
  20798. y = ((y & 252645135) << 4 | (y & 4042322160) >>> 4) >>> 0;
  20799. y = (((y & 16711935) << 8 | (y & 4278255360) >>> 8) >>> 0) / 4294967296;
  20800. // CDF
  20801. var cosTheta = Math.sqrt((1 - y) / (1 + (a * a - 1.0) * y));
  20802. tmp[i] = cosTheta;
  20803. }
  20804. for (var i = 0; i < sampleSize; i++) {
  20805. var offset = (i * roughnessLevels + j) * 4;
  20806. var cosTheta = tmp[i];
  20807. var sinTheta = Math.sqrt(1.0 - cosTheta * cosTheta);
  20808. var x = i / sampleSize;
  20809. var phi = 2.0 * Math.PI * x;
  20810. pixels[offset] = sinTheta * Math.cos(phi);
  20811. pixels[offset + 1] = cosTheta;
  20812. pixels[offset + 2] = sinTheta * Math.sin(phi);
  20813. pixels[offset + 3] = 1.0;
  20814. }
  20815. }
  20816. normalDistribution.pixels = pixels;
  20817. return normalDistribution;
  20818. };
  20819. /* harmony default export */ __webpack_exports__["a"] = (cubemapUtil);
  20820. /***/
  20821. }),
  20822. /* 78 */
  20823. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  20824. "use strict";
  20825. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__common__ = __webpack_require__(20);
  20826. /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
  20827. Redistribution and use in source and binary forms, with or without modification,
  20828. are permitted provided that the following conditions are met:
  20829. * Redistributions of source code must retain the above copyright notice, this
  20830. list of conditions and the following disclaimer.
  20831. * Redistributions in binary form must reproduce the above copyright notice,
  20832. this list of conditions and the following disclaimer in the documentation
  20833. and/or other materials provided with the distribution.
  20834. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20835. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20836. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20837. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  20838. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20839. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20840. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  20841. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  20842. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20843. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
  20844. /**
  20845. * @class 2x2 Matrix
  20846. * @name mat2
  20847. */
  20848. var mat2 = {};
  20849. /**
  20850. * Creates a new identity mat2
  20851. *
  20852. * @returns {mat2} a new 2x2 matrix
  20853. */
  20854. mat2.create = function () {
  20855. var out = new __WEBPACK_IMPORTED_MODULE_0__common__["a" /* GLMAT_ARRAY_TYPE */](4);
  20856. out[0] = 1;
  20857. out[1] = 0;
  20858. out[2] = 0;
  20859. out[3] = 1;
  20860. return out;
  20861. };
  20862. /**
  20863. * Creates a new mat2 initialized with values from an existing matrix
  20864. *
  20865. * @param {mat2} a matrix to clone
  20866. * @returns {mat2} a new 2x2 matrix
  20867. */
  20868. mat2.clone = function (a) {
  20869. var out = new __WEBPACK_IMPORTED_MODULE_0__common__["a" /* GLMAT_ARRAY_TYPE */](4);
  20870. out[0] = a[0];
  20871. out[1] = a[1];
  20872. out[2] = a[2];
  20873. out[3] = a[3];
  20874. return out;
  20875. };
  20876. /**
  20877. * Copy the values from one mat2 to another
  20878. *
  20879. * @param {mat2} out the receiving matrix
  20880. * @param {mat2} a the source matrix
  20881. * @returns {mat2} out
  20882. */
  20883. mat2.copy = function (out, a) {
  20884. out[0] = a[0];
  20885. out[1] = a[1];
  20886. out[2] = a[2];
  20887. out[3] = a[3];
  20888. return out;
  20889. };
  20890. /**
  20891. * Set a mat2 to the identity matrix
  20892. *
  20893. * @param {mat2} out the receiving matrix
  20894. * @returns {mat2} out
  20895. */
  20896. mat2.identity = function (out) {
  20897. out[0] = 1;
  20898. out[1] = 0;
  20899. out[2] = 0;
  20900. out[3] = 1;
  20901. return out;
  20902. };
  20903. /**
  20904. * Transpose the values of a mat2
  20905. *
  20906. * @param {mat2} out the receiving matrix
  20907. * @param {mat2} a the source matrix
  20908. * @returns {mat2} out
  20909. */
  20910. mat2.transpose = function (out, a) {
  20911. // If we are transposing ourselves we can skip a few steps but have to cache some values
  20912. if (out === a) {
  20913. var a1 = a[1];
  20914. out[1] = a[2];
  20915. out[2] = a1;
  20916. } else {
  20917. out[0] = a[0];
  20918. out[1] = a[2];
  20919. out[2] = a[1];
  20920. out[3] = a[3];
  20921. }
  20922. return out;
  20923. };
  20924. /**
  20925. * Inverts a mat2
  20926. *
  20927. * @param {mat2} out the receiving matrix
  20928. * @param {mat2} a the source matrix
  20929. * @returns {mat2} out
  20930. */
  20931. mat2.invert = function (out, a) {
  20932. var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
  20933. // Calculate the determinant
  20934. det = a0 * a3 - a2 * a1;
  20935. if (!det) {
  20936. return null;
  20937. }
  20938. det = 1.0 / det;
  20939. out[0] = a3 * det;
  20940. out[1] = -a1 * det;
  20941. out[2] = -a2 * det;
  20942. out[3] = a0 * det;
  20943. return out;
  20944. };
  20945. /**
  20946. * Calculates the adjugate of a mat2
  20947. *
  20948. * @param {mat2} out the receiving matrix
  20949. * @param {mat2} a the source matrix
  20950. * @returns {mat2} out
  20951. */
  20952. mat2.adjoint = function (out, a) {
  20953. // Caching this value is nessecary if out == a
  20954. var a0 = a[0];
  20955. out[0] = a[3];
  20956. out[1] = -a[1];
  20957. out[2] = -a[2];
  20958. out[3] = a0;
  20959. return out;
  20960. };
  20961. /**
  20962. * Calculates the determinant of a mat2
  20963. *
  20964. * @param {mat2} a the source matrix
  20965. * @returns {Number} determinant of a
  20966. */
  20967. mat2.determinant = function (a) {
  20968. return a[0] * a[3] - a[2] * a[1];
  20969. };
  20970. /**
  20971. * Multiplies two mat2's
  20972. *
  20973. * @param {mat2} out the receiving matrix
  20974. * @param {mat2} a the first operand
  20975. * @param {mat2} b the second operand
  20976. * @returns {mat2} out
  20977. */
  20978. mat2.multiply = function (out, a, b) {
  20979. var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
  20980. var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
  20981. out[0] = a0 * b0 + a2 * b1;
  20982. out[1] = a1 * b0 + a3 * b1;
  20983. out[2] = a0 * b2 + a2 * b3;
  20984. out[3] = a1 * b2 + a3 * b3;
  20985. return out;
  20986. };
  20987. /**
  20988. * Alias for {@link mat2.multiply}
  20989. * @function
  20990. */
  20991. mat2.mul = mat2.multiply;
  20992. /**
  20993. * Rotates a mat2 by the given angle
  20994. *
  20995. * @param {mat2} out the receiving matrix
  20996. * @param {mat2} a the matrix to rotate
  20997. * @param {Number} rad the angle to rotate the matrix by
  20998. * @returns {mat2} out
  20999. */
  21000. mat2.rotate = function (out, a, rad) {
  21001. var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
  21002. s = Math.sin(rad),
  21003. c = Math.cos(rad);
  21004. out[0] = a0 * c + a2 * s;
  21005. out[1] = a1 * c + a3 * s;
  21006. out[2] = a0 * -s + a2 * c;
  21007. out[3] = a1 * -s + a3 * c;
  21008. return out;
  21009. };
  21010. /**
  21011. * Scales the mat2 by the dimensions in the given vec2
  21012. *
  21013. * @param {mat2} out the receiving matrix
  21014. * @param {mat2} a the matrix to rotate
  21015. * @param {vec2} v the vec2 to scale the matrix by
  21016. * @returns {mat2} out
  21017. **/
  21018. mat2.scale = function (out, a, v) {
  21019. var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
  21020. v0 = v[0], v1 = v[1];
  21021. out[0] = a0 * v0;
  21022. out[1] = a1 * v0;
  21023. out[2] = a2 * v1;
  21024. out[3] = a3 * v1;
  21025. return out;
  21026. };
  21027. /**
  21028. * Returns Frobenius norm of a mat2
  21029. *
  21030. * @param {mat2} a the matrix to calculate Frobenius norm of
  21031. * @returns {Number} Frobenius norm
  21032. */
  21033. mat2.frob = function (a) {
  21034. return (Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2)))
  21035. };
  21036. /**
  21037. * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix
  21038. * @param {mat2} L the lower triangular matrix
  21039. * @param {mat2} D the diagonal matrix
  21040. * @param {mat2} U the upper triangular matrix
  21041. * @param {mat2} a the input matrix to factorize
  21042. */
  21043. mat2.LDU = function (L, D, U, a) {
  21044. L[2] = a[2] / a[0];
  21045. U[0] = a[0];
  21046. U[1] = a[1];
  21047. U[3] = a[3] - L[2] * U[1];
  21048. return [L, D, U];
  21049. };
  21050. /* harmony default export */ __webpack_exports__["a"] = (mat2);
  21051. /***/
  21052. }),
  21053. /* 79 */
  21054. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  21055. "use strict";
  21056. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__common__ = __webpack_require__(20);
  21057. /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
  21058. Redistribution and use in source and binary forms, with or without modification,
  21059. are permitted provided that the following conditions are met:
  21060. * Redistributions of source code must retain the above copyright notice, this
  21061. list of conditions and the following disclaimer.
  21062. * Redistributions in binary form must reproduce the above copyright notice,
  21063. this list of conditions and the following disclaimer in the documentation
  21064. and/or other materials provided with the distribution.
  21065. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  21066. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21067. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21068. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  21069. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21070. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21071. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  21072. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21073. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21074. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
  21075. /**
  21076. * @class 2x3 Matrix
  21077. * @name mat2d
  21078. *
  21079. * @description
  21080. * A mat2d contains six elements defined as:
  21081. * <pre>
  21082. * [a, c, tx,
  21083. * b, d, ty]
  21084. * </pre>
  21085. * This is a short form for the 3x3 matrix:
  21086. * <pre>
  21087. * [a, c, tx,
  21088. * b, d, ty,
  21089. * 0, 0, 1]
  21090. * </pre>
  21091. * The last row is ignored so the array is shorter and operations are faster.
  21092. */
  21093. var mat2d = {};
  21094. /**
  21095. * Creates a new identity mat2d
  21096. *
  21097. * @returns {mat2d} a new 2x3 matrix
  21098. */
  21099. mat2d.create = function () {
  21100. var out = new __WEBPACK_IMPORTED_MODULE_0__common__["a" /* GLMAT_ARRAY_TYPE */](6);
  21101. out[0] = 1;
  21102. out[1] = 0;
  21103. out[2] = 0;
  21104. out[3] = 1;
  21105. out[4] = 0;
  21106. out[5] = 0;
  21107. return out;
  21108. };
  21109. /**
  21110. * Creates a new mat2d initialized with values from an existing matrix
  21111. *
  21112. * @param {mat2d} a matrix to clone
  21113. * @returns {mat2d} a new 2x3 matrix
  21114. */
  21115. mat2d.clone = function (a) {
  21116. var out = new __WEBPACK_IMPORTED_MODULE_0__common__["a" /* GLMAT_ARRAY_TYPE */](6);
  21117. out[0] = a[0];
  21118. out[1] = a[1];
  21119. out[2] = a[2];
  21120. out[3] = a[3];
  21121. out[4] = a[4];
  21122. out[5] = a[5];
  21123. return out;
  21124. };
  21125. /**
  21126. * Copy the values from one mat2d to another
  21127. *
  21128. * @param {mat2d} out the receiving matrix
  21129. * @param {mat2d} a the source matrix
  21130. * @returns {mat2d} out
  21131. */
  21132. mat2d.copy = function (out, a) {
  21133. out[0] = a[0];
  21134. out[1] = a[1];
  21135. out[2] = a[2];
  21136. out[3] = a[3];
  21137. out[4] = a[4];
  21138. out[5] = a[5];
  21139. return out;
  21140. };
  21141. /**
  21142. * Set a mat2d to the identity matrix
  21143. *
  21144. * @param {mat2d} out the receiving matrix
  21145. * @returns {mat2d} out
  21146. */
  21147. mat2d.identity = function (out) {
  21148. out[0] = 1;
  21149. out[1] = 0;
  21150. out[2] = 0;
  21151. out[3] = 1;
  21152. out[4] = 0;
  21153. out[5] = 0;
  21154. return out;
  21155. };
  21156. /**
  21157. * Inverts a mat2d
  21158. *
  21159. * @param {mat2d} out the receiving matrix
  21160. * @param {mat2d} a the source matrix
  21161. * @returns {mat2d} out
  21162. */
  21163. mat2d.invert = function (out, a) {
  21164. var aa = a[0], ab = a[1], ac = a[2], ad = a[3],
  21165. atx = a[4], aty = a[5];
  21166. var det = aa * ad - ab * ac;
  21167. if (!det) {
  21168. return null;
  21169. }
  21170. det = 1.0 / det;
  21171. out[0] = ad * det;
  21172. out[1] = -ab * det;
  21173. out[2] = -ac * det;
  21174. out[3] = aa * det;
  21175. out[4] = (ac * aty - ad * atx) * det;
  21176. out[5] = (ab * atx - aa * aty) * det;
  21177. return out;
  21178. };
  21179. /**
  21180. * Calculates the determinant of a mat2d
  21181. *
  21182. * @param {mat2d} a the source matrix
  21183. * @returns {Number} determinant of a
  21184. */
  21185. mat2d.determinant = function (a) {
  21186. return a[0] * a[3] - a[1] * a[2];
  21187. };
  21188. /**
  21189. * Multiplies two mat2d's
  21190. *
  21191. * @param {mat2d} out the receiving matrix
  21192. * @param {mat2d} a the first operand
  21193. * @param {mat2d} b the second operand
  21194. * @returns {mat2d} out
  21195. */
  21196. mat2d.multiply = function (out, a, b) {
  21197. var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5],
  21198. b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5];
  21199. out[0] = a0 * b0 + a2 * b1;
  21200. out[1] = a1 * b0 + a3 * b1;
  21201. out[2] = a0 * b2 + a2 * b3;
  21202. out[3] = a1 * b2 + a3 * b3;
  21203. out[4] = a0 * b4 + a2 * b5 + a4;
  21204. out[5] = a1 * b4 + a3 * b5 + a5;
  21205. return out;
  21206. };
  21207. /**
  21208. * Alias for {@link mat2d.multiply}
  21209. * @function
  21210. */
  21211. mat2d.mul = mat2d.multiply;
  21212. /**
  21213. * Rotates a mat2d by the given angle
  21214. *
  21215. * @param {mat2d} out the receiving matrix
  21216. * @param {mat2d} a the matrix to rotate
  21217. * @param {Number} rad the angle to rotate the matrix by
  21218. * @returns {mat2d} out
  21219. */
  21220. mat2d.rotate = function (out, a, rad) {
  21221. var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5],
  21222. s = Math.sin(rad),
  21223. c = Math.cos(rad);
  21224. out[0] = a0 * c + a2 * s;
  21225. out[1] = a1 * c + a3 * s;
  21226. out[2] = a0 * -s + a2 * c;
  21227. out[3] = a1 * -s + a3 * c;
  21228. out[4] = a4;
  21229. out[5] = a5;
  21230. return out;
  21231. };
  21232. /**
  21233. * Scales the mat2d by the dimensions in the given vec2
  21234. *
  21235. * @param {mat2d} out the receiving matrix
  21236. * @param {mat2d} a the matrix to translate
  21237. * @param {vec2} v the vec2 to scale the matrix by
  21238. * @returns {mat2d} out
  21239. **/
  21240. mat2d.scale = function (out, a, v) {
  21241. var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5],
  21242. v0 = v[0], v1 = v[1];
  21243. out[0] = a0 * v0;
  21244. out[1] = a1 * v0;
  21245. out[2] = a2 * v1;
  21246. out[3] = a3 * v1;
  21247. out[4] = a4;
  21248. out[5] = a5;
  21249. return out;
  21250. };
  21251. /**
  21252. * Translates the mat2d by the dimensions in the given vec2
  21253. *
  21254. * @param {mat2d} out the receiving matrix
  21255. * @param {mat2d} a the matrix to translate
  21256. * @param {vec2} v the vec2 to translate the matrix by
  21257. * @returns {mat2d} out
  21258. **/
  21259. mat2d.translate = function (out, a, v) {
  21260. var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5],
  21261. v0 = v[0], v1 = v[1];
  21262. out[0] = a0;
  21263. out[1] = a1;
  21264. out[2] = a2;
  21265. out[3] = a3;
  21266. out[4] = a0 * v0 + a2 * v1 + a4;
  21267. out[5] = a1 * v0 + a3 * v1 + a5;
  21268. return out;
  21269. };
  21270. /**
  21271. * Returns Frobenius norm of a mat2d
  21272. *
  21273. * @param {mat2d} a the matrix to calculate Frobenius norm of
  21274. * @returns {Number} Frobenius norm
  21275. */
  21276. mat2d.frob = function (a) {
  21277. return (Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + 1))
  21278. };
  21279. /* harmony default export */ __webpack_exports__["a"] = (mat2d);
  21280. /***/
  21281. }),
  21282. /* 80 */
  21283. /***/ (function (module, exports) {
  21284. var _default = typeof window !== 'undefined' && (window.requestAnimationFrame && window.requestAnimationFrame.bind(window) || // https://github.com/ecomfe/zrender/issues/189#issuecomment-224919809
  21285. window.msRequestAnimationFrame && window.msRequestAnimationFrame.bind(window) || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame) || function (func) {
  21286. setTimeout(func, 16);
  21287. };
  21288. module.exports = _default;
  21289. /***/
  21290. }),
  21291. /* 81 */
  21292. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  21293. "use strict";
  21294. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  21295. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  21296. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_Texture2D__ = __webpack_require__(5);
  21297. /**
  21298. * Texture Atlas for the sprites.
  21299. * It uses zrender for 2d element management and rendering
  21300. * @module echarts-gl/util/ZRTextureAtlasSurface
  21301. */
  21302. // TODO Expand.
  21303. function ZRTextureAtlasSurfaceNode(zr, offsetX, offsetY, width, height, gap, dpr) {
  21304. this._zr = zr;
  21305. /**
  21306. * Current cursor x
  21307. * @type {number}
  21308. * @private
  21309. */
  21310. this._x = 0;
  21311. /**
  21312. * Current cursor y
  21313. * @type {number}
  21314. */
  21315. this._y = 0;
  21316. this._rowHeight = 0;
  21317. /**
  21318. * width without dpr.
  21319. * @type {number}
  21320. * @private
  21321. */
  21322. this.width = width;
  21323. /**
  21324. * height without dpr.
  21325. * @type {number}
  21326. * @private
  21327. */
  21328. this.height = height;
  21329. /**
  21330. * offsetX without dpr
  21331. * @type {number}
  21332. */
  21333. this.offsetX = offsetX;
  21334. /**
  21335. * offsetY without dpr
  21336. * @type {number}
  21337. */
  21338. this.offsetY = offsetY;
  21339. this.dpr = dpr;
  21340. this.gap = gap;
  21341. }
  21342. ZRTextureAtlasSurfaceNode.prototype = {
  21343. constructor: ZRTextureAtlasSurfaceNode,
  21344. clear: function () {
  21345. this._x = 0;
  21346. this._y = 0;
  21347. this._rowHeight = 0;
  21348. },
  21349. /**
  21350. * Add shape to atlas
  21351. * @param {module:zrender/graphic/Displayable} shape
  21352. * @param {number} width
  21353. * @param {number} height
  21354. * @return {Array}
  21355. */
  21356. add: function (el, width, height) {
  21357. // FIXME Text element not consider textAlign and textVerticalAlign.
  21358. // TODO, inner text, shadow
  21359. var rect = el.getBoundingRect();
  21360. // FIXME aspect ratio
  21361. if (width == null) {
  21362. width = rect.width;
  21363. }
  21364. if (height == null) {
  21365. height = rect.height;
  21366. }
  21367. width *= this.dpr;
  21368. height *= this.dpr;
  21369. this._fitElement(el, width, height);
  21370. // var aspect = el.scale[1] / el.scale[0];
  21371. // Adjust aspect ratio to make the text more clearly
  21372. // FIXME If height > width, width is useless ?
  21373. // width = height * aspect;
  21374. // el.position[0] *= aspect;
  21375. // el.scale[0] = el.scale[1];
  21376. var x = this._x;
  21377. var y = this._y;
  21378. var canvasWidth = this.width * this.dpr;
  21379. var canvasHeight = this.height * this.dpr;
  21380. var gap = this.gap;
  21381. if (x + width + gap > canvasWidth) {
  21382. // Change a new row
  21383. x = this._x = 0;
  21384. y += this._rowHeight + gap;
  21385. this._y = y;
  21386. // Reset row height
  21387. this._rowHeight = 0;
  21388. }
  21389. this._x += width + gap;
  21390. this._rowHeight = Math.max(this._rowHeight, height);
  21391. if (y + height + gap > canvasHeight) {
  21392. // There is no space anymore
  21393. return null;
  21394. }
  21395. // Shift the el
  21396. el.position[0] += this.offsetX * this.dpr + x;
  21397. el.position[1] += this.offsetY * this.dpr + y;
  21398. this._zr.add(el);
  21399. var coordsOffset = [
  21400. this.offsetX / this.width,
  21401. this.offsetY / this.height
  21402. ];
  21403. var coords = [
  21404. [x / canvasWidth + coordsOffset[0], y / canvasHeight + coordsOffset[1]],
  21405. [(x + width) / canvasWidth + coordsOffset[0], (y + height) / canvasHeight + coordsOffset[1]]
  21406. ];
  21407. return coords;
  21408. },
  21409. /**
  21410. * Fit element size by correct its position and scaling
  21411. * @param {module:zrender/graphic/Displayable} el
  21412. * @param {number} spriteWidth
  21413. * @param {number} spriteHeight
  21414. */
  21415. _fitElement: function (el, spriteWidth, spriteHeight) {
  21416. // TODO, inner text, shadow
  21417. var rect = el.getBoundingRect();
  21418. var scaleX = spriteWidth / rect.width;
  21419. var scaleY = spriteHeight / rect.height;
  21420. el.position = [-rect.x * scaleX, -rect.y * scaleY];
  21421. el.scale = [scaleX, scaleY];
  21422. el.update();
  21423. }
  21424. }
  21425. /**
  21426. * constructor
  21427. * @alias module:echarts-gl/util/ZRTextureAtlasSurface
  21428. * @param {number} opt.width
  21429. * @param {number} opt.height
  21430. * @param {number} opt.devicePixelRatio
  21431. * @param {number} opt.gap Gap for safe.
  21432. * @param {Function} opt.onupdate
  21433. */
  21434. function ZRTextureAtlasSurface(opt) {
  21435. opt = opt || {};
  21436. opt.width = opt.width || 512;
  21437. opt.height = opt.height || 512;
  21438. opt.devicePixelRatio = opt.devicePixelRatio || 1;
  21439. opt.gap = opt.gap == null ? 2 : opt.gap;
  21440. var canvas = document.createElement('canvas');
  21441. canvas.width = opt.width * opt.devicePixelRatio;
  21442. canvas.height = opt.height * opt.devicePixelRatio;
  21443. this._canvas = canvas;
  21444. this._texture = new __WEBPACK_IMPORTED_MODULE_1_claygl_src_Texture2D__["a" /* default */]({
  21445. image: canvas,
  21446. flipY: false
  21447. });
  21448. var self = this;
  21449. /**
  21450. * zrender instance in the Chart
  21451. * @type {zrender~ZRender}
  21452. */
  21453. this._zr = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.zrender.init(canvas);
  21454. var oldRefreshImmediately = this._zr.refreshImmediately;
  21455. this._zr.refreshImmediately = function () {
  21456. oldRefreshImmediately.call(this);
  21457. self._texture.dirty();
  21458. self.onupdate && self.onupdate();
  21459. };
  21460. this._dpr = opt.devicePixelRatio;
  21461. /**
  21462. * Texture coords map for each sprite image
  21463. * @type {Object}
  21464. */
  21465. this._coords = {};
  21466. this.onupdate = opt.onupdate;
  21467. this._gap = opt.gap;
  21468. // Left sub atlas.
  21469. this._textureAtlasNodes = [new ZRTextureAtlasSurfaceNode(
  21470. this._zr, 0, 0, opt.width, opt.height, this._gap, this._dpr
  21471. )];
  21472. this._nodeWidth = opt.width;
  21473. this._nodeHeight = opt.height;
  21474. this._currentNodeIdx = 0;
  21475. }
  21476. ZRTextureAtlasSurface.prototype = {
  21477. /**
  21478. * Clear the texture atlas
  21479. */
  21480. clear: function () {
  21481. for (var i = 0; i < this._textureAtlasNodes.length; i++) {
  21482. this._textureAtlasNodes[i].clear();
  21483. }
  21484. this._currentNodeIdx = 0;
  21485. this._zr.clear();
  21486. this._coords = {};
  21487. },
  21488. /**
  21489. * @return {number}
  21490. */
  21491. getWidth: function () {
  21492. return this._width;
  21493. },
  21494. /**
  21495. * @return {number}
  21496. */
  21497. getHeight: function () {
  21498. return this._height;
  21499. },
  21500. /**
  21501. * @return {number}
  21502. */
  21503. getTexture: function () {
  21504. return this._texture;
  21505. },
  21506. /**
  21507. * @return {number}
  21508. */
  21509. getDevicePixelRatio: function () {
  21510. return this._dpr;
  21511. },
  21512. getZr: function () {
  21513. return this._zr;
  21514. },
  21515. _getCurrentNode: function () {
  21516. return this._textureAtlasNodes[this._currentNodeIdx];
  21517. },
  21518. _expand: function () {
  21519. this._currentNodeIdx++;
  21520. if (this._textureAtlasNodes[this._currentNodeIdx]) {
  21521. // Use the node created previously.
  21522. return this._textureAtlasNodes[this._currentNodeIdx];
  21523. }
  21524. var maxSize = 4096 / this._dpr;
  21525. var textureAtlasNodes = this._textureAtlasNodes;
  21526. var nodeLen = textureAtlasNodes.length;
  21527. var offsetX = (nodeLen * this._nodeWidth) % maxSize;
  21528. var offsetY = Math.floor(nodeLen * this._nodeWidth / maxSize) * this._nodeHeight;
  21529. if (offsetY >= maxSize) {
  21530. // Failed if image is too large.
  21531. if (true) {
  21532. console.error('Too much labels. Some will be ignored.');
  21533. }
  21534. return;
  21535. }
  21536. var width = (offsetX + this._nodeWidth) * this._dpr;
  21537. var height = (offsetY + this._nodeHeight) * this._dpr;
  21538. try {
  21539. // Resize will error in node.
  21540. this._zr.resize({
  21541. width: width,
  21542. height: height
  21543. });
  21544. }
  21545. catch (e) {
  21546. this._canvas.width = width;
  21547. this._canvas.height = height;
  21548. }
  21549. var newNode = new ZRTextureAtlasSurfaceNode(
  21550. this._zr, offsetX, offsetY, this._nodeWidth, this._nodeHeight, this._gap, this._dpr
  21551. );
  21552. this._textureAtlasNodes.push(newNode);
  21553. return newNode;
  21554. },
  21555. add: function (el, width, height) {
  21556. if (this._coords[el.id]) {
  21557. if (true) {
  21558. console.warn('Element already been add');
  21559. }
  21560. return this._coords[el.id];
  21561. }
  21562. var coords = this._getCurrentNode().add(el, width, height);
  21563. if (!coords) {
  21564. var newNode = this._expand();
  21565. if (!newNode) {
  21566. // To maximum
  21567. return;
  21568. }
  21569. coords = newNode.add(el, width, height);
  21570. }
  21571. this._coords[el.id] = coords;
  21572. return coords;
  21573. },
  21574. /**
  21575. * Get coord scale after texture atlas is expanded.
  21576. * @return {Array.<number>}
  21577. */
  21578. getCoordsScale: function () {
  21579. var dpr = this._dpr;
  21580. return [this._nodeWidth / this._canvas.width * dpr, this._nodeHeight / this._canvas.height * dpr];
  21581. },
  21582. /**
  21583. * Get texture coords of sprite image
  21584. * @param {string} id Image id
  21585. * @return {Array}
  21586. */
  21587. getCoords: function (id) {
  21588. return this._coords[id];
  21589. }
  21590. };
  21591. /* harmony default export */ __webpack_exports__["a"] = (ZRTextureAtlasSurface);
  21592. /***/
  21593. }),
  21594. /* 82 */
  21595. /***/ (function (module, exports, __webpack_require__) {
  21596. var vec2 = __webpack_require__(83);
  21597. var matrix = __webpack_require__(84);
  21598. /**
  21599. * @module echarts/core/BoundingRect
  21600. */
  21601. var v2ApplyTransform = vec2.applyTransform;
  21602. var mathMin = Math.min;
  21603. var mathMax = Math.max;
  21604. /**
  21605. * @alias module:echarts/core/BoundingRect
  21606. */
  21607. function BoundingRect(x, y, width, height) {
  21608. if (width < 0) {
  21609. x = x + width;
  21610. width = -width;
  21611. }
  21612. if (height < 0) {
  21613. y = y + height;
  21614. height = -height;
  21615. }
  21616. /**
  21617. * @type {number}
  21618. */
  21619. this.x = x;
  21620. /**
  21621. * @type {number}
  21622. */
  21623. this.y = y;
  21624. /**
  21625. * @type {number}
  21626. */
  21627. this.width = width;
  21628. /**
  21629. * @type {number}
  21630. */
  21631. this.height = height;
  21632. }
  21633. BoundingRect.prototype = {
  21634. constructor: BoundingRect,
  21635. /**
  21636. * @param {module:echarts/core/BoundingRect} other
  21637. */
  21638. union: function (other) {
  21639. var x = mathMin(other.x, this.x);
  21640. var y = mathMin(other.y, this.y);
  21641. this.width = mathMax(other.x + other.width, this.x + this.width) - x;
  21642. this.height = mathMax(other.y + other.height, this.y + this.height) - y;
  21643. this.x = x;
  21644. this.y = y;
  21645. },
  21646. /**
  21647. * @param {Array.<number>} m
  21648. * @methods
  21649. */
  21650. applyTransform: function () {
  21651. var lt = [];
  21652. var rb = [];
  21653. var lb = [];
  21654. var rt = [];
  21655. return function (m) {
  21656. // In case usage like this
  21657. // el.getBoundingRect().applyTransform(el.transform)
  21658. // And element has no transform
  21659. if (!m) {
  21660. return;
  21661. }
  21662. lt[0] = lb[0] = this.x;
  21663. lt[1] = rt[1] = this.y;
  21664. rb[0] = rt[0] = this.x + this.width;
  21665. rb[1] = lb[1] = this.y + this.height;
  21666. v2ApplyTransform(lt, lt, m);
  21667. v2ApplyTransform(rb, rb, m);
  21668. v2ApplyTransform(lb, lb, m);
  21669. v2ApplyTransform(rt, rt, m);
  21670. this.x = mathMin(lt[0], rb[0], lb[0], rt[0]);
  21671. this.y = mathMin(lt[1], rb[1], lb[1], rt[1]);
  21672. var maxX = mathMax(lt[0], rb[0], lb[0], rt[0]);
  21673. var maxY = mathMax(lt[1], rb[1], lb[1], rt[1]);
  21674. this.width = maxX - this.x;
  21675. this.height = maxY - this.y;
  21676. };
  21677. }(),
  21678. /**
  21679. * Calculate matrix of transforming from self to target rect
  21680. * @param {module:zrender/core/BoundingRect} b
  21681. * @return {Array.<number>}
  21682. */
  21683. calculateTransform: function (b) {
  21684. var a = this;
  21685. var sx = b.width / a.width;
  21686. var sy = b.height / a.height;
  21687. var m = matrix.create(); // 矩阵右乘
  21688. matrix.translate(m, m, [-a.x, -a.y]);
  21689. matrix.scale(m, m, [sx, sy]);
  21690. matrix.translate(m, m, [b.x, b.y]);
  21691. return m;
  21692. },
  21693. /**
  21694. * @param {(module:echarts/core/BoundingRect|Object)} b
  21695. * @return {boolean}
  21696. */
  21697. intersect: function (b) {
  21698. if (!b) {
  21699. return false;
  21700. }
  21701. if (!(b instanceof BoundingRect)) {
  21702. // Normalize negative width/height.
  21703. b = BoundingRect.create(b);
  21704. }
  21705. var a = this;
  21706. var ax0 = a.x;
  21707. var ax1 = a.x + a.width;
  21708. var ay0 = a.y;
  21709. var ay1 = a.y + a.height;
  21710. var bx0 = b.x;
  21711. var bx1 = b.x + b.width;
  21712. var by0 = b.y;
  21713. var by1 = b.y + b.height;
  21714. return !(ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  21715. },
  21716. contain: function (x, y) {
  21717. var rect = this;
  21718. return x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height;
  21719. },
  21720. /**
  21721. * @return {module:echarts/core/BoundingRect}
  21722. */
  21723. clone: function () {
  21724. return new BoundingRect(this.x, this.y, this.width, this.height);
  21725. },
  21726. /**
  21727. * Copy from another rect
  21728. */
  21729. copy: function (other) {
  21730. this.x = other.x;
  21731. this.y = other.y;
  21732. this.width = other.width;
  21733. this.height = other.height;
  21734. },
  21735. plain: function () {
  21736. return {
  21737. x: this.x,
  21738. y: this.y,
  21739. width: this.width,
  21740. height: this.height
  21741. };
  21742. }
  21743. };
  21744. /**
  21745. * @param {Object|module:zrender/core/BoundingRect} rect
  21746. * @param {number} rect.x
  21747. * @param {number} rect.y
  21748. * @param {number} rect.width
  21749. * @param {number} rect.height
  21750. * @return {module:zrender/core/BoundingRect}
  21751. */
  21752. BoundingRect.create = function (rect) {
  21753. return new BoundingRect(rect.x, rect.y, rect.width, rect.height);
  21754. };
  21755. var _default = BoundingRect;
  21756. module.exports = _default;
  21757. /***/
  21758. }),
  21759. /* 83 */
  21760. /***/ (function (module, exports) {
  21761. var ArrayCtor = typeof Float32Array === 'undefined' ? Array : Float32Array;
  21762. /**
  21763. * 创建一个向量
  21764. * @param {number} [x=0]
  21765. * @param {number} [y=0]
  21766. * @return {Vector2}
  21767. */
  21768. function create(x, y) {
  21769. var out = new ArrayCtor(2);
  21770. if (x == null) {
  21771. x = 0;
  21772. }
  21773. if (y == null) {
  21774. y = 0;
  21775. }
  21776. out[0] = x;
  21777. out[1] = y;
  21778. return out;
  21779. }
  21780. /**
  21781. * 复制向量数据
  21782. * @param {Vector2} out
  21783. * @param {Vector2} v
  21784. * @return {Vector2}
  21785. */
  21786. function copy(out, v) {
  21787. out[0] = v[0];
  21788. out[1] = v[1];
  21789. return out;
  21790. }
  21791. /**
  21792. * 克隆一个向量
  21793. * @param {Vector2} v
  21794. * @return {Vector2}
  21795. */
  21796. function clone(v) {
  21797. var out = new ArrayCtor(2);
  21798. out[0] = v[0];
  21799. out[1] = v[1];
  21800. return out;
  21801. }
  21802. /**
  21803. * 设置向量的两个项
  21804. * @param {Vector2} out
  21805. * @param {number} a
  21806. * @param {number} b
  21807. * @return {Vector2} 结果
  21808. */
  21809. function set(out, a, b) {
  21810. out[0] = a;
  21811. out[1] = b;
  21812. return out;
  21813. }
  21814. /**
  21815. * 向量相åŠ
  21816. * @param {Vector2} out
  21817. * @param {Vector2} v1
  21818. * @param {Vector2} v2
  21819. */
  21820. function add(out, v1, v2) {
  21821. out[0] = v1[0] + v2[0];
  21822. out[1] = v1[1] + v2[1];
  21823. return out;
  21824. }
  21825. /**
  21826. * 向量缩放后相åŠ
  21827. * @param {Vector2} out
  21828. * @param {Vector2} v1
  21829. * @param {Vector2} v2
  21830. * @param {number} a
  21831. */
  21832. function scaleAndAdd(out, v1, v2, a) {
  21833. out[0] = v1[0] + v2[0] * a;
  21834. out[1] = v1[1] + v2[1] * a;
  21835. return out;
  21836. }
  21837. /**
  21838. * 向量相减
  21839. * @param {Vector2} out
  21840. * @param {Vector2} v1
  21841. * @param {Vector2} v2
  21842. */
  21843. function sub(out, v1, v2) {
  21844. out[0] = v1[0] - v2[0];
  21845. out[1] = v1[1] - v2[1];
  21846. return out;
  21847. }
  21848. /**
  21849. * 向量长度
  21850. * @param {Vector2} v
  21851. * @return {number}
  21852. */
  21853. function len(v) {
  21854. return Math.sqrt(lenSquare(v));
  21855. }
  21856. var length = len; // jshint ignore:line
  21857. /**
  21858. * 向量长度平方
  21859. * @param {Vector2} v
  21860. * @return {number}
  21861. */
  21862. function lenSquare(v) {
  21863. return v[0] * v[0] + v[1] * v[1];
  21864. }
  21865. var lengthSquare = lenSquare;
  21866. /**
  21867. * 向量乘法
  21868. * @param {Vector2} out
  21869. * @param {Vector2} v1
  21870. * @param {Vector2} v2
  21871. */
  21872. function mul(out, v1, v2) {
  21873. out[0] = v1[0] * v2[0];
  21874. out[1] = v1[1] * v2[1];
  21875. return out;
  21876. }
  21877. /**
  21878. * 向量除法
  21879. * @param {Vector2} out
  21880. * @param {Vector2} v1
  21881. * @param {Vector2} v2
  21882. */
  21883. function div(out, v1, v2) {
  21884. out[0] = v1[0] / v2[0];
  21885. out[1] = v1[1] / v2[1];
  21886. return out;
  21887. }
  21888. /**
  21889. * 向量点乘
  21890. * @param {Vector2} v1
  21891. * @param {Vector2} v2
  21892. * @return {number}
  21893. */
  21894. function dot(v1, v2) {
  21895. return v1[0] * v2[0] + v1[1] * v2[1];
  21896. }
  21897. /**
  21898. * 向量缩放
  21899. * @param {Vector2} out
  21900. * @param {Vector2} v
  21901. * @param {number} s
  21902. */
  21903. function scale(out, v, s) {
  21904. out[0] = v[0] * s;
  21905. out[1] = v[1] * s;
  21906. return out;
  21907. }
  21908. /**
  21909. * 向量归一化
  21910. * @param {Vector2} out
  21911. * @param {Vector2} v
  21912. */
  21913. function normalize(out, v) {
  21914. var d = len(v);
  21915. if (d === 0) {
  21916. out[0] = 0;
  21917. out[1] = 0;
  21918. } else {
  21919. out[0] = v[0] / d;
  21920. out[1] = v[1] / d;
  21921. }
  21922. return out;
  21923. }
  21924. /**
  21925. * 计算向量间距离
  21926. * @param {Vector2} v1
  21927. * @param {Vector2} v2
  21928. * @return {number}
  21929. */
  21930. function distance(v1, v2) {
  21931. return Math.sqrt((v1[0] - v2[0]) * (v1[0] - v2[0]) + (v1[1] - v2[1]) * (v1[1] - v2[1]));
  21932. }
  21933. var dist = distance;
  21934. /**
  21935. * 向量距离平方
  21936. * @param {Vector2} v1
  21937. * @param {Vector2} v2
  21938. * @return {number}
  21939. */
  21940. function distanceSquare(v1, v2) {
  21941. return (v1[0] - v2[0]) * (v1[0] - v2[0]) + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  21942. }
  21943. var distSquare = distanceSquare;
  21944. /**
  21945. * 求负向量
  21946. * @param {Vector2} out
  21947. * @param {Vector2} v
  21948. */
  21949. function negate(out, v) {
  21950. out[0] = -v[0];
  21951. out[1] = -v[1];
  21952. return out;
  21953. }
  21954. /**
  21955. * 插值两个点
  21956. * @param {Vector2} out
  21957. * @param {Vector2} v1
  21958. * @param {Vector2} v2
  21959. * @param {number} t
  21960. */
  21961. function lerp(out, v1, v2, t) {
  21962. out[0] = v1[0] + t * (v2[0] - v1[0]);
  21963. out[1] = v1[1] + t * (v2[1] - v1[1]);
  21964. return out;
  21965. }
  21966. /**
  21967. * 矩阵左乘向量
  21968. * @param {Vector2} out
  21969. * @param {Vector2} v
  21970. * @param {Vector2} m
  21971. */
  21972. function applyTransform(out, v, m) {
  21973. var x = v[0];
  21974. var y = v[1];
  21975. out[0] = m[0] * x + m[2] * y + m[4];
  21976. out[1] = m[1] * x + m[3] * y + m[5];
  21977. return out;
  21978. }
  21979. /**
  21980. * 求两个向量最小值
  21981. * @param {Vector2} out
  21982. * @param {Vector2} v1
  21983. * @param {Vector2} v2
  21984. */
  21985. function min(out, v1, v2) {
  21986. out[0] = Math.min(v1[0], v2[0]);
  21987. out[1] = Math.min(v1[1], v2[1]);
  21988. return out;
  21989. }
  21990. /**
  21991. * 求两个向量最大值
  21992. * @param {Vector2} out
  21993. * @param {Vector2} v1
  21994. * @param {Vector2} v2
  21995. */
  21996. function max(out, v1, v2) {
  21997. out[0] = Math.max(v1[0], v2[0]);
  21998. out[1] = Math.max(v1[1], v2[1]);
  21999. return out;
  22000. }
  22001. exports.create = create;
  22002. exports.copy = copy;
  22003. exports.clone = clone;
  22004. exports.set = set;
  22005. exports.add = add;
  22006. exports.scaleAndAdd = scaleAndAdd;
  22007. exports.sub = sub;
  22008. exports.len = len;
  22009. exports.length = length;
  22010. exports.lenSquare = lenSquare;
  22011. exports.lengthSquare = lengthSquare;
  22012. exports.mul = mul;
  22013. exports.div = div;
  22014. exports.dot = dot;
  22015. exports.scale = scale;
  22016. exports.normalize = normalize;
  22017. exports.distance = distance;
  22018. exports.dist = dist;
  22019. exports.distanceSquare = distanceSquare;
  22020. exports.distSquare = distSquare;
  22021. exports.negate = negate;
  22022. exports.lerp = lerp;
  22023. exports.applyTransform = applyTransform;
  22024. exports.min = min;
  22025. exports.max = max;
  22026. /***/
  22027. }),
  22028. /* 84 */
  22029. /***/ (function (module, exports) {
  22030. /**
  22031. * 3x2矩阵操作类
  22032. * @exports zrender/tool/matrix
  22033. */
  22034. var ArrayCtor = typeof Float32Array === 'undefined' ? Array : Float32Array;
  22035. /**
  22036. * Create a identity matrix.
  22037. * @return {Float32Array|Array.<number>}
  22038. */
  22039. function create() {
  22040. var out = new ArrayCtor(6);
  22041. identity(out);
  22042. return out;
  22043. }
  22044. /**
  22045. * 设置矩阵为单位矩阵
  22046. * @param {Float32Array|Array.<number>} out
  22047. */
  22048. function identity(out) {
  22049. out[0] = 1;
  22050. out[1] = 0;
  22051. out[2] = 0;
  22052. out[3] = 1;
  22053. out[4] = 0;
  22054. out[5] = 0;
  22055. return out;
  22056. }
  22057. /**
  22058. * 复制矩阵
  22059. * @param {Float32Array|Array.<number>} out
  22060. * @param {Float32Array|Array.<number>} m
  22061. */
  22062. function copy(out, m) {
  22063. out[0] = m[0];
  22064. out[1] = m[1];
  22065. out[2] = m[2];
  22066. out[3] = m[3];
  22067. out[4] = m[4];
  22068. out[5] = m[5];
  22069. return out;
  22070. }
  22071. /**
  22072. * 矩阵相乘
  22073. * @param {Float32Array|Array.<number>} out
  22074. * @param {Float32Array|Array.<number>} m1
  22075. * @param {Float32Array|Array.<number>} m2
  22076. */
  22077. function mul(out, m1, m2) {
  22078. // Consider matrix.mul(m, m2, m);
  22079. // where out is the same as m2.
  22080. // So use temp variable to escape error.
  22081. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  22082. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  22083. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  22084. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  22085. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  22086. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  22087. out[0] = out0;
  22088. out[1] = out1;
  22089. out[2] = out2;
  22090. out[3] = out3;
  22091. out[4] = out4;
  22092. out[5] = out5;
  22093. return out;
  22094. }
  22095. /**
  22096. * 平移变换
  22097. * @param {Float32Array|Array.<number>} out
  22098. * @param {Float32Array|Array.<number>} a
  22099. * @param {Float32Array|Array.<number>} v
  22100. */
  22101. function translate(out, a, v) {
  22102. out[0] = a[0];
  22103. out[1] = a[1];
  22104. out[2] = a[2];
  22105. out[3] = a[3];
  22106. out[4] = a[4] + v[0];
  22107. out[5] = a[5] + v[1];
  22108. return out;
  22109. }
  22110. /**
  22111. * 旋转变换
  22112. * @param {Float32Array|Array.<number>} out
  22113. * @param {Float32Array|Array.<number>} a
  22114. * @param {number} rad
  22115. */
  22116. function rotate(out, a, rad) {
  22117. var aa = a[0];
  22118. var ac = a[2];
  22119. var atx = a[4];
  22120. var ab = a[1];
  22121. var ad = a[3];
  22122. var aty = a[5];
  22123. var st = Math.sin(rad);
  22124. var ct = Math.cos(rad);
  22125. out[0] = aa * ct + ab * st;
  22126. out[1] = -aa * st + ab * ct;
  22127. out[2] = ac * ct + ad * st;
  22128. out[3] = -ac * st + ct * ad;
  22129. out[4] = ct * atx + st * aty;
  22130. out[5] = ct * aty - st * atx;
  22131. return out;
  22132. }
  22133. /**
  22134. * 缩放变换
  22135. * @param {Float32Array|Array.<number>} out
  22136. * @param {Float32Array|Array.<number>} a
  22137. * @param {Float32Array|Array.<number>} v
  22138. */
  22139. function scale(out, a, v) {
  22140. var vx = v[0];
  22141. var vy = v[1];
  22142. out[0] = a[0] * vx;
  22143. out[1] = a[1] * vy;
  22144. out[2] = a[2] * vx;
  22145. out[3] = a[3] * vy;
  22146. out[4] = a[4] * vx;
  22147. out[5] = a[5] * vy;
  22148. return out;
  22149. }
  22150. /**
  22151. * 求逆矩阵
  22152. * @param {Float32Array|Array.<number>} out
  22153. * @param {Float32Array|Array.<number>} a
  22154. */
  22155. function invert(out, a) {
  22156. var aa = a[0];
  22157. var ac = a[2];
  22158. var atx = a[4];
  22159. var ab = a[1];
  22160. var ad = a[3];
  22161. var aty = a[5];
  22162. var det = aa * ad - ab * ac;
  22163. if (!det) {
  22164. return null;
  22165. }
  22166. det = 1.0 / det;
  22167. out[0] = ad * det;
  22168. out[1] = -ab * det;
  22169. out[2] = -ac * det;
  22170. out[3] = aa * det;
  22171. out[4] = (ac * aty - ad * atx) * det;
  22172. out[5] = (ab * atx - aa * aty) * det;
  22173. return out;
  22174. }
  22175. /**
  22176. * Clone a new matrix.
  22177. * @param {Float32Array|Array.<number>} a
  22178. */
  22179. function clone(a) {
  22180. var b = create();
  22181. copy(b, a);
  22182. return b;
  22183. }
  22184. exports.create = create;
  22185. exports.identity = identity;
  22186. exports.copy = copy;
  22187. exports.mul = mul;
  22188. exports.translate = translate;
  22189. exports.rotate = rotate;
  22190. exports.scale = scale;
  22191. exports.invert = invert;
  22192. exports.clone = clone;
  22193. /***/
  22194. }),
  22195. /* 85 */
  22196. /***/ (function (module, exports, __webpack_require__) {
  22197. var zrUtil = __webpack_require__(13);
  22198. /*
  22199. * Licensed to the Apache Software Foundation (ASF) under one
  22200. * or more contributor license agreements. See the NOTICE file
  22201. * distributed with this work for additional information
  22202. * regarding copyright ownership. The ASF licenses this file
  22203. * to you under the Apache License, Version 2.0 (the
  22204. * "License"); you may not use this file except in compliance
  22205. * with the License. You may obtain a copy of the License at
  22206. *
  22207. * http://www.apache.org/licenses/LICENSE-2.0
  22208. *
  22209. * Unless required by applicable law or agreed to in writing,
  22210. * software distributed under the License is distributed on an
  22211. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22212. * KIND, either express or implied. See the License for the
  22213. * specific language governing permissions and limitations
  22214. * under the License.
  22215. */
  22216. var RADIAN_EPSILON = 1e-4;
  22217. function _trim(str) {
  22218. return str.replace(/^\s+/, '').replace(/\s+$/, '');
  22219. }
  22220. /**
  22221. * Linear mapping a value from domain to range
  22222. * @memberOf module:echarts/util/number
  22223. * @param {(number|Array.<number>)} val
  22224. * @param {Array.<number>} domain Domain extent domain[0] can be bigger than domain[1]
  22225. * @param {Array.<number>} range Range extent range[0] can be bigger than range[1]
  22226. * @param {boolean} clamp
  22227. * @return {(number|Array.<number>}
  22228. */
  22229. function linearMap(val, domain, range, clamp) {
  22230. var subDomain = domain[1] - domain[0];
  22231. var subRange = range[1] - range[0];
  22232. if (subDomain === 0) {
  22233. return subRange === 0 ? range[0] : (range[0] + range[1]) / 2;
  22234. } // Avoid accuracy problem in edge, such as
  22235. // 146.39 - 62.83 === 83.55999999999999.
  22236. // See echarts/test/ut/spec/util/number.js#linearMap#accuracyError
  22237. // It is a little verbose for efficiency considering this method
  22238. // is a hotspot.
  22239. if (clamp) {
  22240. if (subDomain > 0) {
  22241. if (val <= domain[0]) {
  22242. return range[0];
  22243. } else if (val >= domain[1]) {
  22244. return range[1];
  22245. }
  22246. } else {
  22247. if (val >= domain[0]) {
  22248. return range[0];
  22249. } else if (val <= domain[1]) {
  22250. return range[1];
  22251. }
  22252. }
  22253. } else {
  22254. if (val === domain[0]) {
  22255. return range[0];
  22256. }
  22257. if (val === domain[1]) {
  22258. return range[1];
  22259. }
  22260. }
  22261. return (val - domain[0]) / subDomain * subRange + range[0];
  22262. }
  22263. /**
  22264. * Convert a percent string to absolute number.
  22265. * Returns NaN if percent is not a valid string or number
  22266. * @memberOf module:echarts/util/number
  22267. * @param {string|number} percent
  22268. * @param {number} all
  22269. * @return {number}
  22270. */
  22271. function parsePercent(percent, all) {
  22272. switch (percent) {
  22273. case 'center':
  22274. case 'middle':
  22275. percent = '50%';
  22276. break;
  22277. case 'left':
  22278. case 'top':
  22279. percent = '0%';
  22280. break;
  22281. case 'right':
  22282. case 'bottom':
  22283. percent = '100%';
  22284. break;
  22285. }
  22286. if (typeof percent === 'string') {
  22287. if (_trim(percent).match(/%$/)) {
  22288. return parseFloat(percent) / 100 * all;
  22289. }
  22290. return parseFloat(percent);
  22291. }
  22292. return percent == null ? NaN : +percent;
  22293. }
  22294. /**
  22295. * (1) Fix rounding error of float numbers.
  22296. * (2) Support return string to avoid scientific notation like '3.5e-7'.
  22297. *
  22298. * @param {number} x
  22299. * @param {number} [precision]
  22300. * @param {boolean} [returnStr]
  22301. * @return {number|string}
  22302. */
  22303. function round(x, precision, returnStr) {
  22304. if (precision == null) {
  22305. precision = 10;
  22306. } // Avoid range error
  22307. precision = Math.min(Math.max(0, precision), 20);
  22308. x = (+x).toFixed(precision);
  22309. return returnStr ? x : +x;
  22310. }
  22311. function asc(arr) {
  22312. arr.sort(function (a, b) {
  22313. return a - b;
  22314. });
  22315. return arr;
  22316. }
  22317. /**
  22318. * Get precision
  22319. * @param {number} val
  22320. */
  22321. function getPrecision(val) {
  22322. val = +val;
  22323. if (isNaN(val)) {
  22324. return 0;
  22325. } // It is much faster than methods converting number to string as follows
  22326. // var tmp = val.toString();
  22327. // return tmp.length - 1 - tmp.indexOf('.');
  22328. // especially when precision is low
  22329. var e = 1;
  22330. var count = 0;
  22331. while (Math.round(val * e) / e !== val) {
  22332. e *= 10;
  22333. count++;
  22334. }
  22335. return count;
  22336. }
  22337. /**
  22338. * @param {string|number} val
  22339. * @return {number}
  22340. */
  22341. function getPrecisionSafe(val) {
  22342. var str = val.toString(); // Consider scientific notation: '3.4e-12' '3.4e+12'
  22343. var eIndex = str.indexOf('e');
  22344. if (eIndex > 0) {
  22345. var precision = +str.slice(eIndex + 1);
  22346. return precision < 0 ? -precision : 0;
  22347. } else {
  22348. var dotIndex = str.indexOf('.');
  22349. return dotIndex < 0 ? 0 : str.length - 1 - dotIndex;
  22350. }
  22351. }
  22352. /**
  22353. * Minimal dicernible data precisioin according to a single pixel.
  22354. *
  22355. * @param {Array.<number>} dataExtent
  22356. * @param {Array.<number>} pixelExtent
  22357. * @return {number} precision
  22358. */
  22359. function getPixelPrecision(dataExtent, pixelExtent) {
  22360. var log = Math.log;
  22361. var LN10 = Math.LN10;
  22362. var dataQuantity = Math.floor(log(dataExtent[1] - dataExtent[0]) / LN10);
  22363. var sizeQuantity = Math.round(log(Math.abs(pixelExtent[1] - pixelExtent[0])) / LN10); // toFixed() digits argument must be between 0 and 20.
  22364. var precision = Math.min(Math.max(-dataQuantity + sizeQuantity, 0), 20);
  22365. return !isFinite(precision) ? 20 : precision;
  22366. }
  22367. /**
  22368. * Get a data of given precision, assuring the sum of percentages
  22369. * in valueList is 1.
  22370. * The largest remainer method is used.
  22371. * https://en.wikipedia.org/wiki/Largest_remainder_method
  22372. *
  22373. * @param {Array.<number>} valueList a list of all data
  22374. * @param {number} idx index of the data to be processed in valueList
  22375. * @param {number} precision integer number showing digits of precision
  22376. * @return {number} percent ranging from 0 to 100
  22377. */
  22378. function getPercentWithPrecision(valueList, idx, precision) {
  22379. if (!valueList[idx]) {
  22380. return 0;
  22381. }
  22382. var sum = zrUtil.reduce(valueList, function (acc, val) {
  22383. return acc + (isNaN(val) ? 0 : val);
  22384. }, 0);
  22385. if (sum === 0) {
  22386. return 0;
  22387. }
  22388. var digits = Math.pow(10, precision);
  22389. var votesPerQuota = zrUtil.map(valueList, function (val) {
  22390. return (isNaN(val) ? 0 : val) / sum * digits * 100;
  22391. });
  22392. var targetSeats = digits * 100;
  22393. var seats = zrUtil.map(votesPerQuota, function (votes) {
  22394. // Assign automatic seats.
  22395. return Math.floor(votes);
  22396. });
  22397. var currentSum = zrUtil.reduce(seats, function (acc, val) {
  22398. return acc + val;
  22399. }, 0);
  22400. var remainder = zrUtil.map(votesPerQuota, function (votes, idx) {
  22401. return votes - seats[idx];
  22402. }); // Has remainding votes.
  22403. while (currentSum < targetSeats) {
  22404. // Find next largest remainder.
  22405. var max = Number.NEGATIVE_INFINITY;
  22406. var maxId = null;
  22407. for (var i = 0, len = remainder.length; i < len; ++i) {
  22408. if (remainder[i] > max) {
  22409. max = remainder[i];
  22410. maxId = i;
  22411. }
  22412. } // Add a vote to max remainder.
  22413. ++seats[maxId];
  22414. remainder[maxId] = 0;
  22415. ++currentSum;
  22416. }
  22417. return seats[idx] / digits;
  22418. } // Number.MAX_SAFE_INTEGER, ie do not support.
  22419. var MAX_SAFE_INTEGER = 9007199254740991;
  22420. /**
  22421. * To 0 - 2 * PI, considering negative radian.
  22422. * @param {number} radian
  22423. * @return {number}
  22424. */
  22425. function remRadian(radian) {
  22426. var pi2 = Math.PI * 2;
  22427. return (radian % pi2 + pi2) % pi2;
  22428. }
  22429. /**
  22430. * @param {type} radian
  22431. * @return {boolean}
  22432. */
  22433. function isRadianAroundZero(val) {
  22434. return val > -RADIAN_EPSILON && val < RADIAN_EPSILON;
  22435. }
  22436. var TIME_REG = /^(?:(\d{4})(?:[-\/](\d{1,2})(?:[-\/](\d{1,2})(?:[T ](\d{1,2})(?::(\d\d)(?::(\d\d)(?:[.,](\d+))?)?)?(Z|[\+\-]\d\d:?\d\d)?)?)?)?)?$/; // jshint ignore:line
  22437. /**
  22438. * @param {string|Date|number} value These values can be accepted:
  22439. * + An instance of Date, represent a time in its own time zone.
  22440. * + Or string in a subset of ISO 8601, only including:
  22441. * + only year, month, date: '2012-03', '2012-03-01', '2012-03-01 05', '2012-03-01 05:06',
  22442. * + separated with T or space: '2012-03-01T12:22:33.123', '2012-03-01 12:22:33.123',
  22443. * + time zone: '2012-03-01T12:22:33Z', '2012-03-01T12:22:33+8000', '2012-03-01T12:22:33-05:00',
  22444. * all of which will be treated as local time if time zone is not specified
  22445. * (see <https://momentjs.com/>).
  22446. * + Or other string format, including (all of which will be treated as loacal time):
  22447. * '2012', '2012-3-1', '2012/3/1', '2012/03/01',
  22448. * '2009/6/12 2:00', '2009/6/12 2:05:08', '2009/6/12 2:05:08.123'
  22449. * + a timestamp, which represent a time in UTC.
  22450. * @return {Date} date
  22451. */
  22452. function parseDate(value) {
  22453. if (value instanceof Date) {
  22454. return value;
  22455. } else if (typeof value === 'string') {
  22456. // Different browsers parse date in different way, so we parse it manually.
  22457. // Some other issues:
  22458. // new Date('1970-01-01') is UTC,
  22459. // new Date('1970/01/01') and new Date('1970-1-01') is local.
  22460. // See issue #3623
  22461. var match = TIME_REG.exec(value);
  22462. if (!match) {
  22463. // return Invalid Date.
  22464. return new Date(NaN);
  22465. } // Use local time when no timezone offset specifed.
  22466. if (!match[8]) {
  22467. // match[n] can only be string or undefined.
  22468. // But take care of '12' + 1 => '121'.
  22469. return new Date(+match[1], +(match[2] || 1) - 1, +match[3] || 1, +match[4] || 0, +(match[5] || 0), +match[6] || 0, +match[7] || 0);
  22470. } // Timezoneoffset of Javascript Date has considered DST (Daylight Saving Time,
  22471. // https://tc39.github.io/ecma262/#sec-daylight-saving-time-adjustment).
  22472. // For example, system timezone is set as "Time Zone: America/Toronto",
  22473. // then these code will get different result:
  22474. // `new Date(1478411999999).getTimezoneOffset(); // get 240`
  22475. // `new Date(1478412000000).getTimezoneOffset(); // get 300`
  22476. // So we should not use `new Date`, but use `Date.UTC`.
  22477. else {
  22478. var hour = +match[4] || 0;
  22479. if (match[8].toUpperCase() !== 'Z') {
  22480. hour -= match[8].slice(0, 3);
  22481. }
  22482. return new Date(Date.UTC(+match[1], +(match[2] || 1) - 1, +match[3] || 1, hour, +(match[5] || 0), +match[6] || 0, +match[7] || 0));
  22483. }
  22484. } else if (value == null) {
  22485. return new Date(NaN);
  22486. }
  22487. return new Date(Math.round(value));
  22488. }
  22489. /**
  22490. * Quantity of a number. e.g. 0.1, 1, 10, 100
  22491. *
  22492. * @param {number} val
  22493. * @return {number}
  22494. */
  22495. function quantity(val) {
  22496. return Math.pow(10, quantityExponent(val));
  22497. }
  22498. function quantityExponent(val) {
  22499. return Math.floor(Math.log(val) / Math.LN10);
  22500. }
  22501. /**
  22502. * find a “nice” number approximately equal to x. Round the number if round = true,
  22503. * take ceiling if round = false. The primary observation is that the “nicest”
  22504. * numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
  22505. *
  22506. * See "Nice Numbers for Graph Labels" of Graphic Gems.
  22507. *
  22508. * @param {number} val Non-negative value.
  22509. * @param {boolean} round
  22510. * @return {number}
  22511. */
  22512. function nice(val, round) {
  22513. var exponent = quantityExponent(val);
  22514. var exp10 = Math.pow(10, exponent);
  22515. var f = val / exp10; // 1 <= f < 10
  22516. var nf;
  22517. if (round) {
  22518. if (f < 1.5) {
  22519. nf = 1;
  22520. } else if (f < 2.5) {
  22521. nf = 2;
  22522. } else if (f < 4) {
  22523. nf = 3;
  22524. } else if (f < 7) {
  22525. nf = 5;
  22526. } else {
  22527. nf = 10;
  22528. }
  22529. } else {
  22530. if (f < 1) {
  22531. nf = 1;
  22532. } else if (f < 2) {
  22533. nf = 2;
  22534. } else if (f < 3) {
  22535. nf = 3;
  22536. } else if (f < 5) {
  22537. nf = 5;
  22538. } else {
  22539. nf = 10;
  22540. }
  22541. }
  22542. val = nf * exp10; // Fix 3 * 0.1 === 0.30000000000000004 issue (see IEEE 754).
  22543. // 20 is the uppper bound of toFixed.
  22544. return exponent >= -20 ? +val.toFixed(exponent < 0 ? -exponent : 0) : val;
  22545. }
  22546. /**
  22547. * Order intervals asc, and split them when overlap.
  22548. * expect(numberUtil.reformIntervals([
  22549. * {interval: [18, 62], close: [1, 1]},
  22550. * {interval: [-Infinity, -70], close: [0, 0]},
  22551. * {interval: [-70, -26], close: [1, 1]},
  22552. * {interval: [-26, 18], close: [1, 1]},
  22553. * {interval: [62, 150], close: [1, 1]},
  22554. * {interval: [106, 150], close: [1, 1]},
  22555. * {interval: [150, Infinity], close: [0, 0]}
  22556. * ])).toEqual([
  22557. * {interval: [-Infinity, -70], close: [0, 0]},
  22558. * {interval: [-70, -26], close: [1, 1]},
  22559. * {interval: [-26, 18], close: [0, 1]},
  22560. * {interval: [18, 62], close: [0, 1]},
  22561. * {interval: [62, 150], close: [0, 1]},
  22562. * {interval: [150, Infinity], close: [0, 0]}
  22563. * ]);
  22564. * @param {Array.<Object>} list, where `close` mean open or close
  22565. * of the interval, and Infinity can be used.
  22566. * @return {Array.<Object>} The origin list, which has been reformed.
  22567. */
  22568. function reformIntervals(list) {
  22569. list.sort(function (a, b) {
  22570. return littleThan(a, b, 0) ? -1 : 1;
  22571. });
  22572. var curr = -Infinity;
  22573. var currClose = 1;
  22574. for (var i = 0; i < list.length;) {
  22575. var interval = list[i].interval;
  22576. var close = list[i].close;
  22577. for (var lg = 0; lg < 2; lg++) {
  22578. if (interval[lg] <= curr) {
  22579. interval[lg] = curr;
  22580. close[lg] = !lg ? 1 - currClose : 1;
  22581. }
  22582. curr = interval[lg];
  22583. currClose = close[lg];
  22584. }
  22585. if (interval[0] === interval[1] && close[0] * close[1] !== 1) {
  22586. list.splice(i, 1);
  22587. } else {
  22588. i++;
  22589. }
  22590. }
  22591. return list;
  22592. function littleThan(a, b, lg) {
  22593. return a.interval[lg] < b.interval[lg] || a.interval[lg] === b.interval[lg] && (a.close[lg] - b.close[lg] === (!lg ? 1 : -1) || !lg && littleThan(a, b, 1));
  22594. }
  22595. }
  22596. /**
  22597. * parseFloat NaNs numeric-cast false positives (null|true|false|"")
  22598. * ...but misinterprets leading-number strings, particularly hex literals ("0x...")
  22599. * subtraction forces infinities to NaN
  22600. *
  22601. * @param {*} v
  22602. * @return {boolean}
  22603. */
  22604. function isNumeric(v) {
  22605. return v - parseFloat(v) >= 0;
  22606. }
  22607. exports.linearMap = linearMap;
  22608. exports.parsePercent = parsePercent;
  22609. exports.round = round;
  22610. exports.asc = asc;
  22611. exports.getPrecision = getPrecision;
  22612. exports.getPrecisionSafe = getPrecisionSafe;
  22613. exports.getPixelPrecision = getPixelPrecision;
  22614. exports.getPercentWithPrecision = getPercentWithPrecision;
  22615. exports.MAX_SAFE_INTEGER = MAX_SAFE_INTEGER;
  22616. exports.remRadian = remRadian;
  22617. exports.isRadianAroundZero = isRadianAroundZero;
  22618. exports.parseDate = parseDate;
  22619. exports.quantity = quantity;
  22620. exports.nice = nice;
  22621. exports.reformIntervals = reformIntervals;
  22622. exports.isNumeric = isNumeric;
  22623. /***/
  22624. }),
  22625. /* 86 */
  22626. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  22627. "use strict";
  22628. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Texture2D__ = __webpack_require__(5);
  22629. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__core_glenum__ = __webpack_require__(11);
  22630. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__core_util__ = __webpack_require__(23);
  22631. var TexturePool = function () {
  22632. this._pool = {};
  22633. this._allocatedTextures = [];
  22634. };
  22635. TexturePool.prototype = {
  22636. constructor: TexturePool,
  22637. get: function (parameters) {
  22638. var key = generateKey(parameters);
  22639. if (!this._pool.hasOwnProperty(key)) {
  22640. this._pool[key] = [];
  22641. }
  22642. var list = this._pool[key];
  22643. if (!list.length) {
  22644. var texture = new __WEBPACK_IMPORTED_MODULE_0__Texture2D__["a" /* default */](parameters);
  22645. this._allocatedTextures.push(texture);
  22646. return texture;
  22647. }
  22648. return list.pop();
  22649. },
  22650. put: function (texture) {
  22651. var key = generateKey(texture);
  22652. if (!this._pool.hasOwnProperty(key)) {
  22653. this._pool[key] = [];
  22654. }
  22655. var list = this._pool[key];
  22656. list.push(texture);
  22657. },
  22658. clear: function (renderer) {
  22659. for (var i = 0; i < this._allocatedTextures.length; i++) {
  22660. this._allocatedTextures[i].dispose(renderer);
  22661. }
  22662. this._pool = {};
  22663. this._allocatedTextures = [];
  22664. }
  22665. };
  22666. var defaultParams = {
  22667. width: 512,
  22668. height: 512,
  22669. type: __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].UNSIGNED_BYTE,
  22670. format: __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].RGBA,
  22671. wrapS: __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].CLAMP_TO_EDGE,
  22672. wrapT: __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].CLAMP_TO_EDGE,
  22673. minFilter: __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LINEAR_MIPMAP_LINEAR,
  22674. magFilter: __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LINEAR,
  22675. useMipmap: true,
  22676. anisotropic: 1,
  22677. flipY: true,
  22678. unpackAlignment: 4,
  22679. premultiplyAlpha: false
  22680. };
  22681. var defaultParamPropList = Object.keys(defaultParams);
  22682. function generateKey(parameters) {
  22683. __WEBPACK_IMPORTED_MODULE_2__core_util__["a" /* default */].defaultsWithPropList(parameters, defaultParams, defaultParamPropList);
  22684. fallBack(parameters);
  22685. var key = '';
  22686. for (var i = 0; i < defaultParamPropList.length; i++) {
  22687. var name = defaultParamPropList[i];
  22688. var chunk = parameters[name].toString();
  22689. key += chunk;
  22690. }
  22691. return key;
  22692. }
  22693. function fallBack(target) {
  22694. var IPOT = isPowerOfTwo(target.width, target.height);
  22695. if (target.format === __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].DEPTH_COMPONENT) {
  22696. target.useMipmap = false;
  22697. }
  22698. if (!IPOT || !target.useMipmap) {
  22699. if (target.minFilter == __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].NEAREST_MIPMAP_NEAREST ||
  22700. target.minFilter == __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].NEAREST_MIPMAP_LINEAR) {
  22701. target.minFilter = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].NEAREST;
  22702. } else if (
  22703. target.minFilter == __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LINEAR_MIPMAP_LINEAR ||
  22704. target.minFilter == __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LINEAR_MIPMAP_NEAREST
  22705. ) {
  22706. target.minFilter = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].LINEAR;
  22707. }
  22708. }
  22709. if (!IPOT) {
  22710. target.wrapS = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].CLAMP_TO_EDGE;
  22711. target.wrapT = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].CLAMP_TO_EDGE;
  22712. }
  22713. }
  22714. function isPowerOfTwo(width, height) {
  22715. return (width & (width - 1)) === 0 &&
  22716. (height & (height - 1)) === 0;
  22717. }
  22718. /* harmony default export */ __webpack_exports__["a"] = (TexturePool);
  22719. /***/
  22720. }),
  22721. /* 87 */
  22722. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  22723. "use strict";
  22724. /* harmony default export */ __webpack_exports__["a"] = ("@export clay.compositor.kernel.gaussian_9\nfloat gaussianKernel[9];\ngaussianKernel[0] = 0.07;\ngaussianKernel[1] = 0.09;\ngaussianKernel[2] = 0.12;\ngaussianKernel[3] = 0.14;\ngaussianKernel[4] = 0.16;\ngaussianKernel[5] = 0.14;\ngaussianKernel[6] = 0.12;\ngaussianKernel[7] = 0.09;\ngaussianKernel[8] = 0.07;\n@end\n@export clay.compositor.kernel.gaussian_13\nfloat gaussianKernel[13];\ngaussianKernel[0] = 0.02;\ngaussianKernel[1] = 0.03;\ngaussianKernel[2] = 0.06;\ngaussianKernel[3] = 0.08;\ngaussianKernel[4] = 0.11;\ngaussianKernel[5] = 0.13;\ngaussianKernel[6] = 0.14;\ngaussianKernel[7] = 0.13;\ngaussianKernel[8] = 0.11;\ngaussianKernel[9] = 0.08;\ngaussianKernel[10] = 0.06;\ngaussianKernel[11] = 0.03;\ngaussianKernel[12] = 0.02;\n@end\n@export clay.compositor.gaussian_blur\n#define SHADER_NAME gaussian_blur\nuniform sampler2D texture;varying vec2 v_Texcoord;\nuniform float blurSize : 2.0;\nuniform vec2 textureSize : [512.0, 512.0];\nuniform float blurDir : 0.0;\n@import clay.util.rgbm\n@import clay.util.clamp_sample\nvoid main (void)\n{\n @import clay.compositor.kernel.gaussian_9\n vec2 off = blurSize / textureSize;\n off *= vec2(1.0 - blurDir, blurDir);\n vec4 sum = vec4(0.0);\n float weightAll = 0.0;\n for (int i = 0; i < 9; i++) {\n float w = gaussianKernel[i];\n vec4 texel = decodeHDR(clampSample(texture, v_Texcoord + float(i - 4) * off));\n sum += texel * w;\n weightAll += w;\n }\n gl_FragColor = encodeHDR(sum / max(weightAll, 0.01));\n}\n@end\n");
  22725. /***/
  22726. }),
  22727. /* 88 */
  22728. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  22729. "use strict";
  22730. /* harmony default export */ __webpack_exports__["a"] = ("\n@export clay.compositor.lut\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\nuniform sampler2D lookup;\nvoid main()\n{\n vec4 tex = texture2D(texture, v_Texcoord);\n float blueColor = tex.b * 63.0;\n vec2 quad1;\n quad1.y = floor(floor(blueColor) / 8.0);\n quad1.x = floor(blueColor) - (quad1.y * 8.0);\n vec2 quad2;\n quad2.y = floor(ceil(blueColor) / 8.0);\n quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n vec2 texPos1;\n texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.r);\n texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.g);\n vec2 texPos2;\n texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.r);\n texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.g);\n vec4 newColor1 = texture2D(lookup, texPos1);\n vec4 newColor2 = texture2D(lookup, texPos2);\n vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n gl_FragColor = vec4(newColor.rgb, tex.w);\n}\n@end");
  22731. /***/
  22732. }),
  22733. /* 89 */
  22734. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  22735. "use strict";
  22736. /* harmony default export */ __webpack_exports__["a"] = ("@export clay.compositor.output\n#define OUTPUT_ALPHA\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\n@import clay.util.rgbm\nvoid main()\n{\n vec4 tex = decodeHDR(texture2D(texture, v_Texcoord));\n gl_FragColor.rgb = tex.rgb;\n#ifdef OUTPUT_ALPHA\n gl_FragColor.a = tex.a;\n#else\n gl_FragColor.a = 1.0;\n#endif\n gl_FragColor = encodeHDR(gl_FragColor);\n#ifdef PREMULTIPLY_ALPHA\n gl_FragColor.rgb *= gl_FragColor.a;\n#endif\n}\n@end");
  22737. /***/
  22738. }),
  22739. /* 90 */
  22740. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  22741. "use strict";
  22742. /* harmony default export */ __webpack_exports__["a"] = ("@export clay.compositor.bright\nuniform sampler2D texture;\nuniform float threshold : 1;\nuniform float scale : 1.0;\nuniform vec2 textureSize: [512, 512];\nvarying vec2 v_Texcoord;\nconst vec3 lumWeight = vec3(0.2125, 0.7154, 0.0721);\n@import clay.util.rgbm\nvec4 median(vec4 a, vec4 b, vec4 c)\n{\n return a + b + c - min(min(a, b), c) - max(max(a, b), c);\n}\nvoid main()\n{\n vec4 texel = decodeHDR(texture2D(texture, v_Texcoord));\n#ifdef ANTI_FLICKER\n vec3 d = 1.0 / textureSize.xyx * vec3(1.0, 1.0, 0.0);\n vec4 s1 = decodeHDR(texture2D(texture, v_Texcoord - d.xz));\n vec4 s2 = decodeHDR(texture2D(texture, v_Texcoord + d.xz));\n vec4 s3 = decodeHDR(texture2D(texture, v_Texcoord - d.zy));\n vec4 s4 = decodeHDR(texture2D(texture, v_Texcoord + d.zy));\n texel = median(median(texel, s1, s2), s3, s4);\n#endif\n float lum = dot(texel.rgb , lumWeight);\n vec4 color;\n if (lum > threshold && texel.a > 0.0)\n {\n color = vec4(texel.rgb * scale, texel.a * scale);\n }\n else\n {\n color = vec4(0.0);\n }\n gl_FragColor = encodeHDR(color);\n}\n@end\n");
  22743. /***/
  22744. }),
  22745. /* 91 */
  22746. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  22747. "use strict";
  22748. /* harmony default export */ __webpack_exports__["a"] = ("@export clay.compositor.downsample\nuniform sampler2D texture;\nuniform vec2 textureSize : [512, 512];\nvarying vec2 v_Texcoord;\n@import clay.util.rgbm\nfloat brightness(vec3 c)\n{\n return max(max(c.r, c.g), c.b);\n}\n@import clay.util.clamp_sample\nvoid main()\n{\n vec4 d = vec4(-1.0, -1.0, 1.0, 1.0) / textureSize.xyxy;\n#ifdef ANTI_FLICKER\n vec3 s1 = decodeHDR(clampSample(texture, v_Texcoord + d.xy)).rgb;\n vec3 s2 = decodeHDR(clampSample(texture, v_Texcoord + d.zy)).rgb;\n vec3 s3 = decodeHDR(clampSample(texture, v_Texcoord + d.xw)).rgb;\n vec3 s4 = decodeHDR(clampSample(texture, v_Texcoord + d.zw)).rgb;\n float s1w = 1.0 / (brightness(s1) + 1.0);\n float s2w = 1.0 / (brightness(s2) + 1.0);\n float s3w = 1.0 / (brightness(s3) + 1.0);\n float s4w = 1.0 / (brightness(s4) + 1.0);\n float oneDivideSum = 1.0 / (s1w + s2w + s3w + s4w);\n vec4 color = vec4(\n (s1 * s1w + s2 * s2w + s3 * s3w + s4 * s4w) * oneDivideSum,\n 1.0\n );\n#else\n vec4 color = decodeHDR(clampSample(texture, v_Texcoord + d.xy));\n color += decodeHDR(clampSample(texture, v_Texcoord + d.zy));\n color += decodeHDR(clampSample(texture, v_Texcoord + d.xw));\n color += decodeHDR(clampSample(texture, v_Texcoord + d.zw));\n color *= 0.25;\n#endif\n gl_FragColor = encodeHDR(color);\n}\n@end");
  22749. /***/
  22750. }),
  22751. /* 92 */
  22752. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  22753. "use strict";
  22754. /* harmony default export */ __webpack_exports__["a"] = ("\n@export clay.compositor.upsample\n#define HIGH_QUALITY\nuniform sampler2D texture;\nuniform vec2 textureSize : [512, 512];\nuniform float sampleScale: 0.5;\nvarying vec2 v_Texcoord;\n@import clay.util.rgbm\n@import clay.util.clamp_sample\nvoid main()\n{\n#ifdef HIGH_QUALITY\n vec4 d = vec4(1.0, 1.0, -1.0, 0.0) / textureSize.xyxy * sampleScale;\n vec4 s;\n s = decodeHDR(clampSample(texture, v_Texcoord - d.xy));\n s += decodeHDR(clampSample(texture, v_Texcoord - d.wy)) * 2.0;\n s += decodeHDR(clampSample(texture, v_Texcoord - d.zy));\n s += decodeHDR(clampSample(texture, v_Texcoord + d.zw)) * 2.0;\n s += decodeHDR(clampSample(texture, v_Texcoord )) * 4.0;\n s += decodeHDR(clampSample(texture, v_Texcoord + d.xw)) * 2.0;\n s += decodeHDR(clampSample(texture, v_Texcoord + d.zy));\n s += decodeHDR(clampSample(texture, v_Texcoord + d.wy)) * 2.0;\n s += decodeHDR(clampSample(texture, v_Texcoord + d.xy));\n gl_FragColor = encodeHDR(s / 16.0);\n#else\n vec4 d = vec4(-1.0, -1.0, +1.0, +1.0) / textureSize.xyxy;\n vec4 s;\n s = decodeHDR(clampSample(texture, v_Texcoord + d.xy));\n s += decodeHDR(clampSample(texture, v_Texcoord + d.zy));\n s += decodeHDR(clampSample(texture, v_Texcoord + d.xw));\n s += decodeHDR(clampSample(texture, v_Texcoord + d.zw));\n gl_FragColor = encodeHDR(s / 4.0);\n#endif\n}\n@end");
  22755. /***/
  22756. }),
  22757. /* 93 */
  22758. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  22759. "use strict";
  22760. /* harmony default export */ __webpack_exports__["a"] = ("@export clay.compositor.hdr.composite\n#define TONEMAPPING\nuniform sampler2D texture;\n#ifdef BLOOM_ENABLED\nuniform sampler2D bloom;\n#endif\n#ifdef LENSFLARE_ENABLED\nuniform sampler2D lensflare;\nuniform sampler2D lensdirt;\n#endif\n#ifdef LUM_ENABLED\nuniform sampler2D lum;\n#endif\n#ifdef LUT_ENABLED\nuniform sampler2D lut;\n#endif\n#ifdef COLOR_CORRECTION\nuniform float brightness : 0.0;\nuniform float contrast : 1.0;\nuniform float saturation : 1.0;\n#endif\n#ifdef VIGNETTE\nuniform float vignetteDarkness: 1.0;\nuniform float vignetteOffset: 1.0;\n#endif\nuniform float exposure : 1.0;\nuniform float bloomIntensity : 0.25;\nuniform float lensflareIntensity : 1;\nvarying vec2 v_Texcoord;\n@import clay.util.srgb\nvec3 ACESToneMapping(vec3 color)\n{\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nfloat eyeAdaption(float fLum)\n{\n return mix(0.2, fLum, 0.5);\n}\n#ifdef LUT_ENABLED\nvec3 lutTransform(vec3 color) {\n float blueColor = color.b * 63.0;\n vec2 quad1;\n quad1.y = floor(floor(blueColor) / 8.0);\n quad1.x = floor(blueColor) - (quad1.y * 8.0);\n vec2 quad2;\n quad2.y = floor(ceil(blueColor) / 8.0);\n quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n vec2 texPos1;\n texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.r);\n texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.g);\n vec2 texPos2;\n texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.r);\n texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.g);\n vec4 newColor1 = texture2D(lut, texPos1);\n vec4 newColor2 = texture2D(lut, texPos2);\n vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n return newColor.rgb;\n}\n#endif\n@import clay.util.rgbm\nvoid main()\n{\n vec4 texel = vec4(0.0);\n vec4 originalTexel = vec4(0.0);\n#ifdef TEXTURE_ENABLED\n texel = decodeHDR(texture2D(texture, v_Texcoord));\n originalTexel = texel;\n#endif\n#ifdef BLOOM_ENABLED\n vec4 bloomTexel = decodeHDR(texture2D(bloom, v_Texcoord));\n texel.rgb += bloomTexel.rgb * bloomIntensity;\n texel.a += bloomTexel.a * bloomIntensity;\n#endif\n#ifdef LENSFLARE_ENABLED\n texel += decodeHDR(texture2D(lensflare, v_Texcoord)) * texture2D(lensdirt, v_Texcoord) * lensflareIntensity;\n#endif\n texel.a = min(texel.a, 1.0);\n#ifdef LUM_ENABLED\n float fLum = texture2D(lum, vec2(0.5, 0.5)).r;\n float adaptedLumDest = 3.0 / (max(0.1, 1.0 + 10.0*eyeAdaption(fLum)));\n float exposureBias = adaptedLumDest * exposure;\n#else\n float exposureBias = exposure;\n#endif\n#ifdef TONEMAPPING\n texel.rgb *= exposureBias;\n texel.rgb = ACESToneMapping(texel.rgb);\n#endif\n texel = linearTosRGB(texel);\n#ifdef LUT_ENABLED\n texel.rgb = lutTransform(clamp(texel.rgb,vec3(0.0),vec3(1.0)));\n#endif\n#ifdef COLOR_CORRECTION\n texel.rgb = clamp(texel.rgb + vec3(brightness), 0.0, 1.0);\n texel.rgb = clamp((texel.rgb - vec3(0.5))*contrast+vec3(0.5), 0.0, 1.0);\n float lum = dot(texel.rgb, vec3(0.2125, 0.7154, 0.0721));\n texel.rgb = mix(vec3(lum), texel.rgb, saturation);\n#endif\n#ifdef VIGNETTE\n vec2 uv = (v_Texcoord - vec2(0.5)) * vec2(vignetteOffset);\n texel.rgb = mix(texel.rgb, vec3(1.0 - vignetteDarkness), dot(uv, uv));\n#endif\n gl_FragColor = encodeHDR(texel);\n#ifdef DEBUG\n #if DEBUG == 1\n gl_FragColor = encodeHDR(decodeHDR(texture2D(texture, v_Texcoord)));\n #elif DEBUG == 2\n gl_FragColor = encodeHDR(decodeHDR(texture2D(bloom, v_Texcoord)) * bloomIntensity);\n #elif DEBUG == 3\n gl_FragColor = encodeHDR(decodeHDR(texture2D(lensflare, v_Texcoord) * lensflareIntensity));\n #endif\n#endif\n if (originalTexel.a <= 0.01 && gl_FragColor.a > 1e-5) {\n gl_FragColor.a = dot(gl_FragColor.rgb, vec3(0.2125, 0.7154, 0.0721));\n }\n#ifdef PREMULTIPLY_ALPHA\n gl_FragColor.rgb *= gl_FragColor.a;\n#endif\n}\n@end");
  22761. /***/
  22762. }),
  22763. /* 94 */
  22764. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  22765. "use strict";
  22766. /* harmony default export */ __webpack_exports__["a"] = ("@export clay.compositor.blend\n#define SHADER_NAME blend\n#ifdef TEXTURE1_ENABLED\nuniform sampler2D texture1;\nuniform float weight1 : 1.0;\n#endif\n#ifdef TEXTURE2_ENABLED\nuniform sampler2D texture2;\nuniform float weight2 : 1.0;\n#endif\n#ifdef TEXTURE3_ENABLED\nuniform sampler2D texture3;\nuniform float weight3 : 1.0;\n#endif\n#ifdef TEXTURE4_ENABLED\nuniform sampler2D texture4;\nuniform float weight4 : 1.0;\n#endif\n#ifdef TEXTURE5_ENABLED\nuniform sampler2D texture5;\nuniform float weight5 : 1.0;\n#endif\n#ifdef TEXTURE6_ENABLED\nuniform sampler2D texture6;\nuniform float weight6 : 1.0;\n#endif\nvarying vec2 v_Texcoord;\n@import clay.util.rgbm\nvoid main()\n{\n vec4 tex = vec4(0.0);\n#ifdef TEXTURE1_ENABLED\n tex += decodeHDR(texture2D(texture1, v_Texcoord)) * weight1;\n#endif\n#ifdef TEXTURE2_ENABLED\n tex += decodeHDR(texture2D(texture2, v_Texcoord)) * weight2;\n#endif\n#ifdef TEXTURE3_ENABLED\n tex += decodeHDR(texture2D(texture3, v_Texcoord)) * weight3;\n#endif\n#ifdef TEXTURE4_ENABLED\n tex += decodeHDR(texture2D(texture4, v_Texcoord)) * weight4;\n#endif\n#ifdef TEXTURE5_ENABLED\n tex += decodeHDR(texture2D(texture5, v_Texcoord)) * weight5;\n#endif\n#ifdef TEXTURE6_ENABLED\n tex += decodeHDR(texture2D(texture6, v_Texcoord)) * weight6;\n#endif\n gl_FragColor = encodeHDR(tex);\n}\n@end");
  22767. /***/
  22768. }),
  22769. /* 95 */
  22770. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  22771. "use strict";
  22772. /* harmony default export */ __webpack_exports__["a"] = ("@export clay.compositor.fxaa\nuniform sampler2D texture;\nuniform vec4 viewport : VIEWPORT;\nvarying vec2 v_Texcoord;\n#define FXAA_REDUCE_MIN (1.0/128.0)\n#define FXAA_REDUCE_MUL (1.0/8.0)\n#define FXAA_SPAN_MAX 8.0\n@import clay.util.rgbm\nvoid main()\n{\n vec2 resolution = 1.0 / viewport.zw;\n vec3 rgbNW = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( -1.0, -1.0 ) ) * resolution ) ).xyz;\n vec3 rgbNE = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( 1.0, -1.0 ) ) * resolution ) ).xyz;\n vec3 rgbSW = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( -1.0, 1.0 ) ) * resolution ) ).xyz;\n vec3 rgbSE = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( 1.0, 1.0 ) ) * resolution ) ).xyz;\n vec4 rgbaM = decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution ) );\n vec3 rgbM = rgbaM.xyz;\n float opacity = rgbaM.w;\n vec3 luma = vec3( 0.299, 0.587, 0.114 );\n float lumaNW = dot( rgbNW, luma );\n float lumaNE = dot( rgbNE, luma );\n float lumaSW = dot( rgbSW, luma );\n float lumaSE = dot( rgbSE, luma );\n float lumaM = dot( rgbM, luma );\n float lumaMin = min( lumaM, min( min( lumaNW, lumaNE ), min( lumaSW, lumaSE ) ) );\n float lumaMax = max( lumaM, max( max( lumaNW, lumaNE) , max( lumaSW, lumaSE ) ) );\n vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n float dirReduce = max( ( lumaNW + lumaNE + lumaSW + lumaSE ) * ( 0.25 * FXAA_REDUCE_MUL ), FXAA_REDUCE_MIN );\n float rcpDirMin = 1.0 / ( min( abs( dir.x ), abs( dir.y ) ) + dirReduce );\n dir = min( vec2( FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max( vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * resolution;\n vec3 rgbA = decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * ( 1.0 / 3.0 - 0.5 ) ) ).xyz;\n rgbA += decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * ( 2.0 / 3.0 - 0.5 ) ) ).xyz;\n rgbA *= 0.5;\n vec3 rgbB = decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * -0.5 ) ).xyz;\n rgbB += decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * 0.5 ) ).xyz;\n rgbB *= 0.25;\n rgbB += rgbA * 0.5;\n float lumaB = dot( rgbB, luma );\n if ( ( lumaB < lumaMin ) || ( lumaB > lumaMax ) )\n {\n gl_FragColor = vec4( rgbA, opacity );\n }\n else {\n gl_FragColor = vec4( rgbB, opacity );\n }\n}\n@end");
  22773. /***/
  22774. }),
  22775. /* 96 */
  22776. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  22777. "use strict";
  22778. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  22779. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  22780. /* harmony default export */ __webpack_exports__["a"] = ({
  22781. getFilledRegions: function (regions, mapData) {
  22782. var regionsArr = (regions || []).slice();
  22783. var geoJson;
  22784. if (typeof mapData === 'string') {
  22785. mapData = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.getMap(mapData);
  22786. geoJson = mapData && mapData.geoJson;
  22787. }
  22788. else {
  22789. if (mapData && mapData.features) {
  22790. geoJson = mapData;
  22791. }
  22792. }
  22793. if (!geoJson) {
  22794. if (true) {
  22795. console.error('Map ' + mapData + ' not exists. You can download map file on http://echarts.baidu.com/download-map.html');
  22796. if (!geoJson.features) {
  22797. console.error('Invalid GeoJSON for map3D');
  22798. }
  22799. }
  22800. return [];
  22801. }
  22802. var dataNameMap = {};
  22803. var features = geoJson.features;
  22804. for (var i = 0; i < regionsArr.length; i++) {
  22805. dataNameMap[regionsArr[i].name] = regionsArr[i];
  22806. }
  22807. for (var i = 0; i < features.length; i++) {
  22808. var name = features[i].properties.name;
  22809. if (!dataNameMap[name]) {
  22810. regionsArr.push({
  22811. name: name
  22812. });
  22813. }
  22814. }
  22815. return regionsArr;
  22816. },
  22817. defaultOption: {
  22818. show: true,
  22819. zlevel: -10,
  22820. // geoJson used by geo3D
  22821. map: '',
  22822. // Layout used for viewport
  22823. left: 0,
  22824. top: 0,
  22825. width: '100%',
  22826. height: '100%',
  22827. boxWidth: 100,
  22828. boxHeight: 10,
  22829. boxDepth: 'auto',
  22830. regionHeight: 3,
  22831. environment: 'auto',
  22832. groundPlane: {
  22833. show: false,
  22834. color: '#aaa'
  22835. },
  22836. shading: 'lambert',
  22837. light: {
  22838. main: {
  22839. alpha: 40,
  22840. beta: 30
  22841. }
  22842. },
  22843. viewControl: {
  22844. alpha: 40,
  22845. beta: 0,
  22846. distance: 100,
  22847. orthographicSize: 60,
  22848. minAlpha: 5,
  22849. minBeta: -80,
  22850. maxBeta: 80
  22851. },
  22852. label: {
  22853. show: false,
  22854. // Distance in 3d space.
  22855. distance: 2,
  22856. textStyle: {
  22857. fontSize: 20,
  22858. color: '#000',
  22859. backgroundColor: 'rgba(255,255,255,0.7)',
  22860. padding: 3,
  22861. borderRadius: 4
  22862. }
  22863. },
  22864. // TODO
  22865. // altitude: {
  22866. // min: 'auto',
  22867. // max: 'auto',
  22868. // height: []
  22869. // },
  22870. // labelLine
  22871. // light
  22872. // postEffect
  22873. // temporalSuperSampling
  22874. itemStyle: {
  22875. color: '#fff',
  22876. borderWidth: 0,
  22877. borderColor: '#333'
  22878. },
  22879. emphasis: {
  22880. itemStyle: {
  22881. // color: '#f94b59'
  22882. color: '#639fc0'
  22883. },
  22884. label: {
  22885. show: true
  22886. }
  22887. }
  22888. }
  22889. });
  22890. /***/
  22891. }),
  22892. /* 97 */
  22893. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  22894. "use strict";
  22895. function swap(arr, a, b) {
  22896. var tmp = arr[a];
  22897. arr[a] = arr[b];
  22898. arr[b] = tmp;
  22899. }
  22900. function partition(arr, pivot, left, right, compare) {
  22901. var storeIndex = left;
  22902. var pivotValue = arr[pivot];
  22903. // put the pivot on the right
  22904. swap(arr, pivot, right);
  22905. // go through the rest
  22906. for (var v = left; v < right; v++) {
  22907. if (compare(arr[v], pivotValue) < 0) {
  22908. swap(arr, v, storeIndex);
  22909. storeIndex++;
  22910. }
  22911. }
  22912. // finally put the pivot in the correct place
  22913. swap(arr, right, storeIndex);
  22914. return storeIndex;
  22915. }
  22916. function quickSort(array, compare, left, right) {
  22917. if (left < right) {
  22918. var pivot = Math.floor((left + right) / 2);
  22919. var newPivot = partition(array, pivot, left, right, compare);
  22920. quickSort(array, compare, left, newPivot - 1);
  22921. quickSort(array, compare, newPivot + 1, right);
  22922. }
  22923. }
  22924. // TODO Test.
  22925. function ProgressiveQuickSort() {
  22926. // this._pivotList = new LinkedList();
  22927. this._parts = [];
  22928. }
  22929. ProgressiveQuickSort.prototype.step = function (arr, compare, frame) {
  22930. var len = arr.length;
  22931. if (frame === 0) {
  22932. this._parts = [];
  22933. this._sorted = false;
  22934. // Pick a start pivot;
  22935. var pivot = Math.floor(len / 2);
  22936. this._parts.push({
  22937. pivot: pivot,
  22938. left: 0,
  22939. right: len - 1
  22940. });
  22941. this._currentSortPartIdx = 0;
  22942. }
  22943. if (this._sorted) {
  22944. return;
  22945. }
  22946. var parts = this._parts;
  22947. if (parts.length === 0) {
  22948. this._sorted = true;
  22949. // Already finished.
  22950. return true;
  22951. }
  22952. else if (parts.length < 512) {
  22953. // Sort large parts in about 10 frames.
  22954. for (var i = 0; i < parts.length; i++) {
  22955. // Partition and Modify the pivot index.
  22956. parts[i].pivot = partition(
  22957. arr, parts[i].pivot, parts[i].left, parts[i].right, compare
  22958. );
  22959. }
  22960. var subdividedParts = [];
  22961. for (var i = 0; i < parts.length; i++) {
  22962. // Subdivide left
  22963. var left = parts[i].left;
  22964. var right = parts[i].pivot - 1;
  22965. if (right > left) {
  22966. subdividedParts.push({
  22967. pivot: Math.floor((right + left) / 2),
  22968. left: left, right: right
  22969. });
  22970. }
  22971. // Subdivide right
  22972. var left = parts[i].pivot + 1;
  22973. var right = parts[i].right;
  22974. if (right > left) {
  22975. subdividedParts.push({
  22976. pivot: Math.floor((right + left) / 2),
  22977. left: left, right: right
  22978. });
  22979. }
  22980. }
  22981. parts = this._parts = subdividedParts;
  22982. }
  22983. else {
  22984. // console.time('sort');
  22985. // Finally quick sort each parts in 10 frames.
  22986. for (var i = 0; i < Math.floor(parts.length / 10); i++) {
  22987. // Sort near parts first.
  22988. var idx = parts.length - 1 - this._currentSortPartIdx;
  22989. quickSort(arr, compare, parts[idx].left, parts[idx].right);
  22990. this._currentSortPartIdx++;
  22991. // Finish sort
  22992. if (this._currentSortPartIdx === parts.length) {
  22993. this._sorted = true;
  22994. return true;
  22995. }
  22996. }
  22997. // console.timeEnd('sort');
  22998. }
  22999. return false;
  23000. };
  23001. ProgressiveQuickSort.sort = quickSort;
  23002. /* harmony default export */ __webpack_exports__["a"] = (ProgressiveQuickSort);
  23003. /***/
  23004. }),
  23005. /* 98 */
  23006. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  23007. "use strict";
  23008. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__geo3D_Geo3D__ = __webpack_require__(99);
  23009. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts__ = __webpack_require__(0);
  23010. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts__);
  23011. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_echarts_lib_util_layout__ = __webpack_require__(47);
  23012. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_echarts_lib_util_layout___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_echarts_lib_util_layout__);
  23013. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__core_ViewGL__ = __webpack_require__(22);
  23014. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__util_retrieve__ = __webpack_require__(2);
  23015. function resizeGeo3D(geo3DModel, api) {
  23016. // Use left/top/width/height
  23017. var boxLayoutOption = geo3DModel.getBoxLayoutParams();
  23018. var viewport = __WEBPACK_IMPORTED_MODULE_2_echarts_lib_util_layout___default.a.getLayoutRect(boxLayoutOption, {
  23019. width: api.getWidth(),
  23020. height: api.getHeight()
  23021. });
  23022. // Flip Y
  23023. viewport.y = api.getHeight() - viewport.y - viewport.height;
  23024. this.viewGL.setViewport(viewport.x, viewport.y, viewport.width, viewport.height, api.getDevicePixelRatio());
  23025. var geoRect = this.getGeoBoundingRect();
  23026. var aspect = geoRect.width / geoRect.height * (geo3DModel.get('aspectScale') || 0.75);
  23027. var width = geo3DModel.get('boxWidth');
  23028. var depth = geo3DModel.get('boxDepth');
  23029. var height = geo3DModel.get('boxHeight');
  23030. if (height == null) {
  23031. height = 5;
  23032. }
  23033. if (isNaN(width) && isNaN(depth)) {
  23034. // Default to have 100 width
  23035. width = 100;
  23036. }
  23037. if (isNaN(depth)) {
  23038. depth = width / aspect;
  23039. }
  23040. else if (isNaN(width)) {
  23041. width = depth / aspect;
  23042. }
  23043. this.setSize(width, height, depth);
  23044. this.regionHeight = geo3DModel.get('regionHeight');
  23045. if (this.altitudeAxis) {
  23046. this.altitudeAxis.setExtent(0, Math.max(height - this.regionHeight, 0));
  23047. }
  23048. }
  23049. function updateGeo3D(ecModel, api) {
  23050. var altitudeDataExtent = [Infinity, -Infinity];
  23051. ecModel.eachSeries(function (seriesModel) {
  23052. if (seriesModel.coordinateSystem !== this) {
  23053. return;
  23054. }
  23055. if (seriesModel.type === 'series.map3D') {
  23056. return;
  23057. }
  23058. // Get altitude data extent.
  23059. var data = seriesModel.getData();
  23060. var altDims = seriesModel.coordDimToDataDim('alt');
  23061. var altDim = altDims && altDims[0];
  23062. if (altDim) {
  23063. // TODO altitiude is in coords of lines.
  23064. var dataExtent = data.getDataExtent(altDim, true);
  23065. altitudeDataExtent[0] = Math.min(
  23066. altitudeDataExtent[0], dataExtent[0]
  23067. );
  23068. altitudeDataExtent[1] = Math.max(
  23069. altitudeDataExtent[1], dataExtent[1]
  23070. );
  23071. }
  23072. }, this);
  23073. // Create altitude axis
  23074. if (altitudeDataExtent && isFinite(altitudeDataExtent[1] - altitudeDataExtent[0])) {
  23075. var scale = __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default.a.helper.createScale(
  23076. altitudeDataExtent, {
  23077. type: 'value',
  23078. // PENDING
  23079. min: 'dataMin',
  23080. max: 'dataMax'
  23081. }
  23082. );
  23083. this.altitudeAxis = new __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default.a.Axis('altitude', scale);
  23084. // Resize again
  23085. this.resize(this.model, api);
  23086. }
  23087. }
  23088. if (true) {
  23089. var mapNotExistsError = function (name) {
  23090. console.error('Map ' + name + ' not exists. You can download map file on http://echarts.baidu.com/download-map.html');
  23091. };
  23092. }
  23093. var idStart = 0;
  23094. var geo3DCreator = {
  23095. dimensions: __WEBPACK_IMPORTED_MODULE_0__geo3D_Geo3D__["a" /* default */].prototype.dimensions,
  23096. create: function (ecModel, api) {
  23097. var geo3DList = [];
  23098. if (!__WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default.a.getMap) {
  23099. throw new Error('geo3D component depends on geo component');
  23100. }
  23101. function createGeo3D(componentModel, idx) {
  23102. var geo3D = geo3DCreator.createGeo3D(componentModel);
  23103. // FIXME
  23104. componentModel.__viewGL = componentModel.__viewGL || new __WEBPACK_IMPORTED_MODULE_3__core_ViewGL__["a" /* default */]();
  23105. geo3D.viewGL = componentModel.__viewGL;
  23106. componentModel.coordinateSystem = geo3D;
  23107. geo3D.model = componentModel;
  23108. geo3DList.push(geo3D);
  23109. // Inject resize
  23110. geo3D.resize = resizeGeo3D;
  23111. geo3D.resize(componentModel, api);
  23112. geo3D.update = updateGeo3D;
  23113. }
  23114. ecModel.eachComponent('geo3D', function (geo3DModel, idx) {
  23115. createGeo3D(geo3DModel, idx);
  23116. });
  23117. ecModel.eachSeriesByType('map3D', function (map3DModel, idx) {
  23118. var coordSys = map3DModel.get('coordinateSystem');
  23119. if (coordSys == null) {
  23120. coordSys = 'geo3D';
  23121. }
  23122. if (coordSys === 'geo3D') {
  23123. createGeo3D(map3DModel, idx);
  23124. }
  23125. });
  23126. ecModel.eachSeries(function (seriesModel) {
  23127. if (seriesModel.get('coordinateSystem') === 'geo3D') {
  23128. if (seriesModel.type === 'series.map3D') {
  23129. return;
  23130. }
  23131. var geo3DModel = seriesModel.getReferringComponents('geo3D')[0];
  23132. if (!geo3DModel) {
  23133. geo3DModel = ecModel.getComponent('geo3D');
  23134. }
  23135. if (!geo3DModel) {
  23136. throw new Error('geo "' + __WEBPACK_IMPORTED_MODULE_4__util_retrieve__["a" /* default */].firstNotNull(
  23137. seriesModel.get('geo3DIndex'),
  23138. seriesModel.get('geo3DId'),
  23139. 0
  23140. ) + '" not found');
  23141. }
  23142. seriesModel.coordinateSystem = geo3DModel.coordinateSystem;
  23143. }
  23144. });
  23145. return geo3DList;
  23146. },
  23147. createGeo3D: function (componentModel) {
  23148. var mapData = componentModel.get('map');
  23149. var name;
  23150. if (typeof mapData === 'string') {
  23151. name = mapData;
  23152. mapData = __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default.a.getMap(mapData);
  23153. }
  23154. else {
  23155. if (mapData && mapData.features) {
  23156. mapData = {
  23157. geoJson: mapData
  23158. };
  23159. }
  23160. }
  23161. if (true) {
  23162. if (!mapData) {
  23163. mapNotExistsError(mapData);
  23164. }
  23165. if (!mapData.geoJson.features) {
  23166. throw new Error('Invalid GeoJSON for map3D');
  23167. }
  23168. }
  23169. if (name == null) {
  23170. name = 'GEO_ANONYMOUS_' + idStart++;
  23171. }
  23172. return new __WEBPACK_IMPORTED_MODULE_0__geo3D_Geo3D__["a" /* default */](
  23173. name + idStart++, name,
  23174. mapData && mapData.geoJson, mapData && mapData.specialAreas,
  23175. componentModel.get('nameMap')
  23176. );
  23177. }
  23178. };
  23179. __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default.a.registerCoordinateSystem('geo3D', geo3DCreator);
  23180. /* harmony default export */ __webpack_exports__["a"] = (geo3DCreator);
  23181. /***/
  23182. }),
  23183. /* 99 */
  23184. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  23185. "use strict";
  23186. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  23187. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  23188. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_dep_glmatrix__ = __webpack_require__(6);
  23189. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_echarts_lib_coord_geo_fix_textCoord__ = __webpack_require__(205);
  23190. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_echarts_lib_coord_geo_fix_textCoord___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_echarts_lib_coord_geo_fix_textCoord__);
  23191. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_echarts_lib_coord_geo_fix_geoCoord__ = __webpack_require__(206);
  23192. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_echarts_lib_coord_geo_fix_geoCoord___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_3_echarts_lib_coord_geo_fix_geoCoord__);
  23193. var vec3 = __WEBPACK_IMPORTED_MODULE_1_claygl_src_dep_glmatrix__["a" /* default */].vec3;
  23194. var mat4 = __WEBPACK_IMPORTED_MODULE_1_claygl_src_dep_glmatrix__["a" /* default */].mat4;
  23195. // Geo fix functions
  23196. var geoFixFuncs = [__WEBPACK_IMPORTED_MODULE_2_echarts_lib_coord_geo_fix_textCoord___default.a, __WEBPACK_IMPORTED_MODULE_3_echarts_lib_coord_geo_fix_geoCoord___default.a];
  23197. function Geo3D(name, map, geoJson, specialAreas, nameMap) {
  23198. this.name = name;
  23199. this.map = map;
  23200. this.regionHeight = 0;
  23201. this.regions = [];
  23202. this._nameCoordMap = {};
  23203. this.loadGeoJson(geoJson, specialAreas, nameMap);
  23204. this.transform = mat4.identity(new Float64Array(16));
  23205. this.invTransform = mat4.identity(new Float64Array(16));
  23206. // Which dimension to extrude. Y or Z
  23207. this.extrudeY = true;
  23208. this.altitudeAxis;
  23209. }
  23210. Geo3D.prototype = {
  23211. constructor: Geo3D,
  23212. type: 'geo3D',
  23213. dimensions: ['lng', 'lat', 'alt'],
  23214. containPoint: function () { },
  23215. loadGeoJson: function (geoJson, specialAreas, nameMap) {
  23216. var parseGeoJSON = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.parseGeoJSON || __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.parseGeoJson;
  23217. try {
  23218. this.regions = geoJson ? parseGeoJSON(geoJson) : [];
  23219. }
  23220. catch (e) {
  23221. throw 'Invalid geoJson format\n' + e;
  23222. }
  23223. specialAreas = specialAreas || {};
  23224. nameMap = nameMap || {};
  23225. var regions = this.regions;
  23226. var regionsMap = {};
  23227. for (var i = 0; i < regions.length; i++) {
  23228. var regionName = regions[i].name;
  23229. // Try use the alias in nameMap
  23230. regionName = nameMap[regionName] || regionName;
  23231. regions[i].name = regionName;
  23232. regionsMap[regionName] = regions[i];
  23233. // Add geoJson
  23234. this.addGeoCoord(regionName, regions[i].center);
  23235. // Some area like Alaska in USA map needs to be tansformed
  23236. // to look better
  23237. var specialArea = specialAreas[regionName];
  23238. if (specialArea) {
  23239. regions[i].transformTo(
  23240. specialArea.left, specialArea.top, specialArea.width, specialArea.height
  23241. );
  23242. }
  23243. }
  23244. this._regionsMap = regionsMap;
  23245. this._geoRect = null;
  23246. geoFixFuncs.forEach(function (fixFunc) {
  23247. fixFunc(this);
  23248. }, this);
  23249. },
  23250. getGeoBoundingRect: function () {
  23251. if (this._geoRect) {
  23252. return this._geoRect;
  23253. }
  23254. var rect;
  23255. var regions = this.regions;
  23256. for (var i = 0; i < regions.length; i++) {
  23257. var regionRect = regions[i].getBoundingRect();
  23258. rect = rect || regionRect.clone();
  23259. rect.union(regionRect);
  23260. }
  23261. // FIXME Always return new ?
  23262. return (this._geoRect = rect || new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.graphic.BoundingRect(0, 0, 0, 0));
  23263. },
  23264. /**
  23265. * Add geoCoord for indexing by name
  23266. * @param {string} name
  23267. * @param {Array.<number>} geoCoord
  23268. */
  23269. addGeoCoord: function (name, geoCoord) {
  23270. this._nameCoordMap[name] = geoCoord;
  23271. },
  23272. /**
  23273. * @param {string} name
  23274. * @return {module:echarts/coord/geo/Region}
  23275. */
  23276. getRegion: function (name) {
  23277. return this._regionsMap[name];
  23278. },
  23279. getRegionByCoord: function (coord) {
  23280. var regions = this.regions;
  23281. for (var i = 0; i < regions.length; i++) {
  23282. if (regions[i].contain(coord)) {
  23283. return regions[i];
  23284. }
  23285. }
  23286. },
  23287. setSize: function (width, height, depth) {
  23288. this.size = [width, height, depth];
  23289. var rect = this.getGeoBoundingRect();
  23290. var scaleX = width / rect.width;
  23291. var scaleZ = -depth / rect.height;
  23292. var translateX = -width / 2 - rect.x * scaleX;
  23293. var translateZ = depth / 2 - rect.y * scaleZ;
  23294. var position = this.extrudeY ? [translateX, 0, translateZ] : [translateX, translateZ, 0];
  23295. var scale = this.extrudeY ? [scaleX, 1, scaleZ] : [scaleX, scaleZ, 1];
  23296. var m = this.transform;
  23297. mat4.identity(m);
  23298. mat4.translate(m, m, position);
  23299. mat4.scale(m, m, scale);
  23300. mat4.invert(this.invTransform, m);
  23301. },
  23302. dataToPoint: function (data, out) {
  23303. out = out || [];
  23304. var extrudeCoordIndex = this.extrudeY ? 1 : 2;
  23305. var sideCoordIndex = this.extrudeY ? 2 : 1;
  23306. var altitudeVal = data[2];
  23307. // PENDING.
  23308. if (isNaN(altitudeVal)) {
  23309. altitudeVal = 0;
  23310. }
  23311. // lng
  23312. out[0] = data[0];
  23313. // lat
  23314. out[sideCoordIndex] = data[1];
  23315. if (this.altitudeAxis) {
  23316. out[extrudeCoordIndex] = this.altitudeAxis.dataToCoord(altitudeVal);
  23317. }
  23318. else {
  23319. out[extrudeCoordIndex] = 0;
  23320. }
  23321. // PENDING different region height.
  23322. out[extrudeCoordIndex] += this.regionHeight;
  23323. vec3.transformMat4(out, out, this.transform);
  23324. return out;
  23325. },
  23326. pointToData: function (point, out) {
  23327. // TODO
  23328. }
  23329. };
  23330. /* harmony default export */ __webpack_exports__["a"] = (Geo3D);
  23331. /***/
  23332. }),
  23333. /* 100 */
  23334. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  23335. "use strict";
  23336. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_claygl_src_dep_glmatrix__ = __webpack_require__(6);
  23337. var mat4 = __WEBPACK_IMPORTED_MODULE_0_claygl_src_dep_glmatrix__["a" /* default */].mat4;
  23338. var TILE_SIZE = 512;
  23339. var FOV = 0.6435011087932844;
  23340. var PI = Math.PI;
  23341. var WORLD_SCALE = 1 / 10;
  23342. function MapServiceCoordSys3D() {
  23343. /**
  23344. * Width of mapbox viewport
  23345. */
  23346. this.width = 0;
  23347. /**
  23348. * Height of mapbox viewport
  23349. */
  23350. this.height = 0;
  23351. this.altitudeScale = 1;
  23352. // TODO Change boxHeight won't have animation.
  23353. this.boxHeight = 'auto';
  23354. // Set by mapbox creator
  23355. this.altitudeExtent;
  23356. this.bearing = 0;
  23357. this.pitch = 0;
  23358. this.center = [0, 0];
  23359. this._origin;
  23360. this.zoom = 0;
  23361. this._initialZoom;
  23362. // Some parameters for different map services.
  23363. this.maxPitch = 60;
  23364. this.zoomOffset = 0;
  23365. }
  23366. MapServiceCoordSys3D.prototype = {
  23367. constructor: MapServiceCoordSys3D,
  23368. dimensions: ['lng', 'lat', 'alt'],
  23369. containPoint: function () { },
  23370. setCameraOption: function (option) {
  23371. this.bearing = option.bearing;
  23372. this.pitch = option.pitch;
  23373. this.center = option.center;
  23374. this.zoom = option.zoom;
  23375. if (!this._origin) {
  23376. this._origin = this.projectOnTileWithScale(this.center, TILE_SIZE);
  23377. }
  23378. if (this._initialZoom == null) {
  23379. this._initialZoom = this.zoom;
  23380. }
  23381. this.updateTransform();
  23382. },
  23383. // https://github.com/mapbox/mapbox-gl-js/blob/master/src/geo/transform.js#L479
  23384. updateTransform: function () {
  23385. if (!this.height) { return; }
  23386. var cameraToCenterDistance = 0.5 / Math.tan(FOV / 2) * this.height * WORLD_SCALE;
  23387. // Convert to radian.
  23388. var pitch = Math.max(Math.min(this.pitch, this.maxPitch), 0) / 180 * Math.PI;
  23389. // Find the distance from the center point [width/2, height/2] to the
  23390. // center top point [width/2, 0] in Z units, using the law of sines.
  23391. // 1 Z unit is equivalent to 1 horizontal px at the center of the map
  23392. // (the distance between[width/2, height/2] and [width/2 + 1, height/2])
  23393. var halfFov = FOV / 2;
  23394. var groundAngle = Math.PI / 2 + pitch;
  23395. var topHalfSurfaceDistance = Math.sin(halfFov) * cameraToCenterDistance / Math.sin(Math.PI - groundAngle - halfFov);
  23396. // Calculate z distance of the farthest fragment that should be rendered.
  23397. var furthestDistance = Math.cos(Math.PI / 2 - pitch) * topHalfSurfaceDistance + cameraToCenterDistance;
  23398. // Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance`
  23399. var farZ = furthestDistance * 1.1;
  23400. // Forced to be 1000
  23401. if (this.pitch > 50) {
  23402. farZ = 1000;
  23403. }
  23404. // matrix for conversion from location to GL coordinates (-1 .. 1)
  23405. var m = [];
  23406. mat4.perspective(m, FOV, this.width / this.height, 1, farZ);
  23407. this.viewGL.camera.projectionMatrix.setArray(m);
  23408. this.viewGL.camera.decomposeProjectionMatrix();
  23409. var m = mat4.identity([]);
  23410. var pt = this.dataToPoint(this.center);
  23411. // Inverse
  23412. mat4.scale(m, m, [1, -1, 1]);
  23413. // Translate to altitude
  23414. mat4.translate(m, m, [0, 0, -cameraToCenterDistance]);
  23415. mat4.rotateX(m, m, pitch);
  23416. mat4.rotateZ(m, m, -this.bearing / 180 * Math.PI);
  23417. // Translate to center.
  23418. mat4.translate(m, m, [-pt[0] * this.getScale() * WORLD_SCALE, -pt[1] * this.getScale() * WORLD_SCALE, 0]);
  23419. this.viewGL.camera.viewMatrix.array = m;
  23420. var invertM = [];
  23421. mat4.invert(invertM, m);
  23422. this.viewGL.camera.worldTransform.array = invertM;
  23423. this.viewGL.camera.decomposeWorldTransform();
  23424. // scale vertically to meters per pixel (inverse of ground resolution):
  23425. // worldSize / (circumferenceOfEarth * cos(lat * π / 180))
  23426. var worldSize = TILE_SIZE * this.getScale();
  23427. var verticalScale;
  23428. if (this.altitudeExtent && !isNaN(this.boxHeight)) {
  23429. var range = this.altitudeExtent[1] - this.altitudeExtent[0];
  23430. verticalScale = this.boxHeight / range * this.getScale() / Math.pow(2, this._initialZoom - this.zoomOffset);
  23431. }
  23432. else {
  23433. verticalScale = worldSize / (2 * Math.PI * 6378000 * Math.abs(Math.cos(this.center[1] * (Math.PI / 180))))
  23434. * this.altitudeScale * WORLD_SCALE;
  23435. }
  23436. // Include scale to avoid relayout when zooming
  23437. // FIXME Camera scale may have problem in shadow
  23438. this.viewGL.rootNode.scale.set(
  23439. this.getScale() * WORLD_SCALE, this.getScale() * WORLD_SCALE, verticalScale
  23440. );
  23441. },
  23442. getScale: function () {
  23443. return Math.pow(2, this.zoom - this.zoomOffset);
  23444. },
  23445. projectOnTile: function (data, out) {
  23446. return this.projectOnTileWithScale(data, this.getScale() * TILE_SIZE, out);
  23447. },
  23448. projectOnTileWithScale: function (data, scale, out) {
  23449. var lng = data[0];
  23450. var lat = data[1];
  23451. var lambda2 = lng * PI / 180;
  23452. var phi2 = lat * PI / 180;
  23453. var x = scale * (lambda2 + PI) / (2 * PI);
  23454. var y = scale * (PI - Math.log(Math.tan(PI / 4 + phi2 * 0.5))) / (2 * PI);
  23455. out = out || [];
  23456. out[0] = x;
  23457. out[1] = y;
  23458. return out;
  23459. },
  23460. unprojectFromTile: function (point, out) {
  23461. return this.unprojectOnTileWithScale(point, this.getScale() * TILE_SIZE, out);
  23462. },
  23463. unprojectOnTileWithScale: function (point, scale, out) {
  23464. var x = point[0];
  23465. var y = point[1];
  23466. var lambda2 = (x / scale) * (2 * PI) - PI;
  23467. var phi2 = 2 * (Math.atan(Math.exp(PI - (y / scale) * (2 * PI))) - PI / 4);
  23468. out = out || [];
  23469. out[0] = lambda2 * 180 / PI;
  23470. out[1] = phi2 * 180 / PI;
  23471. return out;
  23472. },
  23473. dataToPoint: function (data, out) {
  23474. out = this.projectOnTileWithScale(data, TILE_SIZE, out);
  23475. // Add a origin to avoid precision issue in WebGL.
  23476. out[0] -= this._origin[0];
  23477. out[1] -= this._origin[1];
  23478. // PENDING
  23479. out[2] = !isNaN(data[2]) ? data[2] : 0;
  23480. if (!isNaN(data[2])) {
  23481. out[2] = data[2];
  23482. if (this.altitudeExtent) {
  23483. out[2] -= this.altitudeExtent[0];
  23484. }
  23485. }
  23486. return out;
  23487. }
  23488. };
  23489. /* harmony default export */ __webpack_exports__["a"] = (MapServiceCoordSys3D);
  23490. /***/
  23491. }),
  23492. /* 101 */
  23493. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  23494. "use strict";
  23495. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__util_retrieve__ = __webpack_require__(2);
  23496. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__ = __webpack_require__(1);
  23497. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__core_ViewGL__ = __webpack_require__(22);
  23498. /* harmony default export */ __webpack_exports__["a"] = (function (serviceComponentType, ServiceCtor, afterCreate) {
  23499. function resizeMapService3D(mapService3DModel, api) {
  23500. var width = api.getWidth();
  23501. var height = api.getHeight();
  23502. var dpr = api.getDevicePixelRatio();
  23503. this.viewGL.setViewport(0, 0, width, height, dpr);
  23504. this.width = width;
  23505. this.height = height;
  23506. this.altitudeScale = mapService3DModel.get('altitudeScale');
  23507. this.boxHeight = mapService3DModel.get('boxHeight');
  23508. // this.updateTransform();
  23509. }
  23510. function updateService3D(ecModel, api) {
  23511. if (this.model.get('boxHeight') === 'auto') {
  23512. return;
  23513. }
  23514. var altitudeDataExtent = [Infinity, -Infinity]
  23515. ecModel.eachSeries(function (seriesModel) {
  23516. if (seriesModel.coordinateSystem !== this) {
  23517. return;
  23518. }
  23519. // Get altitude data extent.
  23520. var data = seriesModel.getData();
  23521. var altDim = seriesModel.coordDimToDataDim('alt')[0];
  23522. if (altDim) {
  23523. // TODO altitiude is in coords of lines.
  23524. var dataExtent = data.getDataExtent(altDim, true);
  23525. altitudeDataExtent[0] = Math.min(
  23526. altitudeDataExtent[0], dataExtent[0]
  23527. );
  23528. altitudeDataExtent[1] = Math.max(
  23529. altitudeDataExtent[1], dataExtent[1]
  23530. );
  23531. }
  23532. }, this);
  23533. if (altitudeDataExtent && isFinite(altitudeDataExtent[1] - altitudeDataExtent[0])) {
  23534. this.altitudeExtent = altitudeDataExtent;
  23535. }
  23536. }
  23537. return {
  23538. dimensions: ServiceCtor.prototype.dimensions,
  23539. create: function (ecModel, api) {
  23540. var mapService3DList = [];
  23541. ecModel.eachComponent(serviceComponentType, function (mapService3DModel) {
  23542. var viewGL = mapService3DModel.__viewGL;
  23543. if (!viewGL) {
  23544. viewGL = mapService3DModel.__viewGL = new __WEBPACK_IMPORTED_MODULE_2__core_ViewGL__["a" /* default */]();
  23545. viewGL.setRootNode(new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Node());
  23546. }
  23547. var mapService3DCoordSys = new ServiceCtor();
  23548. mapService3DCoordSys.viewGL = mapService3DModel.__viewGL;
  23549. // Inject resize
  23550. mapService3DCoordSys.resize = resizeMapService3D;
  23551. mapService3DCoordSys.resize(mapService3DModel, api);
  23552. mapService3DList.push(mapService3DCoordSys);
  23553. mapService3DModel.coordinateSystem = mapService3DCoordSys;
  23554. mapService3DCoordSys.model = mapService3DModel;
  23555. mapService3DCoordSys.update = updateService3D;
  23556. });
  23557. ecModel.eachSeries(function (seriesModel) {
  23558. if (seriesModel.get('coordinateSystem') === serviceComponentType) {
  23559. var mapService3DModel = seriesModel.getReferringComponents(serviceComponentType)[0];
  23560. if (!mapService3DModel) {
  23561. mapService3DModel = ecModel.getComponent(serviceComponentType);
  23562. }
  23563. if (!mapService3DModel) {
  23564. throw new Error(serviceComponentType + ' "' + __WEBPACK_IMPORTED_MODULE_0__util_retrieve__["a" /* default */].firstNotNull(
  23565. seriesModel.get(serviceComponentType + 'Index'),
  23566. seriesModel.get(serviceComponentType + 'Id'),
  23567. 0
  23568. ) + '" not found');
  23569. }
  23570. seriesModel.coordinateSystem = mapService3DModel.coordinateSystem;
  23571. }
  23572. });
  23573. afterCreate && afterCreate(mapService3DList, ecModel, api);
  23574. return mapService3DList;
  23575. }
  23576. };
  23577. });
  23578. /***/
  23579. }),
  23580. /* 102 */
  23581. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  23582. "use strict";
  23583. /* harmony default export */ __webpack_exports__["a"] = ("\n@export ecgl.displayShadow.vertex\n\n@import ecgl.common.transformUniforms\n\n@import ecgl.common.uv.header\n\n@import ecgl.common.attributes\n\nvarying vec3 v_WorldPosition;\n\nvarying vec3 v_Normal;\n\nvoid main()\n{\n @import ecgl.common.uv.main\n v_Normal = normalize((worldInverseTranspose * vec4(normal, 0.0)).xyz);\n\n v_WorldPosition = (world * vec4(position, 1.0)).xyz;\n gl_Position = worldViewProjection * vec4(position, 1.0);\n}\n\n@end\n\n\n@export ecgl.displayShadow.fragment\n\n@import ecgl.common.uv.fragmentHeader\n\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\n\nuniform float roughness: 0.2;\n\n#ifdef DIRECTIONAL_LIGHT_COUNT\n@import clay.header.directional_light\n#endif\n\n@import ecgl.common.ssaoMap.header\n\n@import clay.plugin.compute_shadow_map\n\nvoid main()\n{\n float shadow = 1.0;\n\n @import ecgl.common.ssaoMap.main\n\n#if defined(DIRECTIONAL_LIGHT_COUNT) && defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsDir[DIRECTIONAL_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfDirectionalLights(v_WorldPosition, shadowContribsDir);\n }\n for (int i = 0; i < DIRECTIONAL_LIGHT_COUNT; i++) {\n shadow = min(shadow, shadowContribsDir[i] * 0.5 + 0.5);\n }\n#endif\n\n shadow *= 0.5 + ao * 0.5;\n shadow = clamp(shadow, 0.0, 1.0);\n\n gl_FragColor = vec4(vec3(0.0), 1.0 - shadow);\n}\n\n@end");
  23584. /***/
  23585. }),
  23586. /* 103 */
  23587. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  23588. "use strict";
  23589. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_zrender_lib_core_matrix__ = __webpack_require__(84);
  23590. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_zrender_lib_core_matrix___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_zrender_lib_core_matrix__);
  23591. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_zrender_lib_core_vector__ = __webpack_require__(83);
  23592. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_zrender_lib_core_vector___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_zrender_lib_core_vector__);
  23593. function GLViewHelper(viewGL) {
  23594. this.viewGL = viewGL;
  23595. }
  23596. GLViewHelper.prototype.reset = function (seriesModel, api) {
  23597. this._updateCamera(api.getWidth(), api.getHeight(), api.getDevicePixelRatio());
  23598. this._viewTransform = __WEBPACK_IMPORTED_MODULE_0_zrender_lib_core_matrix___default.a.create();
  23599. this.updateTransform(seriesModel, api);
  23600. };
  23601. GLViewHelper.prototype.updateTransform = function (seriesModel, api) {
  23602. var coordinateSystem = seriesModel.coordinateSystem;
  23603. if (coordinateSystem.getRoamTransform) {
  23604. __WEBPACK_IMPORTED_MODULE_0_zrender_lib_core_matrix___default.a.invert(this._viewTransform, coordinateSystem.getRoamTransform());
  23605. this._setCameraTransform(this._viewTransform);
  23606. api.getZr().refresh();
  23607. }
  23608. };
  23609. // Reimplement the dataToPoint of coordinate system.
  23610. // Remove the effect of pan/zoom transform
  23611. GLViewHelper.prototype.dataToPoint = function (coordSys, data, pt) {
  23612. pt = coordSys.dataToPoint(data, null, pt);
  23613. var viewTransform = this._viewTransform;
  23614. if (viewTransform) {
  23615. __WEBPACK_IMPORTED_MODULE_1_zrender_lib_core_vector___default.a.applyTransform(pt, pt, viewTransform);
  23616. }
  23617. };
  23618. /**
  23619. * Remove transform info in point.
  23620. */
  23621. GLViewHelper.prototype.removeTransformInPoint = function (pt) {
  23622. if (this._viewTransform) {
  23623. __WEBPACK_IMPORTED_MODULE_1_zrender_lib_core_vector___default.a.applyTransform(pt, pt, this._viewTransform);
  23624. }
  23625. return pt;
  23626. };
  23627. /**
  23628. * Return number
  23629. */
  23630. GLViewHelper.prototype.getZoom = function () {
  23631. if (this._viewTransform) {
  23632. var m = this._viewTransform;
  23633. return 1 / Math.max(
  23634. Math.sqrt(m[0] * m[0] + m[1] * m[1]),
  23635. Math.sqrt(m[2] * m[2] + m[3] * m[3])
  23636. );
  23637. }
  23638. return 1;
  23639. };
  23640. GLViewHelper.prototype._setCameraTransform = function (m) {
  23641. var camera = this.viewGL.camera;
  23642. camera.position.set(m[4], m[5], 0);
  23643. camera.scale.set(
  23644. Math.sqrt(m[0] * m[0] + m[1] * m[1]),
  23645. Math.sqrt(m[2] * m[2] + m[3] * m[3]),
  23646. 1
  23647. );
  23648. };
  23649. GLViewHelper.prototype._updateCamera = function (width, height, dpr) {
  23650. // TODO, left, top, right, bottom
  23651. this.viewGL.setViewport(0, 0, width, height, dpr);
  23652. var camera = this.viewGL.camera;
  23653. camera.left = camera.top = 0;
  23654. camera.bottom = height;
  23655. camera.right = width;
  23656. camera.near = 0;
  23657. camera.far = 100;
  23658. };
  23659. /* harmony default export */ __webpack_exports__["a"] = (GLViewHelper);
  23660. /***/
  23661. }),
  23662. /* 104 */
  23663. /***/ (function (module, exports, __webpack_require__) {
  23664. /* WEBPACK VAR INJECTION */(function (global) {/*
  23665. * Licensed to the Apache Software Foundation (ASF) under one
  23666. * or more contributor license agreements. See the NOTICE file
  23667. * distributed with this work for additional information
  23668. * regarding copyright ownership. The ASF licenses this file
  23669. * to you under the Apache License, Version 2.0 (the
  23670. * "License"); you may not use this file except in compliance
  23671. * with the License. You may obtain a copy of the License at
  23672. *
  23673. * http://www.apache.org/licenses/LICENSE-2.0
  23674. *
  23675. * Unless required by applicable law or agreed to in writing,
  23676. * software distributed under the License is distributed on an
  23677. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  23678. * KIND, either express or implied. See the License for the
  23679. * specific language governing permissions and limitations
  23680. * under the License.
  23681. */
  23682. // (1) The code `if (__DEV__) ...` can be removed by build tool.
  23683. // (2) If intend to use `__DEV__`, this module should be imported. Use a global
  23684. // variable `__DEV__` may cause that miss the declaration (see #6535), or the
  23685. // declaration is behind of the using position (for example in `Model.extent`,
  23686. // And tools like rollup can not analysis the dependency if not import).
  23687. var dev; // In browser
  23688. if (typeof window !== 'undefined') {
  23689. dev = window.__DEV__;
  23690. } // In node
  23691. else if (typeof global !== 'undefined') {
  23692. dev = global.__DEV__;
  23693. }
  23694. if (typeof dev === 'undefined') {
  23695. dev = true;
  23696. }
  23697. var __DEV__ = dev;
  23698. exports.__DEV__ = __DEV__;
  23699. /* WEBPACK VAR INJECTION */
  23700. }.call(exports, __webpack_require__(68)))
  23701. /***/
  23702. }),
  23703. /* 105 */
  23704. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  23705. "use strict";
  23706. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__ = __webpack_require__(15);
  23707. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts__ = __webpack_require__(0);
  23708. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts__);
  23709. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__dynamicConvertMixin__ = __webpack_require__(38);
  23710. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_claygl_src_dep_glmatrix__ = __webpack_require__(6);
  23711. /**
  23712. * Lines geometry
  23713. * Use screen space projected lines lineWidth > MAX_LINE_WIDTH
  23714. * https://mattdesl.svbtle.com/drawing-lines-is-hard
  23715. * @module echarts-gl/util/geometry/LinesGeometry
  23716. * @author Yi Shen(http://github.com/pissang)
  23717. */
  23718. var vec2 = __WEBPACK_IMPORTED_MODULE_3_claygl_src_dep_glmatrix__["a" /* default */].vec2;
  23719. // var CURVE_RECURSION_LIMIT = 8;
  23720. // var CURVE_COLLINEAR_EPSILON = 40;
  23721. var sampleLinePoints = [[0, 0], [1, 1]];
  23722. /**
  23723. * @constructor
  23724. * @alias module:echarts-gl/util/geometry/LinesGeometry
  23725. * @extends clay.Geometry
  23726. */
  23727. var LinesGeometry = __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].extend(function () {
  23728. return {
  23729. segmentScale: 4,
  23730. dynamic: true,
  23731. /**
  23732. * Need to use mesh to expand lines if lineWidth > MAX_LINE_WIDTH
  23733. */
  23734. useNativeLine: true,
  23735. attributes: {
  23736. position: new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].Attribute('position', 'float', 2, 'POSITION'),
  23737. normal: new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].Attribute('normal', 'float', 2),
  23738. offset: new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].Attribute('offset', 'float', 1),
  23739. color: new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].Attribute('color', 'float', 4, 'COLOR')
  23740. }
  23741. };
  23742. },
  23743. /** @lends module: echarts-gl/util/geometry/LinesGeometry.prototype */
  23744. {
  23745. /**
  23746. * Reset offset
  23747. */
  23748. resetOffset: function () {
  23749. this._vertexOffset = 0;
  23750. this._faceOffset = 0;
  23751. this._itemVertexOffsets = [];
  23752. },
  23753. /**
  23754. * @param {number} nVertex
  23755. */
  23756. setVertexCount: function (nVertex) {
  23757. var attributes = this.attributes;
  23758. if (this.vertexCount !== nVertex) {
  23759. attributes.position.init(nVertex);
  23760. attributes.color.init(nVertex);
  23761. if (!this.useNativeLine) {
  23762. attributes.offset.init(nVertex);
  23763. attributes.normal.init(nVertex);
  23764. }
  23765. if (nVertex > 0xffff) {
  23766. if (this.indices instanceof Uint16Array) {
  23767. this.indices = new Uint32Array(this.indices);
  23768. }
  23769. }
  23770. else {
  23771. if (this.indices instanceof Uint32Array) {
  23772. this.indices = new Uint16Array(this.indices);
  23773. }
  23774. }
  23775. }
  23776. },
  23777. /**
  23778. * @param {number} nTriangle
  23779. */
  23780. setTriangleCount: function (nTriangle) {
  23781. if (this.triangleCount !== nTriangle) {
  23782. if (nTriangle === 0) {
  23783. this.indices = null;
  23784. }
  23785. else {
  23786. this.indices = this.vertexCount > 0xffff ? new Uint32Array(nTriangle * 3) : new Uint16Array(nTriangle * 3);
  23787. }
  23788. }
  23789. },
  23790. _getCubicCurveApproxStep: function (p0, p1, p2, p3) {
  23791. var len = vec2.dist(p0, p1) + vec2.dist(p2, p1) + vec2.dist(p3, p2);
  23792. var step = 1 / (len + 1) * this.segmentScale;
  23793. return step;
  23794. },
  23795. /**
  23796. * Get vertex count of cubic curve
  23797. * @param {Array.<number>} p0
  23798. * @param {Array.<number>} p1
  23799. * @param {Array.<number>} p2
  23800. * @param {Array.<number>} p3
  23801. * @return number
  23802. */
  23803. getCubicCurveVertexCount: function (p0, p1, p2, p3) {
  23804. var step = this._getCubicCurveApproxStep(p0, p1, p2, p3);
  23805. var segCount = Math.ceil(1 / step);
  23806. if (!this.useNativeLine) {
  23807. return segCount * 2 + 2;
  23808. }
  23809. else {
  23810. return segCount * 2;
  23811. }
  23812. },
  23813. /**
  23814. * Get face count of cubic curve
  23815. * @param {Array.<number>} p0
  23816. * @param {Array.<number>} p1
  23817. * @param {Array.<number>} p2
  23818. * @param {Array.<number>} p3
  23819. * @return number
  23820. */
  23821. getCubicCurveTriangleCount: function (p0, p1, p2, p3) {
  23822. var step = this._getCubicCurveApproxStep(p0, p1, p2, p3);
  23823. var segCount = Math.ceil(1 / step);
  23824. if (!this.useNativeLine) {
  23825. return segCount * 2;
  23826. }
  23827. else {
  23828. return 0;
  23829. }
  23830. },
  23831. /**
  23832. * Get vertex count of line
  23833. * @return {number}
  23834. */
  23835. getLineVertexCount: function () {
  23836. return this.getPolylineVertexCount(sampleLinePoints);
  23837. },
  23838. /**
  23839. * Get face count of line
  23840. * @return {number}
  23841. */
  23842. getLineTriangleCount: function () {
  23843. return this.getPolylineTriangleCount(sampleLinePoints);
  23844. },
  23845. /**
  23846. * Get how many vertices will polyline take.
  23847. * @type {number|Array} points Can be a 1d/2d list of points, or a number of points amount.
  23848. * @return {number}
  23849. */
  23850. getPolylineVertexCount: function (points) {
  23851. var pointsLen;
  23852. if (typeof points === 'number') {
  23853. pointsLen = points;
  23854. }
  23855. else {
  23856. var is2DArray = typeof points[0] !== 'number';
  23857. pointsLen = is2DArray ? points.length : (points.length / 2);
  23858. }
  23859. return !this.useNativeLine ? ((pointsLen - 1) * 2 + 2) : (pointsLen - 1) * 2;
  23860. },
  23861. /**
  23862. * Get how many triangles will polyline take.
  23863. * @type {number|Array} points Can be a 1d/2d list of points, or a number of points amount.
  23864. * @return {number}
  23865. */
  23866. getPolylineTriangleCount: function (points) {
  23867. var pointsLen;
  23868. if (typeof points === 'number') {
  23869. pointsLen = points;
  23870. }
  23871. else {
  23872. var is2DArray = typeof points[0] !== 'number';
  23873. pointsLen = is2DArray ? points.length : (points.length / 2);
  23874. }
  23875. return !this.useNativeLine ? (pointsLen - 1) * 2 : 0;
  23876. },
  23877. /**
  23878. * Add a cubic curve
  23879. * @param {Array.<number>} p0
  23880. * @param {Array.<number>} p1
  23881. * @param {Array.<number>} p2
  23882. * @param {Array.<number>} p3
  23883. * @param {Array.<number>} color
  23884. * @param {number} [lineWidth=1]
  23885. */
  23886. addCubicCurve: function (p0, p1, p2, p3, color, lineWidth) {
  23887. if (lineWidth == null) {
  23888. lineWidth = 1;
  23889. }
  23890. // incremental interpolation
  23891. // http://antigrain.com/research/bezier_interpolation/index.html#PAGE_BEZIER_INTERPOLATION
  23892. var x0 = p0[0], y0 = p0[1];
  23893. var x1 = p1[0], y1 = p1[1];
  23894. var x2 = p2[0], y2 = p2[1];
  23895. var x3 = p3[0], y3 = p3[1];
  23896. var step = this._getCubicCurveApproxStep(p0, p1, p2, p3);
  23897. var step2 = step * step;
  23898. var step3 = step2 * step;
  23899. var pre1 = 3.0 * step;
  23900. var pre2 = 3.0 * step2;
  23901. var pre4 = 6.0 * step2;
  23902. var pre5 = 6.0 * step3;
  23903. var tmp1x = x0 - x1 * 2.0 + x2;
  23904. var tmp1y = y0 - y1 * 2.0 + y2;
  23905. var tmp2x = (x1 - x2) * 3.0 - x0 + x3;
  23906. var tmp2y = (y1 - y2) * 3.0 - y0 + y3;
  23907. var fx = x0;
  23908. var fy = y0;
  23909. var dfx = (x1 - x0) * pre1 + tmp1x * pre2 + tmp2x * step3;
  23910. var dfy = (y1 - y0) * pre1 + tmp1y * pre2 + tmp2y * step3;
  23911. var ddfx = tmp1x * pre4 + tmp2x * pre5;
  23912. var ddfy = tmp1y * pre4 + tmp2y * pre5;
  23913. var dddfx = tmp2x * pre5;
  23914. var dddfy = tmp2y * pre5;
  23915. var t = 0;
  23916. var k = 0;
  23917. var segCount = Math.ceil(1 / step);
  23918. var points = new Float32Array((segCount + 1) * 3);
  23919. var points = [];
  23920. var offset = 0;
  23921. for (var k = 0; k < segCount + 1; k++) {
  23922. points[offset++] = fx;
  23923. points[offset++] = fy;
  23924. fx += dfx; fy += dfy;
  23925. dfx += ddfx; dfy += ddfy;
  23926. ddfx += dddfx; ddfy += dddfy;
  23927. t += step;
  23928. if (t > 1) {
  23929. fx = dfx > 0 ? Math.min(fx, x3) : Math.max(fx, x3);
  23930. fy = dfy > 0 ? Math.min(fy, y3) : Math.max(fy, y3);
  23931. }
  23932. }
  23933. this.addPolyline(points, color, lineWidth);
  23934. },
  23935. /**
  23936. * Add a straight line
  23937. * @param {Array.<number>} p0
  23938. * @param {Array.<number>} p1
  23939. * @param {Array.<number>} color
  23940. * @param {number} [lineWidth=1]
  23941. */
  23942. addLine: function (p0, p1, color, lineWidth) {
  23943. this.addPolyline([p0, p1], color, lineWidth);
  23944. },
  23945. /**
  23946. * Add a straight line
  23947. * @param {Array.<Array> | Array.<number>} points
  23948. * @param {Array.<number> | Array.<Array>} color
  23949. * @param {number} [lineWidth=1]
  23950. * @param {number} [arrayOffset=0]
  23951. * @param {number} [pointsCount] Default to be amount of points in the first argument
  23952. */
  23953. addPolyline: (function () {
  23954. var dirA = vec2.create();
  23955. var dirB = vec2.create();
  23956. var normal = vec2.create();
  23957. var tangent = vec2.create();
  23958. var point = [], nextPoint = [], prevPoint = [];
  23959. return function (points, color, lineWidth, arrayOffset, pointsCount) {
  23960. if (!points.length) {
  23961. return;
  23962. }
  23963. var is2DArray = typeof points[0] !== 'number';
  23964. if (pointsCount == null) {
  23965. pointsCount = is2DArray ? points.length : points.length / 2;
  23966. }
  23967. if (pointsCount < 2) {
  23968. return;
  23969. }
  23970. if (arrayOffset == null) {
  23971. arrayOffset = 0;
  23972. }
  23973. if (lineWidth == null) {
  23974. lineWidth = 1;
  23975. }
  23976. this._itemVertexOffsets.push(this._vertexOffset);
  23977. var notSharingColor = is2DArray
  23978. ? typeof color[0] !== 'number'
  23979. : color.length / 4 === pointsCount;
  23980. var positionAttr = this.attributes.position;
  23981. var colorAttr = this.attributes.color;
  23982. var offsetAttr = this.attributes.offset;
  23983. var normalAttr = this.attributes.normal;
  23984. var indices = this.indices;
  23985. var vertexOffset = this._vertexOffset;
  23986. var pointColor;
  23987. for (var k = 0; k < pointsCount; k++) {
  23988. if (is2DArray) {
  23989. point = points[k + arrayOffset];
  23990. if (notSharingColor) {
  23991. pointColor = color[k + arrayOffset];
  23992. }
  23993. else {
  23994. pointColor = color;
  23995. }
  23996. }
  23997. else {
  23998. var k2 = k * 2 + arrayOffset;
  23999. point = point || [];
  24000. point[0] = points[k2];
  24001. point[1] = points[k2 + 1];
  24002. if (notSharingColor) {
  24003. var k4 = k * 4 + arrayOffset;
  24004. pointColor = pointColor || [];
  24005. pointColor[0] = color[k4];
  24006. pointColor[1] = color[k4 + 1];
  24007. pointColor[2] = color[k4 + 2];
  24008. pointColor[3] = color[k4 + 3];
  24009. }
  24010. else {
  24011. pointColor = color;
  24012. }
  24013. }
  24014. if (!this.useNativeLine) {
  24015. var offset;
  24016. if (k < pointsCount - 1) {
  24017. if (is2DArray) {
  24018. vec2.copy(nextPoint, points[k + 1]);
  24019. }
  24020. else {
  24021. var k2 = (k + 1) * 2 + arrayOffset;
  24022. nextPoint = nextPoint || [];
  24023. nextPoint[0] = points[k2];
  24024. nextPoint[1] = points[k2 + 1];
  24025. }
  24026. // TODO In case dir is (0, 0)
  24027. // TODO miterLimit
  24028. if (k > 0) {
  24029. vec2.sub(dirA, point, prevPoint);
  24030. vec2.sub(dirB, nextPoint, point);
  24031. vec2.normalize(dirA, dirA);
  24032. vec2.normalize(dirB, dirB);
  24033. vec2.add(tangent, dirA, dirB);
  24034. vec2.normalize(tangent, tangent);
  24035. var miter = lineWidth / 2 * Math.min(1 / vec2.dot(dirA, tangent), 2);
  24036. normal[0] = -tangent[1];
  24037. normal[1] = tangent[0];
  24038. offset = miter;
  24039. }
  24040. else {
  24041. vec2.sub(dirA, nextPoint, point);
  24042. vec2.normalize(dirA, dirA);
  24043. normal[0] = -dirA[1];
  24044. normal[1] = dirA[0];
  24045. offset = lineWidth / 2;
  24046. }
  24047. }
  24048. else {
  24049. vec2.sub(dirA, point, prevPoint);
  24050. vec2.normalize(dirA, dirA);
  24051. normal[0] = -dirA[1];
  24052. normal[1] = dirA[0];
  24053. offset = lineWidth / 2;
  24054. }
  24055. normalAttr.set(vertexOffset, normal);
  24056. normalAttr.set(vertexOffset + 1, normal);
  24057. offsetAttr.set(vertexOffset, offset);
  24058. offsetAttr.set(vertexOffset + 1, -offset);
  24059. vec2.copy(prevPoint, point);
  24060. positionAttr.set(vertexOffset, point);
  24061. positionAttr.set(vertexOffset + 1, point);
  24062. colorAttr.set(vertexOffset, pointColor);
  24063. colorAttr.set(vertexOffset + 1, pointColor);
  24064. vertexOffset += 2;
  24065. }
  24066. else {
  24067. if (k > 1) {
  24068. positionAttr.copy(vertexOffset, vertexOffset - 1);
  24069. colorAttr.copy(vertexOffset, vertexOffset - 1);
  24070. vertexOffset++;
  24071. }
  24072. }
  24073. if (!this.useNativeLine) {
  24074. if (k > 0) {
  24075. var idx3 = this._faceOffset * 3;
  24076. var indices = this.indices;
  24077. // 0-----2
  24078. // 1-----3
  24079. // 0->1->2, 1->3->2
  24080. indices[idx3] = vertexOffset - 4;
  24081. indices[idx3 + 1] = vertexOffset - 3;
  24082. indices[idx3 + 2] = vertexOffset - 2;
  24083. indices[idx3 + 3] = vertexOffset - 3;
  24084. indices[idx3 + 4] = vertexOffset - 1;
  24085. indices[idx3 + 5] = vertexOffset - 2;
  24086. this._faceOffset += 2;
  24087. }
  24088. }
  24089. else {
  24090. colorAttr.set(vertexOffset, pointColor);
  24091. positionAttr.set(vertexOffset, point);
  24092. vertexOffset++;
  24093. }
  24094. }
  24095. this._vertexOffset = vertexOffset;
  24096. };
  24097. })(),
  24098. /**
  24099. * Set color of single line.
  24100. */
  24101. setItemColor: function (idx, color) {
  24102. var startOffset = this._itemVertexOffsets[idx];
  24103. var endOffset = idx < this._itemVertexOffsets.length - 1 ? this._itemVertexOffsets[idx + 1] : this._vertexOffset;
  24104. for (var i = startOffset; i < endOffset; i++) {
  24105. this.attributes.color.set(i, color);
  24106. }
  24107. this.dirty('color');
  24108. }
  24109. });
  24110. __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default.a.util.defaults(LinesGeometry.prototype, __WEBPACK_IMPORTED_MODULE_2__dynamicConvertMixin__["a" /* default */]);
  24111. /* harmony default export */ __webpack_exports__["a"] = (LinesGeometry);
  24112. /***/
  24113. }),
  24114. /* 106 */
  24115. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  24116. "use strict";
  24117. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  24118. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__src_echarts_gl__ = __webpack_require__(107);
  24119. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__src_component_grid3D__ = __webpack_require__(154);
  24120. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__src_component_geo3D__ = __webpack_require__(201);
  24121. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__src_component_globe__ = __webpack_require__(207);
  24122. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__src_component_mapbox3D__ = __webpack_require__(213);
  24123. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__src_component_maptalks3D__ = __webpack_require__(219);
  24124. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__src_chart_bar3D__ = __webpack_require__(225);
  24125. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__src_chart_line3D__ = __webpack_require__(232);
  24126. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__src_chart_scatter3D__ = __webpack_require__(236);
  24127. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_9__src_chart_lines3D__ = __webpack_require__(243);
  24128. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_10__src_chart_polygons3D__ = __webpack_require__(249);
  24129. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_11__src_chart_surface__ = __webpack_require__(252);
  24130. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_12__src_chart_map3D__ = __webpack_require__(256);
  24131. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_13__src_chart_scatterGL__ = __webpack_require__(259);
  24132. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_14__src_chart_graphGL__ = __webpack_require__(262);
  24133. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_15__src_chart_flowGL__ = __webpack_require__(275);
  24134. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_16__src_chart_linesGL__ = __webpack_require__(281);
  24135. /***/
  24136. }),
  24137. /* 107 */
  24138. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  24139. "use strict";
  24140. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  24141. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  24142. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_version__ = __webpack_require__(108);
  24143. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__core_LayerGL__ = __webpack_require__(109);
  24144. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__preprocessor_backwardCompat__ = __webpack_require__(153);
  24145. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__util_graphicGL__ = __webpack_require__(1);
  24146. /**
  24147. * echarts-gl
  24148. * Extension pack of ECharts providing 3d plots and globe visualization
  24149. *
  24150. * Copyright (c) 2014, echarts-gl
  24151. * All rights reserved.
  24152. *
  24153. * Redistribution and use in source and binary forms, with or without
  24154. * modification, are permitted provided that the following conditions are met:
  24155. *
  24156. * * Redistributions of source code must retain the above copyright notice, this
  24157. * list of conditions and the following disclaimer.
  24158. *
  24159. * * Redistributions in binary form must reproduce the above copyright notice,
  24160. * this list of conditions and the following disclaimer in the documentation
  24161. * and/or other materials provided with the distribution.
  24162. *
  24163. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24164. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24165. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  24166. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  24167. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24168. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  24169. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24170. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  24171. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24172. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24173. */
  24174. /**
  24175. * @module echarts-gl
  24176. * @author Yi Shen(http://github.com/pissang)
  24177. */
  24178. // PENDING Use a single canvas as layer or use image element?
  24179. var echartsGl = {
  24180. version: '1.1.1',
  24181. dependencies: {
  24182. echarts: '4.1.0',
  24183. claygl: '1.2.1'
  24184. }
  24185. };
  24186. // Version checking
  24187. var deps = echartsGl.dependencies;
  24188. function versionTooOldMsg(name) {
  24189. throw new Error(
  24190. name + ' version is too old, needs ' + deps[name] + ' or higher'
  24191. );
  24192. }
  24193. function checkVersion(version, name) {
  24194. if ((version.replace('.', '') - 0) < (deps[name].replace('.', '') - 0)) {
  24195. versionTooOldMsg(name);
  24196. }
  24197. console.log('Loaded ' + name + ', version ' + version);
  24198. }
  24199. checkVersion(__WEBPACK_IMPORTED_MODULE_1_claygl_src_version__["a" /* default */], 'claygl');
  24200. checkVersion(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.version, 'echarts');
  24201. function EChartsGL(zr) {
  24202. this._layers = {};
  24203. this._zr = zr;
  24204. }
  24205. EChartsGL.prototype.update = function (ecModel, api) {
  24206. var self = this;
  24207. var zr = api.getZr();
  24208. if (!zr.getWidth() || !zr.getHeight()) {
  24209. console.warn('Dom has no width or height');
  24210. return;
  24211. }
  24212. function getLayerGL(model) {
  24213. var zlevel;
  24214. // Host on coordinate system.
  24215. if (model.coordinateSystem && model.coordinateSystem.model) {
  24216. zlevel = model.get('zlevel');
  24217. }
  24218. else {
  24219. zlevel = model.get('zlevel');
  24220. }
  24221. var layers = self._layers;
  24222. var layerGL = layers[zlevel];
  24223. if (!layerGL) {
  24224. layerGL = layers[zlevel] = new __WEBPACK_IMPORTED_MODULE_2__core_LayerGL__["a" /* default */]('gl-' + zlevel, zr);
  24225. if (zr.painter.isSingleCanvas()) {
  24226. layerGL.virtual = true;
  24227. // If container is canvas, use image to represent LayerGL
  24228. // FIXME Performance
  24229. var img = new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.graphic.Image({
  24230. z: 1e4,
  24231. style: {
  24232. image: layerGL.renderer.canvas
  24233. },
  24234. silent: true
  24235. });
  24236. layerGL.__hostImage = img;
  24237. zr.add(img);
  24238. }
  24239. zr.painter.insertLayer(zlevel, layerGL);
  24240. }
  24241. if (layerGL.__hostImage) {
  24242. layerGL.__hostImage.setStyle({
  24243. width: layerGL.renderer.getWidth(),
  24244. height: layerGL.renderer.getHeight()
  24245. });
  24246. }
  24247. return layerGL;
  24248. }
  24249. function setSilent(groupGL, silent) {
  24250. if (groupGL) {
  24251. groupGL.traverse(function (mesh) {
  24252. if (mesh.isRenderable && mesh.isRenderable()) {
  24253. mesh.ignorePicking = mesh.$ignorePicking != null
  24254. ? mesh.$ignorePicking : silent;
  24255. }
  24256. });
  24257. }
  24258. }
  24259. for (var zlevel in this._layers) {
  24260. this._layers[zlevel].removeViewsAll();
  24261. }
  24262. ecModel.eachComponent(function (componentType, componentModel) {
  24263. if (componentType !== 'series') {
  24264. var view = api.getViewOfComponentModel(componentModel);
  24265. var coordSys = componentModel.coordinateSystem;
  24266. // View with __ecgl__ flag is a echarts-gl component.
  24267. if (view.__ecgl__) {
  24268. var viewGL;
  24269. if (coordSys) {
  24270. if (!coordSys.viewGL) {
  24271. console.error('Can\'t find viewGL in coordinateSystem of component ' + componentModel.id);
  24272. return;
  24273. }
  24274. viewGL = coordSys.viewGL;
  24275. }
  24276. else {
  24277. if (!componentModel.viewGL) {
  24278. console.error('Can\'t find viewGL of component ' + componentModel.id);
  24279. return;
  24280. }
  24281. viewGL = coordSys.viewGL;
  24282. }
  24283. var viewGL = coordSys.viewGL;
  24284. var layerGL = getLayerGL(componentModel);
  24285. layerGL.addView(viewGL);
  24286. view.afterRender && view.afterRender(
  24287. componentModel, ecModel, api, layerGL
  24288. );
  24289. setSilent(view.groupGL, componentModel.get('silent'));
  24290. }
  24291. }
  24292. });
  24293. ecModel.eachSeries(function (seriesModel) {
  24294. var chartView = api.getViewOfSeriesModel(seriesModel);
  24295. var coordSys = seriesModel.coordinateSystem;
  24296. if (chartView.__ecgl__) {
  24297. if ((coordSys && !coordSys.viewGL) && !chartView.viewGL) {
  24298. console.error('Can\'t find viewGL of series ' + chartView.id);
  24299. return;
  24300. }
  24301. var viewGL = (coordSys && coordSys.viewGL) || chartView.viewGL;
  24302. // TODO Check zlevel not same with component of coordinate system ?
  24303. var layerGL = getLayerGL(seriesModel);
  24304. layerGL.addView(viewGL);
  24305. chartView.afterRender && chartView.afterRender(
  24306. seriesModel, ecModel, api, layerGL
  24307. );
  24308. setSilent(chartView.groupGL, seriesModel.get('silent'));
  24309. }
  24310. });
  24311. };
  24312. // Hack original getRenderedCanvas. Will removed after new echarts released
  24313. // TODO
  24314. var oldInit = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.init;
  24315. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.init = function () {
  24316. var chart = oldInit.apply(this, arguments);
  24317. chart.getZr().painter.getRenderedCanvas = function (opts) {
  24318. opts = opts || {};
  24319. if (this._singleCanvas) {
  24320. return this._layers[0].dom;
  24321. }
  24322. var canvas = document.createElement('canvas');
  24323. var dpr = opts.pixelRatio || this.dpr;
  24324. canvas.width = this.getWidth() * dpr;
  24325. canvas.height = this.getHeight() * dpr;
  24326. var ctx = canvas.getContext('2d');
  24327. ctx.dpr = dpr;
  24328. ctx.clearRect(0, 0, canvas.width, canvas.height);
  24329. if (opts.backgroundColor) {
  24330. ctx.fillStyle = opts.backgroundColor;
  24331. ctx.fillRect(0, 0, canvas.width, canvas.height);
  24332. }
  24333. var displayList = this.storage.getDisplayList(true);
  24334. var scope = {};
  24335. var zlevel;
  24336. var self = this;
  24337. function findAndDrawOtherLayer(smaller, larger) {
  24338. var zlevelList = self._zlevelList;
  24339. if (smaller == null) {
  24340. smaller = -Infinity;
  24341. }
  24342. var intermediateLayer;
  24343. for (var i = 0; i < zlevelList.length; i++) {
  24344. var z = zlevelList[i];
  24345. var layer = self._layers[z];
  24346. if (!layer.__builtin__ && z > smaller && z < larger) {
  24347. intermediateLayer = layer;
  24348. break;
  24349. }
  24350. }
  24351. if (intermediateLayer && intermediateLayer.renderToCanvas) {
  24352. ctx.save();
  24353. intermediateLayer.renderToCanvas(ctx);
  24354. ctx.restore();
  24355. }
  24356. }
  24357. var layer = {
  24358. ctx: ctx
  24359. };
  24360. for (var i = 0; i < displayList.length; i++) {
  24361. var el = displayList[i];
  24362. if (el.zlevel !== zlevel) {
  24363. findAndDrawOtherLayer(zlevel, el.zlevel);
  24364. zlevel = el.zlevel;
  24365. }
  24366. this._doPaintEl(el, layer, true, scope);
  24367. }
  24368. findAndDrawOtherLayer(zlevel, Infinity);
  24369. return canvas;
  24370. };
  24371. return chart;
  24372. };
  24373. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerPostUpdate(function (ecModel, api) {
  24374. var zr = api.getZr();
  24375. var egl = zr.__egl = zr.__egl || new EChartsGL(zr);
  24376. egl.update(ecModel, api);
  24377. });
  24378. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerPreprocessor(__WEBPACK_IMPORTED_MODULE_3__preprocessor_backwardCompat__["a" /* default */]);
  24379. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.graphicGL = __WEBPACK_IMPORTED_MODULE_4__util_graphicGL__["a" /* default */];
  24380. /* unused harmony default export */ var _unused_webpack_default_export = (EChartsGL);
  24381. /***/
  24382. }),
  24383. /* 108 */
  24384. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  24385. "use strict";
  24386. /**
  24387. * @name clay.version
  24388. */
  24389. /* harmony default export */ __webpack_exports__["a"] = ('1.2.1');
  24390. /***/
  24391. }),
  24392. /* 109 */
  24393. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  24394. "use strict";
  24395. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  24396. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  24397. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_Renderer__ = __webpack_require__(52);
  24398. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_claygl_src_picking_RayPicking__ = __webpack_require__(117);
  24399. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture__ = __webpack_require__(4);
  24400. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__util_graphicGL__ = __webpack_require__(1);
  24401. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_claygl_src_core_mixin_notifier__ = __webpack_require__(53);
  24402. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_zrender_lib_animation_requestAnimationFrame__ = __webpack_require__(80);
  24403. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_zrender_lib_animation_requestAnimationFrame___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_6_zrender_lib_animation_requestAnimationFrame__);
  24404. /**
  24405. * Provide WebGL layer to zrender. Which is rendered on top of clay.
  24406. *
  24407. *
  24408. * Relationship between zrender, LayerGL(renderer) and ViewGL(Scene, Camera, Viewport)
  24409. * zrender
  24410. * / \
  24411. * LayerGL LayerGL
  24412. * (renderer) (renderer)
  24413. * / \
  24414. * ViewGL ViewGL
  24415. *
  24416. * @module echarts-gl/core/LayerGL
  24417. * @author Yi Shen(http://github.com/pissang)
  24418. */
  24419. // PENDING, clay. notifier is same with zrender Eventful
  24420. /**
  24421. * @constructor
  24422. * @alias module:echarts-gl/core/LayerGL
  24423. * @param {string} id Layer ID
  24424. * @param {module:zrender/ZRender} zr
  24425. */
  24426. var LayerGL = function (id, zr) {
  24427. /**
  24428. * Layer ID
  24429. * @type {string}
  24430. */
  24431. this.id = id;
  24432. /**
  24433. * @type {module:zrender/ZRender}
  24434. */
  24435. this.zr = zr;
  24436. /**
  24437. * @type {clay.Renderer}
  24438. */
  24439. try {
  24440. this.renderer = new __WEBPACK_IMPORTED_MODULE_1_claygl_src_Renderer__["a" /* default */]({
  24441. clearBit: 0,
  24442. devicePixelRatio: zr.painter.dpr,
  24443. preserveDrawingBuffer: true,
  24444. // PENDING
  24445. premultipliedAlpha: true
  24446. });
  24447. this.renderer.resize(zr.painter.getWidth(), zr.painter.getHeight());
  24448. }
  24449. catch (e) {
  24450. this.renderer = null;
  24451. this.dom = document.createElement('div');
  24452. this.dom.style.cssText = 'position:absolute; left: 0; top: 0; right: 0; bottom: 0;';
  24453. this.dom.className = 'ecgl-nowebgl';
  24454. this.dom.innerHTML = 'Sorry, your browser does not support WebGL';
  24455. console.error(e);
  24456. return;
  24457. }
  24458. this.onglobalout = this.onglobalout.bind(this);
  24459. zr.on('globalout', this.onglobalout);
  24460. /**
  24461. * Canvas dom for webgl rendering
  24462. * @type {HTMLCanvasElement}
  24463. */
  24464. this.dom = this.renderer.canvas;
  24465. var style = this.dom.style;
  24466. style.position = 'absolute';
  24467. style.left = '0';
  24468. style.top = '0';
  24469. /**
  24470. * @type {Array.<clay.Scene>}
  24471. */
  24472. this.views = [];
  24473. this._picking = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_picking_RayPicking__["a" /* default */]({
  24474. renderer: this.renderer
  24475. });
  24476. this._viewsToDispose = [];
  24477. /**
  24478. * Current accumulating id.
  24479. */
  24480. this._accumulatingId = 0;
  24481. this._zrEventProxy = new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.graphic.Rect({
  24482. shape: { x: -1, y: -1, width: 2, height: 2 },
  24483. // FIXME Better solution.
  24484. __isGLToZRProxy: true
  24485. });
  24486. this._backgroundColor = null;
  24487. };
  24488. /**
  24489. * @param {module:echarts-gl/core/ViewGL} view
  24490. */
  24491. LayerGL.prototype.addView = function (view) {
  24492. if (view.layer === this) {
  24493. return;
  24494. }
  24495. // If needs to dispose in this layer. unmark it.
  24496. var idx = this._viewsToDispose.indexOf(view);
  24497. if (idx >= 0) {
  24498. this._viewsToDispose.splice(idx, 1);
  24499. }
  24500. this.views.push(view);
  24501. view.layer = this;
  24502. var zr = this.zr;
  24503. view.scene.traverse(function (node) {
  24504. node.__zr = zr;
  24505. if (node.addAnimatorsToZr) {
  24506. node.addAnimatorsToZr(zr);
  24507. }
  24508. });
  24509. };
  24510. function removeFromZr(node) {
  24511. var zr = node.__zr;
  24512. node.__zr = null;
  24513. if (zr && node.removeAnimatorsFromZr) {
  24514. node.removeAnimatorsFromZr(zr);
  24515. }
  24516. }
  24517. /**
  24518. * @param {module:echarts-gl/core/ViewGL} view
  24519. */
  24520. LayerGL.prototype.removeView = function (view) {
  24521. if (view.layer !== this) {
  24522. return;
  24523. }
  24524. var idx = this.views.indexOf(view);
  24525. if (idx >= 0) {
  24526. this.views.splice(idx, 1);
  24527. view.scene.traverse(removeFromZr, this);
  24528. view.layer = null;
  24529. // Mark to dispose in this layer.
  24530. this._viewsToDispose.push(view);
  24531. }
  24532. };
  24533. /**
  24534. * Remove all views
  24535. */
  24536. LayerGL.prototype.removeViewsAll = function () {
  24537. this.views.forEach(function (view) {
  24538. view.scene.traverse(removeFromZr, this);
  24539. view.layer = null;
  24540. // Mark to dispose in this layer.
  24541. this._viewsToDispose.push(view);
  24542. }, this);
  24543. this.views.length = 0;
  24544. };
  24545. /**
  24546. * Resize the canvas and viewport, will be invoked by zrender
  24547. * @param {number} width
  24548. * @param {number} height
  24549. */
  24550. LayerGL.prototype.resize = function (width, height) {
  24551. var renderer = this.renderer;
  24552. renderer.resize(width, height);
  24553. };
  24554. /**
  24555. * Clear color and depth
  24556. * @return {[type]} [description]
  24557. */
  24558. LayerGL.prototype.clear = function () {
  24559. var gl = this.renderer.gl;
  24560. var clearColor = this._backgroundColor || [0, 0, 0, 0];
  24561. gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
  24562. gl.depthMask(true);
  24563. gl.colorMask(true, true, true, true);
  24564. gl.clear(gl.DEPTH_BUFFER_BIT | gl.COLOR_BUFFER_BIT);
  24565. };
  24566. /**
  24567. * Clear depth
  24568. */
  24569. LayerGL.prototype.clearDepth = function () {
  24570. var gl = this.renderer.gl;
  24571. gl.clear(gl.DEPTH_BUFFER_BIT);
  24572. };
  24573. /**
  24574. * Clear color
  24575. */
  24576. LayerGL.prototype.clearColor = function () {
  24577. var gl = this.renderer.gl;
  24578. gl.clearColor(0, 0, 0, 0);
  24579. gl.clear(gl.COLOR_BUFFER_BIT);
  24580. };
  24581. /**
  24582. * Mark layer to refresh next tick
  24583. */
  24584. LayerGL.prototype.needsRefresh = function () {
  24585. this.zr.refresh();
  24586. };
  24587. /**
  24588. * Refresh the layer, will be invoked by zrender
  24589. */
  24590. LayerGL.prototype.refresh = function (bgColor) {
  24591. this._backgroundColor = bgColor ? __WEBPACK_IMPORTED_MODULE_4__util_graphicGL__["a" /* default */].parseColor(bgColor) : [0, 0, 0, 0];
  24592. this.renderer.clearColor = this._backgroundColor;
  24593. for (var i = 0; i < this.views.length; i++) {
  24594. this.views[i].prepareRender(this.renderer);
  24595. }
  24596. this._doRender(false);
  24597. // Auto dispose unused resources on GPU, like program(shader), texture, geometry(buffers)
  24598. this._trackAndClean();
  24599. // Dispose trashed views
  24600. for (var i = 0; i < this._viewsToDispose.length; i++) {
  24601. this._viewsToDispose[i].dispose(this.renderer);
  24602. }
  24603. this._viewsToDispose.length = 0;
  24604. this._startAccumulating();
  24605. };
  24606. LayerGL.prototype.renderToCanvas = function (ctx) {
  24607. // PENDING will block the page
  24608. this._startAccumulating(true);
  24609. ctx.drawImage(this.dom, 0, 0, ctx.canvas.width, ctx.canvas.height);
  24610. };
  24611. LayerGL.prototype._doRender = function (accumulating) {
  24612. this.clear();
  24613. this.renderer.saveViewport();
  24614. for (var i = 0; i < this.views.length; i++) {
  24615. this.views[i].render(this.renderer, accumulating);
  24616. }
  24617. this.renderer.restoreViewport();
  24618. };
  24619. /**
  24620. * Stop accumulating
  24621. */
  24622. LayerGL.prototype._stopAccumulating = function () {
  24623. this._accumulatingId = 0;
  24624. clearTimeout(this._accumulatingTimeout);
  24625. };
  24626. var accumulatingId = 1;
  24627. /**
  24628. * Start accumulating all the views.
  24629. * Accumulating is for antialising and have more sampling in SSAO
  24630. * @private
  24631. */
  24632. LayerGL.prototype._startAccumulating = function (immediate) {
  24633. var self = this;
  24634. this._stopAccumulating();
  24635. var needsAccumulate = false;
  24636. for (var i = 0; i < this.views.length; i++) {
  24637. needsAccumulate = this.views[i].needsAccumulate() || needsAccumulate;
  24638. }
  24639. if (!needsAccumulate) {
  24640. return;
  24641. }
  24642. function accumulate(id) {
  24643. if (!self._accumulatingId || id !== self._accumulatingId) {
  24644. return;
  24645. }
  24646. var isFinished = true;
  24647. for (var i = 0; i < self.views.length; i++) {
  24648. isFinished = self.views[i].isAccumulateFinished() && needsAccumulate;
  24649. }
  24650. if (!isFinished) {
  24651. self._doRender(true);
  24652. if (immediate) {
  24653. accumulate(id);
  24654. }
  24655. else {
  24656. __WEBPACK_IMPORTED_MODULE_6_zrender_lib_animation_requestAnimationFrame___default()(function () {
  24657. accumulate(id);
  24658. });
  24659. }
  24660. }
  24661. }
  24662. this._accumulatingId = accumulatingId++;
  24663. if (immediate) {
  24664. accumulate(self._accumulatingId);
  24665. }
  24666. else {
  24667. this._accumulatingTimeout = setTimeout(function () {
  24668. accumulate(self._accumulatingId);
  24669. }, 50);
  24670. }
  24671. };
  24672. LayerGL.prototype._trackAndClean = function () {
  24673. var textureList = [];
  24674. var geometriesList = [];
  24675. // Mark all resources unused;
  24676. if (this._textureList) {
  24677. markUnused(this._textureList);
  24678. markUnused(this._geometriesList);
  24679. }
  24680. for (var i = 0; i < this.views.length; i++) {
  24681. collectResources(this.views[i].scene, textureList, geometriesList);
  24682. }
  24683. // Dispose those unsed resources.
  24684. if (this._textureList) {
  24685. checkAndDispose(this.renderer, this._textureList);
  24686. checkAndDispose(this.renderer, this._geometriesList);
  24687. }
  24688. this._textureList = textureList;
  24689. this._geometriesList = geometriesList;
  24690. };
  24691. function markUnused(resourceList) {
  24692. for (var i = 0; i < resourceList.length; i++) {
  24693. resourceList[i].__used__ = 0;
  24694. }
  24695. }
  24696. function checkAndDispose(renderer, resourceList) {
  24697. for (var i = 0; i < resourceList.length; i++) {
  24698. if (!resourceList[i].__used__) {
  24699. resourceList[i].dispose(renderer);
  24700. }
  24701. }
  24702. }
  24703. function updateUsed(resource, list) {
  24704. resource.__used__ = resource.__used__ || 0;
  24705. resource.__used__++;
  24706. if (resource.__used__ === 1) {
  24707. // Don't push to the list twice.
  24708. list.push(resource);
  24709. }
  24710. }
  24711. function collectResources(scene, textureResourceList, geometryResourceList) {
  24712. var prevMaterial;
  24713. var prevGeometry;
  24714. scene.traverse(function (renderable) {
  24715. if (renderable.isRenderable()) {
  24716. var geometry = renderable.geometry;
  24717. var material = renderable.material;
  24718. // TODO optimize!!
  24719. if (material !== prevMaterial) {
  24720. var textureUniforms = material.getTextureUniforms();
  24721. for (var u = 0; u < textureUniforms.length; u++) {
  24722. var uniformName = textureUniforms[u];
  24723. var val = material.uniforms[uniformName].value;
  24724. if (!val) {
  24725. continue;
  24726. }
  24727. if (val instanceof __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture__["a" /* default */]) {
  24728. updateUsed(val, textureResourceList);
  24729. }
  24730. else if (val instanceof Array) {
  24731. for (var k = 0; k < val.length; k++) {
  24732. if (val[k] instanceof __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture__["a" /* default */]) {
  24733. updateUsed(val[k], textureResourceList);
  24734. }
  24735. }
  24736. }
  24737. }
  24738. }
  24739. if (geometry !== prevGeometry) {
  24740. updateUsed(geometry, geometryResourceList);
  24741. }
  24742. prevMaterial = material;
  24743. prevGeometry = geometry;
  24744. }
  24745. });
  24746. for (var k = 0; k < scene.lights.length; k++) {
  24747. // Track AmbientCubemap
  24748. if (scene.lights[k].cubemap) {
  24749. updateUsed(scene.lights[k].cubemap, textureResourceList);
  24750. }
  24751. }
  24752. }
  24753. /**
  24754. * Dispose the layer
  24755. */
  24756. LayerGL.prototype.dispose = function () {
  24757. this._stopAccumulating();
  24758. this.renderer.disposeScene(this.scene);
  24759. this.zr.off('globalout', this.onglobalout);
  24760. };
  24761. // Event handlers
  24762. LayerGL.prototype.onmousedown = function (e) {
  24763. if (e.target && e.target.__isGLToZRProxy) {
  24764. return;
  24765. }
  24766. e = e.event;
  24767. var obj = this.pickObject(e.offsetX, e.offsetY);
  24768. if (obj) {
  24769. this._dispatchEvent('mousedown', e, obj);
  24770. this._dispatchDataEvent('mousedown', e, obj);
  24771. }
  24772. this._downX = e.offsetX;
  24773. this._downY = e.offsetY;
  24774. };
  24775. LayerGL.prototype.onmousemove = function (e) {
  24776. if (e.target && e.target.__isGLToZRProxy) {
  24777. return;
  24778. }
  24779. e = e.event;
  24780. var obj = this.pickObject(e.offsetX, e.offsetY);
  24781. var target = obj && obj.target;
  24782. var lastHovered = this._hovered;
  24783. this._hovered = obj;
  24784. if (lastHovered && target !== lastHovered.target) {
  24785. lastHovered.relatedTarget = target;
  24786. this._dispatchEvent('mouseout', e, lastHovered);
  24787. // this._dispatchDataEvent('mouseout', e, lastHovered);
  24788. this.zr.setCursorStyle('default');
  24789. }
  24790. this._dispatchEvent('mousemove', e, obj);
  24791. if (obj) {
  24792. this.zr.setCursorStyle('pointer');
  24793. if (!lastHovered || (target !== lastHovered.target)) {
  24794. this._dispatchEvent('mouseover', e, obj);
  24795. // this._dispatchDataEvent('mouseover', e, obj);
  24796. }
  24797. }
  24798. this._dispatchDataEvent('mousemove', e, obj);
  24799. };
  24800. LayerGL.prototype.onmouseup = function (e) {
  24801. if (e.target && e.target.__isGLToZRProxy) {
  24802. return;
  24803. }
  24804. e = e.event;
  24805. var obj = this.pickObject(e.offsetX, e.offsetY);
  24806. if (obj) {
  24807. this._dispatchEvent('mouseup', e, obj);
  24808. this._dispatchDataEvent('mouseup', e, obj);
  24809. }
  24810. this._upX = e.offsetX;
  24811. this._upY = e.offsetY;
  24812. };
  24813. LayerGL.prototype.onclick = LayerGL.prototype.dblclick = function (e) {
  24814. if (e.target && e.target.__isGLToZRProxy) {
  24815. return;
  24816. }
  24817. // Ignore click event if mouse moved
  24818. var dx = this._upX - this._downX;
  24819. var dy = this._upY - this._downY;
  24820. if (Math.sqrt(dx * dx + dy * dy) > 20) {
  24821. return;
  24822. }
  24823. e = e.event;
  24824. var obj = this.pickObject(e.offsetX, e.offsetY);
  24825. if (obj) {
  24826. this._dispatchEvent(e.type, e, obj);
  24827. this._dispatchDataEvent(e.type, e, obj);
  24828. }
  24829. // Try set depth of field onclick
  24830. var result = this._clickToSetFocusPoint(e);
  24831. if (result) {
  24832. var success = result.view.setDOFFocusOnPoint(result.distance);
  24833. if (success) {
  24834. this.zr.refresh();
  24835. }
  24836. }
  24837. };
  24838. LayerGL.prototype._clickToSetFocusPoint = function (e) {
  24839. var renderer = this.renderer;
  24840. var oldViewport = renderer.viewport;
  24841. for (var i = this.views.length - 1; i >= 0; i--) {
  24842. var viewGL = this.views[i];
  24843. if (viewGL.hasDOF() && viewGL.containPoint(e.offsetX, e.offsetY)) {
  24844. this._picking.scene = viewGL.scene;
  24845. this._picking.camera = viewGL.camera;
  24846. // Only used for picking, renderer.setViewport will also invoke gl.viewport.
  24847. // Set directly, PENDING.
  24848. renderer.viewport = viewGL.viewport;
  24849. var result = this._picking.pick(e.offsetX, e.offsetY, true);
  24850. if (result) {
  24851. result.view = viewGL;
  24852. return result;
  24853. }
  24854. }
  24855. }
  24856. renderer.viewport = oldViewport;
  24857. };
  24858. LayerGL.prototype.onglobalout = function (e) {
  24859. var lastHovered = this._hovered;
  24860. if (lastHovered) {
  24861. this._dispatchEvent('mouseout', e, {
  24862. target: lastHovered.target
  24863. });
  24864. }
  24865. };
  24866. LayerGL.prototype.pickObject = function (x, y) {
  24867. var output = [];
  24868. var renderer = this.renderer;
  24869. var oldViewport = renderer.viewport;
  24870. for (var i = 0; i < this.views.length; i++) {
  24871. var viewGL = this.views[i];
  24872. if (viewGL.containPoint(x, y)) {
  24873. this._picking.scene = viewGL.scene;
  24874. this._picking.camera = viewGL.camera;
  24875. // Only used for picking, renderer.setViewport will also invoke gl.viewport.
  24876. // Set directly, PENDING.
  24877. renderer.viewport = viewGL.viewport;
  24878. this._picking.pickAll(x, y, output);
  24879. }
  24880. }
  24881. renderer.viewport = oldViewport;
  24882. output.sort(function (a, b) {
  24883. return a.distance - b.distance;
  24884. });
  24885. return output[0];
  24886. };
  24887. LayerGL.prototype._dispatchEvent = function (eveName, originalEvent, newEvent) {
  24888. if (!newEvent) {
  24889. newEvent = {};
  24890. }
  24891. var current = newEvent.target;
  24892. newEvent.cancelBubble = false;
  24893. newEvent.event = originalEvent;
  24894. newEvent.type = eveName;
  24895. newEvent.offsetX = originalEvent.offsetX;
  24896. newEvent.offsetY = originalEvent.offsetY;
  24897. while (current) {
  24898. current.trigger(eveName, newEvent);
  24899. current = current.getParent();
  24900. if (newEvent.cancelBubble) {
  24901. break;
  24902. }
  24903. }
  24904. this._dispatchToView(eveName, newEvent);
  24905. };
  24906. LayerGL.prototype._dispatchDataEvent = function (eveName, originalEvent, newEvent) {
  24907. var mesh = newEvent && newEvent.target;
  24908. var dataIndex = mesh && mesh.dataIndex;
  24909. var seriesIndex = mesh && mesh.seriesIndex;
  24910. // Custom event data
  24911. var eventData = mesh && mesh.eventData;
  24912. var elChangedInMouseMove = false;
  24913. var eventProxy = this._zrEventProxy;
  24914. eventProxy.position = [originalEvent.offsetX, originalEvent.offsetY];
  24915. eventProxy.update();
  24916. var targetInfo = {
  24917. target: eventProxy
  24918. };
  24919. if (eveName === 'mousemove') {
  24920. if (dataIndex != null) {
  24921. if (dataIndex !== this._lastDataIndex) {
  24922. if (parseInt(this._lastDataIndex, 10) >= 0) {
  24923. eventProxy.dataIndex = this._lastDataIndex;
  24924. eventProxy.seriesIndex = this._lastSeriesIndex;
  24925. // FIXME May cause double events.
  24926. this.zr.handler.dispatchToElement(targetInfo, 'mouseout', originalEvent);
  24927. }
  24928. elChangedInMouseMove = true;
  24929. }
  24930. }
  24931. else if (eventData != null) {
  24932. if (eventData !== this._lastEventData) {
  24933. if (this._lastEventData != null) {
  24934. eventProxy.eventData = this._lastEventData;
  24935. // FIXME May cause double events.
  24936. this.zr.handler.dispatchToElement(targetInfo, 'mouseout', originalEvent);
  24937. }
  24938. elChangedInMouseMove = true;
  24939. }
  24940. }
  24941. this._lastEventData = eventData;
  24942. this._lastDataIndex = dataIndex;
  24943. this._lastSeriesIndex = seriesIndex;
  24944. }
  24945. eventProxy.eventData = eventData;
  24946. eventProxy.dataIndex = dataIndex;
  24947. eventProxy.seriesIndex = seriesIndex;
  24948. if (eventData != null || (parseInt(dataIndex, 10) >= 0 && parseInt(seriesIndex, 10) >= 0)) {
  24949. this.zr.handler.dispatchToElement(targetInfo, eveName, originalEvent);
  24950. if (elChangedInMouseMove) {
  24951. this.zr.handler.dispatchToElement(targetInfo, 'mouseover', originalEvent);
  24952. }
  24953. }
  24954. };
  24955. LayerGL.prototype._dispatchToView = function (eventName, e) {
  24956. for (var i = 0; i < this.views.length; i++) {
  24957. if (this.views[i].containPoint(e.offsetX, e.offsetY)) {
  24958. this.views[i].trigger(eventName, e);
  24959. }
  24960. }
  24961. };
  24962. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.extend(LayerGL.prototype, __WEBPACK_IMPORTED_MODULE_5_claygl_src_core_mixin_notifier__["a" /* default */]);
  24963. /* harmony default export */ __webpack_exports__["a"] = (LayerGL);
  24964. /***/
  24965. }),
  24966. /* 110 */
  24967. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  24968. "use strict";
  24969. /**
  24970. * Extend a sub class from base class
  24971. * @param {object|Function} makeDefaultOpt default option of this sub class, method of the sub can use this.xxx to access this option
  24972. * @param {Function} [initialize] Initialize after the sub class is instantiated
  24973. * @param {Object} [proto] Prototype methods/properties of the sub class
  24974. * @memberOf clay.core.mixin.extend
  24975. * @return {Function}
  24976. */
  24977. function derive(makeDefaultOpt, initialize/*optional*/, proto/*optional*/) {
  24978. if (typeof initialize == 'object') {
  24979. proto = initialize;
  24980. initialize = null;
  24981. }
  24982. var _super = this;
  24983. var propList;
  24984. if (!(makeDefaultOpt instanceof Function)) {
  24985. // Optimize the property iterate if it have been fixed
  24986. propList = [];
  24987. for (var propName in makeDefaultOpt) {
  24988. if (makeDefaultOpt.hasOwnProperty(propName)) {
  24989. propList.push(propName);
  24990. }
  24991. }
  24992. }
  24993. var sub = function (options) {
  24994. // call super constructor
  24995. _super.apply(this, arguments);
  24996. if (makeDefaultOpt instanceof Function) {
  24997. // Invoke makeDefaultOpt each time if it is a function, So we can make sure each
  24998. // property in the object will not be shared by mutiple instances
  24999. extend(this, makeDefaultOpt.call(this, options));
  25000. }
  25001. else {
  25002. extendWithPropList(this, makeDefaultOpt, propList);
  25003. }
  25004. if (this.constructor === sub) {
  25005. // Initialize function will be called in the order of inherit
  25006. var initializers = sub.__initializers__;
  25007. for (var i = 0; i < initializers.length; i++) {
  25008. initializers[i].apply(this, arguments);
  25009. }
  25010. }
  25011. };
  25012. // save super constructor
  25013. sub.__super__ = _super;
  25014. // Initialize function will be called after all the super constructor is called
  25015. if (!_super.__initializers__) {
  25016. sub.__initializers__ = [];
  25017. } else {
  25018. sub.__initializers__ = _super.__initializers__.slice();
  25019. }
  25020. if (initialize) {
  25021. sub.__initializers__.push(initialize);
  25022. }
  25023. var Ctor = function () { };
  25024. Ctor.prototype = _super.prototype;
  25025. sub.prototype = new Ctor();
  25026. sub.prototype.constructor = sub;
  25027. extend(sub.prototype, proto);
  25028. // extend the derive method as a static method;
  25029. sub.extend = _super.extend;
  25030. // DEPCRATED
  25031. sub.derive = _super.extend;
  25032. return sub;
  25033. }
  25034. function extend(target, source) {
  25035. if (!source) {
  25036. return;
  25037. }
  25038. for (var name in source) {
  25039. if (source.hasOwnProperty(name)) {
  25040. target[name] = source[name];
  25041. }
  25042. }
  25043. }
  25044. function extendWithPropList(target, source, propList) {
  25045. for (var i = 0; i < propList.length; i++) {
  25046. var propName = propList[i];
  25047. target[propName] = source[propName];
  25048. }
  25049. }
  25050. /**
  25051. * @alias clay.core.mixin.extend
  25052. * @mixin
  25053. */
  25054. /* harmony default export */ __webpack_exports__["a"] = ({
  25055. extend: derive,
  25056. // DEPCRATED
  25057. derive: derive
  25058. });
  25059. /***/
  25060. }),
  25061. /* 111 */
  25062. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  25063. "use strict";
  25064. var EXTENSION_LIST = [
  25065. 'OES_texture_float',
  25066. 'OES_texture_half_float',
  25067. 'OES_texture_float_linear',
  25068. 'OES_texture_half_float_linear',
  25069. 'OES_standard_derivatives',
  25070. 'OES_vertex_array_object',
  25071. 'OES_element_index_uint',
  25072. 'WEBGL_compressed_texture_s3tc',
  25073. 'WEBGL_depth_texture',
  25074. 'EXT_texture_filter_anisotropic',
  25075. 'EXT_shader_texture_lod',
  25076. 'WEBGL_draw_buffers',
  25077. 'EXT_frag_depth',
  25078. 'EXT_sRGB'
  25079. ];
  25080. var PARAMETER_NAMES = [
  25081. 'MAX_TEXTURE_SIZE',
  25082. 'MAX_CUBE_MAP_TEXTURE_SIZE'
  25083. ];
  25084. function GLInfo(_gl) {
  25085. var extensions = {};
  25086. var parameters = {};
  25087. // Get webgl extension
  25088. for (var i = 0; i < EXTENSION_LIST.length; i++) {
  25089. var extName = EXTENSION_LIST[i];
  25090. createExtension(extName);
  25091. }
  25092. // Get parameters
  25093. for (var i = 0; i < PARAMETER_NAMES.length; i++) {
  25094. var name = PARAMETER_NAMES[i];
  25095. parameters[name] = _gl.getParameter(_gl[name]);
  25096. }
  25097. this.getExtension = function (name) {
  25098. if (!(name in extensions)) {
  25099. createExtension(name);
  25100. }
  25101. return extensions[name];
  25102. };
  25103. this.getParameter = function (name) {
  25104. return parameters[name];
  25105. };
  25106. this.getMaxJointNumber = function () {
  25107. return 15;
  25108. };
  25109. function createExtension(name) {
  25110. var ext = _gl.getExtension(name);
  25111. if (!ext) {
  25112. ext = _gl.getExtension('MOZ_' + name);
  25113. }
  25114. if (!ext) {
  25115. ext = _gl.getExtension('WEBKIT_' + name);
  25116. }
  25117. extensions[name] = ext;
  25118. }
  25119. }
  25120. /* harmony default export */ __webpack_exports__["a"] = (GLInfo);
  25121. /***/
  25122. }),
  25123. /* 112 */
  25124. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  25125. "use strict";
  25126. function get(options) {
  25127. var xhr = new XMLHttpRequest();
  25128. xhr.open('get', options.url);
  25129. // With response type set browser can get and put binary data
  25130. // https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest/Sending_and_Receiving_Binary_Data
  25131. // Default is text, and it can be set
  25132. // arraybuffer, blob, document, json, text
  25133. xhr.responseType = options.responseType || 'text';
  25134. if (options.onprogress) {
  25135. //https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest/Using_XMLHttpRequest
  25136. xhr.onprogress = function (e) {
  25137. if (e.lengthComputable) {
  25138. var percent = e.loaded / e.total;
  25139. options.onprogress(percent, e.loaded, e.total);
  25140. }
  25141. else {
  25142. options.onprogress(null);
  25143. }
  25144. };
  25145. }
  25146. xhr.onload = function (e) {
  25147. if (xhr.status >= 400) {
  25148. options.onerror && options.onerror();
  25149. }
  25150. else {
  25151. options.onload && options.onload(xhr.response);
  25152. }
  25153. };
  25154. if (options.onerror) {
  25155. xhr.onerror = options.onerror;
  25156. }
  25157. xhr.send(null);
  25158. }
  25159. /* harmony default export */ __webpack_exports__["a"] = ({
  25160. get: get
  25161. });
  25162. /***/
  25163. }),
  25164. /* 113 */
  25165. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  25166. "use strict";
  25167. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__core_LRU__ = __webpack_require__(69);
  25168. /**
  25169. * @namespace clay.core.color
  25170. */
  25171. var colorUtil = {};
  25172. var kCSSColorTable = {
  25173. 'transparent': [0, 0, 0, 0], 'aliceblue': [240, 248, 255, 1],
  25174. 'antiquewhite': [250, 235, 215, 1], 'aqua': [0, 255, 255, 1],
  25175. 'aquamarine': [127, 255, 212, 1], 'azure': [240, 255, 255, 1],
  25176. 'beige': [245, 245, 220, 1], 'bisque': [255, 228, 196, 1],
  25177. 'black': [0, 0, 0, 1], 'blanchedalmond': [255, 235, 205, 1],
  25178. 'blue': [0, 0, 255, 1], 'blueviolet': [138, 43, 226, 1],
  25179. 'brown': [165, 42, 42, 1], 'burlywood': [222, 184, 135, 1],
  25180. 'cadetblue': [95, 158, 160, 1], 'chartreuse': [127, 255, 0, 1],
  25181. 'chocolate': [210, 105, 30, 1], 'coral': [255, 127, 80, 1],
  25182. 'cornflowerblue': [100, 149, 237, 1], 'cornsilk': [255, 248, 220, 1],
  25183. 'crimson': [220, 20, 60, 1], 'cyan': [0, 255, 255, 1],
  25184. 'darkblue': [0, 0, 139, 1], 'darkcyan': [0, 139, 139, 1],
  25185. 'darkgoldenrod': [184, 134, 11, 1], 'darkgray': [169, 169, 169, 1],
  25186. 'darkgreen': [0, 100, 0, 1], 'darkgrey': [169, 169, 169, 1],
  25187. 'darkkhaki': [189, 183, 107, 1], 'darkmagenta': [139, 0, 139, 1],
  25188. 'darkolivegreen': [85, 107, 47, 1], 'darkorange': [255, 140, 0, 1],
  25189. 'darkorchid': [153, 50, 204, 1], 'darkred': [139, 0, 0, 1],
  25190. 'darksalmon': [233, 150, 122, 1], 'darkseagreen': [143, 188, 143, 1],
  25191. 'darkslateblue': [72, 61, 139, 1], 'darkslategray': [47, 79, 79, 1],
  25192. 'darkslategrey': [47, 79, 79, 1], 'darkturquoise': [0, 206, 209, 1],
  25193. 'darkviolet': [148, 0, 211, 1], 'deeppink': [255, 20, 147, 1],
  25194. 'deepskyblue': [0, 191, 255, 1], 'dimgray': [105, 105, 105, 1],
  25195. 'dimgrey': [105, 105, 105, 1], 'dodgerblue': [30, 144, 255, 1],
  25196. 'firebrick': [178, 34, 34, 1], 'floralwhite': [255, 250, 240, 1],
  25197. 'forestgreen': [34, 139, 34, 1], 'fuchsia': [255, 0, 255, 1],
  25198. 'gainsboro': [220, 220, 220, 1], 'ghostwhite': [248, 248, 255, 1],
  25199. 'gold': [255, 215, 0, 1], 'goldenrod': [218, 165, 32, 1],
  25200. 'gray': [128, 128, 128, 1], 'green': [0, 128, 0, 1],
  25201. 'greenyellow': [173, 255, 47, 1], 'grey': [128, 128, 128, 1],
  25202. 'honeydew': [240, 255, 240, 1], 'hotpink': [255, 105, 180, 1],
  25203. 'indianred': [205, 92, 92, 1], 'indigo': [75, 0, 130, 1],
  25204. 'ivory': [255, 255, 240, 1], 'khaki': [240, 230, 140, 1],
  25205. 'lavender': [230, 230, 250, 1], 'lavenderblush': [255, 240, 245, 1],
  25206. 'lawngreen': [124, 252, 0, 1], 'lemonchiffon': [255, 250, 205, 1],
  25207. 'lightblue': [173, 216, 230, 1], 'lightcoral': [240, 128, 128, 1],
  25208. 'lightcyan': [224, 255, 255, 1], 'lightgoldenrodyellow': [250, 250, 210, 1],
  25209. 'lightgray': [211, 211, 211, 1], 'lightgreen': [144, 238, 144, 1],
  25210. 'lightgrey': [211, 211, 211, 1], 'lightpink': [255, 182, 193, 1],
  25211. 'lightsalmon': [255, 160, 122, 1], 'lightseagreen': [32, 178, 170, 1],
  25212. 'lightskyblue': [135, 206, 250, 1], 'lightslategray': [119, 136, 153, 1],
  25213. 'lightslategrey': [119, 136, 153, 1], 'lightsteelblue': [176, 196, 222, 1],
  25214. 'lightyellow': [255, 255, 224, 1], 'lime': [0, 255, 0, 1],
  25215. 'limegreen': [50, 205, 50, 1], 'linen': [250, 240, 230, 1],
  25216. 'magenta': [255, 0, 255, 1], 'maroon': [128, 0, 0, 1],
  25217. 'mediumaquamarine': [102, 205, 170, 1], 'mediumblue': [0, 0, 205, 1],
  25218. 'mediumorchid': [186, 85, 211, 1], 'mediumpurple': [147, 112, 219, 1],
  25219. 'mediumseagreen': [60, 179, 113, 1], 'mediumslateblue': [123, 104, 238, 1],
  25220. 'mediumspringgreen': [0, 250, 154, 1], 'mediumturquoise': [72, 209, 204, 1],
  25221. 'mediumvioletred': [199, 21, 133, 1], 'midnightblue': [25, 25, 112, 1],
  25222. 'mintcream': [245, 255, 250, 1], 'mistyrose': [255, 228, 225, 1],
  25223. 'moccasin': [255, 228, 181, 1], 'navajowhite': [255, 222, 173, 1],
  25224. 'navy': [0, 0, 128, 1], 'oldlace': [253, 245, 230, 1],
  25225. 'olive': [128, 128, 0, 1], 'olivedrab': [107, 142, 35, 1],
  25226. 'orange': [255, 165, 0, 1], 'orangered': [255, 69, 0, 1],
  25227. 'orchid': [218, 112, 214, 1], 'palegoldenrod': [238, 232, 170, 1],
  25228. 'palegreen': [152, 251, 152, 1], 'paleturquoise': [175, 238, 238, 1],
  25229. 'palevioletred': [219, 112, 147, 1], 'papayawhip': [255, 239, 213, 1],
  25230. 'peachpuff': [255, 218, 185, 1], 'peru': [205, 133, 63, 1],
  25231. 'pink': [255, 192, 203, 1], 'plum': [221, 160, 221, 1],
  25232. 'powderblue': [176, 224, 230, 1], 'purple': [128, 0, 128, 1],
  25233. 'red': [255, 0, 0, 1], 'rosybrown': [188, 143, 143, 1],
  25234. 'royalblue': [65, 105, 225, 1], 'saddlebrown': [139, 69, 19, 1],
  25235. 'salmon': [250, 128, 114, 1], 'sandybrown': [244, 164, 96, 1],
  25236. 'seagreen': [46, 139, 87, 1], 'seashell': [255, 245, 238, 1],
  25237. 'sienna': [160, 82, 45, 1], 'silver': [192, 192, 192, 1],
  25238. 'skyblue': [135, 206, 235, 1], 'slateblue': [106, 90, 205, 1],
  25239. 'slategray': [112, 128, 144, 1], 'slategrey': [112, 128, 144, 1],
  25240. 'snow': [255, 250, 250, 1], 'springgreen': [0, 255, 127, 1],
  25241. 'steelblue': [70, 130, 180, 1], 'tan': [210, 180, 140, 1],
  25242. 'teal': [0, 128, 128, 1], 'thistle': [216, 191, 216, 1],
  25243. 'tomato': [255, 99, 71, 1], 'turquoise': [64, 224, 208, 1],
  25244. 'violet': [238, 130, 238, 1], 'wheat': [245, 222, 179, 1],
  25245. 'white': [255, 255, 255, 1], 'whitesmoke': [245, 245, 245, 1],
  25246. 'yellow': [255, 255, 0, 1], 'yellowgreen': [154, 205, 50, 1]
  25247. };
  25248. function clampCssByte(i) { // Clamp to integer 0 .. 255.
  25249. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  25250. return i < 0 ? 0 : i > 255 ? 255 : i;
  25251. }
  25252. function clampCssAngle(i) { // Clamp to integer 0 .. 360.
  25253. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  25254. return i < 0 ? 0 : i > 360 ? 360 : i;
  25255. }
  25256. function clampCssFloat(f) { // Clamp to float 0.0 .. 1.0.
  25257. return f < 0 ? 0 : f > 1 ? 1 : f;
  25258. }
  25259. function parseCssInt(str) { // int or percentage.
  25260. if (str.length && str.charAt(str.length - 1) === '%') {
  25261. return clampCssByte(parseFloat(str) / 100 * 255);
  25262. }
  25263. return clampCssByte(parseInt(str, 10));
  25264. }
  25265. function parseCssFloat(str) { // float or percentage.
  25266. if (str.length && str.charAt(str.length - 1) === '%') {
  25267. return clampCssFloat(parseFloat(str) / 100);
  25268. }
  25269. return clampCssFloat(parseFloat(str));
  25270. }
  25271. function cssHueToRgb(m1, m2, h) {
  25272. if (h < 0) {
  25273. h += 1;
  25274. }
  25275. else if (h > 1) {
  25276. h -= 1;
  25277. }
  25278. if (h * 6 < 1) {
  25279. return m1 + (m2 - m1) * h * 6;
  25280. }
  25281. if (h * 2 < 1) {
  25282. return m2;
  25283. }
  25284. if (h * 3 < 2) {
  25285. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  25286. }
  25287. return m1;
  25288. }
  25289. function lerpNumber(a, b, p) {
  25290. return a + (b - a) * p;
  25291. }
  25292. function setRgba(out, r, g, b, a) {
  25293. out[0] = r; out[1] = g; out[2] = b; out[3] = a;
  25294. return out;
  25295. }
  25296. function copyRgba(out, a) {
  25297. out[0] = a[0]; out[1] = a[1]; out[2] = a[2]; out[3] = a[3];
  25298. return out;
  25299. }
  25300. var colorCache = new __WEBPACK_IMPORTED_MODULE_0__core_LRU__["a" /* default */](20);
  25301. var lastRemovedArr = null;
  25302. function putToCache(colorStr, rgbaArr) {
  25303. // Reuse removed array
  25304. if (lastRemovedArr) {
  25305. copyRgba(lastRemovedArr, rgbaArr);
  25306. }
  25307. lastRemovedArr = colorCache.put(colorStr, lastRemovedArr || (rgbaArr.slice()));
  25308. }
  25309. /**
  25310. * @name clay.core.color.parse
  25311. * @param {string} colorStr
  25312. * @param {Array.<number>} out
  25313. * @return {Array.<number>}
  25314. */
  25315. colorUtil.parse = function (colorStr, rgbaArr) {
  25316. if (!colorStr) {
  25317. return;
  25318. }
  25319. rgbaArr = rgbaArr || [];
  25320. var cached = colorCache.get(colorStr);
  25321. if (cached) {
  25322. return copyRgba(rgbaArr, cached);
  25323. }
  25324. // colorStr may be not string
  25325. colorStr = colorStr + '';
  25326. // Remove all whitespace, not compliant, but should just be more accepting.
  25327. var str = colorStr.replace(/ /g, '').toLowerCase();
  25328. // Color keywords (and transparent) lookup.
  25329. if (str in kCSSColorTable) {
  25330. copyRgba(rgbaArr, kCSSColorTable[str]);
  25331. putToCache(colorStr, rgbaArr);
  25332. return rgbaArr;
  25333. }
  25334. // #abc and #abc123 syntax.
  25335. if (str.charAt(0) === '#') {
  25336. if (str.length === 4) {
  25337. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  25338. if (!(iv >= 0 && iv <= 0xfff)) {
  25339. setRgba(rgbaArr, 0, 0, 0, 1);
  25340. return; // Covers NaN.
  25341. }
  25342. setRgba(rgbaArr,
  25343. ((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8),
  25344. (iv & 0xf0) | ((iv & 0xf0) >> 4),
  25345. (iv & 0xf) | ((iv & 0xf) << 4),
  25346. 1
  25347. );
  25348. putToCache(colorStr, rgbaArr);
  25349. return rgbaArr;
  25350. }
  25351. else if (str.length === 7) {
  25352. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  25353. if (!(iv >= 0 && iv <= 0xffffff)) {
  25354. setRgba(rgbaArr, 0, 0, 0, 1);
  25355. return; // Covers NaN.
  25356. }
  25357. setRgba(rgbaArr,
  25358. (iv & 0xff0000) >> 16,
  25359. (iv & 0xff00) >> 8,
  25360. iv & 0xff,
  25361. 1
  25362. );
  25363. putToCache(colorStr, rgbaArr);
  25364. return rgbaArr;
  25365. }
  25366. return;
  25367. }
  25368. var op = str.indexOf('('), ep = str.indexOf(')');
  25369. if (op !== -1 && ep + 1 === str.length) {
  25370. var fname = str.substr(0, op);
  25371. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  25372. var alpha = 1; // To allow case fallthrough.
  25373. switch (fname) {
  25374. case 'rgba':
  25375. if (params.length !== 4) {
  25376. setRgba(rgbaArr, 0, 0, 0, 1);
  25377. return;
  25378. }
  25379. alpha = parseCssFloat(params.pop()); // jshint ignore:line
  25380. // Fall through.
  25381. case 'rgb':
  25382. if (params.length !== 3) {
  25383. setRgba(rgbaArr, 0, 0, 0, 1);
  25384. return;
  25385. }
  25386. setRgba(rgbaArr,
  25387. parseCssInt(params[0]),
  25388. parseCssInt(params[1]),
  25389. parseCssInt(params[2]),
  25390. alpha
  25391. );
  25392. putToCache(colorStr, rgbaArr);
  25393. return rgbaArr;
  25394. case 'hsla':
  25395. if (params.length !== 4) {
  25396. setRgba(rgbaArr, 0, 0, 0, 1);
  25397. return;
  25398. }
  25399. params[3] = parseCssFloat(params[3]);
  25400. hsla2rgba(params, rgbaArr);
  25401. putToCache(colorStr, rgbaArr);
  25402. return rgbaArr;
  25403. case 'hsl':
  25404. if (params.length !== 3) {
  25405. setRgba(rgbaArr, 0, 0, 0, 1);
  25406. return;
  25407. }
  25408. hsla2rgba(params, rgbaArr);
  25409. putToCache(colorStr, rgbaArr);
  25410. return rgbaArr;
  25411. default:
  25412. return;
  25413. }
  25414. }
  25415. setRgba(rgbaArr, 0, 0, 0, 1);
  25416. return;
  25417. };
  25418. colorUtil.parseToFloat = function (colorStr, rgbaArr) {
  25419. rgbaArr = colorUtil.parse(colorStr, rgbaArr);
  25420. if (!rgbaArr) {
  25421. return;
  25422. }
  25423. rgbaArr[0] /= 255;
  25424. rgbaArr[1] /= 255;
  25425. rgbaArr[2] /= 255;
  25426. return rgbaArr;
  25427. }
  25428. /**
  25429. * @name clay.core.color.hsla2rgba
  25430. * @param {Array.<number>} hsla
  25431. * @param {Array.<number>} rgba
  25432. * @return {Array.<number>} rgba
  25433. */
  25434. function hsla2rgba(hsla, rgba) {
  25435. var h = (((parseFloat(hsla[0]) % 360) + 360) % 360) / 360; // 0 .. 1
  25436. // NOTE(deanm): According to the CSS spec s/l should only be
  25437. // percentages, but we don't bother and let float or percentage.
  25438. var s = parseCssFloat(hsla[1]);
  25439. var l = parseCssFloat(hsla[2]);
  25440. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  25441. var m1 = l * 2 - m2;
  25442. rgba = rgba || [];
  25443. setRgba(rgba,
  25444. clampCssByte(cssHueToRgb(m1, m2, h + 1 / 3) * 255),
  25445. clampCssByte(cssHueToRgb(m1, m2, h) * 255),
  25446. clampCssByte(cssHueToRgb(m1, m2, h - 1 / 3) * 255),
  25447. 1
  25448. );
  25449. if (hsla.length === 4) {
  25450. rgba[3] = hsla[3];
  25451. }
  25452. return rgba;
  25453. }
  25454. /**
  25455. * @name clay.core.color.rgba2hsla
  25456. * @param {Array.<number>} rgba
  25457. * @return {Array.<number>} hsla
  25458. */
  25459. function rgba2hsla(rgba) {
  25460. if (!rgba) {
  25461. return;
  25462. }
  25463. // RGB from 0 to 255
  25464. var R = rgba[0] / 255;
  25465. var G = rgba[1] / 255;
  25466. var B = rgba[2] / 255;
  25467. var vMin = Math.min(R, G, B); // Min. value of RGB
  25468. var vMax = Math.max(R, G, B); // Max. value of RGB
  25469. var delta = vMax - vMin; // Delta RGB value
  25470. var L = (vMax + vMin) / 2;
  25471. var H;
  25472. var S;
  25473. // HSL results from 0 to 1
  25474. if (delta === 0) {
  25475. H = 0;
  25476. S = 0;
  25477. }
  25478. else {
  25479. if (L < 0.5) {
  25480. S = delta / (vMax + vMin);
  25481. }
  25482. else {
  25483. S = delta / (2 - vMax - vMin);
  25484. }
  25485. var deltaR = (((vMax - R) / 6) + (delta / 2)) / delta;
  25486. var deltaG = (((vMax - G) / 6) + (delta / 2)) / delta;
  25487. var deltaB = (((vMax - B) / 6) + (delta / 2)) / delta;
  25488. if (R === vMax) {
  25489. H = deltaB - deltaG;
  25490. }
  25491. else if (G === vMax) {
  25492. H = (1 / 3) + deltaR - deltaB;
  25493. }
  25494. else if (B === vMax) {
  25495. H = (2 / 3) + deltaG - deltaR;
  25496. }
  25497. if (H < 0) {
  25498. H += 1;
  25499. }
  25500. if (H > 1) {
  25501. H -= 1;
  25502. }
  25503. }
  25504. var hsla = [H * 360, S, L];
  25505. if (rgba[3] != null) {
  25506. hsla.push(rgba[3]);
  25507. }
  25508. return hsla;
  25509. }
  25510. /**
  25511. * @name clay.core.color.lift
  25512. * @param {string} color
  25513. * @param {number} level
  25514. * @return {string}
  25515. */
  25516. colorUtil.lift = function (color, level) {
  25517. var colorArr = colorUtil.parse(color);
  25518. if (colorArr) {
  25519. for (var i = 0; i < 3; i++) {
  25520. if (level < 0) {
  25521. colorArr[i] = colorArr[i] * (1 - level) | 0;
  25522. }
  25523. else {
  25524. colorArr[i] = ((255 - colorArr[i]) * level + colorArr[i]) | 0;
  25525. }
  25526. }
  25527. return colorUtil.stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  25528. }
  25529. }
  25530. /**
  25531. * @name clay.core.color.toHex
  25532. * @param {string} color
  25533. * @return {string}
  25534. */
  25535. colorUtil.toHex = function (color) {
  25536. var colorArr = colorUtil.parse(color);
  25537. if (colorArr) {
  25538. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + (+colorArr[2])).toString(16).slice(1);
  25539. }
  25540. };
  25541. /**
  25542. * Map value to color. Faster than lerp methods because color is represented by rgba array.
  25543. * @name clay.core.color
  25544. * @param {number} normalizedValue A float between 0 and 1.
  25545. * @param {Array.<Array.<number>>} colors List of rgba color array
  25546. * @param {Array.<number>} [out] Mapped gba color array
  25547. * @return {Array.<number>} will be null/undefined if input illegal.
  25548. */
  25549. colorUtil.fastLerp = function (normalizedValue, colors, out) {
  25550. if (!(colors && colors.length)
  25551. || !(normalizedValue >= 0 && normalizedValue <= 1)
  25552. ) {
  25553. return;
  25554. }
  25555. out = out || [];
  25556. var value = normalizedValue * (colors.length - 1);
  25557. var leftIndex = Math.floor(value);
  25558. var rightIndex = Math.ceil(value);
  25559. var leftColor = colors[leftIndex];
  25560. var rightColor = colors[rightIndex];
  25561. var dv = value - leftIndex;
  25562. out[0] = clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv));
  25563. out[1] = clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv));
  25564. out[2] = clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv));
  25565. out[3] = clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv));
  25566. return out;
  25567. }
  25568. colorUtil.fastMapToColor = colorUtil.fastLerp;
  25569. /**
  25570. * @param {number} normalizedValue A float between 0 and 1.
  25571. * @param {Array.<string>} colors Color list.
  25572. * @param {boolean=} fullOutput Default false.
  25573. * @return {(string|Object)} Result color. If fullOutput,
  25574. * return {color: ..., leftIndex: ..., rightIndex: ..., value: ...},
  25575. */
  25576. colorUtil.lerp = function (normalizedValue, colors, fullOutput) {
  25577. if (!(colors && colors.length)
  25578. || !(normalizedValue >= 0 && normalizedValue <= 1)
  25579. ) {
  25580. return;
  25581. }
  25582. var value = normalizedValue * (colors.length - 1);
  25583. var leftIndex = Math.floor(value);
  25584. var rightIndex = Math.ceil(value);
  25585. var leftColor = colorUtil.parse(colors[leftIndex]);
  25586. var rightColor = colorUtil.parse(colors[rightIndex]);
  25587. var dv = value - leftIndex;
  25588. var color = colorUtil.stringify(
  25589. [
  25590. clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv)),
  25591. clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv)),
  25592. clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv)),
  25593. clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv))
  25594. ],
  25595. 'rgba'
  25596. );
  25597. return fullOutput
  25598. ? {
  25599. color: color,
  25600. leftIndex: leftIndex,
  25601. rightIndex: rightIndex,
  25602. value: value
  25603. }
  25604. : color;
  25605. }
  25606. /**
  25607. * @deprecated
  25608. */
  25609. colorUtil.mapToColor = colorUtil.lerp;
  25610. /**
  25611. * @name clay.core.color
  25612. * @param {string} color
  25613. * @param {number=} h 0 ~ 360, ignore when null.
  25614. * @param {number=} s 0 ~ 1, ignore when null.
  25615. * @param {number=} l 0 ~ 1, ignore when null.
  25616. * @return {string} Color string in rgba format.
  25617. */
  25618. colorUtil.modifyHSL = function (color, h, s, l) {
  25619. color = colorUtil.parse(color);
  25620. if (color) {
  25621. color = rgba2hsla(color);
  25622. h != null && (color[0] = clampCssAngle(h));
  25623. s != null && (color[1] = parseCssFloat(s));
  25624. l != null && (color[2] = parseCssFloat(l));
  25625. return colorUtil.stringify(hsla2rgba(color), 'rgba');
  25626. }
  25627. }
  25628. /**
  25629. * @param {string} color
  25630. * @param {number=} alpha 0 ~ 1
  25631. * @return {string} Color string in rgba format.
  25632. */
  25633. colorUtil.modifyAlpha = function (color, alpha) {
  25634. color = colorUtil.parse(color);
  25635. if (color && alpha != null) {
  25636. color[3] = clampCssFloat(alpha);
  25637. return colorUtil.stringify(color, 'rgba');
  25638. }
  25639. }
  25640. /**
  25641. * @param {Array.<number>} arrColor like [12,33,44,0.4]
  25642. * @param {string} type 'rgba', 'hsva', ...
  25643. * @return {string} Result color. (If input illegal, return undefined).
  25644. */
  25645. colorUtil.stringify = function (arrColor, type) {
  25646. if (!arrColor || !arrColor.length) {
  25647. return;
  25648. }
  25649. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  25650. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  25651. colorStr += ',' + arrColor[3];
  25652. }
  25653. return type + '(' + colorStr + ')';
  25654. };
  25655. /* harmony default export */ __webpack_exports__["a"] = (colorUtil);
  25656. /***/
  25657. }),
  25658. /* 114 */
  25659. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  25660. "use strict";
  25661. /**
  25662. * Simple double linked list. Compared with array, it has O(1) remove operation.
  25663. * @constructor
  25664. * @alias clay.core.LinkedList
  25665. */
  25666. var LinkedList = function () {
  25667. /**
  25668. * @type {clay.core.LinkedList.Entry}
  25669. */
  25670. this.head = null;
  25671. /**
  25672. * @type {clay.core.LinkedList.Entry}
  25673. */
  25674. this.tail = null;
  25675. this._length = 0;
  25676. };
  25677. /**
  25678. * Insert a new value at the tail
  25679. * @param {} val
  25680. * @return {clay.core.LinkedList.Entry}
  25681. */
  25682. LinkedList.prototype.insert = function (val) {
  25683. var entry = new LinkedList.Entry(val);
  25684. this.insertEntry(entry);
  25685. return entry;
  25686. };
  25687. /**
  25688. * Insert a new value at idx
  25689. * @param {number} idx
  25690. * @param {} val
  25691. * @return {clay.core.LinkedList.Entry}
  25692. */
  25693. LinkedList.prototype.insertAt = function (idx, val) {
  25694. if (idx < 0) {
  25695. return;
  25696. }
  25697. var next = this.head;
  25698. var cursor = 0;
  25699. while (next && cursor != idx) {
  25700. next = next.next;
  25701. cursor++;
  25702. }
  25703. if (next) {
  25704. var entry = new LinkedList.Entry(val);
  25705. var prev = next.prev;
  25706. if (!prev) { //next is head
  25707. this.head = entry;
  25708. }
  25709. else {
  25710. prev.next = entry;
  25711. entry.prev = prev;
  25712. }
  25713. entry.next = next;
  25714. next.prev = entry;
  25715. }
  25716. else {
  25717. this.insert(val);
  25718. }
  25719. };
  25720. LinkedList.prototype.insertBeforeEntry = function (val, next) {
  25721. var entry = new LinkedList.Entry(val);
  25722. var prev = next.prev;
  25723. if (!prev) { //next is head
  25724. this.head = entry;
  25725. }
  25726. else {
  25727. prev.next = entry;
  25728. entry.prev = prev;
  25729. }
  25730. entry.next = next;
  25731. next.prev = entry;
  25732. this._length++;
  25733. };
  25734. /**
  25735. * Insert an entry at the tail
  25736. * @param {clay.core.LinkedList.Entry} entry
  25737. */
  25738. LinkedList.prototype.insertEntry = function (entry) {
  25739. if (!this.head) {
  25740. this.head = this.tail = entry;
  25741. }
  25742. else {
  25743. this.tail.next = entry;
  25744. entry.prev = this.tail;
  25745. this.tail = entry;
  25746. }
  25747. this._length++;
  25748. };
  25749. /**
  25750. * Remove entry.
  25751. * @param {clay.core.LinkedList.Entry} entry
  25752. */
  25753. LinkedList.prototype.remove = function (entry) {
  25754. var prev = entry.prev;
  25755. var next = entry.next;
  25756. if (prev) {
  25757. prev.next = next;
  25758. }
  25759. else {
  25760. // Is head
  25761. this.head = next;
  25762. }
  25763. if (next) {
  25764. next.prev = prev;
  25765. }
  25766. else {
  25767. // Is tail
  25768. this.tail = prev;
  25769. }
  25770. entry.next = entry.prev = null;
  25771. this._length--;
  25772. };
  25773. /**
  25774. * Remove entry at index.
  25775. * @param {number} idx
  25776. * @return {}
  25777. */
  25778. LinkedList.prototype.removeAt = function (idx) {
  25779. if (idx < 0) {
  25780. return;
  25781. }
  25782. var curr = this.head;
  25783. var cursor = 0;
  25784. while (curr && cursor != idx) {
  25785. curr = curr.next;
  25786. cursor++;
  25787. }
  25788. if (curr) {
  25789. this.remove(curr);
  25790. return curr.value;
  25791. }
  25792. };
  25793. /**
  25794. * Get head value
  25795. * @return {}
  25796. */
  25797. LinkedList.prototype.getHead = function () {
  25798. if (this.head) {
  25799. return this.head.value;
  25800. }
  25801. };
  25802. /**
  25803. * Get tail value
  25804. * @return {}
  25805. */
  25806. LinkedList.prototype.getTail = function () {
  25807. if (this.tail) {
  25808. return this.tail.value;
  25809. }
  25810. };
  25811. /**
  25812. * Get value at idx
  25813. * @param {number} idx
  25814. * @return {}
  25815. */
  25816. LinkedList.prototype.getAt = function (idx) {
  25817. if (idx < 0) {
  25818. return;
  25819. }
  25820. var curr = this.head;
  25821. var cursor = 0;
  25822. while (curr && cursor != idx) {
  25823. curr = curr.next;
  25824. cursor++;
  25825. }
  25826. return curr.value;
  25827. };
  25828. /**
  25829. * @param {} value
  25830. * @return {number}
  25831. */
  25832. LinkedList.prototype.indexOf = function (value) {
  25833. var curr = this.head;
  25834. var cursor = 0;
  25835. while (curr) {
  25836. if (curr.value === value) {
  25837. return cursor;
  25838. }
  25839. curr = curr.next;
  25840. cursor++;
  25841. }
  25842. };
  25843. /**
  25844. * @return {number}
  25845. */
  25846. LinkedList.prototype.length = function () {
  25847. return this._length;
  25848. };
  25849. /**
  25850. * If list is empty
  25851. */
  25852. LinkedList.prototype.isEmpty = function () {
  25853. return this._length === 0;
  25854. };
  25855. /**
  25856. * @param {Function} cb
  25857. * @param {} context
  25858. */
  25859. LinkedList.prototype.forEach = function (cb, context) {
  25860. var curr = this.head;
  25861. var idx = 0;
  25862. var haveContext = typeof (context) != 'undefined';
  25863. while (curr) {
  25864. if (haveContext) {
  25865. cb.call(context, curr.value, idx);
  25866. }
  25867. else {
  25868. cb(curr.value, idx);
  25869. }
  25870. curr = curr.next;
  25871. idx++;
  25872. }
  25873. };
  25874. /**
  25875. * Clear the list
  25876. */
  25877. LinkedList.prototype.clear = function () {
  25878. this.tail = this.head = null;
  25879. this._length = 0;
  25880. };
  25881. /**
  25882. * @constructor
  25883. * @param {} val
  25884. */
  25885. LinkedList.Entry = function (val) {
  25886. /**
  25887. * @type {}
  25888. */
  25889. this.value = val;
  25890. /**
  25891. * @type {clay.core.LinkedList.Entry}
  25892. */
  25893. this.next = null;
  25894. /**
  25895. * @type {clay.core.LinkedList.Entry}
  25896. */
  25897. this.prev = null;
  25898. };
  25899. /* harmony default export */ __webpack_exports__["a"] = (LinkedList);
  25900. /***/
  25901. }),
  25902. /* 115 */
  25903. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  25904. "use strict";
  25905. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__GLProgram__ = __webpack_require__(116);
  25906. var loopRegex = /for\s*?\(int\s*?_idx_\s*\=\s*([\w-]+)\;\s*_idx_\s*<\s*([\w-]+);\s*_idx_\s*\+\+\s*\)\s*\{\{([\s\S]+?)(?=\}\})\}\}/g;
  25907. function unrollLoop(shaderStr, defines, lightsNumbers) {
  25908. // Loop unroll from three.js, https://github.com/mrdoob/three.js/blob/master/src/renderers/webgl/WebGLProgram.js#L175
  25909. // In some case like shadowMap in loop use 'i' to index value much slower.
  25910. // Loop use _idx_ and increased with _idx_++ will be unrolled
  25911. // Use {{ }} to match the pair so the if statement will not be affected
  25912. // Write like following
  25913. // for (int _idx_ = 0; _idx_ < 4; _idx_++) {{
  25914. // vec3 color = texture2D(textures[_idx_], uv).rgb;
  25915. // }}
  25916. function replace(match, start, end, snippet) {
  25917. var unroll = '';
  25918. // Try to treat as define
  25919. if (isNaN(start)) {
  25920. if (start in defines) {
  25921. start = defines[start];
  25922. }
  25923. else {
  25924. start = lightNumberDefines[start];
  25925. }
  25926. }
  25927. if (isNaN(end)) {
  25928. if (end in defines) {
  25929. end = defines[end];
  25930. }
  25931. else {
  25932. end = lightNumberDefines[end];
  25933. }
  25934. }
  25935. // TODO Error checking
  25936. for (var idx = parseInt(start); idx < parseInt(end); idx++) {
  25937. // PENDING Add scope?
  25938. unroll += '{'
  25939. + snippet
  25940. .replace(/float\s*\(\s*_idx_\s*\)/g, idx.toFixed(1))
  25941. .replace(/_idx_/g, idx)
  25942. + '}';
  25943. }
  25944. return unroll;
  25945. }
  25946. var lightNumberDefines = {};
  25947. for (var lightType in lightsNumbers) {
  25948. lightNumberDefines[lightType + '_COUNT'] = lightsNumbers[lightType];
  25949. }
  25950. return shaderStr.replace(loopRegex, replace);
  25951. }
  25952. function getDefineCode(defines, lightsNumbers, enabledTextures) {
  25953. var defineStr = [];
  25954. if (lightsNumbers) {
  25955. for (var lightType in lightsNumbers) {
  25956. var count = lightsNumbers[lightType];
  25957. if (count > 0) {
  25958. defineStr.push('#define ' + lightType.toUpperCase() + '_COUNT ' + count);
  25959. }
  25960. }
  25961. }
  25962. if (enabledTextures) {
  25963. for (var i = 0; i < enabledTextures.length; i++) {
  25964. var symbol = enabledTextures[i];
  25965. defineStr.push('#define ' + symbol.toUpperCase() + '_ENABLED');
  25966. }
  25967. }
  25968. // Custom Defines
  25969. for (var symbol in defines) {
  25970. var value = defines[symbol];
  25971. if (value === null) {
  25972. defineStr.push('#define ' + symbol);
  25973. }
  25974. else {
  25975. defineStr.push('#define ' + symbol + ' ' + value.toString());
  25976. }
  25977. }
  25978. return defineStr.join('\n');
  25979. }
  25980. function getExtensionCode(exts) {
  25981. // Extension declaration must before all non-preprocessor codes
  25982. // TODO vertex ? extension enum ?
  25983. var extensionStr = [];
  25984. for (var i = 0; i < exts.length; i++) {
  25985. extensionStr.push('#extension GL_' + exts[i] + ' : enable');
  25986. }
  25987. return extensionStr.join('\n');
  25988. }
  25989. function getPrecisionCode(precision) {
  25990. return ['precision', precision, 'float'].join(' ') + ';\n'
  25991. + ['precision', precision, 'int'].join(' ') + ';\n'
  25992. // depth texture may have precision problem on iOS device.
  25993. + ['precision', precision, 'sampler2D'].join(' ') + ';\n';
  25994. }
  25995. function ProgramManager(renderer) {
  25996. this._renderer = renderer;
  25997. this._cache = {};
  25998. }
  25999. ProgramManager.prototype.getProgram = function (renderable, material, scene) {
  26000. var cache = this._cache;
  26001. var isSkinnedMesh = renderable.isSkinnedMesh && renderable.isSkinnedMesh();
  26002. var key = 's' + material.shader.shaderID + 'm' + material.getProgramKey();
  26003. if (scene) {
  26004. key += 'se' + scene.getProgramKey(renderable.lightGroup);
  26005. }
  26006. if (isSkinnedMesh) {
  26007. key += ',' + renderable.joints.length;
  26008. }
  26009. var program = cache[key];
  26010. if (program) {
  26011. return program;
  26012. }
  26013. var lightsNumbers = scene ? scene.getLightsNumbers(renderable.lightGroup) : {};
  26014. var renderer = this._renderer;
  26015. var _gl = renderer.gl;
  26016. var enabledTextures = material.getEnabledTextures();
  26017. var skinDefineCode = '';
  26018. if (isSkinnedMesh) {
  26019. var skinDefines = {
  26020. SKINNING: null,
  26021. JOINT_COUNT: renderable.joints.length
  26022. };
  26023. if (renderable.joints.length > renderer.getMaxJointNumber()) {
  26024. skinDefines.USE_SKIN_MATRICES_TEXTURE = null;
  26025. }
  26026. // TODO Add skinning code?
  26027. skinDefineCode = '\n' + getDefineCode(skinDefines) + '\n';
  26028. }
  26029. // TODO Optimize key generation
  26030. // VERTEX
  26031. var vertexDefineStr = skinDefineCode + getDefineCode(material.vertexDefines, lightsNumbers, enabledTextures);
  26032. // FRAGMENT
  26033. var fragmentDefineStr = skinDefineCode + getDefineCode(material.fragmentDefines, lightsNumbers, enabledTextures);
  26034. var vertexCode = vertexDefineStr + '\n' + material.shader.vertex;
  26035. var extensions = [
  26036. 'OES_standard_derivatives',
  26037. 'EXT_shader_texture_lod'
  26038. ].filter(function (ext) {
  26039. return renderer.getGLExtension(ext) != null;
  26040. });
  26041. if (extensions.indexOf('EXT_shader_texture_lod') >= 0) {
  26042. fragmentDefineStr += '\n#define SUPPORT_TEXTURE_LOD';
  26043. }
  26044. if (extensions.indexOf('OES_standard_derivatives') >= 0) {
  26045. fragmentDefineStr += '\n#define SUPPORT_STANDARD_DERIVATIVES';
  26046. }
  26047. var fragmentCode = getExtensionCode(extensions) + '\n'
  26048. + getPrecisionCode(material.precision) + '\n'
  26049. + fragmentDefineStr + '\n'
  26050. + material.shader.fragment;
  26051. var finalVertexCode = unrollLoop(vertexCode, material.vertexDefines, lightsNumbers);
  26052. var finalFragmentCode = unrollLoop(fragmentCode, material.fragmentDefines, lightsNumbers);
  26053. var program = new __WEBPACK_IMPORTED_MODULE_0__GLProgram__["a" /* default */]();
  26054. program.uniformSemantics = material.shader.uniformSemantics;
  26055. program.attributes = material.shader.attributes;
  26056. var errorMsg = program.buildProgram(_gl, material.shader, finalVertexCode, finalFragmentCode);
  26057. program.__error = errorMsg;
  26058. cache[key] = program;
  26059. return program;
  26060. };
  26061. /* harmony default export */ __webpack_exports__["a"] = (ProgramManager);
  26062. /***/
  26063. }),
  26064. /* 116 */
  26065. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  26066. "use strict";
  26067. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__core_vendor__ = __webpack_require__(14);
  26068. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__core_Base__ = __webpack_require__(7);
  26069. var SHADER_STATE_TO_ENABLE = 1;
  26070. var SHADER_STATE_KEEP_ENABLE = 2;
  26071. var SHADER_STATE_PENDING = 3;
  26072. // Enable attribute operation is global to all programs
  26073. // Here saved the list of all enabled attribute index
  26074. // http://www.mjbshaw.com/2013/03/webgl-fixing-invalidoperation.html
  26075. var enabledAttributeList = {};
  26076. // some util functions
  26077. function addLineNumbers(string) {
  26078. var chunks = string.split('\n');
  26079. for (var i = 0, il = chunks.length; i < il; i++) {
  26080. // Chrome reports shader errors on lines
  26081. // starting counting from 1
  26082. chunks[i] = (i + 1) + ': ' + chunks[i];
  26083. }
  26084. return chunks.join('\n');
  26085. }
  26086. // Return true or error msg if error happened
  26087. function checkShaderErrorMsg(_gl, shader, shaderString) {
  26088. if (!_gl.getShaderParameter(shader, _gl.COMPILE_STATUS)) {
  26089. return [_gl.getShaderInfoLog(shader), addLineNumbers(shaderString)].join('\n');
  26090. }
  26091. }
  26092. var tmpFloat32Array16 = new __WEBPACK_IMPORTED_MODULE_0__core_vendor__["a" /* default */].Float32Array(16);
  26093. var GLProgram = __WEBPACK_IMPORTED_MODULE_1__core_Base__["a" /* default */].extend({
  26094. uniformSemantics: {},
  26095. attributes: {}
  26096. }, function () {
  26097. this._locations = {};
  26098. this._textureSlot = 0;
  26099. this._program = null;
  26100. }, {
  26101. bind: function (renderer) {
  26102. this._textureSlot = 0;
  26103. renderer.gl.useProgram(this._program);
  26104. },
  26105. hasUniform: function (symbol) {
  26106. var location = this._locations[symbol];
  26107. return location !== null && location !== undefined;
  26108. },
  26109. useTextureSlot: function (renderer, texture, slot) {
  26110. if (texture) {
  26111. renderer.gl.activeTexture(renderer.gl.TEXTURE0 + slot);
  26112. // Maybe texture is not loaded yet;
  26113. if (texture.isRenderable()) {
  26114. texture.bind(renderer);
  26115. }
  26116. else {
  26117. // Bind texture to null
  26118. texture.unbind(renderer);
  26119. }
  26120. }
  26121. },
  26122. currentTextureSlot: function () {
  26123. return this._textureSlot;
  26124. },
  26125. resetTextureSlot: function (slot) {
  26126. this._textureSlot = slot || 0;
  26127. },
  26128. takeCurrentTextureSlot: function (renderer, texture) {
  26129. var textureSlot = this._textureSlot;
  26130. this.useTextureSlot(renderer, texture, textureSlot);
  26131. this._textureSlot++;
  26132. return textureSlot;
  26133. },
  26134. setUniform: function (_gl, type, symbol, value) {
  26135. var locationMap = this._locations;
  26136. var location = locationMap[symbol];
  26137. // Uniform is not existed in the shader
  26138. if (location === null || location === undefined) {
  26139. return false;
  26140. }
  26141. switch (type) {
  26142. case 'm4':
  26143. if (!(value instanceof Float32Array)) {
  26144. // Use Float32Array is much faster than array when uniformMatrix4fv.
  26145. for (var i = 0; i < value.length; i++) {
  26146. tmpFloat32Array16[i] = value[i];
  26147. }
  26148. value = tmpFloat32Array16;
  26149. }
  26150. _gl.uniformMatrix4fv(location, false, value);
  26151. break;
  26152. case '2i':
  26153. _gl.uniform2i(location, value[0], value[1]);
  26154. break;
  26155. case '2f':
  26156. _gl.uniform2f(location, value[0], value[1]);
  26157. break;
  26158. case '3i':
  26159. _gl.uniform3i(location, value[0], value[1], value[2]);
  26160. break;
  26161. case '3f':
  26162. _gl.uniform3f(location, value[0], value[1], value[2]);
  26163. break;
  26164. case '4i':
  26165. _gl.uniform4i(location, value[0], value[1], value[2], value[3]);
  26166. break;
  26167. case '4f':
  26168. _gl.uniform4f(location, value[0], value[1], value[2], value[3]);
  26169. break;
  26170. case '1i':
  26171. _gl.uniform1i(location, value);
  26172. break;
  26173. case '1f':
  26174. _gl.uniform1f(location, value);
  26175. break;
  26176. case '1fv':
  26177. _gl.uniform1fv(location, value);
  26178. break;
  26179. case '1iv':
  26180. _gl.uniform1iv(location, value);
  26181. break;
  26182. case '2iv':
  26183. _gl.uniform2iv(location, value);
  26184. break;
  26185. case '2fv':
  26186. _gl.uniform2fv(location, value);
  26187. break;
  26188. case '3iv':
  26189. _gl.uniform3iv(location, value);
  26190. break;
  26191. case '3fv':
  26192. _gl.uniform3fv(location, value);
  26193. break;
  26194. case '4iv':
  26195. _gl.uniform4iv(location, value);
  26196. break;
  26197. case '4fv':
  26198. _gl.uniform4fv(location, value);
  26199. break;
  26200. case 'm2':
  26201. case 'm2v':
  26202. _gl.uniformMatrix2fv(location, false, value);
  26203. break;
  26204. case 'm3':
  26205. case 'm3v':
  26206. _gl.uniformMatrix3fv(location, false, value);
  26207. break;
  26208. case 'm4v':
  26209. // Raw value
  26210. if (Array.isArray(value) && Array.isArray(value[0])) {
  26211. var array = new __WEBPACK_IMPORTED_MODULE_0__core_vendor__["a" /* default */].Float32Array(value.length * 16);
  26212. var cursor = 0;
  26213. for (var i = 0; i < value.length; i++) {
  26214. var item = value[i];
  26215. for (var j = 0; j < 16; j++) {
  26216. array[cursor++] = item[j];
  26217. }
  26218. }
  26219. _gl.uniformMatrix4fv(location, false, array);
  26220. }
  26221. else { // ArrayBufferView
  26222. _gl.uniformMatrix4fv(location, false, value);
  26223. }
  26224. break;
  26225. }
  26226. return true;
  26227. },
  26228. setUniformOfSemantic: function (_gl, semantic, val) {
  26229. var semanticInfo = this.uniformSemantics[semantic];
  26230. if (semanticInfo) {
  26231. return this.setUniform(_gl, semanticInfo.type, semanticInfo.symbol, val);
  26232. }
  26233. return false;
  26234. },
  26235. // Used for creating VAO
  26236. // Enable the attributes passed in and disable the rest
  26237. // Example Usage:
  26238. // enableAttributes(renderer, ["position", "texcoords"])
  26239. enableAttributes: function (renderer, attribList, vao) {
  26240. var _gl = renderer.gl;
  26241. var program = this._program;
  26242. var locationMap = this._locations;
  26243. var enabledAttributeListInContext;
  26244. if (vao) {
  26245. enabledAttributeListInContext = vao.__enabledAttributeList;
  26246. }
  26247. else {
  26248. enabledAttributeListInContext = enabledAttributeList[renderer.__uid__];
  26249. }
  26250. if (!enabledAttributeListInContext) {
  26251. // In vertex array object context
  26252. // PENDING Each vao object needs to enable attributes again?
  26253. if (vao) {
  26254. enabledAttributeListInContext
  26255. = vao.__enabledAttributeList
  26256. = [];
  26257. }
  26258. else {
  26259. enabledAttributeListInContext
  26260. = enabledAttributeList[renderer.__uid__]
  26261. = [];
  26262. }
  26263. }
  26264. var locationList = [];
  26265. for (var i = 0; i < attribList.length; i++) {
  26266. var symbol = attribList[i];
  26267. if (!this.attributes[symbol]) {
  26268. locationList[i] = -1;
  26269. continue;
  26270. }
  26271. var location = locationMap[symbol];
  26272. if (location == null) {
  26273. location = _gl.getAttribLocation(program, symbol);
  26274. // Attrib location is a number from 0 to ...
  26275. if (location === -1) {
  26276. locationList[i] = -1;
  26277. continue;
  26278. }
  26279. locationMap[symbol] = location;
  26280. }
  26281. locationList[i] = location;
  26282. if (!enabledAttributeListInContext[location]) {
  26283. enabledAttributeListInContext[location] = SHADER_STATE_TO_ENABLE;
  26284. }
  26285. else {
  26286. enabledAttributeListInContext[location] = SHADER_STATE_KEEP_ENABLE;
  26287. }
  26288. }
  26289. for (var i = 0; i < enabledAttributeListInContext.length; i++) {
  26290. switch (enabledAttributeListInContext[i]) {
  26291. case SHADER_STATE_TO_ENABLE:
  26292. _gl.enableVertexAttribArray(i);
  26293. enabledAttributeListInContext[i] = SHADER_STATE_PENDING;
  26294. break;
  26295. case SHADER_STATE_KEEP_ENABLE:
  26296. enabledAttributeListInContext[i] = SHADER_STATE_PENDING;
  26297. break;
  26298. // Expired
  26299. case SHADER_STATE_PENDING:
  26300. _gl.disableVertexAttribArray(i);
  26301. enabledAttributeListInContext[i] = 0;
  26302. break;
  26303. }
  26304. }
  26305. return locationList;
  26306. },
  26307. buildProgram: function (_gl, shader, vertexShaderCode, fragmentShaderCode) {
  26308. var vertexShader = _gl.createShader(_gl.VERTEX_SHADER);
  26309. var program = _gl.createProgram();
  26310. _gl.shaderSource(vertexShader, vertexShaderCode);
  26311. _gl.compileShader(vertexShader);
  26312. var fragmentShader = _gl.createShader(_gl.FRAGMENT_SHADER);
  26313. _gl.shaderSource(fragmentShader, fragmentShaderCode);
  26314. _gl.compileShader(fragmentShader);
  26315. var msg = checkShaderErrorMsg(_gl, vertexShader, vertexShaderCode);
  26316. if (msg) {
  26317. return msg;
  26318. }
  26319. msg = checkShaderErrorMsg(_gl, fragmentShader, fragmentShaderCode);
  26320. if (msg) {
  26321. return msg;
  26322. }
  26323. _gl.attachShader(program, vertexShader);
  26324. _gl.attachShader(program, fragmentShader);
  26325. // Force the position bind to location 0;
  26326. if (shader.attributeSemantics['POSITION']) {
  26327. _gl.bindAttribLocation(program, 0, shader.attributeSemantics['POSITION'].symbol);
  26328. }
  26329. else {
  26330. // Else choose an attribute and bind to location 0;
  26331. var keys = Object.keys(this.attributes);
  26332. _gl.bindAttribLocation(program, 0, keys[0]);
  26333. }
  26334. _gl.linkProgram(program);
  26335. if (!_gl.getProgramParameter(program, _gl.LINK_STATUS)) {
  26336. return 'Could not link program\n' + _gl.getProgramInfoLog(program);
  26337. }
  26338. // Cache uniform locations
  26339. for (var i = 0; i < shader.uniforms.length; i++) {
  26340. var uniformSymbol = shader.uniforms[i];
  26341. this._locations[uniformSymbol] = _gl.getUniformLocation(program, uniformSymbol);
  26342. }
  26343. _gl.deleteShader(vertexShader);
  26344. _gl.deleteShader(fragmentShader);
  26345. this._program = program;
  26346. // Save code.
  26347. this.vertexCode = vertexShaderCode;
  26348. this.fragmentCode = fragmentShaderCode;
  26349. }
  26350. });
  26351. /* harmony default export */ __webpack_exports__["a"] = (GLProgram);
  26352. /***/
  26353. }),
  26354. /* 117 */
  26355. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  26356. "use strict";
  26357. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__core_Base__ = __webpack_require__(7);
  26358. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__math_Ray__ = __webpack_require__(54);
  26359. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__math_Vector2__ = __webpack_require__(26);
  26360. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__math_Vector3__ = __webpack_require__(3);
  26361. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__math_Matrix4__ = __webpack_require__(9);
  26362. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__Renderable__ = __webpack_require__(72);
  26363. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__core_glenum__ = __webpack_require__(11);
  26364. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__glmatrix_vec3__ = __webpack_require__(12);
  26365. /**
  26366. * @constructor clay.picking.RayPicking
  26367. * @extends clay.core.Base
  26368. */
  26369. var RayPicking = __WEBPACK_IMPORTED_MODULE_0__core_Base__["a" /* default */].extend(/** @lends clay.picking.RayPicking# */{
  26370. /**
  26371. * Target scene
  26372. * @type {clay.Scene}
  26373. */
  26374. scene: null,
  26375. /**
  26376. * Target camera
  26377. * @type {clay.Camera}
  26378. */
  26379. camera: null,
  26380. /**
  26381. * Target renderer
  26382. * @type {clay.Renderer}
  26383. */
  26384. renderer: null
  26385. }, function () {
  26386. this._ray = new __WEBPACK_IMPORTED_MODULE_1__math_Ray__["a" /* default */]();
  26387. this._ndc = new __WEBPACK_IMPORTED_MODULE_2__math_Vector2__["a" /* default */]();
  26388. },
  26389. /** @lends clay.picking.RayPicking.prototype */
  26390. {
  26391. /**
  26392. * Pick the nearest intersection object in the scene
  26393. * @param {number} x Mouse position x
  26394. * @param {number} y Mouse position y
  26395. * @param {boolean} [forcePickAll=false] ignore ignorePicking
  26396. * @return {clay.picking.RayPicking~Intersection}
  26397. */
  26398. pick: function (x, y, forcePickAll) {
  26399. var out = this.pickAll(x, y, [], forcePickAll);
  26400. return out[0] || null;
  26401. },
  26402. /**
  26403. * Pick all intersection objects, wich will be sorted from near to far
  26404. * @param {number} x Mouse position x
  26405. * @param {number} y Mouse position y
  26406. * @param {Array} [output]
  26407. * @param {boolean} [forcePickAll=false] ignore ignorePicking
  26408. * @return {Array.<clay.picking.RayPicking~Intersection>}
  26409. */
  26410. pickAll: function (x, y, output, forcePickAll) {
  26411. this.renderer.screenToNDC(x, y, this._ndc);
  26412. this.camera.castRay(this._ndc, this._ray);
  26413. output = output || [];
  26414. this._intersectNode(this.scene, output, forcePickAll || false);
  26415. output.sort(this._intersectionCompareFunc);
  26416. return output;
  26417. },
  26418. _intersectNode: function (node, out, forcePickAll) {
  26419. if ((node instanceof __WEBPACK_IMPORTED_MODULE_5__Renderable__["a" /* default */]) && node.isRenderable()) {
  26420. if ((!node.ignorePicking || forcePickAll)
  26421. && (
  26422. // Only triangle mesh support ray picking
  26423. (node.mode === __WEBPACK_IMPORTED_MODULE_6__core_glenum__["a" /* default */].TRIANGLES && node.geometry.isUseIndices())
  26424. // Or if geometry has it's own pickByRay, pick, implementation
  26425. || node.geometry.pickByRay
  26426. || node.geometry.pick
  26427. )
  26428. ) {
  26429. this._intersectRenderable(node, out);
  26430. }
  26431. }
  26432. for (var i = 0; i < node._children.length; i++) {
  26433. this._intersectNode(node._children[i], out, forcePickAll);
  26434. }
  26435. },
  26436. _intersectRenderable: (function () {
  26437. var v1 = new __WEBPACK_IMPORTED_MODULE_3__math_Vector3__["a" /* default */]();
  26438. var v2 = new __WEBPACK_IMPORTED_MODULE_3__math_Vector3__["a" /* default */]();
  26439. var v3 = new __WEBPACK_IMPORTED_MODULE_3__math_Vector3__["a" /* default */]();
  26440. var ray = new __WEBPACK_IMPORTED_MODULE_1__math_Ray__["a" /* default */]();
  26441. var worldInverse = new __WEBPACK_IMPORTED_MODULE_4__math_Matrix4__["a" /* default */]();
  26442. return function (renderable, out) {
  26443. var isSkinnedMesh = renderable.isSkinnedMesh();
  26444. ray.copy(this._ray);
  26445. __WEBPACK_IMPORTED_MODULE_4__math_Matrix4__["a" /* default */].invert(worldInverse, renderable.worldTransform);
  26446. // Skinned mesh will ignore the world transform.
  26447. if (!isSkinnedMesh) {
  26448. ray.applyTransform(worldInverse);
  26449. }
  26450. var geometry = renderable.geometry;
  26451. var bbox = isSkinnedMesh ? renderable.skeleton.boundingBox : geometry.boundingBox;
  26452. if (bbox && !ray.intersectBoundingBox(bbox)) {
  26453. return;
  26454. }
  26455. // Use user defined picking algorithm
  26456. if (geometry.pick) {
  26457. geometry.pick(
  26458. this._ndc.x, this._ndc.y,
  26459. this.renderer,
  26460. this.camera,
  26461. renderable, out
  26462. );
  26463. return;
  26464. }
  26465. // Use user defined ray picking algorithm
  26466. else if (geometry.pickByRay) {
  26467. geometry.pickByRay(ray, renderable, out);
  26468. return;
  26469. }
  26470. var cullBack = (renderable.cullFace === __WEBPACK_IMPORTED_MODULE_6__core_glenum__["a" /* default */].BACK && renderable.frontFace === __WEBPACK_IMPORTED_MODULE_6__core_glenum__["a" /* default */].CCW)
  26471. || (renderable.cullFace === __WEBPACK_IMPORTED_MODULE_6__core_glenum__["a" /* default */].FRONT && renderable.frontFace === __WEBPACK_IMPORTED_MODULE_6__core_glenum__["a" /* default */].CW);
  26472. var point;
  26473. var indices = geometry.indices;
  26474. var positionAttr = geometry.attributes.position;
  26475. var weightAttr = geometry.attributes.weight;
  26476. var jointAttr = geometry.attributes.joint;
  26477. var skinMatricesArray;
  26478. var skinMatrices = [];
  26479. // Check if valid.
  26480. if (!positionAttr || !positionAttr.value || !indices) {
  26481. return;
  26482. }
  26483. if (isSkinnedMesh) {
  26484. skinMatricesArray = renderable.skeleton.getSubSkinMatrices(renderable.__uid__, renderable.joints);
  26485. for (var i = 0; i < renderable.joints.length; i++) {
  26486. skinMatrices[i] = skinMatrices[i] || [];
  26487. for (var k = 0; k < 16; k++) {
  26488. skinMatrices[i][k] = skinMatricesArray[i * 16 + k];
  26489. }
  26490. }
  26491. var pos = [];
  26492. var weight = [];
  26493. var joint = [];
  26494. var skinnedPos = [];
  26495. var tmp = [];
  26496. var skinnedPositionAttr = geometry.attributes.skinnedPosition;
  26497. if (!skinnedPositionAttr || !skinnedPositionAttr.value) {
  26498. geometry.createAttribute('skinnedPosition', 'f', 3);
  26499. skinnedPositionAttr = geometry.attributes.skinnedPosition;
  26500. skinnedPositionAttr.init(geometry.vertexCount);
  26501. }
  26502. for (var i = 0; i < geometry.vertexCount; i++) {
  26503. positionAttr.get(i, pos);
  26504. weightAttr.get(i, weight);
  26505. jointAttr.get(i, joint);
  26506. weight[3] = 1 - weight[0] - weight[1] - weight[2];
  26507. __WEBPACK_IMPORTED_MODULE_7__glmatrix_vec3__["a" /* default */].set(skinnedPos, 0, 0, 0);
  26508. for (var k = 0; k < 4; k++) {
  26509. if (joint[k] >= 0 && weight[k] > 1e-4) {
  26510. __WEBPACK_IMPORTED_MODULE_7__glmatrix_vec3__["a" /* default */].transformMat4(tmp, pos, skinMatrices[joint[k]]);
  26511. __WEBPACK_IMPORTED_MODULE_7__glmatrix_vec3__["a" /* default */].scaleAndAdd(skinnedPos, skinnedPos, tmp, weight[k]);
  26512. }
  26513. }
  26514. skinnedPositionAttr.set(i, skinnedPos);
  26515. }
  26516. }
  26517. for (var i = 0; i < indices.length; i += 3) {
  26518. var i1 = indices[i];
  26519. var i2 = indices[i + 1];
  26520. var i3 = indices[i + 2];
  26521. var finalPosAttr = isSkinnedMesh
  26522. ? geometry.attributes.skinnedPosition
  26523. : positionAttr;
  26524. finalPosAttr.get(i1, v1.array);
  26525. finalPosAttr.get(i2, v2.array);
  26526. finalPosAttr.get(i3, v3.array);
  26527. if (cullBack) {
  26528. point = ray.intersectTriangle(v1, v2, v3, renderable.culling);
  26529. }
  26530. else {
  26531. point = ray.intersectTriangle(v1, v3, v2, renderable.culling);
  26532. }
  26533. if (point) {
  26534. var pointW = new __WEBPACK_IMPORTED_MODULE_3__math_Vector3__["a" /* default */]();
  26535. if (!isSkinnedMesh) {
  26536. __WEBPACK_IMPORTED_MODULE_3__math_Vector3__["a" /* default */].transformMat4(pointW, point, renderable.worldTransform);
  26537. }
  26538. else {
  26539. // TODO point maybe not right.
  26540. __WEBPACK_IMPORTED_MODULE_3__math_Vector3__["a" /* default */].copy(pointW, point);
  26541. }
  26542. out.push(new RayPicking.Intersection(
  26543. point, pointW, renderable, [i1, i2, i3], i / 3,
  26544. __WEBPACK_IMPORTED_MODULE_3__math_Vector3__["a" /* default */].dist(pointW, this._ray.origin)
  26545. ));
  26546. }
  26547. }
  26548. };
  26549. })(),
  26550. _intersectionCompareFunc: function (a, b) {
  26551. return a.distance - b.distance;
  26552. }
  26553. });
  26554. /**
  26555. * @constructor clay.picking.RayPicking~Intersection
  26556. * @param {clay.Vector3} point
  26557. * @param {clay.Vector3} pointWorld
  26558. * @param {clay.Node} target
  26559. * @param {Array.<number>} triangle
  26560. * @param {number} triangleIndex
  26561. * @param {number} distance
  26562. */
  26563. RayPicking.Intersection = function (point, pointWorld, target, triangle, triangleIndex, distance) {
  26564. /**
  26565. * Intersection point in local transform coordinates
  26566. * @type {clay.Vector3}
  26567. */
  26568. this.point = point;
  26569. /**
  26570. * Intersection point in world transform coordinates
  26571. * @type {clay.Vector3}
  26572. */
  26573. this.pointWorld = pointWorld;
  26574. /**
  26575. * Intersection scene node
  26576. * @type {clay.Node}
  26577. */
  26578. this.target = target;
  26579. /**
  26580. * Intersection triangle, which is an array of vertex index
  26581. * @type {Array.<number>}
  26582. */
  26583. this.triangle = triangle;
  26584. /**
  26585. * Index of intersection triangle.
  26586. */
  26587. this.triangleIndex = triangleIndex;
  26588. /**
  26589. * Distance from intersection point to ray origin
  26590. * @type {number}
  26591. */
  26592. this.distance = distance;
  26593. };
  26594. /* harmony default export */ __webpack_exports__["a"] = (RayPicking);
  26595. /***/
  26596. }),
  26597. /* 118 */
  26598. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  26599. "use strict";
  26600. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__core_Base__ = __webpack_require__(7);
  26601. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__core_glenum__ = __webpack_require__(11);
  26602. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__core_Cache__ = __webpack_require__(57);
  26603. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__core_vendor__ = __webpack_require__(14);
  26604. function getArrayCtorByType(type) {
  26605. return ({
  26606. 'byte': __WEBPACK_IMPORTED_MODULE_3__core_vendor__["a" /* default */].Int8Array,
  26607. 'ubyte': __WEBPACK_IMPORTED_MODULE_3__core_vendor__["a" /* default */].Uint8Array,
  26608. 'short': __WEBPACK_IMPORTED_MODULE_3__core_vendor__["a" /* default */].Int16Array,
  26609. 'ushort': __WEBPACK_IMPORTED_MODULE_3__core_vendor__["a" /* default */].Uint16Array
  26610. })[type] || __WEBPACK_IMPORTED_MODULE_3__core_vendor__["a" /* default */].Float32Array;
  26611. }
  26612. function makeAttrKey(attrName) {
  26613. return 'attr_' + attrName;
  26614. }
  26615. /**
  26616. * GeometryBase attribute
  26617. * @alias clay.GeometryBase.Attribute
  26618. * @constructor
  26619. */
  26620. function Attribute(name, type, size, semantic) {
  26621. /**
  26622. * Attribute name
  26623. * @type {string}
  26624. */
  26625. this.name = name;
  26626. /**
  26627. * Attribute type
  26628. * Possible values:
  26629. * + `'byte'`
  26630. * + `'ubyte'`
  26631. * + `'short'`
  26632. * + `'ushort'`
  26633. * + `'float'` Most commonly used.
  26634. * @type {string}
  26635. */
  26636. this.type = type;
  26637. /**
  26638. * Size of attribute component. 1 - 4.
  26639. * @type {number}
  26640. */
  26641. this.size = size;
  26642. /**
  26643. * Semantic of this attribute.
  26644. * Possible values:
  26645. * + `'POSITION'`
  26646. * + `'NORMAL'`
  26647. * + `'BINORMAL'`
  26648. * + `'TANGENT'`
  26649. * + `'TEXCOORD'`
  26650. * + `'TEXCOORD_0'`
  26651. * + `'TEXCOORD_1'`
  26652. * + `'COLOR'`
  26653. * + `'JOINT'`
  26654. * + `'WEIGHT'`
  26655. *
  26656. * In shader, attribute with same semantic will be automatically mapped. For example:
  26657. * ```glsl
  26658. * attribute vec3 pos: POSITION
  26659. * ```
  26660. * will use the attribute value with semantic POSITION in geometry, no matter what name it used.
  26661. * @type {string}
  26662. */
  26663. this.semantic = semantic || '';
  26664. /**
  26665. * Value of the attribute.
  26666. * @type {TypedArray}
  26667. */
  26668. this.value = null;
  26669. // Init getter setter
  26670. switch (size) {
  26671. case 1:
  26672. this.get = function (idx) {
  26673. return this.value[idx];
  26674. };
  26675. this.set = function (idx, value) {
  26676. this.value[idx] = value;
  26677. };
  26678. // Copy from source to target
  26679. this.copy = function (target, source) {
  26680. this.value[target] = this.value[target];
  26681. };
  26682. break;
  26683. case 2:
  26684. this.get = function (idx, out) {
  26685. var arr = this.value;
  26686. out[0] = arr[idx * 2];
  26687. out[1] = arr[idx * 2 + 1];
  26688. return out;
  26689. };
  26690. this.set = function (idx, val) {
  26691. var arr = this.value;
  26692. arr[idx * 2] = val[0];
  26693. arr[idx * 2 + 1] = val[1];
  26694. };
  26695. this.copy = function (target, source) {
  26696. var arr = this.value;
  26697. source *= 2;
  26698. target *= 2;
  26699. arr[target] = arr[source];
  26700. arr[target + 1] = arr[source + 1];
  26701. };
  26702. break;
  26703. case 3:
  26704. this.get = function (idx, out) {
  26705. var idx3 = idx * 3;
  26706. var arr = this.value;
  26707. out[0] = arr[idx3];
  26708. out[1] = arr[idx3 + 1];
  26709. out[2] = arr[idx3 + 2];
  26710. return out;
  26711. };
  26712. this.set = function (idx, val) {
  26713. var idx3 = idx * 3;
  26714. var arr = this.value;
  26715. arr[idx3] = val[0];
  26716. arr[idx3 + 1] = val[1];
  26717. arr[idx3 + 2] = val[2];
  26718. };
  26719. this.copy = function (target, source) {
  26720. var arr = this.value;
  26721. source *= 3;
  26722. target *= 3;
  26723. arr[target] = arr[source];
  26724. arr[target + 1] = arr[source + 1];
  26725. arr[target + 2] = arr[source + 2];
  26726. };
  26727. break;
  26728. case 4:
  26729. this.get = function (idx, out) {
  26730. var arr = this.value;
  26731. var idx4 = idx * 4;
  26732. out[0] = arr[idx4];
  26733. out[1] = arr[idx4 + 1];
  26734. out[2] = arr[idx4 + 2];
  26735. out[3] = arr[idx4 + 3];
  26736. return out;
  26737. };
  26738. this.set = function (idx, val) {
  26739. var arr = this.value;
  26740. var idx4 = idx * 4;
  26741. arr[idx4] = val[0];
  26742. arr[idx4 + 1] = val[1];
  26743. arr[idx4 + 2] = val[2];
  26744. arr[idx4 + 3] = val[3];
  26745. };
  26746. this.copy = function (target, source) {
  26747. var arr = this.value;
  26748. source *= 4;
  26749. target *= 4;
  26750. // copyWithin is extremely slow
  26751. arr[target] = arr[source];
  26752. arr[target + 1] = arr[source + 1];
  26753. arr[target + 2] = arr[source + 2];
  26754. arr[target + 3] = arr[source + 3];
  26755. };
  26756. }
  26757. }
  26758. /**
  26759. * Set item value at give index. Second parameter val is number if size is 1
  26760. * @function
  26761. * @name clay.GeometryBase.Attribute#set
  26762. * @param {number} idx
  26763. * @param {number[]|number} val
  26764. * @example
  26765. * geometry.getAttribute('position').set(0, [1, 1, 1]);
  26766. */
  26767. /**
  26768. * Get item value at give index. Second parameter out is no need if size is 1
  26769. * @function
  26770. * @name clay.GeometryBase.Attribute#set
  26771. * @param {number} idx
  26772. * @param {number[]} [out]
  26773. * @example
  26774. * geometry.getAttribute('position').get(0, out);
  26775. */
  26776. /**
  26777. * Initialize attribute with given vertex count
  26778. * @param {number} nVertex
  26779. */
  26780. Attribute.prototype.init = function (nVertex) {
  26781. if (!this.value || this.value.length != nVertex * this.size) {
  26782. var ArrayConstructor = getArrayCtorByType(this.type);
  26783. this.value = new ArrayConstructor(nVertex * this.size);
  26784. }
  26785. };
  26786. /**
  26787. * Initialize attribute with given array. Which can be 1 dimensional or 2 dimensional
  26788. * @param {Array} array
  26789. * @example
  26790. * geometry.getAttribute('position').fromArray(
  26791. * [-1, 0, 0, 1, 0, 0, 0, 1, 0]
  26792. * );
  26793. * geometry.getAttribute('position').fromArray(
  26794. * [ [-1, 0, 0], [1, 0, 0], [0, 1, 0] ]
  26795. * );
  26796. */
  26797. Attribute.prototype.fromArray = function (array) {
  26798. var ArrayConstructor = getArrayCtorByType(this.type);
  26799. var value;
  26800. // Convert 2d array to flat
  26801. if (array[0] && (array[0].length)) {
  26802. var n = 0;
  26803. var size = this.size;
  26804. value = new ArrayConstructor(array.length * size);
  26805. for (var i = 0; i < array.length; i++) {
  26806. for (var j = 0; j < size; j++) {
  26807. value[n++] = array[i][j];
  26808. }
  26809. }
  26810. }
  26811. else {
  26812. value = new ArrayConstructor(array);
  26813. }
  26814. this.value = value;
  26815. };
  26816. Attribute.prototype.clone = function (copyValue) {
  26817. var ret = new Attribute(this.name, this.type, this.size, this.semantic);
  26818. // FIXME
  26819. if (copyValue) {
  26820. console.warn('todo');
  26821. }
  26822. return ret;
  26823. };
  26824. function AttributeBuffer(name, type, buffer, size, semantic) {
  26825. this.name = name;
  26826. this.type = type;
  26827. this.buffer = buffer;
  26828. this.size = size;
  26829. this.semantic = semantic;
  26830. // To be set in mesh
  26831. // symbol in the shader
  26832. this.symbol = '';
  26833. // Needs remove flag
  26834. this.needsRemove = false;
  26835. }
  26836. function IndicesBuffer(buffer) {
  26837. this.buffer = buffer;
  26838. this.count = 0;
  26839. }
  26840. /**
  26841. * Base of all geometry. Use {@link clay.Geometry} for common 3D usage.
  26842. * @constructor clay.GeometryBase
  26843. * @extends clay.core.Base
  26844. */
  26845. var GeometryBase = __WEBPACK_IMPORTED_MODULE_0__core_Base__["a" /* default */].extend(function () {
  26846. return /** @lends clay.GeometryBase# */ {
  26847. /**
  26848. * Attributes of geometry.
  26849. * @type {Object.<string, clay.GeometryBase.Attribute>}
  26850. */
  26851. attributes: {},
  26852. /**
  26853. * Indices of geometry.
  26854. * @type {Uint16Array|Uint32Array}
  26855. */
  26856. indices: null,
  26857. /**
  26858. * Is vertices data dynamically updated.
  26859. * Attributes value can't be changed after first render if dyanmic is false.
  26860. * @type {boolean}
  26861. */
  26862. dynamic: true,
  26863. _enabledAttributes: null,
  26864. // PENDING
  26865. // Init it here to avoid deoptimization when it's assigned in application dynamically
  26866. __used: 0
  26867. };
  26868. }, function () {
  26869. // Use cache
  26870. this._cache = new __WEBPACK_IMPORTED_MODULE_2__core_Cache__["a" /* default */]();
  26871. this._attributeList = Object.keys(this.attributes);
  26872. this.__vaoCache = {};
  26873. },
  26874. /** @lends clay.GeometryBase.prototype */
  26875. {
  26876. /**
  26877. * Main attribute will be used to count vertex number
  26878. * @type {string}
  26879. */
  26880. mainAttribute: '',
  26881. /**
  26882. * User defined picking algorithm instead of default
  26883. * triangle ray intersection
  26884. * x, y are NDC.
  26885. * ```typescript
  26886. * (x, y, renderer, camera, renderable, out) => boolean
  26887. * ```
  26888. * @type {?Function}
  26889. */
  26890. pick: null,
  26891. /**
  26892. * User defined ray picking algorithm instead of default
  26893. * triangle ray intersection
  26894. * ```typescript
  26895. * (ray: clay.Ray, renderable: clay.Renderable, out: Array) => boolean
  26896. * ```
  26897. * @type {?Function}
  26898. */
  26899. pickByRay: null,
  26900. /**
  26901. * Mark attributes and indices in geometry needs to update.
  26902. * Usually called after you change the data in attributes.
  26903. */
  26904. dirty: function () {
  26905. var enabledAttributes = this.getEnabledAttributes();
  26906. for (var i = 0; i < enabledAttributes.length; i++) {
  26907. this.dirtyAttribute(enabledAttributes[i]);
  26908. }
  26909. this.dirtyIndices();
  26910. this._enabledAttributes = null;
  26911. this._cache.dirty('any');
  26912. },
  26913. /**
  26914. * Mark the indices needs to update.
  26915. */
  26916. dirtyIndices: function () {
  26917. this._cache.dirtyAll('indices');
  26918. },
  26919. /**
  26920. * Mark the attributes needs to update.
  26921. * @param {string} [attrName]
  26922. */
  26923. dirtyAttribute: function (attrName) {
  26924. this._cache.dirtyAll(makeAttrKey(attrName));
  26925. this._cache.dirtyAll('attributes');
  26926. },
  26927. /**
  26928. * Get indices of triangle at given index.
  26929. * @param {number} idx
  26930. * @param {Array.<number>} out
  26931. * @return {Array.<number>}
  26932. */
  26933. getTriangleIndices: function (idx, out) {
  26934. if (idx < this.triangleCount && idx >= 0) {
  26935. if (!out) {
  26936. out = [];
  26937. }
  26938. var indices = this.indices;
  26939. out[0] = indices[idx * 3];
  26940. out[1] = indices[idx * 3 + 1];
  26941. out[2] = indices[idx * 3 + 2];
  26942. return out;
  26943. }
  26944. },
  26945. /**
  26946. * Set indices of triangle at given index.
  26947. * @param {number} idx
  26948. * @param {Array.<number>} arr
  26949. */
  26950. setTriangleIndices: function (idx, arr) {
  26951. var indices = this.indices;
  26952. indices[idx * 3] = arr[0];
  26953. indices[idx * 3 + 1] = arr[1];
  26954. indices[idx * 3 + 2] = arr[2];
  26955. },
  26956. isUseIndices: function () {
  26957. return !!this.indices;
  26958. },
  26959. /**
  26960. * Initialize indices from an array.
  26961. * @param {Array} array
  26962. */
  26963. initIndicesFromArray: function (array) {
  26964. var value;
  26965. var ArrayConstructor = this.vertexCount > 0xffff
  26966. ? __WEBPACK_IMPORTED_MODULE_3__core_vendor__["a" /* default */].Uint32Array : __WEBPACK_IMPORTED_MODULE_3__core_vendor__["a" /* default */].Uint16Array;
  26967. // Convert 2d array to flat
  26968. if (array[0] && (array[0].length)) {
  26969. var n = 0;
  26970. var size = 3;
  26971. value = new ArrayConstructor(array.length * size);
  26972. for (var i = 0; i < array.length; i++) {
  26973. for (var j = 0; j < size; j++) {
  26974. value[n++] = array[i][j];
  26975. }
  26976. }
  26977. }
  26978. else {
  26979. value = new ArrayConstructor(array);
  26980. }
  26981. this.indices = value;
  26982. },
  26983. /**
  26984. * Create a new attribute
  26985. * @param {string} name
  26986. * @param {string} type
  26987. * @param {number} size
  26988. * @param {string} [semantic]
  26989. */
  26990. createAttribute: function (name, type, size, semantic) {
  26991. var attrib = new Attribute(name, type, size, semantic);
  26992. if (this.attributes[name]) {
  26993. this.removeAttribute(name);
  26994. }
  26995. this.attributes[name] = attrib;
  26996. this._attributeList.push(name);
  26997. return attrib;
  26998. },
  26999. /**
  27000. * Remove attribute
  27001. * @param {string} name
  27002. */
  27003. removeAttribute: function (name) {
  27004. var attributeList = this._attributeList;
  27005. var idx = attributeList.indexOf(name);
  27006. if (idx >= 0) {
  27007. attributeList.splice(idx, 1);
  27008. delete this.attributes[name];
  27009. return true;
  27010. }
  27011. return false;
  27012. },
  27013. /**
  27014. * Get attribute
  27015. * @param {string} name
  27016. * @return {clay.GeometryBase.Attribute}
  27017. */
  27018. getAttribute: function (name) {
  27019. return this.attributes[name];
  27020. },
  27021. /**
  27022. * Get enabled attributes name list
  27023. * Attribute which has the same vertex number with position is treated as a enabled attribute
  27024. * @return {string[]}
  27025. */
  27026. getEnabledAttributes: function () {
  27027. var enabledAttributes = this._enabledAttributes;
  27028. var attributeList = this._attributeList;
  27029. // Cache
  27030. if (enabledAttributes) {
  27031. return enabledAttributes;
  27032. }
  27033. var result = [];
  27034. var nVertex = this.vertexCount;
  27035. for (var i = 0; i < attributeList.length; i++) {
  27036. var name = attributeList[i];
  27037. var attrib = this.attributes[name];
  27038. if (attrib.value) {
  27039. if (attrib.value.length === nVertex * attrib.size) {
  27040. result.push(name);
  27041. }
  27042. }
  27043. }
  27044. this._enabledAttributes = result;
  27045. return result;
  27046. },
  27047. getBufferChunks: function (renderer) {
  27048. var cache = this._cache;
  27049. cache.use(renderer.__uid__);
  27050. var isAttributesDirty = cache.isDirty('attributes');
  27051. var isIndicesDirty = cache.isDirty('indices');
  27052. if (isAttributesDirty || isIndicesDirty) {
  27053. this._updateBuffer(renderer.gl, isAttributesDirty, isIndicesDirty);
  27054. var enabledAttributes = this.getEnabledAttributes();
  27055. for (var i = 0; i < enabledAttributes.length; i++) {
  27056. cache.fresh(makeAttrKey(enabledAttributes[i]));
  27057. }
  27058. cache.fresh('attributes');
  27059. cache.fresh('indices');
  27060. }
  27061. cache.fresh('any');
  27062. return cache.get('chunks');
  27063. },
  27064. _updateBuffer: function (_gl, isAttributesDirty, isIndicesDirty) {
  27065. var cache = this._cache;
  27066. var chunks = cache.get('chunks');
  27067. var firstUpdate = false;
  27068. if (!chunks) {
  27069. chunks = [];
  27070. // Intialize
  27071. chunks[0] = {
  27072. attributeBuffers: [],
  27073. indicesBuffer: null
  27074. };
  27075. cache.put('chunks', chunks);
  27076. firstUpdate = true;
  27077. }
  27078. var chunk = chunks[0];
  27079. var attributeBuffers = chunk.attributeBuffers;
  27080. var indicesBuffer = chunk.indicesBuffer;
  27081. if (isAttributesDirty || firstUpdate) {
  27082. var attributeList = this.getEnabledAttributes();
  27083. var attributeBufferMap = {};
  27084. if (!firstUpdate) {
  27085. for (var i = 0; i < attributeBuffers.length; i++) {
  27086. attributeBufferMap[attributeBuffers[i].name] = attributeBuffers[i];
  27087. }
  27088. }
  27089. // FIXME If some attributes removed
  27090. for (var k = 0; k < attributeList.length; k++) {
  27091. var name = attributeList[k];
  27092. var attribute = this.attributes[name];
  27093. var bufferInfo;
  27094. if (!firstUpdate) {
  27095. bufferInfo = attributeBufferMap[name];
  27096. }
  27097. var buffer;
  27098. if (bufferInfo) {
  27099. buffer = bufferInfo.buffer;
  27100. }
  27101. else {
  27102. buffer = _gl.createBuffer();
  27103. }
  27104. if (cache.isDirty(makeAttrKey(name))) {
  27105. // Only update when they are dirty.
  27106. // TODO: Use BufferSubData?
  27107. _gl.bindBuffer(_gl.ARRAY_BUFFER, buffer);
  27108. _gl.bufferData(_gl.ARRAY_BUFFER, attribute.value, this.dynamic ? __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].DYNAMIC_DRAW : __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].STATIC_DRAW);
  27109. }
  27110. attributeBuffers[k] = new AttributeBuffer(name, attribute.type, buffer, attribute.size, attribute.semantic);
  27111. }
  27112. // Remove unused attributes buffers.
  27113. // PENDING
  27114. for (var i = k; i < attributeBuffers.length; i++) {
  27115. _gl.deleteBuffer(attributeBuffers[i].buffer);
  27116. }
  27117. attributeBuffers.length = k;
  27118. }
  27119. if (this.isUseIndices() && (isIndicesDirty || firstUpdate)) {
  27120. if (!indicesBuffer) {
  27121. indicesBuffer = new IndicesBuffer(_gl.createBuffer());
  27122. chunk.indicesBuffer = indicesBuffer;
  27123. }
  27124. indicesBuffer.count = this.indices.length;
  27125. _gl.bindBuffer(_gl.ELEMENT_ARRAY_BUFFER, indicesBuffer.buffer);
  27126. _gl.bufferData(_gl.ELEMENT_ARRAY_BUFFER, this.indices, this.dynamic ? __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].DYNAMIC_DRAW : __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].STATIC_DRAW);
  27127. }
  27128. },
  27129. /**
  27130. * Dispose geometry data in GL context.
  27131. * @param {clay.Renderer} renderer
  27132. */
  27133. dispose: function (renderer) {
  27134. var cache = this._cache;
  27135. cache.use(renderer.__uid__);
  27136. var chunks = cache.get('chunks');
  27137. if (chunks) {
  27138. for (var c = 0; c < chunks.length; c++) {
  27139. var chunk = chunks[c];
  27140. for (var k = 0; k < chunk.attributeBuffers.length; k++) {
  27141. var attribs = chunk.attributeBuffers[k];
  27142. renderer.gl.deleteBuffer(attribs.buffer);
  27143. }
  27144. if (chunk.indicesBuffer) {
  27145. renderer.gl.deleteBuffer(chunk.indicesBuffer.buffer);
  27146. }
  27147. }
  27148. }
  27149. if (this.__vaoCache) {
  27150. var vaoExt = renderer.getGLExtension('OES_vertex_array_object');
  27151. for (var id in this.__vaoCache) {
  27152. var vao = this.__vaoCache[id].vao;
  27153. if (vao) {
  27154. vaoExt.deleteVertexArrayOES(vao);
  27155. }
  27156. }
  27157. }
  27158. this.__vaoCache = {};
  27159. cache.deleteContext(renderer.__uid__);
  27160. }
  27161. });
  27162. if (Object.defineProperty) {
  27163. /**
  27164. * @name clay.GeometryBase#vertexCount
  27165. * @type {number}
  27166. * @readOnly
  27167. */
  27168. Object.defineProperty(GeometryBase.prototype, 'vertexCount', {
  27169. enumerable: false,
  27170. get: function () {
  27171. var mainAttribute = this.attributes[this.mainAttribute];
  27172. if (!mainAttribute) {
  27173. mainAttribute = this.attributes[this._attributeList[0]];
  27174. }
  27175. if (!mainAttribute || !mainAttribute.value) {
  27176. return 0;
  27177. }
  27178. return mainAttribute.value.length / mainAttribute.size;
  27179. }
  27180. });
  27181. /**
  27182. * @name clay.GeometryBase#triangleCount
  27183. * @type {number}
  27184. * @readOnly
  27185. */
  27186. Object.defineProperty(GeometryBase.prototype, 'triangleCount', {
  27187. enumerable: false,
  27188. get: function () {
  27189. var indices = this.indices;
  27190. if (!indices) {
  27191. return 0;
  27192. }
  27193. else {
  27194. return indices.length / 3;
  27195. }
  27196. }
  27197. });
  27198. }
  27199. GeometryBase.STATIC_DRAW = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].STATIC_DRAW;
  27200. GeometryBase.DYNAMIC_DRAW = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].DYNAMIC_DRAW;
  27201. GeometryBase.STREAM_DRAW = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].STREAM_DRAW;
  27202. GeometryBase.AttributeBuffer = AttributeBuffer;
  27203. GeometryBase.IndicesBuffer = IndicesBuffer;
  27204. GeometryBase.Attribute = Attribute;
  27205. /* harmony default export */ __webpack_exports__["a"] = (GeometryBase);
  27206. /***/
  27207. }),
  27208. /* 119 */
  27209. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  27210. "use strict";
  27211. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__calcAmbientSHLight_glsl_js__ = __webpack_require__(120);
  27212. var uniformVec3Prefix = 'uniform vec3 ';
  27213. var uniformFloatPrefix = 'uniform float ';
  27214. var exportHeaderPrefix = '@export clay.header.';
  27215. var exportEnd = '@end';
  27216. var unconfigurable = ':unconfigurable;';
  27217. /* harmony default export */ __webpack_exports__["a"] = ([
  27218. exportHeaderPrefix + 'directional_light',
  27219. uniformVec3Prefix + 'directionalLightDirection[DIRECTIONAL_LIGHT_COUNT]' + unconfigurable,
  27220. uniformVec3Prefix + 'directionalLightColor[DIRECTIONAL_LIGHT_COUNT]' + unconfigurable,
  27221. exportEnd,
  27222. exportHeaderPrefix + 'ambient_light',
  27223. uniformVec3Prefix + 'ambientLightColor[AMBIENT_LIGHT_COUNT]' + unconfigurable,
  27224. exportEnd,
  27225. exportHeaderPrefix + 'ambient_sh_light',
  27226. uniformVec3Prefix + 'ambientSHLightColor[AMBIENT_SH_LIGHT_COUNT]' + unconfigurable,
  27227. uniformVec3Prefix + 'ambientSHLightCoefficients[AMBIENT_SH_LIGHT_COUNT * 9]' + unconfigurable,
  27228. __WEBPACK_IMPORTED_MODULE_0__calcAmbientSHLight_glsl_js__["a" /* default */],
  27229. exportEnd,
  27230. exportHeaderPrefix + 'ambient_cubemap_light',
  27231. uniformVec3Prefix + 'ambientCubemapLightColor[AMBIENT_CUBEMAP_LIGHT_COUNT]' + unconfigurable,
  27232. 'uniform samplerCube ambientCubemapLightCubemap[AMBIENT_CUBEMAP_LIGHT_COUNT]' + unconfigurable,
  27233. 'uniform sampler2D ambientCubemapLightBRDFLookup[AMBIENT_CUBEMAP_LIGHT_COUNT]' + unconfigurable,
  27234. exportEnd,
  27235. exportHeaderPrefix + 'point_light',
  27236. uniformVec3Prefix + 'pointLightPosition[POINT_LIGHT_COUNT]' + unconfigurable,
  27237. uniformFloatPrefix + 'pointLightRange[POINT_LIGHT_COUNT]' + unconfigurable,
  27238. uniformVec3Prefix + 'pointLightColor[POINT_LIGHT_COUNT]' + unconfigurable,
  27239. exportEnd,
  27240. exportHeaderPrefix + 'spot_light',
  27241. uniformVec3Prefix + 'spotLightPosition[SPOT_LIGHT_COUNT]' + unconfigurable,
  27242. uniformVec3Prefix + 'spotLightDirection[SPOT_LIGHT_COUNT]' + unconfigurable,
  27243. uniformFloatPrefix + 'spotLightRange[SPOT_LIGHT_COUNT]' + unconfigurable,
  27244. uniformFloatPrefix + 'spotLightUmbraAngleCosine[SPOT_LIGHT_COUNT]' + unconfigurable,
  27245. uniformFloatPrefix + 'spotLightPenumbraAngleCosine[SPOT_LIGHT_COUNT]' + unconfigurable,
  27246. uniformFloatPrefix + 'spotLightFalloffFactor[SPOT_LIGHT_COUNT]' + unconfigurable,
  27247. uniformVec3Prefix + 'spotLightColor[SPOT_LIGHT_COUNT]' + unconfigurable,
  27248. exportEnd
  27249. ].join('\n'));
  27250. /***/
  27251. }),
  27252. /* 120 */
  27253. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  27254. "use strict";
  27255. /* harmony default export */ __webpack_exports__["a"] = ("vec3 calcAmbientSHLight(int idx, vec3 N) {\n int offset = 9 * idx;\n return ambientSHLightCoefficients[0]\n + ambientSHLightCoefficients[1] * N.x\n + ambientSHLightCoefficients[2] * N.y\n + ambientSHLightCoefficients[3] * N.z\n + ambientSHLightCoefficients[4] * N.x * N.z\n + ambientSHLightCoefficients[5] * N.z * N.y\n + ambientSHLightCoefficients[6] * N.y * N.x\n + ambientSHLightCoefficients[7] * (3.0 * N.z * N.z - 1.0)\n + ambientSHLightCoefficients[8] * (N.x * N.x - N.y * N.y);\n}");
  27256. /***/
  27257. }),
  27258. /* 121 */
  27259. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  27260. "use strict";
  27261. /* harmony default export */ __webpack_exports__["a"] = ("@export clay.skybox.vertex\n#define SHADER_NAME skybox\nuniform mat4 world : WORLD;\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nattribute vec3 position : POSITION;\nvarying vec3 v_WorldPosition;\nvoid main()\n{\n v_WorldPosition = (world * vec4(position, 1.0)).xyz;\n gl_Position = worldViewProjection * vec4(position, 1.0);\n}\n@end\n@export clay.skybox.fragment\n#define PI 3.1415926\nuniform mat4 viewInverse : VIEWINVERSE;\n#ifdef EQUIRECTANGULAR\nuniform sampler2D environmentMap;\n#else\nuniform samplerCube environmentMap;\n#endif\nuniform float lod: 0.0;\nvarying vec3 v_WorldPosition;\n@import clay.util.rgbm\n@import clay.util.srgb\n@import clay.util.ACES\nvoid main()\n{\n vec3 eyePos = viewInverse[3].xyz;\n vec3 V = normalize(v_WorldPosition - eyePos);\n#ifdef EQUIRECTANGULAR\n float phi = acos(V.y);\n float theta = atan(-V.x, V.z) + PI * 0.5;\n vec2 uv = vec2(theta / 2.0 / PI, phi / PI);\n vec4 texel = decodeHDR(texture2D(environmentMap, fract(uv)));\n#else\n #if defined(LOD) || defined(SUPPORT_TEXTURE_LOD)\n vec4 texel = decodeHDR(textureCubeLodEXT(environmentMap, V, lod));\n #else\n vec4 texel = decodeHDR(textureCube(environmentMap, V));\n #endif\n#endif\n#ifdef SRGB_DECODE\n texel = sRGBToLinear(texel);\n#endif\n#ifdef TONEMAPPING\n texel.rgb = ACESToneMapping(texel.rgb);\n#endif\n#ifdef SRGB_ENCODE\n texel = linearTosRGB(texel);\n#endif\n gl_FragColor = encodeHDR(vec4(texel.rgb, 1.0));\n}\n@end");
  27262. /***/
  27263. }),
  27264. /* 122 */
  27265. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  27266. "use strict";
  27267. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Texture__ = __webpack_require__(4);
  27268. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__Texture2D__ = __webpack_require__(5);
  27269. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__TextureCube__ = __webpack_require__(27);
  27270. // http://msdn.microsoft.com/en-us/library/windows/desktop/bb943991(v=vs.85).aspx
  27271. // https://github.com/toji/webgl-texture-utils/blob/master/texture-util/dds.js
  27272. var DDS_MAGIC = 0x20534444;
  27273. var DDSD_CAPS = 0x1;
  27274. var DDSD_HEIGHT = 0x2;
  27275. var DDSD_WIDTH = 0x4;
  27276. var DDSD_PITCH = 0x8;
  27277. var DDSD_PIXELFORMAT = 0x1000;
  27278. var DDSD_MIPMAPCOUNT = 0x20000;
  27279. var DDSD_LINEARSIZE = 0x80000;
  27280. var DDSD_DEPTH = 0x800000;
  27281. var DDSCAPS_COMPLEX = 0x8;
  27282. var DDSCAPS_MIPMAP = 0x400000;
  27283. var DDSCAPS_TEXTURE = 0x1000;
  27284. var DDSCAPS2_CUBEMAP = 0x200;
  27285. var DDSCAPS2_CUBEMAP_POSITIVEX = 0x400;
  27286. var DDSCAPS2_CUBEMAP_NEGATIVEX = 0x800;
  27287. var DDSCAPS2_CUBEMAP_POSITIVEY = 0x1000;
  27288. var DDSCAPS2_CUBEMAP_NEGATIVEY = 0x2000;
  27289. var DDSCAPS2_CUBEMAP_POSITIVEZ = 0x4000;
  27290. var DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x8000;
  27291. var DDSCAPS2_VOLUME = 0x200000;
  27292. var DDPF_ALPHAPIXELS = 0x1;
  27293. var DDPF_ALPHA = 0x2;
  27294. var DDPF_FOURCC = 0x4;
  27295. var DDPF_RGB = 0x40;
  27296. var DDPF_YUV = 0x200;
  27297. var DDPF_LUMINANCE = 0x20000;
  27298. function fourCCToInt32(value) {
  27299. return value.charCodeAt(0) +
  27300. (value.charCodeAt(1) << 8) +
  27301. (value.charCodeAt(2) << 16) +
  27302. (value.charCodeAt(3) << 24);
  27303. }
  27304. function int32ToFourCC(value) {
  27305. return String.fromCharCode(
  27306. value & 0xff,
  27307. (value >> 8) & 0xff,
  27308. (value >> 16) & 0xff,
  27309. (value >> 24) & 0xff
  27310. );
  27311. }
  27312. var headerLengthInt = 31; // The header length in 32 bit ints
  27313. var FOURCC_DXT1 = fourCCToInt32('DXT1');
  27314. var FOURCC_DXT3 = fourCCToInt32('DXT3');
  27315. var FOURCC_DXT5 = fourCCToInt32('DXT5');
  27316. // Offsets into the header array
  27317. var off_magic = 0;
  27318. var off_size = 1;
  27319. var off_flags = 2;
  27320. var off_height = 3;
  27321. var off_width = 4;
  27322. var off_mipmapCount = 7;
  27323. var off_pfFlags = 20;
  27324. var off_pfFourCC = 21;
  27325. var off_caps = 27;
  27326. var off_caps2 = 28;
  27327. var off_caps3 = 29;
  27328. var off_caps4 = 30;
  27329. var ret = {
  27330. parse: function (arrayBuffer, out) {
  27331. var header = new Int32Array(arrayBuffer, 0, headerLengthInt);
  27332. if (header[off_magic] !== DDS_MAGIC) {
  27333. return null;
  27334. }
  27335. if (!header(off_pfFlags) & DDPF_FOURCC) {
  27336. return null;
  27337. }
  27338. var fourCC = header(off_pfFourCC);
  27339. var width = header[off_width];
  27340. var height = header[off_height];
  27341. var isCubeMap = header[off_caps2] & DDSCAPS2_CUBEMAP;
  27342. var hasMipmap = header[off_flags] & DDSD_MIPMAPCOUNT;
  27343. var blockBytes, internalFormat;
  27344. switch (fourCC) {
  27345. case FOURCC_DXT1:
  27346. blockBytes = 8;
  27347. internalFormat = __WEBPACK_IMPORTED_MODULE_0__Texture__["a" /* default */].COMPRESSED_RGB_S3TC_DXT1_EXT;
  27348. break;
  27349. case FOURCC_DXT3:
  27350. blockBytes = 16;
  27351. internalFormat = __WEBPACK_IMPORTED_MODULE_0__Texture__["a" /* default */].COMPRESSED_RGBA_S3TC_DXT3_EXT;
  27352. break;
  27353. case FOURCC_DXT5:
  27354. blockBytes = 16;
  27355. internalFormat = __WEBPACK_IMPORTED_MODULE_0__Texture__["a" /* default */].COMPRESSED_RGBA_S3TC_DXT5_EXT;
  27356. break;
  27357. default:
  27358. return null;
  27359. }
  27360. var dataOffset = header[off_size] + 4;
  27361. // TODO: Suppose all face are existed
  27362. var faceNumber = isCubeMap ? 6 : 1;
  27363. var mipmapCount = 1;
  27364. if (hasMipmap) {
  27365. mipmapCount = Math.max(1, header[off_mipmapCount]);
  27366. }
  27367. var textures = [];
  27368. for (var f = 0; f < faceNumber; f++) {
  27369. var _width = width;
  27370. var _height = height;
  27371. textures[f] = new __WEBPACK_IMPORTED_MODULE_1__Texture2D__["a" /* default */]({
  27372. width: _width,
  27373. height: _height,
  27374. format: internalFormat
  27375. });
  27376. var mipmaps = [];
  27377. for (var i = 0; i < mipmapCount; i++) {
  27378. var dataLength = Math.max(4, _width) / 4 * Math.max(4, _height) / 4 * blockBytes;
  27379. var byteArray = new Uint8Array(arrayBuffer, dataOffset, dataLength);
  27380. dataOffset += dataLength;
  27381. _width *= 0.5;
  27382. _height *= 0.5;
  27383. mipmaps[i] = byteArray;
  27384. }
  27385. textures[f].pixels = mipmaps[0];
  27386. if (hasMipmap) {
  27387. textures[f].mipmaps = mipmaps;
  27388. }
  27389. }
  27390. // TODO
  27391. // return isCubeMap ? textures : textures[0];
  27392. if (out) {
  27393. out.width = textures[0].width;
  27394. out.height = textures[0].height;
  27395. out.format = textures[0].format;
  27396. out.pixels = textures[0].pixels;
  27397. out.mipmaps = textures[0].mipmaps;
  27398. }
  27399. else {
  27400. return textures[0];
  27401. }
  27402. }
  27403. };
  27404. /* harmony default export */ __webpack_exports__["a"] = (ret);
  27405. /***/
  27406. }),
  27407. /* 123 */
  27408. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  27409. "use strict";
  27410. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Texture__ = __webpack_require__(4);
  27411. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__Texture2D__ = __webpack_require__(5);
  27412. var toChar = String.fromCharCode;
  27413. var MINELEN = 8;
  27414. var MAXELEN = 0x7fff;
  27415. function rgbe2float(rgbe, buffer, offset, exposure) {
  27416. if (rgbe[3] > 0) {
  27417. var f = Math.pow(2.0, rgbe[3] - 128 - 8 + exposure);
  27418. buffer[offset + 0] = rgbe[0] * f;
  27419. buffer[offset + 1] = rgbe[1] * f;
  27420. buffer[offset + 2] = rgbe[2] * f;
  27421. }
  27422. else {
  27423. buffer[offset + 0] = 0;
  27424. buffer[offset + 1] = 0;
  27425. buffer[offset + 2] = 0;
  27426. }
  27427. buffer[offset + 3] = 1.0;
  27428. return buffer;
  27429. }
  27430. function uint82string(array, offset, size) {
  27431. var str = '';
  27432. for (var i = offset; i < size; i++) {
  27433. str += toChar(array[i]);
  27434. }
  27435. return str;
  27436. }
  27437. function copyrgbe(s, t) {
  27438. t[0] = s[0];
  27439. t[1] = s[1];
  27440. t[2] = s[2];
  27441. t[3] = s[3];
  27442. }
  27443. // TODO : check
  27444. function oldReadColors(scan, buffer, offset, xmax) {
  27445. var rshift = 0, x = 0, len = xmax;
  27446. while (len > 0) {
  27447. scan[x][0] = buffer[offset++];
  27448. scan[x][1] = buffer[offset++];
  27449. scan[x][2] = buffer[offset++];
  27450. scan[x][3] = buffer[offset++];
  27451. if (scan[x][0] === 1 && scan[x][1] === 1 && scan[x][2] === 1) {
  27452. // exp is count of repeated pixels
  27453. for (var i = (scan[x][3] << rshift) >>> 0; i > 0; i--) {
  27454. copyrgbe(scan[x - 1], scan[x]);
  27455. x++;
  27456. len--;
  27457. }
  27458. rshift += 8;
  27459. } else {
  27460. x++;
  27461. len--;
  27462. rshift = 0;
  27463. }
  27464. }
  27465. return offset;
  27466. }
  27467. function readColors(scan, buffer, offset, xmax) {
  27468. if ((xmax < MINELEN) | (xmax > MAXELEN)) {
  27469. return oldReadColors(scan, buffer, offset, xmax);
  27470. }
  27471. var i = buffer[offset++];
  27472. if (i != 2) {
  27473. return oldReadColors(scan, buffer, offset - 1, xmax);
  27474. }
  27475. scan[0][1] = buffer[offset++];
  27476. scan[0][2] = buffer[offset++];
  27477. i = buffer[offset++];
  27478. if ((((scan[0][2] << 8) >>> 0) | i) >>> 0 !== xmax) {
  27479. return null;
  27480. }
  27481. for (var i = 0; i < 4; i++) {
  27482. for (var x = 0; x < xmax;) {
  27483. var code = buffer[offset++];
  27484. if (code > 128) {
  27485. code = (code & 127) >>> 0;
  27486. var val = buffer[offset++];
  27487. while (code--) {
  27488. scan[x++][i] = val;
  27489. }
  27490. } else {
  27491. while (code--) {
  27492. scan[x++][i] = buffer[offset++];
  27493. }
  27494. }
  27495. }
  27496. }
  27497. return offset;
  27498. }
  27499. var ret = {
  27500. // http://www.graphics.cornell.edu/~bjw/rgbe.html
  27501. // Blender source
  27502. // http://radsite.lbl.gov/radiance/refer/Notes/picture_format.html
  27503. parseRGBE: function (arrayBuffer, texture, exposure) {
  27504. if (exposure == null) {
  27505. exposure = 0;
  27506. }
  27507. var data = new Uint8Array(arrayBuffer);
  27508. var size = data.length;
  27509. if (uint82string(data, 0, 2) !== '#?') {
  27510. return;
  27511. }
  27512. // find empty line, next line is resolution info
  27513. for (var i = 2; i < size; i++) {
  27514. if (toChar(data[i]) === '\n' && toChar(data[i + 1]) === '\n') {
  27515. break;
  27516. }
  27517. }
  27518. if (i >= size) { // not found
  27519. return;
  27520. }
  27521. // find resolution info line
  27522. i += 2;
  27523. var str = '';
  27524. for (; i < size; i++) {
  27525. var _char = toChar(data[i]);
  27526. if (_char === '\n') {
  27527. break;
  27528. }
  27529. str += _char;
  27530. }
  27531. // -Y M +X N
  27532. var tmp = str.split(' ');
  27533. var height = parseInt(tmp[1]);
  27534. var width = parseInt(tmp[3]);
  27535. if (!width || !height) {
  27536. return;
  27537. }
  27538. // read and decode actual data
  27539. var offset = i + 1;
  27540. var scanline = [];
  27541. // memzero
  27542. for (var x = 0; x < width; x++) {
  27543. scanline[x] = [];
  27544. for (var j = 0; j < 4; j++) {
  27545. scanline[x][j] = 0;
  27546. }
  27547. }
  27548. var pixels = new Float32Array(width * height * 4);
  27549. var offset2 = 0;
  27550. for (var y = 0; y < height; y++) {
  27551. var offset = readColors(scanline, data, offset, width);
  27552. if (!offset) {
  27553. return null;
  27554. }
  27555. for (var x = 0; x < width; x++) {
  27556. rgbe2float(scanline[x], pixels, offset2, exposure);
  27557. offset2 += 4;
  27558. }
  27559. }
  27560. if (!texture) {
  27561. texture = new __WEBPACK_IMPORTED_MODULE_1__Texture2D__["a" /* default */]();
  27562. }
  27563. texture.width = width;
  27564. texture.height = height;
  27565. texture.pixels = pixels;
  27566. // HALF_FLOAT can't use Float32Array
  27567. texture.type = __WEBPACK_IMPORTED_MODULE_0__Texture__["a" /* default */].FLOAT;
  27568. return texture;
  27569. },
  27570. parseRGBEFromPNG: function (png) {
  27571. }
  27572. };
  27573. /* harmony default export */ __webpack_exports__["a"] = (ret);
  27574. /***/
  27575. }),
  27576. /* 124 */
  27577. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  27578. "use strict";
  27579. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_claygl_src_Texture2D__ = __webpack_require__(5);
  27580. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_math_Vector3__ = __webpack_require__(3);
  27581. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_claygl_src_math_Vector2__ = __webpack_require__(26);
  27582. /**
  27583. * Surface texture in the 3D scene.
  27584. * Provide management and rendering of zrender shapes and groups
  27585. *
  27586. * @module echarts-gl/util/EChartsSurface
  27587. * @author Yi Shen(http://github.com/pissang)
  27588. */
  27589. var events = ['mousedown', 'mouseup', 'mousemove', 'mouseover', 'mouseout', 'click', 'dblclick', 'contextmenu'];
  27590. function makeHandlerName(eventName) {
  27591. return '_on' + eventName;
  27592. }
  27593. /**
  27594. * @constructor
  27595. * @alias echarts-gl/util/EChartsSurface
  27596. * @param {module:echarts~ECharts} chart
  27597. */
  27598. var EChartsSurface = function (chart) {
  27599. var self = this;
  27600. this._texture = new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Texture2D__["a" /* default */]({
  27601. anisotropic: 32,
  27602. flipY: false,
  27603. surface: this,
  27604. dispose: function (renderer) {
  27605. self.dispose();
  27606. __WEBPACK_IMPORTED_MODULE_0_claygl_src_Texture2D__["a" /* default */].prototype.dispose.call(this, renderer);
  27607. }
  27608. });
  27609. events.forEach(function (eventName) {
  27610. this[makeHandlerName(eventName)] = function (eveObj) {
  27611. if (!eveObj.triangle) {
  27612. return;
  27613. }
  27614. this._meshes.forEach(function (mesh) {
  27615. this.dispatchEvent(eventName, mesh, eveObj.triangle, eveObj.point);
  27616. }, this);
  27617. };
  27618. }, this);
  27619. this._meshes = [];
  27620. if (chart) {
  27621. this.setECharts(chart);
  27622. }
  27623. // Texture updated callback;
  27624. this.onupdate = null;
  27625. };
  27626. EChartsSurface.prototype = {
  27627. constructor: EChartsSurface,
  27628. getTexture: function () {
  27629. return this._texture;
  27630. },
  27631. setECharts: function (chart) {
  27632. this._chart = chart;
  27633. var canvas = chart.getDom();
  27634. if (!(canvas instanceof HTMLCanvasElement)) {
  27635. console.error('ECharts must init on canvas if it is used as texture.');
  27636. // Use an empty canvas
  27637. canvas = document.createElement('canvas');
  27638. }
  27639. else {
  27640. var self = this;
  27641. // Wrap refreshImmediately
  27642. var zr = chart.getZr();
  27643. var oldRefreshImmediately = zr.__oldRefreshImmediately || zr.refreshImmediately;
  27644. zr.refreshImmediately = function () {
  27645. oldRefreshImmediately.call(this);
  27646. self._texture.dirty();
  27647. self.onupdate && self.onupdate();
  27648. };
  27649. zr.__oldRefreshImmediately = oldRefreshImmediately;
  27650. }
  27651. this._texture.image = canvas;
  27652. this._texture.dirty();
  27653. this.onupdate && this.onupdate();
  27654. },
  27655. /**
  27656. * @method
  27657. * @param {clay.Mesh} attachedMesh
  27658. * @param {Array.<number>} triangle Triangle indices
  27659. * @param {clay.math.Vector3} point
  27660. */
  27661. dispatchEvent: (function () {
  27662. var p0 = new __WEBPACK_IMPORTED_MODULE_1_claygl_src_math_Vector3__["a" /* default */]();
  27663. var p1 = new __WEBPACK_IMPORTED_MODULE_1_claygl_src_math_Vector3__["a" /* default */]();
  27664. var p2 = new __WEBPACK_IMPORTED_MODULE_1_claygl_src_math_Vector3__["a" /* default */]();
  27665. var uv0 = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_math_Vector2__["a" /* default */]();
  27666. var uv1 = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_math_Vector2__["a" /* default */]();
  27667. var uv2 = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_math_Vector2__["a" /* default */]();
  27668. var uv = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_math_Vector2__["a" /* default */]();
  27669. var vCross = new __WEBPACK_IMPORTED_MODULE_1_claygl_src_math_Vector3__["a" /* default */]();
  27670. return function (eventName, attachedMesh, triangle, point) {
  27671. var geo = attachedMesh.geometry;
  27672. var position = geo.attributes.position;
  27673. var texcoord = geo.attributes.texcoord0;
  27674. var dot = __WEBPACK_IMPORTED_MODULE_1_claygl_src_math_Vector3__["a" /* default */].dot;
  27675. var cross = __WEBPACK_IMPORTED_MODULE_1_claygl_src_math_Vector3__["a" /* default */].cross;
  27676. position.get(triangle[0], p0.array);
  27677. position.get(triangle[1], p1.array);
  27678. position.get(triangle[2], p2.array);
  27679. texcoord.get(triangle[0], uv0.array);
  27680. texcoord.get(triangle[1], uv1.array);
  27681. texcoord.get(triangle[2], uv2.array);
  27682. cross(vCross, p1, p2);
  27683. var det = dot(p0, vCross);
  27684. var t = dot(point, vCross) / det;
  27685. cross(vCross, p2, p0);
  27686. var u = dot(point, vCross) / det;
  27687. cross(vCross, p0, p1);
  27688. var v = dot(point, vCross) / det;
  27689. __WEBPACK_IMPORTED_MODULE_2_claygl_src_math_Vector2__["a" /* default */].scale(uv, uv0, t);
  27690. __WEBPACK_IMPORTED_MODULE_2_claygl_src_math_Vector2__["a" /* default */].scaleAndAdd(uv, uv, uv1, u);
  27691. __WEBPACK_IMPORTED_MODULE_2_claygl_src_math_Vector2__["a" /* default */].scaleAndAdd(uv, uv, uv2, v);
  27692. var x = uv.x * this._chart.getWidth();
  27693. var y = uv.y * this._chart.getHeight();
  27694. this._chart.getZr().handler.dispatch(eventName, {
  27695. zrX: x,
  27696. zrY: y
  27697. });
  27698. };
  27699. })(),
  27700. attachToMesh: function (mesh) {
  27701. if (this._meshes.indexOf(mesh) >= 0) {
  27702. return;
  27703. }
  27704. events.forEach(function (eventName) {
  27705. mesh.on(eventName, this[makeHandlerName(eventName)], this);
  27706. }, this);
  27707. this._meshes.push(mesh);
  27708. },
  27709. detachFromMesh: function (mesh) {
  27710. var idx = this._meshes.indexOf(mesh);
  27711. if (idx >= 0) {
  27712. this._meshes.splice(idx, 1);
  27713. }
  27714. events.forEach(function (eventName) {
  27715. mesh.off(eventName, this[makeHandlerName(eventName)]);
  27716. }, this);
  27717. },
  27718. dispose: function () {
  27719. this._meshes.forEach(function (mesh) {
  27720. this.detachFromMesh(mesh);
  27721. }, this);
  27722. }
  27723. };
  27724. /* harmony default export */ __webpack_exports__["a"] = (EChartsSurface);
  27725. /***/
  27726. }),
  27727. /* 125 */
  27728. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  27729. "use strict";
  27730. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Light__ = __webpack_require__(24);
  27731. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_cubemap__ = __webpack_require__(77);
  27732. // https://docs.unrealengine.com/latest/INT/Engine/Rendering/LightingAndShadows/AmbientCubemap/
  27733. /**
  27734. * Ambient cubemap light provides specular parts of Image Based Lighting.
  27735. * Which is a basic requirement for Physically Based Rendering
  27736. * @constructor clay.light.AmbientCubemap
  27737. * @extends clay.Light
  27738. */
  27739. var AmbientCubemapLight = __WEBPACK_IMPORTED_MODULE_0__Light__["a" /* default */].extend({
  27740. /**
  27741. * @type {clay.TextureCube}
  27742. * @memberOf clay.light.AmbientCubemap#
  27743. */
  27744. cubemap: null,
  27745. // TODO
  27746. // range: 100,
  27747. castShadow: false,
  27748. _normalDistribution: null,
  27749. _brdfLookup: null
  27750. }, /** @lends clay.light.AmbientCubemap# */ {
  27751. type: 'AMBIENT_CUBEMAP_LIGHT',
  27752. /**
  27753. * Do prefitering the cubemap
  27754. * @param {clay.Renderer} renderer
  27755. * @param {number} [size=32]
  27756. */
  27757. prefilter: function (renderer, size) {
  27758. if (!renderer.getGLExtension('EXT_shader_texture_lod')) {
  27759. console.warn('Device not support textureCubeLodEXT');
  27760. return;
  27761. }
  27762. if (!this._brdfLookup) {
  27763. this._normalDistribution = __WEBPACK_IMPORTED_MODULE_1__util_cubemap__["a" /* default */].generateNormalDistribution();
  27764. this._brdfLookup = __WEBPACK_IMPORTED_MODULE_1__util_cubemap__["a" /* default */].integrateBRDF(renderer, this._normalDistribution);
  27765. }
  27766. var cubemap = this.cubemap;
  27767. if (cubemap.__prefiltered) {
  27768. return;
  27769. }
  27770. var result = __WEBPACK_IMPORTED_MODULE_1__util_cubemap__["a" /* default */].prefilterEnvironmentMap(
  27771. renderer, cubemap, {
  27772. encodeRGBM: true,
  27773. width: size,
  27774. height: size
  27775. }, this._normalDistribution, this._brdfLookup
  27776. );
  27777. this.cubemap = result.environmentMap;
  27778. this.cubemap.__prefiltered = true;
  27779. cubemap.dispose(renderer);
  27780. },
  27781. getBRDFLookup: function () {
  27782. return this._brdfLookup;
  27783. },
  27784. uniformTemplates: {
  27785. ambientCubemapLightColor: {
  27786. type: '3f',
  27787. value: function (instance) {
  27788. var color = instance.color;
  27789. var intensity = instance.intensity;
  27790. return [color[0] * intensity, color[1] * intensity, color[2] * intensity];
  27791. }
  27792. },
  27793. ambientCubemapLightCubemap: {
  27794. type: 't',
  27795. value: function (instance) {
  27796. return instance.cubemap;
  27797. }
  27798. },
  27799. ambientCubemapLightBRDFLookup: {
  27800. type: 't',
  27801. value: function (instance) {
  27802. return instance._brdfLookup;
  27803. }
  27804. }
  27805. }
  27806. /**
  27807. * @function
  27808. * @name clone
  27809. * @return {clay.light.AmbientCubemap}
  27810. * @memberOf clay.light.AmbientCubemap.prototype
  27811. */
  27812. });
  27813. /* harmony default export */ __webpack_exports__["a"] = (AmbientCubemapLight);
  27814. /***/
  27815. }),
  27816. /* 126 */
  27817. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  27818. "use strict";
  27819. /* harmony default export */ __webpack_exports__["a"] = ("\n@export clay.compositor.vertex\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nattribute vec3 position : POSITION;\nattribute vec2 texcoord : TEXCOORD_0;\nvarying vec2 v_Texcoord;\nvoid main()\n{\n v_Texcoord = texcoord;\n gl_Position = worldViewProjection * vec4(position, 1.0);\n}\n@end");
  27820. /***/
  27821. }),
  27822. /* 127 */
  27823. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  27824. "use strict";
  27825. /* harmony default export */ __webpack_exports__["a"] = ("#define SAMPLE_NUMBER 1024\n#define PI 3.14159265358979\nuniform sampler2D normalDistribution;\nuniform vec2 viewportSize : [512, 256];\nconst vec3 N = vec3(0.0, 0.0, 1.0);\nconst float fSampleNumber = float(SAMPLE_NUMBER);\nvec3 importanceSampleNormal(float i, float roughness, vec3 N) {\n vec3 H = texture2D(normalDistribution, vec2(roughness, i)).rgb;\n vec3 upVector = abs(N.y) > 0.999 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0);\n vec3 tangentX = normalize(cross(N, upVector));\n vec3 tangentZ = cross(N, tangentX);\n return normalize(tangentX * H.x + N * H.y + tangentZ * H.z);\n}\nfloat G_Smith(float roughness, float NoV, float NoL) {\n float k = roughness * roughness / 2.0;\n float G1V = NoV / (NoV * (1.0 - k) + k);\n float G1L = NoL / (NoL * (1.0 - k) + k);\n return G1L * G1V;\n}\nvoid main() {\n vec2 uv = gl_FragCoord.xy / viewportSize;\n float NoV = uv.x;\n float roughness = uv.y;\n vec3 V;\n V.x = sqrt(1.0 - NoV * NoV);\n V.y = 0.0;\n V.z = NoV;\n float A = 0.0;\n float B = 0.0;\n for (int i = 0; i < SAMPLE_NUMBER; i++) {\n vec3 H = importanceSampleNormal(float(i) / fSampleNumber, roughness, N);\n vec3 L = reflect(-V, H);\n float NoL = clamp(L.z, 0.0, 1.0);\n float NoH = clamp(H.z, 0.0, 1.0);\n float VoH = clamp(dot(V, H), 0.0, 1.0);\n if (NoL > 0.0) {\n float G = G_Smith(roughness, NoV, NoL);\n float G_Vis = G * VoH / (NoH * NoV);\n float Fc = pow(1.0 - VoH, 5.0);\n A += (1.0 - Fc) * G_Vis;\n B += Fc * G_Vis;\n }\n }\n gl_FragColor = vec4(vec2(A, B) / fSampleNumber, 0.0, 1.0);\n}\n");
  27826. /***/
  27827. }),
  27828. /* 128 */
  27829. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  27830. "use strict";
  27831. /* harmony default export */ __webpack_exports__["a"] = ("#define SHADER_NAME prefilter\n#define SAMPLE_NUMBER 1024\n#define PI 3.14159265358979\nuniform mat4 viewInverse : VIEWINVERSE;\nuniform samplerCube environmentMap;\nuniform sampler2D normalDistribution;\nuniform float roughness : 0.5;\nvarying vec2 v_Texcoord;\nvarying vec3 v_WorldPosition;\n@import clay.util.rgbm\nvec3 importanceSampleNormal(float i, float roughness, vec3 N) {\n vec3 H = texture2D(normalDistribution, vec2(roughness, i)).rgb;\n vec3 upVector = abs(N.y) > 0.999 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0);\n vec3 tangentX = normalize(cross(N, upVector));\n vec3 tangentZ = cross(N, tangentX);\n return normalize(tangentX * H.x + N * H.y + tangentZ * H.z);\n}\nvoid main() {\n vec3 eyePos = viewInverse[3].xyz;\n vec3 V = normalize(v_WorldPosition - eyePos);\n vec3 N = V;\n vec3 prefilteredColor = vec3(0.0);\n float totalWeight = 0.0;\n float fMaxSampleNumber = float(SAMPLE_NUMBER);\n for (int i = 0; i < SAMPLE_NUMBER; i++) {\n vec3 H = importanceSampleNormal(float(i) / fMaxSampleNumber, roughness, N);\n vec3 L = reflect(-V, H);\n float NoL = clamp(dot(N, L), 0.0, 1.0);\n if (NoL > 0.0) {\n prefilteredColor += decodeHDR(textureCube(environmentMap, L)).rgb * NoL;\n totalWeight += NoL;\n }\n }\n gl_FragColor = encodeHDR(vec4(prefilteredColor / totalWeight, 1.0));\n}\n");
  27832. /***/
  27833. }),
  27834. /* 129 */
  27835. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  27836. "use strict";
  27837. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Light__ = __webpack_require__(24);
  27838. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__core_vendor__ = __webpack_require__(14);
  27839. /**
  27840. * Spherical Harmonic Ambient Light
  27841. * @constructor clay.light.AmbientSH
  27842. * @extends clay.Light
  27843. */
  27844. var AmbientSHLight = __WEBPACK_IMPORTED_MODULE_0__Light__["a" /* default */].extend({
  27845. castShadow: false,
  27846. /**
  27847. * Spherical Harmonic Coefficients
  27848. * @type {Array.<number>}
  27849. * @memberOf clay.light.AmbientSH#
  27850. */
  27851. coefficients: [],
  27852. }, function () {
  27853. this._coefficientsTmpArr = new __WEBPACK_IMPORTED_MODULE_1__core_vendor__["a" /* default */].Float32Array(9 * 3);
  27854. }, {
  27855. type: 'AMBIENT_SH_LIGHT',
  27856. uniformTemplates: {
  27857. ambientSHLightColor: {
  27858. type: '3f',
  27859. value: function (instance) {
  27860. var color = instance.color;
  27861. var intensity = instance.intensity;
  27862. return [color[0] * intensity, color[1] * intensity, color[2] * intensity];
  27863. }
  27864. },
  27865. ambientSHLightCoefficients: {
  27866. type: '3f',
  27867. value: function (instance) {
  27868. var coefficientsTmpArr = instance._coefficientsTmpArr;
  27869. for (var i = 0; i < instance.coefficients.length; i++) {
  27870. coefficientsTmpArr[i] = instance.coefficients[i];
  27871. }
  27872. return coefficientsTmpArr;
  27873. }
  27874. }
  27875. }
  27876. /**
  27877. * @function
  27878. * @name clone
  27879. * @return {clay.light.Ambient}
  27880. * @memberOf clay.light.Ambient.prototype
  27881. */
  27882. });
  27883. /* harmony default export */ __webpack_exports__["a"] = (AmbientSHLight);
  27884. /***/
  27885. }),
  27886. /* 130 */
  27887. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  27888. "use strict";
  27889. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Texture__ = __webpack_require__(4);
  27890. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__FrameBuffer__ = __webpack_require__(10);
  27891. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__Texture2D__ = __webpack_require__(5);
  27892. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__compositor_Pass__ = __webpack_require__(16);
  27893. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__core_vendor__ = __webpack_require__(14);
  27894. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__plugin_Skybox__ = __webpack_require__(42);
  27895. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__plugin_Skydome__ = __webpack_require__(75);
  27896. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__prePass_EnvironmentMap__ = __webpack_require__(62);
  27897. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__Scene__ = __webpack_require__(36);
  27898. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_9__glmatrix_vec3__ = __webpack_require__(12);
  27899. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_10__shader_projectEnvMap_glsl_js__ = __webpack_require__(131);
  27900. // Spherical Harmonic Helpers
  27901. var sh = {};
  27902. var targets = ['px', 'nx', 'py', 'ny', 'pz', 'nz'];
  27903. // Project on gpu, but needs browser to support readPixels as Float32Array.
  27904. function projectEnvironmentMapGPU(renderer, envMap) {
  27905. var shTexture = new __WEBPACK_IMPORTED_MODULE_2__Texture2D__["a" /* default */]({
  27906. width: 9,
  27907. height: 1,
  27908. type: __WEBPACK_IMPORTED_MODULE_0__Texture__["a" /* default */].FLOAT
  27909. });
  27910. var pass = new __WEBPACK_IMPORTED_MODULE_3__compositor_Pass__["a" /* default */]({
  27911. fragment: __WEBPACK_IMPORTED_MODULE_10__shader_projectEnvMap_glsl_js__["a" /* default */]
  27912. });
  27913. pass.material.define('fragment', 'TEXTURE_SIZE', envMap.width);
  27914. pass.setUniform('environmentMap', envMap);
  27915. var framebuffer = new __WEBPACK_IMPORTED_MODULE_1__FrameBuffer__["a" /* default */]();
  27916. framebuffer.attach(shTexture);
  27917. pass.render(renderer, framebuffer);
  27918. framebuffer.bind(renderer);
  27919. // TODO Only chrome and firefox support Float32Array
  27920. var pixels = new __WEBPACK_IMPORTED_MODULE_4__core_vendor__["a" /* default */].Float32Array(9 * 4);
  27921. renderer.gl.readPixels(0, 0, 9, 1, __WEBPACK_IMPORTED_MODULE_0__Texture__["a" /* default */].RGBA, __WEBPACK_IMPORTED_MODULE_0__Texture__["a" /* default */].FLOAT, pixels);
  27922. var coeff = new __WEBPACK_IMPORTED_MODULE_4__core_vendor__["a" /* default */].Float32Array(9 * 3);
  27923. for (var i = 0; i < 9; i++) {
  27924. coeff[i * 3] = pixels[i * 4];
  27925. coeff[i * 3 + 1] = pixels[i * 4 + 1];
  27926. coeff[i * 3 + 2] = pixels[i * 4 + 2];
  27927. }
  27928. framebuffer.unbind(renderer);
  27929. framebuffer.dispose(renderer);
  27930. pass.dispose(renderer);
  27931. return coeff;
  27932. }
  27933. function harmonics(normal, index) {
  27934. var x = normal[0];
  27935. var y = normal[1];
  27936. var z = normal[2];
  27937. if (index === 0) {
  27938. return 1.0;
  27939. }
  27940. else if (index === 1) {
  27941. return x;
  27942. }
  27943. else if (index === 2) {
  27944. return y;
  27945. }
  27946. else if (index === 3) {
  27947. return z;
  27948. }
  27949. else if (index === 4) {
  27950. return x * z;
  27951. }
  27952. else if (index === 5) {
  27953. return y * z;
  27954. }
  27955. else if (index === 6) {
  27956. return x * y;
  27957. }
  27958. else if (index === 7) {
  27959. return 3.0 * z * z - 1.0;
  27960. }
  27961. else {
  27962. return x * x - y * y;
  27963. }
  27964. }
  27965. var normalTransform = {
  27966. px: [2, 1, 0, -1, -1, 1],
  27967. nx: [2, 1, 0, 1, -1, -1],
  27968. py: [0, 2, 1, 1, -1, -1],
  27969. ny: [0, 2, 1, 1, 1, 1],
  27970. pz: [0, 1, 2, -1, -1, -1],
  27971. nz: [0, 1, 2, 1, -1, 1]
  27972. };
  27973. // Project on cpu.
  27974. function projectEnvironmentMapCPU(renderer, cubePixels, width, height) {
  27975. var coeff = new __WEBPACK_IMPORTED_MODULE_4__core_vendor__["a" /* default */].Float32Array(9 * 3);
  27976. var normal = __WEBPACK_IMPORTED_MODULE_9__glmatrix_vec3__["a" /* default */].create();
  27977. var texel = __WEBPACK_IMPORTED_MODULE_9__glmatrix_vec3__["a" /* default */].create();
  27978. var fetchNormal = __WEBPACK_IMPORTED_MODULE_9__glmatrix_vec3__["a" /* default */].create();
  27979. for (var m = 0; m < 9; m++) {
  27980. var result = __WEBPACK_IMPORTED_MODULE_9__glmatrix_vec3__["a" /* default */].create();
  27981. for (var k = 0; k < targets.length; k++) {
  27982. var pixels = cubePixels[targets[k]];
  27983. var sideResult = __WEBPACK_IMPORTED_MODULE_9__glmatrix_vec3__["a" /* default */].create();
  27984. var divider = 0;
  27985. var i = 0;
  27986. var transform = normalTransform[targets[k]];
  27987. for (var y = 0; y < height; y++) {
  27988. for (var x = 0; x < width; x++) {
  27989. normal[0] = x / (width - 1.0) * 2.0 - 1.0;
  27990. // TODO Flip y?
  27991. normal[1] = y / (height - 1.0) * 2.0 - 1.0;
  27992. normal[2] = -1.0;
  27993. __WEBPACK_IMPORTED_MODULE_9__glmatrix_vec3__["a" /* default */].normalize(normal, normal);
  27994. fetchNormal[0] = normal[transform[0]] * transform[3];
  27995. fetchNormal[1] = normal[transform[1]] * transform[4];
  27996. fetchNormal[2] = normal[transform[2]] * transform[5];
  27997. texel[0] = pixels[i++] / 255;
  27998. texel[1] = pixels[i++] / 255;
  27999. texel[2] = pixels[i++] / 255;
  28000. // RGBM Decode
  28001. var scale = pixels[i++] / 255 * 8.12;
  28002. texel[0] *= scale;
  28003. texel[1] *= scale;
  28004. texel[2] *= scale;
  28005. __WEBPACK_IMPORTED_MODULE_9__glmatrix_vec3__["a" /* default */].scaleAndAdd(sideResult, sideResult, texel, harmonics(fetchNormal, m) * -normal[2]);
  28006. // -normal.z equals cos(theta) of Lambertian
  28007. divider += -normal[2];
  28008. }
  28009. }
  28010. __WEBPACK_IMPORTED_MODULE_9__glmatrix_vec3__["a" /* default */].scaleAndAdd(result, result, sideResult, 1 / divider);
  28011. }
  28012. coeff[m * 3] = result[0] / 6.0;
  28013. coeff[m * 3 + 1] = result[1] / 6.0;
  28014. coeff[m * 3 + 2] = result[2] / 6.0;
  28015. }
  28016. return coeff;
  28017. }
  28018. /**
  28019. * @param {clay.Renderer} renderer
  28020. * @param {clay.Texture} envMap
  28021. * @param {Object} [textureOpts]
  28022. * @param {Object} [textureOpts.lod]
  28023. * @param {boolean} [textureOpts.decodeRGBM]
  28024. */
  28025. sh.projectEnvironmentMap = function (renderer, envMap, opts) {
  28026. // TODO sRGB
  28027. opts = opts || {};
  28028. opts.lod = opts.lod || 0;
  28029. var skybox;
  28030. var dummyScene = new __WEBPACK_IMPORTED_MODULE_8__Scene__["a" /* default */]();
  28031. var size = 64;
  28032. if (envMap.textureType === 'texture2D') {
  28033. skybox = new __WEBPACK_IMPORTED_MODULE_6__plugin_Skydome__["a" /* default */]({
  28034. scene: dummyScene,
  28035. environmentMap: envMap
  28036. });
  28037. }
  28038. else {
  28039. size = (envMap.image && envMap.image.px) ? envMap.image.px.width : envMap.width;
  28040. skybox = new __WEBPACK_IMPORTED_MODULE_5__plugin_Skybox__["a" /* default */]({
  28041. scene: dummyScene,
  28042. environmentMap: envMap
  28043. });
  28044. }
  28045. // Convert to rgbm
  28046. var width = Math.ceil(size / Math.pow(2, opts.lod));
  28047. var height = Math.ceil(size / Math.pow(2, opts.lod));
  28048. var rgbmTexture = new __WEBPACK_IMPORTED_MODULE_2__Texture2D__["a" /* default */]({
  28049. width: width,
  28050. height: height
  28051. });
  28052. var framebuffer = new __WEBPACK_IMPORTED_MODULE_1__FrameBuffer__["a" /* default */]();
  28053. skybox.material.define('fragment', 'RGBM_ENCODE');
  28054. if (opts.decodeRGBM) {
  28055. skybox.material.define('fragment', 'RGBM_DECODE');
  28056. }
  28057. skybox.material.set('lod', opts.lod);
  28058. var envMapPass = new __WEBPACK_IMPORTED_MODULE_7__prePass_EnvironmentMap__["a" /* default */]({
  28059. texture: rgbmTexture
  28060. });
  28061. var cubePixels = {};
  28062. for (var i = 0; i < targets.length; i++) {
  28063. cubePixels[targets[i]] = new Uint8Array(width * height * 4);
  28064. var camera = envMapPass.getCamera(targets[i]);
  28065. camera.fov = 90;
  28066. framebuffer.attach(rgbmTexture);
  28067. framebuffer.bind(renderer);
  28068. renderer.render(dummyScene, camera);
  28069. renderer.gl.readPixels(
  28070. 0, 0, width, height,
  28071. __WEBPACK_IMPORTED_MODULE_0__Texture__["a" /* default */].RGBA, __WEBPACK_IMPORTED_MODULE_0__Texture__["a" /* default */].UNSIGNED_BYTE, cubePixels[targets[i]]
  28072. );
  28073. framebuffer.unbind(renderer);
  28074. }
  28075. skybox.dispose(renderer);
  28076. framebuffer.dispose(renderer);
  28077. rgbmTexture.dispose(renderer);
  28078. return projectEnvironmentMapCPU(renderer, cubePixels, width, height);
  28079. };
  28080. /* harmony default export */ __webpack_exports__["a"] = (sh);
  28081. /***/
  28082. }),
  28083. /* 131 */
  28084. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  28085. "use strict";
  28086. /* harmony default export */ __webpack_exports__["a"] = ("uniform samplerCube environmentMap;\nvarying vec2 v_Texcoord;\n#define TEXTURE_SIZE 16\nmat3 front = mat3(\n 1.0, 0.0, 0.0,\n 0.0, 1.0, 0.0,\n 0.0, 0.0, 1.0\n);\nmat3 back = mat3(\n -1.0, 0.0, 0.0,\n 0.0, 1.0, 0.0,\n 0.0, 0.0, -1.0\n);\nmat3 left = mat3(\n 0.0, 0.0, -1.0,\n 0.0, 1.0, 0.0,\n 1.0, 0.0, 0.0\n);\nmat3 right = mat3(\n 0.0, 0.0, 1.0,\n 0.0, 1.0, 0.0,\n -1.0, 0.0, 0.0\n);\nmat3 up = mat3(\n 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0,\n 0.0, -1.0, 0.0\n);\nmat3 down = mat3(\n 1.0, 0.0, 0.0,\n 0.0, 0.0, -1.0,\n 0.0, 1.0, 0.0\n);\nfloat harmonics(vec3 normal){\n int index = int(gl_FragCoord.x);\n float x = normal.x;\n float y = normal.y;\n float z = normal.z;\n if(index==0){\n return 1.0;\n }\n else if(index==1){\n return x;\n }\n else if(index==2){\n return y;\n }\n else if(index==3){\n return z;\n }\n else if(index==4){\n return x*z;\n }\n else if(index==5){\n return y*z;\n }\n else if(index==6){\n return x*y;\n }\n else if(index==7){\n return 3.0*z*z - 1.0;\n }\n else{\n return x*x - y*y;\n }\n}\nvec3 sampleSide(mat3 rot)\n{\n vec3 result = vec3(0.0);\n float divider = 0.0;\n for (int i = 0; i < TEXTURE_SIZE * TEXTURE_SIZE; i++) {\n float x = mod(float(i), float(TEXTURE_SIZE));\n float y = float(i / TEXTURE_SIZE);\n vec2 sidecoord = ((vec2(x, y) + vec2(0.5, 0.5)) / vec2(TEXTURE_SIZE)) * 2.0 - 1.0;\n vec3 normal = normalize(vec3(sidecoord, -1.0));\n vec3 fetchNormal = rot * normal;\n vec3 texel = textureCube(environmentMap, fetchNormal).rgb;\n result += harmonics(fetchNormal) * texel * -normal.z;\n divider += -normal.z;\n }\n return result / divider;\n}\nvoid main()\n{\n vec3 result = (\n sampleSide(front) +\n sampleSide(back) +\n sampleSide(left) +\n sampleSide(right) +\n sampleSide(up) +\n sampleSide(down)\n ) / 6.0;\n gl_FragColor = vec4(result, 1.0);\n}");
  28087. /***/
  28088. }),
  28089. /* 132 */
  28090. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  28091. "use strict";
  28092. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Geometry__ = __webpack_require__(15);
  28093. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__math_BoundingBox__ = __webpack_require__(18);
  28094. /**
  28095. * @constructor clay.geometry.Sphere
  28096. * @extends clay.Geometry
  28097. * @param {Object} [opt]
  28098. * @param {number} [widthSegments]
  28099. * @param {number} [heightSegments]
  28100. * @param {number} [phiStart]
  28101. * @param {number} [phiLength]
  28102. * @param {number} [thetaStart]
  28103. * @param {number} [thetaLength]
  28104. * @param {number} [radius]
  28105. */
  28106. var Sphere = __WEBPACK_IMPORTED_MODULE_0__Geometry__["a" /* default */].extend(/** @lends clay.geometry.Sphere# */ {
  28107. dynamic: false,
  28108. /**
  28109. * @type {number}
  28110. */
  28111. widthSegments: 40,
  28112. /**
  28113. * @type {number}
  28114. */
  28115. heightSegments: 20,
  28116. /**
  28117. * @type {number}
  28118. */
  28119. phiStart: 0,
  28120. /**
  28121. * @type {number}
  28122. */
  28123. phiLength: Math.PI * 2,
  28124. /**
  28125. * @type {number}
  28126. */
  28127. thetaStart: 0,
  28128. /**
  28129. * @type {number}
  28130. */
  28131. thetaLength: Math.PI,
  28132. /**
  28133. * @type {number}
  28134. */
  28135. radius: 1
  28136. }, function () {
  28137. this.build();
  28138. },
  28139. /** @lends clay.geometry.Sphere.prototype */
  28140. {
  28141. /**
  28142. * Build sphere geometry
  28143. */
  28144. build: function () {
  28145. var heightSegments = this.heightSegments;
  28146. var widthSegments = this.widthSegments;
  28147. var positionAttr = this.attributes.position;
  28148. var texcoordAttr = this.attributes.texcoord0;
  28149. var normalAttr = this.attributes.normal;
  28150. var vertexCount = (widthSegments + 1) * (heightSegments + 1);
  28151. positionAttr.init(vertexCount);
  28152. texcoordAttr.init(vertexCount);
  28153. normalAttr.init(vertexCount);
  28154. var IndicesCtor = vertexCount > 0xffff ? Uint32Array : Uint16Array;
  28155. var indices = this.indices = new IndicesCtor(widthSegments * heightSegments * 6);
  28156. var x, y, z,
  28157. u, v,
  28158. i, j;
  28159. var radius = this.radius;
  28160. var phiStart = this.phiStart;
  28161. var phiLength = this.phiLength;
  28162. var thetaStart = this.thetaStart;
  28163. var thetaLength = this.thetaLength;
  28164. var radius = this.radius;
  28165. var pos = [];
  28166. var uv = [];
  28167. var offset = 0;
  28168. var divider = 1 / radius;
  28169. for (j = 0; j <= heightSegments; j++) {
  28170. for (i = 0; i <= widthSegments; i++) {
  28171. u = i / widthSegments;
  28172. v = j / heightSegments;
  28173. // X axis is inverted so texture can be mapped from left to right
  28174. x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  28175. y = radius * Math.cos(thetaStart + v * thetaLength);
  28176. z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  28177. pos[0] = x; pos[1] = y; pos[2] = z;
  28178. uv[0] = u; uv[1] = v;
  28179. positionAttr.set(offset, pos);
  28180. texcoordAttr.set(offset, uv);
  28181. pos[0] *= divider;
  28182. pos[1] *= divider;
  28183. pos[2] *= divider;
  28184. normalAttr.set(offset, pos);
  28185. offset++;
  28186. }
  28187. }
  28188. var i1, i2, i3, i4;
  28189. var len = widthSegments + 1;
  28190. var n = 0;
  28191. for (j = 0; j < heightSegments; j++) {
  28192. for (i = 0; i < widthSegments; i++) {
  28193. i2 = j * len + i;
  28194. i1 = (j * len + i + 1);
  28195. i4 = (j + 1) * len + i + 1;
  28196. i3 = (j + 1) * len + i;
  28197. indices[n++] = i1;
  28198. indices[n++] = i2;
  28199. indices[n++] = i4;
  28200. indices[n++] = i2;
  28201. indices[n++] = i3;
  28202. indices[n++] = i4;
  28203. }
  28204. }
  28205. this.boundingBox = new __WEBPACK_IMPORTED_MODULE_1__math_BoundingBox__["a" /* default */]();
  28206. this.boundingBox.max.set(radius, radius, radius);
  28207. this.boundingBox.min.set(-radius, -radius, -radius);
  28208. }
  28209. });
  28210. /* harmony default export */ __webpack_exports__["a"] = (Sphere);
  28211. /***/
  28212. }),
  28213. /* 133 */
  28214. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  28215. "use strict";
  28216. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Light__ = __webpack_require__(24);
  28217. /**
  28218. * @constructor clay.light.Ambient
  28219. * @extends clay.Light
  28220. */
  28221. var AmbientLight = __WEBPACK_IMPORTED_MODULE_0__Light__["a" /* default */].extend({
  28222. castShadow: false
  28223. }, {
  28224. type: 'AMBIENT_LIGHT',
  28225. uniformTemplates: {
  28226. ambientLightColor: {
  28227. type: '3f',
  28228. value: function (instance) {
  28229. var color = instance.color;
  28230. var intensity = instance.intensity;
  28231. return [color[0] * intensity, color[1] * intensity, color[2] * intensity];
  28232. }
  28233. }
  28234. }
  28235. /**
  28236. * @function
  28237. * @name clone
  28238. * @return {clay.light.Ambient}
  28239. * @memberOf clay.light.Ambient.prototype
  28240. */
  28241. });
  28242. /* harmony default export */ __webpack_exports__["a"] = (AmbientLight);
  28243. /***/
  28244. }),
  28245. /* 134 */
  28246. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  28247. "use strict";
  28248. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Light__ = __webpack_require__(24);
  28249. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__math_Vector3__ = __webpack_require__(3);
  28250. /**
  28251. * @constructor clay.light.Directional
  28252. * @extends clay.Light
  28253. *
  28254. * @example
  28255. * var light = new clay.light.Directional({
  28256. * intensity: 0.5,
  28257. * color: [1.0, 0.0, 0.0]
  28258. * });
  28259. * light.position.set(10, 10, 10);
  28260. * light.lookAt(clay.Vector3.ZERO);
  28261. * scene.add(light);
  28262. */
  28263. var DirectionalLight = __WEBPACK_IMPORTED_MODULE_0__Light__["a" /* default */].extend(/** @lends clay.light.Directional# */ {
  28264. /**
  28265. * @type {number}
  28266. */
  28267. shadowBias: 0.001,
  28268. /**
  28269. * @type {number}
  28270. */
  28271. shadowSlopeScale: 2.0,
  28272. /**
  28273. * Shadow cascade.
  28274. * Use PSSM technique when it is larger than 1 and have a unique directional light in scene.
  28275. * @type {number}
  28276. */
  28277. shadowCascade: 1,
  28278. /**
  28279. * Available when shadowCascade is larger than 1 and have a unique directional light in scene.
  28280. * @type {number}
  28281. */
  28282. cascadeSplitLogFactor: 0.2
  28283. }, {
  28284. type: 'DIRECTIONAL_LIGHT',
  28285. uniformTemplates: {
  28286. directionalLightDirection: {
  28287. type: '3f',
  28288. value: function (instance) {
  28289. instance.__dir = instance.__dir || new __WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */]();
  28290. // Direction is target to eye
  28291. return instance.__dir.copy(instance.worldTransform.z).normalize().negate().array;
  28292. }
  28293. },
  28294. directionalLightColor: {
  28295. type: '3f',
  28296. value: function (instance) {
  28297. var color = instance.color;
  28298. var intensity = instance.intensity;
  28299. return [color[0] * intensity, color[1] * intensity, color[2] * intensity];
  28300. }
  28301. }
  28302. },
  28303. /**
  28304. * @return {clay.light.Directional}
  28305. * @memberOf clay.light.Directional.prototype
  28306. */
  28307. clone: function () {
  28308. var light = __WEBPACK_IMPORTED_MODULE_0__Light__["a" /* default */].prototype.clone.call(this);
  28309. light.shadowBias = this.shadowBias;
  28310. light.shadowSlopeScale = this.shadowSlopeScale;
  28311. return light;
  28312. }
  28313. });
  28314. /* harmony default export */ __webpack_exports__["a"] = (DirectionalLight);
  28315. /***/
  28316. }),
  28317. /* 135 */
  28318. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  28319. "use strict";
  28320. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Light__ = __webpack_require__(24);
  28321. /**
  28322. * @constructor clay.light.Point
  28323. * @extends clay.Light
  28324. */
  28325. var PointLight = __WEBPACK_IMPORTED_MODULE_0__Light__["a" /* default */].extend(/** @lends clay.light.Point# */ {
  28326. /**
  28327. * @type {number}
  28328. */
  28329. range: 100,
  28330. /**
  28331. * @type {number}
  28332. */
  28333. castShadow: false
  28334. }, {
  28335. type: 'POINT_LIGHT',
  28336. uniformTemplates: {
  28337. pointLightPosition: {
  28338. type: '3f',
  28339. value: function (instance) {
  28340. return instance.getWorldPosition().array;
  28341. }
  28342. },
  28343. pointLightRange: {
  28344. type: '1f',
  28345. value: function (instance) {
  28346. return instance.range;
  28347. }
  28348. },
  28349. pointLightColor: {
  28350. type: '3f',
  28351. value: function (instance) {
  28352. var color = instance.color;
  28353. var intensity = instance.intensity;
  28354. return [color[0] * intensity, color[1] * intensity, color[2] * intensity];
  28355. }
  28356. }
  28357. },
  28358. /**
  28359. * @return {clay.light.Point}
  28360. * @memberOf clay.light.Point.prototype
  28361. */
  28362. clone: function () {
  28363. var light = __WEBPACK_IMPORTED_MODULE_0__Light__["a" /* default */].prototype.clone.call(this);
  28364. light.range = this.range;
  28365. return light;
  28366. }
  28367. });
  28368. /* harmony default export */ __webpack_exports__["a"] = (PointLight);
  28369. /***/
  28370. }),
  28371. /* 136 */
  28372. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  28373. "use strict";
  28374. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Light__ = __webpack_require__(24);
  28375. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__math_Vector3__ = __webpack_require__(3);
  28376. /**
  28377. * @constructor clay.light.Spot
  28378. * @extends clay.Light
  28379. */
  28380. var SpotLight = __WEBPACK_IMPORTED_MODULE_0__Light__["a" /* default */].extend(/**@lends clay.light.Spot */ {
  28381. /**
  28382. * @type {number}
  28383. */
  28384. range: 20,
  28385. /**
  28386. * @type {number}
  28387. */
  28388. umbraAngle: 30,
  28389. /**
  28390. * @type {number}
  28391. */
  28392. penumbraAngle: 45,
  28393. /**
  28394. * @type {number}
  28395. */
  28396. falloffFactor: 2.0,
  28397. /**
  28398. * @type {number}
  28399. */
  28400. shadowBias: 0.001,
  28401. /**
  28402. * @type {number}
  28403. */
  28404. shadowSlopeScale: 2.0
  28405. }, {
  28406. type: 'SPOT_LIGHT',
  28407. uniformTemplates: {
  28408. spotLightPosition: {
  28409. type: '3f',
  28410. value: function (instance) {
  28411. return instance.getWorldPosition().array;
  28412. }
  28413. },
  28414. spotLightRange: {
  28415. type: '1f',
  28416. value: function (instance) {
  28417. return instance.range;
  28418. }
  28419. },
  28420. spotLightUmbraAngleCosine: {
  28421. type: '1f',
  28422. value: function (instance) {
  28423. return Math.cos(instance.umbraAngle * Math.PI / 180);
  28424. }
  28425. },
  28426. spotLightPenumbraAngleCosine: {
  28427. type: '1f',
  28428. value: function (instance) {
  28429. return Math.cos(instance.penumbraAngle * Math.PI / 180);
  28430. }
  28431. },
  28432. spotLightFalloffFactor: {
  28433. type: '1f',
  28434. value: function (instance) {
  28435. return instance.falloffFactor;
  28436. }
  28437. },
  28438. spotLightDirection: {
  28439. type: '3f',
  28440. value: function (instance) {
  28441. instance.__dir = instance.__dir || new __WEBPACK_IMPORTED_MODULE_1__math_Vector3__["a" /* default */]();
  28442. // Direction is target to eye
  28443. return instance.__dir.copy(instance.worldTransform.z).negate().array;
  28444. }
  28445. },
  28446. spotLightColor: {
  28447. type: '3f',
  28448. value: function (instance) {
  28449. var color = instance.color;
  28450. var intensity = instance.intensity;
  28451. return [color[0] * intensity, color[1] * intensity, color[2] * intensity];
  28452. }
  28453. }
  28454. },
  28455. /**
  28456. * @return {clay.light.Spot}
  28457. * @memberOf clay.light.Spot.prototype
  28458. */
  28459. clone: function () {
  28460. var light = __WEBPACK_IMPORTED_MODULE_0__Light__["a" /* default */].prototype.clone.call(this);
  28461. light.range = this.range;
  28462. light.umbraAngle = this.umbraAngle;
  28463. light.penumbraAngle = this.penumbraAngle;
  28464. light.falloffFactor = this.falloffFactor;
  28465. light.shadowBias = this.shadowBias;
  28466. light.shadowSlopeScale = this.shadowSlopeScale;
  28467. return light;
  28468. }
  28469. });
  28470. /* harmony default export */ __webpack_exports__["a"] = (SpotLight);
  28471. /***/
  28472. }),
  28473. /* 137 */
  28474. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  28475. "use strict";
  28476. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__ = __webpack_require__(33);
  28477. /**
  28478. * @constructor
  28479. * @alias clay.Vector4
  28480. * @param {number} x
  28481. * @param {number} y
  28482. * @param {number} z
  28483. * @param {number} w
  28484. */
  28485. var Vector4 = function (x, y, z, w) {
  28486. x = x || 0;
  28487. y = y || 0;
  28488. z = z || 0;
  28489. w = w || 0;
  28490. /**
  28491. * Storage of Vector4, read and write of x, y, z, w will change the values in array
  28492. * All methods also operate on the array instead of x, y, z, w components
  28493. * @name array
  28494. * @type {Float32Array}
  28495. * @memberOf clay.Vector4#
  28496. */
  28497. this.array = __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].fromValues(x, y, z, w);
  28498. /**
  28499. * Dirty flag is used by the Node to determine
  28500. * if the matrix is updated to latest
  28501. * @name _dirty
  28502. * @type {boolean}
  28503. * @memberOf clay.Vector4#
  28504. */
  28505. this._dirty = true;
  28506. };
  28507. Vector4.prototype = {
  28508. constructor: Vector4,
  28509. /**
  28510. * Add b to self
  28511. * @param {clay.Vector4} b
  28512. * @return {clay.Vector4}
  28513. */
  28514. add: function (b) {
  28515. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].add(this.array, this.array, b.array);
  28516. this._dirty = true;
  28517. return this;
  28518. },
  28519. /**
  28520. * Set x, y and z components
  28521. * @param {number} x
  28522. * @param {number} y
  28523. * @param {number} z
  28524. * @param {number} w
  28525. * @return {clay.Vector4}
  28526. */
  28527. set: function (x, y, z, w) {
  28528. this.array[0] = x;
  28529. this.array[1] = y;
  28530. this.array[2] = z;
  28531. this.array[3] = w;
  28532. this._dirty = true;
  28533. return this;
  28534. },
  28535. /**
  28536. * Set x, y, z and w components from array
  28537. * @param {Float32Array|number[]} arr
  28538. * @return {clay.Vector4}
  28539. */
  28540. setArray: function (arr) {
  28541. this.array[0] = arr[0];
  28542. this.array[1] = arr[1];
  28543. this.array[2] = arr[2];
  28544. this.array[3] = arr[3];
  28545. this._dirty = true;
  28546. return this;
  28547. },
  28548. /**
  28549. * Clone a new Vector4
  28550. * @return {clay.Vector4}
  28551. */
  28552. clone: function () {
  28553. return new Vector4(this.x, this.y, this.z, this.w);
  28554. },
  28555. /**
  28556. * Copy from b
  28557. * @param {clay.Vector4} b
  28558. * @return {clay.Vector4}
  28559. */
  28560. copy: function (b) {
  28561. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].copy(this.array, b.array);
  28562. this._dirty = true;
  28563. return this;
  28564. },
  28565. /**
  28566. * Alias for distance
  28567. * @param {clay.Vector4} b
  28568. * @return {number}
  28569. */
  28570. dist: function (b) {
  28571. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].dist(this.array, b.array);
  28572. },
  28573. /**
  28574. * Distance between self and b
  28575. * @param {clay.Vector4} b
  28576. * @return {number}
  28577. */
  28578. distance: function (b) {
  28579. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].distance(this.array, b.array);
  28580. },
  28581. /**
  28582. * Alias for divide
  28583. * @param {clay.Vector4} b
  28584. * @return {clay.Vector4}
  28585. */
  28586. div: function (b) {
  28587. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].div(this.array, this.array, b.array);
  28588. this._dirty = true;
  28589. return this;
  28590. },
  28591. /**
  28592. * Divide self by b
  28593. * @param {clay.Vector4} b
  28594. * @return {clay.Vector4}
  28595. */
  28596. divide: function (b) {
  28597. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].divide(this.array, this.array, b.array);
  28598. this._dirty = true;
  28599. return this;
  28600. },
  28601. /**
  28602. * Dot product of self and b
  28603. * @param {clay.Vector4} b
  28604. * @return {number}
  28605. */
  28606. dot: function (b) {
  28607. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].dot(this.array, b.array);
  28608. },
  28609. /**
  28610. * Alias of length
  28611. * @return {number}
  28612. */
  28613. len: function () {
  28614. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].len(this.array);
  28615. },
  28616. /**
  28617. * Calculate the length
  28618. * @return {number}
  28619. */
  28620. length: function () {
  28621. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].length(this.array);
  28622. },
  28623. /**
  28624. * Linear interpolation between a and b
  28625. * @param {clay.Vector4} a
  28626. * @param {clay.Vector4} b
  28627. * @param {number} t
  28628. * @return {clay.Vector4}
  28629. */
  28630. lerp: function (a, b, t) {
  28631. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].lerp(this.array, a.array, b.array, t);
  28632. this._dirty = true;
  28633. return this;
  28634. },
  28635. /**
  28636. * Minimum of self and b
  28637. * @param {clay.Vector4} b
  28638. * @return {clay.Vector4}
  28639. */
  28640. min: function (b) {
  28641. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].min(this.array, this.array, b.array);
  28642. this._dirty = true;
  28643. return this;
  28644. },
  28645. /**
  28646. * Maximum of self and b
  28647. * @param {clay.Vector4} b
  28648. * @return {clay.Vector4}
  28649. */
  28650. max: function (b) {
  28651. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].max(this.array, this.array, b.array);
  28652. this._dirty = true;
  28653. return this;
  28654. },
  28655. /**
  28656. * Alias for multiply
  28657. * @param {clay.Vector4} b
  28658. * @return {clay.Vector4}
  28659. */
  28660. mul: function (b) {
  28661. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].mul(this.array, this.array, b.array);
  28662. this._dirty = true;
  28663. return this;
  28664. },
  28665. /**
  28666. * Mutiply self and b
  28667. * @param {clay.Vector4} b
  28668. * @return {clay.Vector4}
  28669. */
  28670. multiply: function (b) {
  28671. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].multiply(this.array, this.array, b.array);
  28672. this._dirty = true;
  28673. return this;
  28674. },
  28675. /**
  28676. * Negate self
  28677. * @return {clay.Vector4}
  28678. */
  28679. negate: function () {
  28680. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].negate(this.array, this.array);
  28681. this._dirty = true;
  28682. return this;
  28683. },
  28684. /**
  28685. * Normalize self
  28686. * @return {clay.Vector4}
  28687. */
  28688. normalize: function () {
  28689. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].normalize(this.array, this.array);
  28690. this._dirty = true;
  28691. return this;
  28692. },
  28693. /**
  28694. * Generate random x, y, z, w components with a given scale
  28695. * @param {number} scale
  28696. * @return {clay.Vector4}
  28697. */
  28698. random: function (scale) {
  28699. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].random(this.array, scale);
  28700. this._dirty = true;
  28701. return this;
  28702. },
  28703. /**
  28704. * Scale self
  28705. * @param {number} scale
  28706. * @return {clay.Vector4}
  28707. */
  28708. scale: function (s) {
  28709. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].scale(this.array, this.array, s);
  28710. this._dirty = true;
  28711. return this;
  28712. },
  28713. /**
  28714. * Scale b and add to self
  28715. * @param {clay.Vector4} b
  28716. * @param {number} scale
  28717. * @return {clay.Vector4}
  28718. */
  28719. scaleAndAdd: function (b, s) {
  28720. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].scaleAndAdd(this.array, this.array, b.array, s);
  28721. this._dirty = true;
  28722. return this;
  28723. },
  28724. /**
  28725. * Alias for squaredDistance
  28726. * @param {clay.Vector4} b
  28727. * @return {number}
  28728. */
  28729. sqrDist: function (b) {
  28730. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].sqrDist(this.array, b.array);
  28731. },
  28732. /**
  28733. * Squared distance between self and b
  28734. * @param {clay.Vector4} b
  28735. * @return {number}
  28736. */
  28737. squaredDistance: function (b) {
  28738. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].squaredDistance(this.array, b.array);
  28739. },
  28740. /**
  28741. * Alias for squaredLength
  28742. * @return {number}
  28743. */
  28744. sqrLen: function () {
  28745. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].sqrLen(this.array);
  28746. },
  28747. /**
  28748. * Squared length of self
  28749. * @return {number}
  28750. */
  28751. squaredLength: function () {
  28752. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].squaredLength(this.array);
  28753. },
  28754. /**
  28755. * Alias for subtract
  28756. * @param {clay.Vector4} b
  28757. * @return {clay.Vector4}
  28758. */
  28759. sub: function (b) {
  28760. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].sub(this.array, this.array, b.array);
  28761. this._dirty = true;
  28762. return this;
  28763. },
  28764. /**
  28765. * Subtract b from self
  28766. * @param {clay.Vector4} b
  28767. * @return {clay.Vector4}
  28768. */
  28769. subtract: function (b) {
  28770. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].subtract(this.array, this.array, b.array);
  28771. this._dirty = true;
  28772. return this;
  28773. },
  28774. /**
  28775. * Transform self with a Matrix4 m
  28776. * @param {clay.Matrix4} m
  28777. * @return {clay.Vector4}
  28778. */
  28779. transformMat4: function (m) {
  28780. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].transformMat4(this.array, this.array, m.array);
  28781. this._dirty = true;
  28782. return this;
  28783. },
  28784. /**
  28785. * Transform self with a Quaternion q
  28786. * @param {clay.Quaternion} q
  28787. * @return {clay.Vector4}
  28788. */
  28789. transformQuat: function (q) {
  28790. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].transformQuat(this.array, this.array, q.array);
  28791. this._dirty = true;
  28792. return this;
  28793. },
  28794. toString: function () {
  28795. return '[' + Array.prototype.join.call(this.array, ',') + ']';
  28796. },
  28797. toArray: function () {
  28798. return Array.prototype.slice.call(this.array);
  28799. }
  28800. };
  28801. var defineProperty = Object.defineProperty;
  28802. // Getter and Setter
  28803. if (defineProperty) {
  28804. var proto = Vector4.prototype;
  28805. /**
  28806. * @name x
  28807. * @type {number}
  28808. * @memberOf clay.Vector4
  28809. * @instance
  28810. */
  28811. defineProperty(proto, 'x', {
  28812. get: function () {
  28813. return this.array[0];
  28814. },
  28815. set: function (value) {
  28816. this.array[0] = value;
  28817. this._dirty = true;
  28818. }
  28819. });
  28820. /**
  28821. * @name y
  28822. * @type {number}
  28823. * @memberOf clay.Vector4
  28824. * @instance
  28825. */
  28826. defineProperty(proto, 'y', {
  28827. get: function () {
  28828. return this.array[1];
  28829. },
  28830. set: function (value) {
  28831. this.array[1] = value;
  28832. this._dirty = true;
  28833. }
  28834. });
  28835. /**
  28836. * @name z
  28837. * @type {number}
  28838. * @memberOf clay.Vector4
  28839. * @instance
  28840. */
  28841. defineProperty(proto, 'z', {
  28842. get: function () {
  28843. return this.array[2];
  28844. },
  28845. set: function (value) {
  28846. this.array[2] = value;
  28847. this._dirty = true;
  28848. }
  28849. });
  28850. /**
  28851. * @name w
  28852. * @type {number}
  28853. * @memberOf clay.Vector4
  28854. * @instance
  28855. */
  28856. defineProperty(proto, 'w', {
  28857. get: function () {
  28858. return this.array[3];
  28859. },
  28860. set: function (value) {
  28861. this.array[3] = value;
  28862. this._dirty = true;
  28863. }
  28864. });
  28865. }
  28866. // Supply methods that are not in place
  28867. /**
  28868. * @param {clay.Vector4} out
  28869. * @param {clay.Vector4} a
  28870. * @param {clay.Vector4} b
  28871. * @return {clay.Vector4}
  28872. */
  28873. Vector4.add = function (out, a, b) {
  28874. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].add(out.array, a.array, b.array);
  28875. out._dirty = true;
  28876. return out;
  28877. };
  28878. /**
  28879. * @param {clay.Vector4} out
  28880. * @param {number} x
  28881. * @param {number} y
  28882. * @param {number} z
  28883. * @return {clay.Vector4}
  28884. */
  28885. Vector4.set = function (out, x, y, z, w) {
  28886. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].set(out.array, x, y, z, w);
  28887. out._dirty = true;
  28888. };
  28889. /**
  28890. * @param {clay.Vector4} out
  28891. * @param {clay.Vector4} b
  28892. * @return {clay.Vector4}
  28893. */
  28894. Vector4.copy = function (out, b) {
  28895. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].copy(out.array, b.array);
  28896. out._dirty = true;
  28897. return out;
  28898. };
  28899. /**
  28900. * @param {clay.Vector4} a
  28901. * @param {clay.Vector4} b
  28902. * @return {number}
  28903. */
  28904. Vector4.dist = function (a, b) {
  28905. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].distance(a.array, b.array);
  28906. };
  28907. /**
  28908. * @function
  28909. * @param {clay.Vector4} a
  28910. * @param {clay.Vector4} b
  28911. * @return {number}
  28912. */
  28913. Vector4.distance = Vector4.dist;
  28914. /**
  28915. * @param {clay.Vector4} out
  28916. * @param {clay.Vector4} a
  28917. * @param {clay.Vector4} b
  28918. * @return {clay.Vector4}
  28919. */
  28920. Vector4.div = function (out, a, b) {
  28921. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].divide(out.array, a.array, b.array);
  28922. out._dirty = true;
  28923. return out;
  28924. };
  28925. /**
  28926. * @function
  28927. * @param {clay.Vector4} out
  28928. * @param {clay.Vector4} a
  28929. * @param {clay.Vector4} b
  28930. * @return {clay.Vector4}
  28931. */
  28932. Vector4.divide = Vector4.div;
  28933. /**
  28934. * @param {clay.Vector4} a
  28935. * @param {clay.Vector4} b
  28936. * @return {number}
  28937. */
  28938. Vector4.dot = function (a, b) {
  28939. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].dot(a.array, b.array);
  28940. };
  28941. /**
  28942. * @param {clay.Vector4} a
  28943. * @return {number}
  28944. */
  28945. Vector4.len = function (b) {
  28946. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].length(b.array);
  28947. };
  28948. // Vector4.length = Vector4.len;
  28949. /**
  28950. * @param {clay.Vector4} out
  28951. * @param {clay.Vector4} a
  28952. * @param {clay.Vector4} b
  28953. * @param {number} t
  28954. * @return {clay.Vector4}
  28955. */
  28956. Vector4.lerp = function (out, a, b, t) {
  28957. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].lerp(out.array, a.array, b.array, t);
  28958. out._dirty = true;
  28959. return out;
  28960. };
  28961. /**
  28962. * @param {clay.Vector4} out
  28963. * @param {clay.Vector4} a
  28964. * @param {clay.Vector4} b
  28965. * @return {clay.Vector4}
  28966. */
  28967. Vector4.min = function (out, a, b) {
  28968. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].min(out.array, a.array, b.array);
  28969. out._dirty = true;
  28970. return out;
  28971. };
  28972. /**
  28973. * @param {clay.Vector4} out
  28974. * @param {clay.Vector4} a
  28975. * @param {clay.Vector4} b
  28976. * @return {clay.Vector4}
  28977. */
  28978. Vector4.max = function (out, a, b) {
  28979. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].max(out.array, a.array, b.array);
  28980. out._dirty = true;
  28981. return out;
  28982. };
  28983. /**
  28984. * @param {clay.Vector4} out
  28985. * @param {clay.Vector4} a
  28986. * @param {clay.Vector4} b
  28987. * @return {clay.Vector4}
  28988. */
  28989. Vector4.mul = function (out, a, b) {
  28990. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].multiply(out.array, a.array, b.array);
  28991. out._dirty = true;
  28992. return out;
  28993. };
  28994. /**
  28995. * @function
  28996. * @param {clay.Vector4} out
  28997. * @param {clay.Vector4} a
  28998. * @param {clay.Vector4} b
  28999. * @return {clay.Vector4}
  29000. */
  29001. Vector4.multiply = Vector4.mul;
  29002. /**
  29003. * @param {clay.Vector4} out
  29004. * @param {clay.Vector4} a
  29005. * @return {clay.Vector4}
  29006. */
  29007. Vector4.negate = function (out, a) {
  29008. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].negate(out.array, a.array);
  29009. out._dirty = true;
  29010. return out;
  29011. };
  29012. /**
  29013. * @param {clay.Vector4} out
  29014. * @param {clay.Vector4} a
  29015. * @return {clay.Vector4}
  29016. */
  29017. Vector4.normalize = function (out, a) {
  29018. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].normalize(out.array, a.array);
  29019. out._dirty = true;
  29020. return out;
  29021. };
  29022. /**
  29023. * @param {clay.Vector4} out
  29024. * @param {number} scale
  29025. * @return {clay.Vector4}
  29026. */
  29027. Vector4.random = function (out, scale) {
  29028. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].random(out.array, scale);
  29029. out._dirty = true;
  29030. return out;
  29031. };
  29032. /**
  29033. * @param {clay.Vector4} out
  29034. * @param {clay.Vector4} a
  29035. * @param {number} scale
  29036. * @return {clay.Vector4}
  29037. */
  29038. Vector4.scale = function (out, a, scale) {
  29039. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].scale(out.array, a.array, scale);
  29040. out._dirty = true;
  29041. return out;
  29042. };
  29043. /**
  29044. * @param {clay.Vector4} out
  29045. * @param {clay.Vector4} a
  29046. * @param {clay.Vector4} b
  29047. * @param {number} scale
  29048. * @return {clay.Vector4}
  29049. */
  29050. Vector4.scaleAndAdd = function (out, a, b, scale) {
  29051. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].scaleAndAdd(out.array, a.array, b.array, scale);
  29052. out._dirty = true;
  29053. return out;
  29054. };
  29055. /**
  29056. * @param {clay.Vector4} a
  29057. * @param {clay.Vector4} b
  29058. * @return {number}
  29059. */
  29060. Vector4.sqrDist = function (a, b) {
  29061. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].sqrDist(a.array, b.array);
  29062. };
  29063. /**
  29064. * @function
  29065. * @param {clay.Vector4} a
  29066. * @param {clay.Vector4} b
  29067. * @return {number}
  29068. */
  29069. Vector4.squaredDistance = Vector4.sqrDist;
  29070. /**
  29071. * @param {clay.Vector4} a
  29072. * @return {number}
  29073. */
  29074. Vector4.sqrLen = function (a) {
  29075. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].sqrLen(a.array);
  29076. };
  29077. /**
  29078. * @function
  29079. * @param {clay.Vector4} a
  29080. * @return {number}
  29081. */
  29082. Vector4.squaredLength = Vector4.sqrLen;
  29083. /**
  29084. * @param {clay.Vector4} out
  29085. * @param {clay.Vector4} a
  29086. * @param {clay.Vector4} b
  29087. * @return {clay.Vector4}
  29088. */
  29089. Vector4.sub = function (out, a, b) {
  29090. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].subtract(out.array, a.array, b.array);
  29091. out._dirty = true;
  29092. return out;
  29093. };
  29094. /**
  29095. * @function
  29096. * @param {clay.Vector4} out
  29097. * @param {clay.Vector4} a
  29098. * @param {clay.Vector4} b
  29099. * @return {clay.Vector4}
  29100. */
  29101. Vector4.subtract = Vector4.sub;
  29102. /**
  29103. * @param {clay.Vector4} out
  29104. * @param {clay.Vector4} a
  29105. * @param {clay.Matrix4} m
  29106. * @return {clay.Vector4}
  29107. */
  29108. Vector4.transformMat4 = function (out, a, m) {
  29109. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].transformMat4(out.array, a.array, m.array);
  29110. out._dirty = true;
  29111. return out;
  29112. };
  29113. /**
  29114. * @param {clay.Vector4} out
  29115. * @param {clay.Vector4} a
  29116. * @param {clay.Quaternion} q
  29117. * @return {clay.Vector4}
  29118. */
  29119. Vector4.transformQuat = function (out, a, q) {
  29120. __WEBPACK_IMPORTED_MODULE_0__glmatrix_vec4__["a" /* default */].transformQuat(out.array, a.array, q.array);
  29121. out._dirty = true;
  29122. return out;
  29123. };
  29124. /* harmony default export */ __webpack_exports__["a"] = (Vector4);
  29125. /***/
  29126. }),
  29127. /* 138 */
  29128. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  29129. "use strict";
  29130. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__ = __webpack_require__(78);
  29131. /**
  29132. * @constructor
  29133. * @alias clay.Matrix2
  29134. */
  29135. var Matrix2 = function () {
  29136. /**
  29137. * Storage of Matrix2
  29138. * @name array
  29139. * @type {Float32Array}
  29140. * @memberOf clay.Matrix2#
  29141. */
  29142. this.array = __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].create();
  29143. /**
  29144. * @name _dirty
  29145. * @type {boolean}
  29146. * @memberOf clay.Matrix2#
  29147. */
  29148. this._dirty = true;
  29149. };
  29150. Matrix2.prototype = {
  29151. constructor: Matrix2,
  29152. /**
  29153. * Set components from array
  29154. * @param {Float32Array|number[]} arr
  29155. */
  29156. setArray: function (arr) {
  29157. for (var i = 0; i < this.array.length; i++) {
  29158. this.array[i] = arr[i];
  29159. }
  29160. this._dirty = true;
  29161. return this;
  29162. },
  29163. /**
  29164. * Clone a new Matrix2
  29165. * @return {clay.Matrix2}
  29166. */
  29167. clone: function () {
  29168. return (new Matrix2()).copy(this);
  29169. },
  29170. /**
  29171. * Copy from b
  29172. * @param {clay.Matrix2} b
  29173. * @return {clay.Matrix2}
  29174. */
  29175. copy: function (b) {
  29176. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].copy(this.array, b.array);
  29177. this._dirty = true;
  29178. return this;
  29179. },
  29180. /**
  29181. * Calculate the adjugate of self, in-place
  29182. * @return {clay.Matrix2}
  29183. */
  29184. adjoint: function () {
  29185. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].adjoint(this.array, this.array);
  29186. this._dirty = true;
  29187. return this;
  29188. },
  29189. /**
  29190. * Calculate matrix determinant
  29191. * @return {number}
  29192. */
  29193. determinant: function () {
  29194. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].determinant(this.array);
  29195. },
  29196. /**
  29197. * Set to a identity matrix
  29198. * @return {clay.Matrix2}
  29199. */
  29200. identity: function () {
  29201. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].identity(this.array);
  29202. this._dirty = true;
  29203. return this;
  29204. },
  29205. /**
  29206. * Invert self
  29207. * @return {clay.Matrix2}
  29208. */
  29209. invert: function () {
  29210. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].invert(this.array, this.array);
  29211. this._dirty = true;
  29212. return this;
  29213. },
  29214. /**
  29215. * Alias for mutiply
  29216. * @param {clay.Matrix2} b
  29217. * @return {clay.Matrix2}
  29218. */
  29219. mul: function (b) {
  29220. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].mul(this.array, this.array, b.array);
  29221. this._dirty = true;
  29222. return this;
  29223. },
  29224. /**
  29225. * Alias for multiplyLeft
  29226. * @param {clay.Matrix2} a
  29227. * @return {clay.Matrix2}
  29228. */
  29229. mulLeft: function (a) {
  29230. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].mul(this.array, a.array, this.array);
  29231. this._dirty = true;
  29232. return this;
  29233. },
  29234. /**
  29235. * Multiply self and b
  29236. * @param {clay.Matrix2} b
  29237. * @return {clay.Matrix2}
  29238. */
  29239. multiply: function (b) {
  29240. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].multiply(this.array, this.array, b.array);
  29241. this._dirty = true;
  29242. return this;
  29243. },
  29244. /**
  29245. * Multiply a and self, a is on the left
  29246. * @param {clay.Matrix2} a
  29247. * @return {clay.Matrix2}
  29248. */
  29249. multiplyLeft: function (a) {
  29250. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].multiply(this.array, a.array, this.array);
  29251. this._dirty = true;
  29252. return this;
  29253. },
  29254. /**
  29255. * Rotate self by a given radian
  29256. * @param {number} rad
  29257. * @return {clay.Matrix2}
  29258. */
  29259. rotate: function (rad) {
  29260. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].rotate(this.array, this.array, rad);
  29261. this._dirty = true;
  29262. return this;
  29263. },
  29264. /**
  29265. * Scale self by s
  29266. * @param {clay.Vector2} s
  29267. * @return {clay.Matrix2}
  29268. */
  29269. scale: function (v) {
  29270. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].scale(this.array, this.array, v.array);
  29271. this._dirty = true;
  29272. return this;
  29273. },
  29274. /**
  29275. * Transpose self, in-place.
  29276. * @return {clay.Matrix2}
  29277. */
  29278. transpose: function () {
  29279. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].transpose(this.array, this.array);
  29280. this._dirty = true;
  29281. return this;
  29282. },
  29283. toString: function () {
  29284. return '[' + Array.prototype.join.call(this.array, ',') + ']';
  29285. },
  29286. toArray: function () {
  29287. return Array.prototype.slice.call(this.array);
  29288. }
  29289. };
  29290. /**
  29291. * @param {Matrix2} out
  29292. * @param {Matrix2} a
  29293. * @return {Matrix2}
  29294. */
  29295. Matrix2.adjoint = function (out, a) {
  29296. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].adjoint(out.array, a.array);
  29297. out._dirty = true;
  29298. return out;
  29299. };
  29300. /**
  29301. * @param {clay.Matrix2} out
  29302. * @param {clay.Matrix2} a
  29303. * @return {clay.Matrix2}
  29304. */
  29305. Matrix2.copy = function (out, a) {
  29306. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].copy(out.array, a.array);
  29307. out._dirty = true;
  29308. return out;
  29309. };
  29310. /**
  29311. * @param {clay.Matrix2} a
  29312. * @return {number}
  29313. */
  29314. Matrix2.determinant = function (a) {
  29315. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].determinant(a.array);
  29316. };
  29317. /**
  29318. * @param {clay.Matrix2} out
  29319. * @return {clay.Matrix2}
  29320. */
  29321. Matrix2.identity = function (out) {
  29322. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].identity(out.array);
  29323. out._dirty = true;
  29324. return out;
  29325. };
  29326. /**
  29327. * @param {clay.Matrix2} out
  29328. * @param {clay.Matrix2} a
  29329. * @return {clay.Matrix2}
  29330. */
  29331. Matrix2.invert = function (out, a) {
  29332. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].invert(out.array, a.array);
  29333. out._dirty = true;
  29334. return out;
  29335. };
  29336. /**
  29337. * @param {clay.Matrix2} out
  29338. * @param {clay.Matrix2} a
  29339. * @param {clay.Matrix2} b
  29340. * @return {clay.Matrix2}
  29341. */
  29342. Matrix2.mul = function (out, a, b) {
  29343. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].mul(out.array, a.array, b.array);
  29344. out._dirty = true;
  29345. return out;
  29346. };
  29347. /**
  29348. * @function
  29349. * @param {clay.Matrix2} out
  29350. * @param {clay.Matrix2} a
  29351. * @param {clay.Matrix2} b
  29352. * @return {clay.Matrix2}
  29353. */
  29354. Matrix2.multiply = Matrix2.mul;
  29355. /**
  29356. * @param {clay.Matrix2} out
  29357. * @param {clay.Matrix2} a
  29358. * @param {number} rad
  29359. * @return {clay.Matrix2}
  29360. */
  29361. Matrix2.rotate = function (out, a, rad) {
  29362. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].rotate(out.array, a.array, rad);
  29363. out._dirty = true;
  29364. return out;
  29365. };
  29366. /**
  29367. * @param {clay.Matrix2} out
  29368. * @param {clay.Matrix2} a
  29369. * @param {clay.Vector2} v
  29370. * @return {clay.Matrix2}
  29371. */
  29372. Matrix2.scale = function (out, a, v) {
  29373. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].scale(out.array, a.array, v.array);
  29374. out._dirty = true;
  29375. return out;
  29376. };
  29377. /**
  29378. * @param {Matrix2} out
  29379. * @param {Matrix2} a
  29380. * @return {Matrix2}
  29381. */
  29382. Matrix2.transpose = function (out, a) {
  29383. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2__["a" /* default */].transpose(out.array, a.array);
  29384. out._dirty = true;
  29385. return out;
  29386. };
  29387. /* harmony default export */ __webpack_exports__["a"] = (Matrix2);
  29388. /***/
  29389. }),
  29390. /* 139 */
  29391. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  29392. "use strict";
  29393. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__ = __webpack_require__(79);
  29394. /**
  29395. * @constructor
  29396. * @alias clay.Matrix2d
  29397. */
  29398. var Matrix2d = function () {
  29399. /**
  29400. * Storage of Matrix2d
  29401. * @name array
  29402. * @type {Float32Array}
  29403. * @memberOf clay.Matrix2d#
  29404. */
  29405. this.array = __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].create();
  29406. /**
  29407. * @name _dirty
  29408. * @type {boolean}
  29409. * @memberOf clay.Matrix2d#
  29410. */
  29411. this._dirty = true;
  29412. };
  29413. Matrix2d.prototype = {
  29414. constructor: Matrix2d,
  29415. /**
  29416. * Set components from array
  29417. * @param {Float32Array|number[]} arr
  29418. */
  29419. setArray: function (arr) {
  29420. for (var i = 0; i < this.array.length; i++) {
  29421. this.array[i] = arr[i];
  29422. }
  29423. this._dirty = true;
  29424. return this;
  29425. },
  29426. /**
  29427. * Clone a new Matrix2d
  29428. * @return {clay.Matrix2d}
  29429. */
  29430. clone: function () {
  29431. return (new Matrix2d()).copy(this);
  29432. },
  29433. /**
  29434. * Copy from b
  29435. * @param {clay.Matrix2d} b
  29436. * @return {clay.Matrix2d}
  29437. */
  29438. copy: function (b) {
  29439. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].copy(this.array, b.array);
  29440. this._dirty = true;
  29441. return this;
  29442. },
  29443. /**
  29444. * Calculate matrix determinant
  29445. * @return {number}
  29446. */
  29447. determinant: function () {
  29448. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].determinant(this.array);
  29449. },
  29450. /**
  29451. * Set to a identity matrix
  29452. * @return {clay.Matrix2d}
  29453. */
  29454. identity: function () {
  29455. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].identity(this.array);
  29456. this._dirty = true;
  29457. return this;
  29458. },
  29459. /**
  29460. * Invert self
  29461. * @return {clay.Matrix2d}
  29462. */
  29463. invert: function () {
  29464. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].invert(this.array, this.array);
  29465. this._dirty = true;
  29466. return this;
  29467. },
  29468. /**
  29469. * Alias for mutiply
  29470. * @param {clay.Matrix2d} b
  29471. * @return {clay.Matrix2d}
  29472. */
  29473. mul: function (b) {
  29474. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].mul(this.array, this.array, b.array);
  29475. this._dirty = true;
  29476. return this;
  29477. },
  29478. /**
  29479. * Alias for multiplyLeft
  29480. * @param {clay.Matrix2d} a
  29481. * @return {clay.Matrix2d}
  29482. */
  29483. mulLeft: function (b) {
  29484. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].mul(this.array, b.array, this.array);
  29485. this._dirty = true;
  29486. return this;
  29487. },
  29488. /**
  29489. * Multiply self and b
  29490. * @param {clay.Matrix2d} b
  29491. * @return {clay.Matrix2d}
  29492. */
  29493. multiply: function (b) {
  29494. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].multiply(this.array, this.array, b.array);
  29495. this._dirty = true;
  29496. return this;
  29497. },
  29498. /**
  29499. * Multiply a and self, a is on the left
  29500. * @param {clay.Matrix2d} a
  29501. * @return {clay.Matrix2d}
  29502. */
  29503. multiplyLeft: function (b) {
  29504. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].multiply(this.array, b.array, this.array);
  29505. this._dirty = true;
  29506. return this;
  29507. },
  29508. /**
  29509. * Rotate self by a given radian
  29510. * @param {number} rad
  29511. * @return {clay.Matrix2d}
  29512. */
  29513. rotate: function (rad) {
  29514. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].rotate(this.array, this.array, rad);
  29515. this._dirty = true;
  29516. return this;
  29517. },
  29518. /**
  29519. * Scale self by s
  29520. * @param {clay.Vector2} s
  29521. * @return {clay.Matrix2d}
  29522. */
  29523. scale: function (s) {
  29524. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].scale(this.array, this.array, s.array);
  29525. this._dirty = true;
  29526. return this;
  29527. },
  29528. /**
  29529. * Translate self by v
  29530. * @param {clay.Vector2} v
  29531. * @return {clay.Matrix2d}
  29532. */
  29533. translate: function (v) {
  29534. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].translate(this.array, this.array, v.array);
  29535. this._dirty = true;
  29536. return this;
  29537. },
  29538. toString: function () {
  29539. return '[' + Array.prototype.join.call(this.array, ',') + ']';
  29540. },
  29541. toArray: function () {
  29542. return Array.prototype.slice.call(this.array);
  29543. }
  29544. };
  29545. /**
  29546. * @param {clay.Matrix2d} out
  29547. * @param {clay.Matrix2d} a
  29548. * @return {clay.Matrix2d}
  29549. */
  29550. Matrix2d.copy = function (out, a) {
  29551. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].copy(out.array, a.array);
  29552. out._dirty = true;
  29553. return out;
  29554. };
  29555. /**
  29556. * @param {clay.Matrix2d} a
  29557. * @return {number}
  29558. */
  29559. Matrix2d.determinant = function (a) {
  29560. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].determinant(a.array);
  29561. };
  29562. /**
  29563. * @param {clay.Matrix2d} out
  29564. * @return {clay.Matrix2d}
  29565. */
  29566. Matrix2d.identity = function (out) {
  29567. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].identity(out.array);
  29568. out._dirty = true;
  29569. return out;
  29570. };
  29571. /**
  29572. * @param {clay.Matrix2d} out
  29573. * @param {clay.Matrix2d} a
  29574. * @return {clay.Matrix2d}
  29575. */
  29576. Matrix2d.invert = function (out, a) {
  29577. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].invert(out.array, a.array);
  29578. out._dirty = true;
  29579. return out;
  29580. };
  29581. /**
  29582. * @param {clay.Matrix2d} out
  29583. * @param {clay.Matrix2d} a
  29584. * @param {clay.Matrix2d} b
  29585. * @return {clay.Matrix2d}
  29586. */
  29587. Matrix2d.mul = function (out, a, b) {
  29588. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].mul(out.array, a.array, b.array);
  29589. out._dirty = true;
  29590. return out;
  29591. };
  29592. /**
  29593. * @function
  29594. * @param {clay.Matrix2d} out
  29595. * @param {clay.Matrix2d} a
  29596. * @param {clay.Matrix2d} b
  29597. * @return {clay.Matrix2d}
  29598. */
  29599. Matrix2d.multiply = Matrix2d.mul;
  29600. /**
  29601. * @param {clay.Matrix2d} out
  29602. * @param {clay.Matrix2d} a
  29603. * @param {number} rad
  29604. * @return {clay.Matrix2d}
  29605. */
  29606. Matrix2d.rotate = function (out, a, rad) {
  29607. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].rotate(out.array, a.array, rad);
  29608. out._dirty = true;
  29609. return out;
  29610. };
  29611. /**
  29612. * @param {clay.Matrix2d} out
  29613. * @param {clay.Matrix2d} a
  29614. * @param {clay.Vector2} v
  29615. * @return {clay.Matrix2d}
  29616. */
  29617. Matrix2d.scale = function (out, a, v) {
  29618. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].scale(out.array, a.array, v.array);
  29619. out._dirty = true;
  29620. return out;
  29621. };
  29622. /**
  29623. * @param {clay.Matrix2d} out
  29624. * @param {clay.Matrix2d} a
  29625. * @param {clay.Vector2} v
  29626. * @return {clay.Matrix2d}
  29627. */
  29628. Matrix2d.translate = function (out, a, v) {
  29629. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat2d__["a" /* default */].translate(out.array, a.array, v.array);
  29630. out._dirty = true;
  29631. return out;
  29632. };
  29633. /* harmony default export */ __webpack_exports__["a"] = (Matrix2d);
  29634. /***/
  29635. }),
  29636. /* 140 */
  29637. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  29638. "use strict";
  29639. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__ = __webpack_require__(34);
  29640. /**
  29641. * @constructor
  29642. * @alias clay.Matrix3
  29643. */
  29644. var Matrix3 = function () {
  29645. /**
  29646. * Storage of Matrix3
  29647. * @name array
  29648. * @type {Float32Array}
  29649. * @memberOf clay.Matrix3#
  29650. */
  29651. this.array = __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].create();
  29652. /**
  29653. * @name _dirty
  29654. * @type {boolean}
  29655. * @memberOf clay.Matrix3#
  29656. */
  29657. this._dirty = true;
  29658. };
  29659. Matrix3.prototype = {
  29660. constructor: Matrix3,
  29661. /**
  29662. * Set components from array
  29663. * @param {Float32Array|number[]} arr
  29664. */
  29665. setArray: function (arr) {
  29666. for (var i = 0; i < this.array.length; i++) {
  29667. this.array[i] = arr[i];
  29668. }
  29669. this._dirty = true;
  29670. return this;
  29671. },
  29672. /**
  29673. * Calculate the adjugate of self, in-place
  29674. * @return {clay.Matrix3}
  29675. */
  29676. adjoint: function () {
  29677. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].adjoint(this.array, this.array);
  29678. this._dirty = true;
  29679. return this;
  29680. },
  29681. /**
  29682. * Clone a new Matrix3
  29683. * @return {clay.Matrix3}
  29684. */
  29685. clone: function () {
  29686. return (new Matrix3()).copy(this);
  29687. },
  29688. /**
  29689. * Copy from b
  29690. * @param {clay.Matrix3} b
  29691. * @return {clay.Matrix3}
  29692. */
  29693. copy: function (b) {
  29694. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].copy(this.array, b.array);
  29695. this._dirty = true;
  29696. return this;
  29697. },
  29698. /**
  29699. * Calculate matrix determinant
  29700. * @return {number}
  29701. */
  29702. determinant: function () {
  29703. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].determinant(this.array);
  29704. },
  29705. /**
  29706. * Copy the values from Matrix2d a
  29707. * @param {clay.Matrix2d} a
  29708. * @return {clay.Matrix3}
  29709. */
  29710. fromMat2d: function (a) {
  29711. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].fromMat2d(this.array, a.array);
  29712. this._dirty = true;
  29713. return this;
  29714. },
  29715. /**
  29716. * Copies the upper-left 3x3 values of Matrix4
  29717. * @param {clay.Matrix4} a
  29718. * @return {clay.Matrix3}
  29719. */
  29720. fromMat4: function (a) {
  29721. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].fromMat4(this.array, a.array);
  29722. this._dirty = true;
  29723. return this;
  29724. },
  29725. /**
  29726. * Calculates a rotation matrix from the given quaternion
  29727. * @param {clay.Quaternion} q
  29728. * @return {clay.Matrix3}
  29729. */
  29730. fromQuat: function (q) {
  29731. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].fromQuat(this.array, q.array);
  29732. this._dirty = true;
  29733. return this;
  29734. },
  29735. /**
  29736. * Set to a identity matrix
  29737. * @return {clay.Matrix3}
  29738. */
  29739. identity: function () {
  29740. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].identity(this.array);
  29741. this._dirty = true;
  29742. return this;
  29743. },
  29744. /**
  29745. * Invert self
  29746. * @return {clay.Matrix3}
  29747. */
  29748. invert: function () {
  29749. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].invert(this.array, this.array);
  29750. this._dirty = true;
  29751. return this;
  29752. },
  29753. /**
  29754. * Alias for mutiply
  29755. * @param {clay.Matrix3} b
  29756. * @return {clay.Matrix3}
  29757. */
  29758. mul: function (b) {
  29759. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].mul(this.array, this.array, b.array);
  29760. this._dirty = true;
  29761. return this;
  29762. },
  29763. /**
  29764. * Alias for multiplyLeft
  29765. * @param {clay.Matrix3} a
  29766. * @return {clay.Matrix3}
  29767. */
  29768. mulLeft: function (a) {
  29769. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].mul(this.array, a.array, this.array);
  29770. this._dirty = true;
  29771. return this;
  29772. },
  29773. /**
  29774. * Multiply self and b
  29775. * @param {clay.Matrix3} b
  29776. * @return {clay.Matrix3}
  29777. */
  29778. multiply: function (b) {
  29779. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].multiply(this.array, this.array, b.array);
  29780. this._dirty = true;
  29781. return this;
  29782. },
  29783. /**
  29784. * Multiply a and self, a is on the left
  29785. * @param {clay.Matrix3} a
  29786. * @return {clay.Matrix3}
  29787. */
  29788. multiplyLeft: function (a) {
  29789. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].multiply(this.array, a.array, this.array);
  29790. this._dirty = true;
  29791. return this;
  29792. },
  29793. /**
  29794. * Rotate self by a given radian
  29795. * @param {number} rad
  29796. * @return {clay.Matrix3}
  29797. */
  29798. rotate: function (rad) {
  29799. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].rotate(this.array, this.array, rad);
  29800. this._dirty = true;
  29801. return this;
  29802. },
  29803. /**
  29804. * Scale self by s
  29805. * @param {clay.Vector2} s
  29806. * @return {clay.Matrix3}
  29807. */
  29808. scale: function (v) {
  29809. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].scale(this.array, this.array, v.array);
  29810. this._dirty = true;
  29811. return this;
  29812. },
  29813. /**
  29814. * Translate self by v
  29815. * @param {clay.Vector2} v
  29816. * @return {clay.Matrix3}
  29817. */
  29818. translate: function (v) {
  29819. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].translate(this.array, this.array, v.array);
  29820. this._dirty = true;
  29821. return this;
  29822. },
  29823. /**
  29824. * Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix
  29825. * @param {clay.Matrix4} a
  29826. */
  29827. normalFromMat4: function (a) {
  29828. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].normalFromMat4(this.array, a.array);
  29829. this._dirty = true;
  29830. return this;
  29831. },
  29832. /**
  29833. * Transpose self, in-place.
  29834. * @return {clay.Matrix2}
  29835. */
  29836. transpose: function () {
  29837. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].transpose(this.array, this.array);
  29838. this._dirty = true;
  29839. return this;
  29840. },
  29841. toString: function () {
  29842. return '[' + Array.prototype.join.call(this.array, ',') + ']';
  29843. },
  29844. toArray: function () {
  29845. return Array.prototype.slice.call(this.array);
  29846. }
  29847. };
  29848. /**
  29849. * @param {clay.Matrix3} out
  29850. * @param {clay.Matrix3} a
  29851. * @return {clay.Matrix3}
  29852. */
  29853. Matrix3.adjoint = function (out, a) {
  29854. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].adjoint(out.array, a.array);
  29855. out._dirty = true;
  29856. return out;
  29857. };
  29858. /**
  29859. * @param {clay.Matrix3} out
  29860. * @param {clay.Matrix3} a
  29861. * @return {clay.Matrix3}
  29862. */
  29863. Matrix3.copy = function (out, a) {
  29864. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].copy(out.array, a.array);
  29865. out._dirty = true;
  29866. return out;
  29867. };
  29868. /**
  29869. * @param {clay.Matrix3} a
  29870. * @return {number}
  29871. */
  29872. Matrix3.determinant = function (a) {
  29873. return __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].determinant(a.array);
  29874. };
  29875. /**
  29876. * @param {clay.Matrix3} out
  29877. * @return {clay.Matrix3}
  29878. */
  29879. Matrix3.identity = function (out) {
  29880. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].identity(out.array);
  29881. out._dirty = true;
  29882. return out;
  29883. };
  29884. /**
  29885. * @param {clay.Matrix3} out
  29886. * @param {clay.Matrix3} a
  29887. * @return {clay.Matrix3}
  29888. */
  29889. Matrix3.invert = function (out, a) {
  29890. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].invert(out.array, a.array);
  29891. return out;
  29892. };
  29893. /**
  29894. * @param {clay.Matrix3} out
  29895. * @param {clay.Matrix3} a
  29896. * @param {clay.Matrix3} b
  29897. * @return {clay.Matrix3}
  29898. */
  29899. Matrix3.mul = function (out, a, b) {
  29900. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].mul(out.array, a.array, b.array);
  29901. out._dirty = true;
  29902. return out;
  29903. };
  29904. /**
  29905. * @function
  29906. * @param {clay.Matrix3} out
  29907. * @param {clay.Matrix3} a
  29908. * @param {clay.Matrix3} b
  29909. * @return {clay.Matrix3}
  29910. */
  29911. Matrix3.multiply = Matrix3.mul;
  29912. /**
  29913. * @param {clay.Matrix3} out
  29914. * @param {clay.Matrix2d} a
  29915. * @return {clay.Matrix3}
  29916. */
  29917. Matrix3.fromMat2d = function (out, a) {
  29918. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].fromMat2d(out.array, a.array);
  29919. out._dirty = true;
  29920. return out;
  29921. };
  29922. /**
  29923. * @param {clay.Matrix3} out
  29924. * @param {clay.Matrix4} a
  29925. * @return {clay.Matrix3}
  29926. */
  29927. Matrix3.fromMat4 = function (out, a) {
  29928. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].fromMat4(out.array, a.array);
  29929. out._dirty = true;
  29930. return out;
  29931. };
  29932. /**
  29933. * @param {clay.Matrix3} out
  29934. * @param {clay.Quaternion} a
  29935. * @return {clay.Matrix3}
  29936. */
  29937. Matrix3.fromQuat = function (out, q) {
  29938. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].fromQuat(out.array, q.array);
  29939. out._dirty = true;
  29940. return out;
  29941. };
  29942. /**
  29943. * @param {clay.Matrix3} out
  29944. * @param {clay.Matrix4} a
  29945. * @return {clay.Matrix3}
  29946. */
  29947. Matrix3.normalFromMat4 = function (out, a) {
  29948. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].normalFromMat4(out.array, a.array);
  29949. out._dirty = true;
  29950. return out;
  29951. };
  29952. /**
  29953. * @param {clay.Matrix3} out
  29954. * @param {clay.Matrix3} a
  29955. * @param {number} rad
  29956. * @return {clay.Matrix3}
  29957. */
  29958. Matrix3.rotate = function (out, a, rad) {
  29959. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].rotate(out.array, a.array, rad);
  29960. out._dirty = true;
  29961. return out;
  29962. };
  29963. /**
  29964. * @param {clay.Matrix3} out
  29965. * @param {clay.Matrix3} a
  29966. * @param {clay.Vector2} v
  29967. * @return {clay.Matrix3}
  29968. */
  29969. Matrix3.scale = function (out, a, v) {
  29970. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].scale(out.array, a.array, v.array);
  29971. out._dirty = true;
  29972. return out;
  29973. };
  29974. /**
  29975. * @param {clay.Matrix3} out
  29976. * @param {clay.Matrix3} a
  29977. * @return {clay.Matrix3}
  29978. */
  29979. Matrix3.transpose = function (out, a) {
  29980. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].transpose(out.array, a.array);
  29981. out._dirty = true;
  29982. return out;
  29983. };
  29984. /**
  29985. * @param {clay.Matrix3} out
  29986. * @param {clay.Matrix3} a
  29987. * @param {clay.Vector2} v
  29988. * @return {clay.Matrix3}
  29989. */
  29990. Matrix3.translate = function (out, a, v) {
  29991. __WEBPACK_IMPORTED_MODULE_0__glmatrix_mat3__["a" /* default */].translate(out.array, a.array, v.array);
  29992. out._dirty = true;
  29993. return out;
  29994. };
  29995. /* harmony default export */ __webpack_exports__["a"] = (Matrix3);
  29996. /***/
  29997. }),
  29998. /* 141 */
  29999. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  30000. "use strict";
  30001. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_zrender_lib_animation_Animator__ = __webpack_require__(142);
  30002. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_zrender_lib_animation_Animator___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_zrender_lib_animation_Animator__);
  30003. var animatableMixin = {
  30004. _animators: null,
  30005. getAnimators: function () {
  30006. this._animators = this._animators || [];
  30007. return this._animators;
  30008. },
  30009. animate: function (path, opts) {
  30010. this._animators = this._animators || [];
  30011. var el = this;
  30012. var target;
  30013. if (path) {
  30014. var pathSplitted = path.split('.');
  30015. var prop = el;
  30016. for (var i = 0, l = pathSplitted.length; i < l; i++) {
  30017. if (!prop) {
  30018. continue;
  30019. }
  30020. prop = prop[pathSplitted[i]];
  30021. }
  30022. if (prop) {
  30023. target = prop;
  30024. }
  30025. }
  30026. else {
  30027. target = el;
  30028. }
  30029. if (target == null) {
  30030. throw new Error('Target ' + path + ' not exists');
  30031. }
  30032. var animators = this._animators;
  30033. var animator = new __WEBPACK_IMPORTED_MODULE_0_zrender_lib_animation_Animator___default.a(target, opts);
  30034. var self = this;
  30035. animator.during(function () {
  30036. if (self.__zr) {
  30037. self.__zr.refresh();
  30038. }
  30039. }).done(function () {
  30040. var idx = animators.indexOf(animator);
  30041. if (idx >= 0) {
  30042. animators.splice(idx, 1);
  30043. }
  30044. });
  30045. animators.push(animator);
  30046. if (this.__zr) {
  30047. this.__zr.animation.addAnimator(animator);
  30048. }
  30049. return animator;
  30050. },
  30051. stopAnimation: function (forwardToLast) {
  30052. this._animators = this._animators || [];
  30053. var animators = this._animators;
  30054. var len = animators.length;
  30055. for (var i = 0; i < len; i++) {
  30056. animators[i].stop(forwardToLast);
  30057. }
  30058. animators.length = 0;
  30059. return this;
  30060. },
  30061. addAnimatorsToZr: function (zr) {
  30062. if (this._animators) {
  30063. for (var i = 0; i < this._animators.length; i++) {
  30064. zr.animation.addAnimator(this._animators[i]);
  30065. }
  30066. }
  30067. },
  30068. removeAnimatorsFromZr: function (zr) {
  30069. if (this._animators) {
  30070. for (var i = 0; i < this._animators.length; i++) {
  30071. zr.animation.removeAnimator(this._animators[i]);
  30072. }
  30073. }
  30074. }
  30075. };
  30076. /* harmony default export */ __webpack_exports__["a"] = (animatableMixin);
  30077. /***/
  30078. }),
  30079. /* 142 */
  30080. /***/ (function (module, exports, __webpack_require__) {
  30081. var Clip = __webpack_require__(143);
  30082. var color = __webpack_require__(145);
  30083. var _util = __webpack_require__(13);
  30084. var isArrayLike = _util.isArrayLike;
  30085. /**
  30086. * @module echarts/animation/Animator
  30087. */
  30088. var arraySlice = Array.prototype.slice;
  30089. function defaultGetter(target, key) {
  30090. return target[key];
  30091. }
  30092. function defaultSetter(target, key, value) {
  30093. target[key] = value;
  30094. }
  30095. /**
  30096. * @param {number} p0
  30097. * @param {number} p1
  30098. * @param {number} percent
  30099. * @return {number}
  30100. */
  30101. function interpolateNumber(p0, p1, percent) {
  30102. return (p1 - p0) * percent + p0;
  30103. }
  30104. /**
  30105. * @param {string} p0
  30106. * @param {string} p1
  30107. * @param {number} percent
  30108. * @return {string}
  30109. */
  30110. function interpolateString(p0, p1, percent) {
  30111. return percent > 0.5 ? p1 : p0;
  30112. }
  30113. /**
  30114. * @param {Array} p0
  30115. * @param {Array} p1
  30116. * @param {number} percent
  30117. * @param {Array} out
  30118. * @param {number} arrDim
  30119. */
  30120. function interpolateArray(p0, p1, percent, out, arrDim) {
  30121. var len = p0.length;
  30122. if (arrDim == 1) {
  30123. for (var i = 0; i < len; i++) {
  30124. out[i] = interpolateNumber(p0[i], p1[i], percent);
  30125. }
  30126. } else {
  30127. var len2 = len && p0[0].length;
  30128. for (var i = 0; i < len; i++) {
  30129. for (var j = 0; j < len2; j++) {
  30130. out[i][j] = interpolateNumber(p0[i][j], p1[i][j], percent);
  30131. }
  30132. }
  30133. }
  30134. } // arr0 is source array, arr1 is target array.
  30135. // Do some preprocess to avoid error happened when interpolating from arr0 to arr1
  30136. function fillArr(arr0, arr1, arrDim) {
  30137. var arr0Len = arr0.length;
  30138. var arr1Len = arr1.length;
  30139. if (arr0Len !== arr1Len) {
  30140. // FIXME Not work for TypedArray
  30141. var isPreviousLarger = arr0Len > arr1Len;
  30142. if (isPreviousLarger) {
  30143. // Cut the previous
  30144. arr0.length = arr1Len;
  30145. } else {
  30146. // Fill the previous
  30147. for (var i = arr0Len; i < arr1Len; i++) {
  30148. arr0.push(arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i]));
  30149. }
  30150. }
  30151. } // Handling NaN value
  30152. var len2 = arr0[0] && arr0[0].length;
  30153. for (var i = 0; i < arr0.length; i++) {
  30154. if (arrDim === 1) {
  30155. if (isNaN(arr0[i])) {
  30156. arr0[i] = arr1[i];
  30157. }
  30158. } else {
  30159. for (var j = 0; j < len2; j++) {
  30160. if (isNaN(arr0[i][j])) {
  30161. arr0[i][j] = arr1[i][j];
  30162. }
  30163. }
  30164. }
  30165. }
  30166. }
  30167. /**
  30168. * @param {Array} arr0
  30169. * @param {Array} arr1
  30170. * @param {number} arrDim
  30171. * @return {boolean}
  30172. */
  30173. function isArraySame(arr0, arr1, arrDim) {
  30174. if (arr0 === arr1) {
  30175. return true;
  30176. }
  30177. var len = arr0.length;
  30178. if (len !== arr1.length) {
  30179. return false;
  30180. }
  30181. if (arrDim === 1) {
  30182. for (var i = 0; i < len; i++) {
  30183. if (arr0[i] !== arr1[i]) {
  30184. return false;
  30185. }
  30186. }
  30187. } else {
  30188. var len2 = arr0[0].length;
  30189. for (var i = 0; i < len; i++) {
  30190. for (var j = 0; j < len2; j++) {
  30191. if (arr0[i][j] !== arr1[i][j]) {
  30192. return false;
  30193. }
  30194. }
  30195. }
  30196. }
  30197. return true;
  30198. }
  30199. /**
  30200. * Catmull Rom interpolate array
  30201. * @param {Array} p0
  30202. * @param {Array} p1
  30203. * @param {Array} p2
  30204. * @param {Array} p3
  30205. * @param {number} t
  30206. * @param {number} t2
  30207. * @param {number} t3
  30208. * @param {Array} out
  30209. * @param {number} arrDim
  30210. */
  30211. function catmullRomInterpolateArray(p0, p1, p2, p3, t, t2, t3, out, arrDim) {
  30212. var len = p0.length;
  30213. if (arrDim == 1) {
  30214. for (var i = 0; i < len; i++) {
  30215. out[i] = catmullRomInterpolate(p0[i], p1[i], p2[i], p3[i], t, t2, t3);
  30216. }
  30217. } else {
  30218. var len2 = p0[0].length;
  30219. for (var i = 0; i < len; i++) {
  30220. for (var j = 0; j < len2; j++) {
  30221. out[i][j] = catmullRomInterpolate(p0[i][j], p1[i][j], p2[i][j], p3[i][j], t, t2, t3);
  30222. }
  30223. }
  30224. }
  30225. }
  30226. /**
  30227. * Catmull Rom interpolate number
  30228. * @param {number} p0
  30229. * @param {number} p1
  30230. * @param {number} p2
  30231. * @param {number} p3
  30232. * @param {number} t
  30233. * @param {number} t2
  30234. * @param {number} t3
  30235. * @return {number}
  30236. */
  30237. function catmullRomInterpolate(p0, p1, p2, p3, t, t2, t3) {
  30238. var v0 = (p2 - p0) * 0.5;
  30239. var v1 = (p3 - p1) * 0.5;
  30240. return (2 * (p1 - p2) + v0 + v1) * t3 + (-3 * (p1 - p2) - 2 * v0 - v1) * t2 + v0 * t + p1;
  30241. }
  30242. function cloneValue(value) {
  30243. if (isArrayLike(value)) {
  30244. var len = value.length;
  30245. if (isArrayLike(value[0])) {
  30246. var ret = [];
  30247. for (var i = 0; i < len; i++) {
  30248. ret.push(arraySlice.call(value[i]));
  30249. }
  30250. return ret;
  30251. }
  30252. return arraySlice.call(value);
  30253. }
  30254. return value;
  30255. }
  30256. function rgba2String(rgba) {
  30257. rgba[0] = Math.floor(rgba[0]);
  30258. rgba[1] = Math.floor(rgba[1]);
  30259. rgba[2] = Math.floor(rgba[2]);
  30260. return 'rgba(' + rgba.join(',') + ')';
  30261. }
  30262. function getArrayDim(keyframes) {
  30263. var lastValue = keyframes[keyframes.length - 1].value;
  30264. return isArrayLike(lastValue && lastValue[0]) ? 2 : 1;
  30265. }
  30266. function createTrackClip(animator, easing, oneTrackDone, keyframes, propName, forceAnimate) {
  30267. var getter = animator._getter;
  30268. var setter = animator._setter;
  30269. var useSpline = easing === 'spline';
  30270. var trackLen = keyframes.length;
  30271. if (!trackLen) {
  30272. return;
  30273. } // Guess data type
  30274. var firstVal = keyframes[0].value;
  30275. var isValueArray = isArrayLike(firstVal);
  30276. var isValueColor = false;
  30277. var isValueString = false; // For vertices morphing
  30278. var arrDim = isValueArray ? getArrayDim(keyframes) : 0;
  30279. var trackMaxTime; // Sort keyframe as ascending
  30280. keyframes.sort(function (a, b) {
  30281. return a.time - b.time;
  30282. });
  30283. trackMaxTime = keyframes[trackLen - 1].time; // Percents of each keyframe
  30284. var kfPercents = []; // Value of each keyframe
  30285. var kfValues = [];
  30286. var prevValue = keyframes[0].value;
  30287. var isAllValueEqual = true;
  30288. for (var i = 0; i < trackLen; i++) {
  30289. kfPercents.push(keyframes[i].time / trackMaxTime); // Assume value is a color when it is a string
  30290. var value = keyframes[i].value; // Check if value is equal, deep check if value is array
  30291. if (!(isValueArray && isArraySame(value, prevValue, arrDim) || !isValueArray && value === prevValue)) {
  30292. isAllValueEqual = false;
  30293. }
  30294. prevValue = value; // Try converting a string to a color array
  30295. if (typeof value == 'string') {
  30296. var colorArray = color.parse(value);
  30297. if (colorArray) {
  30298. value = colorArray;
  30299. isValueColor = true;
  30300. } else {
  30301. isValueString = true;
  30302. }
  30303. }
  30304. kfValues.push(value);
  30305. }
  30306. if (!forceAnimate && isAllValueEqual) {
  30307. return;
  30308. }
  30309. var lastValue = kfValues[trackLen - 1]; // Polyfill array and NaN value
  30310. for (var i = 0; i < trackLen - 1; i++) {
  30311. if (isValueArray) {
  30312. fillArr(kfValues[i], lastValue, arrDim);
  30313. } else {
  30314. if (isNaN(kfValues[i]) && !isNaN(lastValue) && !isValueString && !isValueColor) {
  30315. kfValues[i] = lastValue;
  30316. }
  30317. }
  30318. }
  30319. isValueArray && fillArr(getter(animator._target, propName), lastValue, arrDim); // Cache the key of last frame to speed up when
  30320. // animation playback is sequency
  30321. var lastFrame = 0;
  30322. var lastFramePercent = 0;
  30323. var start;
  30324. var w;
  30325. var p0;
  30326. var p1;
  30327. var p2;
  30328. var p3;
  30329. if (isValueColor) {
  30330. var rgba = [0, 0, 0, 0];
  30331. }
  30332. var onframe = function (target, percent) {
  30333. // Find the range keyframes
  30334. // kf1-----kf2---------current--------kf3
  30335. // find kf2 and kf3 and do interpolation
  30336. var frame; // In the easing function like elasticOut, percent may less than 0
  30337. if (percent < 0) {
  30338. frame = 0;
  30339. } else if (percent < lastFramePercent) {
  30340. // Start from next key
  30341. // PENDING start from lastFrame ?
  30342. start = Math.min(lastFrame + 1, trackLen - 1);
  30343. for (frame = start; frame >= 0; frame--) {
  30344. if (kfPercents[frame] <= percent) {
  30345. break;
  30346. }
  30347. } // PENDING really need to do this ?
  30348. frame = Math.min(frame, trackLen - 2);
  30349. } else {
  30350. for (frame = lastFrame; frame < trackLen; frame++) {
  30351. if (kfPercents[frame] > percent) {
  30352. break;
  30353. }
  30354. }
  30355. frame = Math.min(frame - 1, trackLen - 2);
  30356. }
  30357. lastFrame = frame;
  30358. lastFramePercent = percent;
  30359. var range = kfPercents[frame + 1] - kfPercents[frame];
  30360. if (range === 0) {
  30361. return;
  30362. } else {
  30363. w = (percent - kfPercents[frame]) / range;
  30364. }
  30365. if (useSpline) {
  30366. p1 = kfValues[frame];
  30367. p0 = kfValues[frame === 0 ? frame : frame - 1];
  30368. p2 = kfValues[frame > trackLen - 2 ? trackLen - 1 : frame + 1];
  30369. p3 = kfValues[frame > trackLen - 3 ? trackLen - 1 : frame + 2];
  30370. if (isValueArray) {
  30371. catmullRomInterpolateArray(p0, p1, p2, p3, w, w * w, w * w * w, getter(target, propName), arrDim);
  30372. } else {
  30373. var value;
  30374. if (isValueColor) {
  30375. value = catmullRomInterpolateArray(p0, p1, p2, p3, w, w * w, w * w * w, rgba, 1);
  30376. value = rgba2String(rgba);
  30377. } else if (isValueString) {
  30378. // String is step(0.5)
  30379. return interpolateString(p1, p2, w);
  30380. } else {
  30381. value = catmullRomInterpolate(p0, p1, p2, p3, w, w * w, w * w * w);
  30382. }
  30383. setter(target, propName, value);
  30384. }
  30385. } else {
  30386. if (isValueArray) {
  30387. interpolateArray(kfValues[frame], kfValues[frame + 1], w, getter(target, propName), arrDim);
  30388. } else {
  30389. var value;
  30390. if (isValueColor) {
  30391. interpolateArray(kfValues[frame], kfValues[frame + 1], w, rgba, 1);
  30392. value = rgba2String(rgba);
  30393. } else if (isValueString) {
  30394. // String is step(0.5)
  30395. return interpolateString(kfValues[frame], kfValues[frame + 1], w);
  30396. } else {
  30397. value = interpolateNumber(kfValues[frame], kfValues[frame + 1], w);
  30398. }
  30399. setter(target, propName, value);
  30400. }
  30401. }
  30402. };
  30403. var clip = new Clip({
  30404. target: animator._target,
  30405. life: trackMaxTime,
  30406. loop: animator._loop,
  30407. delay: animator._delay,
  30408. onframe: onframe,
  30409. ondestroy: oneTrackDone
  30410. });
  30411. if (easing && easing !== 'spline') {
  30412. clip.easing = easing;
  30413. }
  30414. return clip;
  30415. }
  30416. /**
  30417. * @alias module:zrender/animation/Animator
  30418. * @constructor
  30419. * @param {Object} target
  30420. * @param {boolean} loop
  30421. * @param {Function} getter
  30422. * @param {Function} setter
  30423. */
  30424. var Animator = function (target, loop, getter, setter) {
  30425. this._tracks = {};
  30426. this._target = target;
  30427. this._loop = loop || false;
  30428. this._getter = getter || defaultGetter;
  30429. this._setter = setter || defaultSetter;
  30430. this._clipCount = 0;
  30431. this._delay = 0;
  30432. this._doneList = [];
  30433. this._onframeList = [];
  30434. this._clipList = [];
  30435. };
  30436. Animator.prototype = {
  30437. /**
  30438. * 设置动画关键帧
  30439. * @param {number} time 关键帧时间,单位是ms
  30440. * @param {Object} props 关键帧的属性值,key-value表示
  30441. * @return {module:zrender/animation/Animator}
  30442. */
  30443. when: function (time
  30444. /* ms */
  30445. , props) {
  30446. var tracks = this._tracks;
  30447. for (var propName in props) {
  30448. if (!props.hasOwnProperty(propName)) {
  30449. continue;
  30450. }
  30451. if (!tracks[propName]) {
  30452. tracks[propName] = []; // Invalid value
  30453. var value = this._getter(this._target, propName);
  30454. if (value == null) {
  30455. // zrLog('Invalid property ' + propName);
  30456. continue;
  30457. } // If time is 0
  30458. // Then props is given initialize value
  30459. // Else
  30460. // Initialize value from current prop value
  30461. if (time !== 0) {
  30462. tracks[propName].push({
  30463. time: 0,
  30464. value: cloneValue(value)
  30465. });
  30466. }
  30467. }
  30468. tracks[propName].push({
  30469. time: time,
  30470. value: props[propName]
  30471. });
  30472. }
  30473. return this;
  30474. },
  30475. /**
  30476. * æ·»åŠ åŠ¨ç”»æ¯ä¸€å¸§çš„å›žè°ƒå‡½æ•°
  30477. * @param {Function} callback
  30478. * @return {module:zrender/animation/Animator}
  30479. */
  30480. during: function (callback) {
  30481. this._onframeList.push(callback);
  30482. return this;
  30483. },
  30484. pause: function () {
  30485. for (var i = 0; i < this._clipList.length; i++) {
  30486. this._clipList[i].pause();
  30487. }
  30488. this._paused = true;
  30489. },
  30490. resume: function () {
  30491. for (var i = 0; i < this._clipList.length; i++) {
  30492. this._clipList[i].resume();
  30493. }
  30494. this._paused = false;
  30495. },
  30496. isPaused: function () {
  30497. return !!this._paused;
  30498. },
  30499. _doneCallback: function () {
  30500. // Clear all tracks
  30501. this._tracks = {}; // Clear all clips
  30502. this._clipList.length = 0;
  30503. var doneList = this._doneList;
  30504. var len = doneList.length;
  30505. for (var i = 0; i < len; i++) {
  30506. doneList[i].call(this);
  30507. }
  30508. },
  30509. /**
  30510. * 开始执行动画
  30511. * @param {string|Function} [easing]
  30512. * 动画缓动函数,详见{@link module:zrender/animation/easing}
  30513. * @param {boolean} forceAnimate
  30514. * @return {module:zrender/animation/Animator}
  30515. */
  30516. start: function (easing, forceAnimate) {
  30517. var self = this;
  30518. var clipCount = 0;
  30519. var oneTrackDone = function () {
  30520. clipCount--;
  30521. if (!clipCount) {
  30522. self._doneCallback();
  30523. }
  30524. };
  30525. var lastClip;
  30526. for (var propName in this._tracks) {
  30527. if (!this._tracks.hasOwnProperty(propName)) {
  30528. continue;
  30529. }
  30530. var clip = createTrackClip(this, easing, oneTrackDone, this._tracks[propName], propName, forceAnimate);
  30531. if (clip) {
  30532. this._clipList.push(clip);
  30533. clipCount++; // If start after added to animation
  30534. if (this.animation) {
  30535. this.animation.addClip(clip);
  30536. }
  30537. lastClip = clip;
  30538. }
  30539. } // Add during callback on the last clip
  30540. if (lastClip) {
  30541. var oldOnFrame = lastClip.onframe;
  30542. lastClip.onframe = function (target, percent) {
  30543. oldOnFrame(target, percent);
  30544. for (var i = 0; i < self._onframeList.length; i++) {
  30545. self._onframeList[i](target, percent);
  30546. }
  30547. };
  30548. } // This optimization will help the case that in the upper application
  30549. // the view may be refreshed frequently, where animation will be
  30550. // called repeatly but nothing changed.
  30551. if (!clipCount) {
  30552. this._doneCallback();
  30553. }
  30554. return this;
  30555. },
  30556. /**
  30557. * 停止动画
  30558. * @param {boolean} forwardToLast If move to last frame before stop
  30559. */
  30560. stop: function (forwardToLast) {
  30561. var clipList = this._clipList;
  30562. var animation = this.animation;
  30563. for (var i = 0; i < clipList.length; i++) {
  30564. var clip = clipList[i];
  30565. if (forwardToLast) {
  30566. // Move to last frame before stop
  30567. clip.onframe(this._target, 1);
  30568. }
  30569. animation && animation.removeClip(clip);
  30570. }
  30571. clipList.length = 0;
  30572. },
  30573. /**
  30574. * 设置动画延迟开始的时间
  30575. * @param {number} time 单位ms
  30576. * @return {module:zrender/animation/Animator}
  30577. */
  30578. delay: function (time) {
  30579. this._delay = time;
  30580. return this;
  30581. },
  30582. /**
  30583. * æ·»åŠ åŠ¨ç”»ç»“æŸçš„å›žè°ƒ
  30584. * @param {Function} cb
  30585. * @return {module:zrender/animation/Animator}
  30586. */
  30587. done: function (cb) {
  30588. if (cb) {
  30589. this._doneList.push(cb);
  30590. }
  30591. return this;
  30592. },
  30593. /**
  30594. * @return {Array.<module:zrender/animation/Clip>}
  30595. */
  30596. getClips: function () {
  30597. return this._clipList;
  30598. }
  30599. };
  30600. var _default = Animator;
  30601. module.exports = _default;
  30602. /***/
  30603. }),
  30604. /* 143 */
  30605. /***/ (function (module, exports, __webpack_require__) {
  30606. var easingFuncs = __webpack_require__(144);
  30607. /**
  30608. * 动画主控制器
  30609. * @config target 动画对象,可以是数组,如果是数组的话会批量分发onframe等事件
  30610. * @config life(1000) 动画时长
  30611. * @config delay(0) 动画延迟时间
  30612. * @config loop(true)
  30613. * @config gap(0) 循环的间隔时间
  30614. * @config onframe
  30615. * @config easing(optional)
  30616. * @config ondestroy(optional)
  30617. * @config onrestart(optional)
  30618. *
  30619. * TODO pause
  30620. */
  30621. function Clip(options) {
  30622. this._target = options.target; // 生命周期
  30623. this._life = options.life || 1000; // å»¶æ—¶
  30624. this._delay = options.delay || 0; // 开始时间
  30625. // this._startTime = new Date().getTime() + this._delay;// 单位毫秒
  30626. this._initialized = false; // 是否循环
  30627. this.loop = options.loop == null ? false : options.loop;
  30628. this.gap = options.gap || 0;
  30629. this.easing = options.easing || 'Linear';
  30630. this.onframe = options.onframe;
  30631. this.ondestroy = options.ondestroy;
  30632. this.onrestart = options.onrestart;
  30633. this._pausedTime = 0;
  30634. this._paused = false;
  30635. }
  30636. Clip.prototype = {
  30637. constructor: Clip,
  30638. step: function (globalTime, deltaTime) {
  30639. // Set startTime on first step, or _startTime may has milleseconds different between clips
  30640. // PENDING
  30641. if (!this._initialized) {
  30642. this._startTime = globalTime + this._delay;
  30643. this._initialized = true;
  30644. }
  30645. if (this._paused) {
  30646. this._pausedTime += deltaTime;
  30647. return;
  30648. }
  30649. var percent = (globalTime - this._startTime - this._pausedTime) / this._life; // 还没开始
  30650. if (percent < 0) {
  30651. return;
  30652. }
  30653. percent = Math.min(percent, 1);
  30654. var easing = this.easing;
  30655. var easingFunc = typeof easing == 'string' ? easingFuncs[easing] : easing;
  30656. var schedule = typeof easingFunc === 'function' ? easingFunc(percent) : percent;
  30657. this.fire('frame', schedule); // 结束
  30658. if (percent == 1) {
  30659. if (this.loop) {
  30660. this.restart(globalTime); // 重新开始周期
  30661. // 抛出而不是直接调用事件直到 stage.update 后再统一调用这些事件
  30662. return 'restart';
  30663. } // åŠ¨ç”»å®Œæˆå°†è¿™ä¸ªæŽ§åˆ¶å™¨æ ‡è¯†ä¸ºå¾…åˆ é™¤
  30664. // 在Animation.updateä¸­è¿›è¡Œæ‰¹é‡åˆ é™¤
  30665. this._needsRemove = true;
  30666. return 'destroy';
  30667. }
  30668. return null;
  30669. },
  30670. restart: function (globalTime) {
  30671. var remainder = (globalTime - this._startTime - this._pausedTime) % this._life;
  30672. this._startTime = globalTime - remainder + this.gap;
  30673. this._pausedTime = 0;
  30674. this._needsRemove = false;
  30675. },
  30676. fire: function (eventType, arg) {
  30677. eventType = 'on' + eventType;
  30678. if (this[eventType]) {
  30679. this[eventType](this._target, arg);
  30680. }
  30681. },
  30682. pause: function () {
  30683. this._paused = true;
  30684. },
  30685. resume: function () {
  30686. this._paused = false;
  30687. }
  30688. };
  30689. var _default = Clip;
  30690. module.exports = _default;
  30691. /***/
  30692. }),
  30693. /* 144 */
  30694. /***/ (function (module, exports) {
  30695. /**
  30696. * ç¼“åŠ¨ä»£ç æ¥è‡ª https://github.com/sole/tween.js/blob/master/src/Tween.js
  30697. * @see http://sole.github.io/tween.js/examples/03_graphs.html
  30698. * @exports zrender/animation/easing
  30699. */
  30700. var easing = {
  30701. /**
  30702. * @param {number} k
  30703. * @return {number}
  30704. */
  30705. linear: function (k) {
  30706. return k;
  30707. },
  30708. /**
  30709. * @param {number} k
  30710. * @return {number}
  30711. */
  30712. quadraticIn: function (k) {
  30713. return k * k;
  30714. },
  30715. /**
  30716. * @param {number} k
  30717. * @return {number}
  30718. */
  30719. quadraticOut: function (k) {
  30720. return k * (2 - k);
  30721. },
  30722. /**
  30723. * @param {number} k
  30724. * @return {number}
  30725. */
  30726. quadraticInOut: function (k) {
  30727. if ((k *= 2) < 1) {
  30728. return 0.5 * k * k;
  30729. }
  30730. return -0.5 * (--k * (k - 2) - 1);
  30731. },
  30732. // 三次方的缓动(t^3)
  30733. /**
  30734. * @param {number} k
  30735. * @return {number}
  30736. */
  30737. cubicIn: function (k) {
  30738. return k * k * k;
  30739. },
  30740. /**
  30741. * @param {number} k
  30742. * @return {number}
  30743. */
  30744. cubicOut: function (k) {
  30745. return --k * k * k + 1;
  30746. },
  30747. /**
  30748. * @param {number} k
  30749. * @return {number}
  30750. */
  30751. cubicInOut: function (k) {
  30752. if ((k *= 2) < 1) {
  30753. return 0.5 * k * k * k;
  30754. }
  30755. return 0.5 * ((k -= 2) * k * k + 2);
  30756. },
  30757. // 四次方的缓动(t^4)
  30758. /**
  30759. * @param {number} k
  30760. * @return {number}
  30761. */
  30762. quarticIn: function (k) {
  30763. return k * k * k * k;
  30764. },
  30765. /**
  30766. * @param {number} k
  30767. * @return {number}
  30768. */
  30769. quarticOut: function (k) {
  30770. return 1 - --k * k * k * k;
  30771. },
  30772. /**
  30773. * @param {number} k
  30774. * @return {number}
  30775. */
  30776. quarticInOut: function (k) {
  30777. if ((k *= 2) < 1) {
  30778. return 0.5 * k * k * k * k;
  30779. }
  30780. return -0.5 * ((k -= 2) * k * k * k - 2);
  30781. },
  30782. // 五次方的缓动(t^5)
  30783. /**
  30784. * @param {number} k
  30785. * @return {number}
  30786. */
  30787. quinticIn: function (k) {
  30788. return k * k * k * k * k;
  30789. },
  30790. /**
  30791. * @param {number} k
  30792. * @return {number}
  30793. */
  30794. quinticOut: function (k) {
  30795. return --k * k * k * k * k + 1;
  30796. },
  30797. /**
  30798. * @param {number} k
  30799. * @return {number}
  30800. */
  30801. quinticInOut: function (k) {
  30802. if ((k *= 2) < 1) {
  30803. return 0.5 * k * k * k * k * k;
  30804. }
  30805. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  30806. },
  30807. // 正弦曲线的缓动(sin(t))
  30808. /**
  30809. * @param {number} k
  30810. * @return {number}
  30811. */
  30812. sinusoidalIn: function (k) {
  30813. return 1 - Math.cos(k * Math.PI / 2);
  30814. },
  30815. /**
  30816. * @param {number} k
  30817. * @return {number}
  30818. */
  30819. sinusoidalOut: function (k) {
  30820. return Math.sin(k * Math.PI / 2);
  30821. },
  30822. /**
  30823. * @param {number} k
  30824. * @return {number}
  30825. */
  30826. sinusoidalInOut: function (k) {
  30827. return 0.5 * (1 - Math.cos(Math.PI * k));
  30828. },
  30829. // 指数曲线的缓动(2^t)
  30830. /**
  30831. * @param {number} k
  30832. * @return {number}
  30833. */
  30834. exponentialIn: function (k) {
  30835. return k === 0 ? 0 : Math.pow(1024, k - 1);
  30836. },
  30837. /**
  30838. * @param {number} k
  30839. * @return {number}
  30840. */
  30841. exponentialOut: function (k) {
  30842. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  30843. },
  30844. /**
  30845. * @param {number} k
  30846. * @return {number}
  30847. */
  30848. exponentialInOut: function (k) {
  30849. if (k === 0) {
  30850. return 0;
  30851. }
  30852. if (k === 1) {
  30853. return 1;
  30854. }
  30855. if ((k *= 2) < 1) {
  30856. return 0.5 * Math.pow(1024, k - 1);
  30857. }
  30858. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  30859. },
  30860. // 圆形曲线的缓动(sqrt(1-t^2))
  30861. /**
  30862. * @param {number} k
  30863. * @return {number}
  30864. */
  30865. circularIn: function (k) {
  30866. return 1 - Math.sqrt(1 - k * k);
  30867. },
  30868. /**
  30869. * @param {number} k
  30870. * @return {number}
  30871. */
  30872. circularOut: function (k) {
  30873. return Math.sqrt(1 - --k * k);
  30874. },
  30875. /**
  30876. * @param {number} k
  30877. * @return {number}
  30878. */
  30879. circularInOut: function (k) {
  30880. if ((k *= 2) < 1) {
  30881. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  30882. }
  30883. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  30884. },
  30885. // 创建类似于弹簧在停止前来回振荡的动画
  30886. /**
  30887. * @param {number} k
  30888. * @return {number}
  30889. */
  30890. elasticIn: function (k) {
  30891. var s;
  30892. var a = 0.1;
  30893. var p = 0.4;
  30894. if (k === 0) {
  30895. return 0;
  30896. }
  30897. if (k === 1) {
  30898. return 1;
  30899. }
  30900. if (!a || a < 1) {
  30901. a = 1;
  30902. s = p / 4;
  30903. } else {
  30904. s = p * Math.asin(1 / a) / (2 * Math.PI);
  30905. }
  30906. return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
  30907. },
  30908. /**
  30909. * @param {number} k
  30910. * @return {number}
  30911. */
  30912. elasticOut: function (k) {
  30913. var s;
  30914. var a = 0.1;
  30915. var p = 0.4;
  30916. if (k === 0) {
  30917. return 0;
  30918. }
  30919. if (k === 1) {
  30920. return 1;
  30921. }
  30922. if (!a || a < 1) {
  30923. a = 1;
  30924. s = p / 4;
  30925. } else {
  30926. s = p * Math.asin(1 / a) / (2 * Math.PI);
  30927. }
  30928. return a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1;
  30929. },
  30930. /**
  30931. * @param {number} k
  30932. * @return {number}
  30933. */
  30934. elasticInOut: function (k) {
  30935. var s;
  30936. var a = 0.1;
  30937. var p = 0.4;
  30938. if (k === 0) {
  30939. return 0;
  30940. }
  30941. if (k === 1) {
  30942. return 1;
  30943. }
  30944. if (!a || a < 1) {
  30945. a = 1;
  30946. s = p / 4;
  30947. } else {
  30948. s = p * Math.asin(1 / a) / (2 * Math.PI);
  30949. }
  30950. if ((k *= 2) < 1) {
  30951. return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
  30952. }
  30953. return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  30954. },
  30955. // 在某一动画开始沿指示的路径进行动画处理前稍稍收回该动画的移动
  30956. /**
  30957. * @param {number} k
  30958. * @return {number}
  30959. */
  30960. backIn: function (k) {
  30961. var s = 1.70158;
  30962. return k * k * ((s + 1) * k - s);
  30963. },
  30964. /**
  30965. * @param {number} k
  30966. * @return {number}
  30967. */
  30968. backOut: function (k) {
  30969. var s = 1.70158;
  30970. return --k * k * ((s + 1) * k + s) + 1;
  30971. },
  30972. /**
  30973. * @param {number} k
  30974. * @return {number}
  30975. */
  30976. backInOut: function (k) {
  30977. var s = 1.70158 * 1.525;
  30978. if ((k *= 2) < 1) {
  30979. return 0.5 * (k * k * ((s + 1) * k - s));
  30980. }
  30981. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  30982. },
  30983. // 创建弹跳效果
  30984. /**
  30985. * @param {number} k
  30986. * @return {number}
  30987. */
  30988. bounceIn: function (k) {
  30989. return 1 - easing.bounceOut(1 - k);
  30990. },
  30991. /**
  30992. * @param {number} k
  30993. * @return {number}
  30994. */
  30995. bounceOut: function (k) {
  30996. if (k < 1 / 2.75) {
  30997. return 7.5625 * k * k;
  30998. } else if (k < 2 / 2.75) {
  30999. return 7.5625 * (k -= 1.5 / 2.75) * k + 0.75;
  31000. } else if (k < 2.5 / 2.75) {
  31001. return 7.5625 * (k -= 2.25 / 2.75) * k + 0.9375;
  31002. } else {
  31003. return 7.5625 * (k -= 2.625 / 2.75) * k + 0.984375;
  31004. }
  31005. },
  31006. /**
  31007. * @param {number} k
  31008. * @return {number}
  31009. */
  31010. bounceInOut: function (k) {
  31011. if (k < 0.5) {
  31012. return easing.bounceIn(k * 2) * 0.5;
  31013. }
  31014. return easing.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  31015. }
  31016. };
  31017. var _default = easing;
  31018. module.exports = _default;
  31019. /***/
  31020. }),
  31021. /* 145 */
  31022. /***/ (function (module, exports, __webpack_require__) {
  31023. var LRU = __webpack_require__(60);
  31024. var kCSSColorTable = {
  31025. 'transparent': [0, 0, 0, 0],
  31026. 'aliceblue': [240, 248, 255, 1],
  31027. 'antiquewhite': [250, 235, 215, 1],
  31028. 'aqua': [0, 255, 255, 1],
  31029. 'aquamarine': [127, 255, 212, 1],
  31030. 'azure': [240, 255, 255, 1],
  31031. 'beige': [245, 245, 220, 1],
  31032. 'bisque': [255, 228, 196, 1],
  31033. 'black': [0, 0, 0, 1],
  31034. 'blanchedalmond': [255, 235, 205, 1],
  31035. 'blue': [0, 0, 255, 1],
  31036. 'blueviolet': [138, 43, 226, 1],
  31037. 'brown': [165, 42, 42, 1],
  31038. 'burlywood': [222, 184, 135, 1],
  31039. 'cadetblue': [95, 158, 160, 1],
  31040. 'chartreuse': [127, 255, 0, 1],
  31041. 'chocolate': [210, 105, 30, 1],
  31042. 'coral': [255, 127, 80, 1],
  31043. 'cornflowerblue': [100, 149, 237, 1],
  31044. 'cornsilk': [255, 248, 220, 1],
  31045. 'crimson': [220, 20, 60, 1],
  31046. 'cyan': [0, 255, 255, 1],
  31047. 'darkblue': [0, 0, 139, 1],
  31048. 'darkcyan': [0, 139, 139, 1],
  31049. 'darkgoldenrod': [184, 134, 11, 1],
  31050. 'darkgray': [169, 169, 169, 1],
  31051. 'darkgreen': [0, 100, 0, 1],
  31052. 'darkgrey': [169, 169, 169, 1],
  31053. 'darkkhaki': [189, 183, 107, 1],
  31054. 'darkmagenta': [139, 0, 139, 1],
  31055. 'darkolivegreen': [85, 107, 47, 1],
  31056. 'darkorange': [255, 140, 0, 1],
  31057. 'darkorchid': [153, 50, 204, 1],
  31058. 'darkred': [139, 0, 0, 1],
  31059. 'darksalmon': [233, 150, 122, 1],
  31060. 'darkseagreen': [143, 188, 143, 1],
  31061. 'darkslateblue': [72, 61, 139, 1],
  31062. 'darkslategray': [47, 79, 79, 1],
  31063. 'darkslategrey': [47, 79, 79, 1],
  31064. 'darkturquoise': [0, 206, 209, 1],
  31065. 'darkviolet': [148, 0, 211, 1],
  31066. 'deeppink': [255, 20, 147, 1],
  31067. 'deepskyblue': [0, 191, 255, 1],
  31068. 'dimgray': [105, 105, 105, 1],
  31069. 'dimgrey': [105, 105, 105, 1],
  31070. 'dodgerblue': [30, 144, 255, 1],
  31071. 'firebrick': [178, 34, 34, 1],
  31072. 'floralwhite': [255, 250, 240, 1],
  31073. 'forestgreen': [34, 139, 34, 1],
  31074. 'fuchsia': [255, 0, 255, 1],
  31075. 'gainsboro': [220, 220, 220, 1],
  31076. 'ghostwhite': [248, 248, 255, 1],
  31077. 'gold': [255, 215, 0, 1],
  31078. 'goldenrod': [218, 165, 32, 1],
  31079. 'gray': [128, 128, 128, 1],
  31080. 'green': [0, 128, 0, 1],
  31081. 'greenyellow': [173, 255, 47, 1],
  31082. 'grey': [128, 128, 128, 1],
  31083. 'honeydew': [240, 255, 240, 1],
  31084. 'hotpink': [255, 105, 180, 1],
  31085. 'indianred': [205, 92, 92, 1],
  31086. 'indigo': [75, 0, 130, 1],
  31087. 'ivory': [255, 255, 240, 1],
  31088. 'khaki': [240, 230, 140, 1],
  31089. 'lavender': [230, 230, 250, 1],
  31090. 'lavenderblush': [255, 240, 245, 1],
  31091. 'lawngreen': [124, 252, 0, 1],
  31092. 'lemonchiffon': [255, 250, 205, 1],
  31093. 'lightblue': [173, 216, 230, 1],
  31094. 'lightcoral': [240, 128, 128, 1],
  31095. 'lightcyan': [224, 255, 255, 1],
  31096. 'lightgoldenrodyellow': [250, 250, 210, 1],
  31097. 'lightgray': [211, 211, 211, 1],
  31098. 'lightgreen': [144, 238, 144, 1],
  31099. 'lightgrey': [211, 211, 211, 1],
  31100. 'lightpink': [255, 182, 193, 1],
  31101. 'lightsalmon': [255, 160, 122, 1],
  31102. 'lightseagreen': [32, 178, 170, 1],
  31103. 'lightskyblue': [135, 206, 250, 1],
  31104. 'lightslategray': [119, 136, 153, 1],
  31105. 'lightslategrey': [119, 136, 153, 1],
  31106. 'lightsteelblue': [176, 196, 222, 1],
  31107. 'lightyellow': [255, 255, 224, 1],
  31108. 'lime': [0, 255, 0, 1],
  31109. 'limegreen': [50, 205, 50, 1],
  31110. 'linen': [250, 240, 230, 1],
  31111. 'magenta': [255, 0, 255, 1],
  31112. 'maroon': [128, 0, 0, 1],
  31113. 'mediumaquamarine': [102, 205, 170, 1],
  31114. 'mediumblue': [0, 0, 205, 1],
  31115. 'mediumorchid': [186, 85, 211, 1],
  31116. 'mediumpurple': [147, 112, 219, 1],
  31117. 'mediumseagreen': [60, 179, 113, 1],
  31118. 'mediumslateblue': [123, 104, 238, 1],
  31119. 'mediumspringgreen': [0, 250, 154, 1],
  31120. 'mediumturquoise': [72, 209, 204, 1],
  31121. 'mediumvioletred': [199, 21, 133, 1],
  31122. 'midnightblue': [25, 25, 112, 1],
  31123. 'mintcream': [245, 255, 250, 1],
  31124. 'mistyrose': [255, 228, 225, 1],
  31125. 'moccasin': [255, 228, 181, 1],
  31126. 'navajowhite': [255, 222, 173, 1],
  31127. 'navy': [0, 0, 128, 1],
  31128. 'oldlace': [253, 245, 230, 1],
  31129. 'olive': [128, 128, 0, 1],
  31130. 'olivedrab': [107, 142, 35, 1],
  31131. 'orange': [255, 165, 0, 1],
  31132. 'orangered': [255, 69, 0, 1],
  31133. 'orchid': [218, 112, 214, 1],
  31134. 'palegoldenrod': [238, 232, 170, 1],
  31135. 'palegreen': [152, 251, 152, 1],
  31136. 'paleturquoise': [175, 238, 238, 1],
  31137. 'palevioletred': [219, 112, 147, 1],
  31138. 'papayawhip': [255, 239, 213, 1],
  31139. 'peachpuff': [255, 218, 185, 1],
  31140. 'peru': [205, 133, 63, 1],
  31141. 'pink': [255, 192, 203, 1],
  31142. 'plum': [221, 160, 221, 1],
  31143. 'powderblue': [176, 224, 230, 1],
  31144. 'purple': [128, 0, 128, 1],
  31145. 'red': [255, 0, 0, 1],
  31146. 'rosybrown': [188, 143, 143, 1],
  31147. 'royalblue': [65, 105, 225, 1],
  31148. 'saddlebrown': [139, 69, 19, 1],
  31149. 'salmon': [250, 128, 114, 1],
  31150. 'sandybrown': [244, 164, 96, 1],
  31151. 'seagreen': [46, 139, 87, 1],
  31152. 'seashell': [255, 245, 238, 1],
  31153. 'sienna': [160, 82, 45, 1],
  31154. 'silver': [192, 192, 192, 1],
  31155. 'skyblue': [135, 206, 235, 1],
  31156. 'slateblue': [106, 90, 205, 1],
  31157. 'slategray': [112, 128, 144, 1],
  31158. 'slategrey': [112, 128, 144, 1],
  31159. 'snow': [255, 250, 250, 1],
  31160. 'springgreen': [0, 255, 127, 1],
  31161. 'steelblue': [70, 130, 180, 1],
  31162. 'tan': [210, 180, 140, 1],
  31163. 'teal': [0, 128, 128, 1],
  31164. 'thistle': [216, 191, 216, 1],
  31165. 'tomato': [255, 99, 71, 1],
  31166. 'turquoise': [64, 224, 208, 1],
  31167. 'violet': [238, 130, 238, 1],
  31168. 'wheat': [245, 222, 179, 1],
  31169. 'white': [255, 255, 255, 1],
  31170. 'whitesmoke': [245, 245, 245, 1],
  31171. 'yellow': [255, 255, 0, 1],
  31172. 'yellowgreen': [154, 205, 50, 1]
  31173. };
  31174. function clampCssByte(i) {
  31175. // Clamp to integer 0 .. 255.
  31176. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  31177. return i < 0 ? 0 : i > 255 ? 255 : i;
  31178. }
  31179. function clampCssAngle(i) {
  31180. // Clamp to integer 0 .. 360.
  31181. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  31182. return i < 0 ? 0 : i > 360 ? 360 : i;
  31183. }
  31184. function clampCssFloat(f) {
  31185. // Clamp to float 0.0 .. 1.0.
  31186. return f < 0 ? 0 : f > 1 ? 1 : f;
  31187. }
  31188. function parseCssInt(str) {
  31189. // int or percentage.
  31190. if (str.length && str.charAt(str.length - 1) === '%') {
  31191. return clampCssByte(parseFloat(str) / 100 * 255);
  31192. }
  31193. return clampCssByte(parseInt(str, 10));
  31194. }
  31195. function parseCssFloat(str) {
  31196. // float or percentage.
  31197. if (str.length && str.charAt(str.length - 1) === '%') {
  31198. return clampCssFloat(parseFloat(str) / 100);
  31199. }
  31200. return clampCssFloat(parseFloat(str));
  31201. }
  31202. function cssHueToRgb(m1, m2, h) {
  31203. if (h < 0) {
  31204. h += 1;
  31205. } else if (h > 1) {
  31206. h -= 1;
  31207. }
  31208. if (h * 6 < 1) {
  31209. return m1 + (m2 - m1) * h * 6;
  31210. }
  31211. if (h * 2 < 1) {
  31212. return m2;
  31213. }
  31214. if (h * 3 < 2) {
  31215. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  31216. }
  31217. return m1;
  31218. }
  31219. function lerpNumber(a, b, p) {
  31220. return a + (b - a) * p;
  31221. }
  31222. function setRgba(out, r, g, b, a) {
  31223. out[0] = r;
  31224. out[1] = g;
  31225. out[2] = b;
  31226. out[3] = a;
  31227. return out;
  31228. }
  31229. function copyRgba(out, a) {
  31230. out[0] = a[0];
  31231. out[1] = a[1];
  31232. out[2] = a[2];
  31233. out[3] = a[3];
  31234. return out;
  31235. }
  31236. var colorCache = new LRU(20);
  31237. var lastRemovedArr = null;
  31238. function putToCache(colorStr, rgbaArr) {
  31239. // Reuse removed array
  31240. if (lastRemovedArr) {
  31241. copyRgba(lastRemovedArr, rgbaArr);
  31242. }
  31243. lastRemovedArr = colorCache.put(colorStr, lastRemovedArr || rgbaArr.slice());
  31244. }
  31245. /**
  31246. * @param {string} colorStr
  31247. * @param {Array.<number>} out
  31248. * @return {Array.<number>}
  31249. * @memberOf module:zrender/util/color
  31250. */
  31251. function parse(colorStr, rgbaArr) {
  31252. if (!colorStr) {
  31253. return;
  31254. }
  31255. rgbaArr = rgbaArr || [];
  31256. var cached = colorCache.get(colorStr);
  31257. if (cached) {
  31258. return copyRgba(rgbaArr, cached);
  31259. } // colorStr may be not string
  31260. colorStr = colorStr + ''; // Remove all whitespace, not compliant, but should just be more accepting.
  31261. var str = colorStr.replace(/ /g, '').toLowerCase(); // Color keywords (and transparent) lookup.
  31262. if (str in kCSSColorTable) {
  31263. copyRgba(rgbaArr, kCSSColorTable[str]);
  31264. putToCache(colorStr, rgbaArr);
  31265. return rgbaArr;
  31266. } // #abc and #abc123 syntax.
  31267. if (str.charAt(0) === '#') {
  31268. if (str.length === 4) {
  31269. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  31270. if (!(iv >= 0 && iv <= 0xfff)) {
  31271. setRgba(rgbaArr, 0, 0, 0, 1);
  31272. return; // Covers NaN.
  31273. }
  31274. setRgba(rgbaArr, (iv & 0xf00) >> 4 | (iv & 0xf00) >> 8, iv & 0xf0 | (iv & 0xf0) >> 4, iv & 0xf | (iv & 0xf) << 4, 1);
  31275. putToCache(colorStr, rgbaArr);
  31276. return rgbaArr;
  31277. } else if (str.length === 7) {
  31278. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  31279. if (!(iv >= 0 && iv <= 0xffffff)) {
  31280. setRgba(rgbaArr, 0, 0, 0, 1);
  31281. return; // Covers NaN.
  31282. }
  31283. setRgba(rgbaArr, (iv & 0xff0000) >> 16, (iv & 0xff00) >> 8, iv & 0xff, 1);
  31284. putToCache(colorStr, rgbaArr);
  31285. return rgbaArr;
  31286. }
  31287. return;
  31288. }
  31289. var op = str.indexOf('('),
  31290. ep = str.indexOf(')');
  31291. if (op !== -1 && ep + 1 === str.length) {
  31292. var fname = str.substr(0, op);
  31293. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  31294. var alpha = 1; // To allow case fallthrough.
  31295. switch (fname) {
  31296. case 'rgba':
  31297. if (params.length !== 4) {
  31298. setRgba(rgbaArr, 0, 0, 0, 1);
  31299. return;
  31300. }
  31301. alpha = parseCssFloat(params.pop());
  31302. // jshint ignore:line
  31303. // Fall through.
  31304. case 'rgb':
  31305. if (params.length !== 3) {
  31306. setRgba(rgbaArr, 0, 0, 0, 1);
  31307. return;
  31308. }
  31309. setRgba(rgbaArr, parseCssInt(params[0]), parseCssInt(params[1]), parseCssInt(params[2]), alpha);
  31310. putToCache(colorStr, rgbaArr);
  31311. return rgbaArr;
  31312. case 'hsla':
  31313. if (params.length !== 4) {
  31314. setRgba(rgbaArr, 0, 0, 0, 1);
  31315. return;
  31316. }
  31317. params[3] = parseCssFloat(params[3]);
  31318. hsla2rgba(params, rgbaArr);
  31319. putToCache(colorStr, rgbaArr);
  31320. return rgbaArr;
  31321. case 'hsl':
  31322. if (params.length !== 3) {
  31323. setRgba(rgbaArr, 0, 0, 0, 1);
  31324. return;
  31325. }
  31326. hsla2rgba(params, rgbaArr);
  31327. putToCache(colorStr, rgbaArr);
  31328. return rgbaArr;
  31329. default:
  31330. return;
  31331. }
  31332. }
  31333. setRgba(rgbaArr, 0, 0, 0, 1);
  31334. return;
  31335. }
  31336. /**
  31337. * @param {Array.<number>} hsla
  31338. * @param {Array.<number>} rgba
  31339. * @return {Array.<number>} rgba
  31340. */
  31341. function hsla2rgba(hsla, rgba) {
  31342. var h = (parseFloat(hsla[0]) % 360 + 360) % 360 / 360; // 0 .. 1
  31343. // NOTE(deanm): According to the CSS spec s/l should only be
  31344. // percentages, but we don't bother and let float or percentage.
  31345. var s = parseCssFloat(hsla[1]);
  31346. var l = parseCssFloat(hsla[2]);
  31347. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  31348. var m1 = l * 2 - m2;
  31349. rgba = rgba || [];
  31350. setRgba(rgba, clampCssByte(cssHueToRgb(m1, m2, h + 1 / 3) * 255), clampCssByte(cssHueToRgb(m1, m2, h) * 255), clampCssByte(cssHueToRgb(m1, m2, h - 1 / 3) * 255), 1);
  31351. if (hsla.length === 4) {
  31352. rgba[3] = hsla[3];
  31353. }
  31354. return rgba;
  31355. }
  31356. /**
  31357. * @param {Array.<number>} rgba
  31358. * @return {Array.<number>} hsla
  31359. */
  31360. function rgba2hsla(rgba) {
  31361. if (!rgba) {
  31362. return;
  31363. } // RGB from 0 to 255
  31364. var R = rgba[0] / 255;
  31365. var G = rgba[1] / 255;
  31366. var B = rgba[2] / 255;
  31367. var vMin = Math.min(R, G, B); // Min. value of RGB
  31368. var vMax = Math.max(R, G, B); // Max. value of RGB
  31369. var delta = vMax - vMin; // Delta RGB value
  31370. var L = (vMax + vMin) / 2;
  31371. var H;
  31372. var S; // HSL results from 0 to 1
  31373. if (delta === 0) {
  31374. H = 0;
  31375. S = 0;
  31376. } else {
  31377. if (L < 0.5) {
  31378. S = delta / (vMax + vMin);
  31379. } else {
  31380. S = delta / (2 - vMax - vMin);
  31381. }
  31382. var deltaR = ((vMax - R) / 6 + delta / 2) / delta;
  31383. var deltaG = ((vMax - G) / 6 + delta / 2) / delta;
  31384. var deltaB = ((vMax - B) / 6 + delta / 2) / delta;
  31385. if (R === vMax) {
  31386. H = deltaB - deltaG;
  31387. } else if (G === vMax) {
  31388. H = 1 / 3 + deltaR - deltaB;
  31389. } else if (B === vMax) {
  31390. H = 2 / 3 + deltaG - deltaR;
  31391. }
  31392. if (H < 0) {
  31393. H += 1;
  31394. }
  31395. if (H > 1) {
  31396. H -= 1;
  31397. }
  31398. }
  31399. var hsla = [H * 360, S, L];
  31400. if (rgba[3] != null) {
  31401. hsla.push(rgba[3]);
  31402. }
  31403. return hsla;
  31404. }
  31405. /**
  31406. * @param {string} color
  31407. * @param {number} level
  31408. * @return {string}
  31409. * @memberOf module:zrender/util/color
  31410. */
  31411. function lift(color, level) {
  31412. var colorArr = parse(color);
  31413. if (colorArr) {
  31414. for (var i = 0; i < 3; i++) {
  31415. if (level < 0) {
  31416. colorArr[i] = colorArr[i] * (1 - level) | 0;
  31417. } else {
  31418. colorArr[i] = (255 - colorArr[i]) * level + colorArr[i] | 0;
  31419. }
  31420. if (colorArr[i] > 255) {
  31421. colorArr[i] = 255;
  31422. } else if (color[i] < 0) {
  31423. colorArr[i] = 0;
  31424. }
  31425. }
  31426. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  31427. }
  31428. }
  31429. /**
  31430. * @param {string} color
  31431. * @return {string}
  31432. * @memberOf module:zrender/util/color
  31433. */
  31434. function toHex(color) {
  31435. var colorArr = parse(color);
  31436. if (colorArr) {
  31437. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + +colorArr[2]).toString(16).slice(1);
  31438. }
  31439. }
  31440. /**
  31441. * Map value to color. Faster than lerp methods because color is represented by rgba array.
  31442. * @param {number} normalizedValue A float between 0 and 1.
  31443. * @param {Array.<Array.<number>>} colors List of rgba color array
  31444. * @param {Array.<number>} [out] Mapped gba color array
  31445. * @return {Array.<number>} will be null/undefined if input illegal.
  31446. */
  31447. function fastLerp(normalizedValue, colors, out) {
  31448. if (!(colors && colors.length) || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  31449. return;
  31450. }
  31451. out = out || [];
  31452. var value = normalizedValue * (colors.length - 1);
  31453. var leftIndex = Math.floor(value);
  31454. var rightIndex = Math.ceil(value);
  31455. var leftColor = colors[leftIndex];
  31456. var rightColor = colors[rightIndex];
  31457. var dv = value - leftIndex;
  31458. out[0] = clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv));
  31459. out[1] = clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv));
  31460. out[2] = clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv));
  31461. out[3] = clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv));
  31462. return out;
  31463. }
  31464. /**
  31465. * @deprecated
  31466. */
  31467. var fastMapToColor = fastLerp;
  31468. /**
  31469. * @param {number} normalizedValue A float between 0 and 1.
  31470. * @param {Array.<string>} colors Color list.
  31471. * @param {boolean=} fullOutput Default false.
  31472. * @return {(string|Object)} Result color. If fullOutput,
  31473. * return {color: ..., leftIndex: ..., rightIndex: ..., value: ...},
  31474. * @memberOf module:zrender/util/color
  31475. */
  31476. function lerp(normalizedValue, colors, fullOutput) {
  31477. if (!(colors && colors.length) || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  31478. return;
  31479. }
  31480. var value = normalizedValue * (colors.length - 1);
  31481. var leftIndex = Math.floor(value);
  31482. var rightIndex = Math.ceil(value);
  31483. var leftColor = parse(colors[leftIndex]);
  31484. var rightColor = parse(colors[rightIndex]);
  31485. var dv = value - leftIndex;
  31486. var color = stringify([clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv)), clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv)), clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv)), clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv))], 'rgba');
  31487. return fullOutput ? {
  31488. color: color,
  31489. leftIndex: leftIndex,
  31490. rightIndex: rightIndex,
  31491. value: value
  31492. } : color;
  31493. }
  31494. /**
  31495. * @deprecated
  31496. */
  31497. var mapToColor = lerp;
  31498. /**
  31499. * @param {string} color
  31500. * @param {number=} h 0 ~ 360, ignore when null.
  31501. * @param {number=} s 0 ~ 1, ignore when null.
  31502. * @param {number=} l 0 ~ 1, ignore when null.
  31503. * @return {string} Color string in rgba format.
  31504. * @memberOf module:zrender/util/color
  31505. */
  31506. function modifyHSL(color, h, s, l) {
  31507. color = parse(color);
  31508. if (color) {
  31509. color = rgba2hsla(color);
  31510. h != null && (color[0] = clampCssAngle(h));
  31511. s != null && (color[1] = parseCssFloat(s));
  31512. l != null && (color[2] = parseCssFloat(l));
  31513. return stringify(hsla2rgba(color), 'rgba');
  31514. }
  31515. }
  31516. /**
  31517. * @param {string} color
  31518. * @param {number=} alpha 0 ~ 1
  31519. * @return {string} Color string in rgba format.
  31520. * @memberOf module:zrender/util/color
  31521. */
  31522. function modifyAlpha(color, alpha) {
  31523. color = parse(color);
  31524. if (color && alpha != null) {
  31525. color[3] = clampCssFloat(alpha);
  31526. return stringify(color, 'rgba');
  31527. }
  31528. }
  31529. /**
  31530. * @param {Array.<number>} arrColor like [12,33,44,0.4]
  31531. * @param {string} type 'rgba', 'hsva', ...
  31532. * @return {string} Result color. (If input illegal, return undefined).
  31533. */
  31534. function stringify(arrColor, type) {
  31535. if (!arrColor || !arrColor.length) {
  31536. return;
  31537. }
  31538. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  31539. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  31540. colorStr += ',' + arrColor[3];
  31541. }
  31542. return type + '(' + colorStr + ')';
  31543. }
  31544. exports.parse = parse;
  31545. exports.lift = lift;
  31546. exports.toHex = toHex;
  31547. exports.fastLerp = fastLerp;
  31548. exports.fastMapToColor = fastMapToColor;
  31549. exports.lerp = lerp;
  31550. exports.mapToColor = mapToColor;
  31551. exports.modifyHSL = modifyHSL;
  31552. exports.modifyAlpha = modifyAlpha;
  31553. exports.stringify = stringify;
  31554. /***/
  31555. }),
  31556. /* 146 */
  31557. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  31558. "use strict";
  31559. /* harmony default export */ __webpack_exports__["a"] = ("\n@export clay.util.rand\nhighp float rand(vec2 uv) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot(uv.xy, vec2(a,b)), sn = mod(dt, 3.141592653589793);\n return fract(sin(sn) * c);\n}\n@end\n@export clay.util.calculate_attenuation\nuniform float attenuationFactor : 5.0;\nfloat lightAttenuation(float dist, float range)\n{\n float attenuation = 1.0;\n attenuation = dist*dist/(range*range+1.0);\n float att_s = attenuationFactor;\n attenuation = 1.0/(attenuation*att_s+1.0);\n att_s = 1.0/(att_s+1.0);\n attenuation = attenuation - att_s;\n attenuation /= 1.0 - att_s;\n return clamp(attenuation, 0.0, 1.0);\n}\n@end\n@export clay.util.edge_factor\n#ifdef SUPPORT_STANDARD_DERIVATIVES\nfloat edgeFactor(float width)\n{\n vec3 d = fwidth(v_Barycentric);\n vec3 a3 = smoothstep(vec3(0.0), d * width, v_Barycentric);\n return min(min(a3.x, a3.y), a3.z);\n}\n#else\nfloat edgeFactor(float width)\n{\n return 1.0;\n}\n#endif\n@end\n@export clay.util.encode_float\nvec4 encodeFloat(const in float depth)\n{\n const vec4 bitShifts = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);\n const vec4 bit_mask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);\n vec4 res = fract(depth * bitShifts);\n res -= res.xxyz * bit_mask;\n return res;\n}\n@end\n@export clay.util.decode_float\nfloat decodeFloat(const in vec4 color)\n{\n const vec4 bitShifts = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0);\n return dot(color, bitShifts);\n}\n@end\n@export clay.util.float\n@import clay.util.encode_float\n@import clay.util.decode_float\n@end\n@export clay.util.rgbm_decode\nvec3 RGBMDecode(vec4 rgbm, float range) {\n return range * rgbm.rgb * rgbm.a;\n}\n@end\n@export clay.util.rgbm_encode\nvec4 RGBMEncode(vec3 color, float range) {\n if (dot(color, color) == 0.0) {\n return vec4(0.0);\n }\n vec4 rgbm;\n color /= range;\n rgbm.a = clamp(max(max(color.r, color.g), max(color.b, 1e-6)), 0.0, 1.0);\n rgbm.a = ceil(rgbm.a * 255.0) / 255.0;\n rgbm.rgb = color / rgbm.a;\n return rgbm;\n}\n@end\n@export clay.util.rgbm\n@import clay.util.rgbm_decode\n@import clay.util.rgbm_encode\nvec4 decodeHDR(vec4 color)\n{\n#if defined(RGBM_DECODE) || defined(RGBM)\n return vec4(RGBMDecode(color, 8.12), 1.0);\n#else\n return color;\n#endif\n}\nvec4 encodeHDR(vec4 color)\n{\n#if defined(RGBM_ENCODE) || defined(RGBM)\n return RGBMEncode(color.xyz, 8.12);\n#else\n return color;\n#endif\n}\n@end\n@export clay.util.srgb\nvec4 sRGBToLinear(in vec4 value) {\n return vec4(mix(pow(value.rgb * 0.9478672986 + vec3(0.0521327014), vec3(2.4)), value.rgb * 0.0773993808, vec3(lessThanEqual(value.rgb, vec3(0.04045)))), value.w);\n}\nvec4 linearTosRGB(in vec4 value) {\n return vec4(mix(pow(value.rgb, vec3(0.41666)) * 1.055 - vec3(0.055), value.rgb * 12.92, vec3(lessThanEqual(value.rgb, vec3(0.0031308)))), value.w);\n}\n@end\n@export clay.chunk.skinning_header\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n#ifdef USE_SKIN_MATRICES_TEXTURE\nuniform sampler2D skinMatricesTexture : ignore;\nuniform float skinMatricesTextureSize: ignore;\nmat4 getSkinMatrix(sampler2D tex, float idx) {\n float j = idx * 4.0;\n float x = mod(j, skinMatricesTextureSize);\n float y = floor(j / skinMatricesTextureSize) + 0.5;\n vec2 scale = vec2(skinMatricesTextureSize);\n return mat4(\n texture2D(tex, vec2(x + 0.5, y) / scale),\n texture2D(tex, vec2(x + 1.5, y) / scale),\n texture2D(tex, vec2(x + 2.5, y) / scale),\n texture2D(tex, vec2(x + 3.5, y) / scale)\n );\n}\nmat4 getSkinMatrix(float idx) {\n return getSkinMatrix(skinMatricesTexture, idx);\n}\n#else\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\nmat4 getSkinMatrix(float idx) {\n return skinMatrix[int(idx)];\n}\n#endif\n#endif\n@end\n@export clay.chunk.skin_matrix\nmat4 skinMatrixWS = getSkinMatrix(joint.x) * weight.x;\nif (weight.y > 1e-4)\n{\n skinMatrixWS += getSkinMatrix(joint.y) * weight.y;\n}\nif (weight.z > 1e-4)\n{\n skinMatrixWS += getSkinMatrix(joint.z) * weight.z;\n}\nfloat weightW = 1.0-weight.x-weight.y-weight.z;\nif (weightW > 1e-4)\n{\n skinMatrixWS += getSkinMatrix(joint.w) * weightW;\n}\n@end\n@export clay.util.parallax_correct\nvec3 parallaxCorrect(in vec3 dir, in vec3 pos, in vec3 boxMin, in vec3 boxMax) {\n vec3 first = (boxMax - pos) / dir;\n vec3 second = (boxMin - pos) / dir;\n vec3 further = max(first, second);\n float dist = min(further.x, min(further.y, further.z));\n vec3 fixedPos = pos + dir * dist;\n vec3 boxCenter = (boxMax + boxMin) * 0.5;\n return normalize(fixedPos - boxCenter);\n}\n@end\n@export clay.util.clamp_sample\nvec4 clampSample(const in sampler2D texture, const in vec2 coord)\n{\n#ifdef STEREO\n float eye = step(0.5, coord.x) * 0.5;\n vec2 coordClamped = clamp(coord, vec2(eye, 0.0), vec2(0.5 + eye, 1.0));\n#else\n vec2 coordClamped = clamp(coord, vec2(0.0), vec2(1.0));\n#endif\n return texture2D(texture, coordClamped);\n}\n@end\n@export clay.util.ACES\nvec3 ACESToneMapping(vec3 color)\n{\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\n@end");
  31560. /***/
  31561. }),
  31562. /* 147 */
  31563. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  31564. "use strict";
  31565. /* harmony default export */ __webpack_exports__["a"] = ("\n@export ecgl.common.transformUniforms\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform mat4 worldInverseTranspose : WORLDINVERSETRANSPOSE;\nuniform mat4 world : WORLD;\n@end\n\n@export ecgl.common.attributes\nattribute vec3 position : POSITION;\nattribute vec2 texcoord : TEXCOORD_0;\nattribute vec3 normal : NORMAL;\n@end\n\n@export ecgl.common.uv.header\nuniform vec2 uvRepeat : [1.0, 1.0];\nuniform vec2 uvOffset : [0.0, 0.0];\nuniform vec2 detailUvRepeat : [1.0, 1.0];\nuniform vec2 detailUvOffset : [0.0, 0.0];\n\nvarying vec2 v_Texcoord;\nvarying vec2 v_DetailTexcoord;\n@end\n\n@export ecgl.common.uv.main\nv_Texcoord = texcoord * uvRepeat + uvOffset;\nv_DetailTexcoord = texcoord * detailUvRepeat + detailUvOffset;\n@end\n\n@export ecgl.common.uv.fragmentHeader\nvarying vec2 v_Texcoord;\nvarying vec2 v_DetailTexcoord;\n@end\n\n\n@export ecgl.common.albedo.main\n\n vec4 albedoTexel = vec4(1.0);\n#ifdef DIFFUSEMAP_ENABLED\n albedoTexel = texture2D(diffuseMap, v_Texcoord);\n #ifdef SRGB_DECODE\n albedoTexel = sRGBToLinear(albedoTexel);\n #endif\n#endif\n\n#ifdef DETAILMAP_ENABLED\n vec4 detailTexel = texture2D(detailMap, v_DetailTexcoord);\n #ifdef SRGB_DECODE\n detailTexel = sRGBToLinear(detailTexel);\n #endif\n albedoTexel.rgb = mix(albedoTexel.rgb, detailTexel.rgb, detailTexel.a);\n albedoTexel.a = detailTexel.a + (1.0 - detailTexel.a) * albedoTexel.a;\n#endif\n\n@end\n\n@export ecgl.common.wireframe.vertexHeader\n\n#ifdef WIREFRAME_QUAD\nattribute vec4 barycentric;\nvarying vec4 v_Barycentric;\n#elif defined(WIREFRAME_TRIANGLE)\nattribute vec3 barycentric;\nvarying vec3 v_Barycentric;\n#endif\n\n@end\n\n@export ecgl.common.wireframe.vertexMain\n\n#if defined(WIREFRAME_QUAD) || defined(WIREFRAME_TRIANGLE)\n v_Barycentric = barycentric;\n#endif\n\n@end\n\n\n@export ecgl.common.wireframe.fragmentHeader\n\nuniform float wireframeLineWidth : 1;\nuniform vec4 wireframeLineColor: [0, 0, 0, 0.5];\n\n#ifdef WIREFRAME_QUAD\nvarying vec4 v_Barycentric;\nfloat edgeFactor () {\n vec4 d = fwidth(v_Barycentric);\n vec4 a4 = smoothstep(vec4(0.0), d * wireframeLineWidth, v_Barycentric);\n return min(min(min(a4.x, a4.y), a4.z), a4.w);\n}\n#elif defined(WIREFRAME_TRIANGLE)\nvarying vec3 v_Barycentric;\nfloat edgeFactor () {\n vec3 d = fwidth(v_Barycentric);\n vec3 a3 = smoothstep(vec3(0.0), d * wireframeLineWidth, v_Barycentric);\n return min(min(a3.x, a3.y), a3.z);\n}\n#endif\n\n@end\n\n\n@export ecgl.common.wireframe.fragmentMain\n\n#if defined(WIREFRAME_QUAD) || defined(WIREFRAME_TRIANGLE)\n if (wireframeLineWidth > 0.) {\n vec4 lineColor = wireframeLineColor;\n#ifdef SRGB_DECODE\n lineColor = sRGBToLinear(lineColor);\n#endif\n\n gl_FragColor.rgb = mix(gl_FragColor.rgb, lineColor.rgb, (1.0 - edgeFactor()) * lineColor.a);\n }\n#endif\n@end\n\n\n\n\n@export ecgl.common.bumpMap.header\n\n#ifdef BUMPMAP_ENABLED\nuniform sampler2D bumpMap;\nuniform float bumpScale : 1.0;\n\n\nvec3 bumpNormal(vec3 surfPos, vec3 surfNormal, vec3 baseNormal)\n{\n vec2 dSTdx = dFdx(v_Texcoord);\n vec2 dSTdy = dFdy(v_Texcoord);\n\n float Hll = bumpScale * texture2D(bumpMap, v_Texcoord).x;\n float dHx = bumpScale * texture2D(bumpMap, v_Texcoord + dSTdx).x - Hll;\n float dHy = bumpScale * texture2D(bumpMap, v_Texcoord + dSTdy).x - Hll;\n\n vec3 vSigmaX = dFdx(surfPos);\n vec3 vSigmaY = dFdy(surfPos);\n vec3 vN = surfNormal;\n\n vec3 R1 = cross(vSigmaY, vN);\n vec3 R2 = cross(vN, vSigmaX);\n\n float fDet = dot(vSigmaX, R1);\n\n vec3 vGrad = sign(fDet) * (dHx * R1 + dHy * R2);\n return normalize(abs(fDet) * baseNormal - vGrad);\n\n}\n#endif\n\n@end\n\n@export ecgl.common.normalMap.vertexHeader\n\n#ifdef NORMALMAP_ENABLED\nattribute vec4 tangent : TANGENT;\nvarying vec3 v_Tangent;\nvarying vec3 v_Bitangent;\n#endif\n\n@end\n\n@export ecgl.common.normalMap.vertexMain\n\n#ifdef NORMALMAP_ENABLED\n if (dot(tangent, tangent) > 0.0) {\n v_Tangent = normalize((worldInverseTranspose * vec4(tangent.xyz, 0.0)).xyz);\n v_Bitangent = normalize(cross(v_Normal, v_Tangent) * tangent.w);\n }\n#endif\n\n@end\n\n\n@export ecgl.common.normalMap.fragmentHeader\n\n#ifdef NORMALMAP_ENABLED\nuniform sampler2D normalMap;\nvarying vec3 v_Tangent;\nvarying vec3 v_Bitangent;\n#endif\n\n@end\n\n@export ecgl.common.normalMap.fragmentMain\n#ifdef NORMALMAP_ENABLED\n if (dot(v_Tangent, v_Tangent) > 0.0) {\n vec3 normalTexel = texture2D(normalMap, v_DetailTexcoord).xyz;\n if (dot(normalTexel, normalTexel) > 0.0) { N = normalTexel * 2.0 - 1.0;\n mat3 tbn = mat3(v_Tangent, v_Bitangent, v_Normal);\n N = normalize(tbn * N);\n }\n }\n#endif\n@end\n\n\n\n@export ecgl.common.vertexAnimation.header\n\n#ifdef VERTEX_ANIMATION\nattribute vec3 prevPosition;\nattribute vec3 prevNormal;\nuniform float percent;\n#endif\n\n@end\n\n@export ecgl.common.vertexAnimation.main\n\n#ifdef VERTEX_ANIMATION\n vec3 pos = mix(prevPosition, position, percent);\n vec3 norm = mix(prevNormal, normal, percent);\n#else\n vec3 pos = position;\n vec3 norm = normal;\n#endif\n\n@end\n\n\n@export ecgl.common.ssaoMap.header\n#ifdef SSAOMAP_ENABLED\nuniform sampler2D ssaoMap;\nuniform vec4 viewport : VIEWPORT;\n#endif\n@end\n\n@export ecgl.common.ssaoMap.main\n float ao = 1.0;\n#ifdef SSAOMAP_ENABLED\n ao = texture2D(ssaoMap, (gl_FragCoord.xy - viewport.xy) / viewport.zw).r;\n#endif\n@end\n\n\n\n\n@export ecgl.common.diffuseLayer.header\n\n#if (LAYER_DIFFUSEMAP_COUNT > 0)\nuniform float layerDiffuseIntensity[LAYER_DIFFUSEMAP_COUNT];\nuniform sampler2D layerDiffuseMap[LAYER_DIFFUSEMAP_COUNT];\n#endif\n\n@end\n\n@export ecgl.common.emissiveLayer.header\n\n#if (LAYER_EMISSIVEMAP_COUNT > 0)\nuniform float layerEmissionIntensity[LAYER_EMISSIVEMAP_COUNT];\nuniform sampler2D layerEmissiveMap[LAYER_EMISSIVEMAP_COUNT];\n#endif\n\n@end\n\n@export ecgl.common.layers.header\n@import ecgl.common.diffuseLayer.header\n@import ecgl.common.emissiveLayer.header\n@end\n\n@export ecgl.common.diffuseLayer.main\n\n#if (LAYER_DIFFUSEMAP_COUNT > 0)\n for (int _idx_ = 0; _idx_ < LAYER_DIFFUSEMAP_COUNT; _idx_++) {{\n float intensity = layerDiffuseIntensity[_idx_];\n vec4 texel2 = texture2D(layerDiffuseMap[_idx_], v_Texcoord);\n #ifdef SRGB_DECODE\n texel2 = sRGBToLinear(texel2);\n #endif\n albedoTexel.rgb = mix(albedoTexel.rgb, texel2.rgb * intensity, texel2.a);\n albedoTexel.a = texel2.a + (1.0 - texel2.a) * albedoTexel.a;\n }}\n#endif\n\n@end\n\n@export ecgl.common.emissiveLayer.main\n\n#if (LAYER_EMISSIVEMAP_COUNT > 0)\n for (int _idx_ = 0; _idx_ < LAYER_EMISSIVEMAP_COUNT; _idx_++)\n {{\n vec4 texel2 = texture2D(layerEmissiveMap[_idx_], v_Texcoord) * layerEmissionIntensity[_idx_];\n #ifdef SRGB_DECODE\n texel2 = sRGBToLinear(texel2);\n #endif\n float intensity = layerEmissionIntensity[_idx_];\n gl_FragColor.rgb += texel2.rgb * texel2.a * intensity;\n }}\n#endif\n\n@end\n");
  31566. /***/
  31567. }),
  31568. /* 148 */
  31569. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  31570. "use strict";
  31571. /* harmony default export */ __webpack_exports__["a"] = ("@export ecgl.color.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\n@import ecgl.common.uv.header\n\nattribute vec2 texcoord : TEXCOORD_0;\nattribute vec3 position: POSITION;\n\n@import ecgl.common.wireframe.vertexHeader\n\n#ifdef VERTEX_COLOR\nattribute vec4 a_Color : COLOR;\nvarying vec4 v_Color;\n#endif\n\n#ifdef VERTEX_ANIMATION\nattribute vec3 prevPosition;\nuniform float percent : 1.0;\n#endif\n\nvoid main()\n{\n#ifdef VERTEX_ANIMATION\n vec3 pos = mix(prevPosition, position, percent);\n#else\n vec3 pos = position;\n#endif\n\n gl_Position = worldViewProjection * vec4(pos, 1.0);\n\n @import ecgl.common.uv.main\n\n#ifdef VERTEX_COLOR\n v_Color = a_Color;\n#endif\n\n @import ecgl.common.wireframe.vertexMain\n\n}\n\n@end\n\n@export ecgl.color.fragment\n\n#define LAYER_DIFFUSEMAP_COUNT 0\n#define LAYER_EMISSIVEMAP_COUNT 0\n\nuniform sampler2D diffuseMap;\nuniform sampler2D detailMap;\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\n\n#ifdef VERTEX_COLOR\nvarying vec4 v_Color;\n#endif\n\n@import ecgl.common.layers.header\n\n@import ecgl.common.uv.fragmentHeader\n\n@import ecgl.common.wireframe.fragmentHeader\n\n@import clay.util.srgb\n\nvoid main()\n{\n#ifdef SRGB_DECODE\n gl_FragColor = sRGBToLinear(color);\n#else\n gl_FragColor = color;\n#endif\n\n#ifdef VERTEX_COLOR\n gl_FragColor *= v_Color;\n#endif\n\n @import ecgl.common.albedo.main\n\n @import ecgl.common.diffuseLayer.main\n\n gl_FragColor *= albedoTexel;\n\n @import ecgl.common.emissiveLayer.main\n\n @import ecgl.common.wireframe.fragmentMain\n\n}\n@end");
  31572. /***/
  31573. }),
  31574. /* 149 */
  31575. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  31576. "use strict";
  31577. /* harmony default export */ __webpack_exports__["a"] = ("/**\n * http: */\n\n@export ecgl.lambert.vertex\n\n@import ecgl.common.transformUniforms\n\n@import ecgl.common.uv.header\n\n\n@import ecgl.common.attributes\n\n@import ecgl.common.wireframe.vertexHeader\n\n#ifdef VERTEX_COLOR\nattribute vec4 a_Color : COLOR;\nvarying vec4 v_Color;\n#endif\n\n\n@import ecgl.common.vertexAnimation.header\n\n\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\n\nvoid main()\n{\n @import ecgl.common.uv.main\n\n @import ecgl.common.vertexAnimation.main\n\n\n gl_Position = worldViewProjection * vec4(pos, 1.0);\n\n v_Normal = normalize((worldInverseTranspose * vec4(norm, 0.0)).xyz);\n v_WorldPosition = (world * vec4(pos, 1.0)).xyz;\n\n#ifdef VERTEX_COLOR\n v_Color = a_Color;\n#endif\n\n @import ecgl.common.wireframe.vertexMain\n}\n\n@end\n\n\n@export ecgl.lambert.fragment\n\n#define LAYER_DIFFUSEMAP_COUNT 0\n#define LAYER_EMISSIVEMAP_COUNT 0\n\n#define NORMAL_UP_AXIS 1\n#define NORMAL_FRONT_AXIS 2\n\n@import ecgl.common.uv.fragmentHeader\n\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\n\nuniform sampler2D diffuseMap;\nuniform sampler2D detailMap;\n\n@import ecgl.common.layers.header\n\nuniform float emissionIntensity: 1.0;\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\n\nuniform mat4 viewInverse : VIEWINVERSE;\n\n#ifdef AMBIENT_LIGHT_COUNT\n@import clay.header.ambient_light\n#endif\n#ifdef AMBIENT_SH_LIGHT_COUNT\n@import clay.header.ambient_sh_light\n#endif\n\n#ifdef DIRECTIONAL_LIGHT_COUNT\n@import clay.header.directional_light\n#endif\n\n#ifdef VERTEX_COLOR\nvarying vec4 v_Color;\n#endif\n\n\n@import ecgl.common.ssaoMap.header\n\n@import ecgl.common.bumpMap.header\n\n@import clay.util.srgb\n\n@import ecgl.common.wireframe.fragmentHeader\n\n@import clay.plugin.compute_shadow_map\n\nvoid main()\n{\n#ifdef SRGB_DECODE\n gl_FragColor = sRGBToLinear(color);\n#else\n gl_FragColor = color;\n#endif\n\n#ifdef VERTEX_COLOR\n #ifdef SRGB_DECODE\n gl_FragColor *= sRGBToLinear(v_Color);\n #else\n gl_FragColor *= v_Color;\n #endif\n#endif\n\n @import ecgl.common.albedo.main\n\n @import ecgl.common.diffuseLayer.main\n\n gl_FragColor *= albedoTexel;\n\n vec3 N = v_Normal;\n#ifdef DOUBLE_SIDED\n vec3 eyePos = viewInverse[3].xyz;\n vec3 V = normalize(eyePos - v_WorldPosition);\n\n if (dot(N, V) < 0.0) {\n N = -N;\n }\n#endif\n\n float ambientFactor = 1.0;\n\n#ifdef BUMPMAP_ENABLED\n N = bumpNormal(v_WorldPosition, v_Normal, N);\n ambientFactor = dot(v_Normal, N);\n#endif\n\n vec3 N2 = vec3(N.x, N[NORMAL_UP_AXIS], N[NORMAL_FRONT_AXIS]);\n\n vec3 diffuseColor = vec3(0.0, 0.0, 0.0);\n\n @import ecgl.common.ssaoMap.main\n\n#ifdef AMBIENT_LIGHT_COUNT\n for(int i = 0; i < AMBIENT_LIGHT_COUNT; i++)\n {\n diffuseColor += ambientLightColor[i] * ambientFactor * ao;\n }\n#endif\n#ifdef AMBIENT_SH_LIGHT_COUNT\n for(int _idx_ = 0; _idx_ < AMBIENT_SH_LIGHT_COUNT; _idx_++)\n {{\n diffuseColor += calcAmbientSHLight(_idx_, N2) * ambientSHLightColor[_idx_] * ao;\n }}\n#endif\n#ifdef DIRECTIONAL_LIGHT_COUNT\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsDir[DIRECTIONAL_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfDirectionalLights(v_WorldPosition, shadowContribsDir);\n }\n#endif\n for(int i = 0; i < DIRECTIONAL_LIGHT_COUNT; i++)\n {\n vec3 lightDirection = -directionalLightDirection[i];\n vec3 lightColor = directionalLightColor[i];\n\n float shadowContrib = 1.0;\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n if (shadowEnabled)\n {\n shadowContrib = shadowContribsDir[i];\n }\n#endif\n\n float ndl = dot(N, normalize(lightDirection)) * shadowContrib;\n\n diffuseColor += lightColor * clamp(ndl, 0.0, 1.0);\n }\n#endif\n\n gl_FragColor.rgb *= diffuseColor;\n\n @import ecgl.common.emissiveLayer.main\n\n @import ecgl.common.wireframe.fragmentMain\n}\n\n@end");
  31578. /***/
  31579. }),
  31580. /* 150 */
  31581. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  31582. "use strict";
  31583. /* harmony default export */ __webpack_exports__["a"] = ("@export ecgl.realistic.vertex\n\n@import ecgl.common.transformUniforms\n\n@import ecgl.common.uv.header\n\n@import ecgl.common.attributes\n\n\n@import ecgl.common.wireframe.vertexHeader\n\n#ifdef VERTEX_COLOR\nattribute vec4 a_Color : COLOR;\nvarying vec4 v_Color;\n#endif\n\n#ifdef NORMALMAP_ENABLED\nattribute vec4 tangent : TANGENT;\nvarying vec3 v_Tangent;\nvarying vec3 v_Bitangent;\n#endif\n\n@import ecgl.common.vertexAnimation.header\n\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\n\nvoid main()\n{\n\n @import ecgl.common.uv.main\n\n @import ecgl.common.vertexAnimation.main\n\n gl_Position = worldViewProjection * vec4(pos, 1.0);\n\n v_Normal = normalize((worldInverseTranspose * vec4(norm, 0.0)).xyz);\n v_WorldPosition = (world * vec4(pos, 1.0)).xyz;\n\n#ifdef VERTEX_COLOR\n v_Color = a_Color;\n#endif\n\n#ifdef NORMALMAP_ENABLED\n v_Tangent = normalize((worldInverseTranspose * vec4(tangent.xyz, 0.0)).xyz);\n v_Bitangent = normalize(cross(v_Normal, v_Tangent) * tangent.w);\n#endif\n\n @import ecgl.common.wireframe.vertexMain\n\n}\n\n@end\n\n\n\n@export ecgl.realistic.fragment\n\n#define LAYER_DIFFUSEMAP_COUNT 0\n#define LAYER_EMISSIVEMAP_COUNT 0\n#define PI 3.14159265358979\n#define ROUGHNESS_CHANEL 0\n#define METALNESS_CHANEL 1\n\n#define NORMAL_UP_AXIS 1\n#define NORMAL_FRONT_AXIS 2\n\n#ifdef VERTEX_COLOR\nvarying vec4 v_Color;\n#endif\n\n@import ecgl.common.uv.fragmentHeader\n\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\n\nuniform sampler2D diffuseMap;\n\nuniform sampler2D detailMap;\nuniform sampler2D metalnessMap;\nuniform sampler2D roughnessMap;\n\n@import ecgl.common.layers.header\n\nuniform float emissionIntensity: 1.0;\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\n\nuniform float metalness : 0.0;\nuniform float roughness : 0.5;\n\nuniform mat4 viewInverse : VIEWINVERSE;\n\n#ifdef AMBIENT_LIGHT_COUNT\n@import clay.header.ambient_light\n#endif\n\n#ifdef AMBIENT_SH_LIGHT_COUNT\n@import clay.header.ambient_sh_light\n#endif\n\n#ifdef AMBIENT_CUBEMAP_LIGHT_COUNT\n@import clay.header.ambient_cubemap_light\n#endif\n\n#ifdef DIRECTIONAL_LIGHT_COUNT\n@import clay.header.directional_light\n#endif\n\n@import ecgl.common.normalMap.fragmentHeader\n\n@import ecgl.common.ssaoMap.header\n\n@import ecgl.common.bumpMap.header\n\n@import clay.util.srgb\n\n@import clay.util.rgbm\n\n@import ecgl.common.wireframe.fragmentHeader\n\n@import clay.plugin.compute_shadow_map\n\nvec3 F_Schlick(float ndv, vec3 spec) {\n return spec + (1.0 - spec) * pow(1.0 - ndv, 5.0);\n}\n\nfloat D_Phong(float g, float ndh) {\n float a = pow(8192.0, g);\n return (a + 2.0) / 8.0 * pow(ndh, a);\n}\n\nvoid main()\n{\n vec4 albedoColor = color;\n\n vec3 eyePos = viewInverse[3].xyz;\n vec3 V = normalize(eyePos - v_WorldPosition);\n#ifdef VERTEX_COLOR\n #ifdef SRGB_DECODE\n albedoColor *= sRGBToLinear(v_Color);\n #else\n albedoColor *= v_Color;\n #endif\n#endif\n\n @import ecgl.common.albedo.main\n\n @import ecgl.common.diffuseLayer.main\n\n albedoColor *= albedoTexel;\n\n float m = metalness;\n\n#ifdef METALNESSMAP_ENABLED\n float m2 = texture2D(metalnessMap, v_DetailTexcoord)[METALNESS_CHANEL];\n m = clamp(m2 + (m - 0.5) * 2.0, 0.0, 1.0);\n#endif\n\n vec3 baseColor = albedoColor.rgb;\n albedoColor.rgb = baseColor * (1.0 - m);\n vec3 specFactor = mix(vec3(0.04), baseColor, m);\n\n float g = 1.0 - roughness;\n\n#ifdef ROUGHNESSMAP_ENABLED\n float g2 = 1.0 - texture2D(roughnessMap, v_DetailTexcoord)[ROUGHNESS_CHANEL];\n g = clamp(g2 + (g - 0.5) * 2.0, 0.0, 1.0);\n#endif\n\n vec3 N = v_Normal;\n\n#ifdef DOUBLE_SIDED\n if (dot(N, V) < 0.0) {\n N = -N;\n }\n#endif\n\n float ambientFactor = 1.0;\n\n#ifdef BUMPMAP_ENABLED\n N = bumpNormal(v_WorldPosition, v_Normal, N);\n ambientFactor = dot(v_Normal, N);\n#endif\n\n@import ecgl.common.normalMap.fragmentMain\n\n vec3 N2 = vec3(N.x, N[NORMAL_UP_AXIS], N[NORMAL_FRONT_AXIS]);\n\n vec3 diffuseTerm = vec3(0.0);\n vec3 specularTerm = vec3(0.0);\n\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n vec3 fresnelTerm = F_Schlick(ndv, specFactor);\n\n @import ecgl.common.ssaoMap.main\n\n#ifdef AMBIENT_LIGHT_COUNT\n for(int _idx_ = 0; _idx_ < AMBIENT_LIGHT_COUNT; _idx_++)\n {{\n diffuseTerm += ambientLightColor[_idx_] * ambientFactor * ao;\n }}\n#endif\n\n#ifdef AMBIENT_SH_LIGHT_COUNT\n for(int _idx_ = 0; _idx_ < AMBIENT_SH_LIGHT_COUNT; _idx_++)\n {{\n diffuseTerm += calcAmbientSHLight(_idx_, N2) * ambientSHLightColor[_idx_] * ao;\n }}\n#endif\n\n#ifdef DIRECTIONAL_LIGHT_COUNT\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsDir[DIRECTIONAL_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfDirectionalLights(v_WorldPosition, shadowContribsDir);\n }\n#endif\n for(int _idx_ = 0; _idx_ < DIRECTIONAL_LIGHT_COUNT; _idx_++)\n {{\n vec3 L = -directionalLightDirection[_idx_];\n vec3 lc = directionalLightColor[_idx_];\n\n vec3 H = normalize(L + V);\n float ndl = clamp(dot(N, normalize(L)), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n\n float shadowContrib = 1.0;\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n if (shadowEnabled)\n {\n shadowContrib = shadowContribsDir[_idx_];\n }\n#endif\n\n vec3 li = lc * ndl * shadowContrib;\n\n diffuseTerm += li;\n specularTerm += li * fresnelTerm * D_Phong(g, ndh);\n }}\n#endif\n\n\n#ifdef AMBIENT_CUBEMAP_LIGHT_COUNT\n vec3 L = reflect(-V, N);\n L = vec3(L.x, L[NORMAL_UP_AXIS], L[NORMAL_FRONT_AXIS]);\n float rough2 = clamp(1.0 - g, 0.0, 1.0);\n float bias2 = rough2 * 5.0;\n vec2 brdfParam2 = texture2D(ambientCubemapLightBRDFLookup[0], vec2(rough2, ndv)).xy;\n vec3 envWeight2 = specFactor * brdfParam2.x + brdfParam2.y;\n vec3 envTexel2;\n for(int _idx_ = 0; _idx_ < AMBIENT_CUBEMAP_LIGHT_COUNT; _idx_++)\n {{\n envTexel2 = RGBMDecode(textureCubeLodEXT(ambientCubemapLightCubemap[_idx_], L, bias2), 8.12);\n specularTerm += ambientCubemapLightColor[_idx_] * envTexel2 * envWeight2 * ao;\n }}\n#endif\n\n gl_FragColor.rgb = albedoColor.rgb * diffuseTerm + specularTerm;\n gl_FragColor.a = albedoColor.a;\n\n#ifdef SRGB_ENCODE\n gl_FragColor = linearTosRGB(gl_FragColor);\n#endif\n\n @import ecgl.common.emissiveLayer.main\n\n @import ecgl.common.wireframe.fragmentMain\n}\n\n@end");
  31584. /***/
  31585. }),
  31586. /* 151 */
  31587. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  31588. "use strict";
  31589. /* harmony default export */ __webpack_exports__["a"] = ("@export ecgl.hatching.vertex\n\n@import ecgl.realistic.vertex\n\n@end\n\n\n@export ecgl.hatching.fragment\n\n#define NORMAL_UP_AXIS 1\n#define NORMAL_FRONT_AXIS 2\n\n@import ecgl.common.uv.fragmentHeader\n\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\n\nuniform vec4 color : [0.0, 0.0, 0.0, 1.0];\nuniform vec4 paperColor : [1.0, 1.0, 1.0, 1.0];\n\nuniform mat4 viewInverse : VIEWINVERSE;\n\n#ifdef AMBIENT_LIGHT_COUNT\n@import clay.header.ambient_light\n#endif\n#ifdef AMBIENT_SH_LIGHT_COUNT\n@import clay.header.ambient_sh_light\n#endif\n\n#ifdef DIRECTIONAL_LIGHT_COUNT\n@import clay.header.directional_light\n#endif\n\n#ifdef VERTEX_COLOR\nvarying vec4 v_Color;\n#endif\n\n\n@import ecgl.common.ssaoMap.header\n\n@import ecgl.common.bumpMap.header\n\n@import clay.util.srgb\n\n@import ecgl.common.wireframe.fragmentHeader\n\n@import clay.plugin.compute_shadow_map\n\nuniform sampler2D hatch1;\nuniform sampler2D hatch2;\nuniform sampler2D hatch3;\nuniform sampler2D hatch4;\nuniform sampler2D hatch5;\nuniform sampler2D hatch6;\n\nfloat shade(in float tone) {\n vec4 c = vec4(1. ,1., 1., 1.);\n float step = 1. / 6.;\n vec2 uv = v_DetailTexcoord;\n if (tone <= step / 2.0) {\n c = mix(vec4(0.), texture2D(hatch6, uv), 12. * tone);\n }\n else if (tone <= step) {\n c = mix(texture2D(hatch6, uv), texture2D(hatch5, uv), 6. * tone);\n }\n if(tone > step && tone <= 2. * step){\n c = mix(texture2D(hatch5, uv), texture2D(hatch4, uv) , 6. * (tone - step));\n }\n if(tone > 2. * step && tone <= 3. * step){\n c = mix(texture2D(hatch4, uv), texture2D(hatch3, uv), 6. * (tone - 2. * step));\n }\n if(tone > 3. * step && tone <= 4. * step){\n c = mix(texture2D(hatch3, uv), texture2D(hatch2, uv), 6. * (tone - 3. * step));\n }\n if(tone > 4. * step && tone <= 5. * step){\n c = mix(texture2D(hatch2, uv), texture2D(hatch1, uv), 6. * (tone - 4. * step));\n }\n if(tone > 5. * step){\n c = mix(texture2D(hatch1, uv), vec4(1.), 6. * (tone - 5. * step));\n }\n\n return c.r;\n}\n\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\n\nvoid main()\n{\n#ifdef SRGB_DECODE\n vec4 inkColor = sRGBToLinear(color);\n#else\n vec4 inkColor = color;\n#endif\n\n#ifdef VERTEX_COLOR\n #ifdef SRGB_DECODE\n inkColor *= sRGBToLinear(v_Color);\n #else\n inkColor *= v_Color;\n #endif\n#endif\n\n vec3 N = v_Normal;\n#ifdef DOUBLE_SIDED\n vec3 eyePos = viewInverse[3].xyz;\n vec3 V = normalize(eyePos - v_WorldPosition);\n\n if (dot(N, V) < 0.0) {\n N = -N;\n }\n#endif\n\n float tone = 0.0;\n\n float ambientFactor = 1.0;\n\n#ifdef BUMPMAP_ENABLED\n N = bumpNormal(v_WorldPosition, v_Normal, N);\n ambientFactor = dot(v_Normal, N);\n#endif\n\n vec3 N2 = vec3(N.x, N[NORMAL_UP_AXIS], N[NORMAL_FRONT_AXIS]);\n\n @import ecgl.common.ssaoMap.main\n\n#ifdef AMBIENT_LIGHT_COUNT\n for(int i = 0; i < AMBIENT_LIGHT_COUNT; i++)\n {\n tone += dot(ambientLightColor[i], w) * ambientFactor * ao;\n }\n#endif\n#ifdef AMBIENT_SH_LIGHT_COUNT\n for(int _idx_ = 0; _idx_ < AMBIENT_SH_LIGHT_COUNT; _idx_++)\n {{\n tone += dot(calcAmbientSHLight(_idx_, N2) * ambientSHLightColor[_idx_], w) * ao;\n }}\n#endif\n#ifdef DIRECTIONAL_LIGHT_COUNT\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsDir[DIRECTIONAL_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfDirectionalLights(v_WorldPosition, shadowContribsDir);\n }\n#endif\n for(int i = 0; i < DIRECTIONAL_LIGHT_COUNT; i++)\n {\n vec3 lightDirection = -directionalLightDirection[i];\n float lightTone = dot(directionalLightColor[i], w);\n\n float shadowContrib = 1.0;\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n if (shadowEnabled)\n {\n shadowContrib = shadowContribsDir[i];\n }\n#endif\n\n float ndl = dot(N, normalize(lightDirection)) * shadowContrib;\n\n tone += lightTone * clamp(ndl, 0.0, 1.0);\n }\n#endif\n\n gl_FragColor = mix(inkColor, paperColor, shade(clamp(tone, 0.0, 1.0)));\n }\n@end\n");
  31590. /***/
  31591. }),
  31592. /* 152 */
  31593. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  31594. "use strict";
  31595. /* harmony default export */ __webpack_exports__["a"] = ("@export ecgl.sm.depth.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\nattribute vec2 texcoord : TEXCOORD_0;\n\n#ifdef VERTEX_ANIMATION\nattribute vec3 prevPosition;\nuniform float percent : 1.0;\n#endif\n\nvarying vec4 v_ViewPosition;\nvarying vec2 v_Texcoord;\n\nvoid main(){\n\n#ifdef VERTEX_ANIMATION\n vec3 pos = mix(prevPosition, position, percent);\n#else\n vec3 pos = position;\n#endif\n\n v_ViewPosition = worldViewProjection * vec4(pos, 1.0);\n gl_Position = v_ViewPosition;\n\n v_Texcoord = texcoord;\n\n}\n@end\n\n\n\n@export ecgl.sm.depth.fragment\n\n@import clay.sm.depth.fragment\n\n@end");
  31596. /***/
  31597. }),
  31598. /* 153 */
  31599. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  31600. "use strict";
  31601. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  31602. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  31603. var GL_SERIES = ['bar3D', 'line3D', 'map3D', 'scatter3D', 'surface', 'lines3D', 'scatterGL', 'scatter3D'];
  31604. function convertNormalEmphasis(option, optType) {
  31605. if (option && option[optType] && (option[optType].normal || option[optType].emphasis)) {
  31606. var normalOpt = option[optType].normal;
  31607. var emphasisOpt = option[optType].emphasis;
  31608. if (normalOpt) {
  31609. option[optType] = normalOpt;
  31610. }
  31611. if (emphasisOpt) {
  31612. option.emphasis = option.emphasis || {};
  31613. option.emphasis[optType] = emphasisOpt;
  31614. }
  31615. }
  31616. }
  31617. function convertNormalEmphasisForEach(option) {
  31618. convertNormalEmphasis(option, 'itemStyle');
  31619. convertNormalEmphasis(option, 'lineStyle');
  31620. convertNormalEmphasis(option, 'areaStyle');
  31621. convertNormalEmphasis(option, 'label');
  31622. }
  31623. function removeTextStyleInAxis(axesOpt) {
  31624. if (!axesOpt) {
  31625. return;
  31626. }
  31627. if (!(axesOpt instanceof Array)) {
  31628. axesOpt = [axesOpt];
  31629. }
  31630. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.each(axesOpt, function (axisOpt) {
  31631. if (axisOpt.axisLabel) {
  31632. var labelOpt = axisOpt.axisLabel;
  31633. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.extend(labelOpt, labelOpt.textStyle);
  31634. labelOpt.textStyle = null;
  31635. }
  31636. });
  31637. }
  31638. /* harmony default export */ __webpack_exports__["a"] = (function (option) {
  31639. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.each(option.series, function (series) {
  31640. if (__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.indexOf(GL_SERIES, series.type) >= 0) {
  31641. convertNormalEmphasisForEach(series);
  31642. // Compatitable with original mapbox
  31643. if (series.coordinateSystem === 'mapbox') {
  31644. series.coordinateSystem = 'mapbox3D';
  31645. option.mapbox3D = option.mapbox;
  31646. }
  31647. }
  31648. });
  31649. removeTextStyleInAxis(option.xAxis3D);
  31650. removeTextStyleInAxis(option.yAxis3D);
  31651. removeTextStyleInAxis(option.zAxis3D);
  31652. removeTextStyleInAxis(option.grid3D);
  31653. convertNormalEmphasis(option.geo3D);
  31654. });;
  31655. /***/
  31656. }),
  31657. /* 154 */
  31658. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  31659. "use strict";
  31660. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__grid3D_Axis3DModel__ = __webpack_require__(155);
  31661. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__grid3D_Grid3DModel__ = __webpack_require__(159);
  31662. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__grid3D_Grid3DView__ = __webpack_require__(160);
  31663. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__coord_grid3DCreator__ = __webpack_require__(167);
  31664. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_echarts_lib_echarts__ = __webpack_require__(0);
  31665. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_4_echarts_lib_echarts__);
  31666. __WEBPACK_IMPORTED_MODULE_4_echarts_lib_echarts___default.a.registerAction({
  31667. type: 'grid3DChangeCamera',
  31668. event: 'grid3dcamerachanged',
  31669. update: 'series:updateCamera'
  31670. }, function (payload, ecModel) {
  31671. ecModel.eachComponent({
  31672. mainType: 'grid3D', query: payload
  31673. }, function (componentModel) {
  31674. componentModel.setView(payload);
  31675. });
  31676. });
  31677. __WEBPACK_IMPORTED_MODULE_4_echarts_lib_echarts___default.a.registerAction({
  31678. type: 'grid3DShowAxisPointer',
  31679. event: 'grid3dshowaxispointer',
  31680. update: 'grid3D:showAxisPointer'
  31681. }, function (payload, ecModel) {
  31682. });
  31683. __WEBPACK_IMPORTED_MODULE_4_echarts_lib_echarts___default.a.registerAction({
  31684. type: 'grid3DHideAxisPointer',
  31685. event: 'grid3dhideaxispointer',
  31686. update: 'grid3D:hideAxisPointer'
  31687. }, function (payload, ecModel) {
  31688. });
  31689. /***/
  31690. }),
  31691. /* 155 */
  31692. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  31693. "use strict";
  31694. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  31695. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  31696. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__createAxis3DModel__ = __webpack_require__(156);
  31697. var Axis3DModel = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendComponentModel({
  31698. type: 'cartesian3DAxis',
  31699. axis: null,
  31700. /**
  31701. * @override
  31702. */
  31703. getCoordSysModel: function () {
  31704. return this.ecModel.queryComponents({
  31705. mainType: 'grid3D',
  31706. index: this.option.gridIndex,
  31707. id: this.option.gridId
  31708. })[0];
  31709. }
  31710. });
  31711. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.helper.mixinAxisModelCommonMethods(Axis3DModel);
  31712. function getAxisType(axisDim, option) {
  31713. // Default axis with data is category axis
  31714. return option.type || (option.data ? 'category' : 'value');
  31715. }
  31716. Object(__WEBPACK_IMPORTED_MODULE_1__createAxis3DModel__["a" /* default */])('x', Axis3DModel, getAxisType, {
  31717. name: 'X'
  31718. });
  31719. Object(__WEBPACK_IMPORTED_MODULE_1__createAxis3DModel__["a" /* default */])('y', Axis3DModel, getAxisType, {
  31720. name: 'Y'
  31721. });
  31722. Object(__WEBPACK_IMPORTED_MODULE_1__createAxis3DModel__["a" /* default */])('z', Axis3DModel, getAxisType, {
  31723. name: 'Z'
  31724. });
  31725. /***/
  31726. }),
  31727. /* 156 */
  31728. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  31729. "use strict";
  31730. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  31731. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  31732. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__axis3DDefault__ = __webpack_require__(157);
  31733. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_echarts_lib_data_OrdinalMeta__ = __webpack_require__(158);
  31734. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_echarts_lib_data_OrdinalMeta___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_echarts_lib_data_OrdinalMeta__);
  31735. var AXIS_TYPES = ['value', 'category', 'time', 'log'];
  31736. /**
  31737. * Generate sub axis model class
  31738. * @param {string} dim 'x' 'y' 'radius' 'angle' 'parallel'
  31739. * @param {module:echarts/model/Component} BaseAxisModelClass
  31740. * @param {Function} axisTypeDefaulter
  31741. * @param {Object} [extraDefaultOption]
  31742. */
  31743. /* harmony default export */ __webpack_exports__["a"] = (function (dim, BaseAxisModelClass, axisTypeDefaulter, extraDefaultOption) {
  31744. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.each(AXIS_TYPES, function (axisType) {
  31745. BaseAxisModelClass.extend({
  31746. type: dim + 'Axis3D.' + axisType,
  31747. /**
  31748. * @type readOnly
  31749. */
  31750. __ordinalMeta: null,
  31751. mergeDefaultAndTheme: function (option, ecModel) {
  31752. var themeModel = ecModel.getTheme();
  31753. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(option, themeModel.get(axisType + 'Axis3D'));
  31754. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(option, this.getDefaultOption());
  31755. option.type = axisTypeDefaulter(dim, option);
  31756. },
  31757. /**
  31758. * @override
  31759. */
  31760. optionUpdated: function () {
  31761. var thisOption = this.option;
  31762. if (thisOption.type === 'category') {
  31763. this.__ordinalMeta = __WEBPACK_IMPORTED_MODULE_2_echarts_lib_data_OrdinalMeta___default.a.createByAxisModel(this);
  31764. }
  31765. },
  31766. getCategories: function () {
  31767. if (this.option.type === 'category') {
  31768. return this.__ordinalMeta.categories;
  31769. }
  31770. },
  31771. getOrdinalMeta: function () {
  31772. return this.__ordinalMeta;
  31773. },
  31774. defaultOption: __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(
  31775. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.clone(__WEBPACK_IMPORTED_MODULE_1__axis3DDefault__["a" /* default */][axisType + 'Axis3D']),
  31776. extraDefaultOption || {},
  31777. true
  31778. )
  31779. });
  31780. });
  31781. // TODO
  31782. BaseAxisModelClass.superClass.registerSubTypeDefaulter(
  31783. dim + 'Axis3D',
  31784. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.curry(axisTypeDefaulter, dim)
  31785. );
  31786. });;
  31787. /***/
  31788. }),
  31789. /* 157 */
  31790. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  31791. "use strict";
  31792. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  31793. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  31794. var defaultOption = {
  31795. show: true,
  31796. grid3DIndex: 0,
  31797. // åå‘åæ ‡è½´
  31798. inverse: false,
  31799. // åæ ‡è½´åå­—
  31800. name: '',
  31801. // åæ ‡è½´åå­—ä½ç½®
  31802. nameLocation: 'middle',
  31803. nameTextStyle: {
  31804. fontSize: 16
  31805. },
  31806. // 文字与轴线距离
  31807. nameGap: 20,
  31808. axisPointer: {},
  31809. axisLine: {},
  31810. // åæ ‡è½´å°æ ‡è®°
  31811. axisTick: {},
  31812. axisLabel: {},
  31813. // 分隔区域
  31814. splitArea: {}
  31815. };
  31816. var categoryAxis = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge({
  31817. // 类目起始和结束两端空白策略
  31818. boundaryGap: true,
  31819. // splitArea: {
  31820. // show: false
  31821. // },
  31822. // åæ ‡è½´å°æ ‡è®°
  31823. axisTick: {
  31824. // If tick is align with label when boundaryGap is true
  31825. // Default with axisTick
  31826. alignWithLabel: false,
  31827. interval: 'auto'
  31828. },
  31829. // åæ ‡è½´æ–‡æœ¬æ ‡ç­¾ï¼Œè¯¦è§axis.axisLabel
  31830. axisLabel: {
  31831. interval: 'auto'
  31832. },
  31833. axisPointer: {
  31834. label: {
  31835. show: false
  31836. }
  31837. }
  31838. }, defaultOption);
  31839. var valueAxis = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge({
  31840. // 数值起始和结束两端空白策略
  31841. boundaryGap: [0, 0],
  31842. // 最小值, 设置成 'dataMin' 则从数据中计算最小值
  31843. // min: null,
  31844. // 最大值,设置成 'dataMax' 则从数据中计算最大值
  31845. // max: null,
  31846. // 脱离0值比例,放大聚焦到最终_min,_max区间
  31847. // scale: false,
  31848. // 分割段数,默认为5
  31849. splitNumber: 5,
  31850. // Minimum interval
  31851. // minInterval: null
  31852. axisPointer: {
  31853. label: {
  31854. }
  31855. }
  31856. }, defaultOption);
  31857. // FIXME
  31858. var timeAxis = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.defaults({
  31859. scale: true,
  31860. min: 'dataMin',
  31861. max: 'dataMax'
  31862. }, valueAxis);
  31863. var logAxis = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.defaults({
  31864. logBase: 10
  31865. }, valueAxis);
  31866. logAxis.scale = true;
  31867. /* harmony default export */ __webpack_exports__["a"] = ({
  31868. categoryAxis3D: categoryAxis,
  31869. valueAxis3D: valueAxis,
  31870. timeAxis3D: timeAxis,
  31871. logAxis3D: logAxis
  31872. });
  31873. /***/
  31874. }),
  31875. /* 158 */
  31876. /***/ (function (module, exports, __webpack_require__) {
  31877. var _util = __webpack_require__(13);
  31878. var createHashMap = _util.createHashMap;
  31879. var isObject = _util.isObject;
  31880. var map = _util.map;
  31881. /*
  31882. * Licensed to the Apache Software Foundation (ASF) under one
  31883. * or more contributor license agreements. See the NOTICE file
  31884. * distributed with this work for additional information
  31885. * regarding copyright ownership. The ASF licenses this file
  31886. * to you under the Apache License, Version 2.0 (the
  31887. * "License"); you may not use this file except in compliance
  31888. * with the License. You may obtain a copy of the License at
  31889. *
  31890. * http://www.apache.org/licenses/LICENSE-2.0
  31891. *
  31892. * Unless required by applicable law or agreed to in writing,
  31893. * software distributed under the License is distributed on an
  31894. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31895. * KIND, either express or implied. See the License for the
  31896. * specific language governing permissions and limitations
  31897. * under the License.
  31898. */
  31899. /**
  31900. * @constructor
  31901. * @param {Object} [opt]
  31902. * @param {Object} [opt.categories=[]]
  31903. * @param {Object} [opt.needCollect=false]
  31904. * @param {Object} [opt.deduplication=false]
  31905. */
  31906. function OrdinalMeta(opt) {
  31907. /**
  31908. * @readOnly
  31909. * @type {Array.<string>}
  31910. */
  31911. this.categories = opt.categories || [];
  31912. /**
  31913. * @private
  31914. * @type {boolean}
  31915. */
  31916. this._needCollect = opt.needCollect;
  31917. /**
  31918. * @private
  31919. * @type {boolean}
  31920. */
  31921. this._deduplication = opt.deduplication;
  31922. /**
  31923. * @private
  31924. * @type {boolean}
  31925. */
  31926. this._map;
  31927. }
  31928. /**
  31929. * @param {module:echarts/model/Model} axisModel
  31930. * @return {module:echarts/data/OrdinalMeta}
  31931. */
  31932. OrdinalMeta.createByAxisModel = function (axisModel) {
  31933. var option = axisModel.option;
  31934. var data = option.data;
  31935. var categories = data && map(data, getName);
  31936. return new OrdinalMeta({
  31937. categories: categories,
  31938. needCollect: !categories,
  31939. // deduplication is default in axis.
  31940. deduplication: option.dedplication !== false
  31941. });
  31942. };
  31943. var proto = OrdinalMeta.prototype;
  31944. /**
  31945. * @param {string} category
  31946. * @return {number} ordinal
  31947. */
  31948. proto.getOrdinal = function (category) {
  31949. return getOrCreateMap(this).get(category);
  31950. };
  31951. /**
  31952. * @param {*} category
  31953. * @return {number} The ordinal. If not found, return NaN.
  31954. */
  31955. proto.parseAndCollect = function (category) {
  31956. var index;
  31957. var needCollect = this._needCollect; // The value of category dim can be the index of the given category set.
  31958. // This feature is only supported when !needCollect, because we should
  31959. // consider a common case: a value is 2017, which is a number but is
  31960. // expected to be tread as a category. This case usually happen in dataset,
  31961. // where it happent to be no need of the index feature.
  31962. if (typeof category !== 'string' && !needCollect) {
  31963. return category;
  31964. } // Optimize for the scenario:
  31965. // category is ['2012-01-01', '2012-01-02', ...], where the input
  31966. // data has been ensured not duplicate and is large data.
  31967. // Notice, if a dataset dimension provide categroies, usually echarts
  31968. // should remove duplication except user tell echarts dont do that
  31969. // (set axis.deduplication = false), because echarts do not know whether
  31970. // the values in the category dimension has duplication (consider the
  31971. // parallel-aqi example)
  31972. if (needCollect && !this._deduplication) {
  31973. index = this.categories.length;
  31974. this.categories[index] = category;
  31975. return index;
  31976. }
  31977. var map = getOrCreateMap(this);
  31978. index = map.get(category);
  31979. if (index == null) {
  31980. if (needCollect) {
  31981. index = this.categories.length;
  31982. this.categories[index] = category;
  31983. map.set(category, index);
  31984. } else {
  31985. index = NaN;
  31986. }
  31987. }
  31988. return index;
  31989. }; // Consider big data, do not create map until needed.
  31990. function getOrCreateMap(ordinalMeta) {
  31991. return ordinalMeta._map || (ordinalMeta._map = createHashMap(ordinalMeta.categories));
  31992. }
  31993. function getName(obj) {
  31994. if (isObject(obj) && obj.value != null) {
  31995. return obj.value;
  31996. } else {
  31997. return obj + '';
  31998. }
  31999. }
  32000. var _default = OrdinalMeta;
  32001. module.exports = _default;
  32002. /***/
  32003. }),
  32004. /* 159 */
  32005. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  32006. "use strict";
  32007. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  32008. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  32009. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__common_componentViewControlMixin__ = __webpack_require__(44);
  32010. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__common_componentPostEffectMixin__ = __webpack_require__(28);
  32011. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__common_componentLightMixin__ = __webpack_require__(29);
  32012. var Grid3DModel = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendComponentModel({
  32013. type: 'grid3D',
  32014. dependencies: ['xAxis3D', 'yAxis3D', 'zAxis3D'],
  32015. defaultOption: {
  32016. show: true,
  32017. zlevel: -10,
  32018. // Layout used for viewport
  32019. left: 0,
  32020. top: 0,
  32021. width: '100%',
  32022. height: '100%',
  32023. environment: 'auto',
  32024. // Dimension of grid3D
  32025. boxWidth: 100,
  32026. boxHeight: 100,
  32027. boxDepth: 100,
  32028. // Common axis options.
  32029. axisPointer: {
  32030. show: true,
  32031. lineStyle: {
  32032. color: 'rgba(0, 0, 0, 0.8)',
  32033. width: 1
  32034. },
  32035. label: {
  32036. show: true,
  32037. // (dimValue: number, value: Array) => string
  32038. formatter: null,
  32039. // TODO, Consider boxWidth
  32040. margin: 8,
  32041. // backgroundColor: '#ffbd67',
  32042. // borderColor: '#000',
  32043. // borderWidth: 0,
  32044. textStyle: {
  32045. fontSize: 14,
  32046. color: '#fff',
  32047. backgroundColor: 'rgba(0,0,0,0.5)',
  32048. padding: 3,
  32049. borderRadius: 3
  32050. }
  32051. }
  32052. },
  32053. axisLine: {
  32054. show: true,
  32055. lineStyle: {
  32056. color: '#333',
  32057. width: 2,
  32058. type: 'solid'
  32059. }
  32060. },
  32061. axisTick: {
  32062. show: true,
  32063. inside: false,
  32064. length: 3,
  32065. lineStyle: {
  32066. width: 1
  32067. }
  32068. },
  32069. axisLabel: {
  32070. show: true,
  32071. inside: false,
  32072. rotate: 0,
  32073. margin: 8,
  32074. textStyle: {
  32075. fontSize: 12
  32076. }
  32077. },
  32078. splitLine: {
  32079. show: true,
  32080. lineStyle: {
  32081. color: ['#ccc'],
  32082. width: 1,
  32083. type: 'solid'
  32084. }
  32085. },
  32086. splitArea: {
  32087. show: false,
  32088. areaStyle: {
  32089. color: ['rgba(250,250,250,0.3)', 'rgba(200,200,200,0.3)']
  32090. }
  32091. },
  32092. // Light options
  32093. light: {
  32094. main: {
  32095. // Alpha angle for top-down rotation
  32096. // Positive to rotate to top.
  32097. alpha: 30,
  32098. // beta angle for left-right rotation
  32099. // Positive to rotate to right.
  32100. beta: 40
  32101. },
  32102. ambient: {
  32103. intensity: 0.4
  32104. }
  32105. },
  32106. viewControl: {
  32107. // Small damping for precise control.
  32108. // damping: 0.1,
  32109. // Alpha angle for top-down rotation
  32110. // Positive to rotate to top.
  32111. alpha: 20,
  32112. // beta angle for left-right rotation
  32113. // Positive to rotate to right.
  32114. beta: 40,
  32115. autoRotate: false,
  32116. // Distance to the surface of grid3D.
  32117. distance: 200,
  32118. // Min distance to the surface of grid3D
  32119. minDistance: 40,
  32120. // Max distance to the surface of grid3D
  32121. maxDistance: 400
  32122. }
  32123. }
  32124. });
  32125. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(Grid3DModel.prototype, __WEBPACK_IMPORTED_MODULE_1__common_componentViewControlMixin__["a" /* default */]);
  32126. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(Grid3DModel.prototype, __WEBPACK_IMPORTED_MODULE_2__common_componentPostEffectMixin__["a" /* default */]);
  32127. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(Grid3DModel.prototype, __WEBPACK_IMPORTED_MODULE_3__common_componentLightMixin__["a" /* default */]);
  32128. /* unused harmony default export */ var _unused_webpack_default_export = (Grid3DModel);
  32129. /***/
  32130. }),
  32131. /* 160 */
  32132. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  32133. "use strict";
  32134. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  32135. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  32136. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__ = __webpack_require__(1);
  32137. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_OrbitControl__ = __webpack_require__(45);
  32138. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__util_geometry_Lines3D__ = __webpack_require__(25);
  32139. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__util_retrieve__ = __webpack_require__(2);
  32140. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__util_ZRTextureAtlasSurface__ = __webpack_require__(81);
  32141. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__common_SceneHelper__ = __webpack_require__(30);
  32142. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__Grid3DFace__ = __webpack_require__(162);
  32143. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__Grid3DAxis__ = __webpack_require__(164);
  32144. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_9__util_mesh_LabelsMesh__ = __webpack_require__(63);
  32145. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_10__util_shader_lines3D_glsl_js__ = __webpack_require__(46);
  32146. // TODO orthographic camera
  32147. var firstNotNull = __WEBPACK_IMPORTED_MODULE_4__util_retrieve__["a" /* default */].firstNotNull;
  32148. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader.import(__WEBPACK_IMPORTED_MODULE_10__util_shader_lines3D_glsl_js__["a" /* default */]);
  32149. ['x', 'y', 'z'].forEach(function (dim) {
  32150. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendComponentView({
  32151. type: dim + 'Axis3D'
  32152. });
  32153. });
  32154. var dimIndicesMap = {
  32155. // Left to right
  32156. x: 0,
  32157. // Far to near
  32158. y: 2,
  32159. // Bottom to up
  32160. z: 1
  32161. };
  32162. /* unused harmony default export */ var _unused_webpack_default_export = (__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendComponentView({
  32163. type: 'grid3D',
  32164. __ecgl__: true,
  32165. init: function (ecModel, api) {
  32166. var FACES = [
  32167. // planeDim0, planeDim1, offsetDim, dir on dim3 axis(gl), plane.
  32168. ['y', 'z', 'x', -1, 'left'],
  32169. ['y', 'z', 'x', 1, 'right'],
  32170. ['x', 'y', 'z', -1, 'bottom'],
  32171. ['x', 'y', 'z', 1, 'top'],
  32172. ['x', 'z', 'y', -1, 'far'],
  32173. ['x', 'z', 'y', 1, 'near']
  32174. ];
  32175. var DIMS = ['x', 'y', 'z'];
  32176. var quadsMaterial = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Material({
  32177. // transparent: true,
  32178. shader: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].createShader('ecgl.color'),
  32179. depthMask: false,
  32180. transparent: true
  32181. });
  32182. var linesMaterial = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Material({
  32183. // transparent: true,
  32184. shader: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].createShader('ecgl.meshLines3D'),
  32185. depthMask: false,
  32186. transparent: true
  32187. });
  32188. quadsMaterial.define('fragment', 'DOUBLE_SIDED');
  32189. quadsMaterial.define('both', 'VERTEX_COLOR');
  32190. this.groupGL = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Node();
  32191. this._control = new __WEBPACK_IMPORTED_MODULE_2__util_OrbitControl__["a" /* default */]({
  32192. zr: api.getZr()
  32193. });
  32194. this._control.init();
  32195. // Save mesh and other infos for each face.
  32196. this._faces = FACES.map(function (faceInfo) {
  32197. var face = new __WEBPACK_IMPORTED_MODULE_7__Grid3DFace__["a" /* default */](faceInfo, linesMaterial, quadsMaterial);
  32198. this.groupGL.add(face.rootNode);
  32199. return face;
  32200. }, this);
  32201. // Save mesh and other infos for each axis.
  32202. this._axes = DIMS.map(function (dim) {
  32203. var axis = new __WEBPACK_IMPORTED_MODULE_8__Grid3DAxis__["a" /* default */](dim, linesMaterial);
  32204. this.groupGL.add(axis.rootNode);
  32205. return axis;
  32206. }, this);
  32207. var dpr = api.getDevicePixelRatio();
  32208. // Texture surface for label.
  32209. this._axisLabelSurface = new __WEBPACK_IMPORTED_MODULE_5__util_ZRTextureAtlasSurface__["a" /* default */]({
  32210. width: 256, height: 256,
  32211. devicePixelRatio: dpr
  32212. });
  32213. this._axisLabelSurface.onupdate = function () {
  32214. api.getZr().refresh();
  32215. };
  32216. this._axisPointerLineMesh = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh({
  32217. geometry: new __WEBPACK_IMPORTED_MODULE_3__util_geometry_Lines3D__["a" /* default */]({ useNativeLine: false }),
  32218. material: linesMaterial,
  32219. castShadow: false,
  32220. // PENDING
  32221. ignorePicking: true,
  32222. renderOrder: 3
  32223. });
  32224. this.groupGL.add(this._axisPointerLineMesh);
  32225. this._axisPointerLabelsSurface = new __WEBPACK_IMPORTED_MODULE_5__util_ZRTextureAtlasSurface__["a" /* default */]({
  32226. width: 128, height: 128,
  32227. devicePixelRatio: dpr
  32228. });
  32229. this._axisPointerLabelsMesh = new __WEBPACK_IMPORTED_MODULE_9__util_mesh_LabelsMesh__["a" /* default */]({
  32230. ignorePicking: true, renderOrder: 4,
  32231. castShadow: false
  32232. });
  32233. this._axisPointerLabelsMesh.material.set('textureAtlas', this._axisPointerLabelsSurface.getTexture());
  32234. this.groupGL.add(this._axisPointerLabelsMesh);
  32235. this._lightRoot = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Node();
  32236. this._sceneHelper = new __WEBPACK_IMPORTED_MODULE_6__common_SceneHelper__["a" /* default */]();
  32237. this._sceneHelper.initLight(this._lightRoot);
  32238. },
  32239. render: function (grid3DModel, ecModel, api) {
  32240. this._model = grid3DModel;
  32241. this._api = api;
  32242. var cartesian = grid3DModel.coordinateSystem;
  32243. // Always have light.
  32244. cartesian.viewGL.add(this._lightRoot);
  32245. if (grid3DModel.get('show')) {
  32246. cartesian.viewGL.add(this.groupGL);
  32247. }
  32248. else {
  32249. cartesian.viewGL.remove(this.groupGL);
  32250. }
  32251. // cartesian.viewGL.setCameraType(grid3DModel.get('viewControl.projection'));
  32252. var control = this._control;
  32253. control.setViewGL(cartesian.viewGL);
  32254. var viewControlModel = grid3DModel.getModel('viewControl');
  32255. control.setFromViewControlModel(viewControlModel, 0);
  32256. this._axisLabelSurface.clear();
  32257. control.off('update');
  32258. if (grid3DModel.get('show')) {
  32259. this._faces.forEach(function (face) {
  32260. face.update(grid3DModel, ecModel, api);
  32261. }, this);
  32262. this._axes.forEach(function (axis) {
  32263. axis.update(grid3DModel, this._axisLabelSurface, api);
  32264. }, this);
  32265. }
  32266. control.on('update', this._onCameraChange.bind(this, grid3DModel, api), this);
  32267. this._sceneHelper.setScene(cartesian.viewGL.scene);
  32268. this._sceneHelper.updateLight(grid3DModel);
  32269. // Set post effect
  32270. cartesian.viewGL.setPostEffect(grid3DModel.getModel('postEffect'), api);
  32271. cartesian.viewGL.setTemporalSuperSampling(grid3DModel.getModel('temporalSuperSampling'));
  32272. this._initMouseHandler(grid3DModel);
  32273. },
  32274. afterRender: function (grid3DModel, ecModel, api, layerGL) {
  32275. // Create ambient cubemap after render because we need to know the renderer.
  32276. // TODO
  32277. var renderer = layerGL.renderer;
  32278. this._sceneHelper.updateAmbientCubemap(renderer, grid3DModel, api);
  32279. this._sceneHelper.updateSkybox(renderer, grid3DModel, api);
  32280. },
  32281. /**
  32282. * showAxisPointer will be triggered by action.
  32283. */
  32284. showAxisPointer: function (grid3dModel, ecModel, api, payload) {
  32285. this._doShowAxisPointer();
  32286. this._updateAxisPointer(payload.value);
  32287. },
  32288. /**
  32289. * hideAxisPointer will be triggered by action.
  32290. */
  32291. hideAxisPointer: function (grid3dModel, ecModel, api, payload) {
  32292. this._doHideAxisPointer();
  32293. },
  32294. _initMouseHandler: function (grid3DModel) {
  32295. var cartesian = grid3DModel.coordinateSystem;
  32296. var viewGL = cartesian.viewGL;
  32297. // TODO xAxis3D.axisPointer.show ?
  32298. if (grid3DModel.get('show') && grid3DModel.get('axisPointer.show')) {
  32299. viewGL.on('mousemove', this._updateAxisPointerOnMousePosition, this);
  32300. }
  32301. else {
  32302. viewGL.off('mousemove', this._updateAxisPointerOnMousePosition);
  32303. }
  32304. },
  32305. /**
  32306. * Try find and show axisPointer on the intersect point
  32307. * of mouse ray with grid plane.
  32308. */
  32309. _updateAxisPointerOnMousePosition: function (e) {
  32310. // Ignore if mouse is on the element.
  32311. if (e.target) {
  32312. return;
  32313. }
  32314. var grid3DModel = this._model;
  32315. var cartesian = grid3DModel.coordinateSystem;
  32316. var viewGL = cartesian.viewGL;
  32317. var ray = viewGL.castRay(e.offsetX, e.offsetY, new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Ray());
  32318. var nearestIntersectPoint;
  32319. for (var i = 0; i < this._faces.length; i++) {
  32320. var face = this._faces[i];
  32321. if (face.rootNode.invisible) {
  32322. continue;
  32323. }
  32324. // Plane is not face the camera. flip it
  32325. if (face.plane.normal.dot(viewGL.camera.worldTransform.z) < 0) {
  32326. face.plane.normal.negate();
  32327. }
  32328. var point = ray.intersectPlane(face.plane);
  32329. if (!point) {
  32330. continue;
  32331. }
  32332. var axis0 = cartesian.getAxis(face.faceInfo[0]);
  32333. var axis1 = cartesian.getAxis(face.faceInfo[1]);
  32334. var idx0 = dimIndicesMap[face.faceInfo[0]];
  32335. var idx1 = dimIndicesMap[face.faceInfo[1]];
  32336. if (axis0.contain(point.array[idx0]) && axis1.contain(point.array[idx1])) {
  32337. nearestIntersectPoint = point;
  32338. }
  32339. }
  32340. if (nearestIntersectPoint) {
  32341. var data = cartesian.pointToData(nearestIntersectPoint.array, [], true);
  32342. this._updateAxisPointer(data);
  32343. this._doShowAxisPointer();
  32344. }
  32345. else {
  32346. this._doHideAxisPointer();
  32347. }
  32348. },
  32349. _onCameraChange: function (grid3DModel, api) {
  32350. if (grid3DModel.get('show')) {
  32351. this._updateFaceVisibility();
  32352. this._updateAxisLinePosition();
  32353. }
  32354. var control = this._control;
  32355. api.dispatchAction({
  32356. type: 'grid3DChangeCamera',
  32357. alpha: control.getAlpha(),
  32358. beta: control.getBeta(),
  32359. distance: control.getDistance(),
  32360. center: control.getCenter(),
  32361. from: this.uid,
  32362. grid3DId: grid3DModel.id
  32363. });
  32364. },
  32365. /**
  32366. * Update visibility of each face when camera view changed, front face will be invisible.
  32367. * @private
  32368. */
  32369. _updateFaceVisibility: function () {
  32370. var camera = this._control.getCamera();
  32371. var viewSpacePos = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Vector3();
  32372. camera.update();
  32373. for (var idx = 0; idx < this._faces.length / 2; idx++) {
  32374. var depths = [];
  32375. for (var k = 0; k < 2; k++) {
  32376. var face = this._faces[idx * 2 + k];
  32377. face.rootNode.getWorldPosition(viewSpacePos);
  32378. viewSpacePos.transformMat4(camera.viewMatrix);
  32379. depths[k] = viewSpacePos.z;
  32380. }
  32381. // Set the front face invisible
  32382. var frontIndex = depths[0] > depths[1] ? 0 : 1;
  32383. var frontFace = this._faces[idx * 2 + frontIndex];
  32384. var backFace = this._faces[idx * 2 + 1 - frontIndex];
  32385. // Update rotation.
  32386. frontFace.rootNode.invisible = true;
  32387. backFace.rootNode.invisible = false;
  32388. }
  32389. },
  32390. /**
  32391. * Update axis line position when camera view changed.
  32392. * @private
  32393. */
  32394. _updateAxisLinePosition: function () {
  32395. // Put xAxis, yAxis on x, y visible plane.
  32396. // Put zAxis on the left.
  32397. // TODO
  32398. var cartesian = this._model.coordinateSystem;
  32399. var xAxis = cartesian.getAxis('x');
  32400. var yAxis = cartesian.getAxis('y');
  32401. var zAxis = cartesian.getAxis('z');
  32402. var top = zAxis.getExtentMax();
  32403. var bottom = zAxis.getExtentMin();
  32404. var left = xAxis.getExtentMin();
  32405. var right = xAxis.getExtentMax();
  32406. var near = yAxis.getExtentMax();
  32407. var far = yAxis.getExtentMin();
  32408. var xAxisNode = this._axes[0].rootNode;
  32409. var yAxisNode = this._axes[1].rootNode;
  32410. var zAxisNode = this._axes[2].rootNode;
  32411. var faces = this._faces;
  32412. // Notice: in cartesian up axis is z, but in webgl up axis is y.
  32413. var xAxisZOffset = (faces[4].rootNode.invisible ? far : near);
  32414. var xAxisYOffset = (faces[2].rootNode.invisible ? top : bottom);
  32415. var yAxisXOffset = (faces[0].rootNode.invisible ? left : right);
  32416. var yAxisYOffset = (faces[2].rootNode.invisible ? top : bottom);
  32417. var zAxisXOffset = (faces[0].rootNode.invisible ? right : left);
  32418. var zAxisZOffset = (faces[4].rootNode.invisible ? far : near);
  32419. xAxisNode.rotation.identity();
  32420. yAxisNode.rotation.identity();
  32421. zAxisNode.rotation.identity();
  32422. if (faces[4].rootNode.invisible) {
  32423. this._axes[0].flipped = true;
  32424. xAxisNode.rotation.rotateX(Math.PI);
  32425. }
  32426. if (faces[0].rootNode.invisible) {
  32427. this._axes[1].flipped = true;
  32428. yAxisNode.rotation.rotateZ(Math.PI);
  32429. }
  32430. if (faces[4].rootNode.invisible) {
  32431. this._axes[2].flipped = true;
  32432. zAxisNode.rotation.rotateY(Math.PI);
  32433. }
  32434. xAxisNode.position.set(0, xAxisYOffset, xAxisZOffset);
  32435. yAxisNode.position.set(yAxisXOffset, yAxisYOffset, 0); // Actually z
  32436. zAxisNode.position.set(zAxisXOffset, 0, zAxisZOffset); // Actually y
  32437. xAxisNode.update();
  32438. yAxisNode.update();
  32439. zAxisNode.update();
  32440. this._updateAxisLabelAlign();
  32441. },
  32442. /**
  32443. * Update label align on axis when axisLine position changed.
  32444. * @private
  32445. */
  32446. _updateAxisLabelAlign: function () {
  32447. // var cartesian = this._model.coordinateSystem;
  32448. var camera = this._control.getCamera();
  32449. var coords = [new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Vector4(), new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Vector4()];
  32450. var center = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Vector4();
  32451. this.groupGL.getWorldPosition(center);
  32452. center.w = 1.0;
  32453. center.transformMat4(camera.viewMatrix)
  32454. .transformMat4(camera.projectionMatrix);
  32455. center.x /= center.w;
  32456. center.y /= center.w;
  32457. this._axes.forEach(function (axisInfo) {
  32458. var lineCoords = axisInfo.axisLineCoords;
  32459. var labelGeo = axisInfo.labelsMesh.geometry;
  32460. for (var i = 0; i < coords.length; i++) {
  32461. coords[i].setArray(lineCoords[i]);
  32462. coords[i].w = 1.0;
  32463. coords[i].transformMat4(axisInfo.rootNode.worldTransform)
  32464. .transformMat4(camera.viewMatrix)
  32465. .transformMat4(camera.projectionMatrix);
  32466. coords[i].x /= coords[i].w;
  32467. coords[i].y /= coords[i].w;
  32468. }
  32469. var dx = coords[1].x - coords[0].x;
  32470. var dy = coords[1].y - coords[0].y;
  32471. var cx = (coords[1].x + coords[0].x) / 2;
  32472. var cy = (coords[1].y + coords[0].y) / 2;
  32473. var textAlign;
  32474. var verticalAlign;
  32475. if (Math.abs(dy / dx) < 0.5) {
  32476. textAlign = 'center';
  32477. verticalAlign = cy > center.y ? 'bottom' : 'top';
  32478. }
  32479. else {
  32480. verticalAlign = 'middle';
  32481. textAlign = cx > center.x ? 'left' : 'right';
  32482. }
  32483. // axis labels
  32484. axisInfo.setSpriteAlign(textAlign, verticalAlign, this._api);
  32485. }, this);
  32486. },
  32487. _doShowAxisPointer: function () {
  32488. if (!this._axisPointerLineMesh.invisible) {
  32489. return;
  32490. }
  32491. this._axisPointerLineMesh.invisible = false;
  32492. this._axisPointerLabelsMesh.invisible = false;
  32493. this._api.getZr().refresh();
  32494. },
  32495. _doHideAxisPointer: function () {
  32496. if (this._axisPointerLineMesh.invisible) {
  32497. return;
  32498. }
  32499. this._axisPointerLineMesh.invisible = true;
  32500. this._axisPointerLabelsMesh.invisible = true;
  32501. this._api.getZr().refresh();
  32502. },
  32503. /**
  32504. * @private updateAxisPointer.
  32505. */
  32506. _updateAxisPointer: function (data) {
  32507. var cartesian = this._model.coordinateSystem;
  32508. var point = cartesian.dataToPoint(data);
  32509. var axisPointerLineMesh = this._axisPointerLineMesh;
  32510. var linesGeo = axisPointerLineMesh.geometry;
  32511. var axisPointerParentModel = this._model.getModel('axisPointer');
  32512. var dpr = this._api.getDevicePixelRatio();
  32513. linesGeo.convertToDynamicArray(true);
  32514. function ifShowAxisPointer(axis) {
  32515. return __WEBPACK_IMPORTED_MODULE_4__util_retrieve__["a" /* default */].firstNotNull(
  32516. axis.model.get('axisPointer.show'),
  32517. axisPointerParentModel.get('show')
  32518. );
  32519. }
  32520. function getAxisColorAndLineWidth(axis) {
  32521. var axisPointerModel = axis.model.getModel('axisPointer', axisPointerParentModel);
  32522. var lineStyleModel = axisPointerModel.getModel('lineStyle');
  32523. var color = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(lineStyleModel.get('color'));
  32524. var lineWidth = firstNotNull(lineStyleModel.get('width'), 1);
  32525. var opacity = firstNotNull(lineStyleModel.get('opacity'), 1);
  32526. color[3] *= opacity;
  32527. return {
  32528. color: color,
  32529. lineWidth: lineWidth
  32530. };
  32531. }
  32532. for (var k = 0; k < this._faces.length; k++) {
  32533. var face = this._faces[k];
  32534. if (face.rootNode.invisible) {
  32535. continue;
  32536. }
  32537. var faceInfo = face.faceInfo;
  32538. var otherCoord = faceInfo[3] < 0
  32539. ? cartesian.getAxis(faceInfo[2]).getExtentMin()
  32540. : cartesian.getAxis(faceInfo[2]).getExtentMax();
  32541. var otherDimIdx = dimIndicesMap[faceInfo[2]];
  32542. // Line on face.
  32543. for (var i = 0; i < 2; i++) {
  32544. var dim = faceInfo[i];
  32545. var faceOtherDim = faceInfo[1 - i];
  32546. var axis = cartesian.getAxis(dim);
  32547. var faceOtherAxis = cartesian.getAxis(faceOtherDim);
  32548. if (!ifShowAxisPointer(axis)) {
  32549. continue;
  32550. }
  32551. var p0 = [0, 0, 0]; var p1 = [0, 0, 0];
  32552. var dimIdx = dimIndicesMap[dim];
  32553. var faceOtherDimIdx = dimIndicesMap[faceOtherDim];
  32554. p0[dimIdx] = p1[dimIdx] = point[dimIdx];
  32555. p0[otherDimIdx] = p1[otherDimIdx] = otherCoord;
  32556. p0[faceOtherDimIdx] = faceOtherAxis.getExtentMin();
  32557. p1[faceOtherDimIdx] = faceOtherAxis.getExtentMax();
  32558. var colorAndLineWidth = getAxisColorAndLineWidth(axis);
  32559. linesGeo.addLine(p0, p1, colorAndLineWidth.color, colorAndLineWidth.lineWidth * dpr);
  32560. }
  32561. // Project line.
  32562. if (ifShowAxisPointer(cartesian.getAxis(faceInfo[2]))) {
  32563. var p0 = point.slice();
  32564. var p1 = point.slice();
  32565. p1[otherDimIdx] = otherCoord;
  32566. var colorAndLineWidth = getAxisColorAndLineWidth(cartesian.getAxis(faceInfo[2]));
  32567. linesGeo.addLine(p0, p1, colorAndLineWidth.color, colorAndLineWidth.lineWidth * dpr);
  32568. }
  32569. }
  32570. linesGeo.convertToTypedArray();
  32571. this._updateAxisPointerLabelsMesh(data);
  32572. this._api.getZr().refresh();
  32573. },
  32574. _updateAxisPointerLabelsMesh: function (data) {
  32575. var grid3dModel = this._model;
  32576. var axisPointerLabelsMesh = this._axisPointerLabelsMesh;
  32577. var axisPointerLabelsSurface = this._axisPointerLabelsSurface;
  32578. var cartesian = grid3dModel.coordinateSystem;
  32579. var axisPointerParentModel = grid3dModel.getModel('axisPointer');
  32580. axisPointerLabelsMesh.geometry.convertToDynamicArray(true);
  32581. axisPointerLabelsSurface.clear();
  32582. var otherDim = {
  32583. x: 'y', y: 'x', z: 'y'
  32584. };
  32585. this._axes.forEach(function (axisInfo, idx) {
  32586. var axis = cartesian.getAxis(axisInfo.dim);
  32587. var axisModel = axis.model;
  32588. var axisPointerModel = axisModel.getModel('axisPointer', axisPointerParentModel);
  32589. var labelModel = axisPointerModel.getModel('label');
  32590. var lineColor = axisPointerModel.get('lineStyle.color');
  32591. if (!labelModel.get('show') || !axisPointerModel.get('show')) {
  32592. return;
  32593. }
  32594. var val = data[idx];
  32595. var formatter = labelModel.get('formatter');
  32596. var text = axis.scale.getLabel(val);
  32597. if (formatter != null) {
  32598. text = formatter(text, data);
  32599. }
  32600. else {
  32601. if (axis.scale.type === 'interval' || axis.scale.type === 'log') {
  32602. var precision = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.number.getPrecisionSafe(axis.scale.getTicks()[0]);
  32603. text = val.toFixed(precision + 2);
  32604. }
  32605. }
  32606. var textStyleModel = labelModel.getModel('textStyle');
  32607. var labelColor = textStyleModel.get('color');
  32608. var textEl = new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.graphic.Text();
  32609. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.graphic.setTextStyle(textEl.style, textStyleModel, {
  32610. text: text,
  32611. textFill: labelColor || lineColor,
  32612. textAlign: 'left',
  32613. textVerticalAlign: 'top'
  32614. });
  32615. var coords = axisPointerLabelsSurface.add(textEl);
  32616. var rect = textEl.getBoundingRect();
  32617. var dpr = this._api.getDevicePixelRatio();
  32618. var pos = axisInfo.rootNode.position.toArray();
  32619. var otherIdx = dimIndicesMap[otherDim[axisInfo.dim]];
  32620. pos[otherIdx] += (axisInfo.flipped ? -1 : 1) * labelModel.get('margin');
  32621. pos[dimIndicesMap[axisInfo.dim]] = axis.dataToCoord(data[idx]);
  32622. axisPointerLabelsMesh.geometry.addSprite(
  32623. pos, [rect.width * dpr, rect.height * dpr], coords,
  32624. axisInfo.textAlign, axisInfo.textVerticalAlign
  32625. );
  32626. }, this);
  32627. axisPointerLabelsSurface.getZr().refreshImmediately();
  32628. axisPointerLabelsMesh.material.set('uvScale', axisPointerLabelsSurface.getCoordsScale());
  32629. axisPointerLabelsMesh.geometry.convertToTypedArray();
  32630. },
  32631. dispose: function () {
  32632. this.groupGL.removeAll();
  32633. this._control.dispose();
  32634. }
  32635. }));
  32636. /***/
  32637. }),
  32638. /* 161 */
  32639. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  32640. "use strict";
  32641. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__vec2__ = __webpack_require__(70);
  32642. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__vec3__ = __webpack_require__(12);
  32643. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__vec4__ = __webpack_require__(33);
  32644. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__mat2__ = __webpack_require__(78);
  32645. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__mat2d__ = __webpack_require__(79);
  32646. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__mat3__ = __webpack_require__(34);
  32647. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__mat4__ = __webpack_require__(21);
  32648. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__quat__ = __webpack_require__(55);
  32649. /**
  32650. * @fileoverview gl-matrix - High performance matrix and vector operations
  32651. * @author Brandon Jones
  32652. * @author Colin MacKenzie IV
  32653. * @version 2.2.2
  32654. */
  32655. /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
  32656. Redistribution and use in source and binary forms, with or without modification,
  32657. are permitted provided that the following conditions are met:
  32658. * Redistributions of source code must retain the above copyright notice, this
  32659. list of conditions and the following disclaimer.
  32660. * Redistributions in binary form must reproduce the above copyright notice,
  32661. this list of conditions and the following disclaimer in the documentation
  32662. and/or other materials provided with the distribution.
  32663. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  32664. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  32665. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  32666. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  32667. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  32668. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  32669. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  32670. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32671. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32672. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
  32673. /* harmony default export */ __webpack_exports__["a"] = ({
  32674. vec2: __WEBPACK_IMPORTED_MODULE_0__vec2__["a" /* default */],
  32675. vec3: __WEBPACK_IMPORTED_MODULE_1__vec3__["a" /* default */],
  32676. vec4: __WEBPACK_IMPORTED_MODULE_2__vec4__["a" /* default */],
  32677. mat2: __WEBPACK_IMPORTED_MODULE_3__mat2__["a" /* default */],
  32678. mat2d: __WEBPACK_IMPORTED_MODULE_4__mat2d__["a" /* default */],
  32679. mat3: __WEBPACK_IMPORTED_MODULE_5__mat3__["a" /* default */],
  32680. mat4: __WEBPACK_IMPORTED_MODULE_6__mat4__["a" /* default */],
  32681. quat: __WEBPACK_IMPORTED_MODULE_7__quat__["a" /* default */]
  32682. });
  32683. /***/
  32684. }),
  32685. /* 162 */
  32686. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  32687. "use strict";
  32688. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  32689. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  32690. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__ = __webpack_require__(1);
  32691. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_retrieve__ = __webpack_require__(2);
  32692. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__util_geometry_Lines3D__ = __webpack_require__(25);
  32693. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__util_geometry_Quads__ = __webpack_require__(163);
  32694. var firstNotNull = __WEBPACK_IMPORTED_MODULE_2__util_retrieve__["a" /* default */].firstNotNull;
  32695. var dimIndicesMap = {
  32696. // Left to right
  32697. x: 0,
  32698. // Far to near
  32699. y: 2,
  32700. // Bottom to up
  32701. z: 1
  32702. };
  32703. function updateFacePlane(node, plane, otherAxis, dir) {
  32704. var coord = [0, 0, 0];
  32705. var distance = dir < 0 ? otherAxis.getExtentMin() : otherAxis.getExtentMax();
  32706. coord[dimIndicesMap[otherAxis.dim]] = distance;
  32707. node.position.setArray(coord);
  32708. node.rotation.identity();
  32709. // Negative distance because on the opposite of normal direction.
  32710. plane.distance = -Math.abs(distance);
  32711. plane.normal.set(0, 0, 0);
  32712. if (otherAxis.dim === 'x') {
  32713. node.rotation.rotateY(dir * Math.PI / 2);
  32714. plane.normal.x = -dir;
  32715. }
  32716. else if (otherAxis.dim === 'z') {
  32717. node.rotation.rotateX(-dir * Math.PI / 2);
  32718. plane.normal.y = -dir;
  32719. }
  32720. else {
  32721. if (dir > 0) {
  32722. node.rotation.rotateY(Math.PI);
  32723. }
  32724. plane.normal.z = -dir;
  32725. }
  32726. }
  32727. function Grid3DFace(faceInfo, linesMaterial, quadsMaterial) {
  32728. this.rootNode = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Node();
  32729. var linesMesh = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh({
  32730. geometry: new __WEBPACK_IMPORTED_MODULE_3__util_geometry_Lines3D__["a" /* default */]({ useNativeLine: false }),
  32731. material: linesMaterial,
  32732. castShadow: false,
  32733. ignorePicking: true,
  32734. $ignorePicking: true,
  32735. renderOrder: 1
  32736. });
  32737. var quadsMesh = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh({
  32738. geometry: new __WEBPACK_IMPORTED_MODULE_4__util_geometry_Quads__["a" /* default */](),
  32739. material: quadsMaterial,
  32740. castShadow: false,
  32741. culling: false,
  32742. ignorePicking: true,
  32743. $ignorePicking: true,
  32744. renderOrder: 0
  32745. });
  32746. // Quads are behind lines.
  32747. this.rootNode.add(quadsMesh);
  32748. this.rootNode.add(linesMesh);
  32749. this.faceInfo = faceInfo;
  32750. this.plane = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Plane();
  32751. this.linesMesh = linesMesh;
  32752. this.quadsMesh = quadsMesh;
  32753. }
  32754. Grid3DFace.prototype.update = function (grid3DModel, ecModel, api) {
  32755. var cartesian = grid3DModel.coordinateSystem;
  32756. var axes = [
  32757. cartesian.getAxis(this.faceInfo[0]),
  32758. cartesian.getAxis(this.faceInfo[1])
  32759. ];
  32760. var lineGeometry = this.linesMesh.geometry;
  32761. var quadsGeometry = this.quadsMesh.geometry;
  32762. lineGeometry.convertToDynamicArray(true);
  32763. quadsGeometry.convertToDynamicArray(true);
  32764. this._updateSplitLines(lineGeometry, axes, grid3DModel, api);
  32765. this._udpateSplitAreas(quadsGeometry, axes, grid3DModel, api);
  32766. lineGeometry.convertToTypedArray();
  32767. quadsGeometry.convertToTypedArray();
  32768. var otherAxis = cartesian.getAxis(this.faceInfo[2]);
  32769. updateFacePlane(this.rootNode, this.plane, otherAxis, this.faceInfo[3]);
  32770. };
  32771. Grid3DFace.prototype._updateSplitLines = function (geometry, axes, grid3DModel, api) {
  32772. var dpr = api.getDevicePixelRatio();
  32773. axes.forEach(function (axis, idx) {
  32774. var axisModel = axis.model;
  32775. var otherExtent = axes[1 - idx].getExtent();
  32776. if (axis.scale.isBlank()) {
  32777. return;
  32778. }
  32779. var splitLineModel = axisModel.getModel('splitLine', grid3DModel.getModel('splitLine'));
  32780. // Render splitLines
  32781. if (splitLineModel.get('show')) {
  32782. var lineStyleModel = splitLineModel.getModel('lineStyle');
  32783. var lineColors = lineStyleModel.get('color');
  32784. var opacity = firstNotNull(lineStyleModel.get('opacity'), 1.0);
  32785. var lineWidth = firstNotNull(lineStyleModel.get('width'), 1.0);
  32786. lineColors = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.isArray(lineColors) ? lineColors : [lineColors];
  32787. var ticksCoords = axis.getTicksCoords({
  32788. tickModel: splitLineModel
  32789. });
  32790. var count = 0;
  32791. for (var i = 0; i < ticksCoords.length; i++) {
  32792. var tickCoord = ticksCoords[i].coord;
  32793. var lineColor = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(lineColors[count % lineColors.length]);
  32794. lineColor[3] *= opacity;
  32795. var p0 = [0, 0, 0]; var p1 = [0, 0, 0];
  32796. // 0 - x, 1 - y
  32797. p0[idx] = p1[idx] = tickCoord;
  32798. p0[1 - idx] = otherExtent[0];
  32799. p1[1 - idx] = otherExtent[1];
  32800. geometry.addLine(p0, p1, lineColor, lineWidth * dpr);
  32801. count++;
  32802. }
  32803. }
  32804. });
  32805. };
  32806. Grid3DFace.prototype._udpateSplitAreas = function (geometry, axes, grid3DModel, api) {
  32807. axes.forEach(function (axis, idx) {
  32808. var axisModel = axis.model;
  32809. var otherExtent = axes[1 - idx].getExtent();
  32810. if (axis.scale.isBlank()) {
  32811. return;
  32812. }
  32813. var splitAreaModel = axisModel.getModel('splitArea', grid3DModel.getModel('splitArea'));
  32814. // Render splitAreas
  32815. if (splitAreaModel.get('show')) {
  32816. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  32817. var colors = areaStyleModel.get('color');
  32818. var opacity = firstNotNull(areaStyleModel.get('opacity'), 1.0);
  32819. colors = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.isArray(colors) ? colors : [colors];
  32820. var ticksCoords = axis.getTicksCoords({
  32821. tickModel: splitAreaModel,
  32822. clamp: true
  32823. });
  32824. var count = 0;
  32825. var prevP0 = [0, 0, 0];
  32826. var prevP1 = [0, 0, 0];
  32827. // 0 - x, 1 - y
  32828. for (var i = 0; i < ticksCoords.length; i++) {
  32829. var tickCoord = ticksCoords[i].coord;
  32830. var p0 = [0, 0, 0]; var p1 = [0, 0, 0];
  32831. // 0 - x, 1 - y
  32832. p0[idx] = p1[idx] = tickCoord;
  32833. p0[1 - idx] = otherExtent[0];
  32834. p1[1 - idx] = otherExtent[1];
  32835. if (i === 0) {
  32836. prevP0 = p0;
  32837. prevP1 = p1;
  32838. continue;
  32839. }
  32840. var color = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(colors[count % colors.length]);
  32841. color[3] *= opacity;
  32842. geometry.addQuad([prevP0, p0, p1, prevP1], color);
  32843. prevP0 = p0;
  32844. prevP1 = p1;
  32845. count++;
  32846. }
  32847. }
  32848. });
  32849. };
  32850. /* harmony default export */ __webpack_exports__["a"] = (Grid3DFace);
  32851. /***/
  32852. }),
  32853. /* 163 */
  32854. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  32855. "use strict";
  32856. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__ = __webpack_require__(15);
  32857. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts__ = __webpack_require__(0);
  32858. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts__);
  32859. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__dynamicConvertMixin__ = __webpack_require__(38);
  32860. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_claygl_src_dep_glmatrix__ = __webpack_require__(6);
  32861. /**
  32862. * @module echarts-gl/util/geometry/QuadsGeometry
  32863. * @author Yi Shen(http://github.com/pissang)
  32864. */
  32865. var vec3 = __WEBPACK_IMPORTED_MODULE_3_claygl_src_dep_glmatrix__["a" /* default */].vec3;
  32866. /**
  32867. * @constructor
  32868. * @alias module:echarts-gl/util/geometry/QuadsGeometry
  32869. * @extends clay.Geometry
  32870. */
  32871. var QuadsGeometry = __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].extend(function () {
  32872. return {
  32873. segmentScale: 1,
  32874. /**
  32875. * Need to use mesh to expand lines if lineWidth > MAX_LINE_WIDTH
  32876. */
  32877. useNativeLine: true,
  32878. attributes: {
  32879. position: new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].Attribute('position', 'float', 3, 'POSITION'),
  32880. normal: new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].Attribute('normal', 'float', 3, 'NORMAL'),
  32881. color: new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].Attribute('color', 'float', 4, 'COLOR')
  32882. }
  32883. };
  32884. },
  32885. /** @lends module: echarts-gl/util/geometry/QuadsGeometry.prototype */
  32886. {
  32887. /**
  32888. * Reset offset
  32889. */
  32890. resetOffset: function () {
  32891. this._vertexOffset = 0;
  32892. this._faceOffset = 0;
  32893. },
  32894. /**
  32895. * @param {number} nQuad
  32896. */
  32897. setQuadCount: function (nQuad) {
  32898. var attributes = this.attributes;
  32899. var vertexCount = this.getQuadVertexCount() * nQuad;
  32900. var triangleCount = this.getQuadTriangleCount() * nQuad;
  32901. if (this.vertexCount !== vertexCount) {
  32902. attributes.position.init(vertexCount);
  32903. attributes.normal.init(vertexCount);
  32904. attributes.color.init(vertexCount);
  32905. }
  32906. if (this.triangleCount !== triangleCount) {
  32907. this.indices = vertexCount > 0xffff ? new Uint32Array(triangleCount * 3) : new Uint16Array(triangleCount * 3);
  32908. }
  32909. },
  32910. getQuadVertexCount: function () {
  32911. return 4;
  32912. },
  32913. getQuadTriangleCount: function () {
  32914. return 2;
  32915. },
  32916. /**
  32917. * Add a quad, which in following order:
  32918. * 0-----1
  32919. * 3-----2
  32920. */
  32921. addQuad: (function () {
  32922. var a = vec3.create();
  32923. var b = vec3.create();
  32924. var normal = vec3.create();
  32925. var indices = [0, 3, 1, 3, 2, 1];
  32926. return function (coords, color) {
  32927. var positionAttr = this.attributes.position;
  32928. var normalAttr = this.attributes.normal;
  32929. var colorAttr = this.attributes.color;
  32930. vec3.sub(a, coords[1], coords[0]);
  32931. vec3.sub(b, coords[2], coords[1]);
  32932. vec3.cross(normal, a, b);
  32933. vec3.normalize(normal, normal);
  32934. for (var i = 0; i < 4; i++) {
  32935. positionAttr.set(this._vertexOffset + i, coords[i]);
  32936. colorAttr.set(this._vertexOffset + i, color);
  32937. normalAttr.set(this._vertexOffset + i, normal);
  32938. }
  32939. var idx = this._faceOffset * 3;
  32940. for (var i = 0; i < 6; i++) {
  32941. this.indices[idx + i] = indices[i] + this._vertexOffset;
  32942. }
  32943. this._vertexOffset += 4;
  32944. this._faceOffset += 2;
  32945. };
  32946. })()
  32947. });
  32948. __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default.a.util.defaults(QuadsGeometry.prototype, __WEBPACK_IMPORTED_MODULE_2__dynamicConvertMixin__["a" /* default */]);
  32949. /* harmony default export */ __webpack_exports__["a"] = (QuadsGeometry);
  32950. /***/
  32951. }),
  32952. /* 164 */
  32953. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  32954. "use strict";
  32955. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  32956. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  32957. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__ = __webpack_require__(1);
  32958. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_geometry_Lines3D__ = __webpack_require__(25);
  32959. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__util_retrieve__ = __webpack_require__(2);
  32960. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__util_mesh_LabelsMesh__ = __webpack_require__(63);
  32961. var firstNotNull = __WEBPACK_IMPORTED_MODULE_3__util_retrieve__["a" /* default */].firstNotNull;
  32962. var dimIndicesMap = {
  32963. // Left to right
  32964. x: 0,
  32965. // Far to near
  32966. y: 2,
  32967. // Bottom to up
  32968. z: 1
  32969. };
  32970. function Grid3DAxis(dim, linesMaterial) {
  32971. var linesMesh = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh({
  32972. geometry: new __WEBPACK_IMPORTED_MODULE_2__util_geometry_Lines3D__["a" /* default */]({ useNativeLine: false }),
  32973. material: linesMaterial,
  32974. castShadow: false,
  32975. ignorePicking: true, renderOrder: 2
  32976. });
  32977. var axisLabelsMesh = new __WEBPACK_IMPORTED_MODULE_4__util_mesh_LabelsMesh__["a" /* default */]();
  32978. axisLabelsMesh.material.depthMask = false;
  32979. var rootNode = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Node();
  32980. rootNode.add(linesMesh);
  32981. rootNode.add(axisLabelsMesh);
  32982. this.rootNode = rootNode;
  32983. this.dim = dim;
  32984. this.linesMesh = linesMesh;
  32985. this.labelsMesh = axisLabelsMesh;
  32986. this.axisLineCoords = null;
  32987. this.labelElements = [];
  32988. }
  32989. var otherDim = {
  32990. x: 'y', y: 'x', z: 'y'
  32991. };
  32992. Grid3DAxis.prototype.update = function (
  32993. grid3DModel, axisLabelSurface, api
  32994. ) {
  32995. var cartesian = grid3DModel.coordinateSystem;
  32996. var axis = cartesian.getAxis(this.dim);
  32997. var linesGeo = this.linesMesh.geometry;
  32998. var labelsGeo = this.labelsMesh.geometry;
  32999. linesGeo.convertToDynamicArray(true);
  33000. labelsGeo.convertToDynamicArray(true);
  33001. var axisModel = axis.model;
  33002. var extent = axis.getExtent();
  33003. var dpr = api.getDevicePixelRatio();
  33004. var axisLineModel = axisModel.getModel('axisLine', grid3DModel.getModel('axisLine'));
  33005. var axisTickModel = axisModel.getModel('axisTick', grid3DModel.getModel('axisTick'));
  33006. var axisLabelModel = axisModel.getModel('axisLabel', grid3DModel.getModel('axisLabel'));
  33007. var axisLineColor = axisLineModel.get('lineStyle.color');
  33008. // Render axisLine
  33009. if (axisLineModel.get('show')) {
  33010. var axisLineStyleModel = axisLineModel.getModel('lineStyle');
  33011. var p0 = [0, 0, 0]; var p1 = [0, 0, 0];
  33012. var idx = dimIndicesMap[axis.dim];
  33013. p0[idx] = extent[0];
  33014. p1[idx] = extent[1];
  33015. // Save some useful info.
  33016. this.axisLineCoords = [p0, p1];
  33017. var color = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(axisLineColor);
  33018. var lineWidth = firstNotNull(axisLineStyleModel.get('width'), 1.0);
  33019. var opacity = firstNotNull(axisLineStyleModel.get('opacity'), 1.0);
  33020. color[3] *= opacity;
  33021. linesGeo.addLine(p0, p1, color, lineWidth * dpr);
  33022. }
  33023. // Render axis ticksCoords
  33024. if (axisTickModel.get('show')) {
  33025. var lineStyleModel = axisTickModel.getModel('lineStyle');
  33026. var lineColor = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(
  33027. firstNotNull(lineStyleModel.get('color'), axisLineColor)
  33028. );
  33029. var lineWidth = firstNotNull(lineStyleModel.get('width'), 1.0);
  33030. lineColor[3] *= firstNotNull(lineStyleModel.get('opacity'), 1.0);
  33031. var ticksCoords = axis.getTicksCoords();
  33032. var tickLength = axisTickModel.get('length');
  33033. for (var i = 0; i < ticksCoords.length; i++) {
  33034. var tickCoord = ticksCoords[i].coord;
  33035. var p0 = [0, 0, 0]; var p1 = [0, 0, 0];
  33036. var idx = dimIndicesMap[axis.dim];
  33037. var otherIdx = dimIndicesMap[otherDim[axis.dim]];
  33038. // 0 : x, 1 : y
  33039. p0[idx] = p1[idx] = tickCoord;
  33040. p1[otherIdx] = tickLength;
  33041. linesGeo.addLine(p0, p1, lineColor, lineWidth * dpr);
  33042. }
  33043. }
  33044. this.labelElements = [];
  33045. var dpr = api.getDevicePixelRatio();
  33046. if (axisLabelModel.get('show')) {
  33047. var ticksCoords = axis.getTicksCoords();
  33048. var categoryData = axisModel.get('data');
  33049. var labelMargin = axisLabelModel.get('margin');
  33050. var labels = axis.getViewLabels();
  33051. for (var i = 0; i < labels.length; i++) {
  33052. var tickValue = labels[i].tickValue;
  33053. var formattedLabel = labels[i].formattedLabel;
  33054. var rawLabel = labels[i].rawLabel;
  33055. var tickCoord = axis.dataToCoord(tickValue);
  33056. var p = [0, 0, 0];
  33057. var idx = dimIndicesMap[axis.dim];
  33058. var otherIdx = dimIndicesMap[otherDim[axis.dim]];
  33059. // 0 : x, 1 : y
  33060. p[idx] = p[idx] = tickCoord;
  33061. p[otherIdx] = labelMargin;
  33062. var itemTextStyleModel = axisLabelModel;
  33063. if (categoryData && categoryData[tickValue] && categoryData[tickValue].textStyle) {
  33064. itemTextStyleModel = new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.Model(
  33065. categoryData[tickValue].textStyle, axisLabelModel, axisModel.ecModel
  33066. );
  33067. }
  33068. var textColor = firstNotNull(itemTextStyleModel.get('color'), axisLineColor);
  33069. var textEl = new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.graphic.Text();
  33070. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.graphic.setTextStyle(textEl.style, itemTextStyleModel, {
  33071. text: formattedLabel,
  33072. textFill: typeof textColor === 'function'
  33073. ? textColor(
  33074. // (1) In category axis with data zoom, tick is not the original
  33075. // index of axis.data. So tick should not be exposed to user
  33076. // in category axis.
  33077. // (2) Compatible with previous version, which always returns labelStr.
  33078. // But in interval scale labelStr is like '223,445', which maked
  33079. // user repalce ','. So we modify it to return original val but remain
  33080. // it as 'string' to avoid error in replacing.
  33081. axis.type === 'category' ? rawLabel : axis.type === 'value' ? tickValue + '' : tickValue,
  33082. i
  33083. )
  33084. : textColor,
  33085. textVerticalAlign: 'top',
  33086. textAlign: 'left'
  33087. });
  33088. var coords = axisLabelSurface.add(textEl);
  33089. var rect = textEl.getBoundingRect();
  33090. labelsGeo.addSprite(p, [rect.width * dpr, rect.height * dpr], coords);
  33091. this.labelElements.push(textEl);
  33092. }
  33093. }
  33094. if (axisModel.get('name')) {
  33095. var nameTextStyleModel = axisModel.getModel('nameTextStyle');
  33096. var p = [0, 0, 0];
  33097. var idx = dimIndicesMap[axis.dim];
  33098. var otherIdx = dimIndicesMap[otherDim[axis.dim]];
  33099. var labelColor = firstNotNull(nameTextStyleModel.get('color'), axisLineColor);
  33100. var strokeColor = nameTextStyleModel.get('borderColor');
  33101. var lineWidth = nameTextStyleModel.get('borderWidth');
  33102. // TODO start and end
  33103. p[idx] = p[idx] = (extent[0] + extent[1]) / 2;
  33104. p[otherIdx] = axisModel.get('nameGap');
  33105. var textEl = new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.graphic.Text();
  33106. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.graphic.setTextStyle(textEl.style, nameTextStyleModel, {
  33107. text: axisModel.get('name'),
  33108. textFill: labelColor,
  33109. textStroke: strokeColor,
  33110. lineWidth: lineWidth
  33111. });
  33112. var coords = axisLabelSurface.add(textEl);
  33113. var rect = textEl.getBoundingRect();
  33114. labelsGeo.addSprite(p, [rect.width * dpr, rect.height * dpr], coords);
  33115. textEl.__idx = this.labelElements.length;
  33116. this.nameLabelElement = textEl;
  33117. }
  33118. this.labelsMesh.material.set('textureAtlas', axisLabelSurface.getTexture());
  33119. this.labelsMesh.material.set('uvScale', axisLabelSurface.getCoordsScale());
  33120. linesGeo.convertToTypedArray();
  33121. labelsGeo.convertToTypedArray();
  33122. };
  33123. Grid3DAxis.prototype.setSpriteAlign = function (textAlign, textVerticalAlign, api) {
  33124. var dpr = api.getDevicePixelRatio();
  33125. var labelGeo = this.labelsMesh.geometry;
  33126. for (var i = 0; i < this.labelElements.length; i++) {
  33127. var labelEl = this.labelElements[i];
  33128. var rect = labelEl.getBoundingRect();
  33129. labelGeo.setSpriteAlign(i, [rect.width * dpr, rect.height * dpr], textAlign, textVerticalAlign);
  33130. }
  33131. // name label
  33132. var nameLabelEl = this.nameLabelElement;
  33133. if (nameLabelEl) {
  33134. var rect = nameLabelEl.getBoundingRect();
  33135. labelGeo.setSpriteAlign(nameLabelEl.__idx, [rect.width * dpr, rect.height * dpr], textAlign, textVerticalAlign);
  33136. labelGeo.dirty();
  33137. }
  33138. this.textAlign = textAlign;
  33139. this.textVerticalAlign = textVerticalAlign;
  33140. };
  33141. /* harmony default export */ __webpack_exports__["a"] = (Grid3DAxis);
  33142. /***/
  33143. }),
  33144. /* 165 */
  33145. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  33146. "use strict";
  33147. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  33148. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  33149. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_Geometry__ = __webpack_require__(15);
  33150. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__dynamicConvertMixin__ = __webpack_require__(38);
  33151. /**
  33152. * Geometry collecting sprites
  33153. *
  33154. * @module echarts-gl/util/geometry/Sprites
  33155. * @author Yi Shen(https://github.com/pissang)
  33156. */
  33157. var squareTriangles = [
  33158. 0, 1, 2, 0, 2, 3
  33159. ];
  33160. var SpritesGeometry = __WEBPACK_IMPORTED_MODULE_1_claygl_src_Geometry__["a" /* default */].extend(function () {
  33161. return {
  33162. attributes: {
  33163. position: new __WEBPACK_IMPORTED_MODULE_1_claygl_src_Geometry__["a" /* default */].Attribute('position', 'float', 3, 'POSITION'),
  33164. texcoord: new __WEBPACK_IMPORTED_MODULE_1_claygl_src_Geometry__["a" /* default */].Attribute('texcoord', 'float', 2, 'TEXCOORD_0'),
  33165. offset: new __WEBPACK_IMPORTED_MODULE_1_claygl_src_Geometry__["a" /* default */].Attribute('offset', 'float', 2),
  33166. color: new __WEBPACK_IMPORTED_MODULE_1_claygl_src_Geometry__["a" /* default */].Attribute('color', 'float', 4, 'COLOR')
  33167. }
  33168. };
  33169. }, {
  33170. resetOffset: function () {
  33171. this._vertexOffset = 0;
  33172. this._faceOffset = 0;
  33173. },
  33174. setSpriteCount: function (spriteCount) {
  33175. this._spriteCount = spriteCount;
  33176. var vertexCount = spriteCount * 4;
  33177. var triangleCount = spriteCount * 2;
  33178. if (this.vertexCount !== vertexCount) {
  33179. this.attributes.position.init(vertexCount);
  33180. this.attributes.offset.init(vertexCount);
  33181. this.attributes.color.init(vertexCount);
  33182. }
  33183. if (this.triangleCount !== triangleCount) {
  33184. this.indices = vertexCount > 0xffff ? new Uint32Array(triangleCount * 3) : new Uint16Array(triangleCount * 3);
  33185. }
  33186. },
  33187. setSpriteAlign: function (spriteOffset, size, align, verticalAlign, margin) {
  33188. if (align == null) {
  33189. align = 'left';
  33190. }
  33191. if (verticalAlign == null) {
  33192. verticalAlign = 'top';
  33193. }
  33194. var leftOffset, topOffset, rightOffset, bottomOffset;
  33195. margin = margin || 0;
  33196. switch (align) {
  33197. case 'left':
  33198. leftOffset = margin;
  33199. rightOffset = size[0] + margin;
  33200. break;
  33201. case 'center':
  33202. case 'middle':
  33203. leftOffset = -size[0] / 2;
  33204. rightOffset = size[0] / 2;
  33205. break;
  33206. case 'right':
  33207. leftOffset = -size[0] - margin;
  33208. rightOffset = -margin;
  33209. break;
  33210. }
  33211. switch (verticalAlign) {
  33212. case 'bottom':
  33213. topOffset = margin;
  33214. bottomOffset = size[1] + margin;
  33215. break;
  33216. case 'middle':
  33217. topOffset = -size[1] / 2;
  33218. bottomOffset = size[1] / 2;
  33219. break;
  33220. case 'top':
  33221. topOffset = -size[1] - margin;
  33222. bottomOffset = -margin;
  33223. break;
  33224. }
  33225. // 3----2
  33226. // 0----1
  33227. var vertexOffset = spriteOffset * 4;
  33228. var offsetAttr = this.attributes.offset;
  33229. offsetAttr.set(vertexOffset, [leftOffset, bottomOffset]);
  33230. offsetAttr.set(vertexOffset + 1, [rightOffset, bottomOffset]);
  33231. offsetAttr.set(vertexOffset + 2, [rightOffset, topOffset]);
  33232. offsetAttr.set(vertexOffset + 3, [leftOffset, topOffset]);
  33233. },
  33234. /**
  33235. * Add sprite
  33236. * @param {Array.<number>} position
  33237. * @param {Array.<number>} size [width, height]
  33238. * @param {Array.<Array>} coords [leftBottom, rightTop]
  33239. * @param {string} [align='left'] 'left' 'center' 'right'
  33240. * @param {string} [verticalAlign='top'] 'top' 'middle' 'bottom'
  33241. * @param {number} [screenMargin=0]
  33242. */
  33243. addSprite: function (position, size, coords, align, verticalAlign, screenMargin) {
  33244. var vertexOffset = this._vertexOffset;
  33245. this.setSprite(
  33246. this._vertexOffset / 4, position, size, coords, align, verticalAlign, screenMargin
  33247. )
  33248. for (var i = 0; i < squareTriangles.length; i++) {
  33249. this.indices[this._faceOffset * 3 + i] = squareTriangles[i] + vertexOffset;
  33250. }
  33251. this._faceOffset += 2;
  33252. this._vertexOffset += 4;
  33253. return vertexOffset / 4;
  33254. },
  33255. setSprite: function (spriteOffset, position, size, coords, align, verticalAlign, screenMargin) {
  33256. var vertexOffset = spriteOffset * 4;
  33257. var attributes = this.attributes;
  33258. for (var i = 0; i < 4; i++) {
  33259. attributes.position.set(vertexOffset + i, position);
  33260. }
  33261. // 3----2
  33262. // 0----1
  33263. var texcoordAttr = attributes.texcoord;
  33264. texcoordAttr.set(vertexOffset, [coords[0][0], coords[0][1]]);
  33265. texcoordAttr.set(vertexOffset + 1, [coords[1][0], coords[0][1]]);
  33266. texcoordAttr.set(vertexOffset + 2, [coords[1][0], coords[1][1]]);
  33267. texcoordAttr.set(vertexOffset + 3, [coords[0][0], coords[1][1]]);
  33268. this.setSpriteAlign(spriteOffset, size, align, verticalAlign, screenMargin);
  33269. }
  33270. });
  33271. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.defaults(SpritesGeometry.prototype, __WEBPACK_IMPORTED_MODULE_2__dynamicConvertMixin__["a" /* default */]);
  33272. /* harmony default export */ __webpack_exports__["a"] = (SpritesGeometry);
  33273. /***/
  33274. }),
  33275. /* 166 */
  33276. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  33277. "use strict";
  33278. /* harmony default export */ __webpack_exports__["a"] = ("@export ecgl.labels.vertex\n\nattribute vec3 position: POSITION;\nattribute vec2 texcoord: TEXCOORD_0;\nattribute vec2 offset;\n#ifdef VERTEX_COLOR\nattribute vec4 a_Color : COLOR;\nvarying vec4 v_Color;\n#endif\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform vec4 viewport : VIEWPORT;\n\nvarying vec2 v_Texcoord;\n\nvoid main()\n{\n vec4 proj = worldViewProjection * vec4(position, 1.0);\n\n vec2 screen = (proj.xy / abs(proj.w) + 1.0) * 0.5 * viewport.zw;\n\n screen += offset;\n\n proj.xy = (screen / viewport.zw - 0.5) * 2.0 * abs(proj.w);\n gl_Position = proj;\n#ifdef VERTEX_COLOR\n v_Color = a_Color;\n#endif\n v_Texcoord = texcoord;\n}\n@end\n\n\n@export ecgl.labels.fragment\n\nuniform vec3 color : [1.0, 1.0, 1.0];\nuniform float alpha : 1.0;\nuniform sampler2D textureAtlas;\nuniform vec2 uvScale: [1.0, 1.0];\n\n#ifdef VERTEX_COLOR\nvarying vec4 v_Color;\n#endif\nvarying float v_Miter;\n\nvarying vec2 v_Texcoord;\n\nvoid main()\n{\n gl_FragColor = vec4(color, alpha) * texture2D(textureAtlas, v_Texcoord * uvScale);\n#ifdef VERTEX_COLOR\n gl_FragColor *= v_Color;\n#endif\n}\n\n@end");
  33279. /***/
  33280. }),
  33281. /* 167 */
  33282. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  33283. "use strict";
  33284. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__grid3D_Cartesian3D__ = __webpack_require__(168);
  33285. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__grid3D_Axis3D__ = __webpack_require__(170);
  33286. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_echarts_lib_echarts__ = __webpack_require__(0);
  33287. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_echarts_lib_echarts__);
  33288. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_echarts_lib_util_layout__ = __webpack_require__(47);
  33289. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_echarts_lib_util_layout___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_3_echarts_lib_util_layout__);
  33290. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__core_ViewGL__ = __webpack_require__(22);
  33291. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__util_retrieve__ = __webpack_require__(2);
  33292. function resizeCartesian3D(grid3DModel, api) {
  33293. // Use left/top/width/height
  33294. var boxLayoutOption = grid3DModel.getBoxLayoutParams();
  33295. var viewport = __WEBPACK_IMPORTED_MODULE_3_echarts_lib_util_layout___default.a.getLayoutRect(boxLayoutOption, {
  33296. width: api.getWidth(),
  33297. height: api.getHeight()
  33298. });
  33299. // Flip Y
  33300. viewport.y = api.getHeight() - viewport.y - viewport.height;
  33301. this.viewGL.setViewport(viewport.x, viewport.y, viewport.width, viewport.height, api.getDevicePixelRatio());
  33302. var boxWidth = grid3DModel.get('boxWidth');
  33303. var boxHeight = grid3DModel.get('boxHeight');
  33304. var boxDepth = grid3DModel.get('boxDepth');
  33305. if (true) {
  33306. ['x', 'y', 'z'].forEach(function (dim) {
  33307. if (!this.getAxis(dim)) {
  33308. throw new Error('Grid' + grid3DModel.id + ' don\'t have ' + dim + 'Axis');
  33309. }
  33310. }, this);
  33311. }
  33312. this.getAxis('x').setExtent(-boxWidth / 2, boxWidth / 2);
  33313. // From near to far
  33314. this.getAxis('y').setExtent(boxDepth / 2, -boxDepth / 2);
  33315. this.getAxis('z').setExtent(-boxHeight / 2, boxHeight / 2);
  33316. this.size = [boxWidth, boxHeight, boxDepth];
  33317. }
  33318. function updateCartesian3D(ecModel, api) {
  33319. var dataExtents = {};
  33320. function unionDataExtents(dim, extent) {
  33321. dataExtents[dim] = dataExtents[dim] || [Infinity, -Infinity];
  33322. dataExtents[dim][0] = Math.min(extent[0], dataExtents[dim][0]);
  33323. dataExtents[dim][1] = Math.max(extent[1], dataExtents[dim][1]);
  33324. }
  33325. // Get data extents for scale.
  33326. ecModel.eachSeries(function (seriesModel) {
  33327. if (seriesModel.coordinateSystem !== this) {
  33328. return;
  33329. }
  33330. var data = seriesModel.getData();
  33331. ['x', 'y', 'z'].forEach(function (coordDim) {
  33332. data.mapDimension(coordDim, true).forEach(function (dataDim) {
  33333. unionDataExtents(
  33334. coordDim, data.getDataExtent(dataDim, true)
  33335. );
  33336. });
  33337. });
  33338. }, this);
  33339. ['xAxis3D', 'yAxis3D', 'zAxis3D'].forEach(function (axisType) {
  33340. ecModel.eachComponent(axisType, function (axisModel) {
  33341. var dim = axisType.charAt(0);
  33342. var grid3DModel = axisModel.getReferringComponents('grid3D')[0];
  33343. var cartesian3D = grid3DModel.coordinateSystem;
  33344. if (cartesian3D !== this) {
  33345. return;
  33346. }
  33347. var axis = cartesian3D.getAxis(dim);
  33348. if (axis) {
  33349. if (true) {
  33350. console.warn('Can\'t have two %s in one grid3D', axisType);
  33351. }
  33352. return;
  33353. }
  33354. var scale = __WEBPACK_IMPORTED_MODULE_2_echarts_lib_echarts___default.a.helper.createScale(
  33355. dataExtents[dim] || [Infinity, -Infinity], axisModel
  33356. );
  33357. axis = new __WEBPACK_IMPORTED_MODULE_1__grid3D_Axis3D__["a" /* default */](dim, scale);
  33358. axis.type = axisModel.get('type');
  33359. var isCategory = axis.type === 'category';
  33360. axis.onBand = isCategory && axisModel.get('boundaryGap');
  33361. axis.inverse = axisModel.get('inverse');
  33362. axisModel.axis = axis;
  33363. axis.model = axisModel;
  33364. // override `echarts/coord/Axis#getLabelModel`
  33365. axis.getLabelModel = function () {
  33366. return axisModel.getModel('axisLabel', grid3DModel.getModel('axisLabel'));
  33367. };
  33368. // override `echarts/coord/Axis#getTickModel`
  33369. axis.getTickModel = function () {
  33370. return axisModel.getModel('axisTick', grid3DModel.getModel('axisTick'));
  33371. };
  33372. cartesian3D.addAxis(axis);
  33373. }, this);
  33374. }, this);
  33375. this.resize(this.model, api);
  33376. }
  33377. var grid3DCreator = {
  33378. dimensions: __WEBPACK_IMPORTED_MODULE_0__grid3D_Cartesian3D__["a" /* default */].prototype.dimensions,
  33379. create: function (ecModel, api) {
  33380. var cartesian3DList = [];
  33381. ecModel.eachComponent('grid3D', function (grid3DModel) {
  33382. // FIXME
  33383. grid3DModel.__viewGL = grid3DModel.__viewGL || new __WEBPACK_IMPORTED_MODULE_4__core_ViewGL__["a" /* default */]();
  33384. var cartesian3D = new __WEBPACK_IMPORTED_MODULE_0__grid3D_Cartesian3D__["a" /* default */]();
  33385. cartesian3D.model = grid3DModel;
  33386. cartesian3D.viewGL = grid3DModel.__viewGL;
  33387. grid3DModel.coordinateSystem = cartesian3D;
  33388. cartesian3DList.push(cartesian3D);
  33389. // Inject resize and update
  33390. cartesian3D.resize = resizeCartesian3D;
  33391. cartesian3D.update = updateCartesian3D;
  33392. });
  33393. var axesTypes = ['xAxis3D', 'yAxis3D', 'zAxis3D'];
  33394. function findAxesModels(seriesModel, ecModel) {
  33395. return axesTypes.map(function (axisType) {
  33396. var axisModel = seriesModel.getReferringComponents(axisType)[0];
  33397. if (axisModel == null) {
  33398. axisModel = ecModel.getComponent(axisType);
  33399. }
  33400. if (true) {
  33401. if (!axisModel) {
  33402. throw new Error(axisType + ' "' + __WEBPACK_IMPORTED_MODULE_5__util_retrieve__["a" /* default */].firstNotNull(
  33403. seriesModel.get(axisType + 'Index'),
  33404. seriesModel.get(axisType + 'Id'),
  33405. 0
  33406. ) + '" not found');
  33407. }
  33408. }
  33409. return axisModel;
  33410. });
  33411. }
  33412. ecModel.eachSeries(function (seriesModel) {
  33413. if (seriesModel.get('coordinateSystem') !== 'cartesian3D') {
  33414. return;
  33415. }
  33416. var firstGridModel = seriesModel.getReferringComponents('grid3D')[0];
  33417. if (firstGridModel == null) {
  33418. var axesModels = findAxesModels(seriesModel, ecModel);
  33419. var firstGridModel = axesModels[0].getCoordSysModel();
  33420. axesModels.forEach(function (axisModel) {
  33421. var grid3DModel = axisModel.getCoordSysModel();
  33422. if (true) {
  33423. if (!grid3DModel) {
  33424. throw new Error(
  33425. 'grid3D "' + __WEBPACK_IMPORTED_MODULE_5__util_retrieve__["a" /* default */].firstNotNull(
  33426. axisModel.get('gridIndex'),
  33427. axisModel.get('gridId'),
  33428. 0
  33429. ) + '" not found'
  33430. );
  33431. }
  33432. if (grid3DModel !== firstGridModel) {
  33433. throw new Error('xAxis3D, yAxis3D, zAxis3D must use the same grid');
  33434. }
  33435. }
  33436. });
  33437. }
  33438. var coordSys = firstGridModel.coordinateSystem;
  33439. seriesModel.coordinateSystem = coordSys;
  33440. });
  33441. return cartesian3DList;
  33442. }
  33443. };
  33444. __WEBPACK_IMPORTED_MODULE_2_echarts_lib_echarts___default.a.registerCoordinateSystem('grid3D', grid3DCreator);
  33445. /* unused harmony default export */ var _unused_webpack_default_export = (grid3DCreator);
  33446. /***/
  33447. }),
  33448. /* 168 */
  33449. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  33450. "use strict";
  33451. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  33452. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  33453. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_coord_cartesian_Cartesian__ = __webpack_require__(169);
  33454. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_coord_cartesian_Cartesian___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_echarts_lib_coord_cartesian_Cartesian__);
  33455. function Cartesian3D(name) {
  33456. __WEBPACK_IMPORTED_MODULE_1_echarts_lib_coord_cartesian_Cartesian___default.a.call(this, name);
  33457. this.size = [0, 0, 0];
  33458. }
  33459. Cartesian3D.prototype = {
  33460. constructor: Cartesian3D,
  33461. type: 'cartesian3D',
  33462. dimensions: ['x', 'y', 'z'],
  33463. model: null,
  33464. containPoint: function (point) {
  33465. return this.getAxis('x').contain(point[0])
  33466. && this.getAxis('y').contain(point[2])
  33467. && this.getAxis('z').contain(point[1]);
  33468. },
  33469. containData: function (data) {
  33470. return this.getAxis('x').containData(data[0])
  33471. && this.getAxis('y').containData(data[1])
  33472. && this.getAxis('z').containData(data[2]);
  33473. },
  33474. dataToPoint: function (data, out, clamp) {
  33475. out = out || [];
  33476. out[0] = this.getAxis('x').dataToCoord(data[0], clamp);
  33477. out[2] = this.getAxis('y').dataToCoord(data[1], clamp);
  33478. out[1] = this.getAxis('z').dataToCoord(data[2], clamp);
  33479. return out;
  33480. },
  33481. pointToData: function (point, out, clamp) {
  33482. out = out || [];
  33483. out[0] = this.getAxis('x').coordToData(point[0], clamp);
  33484. out[1] = this.getAxis('y').coordToData(point[2], clamp);
  33485. out[2] = this.getAxis('z').coordToData(point[1], clamp);
  33486. return out;
  33487. }
  33488. };
  33489. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.inherits(Cartesian3D, __WEBPACK_IMPORTED_MODULE_1_echarts_lib_coord_cartesian_Cartesian___default.a);
  33490. /* harmony default export */ __webpack_exports__["a"] = (Cartesian3D);
  33491. /***/
  33492. }),
  33493. /* 169 */
  33494. /***/ (function (module, exports, __webpack_require__) {
  33495. var zrUtil = __webpack_require__(13);
  33496. /*
  33497. * Licensed to the Apache Software Foundation (ASF) under one
  33498. * or more contributor license agreements. See the NOTICE file
  33499. * distributed with this work for additional information
  33500. * regarding copyright ownership. The ASF licenses this file
  33501. * to you under the Apache License, Version 2.0 (the
  33502. * "License"); you may not use this file except in compliance
  33503. * with the License. You may obtain a copy of the License at
  33504. *
  33505. * http://www.apache.org/licenses/LICENSE-2.0
  33506. *
  33507. * Unless required by applicable law or agreed to in writing,
  33508. * software distributed under the License is distributed on an
  33509. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33510. * KIND, either express or implied. See the License for the
  33511. * specific language governing permissions and limitations
  33512. * under the License.
  33513. */
  33514. /**
  33515. * Cartesian coordinate system
  33516. * @module echarts/coord/Cartesian
  33517. *
  33518. */
  33519. function dimAxisMapper(dim) {
  33520. return this._axes[dim];
  33521. }
  33522. /**
  33523. * @alias module:echarts/coord/Cartesian
  33524. * @constructor
  33525. */
  33526. var Cartesian = function (name) {
  33527. this._axes = {};
  33528. this._dimList = [];
  33529. /**
  33530. * @type {string}
  33531. */
  33532. this.name = name || '';
  33533. };
  33534. Cartesian.prototype = {
  33535. constructor: Cartesian,
  33536. type: 'cartesian',
  33537. /**
  33538. * Get axis
  33539. * @param {number|string} dim
  33540. * @return {module:echarts/coord/Cartesian~Axis}
  33541. */
  33542. getAxis: function (dim) {
  33543. return this._axes[dim];
  33544. },
  33545. /**
  33546. * Get axes list
  33547. * @return {Array.<module:echarts/coord/Cartesian~Axis>}
  33548. */
  33549. getAxes: function () {
  33550. return zrUtil.map(this._dimList, dimAxisMapper, this);
  33551. },
  33552. /**
  33553. * Get axes list by given scale type
  33554. */
  33555. getAxesByScale: function (scaleType) {
  33556. scaleType = scaleType.toLowerCase();
  33557. return zrUtil.filter(this.getAxes(), function (axis) {
  33558. return axis.scale.type === scaleType;
  33559. });
  33560. },
  33561. /**
  33562. * Add axis
  33563. * @param {module:echarts/coord/Cartesian.Axis}
  33564. */
  33565. addAxis: function (axis) {
  33566. var dim = axis.dim;
  33567. this._axes[dim] = axis;
  33568. this._dimList.push(dim);
  33569. },
  33570. /**
  33571. * Convert data to coord in nd space
  33572. * @param {Array.<number>|Object.<string, number>} val
  33573. * @return {Array.<number>|Object.<string, number>}
  33574. */
  33575. dataToCoord: function (val) {
  33576. return this._dataCoordConvert(val, 'dataToCoord');
  33577. },
  33578. /**
  33579. * Convert coord in nd space to data
  33580. * @param {Array.<number>|Object.<string, number>} val
  33581. * @return {Array.<number>|Object.<string, number>}
  33582. */
  33583. coordToData: function (val) {
  33584. return this._dataCoordConvert(val, 'coordToData');
  33585. },
  33586. _dataCoordConvert: function (input, method) {
  33587. var dimList = this._dimList;
  33588. var output = input instanceof Array ? [] : {};
  33589. for (var i = 0; i < dimList.length; i++) {
  33590. var dim = dimList[i];
  33591. var axis = this._axes[dim];
  33592. output[dim] = axis[method](input[dim]);
  33593. }
  33594. return output;
  33595. }
  33596. };
  33597. var _default = Cartesian;
  33598. module.exports = _default;
  33599. /***/
  33600. }),
  33601. /* 170 */
  33602. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  33603. "use strict";
  33604. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  33605. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  33606. function Axis3D(dim, scale, extent) {
  33607. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.Axis.call(this, dim, scale, extent);
  33608. }
  33609. Axis3D.prototype = {
  33610. constructor: Axis3D,
  33611. getExtentMin: function () {
  33612. var extent = this._extent;
  33613. return Math.min(extent[0], extent[1]);
  33614. },
  33615. getExtentMax: function () {
  33616. var extent = this._extent;
  33617. return Math.max(extent[0], extent[1]);
  33618. },
  33619. calculateCategoryInterval: function () {
  33620. // TODO consider label length
  33621. return Math.floor(this.scale.count() / 8);
  33622. }
  33623. };
  33624. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.inherits(Axis3D, __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.Axis);
  33625. /* harmony default export */ __webpack_exports__["a"] = (Axis3D);
  33626. /***/
  33627. }),
  33628. /* 171 */
  33629. /***/ (function (module, exports, __webpack_require__) {
  33630. var zrUtil = __webpack_require__(13);
  33631. var textContain = __webpack_require__(172);
  33632. var numberUtil = __webpack_require__(85);
  33633. /*
  33634. * Licensed to the Apache Software Foundation (ASF) under one
  33635. * or more contributor license agreements. See the NOTICE file
  33636. * distributed with this work for additional information
  33637. * regarding copyright ownership. The ASF licenses this file
  33638. * to you under the Apache License, Version 2.0 (the
  33639. * "License"); you may not use this file except in compliance
  33640. * with the License. You may obtain a copy of the License at
  33641. *
  33642. * http://www.apache.org/licenses/LICENSE-2.0
  33643. *
  33644. * Unless required by applicable law or agreed to in writing,
  33645. * software distributed under the License is distributed on an
  33646. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33647. * KIND, either express or implied. See the License for the
  33648. * specific language governing permissions and limitations
  33649. * under the License.
  33650. */
  33651. /**
  33652. * æ¯ä¸‰ä½é»˜è®¤åŠ ,æ ¼å¼åŒ–
  33653. * @param {string|number} x
  33654. * @return {string}
  33655. */
  33656. function addCommas(x) {
  33657. if (isNaN(x)) {
  33658. return '-';
  33659. }
  33660. x = (x + '').split('.');
  33661. return x[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g, '$1,') + (x.length > 1 ? '.' + x[1] : '');
  33662. }
  33663. /**
  33664. * @param {string} str
  33665. * @param {boolean} [upperCaseFirst=false]
  33666. * @return {string} str
  33667. */
  33668. function toCamelCase(str, upperCaseFirst) {
  33669. str = (str || '').toLowerCase().replace(/-(.)/g, function (match, group1) {
  33670. return group1.toUpperCase();
  33671. });
  33672. if (upperCaseFirst && str) {
  33673. str = str.charAt(0).toUpperCase() + str.slice(1);
  33674. }
  33675. return str;
  33676. }
  33677. var normalizeCssArray = zrUtil.normalizeCssArray;
  33678. var replaceReg = /([&<>"'])/g;
  33679. var replaceMap = {
  33680. '&': '&amp;',
  33681. '<': '&lt;',
  33682. '>': '&gt;',
  33683. '"': '&quot;',
  33684. '\'': '&#39;'
  33685. };
  33686. function encodeHTML(source) {
  33687. return source == null ? '' : (source + '').replace(replaceReg, function (str, c) {
  33688. return replaceMap[c];
  33689. });
  33690. }
  33691. var TPL_VAR_ALIAS = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
  33692. var wrapVar = function (varName, seriesIdx) {
  33693. return '{' + varName + (seriesIdx == null ? '' : seriesIdx) + '}';
  33694. };
  33695. /**
  33696. * Template formatter
  33697. * @param {string} tpl
  33698. * @param {Array.<Object>|Object} paramsList
  33699. * @param {boolean} [encode=false]
  33700. * @return {string}
  33701. */
  33702. function formatTpl(tpl, paramsList, encode) {
  33703. if (!zrUtil.isArray(paramsList)) {
  33704. paramsList = [paramsList];
  33705. }
  33706. var seriesLen = paramsList.length;
  33707. if (!seriesLen) {
  33708. return '';
  33709. }
  33710. var $vars = paramsList[0].$vars || [];
  33711. for (var i = 0; i < $vars.length; i++) {
  33712. var alias = TPL_VAR_ALIAS[i];
  33713. tpl = tpl.replace(wrapVar(alias), wrapVar(alias, 0));
  33714. }
  33715. for (var seriesIdx = 0; seriesIdx < seriesLen; seriesIdx++) {
  33716. for (var k = 0; k < $vars.length; k++) {
  33717. var val = paramsList[seriesIdx][$vars[k]];
  33718. tpl = tpl.replace(wrapVar(TPL_VAR_ALIAS[k], seriesIdx), encode ? encodeHTML(val) : val);
  33719. }
  33720. }
  33721. return tpl;
  33722. }
  33723. /**
  33724. * simple Template formatter
  33725. *
  33726. * @param {string} tpl
  33727. * @param {Object} param
  33728. * @param {boolean} [encode=false]
  33729. * @return {string}
  33730. */
  33731. function formatTplSimple(tpl, param, encode) {
  33732. zrUtil.each(param, function (value, key) {
  33733. tpl = tpl.replace('{' + key + '}', encode ? encodeHTML(value) : value);
  33734. });
  33735. return tpl;
  33736. }
  33737. /**
  33738. * @param {Object|string} [opt] If string, means color.
  33739. * @param {string} [opt.color]
  33740. * @param {string} [opt.extraCssText]
  33741. * @param {string} [opt.type='item'] 'item' or 'subItem'
  33742. * @return {string}
  33743. */
  33744. function getTooltipMarker(opt, extraCssText) {
  33745. opt = zrUtil.isString(opt) ? {
  33746. color: opt,
  33747. extraCssText: extraCssText
  33748. } : opt || {};
  33749. var color = opt.color;
  33750. var type = opt.type;
  33751. var extraCssText = opt.extraCssText;
  33752. if (!color) {
  33753. return '';
  33754. }
  33755. return type === 'subItem' ? '<span style="display:inline-block;vertical-align:middle;margin-right:8px;margin-left:3px;' + 'border-radius:4px;width:4px;height:4px;background-color:' + encodeHTML(color) + ';' + (extraCssText || '') + '"></span>' : '<span style="display:inline-block;margin-right:5px;' + 'border-radius:10px;width:10px;height:10px;background-color:' + encodeHTML(color) + ';' + (extraCssText || '') + '"></span>';
  33756. }
  33757. function pad(str, len) {
  33758. str += '';
  33759. return '0000'.substr(0, len - str.length) + str;
  33760. }
  33761. /**
  33762. * ISO Date format
  33763. * @param {string} tpl
  33764. * @param {number} value
  33765. * @param {boolean} [isUTC=false] Default in local time.
  33766. * see `module:echarts/scale/Time`
  33767. * and `module:echarts/util/number#parseDate`.
  33768. * @inner
  33769. */
  33770. function formatTime(tpl, value, isUTC) {
  33771. if (tpl === 'week' || tpl === 'month' || tpl === 'quarter' || tpl === 'half-year' || tpl === 'year') {
  33772. tpl = 'MM-dd\nyyyy';
  33773. }
  33774. var date = numberUtil.parseDate(value);
  33775. var utc = isUTC ? 'UTC' : '';
  33776. var y = date['get' + utc + 'FullYear']();
  33777. var M = date['get' + utc + 'Month']() + 1;
  33778. var d = date['get' + utc + 'Date']();
  33779. var h = date['get' + utc + 'Hours']();
  33780. var m = date['get' + utc + 'Minutes']();
  33781. var s = date['get' + utc + 'Seconds']();
  33782. var S = date['get' + utc + 'Milliseconds']();
  33783. tpl = tpl.replace('MM', pad(M, 2)).replace('M', M).replace('yyyy', y).replace('yy', y % 100).replace('dd', pad(d, 2)).replace('d', d).replace('hh', pad(h, 2)).replace('h', h).replace('mm', pad(m, 2)).replace('m', m).replace('ss', pad(s, 2)).replace('s', s).replace('SSS', pad(S, 3));
  33784. return tpl;
  33785. }
  33786. /**
  33787. * Capital first
  33788. * @param {string} str
  33789. * @return {string}
  33790. */
  33791. function capitalFirst(str) {
  33792. return str ? str.charAt(0).toUpperCase() + str.substr(1) : str;
  33793. }
  33794. var truncateText = textContain.truncateText;
  33795. var getTextRect = textContain.getBoundingRect;
  33796. exports.addCommas = addCommas;
  33797. exports.toCamelCase = toCamelCase;
  33798. exports.normalizeCssArray = normalizeCssArray;
  33799. exports.encodeHTML = encodeHTML;
  33800. exports.formatTpl = formatTpl;
  33801. exports.formatTplSimple = formatTplSimple;
  33802. exports.getTooltipMarker = getTooltipMarker;
  33803. exports.formatTime = formatTime;
  33804. exports.capitalFirst = capitalFirst;
  33805. exports.truncateText = truncateText;
  33806. exports.getTextRect = getTextRect;
  33807. /***/
  33808. }),
  33809. /* 172 */
  33810. /***/ (function (module, exports, __webpack_require__) {
  33811. var BoundingRect = __webpack_require__(82);
  33812. var imageHelper = __webpack_require__(173);
  33813. var _util = __webpack_require__(13);
  33814. var getContext = _util.getContext;
  33815. var extend = _util.extend;
  33816. var retrieve2 = _util.retrieve2;
  33817. var retrieve3 = _util.retrieve3;
  33818. var trim = _util.trim;
  33819. var textWidthCache = {};
  33820. var textWidthCacheCounter = 0;
  33821. var TEXT_CACHE_MAX = 5000;
  33822. var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
  33823. var DEFAULT_FONT = '12px sans-serif'; // Avoid assign to an exported variable, for transforming to cjs.
  33824. var methods = {};
  33825. function $override(name, fn) {
  33826. methods[name] = fn;
  33827. }
  33828. /**
  33829. * @public
  33830. * @param {string} text
  33831. * @param {string} font
  33832. * @return {number} width
  33833. */
  33834. function getWidth(text, font) {
  33835. font = font || DEFAULT_FONT;
  33836. var key = text + ':' + font;
  33837. if (textWidthCache[key]) {
  33838. return textWidthCache[key];
  33839. }
  33840. var textLines = (text + '').split('\n');
  33841. var width = 0;
  33842. for (var i = 0, l = textLines.length; i < l; i++) {
  33843. // textContain.measureText may be overrided in SVG or VML
  33844. width = Math.max(measureText(textLines[i], font).width, width);
  33845. }
  33846. if (textWidthCacheCounter > TEXT_CACHE_MAX) {
  33847. textWidthCacheCounter = 0;
  33848. textWidthCache = {};
  33849. }
  33850. textWidthCacheCounter++;
  33851. textWidthCache[key] = width;
  33852. return width;
  33853. }
  33854. /**
  33855. * @public
  33856. * @param {string} text
  33857. * @param {string} font
  33858. * @param {string} [textAlign='left']
  33859. * @param {string} [textVerticalAlign='top']
  33860. * @param {Array.<number>} [textPadding]
  33861. * @param {Object} [rich]
  33862. * @param {Object} [truncate]
  33863. * @return {Object} {x, y, width, height, lineHeight}
  33864. */
  33865. function getBoundingRect(text, font, textAlign, textVerticalAlign, textPadding, rich, truncate) {
  33866. return rich ? getRichTextRect(text, font, textAlign, textVerticalAlign, textPadding, rich, truncate) : getPlainTextRect(text, font, textAlign, textVerticalAlign, textPadding, truncate);
  33867. }
  33868. function getPlainTextRect(text, font, textAlign, textVerticalAlign, textPadding, truncate) {
  33869. var contentBlock = parsePlainText(text, font, textPadding, truncate);
  33870. var outerWidth = getWidth(text, font);
  33871. if (textPadding) {
  33872. outerWidth += textPadding[1] + textPadding[3];
  33873. }
  33874. var outerHeight = contentBlock.outerHeight;
  33875. var x = adjustTextX(0, outerWidth, textAlign);
  33876. var y = adjustTextY(0, outerHeight, textVerticalAlign);
  33877. var rect = new BoundingRect(x, y, outerWidth, outerHeight);
  33878. rect.lineHeight = contentBlock.lineHeight;
  33879. return rect;
  33880. }
  33881. function getRichTextRect(text, font, textAlign, textVerticalAlign, textPadding, rich, truncate) {
  33882. var contentBlock = parseRichText(text, {
  33883. rich: rich,
  33884. truncate: truncate,
  33885. font: font,
  33886. textAlign: textAlign,
  33887. textPadding: textPadding
  33888. });
  33889. var outerWidth = contentBlock.outerWidth;
  33890. var outerHeight = contentBlock.outerHeight;
  33891. var x = adjustTextX(0, outerWidth, textAlign);
  33892. var y = adjustTextY(0, outerHeight, textVerticalAlign);
  33893. return new BoundingRect(x, y, outerWidth, outerHeight);
  33894. }
  33895. /**
  33896. * @public
  33897. * @param {number} x
  33898. * @param {number} width
  33899. * @param {string} [textAlign='left']
  33900. * @return {number} Adjusted x.
  33901. */
  33902. function adjustTextX(x, width, textAlign) {
  33903. // FIXME Right to left language
  33904. if (textAlign === 'right') {
  33905. x -= width;
  33906. } else if (textAlign === 'center') {
  33907. x -= width / 2;
  33908. }
  33909. return x;
  33910. }
  33911. /**
  33912. * @public
  33913. * @param {number} y
  33914. * @param {number} height
  33915. * @param {string} [textVerticalAlign='top']
  33916. * @return {number} Adjusted y.
  33917. */
  33918. function adjustTextY(y, height, textVerticalAlign) {
  33919. if (textVerticalAlign === 'middle') {
  33920. y -= height / 2;
  33921. } else if (textVerticalAlign === 'bottom') {
  33922. y -= height;
  33923. }
  33924. return y;
  33925. }
  33926. /**
  33927. * @public
  33928. * @param {stirng} textPosition
  33929. * @param {Object} rect {x, y, width, height}
  33930. * @param {number} distance
  33931. * @return {Object} {x, y, textAlign, textVerticalAlign}
  33932. */
  33933. function adjustTextPositionOnRect(textPosition, rect, distance) {
  33934. var x = rect.x;
  33935. var y = rect.y;
  33936. var height = rect.height;
  33937. var width = rect.width;
  33938. var halfHeight = height / 2;
  33939. var textAlign = 'left';
  33940. var textVerticalAlign = 'top';
  33941. switch (textPosition) {
  33942. case 'left':
  33943. x -= distance;
  33944. y += halfHeight;
  33945. textAlign = 'right';
  33946. textVerticalAlign = 'middle';
  33947. break;
  33948. case 'right':
  33949. x += distance + width;
  33950. y += halfHeight;
  33951. textVerticalAlign = 'middle';
  33952. break;
  33953. case 'top':
  33954. x += width / 2;
  33955. y -= distance;
  33956. textAlign = 'center';
  33957. textVerticalAlign = 'bottom';
  33958. break;
  33959. case 'bottom':
  33960. x += width / 2;
  33961. y += height + distance;
  33962. textAlign = 'center';
  33963. break;
  33964. case 'inside':
  33965. x += width / 2;
  33966. y += halfHeight;
  33967. textAlign = 'center';
  33968. textVerticalAlign = 'middle';
  33969. break;
  33970. case 'insideLeft':
  33971. x += distance;
  33972. y += halfHeight;
  33973. textVerticalAlign = 'middle';
  33974. break;
  33975. case 'insideRight':
  33976. x += width - distance;
  33977. y += halfHeight;
  33978. textAlign = 'right';
  33979. textVerticalAlign = 'middle';
  33980. break;
  33981. case 'insideTop':
  33982. x += width / 2;
  33983. y += distance;
  33984. textAlign = 'center';
  33985. break;
  33986. case 'insideBottom':
  33987. x += width / 2;
  33988. y += height - distance;
  33989. textAlign = 'center';
  33990. textVerticalAlign = 'bottom';
  33991. break;
  33992. case 'insideTopLeft':
  33993. x += distance;
  33994. y += distance;
  33995. break;
  33996. case 'insideTopRight':
  33997. x += width - distance;
  33998. y += distance;
  33999. textAlign = 'right';
  34000. break;
  34001. case 'insideBottomLeft':
  34002. x += distance;
  34003. y += height - distance;
  34004. textVerticalAlign = 'bottom';
  34005. break;
  34006. case 'insideBottomRight':
  34007. x += width - distance;
  34008. y += height - distance;
  34009. textAlign = 'right';
  34010. textVerticalAlign = 'bottom';
  34011. break;
  34012. }
  34013. return {
  34014. x: x,
  34015. y: y,
  34016. textAlign: textAlign,
  34017. textVerticalAlign: textVerticalAlign
  34018. };
  34019. }
  34020. /**
  34021. * Show ellipsis if overflow.
  34022. *
  34023. * @public
  34024. * @param {string} text
  34025. * @param {string} containerWidth
  34026. * @param {string} font
  34027. * @param {number} [ellipsis='...']
  34028. * @param {Object} [options]
  34029. * @param {number} [options.maxIterations=3]
  34030. * @param {number} [options.minChar=0] If truncate result are less
  34031. * then minChar, ellipsis will not show, which is
  34032. * better for user hint in some cases.
  34033. * @param {number} [options.placeholder=''] When all truncated, use the placeholder.
  34034. * @return {string}
  34035. */
  34036. function truncateText(text, containerWidth, font, ellipsis, options) {
  34037. if (!containerWidth) {
  34038. return '';
  34039. }
  34040. var textLines = (text + '').split('\n');
  34041. options = prepareTruncateOptions(containerWidth, font, ellipsis, options); // FIXME
  34042. // It is not appropriate that every line has '...' when truncate multiple lines.
  34043. for (var i = 0, len = textLines.length; i < len; i++) {
  34044. textLines[i] = truncateSingleLine(textLines[i], options);
  34045. }
  34046. return textLines.join('\n');
  34047. }
  34048. function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
  34049. options = extend({}, options);
  34050. options.font = font;
  34051. var ellipsis = retrieve2(ellipsis, '...');
  34052. options.maxIterations = retrieve2(options.maxIterations, 2);
  34053. var minChar = options.minChar = retrieve2(options.minChar, 0); // FIXME
  34054. // Other languages?
  34055. options.cnCharWidth = getWidth('国', font); // FIXME
  34056. // Consider proportional font?
  34057. var ascCharWidth = options.ascCharWidth = getWidth('a', font);
  34058. options.placeholder = retrieve2(options.placeholder, ''); // Example 1: minChar: 3, text: 'asdfzxcv', truncate result: 'asdf', but not: 'a...'.
  34059. // Example 2: minChar: 3, text: '维度', truncate result: '维', but not: '...'.
  34060. var contentWidth = containerWidth = Math.max(0, containerWidth - 1); // Reserve some gap.
  34061. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  34062. contentWidth -= ascCharWidth;
  34063. }
  34064. var ellipsisWidth = getWidth(ellipsis);
  34065. if (ellipsisWidth > contentWidth) {
  34066. ellipsis = '';
  34067. ellipsisWidth = 0;
  34068. }
  34069. contentWidth = containerWidth - ellipsisWidth;
  34070. options.ellipsis = ellipsis;
  34071. options.ellipsisWidth = ellipsisWidth;
  34072. options.contentWidth = contentWidth;
  34073. options.containerWidth = containerWidth;
  34074. return options;
  34075. }
  34076. function truncateSingleLine(textLine, options) {
  34077. var containerWidth = options.containerWidth;
  34078. var font = options.font;
  34079. var contentWidth = options.contentWidth;
  34080. if (!containerWidth) {
  34081. return '';
  34082. }
  34083. var lineWidth = getWidth(textLine, font);
  34084. if (lineWidth <= containerWidth) {
  34085. return textLine;
  34086. }
  34087. for (var j = 0; ; j++) {
  34088. if (lineWidth <= contentWidth || j >= options.maxIterations) {
  34089. textLine += options.ellipsis;
  34090. break;
  34091. }
  34092. var subLength = j === 0 ? estimateLength(textLine, contentWidth, options.ascCharWidth, options.cnCharWidth) : lineWidth > 0 ? Math.floor(textLine.length * contentWidth / lineWidth) : 0;
  34093. textLine = textLine.substr(0, subLength);
  34094. lineWidth = getWidth(textLine, font);
  34095. }
  34096. if (textLine === '') {
  34097. textLine = options.placeholder;
  34098. }
  34099. return textLine;
  34100. }
  34101. function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
  34102. var width = 0;
  34103. var i = 0;
  34104. for (var len = text.length; i < len && width < contentWidth; i++) {
  34105. var charCode = text.charCodeAt(i);
  34106. width += 0 <= charCode && charCode <= 127 ? ascCharWidth : cnCharWidth;
  34107. }
  34108. return i;
  34109. }
  34110. /**
  34111. * @public
  34112. * @param {string} font
  34113. * @return {number} line height
  34114. */
  34115. function getLineHeight(font) {
  34116. // FIXME A rough approach.
  34117. return getWidth('国', font);
  34118. }
  34119. /**
  34120. * @public
  34121. * @param {string} text
  34122. * @param {string} font
  34123. * @return {Object} width
  34124. */
  34125. function measureText(text, font) {
  34126. return methods.measureText(text, font);
  34127. } // Avoid assign to an exported variable, for transforming to cjs.
  34128. methods.measureText = function (text, font) {
  34129. var ctx = getContext();
  34130. ctx.font = font || DEFAULT_FONT;
  34131. return ctx.measureText(text);
  34132. };
  34133. /**
  34134. * @public
  34135. * @param {string} text
  34136. * @param {string} font
  34137. * @param {Object} [truncate]
  34138. * @return {Object} block: {lineHeight, lines, height, outerHeight}
  34139. * Notice: for performance, do not calculate outerWidth util needed.
  34140. */
  34141. function parsePlainText(text, font, padding, truncate) {
  34142. text != null && (text += '');
  34143. var lineHeight = getLineHeight(font);
  34144. var lines = text ? text.split('\n') : [];
  34145. var height = lines.length * lineHeight;
  34146. var outerHeight = height;
  34147. if (padding) {
  34148. outerHeight += padding[0] + padding[2];
  34149. }
  34150. if (text && truncate) {
  34151. var truncOuterHeight = truncate.outerHeight;
  34152. var truncOuterWidth = truncate.outerWidth;
  34153. if (truncOuterHeight != null && outerHeight > truncOuterHeight) {
  34154. text = '';
  34155. lines = [];
  34156. } else if (truncOuterWidth != null) {
  34157. var options = prepareTruncateOptions(truncOuterWidth - (padding ? padding[1] + padding[3] : 0), font, truncate.ellipsis, {
  34158. minChar: truncate.minChar,
  34159. placeholder: truncate.placeholder
  34160. }); // FIXME
  34161. // It is not appropriate that every line has '...' when truncate multiple lines.
  34162. for (var i = 0, len = lines.length; i < len; i++) {
  34163. lines[i] = truncateSingleLine(lines[i], options);
  34164. }
  34165. }
  34166. }
  34167. return {
  34168. lines: lines,
  34169. height: height,
  34170. outerHeight: outerHeight,
  34171. lineHeight: lineHeight
  34172. };
  34173. }
  34174. /**
  34175. * For example: 'some text {a|some text}other text{b|some text}xxx{c|}xxx'
  34176. * Also consider 'bbbb{a|xxx\nzzz}xxxx\naaaa'.
  34177. *
  34178. * @public
  34179. * @param {string} text
  34180. * @param {Object} style
  34181. * @return {Object} block
  34182. * {
  34183. * width,
  34184. * height,
  34185. * lines: [{
  34186. * lineHeight,
  34187. * width,
  34188. * tokens: [[{
  34189. * styleName,
  34190. * text,
  34191. * width, // include textPadding
  34192. * height, // include textPadding
  34193. * textWidth, // pure text width
  34194. * textHeight, // pure text height
  34195. * lineHeihgt,
  34196. * font,
  34197. * textAlign,
  34198. * textVerticalAlign
  34199. * }], [...], ...]
  34200. * }, ...]
  34201. * }
  34202. * If styleName is undefined, it is plain text.
  34203. */
  34204. function parseRichText(text, style) {
  34205. var contentBlock = {
  34206. lines: [],
  34207. width: 0,
  34208. height: 0
  34209. };
  34210. text != null && (text += '');
  34211. if (!text) {
  34212. return contentBlock;
  34213. }
  34214. var lastIndex = STYLE_REG.lastIndex = 0;
  34215. var result;
  34216. while ((result = STYLE_REG.exec(text)) != null) {
  34217. var matchedIndex = result.index;
  34218. if (matchedIndex > lastIndex) {
  34219. pushTokens(contentBlock, text.substring(lastIndex, matchedIndex));
  34220. }
  34221. pushTokens(contentBlock, result[2], result[1]);
  34222. lastIndex = STYLE_REG.lastIndex;
  34223. }
  34224. if (lastIndex < text.length) {
  34225. pushTokens(contentBlock, text.substring(lastIndex, text.length));
  34226. }
  34227. var lines = contentBlock.lines;
  34228. var contentHeight = 0;
  34229. var contentWidth = 0; // For `textWidth: 100%`
  34230. var pendingList = [];
  34231. var stlPadding = style.textPadding;
  34232. var truncate = style.truncate;
  34233. var truncateWidth = truncate && truncate.outerWidth;
  34234. var truncateHeight = truncate && truncate.outerHeight;
  34235. if (stlPadding) {
  34236. truncateWidth != null && (truncateWidth -= stlPadding[1] + stlPadding[3]);
  34237. truncateHeight != null && (truncateHeight -= stlPadding[0] + stlPadding[2]);
  34238. } // Calculate layout info of tokens.
  34239. for (var i = 0; i < lines.length; i++) {
  34240. var line = lines[i];
  34241. var lineHeight = 0;
  34242. var lineWidth = 0;
  34243. for (var j = 0; j < line.tokens.length; j++) {
  34244. var token = line.tokens[j];
  34245. var tokenStyle = token.styleName && style.rich[token.styleName] || {}; // textPadding should not inherit from style.
  34246. var textPadding = token.textPadding = tokenStyle.textPadding; // textFont has been asigned to font by `normalizeStyle`.
  34247. var font = token.font = tokenStyle.font || style.font; // textHeight can be used when textVerticalAlign is specified in token.
  34248. var tokenHeight = token.textHeight = retrieve2( // textHeight should not be inherited, consider it can be specified
  34249. // as box height of the block.
  34250. tokenStyle.textHeight, getLineHeight(font));
  34251. textPadding && (tokenHeight += textPadding[0] + textPadding[2]);
  34252. token.height = tokenHeight;
  34253. token.lineHeight = retrieve3(tokenStyle.textLineHeight, style.textLineHeight, tokenHeight);
  34254. token.textAlign = tokenStyle && tokenStyle.textAlign || style.textAlign;
  34255. token.textVerticalAlign = tokenStyle && tokenStyle.textVerticalAlign || 'middle';
  34256. if (truncateHeight != null && contentHeight + token.lineHeight > truncateHeight) {
  34257. return {
  34258. lines: [],
  34259. width: 0,
  34260. height: 0
  34261. };
  34262. }
  34263. token.textWidth = getWidth(token.text, font);
  34264. var tokenWidth = tokenStyle.textWidth;
  34265. var tokenWidthNotSpecified = tokenWidth == null || tokenWidth === 'auto'; // Percent width, can be `100%`, can be used in drawing separate
  34266. // line when box width is needed to be auto.
  34267. if (typeof tokenWidth === 'string' && tokenWidth.charAt(tokenWidth.length - 1) === '%') {
  34268. token.percentWidth = tokenWidth;
  34269. pendingList.push(token);
  34270. tokenWidth = 0; // Do not truncate in this case, because there is no user case
  34271. // and it is too complicated.
  34272. } else {
  34273. if (tokenWidthNotSpecified) {
  34274. tokenWidth = token.textWidth; // FIXME: If image is not loaded and textWidth is not specified, calling
  34275. // `getBoundingRect()` will not get correct result.
  34276. var textBackgroundColor = tokenStyle.textBackgroundColor;
  34277. var bgImg = textBackgroundColor && textBackgroundColor.image; // Use cases:
  34278. // (1) If image is not loaded, it will be loaded at render phase and call
  34279. // `dirty()` and `textBackgroundColor.image` will be replaced with the loaded
  34280. // image, and then the right size will be calculated here at the next tick.
  34281. // See `graphic/helper/text.js`.
  34282. // (2) If image loaded, and `textBackgroundColor.image` is image src string,
  34283. // use `imageHelper.findExistImage` to find cached image.
  34284. // `imageHelper.findExistImage` will always be called here before
  34285. // `imageHelper.createOrUpdateImage` in `graphic/helper/text.js#renderRichText`
  34286. // which ensures that image will not be rendered before correct size calcualted.
  34287. if (bgImg) {
  34288. bgImg = imageHelper.findExistImage(bgImg);
  34289. if (imageHelper.isImageReady(bgImg)) {
  34290. tokenWidth = Math.max(tokenWidth, bgImg.width * tokenHeight / bgImg.height);
  34291. }
  34292. }
  34293. }
  34294. var paddingW = textPadding ? textPadding[1] + textPadding[3] : 0;
  34295. tokenWidth += paddingW;
  34296. var remianTruncWidth = truncateWidth != null ? truncateWidth - lineWidth : null;
  34297. if (remianTruncWidth != null && remianTruncWidth < tokenWidth) {
  34298. if (!tokenWidthNotSpecified || remianTruncWidth < paddingW) {
  34299. token.text = '';
  34300. token.textWidth = tokenWidth = 0;
  34301. } else {
  34302. token.text = truncateText(token.text, remianTruncWidth - paddingW, font, truncate.ellipsis, {
  34303. minChar: truncate.minChar
  34304. });
  34305. token.textWidth = getWidth(token.text, font);
  34306. tokenWidth = token.textWidth + paddingW;
  34307. }
  34308. }
  34309. }
  34310. lineWidth += token.width = tokenWidth;
  34311. tokenStyle && (lineHeight = Math.max(lineHeight, token.lineHeight));
  34312. }
  34313. line.width = lineWidth;
  34314. line.lineHeight = lineHeight;
  34315. contentHeight += lineHeight;
  34316. contentWidth = Math.max(contentWidth, lineWidth);
  34317. }
  34318. contentBlock.outerWidth = contentBlock.width = retrieve2(style.textWidth, contentWidth);
  34319. contentBlock.outerHeight = contentBlock.height = retrieve2(style.textHeight, contentHeight);
  34320. if (stlPadding) {
  34321. contentBlock.outerWidth += stlPadding[1] + stlPadding[3];
  34322. contentBlock.outerHeight += stlPadding[0] + stlPadding[2];
  34323. }
  34324. for (var i = 0; i < pendingList.length; i++) {
  34325. var token = pendingList[i];
  34326. var percentWidth = token.percentWidth; // Should not base on outerWidth, because token can not be placed out of padding.
  34327. token.width = parseInt(percentWidth, 10) / 100 * contentWidth;
  34328. }
  34329. return contentBlock;
  34330. }
  34331. function pushTokens(block, str, styleName) {
  34332. var isEmptyStr = str === '';
  34333. var strs = str.split('\n');
  34334. var lines = block.lines;
  34335. for (var i = 0; i < strs.length; i++) {
  34336. var text = strs[i];
  34337. var token = {
  34338. styleName: styleName,
  34339. text: text,
  34340. isLineHolder: !text && !isEmptyStr
  34341. }; // The first token should be appended to the last line.
  34342. if (!i) {
  34343. var tokens = (lines[lines.length - 1] || (lines[0] = {
  34344. tokens: []
  34345. })).tokens; // Consider cases:
  34346. // (1) ''.split('\n') => ['', '\n', ''], the '' at the first item
  34347. // (which is a placeholder) should be replaced by new token.
  34348. // (2) A image backage, where token likes {a|}.
  34349. // (3) A redundant '' will affect textAlign in line.
  34350. // (4) tokens with the same tplName should not be merged, because
  34351. // they should be displayed in different box (with border and padding).
  34352. var tokensLen = tokens.length;
  34353. tokensLen === 1 && tokens[0].isLineHolder ? tokens[0] = token : // Consider text is '', only insert when it is the "lineHolder" or
  34354. // "emptyStr". Otherwise a redundant '' will affect textAlign in line.
  34355. (text || !tokensLen || isEmptyStr) && tokens.push(token);
  34356. } // Other tokens always start a new line.
  34357. else {
  34358. // If there is '', insert it as a placeholder.
  34359. lines.push({
  34360. tokens: [token]
  34361. });
  34362. }
  34363. }
  34364. }
  34365. function makeFont(style) {
  34366. // FIXME in node-canvas fontWeight is before fontStyle
  34367. // Use `fontSize` `fontFamily` to check whether font properties are defined.
  34368. var font = (style.fontSize || style.fontFamily) && [style.fontStyle, style.fontWeight, (style.fontSize || 12) + 'px', // If font properties are defined, `fontFamily` should not be ignored.
  34369. style.fontFamily || 'sans-serif'].join(' ');
  34370. return font && trim(font) || style.textFont || style.font;
  34371. }
  34372. exports.DEFAULT_FONT = DEFAULT_FONT;
  34373. exports.$override = $override;
  34374. exports.getWidth = getWidth;
  34375. exports.getBoundingRect = getBoundingRect;
  34376. exports.adjustTextX = adjustTextX;
  34377. exports.adjustTextY = adjustTextY;
  34378. exports.adjustTextPositionOnRect = adjustTextPositionOnRect;
  34379. exports.truncateText = truncateText;
  34380. exports.getLineHeight = getLineHeight;
  34381. exports.measureText = measureText;
  34382. exports.parsePlainText = parsePlainText;
  34383. exports.parseRichText = parseRichText;
  34384. exports.makeFont = makeFont;
  34385. /***/
  34386. }),
  34387. /* 173 */
  34388. /***/ (function (module, exports, __webpack_require__) {
  34389. var LRU = __webpack_require__(60);
  34390. var globalImageCache = new LRU(50);
  34391. /**
  34392. * @param {string|HTMLImageElement|HTMLCanvasElement|Canvas} newImageOrSrc
  34393. * @return {HTMLImageElement|HTMLCanvasElement|Canvas} image
  34394. */
  34395. function findExistImage(newImageOrSrc) {
  34396. if (typeof newImageOrSrc === 'string') {
  34397. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  34398. return cachedImgObj && cachedImgObj.image;
  34399. } else {
  34400. return newImageOrSrc;
  34401. }
  34402. }
  34403. /**
  34404. * Caution: User should cache loaded images, but not just count on LRU.
  34405. * Consider if required images more than LRU size, will dead loop occur?
  34406. *
  34407. * @param {string|HTMLImageElement|HTMLCanvasElement|Canvas} newImageOrSrc
  34408. * @param {HTMLImageElement|HTMLCanvasElement|Canvas} image Existent image.
  34409. * @param {module:zrender/Element} [hostEl] For calling `dirty`.
  34410. * @param {Function} [cb] params: (image, cbPayload)
  34411. * @param {Object} [cbPayload] Payload on cb calling.
  34412. * @return {HTMLImageElement|HTMLCanvasElement|Canvas} image
  34413. */
  34414. function createOrUpdateImage(newImageOrSrc, image, hostEl, cb, cbPayload) {
  34415. if (!newImageOrSrc) {
  34416. return image;
  34417. } else if (typeof newImageOrSrc === 'string') {
  34418. // Image should not be loaded repeatly.
  34419. if (image && image.__zrImageSrc === newImageOrSrc || !hostEl) {
  34420. return image;
  34421. } // Only when there is no existent image or existent image src
  34422. // is different, this method is responsible for load.
  34423. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  34424. var pendingWrap = {
  34425. hostEl: hostEl,
  34426. cb: cb,
  34427. cbPayload: cbPayload
  34428. };
  34429. if (cachedImgObj) {
  34430. image = cachedImgObj.image;
  34431. !isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
  34432. } else {
  34433. !image && (image = new Image());
  34434. image.onload = imageOnLoad;
  34435. globalImageCache.put(newImageOrSrc, image.__cachedImgObj = {
  34436. image: image,
  34437. pending: [pendingWrap]
  34438. });
  34439. image.src = image.__zrImageSrc = newImageOrSrc;
  34440. }
  34441. return image;
  34442. } // newImageOrSrc is an HTMLImageElement or HTMLCanvasElement or Canvas
  34443. else {
  34444. return newImageOrSrc;
  34445. }
  34446. }
  34447. function imageOnLoad() {
  34448. var cachedImgObj = this.__cachedImgObj;
  34449. this.onload = this.__cachedImgObj = null;
  34450. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  34451. var pendingWrap = cachedImgObj.pending[i];
  34452. var cb = pendingWrap.cb;
  34453. cb && cb(this, pendingWrap.cbPayload);
  34454. pendingWrap.hostEl.dirty();
  34455. }
  34456. cachedImgObj.pending.length = 0;
  34457. }
  34458. function isImageReady(image) {
  34459. return image && image.width && image.height;
  34460. }
  34461. exports.findExistImage = findExistImage;
  34462. exports.createOrUpdateImage = createOrUpdateImage;
  34463. exports.isImageReady = isImageReady;
  34464. /***/
  34465. }),
  34466. /* 174 */
  34467. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  34468. "use strict";
  34469. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__core_Base__ = __webpack_require__(7);
  34470. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__core_glenum__ = __webpack_require__(11);
  34471. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__math_Vector3__ = __webpack_require__(3);
  34472. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__math_BoundingBox__ = __webpack_require__(18);
  34473. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__math_Frustum__ = __webpack_require__(59);
  34474. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__math_Matrix4__ = __webpack_require__(9);
  34475. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__Renderer__ = __webpack_require__(52);
  34476. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__Shader__ = __webpack_require__(8);
  34477. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__Material__ = __webpack_require__(19);
  34478. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_9__FrameBuffer__ = __webpack_require__(10);
  34479. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_10__Texture__ = __webpack_require__(4);
  34480. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_11__Texture2D__ = __webpack_require__(5);
  34481. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_12__TextureCube__ = __webpack_require__(27);
  34482. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_13__camera_Perspective__ = __webpack_require__(41);
  34483. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_14__camera_Orthographic__ = __webpack_require__(37);
  34484. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_15__compositor_Pass__ = __webpack_require__(16);
  34485. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_16__compositor_TexturePool__ = __webpack_require__(86);
  34486. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_17__glmatrix_mat4__ = __webpack_require__(21);
  34487. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_18__shader_source_shadowmap_glsl_js__ = __webpack_require__(175);
  34488. var targets = ['px', 'nx', 'py', 'ny', 'pz', 'nz'];
  34489. __WEBPACK_IMPORTED_MODULE_7__Shader__["a" /* default */]['import'](__WEBPACK_IMPORTED_MODULE_18__shader_source_shadowmap_glsl_js__["a" /* default */]);
  34490. function getDepthMaterialUniform(renderable, depthMaterial, symbol) {
  34491. if (symbol === 'alphaMap') {
  34492. return renderable.material.get('diffuseMap');
  34493. }
  34494. else if (symbol === 'alphaCutoff') {
  34495. if (renderable.material.isDefined('fragment', 'ALPHA_TEST')
  34496. && renderable.material.get('diffuseMap')
  34497. ) {
  34498. var alphaCutoff = renderable.material.get('alphaCutoff');
  34499. return alphaCutoff || 0;
  34500. }
  34501. return 0;
  34502. }
  34503. else {
  34504. return depthMaterial.get(symbol);
  34505. }
  34506. }
  34507. function isDepthMaterialChanged(renderable, prevRenderable) {
  34508. var matA = renderable.material;
  34509. var matB = prevRenderable.material;
  34510. return matA.get('diffuseMap') !== matB.get('diffuseMap')
  34511. || (matA.get('alphaCutoff') || 0) !== (matB.get('alphaCutoff') || 0);
  34512. }
  34513. /**
  34514. * Pass rendering shadow map.
  34515. *
  34516. * @constructor clay.prePass.ShadowMap
  34517. * @extends clay.core.Base
  34518. * @example
  34519. * var shadowMapPass = new clay.prePass.ShadowMap({
  34520. * softShadow: clay.prePass.ShadowMap.VSM
  34521. * });
  34522. * ...
  34523. * animation.on('frame', function (frameTime) {
  34524. * shadowMapPass.render(renderer, scene, camera);
  34525. * renderer.render(scene, camera);
  34526. * });
  34527. */
  34528. var ShadowMapPass = __WEBPACK_IMPORTED_MODULE_0__core_Base__["a" /* default */].extend(function () {
  34529. return /** @lends clay.prePass.ShadowMap# */ {
  34530. /**
  34531. * Soft shadow technique.
  34532. * Can be {@link clay.prePass.ShadowMap.PCF} or {@link clay.prePass.ShadowMap.VSM}
  34533. * @type {number}
  34534. */
  34535. softShadow: ShadowMapPass.PCF,
  34536. /**
  34537. * Soft shadow blur size
  34538. * @type {number}
  34539. */
  34540. shadowBlur: 1.0,
  34541. lightFrustumBias: 'auto',
  34542. kernelPCF: new Float32Array([
  34543. 1, 0,
  34544. 1, 1,
  34545. -1, 1,
  34546. 0, 1,
  34547. -1, 0,
  34548. -1, -1,
  34549. 1, -1,
  34550. 0, -1
  34551. ]),
  34552. precision: 'highp',
  34553. _lastRenderNotCastShadow: false,
  34554. _frameBuffer: new __WEBPACK_IMPORTED_MODULE_9__FrameBuffer__["a" /* default */](),
  34555. _textures: {},
  34556. _shadowMapNumber: {
  34557. 'POINT_LIGHT': 0,
  34558. 'DIRECTIONAL_LIGHT': 0,
  34559. 'SPOT_LIGHT': 0
  34560. },
  34561. _depthMaterials: {},
  34562. _distanceMaterials: {},
  34563. _receivers: [],
  34564. _lightsCastShadow: [],
  34565. _lightCameras: {},
  34566. _lightMaterials: {},
  34567. _texturePool: new __WEBPACK_IMPORTED_MODULE_16__compositor_TexturePool__["a" /* default */]()
  34568. };
  34569. }, function () {
  34570. // Gaussian filter pass for VSM
  34571. this._gaussianPassH = new __WEBPACK_IMPORTED_MODULE_15__compositor_Pass__["a" /* default */]({
  34572. fragment: __WEBPACK_IMPORTED_MODULE_7__Shader__["a" /* default */].source('clay.compositor.gaussian_blur')
  34573. });
  34574. this._gaussianPassV = new __WEBPACK_IMPORTED_MODULE_15__compositor_Pass__["a" /* default */]({
  34575. fragment: __WEBPACK_IMPORTED_MODULE_7__Shader__["a" /* default */].source('clay.compositor.gaussian_blur')
  34576. });
  34577. this._gaussianPassH.setUniform('blurSize', this.shadowBlur);
  34578. this._gaussianPassH.setUniform('blurDir', 0.0);
  34579. this._gaussianPassV.setUniform('blurSize', this.shadowBlur);
  34580. this._gaussianPassV.setUniform('blurDir', 1.0);
  34581. this._outputDepthPass = new __WEBPACK_IMPORTED_MODULE_15__compositor_Pass__["a" /* default */]({
  34582. fragment: __WEBPACK_IMPORTED_MODULE_7__Shader__["a" /* default */].source('clay.sm.debug_depth')
  34583. });
  34584. }, {
  34585. /**
  34586. * Render scene to shadow textures
  34587. * @param {clay.Renderer} renderer
  34588. * @param {clay.Scene} scene
  34589. * @param {clay.Camera} sceneCamera
  34590. * @param {boolean} [notUpdateScene=false]
  34591. * @memberOf clay.prePass.ShadowMap.prototype
  34592. */
  34593. render: function (renderer, scene, sceneCamera, notUpdateScene) {
  34594. if (!sceneCamera) {
  34595. sceneCamera = scene.getMainCamera();
  34596. }
  34597. this.trigger('beforerender', this, renderer, scene, sceneCamera);
  34598. this._renderShadowPass(renderer, scene, sceneCamera, notUpdateScene);
  34599. this.trigger('afterrender', this, renderer, scene, sceneCamera);
  34600. },
  34601. /**
  34602. * Debug rendering of shadow textures
  34603. * @param {clay.Renderer} renderer
  34604. * @param {number} size
  34605. * @memberOf clay.prePass.ShadowMap.prototype
  34606. */
  34607. renderDebug: function (renderer, size) {
  34608. renderer.saveClear();
  34609. var viewport = renderer.viewport;
  34610. var x = 0, y = 0;
  34611. var width = size || viewport.width / 4;
  34612. var height = width;
  34613. if (this.softShadow === ShadowMapPass.VSM) {
  34614. this._outputDepthPass.material.define('fragment', 'USE_VSM');
  34615. }
  34616. else {
  34617. this._outputDepthPass.material.undefine('fragment', 'USE_VSM');
  34618. }
  34619. for (var name in this._textures) {
  34620. var texture = this._textures[name];
  34621. renderer.setViewport(x, y, width * texture.width / texture.height, height);
  34622. this._outputDepthPass.setUniform('depthMap', texture);
  34623. this._outputDepthPass.render(renderer);
  34624. x += width * texture.width / texture.height;
  34625. }
  34626. renderer.setViewport(viewport);
  34627. renderer.restoreClear();
  34628. },
  34629. _updateReceivers: function (renderer, mesh) {
  34630. if (mesh.receiveShadow) {
  34631. this._receivers.push(mesh);
  34632. mesh.material.set('shadowEnabled', 1);
  34633. mesh.material.set('pcfKernel', this.kernelPCF);
  34634. }
  34635. else {
  34636. mesh.material.set('shadowEnabled', 0);
  34637. }
  34638. if (this.softShadow === ShadowMapPass.VSM) {
  34639. mesh.material.define('fragment', 'USE_VSM');
  34640. mesh.material.undefine('fragment', 'PCF_KERNEL_SIZE');
  34641. }
  34642. else {
  34643. mesh.material.undefine('fragment', 'USE_VSM');
  34644. var kernelPCF = this.kernelPCF;
  34645. if (kernelPCF && kernelPCF.length) {
  34646. mesh.material.define('fragment', 'PCF_KERNEL_SIZE', kernelPCF.length / 2);
  34647. }
  34648. else {
  34649. mesh.material.undefine('fragment', 'PCF_KERNEL_SIZE');
  34650. }
  34651. }
  34652. },
  34653. _update: function (renderer, scene) {
  34654. var self = this;
  34655. scene.traverse(function (renderable) {
  34656. if (renderable.isRenderable()) {
  34657. self._updateReceivers(renderer, renderable);
  34658. }
  34659. });
  34660. for (var i = 0; i < scene.lights.length; i++) {
  34661. var light = scene.lights[i];
  34662. if (light.castShadow && !light.invisible) {
  34663. this._lightsCastShadow.push(light);
  34664. }
  34665. }
  34666. },
  34667. _renderShadowPass: function (renderer, scene, sceneCamera, notUpdateScene) {
  34668. // reset
  34669. for (var name in this._shadowMapNumber) {
  34670. this._shadowMapNumber[name] = 0;
  34671. }
  34672. this._lightsCastShadow.length = 0;
  34673. this._receivers.length = 0;
  34674. var _gl = renderer.gl;
  34675. if (!notUpdateScene) {
  34676. scene.update();
  34677. }
  34678. if (sceneCamera) {
  34679. sceneCamera.update();
  34680. }
  34681. scene.updateLights();
  34682. this._update(renderer, scene);
  34683. // Needs to update the receivers again if shadows come from 1 to 0.
  34684. if (!this._lightsCastShadow.length && this._lastRenderNotCastShadow) {
  34685. return;
  34686. }
  34687. this._lastRenderNotCastShadow = this._lightsCastShadow === 0;
  34688. _gl.enable(_gl.DEPTH_TEST);
  34689. _gl.depthMask(true);
  34690. _gl.disable(_gl.BLEND);
  34691. // Clear with high-z, so the part not rendered will not been shadowed
  34692. // TODO
  34693. // TODO restore
  34694. _gl.clearColor(1.0, 1.0, 1.0, 1.0);
  34695. // Shadow uniforms
  34696. var spotLightShadowMaps = [];
  34697. var spotLightMatrices = [];
  34698. var directionalLightShadowMaps = [];
  34699. var directionalLightMatrices = [];
  34700. var shadowCascadeClips = [];
  34701. var pointLightShadowMaps = [];
  34702. var dirLightHasCascade;
  34703. // Create textures for shadow map
  34704. for (var i = 0; i < this._lightsCastShadow.length; i++) {
  34705. var light = this._lightsCastShadow[i];
  34706. if (light.type === 'DIRECTIONAL_LIGHT') {
  34707. if (dirLightHasCascade) {
  34708. console.warn('Only one direectional light supported with shadow cascade');
  34709. continue;
  34710. }
  34711. if (light.shadowCascade > 4) {
  34712. console.warn('Support at most 4 cascade');
  34713. continue;
  34714. }
  34715. if (light.shadowCascade > 1) {
  34716. dirLightHasCascade = light;
  34717. }
  34718. this.renderDirectionalLightShadow(
  34719. renderer,
  34720. scene,
  34721. sceneCamera,
  34722. light,
  34723. shadowCascadeClips,
  34724. directionalLightMatrices,
  34725. directionalLightShadowMaps
  34726. );
  34727. }
  34728. else if (light.type === 'SPOT_LIGHT') {
  34729. this.renderSpotLightShadow(
  34730. renderer,
  34731. scene,
  34732. light,
  34733. spotLightMatrices,
  34734. spotLightShadowMaps
  34735. );
  34736. }
  34737. else if (light.type === 'POINT_LIGHT') {
  34738. this.renderPointLightShadow(
  34739. renderer,
  34740. scene,
  34741. light,
  34742. pointLightShadowMaps
  34743. );
  34744. }
  34745. this._shadowMapNumber[light.type]++;
  34746. }
  34747. for (var lightType in this._shadowMapNumber) {
  34748. var number = this._shadowMapNumber[lightType];
  34749. var key = lightType + '_SHADOWMAP_COUNT';
  34750. for (var i = 0; i < this._receivers.length; i++) {
  34751. var mesh = this._receivers[i];
  34752. var material = mesh.material;
  34753. if (material.fragmentDefines[key] !== number) {
  34754. if (number > 0) {
  34755. material.define('fragment', key, number);
  34756. }
  34757. else if (material.isDefined('fragment', key)) {
  34758. material.undefine('fragment', key);
  34759. }
  34760. }
  34761. }
  34762. }
  34763. for (var i = 0; i < this._receivers.length; i++) {
  34764. var mesh = this._receivers[i];
  34765. var material = mesh.material;
  34766. if (dirLightHasCascade) {
  34767. material.define('fragment', 'SHADOW_CASCADE', dirLightHasCascade.shadowCascade);
  34768. }
  34769. else {
  34770. material.undefine('fragment', 'SHADOW_CASCADE');
  34771. }
  34772. }
  34773. var shadowUniforms = scene.shadowUniforms;
  34774. function getSize(texture) {
  34775. return texture.height;
  34776. }
  34777. if (directionalLightShadowMaps.length > 0) {
  34778. var directionalLightShadowMapSizes = directionalLightShadowMaps.map(getSize);
  34779. shadowUniforms.directionalLightShadowMaps = { value: directionalLightShadowMaps, type: 'tv' };
  34780. shadowUniforms.directionalLightMatrices = { value: directionalLightMatrices, type: 'm4v' };
  34781. shadowUniforms.directionalLightShadowMapSizes = { value: directionalLightShadowMapSizes, type: '1fv' };
  34782. if (dirLightHasCascade) {
  34783. var shadowCascadeClipsNear = shadowCascadeClips.slice();
  34784. var shadowCascadeClipsFar = shadowCascadeClips.slice();
  34785. shadowCascadeClipsNear.pop();
  34786. shadowCascadeClipsFar.shift();
  34787. // Iterate from far to near
  34788. shadowCascadeClipsNear.reverse();
  34789. shadowCascadeClipsFar.reverse();
  34790. // directionalLightShadowMaps.reverse();
  34791. directionalLightMatrices.reverse();
  34792. shadowUniforms.shadowCascadeClipsNear = { value: shadowCascadeClipsNear, type: '1fv' };
  34793. shadowUniforms.shadowCascadeClipsFar = { value: shadowCascadeClipsFar, type: '1fv' };
  34794. }
  34795. }
  34796. if (spotLightShadowMaps.length > 0) {
  34797. var spotLightShadowMapSizes = spotLightShadowMaps.map(getSize);
  34798. var shadowUniforms = scene.shadowUniforms;
  34799. shadowUniforms.spotLightShadowMaps = { value: spotLightShadowMaps, type: 'tv' };
  34800. shadowUniforms.spotLightMatrices = { value: spotLightMatrices, type: 'm4v' };
  34801. shadowUniforms.spotLightShadowMapSizes = { value: spotLightShadowMapSizes, type: '1fv' };
  34802. }
  34803. if (pointLightShadowMaps.length > 0) {
  34804. shadowUniforms.pointLightShadowMaps = { value: pointLightShadowMaps, type: 'tv' };
  34805. }
  34806. },
  34807. renderDirectionalLightShadow: (function () {
  34808. var splitFrustum = new __WEBPACK_IMPORTED_MODULE_4__math_Frustum__["a" /* default */]();
  34809. var splitProjMatrix = new __WEBPACK_IMPORTED_MODULE_5__math_Matrix4__["a" /* default */]();
  34810. var cropBBox = new __WEBPACK_IMPORTED_MODULE_3__math_BoundingBox__["a" /* default */]();
  34811. var cropMatrix = new __WEBPACK_IMPORTED_MODULE_5__math_Matrix4__["a" /* default */]();
  34812. var lightViewMatrix = new __WEBPACK_IMPORTED_MODULE_5__math_Matrix4__["a" /* default */]();
  34813. var lightViewProjMatrix = new __WEBPACK_IMPORTED_MODULE_5__math_Matrix4__["a" /* default */]();
  34814. var lightProjMatrix = new __WEBPACK_IMPORTED_MODULE_5__math_Matrix4__["a" /* default */]();
  34815. return function (renderer, scene, sceneCamera, light, shadowCascadeClips, directionalLightMatrices, directionalLightShadowMaps) {
  34816. var defaultShadowMaterial = this._getDepthMaterial(light);
  34817. var passConfig = {
  34818. getMaterial: function (renderable) {
  34819. return renderable.shadowDepthMaterial || defaultShadowMaterial;
  34820. },
  34821. isMaterialChanged: isDepthMaterialChanged,
  34822. getUniform: getDepthMaterialUniform,
  34823. ifRender: function (renderable) {
  34824. return renderable.castShadow;
  34825. },
  34826. sortCompare: __WEBPACK_IMPORTED_MODULE_6__Renderer__["a" /* default */].opaqueSortCompare
  34827. };
  34828. // First frame
  34829. if (!scene.viewBoundingBoxLastFrame.isFinite()) {
  34830. var boundingBox = scene.getBoundingBox();
  34831. scene.viewBoundingBoxLastFrame
  34832. .copy(boundingBox).applyTransform(sceneCamera.viewMatrix);
  34833. }
  34834. // Considering moving speed since the bounding box is from last frame
  34835. // TODO: add a bias
  34836. var clippedFar = Math.min(-scene.viewBoundingBoxLastFrame.min.z, sceneCamera.far);
  34837. var clippedNear = Math.max(-scene.viewBoundingBoxLastFrame.max.z, sceneCamera.near);
  34838. var lightCamera = this._getDirectionalLightCamera(light, scene, sceneCamera);
  34839. var lvpMat4Arr = lightViewProjMatrix.array;
  34840. lightProjMatrix.copy(lightCamera.projectionMatrix);
  34841. __WEBPACK_IMPORTED_MODULE_17__glmatrix_mat4__["a" /* default */].invert(lightViewMatrix.array, lightCamera.worldTransform.array);
  34842. __WEBPACK_IMPORTED_MODULE_17__glmatrix_mat4__["a" /* default */].multiply(lightViewMatrix.array, lightViewMatrix.array, sceneCamera.worldTransform.array);
  34843. __WEBPACK_IMPORTED_MODULE_17__glmatrix_mat4__["a" /* default */].multiply(lvpMat4Arr, lightProjMatrix.array, lightViewMatrix.array);
  34844. var clipPlanes = [];
  34845. var isPerspective = sceneCamera instanceof __WEBPACK_IMPORTED_MODULE_13__camera_Perspective__["a" /* default */];
  34846. var scaleZ = (sceneCamera.near + sceneCamera.far) / (sceneCamera.near - sceneCamera.far);
  34847. var offsetZ = 2 * sceneCamera.near * sceneCamera.far / (sceneCamera.near - sceneCamera.far);
  34848. for (var i = 0; i <= light.shadowCascade; i++) {
  34849. var clog = clippedNear * Math.pow(clippedFar / clippedNear, i / light.shadowCascade);
  34850. var cuni = clippedNear + (clippedFar - clippedNear) * i / light.shadowCascade;
  34851. var c = clog * light.cascadeSplitLogFactor + cuni * (1 - light.cascadeSplitLogFactor);
  34852. clipPlanes.push(c);
  34853. shadowCascadeClips.push(-(-c * scaleZ + offsetZ) / -c);
  34854. }
  34855. var texture = this._getTexture(light, light.shadowCascade);
  34856. directionalLightShadowMaps.push(texture);
  34857. var viewport = renderer.viewport;
  34858. var _gl = renderer.gl;
  34859. this._frameBuffer.attach(texture);
  34860. this._frameBuffer.bind(renderer);
  34861. _gl.clear(_gl.COLOR_BUFFER_BIT | _gl.DEPTH_BUFFER_BIT);
  34862. for (var i = 0; i < light.shadowCascade; i++) {
  34863. // Get the splitted frustum
  34864. var nearPlane = clipPlanes[i];
  34865. var farPlane = clipPlanes[i + 1];
  34866. if (isPerspective) {
  34867. __WEBPACK_IMPORTED_MODULE_17__glmatrix_mat4__["a" /* default */].perspective(splitProjMatrix.array, sceneCamera.fov / 180 * Math.PI, sceneCamera.aspect, nearPlane, farPlane);
  34868. }
  34869. else {
  34870. __WEBPACK_IMPORTED_MODULE_17__glmatrix_mat4__["a" /* default */].ortho(
  34871. splitProjMatrix.array,
  34872. sceneCamera.left, sceneCamera.right, sceneCamera.bottom, sceneCamera.top,
  34873. nearPlane, farPlane
  34874. );
  34875. }
  34876. splitFrustum.setFromProjection(splitProjMatrix);
  34877. splitFrustum.getTransformedBoundingBox(cropBBox, lightViewMatrix);
  34878. cropBBox.applyProjection(lightProjMatrix);
  34879. var _min = cropBBox.min.array;
  34880. var _max = cropBBox.max.array;
  34881. _min[0] = Math.max(_min[0], -1);
  34882. _min[1] = Math.max(_min[1], -1);
  34883. _max[0] = Math.min(_max[0], 1);
  34884. _max[1] = Math.min(_max[1], 1);
  34885. cropMatrix.ortho(_min[0], _max[0], _min[1], _max[1], 1, -1);
  34886. lightCamera.projectionMatrix.multiplyLeft(cropMatrix);
  34887. var shadowSize = light.shadowResolution || 512;
  34888. // Reversed, left to right => far to near
  34889. renderer.setViewport((light.shadowCascade - i - 1) * shadowSize, 0, shadowSize, shadowSize, 1);
  34890. var renderList = scene.updateRenderList(lightCamera);
  34891. renderer.renderPass(renderList.opaque, lightCamera, passConfig);
  34892. // Filter for VSM
  34893. if (this.softShadow === ShadowMapPass.VSM) {
  34894. this._gaussianFilter(renderer, texture, texture.width);
  34895. }
  34896. var matrix = new __WEBPACK_IMPORTED_MODULE_5__math_Matrix4__["a" /* default */]();
  34897. matrix.copy(lightCamera.viewMatrix)
  34898. .multiplyLeft(lightCamera.projectionMatrix);
  34899. directionalLightMatrices.push(matrix.array);
  34900. lightCamera.projectionMatrix.copy(lightProjMatrix);
  34901. }
  34902. this._frameBuffer.unbind(renderer);
  34903. renderer.setViewport(viewport);
  34904. };
  34905. })(),
  34906. renderSpotLightShadow: function (renderer, scene, light, spotLightMatrices, spotLightShadowMaps) {
  34907. var texture = this._getTexture(light);
  34908. var lightCamera = this._getSpotLightCamera(light);
  34909. var _gl = renderer.gl;
  34910. this._frameBuffer.attach(texture);
  34911. this._frameBuffer.bind(renderer);
  34912. _gl.clear(_gl.COLOR_BUFFER_BIT | _gl.DEPTH_BUFFER_BIT);
  34913. var defaultShadowMaterial = this._getDepthMaterial(light);
  34914. var passConfig = {
  34915. getMaterial: function (renderable) {
  34916. return renderable.shadowDepthMaterial || defaultShadowMaterial;
  34917. },
  34918. isMaterialChanged: isDepthMaterialChanged,
  34919. getUniform: getDepthMaterialUniform,
  34920. ifRender: function (renderable) {
  34921. return renderable.castShadow;
  34922. },
  34923. sortCompare: __WEBPACK_IMPORTED_MODULE_6__Renderer__["a" /* default */].opaqueSortCompare
  34924. };
  34925. var renderList = scene.updateRenderList(lightCamera);
  34926. renderer.renderPass(renderList.opaque, lightCamera, passConfig);
  34927. this._frameBuffer.unbind(renderer);
  34928. // Filter for VSM
  34929. if (this.softShadow === ShadowMapPass.VSM) {
  34930. this._gaussianFilter(renderer, texture, texture.width);
  34931. }
  34932. var matrix = new __WEBPACK_IMPORTED_MODULE_5__math_Matrix4__["a" /* default */]();
  34933. matrix.copy(lightCamera.worldTransform)
  34934. .invert()
  34935. .multiplyLeft(lightCamera.projectionMatrix);
  34936. spotLightShadowMaps.push(texture);
  34937. spotLightMatrices.push(matrix.array);
  34938. },
  34939. renderPointLightShadow: function (renderer, scene, light, pointLightShadowMaps) {
  34940. var texture = this._getTexture(light);
  34941. var _gl = renderer.gl;
  34942. pointLightShadowMaps.push(texture);
  34943. var defaultShadowMaterial = this._getDepthMaterial(light);
  34944. var passConfig = {
  34945. getMaterial: function (renderable) {
  34946. return renderable.shadowDepthMaterial || defaultShadowMaterial;
  34947. },
  34948. getUniform: getDepthMaterialUniform,
  34949. sortCompare: __WEBPACK_IMPORTED_MODULE_6__Renderer__["a" /* default */].opaqueSortCompare
  34950. };
  34951. var renderListEachSide = {
  34952. px: [], py: [], pz: [], nx: [], ny: [], nz: []
  34953. };
  34954. var bbox = new __WEBPACK_IMPORTED_MODULE_3__math_BoundingBox__["a" /* default */]();
  34955. var lightWorldPosition = light.getWorldPosition().array;
  34956. var lightBBox = new __WEBPACK_IMPORTED_MODULE_3__math_BoundingBox__["a" /* default */]();
  34957. var range = light.range;
  34958. lightBBox.min.setArray(lightWorldPosition);
  34959. lightBBox.max.setArray(lightWorldPosition);
  34960. var extent = new __WEBPACK_IMPORTED_MODULE_2__math_Vector3__["a" /* default */](range, range, range);
  34961. lightBBox.max.add(extent);
  34962. lightBBox.min.sub(extent);
  34963. var targetsNeedRender = { px: false, py: false, pz: false, nx: false, ny: false, nz: false };
  34964. scene.traverse(function (renderable) {
  34965. if (renderable.isRenderable() && renderable.castShadow) {
  34966. var geometry = renderable.geometry;
  34967. if (!geometry.boundingBox) {
  34968. for (var i = 0; i < targets.length; i++) {
  34969. renderListEachSide[targets[i]].push(renderable);
  34970. }
  34971. return;
  34972. }
  34973. bbox.transformFrom(geometry.boundingBox, renderable.worldTransform);
  34974. if (!bbox.intersectBoundingBox(lightBBox)) {
  34975. return;
  34976. }
  34977. bbox.updateVertices();
  34978. for (var i = 0; i < targets.length; i++) {
  34979. targetsNeedRender[targets[i]] = false;
  34980. }
  34981. for (var i = 0; i < 8; i++) {
  34982. var vtx = bbox.vertices[i];
  34983. var x = vtx[0] - lightWorldPosition[0];
  34984. var y = vtx[1] - lightWorldPosition[1];
  34985. var z = vtx[2] - lightWorldPosition[2];
  34986. var absx = Math.abs(x);
  34987. var absy = Math.abs(y);
  34988. var absz = Math.abs(z);
  34989. if (absx > absy) {
  34990. if (absx > absz) {
  34991. targetsNeedRender[x > 0 ? 'px' : 'nx'] = true;
  34992. }
  34993. else {
  34994. targetsNeedRender[z > 0 ? 'pz' : 'nz'] = true;
  34995. }
  34996. }
  34997. else {
  34998. if (absy > absz) {
  34999. targetsNeedRender[y > 0 ? 'py' : 'ny'] = true;
  35000. }
  35001. else {
  35002. targetsNeedRender[z > 0 ? 'pz' : 'nz'] = true;
  35003. }
  35004. }
  35005. }
  35006. for (var i = 0; i < targets.length; i++) {
  35007. if (targetsNeedRender[targets[i]]) {
  35008. renderListEachSide[targets[i]].push(renderable);
  35009. }
  35010. }
  35011. }
  35012. });
  35013. for (var i = 0; i < 6; i++) {
  35014. var target = targets[i];
  35015. var camera = this._getPointLightCamera(light, target);
  35016. this._frameBuffer.attach(texture, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i);
  35017. this._frameBuffer.bind(renderer);
  35018. _gl.clear(_gl.COLOR_BUFFER_BIT | _gl.DEPTH_BUFFER_BIT);
  35019. renderer.renderPass(renderListEachSide[target], camera, passConfig);
  35020. }
  35021. this._frameBuffer.unbind(renderer);
  35022. },
  35023. _getDepthMaterial: function (light) {
  35024. var shadowMaterial = this._lightMaterials[light.__uid__];
  35025. var isPointLight = light.type === 'POINT_LIGHT';
  35026. if (!shadowMaterial) {
  35027. var shaderPrefix = isPointLight ? 'clay.sm.distance.' : 'clay.sm.depth.';
  35028. shadowMaterial = new __WEBPACK_IMPORTED_MODULE_8__Material__["a" /* default */]({
  35029. precision: this.precision,
  35030. shader: new __WEBPACK_IMPORTED_MODULE_7__Shader__["a" /* default */](__WEBPACK_IMPORTED_MODULE_7__Shader__["a" /* default */].source(shaderPrefix + 'vertex'), __WEBPACK_IMPORTED_MODULE_7__Shader__["a" /* default */].source(shaderPrefix + 'fragment'))
  35031. });
  35032. this._lightMaterials[light.__uid__] = shadowMaterial;
  35033. }
  35034. if (light.shadowSlopeScale != null) {
  35035. shadowMaterial.setUniform('slopeScale', light.shadowSlopeScale);
  35036. }
  35037. if (light.shadowBias != null) {
  35038. shadowMaterial.setUniform('bias', light.shadowBias);
  35039. }
  35040. if (this.softShadow === ShadowMapPass.VSM) {
  35041. shadowMaterial.define('fragment', 'USE_VSM');
  35042. }
  35043. else {
  35044. shadowMaterial.undefine('fragment', 'USE_VSM');
  35045. }
  35046. if (isPointLight) {
  35047. shadowMaterial.set('lightPosition', light.getWorldPosition().array);
  35048. shadowMaterial.set('range', light.range);
  35049. }
  35050. return shadowMaterial;
  35051. },
  35052. _gaussianFilter: function (renderer, texture, size) {
  35053. var parameter = {
  35054. width: size,
  35055. height: size,
  35056. type: __WEBPACK_IMPORTED_MODULE_10__Texture__["a" /* default */].FLOAT
  35057. };
  35058. var tmpTexture = this._texturePool.get(parameter);
  35059. this._frameBuffer.attach(tmpTexture);
  35060. this._frameBuffer.bind(renderer);
  35061. this._gaussianPassH.setUniform('texture', texture);
  35062. this._gaussianPassH.setUniform('textureWidth', size);
  35063. this._gaussianPassH.render(renderer);
  35064. this._frameBuffer.attach(texture);
  35065. this._gaussianPassV.setUniform('texture', tmpTexture);
  35066. this._gaussianPassV.setUniform('textureHeight', size);
  35067. this._gaussianPassV.render(renderer);
  35068. this._frameBuffer.unbind(renderer);
  35069. this._texturePool.put(tmpTexture);
  35070. },
  35071. _getTexture: function (light, cascade) {
  35072. var key = light.__uid__;
  35073. var texture = this._textures[key];
  35074. var resolution = light.shadowResolution || 512;
  35075. cascade = cascade || 1;
  35076. if (!texture) {
  35077. if (light.type === 'POINT_LIGHT') {
  35078. texture = new __WEBPACK_IMPORTED_MODULE_12__TextureCube__["a" /* default */]();
  35079. }
  35080. else {
  35081. texture = new __WEBPACK_IMPORTED_MODULE_11__Texture2D__["a" /* default */]();
  35082. }
  35083. // At most 4 cascade
  35084. // TODO share with height ?
  35085. texture.width = resolution * cascade;
  35086. texture.height = resolution;
  35087. if (this.softShadow === ShadowMapPass.VSM) {
  35088. texture.type = __WEBPACK_IMPORTED_MODULE_10__Texture__["a" /* default */].FLOAT;
  35089. texture.anisotropic = 4;
  35090. }
  35091. else {
  35092. texture.minFilter = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].NEAREST;
  35093. texture.magFilter = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].NEAREST;
  35094. texture.useMipmap = false;
  35095. }
  35096. this._textures[key] = texture;
  35097. }
  35098. return texture;
  35099. },
  35100. _getPointLightCamera: function (light, target) {
  35101. if (!this._lightCameras.point) {
  35102. this._lightCameras.point = {
  35103. px: new __WEBPACK_IMPORTED_MODULE_13__camera_Perspective__["a" /* default */](),
  35104. nx: new __WEBPACK_IMPORTED_MODULE_13__camera_Perspective__["a" /* default */](),
  35105. py: new __WEBPACK_IMPORTED_MODULE_13__camera_Perspective__["a" /* default */](),
  35106. ny: new __WEBPACK_IMPORTED_MODULE_13__camera_Perspective__["a" /* default */](),
  35107. pz: new __WEBPACK_IMPORTED_MODULE_13__camera_Perspective__["a" /* default */](),
  35108. nz: new __WEBPACK_IMPORTED_MODULE_13__camera_Perspective__["a" /* default */]()
  35109. };
  35110. }
  35111. var camera = this._lightCameras.point[target];
  35112. camera.far = light.range;
  35113. camera.fov = 90;
  35114. camera.position.set(0, 0, 0);
  35115. switch (target) {
  35116. case 'px':
  35117. camera.lookAt(__WEBPACK_IMPORTED_MODULE_2__math_Vector3__["a" /* default */].POSITIVE_X, __WEBPACK_IMPORTED_MODULE_2__math_Vector3__["a" /* default */].NEGATIVE_Y);
  35118. break;
  35119. case 'nx':
  35120. camera.lookAt(__WEBPACK_IMPORTED_MODULE_2__math_Vector3__["a" /* default */].NEGATIVE_X, __WEBPACK_IMPORTED_MODULE_2__math_Vector3__["a" /* default */].NEGATIVE_Y);
  35121. break;
  35122. case 'py':
  35123. camera.lookAt(__WEBPACK_IMPORTED_MODULE_2__math_Vector3__["a" /* default */].POSITIVE_Y, __WEBPACK_IMPORTED_MODULE_2__math_Vector3__["a" /* default */].POSITIVE_Z);
  35124. break;
  35125. case 'ny':
  35126. camera.lookAt(__WEBPACK_IMPORTED_MODULE_2__math_Vector3__["a" /* default */].NEGATIVE_Y, __WEBPACK_IMPORTED_MODULE_2__math_Vector3__["a" /* default */].NEGATIVE_Z);
  35127. break;
  35128. case 'pz':
  35129. camera.lookAt(__WEBPACK_IMPORTED_MODULE_2__math_Vector3__["a" /* default */].POSITIVE_Z, __WEBPACK_IMPORTED_MODULE_2__math_Vector3__["a" /* default */].NEGATIVE_Y);
  35130. break;
  35131. case 'nz':
  35132. camera.lookAt(__WEBPACK_IMPORTED_MODULE_2__math_Vector3__["a" /* default */].NEGATIVE_Z, __WEBPACK_IMPORTED_MODULE_2__math_Vector3__["a" /* default */].NEGATIVE_Y);
  35133. break;
  35134. }
  35135. light.getWorldPosition(camera.position);
  35136. camera.update();
  35137. return camera;
  35138. },
  35139. _getDirectionalLightCamera: (function () {
  35140. var lightViewMatrix = new __WEBPACK_IMPORTED_MODULE_5__math_Matrix4__["a" /* default */]();
  35141. var sceneViewBoundingBox = new __WEBPACK_IMPORTED_MODULE_3__math_BoundingBox__["a" /* default */]();
  35142. var lightViewBBox = new __WEBPACK_IMPORTED_MODULE_3__math_BoundingBox__["a" /* default */]();
  35143. // Camera of directional light will be adjusted
  35144. // to contain the view frustum and scene bounding box as tightly as possible
  35145. return function (light, scene, sceneCamera) {
  35146. if (!this._lightCameras.directional) {
  35147. this._lightCameras.directional = new __WEBPACK_IMPORTED_MODULE_14__camera_Orthographic__["a" /* default */]();
  35148. }
  35149. var camera = this._lightCameras.directional;
  35150. sceneViewBoundingBox.copy(scene.viewBoundingBoxLastFrame);
  35151. sceneViewBoundingBox.intersection(sceneCamera.frustum.boundingBox);
  35152. // Move to the center of frustum(in world space)
  35153. camera.position
  35154. .copy(sceneViewBoundingBox.min)
  35155. .add(sceneViewBoundingBox.max)
  35156. .scale(0.5)
  35157. .transformMat4(sceneCamera.worldTransform);
  35158. camera.rotation.copy(light.rotation);
  35159. camera.scale.copy(light.scale);
  35160. camera.updateWorldTransform();
  35161. // Transform to light view space
  35162. __WEBPACK_IMPORTED_MODULE_5__math_Matrix4__["a" /* default */].invert(lightViewMatrix, camera.worldTransform);
  35163. __WEBPACK_IMPORTED_MODULE_5__math_Matrix4__["a" /* default */].multiply(lightViewMatrix, lightViewMatrix, sceneCamera.worldTransform);
  35164. lightViewBBox.copy(sceneViewBoundingBox).applyTransform(lightViewMatrix);
  35165. var min = lightViewBBox.min.array;
  35166. var max = lightViewBBox.max.array;
  35167. // Move camera to adjust the near to 0
  35168. camera.position.set((min[0] + max[0]) / 2, (min[1] + max[1]) / 2, max[2])
  35169. .transformMat4(camera.worldTransform);
  35170. camera.near = 0;
  35171. camera.far = -min[2] + max[2];
  35172. // Make sure receivers not in the frustum will stil receive the shadow.
  35173. if (isNaN(this.lightFrustumBias)) {
  35174. camera.far *= 4;
  35175. }
  35176. else {
  35177. camera.far += this.lightFrustumBias;
  35178. }
  35179. camera.left = min[0];
  35180. camera.right = max[0];
  35181. camera.top = max[1];
  35182. camera.bottom = min[1];
  35183. camera.update(true);
  35184. return camera;
  35185. };
  35186. })(),
  35187. _getSpotLightCamera: function (light) {
  35188. if (!this._lightCameras.spot) {
  35189. this._lightCameras.spot = new __WEBPACK_IMPORTED_MODULE_13__camera_Perspective__["a" /* default */]();
  35190. }
  35191. var camera = this._lightCameras.spot;
  35192. // Update properties
  35193. camera.fov = light.penumbraAngle * 2;
  35194. camera.far = light.range;
  35195. camera.worldTransform.copy(light.worldTransform);
  35196. camera.updateProjectionMatrix();
  35197. __WEBPACK_IMPORTED_MODULE_17__glmatrix_mat4__["a" /* default */].invert(camera.viewMatrix.array, camera.worldTransform.array);
  35198. return camera;
  35199. },
  35200. /**
  35201. * @param {clay.Renderer|WebGLRenderingContext} [renderer]
  35202. * @memberOf clay.prePass.ShadowMap.prototype
  35203. */
  35204. // PENDING Renderer or WebGLRenderingContext
  35205. dispose: function (renderer) {
  35206. var _gl = renderer.gl || renderer;
  35207. if (this._frameBuffer) {
  35208. this._frameBuffer.dispose(_gl);
  35209. }
  35210. for (var name in this._textures) {
  35211. this._textures[name].dispose(_gl);
  35212. }
  35213. this._texturePool.clear(renderer.gl);
  35214. this._depthMaterials = {};
  35215. this._distanceMaterials = {};
  35216. this._textures = {};
  35217. this._lightCameras = {};
  35218. this._shadowMapNumber = {
  35219. 'POINT_LIGHT': 0,
  35220. 'DIRECTIONAL_LIGHT': 0,
  35221. 'SPOT_LIGHT': 0
  35222. };
  35223. this._meshMaterials = {};
  35224. for (var i = 0; i < this._receivers.length; i++) {
  35225. var mesh = this._receivers[i];
  35226. // Mesh may be disposed
  35227. if (mesh.material) {
  35228. var material = mesh.material;
  35229. material.undefine('fragment', 'POINT_LIGHT_SHADOW_COUNT');
  35230. material.undefine('fragment', 'DIRECTIONAL_LIGHT_SHADOW_COUNT');
  35231. material.undefine('fragment', 'AMBIENT_LIGHT_SHADOW_COUNT');
  35232. material.set('shadowEnabled', 0);
  35233. }
  35234. }
  35235. this._receivers = [];
  35236. this._lightsCastShadow = [];
  35237. }
  35238. });
  35239. /**
  35240. * @name clay.prePass.ShadowMap.VSM
  35241. * @type {number}
  35242. */
  35243. ShadowMapPass.VSM = 1;
  35244. /**
  35245. * @name clay.prePass.ShadowMap.PCF
  35246. * @type {number}
  35247. */
  35248. ShadowMapPass.PCF = 2;
  35249. /* harmony default export */ __webpack_exports__["a"] = (ShadowMapPass);
  35250. /***/
  35251. }),
  35252. /* 175 */
  35253. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  35254. "use strict";
  35255. /* harmony default export */ __webpack_exports__["a"] = ("@export clay.sm.depth.vertex\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nattribute vec3 position : POSITION;\nattribute vec2 texcoord : TEXCOORD_0;\n@import clay.chunk.skinning_header\nvarying vec4 v_ViewPosition;\nvarying vec2 v_Texcoord;\nvoid main(){\n vec3 skinnedPosition = position;\n#ifdef SKINNING\n @import clay.chunk.skin_matrix\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n#endif\n v_ViewPosition = worldViewProjection * vec4(skinnedPosition, 1.0);\n gl_Position = v_ViewPosition;\n v_Texcoord = texcoord;\n}\n@end\n@export clay.sm.depth.fragment\nvarying vec4 v_ViewPosition;\nvarying vec2 v_Texcoord;\nuniform float bias : 0.001;\nuniform float slopeScale : 1.0;\nuniform sampler2D alphaMap;\nuniform float alphaCutoff: 0.0;\n@import clay.util.encode_float\nvoid main(){\n float depth = v_ViewPosition.z / v_ViewPosition.w;\n if (alphaCutoff > 0.0) {\n if (texture2D(alphaMap, v_Texcoord).a <= alphaCutoff) {\n discard;\n }\n }\n#ifdef USE_VSM\n depth = depth * 0.5 + 0.5;\n float moment1 = depth;\n float moment2 = depth * depth;\n float dx = dFdx(depth);\n float dy = dFdy(depth);\n moment2 += 0.25*(dx*dx+dy*dy);\n gl_FragColor = vec4(moment1, moment2, 0.0, 1.0);\n#else\n float dx = dFdx(depth);\n float dy = dFdy(depth);\n depth += sqrt(dx*dx + dy*dy) * slopeScale + bias;\n gl_FragColor = encodeFloat(depth * 0.5 + 0.5);\n#endif\n}\n@end\n@export clay.sm.debug_depth\nuniform sampler2D depthMap;\nvarying vec2 v_Texcoord;\n@import clay.util.decode_float\nvoid main() {\n vec4 tex = texture2D(depthMap, v_Texcoord);\n#ifdef USE_VSM\n gl_FragColor = vec4(tex.rgb, 1.0);\n#else\n float depth = decodeFloat(tex);\n gl_FragColor = vec4(depth, depth, depth, 1.0);\n#endif\n}\n@end\n@export clay.sm.distance.vertex\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform mat4 world : WORLD;\nattribute vec3 position : POSITION;\n@import clay.chunk.skinning_header\nvarying vec3 v_WorldPosition;\nvoid main (){\n vec3 skinnedPosition = position;\n#ifdef SKINNING\n @import clay.chunk.skin_matrix\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n#endif\n gl_Position = worldViewProjection * vec4(skinnedPosition , 1.0);\n v_WorldPosition = (world * vec4(skinnedPosition, 1.0)).xyz;\n}\n@end\n@export clay.sm.distance.fragment\nuniform vec3 lightPosition;\nuniform float range : 100;\nvarying vec3 v_WorldPosition;\n@import clay.util.encode_float\nvoid main(){\n float dist = distance(lightPosition, v_WorldPosition);\n#ifdef USE_VSM\n gl_FragColor = vec4(dist, dist * dist, 0.0, 0.0);\n#else\n dist = dist / range;\n gl_FragColor = encodeFloat(dist);\n#endif\n}\n@end\n@export clay.plugin.shadow_map_common\n@import clay.util.decode_float\nfloat tapShadowMap(sampler2D map, vec2 uv, float z){\n vec4 tex = texture2D(map, uv);\n return step(z, decodeFloat(tex) * 2.0 - 1.0);\n}\nfloat pcf(sampler2D map, vec2 uv, float z, float textureSize, vec2 scale) {\n float shadowContrib = tapShadowMap(map, uv, z);\n vec2 offset = vec2(1.0 / textureSize) * scale;\n#ifdef PCF_KERNEL_SIZE\n for (int _idx_ = 0; _idx_ < PCF_KERNEL_SIZE; _idx_++) {{\n shadowContrib += tapShadowMap(map, uv + offset * pcfKernel[_idx_], z);\n }}\n return shadowContrib / float(PCF_KERNEL_SIZE + 1);\n#else\n shadowContrib += tapShadowMap(map, uv+vec2(offset.x, 0.0), z);\n shadowContrib += tapShadowMap(map, uv+vec2(offset.x, offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(-offset.x, offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(0.0, offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(-offset.x, 0.0), z);\n shadowContrib += tapShadowMap(map, uv+vec2(-offset.x, -offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(offset.x, -offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(0.0, -offset.y), z);\n return shadowContrib / 9.0;\n#endif\n}\nfloat pcf(sampler2D map, vec2 uv, float z, float textureSize) {\n return pcf(map, uv, z, textureSize, vec2(1.0));\n}\nfloat chebyshevUpperBound(vec2 moments, float z){\n float p = 0.0;\n z = z * 0.5 + 0.5;\n if (z <= moments.x) {\n p = 1.0;\n }\n float variance = moments.y - moments.x * moments.x;\n variance = max(variance, 0.0000001);\n float mD = moments.x - z;\n float pMax = variance / (variance + mD * mD);\n pMax = clamp((pMax-0.4)/(1.0-0.4), 0.0, 1.0);\n return max(p, pMax);\n}\nfloat computeShadowContrib(\n sampler2D map, mat4 lightVPM, vec3 position, float textureSize, vec2 scale, vec2 offset\n) {\n vec4 posInLightSpace = lightVPM * vec4(position, 1.0);\n posInLightSpace.xyz /= posInLightSpace.w;\n float z = posInLightSpace.z;\n if(all(greaterThan(posInLightSpace.xyz, vec3(-0.99, -0.99, -1.0))) &&\n all(lessThan(posInLightSpace.xyz, vec3(0.99, 0.99, 1.0)))){\n vec2 uv = (posInLightSpace.xy+1.0) / 2.0;\n #ifdef USE_VSM\n vec2 moments = texture2D(map, uv * scale + offset).xy;\n return chebyshevUpperBound(moments, z);\n #else\n return pcf(map, uv * scale + offset, z, textureSize, scale);\n #endif\n }\n return 1.0;\n}\nfloat computeShadowContrib(sampler2D map, mat4 lightVPM, vec3 position, float textureSize) {\n return computeShadowContrib(map, lightVPM, position, textureSize, vec2(1.0), vec2(0.0));\n}\nfloat computeShadowContribOmni(samplerCube map, vec3 direction, float range)\n{\n float dist = length(direction);\n vec4 shadowTex = textureCube(map, direction);\n#ifdef USE_VSM\n vec2 moments = shadowTex.xy;\n float variance = moments.y - moments.x * moments.x;\n float mD = moments.x - dist;\n float p = variance / (variance + mD * mD);\n if(moments.x + 0.001 < dist){\n return clamp(p, 0.0, 1.0);\n }else{\n return 1.0;\n }\n#else\n return step(dist, (decodeFloat(shadowTex) + 0.0002) * range);\n#endif\n}\n@end\n@export clay.plugin.compute_shadow_map\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT) || defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT) || defined(POINT_LIGHT_SHADOWMAP_COUNT)\n#ifdef SPOT_LIGHT_SHADOWMAP_COUNT\nuniform sampler2D spotLightShadowMaps[SPOT_LIGHT_SHADOWMAP_COUNT]:unconfigurable;\nuniform mat4 spotLightMatrices[SPOT_LIGHT_SHADOWMAP_COUNT]:unconfigurable;\nuniform float spotLightShadowMapSizes[SPOT_LIGHT_SHADOWMAP_COUNT]:unconfigurable;\n#endif\n#ifdef DIRECTIONAL_LIGHT_SHADOWMAP_COUNT\n#if defined(SHADOW_CASCADE)\nuniform sampler2D directionalLightShadowMaps[1]:unconfigurable;\nuniform mat4 directionalLightMatrices[SHADOW_CASCADE]:unconfigurable;\nuniform float directionalLightShadowMapSizes[1]:unconfigurable;\nuniform float shadowCascadeClipsNear[SHADOW_CASCADE]:unconfigurable;\nuniform float shadowCascadeClipsFar[SHADOW_CASCADE]:unconfigurable;\n#else\nuniform sampler2D directionalLightShadowMaps[DIRECTIONAL_LIGHT_SHADOWMAP_COUNT]:unconfigurable;\nuniform mat4 directionalLightMatrices[DIRECTIONAL_LIGHT_SHADOWMAP_COUNT]:unconfigurable;\nuniform float directionalLightShadowMapSizes[DIRECTIONAL_LIGHT_SHADOWMAP_COUNT]:unconfigurable;\n#endif\n#endif\n#ifdef POINT_LIGHT_SHADOWMAP_COUNT\nuniform samplerCube pointLightShadowMaps[POINT_LIGHT_SHADOWMAP_COUNT]:unconfigurable;\n#endif\nuniform bool shadowEnabled : true;\n#ifdef PCF_KERNEL_SIZE\nuniform vec2 pcfKernel[PCF_KERNEL_SIZE];\n#endif\n@import clay.plugin.shadow_map_common\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT)\nvoid computeShadowOfSpotLights(vec3 position, inout float shadowContribs[SPOT_LIGHT_COUNT] ) {\n float shadowContrib;\n for(int _idx_ = 0; _idx_ < SPOT_LIGHT_SHADOWMAP_COUNT; _idx_++) {{\n shadowContrib = computeShadowContrib(\n spotLightShadowMaps[_idx_], spotLightMatrices[_idx_], position,\n spotLightShadowMapSizes[_idx_]\n );\n shadowContribs[_idx_] = shadowContrib;\n }}\n for(int _idx_ = SPOT_LIGHT_SHADOWMAP_COUNT; _idx_ < SPOT_LIGHT_COUNT; _idx_++){{\n shadowContribs[_idx_] = 1.0;\n }}\n}\n#endif\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n#ifdef SHADOW_CASCADE\nvoid computeShadowOfDirectionalLights(vec3 position, inout float shadowContribs[DIRECTIONAL_LIGHT_COUNT]){\n float depth = (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far)\n / (gl_DepthRange.far - gl_DepthRange.near);\n float shadowContrib;\n shadowContribs[0] = 1.0;\n for (int _idx_ = 0; _idx_ < SHADOW_CASCADE; _idx_++) {{\n if (\n depth >= shadowCascadeClipsNear[_idx_] &&\n depth <= shadowCascadeClipsFar[_idx_]\n ) {\n shadowContrib = computeShadowContrib(\n directionalLightShadowMaps[0], directionalLightMatrices[_idx_], position,\n directionalLightShadowMapSizes[0],\n vec2(1.0 / float(SHADOW_CASCADE), 1.0),\n vec2(float(_idx_) / float(SHADOW_CASCADE), 0.0)\n );\n shadowContribs[0] = shadowContrib;\n }\n }}\n for(int _idx_ = DIRECTIONAL_LIGHT_SHADOWMAP_COUNT; _idx_ < DIRECTIONAL_LIGHT_COUNT; _idx_++) {{\n shadowContribs[_idx_] = 1.0;\n }}\n}\n#else\nvoid computeShadowOfDirectionalLights(vec3 position, inout float shadowContribs[DIRECTIONAL_LIGHT_COUNT]){\n float shadowContrib;\n for(int _idx_ = 0; _idx_ < DIRECTIONAL_LIGHT_SHADOWMAP_COUNT; _idx_++) {{\n shadowContrib = computeShadowContrib(\n directionalLightShadowMaps[_idx_], directionalLightMatrices[_idx_], position,\n directionalLightShadowMapSizes[_idx_]\n );\n shadowContribs[_idx_] = shadowContrib;\n }}\n for(int _idx_ = DIRECTIONAL_LIGHT_SHADOWMAP_COUNT; _idx_ < DIRECTIONAL_LIGHT_COUNT; _idx_++) {{\n shadowContribs[_idx_] = 1.0;\n }}\n}\n#endif\n#endif\n#if defined(POINT_LIGHT_SHADOWMAP_COUNT)\nvoid computeShadowOfPointLights(vec3 position, inout float shadowContribs[POINT_LIGHT_COUNT] ){\n vec3 lightPosition;\n vec3 direction;\n for(int _idx_ = 0; _idx_ < POINT_LIGHT_SHADOWMAP_COUNT; _idx_++) {{\n lightPosition = pointLightPosition[_idx_];\n direction = position - lightPosition;\n shadowContribs[_idx_] = computeShadowContribOmni(pointLightShadowMaps[_idx_], direction, pointLightRange[_idx_]);\n }}\n for(int _idx_ = POINT_LIGHT_SHADOWMAP_COUNT; _idx_ < POINT_LIGHT_COUNT; _idx_++) {{\n shadowContribs[_idx_] = 1.0;\n }}\n}\n#endif\n#endif\n@end");
  35256. /***/
  35257. }),
  35258. /* 176 */
  35259. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  35260. "use strict";
  35261. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_claygl_src_Shader__ = __webpack_require__(8);
  35262. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_Texture2D__ = __webpack_require__(5);
  35263. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_claygl_src_Texture__ = __webpack_require__(4);
  35264. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_claygl_src_FrameBuffer__ = __webpack_require__(10);
  35265. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_claygl_src_compositor_createCompositor__ = __webpack_require__(177);
  35266. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__SSAOPass__ = __webpack_require__(189);
  35267. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__SSRPass__ = __webpack_require__(191);
  35268. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__poissonKernel__ = __webpack_require__(193);
  35269. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__util_graphicGL__ = __webpack_require__(1);
  35270. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_9__NormalPass__ = __webpack_require__(194);
  35271. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_10__EdgePass__ = __webpack_require__(196);
  35272. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_11_claygl_src_math_Matrix4__ = __webpack_require__(9);
  35273. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_12__composite_js__ = __webpack_require__(197);
  35274. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_13_claygl_src_shader_source_compositor_blur_glsl_js__ = __webpack_require__(87);
  35275. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_14_claygl_src_shader_source_compositor_lut_glsl_js__ = __webpack_require__(88);
  35276. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_15_claygl_src_shader_source_compositor_output_glsl_js__ = __webpack_require__(89);
  35277. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_16_claygl_src_shader_source_compositor_bright_glsl_js__ = __webpack_require__(90);
  35278. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_17_claygl_src_shader_source_compositor_downsample_glsl_js__ = __webpack_require__(91);
  35279. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_18_claygl_src_shader_source_compositor_upsample_glsl_js__ = __webpack_require__(92);
  35280. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_19_claygl_src_shader_source_compositor_hdr_glsl_js__ = __webpack_require__(93);
  35281. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_20_claygl_src_shader_source_compositor_blend_glsl_js__ = __webpack_require__(94);
  35282. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_21_claygl_src_shader_source_compositor_fxaa_glsl_js__ = __webpack_require__(95);
  35283. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_22__DOF_glsl_js__ = __webpack_require__(198);
  35284. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_23__edge_glsl_js__ = __webpack_require__(199);
  35285. __WEBPACK_IMPORTED_MODULE_0_claygl_src_Shader__["a" /* default */]['import'](__WEBPACK_IMPORTED_MODULE_13_claygl_src_shader_source_compositor_blur_glsl_js__["a" /* default */]);
  35286. __WEBPACK_IMPORTED_MODULE_0_claygl_src_Shader__["a" /* default */]['import'](__WEBPACK_IMPORTED_MODULE_14_claygl_src_shader_source_compositor_lut_glsl_js__["a" /* default */]);
  35287. __WEBPACK_IMPORTED_MODULE_0_claygl_src_Shader__["a" /* default */]['import'](__WEBPACK_IMPORTED_MODULE_15_claygl_src_shader_source_compositor_output_glsl_js__["a" /* default */]);
  35288. __WEBPACK_IMPORTED_MODULE_0_claygl_src_Shader__["a" /* default */]['import'](__WEBPACK_IMPORTED_MODULE_16_claygl_src_shader_source_compositor_bright_glsl_js__["a" /* default */]);
  35289. __WEBPACK_IMPORTED_MODULE_0_claygl_src_Shader__["a" /* default */]['import'](__WEBPACK_IMPORTED_MODULE_17_claygl_src_shader_source_compositor_downsample_glsl_js__["a" /* default */]);
  35290. __WEBPACK_IMPORTED_MODULE_0_claygl_src_Shader__["a" /* default */]['import'](__WEBPACK_IMPORTED_MODULE_18_claygl_src_shader_source_compositor_upsample_glsl_js__["a" /* default */]);
  35291. __WEBPACK_IMPORTED_MODULE_0_claygl_src_Shader__["a" /* default */]['import'](__WEBPACK_IMPORTED_MODULE_19_claygl_src_shader_source_compositor_hdr_glsl_js__["a" /* default */]);
  35292. __WEBPACK_IMPORTED_MODULE_0_claygl_src_Shader__["a" /* default */]['import'](__WEBPACK_IMPORTED_MODULE_20_claygl_src_shader_source_compositor_blend_glsl_js__["a" /* default */]);
  35293. __WEBPACK_IMPORTED_MODULE_0_claygl_src_Shader__["a" /* default */]['import'](__WEBPACK_IMPORTED_MODULE_21_claygl_src_shader_source_compositor_fxaa_glsl_js__["a" /* default */]);
  35294. __WEBPACK_IMPORTED_MODULE_0_claygl_src_Shader__["a" /* default */]['import'](__WEBPACK_IMPORTED_MODULE_22__DOF_glsl_js__["a" /* default */]);
  35295. __WEBPACK_IMPORTED_MODULE_0_claygl_src_Shader__["a" /* default */]['import'](__WEBPACK_IMPORTED_MODULE_23__edge_glsl_js__["a" /* default */]);
  35296. var commonOutputs = {
  35297. color: {
  35298. parameters: {
  35299. width: function (renderer) {
  35300. return renderer.getWidth();
  35301. },
  35302. height: function (renderer) {
  35303. return renderer.getHeight();
  35304. }
  35305. }
  35306. }
  35307. }
  35308. var FINAL_NODES_CHAIN = ['composite', 'FXAA'];
  35309. function EffectCompositor() {
  35310. this._sourceTexture = new __WEBPACK_IMPORTED_MODULE_1_claygl_src_Texture2D__["a" /* default */]({
  35311. type: __WEBPACK_IMPORTED_MODULE_2_claygl_src_Texture__["a" /* default */].HALF_FLOAT
  35312. });
  35313. this._depthTexture = new __WEBPACK_IMPORTED_MODULE_1_claygl_src_Texture2D__["a" /* default */]({
  35314. format: __WEBPACK_IMPORTED_MODULE_2_claygl_src_Texture__["a" /* default */].DEPTH_COMPONENT,
  35315. type: __WEBPACK_IMPORTED_MODULE_2_claygl_src_Texture__["a" /* default */].UNSIGNED_INT
  35316. });
  35317. this._framebuffer = new __WEBPACK_IMPORTED_MODULE_3_claygl_src_FrameBuffer__["a" /* default */]();
  35318. this._framebuffer.attach(this._sourceTexture);
  35319. this._framebuffer.attach(this._depthTexture, __WEBPACK_IMPORTED_MODULE_3_claygl_src_FrameBuffer__["a" /* default */].DEPTH_ATTACHMENT);
  35320. this._normalPass = new __WEBPACK_IMPORTED_MODULE_9__NormalPass__["a" /* default */]();
  35321. this._compositor = Object(__WEBPACK_IMPORTED_MODULE_4_claygl_src_compositor_createCompositor__["a" /* default */])(__WEBPACK_IMPORTED_MODULE_12__composite_js__["a" /* default */]);
  35322. var sourceNode = this._compositor.getNodeByName('source');
  35323. sourceNode.texture = this._sourceTexture;
  35324. var cocNode = this._compositor.getNodeByName('coc');
  35325. this._sourceNode = sourceNode;
  35326. this._cocNode = cocNode;
  35327. this._compositeNode = this._compositor.getNodeByName('composite');
  35328. this._fxaaNode = this._compositor.getNodeByName('FXAA');
  35329. this._dofBlurNodes = ['dof_far_blur', 'dof_near_blur', 'dof_coc_blur'].map(function (name) {
  35330. return this._compositor.getNodeByName(name);
  35331. }, this);
  35332. this._dofBlurKernel = 0;
  35333. this._dofBlurKernelSize = new Float32Array(0);
  35334. this._finalNodesChain = FINAL_NODES_CHAIN.map(function (name) {
  35335. return this._compositor.getNodeByName(name);
  35336. }, this);
  35337. var gBufferObj = {
  35338. normalTexture: this._normalPass.getNormalTexture(),
  35339. depthTexture: this._normalPass.getDepthTexture()
  35340. };
  35341. this._ssaoPass = new __WEBPACK_IMPORTED_MODULE_5__SSAOPass__["a" /* default */](gBufferObj);
  35342. this._ssrPass = new __WEBPACK_IMPORTED_MODULE_6__SSRPass__["a" /* default */](gBufferObj);
  35343. this._edgePass = new __WEBPACK_IMPORTED_MODULE_10__EdgePass__["a" /* default */](gBufferObj);
  35344. }
  35345. EffectCompositor.prototype.resize = function (width, height, dpr) {
  35346. dpr = dpr || 1;
  35347. var width = width * dpr;
  35348. var height = height * dpr;
  35349. var sourceTexture = this._sourceTexture;
  35350. var depthTexture = this._depthTexture;
  35351. sourceTexture.width = width;
  35352. sourceTexture.height = height;
  35353. depthTexture.width = width;
  35354. depthTexture.height = height;
  35355. };
  35356. EffectCompositor.prototype._ifRenderNormalPass = function () {
  35357. return this._enableSSAO || this._enableEdge || this._enableSSR;
  35358. };
  35359. EffectCompositor.prototype._getPrevNode = function (node) {
  35360. var idx = FINAL_NODES_CHAIN.indexOf(node.name) - 1;
  35361. var prevNode = this._finalNodesChain[idx];
  35362. while (prevNode && !this._compositor.getNodeByName(prevNode.name)) {
  35363. idx -= 1;
  35364. prevNode = this._finalNodesChain[idx];
  35365. }
  35366. return prevNode;
  35367. };
  35368. EffectCompositor.prototype._getNextNode = function (node) {
  35369. var idx = FINAL_NODES_CHAIN.indexOf(node.name) + 1;
  35370. var nextNode = this._finalNodesChain[idx];
  35371. while (nextNode && !this._compositor.getNodeByName(nextNode.name)) {
  35372. idx += 1;
  35373. nextNode = this._finalNodesChain[idx];
  35374. }
  35375. return nextNode;
  35376. };
  35377. EffectCompositor.prototype._addChainNode = function (node) {
  35378. var prevNode = this._getPrevNode(node);
  35379. var nextNode = this._getNextNode(node);
  35380. if (!prevNode) {
  35381. return;
  35382. }
  35383. prevNode.outputs = commonOutputs;
  35384. node.inputs.texture = prevNode.name;
  35385. if (nextNode) {
  35386. node.outputs = commonOutputs;
  35387. nextNode.inputs.texture = node.name;
  35388. }
  35389. else {
  35390. node.outputs = null;
  35391. }
  35392. this._compositor.addNode(node);
  35393. };
  35394. EffectCompositor.prototype._removeChainNode = function (node) {
  35395. var prevNode = this._getPrevNode(node);
  35396. var nextNode = this._getNextNode(node);
  35397. if (!prevNode) {
  35398. return;
  35399. }
  35400. if (nextNode) {
  35401. prevNode.outputs = commonOutputs;
  35402. nextNode.inputs.texture = prevNode.name;
  35403. }
  35404. else {
  35405. prevNode.outputs = null;
  35406. }
  35407. this._compositor.removeNode(node);
  35408. };
  35409. /**
  35410. * Update normal
  35411. */
  35412. EffectCompositor.prototype.updateNormal = function (renderer, scene, camera, frame) {
  35413. if (this._ifRenderNormalPass()) {
  35414. this._normalPass.update(renderer, scene, camera);
  35415. }
  35416. };
  35417. /**
  35418. * Render SSAO after render the scene, before compositing
  35419. */
  35420. EffectCompositor.prototype.updateSSAO = function (renderer, scene, camera, frame) {
  35421. this._ssaoPass.update(renderer, camera, frame);
  35422. };
  35423. /**
  35424. * Enable SSAO effect
  35425. */
  35426. EffectCompositor.prototype.enableSSAO = function () {
  35427. this._enableSSAO = true;
  35428. };
  35429. /**
  35430. * Disable SSAO effect
  35431. */
  35432. EffectCompositor.prototype.disableSSAO = function () {
  35433. this._enableSSAO = false;
  35434. };
  35435. /**
  35436. * Enable SSR effect
  35437. */
  35438. EffectCompositor.prototype.enableSSR = function () {
  35439. this._enableSSR = true;
  35440. // this._normalPass.enableTargetTexture3 = true;
  35441. };
  35442. /**
  35443. * Disable SSR effect
  35444. */
  35445. EffectCompositor.prototype.disableSSR = function () {
  35446. this._enableSSR = false;
  35447. // this._normalPass.enableTargetTexture3 = false;
  35448. };
  35449. /**
  35450. * Render SSAO after render the scene, before compositing
  35451. */
  35452. EffectCompositor.prototype.getSSAOTexture = function () {
  35453. return this._ssaoPass.getTargetTexture();
  35454. };
  35455. /**
  35456. * @return {clay.FrameBuffer}
  35457. */
  35458. EffectCompositor.prototype.getSourceFrameBuffer = function () {
  35459. return this._framebuffer;
  35460. };
  35461. /**
  35462. * @return {clay.Texture2D}
  35463. */
  35464. EffectCompositor.prototype.getSourceTexture = function () {
  35465. return this._sourceTexture;
  35466. };
  35467. /**
  35468. * Disable fxaa effect
  35469. */
  35470. EffectCompositor.prototype.disableFXAA = function () {
  35471. this._removeChainNode(this._fxaaNode);
  35472. };
  35473. /**
  35474. * Enable fxaa effect
  35475. */
  35476. EffectCompositor.prototype.enableFXAA = function () {
  35477. this._addChainNode(this._fxaaNode);
  35478. };
  35479. /**
  35480. * Enable bloom effect
  35481. */
  35482. EffectCompositor.prototype.enableBloom = function () {
  35483. this._compositeNode.inputs.bloom = 'bloom_composite';
  35484. this._compositor.dirty();
  35485. };
  35486. /**
  35487. * Disable bloom effect
  35488. */
  35489. EffectCompositor.prototype.disableBloom = function () {
  35490. this._compositeNode.inputs.bloom = null;
  35491. this._compositor.dirty();
  35492. };
  35493. /**
  35494. * Enable depth of field effect
  35495. */
  35496. EffectCompositor.prototype.enableDOF = function () {
  35497. this._compositeNode.inputs.texture = 'dof_composite';
  35498. this._compositor.dirty();
  35499. };
  35500. /**
  35501. * Disable depth of field effect
  35502. */
  35503. EffectCompositor.prototype.disableDOF = function () {
  35504. this._compositeNode.inputs.texture = 'source';
  35505. this._compositor.dirty();
  35506. };
  35507. /**
  35508. * Enable color correction
  35509. */
  35510. EffectCompositor.prototype.enableColorCorrection = function () {
  35511. this._compositeNode.define('COLOR_CORRECTION');
  35512. this._enableColorCorrection = true;
  35513. };
  35514. /**
  35515. * Disable color correction
  35516. */
  35517. EffectCompositor.prototype.disableColorCorrection = function () {
  35518. this._compositeNode.undefine('COLOR_CORRECTION');
  35519. this._enableColorCorrection = false;
  35520. };
  35521. /**
  35522. * Enable edge detection
  35523. */
  35524. EffectCompositor.prototype.enableEdge = function () {
  35525. this._enableEdge = true;
  35526. };
  35527. /**
  35528. * Disable edge detection
  35529. */
  35530. EffectCompositor.prototype.disableEdge = function () {
  35531. this._enableEdge = false;
  35532. };
  35533. /**
  35534. * Set bloom intensity
  35535. * @param {number} value
  35536. */
  35537. EffectCompositor.prototype.setBloomIntensity = function (value) {
  35538. this._compositeNode.setParameter('bloomIntensity', value);
  35539. };
  35540. EffectCompositor.prototype.setSSAOParameter = function (name, value) {
  35541. switch (name) {
  35542. case 'quality':
  35543. // PENDING
  35544. var kernelSize = ({
  35545. low: 6,
  35546. medium: 12,
  35547. high: 32,
  35548. ultra: 62
  35549. })[value] || 12;
  35550. this._ssaoPass.setParameter('kernelSize', kernelSize);
  35551. break;
  35552. case 'radius':
  35553. this._ssaoPass.setParameter(name, value);
  35554. this._ssaoPass.setParameter('bias', value / 200);
  35555. break;
  35556. case 'intensity':
  35557. this._ssaoPass.setParameter(name, value);
  35558. break;
  35559. default:
  35560. if (true) {
  35561. console.warn('Unkown SSAO parameter ' + name);
  35562. }
  35563. }
  35564. };
  35565. EffectCompositor.prototype.setDOFParameter = function (name, value) {
  35566. switch (name) {
  35567. case 'focalDistance':
  35568. case 'focalRange':
  35569. case 'fstop':
  35570. this._cocNode.setParameter(name, value);
  35571. break;
  35572. case 'blurRadius':
  35573. for (var i = 0; i < this._dofBlurNodes.length; i++) {
  35574. this._dofBlurNodes[i].setParameter('blurRadius', value);
  35575. }
  35576. break;
  35577. case 'quality':
  35578. var kernelSize = ({
  35579. low: 4, medium: 8, high: 16, ultra: 32
  35580. })[value] || 8;
  35581. this._dofBlurKernelSize = kernelSize;
  35582. for (var i = 0; i < this._dofBlurNodes.length; i++) {
  35583. this._dofBlurNodes[i].pass.material.define('POISSON_KERNEL_SIZE', kernelSize);
  35584. }
  35585. this._dofBlurKernel = new Float32Array(kernelSize * 2);
  35586. break;
  35587. default:
  35588. if (true) {
  35589. console.warn('Unkown DOF parameter ' + name);
  35590. }
  35591. }
  35592. };
  35593. EffectCompositor.prototype.setSSRParameter = function (name, value) {
  35594. if (value == null) {
  35595. return;
  35596. }
  35597. switch (name) {
  35598. case 'quality':
  35599. // PENDING
  35600. var maxIteration = ({
  35601. low: 10,
  35602. medium: 15,
  35603. high: 30,
  35604. ultra: 80
  35605. })[value] || 20;
  35606. var pixelStride = ({
  35607. low: 32,
  35608. medium: 16,
  35609. high: 8,
  35610. ultra: 4
  35611. })[value] || 16;
  35612. this._ssrPass.setParameter('maxIteration', maxIteration);
  35613. this._ssrPass.setParameter('pixelStride', pixelStride);
  35614. break;
  35615. case 'maxRoughness':
  35616. this._ssrPass.setParameter('minGlossiness', Math.max(Math.min(1.0 - value, 1.0), 0.0));
  35617. break;
  35618. case 'physical':
  35619. this.setPhysicallyCorrectSSR(value);
  35620. break;
  35621. default:
  35622. console.warn('Unkown SSR parameter ' + name);
  35623. }
  35624. };
  35625. EffectCompositor.prototype.setPhysicallyCorrectSSR = function (physical) {
  35626. this._ssrPass.setPhysicallyCorrect(physical);
  35627. };
  35628. /**
  35629. * Set color of edge
  35630. */
  35631. EffectCompositor.prototype.setEdgeColor = function (value) {
  35632. var color = __WEBPACK_IMPORTED_MODULE_8__util_graphicGL__["a" /* default */].parseColor(value);
  35633. this._edgePass.setParameter('edgeColor', color);
  35634. };
  35635. EffectCompositor.prototype.setExposure = function (value) {
  35636. this._compositeNode.setParameter('exposure', Math.pow(2, value));
  35637. };
  35638. EffectCompositor.prototype.setColorLookupTexture = function (image, api) {
  35639. this._compositeNode.pass.material.setTextureImage('lut', this._enableColorCorrection ? image : 'none', api, {
  35640. minFilter: __WEBPACK_IMPORTED_MODULE_8__util_graphicGL__["a" /* default */].Texture.NEAREST,
  35641. magFilter: __WEBPACK_IMPORTED_MODULE_8__util_graphicGL__["a" /* default */].Texture.NEAREST,
  35642. flipY: false
  35643. });
  35644. };
  35645. EffectCompositor.prototype.setColorCorrection = function (type, value) {
  35646. this._compositeNode.setParameter(type, value);
  35647. };
  35648. EffectCompositor.prototype.isSSREnabled = function () {
  35649. return this._enableSSR;
  35650. };
  35651. EffectCompositor.prototype.composite = function (renderer, scene, camera, framebuffer, frame) {
  35652. var sourceTexture = this._sourceTexture;
  35653. var targetTexture = sourceTexture;
  35654. if (this._enableEdge) {
  35655. this._edgePass.update(renderer, camera, sourceTexture, frame);
  35656. sourceTexture = targetTexture = this._edgePass.getTargetTexture();
  35657. }
  35658. if (this._enableSSR) {
  35659. this._ssrPass.update(renderer, camera, sourceTexture, frame);
  35660. targetTexture = this._ssrPass.getTargetTexture();
  35661. this._ssrPass.setSSAOTexture(
  35662. this._enableSSAO ? this._ssaoPass.getTargetTexture() : null
  35663. );
  35664. // var lights = scene.getLights();
  35665. // for (var i = 0; i < lights.length; i++) {
  35666. // if (lights[i].cubemap) {
  35667. // this._ssrPass.setAmbientCubemap(lights[i].cubemap, lights[i].intensity);
  35668. // }
  35669. // }
  35670. }
  35671. this._sourceNode.texture = targetTexture;
  35672. this._cocNode.setParameter('depth', this._depthTexture);
  35673. var blurKernel = this._dofBlurKernel;
  35674. var blurKernelSize = this._dofBlurKernelSize;
  35675. var frameAll = Math.floor(__WEBPACK_IMPORTED_MODULE_7__poissonKernel__["a" /* default */].length / 2 / blurKernelSize);
  35676. var kernelOffset = frame % frameAll;
  35677. for (var i = 0; i < blurKernelSize * 2; i++) {
  35678. blurKernel[i] = __WEBPACK_IMPORTED_MODULE_7__poissonKernel__["a" /* default */][i + kernelOffset * blurKernelSize * 2];
  35679. }
  35680. for (var i = 0; i < this._dofBlurNodes.length; i++) {
  35681. this._dofBlurNodes[i].setParameter('percent', frame / 30.0);
  35682. this._dofBlurNodes[i].setParameter('poissonKernel', blurKernel);
  35683. }
  35684. this._cocNode.setParameter('zNear', camera.near);
  35685. this._cocNode.setParameter('zFar', camera.far);
  35686. this._compositor.render(renderer, framebuffer);
  35687. };
  35688. EffectCompositor.prototype.dispose = function (renderer) {
  35689. this._sourceTexture.dispose(renderer);
  35690. this._depthTexture.dispose(renderer);
  35691. this._framebuffer.dispose(renderer);
  35692. this._compositor.dispose(renderer);
  35693. this._normalPass.dispose(renderer);
  35694. this._ssaoPass.dispose(renderer);
  35695. };
  35696. /* harmony default export */ __webpack_exports__["a"] = (EffectCompositor);
  35697. /***/
  35698. }),
  35699. /* 177 */
  35700. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  35701. "use strict";
  35702. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__createCompositor__ = __webpack_require__(178);
  35703. // DEPRECATED
  35704. /* harmony default export */ __webpack_exports__["a"] = (__WEBPACK_IMPORTED_MODULE_0__createCompositor__["a" /* default */]);
  35705. /***/
  35706. }),
  35707. /* 178 */
  35708. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  35709. "use strict";
  35710. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__core_util__ = __webpack_require__(23);
  35711. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__compositor_Compositor__ = __webpack_require__(179);
  35712. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__compositor_SceneNode__ = __webpack_require__(181);
  35713. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__compositor_TextureNode__ = __webpack_require__(182);
  35714. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__compositor_FilterNode__ = __webpack_require__(183);
  35715. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__Shader__ = __webpack_require__(8);
  35716. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__Texture__ = __webpack_require__(4);
  35717. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__Texture2D__ = __webpack_require__(5);
  35718. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__TextureCube__ = __webpack_require__(27);
  35719. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_9__shader_registerBuiltinCompositor__ = __webpack_require__(184);
  35720. Object(__WEBPACK_IMPORTED_MODULE_9__shader_registerBuiltinCompositor__["a" /* default */])(__WEBPACK_IMPORTED_MODULE_5__Shader__["a" /* default */]);
  35721. var shaderSourceReg = /^#source\((.*?)\)/;
  35722. /**
  35723. * @name clay.createCompositor
  35724. * @function
  35725. * @param {Object} json
  35726. * @param {Object} [opts]
  35727. * @return {clay.compositor.Compositor}
  35728. */
  35729. function createCompositor(json, opts) {
  35730. var compositor = new __WEBPACK_IMPORTED_MODULE_1__compositor_Compositor__["a" /* default */]();
  35731. opts = opts || {};
  35732. var lib = {
  35733. textures: {},
  35734. parameters: {}
  35735. };
  35736. var afterLoad = function (shaderLib, textureLib) {
  35737. for (var i = 0; i < json.nodes.length; i++) {
  35738. var nodeInfo = json.nodes[i];
  35739. var node = createNode(nodeInfo, lib, opts);
  35740. if (node) {
  35741. compositor.addNode(node);
  35742. }
  35743. }
  35744. };
  35745. for (var name in json.parameters) {
  35746. var paramInfo = json.parameters[name];
  35747. lib.parameters[name] = convertParameter(paramInfo);
  35748. }
  35749. // TODO load texture asynchronous
  35750. loadTextures(json, lib, opts, function (textureLib) {
  35751. lib.textures = textureLib;
  35752. afterLoad();
  35753. });
  35754. return compositor;
  35755. }
  35756. function createNode(nodeInfo, lib, opts) {
  35757. var type = nodeInfo.type || 'filter';
  35758. var shaderSource;
  35759. var inputs;
  35760. var outputs;
  35761. if (type === 'filter') {
  35762. var shaderExp = nodeInfo.shader.trim();
  35763. var res = shaderSourceReg.exec(shaderExp);
  35764. if (res) {
  35765. shaderSource = __WEBPACK_IMPORTED_MODULE_5__Shader__["a" /* default */].source(res[1].trim());
  35766. }
  35767. else if (shaderExp.charAt(0) === '#') {
  35768. shaderSource = lib.shaders[shaderExp.substr(1)];
  35769. }
  35770. if (!shaderSource) {
  35771. shaderSource = shaderExp;
  35772. }
  35773. if (!shaderSource) {
  35774. return;
  35775. }
  35776. }
  35777. if (nodeInfo.inputs) {
  35778. inputs = {};
  35779. for (var name in nodeInfo.inputs) {
  35780. if (typeof nodeInfo.inputs[name] === 'string') {
  35781. inputs[name] = nodeInfo.inputs[name];
  35782. }
  35783. else {
  35784. inputs[name] = {
  35785. node: nodeInfo.inputs[name].node,
  35786. pin: nodeInfo.inputs[name].pin
  35787. };
  35788. }
  35789. }
  35790. }
  35791. if (nodeInfo.outputs) {
  35792. outputs = {};
  35793. for (var name in nodeInfo.outputs) {
  35794. var outputInfo = nodeInfo.outputs[name];
  35795. outputs[name] = {};
  35796. if (outputInfo.attachment != null) {
  35797. outputs[name].attachment = outputInfo.attachment;
  35798. }
  35799. if (outputInfo.keepLastFrame != null) {
  35800. outputs[name].keepLastFrame = outputInfo.keepLastFrame;
  35801. }
  35802. if (outputInfo.outputLastFrame != null) {
  35803. outputs[name].outputLastFrame = outputInfo.outputLastFrame;
  35804. }
  35805. if (outputInfo.parameters) {
  35806. outputs[name].parameters = convertParameter(outputInfo.parameters);
  35807. }
  35808. }
  35809. }
  35810. var node;
  35811. if (type === 'scene') {
  35812. node = new __WEBPACK_IMPORTED_MODULE_2__compositor_SceneNode__["a" /* default */]({
  35813. name: nodeInfo.name,
  35814. scene: opts.scene,
  35815. camera: opts.camera,
  35816. outputs: outputs
  35817. });
  35818. }
  35819. else if (type === 'texture') {
  35820. node = new __WEBPACK_IMPORTED_MODULE_3__compositor_TextureNode__["a" /* default */]({
  35821. name: nodeInfo.name,
  35822. outputs: outputs
  35823. });
  35824. }
  35825. // Default is filter
  35826. else {
  35827. node = new __WEBPACK_IMPORTED_MODULE_4__compositor_FilterNode__["a" /* default */]({
  35828. name: nodeInfo.name,
  35829. shader: shaderSource,
  35830. inputs: inputs,
  35831. outputs: outputs
  35832. });
  35833. }
  35834. if (node) {
  35835. if (nodeInfo.parameters) {
  35836. for (var name in nodeInfo.parameters) {
  35837. var val = nodeInfo.parameters[name];
  35838. if (typeof (val) === 'string') {
  35839. val = val.trim();
  35840. if (val.charAt(0) === '#') {
  35841. val = lib.textures[val.substr(1)];
  35842. }
  35843. else {
  35844. node.on(
  35845. 'beforerender', createSizeSetHandler(
  35846. name, tryConvertExpr(val)
  35847. )
  35848. );
  35849. }
  35850. }
  35851. node.setParameter(name, val);
  35852. }
  35853. }
  35854. if (nodeInfo.defines && node.pass) {
  35855. for (var name in nodeInfo.defines) {
  35856. var val = nodeInfo.defines[name];
  35857. node.pass.material.define('fragment', name, val);
  35858. }
  35859. }
  35860. }
  35861. return node;
  35862. }
  35863. function defaultWidthFunc(width, height) {
  35864. return width;
  35865. }
  35866. function defaultHeightFunc(width, height) {
  35867. return height;
  35868. }
  35869. function convertParameter(paramInfo) {
  35870. var param = {};
  35871. if (!paramInfo) {
  35872. return param;
  35873. }
  35874. ['type', 'minFilter', 'magFilter', 'wrapS', 'wrapT', 'flipY', 'useMipmap']
  35875. .forEach(function (name) {
  35876. var val = paramInfo[name];
  35877. if (val != null) {
  35878. // Convert string to enum
  35879. if (typeof val === 'string') {
  35880. val = __WEBPACK_IMPORTED_MODULE_6__Texture__["a" /* default */][val];
  35881. }
  35882. param[name] = val;
  35883. }
  35884. });
  35885. var sizeScale = paramInfo.scale || 1;
  35886. ['width', 'height']
  35887. .forEach(function (name) {
  35888. if (paramInfo[name] != null) {
  35889. var val = paramInfo[name];
  35890. if (typeof val === 'string') {
  35891. val = val.trim();
  35892. param[name] = createSizeParser(
  35893. name, tryConvertExpr(val), sizeScale
  35894. );
  35895. }
  35896. else {
  35897. param[name] = val;
  35898. }
  35899. }
  35900. });
  35901. if (!param.width) {
  35902. param.width = defaultWidthFunc;
  35903. }
  35904. if (!param.height) {
  35905. param.height = defaultHeightFunc;
  35906. }
  35907. if (paramInfo.useMipmap != null) {
  35908. param.useMipmap = paramInfo.useMipmap;
  35909. }
  35910. return param;
  35911. }
  35912. function loadTextures(json, lib, opts, callback) {
  35913. if (!json.textures) {
  35914. callback({});
  35915. return;
  35916. }
  35917. var textures = {};
  35918. var loading = 0;
  35919. var cbd = false;
  35920. var textureRootPath = opts.textureRootPath;
  35921. __WEBPACK_IMPORTED_MODULE_0__core_util__["a" /* default */].each(json.textures, function (textureInfo, name) {
  35922. var texture;
  35923. var path = textureInfo.path;
  35924. var parameters = convertParameter(textureInfo.parameters);
  35925. if (Array.isArray(path) && path.length === 6) {
  35926. if (textureRootPath) {
  35927. path = path.map(function (item) {
  35928. return __WEBPACK_IMPORTED_MODULE_0__core_util__["a" /* default */].relative2absolute(item, textureRootPath);
  35929. });
  35930. }
  35931. texture = new __WEBPACK_IMPORTED_MODULE_8__TextureCube__["a" /* default */](parameters);
  35932. }
  35933. else if (typeof path === 'string') {
  35934. if (textureRootPath) {
  35935. path = __WEBPACK_IMPORTED_MODULE_0__core_util__["a" /* default */].relative2absolute(path, textureRootPath);
  35936. }
  35937. texture = new __WEBPACK_IMPORTED_MODULE_7__Texture2D__["a" /* default */](parameters);
  35938. }
  35939. else {
  35940. return;
  35941. }
  35942. texture.load(path);
  35943. loading++;
  35944. texture.once('success', function () {
  35945. textures[name] = texture;
  35946. loading--;
  35947. if (loading === 0) {
  35948. callback(textures);
  35949. cbd = true;
  35950. }
  35951. });
  35952. });
  35953. if (loading === 0 && !cbd) {
  35954. callback(textures);
  35955. }
  35956. }
  35957. function createSizeSetHandler(name, exprFunc) {
  35958. return function (renderer) {
  35959. // PENDING viewport size or window size
  35960. var dpr = renderer.getDevicePixelRatio();
  35961. // PENDING If multiply dpr ?
  35962. var width = renderer.getWidth();
  35963. var height = renderer.getHeight();
  35964. var result = exprFunc(width, height, dpr);
  35965. this.setParameter(name, result);
  35966. };
  35967. }
  35968. function createSizeParser(name, exprFunc, scale) {
  35969. scale = scale || 1;
  35970. return function (renderer) {
  35971. var dpr = renderer.getDevicePixelRatio();
  35972. var width = renderer.getWidth() * scale;
  35973. var height = renderer.getHeight() * scale;
  35974. return exprFunc(width, height, dpr);
  35975. };
  35976. }
  35977. function tryConvertExpr(string) {
  35978. // PENDING
  35979. var exprRes = /^expr\((.*)\)$/.exec(string);
  35980. if (exprRes) {
  35981. try {
  35982. var func = new Function('width', 'height', 'dpr', 'return ' + exprRes[1]);
  35983. // Try run t
  35984. func(1, 1);
  35985. return func;
  35986. }
  35987. catch (e) {
  35988. throw new Error('Invalid expression.');
  35989. }
  35990. }
  35991. }
  35992. /* harmony default export */ __webpack_exports__["a"] = (createCompositor);
  35993. /***/
  35994. }),
  35995. /* 179 */
  35996. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  35997. "use strict";
  35998. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Graph__ = __webpack_require__(180);
  35999. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__TexturePool__ = __webpack_require__(86);
  36000. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__FrameBuffer__ = __webpack_require__(10);
  36001. /**
  36002. * Compositor provide graph based post processing
  36003. *
  36004. * @constructor clay.compositor.Compositor
  36005. * @extends clay.compositor.Graph
  36006. *
  36007. */
  36008. var Compositor = __WEBPACK_IMPORTED_MODULE_0__Graph__["a" /* default */].extend(function () {
  36009. return {
  36010. // Output node
  36011. _outputs: [],
  36012. _texturePool: new __WEBPACK_IMPORTED_MODULE_1__TexturePool__["a" /* default */](),
  36013. _frameBuffer: new __WEBPACK_IMPORTED_MODULE_2__FrameBuffer__["a" /* default */]({
  36014. depthBuffer: false
  36015. })
  36016. };
  36017. },
  36018. /** @lends clay.compositor.Compositor.prototype */
  36019. {
  36020. addNode: function (node) {
  36021. __WEBPACK_IMPORTED_MODULE_0__Graph__["a" /* default */].prototype.addNode.call(this, node);
  36022. node._compositor = this;
  36023. },
  36024. /**
  36025. * @param {clay.Renderer} renderer
  36026. */
  36027. render: function (renderer, frameBuffer) {
  36028. if (this._dirty) {
  36029. this.update();
  36030. this._dirty = false;
  36031. this._outputs.length = 0;
  36032. for (var i = 0; i < this.nodes.length; i++) {
  36033. if (!this.nodes[i].outputs) {
  36034. this._outputs.push(this.nodes[i]);
  36035. }
  36036. }
  36037. }
  36038. for (var i = 0; i < this.nodes.length; i++) {
  36039. // Update the reference number of each output texture
  36040. this.nodes[i].beforeFrame();
  36041. }
  36042. for (var i = 0; i < this._outputs.length; i++) {
  36043. this._outputs[i].updateReference();
  36044. }
  36045. for (var i = 0; i < this._outputs.length; i++) {
  36046. this._outputs[i].render(renderer, frameBuffer);
  36047. }
  36048. for (var i = 0; i < this.nodes.length; i++) {
  36049. // Clear up
  36050. this.nodes[i].afterFrame();
  36051. }
  36052. },
  36053. allocateTexture: function (parameters) {
  36054. return this._texturePool.get(parameters);
  36055. },
  36056. releaseTexture: function (parameters) {
  36057. this._texturePool.put(parameters);
  36058. },
  36059. getFrameBuffer: function () {
  36060. return this._frameBuffer;
  36061. },
  36062. /**
  36063. * Dispose compositor
  36064. * @param {clay.Renderer} renderer
  36065. */
  36066. dispose: function (renderer) {
  36067. this._texturePool.clear(renderer);
  36068. }
  36069. });
  36070. /* harmony default export */ __webpack_exports__["a"] = (Compositor);
  36071. /***/
  36072. }),
  36073. /* 180 */
  36074. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  36075. "use strict";
  36076. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__core_Base__ = __webpack_require__(7);
  36077. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__CompositorNode__ = __webpack_require__(48);
  36078. /**
  36079. * @constructor clay.compositor.Graph
  36080. * @extends clay.core.Base
  36081. */
  36082. var Graph = __WEBPACK_IMPORTED_MODULE_0__core_Base__["a" /* default */].extend(function () {
  36083. return /** @lends clay.compositor.Graph# */ {
  36084. /**
  36085. * @type {Array.<clay.compositor.CompositorNode>}
  36086. */
  36087. nodes: []
  36088. };
  36089. },
  36090. /** @lends clay.compositor.Graph.prototype */
  36091. {
  36092. /**
  36093. * Mark to update
  36094. */
  36095. dirty: function () {
  36096. this._dirty = true;
  36097. },
  36098. /**
  36099. * @param {clay.compositor.CompositorNode} node
  36100. */
  36101. addNode: function (node) {
  36102. if (this.nodes.indexOf(node) >= 0) {
  36103. return;
  36104. }
  36105. this.nodes.push(node);
  36106. this._dirty = true;
  36107. },
  36108. /**
  36109. * @param {clay.compositor.CompositorNode|string} node
  36110. */
  36111. removeNode: function (node) {
  36112. if (typeof node === 'string') {
  36113. node = this.getNodeByName(node);
  36114. }
  36115. var idx = this.nodes.indexOf(node);
  36116. if (idx >= 0) {
  36117. this.nodes.splice(idx, 1);
  36118. this._dirty = true;
  36119. }
  36120. },
  36121. /**
  36122. * @param {string} name
  36123. * @return {clay.compositor.CompositorNode}
  36124. */
  36125. getNodeByName: function (name) {
  36126. for (var i = 0; i < this.nodes.length; i++) {
  36127. if (this.nodes[i].name === name) {
  36128. return this.nodes[i];
  36129. }
  36130. }
  36131. },
  36132. /**
  36133. * Update links of graph
  36134. */
  36135. update: function () {
  36136. for (var i = 0; i < this.nodes.length; i++) {
  36137. this.nodes[i].clear();
  36138. }
  36139. // Traverse all the nodes and build the graph
  36140. for (var i = 0; i < this.nodes.length; i++) {
  36141. var node = this.nodes[i];
  36142. if (!node.inputs) {
  36143. continue;
  36144. }
  36145. for (var inputName in node.inputs) {
  36146. if (!node.inputs[inputName]) {
  36147. continue;
  36148. }
  36149. if (node.pass && !node.pass.material.isUniformEnabled(inputName)) {
  36150. console.warn('Pin ' + node.name + '.' + inputName + ' not used.');
  36151. continue;
  36152. }
  36153. var fromPinInfo = node.inputs[inputName];
  36154. var fromPin = this.findPin(fromPinInfo);
  36155. if (fromPin) {
  36156. node.link(inputName, fromPin.node, fromPin.pin);
  36157. }
  36158. else {
  36159. if (typeof fromPinInfo === 'string') {
  36160. console.warn('Node ' + fromPinInfo + ' not exist');
  36161. }
  36162. else {
  36163. console.warn('Pin of ' + fromPinInfo.node + '.' + fromPinInfo.pin + ' not exist');
  36164. }
  36165. }
  36166. }
  36167. }
  36168. },
  36169. findPin: function (input) {
  36170. var node;
  36171. // Try to take input as a directly a node
  36172. if (typeof input === 'string' || input instanceof __WEBPACK_IMPORTED_MODULE_1__CompositorNode__["a" /* default */]) {
  36173. input = {
  36174. node: input
  36175. };
  36176. }
  36177. if (typeof input.node === 'string') {
  36178. for (var i = 0; i < this.nodes.length; i++) {
  36179. var tmp = this.nodes[i];
  36180. if (tmp.name === input.node) {
  36181. node = tmp;
  36182. }
  36183. }
  36184. }
  36185. else {
  36186. node = input.node;
  36187. }
  36188. if (node) {
  36189. var inputPin = input.pin;
  36190. if (!inputPin) {
  36191. // Use first pin defaultly
  36192. if (node.outputs) {
  36193. inputPin = Object.keys(node.outputs)[0];
  36194. }
  36195. }
  36196. if (node.outputs[inputPin]) {
  36197. return {
  36198. node: node,
  36199. pin: inputPin
  36200. };
  36201. }
  36202. }
  36203. }
  36204. });
  36205. /* harmony default export */ __webpack_exports__["a"] = (Graph);
  36206. /***/
  36207. }),
  36208. /* 181 */
  36209. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  36210. "use strict";
  36211. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__CompositorNode__ = __webpack_require__(48);
  36212. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__core_glenum__ = __webpack_require__(11);
  36213. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__FrameBuffer__ = __webpack_require__(10);
  36214. /**
  36215. * @constructor clay.compositor.SceneNode
  36216. * @extends clay.compositor.CompositorNode
  36217. */
  36218. var SceneNode = __WEBPACK_IMPORTED_MODULE_0__CompositorNode__["a" /* default */].extend(
  36219. /** @lends clay.compositor.SceneNode# */
  36220. {
  36221. name: 'scene',
  36222. /**
  36223. * @type {clay.Scene}
  36224. */
  36225. scene: null,
  36226. /**
  36227. * @type {clay.Camera}
  36228. */
  36229. camera: null,
  36230. /**
  36231. * @type {boolean}
  36232. */
  36233. autoUpdateScene: true,
  36234. /**
  36235. * @type {boolean}
  36236. */
  36237. preZ: false
  36238. }, function () {
  36239. this.frameBuffer = new __WEBPACK_IMPORTED_MODULE_2__FrameBuffer__["a" /* default */]();
  36240. }, {
  36241. render: function (renderer) {
  36242. this._rendering = true;
  36243. var _gl = renderer.gl;
  36244. this.trigger('beforerender');
  36245. var renderInfo;
  36246. if (!this.outputs) {
  36247. renderInfo = renderer.render(this.scene, this.camera, !this.autoUpdateScene, this.preZ);
  36248. }
  36249. else {
  36250. var frameBuffer = this.frameBuffer;
  36251. for (var name in this.outputs) {
  36252. var parameters = this.updateParameter(name, renderer);
  36253. var outputInfo = this.outputs[name];
  36254. var texture = this._compositor.allocateTexture(parameters);
  36255. this._outputTextures[name] = texture;
  36256. var attachment = outputInfo.attachment || _gl.COLOR_ATTACHMENT0;
  36257. if (typeof (attachment) == 'string') {
  36258. attachment = _gl[attachment];
  36259. }
  36260. frameBuffer.attach(texture, attachment);
  36261. }
  36262. frameBuffer.bind(renderer);
  36263. // MRT Support in chrome
  36264. // https://www.khronos.org/registry/webgl/sdk/tests/conformance/extensions/ext-draw-buffers.html
  36265. var ext = renderer.getGLExtension('EXT_draw_buffers');
  36266. if (ext) {
  36267. var bufs = [];
  36268. for (var attachment in this.outputs) {
  36269. attachment = parseInt(attachment);
  36270. if (attachment >= _gl.COLOR_ATTACHMENT0 && attachment <= _gl.COLOR_ATTACHMENT0 + 8) {
  36271. bufs.push(attachment);
  36272. }
  36273. }
  36274. ext.drawBuffersEXT(bufs);
  36275. }
  36276. // Always clear
  36277. // PENDING
  36278. renderer.saveClear();
  36279. renderer.clearBit = __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].DEPTH_BUFFER_BIT | __WEBPACK_IMPORTED_MODULE_1__core_glenum__["a" /* default */].COLOR_BUFFER_BIT;
  36280. renderInfo = renderer.render(this.scene, this.camera, !this.autoUpdateScene, this.preZ);
  36281. renderer.restoreClear();
  36282. frameBuffer.unbind(renderer);
  36283. }
  36284. this.trigger('afterrender', renderInfo);
  36285. this._rendering = false;
  36286. this._rendered = true;
  36287. }
  36288. });
  36289. /* harmony default export */ __webpack_exports__["a"] = (SceneNode);
  36290. /***/
  36291. }),
  36292. /* 182 */
  36293. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  36294. "use strict";
  36295. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__CompositorNode__ = __webpack_require__(48);
  36296. /**
  36297. * @constructor clay.compositor.TextureNode
  36298. * @extends clay.compositor.CompositorNode
  36299. */
  36300. var TextureNode = __WEBPACK_IMPORTED_MODULE_0__CompositorNode__["a" /* default */].extend(function () {
  36301. return /** @lends clay.compositor.TextureNode# */ {
  36302. /**
  36303. * @type {clay.Texture2D}
  36304. */
  36305. texture: null,
  36306. // Texture node must have output without parameters
  36307. outputs: {
  36308. color: {}
  36309. }
  36310. };
  36311. }, function () {
  36312. }, {
  36313. getOutput: function (renderer, name) {
  36314. return this.texture;
  36315. },
  36316. // Do nothing
  36317. beforeFrame: function () { },
  36318. afterFrame: function () { }
  36319. });
  36320. /* harmony default export */ __webpack_exports__["a"] = (TextureNode);
  36321. /***/
  36322. }),
  36323. /* 183 */
  36324. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  36325. "use strict";
  36326. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Pass__ = __webpack_require__(16);
  36327. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__CompositorNode__ = __webpack_require__(48);
  36328. // TODO Shader library
  36329. // TODO curlnoise demo wrong
  36330. // PENDING
  36331. // Use topological sort ?
  36332. /**
  36333. * Filter node
  36334. *
  36335. * @constructor clay.compositor.FilterNode
  36336. * @extends clay.compositor.CompositorNode
  36337. *
  36338. * @example
  36339. var node = new clay.compositor.FilterNode({
  36340. name: 'fxaa',
  36341. shader: clay.Shader.source('clay.compositor.fxaa'),
  36342. inputs: {
  36343. texture: {
  36344. node: 'scene',
  36345. pin: 'color'
  36346. }
  36347. },
  36348. // Multiple outputs is preserved for MRT support in WebGL2.0
  36349. outputs: {
  36350. color: {
  36351. attachment: clay.FrameBuffer.COLOR_ATTACHMENT0
  36352. parameters: {
  36353. format: clay.Texture.RGBA,
  36354. width: 512,
  36355. height: 512
  36356. },
  36357. // Node will keep the RTT rendered in last frame
  36358. keepLastFrame: true,
  36359. // Force the node output the RTT rendered in last frame
  36360. outputLastFrame: true
  36361. }
  36362. }
  36363. });
  36364. *
  36365. */
  36366. var FilterNode = __WEBPACK_IMPORTED_MODULE_1__CompositorNode__["a" /* default */].extend(function () {
  36367. return /** @lends clay.compositor.FilterNode# */ {
  36368. /**
  36369. * @type {string}
  36370. */
  36371. name: '',
  36372. /**
  36373. * @type {Object}
  36374. */
  36375. inputs: {},
  36376. /**
  36377. * @type {Object}
  36378. */
  36379. outputs: null,
  36380. /**
  36381. * @type {string}
  36382. */
  36383. shader: '',
  36384. /**
  36385. * Input links, will be updated by the graph
  36386. * @example:
  36387. * inputName: {
  36388. * node: someNode,
  36389. * pin: 'xxxx'
  36390. * }
  36391. * @type {Object}
  36392. */
  36393. inputLinks: {},
  36394. /**
  36395. * Output links, will be updated by the graph
  36396. * @example:
  36397. * outputName: {
  36398. * node: someNode,
  36399. * pin: 'xxxx'
  36400. * }
  36401. * @type {Object}
  36402. */
  36403. outputLinks: {},
  36404. /**
  36405. * @type {clay.compositor.Pass}
  36406. */
  36407. pass: null,
  36408. // Save the output texture of previous frame
  36409. // Will be used when there exist a circular reference
  36410. _prevOutputTextures: {},
  36411. _outputTextures: {},
  36412. // Example: { name: 2 }
  36413. _outputReferences: {},
  36414. _rendering: false,
  36415. // If rendered in this frame
  36416. _rendered: false,
  36417. _compositor: null
  36418. };
  36419. }, function () {
  36420. var pass = new __WEBPACK_IMPORTED_MODULE_0__Pass__["a" /* default */]({
  36421. fragment: this.shader
  36422. });
  36423. this.pass = pass;
  36424. },
  36425. /** @lends clay.compositor.FilterNode.prototype */
  36426. {
  36427. /**
  36428. * @param {clay.Renderer} renderer
  36429. */
  36430. render: function (renderer, frameBuffer) {
  36431. this.trigger('beforerender', renderer);
  36432. this._rendering = true;
  36433. var _gl = renderer.gl;
  36434. for (var inputName in this.inputLinks) {
  36435. var link = this.inputLinks[inputName];
  36436. var inputTexture = link.node.getOutput(renderer, link.pin);
  36437. this.pass.setUniform(inputName, inputTexture);
  36438. }
  36439. // Output
  36440. if (!this.outputs) {
  36441. this.pass.outputs = null;
  36442. this._compositor.getFrameBuffer().unbind(renderer);
  36443. this.pass.render(renderer, frameBuffer);
  36444. }
  36445. else {
  36446. this.pass.outputs = {};
  36447. var attachedTextures = {};
  36448. for (var name in this.outputs) {
  36449. var parameters = this.updateParameter(name, renderer);
  36450. if (isNaN(parameters.width)) {
  36451. this.updateParameter(name, renderer);
  36452. }
  36453. var outputInfo = this.outputs[name];
  36454. var texture = this._compositor.allocateTexture(parameters);
  36455. this._outputTextures[name] = texture;
  36456. var attachment = outputInfo.attachment || _gl.COLOR_ATTACHMENT0;
  36457. if (typeof (attachment) === 'string') {
  36458. attachment = _gl[attachment];
  36459. }
  36460. attachedTextures[attachment] = texture;
  36461. }
  36462. this._compositor.getFrameBuffer().bind(renderer);
  36463. for (var attachment in attachedTextures) {
  36464. // FIXME attachment changes in different nodes
  36465. this._compositor.getFrameBuffer().attach(
  36466. attachedTextures[attachment], attachment
  36467. );
  36468. }
  36469. this.pass.render(renderer);
  36470. // Because the data of texture is changed over time,
  36471. // Here update the mipmaps of texture each time after rendered;
  36472. this._compositor.getFrameBuffer().updateMipmap(renderer);
  36473. }
  36474. for (var inputName in this.inputLinks) {
  36475. var link = this.inputLinks[inputName];
  36476. link.node.removeReference(link.pin);
  36477. }
  36478. this._rendering = false;
  36479. this._rendered = true;
  36480. this.trigger('afterrender', renderer);
  36481. },
  36482. // TODO Remove parameter function callback
  36483. updateParameter: function (outputName, renderer) {
  36484. var outputInfo = this.outputs[outputName];
  36485. var parameters = outputInfo.parameters;
  36486. var parametersCopy = outputInfo._parametersCopy;
  36487. if (!parametersCopy) {
  36488. parametersCopy = outputInfo._parametersCopy = {};
  36489. }
  36490. if (parameters) {
  36491. for (var key in parameters) {
  36492. if (key !== 'width' && key !== 'height') {
  36493. parametersCopy[key] = parameters[key];
  36494. }
  36495. }
  36496. }
  36497. var width, height;
  36498. if (parameters.width instanceof Function) {
  36499. width = parameters.width.call(this, renderer);
  36500. }
  36501. else {
  36502. width = parameters.width;
  36503. }
  36504. if (parameters.height instanceof Function) {
  36505. height = parameters.height.call(this, renderer);
  36506. }
  36507. else {
  36508. height = parameters.height;
  36509. }
  36510. width = Math.ceil(width);
  36511. height = Math.ceil(height);
  36512. if (
  36513. parametersCopy.width !== width
  36514. || parametersCopy.height !== height
  36515. ) {
  36516. if (this._outputTextures[outputName]) {
  36517. this._outputTextures[outputName].dispose(renderer);
  36518. }
  36519. }
  36520. parametersCopy.width = width;
  36521. parametersCopy.height = height;
  36522. return parametersCopy;
  36523. },
  36524. /**
  36525. * Set parameter
  36526. * @param {string} name
  36527. * @param {} value
  36528. */
  36529. setParameter: function (name, value) {
  36530. this.pass.setUniform(name, value);
  36531. },
  36532. /**
  36533. * Get parameter value
  36534. * @param {string} name
  36535. * @return {}
  36536. */
  36537. getParameter: function (name) {
  36538. return this.pass.getUniform(name);
  36539. },
  36540. /**
  36541. * Set parameters
  36542. * @param {Object} obj
  36543. */
  36544. setParameters: function (obj) {
  36545. for (var name in obj) {
  36546. this.setParameter(name, obj[name]);
  36547. }
  36548. },
  36549. // /**
  36550. // * Set shader code
  36551. // * @param {string} shaderStr
  36552. // */
  36553. // setShader: function (shaderStr) {
  36554. // var material = this.pass.material;
  36555. // material.shader.setFragment(shaderStr);
  36556. // material.attachShader(material.shader, true);
  36557. // },
  36558. /**
  36559. * Proxy of pass.material.define('fragment', xxx);
  36560. * @param {string} symbol
  36561. * @param {number} [val]
  36562. */
  36563. define: function (symbol, val) {
  36564. this.pass.material.define('fragment', symbol, val);
  36565. },
  36566. /**
  36567. * Proxy of pass.material.undefine('fragment', xxx)
  36568. * @param {string} symbol
  36569. */
  36570. undefine: function (symbol) {
  36571. this.pass.material.undefine('fragment', symbol);
  36572. },
  36573. removeReference: function (outputName) {
  36574. this._outputReferences[outputName]--;
  36575. if (this._outputReferences[outputName] === 0) {
  36576. var outputInfo = this.outputs[outputName];
  36577. if (outputInfo.keepLastFrame) {
  36578. if (this._prevOutputTextures[outputName]) {
  36579. this._compositor.releaseTexture(this._prevOutputTextures[outputName]);
  36580. }
  36581. this._prevOutputTextures[outputName] = this._outputTextures[outputName];
  36582. }
  36583. else {
  36584. // Output of this node have alreay been used by all other nodes
  36585. // Put the texture back to the pool.
  36586. this._compositor.releaseTexture(this._outputTextures[outputName]);
  36587. }
  36588. }
  36589. },
  36590. clear: function () {
  36591. __WEBPACK_IMPORTED_MODULE_1__CompositorNode__["a" /* default */].prototype.clear.call(this);
  36592. // Default disable all texture
  36593. this.pass.material.disableTexturesAll();
  36594. }
  36595. });
  36596. /* harmony default export */ __webpack_exports__["a"] = (FilterNode);
  36597. /***/
  36598. }),
  36599. /* 184 */
  36600. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  36601. "use strict";
  36602. /* harmony export (immutable) */ __webpack_exports__["a"] = register;
  36603. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__source_compositor_coloradjust_glsl_js__ = __webpack_require__(185);
  36604. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__source_compositor_blur_glsl_js__ = __webpack_require__(87);
  36605. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__source_compositor_lum_glsl_js__ = __webpack_require__(186);
  36606. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__source_compositor_lut_glsl_js__ = __webpack_require__(88);
  36607. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__source_compositor_vignette_glsl_js__ = __webpack_require__(187);
  36608. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__source_compositor_output_glsl_js__ = __webpack_require__(89);
  36609. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__source_compositor_bright_glsl_js__ = __webpack_require__(90);
  36610. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__source_compositor_downsample_glsl_js__ = __webpack_require__(91);
  36611. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__source_compositor_upsample_glsl_js__ = __webpack_require__(92);
  36612. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_9__source_compositor_hdr_glsl_js__ = __webpack_require__(93);
  36613. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_10__source_compositor_lensflare_glsl_js__ = __webpack_require__(188);
  36614. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_11__source_compositor_blend_glsl_js__ = __webpack_require__(94);
  36615. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_12__source_compositor_fxaa_glsl_js__ = __webpack_require__(95);
  36616. // import fxaa3Essl from './source/compositor/fxaa3.glsl.js';
  36617. // TODO Must export a module and be used in the other modules. Or it will be tree shaked
  36618. function register(Shader) {
  36619. // Some build in shaders
  36620. Shader['import'](__WEBPACK_IMPORTED_MODULE_0__source_compositor_coloradjust_glsl_js__["a" /* default */]);
  36621. Shader['import'](__WEBPACK_IMPORTED_MODULE_1__source_compositor_blur_glsl_js__["a" /* default */]);
  36622. Shader['import'](__WEBPACK_IMPORTED_MODULE_2__source_compositor_lum_glsl_js__["a" /* default */]);
  36623. Shader['import'](__WEBPACK_IMPORTED_MODULE_3__source_compositor_lut_glsl_js__["a" /* default */]);
  36624. Shader['import'](__WEBPACK_IMPORTED_MODULE_4__source_compositor_vignette_glsl_js__["a" /* default */]);
  36625. Shader['import'](__WEBPACK_IMPORTED_MODULE_5__source_compositor_output_glsl_js__["a" /* default */]);
  36626. Shader['import'](__WEBPACK_IMPORTED_MODULE_6__source_compositor_bright_glsl_js__["a" /* default */]);
  36627. Shader['import'](__WEBPACK_IMPORTED_MODULE_7__source_compositor_downsample_glsl_js__["a" /* default */]);
  36628. Shader['import'](__WEBPACK_IMPORTED_MODULE_8__source_compositor_upsample_glsl_js__["a" /* default */]);
  36629. Shader['import'](__WEBPACK_IMPORTED_MODULE_9__source_compositor_hdr_glsl_js__["a" /* default */]);
  36630. Shader['import'](__WEBPACK_IMPORTED_MODULE_10__source_compositor_lensflare_glsl_js__["a" /* default */]);
  36631. Shader['import'](__WEBPACK_IMPORTED_MODULE_11__source_compositor_blend_glsl_js__["a" /* default */]);
  36632. Shader['import'](__WEBPACK_IMPORTED_MODULE_12__source_compositor_fxaa_glsl_js__["a" /* default */]);
  36633. }
  36634. /***/
  36635. }),
  36636. /* 185 */
  36637. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  36638. "use strict";
  36639. /* harmony default export */ __webpack_exports__["a"] = ("@export clay.compositor.coloradjust\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\nuniform float brightness : 0.0;\nuniform float contrast : 1.0;\nuniform float exposure : 0.0;\nuniform float gamma : 1.0;\nuniform float saturation : 1.0;\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\nvoid main()\n{\n vec4 tex = texture2D( texture, v_Texcoord);\n vec3 color = clamp(tex.rgb + vec3(brightness), 0.0, 1.0);\n color = clamp( (color-vec3(0.5))*contrast+vec3(0.5), 0.0, 1.0);\n color = clamp( color * pow(2.0, exposure), 0.0, 1.0);\n color = clamp( pow(color, vec3(gamma)), 0.0, 1.0);\n float luminance = dot( color, w );\n color = mix(vec3(luminance), color, saturation);\n gl_FragColor = vec4(color, tex.a);\n}\n@end\n@export clay.compositor.brightness\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\nuniform float brightness : 0.0;\nvoid main()\n{\n vec4 tex = texture2D( texture, v_Texcoord);\n vec3 color = tex.rgb + vec3(brightness);\n gl_FragColor = vec4(color, tex.a);\n}\n@end\n@export clay.compositor.contrast\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\nuniform float contrast : 1.0;\nvoid main()\n{\n vec4 tex = texture2D( texture, v_Texcoord);\n vec3 color = (tex.rgb-vec3(0.5))*contrast+vec3(0.5);\n gl_FragColor = vec4(color, tex.a);\n}\n@end\n@export clay.compositor.exposure\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\nuniform float exposure : 0.0;\nvoid main()\n{\n vec4 tex = texture2D(texture, v_Texcoord);\n vec3 color = tex.rgb * pow(2.0, exposure);\n gl_FragColor = vec4(color, tex.a);\n}\n@end\n@export clay.compositor.gamma\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\nuniform float gamma : 1.0;\nvoid main()\n{\n vec4 tex = texture2D(texture, v_Texcoord);\n vec3 color = pow(tex.rgb, vec3(gamma));\n gl_FragColor = vec4(color, tex.a);\n}\n@end\n@export clay.compositor.saturation\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\nuniform float saturation : 1.0;\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\nvoid main()\n{\n vec4 tex = texture2D(texture, v_Texcoord);\n vec3 color = tex.rgb;\n float luminance = dot(color, w);\n color = mix(vec3(luminance), color, saturation);\n gl_FragColor = vec4(color, tex.a);\n}\n@end");
  36640. /***/
  36641. }),
  36642. /* 186 */
  36643. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  36644. "use strict";
  36645. /* harmony default export */ __webpack_exports__["a"] = ("@export clay.compositor.hdr.log_lum\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\n@import clay.util.rgbm\nvoid main()\n{\n vec4 tex = decodeHDR(texture2D(texture, v_Texcoord));\n float luminance = dot(tex.rgb, w);\n luminance = log(luminance + 0.001);\n gl_FragColor = encodeHDR(vec4(vec3(luminance), 1.0));\n}\n@end\n@export clay.compositor.hdr.lum_adaption\nvarying vec2 v_Texcoord;\nuniform sampler2D adaptedLum;\nuniform sampler2D currentLum;\nuniform float frameTime : 0.02;\n@import clay.util.rgbm\nvoid main()\n{\n float fAdaptedLum = decodeHDR(texture2D(adaptedLum, vec2(0.5, 0.5))).r;\n float fCurrentLum = exp(encodeHDR(texture2D(currentLum, vec2(0.5, 0.5))).r);\n fAdaptedLum += (fCurrentLum - fAdaptedLum) * (1.0 - pow(0.98, 30.0 * frameTime));\n gl_FragColor = encodeHDR(vec4(vec3(fAdaptedLum), 1.0));\n}\n@end\n@export clay.compositor.lum\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\nvoid main()\n{\n vec4 tex = texture2D( texture, v_Texcoord );\n float luminance = dot(tex.rgb, w);\n gl_FragColor = vec4(vec3(luminance), 1.0);\n}\n@end");
  36646. /***/
  36647. }),
  36648. /* 187 */
  36649. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  36650. "use strict";
  36651. /* harmony default export */ __webpack_exports__["a"] = ("@export clay.compositor.vignette\n#define OUTPUT_ALPHA\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\nuniform float darkness: 1;\nuniform float offset: 1;\n@import clay.util.rgbm\nvoid main()\n{\n vec4 texel = decodeHDR(texture2D(texture, v_Texcoord));\n gl_FragColor.rgb = texel.rgb;\n vec2 uv = (v_Texcoord - vec2(0.5)) * vec2(offset);\n gl_FragColor = encodeHDR(vec4(mix(texel.rgb, vec3(1.0 - darkness), dot(uv, uv)), texel.a));\n}\n@end");
  36652. /***/
  36653. }),
  36654. /* 188 */
  36655. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  36656. "use strict";
  36657. /* harmony default export */ __webpack_exports__["a"] = ("@export clay.compositor.lensflare\n#define SAMPLE_NUMBER 8\nuniform sampler2D texture;\nuniform sampler2D lenscolor;\nuniform vec2 textureSize : [512, 512];\nuniform float dispersal : 0.3;\nuniform float haloWidth : 0.4;\nuniform float distortion : 1.0;\nvarying vec2 v_Texcoord;\n@import clay.util.rgbm\nvec4 textureDistorted(\n in vec2 texcoord,\n in vec2 direction,\n in vec3 distortion\n) {\n return vec4(\n decodeHDR(texture2D(texture, texcoord + direction * distortion.r)).r,\n decodeHDR(texture2D(texture, texcoord + direction * distortion.g)).g,\n decodeHDR(texture2D(texture, texcoord + direction * distortion.b)).b,\n 1.0\n );\n}\nvoid main()\n{\n vec2 texcoord = -v_Texcoord + vec2(1.0); vec2 textureOffset = 1.0 / textureSize;\n vec2 ghostVec = (vec2(0.5) - texcoord) * dispersal;\n vec2 haloVec = normalize(ghostVec) * haloWidth;\n vec3 distortion = vec3(-textureOffset.x * distortion, 0.0, textureOffset.x * distortion);\n vec4 result = vec4(0.0);\n for (int i = 0; i < SAMPLE_NUMBER; i++)\n {\n vec2 offset = fract(texcoord + ghostVec * float(i));\n float weight = length(vec2(0.5) - offset) / length(vec2(0.5));\n weight = pow(1.0 - weight, 10.0);\n result += textureDistorted(offset, normalize(ghostVec), distortion) * weight;\n }\n result *= texture2D(lenscolor, vec2(length(vec2(0.5) - texcoord)) / length(vec2(0.5)));\n float weight = length(vec2(0.5) - fract(texcoord + haloVec)) / length(vec2(0.5));\n weight = pow(1.0 - weight, 10.0);\n vec2 offset = fract(texcoord + haloVec);\n result += textureDistorted(offset, normalize(ghostVec), distortion) * weight;\n gl_FragColor = result;\n}\n@end");
  36658. /***/
  36659. }),
  36660. /* 189 */
  36661. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  36662. "use strict";
  36663. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_claygl_src_math_Matrix4__ = __webpack_require__(9);
  36664. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_math_Vector3__ = __webpack_require__(3);
  36665. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_claygl_src_Texture2D__ = __webpack_require__(5);
  36666. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture__ = __webpack_require__(4);
  36667. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_claygl_src_compositor_Pass__ = __webpack_require__(16);
  36668. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_claygl_src_Shader__ = __webpack_require__(8);
  36669. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_claygl_src_FrameBuffer__ = __webpack_require__(10);
  36670. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__halton__ = __webpack_require__(49);
  36671. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__SSAO_glsl_js__ = __webpack_require__(190);
  36672. __WEBPACK_IMPORTED_MODULE_5_claygl_src_Shader__["a" /* default */].import(__WEBPACK_IMPORTED_MODULE_8__SSAO_glsl_js__["a" /* default */]);
  36673. function generateNoiseData(size) {
  36674. var data = new Uint8Array(size * size * 4);
  36675. var n = 0;
  36676. var v3 = new __WEBPACK_IMPORTED_MODULE_1_claygl_src_math_Vector3__["a" /* default */]();
  36677. for (var i = 0; i < size; i++) {
  36678. for (var j = 0; j < size; j++) {
  36679. v3.set(Math.random() * 2 - 1, Math.random() * 2 - 1, 0).normalize();
  36680. data[n++] = (v3.x * 0.5 + 0.5) * 255;
  36681. data[n++] = (v3.y * 0.5 + 0.5) * 255;
  36682. data[n++] = 0;
  36683. data[n++] = 255;
  36684. }
  36685. }
  36686. return data;
  36687. }
  36688. function generateNoiseTexture(size) {
  36689. return new __WEBPACK_IMPORTED_MODULE_2_claygl_src_Texture2D__["a" /* default */]({
  36690. pixels: generateNoiseData(size),
  36691. wrapS: __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture__["a" /* default */].REPEAT,
  36692. wrapT: __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture__["a" /* default */].REPEAT,
  36693. width: size,
  36694. height: size
  36695. });
  36696. }
  36697. function generateKernel(size, offset, hemisphere) {
  36698. var kernel = new Float32Array(size * 3);
  36699. offset = offset || 0;
  36700. for (var i = 0; i < size; i++) {
  36701. var phi = Object(__WEBPACK_IMPORTED_MODULE_7__halton__["a" /* default */])(i + offset, 2) * (hemisphere ? 1 : 2) * Math.PI;
  36702. var theta = Object(__WEBPACK_IMPORTED_MODULE_7__halton__["a" /* default */])(i + offset, 3) * Math.PI;
  36703. var r = Math.random();
  36704. var x = Math.cos(phi) * Math.sin(theta) * r;
  36705. var y = Math.cos(theta) * r;
  36706. var z = Math.sin(phi) * Math.sin(theta) * r;
  36707. kernel[i * 3] = x;
  36708. kernel[i * 3 + 1] = y;
  36709. kernel[i * 3 + 2] = z;
  36710. }
  36711. return kernel;
  36712. // var kernel = new Float32Array(size * 3);
  36713. // var v3 = new Vector3();
  36714. // for (var i = 0; i < size; i++) {
  36715. // v3.set(Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random())
  36716. // .normalize().scale(Math.random());
  36717. // kernel[i * 3] = v3.x;
  36718. // kernel[i * 3 + 1] = v3.y;
  36719. // kernel[i * 3 + 2] = v3.z;
  36720. // }
  36721. // return kernel;
  36722. }
  36723. function SSAOPass(opt) {
  36724. opt = opt || {};
  36725. this._ssaoPass = new __WEBPACK_IMPORTED_MODULE_4_claygl_src_compositor_Pass__["a" /* default */]({
  36726. fragment: __WEBPACK_IMPORTED_MODULE_5_claygl_src_Shader__["a" /* default */].source('ecgl.ssao.estimate')
  36727. });
  36728. this._blurPass = new __WEBPACK_IMPORTED_MODULE_4_claygl_src_compositor_Pass__["a" /* default */]({
  36729. fragment: __WEBPACK_IMPORTED_MODULE_5_claygl_src_Shader__["a" /* default */].source('ecgl.ssao.blur')
  36730. });
  36731. this._framebuffer = new __WEBPACK_IMPORTED_MODULE_6_claygl_src_FrameBuffer__["a" /* default */]({
  36732. depthBuffer: false
  36733. });
  36734. this._ssaoTexture = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_Texture2D__["a" /* default */]();
  36735. this._blurTexture = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_Texture2D__["a" /* default */]();
  36736. this._blurTexture2 = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_Texture2D__["a" /* default */]();
  36737. this._depthTex = opt.depthTexture;
  36738. this._normalTex = opt.normalTexture;
  36739. this.setNoiseSize(4);
  36740. this.setKernelSize(opt.kernelSize || 12);
  36741. if (opt.radius != null) {
  36742. this.setParameter('radius', opt.radius);
  36743. }
  36744. if (opt.power != null) {
  36745. this.setParameter('power', opt.power);
  36746. }
  36747. if (!this._normalTex) {
  36748. this._ssaoPass.material.disableTexture('normalTex');
  36749. this._blurPass.material.disableTexture('normalTex');
  36750. }
  36751. if (!this._depthTex) {
  36752. this._blurPass.material.disableTexture('depthTex');
  36753. }
  36754. this._blurPass.material.setUniform('normalTex', this._normalTex);
  36755. this._blurPass.material.setUniform('depthTex', this._depthTex);
  36756. }
  36757. SSAOPass.prototype.setDepthTexture = function (depthTex) {
  36758. this._depthTex = depthTex;
  36759. };
  36760. SSAOPass.prototype.setNormalTexture = function (normalTex) {
  36761. this._normalTex = normalTex;
  36762. this._ssaoPass.material[normalTex ? 'enableTexture' : 'disableTexture']('normalTex');
  36763. // Switch between hemisphere and shere kernel.
  36764. this.setKernelSize(this._kernelSize);
  36765. };
  36766. SSAOPass.prototype.update = function (renderer, camera, frame) {
  36767. var width = renderer.getWidth();
  36768. var height = renderer.getHeight();
  36769. var ssaoPass = this._ssaoPass;
  36770. var blurPass = this._blurPass;
  36771. ssaoPass.setUniform('kernel', this._kernels[frame % this._kernels.length]);
  36772. ssaoPass.setUniform('depthTex', this._depthTex);
  36773. if (this._normalTex != null) {
  36774. ssaoPass.setUniform('normalTex', this._normalTex);
  36775. }
  36776. ssaoPass.setUniform('depthTexSize', [this._depthTex.width, this._depthTex.height]);
  36777. var viewInverseTranspose = new __WEBPACK_IMPORTED_MODULE_0_claygl_src_math_Matrix4__["a" /* default */]();
  36778. __WEBPACK_IMPORTED_MODULE_0_claygl_src_math_Matrix4__["a" /* default */].transpose(viewInverseTranspose, camera.worldTransform);
  36779. ssaoPass.setUniform('projection', camera.projectionMatrix.array);
  36780. ssaoPass.setUniform('projectionInv', camera.invProjectionMatrix.array);
  36781. ssaoPass.setUniform('viewInverseTranspose', viewInverseTranspose.array);
  36782. var ssaoTexture = this._ssaoTexture;
  36783. var blurTexture = this._blurTexture;
  36784. var blurTexture2 = this._blurTexture2;
  36785. ssaoTexture.width = width / 2;
  36786. ssaoTexture.height = height / 2;
  36787. blurTexture.width = width;
  36788. blurTexture.height = height;
  36789. blurTexture2.width = width;
  36790. blurTexture2.height = height;
  36791. this._framebuffer.attach(ssaoTexture);
  36792. this._framebuffer.bind(renderer);
  36793. renderer.gl.clearColor(1, 1, 1, 1);
  36794. renderer.gl.clear(renderer.gl.COLOR_BUFFER_BIT);
  36795. ssaoPass.render(renderer);
  36796. blurPass.setUniform('textureSize', [width / 2, height / 2]);
  36797. blurPass.setUniform('projection', camera.projectionMatrix.array);
  36798. this._framebuffer.attach(blurTexture);
  36799. blurPass.setUniform('direction', 0);
  36800. blurPass.setUniform('ssaoTexture', ssaoTexture);
  36801. blurPass.render(renderer);
  36802. this._framebuffer.attach(blurTexture2);
  36803. blurPass.setUniform('textureSize', [width, height]);
  36804. blurPass.setUniform('direction', 1);
  36805. blurPass.setUniform('ssaoTexture', blurTexture);
  36806. blurPass.render(renderer);
  36807. this._framebuffer.unbind(renderer);
  36808. // Restore clear
  36809. var clearColor = renderer.clearColor;
  36810. renderer.gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
  36811. };
  36812. SSAOPass.prototype.getTargetTexture = function () {
  36813. return this._blurTexture2;
  36814. }
  36815. SSAOPass.prototype.setParameter = function (name, val) {
  36816. if (name === 'noiseTexSize') {
  36817. this.setNoiseSize(val);
  36818. }
  36819. else if (name === 'kernelSize') {
  36820. this.setKernelSize(val);
  36821. }
  36822. else if (name === 'intensity') {
  36823. this._ssaoPass.material.set('intensity', val);
  36824. }
  36825. else {
  36826. this._ssaoPass.setUniform(name, val);
  36827. }
  36828. };
  36829. SSAOPass.prototype.setKernelSize = function (size) {
  36830. this._kernelSize = size;
  36831. this._ssaoPass.material.define('fragment', 'KERNEL_SIZE', size);
  36832. this._kernels = this._kernels || [];
  36833. for (var i = 0; i < 30; i++) {
  36834. this._kernels[i] = generateKernel(size, i * size, !!this._normalTex);
  36835. }
  36836. };
  36837. SSAOPass.prototype.setNoiseSize = function (size) {
  36838. var texture = this._ssaoPass.getUniform('noiseTex');
  36839. if (!texture) {
  36840. texture = generateNoiseTexture(size);
  36841. this._ssaoPass.setUniform('noiseTex', generateNoiseTexture(size));
  36842. }
  36843. else {
  36844. texture.data = generateNoiseData(size);
  36845. texture.width = texture.height = size;
  36846. texture.dirty();
  36847. }
  36848. this._ssaoPass.setUniform('noiseTexSize', [size, size]);
  36849. };
  36850. SSAOPass.prototype.dispose = function (renderer) {
  36851. this._blurTexture.dispose(renderer);
  36852. this._ssaoTexture.dispose(renderer);
  36853. this._blurTexture2.dispose(renderer);
  36854. };
  36855. /* harmony default export */ __webpack_exports__["a"] = (SSAOPass);
  36856. /***/
  36857. }),
  36858. /* 190 */
  36859. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  36860. "use strict";
  36861. /* harmony default export */ __webpack_exports__["a"] = ("@export ecgl.ssao.estimate\n\nuniform sampler2D depthTex;\n\nuniform sampler2D normalTex;\n\nuniform sampler2D noiseTex;\n\nuniform vec2 depthTexSize;\n\nuniform vec2 noiseTexSize;\n\nuniform mat4 projection;\n\nuniform mat4 projectionInv;\n\nuniform mat4 viewInverseTranspose;\n\nuniform vec3 kernel[KERNEL_SIZE];\n\nuniform float radius : 1;\n\nuniform float power : 1;\n\nuniform float bias: 1e-2;\n\nuniform float intensity: 1.0;\n\nvarying vec2 v_Texcoord;\n\nfloat ssaoEstimator(in vec3 originPos, in mat3 kernelBasis) {\n float occlusion = 0.0;\n\n for (int i = 0; i < KERNEL_SIZE; i++) {\n vec3 samplePos = kernel[i];\n#ifdef NORMALTEX_ENABLED\n samplePos = kernelBasis * samplePos;\n#endif\n samplePos = samplePos * radius + originPos;\n\n vec4 texCoord = projection * vec4(samplePos, 1.0);\n texCoord.xy /= texCoord.w;\n\n vec4 depthTexel = texture2D(depthTex, texCoord.xy * 0.5 + 0.5);\n\n float sampleDepth = depthTexel.r * 2.0 - 1.0;\n if (projection[3][3] == 0.0) {\n sampleDepth = projection[3][2] / (sampleDepth * projection[2][3] - projection[2][2]);\n }\n else {\n sampleDepth = (sampleDepth - projection[3][2]) / projection[2][2];\n }\n \n float rangeCheck = smoothstep(0.0, 1.0, radius / abs(originPos.z - sampleDepth));\n occlusion += rangeCheck * step(samplePos.z, sampleDepth - bias);\n }\n#ifdef NORMALTEX_ENABLED\n occlusion = 1.0 - occlusion / float(KERNEL_SIZE);\n#else\n occlusion = 1.0 - clamp((occlusion / float(KERNEL_SIZE) - 0.6) * 2.5, 0.0, 1.0);\n#endif\n return pow(occlusion, power);\n}\n\nvoid main()\n{\n\n vec4 depthTexel = texture2D(depthTex, v_Texcoord);\n\n#ifdef NORMALTEX_ENABLED\n vec4 tex = texture2D(normalTex, v_Texcoord);\n if (dot(tex.rgb, tex.rgb) == 0.0) {\n gl_FragColor = vec4(1.0);\n return;\n }\n vec3 N = tex.rgb * 2.0 - 1.0;\n N = (viewInverseTranspose * vec4(N, 0.0)).xyz;\n\n vec2 noiseTexCoord = depthTexSize / vec2(noiseTexSize) * v_Texcoord;\n vec3 rvec = texture2D(noiseTex, noiseTexCoord).rgb * 2.0 - 1.0;\n vec3 T = normalize(rvec - N * dot(rvec, N));\n vec3 BT = normalize(cross(N, T));\n mat3 kernelBasis = mat3(T, BT, N);\n#else\n if (depthTexel.r > 0.99999) {\n gl_FragColor = vec4(1.0);\n return;\n }\n mat3 kernelBasis;\n#endif\n\n float z = depthTexel.r * 2.0 - 1.0;\n\n vec4 projectedPos = vec4(v_Texcoord * 2.0 - 1.0, z, 1.0);\n vec4 p4 = projectionInv * projectedPos;\n\n vec3 position = p4.xyz / p4.w;\n\n float ao = ssaoEstimator(position, kernelBasis);\n ao = clamp(1.0 - (1.0 - ao) * intensity, 0.0, 1.0);\n gl_FragColor = vec4(vec3(ao), 1.0);\n}\n\n@end\n\n\n@export ecgl.ssao.blur\n#define SHADER_NAME SSAO_BLUR\n\nuniform sampler2D ssaoTexture;\n\n#ifdef NORMALTEX_ENABLED\nuniform sampler2D normalTex;\n#endif\n\nvarying vec2 v_Texcoord;\n\nuniform vec2 textureSize;\nuniform float blurSize : 1.0;\n\nuniform int direction: 0.0;\n\n#ifdef DEPTHTEX_ENABLED\nuniform sampler2D depthTex;\nuniform mat4 projection;\nuniform float depthRange : 0.5;\n\nfloat getLinearDepth(vec2 coord)\n{\n float depth = texture2D(depthTex, coord).r * 2.0 - 1.0;\n return projection[3][2] / (depth * projection[2][3] - projection[2][2]);\n}\n#endif\n\nvoid main()\n{\n float kernel[5];\n kernel[0] = 0.122581;\n kernel[1] = 0.233062;\n kernel[2] = 0.288713;\n kernel[3] = 0.233062;\n kernel[4] = 0.122581;\n\n vec2 off = vec2(0.0);\n if (direction == 0) {\n off[0] = blurSize / textureSize.x;\n }\n else {\n off[1] = blurSize / textureSize.y;\n }\n\n vec2 coord = v_Texcoord;\n\n float sum = 0.0;\n float weightAll = 0.0;\n\n#ifdef NORMALTEX_ENABLED\n vec3 centerNormal = texture2D(normalTex, v_Texcoord).rgb * 2.0 - 1.0;\n#endif\n#if defined(DEPTHTEX_ENABLED)\n float centerDepth = getLinearDepth(v_Texcoord);\n#endif\n\n for (int i = 0; i < 5; i++) {\n vec2 coord = clamp(v_Texcoord + vec2(float(i) - 2.0) * off, vec2(0.0), vec2(1.0));\n\n float w = kernel[i];\n#ifdef NORMALTEX_ENABLED\n vec3 normal = texture2D(normalTex, coord).rgb * 2.0 - 1.0;\n w *= clamp(dot(normal, centerNormal), 0.0, 1.0);\n#endif\n#ifdef DEPTHTEX_ENABLED\n float d = getLinearDepth(coord);\n w *= (1.0 - smoothstep(abs(centerDepth - d) / depthRange, 0.0, 1.0));\n#endif\n\n weightAll += w;\n sum += texture2D(ssaoTexture, coord).r * w;\n }\n\n gl_FragColor = vec4(vec3(sum / weightAll), 1.0);\n}\n\n@end\n");
  36862. /***/
  36863. }),
  36864. /* 191 */
  36865. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  36866. "use strict";
  36867. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_claygl_src_math_Matrix4__ = __webpack_require__(9);
  36868. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_math_Vector3__ = __webpack_require__(3);
  36869. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_claygl_src_Texture2D__ = __webpack_require__(5);
  36870. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture__ = __webpack_require__(4);
  36871. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_claygl_src_compositor_Pass__ = __webpack_require__(16);
  36872. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_claygl_src_Shader__ = __webpack_require__(8);
  36873. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_claygl_src_FrameBuffer__ = __webpack_require__(10);
  36874. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__halton__ = __webpack_require__(49);
  36875. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8_claygl_src_util_cubemap__ = __webpack_require__(77);
  36876. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_9__SSR_glsl_js__ = __webpack_require__(192);
  36877. __WEBPACK_IMPORTED_MODULE_5_claygl_src_Shader__["a" /* default */].import(__WEBPACK_IMPORTED_MODULE_9__SSR_glsl_js__["a" /* default */]);
  36878. function SSRPass(opt) {
  36879. opt = opt || {};
  36880. this._ssrPass = new __WEBPACK_IMPORTED_MODULE_4_claygl_src_compositor_Pass__["a" /* default */]({
  36881. fragment: __WEBPACK_IMPORTED_MODULE_5_claygl_src_Shader__["a" /* default */].source('ecgl.ssr.main'),
  36882. clearColor: [0, 0, 0, 0]
  36883. });
  36884. this._blurPass1 = new __WEBPACK_IMPORTED_MODULE_4_claygl_src_compositor_Pass__["a" /* default */]({
  36885. fragment: __WEBPACK_IMPORTED_MODULE_5_claygl_src_Shader__["a" /* default */].source('ecgl.ssr.blur'),
  36886. clearColor: [0, 0, 0, 0]
  36887. });
  36888. this._blurPass2 = new __WEBPACK_IMPORTED_MODULE_4_claygl_src_compositor_Pass__["a" /* default */]({
  36889. fragment: __WEBPACK_IMPORTED_MODULE_5_claygl_src_Shader__["a" /* default */].source('ecgl.ssr.blur'),
  36890. clearColor: [0, 0, 0, 0]
  36891. });
  36892. this._blendPass = new __WEBPACK_IMPORTED_MODULE_4_claygl_src_compositor_Pass__["a" /* default */]({
  36893. fragment: __WEBPACK_IMPORTED_MODULE_5_claygl_src_Shader__["a" /* default */].source('clay.compositor.blend')
  36894. });
  36895. this._blendPass.material.disableTexturesAll();
  36896. this._blendPass.material.enableTexture(['texture1', 'texture2']);
  36897. this._ssrPass.setUniform('gBufferTexture1', opt.normalTexture);
  36898. this._ssrPass.setUniform('gBufferTexture2', opt.depthTexture);
  36899. // this._ssrPass.setUniform('gBufferTexture3', opt.albedoTexture);
  36900. this._blurPass1.setUniform('gBufferTexture1', opt.normalTexture);
  36901. this._blurPass1.setUniform('gBufferTexture2', opt.depthTexture);
  36902. this._blurPass2.setUniform('gBufferTexture1', opt.normalTexture);
  36903. this._blurPass2.setUniform('gBufferTexture2', opt.depthTexture);
  36904. this._blurPass2.material.define('fragment', 'VERTICAL');
  36905. this._blurPass2.material.define('fragment', 'BLEND');
  36906. this._ssrTexture = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_Texture2D__["a" /* default */]({
  36907. type: __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture__["a" /* default */].HALF_FLOAT
  36908. });
  36909. this._texture2 = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_Texture2D__["a" /* default */]({
  36910. type: __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture__["a" /* default */].HALF_FLOAT
  36911. });
  36912. this._texture3 = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_Texture2D__["a" /* default */]({
  36913. type: __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture__["a" /* default */].HALF_FLOAT
  36914. });
  36915. this._prevTexture = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_Texture2D__["a" /* default */]({
  36916. type: __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture__["a" /* default */].HALF_FLOAT
  36917. });
  36918. this._currentTexture = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_Texture2D__["a" /* default */]({
  36919. type: __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture__["a" /* default */].HALF_FLOAT
  36920. });
  36921. this._frameBuffer = new __WEBPACK_IMPORTED_MODULE_6_claygl_src_FrameBuffer__["a" /* default */]({
  36922. depthBuffer: false
  36923. });
  36924. this._normalDistribution = null;
  36925. this._totalSamples = 256;
  36926. this._samplePerFrame = 4;
  36927. this._ssrPass.material.define('fragment', 'SAMPLE_PER_FRAME', this._samplePerFrame);
  36928. this._ssrPass.material.define('fragment', 'TOTAL_SAMPLES', this._totalSamples);
  36929. this._downScale = 1;
  36930. }
  36931. SSRPass.prototype.setAmbientCubemap = function (specularCubemap, specularIntensity) {
  36932. this._ssrPass.material.set('specularCubemap', specularCubemap);
  36933. this._ssrPass.material.set('specularIntensity', specularIntensity);
  36934. var enableSpecularMap = specularCubemap && specularIntensity;
  36935. this._ssrPass.material[enableSpecularMap ? 'enableTexture' : 'disableTexture']('specularCubemap');
  36936. };
  36937. SSRPass.prototype.update = function (renderer, camera, sourceTexture, frame) {
  36938. var width = renderer.getWidth();
  36939. var height = renderer.getHeight();
  36940. var ssrTexture = this._ssrTexture;
  36941. var texture2 = this._texture2;
  36942. var texture3 = this._texture3;
  36943. ssrTexture.width = this._prevTexture.width = this._currentTexture.width = width / this._downScale;
  36944. ssrTexture.height = this._prevTexture.height = this._currentTexture.height = height / this._downScale;
  36945. texture2.width = texture3.width = width;
  36946. texture2.height = texture3.height = height;
  36947. var frameBuffer = this._frameBuffer;
  36948. var ssrPass = this._ssrPass;
  36949. var blurPass1 = this._blurPass1;
  36950. var blurPass2 = this._blurPass2;
  36951. var blendPass = this._blendPass;
  36952. var toViewSpace = new __WEBPACK_IMPORTED_MODULE_0_claygl_src_math_Matrix4__["a" /* default */]();
  36953. var toWorldSpace = new __WEBPACK_IMPORTED_MODULE_0_claygl_src_math_Matrix4__["a" /* default */]();
  36954. __WEBPACK_IMPORTED_MODULE_0_claygl_src_math_Matrix4__["a" /* default */].transpose(toViewSpace, camera.worldTransform);
  36955. __WEBPACK_IMPORTED_MODULE_0_claygl_src_math_Matrix4__["a" /* default */].transpose(toWorldSpace, camera.viewMatrix);
  36956. ssrPass.setUniform('sourceTexture', sourceTexture);
  36957. ssrPass.setUniform('projection', camera.projectionMatrix.array);
  36958. ssrPass.setUniform('projectionInv', camera.invProjectionMatrix.array);
  36959. ssrPass.setUniform('toViewSpace', toViewSpace.array);
  36960. ssrPass.setUniform('toWorldSpace', toWorldSpace.array);
  36961. ssrPass.setUniform('nearZ', camera.near);
  36962. var percent = frame / this._totalSamples * this._samplePerFrame;
  36963. ssrPass.setUniform('jitterOffset', percent);
  36964. ssrPass.setUniform('sampleOffset', frame * this._samplePerFrame);
  36965. blurPass1.setUniform('textureSize', [ssrTexture.width, ssrTexture.height]);
  36966. blurPass2.setUniform('textureSize', [width, height]);
  36967. blurPass2.setUniform('sourceTexture', sourceTexture);
  36968. blurPass1.setUniform('projection', camera.projectionMatrix.array);
  36969. blurPass2.setUniform('projection', camera.projectionMatrix.array);
  36970. frameBuffer.attach(ssrTexture);
  36971. frameBuffer.bind(renderer);
  36972. ssrPass.render(renderer);
  36973. if (this._physicallyCorrect) {
  36974. frameBuffer.attach(this._currentTexture);
  36975. blendPass.setUniform('texture1', this._prevTexture);
  36976. blendPass.setUniform('texture2', ssrTexture);
  36977. blendPass.material.set({
  36978. 'weight1': frame >= 1 ? 0.95 : 0,
  36979. 'weight2': frame >= 1 ? 0.05 : 1
  36980. // weight1: frame >= 1 ? 1 : 0,
  36981. // weight2: 1
  36982. });
  36983. blendPass.render(renderer);
  36984. }
  36985. frameBuffer.attach(texture2);
  36986. blurPass1.setUniform('texture', this._physicallyCorrect ? this._currentTexture : ssrTexture);
  36987. blurPass1.render(renderer);
  36988. frameBuffer.attach(texture3);
  36989. blurPass2.setUniform('texture', texture2);
  36990. blurPass2.render(renderer);
  36991. frameBuffer.unbind(renderer);
  36992. if (this._physicallyCorrect) {
  36993. var tmp = this._prevTexture;
  36994. this._prevTexture = this._currentTexture;
  36995. this._currentTexture = tmp;
  36996. }
  36997. };
  36998. SSRPass.prototype.getTargetTexture = function () {
  36999. return this._texture3;
  37000. };
  37001. SSRPass.prototype.setParameter = function (name, val) {
  37002. if (name === 'maxIteration') {
  37003. this._ssrPass.material.define('fragment', 'MAX_ITERATION', val);
  37004. }
  37005. else {
  37006. this._ssrPass.setUniform(name, val);
  37007. }
  37008. };
  37009. SSRPass.prototype.setPhysicallyCorrect = function (isPhysicallyCorrect) {
  37010. if (isPhysicallyCorrect) {
  37011. if (!this._normalDistribution) {
  37012. this._normalDistribution = __WEBPACK_IMPORTED_MODULE_8_claygl_src_util_cubemap__["a" /* default */].generateNormalDistribution(64, this._totalSamples);
  37013. }
  37014. this._ssrPass.material.define('fragment', 'PHYSICALLY_CORRECT');
  37015. this._ssrPass.material.set('normalDistribution', this._normalDistribution);
  37016. this._ssrPass.material.set('normalDistributionSize', [64, this._totalSamples]);
  37017. }
  37018. else {
  37019. this._ssrPass.material.undefine('fragment', 'PHYSICALLY_CORRECT');
  37020. }
  37021. this._physicallyCorrect = isPhysicallyCorrect;
  37022. };
  37023. SSRPass.prototype.setSSAOTexture = function (texture) {
  37024. var blendPass = this._blurPass2;
  37025. if (texture) {
  37026. blendPass.material.enableTexture('ssaoTex');
  37027. blendPass.material.set('ssaoTex', texture);
  37028. }
  37029. else {
  37030. blendPass.material.disableTexture('ssaoTex');
  37031. }
  37032. };
  37033. SSRPass.prototype.isFinished = function (frame) {
  37034. if (this._physicallyCorrect) {
  37035. return frame > (this._totalSamples / this._samplePerFrame);
  37036. }
  37037. else {
  37038. return true;
  37039. }
  37040. };
  37041. SSRPass.prototype.dispose = function (renderer) {
  37042. this._ssrTexture.dispose(renderer);
  37043. this._texture2.dispose(renderer);
  37044. this._texture3.dispose(renderer);
  37045. this._prevTexture.dispose(renderer);
  37046. this._currentTexture.dispose(renderer);
  37047. this._frameBuffer.dispose(renderer);
  37048. };
  37049. /* harmony default export */ __webpack_exports__["a"] = (SSRPass);
  37050. /***/
  37051. }),
  37052. /* 192 */
  37053. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  37054. "use strict";
  37055. /* harmony default export */ __webpack_exports__["a"] = ("@export ecgl.ssr.main\n\n#define SHADER_NAME SSR\n#define MAX_ITERATION 20;\n#define SAMPLE_PER_FRAME 5;\n#define TOTAL_SAMPLES 128;\n\nuniform sampler2D sourceTexture;\nuniform sampler2D gBufferTexture1;\nuniform sampler2D gBufferTexture2;\nuniform sampler2D gBufferTexture3;\nuniform samplerCube specularCubemap;\nuniform float specularIntensity: 1;\n\nuniform mat4 projection;\nuniform mat4 projectionInv;\nuniform mat4 toViewSpace;\nuniform mat4 toWorldSpace;\n\nuniform float maxRayDistance: 200;\n\nuniform float pixelStride: 16;\nuniform float pixelStrideZCutoff: 50; \nuniform float screenEdgeFadeStart: 0.9; \nuniform float eyeFadeStart : 0.2; uniform float eyeFadeEnd: 0.8; \nuniform float minGlossiness: 0.2; uniform float zThicknessThreshold: 1;\n\nuniform float nearZ;\nuniform vec2 viewportSize : VIEWPORT_SIZE;\n\nuniform float jitterOffset: 0;\n\nvarying vec2 v_Texcoord;\n\n#ifdef DEPTH_DECODE\n@import clay.util.decode_float\n#endif\n\n#ifdef PHYSICALLY_CORRECT\nuniform sampler2D normalDistribution;\nuniform float sampleOffset: 0;\nuniform vec2 normalDistributionSize;\n\nvec3 transformNormal(vec3 H, vec3 N) {\n vec3 upVector = N.y > 0.999 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0);\n vec3 tangentX = normalize(cross(N, upVector));\n vec3 tangentZ = cross(N, tangentX);\n return normalize(tangentX * H.x + N * H.y + tangentZ * H.z);\n}\nvec3 importanceSampleNormalGGX(float i, float roughness, vec3 N) {\n float p = fract((i + sampleOffset) / float(TOTAL_SAMPLES));\n vec3 H = texture2D(normalDistribution,vec2(roughness, p)).rgb;\n return transformNormal(H, N);\n}\nfloat G_Smith(float g, float ndv, float ndl) {\n float roughness = 1.0 - g;\n float k = roughness * roughness / 2.0;\n float G1V = ndv / (ndv * (1.0 - k) + k);\n float G1L = ndl / (ndl * (1.0 - k) + k);\n return G1L * G1V;\n}\nvec3 F_Schlick(float ndv, vec3 spec) {\n return spec + (1.0 - spec) * pow(1.0 - ndv, 5.0);\n}\n#endif\n\nfloat fetchDepth(sampler2D depthTexture, vec2 uv)\n{\n vec4 depthTexel = texture2D(depthTexture, uv);\n return depthTexel.r * 2.0 - 1.0;\n}\n\nfloat linearDepth(float depth)\n{\n if (projection[3][3] == 0.0) {\n return projection[3][2] / (depth * projection[2][3] - projection[2][2]);\n }\n else {\n return (depth - projection[3][2]) / projection[2][2];\n }\n}\n\nbool rayIntersectDepth(float rayZNear, float rayZFar, vec2 hitPixel)\n{\n if (rayZFar > rayZNear)\n {\n float t = rayZFar; rayZFar = rayZNear; rayZNear = t;\n }\n float cameraZ = linearDepth(fetchDepth(gBufferTexture2, hitPixel));\n return rayZFar <= cameraZ && rayZNear >= cameraZ - zThicknessThreshold;\n}\n\n\nbool traceScreenSpaceRay(\n vec3 rayOrigin, vec3 rayDir, float jitter,\n out vec2 hitPixel, out vec3 hitPoint, out float iterationCount\n)\n{\n float rayLength = ((rayOrigin.z + rayDir.z * maxRayDistance) > -nearZ)\n ? (-nearZ - rayOrigin.z) / rayDir.z : maxRayDistance;\n\n vec3 rayEnd = rayOrigin + rayDir * rayLength;\n\n vec4 H0 = projection * vec4(rayOrigin, 1.0);\n vec4 H1 = projection * vec4(rayEnd, 1.0);\n\n float k0 = 1.0 / H0.w, k1 = 1.0 / H1.w;\n\n vec3 Q0 = rayOrigin * k0, Q1 = rayEnd * k1;\n\n vec2 P0 = (H0.xy * k0 * 0.5 + 0.5) * viewportSize;\n vec2 P1 = (H1.xy * k1 * 0.5 + 0.5) * viewportSize;\n\n P1 += dot(P1 - P0, P1 - P0) < 0.0001 ? 0.01 : 0.0;\n vec2 delta = P1 - P0;\n\n bool permute = false;\n if (abs(delta.x) < abs(delta.y)) {\n permute = true;\n delta = delta.yx;\n P0 = P0.yx;\n P1 = P1.yx;\n }\n float stepDir = sign(delta.x);\n float invdx = stepDir / delta.x;\n\n vec3 dQ = (Q1 - Q0) * invdx;\n float dk = (k1 - k0) * invdx;\n\n vec2 dP = vec2(stepDir, delta.y * invdx);\n\n float strideScaler = 1.0 - min(1.0, -rayOrigin.z / pixelStrideZCutoff);\n float pixStride = 1.0 + strideScaler * pixelStride;\n\n dP *= pixStride; dQ *= pixStride; dk *= pixStride;\n\n vec4 pqk = vec4(P0, Q0.z, k0);\n vec4 dPQK = vec4(dP, dQ.z, dk);\n\n pqk += dPQK * jitter;\n float rayZFar = (dPQK.z * 0.5 + pqk.z) / (dPQK.w * 0.5 + pqk.w);\n float rayZNear;\n\n bool intersect = false;\n\n vec2 texelSize = 1.0 / viewportSize;\n\n iterationCount = 0.0;\n\n for (int i = 0; i < MAX_ITERATION; i++)\n {\n pqk += dPQK;\n\n rayZNear = rayZFar;\n rayZFar = (dPQK.z * 0.5 + pqk.z) / (dPQK.w * 0.5 + pqk.w);\n\n hitPixel = permute ? pqk.yx : pqk.xy;\n hitPixel *= texelSize;\n\n intersect = rayIntersectDepth(rayZNear, rayZFar, hitPixel);\n\n iterationCount += 1.0;\n\n dPQK *= 1.2;\n\n if (intersect) {\n break;\n }\n }\n\n Q0.xy += dQ.xy * iterationCount;\n Q0.z = pqk.z;\n hitPoint = Q0 / pqk.w;\n\n return intersect;\n}\n\nfloat calculateAlpha(\n float iterationCount, float reflectivity,\n vec2 hitPixel, vec3 hitPoint, float dist, vec3 rayDir\n)\n{\n float alpha = clamp(reflectivity, 0.0, 1.0);\n alpha *= 1.0 - (iterationCount / float(MAX_ITERATION));\n vec2 hitPixelNDC = hitPixel * 2.0 - 1.0;\n float maxDimension = min(1.0, max(abs(hitPixelNDC.x), abs(hitPixelNDC.y)));\n alpha *= 1.0 - max(0.0, maxDimension - screenEdgeFadeStart) / (1.0 - screenEdgeFadeStart);\n\n float _eyeFadeStart = eyeFadeStart;\n float _eyeFadeEnd = eyeFadeEnd;\n if (_eyeFadeStart > _eyeFadeEnd) {\n float tmp = _eyeFadeEnd;\n _eyeFadeEnd = _eyeFadeStart;\n _eyeFadeStart = tmp;\n }\n\n float eyeDir = clamp(rayDir.z, _eyeFadeStart, _eyeFadeEnd);\n alpha *= 1.0 - (eyeDir - _eyeFadeStart) / (_eyeFadeEnd - _eyeFadeStart);\n\n alpha *= 1.0 - clamp(dist / maxRayDistance, 0.0, 1.0);\n\n return alpha;\n}\n\n@import clay.util.rand\n\n@import clay.util.rgbm\n\nvoid main()\n{\n vec4 normalAndGloss = texture2D(gBufferTexture1, v_Texcoord);\n\n if (dot(normalAndGloss.rgb, vec3(1.0)) == 0.0) {\n discard;\n }\n\n float g = normalAndGloss.a;\n#if !defined(PHYSICALLY_CORRECT)\n if (g <= minGlossiness) {\n discard;\n }\n#endif\n\n float reflectivity = (g - minGlossiness) / (1.0 - minGlossiness);\n\n vec3 N = normalize(normalAndGloss.rgb * 2.0 - 1.0);\n N = normalize((toViewSpace * vec4(N, 0.0)).xyz);\n\n vec4 projectedPos = vec4(v_Texcoord * 2.0 - 1.0, fetchDepth(gBufferTexture2, v_Texcoord), 1.0);\n vec4 pos = projectionInv * projectedPos;\n vec3 rayOrigin = pos.xyz / pos.w;\n vec3 V = -normalize(rayOrigin);\n\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n float iterationCount;\n float jitter = rand(fract(v_Texcoord + jitterOffset));\n\n#ifdef PHYSICALLY_CORRECT\n vec4 color = vec4(vec3(0.0), 1.0);\n vec4 albedoMetalness = texture2D(gBufferTexture3, v_Texcoord);\n vec3 albedo = albedoMetalness.rgb;\n float m = albedoMetalness.a;\n vec3 diffuseColor = albedo * (1.0 - m);\n vec3 spec = mix(vec3(0.04), albedo, m);\n\n float jitter2 = rand(fract(v_Texcoord)) * float(TOTAL_SAMPLES);\n\n for (int i = 0; i < SAMPLE_PER_FRAME; i++) {\n vec3 H = importanceSampleNormalGGX(float(i) + jitter2, 1.0 - g, N);\n vec3 rayDir = normalize(reflect(-V, H));\n#else\n vec3 rayDir = normalize(reflect(-V, N));\n#endif\n vec2 hitPixel;\n vec3 hitPoint;\n\n bool intersect = traceScreenSpaceRay(rayOrigin, rayDir, jitter, hitPixel, hitPoint, iterationCount);\n\n float dist = distance(rayOrigin, hitPoint);\n\n vec3 hitNormal = texture2D(gBufferTexture1, hitPixel).rgb * 2.0 - 1.0;\n hitNormal = normalize((toViewSpace * vec4(hitNormal, 0.0)).xyz);\n#ifdef PHYSICALLY_CORRECT\n float ndl = clamp(dot(N, rayDir), 0.0, 1.0);\n float vdh = clamp(dot(V, H), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n vec3 litTexel = vec3(0.0);\n if (dot(hitNormal, rayDir) < 0.0 && intersect) {\n litTexel = texture2D(sourceTexture, hitPixel).rgb;\n litTexel *= pow(clamp(1.0 - dist / 200.0, 0.0, 1.0), 3.0);\n\n }\n else {\n #ifdef SPECULARCUBEMAP_ENABLED\n vec3 rayDirW = normalize(toWorldSpace * vec4(rayDir, 0.0)).rgb;\n litTexel = RGBMDecode(textureCubeLodEXT(specularCubemap, rayDirW, 0.0), 8.12).rgb * specularIntensity;\n#endif\n }\n color.rgb += ndl * litTexel * (\n F_Schlick(ndl, spec) * G_Smith(g, ndv, ndl) * vdh / (ndh * ndv + 0.001)\n );\n }\n color.rgb /= float(SAMPLE_PER_FRAME);\n#else\n #if !defined(SPECULARCUBEMAP_ENABLED)\n if (dot(hitNormal, rayDir) >= 0.0) {\n discard;\n }\n if (!intersect) {\n discard;\n }\n#endif\n float alpha = clamp(calculateAlpha(iterationCount, reflectivity, hitPixel, hitPoint, dist, rayDir), 0.0, 1.0);\n vec4 color = texture2D(sourceTexture, hitPixel);\n color.rgb *= alpha;\n\n#ifdef SPECULARCUBEMAP_ENABLED\n vec3 rayDirW = normalize(toWorldSpace * vec4(rayDir, 0.0)).rgb;\n alpha = alpha * (intersect ? 1.0 : 0.0);\n float bias = (1.0 -g) * 5.0;\n color.rgb += (1.0 - alpha)\n * RGBMDecode(textureCubeLodEXT(specularCubemap, rayDirW, bias), 8.12).rgb\n * specularIntensity;\n#endif\n\n#endif\n\n gl_FragColor = encodeHDR(color);\n}\n@end\n\n@export ecgl.ssr.blur\n\nuniform sampler2D texture;\nuniform sampler2D gBufferTexture1;\nuniform sampler2D gBufferTexture2;\nuniform mat4 projection;\nuniform float depthRange : 0.05;\n\nvarying vec2 v_Texcoord;\n\nuniform vec2 textureSize;\nuniform float blurSize : 1.0;\n\n#ifdef BLEND\n #ifdef SSAOTEX_ENABLED\nuniform sampler2D ssaoTex;\n #endif\nuniform sampler2D sourceTexture;\n#endif\n\nfloat getLinearDepth(vec2 coord)\n{\n float depth = texture2D(gBufferTexture2, coord).r * 2.0 - 1.0;\n return projection[3][2] / (depth * projection[2][3] - projection[2][2]);\n}\n\n@import clay.util.rgbm\n\n\nvoid main()\n{\n @import clay.compositor.kernel.gaussian_9\n\n vec4 centerNTexel = texture2D(gBufferTexture1, v_Texcoord);\n float g = centerNTexel.a;\n float maxBlurSize = clamp(1.0 - g, 0.0, 1.0) * blurSize;\n#ifdef VERTICAL\n vec2 off = vec2(0.0, maxBlurSize / textureSize.y);\n#else\n vec2 off = vec2(maxBlurSize / textureSize.x, 0.0);\n#endif\n\n vec2 coord = v_Texcoord;\n\n vec4 sum = vec4(0.0);\n float weightAll = 0.0;\n\n vec3 cN = centerNTexel.rgb * 2.0 - 1.0;\n float cD = getLinearDepth(v_Texcoord);\n for (int i = 0; i < 9; i++) {\n vec2 coord = clamp((float(i) - 4.0) * off + v_Texcoord, vec2(0.0), vec2(1.0));\n float w = gaussianKernel[i]\n * clamp(dot(cN, texture2D(gBufferTexture1, coord).rgb * 2.0 - 1.0), 0.0, 1.0);\n float d = getLinearDepth(coord);\n w *= (1.0 - smoothstep(abs(cD - d) / depthRange, 0.0, 1.0));\n\n weightAll += w;\n sum += decodeHDR(texture2D(texture, coord)) * w;\n }\n\n#ifdef BLEND\n float aoFactor = 1.0;\n #ifdef SSAOTEX_ENABLED\n aoFactor = texture2D(ssaoTex, v_Texcoord).r;\n #endif\n gl_FragColor = encodeHDR(\n sum / weightAll * aoFactor + decodeHDR(texture2D(sourceTexture, v_Texcoord))\n );\n#else\n gl_FragColor = encodeHDR(sum / weightAll);\n#endif\n}\n\n@end");
  37056. /***/
  37057. }),
  37058. /* 193 */
  37059. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  37060. "use strict";
  37061. // Based on https://bl.ocks.org/mbostock/19168c663618b707158
  37062. /* harmony default export */ __webpack_exports__["a"] = ([
  37063. 0.0, 0.0,
  37064. -0.321585265978, -0.154972575841,
  37065. 0.458126042375, 0.188473391593,
  37066. 0.842080129861, 0.527766490688,
  37067. 0.147304551086, -0.659453822776,
  37068. -0.331943915203, -0.940619700594,
  37069. 0.0479226680259, 0.54812163202,
  37070. 0.701581552186, -0.709825561388,
  37071. -0.295436780218, 0.940589268233,
  37072. -0.901489676764, 0.237713156085,
  37073. 0.973570876096, -0.109899459384,
  37074. -0.866792314779, -0.451805525005,
  37075. 0.330975007087, 0.800048655954,
  37076. -0.344275183665, 0.381779221166,
  37077. -0.386139432542, -0.437418421534,
  37078. -0.576478634965, -0.0148463392551,
  37079. 0.385798197415, -0.262426961053,
  37080. -0.666302061145, 0.682427250835,
  37081. -0.628010632582, -0.732836215494,
  37082. 0.10163141741, -0.987658134403,
  37083. 0.711995289051, -0.320024291314,
  37084. 0.0296005138058, 0.950296523438,
  37085. 0.0130612307608, -0.351024443122,
  37086. -0.879596633704, -0.10478487883,
  37087. 0.435712737232, 0.504254490347,
  37088. 0.779203817497, 0.206477676721,
  37089. 0.388264289969, -0.896736162545,
  37090. -0.153106280781, -0.629203242522,
  37091. -0.245517550697, 0.657969239148,
  37092. 0.126830499058, 0.26862328493,
  37093. -0.634888119007, -0.302301223431,
  37094. 0.617074219636, 0.779817204925
  37095. ]);
  37096. /***/
  37097. }),
  37098. /* 194 */
  37099. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  37100. "use strict";
  37101. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_claygl_src_Texture2D__ = __webpack_require__(5);
  37102. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_Texture__ = __webpack_require__(4);
  37103. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_claygl_src_Shader__ = __webpack_require__(8);
  37104. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_claygl_src_FrameBuffer__ = __webpack_require__(10);
  37105. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_claygl_src_Material__ = __webpack_require__(19);
  37106. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_claygl_src_compositor_Pass__ = __webpack_require__(16);
  37107. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_claygl_src_util_texture__ = __webpack_require__(61);
  37108. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__util_shader_normal_glsl_js__ = __webpack_require__(195);
  37109. // NormalPass will generate normal and depth data.
  37110. // TODO Animation
  37111. __WEBPACK_IMPORTED_MODULE_2_claygl_src_Shader__["a" /* default */].import(__WEBPACK_IMPORTED_MODULE_7__util_shader_normal_glsl_js__["a" /* default */]);
  37112. function attachTextureToSlot(renderer, program, symbol, texture, slot) {
  37113. var gl = renderer.gl;
  37114. program.setUniform(gl, '1i', symbol, slot);
  37115. gl.activeTexture(gl.TEXTURE0 + slot);
  37116. // Maybe texture is not loaded yet;
  37117. if (texture.isRenderable()) {
  37118. texture.bind(renderer);
  37119. }
  37120. else {
  37121. // Bind texture to null
  37122. texture.unbind(renderer);
  37123. }
  37124. }
  37125. // TODO Use globalShader insteadof globalMaterial?
  37126. function getBeforeRenderHook(renderer, defaultNormalMap, defaultBumpMap, defaultRoughnessMap, normalMaterial) {
  37127. var previousNormalMap;
  37128. var previousBumpMap;
  37129. var previousRoughnessMap;
  37130. var previousRenderable;
  37131. var gl = renderer.gl;
  37132. return function (renderable, normalMaterial, prevNormalMaterial) {
  37133. // Material not change
  37134. if (previousRenderable && previousRenderable.material === renderable.material) {
  37135. return;
  37136. }
  37137. var material = renderable.material;
  37138. var program = renderable.__program;
  37139. var roughness = material.get('roughness');
  37140. if (roughness == null) {
  37141. roughness = 1;
  37142. }
  37143. var normalMap = material.get('normalMap') || defaultNormalMap;
  37144. var roughnessMap = material.get('roughnessMap');
  37145. var bumpMap = material.get('bumpMap');
  37146. var uvRepeat = material.get('uvRepeat');
  37147. var uvOffset = material.get('uvOffset');
  37148. var detailUvRepeat = material.get('detailUvRepeat');
  37149. var detailUvOffset = material.get('detailUvOffset');
  37150. var useBumpMap = !!bumpMap && material.isTextureEnabled('bumpMap');
  37151. var useRoughnessMap = !!roughnessMap && material.isTextureEnabled('roughnessMap');
  37152. var doubleSide = material.isDefined('fragment', 'DOUBLE_SIDED');
  37153. bumpMap = bumpMap || defaultBumpMap;
  37154. roughnessMap = roughnessMap || defaultRoughnessMap;
  37155. if (prevNormalMaterial !== normalMaterial) {
  37156. normalMaterial.set('normalMap', normalMap);
  37157. normalMaterial.set('bumpMap', bumpMap);
  37158. normalMaterial.set('roughnessMap', roughnessMap);
  37159. normalMaterial.set('useBumpMap', useBumpMap);
  37160. normalMaterial.set('useRoughnessMap', useRoughnessMap);
  37161. normalMaterial.set('doubleSide', doubleSide);
  37162. uvRepeat != null && normalMaterial.set('uvRepeat', uvRepeat);
  37163. uvOffset != null && normalMaterial.set('uvOffset', uvOffset);
  37164. detailUvRepeat != null && normalMaterial.set('detailUvRepeat', detailUvRepeat);
  37165. detailUvOffset != null && normalMaterial.set('detailUvOffset', detailUvOffset);
  37166. normalMaterial.set('roughness', roughness);
  37167. }
  37168. else {
  37169. program.setUniform(gl, '1f', 'roughness', roughness);
  37170. if (previousNormalMap !== normalMap) {
  37171. attachTextureToSlot(renderer, program, 'normalMap', normalMap, 0);
  37172. }
  37173. if (previousBumpMap !== bumpMap && bumpMap) {
  37174. attachTextureToSlot(renderer, program, 'bumpMap', bumpMap, 1);
  37175. }
  37176. if (previousRoughnessMap !== roughnessMap && roughnessMap) {
  37177. attachTextureToSlot(renderer, program, 'roughnessMap', roughnessMap, 2);
  37178. }
  37179. if (uvRepeat != null) {
  37180. program.setUniform(gl, '2f', 'uvRepeat', uvRepeat);
  37181. }
  37182. if (uvOffset != null) {
  37183. program.setUniform(gl, '2f', 'uvOffset', uvOffset);
  37184. }
  37185. if (detailUvRepeat != null) {
  37186. program.setUniform(gl, '2f', 'detailUvRepeat', detailUvRepeat);
  37187. }
  37188. if (detailUvOffset != null) {
  37189. program.setUniform(gl, '2f', 'detailUvOffset', detailUvOffset);
  37190. }
  37191. program.setUniform(gl, '1i', 'useBumpMap', +useBumpMap);
  37192. program.setUniform(gl, '1i', 'useRoughnessMap', +useRoughnessMap);
  37193. program.setUniform(gl, '1i', 'doubleSide', +doubleSide);
  37194. }
  37195. previousNormalMap = normalMap;
  37196. previousBumpMap = bumpMap;
  37197. previousRoughnessMap = roughnessMap;
  37198. previousRenderable = renderable;
  37199. };
  37200. }
  37201. function NormalPass(opt) {
  37202. opt = opt || {};
  37203. this._depthTex = new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Texture2D__["a" /* default */]({
  37204. format: __WEBPACK_IMPORTED_MODULE_1_claygl_src_Texture__["a" /* default */].DEPTH_COMPONENT,
  37205. type: __WEBPACK_IMPORTED_MODULE_1_claygl_src_Texture__["a" /* default */].UNSIGNED_INT
  37206. });
  37207. this._normalTex = new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Texture2D__["a" /* default */]({
  37208. type: __WEBPACK_IMPORTED_MODULE_1_claygl_src_Texture__["a" /* default */].HALF_FLOAT
  37209. });
  37210. this._framebuffer = new __WEBPACK_IMPORTED_MODULE_3_claygl_src_FrameBuffer__["a" /* default */]();
  37211. this._framebuffer.attach(this._normalTex);
  37212. this._framebuffer.attach(this._depthTex, __WEBPACK_IMPORTED_MODULE_3_claygl_src_FrameBuffer__["a" /* default */].DEPTH_ATTACHMENT);
  37213. this._normalMaterial = new __WEBPACK_IMPORTED_MODULE_4_claygl_src_Material__["a" /* default */]({
  37214. shader: new __WEBPACK_IMPORTED_MODULE_2_claygl_src_Shader__["a" /* default */](
  37215. __WEBPACK_IMPORTED_MODULE_2_claygl_src_Shader__["a" /* default */].source('ecgl.normal.vertex'),
  37216. __WEBPACK_IMPORTED_MODULE_2_claygl_src_Shader__["a" /* default */].source('ecgl.normal.fragment')
  37217. )
  37218. });
  37219. this._normalMaterial.enableTexture(['normalMap', 'bumpMap', 'roughnessMap']);
  37220. this._defaultNormalMap = __WEBPACK_IMPORTED_MODULE_6_claygl_src_util_texture__["a" /* default */].createBlank('#000');
  37221. this._defaultBumpMap = __WEBPACK_IMPORTED_MODULE_6_claygl_src_util_texture__["a" /* default */].createBlank('#000');
  37222. this._defaultRoughessMap = __WEBPACK_IMPORTED_MODULE_6_claygl_src_util_texture__["a" /* default */].createBlank('#000');
  37223. this._debugPass = new __WEBPACK_IMPORTED_MODULE_5_claygl_src_compositor_Pass__["a" /* default */]({
  37224. fragment: __WEBPACK_IMPORTED_MODULE_2_claygl_src_Shader__["a" /* default */].source('clay.compositor.output')
  37225. });
  37226. this._debugPass.setUniform('texture', this._normalTex);
  37227. this._debugPass.material.undefine('fragment', 'OUTPUT_ALPHA');
  37228. }
  37229. NormalPass.prototype.getDepthTexture = function () {
  37230. return this._depthTex;
  37231. };
  37232. NormalPass.prototype.getNormalTexture = function () {
  37233. return this._normalTex;
  37234. };
  37235. NormalPass.prototype.update = function (renderer, scene, camera) {
  37236. var width = renderer.getWidth();
  37237. var height = renderer.getHeight();
  37238. var depthTexture = this._depthTex;
  37239. var normalTexture = this._normalTex;
  37240. var normalMaterial = this._normalMaterial;
  37241. depthTexture.width = width;
  37242. depthTexture.height = height;
  37243. normalTexture.width = width;
  37244. normalTexture.height = height;
  37245. var opaqueList = scene.getRenderList(camera).opaque;
  37246. this._framebuffer.bind(renderer);
  37247. renderer.gl.clearColor(0, 0, 0, 0);
  37248. renderer.gl.clear(renderer.gl.COLOR_BUFFER_BIT | renderer.gl.DEPTH_BUFFER_BIT);
  37249. renderer.gl.disable(renderer.gl.BLEND);
  37250. renderer.renderPass(opaqueList, camera, {
  37251. getMaterial: function () {
  37252. return normalMaterial;
  37253. },
  37254. ifRender: function (object) {
  37255. return object.renderNormal;
  37256. },
  37257. beforeRender: getBeforeRenderHook(
  37258. renderer, this._defaultNormalMap, this._defaultBumpMap, this._defaultRoughessMap, this._normalMaterial
  37259. ),
  37260. sort: renderer.opaqueSortCompare
  37261. });
  37262. this._framebuffer.unbind(renderer);
  37263. };
  37264. NormalPass.prototype.renderDebug = function (renderer) {
  37265. this._debugPass.render(renderer);
  37266. };
  37267. NormalPass.prototype.dispose = function (renderer) {
  37268. this._depthTex.dispose(renderer);
  37269. this._normalTex.dispose(renderer);
  37270. }
  37271. /* harmony default export */ __webpack_exports__["a"] = (NormalPass);
  37272. /***/
  37273. }),
  37274. /* 195 */
  37275. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  37276. "use strict";
  37277. /* harmony default export */ __webpack_exports__["a"] = ("@export ecgl.normal.vertex\n\n@import ecgl.common.transformUniforms\n\n@import ecgl.common.uv.header\n\n@import ecgl.common.attributes\n\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\n\n@import ecgl.common.normalMap.vertexHeader\n\n@import ecgl.common.vertexAnimation.header\n\nvoid main()\n{\n\n @import ecgl.common.vertexAnimation.main\n\n @import ecgl.common.uv.main\n\n v_Normal = normalize((worldInverseTranspose * vec4(normal, 0.0)).xyz);\n v_WorldPosition = (world * vec4(pos, 1.0)).xyz;\n\n @import ecgl.common.normalMap.vertexMain\n\n gl_Position = worldViewProjection * vec4(pos, 1.0);\n\n}\n\n\n@end\n\n\n@export ecgl.normal.fragment\n\n#define ROUGHNESS_CHANEL 0\n\nuniform bool useBumpMap;\nuniform bool useRoughnessMap;\nuniform bool doubleSide;\nuniform float roughness;\n\n@import ecgl.common.uv.fragmentHeader\n\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\n\nuniform mat4 viewInverse : VIEWINVERSE;\n\n@import ecgl.common.normalMap.fragmentHeader\n@import ecgl.common.bumpMap.header\n\nuniform sampler2D roughnessMap;\n\nvoid main()\n{\n vec3 N = v_Normal;\n \n bool flipNormal = false;\n if (doubleSide) {\n vec3 eyePos = viewInverse[3].xyz;\n vec3 V = normalize(eyePos - v_WorldPosition);\n\n if (dot(N, V) < 0.0) {\n flipNormal = true;\n }\n }\n\n @import ecgl.common.normalMap.fragmentMain\n\n if (useBumpMap) {\n N = bumpNormal(v_WorldPosition, v_Normal, N);\n }\n\n float g = 1.0 - roughness;\n\n if (useRoughnessMap) {\n float g2 = 1.0 - texture2D(roughnessMap, v_DetailTexcoord)[ROUGHNESS_CHANEL];\n g = clamp(g2 + (g - 0.5) * 2.0, 0.0, 1.0);\n }\n\n if (flipNormal) {\n N = -N;\n }\n\n gl_FragColor.rgb = (N.xyz + 1.0) * 0.5;\n gl_FragColor.a = g;\n}\n@end");
  37278. /***/
  37279. }),
  37280. /* 196 */
  37281. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  37282. "use strict";
  37283. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_claygl_src_math_Matrix4__ = __webpack_require__(9);
  37284. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_math_Vector3__ = __webpack_require__(3);
  37285. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_claygl_src_Texture2D__ = __webpack_require__(5);
  37286. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture__ = __webpack_require__(4);
  37287. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_claygl_src_compositor_Pass__ = __webpack_require__(16);
  37288. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_claygl_src_Shader__ = __webpack_require__(8);
  37289. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_claygl_src_FrameBuffer__ = __webpack_require__(10);
  37290. function EdgePass(opt) {
  37291. opt = opt || {};
  37292. this._edgePass = new __WEBPACK_IMPORTED_MODULE_4_claygl_src_compositor_Pass__["a" /* default */]({
  37293. fragment: __WEBPACK_IMPORTED_MODULE_5_claygl_src_Shader__["a" /* default */].source('ecgl.edge')
  37294. });
  37295. this._edgePass.setUniform('normalTexture', opt.normalTexture);
  37296. this._edgePass.setUniform('depthTexture', opt.depthTexture);
  37297. this._targetTexture = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_Texture2D__["a" /* default */]({
  37298. type: __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture__["a" /* default */].HALF_FLOAT
  37299. });
  37300. this._frameBuffer = new __WEBPACK_IMPORTED_MODULE_6_claygl_src_FrameBuffer__["a" /* default */]();
  37301. this._frameBuffer.attach(this._targetTexture);
  37302. }
  37303. EdgePass.prototype.update = function (renderer, camera, sourceTexture, frame) {
  37304. var width = renderer.getWidth();
  37305. var height = renderer.getHeight();
  37306. var texture = this._targetTexture;
  37307. texture.width = width;
  37308. texture.height = height;
  37309. var frameBuffer = this._frameBuffer;
  37310. frameBuffer.bind(renderer);
  37311. this._edgePass.setUniform('projectionInv', camera.invProjectionMatrix.array);
  37312. this._edgePass.setUniform('textureSize', [width, height]);
  37313. this._edgePass.setUniform('texture', sourceTexture);
  37314. this._edgePass.render(renderer);
  37315. frameBuffer.unbind(renderer);
  37316. };
  37317. EdgePass.prototype.getTargetTexture = function () {
  37318. return this._targetTexture;
  37319. };
  37320. EdgePass.prototype.setParameter = function (name, val) {
  37321. this._edgePass.setUniform(name, val);
  37322. };
  37323. EdgePass.prototype.dispose = function (renderer) {
  37324. this._targetTexture.dispose(renderer);
  37325. this._frameBuffer.dispose(renderer);
  37326. };
  37327. /* harmony default export */ __webpack_exports__["a"] = (EdgePass);
  37328. /***/
  37329. }),
  37330. /* 197 */
  37331. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  37332. "use strict";
  37333. /* harmony default export */ __webpack_exports__["a"] = ({
  37334. 'type': 'compositor',
  37335. 'nodes': [
  37336. {
  37337. 'name': 'source',
  37338. 'type': 'texture',
  37339. 'outputs': {
  37340. 'color': {}
  37341. }
  37342. },
  37343. {
  37344. 'name': 'source_half',
  37345. 'shader': '#source(clay.compositor.downsample)',
  37346. 'inputs': {
  37347. 'texture': 'source'
  37348. },
  37349. 'outputs': {
  37350. 'color': {
  37351. 'parameters': {
  37352. 'width': 'expr(width * 1.0 / 2)',
  37353. 'height': 'expr(height * 1.0 / 2)',
  37354. 'type': 'HALF_FLOAT'
  37355. }
  37356. }
  37357. },
  37358. 'parameters': {
  37359. 'textureSize': 'expr( [width * 1.0, height * 1.0] )'
  37360. }
  37361. },
  37362. {
  37363. 'name': 'bright',
  37364. 'shader': '#source(clay.compositor.bright)',
  37365. 'inputs': {
  37366. 'texture': 'source_half'
  37367. },
  37368. 'outputs': {
  37369. 'color': {
  37370. 'parameters': {
  37371. 'width': 'expr(width * 1.0 / 2)',
  37372. 'height': 'expr(height * 1.0 / 2)',
  37373. 'type': 'HALF_FLOAT'
  37374. }
  37375. }
  37376. },
  37377. 'parameters': {
  37378. 'threshold': 2,
  37379. 'scale': 4,
  37380. 'textureSize': 'expr([width * 1.0 / 2, height / 2])'
  37381. }
  37382. },
  37383. {
  37384. 'name': 'bright_downsample_4',
  37385. 'shader': '#source(clay.compositor.downsample)',
  37386. 'inputs': {
  37387. 'texture': 'bright'
  37388. },
  37389. 'outputs': {
  37390. 'color': {
  37391. 'parameters': {
  37392. 'width': 'expr(width * 1.0 / 4)',
  37393. 'height': 'expr(height * 1.0 / 4)',
  37394. 'type': 'HALF_FLOAT'
  37395. }
  37396. }
  37397. },
  37398. 'parameters': {
  37399. 'textureSize': 'expr( [width * 1.0 / 2, height / 2] )'
  37400. }
  37401. },
  37402. {
  37403. 'name': 'bright_downsample_8',
  37404. 'shader': '#source(clay.compositor.downsample)',
  37405. 'inputs': {
  37406. 'texture': 'bright_downsample_4'
  37407. },
  37408. 'outputs': {
  37409. 'color': {
  37410. 'parameters': {
  37411. 'width': 'expr(width * 1.0 / 8)',
  37412. 'height': 'expr(height * 1.0 / 8)',
  37413. 'type': 'HALF_FLOAT'
  37414. }
  37415. }
  37416. },
  37417. 'parameters': {
  37418. 'textureSize': 'expr( [width * 1.0 / 4, height / 4] )'
  37419. }
  37420. },
  37421. {
  37422. 'name': 'bright_downsample_16',
  37423. 'shader': '#source(clay.compositor.downsample)',
  37424. 'inputs': {
  37425. 'texture': 'bright_downsample_8'
  37426. },
  37427. 'outputs': {
  37428. 'color': {
  37429. 'parameters': {
  37430. 'width': 'expr(width * 1.0 / 16)',
  37431. 'height': 'expr(height * 1.0 / 16)',
  37432. 'type': 'HALF_FLOAT'
  37433. }
  37434. }
  37435. },
  37436. 'parameters': {
  37437. 'textureSize': 'expr( [width * 1.0 / 8, height / 8] )'
  37438. }
  37439. },
  37440. {
  37441. 'name': 'bright_downsample_32',
  37442. 'shader': '#source(clay.compositor.downsample)',
  37443. 'inputs': {
  37444. 'texture': 'bright_downsample_16'
  37445. },
  37446. 'outputs': {
  37447. 'color': {
  37448. 'parameters': {
  37449. 'width': 'expr(width * 1.0 / 32)',
  37450. 'height': 'expr(height * 1.0 / 32)',
  37451. 'type': 'HALF_FLOAT'
  37452. }
  37453. }
  37454. },
  37455. 'parameters': {
  37456. 'textureSize': 'expr( [width * 1.0 / 16, height / 16] )'
  37457. }
  37458. },
  37459. {
  37460. 'name': 'bright_upsample_16_blur_h',
  37461. 'shader': '#source(clay.compositor.gaussian_blur)',
  37462. 'inputs': {
  37463. 'texture': 'bright_downsample_32'
  37464. },
  37465. 'outputs': {
  37466. 'color': {
  37467. 'parameters': {
  37468. 'width': 'expr(width * 1.0 / 16)',
  37469. 'height': 'expr(height * 1.0 / 16)',
  37470. 'type': 'HALF_FLOAT'
  37471. }
  37472. }
  37473. },
  37474. 'parameters': {
  37475. 'blurSize': 1,
  37476. 'blurDir': 0.0,
  37477. 'textureSize': 'expr( [width * 1.0 / 32, height / 32] )'
  37478. }
  37479. },
  37480. {
  37481. 'name': 'bright_upsample_16_blur_v',
  37482. 'shader': '#source(clay.compositor.gaussian_blur)',
  37483. 'inputs': {
  37484. 'texture': 'bright_upsample_16_blur_h'
  37485. },
  37486. 'outputs': {
  37487. 'color': {
  37488. 'parameters': {
  37489. 'width': 'expr(width * 1.0 / 16)',
  37490. 'height': 'expr(height * 1.0 / 16)',
  37491. 'type': 'HALF_FLOAT'
  37492. }
  37493. }
  37494. },
  37495. 'parameters': {
  37496. 'blurSize': 1,
  37497. 'blurDir': 1.0,
  37498. 'textureSize': 'expr( [width * 1.0 / 16, height * 1.0 / 16] )'
  37499. }
  37500. },
  37501. {
  37502. 'name': 'bright_upsample_8_blur_h',
  37503. 'shader': '#source(clay.compositor.gaussian_blur)',
  37504. 'inputs': {
  37505. 'texture': 'bright_downsample_16'
  37506. },
  37507. 'outputs': {
  37508. 'color': {
  37509. 'parameters': {
  37510. 'width': 'expr(width * 1.0 / 8)',
  37511. 'height': 'expr(height * 1.0 / 8)',
  37512. 'type': 'HALF_FLOAT'
  37513. }
  37514. }
  37515. },
  37516. 'parameters': {
  37517. 'blurSize': 1,
  37518. 'blurDir': 0.0,
  37519. 'textureSize': 'expr( [width * 1.0 / 16, height * 1.0 / 16] )'
  37520. }
  37521. },
  37522. {
  37523. 'name': 'bright_upsample_8_blur_v',
  37524. 'shader': '#source(clay.compositor.gaussian_blur)',
  37525. 'inputs': {
  37526. 'texture': 'bright_upsample_8_blur_h'
  37527. },
  37528. 'outputs': {
  37529. 'color': {
  37530. 'parameters': {
  37531. 'width': 'expr(width * 1.0 / 8)',
  37532. 'height': 'expr(height * 1.0 / 8)',
  37533. 'type': 'HALF_FLOAT'
  37534. }
  37535. }
  37536. },
  37537. 'parameters': {
  37538. 'blurSize': 1,
  37539. 'blurDir': 1.0,
  37540. 'textureSize': 'expr( [width * 1.0 / 8, height * 1.0 / 8] )'
  37541. }
  37542. },
  37543. {
  37544. 'name': 'bright_upsample_8_blend',
  37545. 'shader': '#source(clay.compositor.blend)',
  37546. 'inputs': {
  37547. 'texture1': 'bright_upsample_8_blur_v',
  37548. 'texture2': 'bright_upsample_16_blur_v'
  37549. },
  37550. 'outputs': {
  37551. 'color': {
  37552. 'parameters': {
  37553. 'width': 'expr(width * 1.0 / 8)',
  37554. 'height': 'expr(height * 1.0 / 8)',
  37555. 'type': 'HALF_FLOAT'
  37556. }
  37557. }
  37558. },
  37559. 'parameters': {
  37560. 'weight1': 0.3,
  37561. 'weight2': 0.7
  37562. }
  37563. },
  37564. {
  37565. 'name': 'bright_upsample_4_blur_h',
  37566. 'shader': '#source(clay.compositor.gaussian_blur)',
  37567. 'inputs': {
  37568. 'texture': 'bright_downsample_8'
  37569. },
  37570. 'outputs': {
  37571. 'color': {
  37572. 'parameters': {
  37573. 'width': 'expr(width * 1.0 / 4)',
  37574. 'height': 'expr(height * 1.0 / 4)',
  37575. 'type': 'HALF_FLOAT'
  37576. }
  37577. }
  37578. },
  37579. 'parameters': {
  37580. 'blurSize': 1,
  37581. 'blurDir': 0.0,
  37582. 'textureSize': 'expr( [width * 1.0 / 8, height * 1.0 / 8] )'
  37583. }
  37584. },
  37585. {
  37586. 'name': 'bright_upsample_4_blur_v',
  37587. 'shader': '#source(clay.compositor.gaussian_blur)',
  37588. 'inputs': {
  37589. 'texture': 'bright_upsample_4_blur_h'
  37590. },
  37591. 'outputs': {
  37592. 'color': {
  37593. 'parameters': {
  37594. 'width': 'expr(width * 1.0 / 4)',
  37595. 'height': 'expr(height * 1.0 / 4)',
  37596. 'type': 'HALF_FLOAT'
  37597. }
  37598. }
  37599. },
  37600. 'parameters': {
  37601. 'blurSize': 1,
  37602. 'blurDir': 1.0,
  37603. 'textureSize': 'expr( [width * 1.0 / 4, height * 1.0 / 4] )'
  37604. }
  37605. },
  37606. {
  37607. 'name': 'bright_upsample_4_blend',
  37608. 'shader': '#source(clay.compositor.blend)',
  37609. 'inputs': {
  37610. 'texture1': 'bright_upsample_4_blur_v',
  37611. 'texture2': 'bright_upsample_8_blend'
  37612. },
  37613. 'outputs': {
  37614. 'color': {
  37615. 'parameters': {
  37616. 'width': 'expr(width * 1.0 / 4)',
  37617. 'height': 'expr(height * 1.0 / 4)',
  37618. 'type': 'HALF_FLOAT'
  37619. }
  37620. }
  37621. },
  37622. 'parameters': {
  37623. 'weight1': 0.3,
  37624. 'weight2': 0.7
  37625. }
  37626. },
  37627. {
  37628. 'name': 'bright_upsample_2_blur_h',
  37629. 'shader': '#source(clay.compositor.gaussian_blur)',
  37630. 'inputs': {
  37631. 'texture': 'bright_downsample_4'
  37632. },
  37633. 'outputs': {
  37634. 'color': {
  37635. 'parameters': {
  37636. 'width': 'expr(width * 1.0 / 2)',
  37637. 'height': 'expr(height * 1.0 / 2)',
  37638. 'type': 'HALF_FLOAT'
  37639. }
  37640. }
  37641. },
  37642. 'parameters': {
  37643. 'blurSize': 1,
  37644. 'blurDir': 0.0,
  37645. 'textureSize': 'expr( [width * 1.0 / 4, height * 1.0 / 4] )'
  37646. }
  37647. },
  37648. {
  37649. 'name': 'bright_upsample_2_blur_v',
  37650. 'shader': '#source(clay.compositor.gaussian_blur)',
  37651. 'inputs': {
  37652. 'texture': 'bright_upsample_2_blur_h'
  37653. },
  37654. 'outputs': {
  37655. 'color': {
  37656. 'parameters': {
  37657. 'width': 'expr(width * 1.0 / 2)',
  37658. 'height': 'expr(height * 1.0 / 2)',
  37659. 'type': 'HALF_FLOAT'
  37660. }
  37661. }
  37662. },
  37663. 'parameters': {
  37664. 'blurSize': 1,
  37665. 'blurDir': 1.0,
  37666. 'textureSize': 'expr( [width * 1.0 / 2, height * 1.0 / 2] )'
  37667. }
  37668. },
  37669. {
  37670. 'name': 'bright_upsample_2_blend',
  37671. 'shader': '#source(clay.compositor.blend)',
  37672. 'inputs': {
  37673. 'texture1': 'bright_upsample_2_blur_v',
  37674. 'texture2': 'bright_upsample_4_blend'
  37675. },
  37676. 'outputs': {
  37677. 'color': {
  37678. 'parameters': {
  37679. 'width': 'expr(width * 1.0 / 2)',
  37680. 'height': 'expr(height * 1.0 / 2)',
  37681. 'type': 'HALF_FLOAT'
  37682. }
  37683. }
  37684. },
  37685. 'parameters': {
  37686. 'weight1': 0.3,
  37687. 'weight2': 0.7
  37688. }
  37689. },
  37690. {
  37691. 'name': 'bright_upsample_full_blur_h',
  37692. 'shader': '#source(clay.compositor.gaussian_blur)',
  37693. 'inputs': {
  37694. 'texture': 'bright'
  37695. },
  37696. 'outputs': {
  37697. 'color': {
  37698. 'parameters': {
  37699. 'width': 'expr(width * 1.0)',
  37700. 'height': 'expr(height * 1.0)',
  37701. 'type': 'HALF_FLOAT'
  37702. }
  37703. }
  37704. },
  37705. 'parameters': {
  37706. 'blurSize': 1,
  37707. 'blurDir': 0.0,
  37708. 'textureSize': 'expr( [width * 1.0 / 2, height * 1.0 / 2] )'
  37709. }
  37710. },
  37711. {
  37712. 'name': 'bright_upsample_full_blur_v',
  37713. 'shader': '#source(clay.compositor.gaussian_blur)',
  37714. 'inputs': {
  37715. 'texture': 'bright_upsample_full_blur_h'
  37716. },
  37717. 'outputs': {
  37718. 'color': {
  37719. 'parameters': {
  37720. 'width': 'expr(width * 1.0)',
  37721. 'height': 'expr(height * 1.0)',
  37722. 'type': 'HALF_FLOAT'
  37723. }
  37724. }
  37725. },
  37726. 'parameters': {
  37727. 'blurSize': 1,
  37728. 'blurDir': 1.0,
  37729. 'textureSize': 'expr( [width * 1.0, height * 1.0] )'
  37730. }
  37731. },
  37732. {
  37733. 'name': 'bloom_composite',
  37734. 'shader': '#source(clay.compositor.blend)',
  37735. 'inputs': {
  37736. 'texture1': 'bright_upsample_full_blur_v',
  37737. 'texture2': 'bright_upsample_2_blend'
  37738. },
  37739. 'outputs': {
  37740. 'color': {
  37741. 'parameters': {
  37742. 'width': 'expr(width * 1.0)',
  37743. 'height': 'expr(height * 1.0)',
  37744. 'type': 'HALF_FLOAT'
  37745. }
  37746. }
  37747. },
  37748. 'parameters': {
  37749. 'weight1': 0.3,
  37750. 'weight2': 0.7
  37751. }
  37752. },
  37753. {
  37754. 'name': 'coc',
  37755. 'shader': '#source(ecgl.dof.coc)',
  37756. 'outputs': {
  37757. 'color': {
  37758. 'parameters': {
  37759. 'minFilter': 'NEAREST',
  37760. 'magFilter': 'NEAREST',
  37761. 'width': 'expr(width * 1.0)',
  37762. 'height': 'expr(height * 1.0)'
  37763. }
  37764. }
  37765. },
  37766. 'parameters': {
  37767. 'focalDist': 50,
  37768. 'focalRange': 30
  37769. }
  37770. },
  37771. {
  37772. 'name': 'dof_far_blur',
  37773. 'shader': '#source(ecgl.dof.diskBlur)',
  37774. 'inputs': {
  37775. 'texture': 'source',
  37776. 'coc': 'coc'
  37777. },
  37778. 'outputs': {
  37779. 'color': {
  37780. 'parameters': {
  37781. 'width': 'expr(width * 1.0)',
  37782. 'height': 'expr(height * 1.0)',
  37783. 'type': 'HALF_FLOAT'
  37784. }
  37785. }
  37786. },
  37787. 'parameters': {
  37788. 'textureSize': 'expr( [width * 1.0, height * 1.0] )'
  37789. }
  37790. },
  37791. {
  37792. 'name': 'dof_near_blur',
  37793. 'shader': '#source(ecgl.dof.diskBlur)',
  37794. 'inputs': {
  37795. 'texture': 'source',
  37796. 'coc': 'coc'
  37797. },
  37798. 'outputs': {
  37799. 'color': {
  37800. 'parameters': {
  37801. 'width': 'expr(width * 1.0)',
  37802. 'height': 'expr(height * 1.0)',
  37803. 'type': 'HALF_FLOAT'
  37804. }
  37805. }
  37806. },
  37807. 'parameters': {
  37808. 'textureSize': 'expr( [width * 1.0, height * 1.0] )'
  37809. },
  37810. 'defines': {
  37811. 'BLUR_NEARFIELD': null
  37812. }
  37813. },
  37814. {
  37815. 'name': 'dof_coc_blur',
  37816. 'shader': '#source(ecgl.dof.diskBlur)',
  37817. 'inputs': {
  37818. 'texture': 'coc'
  37819. },
  37820. 'outputs': {
  37821. 'color': {
  37822. 'parameters': {
  37823. 'minFilter': 'NEAREST',
  37824. 'magFilter': 'NEAREST',
  37825. 'width': 'expr(width * 1.0)',
  37826. 'height': 'expr(height * 1.0)'
  37827. }
  37828. }
  37829. },
  37830. 'parameters': {
  37831. 'textureSize': 'expr( [width * 1.0, height * 1.0] )'
  37832. },
  37833. 'defines': {
  37834. 'BLUR_COC': null
  37835. }
  37836. },
  37837. {
  37838. 'name': 'dof_composite',
  37839. 'shader': '#source(ecgl.dof.composite)',
  37840. 'inputs': {
  37841. 'original': 'source',
  37842. 'blurred': 'dof_far_blur',
  37843. 'nearfield': 'dof_near_blur',
  37844. 'coc': 'coc',
  37845. 'nearcoc': 'dof_coc_blur'
  37846. },
  37847. 'outputs': {
  37848. 'color': {
  37849. 'parameters': {
  37850. 'width': 'expr(width * 1.0)',
  37851. 'height': 'expr(height * 1.0)',
  37852. 'type': 'HALF_FLOAT'
  37853. }
  37854. }
  37855. }
  37856. },
  37857. {
  37858. 'name': 'composite',
  37859. 'shader': '#source(clay.compositor.hdr.composite)',
  37860. 'inputs': {
  37861. 'texture': 'source',
  37862. 'bloom': 'bloom_composite'
  37863. },
  37864. 'defines': {
  37865. // Images are all premultiplied alpha before composite because of blending.
  37866. // 'PREMULTIPLY_ALPHA': null,
  37867. // 'DEBUG': 2
  37868. }
  37869. },
  37870. {
  37871. 'name': 'FXAA',
  37872. 'shader': '#source(clay.compositor.fxaa)',
  37873. 'inputs': {
  37874. 'texture': 'composite'
  37875. }
  37876. }
  37877. ]
  37878. });
  37879. /***/
  37880. }),
  37881. /* 198 */
  37882. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  37883. "use strict";
  37884. /* harmony default export */ __webpack_exports__["a"] = ("@export ecgl.dof.coc\n\nuniform sampler2D depth;\n\nuniform float zNear: 0.1;\nuniform float zFar: 2000;\n\nuniform float focalDistance: 3;\nuniform float focalRange: 1;\nuniform float focalLength: 30;\nuniform float fstop: 2.8;\n\nvarying vec2 v_Texcoord;\n\n@import clay.util.encode_float\n\nvoid main()\n{\n float z = texture2D(depth, v_Texcoord).r * 2.0 - 1.0;\n\n float dist = 2.0 * zNear * zFar / (zFar + zNear - z * (zFar - zNear));\n\n float aperture = focalLength / fstop;\n\n float coc;\n\n float uppper = focalDistance + focalRange;\n float lower = focalDistance - focalRange;\n if (dist <= uppper && dist >= lower) {\n coc = 0.5;\n }\n else {\n float focalAdjusted = dist > uppper ? uppper : lower;\n\n coc = abs(aperture * (focalLength * (dist - focalAdjusted)) / (dist * (focalAdjusted - focalLength)));\n coc = clamp(coc, 0.0, 2.0) / 2.00001;\n\n if (dist < lower) {\n coc = -coc;\n }\n coc = coc * 0.5 + 0.5;\n }\n\n gl_FragColor = encodeFloat(coc);\n}\n@end\n\n\n@export ecgl.dof.composite\n\n#define DEBUG 0\n\nuniform sampler2D original;\nuniform sampler2D blurred;\nuniform sampler2D nearfield;\nuniform sampler2D coc;\nuniform sampler2D nearcoc;\nvarying vec2 v_Texcoord;\n\n@import clay.util.rgbm\n@import clay.util.float\n\nvoid main()\n{\n vec4 blurredColor = texture2D(blurred, v_Texcoord);\n vec4 originalColor = texture2D(original, v_Texcoord);\n\n float fCoc = decodeFloat(texture2D(coc, v_Texcoord));\n\n fCoc = abs(fCoc * 2.0 - 1.0);\n\n float weight = smoothstep(0.0, 1.0, fCoc);\n \n#ifdef NEARFIELD_ENABLED\n vec4 nearfieldColor = texture2D(nearfield, v_Texcoord);\n float fNearCoc = decodeFloat(texture2D(nearcoc, v_Texcoord));\n fNearCoc = abs(fNearCoc * 2.0 - 1.0);\n\n gl_FragColor = encodeHDR(\n mix(\n nearfieldColor, mix(originalColor, blurredColor, weight),\n pow(1.0 - fNearCoc, 4.0)\n )\n );\n#else\n gl_FragColor = encodeHDR(mix(originalColor, blurredColor, weight));\n#endif\n\n}\n\n@end\n\n\n\n@export ecgl.dof.diskBlur\n\n#define POISSON_KERNEL_SIZE 16;\n\nuniform sampler2D texture;\nuniform sampler2D coc;\nvarying vec2 v_Texcoord;\n\nuniform float blurRadius : 10.0;\nuniform vec2 textureSize : [512.0, 512.0];\n\nuniform vec2 poissonKernel[POISSON_KERNEL_SIZE];\n\nuniform float percent;\n\nfloat nrand(const in vec2 n) {\n return fract(sin(dot(n.xy ,vec2(12.9898,78.233))) * 43758.5453);\n}\n\n@import clay.util.rgbm\n@import clay.util.float\n\n\nvoid main()\n{\n vec2 offset = blurRadius / textureSize;\n\n float rnd = 6.28318 * nrand(v_Texcoord + 0.07 * percent );\n float cosa = cos(rnd);\n float sina = sin(rnd);\n vec4 basis = vec4(cosa, -sina, sina, cosa);\n\n#if !defined(BLUR_NEARFIELD) && !defined(BLUR_COC)\n offset *= abs(decodeFloat(texture2D(coc, v_Texcoord)) * 2.0 - 1.0);\n#endif\n\n#ifdef BLUR_COC\n float cocSum = 0.0;\n#else\n vec4 color = vec4(0.0);\n#endif\n\n\n float weightSum = 0.0;\n\n for (int i = 0; i < POISSON_KERNEL_SIZE; i++) {\n vec2 ofs = poissonKernel[i];\n\n ofs = vec2(dot(ofs, basis.xy), dot(ofs, basis.zw));\n\n vec2 uv = v_Texcoord + ofs * offset;\n vec4 texel = texture2D(texture, uv);\n\n float w = 1.0;\n#ifdef BLUR_COC\n float fCoc = decodeFloat(texel) * 2.0 - 1.0;\n cocSum += clamp(fCoc, -1.0, 0.0) * w;\n#else\n texel = texel;\n #if !defined(BLUR_NEARFIELD)\n float fCoc = decodeFloat(texture2D(coc, uv)) * 2.0 - 1.0;\n w *= abs(fCoc);\n #endif\n texel.rgb *= texel.a;\n color += texel * w;\n#endif\n\n weightSum += w;\n }\n\n#ifdef BLUR_COC\n gl_FragColor = encodeFloat(clamp(cocSum / weightSum, -1.0, 0.0) * 0.5 + 0.5);\n#else\n color /= weightSum;\n color.rgb /= (color.a + 0.0001);\n gl_FragColor = color;\n#endif\n}\n\n@end");
  37885. /***/
  37886. }),
  37887. /* 199 */
  37888. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  37889. "use strict";
  37890. /* harmony default export */ __webpack_exports__["a"] = ("@export ecgl.edge\n\nuniform sampler2D texture;\n\nuniform sampler2D normalTexture;\nuniform sampler2D depthTexture;\n\nuniform mat4 projectionInv;\n\nuniform vec2 textureSize;\n\nuniform vec4 edgeColor: [0,0,0,0.8];\n\nvarying vec2 v_Texcoord;\n\nvec3 packColor(vec2 coord) {\n float z = texture2D(depthTexture, coord).r * 2.0 - 1.0;\n vec4 p = vec4(v_Texcoord * 2.0 - 1.0, z, 1.0);\n vec4 p4 = projectionInv * p;\n\n return vec3(\n texture2D(normalTexture, coord).rg,\n -p4.z / p4.w / 5.0\n );\n}\n\nvoid main() {\n vec2 cc = v_Texcoord;\n vec3 center = packColor(cc);\n\n float size = clamp(1.0 - (center.z - 10.0) / 100.0, 0.0, 1.0) * 0.5;\n float dx = size / textureSize.x;\n float dy = size / textureSize.y;\n\n vec2 coord;\n vec3 topLeft = packColor(cc+vec2(-dx, -dy));\n vec3 top = packColor(cc+vec2(0.0, -dy));\n vec3 topRight = packColor(cc+vec2(dx, -dy));\n vec3 left = packColor(cc+vec2(-dx, 0.0));\n vec3 right = packColor(cc+vec2(dx, 0.0));\n vec3 bottomLeft = packColor(cc+vec2(-dx, dy));\n vec3 bottom = packColor(cc+vec2(0.0, dy));\n vec3 bottomRight = packColor(cc+vec2(dx, dy));\n\n vec3 v = -topLeft-2.0*top-topRight+bottomLeft+2.0*bottom+bottomRight;\n vec3 h = -bottomLeft-2.0*left-topLeft+bottomRight+2.0*right+topRight;\n\n float edge = sqrt(dot(h, h) + dot(v, v));\n\n edge = smoothstep(0.8, 1.0, edge);\n\n gl_FragColor = mix(texture2D(texture, v_Texcoord), vec4(edgeColor.rgb, 1.0), edgeColor.a * edge);\n}\n@end");
  37891. /***/
  37892. }),
  37893. /* 200 */
  37894. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  37895. "use strict";
  37896. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__halton__ = __webpack_require__(49);
  37897. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_compositor_Pass__ = __webpack_require__(16);
  37898. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_claygl_src_FrameBuffer__ = __webpack_require__(10);
  37899. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture2D__ = __webpack_require__(5);
  37900. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__ = __webpack_require__(8);
  37901. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_claygl_src_math_Matrix4__ = __webpack_require__(9);
  37902. // Temporal Super Sample for static Scene
  37903. function TemporalSuperSampling(frames) {
  37904. var haltonSequence = [];
  37905. for (var i = 0; i < 30; i++) {
  37906. haltonSequence.push([Object(__WEBPACK_IMPORTED_MODULE_0__halton__["a" /* default */])(i, 2), Object(__WEBPACK_IMPORTED_MODULE_0__halton__["a" /* default */])(i, 3)]);
  37907. }
  37908. this._haltonSequence = haltonSequence;
  37909. this._frame = 0;
  37910. this._sourceTex = new __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture2D__["a" /* default */]();
  37911. this._sourceFb = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_FrameBuffer__["a" /* default */]();
  37912. this._sourceFb.attach(this._sourceTex);
  37913. // Frame texture before temporal supersampling
  37914. this._prevFrameTex = new __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture2D__["a" /* default */]();
  37915. this._outputTex = new __WEBPACK_IMPORTED_MODULE_3_claygl_src_Texture2D__["a" /* default */]();
  37916. var blendPass = this._blendPass = new __WEBPACK_IMPORTED_MODULE_1_claygl_src_compositor_Pass__["a" /* default */]({
  37917. fragment: __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].source('clay.compositor.blend')
  37918. });
  37919. blendPass.material.disableTexturesAll();
  37920. blendPass.material.enableTexture(['texture1', 'texture2']);
  37921. this._blendFb = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_FrameBuffer__["a" /* default */]({
  37922. depthBuffer: false
  37923. });
  37924. this._outputPass = new __WEBPACK_IMPORTED_MODULE_1_claygl_src_compositor_Pass__["a" /* default */]({
  37925. fragment: __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].source('clay.compositor.output'),
  37926. // TODO, alpha is premultiplied?
  37927. blendWithPrevious: true
  37928. });
  37929. this._outputPass.material.define('fragment', 'OUTPUT_ALPHA');
  37930. this._outputPass.material.blend = function (_gl) {
  37931. // FIXME.
  37932. // Output is premultiplied alpha when BLEND is enabled ?
  37933. // http://stackoverflow.com/questions/2171085/opengl-blending-with-previous-contents-of-framebuffer
  37934. _gl.blendEquationSeparate(_gl.FUNC_ADD, _gl.FUNC_ADD);
  37935. _gl.blendFuncSeparate(_gl.ONE, _gl.ONE_MINUS_SRC_ALPHA, _gl.ONE, _gl.ONE_MINUS_SRC_ALPHA);
  37936. };
  37937. }
  37938. TemporalSuperSampling.prototype = {
  37939. constructor: TemporalSuperSampling,
  37940. /**
  37941. * Jitter camera projectionMatrix
  37942. * @parma {clay.Renderer} renderer
  37943. * @param {clay.Camera} camera
  37944. */
  37945. jitterProjection: function (renderer, camera) {
  37946. var viewport = renderer.viewport;
  37947. var dpr = viewport.devicePixelRatio || renderer.getDevicePixelRatio();
  37948. var width = viewport.width * dpr;
  37949. var height = viewport.height * dpr;
  37950. var offset = this._haltonSequence[this._frame % this._haltonSequence.length];
  37951. var translationMat = new __WEBPACK_IMPORTED_MODULE_5_claygl_src_math_Matrix4__["a" /* default */]();
  37952. translationMat.array[12] = (offset[0] * 2.0 - 1.0) / width;
  37953. translationMat.array[13] = (offset[1] * 2.0 - 1.0) / height;
  37954. __WEBPACK_IMPORTED_MODULE_5_claygl_src_math_Matrix4__["a" /* default */].mul(camera.projectionMatrix, translationMat, camera.projectionMatrix);
  37955. __WEBPACK_IMPORTED_MODULE_5_claygl_src_math_Matrix4__["a" /* default */].invert(camera.invProjectionMatrix, camera.projectionMatrix);
  37956. },
  37957. /**
  37958. * Reset accumulating frame
  37959. */
  37960. resetFrame: function () {
  37961. this._frame = 0;
  37962. },
  37963. /**
  37964. * Return current frame
  37965. */
  37966. getFrame: function () {
  37967. return this._frame;
  37968. },
  37969. /**
  37970. * Get source framebuffer for usage
  37971. */
  37972. getSourceFrameBuffer: function () {
  37973. return this._sourceFb;
  37974. },
  37975. getOutputTexture: function () {
  37976. return this._outputTex;
  37977. },
  37978. resize: function (width, height) {
  37979. this._prevFrameTex.width = width;
  37980. this._prevFrameTex.height = height;
  37981. this._outputTex.width = width;
  37982. this._outputTex.height = height;
  37983. this._sourceTex.width = width;
  37984. this._sourceTex.height = height;
  37985. this._prevFrameTex.dirty();
  37986. this._outputTex.dirty();
  37987. this._sourceTex.dirty();
  37988. },
  37989. isFinished: function () {
  37990. return this._frame >= this._haltonSequence.length;
  37991. },
  37992. render: function (renderer, sourceTex, notOutput) {
  37993. var blendPass = this._blendPass;
  37994. if (this._frame === 0) {
  37995. // Direct output
  37996. blendPass.setUniform('weight1', 0);
  37997. blendPass.setUniform('weight2', 1);
  37998. }
  37999. else {
  38000. blendPass.setUniform('weight1', 0.9);
  38001. blendPass.setUniform('weight2', 0.1);
  38002. }
  38003. blendPass.setUniform('texture1', this._prevFrameTex);
  38004. blendPass.setUniform('texture2', sourceTex || this._sourceTex);
  38005. this._blendFb.attach(this._outputTex);
  38006. this._blendFb.bind(renderer);
  38007. blendPass.render(renderer);
  38008. this._blendFb.unbind(renderer);
  38009. if (!notOutput) {
  38010. this._outputPass.setUniform('texture', this._outputTex);
  38011. this._outputPass.render(renderer);
  38012. }
  38013. // Swap texture
  38014. var tmp = this._prevFrameTex;
  38015. this._prevFrameTex = this._outputTex;
  38016. this._outputTex = tmp;
  38017. this._frame++;
  38018. },
  38019. dispose: function (renderer) {
  38020. this._sourceFb.dispose(renderer);
  38021. this._blendFb.dispose(renderer);
  38022. this._prevFrameTex.dispose(renderer);
  38023. this._outputTex.dispose(renderer);
  38024. this._sourceTex.dispose(renderer);
  38025. this._outputPass.dispose(renderer);
  38026. this._blendPass.dispose(renderer);
  38027. }
  38028. };
  38029. /* harmony default export */ __webpack_exports__["a"] = (TemporalSuperSampling);
  38030. /***/
  38031. }),
  38032. /* 201 */
  38033. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  38034. "use strict";
  38035. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  38036. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  38037. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__geo3D_Geo3DModel__ = __webpack_require__(202);
  38038. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__geo3D_Geo3DView__ = __webpack_require__(203);
  38039. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__coord_geo3DCreator__ = __webpack_require__(98);
  38040. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerAction({
  38041. type: 'geo3DChangeCamera',
  38042. event: 'geo3dcamerachanged',
  38043. update: 'series:updateCamera'
  38044. }, function (payload, ecModel) {
  38045. ecModel.eachComponent({
  38046. mainType: 'geo3D', query: payload
  38047. }, function (componentModel) {
  38048. componentModel.setView(payload);
  38049. });
  38050. });
  38051. /***/
  38052. }),
  38053. /* 202 */
  38054. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  38055. "use strict";
  38056. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  38057. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  38058. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__common_componentViewControlMixin__ = __webpack_require__(44);
  38059. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__common_componentPostEffectMixin__ = __webpack_require__(28);
  38060. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__common_componentLightMixin__ = __webpack_require__(29);
  38061. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__common_componentShadingMixin__ = __webpack_require__(31);
  38062. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__coord_geo3D_geo3DModelMixin__ = __webpack_require__(96);
  38063. var Geo3DModel = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendComponentModel({
  38064. type: 'geo3D',
  38065. layoutMode: 'box',
  38066. coordinateSystem: null,
  38067. optionUpdated: function () {
  38068. var option = this.option;
  38069. option.regions = this.getFilledRegions(option.regions, option.map);
  38070. var dimensions = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.helper.completeDimensions(['value'], option.data, {
  38071. encodeDef: this.get('encode'),
  38072. dimsDef: this.get('dimensions')
  38073. });
  38074. var list = new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.List(dimensions, this);
  38075. list.initData(option.regions);
  38076. var regionModelMap = {};
  38077. list.each(function (idx) {
  38078. var name = list.getName(idx);
  38079. var itemModel = list.getItemModel(idx);
  38080. regionModelMap[name] = itemModel;
  38081. });
  38082. this._regionModelMap = regionModelMap;
  38083. this._data = list;
  38084. },
  38085. getData: function () {
  38086. return this._data;
  38087. },
  38088. getRegionModel: function (idx) {
  38089. var name = this.getData().getName(idx);
  38090. return this._regionModelMap[name] || new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.Model(null, this);
  38091. },
  38092. getRegionPolygonCoords: function (idx) {
  38093. var name = this.getData().getName(idx);
  38094. var region = this.coordinateSystem.getRegion(name);
  38095. return region ? region.geometries : [];
  38096. },
  38097. /**
  38098. * Format label
  38099. * @param {string} name Region name
  38100. * @param {string} [status='normal'] 'normal' or 'emphasis'
  38101. * @return {string}
  38102. */
  38103. getFormattedLabel: function (dataIndex, status) {
  38104. var name = this._data.getName(dataIndex);
  38105. var regionModel = this.getRegionModel(name);
  38106. var formatter = regionModel.get(status === 'normal' ? ['label', 'formatter'] : ['emphasis', 'label', 'formatter']);
  38107. if (formatter == null) {
  38108. formatter = regionModel.get(['label', 'formatter']);
  38109. }
  38110. var params = {
  38111. name: name
  38112. };
  38113. if (typeof formatter === 'function') {
  38114. params.status = status;
  38115. return formatter(params);
  38116. }
  38117. else if (typeof formatter === 'string') {
  38118. var serName = params.seriesName;
  38119. return formatter.replace('{a}', serName != null ? serName : '');
  38120. }
  38121. else {
  38122. return name;
  38123. }
  38124. },
  38125. defaultOption: {
  38126. // itemStyle: {},
  38127. // height,
  38128. // label: {}
  38129. // realisticMaterial
  38130. regions: []
  38131. }
  38132. });
  38133. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(Geo3DModel.prototype, __WEBPACK_IMPORTED_MODULE_5__coord_geo3D_geo3DModelMixin__["a" /* default */]);
  38134. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(Geo3DModel.prototype, __WEBPACK_IMPORTED_MODULE_1__common_componentViewControlMixin__["a" /* default */]);
  38135. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(Geo3DModel.prototype, __WEBPACK_IMPORTED_MODULE_2__common_componentPostEffectMixin__["a" /* default */]);
  38136. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(Geo3DModel.prototype, __WEBPACK_IMPORTED_MODULE_3__common_componentLightMixin__["a" /* default */]);
  38137. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(Geo3DModel.prototype, __WEBPACK_IMPORTED_MODULE_4__common_componentShadingMixin__["a" /* default */]);
  38138. /* unused harmony default export */ var _unused_webpack_default_export = (Geo3DModel);
  38139. /***/
  38140. }),
  38141. /* 203 */
  38142. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  38143. "use strict";
  38144. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__common_Geo3DBuilder__ = __webpack_require__(64);
  38145. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts__ = __webpack_require__(0);
  38146. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts__);
  38147. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__ = __webpack_require__(1);
  38148. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__util_OrbitControl__ = __webpack_require__(45);
  38149. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__common_SceneHelper__ = __webpack_require__(30);
  38150. /* unused harmony default export */ var _unused_webpack_default_export = (__WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default.a.extendComponentView({
  38151. type: 'geo3D',
  38152. __ecgl__: true,
  38153. init: function (ecModel, api) {
  38154. this._geo3DBuilder = new __WEBPACK_IMPORTED_MODULE_0__common_Geo3DBuilder__["a" /* default */](api);
  38155. this.groupGL = new __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__["a" /* default */].Node();
  38156. this._lightRoot = new __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__["a" /* default */].Node();
  38157. this._sceneHelper = new __WEBPACK_IMPORTED_MODULE_4__common_SceneHelper__["a" /* default */](this._lightRoot);
  38158. this._sceneHelper.initLight(this._lightRoot);
  38159. this._control = new __WEBPACK_IMPORTED_MODULE_3__util_OrbitControl__["a" /* default */]({
  38160. zr: api.getZr()
  38161. });
  38162. this._control.init();
  38163. },
  38164. render: function (geo3DModel, ecModel, api) {
  38165. this.groupGL.add(this._geo3DBuilder.rootNode);
  38166. var geo3D = geo3DModel.coordinateSystem;
  38167. if (!geo3D || !geo3D.viewGL) {
  38168. return;
  38169. }
  38170. // Always have light.
  38171. geo3D.viewGL.add(this._lightRoot);
  38172. if (geo3DModel.get('show')) {
  38173. geo3D.viewGL.add(this.groupGL);
  38174. }
  38175. else {
  38176. geo3D.viewGL.remove(this.groupGL);
  38177. }
  38178. var control = this._control;
  38179. control.setViewGL(geo3D.viewGL);
  38180. var viewControlModel = geo3DModel.getModel('viewControl');
  38181. control.setFromViewControlModel(viewControlModel, 0);
  38182. this._sceneHelper.setScene(geo3D.viewGL.scene);
  38183. this._sceneHelper.updateLight(geo3DModel);
  38184. // Set post effect
  38185. geo3D.viewGL.setPostEffect(geo3DModel.getModel('postEffect'), api);
  38186. geo3D.viewGL.setTemporalSuperSampling(geo3DModel.getModel('temporalSuperSampling'));
  38187. // Must update after geo3D.viewGL.setPostEffect
  38188. this._geo3DBuilder.update(geo3DModel, ecModel, api, 0, geo3DModel.getData().count());
  38189. var srgbDefineMethod = geo3D.viewGL.isLinearSpace() ? 'define' : 'undefine';
  38190. this._geo3DBuilder.rootNode.traverse(function (mesh) {
  38191. if (mesh.material) {
  38192. mesh.material[srgbDefineMethod]('fragment', 'SRGB_DECODE');
  38193. }
  38194. });
  38195. control.off('update');
  38196. control.on('update', function () {
  38197. api.dispatchAction({
  38198. type: 'geo3DChangeCamera',
  38199. alpha: control.getAlpha(),
  38200. beta: control.getBeta(),
  38201. distance: control.getDistance(),
  38202. center: control.getCenter(),
  38203. from: this.uid,
  38204. geo3DId: geo3DModel.id
  38205. });
  38206. });
  38207. control.update();
  38208. },
  38209. afterRender: function (geo3DModel, ecModel, api, layerGL) {
  38210. var renderer = layerGL.renderer;
  38211. this._sceneHelper.updateAmbientCubemap(renderer, geo3DModel, api);
  38212. this._sceneHelper.updateSkybox(renderer, geo3DModel, api);
  38213. },
  38214. dispose: function () {
  38215. this._control.dispose();
  38216. }
  38217. }));
  38218. /***/
  38219. }),
  38220. /* 204 */
  38221. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  38222. "use strict";
  38223. // https://github.com/mapbox/earcut/blob/master/src/earcut.js
  38224. /* harmony default export */ __webpack_exports__["a"] = (earcut);
  38225. function earcut(data, holeIndices, dim) {
  38226. dim = dim || 2;
  38227. var hasHoles = holeIndices && holeIndices.length,
  38228. outerLen = hasHoles ? holeIndices[0] * dim : data.length,
  38229. outerNode = linkedList(data, 0, outerLen, dim, true),
  38230. triangles = [];
  38231. if (!outerNode) return triangles;
  38232. var minX, minY, maxX, maxY, x, y, size;
  38233. if (hasHoles) outerNode = eliminateHoles(data, holeIndices, outerNode, dim);
  38234. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  38235. if (data.length > 80 * dim) {
  38236. minX = maxX = data[0];
  38237. minY = maxY = data[1];
  38238. for (var i = dim; i < outerLen; i += dim) {
  38239. x = data[i];
  38240. y = data[i + 1];
  38241. if (x < minX) minX = x;
  38242. if (y < minY) minY = y;
  38243. if (x > maxX) maxX = x;
  38244. if (y > maxY) maxY = y;
  38245. }
  38246. // minX, minY and size are later used to transform coords into integers for z-order calculation
  38247. size = Math.max(maxX - minX, maxY - minY);
  38248. }
  38249. earcutLinked(outerNode, triangles, dim, minX, minY, size);
  38250. return triangles;
  38251. }
  38252. // create a circular doubly linked list from polygon points in the specified winding order
  38253. function linkedList(data, start, end, dim, clockwise) {
  38254. var i, last;
  38255. if (clockwise === (signedArea(data, start, end, dim) > 0)) {
  38256. for (i = start; i < end; i += dim) last = insertNode(i, data[i], data[i + 1], last);
  38257. } else {
  38258. for (i = end - dim; i >= start; i -= dim) last = insertNode(i, data[i], data[i + 1], last);
  38259. }
  38260. if (last && equals(last, last.next)) {
  38261. removeNode(last);
  38262. last = last.next;
  38263. }
  38264. return last;
  38265. }
  38266. // eliminate colinear or duplicate points
  38267. function filterPoints(start, end) {
  38268. if (!start) return start;
  38269. if (!end) end = start;
  38270. var p = start,
  38271. again;
  38272. do {
  38273. again = false;
  38274. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  38275. removeNode(p);
  38276. p = end = p.prev;
  38277. if (p === p.next) return null;
  38278. again = true;
  38279. } else {
  38280. p = p.next;
  38281. }
  38282. } while (again || p !== end);
  38283. return end;
  38284. }
  38285. // main ear slicing loop which triangulates a polygon (given as a linked list)
  38286. function earcutLinked(ear, triangles, dim, minX, minY, size, pass) {
  38287. if (!ear) return;
  38288. // interlink polygon nodes in z-order
  38289. if (!pass && size) indexCurve(ear, minX, minY, size);
  38290. var stop = ear,
  38291. prev, next;
  38292. // iterate through ears, slicing them one by one
  38293. while (ear.prev !== ear.next) {
  38294. prev = ear.prev;
  38295. next = ear.next;
  38296. if (size ? isEarHashed(ear, minX, minY, size) : isEar(ear)) {
  38297. // cut off the triangle
  38298. triangles.push(prev.i / dim);
  38299. triangles.push(ear.i / dim);
  38300. triangles.push(next.i / dim);
  38301. removeNode(ear);
  38302. // skipping the next vertice leads to less sliver triangles
  38303. ear = next.next;
  38304. stop = next.next;
  38305. continue;
  38306. }
  38307. ear = next;
  38308. // if we looped through the whole remaining polygon and can't find any more ears
  38309. if (ear === stop) {
  38310. // try filtering points and slicing again
  38311. if (!pass) {
  38312. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, size, 1);
  38313. // if this didn't work, try curing all small self-intersections locally
  38314. } else if (pass === 1) {
  38315. ear = cureLocalIntersections(ear, triangles, dim);
  38316. earcutLinked(ear, triangles, dim, minX, minY, size, 2);
  38317. // as a last resort, try splitting the remaining polygon into two
  38318. } else if (pass === 2) {
  38319. splitEarcut(ear, triangles, dim, minX, minY, size);
  38320. }
  38321. break;
  38322. }
  38323. }
  38324. }
  38325. // check whether a polygon node forms a valid ear with adjacent nodes
  38326. function isEar(ear) {
  38327. var a = ear.prev,
  38328. b = ear,
  38329. c = ear.next;
  38330. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  38331. // now make sure we don't have other points inside the potential ear
  38332. var p = ear.next.next;
  38333. while (p !== ear.prev) {
  38334. if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  38335. area(p.prev, p, p.next) >= 0) return false;
  38336. p = p.next;
  38337. }
  38338. return true;
  38339. }
  38340. function isEarHashed(ear, minX, minY, size) {
  38341. var a = ear.prev,
  38342. b = ear,
  38343. c = ear.next;
  38344. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  38345. // triangle bbox; min & max are calculated like this for speed
  38346. var minTX = a.x < b.x ? (a.x < c.x ? a.x : c.x) : (b.x < c.x ? b.x : c.x),
  38347. minTY = a.y < b.y ? (a.y < c.y ? a.y : c.y) : (b.y < c.y ? b.y : c.y),
  38348. maxTX = a.x > b.x ? (a.x > c.x ? a.x : c.x) : (b.x > c.x ? b.x : c.x),
  38349. maxTY = a.y > b.y ? (a.y > c.y ? a.y : c.y) : (b.y > c.y ? b.y : c.y);
  38350. // z-order range for the current triangle bbox;
  38351. var minZ = zOrder(minTX, minTY, minX, minY, size),
  38352. maxZ = zOrder(maxTX, maxTY, minX, minY, size);
  38353. // first look for points inside the triangle in increasing z-order
  38354. var p = ear.nextZ;
  38355. while (p && p.z <= maxZ) {
  38356. if (p !== ear.prev && p !== ear.next &&
  38357. pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  38358. area(p.prev, p, p.next) >= 0) return false;
  38359. p = p.nextZ;
  38360. }
  38361. // then look for points in decreasing z-order
  38362. p = ear.prevZ;
  38363. while (p && p.z >= minZ) {
  38364. if (p !== ear.prev && p !== ear.next &&
  38365. pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  38366. area(p.prev, p, p.next) >= 0) return false;
  38367. p = p.prevZ;
  38368. }
  38369. return true;
  38370. }
  38371. // go through all polygon nodes and cure small local self-intersections
  38372. function cureLocalIntersections(start, triangles, dim) {
  38373. var p = start;
  38374. do {
  38375. var a = p.prev,
  38376. b = p.next.next;
  38377. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  38378. triangles.push(a.i / dim);
  38379. triangles.push(p.i / dim);
  38380. triangles.push(b.i / dim);
  38381. // remove two nodes involved
  38382. removeNode(p);
  38383. removeNode(p.next);
  38384. p = start = b;
  38385. }
  38386. p = p.next;
  38387. } while (p !== start);
  38388. return p;
  38389. }
  38390. // try splitting polygon into two and triangulate them independently
  38391. function splitEarcut(start, triangles, dim, minX, minY, size) {
  38392. // look for a valid diagonal that divides the polygon into two
  38393. var a = start;
  38394. do {
  38395. var b = a.next.next;
  38396. while (b !== a.prev) {
  38397. if (a.i !== b.i && isValidDiagonal(a, b)) {
  38398. // split the polygon in two by the diagonal
  38399. var c = splitPolygon(a, b);
  38400. // filter colinear points around the cuts
  38401. a = filterPoints(a, a.next);
  38402. c = filterPoints(c, c.next);
  38403. // run earcut on each half
  38404. earcutLinked(a, triangles, dim, minX, minY, size);
  38405. earcutLinked(c, triangles, dim, minX, minY, size);
  38406. return;
  38407. }
  38408. b = b.next;
  38409. }
  38410. a = a.next;
  38411. } while (a !== start);
  38412. }
  38413. // link every hole into the outer loop, producing a single-ring polygon without holes
  38414. function eliminateHoles(data, holeIndices, outerNode, dim) {
  38415. var queue = [],
  38416. i, len, start, end, list;
  38417. for (i = 0, len = holeIndices.length; i < len; i++) {
  38418. start = holeIndices[i] * dim;
  38419. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  38420. list = linkedList(data, start, end, dim, false);
  38421. if (list === list.next) list.steiner = true;
  38422. queue.push(getLeftmost(list));
  38423. }
  38424. queue.sort(compareX);
  38425. // process holes from left to right
  38426. for (i = 0; i < queue.length; i++) {
  38427. eliminateHole(queue[i], outerNode);
  38428. outerNode = filterPoints(outerNode, outerNode.next);
  38429. }
  38430. return outerNode;
  38431. }
  38432. function compareX(a, b) {
  38433. return a.x - b.x;
  38434. }
  38435. // find a bridge between vertices that connects hole with an outer ring and and link it
  38436. function eliminateHole(hole, outerNode) {
  38437. outerNode = findHoleBridge(hole, outerNode);
  38438. if (outerNode) {
  38439. var b = splitPolygon(outerNode, hole);
  38440. filterPoints(b, b.next);
  38441. }
  38442. }
  38443. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  38444. function findHoleBridge(hole, outerNode) {
  38445. var p = outerNode,
  38446. hx = hole.x,
  38447. hy = hole.y,
  38448. qx = -Infinity,
  38449. m;
  38450. // find a segment intersected by a ray from the hole's leftmost point to the left;
  38451. // segment's endpoint with lesser x will be potential connection point
  38452. do {
  38453. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  38454. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  38455. if (x <= hx && x > qx) {
  38456. qx = x;
  38457. if (x === hx) {
  38458. if (hy === p.y) return p;
  38459. if (hy === p.next.y) return p.next;
  38460. }
  38461. m = p.x < p.next.x ? p : p.next;
  38462. }
  38463. }
  38464. p = p.next;
  38465. } while (p !== outerNode);
  38466. if (!m) return null;
  38467. if (hx === qx) return m.prev; // hole touches outer segment; pick lower endpoint
  38468. // look for points inside the triangle of hole point, segment intersection and endpoint;
  38469. // if there are no points found, we have a valid connection;
  38470. // otherwise choose the point of the minimum angle with the ray as connection point
  38471. var stop = m,
  38472. mx = m.x,
  38473. my = m.y,
  38474. tanMin = Infinity,
  38475. tan;
  38476. p = m.next;
  38477. while (p !== stop) {
  38478. if (hx >= p.x && p.x >= mx && hx !== p.x &&
  38479. pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
  38480. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  38481. if ((tan < tanMin || (tan === tanMin && p.x > m.x)) && locallyInside(p, hole)) {
  38482. m = p;
  38483. tanMin = tan;
  38484. }
  38485. }
  38486. p = p.next;
  38487. }
  38488. return m;
  38489. }
  38490. // interlink polygon nodes in z-order
  38491. function indexCurve(start, minX, minY, size) {
  38492. var p = start;
  38493. do {
  38494. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, size);
  38495. p.prevZ = p.prev;
  38496. p.nextZ = p.next;
  38497. p = p.next;
  38498. } while (p !== start);
  38499. p.prevZ.nextZ = null;
  38500. p.prevZ = null;
  38501. sortLinked(p);
  38502. }
  38503. // Simon Tatham's linked list merge sort algorithm
  38504. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  38505. function sortLinked(list) {
  38506. var i, p, q, e, tail, numMerges, pSize, qSize,
  38507. inSize = 1;
  38508. do {
  38509. p = list;
  38510. list = null;
  38511. tail = null;
  38512. numMerges = 0;
  38513. while (p) {
  38514. numMerges++;
  38515. q = p;
  38516. pSize = 0;
  38517. for (i = 0; i < inSize; i++) {
  38518. pSize++;
  38519. q = q.nextZ;
  38520. if (!q) break;
  38521. }
  38522. qSize = inSize;
  38523. while (pSize > 0 || (qSize > 0 && q)) {
  38524. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  38525. e = p;
  38526. p = p.nextZ;
  38527. pSize--;
  38528. } else {
  38529. e = q;
  38530. q = q.nextZ;
  38531. qSize--;
  38532. }
  38533. if (tail) tail.nextZ = e;
  38534. else list = e;
  38535. e.prevZ = tail;
  38536. tail = e;
  38537. }
  38538. p = q;
  38539. }
  38540. tail.nextZ = null;
  38541. inSize *= 2;
  38542. } while (numMerges > 1);
  38543. return list;
  38544. }
  38545. // z-order of a point given coords and size of the data bounding box
  38546. function zOrder(x, y, minX, minY, size) {
  38547. // coords are transformed into non-negative 15-bit integer range
  38548. x = 32767 * (x - minX) / size;
  38549. y = 32767 * (y - minY) / size;
  38550. x = (x | (x << 8)) & 0x00FF00FF;
  38551. x = (x | (x << 4)) & 0x0F0F0F0F;
  38552. x = (x | (x << 2)) & 0x33333333;
  38553. x = (x | (x << 1)) & 0x55555555;
  38554. y = (y | (y << 8)) & 0x00FF00FF;
  38555. y = (y | (y << 4)) & 0x0F0F0F0F;
  38556. y = (y | (y << 2)) & 0x33333333;
  38557. y = (y | (y << 1)) & 0x55555555;
  38558. return x | (y << 1);
  38559. }
  38560. // find the leftmost node of a polygon ring
  38561. function getLeftmost(start) {
  38562. var p = start,
  38563. leftmost = start;
  38564. do {
  38565. if (p.x < leftmost.x) leftmost = p;
  38566. p = p.next;
  38567. } while (p !== start);
  38568. return leftmost;
  38569. }
  38570. // check if a point lies within a convex triangle
  38571. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  38572. return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 &&
  38573. (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 &&
  38574. (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
  38575. }
  38576. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  38577. function isValidDiagonal(a, b) {
  38578. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) &&
  38579. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b);
  38580. }
  38581. // signed area of a triangle
  38582. function area(p, q, r) {
  38583. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  38584. }
  38585. // check if two points are equal
  38586. function equals(p1, p2) {
  38587. return p1.x === p2.x && p1.y === p2.y;
  38588. }
  38589. // check if two segments intersect
  38590. function intersects(p1, q1, p2, q2) {
  38591. if ((equals(p1, q1) && equals(p2, q2)) ||
  38592. (equals(p1, q2) && equals(p2, q1))) return true;
  38593. return area(p1, q1, p2) > 0 !== area(p1, q1, q2) > 0 &&
  38594. area(p2, q2, p1) > 0 !== area(p2, q2, q1) > 0;
  38595. }
  38596. // check if a polygon diagonal intersects any polygon segments
  38597. function intersectsPolygon(a, b) {
  38598. var p = a;
  38599. do {
  38600. if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  38601. intersects(p, p.next, a, b)) return true;
  38602. p = p.next;
  38603. } while (p !== a);
  38604. return false;
  38605. }
  38606. // check if a polygon diagonal is locally inside the polygon
  38607. function locallyInside(a, b) {
  38608. return area(a.prev, a, a.next) < 0 ?
  38609. area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 :
  38610. area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
  38611. }
  38612. // check if the middle point of a polygon diagonal is inside the polygon
  38613. function middleInside(a, b) {
  38614. var p = a,
  38615. inside = false,
  38616. px = (a.x + b.x) / 2,
  38617. py = (a.y + b.y) / 2;
  38618. do {
  38619. if (((p.y > py) !== (p.next.y > py)) && p.next.y !== p.y &&
  38620. (px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x))
  38621. inside = !inside;
  38622. p = p.next;
  38623. } while (p !== a);
  38624. return inside;
  38625. }
  38626. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  38627. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  38628. function splitPolygon(a, b) {
  38629. var a2 = new Node(a.i, a.x, a.y),
  38630. b2 = new Node(b.i, b.x, b.y),
  38631. an = a.next,
  38632. bp = b.prev;
  38633. a.next = b;
  38634. b.prev = a;
  38635. a2.next = an;
  38636. an.prev = a2;
  38637. b2.next = a2;
  38638. a2.prev = b2;
  38639. bp.next = b2;
  38640. b2.prev = bp;
  38641. return b2;
  38642. }
  38643. // create a node and optionally link it with previous one (in a circular doubly linked list)
  38644. function insertNode(i, x, y, last) {
  38645. var p = new Node(i, x, y);
  38646. if (!last) {
  38647. p.prev = p;
  38648. p.next = p;
  38649. } else {
  38650. p.next = last.next;
  38651. p.prev = last;
  38652. last.next.prev = p;
  38653. last.next = p;
  38654. }
  38655. return p;
  38656. }
  38657. function removeNode(p) {
  38658. p.next.prev = p.prev;
  38659. p.prev.next = p.next;
  38660. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  38661. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  38662. }
  38663. function Node(i, x, y) {
  38664. // vertice index in coordinates array
  38665. this.i = i;
  38666. // vertex coordinates
  38667. this.x = x;
  38668. this.y = y;
  38669. // previous and next vertice nodes in a polygon ring
  38670. this.prev = null;
  38671. this.next = null;
  38672. // z-order curve value
  38673. this.z = null;
  38674. // previous and next nodes in z-order
  38675. this.prevZ = null;
  38676. this.nextZ = null;
  38677. // indicates whether this is a steiner point
  38678. this.steiner = false;
  38679. }
  38680. // return a percentage difference between the polygon area and its triangulation area;
  38681. // used to verify correctness of triangulation
  38682. earcut.deviation = function (data, holeIndices, dim, triangles) {
  38683. var hasHoles = holeIndices && holeIndices.length;
  38684. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  38685. var polygonArea = Math.abs(signedArea(data, 0, outerLen, dim));
  38686. if (hasHoles) {
  38687. for (var i = 0, len = holeIndices.length; i < len; i++) {
  38688. var start = holeIndices[i] * dim;
  38689. var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  38690. polygonArea -= Math.abs(signedArea(data, start, end, dim));
  38691. }
  38692. }
  38693. var trianglesArea = 0;
  38694. for (i = 0; i < triangles.length; i += 3) {
  38695. var a = triangles[i] * dim;
  38696. var b = triangles[i + 1] * dim;
  38697. var c = triangles[i + 2] * dim;
  38698. trianglesArea += Math.abs(
  38699. (data[a] - data[c]) * (data[b + 1] - data[a + 1]) -
  38700. (data[a] - data[b]) * (data[c + 1] - data[a + 1]));
  38701. }
  38702. return polygonArea === 0 && trianglesArea === 0 ? 0 :
  38703. Math.abs((trianglesArea - polygonArea) / polygonArea);
  38704. };
  38705. function signedArea(data, start, end, dim) {
  38706. var sum = 0;
  38707. for (var i = start, j = end - dim; i < end; i += dim) {
  38708. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  38709. j = i;
  38710. }
  38711. return sum;
  38712. }
  38713. /***/
  38714. }),
  38715. /* 205 */
  38716. /***/ (function (module, exports, __webpack_require__) {
  38717. var zrUtil = __webpack_require__(13);
  38718. /*
  38719. * Licensed to the Apache Software Foundation (ASF) under one
  38720. * or more contributor license agreements. See the NOTICE file
  38721. * distributed with this work for additional information
  38722. * regarding copyright ownership. The ASF licenses this file
  38723. * to you under the Apache License, Version 2.0 (the
  38724. * "License"); you may not use this file except in compliance
  38725. * with the License. You may obtain a copy of the License at
  38726. *
  38727. * http://www.apache.org/licenses/LICENSE-2.0
  38728. *
  38729. * Unless required by applicable law or agreed to in writing,
  38730. * software distributed under the License is distributed on an
  38731. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38732. * KIND, either express or implied. See the License for the
  38733. * specific language governing permissions and limitations
  38734. * under the License.
  38735. */
  38736. var coordsOffsetMap = {
  38737. '南海诸岛': [32, 80],
  38738. // 全国
  38739. '广东': [0, -10],
  38740. '香港': [10, 5],
  38741. '澳门': [-10, 10],
  38742. //'北京': [-10, 0],
  38743. '天津': [5, 5]
  38744. };
  38745. function _default(geo) {
  38746. zrUtil.each(geo.regions, function (region) {
  38747. var coordFix = coordsOffsetMap[region.name];
  38748. if (coordFix) {
  38749. var cp = region.center;
  38750. cp[0] += coordFix[0] / 10.5;
  38751. cp[1] += -coordFix[1] / (10.5 / 0.75);
  38752. }
  38753. });
  38754. }
  38755. module.exports = _default;
  38756. /***/
  38757. }),
  38758. /* 206 */
  38759. /***/ (function (module, exports, __webpack_require__) {
  38760. var zrUtil = __webpack_require__(13);
  38761. /*
  38762. * Licensed to the Apache Software Foundation (ASF) under one
  38763. * or more contributor license agreements. See the NOTICE file
  38764. * distributed with this work for additional information
  38765. * regarding copyright ownership. The ASF licenses this file
  38766. * to you under the Apache License, Version 2.0 (the
  38767. * "License"); you may not use this file except in compliance
  38768. * with the License. You may obtain a copy of the License at
  38769. *
  38770. * http://www.apache.org/licenses/LICENSE-2.0
  38771. *
  38772. * Unless required by applicable law or agreed to in writing,
  38773. * software distributed under the License is distributed on an
  38774. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38775. * KIND, either express or implied. See the License for the
  38776. * specific language governing permissions and limitations
  38777. * under the License.
  38778. */
  38779. var geoCoordMap = {
  38780. 'Russia': [100, 60],
  38781. 'United States': [-99, 38],
  38782. 'United States of America': [-99, 38]
  38783. };
  38784. function _default(geo) {
  38785. zrUtil.each(geo.regions, function (region) {
  38786. var geoCoord = geoCoordMap[region.name];
  38787. if (geoCoord) {
  38788. var cp = region.center;
  38789. cp[0] = geoCoord[0];
  38790. cp[1] = geoCoord[1];
  38791. }
  38792. });
  38793. }
  38794. module.exports = _default;
  38795. /***/
  38796. }),
  38797. /* 207 */
  38798. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  38799. "use strict";
  38800. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  38801. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  38802. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__globe_GlobeModel__ = __webpack_require__(208);
  38803. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__globe_GlobeView__ = __webpack_require__(209);
  38804. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__coord_globeCreator__ = __webpack_require__(211);
  38805. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerAction({
  38806. type: 'globeChangeCamera',
  38807. event: 'globecamerachanged',
  38808. update: 'series:updateCamera'
  38809. }, function (payload, ecModel) {
  38810. ecModel.eachComponent({
  38811. mainType: 'globe', query: payload
  38812. }, function (componentModel) {
  38813. componentModel.setView(payload);
  38814. });
  38815. });
  38816. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerAction({
  38817. type: 'globeUpdateDisplacment',
  38818. event: 'globedisplacementupdated',
  38819. update: 'update'
  38820. }, function (payload, ecModel) {
  38821. // Noop
  38822. });
  38823. /***/
  38824. }),
  38825. /* 208 */
  38826. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  38827. "use strict";
  38828. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  38829. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  38830. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__common_componentViewControlMixin__ = __webpack_require__(44);
  38831. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__common_componentPostEffectMixin__ = __webpack_require__(28);
  38832. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__common_componentLightMixin__ = __webpack_require__(29);
  38833. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__common_componentShadingMixin__ = __webpack_require__(31);
  38834. function defaultId(option, idx) {
  38835. option.id = option.id || option.name || (idx + '');
  38836. }
  38837. var GlobeModel = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendComponentModel({
  38838. type: 'globe',
  38839. layoutMode: 'box',
  38840. coordinateSystem: null,
  38841. init: function () {
  38842. GlobeModel.superApply(this, 'init', arguments);
  38843. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.each(this.option.layers, function (layerOption, idx) {
  38844. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(layerOption, this.defaultLayerOption);
  38845. defaultId(layerOption, idx);
  38846. }, this);
  38847. },
  38848. mergeOption: function (option) {
  38849. // TODO test
  38850. var oldLayers = this.option.layers;
  38851. this.option.layers = null;
  38852. GlobeModel.superApply(this, 'mergeOption', arguments);
  38853. function createLayerMap(layers) {
  38854. return __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.reduce(layers, function (obj, layerOption, idx) {
  38855. defaultId(layerOption, idx);
  38856. obj[layerOption.id] = layerOption;
  38857. return obj;
  38858. }, {});
  38859. }
  38860. if (oldLayers && oldLayers.length) {
  38861. var newLayerMap = createLayerMap(option.layers);
  38862. var oldLayerMap = createLayerMap(oldLayers);
  38863. for (var id in newLayerMap) {
  38864. if (oldLayerMap[id]) {
  38865. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(oldLayerMap[id], newLayerMap[id], true);
  38866. }
  38867. else {
  38868. oldLayers.push(option.layers[id]);
  38869. }
  38870. }
  38871. // Copy back
  38872. this.option.layers = oldLayers;
  38873. }
  38874. // else overwrite
  38875. // Set default
  38876. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.each(this.option.layers, function (layerOption) {
  38877. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(layerOption, this.defaultLayerOption);
  38878. }, this);
  38879. },
  38880. optionUpdated: function () {
  38881. this.updateDisplacementHash();
  38882. },
  38883. defaultLayerOption: {
  38884. show: true,
  38885. type: 'overlay'
  38886. },
  38887. defaultOption: {
  38888. show: true,
  38889. zlevel: -10,
  38890. // Layout used for viewport
  38891. left: 0,
  38892. top: 0,
  38893. width: '100%',
  38894. height: '100%',
  38895. environment: 'auto',
  38896. baseColor: '#fff',
  38897. // Base albedo texture
  38898. baseTexture: '',
  38899. // Height texture for bump mapping and vertex displacement
  38900. heightTexture: '',
  38901. // Texture for vertex displacement, default use heightTexture
  38902. displacementTexture: '',
  38903. // Scale of vertex displacement, available only if displacementTexture is set.
  38904. displacementScale: 0,
  38905. // Detail of displacement. 'low', 'medium', 'high', 'ultra'
  38906. displacementQuality: 'medium',
  38907. // Globe radius
  38908. globeRadius: 100,
  38909. // Globe outer radius. Which is max of altitude.
  38910. globeOuterRadius: 150,
  38911. // Shading of globe
  38912. shading: 'lambert',
  38913. // Extend light
  38914. light: {
  38915. // Main sun light
  38916. main: {
  38917. // Time, default it will use system time
  38918. time: ''
  38919. }
  38920. },
  38921. // light
  38922. // postEffect
  38923. // temporalSuperSampling
  38924. viewControl: {
  38925. autoRotate: true,
  38926. panSensitivity: 0,
  38927. targetCoord: null
  38928. },
  38929. // {
  38930. // show: true,
  38931. // name: 'cloud',
  38932. // type: 'overlay',
  38933. // shading: 'lambert',
  38934. // distance: 10,
  38935. // texture: ''
  38936. // }
  38937. // {
  38938. // type: 'blend',
  38939. // blendTo: 'albedo'
  38940. // blendType: 'source-over'
  38941. // }
  38942. layers: []
  38943. },
  38944. setDisplacementData: function (data, width, height) {
  38945. this.displacementData = data;
  38946. this.displacementWidth = width;
  38947. this.displacementHeight = height;
  38948. },
  38949. getDisplacementTexture: function () {
  38950. return this.get('displacementTexture') || this.get('heightTexture');
  38951. },
  38952. getDisplacemenScale: function () {
  38953. var displacementTexture = this.getDisplacementTexture();
  38954. var displacementScale = this.get('displacementScale');
  38955. if (!displacementTexture || displacementTexture === 'none') {
  38956. displacementScale = 0;
  38957. }
  38958. return displacementScale;
  38959. },
  38960. hasDisplacement: function () {
  38961. return this.getDisplacemenScale() > 0;
  38962. },
  38963. _displacementChanged: true,
  38964. _displacementScale: 0,
  38965. updateDisplacementHash: function () {
  38966. var displacementTexture = this.getDisplacementTexture();
  38967. var displacementScale = this.getDisplacemenScale();
  38968. this._displacementChanged =
  38969. this._displacementTexture !== displacementTexture
  38970. || this._displacementScale !== displacementScale;
  38971. this._displacementTexture = displacementTexture;
  38972. this._displacementScale = displacementScale;
  38973. },
  38974. isDisplacementChanged: function () {
  38975. return this._displacementChanged;
  38976. }
  38977. });
  38978. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(GlobeModel.prototype, __WEBPACK_IMPORTED_MODULE_1__common_componentViewControlMixin__["a" /* default */]);
  38979. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(GlobeModel.prototype, __WEBPACK_IMPORTED_MODULE_2__common_componentPostEffectMixin__["a" /* default */]);
  38980. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(GlobeModel.prototype, __WEBPACK_IMPORTED_MODULE_3__common_componentLightMixin__["a" /* default */]);
  38981. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(GlobeModel.prototype, __WEBPACK_IMPORTED_MODULE_4__common_componentShadingMixin__["a" /* default */]);
  38982. /* unused harmony default export */ var _unused_webpack_default_export = (GlobeModel);
  38983. /***/
  38984. }),
  38985. /* 209 */
  38986. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  38987. "use strict";
  38988. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  38989. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  38990. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__ = __webpack_require__(1);
  38991. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_OrbitControl__ = __webpack_require__(45);
  38992. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__common_SceneHelper__ = __webpack_require__(30);
  38993. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__util_sunCalc__ = __webpack_require__(210);
  38994. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__util_retrieve__ = __webpack_require__(2);
  38995. /* unused harmony default export */ var _unused_webpack_default_export = (__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendComponentView({
  38996. type: 'globe',
  38997. __ecgl__: true,
  38998. _displacementScale: 0,
  38999. init: function (ecModel, api) {
  39000. this.groupGL = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Node();
  39001. /**
  39002. * @type {clay.geometry.Sphere}
  39003. * @private
  39004. */
  39005. this._sphereGeometry = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].SphereGeometry({
  39006. widthSegments: 200,
  39007. heightSegments: 100,
  39008. dynamic: true
  39009. });
  39010. this._overlayGeometry = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].SphereGeometry({
  39011. widthSegments: 80,
  39012. heightSegments: 40
  39013. });
  39014. /**
  39015. * @type {clay.geometry.Plane}
  39016. */
  39017. this._planeGeometry = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].PlaneGeometry();
  39018. /**
  39019. * @type {clay.geometry.Mesh}
  39020. */
  39021. this._earthMesh = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh({
  39022. renderNormal: true
  39023. });
  39024. this._lightRoot = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Node();
  39025. this._sceneHelper = new __WEBPACK_IMPORTED_MODULE_3__common_SceneHelper__["a" /* default */]();
  39026. this._sceneHelper.initLight(this._lightRoot);
  39027. this.groupGL.add(this._earthMesh);
  39028. this._control = new __WEBPACK_IMPORTED_MODULE_2__util_OrbitControl__["a" /* default */]({
  39029. zr: api.getZr()
  39030. });
  39031. this._control.init();
  39032. this._layerMeshes = {};
  39033. },
  39034. render: function (globeModel, ecModel, api) {
  39035. var coordSys = globeModel.coordinateSystem;
  39036. var shading = globeModel.get('shading');
  39037. // Always have light.
  39038. coordSys.viewGL.add(this._lightRoot);
  39039. if (globeModel.get('show')) {
  39040. // Add self to scene;
  39041. coordSys.viewGL.add(this.groupGL);
  39042. }
  39043. else {
  39044. coordSys.viewGL.remove(this.groupGL);
  39045. }
  39046. this._sceneHelper.setScene(coordSys.viewGL.scene);
  39047. // Set post effect
  39048. coordSys.viewGL.setPostEffect(globeModel.getModel('postEffect'), api);
  39049. coordSys.viewGL.setTemporalSuperSampling(globeModel.getModel('temporalSuperSampling'));
  39050. var earthMesh = this._earthMesh;
  39051. earthMesh.geometry = this._sphereGeometry;
  39052. var shadingPrefix = 'ecgl.' + shading;
  39053. if (!earthMesh.material || earthMesh.material.shader.name !== shadingPrefix) {
  39054. earthMesh.material = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].createMaterial(shadingPrefix);
  39055. }
  39056. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].setMaterialFromModel(
  39057. shading, earthMesh.material, globeModel, api
  39058. );
  39059. ['roughnessMap', 'metalnessMap', 'detailMap', 'normalMap'].forEach(function (texName) {
  39060. var texture = earthMesh.material.get(texName);
  39061. if (texture) {
  39062. texture.flipY = false;
  39063. }
  39064. })
  39065. earthMesh.material.set('color', __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(
  39066. globeModel.get('baseColor')
  39067. ));
  39068. // shrink a little
  39069. var scale = coordSys.radius * 0.99;
  39070. earthMesh.scale.set(scale, scale, scale);
  39071. var diffuseTexture = earthMesh.material.setTextureImage('diffuseMap', globeModel.get('baseTexture'), api, {
  39072. flipY: false,
  39073. anisotropic: 8
  39074. });
  39075. if (diffuseTexture && diffuseTexture.surface) {
  39076. diffuseTexture.surface.attachToMesh(earthMesh);
  39077. }
  39078. // Update bump map
  39079. var bumpTexture = earthMesh.material.setTextureImage('bumpMap', globeModel.get('heightTexture'), api, {
  39080. flipY: false,
  39081. anisotropic: 8
  39082. });
  39083. if (bumpTexture && bumpTexture.surface) {
  39084. bumpTexture.surface.attachToMesh(earthMesh);
  39085. }
  39086. earthMesh.material[globeModel.get('postEffect.enable') ? 'define' : 'undefine']('fragment', 'SRGB_DECODE');
  39087. this._updateLight(globeModel, api);
  39088. this._displaceVertices(globeModel, api);
  39089. this._updateViewControl(globeModel, api);
  39090. this._updateLayers(globeModel, api);
  39091. },
  39092. afterRender: function (globeModel, ecModel, api, layerGL) {
  39093. // Create ambient cubemap after render because we need to know the renderer.
  39094. // TODO
  39095. var renderer = layerGL.renderer;
  39096. this._sceneHelper.updateAmbientCubemap(renderer, globeModel, api);
  39097. this._sceneHelper.updateSkybox(renderer, globeModel, api);
  39098. },
  39099. _updateLayers: function (globeModel, api) {
  39100. var coordSys = globeModel.coordinateSystem;
  39101. var layers = globeModel.get('layers');
  39102. var lastDistance = coordSys.radius;
  39103. var layerDiffuseTextures = [];
  39104. var layerDiffuseIntensity = [];
  39105. var layerEmissiveTextures = [];
  39106. var layerEmissionIntensity = [];
  39107. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.each(layers, function (layerOption) {
  39108. var layerModel = new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.Model(layerOption);
  39109. var layerType = layerModel.get('type');
  39110. var texture = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].loadTexture(layerModel.get('texture'), api, {
  39111. flipY: false,
  39112. anisotropic: 8
  39113. });
  39114. if (texture.surface) {
  39115. texture.surface.attachToMesh(this._earthMesh);
  39116. }
  39117. if (layerType === 'blend') {
  39118. var blendTo = layerModel.get('blendTo');
  39119. var intensity = __WEBPACK_IMPORTED_MODULE_5__util_retrieve__["a" /* default */].firstNotNull(layerModel.get('intensity'), 1.0);
  39120. if (blendTo === 'emission') {
  39121. layerEmissiveTextures.push(texture);
  39122. layerEmissionIntensity.push(intensity);
  39123. }
  39124. else { // Default is albedo
  39125. layerDiffuseTextures.push(texture);
  39126. layerDiffuseIntensity.push(intensity);
  39127. }
  39128. }
  39129. else { // Default use overlay
  39130. var id = layerModel.get('id');
  39131. var overlayMesh = this._layerMeshes[id];
  39132. if (!overlayMesh) {
  39133. overlayMesh = this._layerMeshes[id] = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh({
  39134. geometry: this._overlayGeometry,
  39135. castShadow: false,
  39136. ignorePicking: true
  39137. });
  39138. }
  39139. var shading = layerModel.get('shading');
  39140. if (shading === 'lambert') {
  39141. overlayMesh.material = overlayMesh.__lambertMaterial || new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Material({
  39142. autoUpdateTextureStatus: false,
  39143. shader: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].createShader('ecgl.lambert'),
  39144. transparent: true,
  39145. depthMask: false
  39146. });
  39147. overlayMesh.__lambertMaterial = overlayMesh.material;
  39148. }
  39149. else { // color
  39150. overlayMesh.material = overlayMesh.__colorMaterial || new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Material({
  39151. autoUpdateTextureStatus: false,
  39152. shader: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].createShader('ecgl.color'),
  39153. transparent: true,
  39154. depthMask: false
  39155. });
  39156. overlayMesh.__colorMaterial = overlayMesh.material;
  39157. }
  39158. // overlay should be transparent if texture is not loaded yet.
  39159. overlayMesh.material.enableTexture('diffuseMap');
  39160. var distance = layerModel.get('distance');
  39161. // Based on distance of last layer
  39162. var radius = lastDistance + (distance == null ? coordSys.radius / 100 : distance);
  39163. overlayMesh.scale.set(radius, radius, radius);
  39164. lastDistance = radius;
  39165. // FIXME Exists blink.
  39166. var blankTexture = this._blankTexture || (this._blankTexture = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].createBlankTexture('rgba(255, 255, 255, 0)'));
  39167. overlayMesh.material.set('diffuseMap', blankTexture);
  39168. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].loadTexture(layerModel.get('texture'), api, {
  39169. flipY: false,
  39170. anisotropic: 8
  39171. }, function (texture) {
  39172. if (texture.surface) {
  39173. texture.surface.attachToMesh(overlayMesh);
  39174. }
  39175. overlayMesh.material.set('diffuseMap', texture);
  39176. api.getZr().refresh();
  39177. });
  39178. layerModel.get('show') ? this.groupGL.add(overlayMesh) : this.groupGL.remove(overlayMesh);
  39179. }
  39180. }, this);
  39181. var earthMaterial = this._earthMesh.material;
  39182. earthMaterial.define('fragment', 'LAYER_DIFFUSEMAP_COUNT', layerDiffuseTextures.length);
  39183. earthMaterial.define('fragment', 'LAYER_EMISSIVEMAP_COUNT', layerEmissiveTextures.length);
  39184. earthMaterial.set('layerDiffuseMap', layerDiffuseTextures);
  39185. earthMaterial.set('layerDiffuseIntensity', layerDiffuseIntensity);
  39186. earthMaterial.set('layerEmissiveMap', layerEmissiveTextures);
  39187. earthMaterial.set('layerEmissionIntensity', layerEmissionIntensity);
  39188. var debugWireframeModel = globeModel.getModel('debug.wireframe');
  39189. if (debugWireframeModel.get('show')) {
  39190. earthMaterial.define('both', 'WIREFRAME_TRIANGLE');
  39191. var color = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(
  39192. debugWireframeModel.get('lineStyle.color') || 'rgba(0,0,0,0.5)'
  39193. );
  39194. var width = __WEBPACK_IMPORTED_MODULE_5__util_retrieve__["a" /* default */].firstNotNull(
  39195. debugWireframeModel.get('lineStyle.width'), 1
  39196. );
  39197. earthMaterial.set('wireframeLineWidth', width);
  39198. earthMaterial.set('wireframeLineColor', color);
  39199. }
  39200. else {
  39201. earthMaterial.undefine('both', 'WIREFRAME_TRIANGLE');
  39202. }
  39203. },
  39204. _updateViewControl: function (globeModel, api) {
  39205. var coordSys = globeModel.coordinateSystem;
  39206. // Update camera
  39207. var viewControlModel = globeModel.getModel('viewControl');
  39208. var camera = coordSys.viewGL.camera;
  39209. var self = this;
  39210. function makeAction() {
  39211. return {
  39212. type: 'globeChangeCamera',
  39213. alpha: control.getAlpha(),
  39214. beta: control.getBeta(),
  39215. distance: control.getDistance() - coordSys.radius,
  39216. center: control.getCenter(),
  39217. from: self.uid,
  39218. globeId: globeModel.id
  39219. };
  39220. }
  39221. // Update control
  39222. var control = this._control;
  39223. control.setViewGL(coordSys.viewGL);
  39224. var coord = viewControlModel.get('targetCoord');
  39225. var alpha, beta;
  39226. if (coord != null) {
  39227. beta = coord[0] + 90;
  39228. alpha = coord[1];
  39229. }
  39230. control.setFromViewControlModel(viewControlModel, {
  39231. baseDistance: coordSys.radius,
  39232. alpha: alpha,
  39233. beta: beta
  39234. });
  39235. control.off('update');
  39236. control.on('update', function () {
  39237. api.dispatchAction(makeAction());
  39238. });
  39239. },
  39240. _displaceVertices: function (globeModel, api) {
  39241. var displacementQuality = globeModel.get('displacementQuality');
  39242. var showDebugWireframe = globeModel.get('debug.wireframe.show');
  39243. var globe = globeModel.coordinateSystem;
  39244. if (!globeModel.isDisplacementChanged()
  39245. && displacementQuality === this._displacementQuality
  39246. && showDebugWireframe === this._showDebugWireframe
  39247. ) {
  39248. return;
  39249. }
  39250. this._displacementQuality = displacementQuality;
  39251. this._showDebugWireframe = showDebugWireframe;
  39252. var geometry = this._sphereGeometry;
  39253. var widthSegments = ({
  39254. low: 100,
  39255. medium: 200,
  39256. high: 400,
  39257. ultra: 800
  39258. })[displacementQuality] || 200;
  39259. var heightSegments = widthSegments / 2;
  39260. if (geometry.widthSegments !== widthSegments || showDebugWireframe) {
  39261. geometry.widthSegments = widthSegments;
  39262. geometry.heightSegments = heightSegments;
  39263. geometry.build();
  39264. }
  39265. this._doDisplaceVertices(geometry, globe);
  39266. if (showDebugWireframe) {
  39267. geometry.generateBarycentric();
  39268. }
  39269. },
  39270. _doDisplaceVertices: function (geometry, globe) {
  39271. var positionArr = geometry.attributes.position.value;
  39272. var uvArr = geometry.attributes.texcoord0.value;
  39273. var originalPositionArr = geometry.__originalPosition;
  39274. if (!originalPositionArr || originalPositionArr.length !== positionArr.length) {
  39275. originalPositionArr = new Float32Array(positionArr.length);
  39276. originalPositionArr.set(positionArr);
  39277. geometry.__originalPosition = originalPositionArr;
  39278. }
  39279. var width = globe.displacementWidth;
  39280. var height = globe.displacementHeight;
  39281. var data = globe.displacementData;
  39282. for (var i = 0; i < geometry.vertexCount; i++) {
  39283. var i3 = i * 3;
  39284. var i2 = i * 2;
  39285. var x = originalPositionArr[i3 + 1];
  39286. var y = originalPositionArr[i3 + 2];
  39287. var z = originalPositionArr[i3 + 3];
  39288. var u = uvArr[i2++];
  39289. var v = uvArr[i2++];
  39290. var j = Math.round(u * (width - 1));
  39291. var k = Math.round(v * (height - 1));
  39292. var idx = k * width + j;
  39293. var scale = data ? data[idx] : 0;
  39294. positionArr[i3 + 1] = x + x * scale;
  39295. positionArr[i3 + 2] = y + y * scale;
  39296. positionArr[i3 + 3] = z + z * scale;
  39297. }
  39298. geometry.generateVertexNormals();
  39299. geometry.dirty();
  39300. geometry.updateBoundingBox();
  39301. },
  39302. _updateLight: function (globeModel, api) {
  39303. var earthMesh = this._earthMesh;
  39304. this._sceneHelper.updateLight(globeModel);
  39305. var mainLight = this._sceneHelper.mainLight;
  39306. // Put sun in the right position
  39307. var time = globeModel.get('light.main.time') || new Date();
  39308. // http://en.wikipedia.org/wiki/Azimuth
  39309. var pos = __WEBPACK_IMPORTED_MODULE_4__util_sunCalc__["a" /* default */].getPosition(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.number.parseDate(time), 0, 0);
  39310. var r0 = Math.cos(pos.altitude);
  39311. // FIXME How to calculate the y ?
  39312. mainLight.position.y = -r0 * Math.cos(pos.azimuth);
  39313. mainLight.position.x = Math.sin(pos.altitude);
  39314. mainLight.position.z = r0 * Math.sin(pos.azimuth);
  39315. mainLight.lookAt(earthMesh.getWorldPosition());
  39316. },
  39317. dispose: function (ecModel, api) {
  39318. this.groupGL.removeAll();
  39319. this._control.dispose();
  39320. }
  39321. }));
  39322. /***/
  39323. }),
  39324. /* 210 */
  39325. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  39326. "use strict";
  39327. /*
  39328. (c) 2011-2014, Vladimir Agafonkin
  39329. SunCalc is a JavaScript library for calculating sun/mooon position and light phases.
  39330. https://github.com/mourner/suncalc
  39331. */
  39332. // shortcuts for easier to read formulas
  39333. var PI = Math.PI,
  39334. sin = Math.sin,
  39335. cos = Math.cos,
  39336. tan = Math.tan,
  39337. asin = Math.asin,
  39338. atan = Math.atan2,
  39339. rad = PI / 180;
  39340. // sun calculations are based on http://aa.quae.nl/en/reken/zonpositie.html formulas
  39341. // date/time constants and conversions
  39342. var dayMs = 1000 * 60 * 60 * 24,
  39343. J1970 = 2440588,
  39344. J2000 = 2451545;
  39345. function toJulian(date) { return date.valueOf() / dayMs - 0.5 + J1970; }
  39346. function toDays(date) { return toJulian(date) - J2000; }
  39347. // general calculations for position
  39348. var e = rad * 23.4397; // obliquity of the Earth
  39349. function rightAscension(l, b) { return atan(sin(l) * cos(e) - tan(b) * sin(e), cos(l)); }
  39350. function declination(l, b) { return asin(sin(b) * cos(e) + cos(b) * sin(e) * sin(l)); }
  39351. function azimuth(H, phi, dec) { return atan(sin(H), cos(H) * sin(phi) - tan(dec) * cos(phi)); }
  39352. function altitude(H, phi, dec) { return asin(sin(phi) * sin(dec) + cos(phi) * cos(dec) * cos(H)); }
  39353. function siderealTime(d, lw) { return rad * (280.16 + 360.9856235 * d) - lw; }
  39354. // general sun calculations
  39355. function solarMeanAnomaly(d) { return rad * (357.5291 + 0.98560028 * d); }
  39356. function eclipticLongitude(M) {
  39357. var C = rad * (1.9148 * sin(M) + 0.02 * sin(2 * M) + 0.0003 * sin(3 * M)), // equation of center
  39358. P = rad * 102.9372; // perihelion of the Earth
  39359. return M + C + P + PI;
  39360. }
  39361. function sunCoords(d) {
  39362. var M = solarMeanAnomaly(d),
  39363. L = eclipticLongitude(M);
  39364. return {
  39365. dec: declination(L, 0),
  39366. ra: rightAscension(L, 0)
  39367. };
  39368. }
  39369. var SunCalc = {};
  39370. // calculates sun position for a given date and latitude/longitude
  39371. SunCalc.getPosition = function (date, lat, lng) {
  39372. var lw = rad * -lng,
  39373. phi = rad * lat,
  39374. d = toDays(date),
  39375. c = sunCoords(d),
  39376. H = siderealTime(d, lw) - c.ra;
  39377. return {
  39378. azimuth: azimuth(H, phi, c.dec),
  39379. altitude: altitude(H, phi, c.dec)
  39380. };
  39381. };
  39382. /* harmony default export */ __webpack_exports__["a"] = (SunCalc);
  39383. /***/
  39384. }),
  39385. /* 211 */
  39386. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  39387. "use strict";
  39388. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__globe_Globe__ = __webpack_require__(212);
  39389. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts__ = __webpack_require__(0);
  39390. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts__);
  39391. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_echarts_lib_util_layout__ = __webpack_require__(47);
  39392. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_echarts_lib_util_layout___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_echarts_lib_util_layout__);
  39393. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__core_ViewGL__ = __webpack_require__(22);
  39394. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__util_retrieve__ = __webpack_require__(2);
  39395. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__util_graphicGL__ = __webpack_require__(1);
  39396. function getDisplacementData(img, displacementScale) {
  39397. var canvas = document.createElement('canvas');
  39398. var ctx = canvas.getContext('2d');
  39399. var width = img.width;
  39400. var height = img.height;
  39401. canvas.width = width;
  39402. canvas.height = height;
  39403. ctx.drawImage(img, 0, 0, width, height);
  39404. var rgbaArr = ctx.getImageData(0, 0, width, height).data;
  39405. var displacementArr = new Float32Array(rgbaArr.length / 4);
  39406. for (var i = 0; i < rgbaArr.length / 4; i++) {
  39407. var x = rgbaArr[i * 4];
  39408. displacementArr[i] = x / 255 * displacementScale;
  39409. }
  39410. return {
  39411. data: displacementArr,
  39412. width: width,
  39413. height: height
  39414. };
  39415. }
  39416. function resizeGlobe(globeModel, api) {
  39417. // Use left/top/width/height
  39418. var boxLayoutOption = globeModel.getBoxLayoutParams();
  39419. var viewport = __WEBPACK_IMPORTED_MODULE_2_echarts_lib_util_layout___default.a.getLayoutRect(boxLayoutOption, {
  39420. width: api.getWidth(),
  39421. height: api.getHeight()
  39422. });
  39423. // Flip Y
  39424. viewport.y = api.getHeight() - viewport.y - viewport.height;
  39425. this.viewGL.setViewport(viewport.x, viewport.y, viewport.width, viewport.height, api.getDevicePixelRatio());
  39426. this.radius = globeModel.get('globeRadius');
  39427. var outerRadius = globeModel.get('globeOuterRadius');
  39428. if (this.altitudeAxis) {
  39429. this.altitudeAxis.setExtent(0, outerRadius - this.radius);
  39430. }
  39431. }
  39432. function updateGlobe(ecModel, api) {
  39433. var altitudeDataExtent = [Infinity, -Infinity]
  39434. ecModel.eachSeries(function (seriesModel) {
  39435. if (seriesModel.coordinateSystem !== this) {
  39436. return;
  39437. }
  39438. // Get altitude data extent.
  39439. var data = seriesModel.getData();
  39440. var altDims = seriesModel.coordDimToDataDim('alt');
  39441. var altDim = altDims && altDims[0];
  39442. if (altDim) {
  39443. // TODO altitiude is in coords of lines.
  39444. var dataExtent = data.getDataExtent(altDim, true);
  39445. altitudeDataExtent[0] = Math.min(
  39446. altitudeDataExtent[0], dataExtent[0]
  39447. );
  39448. altitudeDataExtent[1] = Math.max(
  39449. altitudeDataExtent[1], dataExtent[1]
  39450. );
  39451. }
  39452. }, this);
  39453. // Create altitude axis
  39454. if (altitudeDataExtent && isFinite(altitudeDataExtent[1] - altitudeDataExtent[0])) {
  39455. var scale = __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default.a.helper.createScale(
  39456. altitudeDataExtent, {
  39457. type: 'value',
  39458. // PENDING
  39459. min: 'dataMin',
  39460. max: 'dataMax'
  39461. }
  39462. );
  39463. this.altitudeAxis = new __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default.a.Axis('altitude', scale);
  39464. // Resize again
  39465. this.resize(this.model, api);
  39466. }
  39467. }
  39468. var globeCreator = {
  39469. dimensions: __WEBPACK_IMPORTED_MODULE_0__globe_Globe__["a" /* default */].prototype.dimensions,
  39470. create: function (ecModel, api) {
  39471. var globeList = [];
  39472. ecModel.eachComponent('globe', function (globeModel) {
  39473. // FIXME
  39474. globeModel.__viewGL = globeModel.__viewGL || new __WEBPACK_IMPORTED_MODULE_3__core_ViewGL__["a" /* default */]();
  39475. var globe = new __WEBPACK_IMPORTED_MODULE_0__globe_Globe__["a" /* default */]();
  39476. globe.viewGL = globeModel.__viewGL;
  39477. globeModel.coordinateSystem = globe;
  39478. globe.model = globeModel;
  39479. globeList.push(globe);
  39480. // Inject resize
  39481. globe.resize = resizeGlobe;
  39482. globe.resize(globeModel, api);
  39483. globe.update = updateGlobe;
  39484. });
  39485. ecModel.eachSeries(function (seriesModel) {
  39486. if (seriesModel.get('coordinateSystem') === 'globe') {
  39487. var globeModel = seriesModel.getReferringComponents('globe')[0];
  39488. if (!globeModel) {
  39489. globeModel = ecModel.getComponent('globe');
  39490. }
  39491. if (!globeModel) {
  39492. throw new Error('globe "' + __WEBPACK_IMPORTED_MODULE_4__util_retrieve__["a" /* default */].firstNotNull(
  39493. seriesModel.get('globe3DIndex'),
  39494. seriesModel.get('globe3DId'),
  39495. 0
  39496. ) + '" not found');
  39497. }
  39498. var coordSys = globeModel.coordinateSystem;
  39499. seriesModel.coordinateSystem = coordSys;
  39500. }
  39501. });
  39502. ecModel.eachComponent('globe', function (globeModel, idx) {
  39503. var globe = globeModel.coordinateSystem;
  39504. // Update displacement data
  39505. var displacementTextureValue = globeModel.getDisplacementTexture();
  39506. var displacementScale = globeModel.getDisplacemenScale();
  39507. if (globeModel.isDisplacementChanged()) {
  39508. if (globeModel.hasDisplacement()) {
  39509. var immediateLoaded = true;
  39510. __WEBPACK_IMPORTED_MODULE_5__util_graphicGL__["a" /* default */].loadTexture(displacementTextureValue, api, function (texture) {
  39511. var img = texture.image;
  39512. var displacementData = getDisplacementData(img, displacementScale);
  39513. globeModel.setDisplacementData(displacementData.data, displacementData.width, displacementData.height);
  39514. if (!immediateLoaded) {
  39515. // Update layouts
  39516. api.dispatchAction({
  39517. type: 'globeUpdateDisplacment'
  39518. });
  39519. }
  39520. });
  39521. immediateLoaded = false;
  39522. }
  39523. else {
  39524. globe.setDisplacementData(null, 0, 0);
  39525. }
  39526. globe.setDisplacementData(
  39527. globeModel.displacementData, globeModel.displacementWidth, globeModel.displacementHeight
  39528. );
  39529. }
  39530. });
  39531. return globeList;
  39532. }
  39533. };
  39534. __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default.a.registerCoordinateSystem('globe', globeCreator);
  39535. /* unused harmony default export */ var _unused_webpack_default_export = (globeCreator);
  39536. /***/
  39537. }),
  39538. /* 212 */
  39539. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  39540. "use strict";
  39541. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_claygl_src_dep_glmatrix__ = __webpack_require__(6);
  39542. var vec3 = __WEBPACK_IMPORTED_MODULE_0_claygl_src_dep_glmatrix__["a" /* default */].vec3;
  39543. function Globe(radius) {
  39544. this.radius = radius;
  39545. this.viewGL = null;
  39546. this.altitudeAxis;
  39547. // Displacement data provided by texture.
  39548. this.displacementData = null;
  39549. this.displacementWidth;
  39550. this.displacementHeight;
  39551. }
  39552. Globe.prototype = {
  39553. constructor: Globe,
  39554. dimensions: ['lng', 'lat', 'alt'],
  39555. type: 'globe',
  39556. containPoint: function () { },
  39557. setDisplacementData: function (data, width, height) {
  39558. this.displacementData = data;
  39559. this.displacementWidth = width;
  39560. this.displacementHeight = height;
  39561. },
  39562. _getDisplacementScale: function (lng, lat) {
  39563. var i = (lng + 180) / 360 * (this.displacementWidth - 1);
  39564. var j = (90 - lat) / 180 * (this.displacementHeight - 1);
  39565. // NEAREST SAMPLING
  39566. // TODO Better bilinear sampling
  39567. var idx = Math.round(i) + Math.round(j) * this.displacementWidth;
  39568. return this.displacementData[idx];
  39569. },
  39570. dataToPoint: function (data, out) {
  39571. var lng = data[0];
  39572. var lat = data[1];
  39573. // Default have 0 altitude
  39574. var altVal = data[2] || 0;
  39575. var r = this.radius;
  39576. if (this.displacementData) {
  39577. r *= 1 + this._getDisplacementScale(lng, lat);
  39578. }
  39579. if (this.altitudeAxis) {
  39580. r += this.altitudeAxis.dataToCoord(altVal);
  39581. }
  39582. lng = lng * Math.PI / 180;
  39583. lat = lat * Math.PI / 180;
  39584. var r0 = Math.cos(lat) * r;
  39585. out = out || [];
  39586. // PENDING
  39587. out[0] = -r0 * Math.cos(lng + Math.PI);
  39588. out[1] = Math.sin(lat) * r;
  39589. out[2] = r0 * Math.sin(lng + Math.PI);
  39590. return out;
  39591. },
  39592. pointToData: function (point, out) {
  39593. var x = point[0];
  39594. var y = point[1];
  39595. var z = point[2];
  39596. var len = vec3.len(point);
  39597. x /= len;
  39598. y /= len;
  39599. z /= len;
  39600. var theta = Math.asin(y);
  39601. var phi = Math.atan2(z, -x);
  39602. if (phi < 0) {
  39603. phi = Math.PI * 2 + phi;
  39604. }
  39605. var lat = theta * 180 / Math.PI;
  39606. var lng = phi * 180 / Math.PI - 180;
  39607. out = out || [];
  39608. out[0] = lng;
  39609. out[1] = lat;
  39610. out[2] = len - this.radius;
  39611. if (this.altitudeAxis) {
  39612. out[2] = this.altitudeAxis.coordToData(out[2]);
  39613. }
  39614. return out;
  39615. }
  39616. };
  39617. /* harmony default export */ __webpack_exports__["a"] = (Globe);
  39618. /***/
  39619. }),
  39620. /* 213 */
  39621. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  39622. "use strict";
  39623. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  39624. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  39625. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__coord_mapbox3DCreator__ = __webpack_require__(214);
  39626. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__mapbox3D_Mapbox3DModel__ = __webpack_require__(216);
  39627. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__mapbox3D_Mapbox3DView__ = __webpack_require__(217);
  39628. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerAction({
  39629. type: 'mapbox3DChangeCamera',
  39630. event: 'mapbox3dcamerachanged',
  39631. update: 'mapbox3D:updateCamera'
  39632. }, function (payload, ecModel) {
  39633. ecModel.eachComponent({
  39634. mainType: 'mapbox3D', query: payload
  39635. }, function (componentModel) {
  39636. componentModel.setMapboxCameraOption(payload);
  39637. });
  39638. });
  39639. /***/
  39640. }),
  39641. /* 214 */
  39642. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  39643. "use strict";
  39644. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__mapbox3D_Mapbox3D__ = __webpack_require__(215);
  39645. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts__ = __webpack_require__(0);
  39646. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts__);
  39647. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__mapServiceCommon_createMapService3DCreator__ = __webpack_require__(101);
  39648. var mapbox3DCreator = Object(__WEBPACK_IMPORTED_MODULE_2__mapServiceCommon_createMapService3DCreator__["a" /* default */])('mapbox3D', __WEBPACK_IMPORTED_MODULE_0__mapbox3D_Mapbox3D__["a" /* default */], function (mapbox3DList) {
  39649. mapbox3DList.forEach(function (mapbox3D) {
  39650. mapbox3D.setCameraOption(mapbox3D.model.getMapboxCameraOption());
  39651. });
  39652. });
  39653. __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default.a.registerCoordinateSystem('mapbox3D', mapbox3DCreator);
  39654. /* unused harmony default export */ var _unused_webpack_default_export = (mapbox3DCreator);
  39655. /***/
  39656. }),
  39657. /* 215 */
  39658. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  39659. "use strict";
  39660. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__mapServiceCommon_MapService3D__ = __webpack_require__(100);
  39661. function Mapbox3D() {
  39662. __WEBPACK_IMPORTED_MODULE_0__mapServiceCommon_MapService3D__["a" /* default */].apply(this, arguments);
  39663. }
  39664. Mapbox3D.prototype = new __WEBPACK_IMPORTED_MODULE_0__mapServiceCommon_MapService3D__["a" /* default */]();
  39665. Mapbox3D.prototype.constructor = Mapbox3D;
  39666. Mapbox3D.prototype.type = 'mapbox3D';
  39667. /* harmony default export */ __webpack_exports__["a"] = (Mapbox3D);
  39668. /***/
  39669. }),
  39670. /* 216 */
  39671. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  39672. "use strict";
  39673. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  39674. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  39675. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__common_componentPostEffectMixin__ = __webpack_require__(28);
  39676. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__common_componentLightMixin__ = __webpack_require__(29);
  39677. var MAPBOX_CAMERA_OPTION = ['zoom', 'center', 'pitch', 'bearing'];
  39678. var Mapbox3DModel = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendComponentModel({
  39679. type: 'mapbox3D',
  39680. layoutMode: 'box',
  39681. coordinateSystem: null,
  39682. defaultOption: {
  39683. zlevel: -10,
  39684. style: 'mapbox://styles/mapbox/light-v9',
  39685. center: [0, 0],
  39686. zoom: 0,
  39687. pitch: 0,
  39688. bearing: 0,
  39689. light: {
  39690. main: {
  39691. alpha: 20,
  39692. beta: 30
  39693. }
  39694. },
  39695. altitudeScale: 1,
  39696. // Default depend on altitudeScale
  39697. boxHeight: 'auto'
  39698. },
  39699. getMapboxCameraOption: function () {
  39700. var self = this;
  39701. return MAPBOX_CAMERA_OPTION.reduce(function (obj, key) {
  39702. obj[key] = self.get(key);
  39703. return obj;
  39704. }, {});
  39705. },
  39706. setMapboxCameraOption: function (option) {
  39707. if (option != null) {
  39708. MAPBOX_CAMERA_OPTION.forEach(function (key) {
  39709. if (option[key] != null) {
  39710. this.option[key] = option[key];
  39711. }
  39712. }, this);
  39713. }
  39714. },
  39715. /**
  39716. * Get mapbox instance
  39717. */
  39718. getMapbox: function () {
  39719. return this._mapbox;
  39720. },
  39721. setMapbox: function (mapbox) {
  39722. this._mapbox = mapbox;
  39723. }
  39724. });
  39725. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(Mapbox3DModel.prototype, __WEBPACK_IMPORTED_MODULE_1__common_componentPostEffectMixin__["a" /* default */]);
  39726. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(Mapbox3DModel.prototype, __WEBPACK_IMPORTED_MODULE_2__common_componentLightMixin__["a" /* default */]);
  39727. /* unused harmony default export */ var _unused_webpack_default_export = (Mapbox3DModel);
  39728. /***/
  39729. }),
  39730. /* 217 */
  39731. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  39732. "use strict";
  39733. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  39734. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  39735. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__Mapbox3DLayer__ = __webpack_require__(218);
  39736. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__common_SceneHelper__ = __webpack_require__(30);
  39737. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__ = __webpack_require__(1);
  39738. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__util_shader_displayShadow_glsl_js__ = __webpack_require__(102);
  39739. __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Shader.import(__WEBPACK_IMPORTED_MODULE_4__util_shader_displayShadow_glsl_js__["a" /* default */]);
  39740. var TILE_SIZE = 512;
  39741. /* unused harmony default export */ var _unused_webpack_default_export = (__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendComponentView({
  39742. type: 'mapbox3D',
  39743. __ecgl__: true,
  39744. init: function (ecModel, api) {
  39745. var zr = api.getZr();
  39746. this._zrLayer = new __WEBPACK_IMPORTED_MODULE_1__Mapbox3DLayer__["a" /* default */]('mapbox3D', zr);
  39747. zr.painter.insertLayer(-1000, this._zrLayer);
  39748. this._lightRoot = new __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Node();
  39749. this._sceneHelper = new __WEBPACK_IMPORTED_MODULE_2__common_SceneHelper__["a" /* default */](this._lightRoot);
  39750. this._sceneHelper.initLight(this._lightRoot);
  39751. var mapbox = this._zrLayer.getMapbox();
  39752. var dispatchInteractAction = this._dispatchInteractAction.bind(this, api, mapbox);
  39753. // PENDING
  39754. ['zoom', 'rotate', 'drag', 'pitch', 'rotate', 'move'].forEach(function (eName) {
  39755. mapbox.on(eName, dispatchInteractAction);
  39756. });
  39757. this._groundMesh = new __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Mesh({
  39758. geometry: new __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].PlaneGeometry(),
  39759. material: new __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Material({
  39760. shader: new __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Shader({
  39761. vertex: __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Shader.source('ecgl.displayShadow.vertex'),
  39762. fragment: __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Shader.source('ecgl.displayShadow.fragment')
  39763. }),
  39764. depthMask: false
  39765. }),
  39766. // Render first
  39767. renderOrder: -100,
  39768. culling: false,
  39769. castShadow: false,
  39770. $ignorePicking: true,
  39771. renderNormal: true
  39772. });
  39773. },
  39774. render: function (mapbox3DModel, ecModel, api) {
  39775. var mapbox = this._zrLayer.getMapbox();
  39776. var styleDesc = mapbox3DModel.get('style');
  39777. var styleStr = JSON.stringify(styleDesc);
  39778. if (styleStr !== this._oldStyleStr) {
  39779. if (styleDesc) {
  39780. mapbox.setStyle(styleDesc);
  39781. }
  39782. }
  39783. this._oldStyleStr = styleStr;
  39784. mapbox.setCenter(mapbox3DModel.get('center'));
  39785. mapbox.setZoom(mapbox3DModel.get('zoom'));
  39786. mapbox.setPitch(mapbox3DModel.get('pitch'));
  39787. mapbox.setBearing(mapbox3DModel.get('bearing'));
  39788. mapbox3DModel.setMapbox(mapbox);
  39789. var coordSys = mapbox3DModel.coordinateSystem;
  39790. // Not add to rootNode. Or light direction will be stretched by rootNode scale
  39791. coordSys.viewGL.scene.add(this._lightRoot);
  39792. coordSys.viewGL.add(this._groundMesh);
  39793. this._updateGroundMesh();
  39794. // Update lights
  39795. this._sceneHelper.setScene(coordSys.viewGL.scene);
  39796. this._sceneHelper.updateLight(mapbox3DModel);
  39797. // Update post effects
  39798. coordSys.viewGL.setPostEffect(mapbox3DModel.getModel('postEffect'), api);
  39799. coordSys.viewGL.setTemporalSuperSampling(mapbox3DModel.getModel('temporalSuperSampling'));
  39800. this._mapbox3DModel = mapbox3DModel;
  39801. },
  39802. afterRender: function (mapbox3DModel, ecModel, api, layerGL) {
  39803. var renderer = layerGL.renderer;
  39804. this._sceneHelper.updateAmbientCubemap(renderer, mapbox3DModel, api);
  39805. this._sceneHelper.updateSkybox(renderer, mapbox3DModel, api);
  39806. // FIXME If other series changes coordinate system.
  39807. // FIXME When doing progressive rendering.
  39808. mapbox3DModel.coordinateSystem.viewGL.scene.traverse(function (mesh) {
  39809. if (mesh.material) {
  39810. mesh.material.define('fragment', 'NORMAL_UP_AXIS', 2);
  39811. mesh.material.define('fragment', 'NORMAL_FRONT_AXIS', 1);
  39812. }
  39813. });
  39814. },
  39815. updateCamera: function (mapbox3DModel, ecModel, api, payload) {
  39816. mapbox3DModel.coordinateSystem.setCameraOption(payload);
  39817. this._updateGroundMesh();
  39818. api.getZr().refresh();
  39819. },
  39820. _dispatchInteractAction: function (api, mapbox, mapbox3DModel) {
  39821. api.dispatchAction({
  39822. type: 'mapbox3DChangeCamera',
  39823. pitch: mapbox.getPitch(),
  39824. zoom: mapbox.getZoom(),
  39825. center: mapbox.getCenter().toArray(),
  39826. bearing: mapbox.getBearing(),
  39827. mapbox3DId: this._mapbox3DModel && this._mapbox3DModel.id
  39828. });
  39829. },
  39830. _updateGroundMesh: function () {
  39831. if (this._mapbox3DModel) {
  39832. var coordSys = this._mapbox3DModel.coordinateSystem;
  39833. var pt = coordSys.dataToPoint(coordSys.center);
  39834. this._groundMesh.position.set(pt[0], pt[1], -0.001);
  39835. var plane = new __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Plane(new __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Vector3(0, 0, 1), 0);
  39836. var ray1 = coordSys.viewGL.camera.castRay(new __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Vector2(-1, -1));
  39837. var ray2 = coordSys.viewGL.camera.castRay(new __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Vector2(1, 1));
  39838. var pos0 = ray1.intersectPlane(plane);
  39839. var pos1 = ray2.intersectPlane(plane);
  39840. var scale = pos0.dist(pos1) / coordSys.viewGL.rootNode.scale.x;
  39841. this._groundMesh.scale.set(scale, scale, 1);
  39842. }
  39843. },
  39844. dispose: function (ecModel, api) {
  39845. if (this._zrLayer) {
  39846. this._zrLayer.dispose();
  39847. }
  39848. api.getZr().painter.delLayer(-1000);
  39849. }
  39850. }));
  39851. /***/
  39852. }),
  39853. /* 218 */
  39854. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  39855. "use strict";
  39856. /**
  39857. * @constructor
  39858. * @alias module:echarts-gl/component/mapbox3D/Mapbox3DLayer
  39859. * @param {string} id Layer ID
  39860. * @param {module:zrender/ZRender} zr
  39861. */
  39862. function Mapbox3DLayer(id, zr) {
  39863. this.id = id;
  39864. this.zr = zr;
  39865. this.dom = document.createElement('div');
  39866. this.dom.style.cssText = 'position:absolute;left:0;right:0;top:0;bottom:0;';
  39867. // FIXME If in module environment.
  39868. if (!mapboxgl) {
  39869. throw new Error('Mapbox GL library must be included. See https://www.mapbox.com/mapbox-gl-js/api/');
  39870. }
  39871. this._mapbox = new mapboxgl.Map({
  39872. container: this.dom
  39873. });
  39874. // Proxy events
  39875. this._initEvents();
  39876. }
  39877. Mapbox3DLayer.prototype.resize = function () {
  39878. this._mapbox.resize();
  39879. };
  39880. Mapbox3DLayer.prototype.getMapbox = function () {
  39881. return this._mapbox;
  39882. };
  39883. Mapbox3DLayer.prototype.clear = function () { };
  39884. Mapbox3DLayer.prototype.refresh = function () {
  39885. this._mapbox.resize();
  39886. };
  39887. var EVENTS = ['mousedown', 'mouseup', 'click', 'dblclick', 'mousemove',
  39888. 'mousewheel', 'wheel',
  39889. 'touchstart', 'touchend', 'touchmove', 'touchcancel'
  39890. ];
  39891. Mapbox3DLayer.prototype._initEvents = function () {
  39892. // Event is bound on canvas container.
  39893. var mapboxRoot = this._mapbox.getCanvasContainer();
  39894. this._handlers = this._handlers || {
  39895. contextmenu: function (e) {
  39896. e.preventDefault();
  39897. return false;
  39898. }
  39899. };
  39900. EVENTS.forEach(function (eName) {
  39901. this._handlers[eName] = function (e) {
  39902. var obj = {};
  39903. for (var name in e) {
  39904. obj[name] = e[name];
  39905. }
  39906. obj.bubbles = false;
  39907. var newE = new e.constructor(e.type, obj);
  39908. mapboxRoot.dispatchEvent(newE);
  39909. };
  39910. this.zr.dom.addEventListener(eName, this._handlers[eName]);
  39911. }, this);
  39912. // PENDING
  39913. this.zr.dom.addEventListener('contextmenu', this._handlers.contextmenu);
  39914. };
  39915. Mapbox3DLayer.prototype.dispose = function () {
  39916. EVENTS.forEach(function (eName) {
  39917. this.zr.dom.removeEventListener(eName, this._handlers[eName]);
  39918. }, this);
  39919. };
  39920. /* harmony default export */ __webpack_exports__["a"] = (Mapbox3DLayer);
  39921. /***/
  39922. }),
  39923. /* 219 */
  39924. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  39925. "use strict";
  39926. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  39927. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  39928. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__coord_maptalks3DCreator__ = __webpack_require__(220);
  39929. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__maptalks3D_Maptalks3DModel__ = __webpack_require__(222);
  39930. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__maptalks3D_Maptalks3DView__ = __webpack_require__(223);
  39931. // Thanks to https://gitee.com/iverson_hu/maptalks-echarts-gl
  39932. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerAction({
  39933. type: 'maptalks3DChangeCamera',
  39934. event: 'maptalks3dcamerachanged',
  39935. update: 'maptalks3D:updateCamera'
  39936. }, function (payload, ecModel) {
  39937. ecModel.eachComponent({
  39938. mainType: 'maptalks3D', query: payload
  39939. }, function (componentModel) {
  39940. componentModel.setMaptalksCameraOption(payload);
  39941. });
  39942. });
  39943. /***/
  39944. }),
  39945. /* 220 */
  39946. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  39947. "use strict";
  39948. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__maptalks3D_Maptalks3D__ = __webpack_require__(221);
  39949. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts__ = __webpack_require__(0);
  39950. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts__);
  39951. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__mapServiceCommon_createMapService3DCreator__ = __webpack_require__(101);
  39952. var maptalks3DCreator = Object(__WEBPACK_IMPORTED_MODULE_2__mapServiceCommon_createMapService3DCreator__["a" /* default */])('maptalks3D', __WEBPACK_IMPORTED_MODULE_0__maptalks3D_Maptalks3D__["a" /* default */], function (maptalks3DList) {
  39953. maptalks3DList.forEach(function (maptalks3D) {
  39954. maptalks3D.setCameraOption(maptalks3D.model.getMaptalksCameraOption());
  39955. });
  39956. });
  39957. __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default.a.registerCoordinateSystem('maptalks3D', maptalks3DCreator);
  39958. /* unused harmony default export */ var _unused_webpack_default_export = (maptalks3DCreator);
  39959. /***/
  39960. }),
  39961. /* 221 */
  39962. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  39963. "use strict";
  39964. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__mapServiceCommon_MapService3D__ = __webpack_require__(100);
  39965. function Maptalks3D() {
  39966. __WEBPACK_IMPORTED_MODULE_0__mapServiceCommon_MapService3D__["a" /* default */].apply(this, arguments);
  39967. this.maxPitch = 85;
  39968. this.zoomOffset = 1;
  39969. }
  39970. Maptalks3D.prototype = new __WEBPACK_IMPORTED_MODULE_0__mapServiceCommon_MapService3D__["a" /* default */]();
  39971. Maptalks3D.prototype.constructor = Maptalks3D;
  39972. Maptalks3D.prototype.type = 'maptalks3D';
  39973. /* harmony default export */ __webpack_exports__["a"] = (Maptalks3D);
  39974. /***/
  39975. }),
  39976. /* 222 */
  39977. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  39978. "use strict";
  39979. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  39980. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  39981. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__common_componentPostEffectMixin__ = __webpack_require__(28);
  39982. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__common_componentLightMixin__ = __webpack_require__(29);
  39983. var MAPTALKS_CAMERA_OPTION = ['zoom', 'center', 'pitch', 'bearing'];
  39984. var Maptalks3DModel = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendComponentModel({
  39985. type: 'maptalks3D',
  39986. layoutMode: 'box',
  39987. coordinateSystem: null,
  39988. defaultOption: {
  39989. zlevel: -10,
  39990. urlTemplate: 'http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
  39991. attribution: '&copy; <a href="http://osm.org">OpenStreetMap</a> contributors, &copy; <a href="https://carto.com/">CARTO</a>',
  39992. center: [0, 0],
  39993. zoom: 0,
  39994. pitch: 0,
  39995. bearing: 0,
  39996. light: {
  39997. main: {
  39998. alpha: 20,
  39999. beta: 30
  40000. }
  40001. },
  40002. altitudeScale: 1,
  40003. // Default depend on altitudeScale
  40004. boxHeight: 'auto'
  40005. },
  40006. getMaptalksCameraOption: function () {
  40007. var self = this;
  40008. return MAPTALKS_CAMERA_OPTION.reduce(function (obj, key) {
  40009. obj[key] = self.get(key);
  40010. return obj;
  40011. }, {});
  40012. },
  40013. setMaptalksCameraOption: function (option) {
  40014. if (option != null) {
  40015. MAPTALKS_CAMERA_OPTION.forEach(function (key) {
  40016. if (option[key] != null) {
  40017. this.option[key] = option[key];
  40018. }
  40019. }, this);
  40020. }
  40021. },
  40022. /**
  40023. * Get maptalks instance
  40024. */
  40025. getMaptalks: function () {
  40026. return this._maptalks;
  40027. },
  40028. setMaptalks: function (maptalks) {
  40029. this._maptalks = maptalks;
  40030. }
  40031. });
  40032. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(Maptalks3DModel.prototype, __WEBPACK_IMPORTED_MODULE_1__common_componentPostEffectMixin__["a" /* default */]);
  40033. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(Maptalks3DModel.prototype, __WEBPACK_IMPORTED_MODULE_2__common_componentLightMixin__["a" /* default */]);
  40034. /* unused harmony default export */ var _unused_webpack_default_export = (Maptalks3DModel);
  40035. /***/
  40036. }),
  40037. /* 223 */
  40038. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  40039. "use strict";
  40040. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  40041. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  40042. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__Maptalks3DLayer__ = __webpack_require__(224);
  40043. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__common_SceneHelper__ = __webpack_require__(30);
  40044. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__ = __webpack_require__(1);
  40045. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__util_shader_displayShadow_glsl_js__ = __webpack_require__(102);
  40046. __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Shader.import(__WEBPACK_IMPORTED_MODULE_4__util_shader_displayShadow_glsl_js__["a" /* default */]);
  40047. /* unused harmony default export */ var _unused_webpack_default_export = (__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendComponentView({
  40048. type: 'maptalks3D',
  40049. __ecgl__: true,
  40050. init: function (ecModel, api) {
  40051. this._groundMesh = new __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Mesh({
  40052. geometry: new __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].PlaneGeometry(),
  40053. material: new __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Material({
  40054. shader: new __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Shader({
  40055. vertex: __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Shader.source('ecgl.displayShadow.vertex'),
  40056. fragment: __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Shader.source('ecgl.displayShadow.fragment')
  40057. }),
  40058. depthMask: false
  40059. }),
  40060. // Render first
  40061. renderOrder: -100,
  40062. culling: false,
  40063. castShadow: false,
  40064. $ignorePicking: true,
  40065. renderNormal: true
  40066. });
  40067. },
  40068. _initMaptalksLayer: function (mapbox3DModel, api) {
  40069. var zr = api.getZr();
  40070. this._zrLayer = new __WEBPACK_IMPORTED_MODULE_1__Maptalks3DLayer__["a" /* default */]('maptalks3D', zr, mapbox3DModel.get('center'), mapbox3DModel.get('zoom'));
  40071. zr.painter.insertLayer(-1000, this._zrLayer);
  40072. this._lightRoot = new __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Node();
  40073. this._sceneHelper = new __WEBPACK_IMPORTED_MODULE_2__common_SceneHelper__["a" /* default */](this._lightRoot);
  40074. this._sceneHelper.initLight(this._lightRoot);
  40075. var maptalks = this._zrLayer.getMaptalks();
  40076. var dispatchInteractAction = this._dispatchInteractAction.bind(this, api, maptalks);
  40077. // PENDING
  40078. ['zoomend', 'zooming', 'zoomstart', 'dragrotating', 'pitch', 'pitchend', 'movestart',
  40079. 'moving', 'moveend', 'resize', 'touchstart', 'touchmove', 'touchend'].forEach(function (eName) {
  40080. maptalks.on(eName, dispatchInteractAction);
  40081. });
  40082. },
  40083. render: function (maptalks3DModel, ecModel, api) {
  40084. if (!this._zrLayer) {
  40085. this._initMaptalksLayer(maptalks3DModel, api);
  40086. }
  40087. var mtks = this._zrLayer.getMaptalks();
  40088. var urlTemplate = maptalks3DModel.get('urlTemplate');
  40089. var baseLayer = mtks.getBaseLayer();
  40090. if (urlTemplate !== this._oldUrlTemplate) {
  40091. if (!baseLayer) {
  40092. baseLayer = new maptalks.TileLayer('maptalks-echarts-gl-baselayer', {
  40093. urlTemplate: urlTemplate,
  40094. // used sequentially to help with browser parallel requests per domain limitation
  40095. subdomains: ['a', 'b', 'c'],
  40096. attribution: maptalks3DModel.get('attribution')
  40097. });
  40098. mtks.setBaseLayer(baseLayer);
  40099. }
  40100. else {
  40101. // PENDING setOptions may not work?
  40102. baseLayer.setOptions({
  40103. urlTemplate: urlTemplate,
  40104. attribution: maptalks3DModel.get('attribution')
  40105. });
  40106. }
  40107. }
  40108. this._oldUrlTemplate = urlTemplate;
  40109. mtks.setCenter(maptalks3DModel.get('center'));
  40110. mtks.setZoom(maptalks3DModel.get('zoom'), { animation: false });
  40111. mtks.setPitch(maptalks3DModel.get('pitch'));
  40112. mtks.setBearing(maptalks3DModel.get('bearing'));
  40113. maptalks3DModel.setMaptalks(mtks);
  40114. var coordSys = maptalks3DModel.coordinateSystem;
  40115. // Not add to rootNode. Or light direction will be stretched by rootNode scale
  40116. coordSys.viewGL.scene.add(this._lightRoot);
  40117. coordSys.viewGL.add(this._groundMesh);
  40118. this._updateGroundMesh();
  40119. // Update lights
  40120. this._sceneHelper.setScene(coordSys.viewGL.scene);
  40121. this._sceneHelper.updateLight(maptalks3DModel);
  40122. // Update post effects
  40123. coordSys.viewGL.setPostEffect(maptalks3DModel.getModel('postEffect'), api);
  40124. coordSys.viewGL.setTemporalSuperSampling(maptalks3DModel.getModel('temporalSuperSampling'));
  40125. this._maptalks3DModel = maptalks3DModel;
  40126. },
  40127. afterRender: function (maptalks3DModel, ecModel, api, layerGL) {
  40128. var renderer = layerGL.renderer;
  40129. this._sceneHelper.updateAmbientCubemap(renderer, maptalks3DModel, api);
  40130. this._sceneHelper.updateSkybox(renderer, maptalks3DModel, api);
  40131. // FIXME If other series changes coordinate system.
  40132. // FIXME When doing progressive rendering.
  40133. maptalks3DModel.coordinateSystem.viewGL.scene.traverse(function (mesh) {
  40134. if (mesh.material) {
  40135. mesh.material.define('fragment', 'NORMAL_UP_AXIS', 2);
  40136. mesh.material.define('fragment', 'NORMAL_FRONT_AXIS', 1);
  40137. }
  40138. });
  40139. },
  40140. updateCamera: function (maptalks3DModel, ecModel, api, payload) {
  40141. maptalks3DModel.coordinateSystem.setCameraOption(payload);
  40142. this._updateGroundMesh();
  40143. api.getZr().refresh();
  40144. },
  40145. _dispatchInteractAction: function (api, maptalks, maptalks3DModel) {
  40146. api.dispatchAction({
  40147. type: 'maptalks3DChangeCamera',
  40148. pitch: maptalks.getPitch(),
  40149. zoom: maptalks.getZoom(),
  40150. center: maptalks.getCenter().toArray(),
  40151. bearing: maptalks.getBearing(),
  40152. maptalks3DId: this._maptalks3DModel && this._maptalks3DModel.id
  40153. });
  40154. },
  40155. _updateGroundMesh: function () {
  40156. if (this._maptalks3DModel) {
  40157. var coordSys = this._maptalks3DModel.coordinateSystem;
  40158. var pt = coordSys.dataToPoint(coordSys.center);
  40159. this._groundMesh.position.set(pt[0], pt[1], -0.001);
  40160. var plane = new __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Plane(new __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Vector3(0, 0, 1), 0);
  40161. var ray1 = coordSys.viewGL.camera.castRay(new __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Vector2(-1, -1));
  40162. var ray2 = coordSys.viewGL.camera.castRay(new __WEBPACK_IMPORTED_MODULE_3__util_graphicGL__["a" /* default */].Vector2(1, 1));
  40163. var pos0 = ray1.intersectPlane(plane);
  40164. var pos1 = ray2.intersectPlane(plane);
  40165. var scale = pos0.dist(pos1) / coordSys.viewGL.rootNode.scale.x;
  40166. this._groundMesh.scale.set(scale, scale, 1);
  40167. }
  40168. },
  40169. dispose: function (ecModel, api) {
  40170. if (this._zrLayer) {
  40171. this._zrLayer.dispose();
  40172. }
  40173. api.getZr().painter.delLayer(-1000);
  40174. }
  40175. }));
  40176. /***/
  40177. }),
  40178. /* 224 */
  40179. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  40180. "use strict";
  40181. /**
  40182. * @constructor
  40183. * @alias module:echarts-gl/component/maptalks/Maptalks3DLayer
  40184. * @param {string} id Layer ID
  40185. * @param {module:zrender/ZRender} zr
  40186. */
  40187. function Maptalks3DLayer(id, zr, defaultCenter, defaultZoom) {
  40188. this.id = id;
  40189. this.zr = zr;
  40190. this.dom = document.createElement('div');
  40191. this.dom.style.cssText = 'position:absolute;left:0;right:0;top:0;bottom:0;';
  40192. // FIXME If in module environment.
  40193. if (!maptalks) {
  40194. throw new Error('Maptalks library must be included. See https://maptalks.org');
  40195. }
  40196. this._maptalks = new maptalks.Map(this.dom, {
  40197. center: defaultCenter,
  40198. zoom: defaultZoom,
  40199. fog: false
  40200. // fogColor: [0, 0, 0]
  40201. });
  40202. // Proxy events
  40203. this._initEvents();
  40204. }
  40205. Maptalks3DLayer.prototype.resize = function () {
  40206. this._maptalks.checkSize();
  40207. };
  40208. Maptalks3DLayer.prototype.getMaptalks = function () {
  40209. return this._maptalks;
  40210. };
  40211. Maptalks3DLayer.prototype.clear = function () { };
  40212. Maptalks3DLayer.prototype.refresh = function () {
  40213. this._maptalks.checkSize();
  40214. };
  40215. var EVENTS = ['mousedown', 'mouseup', 'click', 'dblclick', 'mousemove',
  40216. 'mousewheel', 'DOMMouseScroll',
  40217. 'touchstart', 'touchend', 'touchmove', 'touchcancel'
  40218. ];
  40219. Maptalks3DLayer.prototype._initEvents = function () {
  40220. // Event is bound on canvas container.
  40221. var maptalksRoot = this.dom;
  40222. this._handlers = this._handlers || {
  40223. contextmenu: function (e) {
  40224. e.preventDefault();
  40225. return false;
  40226. }
  40227. };
  40228. EVENTS.forEach(function (eName) {
  40229. this._handlers[eName] = function (e) {
  40230. var obj = {};
  40231. for (var name in e) {
  40232. obj[name] = e[name];
  40233. }
  40234. obj.bubbles = false;
  40235. var newE = new e.constructor(e.type, obj);
  40236. if (eName === 'mousewheel' || eName === 'DOMMouseScroll') {
  40237. // maptalks listens events to different elements?
  40238. maptalksRoot.dispatchEvent(newE);
  40239. }
  40240. else {
  40241. maptalksRoot.firstElementChild.dispatchEvent(newE);
  40242. }
  40243. };
  40244. this.zr.dom.addEventListener(eName, this._handlers[eName]);
  40245. }, this);
  40246. // PENDING
  40247. this.zr.dom.addEventListener('contextmenu', this._handlers.contextmenu);
  40248. };
  40249. Maptalks3DLayer.prototype.dispose = function () {
  40250. EVENTS.forEach(function (eName) {
  40251. this.zr.dom.removeEventListener(eName, this._handlers[eName]);
  40252. }, this);
  40253. this._maptalks.remove();
  40254. };
  40255. /* harmony default export */ __webpack_exports__["a"] = (Maptalks3DLayer);
  40256. /***/
  40257. }),
  40258. /* 225 */
  40259. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  40260. "use strict";
  40261. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  40262. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  40263. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__bar3D_bar3DLayout__ = __webpack_require__(226);
  40264. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__bar3D_Bar3DView__ = __webpack_require__(229);
  40265. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__bar3D_Bar3DSeries__ = __webpack_require__(231);
  40266. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__common_opacityVisual__ = __webpack_require__(17);
  40267. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerVisual(Object(__WEBPACK_IMPORTED_MODULE_4__common_opacityVisual__["a" /* default */])('bar3D'));
  40268. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerProcessor(function (ecModel, api) {
  40269. ecModel.eachSeriesByType('bar3d', function (seriesModel) {
  40270. var data = seriesModel.getData();
  40271. data.filterSelf(function (idx) {
  40272. return data.hasValue(idx);
  40273. });
  40274. });
  40275. });
  40276. /***/
  40277. }),
  40278. /* 226 */
  40279. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  40280. "use strict";
  40281. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  40282. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  40283. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_math_Vector3__ = __webpack_require__(3);
  40284. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_claygl_src_dep_glmatrix__ = __webpack_require__(6);
  40285. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__cartesian3DLayout__ = __webpack_require__(227);
  40286. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__evaluateBarSparseness__ = __webpack_require__(228);
  40287. var vec3 = __WEBPACK_IMPORTED_MODULE_2_claygl_src_dep_glmatrix__["a" /* default */].vec3;
  40288. var isDimensionStacked = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.helper.dataStack.isDimensionStacked;
  40289. function globeLayout(seriesModel, coordSys) {
  40290. var data = seriesModel.getData();
  40291. var barMinHeight = seriesModel.get('minHeight') || 0;
  40292. var barSize = seriesModel.get('barSize');
  40293. var dims = ['lng', 'lat', 'alt'].map(function (coordDimName) {
  40294. return seriesModel.coordDimToDataDim(coordDimName)[0];
  40295. });
  40296. if (barSize == null) {
  40297. var perimeter = coordSys.radius * Math.PI;
  40298. var fillRatio = Object(__WEBPACK_IMPORTED_MODULE_4__evaluateBarSparseness__["a" /* default */])(data, dims[0], dims[1]);
  40299. barSize = [
  40300. perimeter / Math.sqrt(data.count() / fillRatio),
  40301. perimeter / Math.sqrt(data.count() / fillRatio)
  40302. ];
  40303. }
  40304. else if (!__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.isArray(barSize)) {
  40305. barSize = [barSize, barSize];
  40306. }
  40307. var valueDim = getValueDimension(data, dims);
  40308. data.each(dims, function (lng, lat, val, idx) {
  40309. var stackedValue = data.get(valueDim.dimension, idx);
  40310. var baseValue = valueDim.isStacked ? (stackedValue - val) : coordSys.altitudeAxis.scale.getExtent()[0];
  40311. // TODO Stacked with minHeight.
  40312. var height = Math.max(coordSys.altitudeAxis.dataToCoord(val), barMinHeight);
  40313. var start = coordSys.dataToPoint([lng, lat, baseValue]);
  40314. var end = coordSys.dataToPoint([lng, lat, stackedValue]);
  40315. var dir = vec3.sub([], end, start);
  40316. vec3.normalize(dir, dir);
  40317. var size = [barSize[0], height, barSize[1]];
  40318. data.setItemLayout(idx, [start, dir, size]);
  40319. });
  40320. data.setLayout('orient', __WEBPACK_IMPORTED_MODULE_1_claygl_src_math_Vector3__["a" /* default */].UP.array);
  40321. }
  40322. function geo3DLayout(seriesModel, coordSys) {
  40323. var data = seriesModel.getData();
  40324. var barSize = seriesModel.get('barSize');
  40325. var barMinHeight = seriesModel.get('minHeight') || 0;
  40326. var dims = ['lng', 'lat', 'alt'].map(function (coordDimName) {
  40327. return seriesModel.coordDimToDataDim(coordDimName)[0];
  40328. });
  40329. if (barSize == null) {
  40330. var size = Math.min(coordSys.size[0], coordSys.size[2]);
  40331. var fillRatio = Object(__WEBPACK_IMPORTED_MODULE_4__evaluateBarSparseness__["a" /* default */])(data, dims[0], dims[1]);
  40332. barSize = [
  40333. size / Math.sqrt(data.count() / fillRatio),
  40334. size / Math.sqrt(data.count() / fillRatio)
  40335. ];
  40336. }
  40337. else if (!__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.isArray(barSize)) {
  40338. barSize = [barSize, barSize];
  40339. }
  40340. var dir = [0, 1, 0];
  40341. var valueDim = getValueDimension(data, dims);
  40342. data.each(dims, function (lng, lat, val, idx) {
  40343. var stackedValue = data.get(valueDim.dimension, idx);
  40344. var baseValue = valueDim.isStacked ? (stackedValue - val) : coordSys.altitudeAxis.scale.getExtent()[0];
  40345. var height = Math.max(coordSys.altitudeAxis.dataToCoord(val), barMinHeight);
  40346. var start = coordSys.dataToPoint([lng, lat, baseValue]);
  40347. var size = [barSize[0], height, barSize[1]];
  40348. data.setItemLayout(idx, [start, dir, size]);
  40349. });
  40350. data.setLayout('orient', [1, 0, 0]);
  40351. }
  40352. function mapService3DLayout(seriesModel, coordSys) {
  40353. var data = seriesModel.getData();
  40354. var dimLng = seriesModel.coordDimToDataDim('lng')[0];
  40355. var dimLat = seriesModel.coordDimToDataDim('lat')[0];
  40356. var dimAlt = seriesModel.coordDimToDataDim('alt')[0];
  40357. var barSize = seriesModel.get('barSize');
  40358. var barMinHeight = seriesModel.get('minHeight') || 0;
  40359. if (barSize == null) {
  40360. var xExtent = data.getDataExtent(dimLng);
  40361. var yExtent = data.getDataExtent(dimLat);
  40362. var corner0 = coordSys.dataToPoint([xExtent[0], yExtent[0]]);
  40363. var corner1 = coordSys.dataToPoint([xExtent[1], yExtent[1]]);
  40364. var size = Math.min(
  40365. Math.abs(corner0[0] - corner1[0]),
  40366. Math.abs(corner0[1] - corner1[1])
  40367. ) || 1;
  40368. var fillRatio = Object(__WEBPACK_IMPORTED_MODULE_4__evaluateBarSparseness__["a" /* default */])(data, dimLng, dimLat);
  40369. // PENDING, data density
  40370. barSize = [
  40371. size / Math.sqrt(data.count() / fillRatio),
  40372. size / Math.sqrt(data.count() / fillRatio)
  40373. ];
  40374. }
  40375. else {
  40376. if (!__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.isArray(barSize)) {
  40377. barSize = [barSize, barSize];
  40378. }
  40379. barSize[0] /= coordSys.getScale() / 16;
  40380. barSize[1] /= coordSys.getScale() / 16;
  40381. }
  40382. var dir = [0, 0, 1];
  40383. var dims = [dimLng, dimLat, dimAlt];
  40384. var valueDim = getValueDimension(data, dims);
  40385. data.each(dims, function (lng, lat, val, idx) {
  40386. var stackedValue = data.get(valueDim.dimension, idx);
  40387. var baseValue = valueDim.isStacked ? (stackedValue - val) : 0;
  40388. var start = coordSys.dataToPoint([lng, lat, baseValue]);
  40389. var end = coordSys.dataToPoint([lng, lat, stackedValue]);
  40390. var height = Math.max(end[2] - start[2], barMinHeight);
  40391. var size = [barSize[0], height, barSize[1]];
  40392. data.setItemLayout(idx, [start, dir, size]);
  40393. });
  40394. data.setLayout('orient', [1, 0, 0]);
  40395. }
  40396. function getValueDimension(data, dataDims) {
  40397. var isStacked = isDimensionStacked(data, dataDims[2]);
  40398. return {
  40399. dimension: isStacked
  40400. ? data.getCalculationInfo('stackResultDimension')
  40401. : dataDims[2],
  40402. isStacked: isStacked
  40403. };
  40404. }
  40405. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerLayout(function (ecModel, api) {
  40406. ecModel.eachSeriesByType('bar3D', function (seriesModel) {
  40407. var coordSys = seriesModel.coordinateSystem;
  40408. var coordSysType = coordSys && coordSys.type;
  40409. if (coordSysType === 'globe') {
  40410. globeLayout(seriesModel, coordSys);
  40411. }
  40412. else if (coordSysType === 'cartesian3D') {
  40413. Object(__WEBPACK_IMPORTED_MODULE_3__cartesian3DLayout__["a" /* default */])(seriesModel, coordSys);
  40414. }
  40415. else if (coordSysType === 'geo3D') {
  40416. geo3DLayout(seriesModel, coordSys);
  40417. }
  40418. else if (coordSysType === 'mapbox3D' || coordSysType === 'maptalks3D') {
  40419. mapService3DLayout(seriesModel, coordSys);
  40420. }
  40421. else {
  40422. if (true) {
  40423. if (!coordSys) {
  40424. throw new Error('bar3D doesn\'t have coordinate system.');
  40425. }
  40426. else {
  40427. throw new Error('bar3D doesn\'t support coordinate system ' + coordSys.type);
  40428. }
  40429. }
  40430. }
  40431. });
  40432. });
  40433. /***/
  40434. }),
  40435. /* 227 */
  40436. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  40437. "use strict";
  40438. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  40439. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  40440. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_dep_glmatrix__ = __webpack_require__(6);
  40441. var vec3 = __WEBPACK_IMPORTED_MODULE_1_claygl_src_dep_glmatrix__["a" /* default */].vec3;
  40442. var isDimensionStacked = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.helper.dataStack.isDimensionStacked;
  40443. function ifCrossZero(extent) {
  40444. var min = extent[0];
  40445. var max = extent[1];
  40446. return !((min > 0 && max > 0) || (min < 0 && max < 0));
  40447. };
  40448. function cartesian3DLayout(seriesModel, coordSys) {
  40449. var data = seriesModel.getData();
  40450. // var barOnPlane = seriesModel.get('onGridPlane');
  40451. var barSize = seriesModel.get('barSize');
  40452. if (barSize == null) {
  40453. var size = coordSys.size;
  40454. var barWidth;
  40455. var barDepth;
  40456. var xAxis = coordSys.getAxis('x');
  40457. var yAxis = coordSys.getAxis('y');
  40458. if (xAxis.type === 'category') {
  40459. barWidth = xAxis.getBandWidth() * 0.7;
  40460. }
  40461. else {
  40462. // PENDING
  40463. barWidth = Math.round(size[0] / Math.sqrt(data.count())) * 0.6;
  40464. }
  40465. if (yAxis.type === 'category') {
  40466. barDepth = yAxis.getBandWidth() * 0.7;
  40467. }
  40468. else {
  40469. barDepth = Math.round(size[1] / Math.sqrt(data.count())) * 0.6;
  40470. }
  40471. barSize = [barWidth, barDepth];
  40472. }
  40473. else if (!__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.isArray(barSize)) {
  40474. barSize = [barSize, barSize];
  40475. }
  40476. var zAxisExtent = coordSys.getAxis('z').scale.getExtent();
  40477. var ifZAxisCrossZero = ifCrossZero(zAxisExtent);
  40478. var dims = ['x', 'y', 'z'].map(function (coordDimName) {
  40479. return seriesModel.coordDimToDataDim(coordDimName)[0];
  40480. });
  40481. var isStacked = isDimensionStacked(data, dims[2]);
  40482. var valueDim = isStacked
  40483. ? data.getCalculationInfo('stackResultDimension')
  40484. : dims[2];
  40485. data.each(dims, function (x, y, z, idx) {
  40486. // TODO zAxis is inversed
  40487. // TODO On different plane.
  40488. var stackedValue = data.get(valueDim, idx);
  40489. var baseValue = isStacked ? (stackedValue - z)
  40490. : (ifZAxisCrossZero ? 0 : zAxisExtent[0]);
  40491. var start = coordSys.dataToPoint([x, y, baseValue]);
  40492. var end = coordSys.dataToPoint([x, y, stackedValue]);
  40493. var height = vec3.dist(start, end);
  40494. // PENDING When zAxis is not cross zero.
  40495. var dir = [0, end[1] < start[1] ? -1 : 1, 0];
  40496. if (Math.abs(height) === 0) {
  40497. // TODO
  40498. height = 0.1;
  40499. }
  40500. var size = [barSize[0], height, barSize[1]];
  40501. data.setItemLayout(idx, [start, dir, size]);
  40502. });
  40503. data.setLayout('orient', [1, 0, 0]);
  40504. }
  40505. /* harmony default export */ __webpack_exports__["a"] = (cartesian3DLayout);
  40506. /***/
  40507. }),
  40508. /* 228 */
  40509. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  40510. "use strict";
  40511. /* harmony default export */ __webpack_exports__["a"] = (function (data, dimX, dimY) {
  40512. var xExtent = data.getDataExtent(dimX);
  40513. var yExtent = data.getDataExtent(dimY);
  40514. // TODO Handle one data situation
  40515. var xSpan = (xExtent[1] - xExtent[0]) || xExtent[0];
  40516. var ySpan = (yExtent[1] - yExtent[0]) || yExtent[0];
  40517. var dimSize = 50;
  40518. var tmp = new Uint8Array(dimSize * dimSize);
  40519. for (var i = 0; i < data.count(); i++) {
  40520. var x = data.get(dimX, i);
  40521. var y = data.get(dimY, i);
  40522. var xIdx = Math.floor((x - xExtent[0]) / xSpan * (dimSize - 1));
  40523. var yIdx = Math.floor((y - yExtent[0]) / ySpan * (dimSize - 1));
  40524. var idx = yIdx * dimSize + xIdx;
  40525. tmp[idx] = tmp[idx] || 1;
  40526. }
  40527. var filledCount = 0;
  40528. for (var i = 0; i < tmp.length; i++) {
  40529. if (tmp[i]) {
  40530. filledCount++;
  40531. }
  40532. }
  40533. return filledCount / tmp.length;
  40534. });;
  40535. /***/
  40536. }),
  40537. /* 229 */
  40538. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  40539. "use strict";
  40540. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  40541. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  40542. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__ = __webpack_require__(1);
  40543. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_retrieve__ = __webpack_require__(2);
  40544. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__util_format__ = __webpack_require__(32);
  40545. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__util_geometry_Bars3DGeometry__ = __webpack_require__(230);
  40546. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__component_common_LabelsBuilder__ = __webpack_require__(66);
  40547. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_claygl_src_dep_glmatrix__ = __webpack_require__(6);
  40548. var vec3 = __WEBPACK_IMPORTED_MODULE_6_claygl_src_dep_glmatrix__["a" /* default */].vec3;
  40549. /* unused harmony default export */ var _unused_webpack_default_export = (__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendChartView({
  40550. type: 'bar3D',
  40551. __ecgl__: true,
  40552. init: function (ecModel, api) {
  40553. this.groupGL = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Node();
  40554. this._api = api;
  40555. this._labelsBuilder = new __WEBPACK_IMPORTED_MODULE_5__component_common_LabelsBuilder__["a" /* default */](256, 256, api);
  40556. var self = this;
  40557. this._labelsBuilder.getLabelPosition = function (dataIndex, position, distance) {
  40558. if (self._data) {
  40559. var layout = self._data.getItemLayout(dataIndex);
  40560. var start = layout[0];
  40561. var dir = layout[1];
  40562. var height = layout[2][1];
  40563. return vec3.scaleAndAdd([], start, dir, distance + height);
  40564. }
  40565. else {
  40566. return [0, 0];
  40567. }
  40568. };
  40569. // Give a large render order.
  40570. this._labelsBuilder.getMesh().renderOrder = 100;
  40571. },
  40572. render: function (seriesModel, ecModel, api) {
  40573. // Swap barMesh
  40574. var tmp = this._prevBarMesh;
  40575. this._prevBarMesh = this._barMesh;
  40576. this._barMesh = tmp;
  40577. if (!this._barMesh) {
  40578. this._barMesh = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh({
  40579. geometry: new __WEBPACK_IMPORTED_MODULE_4__util_geometry_Bars3DGeometry__["a" /* default */](),
  40580. shadowDepthMaterial: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Material({
  40581. shader: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader(
  40582. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader.source('ecgl.sm.depth.vertex'),
  40583. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader.source('ecgl.sm.depth.fragment')
  40584. )
  40585. }),
  40586. // Only cartesian3D enable culling
  40587. // FIXME Performance
  40588. culling: seriesModel.coordinateSystem.type === 'cartesian3D',
  40589. // Render after axes
  40590. renderOrder: 10,
  40591. // Render normal in normal pass
  40592. renderNormal: true
  40593. });
  40594. }
  40595. this.groupGL.remove(this._prevBarMesh);
  40596. this.groupGL.add(this._barMesh);
  40597. this.groupGL.add(this._labelsBuilder.getMesh());
  40598. var coordSys = seriesModel.coordinateSystem;
  40599. this._doRender(seriesModel, api);
  40600. if (coordSys && coordSys.viewGL) {
  40601. coordSys.viewGL.add(this.groupGL);
  40602. var methodName = coordSys.viewGL.isLinearSpace() ? 'define' : 'undefine';
  40603. this._barMesh.material[methodName]('fragment', 'SRGB_DECODE');
  40604. }
  40605. this._data = seriesModel.getData();
  40606. this._labelsBuilder.updateData(this._data);
  40607. this._labelsBuilder.updateLabels();
  40608. this._updateAnimation(seriesModel);
  40609. },
  40610. _updateAnimation: function (seriesModel) {
  40611. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].updateVertexAnimation(
  40612. [['prevPosition', 'position'],
  40613. ['prevNormal', 'normal']],
  40614. this._prevBarMesh,
  40615. this._barMesh,
  40616. seriesModel
  40617. );
  40618. },
  40619. _doRender: function (seriesModel, api) {
  40620. var data = seriesModel.getData();
  40621. var shading = seriesModel.get('shading');
  40622. var enableNormal = shading !== 'color';
  40623. var self = this;
  40624. var barMesh = this._barMesh;
  40625. var shadingPrefix = 'ecgl.' + shading;
  40626. if (!barMesh.material || barMesh.material.shader.name !== shadingPrefix) {
  40627. barMesh.material = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].createMaterial(shadingPrefix, ['VERTEX_COLOR']);
  40628. }
  40629. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].setMaterialFromModel(
  40630. shading, barMesh.material, seriesModel, api
  40631. );
  40632. barMesh.geometry.enableNormal = enableNormal;
  40633. barMesh.geometry.resetOffset();
  40634. // Bevel settings
  40635. var bevelSize = seriesModel.get('bevelSize');
  40636. var bevelSegments = seriesModel.get('bevelSmoothness');
  40637. barMesh.geometry.bevelSegments = bevelSegments;
  40638. barMesh.geometry.bevelSize = bevelSize;
  40639. var colorArr = [];
  40640. var vertexColors = new Float32Array(data.count() * 4);
  40641. var colorOffset = 0;
  40642. var barCount = 0;
  40643. var hasTransparent = false;
  40644. data.each(function (idx) {
  40645. if (!data.hasValue(idx)) {
  40646. return;
  40647. }
  40648. var color = data.getItemVisual(idx, 'color');
  40649. var opacity = data.getItemVisual(idx, 'opacity');
  40650. if (opacity == null) {
  40651. opacity = 1;
  40652. }
  40653. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(color, colorArr);
  40654. colorArr[3] *= opacity;
  40655. vertexColors[colorOffset++] = colorArr[0];
  40656. vertexColors[colorOffset++] = colorArr[1];
  40657. vertexColors[colorOffset++] = colorArr[2];
  40658. vertexColors[colorOffset++] = colorArr[3];
  40659. if (colorArr[3] > 0) {
  40660. barCount++;
  40661. if (colorArr[3] < 0.99) {
  40662. hasTransparent = true;
  40663. }
  40664. }
  40665. });
  40666. barMesh.geometry.setBarCount(barCount);
  40667. var orient = data.getLayout('orient');
  40668. // Map of dataIndex and barIndex.
  40669. var barIndexOfData = this._barIndexOfData = new Int32Array(data.count());
  40670. var barCount = 0;
  40671. data.each(function (idx) {
  40672. if (!data.hasValue(idx)) {
  40673. barIndexOfData[idx] = -1;
  40674. return;
  40675. }
  40676. var layout = data.getItemLayout(idx);
  40677. var start = layout[0];
  40678. var dir = layout[1];
  40679. var size = layout[2];
  40680. var idx4 = idx * 4;
  40681. colorArr[0] = vertexColors[idx4++];
  40682. colorArr[1] = vertexColors[idx4++];
  40683. colorArr[2] = vertexColors[idx4++];
  40684. colorArr[3] = vertexColors[idx4++];
  40685. if (colorArr[3] > 0) {
  40686. self._barMesh.geometry.addBar(start, dir, orient, size, colorArr, idx);
  40687. barIndexOfData[idx] = barCount++;
  40688. }
  40689. });
  40690. barMesh.geometry.dirty();
  40691. barMesh.geometry.updateBoundingBox();
  40692. var material = barMesh.material;
  40693. material.transparent = hasTransparent;
  40694. material.depthMask = !hasTransparent;
  40695. barMesh.geometry.sortTriangles = hasTransparent;
  40696. this._initHandler(seriesModel, api);
  40697. },
  40698. _initHandler: function (seriesModel, api) {
  40699. var data = seriesModel.getData();
  40700. var barMesh = this._barMesh;
  40701. var isCartesian3D = seriesModel.coordinateSystem.type === 'cartesian3D';
  40702. barMesh.seriesIndex = seriesModel.seriesIndex;
  40703. var lastDataIndex = -1;
  40704. barMesh.off('mousemove');
  40705. barMesh.off('mouseout');
  40706. barMesh.on('mousemove', function (e) {
  40707. var dataIndex = barMesh.geometry.getDataIndexOfVertex(e.triangle[0]);
  40708. if (dataIndex !== lastDataIndex) {
  40709. this._downplay(lastDataIndex);
  40710. this._highlight(dataIndex);
  40711. this._labelsBuilder.updateLabels([dataIndex]);
  40712. if (isCartesian3D) {
  40713. api.dispatchAction({
  40714. type: 'grid3DShowAxisPointer',
  40715. value: [data.get('x', dataIndex), data.get('y', dataIndex), data.get('z', dataIndex, true)]
  40716. });
  40717. }
  40718. }
  40719. lastDataIndex = dataIndex;
  40720. barMesh.dataIndex = dataIndex;
  40721. }, this);
  40722. barMesh.on('mouseout', function (e) {
  40723. this._downplay(lastDataIndex);
  40724. this._labelsBuilder.updateLabels();
  40725. lastDataIndex = -1;
  40726. barMesh.dataIndex = -1;
  40727. if (isCartesian3D) {
  40728. api.dispatchAction({
  40729. type: 'grid3DHideAxisPointer'
  40730. });
  40731. }
  40732. }, this);
  40733. },
  40734. _highlight: function (dataIndex) {
  40735. var data = this._data;
  40736. if (!data) {
  40737. return;
  40738. }
  40739. var barIndex = this._barIndexOfData[dataIndex];
  40740. if (barIndex < 0) {
  40741. return;
  40742. }
  40743. var itemModel = data.getItemModel(dataIndex);
  40744. var emphasisItemStyleModel = itemModel.getModel('emphasis.itemStyle');
  40745. var emphasisColor = emphasisItemStyleModel.get('color');
  40746. var emphasisOpacity = emphasisItemStyleModel.get('opacity');
  40747. if (emphasisColor == null) {
  40748. var color = data.getItemVisual(dataIndex, 'color');
  40749. emphasisColor = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.color.lift(color, -0.4);
  40750. }
  40751. if (emphasisOpacity == null) {
  40752. emphasisOpacity = data.getItemVisual(dataIndex, 'opacity');
  40753. }
  40754. var colorArr = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(emphasisColor);
  40755. colorArr[3] *= emphasisOpacity;
  40756. this._barMesh.geometry.setColor(barIndex, colorArr);
  40757. this._api.getZr().refresh();
  40758. },
  40759. _downplay: function (dataIndex) {
  40760. var data = this._data;
  40761. if (!data) {
  40762. return;
  40763. }
  40764. var barIndex = this._barIndexOfData[dataIndex];
  40765. if (barIndex < 0) {
  40766. return;
  40767. }
  40768. var color = data.getItemVisual(dataIndex, 'color');
  40769. var opacity = data.getItemVisual(dataIndex, 'opacity');
  40770. var colorArr = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(color);
  40771. colorArr[3] *= opacity;
  40772. this._barMesh.geometry.setColor(barIndex, colorArr);
  40773. this._api.getZr().refresh();
  40774. },
  40775. highlight: function (seriesModel, ecModel, api, payload) {
  40776. this._toggleStatus('highlight', seriesModel, ecModel, api, payload);
  40777. },
  40778. downplay: function (seriesModel, ecModel, api, payload) {
  40779. this._toggleStatus('downplay', seriesModel, ecModel, api, payload);
  40780. },
  40781. _toggleStatus: function (status, seriesModel, ecModel, api, payload) {
  40782. var data = seriesModel.getData();
  40783. var dataIndex = __WEBPACK_IMPORTED_MODULE_2__util_retrieve__["a" /* default */].queryDataIndex(data, payload);
  40784. var self = this;
  40785. if (dataIndex != null) {
  40786. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.each(__WEBPACK_IMPORTED_MODULE_3__util_format__["a" /* default */].normalizeToArray(dataIndex), function (dataIdx) {
  40787. status === 'highlight' ? this._highlight(dataIdx) : this._downplay(dataIdx);
  40788. }, this);
  40789. }
  40790. else {
  40791. data.each(function (dataIdx) {
  40792. status === 'highlight' ? self._highlight(dataIdx) : self._downplay(dataIdx);
  40793. });
  40794. }
  40795. },
  40796. remove: function () {
  40797. this.groupGL.removeAll();
  40798. },
  40799. dispose: function () {
  40800. this.groupGL.removeAll();
  40801. }
  40802. }));
  40803. /***/
  40804. }),
  40805. /* 230 */
  40806. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  40807. "use strict";
  40808. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  40809. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  40810. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__dynamicConvertMixin__ = __webpack_require__(38);
  40811. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__trianglesSortMixin__ = __webpack_require__(65);
  40812. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_claygl_src_Geometry__ = __webpack_require__(15);
  40813. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_claygl_src_dep_glmatrix__ = __webpack_require__(6);
  40814. /**
  40815. * Geometry collecting bars data
  40816. *
  40817. * @module echarts-gl/chart/bars/BarsGeometry
  40818. * @author Yi Shen(http://github.com/pissang)
  40819. */
  40820. var vec3 = __WEBPACK_IMPORTED_MODULE_4_claygl_src_dep_glmatrix__["a" /* default */].vec3;
  40821. var mat3 = __WEBPACK_IMPORTED_MODULE_4_claygl_src_dep_glmatrix__["a" /* default */].mat3;
  40822. /**
  40823. * @constructor
  40824. * @alias module:echarts-gl/chart/bars/BarsGeometry
  40825. * @extends clay.Geometry
  40826. */
  40827. var BarsGeometry = __WEBPACK_IMPORTED_MODULE_3_claygl_src_Geometry__["a" /* default */].extend(function () {
  40828. return {
  40829. attributes: {
  40830. position: new __WEBPACK_IMPORTED_MODULE_3_claygl_src_Geometry__["a" /* default */].Attribute('position', 'float', 3, 'POSITION'),
  40831. normal: new __WEBPACK_IMPORTED_MODULE_3_claygl_src_Geometry__["a" /* default */].Attribute('normal', 'float', 3, 'NORMAL'),
  40832. color: new __WEBPACK_IMPORTED_MODULE_3_claygl_src_Geometry__["a" /* default */].Attribute('color', 'float', 4, 'COLOR'),
  40833. prevPosition: new __WEBPACK_IMPORTED_MODULE_3_claygl_src_Geometry__["a" /* default */].Attribute('prevPosition', 'float', 3),
  40834. prevNormal: new __WEBPACK_IMPORTED_MODULE_3_claygl_src_Geometry__["a" /* default */].Attribute('prevNormal', 'float', 3)
  40835. },
  40836. dynamic: true,
  40837. enableNormal: false,
  40838. bevelSize: 1,
  40839. bevelSegments: 0,
  40840. // Map from vertexIndex to dataIndex.
  40841. _dataIndices: null,
  40842. _vertexOffset: 0,
  40843. _triangleOffset: 0
  40844. };
  40845. },
  40846. /** @lends module:echarts-gl/chart/bars/BarsGeometry.prototype */
  40847. {
  40848. resetOffset: function () {
  40849. this._vertexOffset = 0;
  40850. this._triangleOffset = 0;
  40851. },
  40852. setBarCount: function (barCount) {
  40853. var enableNormal = this.enableNormal;
  40854. var vertexCount = this.getBarVertexCount() * barCount;
  40855. var triangleCount = this.getBarTriangleCount() * barCount;
  40856. if (this.vertexCount !== vertexCount) {
  40857. this.attributes.position.init(vertexCount);
  40858. if (enableNormal) {
  40859. this.attributes.normal.init(vertexCount);
  40860. }
  40861. else {
  40862. this.attributes.normal.value = null;
  40863. }
  40864. this.attributes.color.init(vertexCount);
  40865. }
  40866. if (this.triangleCount !== triangleCount) {
  40867. this.indices = vertexCount > 0xffff ? new Uint32Array(triangleCount * 3) : new Uint16Array(triangleCount * 3);
  40868. this._dataIndices = new Uint32Array(vertexCount);
  40869. }
  40870. },
  40871. getBarVertexCount: function () {
  40872. var bevelSegments = this.bevelSize > 0 ? this.bevelSegments : 0;
  40873. return bevelSegments > 0 ? this._getBevelBarVertexCount(bevelSegments)
  40874. : (this.enableNormal ? 24 : 8);
  40875. },
  40876. getBarTriangleCount: function () {
  40877. var bevelSegments = this.bevelSize > 0 ? this.bevelSegments : 0;
  40878. return bevelSegments > 0 ? this._getBevelBarTriangleCount(bevelSegments)
  40879. : 12;
  40880. },
  40881. _getBevelBarVertexCount: function (bevelSegments) {
  40882. return (bevelSegments + 1) * 4 * (bevelSegments + 1) * 2;
  40883. },
  40884. _getBevelBarTriangleCount: function (bevelSegments) {
  40885. var widthSegments = bevelSegments * 4 + 3;
  40886. var heightSegments = bevelSegments * 2 + 1;
  40887. return (widthSegments + 1) * heightSegments * 2 + 4;
  40888. },
  40889. setColor: function (idx, color) {
  40890. var vertexCount = this.getBarVertexCount();
  40891. var start = vertexCount * idx;
  40892. var end = vertexCount * (idx + 1);
  40893. for (var i = start; i < end; i++) {
  40894. this.attributes.color.set(i, color);
  40895. }
  40896. this.dirtyAttribute('color');
  40897. },
  40898. /**
  40899. * Get dataIndex of vertex.
  40900. * @param {number} vertexIndex
  40901. */
  40902. getDataIndexOfVertex: function (vertexIndex) {
  40903. return this._dataIndices ? this._dataIndices[vertexIndex] : null;
  40904. },
  40905. /**
  40906. * Add a bar
  40907. * @param {Array.<number>} start
  40908. * @param {Array.<number>} end
  40909. * @param {Array.<number>} orient right direction
  40910. * @param {Array.<number>} size size on x and z
  40911. * @param {Array.<number>} color
  40912. */
  40913. addBar: (function () {
  40914. var v3Create = vec3.create;
  40915. var v3ScaleAndAdd = vec3.scaleAndAdd;
  40916. var end = v3Create();
  40917. var px = v3Create();
  40918. var py = v3Create();
  40919. var pz = v3Create();
  40920. var nx = v3Create();
  40921. var ny = v3Create();
  40922. var nz = v3Create();
  40923. var pts = [];
  40924. var normals = [];
  40925. for (var i = 0; i < 8; i++) {
  40926. pts[i] = v3Create();
  40927. }
  40928. var cubeFaces4 = [
  40929. // PX
  40930. [0, 1, 5, 4],
  40931. // NX
  40932. [2, 3, 7, 6],
  40933. // PY
  40934. [4, 5, 6, 7],
  40935. // NY
  40936. [3, 2, 1, 0],
  40937. // PZ
  40938. [0, 4, 7, 3],
  40939. // NZ
  40940. [1, 2, 6, 5]
  40941. ];
  40942. var face4To3 = [
  40943. 0, 1, 2, 0, 2, 3
  40944. ];
  40945. var cubeFaces3 = [];
  40946. for (var i = 0; i < cubeFaces4.length; i++) {
  40947. var face4 = cubeFaces4[i];
  40948. for (var j = 0; j < 2; j++) {
  40949. var face = [];
  40950. for (var k = 0; k < 3; k++) {
  40951. face.push(face4[face4To3[j * 3 + k]]);
  40952. }
  40953. cubeFaces3.push(face);
  40954. }
  40955. }
  40956. return function (start, dir, leftDir, size, color, dataIndex) {
  40957. // Use vertex, triangle maybe sorted.
  40958. var startVertex = this._vertexOffset;
  40959. if (this.bevelSize > 0 && this.bevelSegments > 0) {
  40960. this._addBevelBar(start, dir, leftDir, size, this.bevelSize, this.bevelSegments, color);
  40961. }
  40962. else {
  40963. vec3.copy(py, dir);
  40964. vec3.normalize(py, py);
  40965. // x * y => z
  40966. vec3.cross(pz, leftDir, py);
  40967. vec3.normalize(pz, pz);
  40968. // y * z => x
  40969. vec3.cross(px, py, pz);
  40970. vec3.normalize(pz, pz);
  40971. vec3.negate(nx, px);
  40972. vec3.negate(ny, py);
  40973. vec3.negate(nz, pz);
  40974. v3ScaleAndAdd(pts[0], start, px, size[0] / 2);
  40975. v3ScaleAndAdd(pts[0], pts[0], pz, size[2] / 2);
  40976. v3ScaleAndAdd(pts[1], start, px, size[0] / 2);
  40977. v3ScaleAndAdd(pts[1], pts[1], nz, size[2] / 2);
  40978. v3ScaleAndAdd(pts[2], start, nx, size[0] / 2);
  40979. v3ScaleAndAdd(pts[2], pts[2], nz, size[2] / 2);
  40980. v3ScaleAndAdd(pts[3], start, nx, size[0] / 2);
  40981. v3ScaleAndAdd(pts[3], pts[3], pz, size[2] / 2);
  40982. v3ScaleAndAdd(end, start, py, size[1]);
  40983. v3ScaleAndAdd(pts[4], end, px, size[0] / 2);
  40984. v3ScaleAndAdd(pts[4], pts[4], pz, size[2] / 2);
  40985. v3ScaleAndAdd(pts[5], end, px, size[0] / 2);
  40986. v3ScaleAndAdd(pts[5], pts[5], nz, size[2] / 2);
  40987. v3ScaleAndAdd(pts[6], end, nx, size[0] / 2);
  40988. v3ScaleAndAdd(pts[6], pts[6], nz, size[2] / 2);
  40989. v3ScaleAndAdd(pts[7], end, nx, size[0] / 2);
  40990. v3ScaleAndAdd(pts[7], pts[7], pz, size[2] / 2);
  40991. var attributes = this.attributes;
  40992. if (this.enableNormal) {
  40993. normals[0] = px;
  40994. normals[1] = nx;
  40995. normals[2] = py;
  40996. normals[3] = ny;
  40997. normals[4] = pz;
  40998. normals[5] = nz;
  40999. var vertexOffset = this._vertexOffset;
  41000. for (var i = 0; i < cubeFaces4.length; i++) {
  41001. var idx3 = this._triangleOffset * 3;
  41002. for (var k = 0; k < 6; k++) {
  41003. this.indices[idx3++] = vertexOffset + face4To3[k];
  41004. }
  41005. vertexOffset += 4;
  41006. this._triangleOffset += 2;
  41007. }
  41008. for (var i = 0; i < cubeFaces4.length; i++) {
  41009. var normal = normals[i];
  41010. for (var k = 0; k < 4; k++) {
  41011. var idx = cubeFaces4[i][k];
  41012. attributes.position.set(this._vertexOffset, pts[idx]);
  41013. attributes.normal.set(this._vertexOffset, normal);
  41014. attributes.color.set(this._vertexOffset++, color);
  41015. }
  41016. }
  41017. }
  41018. else {
  41019. for (var i = 0; i < cubeFaces3.length; i++) {
  41020. var idx3 = this._triangleOffset * 3;
  41021. for (var k = 0; k < 3; k++) {
  41022. this.indices[idx3 + k] = cubeFaces3[i][k] + this._vertexOffset;
  41023. }
  41024. this._triangleOffset++;
  41025. }
  41026. for (var i = 0; i < pts.length; i++) {
  41027. attributes.position.set(this._vertexOffset, pts[i]);
  41028. attributes.color.set(this._vertexOffset++, color);
  41029. }
  41030. }
  41031. }
  41032. var endVerex = this._vertexOffset;
  41033. for (var i = startVertex; i < endVerex; i++) {
  41034. this._dataIndices[i] = dataIndex;
  41035. }
  41036. };
  41037. })(),
  41038. /**
  41039. * Add a bar with bevel
  41040. * @param {Array.<number>} start
  41041. * @param {Array.<number>} end
  41042. * @param {Array.<number>} orient right direction
  41043. * @param {Array.<number>} size size on x and z
  41044. * @param {number} bevelSize
  41045. * @param {number} bevelSegments
  41046. * @param {Array.<number>} color
  41047. */
  41048. _addBevelBar: (function () {
  41049. var px = vec3.create();
  41050. var py = vec3.create();
  41051. var pz = vec3.create();
  41052. var rotateMat = mat3.create();
  41053. var bevelStartSize = [];
  41054. var xOffsets = [1, -1, -1, 1];
  41055. var zOffsets = [1, 1, -1, -1];
  41056. var yOffsets = [2, 0];
  41057. return function (start, dir, leftDir, size, bevelSize, bevelSegments, color) {
  41058. vec3.copy(py, dir);
  41059. vec3.normalize(py, py);
  41060. // x * y => z
  41061. vec3.cross(pz, leftDir, py);
  41062. vec3.normalize(pz, pz);
  41063. // y * z => x
  41064. vec3.cross(px, py, pz);
  41065. vec3.normalize(pz, pz);
  41066. rotateMat[0] = px[0]; rotateMat[1] = px[1]; rotateMat[2] = px[2];
  41067. rotateMat[3] = py[0]; rotateMat[4] = py[1]; rotateMat[5] = py[2];
  41068. rotateMat[6] = pz[0]; rotateMat[7] = pz[1]; rotateMat[8] = pz[2];
  41069. bevelSize = Math.min(size[0], size[2]) / 2 * bevelSize;
  41070. for (var i = 0; i < 3; i++) {
  41071. bevelStartSize[i] = Math.max(size[i] - bevelSize * 2, 0);
  41072. }
  41073. var rx = (size[0] - bevelStartSize[0]) / 2;
  41074. var ry = (size[1] - bevelStartSize[1]) / 2;
  41075. var rz = (size[2] - bevelStartSize[2]) / 2;
  41076. var pos = [];
  41077. var normal = [];
  41078. var vertexOffset = this._vertexOffset;
  41079. var endIndices = [];
  41080. for (var i = 0; i < 2; i++) {
  41081. endIndices[i] = endIndices[i] = [];
  41082. for (var m = 0; m <= bevelSegments; m++) {
  41083. for (var j = 0; j < 4; j++) {
  41084. if ((m === 0 && i === 0) || (i === 1 && m === bevelSegments)) {
  41085. endIndices[i].push(vertexOffset);
  41086. }
  41087. for (var n = 0; n <= bevelSegments; n++) {
  41088. var phi = n / bevelSegments * Math.PI / 2 + Math.PI / 2 * j;
  41089. var theta = m / bevelSegments * Math.PI / 2 + Math.PI / 2 * i;
  41090. // var r = rx < ry ? (rz < rx ? rz : rx) : (rz < ry ? rz : ry);
  41091. normal[0] = rx * Math.cos(phi) * Math.sin(theta);
  41092. normal[1] = ry * Math.cos(theta);
  41093. normal[2] = rz * Math.sin(phi) * Math.sin(theta);
  41094. pos[0] = normal[0] + xOffsets[j] * bevelStartSize[0] / 2;
  41095. pos[1] = (normal[1] + ry) + yOffsets[i] * bevelStartSize[1] / 2;
  41096. pos[2] = normal[2] + zOffsets[j] * bevelStartSize[2] / 2;
  41097. // Normal is not right if rx, ry, rz not equal.
  41098. if (!(Math.abs(rx - ry) < 1e-6 && Math.abs(ry - rz) < 1e-6)) {
  41099. normal[0] /= rx * rx;
  41100. normal[1] /= ry * ry;
  41101. normal[2] /= rz * rz;
  41102. }
  41103. vec3.normalize(normal, normal);
  41104. vec3.transformMat3(pos, pos, rotateMat);
  41105. vec3.transformMat3(normal, normal, rotateMat);
  41106. vec3.add(pos, pos, start);
  41107. this.attributes.position.set(vertexOffset, pos);
  41108. if (this.enableNormal) {
  41109. this.attributes.normal.set(vertexOffset, normal);
  41110. }
  41111. this.attributes.color.set(vertexOffset, color);
  41112. vertexOffset++;
  41113. }
  41114. }
  41115. }
  41116. }
  41117. var widthSegments = bevelSegments * 4 + 3;
  41118. var heightSegments = bevelSegments * 2 + 1;
  41119. var len = widthSegments + 1;
  41120. for (var j = 0; j < heightSegments; j++) {
  41121. for (var i = 0; i <= widthSegments; i++) {
  41122. var i2 = j * len + i + this._vertexOffset;
  41123. var i1 = (j * len + (i + 1) % len) + this._vertexOffset;
  41124. var i4 = (j + 1) * len + (i + 1) % len + this._vertexOffset;
  41125. var i3 = (j + 1) * len + i + this._vertexOffset;
  41126. this.setTriangleIndices(this._triangleOffset++, [i4, i2, i1]);
  41127. this.setTriangleIndices(this._triangleOffset++, [i4, i3, i2]);
  41128. }
  41129. }
  41130. // Close top and bottom
  41131. this.setTriangleIndices(this._triangleOffset++, [endIndices[0][0], endIndices[0][2], endIndices[0][1]]);
  41132. this.setTriangleIndices(this._triangleOffset++, [endIndices[0][0], endIndices[0][3], endIndices[0][2]]);
  41133. this.setTriangleIndices(this._triangleOffset++, [endIndices[1][0], endIndices[1][1], endIndices[1][2]]);
  41134. this.setTriangleIndices(this._triangleOffset++, [endIndices[1][0], endIndices[1][2], endIndices[1][3]]);
  41135. this._vertexOffset = vertexOffset;
  41136. };
  41137. })()
  41138. });
  41139. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.defaults(BarsGeometry.prototype, __WEBPACK_IMPORTED_MODULE_1__dynamicConvertMixin__["a" /* default */]);
  41140. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.defaults(BarsGeometry.prototype, __WEBPACK_IMPORTED_MODULE_2__trianglesSortMixin__["a" /* default */]);
  41141. /* harmony default export */ __webpack_exports__["a"] = (BarsGeometry);
  41142. /***/
  41143. }),
  41144. /* 231 */
  41145. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  41146. "use strict";
  41147. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  41148. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  41149. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__component_common_componentShadingMixin__ = __webpack_require__(31);
  41150. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_format__ = __webpack_require__(32);
  41151. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__common_formatTooltip__ = __webpack_require__(39);
  41152. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__common_createList__ = __webpack_require__(50);
  41153. var Bar3DSeries = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendSeriesModel({
  41154. type: 'series.bar3D',
  41155. dependencies: ['globe'],
  41156. visualColorAccessPath: 'itemStyle.color',
  41157. getInitialData: function (option, ecModel) {
  41158. return Object(__WEBPACK_IMPORTED_MODULE_4__common_createList__["a" /* default */])(this);
  41159. },
  41160. getFormattedLabel: function (dataIndex, status, dataType, dimIndex) {
  41161. var text = __WEBPACK_IMPORTED_MODULE_2__util_format__["a" /* default */].getFormattedLabel(this, dataIndex, status, dataType, dimIndex);
  41162. if (text == null) {
  41163. text = this.getData().get('z', dataIndex);
  41164. }
  41165. return text;
  41166. },
  41167. formatTooltip: function (dataIndex) {
  41168. return Object(__WEBPACK_IMPORTED_MODULE_3__common_formatTooltip__["a" /* default */])(this, dataIndex);
  41169. },
  41170. defaultOption: {
  41171. coordinateSystem: 'cartesian3D',
  41172. globeIndex: 0,
  41173. grid3DIndex: 0,
  41174. zlevel: -10,
  41175. // bevelSize, 0 has no bevel
  41176. bevelSize: 0,
  41177. // higher is smoother
  41178. bevelSmoothness: 2,
  41179. // Bar width and depth
  41180. // barSize: [1, 1],
  41181. // On grid plane when coordinateSystem is cartesian3D
  41182. onGridPlane: 'xy',
  41183. // Shading of globe
  41184. shading: 'color',
  41185. minHeight: 0,
  41186. itemStyle: {
  41187. opacity: 1
  41188. },
  41189. label: {
  41190. show: false,
  41191. distance: 2,
  41192. textStyle: {
  41193. fontSize: 14,
  41194. color: '#000',
  41195. backgroundColor: 'rgba(255,255,255,0.7)',
  41196. padding: 3,
  41197. borderRadius: 3
  41198. }
  41199. },
  41200. emphasis: {
  41201. label: {
  41202. show: true
  41203. }
  41204. },
  41205. animationDurationUpdate: 500
  41206. }
  41207. });
  41208. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(Bar3DSeries.prototype, __WEBPACK_IMPORTED_MODULE_1__component_common_componentShadingMixin__["a" /* default */]);
  41209. /* unused harmony default export */ var _unused_webpack_default_export = (Bar3DSeries);
  41210. /***/
  41211. }),
  41212. /* 232 */
  41213. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  41214. "use strict";
  41215. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  41216. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  41217. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__line3D_Line3DSeries__ = __webpack_require__(233);
  41218. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__line3D_Line3DView__ = __webpack_require__(234);
  41219. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_echarts_lib_visual_symbol__ = __webpack_require__(51);
  41220. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_echarts_lib_visual_symbol___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_3_echarts_lib_visual_symbol__);
  41221. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__common_opacityVisual__ = __webpack_require__(17);
  41222. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerVisual(__WEBPACK_IMPORTED_MODULE_3_echarts_lib_visual_symbol___default()('line3D', 'circle', null));
  41223. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerVisual(Object(__WEBPACK_IMPORTED_MODULE_4__common_opacityVisual__["a" /* default */])('line3D'));
  41224. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerLayout(function (ecModel, api) {
  41225. ecModel.eachSeriesByType('line3D', function (seriesModel) {
  41226. var data = seriesModel.getData();
  41227. var coordSys = seriesModel.coordinateSystem;
  41228. if (coordSys) {
  41229. if (coordSys.type !== 'cartesian3D') {
  41230. if (true) {
  41231. console.error('line3D needs cartesian3D coordinateSystem');
  41232. }
  41233. return;
  41234. }
  41235. var points = new Float32Array(data.count() * 3);
  41236. var item = [];
  41237. var out = [];
  41238. var coordDims = coordSys.dimensions;
  41239. var dims = coordDims.map(function (coordDim) {
  41240. return seriesModel.coordDimToDataDim(coordDim)[0];
  41241. });
  41242. if (coordSys) {
  41243. data.each(dims, function (x, y, z, idx) {
  41244. item[0] = x;
  41245. item[1] = y;
  41246. item[2] = z;
  41247. coordSys.dataToPoint(item, out);
  41248. points[idx * 3] = out[0];
  41249. points[idx * 3 + 1] = out[1];
  41250. points[idx * 3 + 2] = out[2];
  41251. });
  41252. }
  41253. data.setLayout('points', points);
  41254. }
  41255. });
  41256. });
  41257. /***/
  41258. }),
  41259. /* 233 */
  41260. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  41261. "use strict";
  41262. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  41263. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  41264. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__common_formatTooltip__ = __webpack_require__(39);
  41265. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__common_createList__ = __webpack_require__(50);
  41266. var Line3DSeries = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendSeriesModel({
  41267. type: 'series.line3D',
  41268. dependencies: ['grid3D'],
  41269. visualColorAccessPath: 'lineStyle.color',
  41270. getInitialData: function (option, ecModel) {
  41271. return Object(__WEBPACK_IMPORTED_MODULE_2__common_createList__["a" /* default */])(this);
  41272. },
  41273. formatTooltip: function (dataIndex) {
  41274. return Object(__WEBPACK_IMPORTED_MODULE_1__common_formatTooltip__["a" /* default */])(this, dataIndex);
  41275. },
  41276. defaultOption: {
  41277. coordinateSystem: 'cartesian3D',
  41278. zlevel: -10,
  41279. // Cartesian coordinate system
  41280. grid3DIndex: 0,
  41281. lineStyle: {
  41282. width: 2
  41283. },
  41284. animationDurationUpdate: 500
  41285. }
  41286. });
  41287. /* unused harmony default export */ var _unused_webpack_default_export = (Line3DSeries);
  41288. /***/
  41289. }),
  41290. /* 234 */
  41291. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  41292. "use strict";
  41293. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  41294. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  41295. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__ = __webpack_require__(1);
  41296. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_retrieve__ = __webpack_require__(2);
  41297. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__util_geometry_Lines3D__ = __webpack_require__(25);
  41298. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_claygl_src_math_Matrix4__ = __webpack_require__(9);
  41299. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_claygl_src_math_Vector3__ = __webpack_require__(3);
  41300. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_zrender_lib_contain_line__ = __webpack_require__(235);
  41301. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_zrender_lib_contain_line___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_6_zrender_lib_contain_line__);
  41302. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7_claygl_src_dep_glmatrix__ = __webpack_require__(6);
  41303. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__util_shader_lines3D_glsl_js__ = __webpack_require__(46);
  41304. var vec3 = __WEBPACK_IMPORTED_MODULE_7_claygl_src_dep_glmatrix__["a" /* default */].vec3;
  41305. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader.import(__WEBPACK_IMPORTED_MODULE_8__util_shader_lines3D_glsl_js__["a" /* default */]);
  41306. /* unused harmony default export */ var _unused_webpack_default_export = (__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendChartView({
  41307. type: 'line3D',
  41308. __ecgl__: true,
  41309. init: function (ecModel, api) {
  41310. this.groupGL = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Node();
  41311. this._api = api;
  41312. },
  41313. render: function (seriesModel, ecModel, api) {
  41314. var tmp = this._prevLine3DMesh;
  41315. this._prevLine3DMesh = this._line3DMesh;
  41316. this._line3DMesh = tmp;
  41317. if (!this._line3DMesh) {
  41318. this._line3DMesh = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh({
  41319. geometry: new __WEBPACK_IMPORTED_MODULE_3__util_geometry_Lines3D__["a" /* default */]({
  41320. useNativeLine: false,
  41321. sortTriangles: true
  41322. }),
  41323. material: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Material({
  41324. shader: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].createShader('ecgl.meshLines3D')
  41325. }),
  41326. // Render after axes
  41327. renderOrder: 10
  41328. });
  41329. this._line3DMesh.geometry.pick = this._pick.bind(this);
  41330. }
  41331. this.groupGL.remove(this._prevLine3DMesh);
  41332. this.groupGL.add(this._line3DMesh);
  41333. var coordSys = seriesModel.coordinateSystem;
  41334. if (coordSys && coordSys.viewGL) {
  41335. coordSys.viewGL.add(this.groupGL);
  41336. // TODO
  41337. var methodName = coordSys.viewGL.isLinearSpace() ? 'define' : 'undefine';
  41338. this._line3DMesh.material[methodName]('fragment', 'SRGB_DECODE');
  41339. }
  41340. this._doRender(seriesModel, api);
  41341. this._data = seriesModel.getData();
  41342. this._camera = coordSys.viewGL.camera;
  41343. this.updateCamera();
  41344. this._updateAnimation(seriesModel);
  41345. },
  41346. updateCamera: function () {
  41347. this._updateNDCPosition();
  41348. },
  41349. _doRender: function (seriesModel, api) {
  41350. var data = seriesModel.getData();
  41351. var lineMesh = this._line3DMesh;
  41352. lineMesh.geometry.resetOffset();
  41353. var points = data.getLayout('points');
  41354. var colorArr = [];
  41355. var vertexColors = new Float32Array(points.length / 3 * 4);
  41356. var colorOffset = 0;
  41357. var hasTransparent = false;
  41358. data.each(function (idx) {
  41359. var color = data.getItemVisual(idx, 'color');
  41360. var opacity = data.getItemVisual(idx, 'opacity');
  41361. if (opacity == null) {
  41362. opacity = 1;
  41363. }
  41364. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(color, colorArr);
  41365. colorArr[3] *= opacity;
  41366. vertexColors[colorOffset++] = colorArr[0];
  41367. vertexColors[colorOffset++] = colorArr[1];
  41368. vertexColors[colorOffset++] = colorArr[2];
  41369. vertexColors[colorOffset++] = colorArr[3];
  41370. if (colorArr[3] < 0.99) {
  41371. hasTransparent = true;
  41372. }
  41373. });
  41374. lineMesh.geometry.setVertexCount(
  41375. lineMesh.geometry.getPolylineVertexCount(points)
  41376. );
  41377. lineMesh.geometry.setTriangleCount(
  41378. lineMesh.geometry.getPolylineTriangleCount(points)
  41379. );
  41380. lineMesh.geometry.addPolyline(
  41381. points, vertexColors,
  41382. __WEBPACK_IMPORTED_MODULE_2__util_retrieve__["a" /* default */].firstNotNull(seriesModel.get('lineStyle.width'), 1)
  41383. );
  41384. lineMesh.geometry.dirty();
  41385. lineMesh.geometry.updateBoundingBox();
  41386. var material = lineMesh.material;
  41387. material.transparent = hasTransparent;
  41388. material.depthMask = !hasTransparent;
  41389. var debugWireframeModel = seriesModel.getModel('debug.wireframe');
  41390. if (debugWireframeModel.get('show')) {
  41391. lineMesh.geometry.createAttribute('barycentric', 'float', 3);
  41392. lineMesh.geometry.generateBarycentric();
  41393. lineMesh.material.set('both', 'WIREFRAME_TRIANGLE');
  41394. lineMesh.material.set(
  41395. 'wireframeLineColor', __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(
  41396. debugWireframeModel.get('lineStyle.color') || 'rgba(0,0,0,0.5)'
  41397. )
  41398. );
  41399. lineMesh.material.set(
  41400. 'wireframeLineWidth', __WEBPACK_IMPORTED_MODULE_2__util_retrieve__["a" /* default */].firstNotNull(
  41401. debugWireframeModel.get('lineStyle.width'), 1
  41402. )
  41403. );
  41404. }
  41405. else {
  41406. lineMesh.material.set('both', 'WIREFRAME_TRIANGLE');
  41407. }
  41408. this._points = points;
  41409. this._initHandler(seriesModel, api);
  41410. },
  41411. _updateAnimation: function (seriesModel) {
  41412. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].updateVertexAnimation(
  41413. [['prevPosition', 'position'],
  41414. ['prevPositionPrev', 'positionPrev'],
  41415. ['prevPositionNext', 'positionNext']],
  41416. this._prevLine3DMesh,
  41417. this._line3DMesh,
  41418. seriesModel
  41419. );
  41420. },
  41421. _initHandler: function (seriesModel, api) {
  41422. var data = seriesModel.getData();
  41423. var coordSys = seriesModel.coordinateSystem;
  41424. var lineMesh = this._line3DMesh;
  41425. var lastDataIndex = -1;
  41426. lineMesh.seriesIndex = seriesModel.seriesIndex;
  41427. lineMesh.off('mousemove');
  41428. lineMesh.off('mouseout');
  41429. lineMesh.on('mousemove', function (e) {
  41430. var value = coordSys.pointToData(e.point.array);
  41431. var dataIndex = data.indicesOfNearest('x', value[0])[0];
  41432. if (dataIndex !== lastDataIndex) {
  41433. // this._downplay(lastDataIndex);
  41434. // this._highlight(dataIndex);
  41435. api.dispatchAction({
  41436. type: 'grid3DShowAxisPointer',
  41437. value: [data.get('x', dataIndex), data.get('y', dataIndex), data.get('z', dataIndex)]
  41438. });
  41439. lineMesh.dataIndex = dataIndex;
  41440. }
  41441. lastDataIndex = dataIndex;
  41442. }, this);
  41443. lineMesh.on('mouseout', function (e) {
  41444. // this._downplay(lastDataIndex);
  41445. lastDataIndex = -1;
  41446. lineMesh.dataIndex = -1;
  41447. api.dispatchAction({
  41448. type: 'grid3DHideAxisPointer'
  41449. });
  41450. }, this);
  41451. },
  41452. // _highlight: function (dataIndex) {
  41453. // var data = this._data;
  41454. // if (!data) {
  41455. // return;
  41456. // }
  41457. // },
  41458. // _downplay: function (dataIndex) {
  41459. // var data = this._data;
  41460. // if (!data) {
  41461. // return;
  41462. // }
  41463. // },
  41464. _updateNDCPosition: function () {
  41465. var worldViewProjection = new __WEBPACK_IMPORTED_MODULE_4_claygl_src_math_Matrix4__["a" /* default */]();
  41466. var camera = this._camera;
  41467. __WEBPACK_IMPORTED_MODULE_4_claygl_src_math_Matrix4__["a" /* default */].multiply(worldViewProjection, camera.projectionMatrix, camera.viewMatrix);
  41468. var positionNDC = this._positionNDC;
  41469. var points = this._points;
  41470. var nPoints = points.length / 3;
  41471. if (!positionNDC || positionNDC.length / 2 !== nPoints) {
  41472. positionNDC = this._positionNDC = new Float32Array(nPoints * 2);
  41473. }
  41474. var pos = [];
  41475. for (var i = 0; i < nPoints; i++) {
  41476. var i3 = i * 3;
  41477. var i2 = i * 2;
  41478. pos[0] = points[i3];
  41479. pos[1] = points[i3 + 1];
  41480. pos[2] = points[i3 + 2];
  41481. pos[3] = 1;
  41482. vec3.transformMat4(pos, pos, worldViewProjection.array);
  41483. positionNDC[i2] = pos[0] / pos[3];
  41484. positionNDC[i2 + 1] = pos[1] / pos[3];
  41485. }
  41486. },
  41487. _pick: function (x, y, renderer, camera, renderable, out) {
  41488. var positionNDC = this._positionNDC;
  41489. var seriesModel = this._data.hostModel;
  41490. var lineWidth = seriesModel.get('lineStyle.width');
  41491. var dataIndex = -1;
  41492. var width = renderer.viewport.width;
  41493. var height = renderer.viewport.height;
  41494. var halfWidth = width * 0.5;
  41495. var halfHeight = height * 0.5;
  41496. x = (x + 1) * halfWidth;
  41497. y = (y + 1) * halfHeight;
  41498. for (var i = 1; i < positionNDC.length / 2; i++) {
  41499. var x0 = (positionNDC[(i - 1) * 2] + 1) * halfWidth;
  41500. var y0 = (positionNDC[(i - 1) * 2 + 1] + 1) * halfHeight;
  41501. var x1 = (positionNDC[i * 2] + 1) * halfWidth;
  41502. var y1 = (positionNDC[i * 2 + 1] + 1) * halfHeight;
  41503. if (__WEBPACK_IMPORTED_MODULE_6_zrender_lib_contain_line___default.a.containStroke(x0, y0, x1, y1, lineWidth, x, y)) {
  41504. var dist0 = (x0 - x) * (x0 - x) + (y0 - y) * (y0 - y);
  41505. var dist1 = (x1 - x) * (x1 - x) + (y1 - y) * (y1 - y);
  41506. // Nearest point.
  41507. dataIndex = dist0 < dist1 ? (i - 1) : i;
  41508. }
  41509. }
  41510. if (dataIndex >= 0) {
  41511. var i3 = dataIndex * 3;
  41512. var point = new __WEBPACK_IMPORTED_MODULE_5_claygl_src_math_Vector3__["a" /* default */](
  41513. this._points[i3],
  41514. this._points[i3 + 1],
  41515. this._points[i3 + 2]
  41516. );
  41517. out.push({
  41518. dataIndex: dataIndex,
  41519. point: point,
  41520. pointWorld: point.clone(),
  41521. target: this._line3DMesh,
  41522. distance: this._camera.getWorldPosition().dist(point)
  41523. });
  41524. }
  41525. },
  41526. remove: function () {
  41527. this.groupGL.removeAll();
  41528. },
  41529. dispose: function () {
  41530. this.groupGL.removeAll();
  41531. }
  41532. }));
  41533. /***/
  41534. }),
  41535. /* 235 */
  41536. /***/ (function (module, exports) {
  41537. /**
  41538. * 线段包含判断
  41539. * @param {number} x0
  41540. * @param {number} y0
  41541. * @param {number} x1
  41542. * @param {number} y1
  41543. * @param {number} lineWidth
  41544. * @param {number} x
  41545. * @param {number} y
  41546. * @return {boolean}
  41547. */
  41548. function containStroke(x0, y0, x1, y1, lineWidth, x, y) {
  41549. if (lineWidth === 0) {
  41550. return false;
  41551. }
  41552. var _l = lineWidth;
  41553. var _a = 0;
  41554. var _b = x0; // Quick reject
  41555. if (y > y0 + _l && y > y1 + _l || y < y0 - _l && y < y1 - _l || x > x0 + _l && x > x1 + _l || x < x0 - _l && x < x1 - _l) {
  41556. return false;
  41557. }
  41558. if (x0 !== x1) {
  41559. _a = (y0 - y1) / (x0 - x1);
  41560. _b = (x0 * y1 - x1 * y0) / (x0 - x1);
  41561. } else {
  41562. return Math.abs(x - x0) <= _l / 2;
  41563. }
  41564. var tmp = _a * x - y + _b;
  41565. var _s = tmp * tmp / (_a * _a + 1);
  41566. return _s <= _l / 2 * _l / 2;
  41567. }
  41568. exports.containStroke = containStroke;
  41569. /***/
  41570. }),
  41571. /* 236 */
  41572. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  41573. "use strict";
  41574. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  41575. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  41576. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__scatter3D_Scatter3DSeries__ = __webpack_require__(237);
  41577. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__scatter3D_Scatter3DView__ = __webpack_require__(238);
  41578. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_echarts_lib_visual_symbol__ = __webpack_require__(51);
  41579. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_echarts_lib_visual_symbol___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_3_echarts_lib_visual_symbol__);
  41580. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__common_opacityVisual__ = __webpack_require__(17);
  41581. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerVisual(__WEBPACK_IMPORTED_MODULE_3_echarts_lib_visual_symbol___default()('scatter3D', 'circle', null));
  41582. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerVisual(Object(__WEBPACK_IMPORTED_MODULE_4__common_opacityVisual__["a" /* default */])('scatter3D'));
  41583. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerLayout({
  41584. seriesType: 'scatter3D',
  41585. reset: function (seriesModel) {
  41586. var coordSys = seriesModel.coordinateSystem;
  41587. if (coordSys) {
  41588. var coordDims = coordSys.dimensions;
  41589. if (coordDims.length < 3) {
  41590. if (true) {
  41591. console.error('scatter3D needs 3D coordinateSystem');
  41592. }
  41593. return;
  41594. }
  41595. var dims = coordDims.map(function (coordDim) {
  41596. return seriesModel.coordDimToDataDim(coordDim)[0];
  41597. });
  41598. var item = [];
  41599. var out = [];
  41600. return {
  41601. progress: function (params, data) {
  41602. var points = new Float32Array((params.end - params.start) * 3);
  41603. for (var idx = params.start; idx < params.end; idx++) {
  41604. var idx3 = (idx - params.start) * 3;
  41605. item[0] = data.get(dims[0], idx);
  41606. item[1] = data.get(dims[1], idx);
  41607. item[2] = data.get(dims[2], idx);
  41608. coordSys.dataToPoint(item, out);
  41609. points[idx3] = out[0];
  41610. points[idx3 + 1] = out[1];
  41611. points[idx3 + 2] = out[2];
  41612. }
  41613. data.setLayout('points', points);
  41614. }
  41615. };
  41616. }
  41617. }
  41618. });
  41619. /***/
  41620. }),
  41621. /* 237 */
  41622. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  41623. "use strict";
  41624. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  41625. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  41626. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_format__ = __webpack_require__(32);
  41627. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__common_formatTooltip__ = __webpack_require__(39);
  41628. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__common_createList__ = __webpack_require__(50);
  41629. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendSeriesModel({
  41630. type: 'series.scatter3D',
  41631. dependencies: ['globe', 'grid3D', 'geo3D'],
  41632. visualColorAccessPath: 'itemStyle.color',
  41633. getInitialData: function (option, ecModel) {
  41634. return Object(__WEBPACK_IMPORTED_MODULE_3__common_createList__["a" /* default */])(this);
  41635. },
  41636. getFormattedLabel: function (dataIndex, status, dataType, dimIndex) {
  41637. var text = __WEBPACK_IMPORTED_MODULE_1__util_format__["a" /* default */].getFormattedLabel(this, dataIndex, status, dataType, dimIndex);
  41638. if (text == null) {
  41639. var data = this.getData();
  41640. var lastDim = data.dimensions[data.dimensions.length - 1];
  41641. text = data.get(lastDim, dataIndex);
  41642. }
  41643. return text;
  41644. },
  41645. formatTooltip: function (dataIndex) {
  41646. return Object(__WEBPACK_IMPORTED_MODULE_2__common_formatTooltip__["a" /* default */])(this, dataIndex);
  41647. },
  41648. defaultOption: {
  41649. coordinateSystem: 'cartesian3D',
  41650. zlevel: -10,
  41651. progressive: 1e5,
  41652. progressiveThreshold: 1e5,
  41653. // Cartesian coordinate system
  41654. grid3DIndex: 0,
  41655. globeIndex: 0,
  41656. symbol: 'circle',
  41657. symbolSize: 10,
  41658. // Support source-over, lighter
  41659. blendMode: 'source-over',
  41660. label: {
  41661. show: false,
  41662. position: 'right',
  41663. // Screen space distance
  41664. distance: 5,
  41665. textStyle: {
  41666. fontSize: 14,
  41667. color: '#000',
  41668. backgroundColor: 'rgba(255,255,255,0.7)',
  41669. padding: 3,
  41670. borderRadius: 3
  41671. }
  41672. },
  41673. itemStyle: {
  41674. opacity: 0.8
  41675. },
  41676. emphasis: {
  41677. label: {
  41678. show: true
  41679. }
  41680. },
  41681. animationDurationUpdate: 500
  41682. }
  41683. });
  41684. /***/
  41685. }),
  41686. /* 238 */
  41687. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  41688. "use strict";
  41689. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  41690. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  41691. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__ = __webpack_require__(1);
  41692. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_retrieve__ = __webpack_require__(2);
  41693. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__util_format__ = __webpack_require__(32);
  41694. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__common_PointsBuilder__ = __webpack_require__(67);
  41695. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendChartView({
  41696. type: 'scatter3D',
  41697. __ecgl__: true,
  41698. init: function (ecModel, api) {
  41699. this.groupGL = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Node();
  41700. this._pointsBuilderList = [];
  41701. this._currentStep = 0;
  41702. },
  41703. render: function (seriesModel, ecModel, api) {
  41704. this.groupGL.removeAll();
  41705. if (!seriesModel.getData().count()) {
  41706. return;
  41707. }
  41708. var coordSys = seriesModel.coordinateSystem;
  41709. if (coordSys && coordSys.viewGL) {
  41710. coordSys.viewGL.add(this.groupGL);
  41711. this._camera = coordSys.viewGL.camera;
  41712. var pointsBuilder = this._pointsBuilderList[0];
  41713. if (!pointsBuilder) {
  41714. pointsBuilder = this._pointsBuilderList[0] = new __WEBPACK_IMPORTED_MODULE_4__common_PointsBuilder__["a" /* default */](false, api);
  41715. }
  41716. this._pointsBuilderList.length = 1;
  41717. this.groupGL.add(pointsBuilder.rootNode);
  41718. pointsBuilder.update(seriesModel, ecModel, api);
  41719. pointsBuilder.updateView(coordSys.viewGL.camera);
  41720. }
  41721. else {
  41722. if (true) {
  41723. throw new Error('Invalid coordinate system');
  41724. }
  41725. }
  41726. },
  41727. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  41728. var coordSys = seriesModel.coordinateSystem;
  41729. if (coordSys && coordSys.viewGL) {
  41730. coordSys.viewGL.add(this.groupGL);
  41731. this._camera = coordSys.viewGL.camera;
  41732. }
  41733. else {
  41734. if (true) {
  41735. throw new Error('Invalid coordinate system');
  41736. }
  41737. }
  41738. this.groupGL.removeAll();
  41739. this._currentStep = 0;
  41740. },
  41741. incrementalRender: function (params, seriesModel, ecModel, api) {
  41742. // TODO Sort transparency.
  41743. if (params.end <= params.start) {
  41744. return;
  41745. }
  41746. var pointsBuilder = this._pointsBuilderList[this._currentStep];
  41747. if (!pointsBuilder) {
  41748. pointsBuilder = new __WEBPACK_IMPORTED_MODULE_4__common_PointsBuilder__["a" /* default */](false, api);
  41749. this._pointsBuilderList[this._currentStep] = pointsBuilder;
  41750. }
  41751. this.groupGL.add(pointsBuilder.rootNode);
  41752. pointsBuilder.update(seriesModel, ecModel, api, params.start, params.end);
  41753. pointsBuilder.updateView(seriesModel.coordinateSystem.viewGL.camera);
  41754. this._currentStep++;
  41755. },
  41756. updateCamera: function () {
  41757. this._pointsBuilderList.forEach(function (pointsBuilder) {
  41758. pointsBuilder.updateView(this._camera);
  41759. }, this);
  41760. },
  41761. highlight: function (seriesModel, ecModel, api, payload) {
  41762. this._toggleStatus('highlight', seriesModel, ecModel, api, payload);
  41763. },
  41764. downplay: function (seriesModel, ecModel, api, payload) {
  41765. this._toggleStatus('downplay', seriesModel, ecModel, api, payload);
  41766. },
  41767. _toggleStatus: function (status, seriesModel, ecModel, api, payload) {
  41768. var data = seriesModel.getData();
  41769. var dataIndex = __WEBPACK_IMPORTED_MODULE_2__util_retrieve__["a" /* default */].queryDataIndex(data, payload);
  41770. var isHighlight = status === 'highlight';
  41771. if (dataIndex != null) {
  41772. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.each(__WEBPACK_IMPORTED_MODULE_3__util_format__["a" /* default */].normalizeToArray(dataIndex), function (dataIdx) {
  41773. for (var i = 0; i < this._pointsBuilderList.length; i++) {
  41774. var pointsBuilder = this._pointsBuilderList[i];
  41775. isHighlight ? pointsBuilder.highlight(data, dataIdx) : pointsBuilder.downplay(data, dataIdx);
  41776. }
  41777. }, this);
  41778. }
  41779. else {
  41780. // PENDING, OPTIMIZE
  41781. data.each(function (dataIdx) {
  41782. for (var i = 0; i < this._pointsBuilderList.length; i++) {
  41783. var pointsBuilder = this._pointsBuilderList[i];
  41784. isHighlight ? pointsBuilder.highlight(data, dataIdx) : pointsBuilder.downplay(data, dataIdx);
  41785. }
  41786. });
  41787. }
  41788. },
  41789. dispose: function () {
  41790. this.groupGL.removeAll();
  41791. },
  41792. remove: function () {
  41793. this.groupGL.removeAll();
  41794. }
  41795. });
  41796. /***/
  41797. }),
  41798. /* 239 */
  41799. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  41800. "use strict";
  41801. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  41802. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  41803. function makeSprite(size, canvas, draw) {
  41804. // http://simonsarris.com/blog/346-how-you-clear-your-canvas-matters
  41805. // http://jsperf.com/canvasclear
  41806. // Set width and height is fast
  41807. // And use the exist canvas if possible
  41808. // http://jsperf.com/create-canvas-vs-set-width-height/2
  41809. var canvas = canvas || document.createElement('canvas');
  41810. canvas.width = size;
  41811. canvas.height = size;
  41812. var ctx = canvas.getContext('2d');
  41813. draw && draw(ctx);
  41814. return canvas;
  41815. }
  41816. function makePath(symbol, symbolSize, style, marginBias) {
  41817. if (!__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.isArray(symbolSize)) {
  41818. symbolSize = [symbolSize, symbolSize];
  41819. }
  41820. var margin = spriteUtil.getMarginByStyle(style, marginBias);
  41821. var width = symbolSize[0] + margin.left + margin.right;
  41822. var height = symbolSize[1] + margin.top + margin.bottom;
  41823. var path = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.helper.createSymbol(symbol, 0, 0, symbolSize[0], symbolSize[1]);
  41824. var size = Math.max(width, height);
  41825. path.position = [margin.left, margin.top];
  41826. if (width > height) {
  41827. path.position[1] += (size - height) / 2;
  41828. }
  41829. else {
  41830. path.position[0] += (size - width) / 2;
  41831. }
  41832. var rect = path.getBoundingRect();
  41833. path.position[0] -= rect.x;
  41834. path.position[1] -= rect.y;
  41835. path.setStyle(style);
  41836. path.update();
  41837. path.__size = size;
  41838. return path;
  41839. }
  41840. // http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf
  41841. function generateSDF(ctx, sourceImageData, range) {
  41842. var sourceWidth = sourceImageData.width;
  41843. var sourceHeight = sourceImageData.height;
  41844. var width = ctx.canvas.width;
  41845. var height = ctx.canvas.height;
  41846. var scaleX = sourceWidth / width;
  41847. var scaleY = sourceHeight / height;
  41848. function sign(r) {
  41849. return r < 128 ? 1 : -1;
  41850. }
  41851. function searchMinDistance(x, y) {
  41852. var minDistSqr = Infinity;
  41853. x = Math.floor(x * scaleX);
  41854. y = Math.floor(y * scaleY);
  41855. var i = y * sourceWidth + x;
  41856. var r = sourceImageData.data[i * 4];
  41857. var a = sign(r);
  41858. // Search for min distance
  41859. for (var y2 = Math.max(y - range, 0); y2 < Math.min(y + range, sourceHeight); y2++) {
  41860. for (var x2 = Math.max(x - range, 0); x2 < Math.min(x + range, sourceWidth); x2++) {
  41861. var i = y2 * sourceWidth + x2;
  41862. var r2 = sourceImageData.data[i * 4];
  41863. var b = sign(r2);
  41864. var dx = x2 - x;
  41865. var dy = y2 - y;
  41866. if (a !== b) {
  41867. var distSqr = dx * dx + dy * dy;
  41868. if (distSqr < minDistSqr) {
  41869. minDistSqr = distSqr;
  41870. }
  41871. }
  41872. }
  41873. }
  41874. return a * Math.sqrt(minDistSqr);
  41875. }
  41876. var sdfImageData = ctx.createImageData(width, height);
  41877. for (var y = 0; y < height; y++) {
  41878. for (var x = 0; x < width; x++) {
  41879. var dist = searchMinDistance(x, y);
  41880. var normalized = dist / range * 0.5 + 0.5;
  41881. var i = (y * width + x) * 4;
  41882. sdfImageData.data[i++] = (1.0 - normalized) * 255;
  41883. sdfImageData.data[i++] = (1.0 - normalized) * 255;
  41884. sdfImageData.data[i++] = (1.0 - normalized) * 255;
  41885. sdfImageData.data[i++] = 255;
  41886. }
  41887. }
  41888. return sdfImageData;
  41889. }
  41890. var spriteUtil = {
  41891. getMarginByStyle: function (style) {
  41892. var minMargin = style.minMargin || 0;
  41893. var lineWidth = 0;
  41894. if (style.stroke && style.stroke !== 'none') {
  41895. lineWidth = style.lineWidth == null ? 1 : style.lineWidth;
  41896. }
  41897. var shadowBlurSize = style.shadowBlur || 0;
  41898. var shadowOffsetX = style.shadowOffsetX || 0;
  41899. var shadowOffsetY = style.shadowOffsetY || 0;
  41900. var margin = {};
  41901. margin.left = Math.max(lineWidth / 2, -shadowOffsetX + shadowBlurSize, minMargin);
  41902. margin.right = Math.max(lineWidth / 2, shadowOffsetX + shadowBlurSize, minMargin);
  41903. margin.top = Math.max(lineWidth / 2, -shadowOffsetY + shadowBlurSize, minMargin);
  41904. margin.bottom = Math.max(lineWidth / 2, shadowOffsetY + shadowBlurSize, minMargin);
  41905. return margin;
  41906. },
  41907. // TODO Not consider shadowOffsetX, shadowOffsetY.
  41908. /**
  41909. * @param {string} symbol
  41910. * @param {number | Array.<number>} symbolSize
  41911. * @param {Object} style
  41912. */
  41913. createSymbolSprite: function (symbol, symbolSize, style, canvas) {
  41914. var path = makePath(symbol, symbolSize, style);
  41915. var margin = spriteUtil.getMarginByStyle(style);
  41916. return {
  41917. image: makeSprite(path.__size, canvas, function (ctx) {
  41918. path.brush(ctx);
  41919. }),
  41920. margin: margin
  41921. };
  41922. },
  41923. createSDFFromCanvas: function (canvas, size, range, outCanvas) {
  41924. // TODO Create a low resolution SDF from high resolution image.
  41925. return makeSprite(size, outCanvas, function (outCtx) {
  41926. var ctx = canvas.getContext('2d');
  41927. var imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
  41928. outCtx.putImageData(generateSDF(outCtx, imgData, range), 0, 0);
  41929. });
  41930. },
  41931. createSimpleSprite: function (size, canvas) {
  41932. return makeSprite(size, canvas, function (ctx) {
  41933. var halfSize = size / 2;
  41934. ctx.beginPath();
  41935. ctx.arc(halfSize, halfSize, 60, 0, Math.PI * 2, false);
  41936. ctx.closePath();
  41937. var gradient = ctx.createRadialGradient(
  41938. halfSize, halfSize, 0, halfSize, halfSize, halfSize
  41939. );
  41940. gradient.addColorStop(0, 'rgba(255, 255, 255, 1)');
  41941. gradient.addColorStop(0.5, 'rgba(255, 255, 255, 0.5)');
  41942. gradient.addColorStop(1, 'rgba(255, 255, 255, 0)');
  41943. ctx.fillStyle = gradient;
  41944. ctx.fill();
  41945. });
  41946. }
  41947. };
  41948. /* harmony default export */ __webpack_exports__["a"] = (spriteUtil);
  41949. /***/
  41950. }),
  41951. /* 240 */
  41952. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  41953. "use strict";
  41954. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__ = __webpack_require__(1);
  41955. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_geometry_verticesSortMixin__ = __webpack_require__(241);
  41956. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_echarts_lib_echarts__ = __webpack_require__(0);
  41957. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_echarts_lib_echarts__);
  41958. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_claygl_src_dep_glmatrix__ = __webpack_require__(6);
  41959. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__sdfSprite_glsl_js__ = __webpack_require__(242);
  41960. var vec4 = __WEBPACK_IMPORTED_MODULE_3_claygl_src_dep_glmatrix__["a" /* default */].vec4;
  41961. __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].Shader.import(__WEBPACK_IMPORTED_MODULE_4__sdfSprite_glsl_js__["a" /* default */]);
  41962. var PointsMesh = __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].Mesh.extend(function () {
  41963. var geometry = new __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].Geometry({
  41964. dynamic: true,
  41965. attributes: {
  41966. color: new __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].Geometry.Attribute('color', 'float', 4, 'COLOR'),
  41967. position: new __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].Geometry.Attribute('position', 'float', 3, 'POSITION'),
  41968. size: new __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].Geometry.Attribute('size', 'float', 1),
  41969. prevPosition: new __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].Geometry.Attribute('prevPosition', 'float', 3),
  41970. prevSize: new __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].Geometry.Attribute('prevSize', 'float', 1)
  41971. }
  41972. });
  41973. __WEBPACK_IMPORTED_MODULE_2_echarts_lib_echarts___default.a.util.extend(geometry, __WEBPACK_IMPORTED_MODULE_1__util_geometry_verticesSortMixin__["a" /* default */]);
  41974. var material = new __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].Material({
  41975. shader: __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].createShader('ecgl.sdfSprite'),
  41976. transparent: true,
  41977. depthMask: false
  41978. });
  41979. material.enableTexture('sprite');
  41980. material.define('both', 'VERTEX_COLOR');
  41981. material.define('both', 'VERTEX_SIZE');
  41982. var sdfTexture = new __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].Texture2D({
  41983. image: document.createElement('canvas'),
  41984. flipY: false
  41985. });
  41986. material.set('sprite', sdfTexture);
  41987. // Custom pick methods.
  41988. geometry.pick = this._pick.bind(this);
  41989. return {
  41990. geometry: geometry,
  41991. material: material,
  41992. mode: __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].Mesh.POINTS,
  41993. sizeScale: 1
  41994. };
  41995. }, {
  41996. _pick: function (x, y, renderer, camera, renderable, out) {
  41997. var positionNDC = this._positionNDC;
  41998. if (!positionNDC) {
  41999. return;
  42000. }
  42001. var viewport = renderer.viewport;
  42002. var ndcScaleX = 2 / viewport.width;
  42003. var ndcScaleY = 2 / viewport.height;
  42004. // From near to far. indices have been sorted.
  42005. for (var i = this.geometry.vertexCount - 1; i >= 0; i--) {
  42006. var idx;
  42007. if (!this.geometry.indices) {
  42008. idx = i;
  42009. }
  42010. else {
  42011. idx = this.geometry.indices[i];
  42012. }
  42013. var cx = positionNDC[idx * 2];
  42014. var cy = positionNDC[idx * 2 + 1];
  42015. var size = this.geometry.attributes.size.get(idx) / this.sizeScale;
  42016. var halfSize = size / 2;
  42017. if (
  42018. x > (cx - halfSize * ndcScaleX) && x < (cx + halfSize * ndcScaleX)
  42019. && y > (cy - halfSize * ndcScaleY) && y < (cy + halfSize * ndcScaleY)
  42020. ) {
  42021. var point = new __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].Vector3();
  42022. var pointWorld = new __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].Vector3();
  42023. this.geometry.attributes.position.get(idx, point.array);
  42024. __WEBPACK_IMPORTED_MODULE_0__util_graphicGL__["a" /* default */].Vector3.transformMat4(pointWorld, point, this.worldTransform);
  42025. out.push({
  42026. vertexIndex: idx,
  42027. point: point,
  42028. pointWorld: pointWorld,
  42029. target: this,
  42030. distance: pointWorld.distance(camera.getWorldPosition())
  42031. });
  42032. }
  42033. }
  42034. },
  42035. updateNDCPosition: function (worldViewProjection, is2D, api) {
  42036. var positionNDC = this._positionNDC;
  42037. var geometry = this.geometry;
  42038. if (!positionNDC || positionNDC.length / 2 !== geometry.vertexCount) {
  42039. positionNDC = this._positionNDC = new Float32Array(geometry.vertexCount * 2);
  42040. }
  42041. var pos = vec4.create();
  42042. for (var i = 0; i < geometry.vertexCount; i++) {
  42043. geometry.attributes.position.get(i, pos);
  42044. pos[3] = 1;
  42045. vec4.transformMat4(pos, pos, worldViewProjection.array);
  42046. vec4.scale(pos, pos, 1 / pos[3]);
  42047. positionNDC[i * 2] = pos[0];
  42048. positionNDC[i * 2 + 1] = pos[1];
  42049. }
  42050. }
  42051. });
  42052. /* harmony default export */ __webpack_exports__["a"] = (PointsMesh);
  42053. /***/
  42054. }),
  42055. /* 241 */
  42056. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  42057. "use strict";
  42058. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__ProgressiveQuickSort__ = __webpack_require__(97);
  42059. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_dep_glmatrix__ = __webpack_require__(6);
  42060. var vec3 = __WEBPACK_IMPORTED_MODULE_1_claygl_src_dep_glmatrix__["a" /* default */].vec3;
  42061. /* harmony default export */ __webpack_exports__["a"] = ({
  42062. needsSortVertices: function () {
  42063. return this.sortVertices;
  42064. },
  42065. needsSortVerticesProgressively: function () {
  42066. return this.needsSortVertices() && this.vertexCount >= 2e4;
  42067. },
  42068. doSortVertices: function (cameraPos, frame) {
  42069. var indices = this.indices;
  42070. var p = vec3.create();
  42071. if (!indices) {
  42072. indices = this.indices = this.vertexCount > 0xffff ? new Uint32Array(this.vertexCount) : new Uint16Array(this.vertexCount);
  42073. for (var i = 0; i < indices.length; i++) {
  42074. indices[i] = i;
  42075. }
  42076. }
  42077. // Do progressive quick sort.
  42078. if (frame === 0) {
  42079. var posAttr = this.attributes.position;
  42080. var cameraPos = cameraPos.array;
  42081. var noneCount = 0;
  42082. if (!this._zList || this._zList.length !== this.vertexCount) {
  42083. this._zList = new Float32Array(this.vertexCount);
  42084. }
  42085. var firstZ;
  42086. for (var i = 0; i < this.vertexCount; i++) {
  42087. posAttr.get(i, p);
  42088. // Camera position is in object space
  42089. var z = vec3.sqrDist(p, cameraPos);
  42090. if (isNaN(z)) {
  42091. // Put far away, NaN value may cause sort slow
  42092. z = 1e7;
  42093. noneCount++;
  42094. }
  42095. if (i === 0) {
  42096. firstZ = z;
  42097. z = 0;
  42098. }
  42099. else {
  42100. // Only store the difference to avoid the precision issue.
  42101. z = z - firstZ;
  42102. }
  42103. this._zList[i] = z;
  42104. }
  42105. this._noneCount = noneCount;
  42106. }
  42107. if (this.vertexCount < 2e4) {
  42108. // Use simple native sort for simple geometries.
  42109. if (frame === 0) {
  42110. this._simpleSort(this._noneCount / this.vertexCount > 0.05);
  42111. }
  42112. }
  42113. else {
  42114. for (var i = 0; i < 3; i++) {
  42115. this._progressiveQuickSort(frame * 3 + i);
  42116. }
  42117. }
  42118. this.dirtyIndices();
  42119. },
  42120. _simpleSort: function (useNativeQuickSort) {
  42121. var zList = this._zList;
  42122. var indices = this.indices;
  42123. function compare(a, b) {
  42124. // Sort from far to near. which is descending order
  42125. return zList[b] - zList[a];
  42126. }
  42127. // When too much value are equal, using native quick sort with three partition..
  42128. // or the simple quick sort will be nearly O(n*n)
  42129. // http://stackoverflow.com/questions/5126586/quicksort-complexity-when-all-the-elements-are-same
  42130. // Otherwise simple quicksort is more effecient than v8 native quick sort when data all different.
  42131. if (useNativeQuickSort) {
  42132. Array.prototype.sort.call(indices, compare);
  42133. }
  42134. else {
  42135. __WEBPACK_IMPORTED_MODULE_0__ProgressiveQuickSort__["a" /* default */].sort(indices, compare, 0, indices.length - 1);
  42136. }
  42137. },
  42138. _progressiveQuickSort: function (frame) {
  42139. var zList = this._zList;
  42140. var indices = this.indices;
  42141. this._quickSort = this._quickSort || new __WEBPACK_IMPORTED_MODULE_0__ProgressiveQuickSort__["a" /* default */]();
  42142. this._quickSort.step(indices, function (a, b) {
  42143. return zList[b] - zList[a];
  42144. }, frame);
  42145. }
  42146. });
  42147. /***/
  42148. }),
  42149. /* 242 */
  42150. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  42151. "use strict";
  42152. /* harmony default export */ __webpack_exports__["a"] = ("@export ecgl.sdfSprite.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform float elapsedTime : 0;\n\nattribute vec3 position : POSITION;\n\n#ifdef VERTEX_SIZE\nattribute float size;\n#else\nuniform float u_Size;\n#endif\n\n#ifdef VERTEX_COLOR\nattribute vec4 a_FillColor: COLOR;\nvarying vec4 v_Color;\n#endif\n\n#ifdef VERTEX_ANIMATION\nattribute vec3 prevPosition;\nattribute float prevSize;\nuniform float percent : 1.0;\n#endif\n\n\n#ifdef POSITIONTEXTURE_ENABLED\nuniform sampler2D positionTexture;\n#endif\n\nvarying float v_Size;\n\nvoid main()\n{\n\n#ifdef POSITIONTEXTURE_ENABLED\n gl_Position = worldViewProjection * vec4(texture2D(positionTexture, position.xy).xy, -10.0, 1.0);\n#else\n\n #ifdef VERTEX_ANIMATION\n vec3 pos = mix(prevPosition, position, percent);\n #else\n vec3 pos = position;\n #endif\n gl_Position = worldViewProjection * vec4(pos, 1.0);\n#endif\n\n#ifdef VERTEX_SIZE\n#ifdef VERTEX_ANIMATION\n v_Size = mix(prevSize, size, percent);\n#else\n v_Size = size;\n#endif\n#else\n v_Size = u_Size;\n#endif\n\n#ifdef VERTEX_COLOR\n v_Color = a_FillColor;\n #endif\n\n gl_PointSize = v_Size;\n}\n\n@end\n\n@export ecgl.sdfSprite.fragment\n\nuniform vec4 color: [1, 1, 1, 1];\nuniform vec4 strokeColor: [1, 1, 1, 1];\nuniform float smoothing: 0.07;\n\nuniform float lineWidth: 0.0;\n\n#ifdef VERTEX_COLOR\nvarying vec4 v_Color;\n#endif\n\nvarying float v_Size;\n\nuniform sampler2D sprite;\n\n@import clay.util.srgb\n\nvoid main()\n{\n gl_FragColor = color;\n\n vec4 _strokeColor = strokeColor;\n\n#ifdef VERTEX_COLOR\n gl_FragColor *= v_Color;\n #endif\n\n#ifdef SPRITE_ENABLED\n float d = texture2D(sprite, gl_PointCoord).r;\n gl_FragColor.a *= smoothstep(0.5 - smoothing, 0.5 + smoothing, d);\n\n if (lineWidth > 0.0) {\n float sLineWidth = lineWidth / 2.0;\n\n float outlineMaxValue0 = 0.5 + sLineWidth;\n float outlineMaxValue1 = 0.5 + sLineWidth + smoothing;\n float outlineMinValue0 = 0.5 - sLineWidth - smoothing;\n float outlineMinValue1 = 0.5 - sLineWidth;\n\n if (d <= outlineMaxValue1 && d >= outlineMinValue0) {\n float a = _strokeColor.a;\n if (d <= outlineMinValue1) {\n a = a * smoothstep(outlineMinValue0, outlineMinValue1, d);\n }\n else {\n a = a * smoothstep(outlineMaxValue1, outlineMaxValue0, d);\n }\n gl_FragColor.rgb = mix(gl_FragColor.rgb * gl_FragColor.a, _strokeColor.rgb, a);\n gl_FragColor.a = gl_FragColor.a * (1.0 - a) + a;\n }\n }\n#endif\n\n#ifdef SRGB_DECODE\n gl_FragColor = sRGBToLinear(gl_FragColor);\n#endif\n}\n@end");
  42153. /***/
  42154. }),
  42155. /* 243 */
  42156. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  42157. "use strict";
  42158. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  42159. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  42160. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__lines3D_lines3DLayout__ = __webpack_require__(244);
  42161. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__lines3D_Lines3DView__ = __webpack_require__(245);
  42162. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__lines3D_Lines3DSeries__ = __webpack_require__(248);
  42163. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__common_opacityVisual__ = __webpack_require__(17);
  42164. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerVisual(Object(__WEBPACK_IMPORTED_MODULE_4__common_opacityVisual__["a" /* default */])('lines3D'));
  42165. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerAction({
  42166. type: 'lines3DPauseEffect',
  42167. event: 'lines3deffectpaused',
  42168. update: 'series.lines3D:pauseEffect'
  42169. }, function () { });
  42170. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerAction({
  42171. type: 'lines3DResumeEffect',
  42172. event: 'lines3deffectresumed',
  42173. update: 'series.lines3D:resumeEffect'
  42174. }, function () { });
  42175. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerAction({
  42176. type: 'lines3DToggleEffect',
  42177. event: 'lines3deffectchanged',
  42178. update: 'series.lines3D:toggleEffect'
  42179. }, function () { });
  42180. /***/
  42181. }),
  42182. /* 244 */
  42183. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  42184. "use strict";
  42185. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  42186. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  42187. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_dep_glmatrix__ = __webpack_require__(6);
  42188. var vec3 = __WEBPACK_IMPORTED_MODULE_1_claygl_src_dep_glmatrix__["a" /* default */].vec3;
  42189. var vec2 = __WEBPACK_IMPORTED_MODULE_1_claygl_src_dep_glmatrix__["a" /* default */].vec2;
  42190. var normalize = vec3.normalize;
  42191. var cross = vec3.cross;
  42192. var sub = vec3.sub;
  42193. var add = vec3.add;
  42194. var create = vec3.create;
  42195. var normal = create();
  42196. var tangent = create();
  42197. var bitangent = create();
  42198. var halfVector = create();
  42199. var coord0 = [];
  42200. var coord1 = [];
  42201. function getCubicPointsOnGlobe(coords, coordSys) {
  42202. vec2.copy(coord0, coords[0]);
  42203. vec2.copy(coord1, coords[1]);
  42204. var pts = [];
  42205. var p0 = pts[0] = create();
  42206. var p1 = pts[1] = create();
  42207. var p2 = pts[2] = create();
  42208. var p3 = pts[3] = create();
  42209. coordSys.dataToPoint(coord0, p0);
  42210. coordSys.dataToPoint(coord1, p3);
  42211. // Get p1
  42212. normalize(normal, p0);
  42213. // TODO p0-p3 is parallel with normal
  42214. sub(tangent, p3, p0);
  42215. normalize(tangent, tangent);
  42216. cross(bitangent, tangent, normal);
  42217. normalize(bitangent, bitangent);
  42218. cross(tangent, normal, bitangent);
  42219. // p1 is half vector of p0 and tangent on p0
  42220. add(p1, normal, tangent);
  42221. normalize(p1, p1);
  42222. // Get p2
  42223. normalize(normal, p3);
  42224. sub(tangent, p0, p3);
  42225. normalize(tangent, tangent);
  42226. cross(bitangent, tangent, normal);
  42227. normalize(bitangent, bitangent);
  42228. cross(tangent, normal, bitangent);
  42229. // p2 is half vector of p3 and tangent on p3
  42230. add(p2, normal, tangent);
  42231. normalize(p2, p2);
  42232. // Project distance of p0 on halfVector
  42233. add(halfVector, p0, p3);
  42234. normalize(halfVector, halfVector);
  42235. var projDist = vec3.dot(p0, halfVector);
  42236. // Angle of halfVector and p1
  42237. var cosTheta = vec3.dot(halfVector, p1);
  42238. var len = (Math.max(vec3.len(p0), vec3.len(p3)) - projDist) / cosTheta * 2;
  42239. vec3.scaleAndAdd(p1, p0, p1, len);
  42240. vec3.scaleAndAdd(p2, p3, p2, len);
  42241. return pts;
  42242. }
  42243. function getCubicPointsOnPlane(coords, coordSys, up) {
  42244. var pts = [];
  42245. var p0 = pts[0] = vec3.create();
  42246. var p1 = pts[1] = vec3.create();
  42247. var p2 = pts[2] = vec3.create();
  42248. var p3 = pts[3] = vec3.create();
  42249. coordSys.dataToPoint(coords[0], p0);
  42250. coordSys.dataToPoint(coords[1], p3);
  42251. var len = vec3.dist(p0, p3);
  42252. vec3.lerp(p1, p0, p3, 0.3);
  42253. vec3.lerp(p2, p0, p3, 0.3);
  42254. vec3.scaleAndAdd(p1, p1, up, Math.min(len * 0.1, 10));
  42255. vec3.scaleAndAdd(p2, p2, up, Math.min(len * 0.1, 10));
  42256. return pts;
  42257. }
  42258. function getPolylinePoints(coords, coordSys) {
  42259. var pts = new Float32Array(coords.length * 3);
  42260. var off = 0;
  42261. var pt = [];
  42262. for (var i = 0; i < coords.length; i++) {
  42263. coordSys.dataToPoint(coords[i], pt);
  42264. pts[off++] = pt[0];
  42265. pts[off++] = pt[1];
  42266. pts[off++] = pt[2];
  42267. }
  42268. return pts;
  42269. }
  42270. function prepareCoords(data) {
  42271. var coordsList = [];
  42272. data.each(function (idx) {
  42273. var itemModel = data.getItemModel(idx);
  42274. var coords = (itemModel.option instanceof Array) ?
  42275. itemModel.option : itemModel.getShallow('coords', true);
  42276. if (true) {
  42277. if (!(coords instanceof Array && coords.length > 0 && coords[0] instanceof Array)) {
  42278. throw new Error('Invalid coords ' + JSON.stringify(coords) + '. Lines must have 2d coords array in data item.');
  42279. }
  42280. }
  42281. coordsList.push(coords);
  42282. });
  42283. return {
  42284. coordsList: coordsList
  42285. };
  42286. }
  42287. function layoutGlobe(seriesModel, coordSys) {
  42288. var data = seriesModel.getData();
  42289. var isPolyline = seriesModel.get('polyline');
  42290. data.setLayout('lineType', isPolyline ? 'polyline' : 'cubicBezier');
  42291. var res = prepareCoords(data);
  42292. data.each(function (idx) {
  42293. var coords = res.coordsList[idx];
  42294. var getPointsMethod = isPolyline ? getPolylinePoints : getCubicPointsOnGlobe;
  42295. data.setItemLayout(idx, getPointsMethod(coords, coordSys));
  42296. });
  42297. }
  42298. function layoutOnPlane(seriesModel, coordSys, normal) {
  42299. var data = seriesModel.getData();
  42300. var isPolyline = seriesModel.get('polyline');
  42301. var res = prepareCoords(data);
  42302. data.setLayout('lineType', isPolyline ? 'polyline' : 'cubicBezier');
  42303. data.each(function (idx) {
  42304. var coords = res.coordsList[idx];
  42305. var pts = isPolyline ? getPolylinePoints(coords, coordSys)
  42306. : getCubicPointsOnPlane(coords, coordSys, normal);
  42307. data.setItemLayout(idx, pts);
  42308. });
  42309. }
  42310. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerLayout(function (ecModel, api) {
  42311. ecModel.eachSeriesByType('lines3D', function (seriesModel) {
  42312. var coordSys = seriesModel.coordinateSystem;
  42313. if (coordSys.type === 'globe') {
  42314. layoutGlobe(seriesModel, coordSys);
  42315. }
  42316. else if (coordSys.type === 'geo3D') {
  42317. layoutOnPlane(seriesModel, coordSys, [0, 1, 0]);
  42318. }
  42319. else if (coordSys.type === 'mapbox3D' || coordSys.type === 'maptalks3D') {
  42320. layoutOnPlane(seriesModel, coordSys, [0, 0, 1]);
  42321. }
  42322. });
  42323. });
  42324. /***/
  42325. }),
  42326. /* 245 */
  42327. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  42328. "use strict";
  42329. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  42330. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  42331. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__ = __webpack_require__(1);
  42332. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_geometry_Lines3D__ = __webpack_require__(25);
  42333. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__TrailMesh2__ = __webpack_require__(246);
  42334. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__util_shader_lines3D_glsl_js__ = __webpack_require__(46);
  42335. // import TrailMesh from './TrailMesh';
  42336. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader.import(__WEBPACK_IMPORTED_MODULE_4__util_shader_lines3D_glsl_js__["a" /* default */]);
  42337. function getCoordSysSize(coordSys) {
  42338. if (coordSys.radius != null) {
  42339. return coordSys.radius;
  42340. }
  42341. if (coordSys.size != null) {
  42342. return Math.max(coordSys.size[0], coordSys.size[1], coordSys.size[2]);
  42343. }
  42344. else {
  42345. return 100;
  42346. }
  42347. }
  42348. /* unused harmony default export */ var _unused_webpack_default_export = (__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendChartView({
  42349. type: 'lines3D',
  42350. __ecgl__: true,
  42351. init: function (ecModel, api) {
  42352. this.groupGL = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Node();
  42353. this._meshLinesMaterial = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Material({
  42354. shader: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].createShader('ecgl.meshLines3D'),
  42355. transparent: true,
  42356. depthMask: false
  42357. });
  42358. this._linesMesh = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh({
  42359. geometry: new __WEBPACK_IMPORTED_MODULE_2__util_geometry_Lines3D__["a" /* default */](),
  42360. material: this._meshLinesMaterial,
  42361. $ignorePicking: true
  42362. });
  42363. // this._trailMesh = new TrailMesh();
  42364. this._trailMesh = new __WEBPACK_IMPORTED_MODULE_3__TrailMesh2__["a" /* default */]();
  42365. },
  42366. render: function (seriesModel, ecModel, api) {
  42367. this.groupGL.add(this._linesMesh);
  42368. var coordSys = seriesModel.coordinateSystem;
  42369. var data = seriesModel.getData();
  42370. if (coordSys && coordSys.viewGL) {
  42371. var viewGL = coordSys.viewGL;
  42372. viewGL.add(this.groupGL);
  42373. this._updateLines(seriesModel, ecModel, api);
  42374. var methodName = coordSys.viewGL.isLinearSpace() ? 'define' : 'undefine';
  42375. this._linesMesh.material[methodName]('fragment', 'SRGB_DECODE');
  42376. this._trailMesh.material[methodName]('fragment', 'SRGB_DECODE');
  42377. }
  42378. var trailMesh = this._trailMesh;
  42379. trailMesh.stopAnimation();
  42380. if (seriesModel.get('effect.show')) {
  42381. this.groupGL.add(trailMesh);
  42382. trailMesh.updateData(data, api, this._linesMesh.geometry);
  42383. trailMesh.__time = trailMesh.__time || 0;
  42384. var time = 3600 * 1000; // 1hour
  42385. this._curveEffectsAnimator = trailMesh.animate('', { loop: true })
  42386. .when(time, {
  42387. __time: time
  42388. })
  42389. .during(function () {
  42390. trailMesh.setAnimationTime(trailMesh.__time);
  42391. })
  42392. .start();
  42393. }
  42394. else {
  42395. this.groupGL.remove(trailMesh);
  42396. this._curveEffectsAnimator = null;
  42397. }
  42398. this._linesMesh.material.blend = this._trailMesh.material.blend
  42399. = seriesModel.get('blendMode') === 'lighter'
  42400. ? __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].additiveBlend : null;
  42401. },
  42402. pauseEffect: function () {
  42403. if (this._curveEffectsAnimator) {
  42404. this._curveEffectsAnimator.pause();
  42405. }
  42406. },
  42407. resumeEffect: function () {
  42408. if (this._curveEffectsAnimator) {
  42409. this._curveEffectsAnimator.resume();
  42410. }
  42411. },
  42412. toggleEffect: function () {
  42413. var animator = this._curveEffectsAnimator;
  42414. if (animator) {
  42415. animator.isPaused() ? animator.resume() : animator.pause();
  42416. }
  42417. },
  42418. _updateLines: function (seriesModel, ecModel, api) {
  42419. var data = seriesModel.getData();
  42420. var coordSys = seriesModel.coordinateSystem;
  42421. var geometry = this._linesMesh.geometry;
  42422. var isPolyline = seriesModel.get('polyline');
  42423. geometry.expandLine = true;
  42424. var size = getCoordSysSize(coordSys);
  42425. geometry.segmentScale = size / 20;
  42426. var lineWidthQueryPath = 'lineStyle.width'.split('.');
  42427. var dpr = api.getDevicePixelRatio();
  42428. var maxLineWidth = 0;
  42429. data.each(function (idx) {
  42430. var itemModel = data.getItemModel(idx);
  42431. var lineWidth = itemModel.get(lineWidthQueryPath);
  42432. if (lineWidth == null) {
  42433. lineWidth = 1;
  42434. }
  42435. data.setItemVisual(idx, 'lineWidth', lineWidth);
  42436. maxLineWidth = Math.max(lineWidth, maxLineWidth);
  42437. });
  42438. // Must set useNativeLine before calling any other methods
  42439. geometry.useNativeLine = false;
  42440. var nVertex = 0;
  42441. var nTriangle = 0;
  42442. data.each(function (idx) {
  42443. var pts = data.getItemLayout(idx);
  42444. if (isPolyline) {
  42445. nVertex += geometry.getPolylineVertexCount(pts);
  42446. nTriangle += geometry.getPolylineTriangleCount(pts);
  42447. }
  42448. else {
  42449. nVertex += geometry.getCubicCurveVertexCount(pts[0], pts[1], pts[2], pts[3]);
  42450. nTriangle += geometry.getCubicCurveTriangleCount(pts[0], pts[1], pts[2], pts[3]);
  42451. }
  42452. });
  42453. geometry.setVertexCount(nVertex);
  42454. geometry.setTriangleCount(nTriangle);
  42455. geometry.resetOffset();
  42456. var colorArr = [];
  42457. data.each(function (idx) {
  42458. var pts = data.getItemLayout(idx);
  42459. var color = data.getItemVisual(idx, 'color');
  42460. var opacity = data.getItemVisual(idx, 'opacity');
  42461. var lineWidth = data.getItemVisual(idx, 'lineWidth') * dpr;
  42462. if (opacity == null) {
  42463. opacity = 1;
  42464. }
  42465. colorArr = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(color, colorArr);
  42466. colorArr[3] *= opacity;
  42467. if (isPolyline) {
  42468. geometry.addPolyline(pts, colorArr, lineWidth);
  42469. }
  42470. else {
  42471. geometry.addCubicCurve(pts[0], pts[1], pts[2], pts[3], colorArr, lineWidth);
  42472. }
  42473. });
  42474. geometry.dirty();
  42475. },
  42476. remove: function () {
  42477. this.groupGL.removeAll();
  42478. },
  42479. dispose: function () {
  42480. this.groupGL.removeAll();
  42481. }
  42482. }));
  42483. /***/
  42484. }),
  42485. /* 246 */
  42486. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  42487. "use strict";
  42488. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  42489. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  42490. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__ = __webpack_require__(1);
  42491. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_claygl_src_dep_glmatrix__ = __webpack_require__(6);
  42492. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__util_geometry_Lines3D__ = __webpack_require__(25);
  42493. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__shader_trail2_glsl_js__ = __webpack_require__(247);
  42494. var vec3 = __WEBPACK_IMPORTED_MODULE_2_claygl_src_dep_glmatrix__["a" /* default */].vec3;
  42495. function sign(a) {
  42496. return a > 0 ? 1 : -1;
  42497. }
  42498. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader.import(__WEBPACK_IMPORTED_MODULE_4__shader_trail2_glsl_js__["a" /* default */]);
  42499. /* harmony default export */ __webpack_exports__["a"] = (__WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh.extend(function () {
  42500. var material = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Material({
  42501. shader: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader(
  42502. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader.source('ecgl.trail2.vertex'),
  42503. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader.source('ecgl.trail2.fragment')
  42504. ),
  42505. transparent: true,
  42506. depthMask: false
  42507. });
  42508. var geometry = new __WEBPACK_IMPORTED_MODULE_3__util_geometry_Lines3D__["a" /* default */]({
  42509. dynamic: true
  42510. });
  42511. geometry.createAttribute('dist', 'float', 1);
  42512. geometry.createAttribute('distAll', 'float', 1);
  42513. geometry.createAttribute('start', 'float', 1);
  42514. return {
  42515. geometry: geometry,
  42516. material: material,
  42517. culling: false,
  42518. $ignorePicking: true
  42519. };
  42520. }, {
  42521. updateData: function (data, api, lines3DGeometry) {
  42522. var seriesModel = data.hostModel;
  42523. var geometry = this.geometry;
  42524. var effectModel = seriesModel.getModel('effect');
  42525. var size = effectModel.get('trailWidth') * api.getDevicePixelRatio();
  42526. var trailLength = effectModel.get('trailLength');
  42527. var speed = seriesModel.get('effect.constantSpeed');
  42528. var period = seriesModel.get('effect.period') * 1000;
  42529. var useConstantSpeed = speed != null;
  42530. if (true) {
  42531. if (!this.getScene()) {
  42532. console.error('TrailMesh must been add to scene before updateData');
  42533. }
  42534. }
  42535. useConstantSpeed
  42536. ? this.material.set('speed', speed / 1000)
  42537. : this.material.set('period', period);
  42538. this.material[useConstantSpeed ? 'define' : 'undefine']('vertex', 'CONSTANT_SPEED');
  42539. var isPolyline = seriesModel.get('polyline');
  42540. geometry.trailLength = trailLength;
  42541. this.material.set('trailLength', trailLength);
  42542. geometry.resetOffset();
  42543. ['position', 'positionPrev', 'positionNext'].forEach(function (attrName) {
  42544. geometry.attributes[attrName].value = lines3DGeometry.attributes[attrName].value;
  42545. });
  42546. var extraAttrs = ['dist', 'distAll', 'start', 'offset', 'color'];
  42547. extraAttrs.forEach(function (attrName) {
  42548. geometry.attributes[attrName].init(geometry.vertexCount);
  42549. });
  42550. geometry.indices = lines3DGeometry.indices;
  42551. var colorArr = [];
  42552. var effectColor = effectModel.get('trailColor');
  42553. var effectOpacity = effectModel.get('trailOpacity');
  42554. var hasEffectColor = effectColor != null;
  42555. var hasEffectOpacity = effectOpacity != null;
  42556. this.updateWorldTransform();
  42557. var xScale = this.worldTransform.x.len();
  42558. var yScale = this.worldTransform.y.len();
  42559. var zScale = this.worldTransform.z.len();
  42560. var vertexOffset = 0;
  42561. var maxDistance = 0;
  42562. data.each(function (idx) {
  42563. var pts = data.getItemLayout(idx);
  42564. var opacity = hasEffectOpacity ? effectOpacity : data.getItemVisual(idx, 'opacity');
  42565. var color = data.getItemVisual(idx, 'color');
  42566. if (opacity == null) {
  42567. opacity = 1;
  42568. }
  42569. colorArr = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(hasEffectColor ? effectColor : color, colorArr);
  42570. colorArr[3] *= opacity;
  42571. var vertexCount = isPolyline
  42572. ? lines3DGeometry.getPolylineVertexCount(pts)
  42573. : lines3DGeometry.getCubicCurveVertexCount(pts[0], pts[1], pts[2], pts[3])
  42574. var dist = 0;
  42575. var pos = [];
  42576. var posPrev = [];
  42577. for (var i = vertexOffset; i < vertexOffset + vertexCount; i++) {
  42578. geometry.attributes.position.get(i, pos);
  42579. pos[0] *= xScale;
  42580. pos[1] *= yScale;
  42581. pos[2] *= zScale;
  42582. if (i > vertexOffset) {
  42583. dist += vec3.dist(pos, posPrev);
  42584. }
  42585. geometry.attributes.dist.set(i, dist);
  42586. vec3.copy(posPrev, pos);
  42587. }
  42588. maxDistance = Math.max(maxDistance, dist);
  42589. var randomStart = Math.random() * (useConstantSpeed ? dist : period);
  42590. for (var i = vertexOffset; i < vertexOffset + vertexCount; i++) {
  42591. geometry.attributes.distAll.set(i, dist);
  42592. geometry.attributes.start.set(i, randomStart);
  42593. geometry.attributes.offset.set(
  42594. i, sign(lines3DGeometry.attributes.offset.get(i)) * size / 2
  42595. );
  42596. geometry.attributes.color.set(i, colorArr);
  42597. }
  42598. vertexOffset += vertexCount;
  42599. });
  42600. this.material.set('spotSize', maxDistance * 0.1 * trailLength);
  42601. this.material.set('spotIntensity', effectModel.get('spotIntensity'));
  42602. geometry.dirty();
  42603. },
  42604. setAnimationTime: function (time) {
  42605. this.material.set('time', time);
  42606. }
  42607. }));
  42608. /***/
  42609. }),
  42610. /* 247 */
  42611. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  42612. "use strict";
  42613. /* harmony default export */ __webpack_exports__["a"] = ("@export ecgl.trail2.vertex\nattribute vec3 position: POSITION;\nattribute vec3 positionPrev;\nattribute vec3 positionNext;\nattribute float offset;\nattribute float dist;\nattribute float distAll;\nattribute float start;\n\nattribute vec4 a_Color : COLOR;\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform vec4 viewport : VIEWPORT;\nuniform float near : NEAR;\n\nuniform float speed : 0;\nuniform float trailLength: 0.3;\nuniform float time;\nuniform float period: 1000;\n\nuniform float spotSize: 1;\n\nvarying vec4 v_Color;\nvarying float v_Percent;\nvarying float v_SpotPercent;\n\n@import ecgl.common.wireframe.vertexHeader\n\n@import ecgl.lines3D.clipNear\n\nvoid main()\n{\n @import ecgl.lines3D.expandLine\n\n gl_Position = currProj;\n\n v_Color = a_Color;\n\n @import ecgl.common.wireframe.vertexMain\n\n#ifdef CONSTANT_SPEED\n float t = mod((speed * time + start) / distAll, 1. + trailLength) - trailLength;\n#else\n float t = mod((time + start) / period, 1. + trailLength) - trailLength;\n#endif\n\n float trailLen = distAll * trailLength;\n\n v_Percent = (dist - t * distAll) / trailLen;\n\n v_SpotPercent = spotSize / distAll;\n\n }\n@end\n\n\n@export ecgl.trail2.fragment\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\nuniform float spotIntensity: 5;\n\nvarying vec4 v_Color;\nvarying float v_Percent;\nvarying float v_SpotPercent;\n\n@import ecgl.common.wireframe.fragmentHeader\n\n@import clay.util.srgb\n\nvoid main()\n{\n if (v_Percent > 1.0 || v_Percent < 0.0) {\n discard;\n }\n\n float fade = v_Percent;\n\n#ifdef SRGB_DECODE\n gl_FragColor = sRGBToLinear(color * v_Color);\n#else\n gl_FragColor = color * v_Color;\n#endif\n\n @import ecgl.common.wireframe.fragmentMain\n\n if (v_Percent > (1.0 - v_SpotPercent)) {\n gl_FragColor.rgb *= spotIntensity;\n }\n\n gl_FragColor.a *= fade;\n}\n\n@end");
  42614. /***/
  42615. }),
  42616. /* 248 */
  42617. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  42618. "use strict";
  42619. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  42620. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  42621. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendSeriesModel({
  42622. type: 'series.lines3D',
  42623. dependencies: ['globe'],
  42624. visualColorAccessPath: 'lineStyle.color',
  42625. getInitialData: function (option, ecModel) {
  42626. var lineData = new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.List(['value'], this);
  42627. lineData.hasItemOption = false;
  42628. lineData.initData(option.data, [], function (dataItem, dimName, dataIndex, dimIndex) {
  42629. // dataItem is simply coords
  42630. if (dataItem instanceof Array) {
  42631. return NaN;
  42632. }
  42633. else {
  42634. lineData.hasItemOption = true;
  42635. var value = dataItem.value;
  42636. if (value != null) {
  42637. return value instanceof Array ? value[dimIndex] : value;
  42638. }
  42639. }
  42640. });
  42641. return lineData;
  42642. },
  42643. defaultOption: {
  42644. coordinateSystem: 'globe',
  42645. globeIndex: 0,
  42646. geo3DIndex: 0,
  42647. zlevel: -10,
  42648. polyline: false,
  42649. effect: {
  42650. show: false,
  42651. period: 4,
  42652. // Trail width
  42653. trailWidth: 4,
  42654. trailLength: 0.2,
  42655. spotIntensity: 6
  42656. },
  42657. silent: true,
  42658. // Support source-over, lighter
  42659. blendMode: 'source-over',
  42660. lineStyle: {
  42661. width: 1,
  42662. opacity: 0.5
  42663. // color
  42664. }
  42665. }
  42666. });
  42667. /***/
  42668. }),
  42669. /* 249 */
  42670. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  42671. "use strict";
  42672. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  42673. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  42674. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__polygons3D_Polygons3DSeries__ = __webpack_require__(250);
  42675. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__polygons3D_Polygons3DView__ = __webpack_require__(251);
  42676. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__common_opacityVisual__ = __webpack_require__(17);
  42677. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerVisual(Object(__WEBPACK_IMPORTED_MODULE_3__common_opacityVisual__["a" /* default */])('polygons3D'));
  42678. /***/
  42679. }),
  42680. /* 250 */
  42681. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  42682. "use strict";
  42683. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  42684. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  42685. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__component_common_componentShadingMixin__ = __webpack_require__(31);
  42686. function transformPolygon(coordSys, poly) {
  42687. var ret = [];
  42688. for (var i = 0; i < poly.length; i++) {
  42689. ret.push(coordSys.dataToPoint(poly[i]));
  42690. }
  42691. return ret;
  42692. }
  42693. var Polygons3DSeries = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendSeriesModel({
  42694. type: 'series.polygons3D',
  42695. getRegionModel: function (idx) {
  42696. return this.getData().getItemModel(idx);
  42697. },
  42698. getRegionPolygonCoords: function (idx) {
  42699. var coordSys = this.coordinateSystem;
  42700. var itemModel = this.getData().getItemModel(idx);
  42701. var coords = itemModel.option instanceof Array
  42702. ? itemModel.option : itemModel.getShallow('coords');
  42703. if (!itemModel.get('multiPolygon')) {
  42704. coords = [coords];
  42705. }
  42706. // TODO Validate
  42707. var out = [];
  42708. for (var i = 0; i < coords.length; i++) {
  42709. // TODO Convert here ?
  42710. var interiors = [];
  42711. for (var k = 1; k < coords[i].length; k++) {
  42712. interiors.push(transformPolygon(coordSys, coords[i][k]));
  42713. }
  42714. out.push({
  42715. exterior: transformPolygon(coordSys, coords[i][0]),
  42716. interiors: interiors
  42717. });
  42718. }
  42719. return out;
  42720. },
  42721. getInitialData: function (option) {
  42722. var polygonsData = new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.List(['value'], this);
  42723. polygonsData.hasItemOption = false;
  42724. polygonsData.initData(option.data, [], function (dataItem, dimName, dataIndex, dimIndex) {
  42725. // dataItem is simply coords
  42726. if (dataItem instanceof Array) {
  42727. return NaN;
  42728. }
  42729. else {
  42730. polygonsData.hasItemOption = true;
  42731. var value = dataItem.value;
  42732. if (value != null) {
  42733. return value instanceof Array ? value[dimIndex] : value;
  42734. }
  42735. }
  42736. });
  42737. return polygonsData;
  42738. },
  42739. defaultOption: {
  42740. show: true,
  42741. data: null,
  42742. multiPolygon: false,
  42743. progressiveThreshold: 1e3,
  42744. progressive: 1e3,
  42745. zlevel: -10,
  42746. label: {
  42747. show: false,
  42748. // Distance in 3d space.
  42749. distance: 2,
  42750. textStyle: {
  42751. fontSize: 20,
  42752. color: '#000',
  42753. backgroundColor: 'rgba(255,255,255,0.7)',
  42754. padding: 3,
  42755. borderRadius: 4
  42756. }
  42757. },
  42758. itemStyle: {
  42759. color: '#fff',
  42760. borderWidth: 0,
  42761. borderColor: '#333'
  42762. },
  42763. emphasis: {
  42764. itemStyle: {
  42765. color: '#639fc0'
  42766. },
  42767. label: {
  42768. show: true
  42769. }
  42770. }
  42771. }
  42772. });
  42773. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(Polygons3DSeries.prototype, __WEBPACK_IMPORTED_MODULE_1__component_common_componentShadingMixin__["a" /* default */]);
  42774. /* unused harmony default export */ var _unused_webpack_default_export = (Polygons3DSeries);
  42775. /***/
  42776. }),
  42777. /* 251 */
  42778. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  42779. "use strict";
  42780. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  42781. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  42782. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__component_common_Geo3DBuilder__ = __webpack_require__(64);
  42783. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__ = __webpack_require__(1);
  42784. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendChartView({
  42785. type: 'polygons3D',
  42786. __ecgl__: true,
  42787. init: function (ecModel, api) {
  42788. this.groupGL = new __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__["a" /* default */].Node();
  42789. this._geo3DBuilderList = [];
  42790. this._currentStep = 0;
  42791. },
  42792. render: function (seriesModel, ecModel, api) {
  42793. this.groupGL.removeAll();
  42794. var coordSys = seriesModel.coordinateSystem;
  42795. if (coordSys && coordSys.viewGL) {
  42796. coordSys.viewGL.add(this.groupGL);
  42797. }
  42798. var geo3DBuilder = this._geo3DBuilderList[0];
  42799. if (!geo3DBuilder) {
  42800. geo3DBuilder = new __WEBPACK_IMPORTED_MODULE_1__component_common_Geo3DBuilder__["a" /* default */](api);
  42801. geo3DBuilder.extrudeY = coordSys.type !== 'mapbox3D'
  42802. && coordSys.type !== 'maptalks3D';
  42803. this._geo3DBuilderList[0] = geo3DBuilder;
  42804. }
  42805. this._updateShaderDefines(coordSys, geo3DBuilder);
  42806. geo3DBuilder.update(seriesModel, ecModel, api);
  42807. this._geo3DBuilderList.length = 1;
  42808. this.groupGL.add(geo3DBuilder.rootNode);
  42809. },
  42810. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  42811. this.groupGL.removeAll();
  42812. var coordSys = seriesModel.coordinateSystem;
  42813. if (coordSys && coordSys.viewGL) {
  42814. coordSys.viewGL.add(this.groupGL);
  42815. }
  42816. this._currentStep = 0;
  42817. },
  42818. incrementalRender: function (params, seriesModel, ecModel, api) {
  42819. var geo3DBuilder = this._geo3DBuilderList[this._currentStep];
  42820. var coordSys = seriesModel.coordinateSystem;
  42821. if (!geo3DBuilder) {
  42822. geo3DBuilder = new __WEBPACK_IMPORTED_MODULE_1__component_common_Geo3DBuilder__["a" /* default */](api);
  42823. geo3DBuilder.extrudeY = coordSys.type !== 'mapbox3D'
  42824. && coordSys.type !== 'maptalks3D';
  42825. this._geo3DBuilderList[this._currentStep] = geo3DBuilder;
  42826. }
  42827. geo3DBuilder.update(seriesModel, ecModel, api, params.start, params.end);
  42828. this.groupGL.add(geo3DBuilder.rootNode);
  42829. this._updateShaderDefines(coordSys, geo3DBuilder);
  42830. this._currentStep++;
  42831. },
  42832. _updateShaderDefines: function (coordSys, geo3DBuilder) {
  42833. var methodName = coordSys.viewGL.isLinearSpace() ? 'define' : 'undefine';
  42834. geo3DBuilder.rootNode.traverse(function (mesh) {
  42835. if (mesh.material) {
  42836. mesh.material[methodName]('fragment', 'SRGB_DECODE');
  42837. // FIXME
  42838. if (coordSys.type === 'mapbox3D' || coordSys.type === 'maptalks3D') {
  42839. mesh.material.define('fragment', 'NORMAL_UP_AXIS', 2);
  42840. mesh.material.define('fragment', 'NORMAL_FRONT_AXIS', 1);
  42841. }
  42842. }
  42843. });
  42844. },
  42845. remove: function () {
  42846. this.groupGL.removeAll();
  42847. },
  42848. dispose: function () {
  42849. this.groupGL.removeAll();
  42850. }
  42851. });
  42852. /***/
  42853. }),
  42854. /* 252 */
  42855. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  42856. "use strict";
  42857. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  42858. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  42859. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__surface_SurfaceSeries__ = __webpack_require__(253);
  42860. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__surface_SurfaceView__ = __webpack_require__(254);
  42861. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__surface_surfaceLayout__ = __webpack_require__(255);
  42862. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__common_opacityVisual__ = __webpack_require__(17);
  42863. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerVisual(Object(__WEBPACK_IMPORTED_MODULE_4__common_opacityVisual__["a" /* default */])('surface'));
  42864. /***/
  42865. }),
  42866. /* 253 */
  42867. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  42868. "use strict";
  42869. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  42870. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  42871. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__component_common_componentShadingMixin__ = __webpack_require__(31);
  42872. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__common_formatTooltip__ = __webpack_require__(39);
  42873. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__common_createList__ = __webpack_require__(50);
  42874. var SurfaceSeries = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendSeriesModel({
  42875. type: 'series.surface',
  42876. dependencies: ['globe', 'grid3D', 'geo3D'],
  42877. visualColorAccessPath: 'itemStyle.color',
  42878. formatTooltip: function (dataIndex) {
  42879. return Object(__WEBPACK_IMPORTED_MODULE_2__common_formatTooltip__["a" /* default */])(this, dataIndex);
  42880. },
  42881. getInitialData: function (option, ecModel) {
  42882. var data = option.data;
  42883. function validateDimension(dimOpts) {
  42884. return !(isNaN(dimOpts.min) || isNaN(dimOpts.max) || isNaN(dimOpts.step));
  42885. }
  42886. function getPrecision(dimOpts) {
  42887. var getPrecision = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.number.getPrecisionSafe;
  42888. return Math.max(
  42889. getPrecision(dimOpts.min), getPrecision(dimOpts.max), getPrecision(dimOpts.step)
  42890. ) + 1;
  42891. }
  42892. if (!data) {
  42893. if (!option.parametric) {
  42894. // From surface equation
  42895. var equation = option.equation || {};
  42896. var xOpts = equation.x || {};
  42897. var yOpts = equation.y || {};
  42898. ['x', 'y'].forEach(function (dim) {
  42899. if (!validateDimension(equation[dim])) {
  42900. if (true) {
  42901. console.error('Invalid equation.%s', dim);
  42902. }
  42903. return;
  42904. }
  42905. });
  42906. if (typeof equation.z !== 'function') {
  42907. if (true) {
  42908. console.error('equation.z needs to be function');
  42909. }
  42910. return;
  42911. }
  42912. var xCount = Math.floor((xOpts.max + xOpts.step - xOpts.min) / xOpts.step);
  42913. var yCount = Math.floor((yOpts.max + yOpts.step - yOpts.min) / yOpts.step);
  42914. data = new Float32Array(xCount * yCount * 3);
  42915. var xPrecision = getPrecision(xOpts);
  42916. var yPrecision = getPrecision(yOpts);
  42917. var off = 0;
  42918. for (var j = 0; j < yCount; j++) {
  42919. for (var i = 0; i < xCount; i++) {
  42920. var x = i * xOpts.step + xOpts.min;
  42921. var y = j * yOpts.step + yOpts.min;
  42922. var x2 = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.number.round(Math.min(x, xOpts.max), xPrecision);
  42923. var y2 = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.number.round(Math.min(y, yOpts.max), yPrecision);
  42924. var z = equation.z(x2, y2);
  42925. data[off++] = x2;
  42926. data[off++] = y2;
  42927. data[off++] = z;
  42928. }
  42929. }
  42930. }
  42931. else {
  42932. var parametricEquation = option.parametricEquation || {};
  42933. var uOpts = parametricEquation.u || {};
  42934. var vOpts = parametricEquation.v || {};
  42935. ['u', 'v'].forEach(function (dim) {
  42936. if (!validateDimension(parametricEquation[dim])) {
  42937. if (true) {
  42938. console.error('Invalid parametricEquation.%s', dim);
  42939. }
  42940. return;
  42941. }
  42942. });
  42943. ['x', 'y', 'z'].forEach(function (dim) {
  42944. if (typeof parametricEquation[dim] !== 'function') {
  42945. if (true) {
  42946. console.error('parametricEquation.%s needs to be function', dim);
  42947. }
  42948. return;
  42949. }
  42950. });
  42951. var uCount = Math.floor((uOpts.max + uOpts.step - uOpts.min) / uOpts.step);
  42952. var vCount = Math.floor((vOpts.max + vOpts.step - vOpts.min) / vOpts.step);
  42953. data = new Float32Array(uCount * vCount * 5);
  42954. var uPrecision = getPrecision(uOpts);
  42955. var vPrecision = getPrecision(vOpts);
  42956. var off = 0;
  42957. for (var j = 0; j < vCount; j++) {
  42958. for (var i = 0; i < uCount; i++) {
  42959. var u = i * uOpts.step + uOpts.min;
  42960. var v = j * vOpts.step + vOpts.min;
  42961. var u2 = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.number.round(Math.min(u, uOpts.max), uPrecision);
  42962. var v2 = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.number.round(Math.min(v, vOpts.max), vPrecision);
  42963. var x = parametricEquation.x(u2, v2);
  42964. var y = parametricEquation.y(u2, v2);
  42965. var z = parametricEquation.z(u2, v2);
  42966. data[off++] = x;
  42967. data[off++] = y;
  42968. data[off++] = z;
  42969. data[off++] = u2;
  42970. data[off++] = v2;
  42971. }
  42972. }
  42973. }
  42974. }
  42975. var dims = ['x', 'y', 'z'];
  42976. if (option.parametric) {
  42977. dims.push('u', 'v');
  42978. }
  42979. // PENDING getSource?
  42980. var list = Object(__WEBPACK_IMPORTED_MODULE_3__common_createList__["a" /* default */])(this, dims, data);
  42981. return list;
  42982. },
  42983. defaultOption: {
  42984. coordinateSystem: 'cartesian3D',
  42985. zlevel: -10,
  42986. // Cartesian coordinate system
  42987. grid3DIndex: 0,
  42988. // Surface needs lambert shading to show the difference
  42989. shading: 'lambert',
  42990. // If parametric surface
  42991. parametric: false,
  42992. wireframe: {
  42993. show: true,
  42994. lineStyle: {
  42995. color: 'rgba(0,0,0,0.5)',
  42996. width: 1
  42997. }
  42998. },
  42999. /**
  43000. * Generate surface data from z = f(x, y) equation
  43001. */
  43002. equation: {
  43003. // [min, max, step]
  43004. x: {
  43005. min: -1,
  43006. max: 1,
  43007. step: 0.1
  43008. },
  43009. y: {
  43010. min: -1,
  43011. max: 1,
  43012. step: 0.1
  43013. },
  43014. z: null
  43015. },
  43016. parametricEquation: {
  43017. // [min, max, step]
  43018. u: {
  43019. min: -1,
  43020. max: 1,
  43021. step: 0.1
  43022. },
  43023. v: {
  43024. min: -1,
  43025. max: 1,
  43026. step: 0.1
  43027. },
  43028. // [x, y, z] = f(x, y)
  43029. x: null,
  43030. y: null,
  43031. z: null
  43032. },
  43033. itemStyle: {
  43034. // Color
  43035. },
  43036. animationDurationUpdate: 500
  43037. }
  43038. });
  43039. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(SurfaceSeries.prototype, __WEBPACK_IMPORTED_MODULE_1__component_common_componentShadingMixin__["a" /* default */]);
  43040. /* unused harmony default export */ var _unused_webpack_default_export = (SurfaceSeries);
  43041. /***/
  43042. }),
  43043. /* 254 */
  43044. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  43045. "use strict";
  43046. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  43047. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  43048. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__ = __webpack_require__(1);
  43049. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_retrieve__ = __webpack_require__(2);
  43050. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_claygl_src_dep_glmatrix__ = __webpack_require__(6);
  43051. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__util_geometry_trianglesSortMixin__ = __webpack_require__(65);
  43052. var vec3 = __WEBPACK_IMPORTED_MODULE_3_claygl_src_dep_glmatrix__["a" /* default */].vec3;
  43053. function isPointsNaN(pt) {
  43054. return isNaN(pt[0]) || isNaN(pt[1]) || isNaN(pt[2]);
  43055. }
  43056. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendChartView({
  43057. type: 'surface',
  43058. __ecgl__: true,
  43059. init: function (ecModel, api) {
  43060. this.groupGL = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Node();
  43061. },
  43062. render: function (seriesModel, ecModel, api) {
  43063. // Swap surfaceMesh
  43064. var tmp = this._prevSurfaceMesh;
  43065. this._prevSurfaceMesh = this._surfaceMesh;
  43066. this._surfaceMesh = tmp;
  43067. if (!this._surfaceMesh) {
  43068. this._surfaceMesh = this._createSurfaceMesh();
  43069. }
  43070. this.groupGL.remove(this._prevSurfaceMesh);
  43071. this.groupGL.add(this._surfaceMesh);
  43072. var coordSys = seriesModel.coordinateSystem;
  43073. var shading = seriesModel.get('shading');
  43074. var data = seriesModel.getData();
  43075. var shadingPrefix = 'ecgl.' + shading;
  43076. if (!this._surfaceMesh.material || this._surfaceMesh.material.shader.name !== shadingPrefix) {
  43077. this._surfaceMesh.material = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].createMaterial(shadingPrefix, ['VERTEX_COLOR', 'DOUBLE_SIDED']);
  43078. }
  43079. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].setMaterialFromModel(
  43080. shading, this._surfaceMesh.material, seriesModel, api
  43081. );
  43082. if (coordSys && coordSys.viewGL) {
  43083. coordSys.viewGL.add(this.groupGL);
  43084. var methodName = coordSys.viewGL.isLinearSpace() ? 'define' : 'undefine';
  43085. this._surfaceMesh.material[methodName]('fragment', 'SRGB_DECODE');
  43086. }
  43087. var isParametric = seriesModel.get('parametric');
  43088. var dataShape = this._getDataShape(data, isParametric);
  43089. var wireframeModel = seriesModel.getModel('wireframe');
  43090. var wireframeLineWidth = wireframeModel.get('lineStyle.width');
  43091. var showWireframe = wireframeModel.get('show') && wireframeLineWidth > 0;
  43092. this._updateSurfaceMesh(this._surfaceMesh, seriesModel, dataShape, showWireframe);
  43093. var material = this._surfaceMesh.material;
  43094. if (showWireframe) {
  43095. material.define('WIREFRAME_QUAD');
  43096. material.set('wireframeLineWidth', wireframeLineWidth);
  43097. material.set('wireframeLineColor', __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(wireframeModel.get('lineStyle.color')));
  43098. }
  43099. else {
  43100. material.undefine('WIREFRAME_QUAD');
  43101. }
  43102. this._initHandler(seriesModel, api);
  43103. this._updateAnimation(seriesModel);
  43104. },
  43105. _updateAnimation: function (seriesModel) {
  43106. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].updateVertexAnimation(
  43107. [['prevPosition', 'position'],
  43108. ['prevNormal', 'normal']],
  43109. this._prevSurfaceMesh,
  43110. this._surfaceMesh,
  43111. seriesModel
  43112. );
  43113. },
  43114. _createSurfaceMesh: function () {
  43115. var mesh = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh({
  43116. geometry: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Geometry({
  43117. dynamic: true,
  43118. sortTriangles: true
  43119. }),
  43120. shadowDepthMaterial: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Material({
  43121. shader: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader(__WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader.source('ecgl.sm.depth.vertex'), __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader.source('ecgl.sm.depth.fragment'))
  43122. }),
  43123. culling: false,
  43124. // Render after axes
  43125. renderOrder: 10,
  43126. // Render normal in normal pass
  43127. renderNormal: true
  43128. });
  43129. mesh.geometry.createAttribute('barycentric', 'float', 4);
  43130. mesh.geometry.createAttribute('prevPosition', 'float', 3);
  43131. mesh.geometry.createAttribute('prevNormal', 'float', 3);
  43132. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.extend(mesh.geometry, __WEBPACK_IMPORTED_MODULE_4__util_geometry_trianglesSortMixin__["a" /* default */]);
  43133. return mesh;
  43134. },
  43135. _initHandler: function (seriesModel, api) {
  43136. var data = seriesModel.getData();
  43137. var surfaceMesh = this._surfaceMesh;
  43138. var coordSys = seriesModel.coordinateSystem;
  43139. function getNearestPointIdx(triangle, point) {
  43140. var nearestDist = Infinity;
  43141. var nearestIdx = -1;
  43142. var pos = [];
  43143. for (var i = 0; i < triangle.length; i++) {
  43144. surfaceMesh.geometry.attributes.position.get(triangle[i], pos);
  43145. var dist = vec3.dist(point.array, pos);
  43146. if (dist < nearestDist) {
  43147. nearestDist = dist;
  43148. nearestIdx = triangle[i];
  43149. }
  43150. }
  43151. return nearestIdx;
  43152. }
  43153. surfaceMesh.seriesIndex = seriesModel.seriesIndex;
  43154. var lastDataIndex = -1;
  43155. surfaceMesh.off('mousemove');
  43156. surfaceMesh.off('mouseout');
  43157. surfaceMesh.on('mousemove', function (e) {
  43158. var idx = getNearestPointIdx(e.triangle, e.point);
  43159. if (idx >= 0) {
  43160. var point = [];
  43161. surfaceMesh.geometry.attributes.position.get(idx, point);
  43162. var value = coordSys.pointToData(point);
  43163. var minDist = Infinity;
  43164. var dataIndex = -1;
  43165. var item = [];
  43166. for (var i = 0; i < data.count(); i++) {
  43167. item[0] = data.get('x', i);
  43168. item[1] = data.get('y', i);
  43169. item[2] = data.get('z', i);
  43170. var dist = vec3.squaredDistance(item, value);
  43171. if (dist < minDist) {
  43172. dataIndex = i;
  43173. minDist = dist;
  43174. }
  43175. }
  43176. if (dataIndex !== lastDataIndex) {
  43177. api.dispatchAction({
  43178. type: 'grid3DShowAxisPointer',
  43179. value: value
  43180. });
  43181. }
  43182. lastDataIndex = dataIndex;
  43183. surfaceMesh.dataIndex = dataIndex;
  43184. }
  43185. else {
  43186. surfaceMesh.dataIndex = -1;
  43187. }
  43188. }, this);
  43189. surfaceMesh.on('mouseout', function (e) {
  43190. lastDataIndex = -1;
  43191. surfaceMesh.dataIndex = -1;
  43192. api.dispatchAction({
  43193. type: 'grid3DHideAxisPointer'
  43194. });
  43195. }, this);
  43196. },
  43197. _updateSurfaceMesh: function (surfaceMesh, seriesModel, dataShape, showWireframe) {
  43198. var geometry = surfaceMesh.geometry;
  43199. var data = seriesModel.getData();
  43200. var pointsArr = data.getLayout('points');
  43201. var invalidDataCount = 0;
  43202. data.each(function (idx) {
  43203. if (!data.hasValue(idx)) {
  43204. invalidDataCount++;
  43205. }
  43206. });
  43207. var needsSplitQuad = invalidDataCount || showWireframe;
  43208. var positionAttr = geometry.attributes.position;
  43209. var normalAttr = geometry.attributes.normal;
  43210. var texcoordAttr = geometry.attributes.texcoord0;
  43211. var barycentricAttr = geometry.attributes.barycentric;
  43212. var colorAttr = geometry.attributes.color;
  43213. var row = dataShape.row;
  43214. var column = dataShape.column;
  43215. var shading = seriesModel.get('shading');
  43216. var needsNormal = shading !== 'color';
  43217. if (needsSplitQuad) {
  43218. // TODO, If needs remove the invalid points, or set color transparent.
  43219. var vertexCount = (row - 1) * (column - 1) * 4;
  43220. positionAttr.init(vertexCount);
  43221. if (showWireframe) {
  43222. barycentricAttr.init(vertexCount);
  43223. }
  43224. }
  43225. else {
  43226. positionAttr.value = new Float32Array(pointsArr);
  43227. }
  43228. colorAttr.init(geometry.vertexCount);
  43229. texcoordAttr.init(geometry.vertexCount);
  43230. var quadToTriangle = [0, 3, 1, 1, 3, 2];
  43231. // 3----2
  43232. // 0----1
  43233. // Make sure pixels on 1---3 edge will not have channel 0.
  43234. // And pixels on four edges have at least one channel 0.
  43235. var quadBarycentric = [
  43236. [1, 1, 0, 0],
  43237. [0, 1, 0, 1],
  43238. [1, 0, 0, 1],
  43239. [1, 0, 1, 0]
  43240. ];
  43241. var indices = geometry.indices = new (geometry.vertexCount > 0xffff ? Uint32Array : Uint16Array)((row - 1) * (column - 1) * 6);
  43242. var getQuadIndices = function (i, j, out) {
  43243. out[1] = i * column + j;
  43244. out[0] = i * column + j + 1;
  43245. out[3] = (i + 1) * column + j + 1;
  43246. out[2] = (i + 1) * column + j;
  43247. };
  43248. var isTransparent = false;
  43249. if (needsSplitQuad) {
  43250. var quadIndices = [];
  43251. var pos = [];
  43252. var faceOffset = 0;
  43253. if (needsNormal) {
  43254. normalAttr.init(geometry.vertexCount);
  43255. }
  43256. else {
  43257. normalAttr.value = null;
  43258. }
  43259. var pts = [[], [], []];
  43260. var v21 = [], v32 = [];
  43261. var normal = vec3.create();
  43262. var getFromArray = function (arr, idx, out) {
  43263. var idx3 = idx * 3;
  43264. out[0] = arr[idx3];
  43265. out[1] = arr[idx3 + 1];
  43266. out[2] = arr[idx3 + 2];
  43267. return out;
  43268. };
  43269. var vertexNormals = new Float32Array(pointsArr.length);
  43270. var vertexColors = new Float32Array(pointsArr.length / 3 * 4);
  43271. for (var i = 0; i < data.count(); i++) {
  43272. if (data.hasValue(i)) {
  43273. var rgbaArr = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(data.getItemVisual(i, 'color'));
  43274. var opacity = data.getItemVisual(i, 'opacity');
  43275. rgbaArr[3] *= opacity;
  43276. if (rgbaArr[3] < 0.99) {
  43277. isTransparent = true;
  43278. }
  43279. for (var k = 0; k < 4; k++) {
  43280. vertexColors[i * 4 + k] = rgbaArr[k];
  43281. }
  43282. }
  43283. }
  43284. var farPoints = [1e7, 1e7, 1e7];
  43285. for (var i = 0; i < row - 1; i++) {
  43286. for (var j = 0; j < column - 1; j++) {
  43287. var dataIndex = i * (column - 1) + j;
  43288. var vertexOffset = dataIndex * 4;
  43289. getQuadIndices(i, j, quadIndices);
  43290. var invisibleQuad = false;
  43291. for (var k = 0; k < 4; k++) {
  43292. getFromArray(pointsArr, quadIndices[k], pos);
  43293. if (isPointsNaN(pos)) {
  43294. // Quad is invisible if any point is NaN
  43295. invisibleQuad = true;
  43296. }
  43297. }
  43298. for (var k = 0; k < 4; k++) {
  43299. if (invisibleQuad) {
  43300. // Move point far away
  43301. positionAttr.set(vertexOffset + k, farPoints);
  43302. }
  43303. else {
  43304. getFromArray(pointsArr, quadIndices[k], pos);
  43305. positionAttr.set(vertexOffset + k, pos);
  43306. }
  43307. if (showWireframe) {
  43308. barycentricAttr.set(vertexOffset + k, quadBarycentric[k]);
  43309. }
  43310. }
  43311. for (var k = 0; k < 6; k++) {
  43312. indices[faceOffset++] = quadToTriangle[k] + vertexOffset;
  43313. }
  43314. // Vertex normals
  43315. if (needsNormal && !invisibleQuad) {
  43316. for (var k = 0; k < 2; k++) {
  43317. var k3 = k * 3;
  43318. for (var m = 0; m < 3; m++) {
  43319. var idx = quadIndices[quadToTriangle[k3] + m];
  43320. getFromArray(pointsArr, idx, pts[m]);
  43321. }
  43322. vec3.sub(v21, pts[0], pts[1]);
  43323. vec3.sub(v32, pts[1], pts[2]);
  43324. vec3.cross(normal, v21, v32);
  43325. // Weighted by the triangle area
  43326. for (var m = 0; m < 3; m++) {
  43327. var idx3 = quadIndices[quadToTriangle[k3] + m] * 3;
  43328. vertexNormals[idx3] = vertexNormals[idx3] + normal[0];
  43329. vertexNormals[idx3 + 1] = vertexNormals[idx3 + 1] + normal[1];
  43330. vertexNormals[idx3 + 2] = vertexNormals[idx3 + 2] + normal[2];
  43331. }
  43332. }
  43333. }
  43334. }
  43335. }
  43336. if (needsNormal) {
  43337. for (var i = 0; i < vertexNormals.length / 3; i++) {
  43338. getFromArray(vertexNormals, i, normal);
  43339. vec3.normalize(normal, normal);
  43340. vertexNormals[i * 3] = normal[0];
  43341. vertexNormals[i * 3 + 1] = normal[1];
  43342. vertexNormals[i * 3 + 2] = normal[2];
  43343. }
  43344. }
  43345. // Split normal and colors, write to the attributes.
  43346. var rgbaArr = [];
  43347. var uvArr = [];
  43348. for (var i = 0; i < row - 1; i++) {
  43349. for (var j = 0; j < column - 1; j++) {
  43350. var dataIndex = i * (column - 1) + j;
  43351. var vertexOffset = dataIndex * 4;
  43352. getQuadIndices(i, j, quadIndices);
  43353. for (var k = 0; k < 4; k++) {
  43354. for (var m = 0; m < 4; m++) {
  43355. rgbaArr[m] = vertexColors[quadIndices[k] * 4 + m];
  43356. }
  43357. colorAttr.set(vertexOffset + k, rgbaArr);
  43358. if (needsNormal) {
  43359. getFromArray(vertexNormals, quadIndices[k], normal);
  43360. normalAttr.set(vertexOffset + k, normal);
  43361. }
  43362. var idx = quadIndices[k];
  43363. uvArr[0] = (idx % column) / (column - 1);
  43364. uvArr[1] = Math.floor(idx / column) / (row - 1);
  43365. texcoordAttr.set(vertexOffset + k, uvArr);
  43366. }
  43367. dataIndex++;
  43368. }
  43369. }
  43370. }
  43371. else {
  43372. var uvArr = [];
  43373. for (var i = 0; i < data.count(); i++) {
  43374. uvArr[0] = (i % column) / (column - 1);
  43375. uvArr[1] = Math.floor(i / column) / (row - 1);
  43376. var rgbaArr = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(data.getItemVisual(i, 'color'));
  43377. var opacity = data.getItemVisual(i, 'opacity');
  43378. rgbaArr[3] *= opacity;
  43379. if (rgbaArr[3] < 0.99) {
  43380. isTransparent = true;
  43381. }
  43382. colorAttr.set(i, rgbaArr);
  43383. texcoordAttr.set(i, uvArr);
  43384. }
  43385. var quadIndices = [];
  43386. // Triangles
  43387. var cursor = 0;
  43388. for (var i = 0; i < row - 1; i++) {
  43389. for (var j = 0; j < column - 1; j++) {
  43390. getQuadIndices(i, j, quadIndices);
  43391. for (var k = 0; k < 6; k++) {
  43392. indices[cursor++] = quadIndices[quadToTriangle[k]];
  43393. }
  43394. }
  43395. }
  43396. if (needsNormal) {
  43397. geometry.generateVertexNormals();
  43398. }
  43399. else {
  43400. normalAttr.value = null;
  43401. }
  43402. }
  43403. if (surfaceMesh.material.get('normalMap')) {
  43404. geometry.generateTangents();
  43405. }
  43406. geometry.updateBoundingBox();
  43407. geometry.dirty();
  43408. surfaceMesh.material.transparent = isTransparent;
  43409. surfaceMesh.material.depthMask = !isTransparent;
  43410. },
  43411. _getDataShape: function (data, isParametric) {
  43412. var prevX = -Infinity;
  43413. var rowCount = 0;
  43414. var columnCount = 0;
  43415. var prevColumnCount = 0;
  43416. var rowDim = isParametric ? 'u' : 'x';
  43417. // Check data format
  43418. for (var i = 0; i < data.count(); i++) {
  43419. var x = data.get(rowDim, i);
  43420. if (x < prevX) {
  43421. if (prevColumnCount && prevColumnCount !== columnCount) {
  43422. if (true) {
  43423. throw new Error('Invalid data. data should be a row major 2d array.')
  43424. }
  43425. }
  43426. // A new row.
  43427. prevColumnCount = columnCount;
  43428. columnCount = 0;
  43429. rowCount++;
  43430. }
  43431. prevX = x;
  43432. columnCount++;
  43433. }
  43434. return {
  43435. row: rowCount + 1,
  43436. column: columnCount
  43437. };
  43438. },
  43439. dispose: function () {
  43440. this.groupGL.removeAll();
  43441. },
  43442. remove: function () {
  43443. this.groupGL.removeAll();
  43444. }
  43445. });
  43446. /***/
  43447. }),
  43448. /* 255 */
  43449. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  43450. "use strict";
  43451. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  43452. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  43453. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerLayout(function (ecModel, api) {
  43454. ecModel.eachSeriesByType('surface', function (surfaceModel) {
  43455. var cartesian = surfaceModel.coordinateSystem;
  43456. if (!cartesian || cartesian.type !== 'cartesian3D') {
  43457. if (true) {
  43458. console.error('Surface chart only support cartesian3D coordinateSystem');
  43459. }
  43460. }
  43461. var data = surfaceModel.getData();
  43462. var points = new Float32Array(3 * data.count());
  43463. var nanPoint = [NaN, NaN, NaN];
  43464. if (cartesian && cartesian.type === 'cartesian3D') {
  43465. var coordDims = cartesian.dimensions;
  43466. var dims = coordDims.map(function (coordDim) {
  43467. return surfaceModel.coordDimToDataDim(coordDim)[0];
  43468. });
  43469. data.each(dims, function (x, y, z, idx) {
  43470. var pt;
  43471. if (!data.hasValue(idx)) {
  43472. pt = nanPoint;
  43473. }
  43474. else {
  43475. pt = cartesian.dataToPoint([x, y, z]);
  43476. }
  43477. points[idx * 3] = pt[0];
  43478. points[idx * 3 + 1] = pt[1];
  43479. points[idx * 3 + 2] = pt[2];
  43480. });
  43481. }
  43482. data.setLayout('points', points);
  43483. });
  43484. });
  43485. /***/
  43486. }),
  43487. /* 256 */
  43488. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  43489. "use strict";
  43490. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  43491. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  43492. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__coord_geo3D_Geo3D__ = __webpack_require__(99);
  43493. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__map3D_Map3DSeries__ = __webpack_require__(257);
  43494. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__map3D_Map3DView__ = __webpack_require__(258);
  43495. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__common_opacityVisual__ = __webpack_require__(17);
  43496. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerVisual(Object(__WEBPACK_IMPORTED_MODULE_4__common_opacityVisual__["a" /* default */])('map3D'));
  43497. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerAction({
  43498. type: 'map3DChangeCamera',
  43499. event: 'map3dcamerachanged',
  43500. update: 'series:updateCamera'
  43501. }, function (payload, ecModel) {
  43502. ecModel.eachComponent({
  43503. mainType: 'series', subType: 'map3D', query: payload
  43504. }, function (componentModel) {
  43505. componentModel.setView(payload);
  43506. });
  43507. });
  43508. /***/
  43509. }),
  43510. /* 257 */
  43511. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  43512. "use strict";
  43513. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  43514. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  43515. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__component_common_componentViewControlMixin__ = __webpack_require__(44);
  43516. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__component_common_componentPostEffectMixin__ = __webpack_require__(28);
  43517. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__component_common_componentLightMixin__ = __webpack_require__(29);
  43518. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__component_common_componentShadingMixin__ = __webpack_require__(31);
  43519. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__coord_geo3D_geo3DModelMixin__ = __webpack_require__(96);
  43520. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__util_format__ = __webpack_require__(32);
  43521. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__common_formatTooltip__ = __webpack_require__(39);
  43522. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__coord_geo3DCreator__ = __webpack_require__(98);
  43523. function transformPolygon(mapbox3DCoordSys, poly) {
  43524. var newPoly = [];
  43525. for (var k = 0; k < poly.length; k++) {
  43526. newPoly.push(mapbox3DCoordSys.dataToPoint(poly[k]));
  43527. }
  43528. return newPoly;
  43529. }
  43530. var Map3DSeries = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendSeriesModel({
  43531. type: 'series.map3D',
  43532. layoutMode: 'box',
  43533. coordinateSystem: null,
  43534. visualColorAccessPath: 'itemStyle.color',
  43535. optionUpdated: function (newOpt) {
  43536. newOpt = newOpt || {};
  43537. var coordSysType = this.get('coordinateSystem');
  43538. if (coordSysType == null || coordSysType === 'geo3D') {
  43539. return;
  43540. }
  43541. if (true) {
  43542. var propsNeedToCheck = [
  43543. 'left', 'top', 'width', 'height',
  43544. 'boxWidth', 'boxDepth', 'boxHeight',
  43545. 'light', 'viewControl', 'postEffect', 'temporalSuperSampling',
  43546. 'environment', 'groundPlane'
  43547. ];
  43548. var ignoredProperties = [];
  43549. propsNeedToCheck.forEach(function (propName) {
  43550. if (newOpt[propName] != null) {
  43551. ignoredProperties.push(propName);
  43552. }
  43553. });
  43554. if (ignoredProperties.length) {
  43555. console.warn(
  43556. 'Property %s in map3D series will be ignored if coordinate system is %s',
  43557. ignoredProperties.join(', '), coordSysType
  43558. );
  43559. }
  43560. }
  43561. if (this.get('groundPlane.show')) {
  43562. // Force disable groundPlane if map3D has other coordinate systems.
  43563. this.option.groundPlane.show = false;
  43564. }
  43565. // Reset geo.
  43566. this._geo = null;
  43567. },
  43568. getInitialData: function (option) {
  43569. option.data = this.getFilledRegions(option.data, option.map);
  43570. var dimensions = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.helper.completeDimensions(['value'], option.data);
  43571. var list = new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.List(dimensions, this);
  43572. list.initData(option.data);
  43573. var regionModelMap = {};
  43574. list.each(function (idx) {
  43575. var name = list.getName(idx);
  43576. var itemModel = list.getItemModel(idx);
  43577. regionModelMap[name] = itemModel;
  43578. });
  43579. this._regionModelMap = regionModelMap;
  43580. return list;
  43581. },
  43582. formatTooltip: function (dataIndex) {
  43583. return Object(__WEBPACK_IMPORTED_MODULE_7__common_formatTooltip__["a" /* default */])(this, dataIndex);
  43584. },
  43585. getRegionModel: function (idx) {
  43586. var name = this.getData().getName(idx);
  43587. return this._regionModelMap[name] || new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.Model(null, this);
  43588. },
  43589. getRegionPolygonCoords: function (idx) {
  43590. var coordSys = this.coordinateSystem;
  43591. var name = this.getData().getName(idx);
  43592. if (coordSys.transform) {
  43593. var region = coordSys.getRegion(name);
  43594. return region ? region.geometries : [];
  43595. }
  43596. else {
  43597. if (!this._geo) {
  43598. this._geo = __WEBPACK_IMPORTED_MODULE_8__coord_geo3DCreator__["a" /* default */].createGeo3D(this);
  43599. }
  43600. var region = this._geo.getRegion(name);
  43601. var ret = [];
  43602. for (var k = 0; k < region.geometries.length; k++) {
  43603. var geo = region.geometries[k];
  43604. var interiors = [];
  43605. var exterior = transformPolygon(coordSys, geo.exterior);
  43606. if (interiors && interiors.length) {
  43607. for (var m = 0; m < geo.interiors.length; m++) {
  43608. interiors.push(transformPolygon(coordSys, interiors[m]));
  43609. }
  43610. }
  43611. ret.push({
  43612. interiors: interiors,
  43613. exterior: exterior
  43614. });
  43615. }
  43616. return ret;
  43617. }
  43618. },
  43619. /**
  43620. * Format label
  43621. * @param {string} name Region name
  43622. * @param {string} [status='normal'] 'normal' or 'emphasis'
  43623. * @return {string}
  43624. */
  43625. getFormattedLabel: function (dataIndex, status) {
  43626. var text = __WEBPACK_IMPORTED_MODULE_6__util_format__["a" /* default */].getFormattedLabel(this, dataIndex, status);
  43627. if (text == null) {
  43628. text = this.getData().getName(dataIndex);
  43629. }
  43630. return text;
  43631. },
  43632. defaultOption: {
  43633. // Support geo3D, mapbox, maptalks3D
  43634. coordinateSystem: 'geo3D',
  43635. // itemStyle: {},
  43636. // height,
  43637. // label: {}
  43638. data: null
  43639. }
  43640. });
  43641. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(Map3DSeries.prototype, __WEBPACK_IMPORTED_MODULE_5__coord_geo3D_geo3DModelMixin__["a" /* default */]);
  43642. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(Map3DSeries.prototype, __WEBPACK_IMPORTED_MODULE_1__component_common_componentViewControlMixin__["a" /* default */]);
  43643. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(Map3DSeries.prototype, __WEBPACK_IMPORTED_MODULE_2__component_common_componentPostEffectMixin__["a" /* default */]);
  43644. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(Map3DSeries.prototype, __WEBPACK_IMPORTED_MODULE_3__component_common_componentLightMixin__["a" /* default */]);
  43645. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.merge(Map3DSeries.prototype, __WEBPACK_IMPORTED_MODULE_4__component_common_componentShadingMixin__["a" /* default */]);
  43646. /* unused harmony default export */ var _unused_webpack_default_export = (Map3DSeries);
  43647. /***/
  43648. }),
  43649. /* 258 */
  43650. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  43651. "use strict";
  43652. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  43653. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  43654. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__ = __webpack_require__(1);
  43655. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_OrbitControl__ = __webpack_require__(45);
  43656. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__component_common_SceneHelper__ = __webpack_require__(30);
  43657. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__component_common_Geo3DBuilder__ = __webpack_require__(64);
  43658. /* unused harmony default export */ var _unused_webpack_default_export = (__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendChartView({
  43659. type: 'map3D',
  43660. __ecgl__: true,
  43661. init: function (ecModel, api) {
  43662. this._geo3DBuilder = new __WEBPACK_IMPORTED_MODULE_4__component_common_Geo3DBuilder__["a" /* default */](api);
  43663. this.groupGL = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Node();
  43664. },
  43665. render: function (map3DModel, ecModel, api) {
  43666. var coordSys = map3DModel.coordinateSystem;
  43667. if (!coordSys || !coordSys.viewGL) {
  43668. return;
  43669. }
  43670. this.groupGL.add(this._geo3DBuilder.rootNode);
  43671. coordSys.viewGL.add(this.groupGL);
  43672. var geo3D;
  43673. if (coordSys.type === 'geo3D') {
  43674. geo3D = coordSys;
  43675. if (!this._sceneHelper) {
  43676. this._sceneHelper = new __WEBPACK_IMPORTED_MODULE_3__component_common_SceneHelper__["a" /* default */]();
  43677. this._sceneHelper.initLight(this.groupGL);
  43678. }
  43679. this._sceneHelper.setScene(coordSys.viewGL.scene);
  43680. this._sceneHelper.updateLight(map3DModel);
  43681. // Set post effect
  43682. coordSys.viewGL.setPostEffect(map3DModel.getModel('postEffect'), api);
  43683. coordSys.viewGL.setTemporalSuperSampling(map3DModel.getModel('temporalSuperSampling'));
  43684. var control = this._control;
  43685. if (!control) {
  43686. control = this._control = new __WEBPACK_IMPORTED_MODULE_2__util_OrbitControl__["a" /* default */]({
  43687. zr: api.getZr()
  43688. });
  43689. this._control.init();
  43690. }
  43691. var viewControlModel = map3DModel.getModel('viewControl');
  43692. control.setViewGL(coordSys.viewGL);
  43693. control.setFromViewControlModel(viewControlModel, 0);
  43694. control.off('update');
  43695. control.on('update', function () {
  43696. api.dispatchAction({
  43697. type: 'map3DChangeCamera',
  43698. alpha: control.getAlpha(),
  43699. beta: control.getBeta(),
  43700. distance: control.getDistance(),
  43701. from: this.uid,
  43702. map3DId: map3DModel.id
  43703. });
  43704. });
  43705. this._geo3DBuilder.extrudeY = true;
  43706. }
  43707. else {
  43708. if (this._control) {
  43709. this._control.dispose();
  43710. this._control = null;
  43711. }
  43712. if (this._sceneHelper) {
  43713. this._sceneHelper.dispose();
  43714. this._sceneHelper = null;
  43715. }
  43716. geo3D = map3DModel.getData().getLayout('geo3D');
  43717. this._geo3DBuilder.extrudeY = false;
  43718. }
  43719. this._geo3DBuilder.update(map3DModel, ecModel, api, 0, map3DModel.getData().count());
  43720. // Must update after geo3D.viewGL.setPostEffect to determine linear space
  43721. var srgbDefineMethod = coordSys.viewGL.isLinearSpace() ? 'define' : 'undefine';
  43722. this._geo3DBuilder.rootNode.traverse(function (mesh) {
  43723. if (mesh.material) {
  43724. mesh.material[srgbDefineMethod]('fragment', 'SRGB_DECODE');
  43725. }
  43726. });
  43727. },
  43728. afterRender: function (map3DModel, ecModel, api, layerGL) {
  43729. var renderer = layerGL.renderer;
  43730. var coordSys = map3DModel.coordinateSystem;
  43731. if (coordSys && coordSys.type === 'geo3D') {
  43732. this._sceneHelper.updateAmbientCubemap(renderer, map3DModel, api);
  43733. this._sceneHelper.updateSkybox(renderer, map3DModel, api);
  43734. }
  43735. },
  43736. dispose: function () {
  43737. this.groupGL.removeAll();
  43738. this._control.dispose();
  43739. }
  43740. }));
  43741. /***/
  43742. }),
  43743. /* 259 */
  43744. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  43745. "use strict";
  43746. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  43747. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  43748. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__scatterGL_ScatterGLSeries__ = __webpack_require__(260);
  43749. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__scatterGL_ScatterGLView__ = __webpack_require__(261);
  43750. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_echarts_lib_visual_symbol__ = __webpack_require__(51);
  43751. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_echarts_lib_visual_symbol___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_3_echarts_lib_visual_symbol__);
  43752. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__common_opacityVisual__ = __webpack_require__(17);
  43753. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerVisual(__WEBPACK_IMPORTED_MODULE_3_echarts_lib_visual_symbol___default()('scatterGL', 'circle', null));
  43754. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerVisual(Object(__WEBPACK_IMPORTED_MODULE_4__common_opacityVisual__["a" /* default */])('scatterGL'));
  43755. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerLayout({
  43756. seriesType: 'scatterGL',
  43757. reset: function (seriesModel) {
  43758. var coordSys = seriesModel.coordinateSystem;
  43759. var progress;
  43760. if (coordSys) {
  43761. var dims = coordSys.dimensions;
  43762. var pt = [];
  43763. if (dims.length === 1) {
  43764. progress = function (params, data) {
  43765. var points = new Float32Array((params.end - params.start) * 2);
  43766. for (var idx = params.start; idx < params.end; idx++) {
  43767. var offset = (idx - params.start) * 2;
  43768. var x = data.get(dims[0], idx);
  43769. var pt = coordSys.dataToPoint(x);
  43770. points[offset] = pt[0];
  43771. points[offset + 1] = pt[1];
  43772. }
  43773. data.setLayout('points', points);
  43774. };
  43775. }
  43776. else if (dims.length === 2) {
  43777. progress = function (params, data) {
  43778. var points = new Float32Array((params.end - params.start) * 2);
  43779. for (var idx = params.start; idx < params.end; idx++) {
  43780. var offset = (idx - params.start) * 2;
  43781. var x = data.get(dims[0], idx);
  43782. var y = data.get(dims[1], idx);
  43783. pt[0] = x;
  43784. pt[1] = y;
  43785. pt = coordSys.dataToPoint(pt);
  43786. points[offset] = pt[0];
  43787. points[offset + 1] = pt[1];
  43788. }
  43789. data.setLayout('points', points);
  43790. };
  43791. }
  43792. }
  43793. return { progress: progress };
  43794. }
  43795. });
  43796. /***/
  43797. }),
  43798. /* 260 */
  43799. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  43800. "use strict";
  43801. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  43802. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  43803. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendSeriesModel({
  43804. type: 'series.scatterGL',
  43805. dependencies: ['grid', 'polar', 'geo', 'singleAxis'],
  43806. visualColorAccessPath: 'itemStyle.color',
  43807. getInitialData: function () {
  43808. return __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.helper.createList(this);
  43809. },
  43810. defaultOption: {
  43811. coordinateSystem: 'cartesian2d',
  43812. zlevel: 10,
  43813. progressive: 1e5,
  43814. progressiveThreshold: 1e5,
  43815. // Cartesian coordinate system
  43816. // xAxisIndex: 0,
  43817. // yAxisIndex: 0,
  43818. // Polar coordinate system
  43819. // polarIndex: 0,
  43820. // Geo coordinate system
  43821. // geoIndex: 0,
  43822. large: false,
  43823. symbol: 'circle',
  43824. symbolSize: 10,
  43825. // symbolSize scale when zooming.
  43826. zoomScale: 0,
  43827. // Support source-over, lighter
  43828. blendMode: 'source-over',
  43829. itemStyle: {
  43830. opacity: 0.8
  43831. },
  43832. postEffect: {
  43833. enable: false,
  43834. colorCorrection: {
  43835. exposure: 0,
  43836. brightness: 0,
  43837. contrast: 1,
  43838. saturation: 1,
  43839. enable: true
  43840. }
  43841. }
  43842. }
  43843. });
  43844. /***/
  43845. }),
  43846. /* 261 */
  43847. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  43848. "use strict";
  43849. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  43850. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  43851. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__ = __webpack_require__(1);
  43852. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__core_ViewGL__ = __webpack_require__(22);
  43853. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__common_PointsBuilder__ = __webpack_require__(67);
  43854. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__common_GLViewHelper__ = __webpack_require__(103);
  43855. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__util_retrieve__ = __webpack_require__(2);
  43856. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendChartView({
  43857. type: 'scatterGL',
  43858. __ecgl__: true,
  43859. init: function (ecModel, api) {
  43860. this.groupGL = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Node();
  43861. this.viewGL = new __WEBPACK_IMPORTED_MODULE_2__core_ViewGL__["a" /* default */]('orthographic');
  43862. this.viewGL.add(this.groupGL);
  43863. this._pointsBuilderList = [];
  43864. this._currentStep = 0;
  43865. this._sizeScale = 1;
  43866. this._glViewHelper = new __WEBPACK_IMPORTED_MODULE_4__common_GLViewHelper__["a" /* default */](this.viewGL);
  43867. },
  43868. render: function (seriesModel, ecModel, api) {
  43869. this.groupGL.removeAll();
  43870. this._glViewHelper.reset(seriesModel, api);
  43871. if (!seriesModel.getData().count()) {
  43872. return;
  43873. }
  43874. var pointsBuilder = this._pointsBuilderList[0];
  43875. if (!pointsBuilder) {
  43876. pointsBuilder = this._pointsBuilderList[0] = new __WEBPACK_IMPORTED_MODULE_3__common_PointsBuilder__["a" /* default */](true, api);
  43877. }
  43878. this._pointsBuilderList.length = 1;
  43879. this.groupGL.add(pointsBuilder.rootNode);
  43880. this._removeTransformInPoints(seriesModel.getData().getLayout('points'));
  43881. pointsBuilder.update(seriesModel, ecModel, api);
  43882. this.viewGL.setPostEffect(seriesModel.getModel('postEffect'), api);
  43883. },
  43884. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  43885. this.groupGL.removeAll();
  43886. this._glViewHelper.reset(seriesModel, api);
  43887. this._currentStep = 0;
  43888. this.viewGL.setPostEffect(seriesModel.getModel('postEffect'), api);
  43889. },
  43890. incrementalRender: function (params, seriesModel, ecModel, api) {
  43891. if (params.end <= params.start) {
  43892. return;
  43893. }
  43894. var pointsBuilder = this._pointsBuilderList[this._currentStep];
  43895. if (!pointsBuilder) {
  43896. pointsBuilder = new __WEBPACK_IMPORTED_MODULE_3__common_PointsBuilder__["a" /* default */](true, api);
  43897. this._pointsBuilderList[this._currentStep] = pointsBuilder;
  43898. }
  43899. this.groupGL.add(pointsBuilder.rootNode);
  43900. this._removeTransformInPoints(seriesModel.getData().getLayout('points'));
  43901. pointsBuilder.setSizeScale(this._sizeScale);
  43902. pointsBuilder.update(seriesModel, ecModel, api, params.start, params.end);
  43903. api.getZr().refresh();
  43904. this._currentStep++;
  43905. },
  43906. updateTransform: function (seriesModel, ecModel, api) {
  43907. if (seriesModel.coordinateSystem.getRoamTransform) {
  43908. this._glViewHelper.updateTransform(seriesModel, api);
  43909. var zoom = this._glViewHelper.getZoom();
  43910. var sizeScale = Math.max((seriesModel.get('zoomScale') || 0) * (zoom - 1) + 1, 0);
  43911. this._sizeScale = sizeScale;
  43912. this._pointsBuilderList.forEach(function (pointsBuilder) {
  43913. pointsBuilder.setSizeScale(sizeScale);
  43914. });
  43915. }
  43916. },
  43917. _removeTransformInPoints: function (points) {
  43918. if (!points) {
  43919. return;
  43920. }
  43921. var pt = [];
  43922. for (var i = 0; i < points.length; i += 2) {
  43923. pt[0] = points[i];
  43924. pt[1] = points[i + 1];
  43925. this._glViewHelper.removeTransformInPoint(pt);
  43926. points[i] = pt[0];
  43927. points[i + 1] = pt[1];
  43928. }
  43929. },
  43930. dispose: function () {
  43931. this.groupGL.removeAll();
  43932. },
  43933. remove: function () {
  43934. this.groupGL.removeAll();
  43935. }
  43936. });
  43937. /***/
  43938. }),
  43939. /* 262 */
  43940. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  43941. "use strict";
  43942. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  43943. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  43944. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__graphGL_GraphGLSeries__ = __webpack_require__(263);
  43945. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__graphGL_GraphGLView__ = __webpack_require__(268);
  43946. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_echarts_lib_visual_symbol__ = __webpack_require__(51);
  43947. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_echarts_lib_visual_symbol___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_3_echarts_lib_visual_symbol__);
  43948. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__common_opacityVisual__ = __webpack_require__(17);
  43949. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerVisual(__WEBPACK_IMPORTED_MODULE_3_echarts_lib_visual_symbol___default()('graphGL', 'circle', null));
  43950. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerVisual(Object(__WEBPACK_IMPORTED_MODULE_4__common_opacityVisual__["a" /* default */])('graphGL'));
  43951. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerVisual(function (ecModel) {
  43952. var paletteScope = {};
  43953. ecModel.eachSeriesByType('graphGL', function (seriesModel) {
  43954. var categoriesData = seriesModel.getCategoriesData();
  43955. var data = seriesModel.getData();
  43956. var categoryNameIdxMap = {};
  43957. categoriesData.each(function (idx) {
  43958. var name = categoriesData.getName(idx);
  43959. categoryNameIdxMap[name] = idx;
  43960. var itemModel = categoriesData.getItemModel(idx);
  43961. var color = itemModel.get('itemStyle.color')
  43962. || seriesModel.getColorFromPalette(name, paletteScope);
  43963. categoriesData.setItemVisual(idx, 'color', color);
  43964. });
  43965. // Assign category color to visual
  43966. if (categoriesData.count()) {
  43967. data.each(function (idx) {
  43968. var model = data.getItemModel(idx);
  43969. var category = model.getShallow('category');
  43970. if (category != null) {
  43971. if (typeof category === 'string') {
  43972. category = categoryNameIdxMap[category];
  43973. }
  43974. if (!data.getItemVisual(idx, 'color', true)) {
  43975. data.setItemVisual(
  43976. idx, 'color',
  43977. categoriesData.getItemVisual(category, 'color')
  43978. );
  43979. }
  43980. }
  43981. });
  43982. }
  43983. });
  43984. });
  43985. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerVisual(function (ecModel) {
  43986. ecModel.eachSeriesByType('graphGL', function (seriesModel) {
  43987. var graph = seriesModel.getGraph();
  43988. var edgeData = seriesModel.getEdgeData();
  43989. var colorQuery = 'lineStyle.color'.split('.');
  43990. var opacityQuery = 'lineStyle.opacity'.split('.');
  43991. edgeData.setVisual('color', seriesModel.get(colorQuery));
  43992. edgeData.setVisual('opacity', seriesModel.get(opacityQuery));
  43993. edgeData.each(function (idx) {
  43994. var itemModel = edgeData.getItemModel(idx);
  43995. var edge = graph.getEdgeByIndex(idx);
  43996. // Edge visual must after node visual
  43997. var color = itemModel.get(colorQuery);
  43998. var opacity = itemModel.get(opacityQuery);
  43999. switch (color) {
  44000. case 'source':
  44001. color = edge.node1.getVisual('color');
  44002. break;
  44003. case 'target':
  44004. color = edge.node2.getVisual('color');
  44005. break;
  44006. }
  44007. edge.setVisual('color', color);
  44008. edge.setVisual('opacity', opacity);
  44009. });
  44010. });
  44011. });
  44012. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerAction({
  44013. type: 'graphGLRoam',
  44014. event: 'graphglroam',
  44015. update: 'series.graphGL:roam'
  44016. }, function (payload, ecModel) {
  44017. ecModel.eachComponent({
  44018. mainType: 'series', query: payload
  44019. }, function (componentModel) {
  44020. componentModel.setView(payload);
  44021. });
  44022. });
  44023. function noop() { }
  44024. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerAction({
  44025. type: 'graphGLStartLayout',
  44026. event: 'graphgllayoutstarted',
  44027. update: 'series.graphGL:startLayout'
  44028. }, noop);
  44029. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerAction({
  44030. type: 'graphGLStopLayout',
  44031. event: 'graphgllayoutstopped',
  44032. update: 'series.graphGL:stopLayout'
  44033. }, noop);
  44034. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerAction({
  44035. type: 'graphGLFocusNodeAdjacency',
  44036. event: 'graphGLFocusNodeAdjacency',
  44037. update: 'series.graphGL:focusNodeAdjacency'
  44038. }, noop);
  44039. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerAction({
  44040. type: 'graphGLUnfocusNodeAdjacency',
  44041. event: 'graphGLUnfocusNodeAdjacency',
  44042. update: 'series.graphGL:unfocusNodeAdjacency'
  44043. }, noop);
  44044. /***/
  44045. }),
  44046. /* 263 */
  44047. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  44048. "use strict";
  44049. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  44050. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  44051. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__createGraphFromNodeEdge__ = __webpack_require__(264);
  44052. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_format__ = __webpack_require__(32);
  44053. var GraphSeries = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendSeriesModel({
  44054. type: 'series.graphGL',
  44055. visualColorAccessPath: 'itemStyle.color',
  44056. init: function (option) {
  44057. GraphSeries.superApply(this, 'init', arguments);
  44058. // Provide data for legend select
  44059. this.legendDataProvider = function () {
  44060. return this._categoriesData;
  44061. };
  44062. this._updateCategoriesData();
  44063. },
  44064. mergeOption: function (option) {
  44065. GraphSeries.superApply(this, 'mergeOption', arguments);
  44066. this._updateCategoriesData();
  44067. },
  44068. getFormattedLabel: function (dataIndex, status, dataType, dimIndex) {
  44069. var text = __WEBPACK_IMPORTED_MODULE_2__util_format__["a" /* default */].getFormattedLabel(this, dataIndex, status, dataType, dimIndex);
  44070. if (text == null) {
  44071. var data = this.getData();
  44072. var lastDim = data.dimensions[data.dimensions.length - 1];
  44073. text = data.get(lastDim, dataIndex);
  44074. }
  44075. return text;
  44076. },
  44077. getInitialData: function (option, ecModel) {
  44078. var edges = option.edges || option.links || [];
  44079. var nodes = option.data || option.nodes || [];
  44080. var self = this;
  44081. if (nodes && edges) {
  44082. return Object(__WEBPACK_IMPORTED_MODULE_1__createGraphFromNodeEdge__["a" /* default */])(nodes, edges, this, true, beforeLink).data;
  44083. }
  44084. function beforeLink(nodeData, edgeData) {
  44085. // Overwrite nodeData.getItemModel to
  44086. nodeData.wrapMethod('getItemModel', function (model) {
  44087. var categoriesModels = self._categoriesModels;
  44088. var categoryIdx = model.getShallow('category');
  44089. var categoryModel = categoriesModels[categoryIdx];
  44090. if (categoryModel) {
  44091. categoryModel.parentModel = model.parentModel;
  44092. model.parentModel = categoryModel;
  44093. }
  44094. return model;
  44095. });
  44096. var edgeLabelModel = self.getModel('edgeLabel');
  44097. // For option `edgeLabel` can be found by label.xxx.xxx on item mode.
  44098. var fakeSeriesModel = new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.Model(
  44099. { label: edgeLabelModel.option },
  44100. edgeLabelModel.parentModel,
  44101. ecModel
  44102. );
  44103. edgeData.wrapMethod('getItemModel', function (model) {
  44104. model.customizeGetParent(edgeGetParent);
  44105. return model;
  44106. });
  44107. function edgeGetParent(path) {
  44108. path = this.parsePath(path);
  44109. return (path && path[0] === 'label')
  44110. ? fakeSeriesModel
  44111. : this.parentModel;
  44112. }
  44113. }
  44114. },
  44115. /**
  44116. * @return {module:echarts/data/Graph}
  44117. */
  44118. getGraph: function () {
  44119. return this.getData().graph;
  44120. },
  44121. /**
  44122. * @return {module:echarts/data/List}
  44123. */
  44124. getEdgeData: function () {
  44125. return this.getGraph().edgeData;
  44126. },
  44127. /**
  44128. * @return {module:echarts/data/List}
  44129. */
  44130. getCategoriesData: function () {
  44131. return this._categoriesData;
  44132. },
  44133. /**
  44134. * @override
  44135. */
  44136. formatTooltip: function (dataIndex, multipleSeries, dataType) {
  44137. if (dataType === 'edge') {
  44138. var nodeData = this.getData();
  44139. var params = this.getDataParams(dataIndex, dataType);
  44140. var edge = nodeData.graph.getEdgeByIndex(dataIndex);
  44141. var sourceName = nodeData.getName(edge.node1.dataIndex);
  44142. var targetName = nodeData.getName(edge.node2.dataIndex);
  44143. var html = [];
  44144. sourceName != null && html.push(sourceName);
  44145. targetName != null && html.push(targetName);
  44146. html = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.format.encodeHTML(html.join(' > '));
  44147. if (params.value) {
  44148. html += ' : ' + __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.format.encodeHTML(params.value);
  44149. }
  44150. return html;
  44151. }
  44152. else { // dataType === 'node' or empty
  44153. return GraphSeries.superApply(this, 'formatTooltip', arguments);
  44154. }
  44155. },
  44156. _updateCategoriesData: function () {
  44157. var categories = (this.option.categories || []).map(function (category) {
  44158. // Data must has value
  44159. return category.value != null ? category : __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.util.extend({
  44160. value: 0
  44161. }, category);
  44162. });
  44163. var categoriesData = new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.List(['value'], this);
  44164. categoriesData.initData(categories);
  44165. this._categoriesData = categoriesData;
  44166. this._categoriesModels = categoriesData.mapArray(function (idx) {
  44167. return categoriesData.getItemModel(idx, true);
  44168. });
  44169. },
  44170. setView: function (payload) {
  44171. if (payload.zoom != null) {
  44172. this.option.zoom = payload.zoom;
  44173. }
  44174. if (payload.offset != null) {
  44175. this.option.offset = payload.offset;
  44176. }
  44177. },
  44178. setNodePosition: function (points) {
  44179. for (var i = 0; i < points.length / 2; i++) {
  44180. var x = points[i * 2];
  44181. var y = points[i * 2 + 1];
  44182. var opt = this.getData().getRawDataItem(i);
  44183. opt.x = x;
  44184. opt.y = y;
  44185. }
  44186. },
  44187. isAnimationEnabled: function () {
  44188. return GraphSeries.superCall(this, 'isAnimationEnabled')
  44189. // Not enable animation when do force layout
  44190. && !(this.get('layout') === 'force' && this.get('force.layoutAnimation'));
  44191. },
  44192. defaultOption: {
  44193. zlevel: 10,
  44194. z: 2,
  44195. legendHoverLink: true,
  44196. // Only support forceAtlas2
  44197. layout: 'forceAtlas2',
  44198. // Configuration of force directed layout
  44199. forceAtlas2: {
  44200. initLayout: null,
  44201. GPU: true,
  44202. steps: 1,
  44203. // barnesHutOptimize
  44204. // Maxp layout steps.
  44205. maxSteps: 1000,
  44206. repulsionByDegree: true,
  44207. linLogMode: false,
  44208. strongGravityMode: false,
  44209. gravity: 1.0,
  44210. // scaling: 1.0,
  44211. edgeWeightInfluence: 1.0,
  44212. // Edge weight range.
  44213. edgeWeight: [1, 4],
  44214. // Node weight range.
  44215. nodeWeight: [1, 4],
  44216. // jitterTolerence: 0.1,
  44217. preventOverlap: false,
  44218. gravityCenter: null
  44219. },
  44220. focusNodeAdjacency: true,
  44221. focusNodeAdjacencyOn: 'mouseover',
  44222. left: 'center',
  44223. top: 'center',
  44224. // right: null,
  44225. // bottom: null,
  44226. // width: '80%',
  44227. // height: '80%',
  44228. symbol: 'circle',
  44229. symbolSize: 5,
  44230. roam: false,
  44231. // Default on center of graph
  44232. center: null,
  44233. zoom: 1,
  44234. // categories: [],
  44235. // data: []
  44236. // Or
  44237. // nodes: []
  44238. //
  44239. // links: []
  44240. // Or
  44241. // edges: []
  44242. label: {
  44243. show: false,
  44244. formatter: '{b}',
  44245. position: 'right',
  44246. distance: 5,
  44247. textStyle: {
  44248. fontSize: 14
  44249. }
  44250. },
  44251. itemStyle: {},
  44252. lineStyle: {
  44253. color: '#aaa',
  44254. width: 1,
  44255. opacity: 0.5
  44256. },
  44257. emphasis: {
  44258. label: {
  44259. show: true
  44260. }
  44261. },
  44262. animation: false
  44263. }
  44264. });
  44265. /* unused harmony default export */ var _unused_webpack_default_export = (GraphSeries);
  44266. /***/
  44267. }),
  44268. /* 264 */
  44269. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  44270. "use strict";
  44271. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  44272. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  44273. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_data_Graph__ = __webpack_require__(265);
  44274. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_data_Graph___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_echarts_lib_data_Graph__);
  44275. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_echarts_lib_data_helper_linkList__ = __webpack_require__(267);
  44276. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_echarts_lib_data_helper_linkList___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_echarts_lib_data_helper_linkList__);
  44277. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__util_retrieve__ = __webpack_require__(2);
  44278. /* harmony default export */ __webpack_exports__["a"] = (function (nodes, edges, hostModel, directed, beforeLink) {
  44279. var graph = new __WEBPACK_IMPORTED_MODULE_1_echarts_lib_data_Graph___default.a(directed);
  44280. for (var i = 0; i < nodes.length; i++) {
  44281. graph.addNode(__WEBPACK_IMPORTED_MODULE_3__util_retrieve__["a" /* default */].firstNotNull(
  44282. // Id, name, dataIndex
  44283. nodes[i].id, nodes[i].name, i
  44284. ), i);
  44285. }
  44286. var linkNameList = [];
  44287. var validEdges = [];
  44288. var linkCount = 0;
  44289. for (var i = 0; i < edges.length; i++) {
  44290. var link = edges[i];
  44291. var source = link.source;
  44292. var target = link.target;
  44293. // addEdge may fail when source or target not exists
  44294. if (graph.addEdge(source, target, linkCount)) {
  44295. validEdges.push(link);
  44296. linkNameList.push(__WEBPACK_IMPORTED_MODULE_3__util_retrieve__["a" /* default */].firstNotNull(link.id, source + ' > ' + target));
  44297. linkCount++;
  44298. }
  44299. }
  44300. var nodeData;
  44301. // FIXME, support more coordinate systems.
  44302. var dimensionNames = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.helper.completeDimensions(
  44303. ['value'], nodes
  44304. );
  44305. nodeData = new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.List(dimensionNames, hostModel);
  44306. nodeData.initData(nodes);
  44307. var edgeData = new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.List(['value'], hostModel);
  44308. edgeData.initData(validEdges, linkNameList);
  44309. beforeLink && beforeLink(nodeData, edgeData);
  44310. __WEBPACK_IMPORTED_MODULE_2_echarts_lib_data_helper_linkList___default()({
  44311. mainData: nodeData,
  44312. struct: graph,
  44313. structAttr: 'graph',
  44314. datas: { node: nodeData, edge: edgeData },
  44315. datasAttr: { node: 'data', edge: 'edgeData' }
  44316. });
  44317. // Update dataIndex of nodes and edges because invalid edge may be removed
  44318. graph.update();
  44319. return graph;
  44320. });;
  44321. /***/
  44322. }),
  44323. /* 265 */
  44324. /***/ (function (module, exports, __webpack_require__) {
  44325. var _config = __webpack_require__(104);
  44326. var __DEV__ = _config.__DEV__;
  44327. var zrUtil = __webpack_require__(13);
  44328. var _clazz = __webpack_require__(266);
  44329. var enableClassCheck = _clazz.enableClassCheck;
  44330. /*
  44331. * Licensed to the Apache Software Foundation (ASF) under one
  44332. * or more contributor license agreements. See the NOTICE file
  44333. * distributed with this work for additional information
  44334. * regarding copyright ownership. The ASF licenses this file
  44335. * to you under the Apache License, Version 2.0 (the
  44336. * "License"); you may not use this file except in compliance
  44337. * with the License. You may obtain a copy of the License at
  44338. *
  44339. * http://www.apache.org/licenses/LICENSE-2.0
  44340. *
  44341. * Unless required by applicable law or agreed to in writing,
  44342. * software distributed under the License is distributed on an
  44343. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  44344. * KIND, either express or implied. See the License for the
  44345. * specific language governing permissions and limitations
  44346. * under the License.
  44347. */
  44348. /**
  44349. * Graph data structure
  44350. *
  44351. * @module echarts/data/Graph
  44352. * @author Yi Shen(https://www.github.com/pissang)
  44353. */
  44354. // id may be function name of Object, add a prefix to avoid this problem.
  44355. function generateNodeKey(id) {
  44356. return '_EC_' + id;
  44357. }
  44358. /**
  44359. * @alias module:echarts/data/Graph
  44360. * @constructor
  44361. * @param {boolean} directed
  44362. */
  44363. var Graph = function (directed) {
  44364. /**
  44365. * 是否是有向图
  44366. * @type {boolean}
  44367. * @private
  44368. */
  44369. this._directed = directed || false;
  44370. /**
  44371. * @type {Array.<module:echarts/data/Graph.Node>}
  44372. * @readOnly
  44373. */
  44374. this.nodes = [];
  44375. /**
  44376. * @type {Array.<module:echarts/data/Graph.Edge>}
  44377. * @readOnly
  44378. */
  44379. this.edges = [];
  44380. /**
  44381. * @type {Object.<string, module:echarts/data/Graph.Node>}
  44382. * @private
  44383. */
  44384. this._nodesMap = {};
  44385. /**
  44386. * @type {Object.<string, module:echarts/data/Graph.Edge>}
  44387. * @private
  44388. */
  44389. this._edgesMap = {};
  44390. /**
  44391. * @type {module:echarts/data/List}
  44392. * @readOnly
  44393. */
  44394. this.data;
  44395. /**
  44396. * @type {module:echarts/data/List}
  44397. * @readOnly
  44398. */
  44399. this.edgeData;
  44400. };
  44401. var graphProto = Graph.prototype;
  44402. /**
  44403. * @type {string}
  44404. */
  44405. graphProto.type = 'graph';
  44406. /**
  44407. * If is directed graph
  44408. * @return {boolean}
  44409. */
  44410. graphProto.isDirected = function () {
  44411. return this._directed;
  44412. };
  44413. /**
  44414. * Add a new node
  44415. * @param {string} id
  44416. * @param {number} [dataIndex]
  44417. */
  44418. graphProto.addNode = function (id, dataIndex) {
  44419. id = id || '' + dataIndex;
  44420. var nodesMap = this._nodesMap;
  44421. if (nodesMap[generateNodeKey(id)]) {
  44422. return;
  44423. }
  44424. var node = new Node(id, dataIndex);
  44425. node.hostGraph = this;
  44426. this.nodes.push(node);
  44427. nodesMap[generateNodeKey(id)] = node;
  44428. return node;
  44429. };
  44430. /**
  44431. * Get node by data index
  44432. * @param {number} dataIndex
  44433. * @return {module:echarts/data/Graph~Node}
  44434. */
  44435. graphProto.getNodeByIndex = function (dataIndex) {
  44436. var rawIdx = this.data.getRawIndex(dataIndex);
  44437. return this.nodes[rawIdx];
  44438. };
  44439. /**
  44440. * Get node by id
  44441. * @param {string} id
  44442. * @return {module:echarts/data/Graph.Node}
  44443. */
  44444. graphProto.getNodeById = function (id) {
  44445. return this._nodesMap[generateNodeKey(id)];
  44446. };
  44447. /**
  44448. * Add a new edge
  44449. * @param {number|string|module:echarts/data/Graph.Node} n1
  44450. * @param {number|string|module:echarts/data/Graph.Node} n2
  44451. * @param {number} [dataIndex=-1]
  44452. * @return {module:echarts/data/Graph.Edge}
  44453. */
  44454. graphProto.addEdge = function (n1, n2, dataIndex) {
  44455. var nodesMap = this._nodesMap;
  44456. var edgesMap = this._edgesMap; // PNEDING
  44457. if (typeof n1 === 'number') {
  44458. n1 = this.nodes[n1];
  44459. }
  44460. if (typeof n2 === 'number') {
  44461. n2 = this.nodes[n2];
  44462. }
  44463. if (!Node.isInstance(n1)) {
  44464. n1 = nodesMap[generateNodeKey(n1)];
  44465. }
  44466. if (!Node.isInstance(n2)) {
  44467. n2 = nodesMap[generateNodeKey(n2)];
  44468. }
  44469. if (!n1 || !n2) {
  44470. return;
  44471. }
  44472. var key = n1.id + '-' + n2.id; // PENDING
  44473. if (edgesMap[key]) {
  44474. return;
  44475. }
  44476. var edge = new Edge(n1, n2, dataIndex);
  44477. edge.hostGraph = this;
  44478. if (this._directed) {
  44479. n1.outEdges.push(edge);
  44480. n2.inEdges.push(edge);
  44481. }
  44482. n1.edges.push(edge);
  44483. if (n1 !== n2) {
  44484. n2.edges.push(edge);
  44485. }
  44486. this.edges.push(edge);
  44487. edgesMap[key] = edge;
  44488. return edge;
  44489. };
  44490. /**
  44491. * Get edge by data index
  44492. * @param {number} dataIndex
  44493. * @return {module:echarts/data/Graph~Node}
  44494. */
  44495. graphProto.getEdgeByIndex = function (dataIndex) {
  44496. var rawIdx = this.edgeData.getRawIndex(dataIndex);
  44497. return this.edges[rawIdx];
  44498. };
  44499. /**
  44500. * Get edge by two linked nodes
  44501. * @param {module:echarts/data/Graph.Node|string} n1
  44502. * @param {module:echarts/data/Graph.Node|string} n2
  44503. * @return {module:echarts/data/Graph.Edge}
  44504. */
  44505. graphProto.getEdge = function (n1, n2) {
  44506. if (Node.isInstance(n1)) {
  44507. n1 = n1.id;
  44508. }
  44509. if (Node.isInstance(n2)) {
  44510. n2 = n2.id;
  44511. }
  44512. var edgesMap = this._edgesMap;
  44513. if (this._directed) {
  44514. return edgesMap[n1 + '-' + n2];
  44515. } else {
  44516. return edgesMap[n1 + '-' + n2] || edgesMap[n2 + '-' + n1];
  44517. }
  44518. };
  44519. /**
  44520. * Iterate all nodes
  44521. * @param {Function} cb
  44522. * @param {*} [context]
  44523. */
  44524. graphProto.eachNode = function (cb, context) {
  44525. var nodes = this.nodes;
  44526. var len = nodes.length;
  44527. for (var i = 0; i < len; i++) {
  44528. if (nodes[i].dataIndex >= 0) {
  44529. cb.call(context, nodes[i], i);
  44530. }
  44531. }
  44532. };
  44533. /**
  44534. * Iterate all edges
  44535. * @param {Function} cb
  44536. * @param {*} [context]
  44537. */
  44538. graphProto.eachEdge = function (cb, context) {
  44539. var edges = this.edges;
  44540. var len = edges.length;
  44541. for (var i = 0; i < len; i++) {
  44542. if (edges[i].dataIndex >= 0 && edges[i].node1.dataIndex >= 0 && edges[i].node2.dataIndex >= 0) {
  44543. cb.call(context, edges[i], i);
  44544. }
  44545. }
  44546. };
  44547. /**
  44548. * Breadth first traverse
  44549. * @param {Function} cb
  44550. * @param {module:echarts/data/Graph.Node} startNode
  44551. * @param {string} [direction='none'] 'none'|'in'|'out'
  44552. * @param {*} [context]
  44553. */
  44554. graphProto.breadthFirstTraverse = function (cb, startNode, direction, context) {
  44555. if (!Node.isInstance(startNode)) {
  44556. startNode = this._nodesMap[generateNodeKey(startNode)];
  44557. }
  44558. if (!startNode) {
  44559. return;
  44560. }
  44561. var edgeType = direction === 'out' ? 'outEdges' : direction === 'in' ? 'inEdges' : 'edges';
  44562. for (var i = 0; i < this.nodes.length; i++) {
  44563. this.nodes[i].__visited = false;
  44564. }
  44565. if (cb.call(context, startNode, null)) {
  44566. return;
  44567. }
  44568. var queue = [startNode];
  44569. while (queue.length) {
  44570. var currentNode = queue.shift();
  44571. var edges = currentNode[edgeType];
  44572. for (var i = 0; i < edges.length; i++) {
  44573. var e = edges[i];
  44574. var otherNode = e.node1 === currentNode ? e.node2 : e.node1;
  44575. if (!otherNode.__visited) {
  44576. if (cb.call(context, otherNode, currentNode)) {
  44577. // Stop traversing
  44578. return;
  44579. }
  44580. queue.push(otherNode);
  44581. otherNode.__visited = true;
  44582. }
  44583. }
  44584. }
  44585. }; // TODO
  44586. // graphProto.depthFirstTraverse = function (
  44587. // cb, startNode, direction, context
  44588. // ) {
  44589. // };
  44590. // Filter update
  44591. graphProto.update = function () {
  44592. var data = this.data;
  44593. var edgeData = this.edgeData;
  44594. var nodes = this.nodes;
  44595. var edges = this.edges;
  44596. for (var i = 0, len = nodes.length; i < len; i++) {
  44597. nodes[i].dataIndex = -1;
  44598. }
  44599. for (var i = 0, len = data.count(); i < len; i++) {
  44600. nodes[data.getRawIndex(i)].dataIndex = i;
  44601. }
  44602. edgeData.filterSelf(function (idx) {
  44603. var edge = edges[edgeData.getRawIndex(idx)];
  44604. return edge.node1.dataIndex >= 0 && edge.node2.dataIndex >= 0;
  44605. }); // Update edge
  44606. for (var i = 0, len = edges.length; i < len; i++) {
  44607. edges[i].dataIndex = -1;
  44608. }
  44609. for (var i = 0, len = edgeData.count(); i < len; i++) {
  44610. edges[edgeData.getRawIndex(i)].dataIndex = i;
  44611. }
  44612. };
  44613. /**
  44614. * @return {module:echarts/data/Graph}
  44615. */
  44616. graphProto.clone = function () {
  44617. var graph = new Graph(this._directed);
  44618. var nodes = this.nodes;
  44619. var edges = this.edges;
  44620. for (var i = 0; i < nodes.length; i++) {
  44621. graph.addNode(nodes[i].id, nodes[i].dataIndex);
  44622. }
  44623. for (var i = 0; i < edges.length; i++) {
  44624. var e = edges[i];
  44625. graph.addEdge(e.node1.id, e.node2.id, e.dataIndex);
  44626. }
  44627. return graph;
  44628. };
  44629. /**
  44630. * @alias module:echarts/data/Graph.Node
  44631. */
  44632. function Node(id, dataIndex) {
  44633. /**
  44634. * @type {string}
  44635. */
  44636. this.id = id == null ? '' : id;
  44637. /**
  44638. * @type {Array.<module:echarts/data/Graph.Edge>}
  44639. */
  44640. this.inEdges = [];
  44641. /**
  44642. * @type {Array.<module:echarts/data/Graph.Edge>}
  44643. */
  44644. this.outEdges = [];
  44645. /**
  44646. * @type {Array.<module:echarts/data/Graph.Edge>}
  44647. */
  44648. this.edges = [];
  44649. /**
  44650. * @type {module:echarts/data/Graph}
  44651. */
  44652. this.hostGraph;
  44653. /**
  44654. * @type {number}
  44655. */
  44656. this.dataIndex = dataIndex == null ? -1 : dataIndex;
  44657. }
  44658. Node.prototype = {
  44659. constructor: Node,
  44660. /**
  44661. * @return {number}
  44662. */
  44663. degree: function () {
  44664. return this.edges.length;
  44665. },
  44666. /**
  44667. * @return {number}
  44668. */
  44669. inDegree: function () {
  44670. return this.inEdges.length;
  44671. },
  44672. /**
  44673. * @return {number}
  44674. */
  44675. outDegree: function () {
  44676. return this.outEdges.length;
  44677. },
  44678. /**
  44679. * @param {string} [path]
  44680. * @return {module:echarts/model/Model}
  44681. */
  44682. getModel: function (path) {
  44683. if (this.dataIndex < 0) {
  44684. return;
  44685. }
  44686. var graph = this.hostGraph;
  44687. var itemModel = graph.data.getItemModel(this.dataIndex);
  44688. return itemModel.getModel(path);
  44689. }
  44690. };
  44691. /**
  44692. * 图边
  44693. * @alias module:echarts/data/Graph.Edge
  44694. * @param {module:echarts/data/Graph.Node} n1
  44695. * @param {module:echarts/data/Graph.Node} n2
  44696. * @param {number} [dataIndex=-1]
  44697. */
  44698. function Edge(n1, n2, dataIndex) {
  44699. /**
  44700. * 节点1,如果是有向图则为源节点
  44701. * @type {module:echarts/data/Graph.Node}
  44702. */
  44703. this.node1 = n1;
  44704. /**
  44705. * 节点2ï¼Œå¦‚æžœæ˜¯æœ‰å‘å›¾åˆ™ä¸ºç›®æ ‡èŠ‚ç‚¹
  44706. * @type {module:echarts/data/Graph.Node}
  44707. */
  44708. this.node2 = n2;
  44709. this.dataIndex = dataIndex == null ? -1 : dataIndex;
  44710. }
  44711. /**
  44712. * @param {string} [path]
  44713. * @return {module:echarts/model/Model}
  44714. */
  44715. Edge.prototype.getModel = function (path) {
  44716. if (this.dataIndex < 0) {
  44717. return;
  44718. }
  44719. var graph = this.hostGraph;
  44720. var itemModel = graph.edgeData.getItemModel(this.dataIndex);
  44721. return itemModel.getModel(path);
  44722. };
  44723. var createGraphDataProxyMixin = function (hostName, dataName) {
  44724. return {
  44725. /**
  44726. * @param {string=} [dimension='value'] Default 'value'. can be 'a', 'b', 'c', 'd', 'e'.
  44727. * @return {number}
  44728. */
  44729. getValue: function (dimension) {
  44730. var data = this[hostName][dataName];
  44731. return data.get(data.getDimension(dimension || 'value'), this.dataIndex);
  44732. },
  44733. /**
  44734. * @param {Object|string} key
  44735. * @param {*} [value]
  44736. */
  44737. setVisual: function (key, value) {
  44738. this.dataIndex >= 0 && this[hostName][dataName].setItemVisual(this.dataIndex, key, value);
  44739. },
  44740. /**
  44741. * @param {string} key
  44742. * @return {boolean}
  44743. */
  44744. getVisual: function (key, ignoreParent) {
  44745. return this[hostName][dataName].getItemVisual(this.dataIndex, key, ignoreParent);
  44746. },
  44747. /**
  44748. * @param {Object} layout
  44749. * @return {boolean} [merge=false]
  44750. */
  44751. setLayout: function (layout, merge) {
  44752. this.dataIndex >= 0 && this[hostName][dataName].setItemLayout(this.dataIndex, layout, merge);
  44753. },
  44754. /**
  44755. * @return {Object}
  44756. */
  44757. getLayout: function () {
  44758. return this[hostName][dataName].getItemLayout(this.dataIndex);
  44759. },
  44760. /**
  44761. * @return {module:zrender/Element}
  44762. */
  44763. getGraphicEl: function () {
  44764. return this[hostName][dataName].getItemGraphicEl(this.dataIndex);
  44765. },
  44766. /**
  44767. * @return {number}
  44768. */
  44769. getRawIndex: function () {
  44770. return this[hostName][dataName].getRawIndex(this.dataIndex);
  44771. }
  44772. };
  44773. };
  44774. zrUtil.mixin(Node, createGraphDataProxyMixin('hostGraph', 'data'));
  44775. zrUtil.mixin(Edge, createGraphDataProxyMixin('hostGraph', 'edgeData'));
  44776. Graph.Node = Node;
  44777. Graph.Edge = Edge;
  44778. enableClassCheck(Node);
  44779. enableClassCheck(Edge);
  44780. var _default = Graph;
  44781. module.exports = _default;
  44782. /***/
  44783. }),
  44784. /* 266 */
  44785. /***/ (function (module, exports, __webpack_require__) {
  44786. var _config = __webpack_require__(104);
  44787. var __DEV__ = _config.__DEV__;
  44788. var zrUtil = __webpack_require__(13);
  44789. /*
  44790. * Licensed to the Apache Software Foundation (ASF) under one
  44791. * or more contributor license agreements. See the NOTICE file
  44792. * distributed with this work for additional information
  44793. * regarding copyright ownership. The ASF licenses this file
  44794. * to you under the Apache License, Version 2.0 (the
  44795. * "License"); you may not use this file except in compliance
  44796. * with the License. You may obtain a copy of the License at
  44797. *
  44798. * http://www.apache.org/licenses/LICENSE-2.0
  44799. *
  44800. * Unless required by applicable law or agreed to in writing,
  44801. * software distributed under the License is distributed on an
  44802. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  44803. * KIND, either express or implied. See the License for the
  44804. * specific language governing permissions and limitations
  44805. * under the License.
  44806. */
  44807. var TYPE_DELIMITER = '.';
  44808. var IS_CONTAINER = '___EC__COMPONENT__CONTAINER___';
  44809. /**
  44810. * Notice, parseClassType('') should returns {main: '', sub: ''}
  44811. * @public
  44812. */
  44813. function parseClassType(componentType) {
  44814. var ret = {
  44815. main: '',
  44816. sub: ''
  44817. };
  44818. if (componentType) {
  44819. componentType = componentType.split(TYPE_DELIMITER);
  44820. ret.main = componentType[0] || '';
  44821. ret.sub = componentType[1] || '';
  44822. }
  44823. return ret;
  44824. }
  44825. /**
  44826. * @public
  44827. */
  44828. function checkClassType(componentType) {
  44829. zrUtil.assert(/^[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)?$/.test(componentType), 'componentType "' + componentType + '" illegal');
  44830. }
  44831. /**
  44832. * @public
  44833. */
  44834. function enableClassExtend(RootClass, mandatoryMethods) {
  44835. RootClass.$constructor = RootClass;
  44836. RootClass.extend = function (proto) {
  44837. var superClass = this;
  44838. var ExtendedClass = function () {
  44839. if (!proto.$constructor) {
  44840. superClass.apply(this, arguments);
  44841. } else {
  44842. proto.$constructor.apply(this, arguments);
  44843. }
  44844. };
  44845. zrUtil.extend(ExtendedClass.prototype, proto);
  44846. ExtendedClass.extend = this.extend;
  44847. ExtendedClass.superCall = superCall;
  44848. ExtendedClass.superApply = superApply;
  44849. zrUtil.inherits(ExtendedClass, this);
  44850. ExtendedClass.superClass = superClass;
  44851. return ExtendedClass;
  44852. };
  44853. }
  44854. var classBase = 0;
  44855. /**
  44856. * Can not use instanceof, consider different scope by
  44857. * cross domain or es module import in ec extensions.
  44858. * Mount a method "isInstance()" to Clz.
  44859. */
  44860. function enableClassCheck(Clz) {
  44861. var classAttr = ['__\0is_clz', classBase++, Math.random().toFixed(3)].join('_');
  44862. Clz.prototype[classAttr] = true;
  44863. Clz.isInstance = function (obj) {
  44864. return !!(obj && obj[classAttr]);
  44865. };
  44866. } // superCall should have class info, which can not be fetch from 'this'.
  44867. // Consider this case:
  44868. // class A has method f,
  44869. // class B inherits class A, overrides method f, f call superApply('f'),
  44870. // class C inherits class B, do not overrides method f,
  44871. // then when method of class C is called, dead loop occured.
  44872. function superCall(context, methodName) {
  44873. var args = zrUtil.slice(arguments, 2);
  44874. return this.superClass.prototype[methodName].apply(context, args);
  44875. }
  44876. function superApply(context, methodName, args) {
  44877. return this.superClass.prototype[methodName].apply(context, args);
  44878. }
  44879. /**
  44880. * @param {Object} entity
  44881. * @param {Object} options
  44882. * @param {boolean} [options.registerWhenExtend]
  44883. * @public
  44884. */
  44885. function enableClassManagement(entity, options) {
  44886. options = options || {};
  44887. /**
  44888. * Component model classes
  44889. * key: componentType,
  44890. * value:
  44891. * componentClass, when componentType is 'xxx'
  44892. * or Object.<subKey, componentClass>, when componentType is 'xxx.yy'
  44893. * @type {Object}
  44894. */
  44895. var storage = {};
  44896. entity.registerClass = function (Clazz, componentType) {
  44897. if (componentType) {
  44898. checkClassType(componentType);
  44899. componentType = parseClassType(componentType);
  44900. if (!componentType.sub) {
  44901. storage[componentType.main] = Clazz;
  44902. } else if (componentType.sub !== IS_CONTAINER) {
  44903. var container = makeContainer(componentType);
  44904. container[componentType.sub] = Clazz;
  44905. }
  44906. }
  44907. return Clazz;
  44908. };
  44909. entity.getClass = function (componentMainType, subType, throwWhenNotFound) {
  44910. var Clazz = storage[componentMainType];
  44911. if (Clazz && Clazz[IS_CONTAINER]) {
  44912. Clazz = subType ? Clazz[subType] : null;
  44913. }
  44914. if (throwWhenNotFound && !Clazz) {
  44915. throw new Error(!subType ? componentMainType + '.' + 'type should be specified.' : 'Component ' + componentMainType + '.' + (subType || '') + ' not exists. Load it first.');
  44916. }
  44917. return Clazz;
  44918. };
  44919. entity.getClassesByMainType = function (componentType) {
  44920. componentType = parseClassType(componentType);
  44921. var result = [];
  44922. var obj = storage[componentType.main];
  44923. if (obj && obj[IS_CONTAINER]) {
  44924. zrUtil.each(obj, function (o, type) {
  44925. type !== IS_CONTAINER && result.push(o);
  44926. });
  44927. } else {
  44928. result.push(obj);
  44929. }
  44930. return result;
  44931. };
  44932. entity.hasClass = function (componentType) {
  44933. // Just consider componentType.main.
  44934. componentType = parseClassType(componentType);
  44935. return !!storage[componentType.main];
  44936. };
  44937. /**
  44938. * @return {Array.<string>} Like ['aa', 'bb'], but can not be ['aa.xx']
  44939. */
  44940. entity.getAllClassMainTypes = function () {
  44941. var types = [];
  44942. zrUtil.each(storage, function (obj, type) {
  44943. types.push(type);
  44944. });
  44945. return types;
  44946. };
  44947. /**
  44948. * If a main type is container and has sub types
  44949. * @param {string} mainType
  44950. * @return {boolean}
  44951. */
  44952. entity.hasSubTypes = function (componentType) {
  44953. componentType = parseClassType(componentType);
  44954. var obj = storage[componentType.main];
  44955. return obj && obj[IS_CONTAINER];
  44956. };
  44957. entity.parseClassType = parseClassType;
  44958. function makeContainer(componentType) {
  44959. var container = storage[componentType.main];
  44960. if (!container || !container[IS_CONTAINER]) {
  44961. container = storage[componentType.main] = {};
  44962. container[IS_CONTAINER] = true;
  44963. }
  44964. return container;
  44965. }
  44966. if (options.registerWhenExtend) {
  44967. var originalExtend = entity.extend;
  44968. if (originalExtend) {
  44969. entity.extend = function (proto) {
  44970. var ExtendedClass = originalExtend.call(this, proto);
  44971. return entity.registerClass(ExtendedClass, proto.type);
  44972. };
  44973. }
  44974. }
  44975. return entity;
  44976. }
  44977. /**
  44978. * @param {string|Array.<string>} properties
  44979. */
  44980. function setReadOnly(obj, properties) {// FIXME It seems broken in IE8 simulation of IE11
  44981. // if (!zrUtil.isArray(properties)) {
  44982. // properties = properties != null ? [properties] : [];
  44983. // }
  44984. // zrUtil.each(properties, function (prop) {
  44985. // var value = obj[prop];
  44986. // Object.defineProperty
  44987. // && Object.defineProperty(obj, prop, {
  44988. // value: value, writable: false
  44989. // });
  44990. // zrUtil.isArray(obj[prop])
  44991. // && Object.freeze
  44992. // && Object.freeze(obj[prop]);
  44993. // });
  44994. }
  44995. exports.parseClassType = parseClassType;
  44996. exports.enableClassExtend = enableClassExtend;
  44997. exports.enableClassCheck = enableClassCheck;
  44998. exports.enableClassManagement = enableClassManagement;
  44999. exports.setReadOnly = setReadOnly;
  45000. /***/
  45001. }),
  45002. /* 267 */
  45003. /***/ (function (module, exports, __webpack_require__) {
  45004. var zrUtil = __webpack_require__(13);
  45005. /*
  45006. * Licensed to the Apache Software Foundation (ASF) under one
  45007. * or more contributor license agreements. See the NOTICE file
  45008. * distributed with this work for additional information
  45009. * regarding copyright ownership. The ASF licenses this file
  45010. * to you under the Apache License, Version 2.0 (the
  45011. * "License"); you may not use this file except in compliance
  45012. * with the License. You may obtain a copy of the License at
  45013. *
  45014. * http://www.apache.org/licenses/LICENSE-2.0
  45015. *
  45016. * Unless required by applicable law or agreed to in writing,
  45017. * software distributed under the License is distributed on an
  45018. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  45019. * KIND, either express or implied. See the License for the
  45020. * specific language governing permissions and limitations
  45021. * under the License.
  45022. */
  45023. /**
  45024. * Link lists and struct (graph or tree)
  45025. */
  45026. var each = zrUtil.each;
  45027. var DATAS = '\0__link_datas';
  45028. var MAIN_DATA = '\0__link_mainData'; // Caution:
  45029. // In most case, either list or its shallow clones (see list.cloneShallow)
  45030. // is active in echarts process. So considering heap memory consumption,
  45031. // we do not clone tree or graph, but share them among list and its shallow clones.
  45032. // But in some rare case, we have to keep old list (like do animation in chart). So
  45033. // please take care that both the old list and the new list share the same tree/graph.
  45034. /**
  45035. * @param {Object} opt
  45036. * @param {module:echarts/data/List} opt.mainData
  45037. * @param {Object} [opt.struct] For example, instance of Graph or Tree.
  45038. * @param {string} [opt.structAttr] designation: list[structAttr] = struct;
  45039. * @param {Object} [opt.datas] {dataType: data},
  45040. * like: {node: nodeList, edge: edgeList}.
  45041. * Should contain mainData.
  45042. * @param {Object} [opt.datasAttr] {dataType: attr},
  45043. * designation: struct[datasAttr[dataType]] = list;
  45044. */
  45045. function linkList(opt) {
  45046. var mainData = opt.mainData;
  45047. var datas = opt.datas;
  45048. if (!datas) {
  45049. datas = {
  45050. main: mainData
  45051. };
  45052. opt.datasAttr = {
  45053. main: 'data'
  45054. };
  45055. }
  45056. opt.datas = opt.mainData = null;
  45057. linkAll(mainData, datas, opt); // Porxy data original methods.
  45058. each(datas, function (data) {
  45059. each(mainData.TRANSFERABLE_METHODS, function (methodName) {
  45060. data.wrapMethod(methodName, zrUtil.curry(transferInjection, opt));
  45061. });
  45062. }); // Beyond transfer, additional features should be added to `cloneShallow`.
  45063. mainData.wrapMethod('cloneShallow', zrUtil.curry(cloneShallowInjection, opt)); // Only mainData trigger change, because struct.update may trigger
  45064. // another changable methods, which may bring about dead lock.
  45065. each(mainData.CHANGABLE_METHODS, function (methodName) {
  45066. mainData.wrapMethod(methodName, zrUtil.curry(changeInjection, opt));
  45067. }); // Make sure datas contains mainData.
  45068. zrUtil.assert(datas[mainData.dataType] === mainData);
  45069. }
  45070. function transferInjection(opt, res) {
  45071. if (isMainData(this)) {
  45072. // Transfer datas to new main data.
  45073. var datas = zrUtil.extend({}, this[DATAS]);
  45074. datas[this.dataType] = res;
  45075. linkAll(res, datas, opt);
  45076. } else {
  45077. // Modify the reference in main data to point newData.
  45078. linkSingle(res, this.dataType, this[MAIN_DATA], opt);
  45079. }
  45080. return res;
  45081. }
  45082. function changeInjection(opt, res) {
  45083. opt.struct && opt.struct.update(this);
  45084. return res;
  45085. }
  45086. function cloneShallowInjection(opt, res) {
  45087. // cloneShallow, which brings about some fragilities, may be inappropriate
  45088. // to be exposed as an API. So for implementation simplicity we can make
  45089. // the restriction that cloneShallow of not-mainData should not be invoked
  45090. // outside, but only be invoked here.
  45091. each(res[DATAS], function (data, dataType) {
  45092. data !== res && linkSingle(data.cloneShallow(), dataType, res, opt);
  45093. });
  45094. return res;
  45095. }
  45096. /**
  45097. * Supplement method to List.
  45098. *
  45099. * @public
  45100. * @param {string} [dataType] If not specified, return mainData.
  45101. * @return {module:echarts/data/List}
  45102. */
  45103. function getLinkedData(dataType) {
  45104. var mainData = this[MAIN_DATA];
  45105. return dataType == null || mainData == null ? mainData : mainData[DATAS][dataType];
  45106. }
  45107. function isMainData(data) {
  45108. return data[MAIN_DATA] === data;
  45109. }
  45110. function linkAll(mainData, datas, opt) {
  45111. mainData[DATAS] = {};
  45112. each(datas, function (data, dataType) {
  45113. linkSingle(data, dataType, mainData, opt);
  45114. });
  45115. }
  45116. function linkSingle(data, dataType, mainData, opt) {
  45117. mainData[DATAS][dataType] = data;
  45118. data[MAIN_DATA] = mainData;
  45119. data.dataType = dataType;
  45120. if (opt.struct) {
  45121. data[opt.structAttr] = opt.struct;
  45122. opt.struct[opt.datasAttr[dataType]] = data;
  45123. } // Supplement method.
  45124. data.getLinkedData = getLinkedData;
  45125. }
  45126. var _default = linkList;
  45127. module.exports = _default;
  45128. /***/
  45129. }),
  45130. /* 268 */
  45131. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  45132. "use strict";
  45133. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  45134. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  45135. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_util_layout__ = __webpack_require__(47);
  45136. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_util_layout___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_echarts_lib_util_layout__);
  45137. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__ = __webpack_require__(1);
  45138. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__core_ViewGL__ = __webpack_require__(22);
  45139. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__util_geometry_Lines2D__ = __webpack_require__(105);
  45140. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__util_retrieve__ = __webpack_require__(2);
  45141. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__ForceAtlas2GPU__ = __webpack_require__(269);
  45142. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__ForceAtlas2__ = __webpack_require__(271);
  45143. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8_zrender_lib_animation_requestAnimationFrame__ = __webpack_require__(80);
  45144. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8_zrender_lib_animation_requestAnimationFrame___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_8_zrender_lib_animation_requestAnimationFrame__);
  45145. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_9_claygl_src_dep_glmatrix__ = __webpack_require__(6);
  45146. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_10__util_Roam2DControl__ = __webpack_require__(273);
  45147. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_11__common_PointsBuilder__ = __webpack_require__(67);
  45148. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_12__util_shader_lines2D_glsl_js__ = __webpack_require__(274);
  45149. var vec2 = __WEBPACK_IMPORTED_MODULE_9_claygl_src_dep_glmatrix__["a" /* default */].vec2;
  45150. __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__["a" /* default */].Shader.import(__WEBPACK_IMPORTED_MODULE_12__util_shader_lines2D_glsl_js__["a" /* default */]);
  45151. var globalLayoutId = 1;
  45152. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendChartView({
  45153. type: 'graphGL',
  45154. __ecgl__: true,
  45155. init: function (ecModel, api) {
  45156. this.groupGL = new __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__["a" /* default */].Node();
  45157. this.viewGL = new __WEBPACK_IMPORTED_MODULE_3__core_ViewGL__["a" /* default */]('orthographic');
  45158. this.viewGL.camera.left = this.viewGL.camera.right = 0;
  45159. this.viewGL.add(this.groupGL);
  45160. this._pointsBuilder = new __WEBPACK_IMPORTED_MODULE_11__common_PointsBuilder__["a" /* default */](true, api);
  45161. // Mesh used during force directed layout.
  45162. this._forceEdgesMesh = new __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__["a" /* default */].Mesh({
  45163. material: new __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__["a" /* default */].Material({
  45164. shader: __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__["a" /* default */].createShader('ecgl.forceAtlas2.edges'),
  45165. transparent: true,
  45166. depthMask: false,
  45167. depthTest: false
  45168. }),
  45169. $ignorePicking: true,
  45170. geometry: new __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__["a" /* default */].Geometry({
  45171. attributes: {
  45172. node: new __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__["a" /* default */].Geometry.Attribute('node', 'float', 2),
  45173. color: new __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__["a" /* default */].Geometry.Attribute('color', 'float', 4, 'COLOR')
  45174. },
  45175. dynamic: true,
  45176. mainAttribute: 'node'
  45177. }),
  45178. renderOrder: -1,
  45179. mode: __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__["a" /* default */].Mesh.LINES
  45180. });
  45181. // Mesh used after force directed layout.
  45182. this._edgesMesh = new __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__["a" /* default */].Mesh({
  45183. material: new __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__["a" /* default */].Material({
  45184. shader: __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__["a" /* default */].createShader('ecgl.meshLines2D'),
  45185. transparent: true,
  45186. depthMask: false,
  45187. depthTest: false
  45188. }),
  45189. $ignorePicking: true,
  45190. geometry: new __WEBPACK_IMPORTED_MODULE_4__util_geometry_Lines2D__["a" /* default */]({
  45191. useNativeLine: false,
  45192. dynamic: true
  45193. }),
  45194. renderOrder: -1,
  45195. culling: false
  45196. });
  45197. this._layoutId = 0;
  45198. this._control = new __WEBPACK_IMPORTED_MODULE_10__util_Roam2DControl__["a" /* default */]({
  45199. zr: api.getZr(),
  45200. viewGL: this.viewGL
  45201. });
  45202. this._control.setTarget(this.groupGL);
  45203. this._control.init();
  45204. this._clickHandler = this._clickHandler.bind(this);
  45205. },
  45206. render: function (seriesModel, ecModel, api) {
  45207. this.groupGL.add(this._pointsBuilder.rootNode);
  45208. this._model = seriesModel;
  45209. this._api = api;
  45210. this._initLayout(seriesModel, ecModel, api);
  45211. this._pointsBuilder.update(seriesModel, ecModel, api);
  45212. if (!(this._forceLayoutInstance instanceof __WEBPACK_IMPORTED_MODULE_6__ForceAtlas2GPU__["a" /* default */])) {
  45213. this.groupGL.remove(this._forceEdgesMesh);
  45214. }
  45215. this._updateCamera(seriesModel, api);
  45216. this._control.off('update');
  45217. this._control.on('update', function () {
  45218. api.dispatchAction({
  45219. type: 'graphGLRoam',
  45220. seriesId: seriesModel.id,
  45221. zoom: this._control.getZoom(),
  45222. offset: this._control.getOffset()
  45223. });
  45224. this._pointsBuilder.updateView(this.viewGL.camera);
  45225. }, this);
  45226. this._control.setZoom(__WEBPACK_IMPORTED_MODULE_5__util_retrieve__["a" /* default */].firstNotNull(seriesModel.get('zoom'), 1));
  45227. this._control.setOffset(seriesModel.get('offset') || [0, 0]);
  45228. var mesh = this._pointsBuilder.getPointsMesh();
  45229. mesh.off('mousemove', this._mousemoveHandler);
  45230. mesh.off('mouseout', this._mouseOutHandler, this);
  45231. api.getZr().off('click', this._clickHandler);
  45232. this._pointsBuilder.highlightOnMouseover = true;
  45233. if (seriesModel.get('focusNodeAdjacency')) {
  45234. var focusNodeAdjacencyOn = seriesModel.get('focusNodeAdjacencyOn');
  45235. if (focusNodeAdjacencyOn === 'click') {
  45236. // Remove default emphasis effect
  45237. api.getZr().on('click', this._clickHandler);
  45238. }
  45239. else if (focusNodeAdjacencyOn === 'mouseover') {
  45240. mesh.on('mousemove', this._mousemoveHandler, this);
  45241. mesh.on('mouseout', this._mouseOutHandler, this);
  45242. this._pointsBuilder.highlightOnMouseover = false;
  45243. }
  45244. else {
  45245. if (true) {
  45246. console.warn('Unkown focusNodeAdjacencyOn value \s' + focusNodeAdjacencyOn);
  45247. }
  45248. }
  45249. }
  45250. // Reset
  45251. this._lastMouseOverDataIndex = -1;
  45252. },
  45253. _clickHandler: function (e) {
  45254. if (this._layouting) {
  45255. return;
  45256. }
  45257. var dataIndex = this._pointsBuilder.getPointsMesh().dataIndex;
  45258. if (dataIndex >= 0) {
  45259. this._api.dispatchAction({
  45260. type: 'graphGLFocusNodeAdjacency',
  45261. seriesId: this._model.id,
  45262. dataIndex: dataIndex
  45263. });
  45264. }
  45265. else {
  45266. this._api.dispatchAction({
  45267. type: 'graphGLUnfocusNodeAdjacency',
  45268. seriesId: this._model.id
  45269. });
  45270. }
  45271. },
  45272. _mousemoveHandler: function (e) {
  45273. if (this._layouting) {
  45274. return;
  45275. }
  45276. var dataIndex = this._pointsBuilder.getPointsMesh().dataIndex;
  45277. if (dataIndex >= 0) {
  45278. if (dataIndex !== this._lastMouseOverDataIndex) {
  45279. this._api.dispatchAction({
  45280. type: 'graphGLFocusNodeAdjacency',
  45281. seriesId: this._model.id,
  45282. dataIndex: dataIndex
  45283. });
  45284. }
  45285. }
  45286. else {
  45287. this._mouseOutHandler(e);
  45288. }
  45289. this._lastMouseOverDataIndex = dataIndex;
  45290. },
  45291. _mouseOutHandler: function (e) {
  45292. if (this._layouting) {
  45293. return;
  45294. }
  45295. this._api.dispatchAction({
  45296. type: 'graphGLUnfocusNodeAdjacency',
  45297. seriesId: this._model.id
  45298. });
  45299. this._lastMouseOverDataIndex = -1;
  45300. },
  45301. _updateForceEdgesGeometry: function (edges, seriesModel) {
  45302. var geometry = this._forceEdgesMesh.geometry;
  45303. var edgeData = seriesModel.getEdgeData();
  45304. var offset = 0;
  45305. var layoutInstance = this._forceLayoutInstance;
  45306. var vertexCount = edgeData.count() * 2;
  45307. geometry.attributes.node.init(vertexCount);
  45308. geometry.attributes.color.init(vertexCount);
  45309. edgeData.each(function (idx) {
  45310. var edge = edges[idx];
  45311. geometry.attributes.node.set(offset, layoutInstance.getNodeUV(edge.node1));
  45312. geometry.attributes.node.set(offset + 1, layoutInstance.getNodeUV(edge.node2));
  45313. var color = edgeData.getItemVisual(edge.dataIndex, 'color');
  45314. var colorArr = __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__["a" /* default */].parseColor(color);
  45315. colorArr[3] *= __WEBPACK_IMPORTED_MODULE_5__util_retrieve__["a" /* default */].firstNotNull(
  45316. edgeData.getItemVisual(edge.dataIndex, 'opacity'), 1
  45317. );
  45318. geometry.attributes.color.set(offset, colorArr);
  45319. geometry.attributes.color.set(offset + 1, colorArr);
  45320. offset += 2;
  45321. });
  45322. geometry.dirty();
  45323. },
  45324. _updateMeshLinesGeometry: function () {
  45325. var edgeData = this._model.getEdgeData();
  45326. var geometry = this._edgesMesh.geometry;
  45327. var edgeData = this._model.getEdgeData();
  45328. var points = this._model.getData().getLayout('points');
  45329. geometry.resetOffset();
  45330. geometry.setVertexCount(edgeData.count() * geometry.getLineVertexCount());
  45331. geometry.setTriangleCount(edgeData.count() * geometry.getLineTriangleCount());
  45332. var p0 = [];
  45333. var p1 = [];
  45334. var lineWidthQuery = ['lineStyle', 'width'];
  45335. this._originalEdgeColors = new Float32Array(edgeData.count() * 4);
  45336. this._edgeIndicesMap = new Float32Array(edgeData.count());
  45337. edgeData.each(function (idx) {
  45338. var edge = edgeData.graph.getEdgeByIndex(idx);
  45339. var idx1 = edge.node1.dataIndex * 2;
  45340. var idx2 = edge.node2.dataIndex * 2;
  45341. p0[0] = points[idx1];
  45342. p0[1] = points[idx1 + 1];
  45343. p1[0] = points[idx2];
  45344. p1[1] = points[idx2 + 1];
  45345. var color = edgeData.getItemVisual(edge.dataIndex, 'color');
  45346. var colorArr = __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__["a" /* default */].parseColor(color);
  45347. colorArr[3] *= __WEBPACK_IMPORTED_MODULE_5__util_retrieve__["a" /* default */].firstNotNull(edgeData.getItemVisual(edge.dataIndex, 'opacity'), 1);
  45348. var itemModel = edgeData.getItemModel(edge.dataIndex);
  45349. var lineWidth = __WEBPACK_IMPORTED_MODULE_5__util_retrieve__["a" /* default */].firstNotNull(itemModel.get(lineWidthQuery), 1) * this._api.getDevicePixelRatio();
  45350. geometry.addLine(p0, p1, colorArr, lineWidth);
  45351. for (var k = 0; k < 4; k++) {
  45352. this._originalEdgeColors[edge.dataIndex * 4 + k] = colorArr[k];
  45353. }
  45354. this._edgeIndicesMap[edge.dataIndex] = idx;
  45355. }, this);
  45356. geometry.dirty();
  45357. },
  45358. _updateForceNodesGeometry: function (nodeData) {
  45359. var pointsMesh = this._pointsBuilder.getPointsMesh();
  45360. var pos = [];
  45361. for (var i = 0; i < nodeData.count(); i++) {
  45362. this._forceLayoutInstance.getNodeUV(i, pos);
  45363. pointsMesh.geometry.attributes.position.set(i, pos);
  45364. }
  45365. pointsMesh.geometry.dirty('position');
  45366. },
  45367. _initLayout: function (seriesModel, ecModel, api) {
  45368. var layout = seriesModel.get('layout');
  45369. var graph = seriesModel.getGraph();
  45370. var boxLayoutOption = seriesModel.getBoxLayoutParams();
  45371. var viewport = __WEBPACK_IMPORTED_MODULE_1_echarts_lib_util_layout___default.a.getLayoutRect(boxLayoutOption, {
  45372. width: api.getWidth(),
  45373. height: api.getHeight()
  45374. });
  45375. if (layout === 'force') {
  45376. if (true) {
  45377. console.warn('Currently only forceAtlas2 layout supported.');
  45378. }
  45379. layout = 'forceAtlas2';
  45380. }
  45381. // Stop previous layout
  45382. this.stopLayout(seriesModel, ecModel, api, {
  45383. beforeLayout: true
  45384. });
  45385. var nodeData = seriesModel.getData();
  45386. var edgeData = seriesModel.getData();
  45387. if (layout === 'forceAtlas2') {
  45388. var layoutModel = seriesModel.getModel('forceAtlas2');
  45389. var layoutInstance = this._forceLayoutInstance;
  45390. var nodes = [];
  45391. var edges = [];
  45392. var nodeDataExtent = nodeData.getDataExtent('value');
  45393. var edgeDataExtent = edgeData.getDataExtent('value');
  45394. var edgeWeightRange = __WEBPACK_IMPORTED_MODULE_5__util_retrieve__["a" /* default */].firstNotNull(layoutModel.get('edgeWeight'), 1.0);
  45395. var nodeWeightRange = __WEBPACK_IMPORTED_MODULE_5__util_retrieve__["a" /* default */].firstNotNull(layoutModel.get('nodeWeight'), 1.0);
  45396. if (typeof edgeWeightRange === 'number') {
  45397. edgeWeightRange = [edgeWeightRange, edgeWeightRange];
  45398. }
  45399. if (typeof nodeWeightRange === 'number') {
  45400. nodeWeightRange = [nodeWeightRange, nodeWeightRange];
  45401. }
  45402. var offset = 0;
  45403. var nodesIndicesMap = {};
  45404. var layoutPoints = new Float32Array(nodeData.count() * 2);
  45405. graph.eachNode(function (node) {
  45406. var dataIndex = node.dataIndex;
  45407. var value = nodeData.get('value', dataIndex);
  45408. var x;
  45409. var y;
  45410. if (nodeData.hasItemOption) {
  45411. var itemModel = nodeData.getItemModel(dataIndex);
  45412. x = itemModel.get('x');
  45413. y = itemModel.get('y');
  45414. }
  45415. if (x == null) {
  45416. // Random in rectangle
  45417. x = viewport.x + Math.random() * viewport.width;
  45418. y = viewport.y + Math.random() * viewport.height;
  45419. }
  45420. layoutPoints[offset * 2] = x;
  45421. layoutPoints[offset * 2 + 1] = y;
  45422. nodesIndicesMap[node.id] = offset++;
  45423. var mass = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.number.linearMap(value, nodeDataExtent, nodeWeightRange);
  45424. if (isNaN(mass)) {
  45425. if (!isNaN(nodeWeightRange[0])) {
  45426. mass = nodeWeightRange[0];
  45427. }
  45428. else {
  45429. mass = 1;
  45430. }
  45431. }
  45432. nodes.push({
  45433. x: x, y: y, mass: mass, size: nodeData.getItemVisual(dataIndex, 'symbolSize')
  45434. });
  45435. });
  45436. nodeData.setLayout('points', layoutPoints);
  45437. graph.eachEdge(function (edge) {
  45438. var dataIndex = edge.dataIndex;
  45439. var value = nodeData.get('value', dataIndex);
  45440. var weight = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.number.linearMap(value, edgeDataExtent, edgeWeightRange);
  45441. if (isNaN(weight)) {
  45442. if (!isNaN(edgeWeightRange[0])) {
  45443. weight = edgeWeightRange[0];
  45444. }
  45445. else {
  45446. weight = 1;
  45447. }
  45448. }
  45449. edges.push({
  45450. node1: nodesIndicesMap[edge.node1.id],
  45451. node2: nodesIndicesMap[edge.node2.id],
  45452. weight: weight,
  45453. dataIndex: dataIndex
  45454. });
  45455. });
  45456. if (!layoutInstance) {
  45457. var isGPU = layoutModel.get('GPU');
  45458. if (this._forceLayoutInstance) {
  45459. if ((isGPU && !(this._forceLayoutInstance instanceof __WEBPACK_IMPORTED_MODULE_6__ForceAtlas2GPU__["a" /* default */]))
  45460. || (!isGPU && !(this._forceLayoutInstance instanceof __WEBPACK_IMPORTED_MODULE_7__ForceAtlas2__["a" /* default */]))
  45461. ) {
  45462. // Mark to dispose
  45463. this._forceLayoutInstanceToDispose = this._forceLayoutInstance;
  45464. }
  45465. }
  45466. layoutInstance = this._forceLayoutInstance = isGPU
  45467. ? new __WEBPACK_IMPORTED_MODULE_6__ForceAtlas2GPU__["a" /* default */]()
  45468. : new __WEBPACK_IMPORTED_MODULE_7__ForceAtlas2__["a" /* default */]();
  45469. }
  45470. layoutInstance.initData(nodes, edges);
  45471. layoutInstance.updateOption(layoutModel.option);
  45472. // Update lines geometry after first layout;
  45473. this._updateForceEdgesGeometry(layoutInstance.getEdges(), seriesModel);
  45474. this._updatePositionTexture();
  45475. api.dispatchAction({
  45476. type: 'graphGLStartLayout',
  45477. from: this.uid
  45478. });
  45479. }
  45480. else {
  45481. var layoutPoints = new Float32Array(nodeData.count() * 2);
  45482. var offset = 0;
  45483. graph.eachNode(function (node) {
  45484. var dataIndex = node.dataIndex;
  45485. var x;
  45486. var y;
  45487. if (nodeData.hasItemOption) {
  45488. var itemModel = nodeData.getItemModel(dataIndex);
  45489. x = itemModel.get('x');
  45490. y = itemModel.get('y');
  45491. }
  45492. layoutPoints[offset++] = x;
  45493. layoutPoints[offset++] = y;
  45494. });
  45495. nodeData.setLayout('points', layoutPoints);
  45496. this._updateAfterLayout(seriesModel, ecModel, api);
  45497. }
  45498. },
  45499. _updatePositionTexture: function () {
  45500. var positionTex = this._forceLayoutInstance.getNodePositionTexture();
  45501. this._pointsBuilder.setPositionTexture(positionTex);
  45502. this._forceEdgesMesh.material.set('positionTex', positionTex);
  45503. },
  45504. startLayout: function (seriesModel, ecModel, api, payload) {
  45505. if (payload && payload.from != null && payload.from !== this.uid) {
  45506. return;
  45507. }
  45508. var viewGL = this.viewGL;
  45509. var api = this._api;
  45510. var layoutInstance = this._forceLayoutInstance;
  45511. var data = this._model.getData();
  45512. var layoutModel = this._model.getModel('forceAtlas2');
  45513. if (!layoutInstance) {
  45514. if (true) {
  45515. console.error('None layout don\'t have startLayout action');
  45516. }
  45517. return;
  45518. }
  45519. this.groupGL.remove(this._edgesMesh);
  45520. this.groupGL.add(this._forceEdgesMesh);
  45521. if (!this._forceLayoutInstance) {
  45522. return;
  45523. }
  45524. this._updateForceNodesGeometry(seriesModel.getData());
  45525. this._pointsBuilder.hideLabels();
  45526. var self = this;
  45527. var layoutId = this._layoutId = globalLayoutId++;
  45528. var maxSteps = layoutModel.getShallow('maxSteps');
  45529. var steps = layoutModel.getShallow('steps');
  45530. var stepsCount = 0;
  45531. var syncStepCount = Math.max(steps * 2, 20);
  45532. var doLayout = function (layoutId) {
  45533. if (layoutId !== self._layoutId) {
  45534. return;
  45535. }
  45536. if (layoutInstance.isFinished(maxSteps)) {
  45537. api.dispatchAction({
  45538. type: 'graphGLStopLayout',
  45539. from: self.uid
  45540. });
  45541. api.dispatchAction({
  45542. type: 'graphGLFinishLayout',
  45543. points: data.getLayout('points'),
  45544. from: self.uid
  45545. });
  45546. return;
  45547. }
  45548. layoutInstance.update(viewGL.layer.renderer, steps, function () {
  45549. self._updatePositionTexture();
  45550. // PENDING Performance.
  45551. stepsCount += steps;
  45552. // Sync posiiton every 20 steps.
  45553. if (stepsCount >= syncStepCount) {
  45554. self._syncNodePosition(seriesModel);
  45555. stepsCount = 0;
  45556. }
  45557. // Position texture will been swapped. set every time.
  45558. api.getZr().refresh();
  45559. __WEBPACK_IMPORTED_MODULE_8_zrender_lib_animation_requestAnimationFrame___default()(function () {
  45560. doLayout(layoutId);
  45561. });
  45562. });
  45563. };
  45564. __WEBPACK_IMPORTED_MODULE_8_zrender_lib_animation_requestAnimationFrame___default()(function () {
  45565. if (self._forceLayoutInstanceToDispose) {
  45566. self._forceLayoutInstanceToDispose.dispose(viewGL.layer.renderer);
  45567. self._forceLayoutInstanceToDispose = null;
  45568. }
  45569. doLayout(layoutId);
  45570. });
  45571. this._layouting = true;
  45572. },
  45573. stopLayout: function (seriesModel, ecModel, api, payload) {
  45574. if (payload && payload.from != null && payload.from !== this.uid) {
  45575. return;
  45576. }
  45577. this._layoutId = 0;
  45578. this.groupGL.remove(this._forceEdgesMesh);
  45579. this.groupGL.add(this._edgesMesh);
  45580. if (!this._forceLayoutInstance) {
  45581. return;
  45582. }
  45583. if (!this.viewGL.layer) {
  45584. return;
  45585. }
  45586. if (!(payload && payload.beforeLayout)) {
  45587. this._syncNodePosition(seriesModel);
  45588. this._updateAfterLayout(seriesModel, ecModel, api);
  45589. }
  45590. this._api.getZr().refresh();
  45591. this._layouting = false;
  45592. },
  45593. _syncNodePosition: function (seriesModel) {
  45594. var points = this._forceLayoutInstance.getNodePosition(this.viewGL.layer.renderer);
  45595. seriesModel.getData().setLayout('points', points);
  45596. seriesModel.setNodePosition(points);
  45597. },
  45598. _updateAfterLayout: function (seriesModel, ecModel, api) {
  45599. this._updateMeshLinesGeometry();
  45600. this._pointsBuilder.removePositionTexture();
  45601. this._pointsBuilder.updateLayout(seriesModel, ecModel, api);
  45602. this._pointsBuilder.updateView(this.viewGL.camera);
  45603. this._pointsBuilder.updateLabels();
  45604. this._pointsBuilder.showLabels();
  45605. },
  45606. focusNodeAdjacency: function (seriesModel, ecModel, api, payload) {
  45607. var data = this._model.getData();
  45608. this._downplayAll();
  45609. var dataIndex = payload.dataIndex;
  45610. var graph = data.graph;
  45611. var focusNodes = [];
  45612. var node = graph.getNodeByIndex(dataIndex);
  45613. focusNodes.push(node);
  45614. node.edges.forEach(function (edge) {
  45615. if (edge.dataIndex < 0) {
  45616. return;
  45617. }
  45618. edge.node1 !== node && focusNodes.push(edge.node1);
  45619. edge.node2 !== node && focusNodes.push(edge.node2);
  45620. }, this);
  45621. this._pointsBuilder.fadeOutAll(0.05);
  45622. this._fadeOutEdgesAll(0.05);
  45623. focusNodes.forEach(function (node) {
  45624. this._pointsBuilder.highlight(data, node.dataIndex);
  45625. }, this);
  45626. this._pointsBuilder.updateLabels(focusNodes.map(function (node) {
  45627. return node.dataIndex;
  45628. }));
  45629. var focusEdges = [];
  45630. node.edges.forEach(function (edge) {
  45631. if (edge.dataIndex >= 0) {
  45632. this._highlightEdge(edge.dataIndex);
  45633. focusEdges.push(edge);
  45634. }
  45635. }, this);
  45636. this._focusNodes = focusNodes;
  45637. this._focusEdges = focusEdges;
  45638. },
  45639. unfocusNodeAdjacency: function (seriesModel, ecModel, api, payload) {
  45640. this._downplayAll();
  45641. this._pointsBuilder.fadeInAll();
  45642. this._fadeInEdgesAll();
  45643. this._pointsBuilder.updateLabels();
  45644. },
  45645. _highlightEdge: function (dataIndex) {
  45646. var itemModel = this._model.getEdgeData().getItemModel(dataIndex);
  45647. var emphasisColor = __WEBPACK_IMPORTED_MODULE_2__util_graphicGL__["a" /* default */].parseColor(itemModel.get('emphasis.lineStyle.color') || itemModel.get('lineStyle.color'));
  45648. var emphasisOpacity = __WEBPACK_IMPORTED_MODULE_5__util_retrieve__["a" /* default */].firstNotNull(itemModel.get('emphasis.lineStyle.opacity'), itemModel.get('lineStyle.opacity'), 1);
  45649. emphasisColor[3] *= emphasisOpacity;
  45650. this._edgesMesh.geometry.setItemColor(this._edgeIndicesMap[dataIndex], emphasisColor);
  45651. },
  45652. _downplayAll: function () {
  45653. if (this._focusNodes) {
  45654. this._focusNodes.forEach(function (node) {
  45655. this._pointsBuilder.downplay(this._model.getData(), node.dataIndex);
  45656. }, this);
  45657. }
  45658. if (this._focusEdges) {
  45659. this._focusEdges.forEach(function (edge) {
  45660. this._downplayEdge(edge.dataIndex);
  45661. }, this);
  45662. }
  45663. },
  45664. _downplayEdge: function (dataIndex) {
  45665. var color = this._getColor(dataIndex, []);
  45666. this._edgesMesh.geometry.setItemColor(this._edgeIndicesMap[dataIndex], color);
  45667. },
  45668. _setEdgeFade: (function () {
  45669. var color = [];
  45670. return function (dataIndex, percent) {
  45671. this._getColor(dataIndex, color);
  45672. color[3] *= percent;
  45673. this._edgesMesh.geometry.setItemColor(this._edgeIndicesMap[dataIndex], color);
  45674. };
  45675. })(),
  45676. _getColor: function (dataIndex, out) {
  45677. for (var i = 0; i < 4; i++) {
  45678. out[i] = this._originalEdgeColors[dataIndex * 4 + i];
  45679. }
  45680. return out;
  45681. },
  45682. _fadeOutEdgesAll: function (percent) {
  45683. var graph = this._model.getData().graph;
  45684. graph.eachEdge(function (edge) {
  45685. this._setEdgeFade(edge.dataIndex, percent);
  45686. }, this);
  45687. },
  45688. _fadeInEdgesAll: function () {
  45689. this._fadeOutEdgesAll(1);
  45690. },
  45691. _updateCamera: function (seriesModel, api) {
  45692. this.viewGL.setViewport(0, 0, api.getWidth(), api.getHeight(), api.getDevicePixelRatio());
  45693. var camera = this.viewGL.camera;
  45694. var nodeData = seriesModel.getData();
  45695. var points = nodeData.getLayout('points');
  45696. var min = vec2.create(Infinity, Infinity);
  45697. var max = vec2.create(-Infinity, -Infinity);
  45698. var pt = [];
  45699. for (var i = 0; i < points.length;) {
  45700. pt[0] = points[i++];
  45701. pt[1] = points[i++];
  45702. vec2.min(min, min, pt);
  45703. vec2.max(max, max, pt);
  45704. }
  45705. var cy = (max[1] + min[1]) / 2;
  45706. var cx = (max[0] + min[0]) / 2;
  45707. // Only fit the camera when graph is not in the center.
  45708. // PENDING
  45709. if (cx > camera.left && cx < camera.right
  45710. && cy < camera.bottom && cy > camera.top
  45711. ) {
  45712. return;
  45713. }
  45714. // Scale a bit
  45715. var width = Math.max(max[0] - min[0], 10);
  45716. // Keep aspect
  45717. var height = width / api.getWidth() * api.getHeight();
  45718. width *= 1.4;
  45719. height *= 1.4;
  45720. min[0] -= width * 0.2;
  45721. camera.left = min[0];
  45722. camera.top = cy - height / 2;
  45723. camera.bottom = cy + height / 2;
  45724. camera.right = width + min[0];
  45725. camera.near = 0;
  45726. camera.far = 100;
  45727. },
  45728. dispose: function () {
  45729. var renderer = this.viewGL.layer.renderer;
  45730. if (this._forceLayoutInstance) {
  45731. this._forceLayoutInstance.dispose(renderer);
  45732. }
  45733. this.groupGL.removeAll();
  45734. // Stop layout.
  45735. this._layoutId = -1;
  45736. },
  45737. remove: function () {
  45738. this.groupGL.removeAll();
  45739. this._control.dispose();
  45740. }
  45741. });
  45742. /***/
  45743. }),
  45744. /* 269 */
  45745. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  45746. "use strict";
  45747. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  45748. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  45749. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__ = __webpack_require__(1);
  45750. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_claygl_src_compositor_Pass__ = __webpack_require__(16);
  45751. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_claygl_src_FrameBuffer__ = __webpack_require__(10);
  45752. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__forceAtlas2_glsl_js__ = __webpack_require__(270);
  45753. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader.import(__WEBPACK_IMPORTED_MODULE_4__forceAtlas2_glsl_js__["a" /* default */]);
  45754. var defaultConfigs = {
  45755. repulsionByDegree: true,
  45756. linLogMode: false,
  45757. strongGravityMode: false,
  45758. gravity: 1.0,
  45759. scaling: 1.0,
  45760. edgeWeightInfluence: 1.0,
  45761. jitterTolerence: 0.1,
  45762. preventOverlap: false,
  45763. dissuadeHubs: false,
  45764. gravityCenter: null
  45765. };
  45766. function ForceAtlas2GPU(options) {
  45767. var textureOpt = {
  45768. type: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Texture.FLOAT,
  45769. minFilter: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Texture.NEAREST,
  45770. magFilter: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Texture.NEAREST
  45771. };
  45772. this._positionSourceTex = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Texture2D(textureOpt);
  45773. this._positionSourceTex.flipY = false;
  45774. this._positionTex = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Texture2D(textureOpt);
  45775. this._positionPrevTex = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Texture2D(textureOpt);
  45776. this._forceTex = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Texture2D(textureOpt);
  45777. this._forcePrevTex = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Texture2D(textureOpt);
  45778. this._weightedSumTex = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Texture2D(textureOpt);
  45779. this._weightedSumTex.width = this._weightedSumTex.height = 1;
  45780. this._globalSpeedTex = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Texture2D(textureOpt);
  45781. this._globalSpeedPrevTex = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Texture2D(textureOpt);
  45782. this._globalSpeedTex.width = this._globalSpeedTex.height = 1;
  45783. this._globalSpeedPrevTex.width = this._globalSpeedPrevTex.height = 1;
  45784. this._nodeRepulsionPass = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_compositor_Pass__["a" /* default */]({
  45785. fragment: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader.source('ecgl.forceAtlas2.updateNodeRepulsion')
  45786. });
  45787. this._positionPass = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_compositor_Pass__["a" /* default */]({
  45788. fragment: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader.source('ecgl.forceAtlas2.updatePosition')
  45789. });
  45790. this._globalSpeedPass = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_compositor_Pass__["a" /* default */]({
  45791. fragment: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader.source('ecgl.forceAtlas2.calcGlobalSpeed')
  45792. });
  45793. this._copyPass = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_compositor_Pass__["a" /* default */]({
  45794. fragment: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader.source('clay.compositor.output')
  45795. });
  45796. var additiveBlend = function (gl) {
  45797. gl.blendEquation(gl.FUNC_ADD);
  45798. gl.blendFunc(gl.ONE, gl.ONE);
  45799. };
  45800. this._edgeForceMesh = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh({
  45801. geometry: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Geometry({
  45802. attributes: {
  45803. node1: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Geometry.Attribute('node1', 'float', 2),
  45804. node2: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Geometry.Attribute('node2', 'float', 2),
  45805. weight: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Geometry.Attribute('weight', 'float', 1)
  45806. },
  45807. dynamic: true,
  45808. mainAttribute: 'node1'
  45809. }),
  45810. material: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Material({
  45811. transparent: true,
  45812. shader: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].createShader('ecgl.forceAtlas2.updateEdgeAttraction'),
  45813. blend: additiveBlend,
  45814. depthMask: false,
  45815. depthText: false
  45816. }),
  45817. mode: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh.POINTS
  45818. });
  45819. this._weightedSumMesh = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh({
  45820. geometry: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Geometry({
  45821. attributes: {
  45822. node: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Geometry.Attribute('node', 'float', 2)
  45823. },
  45824. dynamic: true,
  45825. mainAttribute: 'node'
  45826. }),
  45827. material: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Material({
  45828. transparent: true,
  45829. shader: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].createShader('ecgl.forceAtlas2.calcWeightedSum'),
  45830. blend: additiveBlend,
  45831. depthMask: false,
  45832. depthText: false
  45833. }),
  45834. mode: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh.POINTS
  45835. });
  45836. this._framebuffer = new __WEBPACK_IMPORTED_MODULE_3_claygl_src_FrameBuffer__["a" /* default */]({
  45837. depthBuffer: false
  45838. });
  45839. this._dummyCamera = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].OrthographicCamera({
  45840. left: -1, right: 1,
  45841. top: 1, bottom: -1,
  45842. near: 0, far: 100
  45843. });
  45844. this._globalSpeed = 0;
  45845. }
  45846. ForceAtlas2GPU.prototype.updateOption = function (options) {
  45847. // Default config
  45848. for (var name in defaultConfigs) {
  45849. this[name] = defaultConfigs[name];
  45850. }
  45851. // Config according to data scale
  45852. var nNodes = this._nodes.length;
  45853. if (nNodes > 50000) {
  45854. this.jitterTolerence = 10;
  45855. }
  45856. else if (nNodes > 5000) {
  45857. this.jitterTolerence = 1;
  45858. }
  45859. else {
  45860. this.jitterTolerence = 0.1;
  45861. }
  45862. if (nNodes > 100) {
  45863. this.scaling = 2.0;
  45864. }
  45865. else {
  45866. this.scaling = 10.0;
  45867. }
  45868. // this.edgeWeightInfluence = 1;
  45869. // this.gravity = 1;
  45870. // this.strongGravityMode = false;
  45871. if (options) {
  45872. for (var name in defaultConfigs) {
  45873. if (options[name] != null) {
  45874. this[name] = options[name];
  45875. }
  45876. }
  45877. }
  45878. if (this.repulsionByDegree) {
  45879. var positionBuffer = this._positionSourceTex.pixels;
  45880. for (var i = 0; i < this._nodes.length; i++) {
  45881. positionBuffer[i * 4 + 2] = (this._nodes[i].degree || 0) + 1;
  45882. }
  45883. }
  45884. };
  45885. ForceAtlas2GPU.prototype._updateGravityCenter = function (options) {
  45886. var nodes = this._nodes;
  45887. var edges = this._edges;
  45888. if (!this.gravityCenter) {
  45889. var min = [Infinity, Infinity];
  45890. var max = [-Infinity, -Infinity];
  45891. for (var i = 0; i < nodes.length; i++) {
  45892. min[0] = Math.min(nodes[i].x, min[0]);
  45893. min[1] = Math.min(nodes[i].y, min[1]);
  45894. max[0] = Math.max(nodes[i].x, max[0]);
  45895. max[1] = Math.max(nodes[i].y, max[1]);
  45896. }
  45897. this._gravityCenter = [(min[0] + max[0]) * 0.5, (min[1] + max[1]) * 0.5];
  45898. }
  45899. else {
  45900. this._gravityCenter = this.gravityCenter;
  45901. }
  45902. // Update inDegree, outDegree
  45903. for (var i = 0; i < edges.length; i++) {
  45904. var node1 = edges[i].node1;
  45905. var node2 = edges[i].node2;
  45906. nodes[node1].degree = (nodes[node1].degree || 0) + 1;
  45907. nodes[node2].degree = (nodes[node2].degree || 0) + 1;
  45908. }
  45909. };
  45910. /**
  45911. * @param {Array.<Object>} [{ x, y, mass }] nodes
  45912. * @param {Array.<Object>} [{ node1, node2, weight }] edges
  45913. */
  45914. ForceAtlas2GPU.prototype.initData = function (nodes, edges) {
  45915. this._nodes = nodes;
  45916. this._edges = edges;
  45917. this._updateGravityCenter();
  45918. var textureWidth = Math.ceil(Math.sqrt(nodes.length));
  45919. var textureHeight = textureWidth;
  45920. var positionBuffer = new Float32Array(textureWidth * textureHeight * 4);
  45921. this._resize(textureWidth, textureHeight);
  45922. var offset = 0;
  45923. for (var i = 0; i < nodes.length; i++) {
  45924. var node = nodes[i];
  45925. positionBuffer[offset++] = node.x || 0;
  45926. positionBuffer[offset++] = node.y || 0;
  45927. positionBuffer[offset++] = node.mass || 1;
  45928. positionBuffer[offset++] = node.size || 1;
  45929. }
  45930. this._positionSourceTex.pixels = positionBuffer;
  45931. var edgeGeometry = this._edgeForceMesh.geometry;
  45932. var edgeLen = edges.length;
  45933. edgeGeometry.attributes.node1.init(edgeLen * 2);
  45934. edgeGeometry.attributes.node2.init(edgeLen * 2);
  45935. edgeGeometry.attributes.weight.init(edgeLen * 2);
  45936. var uv = [];
  45937. for (var i = 0; i < edges.length; i++) {
  45938. var attributes = edgeGeometry.attributes;
  45939. var weight = edges[i].weight;
  45940. if (weight == null) {
  45941. weight = 1;
  45942. }
  45943. // Two way.
  45944. attributes.node1.set(i, this.getNodeUV(edges[i].node1, uv));
  45945. attributes.node2.set(i, this.getNodeUV(edges[i].node2, uv));
  45946. attributes.weight.set(i, weight);
  45947. attributes.node1.set(i + edgeLen, this.getNodeUV(edges[i].node2, uv));
  45948. attributes.node2.set(i + edgeLen, this.getNodeUV(edges[i].node1, uv));
  45949. attributes.weight.set(i + edgeLen, weight);
  45950. }
  45951. var weigtedSumGeo = this._weightedSumMesh.geometry;
  45952. weigtedSumGeo.attributes.node.init(nodes.length);
  45953. for (var i = 0; i < nodes.length; i++) {
  45954. weigtedSumGeo.attributes.node.set(i, this.getNodeUV(i, uv));
  45955. }
  45956. edgeGeometry.dirty();
  45957. weigtedSumGeo.dirty();
  45958. this._nodeRepulsionPass.material.define('fragment', 'NODE_COUNT', nodes.length);
  45959. this._nodeRepulsionPass.material.setUniform('textureSize', [textureWidth, textureHeight]);
  45960. this._inited = false;
  45961. this._frame = 0;
  45962. };
  45963. ForceAtlas2GPU.prototype.getNodes = function () {
  45964. return this._nodes;
  45965. };
  45966. ForceAtlas2GPU.prototype.getEdges = function () {
  45967. return this._edges;
  45968. };
  45969. ForceAtlas2GPU.prototype.step = function (renderer) {
  45970. if (!this._inited) {
  45971. this._initFromSource(renderer);
  45972. this._inited = true;
  45973. }
  45974. this._frame++;
  45975. this._framebuffer.attach(this._forceTex);
  45976. this._framebuffer.bind(renderer);
  45977. var nodeRepulsionPass = this._nodeRepulsionPass;
  45978. // Calc node repulsion, gravity
  45979. nodeRepulsionPass.setUniform('strongGravityMode', this.strongGravityMode);
  45980. nodeRepulsionPass.setUniform('gravity', this.gravity);
  45981. nodeRepulsionPass.setUniform('gravityCenter', this._gravityCenter);
  45982. nodeRepulsionPass.setUniform('scaling', this.scaling);
  45983. nodeRepulsionPass.setUniform('preventOverlap', this.preventOverlap);
  45984. nodeRepulsionPass.setUniform('positionTex', this._positionPrevTex);
  45985. nodeRepulsionPass.render(renderer);
  45986. // Calc edge attraction force
  45987. var edgeForceMesh = this._edgeForceMesh;
  45988. edgeForceMesh.material.set('linLogMode', this.linLogMode);
  45989. edgeForceMesh.material.set('edgeWeightInfluence', this.edgeWeightInfluence);
  45990. edgeForceMesh.material.set('preventOverlap', this.preventOverlap);
  45991. edgeForceMesh.material.set('positionTex', this._positionPrevTex);
  45992. renderer.gl.enable(renderer.gl.BLEND);
  45993. renderer.renderPass([edgeForceMesh], this._dummyCamera);
  45994. // Calc weighted sum.
  45995. this._framebuffer.attach(this._weightedSumTex);
  45996. renderer.gl.clearColor(0, 0, 0, 0);
  45997. renderer.gl.clear(renderer.gl.COLOR_BUFFER_BIT);
  45998. renderer.gl.enable(renderer.gl.BLEND);
  45999. var weightedSumMesh = this._weightedSumMesh;
  46000. weightedSumMesh.material.set('positionTex', this._positionPrevTex);
  46001. weightedSumMesh.material.set('forceTex', this._forceTex);
  46002. weightedSumMesh.material.set('forcePrevTex', this._forcePrevTex);
  46003. renderer.renderPass([weightedSumMesh], this._dummyCamera);
  46004. // Calc global speed.
  46005. this._framebuffer.attach(this._globalSpeedTex);
  46006. var globalSpeedPass = this._globalSpeedPass;
  46007. globalSpeedPass.setUniform('globalSpeedPrevTex', this._globalSpeedPrevTex);
  46008. globalSpeedPass.setUniform('weightedSumTex', this._weightedSumTex);
  46009. globalSpeedPass.setUniform('jitterTolerence', this.jitterTolerence);
  46010. renderer.gl.disable(renderer.gl.BLEND);
  46011. globalSpeedPass.render(renderer);
  46012. // Update position.
  46013. var positionPass = this._positionPass;
  46014. this._framebuffer.attach(this._positionTex);
  46015. positionPass.setUniform('globalSpeedTex', this._globalSpeedTex);
  46016. positionPass.setUniform('positionTex', this._positionPrevTex);
  46017. positionPass.setUniform('forceTex', this._forceTex);
  46018. positionPass.setUniform('forcePrevTex', this._forcePrevTex);
  46019. positionPass.render(renderer);
  46020. this._framebuffer.unbind(renderer);
  46021. this._swapTexture();
  46022. };
  46023. ForceAtlas2GPU.prototype.update = function (renderer, steps, cb) {
  46024. if (steps == null) {
  46025. steps = 1;
  46026. }
  46027. steps = Math.max(steps, 1);
  46028. for (var i = 0; i < steps; i++) {
  46029. this.step(renderer);
  46030. }
  46031. cb && cb();
  46032. };
  46033. ForceAtlas2GPU.prototype.getNodePositionTexture = function () {
  46034. return this._inited
  46035. // Texture already been swapped.
  46036. ? this._positionPrevTex
  46037. : this._positionSourceTex;
  46038. };
  46039. ForceAtlas2GPU.prototype.getNodeUV = function (nodeIndex, uv) {
  46040. uv = uv || [];
  46041. var textureWidth = this._positionTex.width;
  46042. var textureHeight = this._positionTex.height;
  46043. uv[0] = (nodeIndex % textureWidth) / (textureWidth - 1);
  46044. uv[1] = Math.floor(nodeIndex / textureWidth) / (textureHeight - 1) || 0;
  46045. return uv;
  46046. };
  46047. ForceAtlas2GPU.prototype.getNodePosition = function (renderer, out) {
  46048. var positionArr = this._positionArr;
  46049. var width = this._positionTex.width;
  46050. var height = this._positionTex.height;
  46051. var size = width * height;
  46052. if (!positionArr || positionArr.length !== size * 4) {
  46053. positionArr = this._positionArr = new Float32Array(size * 4);
  46054. }
  46055. this._framebuffer.bind(renderer);
  46056. this._framebuffer.attach(this._positionPrevTex);
  46057. renderer.gl.readPixels(
  46058. 0, 0, width, height,
  46059. renderer.gl.RGBA, renderer.gl.FLOAT,
  46060. positionArr
  46061. );
  46062. this._framebuffer.unbind(renderer);
  46063. if (!out) {
  46064. out = new Float32Array(this._nodes.length * 2);
  46065. }
  46066. for (var i = 0; i < this._nodes.length; i++) {
  46067. out[i * 2] = positionArr[i * 4];
  46068. out[i * 2 + 1] = positionArr[i * 4 + 1];
  46069. }
  46070. return out;
  46071. };
  46072. ForceAtlas2GPU.prototype.getTextureData = function (renderer, textureName) {
  46073. var tex = this['_' + textureName + 'Tex'];
  46074. var width = tex.width;
  46075. var height = tex.height;
  46076. this._framebuffer.bind(renderer);
  46077. this._framebuffer.attach(tex);
  46078. var arr = new Float32Array(width * height * 4);
  46079. renderer.gl.readPixels(0, 0, width, height, renderer.gl.RGBA, renderer.gl.FLOAT, arr);
  46080. this._framebuffer.unbind(renderer);
  46081. return arr;
  46082. };
  46083. ForceAtlas2GPU.prototype.getTextureSize = function () {
  46084. return {
  46085. width: this._positionTex.width,
  46086. height: this._positionTex.height
  46087. };
  46088. };
  46089. ForceAtlas2GPU.prototype.isFinished = function (maxSteps) {
  46090. return this._frame > maxSteps;
  46091. };
  46092. ForceAtlas2GPU.prototype._swapTexture = function () {
  46093. var tmp = this._positionPrevTex;
  46094. this._positionPrevTex = this._positionTex;
  46095. this._positionTex = tmp;
  46096. var tmp = this._forcePrevTex;
  46097. this._forcePrevTex = this._forceTex;
  46098. this._forceTex = tmp;
  46099. var tmp = this._globalSpeedPrevTex;
  46100. this._globalSpeedPrevTex = this._globalSpeedTex;
  46101. this._globalSpeedTex = tmp;
  46102. };
  46103. ForceAtlas2GPU.prototype._initFromSource = function (renderer) {
  46104. this._framebuffer.attach(this._positionPrevTex);
  46105. this._framebuffer.bind(renderer);
  46106. this._copyPass.setUniform('texture', this._positionSourceTex);
  46107. this._copyPass.render(renderer);
  46108. renderer.gl.clearColor(0, 0, 0, 0);
  46109. this._framebuffer.attach(this._forcePrevTex);
  46110. renderer.gl.clear(renderer.gl.COLOR_BUFFER_BIT);
  46111. this._framebuffer.attach(this._globalSpeedPrevTex);
  46112. renderer.gl.clear(renderer.gl.COLOR_BUFFER_BIT);
  46113. this._framebuffer.unbind(renderer);
  46114. };
  46115. ForceAtlas2GPU.prototype._resize = function (width, height) {
  46116. ['_positionSourceTex', '_positionTex', '_positionPrevTex', '_forceTex', '_forcePrevTex'].forEach(function (texName) {
  46117. this[texName].width = width;
  46118. this[texName].height = height;
  46119. this[texName].dirty();
  46120. }, this);
  46121. };
  46122. ForceAtlas2GPU.prototype.dispose = function (renderer) {
  46123. this._framebuffer.dispose(renderer);
  46124. this._copyPass.dispose(renderer);
  46125. this._nodeRepulsionPass.dispose(renderer);
  46126. this._positionPass.dispose(renderer);
  46127. this._globalSpeedPass.dispose(renderer);
  46128. this._edgeForceMesh.geometry.dispose(renderer);
  46129. this._weightedSumMesh.geometry.dispose(renderer);
  46130. this._positionSourceTex.dispose(renderer);
  46131. this._positionTex.dispose(renderer);
  46132. this._positionPrevTex.dispose(renderer);
  46133. this._forceTex.dispose(renderer);
  46134. this._forcePrevTex.dispose(renderer);
  46135. this._weightedSumTex.dispose(renderer);
  46136. this._globalSpeedTex.dispose(renderer);
  46137. this._globalSpeedPrevTex.dispose(renderer);
  46138. };
  46139. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.ForceAtlas2GPU = ForceAtlas2GPU;
  46140. /* harmony default export */ __webpack_exports__["a"] = (ForceAtlas2GPU);
  46141. /***/
  46142. }),
  46143. /* 270 */
  46144. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  46145. "use strict";
  46146. /* harmony default export */ __webpack_exports__["a"] = ("@export ecgl.forceAtlas2.updateNodeRepulsion\n\n#define NODE_COUNT 0\n\nuniform sampler2D positionTex;\n\nuniform vec2 textureSize;\nuniform float gravity;\nuniform float scaling;\nuniform vec2 gravityCenter;\n\nuniform bool strongGravityMode;\nuniform bool preventOverlap;\n\nvarying vec2 v_Texcoord;\n\nvoid main() {\n\n vec4 n0 = texture2D(positionTex, v_Texcoord);\n\n vec2 force = vec2(0.0);\n for (int i = 0; i < NODE_COUNT; i++) {\n vec2 uv = vec2(\n mod(float(i), textureSize.x) / (textureSize.x - 1.0),\n floor(float(i) / textureSize.x) / (textureSize.y - 1.0)\n );\n vec4 n1 = texture2D(positionTex, uv);\n\n vec2 dir = n0.xy - n1.xy;\n float d2 = dot(dir, dir);\n\n if (d2 > 0.0) {\n float factor = 0.0;\n if (preventOverlap) {\n float d = sqrt(d2);\n d = d - n0.w - n1.w;\n if (d > 0.0) {\n factor = scaling * n0.z * n1.z / (d * d);\n }\n else if (d < 0.0) {\n factor = scaling * 100.0 * n0.z * n1.z;\n }\n }\n else {\n factor = scaling * n0.z * n1.z / d2;\n }\n force += dir * factor;\n }\n }\n\n vec2 dir = gravityCenter - n0.xy;\n float d = 1.0;\n if (!strongGravityMode) {\n d = length(dir);\n }\n\n force += dir * n0.z * gravity / (d + 1.0);\n\n gl_FragColor = vec4(force, 0.0, 1.0);\n}\n@end\n\n@export ecgl.forceAtlas2.updateEdgeAttraction.vertex\n\nattribute vec2 node1;\nattribute vec2 node2;\nattribute float weight;\n\nuniform sampler2D positionTex;\nuniform float edgeWeightInfluence;\nuniform bool preventOverlap;\nuniform bool linLogMode;\n\nuniform vec2 windowSize: WINDOW_SIZE;\n\nvarying vec2 v_Force;\n\nvoid main() {\n\n vec4 n0 = texture2D(positionTex, node1);\n vec4 n1 = texture2D(positionTex, node2);\n\n vec2 dir = n1.xy - n0.xy;\n float d = length(dir);\n float w;\n if (edgeWeightInfluence == 0.0) {\n w = 1.0;\n }\n else if (edgeWeightInfluence == 1.0) {\n w = weight;\n }\n else {\n w = pow(weight, edgeWeightInfluence);\n }\n vec2 offset = vec2(1.0 / windowSize.x, 1.0 / windowSize.y);\n vec2 scale = vec2((windowSize.x - 1.0) / windowSize.x, (windowSize.y - 1.0) / windowSize.y);\n vec2 pos = node1 * scale * 2.0 - 1.0;\n gl_Position = vec4(pos + offset, 0.0, 1.0);\n gl_PointSize = 1.0;\n\n float factor;\n if (preventOverlap) {\n d = d - n1.w - n0.w;\n }\n if (d <= 0.0) {\n v_Force = vec2(0.0);\n return;\n }\n\n if (linLogMode) {\n factor = w * log(d) / d;\n }\n else {\n factor = w;\n }\n v_Force = dir * factor;\n}\n@end\n\n@export ecgl.forceAtlas2.updateEdgeAttraction.fragment\n\nvarying vec2 v_Force;\n\nvoid main() {\n gl_FragColor = vec4(v_Force, 0.0, 0.0);\n}\n@end\n\n@export ecgl.forceAtlas2.calcWeightedSum.vertex\n\nattribute vec2 node;\n\nvarying vec2 v_NodeUv;\n\nvoid main() {\n\n v_NodeUv = node;\n gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n gl_PointSize = 1.0;\n}\n@end\n\n@export ecgl.forceAtlas2.calcWeightedSum.fragment\n\nvarying vec2 v_NodeUv;\n\nuniform sampler2D positionTex;\nuniform sampler2D forceTex;\nuniform sampler2D forcePrevTex;\n\nvoid main() {\n vec2 force = texture2D(forceTex, v_NodeUv).rg;\n vec2 forcePrev = texture2D(forcePrevTex, v_NodeUv).rg;\n\n float mass = texture2D(positionTex, v_NodeUv).z;\n float swing = length(force - forcePrev) * mass;\n float traction = length(force + forcePrev) * 0.5 * mass;\n\n gl_FragColor = vec4(swing, traction, 0.0, 0.0);\n}\n@end\n\n@export ecgl.forceAtlas2.calcGlobalSpeed\n\nuniform sampler2D globalSpeedPrevTex;\nuniform sampler2D weightedSumTex;\nuniform float jitterTolerence;\n\nvoid main() {\n vec2 weightedSum = texture2D(weightedSumTex, vec2(0.5)).xy;\n float prevGlobalSpeed = texture2D(globalSpeedPrevTex, vec2(0.5)).x;\n float globalSpeed = jitterTolerence * jitterTolerence\n * weightedSum.y / weightedSum.x;\n if (prevGlobalSpeed > 0.0) {\n globalSpeed = min(globalSpeed / prevGlobalSpeed, 1.5) * prevGlobalSpeed;\n }\n gl_FragColor = vec4(globalSpeed, 0.0, 0.0, 1.0);\n}\n@end\n\n@export ecgl.forceAtlas2.updatePosition\n\nuniform sampler2D forceTex;\nuniform sampler2D forcePrevTex;\nuniform sampler2D positionTex;\nuniform sampler2D globalSpeedTex;\n\nvarying vec2 v_Texcoord;\n\nvoid main() {\n vec2 force = texture2D(forceTex, v_Texcoord).xy;\n vec2 forcePrev = texture2D(forcePrevTex, v_Texcoord).xy;\n vec4 node = texture2D(positionTex, v_Texcoord);\n\n float globalSpeed = texture2D(globalSpeedTex, vec2(0.5)).r;\n float swing = length(force - forcePrev);\n float speed = 0.1 * globalSpeed / (0.1 + globalSpeed * sqrt(swing));\n\n float df = length(force);\n if (df > 0.0) {\n speed = min(df * speed, 10.0) / df;\n\n gl_FragColor = vec4(node.xy + speed * force, node.zw);\n }\n else {\n gl_FragColor = node;\n }\n}\n@end\n\n@export ecgl.forceAtlas2.edges.vertex\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec2 node;\nattribute vec4 a_Color : COLOR;\nvarying vec4 v_Color;\n\nuniform sampler2D positionTex;\n\nvoid main()\n{\n gl_Position = worldViewProjection * vec4(\n texture2D(positionTex, node).xy, -10.0, 1.0\n );\n v_Color = a_Color;\n}\n@end\n\n@export ecgl.forceAtlas2.edges.fragment\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\nvarying vec4 v_Color;\nvoid main() {\n gl_FragColor = color * v_Color;\n}\n@end");
  46147. /***/
  46148. }),
  46149. /* 271 */
  46150. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  46151. "use strict";
  46152. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_claygl_src_Texture2D__ = __webpack_require__(5);
  46153. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_Texture__ = __webpack_require__(4);
  46154. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__forceAtlas2Worker_js__ = __webpack_require__(272);
  46155. var workerUrl = __WEBPACK_IMPORTED_MODULE_2__forceAtlas2Worker_js__["a" /* default */].toString();
  46156. workerUrl = workerUrl.slice(workerUrl.indexOf('{') + 1, workerUrl.lastIndexOf('}'));
  46157. var defaultConfigs = {
  46158. barnesHutOptimize: true,
  46159. barnesHutTheta: 1.5,
  46160. repulsionByDegree: true,
  46161. linLogMode: false,
  46162. strongGravityMode: false,
  46163. gravity: 1.0,
  46164. scaling: 1.0,
  46165. edgeWeightInfluence: 1.0,
  46166. jitterTolerence: 0.1,
  46167. preventOverlap: false,
  46168. dissuadeHubs: false,
  46169. gravityCenter: null
  46170. };
  46171. var ForceAtlas2 = function (options) {
  46172. for (var name in defaultConfigs) {
  46173. this[name] = defaultConfigs[name];
  46174. }
  46175. if (options) {
  46176. for (var name in options) {
  46177. this[name] = options[name];
  46178. }
  46179. }
  46180. this._nodes = [];
  46181. this._edges = [];
  46182. this._disposed = false;
  46183. this._positionTex = new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Texture2D__["a" /* default */]({
  46184. type: __WEBPACK_IMPORTED_MODULE_1_claygl_src_Texture__["a" /* default */].FLOAT,
  46185. flipY: false,
  46186. minFilter: __WEBPACK_IMPORTED_MODULE_1_claygl_src_Texture__["a" /* default */].NEAREST,
  46187. magFilter: __WEBPACK_IMPORTED_MODULE_1_claygl_src_Texture__["a" /* default */].NEAREST
  46188. });
  46189. };
  46190. ForceAtlas2.prototype.initData = function (nodes, edges) {
  46191. var bb = new Blob([workerUrl]);
  46192. var blobURL = window.URL.createObjectURL(bb);
  46193. this._worker = new Worker(blobURL);
  46194. this._worker.onmessage = this._$onupdate.bind(this);
  46195. this._nodes = nodes;
  46196. this._edges = edges;
  46197. this._frame = 0;
  46198. var nNodes = nodes.length;
  46199. var nEdges = edges.length;
  46200. var positionArr = new Float32Array(nNodes * 2);
  46201. var massArr = new Float32Array(nNodes);
  46202. var sizeArr = new Float32Array(nNodes);
  46203. var edgeArr = new Float32Array(nEdges * 2);
  46204. var edgeWeightArr = new Float32Array(nEdges);
  46205. for (var i = 0; i < nodes.length; i++) {
  46206. var node = nodes[i];
  46207. positionArr[i * 2] = node.x;
  46208. positionArr[i * 2 + 1] = node.y;
  46209. massArr[i] = node.mass == null ? 1 : node.mass;
  46210. sizeArr[i] = node.size == null ? 1 : node.size;
  46211. }
  46212. for (var i = 0; i < edges.length; i++) {
  46213. var edge = edges[i];
  46214. var source = edge.node1;
  46215. var target = edge.node2;
  46216. edgeArr[i * 2] = source;
  46217. edgeArr[i * 2 + 1] = target;
  46218. edgeWeightArr[i] = edge.weight == null ? 1 : edge.weight;
  46219. }
  46220. var textureWidth = Math.ceil(Math.sqrt(nodes.length));
  46221. var textureHeight = textureWidth;
  46222. var pixels = new Float32Array(textureWidth * textureHeight * 4);
  46223. var positionTex = this._positionTex;
  46224. positionTex.width = textureWidth;
  46225. positionTex.height = textureHeight;
  46226. positionTex.pixels = pixels;
  46227. this._worker.postMessage({
  46228. cmd: 'init',
  46229. nodesPosition: positionArr,
  46230. nodesMass: massArr,
  46231. nodesSize: sizeArr,
  46232. edges: edgeArr,
  46233. edgesWeight: edgeWeightArr
  46234. });
  46235. this._globalSpeed = Infinity;
  46236. };
  46237. ForceAtlas2.prototype.updateOption = function (options) {
  46238. var config = {};
  46239. // Default config
  46240. for (var name in defaultConfigs) {
  46241. config[name] = defaultConfigs[name];
  46242. }
  46243. var nodes = this._nodes;
  46244. var edges = this._edges;
  46245. // Config according to data scale
  46246. var nNodes = nodes.length;
  46247. if (nNodes > 50000) {
  46248. config.jitterTolerence = 10;
  46249. }
  46250. else if (nNodes > 5000) {
  46251. config.jitterTolerence = 1;
  46252. }
  46253. else {
  46254. config.jitterTolerence = 0.1;
  46255. }
  46256. if (nNodes > 100) {
  46257. config.scaling = 2.0;
  46258. }
  46259. else {
  46260. config.scaling = 10.0;
  46261. }
  46262. if (nNodes > 1000) {
  46263. config.barnesHutOptimize = true;
  46264. }
  46265. else {
  46266. config.barnesHutOptimize = false;
  46267. }
  46268. if (options) {
  46269. for (var name in defaultConfigs) {
  46270. if (options[name] != null) {
  46271. config[name] = options[name];
  46272. }
  46273. }
  46274. }
  46275. if (!config.gravityCenter) {
  46276. var min = [Infinity, Infinity];
  46277. var max = [-Infinity, -Infinity];
  46278. for (var i = 0; i < nodes.length; i++) {
  46279. min[0] = Math.min(nodes[i].x, min[0]);
  46280. min[1] = Math.min(nodes[i].y, min[1]);
  46281. max[0] = Math.max(nodes[i].x, max[0]);
  46282. max[1] = Math.max(nodes[i].y, max[1]);
  46283. }
  46284. config.gravityCenter = [(min[0] + max[0]) * 0.5, (min[1] + max[1]) * 0.5];
  46285. }
  46286. // Update inDegree, outDegree
  46287. for (var i = 0; i < edges.length; i++) {
  46288. var node1 = edges[i].node1;
  46289. var node2 = edges[i].node2;
  46290. nodes[node1].degree = (nodes[node1].degree || 0) + 1;
  46291. nodes[node2].degree = (nodes[node2].degree || 0) + 1;
  46292. }
  46293. if (this._worker) {
  46294. this._worker.postMessage({
  46295. cmd: 'updateConfig',
  46296. config: config
  46297. });
  46298. }
  46299. };
  46300. // Steps per call, to keep sync with rendering
  46301. ForceAtlas2.prototype.update = function (renderer, steps, cb) {
  46302. if (steps == null) {
  46303. steps = 1;
  46304. }
  46305. steps = Math.max(steps, 1);
  46306. this._frame += steps;
  46307. this._onupdate = cb;
  46308. if (this._worker) {
  46309. this._worker.postMessage({
  46310. cmd: 'update',
  46311. steps: Math.round(steps)
  46312. });
  46313. }
  46314. };
  46315. ForceAtlas2.prototype._$onupdate = function (e) {
  46316. // Incase the worker keep postMessage of last frame after it is disposed
  46317. if (this._disposed) {
  46318. return;
  46319. }
  46320. var positionArr = new Float32Array(e.data.buffer);
  46321. this._globalSpeed = e.data.globalSpeed;
  46322. this._positionArr = positionArr;
  46323. this._updateTexture(positionArr);
  46324. this._onupdate && this._onupdate();
  46325. };
  46326. ForceAtlas2.prototype.getNodePositionTexture = function () {
  46327. return this._positionTex;
  46328. };
  46329. ForceAtlas2.prototype.getNodeUV = function (nodeIndex, uv) {
  46330. uv = uv || [];
  46331. var textureWidth = this._positionTex.width;
  46332. var textureHeight = this._positionTex.height;
  46333. uv[0] = (nodeIndex % textureWidth) / (textureWidth - 1);
  46334. uv[1] = Math.floor(nodeIndex / textureWidth) / (textureHeight - 1);
  46335. return uv;
  46336. };
  46337. ForceAtlas2.prototype.getNodes = function () {
  46338. return this._nodes;
  46339. };
  46340. ForceAtlas2.prototype.getEdges = function () {
  46341. return this._edges;
  46342. };
  46343. ForceAtlas2.prototype.isFinished = function (maxSteps) {
  46344. return this._frame > maxSteps;
  46345. };
  46346. ForceAtlas2.prototype.getNodePosition = function (renderer, out) {
  46347. if (!out) {
  46348. out = new Float32Array(this._nodes.length * 2);
  46349. }
  46350. if (this._positionArr) {
  46351. for (var i = 0; i < this._positionArr.length; i++) {
  46352. out[i] = this._positionArr[i];
  46353. }
  46354. }
  46355. return out;
  46356. };
  46357. ForceAtlas2.prototype._updateTexture = function (positionArr) {
  46358. var pixels = this._positionTex.pixels;
  46359. var offset = 0;
  46360. for (var i = 0; i < positionArr.length;) {
  46361. pixels[offset++] = positionArr[i++];
  46362. pixels[offset++] = positionArr[i++];
  46363. pixels[offset++] = 1;
  46364. pixels[offset++] = 1;
  46365. }
  46366. this._positionTex.dirty();
  46367. };
  46368. ForceAtlas2.prototype.dispose = function (renderer) {
  46369. this._disposed = true;
  46370. this._worker = null;
  46371. };
  46372. /* harmony default export */ __webpack_exports__["a"] = (ForceAtlas2);
  46373. /***/
  46374. }),
  46375. /* 272 */
  46376. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  46377. "use strict";
  46378. /****************************
  46379. * Vector2 math functions
  46380. ***************************/
  46381. function forceAtlas2Worker() {
  46382. var vec2 = {
  46383. create: function () {
  46384. return new Float32Array(2);
  46385. },
  46386. dist: function (a, b) {
  46387. var x = b[0] - a[0];
  46388. var y = b[1] - a[1];
  46389. return Math.sqrt(x * x + y * y);
  46390. },
  46391. len: function (a) {
  46392. var x = a[0];
  46393. var y = a[1];
  46394. return Math.sqrt(x * x + y * y);
  46395. },
  46396. scaleAndAdd: function (out, a, b, scale) {
  46397. out[0] = a[0] + b[0] * scale;
  46398. out[1] = a[1] + b[1] * scale;
  46399. return out;
  46400. },
  46401. scale: function (out, a, b) {
  46402. out[0] = a[0] * b;
  46403. out[1] = a[1] * b;
  46404. return out;
  46405. },
  46406. add: function (out, a, b) {
  46407. out[0] = a[0] + b[0];
  46408. out[1] = a[1] + b[1];
  46409. return out;
  46410. },
  46411. sub: function (out, a, b) {
  46412. out[0] = a[0] - b[0];
  46413. out[1] = a[1] - b[1];
  46414. return out;
  46415. },
  46416. normalize: function (out, a) {
  46417. var x = a[0];
  46418. var y = a[1];
  46419. var len = x * x + y * y;
  46420. if (len > 0) {
  46421. //TODO: evaluate use of glm_invsqrt here?
  46422. len = 1 / Math.sqrt(len);
  46423. out[0] = a[0] * len;
  46424. out[1] = a[1] * len;
  46425. }
  46426. return out;
  46427. },
  46428. negate: function (out, a) {
  46429. out[0] = -a[0];
  46430. out[1] = -a[1];
  46431. return out;
  46432. },
  46433. copy: function (out, a) {
  46434. out[0] = a[0];
  46435. out[1] = a[1];
  46436. return out;
  46437. },
  46438. set: function (out, x, y) {
  46439. out[0] = x;
  46440. out[1] = y;
  46441. return out;
  46442. }
  46443. }
  46444. /****************************
  46445. * Class: Region
  46446. ***************************/
  46447. function Region() {
  46448. this.subRegions = [];
  46449. this.nSubRegions = 0;
  46450. this.node = null;
  46451. this.mass = 0;
  46452. this.centerOfMass = null;
  46453. this.bbox = new Float32Array(4);
  46454. this.size = 0;
  46455. }
  46456. var regionProto = Region.prototype;
  46457. // Reset before update
  46458. regionProto.beforeUpdate = function () {
  46459. for (var i = 0; i < this.nSubRegions; i++) {
  46460. this.subRegions[i].beforeUpdate();
  46461. }
  46462. this.mass = 0;
  46463. if (this.centerOfMass) {
  46464. this.centerOfMass[0] = 0;
  46465. this.centerOfMass[1] = 0;
  46466. }
  46467. this.nSubRegions = 0;
  46468. this.node = null;
  46469. };
  46470. // Clear after update
  46471. regionProto.afterUpdate = function () {
  46472. this.subRegions.length = this.nSubRegions;
  46473. for (var i = 0; i < this.nSubRegions; i++) {
  46474. this.subRegions[i].afterUpdate();
  46475. }
  46476. };
  46477. regionProto.addNode = function (node) {
  46478. if (this.nSubRegions === 0) {
  46479. if (this.node == null) {
  46480. this.node = node;
  46481. return;
  46482. }
  46483. // Already have node, subdivide self.
  46484. else {
  46485. this._addNodeToSubRegion(this.node);
  46486. this.node = null;
  46487. }
  46488. }
  46489. this._addNodeToSubRegion(node);
  46490. this._updateCenterOfMass(node);
  46491. };
  46492. regionProto.findSubRegion = function (x, y) {
  46493. for (var i = 0; i < this.nSubRegions; i++) {
  46494. var region = this.subRegions[i];
  46495. if (region.contain(x, y)) {
  46496. return region;
  46497. }
  46498. }
  46499. };
  46500. regionProto.contain = function (x, y) {
  46501. return this.bbox[0] <= x
  46502. && this.bbox[2] >= x
  46503. && this.bbox[1] <= y
  46504. && this.bbox[3] >= y;
  46505. };
  46506. regionProto.setBBox = function (minX, minY, maxX, maxY) {
  46507. // Min
  46508. this.bbox[0] = minX;
  46509. this.bbox[1] = minY;
  46510. // Max
  46511. this.bbox[2] = maxX;
  46512. this.bbox[3] = maxY;
  46513. this.size = (maxX - minX + maxY - minY) / 2;
  46514. };
  46515. regionProto._newSubRegion = function () {
  46516. var subRegion = this.subRegions[this.nSubRegions];
  46517. if (!subRegion) {
  46518. subRegion = new Region();
  46519. this.subRegions[this.nSubRegions] = subRegion;
  46520. }
  46521. this.nSubRegions++;
  46522. return subRegion;
  46523. };
  46524. regionProto._addNodeToSubRegion = function (node) {
  46525. var subRegion = this.findSubRegion(node.position[0], node.position[1]);
  46526. var bbox = this.bbox;
  46527. if (!subRegion) {
  46528. var cx = (bbox[0] + bbox[2]) / 2;
  46529. var cy = (bbox[1] + bbox[3]) / 2;
  46530. var w = (bbox[2] - bbox[0]) / 2;
  46531. var h = (bbox[3] - bbox[1]) / 2;
  46532. var xi = node.position[0] >= cx ? 1 : 0;
  46533. var yi = node.position[1] >= cy ? 1 : 0;
  46534. var subRegion = this._newSubRegion();
  46535. // Min
  46536. subRegion.setBBox(
  46537. // Min
  46538. xi * w + bbox[0],
  46539. yi * h + bbox[1],
  46540. // Max
  46541. (xi + 1) * w + bbox[0],
  46542. (yi + 1) * h + bbox[1]
  46543. );
  46544. }
  46545. subRegion.addNode(node);
  46546. };
  46547. regionProto._updateCenterOfMass = function (node) {
  46548. // Incrementally update
  46549. if (this.centerOfMass == null) {
  46550. this.centerOfMass = new Float32Array(2);
  46551. }
  46552. var x = this.centerOfMass[0] * this.mass;
  46553. var y = this.centerOfMass[1] * this.mass;
  46554. x += node.position[0] * node.mass;
  46555. y += node.position[1] * node.mass;
  46556. this.mass += node.mass;
  46557. this.centerOfMass[0] = x / this.mass;
  46558. this.centerOfMass[1] = y / this.mass;
  46559. };
  46560. /****************************
  46561. * Class: Graph Node
  46562. ***************************/
  46563. function GraphNode() {
  46564. this.position = new Float32Array(2);
  46565. this.force = vec2.create();
  46566. this.forcePrev = vec2.create();
  46567. // If repulsionByDegree is true
  46568. // mass = inDegree + outDegree + 1
  46569. // Else
  46570. // mass is manually set
  46571. this.mass = 1;
  46572. this.inDegree = 0;
  46573. this.outDegree = 0;
  46574. // Optional
  46575. // this.size = 1;
  46576. }
  46577. /****************************
  46578. * Class: Graph Edge
  46579. ***************************/
  46580. function GraphEdge(source, target) {
  46581. this.source = source;
  46582. this.target = target;
  46583. this.weight = 1;
  46584. }
  46585. /****************************
  46586. * Class: ForceStlas2
  46587. ***************************/
  46588. function ForceAtlas2() {
  46589. //-------------
  46590. // Configs
  46591. // If auto settings is true
  46592. // barnesHutOptimize,
  46593. // barnesHutTheta,
  46594. // scaling,
  46595. // jitterTolerence
  46596. // Will be set by the system automatically
  46597. // preventOverlap will be set false
  46598. // if node size is not given
  46599. this.autoSettings = true;
  46600. // Barnes Hut
  46601. // http://arborjs.org/docs/barnes-hut
  46602. this.barnesHutOptimize = true;
  46603. this.barnesHutTheta = 1.5;
  46604. // Force Atlas2 Configs
  46605. this.repulsionByDegree = true;
  46606. this.linLogMode = false;
  46607. this.strongGravityMode = false;
  46608. this.gravity = 1.0;
  46609. this.scaling = 1.0;
  46610. this.edgeWeightInfluence = 1.0;
  46611. this.jitterTolerence = 0.1;
  46612. // TODO
  46613. this.preventOverlap = false;
  46614. this.dissuadeHubs = false;
  46615. //
  46616. this.rootRegion = new Region();
  46617. this.rootRegion.centerOfMass = vec2.create();
  46618. this.nodes = [];
  46619. this.edges = [];
  46620. this.bbox = new Float32Array(4);
  46621. this.gravityCenter = null;
  46622. this._massArr = null;
  46623. this._swingingArr = null;
  46624. this._sizeArr = null;
  46625. this._globalSpeed = 0;
  46626. }
  46627. var forceAtlas2Proto = ForceAtlas2.prototype;
  46628. forceAtlas2Proto.initNodes = function (positionArr, massArr, sizeArr) {
  46629. var nNodes = massArr.length;
  46630. this.nodes.length = 0;
  46631. var haveSize = typeof (sizeArr) != 'undefined';
  46632. for (var i = 0; i < nNodes; i++) {
  46633. var node = new GraphNode();
  46634. node.position[0] = positionArr[i * 2];
  46635. node.position[1] = positionArr[i * 2 + 1];
  46636. node.mass = massArr[i];
  46637. if (haveSize) {
  46638. node.size = sizeArr[i];
  46639. }
  46640. this.nodes.push(node);
  46641. }
  46642. this._massArr = massArr;
  46643. this._swingingArr = new Float32Array(nNodes);
  46644. if (haveSize) {
  46645. this._sizeArr = sizeArr;
  46646. }
  46647. };
  46648. forceAtlas2Proto.initEdges = function (edgeArr, edgeWeightArr) {
  46649. var nEdges = edgeArr.length / 2;
  46650. this.edges.length = 0;
  46651. for (var i = 0; i < nEdges; i++) {
  46652. var sIdx = edgeArr[i * 2];
  46653. var tIdx = edgeArr[i * 2 + 1];
  46654. var sNode = this.nodes[sIdx];
  46655. var tNode = this.nodes[tIdx];
  46656. if (!sNode || !tNode) {
  46657. console.error('Node not exists, try initNodes before initEdges');
  46658. return;
  46659. }
  46660. sNode.outDegree++;
  46661. tNode.inDegree++;
  46662. var edge = new GraphEdge(sNode, tNode);
  46663. if (edgeWeightArr) {
  46664. edge.weight = edgeWeightArr[i];
  46665. }
  46666. this.edges.push(edge);
  46667. }
  46668. }
  46669. forceAtlas2Proto.updateSettings = function () {
  46670. if (this.repulsionByDegree) {
  46671. for (var i = 0; i < this.nodes.length; i++) {
  46672. var node = this.nodes[i];
  46673. node.mass = node.inDegree + node.outDegree + 1;
  46674. }
  46675. }
  46676. else {
  46677. for (var i = 0; i < this.nodes.length; i++) {
  46678. var node = this.nodes[i];
  46679. node.mass = this._massArr[i];
  46680. }
  46681. }
  46682. };
  46683. forceAtlas2Proto.update = function () {
  46684. var nNodes = this.nodes.length;
  46685. this.updateSettings();
  46686. this.updateBBox();
  46687. // Update region
  46688. if (this.barnesHutOptimize) {
  46689. this.rootRegion.setBBox(
  46690. this.bbox[0], this.bbox[1],
  46691. this.bbox[2], this.bbox[3]
  46692. );
  46693. this.rootRegion.beforeUpdate();
  46694. for (var i = 0; i < nNodes; i++) {
  46695. this.rootRegion.addNode(this.nodes[i]);
  46696. }
  46697. this.rootRegion.afterUpdate();
  46698. }
  46699. // Reset forces
  46700. for (var i = 0; i < nNodes; i++) {
  46701. var node = this.nodes[i];
  46702. vec2.copy(node.forcePrev, node.force);
  46703. vec2.set(node.force, 0, 0);
  46704. }
  46705. // Compute forces
  46706. // Repulsion
  46707. for (var i = 0; i < nNodes; i++) {
  46708. var na = this.nodes[i];
  46709. if (this.barnesHutOptimize) {
  46710. this.applyRegionToNodeRepulsion(this.rootRegion, na);
  46711. }
  46712. else {
  46713. for (var j = i + 1; j < nNodes; j++) {
  46714. var nb = this.nodes[j];
  46715. this.applyNodeToNodeRepulsion(na, nb, false);
  46716. }
  46717. }
  46718. // Gravity
  46719. if (this.gravity > 0) {
  46720. if (this.strongGravityMode) {
  46721. this.applyNodeStrongGravity(na);
  46722. }
  46723. else {
  46724. this.applyNodeGravity(na);
  46725. }
  46726. }
  46727. }
  46728. // Attraction
  46729. for (var i = 0; i < this.edges.length; i++) {
  46730. this.applyEdgeAttraction(this.edges[i]);
  46731. }
  46732. // Handle swinging
  46733. var swingWeightedSum = 0;
  46734. var tractionWeightedSum = 0;
  46735. var tmp = vec2.create();
  46736. for (var i = 0; i < nNodes; i++) {
  46737. var node = this.nodes[i];
  46738. var swing = vec2.dist(node.force, node.forcePrev);
  46739. swingWeightedSum += swing * node.mass;
  46740. vec2.add(tmp, node.force, node.forcePrev);
  46741. var traction = vec2.len(tmp) * 0.5;
  46742. tractionWeightedSum += traction * node.mass;
  46743. // Save the value for using later
  46744. this._swingingArr[i] = swing;
  46745. }
  46746. var globalSpeed = this.jitterTolerence * this.jitterTolerence
  46747. * tractionWeightedSum / swingWeightedSum;
  46748. // NB: During our tests we observed that an excessive rise of the global speed could have a negative impact.
  46749. // That’s why we limited the increase of global speed s(t)(G) to 50% of the previous step s(t−1)(G).
  46750. if (this._globalSpeed > 0) {
  46751. globalSpeed = Math.min(globalSpeed / this._globalSpeed, 1.5) * this._globalSpeed;
  46752. }
  46753. this._globalSpeed = globalSpeed;
  46754. // Apply forces
  46755. for (var i = 0; i < nNodes; i++) {
  46756. var node = this.nodes[i];
  46757. var swing = this._swingingArr[i];
  46758. var speed = 0.1 * globalSpeed / (1 + globalSpeed * Math.sqrt(swing));
  46759. // Additional constraint to prevent local speed gets too high
  46760. var df = vec2.len(node.force);
  46761. if (df > 0) {
  46762. speed = Math.min(df * speed, 10) / df;
  46763. vec2.scaleAndAdd(node.position, node.position, node.force, speed);
  46764. }
  46765. }
  46766. };
  46767. forceAtlas2Proto.applyRegionToNodeRepulsion = (function () {
  46768. var v = vec2.create();
  46769. return function applyRegionToNodeRepulsion(region, node) {
  46770. if (region.node) { // Region is a leaf
  46771. this.applyNodeToNodeRepulsion(region.node, node, true);
  46772. }
  46773. else {
  46774. vec2.sub(v, node.position, region.centerOfMass);
  46775. var d2 = v[0] * v[0] + v[1] * v[1];
  46776. if (d2 > this.barnesHutTheta * region.size * region.size) {
  46777. var factor = this.scaling * node.mass * region.mass / d2;
  46778. vec2.scaleAndAdd(node.force, node.force, v, factor);
  46779. }
  46780. else {
  46781. for (var i = 0; i < region.nSubRegions; i++) {
  46782. this.applyRegionToNodeRepulsion(region.subRegions[i], node);
  46783. }
  46784. }
  46785. }
  46786. }
  46787. })();
  46788. forceAtlas2Proto.applyNodeToNodeRepulsion = (function () {
  46789. var v = vec2.create();
  46790. return function applyNodeToNodeRepulsion(na, nb, oneWay) {
  46791. if (na == nb) {
  46792. return;
  46793. }
  46794. vec2.sub(v, na.position, nb.position);
  46795. var d2 = v[0] * v[0] + v[1] * v[1];
  46796. // PENDING
  46797. if (d2 === 0) {
  46798. return;
  46799. }
  46800. var factor;
  46801. if (this.preventOverlap) {
  46802. var d = Math.sqrt(d2);
  46803. d = d - na.size - nb.size;
  46804. if (d > 0) {
  46805. factor = this.scaling * na.mass * nb.mass / (d * d);
  46806. }
  46807. else if (d < 0) {
  46808. // A stronger repulsion if overlap
  46809. factor = this.scaling * 100 * na.mass * nb.mass;
  46810. }
  46811. else {
  46812. // No repulsion
  46813. return;
  46814. }
  46815. }
  46816. else {
  46817. // Divide factor by an extra `d` to normalize the `v`
  46818. factor = this.scaling * na.mass * nb.mass / d2;
  46819. }
  46820. vec2.scaleAndAdd(na.force, na.force, v, factor);
  46821. vec2.scaleAndAdd(nb.force, nb.force, v, -factor);
  46822. }
  46823. })();
  46824. forceAtlas2Proto.applyEdgeAttraction = (function () {
  46825. var v = vec2.create();
  46826. return function applyEdgeAttraction(edge) {
  46827. var na = edge.source;
  46828. var nb = edge.target;
  46829. vec2.sub(v, na.position, nb.position);
  46830. var d = vec2.len(v);
  46831. var w;
  46832. if (this.edgeWeightInfluence === 0) {
  46833. w = 1;
  46834. }
  46835. else if (this.edgeWeightInfluence === 1) {
  46836. w = edge.weight;
  46837. }
  46838. else {
  46839. w = Math.pow(edge.weight, this.edgeWeightInfluence);
  46840. }
  46841. var factor;
  46842. if (this.preventOverlap) {
  46843. d = d - na.size - nb.size;
  46844. if (d <= 0) {
  46845. // No attraction
  46846. return;
  46847. }
  46848. }
  46849. if (this.linLogMode) {
  46850. // Divide factor by an extra `d` to normalize the `v`
  46851. factor = - w * Math.log(d + 1) / (d + 1);
  46852. }
  46853. else {
  46854. factor = - w;
  46855. }
  46856. vec2.scaleAndAdd(na.force, na.force, v, factor);
  46857. vec2.scaleAndAdd(nb.force, nb.force, v, -factor);
  46858. }
  46859. })();
  46860. forceAtlas2Proto.applyNodeGravity = (function () {
  46861. var v = vec2.create();
  46862. return function (node) {
  46863. vec2.sub(v, this.gravityCenter, node.position);
  46864. var d = vec2.len(v);
  46865. vec2.scaleAndAdd(node.force, node.force, v, this.gravity * node.mass / (d + 1));
  46866. }
  46867. })();
  46868. forceAtlas2Proto.applyNodeStrongGravity = (function () {
  46869. var v = vec2.create();
  46870. return function (node) {
  46871. vec2.sub(v, this.gravityCenter, node.position);
  46872. vec2.scaleAndAdd(node.force, node.force, v, this.gravity * node.mass);
  46873. }
  46874. })();
  46875. forceAtlas2Proto.updateBBox = function () {
  46876. var minX = Infinity;
  46877. var minY = Infinity;
  46878. var maxX = -Infinity;
  46879. var maxY = -Infinity;
  46880. for (var i = 0; i < this.nodes.length; i++) {
  46881. var pos = this.nodes[i].position;
  46882. minX = Math.min(minX, pos[0]);
  46883. minY = Math.min(minY, pos[1]);
  46884. maxX = Math.max(maxX, pos[0]);
  46885. maxY = Math.max(maxY, pos[1]);
  46886. }
  46887. this.bbox[0] = minX;
  46888. this.bbox[1] = minY;
  46889. this.bbox[2] = maxX;
  46890. this.bbox[3] = maxY;
  46891. };
  46892. forceAtlas2Proto.getGlobalSpeed = function () {
  46893. return this._globalSpeed;
  46894. }
  46895. /****************************
  46896. * Main process
  46897. ***************************/
  46898. var forceAtlas2 = null;
  46899. self.onmessage = function (e) {
  46900. switch (e.data.cmd) {
  46901. case 'init':
  46902. forceAtlas2 = new ForceAtlas2();
  46903. forceAtlas2.initNodes(e.data.nodesPosition, e.data.nodesMass, e.data.nodesSize);
  46904. forceAtlas2.initEdges(e.data.edges, e.data.edgesWeight);
  46905. break;
  46906. case 'updateConfig':
  46907. if (forceAtlas2) {
  46908. for (var name in e.data.config) {
  46909. forceAtlas2[name] = e.data.config[name];
  46910. }
  46911. }
  46912. break;
  46913. case 'update':
  46914. var steps = e.data.steps;
  46915. if (forceAtlas2) {
  46916. for (var i = 0; i < steps; i++) {
  46917. forceAtlas2.update();
  46918. }
  46919. var nNodes = forceAtlas2.nodes.length;
  46920. var positionArr = new Float32Array(nNodes * 2);
  46921. // Callback
  46922. for (var i = 0; i < nNodes; i++) {
  46923. var node = forceAtlas2.nodes[i];
  46924. positionArr[i * 2] = node.position[0];
  46925. positionArr[i * 2 + 1] = node.position[1];
  46926. }
  46927. self.postMessage({
  46928. buffer: positionArr.buffer,
  46929. globalSpeed: forceAtlas2.getGlobalSpeed()
  46930. }, [positionArr.buffer]);
  46931. }
  46932. else {
  46933. // Not initialzied yet
  46934. var emptyArr = new Float32Array();
  46935. // Post transfer object
  46936. self.postMessage({
  46937. buffer: emptyArr.buffer,
  46938. globalSpeed: forceAtlas2.getGlobalSpeed()
  46939. }, [emptyArr.buffer]);
  46940. }
  46941. break;
  46942. }
  46943. }
  46944. }
  46945. /* harmony default export */ __webpack_exports__["a"] = (forceAtlas2Worker);
  46946. /***/
  46947. }),
  46948. /* 273 */
  46949. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  46950. "use strict";
  46951. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_claygl_src_core_Base__ = __webpack_require__(7);
  46952. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__retrieve__ = __webpack_require__(2);
  46953. /**
  46954. * @alias module:echarts-gl/util/Roam2DControl
  46955. */
  46956. var Roam2DControl = __WEBPACK_IMPORTED_MODULE_0_claygl_src_core_Base__["a" /* default */].extend(function () {
  46957. return {
  46958. /**
  46959. * @type {module:zrender~ZRender}
  46960. */
  46961. zr: null,
  46962. /**
  46963. * @type {module:echarts-gl/core/ViewGL}
  46964. */
  46965. viewGL: null,
  46966. minZoom: 0.2,
  46967. maxZoom: 5,
  46968. _needsUpdate: false,
  46969. _dx: 0,
  46970. _dy: 0,
  46971. _zoom: 1
  46972. };
  46973. }, function () {
  46974. // Each Roam2DControl has it's own handler
  46975. this._mouseDownHandler = this._mouseDownHandler.bind(this);
  46976. this._mouseWheelHandler = this._mouseWheelHandler.bind(this);
  46977. this._mouseMoveHandler = this._mouseMoveHandler.bind(this);
  46978. this._mouseUpHandler = this._mouseUpHandler.bind(this);
  46979. this._update = this._update.bind(this);
  46980. }, {
  46981. init: function () {
  46982. var zr = this.zr;
  46983. zr.on('mousedown', this._mouseDownHandler);
  46984. zr.on('mousewheel', this._mouseWheelHandler);
  46985. zr.on('globalout', this._mouseUpHandler);
  46986. zr.animation.on('frame', this._update);
  46987. },
  46988. setTarget: function (target) {
  46989. this._target = target;
  46990. },
  46991. setZoom: function (zoom) {
  46992. this._zoom = Math.max(Math.min(
  46993. zoom, this.maxZoom
  46994. ), this.minZoom);
  46995. this._needsUpdate = true;
  46996. },
  46997. setOffset: function (offset) {
  46998. this._dx = offset[0];
  46999. this._dy = offset[1];
  47000. this._needsUpdate = true;
  47001. },
  47002. getZoom: function () {
  47003. return this._zoom;
  47004. },
  47005. getOffset: function () {
  47006. return [this._dx, this._dy];
  47007. },
  47008. _update: function () {
  47009. if (!this._target) {
  47010. return;
  47011. }
  47012. if (!this._needsUpdate) {
  47013. return;
  47014. }
  47015. var target = this._target;
  47016. var scale = this._zoom;
  47017. target.position.x = this._dx;
  47018. target.position.y = this._dy;
  47019. target.scale.set(scale, scale, scale);
  47020. this.zr.refresh();
  47021. this._needsUpdate = false;
  47022. this.trigger('update');
  47023. },
  47024. _mouseDownHandler: function (e) {
  47025. if (e.target) {
  47026. return;
  47027. }
  47028. var x = e.offsetX;
  47029. var y = e.offsetY;
  47030. if (this.viewGL && !this.viewGL.containPoint(x, y)) {
  47031. return;
  47032. }
  47033. this.zr.on('mousemove', this._mouseMoveHandler);
  47034. this.zr.on('mouseup', this._mouseUpHandler);
  47035. var pos = this._convertPos(x, y);
  47036. this._x = pos.x;
  47037. this._y = pos.y;
  47038. },
  47039. // Convert pos from screen space to viewspace.
  47040. _convertPos: function (x, y) {
  47041. var camera = this.viewGL.camera;
  47042. var viewport = this.viewGL.viewport;
  47043. // PENDING
  47044. return {
  47045. x: (x - viewport.x) / viewport.width * (camera.right - camera.left) + camera.left,
  47046. y: (y - viewport.y) / viewport.height * (camera.bottom - camera.top) + camera.top
  47047. };
  47048. },
  47049. _mouseMoveHandler: function (e) {
  47050. var pos = this._convertPos(e.offsetX, e.offsetY);
  47051. this._dx += pos.x - this._x;
  47052. this._dy += pos.y - this._y;
  47053. this._x = pos.x;
  47054. this._y = pos.y;
  47055. this._needsUpdate = true;
  47056. },
  47057. _mouseUpHandler: function (e) {
  47058. this.zr.off('mousemove', this._mouseMoveHandler);
  47059. this.zr.off('mouseup', this._mouseUpHandler);
  47060. },
  47061. _mouseWheelHandler: function (e) {
  47062. e = e.event;
  47063. var delta = e.wheelDelta // Webkit
  47064. || -e.detail; // Firefox
  47065. if (delta === 0) {
  47066. return;
  47067. }
  47068. var x = e.offsetX;
  47069. var y = e.offsetY;
  47070. if (this.viewGL && !this.viewGL.containPoint(x, y)) {
  47071. return;
  47072. }
  47073. var zoomScale = delta > 0 ? 1.1 : 0.9;
  47074. var newZoom = Math.max(Math.min(
  47075. this._zoom * zoomScale, this.maxZoom
  47076. ), this.minZoom);
  47077. zoomScale = newZoom / this._zoom;
  47078. var pos = this._convertPos(x, y);
  47079. var fixX = (pos.x - this._dx) * (zoomScale - 1);
  47080. var fixY = (pos.y - this._dy) * (zoomScale - 1);
  47081. this._dx -= fixX;
  47082. this._dy -= fixY;
  47083. this._zoom = newZoom;
  47084. this._needsUpdate = true;
  47085. },
  47086. dispose: function () {
  47087. var zr = this.zr;
  47088. zr.off('mousedown', this._mouseDownHandler);
  47089. zr.off('mousemove', this._mouseMoveHandler);
  47090. zr.off('mouseup', this._mouseUpHandler);
  47091. zr.off('mousewheel', this._mouseWheelHandler);
  47092. zr.off('globalout', this._mouseUpHandler);
  47093. zr.animation.off('frame', this._update);
  47094. }
  47095. });
  47096. /* harmony default export */ __webpack_exports__["a"] = (Roam2DControl);
  47097. /***/
  47098. }),
  47099. /* 274 */
  47100. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  47101. "use strict";
  47102. /* harmony default export */ __webpack_exports__["a"] = ("@export ecgl.lines2D.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec2 position: POSITION;\nattribute vec4 a_Color : COLOR;\nvarying vec4 v_Color;\n\n#ifdef POSITIONTEXTURE_ENABLED\nuniform sampler2D positionTexture;\n#endif\n\nvoid main()\n{\n gl_Position = worldViewProjection * vec4(position, -10.0, 1.0);\n\n v_Color = a_Color;\n}\n\n@end\n\n@export ecgl.lines2D.fragment\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\n\nvarying vec4 v_Color;\n\nvoid main()\n{\n gl_FragColor = color * v_Color;\n}\n@end\n\n\n@export ecgl.meshLines2D.vertex\n\nattribute vec2 position: POSITION;\nattribute vec2 normal;\nattribute float offset;\nattribute vec4 a_Color : COLOR;\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform vec4 viewport : VIEWPORT;\n\nvarying vec4 v_Color;\nvarying float v_Miter;\n\nvoid main()\n{\n vec4 p2 = worldViewProjection * vec4(position + normal, -10.0, 1.0);\n gl_Position = worldViewProjection * vec4(position, -10.0, 1.0);\n\n p2.xy /= p2.w;\n gl_Position.xy /= gl_Position.w;\n\n vec2 N = normalize(p2.xy - gl_Position.xy);\n gl_Position.xy += N * offset / viewport.zw * 2.0;\n\n gl_Position.xy *= gl_Position.w;\n\n v_Color = a_Color;\n}\n@end\n\n\n@export ecgl.meshLines2D.fragment\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\n\nvarying vec4 v_Color;\nvarying float v_Miter;\n\nvoid main()\n{\n gl_FragColor = color * v_Color;\n}\n\n@end");
  47103. /***/
  47104. }),
  47105. /* 275 */
  47106. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  47107. "use strict";
  47108. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  47109. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  47110. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__flowGL_FlowGLView__ = __webpack_require__(276);
  47111. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__flowGL_FlowGLSeries__ = __webpack_require__(280);
  47112. /***/
  47113. }),
  47114. /* 276 */
  47115. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  47116. "use strict";
  47117. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  47118. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  47119. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__ = __webpack_require__(1);
  47120. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_retrieve__ = __webpack_require__(2);
  47121. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__core_ViewGL__ = __webpack_require__(22);
  47122. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__VectorFieldParticleSurface__ = __webpack_require__(277);
  47123. // TODO 百度地图不是 linear 的
  47124. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendChartView({
  47125. type: 'flowGL',
  47126. __ecgl__: true,
  47127. init: function (ecModel, api) {
  47128. this.viewGL = new __WEBPACK_IMPORTED_MODULE_3__core_ViewGL__["a" /* default */]('orthographic');
  47129. this.groupGL = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Node();
  47130. this.viewGL.add(this.groupGL);
  47131. this._particleSurface = new __WEBPACK_IMPORTED_MODULE_4__VectorFieldParticleSurface__["a" /* default */]();
  47132. var planeMesh = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh({
  47133. geometry: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].PlaneGeometry(),
  47134. material: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Material({
  47135. shader: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader({
  47136. vertex: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader.source('ecgl.color.vertex'),
  47137. fragment: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Shader.source('ecgl.color.fragment')
  47138. }),
  47139. // Must enable blending and multiply alpha.
  47140. // Or premultipliedAlpha will let the alpha useless.
  47141. transparent: true
  47142. })
  47143. });
  47144. planeMesh.material.enableTexture('diffuseMap');
  47145. this.groupGL.add(planeMesh);
  47146. this._planeMesh = planeMesh;
  47147. },
  47148. render: function (seriesModel, ecModel, api) {
  47149. var particleSurface = this._particleSurface;
  47150. // Set particleType before set others.
  47151. particleSurface.setParticleType(seriesModel.get('particleType'));
  47152. particleSurface.setSupersampling(seriesModel.get('supersampling'));
  47153. this._updateData(seriesModel, api);
  47154. this._updateCamera(api.getWidth(), api.getHeight(), api.getDevicePixelRatio());
  47155. var particleDensity = __WEBPACK_IMPORTED_MODULE_2__util_retrieve__["a" /* default */].firstNotNull(seriesModel.get('particleDensity'), 128);
  47156. particleSurface.setParticleDensity(particleDensity, particleDensity);
  47157. var planeMesh = this._planeMesh;
  47158. var time = +(new Date());
  47159. var self = this;
  47160. var firstFrame = true;
  47161. planeMesh.__percent = 0;
  47162. planeMesh.stopAnimation();
  47163. planeMesh.animate('', { loop: true })
  47164. .when(100000, {
  47165. __percent: 1
  47166. })
  47167. .during(function () {
  47168. var timeNow = + (new Date());
  47169. var dTime = Math.min(timeNow - time, 20);
  47170. time = time + dTime;
  47171. if (self._renderer) {
  47172. particleSurface.update(self._renderer, api, dTime / 1000, firstFrame);
  47173. planeMesh.material.set('diffuseMap', particleSurface.getSurfaceTexture());
  47174. // planeMesh.material.set('diffuseMap', self._particleSurface.vectorFieldTexture);
  47175. }
  47176. firstFrame = false;
  47177. })
  47178. .start();
  47179. var itemStyleModel = seriesModel.getModel('itemStyle');
  47180. var color = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(itemStyleModel.get('color'));
  47181. color[3] *= __WEBPACK_IMPORTED_MODULE_2__util_retrieve__["a" /* default */].firstNotNull(itemStyleModel.get('opacity'), 1);
  47182. planeMesh.material.set('color', color);
  47183. particleSurface.setColorTextureImage(seriesModel.get('colorTexture'), api);
  47184. particleSurface.setParticleSize(seriesModel.get('particleSize'));
  47185. particleSurface.particleSpeedScaling = seriesModel.get('particleSpeed');
  47186. particleSurface.motionBlurFactor = 1.0 - Math.pow(0.1, seriesModel.get('particleTrail'));
  47187. },
  47188. updateTransform: function (seriesModel, ecModel, api) {
  47189. this._updateData(seriesModel, api);
  47190. },
  47191. afterRender: function (globeModel, ecModel, api, layerGL) {
  47192. var renderer = layerGL.renderer;
  47193. this._renderer = renderer;
  47194. },
  47195. _updateData: function (seriesModel, api) {
  47196. var coordSys = seriesModel.coordinateSystem;
  47197. var dims = coordSys.dimensions.map(function (coordDim) {
  47198. return seriesModel.coordDimToDataDim(coordDim)[0];
  47199. });
  47200. var data = seriesModel.getData();
  47201. var xExtent = data.getDataExtent(dims[0]);
  47202. var yExtent = data.getDataExtent(dims[1]);
  47203. var gridWidth = seriesModel.get('gridWidth');
  47204. var gridHeight = seriesModel.get('gridHeight');
  47205. if (gridWidth == null || gridWidth === 'auto') {
  47206. // TODO not accurate.
  47207. var aspect = (xExtent[1] - xExtent[0]) / (yExtent[1] - yExtent[0]);
  47208. gridWidth = Math.round(Math.sqrt(aspect * data.count()));
  47209. }
  47210. if (gridHeight == null || gridHeight === 'auto') {
  47211. gridHeight = Math.ceil(data.count() / gridWidth);
  47212. }
  47213. var vectorFieldTexture = this._particleSurface.vectorFieldTexture;
  47214. // Half Float needs Uint16Array
  47215. var pixels = vectorFieldTexture.pixels;
  47216. if (!pixels || pixels.length !== gridHeight * gridWidth * 4) {
  47217. pixels = vectorFieldTexture.pixels = new Float32Array(gridWidth * gridHeight * 4);
  47218. }
  47219. else {
  47220. for (var i = 0; i < pixels.length; i++) {
  47221. pixels[i] = 0;
  47222. }
  47223. }
  47224. var maxMag = 0;
  47225. var minMag = Infinity;
  47226. var points = new Float32Array(data.count() * 2);
  47227. var offset = 0;
  47228. var bbox = [[Infinity, Infinity], [-Infinity, -Infinity]];
  47229. data.each([dims[0], dims[1], 'vx', 'vy'], function (x, y, vx, vy) {
  47230. var pt = coordSys.dataToPoint([x, y]);
  47231. points[offset++] = pt[0];
  47232. points[offset++] = pt[1];
  47233. bbox[0][0] = Math.min(pt[0], bbox[0][0]);
  47234. bbox[0][1] = Math.min(pt[1], bbox[0][1]);
  47235. bbox[1][0] = Math.max(pt[0], bbox[1][0]);
  47236. bbox[1][1] = Math.max(pt[1], bbox[1][1]);
  47237. var mag = Math.sqrt(vx * vx + vy * vy);
  47238. maxMag = Math.max(maxMag, mag);
  47239. minMag = Math.min(minMag, mag);
  47240. });
  47241. data.each(['vx', 'vy'], function (vx, vy, i) {
  47242. var xPix = Math.round((points[i * 2] - bbox[0][0]) / (bbox[1][0] - bbox[0][0]) * (gridWidth - 1));
  47243. var yPix = gridHeight - 1 - Math.round((points[i * 2 + 1] - bbox[0][1]) / (bbox[1][1] - bbox[0][1]) * (gridHeight - 1));
  47244. var idx = (yPix * gridWidth + xPix) * 4;
  47245. pixels[idx] = (vx / maxMag * 0.5 + 0.5);
  47246. pixels[idx + 1] = (vy / maxMag * 0.5 + 0.5);
  47247. pixels[idx + 3] = 1;
  47248. });
  47249. vectorFieldTexture.width = gridWidth;
  47250. vectorFieldTexture.height = gridHeight;
  47251. if (seriesModel.get('coordinateSystem') === 'bmap') {
  47252. this._fillEmptyPixels(vectorFieldTexture);
  47253. }
  47254. vectorFieldTexture.dirty();
  47255. this._updatePlanePosition(bbox[0], bbox[1], seriesModel, api);
  47256. this._updateGradientTexture(data.getVisual('visualMeta'), [minMag, maxMag]);
  47257. },
  47258. // PENDING Use grid mesh ? or delaunay triangulation?
  47259. _fillEmptyPixels: function (texture) {
  47260. var pixels = texture.pixels;
  47261. var width = texture.width;
  47262. var height = texture.height;
  47263. function fetchPixel(x, y, rg) {
  47264. x = Math.max(Math.min(x, width - 1), 0);
  47265. y = Math.max(Math.min(y, height - 1), 0);
  47266. var idx = (y * (width - 1) + x) * 4;
  47267. if (pixels[idx + 3] === 0) {
  47268. return false;
  47269. }
  47270. rg[0] = pixels[idx];
  47271. rg[1] = pixels[idx + 1];
  47272. return true;
  47273. }
  47274. function addPixel(a, b, out) {
  47275. out[0] = a[0] + b[0];
  47276. out[1] = a[1] + b[1];
  47277. }
  47278. var center = [], left = [], right = [], top = [], bottom = [];
  47279. var weight = 0;
  47280. for (var y = 0; y < height; y++) {
  47281. for (var x = 0; x < width; x++) {
  47282. var idx = (y * (width - 1) + x) * 4;
  47283. if (pixels[idx + 3] === 0) {
  47284. weight = center[0] = center[1] = 0;
  47285. if (fetchPixel(x - 1, y, left)) {
  47286. weight++; addPixel(left, center, center);
  47287. }
  47288. if (fetchPixel(x + 1, y, right)) {
  47289. weight++; addPixel(right, center, center);
  47290. }
  47291. if (fetchPixel(x, y - 1, top)) {
  47292. weight++; addPixel(top, center, center);
  47293. }
  47294. if (fetchPixel(x, y + 1, bottom)) {
  47295. weight++; addPixel(bottom, center, center);
  47296. }
  47297. center[0] /= weight;
  47298. center[1] /= weight;
  47299. // PENDING If overwrite. bilinear interpolation.
  47300. pixels[idx] = center[0];
  47301. pixels[idx + 1] = center[1];
  47302. }
  47303. pixels[idx + 3] = 1;
  47304. }
  47305. }
  47306. },
  47307. _updateGradientTexture: function (visualMeta, magExtent) {
  47308. if (!visualMeta || !visualMeta.length) {
  47309. this._particleSurface.setGradientTexture(null);
  47310. return;
  47311. }
  47312. // TODO Different dimensions
  47313. this._gradientTexture = this._gradientTexture || new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Texture2D({
  47314. image: document.createElement('canvas')
  47315. });
  47316. var gradientTexture = this._gradientTexture;
  47317. var canvas = gradientTexture.image;
  47318. canvas.width = 200;
  47319. canvas.height = 1;
  47320. var ctx = canvas.getContext('2d');
  47321. var gradient = ctx.createLinearGradient(0, 0.5, canvas.width, 0.5);
  47322. visualMeta[0].stops.forEach(function (stop) {
  47323. var offset;
  47324. if (magExtent[1] === magExtent[0]) {
  47325. offset = 0;
  47326. }
  47327. else {
  47328. offset = stop.value / magExtent[1];
  47329. offset = Math.min(Math.max(offset, 0), 1);
  47330. }
  47331. gradient.addColorStop(offset, stop.color);
  47332. });
  47333. ctx.fillStyle = gradient;
  47334. ctx.fillRect(0, 0, canvas.width, canvas.height);
  47335. gradientTexture.dirty();
  47336. this._particleSurface.setGradientTexture(this._gradientTexture);
  47337. },
  47338. _updatePlanePosition: function (leftTop, rightBottom, seriesModel, api) {
  47339. var limitedResult = this._limitInViewportAndFullFill(leftTop, rightBottom, seriesModel, api);
  47340. leftTop = limitedResult.leftTop;
  47341. rightBottom = limitedResult.rightBottom;
  47342. this._particleSurface.setRegion(limitedResult.region);
  47343. this._planeMesh.position.set(
  47344. (leftTop[0] + rightBottom[0]) / 2,
  47345. api.getHeight() - (leftTop[1] + rightBottom[1]) / 2,
  47346. 0
  47347. );
  47348. var width = rightBottom[0] - leftTop[0];
  47349. var height = rightBottom[1] - leftTop[1];
  47350. this._planeMesh.scale.set(width / 2, height / 2, 1);
  47351. this._particleSurface.resize(
  47352. Math.max(Math.min(width, 2048), 1),
  47353. Math.max(Math.min(height, 2048), 1)
  47354. );
  47355. if (this._renderer) {
  47356. this._particleSurface.clearFrame(this._renderer);
  47357. }
  47358. },
  47359. _limitInViewportAndFullFill: function (leftTop, rightBottom, seriesModel, api) {
  47360. var newLeftTop = [
  47361. Math.max(leftTop[0], 0),
  47362. Math.max(leftTop[1], 0)
  47363. ];
  47364. var newRightBottom = [
  47365. Math.min(rightBottom[0], api.getWidth()),
  47366. Math.min(rightBottom[1], api.getHeight())
  47367. ];
  47368. // Tiliing in lng orientation.
  47369. if (seriesModel.get('coordinateSystem') === 'bmap') {
  47370. var lngRange = seriesModel.getData().getDataExtent(seriesModel.coordDimToDataDim('lng')[0]);
  47371. // PENDING, consider grid density
  47372. var isContinuous = Math.floor(lngRange[1] - lngRange[0]) >= 359;
  47373. if (isContinuous) {
  47374. if (newLeftTop[0] > 0) {
  47375. newLeftTop[0] = 0;
  47376. }
  47377. if (newRightBottom[0] < api.getWidth()) {
  47378. newRightBottom[0] = api.getWidth();
  47379. }
  47380. }
  47381. }
  47382. var width = rightBottom[0] - leftTop[0];
  47383. var height = rightBottom[1] - leftTop[1];
  47384. var newWidth = newRightBottom[0] - newLeftTop[0];
  47385. var newHeight = newRightBottom[1] - newLeftTop[1];
  47386. var region = [
  47387. (newLeftTop[0] - leftTop[0]) / width,
  47388. 1.0 - newHeight / height - (newLeftTop[1] - leftTop[1]) / height,
  47389. newWidth / width,
  47390. newHeight / height
  47391. ];
  47392. return {
  47393. leftTop: newLeftTop,
  47394. rightBottom: newRightBottom,
  47395. region: region
  47396. };
  47397. },
  47398. _updateCamera: function (width, height, dpr) {
  47399. this.viewGL.setViewport(0, 0, width, height, dpr);
  47400. var camera = this.viewGL.camera;
  47401. // FIXME bottom can't be larger than top
  47402. camera.left = camera.bottom = 0;
  47403. camera.top = height;
  47404. camera.right = width;
  47405. camera.near = 0;
  47406. camera.far = 100;
  47407. camera.position.z = 10;
  47408. },
  47409. remove: function () {
  47410. this._planeMesh.stopAnimation();
  47411. this.groupGL.removeAll();
  47412. },
  47413. dispose: function () {
  47414. if (this._renderer) {
  47415. this._particleSurface.dispose(this._renderer);
  47416. }
  47417. this.groupGL.removeAll();
  47418. }
  47419. });
  47420. /***/
  47421. }),
  47422. /* 277 */
  47423. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  47424. "use strict";
  47425. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_claygl_src_compositor_Pass__ = __webpack_require__(16);
  47426. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_claygl_src_Geometry__ = __webpack_require__(15);
  47427. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_claygl_src_Mesh__ = __webpack_require__(40);
  47428. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_claygl_src_Material__ = __webpack_require__(19);
  47429. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__ = __webpack_require__(8);
  47430. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_claygl_src_Texture2D__ = __webpack_require__(5);
  47431. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_claygl_src_Texture__ = __webpack_require__(4);
  47432. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7_claygl_src_camera_Orthographic__ = __webpack_require__(37);
  47433. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8_claygl_src_geometry_Plane__ = __webpack_require__(43);
  47434. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_9_claygl_src_FrameBuffer__ = __webpack_require__(10);
  47435. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_10__Line2D__ = __webpack_require__(278);
  47436. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_11__vectorFieldParticle_glsl_js__ = __webpack_require__(279);
  47437. // import TemporalSS from '../../effect/TemporalSuperSampling';
  47438. __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */]['import'](__WEBPACK_IMPORTED_MODULE_11__vectorFieldParticle_glsl_js__["a" /* default */]);
  47439. function createSpriteCanvas(size) {
  47440. var canvas = document.createElement('canvas');
  47441. canvas.width = canvas.height = size;
  47442. var ctx = canvas.getContext('2d');
  47443. ctx.fillStyle = '#fff';
  47444. ctx.arc(size / 2, size / 2, size / 2, 0, Math.PI * 2);
  47445. ctx.fill();
  47446. return canvas;
  47447. }
  47448. // import spriteUtil from '../../util/sprite';
  47449. var VectorFieldParticleSurface = function () {
  47450. /**
  47451. * @type {number}
  47452. */
  47453. this.motionBlurFactor = 0.99;
  47454. /**
  47455. * Vector field lookup image
  47456. * @type {clay.Texture2D}
  47457. */
  47458. this.vectorFieldTexture = new __WEBPACK_IMPORTED_MODULE_5_claygl_src_Texture2D__["a" /* default */]({
  47459. type: __WEBPACK_IMPORTED_MODULE_6_claygl_src_Texture__["a" /* default */].FLOAT,
  47460. // minFilter: Texture.NEAREST,
  47461. // magFilter: Texture.NEAREST,
  47462. flipY: false
  47463. });
  47464. /**
  47465. * Particle life range
  47466. * @type {Array.<number>}
  47467. */
  47468. this.particleLife = [5, 20];
  47469. this._particleType = 'point';
  47470. /**
  47471. * @type {number}
  47472. */
  47473. this._particleSize = 1;
  47474. /**
  47475. * @type {Array.<number>}
  47476. */
  47477. this.particleColor = [1, 1, 1, 1];
  47478. /**
  47479. * @type {number}
  47480. */
  47481. this.particleSpeedScaling = 1.0;
  47482. /**
  47483. * @type {clay.Texture2D}
  47484. */
  47485. this._thisFrameTexture = null;
  47486. this._particlePass = null;
  47487. this._spawnTexture = null;
  47488. this._particleTexture0 = null;
  47489. this._particleTexture1 = null;
  47490. this._particlePointsMesh = null;
  47491. this._surfaceFrameBuffer = null;
  47492. this._elapsedTime = 0.0;
  47493. this._scene = null;
  47494. this._camera = null;
  47495. this._lastFrameTexture = null;
  47496. // this._temporalSS = new TemporalSS(50);
  47497. // this._antialising = false;
  47498. this._supersampling = 1;
  47499. this._downsampleTextures = [];
  47500. this._width = 512;
  47501. this._height = 512;
  47502. this.init();
  47503. };
  47504. VectorFieldParticleSurface.prototype = {
  47505. constructor: VectorFieldParticleSurface,
  47506. init: function () {
  47507. var parameters = {
  47508. type: __WEBPACK_IMPORTED_MODULE_6_claygl_src_Texture__["a" /* default */].FLOAT,
  47509. minFilter: __WEBPACK_IMPORTED_MODULE_6_claygl_src_Texture__["a" /* default */].NEAREST,
  47510. magFilter: __WEBPACK_IMPORTED_MODULE_6_claygl_src_Texture__["a" /* default */].NEAREST,
  47511. useMipmap: false
  47512. };
  47513. this._spawnTexture = new __WEBPACK_IMPORTED_MODULE_5_claygl_src_Texture2D__["a" /* default */](parameters);
  47514. this._particleTexture0 = new __WEBPACK_IMPORTED_MODULE_5_claygl_src_Texture2D__["a" /* default */](parameters);
  47515. this._particleTexture1 = new __WEBPACK_IMPORTED_MODULE_5_claygl_src_Texture2D__["a" /* default */](parameters);
  47516. this._frameBuffer = new __WEBPACK_IMPORTED_MODULE_9_claygl_src_FrameBuffer__["a" /* default */]({
  47517. depthBuffer: false
  47518. });
  47519. this._particlePass = new __WEBPACK_IMPORTED_MODULE_0_claygl_src_compositor_Pass__["a" /* default */]({
  47520. fragment: __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].source('ecgl.vfParticle.particle.fragment')
  47521. });
  47522. this._particlePass.setUniform('velocityTexture', this.vectorFieldTexture);
  47523. this._particlePass.setUniform('spawnTexture', this._spawnTexture);
  47524. this._downsamplePass = new __WEBPACK_IMPORTED_MODULE_0_claygl_src_compositor_Pass__["a" /* default */]({
  47525. fragment: __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].source('clay.compositor.downsample')
  47526. });
  47527. var particlePointsMesh = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_Mesh__["a" /* default */]({
  47528. // Render after last frame full quad
  47529. renderOrder: 10,
  47530. material: new __WEBPACK_IMPORTED_MODULE_3_claygl_src_Material__["a" /* default */]({
  47531. shader: new __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */](
  47532. __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].source('ecgl.vfParticle.renderPoints.vertex'),
  47533. __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].source('ecgl.vfParticle.renderPoints.fragment')
  47534. )
  47535. }),
  47536. mode: __WEBPACK_IMPORTED_MODULE_2_claygl_src_Mesh__["a" /* default */].POINTS,
  47537. geometry: new __WEBPACK_IMPORTED_MODULE_1_claygl_src_Geometry__["a" /* default */]({
  47538. dynamic: true,
  47539. mainAttribute: 'texcoord0'
  47540. })
  47541. });
  47542. var particleLinesMesh = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_Mesh__["a" /* default */]({
  47543. // Render after last frame full quad
  47544. renderOrder: 10,
  47545. material: new __WEBPACK_IMPORTED_MODULE_3_claygl_src_Material__["a" /* default */]({
  47546. shader: new __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */](
  47547. __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].source('ecgl.vfParticle.renderLines.vertex'),
  47548. __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].source('ecgl.vfParticle.renderLines.fragment')
  47549. )
  47550. }),
  47551. geometry: new __WEBPACK_IMPORTED_MODULE_10__Line2D__["a" /* default */](),
  47552. culling: false
  47553. });
  47554. var lastFrameFullQuad = new __WEBPACK_IMPORTED_MODULE_2_claygl_src_Mesh__["a" /* default */]({
  47555. material: new __WEBPACK_IMPORTED_MODULE_3_claygl_src_Material__["a" /* default */]({
  47556. shader: new __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */](
  47557. __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].source('ecgl.color.vertex'),
  47558. __WEBPACK_IMPORTED_MODULE_4_claygl_src_Shader__["a" /* default */].source('ecgl.color.fragment')
  47559. )
  47560. // DO NOT BLEND Blend will multiply alpha
  47561. // transparent: true
  47562. }),
  47563. geometry: new __WEBPACK_IMPORTED_MODULE_8_claygl_src_geometry_Plane__["a" /* default */]()
  47564. });
  47565. lastFrameFullQuad.material.enableTexture('diffuseMap');
  47566. this._particlePointsMesh = particlePointsMesh;
  47567. this._particleLinesMesh = particleLinesMesh;
  47568. this._lastFrameFullQuadMesh = lastFrameFullQuad;
  47569. this._camera = new __WEBPACK_IMPORTED_MODULE_7_claygl_src_camera_Orthographic__["a" /* default */]();
  47570. this._thisFrameTexture = new __WEBPACK_IMPORTED_MODULE_5_claygl_src_Texture2D__["a" /* default */]();
  47571. this._lastFrameTexture = new __WEBPACK_IMPORTED_MODULE_5_claygl_src_Texture2D__["a" /* default */]();
  47572. },
  47573. setParticleDensity: function (width, height) {
  47574. var nVertex = width * height;
  47575. var spawnTextureData = new Float32Array(nVertex * 4);
  47576. var off = 0;
  47577. var lifeRange = this.particleLife;
  47578. for (var i = 0; i < width; i++) {
  47579. for (var j = 0; j < height; j++ , off++) {
  47580. // x position, range [0 - 1]
  47581. spawnTextureData[off * 4] = Math.random();
  47582. // y position, range [0 - 1]
  47583. spawnTextureData[off * 4 + 1] = Math.random();
  47584. // Some property
  47585. spawnTextureData[off * 4 + 2] = Math.random();
  47586. var life = (lifeRange[1] - lifeRange[0]) * Math.random() + lifeRange[0];
  47587. // Particle life
  47588. spawnTextureData[off * 4 + 3] = life;
  47589. }
  47590. }
  47591. if (this._particleType === 'line') {
  47592. this._setLineGeometry(width, height);
  47593. }
  47594. else {
  47595. this._setPointsGeometry(width, height);
  47596. }
  47597. this._spawnTexture.width = width;
  47598. this._spawnTexture.height = height;
  47599. this._spawnTexture.pixels = spawnTextureData;
  47600. this._particleTexture0.width = this._particleTexture1.width = width;
  47601. this._particleTexture0.height = this._particleTexture1.height = height;
  47602. this._particlePass.setUniform('textureSize', [width, height]);
  47603. },
  47604. _setPointsGeometry: function (width, height) {
  47605. var nVertex = width * height;
  47606. var geometry = this._particlePointsMesh.geometry;
  47607. var attributes = geometry.attributes;
  47608. attributes.texcoord0.init(nVertex);
  47609. var off = 0;
  47610. for (var i = 0; i < width; i++) {
  47611. for (var j = 0; j < height; j++ , off++) {
  47612. attributes.texcoord0.value[off * 2] = i / width;
  47613. attributes.texcoord0.value[off * 2 + 1] = j / height;
  47614. }
  47615. }
  47616. geometry.dirty();
  47617. },
  47618. _setLineGeometry: function (width, height) {
  47619. var nLine = width * height;
  47620. var geometry = this._getParticleMesh().geometry;
  47621. geometry.setLineCount(nLine);
  47622. geometry.resetOffset();
  47623. for (var i = 0; i < width; i++) {
  47624. for (var j = 0; j < height; j++) {
  47625. geometry.addLine([i / width, j / height]);
  47626. }
  47627. }
  47628. geometry.dirty();
  47629. },
  47630. _getParticleMesh: function () {
  47631. return this._particleType === 'line' ? this._particleLinesMesh : this._particlePointsMesh;
  47632. },
  47633. update: function (renderer, api, deltaTime, firstFrame) {
  47634. var particleMesh = this._getParticleMesh();
  47635. var frameBuffer = this._frameBuffer;
  47636. var particlePass = this._particlePass;
  47637. if (firstFrame) {
  47638. this._updateDownsampleTextures(renderer, api);
  47639. }
  47640. particleMesh.material.set('size', this._particleSize * this._supersampling);
  47641. particleMesh.material.set('color', this.particleColor);
  47642. particlePass.setUniform('speedScaling', this.particleSpeedScaling);
  47643. frameBuffer.attach(this._particleTexture1);
  47644. particlePass.setUniform('firstFrameTime', firstFrame ? (this.particleLife[1] + this.particleLife[0]) / 2 : 0);
  47645. particlePass.setUniform('particleTexture', this._particleTexture0);
  47646. particlePass.setUniform('deltaTime', deltaTime);
  47647. particlePass.setUniform('elapsedTime', this._elapsedTime);
  47648. particlePass.render(renderer, frameBuffer);
  47649. particleMesh.material.set('particleTexture', this._particleTexture1);
  47650. particleMesh.material.set('prevParticleTexture', this._particleTexture0);
  47651. frameBuffer.attach(this._thisFrameTexture);
  47652. frameBuffer.bind(renderer);
  47653. renderer.gl.clear(renderer.gl.DEPTH_BUFFER_BIT | renderer.gl.COLOR_BUFFER_BIT);
  47654. var lastFrameFullQuad = this._lastFrameFullQuadMesh;
  47655. lastFrameFullQuad.material.set('diffuseMap', this._lastFrameTexture);
  47656. lastFrameFullQuad.material.set('color', [1, 1, 1, this.motionBlurFactor]);
  47657. this._camera.update(true);
  47658. renderer.renderPass([lastFrameFullQuad, particleMesh], this._camera);
  47659. frameBuffer.unbind(renderer);
  47660. this._downsample(renderer);
  47661. this._swapTexture();
  47662. this._elapsedTime += deltaTime;
  47663. },
  47664. _downsample: function (renderer) {
  47665. var downsampleTextures = this._downsampleTextures;
  47666. if (downsampleTextures.length === 0) {
  47667. return;
  47668. }
  47669. var current = 0;
  47670. var sourceTexture = this._thisFrameTexture;
  47671. var targetTexture = downsampleTextures[current];
  47672. while (targetTexture) {
  47673. this._frameBuffer.attach(targetTexture);
  47674. this._downsamplePass.setUniform('texture', sourceTexture);
  47675. this._downsamplePass.setUniform('textureSize', [sourceTexture.width, sourceTexture.height]);
  47676. this._downsamplePass.render(renderer, this._frameBuffer);
  47677. sourceTexture = targetTexture;
  47678. targetTexture = downsampleTextures[++current];
  47679. }
  47680. },
  47681. getSurfaceTexture: function () {
  47682. var downsampleTextures = this._downsampleTextures;
  47683. return downsampleTextures.length > 0
  47684. ? downsampleTextures[downsampleTextures.length - 1]
  47685. : this._lastFrameTexture;
  47686. },
  47687. setRegion: function (region) {
  47688. this._particlePass.setUniform('region', region);
  47689. },
  47690. resize: function (width, height) {
  47691. this._lastFrameTexture.width = width * this._supersampling;
  47692. this._lastFrameTexture.height = height * this._supersampling;
  47693. this._thisFrameTexture.width = width * this._supersampling;
  47694. this._thisFrameTexture.height = height * this._supersampling;
  47695. this._width = width;
  47696. this._height = height;
  47697. },
  47698. setParticleSize: function (size) {
  47699. var particleMesh = this._getParticleMesh();
  47700. if (size <= 2) {
  47701. particleMesh.material.disableTexture('spriteTexture');
  47702. particleMesh.material.transparent = false;
  47703. return;
  47704. }
  47705. if (!this._spriteTexture) {
  47706. this._spriteTexture = new __WEBPACK_IMPORTED_MODULE_5_claygl_src_Texture2D__["a" /* default */]();
  47707. }
  47708. if (!this._spriteTexture.image || this._spriteTexture.image.width !== size) {
  47709. this._spriteTexture.image = createSpriteCanvas(size);
  47710. this._spriteTexture.dirty();
  47711. }
  47712. particleMesh.material.transparent = true;
  47713. particleMesh.material.enableTexture('spriteTexture');
  47714. particleMesh.material.set('spriteTexture', this._spriteTexture);
  47715. this._particleSize = size;
  47716. },
  47717. setGradientTexture: function (gradientTexture) {
  47718. var material = this._getParticleMesh().material;
  47719. material[gradientTexture ? 'enableTexture' : 'disableTexture']('gradientTexture');
  47720. material.setUniform('gradientTexture', gradientTexture);
  47721. },
  47722. setColorTextureImage: function (colorTextureImg, api) {
  47723. var material = this._getParticleMesh().material;
  47724. material.setTextureImage('colorTexture', colorTextureImg, api, {
  47725. flipY: true
  47726. });
  47727. },
  47728. setParticleType: function (type) {
  47729. this._particleType = type;
  47730. },
  47731. clearFrame: function (renderer) {
  47732. var frameBuffer = this._frameBuffer;
  47733. frameBuffer.attach(this._lastFrameTexture);
  47734. frameBuffer.bind(renderer);
  47735. renderer.gl.clear(renderer.gl.DEPTH_BUFFER_BIT | renderer.gl.COLOR_BUFFER_BIT);
  47736. frameBuffer.unbind(renderer);
  47737. },
  47738. setSupersampling: function (supersampling) {
  47739. this._supersampling = supersampling;
  47740. this.resize(this._width, this._height);
  47741. },
  47742. _updateDownsampleTextures: function (renderer, api) {
  47743. var downsampleTextures = this._downsampleTextures;
  47744. var upScale = Math.max(Math.floor(Math.log(this._supersampling / api.getDevicePixelRatio()) / Math.log(2)), 0);
  47745. var scale = 2;
  47746. var width = this._width * this._supersampling;
  47747. var height = this._height * this._supersampling;
  47748. for (var i = 0; i < upScale; i++) {
  47749. downsampleTextures[i] = downsampleTextures[i] || new __WEBPACK_IMPORTED_MODULE_5_claygl_src_Texture2D__["a" /* default */]();
  47750. downsampleTextures[i].width = width / scale;
  47751. downsampleTextures[i].height = height / scale;
  47752. scale *= 2;
  47753. }
  47754. for (; i < downsampleTextures.length; i++) {
  47755. downsampleTextures[i].dispose(renderer);
  47756. }
  47757. downsampleTextures.length = upScale;
  47758. },
  47759. _swapTexture: function () {
  47760. var tmp = this._particleTexture0;
  47761. this._particleTexture0 = this._particleTexture1;
  47762. this._particleTexture1 = tmp;
  47763. var tmp = this._thisFrameTexture;
  47764. this._thisFrameTexture = this._lastFrameTexture;
  47765. this._lastFrameTexture = tmp;
  47766. },
  47767. dispose: function (renderer) {
  47768. renderer.disposeFrameBuffer(this._frameBuffer);
  47769. // Dispose textures
  47770. renderer.disposeTexture(this.vectorFieldTexture);
  47771. renderer.disposeTexture(this._spawnTexture);
  47772. renderer.disposeTexture(this._particleTexture0);
  47773. renderer.disposeTexture(this._particleTexture1);
  47774. renderer.disposeTexture(this._thisFrameTexture);
  47775. renderer.disposeTexture(this._lastFrameTexture);
  47776. renderer.disposeGeometry(this._particleLinesMesh.geometry);
  47777. renderer.disposeGeometry(this._particlePointsMesh.geometry);
  47778. renderer.disposeGeometry(this._lastFrameFullQuadMesh.geometry);
  47779. if (this._spriteTexture) {
  47780. renderer.disposeTexture(this._spriteTexture);
  47781. }
  47782. this._particlePass.dispose(renderer);
  47783. this._downsamplePass.dispose(renderer);
  47784. this._downsampleTextures.forEach(function (texture) {
  47785. texture.dispose(renderer);
  47786. });
  47787. }
  47788. };
  47789. /* harmony default export */ __webpack_exports__["a"] = (VectorFieldParticleSurface);
  47790. /***/
  47791. }),
  47792. /* 278 */
  47793. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  47794. "use strict";
  47795. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__ = __webpack_require__(15);
  47796. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts__ = __webpack_require__(0);
  47797. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_echarts_lib_echarts__);
  47798. /**
  47799. * Lines geometry
  47800. * Use screen space projected lines lineWidth > MAX_LINE_WIDTH
  47801. * https://mattdesl.svbtle.com/drawing-lines-is-hard
  47802. * @module echarts-gl/util/geometry/LinesGeometry
  47803. * @author Yi Shen(http://github.com/pissang)
  47804. */
  47805. /**
  47806. * @constructor
  47807. * @alias module:echarts-gl/chart/flowGL/Line2D
  47808. * @extends clay.Geometry
  47809. */
  47810. var LinesGeometry = __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].extend(function () {
  47811. return {
  47812. dynamic: true,
  47813. attributes: {
  47814. position: new __WEBPACK_IMPORTED_MODULE_0_claygl_src_Geometry__["a" /* default */].Attribute('position', 'float', 3, 'POSITION')
  47815. }
  47816. };
  47817. },
  47818. /** @lends module: echarts-gl/util/geometry/LinesGeometry.prototype */
  47819. {
  47820. /**
  47821. * Reset offset
  47822. */
  47823. resetOffset: function () {
  47824. this._vertexOffset = 0;
  47825. this._faceOffset = 0;
  47826. },
  47827. /**
  47828. * @param {number} nVertex
  47829. */
  47830. setLineCount: function (nLine) {
  47831. var attributes = this.attributes;
  47832. var nVertex = 4 * nLine;
  47833. var nTriangle = 2 * nLine;
  47834. if (this.vertexCount !== nVertex) {
  47835. attributes.position.init(nVertex);
  47836. }
  47837. if (this.triangleCount !== nTriangle) {
  47838. if (nTriangle === 0) {
  47839. this.indices = null;
  47840. }
  47841. else {
  47842. this.indices = this.vertexCount > 0xffff ? new Uint32Array(nTriangle * 3) : new Uint16Array(nTriangle * 3);
  47843. }
  47844. }
  47845. },
  47846. addLine: function (p) {
  47847. var vertexOffset = this._vertexOffset;
  47848. this.attributes.position.set(vertexOffset, [p[0], p[1], 1]);
  47849. this.attributes.position.set(vertexOffset + 1, [p[0], p[1], -1]);
  47850. this.attributes.position.set(vertexOffset + 2, [p[0], p[1], 2]);
  47851. this.attributes.position.set(vertexOffset + 3, [p[0], p[1], -2]);
  47852. this.setTriangleIndices(
  47853. this._faceOffset++, [
  47854. vertexOffset, vertexOffset + 1, vertexOffset + 2
  47855. ]
  47856. );
  47857. this.setTriangleIndices(
  47858. this._faceOffset++, [
  47859. vertexOffset + 1, vertexOffset + 2, vertexOffset + 3
  47860. ]
  47861. );
  47862. this._vertexOffset += 4;
  47863. }
  47864. });
  47865. /* harmony default export */ __webpack_exports__["a"] = (LinesGeometry);
  47866. /***/
  47867. }),
  47868. /* 279 */
  47869. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  47870. "use strict";
  47871. /* harmony default export */ __webpack_exports__["a"] = ("@export ecgl.vfParticle.particle.fragment\n\nuniform sampler2D particleTexture;\nuniform sampler2D spawnTexture;\nuniform sampler2D velocityTexture;\n\nuniform float deltaTime;\nuniform float elapsedTime;\n\nuniform float speedScaling : 1.0;\n\nuniform vec2 textureSize;\nuniform vec4 region : [0, 0, 1, 1];\nuniform float firstFrameTime;\n\nvarying vec2 v_Texcoord;\n\n\nvoid main()\n{\n vec4 p = texture2D(particleTexture, v_Texcoord);\n bool spawn = false;\n if (p.w <= 0.0) {\n p = texture2D(spawnTexture, fract(v_Texcoord + elapsedTime / 10.0));\n p.w -= firstFrameTime;\n spawn = true;\n }\n vec2 v = texture2D(velocityTexture, fract(p.xy * region.zw + region.xy)).xy;\n v = (v - 0.5) * 2.0;\n p.z = length(v);\n p.xy += v * deltaTime / 10.0 * speedScaling;\n p.w -= deltaTime;\n\n if (spawn || p.xy != fract(p.xy)) {\n p.z = 0.0;\n }\n p.xy = fract(p.xy);\n\n gl_FragColor = p;\n}\n@end\n\n@export ecgl.vfParticle.renderPoints.vertex\n\n#define PI 3.1415926\n\nattribute vec2 texcoord : TEXCOORD_0;\n\nuniform sampler2D particleTexture;\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nuniform float size : 1.0;\n\nvarying float v_Mag;\nvarying vec2 v_Uv;\n\nvoid main()\n{\n vec4 p = texture2D(particleTexture, texcoord);\n\n if (p.w > 0.0 && p.z > 1e-5) {\n gl_Position = worldViewProjection * vec4(p.xy * 2.0 - 1.0, 0.0, 1.0);\n }\n else {\n gl_Position = vec4(100000.0, 100000.0, 100000.0, 1.0);\n }\n\n v_Mag = p.z;\n v_Uv = p.xy;\n\n gl_PointSize = size;\n}\n\n@end\n\n@export ecgl.vfParticle.renderPoints.fragment\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\nuniform sampler2D gradientTexture;\nuniform sampler2D colorTexture;\nuniform sampler2D spriteTexture;\n\nvarying float v_Mag;\nvarying vec2 v_Uv;\n\nvoid main()\n{\n gl_FragColor = color;\n#ifdef SPRITETEXTURE_ENABLED\n gl_FragColor *= texture2D(spriteTexture, gl_PointCoord);\n if (color.a == 0.0) {\n discard;\n }\n#endif\n#ifdef GRADIENTTEXTURE_ENABLED\n gl_FragColor *= texture2D(gradientTexture, vec2(v_Mag, 0.5));\n#endif\n#ifdef COLORTEXTURE_ENABLED\n gl_FragColor *= texture2D(colorTexture, v_Uv);\n#endif\n}\n\n@end\n\n@export ecgl.vfParticle.renderLines.vertex\n\n#define PI 3.1415926\n\nattribute vec3 position : POSITION;\n\nuniform sampler2D particleTexture;\nuniform sampler2D prevParticleTexture;\n\nuniform float size : 1.0;\nuniform vec4 vp: VIEWPORT;\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nvarying float v_Mag;\nvarying vec2 v_Uv;\n\n@import clay.util.rand\n\nvoid main()\n{\n vec4 p = texture2D(particleTexture, position.xy);\n vec4 p2 = texture2D(prevParticleTexture, position.xy);\n\n p.xy = p.xy * 2.0 - 1.0;\n p2.xy = p2.xy * 2.0 - 1.0;\n\n if (p.w > 0.0 && p.z > 1e-5) {\n vec2 dir = normalize(p.xy - p2.xy);\n vec2 norm = vec2(dir.y / vp.z, -dir.x / vp.w) * sign(position.z) * size;\n if (abs(position.z) == 2.0) {\n gl_Position = vec4(p.xy + norm, 0.0, 1.0);\n v_Uv = p.xy;\n v_Mag = p.z;\n }\n else {\n gl_Position = vec4(p2.xy + norm, 0.0, 1.0);\n v_Mag = p2.z;\n v_Uv = p2.xy;\n }\n gl_Position = worldViewProjection * gl_Position;\n }\n else {\n gl_Position = vec4(100000.0, 100000.0, 100000.0, 1.0);\n }\n}\n\n@end\n\n@export ecgl.vfParticle.renderLines.fragment\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\nuniform sampler2D gradientTexture;\nuniform sampler2D colorTexture;\n\nvarying float v_Mag;\nvarying vec2 v_Uv;\n\nvoid main()\n{\n gl_FragColor = color;\n #ifdef GRADIENTTEXTURE_ENABLED\n gl_FragColor *= texture2D(gradientTexture, vec2(v_Mag, 0.5));\n#endif\n#ifdef COLORTEXTURE_ENABLED\n gl_FragColor *= texture2D(colorTexture, v_Uv);\n#endif\n}\n\n@end\n");
  47872. /***/
  47873. }),
  47874. /* 280 */
  47875. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  47876. "use strict";
  47877. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  47878. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  47879. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendSeriesModel({
  47880. type: 'series.flowGL',
  47881. dependencies: ['geo', 'grid', 'bmap'],
  47882. visualColorAccessPath: 'itemStyle.color',
  47883. getInitialData: function (option, ecModel) {
  47884. var coordSysDimensions = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.getCoordinateSystemDimensions(this.get('coordinateSystem')) || ['x', 'y'];
  47885. if (true) {
  47886. if (coordSysDimensions.length > 2) {
  47887. throw new Error('flowGL can only be used on 2d coordinate systems.')
  47888. }
  47889. }
  47890. coordSysDimensions.push('vx', 'vy');
  47891. var dimensions = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.helper.completeDimensions(coordSysDimensions, this.getSource(), {
  47892. encodeDef: this.get('encode'),
  47893. dimsDef: this.get('dimensions')
  47894. });
  47895. var data = new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.List(dimensions, this);
  47896. data.initData(this.getSource());
  47897. return data;
  47898. },
  47899. defaultOption: {
  47900. coordinateSystem: 'cartesian2d',
  47901. zlevel: 10,
  47902. supersampling: 1,
  47903. // 128x128 particles
  47904. particleType: 'point',
  47905. particleDensity: 128,
  47906. particleSize: 1,
  47907. particleSpeed: 1,
  47908. particleTrail: 2,
  47909. colorTexture: null,
  47910. gridWidth: 'auto',
  47911. gridHeight: 'auto',
  47912. itemStyle: {
  47913. color: '#fff',
  47914. opacity: 0.8
  47915. }
  47916. }
  47917. });
  47918. /***/
  47919. }),
  47920. /* 281 */
  47921. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  47922. "use strict";
  47923. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  47924. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  47925. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__linesGL_LinesGLSeries__ = __webpack_require__(282);
  47926. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__linesGL_LinesGLView__ = __webpack_require__(283);
  47927. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__common_opacityVisual__ = __webpack_require__(17);
  47928. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.registerVisual(Object(__WEBPACK_IMPORTED_MODULE_3__common_opacityVisual__["a" /* default */])('linesGL'));
  47929. /***/
  47930. }),
  47931. /* 282 */
  47932. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  47933. "use strict";
  47934. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  47935. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  47936. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_zrender_lib_core_util__ = __webpack_require__(13);
  47937. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_zrender_lib_core_util___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_zrender_lib_core_util__);
  47938. var LinesSeries = __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendSeriesModel({
  47939. type: 'series.linesGL',
  47940. dependencies: ['grid', 'geo'],
  47941. visualColorAccessPath: 'lineStyle.color',
  47942. streamEnabled: true,
  47943. init: function (option) {
  47944. var result = this._processFlatCoordsArray(option.data);
  47945. this._flatCoords = result.flatCoords;
  47946. this._flatCoordsOffset = result.flatCoordsOffset;
  47947. if (result.flatCoords) {
  47948. option.data = new Float32Array(result.count);
  47949. }
  47950. LinesSeries.superApply(this, 'init', arguments);
  47951. },
  47952. mergeOption: function (option) {
  47953. var result = this._processFlatCoordsArray(option.data);
  47954. this._flatCoords = result.flatCoords;
  47955. this._flatCoordsOffset = result.flatCoordsOffset;
  47956. if (result.flatCoords) {
  47957. option.data = new Float32Array(result.count);
  47958. }
  47959. LinesSeries.superApply(this, 'mergeOption', arguments);
  47960. },
  47961. appendData: function (params) {
  47962. var result = this._processFlatCoordsArray(params.data);
  47963. if (result.flatCoords) {
  47964. if (!this._flatCoords) {
  47965. this._flatCoords = result.flatCoords;
  47966. this._flatCoordsOffset = result.flatCoordsOffset;
  47967. }
  47968. else {
  47969. this._flatCoords = Object(__WEBPACK_IMPORTED_MODULE_1_zrender_lib_core_util__["concatArray"])(this._flatCoords, result.flatCoords);
  47970. this._flatCoordsOffset = Object(__WEBPACK_IMPORTED_MODULE_1_zrender_lib_core_util__["concatArray"])(this._flatCoordsOffset, result.flatCoordsOffset);
  47971. }
  47972. params.data = new Float32Array(result.count);
  47973. }
  47974. this.getRawData().appendData(params.data);
  47975. },
  47976. _getCoordsFromItemModel: function (idx) {
  47977. var itemModel = this.getData().getItemModel(idx);
  47978. var coords = (itemModel.option instanceof Array)
  47979. ? itemModel.option : itemModel.getShallow('coords');
  47980. if (true) {
  47981. if (!(coords instanceof Array && coords.length > 0 && coords[0] instanceof Array)) {
  47982. throw new Error('Invalid coords ' + JSON.stringify(coords) + '. Lines must have 2d coords array in data item.');
  47983. }
  47984. }
  47985. return coords;
  47986. },
  47987. getLineCoordsCount: function (idx) {
  47988. if (this._flatCoordsOffset) {
  47989. return this._flatCoordsOffset[idx * 2 + 1];
  47990. }
  47991. else {
  47992. return this._getCoordsFromItemModel(idx).length;
  47993. }
  47994. },
  47995. getLineCoords: function (idx, out) {
  47996. if (this._flatCoordsOffset) {
  47997. var offset = this._flatCoordsOffset[idx * 2];
  47998. var len = this._flatCoordsOffset[idx * 2 + 1];
  47999. for (var i = 0; i < len; i++) {
  48000. out[i] = out[i] || [];
  48001. out[i][0] = this._flatCoords[offset + i * 2];
  48002. out[i][1] = this._flatCoords[offset + i * 2 + 1];
  48003. }
  48004. return len;
  48005. }
  48006. else {
  48007. var coords = this._getCoordsFromItemModel(idx);
  48008. for (var i = 0; i < coords.length; i++) {
  48009. out[i] = out[i] || [];
  48010. out[i][0] = coords[i][0];
  48011. out[i][1] = coords[i][1];
  48012. }
  48013. return coords.length;
  48014. }
  48015. },
  48016. _processFlatCoordsArray: function (data) {
  48017. var startOffset = 0;
  48018. if (this._flatCoords) {
  48019. startOffset = this._flatCoords.length;
  48020. }
  48021. // Stored as a typed array. In format
  48022. // Points Count(2) | x | y | x | y | Points Count(3) | x | y | x | y | x | y |
  48023. if (typeof data[0] === 'number') {
  48024. var len = data.length;
  48025. // Store offset and len of each segment
  48026. var coordsOffsetAndLenStorage = new Uint32Array(len);
  48027. var coordsStorage = new Float64Array(len);
  48028. var coordsCursor = 0;
  48029. var offsetCursor = 0;
  48030. var dataCount = 0;
  48031. for (var i = 0; i < len;) {
  48032. dataCount++;
  48033. var count = data[i++];
  48034. // Offset
  48035. coordsOffsetAndLenStorage[offsetCursor++] = coordsCursor + startOffset;
  48036. // Len
  48037. coordsOffsetAndLenStorage[offsetCursor++] = count;
  48038. for (var k = 0; k < count; k++) {
  48039. var x = data[i++];
  48040. var y = data[i++];
  48041. coordsStorage[coordsCursor++] = x;
  48042. coordsStorage[coordsCursor++] = y;
  48043. if (i > len) {
  48044. if (true) {
  48045. throw new Error('Invalid data format.');
  48046. }
  48047. }
  48048. }
  48049. }
  48050. return {
  48051. flatCoordsOffset: new Uint32Array(coordsOffsetAndLenStorage.buffer, 0, offsetCursor),
  48052. flatCoords: coordsStorage,
  48053. count: dataCount
  48054. };
  48055. }
  48056. return {
  48057. flatCoordsOffset: null,
  48058. flatCoords: null,
  48059. count: data.length
  48060. };
  48061. },
  48062. getInitialData: function (option, ecModel) {
  48063. var lineData = new __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.List(['value'], this);
  48064. lineData.hasItemOption = false;
  48065. lineData.initData(option.data, [], function (dataItem, dimName, dataIndex, dimIndex) {
  48066. // dataItem is simply coords
  48067. if (dataItem instanceof Array) {
  48068. return NaN;
  48069. }
  48070. else {
  48071. lineData.hasItemOption = true;
  48072. var value = dataItem.value;
  48073. if (value != null) {
  48074. return value instanceof Array ? value[dimIndex] : value;
  48075. }
  48076. }
  48077. });
  48078. return lineData;
  48079. },
  48080. defaultOption: {
  48081. coordinateSystem: 'geo',
  48082. zlevel: 10,
  48083. progressive: 1e4,
  48084. progressiveThreshold: 5e4,
  48085. // Cartesian coordinate system
  48086. // xAxisIndex: 0,
  48087. // yAxisIndex: 0,
  48088. // Geo coordinate system
  48089. // geoIndex: 0,
  48090. // Support source-over, lighter
  48091. blendMode: 'source-over',
  48092. lineStyle: {
  48093. opacity: 0.8
  48094. },
  48095. postEffect: {
  48096. enable: false,
  48097. colorCorrection: {
  48098. exposure: 0,
  48099. brightness: 0,
  48100. contrast: 1,
  48101. saturation: 1,
  48102. enable: true
  48103. }
  48104. }
  48105. }
  48106. });
  48107. /***/
  48108. }),
  48109. /* 283 */
  48110. /***/ (function (module, __webpack_exports__, __webpack_require__) {
  48111. "use strict";
  48112. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__ = __webpack_require__(0);
  48113. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts__);
  48114. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__ = __webpack_require__(1);
  48115. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__core_ViewGL__ = __webpack_require__(22);
  48116. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__util_geometry_Lines2D__ = __webpack_require__(105);
  48117. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__common_GLViewHelper__ = __webpack_require__(103);
  48118. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__util_retrieve__ = __webpack_require__(2);
  48119. __WEBPACK_IMPORTED_MODULE_0_echarts_lib_echarts___default.a.extendChartView({
  48120. type: 'linesGL',
  48121. __ecgl__: true,
  48122. init: function (ecModel, api) {
  48123. this.groupGL = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Node();
  48124. this.viewGL = new __WEBPACK_IMPORTED_MODULE_2__core_ViewGL__["a" /* default */]('orthographic');
  48125. this.viewGL.add(this.groupGL);
  48126. this._glViewHelper = new __WEBPACK_IMPORTED_MODULE_4__common_GLViewHelper__["a" /* default */](this.viewGL);
  48127. this._nativeLinesShader = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].createShader('ecgl.lines3D');
  48128. this._meshLinesShader = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].createShader('ecgl.meshLines3D');
  48129. this._linesMeshes = [];
  48130. this._currentStep = 0;
  48131. },
  48132. render: function (seriesModel, ecModel, api) {
  48133. this.groupGL.removeAll();
  48134. this._glViewHelper.reset(seriesModel, api);
  48135. var linesMesh = this._linesMeshes[0];
  48136. if (!linesMesh) {
  48137. linesMesh = this._linesMeshes[0] = this._createLinesMesh(seriesModel);
  48138. }
  48139. this._linesMeshes.length = 1;
  48140. this.groupGL.add(linesMesh);
  48141. this._updateLinesMesh(seriesModel, linesMesh, 0, seriesModel.getData().count());
  48142. this.viewGL.setPostEffect(seriesModel.getModel('postEffect'), api);
  48143. },
  48144. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  48145. this.groupGL.removeAll();
  48146. this._glViewHelper.reset(seriesModel, api);
  48147. this._currentStep = 0;
  48148. this.viewGL.setPostEffect(seriesModel.getModel('postEffect'), api);
  48149. },
  48150. incrementalRender: function (params, seriesModel, ecModel, api) {
  48151. var linesMesh = this._linesMeshes[this._currentStep];
  48152. if (!linesMesh) {
  48153. linesMesh = this._createLinesMesh(seriesModel);
  48154. this._linesMeshes[this._currentStep] = linesMesh;
  48155. }
  48156. this._updateLinesMesh(seriesModel, linesMesh, params.start, params.end);
  48157. this.groupGL.add(linesMesh);
  48158. api.getZr().refresh();
  48159. this._currentStep++;
  48160. },
  48161. updateTransform: function (seriesModel, ecModel, api) {
  48162. if (seriesModel.coordinateSystem.getRoamTransform) {
  48163. this._glViewHelper.updateTransform(seriesModel, api);
  48164. }
  48165. },
  48166. _createLinesMesh: function (seriesModel) {
  48167. var linesMesh = new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh({
  48168. $ignorePicking: true,
  48169. material: new __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Material({
  48170. shader: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].createShader('ecgl.lines3D'),
  48171. transparent: true,
  48172. depthMask: false,
  48173. depthTest: false
  48174. }),
  48175. geometry: new __WEBPACK_IMPORTED_MODULE_3__util_geometry_Lines2D__["a" /* default */]({
  48176. segmentScale: 10,
  48177. useNativeLine: true,
  48178. dynamic: false
  48179. }),
  48180. mode: __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh.LINES,
  48181. culling: false
  48182. });
  48183. return linesMesh;
  48184. },
  48185. _updateLinesMesh: function (seriesModel, linesMesh, start, end) {
  48186. var data = seriesModel.getData();
  48187. linesMesh.material.blend = seriesModel.get('blendMode') === 'lighter'
  48188. ? __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].additiveBlend : null;
  48189. var curveness = seriesModel.get('lineStyle.curveness') || 0;
  48190. var isPolyline = seriesModel.get('polyline');
  48191. var geometry = linesMesh.geometry;
  48192. var coordSys = seriesModel.coordinateSystem;
  48193. var lineWidth = __WEBPACK_IMPORTED_MODULE_5__util_retrieve__["a" /* default */].firstNotNull(seriesModel.get('lineStyle.width'), 1);
  48194. if (lineWidth > 1) {
  48195. if (linesMesh.material.shader !== this._meshLinesShader) {
  48196. linesMesh.material.attachShader(this._meshLinesShader);
  48197. }
  48198. linesMesh.mode = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh.TRIANGLES;
  48199. }
  48200. else {
  48201. if (linesMesh.material.shader !== this._nativeLinesShader) {
  48202. linesMesh.material.attachShader(this._nativeLinesShader);
  48203. }
  48204. linesMesh.mode = __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].Mesh.LINES;
  48205. }
  48206. start = start || 0;
  48207. end = end || data.count();
  48208. geometry.resetOffset();
  48209. var vertexCount = 0;
  48210. var triangleCount = 0;
  48211. var p0 = [];
  48212. var p1 = [];
  48213. var p2 = [];
  48214. var p3 = [];
  48215. var lineCoords = [];
  48216. var t = 0.3;
  48217. var t2 = 0.7;
  48218. function updateBezierControlPoints() {
  48219. p1[0] = (p0[0] * t2 + p3[0] * t) - (p0[1] - p3[1]) * curveness;
  48220. p1[1] = (p0[1] * t2 + p3[1] * t) - (p3[0] - p0[0]) * curveness;
  48221. p2[0] = (p0[0] * t + p3[0] * t2) - (p0[1] - p3[1]) * curveness;
  48222. p2[1] = (p0[1] * t + p3[1] * t2) - (p3[0] - p0[0]) * curveness;
  48223. }
  48224. if (isPolyline || curveness !== 0) {
  48225. for (var idx = start; idx < end; idx++) {
  48226. if (isPolyline) {
  48227. var count = seriesModel.getLineCoordsCount(idx);
  48228. vertexCount += geometry.getPolylineVertexCount(count);
  48229. triangleCount += geometry.getPolylineTriangleCount(count);
  48230. }
  48231. else {
  48232. seriesModel.getLineCoords(idx, lineCoords);
  48233. this._glViewHelper.dataToPoint(coordSys, lineCoords[0], p0);
  48234. this._glViewHelper.dataToPoint(coordSys, lineCoords[1], p3);
  48235. updateBezierControlPoints();
  48236. vertexCount += geometry.getCubicCurveVertexCount(p0, p1, p2, p3);
  48237. triangleCount += geometry.getCubicCurveTriangleCount(p0, p1, p2, p3);
  48238. }
  48239. }
  48240. }
  48241. else {
  48242. var lineCount = end - start;
  48243. vertexCount += lineCount * geometry.getLineVertexCount();
  48244. triangleCount += lineCount * geometry.getLineVertexCount();
  48245. }
  48246. geometry.setVertexCount(vertexCount);
  48247. geometry.setTriangleCount(triangleCount);
  48248. var dataIndex = start;
  48249. var colorArr = [];
  48250. for (var idx = start; idx < end; idx++) {
  48251. __WEBPACK_IMPORTED_MODULE_1__util_graphicGL__["a" /* default */].parseColor(data.getItemVisual(dataIndex, 'color'), colorArr);
  48252. var opacity = __WEBPACK_IMPORTED_MODULE_5__util_retrieve__["a" /* default */].firstNotNull(data.getItemVisual(dataIndex, 'opacity'), 1);
  48253. colorArr[3] *= opacity;
  48254. var count = seriesModel.getLineCoords(idx, lineCoords);
  48255. for (var k = 0; k < count; k++) {
  48256. this._glViewHelper.dataToPoint(coordSys, lineCoords[k], lineCoords[k]);
  48257. }
  48258. if (isPolyline) {
  48259. geometry.addPolyline(lineCoords, colorArr, lineWidth, 0, count);
  48260. }
  48261. else if (curveness !== 0) {
  48262. p0 = lineCoords[0];
  48263. p3 = lineCoords[1];
  48264. updateBezierControlPoints();
  48265. geometry.addCubicCurve(p0, p1, p2, p3, colorArr, lineWidth);
  48266. }
  48267. else {
  48268. geometry.addPolyline(lineCoords, colorArr, lineWidth, 0, 2);
  48269. }
  48270. dataIndex++;
  48271. }
  48272. },
  48273. dispose: function () {
  48274. this.groupGL.removeAll();
  48275. },
  48276. remove: function () {
  48277. this.groupGL.removeAll();
  48278. }
  48279. });
  48280. /***/
  48281. })
  48282. /******/]);
  48283. });