laya.core.js 979 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672
  1. window.Laya= (function (exports) {
  2. 'use strict';
  3. class Config {
  4. }
  5. Config.animationInterval = 50;
  6. Config.isAntialias = false;
  7. Config.isAlpha = false;
  8. Config.premultipliedAlpha = true;
  9. Config.isStencil = true;
  10. Config.preserveDrawingBuffer = false;
  11. Config.webGL2D_MeshAllocMaxMem = true;
  12. Config.is2DPixelArtGame = false;
  13. Config.useWebGL2 = true;
  14. Config.useRetinalCanvas = false;
  15. window.Config = Config;
  16. class ILaya {
  17. static regClass(c) {
  18. ILaya.__classMap[c.name] = c;
  19. }
  20. }
  21. ILaya.Laya = null;
  22. ILaya.Timer = null;
  23. ILaya.WorkerLoader = null;
  24. ILaya.Dragging = null;
  25. ILaya.GraphicsBounds = null;
  26. ILaya.Sprite = null;
  27. ILaya.TextRender = null;
  28. ILaya.TextAtlas = null;
  29. ILaya.timer = null;
  30. ILaya.systemTimer = null;
  31. ILaya.startTimer = null;
  32. ILaya.updateTimer = null;
  33. ILaya.lateTimer = null;
  34. ILaya.physicsTimer = null;
  35. ILaya.stage = null;
  36. ILaya.Loader = null;
  37. ILaya.loader = null;
  38. ILaya.TTFLoader = null;
  39. ILaya.SoundManager = null;
  40. ILaya.WebAudioSound = null;
  41. ILaya.AudioSound = null;
  42. ILaya.ShaderCompile = null;
  43. ILaya.ClassUtils = null;
  44. ILaya.SceneUtils = null;
  45. ILaya.Context = null;
  46. ILaya.Render = null;
  47. ILaya.MouseManager = null;
  48. ILaya.Text = null;
  49. ILaya.Browser = null;
  50. ILaya.WebGL = null;
  51. ILaya.Pool = null;
  52. ILaya.Utils = null;
  53. ILaya.Graphics = null;
  54. ILaya.Submit = null;
  55. ILaya.Stage = null;
  56. ILaya.Resource = null;
  57. ILaya.__classMap = {};
  58. class Pool {
  59. static getPoolBySign(sign) {
  60. return Pool._poolDic[sign] || (Pool._poolDic[sign] = []);
  61. }
  62. static clearBySign(sign) {
  63. if (Pool._poolDic[sign])
  64. Pool._poolDic[sign].length = 0;
  65. }
  66. static recover(sign, item) {
  67. if (item[Pool.POOLSIGN])
  68. return;
  69. item[Pool.POOLSIGN] = true;
  70. Pool.getPoolBySign(sign).push(item);
  71. }
  72. static recoverByClass(instance) {
  73. if (instance) {
  74. var className = instance["__className"] || instance.constructor._$gid;
  75. if (className)
  76. Pool.recover(className, instance);
  77. }
  78. }
  79. static _getClassSign(cla) {
  80. var className = cla["__className"] || cla["_$gid"];
  81. if (!className) {
  82. cla["_$gid"] = className = Pool._CLSID + "";
  83. Pool._CLSID++;
  84. }
  85. return className;
  86. }
  87. static createByClass(cls) {
  88. return Pool.getItemByClass(Pool._getClassSign(cls), cls);
  89. }
  90. static getItemByClass(sign, cls) {
  91. if (!Pool._poolDic[sign])
  92. return new cls();
  93. var pool = Pool.getPoolBySign(sign);
  94. if (pool.length) {
  95. var rst = pool.pop();
  96. rst[Pool.POOLSIGN] = false;
  97. }
  98. else {
  99. rst = new cls();
  100. }
  101. return rst;
  102. }
  103. static getItemByCreateFun(sign, createFun, caller = null) {
  104. var pool = Pool.getPoolBySign(sign);
  105. var rst = pool.length ? pool.pop() : createFun.call(caller);
  106. rst[Pool.POOLSIGN] = false;
  107. return rst;
  108. }
  109. static getItem(sign) {
  110. var pool = Pool.getPoolBySign(sign);
  111. var rst = pool.length ? pool.pop() : null;
  112. if (rst) {
  113. rst[Pool.POOLSIGN] = false;
  114. }
  115. return rst;
  116. }
  117. }
  118. Pool._CLSID = 0;
  119. Pool.POOLSIGN = "__InPool";
  120. Pool._poolDic = {};
  121. class AlphaCmd {
  122. static create(alpha) {
  123. var cmd = Pool.getItemByClass("AlphaCmd", AlphaCmd);
  124. cmd.alpha = alpha;
  125. return cmd;
  126. }
  127. recover() {
  128. Pool.recover("AlphaCmd", this);
  129. }
  130. run(context, gx, gy) {
  131. context.alpha(this.alpha);
  132. }
  133. get cmdID() {
  134. return AlphaCmd.ID;
  135. }
  136. }
  137. AlphaCmd.ID = "Alpha";
  138. class DrawCircleCmd {
  139. static create(x, y, radius, fillColor, lineColor, lineWidth, vid) {
  140. var cmd = Pool.getItemByClass("DrawCircleCmd", DrawCircleCmd);
  141. cmd.x = x;
  142. cmd.y = y;
  143. cmd.radius = radius;
  144. cmd.fillColor = fillColor;
  145. cmd.lineColor = lineColor;
  146. cmd.lineWidth = lineWidth;
  147. cmd.vid = vid;
  148. return cmd;
  149. }
  150. recover() {
  151. this.fillColor = null;
  152. this.lineColor = null;
  153. Pool.recover("DrawCircleCmd", this);
  154. }
  155. run(context, gx, gy) {
  156. context._drawCircle(this.x + gx, this.y + gy, this.radius, this.fillColor, this.lineColor, this.lineWidth, this.vid);
  157. }
  158. get cmdID() {
  159. return DrawCircleCmd.ID;
  160. }
  161. }
  162. DrawCircleCmd.ID = "DrawCircle";
  163. class DrawCurvesCmd {
  164. static create(x, y, points, lineColor, lineWidth) {
  165. var cmd = Pool.getItemByClass("DrawCurvesCmd", DrawCurvesCmd);
  166. cmd.x = x;
  167. cmd.y = y;
  168. cmd.points = points;
  169. cmd.lineColor = lineColor;
  170. cmd.lineWidth = lineWidth;
  171. return cmd;
  172. }
  173. recover() {
  174. this.points = null;
  175. this.lineColor = null;
  176. Pool.recover("DrawCurvesCmd", this);
  177. }
  178. run(context, gx, gy) {
  179. if (this.points)
  180. context.drawCurves(this.x + gx, this.y + gy, this.points, this.lineColor, this.lineWidth);
  181. }
  182. get cmdID() {
  183. return DrawCurvesCmd.ID;
  184. }
  185. }
  186. DrawCurvesCmd.ID = "DrawCurves";
  187. class DrawImageCmd {
  188. static create(texture, x, y, width, height) {
  189. var cmd = Pool.getItemByClass("DrawImageCmd", DrawImageCmd);
  190. cmd.texture = texture;
  191. texture._addReference();
  192. cmd.x = x;
  193. cmd.y = y;
  194. cmd.width = width;
  195. cmd.height = height;
  196. return cmd;
  197. }
  198. recover() {
  199. this.texture && this.texture._removeReference();
  200. this.texture = null;
  201. Pool.recover("DrawImageCmd", this);
  202. }
  203. run(context, gx, gy) {
  204. if (this.texture)
  205. context.drawTexture(this.texture, this.x + gx, this.y + gy, this.width, this.height);
  206. }
  207. get cmdID() {
  208. return DrawImageCmd.ID;
  209. }
  210. }
  211. DrawImageCmd.ID = "DrawImage";
  212. class DrawLineCmd {
  213. static create(fromX, fromY, toX, toY, lineColor, lineWidth, vid) {
  214. var cmd = Pool.getItemByClass("DrawLineCmd", DrawLineCmd);
  215. cmd.fromX = fromX;
  216. cmd.fromY = fromY;
  217. cmd.toX = toX;
  218. cmd.toY = toY;
  219. cmd.lineColor = lineColor;
  220. cmd.lineWidth = lineWidth;
  221. cmd.vid = vid;
  222. return cmd;
  223. }
  224. recover() {
  225. Pool.recover("DrawLineCmd", this);
  226. }
  227. run(context, gx, gy) {
  228. context._drawLine(gx, gy, this.fromX, this.fromY, this.toX, this.toY, this.lineColor, this.lineWidth, this.vid);
  229. }
  230. get cmdID() {
  231. return DrawLineCmd.ID;
  232. }
  233. }
  234. DrawLineCmd.ID = "DrawLine";
  235. class DrawLinesCmd {
  236. static create(x, y, points, lineColor, lineWidth, vid) {
  237. var cmd = Pool.getItemByClass("DrawLinesCmd", DrawLinesCmd);
  238. cmd.x = x;
  239. cmd.y = y;
  240. cmd.points = points;
  241. cmd.lineColor = lineColor;
  242. cmd.lineWidth = lineWidth;
  243. cmd.vid = vid;
  244. return cmd;
  245. }
  246. recover() {
  247. this.points = null;
  248. this.lineColor = null;
  249. Pool.recover("DrawLinesCmd", this);
  250. }
  251. run(context, gx, gy) {
  252. this.points && context._drawLines(this.x + gx, this.y + gy, this.points, this.lineColor, this.lineWidth, this.vid);
  253. }
  254. get cmdID() {
  255. return DrawLinesCmd.ID;
  256. }
  257. }
  258. DrawLinesCmd.ID = "DrawLines";
  259. class DrawPathCmd {
  260. static create(x, y, paths, brush, pen) {
  261. var cmd = Pool.getItemByClass("DrawPathCmd", DrawPathCmd);
  262. cmd.x = x;
  263. cmd.y = y;
  264. cmd.paths = paths;
  265. cmd.brush = brush;
  266. cmd.pen = pen;
  267. return cmd;
  268. }
  269. recover() {
  270. this.paths = null;
  271. this.brush = null;
  272. this.pen = null;
  273. Pool.recover("DrawPathCmd", this);
  274. }
  275. run(context, gx, gy) {
  276. this.paths && context._drawPath(this.x + gx, this.y + gy, this.paths, this.brush, this.pen);
  277. }
  278. get cmdID() {
  279. return DrawPathCmd.ID;
  280. }
  281. }
  282. DrawPathCmd.ID = "DrawPath";
  283. class DrawPieCmd {
  284. static create(x, y, radius, startAngle, endAngle, fillColor, lineColor, lineWidth, vid) {
  285. var cmd = Pool.getItemByClass("DrawPieCmd", DrawPieCmd);
  286. cmd.x = x;
  287. cmd.y = y;
  288. cmd.radius = radius;
  289. cmd._startAngle = startAngle;
  290. cmd._endAngle = endAngle;
  291. cmd.fillColor = fillColor;
  292. cmd.lineColor = lineColor;
  293. cmd.lineWidth = lineWidth;
  294. cmd.vid = vid;
  295. return cmd;
  296. }
  297. recover() {
  298. this.fillColor = null;
  299. this.lineColor = null;
  300. Pool.recover("DrawPieCmd", this);
  301. }
  302. run(context, gx, gy) {
  303. context._drawPie(this.x + gx, this.y + gy, this.radius, this._startAngle, this._endAngle, this.fillColor, this.lineColor, this.lineWidth, this.vid);
  304. }
  305. get cmdID() {
  306. return DrawPieCmd.ID;
  307. }
  308. get startAngle() {
  309. return this._startAngle * 180 / Math.PI;
  310. }
  311. set startAngle(value) {
  312. this._startAngle = value * Math.PI / 180;
  313. }
  314. get endAngle() {
  315. return this._endAngle * 180 / Math.PI;
  316. }
  317. set endAngle(value) {
  318. this._endAngle = value * Math.PI / 180;
  319. }
  320. }
  321. DrawPieCmd.ID = "DrawPie";
  322. class DrawPolyCmd {
  323. static create(x, y, points, fillColor, lineColor, lineWidth, isConvexPolygon, vid) {
  324. var cmd = Pool.getItemByClass("DrawPolyCmd", DrawPolyCmd);
  325. cmd.x = x;
  326. cmd.y = y;
  327. cmd.points = points;
  328. cmd.fillColor = fillColor;
  329. cmd.lineColor = lineColor;
  330. cmd.lineWidth = lineWidth;
  331. cmd.isConvexPolygon = isConvexPolygon;
  332. cmd.vid = vid;
  333. return cmd;
  334. }
  335. recover() {
  336. this.points = null;
  337. this.fillColor = null;
  338. this.lineColor = null;
  339. Pool.recover("DrawPolyCmd", this);
  340. }
  341. run(context, gx, gy) {
  342. this.points && context._drawPoly(this.x + gx, this.y + gy, this.points, this.fillColor, this.lineColor, this.lineWidth, this.isConvexPolygon, this.vid);
  343. }
  344. get cmdID() {
  345. return DrawPolyCmd.ID;
  346. }
  347. }
  348. DrawPolyCmd.ID = "DrawPoly";
  349. class DrawRectCmd {
  350. static create(x, y, width, height, fillColor, lineColor, lineWidth) {
  351. var cmd = Pool.getItemByClass("DrawRectCmd", DrawRectCmd);
  352. cmd.x = x;
  353. cmd.y = y;
  354. cmd.width = width;
  355. cmd.height = height;
  356. cmd.fillColor = fillColor;
  357. cmd.lineColor = lineColor;
  358. cmd.lineWidth = lineWidth;
  359. return cmd;
  360. }
  361. recover() {
  362. this.fillColor = null;
  363. this.lineColor = null;
  364. Pool.recover("DrawRectCmd", this);
  365. }
  366. run(context, gx, gy) {
  367. context.drawRect(this.x + gx, this.y + gy, this.width, this.height, this.fillColor, this.lineColor, this.lineWidth);
  368. }
  369. get cmdID() {
  370. return DrawRectCmd.ID;
  371. }
  372. }
  373. DrawRectCmd.ID = "DrawRect";
  374. class Matrix {
  375. constructor(a = 1, b = 0, c = 0, d = 1, tx = 0, ty = 0, nums = 0) {
  376. this._bTransform = false;
  377. if (Matrix._createFun != null) {
  378. return Matrix._createFun(a, b, c, d, tx, ty, nums);
  379. }
  380. this.a = a;
  381. this.b = b;
  382. this.c = c;
  383. this.d = d;
  384. this.tx = tx;
  385. this.ty = ty;
  386. this._checkTransform();
  387. }
  388. identity() {
  389. this.a = this.d = 1;
  390. this.b = this.tx = this.ty = this.c = 0;
  391. this._bTransform = false;
  392. return this;
  393. }
  394. _checkTransform() {
  395. return this._bTransform = (this.a !== 1 || this.b !== 0 || this.c !== 0 || this.d !== 1);
  396. }
  397. setTranslate(x, y) {
  398. this.tx = x;
  399. this.ty = y;
  400. return this;
  401. }
  402. translate(x, y) {
  403. this.tx += x;
  404. this.ty += y;
  405. return this;
  406. }
  407. scale(x, y) {
  408. this.a *= x;
  409. this.d *= y;
  410. this.c *= x;
  411. this.b *= y;
  412. this.tx *= x;
  413. this.ty *= y;
  414. this._bTransform = true;
  415. return this;
  416. }
  417. rotate(angle) {
  418. var cos = Math.cos(angle);
  419. var sin = Math.sin(angle);
  420. var a1 = this.a;
  421. var c1 = this.c;
  422. var tx1 = this.tx;
  423. this.a = a1 * cos - this.b * sin;
  424. this.b = a1 * sin + this.b * cos;
  425. this.c = c1 * cos - this.d * sin;
  426. this.d = c1 * sin + this.d * cos;
  427. this.tx = tx1 * cos - this.ty * sin;
  428. this.ty = tx1 * sin + this.ty * cos;
  429. this._bTransform = true;
  430. return this;
  431. }
  432. skew(x, y) {
  433. var tanX = Math.tan(x);
  434. var tanY = Math.tan(y);
  435. var a1 = this.a;
  436. var b1 = this.b;
  437. this.a += tanY * this.c;
  438. this.b += tanY * this.d;
  439. this.c += tanX * a1;
  440. this.d += tanX * b1;
  441. return this;
  442. }
  443. invertTransformPoint(out) {
  444. var a1 = this.a;
  445. var b1 = this.b;
  446. var c1 = this.c;
  447. var d1 = this.d;
  448. var tx1 = this.tx;
  449. var n = a1 * d1 - b1 * c1;
  450. var a2 = d1 / n;
  451. var b2 = -b1 / n;
  452. var c2 = -c1 / n;
  453. var d2 = a1 / n;
  454. var tx2 = (c1 * this.ty - d1 * tx1) / n;
  455. var ty2 = -(a1 * this.ty - b1 * tx1) / n;
  456. return out.setTo(a2 * out.x + c2 * out.y + tx2, b2 * out.x + d2 * out.y + ty2);
  457. }
  458. transformPoint(out) {
  459. return out.setTo(this.a * out.x + this.c * out.y + this.tx, this.b * out.x + this.d * out.y + this.ty);
  460. }
  461. transformPointN(out) {
  462. return out.setTo(this.a * out.x + this.c * out.y, this.b * out.x + this.d * out.y);
  463. }
  464. getScaleX() {
  465. return this.b === 0 ? this.a : Math.sqrt(this.a * this.a + this.b * this.b);
  466. }
  467. getScaleY() {
  468. return this.c === 0 ? this.d : Math.sqrt(this.c * this.c + this.d * this.d);
  469. }
  470. invert() {
  471. var a1 = this.a;
  472. var b1 = this.b;
  473. var c1 = this.c;
  474. var d1 = this.d;
  475. var tx1 = this.tx;
  476. var n = a1 * d1 - b1 * c1;
  477. this.a = d1 / n;
  478. this.b = -b1 / n;
  479. this.c = -c1 / n;
  480. this.d = a1 / n;
  481. this.tx = (c1 * this.ty - d1 * tx1) / n;
  482. this.ty = -(a1 * this.ty - b1 * tx1) / n;
  483. return this;
  484. }
  485. setTo(a, b, c, d, tx, ty) {
  486. this.a = a, this.b = b, this.c = c, this.d = d, this.tx = tx, this.ty = ty;
  487. return this;
  488. }
  489. concat(matrix) {
  490. var a = this.a;
  491. var c = this.c;
  492. var tx = this.tx;
  493. this.a = a * matrix.a + this.b * matrix.c;
  494. this.b = a * matrix.b + this.b * matrix.d;
  495. this.c = c * matrix.a + this.d * matrix.c;
  496. this.d = c * matrix.b + this.d * matrix.d;
  497. this.tx = tx * matrix.a + this.ty * matrix.c + matrix.tx;
  498. this.ty = tx * matrix.b + this.ty * matrix.d + matrix.ty;
  499. return this;
  500. }
  501. static mul(m1, m2, out) {
  502. var aa = m1.a, ab = m1.b, ac = m1.c, ad = m1.d, atx = m1.tx, aty = m1.ty;
  503. var ba = m2.a, bb = m2.b, bc = m2.c, bd = m2.d, btx = m2.tx, bty = m2.ty;
  504. if (bb !== 0 || bc !== 0) {
  505. out.a = aa * ba + ab * bc;
  506. out.b = aa * bb + ab * bd;
  507. out.c = ac * ba + ad * bc;
  508. out.d = ac * bb + ad * bd;
  509. out.tx = ba * atx + bc * aty + btx;
  510. out.ty = bb * atx + bd * aty + bty;
  511. }
  512. else {
  513. out.a = aa * ba;
  514. out.b = ab * bd;
  515. out.c = ac * ba;
  516. out.d = ad * bd;
  517. out.tx = ba * atx + btx;
  518. out.ty = bd * aty + bty;
  519. }
  520. return out;
  521. }
  522. static mul16(m1, m2, out) {
  523. var aa = m1.a, ab = m1.b, ac = m1.c, ad = m1.d, atx = m1.tx, aty = m1.ty;
  524. var ba = m2.a, bb = m2.b, bc = m2.c, bd = m2.d, btx = m2.tx, bty = m2.ty;
  525. if (bb !== 0 || bc !== 0) {
  526. out[0] = aa * ba + ab * bc;
  527. out[1] = aa * bb + ab * bd;
  528. out[4] = ac * ba + ad * bc;
  529. out[5] = ac * bb + ad * bd;
  530. out[12] = ba * atx + bc * aty + btx;
  531. out[13] = bb * atx + bd * aty + bty;
  532. }
  533. else {
  534. out[0] = aa * ba;
  535. out[1] = ab * bd;
  536. out[4] = ac * ba;
  537. out[5] = ad * bd;
  538. out[12] = ba * atx + btx;
  539. out[13] = bd * aty + bty;
  540. }
  541. return out;
  542. }
  543. scaleEx(x, y) {
  544. var ba = this.a, bb = this.b, bc = this.c, bd = this.d;
  545. if (bb !== 0 || bc !== 0) {
  546. this.a = x * ba;
  547. this.b = x * bb;
  548. this.c = y * bc;
  549. this.d = y * bd;
  550. }
  551. else {
  552. this.a = x * ba;
  553. this.b = 0 * bd;
  554. this.c = 0 * ba;
  555. this.d = y * bd;
  556. }
  557. this._bTransform = true;
  558. }
  559. rotateEx(angle) {
  560. var cos = Math.cos(angle);
  561. var sin = Math.sin(angle);
  562. var ba = this.a, bb = this.b, bc = this.c, bd = this.d;
  563. if (bb !== 0 || bc !== 0) {
  564. this.a = cos * ba + sin * bc;
  565. this.b = cos * bb + sin * bd;
  566. this.c = -sin * ba + cos * bc;
  567. this.d = -sin * bb + cos * bd;
  568. }
  569. else {
  570. this.a = cos * ba;
  571. this.b = sin * bd;
  572. this.c = -sin * ba;
  573. this.d = cos * bd;
  574. }
  575. this._bTransform = true;
  576. }
  577. clone() {
  578. var dec = Matrix.create();
  579. dec.a = this.a;
  580. dec.b = this.b;
  581. dec.c = this.c;
  582. dec.d = this.d;
  583. dec.tx = this.tx;
  584. dec.ty = this.ty;
  585. dec._bTransform = this._bTransform;
  586. return dec;
  587. }
  588. copyTo(dec) {
  589. dec.a = this.a;
  590. dec.b = this.b;
  591. dec.c = this.c;
  592. dec.d = this.d;
  593. dec.tx = this.tx;
  594. dec.ty = this.ty;
  595. dec._bTransform = this._bTransform;
  596. return dec;
  597. }
  598. toString() {
  599. return this.a + "," + this.b + "," + this.c + "," + this.d + "," + this.tx + "," + this.ty;
  600. }
  601. destroy() {
  602. this.recover();
  603. }
  604. recover() {
  605. Pool.recover("Matrix", this.identity());
  606. }
  607. static create() {
  608. return Pool.getItemByClass("Matrix", Matrix);
  609. }
  610. }
  611. Matrix.EMPTY = new Matrix();
  612. Matrix.TEMP = new Matrix();
  613. Matrix._createFun = null;
  614. class Point {
  615. constructor(x = 0, y = 0) {
  616. this.x = x;
  617. this.y = y;
  618. }
  619. static create() {
  620. return Pool.getItemByClass("Point", Point);
  621. }
  622. setTo(x, y) {
  623. this.x = x;
  624. this.y = y;
  625. return this;
  626. }
  627. reset() {
  628. this.x = this.y = 0;
  629. return this;
  630. }
  631. recover() {
  632. Pool.recover("Point", this.reset());
  633. }
  634. distance(x, y) {
  635. return Math.sqrt((this.x - x) * (this.x - x) + (this.y - y) * (this.y - y));
  636. }
  637. toString() {
  638. return this.x + "," + this.y;
  639. }
  640. normalize() {
  641. var d = Math.sqrt(this.x * this.x + this.y * this.y);
  642. if (d > 0) {
  643. var id = 1.0 / d;
  644. this.x *= id;
  645. this.y *= id;
  646. }
  647. }
  648. copy(point) {
  649. return this.setTo(point.x, point.y);
  650. }
  651. }
  652. Point.TEMP = new Point();
  653. Point.EMPTY = new Point();
  654. class Rectangle {
  655. constructor(x = 0, y = 0, width = 0, height = 0) {
  656. this.x = x;
  657. this.y = y;
  658. this.width = width;
  659. this.height = height;
  660. }
  661. get right() {
  662. return this.x + this.width;
  663. }
  664. get bottom() {
  665. return this.y + this.height;
  666. }
  667. setTo(x, y, width, height) {
  668. this.x = x;
  669. this.y = y;
  670. this.width = width;
  671. this.height = height;
  672. return this;
  673. }
  674. reset() {
  675. this.x = this.y = this.width = this.height = 0;
  676. return this;
  677. }
  678. recover() {
  679. if (this == Rectangle.TEMP || this == Rectangle.EMPTY) {
  680. console.log("recover Temp or Empty:", this);
  681. return;
  682. }
  683. Pool.recover("Rectangle", this.reset());
  684. }
  685. static create() {
  686. return Pool.getItemByClass("Rectangle", Rectangle);
  687. }
  688. copyFrom(source) {
  689. this.x = source.x;
  690. this.y = source.y;
  691. this.width = source.width;
  692. this.height = source.height;
  693. return this;
  694. }
  695. contains(x, y) {
  696. if (this.width <= 0 || this.height <= 0)
  697. return false;
  698. if (x >= this.x && x < this.right) {
  699. if (y >= this.y && y < this.bottom) {
  700. return true;
  701. }
  702. }
  703. return false;
  704. }
  705. intersects(rect) {
  706. return !(rect.x > (this.x + this.width) || (rect.x + rect.width) < this.x || rect.y > (this.y + this.height) || (rect.y + rect.height) < this.y);
  707. }
  708. intersection(rect, out = null) {
  709. if (!this.intersects(rect))
  710. return null;
  711. out || (out = new Rectangle());
  712. out.x = Math.max(this.x, rect.x);
  713. out.y = Math.max(this.y, rect.y);
  714. out.width = Math.min(this.right, rect.right) - out.x;
  715. out.height = Math.min(this.bottom, rect.bottom) - out.y;
  716. return out;
  717. }
  718. union(source, out = null) {
  719. out || (out = new Rectangle());
  720. this.clone(out);
  721. if (source.width <= 0 || source.height <= 0)
  722. return out;
  723. out.addPoint(source.x, source.y);
  724. out.addPoint(source.right, source.bottom);
  725. return this;
  726. }
  727. clone(out = null) {
  728. out || (out = new Rectangle());
  729. out.x = this.x;
  730. out.y = this.y;
  731. out.width = this.width;
  732. out.height = this.height;
  733. return out;
  734. }
  735. toString() {
  736. return this.x + "," + this.y + "," + this.width + "," + this.height;
  737. }
  738. equals(rect) {
  739. if (!rect || rect.x !== this.x || rect.y !== this.y || rect.width !== this.width || rect.height !== this.height)
  740. return false;
  741. return true;
  742. }
  743. addPoint(x, y) {
  744. this.x > x && (this.width += this.x - x, this.x = x);
  745. this.y > y && (this.height += this.y - y, this.y = y);
  746. if (this.width < x - this.x)
  747. this.width = x - this.x;
  748. if (this.height < y - this.y)
  749. this.height = y - this.y;
  750. return this;
  751. }
  752. _getBoundPoints() {
  753. var rst = Rectangle._temB;
  754. rst.length = 0;
  755. if (this.width == 0 || this.height == 0)
  756. return rst;
  757. rst.push(this.x, this.y, this.x + this.width, this.y, this.x, this.y + this.height, this.x + this.width, this.y + this.height);
  758. return rst;
  759. }
  760. static _getBoundPointS(x, y, width, height) {
  761. var rst = Rectangle._temA;
  762. rst.length = 0;
  763. if (width == 0 || height == 0)
  764. return rst;
  765. rst.push(x, y, x + width, y, x, y + height, x + width, y + height);
  766. return rst;
  767. }
  768. static _getWrapRec(pointList, rst = null) {
  769. if (!pointList || pointList.length < 1)
  770. return rst ? rst.setTo(0, 0, 0, 0) : Rectangle.TEMP.setTo(0, 0, 0, 0);
  771. rst = rst ? rst : Rectangle.create();
  772. var i, len = pointList.length, minX, maxX, minY, maxY, tPoint = Point.TEMP;
  773. minX = minY = 99999;
  774. maxX = maxY = -minX;
  775. for (i = 0; i < len; i += 2) {
  776. tPoint.x = pointList[i];
  777. tPoint.y = pointList[i + 1];
  778. minX = minX < tPoint.x ? minX : tPoint.x;
  779. minY = minY < tPoint.y ? minY : tPoint.y;
  780. maxX = maxX > tPoint.x ? maxX : tPoint.x;
  781. maxY = maxY > tPoint.y ? maxY : tPoint.y;
  782. }
  783. return rst.setTo(minX, minY, maxX - minX, maxY - minY);
  784. }
  785. isEmpty() {
  786. if (this.width <= 0 || this.height <= 0)
  787. return true;
  788. return false;
  789. }
  790. }
  791. Rectangle.EMPTY = new Rectangle();
  792. Rectangle.TEMP = new Rectangle();
  793. Rectangle._temB = [];
  794. Rectangle._temA = [];
  795. class LayaGL {
  796. }
  797. LayaGL.ARRAY_BUFFER_TYPE_DATA = 0;
  798. LayaGL.ARRAY_BUFFER_TYPE_CMD = 1;
  799. LayaGL.ARRAY_BUFFER_REF_REFERENCE = 0;
  800. LayaGL.ARRAY_BUFFER_REF_COPY = 1;
  801. LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_ID = 0;
  802. LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_DATA = 1;
  803. class WebGLContext {
  804. static __init__() {
  805. var gl = LayaGL.instance;
  806. WebGLContext._depthFunc = gl.LESS;
  807. WebGLContext._blendEquation = gl.FUNC_ADD;
  808. WebGLContext._blendEquationRGB = gl.FUNC_ADD;
  809. WebGLContext._blendEquationAlpha = gl.FUNC_ADD;
  810. WebGLContext._sFactor = gl.ONE;
  811. WebGLContext._dFactor = gl.ZERO;
  812. WebGLContext._sFactorAlpha = gl.ONE;
  813. WebGLContext._dFactorAlpha = gl.ZERO;
  814. WebGLContext._activedTextureID = gl.TEXTURE0;
  815. WebGLContext._glTextureIDs = [gl.TEXTURE0, gl.TEXTURE1, gl.TEXTURE2, gl.TEXTURE3, gl.TEXTURE4, gl.TEXTURE5, gl.TEXTURE6, gl.TEXTURE7];
  816. }
  817. static useProgram(gl, program) {
  818. if (WebGLContext._useProgram === program)
  819. return false;
  820. gl.useProgram(program);
  821. WebGLContext._useProgram = program;
  822. return true;
  823. }
  824. static setDepthTest(gl, value) {
  825. value !== WebGLContext._depthTest && (WebGLContext._depthTest = value, value ? gl.enable(gl.DEPTH_TEST) : gl.disable(gl.DEPTH_TEST));
  826. }
  827. static setDepthMask(gl, value) {
  828. value !== WebGLContext._depthMask && (WebGLContext._depthMask = value, gl.depthMask(value));
  829. }
  830. static setDepthFunc(gl, value) {
  831. value !== WebGLContext._depthFunc && (WebGLContext._depthFunc = value, gl.depthFunc(value));
  832. }
  833. static setBlend(gl, value) {
  834. value !== WebGLContext._blend && (WebGLContext._blend = value, value ? gl.enable(gl.BLEND) : gl.disable(gl.BLEND));
  835. }
  836. static setBlendEquation(gl, blendEquation) {
  837. if (blendEquation !== WebGLContext._blendEquation) {
  838. WebGLContext._blendEquation = blendEquation;
  839. WebGLContext._blendEquationRGB = WebGLContext._blendEquationAlpha = null;
  840. gl.blendEquation(blendEquation);
  841. }
  842. }
  843. static setBlendEquationSeparate(gl, blendEquationRGB, blendEquationAlpha) {
  844. if (blendEquationRGB !== WebGLContext._blendEquationRGB || blendEquationAlpha !== WebGLContext._blendEquationAlpha) {
  845. WebGLContext._blendEquationRGB = blendEquationRGB;
  846. WebGLContext._blendEquationAlpha = blendEquationAlpha;
  847. WebGLContext._blendEquation = null;
  848. gl.blendEquationSeparate(blendEquationRGB, blendEquationAlpha);
  849. }
  850. }
  851. static setBlendFunc(gl, sFactor, dFactor) {
  852. if (sFactor !== WebGLContext._sFactor || dFactor !== WebGLContext._dFactor) {
  853. WebGLContext._sFactor = sFactor;
  854. WebGLContext._dFactor = dFactor;
  855. WebGLContext._sFactorRGB = null;
  856. WebGLContext._dFactorRGB = null;
  857. WebGLContext._sFactorAlpha = null;
  858. WebGLContext._dFactorAlpha = null;
  859. gl.blendFunc(sFactor, dFactor);
  860. }
  861. }
  862. static setBlendFuncSeperate(gl, srcRGB, dstRGB, srcAlpha, dstAlpha) {
  863. if (srcRGB !== WebGLContext._sFactorRGB || dstRGB !== WebGLContext._dFactorRGB || srcAlpha !== WebGLContext._sFactorAlpha || dstAlpha !== WebGLContext._dFactorAlpha) {
  864. WebGLContext._sFactorRGB = srcRGB;
  865. WebGLContext._dFactorRGB = dstRGB;
  866. WebGLContext._sFactorAlpha = srcAlpha;
  867. WebGLContext._dFactorAlpha = dstAlpha;
  868. WebGLContext._sFactor = null;
  869. WebGLContext._dFactor = null;
  870. gl.blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
  871. }
  872. }
  873. static setCullFace(gl, value) {
  874. value !== WebGLContext._cullFace && (WebGLContext._cullFace = value, value ? gl.enable(gl.CULL_FACE) : gl.disable(gl.CULL_FACE));
  875. }
  876. static setFrontFace(gl, value) {
  877. value !== WebGLContext._frontFace && (WebGLContext._frontFace = value, gl.frontFace(value));
  878. }
  879. static activeTexture(gl, textureID) {
  880. if (WebGLContext._activedTextureID !== textureID) {
  881. gl.activeTexture(textureID);
  882. WebGLContext._activedTextureID = textureID;
  883. }
  884. }
  885. static bindTexture(gl, target, texture) {
  886. if (WebGLContext._activeTextures[WebGLContext._activedTextureID - gl.TEXTURE0] !== texture) {
  887. gl.bindTexture(target, texture);
  888. WebGLContext._activeTextures[WebGLContext._activedTextureID - gl.TEXTURE0] = texture;
  889. }
  890. }
  891. static __init_native() {
  892. if (!ILaya.Render.supportWebGLPlusRendering)
  893. return;
  894. var webGLContext = WebGLContext;
  895. webGLContext.activeTexture = webGLContext.activeTextureForNative;
  896. webGLContext.bindTexture = webGLContext.bindTextureForNative;
  897. }
  898. static useProgramForNative(gl, program) {
  899. gl.useProgram(program);
  900. return true;
  901. }
  902. static setDepthTestForNative(gl, value) {
  903. if (value)
  904. gl.enable(gl.DEPTH_TEST);
  905. else
  906. gl.disable(gl.DEPTH_TEST);
  907. }
  908. static setDepthMaskForNative(gl, value) {
  909. gl.depthMask(value);
  910. }
  911. static setDepthFuncForNative(gl, value) {
  912. gl.depthFunc(value);
  913. }
  914. static setBlendForNative(gl, value) {
  915. if (value)
  916. gl.enable(gl.BLEND);
  917. else
  918. gl.disable(gl.BLEND);
  919. }
  920. static setBlendFuncForNative(gl, sFactor, dFactor) {
  921. gl.blendFunc(sFactor, dFactor);
  922. }
  923. static setCullFaceForNative(gl, value) {
  924. if (value)
  925. gl.enable(gl.CULL_FACE);
  926. else
  927. gl.disable(gl.CULL_FACE);
  928. }
  929. static setFrontFaceForNative(gl, value) {
  930. gl.frontFace(value);
  931. }
  932. static activeTextureForNative(gl, textureID) {
  933. gl.activeTexture(textureID);
  934. }
  935. static bindTextureForNative(gl, target, texture) {
  936. gl.bindTexture(target, texture);
  937. }
  938. static bindVertexArrayForNative(gl, vertexArray) {
  939. gl.bindVertexArray(vertexArray);
  940. }
  941. }
  942. WebGLContext._activeTextures = new Array(8);
  943. WebGLContext._useProgram = null;
  944. WebGLContext._depthTest = true;
  945. WebGLContext._depthMask = true;
  946. WebGLContext._blend = false;
  947. WebGLContext._cullFace = false;
  948. WebGLContext.mainContext = null;
  949. class Handler {
  950. constructor(caller = null, method = null, args = null, once = false) {
  951. this.once = false;
  952. this._id = 0;
  953. this.setTo(caller, method, args, once);
  954. }
  955. setTo(caller, method, args, once = false) {
  956. this._id = Handler._gid++;
  957. this.caller = caller;
  958. this.method = method;
  959. this.args = args;
  960. this.once = once;
  961. return this;
  962. }
  963. run() {
  964. if (this.method == null)
  965. return null;
  966. var id = this._id;
  967. var result = this.method.apply(this.caller, this.args);
  968. this._id === id && this.once && this.recover();
  969. return result;
  970. }
  971. runWith(data) {
  972. if (this.method == null)
  973. return null;
  974. var id = this._id;
  975. if (data == null)
  976. var result = this.method.apply(this.caller, this.args);
  977. else if (!this.args && !data.unshift)
  978. result = this.method.call(this.caller, data);
  979. else if (this.args)
  980. result = this.method.apply(this.caller, this.args.concat(data));
  981. else
  982. result = this.method.apply(this.caller, data);
  983. this._id === id && this.once && this.recover();
  984. return result;
  985. }
  986. clear() {
  987. this.caller = null;
  988. this.method = null;
  989. this.args = null;
  990. return this;
  991. }
  992. recover() {
  993. if (this._id > 0) {
  994. this._id = 0;
  995. Handler._pool.push(this.clear());
  996. }
  997. }
  998. static create(caller, method, args = null, once = true) {
  999. if (Handler._pool.length)
  1000. return Handler._pool.pop().setTo(caller, method, args, once);
  1001. return new Handler(caller, method, args, once);
  1002. }
  1003. }
  1004. Handler._pool = [];
  1005. Handler._gid = 1;
  1006. class EventDispatcher {
  1007. hasListener(type) {
  1008. var listener = this._events && this._events[type];
  1009. return !!listener;
  1010. }
  1011. event(type, data = null) {
  1012. if (!this._events || !this._events[type])
  1013. return false;
  1014. var listeners = this._events[type];
  1015. if (listeners.run) {
  1016. if (listeners.once)
  1017. delete this._events[type];
  1018. data != null ? listeners.runWith(data) : listeners.run();
  1019. }
  1020. else {
  1021. for (var i = 0, n = listeners.length; i < n; i++) {
  1022. var listener = listeners[i];
  1023. if (listener) {
  1024. (data != null) ? listener.runWith(data) : listener.run();
  1025. }
  1026. if (!listener || listener.once) {
  1027. listeners.splice(i, 1);
  1028. i--;
  1029. n--;
  1030. }
  1031. }
  1032. if (listeners.length === 0 && this._events)
  1033. delete this._events[type];
  1034. }
  1035. return true;
  1036. }
  1037. on(type, caller, listener, args = null) {
  1038. return this._createListener(type, caller, listener, args, false);
  1039. }
  1040. once(type, caller, listener, args = null) {
  1041. return this._createListener(type, caller, listener, args, true);
  1042. }
  1043. _createListener(type, caller, listener, args, once, offBefore = true) {
  1044. offBefore && this.off(type, caller, listener, once);
  1045. var handler = EventHandler.create(caller || this, listener, args, once);
  1046. this._events || (this._events = {});
  1047. var events = this._events;
  1048. if (!events[type])
  1049. events[type] = handler;
  1050. else {
  1051. if (!events[type].run)
  1052. events[type].push(handler);
  1053. else
  1054. events[type] = [events[type], handler];
  1055. }
  1056. return this;
  1057. }
  1058. off(type, caller, listener, onceOnly = false) {
  1059. if (!this._events || !this._events[type])
  1060. return this;
  1061. var listeners = this._events[type];
  1062. if (listeners != null) {
  1063. if (listeners.run) {
  1064. if ((!caller || listeners.caller === caller) && (listener == null || listeners.method === listener) && (!onceOnly || listeners.once)) {
  1065. delete this._events[type];
  1066. listeners.recover();
  1067. }
  1068. }
  1069. else {
  1070. var count = 0;
  1071. for (var i = 0, n = listeners.length; i < n; i++) {
  1072. var item = listeners[i];
  1073. if (!item) {
  1074. count++;
  1075. continue;
  1076. }
  1077. if (item && (!caller || item.caller === caller) && (listener == null || item.method === listener) && (!onceOnly || item.once)) {
  1078. count++;
  1079. listeners[i] = null;
  1080. item.recover();
  1081. }
  1082. }
  1083. if (count === n)
  1084. delete this._events[type];
  1085. }
  1086. }
  1087. return this;
  1088. }
  1089. offAll(type = null) {
  1090. var events = this._events;
  1091. if (!events)
  1092. return this;
  1093. if (type) {
  1094. this._recoverHandlers(events[type]);
  1095. delete events[type];
  1096. }
  1097. else {
  1098. for (var name in events) {
  1099. this._recoverHandlers(events[name]);
  1100. }
  1101. this._events = null;
  1102. }
  1103. return this;
  1104. }
  1105. offAllCaller(caller) {
  1106. if (caller && this._events) {
  1107. for (var name in this._events) {
  1108. this.off(name, caller, null);
  1109. }
  1110. }
  1111. return this;
  1112. }
  1113. _recoverHandlers(arr) {
  1114. if (!arr)
  1115. return;
  1116. if (arr.run) {
  1117. arr.recover();
  1118. }
  1119. else {
  1120. for (var i = arr.length - 1; i > -1; i--) {
  1121. if (arr[i]) {
  1122. arr[i].recover();
  1123. arr[i] = null;
  1124. }
  1125. }
  1126. }
  1127. }
  1128. isMouseEvent(type) {
  1129. return EventDispatcher.MOUSE_EVENTS[type] || false;
  1130. }
  1131. }
  1132. EventDispatcher.MOUSE_EVENTS = { "rightmousedown": true, "rightmouseup": true, "rightclick": true, "mousedown": true, "mouseup": true, "mousemove": true, "mouseover": true, "mouseout": true, "click": true, "doubleclick": true };
  1133. class EventHandler extends Handler {
  1134. constructor(caller, method, args, once) {
  1135. super(caller, method, args, once);
  1136. }
  1137. recover() {
  1138. if (this._id > 0) {
  1139. this._id = 0;
  1140. EventHandler._pool.push(this.clear());
  1141. }
  1142. }
  1143. static create(caller, method, args = null, once = true) {
  1144. if (EventHandler._pool.length)
  1145. return EventHandler._pool.pop().setTo(caller, method, args, once);
  1146. return new EventHandler(caller, method, args, once);
  1147. }
  1148. }
  1149. EventHandler._pool = [];
  1150. class URL {
  1151. constructor(url) {
  1152. this._url = URL.formatURL(url);
  1153. this._path = URL.getPath(url);
  1154. }
  1155. get url() {
  1156. return this._url;
  1157. }
  1158. get path() {
  1159. return this._path;
  1160. }
  1161. static set basePath(value) {
  1162. URL._basePath = ILaya.Laya._getUrlPath();
  1163. URL._basePath = URL.formatURL(value);
  1164. }
  1165. static get basePath() {
  1166. return URL._basePath;
  1167. }
  1168. static formatURL(url) {
  1169. if (!url)
  1170. return "null path";
  1171. if (url.indexOf(":") > 0)
  1172. return url;
  1173. if (URL.customFormat != null)
  1174. url = URL.customFormat(url);
  1175. if (url.indexOf(":") > 0)
  1176. return url;
  1177. var char1 = url.charAt(0);
  1178. if (char1 === ".") {
  1179. return URL._formatRelativePath(URL._basePath + url);
  1180. }
  1181. else if (char1 === '~') {
  1182. return URL.rootPath + url.substring(1);
  1183. }
  1184. else if (char1 === "d") {
  1185. if (url.indexOf("data:image") === 0)
  1186. return url;
  1187. }
  1188. else if (char1 === "/") {
  1189. return url;
  1190. }
  1191. return URL._basePath + url;
  1192. }
  1193. static _formatRelativePath(value) {
  1194. var parts = value.split("/");
  1195. for (var i = 0, len = parts.length; i < len; i++) {
  1196. if (parts[i] == '..') {
  1197. parts.splice(i - 1, 2);
  1198. i -= 2;
  1199. }
  1200. }
  1201. return parts.join('/');
  1202. }
  1203. static getPath(url) {
  1204. var ofs = url.lastIndexOf('/');
  1205. return ofs > 0 ? url.substr(0, ofs + 1) : "";
  1206. }
  1207. static getFileName(url) {
  1208. var ofs = url.lastIndexOf('/');
  1209. return ofs > 0 ? url.substr(ofs + 1) : url;
  1210. }
  1211. static getAdptedFilePath(url) {
  1212. if (!URL.exportSceneToJson || !url)
  1213. return url;
  1214. var i, len;
  1215. len = URL._adpteTypeList.length;
  1216. var tArr;
  1217. for (i = 0; i < len; i++) {
  1218. tArr = URL._adpteTypeList[i];
  1219. url = url.replace(tArr[0], tArr[1]);
  1220. }
  1221. return url;
  1222. }
  1223. }
  1224. URL.version = {};
  1225. URL.exportSceneToJson = false;
  1226. URL._basePath = "";
  1227. URL.rootPath = "";
  1228. URL.customFormat = function (url) {
  1229. var newUrl = URL.version[url];
  1230. if (!window.conch && newUrl)
  1231. url += "?v=" + newUrl;
  1232. return url;
  1233. };
  1234. URL._adpteTypeList = [[".scene3d", ".json"], [".scene", ".json"], [".taa", ".json"], [".prefab", ".json"]];
  1235. class Resource extends EventDispatcher {
  1236. constructor() {
  1237. super();
  1238. this._id = 0;
  1239. this._url = null;
  1240. this._cpuMemory = 0;
  1241. this._gpuMemory = 0;
  1242. this._destroyed = false;
  1243. this._referenceCount = 0;
  1244. this.lock = false;
  1245. this.name = null;
  1246. this._id = ++Resource._uniqueIDCounter;
  1247. this._destroyed = false;
  1248. this._referenceCount = 0;
  1249. Resource._idResourcesMap[this.id] = this;
  1250. this.lock = false;
  1251. }
  1252. static get cpuMemory() {
  1253. return Resource._cpuMemory;
  1254. }
  1255. static get gpuMemory() {
  1256. return Resource._gpuMemory;
  1257. }
  1258. static _addCPUMemory(size) {
  1259. Resource._cpuMemory += size;
  1260. }
  1261. static _addGPUMemory(size) {
  1262. Resource._gpuMemory += size;
  1263. }
  1264. static _addMemory(cpuSize, gpuSize) {
  1265. Resource._cpuMemory += cpuSize;
  1266. Resource._gpuMemory += gpuSize;
  1267. }
  1268. static getResourceByID(id) {
  1269. return Resource._idResourcesMap[id];
  1270. }
  1271. static getResourceByURL(url, index = 0) {
  1272. return Resource._urlResourcesMap[url][index];
  1273. }
  1274. static destroyUnusedResources() {
  1275. for (var k in Resource._idResourcesMap) {
  1276. var res = Resource._idResourcesMap[k];
  1277. if (!res.lock && res._referenceCount === 0)
  1278. res.destroy();
  1279. }
  1280. }
  1281. get id() {
  1282. return this._id;
  1283. }
  1284. get url() {
  1285. return this._url;
  1286. }
  1287. get cpuMemory() {
  1288. return this._cpuMemory;
  1289. }
  1290. get gpuMemory() {
  1291. return this._gpuMemory;
  1292. }
  1293. get destroyed() {
  1294. return this._destroyed;
  1295. }
  1296. get referenceCount() {
  1297. return this._referenceCount;
  1298. }
  1299. _setCPUMemory(value) {
  1300. var offsetValue = value - this._cpuMemory;
  1301. this._cpuMemory = value;
  1302. Resource._addCPUMemory(offsetValue);
  1303. }
  1304. _setGPUMemory(value) {
  1305. var offsetValue = value - this._gpuMemory;
  1306. this._gpuMemory = value;
  1307. Resource._addGPUMemory(offsetValue);
  1308. }
  1309. _setCreateURL(url) {
  1310. url = URL.formatURL(url);
  1311. if (this._url !== url) {
  1312. var resList;
  1313. if (this._url) {
  1314. resList = Resource._urlResourcesMap[this._url];
  1315. resList.splice(resList.indexOf(this), 1);
  1316. (resList.length === 0) && (delete Resource._urlResourcesMap[this._url]);
  1317. }
  1318. if (url) {
  1319. resList = Resource._urlResourcesMap[url];
  1320. (resList) || (Resource._urlResourcesMap[url] = resList = []);
  1321. resList.push(this);
  1322. }
  1323. this._url = url;
  1324. }
  1325. }
  1326. _addReference(count = 1) {
  1327. this._referenceCount += count;
  1328. }
  1329. _removeReference(count = 1) {
  1330. this._referenceCount -= count;
  1331. }
  1332. _clearReference() {
  1333. this._referenceCount = 0;
  1334. }
  1335. _recoverResource() {
  1336. }
  1337. _disposeResource() {
  1338. }
  1339. _activeResource() {
  1340. }
  1341. destroy() {
  1342. if (this._destroyed)
  1343. return;
  1344. this._destroyed = true;
  1345. this.lock = false;
  1346. this._disposeResource();
  1347. delete Resource._idResourcesMap[this.id];
  1348. var resList;
  1349. if (this._url) {
  1350. resList = Resource._urlResourcesMap[this._url];
  1351. if (resList) {
  1352. resList.splice(resList.indexOf(this), 1);
  1353. (resList.length === 0) && (delete Resource._urlResourcesMap[this._url]);
  1354. }
  1355. var resou = ILaya.Loader.loadedMap[this._url];
  1356. (resou == this) && (delete ILaya.Loader.loadedMap[this._url]);
  1357. }
  1358. }
  1359. }
  1360. Resource._uniqueIDCounter = 0;
  1361. Resource._idResourcesMap = {};
  1362. Resource._urlResourcesMap = {};
  1363. Resource._cpuMemory = 0;
  1364. Resource._gpuMemory = 0;
  1365. class Bitmap extends Resource {
  1366. get width() {
  1367. return this._width;
  1368. }
  1369. set width(width) {
  1370. this._width = width;
  1371. }
  1372. get height() {
  1373. return this._height;
  1374. }
  1375. set height(height) {
  1376. this._height = height;
  1377. }
  1378. constructor() {
  1379. super();
  1380. this._width = -1;
  1381. this._height = -1;
  1382. }
  1383. _getSource() {
  1384. throw "Bitmap: must override it.";
  1385. }
  1386. }
  1387. (function (TextureFormat) {
  1388. TextureFormat[TextureFormat["R8G8B8"] = 0] = "R8G8B8";
  1389. TextureFormat[TextureFormat["R8G8B8A8"] = 1] = "R8G8B8A8";
  1390. TextureFormat[TextureFormat["Alpha8"] = 2] = "Alpha8";
  1391. TextureFormat[TextureFormat["DXT1"] = 3] = "DXT1";
  1392. TextureFormat[TextureFormat["DXT5"] = 4] = "DXT5";
  1393. TextureFormat[TextureFormat["ETC1RGB"] = 5] = "ETC1RGB";
  1394. TextureFormat[TextureFormat["PVRTCRGB_2BPPV"] = 9] = "PVRTCRGB_2BPPV";
  1395. TextureFormat[TextureFormat["PVRTCRGBA_2BPPV"] = 10] = "PVRTCRGBA_2BPPV";
  1396. TextureFormat[TextureFormat["PVRTCRGB_4BPPV"] = 11] = "PVRTCRGB_4BPPV";
  1397. TextureFormat[TextureFormat["PVRTCRGBA_4BPPV"] = 12] = "PVRTCRGBA_4BPPV";
  1398. TextureFormat[TextureFormat["R32G32B32A32"] = 15] = "R32G32B32A32";
  1399. })(exports.TextureFormat || (exports.TextureFormat = {}));
  1400. class BaseTexture extends Bitmap {
  1401. constructor(format, mipMap) {
  1402. super();
  1403. this._wrapModeU = BaseTexture.WARPMODE_REPEAT;
  1404. this._wrapModeV = BaseTexture.WARPMODE_REPEAT;
  1405. this._filterMode = BaseTexture.FILTERMODE_BILINEAR;
  1406. this._readyed = false;
  1407. this._width = -1;
  1408. this._height = -1;
  1409. this._format = format;
  1410. this._mipmap = mipMap;
  1411. this._anisoLevel = 1;
  1412. this._glTexture = LayaGL.instance.createTexture();
  1413. }
  1414. get mipmap() {
  1415. return this._mipmap;
  1416. }
  1417. get format() {
  1418. return this._format;
  1419. }
  1420. get wrapModeU() {
  1421. return this._wrapModeU;
  1422. }
  1423. set wrapModeU(value) {
  1424. if (this._wrapModeU !== value) {
  1425. this._wrapModeU = value;
  1426. (this._width !== -1) && (this._setWarpMode(LayaGL.instance.TEXTURE_WRAP_S, value));
  1427. }
  1428. }
  1429. get wrapModeV() {
  1430. return this._wrapModeV;
  1431. }
  1432. set wrapModeV(value) {
  1433. if (this._wrapModeV !== value) {
  1434. this._wrapModeV = value;
  1435. (this._height !== -1) && (this._setWarpMode(LayaGL.instance.TEXTURE_WRAP_T, value));
  1436. }
  1437. }
  1438. get filterMode() {
  1439. return this._filterMode;
  1440. }
  1441. set filterMode(value) {
  1442. if (value !== this._filterMode) {
  1443. this._filterMode = value;
  1444. ((this._width !== -1) && (this._height !== -1)) && (this._setFilterMode(value));
  1445. }
  1446. }
  1447. get anisoLevel() {
  1448. return this._anisoLevel;
  1449. }
  1450. set anisoLevel(value) {
  1451. if (value !== this._anisoLevel) {
  1452. this._anisoLevel = Math.max(1, Math.min(16, value));
  1453. ((this._width !== -1) && (this._height !== -1)) && (this._setAnisotropy(value));
  1454. }
  1455. }
  1456. get mipmapCount() {
  1457. return this._mipmapCount;
  1458. }
  1459. get defaulteTexture() {
  1460. throw "BaseTexture:must override it.";
  1461. }
  1462. _getFormatByteCount() {
  1463. switch (this._format) {
  1464. case exports.TextureFormat.R8G8B8:
  1465. return 3;
  1466. case exports.TextureFormat.R8G8B8A8:
  1467. return 4;
  1468. case exports.TextureFormat.Alpha8:
  1469. return 1;
  1470. case exports.TextureFormat.R32G32B32A32:
  1471. return 4;
  1472. default:
  1473. throw "Texture2D: unknown format.";
  1474. }
  1475. }
  1476. _isPot(size) {
  1477. return (size & (size - 1)) === 0;
  1478. }
  1479. _getGLFormat() {
  1480. var glFormat;
  1481. var gl = LayaGL.instance;
  1482. var gpu = LayaGL.layaGPUInstance;
  1483. switch (this._format) {
  1484. case exports.TextureFormat.R8G8B8:
  1485. glFormat = gl.RGB;
  1486. break;
  1487. case exports.TextureFormat.R8G8B8A8:
  1488. glFormat = gl.RGBA;
  1489. break;
  1490. case exports.TextureFormat.Alpha8:
  1491. glFormat = gl.ALPHA;
  1492. break;
  1493. case exports.TextureFormat.R32G32B32A32:
  1494. glFormat = gl.RGBA;
  1495. break;
  1496. case exports.TextureFormat.DXT1:
  1497. if (gpu._compressedTextureS3tc)
  1498. glFormat = gpu._compressedTextureS3tc.COMPRESSED_RGB_S3TC_DXT1_EXT;
  1499. else
  1500. throw "BaseTexture: not support DXT1 format.";
  1501. break;
  1502. case exports.TextureFormat.DXT5:
  1503. if (gpu._compressedTextureS3tc)
  1504. glFormat = gpu._compressedTextureS3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  1505. else
  1506. throw "BaseTexture: not support DXT5 format.";
  1507. break;
  1508. case exports.TextureFormat.ETC1RGB:
  1509. if (gpu._compressedTextureEtc1)
  1510. glFormat = gpu._compressedTextureEtc1.COMPRESSED_RGB_ETC1_WEBGL;
  1511. else
  1512. throw "BaseTexture: not support ETC1RGB format.";
  1513. break;
  1514. case exports.TextureFormat.PVRTCRGB_2BPPV:
  1515. if (gpu._compressedTexturePvrtc)
  1516. glFormat = gpu._compressedTexturePvrtc.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  1517. else
  1518. throw "BaseTexture: not support PVRTCRGB_2BPPV format.";
  1519. break;
  1520. case exports.TextureFormat.PVRTCRGBA_2BPPV:
  1521. if (gpu._compressedTexturePvrtc)
  1522. glFormat = gpu._compressedTexturePvrtc.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  1523. else
  1524. throw "BaseTexture: not support PVRTCRGBA_2BPPV format.";
  1525. break;
  1526. case exports.TextureFormat.PVRTCRGB_4BPPV:
  1527. if (gpu._compressedTexturePvrtc)
  1528. glFormat = gpu._compressedTexturePvrtc.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  1529. else
  1530. throw "BaseTexture: not support PVRTCRGB_4BPPV format.";
  1531. break;
  1532. case exports.TextureFormat.PVRTCRGBA_4BPPV:
  1533. if (gpu._compressedTexturePvrtc)
  1534. glFormat = gpu._compressedTexturePvrtc.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  1535. else
  1536. throw "BaseTexture: not support PVRTCRGBA_4BPPV format.";
  1537. break;
  1538. default:
  1539. throw "BaseTexture: unknown texture format.";
  1540. }
  1541. return glFormat;
  1542. }
  1543. _setFilterMode(value) {
  1544. var gl = LayaGL.instance;
  1545. WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  1546. switch (value) {
  1547. case BaseTexture.FILTERMODE_POINT:
  1548. if (this._mipmap)
  1549. gl.texParameteri(this._glTextureType, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_NEAREST);
  1550. else
  1551. gl.texParameteri(this._glTextureType, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  1552. gl.texParameteri(this._glTextureType, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  1553. break;
  1554. case BaseTexture.FILTERMODE_BILINEAR:
  1555. if (this._mipmap)
  1556. gl.texParameteri(this._glTextureType, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST);
  1557. else
  1558. gl.texParameteri(this._glTextureType, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  1559. gl.texParameteri(this._glTextureType, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  1560. break;
  1561. case BaseTexture.FILTERMODE_TRILINEAR:
  1562. if (this._mipmap)
  1563. gl.texParameteri(this._glTextureType, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
  1564. else
  1565. gl.texParameteri(this._glTextureType, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  1566. gl.texParameteri(this._glTextureType, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  1567. break;
  1568. default:
  1569. throw new Error("BaseTexture:unknown filterMode value.");
  1570. }
  1571. }
  1572. _setWarpMode(orientation, mode) {
  1573. var gl = LayaGL.instance;
  1574. WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  1575. if (this._isPot(this._width) && this._isPot(this._height)) {
  1576. switch (mode) {
  1577. case BaseTexture.WARPMODE_REPEAT:
  1578. gl.texParameteri(this._glTextureType, orientation, gl.REPEAT);
  1579. break;
  1580. case BaseTexture.WARPMODE_CLAMP:
  1581. gl.texParameteri(this._glTextureType, orientation, gl.CLAMP_TO_EDGE);
  1582. break;
  1583. }
  1584. }
  1585. else {
  1586. gl.texParameteri(this._glTextureType, orientation, gl.CLAMP_TO_EDGE);
  1587. }
  1588. }
  1589. _setAnisotropy(value) {
  1590. var anisotropic = LayaGL.layaGPUInstance._extTextureFilterAnisotropic;
  1591. if (anisotropic) {
  1592. value = Math.max(value, 1);
  1593. var gl = LayaGL.instance;
  1594. WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  1595. value = Math.min(gl.getParameter(anisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT), value);
  1596. gl.texParameterf(this._glTextureType, anisotropic.TEXTURE_MAX_ANISOTROPY_EXT, value);
  1597. }
  1598. }
  1599. _disposeResource() {
  1600. if (this._glTexture) {
  1601. LayaGL.instance.deleteTexture(this._glTexture);
  1602. this._glTexture = null;
  1603. this._setGPUMemory(0);
  1604. }
  1605. }
  1606. _getSource() {
  1607. if (this._readyed)
  1608. return this._glTexture;
  1609. else
  1610. return null;
  1611. }
  1612. generateMipmap() {
  1613. if (this._isPot(this.width) && this._isPot(this.height))
  1614. LayaGL.instance.generateMipmap(this._glTextureType);
  1615. }
  1616. }
  1617. BaseTexture.WARPMODE_REPEAT = 0;
  1618. BaseTexture.WARPMODE_CLAMP = 1;
  1619. BaseTexture.FILTERMODE_POINT = 0;
  1620. BaseTexture.FILTERMODE_BILINEAR = 1;
  1621. BaseTexture.FILTERMODE_TRILINEAR = 2;
  1622. BaseTexture.FORMAT_R8G8B8 = 0;
  1623. BaseTexture.FORMAT_R8G8B8A8 = 1;
  1624. BaseTexture.FORMAT_ALPHA8 = 2;
  1625. BaseTexture.FORMAT_DXT1 = 3;
  1626. BaseTexture.FORMAT_DXT5 = 4;
  1627. BaseTexture.FORMAT_ETC1RGB = 5;
  1628. BaseTexture.FORMAT_PVRTCRGB_2BPPV = 9;
  1629. BaseTexture.FORMAT_PVRTCRGBA_2BPPV = 10;
  1630. BaseTexture.FORMAT_PVRTCRGB_4BPPV = 11;
  1631. BaseTexture.FORMAT_PVRTCRGBA_4BPPV = 12;
  1632. BaseTexture.RENDERTEXTURE_FORMAT_RGBA_HALF_FLOAT = 14;
  1633. BaseTexture.FORMAT_R32G32B32A32 = 15;
  1634. BaseTexture.FORMAT_DEPTH_16 = 0;
  1635. BaseTexture.FORMAT_STENCIL_8 = 1;
  1636. BaseTexture.FORMAT_DEPTHSTENCIL_16_8 = 2;
  1637. BaseTexture.FORMAT_DEPTHSTENCIL_NONE = 3;
  1638. class Texture2D extends BaseTexture {
  1639. constructor(width = 0, height = 0, format = exports.TextureFormat.R8G8B8A8, mipmap = true, canRead = false) {
  1640. super(format, mipmap);
  1641. var gl = LayaGL.instance;
  1642. this._glTextureType = gl.TEXTURE_2D;
  1643. this._width = width;
  1644. this._height = height;
  1645. this._canRead = canRead;
  1646. this._setWarpMode(gl.TEXTURE_WRAP_S, this._wrapModeU);
  1647. this._setWarpMode(gl.TEXTURE_WRAP_T, this._wrapModeV);
  1648. this._setFilterMode(this._filterMode);
  1649. this._setAnisotropy(this._anisoLevel);
  1650. if (this._mipmap) {
  1651. this._mipmapCount = Math.max(Math.ceil(Math.log2(width)) + 1, Math.ceil(Math.log2(height)) + 1);
  1652. for (var i = 0; i < this._mipmapCount; i++)
  1653. this._setPixels(null, i, Math.max(width >> i, 1), Math.max(height >> i, 1));
  1654. this._setGPUMemory(width * height * 4 * (1 + 1 / 3));
  1655. }
  1656. else {
  1657. this._mipmapCount = 1;
  1658. this._setPixels(null, 0, width, height);
  1659. this._setGPUMemory(width * height * 4);
  1660. }
  1661. }
  1662. static __init__() {
  1663. var pixels = new Uint8Array(3);
  1664. pixels[0] = 128;
  1665. pixels[1] = 128;
  1666. pixels[2] = 128;
  1667. Texture2D.grayTexture = new Texture2D(1, 1, exports.TextureFormat.R8G8B8, false, false);
  1668. Texture2D.grayTexture.setPixels(pixels);
  1669. Texture2D.grayTexture.lock = true;
  1670. pixels[0] = 255;
  1671. pixels[1] = 255;
  1672. pixels[2] = 255;
  1673. Texture2D.whiteTexture = new Texture2D(1, 1, exports.TextureFormat.R8G8B8, false, false);
  1674. Texture2D.whiteTexture.setPixels(pixels);
  1675. Texture2D.whiteTexture.lock = true;
  1676. pixels[0] = 0;
  1677. pixels[1] = 0;
  1678. pixels[2] = 0;
  1679. Texture2D.blackTexture = new Texture2D(1, 1, exports.TextureFormat.R8G8B8, false, false);
  1680. Texture2D.blackTexture.setPixels(pixels);
  1681. Texture2D.blackTexture.lock = true;
  1682. }
  1683. static _parse(data, propertyParams = null, constructParams = null) {
  1684. var texture = constructParams ? new Texture2D(constructParams[0], constructParams[1], constructParams[2], constructParams[3], constructParams[4]) : new Texture2D(0, 0);
  1685. if (propertyParams) {
  1686. texture.wrapModeU = propertyParams.wrapModeU;
  1687. texture.wrapModeV = propertyParams.wrapModeV;
  1688. texture.filterMode = propertyParams.filterMode;
  1689. texture.anisoLevel = propertyParams.anisoLevel;
  1690. }
  1691. switch (texture._format) {
  1692. case exports.TextureFormat.R8G8B8:
  1693. case exports.TextureFormat.R8G8B8A8:
  1694. texture.loadImageSource(data);
  1695. break;
  1696. case exports.TextureFormat.DXT1:
  1697. case exports.TextureFormat.DXT5:
  1698. case exports.TextureFormat.ETC1RGB:
  1699. case exports.TextureFormat.PVRTCRGB_2BPPV:
  1700. case exports.TextureFormat.PVRTCRGBA_2BPPV:
  1701. case exports.TextureFormat.PVRTCRGB_4BPPV:
  1702. case exports.TextureFormat.PVRTCRGBA_4BPPV:
  1703. texture.setCompressData(data);
  1704. break;
  1705. default:
  1706. throw "Texture2D:unkonwn format.";
  1707. }
  1708. return texture;
  1709. }
  1710. static load(url, complete) {
  1711. ILaya.loader.create(url, complete, null, ILaya.Loader.TEXTURE2D);
  1712. }
  1713. get defaulteTexture() {
  1714. return Texture2D.grayTexture;
  1715. }
  1716. _setPixels(pixels, miplevel, width, height) {
  1717. var gl = LayaGL.instance;
  1718. var textureType = this._glTextureType;
  1719. var glFormat = this._getGLFormat();
  1720. WebGLContext.bindTexture(gl, textureType, this._glTexture);
  1721. switch (this.format) {
  1722. case exports.TextureFormat.R8G8B8:
  1723. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
  1724. gl.texImage2D(textureType, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels);
  1725. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
  1726. break;
  1727. case exports.TextureFormat.R32G32B32A32:
  1728. if (LayaGL.layaGPUInstance._isWebGL2)
  1729. gl.texImage2D(textureType, miplevel, gl.RGBA32F, width, height, 0, glFormat, gl.FLOAT, pixels);
  1730. else
  1731. gl.texImage2D(textureType, miplevel, gl.RGBA, width, height, 0, glFormat, gl.FLOAT, pixels);
  1732. break;
  1733. default:
  1734. gl.texImage2D(textureType, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels);
  1735. }
  1736. }
  1737. _calcualatesCompressedDataSize(format, width, height) {
  1738. switch (format) {
  1739. case exports.TextureFormat.DXT1:
  1740. case exports.TextureFormat.ETC1RGB:
  1741. return ((width + 3) >> 2) * ((height + 3) >> 2) * 8;
  1742. case exports.TextureFormat.DXT5:
  1743. return ((width + 3) >> 2) * ((height + 3) >> 2) * 16;
  1744. case exports.TextureFormat.PVRTCRGB_4BPPV:
  1745. case exports.TextureFormat.PVRTCRGBA_4BPPV:
  1746. return Math.floor((Math.max(width, 8) * Math.max(height, 8) * 4 + 7) / 8);
  1747. case exports.TextureFormat.PVRTCRGB_2BPPV:
  1748. case exports.TextureFormat.PVRTCRGBA_2BPPV:
  1749. return Math.floor((Math.max(width, 16) * Math.max(height, 8) * 2 + 7) / 8);
  1750. default:
  1751. return 0;
  1752. }
  1753. }
  1754. _pharseDDS(arrayBuffer) {
  1755. const FOURCC_DXT1 = 827611204;
  1756. const FOURCC_DXT5 = 894720068;
  1757. const DDPF_FOURCC = 0x4;
  1758. const DDSD_MIPMAPCOUNT = 0x20000;
  1759. const DDS_MAGIC = 0x20534444;
  1760. const DDS_HEADER_LENGTH = 31;
  1761. const DDS_HEADER_MAGIC = 0;
  1762. const DDS_HEADER_SIZE = 1;
  1763. const DDS_HEADER_FLAGS = 2;
  1764. const DDS_HEADER_HEIGHT = 3;
  1765. const DDS_HEADER_WIDTH = 4;
  1766. const DDS_HEADER_MIPMAPCOUNT = 7;
  1767. const DDS_HEADER_PF_FLAGS = 20;
  1768. const DDS_HEADER_PF_FOURCC = 21;
  1769. var header = new Int32Array(arrayBuffer, 0, DDS_HEADER_LENGTH);
  1770. if (header[DDS_HEADER_MAGIC] != DDS_MAGIC)
  1771. throw "Invalid magic number in DDS header";
  1772. if (!(header[DDS_HEADER_PF_FLAGS] & DDPF_FOURCC))
  1773. throw "Unsupported format, must contain a FourCC code";
  1774. var compressedFormat = header[DDS_HEADER_PF_FOURCC];
  1775. switch (this._format) {
  1776. case exports.TextureFormat.DXT1:
  1777. if (compressedFormat !== FOURCC_DXT1)
  1778. throw "the FourCC code is not same with texture format.";
  1779. break;
  1780. case exports.TextureFormat.DXT5:
  1781. if (compressedFormat !== FOURCC_DXT5)
  1782. throw "the FourCC code is not same with texture format.";
  1783. break;
  1784. default:
  1785. throw "unknown texture format.";
  1786. }
  1787. var mipLevels = 1;
  1788. if (header[DDS_HEADER_FLAGS] & DDSD_MIPMAPCOUNT) {
  1789. mipLevels = Math.max(1, header[DDS_HEADER_MIPMAPCOUNT]);
  1790. if (!this._mipmap)
  1791. throw "the mipmap is not same with Texture2D.";
  1792. }
  1793. else {
  1794. if (this._mipmap)
  1795. throw "the mipmap is not same with Texture2D.";
  1796. }
  1797. var width = header[DDS_HEADER_WIDTH];
  1798. var height = header[DDS_HEADER_HEIGHT];
  1799. this._width = width;
  1800. this._height = height;
  1801. var dataOffset = header[DDS_HEADER_SIZE] + 4;
  1802. this._upLoadCompressedTexImage2D(arrayBuffer, width, height, mipLevels, dataOffset, 0);
  1803. }
  1804. _pharseKTX(arrayBuffer) {
  1805. const ETC_HEADER_LENGTH = 13;
  1806. const ETC_HEADER_FORMAT = 4;
  1807. const ETC_HEADER_HEIGHT = 7;
  1808. const ETC_HEADER_WIDTH = 6;
  1809. const ETC_HEADER_MIPMAPCOUNT = 11;
  1810. const ETC_HEADER_METADATA = 12;
  1811. var id = new Uint8Array(arrayBuffer, 0, 12);
  1812. if (id[0] != 0xAB || id[1] != 0x4B || id[2] != 0x54 || id[3] != 0x58 || id[4] != 0x20 || id[5] != 0x31 || id[6] != 0x31 || id[7] != 0xBB || id[8] != 0x0D || id[9] != 0x0A || id[10] != 0x1A || id[11] != 0x0A)
  1813. throw ("Invalid fileIdentifier in KTX header");
  1814. var header = new Int32Array(id.buffer, id.length, ETC_HEADER_LENGTH);
  1815. var compressedFormat = header[ETC_HEADER_FORMAT];
  1816. switch (compressedFormat) {
  1817. case LayaGL.layaGPUInstance._compressedTextureEtc1.COMPRESSED_RGB_ETC1_WEBGL:
  1818. this._format = exports.TextureFormat.ETC1RGB;
  1819. break;
  1820. default:
  1821. throw "unknown texture format.";
  1822. }
  1823. var mipLevels = header[ETC_HEADER_MIPMAPCOUNT];
  1824. var width = header[ETC_HEADER_WIDTH];
  1825. var height = header[ETC_HEADER_HEIGHT];
  1826. this._width = width;
  1827. this._height = height;
  1828. var dataOffset = 64 + header[ETC_HEADER_METADATA];
  1829. this._upLoadCompressedTexImage2D(arrayBuffer, width, height, mipLevels, dataOffset, 4);
  1830. }
  1831. _pharsePVR(arrayBuffer) {
  1832. const PVR_FORMAT_2BPP_RGB = 0;
  1833. const PVR_FORMAT_2BPP_RGBA = 1;
  1834. const PVR_FORMAT_4BPP_RGB = 2;
  1835. const PVR_FORMAT_4BPP_RGBA = 3;
  1836. const PVR_MAGIC = 0x03525650;
  1837. const PVR_HEADER_LENGTH = 13;
  1838. const PVR_HEADER_MAGIC = 0;
  1839. const PVR_HEADER_FORMAT = 2;
  1840. const PVR_HEADER_HEIGHT = 6;
  1841. const PVR_HEADER_WIDTH = 7;
  1842. const PVR_HEADER_MIPMAPCOUNT = 11;
  1843. const PVR_HEADER_METADATA = 12;
  1844. var header = new Int32Array(arrayBuffer, 0, PVR_HEADER_LENGTH);
  1845. if (header[PVR_HEADER_MAGIC] != PVR_MAGIC)
  1846. throw ("Invalid magic number in PVR header");
  1847. var compressedFormat = header[PVR_HEADER_FORMAT];
  1848. switch (compressedFormat) {
  1849. case PVR_FORMAT_2BPP_RGB:
  1850. this._format = exports.TextureFormat.PVRTCRGB_2BPPV;
  1851. break;
  1852. case PVR_FORMAT_4BPP_RGB:
  1853. this._format = exports.TextureFormat.PVRTCRGB_4BPPV;
  1854. break;
  1855. case PVR_FORMAT_2BPP_RGBA:
  1856. this._format = exports.TextureFormat.PVRTCRGBA_2BPPV;
  1857. break;
  1858. case PVR_FORMAT_4BPP_RGBA:
  1859. this._format = exports.TextureFormat.PVRTCRGBA_4BPPV;
  1860. break;
  1861. default:
  1862. throw "Texture2D:unknown PVR format.";
  1863. }
  1864. var mipLevels = header[PVR_HEADER_MIPMAPCOUNT];
  1865. var width = header[PVR_HEADER_WIDTH];
  1866. var height = header[PVR_HEADER_HEIGHT];
  1867. this._width = width;
  1868. this._height = height;
  1869. var dataOffset = header[PVR_HEADER_METADATA] + 52;
  1870. this._upLoadCompressedTexImage2D(arrayBuffer, width, height, mipLevels, dataOffset, 0);
  1871. }
  1872. _upLoadCompressedTexImage2D(data, width, height, miplevelCount, dataOffset, imageSizeOffset) {
  1873. var gl = LayaGL.instance;
  1874. var textureType = this._glTextureType;
  1875. WebGLContext.bindTexture(gl, textureType, this._glTexture);
  1876. var glFormat = this._getGLFormat();
  1877. var offset = dataOffset;
  1878. for (var i = 0; i < miplevelCount; i++) {
  1879. offset += imageSizeOffset;
  1880. var mipDataSize = this._calcualatesCompressedDataSize(this._format, width, height);
  1881. var mipData = new Uint8Array(data, offset, mipDataSize);
  1882. gl.compressedTexImage2D(textureType, i, glFormat, width, height, 0, mipData);
  1883. width = Math.max(width >> 1, 1.0);
  1884. height = Math.max(height >> 1, 1.0);
  1885. offset += mipDataSize;
  1886. }
  1887. var memory = offset;
  1888. this._setGPUMemory(memory);
  1889. this._readyed = true;
  1890. this._activeResource();
  1891. }
  1892. loadImageSource(source, premultiplyAlpha = false) {
  1893. var gl = LayaGL.instance;
  1894. var width = source.width;
  1895. var height = source.height;
  1896. this._width = width;
  1897. this._height = height;
  1898. if (!(this._isPot(width) && this._isPot(height)))
  1899. this._mipmap = false;
  1900. this._setWarpMode(gl.TEXTURE_WRAP_S, this._wrapModeU);
  1901. this._setWarpMode(gl.TEXTURE_WRAP_T, this._wrapModeV);
  1902. this._setFilterMode(this._filterMode);
  1903. WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  1904. var glFormat = this._getGLFormat();
  1905. if (ILaya.Render.isConchApp) {
  1906. if (source.setPremultiplyAlpha) {
  1907. source.setPremultiplyAlpha(premultiplyAlpha);
  1908. }
  1909. gl.texImage2D(this._glTextureType, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
  1910. }
  1911. else {
  1912. (premultiplyAlpha) && (gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true));
  1913. gl.texImage2D(this._glTextureType, 0, glFormat, glFormat, gl.UNSIGNED_BYTE, source);
  1914. (premultiplyAlpha) && (gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false));
  1915. }
  1916. if (this._mipmap) {
  1917. gl.generateMipmap(this._glTextureType);
  1918. this._setGPUMemory(width * height * 4 * (1 + 1 / 3));
  1919. }
  1920. else {
  1921. this._setGPUMemory(width * height * 4);
  1922. }
  1923. if (this._canRead) {
  1924. if (ILaya.Render.isConchApp) {
  1925. this._pixels = new Uint8Array(source._nativeObj.getImageData(0, 0, width, height));
  1926. }
  1927. else {
  1928. ILaya.Browser.canvas.size(width, height);
  1929. ILaya.Browser.canvas.clear();
  1930. ILaya.Browser.context.drawImage(source, 0, 0, width, height);
  1931. this._pixels = new Uint8Array(ILaya.Browser.context.getImageData(0, 0, width, height).data.buffer);
  1932. }
  1933. }
  1934. this._readyed = true;
  1935. this._activeResource();
  1936. }
  1937. setPixels(pixels, miplevel = 0) {
  1938. if (!pixels)
  1939. throw "Texture2D:pixels can't be null.";
  1940. var width = Math.max(this._width >> miplevel, 1);
  1941. var height = Math.max(this._height >> miplevel, 1);
  1942. var pixelsCount = width * height * this._getFormatByteCount();
  1943. if (pixels.length < pixelsCount)
  1944. throw "Texture2D:pixels length should at least " + pixelsCount + ".";
  1945. this._setPixels(pixels, miplevel, width, height);
  1946. if (this._canRead)
  1947. this._pixels = pixels;
  1948. this._readyed = true;
  1949. this._activeResource();
  1950. }
  1951. setSubPixels(x, y, width, height, pixels, miplevel = 0) {
  1952. if (!pixels)
  1953. throw "Texture2D:pixels can't be null.";
  1954. var gl = LayaGL.instance;
  1955. var textureType = this._glTextureType;
  1956. WebGLContext.bindTexture(gl, textureType, this._glTexture);
  1957. var glFormat = this._getGLFormat();
  1958. switch (this.format) {
  1959. case exports.TextureFormat.R8G8B8:
  1960. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
  1961. gl.texSubImage2D(textureType, miplevel, x, y, width, height, glFormat, gl.UNSIGNED_BYTE, pixels);
  1962. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
  1963. break;
  1964. case exports.TextureFormat.R32G32B32A32:
  1965. gl.texSubImage2D(textureType, miplevel, x, y, width, height, glFormat, gl.FLOAT, pixels);
  1966. break;
  1967. default:
  1968. gl.texSubImage2D(textureType, miplevel, x, y, width, height, glFormat, gl.UNSIGNED_BYTE, pixels);
  1969. }
  1970. this._readyed = true;
  1971. this._activeResource();
  1972. }
  1973. setCompressData(data) {
  1974. switch (this._format) {
  1975. case exports.TextureFormat.DXT1:
  1976. case exports.TextureFormat.DXT5:
  1977. this._pharseDDS(data);
  1978. break;
  1979. case exports.TextureFormat.ETC1RGB:
  1980. this._pharseKTX(data);
  1981. break;
  1982. case exports.TextureFormat.PVRTCRGB_2BPPV:
  1983. case exports.TextureFormat.PVRTCRGBA_2BPPV:
  1984. case exports.TextureFormat.PVRTCRGB_4BPPV:
  1985. case exports.TextureFormat.PVRTCRGBA_4BPPV:
  1986. this._pharsePVR(data);
  1987. break;
  1988. default:
  1989. throw "Texture2D:unkonwn format.";
  1990. }
  1991. }
  1992. _recoverResource() {
  1993. }
  1994. getPixels() {
  1995. if (this._canRead)
  1996. return this._pixels;
  1997. else
  1998. throw new Error("Texture2D: must set texture canRead is true.");
  1999. }
  2000. }
  2001. Texture2D.TEXTURE2D = "TEXTURE2D";
  2002. Texture2D.grayTexture = null;
  2003. Texture2D.whiteTexture = null;
  2004. Texture2D.blackTexture = null;
  2005. class BaseShader extends Resource {
  2006. constructor() {
  2007. super();
  2008. }
  2009. }
  2010. class RenderState2D {
  2011. static mat2MatArray(mat, matArray) {
  2012. var m = mat;
  2013. var m4 = matArray;
  2014. m4[0] = m.a;
  2015. m4[1] = m.b;
  2016. m4[2] = RenderState2D.EMPTYMAT4_ARRAY[2];
  2017. m4[3] = RenderState2D.EMPTYMAT4_ARRAY[3];
  2018. m4[4] = m.c;
  2019. m4[5] = m.d;
  2020. m4[6] = RenderState2D.EMPTYMAT4_ARRAY[6];
  2021. m4[7] = RenderState2D.EMPTYMAT4_ARRAY[7];
  2022. m4[8] = RenderState2D.EMPTYMAT4_ARRAY[8];
  2023. m4[9] = RenderState2D.EMPTYMAT4_ARRAY[9];
  2024. m4[10] = RenderState2D.EMPTYMAT4_ARRAY[10];
  2025. m4[11] = RenderState2D.EMPTYMAT4_ARRAY[11];
  2026. m4[12] = m.tx;
  2027. m4[13] = m.ty;
  2028. m4[14] = RenderState2D.EMPTYMAT4_ARRAY[14];
  2029. m4[15] = RenderState2D.EMPTYMAT4_ARRAY[15];
  2030. return matArray;
  2031. }
  2032. static restoreTempArray() {
  2033. RenderState2D.TEMPMAT4_ARRAY[0] = 1;
  2034. RenderState2D.TEMPMAT4_ARRAY[1] = 0;
  2035. RenderState2D.TEMPMAT4_ARRAY[4] = 0;
  2036. RenderState2D.TEMPMAT4_ARRAY[5] = 1;
  2037. RenderState2D.TEMPMAT4_ARRAY[12] = 0;
  2038. RenderState2D.TEMPMAT4_ARRAY[13] = 0;
  2039. }
  2040. static clear() {
  2041. RenderState2D.worldScissorTest = false;
  2042. RenderState2D.worldAlpha = 1;
  2043. }
  2044. }
  2045. RenderState2D._MAXSIZE = 99999999;
  2046. RenderState2D.EMPTYMAT4_ARRAY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  2047. RenderState2D.TEMPMAT4_ARRAY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  2048. RenderState2D.worldMatrix4 = RenderState2D.TEMPMAT4_ARRAY;
  2049. RenderState2D.worldMatrix = new Matrix();
  2050. RenderState2D.matWVP = null;
  2051. RenderState2D.worldAlpha = 1.0;
  2052. RenderState2D.worldScissorTest = false;
  2053. RenderState2D.width = 0;
  2054. RenderState2D.height = 0;
  2055. (function (RenderTextureFormat) {
  2056. RenderTextureFormat[RenderTextureFormat["R8G8B8"] = 0] = "R8G8B8";
  2057. RenderTextureFormat[RenderTextureFormat["R8G8B8A8"] = 1] = "R8G8B8A8";
  2058. RenderTextureFormat[RenderTextureFormat["Alpha8"] = 2] = "Alpha8";
  2059. RenderTextureFormat[RenderTextureFormat["R16G16B16A16"] = 14] = "R16G16B16A16";
  2060. })(exports.RenderTextureFormat || (exports.RenderTextureFormat = {}));
  2061. (function (RenderTextureDepthFormat) {
  2062. RenderTextureDepthFormat[RenderTextureDepthFormat["DEPTH_16"] = 0] = "DEPTH_16";
  2063. RenderTextureDepthFormat[RenderTextureDepthFormat["STENCIL_8"] = 1] = "STENCIL_8";
  2064. RenderTextureDepthFormat[RenderTextureDepthFormat["DEPTHSTENCIL_16_8"] = 2] = "DEPTHSTENCIL_16_8";
  2065. RenderTextureDepthFormat[RenderTextureDepthFormat["DEPTHSTENCIL_NONE"] = 3] = "DEPTHSTENCIL_NONE";
  2066. })(exports.RenderTextureDepthFormat || (exports.RenderTextureDepthFormat = {}));
  2067. class RenderTexture2D extends BaseTexture {
  2068. constructor(width, height, format = exports.RenderTextureFormat.R8G8B8, depthStencilFormat = exports.RenderTextureDepthFormat.DEPTH_16) {
  2069. super(format, false);
  2070. this._mgrKey = 0;
  2071. this._glTextureType = LayaGL.instance.TEXTURE_2D;
  2072. this._width = width;
  2073. this._height = height;
  2074. this._depthStencilFormat = depthStencilFormat;
  2075. this._create(width, height);
  2076. this.lock = true;
  2077. }
  2078. static get currentActive() {
  2079. return RenderTexture2D._currentActive;
  2080. }
  2081. get depthStencilFormat() {
  2082. return this._depthStencilFormat;
  2083. }
  2084. get defaulteTexture() {
  2085. return Texture2D.grayTexture;
  2086. }
  2087. getIsReady() {
  2088. return true;
  2089. }
  2090. get sourceWidth() {
  2091. return this._width;
  2092. }
  2093. get sourceHeight() {
  2094. return this._height;
  2095. }
  2096. get offsetX() {
  2097. return 0;
  2098. }
  2099. get offsetY() {
  2100. return 0;
  2101. }
  2102. _create(width, height) {
  2103. var gl = LayaGL.instance;
  2104. this._frameBuffer = gl.createFramebuffer();
  2105. WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  2106. var glFormat = this._getGLFormat();
  2107. gl.texImage2D(this._glTextureType, 0, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, null);
  2108. this._setGPUMemory(width * height * 4);
  2109. gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
  2110. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._glTexture, 0);
  2111. if (this._depthStencilFormat !== exports.RenderTextureDepthFormat.DEPTHSTENCIL_NONE) {
  2112. this._depthStencilBuffer = gl.createRenderbuffer();
  2113. gl.bindRenderbuffer(gl.RENDERBUFFER, this._depthStencilBuffer);
  2114. switch (this._depthStencilFormat) {
  2115. case exports.RenderTextureDepthFormat.DEPTH_16:
  2116. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height);
  2117. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, this._depthStencilBuffer);
  2118. break;
  2119. case exports.RenderTextureDepthFormat.STENCIL_8:
  2120. gl.renderbufferStorage(gl.RENDERBUFFER, gl.STENCIL_INDEX8, width, height);
  2121. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, this._depthStencilBuffer);
  2122. break;
  2123. case exports.RenderTextureDepthFormat.DEPTHSTENCIL_16_8:
  2124. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height);
  2125. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this._depthStencilBuffer);
  2126. break;
  2127. default:
  2128. }
  2129. }
  2130. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  2131. gl.bindRenderbuffer(gl.RENDERBUFFER, null);
  2132. this._setWarpMode(gl.TEXTURE_WRAP_S, this._wrapModeU);
  2133. this._setWarpMode(gl.TEXTURE_WRAP_T, this._wrapModeV);
  2134. this._setFilterMode(this._filterMode);
  2135. this._setAnisotropy(this._anisoLevel);
  2136. this._readyed = true;
  2137. this._activeResource();
  2138. }
  2139. generateMipmap() {
  2140. if (this._isPot(this.width) && this._isPot(this.height)) {
  2141. this._mipmap = true;
  2142. LayaGL.instance.generateMipmap(this._glTextureType);
  2143. this._setFilterMode(this._filterMode);
  2144. this._setGPUMemory(this.width * this.height * 4 * (1 + 1 / 3));
  2145. }
  2146. else {
  2147. this._mipmap = false;
  2148. this._setGPUMemory(this.width * this.height * 4);
  2149. }
  2150. }
  2151. static pushRT() {
  2152. RenderTexture2D.rtStack.push({ rt: RenderTexture2D._currentActive, w: RenderState2D.width, h: RenderState2D.height });
  2153. }
  2154. static popRT() {
  2155. var gl = LayaGL.instance;
  2156. var top = RenderTexture2D.rtStack.pop();
  2157. if (top) {
  2158. if (RenderTexture2D._currentActive != top.rt) {
  2159. LayaGL.instance.bindFramebuffer(gl.FRAMEBUFFER, top.rt ? top.rt._frameBuffer : null);
  2160. RenderTexture2D._currentActive = top.rt;
  2161. }
  2162. gl.viewport(0, 0, top.w, top.h);
  2163. RenderState2D.width = top.w;
  2164. RenderState2D.height = top.h;
  2165. }
  2166. }
  2167. start() {
  2168. var gl = LayaGL.instance;
  2169. LayaGL.instance.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
  2170. this._lastRT = RenderTexture2D._currentActive;
  2171. RenderTexture2D._currentActive = this;
  2172. this._readyed = true;
  2173. gl.viewport(0, 0, this._width, this._height);
  2174. this._lastWidth = RenderState2D.width;
  2175. this._lastHeight = RenderState2D.height;
  2176. RenderState2D.width = this._width;
  2177. RenderState2D.height = this._height;
  2178. BaseShader.activeShader = null;
  2179. }
  2180. end() {
  2181. var gl = LayaGL.instance;
  2182. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  2183. RenderTexture2D._currentActive = null;
  2184. this._readyed = true;
  2185. }
  2186. restore() {
  2187. var gl = LayaGL.instance;
  2188. if (this._lastRT != RenderTexture2D._currentActive) {
  2189. LayaGL.instance.bindFramebuffer(gl.FRAMEBUFFER, this._lastRT ? this._lastRT._frameBuffer : null);
  2190. RenderTexture2D._currentActive = this._lastRT;
  2191. }
  2192. this._readyed = true;
  2193. gl.viewport(0, 0, this._lastWidth, this._lastHeight);
  2194. RenderState2D.width = this._lastWidth;
  2195. RenderState2D.height = this._lastHeight;
  2196. BaseShader.activeShader = null;
  2197. }
  2198. clear(r = 0.0, g = 0.0, b = 0.0, a = 1.0) {
  2199. var gl = LayaGL.instance;
  2200. gl.clearColor(r, g, b, a);
  2201. var clearFlag = gl.COLOR_BUFFER_BIT;
  2202. switch (this._depthStencilFormat) {
  2203. case gl.DEPTH_COMPONENT16:
  2204. clearFlag |= gl.DEPTH_BUFFER_BIT;
  2205. break;
  2206. case gl.STENCIL_INDEX8:
  2207. clearFlag |= gl.STENCIL_BUFFER_BIT;
  2208. break;
  2209. case gl.DEPTH_STENCIL:
  2210. clearFlag |= gl.DEPTH_BUFFER_BIT;
  2211. clearFlag |= gl.STENCIL_BUFFER_BIT;
  2212. break;
  2213. }
  2214. gl.clear(clearFlag);
  2215. }
  2216. getData(x, y, width, height) {
  2217. if (ILaya.Render.isConchApp && window.conchConfig.threadMode == 2) {
  2218. throw "native 2 thread mode use getDataAsync";
  2219. }
  2220. var gl = LayaGL.instance;
  2221. gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
  2222. var canRead = (gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE);
  2223. if (!canRead) {
  2224. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  2225. return null;
  2226. }
  2227. var pixels = new Uint8Array(this._width * this._height * 4);
  2228. var glFormat = this._getGLFormat();
  2229. gl.readPixels(x, y, width, height, glFormat, gl.UNSIGNED_BYTE, pixels);
  2230. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  2231. return pixels;
  2232. }
  2233. getDataAsync(x, y, width, height, callBack) {
  2234. var gl = LayaGL.instance;
  2235. gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
  2236. gl.readPixelsAsync(x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE, function (data) {
  2237. callBack(new Uint8Array(data));
  2238. });
  2239. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  2240. }
  2241. recycle() {
  2242. }
  2243. _disposeResource() {
  2244. if (this._frameBuffer) {
  2245. var gl = LayaGL.instance;
  2246. gl.deleteTexture(this._glTexture);
  2247. gl.deleteFramebuffer(this._frameBuffer);
  2248. gl.deleteRenderbuffer(this._depthStencilBuffer);
  2249. this._glTexture = null;
  2250. this._frameBuffer = null;
  2251. this._depthStencilBuffer = null;
  2252. this._setGPUMemory(0);
  2253. }
  2254. }
  2255. }
  2256. RenderTexture2D.rtStack = [];
  2257. RenderTexture2D.defuv = [0, 0, 1, 0, 1, 1, 0, 1];
  2258. RenderTexture2D.flipyuv = [0, 1, 1, 1, 1, 0, 0, 0];
  2259. class WebGLRTMgr {
  2260. static getRT(w, h) {
  2261. w = w | 0;
  2262. h = h | 0;
  2263. if (w >= 10000) {
  2264. console.error('getRT error! w too big');
  2265. }
  2266. var ret;
  2267. ret = new RenderTexture2D(w, h, exports.RenderTextureFormat.R8G8B8A8, -1);
  2268. return ret;
  2269. }
  2270. static releaseRT(rt) {
  2271. rt._disposeResource();
  2272. return;
  2273. }
  2274. }
  2275. WebGLRTMgr.dict = {};
  2276. class BlendMode {
  2277. static _init_(gl) {
  2278. BlendMode.fns = [BlendMode.BlendNormal, BlendMode.BlendAdd, BlendMode.BlendMultiply, BlendMode.BlendScreen, BlendMode.BlendOverlay, BlendMode.BlendLight, BlendMode.BlendMask, BlendMode.BlendDestinationOut];
  2279. BlendMode.targetFns = [BlendMode.BlendNormalTarget, BlendMode.BlendAddTarget, BlendMode.BlendMultiplyTarget, BlendMode.BlendScreenTarget, BlendMode.BlendOverlayTarget, BlendMode.BlendLightTarget, BlendMode.BlendMask, BlendMode.BlendDestinationOut];
  2280. }
  2281. static BlendNormal(gl) {
  2282. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  2283. }
  2284. static BlendAdd(gl) {
  2285. WebGLContext.setBlendFunc(gl, gl.ONE, gl.DST_ALPHA);
  2286. }
  2287. static BlendMultiply(gl) {
  2288. WebGLContext.setBlendFunc(gl, gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA);
  2289. }
  2290. static BlendScreen(gl) {
  2291. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE);
  2292. }
  2293. static BlendOverlay(gl) {
  2294. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE_MINUS_SRC_COLOR);
  2295. }
  2296. static BlendLight(gl) {
  2297. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE);
  2298. }
  2299. static BlendNormalTarget(gl) {
  2300. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  2301. }
  2302. static BlendAddTarget(gl) {
  2303. WebGLContext.setBlendFunc(gl, gl.ONE, gl.DST_ALPHA);
  2304. }
  2305. static BlendMultiplyTarget(gl) {
  2306. WebGLContext.setBlendFunc(gl, gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA);
  2307. }
  2308. static BlendScreenTarget(gl) {
  2309. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE);
  2310. }
  2311. static BlendOverlayTarget(gl) {
  2312. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE_MINUS_SRC_COLOR);
  2313. }
  2314. static BlendLightTarget(gl) {
  2315. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE);
  2316. }
  2317. static BlendMask(gl) {
  2318. WebGLContext.setBlendFunc(gl, gl.ZERO, gl.SRC_ALPHA);
  2319. }
  2320. static BlendDestinationOut(gl) {
  2321. WebGLContext.setBlendFunc(gl, gl.ZERO, gl.ZERO);
  2322. }
  2323. }
  2324. BlendMode.activeBlendFunction = null;
  2325. BlendMode.NAMES = ["normal", "add", "multiply", "screen", "overlay", "light", "mask", "destination-out"];
  2326. BlendMode.TOINT = { "normal": 0, "add": 1, "multiply": 2, "screen": 3, "overlay": 4, "light": 5, "mask": 6, "destination-out": 7, "lighter": 1 };
  2327. BlendMode.NORMAL = "normal";
  2328. BlendMode.ADD = "add";
  2329. BlendMode.MULTIPLY = "multiply";
  2330. BlendMode.SCREEN = "screen";
  2331. BlendMode.OVERLAY = "overlay";
  2332. BlendMode.LIGHT = "light";
  2333. BlendMode.MASK = "mask";
  2334. BlendMode.DESTINATIONOUT = "destination-out";
  2335. BlendMode.LIGHTER = "lighter";
  2336. BlendMode.fns = [];
  2337. BlendMode.targetFns = [];
  2338. class ShaderDefinesBase {
  2339. constructor(name2int, int2name, int2nameMap) {
  2340. this._value = 0;
  2341. this._name2int = name2int;
  2342. this._int2name = int2name;
  2343. this._int2nameMap = int2nameMap;
  2344. }
  2345. add(value) {
  2346. if (typeof (value) == 'string') {
  2347. this._value |= this._name2int[value];
  2348. }
  2349. else {
  2350. this._value |= value;
  2351. }
  2352. return this._value;
  2353. }
  2354. addInt(value) {
  2355. this._value |= value;
  2356. return this._value;
  2357. }
  2358. remove(value) {
  2359. if (typeof (value) == 'string') {
  2360. this._value &= ~(this._name2int[value]);
  2361. }
  2362. else {
  2363. this._value &= (~value);
  2364. }
  2365. return this._value;
  2366. }
  2367. isDefine(def) {
  2368. return (this._value & def) === def;
  2369. }
  2370. getValue() {
  2371. return this._value;
  2372. }
  2373. setValue(value) {
  2374. this._value = value;
  2375. }
  2376. toNameDic() {
  2377. var r = this._int2nameMap[this._value];
  2378. return r ? r : ShaderDefinesBase._toText(this._value, this._int2name, this._int2nameMap);
  2379. }
  2380. static _reg(name, value, _name2int, _int2name) {
  2381. _name2int[name] = value;
  2382. _int2name[value] = name;
  2383. }
  2384. static _toText(value, _int2name, _int2nameMap) {
  2385. var r = _int2nameMap[value];
  2386. if (r)
  2387. return r;
  2388. var o = {};
  2389. var d = 1;
  2390. for (var i = 0; i < 32; i++) {
  2391. d = 1 << i;
  2392. if (d > value)
  2393. break;
  2394. if (value & d) {
  2395. var name = _int2name[d];
  2396. name && (o[name] = "");
  2397. }
  2398. }
  2399. _int2nameMap[value] = o;
  2400. return o;
  2401. }
  2402. static _toInt(names, _name2int) {
  2403. var words = names.split('.');
  2404. var num = 0;
  2405. for (var i = 0, n = words.length; i < n; i++) {
  2406. var value = _name2int[words[i]];
  2407. if (!value)
  2408. throw new Error("Defines to int err:" + names + "/" + words[i]);
  2409. num |= value;
  2410. }
  2411. return num;
  2412. }
  2413. }
  2414. class ShaderDefines2D extends ShaderDefinesBase {
  2415. constructor() {
  2416. super(ShaderDefines2D.__name2int, ShaderDefines2D.__int2name, ShaderDefines2D.__int2nameMap);
  2417. }
  2418. static __init__() {
  2419. ShaderDefines2D.reg("TEXTURE2D", ShaderDefines2D.TEXTURE2D);
  2420. ShaderDefines2D.reg("PRIMITIVE", ShaderDefines2D.PRIMITIVE);
  2421. ShaderDefines2D.reg("GLOW_FILTER", ShaderDefines2D.FILTERGLOW);
  2422. ShaderDefines2D.reg("BLUR_FILTER", ShaderDefines2D.FILTERBLUR);
  2423. ShaderDefines2D.reg("COLOR_FILTER", ShaderDefines2D.FILTERCOLOR);
  2424. ShaderDefines2D.reg("COLOR_ADD", ShaderDefines2D.COLORADD);
  2425. ShaderDefines2D.reg("WORLDMAT", ShaderDefines2D.WORLDMAT);
  2426. ShaderDefines2D.reg("FILLTEXTURE", ShaderDefines2D.FILLTEXTURE);
  2427. ShaderDefines2D.reg("FSHIGHPRECISION", ShaderDefines2D.SHADERDEFINE_FSHIGHPRECISION);
  2428. ShaderDefines2D.reg('MVP3D', ShaderDefines2D.MVP3D);
  2429. }
  2430. static reg(name, value) {
  2431. this._reg(name, value, ShaderDefines2D.__name2int, ShaderDefines2D.__int2name);
  2432. }
  2433. static toText(value, int2name, int2nameMap) {
  2434. return this._toText(value, int2name, int2nameMap);
  2435. }
  2436. static toInt(names) {
  2437. return this._toInt(names, ShaderDefines2D.__name2int);
  2438. }
  2439. }
  2440. ShaderDefines2D.TEXTURE2D = 0x01;
  2441. ShaderDefines2D.PRIMITIVE = 0x04;
  2442. ShaderDefines2D.FILTERGLOW = 0x08;
  2443. ShaderDefines2D.FILTERBLUR = 0x10;
  2444. ShaderDefines2D.FILTERCOLOR = 0x20;
  2445. ShaderDefines2D.COLORADD = 0x40;
  2446. ShaderDefines2D.WORLDMAT = 0x80;
  2447. ShaderDefines2D.FILLTEXTURE = 0x100;
  2448. ShaderDefines2D.SKINMESH = 0x200;
  2449. ShaderDefines2D.SHADERDEFINE_FSHIGHPRECISION = 0x400;
  2450. ShaderDefines2D.MVP3D = 0x800;
  2451. ShaderDefines2D.NOOPTMASK = ShaderDefines2D.FILTERGLOW | ShaderDefines2D.FILTERBLUR | ShaderDefines2D.FILTERCOLOR | ShaderDefines2D.FILLTEXTURE;
  2452. ShaderDefines2D.__name2int = {};
  2453. ShaderDefines2D.__int2name = [];
  2454. ShaderDefines2D.__int2nameMap = [];
  2455. class Stat {
  2456. static show(x = 0, y = 0) {
  2457. Stat._StatRender.show(x, y);
  2458. }
  2459. static enable() {
  2460. Stat._StatRender.enable();
  2461. }
  2462. static hide() {
  2463. Stat._StatRender.hide();
  2464. }
  2465. static clear() {
  2466. Stat.trianglesFaces = Stat.renderBatches = Stat.savedRenderBatches = Stat.shaderCall = Stat.spriteRenderUseCacheCount = Stat.frustumCulling = Stat.octreeNodeCulling = Stat.canvasNormal = Stat.canvasBitmap = Stat.canvasReCache = 0;
  2467. }
  2468. static set onclick(fn) {
  2469. Stat._StatRender.set_onclick(fn);
  2470. }
  2471. }
  2472. Stat.FPS = 0;
  2473. Stat.loopCount = 0;
  2474. Stat.shaderCall = 0;
  2475. Stat.renderBatches = 0;
  2476. Stat.savedRenderBatches = 0;
  2477. Stat.trianglesFaces = 0;
  2478. Stat.spriteCount = 0;
  2479. Stat.spriteRenderUseCacheCount = 0;
  2480. Stat.frustumCulling = 0;
  2481. Stat.octreeNodeCulling = 0;
  2482. Stat.canvasNormal = 0;
  2483. Stat.canvasBitmap = 0;
  2484. Stat.canvasReCache = 0;
  2485. Stat.renderSlow = false;
  2486. Stat._fpsData = [];
  2487. Stat._timer = 0;
  2488. Stat._count = 0;
  2489. Stat._StatRender = null;
  2490. class StringKey {
  2491. constructor() {
  2492. this._strsToID = {};
  2493. this._idToStrs = [];
  2494. this._length = 0;
  2495. }
  2496. add(str) {
  2497. var index = this._strsToID[str];
  2498. if (index != null)
  2499. return index;
  2500. this._idToStrs[this._length] = str;
  2501. return this._strsToID[str] = this._length++;
  2502. }
  2503. getID(str) {
  2504. var index = this._strsToID[str];
  2505. return index == null ? -1 : index;
  2506. }
  2507. getName(id) {
  2508. var str = this._idToStrs[id];
  2509. return str == null ? undefined : str;
  2510. }
  2511. }
  2512. class Shader extends BaseShader {
  2513. constructor(vs, ps, saveName = null, nameMap = null, bindAttrib = null) {
  2514. super();
  2515. this._attribInfo = null;
  2516. this.customCompile = false;
  2517. this._curActTexIndex = 0;
  2518. this.tag = {};
  2519. this._program = null;
  2520. this._params = null;
  2521. this._paramsMap = {};
  2522. if ((!vs) || (!ps))
  2523. throw "Shader Error";
  2524. this._attribInfo = bindAttrib;
  2525. this._id = ++Shader._count;
  2526. this._vs = vs;
  2527. this._ps = ps;
  2528. this._nameMap = nameMap ? nameMap : {};
  2529. saveName != null && (Shader.sharders[saveName] = this);
  2530. this.recreateResource();
  2531. this.lock = true;
  2532. }
  2533. static getShader(name) {
  2534. return Shader.sharders[name];
  2535. }
  2536. static create(vs, ps, saveName = null, nameMap = null, bindAttrib = null) {
  2537. return new Shader(vs, ps, saveName, nameMap, bindAttrib);
  2538. }
  2539. static withCompile(nameID, define, shaderName, createShader) {
  2540. if (shaderName && Shader.sharders[shaderName])
  2541. return Shader.sharders[shaderName];
  2542. var pre = Shader._preCompileShader[Shader.SHADERNAME2ID * nameID];
  2543. if (!pre)
  2544. throw new Error("withCompile shader err!" + nameID);
  2545. return pre.createShader(define, shaderName, createShader, null);
  2546. }
  2547. static withCompile2D(nameID, mainID, define, shaderName, createShader, bindAttrib = null) {
  2548. if (shaderName && Shader.sharders[shaderName])
  2549. return Shader.sharders[shaderName];
  2550. var pre = Shader._preCompileShader[Shader.SHADERNAME2ID * nameID + mainID];
  2551. if (!pre)
  2552. throw new Error("withCompile shader err!" + nameID + " " + mainID);
  2553. return pre.createShader(define, shaderName, createShader, bindAttrib);
  2554. }
  2555. static addInclude(fileName, txt) {
  2556. ILaya.ShaderCompile.addInclude(fileName, txt);
  2557. }
  2558. static preCompile(nameID, vs, ps, nameMap) {
  2559. var id = Shader.SHADERNAME2ID * nameID;
  2560. Shader._preCompileShader[id] = new ILaya.ShaderCompile(vs, ps, nameMap);
  2561. }
  2562. static preCompile2D(nameID, mainID, vs, ps, nameMap) {
  2563. var id = Shader.SHADERNAME2ID * nameID + mainID;
  2564. Shader._preCompileShader[id] = new ILaya.ShaderCompile(vs, ps, nameMap);
  2565. }
  2566. recreateResource() {
  2567. this._compile();
  2568. this._setGPUMemory(0);
  2569. }
  2570. _disposeResource() {
  2571. WebGLContext.mainContext.deleteShader(this._vshader);
  2572. WebGLContext.mainContext.deleteShader(this._pshader);
  2573. WebGLContext.mainContext.deleteProgram(this._program);
  2574. this._vshader = this._pshader = this._program = null;
  2575. this._params = null;
  2576. this._paramsMap = {};
  2577. this._setGPUMemory(0);
  2578. this._curActTexIndex = 0;
  2579. }
  2580. _compile() {
  2581. if (!this._vs || !this._ps || this._params)
  2582. return;
  2583. this._reCompile = true;
  2584. this._params = [];
  2585. var result;
  2586. if (this.customCompile)
  2587. result = ILaya.ShaderCompile.preGetParams(this._vs, this._ps);
  2588. var gl = WebGLContext.mainContext;
  2589. this._program = gl.createProgram();
  2590. this._vshader = Shader._createShader(gl, this._vs, gl.VERTEX_SHADER);
  2591. this._pshader = Shader._createShader(gl, this._ps, gl.FRAGMENT_SHADER);
  2592. gl.attachShader(this._program, this._vshader);
  2593. gl.attachShader(this._program, this._pshader);
  2594. var one, i, n, location;
  2595. var attribDescNum = this._attribInfo ? this._attribInfo.length : 0;
  2596. for (i = 0; i < attribDescNum; i += 2) {
  2597. gl.bindAttribLocation(this._program, this._attribInfo[i + 1], this._attribInfo[i]);
  2598. }
  2599. gl.linkProgram(this._program);
  2600. if (!this.customCompile && !gl.getProgramParameter(this._program, gl.LINK_STATUS)) {
  2601. throw gl.getProgramInfoLog(this._program);
  2602. }
  2603. var nUniformNum = this.customCompile ? result.uniforms.length : gl.getProgramParameter(this._program, gl.ACTIVE_UNIFORMS);
  2604. for (i = 0; i < nUniformNum; i++) {
  2605. var uniform = this.customCompile ? result.uniforms[i] : gl.getActiveUniform(this._program, i);
  2606. location = gl.getUniformLocation(this._program, uniform.name);
  2607. one = { vartype: "uniform", glfun: null, ivartype: 1, location: location, name: uniform.name, type: uniform.type, isArray: false, isSame: false, preValue: null, indexOfParams: 0 };
  2608. if (one.name.indexOf('[0]') > 0) {
  2609. one.name = one.name.substr(0, one.name.length - 3);
  2610. one.isArray = true;
  2611. one.location = gl.getUniformLocation(this._program, one.name);
  2612. }
  2613. this._params.push(one);
  2614. }
  2615. for (i = 0, n = this._params.length; i < n; i++) {
  2616. one = this._params[i];
  2617. one.indexOfParams = i;
  2618. one.index = 1;
  2619. one.value = [one.location, null];
  2620. one.codename = one.name;
  2621. one.name = this._nameMap[one.codename] ? this._nameMap[one.codename] : one.codename;
  2622. this._paramsMap[one.name] = one;
  2623. one._this = this;
  2624. one.uploadedValue = [];
  2625. switch (one.type) {
  2626. case gl.INT:
  2627. one.fun = one.isArray ? this._uniform1iv : this._uniform1i;
  2628. break;
  2629. case gl.FLOAT:
  2630. one.fun = one.isArray ? this._uniform1fv : this._uniform1f;
  2631. break;
  2632. case gl.FLOAT_VEC2:
  2633. one.fun = one.isArray ? this._uniform_vec2v : this._uniform_vec2;
  2634. break;
  2635. case gl.FLOAT_VEC3:
  2636. one.fun = one.isArray ? this._uniform_vec3v : this._uniform_vec3;
  2637. break;
  2638. case gl.FLOAT_VEC4:
  2639. one.fun = one.isArray ? this._uniform_vec4v : this._uniform_vec4;
  2640. break;
  2641. case gl.SAMPLER_2D:
  2642. one.fun = this._uniform_sampler2D;
  2643. break;
  2644. case gl.SAMPLER_CUBE:
  2645. one.fun = this._uniform_samplerCube;
  2646. break;
  2647. case gl.FLOAT_MAT4:
  2648. one.glfun = gl.uniformMatrix4fv;
  2649. one.fun = this._uniformMatrix4fv;
  2650. break;
  2651. case gl.BOOL:
  2652. one.fun = this._uniform1i;
  2653. break;
  2654. case gl.FLOAT_MAT2:
  2655. case gl.FLOAT_MAT3:
  2656. throw new Error("compile shader err!");
  2657. default:
  2658. throw new Error("compile shader err!");
  2659. }
  2660. }
  2661. }
  2662. static _createShader(gl, str, type) {
  2663. var shader = gl.createShader(type);
  2664. gl.shaderSource(shader, str);
  2665. gl.compileShader(shader);
  2666. if (gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
  2667. return shader;
  2668. }
  2669. else {
  2670. console.log(gl.getShaderInfoLog(shader));
  2671. return null;
  2672. }
  2673. }
  2674. getUniform(name) {
  2675. return this._paramsMap[name];
  2676. }
  2677. _uniform1f(one, value) {
  2678. var uploadedValue = one.uploadedValue;
  2679. if (uploadedValue[0] !== value) {
  2680. WebGLContext.mainContext.uniform1f(one.location, uploadedValue[0] = value);
  2681. return 1;
  2682. }
  2683. return 0;
  2684. }
  2685. _uniform1fv(one, value) {
  2686. if (value.length < 4) {
  2687. var uploadedValue = one.uploadedValue;
  2688. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2] || uploadedValue[3] !== value[3]) {
  2689. WebGLContext.mainContext.uniform1fv(one.location, value);
  2690. uploadedValue[0] = value[0];
  2691. uploadedValue[1] = value[1];
  2692. uploadedValue[2] = value[2];
  2693. uploadedValue[3] = value[3];
  2694. return 1;
  2695. }
  2696. return 0;
  2697. }
  2698. else {
  2699. WebGLContext.mainContext.uniform1fv(one.location, value);
  2700. return 1;
  2701. }
  2702. }
  2703. _uniform_vec2(one, value) {
  2704. var uploadedValue = one.uploadedValue;
  2705. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1]) {
  2706. WebGLContext.mainContext.uniform2f(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1]);
  2707. return 1;
  2708. }
  2709. return 0;
  2710. }
  2711. _uniform_vec2v(one, value) {
  2712. if (value.length < 2) {
  2713. var uploadedValue = one.uploadedValue;
  2714. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2] || uploadedValue[3] !== value[3]) {
  2715. WebGLContext.mainContext.uniform2fv(one.location, value);
  2716. uploadedValue[0] = value[0];
  2717. uploadedValue[1] = value[1];
  2718. uploadedValue[2] = value[2];
  2719. uploadedValue[3] = value[3];
  2720. return 1;
  2721. }
  2722. return 0;
  2723. }
  2724. else {
  2725. WebGLContext.mainContext.uniform2fv(one.location, value);
  2726. return 1;
  2727. }
  2728. }
  2729. _uniform_vec3(one, value) {
  2730. var uploadedValue = one.uploadedValue;
  2731. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2]) {
  2732. WebGLContext.mainContext.uniform3f(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1], uploadedValue[2] = value[2]);
  2733. return 1;
  2734. }
  2735. return 0;
  2736. }
  2737. _uniform_vec3v(one, value) {
  2738. WebGLContext.mainContext.uniform3fv(one.location, value);
  2739. return 1;
  2740. }
  2741. _uniform_vec4(one, value) {
  2742. var uploadedValue = one.uploadedValue;
  2743. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2] || uploadedValue[3] !== value[3]) {
  2744. WebGLContext.mainContext.uniform4f(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1], uploadedValue[2] = value[2], uploadedValue[3] = value[3]);
  2745. return 1;
  2746. }
  2747. return 0;
  2748. }
  2749. _uniform_vec4v(one, value) {
  2750. WebGLContext.mainContext.uniform4fv(one.location, value);
  2751. return 1;
  2752. }
  2753. _uniformMatrix2fv(one, value) {
  2754. WebGLContext.mainContext.uniformMatrix2fv(one.location, false, value);
  2755. return 1;
  2756. }
  2757. _uniformMatrix3fv(one, value) {
  2758. WebGLContext.mainContext.uniformMatrix3fv(one.location, false, value);
  2759. return 1;
  2760. }
  2761. _uniformMatrix4fv(one, value) {
  2762. WebGLContext.mainContext.uniformMatrix4fv(one.location, false, value);
  2763. return 1;
  2764. }
  2765. _uniform1i(one, value) {
  2766. var uploadedValue = one.uploadedValue;
  2767. if (uploadedValue[0] !== value) {
  2768. WebGLContext.mainContext.uniform1i(one.location, uploadedValue[0] = value);
  2769. return 1;
  2770. }
  2771. return 0;
  2772. }
  2773. _uniform1iv(one, value) {
  2774. WebGLContext.mainContext.uniform1iv(one.location, value);
  2775. return 1;
  2776. }
  2777. _uniform_ivec2(one, value) {
  2778. var uploadedValue = one.uploadedValue;
  2779. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1]) {
  2780. WebGLContext.mainContext.uniform2i(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1]);
  2781. return 1;
  2782. }
  2783. return 0;
  2784. }
  2785. _uniform_ivec2v(one, value) {
  2786. WebGLContext.mainContext.uniform2iv(one.location, value);
  2787. return 1;
  2788. }
  2789. _uniform_vec3i(one, value) {
  2790. var uploadedValue = one.uploadedValue;
  2791. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2]) {
  2792. WebGLContext.mainContext.uniform3i(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1], uploadedValue[2] = value[2]);
  2793. return 1;
  2794. }
  2795. return 0;
  2796. }
  2797. _uniform_vec3vi(one, value) {
  2798. WebGLContext.mainContext.uniform3iv(one.location, value);
  2799. return 1;
  2800. }
  2801. _uniform_vec4i(one, value) {
  2802. var uploadedValue = one.uploadedValue;
  2803. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2] || uploadedValue[3] !== value[3]) {
  2804. WebGLContext.mainContext.uniform4i(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1], uploadedValue[2] = value[2], uploadedValue[3] = value[3]);
  2805. return 1;
  2806. }
  2807. return 0;
  2808. }
  2809. _uniform_vec4vi(one, value) {
  2810. WebGLContext.mainContext.uniform4iv(one.location, value);
  2811. return 1;
  2812. }
  2813. _uniform_sampler2D(one, value) {
  2814. var gl = WebGLContext.mainContext;
  2815. var uploadedValue = one.uploadedValue;
  2816. if (uploadedValue[0] == null) {
  2817. uploadedValue[0] = this._curActTexIndex;
  2818. gl.uniform1i(one.location, this._curActTexIndex);
  2819. WebGLContext.activeTexture(gl, gl.TEXTURE0 + this._curActTexIndex);
  2820. WebGLContext.bindTexture(gl, gl.TEXTURE_2D, value);
  2821. this._curActTexIndex++;
  2822. return 1;
  2823. }
  2824. else {
  2825. WebGLContext.activeTexture(gl, gl.TEXTURE0 + uploadedValue[0]);
  2826. WebGLContext.bindTexture(gl, gl.TEXTURE_2D, value);
  2827. return 0;
  2828. }
  2829. }
  2830. _uniform_samplerCube(one, value) {
  2831. var gl = WebGLContext.mainContext;
  2832. var uploadedValue = one.uploadedValue;
  2833. if (uploadedValue[0] == null) {
  2834. uploadedValue[0] = this._curActTexIndex;
  2835. gl.uniform1i(one.location, this._curActTexIndex);
  2836. WebGLContext.activeTexture(gl, gl.TEXTURE0 + this._curActTexIndex);
  2837. WebGLContext.bindTexture(gl, gl.TEXTURE_CUBE_MAP, value);
  2838. this._curActTexIndex++;
  2839. return 1;
  2840. }
  2841. else {
  2842. WebGLContext.activeTexture(gl, gl.TEXTURE0 + uploadedValue[0]);
  2843. WebGLContext.bindTexture(gl, gl.TEXTURE_CUBE_MAP, value);
  2844. return 0;
  2845. }
  2846. }
  2847. _noSetValue(one) {
  2848. console.log("no....:" + one.name);
  2849. }
  2850. uploadOne(name, value) {
  2851. WebGLContext.useProgram(WebGLContext.mainContext, this._program);
  2852. var one = this._paramsMap[name];
  2853. one.fun.call(this, one, value);
  2854. }
  2855. uploadTexture2D(value) {
  2856. var CTX = WebGLContext;
  2857. if (CTX._activeTextures[0] !== value) {
  2858. CTX.bindTexture(WebGLContext.mainContext, LayaGL.instance.TEXTURE_2D, value);
  2859. CTX._activeTextures[0] = value;
  2860. }
  2861. }
  2862. upload(shaderValue, params = null) {
  2863. BaseShader.activeShader = BaseShader.bindShader = this;
  2864. var gl = WebGLContext.mainContext;
  2865. WebGLContext.useProgram(gl, this._program);
  2866. if (this._reCompile) {
  2867. params = this._params;
  2868. this._reCompile = false;
  2869. }
  2870. else {
  2871. params = params || this._params;
  2872. }
  2873. var one, value, n = params.length, shaderCall = 0;
  2874. for (var i = 0; i < n; i++) {
  2875. one = params[i];
  2876. if ((value = shaderValue[one.name]) !== null)
  2877. shaderCall += one.fun.call(this, one, value);
  2878. }
  2879. Stat.shaderCall += shaderCall;
  2880. }
  2881. uploadArray(shaderValue, length, _bufferUsage) {
  2882. BaseShader.activeShader = this;
  2883. BaseShader.bindShader = this;
  2884. WebGLContext.useProgram(WebGLContext.mainContext, this._program);
  2885. var params = this._params, value;
  2886. var one, shaderCall = 0;
  2887. for (var i = length - 2; i >= 0; i -= 2) {
  2888. one = this._paramsMap[shaderValue[i]];
  2889. if (!one)
  2890. continue;
  2891. value = shaderValue[i + 1];
  2892. if (value != null) {
  2893. _bufferUsage && _bufferUsage[one.name] && _bufferUsage[one.name].bind();
  2894. shaderCall += one.fun.call(this, one, value);
  2895. }
  2896. }
  2897. Stat.shaderCall += shaderCall;
  2898. }
  2899. getParams() {
  2900. return this._params;
  2901. }
  2902. setAttributesLocation(attribDesc) {
  2903. this._attribInfo = attribDesc;
  2904. }
  2905. }
  2906. Shader._count = 0;
  2907. Shader._preCompileShader = {};
  2908. Shader.SHADERNAME2ID = 0.0002;
  2909. Shader.nameKey = new StringKey();
  2910. Shader.sharders = new Array(0x20);
  2911. class Shader2X extends Shader {
  2912. constructor(vs, ps, saveName = null, nameMap = null, bindAttrib = null) {
  2913. super(vs, ps, saveName, nameMap, bindAttrib);
  2914. this._params2dQuick2 = null;
  2915. this._shaderValueWidth = 0;
  2916. this._shaderValueHeight = 0;
  2917. }
  2918. _disposeResource() {
  2919. super._disposeResource();
  2920. this._params2dQuick2 = null;
  2921. }
  2922. upload2dQuick2(shaderValue) {
  2923. this.upload(shaderValue, this._params2dQuick2 || this._make2dQuick2());
  2924. }
  2925. _make2dQuick2() {
  2926. if (!this._params2dQuick2) {
  2927. this._params2dQuick2 = [];
  2928. var params = this._params, one;
  2929. for (var i = 0, n = params.length; i < n; i++) {
  2930. one = params[i];
  2931. if (one.name !== "size")
  2932. this._params2dQuick2.push(one);
  2933. }
  2934. }
  2935. return this._params2dQuick2;
  2936. }
  2937. static create(vs, ps, saveName = null, nameMap = null, bindAttrib = null) {
  2938. return new Shader2X(vs, ps, saveName, nameMap, bindAttrib);
  2939. }
  2940. }
  2941. class Value2D {
  2942. constructor(mainID, subID) {
  2943. this.defines = new ShaderDefines2D();
  2944. this.size = [0, 0];
  2945. this.alpha = 1.0;
  2946. this.ALPHA = 1.0;
  2947. this.subID = 0;
  2948. this.ref = 1;
  2949. this._cacheID = 0;
  2950. this.clipMatDir = [ILaya.Context._MAXSIZE, 0, 0, ILaya.Context._MAXSIZE];
  2951. this.clipMatPos = [0, 0];
  2952. this.clipOff = [0, 0];
  2953. this.mainID = mainID;
  2954. this.subID = subID;
  2955. this.textureHost = null;
  2956. this.texture = null;
  2957. this.color = null;
  2958. this.colorAdd = null;
  2959. this.u_mmat2 = null;
  2960. this._cacheID = mainID | subID;
  2961. this._inClassCache = Value2D._cache[this._cacheID];
  2962. if (mainID > 0 && !this._inClassCache) {
  2963. this._inClassCache = Value2D._cache[this._cacheID] = [];
  2964. this._inClassCache._length = 0;
  2965. }
  2966. this.clear();
  2967. }
  2968. static _initone(type, classT) {
  2969. Value2D._typeClass[type] = classT;
  2970. Value2D._cache[type] = [];
  2971. Value2D._cache[type]._length = 0;
  2972. }
  2973. static __init__() {
  2974. }
  2975. setValue(value) { }
  2976. _ShaderWithCompile() {
  2977. var ret = Shader.withCompile2D(0, this.mainID, this.defines.toNameDic(), this.mainID | this.defines._value, Shader2X.create, this._attribLocation);
  2978. return ret;
  2979. }
  2980. upload() {
  2981. var renderstate2d = RenderState2D;
  2982. RenderState2D.worldMatrix4 === RenderState2D.TEMPMAT4_ARRAY || this.defines.addInt(ShaderDefines2D.WORLDMAT);
  2983. this.mmat = renderstate2d.worldMatrix4;
  2984. if (RenderState2D.matWVP) {
  2985. this.defines.addInt(ShaderDefines2D.MVP3D);
  2986. this.u_MvpMatrix = RenderState2D.matWVP.elements;
  2987. }
  2988. var sd = Shader.sharders[this.mainID | this.defines._value] || this._ShaderWithCompile();
  2989. if (sd._shaderValueWidth !== renderstate2d.width || sd._shaderValueHeight !== renderstate2d.height) {
  2990. this.size[0] = renderstate2d.width;
  2991. this.size[1] = renderstate2d.height;
  2992. sd._shaderValueWidth = renderstate2d.width;
  2993. sd._shaderValueHeight = renderstate2d.height;
  2994. sd.upload(this, null);
  2995. }
  2996. else {
  2997. sd.upload(this, sd._params2dQuick2 || sd._make2dQuick2());
  2998. }
  2999. }
  3000. setFilters(value) {
  3001. this.filters = value;
  3002. if (!value)
  3003. return;
  3004. var n = value.length, f;
  3005. for (var i = 0; i < n; i++) {
  3006. f = value[i];
  3007. if (f) {
  3008. this.defines.add(f.type);
  3009. f.action.setValue(this);
  3010. }
  3011. }
  3012. }
  3013. clear() {
  3014. this.defines._value = this.subID + (ILaya.WebGL.shaderHighPrecision ? ShaderDefines2D.SHADERDEFINE_FSHIGHPRECISION : 0);
  3015. this.clipOff[0] = 0;
  3016. }
  3017. release() {
  3018. if ((--this.ref) < 1) {
  3019. this._inClassCache && (this._inClassCache[this._inClassCache._length++] = this);
  3020. this.clear();
  3021. this.filters = null;
  3022. this.ref = 1;
  3023. this.clipOff[0] = 0;
  3024. }
  3025. }
  3026. static create(mainType, subType) {
  3027. var types = Value2D._cache[mainType | subType];
  3028. if (types._length)
  3029. return types[--types._length];
  3030. else
  3031. return new Value2D._typeClass[mainType | subType](subType);
  3032. }
  3033. }
  3034. Value2D._cache = [];
  3035. Value2D._typeClass = [];
  3036. Value2D.TEMPMAT4_ARRAY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  3037. class SubmitKey {
  3038. constructor() {
  3039. this.clear();
  3040. }
  3041. clear() {
  3042. this.submitType = -1;
  3043. this.blendShader = this.other = 0;
  3044. }
  3045. copyFrom(src) {
  3046. this.other = src.other;
  3047. this.blendShader = src.blendShader;
  3048. this.submitType = src.submitType;
  3049. }
  3050. copyFrom2(src, submitType, other) {
  3051. this.other = other;
  3052. this.submitType = submitType;
  3053. }
  3054. equal3_2(next, submitType, other) {
  3055. return this.submitType === submitType && this.other === other && this.blendShader === next.blendShader;
  3056. }
  3057. equal4_2(next, submitType, other) {
  3058. return this.submitType === submitType && this.other === other && this.blendShader === next.blendShader;
  3059. }
  3060. equal_3(next) {
  3061. return this.submitType === next.submitType && this.blendShader === next.blendShader;
  3062. }
  3063. equal(next) {
  3064. return this.other === next.other && this.submitType === next.submitType && this.blendShader === next.blendShader;
  3065. }
  3066. }
  3067. class SubmitCMD {
  3068. constructor() {
  3069. this._ref = 1;
  3070. this._key = new SubmitKey();
  3071. }
  3072. renderSubmit() {
  3073. this.fun.apply(this._this, this.args);
  3074. return 1;
  3075. }
  3076. getRenderType() {
  3077. return 0;
  3078. }
  3079. releaseRender() {
  3080. if ((--this._ref) < 1) {
  3081. var pool = SubmitCMD.POOL;
  3082. pool[pool._length++] = this;
  3083. }
  3084. }
  3085. static create(args, fun, thisobj) {
  3086. var o = SubmitCMD.POOL._length ? SubmitCMD.POOL[--SubmitCMD.POOL._length] : new SubmitCMD();
  3087. o.fun = fun;
  3088. o.args = args;
  3089. o._this = thisobj;
  3090. o._ref = 1;
  3091. o._key.clear();
  3092. return o;
  3093. }
  3094. }
  3095. SubmitCMD.POOL = [];
  3096. {
  3097. SubmitCMD.POOL._length = 0;
  3098. }
  3099. class Filter {
  3100. constructor() { }
  3101. get type() { return -1; }
  3102. }
  3103. Filter.BLUR = 0x10;
  3104. Filter.COLOR = 0x20;
  3105. Filter.GLOW = 0x08;
  3106. Filter._filter = function (sprite, context, x, y) {
  3107. var webglctx = context;
  3108. var next = this._next;
  3109. if (next) {
  3110. var filters = sprite.filters, len = filters.length;
  3111. if (len == 1 && (filters[0].type == Filter.COLOR)) {
  3112. context.save();
  3113. context.setColorFilter(filters[0]);
  3114. next._fun.call(next, sprite, context, x, y);
  3115. context.restore();
  3116. return;
  3117. }
  3118. var svCP = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  3119. var b;
  3120. var p = Point.TEMP;
  3121. var tMatrix = webglctx._curMat;
  3122. var mat = Matrix.create();
  3123. tMatrix.copyTo(mat);
  3124. var tPadding = 0;
  3125. var tHalfPadding = 0;
  3126. var tIsHaveGlowFilter = false;
  3127. var source = null;
  3128. var out = sprite._cacheStyle.filterCache || null;
  3129. if (!out || sprite.getRepaint() != 0) {
  3130. tIsHaveGlowFilter = sprite._isHaveGlowFilter();
  3131. if (tIsHaveGlowFilter) {
  3132. tPadding = 50;
  3133. tHalfPadding = 25;
  3134. }
  3135. b = new Rectangle();
  3136. b.copyFrom(sprite.getSelfBounds());
  3137. b.x += sprite.x;
  3138. b.y += sprite.y;
  3139. b.x -= sprite.pivotX + 4;
  3140. b.y -= sprite.pivotY + 4;
  3141. var tSX = b.x;
  3142. var tSY = b.y;
  3143. b.width += (tPadding + 8);
  3144. b.height += (tPadding + 8);
  3145. p.x = b.x * mat.a + b.y * mat.c;
  3146. p.y = b.y * mat.d + b.x * mat.b;
  3147. b.x = p.x;
  3148. b.y = p.y;
  3149. p.x = b.width * mat.a + b.height * mat.c;
  3150. p.y = b.height * mat.d + b.width * mat.b;
  3151. b.width = p.x;
  3152. b.height = p.y;
  3153. if (b.width <= 0 || b.height <= 0) {
  3154. return;
  3155. }
  3156. out && WebGLRTMgr.releaseRT(out);
  3157. source = WebGLRTMgr.getRT(b.width, b.height);
  3158. var outRT = out = WebGLRTMgr.getRT(b.width, b.height);
  3159. sprite._getCacheStyle().filterCache = out;
  3160. webglctx.pushRT();
  3161. webglctx.useRT(source);
  3162. var tX = sprite.x - tSX + tHalfPadding;
  3163. var tY = sprite.y - tSY + tHalfPadding;
  3164. next._fun.call(next, sprite, context, tX, tY);
  3165. webglctx.useRT(outRT);
  3166. for (var i = 0; i < len; i++) {
  3167. if (i != 0) {
  3168. webglctx.useRT(source);
  3169. webglctx.drawTarget(outRT, 0, 0, b.width, b.height, Matrix.TEMP.identity(), svCP, null, BlendMode.TOINT.overlay);
  3170. webglctx.useRT(outRT);
  3171. }
  3172. var fil = filters[i];
  3173. switch (fil.type) {
  3174. case Filter.BLUR:
  3175. fil._glRender && fil._glRender.render(source, context, b.width, b.height, fil);
  3176. break;
  3177. case Filter.GLOW:
  3178. fil._glRender && fil._glRender.render(source, context, b.width, b.height, fil);
  3179. break;
  3180. case Filter.COLOR:
  3181. webglctx.setColorFilter(fil);
  3182. webglctx.drawTarget(source, 0, 0, b.width, b.height, Matrix.EMPTY.identity(), Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  3183. webglctx.setColorFilter(null);
  3184. break;
  3185. }
  3186. }
  3187. webglctx.popRT();
  3188. }
  3189. else {
  3190. tIsHaveGlowFilter = sprite._cacheStyle.hasGlowFilter || false;
  3191. if (tIsHaveGlowFilter) {
  3192. tPadding = 50;
  3193. tHalfPadding = 25;
  3194. }
  3195. b = sprite.getBounds();
  3196. if (b.width <= 0 || b.height <= 0) {
  3197. return;
  3198. }
  3199. b.width += tPadding;
  3200. b.height += tPadding;
  3201. p.x = b.x * mat.a + b.y * mat.c;
  3202. p.y = b.y * mat.d + b.x * mat.b;
  3203. b.x = p.x;
  3204. b.y = p.y;
  3205. p.x = b.width * mat.a + b.height * mat.c;
  3206. p.y = b.height * mat.d + b.width * mat.b;
  3207. b.width = p.x;
  3208. b.height = p.y;
  3209. }
  3210. x = x - tHalfPadding - sprite.x;
  3211. y = y - tHalfPadding - sprite.y;
  3212. p.setTo(x, y);
  3213. mat.transformPoint(p);
  3214. x = p.x + b.x;
  3215. y = p.y + b.y;
  3216. webglctx._drawRenderTexture(out, x, y, b.width, b.height, Matrix.TEMP.identity(), 1.0, RenderTexture2D.defuv);
  3217. if (source) {
  3218. var submit = SubmitCMD.create([source], function (s) {
  3219. s.destroy();
  3220. }, this);
  3221. source = null;
  3222. context.addRenderObject(submit);
  3223. }
  3224. mat.destroy();
  3225. }
  3226. };
  3227. class Utils {
  3228. static toRadian(angle) {
  3229. return angle * Utils._pi2;
  3230. }
  3231. static toAngle(radian) {
  3232. return radian * Utils._pi;
  3233. }
  3234. static toHexColor(color) {
  3235. if (color < 0 || isNaN(color))
  3236. return null;
  3237. var str = color.toString(16);
  3238. while (str.length < 6)
  3239. str = "0" + str;
  3240. return "#" + str;
  3241. }
  3242. static getGID() {
  3243. return Utils._gid++;
  3244. }
  3245. static concatArray(source, array) {
  3246. if (!array)
  3247. return source;
  3248. if (!source)
  3249. return array;
  3250. var i, len = array.length;
  3251. for (i = 0; i < len; i++) {
  3252. source.push(array[i]);
  3253. }
  3254. return source;
  3255. }
  3256. static clearArray(array) {
  3257. if (!array)
  3258. return array;
  3259. array.length = 0;
  3260. return array;
  3261. }
  3262. static copyArray(source, array) {
  3263. source || (source = []);
  3264. if (!array)
  3265. return source;
  3266. source.length = array.length;
  3267. var i, len = array.length;
  3268. for (i = 0; i < len; i++) {
  3269. source[i] = array[i];
  3270. }
  3271. return source;
  3272. }
  3273. static getGlobalRecByPoints(sprite, x0, y0, x1, y1) {
  3274. var newLTPoint;
  3275. newLTPoint = Point.create().setTo(x0, y0);
  3276. newLTPoint = sprite.localToGlobal(newLTPoint);
  3277. var newRBPoint;
  3278. newRBPoint = Point.create().setTo(x1, y1);
  3279. newRBPoint = sprite.localToGlobal(newRBPoint);
  3280. var rst = Rectangle._getWrapRec([newLTPoint.x, newLTPoint.y, newRBPoint.x, newRBPoint.y]);
  3281. newLTPoint.recover();
  3282. newRBPoint.recover();
  3283. return rst;
  3284. }
  3285. static getGlobalPosAndScale(sprite) {
  3286. return Utils.getGlobalRecByPoints(sprite, 0, 0, 1, 1);
  3287. }
  3288. static bind(fun, scope) {
  3289. var rst = fun;
  3290. rst = fun.bind(scope);
  3291. return rst;
  3292. }
  3293. static updateOrder(array) {
  3294. if (!array || array.length < 2)
  3295. return false;
  3296. var i = 1, j, len = array.length, key, c;
  3297. while (i < len) {
  3298. j = i;
  3299. c = array[j];
  3300. key = array[j]._zOrder;
  3301. while (--j > -1) {
  3302. if (array[j]._zOrder > key)
  3303. array[j + 1] = array[j];
  3304. else
  3305. break;
  3306. }
  3307. array[j + 1] = c;
  3308. i++;
  3309. }
  3310. return true;
  3311. }
  3312. static transPointList(points, x, y) {
  3313. var i, len = points.length;
  3314. for (i = 0; i < len; i += 2) {
  3315. points[i] += x;
  3316. points[i + 1] += y;
  3317. }
  3318. }
  3319. static parseInt(str, radix = 0) {
  3320. var result = parseInt(str, radix);
  3321. if (isNaN(result))
  3322. return 0;
  3323. return result;
  3324. }
  3325. static getFileExtension(path) {
  3326. Utils._extReg.lastIndex = path.lastIndexOf(".");
  3327. var result = Utils._extReg.exec(path);
  3328. if (result && result.length > 1) {
  3329. return result[1].toLowerCase();
  3330. }
  3331. return null;
  3332. }
  3333. static getTransformRelativeToWindow(coordinateSpace, x, y) {
  3334. var stage = Utils.gStage;
  3335. var globalTransform = Utils.getGlobalPosAndScale(coordinateSpace);
  3336. var canvasMatrix = stage._canvasTransform.clone();
  3337. var canvasLeft = canvasMatrix.tx;
  3338. var canvasTop = canvasMatrix.ty;
  3339. canvasMatrix.rotate(-Math.PI / 180 * stage.canvasDegree);
  3340. canvasMatrix.scale(stage.clientScaleX, stage.clientScaleY);
  3341. var perpendicular = (stage.canvasDegree % 180 != 0);
  3342. var tx, ty;
  3343. if (perpendicular) {
  3344. tx = y + globalTransform.y;
  3345. ty = x + globalTransform.x;
  3346. tx *= canvasMatrix.d;
  3347. ty *= canvasMatrix.a;
  3348. if (stage.canvasDegree == 90) {
  3349. tx = canvasLeft - tx;
  3350. ty += canvasTop;
  3351. }
  3352. else {
  3353. tx += canvasLeft;
  3354. ty = canvasTop - ty;
  3355. }
  3356. }
  3357. else {
  3358. tx = x + globalTransform.x;
  3359. ty = y + globalTransform.y;
  3360. tx *= canvasMatrix.a;
  3361. ty *= canvasMatrix.d;
  3362. tx += canvasLeft;
  3363. ty += canvasTop;
  3364. }
  3365. ty += stage['_safariOffsetY'];
  3366. var domScaleX, domScaleY;
  3367. if (perpendicular) {
  3368. domScaleX = canvasMatrix.d * globalTransform.height;
  3369. domScaleY = canvasMatrix.a * globalTransform.width;
  3370. }
  3371. else {
  3372. domScaleX = canvasMatrix.a * globalTransform.width;
  3373. domScaleY = canvasMatrix.d * globalTransform.height;
  3374. }
  3375. return { x: tx, y: ty, scaleX: domScaleX, scaleY: domScaleY };
  3376. }
  3377. static fitDOMElementInArea(dom, coordinateSpace, x, y, width, height) {
  3378. if (!dom._fitLayaAirInitialized) {
  3379. dom._fitLayaAirInitialized = true;
  3380. dom.style.transformOrigin = dom.style.webKittransformOrigin = "left top";
  3381. dom.style.position = "absolute";
  3382. }
  3383. var transform = Utils.getTransformRelativeToWindow(coordinateSpace, x, y);
  3384. dom.style.transform = dom.style.webkitTransform = "scale(" + transform.scaleX + "," + transform.scaleY + ") rotate(" + (Utils.gStage.canvasDegree) + "deg)";
  3385. dom.style.width = width + 'px';
  3386. dom.style.height = height + 'px';
  3387. dom.style.left = transform.x + 'px';
  3388. dom.style.top = transform.y + 'px';
  3389. }
  3390. static isOkTextureList(textureList) {
  3391. if (!textureList)
  3392. return false;
  3393. var i, len = textureList.length;
  3394. var tTexture;
  3395. for (i = 0; i < len; i++) {
  3396. tTexture = textureList[i];
  3397. if (!tTexture || !tTexture._getSource())
  3398. return false;
  3399. }
  3400. return true;
  3401. }
  3402. static isOKCmdList(cmds) {
  3403. if (!cmds)
  3404. return false;
  3405. var i, len = cmds.length;
  3406. var cmd;
  3407. for (i = 0; i < len; i++) {
  3408. cmd = cmds[i];
  3409. }
  3410. return true;
  3411. }
  3412. static getQueryString(name) {
  3413. if (ILaya.Browser.onMiniGame)
  3414. return null;
  3415. if (!window.location || !window.location.search)
  3416. return null;
  3417. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  3418. var r = window.location.search.substr(1).match(reg);
  3419. if (r != null)
  3420. return unescape(r[2]);
  3421. return null;
  3422. }
  3423. }
  3424. Utils.gStage = null;
  3425. Utils._gid = 1;
  3426. Utils._pi = 180 / Math.PI;
  3427. Utils._pi2 = Math.PI / 180;
  3428. Utils._extReg = /\.(\w+)\??/g;
  3429. Utils.parseXMLFromString = function (value) {
  3430. var rst;
  3431. value = value.replace(/>\s+</g, '><');
  3432. rst = (new DOMParser()).parseFromString(value, 'text/xml');
  3433. if (rst.firstChild.textContent.indexOf("This page contains the following errors") > -1) {
  3434. throw new Error(rst.firstChild.firstChild.textContent);
  3435. }
  3436. return rst;
  3437. };
  3438. class ColorUtils {
  3439. constructor(value) {
  3440. this.arrColor = [];
  3441. if (value == null) {
  3442. this.strColor = "#00000000";
  3443. this.numColor = 0;
  3444. this.arrColor = [0, 0, 0, 0];
  3445. return;
  3446. }
  3447. var i, len;
  3448. var color;
  3449. if (typeof (value) == 'string') {
  3450. if (value.indexOf("rgba(") >= 0 || value.indexOf("rgb(") >= 0) {
  3451. var tStr = value;
  3452. var beginI, endI;
  3453. beginI = tStr.indexOf("(");
  3454. endI = tStr.indexOf(")");
  3455. tStr = tStr.substring(beginI + 1, endI);
  3456. this.arrColor = tStr.split(",");
  3457. len = this.arrColor.length;
  3458. for (i = 0; i < len; i++) {
  3459. this.arrColor[i] = parseFloat(this.arrColor[i]);
  3460. if (i < 3) {
  3461. this.arrColor[i] = Math.round(this.arrColor[i]);
  3462. }
  3463. }
  3464. if (this.arrColor.length == 4) {
  3465. color = ((this.arrColor[0] * 256 + this.arrColor[1]) * 256 + this.arrColor[2]) * 256 + Math.round(this.arrColor[3] * 255);
  3466. }
  3467. else {
  3468. color = ((this.arrColor[0] * 256 + this.arrColor[1]) * 256 + this.arrColor[2]);
  3469. }
  3470. this.strColor = value;
  3471. }
  3472. else {
  3473. this.strColor = value;
  3474. value.charAt(0) === '#' && (value = value.substr(1));
  3475. len = value.length;
  3476. if (len === 3 || len === 4) {
  3477. var temp = "";
  3478. for (i = 0; i < len; i++) {
  3479. temp += (value[i] + value[i]);
  3480. }
  3481. value = temp;
  3482. }
  3483. color = parseInt(value, 16);
  3484. }
  3485. }
  3486. else {
  3487. color = value;
  3488. this.strColor = Utils.toHexColor(color);
  3489. }
  3490. if (this.strColor.indexOf("rgba") >= 0 || this.strColor.length === 9) {
  3491. this.arrColor = [((0xFF000000 & color) >>> 24) / 255, ((0xFF0000 & color) >> 16) / 255, ((0xFF00 & color) >> 8) / 255, (0xFF & color) / 255];
  3492. this.numColor = (0xff000000 & color) >>> 24 | (color & 0xff0000) >> 8 | (color & 0x00ff00) << 8 | ((color & 0xff) << 24);
  3493. }
  3494. else {
  3495. this.arrColor = [((0xFF0000 & color) >> 16) / 255, ((0xFF00 & color) >> 8) / 255, (0xFF & color) / 255, 1];
  3496. this.numColor = 0xff000000 | (color & 0xff0000) >> 16 | (color & 0x00ff00) | (color & 0xff) << 16;
  3497. }
  3498. this.arrColor.__id = ++ColorUtils._COLODID;
  3499. }
  3500. static _initDefault() {
  3501. ColorUtils._DEFAULT = {};
  3502. for (var i in ColorUtils._COLOR_MAP)
  3503. ColorUtils._SAVE[i] = ColorUtils._DEFAULT[i] = new ColorUtils(ColorUtils._COLOR_MAP[i]);
  3504. return ColorUtils._DEFAULT;
  3505. }
  3506. static _initSaveMap() {
  3507. ColorUtils._SAVE_SIZE = 0;
  3508. ColorUtils._SAVE = {};
  3509. for (var i in ColorUtils._DEFAULT)
  3510. ColorUtils._SAVE[i] = ColorUtils._DEFAULT[i];
  3511. }
  3512. static create(value) {
  3513. var key = value + "";
  3514. var color = ColorUtils._SAVE[key];
  3515. if (color != null)
  3516. return color;
  3517. if (ColorUtils._SAVE_SIZE < 1000)
  3518. ColorUtils._initSaveMap();
  3519. return ColorUtils._SAVE[key] = new ColorUtils(value);
  3520. }
  3521. }
  3522. ColorUtils._SAVE = {};
  3523. ColorUtils._SAVE_SIZE = 0;
  3524. ColorUtils._COLOR_MAP = { "purple": "#800080", "orange": "#ffa500", "white": '#FFFFFF', "red": '#FF0000', "green": '#00FF00', "blue": '#0000FF', "black": '#000000', "yellow": '#FFFF00', 'gray': '#808080' };
  3525. ColorUtils._DEFAULT = ColorUtils._initDefault();
  3526. ColorUtils._COLODID = 1;
  3527. class ColorFilter extends Filter {
  3528. constructor(mat = null) {
  3529. super();
  3530. if (!mat)
  3531. mat = this._copyMatrix(ColorFilter.IDENTITY_MATRIX);
  3532. this._mat = new Float32Array(16);
  3533. this._alpha = new Float32Array(4);
  3534. this.setByMatrix(mat);
  3535. }
  3536. gray() {
  3537. return this.setByMatrix(ColorFilter.GRAY_MATRIX);
  3538. }
  3539. color(red = 0, green = 0, blue = 0, alpha = 1) {
  3540. return this.setByMatrix([1, 0, 0, 0, red, 0, 1, 0, 0, green, 0, 0, 1, 0, blue, 0, 0, 0, 1, alpha]);
  3541. }
  3542. setColor(color) {
  3543. var arr = ColorUtils.create(color).arrColor;
  3544. var mt = [0, 0, 0, 0, 256 * arr[0], 0, 0, 0, 0, 256 * arr[1], 0, 0, 0, 0, 256 * arr[2], 0, 0, 0, 1, 0];
  3545. return this.setByMatrix(mt);
  3546. }
  3547. setByMatrix(matrix) {
  3548. if (this._matrix != matrix)
  3549. this._copyMatrix(matrix);
  3550. var j = 0;
  3551. var z = 0;
  3552. for (var i = 0; i < 20; i++) {
  3553. if (i % 5 != 4) {
  3554. this._mat[j++] = matrix[i];
  3555. }
  3556. else {
  3557. this._alpha[z++] = matrix[i];
  3558. }
  3559. }
  3560. return this;
  3561. }
  3562. get type() {
  3563. return Filter.COLOR;
  3564. }
  3565. adjustColor(brightness, contrast, saturation, hue) {
  3566. this.adjustHue(hue);
  3567. this.adjustContrast(contrast);
  3568. this.adjustBrightness(brightness);
  3569. this.adjustSaturation(saturation);
  3570. return this;
  3571. }
  3572. adjustBrightness(brightness) {
  3573. brightness = this._clampValue(brightness, 100);
  3574. if (brightness == 0 || isNaN(brightness))
  3575. return this;
  3576. return this._multiplyMatrix([1, 0, 0, 0, brightness, 0, 1, 0, 0, brightness, 0, 0, 1, 0, brightness, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1]);
  3577. }
  3578. adjustContrast(contrast) {
  3579. contrast = this._clampValue(contrast, 100);
  3580. if (contrast == 0 || isNaN(contrast))
  3581. return this;
  3582. var x;
  3583. if (contrast < 0) {
  3584. x = 127 + contrast / 100 * 127;
  3585. }
  3586. else {
  3587. x = contrast % 1;
  3588. if (x == 0) {
  3589. x = ColorFilter.DELTA_INDEX[contrast];
  3590. }
  3591. else {
  3592. x = ColorFilter.DELTA_INDEX[(contrast << 0)] * (1 - x) + ColorFilter.DELTA_INDEX[(contrast << 0) + 1] * x;
  3593. }
  3594. x = x * 127 + 127;
  3595. }
  3596. var x1 = x / 127;
  3597. var x2 = (127 - x) * 0.5;
  3598. return this._multiplyMatrix([x1, 0, 0, 0, x2, 0, x1, 0, 0, x2, 0, 0, x1, 0, x2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1]);
  3599. }
  3600. adjustSaturation(saturation) {
  3601. saturation = this._clampValue(saturation, 100);
  3602. if (saturation == 0 || isNaN(saturation))
  3603. return this;
  3604. var x = 1 + ((saturation > 0) ? 3 * saturation / 100 : saturation / 100);
  3605. var dx = 1 - x;
  3606. var r = 0.3086 * dx;
  3607. var g = 0.6094 * dx;
  3608. var b = 0.0820 * dx;
  3609. return this._multiplyMatrix([r + x, g, b, 0, 0, r, g + x, b, 0, 0, r, g, b + x, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1]);
  3610. }
  3611. adjustHue(hue) {
  3612. hue = this._clampValue(hue, 180) / 180 * Math.PI;
  3613. if (hue == 0 || isNaN(hue))
  3614. return this;
  3615. var cos = Math.cos(hue);
  3616. var sin = Math.sin(hue);
  3617. var r = 0.213;
  3618. var g = 0.715;
  3619. var b = 0.072;
  3620. return this._multiplyMatrix([r + cos * (1 - r) + sin * (-r), g + cos * (-g) + sin * (-g), b + cos * (-b) + sin * (1 - b), 0, 0, r + cos * (-r) + sin * (0.143), g + cos * (1 - g) + sin * (0.140), b + cos * (-b) + sin * (-0.283), 0, 0, r + cos * (-r) + sin * (-(1 - r)), g + cos * (-g) + sin * (g), b + cos * (1 - b) + sin * (b), 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1]);
  3621. }
  3622. reset() {
  3623. return this.setByMatrix(this._copyMatrix(ColorFilter.IDENTITY_MATRIX));
  3624. }
  3625. _multiplyMatrix(matrix) {
  3626. var col = [];
  3627. this._matrix = this._fixMatrix(this._matrix);
  3628. for (var i = 0; i < 5; i++) {
  3629. for (var j = 0; j < 5; j++) {
  3630. col[j] = this._matrix[j + i * 5];
  3631. }
  3632. for (j = 0; j < 5; j++) {
  3633. var val = 0;
  3634. for (var k = 0; k < 5; k++) {
  3635. val += matrix[j + k * 5] * col[k];
  3636. }
  3637. this._matrix[j + i * 5] = val;
  3638. }
  3639. }
  3640. return this.setByMatrix(this._matrix);
  3641. }
  3642. _clampValue(val, limit) {
  3643. return Math.min(limit, Math.max(-limit, val));
  3644. }
  3645. _fixMatrix(matrix = null) {
  3646. if (matrix == null)
  3647. return ColorFilter.IDENTITY_MATRIX;
  3648. if (matrix.length < ColorFilter.LENGTH)
  3649. matrix = matrix.slice(0, matrix.length).concat(ColorFilter.IDENTITY_MATRIX.slice(matrix.length, ColorFilter.LENGTH));
  3650. else if (matrix.length > ColorFilter.LENGTH)
  3651. matrix = matrix.slice(0, ColorFilter.LENGTH);
  3652. return matrix;
  3653. }
  3654. _copyMatrix(matrix) {
  3655. var len = ColorFilter.LENGTH;
  3656. if (!this._matrix)
  3657. this._matrix = [];
  3658. for (var i = 0; i < len; i++) {
  3659. this._matrix[i] = matrix[i];
  3660. }
  3661. return this._matrix;
  3662. }
  3663. }
  3664. ColorFilter.DELTA_INDEX = [0, 0.01, 0.02, 0.04, 0.05, 0.06, 0.07, 0.08, 0.1, 0.11, 0.12, 0.14, 0.15, 0.16, 0.17, 0.18, 0.20, 0.21, 0.22, 0.24, 0.25, 0.27, 0.28, 0.30, 0.32, 0.34, 0.36, 0.38, 0.40, 0.42, 0.44, 0.46, 0.48, 0.5, 0.53, 0.56, 0.59, 0.62, 0.65, 0.68, 0.71, 0.74, 0.77, 0.80, 0.83, 0.86, 0.89, 0.92, 0.95, 0.98, 1.0, 1.06, 1.12, 1.18, 1.24, 1.30, 1.36, 1.42, 1.48, 1.54, 1.60, 1.66, 1.72, 1.78, 1.84, 1.90, 1.96, 2.0, 2.12, 2.25, 2.37, 2.50, 2.62, 2.75, 2.87, 3.0, 3.2, 3.4, 3.6, 3.8, 4.0, 4.3, 4.7, 4.9, 5.0, 5.5, 6.0, 6.5, 6.8, 7.0, 7.3, 7.5, 7.8, 8.0, 8.4, 8.7, 9.0, 9.4, 9.6, 9.8, 10.0];
  3665. ColorFilter.GRAY_MATRIX = [0.3086, 0.6094, 0.082, 0, 0, 0.3086, 0.6094, 0.082, 0, 0, 0.3086, 0.6094, 0.082, 0, 0, 0, 0, 0, 1, 0];
  3666. ColorFilter.IDENTITY_MATRIX = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1];
  3667. ColorFilter.LENGTH = 25;
  3668. class DrawTextureCmd {
  3669. constructor() {
  3670. this.colorFlt = null;
  3671. this.uv = null;
  3672. }
  3673. static create(texture, x, y, width, height, matrix, alpha, color, blendMode, uv) {
  3674. var cmd = Pool.getItemByClass("DrawTextureCmd", DrawTextureCmd);
  3675. cmd.texture = texture;
  3676. texture._addReference();
  3677. cmd.x = x;
  3678. cmd.y = y;
  3679. cmd.width = width;
  3680. cmd.height = height;
  3681. cmd.matrix = matrix;
  3682. cmd.alpha = alpha;
  3683. cmd.color = color;
  3684. cmd.blendMode = blendMode;
  3685. cmd.uv = uv == undefined ? null : uv;
  3686. if (color) {
  3687. cmd.colorFlt = new ColorFilter();
  3688. cmd.colorFlt.setColor(color);
  3689. }
  3690. return cmd;
  3691. }
  3692. recover() {
  3693. this.texture && this.texture._removeReference();
  3694. this.texture = null;
  3695. this.matrix = null;
  3696. Pool.recover("DrawTextureCmd", this);
  3697. }
  3698. run(context, gx, gy) {
  3699. this.texture && context.drawTextureWithTransform(this.texture, this.x, this.y, this.width, this.height, this.matrix, gx, gy, this.alpha, this.blendMode, this.colorFlt, this.uv);
  3700. }
  3701. get cmdID() {
  3702. return DrawTextureCmd.ID;
  3703. }
  3704. }
  3705. DrawTextureCmd.ID = "DrawTexture";
  3706. class FillTextureCmd {
  3707. static create(texture, x, y, width, height, type, offset, other) {
  3708. var cmd = Pool.getItemByClass("FillTextureCmd", FillTextureCmd);
  3709. cmd.texture = texture;
  3710. cmd.x = x;
  3711. cmd.y = y;
  3712. cmd.width = width;
  3713. cmd.height = height;
  3714. cmd.type = type;
  3715. cmd.offset = offset;
  3716. cmd.other = other;
  3717. return cmd;
  3718. }
  3719. recover() {
  3720. this.texture = null;
  3721. this.offset = null;
  3722. this.other = null;
  3723. Pool.recover("FillTextureCmd", this);
  3724. }
  3725. run(context, gx, gy) {
  3726. context.fillTexture(this.texture, this.x + gx, this.y + gy, this.width, this.height, this.type, this.offset, this.other);
  3727. }
  3728. get cmdID() {
  3729. return FillTextureCmd.ID;
  3730. }
  3731. }
  3732. FillTextureCmd.ID = "FillTexture";
  3733. class RestoreCmd {
  3734. static create() {
  3735. var cmd = Pool.getItemByClass("RestoreCmd", RestoreCmd);
  3736. return cmd;
  3737. }
  3738. recover() {
  3739. Pool.recover("RestoreCmd", this);
  3740. }
  3741. run(context, gx, gy) {
  3742. context.restore();
  3743. }
  3744. get cmdID() {
  3745. return RestoreCmd.ID;
  3746. }
  3747. }
  3748. RestoreCmd.ID = "Restore";
  3749. class RotateCmd {
  3750. static create(angle, pivotX, pivotY) {
  3751. var cmd = Pool.getItemByClass("RotateCmd", RotateCmd);
  3752. cmd.angle = angle;
  3753. cmd.pivotX = pivotX;
  3754. cmd.pivotY = pivotY;
  3755. return cmd;
  3756. }
  3757. recover() {
  3758. Pool.recover("RotateCmd", this);
  3759. }
  3760. run(context, gx, gy) {
  3761. context._rotate(this.angle, this.pivotX + gx, this.pivotY + gy);
  3762. }
  3763. get cmdID() {
  3764. return RotateCmd.ID;
  3765. }
  3766. }
  3767. RotateCmd.ID = "Rotate";
  3768. class ScaleCmd {
  3769. static create(scaleX, scaleY, pivotX, pivotY) {
  3770. var cmd = Pool.getItemByClass("ScaleCmd", ScaleCmd);
  3771. cmd.scaleX = scaleX;
  3772. cmd.scaleY = scaleY;
  3773. cmd.pivotX = pivotX;
  3774. cmd.pivotY = pivotY;
  3775. return cmd;
  3776. }
  3777. recover() {
  3778. Pool.recover("ScaleCmd", this);
  3779. }
  3780. run(context, gx, gy) {
  3781. context._scale(this.scaleX, this.scaleY, this.pivotX + gx, this.pivotY + gy);
  3782. }
  3783. get cmdID() {
  3784. return ScaleCmd.ID;
  3785. }
  3786. }
  3787. ScaleCmd.ID = "Scale";
  3788. class TransformCmd {
  3789. static create(matrix, pivotX, pivotY) {
  3790. var cmd = Pool.getItemByClass("TransformCmd", TransformCmd);
  3791. cmd.matrix = matrix;
  3792. cmd.pivotX = pivotX;
  3793. cmd.pivotY = pivotY;
  3794. return cmd;
  3795. }
  3796. recover() {
  3797. this.matrix = null;
  3798. Pool.recover("TransformCmd", this);
  3799. }
  3800. run(context, gx, gy) {
  3801. context._transform(this.matrix, this.pivotX + gx, this.pivotY + gy);
  3802. }
  3803. get cmdID() {
  3804. return TransformCmd.ID;
  3805. }
  3806. }
  3807. TransformCmd.ID = "Transform";
  3808. class TranslateCmd {
  3809. static create(tx, ty) {
  3810. var cmd = Pool.getItemByClass("TranslateCmd", TranslateCmd);
  3811. cmd.tx = tx;
  3812. cmd.ty = ty;
  3813. return cmd;
  3814. }
  3815. recover() {
  3816. Pool.recover("TranslateCmd", this);
  3817. }
  3818. run(context, gx, gy) {
  3819. context.translate(this.tx, this.ty);
  3820. }
  3821. get cmdID() {
  3822. return TranslateCmd.ID;
  3823. }
  3824. }
  3825. TranslateCmd.ID = "Translate";
  3826. class Bezier {
  3827. constructor() {
  3828. this._controlPoints = [new Point(), new Point(), new Point()];
  3829. this._calFun = this.getPoint2;
  3830. }
  3831. _switchPoint(x, y) {
  3832. var tPoint = this._controlPoints.shift();
  3833. tPoint.setTo(x, y);
  3834. this._controlPoints.push(tPoint);
  3835. }
  3836. getPoint2(t, rst) {
  3837. var p1 = this._controlPoints[0];
  3838. var p2 = this._controlPoints[1];
  3839. var p3 = this._controlPoints[2];
  3840. var lineX = Math.pow((1 - t), 2) * p1.x + 2 * t * (1 - t) * p2.x + Math.pow(t, 2) * p3.x;
  3841. var lineY = Math.pow((1 - t), 2) * p1.y + 2 * t * (1 - t) * p2.y + Math.pow(t, 2) * p3.y;
  3842. rst.push(lineX, lineY);
  3843. }
  3844. getPoint3(t, rst) {
  3845. var p1 = this._controlPoints[0];
  3846. var p2 = this._controlPoints[1];
  3847. var p3 = this._controlPoints[2];
  3848. var p4 = this._controlPoints[3];
  3849. var lineX = Math.pow((1 - t), 3) * p1.x + 3 * p2.x * t * (1 - t) * (1 - t) + 3 * p3.x * t * t * (1 - t) + p4.x * Math.pow(t, 3);
  3850. var lineY = Math.pow((1 - t), 3) * p1.y + 3 * p2.y * t * (1 - t) * (1 - t) + 3 * p3.y * t * t * (1 - t) + p4.y * Math.pow(t, 3);
  3851. rst.push(lineX, lineY);
  3852. }
  3853. insertPoints(count, rst) {
  3854. var i;
  3855. count = count > 0 ? count : 5;
  3856. var dLen;
  3857. dLen = 1 / count;
  3858. for (i = 0; i <= 1; i += dLen) {
  3859. this._calFun(i, rst);
  3860. }
  3861. }
  3862. getBezierPoints(pList, inSertCount = 5, count = 2) {
  3863. var i, len;
  3864. len = pList.length;
  3865. if (len < (count + 1) * 2)
  3866. return [];
  3867. var rst = [];
  3868. switch (count) {
  3869. case 2:
  3870. this._calFun = this.getPoint2;
  3871. break;
  3872. case 3:
  3873. this._calFun = this.getPoint3;
  3874. break;
  3875. default:
  3876. return [];
  3877. }
  3878. while (this._controlPoints.length <= count) {
  3879. this._controlPoints.push(Point.create());
  3880. }
  3881. for (i = 0; i < count * 2; i += 2) {
  3882. this._switchPoint(pList[i], pList[i + 1]);
  3883. }
  3884. for (i = count * 2; i < len; i += 2) {
  3885. this._switchPoint(pList[i], pList[i + 1]);
  3886. if ((i / 2) % count == 0)
  3887. this.insertPoints(inSertCount, rst);
  3888. }
  3889. return rst;
  3890. }
  3891. }
  3892. Bezier.I = new Bezier();
  3893. class GrahamScan {
  3894. static multiply(p1, p2, p0) {
  3895. return ((p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y));
  3896. }
  3897. static dis(p1, p2) {
  3898. return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
  3899. }
  3900. static _getPoints(count, tempUse = false, rst = null) {
  3901. if (!GrahamScan._mPointList)
  3902. GrahamScan._mPointList = [];
  3903. while (GrahamScan._mPointList.length < count)
  3904. GrahamScan._mPointList.push(new Point());
  3905. if (!rst)
  3906. rst = [];
  3907. rst.length = 0;
  3908. if (tempUse) {
  3909. GrahamScan.getFrom(rst, GrahamScan._mPointList, count);
  3910. }
  3911. else {
  3912. GrahamScan.getFromR(rst, GrahamScan._mPointList, count);
  3913. }
  3914. return rst;
  3915. }
  3916. static getFrom(rst, src, count) {
  3917. var i;
  3918. for (i = 0; i < count; i++) {
  3919. rst.push(src[i]);
  3920. }
  3921. return rst;
  3922. }
  3923. static getFromR(rst, src, count) {
  3924. var i;
  3925. for (i = 0; i < count; i++) {
  3926. rst.push(src.pop());
  3927. }
  3928. return rst;
  3929. }
  3930. static pListToPointList(pList, tempUse = false) {
  3931. var i, len = pList.length / 2, rst = GrahamScan._getPoints(len, tempUse, GrahamScan._tempPointList);
  3932. for (i = 0; i < len; i++) {
  3933. rst[i].setTo(pList[i + i], pList[i + i + 1]);
  3934. }
  3935. return rst;
  3936. }
  3937. static pointListToPlist(pointList) {
  3938. var i, len = pointList.length, rst = GrahamScan._temPList, tPoint;
  3939. rst.length = 0;
  3940. for (i = 0; i < len; i++) {
  3941. tPoint = pointList[i];
  3942. rst.push(tPoint.x, tPoint.y);
  3943. }
  3944. return rst;
  3945. }
  3946. static scanPList(pList) {
  3947. return Utils.copyArray(pList, GrahamScan.pointListToPlist(GrahamScan.scan(GrahamScan.pListToPointList(pList, true))));
  3948. }
  3949. static scan(PointSet) {
  3950. var i, j, k = 0, tmp, n = PointSet.length, ch;
  3951. var _tmpDic = {};
  3952. var key;
  3953. ch = GrahamScan._temArr;
  3954. ch.length = 0;
  3955. n = PointSet.length;
  3956. for (i = n - 1; i >= 0; i--) {
  3957. tmp = PointSet[i];
  3958. key = tmp.x + "_" + tmp.y;
  3959. if (!(key in _tmpDic)) {
  3960. _tmpDic[key] = true;
  3961. ch.push(tmp);
  3962. }
  3963. }
  3964. n = ch.length;
  3965. Utils.copyArray(PointSet, ch);
  3966. for (i = 1; i < n; i++)
  3967. if ((PointSet[i].y < PointSet[k].y) || ((PointSet[i].y == PointSet[k].y) && (PointSet[i].x < PointSet[k].x)))
  3968. k = i;
  3969. tmp = PointSet[0];
  3970. PointSet[0] = PointSet[k];
  3971. PointSet[k] = tmp;
  3972. for (i = 1; i < n - 1; i++) {
  3973. k = i;
  3974. for (j = i + 1; j < n; j++)
  3975. if ((GrahamScan.multiply(PointSet[j], PointSet[k], PointSet[0]) > 0) || ((GrahamScan.multiply(PointSet[j], PointSet[k], PointSet[0]) == 0) && (GrahamScan.dis(PointSet[0], PointSet[j]) < GrahamScan.dis(PointSet[0], PointSet[k]))))
  3976. k = j;
  3977. tmp = PointSet[i];
  3978. PointSet[i] = PointSet[k];
  3979. PointSet[k] = tmp;
  3980. }
  3981. ch = GrahamScan._temArr;
  3982. ch.length = 0;
  3983. if (PointSet.length < 3) {
  3984. return Utils.copyArray(ch, PointSet);
  3985. }
  3986. ch.push(PointSet[0], PointSet[1], PointSet[2]);
  3987. for (i = 3; i < n; i++) {
  3988. while (ch.length >= 2 && GrahamScan.multiply(PointSet[i], ch[ch.length - 1], ch[ch.length - 2]) >= 0)
  3989. ch.pop();
  3990. PointSet[i] && ch.push(PointSet[i]);
  3991. }
  3992. return ch;
  3993. }
  3994. }
  3995. GrahamScan._tempPointList = [];
  3996. GrahamScan._temPList = [];
  3997. GrahamScan._temArr = [];
  3998. class DrawStyle {
  3999. constructor(value) {
  4000. this.setValue(value);
  4001. }
  4002. static create(value) {
  4003. if (value) {
  4004. var color = (value instanceof ColorUtils) ? value : ColorUtils.create(value);
  4005. return color._drawStyle || (color._drawStyle = new DrawStyle(value));
  4006. }
  4007. return DrawStyle.DEFAULT;
  4008. }
  4009. setValue(value) {
  4010. if (value) {
  4011. this._color = (value instanceof ColorUtils) ? value : ColorUtils.create(value);
  4012. }
  4013. else
  4014. this._color = ColorUtils.create("#000000");
  4015. }
  4016. reset() {
  4017. this._color = ColorUtils.create("#000000");
  4018. }
  4019. toInt() {
  4020. return this._color.numColor;
  4021. }
  4022. equal(value) {
  4023. if (typeof (value) == 'string')
  4024. return this._color.strColor === value;
  4025. if (value instanceof ColorUtils)
  4026. return this._color.numColor === value.numColor;
  4027. return false;
  4028. }
  4029. toColorStr() {
  4030. return this._color.strColor;
  4031. }
  4032. }
  4033. DrawStyle.DEFAULT = new DrawStyle("#000000");
  4034. class Path {
  4035. constructor() {
  4036. this._lastOriX = 0;
  4037. this._lastOriY = 0;
  4038. this.paths = [];
  4039. this._curPath = null;
  4040. }
  4041. beginPath(convex) {
  4042. this.paths.length = 1;
  4043. this._curPath = this.paths[0] = new renderPath();
  4044. this._curPath.convex = convex;
  4045. }
  4046. closePath() {
  4047. this._curPath.loop = true;
  4048. }
  4049. newPath() {
  4050. this._curPath = new renderPath();
  4051. this.paths.push(this._curPath);
  4052. }
  4053. addPoint(pointX, pointY) {
  4054. this._curPath.path.push(pointX, pointY);
  4055. }
  4056. push(points, convex) {
  4057. if (!this._curPath) {
  4058. this._curPath = new renderPath();
  4059. this.paths.push(this._curPath);
  4060. }
  4061. else if (this._curPath.path.length > 0) {
  4062. this._curPath = new renderPath();
  4063. this.paths.push(this._curPath);
  4064. }
  4065. var rp = this._curPath;
  4066. rp.path = points.slice();
  4067. rp.convex = convex;
  4068. }
  4069. reset() {
  4070. this.paths.length = 0;
  4071. }
  4072. }
  4073. class renderPath {
  4074. constructor() {
  4075. this.path = [];
  4076. this.loop = false;
  4077. this.convex = false;
  4078. }
  4079. }
  4080. class SubmitBase {
  4081. constructor(renderType = SubmitBase.TYPE_2D) {
  4082. this.clipInfoID = -1;
  4083. this._mesh = null;
  4084. this._blendFn = null;
  4085. this._id = 0;
  4086. this._renderType = 0;
  4087. this._parent = null;
  4088. this._key = new SubmitKey();
  4089. this._startIdx = 0;
  4090. this._numEle = 0;
  4091. this._ref = 1;
  4092. this.shaderValue = null;
  4093. this._renderType = renderType;
  4094. this._id = ++SubmitBase.ID;
  4095. }
  4096. static __init__() {
  4097. var s = SubmitBase.RENDERBASE = new SubmitBase(-1);
  4098. s.shaderValue = new Value2D(0, 0);
  4099. s.shaderValue.ALPHA = 1;
  4100. s._ref = 0xFFFFFFFF;
  4101. }
  4102. getID() {
  4103. return this._id;
  4104. }
  4105. getRenderType() {
  4106. return this._renderType;
  4107. }
  4108. toString() {
  4109. return "ibindex:" + this._startIdx + " num:" + this._numEle + " key=" + this._key;
  4110. }
  4111. renderSubmit() { return 1; }
  4112. releaseRender() { }
  4113. }
  4114. SubmitBase.TYPE_2D = 10000;
  4115. SubmitBase.TYPE_CANVAS = 10003;
  4116. SubmitBase.TYPE_CMDSETRT = 10004;
  4117. SubmitBase.TYPE_CUSTOM = 10005;
  4118. SubmitBase.TYPE_BLURRT = 10006;
  4119. SubmitBase.TYPE_CMDDESTORYPRERT = 10007;
  4120. SubmitBase.TYPE_DISABLESTENCIL = 10008;
  4121. SubmitBase.TYPE_OTHERIBVB = 10009;
  4122. SubmitBase.TYPE_PRIMITIVE = 10010;
  4123. SubmitBase.TYPE_RT = 10011;
  4124. SubmitBase.TYPE_BLUR_RT = 10012;
  4125. SubmitBase.TYPE_TARGET = 10013;
  4126. SubmitBase.TYPE_CHANGE_VALUE = 10014;
  4127. SubmitBase.TYPE_SHAPE = 10015;
  4128. SubmitBase.TYPE_TEXTURE = 10016;
  4129. SubmitBase.TYPE_FILLTEXTURE = 10017;
  4130. SubmitBase.KEY_ONCE = -1;
  4131. SubmitBase.KEY_FILLRECT = 1;
  4132. SubmitBase.KEY_DRAWTEXTURE = 2;
  4133. SubmitBase.KEY_VG = 3;
  4134. SubmitBase.KEY_TRIANGLES = 4;
  4135. SubmitBase.ID = 1;
  4136. SubmitBase.preRender = null;
  4137. class SaveBase {
  4138. constructor() {
  4139. }
  4140. static _createArray() {
  4141. var value = [];
  4142. value._length = 0;
  4143. return value;
  4144. }
  4145. static _init() {
  4146. var namemap = SaveBase._namemap = {};
  4147. namemap[SaveBase.TYPE_ALPHA] = "ALPHA";
  4148. namemap[SaveBase.TYPE_FILESTYLE] = "fillStyle";
  4149. namemap[SaveBase.TYPE_FONT] = "font";
  4150. namemap[SaveBase.TYPE_LINEWIDTH] = "lineWidth";
  4151. namemap[SaveBase.TYPE_STROKESTYLE] = "strokeStyle";
  4152. namemap[SaveBase.TYPE_ENABLEMERGE] = "_mergeID";
  4153. namemap[SaveBase.TYPE_MARK] = namemap[SaveBase.TYPE_TRANSFORM] = namemap[SaveBase.TYPE_TRANSLATE] = [];
  4154. namemap[SaveBase.TYPE_TEXTBASELINE] = "textBaseline";
  4155. namemap[SaveBase.TYPE_TEXTALIGN] = "textAlign";
  4156. namemap[SaveBase.TYPE_GLOBALCOMPOSITEOPERATION] = "_nBlendType";
  4157. namemap[SaveBase.TYPE_SHADER] = "shader";
  4158. namemap[SaveBase.TYPE_FILTERS] = "filters";
  4159. namemap[SaveBase.TYPE_COLORFILTER] = '_colorFiler';
  4160. return namemap;
  4161. }
  4162. isSaveMark() { return false; }
  4163. restore(context) {
  4164. this._dataObj[this._valueName] = this._value;
  4165. SaveBase.POOL[SaveBase.POOL._length++] = this;
  4166. this._newSubmit && (context._curSubmit = SubmitBase.RENDERBASE);
  4167. }
  4168. static save(context, type, dataObj, newSubmit) {
  4169. if ((context._saveMark._saveuse & type) !== type) {
  4170. context._saveMark._saveuse |= type;
  4171. var cache = SaveBase.POOL;
  4172. var o = cache._length > 0 ? cache[--cache._length] : (new SaveBase());
  4173. o._value = dataObj[o._valueName = SaveBase._namemap[type]];
  4174. o._dataObj = dataObj;
  4175. o._newSubmit = newSubmit;
  4176. var _save = context._save;
  4177. _save[_save._length++] = o;
  4178. }
  4179. }
  4180. }
  4181. SaveBase.TYPE_ALPHA = 0x1;
  4182. SaveBase.TYPE_FILESTYLE = 0x2;
  4183. SaveBase.TYPE_FONT = 0x8;
  4184. SaveBase.TYPE_LINEWIDTH = 0x100;
  4185. SaveBase.TYPE_STROKESTYLE = 0x200;
  4186. SaveBase.TYPE_MARK = 0x400;
  4187. SaveBase.TYPE_TRANSFORM = 0x800;
  4188. SaveBase.TYPE_TRANSLATE = 0x1000;
  4189. SaveBase.TYPE_ENABLEMERGE = 0x2000;
  4190. SaveBase.TYPE_TEXTBASELINE = 0x4000;
  4191. SaveBase.TYPE_TEXTALIGN = 0x8000;
  4192. SaveBase.TYPE_GLOBALCOMPOSITEOPERATION = 0x10000;
  4193. SaveBase.TYPE_CLIPRECT = 0x20000;
  4194. SaveBase.TYPE_CLIPRECT_STENCIL = 0x40000;
  4195. SaveBase.TYPE_IBVB = 0x80000;
  4196. SaveBase.TYPE_SHADER = 0x100000;
  4197. SaveBase.TYPE_FILTERS = 0x200000;
  4198. SaveBase.TYPE_FILTERS_TYPE = 0x400000;
  4199. SaveBase.TYPE_COLORFILTER = 0x800000;
  4200. SaveBase.POOL = SaveBase._createArray();
  4201. SaveBase._namemap = SaveBase._init();
  4202. class SaveClipRect {
  4203. constructor() {
  4204. this._globalClipMatrix = new Matrix();
  4205. this._clipInfoID = -1;
  4206. this._clipRect = new Rectangle();
  4207. this.incache = false;
  4208. }
  4209. isSaveMark() { return false; }
  4210. restore(context) {
  4211. this._globalClipMatrix.copyTo(context._globalClipMatrix);
  4212. this._clipRect.clone(context._clipRect);
  4213. context._clipInfoID = this._clipInfoID;
  4214. SaveClipRect.POOL[SaveClipRect.POOL._length++] = this;
  4215. context._clipInCache = this.incache;
  4216. }
  4217. static save(context) {
  4218. if ((context._saveMark._saveuse & SaveBase.TYPE_CLIPRECT) == SaveBase.TYPE_CLIPRECT)
  4219. return;
  4220. context._saveMark._saveuse |= SaveBase.TYPE_CLIPRECT;
  4221. var cache = SaveClipRect.POOL;
  4222. var o = cache._length > 0 ? cache[--cache._length] : (new SaveClipRect());
  4223. context._globalClipMatrix.copyTo(o._globalClipMatrix);
  4224. context._clipRect.clone(o._clipRect);
  4225. o._clipInfoID = context._clipInfoID;
  4226. o.incache = context._clipInCache;
  4227. var _save = context._save;
  4228. _save[_save._length++] = o;
  4229. }
  4230. }
  4231. SaveClipRect.POOL = SaveBase._createArray();
  4232. class SaveMark {
  4233. constructor() {
  4234. this._saveuse = 0;
  4235. }
  4236. isSaveMark() {
  4237. return true;
  4238. }
  4239. restore(context) {
  4240. context._saveMark = this._preSaveMark;
  4241. SaveMark.POOL[SaveMark.POOL._length++] = this;
  4242. }
  4243. static Create(context) {
  4244. var no = SaveMark.POOL;
  4245. var o = no._length > 0 ? no[--no._length] : (new SaveMark());
  4246. o._saveuse = 0;
  4247. o._preSaveMark = context._saveMark;
  4248. context._saveMark = o;
  4249. return o;
  4250. }
  4251. }
  4252. SaveMark.POOL = SaveBase._createArray();
  4253. class SaveTransform {
  4254. constructor() {
  4255. this._matrix = new Matrix();
  4256. }
  4257. isSaveMark() { return false; }
  4258. restore(context) {
  4259. context._curMat = this._savematrix;
  4260. SaveTransform.POOL[SaveTransform.POOL._length++] = this;
  4261. }
  4262. static save(context) {
  4263. var _saveMark = context._saveMark;
  4264. if ((_saveMark._saveuse & SaveBase.TYPE_TRANSFORM) === SaveBase.TYPE_TRANSFORM)
  4265. return;
  4266. _saveMark._saveuse |= SaveBase.TYPE_TRANSFORM;
  4267. var no = SaveTransform.POOL;
  4268. var o = no._length > 0 ? no[--no._length] : (new SaveTransform());
  4269. o._savematrix = context._curMat;
  4270. context._curMat = context._curMat.copyTo(o._matrix);
  4271. var _save = context._save;
  4272. _save[_save._length++] = o;
  4273. }
  4274. }
  4275. SaveTransform.POOL = SaveBase._createArray();
  4276. class SaveTranslate {
  4277. constructor() {
  4278. this._mat = new Matrix();
  4279. }
  4280. isSaveMark() { return false; }
  4281. restore(context) {
  4282. this._mat.copyTo(context._curMat);
  4283. SaveTranslate.POOL[SaveTranslate.POOL._length++] = this;
  4284. }
  4285. static save(context) {
  4286. var no = SaveTranslate.POOL;
  4287. var o = no._length > 0 ? no[--no._length] : (new SaveTranslate());
  4288. context._curMat.copyTo(o._mat);
  4289. var _save = context._save;
  4290. _save[_save._length++] = o;
  4291. }
  4292. }
  4293. SaveTranslate.POOL = SaveBase._createArray();
  4294. class BufferStateBase {
  4295. constructor() {
  4296. this._nativeVertexArrayObject = LayaGL.layaGPUInstance.createVertexArray();
  4297. }
  4298. bind() {
  4299. if (BufferStateBase._curBindedBufferState !== this) {
  4300. LayaGL.layaGPUInstance.bindVertexArray(this._nativeVertexArrayObject);
  4301. BufferStateBase._curBindedBufferState = this;
  4302. }
  4303. }
  4304. unBind() {
  4305. if (BufferStateBase._curBindedBufferState === this) {
  4306. LayaGL.layaGPUInstance.bindVertexArray(null);
  4307. BufferStateBase._curBindedBufferState = null;
  4308. }
  4309. else {
  4310. throw "BufferState: must call bind() function first.";
  4311. }
  4312. }
  4313. destroy() {
  4314. LayaGL.layaGPUInstance.deleteVertexArray(this._nativeVertexArrayObject);
  4315. }
  4316. bindForNative() {
  4317. LayaGL.instance.bindVertexArray(this._nativeVertexArrayObject);
  4318. BufferStateBase._curBindedBufferState = this;
  4319. }
  4320. unBindForNative() {
  4321. LayaGL.instance.bindVertexArray(null);
  4322. BufferStateBase._curBindedBufferState = null;
  4323. }
  4324. }
  4325. class BufferState2D extends BufferStateBase {
  4326. constructor() {
  4327. super();
  4328. }
  4329. }
  4330. class Buffer {
  4331. constructor() {
  4332. this._byteLength = 0;
  4333. this._glBuffer = LayaGL.instance.createBuffer();
  4334. }
  4335. get bufferUsage() {
  4336. return this._bufferUsage;
  4337. }
  4338. _bindForVAO() {
  4339. }
  4340. bind() {
  4341. return false;
  4342. }
  4343. destroy() {
  4344. if (this._glBuffer) {
  4345. LayaGL.instance.deleteBuffer(this._glBuffer);
  4346. this._glBuffer = null;
  4347. }
  4348. }
  4349. }
  4350. class RenderInfo {
  4351. }
  4352. RenderInfo.loopStTm = 0;
  4353. RenderInfo.loopCount = 0;
  4354. class Buffer2D extends Buffer {
  4355. constructor() {
  4356. super();
  4357. this._maxsize = 0;
  4358. this._upload = true;
  4359. this._uploadSize = 0;
  4360. this._bufferSize = 0;
  4361. this._u8Array = null;
  4362. }
  4363. static __int__(gl) {
  4364. }
  4365. get bufferLength() {
  4366. return this._buffer.byteLength;
  4367. }
  4368. set byteLength(value) {
  4369. this.setByteLength(value);
  4370. }
  4371. setByteLength(value) {
  4372. if (this._byteLength !== value) {
  4373. value <= this._bufferSize || (this._resizeBuffer(value * 2 + 256, true));
  4374. this._byteLength = value;
  4375. }
  4376. }
  4377. needSize(sz) {
  4378. var old = this._byteLength;
  4379. if (sz) {
  4380. var needsz = this._byteLength + sz;
  4381. needsz <= this._bufferSize || (this._resizeBuffer(needsz << 1, true));
  4382. this._byteLength = needsz;
  4383. }
  4384. return old;
  4385. }
  4386. _bufferData() {
  4387. this._maxsize = Math.max(this._maxsize, this._byteLength);
  4388. if (RenderInfo.loopCount % 30 == 0) {
  4389. if (this._buffer.byteLength > (this._maxsize + 64)) {
  4390. this._buffer = this._buffer.slice(0, this._maxsize + 64);
  4391. this._bufferSize = this._buffer.byteLength;
  4392. this._checkArrayUse();
  4393. }
  4394. this._maxsize = this._byteLength;
  4395. }
  4396. if (this._uploadSize < this._buffer.byteLength) {
  4397. this._uploadSize = this._buffer.byteLength;
  4398. LayaGL.instance.bufferData(this._bufferType, this._uploadSize, this._bufferUsage);
  4399. }
  4400. LayaGL.instance.bufferSubData(this._bufferType, 0, new Uint8Array(this._buffer, 0, this._byteLength));
  4401. }
  4402. _bufferSubData(offset = 0, dataStart = 0, dataLength = 0) {
  4403. this._maxsize = Math.max(this._maxsize, this._byteLength);
  4404. if (RenderInfo.loopCount % 30 == 0) {
  4405. if (this._buffer.byteLength > (this._maxsize + 64)) {
  4406. this._buffer = this._buffer.slice(0, this._maxsize + 64);
  4407. this._bufferSize = this._buffer.byteLength;
  4408. this._checkArrayUse();
  4409. }
  4410. this._maxsize = this._byteLength;
  4411. }
  4412. if (this._uploadSize < this._buffer.byteLength) {
  4413. this._uploadSize = this._buffer.byteLength;
  4414. LayaGL.instance.bufferData(this._bufferType, this._uploadSize, this._bufferUsage);
  4415. }
  4416. if (dataStart || dataLength) {
  4417. var subBuffer = this._buffer.slice(dataStart, dataLength);
  4418. LayaGL.instance.bufferSubData(this._bufferType, offset, subBuffer);
  4419. }
  4420. else {
  4421. LayaGL.instance.bufferSubData(this._bufferType, offset, this._buffer);
  4422. }
  4423. }
  4424. _checkArrayUse() {
  4425. }
  4426. _bind_uploadForVAO() {
  4427. if (!this._upload)
  4428. return false;
  4429. this._upload = false;
  4430. this._bindForVAO();
  4431. this._bufferData();
  4432. return true;
  4433. }
  4434. _bind_upload() {
  4435. if (!this._upload)
  4436. return false;
  4437. this._upload = false;
  4438. this.bind();
  4439. this._bufferData();
  4440. return true;
  4441. }
  4442. _bind_subUpload(offset = 0, dataStart = 0, dataLength = 0) {
  4443. if (!this._upload)
  4444. return false;
  4445. this._upload = false;
  4446. this.bind();
  4447. this._bufferSubData(offset, dataStart, dataLength);
  4448. return true;
  4449. }
  4450. _resizeBuffer(nsz, copy) {
  4451. var buff = this._buffer;
  4452. if (nsz <= buff.byteLength)
  4453. return this;
  4454. var u8buf = this._u8Array;
  4455. if (copy && buff && buff.byteLength > 0) {
  4456. var newbuffer = new ArrayBuffer(nsz);
  4457. var oldU8Arr = (u8buf && u8buf.buffer == buff) ? u8buf : new Uint8Array(buff);
  4458. u8buf = this._u8Array = new Uint8Array(newbuffer);
  4459. u8buf.set(oldU8Arr, 0);
  4460. buff = this._buffer = newbuffer;
  4461. }
  4462. else {
  4463. buff = this._buffer = new ArrayBuffer(nsz);
  4464. this._u8Array = null;
  4465. }
  4466. this._checkArrayUse();
  4467. this._upload = true;
  4468. this._bufferSize = buff.byteLength;
  4469. return this;
  4470. }
  4471. append(data) {
  4472. this._upload = true;
  4473. var byteLen, n;
  4474. byteLen = data.byteLength;
  4475. if (data instanceof Uint8Array) {
  4476. this._resizeBuffer(this._byteLength + byteLen, true);
  4477. n = new Uint8Array(this._buffer, this._byteLength);
  4478. }
  4479. else if (data instanceof Uint16Array) {
  4480. this._resizeBuffer(this._byteLength + byteLen, true);
  4481. n = new Uint16Array(this._buffer, this._byteLength);
  4482. }
  4483. else if (data instanceof Float32Array) {
  4484. this._resizeBuffer(this._byteLength + byteLen, true);
  4485. n = new Float32Array(this._buffer, this._byteLength);
  4486. }
  4487. n.set(data, 0);
  4488. this._byteLength += byteLen;
  4489. this._checkArrayUse();
  4490. }
  4491. appendU16Array(data, len) {
  4492. this._resizeBuffer(this._byteLength + len * 2, true);
  4493. var u = new Uint16Array(this._buffer, this._byteLength, len);
  4494. if (len == 6) {
  4495. u[0] = data[0];
  4496. u[1] = data[1];
  4497. u[2] = data[2];
  4498. u[3] = data[3];
  4499. u[4] = data[4];
  4500. u[5] = data[5];
  4501. }
  4502. else if (len >= 100) {
  4503. u.set(new Uint16Array(data.buffer, 0, len));
  4504. }
  4505. else {
  4506. for (var i = 0; i < len; i++) {
  4507. u[i] = data[i];
  4508. }
  4509. }
  4510. this._byteLength += len * 2;
  4511. this._checkArrayUse();
  4512. }
  4513. appendEx(data, type) {
  4514. this._upload = true;
  4515. var byteLen, n;
  4516. byteLen = data.byteLength;
  4517. this._resizeBuffer(this._byteLength + byteLen, true);
  4518. n = new type(this._buffer, this._byteLength);
  4519. n.set(data, 0);
  4520. this._byteLength += byteLen;
  4521. this._checkArrayUse();
  4522. }
  4523. appendEx2(data, type, dataLen, perDataLen = 1) {
  4524. this._upload = true;
  4525. var byteLen, n;
  4526. byteLen = dataLen * perDataLen;
  4527. this._resizeBuffer(this._byteLength + byteLen, true);
  4528. n = new type(this._buffer, this._byteLength);
  4529. var i;
  4530. for (i = 0; i < dataLen; i++) {
  4531. n[i] = data[i];
  4532. }
  4533. this._byteLength += byteLen;
  4534. this._checkArrayUse();
  4535. }
  4536. getBuffer() {
  4537. return this._buffer;
  4538. }
  4539. setNeedUpload() {
  4540. this._upload = true;
  4541. }
  4542. getNeedUpload() {
  4543. return this._upload;
  4544. }
  4545. upload() {
  4546. var gl = LayaGL.instance;
  4547. var scuess = this._bind_upload();
  4548. gl.bindBuffer(this._bufferType, null);
  4549. if (this._bufferType == gl.ARRAY_BUFFER)
  4550. Buffer._bindedVertexBuffer = null;
  4551. if (this._bufferType == gl.ELEMENT_ARRAY_BUFFER)
  4552. Buffer._bindedIndexBuffer = null;
  4553. BaseShader.activeShader = null;
  4554. return scuess;
  4555. }
  4556. subUpload(offset = 0, dataStart = 0, dataLength = 0) {
  4557. var gl = LayaGL.instance;
  4558. var scuess = this._bind_subUpload();
  4559. gl.bindBuffer(this._bufferType, null);
  4560. if (this._bufferType == gl.ARRAY_BUFFER)
  4561. Buffer._bindedVertexBuffer = null;
  4562. if (this._bufferType == gl.ELEMENT_ARRAY_BUFFER)
  4563. Buffer._bindedIndexBuffer = null;
  4564. BaseShader.activeShader = null;
  4565. return scuess;
  4566. }
  4567. _disposeResource() {
  4568. this._upload = true;
  4569. this._uploadSize = 0;
  4570. }
  4571. clear() {
  4572. this._byteLength = 0;
  4573. this._upload = true;
  4574. }
  4575. }
  4576. Buffer2D.FLOAT32 = 4;
  4577. Buffer2D.SHORT = 2;
  4578. class IndexBuffer2D extends Buffer2D {
  4579. constructor(bufferUsage = 0x88e4) {
  4580. super();
  4581. this._bufferUsage = bufferUsage;
  4582. this._bufferType = LayaGL.instance.ELEMENT_ARRAY_BUFFER;
  4583. this._buffer = new ArrayBuffer(8);
  4584. }
  4585. _checkArrayUse() {
  4586. this._uint16Array && (this._uint16Array = new Uint16Array(this._buffer));
  4587. }
  4588. getUint16Array() {
  4589. return this._uint16Array || (this._uint16Array = new Uint16Array(this._buffer));
  4590. }
  4591. _bindForVAO() {
  4592. var gl = LayaGL.instance;
  4593. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._glBuffer);
  4594. }
  4595. bind() {
  4596. if (Buffer._bindedIndexBuffer !== this._glBuffer) {
  4597. var gl = LayaGL.instance;
  4598. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._glBuffer);
  4599. Buffer._bindedIndexBuffer = this._glBuffer;
  4600. return true;
  4601. }
  4602. return false;
  4603. }
  4604. destory() {
  4605. this._uint16Array = null;
  4606. this._buffer = null;
  4607. }
  4608. disposeResource() {
  4609. this._disposeResource();
  4610. }
  4611. }
  4612. IndexBuffer2D.create = function (bufferUsage = 0x88e4) {
  4613. return new IndexBuffer2D(bufferUsage);
  4614. };
  4615. class VertexBuffer2D extends Buffer2D {
  4616. constructor(vertexStride, bufferUsage) {
  4617. super();
  4618. this._vertexStride = vertexStride;
  4619. this._bufferUsage = bufferUsage;
  4620. this._bufferType = LayaGL.instance.ARRAY_BUFFER;
  4621. this._buffer = new ArrayBuffer(8);
  4622. this._floatArray32 = new Float32Array(this._buffer);
  4623. this._uint32Array = new Uint32Array(this._buffer);
  4624. }
  4625. get vertexStride() {
  4626. return this._vertexStride;
  4627. }
  4628. getFloat32Array() {
  4629. return this._floatArray32;
  4630. }
  4631. appendArray(data) {
  4632. var oldoff = this._byteLength >> 2;
  4633. this.setByteLength(this._byteLength + data.length * 4);
  4634. var vbdata = this.getFloat32Array();
  4635. vbdata.set(data, oldoff);
  4636. this._upload = true;
  4637. }
  4638. _checkArrayUse() {
  4639. this._floatArray32 && (this._floatArray32 = new Float32Array(this._buffer));
  4640. this._uint32Array && (this._uint32Array = new Uint32Array(this._buffer));
  4641. }
  4642. deleteBuffer() {
  4643. super._disposeResource();
  4644. }
  4645. _bindForVAO() {
  4646. var gl = LayaGL.instance;
  4647. gl.bindBuffer(gl.ARRAY_BUFFER, this._glBuffer);
  4648. }
  4649. bind() {
  4650. if (Buffer._bindedVertexBuffer !== this._glBuffer) {
  4651. var gl = LayaGL.instance;
  4652. gl.bindBuffer(gl.ARRAY_BUFFER, this._glBuffer);
  4653. Buffer._bindedVertexBuffer = this._glBuffer;
  4654. return true;
  4655. }
  4656. return false;
  4657. }
  4658. destroy() {
  4659. super.destroy();
  4660. this._byteLength = 0;
  4661. this._upload = true;
  4662. this._buffer = null;
  4663. this._floatArray32 = null;
  4664. }
  4665. }
  4666. VertexBuffer2D.create = function (vertexStride, bufferUsage = 0x88e8) {
  4667. return new VertexBuffer2D(vertexStride, bufferUsage);
  4668. };
  4669. class Mesh2D {
  4670. constructor(stride, vballoc, iballoc) {
  4671. this._stride = 0;
  4672. this.vertNum = 0;
  4673. this.indexNum = 0;
  4674. this._applied = false;
  4675. this._quadNum = 0;
  4676. this.canReuse = false;
  4677. this._stride = stride;
  4678. this._vb = new VertexBuffer2D(stride, LayaGL.instance.DYNAMIC_DRAW);
  4679. if (vballoc) {
  4680. this._vb._resizeBuffer(vballoc, false);
  4681. }
  4682. else {
  4683. Config.webGL2D_MeshAllocMaxMem && this._vb._resizeBuffer(64 * 1024 * stride, false);
  4684. }
  4685. this._ib = new IndexBuffer2D();
  4686. if (iballoc) {
  4687. this._ib._resizeBuffer(iballoc, false);
  4688. }
  4689. }
  4690. cloneWithNewVB() {
  4691. var mesh = new Mesh2D(this._stride, 0, 0);
  4692. mesh._ib = this._ib;
  4693. mesh._quadNum = this._quadNum;
  4694. mesh._attribInfo = this._attribInfo;
  4695. return mesh;
  4696. }
  4697. cloneWithNewVBIB() {
  4698. var mesh = new Mesh2D(this._stride, 0, 0);
  4699. mesh._attribInfo = this._attribInfo;
  4700. return mesh;
  4701. }
  4702. getVBW() {
  4703. this._vb.setNeedUpload();
  4704. return this._vb;
  4705. }
  4706. getVBR() {
  4707. return this._vb;
  4708. }
  4709. getIBR() {
  4710. return this._ib;
  4711. }
  4712. getIBW() {
  4713. this._ib.setNeedUpload();
  4714. return this._ib;
  4715. }
  4716. createQuadIB(QuadNum) {
  4717. this._quadNum = QuadNum;
  4718. this._ib._resizeBuffer(QuadNum * 6 * 2, false);
  4719. this._ib.byteLength = this._ib.bufferLength;
  4720. var bd = this._ib.getUint16Array();
  4721. var idx = 0;
  4722. var curvert = 0;
  4723. for (var i = 0; i < QuadNum; i++) {
  4724. bd[idx++] = curvert;
  4725. bd[idx++] = curvert + 2;
  4726. bd[idx++] = curvert + 1;
  4727. bd[idx++] = curvert;
  4728. bd[idx++] = curvert + 3;
  4729. bd[idx++] = curvert + 2;
  4730. curvert += 4;
  4731. }
  4732. this._ib.setNeedUpload();
  4733. }
  4734. setAttributes(attribs) {
  4735. this._attribInfo = attribs;
  4736. if (this._attribInfo.length % 3 != 0) {
  4737. throw 'Mesh2D setAttributes error!';
  4738. }
  4739. }
  4740. configVAO(gl) {
  4741. if (this._applied)
  4742. return;
  4743. this._applied = true;
  4744. if (!this._vao) {
  4745. this._vao = new BufferState2D();
  4746. }
  4747. this._vao.bind();
  4748. this._vb._bindForVAO();
  4749. this._ib.setNeedUpload();
  4750. this._ib._bind_uploadForVAO();
  4751. var attribNum = this._attribInfo.length / 3;
  4752. var idx = 0;
  4753. for (var i = 0; i < attribNum; i++) {
  4754. var _size = this._attribInfo[idx + 1];
  4755. var _type = this._attribInfo[idx];
  4756. var _off = this._attribInfo[idx + 2];
  4757. gl.enableVertexAttribArray(i);
  4758. gl.vertexAttribPointer(i, _size, _type, false, this._stride, _off);
  4759. idx += 3;
  4760. }
  4761. this._vao.unBind();
  4762. }
  4763. useMesh(gl) {
  4764. this._applied || this.configVAO(gl);
  4765. this._vao.bind();
  4766. this._vb.bind();
  4767. this._ib._bind_upload() || this._ib.bind();
  4768. this._vb._bind_upload() || this._vb.bind();
  4769. }
  4770. getEleNum() {
  4771. return this._ib.getBuffer().byteLength / 2;
  4772. }
  4773. releaseMesh() { }
  4774. destroy() {
  4775. }
  4776. clearVB() {
  4777. this._vb.clear();
  4778. }
  4779. }
  4780. Mesh2D._gvaoid = 0;
  4781. class MeshQuadTexture extends Mesh2D {
  4782. constructor() {
  4783. super(MeshQuadTexture.const_stride, 4, 4);
  4784. this.canReuse = true;
  4785. this.setAttributes(MeshQuadTexture._fixattriInfo);
  4786. if (!MeshQuadTexture._fixib) {
  4787. this.createQuadIB(MeshQuadTexture._maxIB);
  4788. MeshQuadTexture._fixib = this._ib;
  4789. }
  4790. else {
  4791. this._ib = MeshQuadTexture._fixib;
  4792. this._quadNum = MeshQuadTexture._maxIB;
  4793. }
  4794. }
  4795. static __int__() {
  4796. MeshQuadTexture._fixattriInfo = [5126, 4, 0,
  4797. 5121, 4, 16,
  4798. 5121, 4, 20];
  4799. }
  4800. static getAMesh(mainctx) {
  4801. var ret = null;
  4802. if (MeshQuadTexture._POOL.length) {
  4803. ret = MeshQuadTexture._POOL.pop();
  4804. }
  4805. else
  4806. ret = new MeshQuadTexture();
  4807. mainctx && ret._vb._resizeBuffer(64 * 1024 * MeshQuadTexture.const_stride, false);
  4808. return ret;
  4809. }
  4810. releaseMesh() {
  4811. this._vb.setByteLength(0);
  4812. this.vertNum = 0;
  4813. this.indexNum = 0;
  4814. MeshQuadTexture._POOL.push(this);
  4815. }
  4816. destroy() {
  4817. this._vb.destroy();
  4818. this._vb.deleteBuffer();
  4819. }
  4820. addQuad(pos, uv, color, useTex) {
  4821. var vb = this._vb;
  4822. var vpos = (vb._byteLength >> 2);
  4823. vb.setByteLength((vpos + MeshQuadTexture.const_stride) << 2);
  4824. var vbdata = vb._floatArray32 || vb.getFloat32Array();
  4825. var vbu32Arr = vb._uint32Array;
  4826. var cpos = vpos;
  4827. var useTexVal = useTex ? 0xff : 0;
  4828. vbdata[cpos++] = pos[0];
  4829. vbdata[cpos++] = pos[1];
  4830. vbdata[cpos++] = uv[0];
  4831. vbdata[cpos++] = uv[1];
  4832. vbu32Arr[cpos++] = color;
  4833. vbu32Arr[cpos++] = useTexVal;
  4834. vbdata[cpos++] = pos[2];
  4835. vbdata[cpos++] = pos[3];
  4836. vbdata[cpos++] = uv[2];
  4837. vbdata[cpos++] = uv[3];
  4838. vbu32Arr[cpos++] = color;
  4839. vbu32Arr[cpos++] = useTexVal;
  4840. vbdata[cpos++] = pos[4];
  4841. vbdata[cpos++] = pos[5];
  4842. vbdata[cpos++] = uv[4];
  4843. vbdata[cpos++] = uv[5];
  4844. vbu32Arr[cpos++] = color;
  4845. vbu32Arr[cpos++] = useTexVal;
  4846. vbdata[cpos++] = pos[6];
  4847. vbdata[cpos++] = pos[7];
  4848. vbdata[cpos++] = uv[6];
  4849. vbdata[cpos++] = uv[7];
  4850. vbu32Arr[cpos++] = color;
  4851. vbu32Arr[cpos++] = useTexVal;
  4852. vb._upload = true;
  4853. }
  4854. }
  4855. MeshQuadTexture.const_stride = 24;
  4856. MeshQuadTexture._maxIB = 16 * 1024;
  4857. MeshQuadTexture._POOL = [];
  4858. class MeshTexture extends Mesh2D {
  4859. constructor() {
  4860. super(MeshTexture.const_stride, 4, 4);
  4861. this.canReuse = true;
  4862. this.setAttributes(MeshTexture._fixattriInfo);
  4863. }
  4864. static __init__() {
  4865. MeshTexture._fixattriInfo = [5126, 4, 0,
  4866. 5121, 4, 16,
  4867. 5121, 4, 20];
  4868. }
  4869. static getAMesh(mainctx) {
  4870. var ret;
  4871. if (MeshTexture._POOL.length) {
  4872. ret = MeshTexture._POOL.pop();
  4873. }
  4874. else
  4875. ret = new MeshTexture();
  4876. mainctx && ret._vb._resizeBuffer(64 * 1024 * MeshTexture.const_stride, false);
  4877. return ret;
  4878. }
  4879. addData(vertices, uvs, idx, matrix, rgba) {
  4880. var vb = this._vb;
  4881. var ib = this._ib;
  4882. var vertsz = vertices.length >> 1;
  4883. var startpos = vb.needSize(vertsz * MeshTexture.const_stride);
  4884. var f32pos = startpos >> 2;
  4885. var vbdata = vb._floatArray32 || vb.getFloat32Array();
  4886. var vbu32Arr = vb._uint32Array;
  4887. var ci = 0;
  4888. var m00 = matrix.a;
  4889. var m01 = matrix.b;
  4890. var m10 = matrix.c;
  4891. var m11 = matrix.d;
  4892. var tx = matrix.tx;
  4893. var ty = matrix.ty;
  4894. var i = 0;
  4895. for (i = 0; i < vertsz; i++) {
  4896. var x = vertices[ci], y = vertices[ci + 1];
  4897. vbdata[f32pos] = x * m00 + y * m10 + tx;
  4898. vbdata[f32pos + 1] = x * m01 + y * m11 + ty;
  4899. vbdata[f32pos + 2] = uvs[ci];
  4900. vbdata[f32pos + 3] = uvs[ci + 1];
  4901. vbu32Arr[f32pos + 4] = rgba;
  4902. vbu32Arr[f32pos + 5] = 0xff;
  4903. f32pos += 6;
  4904. ci += 2;
  4905. }
  4906. vb.setNeedUpload();
  4907. var vertN = this.vertNum;
  4908. var sz = idx.length;
  4909. var stib = ib.needSize(idx.byteLength);
  4910. var cidx = ib.getUint16Array();
  4911. var stibid = stib >> 1;
  4912. if (vertN > 0) {
  4913. var end = stibid + sz;
  4914. var si = 0;
  4915. for (i = stibid; i < end; i++, si++) {
  4916. cidx[i] = idx[si] + vertN;
  4917. }
  4918. }
  4919. else {
  4920. cidx.set(idx, stibid);
  4921. }
  4922. ib.setNeedUpload();
  4923. this.vertNum += vertsz;
  4924. this.indexNum += idx.length;
  4925. }
  4926. releaseMesh() {
  4927. this._vb.setByteLength(0);
  4928. this._ib.setByteLength(0);
  4929. this.vertNum = 0;
  4930. this.indexNum = 0;
  4931. MeshTexture._POOL.push(this);
  4932. }
  4933. destroy() {
  4934. this._ib.destroy();
  4935. this._vb.destroy();
  4936. this._ib.disposeResource();
  4937. this._vb.deleteBuffer();
  4938. }
  4939. }
  4940. MeshTexture.const_stride = 24;
  4941. MeshTexture._POOL = [];
  4942. class MeshVG extends Mesh2D {
  4943. constructor() {
  4944. super(MeshVG.const_stride, 4, 4);
  4945. this.canReuse = true;
  4946. this.setAttributes(MeshVG._fixattriInfo);
  4947. }
  4948. static __init__() {
  4949. MeshVG._fixattriInfo = [5126, 2, 0,
  4950. 5121, 4, 8];
  4951. }
  4952. static getAMesh(mainctx) {
  4953. var ret;
  4954. if (MeshVG._POOL.length) {
  4955. ret = MeshVG._POOL.pop();
  4956. }
  4957. else
  4958. ret = new MeshVG();
  4959. mainctx && ret._vb._resizeBuffer(64 * 1024 * MeshVG.const_stride, false);
  4960. return ret;
  4961. }
  4962. addVertAndIBToMesh(ctx, points, rgba, ib) {
  4963. var startpos = this._vb.needSize(points.length / 2 * MeshVG.const_stride);
  4964. var f32pos = startpos >> 2;
  4965. var vbdata = this._vb._floatArray32 || this._vb.getFloat32Array();
  4966. var vbu32Arr = this._vb._uint32Array;
  4967. var ci = 0;
  4968. var sz = points.length / 2;
  4969. for (var i = 0; i < sz; i++) {
  4970. vbdata[f32pos++] = points[ci];
  4971. vbdata[f32pos++] = points[ci + 1];
  4972. ci += 2;
  4973. vbu32Arr[f32pos++] = rgba;
  4974. }
  4975. this._vb.setNeedUpload();
  4976. this._ib.append(new Uint16Array(ib));
  4977. this._ib.setNeedUpload();
  4978. this.vertNum += sz;
  4979. this.indexNum += ib.length;
  4980. }
  4981. releaseMesh() {
  4982. this._vb.setByteLength(0);
  4983. this._ib.setByteLength(0);
  4984. this.vertNum = 0;
  4985. this.indexNum = 0;
  4986. MeshVG._POOL.push(this);
  4987. }
  4988. destroy() {
  4989. this._ib.destroy();
  4990. this._vb.destroy();
  4991. this._ib.disposeResource();
  4992. this._vb.deleteBuffer();
  4993. }
  4994. }
  4995. MeshVG.const_stride = 12;
  4996. MeshVG._POOL = [];
  4997. class WebGLCacheAsNormalCanvas {
  4998. constructor(ctx, sp) {
  4999. this.submitStartPos = 0;
  5000. this.submitEndPos = 0;
  5001. this.context = null;
  5002. this.touches = [];
  5003. this.submits = [];
  5004. this.sprite = null;
  5005. this.meshlist = [];
  5006. this.cachedClipInfo = new Matrix();
  5007. this.oldTx = 0;
  5008. this.oldTy = 0;
  5009. this.invMat = new Matrix();
  5010. this.context = ctx;
  5011. this.sprite = sp;
  5012. ctx._globalClipMatrix.copyTo(this.cachedClipInfo);
  5013. }
  5014. startRec() {
  5015. if (this.context._charSubmitCache._enbale) {
  5016. this.context._charSubmitCache.enable(false, this.context);
  5017. this.context._charSubmitCache.enable(true, this.context);
  5018. }
  5019. this.context._incache = true;
  5020. this.touches.length = 0;
  5021. this.context.touches = this.touches;
  5022. this.context._globalClipMatrix.copyTo(this.cachedClipInfo);
  5023. this.submits.length = 0;
  5024. this.submitStartPos = this.context._submits._length;
  5025. for (var i = 0, sz = this.meshlist.length; i < sz; i++) {
  5026. var curm = this.meshlist[i];
  5027. curm.canReuse ? (curm.releaseMesh()) : (curm.destroy());
  5028. }
  5029. this.meshlist.length = 0;
  5030. this._mesh = MeshQuadTexture.getAMesh(false);
  5031. this._pathMesh = MeshVG.getAMesh(false);
  5032. this._triangleMesh = MeshTexture.getAMesh(false);
  5033. this.meshlist.push(this._mesh);
  5034. this.meshlist.push(this._pathMesh);
  5035. this.meshlist.push(this._triangleMesh);
  5036. this.context._curSubmit = SubmitBase.RENDERBASE;
  5037. this._oldMesh = this.context._mesh;
  5038. this._oldPathMesh = this.context._pathMesh;
  5039. this._oldTriMesh = this.context._triangleMesh;
  5040. this._oldMeshList = this.context.meshlist;
  5041. this.context._mesh = this._mesh;
  5042. this.context._pathMesh = this._pathMesh;
  5043. this.context._triangleMesh = this._triangleMesh;
  5044. this.context.meshlist = this.meshlist;
  5045. this.oldTx = this.context._curMat.tx;
  5046. this.oldTy = this.context._curMat.ty;
  5047. this.context._curMat.tx = 0;
  5048. this.context._curMat.ty = 0;
  5049. this.context._curMat.copyTo(this.invMat);
  5050. this.invMat.invert();
  5051. }
  5052. endRec() {
  5053. if (this.context._charSubmitCache._enbale) {
  5054. this.context._charSubmitCache.enable(false, this.context);
  5055. this.context._charSubmitCache.enable(true, this.context);
  5056. }
  5057. var parsubmits = this.context._submits;
  5058. this.submitEndPos = parsubmits._length;
  5059. var num = this.submitEndPos - this.submitStartPos;
  5060. for (var i = 0; i < num; i++) {
  5061. this.submits.push(parsubmits[this.submitStartPos + i]);
  5062. }
  5063. parsubmits._length -= num;
  5064. this.context._mesh = this._oldMesh;
  5065. this.context._pathMesh = this._oldPathMesh;
  5066. this.context._triangleMesh = this._oldTriMesh;
  5067. this.context.meshlist = this._oldMeshList;
  5068. this.context._curSubmit = SubmitBase.RENDERBASE;
  5069. this.context._curMat.tx = this.oldTx;
  5070. this.context._curMat.ty = this.oldTy;
  5071. this.context.touches = null;
  5072. this.context._incache = false;
  5073. }
  5074. isCacheValid() {
  5075. var curclip = this.context._globalClipMatrix;
  5076. if (curclip.a != this.cachedClipInfo.a || curclip.b != this.cachedClipInfo.b || curclip.c != this.cachedClipInfo.c
  5077. || curclip.d != this.cachedClipInfo.d || curclip.tx != this.cachedClipInfo.tx || curclip.ty != this.cachedClipInfo.ty)
  5078. return false;
  5079. return true;
  5080. }
  5081. flushsubmit() {
  5082. var curSubmit = SubmitBase.RENDERBASE;
  5083. this.submits.forEach(function (subm) {
  5084. if (subm == SubmitBase.RENDERBASE)
  5085. return;
  5086. SubmitBase.preRender = curSubmit;
  5087. curSubmit = subm;
  5088. subm.renderSubmit();
  5089. });
  5090. }
  5091. releaseMem() {
  5092. }
  5093. }
  5094. WebGLCacheAsNormalCanvas.matI = new Matrix();
  5095. var texture_vs = "/*\r\n\ttexture和fillrect使用的。\r\n*/\r\nattribute vec4 posuv;\r\nattribute vec4 attribColor;\r\nattribute vec4 attribFlags;\r\n//attribute vec4 clipDir;\r\n//attribute vec2 clipRect;\r\nuniform vec4 clipMatDir;\r\nuniform vec2 clipMatPos;\t\t// 这个是全局的,不用再应用矩阵了。\r\nvarying vec2 cliped;\r\nuniform vec2 size;\r\nuniform vec2 clipOff;\t\t\t// 使用要把clip偏移。cacheas normal用. 只用了[0]\r\n#ifdef WORLDMAT\r\n\tuniform mat4 mmat;\r\n#endif\r\n#ifdef MVP3D\r\n\tuniform mat4 u_MvpMatrix;\r\n#endif\r\nvarying vec4 v_texcoordAlpha;\r\nvarying vec4 v_color;\r\nvarying float v_useTex;\r\n\r\nvoid main() {\r\n\r\n\tvec4 pos = vec4(posuv.xy,0.,1.);\r\n#ifdef WORLDMAT\r\n\tpos=mmat*pos;\r\n#endif\r\n\tvec4 pos1 =vec4((pos.x/size.x-0.5)*2.0,(0.5-pos.y/size.y)*2.0,0.,1.0);\r\n#ifdef MVP3D\r\n\tgl_Position=u_MvpMatrix*pos1;\r\n#else\r\n\tgl_Position=pos1;\r\n#endif\r\n\tv_texcoordAlpha.xy = posuv.zw;\r\n\t//v_texcoordAlpha.z = attribColor.a/255.0;\r\n\tv_color = attribColor/255.0;\r\n\tv_color.xyz*=v_color.w;//反正后面也要预乘\r\n\t\r\n\tv_useTex = attribFlags.r/255.0;\r\n\tfloat clipw = length(clipMatDir.xy);\r\n\tfloat cliph = length(clipMatDir.zw);\r\n\t\r\n\tvec2 clpos = clipMatPos.xy;\r\n\t#ifdef WORLDMAT\r\n\t\t// 如果有mmat,需要修改clipMatPos,因为 这是cacheas normal (如果不是就错了), clipMatPos被去掉了偏移\r\n\t\tif(clipOff[0]>0.0){\r\n\t\t\tclpos.x+=mmat[3].x;\t//tx\t最简单处理\r\n\t\t\tclpos.y+=mmat[3].y;\t//ty\r\n\t\t}\r\n\t#endif\r\n\tvec2 clippos = pos.xy - clpos;\t//pos已经应用矩阵了,为了减的有意义,clip的位置也要缩放\r\n\tif(clipw>20000. && cliph>20000.)\r\n\t\tcliped = vec2(0.5,0.5);\r\n\telse {\r\n\t\t//转成0到1之间。/clipw/clipw 表示clippos与normalize之后的clip朝向点积之后,再除以clipw\r\n\t\tcliped=vec2( dot(clippos,clipMatDir.xy)/clipw/clipw, dot(clippos,clipMatDir.zw)/cliph/cliph);\r\n\t}\r\n\r\n}";
  5096. var texture_ps = "/*\r\n\ttexture和fillrect使用的。\r\n*/\r\n#ifdef FSHIGHPRECISION\r\nprecision highp float;\r\n#else\r\nprecision mediump float;\r\n#endif\r\n\r\nvarying vec4 v_texcoordAlpha;\r\nvarying vec4 v_color;\r\nvarying float v_useTex;\r\nuniform sampler2D texture;\r\nvarying vec2 cliped;\r\n\r\n#ifdef BLUR_FILTER\r\nuniform vec4 strength_sig2_2sig2_gauss1;\r\nuniform vec2 blurInfo;\r\n\r\n#define PI 3.141593\r\n\r\nfloat getGaussian(float x, float y){\r\n return strength_sig2_2sig2_gauss1.w*exp(-(x*x+y*y)/strength_sig2_2sig2_gauss1.z);\r\n}\r\n\r\nvec4 blur(){\r\n const float blurw = 9.0;\r\n vec4 vec4Color = vec4(0.0,0.0,0.0,0.0);\r\n vec2 halfsz=vec2(blurw,blurw)/2.0/blurInfo; \r\n vec2 startpos=v_texcoordAlpha.xy-halfsz;\r\n vec2 ctexcoord = startpos;\r\n vec2 step = 1.0/blurInfo; //每个像素 \r\n \r\n for(float y = 0.0;y<=blurw; ++y){\r\n ctexcoord.x=startpos.x;\r\n for(float x = 0.0;x<=blurw; ++x){\r\n //TODO 纹理坐标的固定偏移应该在vs中处理\r\n vec4Color += texture2D(texture, ctexcoord)*getGaussian(x-blurw/2.0,y-blurw/2.0);\r\n ctexcoord.x+=step.x;\r\n }\r\n ctexcoord.y+=step.y;\r\n }\r\n return vec4Color;\r\n}\r\n#endif\r\n\r\n#ifdef COLOR_FILTER\r\nuniform vec4 colorAlpha;\r\nuniform mat4 colorMat;\r\n#endif\r\n\r\n#ifdef GLOW_FILTER\r\nuniform vec4 u_color;\r\nuniform vec4 u_blurInfo1;\r\nuniform vec4 u_blurInfo2;\r\n#endif\r\n\r\n#ifdef COLOR_ADD\r\nuniform vec4 colorAdd;\r\n#endif\r\n\r\n#ifdef FILLTEXTURE\t\r\nuniform vec4 u_TexRange;//startu,startv,urange, vrange\r\n#endif\r\nvoid main() {\r\n\tif(cliped.x<0.) discard;\r\n\tif(cliped.x>1.) discard;\r\n\tif(cliped.y<0.) discard;\r\n\tif(cliped.y>1.) discard;\r\n\t\r\n#ifdef FILLTEXTURE\t\r\n vec4 color= texture2D(texture, fract(v_texcoordAlpha.xy)*u_TexRange.zw + u_TexRange.xy);\r\n#else\r\n vec4 color= texture2D(texture, v_texcoordAlpha.xy);\r\n#endif\r\n\r\n if(v_useTex<=0.)color = vec4(1.,1.,1.,1.);\r\n color.a*=v_color.w;\r\n //color.rgb*=v_color.w;\r\n color.rgb*=v_color.rgb;\r\n gl_FragColor=color;\r\n \r\n #ifdef COLOR_ADD\r\n\tgl_FragColor = vec4(colorAdd.rgb,colorAdd.a*gl_FragColor.a);\r\n\tgl_FragColor.xyz *= colorAdd.a;\r\n #endif\r\n \r\n #ifdef BLUR_FILTER\r\n\tgl_FragColor = blur();\r\n\tgl_FragColor.w*=v_color.w; \r\n #endif\r\n \r\n #ifdef COLOR_FILTER\r\n\tmat4 alphaMat =colorMat;\r\n\r\n\talphaMat[0][3] *= gl_FragColor.a;\r\n\talphaMat[1][3] *= gl_FragColor.a;\r\n\talphaMat[2][3] *= gl_FragColor.a;\r\n\r\n\tgl_FragColor = gl_FragColor * alphaMat;\r\n\tgl_FragColor += colorAlpha/255.0*gl_FragColor.a;\r\n #endif\r\n \r\n #ifdef GLOW_FILTER\r\n\tconst float c_IterationTime = 10.0;\r\n\tfloat floatIterationTotalTime = c_IterationTime * c_IterationTime;\r\n\tvec4 vec4Color = vec4(0.0,0.0,0.0,0.0);\r\n\tvec2 vec2FilterDir = vec2(-(u_blurInfo1.z)/u_blurInfo2.x,-(u_blurInfo1.w)/u_blurInfo2.y);\r\n\tvec2 vec2FilterOff = vec2(u_blurInfo1.x/u_blurInfo2.x/c_IterationTime * 2.0,u_blurInfo1.y/u_blurInfo2.y/c_IterationTime * 2.0);\r\n\tfloat maxNum = u_blurInfo1.x * u_blurInfo1.y;\r\n\tvec2 vec2Off = vec2(0.0,0.0);\r\n\tfloat floatOff = c_IterationTime/2.0;\r\n\tfor(float i = 0.0;i<=c_IterationTime; ++i){\r\n\t\tfor(float j = 0.0;j<=c_IterationTime; ++j){\r\n\t\t\tvec2Off = vec2(vec2FilterOff.x * (i - floatOff),vec2FilterOff.y * (j - floatOff));\r\n\t\t\tvec4Color += texture2D(texture, v_texcoordAlpha.xy + vec2FilterDir + vec2Off)/floatIterationTotalTime;\r\n\t\t}\r\n\t}\r\n\tgl_FragColor = vec4(u_color.rgb,vec4Color.a * u_blurInfo2.z);\r\n\tgl_FragColor.rgb *= gl_FragColor.a; \r\n #endif\r\n \r\n}";
  5097. var prime_vs = "attribute vec4 position;\r\nattribute vec4 attribColor;\r\n//attribute vec4 clipDir;\r\n//attribute vec2 clipRect;\r\nuniform vec4 clipMatDir;\r\nuniform vec2 clipMatPos;\r\n#ifdef WORLDMAT\r\n\tuniform mat4 mmat;\r\n#endif\r\nuniform mat4 u_mmat2;\r\n//uniform vec2 u_pos;\r\nuniform vec2 size;\r\nvarying vec4 color;\r\n//vec4 dirxy=vec4(0.9,0.1, -0.1,0.9);\r\n//vec4 clip=vec4(100.,30.,300.,600.);\r\nvarying vec2 cliped;\r\nvoid main(){\r\n\t\r\n#ifdef WORLDMAT\r\n\tvec4 pos=mmat*vec4(position.xy,0.,1.);\r\n\tgl_Position =vec4((pos.x/size.x-0.5)*2.0,(0.5-pos.y/size.y)*2.0,pos.z,1.0);\r\n#else\r\n\tgl_Position =vec4((position.x/size.x-0.5)*2.0,(0.5-position.y/size.y)*2.0,position.z,1.0);\r\n#endif\t\r\n\tfloat clipw = length(clipMatDir.xy);\r\n\tfloat cliph = length(clipMatDir.zw);\r\n\tvec2 clippos = position.xy - clipMatPos.xy;\t//pos已经应用矩阵了,为了减的有意义,clip的位置也要缩放\r\n\tif(clipw>20000. && cliph>20000.)\r\n\t\tcliped = vec2(0.5,0.5);\r\n\telse {\r\n\t\t//clipdir是带缩放的方向,由于上面clippos是在缩放后的空间计算的,所以需要把方向先normalize一下\r\n\t\tcliped=vec2( dot(clippos,clipMatDir.xy)/clipw/clipw, dot(clippos,clipMatDir.zw)/cliph/cliph);\r\n\t}\r\n //pos2d.x = dot(clippos,dirx);\r\n color=attribColor/255.;\r\n}";
  5098. var prime_ps = "precision mediump float;\r\n//precision mediump float;\r\nvarying vec4 color;\r\n//uniform float alpha;\r\nvarying vec2 cliped;\r\nvoid main(){\r\n\t//vec4 a=vec4(color.r, color.g, color.b, 1);\r\n\t//a.a*=alpha;\r\n gl_FragColor= color;// vec4(color.r, color.g, color.b, alpha);\r\n\tgl_FragColor.rgb*=color.a;\r\n\tif(cliped.x<0.) discard;\r\n\tif(cliped.x>1.) discard;\r\n\tif(cliped.y<0.) discard;\r\n\tif(cliped.y>1.) discard;\r\n}";
  5099. var skin_vs = "attribute vec2 position;\r\nattribute vec2 texcoord;\r\nattribute vec4 color;\r\nuniform vec2 size;\r\nuniform float offsetX;\r\nuniform float offsetY;\r\nuniform mat4 mmat;\r\nuniform mat4 u_mmat2;\r\nvarying vec2 v_texcoord;\r\nvarying vec4 v_color;\r\nvoid main() {\r\n vec4 pos=mmat*u_mmat2*vec4(offsetX+position.x,offsetY+position.y,0,1 );\r\n gl_Position = vec4((pos.x/size.x-0.5)*2.0,(0.5-pos.y/size.y)*2.0,pos.z,1.0);\r\n v_color = color;\r\n v_color.rgb *= v_color.a;\r\n v_texcoord = texcoord; \r\n}";
  5100. var skin_ps = "precision mediump float;\r\nvarying vec2 v_texcoord;\r\nvarying vec4 v_color;\r\nuniform sampler2D texture;\r\nuniform float alpha;\r\nvoid main() {\r\n\tvec4 t_color = texture2D(texture, v_texcoord);\r\n\tgl_FragColor = t_color.rgba * v_color;\r\n\tgl_FragColor *= alpha;\r\n}";
  5101. class Shader2D {
  5102. constructor() {
  5103. this.ALPHA = 1;
  5104. this.defines = new ShaderDefines2D();
  5105. this.shaderType = 0;
  5106. this.fillStyle = DrawStyle.DEFAULT;
  5107. this.strokeStyle = DrawStyle.DEFAULT;
  5108. }
  5109. destroy() {
  5110. this.defines = null;
  5111. this.filters = null;
  5112. }
  5113. static __init__() {
  5114. Shader.preCompile2D(0, ShaderDefines2D.TEXTURE2D, texture_vs, texture_ps, null);
  5115. Shader.preCompile2D(0, ShaderDefines2D.PRIMITIVE, prime_vs, prime_ps, null);
  5116. Shader.preCompile2D(0, ShaderDefines2D.SKINMESH, skin_vs, skin_ps, null);
  5117. }
  5118. }
  5119. class SkinMeshBuffer {
  5120. constructor() {
  5121. var gl = LayaGL.instance;
  5122. this.ib = IndexBuffer2D.create(gl.DYNAMIC_DRAW);
  5123. this.vb = VertexBuffer2D.create(8);
  5124. }
  5125. static getInstance() {
  5126. return SkinMeshBuffer.instance = SkinMeshBuffer.instance || new SkinMeshBuffer();
  5127. }
  5128. addSkinMesh(skinMesh) {
  5129. skinMesh.getData2(this.vb, this.ib, this.vb._byteLength / 32);
  5130. }
  5131. reset() {
  5132. this.vb.clear();
  5133. this.ib.clear();
  5134. }
  5135. }
  5136. class BasePoly {
  5137. static createLine2(p, indices, lineWidth, indexBase, outVertex, loop) {
  5138. if (p.length < 4)
  5139. return null;
  5140. var points = BasePoly.tempData.length > (p.length + 2) ? BasePoly.tempData : new Array(p.length + 2);
  5141. points[0] = p[0];
  5142. points[1] = p[1];
  5143. var newlen = 2;
  5144. var i = 0;
  5145. var length = p.length;
  5146. for (i = 2; i < length; i += 2) {
  5147. if (Math.abs(p[i] - p[i - 2]) + Math.abs(p[i + 1] - p[i - 1]) > 0.01) {
  5148. points[newlen++] = p[i];
  5149. points[newlen++] = p[i + 1];
  5150. }
  5151. }
  5152. if (loop && Math.abs(p[0] - points[newlen - 2]) + Math.abs(p[1] - points[newlen - 1]) > 0.01) {
  5153. points[newlen++] = p[0];
  5154. points[newlen++] = p[1];
  5155. }
  5156. var result = outVertex;
  5157. length = newlen / 2;
  5158. var w = lineWidth / 2;
  5159. var px, py, p1x, p1y, p2x, p2y, p3x, p3y;
  5160. var perpx, perpy, perp2x, perp2y;
  5161. var a1, b1, c1, a2, b2, c2;
  5162. var denom, dist;
  5163. p1x = points[0];
  5164. p1y = points[1];
  5165. p2x = points[2];
  5166. p2y = points[3];
  5167. perpx = -(p1y - p2y);
  5168. perpy = p1x - p2x;
  5169. dist = Math.sqrt(perpx * perpx + perpy * perpy);
  5170. perpx = perpx / dist * w;
  5171. perpy = perpy / dist * w;
  5172. result.push(p1x - perpx, p1y - perpy, p1x + perpx, p1y + perpy);
  5173. for (i = 1; i < length - 1; i++) {
  5174. p1x = points[(i - 1) * 2];
  5175. p1y = points[(i - 1) * 2 + 1];
  5176. p2x = points[(i) * 2];
  5177. p2y = points[(i) * 2 + 1];
  5178. p3x = points[(i + 1) * 2];
  5179. p3y = points[(i + 1) * 2 + 1];
  5180. perpx = -(p1y - p2y);
  5181. perpy = p1x - p2x;
  5182. dist = Math.sqrt(perpx * perpx + perpy * perpy);
  5183. perpx = perpx / dist * w;
  5184. perpy = perpy / dist * w;
  5185. perp2x = -(p2y - p3y);
  5186. perp2y = p2x - p3x;
  5187. dist = Math.sqrt(perp2x * perp2x + perp2y * perp2y);
  5188. perp2x = perp2x / dist * w;
  5189. perp2y = perp2y / dist * w;
  5190. a1 = (-perpy + p1y) - (-perpy + p2y);
  5191. b1 = (-perpx + p2x) - (-perpx + p1x);
  5192. c1 = (-perpx + p1x) * (-perpy + p2y) - (-perpx + p2x) * (-perpy + p1y);
  5193. a2 = (-perp2y + p3y) - (-perp2y + p2y);
  5194. b2 = (-perp2x + p2x) - (-perp2x + p3x);
  5195. c2 = (-perp2x + p3x) * (-perp2y + p2y) - (-perp2x + p2x) * (-perp2y + p3y);
  5196. denom = a1 * b2 - a2 * b1;
  5197. if (Math.abs(denom) < 0.1) {
  5198. denom += 10.1;
  5199. result.push(p2x - perpx, p2y - perpy, p2x + perpx, p2y + perpy);
  5200. continue;
  5201. }
  5202. px = (b1 * c2 - b2 * c1) / denom;
  5203. py = (a2 * c1 - a1 * c2) / denom;
  5204. result.push(px, py, p2x - (px - p2x), p2y - (py - p2y));
  5205. }
  5206. p1x = points[newlen - 4];
  5207. p1y = points[newlen - 3];
  5208. p2x = points[newlen - 2];
  5209. p2y = points[newlen - 1];
  5210. perpx = -(p1y - p2y);
  5211. perpy = p1x - p2x;
  5212. dist = Math.sqrt(perpx * perpx + perpy * perpy);
  5213. perpx = perpx / dist * w;
  5214. perpy = perpy / dist * w;
  5215. result.push(p2x - perpx, p2y - perpy, p2x + perpx, p2y + perpy);
  5216. for (i = 1; i < length; i++) {
  5217. indices.push(indexBase + (i - 1) * 2, indexBase + (i - 1) * 2 + 1, indexBase + i * 2 + 1, indexBase + i * 2 + 1, indexBase + i * 2, indexBase + (i - 1) * 2);
  5218. }
  5219. return result;
  5220. }
  5221. static createLineTriangle(path, color, width, loop, outvb, vbstride, outib) {
  5222. var points = path.slice();
  5223. var ptlen = points.length;
  5224. var p1x = points[0], p1y = points[1];
  5225. var p2x = points[2], p2y = points[2];
  5226. var len = 0;
  5227. var rp = 0;
  5228. var dx = 0, dy = 0;
  5229. var pointnum = ptlen / 2;
  5230. if (pointnum <= 1)
  5231. return;
  5232. if (pointnum == 2) {
  5233. return;
  5234. }
  5235. var tmpData = new Array(pointnum * 4);
  5236. var realPtNum = 0;
  5237. var ci = 0;
  5238. for (var i = 0; i < pointnum - 1; i++) {
  5239. p1x = points[ci++], p1y = points[ci++];
  5240. p2x = points[ci++], p2y = points[ci++];
  5241. dx = p2x - p1x, dy = p2y - p1y;
  5242. if (dx != 0 && dy != 0) {
  5243. len = Math.sqrt(dx * dx + dy * dy);
  5244. if (len > 1e-3) {
  5245. rp = realPtNum * 4;
  5246. tmpData[rp] = p1x;
  5247. tmpData[rp + 1] = p1y;
  5248. tmpData[rp + 2] = dx / len;
  5249. tmpData[rp + 3] = dy / len;
  5250. realPtNum++;
  5251. }
  5252. }
  5253. }
  5254. if (loop) {
  5255. p1x = points[ptlen - 2], p1y = points[ptlen - 1];
  5256. p2x = points[0], p2y = points[1];
  5257. dx = p2x - p1x, dy = p2y - p1y;
  5258. if (dx != 0 && dy != 0) {
  5259. len = Math.sqrt(dx * dx + dy * dy);
  5260. if (len > 1e-3) {
  5261. rp = realPtNum * 4;
  5262. tmpData[rp] = p1x;
  5263. tmpData[rp + 1] = p1y;
  5264. tmpData[rp + 2] = dx / len;
  5265. tmpData[rp + 3] = dy / len;
  5266. realPtNum++;
  5267. }
  5268. }
  5269. }
  5270. else {
  5271. rp = realPtNum * 4;
  5272. tmpData[rp] = p1x;
  5273. tmpData[rp + 1] = p1y;
  5274. tmpData[rp + 2] = dx / len;
  5275. tmpData[rp + 3] = dy / len;
  5276. realPtNum++;
  5277. }
  5278. ci = 0;
  5279. for (i = 0; i < pointnum; i++) {
  5280. p1x = points[ci], p1y = points[ci + 1];
  5281. p2x = points[ci + 2], p2y = points[ci + 3];
  5282. }
  5283. }
  5284. }
  5285. BasePoly.tempData = new Array(256);
  5286. class EarcutNode {
  5287. constructor(i, x, y) {
  5288. this.i = i;
  5289. this.x = x;
  5290. this.y = y;
  5291. this.prev = null;
  5292. this.next = null;
  5293. this.z = null;
  5294. this.prevZ = null;
  5295. this.nextZ = null;
  5296. this.steiner = false;
  5297. }
  5298. }
  5299. class Earcut {
  5300. static earcut(data, holeIndices, dim) {
  5301. dim = dim || 2;
  5302. var hasHoles = holeIndices && holeIndices.length, outerLen = hasHoles ? holeIndices[0] * dim : data.length, outerNode = Earcut.linkedList(data, 0, outerLen, dim, true), triangles = [];
  5303. if (!outerNode)
  5304. return triangles;
  5305. var minX, minY, maxX, maxY, x, y, invSize;
  5306. if (hasHoles)
  5307. outerNode = Earcut.eliminateHoles(data, holeIndices, outerNode, dim);
  5308. if (data.length > 80 * dim) {
  5309. minX = maxX = data[0];
  5310. minY = maxY = data[1];
  5311. for (var i = dim; i < outerLen; i += dim) {
  5312. x = data[i];
  5313. y = data[i + 1];
  5314. if (x < minX)
  5315. minX = x;
  5316. if (y < minY)
  5317. minY = y;
  5318. if (x > maxX)
  5319. maxX = x;
  5320. if (y > maxY)
  5321. maxY = y;
  5322. }
  5323. invSize = Math.max(maxX - minX, maxY - minY);
  5324. invSize = invSize !== 0 ? 1 / invSize : 0;
  5325. }
  5326. Earcut.earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  5327. return triangles;
  5328. }
  5329. static linkedList(data, start, end, dim, clockwise) {
  5330. var i, last;
  5331. if (clockwise === (Earcut.signedArea(data, start, end, dim) > 0)) {
  5332. for (i = start; i < end; i += dim)
  5333. last = Earcut.insertNode(i, data[i], data[i + 1], last);
  5334. }
  5335. else {
  5336. for (i = end - dim; i >= start; i -= dim)
  5337. last = Earcut.insertNode(i, data[i], data[i + 1], last);
  5338. }
  5339. if (last && Earcut.equals(last, last.next)) {
  5340. Earcut.removeNode(last);
  5341. last = last.next;
  5342. }
  5343. return last;
  5344. }
  5345. static filterPoints(start, end) {
  5346. if (!start)
  5347. return start;
  5348. if (!end)
  5349. end = start;
  5350. var p = start, again;
  5351. do {
  5352. again = false;
  5353. if (!p.steiner && (Earcut.equals(p, p.next) || Earcut.area(p.prev, p, p.next) === 0)) {
  5354. Earcut.removeNode(p);
  5355. p = end = p.prev;
  5356. if (p === p.next)
  5357. break;
  5358. again = true;
  5359. }
  5360. else {
  5361. p = p.next;
  5362. }
  5363. } while (again || p !== end);
  5364. return end;
  5365. }
  5366. static earcutLinked(ear, triangles, dim, minX, minY, invSize, pass = null) {
  5367. if (!ear)
  5368. return;
  5369. if (!pass && invSize)
  5370. Earcut.indexCurve(ear, minX, minY, invSize);
  5371. var stop = ear, prev, next;
  5372. while (ear.prev !== ear.next) {
  5373. prev = ear.prev;
  5374. next = ear.next;
  5375. if (invSize ? Earcut.isEarHashed(ear, minX, minY, invSize) : Earcut.isEar(ear)) {
  5376. triangles.push(prev.i / dim);
  5377. triangles.push(ear.i / dim);
  5378. triangles.push(next.i / dim);
  5379. Earcut.removeNode(ear);
  5380. ear = next.next;
  5381. stop = next.next;
  5382. continue;
  5383. }
  5384. ear = next;
  5385. if (ear === stop) {
  5386. if (!pass) {
  5387. Earcut.earcutLinked(Earcut.filterPoints(ear, null), triangles, dim, minX, minY, invSize, 1);
  5388. }
  5389. else if (pass === 1) {
  5390. ear = Earcut.cureLocalIntersections(ear, triangles, dim);
  5391. Earcut.earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
  5392. }
  5393. else if (pass === 2) {
  5394. Earcut.splitEarcut(ear, triangles, dim, minX, minY, invSize);
  5395. }
  5396. break;
  5397. }
  5398. }
  5399. }
  5400. static isEar(ear) {
  5401. var a = ear.prev, b = ear, c = ear.next;
  5402. if (Earcut.area(a, b, c) >= 0)
  5403. return false;
  5404. var p = ear.next.next;
  5405. while (p !== ear.prev) {
  5406. if (Earcut.pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  5407. Earcut.area(p.prev, p, p.next) >= 0)
  5408. return false;
  5409. p = p.next;
  5410. }
  5411. return true;
  5412. }
  5413. static isEarHashed(ear, minX, minY, invSize) {
  5414. var a = ear.prev, b = ear, c = ear.next;
  5415. if (Earcut.area(a, b, c) >= 0)
  5416. return false;
  5417. var minTX = a.x < b.x ? (a.x < c.x ? a.x : c.x) : (b.x < c.x ? b.x : c.x), minTY = a.y < b.y ? (a.y < c.y ? a.y : c.y) : (b.y < c.y ? b.y : c.y), maxTX = a.x > b.x ? (a.x > c.x ? a.x : c.x) : (b.x > c.x ? b.x : c.x), maxTY = a.y > b.y ? (a.y > c.y ? a.y : c.y) : (b.y > c.y ? b.y : c.y);
  5418. var minZ = Earcut.zOrder(minTX, minTY, minX, minY, invSize), maxZ = Earcut.zOrder(maxTX, maxTY, minX, minY, invSize);
  5419. var p = ear.nextZ;
  5420. while (p && p.z <= maxZ) {
  5421. if (p !== ear.prev && p !== ear.next &&
  5422. Earcut.pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  5423. Earcut.area(p.prev, p, p.next) >= 0)
  5424. return false;
  5425. p = p.nextZ;
  5426. }
  5427. p = ear.prevZ;
  5428. while (p && p.z >= minZ) {
  5429. if (p !== ear.prev && p !== ear.next &&
  5430. Earcut.pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  5431. Earcut.area(p.prev, p, p.next) >= 0)
  5432. return false;
  5433. p = p.prevZ;
  5434. }
  5435. return true;
  5436. }
  5437. static cureLocalIntersections(start, triangles, dim) {
  5438. var p = start;
  5439. do {
  5440. var a = p.prev, b = p.next.next;
  5441. if (!Earcut.equals(a, b) && Earcut.intersects(a, p, p.next, b) && Earcut.locallyInside(a, b) && Earcut.locallyInside(b, a)) {
  5442. triangles.push(a.i / dim);
  5443. triangles.push(p.i / dim);
  5444. triangles.push(b.i / dim);
  5445. Earcut.removeNode(p);
  5446. Earcut.removeNode(p.next);
  5447. p = start = b;
  5448. }
  5449. p = p.next;
  5450. } while (p !== start);
  5451. return p;
  5452. }
  5453. static splitEarcut(start, triangles, dim, minX, minY, invSize) {
  5454. var a = start;
  5455. do {
  5456. var b = a.next.next;
  5457. while (b !== a.prev) {
  5458. if (a.i !== b.i && Earcut.isValidDiagonal(a, b)) {
  5459. var c = Earcut.splitPolygon(a, b);
  5460. a = Earcut.filterPoints(a, a.next);
  5461. c = Earcut.filterPoints(c, c.next);
  5462. Earcut.earcutLinked(a, triangles, dim, minX, minY, invSize);
  5463. Earcut.earcutLinked(c, triangles, dim, minX, minY, invSize);
  5464. return;
  5465. }
  5466. b = b.next;
  5467. }
  5468. a = a.next;
  5469. } while (a !== start);
  5470. }
  5471. static eliminateHoles(data, holeIndices, outerNode, dim) {
  5472. var queue = [], i, len, start, end, list;
  5473. for (i = 0, len = holeIndices.length; i < len; i++) {
  5474. start = holeIndices[i] * dim;
  5475. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  5476. list = Earcut.linkedList(data, start, end, dim, false);
  5477. if (list === list.next)
  5478. list.steiner = true;
  5479. queue.push(Earcut.getLeftmost(list));
  5480. }
  5481. queue.sort(Earcut.compareX);
  5482. for (i = 0; i < queue.length; i++) {
  5483. Earcut.eliminateHole(queue[i], outerNode);
  5484. outerNode = Earcut.filterPoints(outerNode, outerNode.next);
  5485. }
  5486. return outerNode;
  5487. }
  5488. static compareX(a, b) {
  5489. return a.x - b.x;
  5490. }
  5491. static eliminateHole(hole, outerNode) {
  5492. outerNode = Earcut.findHoleBridge(hole, outerNode);
  5493. if (outerNode) {
  5494. var b = Earcut.splitPolygon(outerNode, hole);
  5495. Earcut.filterPoints(b, b.next);
  5496. }
  5497. }
  5498. static findHoleBridge(hole, outerNode) {
  5499. var p = outerNode, hx = hole.x, hy = hole.y, qx = -Infinity, m;
  5500. do {
  5501. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  5502. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  5503. if (x <= hx && x > qx) {
  5504. qx = x;
  5505. if (x === hx) {
  5506. if (hy === p.y)
  5507. return p;
  5508. if (hy === p.next.y)
  5509. return p.next;
  5510. }
  5511. m = p.x < p.next.x ? p : p.next;
  5512. }
  5513. }
  5514. p = p.next;
  5515. } while (p !== outerNode);
  5516. if (!m)
  5517. return null;
  5518. if (hx === qx)
  5519. return m.prev;
  5520. var stop = m, mx = m.x, my = m.y, tanMin = Infinity, tan;
  5521. p = m.next;
  5522. while (p !== stop) {
  5523. if (hx >= p.x && p.x >= mx && hx !== p.x &&
  5524. Earcut.pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
  5525. tan = Math.abs(hy - p.y) / (hx - p.x);
  5526. if ((tan < tanMin || (tan === tanMin && p.x > m.x)) && Earcut.locallyInside(p, hole)) {
  5527. m = p;
  5528. tanMin = tan;
  5529. }
  5530. }
  5531. p = p.next;
  5532. }
  5533. return m;
  5534. }
  5535. static indexCurve(start, minX, minY, invSize) {
  5536. var p = start;
  5537. do {
  5538. if (p.z === null)
  5539. p.z = Earcut.zOrder(p.x, p.y, minX, minY, invSize);
  5540. p.prevZ = p.prev;
  5541. p.nextZ = p.next;
  5542. p = p.next;
  5543. } while (p !== start);
  5544. p.prevZ.nextZ = null;
  5545. p.prevZ = null;
  5546. Earcut.sortLinked(p);
  5547. }
  5548. static sortLinked(list) {
  5549. var i, p, q, e, tail, numMerges, pSize, qSize, inSize = 1;
  5550. do {
  5551. p = list;
  5552. list = null;
  5553. tail = null;
  5554. numMerges = 0;
  5555. while (p) {
  5556. numMerges++;
  5557. q = p;
  5558. pSize = 0;
  5559. for (i = 0; i < inSize; i++) {
  5560. pSize++;
  5561. q = q.nextZ;
  5562. if (!q)
  5563. break;
  5564. }
  5565. qSize = inSize;
  5566. while (pSize > 0 || (qSize > 0 && q)) {
  5567. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  5568. e = p;
  5569. p = p.nextZ;
  5570. pSize--;
  5571. }
  5572. else {
  5573. e = q;
  5574. q = q.nextZ;
  5575. qSize--;
  5576. }
  5577. if (tail)
  5578. tail.nextZ = e;
  5579. else
  5580. list = e;
  5581. e.prevZ = tail;
  5582. tail = e;
  5583. }
  5584. p = q;
  5585. }
  5586. tail.nextZ = null;
  5587. inSize *= 2;
  5588. } while (numMerges > 1);
  5589. return list;
  5590. }
  5591. static zOrder(x, y, minX, minY, invSize) {
  5592. x = 32767 * (x - minX) * invSize;
  5593. y = 32767 * (y - minY) * invSize;
  5594. x = (x | (x << 8)) & 0x00FF00FF;
  5595. x = (x | (x << 4)) & 0x0F0F0F0F;
  5596. x = (x | (x << 2)) & 0x33333333;
  5597. x = (x | (x << 1)) & 0x55555555;
  5598. y = (y | (y << 8)) & 0x00FF00FF;
  5599. y = (y | (y << 4)) & 0x0F0F0F0F;
  5600. y = (y | (y << 2)) & 0x33333333;
  5601. y = (y | (y << 1)) & 0x55555555;
  5602. return x | (y << 1);
  5603. }
  5604. static getLeftmost(start) {
  5605. var p = start, leftmost = start;
  5606. do {
  5607. if (p.x < leftmost.x)
  5608. leftmost = p;
  5609. p = p.next;
  5610. } while (p !== start);
  5611. return leftmost;
  5612. }
  5613. static pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  5614. return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 &&
  5615. (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 &&
  5616. (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
  5617. }
  5618. static isValidDiagonal(a, b) {
  5619. return a.next.i !== b.i && a.prev.i !== b.i && !Earcut.intersectsPolygon(a, b) &&
  5620. Earcut.locallyInside(a, b) && Earcut.locallyInside(b, a) && Earcut.middleInside(a, b);
  5621. }
  5622. static area(p, q, r) {
  5623. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  5624. }
  5625. static equals(p1, p2) {
  5626. return p1.x === p2.x && p1.y === p2.y;
  5627. }
  5628. static intersects(p1, q1, p2, q2) {
  5629. if ((Earcut.equals(p1, q1) && Earcut.equals(p2, q2)) ||
  5630. (Earcut.equals(p1, q2) && Earcut.equals(p2, q1)))
  5631. return true;
  5632. return Earcut.area(p1, q1, p2) > 0 !== Earcut.area(p1, q1, q2) > 0 &&
  5633. Earcut.area(p2, q2, p1) > 0 !== Earcut.area(p2, q2, q1) > 0;
  5634. }
  5635. static intersectsPolygon(a, b) {
  5636. var p = a;
  5637. do {
  5638. if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  5639. Earcut.intersects(p, p.next, a, b))
  5640. return true;
  5641. p = p.next;
  5642. } while (p !== a);
  5643. return false;
  5644. }
  5645. static locallyInside(a, b) {
  5646. return Earcut.area(a.prev, a, a.next) < 0 ?
  5647. Earcut.area(a, b, a.next) >= 0 && Earcut.area(a, a.prev, b) >= 0 :
  5648. Earcut.area(a, b, a.prev) < 0 || Earcut.area(a, a.next, b) < 0;
  5649. }
  5650. static middleInside(a, b) {
  5651. var p = a, inside = false, px = (a.x + b.x) / 2, py = (a.y + b.y) / 2;
  5652. do {
  5653. if (((p.y > py) !== (p.next.y > py)) && p.next.y !== p.y &&
  5654. (px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x))
  5655. inside = !inside;
  5656. p = p.next;
  5657. } while (p !== a);
  5658. return inside;
  5659. }
  5660. static splitPolygon(a, b) {
  5661. var a2 = new EarcutNode(a.i, a.x, a.y), b2 = new EarcutNode(b.i, b.x, b.y), an = a.next, bp = b.prev;
  5662. a.next = b;
  5663. b.prev = a;
  5664. a2.next = an;
  5665. an.prev = a2;
  5666. b2.next = a2;
  5667. a2.prev = b2;
  5668. bp.next = b2;
  5669. b2.prev = bp;
  5670. return b2;
  5671. }
  5672. static insertNode(i, x, y, last) {
  5673. var p = new EarcutNode(i, x, y);
  5674. if (!last) {
  5675. p.prev = p;
  5676. p.next = p;
  5677. }
  5678. else {
  5679. p.next = last.next;
  5680. p.prev = last;
  5681. last.next.prev = p;
  5682. last.next = p;
  5683. }
  5684. return p;
  5685. }
  5686. static removeNode(p) {
  5687. p.next.prev = p.prev;
  5688. p.prev.next = p.next;
  5689. if (p.prevZ)
  5690. p.prevZ.nextZ = p.nextZ;
  5691. if (p.nextZ)
  5692. p.nextZ.prevZ = p.prevZ;
  5693. }
  5694. static signedArea(data, start, end, dim) {
  5695. var sum = 0;
  5696. for (var i = start, j = end - dim; i < end; i += dim) {
  5697. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  5698. j = i;
  5699. }
  5700. return sum;
  5701. }
  5702. }
  5703. class CONST3D2D {
  5704. }
  5705. CONST3D2D.BYTES_PE = 4;
  5706. CONST3D2D.BYTES_PIDX = 2;
  5707. CONST3D2D.defaultMatrix4 = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  5708. CONST3D2D.defaultMinusYMatrix4 = [1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  5709. CONST3D2D.uniformMatrix3 = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0];
  5710. CONST3D2D._TMPARRAY = [];
  5711. CONST3D2D._OFFSETX = 0;
  5712. CONST3D2D._OFFSETY = 0;
  5713. class Submit extends SubmitBase {
  5714. constructor(renderType = SubmitBase.TYPE_2D) {
  5715. super(renderType);
  5716. }
  5717. renderSubmit() {
  5718. if (this._numEle === 0 || !this._mesh || this._numEle == 0)
  5719. return 1;
  5720. var _tex = this.shaderValue.textureHost;
  5721. if (_tex) {
  5722. var source = _tex._getSource();
  5723. if (!source)
  5724. return 1;
  5725. this.shaderValue.texture = source;
  5726. }
  5727. var gl = WebGLContext.mainContext;
  5728. this._mesh.useMesh(gl);
  5729. this.shaderValue.upload();
  5730. if (BlendMode.activeBlendFunction !== this._blendFn) {
  5731. WebGLContext.setBlend(gl, true);
  5732. this._blendFn(gl);
  5733. BlendMode.activeBlendFunction = this._blendFn;
  5734. }
  5735. gl.drawElements(gl.TRIANGLES, this._numEle, gl.UNSIGNED_SHORT, this._startIdx);
  5736. Stat.renderBatches++;
  5737. Stat.trianglesFaces += this._numEle / 3;
  5738. return 1;
  5739. }
  5740. releaseRender() {
  5741. if (SubmitBase.RENDERBASE == this)
  5742. return;
  5743. if ((--this._ref) < 1) {
  5744. Submit.POOL[Submit._poolSize++] = this;
  5745. this.shaderValue.release();
  5746. this.shaderValue = null;
  5747. this._mesh = null;
  5748. this._parent && (this._parent.releaseRender(), this._parent = null);
  5749. }
  5750. }
  5751. static create(context, mesh, sv) {
  5752. var o = Submit._poolSize ? Submit.POOL[--Submit._poolSize] : new Submit();
  5753. o._ref = 1;
  5754. o._mesh = mesh;
  5755. o._key.clear();
  5756. o._startIdx = mesh.indexNum * CONST3D2D.BYTES_PIDX;
  5757. o._numEle = 0;
  5758. var blendType = context._nBlendType;
  5759. o._blendFn = context._targets ? BlendMode.targetFns[blendType] : BlendMode.fns[blendType];
  5760. o.shaderValue = sv;
  5761. o.shaderValue.setValue(context._shader2D);
  5762. var filters = context._shader2D.filters;
  5763. filters && o.shaderValue.setFilters(filters);
  5764. return o;
  5765. }
  5766. static createShape(ctx, mesh, numEle, sv) {
  5767. var o = Submit._poolSize ? Submit.POOL[--Submit._poolSize] : (new Submit());
  5768. o._mesh = mesh;
  5769. o._numEle = numEle;
  5770. o._startIdx = mesh.indexNum * 2;
  5771. o._ref = 1;
  5772. o.shaderValue = sv;
  5773. o.shaderValue.setValue(ctx._shader2D);
  5774. var blendType = ctx._nBlendType;
  5775. o._key.blendShader = blendType;
  5776. o._blendFn = ctx._targets ? BlendMode.targetFns[blendType] : BlendMode.fns[blendType];
  5777. return o;
  5778. }
  5779. }
  5780. Submit._poolSize = 0;
  5781. Submit.POOL = [];
  5782. class SubmitCanvas extends SubmitBase {
  5783. constructor() {
  5784. super(SubmitBase.TYPE_2D);
  5785. this._matrix = new Matrix();
  5786. this._matrix4 = CONST3D2D.defaultMatrix4.concat();
  5787. this.shaderValue = new Value2D(0, 0);
  5788. }
  5789. static create(canvas, alpha, filters) {
  5790. var o = (!SubmitCanvas.POOL._length) ? (new SubmitCanvas()) : SubmitCanvas.POOL[--SubmitCanvas.POOL._length];
  5791. o.canv = canvas;
  5792. o._ref = 1;
  5793. o._numEle = 0;
  5794. var v = o.shaderValue;
  5795. v.alpha = alpha;
  5796. v.defines.setValue(0);
  5797. filters && filters.length && v.setFilters(filters);
  5798. return o;
  5799. }
  5800. renderSubmit() {
  5801. var preAlpha = RenderState2D.worldAlpha;
  5802. var preMatrix4 = RenderState2D.worldMatrix4;
  5803. var preMatrix = RenderState2D.worldMatrix;
  5804. var preFilters = RenderState2D.worldFilters;
  5805. var preWorldShaderDefines = RenderState2D.worldShaderDefines;
  5806. var v = this.shaderValue;
  5807. var m = this._matrix;
  5808. var m4 = this._matrix4;
  5809. var mout = Matrix.TEMP;
  5810. Matrix.mul(m, preMatrix, mout);
  5811. m4[0] = mout.a;
  5812. m4[1] = mout.b;
  5813. m4[4] = mout.c;
  5814. m4[5] = mout.d;
  5815. m4[12] = mout.tx;
  5816. m4[13] = mout.ty;
  5817. RenderState2D.worldMatrix = mout.clone();
  5818. RenderState2D.worldMatrix4 = m4;
  5819. RenderState2D.worldAlpha = RenderState2D.worldAlpha * v.alpha;
  5820. if (v.filters && v.filters.length) {
  5821. RenderState2D.worldFilters = v.filters;
  5822. RenderState2D.worldShaderDefines = v.defines;
  5823. }
  5824. this.canv['flushsubmit']();
  5825. RenderState2D.worldAlpha = preAlpha;
  5826. RenderState2D.worldMatrix4 = preMatrix4;
  5827. RenderState2D.worldMatrix.destroy();
  5828. RenderState2D.worldMatrix = preMatrix;
  5829. RenderState2D.worldFilters = preFilters;
  5830. RenderState2D.worldShaderDefines = preWorldShaderDefines;
  5831. return 1;
  5832. }
  5833. releaseRender() {
  5834. if ((--this._ref) < 1) {
  5835. var cache = SubmitCanvas.POOL;
  5836. this._mesh = null;
  5837. cache[cache._length++] = this;
  5838. }
  5839. }
  5840. getRenderType() {
  5841. return SubmitBase.TYPE_CANVAS;
  5842. }
  5843. ;
  5844. }
  5845. SubmitCanvas.POOL = [];
  5846. {
  5847. SubmitCanvas.POOL._length = 0;
  5848. }
  5849. class SubmitTarget {
  5850. constructor() {
  5851. this.blendType = 0;
  5852. this._ref = 1;
  5853. this._key = new SubmitKey();
  5854. }
  5855. renderSubmit() {
  5856. var gl = WebGLContext.mainContext;
  5857. this._mesh.useMesh(gl);
  5858. var target = this.srcRT;
  5859. if (target) {
  5860. this.shaderValue.texture = target._getSource();
  5861. this.shaderValue.upload();
  5862. this.blend();
  5863. Stat.renderBatches++;
  5864. Stat.trianglesFaces += this._numEle / 3;
  5865. gl.drawElements(gl.TRIANGLES, this._numEle, gl.UNSIGNED_SHORT, this._startIdx);
  5866. }
  5867. return 1;
  5868. }
  5869. blend() {
  5870. if (BlendMode.activeBlendFunction !== BlendMode.fns[this.blendType]) {
  5871. var gl = WebGLContext.mainContext;
  5872. gl.enable(gl.BLEND);
  5873. BlendMode.fns[this.blendType](gl);
  5874. BlendMode.activeBlendFunction = BlendMode.fns[this.blendType];
  5875. }
  5876. }
  5877. getRenderType() {
  5878. return 0;
  5879. }
  5880. releaseRender() {
  5881. if ((--this._ref) < 1) {
  5882. var pool = SubmitTarget.POOL;
  5883. pool[pool._length++] = this;
  5884. }
  5885. }
  5886. static create(context, mesh, sv, rt) {
  5887. var o = SubmitTarget.POOL._length ? SubmitTarget.POOL[--SubmitTarget.POOL._length] : new SubmitTarget();
  5888. o._mesh = mesh;
  5889. o.srcRT = rt;
  5890. o._startIdx = mesh.indexNum * CONST3D2D.BYTES_PIDX;
  5891. o._ref = 1;
  5892. o._key.clear();
  5893. o._numEle = 0;
  5894. o.blendType = context._nBlendType;
  5895. o._key.blendShader = o.blendType;
  5896. o.shaderValue = sv;
  5897. o.shaderValue.setValue(context._shader2D);
  5898. if (context._colorFiler) {
  5899. var ft = context._colorFiler;
  5900. sv.defines.add(ft.type);
  5901. sv.colorMat = ft._mat;
  5902. sv.colorAlpha = ft._alpha;
  5903. }
  5904. return o;
  5905. }
  5906. }
  5907. SubmitTarget.POOL = [];
  5908. {
  5909. SubmitTarget.POOL._length = 0;
  5910. }
  5911. class SubmitTexture extends SubmitBase {
  5912. constructor(renderType = SubmitBase.TYPE_2D) {
  5913. super(renderType);
  5914. }
  5915. releaseRender() {
  5916. if ((--this._ref) < 1) {
  5917. SubmitTexture.POOL[SubmitTexture._poolSize++] = this;
  5918. this.shaderValue.release();
  5919. this._mesh = null;
  5920. this._parent && (this._parent.releaseRender(), this._parent = null);
  5921. }
  5922. }
  5923. renderSubmit() {
  5924. if (this._numEle === 0)
  5925. return 1;
  5926. var tex = this.shaderValue.textureHost;
  5927. if (tex) {
  5928. var source = tex ? tex._getSource() : null;
  5929. if (!source)
  5930. return 1;
  5931. }
  5932. var gl = WebGLContext.mainContext;
  5933. this._mesh.useMesh(gl);
  5934. var lastSubmit = SubmitBase.preRender;
  5935. var prekey = SubmitBase.preRender._key;
  5936. if (this._key.blendShader === 0 && (this._key.submitType === prekey.submitType && this._key.blendShader === prekey.blendShader) && BaseShader.activeShader &&
  5937. SubmitBase.preRender.clipInfoID == this.clipInfoID &&
  5938. lastSubmit.shaderValue.defines._value === this.shaderValue.defines._value &&
  5939. (this.shaderValue.defines._value & ShaderDefines2D.NOOPTMASK) == 0) {
  5940. BaseShader.activeShader.uploadTexture2D(source);
  5941. }
  5942. else {
  5943. if (BlendMode.activeBlendFunction !== this._blendFn) {
  5944. WebGLContext.setBlend(gl, true);
  5945. this._blendFn(gl);
  5946. BlendMode.activeBlendFunction = this._blendFn;
  5947. }
  5948. this.shaderValue.texture = source;
  5949. this.shaderValue.upload();
  5950. }
  5951. gl.drawElements(gl.TRIANGLES, this._numEle, gl.UNSIGNED_SHORT, this._startIdx);
  5952. Stat.renderBatches++;
  5953. Stat.trianglesFaces += this._numEle / 3;
  5954. return 1;
  5955. }
  5956. static create(context, mesh, sv) {
  5957. var o = SubmitTexture._poolSize ? SubmitTexture.POOL[--SubmitTexture._poolSize] : new SubmitTexture(SubmitBase.TYPE_TEXTURE);
  5958. o._mesh = mesh;
  5959. o._key.clear();
  5960. o._key.submitType = SubmitBase.KEY_DRAWTEXTURE;
  5961. o._ref = 1;
  5962. o._startIdx = mesh.indexNum * CONST3D2D.BYTES_PIDX;
  5963. o._numEle = 0;
  5964. var blendType = context._nBlendType;
  5965. o._key.blendShader = blendType;
  5966. o._blendFn = context._targets ? BlendMode.targetFns[blendType] : BlendMode.fns[blendType];
  5967. o.shaderValue = sv;
  5968. if (context._colorFiler) {
  5969. var ft = context._colorFiler;
  5970. sv.defines.add(ft.type);
  5971. sv.colorMat = ft._mat;
  5972. sv.colorAlpha = ft._alpha;
  5973. }
  5974. return o;
  5975. }
  5976. }
  5977. SubmitTexture._poolSize = 0;
  5978. SubmitTexture.POOL = [];
  5979. class CharSubmitCache {
  5980. constructor() {
  5981. this._data = [];
  5982. this._ndata = 0;
  5983. this._clipid = -1;
  5984. this._clipMatrix = new Matrix();
  5985. this._enbale = false;
  5986. }
  5987. clear() {
  5988. this._tex = null;
  5989. this._imgId = -1;
  5990. this._ndata = 0;
  5991. this._enbale = false;
  5992. this._colorFiler = null;
  5993. }
  5994. destroy() {
  5995. this.clear();
  5996. this._data.length = 0;
  5997. this._data = null;
  5998. }
  5999. add(ctx, tex, imgid, pos, uv, color) {
  6000. if (this._ndata > 0 && (this._tex != tex || this._imgId != imgid ||
  6001. (this._clipid >= 0 && this._clipid != ctx._clipInfoID))) {
  6002. this.submit(ctx);
  6003. }
  6004. this._clipid = ctx._clipInfoID;
  6005. ctx._globalClipMatrix.copyTo(this._clipMatrix);
  6006. this._tex = tex;
  6007. this._imgId = imgid;
  6008. this._colorFiler = ctx._colorFiler;
  6009. this._data[this._ndata] = pos;
  6010. this._data[this._ndata + 1] = uv;
  6011. this._data[this._ndata + 2] = color;
  6012. this._ndata += 3;
  6013. }
  6014. getPos() {
  6015. if (CharSubmitCache.__nPosPool == 0)
  6016. return new Array(8);
  6017. return CharSubmitCache.__posPool[--CharSubmitCache.__nPosPool];
  6018. }
  6019. enable(value, ctx) {
  6020. if (value === this._enbale)
  6021. return;
  6022. this._enbale = value;
  6023. this._enbale || this.submit(ctx);
  6024. }
  6025. submit(ctx) {
  6026. var n = this._ndata;
  6027. if (!n)
  6028. return;
  6029. var _mesh = ctx._mesh;
  6030. var colorFiler = ctx._colorFiler;
  6031. ctx._colorFiler = this._colorFiler;
  6032. var submit = SubmitTexture.create(ctx, _mesh, Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  6033. ctx._submits[ctx._submits._length++] = ctx._curSubmit = submit;
  6034. submit.shaderValue.textureHost = this._tex;
  6035. submit._key.other = this._imgId;
  6036. ctx._colorFiler = colorFiler;
  6037. ctx._copyClipInfo(submit, this._clipMatrix);
  6038. submit.clipInfoID = this._clipid;
  6039. for (var i = 0; i < n; i += 3) {
  6040. _mesh.addQuad(this._data[i], this._data[i + 1], this._data[i + 2], true);
  6041. CharSubmitCache.__posPool[CharSubmitCache.__nPosPool++] = this._data[i];
  6042. }
  6043. n /= 3;
  6044. submit._numEle += n * 6;
  6045. _mesh.indexNum += n * 6;
  6046. _mesh.vertNum += n * 4;
  6047. ctx._drawCount += n;
  6048. this._ndata = 0;
  6049. if (RenderInfo.loopCount % 100 == 0)
  6050. this._data.length = 0;
  6051. }
  6052. }
  6053. CharSubmitCache.__posPool = [];
  6054. CharSubmitCache.__nPosPool = 0;
  6055. class AtlasGrid {
  6056. constructor(width = 0, height = 0, id = 0) {
  6057. this.atlasID = 0;
  6058. this._width = 0;
  6059. this._height = 0;
  6060. this._texCount = 0;
  6061. this._rowInfo = null;
  6062. this._cells = null;
  6063. this._used = 0;
  6064. this._cells = null;
  6065. this._rowInfo = null;
  6066. this.atlasID = id;
  6067. this._init(width, height);
  6068. }
  6069. addRect(type, width, height, pt) {
  6070. if (!this._get(width, height, pt))
  6071. return false;
  6072. this._fill(pt.x, pt.y, width, height, type);
  6073. this._texCount++;
  6074. return true;
  6075. }
  6076. _release() {
  6077. this._cells = null;
  6078. this._rowInfo = null;
  6079. }
  6080. _init(width, height) {
  6081. this._width = width;
  6082. this._height = height;
  6083. this._release();
  6084. if (this._width == 0)
  6085. return false;
  6086. this._cells = new Uint8Array(this._width * this._height * 3);
  6087. this._rowInfo = new Uint8Array(this._height);
  6088. this._used = 0;
  6089. this._clear();
  6090. return true;
  6091. }
  6092. _get(width, height, pt) {
  6093. if (width > this._width || height > this._height) {
  6094. return false;
  6095. }
  6096. var rx = -1;
  6097. var ry = -1;
  6098. var nWidth = this._width;
  6099. var nHeight = this._height;
  6100. var pCellBox = this._cells;
  6101. for (var y = 0; y < nHeight; y++) {
  6102. if (this._rowInfo[y] < width)
  6103. continue;
  6104. for (var x = 0; x < nWidth;) {
  6105. var tm = (y * nWidth + x) * 3;
  6106. if (pCellBox[tm] != 0 || pCellBox[tm + 1] < width || pCellBox[tm + 2] < height) {
  6107. x += pCellBox[tm + 1];
  6108. continue;
  6109. }
  6110. rx = x;
  6111. ry = y;
  6112. for (var xx = 0; xx < width; xx++) {
  6113. if (pCellBox[3 * xx + tm + 2] < height) {
  6114. rx = -1;
  6115. break;
  6116. }
  6117. }
  6118. if (rx < 0) {
  6119. x += pCellBox[tm + 1];
  6120. continue;
  6121. }
  6122. pt.x = rx;
  6123. pt.y = ry;
  6124. return true;
  6125. }
  6126. }
  6127. return false;
  6128. }
  6129. _fill(x, y, w, h, type) {
  6130. var nWidth = this._width;
  6131. var nHeghit = this._height;
  6132. this._check((x + w) <= nWidth && (y + h) <= nHeghit);
  6133. for (var yy = y; yy < (h + y); ++yy) {
  6134. this._check(this._rowInfo[yy] >= w);
  6135. this._rowInfo[yy] -= w;
  6136. for (var xx = 0; xx < w; xx++) {
  6137. var tm = (x + yy * nWidth + xx) * 3;
  6138. this._check(this._cells[tm] == 0);
  6139. this._cells[tm] = type;
  6140. this._cells[tm + 1] = w;
  6141. this._cells[tm + 2] = h;
  6142. }
  6143. }
  6144. if (x > 0) {
  6145. for (yy = 0; yy < h; ++yy) {
  6146. var s = 0;
  6147. for (xx = x - 1; xx >= 0; --xx, ++s) {
  6148. if (this._cells[((y + yy) * nWidth + xx) * 3] != 0)
  6149. break;
  6150. }
  6151. for (xx = s; xx > 0; --xx) {
  6152. this._cells[((y + yy) * nWidth + x - xx) * 3 + 1] = xx;
  6153. this._check(xx > 0);
  6154. }
  6155. }
  6156. }
  6157. if (y > 0) {
  6158. for (xx = x; xx < (x + w); ++xx) {
  6159. s = 0;
  6160. for (yy = y - 1; yy >= 0; --yy, s++) {
  6161. if (this._cells[(xx + yy * nWidth) * 3] != 0)
  6162. break;
  6163. }
  6164. for (yy = s; yy > 0; --yy) {
  6165. this._cells[(xx + (y - yy) * nWidth) * 3 + 2] = yy;
  6166. this._check(yy > 0);
  6167. }
  6168. }
  6169. }
  6170. this._used += (w * h) / (this._width * this._height);
  6171. }
  6172. _check(ret) {
  6173. if (ret == false) {
  6174. console.log("xtexMerger 错误啦");
  6175. }
  6176. }
  6177. _clear() {
  6178. this._texCount = 0;
  6179. for (var y = 0; y < this._height; y++) {
  6180. this._rowInfo[y] = this._width;
  6181. }
  6182. for (var i = 0; i < this._height; i++) {
  6183. for (var j = 0; j < this._width; j++) {
  6184. var tm = (i * this._width + j) * 3;
  6185. this._cells[tm] = 0;
  6186. this._cells[tm + 1] = this._width - j;
  6187. this._cells[tm + 2] = this._width - i;
  6188. }
  6189. }
  6190. }
  6191. }
  6192. class TextTexture extends Resource {
  6193. constructor(textureW, textureH) {
  6194. super();
  6195. this._texW = 0;
  6196. this._texH = 0;
  6197. this.__destroyed = false;
  6198. this._discardTm = 0;
  6199. this.genID = 0;
  6200. this.bitmap = { id: 0, _glTexture: null };
  6201. this.curUsedCovRate = 0;
  6202. this.curUsedCovRateAtlas = 0;
  6203. this.lastTouchTm = 0;
  6204. this.ri = null;
  6205. this._texW = textureW || TextTexture.gTextRender.atlasWidth;
  6206. this._texH = textureH || TextTexture.gTextRender.atlasWidth;
  6207. this.bitmap.id = this.id;
  6208. this.lock = true;
  6209. }
  6210. recreateResource() {
  6211. if (this._source)
  6212. return;
  6213. var gl = LayaGL.instance;
  6214. var glTex = this._source = gl.createTexture();
  6215. this.bitmap._glTexture = glTex;
  6216. WebGLContext.bindTexture(gl, gl.TEXTURE_2D, glTex);
  6217. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this._texW, this._texH, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
  6218. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  6219. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  6220. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  6221. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  6222. if (TextTexture.gTextRender.debugUV) {
  6223. this.fillWhite();
  6224. }
  6225. }
  6226. addChar(data, x, y, uv = null) {
  6227. if (TextTexture.gTextRender.isWan1Wan) {
  6228. return this.addCharCanvas(data, x, y, uv);
  6229. }
  6230. !this._source && this.recreateResource();
  6231. var gl = LayaGL.instance;
  6232. WebGLContext.bindTexture(gl, gl.TEXTURE_2D, this._source);
  6233. !ILaya.Render.isConchApp && gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
  6234. var dt = data.data;
  6235. if (data.data instanceof Uint8ClampedArray)
  6236. dt = new Uint8Array(dt.buffer);
  6237. gl.texSubImage2D(gl.TEXTURE_2D, 0, x, y, data.width, data.height, gl.RGBA, gl.UNSIGNED_BYTE, dt);
  6238. !ILaya.Render.isConchApp && gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
  6239. var u0;
  6240. var v0;
  6241. var u1;
  6242. var v1;
  6243. if (ILaya.Render.isConchApp) {
  6244. u0 = x / this._texW;
  6245. v0 = y / this._texH;
  6246. u1 = (x + data.width) / this._texW;
  6247. v1 = (y + data.height) / this._texH;
  6248. }
  6249. else {
  6250. u0 = (x + 1) / this._texW;
  6251. v0 = (y) / this._texH;
  6252. u1 = (x + data.width - 1) / this._texW;
  6253. v1 = (y + data.height - 1) / this._texH;
  6254. }
  6255. uv = uv || new Array(8);
  6256. uv[0] = u0, uv[1] = v0;
  6257. uv[2] = u1, uv[3] = v0;
  6258. uv[4] = u1, uv[5] = v1;
  6259. uv[6] = u0, uv[7] = v1;
  6260. return uv;
  6261. }
  6262. addCharCanvas(canv, x, y, uv = null) {
  6263. !this._source && this.recreateResource();
  6264. var gl = LayaGL.instance;
  6265. WebGLContext.bindTexture(gl, gl.TEXTURE_2D, this._source);
  6266. !ILaya.Render.isConchApp && gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
  6267. gl.texSubImage2D(gl.TEXTURE_2D, 0, x, y, gl.RGBA, gl.UNSIGNED_BYTE, canv);
  6268. !ILaya.Render.isConchApp && gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
  6269. var u0;
  6270. var v0;
  6271. var u1;
  6272. var v1;
  6273. if (ILaya.Render.isConchApp) {
  6274. u0 = x / this._texW;
  6275. v0 = y / this._texH;
  6276. u1 = (x + canv.width) / this._texW;
  6277. v1 = (y + canv.height) / this._texH;
  6278. }
  6279. else {
  6280. u0 = (x + 1) / this._texW;
  6281. v0 = (y + 1) / this._texH;
  6282. u1 = (x + canv.width - 1) / this._texW;
  6283. v1 = (y + canv.height - 1) / this._texH;
  6284. }
  6285. uv = uv || new Array(8);
  6286. uv[0] = u0, uv[1] = v0;
  6287. uv[2] = u1, uv[3] = v0;
  6288. uv[4] = u1, uv[5] = v1;
  6289. uv[6] = u0, uv[7] = v1;
  6290. return uv;
  6291. }
  6292. fillWhite() {
  6293. !this._source && this.recreateResource();
  6294. var gl = LayaGL.instance;
  6295. var dt = new Uint8Array(this._texW * this._texH * 4);
  6296. dt.fill(0xff);
  6297. gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, this._texW, this._texH, gl.RGBA, gl.UNSIGNED_BYTE, dt);
  6298. }
  6299. discard() {
  6300. if (this._texW != TextTexture.gTextRender.atlasWidth || this._texH != TextTexture.gTextRender.atlasWidth) {
  6301. this.destroy();
  6302. return;
  6303. }
  6304. this.genID++;
  6305. if (TextTexture.poolLen >= TextTexture.pool.length) {
  6306. TextTexture.pool = TextTexture.pool.concat(new Array(10));
  6307. }
  6308. this._discardTm = RenderInfo.loopStTm;
  6309. TextTexture.pool[TextTexture.poolLen++] = this;
  6310. }
  6311. static getTextTexture(w, h) {
  6312. if (w != TextTexture.gTextRender.atlasWidth || w != TextTexture.gTextRender.atlasWidth)
  6313. return new TextTexture(w, h);
  6314. if (TextTexture.poolLen > 0) {
  6315. var ret = TextTexture.pool[--TextTexture.poolLen];
  6316. if (TextTexture.poolLen > 0)
  6317. TextTexture.clean();
  6318. return ret;
  6319. }
  6320. return new TextTexture(w, h);
  6321. }
  6322. destroy() {
  6323. this.__destroyed = true;
  6324. var gl = LayaGL.instance;
  6325. this._source && gl.deleteTexture(this._source);
  6326. this._source = null;
  6327. }
  6328. static clean() {
  6329. var curtm = RenderInfo.loopStTm;
  6330. if (TextTexture.cleanTm === 0)
  6331. TextTexture.cleanTm = curtm;
  6332. if (curtm - TextTexture.cleanTm >= TextTexture.gTextRender.checkCleanTextureDt) {
  6333. for (var i = 0; i < TextTexture.poolLen; i++) {
  6334. var p = TextTexture.pool[i];
  6335. if (curtm - p._discardTm >= TextTexture.gTextRender.destroyUnusedTextureDt) {
  6336. p.destroy();
  6337. TextTexture.pool[i] = TextTexture.pool[TextTexture.poolLen - 1];
  6338. TextTexture.poolLen--;
  6339. i--;
  6340. }
  6341. }
  6342. TextTexture.cleanTm = curtm;
  6343. }
  6344. }
  6345. touchRect(ri, curloop) {
  6346. if (this.lastTouchTm != curloop) {
  6347. this.curUsedCovRate = 0;
  6348. this.curUsedCovRateAtlas = 0;
  6349. this.lastTouchTm = curloop;
  6350. }
  6351. var texw2 = TextTexture.gTextRender.atlasWidth * TextTexture.gTextRender.atlasWidth;
  6352. var gridw2 = ILaya.TextAtlas.atlasGridW * ILaya.TextAtlas.atlasGridW;
  6353. this.curUsedCovRate += (ri.bmpWidth * ri.bmpHeight) / texw2;
  6354. this.curUsedCovRateAtlas += (Math.ceil(ri.bmpWidth / ILaya.TextAtlas.atlasGridW) * Math.ceil(ri.bmpHeight / ILaya.TextAtlas.atlasGridW)) / (texw2 / gridw2);
  6355. }
  6356. get texture() {
  6357. return this;
  6358. }
  6359. _getSource() {
  6360. return this._source;
  6361. }
  6362. drawOnScreen(x, y) {
  6363. }
  6364. }
  6365. TextTexture.gTextRender = null;
  6366. TextTexture.pool = new Array(10);
  6367. TextTexture.poolLen = 0;
  6368. TextTexture.cleanTm = 0;
  6369. class TextAtlas {
  6370. constructor() {
  6371. this.texWidth = 1024;
  6372. this.texHeight = 1024;
  6373. this.texture = null;
  6374. this.charMaps = {};
  6375. this.texHeight = this.texWidth = ILaya.TextRender.atlasWidth;
  6376. this.texture = TextTexture.getTextTexture(this.texWidth, this.texHeight);
  6377. if (this.texWidth / TextAtlas.atlasGridW > 256) {
  6378. TextAtlas.atlasGridW = Math.ceil(this.texWidth / 256);
  6379. }
  6380. this.atlasgrid = new AtlasGrid(this.texWidth / TextAtlas.atlasGridW, this.texHeight / TextAtlas.atlasGridW, this.texture.id);
  6381. }
  6382. setProtecteDist(d) {
  6383. }
  6384. getAEmpty(w, h, pt) {
  6385. var find = this.atlasgrid.addRect(1, Math.ceil(w / TextAtlas.atlasGridW), Math.ceil(h / TextAtlas.atlasGridW), pt);
  6386. if (find) {
  6387. pt.x *= TextAtlas.atlasGridW;
  6388. pt.y *= TextAtlas.atlasGridW;
  6389. }
  6390. return find;
  6391. }
  6392. get usedRate() {
  6393. return this.atlasgrid._used;
  6394. }
  6395. destroy() {
  6396. for (var k in this.charMaps) {
  6397. var ri = this.charMaps[k];
  6398. ri.deleted = true;
  6399. }
  6400. this.texture.discard();
  6401. }
  6402. printDebugInfo() {
  6403. }
  6404. }
  6405. TextAtlas.atlasGridW = 16;
  6406. class Event {
  6407. setTo(type, currentTarget, target) {
  6408. this.type = type;
  6409. this.currentTarget = currentTarget;
  6410. this.target = target;
  6411. return this;
  6412. }
  6413. stopPropagation() {
  6414. this._stoped = true;
  6415. }
  6416. get touches() {
  6417. if (!this.nativeEvent)
  6418. return null;
  6419. var arr = this.nativeEvent.touches;
  6420. if (arr) {
  6421. var stage = ILaya.stage;
  6422. for (var i = 0, n = arr.length; i < n; i++) {
  6423. var e = arr[i];
  6424. var point = Point.TEMP;
  6425. point.setTo(e.clientX, e.clientY);
  6426. stage._canvasTransform.invertTransformPoint(point);
  6427. stage.transform.invertTransformPoint(point);
  6428. e.stageX = point.x;
  6429. e.stageY = point.y;
  6430. }
  6431. }
  6432. return arr;
  6433. }
  6434. get altKey() {
  6435. return this.nativeEvent.altKey;
  6436. }
  6437. get ctrlKey() {
  6438. return this.nativeEvent.ctrlKey;
  6439. }
  6440. get shiftKey() {
  6441. return this.nativeEvent.shiftKey;
  6442. }
  6443. get charCode() {
  6444. return this.nativeEvent.charCode;
  6445. }
  6446. get keyLocation() {
  6447. return this.nativeEvent.location || this.nativeEvent.keyLocation;
  6448. }
  6449. get stageX() {
  6450. return ILaya.stage.mouseX;
  6451. }
  6452. get stageY() {
  6453. return ILaya.stage.mouseY;
  6454. }
  6455. }
  6456. Event.EMPTY = new Event();
  6457. Event.MOUSE_DOWN = "mousedown";
  6458. Event.MOUSE_UP = "mouseup";
  6459. Event.CLICK = "click";
  6460. Event.RIGHT_MOUSE_DOWN = "rightmousedown";
  6461. Event.RIGHT_MOUSE_UP = "rightmouseup";
  6462. Event.RIGHT_CLICK = "rightclick";
  6463. Event.MOUSE_MOVE = "mousemove";
  6464. Event.MOUSE_OVER = "mouseover";
  6465. Event.MOUSE_OUT = "mouseout";
  6466. Event.MOUSE_WHEEL = "mousewheel";
  6467. Event.ROLL_OVER = "mouseover";
  6468. Event.ROLL_OUT = "mouseout";
  6469. Event.DOUBLE_CLICK = "doubleclick";
  6470. Event.CHANGE = "change";
  6471. Event.CHANGED = "changed";
  6472. Event.RESIZE = "resize";
  6473. Event.ADDED = "added";
  6474. Event.REMOVED = "removed";
  6475. Event.DISPLAY = "display";
  6476. Event.UNDISPLAY = "undisplay";
  6477. Event.ERROR = "error";
  6478. Event.COMPLETE = "complete";
  6479. Event.LOADED = "loaded";
  6480. Event.READY = "ready";
  6481. Event.PROGRESS = "progress";
  6482. Event.INPUT = "input";
  6483. Event.RENDER = "render";
  6484. Event.OPEN = "open";
  6485. Event.MESSAGE = "message";
  6486. Event.CLOSE = "close";
  6487. Event.KEY_DOWN = "keydown";
  6488. Event.KEY_PRESS = "keypress";
  6489. Event.KEY_UP = "keyup";
  6490. Event.FRAME = "enterframe";
  6491. Event.DRAG_START = "dragstart";
  6492. Event.DRAG_MOVE = "dragmove";
  6493. Event.DRAG_END = "dragend";
  6494. Event.ENTER = "enter";
  6495. Event.SELECT = "select";
  6496. Event.BLUR = "blur";
  6497. Event.FOCUS = "focus";
  6498. Event.VISIBILITY_CHANGE = "visibilitychange";
  6499. Event.FOCUS_CHANGE = "focuschange";
  6500. Event.PLAYED = "played";
  6501. Event.PAUSED = "paused";
  6502. Event.STOPPED = "stopped";
  6503. Event.START = "start";
  6504. Event.END = "end";
  6505. Event.COMPONENT_ADDED = "componentadded";
  6506. Event.COMPONENT_REMOVED = "componentremoved";
  6507. Event.RELEASED = "released";
  6508. Event.LINK = "link";
  6509. Event.LABEL = "label";
  6510. Event.FULL_SCREEN_CHANGE = "fullscreenchange";
  6511. Event.DEVICE_LOST = "devicelost";
  6512. Event.TRANSFORM_CHANGED = "transformchanged";
  6513. Event.ANIMATION_CHANGED = "animationchanged";
  6514. Event.TRAIL_FILTER_CHANGE = "trailfilterchange";
  6515. Event.TRIGGER_ENTER = "triggerenter";
  6516. Event.TRIGGER_STAY = "triggerstay";
  6517. Event.TRIGGER_EXIT = "triggerexit";
  6518. class Texture extends EventDispatcher {
  6519. constructor(bitmap = null, uv = null, sourceWidth = 0, sourceHeight = 0) {
  6520. super();
  6521. this.uvrect = [0, 0, 1, 1];
  6522. this._destroyed = false;
  6523. this._referenceCount = 0;
  6524. this.$_GID = 0;
  6525. this.offsetX = 0;
  6526. this.offsetY = 0;
  6527. this._w = 0;
  6528. this._h = 0;
  6529. this.sourceWidth = 0;
  6530. this.sourceHeight = 0;
  6531. this.url = null;
  6532. this.scaleRate = 1;
  6533. this.setTo(bitmap, uv, sourceWidth, sourceHeight);
  6534. }
  6535. static moveUV(offsetX, offsetY, uv) {
  6536. for (var i = 0; i < 8; i += 2) {
  6537. uv[i] += offsetX;
  6538. uv[i + 1] += offsetY;
  6539. }
  6540. return uv;
  6541. }
  6542. static create(source, x, y, width, height, offsetX = 0, offsetY = 0, sourceWidth = 0, sourceHeight = 0) {
  6543. return Texture._create(source, x, y, width, height, offsetX, offsetY, sourceWidth, sourceHeight);
  6544. }
  6545. static _create(source, x, y, width, height, offsetX = 0, offsetY = 0, sourceWidth = 0, sourceHeight = 0, outTexture = null) {
  6546. var btex = source instanceof Texture;
  6547. var uv = btex ? source.uv : Texture.DEF_UV;
  6548. var bitmap = btex ? source.bitmap : source;
  6549. if (bitmap.width && (x + width) > bitmap.width)
  6550. width = bitmap.width - x;
  6551. if (bitmap.height && (y + height) > bitmap.height)
  6552. height = bitmap.height - y;
  6553. var tex;
  6554. if (outTexture) {
  6555. tex = outTexture;
  6556. tex.setTo(bitmap, null, sourceWidth || width, sourceHeight || height);
  6557. }
  6558. else {
  6559. tex = new Texture(bitmap, null, sourceWidth || width, sourceHeight || height);
  6560. }
  6561. tex.width = width;
  6562. tex.height = height;
  6563. tex.offsetX = offsetX;
  6564. tex.offsetY = offsetY;
  6565. var dwidth = 1 / bitmap.width;
  6566. var dheight = 1 / bitmap.height;
  6567. x *= dwidth;
  6568. y *= dheight;
  6569. width *= dwidth;
  6570. height *= dheight;
  6571. var u1 = tex.uv[0], v1 = tex.uv[1], u2 = tex.uv[4], v2 = tex.uv[5];
  6572. var inAltasUVWidth = (u2 - u1), inAltasUVHeight = (v2 - v1);
  6573. var oriUV = Texture.moveUV(uv[0], uv[1], [x, y, x + width, y, x + width, y + height, x, y + height]);
  6574. tex.uv = new Float32Array([u1 + oriUV[0] * inAltasUVWidth, v1 + oriUV[1] * inAltasUVHeight,
  6575. u2 - (1 - oriUV[2]) * inAltasUVWidth, v1 + oriUV[3] * inAltasUVHeight,
  6576. u2 - (1 - oriUV[4]) * inAltasUVWidth, v2 - (1 - oriUV[5]) * inAltasUVHeight,
  6577. u1 + oriUV[6] * inAltasUVWidth, v2 - (1 - oriUV[7]) * inAltasUVHeight]);
  6578. var bitmapScale = bitmap.scaleRate;
  6579. if (bitmapScale && bitmapScale != 1) {
  6580. tex.sourceWidth /= bitmapScale;
  6581. tex.sourceHeight /= bitmapScale;
  6582. tex.width /= bitmapScale;
  6583. tex.height /= bitmapScale;
  6584. tex.scaleRate = bitmapScale;
  6585. }
  6586. else {
  6587. tex.scaleRate = 1;
  6588. }
  6589. return tex;
  6590. }
  6591. static createFromTexture(texture, x, y, width, height) {
  6592. var texScaleRate = texture.scaleRate;
  6593. if (texScaleRate != 1) {
  6594. x *= texScaleRate;
  6595. y *= texScaleRate;
  6596. width *= texScaleRate;
  6597. height *= texScaleRate;
  6598. }
  6599. var rect = Rectangle.TEMP.setTo(x - texture.offsetX, y - texture.offsetY, width, height);
  6600. var result = rect.intersection(Texture._rect1.setTo(0, 0, texture.width, texture.height), Texture._rect2);
  6601. if (result)
  6602. var tex = Texture.create(texture, result.x, result.y, result.width, result.height, result.x - rect.x, result.y - rect.y, width, height);
  6603. else
  6604. return null;
  6605. return tex;
  6606. }
  6607. get uv() {
  6608. return this._uv;
  6609. }
  6610. set uv(value) {
  6611. this.uvrect[0] = Math.min(value[0], value[2], value[4], value[6]);
  6612. this.uvrect[1] = Math.min(value[1], value[3], value[5], value[7]);
  6613. this.uvrect[2] = Math.max(value[0], value[2], value[4], value[6]) - this.uvrect[0];
  6614. this.uvrect[3] = Math.max(value[1], value[3], value[5], value[7]) - this.uvrect[1];
  6615. this._uv = value;
  6616. }
  6617. get width() {
  6618. if (this._w)
  6619. return this._w;
  6620. if (!this.bitmap)
  6621. return 0;
  6622. return (this.uv && this.uv !== Texture.DEF_UV) ? (this.uv[2] - this.uv[0]) * this.bitmap.width : this.bitmap.width;
  6623. }
  6624. set width(value) {
  6625. this._w = value;
  6626. this.sourceWidth || (this.sourceWidth = value);
  6627. }
  6628. get height() {
  6629. if (this._h)
  6630. return this._h;
  6631. if (!this.bitmap)
  6632. return 0;
  6633. return (this.uv && this.uv !== Texture.DEF_UV) ? (this.uv[5] - this.uv[1]) * this.bitmap.height : this.bitmap.height;
  6634. }
  6635. set height(value) {
  6636. this._h = value;
  6637. this.sourceHeight || (this.sourceHeight = value);
  6638. }
  6639. get bitmap() {
  6640. return this._bitmap;
  6641. }
  6642. set bitmap(value) {
  6643. this._bitmap && this._bitmap._removeReference(this._referenceCount);
  6644. this._bitmap = value;
  6645. value && (value._addReference(this._referenceCount));
  6646. }
  6647. get destroyed() {
  6648. return this._destroyed;
  6649. }
  6650. _addReference() {
  6651. this._bitmap && this._bitmap._addReference();
  6652. this._referenceCount++;
  6653. }
  6654. _removeReference() {
  6655. this._bitmap && this._bitmap._removeReference();
  6656. this._referenceCount--;
  6657. }
  6658. _getSource(cb = null) {
  6659. if (this._destroyed || !this._bitmap)
  6660. return null;
  6661. this.recoverBitmap(cb);
  6662. return this._bitmap.destroyed ? null : this.bitmap._getSource();
  6663. }
  6664. _onLoaded(complete, context) {
  6665. if (!context) ;
  6666. else if (context == this) ;
  6667. else if (context instanceof Texture) {
  6668. var tex = context;
  6669. Texture._create(context, 0, 0, tex.width, tex.height, 0, 0, tex.sourceWidth, tex.sourceHeight, this);
  6670. }
  6671. else {
  6672. this.bitmap = context;
  6673. this.sourceWidth = this._w = context.width;
  6674. this.sourceHeight = this._h = context.height;
  6675. }
  6676. complete && complete.run();
  6677. this.event(Event.READY, this);
  6678. }
  6679. getIsReady() {
  6680. return this._destroyed ? false : (this._bitmap ? true : false);
  6681. }
  6682. setTo(bitmap = null, uv = null, sourceWidth = 0, sourceHeight = 0) {
  6683. this.bitmap = bitmap;
  6684. this.sourceWidth = sourceWidth;
  6685. this.sourceHeight = sourceHeight;
  6686. if (bitmap) {
  6687. this._w = bitmap.width;
  6688. this._h = bitmap.height;
  6689. this.sourceWidth = this.sourceWidth || bitmap.width;
  6690. this.sourceHeight = this.sourceHeight || bitmap.height;
  6691. }
  6692. this.uv = uv || Texture.DEF_UV;
  6693. }
  6694. load(url, complete = null) {
  6695. if (!this._destroyed)
  6696. ILaya.loader.load(url, Handler.create(this, this._onLoaded, [complete]), null, "htmlimage", 1, true);
  6697. }
  6698. getTexturePixels(x, y, width, height) {
  6699. var st, dst, i;
  6700. var tex2d = this.bitmap;
  6701. var texw = tex2d.width;
  6702. var texh = tex2d.height;
  6703. if (x + width > texw)
  6704. width -= (x + width) - texw;
  6705. if (y + height > texh)
  6706. height -= (y + height) - texh;
  6707. if (width <= 0 || height <= 0)
  6708. return null;
  6709. var wstride = width * 4;
  6710. var pix = null;
  6711. try {
  6712. pix = tex2d.getPixels();
  6713. }
  6714. catch (e) {
  6715. }
  6716. if (pix) {
  6717. if (x == 0 && y == 0 && width == texw && height == texh)
  6718. return pix;
  6719. var ret = new Uint8Array(width * height * 4);
  6720. wstride = texw * 4;
  6721. st = x * 4;
  6722. dst = (y + height - 1) * wstride + x * 4;
  6723. for (i = height - 1; i >= 0; i--) {
  6724. ret.set(dt.slice(dst, dst + width * 4), st);
  6725. st += wstride;
  6726. dst -= wstride;
  6727. }
  6728. return ret;
  6729. }
  6730. var ctx = new ILaya.Context();
  6731. ctx.size(width, height);
  6732. ctx.asBitmap = true;
  6733. var uv = null;
  6734. if (x != 0 || y != 0 || width != texw || height != texh) {
  6735. uv = this._uv.slice();
  6736. var stu = uv[0];
  6737. var stv = uv[1];
  6738. var uvw = uv[2] - stu;
  6739. var uvh = uv[7] - stv;
  6740. var uk = uvw / texw;
  6741. var vk = uvh / texh;
  6742. uv = [stu + x * uk, stv + y * vk,
  6743. stu + (x + width) * uk, stv + y * vk,
  6744. stu + (x + width) * uk, stv + (y + height) * vk,
  6745. stu + x * uk, stv + (y + height) * vk];
  6746. }
  6747. ctx._drawTextureM(this, 0, 0, width, height, null, 1.0, uv);
  6748. ctx._targets.start();
  6749. ctx.flush();
  6750. ctx._targets.end();
  6751. ctx._targets.restore();
  6752. var dt = ctx._targets.getData(0, 0, width, height);
  6753. ctx.destroy();
  6754. ret = new Uint8Array(width * height * 4);
  6755. st = 0;
  6756. dst = (height - 1) * wstride;
  6757. for (i = height - 1; i >= 0; i--) {
  6758. ret.set(dt.slice(dst, dst + wstride), st);
  6759. st += wstride;
  6760. dst -= wstride;
  6761. }
  6762. return ret;
  6763. }
  6764. getPixels(x, y, width, height) {
  6765. if (window.conch) {
  6766. return this._nativeObj.getImageData(x, y, width, height);
  6767. }
  6768. else {
  6769. return this.getTexturePixels(x, y, width, height);
  6770. }
  6771. }
  6772. recoverBitmap(onok = null) {
  6773. var url = this._bitmap.url;
  6774. if (!this._destroyed && (!this._bitmap || this._bitmap.destroyed) && url) {
  6775. ILaya.loader.load(url, Handler.create(this, function (bit) {
  6776. this.bitmap = bit;
  6777. onok && onok();
  6778. }), null, "htmlimage", 1, true);
  6779. }
  6780. }
  6781. disposeBitmap() {
  6782. if (!this._destroyed && this._bitmap) {
  6783. this._bitmap.destroy();
  6784. }
  6785. }
  6786. destroy(force = false) {
  6787. if (!this._destroyed) {
  6788. this._destroyed = true;
  6789. var bit = this._bitmap;
  6790. if (bit) {
  6791. bit._removeReference(this._referenceCount);
  6792. if (bit.referenceCount === 0 || force)
  6793. bit.destroy();
  6794. bit = null;
  6795. }
  6796. if (this.url && this === ILaya.loader.getRes(this.url))
  6797. ILaya.Loader.clearRes(this.url);
  6798. }
  6799. }
  6800. }
  6801. Texture.DEF_UV = new Float32Array([0, 0, 1.0, 0, 1.0, 1.0, 0, 1.0]);
  6802. Texture.NO_UV = new Float32Array([0, 0, 0, 0, 0, 0, 0, 0]);
  6803. Texture.INV_UV = new Float32Array([0, 1, 1.0, 1, 1.0, 0.0, 0, 0.0]);
  6804. Texture._rect1 = new Rectangle();
  6805. Texture._rect2 = new Rectangle();
  6806. class FontInfo {
  6807. constructor(font) {
  6808. this._font = "14px Arial";
  6809. this._family = "Arial";
  6810. this._size = 14;
  6811. this._italic = false;
  6812. this._bold = false;
  6813. this._id = FontInfo._gfontID++;
  6814. this.setFont(font || this._font);
  6815. }
  6816. static Parse(font) {
  6817. if (font === FontInfo._lastFont) {
  6818. return FontInfo._lastFontInfo;
  6819. }
  6820. var r = FontInfo._cache[font];
  6821. if (!r) {
  6822. r = FontInfo._cache[font] = new FontInfo(font);
  6823. }
  6824. FontInfo._lastFont = font;
  6825. FontInfo._lastFontInfo = r;
  6826. return r;
  6827. }
  6828. setFont(value) {
  6829. this._font = value;
  6830. var _words = value.split(' ');
  6831. var l = _words.length;
  6832. if (l < 2) {
  6833. if (l == 1) {
  6834. if (_words[0].indexOf('px') > 0) {
  6835. this._size = parseInt(_words[0]);
  6836. }
  6837. }
  6838. return;
  6839. }
  6840. var szpos = -1;
  6841. for (var i = 0; i < l; i++) {
  6842. if (_words[i].indexOf('px') > 0 || _words[i].indexOf('pt') > 0) {
  6843. szpos = i;
  6844. this._size = parseInt(_words[i]);
  6845. if (this._size <= 0) {
  6846. console.error('font parse error:' + value);
  6847. this._size = 14;
  6848. }
  6849. break;
  6850. }
  6851. }
  6852. var fpos = szpos + 1;
  6853. var familys = _words[fpos];
  6854. fpos++;
  6855. for (; fpos < l; fpos++) {
  6856. familys += ' ' + _words[fpos];
  6857. }
  6858. this._family = (familys.split(','))[0];
  6859. this._italic = _words.indexOf('italic') >= 0;
  6860. this._bold = _words.indexOf('bold') >= 0;
  6861. }
  6862. }
  6863. FontInfo.EMPTY = new FontInfo(null);
  6864. FontInfo._cache = {};
  6865. FontInfo._gfontID = 0;
  6866. FontInfo._lastFont = '';
  6867. class WordText {
  6868. constructor() {
  6869. this.save = [];
  6870. this.toUpperCase = null;
  6871. this.width = -1;
  6872. this.pageChars = [];
  6873. this.startID = 0;
  6874. this.startIDStroke = 0;
  6875. this.lastGCCnt = 0;
  6876. this.splitRender = false;
  6877. }
  6878. setText(txt) {
  6879. this.changed = true;
  6880. this._text = txt;
  6881. this.width = -1;
  6882. this.cleanCache();
  6883. }
  6884. toString() {
  6885. return this._text;
  6886. }
  6887. get length() {
  6888. return this._text ? this._text.length : 0;
  6889. }
  6890. charCodeAt(i) {
  6891. return this._text ? this._text.charCodeAt(i) : NaN;
  6892. }
  6893. charAt(i) {
  6894. return this._text ? this._text.charAt(i) : null;
  6895. }
  6896. cleanCache() {
  6897. this.pageChars.forEach(function (p) {
  6898. var tex = p.tex;
  6899. var words = p.words;
  6900. if (p.words.length == 1 && tex && tex.ri) {
  6901. tex.destroy();
  6902. }
  6903. });
  6904. this.pageChars = [];
  6905. this.startID = 0;
  6906. }
  6907. }
  6908. class CharRenderInfo {
  6909. constructor() {
  6910. this.char = '';
  6911. this.deleted = false;
  6912. this.uv = new Array(8);
  6913. this.pos = 0;
  6914. this.orix = 0;
  6915. this.oriy = 0;
  6916. this.touchTick = 0;
  6917. this.isSpace = false;
  6918. }
  6919. touch() {
  6920. var curLoop = RenderInfo.loopCount;
  6921. if (this.touchTick != curLoop) {
  6922. this.tex.touchRect(this, curLoop);
  6923. }
  6924. this.touchTick = curLoop;
  6925. }
  6926. }
  6927. class ICharRender {
  6928. constructor() {
  6929. this.fontsz = 16;
  6930. }
  6931. getWidth(font, str) { return 0; }
  6932. scale(sx, sy) {
  6933. }
  6934. get canvasWidth() {
  6935. return 0;
  6936. }
  6937. set canvasWidth(w) {
  6938. }
  6939. getCharBmp(char, font, lineWidth, colStr, strokeColStr, size, margin_left, margin_top, margin_right, margin_bottom, rect = null) {
  6940. return null;
  6941. }
  6942. }
  6943. class Browser {
  6944. static __init__() {
  6945. var Laya = window.Laya || ILaya.Laya;
  6946. if (Browser._window)
  6947. return Browser._window;
  6948. var win = Browser._window = window;
  6949. var doc = Browser._document = win.document;
  6950. var u = Browser.userAgent = win.navigator.userAgent;
  6951. if (u.indexOf('AlipayMiniGame') > -1 && "my" in Browser.window) {
  6952. window.aliPayMiniGame(Laya, Laya);
  6953. if (!Laya["ALIMiniAdapter"]) {
  6954. console.error("请先添加阿里小游戏适配库");
  6955. }
  6956. else {
  6957. Laya["ALIMiniAdapter"].enable();
  6958. }
  6959. }
  6960. if (u.indexOf('OPPO') == -1 && u.indexOf("MiniGame") > -1 && "wx" in Browser.window) {
  6961. if ("qq" in Browser.window) {
  6962. window.qqMiniGame(Laya, Laya);
  6963. if (!Laya["QQMiniAdapter"]) {
  6964. console.error("请引入手机QQ小游戏的适配库:https://ldc2.layabox.com/doc/?nav=zh-ts-5-0-0");
  6965. }
  6966. else {
  6967. Laya["QQMiniAdapter"].enable();
  6968. }
  6969. }
  6970. else {
  6971. window.wxMiniGame(Laya, Laya);
  6972. if (!Laya["MiniAdpter"]) {
  6973. console.error("请先添加小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?nav=zh-ts-5-0-0");
  6974. }
  6975. else {
  6976. Laya["MiniAdpter"].enable();
  6977. }
  6978. }
  6979. }
  6980. if (u.indexOf("MiniGame") > -1 && "qq" in Browser.window) {
  6981. window.qqMiniGame(Laya, Laya);
  6982. if (!Laya["QQMiniAdapter"]) {
  6983. console.error("请先添加小游戏适配库,详细教程");
  6984. }
  6985. else {
  6986. Laya["QQMiniAdapter"].enable();
  6987. }
  6988. }
  6989. if (u.indexOf("SwanGame") > -1) {
  6990. window.bdMiniGame(Laya, Laya);
  6991. if (!Laya["BMiniAdapter"]) {
  6992. console.error("请先添加百度小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?nav=zh-ts-5-0-0");
  6993. }
  6994. else {
  6995. Laya["BMiniAdapter"].enable();
  6996. }
  6997. }
  6998. if (u.indexOf('QuickGame') > -1) {
  6999. window.miMiniGame(Laya, Laya);
  7000. if (!Laya["KGMiniAdapter"]) {
  7001. console.error("请先添加小米小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?nav=zh-ts-5-0-0");
  7002. }
  7003. else {
  7004. Laya["KGMiniAdapter"].enable();
  7005. }
  7006. }
  7007. if (u.indexOf('OPPO') > -1 && u.indexOf('MiniGame') > -1) {
  7008. window.qgMiniGame(Laya, Laya);
  7009. if (!Laya["QGMiniAdapter"]) {
  7010. console.error("请先添加OPPO小游戏适配库");
  7011. }
  7012. else {
  7013. Laya["QGMiniAdapter"].enable();
  7014. }
  7015. }
  7016. if (u.indexOf('VVGame') > -1) {
  7017. window.vvMiniGame(Laya, Laya);
  7018. if (!Laya["VVMiniAdapter"]) {
  7019. console.error("请先添加VIVO小游戏适配库");
  7020. }
  7021. else {
  7022. Laya["VVMiniAdapter"].enable();
  7023. }
  7024. }
  7025. win.trace = console.log;
  7026. win.requestAnimationFrame = win.requestAnimationFrame || win.webkitRequestAnimationFrame || win.mozRequestAnimationFrame || win.oRequestAnimationFrame || win.msRequestAnimationFrame || function (fun) {
  7027. return win.setTimeout(fun, 1000 / 60);
  7028. };
  7029. var bodyStyle = doc.body.style;
  7030. bodyStyle.margin = 0;
  7031. bodyStyle.overflow = 'hidden';
  7032. bodyStyle['-webkit-user-select'] = 'none';
  7033. bodyStyle['-webkit-tap-highlight-color'] = 'rgba(200,200,200,0)';
  7034. var metas = doc.getElementsByTagName('meta');
  7035. var i = 0, flag = false, content = 'width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no';
  7036. while (i < metas.length) {
  7037. var meta = metas[i];
  7038. if (meta.name == 'viewport') {
  7039. meta.content = content;
  7040. flag = true;
  7041. break;
  7042. }
  7043. i++;
  7044. }
  7045. if (!flag) {
  7046. meta = doc.createElement('meta');
  7047. meta.name = 'viewport', meta.content = content;
  7048. doc.getElementsByTagName('head')[0].appendChild(meta);
  7049. }
  7050. Browser.onMobile = window.isConchApp ? true : u.indexOf("Mobile") > -1;
  7051. Browser.onIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
  7052. Browser.onIPhone = u.indexOf("iPhone") > -1;
  7053. Browser.onMac = u.indexOf("Mac OS X") > -1;
  7054. Browser.onIPad = u.indexOf("iPad") > -1;
  7055. Browser.onAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
  7056. Browser.onWP = u.indexOf("Windows Phone") > -1;
  7057. Browser.onQQBrowser = u.indexOf("QQBrowser") > -1;
  7058. Browser.onMQQBrowser = u.indexOf("MQQBrowser") > -1 || (u.indexOf("Mobile") > -1 && u.indexOf("QQ") > -1);
  7059. Browser.onIE = !!win.ActiveXObject || "ActiveXObject" in win;
  7060. Browser.onWeiXin = u.indexOf('MicroMessenger') > -1;
  7061. Browser.onSafari = u.indexOf("Safari") > -1;
  7062. Browser.onPC = !Browser.onMobile;
  7063. Browser.onMiniGame = u.indexOf('MiniGame') > -1;
  7064. Browser.onBDMiniGame = u.indexOf('SwanGame') > -1;
  7065. Browser.onLayaRuntime = !!Browser.window.conch;
  7066. if (u.indexOf('OPPO') > -1 && u.indexOf('MiniGame') > -1) {
  7067. Browser.onQGMiniGame = true;
  7068. Browser.onMiniGame = false;
  7069. }
  7070. else if ("qq" in Browser.window && u.indexOf('MiniGame') > -1) {
  7071. Browser.onQQMiniGame = true;
  7072. Browser.onMiniGame = false;
  7073. }
  7074. Browser.onVVMiniGame = u.indexOf('VVGame') > -1;
  7075. Browser.onKGMiniGame = u.indexOf('QuickGame') > -1;
  7076. if (u.indexOf('AlipayMiniGame') > -1) {
  7077. Browser.onAlipayMiniGame = true;
  7078. Browser.onMiniGame = false;
  7079. }
  7080. return win;
  7081. }
  7082. static createElement(type) {
  7083. Browser.__init__();
  7084. return Browser._document.createElement(type);
  7085. }
  7086. static getElementById(type) {
  7087. Browser.__init__();
  7088. return Browser._document.getElementById(type);
  7089. }
  7090. static removeElement(ele) {
  7091. if (ele && ele.parentNode)
  7092. ele.parentNode.removeChild(ele);
  7093. }
  7094. static now() {
  7095. return Date.now();
  7096. }
  7097. static get clientWidth() {
  7098. Browser.__init__();
  7099. return Browser._window.innerWidth || Browser._document.body.clientWidth;
  7100. }
  7101. static get clientHeight() {
  7102. Browser.__init__();
  7103. return Browser._window.innerHeight || Browser._document.body.clientHeight || Browser._document.documentElement.clientHeight;
  7104. }
  7105. static get width() {
  7106. Browser.__init__();
  7107. return ((ILaya.stage && ILaya.stage.canvasRotation) ? Browser.clientHeight : Browser.clientWidth) * Browser.pixelRatio;
  7108. }
  7109. static get height() {
  7110. Browser.__init__();
  7111. return ((ILaya.stage && ILaya.stage.canvasRotation) ? Browser.clientWidth : Browser.clientHeight) * Browser.pixelRatio;
  7112. }
  7113. static get pixelRatio() {
  7114. if (Browser._pixelRatio < 0) {
  7115. Browser.__init__();
  7116. if (Browser.userAgent.indexOf("Mozilla/6.0(Linux; Android 6.0; HUAWEI NXT-AL10 Build/HUAWEINXT-AL10)") > -1)
  7117. Browser._pixelRatio = 2;
  7118. else {
  7119. Browser._pixelRatio = (Browser._window.devicePixelRatio || 1);
  7120. if (Browser._pixelRatio < 1)
  7121. Browser._pixelRatio = 1;
  7122. }
  7123. }
  7124. return Browser._pixelRatio;
  7125. }
  7126. static get container() {
  7127. if (!Browser._container) {
  7128. Browser.__init__();
  7129. Browser._container = Browser.createElement("div");
  7130. Browser._container.id = "layaContainer";
  7131. Browser._document.body.appendChild(Browser._container);
  7132. }
  7133. return Browser._container;
  7134. }
  7135. static set container(value) {
  7136. Browser._container = value;
  7137. }
  7138. static get window() {
  7139. return Browser._window || Browser.__init__();
  7140. }
  7141. static get document() {
  7142. Browser.__init__();
  7143. return Browser._document;
  7144. }
  7145. }
  7146. Browser._pixelRatio = -1;
  7147. Browser.mainCanvas = null;
  7148. Browser.hanzi = new RegExp("^[\u4E00-\u9FA5]$");
  7149. Browser.fontMap = [];
  7150. Browser.measureText = function (txt, font) {
  7151. var isChinese = Browser.hanzi.test(txt);
  7152. if (isChinese && Browser.fontMap[font]) {
  7153. return Browser.fontMap[font];
  7154. }
  7155. var ctx = Browser.context;
  7156. ctx.font = font;
  7157. var r = ctx.measureText(txt);
  7158. if (isChinese)
  7159. Browser.fontMap[font] = r;
  7160. return r;
  7161. };
  7162. class CharRender_Canvas extends ICharRender {
  7163. constructor(maxw, maxh, scalefont = true, useImageData = true, showdbg = false) {
  7164. super();
  7165. this.ctx = null;
  7166. this.lastScaleX = 1.0;
  7167. this.lastScaleY = 1.0;
  7168. this.maxTexW = 0;
  7169. this.maxTexH = 0;
  7170. this.scaleFontSize = true;
  7171. this.showDbgInfo = false;
  7172. this.supportImageData = true;
  7173. this.maxTexW = maxw;
  7174. this.maxTexH = maxh;
  7175. this.scaleFontSize = scalefont;
  7176. this.supportImageData = useImageData;
  7177. this.showDbgInfo = showdbg;
  7178. if (!CharRender_Canvas.canvas) {
  7179. CharRender_Canvas.canvas = Browser.createElement('canvas');
  7180. CharRender_Canvas.canvas.width = 1024;
  7181. CharRender_Canvas.canvas.height = 512;
  7182. CharRender_Canvas.canvas.style.left = "-10000px";
  7183. CharRender_Canvas.canvas.style.position = "absolute";
  7184. document.body.appendChild(CharRender_Canvas.canvas);
  7185. this.ctx = CharRender_Canvas.canvas.getContext('2d');
  7186. }
  7187. }
  7188. get canvasWidth() {
  7189. return CharRender_Canvas.canvas.width;
  7190. }
  7191. set canvasWidth(w) {
  7192. if (CharRender_Canvas.canvas.width == w)
  7193. return;
  7194. CharRender_Canvas.canvas.width = w;
  7195. if (w > 2048) {
  7196. console.warn("画文字设置的宽度太大,超过2048了");
  7197. }
  7198. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  7199. this.ctx.scale(this.lastScaleX, this.lastScaleY);
  7200. }
  7201. getWidth(font, str) {
  7202. if (!this.ctx)
  7203. return 0;
  7204. if (this.ctx._lastFont != font) {
  7205. this.ctx.font = font;
  7206. this.ctx._lastFont = font;
  7207. }
  7208. return this.ctx.measureText(str).width;
  7209. }
  7210. scale(sx, sy) {
  7211. if (!this.supportImageData) {
  7212. this.lastScaleX = sx;
  7213. this.lastScaleY = sy;
  7214. return;
  7215. }
  7216. if (this.lastScaleX != sx || this.lastScaleY != sy) {
  7217. this.ctx.setTransform(sx, 0, 0, sy, 0, 0);
  7218. this.lastScaleX = sx;
  7219. this.lastScaleY = sy;
  7220. }
  7221. }
  7222. getCharBmp(char, font, lineWidth, colStr, strokeColStr, cri, margin_left, margin_top, margin_right, margin_bottom, rect = null) {
  7223. if (!this.supportImageData)
  7224. return this.getCharCanvas(char, font, lineWidth, colStr, strokeColStr, cri, margin_left, margin_top, margin_right, margin_bottom);
  7225. var ctx = this.ctx;
  7226. var sz = this.fontsz;
  7227. if (ctx.font != font) {
  7228. ctx.font = font;
  7229. ctx._lastFont = font;
  7230. }
  7231. cri.width = ctx.measureText(char).width;
  7232. var w = cri.width * this.lastScaleX;
  7233. var h = cri.height * this.lastScaleY;
  7234. w += (margin_left + margin_right) * this.lastScaleX;
  7235. h += (margin_top + margin_bottom) * this.lastScaleY;
  7236. w = Math.ceil(w);
  7237. h = Math.ceil(h);
  7238. w = Math.min(w, CharRender_Canvas.canvas.width);
  7239. h = Math.min(h, CharRender_Canvas.canvas.height);
  7240. var clearW = w + lineWidth * 2 + 1;
  7241. var clearH = h + lineWidth * 2 + 1;
  7242. if (rect) {
  7243. clearW = Math.max(clearW, rect[0] + rect[2] + 1);
  7244. clearH = Math.max(clearH, rect[1] + rect[3] + 1);
  7245. }
  7246. ctx.clearRect(0, 0, clearW, clearH);
  7247. ctx.save();
  7248. ctx.textBaseline = "middle";
  7249. if (lineWidth > 0) {
  7250. ctx.strokeStyle = strokeColStr;
  7251. ctx.lineWidth = lineWidth;
  7252. ctx.strokeText(char, margin_left, margin_top + sz / 2);
  7253. }
  7254. if (colStr) {
  7255. ctx.fillStyle = colStr;
  7256. ctx.fillText(char, margin_left, margin_top + sz / 2);
  7257. }
  7258. if (this.showDbgInfo) {
  7259. ctx.strokeStyle = '#ff0000';
  7260. ctx.strokeRect(1, 1, w - 2, h - 2);
  7261. ctx.strokeStyle = '#00ff00';
  7262. ctx.strokeRect(margin_left, margin_top, cri.width, cri.height);
  7263. }
  7264. if (rect) {
  7265. if (rect[2] == -1)
  7266. rect[2] = Math.ceil((cri.width + lineWidth * 2) * this.lastScaleX);
  7267. }
  7268. var imgdt = rect ? (ctx.getImageData(rect[0], rect[1], rect[2], rect[3])) : (ctx.getImageData(0, 0, w, h));
  7269. ctx.restore();
  7270. cri.bmpWidth = imgdt.width;
  7271. cri.bmpHeight = imgdt.height;
  7272. return imgdt;
  7273. }
  7274. getCharCanvas(char, font, lineWidth, colStr, strokeColStr, cri, margin_left, margin_top, margin_right, margin_bottom) {
  7275. var ctx = this.ctx;
  7276. if (ctx.font != font) {
  7277. ctx.font = font;
  7278. ctx._lastFont = font;
  7279. }
  7280. cri.width = ctx.measureText(char).width;
  7281. var w = cri.width * this.lastScaleX;
  7282. var h = cri.height * this.lastScaleY;
  7283. w += (margin_left + margin_right) * this.lastScaleX;
  7284. h += ((margin_top + margin_bottom) * this.lastScaleY + 1);
  7285. w = Math.min(w, this.maxTexW);
  7286. h = Math.min(h, this.maxTexH);
  7287. CharRender_Canvas.canvas.width = Math.min(w + 1, this.maxTexW);
  7288. CharRender_Canvas.canvas.height = Math.min(h + 1, this.maxTexH);
  7289. ctx.font = font;
  7290. ctx.clearRect(0, 0, w + 1 + lineWidth, h + 1 + lineWidth);
  7291. ctx.setTransform(1, 0, 0, 1, 0, 0);
  7292. ctx.save();
  7293. if (this.scaleFontSize) {
  7294. ctx.scale(this.lastScaleX, this.lastScaleY);
  7295. }
  7296. ctx.translate(margin_left, margin_top);
  7297. ctx.textAlign = "left";
  7298. var sz = this.fontsz;
  7299. ctx.textBaseline = "middle";
  7300. if (lineWidth > 0) {
  7301. ctx.strokeStyle = strokeColStr;
  7302. ctx.fillStyle = colStr;
  7303. ctx.lineWidth = lineWidth;
  7304. if (ctx.fillAndStrokeText) {
  7305. ctx.fillAndStrokeText(char, 0, sz / 2);
  7306. }
  7307. else {
  7308. ctx.strokeText(char, 0, sz / 2);
  7309. ctx.fillText(char, 0, sz / 2);
  7310. }
  7311. }
  7312. else if (colStr) {
  7313. ctx.fillStyle = colStr;
  7314. ctx.fillText(char, 0, sz / 2);
  7315. }
  7316. if (this.showDbgInfo) {
  7317. ctx.strokeStyle = '#ff0000';
  7318. ctx.strokeRect(0, 0, w, h);
  7319. ctx.strokeStyle = '#00ff00';
  7320. ctx.strokeRect(0, 0, cri.width, cri.height);
  7321. }
  7322. ctx.restore();
  7323. cri.bmpWidth = CharRender_Canvas.canvas.width;
  7324. cri.bmpHeight = CharRender_Canvas.canvas.height;
  7325. return CharRender_Canvas.canvas;
  7326. }
  7327. }
  7328. CharRender_Canvas.canvas = null;
  7329. class CharRender_Native extends ICharRender {
  7330. constructor() {
  7331. super();
  7332. this.lastFont = '';
  7333. }
  7334. getWidth(font, str) {
  7335. if (!window.conchTextCanvas)
  7336. return 0;
  7337. window.conchTextCanvas.font = font;
  7338. this.lastFont = font;
  7339. return window.conchTextCanvas.measureText(str).width;
  7340. }
  7341. scale(sx, sy) {
  7342. }
  7343. getCharBmp(char, font, lineWidth, colStr, strokeColStr, size, margin_left, margin_top, margin_right, margin_bottom, rect = null) {
  7344. if (!window.conchTextCanvas)
  7345. return null;
  7346. window.conchTextCanvas.font = font;
  7347. this.lastFont = font;
  7348. var w = size.width = window.conchTextCanvas.measureText(char).width;
  7349. var h = size.height;
  7350. w += (margin_left + margin_right);
  7351. h += (margin_top + margin_bottom);
  7352. var c1 = ColorUtils.create(strokeColStr);
  7353. var nStrokeColor = c1.numColor;
  7354. var c2 = ColorUtils.create(colStr);
  7355. var nTextColor = c2.numColor;
  7356. var textInfo = window.conchTextCanvas.getTextBitmapData(char, nTextColor, lineWidth > 2 ? 2 : lineWidth, nStrokeColor);
  7357. size.bmpWidth = textInfo.width;
  7358. size.bmpHeight = textInfo.height;
  7359. return textInfo;
  7360. }
  7361. }
  7362. class TextRender {
  7363. constructor() {
  7364. this.fontSizeInfo = {};
  7365. this.mapFont = {};
  7366. this.fontID = 0;
  7367. this.mapColor = [];
  7368. this.colorID = 0;
  7369. this.fontScaleX = 1.0;
  7370. this.fontScaleY = 1.0;
  7371. this._curStrPos = 0;
  7372. this.textAtlases = [];
  7373. this.isoTextures = [];
  7374. this.lastFont = null;
  7375. this.fontSizeW = 0;
  7376. this.fontSizeH = 0;
  7377. this.fontSizeOffX = 0;
  7378. this.fontSizeOffY = 0;
  7379. this.renderPerChar = true;
  7380. this.tmpAtlasPos = new Point();
  7381. this.textureMem = 0;
  7382. ILaya.TextAtlas = TextAtlas;
  7383. var bugIOS = false;
  7384. var miniadp = ILaya.Laya['MiniAdpter'];
  7385. if (miniadp && miniadp.systemInfo && miniadp.systemInfo.system) {
  7386. bugIOS = miniadp.systemInfo.system.toLowerCase() === 'ios 10.1.1';
  7387. }
  7388. if (ILaya.Browser.onMiniGame && !bugIOS)
  7389. TextRender.isWan1Wan = true;
  7390. this.charRender = ILaya.Render.isConchApp ? (new CharRender_Native()) : (new CharRender_Canvas(TextRender.atlasWidth, TextRender.atlasWidth, TextRender.scaleFontWithCtx, !TextRender.isWan1Wan, false));
  7391. TextRender.textRenderInst = this;
  7392. ILaya.Laya['textRender'] = this;
  7393. TextRender.atlasWidth2 = TextRender.atlasWidth * TextRender.atlasWidth;
  7394. }
  7395. setFont(font) {
  7396. if (this.lastFont == font)
  7397. return;
  7398. this.lastFont = font;
  7399. var fontsz = this.getFontSizeInfo(font._family);
  7400. var offx = fontsz >> 24;
  7401. var offy = (fontsz >> 16) & 0xff;
  7402. var fw = (fontsz >> 8) & 0xff;
  7403. var fh = fontsz & 0xff;
  7404. var k = font._size / TextRender.standardFontSize;
  7405. this.fontSizeOffX = Math.ceil(offx * k);
  7406. this.fontSizeOffY = Math.ceil(offy * k);
  7407. this.fontSizeW = Math.ceil(fw * k);
  7408. this.fontSizeH = Math.ceil(fh * k);
  7409. if (font._font.indexOf('italic') >= 0) {
  7410. this.fontStr = font._font.replace('italic', '');
  7411. }
  7412. else {
  7413. this.fontStr = font._font;
  7414. }
  7415. }
  7416. getNextChar(str) {
  7417. var len = str.length;
  7418. var start = this._curStrPos;
  7419. if (start >= len)
  7420. return null;
  7421. var i = start;
  7422. var state = 0;
  7423. for (; i < len; i++) {
  7424. var c = str.charCodeAt(i);
  7425. if ((c >>> 11) == 0x1b) {
  7426. if (state == 1)
  7427. break;
  7428. state = 1;
  7429. i++;
  7430. }
  7431. else if (c === 0xfe0e || c === 0xfe0f) ;
  7432. else if (c == 0x200d) {
  7433. state = 2;
  7434. }
  7435. else {
  7436. if (state == 0)
  7437. state = 1;
  7438. else if (state == 1)
  7439. break;
  7440. }
  7441. }
  7442. this._curStrPos = i;
  7443. return str.substring(start, i);
  7444. }
  7445. filltext(ctx, data, x, y, fontStr, color, strokeColor, lineWidth, textAlign, underLine = 0) {
  7446. if (data.length <= 0)
  7447. return;
  7448. var font = FontInfo.Parse(fontStr);
  7449. var nTextAlign = 0;
  7450. switch (textAlign) {
  7451. case 'center':
  7452. nTextAlign = ILaya.Context.ENUM_TEXTALIGN_CENTER;
  7453. break;
  7454. case 'right':
  7455. nTextAlign = ILaya.Context.ENUM_TEXTALIGN_RIGHT;
  7456. break;
  7457. }
  7458. this._fast_filltext(ctx, data, null, x, y, font, color, strokeColor, lineWidth, nTextAlign, underLine);
  7459. }
  7460. fillWords(ctx, data, x, y, fontStr, color, strokeColor, lineWidth) {
  7461. if (!data)
  7462. return;
  7463. if (data.length <= 0)
  7464. return;
  7465. var font = typeof (fontStr) === 'string' ? FontInfo.Parse(fontStr) : fontStr;
  7466. this._fast_filltext(ctx, null, data, x, y, font, color, strokeColor, lineWidth, 0, 0);
  7467. }
  7468. _fast_filltext(ctx, data, htmlchars, x, y, font, color, strokeColor, lineWidth, textAlign, underLine = 0) {
  7469. if (data && data.length < 1)
  7470. return;
  7471. if (htmlchars && htmlchars.length < 1)
  7472. return;
  7473. if (lineWidth < 0)
  7474. lineWidth = 0;
  7475. this.setFont(font);
  7476. this.fontScaleX = this.fontScaleY = 1.0;
  7477. if (!ILaya.Render.isConchApp && TextRender.scaleFontWithCtx) {
  7478. var sx = 1;
  7479. var sy = 1;
  7480. if (ILaya.Render.isConchApp) {
  7481. sx = ctx._curMat.getScaleX();
  7482. sy = ctx._curMat.getScaleY();
  7483. }
  7484. else {
  7485. sx = ctx.getMatScaleX();
  7486. sy = ctx.getMatScaleY();
  7487. }
  7488. if (sx < 1e-4 || sy < 1e-1)
  7489. return;
  7490. if (sx > 1)
  7491. this.fontScaleX = sx;
  7492. if (sy > 1)
  7493. this.fontScaleY = sy;
  7494. }
  7495. font._italic && (ctx._italicDeg = 13);
  7496. var wt = data;
  7497. var isWT = !htmlchars && (data instanceof WordText);
  7498. var str = data;
  7499. var isHtmlChar = !!htmlchars;
  7500. var sameTexData = isWT ? wt.pageChars : [];
  7501. var strWidth = 0;
  7502. if (isWT) {
  7503. str = wt._text;
  7504. strWidth = wt.width;
  7505. if (strWidth < 0) {
  7506. strWidth = wt.width = this.charRender.getWidth(this.fontStr, str);
  7507. }
  7508. }
  7509. else {
  7510. strWidth = str ? this.charRender.getWidth(this.fontStr, str) : 0;
  7511. }
  7512. switch (textAlign) {
  7513. case ILaya.Context.ENUM_TEXTALIGN_CENTER:
  7514. x -= strWidth / 2;
  7515. break;
  7516. case ILaya.Context.ENUM_TEXTALIGN_RIGHT:
  7517. x -= strWidth;
  7518. break;
  7519. }
  7520. if (wt && sameTexData) {
  7521. if (this.hasFreedText(sameTexData)) {
  7522. sameTexData = wt.pageChars = [];
  7523. }
  7524. }
  7525. var ri = null;
  7526. var splitTex = this.renderPerChar = (!isWT) || TextRender.forceSplitRender || isHtmlChar || (isWT && wt.splitRender);
  7527. if (!sameTexData || sameTexData.length < 1) {
  7528. if (splitTex) {
  7529. var stx = 0;
  7530. var sty = 0;
  7531. this._curStrPos = 0;
  7532. var curstr;
  7533. while (true) {
  7534. if (htmlchars) {
  7535. var chc = htmlchars[this._curStrPos++];
  7536. if (chc) {
  7537. curstr = chc.char;
  7538. stx = chc.x;
  7539. sty = chc.y;
  7540. }
  7541. else {
  7542. curstr = null;
  7543. }
  7544. }
  7545. else {
  7546. curstr = this.getNextChar(str);
  7547. }
  7548. if (!curstr)
  7549. break;
  7550. ri = this.getCharRenderInfo(curstr, font, color, strokeColor, lineWidth, false);
  7551. if (!ri) {
  7552. break;
  7553. }
  7554. if (ri.isSpace) ;
  7555. else {
  7556. var add = sameTexData[ri.tex.id];
  7557. if (!add) {
  7558. var o1 = { texgen: ri.tex.genID, tex: ri.tex, words: [] };
  7559. sameTexData[ri.tex.id] = o1;
  7560. add = o1.words;
  7561. }
  7562. else {
  7563. add = add.words;
  7564. }
  7565. if (ILaya.Render.isConchApp) {
  7566. add.push({ ri: ri, x: stx, y: sty, w: ri.bmpWidth / this.fontScaleX, h: ri.bmpHeight / this.fontScaleY });
  7567. }
  7568. else {
  7569. add.push({ ri: ri, x: stx + 1 / this.fontScaleX, y: sty, w: (ri.bmpWidth - 2) / this.fontScaleX, h: (ri.bmpHeight - 1) / this.fontScaleY });
  7570. }
  7571. stx += ri.width;
  7572. }
  7573. }
  7574. }
  7575. else {
  7576. var isotex = TextRender.noAtlas || strWidth * this.fontScaleX > TextRender.atlasWidth;
  7577. ri = this.getCharRenderInfo(str, font, color, strokeColor, lineWidth, isotex);
  7578. if (ILaya.Render.isConchApp) {
  7579. sameTexData[0] = { texgen: ri.tex.genID, tex: ri.tex, words: [{ ri: ri, x: 0, y: 0, w: ri.bmpWidth / this.fontScaleX, h: ri.bmpHeight / this.fontScaleY }] };
  7580. }
  7581. else {
  7582. sameTexData[0] = { texgen: ri.tex.genID, tex: ri.tex, words: [{ ri: ri, x: 1 / this.fontScaleX, y: 0 / this.fontScaleY, w: (ri.bmpWidth - 2) / this.fontScaleX, h: (ri.bmpHeight - 1) / this.fontScaleY }] };
  7583. }
  7584. }
  7585. }
  7586. this._drawResortedWords(ctx, x, y, sameTexData);
  7587. ctx._italicDeg = 0;
  7588. }
  7589. _drawResortedWords(ctx, startx, starty, samePagesData) {
  7590. var isLastRender = ctx._charSubmitCache ? ctx._charSubmitCache._enbale : false;
  7591. var mat = ctx._curMat;
  7592. var slen = samePagesData.length;
  7593. for (var id = 0; id < slen; id++) {
  7594. var dt = samePagesData[id];
  7595. if (!dt)
  7596. continue;
  7597. var pri = dt.words;
  7598. var pisz = pri.length;
  7599. if (pisz <= 0)
  7600. continue;
  7601. var tex = samePagesData[id].tex;
  7602. for (var j = 0; j < pisz; j++) {
  7603. var riSaved = pri[j];
  7604. var ri = riSaved.ri;
  7605. if (ri.isSpace)
  7606. continue;
  7607. ri.touch();
  7608. ctx.drawTexAlign = true;
  7609. if (ILaya.Render.isConchApp) {
  7610. ctx._drawTextureM(tex.texture, startx + riSaved.x - ri.orix, starty + riSaved.y - ri.oriy, riSaved.w, riSaved.h, null, 1.0, ri.uv);
  7611. }
  7612. else {
  7613. let t = tex;
  7614. ctx._inner_drawTexture(t.texture, t.id, startx + riSaved.x - ri.orix, starty + riSaved.y - ri.oriy, riSaved.w, riSaved.h, mat, ri.uv, 1.0, isLastRender);
  7615. }
  7616. if (ctx.touches) {
  7617. ctx.touches.push(ri);
  7618. }
  7619. }
  7620. }
  7621. }
  7622. hasFreedText(txts) {
  7623. var sz = txts.length;
  7624. for (var i = 0; i < sz; i++) {
  7625. var pri = txts[i];
  7626. if (!pri)
  7627. continue;
  7628. var tex = pri.tex;
  7629. if (tex.__destroyed || tex.genID != pri.texgen) {
  7630. return true;
  7631. }
  7632. }
  7633. return false;
  7634. }
  7635. getCharRenderInfo(str, font, color, strokeColor, lineWidth, isoTexture = false) {
  7636. var fid = this.mapFont[font._family];
  7637. if (fid == undefined) {
  7638. this.mapFont[font._family] = fid = this.fontID++;
  7639. }
  7640. var key = str + '_' + fid + '_' + font._size + '_' + color;
  7641. if (lineWidth > 0)
  7642. key += '_' + strokeColor + lineWidth;
  7643. if (font._bold)
  7644. key += 'P';
  7645. if (this.fontScaleX != 1 || this.fontScaleY != 1) {
  7646. key += (this.fontScaleX * 20 | 0) + '_' + (this.fontScaleY * 20 | 0);
  7647. }
  7648. var i = 0;
  7649. var sz = this.textAtlases.length;
  7650. var ri;
  7651. var atlas;
  7652. if (!isoTexture) {
  7653. for (i = 0; i < sz; i++) {
  7654. atlas = this.textAtlases[i];
  7655. ri = atlas.charMaps[key];
  7656. if (ri) {
  7657. ri.touch();
  7658. return ri;
  7659. }
  7660. }
  7661. }
  7662. ri = new CharRenderInfo();
  7663. this.charRender.scale(this.fontScaleX, this.fontScaleY);
  7664. ri.char = str;
  7665. ri.height = font._size;
  7666. var margin = ILaya.Render.isConchApp ? 0 : (font._size / 3 | 0);
  7667. var imgdt = null;
  7668. if (!lineWidth) {
  7669. lineWidth = 0;
  7670. }
  7671. var w1 = Math.ceil((this.charRender.getWidth(this.fontStr, str) + 2 * lineWidth) * this.fontScaleX);
  7672. if (w1 > this.charRender.canvasWidth) {
  7673. this.charRender.canvasWidth = Math.min(2048, w1 + margin * 2);
  7674. }
  7675. if (isoTexture) {
  7676. this.charRender.fontsz = font._size;
  7677. imgdt = this.charRender.getCharBmp(str, this.fontStr, lineWidth, color, strokeColor, ri, margin, margin, margin, margin, null);
  7678. if (imgdt) {
  7679. var tex = TextTexture.getTextTexture(imgdt.width, imgdt.height);
  7680. tex.addChar(imgdt, 0, 0, ri.uv);
  7681. ri.tex = tex;
  7682. ri.orix = margin;
  7683. ri.oriy = margin;
  7684. tex.ri = ri;
  7685. this.isoTextures.push(tex);
  7686. }
  7687. }
  7688. else {
  7689. var len = str.length;
  7690. var lineExt = lineWidth * 1;
  7691. var fw = Math.ceil((this.fontSizeW + lineExt * 2) * this.fontScaleX);
  7692. var fh = Math.ceil((this.fontSizeH + lineExt * 2) * this.fontScaleY);
  7693. TextRender.imgdtRect[0] = ((margin - this.fontSizeOffX - lineExt) * this.fontScaleX) | 0;
  7694. TextRender.imgdtRect[1] = ((margin - this.fontSizeOffY - lineExt) * this.fontScaleY) | 0;
  7695. if (this.renderPerChar || len == 1) {
  7696. TextRender.imgdtRect[2] = Math.max(w1, fw);
  7697. TextRender.imgdtRect[3] = Math.max(w1, fh);
  7698. }
  7699. else {
  7700. TextRender.imgdtRect[2] = -1;
  7701. TextRender.imgdtRect[3] = fh;
  7702. }
  7703. this.charRender.fontsz = font._size;
  7704. imgdt = this.charRender.getCharBmp(str, this.fontStr, lineWidth, color, strokeColor, ri, margin, margin, margin, margin, TextRender.imgdtRect);
  7705. if (imgdt) {
  7706. atlas = this.addBmpData(imgdt, ri);
  7707. if (TextRender.isWan1Wan) {
  7708. ri.orix = margin;
  7709. ri.oriy = margin;
  7710. }
  7711. else {
  7712. ri.orix = (this.fontSizeOffX + lineExt);
  7713. ri.oriy = (this.fontSizeOffY + lineExt);
  7714. }
  7715. atlas.charMaps[key] = ri;
  7716. }
  7717. }
  7718. return ri;
  7719. }
  7720. addBmpData(data, ri) {
  7721. var w = data.width;
  7722. var h = data.height;
  7723. var sz = this.textAtlases.length;
  7724. var atlas;
  7725. var find = false;
  7726. for (var i = 0; i < sz; i++) {
  7727. atlas = this.textAtlases[i];
  7728. find = atlas.getAEmpty(w, h, this.tmpAtlasPos);
  7729. if (find) {
  7730. break;
  7731. }
  7732. }
  7733. if (!find) {
  7734. atlas = new TextAtlas();
  7735. this.textAtlases.push(atlas);
  7736. find = atlas.getAEmpty(w, h, this.tmpAtlasPos);
  7737. if (!find) {
  7738. throw 'err1';
  7739. }
  7740. this.cleanAtlases();
  7741. }
  7742. if (find) {
  7743. atlas.texture.addChar(data, this.tmpAtlasPos.x, this.tmpAtlasPos.y, ri.uv);
  7744. ri.tex = atlas.texture;
  7745. }
  7746. return atlas;
  7747. }
  7748. GC() {
  7749. var i = 0;
  7750. var sz = this.textAtlases.length;
  7751. var dt = 0;
  7752. var destroyDt = TextRender.destroyAtlasDt;
  7753. var totalUsedRate = 0;
  7754. var totalUsedRateAtlas = 0;
  7755. var curloop = RenderInfo.loopCount;
  7756. var maxWasteRateID = -1;
  7757. var maxWasteRate = 0;
  7758. var tex = null;
  7759. var curatlas = null;
  7760. for (; i < sz; i++) {
  7761. curatlas = this.textAtlases[i];
  7762. tex = curatlas.texture;
  7763. if (tex) {
  7764. totalUsedRate += tex.curUsedCovRate;
  7765. totalUsedRateAtlas += tex.curUsedCovRateAtlas;
  7766. var waste = curatlas.usedRate - tex.curUsedCovRateAtlas;
  7767. if (maxWasteRate < waste) {
  7768. maxWasteRate = waste;
  7769. maxWasteRateID = i;
  7770. }
  7771. }
  7772. dt = curloop - curatlas.texture.lastTouchTm;
  7773. if (dt > destroyDt) {
  7774. TextRender.showLog && console.log('TextRender GC delete atlas ' + tex ? curatlas.texture.id : 'unk');
  7775. curatlas.destroy();
  7776. this.textAtlases[i] = this.textAtlases[sz - 1];
  7777. sz--;
  7778. i--;
  7779. maxWasteRateID = -1;
  7780. }
  7781. }
  7782. this.textAtlases.length = sz;
  7783. sz = this.isoTextures.length;
  7784. for (i = 0; i < sz; i++) {
  7785. tex = this.isoTextures[i];
  7786. dt = curloop - tex.lastTouchTm;
  7787. if (dt > TextRender.destroyUnusedTextureDt) {
  7788. tex.ri.deleted = true;
  7789. tex.ri.tex = null;
  7790. tex.destroy();
  7791. this.isoTextures[i] = this.isoTextures[sz - 1];
  7792. sz--;
  7793. i--;
  7794. }
  7795. }
  7796. this.isoTextures.length = sz;
  7797. var needGC = this.textAtlases.length > 1 && this.textAtlases.length - totalUsedRateAtlas >= 2;
  7798. if (TextRender.atlasWidth * TextRender.atlasWidth * 4 * this.textAtlases.length > TextRender.cleanMem || needGC || TextRender.simClean) {
  7799. TextRender.simClean = false;
  7800. TextRender.showLog && console.log('清理使用率低的贴图。总使用率:', totalUsedRateAtlas, ':', this.textAtlases.length, '最差贴图:' + maxWasteRateID);
  7801. if (maxWasteRateID >= 0) {
  7802. curatlas = this.textAtlases[maxWasteRateID];
  7803. curatlas.destroy();
  7804. this.textAtlases[maxWasteRateID] = this.textAtlases[this.textAtlases.length - 1];
  7805. this.textAtlases.length = this.textAtlases.length - 1;
  7806. }
  7807. }
  7808. TextTexture.clean();
  7809. }
  7810. cleanAtlases() {
  7811. }
  7812. getCharBmp(c) {
  7813. }
  7814. checkBmpLine(data, l, sx, ex) {
  7815. if (this.bmpData32.buffer != data.data.buffer) {
  7816. this.bmpData32 = new Uint32Array(data.data.buffer);
  7817. }
  7818. var stpos = data.width * l + sx;
  7819. for (var x = sx; x < ex; x++) {
  7820. if (this.bmpData32[stpos++] != 0)
  7821. return true;
  7822. }
  7823. return false;
  7824. }
  7825. updateBbx(data, curbbx, onlyH = false) {
  7826. var w = data.width;
  7827. var h = data.height;
  7828. var x = 0;
  7829. var sy = curbbx[1];
  7830. var ey = 0;
  7831. var y = sy;
  7832. if (this.checkBmpLine(data, sy, 0, w)) {
  7833. while (true) {
  7834. y = (sy + ey) / 2 | 0;
  7835. if (y + 1 >= sy) {
  7836. curbbx[1] = y;
  7837. break;
  7838. }
  7839. if (this.checkBmpLine(data, y, 0, w)) {
  7840. sy = y;
  7841. }
  7842. else {
  7843. ey = y;
  7844. }
  7845. }
  7846. }
  7847. if (curbbx[3] > h)
  7848. curbbx[3] = h;
  7849. else {
  7850. y = sy = curbbx[3];
  7851. ey = h;
  7852. if (this.checkBmpLine(data, sy, 0, w)) {
  7853. while (true) {
  7854. y = (sy + ey) / 2 | 0;
  7855. if (y - 1 <= sy) {
  7856. curbbx[3] = y;
  7857. break;
  7858. }
  7859. if (this.checkBmpLine(data, y, 0, w)) {
  7860. sy = y;
  7861. }
  7862. else {
  7863. ey = y;
  7864. }
  7865. }
  7866. }
  7867. }
  7868. if (onlyH)
  7869. return;
  7870. var minx = curbbx[0];
  7871. var stpos = w * curbbx[1];
  7872. for (y = curbbx[1]; y < curbbx[3]; y++) {
  7873. for (x = 0; x < minx; x++) {
  7874. if (this.bmpData32[stpos + x] != 0) {
  7875. minx = x;
  7876. break;
  7877. }
  7878. }
  7879. stpos += w;
  7880. }
  7881. curbbx[0] = minx;
  7882. var maxx = curbbx[2];
  7883. stpos = w * curbbx[1];
  7884. for (y = curbbx[1]; y < curbbx[3]; y++) {
  7885. for (x = maxx; x < w; x++) {
  7886. if (this.bmpData32[stpos + x] != 0) {
  7887. maxx = x;
  7888. break;
  7889. }
  7890. }
  7891. stpos += w;
  7892. }
  7893. curbbx[2] = maxx;
  7894. }
  7895. getFontSizeInfo(font) {
  7896. var finfo = this.fontSizeInfo[font];
  7897. if (finfo != undefined)
  7898. return finfo;
  7899. var fontstr = 'bold ' + TextRender.standardFontSize + 'px ' + font;
  7900. if (TextRender.isWan1Wan) {
  7901. this.fontSizeW = this.charRender.getWidth(fontstr, '有') * 1.5;
  7902. this.fontSizeH = TextRender.standardFontSize * 1.5;
  7903. var szinfo = this.fontSizeW << 8 | this.fontSizeH;
  7904. this.fontSizeInfo[font] = szinfo;
  7905. return szinfo;
  7906. }
  7907. TextRender.pixelBBX[0] = TextRender.standardFontSize / 2;
  7908. TextRender.pixelBBX[1] = TextRender.standardFontSize / 2;
  7909. TextRender.pixelBBX[2] = TextRender.standardFontSize;
  7910. TextRender.pixelBBX[3] = TextRender.standardFontSize;
  7911. var orix = 16;
  7912. var oriy = 16;
  7913. var marginr = 16;
  7914. var marginb = 16;
  7915. this.charRender.scale(1, 1);
  7916. TextRender.tmpRI.height = TextRender.standardFontSize;
  7917. this.charRender.fontsz = TextRender.standardFontSize;
  7918. var bmpdt = this.charRender.getCharBmp('g', fontstr, 0, 'red', null, TextRender.tmpRI, orix, oriy, marginr, marginb);
  7919. if (ILaya.Render.isConchApp) {
  7920. bmpdt.data = new Uint8ClampedArray(bmpdt.data);
  7921. }
  7922. this.bmpData32 = new Uint32Array(bmpdt.data.buffer);
  7923. this.updateBbx(bmpdt, TextRender.pixelBBX, false);
  7924. bmpdt = this.charRender.getCharBmp('有', fontstr, 0, 'red', null, TextRender.tmpRI, oriy, oriy, marginr, marginb);
  7925. if (ILaya.Render.isConchApp) {
  7926. bmpdt.data = new Uint8ClampedArray(bmpdt.data);
  7927. }
  7928. this.bmpData32 = new Uint32Array(bmpdt.data.buffer);
  7929. if (TextRender.pixelBBX[2] < orix + TextRender.tmpRI.width)
  7930. TextRender.pixelBBX[2] = orix + TextRender.tmpRI.width;
  7931. this.updateBbx(bmpdt, TextRender.pixelBBX, false);
  7932. if (ILaya.Render.isConchApp) {
  7933. orix = 0;
  7934. oriy = 0;
  7935. }
  7936. var xoff = Math.max(orix - TextRender.pixelBBX[0], 0);
  7937. var yoff = Math.max(oriy - TextRender.pixelBBX[1], 0);
  7938. var bbxw = TextRender.pixelBBX[2] - TextRender.pixelBBX[0];
  7939. var bbxh = TextRender.pixelBBX[3] - TextRender.pixelBBX[1];
  7940. var sizeinfo = xoff << 24 | yoff << 16 | bbxw << 8 | bbxh;
  7941. this.fontSizeInfo[font] = sizeinfo;
  7942. return sizeinfo;
  7943. }
  7944. printDbgInfo() {
  7945. console.log('图集个数:' + this.textAtlases.length + ',每个图集大小:' + TextRender.atlasWidth + 'x' + TextRender.atlasWidth, ' 用canvas:', TextRender.isWan1Wan);
  7946. console.log('图集占用空间:' + (TextRender.atlasWidth * TextRender.atlasWidth * 4 / 1024 / 1024 * this.textAtlases.length) + 'M');
  7947. console.log('缓存用到的字体:');
  7948. for (var f in this.mapFont) {
  7949. var fontsz = this.getFontSizeInfo(f);
  7950. var offx = fontsz >> 24;
  7951. var offy = (fontsz >> 16) & 0xff;
  7952. var fw = (fontsz >> 8) & 0xff;
  7953. var fh = fontsz & 0xff;
  7954. console.log(' ' + f, ' off:', offx, offy, ' size:', fw, fh);
  7955. }
  7956. var num = 0;
  7957. console.log('缓存数据:');
  7958. var totalUsedRate = 0;
  7959. var totalUsedRateAtlas = 0;
  7960. this.textAtlases.forEach(function (a) {
  7961. var id = a.texture.id;
  7962. var dt = RenderInfo.loopCount - a.texture.lastTouchTm;
  7963. var dtstr = dt > 0 ? ('' + dt + '帧以前') : '当前帧';
  7964. totalUsedRate += a.texture.curUsedCovRate;
  7965. totalUsedRateAtlas += a.texture.curUsedCovRateAtlas;
  7966. console.log('--图集(id:' + id + ',当前使用率:' + (a.texture.curUsedCovRate * 1000 | 0) + '‰', '当前图集使用率:', (a.texture.curUsedCovRateAtlas * 100 | 0) + '%', '图集使用率:', (a.usedRate * 100 | 0), '%, 使用于:' + dtstr + ')--:');
  7967. for (var k in a.charMaps) {
  7968. var ri = a.charMaps[k];
  7969. console.log(' off:', ri.orix, ri.oriy, ' bmp宽高:', ri.bmpWidth, ri.bmpHeight, '无效:', ri.deleted, 'touchdt:', (RenderInfo.loopCount - ri.touchTick), '位置:', ri.uv[0] * TextRender.atlasWidth | 0, ri.uv[1] * TextRender.atlasWidth | 0, '字符:', ri.char, 'key:', k);
  7970. num++;
  7971. }
  7972. });
  7973. console.log('独立贴图文字(' + this.isoTextures.length + '个):');
  7974. this.isoTextures.forEach(function (tex) {
  7975. console.log(' size:', tex._texW, tex._texH, 'touch间隔:', (RenderInfo.loopCount - tex.lastTouchTm), 'char:', tex.ri.char);
  7976. });
  7977. console.log('总缓存:', num, '总使用率:', totalUsedRate, '总当前图集使用率:', totalUsedRateAtlas);
  7978. }
  7979. showAtlas(n, bgcolor, x, y, w, h) {
  7980. if (!this.textAtlases[n]) {
  7981. console.log('没有这个图集');
  7982. return null;
  7983. }
  7984. var sp = new ILaya.Sprite();
  7985. var texttex = this.textAtlases[n].texture;
  7986. var texture = {
  7987. width: TextRender.atlasWidth,
  7988. height: TextRender.atlasWidth,
  7989. sourceWidth: TextRender.atlasWidth,
  7990. sourceHeight: TextRender.atlasWidth,
  7991. offsetX: 0,
  7992. offsetY: 0,
  7993. getIsReady: function () { return true; },
  7994. _addReference: function () { },
  7995. _removeReference: function () { },
  7996. _getSource: function () { return texttex._getSource(); },
  7997. bitmap: { id: texttex.id },
  7998. _uv: Texture.DEF_UV
  7999. };
  8000. sp.size = function (w, h) {
  8001. this.width = w;
  8002. this.height = h;
  8003. sp.graphics.clear();
  8004. sp.graphics.drawRect(0, 0, sp.width, sp.height, bgcolor);
  8005. sp.graphics.drawTexture(texture, 0, 0, sp.width, sp.height);
  8006. return this;
  8007. };
  8008. sp.graphics.drawRect(0, 0, w, h, bgcolor);
  8009. sp.graphics.drawTexture(texture, 0, 0, w, h);
  8010. sp.pos(x, y);
  8011. ILaya.stage.addChild(sp);
  8012. return sp;
  8013. }
  8014. filltext_native(ctx, data, htmlchars, x, y, fontStr, color, strokeColor, lineWidth, textAlign, underLine = 0) {
  8015. if (data && data.length <= 0)
  8016. return;
  8017. if (htmlchars && htmlchars.length < 1)
  8018. return;
  8019. var font = FontInfo.Parse(fontStr);
  8020. var nTextAlign = 0;
  8021. switch (textAlign) {
  8022. case 'center':
  8023. nTextAlign = ILaya.Context.ENUM_TEXTALIGN_CENTER;
  8024. break;
  8025. case 'right':
  8026. nTextAlign = ILaya.Context.ENUM_TEXTALIGN_RIGHT;
  8027. break;
  8028. }
  8029. return this._fast_filltext(ctx, data, htmlchars, x, y, font, color, strokeColor, lineWidth, nTextAlign, underLine);
  8030. }
  8031. }
  8032. TextRender.useOldCharBook = false;
  8033. TextRender.atlasWidth = 2048;
  8034. TextRender.noAtlas = false;
  8035. TextRender.forceSplitRender = false;
  8036. TextRender.forceWholeRender = false;
  8037. TextRender.scaleFontWithCtx = true;
  8038. TextRender.standardFontSize = 32;
  8039. TextRender.destroyAtlasDt = 10;
  8040. TextRender.checkCleanTextureDt = 2000;
  8041. TextRender.destroyUnusedTextureDt = 3000;
  8042. TextRender.cleanMem = 100 * 1024 * 1024;
  8043. TextRender.isWan1Wan = false;
  8044. TextRender.showLog = false;
  8045. TextRender.debugUV = false;
  8046. TextRender.atlasWidth2 = 2048 * 2048;
  8047. TextRender.tmpRI = new CharRenderInfo();
  8048. TextRender.pixelBBX = [0, 0, 0, 0];
  8049. TextRender.imgdtRect = [0, 0, 0, 0];
  8050. TextRender.simClean = false;
  8051. TextTexture.gTextRender = TextRender;
  8052. class Context {
  8053. constructor() {
  8054. this._tmpMatrix = new Matrix();
  8055. this._drawTexToDrawTri_Vert = new Float32Array(8);
  8056. this._drawTexToDrawTri_Index = new Uint16Array([0, 1, 2, 0, 2, 3]);
  8057. this._tempUV = new Float32Array(8);
  8058. this._drawTriUseAbsMatrix = false;
  8059. this._id = ++Context._COUNT;
  8060. this._other = null;
  8061. this._renderNextSubmitIndex = 0;
  8062. this._path = null;
  8063. this._drawCount = 1;
  8064. this._width = Context._MAXSIZE;
  8065. this._height = Context._MAXSIZE;
  8066. this._renderCount = 0;
  8067. this._submits = null;
  8068. this._curSubmit = null;
  8069. this._submitKey = new SubmitKey();
  8070. this._mesh = null;
  8071. this._pathMesh = null;
  8072. this._triangleMesh = null;
  8073. this.meshlist = [];
  8074. this._transedPoints = new Array(8);
  8075. this._temp4Points = new Array(8);
  8076. this._clipRect = Context.MAXCLIPRECT;
  8077. this._globalClipMatrix = new Matrix(Context._MAXSIZE, 0, 0, Context._MAXSIZE, 0, 0);
  8078. this._clipInCache = false;
  8079. this._clipInfoID = 0;
  8080. this._clipID_Gen = 0;
  8081. this._lastMatScaleX = 1.0;
  8082. this._lastMatScaleY = 1.0;
  8083. this._lastMat_a = 1.0;
  8084. this._lastMat_b = 0.0;
  8085. this._lastMat_c = 0.0;
  8086. this._lastMat_d = 1.0;
  8087. this._nBlendType = 0;
  8088. this._save = null;
  8089. this._targets = null;
  8090. this._charSubmitCache = null;
  8091. this._saveMark = null;
  8092. this._shader2D = new Shader2D();
  8093. this.sprite = null;
  8094. this._italicDeg = 0;
  8095. this._lastTex = null;
  8096. this._fillColor = 0;
  8097. this._flushCnt = 0;
  8098. this.defTexture = null;
  8099. this._colorFiler = null;
  8100. this.drawTexAlign = false;
  8101. this._incache = false;
  8102. this.isMain = false;
  8103. Context._contextcount++;
  8104. Context._textRender = Context._textRender || new TextRender();
  8105. if (!this.defTexture) {
  8106. var defTex2d = new Texture2D(2, 2);
  8107. defTex2d.setPixels(new Uint8Array(16));
  8108. defTex2d.lock = true;
  8109. this.defTexture = new Texture(defTex2d);
  8110. }
  8111. this._lastTex = this.defTexture;
  8112. this.clear();
  8113. }
  8114. static __init__() {
  8115. Context.MAXCLIPRECT = new Rectangle(0, 0, Context._MAXSIZE, Context._MAXSIZE);
  8116. ContextParams.DEFAULT = new ContextParams();
  8117. }
  8118. drawImage(...args) {
  8119. }
  8120. getImageData(...args) {
  8121. }
  8122. measureText(text) {
  8123. return null;
  8124. }
  8125. setTransform(...args) {
  8126. }
  8127. $transform(a, b, c, d, tx, ty) {
  8128. }
  8129. get lineJoin() {
  8130. return '';
  8131. }
  8132. set lineJoin(value) {
  8133. }
  8134. get lineCap() {
  8135. return '';
  8136. }
  8137. set lineCap(value) {
  8138. }
  8139. get miterLimit() {
  8140. return '';
  8141. }
  8142. set miterLimit(value) {
  8143. }
  8144. clearRect(x, y, width, height) {
  8145. }
  8146. _drawRect(x, y, width, height, style) {
  8147. Stat.renderBatches++;
  8148. style && (this.fillStyle = style);
  8149. this.fillRect(x, y, width, height, null);
  8150. }
  8151. drawTexture2(x, y, pivotX, pivotY, m, args2) {
  8152. }
  8153. transformByMatrix(matrix, tx, ty) {
  8154. this.transform(matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx + tx, matrix.ty + ty);
  8155. }
  8156. saveTransform(matrix) {
  8157. this.save();
  8158. }
  8159. restoreTransform(matrix) {
  8160. this.restore();
  8161. }
  8162. drawRect(x, y, width, height, fillColor, lineColor, lineWidth) {
  8163. var ctx = this;
  8164. if (fillColor != null) {
  8165. ctx.fillStyle = fillColor;
  8166. ctx.fillRect(x, y, width, height);
  8167. }
  8168. if (lineColor != null) {
  8169. ctx.strokeStyle = lineColor;
  8170. ctx.lineWidth = lineWidth;
  8171. ctx.strokeRect(x, y, width, height);
  8172. }
  8173. }
  8174. alpha(value) {
  8175. this.globalAlpha *= value;
  8176. }
  8177. _transform(mat, pivotX, pivotY) {
  8178. this.translate(pivotX, pivotY);
  8179. this.transform(mat.a, mat.b, mat.c, mat.d, mat.tx, mat.ty);
  8180. this.translate(-pivotX, -pivotY);
  8181. }
  8182. _rotate(angle, pivotX, pivotY) {
  8183. this.translate(pivotX, pivotY);
  8184. this.rotate(angle);
  8185. this.translate(-pivotX, -pivotY);
  8186. }
  8187. _scale(scaleX, scaleY, pivotX, pivotY) {
  8188. this.translate(pivotX, pivotY);
  8189. this.scale(scaleX, scaleY);
  8190. this.translate(-pivotX, -pivotY);
  8191. }
  8192. _drawLine(x, y, fromX, fromY, toX, toY, lineColor, lineWidth, vid) {
  8193. this.beginPath();
  8194. this.strokeStyle = lineColor;
  8195. this.lineWidth = lineWidth;
  8196. this.moveTo(x + fromX, y + fromY);
  8197. this.lineTo(x + toX, y + toY);
  8198. this.stroke();
  8199. }
  8200. _drawLines(x, y, points, lineColor, lineWidth, vid) {
  8201. this.beginPath();
  8202. this.strokeStyle = lineColor;
  8203. this.lineWidth = lineWidth;
  8204. this.addPath(points.slice(), false, false, x, y);
  8205. this.stroke();
  8206. }
  8207. drawCurves(x, y, points, lineColor, lineWidth) {
  8208. this.beginPath();
  8209. this.strokeStyle = lineColor;
  8210. this.lineWidth = lineWidth;
  8211. this.moveTo(x + points[0], y + points[1]);
  8212. var i = 2, n = points.length;
  8213. while (i < n) {
  8214. this.quadraticCurveTo(x + points[i++], y + points[i++], x + points[i++], y + points[i++]);
  8215. }
  8216. this.stroke();
  8217. }
  8218. _fillAndStroke(fillColor, strokeColor, lineWidth, isConvexPolygon = false) {
  8219. if (fillColor != null) {
  8220. this.fillStyle = fillColor;
  8221. this.fill();
  8222. }
  8223. if (strokeColor != null && lineWidth > 0) {
  8224. this.strokeStyle = strokeColor;
  8225. this.lineWidth = lineWidth;
  8226. this.stroke();
  8227. }
  8228. }
  8229. _drawCircle(x, y, radius, fillColor, lineColor, lineWidth, vid) {
  8230. Stat.renderBatches++;
  8231. this.beginPath(true);
  8232. this.arc(x, y, radius, 0, Context.PI2);
  8233. this.closePath();
  8234. this._fillAndStroke(fillColor, lineColor, lineWidth);
  8235. }
  8236. _drawPie(x, y, radius, startAngle, endAngle, fillColor, lineColor, lineWidth, vid) {
  8237. this.beginPath();
  8238. this.moveTo(x, y);
  8239. this.arc(x, y, radius, startAngle, endAngle);
  8240. this.closePath();
  8241. this._fillAndStroke(fillColor, lineColor, lineWidth);
  8242. }
  8243. _drawPoly(x, y, points, fillColor, lineColor, lineWidth, isConvexPolygon, vid) {
  8244. this.beginPath();
  8245. this.addPath(points.slice(), true, isConvexPolygon, x, y);
  8246. this.closePath();
  8247. this._fillAndStroke(fillColor, lineColor, lineWidth, isConvexPolygon);
  8248. }
  8249. _drawPath(x, y, paths, brush, pen) {
  8250. this.beginPath();
  8251. for (var i = 0, n = paths.length; i < n; i++) {
  8252. var path = paths[i];
  8253. switch (path[0]) {
  8254. case "moveTo":
  8255. this.moveTo(x + path[1], y + path[2]);
  8256. break;
  8257. case "lineTo":
  8258. this.lineTo(x + path[1], y + path[2]);
  8259. break;
  8260. case "arcTo":
  8261. this.arcTo(x + path[1], y + path[2], x + path[3], y + path[4], path[5]);
  8262. break;
  8263. case "closePath":
  8264. this.closePath();
  8265. break;
  8266. }
  8267. }
  8268. if (brush != null) {
  8269. this.fillStyle = brush.fillStyle;
  8270. this.fill();
  8271. }
  8272. if (pen != null) {
  8273. this.strokeStyle = pen.strokeStyle;
  8274. this.lineWidth = pen.lineWidth || 1;
  8275. this.lineJoin = pen.lineJoin;
  8276. this.lineCap = pen.lineCap;
  8277. this.miterLimit = pen.miterLimit;
  8278. this.stroke();
  8279. }
  8280. }
  8281. static set2DRenderConfig() {
  8282. var gl = LayaGL.instance;
  8283. WebGLContext.setBlend(gl, true);
  8284. WebGLContext.setBlendEquation(gl, gl.FUNC_ADD);
  8285. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  8286. WebGLContext.setDepthTest(gl, false);
  8287. WebGLContext.setCullFace(gl, false);
  8288. WebGLContext.setDepthMask(gl, true);
  8289. WebGLContext.setFrontFace(gl, gl.CCW);
  8290. gl.viewport(0, 0, RenderState2D.width, RenderState2D.height);
  8291. }
  8292. clearBG(r, g, b, a) {
  8293. var gl = WebGLContext.mainContext;
  8294. gl.clearColor(r, g, b, a);
  8295. gl.clear(gl.COLOR_BUFFER_BIT);
  8296. }
  8297. _getSubmits() {
  8298. return this._submits;
  8299. }
  8300. _releaseMem(keepRT = false) {
  8301. if (!this._submits)
  8302. return;
  8303. this._curMat && this._curMat.destroy();
  8304. this._curMat = null;
  8305. this._shader2D.destroy();
  8306. this._shader2D = null;
  8307. this._charSubmitCache.clear();
  8308. for (var i = 0, n = this._submits._length; i < n; i++) {
  8309. this._submits[i].releaseRender();
  8310. }
  8311. this._submits.length = 0;
  8312. this._submits._length = 0;
  8313. this._submits = null;
  8314. this._curSubmit = null;
  8315. this._path = null;
  8316. this._save = null;
  8317. var sz;
  8318. for (i = 0, sz = this.meshlist.length; i < sz; i++) {
  8319. var curm = this.meshlist[i];
  8320. curm.destroy();
  8321. }
  8322. this.meshlist.length = 0;
  8323. this.sprite = null;
  8324. if (!keepRT) {
  8325. this._targets && (this._targets.destroy());
  8326. this._targets = null;
  8327. }
  8328. }
  8329. destroy(keepRT = false) {
  8330. --Context._contextcount;
  8331. this.sprite = null;
  8332. this._releaseMem(keepRT);
  8333. this._charSubmitCache.destroy();
  8334. this._mesh.destroy();
  8335. if (!keepRT) {
  8336. this._targets && this._targets.destroy();
  8337. this._targets = null;
  8338. }
  8339. }
  8340. clear() {
  8341. if (!this._submits) {
  8342. this._other = ContextParams.DEFAULT;
  8343. this._curMat = Matrix.create();
  8344. this._charSubmitCache = new CharSubmitCache();
  8345. this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  8346. this.meshlist.push(this._mesh);
  8347. this._pathMesh = MeshVG.getAMesh(this.isMain);
  8348. this.meshlist.push(this._pathMesh);
  8349. this._triangleMesh = MeshTexture.getAMesh(this.isMain);
  8350. this.meshlist.push(this._triangleMesh);
  8351. this._submits = [];
  8352. this._save = [SaveMark.Create(this)];
  8353. this._save.length = 10;
  8354. this._shader2D = new Shader2D();
  8355. }
  8356. this._submitKey.clear();
  8357. this._mesh.clearVB();
  8358. this._drawCount = 1;
  8359. this._other = ContextParams.DEFAULT;
  8360. this._other.lineWidth = this._shader2D.ALPHA = 1.0;
  8361. this._nBlendType = 0;
  8362. this._clipRect = Context.MAXCLIPRECT;
  8363. this._curSubmit = SubmitBase.RENDERBASE;
  8364. SubmitBase.RENDERBASE._ref = 0xFFFFFF;
  8365. SubmitBase.RENDERBASE._numEle = 0;
  8366. this._shader2D.fillStyle = this._shader2D.strokeStyle = DrawStyle.DEFAULT;
  8367. for (var i = 0, n = this._submits._length; i < n; i++)
  8368. this._submits[i].releaseRender();
  8369. this._submits._length = 0;
  8370. this._curMat.identity();
  8371. this._other.clear();
  8372. this._saveMark = this._save[0];
  8373. this._save._length = 1;
  8374. }
  8375. size(w, h) {
  8376. if (this._width != w || this._height != h) {
  8377. this._width = w;
  8378. this._height = h;
  8379. if (this._targets) {
  8380. this._targets.destroy();
  8381. this._targets = new RenderTexture2D(w, h, exports.RenderTextureFormat.R8G8B8A8, -1);
  8382. }
  8383. if (this.isMain) {
  8384. WebGLContext.mainContext.viewport(0, 0, w, h);
  8385. RenderState2D.width = w;
  8386. RenderState2D.height = h;
  8387. }
  8388. }
  8389. if (w === 0 && h === 0)
  8390. this._releaseMem();
  8391. }
  8392. set asBitmap(value) {
  8393. if (value) {
  8394. this._targets || (this._targets = new RenderTexture2D(this._width, this._height, exports.RenderTextureFormat.R8G8B8A8, -1));
  8395. if (!this._width || !this._height)
  8396. throw Error("asBitmap no size!");
  8397. }
  8398. else {
  8399. this._targets && this._targets.destroy();
  8400. this._targets = null;
  8401. }
  8402. }
  8403. getMatScaleX() {
  8404. if (this._lastMat_a == this._curMat.a && this._lastMat_b == this._curMat.b)
  8405. return this._lastMatScaleX;
  8406. this._lastMatScaleX = this._curMat.getScaleX();
  8407. this._lastMat_a = this._curMat.a;
  8408. this._lastMat_b = this._curMat.b;
  8409. return this._lastMatScaleX;
  8410. }
  8411. getMatScaleY() {
  8412. if (this._lastMat_c == this._curMat.c && this._lastMat_d == this._curMat.d)
  8413. return this._lastMatScaleY;
  8414. this._lastMatScaleY = this._curMat.getScaleY();
  8415. this._lastMat_c = this._curMat.c;
  8416. this._lastMat_d = this._curMat.d;
  8417. return this._lastMatScaleY;
  8418. }
  8419. setFillColor(color) {
  8420. this._fillColor = color;
  8421. }
  8422. getFillColor() {
  8423. return this._fillColor;
  8424. }
  8425. set fillStyle(value) {
  8426. if (!this._shader2D.fillStyle.equal(value)) {
  8427. SaveBase.save(this, SaveBase.TYPE_FILESTYLE, this._shader2D, false);
  8428. this._shader2D.fillStyle = DrawStyle.create(value);
  8429. this._submitKey.other = -this._shader2D.fillStyle.toInt();
  8430. }
  8431. }
  8432. get fillStyle() {
  8433. return this._shader2D.fillStyle;
  8434. }
  8435. set globalAlpha(value) {
  8436. value = Math.floor(value * 1000) / 1000;
  8437. if (value != this._shader2D.ALPHA) {
  8438. SaveBase.save(this, SaveBase.TYPE_ALPHA, this._shader2D, false);
  8439. this._shader2D.ALPHA = value;
  8440. }
  8441. }
  8442. get globalAlpha() {
  8443. return this._shader2D.ALPHA;
  8444. }
  8445. set textAlign(value) {
  8446. (this._other.textAlign === value) || (this._other = this._other.make(), SaveBase.save(this, SaveBase.TYPE_TEXTALIGN, this._other, false), this._other.textAlign = value);
  8447. }
  8448. get textAlign() {
  8449. return this._other.textAlign;
  8450. }
  8451. set textBaseline(value) {
  8452. (this._other.textBaseline === value) || (this._other = this._other.make(), SaveBase.save(this, SaveBase.TYPE_TEXTBASELINE, this._other, false), this._other.textBaseline = value);
  8453. }
  8454. get textBaseline() {
  8455. return this._other.textBaseline;
  8456. }
  8457. set globalCompositeOperation(value) {
  8458. var n = BlendMode.TOINT[value];
  8459. n == null || (this._nBlendType === n) || (SaveBase.save(this, SaveBase.TYPE_GLOBALCOMPOSITEOPERATION, this, true), this._curSubmit = SubmitBase.RENDERBASE, this._nBlendType = n);
  8460. }
  8461. get globalCompositeOperation() {
  8462. return BlendMode.NAMES[this._nBlendType];
  8463. }
  8464. set strokeStyle(value) {
  8465. this._shader2D.strokeStyle.equal(value) || (SaveBase.save(this, SaveBase.TYPE_STROKESTYLE, this._shader2D, false), this._shader2D.strokeStyle = DrawStyle.create(value), this._submitKey.other = -this._shader2D.strokeStyle.toInt());
  8466. }
  8467. get strokeStyle() {
  8468. return this._shader2D.strokeStyle;
  8469. }
  8470. translate(x, y) {
  8471. if (x !== 0 || y !== 0) {
  8472. SaveTranslate.save(this);
  8473. if (this._curMat._bTransform) {
  8474. SaveTransform.save(this);
  8475. this._curMat.tx += (x * this._curMat.a + y * this._curMat.c);
  8476. this._curMat.ty += (x * this._curMat.b + y * this._curMat.d);
  8477. }
  8478. else {
  8479. this._curMat.tx = x;
  8480. this._curMat.ty = y;
  8481. }
  8482. }
  8483. }
  8484. set lineWidth(value) {
  8485. (this._other.lineWidth === value) || (this._other = this._other.make(), SaveBase.save(this, SaveBase.TYPE_LINEWIDTH, this._other, false), this._other.lineWidth = value);
  8486. }
  8487. get lineWidth() {
  8488. return this._other.lineWidth;
  8489. }
  8490. save() {
  8491. this._save[this._save._length++] = SaveMark.Create(this);
  8492. }
  8493. restore() {
  8494. var sz = this._save._length;
  8495. var lastBlend = this._nBlendType;
  8496. if (sz < 1)
  8497. return;
  8498. for (var i = sz - 1; i >= 0; i--) {
  8499. var o = this._save[i];
  8500. o.restore(this);
  8501. if (o.isSaveMark()) {
  8502. this._save._length = i;
  8503. return;
  8504. }
  8505. }
  8506. if (lastBlend != this._nBlendType) {
  8507. this._curSubmit = SubmitBase.RENDERBASE;
  8508. }
  8509. }
  8510. set font(str) {
  8511. this._other = this._other.make();
  8512. SaveBase.save(this, SaveBase.TYPE_FONT, this._other, false);
  8513. }
  8514. fillText(txt, x, y, fontStr, color, align, lineWidth = 0, borderColor = "") {
  8515. Context._textRender.filltext(this, txt, x, y, fontStr, color, borderColor, lineWidth, align);
  8516. }
  8517. drawText(text, x, y, font, color, textAlign) {
  8518. Context._textRender.filltext(this, text, x, y, font, color, null, 0, textAlign);
  8519. }
  8520. fillWords(words, x, y, fontStr, color) {
  8521. Context._textRender.fillWords(this, words, x, y, fontStr, color, null, 0);
  8522. }
  8523. strokeWord(text, x, y, font, color, lineWidth, textAlign) {
  8524. Context._textRender.filltext(this, text, x, y, font, null, color, lineWidth, textAlign);
  8525. }
  8526. fillBorderText(txt, x, y, font, color, borderColor, lineWidth, textAlign) {
  8527. Context._textRender.filltext(this, txt, x, y, font, color, borderColor, lineWidth, textAlign);
  8528. }
  8529. fillBorderWords(words, x, y, font, color, borderColor, lineWidth) {
  8530. Context._textRender.fillWords(this, words, x, y, font, color, borderColor, lineWidth);
  8531. }
  8532. _fast_filltext(data, x, y, fontObj, color, strokeColor, lineWidth, textAlign, underLine = 0) {
  8533. Context._textRender._fast_filltext(this, data, null, x, y, fontObj, color, strokeColor, lineWidth, textAlign, underLine);
  8534. }
  8535. _fillRect(x, y, width, height, rgba) {
  8536. var submit = this._curSubmit;
  8537. var sameKey = submit && (submit._key.submitType === SubmitBase.KEY_DRAWTEXTURE && submit._key.blendShader === this._nBlendType);
  8538. if (this._mesh.vertNum + 4 > Context._MAXVERTNUM) {
  8539. this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  8540. this.meshlist.push(this._mesh);
  8541. sameKey = false;
  8542. }
  8543. sameKey && (sameKey = sameKey && this.isSameClipInfo(submit));
  8544. this.transformQuad(x, y, width, height, 0, this._curMat, this._transedPoints);
  8545. if (!this.clipedOff(this._transedPoints)) {
  8546. this._mesh.addQuad(this._transedPoints, Texture.NO_UV, rgba, false);
  8547. if (!sameKey) {
  8548. submit = this._curSubmit = SubmitTexture.create(this, this._mesh, Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  8549. this._submits[this._submits._length++] = submit;
  8550. this._copyClipInfo(submit, this._globalClipMatrix);
  8551. submit.shaderValue.textureHost = this._lastTex;
  8552. submit._key.other = (this._lastTex && this._lastTex.bitmap) ? this._lastTex.bitmap.id : -1;
  8553. submit._renderType = SubmitBase.TYPE_TEXTURE;
  8554. }
  8555. this._curSubmit._numEle += 6;
  8556. this._mesh.indexNum += 6;
  8557. this._mesh.vertNum += 4;
  8558. }
  8559. }
  8560. fillRect(x, y, width, height, fillStyle) {
  8561. var drawstyle = fillStyle ? DrawStyle.create(fillStyle) : this._shader2D.fillStyle;
  8562. var rgba = this.mixRGBandAlpha(drawstyle.toInt());
  8563. this._fillRect(x, y, width, height, rgba);
  8564. }
  8565. fillTexture(texture, x, y, width, height, type, offset, other) {
  8566. if (!texture._getSource()) {
  8567. this.sprite && ILaya.systemTimer.callLater(this, this._repaintSprite);
  8568. return;
  8569. }
  8570. this._fillTexture(texture, texture.width, texture.height, texture.uvrect, x, y, width, height, type, offset.x, offset.y);
  8571. }
  8572. _fillTexture(texture, texw, texh, texuvRect, x, y, width, height, type, offsetx, offsety) {
  8573. var submit = this._curSubmit;
  8574. if (this._mesh.vertNum + 4 > Context._MAXVERTNUM) {
  8575. this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  8576. this.meshlist.push(this._mesh);
  8577. }
  8578. var repeatx = true;
  8579. var repeaty = true;
  8580. switch (type) {
  8581. case "repeat": break;
  8582. case "repeat-x":
  8583. repeaty = false;
  8584. break;
  8585. case "repeat-y":
  8586. repeatx = false;
  8587. break;
  8588. case "no-repeat":
  8589. repeatx = repeaty = false;
  8590. break;
  8591. default: break;
  8592. }
  8593. var uv = this._temp4Points;
  8594. var stu = 0;
  8595. var stv = 0;
  8596. var stx = 0, sty = 0, edx = 0, edy = 0;
  8597. if (offsetx < 0) {
  8598. stx = x;
  8599. stu = (-offsetx % texw) / texw;
  8600. }
  8601. else {
  8602. stx = x + offsetx;
  8603. }
  8604. if (offsety < 0) {
  8605. sty = y;
  8606. stv = (-offsety % texh) / texh;
  8607. }
  8608. else {
  8609. sty = y + offsety;
  8610. }
  8611. edx = x + width;
  8612. edy = y + height;
  8613. (!repeatx) && (edx = Math.min(edx, x + offsetx + texw));
  8614. (!repeaty) && (edy = Math.min(edy, y + offsety + texh));
  8615. if (edx < x || edy < y)
  8616. return;
  8617. if (stx > edx || sty > edy)
  8618. return;
  8619. var edu = (edx - x - offsetx) / texw;
  8620. var edv = (edy - y - offsety) / texh;
  8621. this.transformQuad(stx, sty, edx - stx, edy - sty, 0, this._curMat, this._transedPoints);
  8622. uv[0] = stu;
  8623. uv[1] = stv;
  8624. uv[2] = edu;
  8625. uv[3] = stv;
  8626. uv[4] = edu;
  8627. uv[5] = edv;
  8628. uv[6] = stu;
  8629. uv[7] = edv;
  8630. if (!this.clipedOff(this._transedPoints)) {
  8631. var rgba = this._mixRGBandAlpha(0xffffffff, this._shader2D.ALPHA);
  8632. this._mesh.addQuad(this._transedPoints, uv, rgba, true);
  8633. var sv = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  8634. sv.defines.add(ShaderDefines2D.FILLTEXTURE);
  8635. sv.u_TexRange = texuvRect;
  8636. submit = this._curSubmit = SubmitTexture.create(this, this._mesh, sv);
  8637. this._submits[this._submits._length++] = submit;
  8638. this._copyClipInfo(submit, this._globalClipMatrix);
  8639. submit.shaderValue.textureHost = texture;
  8640. submit._renderType = SubmitBase.TYPE_TEXTURE;
  8641. this._curSubmit._numEle += 6;
  8642. this._mesh.indexNum += 6;
  8643. this._mesh.vertNum += 4;
  8644. }
  8645. this.breakNextMerge();
  8646. }
  8647. setColorFilter(filter) {
  8648. SaveBase.save(this, SaveBase.TYPE_COLORFILTER, this, true);
  8649. this._colorFiler = filter;
  8650. this._curSubmit = SubmitBase.RENDERBASE;
  8651. }
  8652. drawTexture(tex, x, y, width, height) {
  8653. this._drawTextureM(tex, x, y, width, height, null, 1, null);
  8654. }
  8655. drawTextures(tex, pos, tx, ty) {
  8656. if (!tex._getSource()) {
  8657. this.sprite && ILaya.systemTimer.callLater(this, this._repaintSprite);
  8658. return;
  8659. }
  8660. var n = pos.length / 2;
  8661. var ipos = 0;
  8662. var bmpid = tex.bitmap.id;
  8663. for (var i = 0; i < n; i++) {
  8664. this._inner_drawTexture(tex, bmpid, pos[ipos++] + tx, pos[ipos++] + ty, 0, 0, null, null, 1.0, false);
  8665. }
  8666. }
  8667. _drawTextureAddSubmit(imgid, tex) {
  8668. var submit = null;
  8669. submit = SubmitTexture.create(this, this._mesh, Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  8670. this._submits[this._submits._length++] = submit;
  8671. submit.shaderValue.textureHost = tex;
  8672. submit._key.other = imgid;
  8673. submit._renderType = SubmitBase.TYPE_TEXTURE;
  8674. this._curSubmit = submit;
  8675. }
  8676. _drawTextureM(tex, x, y, width, height, m, alpha, uv) {
  8677. var cs = this.sprite;
  8678. if (!tex._getSource(function () {
  8679. if (cs) {
  8680. cs.repaint();
  8681. }
  8682. })) {
  8683. return false;
  8684. }
  8685. return this._inner_drawTexture(tex, tex.bitmap.id, x, y, width, height, m, uv, alpha, false);
  8686. }
  8687. _drawRenderTexture(tex, x, y, width, height, m, alpha, uv) {
  8688. return this._inner_drawTexture(tex, -1, x, y, width, height, m, uv, 1.0, false);
  8689. }
  8690. submitDebugger() {
  8691. this._submits[this._submits._length++] = SubmitCMD.create([], function () { debugger; }, this);
  8692. }
  8693. _copyClipInfo(submit, clipInfo) {
  8694. var cm = submit.shaderValue.clipMatDir;
  8695. cm[0] = clipInfo.a;
  8696. cm[1] = clipInfo.b;
  8697. cm[2] = clipInfo.c;
  8698. cm[3] = clipInfo.d;
  8699. var cmp = submit.shaderValue.clipMatPos;
  8700. cmp[0] = clipInfo.tx;
  8701. cmp[1] = clipInfo.ty;
  8702. submit.clipInfoID = this._clipInfoID;
  8703. if (this._clipInCache) {
  8704. submit.shaderValue.clipOff[0] = 1;
  8705. }
  8706. }
  8707. isSameClipInfo(submit) {
  8708. return (submit.clipInfoID === this._clipInfoID);
  8709. }
  8710. _useNewTex2DSubmit(tex, minVertNum) {
  8711. if (this._mesh.vertNum + minVertNum > Context._MAXVERTNUM) {
  8712. this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  8713. this.meshlist.push(this._mesh);
  8714. }
  8715. var submit = SubmitTexture.create(this, this._mesh, Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  8716. this._submits[this._submits._length++] = this._curSubmit = submit;
  8717. submit.shaderValue.textureHost = tex;
  8718. this._copyClipInfo(submit, this._globalClipMatrix);
  8719. }
  8720. _drawTexRect(x, y, w, h, uv) {
  8721. this.transformQuad(x, y, w, h, this._italicDeg, this._curMat, this._transedPoints);
  8722. var ops = this._transedPoints;
  8723. ops[0] = (ops[0] + 0.5) | 0;
  8724. ops[1] = (ops[1] + 0.5) | 0;
  8725. ops[2] = (ops[2] + 0.5) | 0;
  8726. ops[3] = (ops[3] + 0.5) | 0;
  8727. ops[4] = (ops[4] + 0.5) | 0;
  8728. ops[5] = (ops[5] + 0.5) | 0;
  8729. ops[6] = (ops[6] + 0.5) | 0;
  8730. ops[7] = (ops[7] + 0.5) | 0;
  8731. if (!this.clipedOff(this._transedPoints)) {
  8732. this._mesh.addQuad(this._transedPoints, uv, this._fillColor, true);
  8733. this._curSubmit._numEle += 6;
  8734. this._mesh.indexNum += 6;
  8735. this._mesh.vertNum += 4;
  8736. }
  8737. }
  8738. drawCallOptimize(enbale) {
  8739. this._charSubmitCache.enable(enbale, this);
  8740. return enbale;
  8741. }
  8742. _inner_drawTexture(tex, imgid, x, y, width, height, m, uv, alpha, lastRender) {
  8743. var preKey = this._curSubmit._key;
  8744. uv = uv || tex._uv;
  8745. if (preKey.submitType === SubmitBase.KEY_TRIANGLES && preKey.other === imgid) {
  8746. var tv = this._drawTexToDrawTri_Vert;
  8747. tv[0] = x;
  8748. tv[1] = y;
  8749. tv[2] = x + width, tv[3] = y, tv[4] = x + width, tv[5] = y + height, tv[6] = x, tv[7] = y + height;
  8750. this._drawTriUseAbsMatrix = true;
  8751. var tuv = this._tempUV;
  8752. tuv[0] = uv[0];
  8753. tuv[1] = uv[1];
  8754. tuv[2] = uv[2];
  8755. tuv[3] = uv[3];
  8756. tuv[4] = uv[4];
  8757. tuv[5] = uv[5];
  8758. tuv[6] = uv[6];
  8759. tuv[7] = uv[7];
  8760. this.drawTriangles(tex, 0, 0, tv, tuv, this._drawTexToDrawTri_Index, m, alpha, null, null);
  8761. this._drawTriUseAbsMatrix = false;
  8762. return true;
  8763. }
  8764. var mesh = this._mesh;
  8765. var submit = this._curSubmit;
  8766. var ops = lastRender ? this._charSubmitCache.getPos() : this._transedPoints;
  8767. this.transformQuad(x, y, width || tex.width, height || tex.height, this._italicDeg, m || this._curMat, ops);
  8768. if (this.drawTexAlign) {
  8769. var round = Math.round;
  8770. ops[0] = round(ops[0]);
  8771. ops[1] = round(ops[1]);
  8772. ops[2] = round(ops[2]);
  8773. ops[3] = round(ops[3]);
  8774. ops[4] = round(ops[4]);
  8775. ops[5] = round(ops[5]);
  8776. ops[6] = round(ops[6]);
  8777. ops[7] = round(ops[7]);
  8778. this.drawTexAlign = false;
  8779. }
  8780. var rgba = this._mixRGBandAlpha(0xffffffff, this._shader2D.ALPHA * alpha);
  8781. if (lastRender) {
  8782. this._charSubmitCache.add(this, tex, imgid, ops, uv, rgba);
  8783. return true;
  8784. }
  8785. this._drawCount++;
  8786. var sameKey = imgid >= 0 && preKey.submitType === SubmitBase.KEY_DRAWTEXTURE && preKey.other === imgid;
  8787. sameKey && (sameKey = sameKey && this.isSameClipInfo(submit));
  8788. this._lastTex = tex;
  8789. if (mesh.vertNum + 4 > Context._MAXVERTNUM) {
  8790. mesh = this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  8791. this.meshlist.push(mesh);
  8792. sameKey = false;
  8793. }
  8794. {
  8795. mesh.addQuad(ops, uv, rgba, true);
  8796. if (!sameKey) {
  8797. this._submits[this._submits._length++] = this._curSubmit = submit = SubmitTexture.create(this, mesh, Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  8798. submit.shaderValue.textureHost = tex;
  8799. submit._key.other = imgid;
  8800. this._copyClipInfo(submit, this._globalClipMatrix);
  8801. }
  8802. submit._numEle += 6;
  8803. mesh.indexNum += 6;
  8804. mesh.vertNum += 4;
  8805. return true;
  8806. }
  8807. return false;
  8808. }
  8809. transform4Points(a, m, out) {
  8810. var tx = m.tx;
  8811. var ty = m.ty;
  8812. var ma = m.a;
  8813. var mb = m.b;
  8814. var mc = m.c;
  8815. var md = m.d;
  8816. var a0 = a[0];
  8817. var a1 = a[1];
  8818. var a2 = a[2];
  8819. var a3 = a[3];
  8820. var a4 = a[4];
  8821. var a5 = a[5];
  8822. var a6 = a[6];
  8823. var a7 = a[7];
  8824. if (m._bTransform) {
  8825. out[0] = a0 * ma + a1 * mc + tx;
  8826. out[1] = a0 * mb + a1 * md + ty;
  8827. out[2] = a2 * ma + a3 * mc + tx;
  8828. out[3] = a2 * mb + a3 * md + ty;
  8829. out[4] = a4 * ma + a5 * mc + tx;
  8830. out[5] = a4 * mb + a5 * md + ty;
  8831. out[6] = a6 * ma + a7 * mc + tx;
  8832. out[7] = a6 * mb + a7 * md + ty;
  8833. }
  8834. else {
  8835. out[0] = a0 + tx;
  8836. out[1] = a1 + ty;
  8837. out[2] = a2 + tx;
  8838. out[3] = a3 + ty;
  8839. out[4] = a4 + tx;
  8840. out[5] = a5 + ty;
  8841. out[6] = a6 + tx;
  8842. out[7] = a7 + ty;
  8843. }
  8844. }
  8845. clipedOff(pt) {
  8846. if (this._clipRect.width <= 0 || this._clipRect.height <= 0)
  8847. return true;
  8848. return false;
  8849. }
  8850. transformQuad(x, y, w, h, italicDeg, m, out) {
  8851. var xoff = 0;
  8852. if (italicDeg != 0) {
  8853. xoff = Math.tan(italicDeg * Math.PI / 180) * h;
  8854. }
  8855. var maxx = x + w;
  8856. var maxy = y + h;
  8857. var tx = m.tx;
  8858. var ty = m.ty;
  8859. var ma = m.a;
  8860. var mb = m.b;
  8861. var mc = m.c;
  8862. var md = m.d;
  8863. var a0 = x + xoff;
  8864. var a1 = y;
  8865. var a2 = maxx + xoff;
  8866. var a3 = y;
  8867. var a4 = maxx;
  8868. var a5 = maxy;
  8869. var a6 = x;
  8870. var a7 = maxy;
  8871. if (m._bTransform) {
  8872. out[0] = a0 * ma + a1 * mc + tx;
  8873. out[1] = a0 * mb + a1 * md + ty;
  8874. out[2] = a2 * ma + a3 * mc + tx;
  8875. out[3] = a2 * mb + a3 * md + ty;
  8876. out[4] = a4 * ma + a5 * mc + tx;
  8877. out[5] = a4 * mb + a5 * md + ty;
  8878. out[6] = a6 * ma + a7 * mc + tx;
  8879. out[7] = a6 * mb + a7 * md + ty;
  8880. }
  8881. else {
  8882. out[0] = a0 + tx;
  8883. out[1] = a1 + ty;
  8884. out[2] = a2 + tx;
  8885. out[3] = a3 + ty;
  8886. out[4] = a4 + tx;
  8887. out[5] = a5 + ty;
  8888. out[6] = a6 + tx;
  8889. out[7] = a7 + ty;
  8890. }
  8891. }
  8892. pushRT() {
  8893. this.addRenderObject(SubmitCMD.create(null, RenderTexture2D.pushRT, this));
  8894. }
  8895. popRT() {
  8896. this.addRenderObject(SubmitCMD.create(null, RenderTexture2D.popRT, this));
  8897. this.breakNextMerge();
  8898. }
  8899. useRT(rt) {
  8900. function _use(rt) {
  8901. if (!rt) {
  8902. throw 'error useRT';
  8903. }
  8904. else {
  8905. rt.start();
  8906. rt.clear(0, 0, 0, 0);
  8907. }
  8908. }
  8909. this.addRenderObject(SubmitCMD.create([rt], _use, this));
  8910. this.breakNextMerge();
  8911. }
  8912. RTRestore(rt) {
  8913. function _restore(rt) {
  8914. rt.restore();
  8915. }
  8916. this.addRenderObject(SubmitCMD.create([rt], _restore, this));
  8917. this.breakNextMerge();
  8918. }
  8919. breakNextMerge() {
  8920. this._curSubmit = SubmitBase.RENDERBASE;
  8921. }
  8922. _repaintSprite() {
  8923. this.sprite && this.sprite.repaint();
  8924. }
  8925. drawTextureWithTransform(tex, x, y, width, height, transform, tx, ty, alpha, blendMode, colorfilter = null, uv) {
  8926. var oldcomp;
  8927. var curMat = this._curMat;
  8928. if (blendMode) {
  8929. oldcomp = this.globalCompositeOperation;
  8930. this.globalCompositeOperation = blendMode;
  8931. }
  8932. var oldColorFilter = this._colorFiler;
  8933. if (colorfilter) {
  8934. this.setColorFilter(colorfilter);
  8935. }
  8936. if (!transform) {
  8937. this._drawTextureM(tex, x + tx, y + ty, width, height, curMat, alpha, uv);
  8938. if (blendMode) {
  8939. this.globalCompositeOperation = oldcomp;
  8940. }
  8941. if (colorfilter) {
  8942. this.setColorFilter(oldColorFilter);
  8943. }
  8944. return;
  8945. }
  8946. var tmpMat = this._tmpMatrix;
  8947. tmpMat.a = transform.a;
  8948. tmpMat.b = transform.b;
  8949. tmpMat.c = transform.c;
  8950. tmpMat.d = transform.d;
  8951. tmpMat.tx = transform.tx + tx;
  8952. tmpMat.ty = transform.ty + ty;
  8953. tmpMat._bTransform = transform._bTransform;
  8954. if (transform && curMat._bTransform) {
  8955. Matrix.mul(tmpMat, curMat, tmpMat);
  8956. transform = tmpMat;
  8957. transform._bTransform = true;
  8958. }
  8959. else {
  8960. tmpMat.tx += curMat.tx;
  8961. tmpMat.ty += curMat.ty;
  8962. transform = tmpMat;
  8963. }
  8964. this._drawTextureM(tex, x, y, width, height, transform, alpha, uv);
  8965. if (blendMode) {
  8966. this.globalCompositeOperation = oldcomp;
  8967. }
  8968. if (colorfilter) {
  8969. this.setColorFilter(oldColorFilter);
  8970. }
  8971. }
  8972. _flushToTarget(context, target) {
  8973. RenderState2D.worldScissorTest = false;
  8974. var gl = LayaGL.instance;
  8975. gl.disable(gl.SCISSOR_TEST);
  8976. var preAlpha = RenderState2D.worldAlpha;
  8977. var preMatrix4 = RenderState2D.worldMatrix4;
  8978. var preMatrix = RenderState2D.worldMatrix;
  8979. RenderState2D.worldMatrix = Matrix.EMPTY;
  8980. RenderState2D.restoreTempArray();
  8981. RenderState2D.worldMatrix4 = RenderState2D.TEMPMAT4_ARRAY;
  8982. RenderState2D.worldAlpha = 1;
  8983. BaseShader.activeShader = null;
  8984. target.start();
  8985. if (context._submits._length > 0)
  8986. target.clear(0, 0, 0, 0);
  8987. context._curSubmit = SubmitBase.RENDERBASE;
  8988. context.flush();
  8989. context.clear();
  8990. target.restore();
  8991. context._curSubmit = SubmitBase.RENDERBASE;
  8992. BaseShader.activeShader = null;
  8993. RenderState2D.worldAlpha = preAlpha;
  8994. RenderState2D.worldMatrix4 = preMatrix4;
  8995. RenderState2D.worldMatrix = preMatrix;
  8996. }
  8997. drawCanvas(canvas, x, y, width, height) {
  8998. if (!canvas)
  8999. return;
  9000. var src = canvas.context;
  9001. var submit;
  9002. if (src._targets) {
  9003. if (src._submits._length > 0) {
  9004. submit = SubmitCMD.create([src, src._targets], this._flushToTarget, this);
  9005. this._submits[this._submits._length++] = submit;
  9006. }
  9007. this._drawRenderTexture(src._targets, x, y, width, height, null, 1.0, RenderTexture2D.flipyuv);
  9008. this._curSubmit = SubmitBase.RENDERBASE;
  9009. }
  9010. else {
  9011. var canv = canvas;
  9012. if (canv.touches) {
  9013. canv.touches.forEach(function (v) { v.touch(); });
  9014. }
  9015. submit = SubmitCanvas.create(canvas, this._shader2D.ALPHA, this._shader2D.filters);
  9016. this._submits[this._submits._length++] = submit;
  9017. submit._key.clear();
  9018. var mat = submit._matrix;
  9019. this._curMat.copyTo(mat);
  9020. var tx = mat.tx, ty = mat.ty;
  9021. mat.tx = mat.ty = 0;
  9022. mat.transformPoint(Point.TEMP.setTo(x, y));
  9023. mat.translate(Point.TEMP.x + tx, Point.TEMP.y + ty);
  9024. Matrix.mul(canv.invMat, mat, mat);
  9025. this._curSubmit = SubmitBase.RENDERBASE;
  9026. }
  9027. }
  9028. drawTarget(rt, x, y, width, height, m, shaderValue, uv = null, blend = -1) {
  9029. this._drawCount++;
  9030. if (this._mesh.vertNum + 4 > Context._MAXVERTNUM) {
  9031. this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  9032. this.meshlist.push(this._mesh);
  9033. }
  9034. this.transformQuad(x, y, width, height, 0, m || this._curMat, this._transedPoints);
  9035. if (!this.clipedOff(this._transedPoints)) {
  9036. this._mesh.addQuad(this._transedPoints, uv || Texture.DEF_UV, 0xffffffff, true);
  9037. var submit = this._curSubmit = SubmitTarget.create(this, this._mesh, shaderValue, rt);
  9038. submit.blendType = (blend == -1) ? this._nBlendType : blend;
  9039. this._copyClipInfo(submit, this._globalClipMatrix);
  9040. submit._numEle = 6;
  9041. this._mesh.indexNum += 6;
  9042. this._mesh.vertNum += 4;
  9043. this._submits[this._submits._length++] = submit;
  9044. this._curSubmit = SubmitBase.RENDERBASE;
  9045. return true;
  9046. }
  9047. this._curSubmit = SubmitBase.RENDERBASE;
  9048. return false;
  9049. }
  9050. drawTriangles(tex, x, y, vertices, uvs, indices, matrix, alpha, color, blendMode, colorNum = 0xffffffff) {
  9051. var oldcomp = null;
  9052. if (blendMode) {
  9053. oldcomp = this.globalCompositeOperation;
  9054. this.globalCompositeOperation = blendMode;
  9055. }
  9056. if (!tex._getSource()) {
  9057. if (this.sprite) {
  9058. ILaya.systemTimer.callLater(this, this._repaintSprite);
  9059. }
  9060. return;
  9061. }
  9062. this._drawCount++;
  9063. var tmpMat = this._tmpMatrix;
  9064. var triMesh = this._triangleMesh;
  9065. var oldColorFilter = null;
  9066. var needRestorFilter = false;
  9067. if (color) {
  9068. oldColorFilter = this._colorFiler;
  9069. this._colorFiler = color;
  9070. this._curSubmit = SubmitBase.RENDERBASE;
  9071. needRestorFilter = oldColorFilter != color;
  9072. }
  9073. var webGLImg = tex.bitmap;
  9074. var preKey = this._curSubmit._key;
  9075. var sameKey = preKey.submitType === SubmitBase.KEY_TRIANGLES && preKey.other === webGLImg.id && preKey.blendShader == this._nBlendType;
  9076. if (triMesh.vertNum + vertices.length / 2 > Context._MAXVERTNUM) {
  9077. triMesh = this._triangleMesh = MeshTexture.getAMesh(this.isMain);
  9078. this.meshlist.push(triMesh);
  9079. sameKey = false;
  9080. }
  9081. if (!sameKey) {
  9082. var submit = this._curSubmit = SubmitTexture.create(this, triMesh, Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  9083. submit.shaderValue.textureHost = tex;
  9084. submit._renderType = SubmitBase.TYPE_TEXTURE;
  9085. submit._key.submitType = SubmitBase.KEY_TRIANGLES;
  9086. submit._key.other = webGLImg.id;
  9087. this._copyClipInfo(submit, this._globalClipMatrix);
  9088. this._submits[this._submits._length++] = submit;
  9089. }
  9090. var rgba = this._mixRGBandAlpha(colorNum, this._shader2D.ALPHA * alpha);
  9091. if (!this._drawTriUseAbsMatrix) {
  9092. if (!matrix) {
  9093. tmpMat.a = 1;
  9094. tmpMat.b = 0;
  9095. tmpMat.c = 0;
  9096. tmpMat.d = 1;
  9097. tmpMat.tx = x;
  9098. tmpMat.ty = y;
  9099. }
  9100. else {
  9101. tmpMat.a = matrix.a;
  9102. tmpMat.b = matrix.b;
  9103. tmpMat.c = matrix.c;
  9104. tmpMat.d = matrix.d;
  9105. tmpMat.tx = matrix.tx + x;
  9106. tmpMat.ty = matrix.ty + y;
  9107. }
  9108. Matrix.mul(tmpMat, this._curMat, tmpMat);
  9109. triMesh.addData(vertices, uvs, indices, tmpMat || this._curMat, rgba);
  9110. }
  9111. else {
  9112. triMesh.addData(vertices, uvs, indices, matrix, rgba);
  9113. }
  9114. this._curSubmit._numEle += indices.length;
  9115. if (needRestorFilter) {
  9116. this._colorFiler = oldColorFilter;
  9117. this._curSubmit = SubmitBase.RENDERBASE;
  9118. }
  9119. if (blendMode) {
  9120. this.globalCompositeOperation = oldcomp;
  9121. }
  9122. }
  9123. transform(a, b, c, d, tx, ty) {
  9124. SaveTransform.save(this);
  9125. Matrix.mul(Matrix.TEMP.setTo(a, b, c, d, tx, ty), this._curMat, this._curMat);
  9126. this._curMat._checkTransform();
  9127. }
  9128. _transformByMatrix(matrix, tx, ty) {
  9129. matrix.setTranslate(tx, ty);
  9130. Matrix.mul(matrix, this._curMat, this._curMat);
  9131. matrix.setTranslate(0, 0);
  9132. this._curMat._bTransform = true;
  9133. }
  9134. setTransformByMatrix(value) {
  9135. value.copyTo(this._curMat);
  9136. }
  9137. rotate(angle) {
  9138. SaveTransform.save(this);
  9139. this._curMat.rotateEx(angle);
  9140. }
  9141. scale(scaleX, scaleY) {
  9142. SaveTransform.save(this);
  9143. this._curMat.scaleEx(scaleX, scaleY);
  9144. }
  9145. clipRect(x, y, width, height) {
  9146. SaveClipRect.save(this);
  9147. if (this._clipRect == Context.MAXCLIPRECT) {
  9148. this._clipRect = new Rectangle(x, y, width, height);
  9149. }
  9150. else {
  9151. this._clipRect.width = width;
  9152. this._clipRect.height = height;
  9153. this._clipRect.x = x;
  9154. this._clipRect.y = y;
  9155. }
  9156. this._clipID_Gen++;
  9157. this._clipID_Gen %= 10000;
  9158. this._clipInfoID = this._clipID_Gen;
  9159. var cm = this._globalClipMatrix;
  9160. var minx = cm.tx;
  9161. var miny = cm.ty;
  9162. var maxx = minx + cm.a;
  9163. var maxy = miny + cm.d;
  9164. if (this._clipRect.width >= Context._MAXSIZE) {
  9165. cm.a = cm.d = Context._MAXSIZE;
  9166. cm.b = cm.c = cm.tx = cm.ty = 0;
  9167. }
  9168. else {
  9169. if (this._curMat._bTransform) {
  9170. cm.tx = this._clipRect.x * this._curMat.a + this._clipRect.y * this._curMat.c + this._curMat.tx;
  9171. cm.ty = this._clipRect.x * this._curMat.b + this._clipRect.y * this._curMat.d + this._curMat.ty;
  9172. cm.a = this._clipRect.width * this._curMat.a;
  9173. cm.b = this._clipRect.width * this._curMat.b;
  9174. cm.c = this._clipRect.height * this._curMat.c;
  9175. cm.d = this._clipRect.height * this._curMat.d;
  9176. }
  9177. else {
  9178. cm.tx = this._clipRect.x + this._curMat.tx;
  9179. cm.ty = this._clipRect.y + this._curMat.ty;
  9180. cm.a = this._clipRect.width;
  9181. cm.b = cm.c = 0;
  9182. cm.d = this._clipRect.height;
  9183. }
  9184. if (this._incache) {
  9185. this._clipInCache = true;
  9186. }
  9187. }
  9188. if (cm.a > 0 && cm.d > 0) {
  9189. var cmaxx = cm.tx + cm.a;
  9190. var cmaxy = cm.ty + cm.d;
  9191. if (cmaxx <= minx || cmaxy <= miny || cm.tx >= maxx || cm.ty >= maxy) {
  9192. cm.a = -0.1;
  9193. cm.d = -0.1;
  9194. }
  9195. else {
  9196. if (cm.tx < minx) {
  9197. cm.a -= (minx - cm.tx);
  9198. cm.tx = minx;
  9199. }
  9200. if (cmaxx > maxx) {
  9201. cm.a -= (cmaxx - maxx);
  9202. }
  9203. if (cm.ty < miny) {
  9204. cm.d -= (miny - cm.ty);
  9205. cm.ty = miny;
  9206. }
  9207. if (cmaxy > maxy) {
  9208. cm.d -= (cmaxy - maxy);
  9209. }
  9210. if (cm.a <= 0)
  9211. cm.a = -0.1;
  9212. if (cm.d <= 0)
  9213. cm.d = -0.1;
  9214. }
  9215. }
  9216. }
  9217. drawMesh(x, y, ib, vb, numElement, mat, shader, shaderValues, startIndex = 0) {
  9218. }
  9219. addRenderObject(o) {
  9220. this._submits[this._submits._length++] = o;
  9221. }
  9222. submitElement(start, end) {
  9223. var mainCtx = this.isMain;
  9224. var renderList = this._submits;
  9225. var ret = renderList._length;
  9226. end < 0 && (end = renderList._length);
  9227. var submit = SubmitBase.RENDERBASE;
  9228. while (start < end) {
  9229. this._renderNextSubmitIndex = start + 1;
  9230. if (renderList[start] === SubmitBase.RENDERBASE) {
  9231. start++;
  9232. continue;
  9233. }
  9234. SubmitBase.preRender = submit;
  9235. submit = renderList[start];
  9236. start += submit.renderSubmit();
  9237. }
  9238. return ret;
  9239. }
  9240. flush() {
  9241. this._clipID_Gen = 0;
  9242. var ret = this.submitElement(0, this._submits._length);
  9243. this._path && this._path.reset();
  9244. SkinMeshBuffer.instance && SkinMeshBuffer.getInstance().reset();
  9245. this._curSubmit = SubmitBase.RENDERBASE;
  9246. for (var i = 0, sz = this.meshlist.length; i < sz; i++) {
  9247. var curm = this.meshlist[i];
  9248. curm.canReuse ? (curm.releaseMesh()) : (curm.destroy());
  9249. }
  9250. this.meshlist.length = 0;
  9251. this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  9252. this._pathMesh = MeshVG.getAMesh(this.isMain);
  9253. this._triangleMesh = MeshTexture.getAMesh(this.isMain);
  9254. this.meshlist.push(this._mesh, this._pathMesh, this._triangleMesh);
  9255. this._flushCnt++;
  9256. if (this._flushCnt % 60 == 0 && this.isMain) {
  9257. if (TextRender.textRenderInst) {
  9258. TextRender.textRenderInst.GC();
  9259. }
  9260. }
  9261. return ret;
  9262. }
  9263. beginPath(convex = false) {
  9264. var tPath = this._getPath();
  9265. tPath.beginPath(convex);
  9266. }
  9267. closePath() {
  9268. this._path.closePath();
  9269. }
  9270. addPath(points, close, convex, dx, dy) {
  9271. var ci = 0;
  9272. for (var i = 0, sz = points.length / 2; i < sz; i++) {
  9273. var x1 = points[ci] + dx, y1 = points[ci + 1] + dy;
  9274. points[ci] = x1;
  9275. points[ci + 1] = y1;
  9276. ci += 2;
  9277. }
  9278. this._getPath().push(points, convex);
  9279. }
  9280. fill() {
  9281. var m = this._curMat;
  9282. var tPath = this._getPath();
  9283. var submit = this._curSubmit;
  9284. var sameKey = (submit._key.submitType === SubmitBase.KEY_VG && submit._key.blendShader === this._nBlendType);
  9285. sameKey && (sameKey = sameKey && this.isSameClipInfo(submit));
  9286. if (!sameKey) {
  9287. this._curSubmit = this.addVGSubmit(this._pathMesh);
  9288. }
  9289. var rgba = this.mixRGBandAlpha(this.fillStyle.toInt());
  9290. var curEleNum = 0;
  9291. var idx;
  9292. for (var i = 0, sz = tPath.paths.length; i < sz; i++) {
  9293. var p = tPath.paths[i];
  9294. var vertNum = p.path.length / 2;
  9295. if (vertNum < 3 || (vertNum == 3 && !p.convex))
  9296. continue;
  9297. var cpath = p.path.concat();
  9298. var pi = 0;
  9299. var xp, yp;
  9300. var _x, _y;
  9301. if (m._bTransform) {
  9302. for (pi = 0; pi < vertNum; pi++) {
  9303. xp = pi << 1;
  9304. yp = xp + 1;
  9305. _x = cpath[xp];
  9306. _y = cpath[yp];
  9307. cpath[xp] = m.a * _x + m.c * _y + m.tx;
  9308. cpath[yp] = m.b * _x + m.d * _y + m.ty;
  9309. }
  9310. }
  9311. else {
  9312. for (pi = 0; pi < vertNum; pi++) {
  9313. xp = pi << 1;
  9314. yp = xp + 1;
  9315. _x = cpath[xp];
  9316. _y = cpath[yp];
  9317. cpath[xp] = _x + m.tx;
  9318. cpath[yp] = _y + m.ty;
  9319. }
  9320. }
  9321. if (this._pathMesh.vertNum + vertNum > Context._MAXVERTNUM) {
  9322. this._curSubmit._numEle += curEleNum;
  9323. curEleNum = 0;
  9324. this._pathMesh = MeshVG.getAMesh(this.isMain);
  9325. this._curSubmit = this.addVGSubmit(this._pathMesh);
  9326. }
  9327. var curvert = this._pathMesh.vertNum;
  9328. if (p.convex) {
  9329. var faceNum = vertNum - 2;
  9330. idx = new Array(faceNum * 3);
  9331. var idxpos = 0;
  9332. for (var fi = 0; fi < faceNum; fi++) {
  9333. idx[idxpos++] = curvert;
  9334. idx[idxpos++] = fi + 1 + curvert;
  9335. idx[idxpos++] = fi + 2 + curvert;
  9336. }
  9337. }
  9338. else {
  9339. idx = Earcut.earcut(cpath, null, 2);
  9340. if (curvert > 0) {
  9341. for (var ii = 0; ii < idx.length; ii++) {
  9342. idx[ii] += curvert;
  9343. }
  9344. }
  9345. }
  9346. this._pathMesh.addVertAndIBToMesh(this, cpath, rgba, idx);
  9347. curEleNum += idx.length;
  9348. }
  9349. this._curSubmit._numEle += curEleNum;
  9350. }
  9351. addVGSubmit(mesh) {
  9352. var submit = Submit.createShape(this, mesh, 0, Value2D.create(ShaderDefines2D.PRIMITIVE, 0));
  9353. submit._key.submitType = SubmitBase.KEY_VG;
  9354. this._submits[this._submits._length++] = submit;
  9355. this._copyClipInfo(submit, this._globalClipMatrix);
  9356. return submit;
  9357. }
  9358. stroke() {
  9359. if (this.lineWidth > 0) {
  9360. var rgba = this.mixRGBandAlpha(this.strokeStyle._color.numColor);
  9361. var tPath = this._getPath();
  9362. var submit = this._curSubmit;
  9363. var sameKey = (submit._key.submitType === SubmitBase.KEY_VG && submit._key.blendShader === this._nBlendType);
  9364. sameKey && (sameKey = sameKey && this.isSameClipInfo(submit));
  9365. if (!sameKey) {
  9366. this._curSubmit = this.addVGSubmit(this._pathMesh);
  9367. }
  9368. var curEleNum = 0;
  9369. for (var i = 0, sz = tPath.paths.length; i < sz; i++) {
  9370. var p = tPath.paths[i];
  9371. if (p.path.length <= 0)
  9372. continue;
  9373. var idx = [];
  9374. var vertex = [];
  9375. var maxVertexNum = p.path.length * 2;
  9376. if (maxVertexNum < 2)
  9377. continue;
  9378. if (this._pathMesh.vertNum + maxVertexNum > Context._MAXVERTNUM) {
  9379. this._curSubmit._numEle += curEleNum;
  9380. curEleNum = 0;
  9381. this._pathMesh = MeshVG.getAMesh(this.isMain);
  9382. this.meshlist.push(this._pathMesh);
  9383. this._curSubmit = this.addVGSubmit(this._pathMesh);
  9384. }
  9385. BasePoly.createLine2(p.path, idx, this.lineWidth, this._pathMesh.vertNum, vertex, p.loop);
  9386. var ptnum = vertex.length / 2;
  9387. var m = this._curMat;
  9388. var pi = 0;
  9389. var xp, yp;
  9390. var _x, _y;
  9391. if (m._bTransform) {
  9392. for (pi = 0; pi < ptnum; pi++) {
  9393. xp = pi << 1;
  9394. yp = xp + 1;
  9395. _x = vertex[xp];
  9396. _y = vertex[yp];
  9397. vertex[xp] = m.a * _x + m.c * _y + m.tx;
  9398. vertex[yp] = m.b * _x + m.d * _y + m.ty;
  9399. }
  9400. }
  9401. else {
  9402. for (pi = 0; pi < ptnum; pi++) {
  9403. xp = pi << 1;
  9404. yp = xp + 1;
  9405. _x = vertex[xp];
  9406. _y = vertex[yp];
  9407. vertex[xp] = _x + m.tx;
  9408. vertex[yp] = _y + m.ty;
  9409. }
  9410. }
  9411. this._pathMesh.addVertAndIBToMesh(this, vertex, rgba, idx);
  9412. curEleNum += idx.length;
  9413. }
  9414. this._curSubmit._numEle += curEleNum;
  9415. }
  9416. }
  9417. moveTo(x, y) {
  9418. var tPath = this._getPath();
  9419. tPath.newPath();
  9420. tPath._lastOriX = x;
  9421. tPath._lastOriY = y;
  9422. tPath.addPoint(x, y);
  9423. }
  9424. lineTo(x, y) {
  9425. var tPath = this._getPath();
  9426. if (Math.abs(x - tPath._lastOriX) < 1e-3 && Math.abs(y - tPath._lastOriY) < 1e-3)
  9427. return;
  9428. tPath._lastOriX = x;
  9429. tPath._lastOriY = y;
  9430. tPath.addPoint(x, y);
  9431. }
  9432. arcTo(x1, y1, x2, y2, r) {
  9433. var i = 0;
  9434. var x = 0, y = 0;
  9435. var dx = this._path._lastOriX - x1;
  9436. var dy = this._path._lastOriY - y1;
  9437. var len1 = Math.sqrt(dx * dx + dy * dy);
  9438. if (len1 <= 0.000001) {
  9439. return;
  9440. }
  9441. var ndx = dx / len1;
  9442. var ndy = dy / len1;
  9443. var dx2 = x2 - x1;
  9444. var dy2 = y2 - y1;
  9445. var len22 = dx2 * dx2 + dy2 * dy2;
  9446. var len2 = Math.sqrt(len22);
  9447. if (len2 <= 0.000001) {
  9448. return;
  9449. }
  9450. var ndx2 = dx2 / len2;
  9451. var ndy2 = dy2 / len2;
  9452. var odx = ndx + ndx2;
  9453. var ody = ndy + ndy2;
  9454. var olen = Math.sqrt(odx * odx + ody * ody);
  9455. if (olen <= 0.000001) {
  9456. return;
  9457. }
  9458. var nOdx = odx / olen;
  9459. var nOdy = ody / olen;
  9460. var alpha = Math.acos(nOdx * ndx + nOdy * ndy);
  9461. var halfAng = Math.PI / 2 - alpha;
  9462. len1 = r / Math.tan(halfAng);
  9463. var ptx1 = len1 * ndx + x1;
  9464. var pty1 = len1 * ndy + y1;
  9465. var orilen = Math.sqrt(len1 * len1 + r * r);
  9466. var orix = x1 + nOdx * orilen;
  9467. var oriy = y1 + nOdy * orilen;
  9468. var dir = ndx * ndy2 - ndy * ndx2;
  9469. var fChgAng = 0;
  9470. var sinx = 0.0;
  9471. var cosx = 0.0;
  9472. if (dir >= 0) {
  9473. fChgAng = halfAng * 2;
  9474. var fda = fChgAng / Context.SEGNUM;
  9475. sinx = Math.sin(fda);
  9476. cosx = Math.cos(fda);
  9477. }
  9478. else {
  9479. fChgAng = -halfAng * 2;
  9480. fda = fChgAng / Context.SEGNUM;
  9481. sinx = Math.sin(fda);
  9482. cosx = Math.cos(fda);
  9483. }
  9484. var lastx = this._path._lastOriX, lasty = this._path._lastOriY;
  9485. var _x1 = ptx1, _y1 = pty1;
  9486. if (Math.abs(_x1 - this._path._lastOriX) > 0.1 || Math.abs(_y1 - this._path._lastOriY) > 0.1) {
  9487. x = _x1;
  9488. y = _y1;
  9489. lastx = _x1;
  9490. lasty = _y1;
  9491. this._path._lastOriX = x;
  9492. this._path._lastOriY = y;
  9493. this._path.addPoint(x, y);
  9494. }
  9495. var cvx = ptx1 - orix;
  9496. var cvy = pty1 - oriy;
  9497. for (i = 0; i < Context.SEGNUM; i++) {
  9498. var cx = cvx * cosx + cvy * sinx;
  9499. var cy = -cvx * sinx + cvy * cosx;
  9500. x = cx + orix;
  9501. y = cy + oriy;
  9502. if (Math.abs(lastx - x) > 0.1 || Math.abs(lasty - y) > 0.1) {
  9503. this._path._lastOriX = x;
  9504. this._path._lastOriY = y;
  9505. this._path.addPoint(x, y);
  9506. lastx = x;
  9507. lasty = y;
  9508. }
  9509. cvx = cx;
  9510. cvy = cy;
  9511. }
  9512. }
  9513. arc(cx, cy, r, startAngle, endAngle, counterclockwise = false, b = true) {
  9514. var a = 0, da = 0;
  9515. var dx = 0, dy = 0, x = 0, y = 0;
  9516. var i, ndivs;
  9517. da = endAngle - startAngle;
  9518. if (!counterclockwise) {
  9519. if (Math.abs(da) >= Math.PI * 2) {
  9520. da = Math.PI * 2;
  9521. }
  9522. else {
  9523. while (da < 0.0) {
  9524. da += Math.PI * 2;
  9525. }
  9526. }
  9527. }
  9528. else {
  9529. if (Math.abs(da) >= Math.PI * 2) {
  9530. da = -Math.PI * 2;
  9531. }
  9532. else {
  9533. while (da > 0.0) {
  9534. da -= Math.PI * 2;
  9535. }
  9536. }
  9537. }
  9538. var sx = this.getMatScaleX();
  9539. var sy = this.getMatScaleY();
  9540. var sr = r * (sx > sy ? sx : sy);
  9541. var cl = 2 * Math.PI * sr;
  9542. ndivs = (Math.max(cl / 10, 10)) | 0;
  9543. var tPath = this._getPath();
  9544. for (i = 0; i <= ndivs; i++) {
  9545. a = startAngle + da * (i / ndivs);
  9546. dx = Math.cos(a);
  9547. dy = Math.sin(a);
  9548. x = cx + dx * r;
  9549. y = cy + dy * r;
  9550. if (x != this._path._lastOriX || y != this._path._lastOriY) {
  9551. tPath.addPoint(x, y);
  9552. }
  9553. }
  9554. dx = Math.cos(endAngle);
  9555. dy = Math.sin(endAngle);
  9556. x = cx + dx * r;
  9557. y = cy + dy * r;
  9558. if (x != this._path._lastOriX || y != this._path._lastOriY) {
  9559. tPath.addPoint(x, y);
  9560. }
  9561. }
  9562. quadraticCurveTo(cpx, cpy, x, y) {
  9563. var tBezier = Bezier.I;
  9564. var tArray = tBezier.getBezierPoints([this._path._lastOriX, this._path._lastOriY, cpx, cpy, x, y], 30, 2);
  9565. for (var i = 0, n = tArray.length / 2; i < n; i++) {
  9566. this.lineTo(tArray[i * 2], tArray[i * 2 + 1]);
  9567. }
  9568. this.lineTo(x, y);
  9569. }
  9570. mixRGBandAlpha(color) {
  9571. return this._mixRGBandAlpha(color, this._shader2D.ALPHA);
  9572. }
  9573. _mixRGBandAlpha(color, alpha) {
  9574. if (alpha >= 1) {
  9575. return color;
  9576. }
  9577. var a = ((color & 0xff000000) >>> 24);
  9578. if (a != 0) {
  9579. a *= alpha;
  9580. }
  9581. else {
  9582. a = alpha * 255;
  9583. }
  9584. return (color & 0x00ffffff) | (a << 24);
  9585. }
  9586. strokeRect(x, y, width, height, parameterLineWidth) {
  9587. if (this.lineWidth > 0) {
  9588. var rgba = this.mixRGBandAlpha(this.strokeStyle._color.numColor);
  9589. var hw = this.lineWidth / 2;
  9590. this._fillRect(x - hw, y - hw, width + this.lineWidth, this.lineWidth, rgba);
  9591. this._fillRect(x - hw, y - hw + height, width + this.lineWidth, this.lineWidth, rgba);
  9592. this._fillRect(x - hw, y + hw, this.lineWidth, height - this.lineWidth, rgba);
  9593. this._fillRect(x - hw + width, y + hw, this.lineWidth, height - this.lineWidth, rgba);
  9594. }
  9595. }
  9596. clip() {
  9597. }
  9598. drawParticle(x, y, pt) {
  9599. pt.x = x;
  9600. pt.y = y;
  9601. this._submits[this._submits._length++] = pt;
  9602. }
  9603. _getPath() {
  9604. return this._path || (this._path = new Path());
  9605. }
  9606. get canvas() {
  9607. return this._canvas;
  9608. }
  9609. _fillTexture_h(tex, imgid, uv, oriw, orih, x, y, w) {
  9610. var stx = x;
  9611. var num = Math.floor(w / oriw);
  9612. var left = w % oriw;
  9613. for (var i = 0; i < num; i++) {
  9614. this._inner_drawTexture(tex, imgid, stx, y, oriw, orih, this._curMat, uv, 1, false);
  9615. stx += oriw;
  9616. }
  9617. if (left > 0) {
  9618. var du = uv[2] - uv[0];
  9619. var uvr = uv[0] + du * (left / oriw);
  9620. var tuv = Context.tmpuv1;
  9621. tuv[0] = uv[0];
  9622. tuv[1] = uv[1];
  9623. tuv[2] = uvr;
  9624. tuv[3] = uv[3];
  9625. tuv[4] = uvr;
  9626. tuv[5] = uv[5];
  9627. tuv[6] = uv[6];
  9628. tuv[7] = uv[7];
  9629. this._inner_drawTexture(tex, imgid, stx, y, left, orih, this._curMat, tuv, 1, false);
  9630. }
  9631. }
  9632. _fillTexture_v(tex, imgid, uv, oriw, orih, x, y, h) {
  9633. var sty = y;
  9634. var num = Math.floor(h / orih);
  9635. var left = h % orih;
  9636. for (var i = 0; i < num; i++) {
  9637. this._inner_drawTexture(tex, imgid, x, sty, oriw, orih, this._curMat, uv, 1, false);
  9638. sty += orih;
  9639. }
  9640. if (left > 0) {
  9641. var dv = uv[7] - uv[1];
  9642. var uvb = uv[1] + dv * (left / orih);
  9643. var tuv = Context.tmpuv1;
  9644. tuv[0] = uv[0];
  9645. tuv[1] = uv[1];
  9646. tuv[2] = uv[2];
  9647. tuv[3] = uv[3];
  9648. tuv[4] = uv[4];
  9649. tuv[5] = uvb;
  9650. tuv[6] = uv[6];
  9651. tuv[7] = uvb;
  9652. this._inner_drawTexture(tex, imgid, x, sty, oriw, left, this._curMat, tuv, 1, false);
  9653. }
  9654. }
  9655. drawTextureWithSizeGrid(tex, tx, ty, width, height, sizeGrid, gx, gy) {
  9656. if (!tex._getSource())
  9657. return;
  9658. tx += gx;
  9659. ty += gy;
  9660. var uv = tex.uv, w = tex.bitmap.width, h = tex.bitmap.height;
  9661. var top = sizeGrid[0];
  9662. var left = sizeGrid[3];
  9663. var d_top = top / h;
  9664. var d_left = left / w;
  9665. var right = sizeGrid[1];
  9666. var bottom = sizeGrid[2];
  9667. var d_right = right / w;
  9668. var d_bottom = bottom / h;
  9669. var repeat = sizeGrid[4];
  9670. var needClip = false;
  9671. if (width == w) {
  9672. left = right = 0;
  9673. }
  9674. if (height == h) {
  9675. top = bottom = 0;
  9676. }
  9677. if (left + right > width) {
  9678. var clipWidth = width;
  9679. needClip = true;
  9680. width = left + right;
  9681. this.save();
  9682. this.clipRect(0 + tx, 0 + ty, clipWidth, height);
  9683. }
  9684. var imgid = tex.bitmap.id;
  9685. var mat = this._curMat;
  9686. var tuv = this._tempUV;
  9687. var uvl = uv[0];
  9688. var uvt = uv[1];
  9689. var uvr = uv[4];
  9690. var uvb = uv[5];
  9691. var uvl_ = uvl;
  9692. var uvt_ = uvt;
  9693. var uvr_ = uvr;
  9694. var uvb_ = uvb;
  9695. if (left && top) {
  9696. uvr_ = uvl + d_left;
  9697. uvb_ = uvt + d_top;
  9698. tuv[0] = uvl, tuv[1] = uvt, tuv[2] = uvr_, tuv[3] = uvt,
  9699. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl, tuv[7] = uvb_;
  9700. this._inner_drawTexture(tex, imgid, tx, ty, left, top, mat, tuv, 1, false);
  9701. }
  9702. if (right && top) {
  9703. uvl_ = uvr - d_right;
  9704. uvt_ = uvt;
  9705. uvr_ = uvr;
  9706. uvb_ = uvt + d_top;
  9707. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9708. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9709. this._inner_drawTexture(tex, imgid, width - right + tx, 0 + ty, right, top, mat, tuv, 1, false);
  9710. }
  9711. if (left && bottom) {
  9712. uvl_ = uvl;
  9713. uvt_ = uvb - d_bottom;
  9714. uvr_ = uvl + d_left;
  9715. uvb_ = uvb;
  9716. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9717. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9718. this._inner_drawTexture(tex, imgid, 0 + tx, height - bottom + ty, left, bottom, mat, tuv, 1, false);
  9719. }
  9720. if (right && bottom) {
  9721. uvl_ = uvr - d_right;
  9722. uvt_ = uvb - d_bottom;
  9723. uvr_ = uvr;
  9724. uvb_ = uvb;
  9725. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9726. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9727. this._inner_drawTexture(tex, imgid, width - right + tx, height - bottom + ty, right, bottom, mat, tuv, 1, false);
  9728. }
  9729. if (top) {
  9730. uvl_ = uvl + d_left;
  9731. uvt_ = uvt;
  9732. uvr_ = uvr - d_right;
  9733. uvb_ = uvt + d_top;
  9734. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9735. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9736. if (repeat) {
  9737. this._fillTexture_h(tex, imgid, tuv, tex.width - left - right, top, left + tx, ty, width - left - right);
  9738. }
  9739. else {
  9740. this._inner_drawTexture(tex, imgid, left + tx, ty, width - left - right, top, mat, tuv, 1, false);
  9741. }
  9742. }
  9743. if (bottom) {
  9744. uvl_ = uvl + d_left;
  9745. uvt_ = uvb - d_bottom;
  9746. uvr_ = uvr - d_right;
  9747. uvb_ = uvb;
  9748. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9749. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9750. if (repeat) {
  9751. this._fillTexture_h(tex, imgid, tuv, tex.width - left - right, bottom, left + tx, height - bottom + ty, width - left - right);
  9752. }
  9753. else {
  9754. this._inner_drawTexture(tex, imgid, left + tx, height - bottom + ty, width - left - right, bottom, mat, tuv, 1, false);
  9755. }
  9756. }
  9757. if (left) {
  9758. uvl_ = uvl;
  9759. uvt_ = uvt + d_top;
  9760. uvr_ = uvl + d_left;
  9761. uvb_ = uvb - d_bottom;
  9762. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9763. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9764. if (repeat) {
  9765. this._fillTexture_v(tex, imgid, tuv, left, tex.height - top - bottom, tx, top + ty, height - top - bottom);
  9766. }
  9767. else {
  9768. this._inner_drawTexture(tex, imgid, tx, top + ty, left, height - top - bottom, mat, tuv, 1, false);
  9769. }
  9770. }
  9771. if (right) {
  9772. uvl_ = uvr - d_right;
  9773. uvt_ = uvt + d_top;
  9774. uvr_ = uvr;
  9775. uvb_ = uvb - d_bottom;
  9776. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9777. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9778. if (repeat) {
  9779. this._fillTexture_v(tex, imgid, tuv, right, tex.height - top - bottom, width - right + tx, top + ty, height - top - bottom);
  9780. }
  9781. else {
  9782. this._inner_drawTexture(tex, imgid, width - right + tx, top + ty, right, height - top - bottom, mat, tuv, 1, false);
  9783. }
  9784. }
  9785. uvl_ = uvl + d_left;
  9786. uvt_ = uvt + d_top;
  9787. uvr_ = uvr - d_right;
  9788. uvb_ = uvb - d_bottom;
  9789. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9790. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9791. if (repeat) {
  9792. var tuvr = Context.tmpUVRect;
  9793. tuvr[0] = uvl_;
  9794. tuvr[1] = uvt_;
  9795. tuvr[2] = uvr_ - uvl_;
  9796. tuvr[3] = uvb_ - uvt_;
  9797. this._fillTexture(tex, tex.width - left - right, tex.height - top - bottom, tuvr, left + tx, top + ty, width - left - right, height - top - bottom, 'repeat', 0, 0);
  9798. }
  9799. else {
  9800. this._inner_drawTexture(tex, imgid, left + tx, top + ty, width - left - right, height - top - bottom, mat, tuv, 1, false);
  9801. }
  9802. if (needClip)
  9803. this.restore();
  9804. }
  9805. }
  9806. Context.ENUM_TEXTALIGN_DEFAULT = 0;
  9807. Context.ENUM_TEXTALIGN_CENTER = 1;
  9808. Context.ENUM_TEXTALIGN_RIGHT = 2;
  9809. Context._SUBMITVBSIZE = 32000;
  9810. Context._MAXSIZE = 99999999;
  9811. Context._MAXVERTNUM = 65535;
  9812. Context.MAXCLIPRECT = null;
  9813. Context._COUNT = 0;
  9814. Context.SEGNUM = 32;
  9815. Context._contextcount = 0;
  9816. Context.PI2 = 2 * Math.PI;
  9817. Context._textRender = null;
  9818. Context.tmpuv1 = [0, 0, 0, 0, 0, 0, 0, 0];
  9819. Context.tmpUV = [0, 0, 0, 0, 0, 0, 0, 0];
  9820. Context.tmpUVRect = [0, 0, 0, 0];
  9821. class ContextParams {
  9822. constructor() {
  9823. this.lineWidth = 1;
  9824. }
  9825. clear() {
  9826. this.lineWidth = 1;
  9827. this.textAlign = this.textBaseline = null;
  9828. }
  9829. make() {
  9830. return this === ContextParams.DEFAULT ? new ContextParams() : this;
  9831. }
  9832. }
  9833. class WebGL {
  9834. static _uint8ArraySlice() {
  9835. var _this = this;
  9836. var sz = _this.length;
  9837. var dec = new Uint8Array(_this.length);
  9838. for (var i = 0; i < sz; i++)
  9839. dec[i] = _this[i];
  9840. return dec;
  9841. }
  9842. static _float32ArraySlice() {
  9843. var _this = this;
  9844. var sz = _this.length;
  9845. var dec = new Float32Array(_this.length);
  9846. for (var i = 0; i < sz; i++)
  9847. dec[i] = _this[i];
  9848. return dec;
  9849. }
  9850. static _uint16ArraySlice(...arg) {
  9851. var _this = this;
  9852. var sz;
  9853. var dec;
  9854. var i;
  9855. if (arg.length === 0) {
  9856. sz = _this.length;
  9857. dec = new Uint16Array(sz);
  9858. for (i = 0; i < sz; i++)
  9859. dec[i] = _this[i];
  9860. }
  9861. else if (arg.length === 2) {
  9862. var start = arg[0];
  9863. var end = arg[1];
  9864. if (end > start) {
  9865. sz = end - start;
  9866. dec = new Uint16Array(sz);
  9867. for (i = start; i < end; i++)
  9868. dec[i - start] = _this[i];
  9869. }
  9870. else {
  9871. dec = new Uint16Array(0);
  9872. }
  9873. }
  9874. return dec;
  9875. }
  9876. static _nativeRender_enable() {
  9877. }
  9878. static enable() {
  9879. return true;
  9880. }
  9881. static inner_enable() {
  9882. Float32Array.prototype.slice || (Float32Array.prototype.slice = WebGL._float32ArraySlice);
  9883. Uint16Array.prototype.slice || (Uint16Array.prototype.slice = WebGL._uint16ArraySlice);
  9884. Uint8Array.prototype.slice || (Uint8Array.prototype.slice = WebGL._uint8ArraySlice);
  9885. return true;
  9886. }
  9887. static onStageResize(width, height) {
  9888. if (WebGLContext.mainContext == null)
  9889. return;
  9890. WebGLContext.mainContext.viewport(0, 0, width, height);
  9891. RenderState2D.width = width;
  9892. RenderState2D.height = height;
  9893. }
  9894. }
  9895. WebGL._isWebGL2 = false;
  9896. WebGL.isNativeRender_enable = false;
  9897. class VertexArrayObject {
  9898. constructor() {
  9899. }
  9900. }
  9901. (function () {
  9902. var glErrorShadow = {};
  9903. function error(msg) {
  9904. if (window.console && window.console.error) {
  9905. window.console.error(msg);
  9906. }
  9907. }
  9908. function log(msg) {
  9909. if (window.console && window.console.log) {
  9910. window.console.log(msg);
  9911. }
  9912. }
  9913. function synthesizeGLError(err, opt_msg) {
  9914. glErrorShadow[err] = true;
  9915. if (opt_msg !== undefined) {
  9916. error(opt_msg);
  9917. }
  9918. }
  9919. function wrapGLError(gl) {
  9920. var f = gl.getError;
  9921. gl.getError = function () {
  9922. var err;
  9923. do {
  9924. err = f.apply(gl);
  9925. if (err != gl.NO_ERROR) {
  9926. glErrorShadow[err] = true;
  9927. }
  9928. } while (err != gl.NO_ERROR);
  9929. for (var err1 in glErrorShadow) {
  9930. if (glErrorShadow[err1]) {
  9931. delete glErrorShadow[err1];
  9932. return parseInt(err1);
  9933. }
  9934. }
  9935. return gl.NO_ERROR;
  9936. };
  9937. }
  9938. var WebGLVertexArrayObjectOES = function WebGLVertexArrayObjectOES(ext) {
  9939. var gl = ext.gl;
  9940. this.ext = ext;
  9941. this.isAlive = true;
  9942. this.hasBeenBound = false;
  9943. this.elementArrayBuffer = null;
  9944. this.attribs = new Array(ext.maxVertexAttribs);
  9945. for (var n = 0; n < this.attribs.length; n++) {
  9946. var attrib = new WebGLVertexArrayObjectOES.VertexAttrib(gl);
  9947. this.attribs[n] = attrib;
  9948. }
  9949. this.maxAttrib = 0;
  9950. };
  9951. WebGLVertexArrayObjectOES.VertexAttrib = function VertexAttrib(gl) {
  9952. this.enabled = false;
  9953. this.buffer = null;
  9954. this.size = 4;
  9955. this.type = gl.FLOAT;
  9956. this.normalized = false;
  9957. this.stride = 16;
  9958. this.offset = 0;
  9959. this.cached = "";
  9960. this.recache();
  9961. };
  9962. WebGLVertexArrayObjectOES.VertexAttrib.prototype.recache = function recache() {
  9963. this.cached = [this.size, this.type, this.normalized, this.stride, this.offset].join(":");
  9964. };
  9965. var OESVertexArrayObject = function OESVertexArrayObject(gl) {
  9966. var self = this;
  9967. this.gl = gl;
  9968. wrapGLError(gl);
  9969. var original = this.original = {
  9970. getParameter: gl.getParameter,
  9971. enableVertexAttribArray: gl.enableVertexAttribArray,
  9972. disableVertexAttribArray: gl.disableVertexAttribArray,
  9973. bindBuffer: gl.bindBuffer,
  9974. getVertexAttrib: gl.getVertexAttrib,
  9975. vertexAttribPointer: gl.vertexAttribPointer
  9976. };
  9977. gl.getParameter = function getParameter(pname) {
  9978. if (pname == self.VERTEX_ARRAY_BINDING_OES) {
  9979. if (self.currentVertexArrayObject == self.defaultVertexArrayObject) {
  9980. return null;
  9981. }
  9982. else {
  9983. return self.currentVertexArrayObject;
  9984. }
  9985. }
  9986. return original.getParameter.apply(this, arguments);
  9987. };
  9988. gl.enableVertexAttribArray = function enableVertexAttribArray(index) {
  9989. var vao = self.currentVertexArrayObject;
  9990. vao.maxAttrib = Math.max(vao.maxAttrib, index);
  9991. var attrib = vao.attribs[index];
  9992. attrib.enabled = true;
  9993. return original.enableVertexAttribArray.apply(this, arguments);
  9994. };
  9995. gl.disableVertexAttribArray = function disableVertexAttribArray(index) {
  9996. var vao = self.currentVertexArrayObject;
  9997. vao.maxAttrib = Math.max(vao.maxAttrib, index);
  9998. var attrib = vao.attribs[index];
  9999. attrib.enabled = false;
  10000. return original.disableVertexAttribArray.apply(this, arguments);
  10001. };
  10002. gl.bindBuffer = function bindBuffer(target, buffer) {
  10003. switch (target) {
  10004. case gl.ARRAY_BUFFER:
  10005. self.currentArrayBuffer = buffer;
  10006. break;
  10007. case gl.ELEMENT_ARRAY_BUFFER:
  10008. self.currentVertexArrayObject.elementArrayBuffer = buffer;
  10009. break;
  10010. }
  10011. return original.bindBuffer.apply(this, arguments);
  10012. };
  10013. gl.getVertexAttrib = function getVertexAttrib(index, pname) {
  10014. var vao = self.currentVertexArrayObject;
  10015. var attrib = vao.attribs[index];
  10016. switch (pname) {
  10017. case gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
  10018. return attrib.buffer;
  10019. case gl.VERTEX_ATTRIB_ARRAY_ENABLED:
  10020. return attrib.enabled;
  10021. case gl.VERTEX_ATTRIB_ARRAY_SIZE:
  10022. return attrib.size;
  10023. case gl.VERTEX_ATTRIB_ARRAY_STRIDE:
  10024. return attrib.stride;
  10025. case gl.VERTEX_ATTRIB_ARRAY_TYPE:
  10026. return attrib.type;
  10027. case gl.VERTEX_ATTRIB_ARRAY_NORMALIZED:
  10028. return attrib.normalized;
  10029. default:
  10030. return original.getVertexAttrib.apply(this, arguments);
  10031. }
  10032. };
  10033. gl.vertexAttribPointer = function vertexAttribPointer(indx, size, type, normalized, stride, offset) {
  10034. var vao = self.currentVertexArrayObject;
  10035. vao.maxAttrib = Math.max(vao.maxAttrib, indx);
  10036. var attrib = vao.attribs[indx];
  10037. attrib.buffer = self.currentArrayBuffer;
  10038. attrib.size = size;
  10039. attrib.type = type;
  10040. attrib.normalized = normalized;
  10041. attrib.stride = stride;
  10042. attrib.offset = offset;
  10043. attrib.recache();
  10044. return original.vertexAttribPointer.apply(this, arguments);
  10045. };
  10046. if (gl.instrumentExtension) {
  10047. gl.instrumentExtension(this, "OES_vertex_array_object");
  10048. }
  10049. gl.canvas.addEventListener('webglcontextrestored', function () {
  10050. log("OESVertexArrayObject emulation library context restored");
  10051. self.reset_();
  10052. }, true);
  10053. this.reset_();
  10054. };
  10055. OESVertexArrayObject.prototype.VERTEX_ARRAY_BINDING_OES = 0x85B5;
  10056. OESVertexArrayObject.prototype.reset_ = function reset_() {
  10057. var contextWasLost = this.vertexArrayObjects !== undefined;
  10058. if (contextWasLost) {
  10059. for (var ii = 0; ii < this.vertexArrayObjects.length; ++ii) {
  10060. this.vertexArrayObjects.isAlive = false;
  10061. }
  10062. }
  10063. var gl = this.gl;
  10064. this.maxVertexAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
  10065. this.defaultVertexArrayObject = new WebGLVertexArrayObjectOES(this);
  10066. this.currentVertexArrayObject = null;
  10067. this.currentArrayBuffer = null;
  10068. this.vertexArrayObjects = [this.defaultVertexArrayObject];
  10069. this.bindVertexArrayOES(null);
  10070. };
  10071. OESVertexArrayObject.prototype.createVertexArrayOES = function createVertexArrayOES() {
  10072. var arrayObject = new WebGLVertexArrayObjectOES(this);
  10073. this.vertexArrayObjects.push(arrayObject);
  10074. return arrayObject;
  10075. };
  10076. OESVertexArrayObject.prototype.deleteVertexArrayOES = function deleteVertexArrayOES(arrayObject) {
  10077. arrayObject.isAlive = false;
  10078. this.vertexArrayObjects.splice(this.vertexArrayObjects.indexOf(arrayObject), 1);
  10079. if (this.currentVertexArrayObject == arrayObject) {
  10080. this.bindVertexArrayOES(null);
  10081. }
  10082. };
  10083. OESVertexArrayObject.prototype.isVertexArrayOES = function isVertexArrayOES(arrayObject) {
  10084. if (arrayObject && arrayObject instanceof WebGLVertexArrayObjectOES) {
  10085. if (arrayObject.hasBeenBound && arrayObject.ext == this) {
  10086. return true;
  10087. }
  10088. }
  10089. return false;
  10090. };
  10091. OESVertexArrayObject.prototype.bindVertexArrayOES = function bindVertexArrayOES(arrayObject) {
  10092. var gl = this.gl;
  10093. if (arrayObject && !arrayObject.isAlive) {
  10094. synthesizeGLError(gl.INVALID_OPERATION, "bindVertexArrayOES: attempt to bind deleted arrayObject");
  10095. return;
  10096. }
  10097. var original = this.original;
  10098. var oldVAO = this.currentVertexArrayObject;
  10099. this.currentVertexArrayObject = arrayObject || this.defaultVertexArrayObject;
  10100. this.currentVertexArrayObject.hasBeenBound = true;
  10101. var newVAO = this.currentVertexArrayObject;
  10102. if (oldVAO == newVAO) {
  10103. return;
  10104. }
  10105. if (!oldVAO || newVAO.elementArrayBuffer != oldVAO.elementArrayBuffer) {
  10106. original.bindBuffer.call(gl, gl.ELEMENT_ARRAY_BUFFER, newVAO.elementArrayBuffer);
  10107. }
  10108. var currentBinding = this.currentArrayBuffer;
  10109. var maxAttrib = Math.max(oldVAO ? oldVAO.maxAttrib : 0, newVAO.maxAttrib);
  10110. for (var n = 0; n <= maxAttrib; n++) {
  10111. var attrib = newVAO.attribs[n];
  10112. var oldAttrib = oldVAO ? oldVAO.attribs[n] : null;
  10113. if (!oldVAO || attrib.enabled != oldAttrib.enabled) {
  10114. if (attrib.enabled) {
  10115. original.enableVertexAttribArray.call(gl, n);
  10116. }
  10117. else {
  10118. original.disableVertexAttribArray.call(gl, n);
  10119. }
  10120. }
  10121. if (attrib.enabled) {
  10122. var bufferChanged = false;
  10123. if (!oldVAO || attrib.buffer != oldAttrib.buffer) {
  10124. if (currentBinding != attrib.buffer) {
  10125. original.bindBuffer.call(gl, gl.ARRAY_BUFFER, attrib.buffer);
  10126. currentBinding = attrib.buffer;
  10127. }
  10128. bufferChanged = true;
  10129. }
  10130. if (bufferChanged || attrib.cached != oldAttrib.cached) {
  10131. original.vertexAttribPointer.call(gl, n, attrib.size, attrib.type, attrib.normalized, attrib.stride, attrib.offset);
  10132. }
  10133. }
  10134. }
  10135. if (this.currentArrayBuffer != currentBinding) {
  10136. original.bindBuffer.call(gl, gl.ARRAY_BUFFER, this.currentArrayBuffer);
  10137. }
  10138. };
  10139. window._setupVertexArrayObject = function (gl) {
  10140. var original_getSupportedExtensions = gl.getSupportedExtensions;
  10141. gl.getSupportedExtensions = function getSupportedExtensions() {
  10142. var list = original_getSupportedExtensions.call(this) || [];
  10143. if (list.indexOf("OES_vertex_array_object") < 0) {
  10144. list.push("OES_vertex_array_object");
  10145. }
  10146. return list;
  10147. };
  10148. var original_getExtension = gl.getExtension;
  10149. gl.getExtension = function getExtension(name) {
  10150. var ext = original_getExtension.call(this, name);
  10151. if (ext) {
  10152. return ext;
  10153. }
  10154. if (name !== "OES_vertex_array_object") {
  10155. return null;
  10156. }
  10157. if (!this.__OESVertexArrayObject) {
  10158. console.log("Setup OES_vertex_array_object polyfill");
  10159. this.__OESVertexArrayObject = new OESVertexArrayObject(this);
  10160. }
  10161. return this.__OESVertexArrayObject;
  10162. };
  10163. };
  10164. window._forceSetupVertexArrayObject = function (gl) {
  10165. var original_getSupportedExtensions = gl.getSupportedExtensions;
  10166. gl.getSupportedExtensions = function getSupportedExtensions() {
  10167. var list = original_getSupportedExtensions.call(this) || [];
  10168. if (list.indexOf("OES_vertex_array_object") < 0) {
  10169. list.push("OES_vertex_array_object");
  10170. }
  10171. return list;
  10172. };
  10173. var original_getExtension = gl.getExtension;
  10174. gl.getExtension = function getExtension(name) {
  10175. if (name === "OES_vertex_array_object") {
  10176. if (!this.__OESVertexArrayObject) {
  10177. console.log("Setup OES_vertex_array_object polyfill");
  10178. this.__OESVertexArrayObject = new OESVertexArrayObject(this);
  10179. }
  10180. return this.__OESVertexArrayObject;
  10181. }
  10182. else {
  10183. var ext = original_getExtension.call(this, name);
  10184. if (ext) {
  10185. return ext;
  10186. }
  10187. else {
  10188. return null;
  10189. }
  10190. }
  10191. };
  10192. };
  10193. }());
  10194. class LayaGPU {
  10195. constructor(gl, isWebGL2) {
  10196. this._gl = null;
  10197. this._vaoExt = null;
  10198. this._angleInstancedArrays = null;
  10199. this._isWebGL2 = false;
  10200. this._oesTextureHalfFloat = null;
  10201. this._oesTextureHalfFloatLinear = null;
  10202. this._oesTextureFloat = null;
  10203. this._extTextureFilterAnisotropic = null;
  10204. this._compressedTextureS3tc = null;
  10205. this._compressedTexturePvrtc = null;
  10206. this._compressedTextureEtc1 = null;
  10207. this._gl = gl;
  10208. this._isWebGL2 = isWebGL2;
  10209. try {
  10210. var precisionFormat = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT);
  10211. precisionFormat.precision ? (WebGL.shaderHighPrecision = true) : WebGL.shaderHighPrecision = false;
  10212. }
  10213. catch (e) {
  10214. }
  10215. if (!isWebGL2) {
  10216. var forceVAO = LayaGPU._forceSupportVAOPlatform();
  10217. if (!ILaya.Render.isConchApp) {
  10218. if (window._setupVertexArrayObject) {
  10219. if (forceVAO)
  10220. window._forceSetupVertexArrayObject(gl);
  10221. else
  10222. window._setupVertexArrayObject(gl);
  10223. }
  10224. }
  10225. this._vaoExt = this._getExtension("OES_vertex_array_object");
  10226. if (!forceVAO)
  10227. this._angleInstancedArrays = this._getExtension("ANGLE_instanced_arrays");
  10228. this._oesTextureHalfFloat = this._getExtension("OES_texture_half_float");
  10229. this._oesTextureHalfFloatLinear = this._getExtension("OES_texture_half_float_linear");
  10230. this._oesTextureFloat = this._getExtension("OES_texture_float");
  10231. }
  10232. else {
  10233. this._getExtension("EXT_color_buffer_float");
  10234. }
  10235. this._extTextureFilterAnisotropic = this._getExtension("EXT_texture_filter_anisotropic");
  10236. this._compressedTextureS3tc = this._getExtension("WEBGL_compressed_texture_s3tc");
  10237. this._compressedTexturePvrtc = this._getExtension("WEBGL_compressed_texture_pvrtc");
  10238. this._compressedTextureEtc1 = this._getExtension("WEBGL_compressed_texture_etc1");
  10239. }
  10240. static _forceSupportVAOPlatform() {
  10241. let Browser = ILaya.Browser;
  10242. return Browser.onBDMiniGame || Browser.onQGMiniGame;
  10243. }
  10244. _getExtension(name) {
  10245. var prefixes = LayaGPU._extentionVendorPrefixes;
  10246. for (var k in prefixes) {
  10247. var ext = this._gl.getExtension(prefixes[k] + name);
  10248. if (ext)
  10249. return ext;
  10250. }
  10251. return null;
  10252. }
  10253. createVertexArray() {
  10254. if (this._isWebGL2)
  10255. return this._gl.createVertexArray();
  10256. else
  10257. return this._vaoExt.createVertexArrayOES();
  10258. }
  10259. bindVertexArray(vertexArray) {
  10260. if (this._isWebGL2)
  10261. this._gl.bindVertexArray(vertexArray);
  10262. else
  10263. this._vaoExt.bindVertexArrayOES(vertexArray);
  10264. }
  10265. deleteVertexArray(vertexArray) {
  10266. if (this._isWebGL2)
  10267. this._gl.deleteVertexArray(vertexArray);
  10268. else
  10269. this._vaoExt.deleteVertexArrayOES(vertexArray);
  10270. }
  10271. isVertexArray(vertexArray) {
  10272. if (this._isWebGL2)
  10273. this._gl.isVertexArray(vertexArray);
  10274. else
  10275. this._vaoExt.isVertexArrayOES(vertexArray);
  10276. }
  10277. drawElementsInstanced(mode, count, type, offset, instanceCount) {
  10278. if (this._isWebGL2)
  10279. this._gl.drawElementsInstanced(mode, count, type, offset, instanceCount);
  10280. else
  10281. this._angleInstancedArrays.drawElementsInstancedANGLE(mode, count, type, offset, instanceCount);
  10282. }
  10283. drawArraysInstanced(mode, first, count, instanceCount) {
  10284. if (this._isWebGL2)
  10285. this._gl.drawArraysInstanced(mode, first, count, instanceCount);
  10286. else
  10287. this._angleInstancedArrays.drawArraysInstancedANGLE(mode, first, count, instanceCount);
  10288. }
  10289. vertexAttribDivisor(index, divisor) {
  10290. if (this._isWebGL2)
  10291. this._gl.vertexAttribDivisor(index, divisor);
  10292. else
  10293. this._angleInstancedArrays.vertexAttribDivisorANGLE(index, divisor);
  10294. }
  10295. supportInstance() {
  10296. if (this._isWebGL2 || this._angleInstancedArrays)
  10297. return true;
  10298. else
  10299. return false;
  10300. }
  10301. }
  10302. LayaGPU._extentionVendorPrefixes = ["", "WEBKIT_", "MOZ_"];
  10303. class Render {
  10304. constructor(width, height, mainCanv) {
  10305. this._timeId = 0;
  10306. Render._mainCanvas = mainCanv;
  10307. let source = Render._mainCanvas.source;
  10308. source.id = "layaCanvas";
  10309. source.width = width;
  10310. source.height = height;
  10311. if (Render.isConchApp) {
  10312. document.body.appendChild(source);
  10313. }
  10314. this.initRender(Render._mainCanvas, width, height);
  10315. window.requestAnimationFrame(loop);
  10316. function loop(stamp) {
  10317. ILaya.stage._loop();
  10318. window.requestAnimationFrame(loop);
  10319. }
  10320. ILaya.stage.on("visibilitychange", this, this._onVisibilitychange);
  10321. }
  10322. _onVisibilitychange() {
  10323. if (!ILaya.stage.isVisibility) {
  10324. this._timeId = window.setInterval(this._enterFrame, 1000);
  10325. }
  10326. else if (this._timeId != 0) {
  10327. window.clearInterval(this._timeId);
  10328. }
  10329. }
  10330. initRender(canvas, w, h) {
  10331. function getWebGLContext(canvas) {
  10332. var gl;
  10333. var names = ["webgl2", "webgl", "experimental-webgl", "webkit-3d", "moz-webgl"];
  10334. if (!Config.useWebGL2 || Browser.onBDMiniGame) {
  10335. names.shift();
  10336. }
  10337. for (var i = 0; i < names.length; i++) {
  10338. try {
  10339. gl = canvas.getContext(names[i], { stencil: Config.isStencil, alpha: Config.isAlpha, antialias: Config.isAntialias, premultipliedAlpha: Config.premultipliedAlpha, preserveDrawingBuffer: Config.preserveDrawingBuffer });
  10340. }
  10341. catch (e) {
  10342. }
  10343. if (gl) {
  10344. (names[i] === 'webgl2') && (WebGL._isWebGL2 = true);
  10345. return gl;
  10346. }
  10347. }
  10348. return null;
  10349. }
  10350. var gl = LayaGL.instance = WebGLContext.mainContext = getWebGLContext(Render._mainCanvas.source);
  10351. if (!gl)
  10352. return false;
  10353. LayaGL.instance = gl;
  10354. LayaGL.layaGPUInstance = new LayaGPU(gl, WebGL._isWebGL2);
  10355. canvas.size(w, h);
  10356. Context.__init__();
  10357. SubmitBase.__init__();
  10358. var ctx = new Context();
  10359. ctx.isMain = true;
  10360. Render._context = ctx;
  10361. canvas._setContext(ctx);
  10362. ShaderDefines2D.__init__();
  10363. Value2D.__init__();
  10364. Shader2D.__init__();
  10365. Buffer2D.__int__(gl);
  10366. BlendMode._init_(gl);
  10367. return true;
  10368. }
  10369. _enterFrame(e = null) {
  10370. ILaya.stage._loop();
  10371. }
  10372. static get context() {
  10373. return Render._context;
  10374. }
  10375. static get canvas() {
  10376. return Render._mainCanvas.source;
  10377. }
  10378. }
  10379. Render.supportWebGLPlusCulling = false;
  10380. Render.supportWebGLPlusAnimation = false;
  10381. Render.supportWebGLPlusRendering = false;
  10382. Render.isConchApp = false;
  10383. {
  10384. Render.isConchApp = (window.conch != null);
  10385. if (Render.isConchApp) {
  10386. Render.supportWebGLPlusCulling = false;
  10387. Render.supportWebGLPlusAnimation = true;
  10388. Render.supportWebGLPlusRendering = true;
  10389. }
  10390. else if (window.qq != null && window.qq.webglPlus != null) {
  10391. Render.supportWebGLPlusCulling = false;
  10392. Render.supportWebGLPlusAnimation = true;
  10393. Render.supportWebGLPlusRendering = true;
  10394. }
  10395. }
  10396. class DrawTrianglesCmd {
  10397. static create(texture, x, y, vertices, uvs, indices, matrix, alpha, color, blendMode, colorNum) {
  10398. var cmd = Pool.getItemByClass("DrawTrianglesCmd", DrawTrianglesCmd);
  10399. cmd.texture = texture;
  10400. cmd.x = x;
  10401. cmd.y = y;
  10402. cmd.vertices = vertices;
  10403. cmd.uvs = uvs;
  10404. cmd.indices = indices;
  10405. cmd.matrix = matrix;
  10406. cmd.alpha = alpha;
  10407. if (color) {
  10408. cmd.color = new ColorFilter();
  10409. var c = ColorUtils.create(color).arrColor;
  10410. cmd.color.color(c[0] * 255, c[1] * 255, c[2] * 255, c[3] * 255);
  10411. }
  10412. cmd.blendMode = blendMode;
  10413. cmd.colorNum = colorNum;
  10414. return cmd;
  10415. }
  10416. recover() {
  10417. this.texture = null;
  10418. this.vertices = null;
  10419. this.uvs = null;
  10420. this.indices = null;
  10421. this.matrix = null;
  10422. Pool.recover("DrawTrianglesCmd", this);
  10423. }
  10424. run(context, gx, gy) {
  10425. context.drawTriangles(this.texture, this.x + gx, this.y + gy, this.vertices, this.uvs, this.indices, this.matrix, this.alpha, this.color, this.blendMode, this.colorNum);
  10426. }
  10427. get cmdID() {
  10428. return DrawTrianglesCmd.ID;
  10429. }
  10430. }
  10431. DrawTrianglesCmd.ID = "DrawTriangles";
  10432. class Draw9GridTexture {
  10433. constructor() {
  10434. }
  10435. static create(texture, x, y, width, height, sizeGrid) {
  10436. var cmd = Pool.getItemByClass("Draw9GridTexture", Draw9GridTexture);
  10437. cmd.texture = texture;
  10438. texture._addReference();
  10439. cmd.x = x;
  10440. cmd.y = y;
  10441. cmd.width = width;
  10442. cmd.height = height;
  10443. cmd.sizeGrid = sizeGrid;
  10444. return cmd;
  10445. }
  10446. recover() {
  10447. this.texture._removeReference();
  10448. Pool.recover("Draw9GridTexture", this);
  10449. }
  10450. run(context, gx, gy) {
  10451. context.drawTextureWithSizeGrid(this.texture, this.x, this.y, this.width, this.height, this.sizeGrid, gx, gy);
  10452. }
  10453. get cmdID() {
  10454. return Draw9GridTexture.ID;
  10455. }
  10456. }
  10457. Draw9GridTexture.ID = "Draw9GridTexture";
  10458. class GraphicsBounds {
  10459. constructor() {
  10460. this._cacheBoundsType = false;
  10461. }
  10462. destroy() {
  10463. this._graphics = null;
  10464. this._cacheBoundsType = false;
  10465. if (this._temp)
  10466. this._temp.length = 0;
  10467. if (this._rstBoundPoints)
  10468. this._rstBoundPoints.length = 0;
  10469. if (this._bounds)
  10470. this._bounds.recover();
  10471. this._bounds = null;
  10472. Pool.recover("GraphicsBounds", this);
  10473. }
  10474. static create() {
  10475. return Pool.getItemByClass("GraphicsBounds", GraphicsBounds);
  10476. }
  10477. reset() {
  10478. this._temp && (this._temp.length = 0);
  10479. }
  10480. getBounds(realSize = false) {
  10481. if (!this._bounds || !this._temp || this._temp.length < 1 || realSize != this._cacheBoundsType) {
  10482. this._bounds = Rectangle._getWrapRec(this.getBoundPoints(realSize), this._bounds);
  10483. }
  10484. this._cacheBoundsType = realSize;
  10485. return this._bounds;
  10486. }
  10487. getBoundPoints(realSize = false) {
  10488. if (!this._temp || this._temp.length < 1 || realSize != this._cacheBoundsType)
  10489. this._temp = this._getCmdPoints(realSize);
  10490. this._cacheBoundsType = realSize;
  10491. return this._rstBoundPoints = Utils.copyArray(this._rstBoundPoints, this._temp);
  10492. }
  10493. _getCmdPoints(realSize = false) {
  10494. var cmds = this._graphics.cmds;
  10495. var rst;
  10496. rst = this._temp || (this._temp = []);
  10497. rst.length = 0;
  10498. if (!cmds && this._graphics._one != null) {
  10499. GraphicsBounds._tempCmds.length = 0;
  10500. GraphicsBounds._tempCmds.push(this._graphics._one);
  10501. cmds = GraphicsBounds._tempCmds;
  10502. }
  10503. if (!cmds)
  10504. return rst;
  10505. var matrixs = GraphicsBounds._tempMatrixArrays;
  10506. matrixs.length = 0;
  10507. var tMatrix = GraphicsBounds._initMatrix;
  10508. tMatrix.identity();
  10509. var tempMatrix = GraphicsBounds._tempMatrix;
  10510. var cmd;
  10511. var tex;
  10512. for (var i = 0, n = cmds.length; i < n; i++) {
  10513. cmd = cmds[i];
  10514. switch (cmd.cmdID) {
  10515. case AlphaCmd.ID:
  10516. matrixs.push(tMatrix);
  10517. tMatrix = tMatrix.clone();
  10518. break;
  10519. case RestoreCmd.ID:
  10520. tMatrix = matrixs.pop();
  10521. break;
  10522. case ScaleCmd.ID:
  10523. tempMatrix.identity();
  10524. tempMatrix.translate(-cmd.pivotX, -cmd.pivotY);
  10525. tempMatrix.scale(cmd.scaleX, cmd.scaleY);
  10526. tempMatrix.translate(cmd.pivotX, cmd.pivotY);
  10527. this._switchMatrix(tMatrix, tempMatrix);
  10528. break;
  10529. case RotateCmd.ID:
  10530. tempMatrix.identity();
  10531. tempMatrix.translate(-cmd.pivotX, -cmd.pivotY);
  10532. tempMatrix.rotate(cmd.angle);
  10533. tempMatrix.translate(cmd.pivotX, cmd.pivotY);
  10534. this._switchMatrix(tMatrix, tempMatrix);
  10535. break;
  10536. case TranslateCmd.ID:
  10537. tempMatrix.identity();
  10538. tempMatrix.translate(cmd.tx, cmd.ty);
  10539. this._switchMatrix(tMatrix, tempMatrix);
  10540. break;
  10541. case TransformCmd.ID:
  10542. tempMatrix.identity();
  10543. tempMatrix.translate(-cmd.pivotX, -cmd.pivotY);
  10544. tempMatrix.concat(cmd.matrix);
  10545. tempMatrix.translate(cmd.pivotX, cmd.pivotY);
  10546. this._switchMatrix(tMatrix, tempMatrix);
  10547. break;
  10548. case DrawImageCmd.ID:
  10549. case FillTextureCmd.ID:
  10550. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, cmd.width, cmd.height), tMatrix);
  10551. break;
  10552. case DrawTextureCmd.ID:
  10553. tMatrix.copyTo(tempMatrix);
  10554. if (cmd.matrix)
  10555. tempMatrix.concat(cmd.matrix);
  10556. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, cmd.width, cmd.height), tempMatrix);
  10557. break;
  10558. case DrawImageCmd.ID:
  10559. tex = cmd.texture;
  10560. if (realSize) {
  10561. if (cmd.width && cmd.height) {
  10562. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, cmd.width, cmd.height), tMatrix);
  10563. }
  10564. else {
  10565. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, tex.width, tex.height), tMatrix);
  10566. }
  10567. }
  10568. else {
  10569. var wRate = (cmd.width || tex.sourceWidth) / tex.width;
  10570. var hRate = (cmd.height || tex.sourceHeight) / tex.height;
  10571. var oWidth = wRate * tex.sourceWidth;
  10572. var oHeight = hRate * tex.sourceHeight;
  10573. var offX = tex.offsetX > 0 ? tex.offsetX : 0;
  10574. var offY = tex.offsetY > 0 ? tex.offsetY : 0;
  10575. offX *= wRate;
  10576. offY *= hRate;
  10577. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x - offX, cmd.y - offY, oWidth, oHeight), tMatrix);
  10578. }
  10579. break;
  10580. case FillTextureCmd.ID:
  10581. if (cmd.width && cmd.height) {
  10582. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, cmd.width, cmd.height), tMatrix);
  10583. }
  10584. else {
  10585. tex = cmd.texture;
  10586. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, tex.width, tex.height), tMatrix);
  10587. }
  10588. break;
  10589. case DrawTextureCmd.ID:
  10590. var drawMatrix;
  10591. if (cmd.matrix) {
  10592. tMatrix.copyTo(tempMatrix);
  10593. tempMatrix.concat(cmd.matrix);
  10594. drawMatrix = tempMatrix;
  10595. }
  10596. else {
  10597. drawMatrix = tMatrix;
  10598. }
  10599. if (realSize) {
  10600. if (cmd.width && cmd.height) {
  10601. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, cmd.width, cmd.height), drawMatrix);
  10602. }
  10603. else {
  10604. tex = cmd.texture;
  10605. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, tex.width, tex.height), drawMatrix);
  10606. }
  10607. }
  10608. else {
  10609. tex = cmd.texture;
  10610. wRate = (cmd.width || tex.sourceWidth) / tex.width;
  10611. hRate = (cmd.height || tex.sourceHeight) / tex.height;
  10612. oWidth = wRate * tex.sourceWidth;
  10613. oHeight = hRate * tex.sourceHeight;
  10614. offX = tex.offsetX > 0 ? tex.offsetX : 0;
  10615. offY = tex.offsetY > 0 ? tex.offsetY : 0;
  10616. offX *= wRate;
  10617. offY *= hRate;
  10618. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x - offX, cmd.y - offY, oWidth, oHeight), drawMatrix);
  10619. }
  10620. break;
  10621. case DrawRectCmd.ID:
  10622. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, cmd.width, cmd.height), tMatrix);
  10623. break;
  10624. case DrawCircleCmd.ID:
  10625. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x - cmd.radius, cmd.y - cmd.radius, cmd.radius + cmd.radius, cmd.radius + cmd.radius), tMatrix);
  10626. break;
  10627. case DrawLineCmd.ID:
  10628. GraphicsBounds._tempPoints.length = 0;
  10629. var lineWidth;
  10630. lineWidth = cmd.lineWidth * 0.5;
  10631. if (cmd.fromX == cmd.toX) {
  10632. GraphicsBounds._tempPoints.push(cmd.fromX + lineWidth, cmd.fromY, cmd.toX + lineWidth, cmd.toY, cmd.fromX - lineWidth, cmd.fromY, cmd.toX - lineWidth, cmd.toY);
  10633. }
  10634. else if (cmd.fromY == cmd.toY) {
  10635. GraphicsBounds._tempPoints.push(cmd.fromX, cmd.fromY + lineWidth, cmd.toX, cmd.toY + lineWidth, cmd.fromX, cmd.fromY - lineWidth, cmd.toX, cmd.toY - lineWidth);
  10636. }
  10637. else {
  10638. GraphicsBounds._tempPoints.push(cmd.fromX, cmd.fromY, cmd.toX, cmd.toY);
  10639. }
  10640. GraphicsBounds._addPointArrToRst(rst, GraphicsBounds._tempPoints, tMatrix);
  10641. break;
  10642. case DrawCurvesCmd.ID:
  10643. GraphicsBounds._addPointArrToRst(rst, Bezier.I.getBezierPoints(cmd.points), tMatrix, cmd.x, cmd.y);
  10644. break;
  10645. case DrawLinesCmd.ID:
  10646. case DrawPolyCmd.ID:
  10647. GraphicsBounds._addPointArrToRst(rst, cmd.points, tMatrix, cmd.x, cmd.y);
  10648. break;
  10649. case DrawPathCmd.ID:
  10650. GraphicsBounds._addPointArrToRst(rst, this._getPathPoints(cmd.paths), tMatrix, cmd.x, cmd.y);
  10651. break;
  10652. case DrawPieCmd.ID:
  10653. GraphicsBounds._addPointArrToRst(rst, this._getPiePoints(cmd.x, cmd.y, cmd.radius, cmd.startAngle, cmd.endAngle), tMatrix);
  10654. break;
  10655. case DrawTrianglesCmd.ID:
  10656. GraphicsBounds._addPointArrToRst(rst, this._getTriAngBBXPoints(cmd.vertices), tMatrix);
  10657. break;
  10658. case Draw9GridTexture.ID:
  10659. GraphicsBounds._addPointArrToRst(rst, this._getDraw9GridBBXPoints(cmd), tMatrix);
  10660. break;
  10661. }
  10662. }
  10663. if (rst.length > 200) {
  10664. rst = Utils.copyArray(rst, Rectangle._getWrapRec(rst)._getBoundPoints());
  10665. }
  10666. else if (rst.length > 8)
  10667. rst = GrahamScan.scanPList(rst);
  10668. return rst;
  10669. }
  10670. _switchMatrix(tMatix, tempMatrix) {
  10671. tempMatrix.concat(tMatix);
  10672. tempMatrix.copyTo(tMatix);
  10673. }
  10674. static _addPointArrToRst(rst, points, matrix, dx = 0, dy = 0) {
  10675. var i, len;
  10676. len = points.length;
  10677. for (i = 0; i < len; i += 2) {
  10678. GraphicsBounds._addPointToRst(rst, points[i] + dx, points[i + 1] + dy, matrix);
  10679. }
  10680. }
  10681. static _addPointToRst(rst, x, y, matrix) {
  10682. var _tempPoint = Point.TEMP;
  10683. _tempPoint.setTo(x ? x : 0, y ? y : 0);
  10684. matrix.transformPoint(_tempPoint);
  10685. rst.push(_tempPoint.x, _tempPoint.y);
  10686. }
  10687. _getPiePoints(x, y, radius, startAngle, endAngle) {
  10688. var rst = GraphicsBounds._tempPoints;
  10689. GraphicsBounds._tempPoints.length = 0;
  10690. var k = Math.PI / 180;
  10691. var d1 = endAngle - startAngle;
  10692. if (d1 >= 360 || d1 <= -360) {
  10693. rst.push(x - radius, y - radius);
  10694. rst.push(x + radius, y - radius);
  10695. rst.push(x + radius, y + radius);
  10696. rst.push(x - radius, y + radius);
  10697. return rst;
  10698. }
  10699. rst.push(x, y);
  10700. var delta = d1 % 360;
  10701. if (delta < 0)
  10702. delta += 360;
  10703. var end1 = startAngle + delta;
  10704. var st = startAngle * k;
  10705. var ed = end1 * k;
  10706. rst.push(x + radius * Math.cos(st), y + radius * Math.sin(st));
  10707. rst.push(x + radius * Math.cos(ed), y + radius * Math.sin(ed));
  10708. var s1 = Math.ceil(startAngle / 90) * 90;
  10709. var s2 = Math.floor(end1 / 90) * 90;
  10710. for (var cs = s1; cs <= s2; cs += 90) {
  10711. var csr = cs * k;
  10712. rst.push(x + radius * Math.cos(csr), y + radius * Math.sin(csr));
  10713. }
  10714. return rst;
  10715. }
  10716. _getTriAngBBXPoints(vert) {
  10717. var vnum = vert.length;
  10718. if (vnum < 2)
  10719. return [];
  10720. var minx = vert[0];
  10721. var miny = vert[1];
  10722. var maxx = minx;
  10723. var maxy = miny;
  10724. for (var i = 2; i < vnum;) {
  10725. var cx = vert[i++];
  10726. var cy = vert[i++];
  10727. if (minx > cx)
  10728. minx = cx;
  10729. if (miny > cy)
  10730. miny = cy;
  10731. if (maxx < cx)
  10732. maxx = cx;
  10733. if (maxy < cy)
  10734. maxy = cy;
  10735. }
  10736. return [minx, miny, maxx, miny, maxx, maxy, minx, maxy];
  10737. }
  10738. _getDraw9GridBBXPoints(cmd) {
  10739. var minx = 0;
  10740. var miny = 0;
  10741. var maxx = cmd.width;
  10742. var maxy = cmd.height;
  10743. return [minx, miny, maxx, miny, maxx, maxy, minx, maxy];
  10744. }
  10745. _getPathPoints(paths) {
  10746. var i, len;
  10747. var rst = GraphicsBounds._tempPoints;
  10748. rst.length = 0;
  10749. len = paths.length;
  10750. var tCMD;
  10751. for (i = 0; i < len; i++) {
  10752. tCMD = paths[i];
  10753. if (tCMD.length > 1) {
  10754. rst.push(tCMD[1], tCMD[2]);
  10755. if (tCMD.length > 3) {
  10756. rst.push(tCMD[3], tCMD[4]);
  10757. }
  10758. }
  10759. }
  10760. return rst;
  10761. }
  10762. }
  10763. GraphicsBounds._tempMatrix = new Matrix();
  10764. GraphicsBounds._initMatrix = new Matrix();
  10765. GraphicsBounds._tempPoints = [];
  10766. GraphicsBounds._tempMatrixArrays = [];
  10767. GraphicsBounds._tempCmds = [];
  10768. class SpriteConst {
  10769. }
  10770. SpriteConst.ALPHA = 0x01;
  10771. SpriteConst.TRANSFORM = 0x02;
  10772. SpriteConst.BLEND = 0x04;
  10773. SpriteConst.CANVAS = 0x08;
  10774. SpriteConst.FILTERS = 0x10;
  10775. SpriteConst.MASK = 0x20;
  10776. SpriteConst.CLIP = 0x40;
  10777. SpriteConst.STYLE = 0x80;
  10778. SpriteConst.TEXTURE = 0x100;
  10779. SpriteConst.GRAPHICS = 0x200;
  10780. SpriteConst.LAYAGL3D = 0x400;
  10781. SpriteConst.CUSTOM = 0x800;
  10782. SpriteConst.ONECHILD = 0x1000;
  10783. SpriteConst.CHILDS = 0x2000;
  10784. SpriteConst.REPAINT_NONE = 0;
  10785. SpriteConst.REPAINT_NODE = 0x01;
  10786. SpriteConst.REPAINT_CACHE = 0x02;
  10787. SpriteConst.REPAINT_ALL = 0x03;
  10788. class ClipRectCmd {
  10789. static create(x, y, width, height) {
  10790. var cmd = Pool.getItemByClass("ClipRectCmd", ClipRectCmd);
  10791. cmd.x = x;
  10792. cmd.y = y;
  10793. cmd.width = width;
  10794. cmd.height = height;
  10795. return cmd;
  10796. }
  10797. recover() {
  10798. Pool.recover("ClipRectCmd", this);
  10799. }
  10800. run(context, gx, gy) {
  10801. context.clipRect(this.x + gx, this.y + gy, this.width, this.height);
  10802. }
  10803. get cmdID() {
  10804. return ClipRectCmd.ID;
  10805. }
  10806. }
  10807. ClipRectCmd.ID = "ClipRect";
  10808. class DrawTexturesCmd {
  10809. static create(texture, pos) {
  10810. var cmd = Pool.getItemByClass("DrawTexturesCmd", DrawTexturesCmd);
  10811. cmd.texture = texture;
  10812. texture._addReference();
  10813. cmd.pos = pos;
  10814. return cmd;
  10815. }
  10816. recover() {
  10817. this.texture._removeReference();
  10818. this.texture = null;
  10819. this.pos = null;
  10820. Pool.recover("DrawTexturesCmd", this);
  10821. }
  10822. run(context, gx, gy) {
  10823. context.drawTextures(this.texture, this.pos, gx, gy);
  10824. }
  10825. get cmdID() {
  10826. return DrawTexturesCmd.ID;
  10827. }
  10828. }
  10829. DrawTexturesCmd.ID = "DrawTextures";
  10830. class FillTextCmd {
  10831. constructor() {
  10832. this._textIsWorldText = false;
  10833. this._fontColor = 0xffffffff;
  10834. this._strokeColor = 0;
  10835. this._fontObj = FillTextCmd._defFontObj;
  10836. this._nTexAlign = 0;
  10837. }
  10838. static create(text, words, x, y, font, color, textAlign, lineWidth, borderColor) {
  10839. var cmd = Pool.getItemByClass("FillTextCmd", FillTextCmd);
  10840. cmd.text = text;
  10841. cmd._textIsWorldText = text instanceof WordText;
  10842. cmd._words = words;
  10843. cmd.x = x;
  10844. cmd.y = y;
  10845. cmd.font = font;
  10846. cmd.color = color;
  10847. cmd.textAlign = textAlign;
  10848. cmd._lineWidth = lineWidth;
  10849. cmd._borderColor = borderColor;
  10850. return cmd;
  10851. }
  10852. recover() {
  10853. Pool.recover("FillTextCmd", this);
  10854. }
  10855. run(context, gx, gy) {
  10856. if (ILaya.stage.isGlobalRepaint()) {
  10857. this._textIsWorldText && this._text.cleanCache();
  10858. }
  10859. if (this._words) {
  10860. Context._textRender.fillWords(context, this._words, this.x + gx, this.y + gy, this._fontObj, this._color, this._borderColor, this._lineWidth);
  10861. }
  10862. else {
  10863. if (this._textIsWorldText) {
  10864. context._fast_filltext(this._text, this.x + gx, this.y + gy, this._fontObj, this._color, this._borderColor, this._lineWidth, this._nTexAlign, 0);
  10865. }
  10866. else {
  10867. Context._textRender.filltext(context, this._text, this.x + gx, this.y + gy, this.font, this.color, this._borderColor, this._lineWidth, this._textAlign);
  10868. }
  10869. }
  10870. }
  10871. get cmdID() {
  10872. return FillTextCmd.ID;
  10873. }
  10874. get text() {
  10875. return this._text;
  10876. }
  10877. set text(value) {
  10878. this._text = value;
  10879. this._textIsWorldText = value instanceof WordText;
  10880. this._textIsWorldText && this._text.cleanCache();
  10881. }
  10882. get font() {
  10883. return this._font;
  10884. }
  10885. set font(value) {
  10886. this._font = value;
  10887. this._fontObj = FontInfo.Parse(value);
  10888. this._textIsWorldText && this._text.cleanCache();
  10889. }
  10890. get color() {
  10891. return this._color;
  10892. }
  10893. set color(value) {
  10894. this._color = value;
  10895. this._fontColor = ColorUtils.create(value).numColor;
  10896. this._textIsWorldText && this._text.cleanCache();
  10897. }
  10898. get textAlign() {
  10899. return this._textAlign;
  10900. }
  10901. set textAlign(value) {
  10902. this._textAlign = value;
  10903. switch (value) {
  10904. case 'center':
  10905. this._nTexAlign = ILaya.Context.ENUM_TEXTALIGN_CENTER;
  10906. break;
  10907. case 'right':
  10908. this._nTexAlign = ILaya.Context.ENUM_TEXTALIGN_RIGHT;
  10909. break;
  10910. default:
  10911. this._nTexAlign = ILaya.Context.ENUM_TEXTALIGN_DEFAULT;
  10912. }
  10913. this._textIsWorldText && this._text.cleanCache();
  10914. }
  10915. }
  10916. FillTextCmd.ID = "FillText";
  10917. FillTextCmd._defFontObj = new FontInfo(null);
  10918. class SaveCmd {
  10919. static create() {
  10920. var cmd = Pool.getItemByClass("SaveCmd", SaveCmd);
  10921. return cmd;
  10922. }
  10923. recover() {
  10924. Pool.recover("SaveCmd", this);
  10925. }
  10926. run(context, gx, gy) {
  10927. context.save();
  10928. }
  10929. get cmdID() {
  10930. return SaveCmd.ID;
  10931. }
  10932. }
  10933. SaveCmd.ID = "Save";
  10934. class CacheManger {
  10935. constructor() {
  10936. }
  10937. static regCacheByFunction(disposeFunction, getCacheListFunction) {
  10938. CacheManger.unRegCacheByFunction(disposeFunction, getCacheListFunction);
  10939. var cache;
  10940. cache = { tryDispose: disposeFunction, getCacheList: getCacheListFunction };
  10941. CacheManger._cacheList.push(cache);
  10942. }
  10943. static unRegCacheByFunction(disposeFunction, getCacheListFunction) {
  10944. var i, len;
  10945. len = CacheManger._cacheList.length;
  10946. for (i = 0; i < len; i++) {
  10947. if (CacheManger._cacheList[i].tryDispose == disposeFunction && CacheManger._cacheList[i].getCacheList == getCacheListFunction) {
  10948. CacheManger._cacheList.splice(i, 1);
  10949. return;
  10950. }
  10951. }
  10952. }
  10953. static forceDispose() {
  10954. var i, len = CacheManger._cacheList.length;
  10955. for (i = 0; i < len; i++) {
  10956. CacheManger._cacheList[i].tryDispose(true);
  10957. }
  10958. }
  10959. static beginCheck(waitTime = 15000) {
  10960. ILaya.systemTimer.loop(waitTime, null, CacheManger._checkLoop);
  10961. }
  10962. static stopCheck() {
  10963. ILaya.systemTimer.clear(null, CacheManger._checkLoop);
  10964. }
  10965. static _checkLoop() {
  10966. var cacheList = CacheManger._cacheList;
  10967. if (cacheList.length < 1)
  10968. return;
  10969. var tTime = ILaya.Browser.now();
  10970. var count;
  10971. var len;
  10972. len = count = cacheList.length;
  10973. while (count > 0) {
  10974. CacheManger._index++;
  10975. CacheManger._index = CacheManger._index % len;
  10976. cacheList[CacheManger._index].tryDispose(false);
  10977. if (ILaya.Browser.now() - tTime > CacheManger.loopTimeLimit)
  10978. break;
  10979. count--;
  10980. }
  10981. }
  10982. }
  10983. CacheManger.loopTimeLimit = 2;
  10984. CacheManger._cacheList = [];
  10985. CacheManger._index = 0;
  10986. class VectorGraphManager {
  10987. constructor() {
  10988. this.useDic = {};
  10989. this.shapeDic = {};
  10990. this.shapeLineDic = {};
  10991. this._id = 0;
  10992. this._checkKey = false;
  10993. this._freeIdArray = [];
  10994. CacheManger.regCacheByFunction(this.startDispose.bind(this), this.getCacheList.bind(this));
  10995. }
  10996. static getInstance() {
  10997. return VectorGraphManager.instance = VectorGraphManager.instance || new VectorGraphManager();
  10998. }
  10999. getId() {
  11000. return this._id++;
  11001. }
  11002. addShape(id, shape) {
  11003. this.shapeDic[id] = shape;
  11004. if (!this.useDic[id]) {
  11005. this.useDic[id] = true;
  11006. }
  11007. }
  11008. addLine(id, Line) {
  11009. this.shapeLineDic[id] = Line;
  11010. if (!this.shapeLineDic[id]) {
  11011. this.shapeLineDic[id] = true;
  11012. }
  11013. }
  11014. getShape(id) {
  11015. if (this._checkKey) {
  11016. if (this.useDic[id] != null) {
  11017. this.useDic[id] = true;
  11018. }
  11019. }
  11020. }
  11021. deleteShape(id) {
  11022. if (this.shapeDic[id]) {
  11023. this.shapeDic[id] = null;
  11024. delete this.shapeDic[id];
  11025. }
  11026. if (this.shapeLineDic[id]) {
  11027. this.shapeLineDic[id] = null;
  11028. delete this.shapeLineDic[id];
  11029. }
  11030. if (this.useDic[id] != null) {
  11031. delete this.useDic[id];
  11032. }
  11033. }
  11034. getCacheList() {
  11035. var str;
  11036. var list = [];
  11037. for (str in this.shapeDic) {
  11038. list.push(this.shapeDic[str]);
  11039. }
  11040. for (str in this.shapeLineDic) {
  11041. list.push(this.shapeLineDic[str]);
  11042. }
  11043. return list;
  11044. }
  11045. startDispose(key) {
  11046. var str;
  11047. for (str in this.useDic) {
  11048. this.useDic[str] = false;
  11049. }
  11050. this._checkKey = true;
  11051. }
  11052. endDispose() {
  11053. if (this._checkKey) {
  11054. var str;
  11055. for (str in this.useDic) {
  11056. if (!this.useDic[str]) {
  11057. this.deleteShape(str);
  11058. }
  11059. }
  11060. this._checkKey = false;
  11061. }
  11062. }
  11063. }
  11064. class Graphics {
  11065. constructor() {
  11066. this._sp = null;
  11067. this._one = null;
  11068. this._render = this._renderEmpty;
  11069. this._cmds = null;
  11070. this._vectorgraphArray = null;
  11071. this._graphicBounds = null;
  11072. this.autoDestroy = false;
  11073. this._createData();
  11074. }
  11075. _createData() {
  11076. }
  11077. _clearData() {
  11078. }
  11079. _destroyData() {
  11080. }
  11081. destroy() {
  11082. this.clear(true);
  11083. if (this._graphicBounds)
  11084. this._graphicBounds.destroy();
  11085. this._graphicBounds = null;
  11086. this._vectorgraphArray = null;
  11087. if (this._sp) {
  11088. this._sp._renderType = 0;
  11089. this._sp._setRenderType(0);
  11090. this._sp = null;
  11091. }
  11092. this._destroyData();
  11093. }
  11094. clear(recoverCmds = true) {
  11095. if (recoverCmds) {
  11096. var tCmd = this._one;
  11097. if (this._cmds) {
  11098. var i, len = this._cmds.length;
  11099. for (i = 0; i < len; i++) {
  11100. tCmd = this._cmds[i];
  11101. tCmd.recover();
  11102. }
  11103. this._cmds.length = 0;
  11104. }
  11105. else if (tCmd) {
  11106. tCmd.recover();
  11107. }
  11108. }
  11109. else {
  11110. this._cmds = null;
  11111. }
  11112. this._one = null;
  11113. this._render = this._renderEmpty;
  11114. this._clearData();
  11115. if (this._sp) {
  11116. this._sp._renderType &= ~SpriteConst.GRAPHICS;
  11117. this._sp._setRenderType(this._sp._renderType);
  11118. }
  11119. this._repaint();
  11120. if (this._vectorgraphArray) {
  11121. for (i = 0, len = this._vectorgraphArray.length; i < len; i++) {
  11122. VectorGraphManager.getInstance().deleteShape(this._vectorgraphArray[i]);
  11123. }
  11124. this._vectorgraphArray.length = 0;
  11125. }
  11126. }
  11127. _clearBoundsCache() {
  11128. if (this._graphicBounds)
  11129. this._graphicBounds.reset();
  11130. }
  11131. _initGraphicBounds() {
  11132. if (!this._graphicBounds) {
  11133. this._graphicBounds = GraphicsBounds.create();
  11134. this._graphicBounds._graphics = this;
  11135. }
  11136. }
  11137. _repaint() {
  11138. this._clearBoundsCache();
  11139. this._sp && this._sp.repaint();
  11140. }
  11141. _isOnlyOne() {
  11142. return !this._cmds || this._cmds.length === 0;
  11143. }
  11144. get cmds() {
  11145. return this._cmds;
  11146. }
  11147. set cmds(value) {
  11148. if (this._sp) {
  11149. this._sp._renderType |= SpriteConst.GRAPHICS;
  11150. this._sp._setRenderType(this._sp._renderType);
  11151. }
  11152. this._cmds = value;
  11153. this._render = this._renderAll;
  11154. this._repaint();
  11155. }
  11156. getBounds(realSize = false) {
  11157. this._initGraphicBounds();
  11158. return this._graphicBounds.getBounds(realSize);
  11159. }
  11160. getBoundPoints(realSize = false) {
  11161. this._initGraphicBounds();
  11162. return this._graphicBounds.getBoundPoints(realSize);
  11163. }
  11164. drawImage(texture, x = 0, y = 0, width = 0, height = 0) {
  11165. if (!texture)
  11166. return null;
  11167. if (!width)
  11168. width = texture.sourceWidth;
  11169. if (!height)
  11170. height = texture.sourceHeight;
  11171. if (texture.getIsReady()) {
  11172. var wRate = width / texture.sourceWidth;
  11173. var hRate = height / texture.sourceHeight;
  11174. width = texture.width * wRate;
  11175. height = texture.height * hRate;
  11176. if (width <= 0 || height <= 0)
  11177. return null;
  11178. x += texture.offsetX * wRate;
  11179. y += texture.offsetY * hRate;
  11180. }
  11181. if (this._sp) {
  11182. this._sp._renderType |= SpriteConst.GRAPHICS;
  11183. this._sp._setRenderType(this._sp._renderType);
  11184. }
  11185. var args = DrawImageCmd.create.call(this, texture, x, y, width, height);
  11186. if (this._one == null) {
  11187. this._one = args;
  11188. this._render = this._renderOneImg;
  11189. }
  11190. else {
  11191. this._saveToCmd(null, args);
  11192. }
  11193. this._repaint();
  11194. return args;
  11195. }
  11196. drawTexture(texture, x = 0, y = 0, width = 0, height = 0, matrix = null, alpha = 1, color = null, blendMode = null, uv) {
  11197. if (!texture || alpha < 0.01)
  11198. return null;
  11199. if (!texture.getIsReady())
  11200. return null;
  11201. if (!width)
  11202. width = texture.sourceWidth;
  11203. if (!height)
  11204. height = texture.sourceHeight;
  11205. if (texture.getIsReady()) {
  11206. var wRate = width / texture.sourceWidth;
  11207. var hRate = height / texture.sourceHeight;
  11208. width = texture.width * wRate;
  11209. height = texture.height * hRate;
  11210. if (width <= 0 || height <= 0)
  11211. return null;
  11212. x += texture.offsetX * wRate;
  11213. y += texture.offsetY * hRate;
  11214. }
  11215. if (this._sp) {
  11216. this._sp._renderType |= SpriteConst.GRAPHICS;
  11217. this._sp._setRenderType(this._sp._renderType);
  11218. }
  11219. var args = DrawTextureCmd.create.call(this, texture, x, y, width, height, matrix, alpha, color, blendMode, uv);
  11220. this._repaint();
  11221. return this._saveToCmd(null, args);
  11222. }
  11223. drawTextures(texture, pos) {
  11224. if (!texture)
  11225. return null;
  11226. return this._saveToCmd(Render._context.drawTextures, DrawTexturesCmd.create.call(this, texture, pos));
  11227. }
  11228. drawTriangles(texture, x, y, vertices, uvs, indices, matrix = null, alpha = 1, color = null, blendMode = null, colorNum = undefined) {
  11229. return this._saveToCmd(Render._context.drawTriangles, DrawTrianglesCmd.create.call(this, texture, x, y, vertices, uvs, indices, matrix, alpha, color, blendMode, colorNum));
  11230. }
  11231. fillTexture(texture, x, y, width = 0, height = 0, type = "repeat", offset = null) {
  11232. if (texture && texture.getIsReady())
  11233. return this._saveToCmd(Render._context._fillTexture, FillTextureCmd.create.call(this, texture, x, y, width, height, type, offset || Point.EMPTY, {}));
  11234. else
  11235. return null;
  11236. }
  11237. _saveToCmd(fun, args) {
  11238. if (this._sp) {
  11239. this._sp._renderType |= SpriteConst.GRAPHICS;
  11240. this._sp._setRenderType(this._sp._renderType);
  11241. }
  11242. if (this._one == null) {
  11243. this._one = args;
  11244. this._render = this._renderOne;
  11245. }
  11246. else {
  11247. this._render = this._renderAll;
  11248. (this._cmds || (this._cmds = [])).length === 0 && this._cmds.push(this._one);
  11249. this._cmds.push(args);
  11250. }
  11251. this._repaint();
  11252. return args;
  11253. }
  11254. clipRect(x, y, width, height) {
  11255. return this._saveToCmd(Render._context.clipRect, ClipRectCmd.create.call(this, x, y, width, height));
  11256. }
  11257. fillText(text, x, y, font, color, textAlign) {
  11258. return this._saveToCmd(Render._context.fillText, FillTextCmd.create.call(this, text, null, x, y, font || ILaya.Text.defaultFontStr(), color, textAlign, 0, ""));
  11259. }
  11260. fillBorderText(text, x, y, font, fillColor, textAlign, lineWidth, borderColor) {
  11261. return this._saveToCmd(Render._context.fillText, FillTextCmd.create.call(this, text, null, x, y, font || ILaya.Text.defaultFontStr(), fillColor, borderColor, lineWidth, textAlign));
  11262. }
  11263. fillWords(words, x, y, font, color) {
  11264. return this._saveToCmd(Render._context.fillText, FillTextCmd.create.call(this, null, words, x, y, font || ILaya.Text.defaultFontStr(), color));
  11265. }
  11266. fillBorderWords(words, x, y, font, fillColor, borderColor, lineWidth) {
  11267. return this._saveToCmd(Render._context.fillText, FillTextCmd.create.call(this, null, words, x, y, font || ILaya.Text.defaultFontStr(), fillColor, "", lineWidth, borderColor));
  11268. }
  11269. strokeText(text, x, y, font, color, lineWidth, textAlign) {
  11270. return this._saveToCmd(Render._context.fillText, FillTextCmd.create.call(this, text, null, x, y, font || ILaya.Text.defaultFontStr(), null, textAlign, lineWidth, color));
  11271. }
  11272. alpha(alpha) {
  11273. return this._saveToCmd(Render._context.alpha, AlphaCmd.create.call(this, alpha));
  11274. }
  11275. transform(matrix, pivotX = 0, pivotY = 0) {
  11276. return this._saveToCmd(Render._context._transform, TransformCmd.create.call(this, matrix, pivotX, pivotY));
  11277. }
  11278. rotate(angle, pivotX = 0, pivotY = 0) {
  11279. return this._saveToCmd(Render._context._rotate, RotateCmd.create.call(this, angle, pivotX, pivotY));
  11280. }
  11281. scale(scaleX, scaleY, pivotX = 0, pivotY = 0) {
  11282. return this._saveToCmd(Render._context._scale, ScaleCmd.create.call(this, scaleX, scaleY, pivotX, pivotY));
  11283. }
  11284. translate(tx, ty) {
  11285. return this._saveToCmd(Render._context.translate, TranslateCmd.create.call(this, tx, ty));
  11286. }
  11287. save() {
  11288. return this._saveToCmd(Render._context._save, SaveCmd.create.call(this));
  11289. }
  11290. restore() {
  11291. return this._saveToCmd(Render._context.restore, RestoreCmd.create.call(this));
  11292. }
  11293. replaceText(text) {
  11294. this._repaint();
  11295. var cmds = this._cmds;
  11296. if (!cmds) {
  11297. if (this._one && this._isTextCmd(this._one)) {
  11298. this._one.text = text;
  11299. return true;
  11300. }
  11301. }
  11302. else {
  11303. for (var i = cmds.length - 1; i > -1; i--) {
  11304. if (this._isTextCmd(cmds[i])) {
  11305. cmds[i].text = text;
  11306. return true;
  11307. }
  11308. }
  11309. }
  11310. return false;
  11311. }
  11312. _isTextCmd(cmd) {
  11313. var cmdID = cmd.cmdID;
  11314. return cmdID == FillTextCmd.ID;
  11315. }
  11316. replaceTextColor(color) {
  11317. this._repaint();
  11318. var cmds = this._cmds;
  11319. if (!cmds) {
  11320. if (this._one && this._isTextCmd(this._one)) {
  11321. this._setTextCmdColor(this._one, color);
  11322. }
  11323. }
  11324. else {
  11325. for (var i = cmds.length - 1; i > -1; i--) {
  11326. if (this._isTextCmd(cmds[i])) {
  11327. this._setTextCmdColor(cmds[i], color);
  11328. }
  11329. }
  11330. }
  11331. }
  11332. _setTextCmdColor(cmdO, color) {
  11333. var cmdID = cmdO.cmdID;
  11334. switch (cmdID) {
  11335. case FillTextCmd.ID:
  11336. cmdO.color = color;
  11337. break;
  11338. }
  11339. }
  11340. loadImage(url, x = 0, y = 0, width = 0, height = 0, complete = null) {
  11341. var tex = ILaya.Loader.getRes(url);
  11342. if (!tex) {
  11343. tex = new Texture();
  11344. tex.load(url);
  11345. ILaya.Loader.cacheTexture(url, tex);
  11346. tex.once(Event.READY, this, this.drawImage, [tex, x, y, width, height]);
  11347. }
  11348. else {
  11349. if (!tex.getIsReady()) {
  11350. tex.once(Event.READY, this, this.drawImage, [tex, x, y, width, height]);
  11351. }
  11352. else
  11353. this.drawImage(tex, x, y, width, height);
  11354. }
  11355. if (complete != null) {
  11356. tex.getIsReady() ? complete.call(this._sp) : tex.on(Event.READY, this._sp, complete);
  11357. }
  11358. }
  11359. _renderEmpty(sprite, context, x, y) {
  11360. }
  11361. _renderAll(sprite, context, x, y) {
  11362. var cmds = this._cmds;
  11363. for (var i = 0, n = cmds.length; i < n; i++) {
  11364. cmds[i].run(context, x, y);
  11365. }
  11366. }
  11367. _renderOne(sprite, context, x, y) {
  11368. context.sprite = sprite;
  11369. this._one.run(context, x, y);
  11370. }
  11371. _renderOneImg(sprite, context, x, y) {
  11372. context.sprite = sprite;
  11373. this._one.run(context, x, y);
  11374. }
  11375. drawLine(fromX, fromY, toX, toY, lineColor, lineWidth = 1) {
  11376. var offset = (lineWidth < 1 || lineWidth % 2 === 0) ? 0 : 0.5;
  11377. return this._saveToCmd(Render._context._drawLine, DrawLineCmd.create.call(this, fromX + offset, fromY + offset, toX + offset, toY + offset, lineColor, lineWidth, 0));
  11378. }
  11379. drawLines(x, y, points, lineColor, lineWidth = 1) {
  11380. if (!points || points.length < 4)
  11381. return null;
  11382. var offset = (lineWidth < 1 || lineWidth % 2 === 0) ? 0 : 0.5;
  11383. return this._saveToCmd(Render._context._drawLines, DrawLinesCmd.create.call(this, x + offset, y + offset, points, lineColor, lineWidth, 0));
  11384. }
  11385. drawCurves(x, y, points, lineColor, lineWidth = 1) {
  11386. return this._saveToCmd(Render._context.drawCurves, DrawCurvesCmd.create.call(this, x, y, points, lineColor, lineWidth));
  11387. }
  11388. drawRect(x, y, width, height, fillColor, lineColor = null, lineWidth = 1) {
  11389. var offset = (lineWidth >= 1 && lineColor) ? lineWidth / 2 : 0;
  11390. var lineOffset = lineColor ? lineWidth : 0;
  11391. return this._saveToCmd(Render._context.drawRect, DrawRectCmd.create.call(this, x + offset, y + offset, width - lineOffset, height - lineOffset, fillColor, lineColor, lineWidth));
  11392. }
  11393. drawCircle(x, y, radius, fillColor, lineColor = null, lineWidth = 1) {
  11394. var offset = (lineWidth >= 1 && lineColor) ? lineWidth / 2 : 0;
  11395. return this._saveToCmd(Render._context._drawCircle, DrawCircleCmd.create.call(this, x, y, radius - offset, fillColor, lineColor, lineWidth, 0));
  11396. }
  11397. drawPie(x, y, radius, startAngle, endAngle, fillColor, lineColor = null, lineWidth = 1) {
  11398. var offset = (lineWidth >= 1 && lineColor) ? lineWidth / 2 : 0;
  11399. var lineOffset = lineColor ? lineWidth : 0;
  11400. return this._saveToCmd(Render._context._drawPie, DrawPieCmd.create.call(this, x + offset, y + offset, radius - lineOffset, Utils.toRadian(startAngle), Utils.toRadian(endAngle), fillColor, lineColor, lineWidth, 0));
  11401. }
  11402. drawPoly(x, y, points, fillColor, lineColor = null, lineWidth = 1) {
  11403. var tIsConvexPolygon = false;
  11404. if (points.length > 6) {
  11405. tIsConvexPolygon = false;
  11406. }
  11407. else {
  11408. tIsConvexPolygon = true;
  11409. }
  11410. var offset = (lineWidth >= 1 && lineColor) ? (lineWidth % 2 === 0 ? 0 : 0.5) : 0;
  11411. return this._saveToCmd(Render._context._drawPoly, DrawPolyCmd.create.call(this, x + offset, y + offset, points, fillColor, lineColor, lineWidth, tIsConvexPolygon, 0));
  11412. }
  11413. drawPath(x, y, paths, brush = null, pen = null) {
  11414. return this._saveToCmd(Render._context._drawPath, DrawPathCmd.create.call(this, x, y, paths, brush, pen));
  11415. }
  11416. draw9Grid(texture, x = 0, y = 0, width = 0, height = 0, sizeGrid = null) {
  11417. this._saveToCmd(null, Draw9GridTexture.create(texture, x, y, width, height, sizeGrid));
  11418. }
  11419. }
  11420. class Const {
  11421. }
  11422. Const.NOT_ACTIVE = 0x01;
  11423. Const.ACTIVE_INHIERARCHY = 0x02;
  11424. Const.AWAKED = 0x04;
  11425. Const.NOT_READY = 0x08;
  11426. Const.DISPLAY = 0x10;
  11427. Const.HAS_ZORDER = 0x20;
  11428. Const.HAS_MOUSE = 0x40;
  11429. Const.DISPLAYED_INSTAGE = 0x80;
  11430. Const.DRAWCALL_OPTIMIZE = 0x100;
  11431. class LayaGLQuickRunner {
  11432. static __init__() {
  11433. LayaGLQuickRunner.map[SpriteConst.ALPHA | SpriteConst.TRANSFORM | SpriteConst.GRAPHICS] = LayaGLQuickRunner.alpha_transform_drawLayaGL;
  11434. LayaGLQuickRunner.map[SpriteConst.ALPHA | SpriteConst.GRAPHICS] = LayaGLQuickRunner.alpha_drawLayaGL;
  11435. LayaGLQuickRunner.map[SpriteConst.TRANSFORM | SpriteConst.GRAPHICS] = LayaGLQuickRunner.transform_drawLayaGL;
  11436. LayaGLQuickRunner.map[SpriteConst.TRANSFORM | SpriteConst.CHILDS] = LayaGLQuickRunner.transform_drawNodes;
  11437. LayaGLQuickRunner.map[SpriteConst.ALPHA | SpriteConst.TRANSFORM | SpriteConst.TEXTURE] = LayaGLQuickRunner.alpha_transform_drawTexture;
  11438. LayaGLQuickRunner.map[SpriteConst.ALPHA | SpriteConst.TEXTURE] = LayaGLQuickRunner.alpha_drawTexture;
  11439. LayaGLQuickRunner.map[SpriteConst.TRANSFORM | SpriteConst.TEXTURE] = LayaGLQuickRunner.transform_drawTexture;
  11440. LayaGLQuickRunner.map[SpriteConst.GRAPHICS | SpriteConst.CHILDS] = LayaGLQuickRunner.drawLayaGL_drawNodes;
  11441. }
  11442. static transform_drawTexture(sprite, context, x, y) {
  11443. var style = sprite._style;
  11444. var tex = sprite.texture;
  11445. context.saveTransform(LayaGLQuickRunner.curMat);
  11446. context.transformByMatrix(sprite.transform, x, y);
  11447. context.drawTexture(tex, -sprite.pivotX, -sprite.pivotY, sprite._width || tex.width, sprite._height || tex.height);
  11448. context.restoreTransform(LayaGLQuickRunner.curMat);
  11449. }
  11450. static alpha_drawTexture(sprite, context, x, y) {
  11451. var style = sprite._style;
  11452. var alpha;
  11453. var tex = sprite.texture;
  11454. if ((alpha = style.alpha) > 0.01 || sprite._needRepaint()) {
  11455. var temp = context.globalAlpha;
  11456. context.globalAlpha *= alpha;
  11457. context.drawTexture(tex, x - style.pivotX + tex.offsetX, y - style.pivotY + tex.offsetY, sprite._width || tex.width, sprite._height || tex.height);
  11458. context.globalAlpha = temp;
  11459. }
  11460. }
  11461. static alpha_transform_drawTexture(sprite, context, x, y) {
  11462. var style = sprite._style;
  11463. var alpha;
  11464. var tex = sprite.texture;
  11465. if ((alpha = style.alpha) > 0.01 || sprite._needRepaint()) {
  11466. var temp = context.globalAlpha;
  11467. context.globalAlpha *= alpha;
  11468. context.saveTransform(LayaGLQuickRunner.curMat);
  11469. context.transformByMatrix(sprite.transform, x, y);
  11470. context.drawTexture(tex, -style.pivotX + tex.offsetX, -style.pivotY + tex.offsetY, sprite._width || tex.width, sprite._height || tex.height);
  11471. context.restoreTransform(LayaGLQuickRunner.curMat);
  11472. context.globalAlpha = temp;
  11473. }
  11474. }
  11475. static alpha_transform_drawLayaGL(sprite, context, x, y) {
  11476. var style = sprite._style;
  11477. var alpha;
  11478. if ((alpha = style.alpha) > 0.01 || sprite._needRepaint()) {
  11479. var temp = context.globalAlpha;
  11480. context.globalAlpha *= alpha;
  11481. context.saveTransform(LayaGLQuickRunner.curMat);
  11482. context.transformByMatrix(sprite.transform, x, y);
  11483. sprite._graphics && sprite._graphics._render(sprite, context, -style.pivotX, -style.pivotY);
  11484. context.restoreTransform(LayaGLQuickRunner.curMat);
  11485. context.globalAlpha = temp;
  11486. }
  11487. }
  11488. static alpha_drawLayaGL(sprite, context, x, y) {
  11489. var style = sprite._style;
  11490. var alpha;
  11491. if ((alpha = style.alpha) > 0.01 || sprite._needRepaint()) {
  11492. var temp = context.globalAlpha;
  11493. context.globalAlpha *= alpha;
  11494. sprite._graphics && sprite._graphics._render(sprite, context, x - style.pivotX, y - style.pivotY);
  11495. context.globalAlpha = temp;
  11496. }
  11497. }
  11498. static transform_drawLayaGL(sprite, context, x, y) {
  11499. var style = sprite._style;
  11500. context.saveTransform(LayaGLQuickRunner.curMat);
  11501. context.transformByMatrix(sprite.transform, x, y);
  11502. sprite._graphics && sprite._graphics._render(sprite, context, -style.pivotX, -style.pivotY);
  11503. context.restoreTransform(LayaGLQuickRunner.curMat);
  11504. }
  11505. static transform_drawNodes(sprite, context, x, y) {
  11506. var textLastRender = sprite._getBit(Const.DRAWCALL_OPTIMIZE) && context.drawCallOptimize(true);
  11507. var style = sprite._style;
  11508. context.saveTransform(LayaGLQuickRunner.curMat);
  11509. context.transformByMatrix(sprite.transform, x, y);
  11510. x = -style.pivotX;
  11511. y = -style.pivotY;
  11512. var childs = sprite._children, n = childs.length, ele;
  11513. if (style.viewport) {
  11514. var rect = style.viewport;
  11515. var left = rect.x;
  11516. var top = rect.y;
  11517. var right = rect.right;
  11518. var bottom = rect.bottom;
  11519. var _x, _y;
  11520. for (i = 0; i < n; ++i) {
  11521. if ((ele = childs[i])._visible && ((_x = ele._x) < right && (_x + ele.width) > left && (_y = ele._y) < bottom && (_y + ele.height) > top)) {
  11522. ele.render(context, x, y);
  11523. }
  11524. }
  11525. }
  11526. else {
  11527. for (var i = 0; i < n; ++i)
  11528. (ele = childs[i])._visible && ele.render(context, x, y);
  11529. }
  11530. context.restoreTransform(LayaGLQuickRunner.curMat);
  11531. textLastRender && context.drawCallOptimize(false);
  11532. }
  11533. static drawLayaGL_drawNodes(sprite, context, x, y) {
  11534. var textLastRender = sprite._getBit(Const.DRAWCALL_OPTIMIZE) && context.drawCallOptimize(true);
  11535. var style = sprite._style;
  11536. x = x - style.pivotX;
  11537. y = y - style.pivotY;
  11538. sprite._graphics && sprite._graphics._render(sprite, context, x, y);
  11539. var childs = sprite._children, n = childs.length, ele;
  11540. if (style.viewport) {
  11541. var rect = style.viewport;
  11542. var left = rect.x;
  11543. var top = rect.y;
  11544. var right = rect.right;
  11545. var bottom = rect.bottom;
  11546. var _x, _y;
  11547. for (i = 0; i < n; ++i) {
  11548. if ((ele = childs[i])._visible && ((_x = ele._x) < right && (_x + ele.width) > left && (_y = ele._y) < bottom && (_y + ele.height) > top)) {
  11549. ele.render(context, x, y);
  11550. }
  11551. }
  11552. }
  11553. else {
  11554. for (var i = 0; i < n; ++i)
  11555. (ele = childs[i])._visible && ele.render(context, x, y);
  11556. }
  11557. textLastRender && context.drawCallOptimize(false);
  11558. }
  11559. }
  11560. LayaGLQuickRunner.map = {};
  11561. LayaGLQuickRunner.curMat = new Matrix();
  11562. class RenderSprite {
  11563. constructor(type, next) {
  11564. if (LayaGLQuickRunner.map[type]) {
  11565. this._fun = LayaGLQuickRunner.map[type];
  11566. this._next = RenderSprite.NORENDER;
  11567. return;
  11568. }
  11569. this._next = next || RenderSprite.NORENDER;
  11570. switch (type) {
  11571. case 0:
  11572. this._fun = this._no;
  11573. return;
  11574. case SpriteConst.ALPHA:
  11575. this._fun = this._alpha;
  11576. return;
  11577. case SpriteConst.TRANSFORM:
  11578. this._fun = this._transform;
  11579. return;
  11580. case SpriteConst.BLEND:
  11581. this._fun = this._blend;
  11582. return;
  11583. case SpriteConst.CANVAS:
  11584. this._fun = this._canvas;
  11585. return;
  11586. case SpriteConst.MASK:
  11587. this._fun = this._mask;
  11588. return;
  11589. case SpriteConst.CLIP:
  11590. this._fun = this._clip;
  11591. return;
  11592. case SpriteConst.STYLE:
  11593. this._fun = this._style;
  11594. return;
  11595. case SpriteConst.GRAPHICS:
  11596. this._fun = this._graphics;
  11597. return;
  11598. case SpriteConst.CHILDS:
  11599. this._fun = this._children;
  11600. return;
  11601. case SpriteConst.CUSTOM:
  11602. this._fun = this._custom;
  11603. return;
  11604. case SpriteConst.TEXTURE:
  11605. this._fun = this._texture;
  11606. return;
  11607. case SpriteConst.FILTERS:
  11608. this._fun = Filter._filter;
  11609. return;
  11610. case RenderSprite.INIT:
  11611. this._fun = RenderSprite._initRenderFun;
  11612. return;
  11613. }
  11614. this.onCreate(type);
  11615. }
  11616. static __init__() {
  11617. LayaGLQuickRunner.__init__();
  11618. var i, len;
  11619. var initRender;
  11620. initRender = new RenderSprite(RenderSprite.INIT, null);
  11621. len = RenderSprite.renders.length = SpriteConst.CHILDS * 2;
  11622. for (i = 0; i < len; i++)
  11623. RenderSprite.renders[i] = initRender;
  11624. RenderSprite.renders[0] = new RenderSprite(0, null);
  11625. }
  11626. static _initRenderFun(sprite, context, x, y) {
  11627. var type = sprite._renderType;
  11628. var r = RenderSprite.renders[type] = RenderSprite._getTypeRender(type);
  11629. r._fun(sprite, context, x, y);
  11630. }
  11631. static _getTypeRender(type) {
  11632. if (LayaGLQuickRunner.map[type])
  11633. return new RenderSprite(type, null);
  11634. var rst = null;
  11635. var tType = SpriteConst.CHILDS;
  11636. while (tType > 0) {
  11637. if (tType & type)
  11638. rst = new RenderSprite(tType, rst);
  11639. tType = tType >> 1;
  11640. }
  11641. return rst;
  11642. }
  11643. onCreate(type) {
  11644. }
  11645. _style(sprite, context, x, y) {
  11646. var style = sprite._style;
  11647. if (style.render != null)
  11648. style.render(sprite, context, x, y);
  11649. var next = this._next;
  11650. next._fun.call(next, sprite, context, x, y);
  11651. }
  11652. _no(sprite, context, x, y) {
  11653. }
  11654. _custom(sprite, context, x, y) {
  11655. sprite.customRender(context, x, y);
  11656. this._next._fun.call(this._next, sprite, context, x - sprite.pivotX, y - sprite.pivotY);
  11657. }
  11658. _clip(sprite, context, x, y) {
  11659. var next = this._next;
  11660. if (next == RenderSprite.NORENDER)
  11661. return;
  11662. var r = sprite._style.scrollRect;
  11663. context.save();
  11664. context.clipRect(x, y, r.width, r.height);
  11665. next._fun.call(next, sprite, context, x - r.x, y - r.y);
  11666. context.restore();
  11667. }
  11668. _texture(sprite, context, x, y) {
  11669. var tex = sprite.texture;
  11670. if (tex._getSource())
  11671. context.drawTexture(tex, x - sprite.pivotX + tex.offsetX, y - sprite.pivotY + tex.offsetY, sprite._width || tex.width, sprite._height || tex.height);
  11672. var next = this._next;
  11673. if (next != RenderSprite.NORENDER)
  11674. next._fun.call(next, sprite, context, x, y);
  11675. }
  11676. _graphics(sprite, context, x, y) {
  11677. var style = sprite._style;
  11678. var g = sprite._graphics;
  11679. g && g._render(sprite, context, x - style.pivotX, y - style.pivotY);
  11680. var next = this._next;
  11681. if (next != RenderSprite.NORENDER)
  11682. next._fun.call(next, sprite, context, x, y);
  11683. }
  11684. _image(sprite, context, x, y) {
  11685. var style = sprite._style;
  11686. context.drawTexture2(x, y, style.pivotX, style.pivotY, sprite.transform, sprite._graphics._one);
  11687. }
  11688. _image2(sprite, context, x, y) {
  11689. var style = sprite._style;
  11690. context.drawTexture2(x, y, style.pivotX, style.pivotY, sprite.transform, sprite._graphics._one);
  11691. }
  11692. _alpha(sprite, context, x, y) {
  11693. var style = sprite._style;
  11694. var alpha;
  11695. if ((alpha = style.alpha) > 0.01 || sprite._needRepaint()) {
  11696. var temp = context.globalAlpha;
  11697. context.globalAlpha *= alpha;
  11698. var next = this._next;
  11699. next._fun.call(next, sprite, context, x, y);
  11700. context.globalAlpha = temp;
  11701. }
  11702. }
  11703. _transform(sprite, context, x, y) {
  11704. var transform = sprite.transform, _next = this._next;
  11705. var style = sprite._style;
  11706. if (transform && _next != RenderSprite.NORENDER) {
  11707. context.save();
  11708. context.transform(transform.a, transform.b, transform.c, transform.d, transform.tx + x, transform.ty + y);
  11709. _next._fun.call(_next, sprite, context, 0, 0);
  11710. context.restore();
  11711. }
  11712. else {
  11713. if (_next != RenderSprite.NORENDER)
  11714. _next._fun.call(_next, sprite, context, x, y);
  11715. }
  11716. }
  11717. _children(sprite, context, x, y) {
  11718. var style = sprite._style;
  11719. var childs = sprite._children, n = childs.length, ele;
  11720. x = x - sprite.pivotX;
  11721. y = y - sprite.pivotY;
  11722. var textLastRender = sprite._getBit(Const.DRAWCALL_OPTIMIZE) && context.drawCallOptimize(true);
  11723. if (style.viewport) {
  11724. var rect = style.viewport;
  11725. var left = rect.x;
  11726. var top = rect.y;
  11727. var right = rect.right;
  11728. var bottom = rect.bottom;
  11729. var _x, _y;
  11730. for (i = 0; i < n; ++i) {
  11731. if ((ele = childs[i])._visible && ((_x = ele._x) < right && (_x + ele.width) > left && (_y = ele._y) < bottom && (_y + ele.height) > top)) {
  11732. ele.render(context, x, y);
  11733. }
  11734. }
  11735. }
  11736. else {
  11737. for (var i = 0; i < n; ++i)
  11738. (ele = childs[i])._visible && ele.render(context, x, y);
  11739. }
  11740. textLastRender && context.drawCallOptimize(false);
  11741. }
  11742. _canvas(sprite, context, x, y) {
  11743. var _cacheStyle = sprite._cacheStyle;
  11744. var _next = this._next;
  11745. if (!_cacheStyle.enableCanvasRender) {
  11746. _next._fun.call(_next, sprite, context, x, y);
  11747. return;
  11748. }
  11749. _cacheStyle.cacheAs === 'bitmap' ? (Stat.canvasBitmap++) : (Stat.canvasNormal++);
  11750. var cacheNeedRebuild = false;
  11751. var textNeedRestore = false;
  11752. if (_cacheStyle.canvas) {
  11753. var canv = _cacheStyle.canvas;
  11754. var ctx = canv.context;
  11755. var charRIs = canv.touches;
  11756. if (charRIs) {
  11757. for (var ci = 0; ci < charRIs.length; ci++) {
  11758. if (charRIs[ci].deleted) {
  11759. textNeedRestore = true;
  11760. break;
  11761. }
  11762. }
  11763. }
  11764. cacheNeedRebuild = canv.isCacheValid && !canv.isCacheValid();
  11765. }
  11766. if (sprite._needRepaint() || (!_cacheStyle.canvas) || textNeedRestore || cacheNeedRebuild || ILaya.stage.isGlobalRepaint()) {
  11767. if (_cacheStyle.cacheAs === 'normal') {
  11768. if (context._targets) {
  11769. _next._fun.call(_next, sprite, context, x, y);
  11770. return;
  11771. }
  11772. else {
  11773. this._canvas_webgl_normal_repaint(sprite, context);
  11774. }
  11775. }
  11776. else {
  11777. this._canvas_repaint(sprite, context, x, y);
  11778. }
  11779. }
  11780. var tRec = _cacheStyle.cacheRect;
  11781. context.drawCanvas(_cacheStyle.canvas, x + tRec.x, y + tRec.y, tRec.width, tRec.height);
  11782. }
  11783. _canvas_repaint(sprite, context, x, y) {
  11784. var _cacheStyle = sprite._cacheStyle;
  11785. var _next = this._next;
  11786. var tx;
  11787. var canvas = _cacheStyle.canvas;
  11788. var left;
  11789. var top;
  11790. var tRec;
  11791. var tCacheType = _cacheStyle.cacheAs;
  11792. var w, h;
  11793. var scaleX, scaleY;
  11794. var scaleInfo;
  11795. scaleInfo = _cacheStyle._calculateCacheRect(sprite, tCacheType, x, y);
  11796. scaleX = scaleInfo.x;
  11797. scaleY = scaleInfo.y;
  11798. tRec = _cacheStyle.cacheRect;
  11799. w = tRec.width * scaleX;
  11800. h = tRec.height * scaleY;
  11801. left = tRec.x;
  11802. top = tRec.y;
  11803. if (tCacheType === 'bitmap' && (w > 2048 || h > 2048)) {
  11804. console.warn("cache bitmap size larger than 2048,cache ignored");
  11805. _cacheStyle.releaseContext();
  11806. _next._fun.call(_next, sprite, context, x, y);
  11807. return;
  11808. }
  11809. if (!canvas) {
  11810. _cacheStyle.createContext();
  11811. canvas = _cacheStyle.canvas;
  11812. }
  11813. tx = canvas.context;
  11814. tx.sprite = sprite;
  11815. (canvas.width != w || canvas.height != h) && canvas.size(w, h);
  11816. if (tCacheType === 'bitmap')
  11817. tx.asBitmap = true;
  11818. else if (tCacheType === 'normal')
  11819. tx.asBitmap = false;
  11820. tx.clear();
  11821. if (scaleX != 1 || scaleY != 1) {
  11822. var ctx = tx;
  11823. ctx.save();
  11824. ctx.scale(scaleX, scaleY);
  11825. _next._fun.call(_next, sprite, tx, -left, -top);
  11826. ctx.restore();
  11827. sprite._applyFilters();
  11828. }
  11829. else {
  11830. ctx = tx;
  11831. _next._fun.call(_next, sprite, tx, -left, -top);
  11832. sprite._applyFilters();
  11833. }
  11834. if (_cacheStyle.staticCache)
  11835. _cacheStyle.reCache = false;
  11836. Stat.canvasReCache++;
  11837. }
  11838. _canvas_webgl_normal_repaint(sprite, context) {
  11839. var _cacheStyle = sprite._cacheStyle;
  11840. var _next = this._next;
  11841. var canvas = _cacheStyle.canvas;
  11842. var tCacheType = _cacheStyle.cacheAs;
  11843. _cacheStyle._calculateCacheRect(sprite, tCacheType, 0, 0);
  11844. if (!canvas) {
  11845. canvas = _cacheStyle.canvas = new WebGLCacheAsNormalCanvas(context, sprite);
  11846. }
  11847. var tx = canvas.context;
  11848. canvas['startRec']();
  11849. _next._fun.call(_next, sprite, tx, sprite.pivotX, sprite.pivotY);
  11850. sprite._applyFilters();
  11851. Stat.canvasReCache++;
  11852. canvas['endRec']();
  11853. }
  11854. _blend(sprite, context, x, y) {
  11855. var style = sprite._style;
  11856. var next = this._next;
  11857. if (style.blendMode) {
  11858. context.save();
  11859. context.globalCompositeOperation = style.blendMode;
  11860. next._fun.call(next, sprite, context, x, y);
  11861. context.restore();
  11862. }
  11863. else {
  11864. next._fun.call(next, sprite, context, x, y);
  11865. }
  11866. }
  11867. _mask(sprite, context, x, y) {
  11868. var next = this._next;
  11869. var mask = sprite.mask;
  11870. var ctx = context;
  11871. if (mask) {
  11872. ctx.save();
  11873. var preBlendMode = ctx.globalCompositeOperation;
  11874. var tRect = new Rectangle();
  11875. tRect.copyFrom(mask.getBounds());
  11876. tRect.width = Math.round(tRect.width);
  11877. tRect.height = Math.round(tRect.height);
  11878. tRect.x = Math.round(tRect.x);
  11879. tRect.y = Math.round(tRect.y);
  11880. if (tRect.width > 0 && tRect.height > 0) {
  11881. var w = tRect.width;
  11882. var h = tRect.height;
  11883. var tmpRT = WebGLRTMgr.getRT(w, h);
  11884. ctx.breakNextMerge();
  11885. ctx.pushRT();
  11886. ctx.addRenderObject(SubmitCMD.create([ctx, tmpRT, w, h], RenderSprite.tmpTarget, this));
  11887. mask.render(ctx, -tRect.x, -tRect.y);
  11888. ctx.breakNextMerge();
  11889. ctx.popRT();
  11890. ctx.save();
  11891. ctx.clipRect(x + tRect.x - sprite.getStyle().pivotX, y + tRect.y - sprite.getStyle().pivotY, w, h);
  11892. next._fun.call(next, sprite, ctx, x, y);
  11893. ctx.restore();
  11894. preBlendMode = ctx.globalCompositeOperation;
  11895. ctx.addRenderObject(SubmitCMD.create(["mask"], RenderSprite.setBlendMode, this));
  11896. var shaderValue = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  11897. var uv = Texture.INV_UV;
  11898. ctx.drawTarget(tmpRT, x + tRect.x - sprite.getStyle().pivotX, y + tRect.y - sprite.getStyle().pivotY, w, h, Matrix.TEMP.identity(), shaderValue, uv, 6);
  11899. ctx.addRenderObject(SubmitCMD.create([tmpRT], RenderSprite.recycleTarget, this));
  11900. ctx.addRenderObject(SubmitCMD.create([preBlendMode], RenderSprite.setBlendMode, this));
  11901. }
  11902. ctx.restore();
  11903. }
  11904. else {
  11905. next._fun.call(next, sprite, context, x, y);
  11906. }
  11907. }
  11908. static tmpTarget(ctx, rt, w, h) {
  11909. rt.start();
  11910. rt.clear(0, 0, 0, 0);
  11911. }
  11912. static recycleTarget(rt) {
  11913. WebGLRTMgr.releaseRT(rt);
  11914. }
  11915. static setBlendMode(blendMode) {
  11916. var gl = WebGLContext.mainContext;
  11917. BlendMode.targetFns[BlendMode.TOINT[blendMode]](gl);
  11918. }
  11919. }
  11920. RenderSprite.INIT = 0x11111;
  11921. RenderSprite.renders = [];
  11922. RenderSprite.NORENDER = new RenderSprite(0, null);
  11923. RenderSprite.tempUV = new Array(8);
  11924. class HTMLCanvas extends Bitmap {
  11925. get source() {
  11926. return this._source;
  11927. }
  11928. _getSource() {
  11929. return this._source;
  11930. }
  11931. constructor(createCanvas = false) {
  11932. super();
  11933. if (createCanvas)
  11934. this._source = Browser.createElement("canvas");
  11935. else {
  11936. this._source = this;
  11937. }
  11938. this.lock = true;
  11939. }
  11940. clear() {
  11941. this._ctx && this._ctx.clear && this._ctx.clear();
  11942. if (this._texture) {
  11943. this._texture.destroy();
  11944. this._texture = null;
  11945. }
  11946. }
  11947. destroy() {
  11948. super.destroy();
  11949. this._setCPUMemory(0);
  11950. this._ctx && this._ctx.destroy && this._ctx.destroy();
  11951. this._ctx = null;
  11952. }
  11953. release() {
  11954. }
  11955. get context() {
  11956. if (this._ctx)
  11957. return this._ctx;
  11958. if (this._source == this) {
  11959. this._ctx = new ILaya.Context();
  11960. }
  11961. else {
  11962. this._ctx = this._source.getContext(ILaya.Render.isConchApp ? 'layagl' : '2d');
  11963. }
  11964. this._ctx._canvas = this;
  11965. return this._ctx;
  11966. }
  11967. _setContext(context) {
  11968. this._ctx = context;
  11969. }
  11970. getContext(contextID, other = null) {
  11971. return this.context;
  11972. }
  11973. getMemSize() {
  11974. return 0;
  11975. }
  11976. size(w, h) {
  11977. if (this._width != w || this._height != h || (this._source && (this._source.width != w || this._source.height != h))) {
  11978. this._width = w;
  11979. this._height = h;
  11980. this._setCPUMemory(w * h * 4);
  11981. this._ctx && this._ctx.size && this._ctx.size(w, h);
  11982. if (this._source) {
  11983. this._source.height = h;
  11984. this._source.width = w;
  11985. }
  11986. if (this._texture) {
  11987. this._texture.destroy();
  11988. this._texture = null;
  11989. }
  11990. }
  11991. }
  11992. getTexture() {
  11993. if (!this._texture) {
  11994. var bitmap = new Texture2D();
  11995. bitmap.loadImageSource(this.source);
  11996. this._texture = new Texture(bitmap);
  11997. }
  11998. return this._texture;
  11999. }
  12000. toBase64(type, encoderOptions) {
  12001. if (this._source) {
  12002. if (ILaya.Render.isConchApp) {
  12003. var win = window;
  12004. if (win.conchConfig.threadMode == 2) {
  12005. throw "native 2 thread mode use toBase64Async";
  12006. }
  12007. var width = this._ctx._targets.sourceWidth;
  12008. var height = this._ctx._targets.sourceHeight;
  12009. var data = this._ctx._targets.getData(0, 0, width, height);
  12010. return win.conchToBase64FlipY ? win.conchToBase64FlipY(type, encoderOptions, data.buffer, width, height) : win.conchToBase64(type, encoderOptions, data.buffer, width, height);
  12011. }
  12012. else {
  12013. return this._source.toDataURL(type, encoderOptions);
  12014. }
  12015. }
  12016. return null;
  12017. }
  12018. toBase64Async(type, encoderOptions, callBack) {
  12019. var width = this._ctx._targets.sourceWidth;
  12020. var height = this._ctx._targets.sourceHeight;
  12021. this._ctx._targets.getDataAsync(0, 0, width, height, function (data) {
  12022. let win = window;
  12023. var base64 = win.conchToBase64FlipY ? win.conchToBase64FlipY(type, encoderOptions, data.buffer, width, height) : win.conchToBase64(type, encoderOptions, data.buffer, width, height);
  12024. callBack(base64);
  12025. });
  12026. }
  12027. }
  12028. class HitArea {
  12029. contains(x, y) {
  12030. if (!HitArea._isHitGraphic(x, y, this.hit))
  12031. return false;
  12032. return !HitArea._isHitGraphic(x, y, this.unHit);
  12033. }
  12034. static _isHitGraphic(x, y, graphic) {
  12035. if (!graphic)
  12036. return false;
  12037. var cmds = graphic.cmds;
  12038. if (!cmds && graphic._one) {
  12039. cmds = HitArea._cmds;
  12040. cmds.length = 1;
  12041. cmds[0] = graphic._one;
  12042. }
  12043. if (!cmds)
  12044. return false;
  12045. var i, len;
  12046. len = cmds.length;
  12047. var cmd;
  12048. for (i = 0; i < len; i++) {
  12049. cmd = cmds[i];
  12050. if (!cmd)
  12051. continue;
  12052. switch (cmd.cmdID) {
  12053. case "Translate":
  12054. x -= cmd.tx;
  12055. y -= cmd.ty;
  12056. }
  12057. if (HitArea._isHitCmd(x, y, cmd))
  12058. return true;
  12059. }
  12060. return false;
  12061. }
  12062. static _isHitCmd(x, y, cmd) {
  12063. if (!cmd)
  12064. return false;
  12065. var rst = false;
  12066. switch (cmd.cmdID) {
  12067. case "DrawRect":
  12068. HitArea._rect.setTo(cmd.x, cmd.y, cmd.width, cmd.height);
  12069. rst = HitArea._rect.contains(x, y);
  12070. break;
  12071. case "DrawCircle":
  12072. var d;
  12073. x -= cmd.x;
  12074. y -= cmd.y;
  12075. d = x * x + y * y;
  12076. rst = d < cmd.radius * cmd.radius;
  12077. break;
  12078. case "DrawPoly":
  12079. x -= cmd.x;
  12080. y -= cmd.y;
  12081. rst = HitArea._ptInPolygon(x, y, cmd.points);
  12082. break;
  12083. }
  12084. return rst;
  12085. }
  12086. static _ptInPolygon(x, y, areaPoints) {
  12087. var p = HitArea._ptPoint;
  12088. p.setTo(x, y);
  12089. var nCross = 0;
  12090. var p1x, p1y, p2x, p2y;
  12091. var len;
  12092. len = areaPoints.length;
  12093. for (var i = 0; i < len; i += 2) {
  12094. p1x = areaPoints[i];
  12095. p1y = areaPoints[i + 1];
  12096. p2x = areaPoints[(i + 2) % len];
  12097. p2y = areaPoints[(i + 3) % len];
  12098. if (p1y == p2y)
  12099. continue;
  12100. if (p.y < Math.min(p1y, p2y))
  12101. continue;
  12102. if (p.y >= Math.max(p1y, p2y))
  12103. continue;
  12104. var tx = (p.y - p1y) * (p2x - p1x) / (p2y - p1y) + p1x;
  12105. if (tx > p.x)
  12106. nCross++;
  12107. }
  12108. return (nCross % 2 == 1);
  12109. }
  12110. get hit() {
  12111. if (!this._hit)
  12112. this._hit = new ILaya.Graphics();
  12113. return this._hit;
  12114. }
  12115. set hit(value) {
  12116. this._hit = value;
  12117. }
  12118. get unHit() {
  12119. if (!this._unHit)
  12120. this._unHit = new ILaya.Graphics();
  12121. return this._unHit;
  12122. }
  12123. set unHit(value) {
  12124. this._unHit = value;
  12125. }
  12126. }
  12127. HitArea._cmds = [];
  12128. HitArea._rect = new Rectangle();
  12129. HitArea._ptPoint = new Point();
  12130. class ClassUtils {
  12131. static regClass(className, classDef) {
  12132. ClassUtils._classMap[className] = classDef;
  12133. }
  12134. static regShortClassName(classes) {
  12135. for (var i = 0; i < classes.length; i++) {
  12136. var classDef = classes[i];
  12137. var className = classDef.name;
  12138. ClassUtils._classMap[className] = classDef;
  12139. }
  12140. }
  12141. static getRegClass(className) {
  12142. return ClassUtils._classMap[className];
  12143. }
  12144. static getClass(className) {
  12145. var classObject = ClassUtils._classMap[className] || ClassUtils._classMap['Laya.' + className] || className;
  12146. var glaya = ILaya.Laya;
  12147. if (typeof (classObject) == 'string')
  12148. return (ILaya.__classMap[classObject] || glaya[className]);
  12149. return classObject;
  12150. }
  12151. static getInstance(className) {
  12152. var compClass = ClassUtils.getClass(className);
  12153. if (compClass)
  12154. return new compClass();
  12155. else
  12156. console.warn("[error] Undefined class:", className);
  12157. return null;
  12158. }
  12159. static createByJson(json, node = null, root = null, customHandler = null, instanceHandler = null) {
  12160. if (typeof (json) == 'string')
  12161. json = JSON.parse(json);
  12162. var props = json.props;
  12163. if (!node) {
  12164. node = instanceHandler ? instanceHandler.runWith(json) : ClassUtils.getInstance(props.runtime || json.type);
  12165. if (!node)
  12166. return null;
  12167. }
  12168. var child = json.child;
  12169. if (child) {
  12170. for (var i = 0, n = child.length; i < n; i++) {
  12171. var data = child[i];
  12172. if ((data.props.name === "render" || data.props.renderType === "render") && node["_$set_itemRender"])
  12173. node.itemRender = data;
  12174. else {
  12175. if (data.type == "Graphic") {
  12176. ClassUtils._addGraphicsToSprite(data, node);
  12177. }
  12178. else if (ClassUtils._isDrawType(data.type)) {
  12179. ClassUtils._addGraphicToSprite(data, node, true);
  12180. }
  12181. else {
  12182. var tChild = ClassUtils.createByJson(data, null, root, customHandler, instanceHandler);
  12183. if (data.type === "Script") {
  12184. if ("owner" in tChild) {
  12185. tChild["owner"] = node;
  12186. }
  12187. else if ("target" in tChild) {
  12188. tChild["target"] = node;
  12189. }
  12190. }
  12191. else if (data.props.renderType == "mask") {
  12192. node.mask = tChild;
  12193. }
  12194. else {
  12195. node.addChild(tChild);
  12196. }
  12197. }
  12198. }
  12199. }
  12200. }
  12201. if (props) {
  12202. for (var prop in props) {
  12203. var value = props[prop];
  12204. if (prop === "var" && root) {
  12205. root[value] = node;
  12206. }
  12207. else if (value instanceof Array && node[prop] instanceof Function) {
  12208. node[prop].apply(node, value);
  12209. }
  12210. else {
  12211. node[prop] = value;
  12212. }
  12213. }
  12214. }
  12215. if (customHandler && json.customProps) {
  12216. customHandler.runWith([node, json]);
  12217. }
  12218. if (node["created"])
  12219. node.created();
  12220. return node;
  12221. }
  12222. static _addGraphicsToSprite(graphicO, sprite) {
  12223. var graphics = graphicO.child;
  12224. if (!graphics || graphics.length < 1)
  12225. return;
  12226. var g = ClassUtils._getGraphicsFromSprite(graphicO, sprite);
  12227. var ox = 0;
  12228. var oy = 0;
  12229. if (graphicO.props) {
  12230. ox = ClassUtils._getObjVar(graphicO.props, "x", 0);
  12231. oy = ClassUtils._getObjVar(graphicO.props, "y", 0);
  12232. }
  12233. if (ox != 0 && oy != 0) {
  12234. g.translate(ox, oy);
  12235. }
  12236. var i, len;
  12237. len = graphics.length;
  12238. for (i = 0; i < len; i++) {
  12239. ClassUtils._addGraphicToGraphics(graphics[i], g);
  12240. }
  12241. if (ox != 0 && oy != 0) {
  12242. g.translate(-ox, -oy);
  12243. }
  12244. }
  12245. static _addGraphicToSprite(graphicO, sprite, isChild = false) {
  12246. var g = isChild ? ClassUtils._getGraphicsFromSprite(graphicO, sprite) : sprite.graphics;
  12247. ClassUtils._addGraphicToGraphics(graphicO, g);
  12248. }
  12249. static _getGraphicsFromSprite(dataO, sprite) {
  12250. if (!dataO || !dataO.props)
  12251. return sprite.graphics;
  12252. var propsName = dataO.props.renderType;
  12253. if (propsName === "hit" || propsName === "unHit") {
  12254. var hitArea = sprite._style.hitArea || (sprite.hitArea = new HitArea());
  12255. if (!hitArea[propsName]) {
  12256. hitArea[propsName] = new Graphics();
  12257. }
  12258. var g = hitArea[propsName];
  12259. }
  12260. if (!g)
  12261. g = sprite.graphics;
  12262. return g;
  12263. }
  12264. static _getTransformData(propsO) {
  12265. var m;
  12266. if ("pivotX" in propsO || "pivotY" in propsO) {
  12267. m = m || new Matrix();
  12268. m.translate(-ClassUtils._getObjVar(propsO, "pivotX", 0), -ClassUtils._getObjVar(propsO, "pivotY", 0));
  12269. }
  12270. var sx = ClassUtils._getObjVar(propsO, "scaleX", 1), sy = ClassUtils._getObjVar(propsO, "scaleY", 1);
  12271. var rotate = ClassUtils._getObjVar(propsO, "rotation", 0);
  12272. var skewX = ClassUtils._getObjVar(propsO, "skewX", 0);
  12273. var skewY = ClassUtils._getObjVar(propsO, "skewY", 0);
  12274. if (sx != 1 || sy != 1 || rotate != 0) {
  12275. m = m || new Matrix();
  12276. m.scale(sx, sy);
  12277. m.rotate(rotate * 0.0174532922222222);
  12278. }
  12279. return m;
  12280. }
  12281. static _addGraphicToGraphics(graphicO, graphic) {
  12282. var propsO;
  12283. propsO = graphicO.props;
  12284. if (!propsO)
  12285. return;
  12286. var drawConfig;
  12287. drawConfig = ClassUtils.DrawTypeDic[graphicO.type];
  12288. if (!drawConfig)
  12289. return;
  12290. var g = graphic;
  12291. var params = ClassUtils._getParams(propsO, drawConfig[1], drawConfig[2], drawConfig[3]);
  12292. var m = ClassUtils._tM;
  12293. if (m || ClassUtils._alpha != 1) {
  12294. g.save();
  12295. if (m)
  12296. g.transform(m);
  12297. if (ClassUtils._alpha != 1)
  12298. g.alpha(ClassUtils._alpha);
  12299. }
  12300. g[drawConfig[0]].apply(g, params);
  12301. if (m || ClassUtils._alpha != 1) {
  12302. g.restore();
  12303. }
  12304. }
  12305. static _adptLineData(params) {
  12306. params[2] = parseFloat(params[0]) + parseFloat(params[2]);
  12307. params[3] = parseFloat(params[1]) + parseFloat(params[3]);
  12308. return params;
  12309. }
  12310. static _adptTextureData(params) {
  12311. params[0] = ILaya.Loader.getRes(params[0]);
  12312. return params;
  12313. }
  12314. static _adptLinesData(params) {
  12315. params[2] = ClassUtils._getPointListByStr(params[2]);
  12316. return params;
  12317. }
  12318. static _isDrawType(type) {
  12319. if (type === "Image")
  12320. return false;
  12321. return type in ClassUtils.DrawTypeDic;
  12322. }
  12323. static _getParams(obj, params, xPos = 0, adptFun = null) {
  12324. var rst = ClassUtils._temParam;
  12325. rst.length = params.length;
  12326. var i, len;
  12327. len = params.length;
  12328. for (i = 0; i < len; i++) {
  12329. rst[i] = ClassUtils._getObjVar(obj, params[i][0], params[i][1]);
  12330. }
  12331. ClassUtils._alpha = ClassUtils._getObjVar(obj, "alpha", 1);
  12332. var m;
  12333. m = ClassUtils._getTransformData(obj);
  12334. if (m) {
  12335. if (!xPos)
  12336. xPos = 0;
  12337. m.translate(rst[xPos], rst[xPos + 1]);
  12338. rst[xPos] = rst[xPos + 1] = 0;
  12339. ClassUtils._tM = m;
  12340. }
  12341. else {
  12342. ClassUtils._tM = null;
  12343. }
  12344. if (adptFun && ClassUtils[adptFun]) {
  12345. rst = ClassUtils[adptFun](rst);
  12346. }
  12347. return rst;
  12348. }
  12349. static _getPointListByStr(str) {
  12350. var pointArr = str.split(",");
  12351. var i, len;
  12352. len = pointArr.length;
  12353. for (i = 0; i < len; i++) {
  12354. pointArr[i] = parseFloat(pointArr[i]);
  12355. }
  12356. return pointArr;
  12357. }
  12358. static _getObjVar(obj, key, noValue) {
  12359. if (key in obj) {
  12360. return obj[key];
  12361. }
  12362. return noValue;
  12363. }
  12364. }
  12365. ClassUtils.DrawTypeDic = { "Rect": ["drawRect", [["x", 0], ["y", 0], ["width", 0], ["height", 0], ["fillColor", null], ["lineColor", null], ["lineWidth", 1]]], "Circle": ["drawCircle", [["x", 0], ["y", 0], ["radius", 0], ["fillColor", null], ["lineColor", null], ["lineWidth", 1]]], "Pie": ["drawPie", [["x", 0], ["y", 0], ["radius", 0], ["startAngle", 0], ["endAngle", 0], ["fillColor", null], ["lineColor", null], ["lineWidth", 1]]], "Image": ["drawTexture", [["x", 0], ["y", 0], ["width", 0], ["height", 0]]], "Texture": ["drawTexture", [["skin", null], ["x", 0], ["y", 0], ["width", 0], ["height", 0]], 1, "_adptTextureData"], "FillTexture": ["fillTexture", [["skin", null], ["x", 0], ["y", 0], ["width", 0], ["height", 0], ["repeat", null]], 1, "_adptTextureData"], "FillText": ["fillText", [["text", ""], ["x", 0], ["y", 0], ["font", null], ["color", null], ["textAlign", null]], 1], "Line": ["drawLine", [["x", 0], ["y", 0], ["toX", 0], ["toY", 0], ["lineColor", null], ["lineWidth", 0]], 0, "_adptLineData"], "Lines": ["drawLines", [["x", 0], ["y", 0], ["points", ""], ["lineColor", null], ["lineWidth", 0]], 0, "_adptLinesData"], "Curves": ["drawCurves", [["x", 0], ["y", 0], ["points", ""], ["lineColor", null], ["lineWidth", 0]], 0, "_adptLinesData"], "Poly": ["drawPoly", [["x", 0], ["y", 0], ["points", ""], ["fillColor", null], ["lineColor", null], ["lineWidth", 1]], 0, "_adptLinesData"] };
  12366. ClassUtils._temParam = [];
  12367. ClassUtils._classMap = {};
  12368. class BoundsStyle {
  12369. reset() {
  12370. if (this.bounds)
  12371. this.bounds.recover();
  12372. if (this.userBounds)
  12373. this.userBounds.recover();
  12374. this.bounds = null;
  12375. this.userBounds = null;
  12376. this.temBM = null;
  12377. return this;
  12378. }
  12379. recover() {
  12380. Pool.recover("BoundsStyle", this.reset());
  12381. }
  12382. static create() {
  12383. return Pool.getItemByClass("BoundsStyle", BoundsStyle);
  12384. }
  12385. }
  12386. class CacheStyle {
  12387. constructor() {
  12388. this.reset();
  12389. }
  12390. needBitmapCache() {
  12391. return this.cacheForFilters || !!this.mask;
  12392. }
  12393. needEnableCanvasRender() {
  12394. return this.userSetCache != "none" || this.cacheForFilters || !!this.mask;
  12395. }
  12396. releaseContext() {
  12397. if (this.canvas && this.canvas.size) {
  12398. Pool.recover("CacheCanvas", this.canvas);
  12399. this.canvas.size(0, 0);
  12400. try {
  12401. this.canvas.width = 0;
  12402. this.canvas.height = 0;
  12403. }
  12404. catch (e) {
  12405. }
  12406. }
  12407. this.canvas = null;
  12408. }
  12409. createContext() {
  12410. if (!this.canvas) {
  12411. this.canvas = Pool.getItem("CacheCanvas") || new HTMLCanvas(false);
  12412. var tx = this.canvas.context;
  12413. if (!tx) {
  12414. tx = this.canvas.getContext('2d');
  12415. }
  12416. }
  12417. }
  12418. releaseFilterCache() {
  12419. var fc = this.filterCache;
  12420. if (fc) {
  12421. fc.destroy();
  12422. fc.recycle();
  12423. this.filterCache = null;
  12424. }
  12425. }
  12426. recover() {
  12427. if (this === CacheStyle.EMPTY)
  12428. return;
  12429. Pool.recover("SpriteCache", this.reset());
  12430. }
  12431. reset() {
  12432. this.releaseContext();
  12433. this.releaseFilterCache();
  12434. this.cacheAs = "none";
  12435. this.enableCanvasRender = false;
  12436. this.userSetCache = "none";
  12437. this.cacheForFilters = false;
  12438. this.staticCache = false;
  12439. this.reCache = true;
  12440. this.mask = null;
  12441. this.maskParent = null;
  12442. this.filterCache = null;
  12443. this.filters = null;
  12444. this.hasGlowFilter = false;
  12445. if (this.cacheRect)
  12446. this.cacheRect.recover();
  12447. this.cacheRect = null;
  12448. return this;
  12449. }
  12450. static create() {
  12451. return Pool.getItemByClass("SpriteCache", CacheStyle);
  12452. }
  12453. _calculateCacheRect(sprite, tCacheType, x, y) {
  12454. var _cacheStyle = sprite._cacheStyle;
  12455. if (!_cacheStyle.cacheRect)
  12456. _cacheStyle.cacheRect = Rectangle.create();
  12457. var tRec;
  12458. if (tCacheType === "bitmap") {
  12459. tRec = sprite.getSelfBounds();
  12460. tRec.width = tRec.width + CacheStyle.CANVAS_EXTEND_EDGE * 2;
  12461. tRec.height = tRec.height + CacheStyle.CANVAS_EXTEND_EDGE * 2;
  12462. tRec.x = tRec.x - sprite.pivotX;
  12463. tRec.y = tRec.y - sprite.pivotY;
  12464. tRec.x = tRec.x - CacheStyle.CANVAS_EXTEND_EDGE;
  12465. tRec.y = tRec.y - CacheStyle.CANVAS_EXTEND_EDGE;
  12466. tRec.x = Math.floor(tRec.x + x) - x;
  12467. tRec.y = Math.floor(tRec.y + y) - y;
  12468. tRec.width = Math.floor(tRec.width);
  12469. tRec.height = Math.floor(tRec.height);
  12470. _cacheStyle.cacheRect.copyFrom(tRec);
  12471. }
  12472. else {
  12473. _cacheStyle.cacheRect.setTo(-sprite._style.pivotX, -sprite._style.pivotY, 1, 1);
  12474. }
  12475. tRec = _cacheStyle.cacheRect;
  12476. if (sprite._style.scrollRect) {
  12477. var scrollRect = sprite._style.scrollRect;
  12478. tRec.x -= scrollRect.x;
  12479. tRec.y -= scrollRect.y;
  12480. }
  12481. CacheStyle._scaleInfo.setTo(1, 1);
  12482. return CacheStyle._scaleInfo;
  12483. }
  12484. }
  12485. CacheStyle.EMPTY = new CacheStyle();
  12486. CacheStyle._scaleInfo = new Point();
  12487. CacheStyle.CANVAS_EXTEND_EDGE = 16;
  12488. class SpriteStyle {
  12489. constructor() {
  12490. this.reset();
  12491. }
  12492. reset() {
  12493. this.scaleX = this.scaleY = 1;
  12494. this.skewX = this.skewY = 0;
  12495. this.pivotX = this.pivotY = this.rotation = 0;
  12496. this.alpha = 1;
  12497. if (this.scrollRect)
  12498. this.scrollRect.recover();
  12499. this.scrollRect = null;
  12500. if (this.viewport)
  12501. this.viewport.recover();
  12502. this.viewport = null;
  12503. this.hitArea = null;
  12504. this.dragging = null;
  12505. this.blendMode = null;
  12506. return this;
  12507. }
  12508. recover() {
  12509. if (this === SpriteStyle.EMPTY)
  12510. return;
  12511. Pool.recover("SpriteStyle", this.reset());
  12512. }
  12513. static create() {
  12514. return Pool.getItemByClass("SpriteStyle", SpriteStyle);
  12515. }
  12516. }
  12517. SpriteStyle.EMPTY = new SpriteStyle();
  12518. class Node extends EventDispatcher {
  12519. constructor() {
  12520. super();
  12521. this._bits = 0;
  12522. this._children = Node.ARRAY_EMPTY;
  12523. this._extUIChild = Node.ARRAY_EMPTY;
  12524. this._parent = null;
  12525. this.name = "";
  12526. this.destroyed = false;
  12527. this.createGLBuffer();
  12528. }
  12529. createGLBuffer() {
  12530. }
  12531. _setBit(type, value) {
  12532. if (type === Const.DISPLAY) {
  12533. var preValue = this._getBit(type);
  12534. if (preValue != value)
  12535. this._updateDisplayedInstage();
  12536. }
  12537. if (value)
  12538. this._bits |= type;
  12539. else
  12540. this._bits &= ~type;
  12541. }
  12542. _getBit(type) {
  12543. return (this._bits & type) != 0;
  12544. }
  12545. _setUpNoticeChain() {
  12546. if (this._getBit(Const.DISPLAY))
  12547. this._setBitUp(Const.DISPLAY);
  12548. }
  12549. _setBitUp(type) {
  12550. var ele = this;
  12551. ele._setBit(type, true);
  12552. ele = ele._parent;
  12553. while (ele) {
  12554. if (ele._getBit(type))
  12555. return;
  12556. ele._setBit(type, true);
  12557. ele = ele._parent;
  12558. }
  12559. }
  12560. on(type, caller, listener, args = null) {
  12561. if (type === Event.DISPLAY || type === Event.UNDISPLAY) {
  12562. if (!this._getBit(Const.DISPLAY))
  12563. this._setBitUp(Const.DISPLAY);
  12564. }
  12565. return this._createListener(type, caller, listener, args, false);
  12566. }
  12567. once(type, caller, listener, args = null) {
  12568. if (type === Event.DISPLAY || type === Event.UNDISPLAY) {
  12569. if (!this._getBit(Const.DISPLAY))
  12570. this._setBitUp(Const.DISPLAY);
  12571. }
  12572. return this._createListener(type, caller, listener, args, true);
  12573. }
  12574. destroy(destroyChild = true) {
  12575. this.destroyed = true;
  12576. this._destroyAllComponent();
  12577. this._parent && this._parent.removeChild(this);
  12578. if (this._children) {
  12579. if (destroyChild)
  12580. this.destroyChildren();
  12581. else
  12582. this.removeChildren();
  12583. }
  12584. this.onDestroy();
  12585. this._children = null;
  12586. this.offAll();
  12587. }
  12588. onDestroy() {
  12589. }
  12590. destroyChildren() {
  12591. if (this._children) {
  12592. for (var i = 0, n = this._children.length; i < n; i++) {
  12593. this._children[0].destroy(true);
  12594. }
  12595. }
  12596. }
  12597. addChild(node) {
  12598. if (!node || this.destroyed || node === this)
  12599. return node;
  12600. if (node._zOrder)
  12601. this._setBit(Const.HAS_ZORDER, true);
  12602. if (node._parent === this) {
  12603. var index = this.getChildIndex(node);
  12604. if (index !== this._children.length - 1) {
  12605. this._children.splice(index, 1);
  12606. this._children.push(node);
  12607. this._childChanged();
  12608. }
  12609. }
  12610. else {
  12611. node._parent && node._parent.removeChild(node);
  12612. this._children === Node.ARRAY_EMPTY && (this._children = []);
  12613. this._children.push(node);
  12614. node._setParent(this);
  12615. this._childChanged();
  12616. }
  12617. return node;
  12618. }
  12619. addInputChild(node) {
  12620. if (this._extUIChild == Node.ARRAY_EMPTY) {
  12621. this._extUIChild = [node];
  12622. }
  12623. else {
  12624. if (this._extUIChild.indexOf(node) >= 0) {
  12625. return null;
  12626. }
  12627. this._extUIChild.push(node);
  12628. }
  12629. return null;
  12630. }
  12631. removeInputChild(node) {
  12632. var idx = this._extUIChild.indexOf(node);
  12633. if (idx >= 0) {
  12634. this._extUIChild.splice(idx, 1);
  12635. }
  12636. }
  12637. addChildren(...args) {
  12638. var i = 0, n = args.length;
  12639. while (i < n) {
  12640. this.addChild(args[i++]);
  12641. }
  12642. }
  12643. addChildAt(node, index) {
  12644. if (!node || this.destroyed || node === this)
  12645. return node;
  12646. if (node._zOrder)
  12647. this._setBit(Const.HAS_ZORDER, true);
  12648. if (index >= 0 && index <= this._children.length) {
  12649. if (node._parent === this) {
  12650. var oldIndex = this.getChildIndex(node);
  12651. this._children.splice(oldIndex, 1);
  12652. this._children.splice(index, 0, node);
  12653. this._childChanged();
  12654. }
  12655. else {
  12656. node._parent && node._parent.removeChild(node);
  12657. this._children === Node.ARRAY_EMPTY && (this._children = []);
  12658. this._children.splice(index, 0, node);
  12659. node._setParent(this);
  12660. }
  12661. return node;
  12662. }
  12663. else {
  12664. throw new Error("appendChildAt:The index is out of bounds");
  12665. }
  12666. }
  12667. getChildIndex(node) {
  12668. return this._children.indexOf(node);
  12669. }
  12670. getChildByName(name) {
  12671. var nodes = this._children;
  12672. if (nodes) {
  12673. for (var i = 0, n = nodes.length; i < n; i++) {
  12674. var node = nodes[i];
  12675. if (node.name === name)
  12676. return node;
  12677. }
  12678. }
  12679. return null;
  12680. }
  12681. getChildAt(index) {
  12682. return this._children[index] || null;
  12683. }
  12684. setChildIndex(node, index) {
  12685. var childs = this._children;
  12686. if (index < 0 || index >= childs.length) {
  12687. throw new Error("setChildIndex:The index is out of bounds.");
  12688. }
  12689. var oldIndex = this.getChildIndex(node);
  12690. if (oldIndex < 0)
  12691. throw new Error("setChildIndex:node is must child of this object.");
  12692. childs.splice(oldIndex, 1);
  12693. childs.splice(index, 0, node);
  12694. this._childChanged();
  12695. return node;
  12696. }
  12697. _childChanged(child = null) {
  12698. }
  12699. removeChild(node) {
  12700. if (!this._children)
  12701. return node;
  12702. var index = this._children.indexOf(node);
  12703. return this.removeChildAt(index);
  12704. }
  12705. removeSelf() {
  12706. this._parent && this._parent.removeChild(this);
  12707. return this;
  12708. }
  12709. removeChildByName(name) {
  12710. var node = this.getChildByName(name);
  12711. node && this.removeChild(node);
  12712. return node;
  12713. }
  12714. removeChildAt(index) {
  12715. var node = this.getChildAt(index);
  12716. if (node) {
  12717. this._children.splice(index, 1);
  12718. node._setParent(null);
  12719. }
  12720. return node;
  12721. }
  12722. removeChildren(beginIndex = 0, endIndex = 0x7fffffff) {
  12723. if (this._children && this._children.length > 0) {
  12724. var childs = this._children;
  12725. if (beginIndex === 0 && endIndex >= childs.length - 1) {
  12726. var arr = childs;
  12727. this._children = Node.ARRAY_EMPTY;
  12728. }
  12729. else {
  12730. arr = childs.splice(beginIndex, endIndex - beginIndex);
  12731. }
  12732. for (var i = 0, n = arr.length; i < n; i++) {
  12733. arr[i]._setParent(null);
  12734. }
  12735. }
  12736. return this;
  12737. }
  12738. replaceChild(newNode, oldNode) {
  12739. var index = this._children.indexOf(oldNode);
  12740. if (index > -1) {
  12741. this._children.splice(index, 1, newNode);
  12742. oldNode._setParent(null);
  12743. newNode._setParent(this);
  12744. return newNode;
  12745. }
  12746. return null;
  12747. }
  12748. get numChildren() {
  12749. return this._children.length;
  12750. }
  12751. get parent() {
  12752. return this._parent;
  12753. }
  12754. _setParent(value) {
  12755. if (this._parent !== value) {
  12756. if (value) {
  12757. this._parent = value;
  12758. this._onAdded();
  12759. this.event(Event.ADDED);
  12760. if (this._getBit(Const.DISPLAY)) {
  12761. this._setUpNoticeChain();
  12762. value.displayedInStage && this._displayChild(this, true);
  12763. }
  12764. value._childChanged(this);
  12765. }
  12766. else {
  12767. this._onRemoved();
  12768. this.event(Event.REMOVED);
  12769. this._parent._childChanged();
  12770. if (this._getBit(Const.DISPLAY))
  12771. this._displayChild(this, false);
  12772. this._parent = value;
  12773. }
  12774. }
  12775. }
  12776. get displayedInStage() {
  12777. if (this._getBit(Const.DISPLAY))
  12778. return this._getBit(Const.DISPLAYED_INSTAGE);
  12779. this._setBitUp(Const.DISPLAY);
  12780. return this._getBit(Const.DISPLAYED_INSTAGE);
  12781. }
  12782. _updateDisplayedInstage() {
  12783. var ele;
  12784. ele = this;
  12785. var stage = ILaya.stage;
  12786. var displayedInStage = false;
  12787. while (ele) {
  12788. if (ele._getBit(Const.DISPLAY)) {
  12789. displayedInStage = ele._getBit(Const.DISPLAYED_INSTAGE);
  12790. break;
  12791. }
  12792. if (ele === stage || ele._getBit(Const.DISPLAYED_INSTAGE)) {
  12793. displayedInStage = true;
  12794. break;
  12795. }
  12796. ele = ele._parent;
  12797. }
  12798. this._setBit(Const.DISPLAYED_INSTAGE, displayedInStage);
  12799. }
  12800. _setDisplay(value) {
  12801. if (this._getBit(Const.DISPLAYED_INSTAGE) !== value) {
  12802. this._setBit(Const.DISPLAYED_INSTAGE, value);
  12803. if (value)
  12804. this.event(Event.DISPLAY);
  12805. else
  12806. this.event(Event.UNDISPLAY);
  12807. }
  12808. }
  12809. _displayChild(node, display) {
  12810. var childs = node._children;
  12811. if (childs) {
  12812. for (var i = 0, n = childs.length; i < n; i++) {
  12813. var child = childs[i];
  12814. if (!child._getBit(Const.DISPLAY))
  12815. continue;
  12816. if (child._children.length > 0) {
  12817. this._displayChild(child, display);
  12818. }
  12819. else {
  12820. child._setDisplay(display);
  12821. }
  12822. }
  12823. }
  12824. node._setDisplay(display);
  12825. }
  12826. contains(node) {
  12827. if (node === this)
  12828. return true;
  12829. while (node) {
  12830. if (node._parent === this)
  12831. return true;
  12832. node = node._parent;
  12833. }
  12834. return false;
  12835. }
  12836. timerLoop(delay, caller, method, args = null, coverBefore = true, jumpFrame = false) {
  12837. var timer = this.scene ? this.scene.timer : ILaya.timer;
  12838. timer.loop(delay, caller, method, args, coverBefore, jumpFrame);
  12839. }
  12840. timerOnce(delay, caller, method, args = null, coverBefore = true) {
  12841. var timer = this.scene ? this.scene.timer : ILaya.timer;
  12842. timer._create(false, false, delay, caller, method, args, coverBefore);
  12843. }
  12844. frameLoop(delay, caller, method, args = null, coverBefore = true) {
  12845. var timer = this.scene ? this.scene.timer : ILaya.timer;
  12846. timer._create(true, true, delay, caller, method, args, coverBefore);
  12847. }
  12848. frameOnce(delay, caller, method, args = null, coverBefore = true) {
  12849. var timer = this.scene ? this.scene.timer : ILaya.timer;
  12850. timer._create(true, false, delay, caller, method, args, coverBefore);
  12851. }
  12852. clearTimer(caller, method) {
  12853. var timer = this.scene ? this.scene.timer : ILaya.timer;
  12854. timer.clear(caller, method);
  12855. }
  12856. callLater(method, args = null) {
  12857. var timer = this.scene ? this.scene.timer : ILaya.timer;
  12858. timer.callLater(this, method, args);
  12859. }
  12860. runCallLater(method) {
  12861. var timer = this.scene ? this.scene.timer : ILaya.timer;
  12862. timer.runCallLater(this, method);
  12863. }
  12864. get scene() {
  12865. return this._scene;
  12866. }
  12867. get active() {
  12868. return !this._getBit(Const.NOT_READY) && !this._getBit(Const.NOT_ACTIVE);
  12869. }
  12870. set active(value) {
  12871. value = !!value;
  12872. if (!this._getBit(Const.NOT_ACTIVE) !== value) {
  12873. if (this._activeChangeScripts && this._activeChangeScripts.length !== 0) {
  12874. if (value)
  12875. throw "Node: can't set the main inActive node active in hierarchy,if the operate is in main inActive node or it's children script's onDisable Event.";
  12876. else
  12877. throw "Node: can't set the main active node inActive in hierarchy,if the operate is in main active node or it's children script's onEnable Event.";
  12878. }
  12879. else {
  12880. this._setBit(Const.NOT_ACTIVE, !value);
  12881. if (this._parent) {
  12882. if (this._parent.activeInHierarchy) {
  12883. if (value)
  12884. this._processActive();
  12885. else
  12886. this._processInActive();
  12887. }
  12888. }
  12889. }
  12890. }
  12891. }
  12892. get activeInHierarchy() {
  12893. return this._getBit(Const.ACTIVE_INHIERARCHY);
  12894. }
  12895. _onActive() {
  12896. Stat.spriteCount++;
  12897. }
  12898. _onInActive() {
  12899. Stat.spriteCount--;
  12900. }
  12901. _onActiveInScene() {
  12902. }
  12903. _onInActiveInScene() {
  12904. }
  12905. _parse(data, spriteMap) {
  12906. }
  12907. _setBelongScene(scene) {
  12908. if (!this._scene) {
  12909. this._scene = scene;
  12910. this._onActiveInScene();
  12911. for (var i = 0, n = this._children.length; i < n; i++)
  12912. this._children[i]._setBelongScene(scene);
  12913. }
  12914. }
  12915. _setUnBelongScene() {
  12916. if (this._scene !== this) {
  12917. this._onInActiveInScene();
  12918. this._scene = null;
  12919. for (var i = 0, n = this._children.length; i < n; i++)
  12920. this._children[i]._setUnBelongScene();
  12921. }
  12922. }
  12923. onAwake() {
  12924. }
  12925. onEnable() {
  12926. }
  12927. _processActive() {
  12928. (this._activeChangeScripts) || (this._activeChangeScripts = []);
  12929. this._activeHierarchy(this._activeChangeScripts);
  12930. this._activeScripts();
  12931. }
  12932. _activeHierarchy(activeChangeScripts) {
  12933. this._setBit(Const.ACTIVE_INHIERARCHY, true);
  12934. if (this._components) {
  12935. for (var i = 0, n = this._components.length; i < n; i++) {
  12936. var comp = this._components[i];
  12937. comp._setActive(true);
  12938. (comp._isScript() && comp._enabled) && (activeChangeScripts.push(comp));
  12939. }
  12940. }
  12941. this._onActive();
  12942. for (i = 0, n = this._children.length; i < n; i++) {
  12943. var child = this._children[i];
  12944. (!child._getBit(Const.NOT_ACTIVE)) && (child._activeHierarchy(activeChangeScripts));
  12945. }
  12946. if (!this._getBit(Const.AWAKED)) {
  12947. this._setBit(Const.AWAKED, true);
  12948. this.onAwake();
  12949. }
  12950. this.onEnable();
  12951. }
  12952. _activeScripts() {
  12953. for (var i = 0, n = this._activeChangeScripts.length; i < n; i++)
  12954. this._activeChangeScripts[i].onEnable();
  12955. this._activeChangeScripts.length = 0;
  12956. }
  12957. _processInActive() {
  12958. (this._activeChangeScripts) || (this._activeChangeScripts = []);
  12959. this._inActiveHierarchy(this._activeChangeScripts);
  12960. this._inActiveScripts();
  12961. }
  12962. _inActiveHierarchy(activeChangeScripts) {
  12963. this._onInActive();
  12964. if (this._components) {
  12965. for (var i = 0, n = this._components.length; i < n; i++) {
  12966. var comp = this._components[i];
  12967. comp._setActive(false);
  12968. (comp._isScript() && comp._enabled) && (activeChangeScripts.push(comp));
  12969. }
  12970. }
  12971. this._setBit(Const.ACTIVE_INHIERARCHY, false);
  12972. for (i = 0, n = this._children.length; i < n; i++) {
  12973. var child = this._children[i];
  12974. (child && !child._getBit(Const.NOT_ACTIVE)) && (child._inActiveHierarchy(activeChangeScripts));
  12975. }
  12976. this.onDisable();
  12977. }
  12978. _inActiveScripts() {
  12979. for (var i = 0, n = this._activeChangeScripts.length; i < n; i++)
  12980. this._activeChangeScripts[i].onDisable();
  12981. this._activeChangeScripts.length = 0;
  12982. }
  12983. onDisable() {
  12984. }
  12985. _onAdded() {
  12986. if (this._activeChangeScripts && this._activeChangeScripts.length !== 0) {
  12987. throw "Node: can't set the main inActive node active in hierarchy,if the operate is in main inActive node or it's children script's onDisable Event.";
  12988. }
  12989. else {
  12990. var parentScene = this._parent.scene;
  12991. parentScene && this._setBelongScene(parentScene);
  12992. (this._parent.activeInHierarchy && this.active) && this._processActive();
  12993. }
  12994. }
  12995. _onRemoved() {
  12996. if (this._activeChangeScripts && this._activeChangeScripts.length !== 0) {
  12997. throw "Node: can't set the main active node inActive in hierarchy,if the operate is in main active node or it's children script's onEnable Event.";
  12998. }
  12999. else {
  13000. (this._parent.activeInHierarchy && this.active) && this._processInActive();
  13001. this._parent.scene && this._setUnBelongScene();
  13002. }
  13003. }
  13004. _addComponentInstance(comp) {
  13005. this._components = this._components || [];
  13006. this._components.push(comp);
  13007. comp.owner = this;
  13008. comp._onAdded();
  13009. if (this.activeInHierarchy) {
  13010. comp._setActive(true);
  13011. (comp._isScript() && comp._enabled) && (comp.onEnable());
  13012. }
  13013. }
  13014. _destroyComponent(comp) {
  13015. if (this._components) {
  13016. for (var i = 0, n = this._components.length; i < n; i++) {
  13017. var item = this._components[i];
  13018. if (item === comp) {
  13019. item._destroy();
  13020. this._components.splice(i, 1);
  13021. break;
  13022. }
  13023. }
  13024. }
  13025. }
  13026. _destroyAllComponent() {
  13027. if (this._components) {
  13028. for (var i = 0, n = this._components.length; i < n; i++) {
  13029. var item = this._components[i];
  13030. item._destroy();
  13031. }
  13032. this._components.length = 0;
  13033. }
  13034. }
  13035. _cloneTo(destObject, srcRoot, dstRoot) {
  13036. var destNode = destObject;
  13037. if (this._components) {
  13038. for (var i = 0, n = this._components.length; i < n; i++) {
  13039. var destComponent = destNode.addComponent(this._components[i].constructor);
  13040. this._components[i]._cloneTo(destComponent);
  13041. }
  13042. }
  13043. }
  13044. addComponentIntance(comp) {
  13045. if (comp.owner)
  13046. throw "Node:the component has belong to other node.";
  13047. if (comp.isSingleton && this.getComponent(comp.constructor))
  13048. throw "Node:the component is singleton,can't add the second one.";
  13049. this._addComponentInstance(comp);
  13050. return comp;
  13051. }
  13052. addComponent(type) {
  13053. var comp = Pool.createByClass(type);
  13054. comp._destroyed = false;
  13055. if (comp.isSingleton && this.getComponent(type))
  13056. throw "无法实例" + type + "组件" + "," + type + "组件已存在!";
  13057. this._addComponentInstance(comp);
  13058. return comp;
  13059. }
  13060. getComponent(clas) {
  13061. if (this._components) {
  13062. for (var i = 0, n = this._components.length; i < n; i++) {
  13063. var comp = this._components[i];
  13064. if (comp instanceof clas)
  13065. return comp;
  13066. }
  13067. }
  13068. return null;
  13069. }
  13070. getComponents(clas) {
  13071. var arr;
  13072. if (this._components) {
  13073. for (var i = 0, n = this._components.length; i < n; i++) {
  13074. var comp = this._components[i];
  13075. if (comp instanceof clas) {
  13076. arr = arr || [];
  13077. arr.push(comp);
  13078. }
  13079. }
  13080. }
  13081. return arr;
  13082. }
  13083. get timer() {
  13084. return this.scene ? this.scene.timer : ILaya.timer;
  13085. }
  13086. }
  13087. Node.ARRAY_EMPTY = [];
  13088. ClassUtils.regClass("laya.display.Node", Node);
  13089. ClassUtils.regClass("Laya.Node", Node);
  13090. class Sprite extends Node {
  13091. constructor() {
  13092. super();
  13093. this._x = 0;
  13094. this._y = 0;
  13095. this._width = 0;
  13096. this._height = 0;
  13097. this._visible = true;
  13098. this._mouseState = 0;
  13099. this._zOrder = 0;
  13100. this._renderType = 0;
  13101. this._transform = null;
  13102. this._tfChanged = false;
  13103. this._repaint = SpriteConst.REPAINT_NONE;
  13104. this._texture = null;
  13105. this._style = SpriteStyle.EMPTY;
  13106. this._cacheStyle = CacheStyle.EMPTY;
  13107. this._boundStyle = null;
  13108. this._graphics = null;
  13109. this.mouseThrough = false;
  13110. this.autoSize = false;
  13111. this.hitTestPrior = false;
  13112. }
  13113. destroy(destroyChild = true) {
  13114. super.destroy(destroyChild);
  13115. this._style && this._style.recover();
  13116. this._cacheStyle && this._cacheStyle.recover();
  13117. this._boundStyle && this._boundStyle.recover();
  13118. this._style = null;
  13119. this._cacheStyle = null;
  13120. this._boundStyle = null;
  13121. this._transform = null;
  13122. if (this._graphics && this._graphics.autoDestroy) {
  13123. this._graphics.destroy();
  13124. }
  13125. this._graphics = null;
  13126. this.texture = null;
  13127. }
  13128. updateZOrder() {
  13129. Utils.updateOrder(this._children) && this.repaint();
  13130. }
  13131. _getBoundsStyle() {
  13132. if (!this._boundStyle)
  13133. this._boundStyle = BoundsStyle.create();
  13134. return this._boundStyle;
  13135. }
  13136. _setCustomRender() {
  13137. }
  13138. set customRenderEnable(b) {
  13139. if (b) {
  13140. this._renderType |= SpriteConst.CUSTOM;
  13141. this._setRenderType(this._renderType);
  13142. this._setCustomRender();
  13143. }
  13144. }
  13145. get cacheAs() {
  13146. return this._cacheStyle.cacheAs;
  13147. }
  13148. _setCacheAs(value) {
  13149. }
  13150. set cacheAs(value) {
  13151. if (value === this._cacheStyle.userSetCache)
  13152. return;
  13153. if (this.mask && value === 'normal')
  13154. return;
  13155. this._setCacheAs(value);
  13156. this._getCacheStyle().userSetCache = value;
  13157. this._checkCanvasEnable();
  13158. this.repaint();
  13159. }
  13160. _checkCanvasEnable() {
  13161. var tEnable = this._cacheStyle.needEnableCanvasRender();
  13162. this._getCacheStyle().enableCanvasRender = tEnable;
  13163. if (tEnable) {
  13164. if (this._cacheStyle.needBitmapCache()) {
  13165. this._cacheStyle.cacheAs = "bitmap";
  13166. }
  13167. else {
  13168. this._cacheStyle.cacheAs = this._cacheStyle.userSetCache;
  13169. }
  13170. this._cacheStyle.reCache = true;
  13171. this._renderType |= SpriteConst.CANVAS;
  13172. }
  13173. else {
  13174. this._cacheStyle.cacheAs = "none";
  13175. this._cacheStyle.releaseContext();
  13176. this._renderType &= ~SpriteConst.CANVAS;
  13177. }
  13178. this._setCacheAs(this._cacheStyle.cacheAs);
  13179. this._setRenderType(this._renderType);
  13180. }
  13181. get staticCache() {
  13182. return this._cacheStyle.staticCache;
  13183. }
  13184. set staticCache(value) {
  13185. this._getCacheStyle().staticCache = value;
  13186. if (!value)
  13187. this.reCache();
  13188. }
  13189. reCache() {
  13190. this._cacheStyle.reCache = true;
  13191. this._repaint |= SpriteConst.REPAINT_CACHE;
  13192. }
  13193. getRepaint() {
  13194. return this._repaint;
  13195. }
  13196. _setX(value) {
  13197. this._x = value;
  13198. }
  13199. _setY(value) {
  13200. this._y = value;
  13201. }
  13202. _setWidth(texture, value) {
  13203. }
  13204. _setHeight(texture, value) {
  13205. }
  13206. get x() {
  13207. return this._x;
  13208. }
  13209. set x(value) {
  13210. if (this.destroyed)
  13211. return;
  13212. if (this._x !== value) {
  13213. this._setX(value);
  13214. this.parentRepaint(SpriteConst.REPAINT_CACHE);
  13215. var p = this._cacheStyle.maskParent;
  13216. if (p) {
  13217. p.repaint(SpriteConst.REPAINT_CACHE);
  13218. }
  13219. }
  13220. }
  13221. get y() {
  13222. return this._y;
  13223. }
  13224. set y(value) {
  13225. if (this.destroyed)
  13226. return;
  13227. if (this._y !== value) {
  13228. this._setY(value);
  13229. this.parentRepaint(SpriteConst.REPAINT_CACHE);
  13230. var p = this._cacheStyle.maskParent;
  13231. if (p) {
  13232. p.repaint(SpriteConst.REPAINT_CACHE);
  13233. }
  13234. }
  13235. }
  13236. get width() {
  13237. return this.get_width();
  13238. }
  13239. set width(value) {
  13240. this.set_width(value);
  13241. }
  13242. set_width(value) {
  13243. if (this._width !== value) {
  13244. this._width = value;
  13245. this._setWidth(this.texture, value);
  13246. this._setTranformChange();
  13247. }
  13248. }
  13249. get_width() {
  13250. if (!this.autoSize)
  13251. return this._width || (this.texture ? this.texture.width : 0);
  13252. if (this.texture)
  13253. return this.texture.width;
  13254. if (!this._graphics && this._children.length === 0)
  13255. return 0;
  13256. return this.getSelfBounds().width;
  13257. }
  13258. get height() {
  13259. return this.get_height();
  13260. }
  13261. set height(value) {
  13262. this.set_height(value);
  13263. }
  13264. set_height(value) {
  13265. if (this._height !== value) {
  13266. this._height = value;
  13267. this._setHeight(this.texture, value);
  13268. this._setTranformChange();
  13269. }
  13270. }
  13271. get_height() {
  13272. if (!this.autoSize)
  13273. return this._height || (this.texture ? this.texture.height : 0);
  13274. if (this.texture)
  13275. return this.texture.height;
  13276. if (!this._graphics && this._children.length === 0)
  13277. return 0;
  13278. return this.getSelfBounds().height;
  13279. }
  13280. get displayWidth() {
  13281. return this.width * this.scaleX;
  13282. }
  13283. get displayHeight() {
  13284. return this.height * this.scaleY;
  13285. }
  13286. setSelfBounds(bound) {
  13287. this._getBoundsStyle().userBounds = bound;
  13288. }
  13289. getBounds() {
  13290. return this._getBoundsStyle().bounds = Rectangle._getWrapRec(this._boundPointsToParent());
  13291. }
  13292. getSelfBounds() {
  13293. if (this._boundStyle && this._boundStyle.userBounds)
  13294. return this._boundStyle.userBounds;
  13295. if (!this._graphics && this._children.length === 0 && !this._texture)
  13296. return Rectangle.TEMP.setTo(0, 0, this.width, this.height);
  13297. return this._getBoundsStyle().bounds = Rectangle._getWrapRec(this._getBoundPointsM(false));
  13298. }
  13299. _boundPointsToParent(ifRotate = false) {
  13300. var pX = 0, pY = 0;
  13301. if (this._style) {
  13302. pX = this.pivotX;
  13303. pY = this.pivotY;
  13304. ifRotate = ifRotate || (this._style.rotation !== 0);
  13305. if (this._style.scrollRect) {
  13306. pX += this._style.scrollRect.x;
  13307. pY += this._style.scrollRect.y;
  13308. }
  13309. }
  13310. var pList = this._getBoundPointsM(ifRotate);
  13311. if (!pList || pList.length < 1)
  13312. return pList;
  13313. if (pList.length != 8) {
  13314. pList = ifRotate ? GrahamScan.scanPList(pList) : Rectangle._getWrapRec(pList, Rectangle.TEMP)._getBoundPoints();
  13315. }
  13316. if (!this.transform) {
  13317. Utils.transPointList(pList, this._x - pX, this._y - pY);
  13318. return pList;
  13319. }
  13320. var tPoint = Point.TEMP;
  13321. var i, len = pList.length;
  13322. for (i = 0; i < len; i += 2) {
  13323. tPoint.x = pList[i];
  13324. tPoint.y = pList[i + 1];
  13325. this.toParentPoint(tPoint);
  13326. pList[i] = tPoint.x;
  13327. pList[i + 1] = tPoint.y;
  13328. }
  13329. return pList;
  13330. }
  13331. getGraphicBounds(realSize = false) {
  13332. if (!this._graphics)
  13333. return Rectangle.TEMP.setTo(0, 0, 0, 0);
  13334. return this._graphics.getBounds(realSize);
  13335. }
  13336. _getBoundPointsM(ifRotate = false) {
  13337. if (this._boundStyle && this._boundStyle.userBounds)
  13338. return this._boundStyle.userBounds._getBoundPoints();
  13339. if (!this._boundStyle)
  13340. this._getBoundsStyle();
  13341. if (!this._boundStyle.temBM)
  13342. this._boundStyle.temBM = [];
  13343. if (this._style.scrollRect) {
  13344. var rst = Utils.clearArray(this._boundStyle.temBM);
  13345. var rec = Rectangle.TEMP;
  13346. rec.copyFrom(this._style.scrollRect);
  13347. Utils.concatArray(rst, rec._getBoundPoints());
  13348. return rst;
  13349. }
  13350. var pList;
  13351. if (this._graphics) {
  13352. pList = this._graphics.getBoundPoints();
  13353. }
  13354. else {
  13355. pList = Utils.clearArray(this._boundStyle.temBM);
  13356. if (this._texture) {
  13357. rec = Rectangle.TEMP;
  13358. rec.setTo(0, 0, this.width || this._texture.width, this.height || this._texture.height);
  13359. Utils.concatArray(pList, rec._getBoundPoints());
  13360. }
  13361. }
  13362. var child;
  13363. var cList;
  13364. var __childs;
  13365. __childs = this._children;
  13366. for (var i = 0, n = __childs.length; i < n; i++) {
  13367. child = __childs[i];
  13368. if (child instanceof Sprite && child._visible === true) {
  13369. cList = child._boundPointsToParent(ifRotate);
  13370. if (cList)
  13371. pList = pList ? Utils.concatArray(pList, cList) : cList;
  13372. }
  13373. }
  13374. return pList;
  13375. }
  13376. _getCacheStyle() {
  13377. this._cacheStyle === CacheStyle.EMPTY && (this._cacheStyle = CacheStyle.create());
  13378. return this._cacheStyle;
  13379. }
  13380. getStyle() {
  13381. this._style === SpriteStyle.EMPTY && (this._style = SpriteStyle.create());
  13382. return this._style;
  13383. }
  13384. setStyle(value) {
  13385. this._style = value;
  13386. }
  13387. get scaleX() {
  13388. return this._style.scaleX;
  13389. }
  13390. set scaleX(value) {
  13391. this.set_scaleX(value);
  13392. }
  13393. _setScaleX(value) {
  13394. this._style.scaleX = value;
  13395. }
  13396. get scaleY() {
  13397. return this._style.scaleY;
  13398. }
  13399. set scaleY(value) {
  13400. this.set_scaleY(value);
  13401. }
  13402. _setScaleY(value) {
  13403. this._style.scaleY = value;
  13404. }
  13405. set_scaleX(value) {
  13406. var style = this.getStyle();
  13407. if (style.scaleX !== value) {
  13408. this._setScaleX(value);
  13409. this._setTranformChange();
  13410. }
  13411. }
  13412. get_scaleX() {
  13413. return this._style.scaleX;
  13414. }
  13415. set_scaleY(value) {
  13416. var style = this.getStyle();
  13417. if (style.scaleY !== value) {
  13418. this._setScaleY(value);
  13419. this._setTranformChange();
  13420. }
  13421. }
  13422. get_scaleY() {
  13423. return this._style.scaleY;
  13424. }
  13425. get rotation() {
  13426. return this._style.rotation;
  13427. }
  13428. set rotation(value) {
  13429. var style = this.getStyle();
  13430. if (style.rotation !== value) {
  13431. this._setRotation(value);
  13432. this._setTranformChange();
  13433. }
  13434. }
  13435. _setRotation(value) {
  13436. this._style.rotation = value;
  13437. }
  13438. get skewX() {
  13439. return this._style.skewX;
  13440. }
  13441. set skewX(value) {
  13442. var style = this.getStyle();
  13443. if (style.skewX !== value) {
  13444. this._setSkewX(value);
  13445. this._setTranformChange();
  13446. }
  13447. }
  13448. _setSkewX(value) {
  13449. this._style.skewX = value;
  13450. }
  13451. get skewY() {
  13452. return this._style.skewY;
  13453. }
  13454. set skewY(value) {
  13455. var style = this.getStyle();
  13456. if (style.skewY !== value) {
  13457. this._setSkewY(value);
  13458. this._setTranformChange();
  13459. }
  13460. }
  13461. _setSkewY(value) {
  13462. this._style.skewY = value;
  13463. }
  13464. _createTransform() {
  13465. return Matrix.create();
  13466. }
  13467. _adjustTransform() {
  13468. this._tfChanged = false;
  13469. var style = this._style;
  13470. var sx = style.scaleX, sy = style.scaleY;
  13471. var sskx = style.skewX;
  13472. var ssky = style.skewY;
  13473. var rot = style.rotation;
  13474. var m = this._transform || (this._transform = this._createTransform());
  13475. if (rot || sx !== 1 || sy !== 1 || sskx !== 0 || ssky !== 0) {
  13476. m._bTransform = true;
  13477. var skx = (rot - sskx) * 0.0174532922222222;
  13478. var sky = (rot + ssky) * 0.0174532922222222;
  13479. var cx = Math.cos(sky);
  13480. var ssx = Math.sin(sky);
  13481. var cy = Math.sin(skx);
  13482. var ssy = Math.cos(skx);
  13483. m.a = sx * cx;
  13484. m.b = sx * ssx;
  13485. m.c = -sy * cy;
  13486. m.d = sy * ssy;
  13487. m.tx = m.ty = 0;
  13488. }
  13489. else {
  13490. m.identity();
  13491. this._renderType &= ~SpriteConst.TRANSFORM;
  13492. this._setRenderType(this._renderType);
  13493. }
  13494. return m;
  13495. }
  13496. _setTransform(value) {
  13497. }
  13498. get transform() {
  13499. return this._tfChanged ? this._adjustTransform() : this._transform;
  13500. }
  13501. set transform(value) {
  13502. this.set_transform(value);
  13503. }
  13504. get_transform() {
  13505. return this._tfChanged ? this._adjustTransform() : this._transform;
  13506. }
  13507. set_transform(value) {
  13508. this._tfChanged = false;
  13509. var m = this._transform || (this._transform = this._createTransform());
  13510. value.copyTo(m);
  13511. this._setTransform(m);
  13512. if (value) {
  13513. this._x = m.tx;
  13514. this._y = m.ty;
  13515. m.tx = m.ty = 0;
  13516. }
  13517. if (value)
  13518. this._renderType |= SpriteConst.TRANSFORM;
  13519. else {
  13520. this._renderType &= ~SpriteConst.TRANSFORM;
  13521. }
  13522. this._setRenderType(this._renderType);
  13523. this.parentRepaint();
  13524. }
  13525. _setPivotX(value) {
  13526. var style = this.getStyle();
  13527. style.pivotX = value;
  13528. }
  13529. _getPivotX() {
  13530. return this._style.pivotX;
  13531. }
  13532. _setPivotY(value) {
  13533. var style = this.getStyle();
  13534. style.pivotY = value;
  13535. }
  13536. _getPivotY() {
  13537. return this._style.pivotY;
  13538. }
  13539. get pivotX() {
  13540. return this._getPivotX();
  13541. }
  13542. set pivotX(value) {
  13543. this._setPivotX(value);
  13544. this.repaint();
  13545. }
  13546. get pivotY() {
  13547. return this._getPivotY();
  13548. }
  13549. set pivotY(value) {
  13550. this._setPivotY(value);
  13551. this.repaint();
  13552. }
  13553. _setAlpha(value) {
  13554. if (this._style.alpha !== value) {
  13555. var style = this.getStyle();
  13556. style.alpha = value;
  13557. if (value !== 1)
  13558. this._renderType |= SpriteConst.ALPHA;
  13559. else
  13560. this._renderType &= ~SpriteConst.ALPHA;
  13561. this._setRenderType(this._renderType);
  13562. this.parentRepaint();
  13563. }
  13564. }
  13565. _getAlpha() {
  13566. return this._style.alpha;
  13567. }
  13568. get alpha() {
  13569. return this._getAlpha();
  13570. }
  13571. set alpha(value) {
  13572. value = value < 0 ? 0 : (value > 1 ? 1 : value);
  13573. this._setAlpha(value);
  13574. }
  13575. get visible() {
  13576. return this.get_visible();
  13577. }
  13578. set visible(value) {
  13579. this.set_visible(value);
  13580. }
  13581. get_visible() {
  13582. return this._visible;
  13583. }
  13584. set_visible(value) {
  13585. if (this._visible !== value) {
  13586. this._visible = value;
  13587. this.parentRepaint(SpriteConst.REPAINT_ALL);
  13588. }
  13589. }
  13590. _setBlendMode(value) {
  13591. }
  13592. get blendMode() {
  13593. return this._style.blendMode;
  13594. }
  13595. set blendMode(value) {
  13596. this._setBlendMode(value);
  13597. this.getStyle().blendMode = value;
  13598. if (value && value != "source-over")
  13599. this._renderType |= SpriteConst.BLEND;
  13600. else
  13601. this._renderType &= ~SpriteConst.BLEND;
  13602. this._setRenderType(this._renderType);
  13603. this.parentRepaint();
  13604. }
  13605. get graphics() {
  13606. if (!this._graphics) {
  13607. this.graphics = new Graphics();
  13608. this._graphics.autoDestroy = true;
  13609. }
  13610. return this._graphics;
  13611. }
  13612. _setGraphics(value) {
  13613. }
  13614. _setGraphicsCallBack() {
  13615. }
  13616. set graphics(value) {
  13617. if (this._graphics)
  13618. this._graphics._sp = null;
  13619. this._graphics = value;
  13620. if (value) {
  13621. this._setGraphics(value);
  13622. this._renderType |= SpriteConst.GRAPHICS;
  13623. value._sp = this;
  13624. }
  13625. else {
  13626. this._renderType &= ~SpriteConst.GRAPHICS;
  13627. }
  13628. this._setRenderType(this._renderType);
  13629. this.repaint();
  13630. }
  13631. get scrollRect() {
  13632. return this._style.scrollRect;
  13633. }
  13634. _setScrollRect(value) {
  13635. }
  13636. set scrollRect(value) {
  13637. this.getStyle().scrollRect = value;
  13638. this._setScrollRect(value);
  13639. this.repaint();
  13640. if (value) {
  13641. this._renderType |= SpriteConst.CLIP;
  13642. }
  13643. else {
  13644. this._renderType &= ~SpriteConst.CLIP;
  13645. }
  13646. this._setRenderType(this._renderType);
  13647. }
  13648. pos(x, y, speedMode = false) {
  13649. if (this._x !== x || this._y !== y) {
  13650. if (this.destroyed)
  13651. return this;
  13652. if (speedMode) {
  13653. this._setX(x);
  13654. this._setY(y);
  13655. this.parentRepaint(SpriteConst.REPAINT_CACHE);
  13656. var p = this._cacheStyle.maskParent;
  13657. if (p) {
  13658. p.repaint(SpriteConst.REPAINT_CACHE);
  13659. }
  13660. }
  13661. else {
  13662. this.x = x;
  13663. this.y = y;
  13664. }
  13665. }
  13666. return this;
  13667. }
  13668. pivot(x, y) {
  13669. this.pivotX = x;
  13670. this.pivotY = y;
  13671. return this;
  13672. }
  13673. size(width, height) {
  13674. this.width = width;
  13675. this.height = height;
  13676. return this;
  13677. }
  13678. scale(scaleX, scaleY, speedMode = false) {
  13679. var style = this.getStyle();
  13680. if (style.scaleX != scaleX || style.scaleY != scaleY) {
  13681. if (this.destroyed)
  13682. return this;
  13683. if (speedMode) {
  13684. this._setScaleX(scaleX);
  13685. this._setScaleY(scaleY);
  13686. this._setTranformChange();
  13687. }
  13688. else {
  13689. this.scaleX = scaleX;
  13690. this.scaleY = scaleY;
  13691. }
  13692. }
  13693. return this;
  13694. }
  13695. skew(skewX, skewY) {
  13696. this.skewX = skewX;
  13697. this.skewY = skewY;
  13698. return this;
  13699. }
  13700. render(ctx, x, y) {
  13701. RenderSprite.renders[this._renderType]._fun(this, ctx, x + this._x, y + this._y);
  13702. this._repaint = 0;
  13703. }
  13704. drawToCanvas(canvasWidth, canvasHeight, offsetX, offsetY) {
  13705. return Sprite.drawToCanvas(this, this._renderType, canvasWidth, canvasHeight, offsetX, offsetY);
  13706. }
  13707. drawToTexture(canvasWidth, canvasHeight, offsetX, offsetY) {
  13708. return Sprite.drawToTexture(this, this._renderType, canvasWidth, canvasHeight, offsetX, offsetY);
  13709. }
  13710. drawToTexture3D(offx, offy, tex) {
  13711. throw 'not implement';
  13712. }
  13713. static drawToCanvas(sprite, _renderType, canvasWidth, canvasHeight, offsetX, offsetY) {
  13714. offsetX -= sprite.x;
  13715. offsetY -= sprite.y;
  13716. offsetX |= 0;
  13717. offsetY |= 0;
  13718. canvasWidth |= 0;
  13719. canvasHeight |= 0;
  13720. var ctx = new Context();
  13721. ctx.size(canvasWidth, canvasHeight);
  13722. ctx.asBitmap = true;
  13723. ctx._targets.start();
  13724. ctx._targets.clear(0, 0, 0, 0);
  13725. RenderSprite.renders[_renderType]._fun(sprite, ctx, offsetX, offsetY);
  13726. ctx.flush();
  13727. ctx._targets.end();
  13728. ctx._targets.restore();
  13729. var dt = ctx._targets.getData(0, 0, canvasWidth, canvasHeight);
  13730. ctx.destroy();
  13731. var imgdata = new ImageData(canvasWidth, canvasHeight);
  13732. var lineLen = canvasWidth * 4;
  13733. var dst = imgdata.data;
  13734. var y = canvasHeight - 1;
  13735. var off = y * lineLen;
  13736. var srcoff = 0;
  13737. for (; y >= 0; y--) {
  13738. dst.set(dt.subarray(srcoff, srcoff + lineLen), off);
  13739. off -= lineLen;
  13740. srcoff += lineLen;
  13741. }
  13742. var canv = new HTMLCanvas(true);
  13743. canv.size(canvasWidth, canvasHeight);
  13744. var ctx2d = canv.getContext('2d');
  13745. ctx2d.putImageData(imgdata, 0, 0);
  13746. return canv;
  13747. }
  13748. static drawToTexture(sprite, _renderType, canvasWidth, canvasHeight, offsetX, offsetY) {
  13749. offsetX -= sprite.x;
  13750. offsetY -= sprite.y;
  13751. offsetX |= 0;
  13752. offsetY |= 0;
  13753. canvasWidth |= 0;
  13754. canvasHeight |= 0;
  13755. var ctx = new Context();
  13756. ctx.size(canvasWidth, canvasHeight);
  13757. ctx.asBitmap = true;
  13758. ctx._targets.start();
  13759. ctx._targets.clear(0, 0, 0, 0);
  13760. RenderSprite.renders[_renderType]._fun(sprite, ctx, offsetX, offsetY);
  13761. ctx.flush();
  13762. ctx._targets.end();
  13763. ctx._targets.restore();
  13764. var rtex = new Texture(ctx._targets, Texture.INV_UV);
  13765. ctx.destroy(true);
  13766. return rtex;
  13767. }
  13768. customRender(context, x, y) {
  13769. this._repaint = SpriteConst.REPAINT_ALL;
  13770. }
  13771. _applyFilters() {
  13772. }
  13773. get filters() {
  13774. return this._cacheStyle.filters;
  13775. }
  13776. _setColorFilter(value) { }
  13777. set filters(value) {
  13778. value && value.length === 0 && (value = null);
  13779. if (this._cacheStyle.filters == value)
  13780. return;
  13781. this._getCacheStyle().filters = value ? value.slice() : null;
  13782. if (value && value.length) {
  13783. this._setColorFilter(value[0]);
  13784. this._renderType |= SpriteConst.FILTERS;
  13785. }
  13786. else {
  13787. this._setColorFilter(null);
  13788. this._renderType &= ~SpriteConst.FILTERS;
  13789. }
  13790. this._setRenderType(this._renderType);
  13791. if (value && value.length > 0) {
  13792. if (!this._getBit(Const.DISPLAY))
  13793. this._setBitUp(Const.DISPLAY);
  13794. if (!(value.length == 1 && (value[0] instanceof ColorFilter))) {
  13795. this._getCacheStyle().cacheForFilters = true;
  13796. this._checkCanvasEnable();
  13797. }
  13798. }
  13799. else {
  13800. if (this._cacheStyle.cacheForFilters) {
  13801. this._cacheStyle.cacheForFilters = false;
  13802. this._checkCanvasEnable();
  13803. }
  13804. }
  13805. this._getCacheStyle().hasGlowFilter = this._isHaveGlowFilter();
  13806. this.repaint();
  13807. }
  13808. _isHaveGlowFilter() {
  13809. var i, len;
  13810. if (this.filters) {
  13811. for (i = 0; i < this.filters.length; i++) {
  13812. if (this.filters[i].type == Filter.GLOW) {
  13813. return true;
  13814. }
  13815. }
  13816. }
  13817. for (i = 0, len = this._children.length; i < len; i++) {
  13818. if (this._children[i]._isHaveGlowFilter()) {
  13819. return true;
  13820. }
  13821. }
  13822. return false;
  13823. }
  13824. localToGlobal(point, createNewPoint = false, globalNode = null) {
  13825. if (createNewPoint === true) {
  13826. point = new Point(point.x, point.y);
  13827. }
  13828. var ele = this;
  13829. globalNode = globalNode || ILaya.stage;
  13830. while (ele && !ele.destroyed) {
  13831. if (ele == globalNode)
  13832. break;
  13833. point = ele.toParentPoint(point);
  13834. ele = ele.parent;
  13835. }
  13836. return point;
  13837. }
  13838. globalToLocal(point, createNewPoint = false, globalNode = null) {
  13839. if (createNewPoint) {
  13840. point = new Point(point.x, point.y);
  13841. }
  13842. var ele = this;
  13843. var list = [];
  13844. globalNode = globalNode || ILaya.stage;
  13845. while (ele && !ele.destroyed) {
  13846. if (ele == globalNode)
  13847. break;
  13848. list.push(ele);
  13849. ele = ele.parent;
  13850. }
  13851. var i = list.length - 1;
  13852. while (i >= 0) {
  13853. ele = list[i];
  13854. point = ele.fromParentPoint(point);
  13855. i--;
  13856. }
  13857. return point;
  13858. }
  13859. toParentPoint(point) {
  13860. if (!point)
  13861. return point;
  13862. point.x -= this.pivotX;
  13863. point.y -= this.pivotY;
  13864. if (this.transform) {
  13865. this._transform.transformPoint(point);
  13866. }
  13867. point.x += this._x;
  13868. point.y += this._y;
  13869. var scroll = this._style.scrollRect;
  13870. if (scroll) {
  13871. point.x -= scroll.x;
  13872. point.y -= scroll.y;
  13873. }
  13874. return point;
  13875. }
  13876. fromParentPoint(point) {
  13877. if (!point)
  13878. return point;
  13879. point.x -= this._x;
  13880. point.y -= this._y;
  13881. var scroll = this._style.scrollRect;
  13882. if (scroll) {
  13883. point.x += scroll.x;
  13884. point.y += scroll.y;
  13885. }
  13886. if (this.transform) {
  13887. this._transform.invertTransformPoint(point);
  13888. }
  13889. point.x += this.pivotX;
  13890. point.y += this.pivotY;
  13891. return point;
  13892. }
  13893. fromStagePoint(point) {
  13894. return point;
  13895. }
  13896. on(type, caller, listener, args = null) {
  13897. if (this._mouseState !== 1 && this.isMouseEvent(type)) {
  13898. this.mouseEnabled = true;
  13899. this._setBit(Const.HAS_MOUSE, true);
  13900. if (this._parent) {
  13901. this._onDisplay();
  13902. }
  13903. return this._createListener(type, caller, listener, args, false);
  13904. }
  13905. return super.on(type, caller, listener, args);
  13906. }
  13907. once(type, caller, listener, args = null) {
  13908. if (this._mouseState !== 1 && this.isMouseEvent(type)) {
  13909. this.mouseEnabled = true;
  13910. this._setBit(Const.HAS_MOUSE, true);
  13911. if (this._parent) {
  13912. this._onDisplay();
  13913. }
  13914. return this._createListener(type, caller, listener, args, true);
  13915. }
  13916. return super.once(type, caller, listener, args);
  13917. }
  13918. _onDisplay(v) {
  13919. if (this._mouseState !== 1) {
  13920. var ele = this;
  13921. ele = ele.parent;
  13922. while (ele && ele._mouseState !== 1) {
  13923. if (ele._getBit(Const.HAS_MOUSE))
  13924. break;
  13925. ele.mouseEnabled = true;
  13926. ele._setBit(Const.HAS_MOUSE, true);
  13927. ele = ele.parent;
  13928. }
  13929. }
  13930. }
  13931. _setParent(value) {
  13932. super._setParent(value);
  13933. if (value && this._getBit(Const.HAS_MOUSE)) {
  13934. this._onDisplay();
  13935. }
  13936. }
  13937. loadImage(url, complete = null) {
  13938. if (!url) {
  13939. this.texture = null;
  13940. loaded.call(this);
  13941. }
  13942. else {
  13943. var tex = ILaya.Loader.textureMap[URL.formatURL(url)];
  13944. if (!tex) {
  13945. tex = new Texture();
  13946. tex.load(url);
  13947. ILaya.Loader.cacheTexture(url, tex);
  13948. }
  13949. this.texture = tex;
  13950. if (!tex.getIsReady())
  13951. tex.once(Event.READY, this, loaded);
  13952. else
  13953. loaded.call(this);
  13954. }
  13955. function loaded() {
  13956. this.repaint(SpriteConst.REPAINT_ALL);
  13957. complete && complete.run();
  13958. }
  13959. return this;
  13960. }
  13961. static fromImage(url) {
  13962. return new Sprite().loadImage(url);
  13963. }
  13964. repaint(type = SpriteConst.REPAINT_CACHE) {
  13965. if (!(this._repaint & type)) {
  13966. this._repaint |= type;
  13967. this.parentRepaint(type);
  13968. }
  13969. if (this._cacheStyle && this._cacheStyle.maskParent) {
  13970. this._cacheStyle.maskParent.repaint(type);
  13971. }
  13972. }
  13973. _needRepaint() {
  13974. return (this._repaint & SpriteConst.REPAINT_CACHE) && this._cacheStyle.enableCanvasRender && this._cacheStyle.reCache;
  13975. }
  13976. _childChanged(child = null) {
  13977. if (this._children.length)
  13978. this._renderType |= SpriteConst.CHILDS;
  13979. else
  13980. this._renderType &= ~SpriteConst.CHILDS;
  13981. this._setRenderType(this._renderType);
  13982. if (child && this._getBit(Const.HAS_ZORDER))
  13983. ILaya.systemTimer.callLater(this, this.updateZOrder);
  13984. this.repaint(SpriteConst.REPAINT_ALL);
  13985. }
  13986. parentRepaint(type = SpriteConst.REPAINT_CACHE) {
  13987. var p = this._parent;
  13988. if (p && !(p._repaint & type)) {
  13989. p._repaint |= type;
  13990. p.parentRepaint(type);
  13991. }
  13992. }
  13993. get stage() {
  13994. return ILaya.stage;
  13995. }
  13996. get hitArea() {
  13997. return this._style.hitArea;
  13998. }
  13999. set hitArea(value) {
  14000. this.getStyle().hitArea = value;
  14001. }
  14002. _setMask(value) {
  14003. }
  14004. get mask() {
  14005. return this._cacheStyle.mask;
  14006. }
  14007. set mask(value) {
  14008. if (value && this.mask && this.mask._cacheStyle.maskParent)
  14009. return;
  14010. this._getCacheStyle().mask = value;
  14011. this._setMask(value);
  14012. this._checkCanvasEnable();
  14013. if (value) {
  14014. value._getCacheStyle().maskParent = this;
  14015. }
  14016. else {
  14017. if (this.mask) {
  14018. this.mask._getCacheStyle().maskParent = null;
  14019. }
  14020. }
  14021. this._renderType |= SpriteConst.MASK;
  14022. this._setRenderType(this._renderType);
  14023. this.parentRepaint(SpriteConst.REPAINT_ALL);
  14024. }
  14025. get mouseEnabled() {
  14026. return this._mouseState > 1;
  14027. }
  14028. set mouseEnabled(value) {
  14029. this._mouseState = value ? 2 : 1;
  14030. }
  14031. startDrag(area = null, hasInertia = false, elasticDistance = 0, elasticBackTime = 300, data = null, disableMouseEvent = false, ratio = 0.92) {
  14032. this._style.dragging || (this.getStyle().dragging = new ILaya.Dragging());
  14033. this._style.dragging.start(this, area, hasInertia, elasticDistance, elasticBackTime, data, disableMouseEvent, ratio);
  14034. }
  14035. stopDrag() {
  14036. this._style.dragging && this._style.dragging.stop();
  14037. }
  14038. _setDisplay(value) {
  14039. if (!value) {
  14040. if (this._cacheStyle) {
  14041. this._cacheStyle.releaseContext();
  14042. this._cacheStyle.releaseFilterCache();
  14043. if (this._cacheStyle.hasGlowFilter) {
  14044. this._cacheStyle.hasGlowFilter = false;
  14045. }
  14046. }
  14047. }
  14048. super._setDisplay(value);
  14049. }
  14050. hitTestPoint(x, y) {
  14051. var point = this.globalToLocal(Point.TEMP.setTo(x, y));
  14052. x = point.x;
  14053. y = point.y;
  14054. var rect = this._style.hitArea ? this._style.hitArea : (this._width > 0 && this._height > 0) ? Rectangle.TEMP.setTo(0, 0, this._width, this._height) : this.getSelfBounds();
  14055. return rect.contains(x, y);
  14056. }
  14057. getMousePoint() {
  14058. return this.globalToLocal(Point.TEMP.setTo(ILaya.stage.mouseX, ILaya.stage.mouseY));
  14059. }
  14060. get globalScaleX() {
  14061. var scale = 1;
  14062. var ele = this;
  14063. while (ele) {
  14064. if (ele === ILaya.stage)
  14065. break;
  14066. scale *= ele.scaleX;
  14067. ele = ele.parent;
  14068. }
  14069. return scale;
  14070. }
  14071. get globalRotation() {
  14072. var angle = 0;
  14073. var ele = this;
  14074. while (ele) {
  14075. if (ele === ILaya.stage)
  14076. break;
  14077. angle += ele.rotation;
  14078. ele = ele.parent;
  14079. }
  14080. return angle;
  14081. }
  14082. get globalScaleY() {
  14083. var scale = 1;
  14084. var ele = this;
  14085. while (ele) {
  14086. if (ele === ILaya.stage)
  14087. break;
  14088. scale *= ele.scaleY;
  14089. ele = ele.parent;
  14090. }
  14091. return scale;
  14092. }
  14093. get mouseX() {
  14094. return this.getMousePoint().x;
  14095. }
  14096. get mouseY() {
  14097. return this.getMousePoint().y;
  14098. }
  14099. get zOrder() {
  14100. return this._zOrder;
  14101. }
  14102. set zOrder(value) {
  14103. if (this._zOrder != value) {
  14104. this._zOrder = value;
  14105. if (this._parent) {
  14106. value && this._parent._setBit(Const.HAS_ZORDER, true);
  14107. ILaya.systemTimer.callLater(this._parent, this.updateZOrder);
  14108. }
  14109. }
  14110. }
  14111. get texture() {
  14112. return this._texture;
  14113. }
  14114. _setTexture(value) {
  14115. }
  14116. set texture(value) {
  14117. if (typeof (value) == 'string') {
  14118. this.loadImage(value);
  14119. }
  14120. else if (this._texture != value) {
  14121. this._texture && this._texture._removeReference();
  14122. this._texture = value;
  14123. value && value._addReference();
  14124. this._setTexture(value);
  14125. this._setWidth(this._texture, this.width);
  14126. this._setHeight(this._texture, this.height);
  14127. if (value)
  14128. this._renderType |= SpriteConst.TEXTURE;
  14129. else
  14130. this._renderType &= ~SpriteConst.TEXTURE;
  14131. this._setRenderType(this._renderType);
  14132. this.repaint();
  14133. }
  14134. }
  14135. get viewport() {
  14136. return this._style.viewport;
  14137. }
  14138. set viewport(value) {
  14139. if (typeof (value) == 'string') {
  14140. var recArr;
  14141. recArr = value.split(",");
  14142. if (recArr.length > 3) {
  14143. value = new Rectangle(parseFloat(recArr[0]), parseFloat(recArr[1]), parseFloat(recArr[2]), parseFloat(recArr[3]));
  14144. }
  14145. }
  14146. this.getStyle().viewport = value;
  14147. }
  14148. _setRenderType(type) {
  14149. }
  14150. _setTranformChange() {
  14151. this._tfChanged = true;
  14152. this._renderType |= SpriteConst.TRANSFORM;
  14153. this.parentRepaint(SpriteConst.REPAINT_CACHE);
  14154. }
  14155. _setBgStyleColor(x, y, width, height, fillColor) {
  14156. }
  14157. _setBorderStyleColor(x, y, width, height, fillColor, borderWidth) {
  14158. }
  14159. captureMouseEvent(exclusive) {
  14160. ILaya.MouseManager.instance.setCapture(this, exclusive);
  14161. }
  14162. releaseMouseEvent() {
  14163. ILaya.MouseManager.instance.releaseCapture();
  14164. }
  14165. set drawCallOptimize(value) {
  14166. this._setBit(Const.DRAWCALL_OPTIMIZE, value);
  14167. }
  14168. get drawCallOptimize() {
  14169. return this._getBit(Const.DRAWCALL_OPTIMIZE);
  14170. }
  14171. }
  14172. ClassUtils.regClass("laya.display.Sprite", Sprite);
  14173. ClassUtils.regClass("Laya.Sprite", Sprite);
  14174. class TextStyle extends SpriteStyle {
  14175. constructor() {
  14176. super(...arguments);
  14177. this.italic = false;
  14178. }
  14179. reset() {
  14180. super.reset();
  14181. this.italic = false;
  14182. this.align = "left";
  14183. this.wordWrap = false;
  14184. this.leading = 0;
  14185. this.padding = [0, 0, 0, 0];
  14186. this.bgColor = null;
  14187. this.borderColor = null;
  14188. this.asPassword = false;
  14189. this.stroke = 0;
  14190. this.strokeColor = "#000000";
  14191. this.bold = false;
  14192. this.underline = false;
  14193. this.underlineColor = null;
  14194. this.currBitmapFont = null;
  14195. return this;
  14196. }
  14197. recover() {
  14198. if (this === TextStyle.EMPTY)
  14199. return;
  14200. Pool.recover("TextStyle", this.reset());
  14201. }
  14202. static create() {
  14203. return Pool.getItemByClass("TextStyle", TextStyle);
  14204. }
  14205. render(sprite, context, x, y) {
  14206. (this.bgColor || this.borderColor) && context.drawRect(x, y, sprite.width, sprite.height, this.bgColor, this.borderColor, 1);
  14207. }
  14208. }
  14209. TextStyle.EMPTY = new TextStyle();
  14210. class Text extends Sprite {
  14211. constructor() {
  14212. super();
  14213. this._textWidth = 0;
  14214. this._textHeight = 0;
  14215. this._lines = [];
  14216. this._lineWidths = [];
  14217. this._startX = 0;
  14218. this._startY = 0;
  14219. this._charSize = {};
  14220. this._valign = "top";
  14221. this._fontSize = Text.defaultFontSize;
  14222. this._font = Text.defaultFont;
  14223. this._color = "#000000";
  14224. this._singleCharRender = false;
  14225. this.overflow = Text.VISIBLE;
  14226. this._style = TextStyle.EMPTY;
  14227. }
  14228. static defaultFontStr() {
  14229. return Text.defaultFontSize + "px " + Text.defaultFont;
  14230. }
  14231. getStyle() {
  14232. this._style === TextStyle.EMPTY && (this._style = TextStyle.create());
  14233. return this._style;
  14234. }
  14235. _getTextStyle() {
  14236. if (this._style === TextStyle.EMPTY) {
  14237. this._style = TextStyle.create();
  14238. }
  14239. return this._style;
  14240. }
  14241. static registerBitmapFont(name, bitmapFont) {
  14242. Text._bitmapFonts || (Text._bitmapFonts = {});
  14243. Text._bitmapFonts[name] = bitmapFont;
  14244. }
  14245. static unregisterBitmapFont(name, destroy = true) {
  14246. if (Text._bitmapFonts && Text._bitmapFonts[name]) {
  14247. var tBitmapFont = Text._bitmapFonts[name];
  14248. if (destroy)
  14249. tBitmapFont.destroy();
  14250. delete Text._bitmapFonts[name];
  14251. }
  14252. }
  14253. destroy(destroyChild = true) {
  14254. super.destroy(destroyChild);
  14255. this._clipPoint = null;
  14256. this._lines = null;
  14257. this._lineWidths = null;
  14258. this._words && this._words.forEach(function (w) {
  14259. w.cleanCache();
  14260. });
  14261. this._words = null;
  14262. this._charSize = null;
  14263. }
  14264. _getBoundPointsM(ifRotate = false) {
  14265. var rec = Rectangle.TEMP;
  14266. rec.setTo(0, 0, this.width, this.height);
  14267. return rec._getBoundPoints();
  14268. }
  14269. getGraphicBounds(realSize = false) {
  14270. var rec = Rectangle.TEMP;
  14271. rec.setTo(0, 0, this.width, this.height);
  14272. return rec;
  14273. }
  14274. get width() {
  14275. if (this._width)
  14276. return this._width;
  14277. return this.textWidth + this.padding[1] + this.padding[3];
  14278. }
  14279. set width(value) {
  14280. if (value != this._width) {
  14281. super.set_width(value);
  14282. this.isChanged = true;
  14283. if (this.borderColor) {
  14284. this._setBorderStyleColor(0, 0, this.width, this.height, this.borderColor, 1);
  14285. }
  14286. }
  14287. }
  14288. _getCSSStyle() {
  14289. return this._style;
  14290. }
  14291. get height() {
  14292. if (this._height)
  14293. return this._height;
  14294. return this.textHeight;
  14295. }
  14296. set height(value) {
  14297. if (value != this._height) {
  14298. super.set_height(value);
  14299. this.isChanged = true;
  14300. if (this.borderColor) {
  14301. this._setBorderStyleColor(0, 0, this.width, this.height, this.borderColor, 1);
  14302. }
  14303. }
  14304. }
  14305. get textWidth() {
  14306. this._isChanged && ILaya.systemTimer.runCallLater(this, this.typeset);
  14307. return this._textWidth;
  14308. }
  14309. get textHeight() {
  14310. this._isChanged && ILaya.systemTimer.runCallLater(this, this.typeset);
  14311. return this._textHeight;
  14312. }
  14313. get text() {
  14314. return this._text || "";
  14315. }
  14316. get_text() {
  14317. return this._text || "";
  14318. }
  14319. set_text(value) {
  14320. if (this._text !== value) {
  14321. this.lang(value + "");
  14322. this.isChanged = true;
  14323. this.event(Event.CHANGE);
  14324. if (this.borderColor) {
  14325. this._setBorderStyleColor(0, 0, this.width, this.height, this.borderColor, 1);
  14326. }
  14327. }
  14328. }
  14329. set text(value) {
  14330. this.set_text(value);
  14331. }
  14332. lang(text, arg1 = null, arg2 = null, arg3 = null, arg4 = null, arg5 = null, arg6 = null, arg7 = null, arg8 = null, arg9 = null, arg10 = null) {
  14333. text = Text.langPacks && Text.langPacks[text] ? Text.langPacks[text] : text;
  14334. if (arguments.length < 2) {
  14335. this._text = text;
  14336. }
  14337. else {
  14338. for (var i = 0, n = arguments.length; i < n; i++) {
  14339. text = text.replace("{" + i + "}", arguments[i + 1]);
  14340. }
  14341. this._text = text;
  14342. }
  14343. }
  14344. get font() {
  14345. return this._font;
  14346. }
  14347. set font(value) {
  14348. if (this._style.currBitmapFont) {
  14349. this._getTextStyle().currBitmapFont = null;
  14350. this.scale(1, 1);
  14351. }
  14352. if (Text._bitmapFonts && Text._bitmapFonts[value]) {
  14353. this._getTextStyle().currBitmapFont = Text._bitmapFonts[value];
  14354. }
  14355. this._font = value;
  14356. this.isChanged = true;
  14357. }
  14358. get fontSize() {
  14359. return this._fontSize;
  14360. }
  14361. set fontSize(value) {
  14362. if (this._fontSize != value) {
  14363. this._fontSize = value;
  14364. this.isChanged = true;
  14365. }
  14366. }
  14367. get bold() {
  14368. return this._style.bold;
  14369. }
  14370. set bold(value) {
  14371. this._getTextStyle().bold = value;
  14372. this.isChanged = true;
  14373. }
  14374. get color() {
  14375. return this._color;
  14376. }
  14377. set color(value) {
  14378. this.set_color(value);
  14379. }
  14380. get_color() {
  14381. return this._color;
  14382. }
  14383. set_color(value) {
  14384. if (this._color != value) {
  14385. this._color = value;
  14386. if (!this._isChanged && this._graphics) {
  14387. this._graphics.replaceTextColor(this.color);
  14388. }
  14389. else {
  14390. this.isChanged = true;
  14391. }
  14392. }
  14393. }
  14394. get italic() {
  14395. return this._style.italic;
  14396. }
  14397. set italic(value) {
  14398. this._getTextStyle().italic = value;
  14399. this.isChanged = true;
  14400. }
  14401. get align() {
  14402. return this._style.align;
  14403. }
  14404. set align(value) {
  14405. this._getTextStyle().align = value;
  14406. this.isChanged = true;
  14407. }
  14408. get valign() {
  14409. return this._valign;
  14410. }
  14411. set valign(value) {
  14412. this._valign = value;
  14413. this.isChanged = true;
  14414. }
  14415. get wordWrap() {
  14416. return this._style.wordWrap;
  14417. }
  14418. set wordWrap(value) {
  14419. this._getTextStyle().wordWrap = value;
  14420. this.isChanged = true;
  14421. }
  14422. get leading() {
  14423. return this._style.leading;
  14424. }
  14425. set leading(value) {
  14426. this._getTextStyle().leading = value;
  14427. this.isChanged = true;
  14428. }
  14429. get padding() {
  14430. return this._style.padding;
  14431. }
  14432. set padding(value) {
  14433. if (typeof (value) == 'string') {
  14434. var arr;
  14435. arr = value.split(",");
  14436. var i, len;
  14437. len = arr.length;
  14438. while (arr.length < 4) {
  14439. arr.push(0);
  14440. }
  14441. for (i = 0; i < len; i++) {
  14442. arr[i] = parseFloat(arr[i]) || 0;
  14443. }
  14444. value = arr;
  14445. }
  14446. this._getTextStyle().padding = value;
  14447. this.isChanged = true;
  14448. }
  14449. get bgColor() {
  14450. return this._style.bgColor;
  14451. }
  14452. set bgColor(value) {
  14453. this.set_bgColor(value);
  14454. }
  14455. set_bgColor(value) {
  14456. this._getTextStyle().bgColor = value;
  14457. this._renderType |= SpriteConst.STYLE;
  14458. this._setBgStyleColor(0, 0, this.width, this.height, value);
  14459. this._setRenderType(this._renderType);
  14460. this.isChanged = true;
  14461. }
  14462. get_bgColor() {
  14463. return this._style.bgColor;
  14464. }
  14465. get borderColor() {
  14466. return this._style.borderColor;
  14467. }
  14468. set borderColor(value) {
  14469. this._getTextStyle().borderColor = value;
  14470. this._renderType |= SpriteConst.STYLE;
  14471. this._setBorderStyleColor(0, 0, this.width, this.height, value, 1);
  14472. this._setRenderType(this._renderType);
  14473. this.isChanged = true;
  14474. }
  14475. get stroke() {
  14476. return this._style.stroke;
  14477. }
  14478. set stroke(value) {
  14479. this._getTextStyle().stroke = value;
  14480. this.isChanged = true;
  14481. }
  14482. get strokeColor() {
  14483. return this._style.strokeColor;
  14484. }
  14485. set strokeColor(value) {
  14486. this._getTextStyle().strokeColor = value;
  14487. this.isChanged = true;
  14488. }
  14489. set isChanged(value) {
  14490. if (this._isChanged !== value) {
  14491. this._isChanged = value;
  14492. value && ILaya.systemTimer.callLater(this, this.typeset);
  14493. }
  14494. }
  14495. _getContextFont() {
  14496. return (this.italic ? "italic " : "") + (this.bold ? "bold " : "") + this.fontSize + "px " + (ILaya.Browser.onIPhone ? (Text.fontFamilyMap[this.font] || this.font) : this.font);
  14497. }
  14498. _isPassWordMode() {
  14499. var style = this._style;
  14500. var password = style.asPassword;
  14501. if (("prompt" in this) && this['prompt'] == this._text)
  14502. password = false;
  14503. return password;
  14504. }
  14505. _getPassWordTxt(txt) {
  14506. var len = txt.length;
  14507. var word;
  14508. word = "";
  14509. for (var j = len; j > 0; j--) {
  14510. word += "●";
  14511. }
  14512. return word;
  14513. }
  14514. _renderText() {
  14515. var padding = this.padding;
  14516. var visibleLineCount = this._lines.length;
  14517. if (this.overflow != Text.VISIBLE) {
  14518. visibleLineCount = Math.min(visibleLineCount, Math.floor((this.height - padding[0] - padding[2]) / (this.leading + this._charSize.height)) + 1);
  14519. }
  14520. var beginLine = this.scrollY / (this._charSize.height + this.leading) | 0;
  14521. var graphics = this.graphics;
  14522. graphics.clear(true);
  14523. var ctxFont = this._getContextFont();
  14524. ILaya.Browser.context.font = ctxFont;
  14525. var startX = padding[3];
  14526. var textAlgin = "left";
  14527. var lines = this._lines;
  14528. var lineHeight = this.leading + this._charSize.height;
  14529. var tCurrBitmapFont = this._style.currBitmapFont;
  14530. if (tCurrBitmapFont) {
  14531. lineHeight = this.leading + tCurrBitmapFont.getMaxHeight();
  14532. }
  14533. var startY = padding[0];
  14534. if ((!tCurrBitmapFont) && this._width > 0 && this._textWidth <= this._width) {
  14535. if (this.align == "right") {
  14536. textAlgin = "right";
  14537. startX = this._width - padding[1];
  14538. }
  14539. else if (this.align == "center") {
  14540. textAlgin = "center";
  14541. startX = this._width * 0.5 + padding[3] - padding[1];
  14542. }
  14543. }
  14544. if (this._height > 0) {
  14545. var tempVAlign = (this._textHeight > this._height) ? "top" : this.valign;
  14546. if (tempVAlign === "middle")
  14547. startY = (this._height - visibleLineCount * lineHeight) * 0.5 + padding[0] - padding[2];
  14548. else if (tempVAlign === "bottom")
  14549. startY = this._height - visibleLineCount * lineHeight - padding[2];
  14550. }
  14551. var style = this._style;
  14552. if (tCurrBitmapFont && tCurrBitmapFont.autoScaleSize) {
  14553. var bitmapScale = tCurrBitmapFont.fontSize / this.fontSize;
  14554. }
  14555. if (this._clipPoint) {
  14556. graphics.save();
  14557. if (tCurrBitmapFont && tCurrBitmapFont.autoScaleSize) {
  14558. var tClipWidth;
  14559. var tClipHeight;
  14560. this._width ? tClipWidth = (this._width - padding[3] - padding[1]) : tClipWidth = this._textWidth;
  14561. this._height ? tClipHeight = (this._height - padding[0] - padding[2]) : tClipHeight = this._textHeight;
  14562. tClipWidth *= bitmapScale;
  14563. tClipHeight *= bitmapScale;
  14564. graphics.clipRect(padding[3], padding[0], tClipWidth, tClipHeight);
  14565. }
  14566. else {
  14567. graphics.clipRect(padding[3], padding[0], this._width ? (this._width - padding[3] - padding[1]) : this._textWidth, this._height ? (this._height - padding[0] - padding[2]) : this._textHeight);
  14568. }
  14569. this.repaint();
  14570. }
  14571. var password = style.asPassword;
  14572. if (("prompt" in this) && this['prompt'] == this._text)
  14573. password = false;
  14574. var x = 0, y = 0;
  14575. var end = Math.min(this._lines.length, visibleLineCount + beginLine) || 1;
  14576. for (var i = beginLine; i < end; i++) {
  14577. var word = lines[i];
  14578. var _word;
  14579. if (password) {
  14580. var len = word.length;
  14581. word = "";
  14582. for (var j = len; j > 0; j--) {
  14583. word += "●";
  14584. }
  14585. }
  14586. if (word == null)
  14587. word = "";
  14588. x = startX - (this._clipPoint ? this._clipPoint.x : 0);
  14589. y = startY + lineHeight * i - (this._clipPoint ? this._clipPoint.y : 0);
  14590. this.underline && this._drawUnderline(textAlgin, x, y, i);
  14591. if (tCurrBitmapFont) {
  14592. var tWidth = this.width;
  14593. if (tCurrBitmapFont.autoScaleSize) {
  14594. tWidth = this.width * bitmapScale;
  14595. }
  14596. tCurrBitmapFont._drawText(word, this, x, y, this.align, tWidth);
  14597. }
  14598. else {
  14599. this._words || (this._words = []);
  14600. if (this._words.length > (i - beginLine)) {
  14601. _word = this._words[i - beginLine];
  14602. }
  14603. else {
  14604. _word = new WordText();
  14605. this._words.push(_word);
  14606. }
  14607. _word.setText(word);
  14608. _word.splitRender = this._singleCharRender;
  14609. style.stroke ? graphics.fillBorderText(_word, x, y, ctxFont, this.color, style.strokeColor, style.stroke, textAlgin) : graphics.fillText(_word, x, y, ctxFont, this.color, textAlgin);
  14610. }
  14611. }
  14612. if (tCurrBitmapFont && tCurrBitmapFont.autoScaleSize) {
  14613. var tScale = 1 / bitmapScale;
  14614. this.scale(tScale, tScale);
  14615. }
  14616. if (this._clipPoint)
  14617. graphics.restore();
  14618. this._startX = startX;
  14619. this._startY = startY;
  14620. }
  14621. _drawUnderline(align, x, y, lineIndex) {
  14622. var lineWidth = this._lineWidths[lineIndex];
  14623. switch (align) {
  14624. case 'center':
  14625. x -= lineWidth / 2;
  14626. break;
  14627. case 'right':
  14628. x -= lineWidth;
  14629. break;
  14630. case 'left':
  14631. default:
  14632. break;
  14633. }
  14634. y += this._charSize.height;
  14635. this._graphics.drawLine(x, y, x + lineWidth, y, this.underlineColor || this.color, 1);
  14636. }
  14637. typeset() {
  14638. this._isChanged = false;
  14639. if (!this._text) {
  14640. this._clipPoint = null;
  14641. this._textWidth = this._textHeight = 0;
  14642. this.graphics.clear(true);
  14643. return;
  14644. }
  14645. if (ILaya.Render.isConchApp) {
  14646. window.conchTextCanvas.font = this._getContextFont();
  14647. }
  14648. else {
  14649. ILaya.Browser.context.font = this._getContextFont();
  14650. }
  14651. this._lines.length = 0;
  14652. this._lineWidths.length = 0;
  14653. if (this._isPassWordMode()) {
  14654. this._parseLines(this._getPassWordTxt(this._text));
  14655. }
  14656. else
  14657. this._parseLines(this._text);
  14658. this._evalTextSize();
  14659. if (this._checkEnabledViewportOrNot())
  14660. this._clipPoint || (this._clipPoint = new Point(0, 0));
  14661. else
  14662. this._clipPoint = null;
  14663. this._renderText();
  14664. }
  14665. _evalTextSize() {
  14666. var nw, nh;
  14667. nw = Math.max.apply(this, this._lineWidths);
  14668. if (this._style.currBitmapFont)
  14669. nh = this._lines.length * (this._style.currBitmapFont.getMaxHeight() + this.leading) + this.padding[0] + this.padding[2];
  14670. else
  14671. nh = this._lines.length * (this._charSize.height + this.leading) + this.padding[0] + this.padding[2];
  14672. if (nw != this._textWidth || nh != this._textHeight) {
  14673. this._textWidth = nw;
  14674. this._textHeight = nh;
  14675. }
  14676. }
  14677. _checkEnabledViewportOrNot() {
  14678. return this.overflow == Text.SCROLL && ((this._width > 0 && this._textWidth > this._width) || (this._height > 0 && this._textHeight > this._height));
  14679. }
  14680. changeText(text) {
  14681. if (this._text !== text) {
  14682. this.lang(text + "");
  14683. if (this._graphics && this._graphics.replaceText(this._text)) ;
  14684. else {
  14685. this.typeset();
  14686. }
  14687. }
  14688. }
  14689. _parseLines(text) {
  14690. var needWordWrapOrTruncate = this.wordWrap || this.overflow == Text.HIDDEN;
  14691. if (needWordWrapOrTruncate) {
  14692. var wordWrapWidth = this._getWordWrapWidth();
  14693. }
  14694. var bitmapFont = this._style.currBitmapFont;
  14695. if (bitmapFont) {
  14696. this._charSize.width = bitmapFont.getMaxWidth();
  14697. this._charSize.height = bitmapFont.getMaxHeight();
  14698. }
  14699. else {
  14700. var measureResult = null;
  14701. if (ILaya.Render.isConchApp) {
  14702. measureResult = window.conchTextCanvas.measureText(Text._testWord);
  14703. }
  14704. else {
  14705. measureResult = ILaya.Browser.context.measureText(Text._testWord);
  14706. }
  14707. if (!measureResult)
  14708. measureResult = { width: 100 };
  14709. this._charSize.width = measureResult.width;
  14710. this._charSize.height = (measureResult.height || this.fontSize);
  14711. }
  14712. var lines = text.replace(/\r\n/g, "\n").split("\n");
  14713. for (var i = 0, n = lines.length; i < n; i++) {
  14714. var line = lines[i];
  14715. if (needWordWrapOrTruncate)
  14716. this._parseLine(line, wordWrapWidth);
  14717. else {
  14718. this._lineWidths.push(this._getTextWidth(line));
  14719. this._lines.push(line);
  14720. }
  14721. }
  14722. }
  14723. _parseLine(line, wordWrapWidth) {
  14724. var lines = this._lines;
  14725. var maybeIndex = 0;
  14726. var charsWidth = 0;
  14727. var wordWidth = 0;
  14728. var startIndex = 0;
  14729. charsWidth = this._getTextWidth(line);
  14730. if (charsWidth <= wordWrapWidth) {
  14731. lines.push(line);
  14732. this._lineWidths.push(charsWidth);
  14733. return;
  14734. }
  14735. charsWidth = this._charSize.width;
  14736. maybeIndex = Math.floor(wordWrapWidth / charsWidth);
  14737. (maybeIndex == 0) && (maybeIndex = 1);
  14738. charsWidth = this._getTextWidth(line.substring(0, maybeIndex));
  14739. wordWidth = charsWidth;
  14740. for (var j = maybeIndex, m = line.length; j < m; j++) {
  14741. charsWidth = this._getTextWidth(line.charAt(j));
  14742. wordWidth += charsWidth;
  14743. if (wordWidth > wordWrapWidth) {
  14744. if (this.wordWrap) {
  14745. var newLine = line.substring(startIndex, j);
  14746. if (newLine.charCodeAt(newLine.length - 1) < 255) {
  14747. var execResult = /(?:\w|-)+$/.exec(newLine);
  14748. if (execResult) {
  14749. j = execResult.index + startIndex;
  14750. if (execResult.index == 0)
  14751. j += newLine.length;
  14752. else
  14753. newLine = line.substring(startIndex, j);
  14754. }
  14755. }
  14756. lines.push(newLine);
  14757. this._lineWidths.push(wordWidth - charsWidth);
  14758. startIndex = j;
  14759. if (j + maybeIndex < m) {
  14760. j += maybeIndex;
  14761. charsWidth = this._getTextWidth(line.substring(startIndex, j));
  14762. wordWidth = charsWidth;
  14763. j--;
  14764. }
  14765. else {
  14766. lines.push(line.substring(startIndex, m));
  14767. this._lineWidths.push(this._getTextWidth(lines[lines.length - 1]));
  14768. startIndex = -1;
  14769. break;
  14770. }
  14771. }
  14772. else if (this.overflow == Text.HIDDEN) {
  14773. lines.push(line.substring(0, j));
  14774. this._lineWidths.push(this._getTextWidth(lines[lines.length - 1]));
  14775. return;
  14776. }
  14777. }
  14778. }
  14779. if (this.wordWrap && startIndex != -1) {
  14780. lines.push(line.substring(startIndex, m));
  14781. this._lineWidths.push(this._getTextWidth(lines[lines.length - 1]));
  14782. }
  14783. }
  14784. _getTextWidth(text) {
  14785. var bitmapFont = this._style.currBitmapFont;
  14786. if (bitmapFont)
  14787. return bitmapFont.getTextWidth(text);
  14788. else {
  14789. if (ILaya.Render.isConchApp) {
  14790. return window.conchTextCanvas.measureText(text).width;
  14791. }
  14792. else
  14793. return ILaya.Browser.context.measureText(text).width;
  14794. }
  14795. }
  14796. _getWordWrapWidth() {
  14797. var p = this.padding;
  14798. var w;
  14799. var bitmapFont = this._style.currBitmapFont;
  14800. if (bitmapFont && bitmapFont.autoScaleSize)
  14801. w = this._width * (bitmapFont.fontSize / this.fontSize);
  14802. else
  14803. w = this._width;
  14804. if (w <= 0) {
  14805. w = this.wordWrap ? 100 : ILaya.Browser.width;
  14806. }
  14807. w <= 0 && (w = 100);
  14808. return w - p[3] - p[1];
  14809. }
  14810. getCharPoint(charIndex, out = null) {
  14811. this._isChanged && ILaya.systemTimer.runCallLater(this, this.typeset);
  14812. var len = 0, lines = this._lines, startIndex = 0;
  14813. for (var i = 0, n = lines.length; i < n; i++) {
  14814. len += lines[i].length;
  14815. if (charIndex < len) {
  14816. var line = i;
  14817. break;
  14818. }
  14819. startIndex = len;
  14820. }
  14821. var ctxFont = (this.italic ? "italic " : "") + (this.bold ? "bold " : "") + this.fontSize + "px " + this.font;
  14822. ILaya.Browser.context.font = ctxFont;
  14823. var width = this._getTextWidth(this._text.substring(startIndex, charIndex));
  14824. var point = out || new Point();
  14825. return point.setTo(this._startX + width - (this._clipPoint ? this._clipPoint.x : 0), this._startY + line * (this._charSize.height + this.leading) - (this._clipPoint ? this._clipPoint.y : 0));
  14826. }
  14827. set scrollX(value) {
  14828. if (this.overflow != Text.SCROLL || (this.textWidth < this._width || !this._clipPoint))
  14829. return;
  14830. value = value < this.padding[3] ? this.padding[3] : value;
  14831. var maxScrollX = this._textWidth - this._width;
  14832. value = value > maxScrollX ? maxScrollX : value;
  14833. this._clipPoint.x = value;
  14834. this._renderText();
  14835. }
  14836. get scrollX() {
  14837. if (!this._clipPoint)
  14838. return 0;
  14839. return this._clipPoint.x;
  14840. }
  14841. set scrollY(value) {
  14842. if (this.overflow != Text.SCROLL || (this.textHeight < this._height || !this._clipPoint))
  14843. return;
  14844. value = value < this.padding[0] ? this.padding[0] : value;
  14845. var maxScrollY = this._textHeight - this._height;
  14846. value = value > maxScrollY ? maxScrollY : value;
  14847. this._clipPoint.y = value;
  14848. this._renderText();
  14849. }
  14850. get scrollY() {
  14851. if (!this._clipPoint)
  14852. return 0;
  14853. return this._clipPoint.y;
  14854. }
  14855. get maxScrollX() {
  14856. return (this.textWidth < this._width) ? 0 : this._textWidth - this._width;
  14857. }
  14858. get maxScrollY() {
  14859. return (this.textHeight < this._height) ? 0 : this._textHeight - this._height;
  14860. }
  14861. get lines() {
  14862. if (this._isChanged)
  14863. this.typeset();
  14864. return this._lines;
  14865. }
  14866. get underlineColor() {
  14867. return this._style.underlineColor;
  14868. }
  14869. set underlineColor(value) {
  14870. this._getTextStyle().underlineColor = value;
  14871. if (!this._isChanged)
  14872. this._renderText();
  14873. }
  14874. get underline() {
  14875. return this._style.underline;
  14876. }
  14877. set underline(value) {
  14878. this._getTextStyle().underline = value;
  14879. }
  14880. set singleCharRender(value) {
  14881. this._singleCharRender = value;
  14882. }
  14883. get singleCharRender() {
  14884. return this._singleCharRender;
  14885. }
  14886. }
  14887. Text.VISIBLE = "visible";
  14888. Text.SCROLL = "scroll";
  14889. Text.HIDDEN = "hidden";
  14890. Text.defaultFontSize = 12;
  14891. Text.defaultFont = "Arial";
  14892. Text.isComplexText = false;
  14893. Text.fontFamilyMap = { "报隶": "报隶-简", "黑体": "黑体-简", "楷体": "楷体-简", "兰亭黑": "兰亭黑-简", "隶变": "隶变-简", "凌慧体": "凌慧体-简", "翩翩体": "翩翩体-简", "苹方": "苹方-简", "手札体": "手札体-简", "宋体": "宋体-简", "娃娃体": "娃娃体-简", "魏碑": "魏碑-简", "行楷": "行楷-简", "雅痞": "雅痞-简", "圆体": "圆体-简" };
  14894. Text._testWord = "游";
  14895. Text.CharacterCache = true;
  14896. Text.RightToLeft = false;
  14897. ILaya.regClass(Text);
  14898. ClassUtils.regClass("laya.display.Text", Text);
  14899. ClassUtils.regClass("Laya.Text", Text);
  14900. class Input extends Text {
  14901. constructor() {
  14902. super();
  14903. this._multiline = false;
  14904. this._editable = true;
  14905. this._maxChars = 1E5;
  14906. this._type = "text";
  14907. this._prompt = '';
  14908. this._promptColor = "#A9A9A9";
  14909. this._originColor = "#000000";
  14910. this._content = '';
  14911. Input.IOS_IFRAME = (ILaya.Browser.onIOS && ILaya.Browser.window.top != ILaya.Browser.window.self);
  14912. this._width = 100;
  14913. this._height = 20;
  14914. this.multiline = false;
  14915. this.overflow = Text.SCROLL;
  14916. this.on(Event.MOUSE_DOWN, this, this._onMouseDown);
  14917. this.on(Event.UNDISPLAY, this, this._onUnDisplay);
  14918. }
  14919. static __init__() {
  14920. Input._createInputElement();
  14921. if (ILaya.Browser.onMobile) {
  14922. var isTrue = false;
  14923. if (ILaya.Browser.onMiniGame || ILaya.Browser.onBDMiniGame || ILaya.Browser.onQGMiniGame || ILaya.Browser.onKGMiniGame || ILaya.Browser.onVVMiniGame || ILaya.Browser.onAlipayMiniGame || ILaya.Browser.onQQMiniGame) {
  14924. isTrue = true;
  14925. }
  14926. ILaya.Render.canvas.addEventListener(Input.IOS_IFRAME ? (isTrue ? "touchend" : "click") : "touchend", Input._popupInputMethod);
  14927. }
  14928. }
  14929. static _popupInputMethod(e) {
  14930. if (!Input.isInputting)
  14931. return;
  14932. var input = Input.inputElement;
  14933. input.focus();
  14934. }
  14935. static _createInputElement() {
  14936. Input._initInput(Input.area = ILaya.Browser.createElement("textarea"));
  14937. Input._initInput(Input.input = ILaya.Browser.createElement("input"));
  14938. Input.inputContainer = ILaya.Browser.createElement("div");
  14939. Input.inputContainer.style.position = "absolute";
  14940. Input.inputContainer.style.zIndex = 1E5;
  14941. ILaya.Browser.container.appendChild(Input.inputContainer);
  14942. Input.inputContainer.setPos = function (x, y) {
  14943. Input.inputContainer.style.left = x + 'px';
  14944. Input.inputContainer.style.top = y + 'px';
  14945. };
  14946. }
  14947. static _initInput(input) {
  14948. var style = input.style;
  14949. style.cssText = "position:absolute;overflow:hidden;resize:none;transform-origin:0 0;-webkit-transform-origin:0 0;-moz-transform-origin:0 0;-o-transform-origin:0 0;";
  14950. style.resize = 'none';
  14951. style.backgroundColor = 'transparent';
  14952. style.border = 'none';
  14953. style.outline = 'none';
  14954. style.zIndex = 1;
  14955. input.addEventListener('input', Input._processInputting);
  14956. input.addEventListener('mousemove', Input._stopEvent);
  14957. input.addEventListener('mousedown', Input._stopEvent);
  14958. input.addEventListener('touchmove', Input._stopEvent);
  14959. input.setFontFace = function (fontFace) { input.style.fontFamily = fontFace; };
  14960. if (!ILaya.Render.isConchApp) {
  14961. input.setColor = function (color) { input.style.color = color; };
  14962. input.setFontSize = function (fontSize) { input.style.fontSize = fontSize + 'px'; };
  14963. }
  14964. }
  14965. static _processInputting(e) {
  14966. var input = Input.inputElement.target;
  14967. if (!input)
  14968. return;
  14969. var value = Input.inputElement.value;
  14970. if (input._restrictPattern) {
  14971. value = value.replace(/\u2006|\x27/g, "");
  14972. if (input._restrictPattern.test(value)) {
  14973. value = value.replace(input._restrictPattern, "");
  14974. Input.inputElement.value = value;
  14975. }
  14976. }
  14977. input._text = value;
  14978. input.event(Event.INPUT);
  14979. }
  14980. static _stopEvent(e) {
  14981. if (e.type == 'touchmove')
  14982. e.preventDefault();
  14983. e.stopPropagation && e.stopPropagation();
  14984. }
  14985. setSelection(startIndex, endIndex) {
  14986. this.focus = true;
  14987. Input.inputElement.selectionStart = startIndex;
  14988. Input.inputElement.selectionEnd = endIndex;
  14989. }
  14990. get multiline() {
  14991. return this._multiline;
  14992. }
  14993. set multiline(value) {
  14994. this._multiline = value;
  14995. this.valign = value ? "top" : "middle";
  14996. }
  14997. get nativeInput() {
  14998. return this._multiline ? Input.area : Input.input;
  14999. }
  15000. _onUnDisplay(e = null) {
  15001. this.focus = false;
  15002. }
  15003. _onMouseDown(e) {
  15004. this.focus = true;
  15005. }
  15006. _syncInputTransform() {
  15007. var inputElement = this.nativeInput;
  15008. var transform = Utils.getTransformRelativeToWindow(this, this.padding[3], this.padding[0]);
  15009. var inputWid = this._width - this.padding[1] - this.padding[3];
  15010. var inputHei = this._height - this.padding[0] - this.padding[2];
  15011. if (ILaya.Render.isConchApp) {
  15012. inputElement.setScale(transform.scaleX, transform.scaleY);
  15013. inputElement.setSize(inputWid, inputHei);
  15014. inputElement.setPos(transform.x, transform.y);
  15015. }
  15016. else {
  15017. Input.inputContainer.style.transform = Input.inputContainer.style.webkitTransform = "scale(" + transform.scaleX + "," + transform.scaleY + ") rotate(" + (ILaya.stage.canvasDegree) + "deg)";
  15018. inputElement.style.width = inputWid + 'px';
  15019. inputElement.style.height = inputHei + 'px';
  15020. Input.inputContainer.style.left = transform.x + 'px';
  15021. Input.inputContainer.style.top = transform.y + 'px';
  15022. }
  15023. }
  15024. select() {
  15025. this.nativeInput.select();
  15026. }
  15027. get focus() {
  15028. return this._focus;
  15029. }
  15030. set focus(value) {
  15031. var input = this.nativeInput;
  15032. if (this._focus !== value) {
  15033. if (value) {
  15034. if (input.target) {
  15035. input.target._focusOut();
  15036. }
  15037. else {
  15038. this._setInputMethod();
  15039. }
  15040. input.target = this;
  15041. this._focusIn();
  15042. }
  15043. else {
  15044. input.target = null;
  15045. this._focusOut();
  15046. ILaya.Browser.document.body.scrollTop = 0;
  15047. input.blur();
  15048. if (ILaya.Render.isConchApp)
  15049. input.setPos(-10000, -10000);
  15050. else if (Input.inputContainer.contains(input))
  15051. Input.inputContainer.removeChild(input);
  15052. }
  15053. }
  15054. }
  15055. _setInputMethod() {
  15056. Input.input.parentElement && (Input.inputContainer.removeChild(Input.input));
  15057. Input.area.parentElement && (Input.inputContainer.removeChild(Input.area));
  15058. Input.inputElement = (this._multiline ? Input.area : Input.input);
  15059. Input.inputContainer.appendChild(Input.inputElement);
  15060. if (Text.RightToLeft) {
  15061. Input.inputElement.style.direction = "rtl";
  15062. }
  15063. }
  15064. _focusIn() {
  15065. Input.isInputting = true;
  15066. var input = this.nativeInput;
  15067. this._focus = true;
  15068. var cssStyle = input.style;
  15069. cssStyle.whiteSpace = (this.wordWrap ? "pre-wrap" : "nowrap");
  15070. this._setPromptColor();
  15071. input.readOnly = !this._editable;
  15072. if (ILaya.Render.isConchApp) {
  15073. input.setType(this._type);
  15074. input.setForbidEdit(!this._editable);
  15075. }
  15076. input.maxLength = this._maxChars;
  15077. var padding = this.padding;
  15078. input.value = this._content;
  15079. input.placeholder = this._prompt;
  15080. ILaya.stage.off(Event.KEY_DOWN, this, this._onKeyDown);
  15081. ILaya.stage.on(Event.KEY_DOWN, this, this._onKeyDown);
  15082. ILaya.stage.focus = this;
  15083. this.event(Event.FOCUS);
  15084. if (ILaya.Browser.onPC)
  15085. input.focus();
  15086. if (!ILaya.Browser.onMiniGame && !ILaya.Browser.onBDMiniGame && !ILaya.Browser.onQGMiniGame && !ILaya.Browser.onKGMiniGame && !ILaya.Browser.onVVMiniGame && !ILaya.Browser.onAlipayMiniGame && !ILaya.Browser.onQQMiniGame) {
  15087. var temp = this._text;
  15088. this._text = null;
  15089. }
  15090. this.typeset();
  15091. input.setColor(this._originColor);
  15092. input.setFontSize(this.fontSize);
  15093. input.setFontFace(ILaya.Browser.onIPhone ? (Text.fontFamilyMap[this.font] || this.font) : this.font);
  15094. if (ILaya.Render.isConchApp) {
  15095. input.setMultiAble && input.setMultiAble(this._multiline);
  15096. }
  15097. cssStyle.lineHeight = (this.leading + this.fontSize) + "px";
  15098. cssStyle.fontStyle = (this.italic ? "italic" : "normal");
  15099. cssStyle.fontWeight = (this.bold ? "bold" : "normal");
  15100. cssStyle.textAlign = this.align;
  15101. cssStyle.padding = "0 0";
  15102. this._syncInputTransform();
  15103. if (!ILaya.Render.isConchApp && ILaya.Browser.onPC)
  15104. ILaya.systemTimer.frameLoop(1, this, this._syncInputTransform);
  15105. }
  15106. _setPromptColor() {
  15107. Input.promptStyleDOM = ILaya.Browser.getElementById("promptStyle");
  15108. if (!Input.promptStyleDOM) {
  15109. Input.promptStyleDOM = ILaya.Browser.createElement("style");
  15110. Input.promptStyleDOM.setAttribute("id", "promptStyle");
  15111. ILaya.Browser.document.head.appendChild(Input.promptStyleDOM);
  15112. }
  15113. Input.promptStyleDOM.innerText = "input::-webkit-input-placeholder, textarea::-webkit-input-placeholder {" + "color:" + this._promptColor + "}" + "input:-moz-placeholder, textarea:-moz-placeholder {" + "color:" + this._promptColor + "}" + "input::-moz-placeholder, textarea::-moz-placeholder {" + "color:" + this._promptColor + "}" + "input:-ms-input-placeholder, textarea:-ms-input-placeholder {" + "color:" + this._promptColor + "}";
  15114. }
  15115. _focusOut() {
  15116. Input.isInputting = false;
  15117. this._focus = false;
  15118. this._text = null;
  15119. this._content = this.nativeInput.value;
  15120. if (!this._content) {
  15121. super.set_text(this._prompt);
  15122. super.set_color(this._promptColor);
  15123. }
  15124. else {
  15125. super.set_text(this._content);
  15126. super.set_color(this._originColor);
  15127. }
  15128. ILaya.stage.off(Event.KEY_DOWN, this, this._onKeyDown);
  15129. ILaya.stage.focus = null;
  15130. this.event(Event.BLUR);
  15131. this.event(Event.CHANGE);
  15132. if (ILaya.Render.isConchApp)
  15133. this.nativeInput.blur();
  15134. ILaya.Browser.onPC && ILaya.systemTimer.clear(this, this._syncInputTransform);
  15135. }
  15136. _onKeyDown(e) {
  15137. if (e.keyCode === 13) {
  15138. if (ILaya.Browser.onMobile && !this._multiline)
  15139. this.focus = false;
  15140. this.event(Event.ENTER);
  15141. }
  15142. }
  15143. set text(value) {
  15144. super.set_color(this._originColor);
  15145. value += '';
  15146. if (this._focus) {
  15147. this.nativeInput.value = value || '';
  15148. this.event(Event.CHANGE);
  15149. }
  15150. else {
  15151. if (!this._multiline)
  15152. value = value.replace(/\r?\n/g, '');
  15153. this._content = value;
  15154. if (value)
  15155. super.set_text(value);
  15156. else {
  15157. super.set_text(this._prompt);
  15158. super.set_color(this.promptColor);
  15159. }
  15160. }
  15161. }
  15162. get text() {
  15163. if (this._focus)
  15164. return this.nativeInput.value;
  15165. else
  15166. return this._content || "";
  15167. }
  15168. changeText(text) {
  15169. this._content = text;
  15170. if (this._focus) {
  15171. this.nativeInput.value = text || '';
  15172. this.event(Event.CHANGE);
  15173. }
  15174. else
  15175. super.changeText(text);
  15176. }
  15177. set color(value) {
  15178. if (this._focus)
  15179. this.nativeInput.setColor(value);
  15180. super.set_color(this._content ? value : this._promptColor);
  15181. this._originColor = value;
  15182. }
  15183. get color() {
  15184. return super.color;
  15185. }
  15186. set bgColor(value) {
  15187. super.set_bgColor(value);
  15188. if (ILaya.Render.isConchApp)
  15189. this.nativeInput.setBgColor(value);
  15190. }
  15191. get bgColor() {
  15192. return super.bgColor;
  15193. }
  15194. get restrict() {
  15195. if (this._restrictPattern) {
  15196. return this._restrictPattern.source;
  15197. }
  15198. return "";
  15199. }
  15200. set restrict(pattern) {
  15201. if (pattern) {
  15202. pattern = "[^" + pattern + "]";
  15203. if (pattern.indexOf("^^") > -1)
  15204. pattern = pattern.replace("^^", "");
  15205. this._restrictPattern = new RegExp(pattern, "g");
  15206. }
  15207. else
  15208. this._restrictPattern = null;
  15209. }
  15210. set editable(value) {
  15211. this._editable = value;
  15212. if (ILaya.Render.isConchApp) {
  15213. Input.input.setForbidEdit(!value);
  15214. }
  15215. }
  15216. get editable() {
  15217. return this._editable;
  15218. }
  15219. get maxChars() {
  15220. return this._maxChars;
  15221. }
  15222. set maxChars(value) {
  15223. if (value <= 0)
  15224. value = 1E5;
  15225. this._maxChars = value;
  15226. }
  15227. get prompt() {
  15228. return this._prompt;
  15229. }
  15230. set prompt(value) {
  15231. if (!this._text && value)
  15232. super.set_color(this._promptColor);
  15233. this.promptColor = this._promptColor;
  15234. if (this._text)
  15235. super.set_text((this._text == this._prompt) ? value : this._text);
  15236. else
  15237. super.set_text(value);
  15238. this._prompt = Text.langPacks && Text.langPacks[value] ? Text.langPacks[value] : value;
  15239. }
  15240. get promptColor() {
  15241. return this._promptColor;
  15242. }
  15243. set promptColor(value) {
  15244. this._promptColor = value;
  15245. if (!this._content)
  15246. super.set_color(value);
  15247. }
  15248. get type() {
  15249. return this._type;
  15250. }
  15251. set type(value) {
  15252. if (value === "password")
  15253. this._getTextStyle().asPassword = true;
  15254. else
  15255. this._getTextStyle().asPassword = false;
  15256. this._type = value;
  15257. }
  15258. }
  15259. Input.TYPE_TEXT = "text";
  15260. Input.TYPE_PASSWORD = "password";
  15261. Input.TYPE_EMAIL = "email";
  15262. Input.TYPE_URL = "url";
  15263. Input.TYPE_NUMBER = "number";
  15264. Input.TYPE_RANGE = "range";
  15265. Input.TYPE_DATE = "date";
  15266. Input.TYPE_MONTH = "month";
  15267. Input.TYPE_WEEK = "week";
  15268. Input.TYPE_TIME = "time";
  15269. Input.TYPE_DATE_TIME = "datetime";
  15270. Input.TYPE_DATE_TIME_LOCAL = "datetime-local";
  15271. Input.TYPE_SEARCH = "search";
  15272. Input.IOS_IFRAME = false;
  15273. Input.inputHeight = 45;
  15274. Input.isInputting = false;
  15275. ClassUtils.regClass("laya.display.Input", Input);
  15276. ClassUtils.regClass("Laya.Input", Input);
  15277. class TouchManager {
  15278. constructor() {
  15279. this.preOvers = [];
  15280. this.preDowns = [];
  15281. this.preRightDowns = [];
  15282. this.enable = true;
  15283. this._event = new Event();
  15284. this._lastClickTime = 0;
  15285. }
  15286. _clearTempArrs() {
  15287. TouchManager._oldArr.length = 0;
  15288. TouchManager._newArr.length = 0;
  15289. TouchManager._tEleArr.length = 0;
  15290. }
  15291. getTouchFromArr(touchID, arr) {
  15292. var i, len;
  15293. len = arr.length;
  15294. var tTouchO;
  15295. for (i = 0; i < len; i++) {
  15296. tTouchO = arr[i];
  15297. if (tTouchO.id == touchID) {
  15298. return tTouchO;
  15299. }
  15300. }
  15301. return null;
  15302. }
  15303. removeTouchFromArr(touchID, arr) {
  15304. var i;
  15305. for (i = arr.length - 1; i >= 0; i--) {
  15306. if (arr[i].id == touchID) {
  15307. arr.splice(i, 1);
  15308. }
  15309. }
  15310. }
  15311. createTouchO(ele, touchID) {
  15312. var rst;
  15313. rst = Pool.getItem("TouchData") || {};
  15314. rst.id = touchID;
  15315. rst.tar = ele;
  15316. return rst;
  15317. }
  15318. onMouseDown(ele, touchID, isLeft = false) {
  15319. if (!this.enable)
  15320. return;
  15321. var preO;
  15322. var tO;
  15323. var arrs;
  15324. preO = this.getTouchFromArr(touchID, this.preOvers);
  15325. arrs = this.getEles(ele, null, TouchManager._tEleArr);
  15326. if (!preO) {
  15327. tO = this.createTouchO(ele, touchID);
  15328. this.preOvers.push(tO);
  15329. }
  15330. else {
  15331. preO.tar = ele;
  15332. }
  15333. if (Browser.onMobile)
  15334. this.sendEvents(arrs, Event.MOUSE_OVER);
  15335. var preDowns;
  15336. preDowns = isLeft ? this.preDowns : this.preRightDowns;
  15337. preO = this.getTouchFromArr(touchID, preDowns);
  15338. if (!preO) {
  15339. tO = this.createTouchO(ele, touchID);
  15340. preDowns.push(tO);
  15341. }
  15342. else {
  15343. preO.tar = ele;
  15344. }
  15345. this.sendEvents(arrs, isLeft ? Event.MOUSE_DOWN : Event.RIGHT_MOUSE_DOWN);
  15346. this._clearTempArrs();
  15347. }
  15348. sendEvents(eles, type) {
  15349. var i, len;
  15350. len = eles.length;
  15351. this._event._stoped = false;
  15352. var _target;
  15353. _target = eles[0];
  15354. for (i = 0; i < len; i++) {
  15355. var tE = eles[i];
  15356. if (tE.destroyed)
  15357. return;
  15358. tE.event(type, this._event.setTo(type, tE, _target));
  15359. if (this._event._stoped)
  15360. break;
  15361. }
  15362. }
  15363. getEles(start, end = null, rst = null) {
  15364. if (!rst) {
  15365. rst = [];
  15366. }
  15367. else {
  15368. rst.length = 0;
  15369. }
  15370. while (start && start != end) {
  15371. rst.push(start);
  15372. start = start.parent;
  15373. }
  15374. return rst;
  15375. }
  15376. checkMouseOutAndOverOfMove(eleNew, elePre, touchID = 0) {
  15377. if (elePre == eleNew)
  15378. return;
  15379. var tar;
  15380. var arrs;
  15381. var i, len;
  15382. if (elePre.contains(eleNew)) {
  15383. arrs = this.getEles(eleNew, elePre, TouchManager._tEleArr);
  15384. this.sendEvents(arrs, Event.MOUSE_OVER);
  15385. }
  15386. else if (eleNew.contains(elePre)) {
  15387. arrs = this.getEles(elePre, eleNew, TouchManager._tEleArr);
  15388. this.sendEvents(arrs, Event.MOUSE_OUT);
  15389. }
  15390. else {
  15391. arrs = TouchManager._tEleArr;
  15392. arrs.length = 0;
  15393. var oldArr;
  15394. oldArr = this.getEles(elePre, null, TouchManager._oldArr);
  15395. var newArr;
  15396. newArr = this.getEles(eleNew, null, TouchManager._newArr);
  15397. len = oldArr.length;
  15398. var tIndex;
  15399. for (i = 0; i < len; i++) {
  15400. tar = oldArr[i];
  15401. tIndex = newArr.indexOf(tar);
  15402. if (tIndex >= 0) {
  15403. newArr.splice(tIndex, newArr.length - tIndex);
  15404. break;
  15405. }
  15406. else {
  15407. arrs.push(tar);
  15408. }
  15409. }
  15410. if (arrs.length > 0) {
  15411. this.sendEvents(arrs, Event.MOUSE_OUT);
  15412. }
  15413. if (newArr.length > 0) {
  15414. this.sendEvents(newArr, Event.MOUSE_OVER);
  15415. }
  15416. }
  15417. }
  15418. onMouseMove(ele, touchID) {
  15419. if (!this.enable)
  15420. return;
  15421. var preO;
  15422. preO = this.getTouchFromArr(touchID, this.preOvers);
  15423. var arrs;
  15424. if (!preO) {
  15425. arrs = this.getEles(ele, null, TouchManager._tEleArr);
  15426. this.sendEvents(arrs, Event.MOUSE_OVER);
  15427. this.preOvers.push(this.createTouchO(ele, touchID));
  15428. }
  15429. else {
  15430. this.checkMouseOutAndOverOfMove(ele, preO.tar);
  15431. preO.tar = ele;
  15432. arrs = this.getEles(ele, null, TouchManager._tEleArr);
  15433. }
  15434. this.sendEvents(arrs, Event.MOUSE_MOVE);
  15435. this._clearTempArrs();
  15436. }
  15437. getLastOvers() {
  15438. TouchManager._tEleArr.length = 0;
  15439. if (this.preOvers.length > 0 && this.preOvers[0].tar) {
  15440. return this.getEles(this.preOvers[0].tar, null, TouchManager._tEleArr);
  15441. }
  15442. TouchManager._tEleArr.push(ILaya.stage);
  15443. return TouchManager._tEleArr;
  15444. }
  15445. stageMouseOut() {
  15446. var lastOvers;
  15447. lastOvers = this.getLastOvers();
  15448. this.preOvers.length = 0;
  15449. this.sendEvents(lastOvers, Event.MOUSE_OUT);
  15450. }
  15451. onMouseUp(ele, touchID, isLeft = false) {
  15452. if (!this.enable)
  15453. return;
  15454. var preO;
  15455. var arrs;
  15456. var oldArr;
  15457. var i, len;
  15458. var tar;
  15459. var sendArr;
  15460. var onMobile = Browser.onMobile;
  15461. arrs = this.getEles(ele, null, TouchManager._tEleArr);
  15462. this.sendEvents(arrs, isLeft ? Event.MOUSE_UP : Event.RIGHT_MOUSE_UP);
  15463. var preDowns;
  15464. preDowns = isLeft ? this.preDowns : this.preRightDowns;
  15465. preO = this.getTouchFromArr(touchID, preDowns);
  15466. if (!preO) ;
  15467. else {
  15468. var isDouble;
  15469. var now = Browser.now();
  15470. isDouble = now - this._lastClickTime < 300;
  15471. this._lastClickTime = now;
  15472. if (ele == preO.tar) {
  15473. sendArr = arrs;
  15474. }
  15475. else {
  15476. oldArr = this.getEles(preO.tar, null, TouchManager._oldArr);
  15477. sendArr = TouchManager._newArr;
  15478. sendArr.length = 0;
  15479. len = oldArr.length;
  15480. for (i = 0; i < len; i++) {
  15481. tar = oldArr[i];
  15482. if (arrs.indexOf(tar) >= 0) {
  15483. sendArr.push(tar);
  15484. }
  15485. }
  15486. }
  15487. if (sendArr.length > 0) {
  15488. this.sendEvents(sendArr, isLeft ? Event.CLICK : Event.RIGHT_CLICK);
  15489. }
  15490. if (isLeft && isDouble) {
  15491. this.sendEvents(sendArr, Event.DOUBLE_CLICK);
  15492. }
  15493. this.removeTouchFromArr(touchID, preDowns);
  15494. preO.tar = null;
  15495. Pool.recover("TouchData", preO);
  15496. }
  15497. preO = this.getTouchFromArr(touchID, this.preOvers);
  15498. if (!preO) ;
  15499. else {
  15500. if (onMobile) {
  15501. sendArr = this.getEles(preO.tar, null, sendArr);
  15502. if (sendArr && sendArr.length > 0) {
  15503. this.sendEvents(sendArr, Event.MOUSE_OUT);
  15504. }
  15505. this.removeTouchFromArr(touchID, this.preOvers);
  15506. preO.tar = null;
  15507. Pool.recover("TouchData", preO);
  15508. }
  15509. }
  15510. this._clearTempArrs();
  15511. }
  15512. }
  15513. TouchManager.I = new TouchManager();
  15514. TouchManager._oldArr = [];
  15515. TouchManager._newArr = [];
  15516. TouchManager._tEleArr = [];
  15517. class MouseManager {
  15518. constructor() {
  15519. this.mouseX = 0;
  15520. this.mouseY = 0;
  15521. this.disableMouseEvent = false;
  15522. this.mouseDownTime = 0;
  15523. this.mouseMoveAccuracy = 2;
  15524. this._event = new Event();
  15525. this._captureSp = null;
  15526. this._captureChain = [];
  15527. this._captureExlusiveMode = false;
  15528. this._hitCaputreSp = false;
  15529. this._point = new Point();
  15530. this._rect = new Rectangle();
  15531. this._lastMoveTimer = 0;
  15532. this._prePoint = new Point();
  15533. this._touchIDs = {};
  15534. this._curTouchID = NaN;
  15535. this._id = 1;
  15536. }
  15537. __init__(stage, canvas) {
  15538. this._stage = stage;
  15539. var _this = this;
  15540. canvas.oncontextmenu = function (e) {
  15541. if (MouseManager.enabled)
  15542. return false;
  15543. };
  15544. canvas.addEventListener('mousedown', function (e) {
  15545. if (MouseManager.enabled) {
  15546. if (!Browser.onIE)
  15547. (e.cancelable) && (e.preventDefault());
  15548. _this.mouseDownTime = Browser.now();
  15549. _this.runEvent(e);
  15550. }
  15551. });
  15552. canvas.addEventListener('mouseup', function (e) {
  15553. if (MouseManager.enabled) {
  15554. (e.cancelable) && (e.preventDefault());
  15555. _this.mouseDownTime = -Browser.now();
  15556. _this.runEvent(e);
  15557. }
  15558. }, true);
  15559. canvas.addEventListener('mousemove', function (e) {
  15560. if (MouseManager.enabled) {
  15561. (e.cancelable) && (e.preventDefault());
  15562. var now = Browser.now();
  15563. if (now - _this._lastMoveTimer < 10)
  15564. return;
  15565. _this._lastMoveTimer = now;
  15566. _this.runEvent(e);
  15567. }
  15568. }, true);
  15569. canvas.addEventListener("mouseout", function (e) {
  15570. if (MouseManager.enabled)
  15571. _this.runEvent(e);
  15572. });
  15573. canvas.addEventListener("mouseover", function (e) {
  15574. if (MouseManager.enabled)
  15575. _this.runEvent(e);
  15576. });
  15577. canvas.addEventListener("touchstart", function (e) {
  15578. if (MouseManager.enabled) {
  15579. if (!MouseManager._isFirstTouch && !Input.isInputting)
  15580. (e.cancelable) && (e.preventDefault());
  15581. _this.mouseDownTime = Browser.now();
  15582. _this.runEvent(e);
  15583. }
  15584. });
  15585. canvas.addEventListener("touchend", function (e) {
  15586. if (MouseManager.enabled) {
  15587. if (!MouseManager._isFirstTouch && !Input.isInputting)
  15588. (e.cancelable) && (e.preventDefault());
  15589. MouseManager._isFirstTouch = false;
  15590. _this.mouseDownTime = -Browser.now();
  15591. _this.runEvent(e);
  15592. }
  15593. else {
  15594. _this._curTouchID = NaN;
  15595. }
  15596. }, true);
  15597. canvas.addEventListener("touchmove", function (e) {
  15598. if (MouseManager.enabled) {
  15599. (e.cancelable) && (e.preventDefault());
  15600. _this.runEvent(e);
  15601. }
  15602. }, true);
  15603. canvas.addEventListener("touchcancel", function (e) {
  15604. if (MouseManager.enabled) {
  15605. (e.cancelable) && (e.preventDefault());
  15606. _this.runEvent(e);
  15607. }
  15608. else {
  15609. _this._curTouchID = NaN;
  15610. }
  15611. }, true);
  15612. canvas.addEventListener('mousewheel', function (e) {
  15613. if (MouseManager.enabled)
  15614. _this.runEvent(e);
  15615. });
  15616. canvas.addEventListener('DOMMouseScroll', function (e) {
  15617. if (MouseManager.enabled)
  15618. _this.runEvent(e);
  15619. });
  15620. }
  15621. initEvent(e, nativeEvent = null) {
  15622. var _this = this;
  15623. _this._event._stoped = false;
  15624. _this._event.nativeEvent = nativeEvent || e;
  15625. _this._target = null;
  15626. this._point.setTo(e.pageX || e.clientX, e.pageY || e.clientY);
  15627. if (this._stage._canvasTransform) {
  15628. this._stage._canvasTransform.invertTransformPoint(this._point);
  15629. _this.mouseX = this._point.x;
  15630. _this.mouseY = this._point.y;
  15631. }
  15632. _this._event.touchId = e.identifier || 0;
  15633. this._tTouchID = _this._event.touchId;
  15634. var evt;
  15635. evt = TouchManager.I._event;
  15636. evt._stoped = false;
  15637. evt.nativeEvent = _this._event.nativeEvent;
  15638. evt.touchId = _this._event.touchId;
  15639. }
  15640. checkMouseWheel(e) {
  15641. this._event.delta = e.wheelDelta ? e.wheelDelta * 0.025 : -e.detail;
  15642. var _lastOvers = TouchManager.I.getLastOvers();
  15643. for (var i = 0, n = _lastOvers.length; i < n; i++) {
  15644. var ele = _lastOvers[i];
  15645. ele.event(Event.MOUSE_WHEEL, this._event.setTo(Event.MOUSE_WHEEL, ele, this._target));
  15646. }
  15647. }
  15648. onMouseMove(ele) {
  15649. TouchManager.I.onMouseMove(ele, this._tTouchID);
  15650. }
  15651. onMouseDown(ele) {
  15652. if (Input.isInputting && ILaya.stage.focus && ILaya.stage.focus["focus"] && !ILaya.stage.focus.contains(this._target)) {
  15653. var pre_input = ILaya.stage.focus['_tf'] || ILaya.stage.focus;
  15654. var new_input = ele['_tf'] || ele;
  15655. if (new_input instanceof Input && new_input.multiline == pre_input.multiline)
  15656. pre_input['_focusOut']();
  15657. else
  15658. pre_input.focus = false;
  15659. }
  15660. TouchManager.I.onMouseDown(ele, this._tTouchID, this._isLeftMouse);
  15661. }
  15662. onMouseUp(ele) {
  15663. TouchManager.I.onMouseUp(ele, this._tTouchID, this._isLeftMouse);
  15664. }
  15665. check(sp, mouseX, mouseY, callBack) {
  15666. this._point.setTo(mouseX, mouseY);
  15667. sp.fromParentPoint(this._point);
  15668. mouseX = this._point.x;
  15669. mouseY = this._point.y;
  15670. var scrollRect = sp._style.scrollRect;
  15671. if (scrollRect) {
  15672. this._rect.setTo(scrollRect.x, scrollRect.y, scrollRect.width, scrollRect.height);
  15673. if (!this._rect.contains(mouseX, mouseY))
  15674. return false;
  15675. }
  15676. if (!this.disableMouseEvent) {
  15677. if (sp.hitTestPrior && !sp.mouseThrough && !this.hitTest(sp, mouseX, mouseY)) {
  15678. return false;
  15679. }
  15680. for (var i = sp._children.length - 1; i > -1; i--) {
  15681. var child = sp._children[i];
  15682. if (!child.destroyed && child._mouseState > 1 && child._visible) {
  15683. if (this.check(child, mouseX, mouseY, callBack))
  15684. return true;
  15685. }
  15686. }
  15687. for (i = sp._extUIChild.length - 1; i >= 0; i--) {
  15688. var c = sp._extUIChild[i];
  15689. if (!c.destroyed && c._mouseState > 1 && c._visible) {
  15690. if (this.check(c, mouseX, mouseY, callBack))
  15691. return true;
  15692. }
  15693. }
  15694. }
  15695. var isHit = (sp.hitTestPrior && !sp.mouseThrough && !this.disableMouseEvent) ? true : this.hitTest(sp, mouseX, mouseY);
  15696. if (isHit) {
  15697. this._target = sp;
  15698. callBack.call(this, sp);
  15699. if (this._target == this._hitCaputreSp) {
  15700. this._hitCaputreSp = true;
  15701. }
  15702. }
  15703. else if (callBack === this.onMouseUp && sp === this._stage) {
  15704. this._target = this._stage;
  15705. callBack.call(this, this._target);
  15706. }
  15707. return isHit;
  15708. }
  15709. hitTest(sp, mouseX, mouseY) {
  15710. var isHit = false;
  15711. if (sp.scrollRect) {
  15712. mouseX -= sp._style.scrollRect.x;
  15713. mouseY -= sp._style.scrollRect.y;
  15714. }
  15715. var hitArea = sp._style.hitArea;
  15716. if (hitArea && hitArea._hit) {
  15717. return hitArea.contains(mouseX, mouseY);
  15718. }
  15719. if (sp.width > 0 && sp.height > 0 || sp.mouseThrough || hitArea) {
  15720. if (!sp.mouseThrough) {
  15721. isHit = (hitArea ? hitArea : this._rect.setTo(0, 0, sp.width, sp.height)).contains(mouseX, mouseY);
  15722. }
  15723. else {
  15724. isHit = sp.getGraphicBounds().contains(mouseX, mouseY);
  15725. }
  15726. }
  15727. return isHit;
  15728. }
  15729. _checkAllBaseUI(mousex, mousey, callback) {
  15730. var ret = this.handleExclusiveCapture(this.mouseX, this.mouseY, callback);
  15731. if (ret)
  15732. return true;
  15733. ret = this.check(this._stage, this.mouseX, this.mouseY, callback);
  15734. return this.handleCapture(this.mouseX, this.mouseY, callback) || ret;
  15735. }
  15736. check3DUI(mousex, mousey, callback) {
  15737. var uis = this._stage._3dUI;
  15738. var i = 0;
  15739. var ret = false;
  15740. for (; i < uis.length; i++) {
  15741. var curui = uis[i];
  15742. this._stage._curUIBase = curui;
  15743. if (!curui.destroyed && curui._mouseState > 1 && curui._visible) {
  15744. ret = ret || this.check(curui, this.mouseX, this.mouseY, callback);
  15745. }
  15746. }
  15747. this._stage._curUIBase = this._stage;
  15748. return ret;
  15749. }
  15750. handleExclusiveCapture(mousex, mousey, callback) {
  15751. if (this._captureExlusiveMode && this._captureSp && this._captureChain.length > 0) {
  15752. var cursp;
  15753. this._point.setTo(mousex, mousey);
  15754. for (var i = 0; i < this._captureChain.length; i++) {
  15755. cursp = this._captureChain[i];
  15756. cursp.fromParentPoint(this._point);
  15757. }
  15758. this._target = cursp;
  15759. callback.call(this, cursp);
  15760. return true;
  15761. }
  15762. return false;
  15763. }
  15764. handleCapture(mousex, mousey, callback) {
  15765. if (!this._hitCaputreSp && this._captureSp && this._captureChain.length > 0) {
  15766. var cursp;
  15767. this._point.setTo(mousex, mousey);
  15768. for (var i = 0; i < this._captureChain.length; i++) {
  15769. cursp = this._captureChain[i];
  15770. cursp.fromParentPoint(this._point);
  15771. }
  15772. this._target = cursp;
  15773. callback.call(this, cursp);
  15774. return true;
  15775. }
  15776. return false;
  15777. }
  15778. runEvent(evt) {
  15779. var i, n, touch;
  15780. if (evt.type !== 'mousemove')
  15781. this._prePoint.x = this._prePoint.y = -1000000;
  15782. switch (evt.type) {
  15783. case 'mousedown':
  15784. this._touchIDs[0] = this._id++;
  15785. if (!MouseManager._isTouchRespond) {
  15786. this._isLeftMouse = evt.button === 0;
  15787. this.initEvent(evt);
  15788. this._checkAllBaseUI(this.mouseX, this.mouseY, this.onMouseDown);
  15789. }
  15790. else
  15791. MouseManager._isTouchRespond = false;
  15792. break;
  15793. case 'mouseup':
  15794. this._isLeftMouse = evt.button === 0;
  15795. this.initEvent(evt);
  15796. this._checkAllBaseUI(this.mouseX, this.mouseY, this.onMouseUp);
  15797. break;
  15798. case 'mousemove':
  15799. if ((Math.abs(this._prePoint.x - evt.clientX) + Math.abs(this._prePoint.y - evt.clientY)) >= this.mouseMoveAccuracy) {
  15800. this._prePoint.x = evt.clientX;
  15801. this._prePoint.y = evt.clientY;
  15802. this.initEvent(evt);
  15803. this._checkAllBaseUI(this.mouseX, this.mouseY, this.onMouseMove);
  15804. }
  15805. break;
  15806. case "touchstart":
  15807. MouseManager._isTouchRespond = true;
  15808. this._isLeftMouse = true;
  15809. var touches = evt.changedTouches;
  15810. for (i = 0, n = touches.length; i < n; i++) {
  15811. touch = touches[i];
  15812. if (MouseManager.multiTouchEnabled || isNaN(this._curTouchID)) {
  15813. this._curTouchID = touch.identifier;
  15814. if (this._id % 200 === 0)
  15815. this._touchIDs = {};
  15816. this._touchIDs[touch.identifier] = this._id++;
  15817. this.initEvent(touch, evt);
  15818. this._checkAllBaseUI(this.mouseX, this.mouseY, this.onMouseDown);
  15819. }
  15820. }
  15821. break;
  15822. case "touchend":
  15823. case "touchcancel":
  15824. MouseManager._isTouchRespond = true;
  15825. this._isLeftMouse = true;
  15826. var touchends = evt.changedTouches;
  15827. for (i = 0, n = touchends.length; i < n; i++) {
  15828. touch = touchends[i];
  15829. if (MouseManager.multiTouchEnabled || touch.identifier == this._curTouchID) {
  15830. this._curTouchID = NaN;
  15831. this.initEvent(touch, evt);
  15832. var isChecked;
  15833. isChecked = this._checkAllBaseUI(this.mouseX, this.mouseY, this.onMouseUp);
  15834. if (!isChecked) {
  15835. this.onMouseUp(null);
  15836. }
  15837. }
  15838. }
  15839. break;
  15840. case "touchmove":
  15841. var touchemoves = evt.changedTouches;
  15842. for (i = 0, n = touchemoves.length; i < n; i++) {
  15843. touch = touchemoves[i];
  15844. if (MouseManager.multiTouchEnabled || touch.identifier == this._curTouchID) {
  15845. this.initEvent(touch, evt);
  15846. this._checkAllBaseUI(this.mouseX, this.mouseY, this.onMouseMove);
  15847. }
  15848. }
  15849. break;
  15850. case "wheel":
  15851. case "mousewheel":
  15852. case "DOMMouseScroll":
  15853. this.checkMouseWheel(evt);
  15854. break;
  15855. case "mouseout":
  15856. TouchManager.I.stageMouseOut();
  15857. break;
  15858. case "mouseover":
  15859. this._stage.event(Event.MOUSE_OVER, this._event.setTo(Event.MOUSE_OVER, this._stage, this._stage));
  15860. break;
  15861. }
  15862. }
  15863. setCapture(sp, exclusive = false) {
  15864. this._captureSp = sp;
  15865. this._captureExlusiveMode = exclusive;
  15866. this._captureChain.length = 0;
  15867. this._captureChain.push(sp);
  15868. var cursp = sp;
  15869. while (true) {
  15870. if (cursp == ILaya.stage)
  15871. break;
  15872. if (cursp == ILaya.stage._curUIBase)
  15873. break;
  15874. cursp = cursp.parent;
  15875. if (!cursp)
  15876. break;
  15877. this._captureChain.splice(0, 0, cursp);
  15878. }
  15879. }
  15880. releaseCapture() {
  15881. console.log('release capture');
  15882. this._captureSp = null;
  15883. }
  15884. }
  15885. MouseManager.instance = new MouseManager();
  15886. MouseManager.enabled = true;
  15887. MouseManager.multiTouchEnabled = true;
  15888. MouseManager._isFirstTouch = true;
  15889. class CallLater {
  15890. constructor() {
  15891. this._pool = [];
  15892. this._map = {};
  15893. this._laters = [];
  15894. }
  15895. _update() {
  15896. let laters = this._laters;
  15897. let len = laters.length;
  15898. if (len > 0) {
  15899. for (let i = 0, n = len - 1; i <= n; i++) {
  15900. let handler = laters[i];
  15901. this._map[handler.key] = null;
  15902. if (handler.method !== null) {
  15903. handler.run();
  15904. handler.clear();
  15905. }
  15906. this._pool.push(handler);
  15907. i === n && (n = laters.length - 1);
  15908. }
  15909. laters.length = 0;
  15910. }
  15911. }
  15912. _getHandler(caller, method) {
  15913. var cid = caller ? caller.$_GID || (caller.$_GID = ILaya.Utils.getGID()) : 0;
  15914. var mid = method.$_TID || (method.$_TID = (ILaya.Timer._mid++));
  15915. return this._map[cid + '.' + mid];
  15916. }
  15917. callLater(caller, method, args = null) {
  15918. if (this._getHandler(caller, method) == null) {
  15919. let handler;
  15920. if (this._pool.length)
  15921. handler = this._pool.pop();
  15922. else
  15923. handler = new LaterHandler();
  15924. handler.caller = caller;
  15925. handler.method = method;
  15926. handler.args = args;
  15927. var cid = caller ? caller.$_GID : 0;
  15928. var mid = method["$_TID"];
  15929. handler.key = cid + '.' + mid;
  15930. this._map[handler.key] = handler;
  15931. this._laters.push(handler);
  15932. }
  15933. }
  15934. runCallLater(caller, method) {
  15935. var handler = this._getHandler(caller, method);
  15936. if (handler && handler.method != null) {
  15937. this._map[handler.key] = null;
  15938. handler.run();
  15939. handler.clear();
  15940. }
  15941. }
  15942. }
  15943. CallLater.I = new CallLater();
  15944. class LaterHandler {
  15945. clear() {
  15946. this.caller = null;
  15947. this.method = null;
  15948. this.args = null;
  15949. }
  15950. run() {
  15951. var caller = this.caller;
  15952. if (caller && caller.destroyed)
  15953. return this.clear();
  15954. var method = this.method;
  15955. var args = this.args;
  15956. if (method == null)
  15957. return;
  15958. args ? method.apply(caller, args) : method.call(caller);
  15959. }
  15960. }
  15961. class RunDriver {
  15962. }
  15963. RunDriver.createShaderCondition = function (conditionScript) {
  15964. var fn = "(function() {return " + conditionScript + ";})";
  15965. return window.Laya._runScript(fn);
  15966. };
  15967. RunDriver.changeWebGLSize = function (w, h) {
  15968. WebGL.onStageResize(w, h);
  15969. };
  15970. class Stage extends Sprite {
  15971. constructor() {
  15972. super();
  15973. this.offset = new Point();
  15974. this._frameRate = "fast";
  15975. this.designWidth = 0;
  15976. this.designHeight = 0;
  15977. this.canvasRotation = false;
  15978. this.canvasDegree = 0;
  15979. this.renderingEnabled = true;
  15980. this.screenAdaptationEnabled = true;
  15981. this._canvasTransform = new Matrix();
  15982. this._screenMode = "none";
  15983. this._scaleMode = "noscale";
  15984. this._alignV = "top";
  15985. this._alignH = "left";
  15986. this._bgColor = "black";
  15987. this._mouseMoveTime = 0;
  15988. this._renderCount = 0;
  15989. this._safariOffsetY = 0;
  15990. this._frameStartTime = 0;
  15991. this._previousOrientation = Browser.window.orientation;
  15992. this._wgColor = [0, 0, 0, 1];
  15993. this._scene3Ds = [];
  15994. this._globalRepaintSet = false;
  15995. this._globalRepaintGet = false;
  15996. this._3dUI = [];
  15997. this._curUIBase = null;
  15998. this.useRetinalCanvas = false;
  15999. super.set_transform(this._createTransform());
  16000. this.mouseEnabled = true;
  16001. this.hitTestPrior = true;
  16002. this.autoSize = false;
  16003. this._setBit(Const.DISPLAYED_INSTAGE, true);
  16004. this._setBit(Const.ACTIVE_INHIERARCHY, true);
  16005. this._isFocused = true;
  16006. this._isVisibility = true;
  16007. this.useRetinalCanvas = Config.useRetinalCanvas;
  16008. var window = Browser.window;
  16009. window.addEventListener("focus", () => {
  16010. this._isFocused = true;
  16011. this.event(Event.FOCUS);
  16012. this.event(Event.FOCUS_CHANGE);
  16013. });
  16014. window.addEventListener("blur", () => {
  16015. this._isFocused = false;
  16016. this.event(Event.BLUR);
  16017. this.event(Event.FOCUS_CHANGE);
  16018. if (this._isInputting())
  16019. Input["inputElement"].target.focus = false;
  16020. });
  16021. var state = "visibilityState", visibilityChange = "visibilitychange";
  16022. var document = window.document;
  16023. if (typeof document.hidden !== "undefined") {
  16024. visibilityChange = "visibilitychange";
  16025. state = "visibilityState";
  16026. }
  16027. else if (typeof document.mozHidden !== "undefined") {
  16028. visibilityChange = "mozvisibilitychange";
  16029. state = "mozVisibilityState";
  16030. }
  16031. else if (typeof document.msHidden !== "undefined") {
  16032. visibilityChange = "msvisibilitychange";
  16033. state = "msVisibilityState";
  16034. }
  16035. else if (typeof document.webkitHidden !== "undefined") {
  16036. visibilityChange = "webkitvisibilitychange";
  16037. state = "webkitVisibilityState";
  16038. }
  16039. window.document.addEventListener(visibilityChange, () => {
  16040. if (Browser.document[state] == "hidden") {
  16041. this._isVisibility = false;
  16042. if (this._isInputting())
  16043. Input["inputElement"].target.focus = false;
  16044. }
  16045. else {
  16046. this._isVisibility = true;
  16047. }
  16048. this.renderingEnabled = this._isVisibility;
  16049. this.event(Event.VISIBILITY_CHANGE);
  16050. });
  16051. window.addEventListener("resize", () => {
  16052. var orientation = Browser.window.orientation;
  16053. if (orientation != null && orientation != this._previousOrientation && this._isInputting()) {
  16054. Input["inputElement"].target.focus = false;
  16055. }
  16056. this._previousOrientation = orientation;
  16057. if (this._isInputting())
  16058. return;
  16059. if (Browser.onSafari)
  16060. this._safariOffsetY = (Browser.window.__innerHeight || Browser.document.body.clientHeight || Browser.document.documentElement.clientHeight) - Browser.window.innerHeight;
  16061. this._resetCanvas();
  16062. });
  16063. window.addEventListener("orientationchange", (e) => {
  16064. this._resetCanvas();
  16065. });
  16066. this.on(Event.MOUSE_MOVE, this, this._onmouseMove);
  16067. if (Browser.onMobile)
  16068. this.on(Event.MOUSE_DOWN, this, this._onmouseMove);
  16069. }
  16070. _isInputting() {
  16071. return (Browser.onMobile && Input.isInputting);
  16072. }
  16073. set width(value) {
  16074. this.designWidth = value;
  16075. super.set_width(value);
  16076. ILaya.systemTimer.callLater(this, this._changeCanvasSize);
  16077. }
  16078. get width() {
  16079. return super.get_width();
  16080. }
  16081. set height(value) {
  16082. this.designHeight = value;
  16083. super.set_height(value);
  16084. ILaya.systemTimer.callLater(this, this._changeCanvasSize);
  16085. }
  16086. get height() {
  16087. return super.get_height();
  16088. }
  16089. set transform(value) {
  16090. super.set_transform(value);
  16091. }
  16092. get transform() {
  16093. if (this._tfChanged)
  16094. this._adjustTransform();
  16095. return (this._transform = this._transform || this._createTransform());
  16096. }
  16097. get isFocused() {
  16098. return this._isFocused;
  16099. }
  16100. get isVisibility() {
  16101. return this._isVisibility;
  16102. }
  16103. _changeCanvasSize() {
  16104. this.setScreenSize(Browser.clientWidth * Browser.pixelRatio, Browser.clientHeight * Browser.pixelRatio);
  16105. }
  16106. _resetCanvas() {
  16107. if (!this.screenAdaptationEnabled)
  16108. return;
  16109. this._changeCanvasSize();
  16110. }
  16111. setScreenSize(screenWidth, screenHeight) {
  16112. var rotation = false;
  16113. if (this._screenMode !== Stage.SCREEN_NONE) {
  16114. var screenType = screenWidth / screenHeight < 1 ? Stage.SCREEN_VERTICAL : Stage.SCREEN_HORIZONTAL;
  16115. rotation = screenType !== this._screenMode;
  16116. if (rotation) {
  16117. var temp = screenHeight;
  16118. screenHeight = screenWidth;
  16119. screenWidth = temp;
  16120. }
  16121. }
  16122. this.canvasRotation = rotation;
  16123. var canvas = Render._mainCanvas;
  16124. var canvasStyle = canvas.source.style;
  16125. var mat = this._canvasTransform.identity();
  16126. var scaleMode = this._scaleMode;
  16127. var scaleX = screenWidth / this.designWidth;
  16128. var scaleY = screenHeight / this.designHeight;
  16129. var canvasWidth = this.useRetinalCanvas ? screenWidth : this.designWidth;
  16130. var canvasHeight = this.useRetinalCanvas ? screenHeight : this.designHeight;
  16131. var realWidth = screenWidth;
  16132. var realHeight = screenHeight;
  16133. var pixelRatio = Browser.pixelRatio;
  16134. this._width = this.designWidth;
  16135. this._height = this.designHeight;
  16136. switch (scaleMode) {
  16137. case Stage.SCALE_NOSCALE:
  16138. scaleX = scaleY = 1;
  16139. realWidth = this.designWidth;
  16140. realHeight = this.designHeight;
  16141. break;
  16142. case Stage.SCALE_SHOWALL:
  16143. scaleX = scaleY = Math.min(scaleX, scaleY);
  16144. canvasWidth = realWidth = Math.round(this.designWidth * scaleX);
  16145. canvasHeight = realHeight = Math.round(this.designHeight * scaleY);
  16146. break;
  16147. case Stage.SCALE_NOBORDER:
  16148. scaleX = scaleY = Math.max(scaleX, scaleY);
  16149. realWidth = Math.round(this.designWidth * scaleX);
  16150. realHeight = Math.round(this.designHeight * scaleY);
  16151. break;
  16152. case Stage.SCALE_FULL:
  16153. scaleX = scaleY = 1;
  16154. this._width = canvasWidth = screenWidth;
  16155. this._height = canvasHeight = screenHeight;
  16156. break;
  16157. case Stage.SCALE_FIXED_WIDTH:
  16158. scaleY = scaleX;
  16159. this._height = canvasHeight = Math.round(screenHeight / scaleX);
  16160. break;
  16161. case Stage.SCALE_FIXED_HEIGHT:
  16162. scaleX = scaleY;
  16163. this._width = canvasWidth = Math.round(screenWidth / scaleY);
  16164. break;
  16165. case Stage.SCALE_FIXED_AUTO:
  16166. if ((screenWidth / screenHeight) < (this.designWidth / this.designHeight)) {
  16167. scaleY = scaleX;
  16168. this._height = canvasHeight = Math.round(screenHeight / scaleX);
  16169. }
  16170. else {
  16171. scaleX = scaleY;
  16172. this._width = canvasWidth = Math.round(screenWidth / scaleY);
  16173. }
  16174. break;
  16175. }
  16176. if (this.useRetinalCanvas) {
  16177. canvasWidth = screenWidth;
  16178. canvasHeight = screenHeight;
  16179. }
  16180. scaleX *= this.scaleX;
  16181. scaleY *= this.scaleY;
  16182. if (scaleX === 1 && scaleY === 1) {
  16183. this.transform.identity();
  16184. }
  16185. else {
  16186. this.transform.a = this._formatData(scaleX / (realWidth / canvasWidth));
  16187. this.transform.d = this._formatData(scaleY / (realHeight / canvasHeight));
  16188. }
  16189. canvas.size(canvasWidth, canvasHeight);
  16190. RunDriver.changeWebGLSize(canvasWidth, canvasHeight);
  16191. mat.scale(realWidth / canvasWidth / pixelRatio, realHeight / canvasHeight / pixelRatio);
  16192. if (this._alignH === Stage.ALIGN_LEFT)
  16193. this.offset.x = 0;
  16194. else if (this._alignH === Stage.ALIGN_RIGHT)
  16195. this.offset.x = screenWidth - realWidth;
  16196. else
  16197. this.offset.x = (screenWidth - realWidth) * 0.5 / pixelRatio;
  16198. if (this._alignV === Stage.ALIGN_TOP)
  16199. this.offset.y = 0;
  16200. else if (this._alignV === Stage.ALIGN_BOTTOM)
  16201. this.offset.y = screenHeight - realHeight;
  16202. else
  16203. this.offset.y = (screenHeight - realHeight) * 0.5 / pixelRatio;
  16204. this.offset.x = Math.round(this.offset.x);
  16205. this.offset.y = Math.round(this.offset.y);
  16206. mat.translate(this.offset.x, this.offset.y);
  16207. if (this._safariOffsetY)
  16208. mat.translate(0, this._safariOffsetY);
  16209. this.canvasDegree = 0;
  16210. if (rotation) {
  16211. if (this._screenMode === Stage.SCREEN_HORIZONTAL) {
  16212. mat.rotate(Math.PI / 2);
  16213. mat.translate(screenHeight / pixelRatio, 0);
  16214. this.canvasDegree = 90;
  16215. }
  16216. else {
  16217. mat.rotate(-Math.PI / 2);
  16218. mat.translate(0, screenWidth / pixelRatio);
  16219. this.canvasDegree = -90;
  16220. }
  16221. }
  16222. mat.a = this._formatData(mat.a);
  16223. mat.d = this._formatData(mat.d);
  16224. mat.tx = this._formatData(mat.tx);
  16225. mat.ty = this._formatData(mat.ty);
  16226. super.set_transform(this.transform);
  16227. canvasStyle.transformOrigin = canvasStyle.webkitTransformOrigin = canvasStyle.msTransformOrigin = canvasStyle.mozTransformOrigin = canvasStyle.oTransformOrigin = "0px 0px 0px";
  16228. canvasStyle.transform = canvasStyle.webkitTransform = canvasStyle.msTransform = canvasStyle.mozTransform = canvasStyle.oTransform = "matrix(" + mat.toString() + ")";
  16229. if (this._safariOffsetY)
  16230. mat.translate(0, -this._safariOffsetY);
  16231. mat.translate(parseInt(canvasStyle.left) || 0, parseInt(canvasStyle.top) || 0);
  16232. this.visible = true;
  16233. this._repaint |= SpriteConst.REPAINT_CACHE;
  16234. this.event(Event.RESIZE);
  16235. }
  16236. _formatData(value) {
  16237. if (Math.abs(value) < 0.000001)
  16238. return 0;
  16239. if (Math.abs(1 - value) < 0.001)
  16240. return value > 0 ? 1 : -1;
  16241. return value;
  16242. }
  16243. get scaleMode() {
  16244. return this._scaleMode;
  16245. }
  16246. set scaleMode(value) {
  16247. this._scaleMode = value;
  16248. ILaya.systemTimer.callLater(this, this._changeCanvasSize);
  16249. }
  16250. get alignH() {
  16251. return this._alignH;
  16252. }
  16253. set alignH(value) {
  16254. this._alignH = value;
  16255. ILaya.systemTimer.callLater(this, this._changeCanvasSize);
  16256. }
  16257. get alignV() {
  16258. return this._alignV;
  16259. }
  16260. set alignV(value) {
  16261. this._alignV = value;
  16262. ILaya.systemTimer.callLater(this, this._changeCanvasSize);
  16263. }
  16264. get bgColor() {
  16265. return this._bgColor;
  16266. }
  16267. set bgColor(value) {
  16268. this._bgColor = value;
  16269. if (value)
  16270. this._wgColor = ColorUtils.create(value).arrColor;
  16271. else
  16272. this._wgColor = null;
  16273. if (value) {
  16274. Render.canvas.style.background = value;
  16275. }
  16276. else {
  16277. Render.canvas.style.background = "none";
  16278. }
  16279. }
  16280. get mouseX() {
  16281. return Math.round(MouseManager.instance.mouseX / this.clientScaleX);
  16282. }
  16283. get mouseY() {
  16284. return Math.round(MouseManager.instance.mouseY / this.clientScaleY);
  16285. }
  16286. getMousePoint() {
  16287. return Point.TEMP.setTo(this.mouseX, this.mouseY);
  16288. }
  16289. get clientScaleX() {
  16290. return this._transform ? this._transform.getScaleX() : 1;
  16291. }
  16292. get clientScaleY() {
  16293. return this._transform ? this._transform.getScaleY() : 1;
  16294. }
  16295. get screenMode() {
  16296. return this._screenMode;
  16297. }
  16298. set screenMode(value) {
  16299. this._screenMode = value;
  16300. }
  16301. repaint(type = SpriteConst.REPAINT_CACHE) {
  16302. this._repaint |= type;
  16303. }
  16304. parentRepaint(type = SpriteConst.REPAINT_CACHE) {
  16305. }
  16306. _loop() {
  16307. this._globalRepaintGet = this._globalRepaintSet;
  16308. this._globalRepaintSet = false;
  16309. this.render(Render._context, 0, 0);
  16310. return true;
  16311. }
  16312. getFrameTm() {
  16313. return this._frameStartTime;
  16314. }
  16315. _onmouseMove(e) {
  16316. this._mouseMoveTime = Browser.now();
  16317. }
  16318. getTimeFromFrameStart() {
  16319. return Browser.now() - this._frameStartTime;
  16320. }
  16321. set visible(value) {
  16322. if (this.visible !== value) {
  16323. super.set_visible(value);
  16324. var style = Render._mainCanvas.source.style;
  16325. style.visibility = value ? "visible" : "hidden";
  16326. }
  16327. }
  16328. get visible() {
  16329. return super.visible;
  16330. }
  16331. render(context, x, y) {
  16332. if (window.conch) {
  16333. this.renderToNative(context, x, y);
  16334. return;
  16335. }
  16336. Stage._dbgSprite.graphics.clear();
  16337. if (this._frameRate === Stage.FRAME_SLEEP) {
  16338. var now = Browser.now();
  16339. if (now - this._frameStartTime >= 1000)
  16340. this._frameStartTime = now;
  16341. else
  16342. return;
  16343. }
  16344. else {
  16345. if (!this._visible) {
  16346. this._renderCount++;
  16347. if (this._renderCount % 5 === 0) {
  16348. CallLater.I._update();
  16349. Stat.loopCount++;
  16350. RenderInfo.loopCount = Stat.loopCount;
  16351. this._updateTimers();
  16352. }
  16353. return;
  16354. }
  16355. this._frameStartTime = Browser.now();
  16356. RenderInfo.loopStTm = this._frameStartTime;
  16357. }
  16358. this._renderCount++;
  16359. var frameMode = this._frameRate === Stage.FRAME_MOUSE ? (((this._frameStartTime - this._mouseMoveTime) < 2000) ? Stage.FRAME_FAST : Stage.FRAME_SLOW) : this._frameRate;
  16360. var isFastMode = (frameMode !== Stage.FRAME_SLOW);
  16361. var isDoubleLoop = (this._renderCount % 2 === 0);
  16362. Stat.renderSlow = !isFastMode;
  16363. if (!isFastMode && !isDoubleLoop)
  16364. return;
  16365. CallLater.I._update();
  16366. Stat.loopCount++;
  16367. RenderInfo.loopCount = Stat.loopCount;
  16368. if (this.renderingEnabled) {
  16369. for (var i = 0, n = this._scene3Ds.length; i < n; i++)
  16370. this._scene3Ds[i]._update();
  16371. context.clear();
  16372. super.render(context, x, y);
  16373. Stat._StatRender.renderNotCanvas(context, x, y);
  16374. }
  16375. Stage._dbgSprite.render(context, 0, 0);
  16376. if (this.renderingEnabled) {
  16377. Stage.clear(this._bgColor);
  16378. context.flush();
  16379. VectorGraphManager.instance && VectorGraphManager.getInstance().endDispose();
  16380. }
  16381. this._updateTimers();
  16382. }
  16383. renderToNative(context, x, y) {
  16384. this._renderCount++;
  16385. if (!this._visible) {
  16386. if (this._renderCount % 5 === 0) {
  16387. CallLater.I._update();
  16388. Stat.loopCount++;
  16389. RenderInfo.loopCount = Stat.loopCount;
  16390. this._updateTimers();
  16391. }
  16392. return;
  16393. }
  16394. CallLater.I._update();
  16395. Stat.loopCount++;
  16396. RenderInfo.loopCount = Stat.loopCount;
  16397. if (this.renderingEnabled) {
  16398. for (var i = 0, n = this._scene3Ds.length; i < n; i++)
  16399. this._scene3Ds[i]._update();
  16400. context.clear();
  16401. super.render(context, x, y);
  16402. Stat._StatRender.renderNotCanvas(context, x, y);
  16403. }
  16404. if (this.renderingEnabled) {
  16405. Stage.clear(this._bgColor);
  16406. context.flush();
  16407. VectorGraphManager.instance && VectorGraphManager.getInstance().endDispose();
  16408. }
  16409. this._updateTimers();
  16410. }
  16411. _updateTimers() {
  16412. ILaya.systemTimer._update();
  16413. ILaya.startTimer._update();
  16414. ILaya.physicsTimer._update();
  16415. ILaya.updateTimer._update();
  16416. ILaya.lateTimer._update();
  16417. ILaya.timer._update();
  16418. }
  16419. set fullScreenEnabled(value) {
  16420. var document = Browser.document;
  16421. var canvas = Render.canvas;
  16422. if (value) {
  16423. canvas.addEventListener('mousedown', this._requestFullscreen);
  16424. canvas.addEventListener('touchstart', this._requestFullscreen);
  16425. document.addEventListener("fullscreenchange", this._fullScreenChanged);
  16426. document.addEventListener("mozfullscreenchange", this._fullScreenChanged);
  16427. document.addEventListener("webkitfullscreenchange", this._fullScreenChanged);
  16428. document.addEventListener("msfullscreenchange", this._fullScreenChanged);
  16429. }
  16430. else {
  16431. canvas.removeEventListener('mousedown', this._requestFullscreen);
  16432. canvas.removeEventListener('touchstart', this._requestFullscreen);
  16433. document.removeEventListener("fullscreenchange", this._fullScreenChanged);
  16434. document.removeEventListener("mozfullscreenchange", this._fullScreenChanged);
  16435. document.removeEventListener("webkitfullscreenchange", this._fullScreenChanged);
  16436. document.removeEventListener("msfullscreenchange", this._fullScreenChanged);
  16437. }
  16438. }
  16439. get frameRate() {
  16440. if (!ILaya.Render.isConchApp) {
  16441. return this._frameRate;
  16442. }
  16443. else {
  16444. return this._frameRateNative;
  16445. }
  16446. }
  16447. set frameRate(value) {
  16448. if (!ILaya.Render.isConchApp) {
  16449. this._frameRate = value;
  16450. }
  16451. else {
  16452. var c = window.conch;
  16453. switch (value) {
  16454. case Stage.FRAME_FAST:
  16455. c.config.setLimitFPS(60);
  16456. break;
  16457. case Stage.FRAME_MOUSE:
  16458. c.config.setMouseFrame(2000);
  16459. break;
  16460. case Stage.FRAME_SLOW:
  16461. c.config.setSlowFrame(true);
  16462. break;
  16463. case Stage.FRAME_SLEEP:
  16464. c.config.setLimitFPS(1);
  16465. break;
  16466. }
  16467. this._frameRateNative = value;
  16468. }
  16469. }
  16470. _requestFullscreen() {
  16471. var element = Browser.document.documentElement;
  16472. if (element.requestFullscreen) {
  16473. element.requestFullscreen();
  16474. }
  16475. else if (element.mozRequestFullScreen) {
  16476. element.mozRequestFullScreen();
  16477. }
  16478. else if (element.webkitRequestFullscreen) {
  16479. element.webkitRequestFullscreen();
  16480. }
  16481. else if (element.msRequestFullscreen) {
  16482. element.msRequestFullscreen();
  16483. }
  16484. }
  16485. _fullScreenChanged() {
  16486. ILaya.stage.event(Event.FULL_SCREEN_CHANGE);
  16487. }
  16488. exitFullscreen() {
  16489. var document = Browser.document;
  16490. if (document.exitFullscreen) {
  16491. document.exitFullscreen();
  16492. }
  16493. else if (document.mozCancelFullScreen) {
  16494. document.mozCancelFullScreen();
  16495. }
  16496. else if (document.webkitExitFullscreen) {
  16497. document.webkitExitFullscreen();
  16498. }
  16499. }
  16500. isGlobalRepaint() {
  16501. return this._globalRepaintGet;
  16502. }
  16503. setGlobalRepaint() {
  16504. this._globalRepaintSet = true;
  16505. }
  16506. add3DUI(uibase) {
  16507. var uiroot = uibase.rootView;
  16508. if (this._3dUI.indexOf(uiroot) >= 0)
  16509. return;
  16510. this._3dUI.push(uiroot);
  16511. }
  16512. remove3DUI(uibase) {
  16513. var uiroot = uibase.rootView;
  16514. var p = this._3dUI.indexOf(uiroot);
  16515. if (p >= 0) {
  16516. this._3dUI.splice(p, 1);
  16517. return true;
  16518. }
  16519. return false;
  16520. }
  16521. }
  16522. Stage.SCALE_NOSCALE = "noscale";
  16523. Stage.SCALE_EXACTFIT = "exactfit";
  16524. Stage.SCALE_SHOWALL = "showall";
  16525. Stage.SCALE_NOBORDER = "noborder";
  16526. Stage.SCALE_FULL = "full";
  16527. Stage.SCALE_FIXED_WIDTH = "fixedwidth";
  16528. Stage.SCALE_FIXED_HEIGHT = "fixedheight";
  16529. Stage.SCALE_FIXED_AUTO = "fixedauto";
  16530. Stage.ALIGN_LEFT = "left";
  16531. Stage.ALIGN_RIGHT = "right";
  16532. Stage.ALIGN_CENTER = "center";
  16533. Stage.ALIGN_TOP = "top";
  16534. Stage.ALIGN_MIDDLE = "middle";
  16535. Stage.ALIGN_BOTTOM = "bottom";
  16536. Stage.SCREEN_NONE = "none";
  16537. Stage.SCREEN_HORIZONTAL = "horizontal";
  16538. Stage.SCREEN_VERTICAL = "vertical";
  16539. Stage.FRAME_FAST = "fast";
  16540. Stage.FRAME_SLOW = "slow";
  16541. Stage.FRAME_MOUSE = "mouse";
  16542. Stage.FRAME_SLEEP = "sleep";
  16543. Stage._dbgSprite = new Sprite();
  16544. Stage.clear = function (value) {
  16545. Context.set2DRenderConfig();
  16546. var gl = LayaGL.instance;
  16547. RenderState2D.worldScissorTest && gl.disable(gl.SCISSOR_TEST);
  16548. var ctx = Render.context;
  16549. var c = (ctx._submits._length == 0 || Config.preserveDrawingBuffer) ? ColorUtils.create(value).arrColor : window.Laya.stage._wgColor;
  16550. if (c)
  16551. ctx.clearBG(c[0], c[1], c[2], c[3]);
  16552. else
  16553. ctx.clearBG(0, 0, 0, 0);
  16554. RenderState2D.clear();
  16555. };
  16556. ClassUtils.regClass("laya.display.Stage", Stage);
  16557. ClassUtils.regClass("Laya.Stage", Stage);
  16558. class KeyBoardManager {
  16559. static __init__() {
  16560. KeyBoardManager._addEvent("keydown");
  16561. KeyBoardManager._addEvent("keypress");
  16562. KeyBoardManager._addEvent("keyup");
  16563. }
  16564. static _addEvent(type) {
  16565. ILaya.Browser.document.addEventListener(type, function (e) {
  16566. KeyBoardManager._dispatch(e, type);
  16567. }, true);
  16568. }
  16569. static _dispatch(e, type) {
  16570. if (!KeyBoardManager.enabled)
  16571. return;
  16572. KeyBoardManager._event._stoped = false;
  16573. KeyBoardManager._event.nativeEvent = e;
  16574. KeyBoardManager._event.keyCode = e.keyCode || e.which || e.charCode;
  16575. if (type === "keydown")
  16576. KeyBoardManager._pressKeys[KeyBoardManager._event.keyCode] = true;
  16577. else if (type === "keyup")
  16578. KeyBoardManager._pressKeys[KeyBoardManager._event.keyCode] = null;
  16579. var target = (ILaya.stage.focus && (ILaya.stage.focus.event != null) && ILaya.stage.focus.displayedInStage) ? ILaya.stage.focus : ILaya.stage;
  16580. var ct = target;
  16581. while (ct) {
  16582. ct.event(type, KeyBoardManager._event.setTo(type, ct, target));
  16583. ct = ct.parent;
  16584. }
  16585. }
  16586. static hasKeyDown(key) {
  16587. return KeyBoardManager._pressKeys[key];
  16588. }
  16589. }
  16590. KeyBoardManager._pressKeys = {};
  16591. KeyBoardManager.enabled = true;
  16592. KeyBoardManager._event = new Event();
  16593. class SoundChannel extends EventDispatcher {
  16594. constructor() {
  16595. super(...arguments);
  16596. this.isStopped = false;
  16597. }
  16598. set volume(v) {
  16599. }
  16600. get volume() {
  16601. return 1;
  16602. }
  16603. get position() {
  16604. return 0;
  16605. }
  16606. get duration() {
  16607. return 0;
  16608. }
  16609. play() {
  16610. }
  16611. stop() {
  16612. if (this.completeHandler)
  16613. this.completeHandler.run();
  16614. }
  16615. pause() {
  16616. }
  16617. resume() {
  16618. }
  16619. __runComplete(handler) {
  16620. if (handler) {
  16621. handler.run();
  16622. }
  16623. }
  16624. }
  16625. class AudioSoundChannel extends SoundChannel {
  16626. constructor(audio) {
  16627. super();
  16628. this._audio = null;
  16629. this._onEnd = this.__onEnd.bind(this);
  16630. this._resumePlay = this.__resumePlay.bind(this);
  16631. audio.addEventListener("ended", this._onEnd);
  16632. this._audio = audio;
  16633. }
  16634. __onEnd(evt) {
  16635. if (this.loops == 1) {
  16636. if (this.completeHandler) {
  16637. ILaya.systemTimer.once(10, this, this.__runComplete, [this.completeHandler], false);
  16638. this.completeHandler = null;
  16639. }
  16640. this.stop();
  16641. this.event(Event.COMPLETE);
  16642. return;
  16643. }
  16644. if (this.loops > 0) {
  16645. this.loops--;
  16646. }
  16647. this.startTime = 0;
  16648. this.play();
  16649. }
  16650. __resumePlay() {
  16651. if (this._audio)
  16652. this._audio.removeEventListener("canplay", this._resumePlay);
  16653. if (this.isStopped)
  16654. return;
  16655. try {
  16656. this._audio.currentTime = this.startTime;
  16657. Browser.container.appendChild(this._audio);
  16658. this._audio.play();
  16659. }
  16660. catch (e) {
  16661. this.event(Event.ERROR);
  16662. }
  16663. }
  16664. play() {
  16665. this.isStopped = false;
  16666. try {
  16667. this._audio.playbackRate = ILaya.SoundManager.playbackRate;
  16668. this._audio.currentTime = this.startTime;
  16669. }
  16670. catch (e) {
  16671. this._audio.addEventListener("canplay", this._resumePlay);
  16672. return;
  16673. }
  16674. ILaya.SoundManager.addChannel(this);
  16675. Browser.container.appendChild(this._audio);
  16676. if ("play" in this._audio)
  16677. this._audio.play();
  16678. }
  16679. get position() {
  16680. if (!this._audio)
  16681. return 0;
  16682. return this._audio.currentTime;
  16683. }
  16684. get duration() {
  16685. if (!this._audio)
  16686. return 0;
  16687. return this._audio.duration;
  16688. }
  16689. stop() {
  16690. super.stop();
  16691. this.isStopped = true;
  16692. ILaya.SoundManager.removeChannel(this);
  16693. this.completeHandler = null;
  16694. if (!this._audio)
  16695. return;
  16696. if ("pause" in this._audio)
  16697. if (ILaya.Render.isConchApp) {
  16698. this._audio.stop();
  16699. }
  16700. this._audio.pause();
  16701. this._audio.removeEventListener("ended", this._onEnd);
  16702. this._audio.removeEventListener("canplay", this._resumePlay);
  16703. if (!ILaya.Browser.onIE) {
  16704. if (this._audio != ILaya.AudioSound._musicAudio) {
  16705. ILaya.Pool.recover("audio:" + this.url, this._audio);
  16706. }
  16707. }
  16708. Browser.removeElement(this._audio);
  16709. this._audio = null;
  16710. if (ILaya.SoundManager.autoReleaseSound)
  16711. ILaya.SoundManager.disposeSoundLater(this.url);
  16712. }
  16713. pause() {
  16714. this.isStopped = true;
  16715. ILaya.SoundManager.removeChannel(this);
  16716. if ("pause" in this._audio)
  16717. this._audio.pause();
  16718. if (ILaya.SoundManager.autoReleaseSound)
  16719. ILaya.SoundManager.disposeSoundLater(this.url);
  16720. }
  16721. resume() {
  16722. if (!this._audio)
  16723. return;
  16724. this.isStopped = false;
  16725. ILaya.SoundManager.addChannel(this);
  16726. if ("play" in this._audio)
  16727. this._audio.play();
  16728. }
  16729. set volume(v) {
  16730. if (!this._audio)
  16731. return;
  16732. this._audio.volume = v;
  16733. }
  16734. get volume() {
  16735. if (!this._audio)
  16736. return 1;
  16737. return this._audio.volume;
  16738. }
  16739. }
  16740. class AudioSound extends EventDispatcher {
  16741. constructor() {
  16742. super(...arguments);
  16743. this.loaded = false;
  16744. }
  16745. dispose() {
  16746. var ad = AudioSound._audioCache[this.url];
  16747. Pool.clearBySign("audio:" + this.url);
  16748. if (ad) {
  16749. if (!Render.isConchApp) {
  16750. ad.src = "";
  16751. }
  16752. delete AudioSound._audioCache[this.url];
  16753. }
  16754. }
  16755. static _initMusicAudio() {
  16756. if (AudioSound._musicAudio)
  16757. return;
  16758. if (!AudioSound._musicAudio)
  16759. AudioSound._musicAudio = Browser.createElement("audio");
  16760. if (!Render.isConchApp) {
  16761. Browser.document.addEventListener("mousedown", AudioSound._makeMusicOK);
  16762. }
  16763. }
  16764. static _makeMusicOK() {
  16765. Browser.document.removeEventListener("mousedown", AudioSound._makeMusicOK);
  16766. if (!AudioSound._musicAudio.src) {
  16767. AudioSound._musicAudio.src = "";
  16768. AudioSound._musicAudio.load();
  16769. }
  16770. else {
  16771. AudioSound._musicAudio.play();
  16772. }
  16773. }
  16774. load(url) {
  16775. url = URL.formatURL(url);
  16776. this.url = url;
  16777. var ad;
  16778. if (url == ILaya.SoundManager._bgMusic) {
  16779. AudioSound._initMusicAudio();
  16780. ad = AudioSound._musicAudio;
  16781. if (ad.src != url) {
  16782. AudioSound._audioCache[ad.src] = null;
  16783. ad = null;
  16784. }
  16785. }
  16786. else {
  16787. ad = AudioSound._audioCache[url];
  16788. }
  16789. if (ad && ad.readyState >= 2) {
  16790. this.event(Event.COMPLETE);
  16791. return;
  16792. }
  16793. if (!ad) {
  16794. if (url == ILaya.SoundManager._bgMusic) {
  16795. AudioSound._initMusicAudio();
  16796. ad = AudioSound._musicAudio;
  16797. }
  16798. else {
  16799. ad = Browser.createElement("audio");
  16800. }
  16801. AudioSound._audioCache[url] = ad;
  16802. ad.src = url;
  16803. }
  16804. ad.addEventListener("canplaythrough", onLoaded);
  16805. ad.addEventListener("error", onErr);
  16806. var me = this;
  16807. function onLoaded() {
  16808. offs();
  16809. me.loaded = true;
  16810. me.event(Event.COMPLETE);
  16811. }
  16812. function onErr() {
  16813. ad.load = null;
  16814. offs();
  16815. me.event(Event.ERROR);
  16816. }
  16817. function offs() {
  16818. ad.removeEventListener("canplaythrough", onLoaded);
  16819. ad.removeEventListener("error", onErr);
  16820. }
  16821. this.audio = ad;
  16822. if (ad.load) {
  16823. ad.load();
  16824. }
  16825. else {
  16826. onErr();
  16827. }
  16828. }
  16829. play(startTime = 0, loops = 0) {
  16830. if (!this.url)
  16831. return null;
  16832. var ad;
  16833. if (this.url == ILaya.SoundManager._bgMusic) {
  16834. ad = AudioSound._musicAudio;
  16835. }
  16836. else {
  16837. ad = AudioSound._audioCache[this.url];
  16838. }
  16839. if (!ad)
  16840. return null;
  16841. var tAd;
  16842. tAd = Pool.getItem("audio:" + this.url);
  16843. if (Render.isConchApp) {
  16844. if (!tAd) {
  16845. tAd = Browser.createElement("audio");
  16846. tAd.src = this.url;
  16847. }
  16848. }
  16849. else {
  16850. if (this.url == ILaya.SoundManager._bgMusic) {
  16851. AudioSound._initMusicAudio();
  16852. tAd = AudioSound._musicAudio;
  16853. tAd.src = this.url;
  16854. }
  16855. else {
  16856. tAd = tAd ? tAd : ad.cloneNode(true);
  16857. }
  16858. }
  16859. var channel = new AudioSoundChannel(tAd);
  16860. channel.url = this.url;
  16861. channel.loops = loops;
  16862. channel.startTime = startTime;
  16863. channel.play();
  16864. ILaya.SoundManager.addChannel(channel);
  16865. return channel;
  16866. }
  16867. get duration() {
  16868. var ad;
  16869. ad = AudioSound._audioCache[this.url];
  16870. if (!ad)
  16871. return 0;
  16872. return ad.duration;
  16873. }
  16874. }
  16875. AudioSound._audioCache = {};
  16876. class WebAudioSoundChannel extends SoundChannel {
  16877. constructor() {
  16878. super();
  16879. this.bufferSource = null;
  16880. this._currentTime = 0;
  16881. this._volume = 1;
  16882. this._startTime = 0;
  16883. this._pauseTime = 0;
  16884. this.context = ILaya.WebAudioSound.ctx;
  16885. this._onPlayEnd = Utils.bind(this.__onPlayEnd, this);
  16886. if (this.context["createGain"]) {
  16887. this.gain = this.context["createGain"]();
  16888. }
  16889. else {
  16890. this.gain = this.context["createGainNode"]();
  16891. }
  16892. }
  16893. play() {
  16894. ILaya.SoundManager.addChannel(this);
  16895. this.isStopped = false;
  16896. this._clearBufferSource();
  16897. if (!this.audioBuffer)
  16898. return;
  16899. if (this.startTime >= this.duration)
  16900. return stop();
  16901. var context = this.context;
  16902. var gain = this.gain;
  16903. var bufferSource = context.createBufferSource();
  16904. this.bufferSource = bufferSource;
  16905. bufferSource.buffer = this.audioBuffer;
  16906. bufferSource.connect(gain);
  16907. if (gain)
  16908. gain.disconnect();
  16909. gain.connect(context.destination);
  16910. bufferSource.onended = this._onPlayEnd;
  16911. this._startTime = Browser.now();
  16912. if (this.gain.gain.setTargetAtTime) {
  16913. this.gain.gain.setTargetAtTime(this._volume, this.context.currentTime, WebAudioSoundChannel.SetTargetDelay);
  16914. }
  16915. else
  16916. this.gain.gain.value = this._volume;
  16917. if (this.loops == 0) {
  16918. bufferSource.loop = true;
  16919. }
  16920. if (bufferSource.playbackRate.setTargetAtTime) {
  16921. bufferSource.playbackRate.setTargetAtTime(ILaya.SoundManager.playbackRate, this.context.currentTime, WebAudioSoundChannel.SetTargetDelay);
  16922. }
  16923. else
  16924. bufferSource.playbackRate.value = ILaya.SoundManager.playbackRate;
  16925. bufferSource.start(0, this.startTime);
  16926. this._currentTime = 0;
  16927. }
  16928. __onPlayEnd() {
  16929. if (this.loops == 1) {
  16930. if (this.completeHandler) {
  16931. ILaya.timer.once(10, this, this.__runComplete, [this.completeHandler], false);
  16932. this.completeHandler = null;
  16933. }
  16934. this.stop();
  16935. this.event(Event.COMPLETE);
  16936. return;
  16937. }
  16938. if (this.loops > 0) {
  16939. this.loops--;
  16940. }
  16941. this.startTime = 0;
  16942. this.play();
  16943. }
  16944. get position() {
  16945. if (this.bufferSource) {
  16946. return (Browser.now() - this._startTime) / 1000 + this.startTime;
  16947. }
  16948. return 0;
  16949. }
  16950. get duration() {
  16951. if (this.audioBuffer) {
  16952. return this.audioBuffer.duration;
  16953. }
  16954. return 0;
  16955. }
  16956. _clearBufferSource() {
  16957. if (this.bufferSource) {
  16958. var sourceNode = this.bufferSource;
  16959. if (sourceNode.stop) {
  16960. sourceNode.stop(0);
  16961. }
  16962. else {
  16963. sourceNode.noteOff(0);
  16964. }
  16965. sourceNode.disconnect(0);
  16966. sourceNode.onended = null;
  16967. if (!WebAudioSoundChannel._tryCleanFailed)
  16968. this._tryClearBuffer(sourceNode);
  16969. this.bufferSource = null;
  16970. }
  16971. }
  16972. _tryClearBuffer(sourceNode) {
  16973. if (!Browser.onMac) {
  16974. try {
  16975. sourceNode.buffer = null;
  16976. }
  16977. catch (e) {
  16978. WebAudioSoundChannel._tryCleanFailed = true;
  16979. }
  16980. return;
  16981. }
  16982. try {
  16983. sourceNode.buffer = ILaya.WebAudioSound._miniBuffer;
  16984. }
  16985. catch (e) {
  16986. WebAudioSoundChannel._tryCleanFailed = true;
  16987. }
  16988. }
  16989. stop() {
  16990. super.stop();
  16991. this._clearBufferSource();
  16992. this.audioBuffer = null;
  16993. if (this.gain)
  16994. this.gain.disconnect();
  16995. this.isStopped = true;
  16996. ILaya.SoundManager.removeChannel(this);
  16997. this.completeHandler = null;
  16998. if (ILaya.SoundManager.autoReleaseSound)
  16999. ILaya.SoundManager.disposeSoundLater(this.url);
  17000. }
  17001. pause() {
  17002. if (!this.isStopped) {
  17003. this._pauseTime = this.position;
  17004. }
  17005. this._clearBufferSource();
  17006. if (this.gain)
  17007. this.gain.disconnect();
  17008. this.isStopped = true;
  17009. ILaya.SoundManager.removeChannel(this);
  17010. if (ILaya.SoundManager.autoReleaseSound)
  17011. ILaya.SoundManager.disposeSoundLater(this.url);
  17012. }
  17013. resume() {
  17014. this.startTime = this._pauseTime;
  17015. this.play();
  17016. }
  17017. set volume(v) {
  17018. this._volume = v;
  17019. if (this.isStopped) {
  17020. return;
  17021. }
  17022. if (this.gain.gain.setTargetAtTime) {
  17023. this.gain.gain.setTargetAtTime(v, this.context.currentTime, WebAudioSoundChannel.SetTargetDelay);
  17024. }
  17025. else
  17026. this.gain.gain.value = v;
  17027. }
  17028. get volume() {
  17029. return this._volume;
  17030. }
  17031. }
  17032. WebAudioSoundChannel._tryCleanFailed = false;
  17033. WebAudioSoundChannel.SetTargetDelay = 0.001;
  17034. class WebAudioSound extends EventDispatcher {
  17035. constructor() {
  17036. super(...arguments);
  17037. this.loaded = false;
  17038. this._disposed = false;
  17039. }
  17040. static decode() {
  17041. if (WebAudioSound.buffs.length <= 0 || WebAudioSound.isDecoding) {
  17042. return;
  17043. }
  17044. WebAudioSound.isDecoding = true;
  17045. WebAudioSound.tInfo = WebAudioSound.buffs.shift();
  17046. WebAudioSound.ctx.decodeAudioData(WebAudioSound.tInfo["buffer"], WebAudioSound._done, WebAudioSound._fail);
  17047. }
  17048. static _done(audioBuffer) {
  17049. WebAudioSound.e.event("loaded:" + WebAudioSound.tInfo.url, audioBuffer);
  17050. WebAudioSound.isDecoding = false;
  17051. WebAudioSound.decode();
  17052. }
  17053. static _fail() {
  17054. WebAudioSound.e.event("err:" + WebAudioSound.tInfo.url, null);
  17055. WebAudioSound.isDecoding = false;
  17056. WebAudioSound.decode();
  17057. }
  17058. static _playEmptySound() {
  17059. if (WebAudioSound.ctx == null) {
  17060. return;
  17061. }
  17062. var source = WebAudioSound.ctx.createBufferSource();
  17063. source.buffer = WebAudioSound._miniBuffer;
  17064. source.connect(WebAudioSound.ctx.destination);
  17065. source.start(0, 0, 0);
  17066. }
  17067. static _unlock() {
  17068. if (WebAudioSound._unlocked) {
  17069. return;
  17070. }
  17071. WebAudioSound._playEmptySound();
  17072. if (WebAudioSound.ctx.state == "running") {
  17073. window.document.removeEventListener("mousedown", WebAudioSound._unlock, true);
  17074. window.document.removeEventListener("touchend", WebAudioSound._unlock, true);
  17075. window.document.removeEventListener("touchstart", WebAudioSound._unlock, true);
  17076. WebAudioSound._unlocked = true;
  17077. }
  17078. }
  17079. static initWebAudio() {
  17080. if (WebAudioSound.ctx.state != "running") {
  17081. WebAudioSound._unlock();
  17082. window.document.addEventListener("mousedown", WebAudioSound._unlock, true);
  17083. window.document.addEventListener("touchend", WebAudioSound._unlock, true);
  17084. window.document.addEventListener("touchstart", WebAudioSound._unlock, true);
  17085. }
  17086. }
  17087. load(url) {
  17088. var me = this;
  17089. url = URL.formatURL(url);
  17090. this.url = url;
  17091. this.audioBuffer = WebAudioSound._dataCache[url];
  17092. if (this.audioBuffer) {
  17093. this._loaded(this.audioBuffer);
  17094. return;
  17095. }
  17096. WebAudioSound.e.on("loaded:" + url, this, this._loaded);
  17097. WebAudioSound.e.on("err:" + url, this, this._err);
  17098. if (WebAudioSound.__loadingSound[url]) {
  17099. return;
  17100. }
  17101. WebAudioSound.__loadingSound[url] = true;
  17102. var request = new XMLHttpRequest();
  17103. request.open("GET", url, true);
  17104. request.responseType = "arraybuffer";
  17105. request.onload = function () {
  17106. if (me._disposed) {
  17107. me._removeLoadEvents();
  17108. return;
  17109. }
  17110. me.data = request.response;
  17111. WebAudioSound.buffs.push({ "buffer": me.data, "url": me.url });
  17112. WebAudioSound.decode();
  17113. };
  17114. request.onerror = function (e) {
  17115. me._err();
  17116. };
  17117. request.send();
  17118. }
  17119. _err() {
  17120. this._removeLoadEvents();
  17121. WebAudioSound.__loadingSound[this.url] = false;
  17122. this.event(Event.ERROR);
  17123. }
  17124. _loaded(audioBuffer) {
  17125. this._removeLoadEvents();
  17126. if (this._disposed) {
  17127. return;
  17128. }
  17129. this.audioBuffer = audioBuffer;
  17130. WebAudioSound._dataCache[this.url] = this.audioBuffer;
  17131. this.loaded = true;
  17132. this.event(Event.COMPLETE);
  17133. }
  17134. _removeLoadEvents() {
  17135. WebAudioSound.e.off("loaded:" + this.url, this, this._loaded);
  17136. WebAudioSound.e.off("err:" + this.url, this, this._err);
  17137. }
  17138. __playAfterLoaded() {
  17139. if (!this.__toPlays)
  17140. return;
  17141. var i, len;
  17142. var toPlays;
  17143. toPlays = this.__toPlays;
  17144. len = toPlays.length;
  17145. var tParams;
  17146. for (i = 0; i < len; i++) {
  17147. tParams = toPlays[i];
  17148. if (tParams[2] && !tParams[2].isStopped) {
  17149. this.play(tParams[0], tParams[1], tParams[2]);
  17150. }
  17151. }
  17152. this.__toPlays.length = 0;
  17153. }
  17154. play(startTime = 0, loops = 0, channel = null) {
  17155. channel = channel ? channel : new WebAudioSoundChannel();
  17156. if (!this.audioBuffer) {
  17157. if (this.url) {
  17158. if (!this.__toPlays)
  17159. this.__toPlays = [];
  17160. this.__toPlays.push([startTime, loops, channel]);
  17161. this.once(Event.COMPLETE, this, this.__playAfterLoaded);
  17162. this.load(this.url);
  17163. }
  17164. }
  17165. channel.url = this.url;
  17166. channel.loops = loops;
  17167. channel["audioBuffer"] = this.audioBuffer;
  17168. channel.startTime = startTime;
  17169. channel.play();
  17170. ILaya.SoundManager.addChannel(channel);
  17171. return channel;
  17172. }
  17173. get duration() {
  17174. if (this.audioBuffer) {
  17175. return this.audioBuffer.duration;
  17176. }
  17177. return 0;
  17178. }
  17179. dispose() {
  17180. this._disposed = true;
  17181. delete WebAudioSound._dataCache[this.url];
  17182. delete WebAudioSound.__loadingSound[this.url];
  17183. this.audioBuffer = null;
  17184. this.data = null;
  17185. this.__toPlays = [];
  17186. }
  17187. }
  17188. WebAudioSound._dataCache = {};
  17189. WebAudioSound.webAudioEnabled = window["AudioContext"] || window["webkitAudioContext"] || window["mozAudioContext"];
  17190. WebAudioSound.ctx = WebAudioSound.webAudioEnabled ? new (window["AudioContext"] || window["webkitAudioContext"] || window["mozAudioContext"])() : undefined;
  17191. WebAudioSound.buffs = [];
  17192. WebAudioSound.isDecoding = false;
  17193. WebAudioSound._miniBuffer = WebAudioSound.ctx ? WebAudioSound.ctx.createBuffer(1, 1, 22050) : undefined;
  17194. WebAudioSound.e = new EventDispatcher();
  17195. WebAudioSound._unlocked = false;
  17196. WebAudioSound.__loadingSound = {};
  17197. class SoundManager {
  17198. static __init__() {
  17199. var win = ILaya.Browser.window;
  17200. var supportWebAudio = win["AudioContext"] || win["webkitAudioContext"] || win["mozAudioContext"] ? true : false;
  17201. if (supportWebAudio)
  17202. WebAudioSound.initWebAudio();
  17203. SoundManager._soundClass = supportWebAudio ? WebAudioSound : AudioSound;
  17204. AudioSound._initMusicAudio();
  17205. SoundManager._musicClass = AudioSound;
  17206. return supportWebAudio;
  17207. }
  17208. static addChannel(channel) {
  17209. if (SoundManager._channels.indexOf(channel) >= 0)
  17210. return;
  17211. SoundManager._channels.push(channel);
  17212. }
  17213. static removeChannel(channel) {
  17214. var i;
  17215. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17216. if (SoundManager._channels[i] == channel) {
  17217. SoundManager._channels.splice(i, 1);
  17218. }
  17219. }
  17220. }
  17221. static disposeSoundLater(url) {
  17222. SoundManager._lastSoundUsedTimeDic[url] = ILaya.Browser.now();
  17223. if (!SoundManager._isCheckingDispose) {
  17224. SoundManager._isCheckingDispose = true;
  17225. ILaya.timer.loop(5000, null, SoundManager._checkDisposeSound);
  17226. }
  17227. }
  17228. static _checkDisposeSound() {
  17229. var key;
  17230. var tTime = ILaya.Browser.now();
  17231. var hasCheck = false;
  17232. for (key in SoundManager._lastSoundUsedTimeDic) {
  17233. if (tTime - SoundManager._lastSoundUsedTimeDic[key] > 30000) {
  17234. delete SoundManager._lastSoundUsedTimeDic[key];
  17235. SoundManager.disposeSoundIfNotUsed(key);
  17236. }
  17237. else {
  17238. hasCheck = true;
  17239. }
  17240. }
  17241. if (!hasCheck) {
  17242. SoundManager._isCheckingDispose = false;
  17243. ILaya.timer.clear(null, SoundManager._checkDisposeSound);
  17244. }
  17245. }
  17246. static disposeSoundIfNotUsed(url) {
  17247. var i;
  17248. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17249. if (SoundManager._channels[i].url == url) {
  17250. return;
  17251. }
  17252. }
  17253. SoundManager.destroySound(url);
  17254. }
  17255. static set autoStopMusic(v) {
  17256. ILaya.stage.off(Event.BLUR, null, SoundManager._stageOnBlur);
  17257. ILaya.stage.off(Event.FOCUS, null, SoundManager._stageOnFocus);
  17258. ILaya.stage.off(Event.VISIBILITY_CHANGE, null, SoundManager._visibilityChange);
  17259. SoundManager._autoStopMusic = v;
  17260. if (v) {
  17261. ILaya.stage.on(Event.BLUR, null, SoundManager._stageOnBlur);
  17262. ILaya.stage.on(Event.FOCUS, null, SoundManager._stageOnFocus);
  17263. ILaya.stage.on(Event.VISIBILITY_CHANGE, null, SoundManager._visibilityChange);
  17264. }
  17265. }
  17266. static get autoStopMusic() {
  17267. return SoundManager._autoStopMusic;
  17268. }
  17269. static _visibilityChange() {
  17270. if (ILaya.stage.isVisibility) {
  17271. SoundManager._stageOnFocus();
  17272. }
  17273. else {
  17274. SoundManager._stageOnBlur();
  17275. }
  17276. }
  17277. static _stageOnBlur() {
  17278. SoundManager._isActive = false;
  17279. if (SoundManager._musicChannel) {
  17280. if (!SoundManager._musicChannel.isStopped) {
  17281. SoundManager._blurPaused = true;
  17282. SoundManager._musicChannel.pause();
  17283. }
  17284. }
  17285. SoundManager.stopAllSound();
  17286. ILaya.stage.once(Event.MOUSE_DOWN, null, SoundManager._stageOnFocus);
  17287. }
  17288. static _recoverWebAudio() {
  17289. if (WebAudioSound.ctx && WebAudioSound.ctx.state != "running" && WebAudioSound.ctx.resume)
  17290. WebAudioSound.ctx.resume();
  17291. }
  17292. static _stageOnFocus() {
  17293. SoundManager._isActive = true;
  17294. SoundManager._recoverWebAudio();
  17295. ILaya.stage.off(Event.MOUSE_DOWN, null, SoundManager._stageOnFocus);
  17296. if (SoundManager._blurPaused) {
  17297. if (SoundManager._musicChannel && SoundManager._musicChannel.isStopped) {
  17298. SoundManager._blurPaused = false;
  17299. SoundManager._musicChannel.resume();
  17300. }
  17301. }
  17302. }
  17303. static set muted(value) {
  17304. if (value == SoundManager._muted)
  17305. return;
  17306. if (value) {
  17307. SoundManager.stopAllSound();
  17308. }
  17309. SoundManager.musicMuted = value;
  17310. SoundManager._muted = value;
  17311. }
  17312. static get muted() {
  17313. return SoundManager._muted;
  17314. }
  17315. static set soundMuted(value) {
  17316. SoundManager._soundMuted = value;
  17317. }
  17318. static get soundMuted() {
  17319. return SoundManager._soundMuted;
  17320. }
  17321. static set musicMuted(value) {
  17322. if (value == SoundManager._musicMuted)
  17323. return;
  17324. if (value) {
  17325. if (SoundManager._bgMusic) {
  17326. if (SoundManager._musicChannel && !SoundManager._musicChannel.isStopped) {
  17327. if (ILaya.Render.isConchApp) {
  17328. if (SoundManager._musicChannel._audio)
  17329. SoundManager._musicChannel._audio.muted = true;
  17330. }
  17331. else {
  17332. SoundManager._musicChannel.pause();
  17333. }
  17334. }
  17335. else {
  17336. SoundManager._musicChannel = null;
  17337. }
  17338. }
  17339. else {
  17340. SoundManager._musicChannel = null;
  17341. }
  17342. SoundManager._musicMuted = value;
  17343. }
  17344. else {
  17345. SoundManager._musicMuted = value;
  17346. if (SoundManager._bgMusic) {
  17347. if (SoundManager._musicChannel) {
  17348. if (ILaya.Render.isConchApp) {
  17349. if (SoundManager._musicChannel._audio)
  17350. SoundManager._musicChannel._audio.muted = false;
  17351. }
  17352. else {
  17353. SoundManager._musicChannel.resume();
  17354. }
  17355. }
  17356. }
  17357. }
  17358. }
  17359. static get musicMuted() {
  17360. return SoundManager._musicMuted;
  17361. }
  17362. static get useAudioMusic() {
  17363. return SoundManager._useAudioMusic;
  17364. }
  17365. static set useAudioMusic(value) {
  17366. SoundManager._useAudioMusic = value;
  17367. if (value) {
  17368. SoundManager._musicClass = AudioSound;
  17369. }
  17370. else {
  17371. SoundManager._musicClass = null;
  17372. }
  17373. }
  17374. static playSound(url, loops = 1, complete = null, soundClass = null, startTime = 0) {
  17375. if (!SoundManager._isActive || !url)
  17376. return null;
  17377. if (SoundManager._muted)
  17378. return null;
  17379. SoundManager._recoverWebAudio();
  17380. url = URL.formatURL(url);
  17381. if (url == SoundManager._bgMusic) {
  17382. if (SoundManager._musicMuted)
  17383. return null;
  17384. }
  17385. else {
  17386. if (ILaya.Render.isConchApp) {
  17387. var ext = Utils.getFileExtension(url);
  17388. if (ext != "wav" && ext != "ogg") {
  17389. alert("The sound only supports wav or ogg format,for optimal performance reason,please refer to the official website document.");
  17390. return null;
  17391. }
  17392. }
  17393. if (SoundManager._soundMuted)
  17394. return null;
  17395. }
  17396. var tSound;
  17397. if (!ILaya.Browser.onBDMiniGame && !ILaya.Browser.onMiniGame && !ILaya.Browser.onKGMiniGame && !ILaya.Browser.onQGMiniGame && !ILaya.Browser.onVVMiniGame && !ILaya.Browser.onAlipayMiniGame && !ILaya.Browser.onQQMiniGame) {
  17398. tSound = ILaya.loader.getRes(url);
  17399. }
  17400. if (!soundClass)
  17401. soundClass = SoundManager._soundClass;
  17402. if (!tSound) {
  17403. tSound = new soundClass();
  17404. tSound.load(url);
  17405. if (!ILaya.Browser.onBDMiniGame && !ILaya.Browser.onMiniGame && !ILaya.Browser.onKGMiniGame && !ILaya.Browser.onQGMiniGame && !ILaya.Browser.onVVMiniGame && !ILaya.Browser.onAlipayMiniGame && !ILaya.Browser.onQQMiniGame) {
  17406. ILaya.Loader.cacheRes(url, tSound);
  17407. }
  17408. }
  17409. var channel;
  17410. channel = tSound.play(startTime, loops);
  17411. if (!channel)
  17412. return null;
  17413. channel.url = url;
  17414. channel.volume = (url == SoundManager._bgMusic) ? SoundManager.musicVolume : SoundManager.soundVolume;
  17415. channel.completeHandler = complete;
  17416. return channel;
  17417. }
  17418. static destroySound(url) {
  17419. var tSound = ILaya.loader.getRes(url);
  17420. if (tSound) {
  17421. ILaya.Loader.clearRes(url);
  17422. tSound.dispose();
  17423. }
  17424. }
  17425. static playMusic(url, loops = 0, complete = null, startTime = 0) {
  17426. url = URL.formatURL(url);
  17427. SoundManager._bgMusic = url;
  17428. if (SoundManager._musicChannel)
  17429. SoundManager._musicChannel.stop();
  17430. return SoundManager._musicChannel = SoundManager.playSound(url, loops, complete, SoundManager._musicClass, startTime);
  17431. }
  17432. static stopSound(url) {
  17433. url = URL.formatURL(url);
  17434. var i;
  17435. var channel;
  17436. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17437. channel = SoundManager._channels[i];
  17438. if (channel.url == url) {
  17439. channel.stop();
  17440. }
  17441. }
  17442. }
  17443. static stopAll() {
  17444. SoundManager._bgMusic = null;
  17445. var i;
  17446. var channel;
  17447. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17448. channel = SoundManager._channels[i];
  17449. channel.stop();
  17450. }
  17451. }
  17452. static stopAllSound() {
  17453. var i;
  17454. var channel;
  17455. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17456. channel = SoundManager._channels[i];
  17457. if (channel.url != SoundManager._bgMusic) {
  17458. channel.stop();
  17459. }
  17460. }
  17461. }
  17462. static stopMusic() {
  17463. if (SoundManager._musicChannel)
  17464. SoundManager._musicChannel.stop();
  17465. SoundManager._bgMusic = null;
  17466. }
  17467. static setSoundVolume(volume, url = null) {
  17468. if (url) {
  17469. url = URL.formatURL(url);
  17470. SoundManager._setVolume(url, volume);
  17471. }
  17472. else {
  17473. SoundManager.soundVolume = volume;
  17474. var i;
  17475. var channel;
  17476. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17477. channel = SoundManager._channels[i];
  17478. if (channel.url != SoundManager._bgMusic) {
  17479. channel.volume = volume;
  17480. }
  17481. }
  17482. }
  17483. }
  17484. static setMusicVolume(volume) {
  17485. SoundManager.musicVolume = volume;
  17486. SoundManager._setVolume(SoundManager._bgMusic, volume);
  17487. }
  17488. static _setVolume(url, volume) {
  17489. url = URL.formatURL(url);
  17490. var i;
  17491. var channel;
  17492. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17493. channel = SoundManager._channels[i];
  17494. if (channel.url == url) {
  17495. channel.volume = volume;
  17496. }
  17497. }
  17498. }
  17499. }
  17500. SoundManager.musicVolume = 1;
  17501. SoundManager.soundVolume = 1;
  17502. SoundManager.playbackRate = 1;
  17503. SoundManager._useAudioMusic = true;
  17504. SoundManager._muted = false;
  17505. SoundManager._soundMuted = false;
  17506. SoundManager._musicMuted = false;
  17507. SoundManager._bgMusic = null;
  17508. SoundManager._musicChannel = null;
  17509. SoundManager._channels = [];
  17510. SoundManager._blurPaused = false;
  17511. SoundManager._isActive = true;
  17512. SoundManager._lastSoundUsedTimeDic = {};
  17513. SoundManager._isCheckingDispose = false;
  17514. SoundManager.autoReleaseSound = true;
  17515. class Prefab {
  17516. create() {
  17517. if (this.json)
  17518. return ILaya.SceneUtils.createByData(null, this.json);
  17519. return null;
  17520. }
  17521. }
  17522. class Byte {
  17523. constructor(data = null) {
  17524. this._xd_ = true;
  17525. this._allocated_ = 8;
  17526. this._pos_ = 0;
  17527. this._length = 0;
  17528. if (data) {
  17529. this._u8d_ = new Uint8Array(data);
  17530. this._d_ = new DataView(this._u8d_.buffer);
  17531. this._length = this._d_.byteLength;
  17532. }
  17533. else {
  17534. this._resizeBuffer(this._allocated_);
  17535. }
  17536. }
  17537. static getSystemEndian() {
  17538. if (!Byte._sysEndian) {
  17539. var buffer = new ArrayBuffer(2);
  17540. new DataView(buffer).setInt16(0, 256, true);
  17541. Byte._sysEndian = (new Int16Array(buffer))[0] === 256 ? Byte.LITTLE_ENDIAN : Byte.BIG_ENDIAN;
  17542. }
  17543. return Byte._sysEndian;
  17544. }
  17545. get buffer() {
  17546. var rstBuffer = this._d_.buffer;
  17547. if (rstBuffer.byteLength === this._length)
  17548. return rstBuffer;
  17549. return rstBuffer.slice(0, this._length);
  17550. }
  17551. get endian() {
  17552. return this._xd_ ? Byte.LITTLE_ENDIAN : Byte.BIG_ENDIAN;
  17553. }
  17554. set endian(value) {
  17555. this._xd_ = (value === Byte.LITTLE_ENDIAN);
  17556. }
  17557. set length(value) {
  17558. if (this._allocated_ < value)
  17559. this._resizeBuffer(this._allocated_ = Math.floor(Math.max(value, this._allocated_ * 2)));
  17560. else if (this._allocated_ > value)
  17561. this._resizeBuffer(this._allocated_ = value);
  17562. this._length = value;
  17563. }
  17564. get length() {
  17565. return this._length;
  17566. }
  17567. _resizeBuffer(len) {
  17568. try {
  17569. var newByteView = new Uint8Array(len);
  17570. if (this._u8d_ != null) {
  17571. if (this._u8d_.length <= len)
  17572. newByteView.set(this._u8d_);
  17573. else
  17574. newByteView.set(this._u8d_.subarray(0, len));
  17575. }
  17576. this._u8d_ = newByteView;
  17577. this._d_ = new DataView(newByteView.buffer);
  17578. }
  17579. catch (err) {
  17580. throw "Invalid typed array length:" + len;
  17581. }
  17582. }
  17583. getString() {
  17584. return this.readString();
  17585. }
  17586. readString() {
  17587. return this._rUTF(this.getUint16());
  17588. }
  17589. getFloat32Array(start, len) {
  17590. return this.readFloat32Array(start, len);
  17591. }
  17592. readFloat32Array(start, len) {
  17593. var end = start + len;
  17594. end = (end > this._length) ? this._length : end;
  17595. var v = new Float32Array(this._d_.buffer.slice(start, end));
  17596. this._pos_ = end;
  17597. return v;
  17598. }
  17599. getUint8Array(start, len) {
  17600. return this.readUint8Array(start, len);
  17601. }
  17602. readUint8Array(start, len) {
  17603. var end = start + len;
  17604. end = (end > this._length) ? this._length : end;
  17605. var v = new Uint8Array(this._d_.buffer.slice(start, end));
  17606. this._pos_ = end;
  17607. return v;
  17608. }
  17609. getInt16Array(start, len) {
  17610. return this.readInt16Array(start, len);
  17611. }
  17612. readInt16Array(start, len) {
  17613. var end = start + len;
  17614. end = (end > this._length) ? this._length : end;
  17615. var v = new Int16Array(this._d_.buffer.slice(start, end));
  17616. this._pos_ = end;
  17617. return v;
  17618. }
  17619. getFloat32() {
  17620. return this.readFloat32();
  17621. }
  17622. readFloat32() {
  17623. if (this._pos_ + 4 > this._length)
  17624. throw "getFloat32 error - Out of bounds";
  17625. var v = this._d_.getFloat32(this._pos_, this._xd_);
  17626. this._pos_ += 4;
  17627. return v;
  17628. }
  17629. getFloat64() {
  17630. return this.readFloat64();
  17631. }
  17632. readFloat64() {
  17633. if (this._pos_ + 8 > this._length)
  17634. throw "getFloat64 error - Out of bounds";
  17635. var v = this._d_.getFloat64(this._pos_, this._xd_);
  17636. this._pos_ += 8;
  17637. return v;
  17638. }
  17639. writeFloat32(value) {
  17640. this._ensureWrite(this._pos_ + 4);
  17641. this._d_.setFloat32(this._pos_, value, this._xd_);
  17642. this._pos_ += 4;
  17643. }
  17644. writeFloat64(value) {
  17645. this._ensureWrite(this._pos_ + 8);
  17646. this._d_.setFloat64(this._pos_, value, this._xd_);
  17647. this._pos_ += 8;
  17648. }
  17649. getInt32() {
  17650. return this.readInt32();
  17651. }
  17652. readInt32() {
  17653. if (this._pos_ + 4 > this._length)
  17654. throw "getInt32 error - Out of bounds";
  17655. var float = this._d_.getInt32(this._pos_, this._xd_);
  17656. this._pos_ += 4;
  17657. return float;
  17658. }
  17659. getUint32() {
  17660. return this.readUint32();
  17661. }
  17662. readUint32() {
  17663. if (this._pos_ + 4 > this._length)
  17664. throw "getUint32 error - Out of bounds";
  17665. var v = this._d_.getUint32(this._pos_, this._xd_);
  17666. this._pos_ += 4;
  17667. return v;
  17668. }
  17669. writeInt32(value) {
  17670. this._ensureWrite(this._pos_ + 4);
  17671. this._d_.setInt32(this._pos_, value, this._xd_);
  17672. this._pos_ += 4;
  17673. }
  17674. writeUint32(value) {
  17675. this._ensureWrite(this._pos_ + 4);
  17676. this._d_.setUint32(this._pos_, value, this._xd_);
  17677. this._pos_ += 4;
  17678. }
  17679. getInt16() {
  17680. return this.readInt16();
  17681. }
  17682. readInt16() {
  17683. if (this._pos_ + 2 > this._length)
  17684. throw "getInt16 error - Out of bounds";
  17685. var us = this._d_.getInt16(this._pos_, this._xd_);
  17686. this._pos_ += 2;
  17687. return us;
  17688. }
  17689. getUint16() {
  17690. return this.readUint16();
  17691. }
  17692. readUint16() {
  17693. if (this._pos_ + 2 > this._length)
  17694. throw "getUint16 error - Out of bounds";
  17695. var us = this._d_.getUint16(this._pos_, this._xd_);
  17696. this._pos_ += 2;
  17697. return us;
  17698. }
  17699. writeUint16(value) {
  17700. this._ensureWrite(this._pos_ + 2);
  17701. this._d_.setUint16(this._pos_, value, this._xd_);
  17702. this._pos_ += 2;
  17703. }
  17704. writeInt16(value) {
  17705. this._ensureWrite(this._pos_ + 2);
  17706. this._d_.setInt16(this._pos_, value, this._xd_);
  17707. this._pos_ += 2;
  17708. }
  17709. getUint8() {
  17710. return this.readUint8();
  17711. }
  17712. readUint8() {
  17713. if (this._pos_ + 1 > this._length)
  17714. throw "getUint8 error - Out of bounds";
  17715. return this._u8d_[this._pos_++];
  17716. }
  17717. writeUint8(value) {
  17718. this._ensureWrite(this._pos_ + 1);
  17719. this._d_.setUint8(this._pos_, value);
  17720. this._pos_++;
  17721. }
  17722. _getUInt8(pos) {
  17723. return this._readUInt8(pos);
  17724. }
  17725. _readUInt8(pos) {
  17726. return this._d_.getUint8(pos);
  17727. }
  17728. _getUint16(pos) {
  17729. return this._readUint16(pos);
  17730. }
  17731. _readUint16(pos) {
  17732. return this._d_.getUint16(pos, this._xd_);
  17733. }
  17734. _getMatrix() {
  17735. return this._readMatrix();
  17736. }
  17737. _readMatrix() {
  17738. var rst = new Matrix(this.getFloat32(), this.getFloat32(), this.getFloat32(), this.getFloat32(), this.getFloat32(), this.getFloat32());
  17739. return rst;
  17740. }
  17741. _rUTF(len) {
  17742. var max = this._pos_ + len, c, c2, c3, f = String.fromCharCode;
  17743. var u = this._u8d_;
  17744. var strs = [];
  17745. var n = 0;
  17746. strs.length = 1000;
  17747. while (this._pos_ < max) {
  17748. c = u[this._pos_++];
  17749. if (c < 0x80) {
  17750. if (c != 0)
  17751. strs[n++] = f(c);
  17752. }
  17753. else if (c < 0xE0) {
  17754. strs[n++] = f(((c & 0x3F) << 6) | (u[this._pos_++] & 0x7F));
  17755. }
  17756. else if (c < 0xF0) {
  17757. c2 = u[this._pos_++];
  17758. strs[n++] = f(((c & 0x1F) << 12) | ((c2 & 0x7F) << 6) | (u[this._pos_++] & 0x7F));
  17759. }
  17760. else {
  17761. c2 = u[this._pos_++];
  17762. c3 = u[this._pos_++];
  17763. strs[n++] = f(((c & 0x0F) << 18) | ((c2 & 0x7F) << 12) | ((c3 << 6) & 0x7F) | (u[this._pos_++] & 0x7F));
  17764. }
  17765. }
  17766. strs.length = n;
  17767. return strs.join('');
  17768. }
  17769. getCustomString(len) {
  17770. return this.readCustomString(len);
  17771. }
  17772. readCustomString(len) {
  17773. var v = "", ulen = 0, c, c2, f = String.fromCharCode;
  17774. var u = this._u8d_;
  17775. while (len > 0) {
  17776. c = u[this._pos_];
  17777. if (c < 0x80) {
  17778. v += f(c);
  17779. this._pos_++;
  17780. len--;
  17781. }
  17782. else {
  17783. ulen = c - 0x80;
  17784. this._pos_++;
  17785. len -= ulen;
  17786. while (ulen > 0) {
  17787. c = u[this._pos_++];
  17788. c2 = u[this._pos_++];
  17789. v += f((c2 << 8) | c);
  17790. ulen--;
  17791. }
  17792. }
  17793. }
  17794. return v;
  17795. }
  17796. get pos() {
  17797. return this._pos_;
  17798. }
  17799. set pos(value) {
  17800. this._pos_ = value;
  17801. }
  17802. get bytesAvailable() {
  17803. return this._length - this._pos_;
  17804. }
  17805. clear() {
  17806. this._pos_ = 0;
  17807. this.length = 0;
  17808. }
  17809. __getBuffer() {
  17810. return this._d_.buffer;
  17811. }
  17812. writeUTFBytes(value) {
  17813. value = value + "";
  17814. for (var i = 0, sz = value.length; i < sz; i++) {
  17815. var c = value.charCodeAt(i);
  17816. if (c <= 0x7F) {
  17817. this.writeByte(c);
  17818. }
  17819. else if (c <= 0x7FF) {
  17820. this._ensureWrite(this._pos_ + 2);
  17821. this._u8d_.set([0xC0 | (c >> 6), 0x80 | (c & 0x3F)], this._pos_);
  17822. this._pos_ += 2;
  17823. }
  17824. else if (c <= 0xFFFF) {
  17825. this._ensureWrite(this._pos_ + 3);
  17826. this._u8d_.set([0xE0 | (c >> 12), 0x80 | ((c >> 6) & 0x3F), 0x80 | (c & 0x3F)], this._pos_);
  17827. this._pos_ += 3;
  17828. }
  17829. else {
  17830. this._ensureWrite(this._pos_ + 4);
  17831. this._u8d_.set([0xF0 | (c >> 18), 0x80 | ((c >> 12) & 0x3F), 0x80 | ((c >> 6) & 0x3F), 0x80 | (c & 0x3F)], this._pos_);
  17832. this._pos_ += 4;
  17833. }
  17834. }
  17835. }
  17836. writeUTFString(value) {
  17837. var tPos = this.pos;
  17838. this.writeUint16(1);
  17839. this.writeUTFBytes(value);
  17840. var dPos = this.pos - tPos - 2;
  17841. this._d_.setUint16(tPos, dPos, this._xd_);
  17842. }
  17843. readUTFString() {
  17844. return this.readUTFBytes(this.getUint16());
  17845. }
  17846. getUTFString() {
  17847. return this.readUTFString();
  17848. }
  17849. readUTFBytes(len = -1) {
  17850. if (len === 0)
  17851. return "";
  17852. var lastBytes = this.bytesAvailable;
  17853. if (len > lastBytes)
  17854. throw "readUTFBytes error - Out of bounds";
  17855. len = len > 0 ? len : lastBytes;
  17856. return this._rUTF(len);
  17857. }
  17858. getUTFBytes(len = -1) {
  17859. return this.readUTFBytes(len);
  17860. }
  17861. writeByte(value) {
  17862. this._ensureWrite(this._pos_ + 1);
  17863. this._d_.setInt8(this._pos_, value);
  17864. this._pos_ += 1;
  17865. }
  17866. readByte() {
  17867. if (this._pos_ + 1 > this._length)
  17868. throw "readByte error - Out of bounds";
  17869. return this._d_.getInt8(this._pos_++);
  17870. }
  17871. getByte() {
  17872. return this.readByte();
  17873. }
  17874. _ensureWrite(lengthToEnsure) {
  17875. if (this._length < lengthToEnsure)
  17876. this._length = lengthToEnsure;
  17877. if (this._allocated_ < lengthToEnsure)
  17878. this.length = lengthToEnsure;
  17879. }
  17880. writeArrayBuffer(arraybuffer, offset = 0, length = 0) {
  17881. if (offset < 0 || length < 0)
  17882. throw "writeArrayBuffer error - Out of bounds";
  17883. if (length == 0)
  17884. length = arraybuffer.byteLength - offset;
  17885. this._ensureWrite(this._pos_ + length);
  17886. var uint8array = new Uint8Array(arraybuffer);
  17887. this._u8d_.set(uint8array.subarray(offset, offset + length), this._pos_);
  17888. this._pos_ += length;
  17889. }
  17890. readArrayBuffer(length) {
  17891. var rst;
  17892. rst = this._u8d_.buffer.slice(this._pos_, this._pos_ + length);
  17893. this._pos_ = this._pos_ + length;
  17894. return rst;
  17895. }
  17896. }
  17897. Byte.BIG_ENDIAN = "bigEndian";
  17898. Byte.LITTLE_ENDIAN = "littleEndian";
  17899. Byte._sysEndian = null;
  17900. class BitmapFont {
  17901. constructor() {
  17902. this._fontCharDic = {};
  17903. this._fontWidthMap = {};
  17904. this._maxWidth = 0;
  17905. this._spaceWidth = 10;
  17906. this.fontSize = 12;
  17907. this.autoScaleSize = false;
  17908. this.letterSpacing = 0;
  17909. }
  17910. loadFont(path, complete) {
  17911. this._path = path;
  17912. this._complete = complete;
  17913. if (!path || path.indexOf(".fnt") === -1) {
  17914. console.error('Bitmap font configuration information must be a ".fnt" file');
  17915. return;
  17916. }
  17917. ILaya.loader.load([{ url: path, type: ILaya.Loader.XML }, { url: path.replace(".fnt", ".png"), type: ILaya.Loader.IMAGE }], Handler.create(this, this._onLoaded));
  17918. }
  17919. _onLoaded() {
  17920. this.parseFont(ILaya.Loader.getRes(this._path), ILaya.Loader.getRes(this._path.replace(".fnt", ".png")));
  17921. this._complete && this._complete.run();
  17922. }
  17923. parseFont(xml, texture) {
  17924. if (xml == null || texture == null)
  17925. return;
  17926. this._texture = texture;
  17927. var tScale = 1;
  17928. var tInfo = xml.getElementsByTagName("info");
  17929. if (!tInfo[0].getAttributeNode) {
  17930. return this.parseFont2(xml, texture);
  17931. }
  17932. this.fontSize = parseInt(tInfo[0].getAttributeNode("size").nodeValue);
  17933. var tPadding = tInfo[0].getAttributeNode("padding").nodeValue;
  17934. var tPaddingArray = tPadding.split(",");
  17935. this._padding = [parseInt(tPaddingArray[0]), parseInt(tPaddingArray[1]), parseInt(tPaddingArray[2]), parseInt(tPaddingArray[3])];
  17936. var chars = xml.getElementsByTagName("char");
  17937. var i = 0;
  17938. for (i = 0; i < chars.length; i++) {
  17939. var tAttribute = chars[i];
  17940. var tId = parseInt(tAttribute.getAttributeNode("id").nodeValue);
  17941. var xOffset = parseInt(tAttribute.getAttributeNode("xoffset").nodeValue) / tScale;
  17942. var yOffset = parseInt(tAttribute.getAttributeNode("yoffset").nodeValue) / tScale;
  17943. var xAdvance = parseInt(tAttribute.getAttributeNode("xadvance").nodeValue) / tScale;
  17944. var region = new Rectangle();
  17945. region.x = parseInt(tAttribute.getAttributeNode("x").nodeValue);
  17946. region.y = parseInt(tAttribute.getAttributeNode("y").nodeValue);
  17947. region.width = parseInt(tAttribute.getAttributeNode("width").nodeValue);
  17948. region.height = parseInt(tAttribute.getAttributeNode("height").nodeValue);
  17949. var tTexture = Texture.create(texture, region.x, region.y, region.width, region.height, xOffset, yOffset);
  17950. this._maxWidth = Math.max(this._maxWidth, xAdvance + this.letterSpacing);
  17951. this._fontCharDic[tId] = tTexture;
  17952. this._fontWidthMap[tId] = xAdvance;
  17953. }
  17954. }
  17955. parseFont2(xml, texture) {
  17956. if (xml == null || texture == null)
  17957. return;
  17958. this._texture = texture;
  17959. var tScale = 1;
  17960. var tInfo = xml.getElementsByTagName("info");
  17961. this.fontSize = parseInt(tInfo[0].attributes["size"].nodeValue);
  17962. var tPadding = tInfo[0].attributes["padding"].nodeValue;
  17963. var tPaddingArray = tPadding.split(",");
  17964. this._padding = [parseInt(tPaddingArray[0]), parseInt(tPaddingArray[1]), parseInt(tPaddingArray[2]), parseInt(tPaddingArray[3])];
  17965. var chars = xml.getElementsByTagName("char");
  17966. var i = 0;
  17967. for (i = 0; i < chars.length; i++) {
  17968. var tAttribute = chars[i].attributes;
  17969. var tId = parseInt(tAttribute["id"].nodeValue);
  17970. var xOffset = parseInt(tAttribute["xoffset"].nodeValue) / tScale;
  17971. var yOffset = parseInt(tAttribute["yoffset"].nodeValue) / tScale;
  17972. var xAdvance = parseInt(tAttribute["xadvance"].nodeValue) / tScale;
  17973. var region = new Rectangle();
  17974. region.x = parseInt(tAttribute["x"].nodeValue);
  17975. region.y = parseInt(tAttribute["y"].nodeValue);
  17976. region.width = parseInt(tAttribute["width"].nodeValue);
  17977. region.height = parseInt(tAttribute["height"].nodeValue);
  17978. var tTexture = Texture.create(texture, region.x, region.y, region.width, region.height, xOffset, yOffset);
  17979. this._maxWidth = Math.max(this._maxWidth, xAdvance + this.letterSpacing);
  17980. this._fontCharDic[tId] = tTexture;
  17981. this._fontWidthMap[tId] = xAdvance;
  17982. }
  17983. }
  17984. getCharTexture(char) {
  17985. return this._fontCharDic[char.charCodeAt(0)];
  17986. }
  17987. destroy() {
  17988. if (this._texture) {
  17989. for (var p in this._fontCharDic) {
  17990. var tTexture = this._fontCharDic[p];
  17991. if (tTexture)
  17992. tTexture.destroy();
  17993. }
  17994. this._texture.destroy();
  17995. this._fontCharDic = null;
  17996. this._fontWidthMap = null;
  17997. this._texture = null;
  17998. this._complete = null;
  17999. this._padding = null;
  18000. }
  18001. }
  18002. setSpaceWidth(spaceWidth) {
  18003. this._spaceWidth = spaceWidth;
  18004. }
  18005. getCharWidth(char) {
  18006. var code = char.charCodeAt(0);
  18007. if (this._fontWidthMap[code])
  18008. return this._fontWidthMap[code] + this.letterSpacing;
  18009. if (char === " ")
  18010. return this._spaceWidth + this.letterSpacing;
  18011. return 0;
  18012. }
  18013. getTextWidth(text) {
  18014. var tWidth = 0;
  18015. for (var i = 0, n = text.length; i < n; i++) {
  18016. tWidth += this.getCharWidth(text.charAt(i));
  18017. }
  18018. return tWidth;
  18019. }
  18020. getMaxWidth() {
  18021. return this._maxWidth;
  18022. }
  18023. getMaxHeight() {
  18024. return this.fontSize;
  18025. }
  18026. _drawText(text, sprite, drawX, drawY, align, width) {
  18027. var tWidth = this.getTextWidth(text);
  18028. var tTexture;
  18029. var dx = 0;
  18030. align === "center" && (dx = (width - tWidth) / 2);
  18031. align === "right" && (dx = (width - tWidth));
  18032. var tx = 0;
  18033. for (var i = 0, n = text.length; i < n; i++) {
  18034. tTexture = this.getCharTexture(text.charAt(i));
  18035. if (tTexture) {
  18036. sprite.graphics.drawImage(tTexture, drawX + tx + dx, drawY);
  18037. tx += this.getCharWidth(text.charAt(i));
  18038. }
  18039. }
  18040. }
  18041. }
  18042. ClassUtils.regClass("laya.display.BitmapFont", BitmapFont);
  18043. ClassUtils.regClass("Laya.BitmapFont", BitmapFont);
  18044. class HttpRequest extends EventDispatcher {
  18045. constructor() {
  18046. super(...arguments);
  18047. this._http = new XMLHttpRequest();
  18048. }
  18049. send(url, data = null, method = "get", responseType = "text", headers = null) {
  18050. this._responseType = responseType;
  18051. this._data = null;
  18052. if (Browser.onVVMiniGame || Browser.onQGMiniGame || Browser.onQQMiniGame) {
  18053. url = encodeURI(url);
  18054. }
  18055. this._url = url;
  18056. var _this = this;
  18057. var http = this._http;
  18058. url = URL.getAdptedFilePath(url);
  18059. http.open(method, url, true);
  18060. if (headers) {
  18061. for (var i = 0; i < headers.length; i++) {
  18062. http.setRequestHeader(headers[i++], headers[i]);
  18063. }
  18064. }
  18065. else if (!(window.conch)) {
  18066. if (!data || typeof (data) == 'string')
  18067. http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  18068. else
  18069. http.setRequestHeader("Content-Type", "application/json");
  18070. }
  18071. let restype = responseType !== "arraybuffer" ? "text" : "arraybuffer";
  18072. http.responseType = restype;
  18073. if (http.dataType) {
  18074. http.dataType = restype;
  18075. }
  18076. http.onerror = function (e) {
  18077. _this._onError(e);
  18078. };
  18079. http.onabort = function (e) {
  18080. _this._onAbort(e);
  18081. };
  18082. http.onprogress = function (e) {
  18083. _this._onProgress(e);
  18084. };
  18085. http.onload = function (e) {
  18086. _this._onLoad(e);
  18087. };
  18088. http.send(data);
  18089. }
  18090. _onProgress(e) {
  18091. if (e && e.lengthComputable)
  18092. this.event(Event.PROGRESS, e.loaded / e.total);
  18093. }
  18094. _onAbort(e) {
  18095. this.error("Request was aborted by user");
  18096. }
  18097. _onError(e) {
  18098. this.error("Request failed Status:" + this._http.status + " text:" + this._http.statusText);
  18099. }
  18100. _onLoad(e) {
  18101. var http = this._http;
  18102. var status = http.status !== undefined ? http.status : 200;
  18103. if (status === 200 || status === 204 || status === 0) {
  18104. this.complete();
  18105. }
  18106. else {
  18107. this.error("[" + http.status + "]" + http.statusText + ":" + http.responseURL);
  18108. }
  18109. }
  18110. error(message) {
  18111. this.clear();
  18112. console.warn(this.url, message);
  18113. this.event(Event.ERROR, message);
  18114. }
  18115. complete() {
  18116. this.clear();
  18117. var flag = true;
  18118. try {
  18119. if (this._responseType === "json") {
  18120. this._data = JSON.parse(this._http.responseText);
  18121. }
  18122. else if (this._responseType === "xml") {
  18123. this._data = Utils.parseXMLFromString(this._http.responseText);
  18124. }
  18125. else {
  18126. this._data = this._http.response || this._http.responseText;
  18127. }
  18128. }
  18129. catch (e) {
  18130. flag = false;
  18131. this.error(e.message);
  18132. }
  18133. flag && this.event(Event.COMPLETE, this._data instanceof Array ? [this._data] : this._data);
  18134. }
  18135. clear() {
  18136. var http = this._http;
  18137. http.onerror = http.onabort = http.onprogress = http.onload = null;
  18138. }
  18139. get url() {
  18140. return this._url;
  18141. }
  18142. get data() {
  18143. return this._data;
  18144. }
  18145. get http() {
  18146. return this._http;
  18147. }
  18148. }
  18149. class Loader extends EventDispatcher {
  18150. constructor() {
  18151. super(...arguments);
  18152. this._customParse = false;
  18153. }
  18154. static getTypeFromUrl(url) {
  18155. var type = Utils.getFileExtension(url);
  18156. if (type)
  18157. return Loader.typeMap[type];
  18158. console.warn("Not recognize the resources suffix", url);
  18159. return "text";
  18160. }
  18161. load(url, type = null, cache = true, group = null, ignoreCache = false, useWorkerLoader = ILaya.WorkerLoader.enable) {
  18162. if (!url) {
  18163. this.onLoaded(null);
  18164. return;
  18165. }
  18166. Loader.setGroup(url, "666");
  18167. this._url = url;
  18168. if (url.indexOf("data:image") === 0)
  18169. type = Loader.IMAGE;
  18170. else
  18171. url = URL.formatURL(url);
  18172. this._type = type || (type = Loader.getTypeFromUrl(this._url));
  18173. this._cache = cache;
  18174. this._useWorkerLoader = useWorkerLoader;
  18175. this._data = null;
  18176. if (useWorkerLoader)
  18177. ILaya.WorkerLoader.enableWorkerLoader();
  18178. var cacheRes;
  18179. if (type == Loader.IMAGE)
  18180. cacheRes = Loader.textureMap[url];
  18181. else
  18182. cacheRes = Loader.loadedMap[url];
  18183. if (!ignoreCache && cacheRes) {
  18184. this._data = cacheRes;
  18185. this.event(Event.PROGRESS, 1);
  18186. this.event(Event.COMPLETE, this._data);
  18187. return;
  18188. }
  18189. if (group)
  18190. Loader.setGroup(url, group);
  18191. if (Loader.parserMap[type] != null) {
  18192. this._customParse = true;
  18193. if (Loader.parserMap[type] instanceof Handler)
  18194. Loader.parserMap[type].runWith(this);
  18195. else
  18196. Loader.parserMap[type].call(null, this);
  18197. return;
  18198. }
  18199. this._loadResourceFilter(type, url);
  18200. }
  18201. _loadResourceFilter(type, url) {
  18202. this._loadResource(type, url);
  18203. }
  18204. _loadResource(type, url) {
  18205. switch (type) {
  18206. case Loader.IMAGE:
  18207. case "htmlimage":
  18208. case "nativeimage":
  18209. this._loadImage(url);
  18210. break;
  18211. case Loader.SOUND:
  18212. this._loadSound(url);
  18213. break;
  18214. case Loader.TTF:
  18215. this._loadTTF(url);
  18216. break;
  18217. case Loader.ATLAS:
  18218. case Loader.PREFAB:
  18219. case Loader.PLF:
  18220. this._loadHttpRequestWhat(url, Loader.JSON);
  18221. break;
  18222. case Loader.FONT:
  18223. this._loadHttpRequestWhat(url, Loader.XML);
  18224. break;
  18225. case Loader.PLFB:
  18226. this._loadHttpRequestWhat(url, Loader.BUFFER);
  18227. break;
  18228. default:
  18229. this._loadHttpRequestWhat(url, type);
  18230. }
  18231. }
  18232. _loadHttpRequest(url, contentType, onLoadCaller, onLoad, onProcessCaller, onProcess, onErrorCaller, onError) {
  18233. if (Browser.onVVMiniGame) {
  18234. this._http = new HttpRequest();
  18235. }
  18236. else {
  18237. if (!this._http)
  18238. this._http = new HttpRequest();
  18239. }
  18240. onProcess && this._http.on(Event.PROGRESS, onProcessCaller, onProcess);
  18241. onLoad && this._http.on(Event.COMPLETE, onLoadCaller, onLoad);
  18242. this._http.on(Event.ERROR, onErrorCaller, onError);
  18243. this._http.send(url, null, "get", contentType);
  18244. }
  18245. _loadHtmlImage(url, onLoadCaller, onLoad, onErrorCaller, onError) {
  18246. var image;
  18247. function clear() {
  18248. var img = image;
  18249. img.onload = null;
  18250. img.onerror = null;
  18251. delete Loader._imgCache[url];
  18252. }
  18253. var onerror = function () {
  18254. clear();
  18255. onError.call(onErrorCaller);
  18256. };
  18257. var onload = function () {
  18258. clear();
  18259. onLoad.call(onLoadCaller, image);
  18260. };
  18261. image = new Browser.window.Image();
  18262. image.crossOrigin = "";
  18263. image.onload = onload;
  18264. image.onerror = onerror;
  18265. image.src = url;
  18266. Loader._imgCache[url] = image;
  18267. }
  18268. _loadHttpRequestWhat(url, contentType) {
  18269. if (Loader.preLoadedMap[url])
  18270. this.onLoaded(Loader.preLoadedMap[url]);
  18271. else
  18272. this._loadHttpRequest(url, contentType, this, this.onLoaded, this, this.onProgress, this, this.onError);
  18273. }
  18274. _loadTTF(url) {
  18275. url = URL.formatURL(url);
  18276. var ttfLoader = new ILaya.TTFLoader();
  18277. ttfLoader.complete = Handler.create(this, this.onLoaded);
  18278. ttfLoader.load(url);
  18279. }
  18280. _loadImage(url, isformatURL = true) {
  18281. var _this = this;
  18282. if (isformatURL)
  18283. url = URL.formatURL(url);
  18284. var onLoaded;
  18285. var onError = function () {
  18286. _this.event(Event.ERROR, "Load image failed");
  18287. };
  18288. if (this._type === "nativeimage") {
  18289. onLoaded = (image) => {
  18290. this.onLoaded(image);
  18291. };
  18292. this._loadHtmlImage(url, this, onLoaded, this, onError);
  18293. }
  18294. else {
  18295. var ext = Utils.getFileExtension(url);
  18296. if (ext === "ktx" || ext === "pvr") {
  18297. onLoaded = function (imageData) {
  18298. let format;
  18299. switch (ext) {
  18300. case "ktx":
  18301. format = exports.TextureFormat.ETC1RGB;
  18302. break;
  18303. case "pvr":
  18304. format = exports.TextureFormat.PVRTCRGBA_4BPPV;
  18305. break;
  18306. default: {
  18307. console.error('unknown format', ext);
  18308. return;
  18309. }
  18310. }
  18311. var tex = new Texture2D(0, 0, format, false, false);
  18312. tex.wrapModeU = BaseTexture.WARPMODE_CLAMP;
  18313. tex.wrapModeV = BaseTexture.WARPMODE_CLAMP;
  18314. tex.setCompressData(imageData);
  18315. tex._setCreateURL(url);
  18316. _this.onLoaded(tex);
  18317. };
  18318. this._loadHttpRequest(url, Loader.BUFFER, this, onLoaded, null, null, this, onError);
  18319. }
  18320. else {
  18321. onLoaded = function (image) {
  18322. var tex = new Texture2D(image.width, image.height, 1, false, false);
  18323. tex.wrapModeU = BaseTexture.WARPMODE_CLAMP;
  18324. tex.wrapModeV = BaseTexture.WARPMODE_CLAMP;
  18325. tex.loadImageSource(image, true);
  18326. tex._setCreateURL(url);
  18327. _this.onLoaded(tex);
  18328. };
  18329. this._loadHtmlImage(url, this, onLoaded, this, onError);
  18330. }
  18331. }
  18332. }
  18333. _loadSound(url) {
  18334. var sound = (new SoundManager._soundClass());
  18335. var _this = this;
  18336. sound.on(Event.COMPLETE, this, soundOnload);
  18337. sound.on(Event.ERROR, this, soundOnErr);
  18338. sound.load(url);
  18339. function soundOnload() {
  18340. clear();
  18341. _this.onLoaded(sound);
  18342. }
  18343. function soundOnErr() {
  18344. clear();
  18345. sound.dispose();
  18346. _this.event(Event.ERROR, "Load sound failed");
  18347. }
  18348. function clear() {
  18349. sound.offAll();
  18350. }
  18351. }
  18352. onProgress(value) {
  18353. if (this._type === Loader.ATLAS)
  18354. this.event(Event.PROGRESS, value * 0.3);
  18355. else
  18356. this.event(Event.PROGRESS, value);
  18357. }
  18358. onError(message) {
  18359. this.event(Event.ERROR, message);
  18360. }
  18361. onLoaded(data = null) {
  18362. var type = this._type;
  18363. if (type == Loader.PLFB) {
  18364. this.parsePLFBData(data);
  18365. this.complete(data);
  18366. }
  18367. else if (type == Loader.PLF) {
  18368. this.parsePLFData(data);
  18369. this.complete(data);
  18370. }
  18371. else if (type === Loader.IMAGE) {
  18372. var tex = new Texture(data);
  18373. tex.url = this._url;
  18374. this.complete(tex);
  18375. }
  18376. else if (type === Loader.SOUND || type === "htmlimage" || type === "nativeimage") {
  18377. this.complete(data);
  18378. }
  18379. else if (type === Loader.ATLAS) {
  18380. if (!(data instanceof Texture2D)) {
  18381. var toloadPics = [];
  18382. if (!this._data) {
  18383. this._data = data;
  18384. if (data.meta && data.meta.image) {
  18385. toloadPics = data.meta.image.split(",");
  18386. var split = this._url.indexOf("/") >= 0 ? "/" : "\\";
  18387. var idx = this._url.lastIndexOf(split);
  18388. var folderPath = idx >= 0 ? this._url.substr(0, idx + 1) : "";
  18389. var changeType = null;
  18390. if (Browser.onAndroid && data.meta.compressTextureAndroid) {
  18391. changeType = ".ktx";
  18392. }
  18393. if (Browser.onIOS && data.meta.compressTextureIOS) {
  18394. changeType = ".pvr";
  18395. }
  18396. for (var i = 0, len = toloadPics.length; i < len; i++) {
  18397. if (changeType) {
  18398. toloadPics[i] = folderPath + toloadPics[i].replace(".png", changeType);
  18399. }
  18400. else {
  18401. toloadPics[i] = folderPath + toloadPics[i];
  18402. }
  18403. }
  18404. }
  18405. else {
  18406. toloadPics = [this._url.replace(".json", ".png")];
  18407. }
  18408. toloadPics.reverse();
  18409. data.toLoads = toloadPics;
  18410. data.pics = [];
  18411. }
  18412. this.event(Event.PROGRESS, 0.3 + 1 / toloadPics.length * 0.6);
  18413. return this._loadResourceFilter(Loader.IMAGE, toloadPics.pop());
  18414. }
  18415. else {
  18416. this._data.pics.push(data);
  18417. if (this._data.toLoads.length > 0) {
  18418. this.event(Event.PROGRESS, 0.3 + 1 / this._data.toLoads.length * 0.6);
  18419. return this._loadResourceFilter(Loader.IMAGE, this._data.toLoads.pop());
  18420. }
  18421. var frames = this._data.frames;
  18422. var cleanUrl = this._url.split("?")[0];
  18423. var directory = (this._data.meta && this._data.meta.prefix) ? this._data.meta.prefix : cleanUrl.substring(0, cleanUrl.lastIndexOf(".")) + "/";
  18424. var pics = this._data.pics;
  18425. var atlasURL = URL.formatURL(this._url);
  18426. var map = Loader.atlasMap[atlasURL] || (Loader.atlasMap[atlasURL] = []);
  18427. map.dir = directory;
  18428. var scaleRate = 1;
  18429. if (this._data.meta && this._data.meta.scale && this._data.meta.scale != 1) {
  18430. scaleRate = parseFloat(this._data.meta.scale);
  18431. for (var name in frames) {
  18432. var obj = frames[name];
  18433. var tPic = pics[obj.frame.idx ? obj.frame.idx : 0];
  18434. var url = URL.formatURL(directory + name);
  18435. tPic.scaleRate = scaleRate;
  18436. var tTexture;
  18437. tTexture = Texture._create(tPic, obj.frame.x, obj.frame.y, obj.frame.w, obj.frame.h, obj.spriteSourceSize.x, obj.spriteSourceSize.y, obj.sourceSize.w, obj.sourceSize.h, Loader.getRes(url));
  18438. Loader.cacheTexture(url, tTexture);
  18439. tTexture.url = url;
  18440. map.push(url);
  18441. }
  18442. }
  18443. else {
  18444. for (name in frames) {
  18445. obj = frames[name];
  18446. tPic = pics[obj.frame.idx ? obj.frame.idx : 0];
  18447. url = URL.formatURL(directory + name);
  18448. tTexture = Texture._create(tPic, obj.frame.x, obj.frame.y, obj.frame.w, obj.frame.h, obj.spriteSourceSize.x, obj.spriteSourceSize.y, obj.sourceSize.w, obj.sourceSize.h, Loader.getRes(url));
  18449. Loader.cacheTexture(url, tTexture);
  18450. tTexture.url = url;
  18451. map.push(url);
  18452. }
  18453. }
  18454. delete this._data.pics;
  18455. this.complete(this._data);
  18456. }
  18457. }
  18458. else if (type === Loader.FONT) {
  18459. if (!data._source) {
  18460. this._data = data;
  18461. this.event(Event.PROGRESS, 0.5);
  18462. return this._loadResourceFilter(Loader.IMAGE, this._url.replace(".fnt", ".png"));
  18463. }
  18464. else {
  18465. var bFont = new BitmapFont();
  18466. bFont.parseFont(this._data, new Texture(data));
  18467. var tArr = this._url.split(".fnt")[0].split("/");
  18468. var fontName = tArr[tArr.length - 1];
  18469. Text.registerBitmapFont(fontName, bFont);
  18470. this._data = bFont;
  18471. this.complete(this._data);
  18472. }
  18473. }
  18474. else if (type === Loader.PREFAB) {
  18475. var prefab = new Prefab();
  18476. prefab.json = data;
  18477. this.complete(prefab);
  18478. }
  18479. else {
  18480. this.complete(data);
  18481. }
  18482. }
  18483. parsePLFData(plfData) {
  18484. var type;
  18485. var filePath;
  18486. var fileDic;
  18487. for (type in plfData) {
  18488. fileDic = plfData[type];
  18489. switch (type) {
  18490. case "json":
  18491. case "text":
  18492. for (filePath in fileDic) {
  18493. Loader.preLoadedMap[URL.formatURL(filePath)] = fileDic[filePath];
  18494. }
  18495. break;
  18496. default:
  18497. for (filePath in fileDic) {
  18498. Loader.preLoadedMap[URL.formatURL(filePath)] = fileDic[filePath];
  18499. }
  18500. }
  18501. }
  18502. }
  18503. parsePLFBData(plfData) {
  18504. var byte;
  18505. byte = new Byte(plfData);
  18506. var i, len;
  18507. len = byte.getInt32();
  18508. for (i = 0; i < len; i++) {
  18509. this.parseOnePLFBFile(byte);
  18510. }
  18511. }
  18512. parseOnePLFBFile(byte) {
  18513. var fileLen;
  18514. var fileName;
  18515. var fileData;
  18516. fileName = byte.getUTFString();
  18517. fileLen = byte.getInt32();
  18518. fileData = byte.readArrayBuffer(fileLen);
  18519. Loader.preLoadedMap[URL.formatURL(fileName)] = fileData;
  18520. }
  18521. complete(data) {
  18522. this._data = data;
  18523. if (this._customParse) {
  18524. this.event(Event.LOADED, data instanceof Array ? [data] : data);
  18525. }
  18526. else {
  18527. Loader._loaders.push(this);
  18528. if (!Loader._isWorking)
  18529. Loader.checkNext();
  18530. }
  18531. }
  18532. static checkNext() {
  18533. Loader._isWorking = true;
  18534. var startTimer = Browser.now();
  18535. while (Loader._startIndex < Loader._loaders.length) {
  18536. Loader._loaders[Loader._startIndex].endLoad();
  18537. Loader._startIndex++;
  18538. if (Browser.now() - startTimer > Loader.maxTimeOut) {
  18539. console.warn("loader callback cost a long time:" + (Browser.now() - startTimer) + " url=" + Loader._loaders[Loader._startIndex - 1].url);
  18540. ILaya.systemTimer.frameOnce(1, null, Loader.checkNext);
  18541. return;
  18542. }
  18543. }
  18544. Loader._loaders.length = 0;
  18545. Loader._startIndex = 0;
  18546. Loader._isWorking = false;
  18547. }
  18548. endLoad(content = null) {
  18549. content && (this._data = content);
  18550. if (this._cache)
  18551. Loader.cacheRes(this._url, this._data);
  18552. this.event(Event.PROGRESS, 1);
  18553. this.event(Event.COMPLETE, this.data instanceof Array ? [this.data] : this.data);
  18554. }
  18555. get url() {
  18556. return this._url;
  18557. }
  18558. get type() {
  18559. return this._type;
  18560. }
  18561. get cache() {
  18562. return this._cache;
  18563. }
  18564. get data() {
  18565. return this._data;
  18566. }
  18567. static clearRes(url) {
  18568. url = URL.formatURL(url);
  18569. var arr = Loader.getAtlas(url);
  18570. if (arr) {
  18571. for (var i = 0, n = arr.length; i < n; i++) {
  18572. var resUrl = arr[i];
  18573. var tex = Loader.getRes(resUrl);
  18574. delete Loader.textureMap[resUrl];
  18575. if (tex)
  18576. tex.destroy();
  18577. }
  18578. arr.length = 0;
  18579. delete Loader.atlasMap[url];
  18580. }
  18581. var texture = Loader.textureMap[url];
  18582. if (texture) {
  18583. texture.destroy();
  18584. delete Loader.textureMap[url];
  18585. }
  18586. var res = Loader.loadedMap[url];
  18587. (res) && (delete Loader.loadedMap[url]);
  18588. }
  18589. static clearTextureRes(url) {
  18590. url = URL.formatURL(url);
  18591. var arr = Loader.getAtlas(url);
  18592. if (arr && arr.length > 0) {
  18593. arr.forEach(function (t) {
  18594. var tex = Loader.getRes(t);
  18595. if (tex instanceof Texture) {
  18596. tex.disposeBitmap();
  18597. }
  18598. });
  18599. }
  18600. else {
  18601. var t = Loader.getRes(url);
  18602. if (t instanceof Texture) {
  18603. t.disposeBitmap();
  18604. }
  18605. }
  18606. }
  18607. static getRes(url) {
  18608. var res = Loader.textureMap[URL.formatURL(url)];
  18609. if (res)
  18610. return res;
  18611. else
  18612. return Loader.loadedMap[URL.formatURL(url)];
  18613. }
  18614. static getAtlas(url) {
  18615. return Loader.atlasMap[URL.formatURL(url)];
  18616. }
  18617. static cacheRes(url, data) {
  18618. url = URL.formatURL(url);
  18619. if (Loader.loadedMap[url] != null) {
  18620. console.warn("Resources already exist,is repeated loading:", url);
  18621. }
  18622. else {
  18623. if (data instanceof Texture) {
  18624. Loader.loadedMap[url] = data.bitmap;
  18625. Loader.textureMap[url] = data;
  18626. }
  18627. else {
  18628. Loader.loadedMap[url] = data;
  18629. }
  18630. }
  18631. }
  18632. static cacheTexture(url, data) {
  18633. url = URL.formatURL(url);
  18634. if (Loader.textureMap[url] != null) {
  18635. console.warn("Resources already exist,is repeated loading:", url);
  18636. }
  18637. else {
  18638. Loader.textureMap[url] = data;
  18639. }
  18640. }
  18641. static setGroup(url, group) {
  18642. if (!Loader.groupMap[group])
  18643. Loader.groupMap[group] = [];
  18644. Loader.groupMap[group].push(url);
  18645. }
  18646. static clearResByGroup(group) {
  18647. if (!Loader.groupMap[group])
  18648. return;
  18649. var arr = Loader.groupMap[group], i, len = arr.length;
  18650. for (i = 0; i < len; i++) {
  18651. Loader.clearRes(arr[i]);
  18652. }
  18653. arr.length = 0;
  18654. }
  18655. }
  18656. Loader.TEXT = "text";
  18657. Loader.JSON = "json";
  18658. Loader.PREFAB = "prefab";
  18659. Loader.XML = "xml";
  18660. Loader.BUFFER = "arraybuffer";
  18661. Loader.IMAGE = "image";
  18662. Loader.SOUND = "sound";
  18663. Loader.ATLAS = "atlas";
  18664. Loader.FONT = "font";
  18665. Loader.TTF = "ttf";
  18666. Loader.PLF = "plf";
  18667. Loader.PLFB = "plfb";
  18668. Loader.HIERARCHY = "HIERARCHY";
  18669. Loader.MESH = "MESH";
  18670. Loader.MATERIAL = "MATERIAL";
  18671. Loader.TEXTURE2D = "TEXTURE2D";
  18672. Loader.TEXTURECUBE = "TEXTURECUBE";
  18673. Loader.ANIMATIONCLIP = "ANIMATIONCLIP";
  18674. Loader.AVATAR = "AVATAR";
  18675. Loader.TERRAINHEIGHTDATA = "TERRAINHEIGHTDATA";
  18676. Loader.TERRAINRES = "TERRAIN";
  18677. Loader.typeMap = { "ttf": "ttf", "png": "image", "jpg": "image", "jpeg": "image", "ktx": "image", "pvr": "image", "txt": "text", "json": "json", "prefab": "prefab", "xml": "xml", "als": "atlas", "atlas": "atlas", "mp3": "sound", "ogg": "sound", "wav": "sound", "part": "json", "fnt": "font", "plf": "plf", "plfb": "plfb", "scene": "json", "ani": "json", "sk": "arraybuffer" };
  18678. Loader.parserMap = {};
  18679. Loader.maxTimeOut = 100;
  18680. Loader.groupMap = {};
  18681. Loader.loadedMap = {};
  18682. Loader.atlasMap = {};
  18683. Loader.textureMap = {};
  18684. Loader.preLoadedMap = {};
  18685. Loader._imgCache = {};
  18686. Loader._loaders = [];
  18687. Loader._isWorking = false;
  18688. Loader._startIndex = 0;
  18689. class AtlasInfoManager {
  18690. static enable(infoFile, callback = null) {
  18691. ILaya.loader.load(infoFile, Handler.create(null, AtlasInfoManager._onInfoLoaded, [callback]), null, Loader.JSON);
  18692. }
  18693. static _onInfoLoaded(callback, data) {
  18694. var tKey;
  18695. var tPrefix;
  18696. var tArr;
  18697. var i, len;
  18698. for (tKey in data) {
  18699. tArr = data[tKey];
  18700. tPrefix = tArr[0];
  18701. tArr = tArr[1];
  18702. len = tArr.length;
  18703. for (i = 0; i < len; i++) {
  18704. AtlasInfoManager._fileLoadDic[tPrefix + tArr[i]] = tKey;
  18705. }
  18706. }
  18707. callback && callback.run();
  18708. }
  18709. static getFileLoadPath(file) {
  18710. return AtlasInfoManager._fileLoadDic[file] || file;
  18711. }
  18712. }
  18713. AtlasInfoManager._fileLoadDic = {};
  18714. class LoaderManager extends EventDispatcher {
  18715. constructor() {
  18716. super();
  18717. this.retryNum = 1;
  18718. this.retryDelay = 0;
  18719. this.maxLoader = 5;
  18720. this._loaders = [];
  18721. this._loaderCount = 0;
  18722. this._resInfos = [];
  18723. this._infoPool = [];
  18724. this._maxPriority = 5;
  18725. this._failRes = {};
  18726. this._statInfo = { count: 1, loaded: 1 };
  18727. for (var i = 0; i < this._maxPriority; i++)
  18728. this._resInfos[i] = [];
  18729. }
  18730. getProgress() {
  18731. return this._statInfo.loaded / this._statInfo.count;
  18732. }
  18733. resetProgress() {
  18734. this._statInfo.count = this._statInfo.loaded = 1;
  18735. }
  18736. create(url, complete = null, progress = null, type = null, constructParams = null, propertyParams = null, priority = 1, cache = true) {
  18737. this._create(url, true, complete, progress, type, constructParams, propertyParams, priority, cache);
  18738. }
  18739. _create(url, mainResou, complete = null, progress = null, type = null, constructParams = null, propertyParams = null, priority = 1, cache = true) {
  18740. if (url instanceof Array) {
  18741. var allScuess = true;
  18742. var items = url;
  18743. var itemCount = items.length;
  18744. var loadedCount = 0;
  18745. if (progress) {
  18746. var progress2 = Handler.create(progress.caller, progress ? progress.method : null, progress.args, false);
  18747. }
  18748. for (var i = 0; i < itemCount; i++) {
  18749. var item = items[i];
  18750. if (typeof (item) == 'string')
  18751. item = items[i] = { url: item };
  18752. item.progress = 0;
  18753. }
  18754. for (i = 0; i < itemCount; i++) {
  18755. item = items[i];
  18756. var progressHandler = progress ? Handler.create(null, function (item, value) {
  18757. item.progress = value;
  18758. var num = 0;
  18759. for (var j = 0; j < itemCount; j++) {
  18760. var item1 = items[j];
  18761. num += item1.progress;
  18762. }
  18763. var v = num / itemCount;
  18764. progress2.runWith(v);
  18765. }, [item], false) : null;
  18766. var completeHandler = (progress || complete) ? Handler.create(null, function (item, content = null) {
  18767. loadedCount++;
  18768. item.progress = 1;
  18769. content || (allScuess = false);
  18770. if (loadedCount === itemCount && complete) {
  18771. complete.runWith(allScuess);
  18772. }
  18773. }, [item]) : null;
  18774. this._createOne(item.url, mainResou, completeHandler, progressHandler, item.type || type, item.constructParams || constructParams, item.propertyParams || propertyParams, item.priority || priority, cache);
  18775. }
  18776. }
  18777. else {
  18778. this._createOne(url, mainResou, complete, progress, type, constructParams, propertyParams, priority, cache);
  18779. }
  18780. }
  18781. _createOne(url, mainResou, complete = null, progress = null, type = null, constructParams = null, propertyParams = null, priority = 1, cache = true) {
  18782. var item = this.getRes(url);
  18783. if (!item) {
  18784. var extension = Utils.getFileExtension(url);
  18785. (type) || (type = LoaderManager.createMap[extension] ? LoaderManager.createMap[extension][0] : null);
  18786. if (!type) {
  18787. this.load(url, complete, progress, type, priority, cache);
  18788. return;
  18789. }
  18790. var parserMap = Loader.parserMap;
  18791. if (!parserMap[type]) {
  18792. this.load(url, complete, progress, type, priority, cache);
  18793. return;
  18794. }
  18795. this._createLoad(url, Handler.create(null, function (createRes) {
  18796. if (createRes) {
  18797. if (!mainResou && createRes instanceof Resource)
  18798. createRes._addReference();
  18799. createRes._setCreateURL(url);
  18800. }
  18801. complete && complete.runWith(createRes);
  18802. ILaya.loader.event(url);
  18803. }), progress, type, constructParams, propertyParams, priority, cache, true);
  18804. }
  18805. else {
  18806. if (!mainResou && item instanceof Resource)
  18807. item._addReference();
  18808. progress && progress.runWith(1);
  18809. complete && complete.runWith(item);
  18810. }
  18811. }
  18812. load(url, complete = null, progress = null, type = null, priority = 1, cache = true, group = null, ignoreCache = false, useWorkerLoader = ILaya.WorkerLoader.enable) {
  18813. if (url instanceof Array) {
  18814. return this._loadAssets(url, complete, progress, type, priority, cache, group);
  18815. }
  18816. var content;
  18817. if (type === Loader.IMAGE)
  18818. content = Loader.textureMap[URL.formatURL(url)];
  18819. else
  18820. content = Loader.loadedMap[URL.formatURL(url)];
  18821. if (!ignoreCache && content != null) {
  18822. ILaya.systemTimer.frameOnce(1, this, function () {
  18823. progress && progress.runWith(1);
  18824. complete && complete.runWith(content instanceof Array ? [content] : content);
  18825. this._loaderCount || this.event(Event.COMPLETE);
  18826. });
  18827. }
  18828. else {
  18829. var original;
  18830. original = url;
  18831. url = AtlasInfoManager.getFileLoadPath(url);
  18832. if (url != original && type !== "nativeimage") {
  18833. type = Loader.ATLAS;
  18834. }
  18835. else {
  18836. original = null;
  18837. }
  18838. var info = LoaderManager._resMap[url];
  18839. if (!info) {
  18840. info = this._infoPool.length ? this._infoPool.pop() : new ResInfo();
  18841. info.url = url;
  18842. info.type = type;
  18843. info.cache = cache;
  18844. info.group = group;
  18845. info.ignoreCache = ignoreCache;
  18846. info.useWorkerLoader = useWorkerLoader;
  18847. info.originalUrl = original;
  18848. complete && info.on(Event.COMPLETE, complete.caller, complete.method, complete.args);
  18849. progress && info.on(Event.PROGRESS, progress.caller, progress.method, progress.args);
  18850. LoaderManager._resMap[url] = info;
  18851. priority = priority < this._maxPriority ? priority : this._maxPriority - 1;
  18852. this._resInfos[priority].push(info);
  18853. this._statInfo.count++;
  18854. this.event(Event.PROGRESS, this.getProgress());
  18855. this._next();
  18856. }
  18857. else {
  18858. if (complete) {
  18859. if (original) {
  18860. complete && info._createListener(Event.COMPLETE, this, this._resInfoLoaded, [original, complete], false, false);
  18861. }
  18862. else {
  18863. complete && info._createListener(Event.COMPLETE, complete.caller, complete.method, complete.args, false, false);
  18864. }
  18865. }
  18866. progress && info._createListener(Event.PROGRESS, progress.caller, progress.method, progress.args, false, false);
  18867. }
  18868. }
  18869. return this;
  18870. }
  18871. _resInfoLoaded(original, complete) {
  18872. complete.runWith(Loader.getRes(original));
  18873. }
  18874. _createLoad(url, complete = null, progress = null, type = null, constructParams = null, propertyParams = null, priority = 1, cache = true, ignoreCache = false) {
  18875. if (url instanceof Array)
  18876. return this._loadAssets(url, complete, progress, type, priority, cache);
  18877. var content = Loader.getRes(url);
  18878. if (content != null) {
  18879. ILaya.systemTimer.frameOnce(1, this, function () {
  18880. progress && progress.runWith(1);
  18881. complete && complete.runWith(content);
  18882. this._loaderCount || this.event(Event.COMPLETE);
  18883. });
  18884. }
  18885. else {
  18886. var info = LoaderManager._resMap[url];
  18887. if (!info) {
  18888. info = this._infoPool.length ? this._infoPool.pop() : new ResInfo();
  18889. info.url = url;
  18890. info.type = type;
  18891. info.cache = false;
  18892. info.ignoreCache = ignoreCache;
  18893. info.originalUrl = null;
  18894. info.group = null;
  18895. info.createCache = cache;
  18896. info.createConstructParams = constructParams;
  18897. info.createPropertyParams = propertyParams;
  18898. complete && info.on(Event.COMPLETE, complete.caller, complete.method, complete.args);
  18899. progress && info.on(Event.PROGRESS, progress.caller, progress.method, progress.args);
  18900. LoaderManager._resMap[url] = info;
  18901. priority = priority < this._maxPriority ? priority : this._maxPriority - 1;
  18902. this._resInfos[priority].push(info);
  18903. this._statInfo.count++;
  18904. this.event(Event.PROGRESS, this.getProgress());
  18905. this._next();
  18906. }
  18907. else {
  18908. complete && info._createListener(Event.COMPLETE, complete.caller, complete.method, complete.args, false, false);
  18909. progress && info._createListener(Event.PROGRESS, progress.caller, progress.method, progress.args, false, false);
  18910. }
  18911. }
  18912. return this;
  18913. }
  18914. _next() {
  18915. if (this._loaderCount >= this.maxLoader)
  18916. return;
  18917. for (var i = 0; i < this._maxPriority; i++) {
  18918. var infos = this._resInfos[i];
  18919. while (infos.length > 0) {
  18920. var info = infos.shift();
  18921. if (info)
  18922. return this._doLoad(info);
  18923. }
  18924. }
  18925. this._loaderCount || this.event(Event.COMPLETE);
  18926. }
  18927. _doLoad(resInfo) {
  18928. this._loaderCount++;
  18929. var loader = this._loaders.length ? this._loaders.pop() : new Loader();
  18930. loader.on(Event.COMPLETE, null, onLoaded);
  18931. loader.on(Event.PROGRESS, null, function (num) {
  18932. resInfo.event(Event.PROGRESS, num);
  18933. });
  18934. loader.on(Event.ERROR, null, function (msg) {
  18935. onLoaded(null);
  18936. });
  18937. var _me = this;
  18938. function onLoaded(data = null) {
  18939. loader.offAll();
  18940. loader._data = null;
  18941. loader._customParse = false;
  18942. _me._loaders.push(loader);
  18943. _me._endLoad(resInfo, data instanceof Array ? [data] : data);
  18944. _me._loaderCount--;
  18945. _me._next();
  18946. }
  18947. loader._constructParams = resInfo.createConstructParams;
  18948. loader._propertyParams = resInfo.createPropertyParams;
  18949. loader._createCache = resInfo.createCache;
  18950. loader.load(resInfo.url, resInfo.type, resInfo.cache, resInfo.group, resInfo.ignoreCache, resInfo.useWorkerLoader);
  18951. }
  18952. _endLoad(resInfo, content) {
  18953. var url = resInfo.url;
  18954. if (content == null) {
  18955. var errorCount = this._failRes[url] || 0;
  18956. if (errorCount < this.retryNum) {
  18957. console.warn("[warn]Retry to load:", url);
  18958. this._failRes[url] = errorCount + 1;
  18959. ILaya.systemTimer.once(this.retryDelay, this, this._addReTry, [resInfo], false);
  18960. return;
  18961. }
  18962. else {
  18963. Loader.clearRes(url);
  18964. console.warn("[error]Failed to load:", url);
  18965. this.event(Event.ERROR, url);
  18966. }
  18967. }
  18968. if (this._failRes[url])
  18969. this._failRes[url] = 0;
  18970. delete LoaderManager._resMap[url];
  18971. if (resInfo.originalUrl) {
  18972. content = Loader.getRes(resInfo.originalUrl);
  18973. }
  18974. resInfo.event(Event.COMPLETE, content);
  18975. resInfo.offAll();
  18976. this._infoPool.push(resInfo);
  18977. this._statInfo.loaded++;
  18978. this.event(Event.PROGRESS, this.getProgress());
  18979. }
  18980. _addReTry(resInfo) {
  18981. this._resInfos[this._maxPriority - 1].push(resInfo);
  18982. this._next();
  18983. }
  18984. clearRes(url) {
  18985. Loader.clearRes(url);
  18986. }
  18987. clearTextureRes(url) {
  18988. Loader.clearTextureRes(url);
  18989. }
  18990. getRes(url) {
  18991. return Loader.getRes(url);
  18992. }
  18993. cacheRes(url, data) {
  18994. Loader.cacheRes(url, data);
  18995. }
  18996. setGroup(url, group) {
  18997. Loader.setGroup(url, group);
  18998. }
  18999. clearResByGroup(group) {
  19000. Loader.clearResByGroup(group);
  19001. }
  19002. static cacheRes(url, data) {
  19003. Loader.cacheRes(url, data);
  19004. }
  19005. clearUnLoaded() {
  19006. for (var i = 0; i < this._maxPriority; i++) {
  19007. var infos = this._resInfos[i];
  19008. for (var j = infos.length - 1; j > -1; j--) {
  19009. var info = infos[j];
  19010. if (info) {
  19011. info.offAll();
  19012. this._infoPool.push(info);
  19013. }
  19014. }
  19015. infos.length = 0;
  19016. }
  19017. this._loaderCount = 0;
  19018. LoaderManager._resMap = {};
  19019. }
  19020. cancelLoadByUrls(urls) {
  19021. if (!urls)
  19022. return;
  19023. for (var i = 0, n = urls.length; i < n; i++) {
  19024. this.cancelLoadByUrl(urls[i]);
  19025. }
  19026. }
  19027. cancelLoadByUrl(url) {
  19028. for (var i = 0; i < this._maxPriority; i++) {
  19029. var infos = this._resInfos[i];
  19030. for (var j = infos.length - 1; j > -1; j--) {
  19031. var info = infos[j];
  19032. if (info && info.url === url) {
  19033. infos[j] = null;
  19034. info.offAll();
  19035. this._infoPool.push(info);
  19036. }
  19037. }
  19038. }
  19039. if (LoaderManager._resMap[url])
  19040. delete LoaderManager._resMap[url];
  19041. }
  19042. _loadAssets(arr, complete = null, progress = null, type = null, priority = 1, cache = true, group = null) {
  19043. var itemCount = arr.length;
  19044. var loadedCount = 0;
  19045. var totalSize = 0;
  19046. var items = [];
  19047. var success = true;
  19048. for (var i = 0; i < itemCount; i++) {
  19049. let url = arr[i];
  19050. let item;
  19051. if (typeof (url) == 'string')
  19052. item = { url: url, type: type, size: 1, priority: priority };
  19053. else
  19054. item = url;
  19055. if (!item.size)
  19056. item.size = 1;
  19057. item.progress = 0;
  19058. totalSize += item.size;
  19059. items.push(item);
  19060. var progressHandler = progress ? Handler.create(null, loadProgress, [item], false) : null;
  19061. var completeHandler = (complete || progress) ? Handler.create(null, loadComplete, [item]) : null;
  19062. this.load(item.url, completeHandler, progressHandler, item.type, item.priority || 1, cache, item.group || group, false, item.useWorkerLoader);
  19063. }
  19064. function loadComplete(item, content = null) {
  19065. loadedCount++;
  19066. item.progress = 1;
  19067. if (!content)
  19068. success = false;
  19069. if (loadedCount === itemCount && complete) {
  19070. complete.runWith(success);
  19071. }
  19072. }
  19073. function loadProgress(item, value) {
  19074. if (progress != null) {
  19075. item.progress = value;
  19076. var num = 0;
  19077. for (var j = 0; j < items.length; j++) {
  19078. var item1 = items[j];
  19079. if (item1) {
  19080. let prog = item1.progress == undefined ? 0 : item1.progress;
  19081. num += item1.size == undefined ? 0 : item1.size * prog;
  19082. }
  19083. }
  19084. var v = num / totalSize;
  19085. progress.runWith(v);
  19086. }
  19087. }
  19088. return this;
  19089. }
  19090. decodeBitmaps(urls) {
  19091. var i, len = urls.length;
  19092. var ctx;
  19093. ctx = ILaya.Render._context;
  19094. for (i = 0; i < len; i++) {
  19095. var atlas;
  19096. atlas = Loader.getAtlas(urls[i]);
  19097. if (atlas) {
  19098. this._decodeTexture(atlas[0], ctx);
  19099. }
  19100. else {
  19101. var tex;
  19102. tex = this.getRes(urls[i]);
  19103. if (tex && tex instanceof Texture) {
  19104. this._decodeTexture(tex, ctx);
  19105. }
  19106. }
  19107. }
  19108. }
  19109. _decodeTexture(tex, ctx) {
  19110. var bitmap = tex.bitmap;
  19111. if (!tex || !bitmap)
  19112. return;
  19113. var tImg = bitmap.source || bitmap.image;
  19114. if (!tImg)
  19115. return;
  19116. if (tImg instanceof HTMLImageElement) {
  19117. ctx.drawImage(tImg, 0, 0, 1, 1);
  19118. var info = ctx.getImageData(0, 0, 1, 1);
  19119. }
  19120. }
  19121. }
  19122. LoaderManager._resMap = {};
  19123. LoaderManager.createMap = { atlas: [null, Loader.ATLAS] };
  19124. class ResInfo extends EventDispatcher {
  19125. }
  19126. class LocalStorage {
  19127. static __init__() {
  19128. if (!LocalStorage._baseClass) {
  19129. LocalStorage._baseClass = Storage;
  19130. Storage.init();
  19131. }
  19132. LocalStorage.items = LocalStorage._baseClass.items;
  19133. LocalStorage.support = LocalStorage._baseClass.support;
  19134. return LocalStorage.support;
  19135. }
  19136. static setItem(key, value) {
  19137. LocalStorage._baseClass.setItem(key, value);
  19138. }
  19139. static getItem(key) {
  19140. return LocalStorage._baseClass.getItem(key);
  19141. }
  19142. static setJSON(key, value) {
  19143. LocalStorage._baseClass.setJSON(key, value);
  19144. }
  19145. static getJSON(key) {
  19146. return LocalStorage._baseClass.getJSON(key);
  19147. }
  19148. static removeItem(key) {
  19149. LocalStorage._baseClass.removeItem(key);
  19150. }
  19151. static clear() {
  19152. LocalStorage._baseClass.clear();
  19153. }
  19154. }
  19155. LocalStorage.support = false;
  19156. class Storage {
  19157. static init() {
  19158. try {
  19159. Storage.support = true;
  19160. Storage.items = window.localStorage;
  19161. Storage.setItem('laya', '1');
  19162. Storage.removeItem('laya');
  19163. }
  19164. catch (e) {
  19165. Storage.support = false;
  19166. }
  19167. if (!Storage.support)
  19168. console.log('LocalStorage is not supprot or browser is private mode.');
  19169. }
  19170. static setItem(key, value) {
  19171. try {
  19172. Storage.support && Storage.items.setItem(key, value);
  19173. }
  19174. catch (e) {
  19175. console.warn("set localStorage failed", e);
  19176. }
  19177. }
  19178. static getItem(key) {
  19179. return Storage.support ? Storage.items.getItem(key) : null;
  19180. }
  19181. static setJSON(key, value) {
  19182. try {
  19183. Storage.support && Storage.items.setItem(key, JSON.stringify(value));
  19184. }
  19185. catch (e) {
  19186. console.warn("set localStorage failed", e);
  19187. }
  19188. }
  19189. static getJSON(key) {
  19190. return JSON.parse(Storage.support ? Storage.items.getItem(key) : null);
  19191. }
  19192. static removeItem(key) {
  19193. Storage.support && Storage.items.removeItem(key);
  19194. }
  19195. static clear() {
  19196. Storage.support && Storage.items.clear();
  19197. }
  19198. }
  19199. Storage.support = false;
  19200. class TTFLoader {
  19201. load(fontPath) {
  19202. this._url = fontPath;
  19203. var tArr = fontPath.split(".ttf")[0].split("/");
  19204. this.fontName = tArr[tArr.length - 1];
  19205. if (ILaya.Render.isConchApp) {
  19206. this._loadConch();
  19207. }
  19208. else if (window.FontFace) {
  19209. this._loadWithFontFace();
  19210. }
  19211. else {
  19212. this._loadWithCSS();
  19213. }
  19214. }
  19215. _loadConch() {
  19216. this._http = new HttpRequest();
  19217. this._http.on(Event.ERROR, this, this._onErr);
  19218. this._http.on(Event.COMPLETE, this, this._onHttpLoaded);
  19219. this._http.send(this._url, null, "get", Loader.BUFFER);
  19220. }
  19221. _onHttpLoaded(data = null) {
  19222. window["conchTextCanvas"].setFontFaceFromBuffer(this.fontName, data);
  19223. this._clearHttp();
  19224. this._complete();
  19225. }
  19226. _clearHttp() {
  19227. if (this._http) {
  19228. this._http.off(Event.ERROR, this, this._onErr);
  19229. this._http.off(Event.COMPLETE, this, this._onHttpLoaded);
  19230. this._http = null;
  19231. }
  19232. }
  19233. _onErr() {
  19234. this._clearHttp();
  19235. if (this.err) {
  19236. this.err.runWith("fail:" + this._url);
  19237. this.err = null;
  19238. }
  19239. }
  19240. _complete() {
  19241. ILaya.systemTimer.clear(this, this._complete);
  19242. ILaya.systemTimer.clear(this, this._checkComplete);
  19243. if (this._div && this._div.parentNode) {
  19244. this._div.parentNode.removeChild(this._div);
  19245. this._div = null;
  19246. }
  19247. if (this.complete) {
  19248. this.complete.runWith(this);
  19249. this.complete = null;
  19250. }
  19251. }
  19252. _checkComplete() {
  19253. if (ILaya.Browser.measureText(TTFLoader._testString, this._fontTxt).width != this._txtWidth) {
  19254. this._complete();
  19255. }
  19256. }
  19257. _loadWithFontFace() {
  19258. var fontFace = new window.FontFace(this.fontName, "url('" + this._url + "')");
  19259. document.fonts.add(fontFace);
  19260. var self = this;
  19261. fontFace.loaded.then((function () {
  19262. self._complete();
  19263. }));
  19264. fontFace.load();
  19265. }
  19266. _createDiv() {
  19267. this._div = Browser.createElement("div");
  19268. this._div.innerHTML = "laya";
  19269. var _style = this._div.style;
  19270. _style.fontFamily = this.fontName;
  19271. _style.position = "absolute";
  19272. _style.left = "-100px";
  19273. _style.top = "-100px";
  19274. document.body.appendChild(this._div);
  19275. }
  19276. _loadWithCSS() {
  19277. var fontStyle = Browser.createElement("style");
  19278. fontStyle.type = "text/css";
  19279. document.body.appendChild(fontStyle);
  19280. fontStyle.textContent = "@font-face { font-family:'" + this.fontName + "'; src:url('" + this._url + "');}";
  19281. this._fontTxt = "40px " + this.fontName;
  19282. this._txtWidth = Browser.measureText(TTFLoader._testString, this._fontTxt).width;
  19283. var self = this;
  19284. fontStyle.onload = function () {
  19285. ILaya.systemTimer.once(10000, self, this._complete);
  19286. };
  19287. ILaya.systemTimer.loop(20, this, this._checkComplete);
  19288. this._createDiv();
  19289. }
  19290. }
  19291. TTFLoader._testString = "LayaTTFFont";
  19292. class Ease {
  19293. static linearNone(t, b, c, d) {
  19294. return c * t / d + b;
  19295. }
  19296. static linearIn(t, b, c, d) {
  19297. return c * t / d + b;
  19298. }
  19299. static linearInOut(t, b, c, d) {
  19300. return c * t / d + b;
  19301. }
  19302. static linearOut(t, b, c, d) {
  19303. return c * t / d + b;
  19304. }
  19305. static bounceIn(t, b, c, d) {
  19306. return c - Ease.bounceOut(d - t, 0, c, d) + b;
  19307. }
  19308. static bounceInOut(t, b, c, d) {
  19309. if (t < d * 0.5)
  19310. return Ease.bounceIn(t * 2, 0, c, d) * .5 + b;
  19311. else
  19312. return Ease.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
  19313. }
  19314. static bounceOut(t, b, c, d) {
  19315. if ((t /= d) < (1 / 2.75))
  19316. return c * (7.5625 * t * t) + b;
  19317. else if (t < (2 / 2.75))
  19318. return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
  19319. else if (t < (2.5 / 2.75))
  19320. return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
  19321. else
  19322. return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
  19323. }
  19324. static backIn(t, b, c, d, s = 1.70158) {
  19325. return c * (t /= d) * t * ((s + 1) * t - s) + b;
  19326. }
  19327. static backInOut(t, b, c, d, s = 1.70158) {
  19328. if ((t /= d * 0.5) < 1)
  19329. return c * 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
  19330. return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
  19331. }
  19332. static backOut(t, b, c, d, s = 1.70158) {
  19333. return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
  19334. }
  19335. static elasticIn(t, b, c, d, a = 0, p = 0) {
  19336. var s;
  19337. if (t == 0)
  19338. return b;
  19339. if ((t /= d) == 1)
  19340. return b + c;
  19341. if (!p)
  19342. p = d * .3;
  19343. if (!a || (c > 0 && a < c) || (c < 0 && a < -c)) {
  19344. a = c;
  19345. s = p / 4;
  19346. }
  19347. else
  19348. s = p / Ease.PI2 * Math.asin(c / a);
  19349. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * Ease.PI2 / p)) + b;
  19350. }
  19351. static elasticInOut(t, b, c, d, a = 0, p = 0) {
  19352. var s;
  19353. if (t == 0)
  19354. return b;
  19355. if ((t /= d * 0.5) == 2)
  19356. return b + c;
  19357. if (!p)
  19358. p = d * (.3 * 1.5);
  19359. if (!a || (c > 0 && a < c) || (c < 0 && a < -c)) {
  19360. a = c;
  19361. s = p / 4;
  19362. }
  19363. else
  19364. s = p / Ease.PI2 * Math.asin(c / a);
  19365. if (t < 1)
  19366. return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * Ease.PI2 / p)) + b;
  19367. return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * Ease.PI2 / p) * .5 + c + b;
  19368. }
  19369. static elasticOut(t, b, c, d, a = 0, p = 0) {
  19370. var s;
  19371. if (t == 0)
  19372. return b;
  19373. if ((t /= d) == 1)
  19374. return b + c;
  19375. if (!p)
  19376. p = d * .3;
  19377. if (!a || (c > 0 && a < c) || (c < 0 && a < -c)) {
  19378. a = c;
  19379. s = p / 4;
  19380. }
  19381. else
  19382. s = p / Ease.PI2 * Math.asin(c / a);
  19383. return (a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * Ease.PI2 / p) + c + b);
  19384. }
  19385. static strongIn(t, b, c, d) {
  19386. return c * (t /= d) * t * t * t * t + b;
  19387. }
  19388. static strongInOut(t, b, c, d) {
  19389. if ((t /= d * 0.5) < 1)
  19390. return c * 0.5 * t * t * t * t * t + b;
  19391. return c * 0.5 * ((t -= 2) * t * t * t * t + 2) + b;
  19392. }
  19393. static strongOut(t, b, c, d) {
  19394. return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
  19395. }
  19396. static sineInOut(t, b, c, d) {
  19397. return -c * 0.5 * (Math.cos(Math.PI * t / d) - 1) + b;
  19398. }
  19399. static sineIn(t, b, c, d) {
  19400. return -c * Math.cos(t / d * Ease.HALF_PI) + c + b;
  19401. }
  19402. static sineOut(t, b, c, d) {
  19403. return c * Math.sin(t / d * Ease.HALF_PI) + b;
  19404. }
  19405. static quintIn(t, b, c, d) {
  19406. return c * (t /= d) * t * t * t * t + b;
  19407. }
  19408. static quintInOut(t, b, c, d) {
  19409. if ((t /= d * 0.5) < 1)
  19410. return c * 0.5 * t * t * t * t * t + b;
  19411. return c * 0.5 * ((t -= 2) * t * t * t * t + 2) + b;
  19412. }
  19413. static quintOut(t, b, c, d) {
  19414. return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
  19415. }
  19416. static quartIn(t, b, c, d) {
  19417. return c * (t /= d) * t * t * t + b;
  19418. }
  19419. static quartInOut(t, b, c, d) {
  19420. if ((t /= d * 0.5) < 1)
  19421. return c * 0.5 * t * t * t * t + b;
  19422. return -c * 0.5 * ((t -= 2) * t * t * t - 2) + b;
  19423. }
  19424. static quartOut(t, b, c, d) {
  19425. return -c * ((t = t / d - 1) * t * t * t - 1) + b;
  19426. }
  19427. static cubicIn(t, b, c, d) {
  19428. return c * (t /= d) * t * t + b;
  19429. }
  19430. static cubicInOut(t, b, c, d) {
  19431. if ((t /= d * 0.5) < 1)
  19432. return c * 0.5 * t * t * t + b;
  19433. return c * 0.5 * ((t -= 2) * t * t + 2) + b;
  19434. }
  19435. static cubicOut(t, b, c, d) {
  19436. return c * ((t = t / d - 1) * t * t + 1) + b;
  19437. }
  19438. static quadIn(t, b, c, d) {
  19439. return c * (t /= d) * t + b;
  19440. }
  19441. static quadInOut(t, b, c, d) {
  19442. if ((t /= d * 0.5) < 1)
  19443. return c * 0.5 * t * t + b;
  19444. return -c * 0.5 * ((--t) * (t - 2) - 1) + b;
  19445. }
  19446. static quadOut(t, b, c, d) {
  19447. return -c * (t /= d) * (t - 2) + b;
  19448. }
  19449. static expoIn(t, b, c, d) {
  19450. return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b - c * 0.001;
  19451. }
  19452. static expoInOut(t, b, c, d) {
  19453. if (t == 0)
  19454. return b;
  19455. if (t == d)
  19456. return b + c;
  19457. if ((t /= d * 0.5) < 1)
  19458. return c * 0.5 * Math.pow(2, 10 * (t - 1)) + b;
  19459. return c * 0.5 * (-Math.pow(2, -10 * --t) + 2) + b;
  19460. }
  19461. static expoOut(t, b, c, d) {
  19462. return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
  19463. }
  19464. static circIn(t, b, c, d) {
  19465. return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
  19466. }
  19467. static circInOut(t, b, c, d) {
  19468. if ((t /= d * 0.5) < 1)
  19469. return -c * 0.5 * (Math.sqrt(1 - t * t) - 1) + b;
  19470. return c * 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
  19471. }
  19472. static circOut(t, b, c, d) {
  19473. return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
  19474. }
  19475. }
  19476. Ease.HALF_PI = Math.PI * 0.5;
  19477. Ease.PI2 = Math.PI * 2;
  19478. class Tween {
  19479. constructor() {
  19480. this.gid = 0;
  19481. this.repeat = 1;
  19482. this._count = 0;
  19483. }
  19484. static to(target, props, duration, ease = null, complete = null, delay = 0, coverBefore = false, autoRecover = true) {
  19485. return Pool.getItemByClass("tween", Tween)._create(target, props, duration, ease, complete, delay, coverBefore, true, autoRecover, true);
  19486. }
  19487. static from(target, props, duration, ease = null, complete = null, delay = 0, coverBefore = false, autoRecover = true) {
  19488. return Pool.getItemByClass("tween", Tween)._create(target, props, duration, ease, complete, delay, coverBefore, false, autoRecover, true);
  19489. }
  19490. to(target, props, duration, ease = null, complete = null, delay = 0, coverBefore = false) {
  19491. return this._create(target, props, duration, ease, complete, delay, coverBefore, true, false, true);
  19492. }
  19493. from(target, props, duration, ease = null, complete = null, delay = 0, coverBefore = false) {
  19494. return this._create(target, props, duration, ease, complete, delay, coverBefore, false, false, true);
  19495. }
  19496. _create(target, props, duration, ease, complete, delay, coverBefore, isTo, usePool, runNow) {
  19497. if (!target)
  19498. throw new Error("Tween:target is null");
  19499. this._target = target;
  19500. this._duration = duration;
  19501. this._ease = ease || props.ease || Tween.easeNone;
  19502. this._complete = complete || props.complete;
  19503. this._delay = delay;
  19504. this._props = [];
  19505. this._usedTimer = 0;
  19506. this._startTimer = Browser.now();
  19507. this._usedPool = usePool;
  19508. this._delayParam = null;
  19509. this.update = props.update;
  19510. var gid = (target.$_GID || (target.$_GID = Utils.getGID()));
  19511. if (!Tween.tweenMap[gid]) {
  19512. Tween.tweenMap[gid] = [this];
  19513. }
  19514. else {
  19515. if (coverBefore)
  19516. Tween.clearTween(target);
  19517. Tween.tweenMap[gid].push(this);
  19518. }
  19519. if (runNow) {
  19520. if (delay <= 0)
  19521. this.firstStart(target, props, isTo);
  19522. else {
  19523. this._delayParam = [target, props, isTo];
  19524. ILaya.timer.once(delay, this, this.firstStart, this._delayParam);
  19525. }
  19526. }
  19527. else {
  19528. this._initProps(target, props, isTo);
  19529. }
  19530. return this;
  19531. }
  19532. firstStart(target, props, isTo) {
  19533. this._delayParam = null;
  19534. if (target.destroyed) {
  19535. this.clear();
  19536. return;
  19537. }
  19538. this._initProps(target, props, isTo);
  19539. this._beginLoop();
  19540. }
  19541. _initProps(target, props, isTo) {
  19542. for (var p in props) {
  19543. if (typeof (target[p]) == 'number') {
  19544. var start = isTo ? target[p] : props[p];
  19545. var end = isTo ? props[p] : target[p];
  19546. this._props.push([p, start, end - start]);
  19547. if (!isTo)
  19548. target[p] = start;
  19549. }
  19550. }
  19551. }
  19552. _beginLoop() {
  19553. ILaya.timer.frameLoop(1, this, this._doEase);
  19554. }
  19555. _doEase() {
  19556. this._updateEase(Browser.now());
  19557. }
  19558. _updateEase(time) {
  19559. var target = this._target;
  19560. if (!target)
  19561. return;
  19562. if (target.destroyed)
  19563. return Tween.clearTween(target);
  19564. var usedTimer = this._usedTimer = time - this._startTimer - this._delay;
  19565. if (usedTimer < 0)
  19566. return;
  19567. if (usedTimer >= this._duration)
  19568. return this.complete();
  19569. var ratio = usedTimer > 0 ? this._ease(usedTimer, 0, 1, this._duration) : 0;
  19570. var props = this._props;
  19571. for (var i = 0, n = props.length; i < n; i++) {
  19572. var prop = props[i];
  19573. target[prop[0]] = prop[1] + (ratio * prop[2]);
  19574. }
  19575. if (this.update)
  19576. this.update.run();
  19577. }
  19578. set progress(v) {
  19579. var uTime = v * this._duration;
  19580. this._startTimer = Browser.now() - this._delay - uTime;
  19581. }
  19582. complete() {
  19583. if (!this._target)
  19584. return;
  19585. ILaya.timer.runTimer(this, this.firstStart);
  19586. var target = this._target;
  19587. var props = this._props;
  19588. var handler = this._complete;
  19589. for (var i = 0, n = props.length; i < n; i++) {
  19590. var prop = props[i];
  19591. target[prop[0]] = prop[1] + prop[2];
  19592. }
  19593. if (this.update)
  19594. this.update.run();
  19595. this._count++;
  19596. if (this.repeat != 0 && this._count >= this.repeat) {
  19597. this.clear();
  19598. handler && handler.run();
  19599. }
  19600. else {
  19601. this.restart();
  19602. }
  19603. }
  19604. pause() {
  19605. ILaya.timer.clear(this, this._beginLoop);
  19606. ILaya.timer.clear(this, this._doEase);
  19607. ILaya.timer.clear(this, this.firstStart);
  19608. var time = Browser.now();
  19609. var dTime;
  19610. dTime = time - this._startTimer - this._delay;
  19611. if (dTime < 0) {
  19612. this._usedTimer = dTime;
  19613. }
  19614. }
  19615. setStartTime(startTime) {
  19616. this._startTimer = startTime;
  19617. }
  19618. static clearAll(target) {
  19619. if (!target || !target.$_GID)
  19620. return;
  19621. var tweens = Tween.tweenMap[target.$_GID];
  19622. if (tweens) {
  19623. for (var i = 0, n = tweens.length; i < n; i++) {
  19624. tweens[i]._clear();
  19625. }
  19626. tweens.length = 0;
  19627. }
  19628. }
  19629. static clear(tween) {
  19630. tween.clear();
  19631. }
  19632. static clearTween(target) {
  19633. Tween.clearAll(target);
  19634. }
  19635. clear() {
  19636. if (this._target) {
  19637. this._remove();
  19638. this._clear();
  19639. }
  19640. }
  19641. _clear() {
  19642. this.pause();
  19643. ILaya.timer.clear(this, this.firstStart);
  19644. this._complete = null;
  19645. this._target = null;
  19646. this._ease = null;
  19647. this._props = null;
  19648. this._delayParam = null;
  19649. if (this._usedPool) {
  19650. this.update = null;
  19651. Pool.recover("tween", this);
  19652. }
  19653. }
  19654. recover() {
  19655. this._usedPool = true;
  19656. this._clear();
  19657. }
  19658. _remove() {
  19659. var tweens = Tween.tweenMap[this._target.$_GID];
  19660. if (tweens) {
  19661. for (var i = 0, n = tweens.length; i < n; i++) {
  19662. if (tweens[i] === this) {
  19663. tweens.splice(i, 1);
  19664. break;
  19665. }
  19666. }
  19667. }
  19668. }
  19669. restart() {
  19670. this.pause();
  19671. this._usedTimer = 0;
  19672. this._startTimer = Browser.now();
  19673. if (this._delayParam) {
  19674. ILaya.timer.once(this._delay, this, this.firstStart, this._delayParam);
  19675. return;
  19676. }
  19677. var props = this._props;
  19678. for (var i = 0, n = props.length; i < n; i++) {
  19679. var prop = props[i];
  19680. this._target[prop[0]] = prop[1];
  19681. }
  19682. ILaya.timer.once(this._delay, this, this._beginLoop);
  19683. }
  19684. resume() {
  19685. if (this._usedTimer >= this._duration)
  19686. return;
  19687. this._startTimer = Browser.now() - this._usedTimer - this._delay;
  19688. if (this._delayParam) {
  19689. if (this._usedTimer < 0) {
  19690. ILaya.timer.once(-this._usedTimer, this, this.firstStart, this._delayParam);
  19691. }
  19692. else {
  19693. this.firstStart.apply(this, this._delayParam);
  19694. }
  19695. }
  19696. else {
  19697. this._beginLoop();
  19698. }
  19699. }
  19700. static easeNone(t, b, c, d) {
  19701. return c * t / d + b;
  19702. }
  19703. }
  19704. Tween.tweenMap = [];
  19705. class Dragging {
  19706. constructor() {
  19707. this.ratio = 0.92;
  19708. this.maxOffset = 60;
  19709. this._dragging = false;
  19710. this._clickOnly = true;
  19711. }
  19712. start(target, area, hasInertia, elasticDistance, elasticBackTime, data, disableMouseEvent, ratio = 0.92) {
  19713. this.clearTimer();
  19714. this.target = target;
  19715. this.area = area;
  19716. this.hasInertia = hasInertia;
  19717. this.elasticDistance = area ? elasticDistance : 0;
  19718. this.elasticBackTime = elasticBackTime;
  19719. this.data = data;
  19720. this._disableMouseEvent = disableMouseEvent;
  19721. this.ratio = ratio;
  19722. this._parent = target.parent;
  19723. this._clickOnly = true;
  19724. this._dragging = true;
  19725. this._elasticRateX = this._elasticRateY = 1;
  19726. this._lastX = this._parent.mouseX;
  19727. this._lastY = this._parent.mouseY;
  19728. ILaya.stage.on(Event.MOUSE_UP, this, this.onStageMouseUp);
  19729. ILaya.stage.on(Event.MOUSE_OUT, this, this.onStageMouseUp);
  19730. ILaya.systemTimer.frameLoop(1, this, this.loop);
  19731. }
  19732. clearTimer() {
  19733. ILaya.systemTimer.clear(this, this.loop);
  19734. ILaya.systemTimer.clear(this, this.tweenMove);
  19735. if (this._tween) {
  19736. this._tween.recover();
  19737. this._tween = null;
  19738. }
  19739. }
  19740. stop() {
  19741. if (this._dragging) {
  19742. MouseManager.instance.disableMouseEvent = false;
  19743. ILaya.stage.off(Event.MOUSE_UP, this, this.onStageMouseUp);
  19744. ILaya.stage.off(Event.MOUSE_OUT, this, this.onStageMouseUp);
  19745. this._dragging = false;
  19746. this.target && this.area && this.backToArea();
  19747. this.clear();
  19748. }
  19749. }
  19750. loop() {
  19751. var point = this._parent.getMousePoint();
  19752. var mouseX = point.x;
  19753. var mouseY = point.y;
  19754. var offsetX = mouseX - this._lastX;
  19755. var offsetY = mouseY - this._lastY;
  19756. if (this._clickOnly) {
  19757. if (Math.abs(offsetX * ILaya.stage._canvasTransform.getScaleX()) > 1 || Math.abs(offsetY * ILaya.stage._canvasTransform.getScaleY()) > 1) {
  19758. this._clickOnly = false;
  19759. this._offsets || (this._offsets = []);
  19760. this._offsets.length = 0;
  19761. this.target.event(Event.DRAG_START, this.data);
  19762. MouseManager.instance.disableMouseEvent = this._disableMouseEvent;
  19763. }
  19764. else
  19765. return;
  19766. }
  19767. else {
  19768. this._offsets.push(offsetX, offsetY);
  19769. }
  19770. if (offsetX === 0 && offsetY === 0)
  19771. return;
  19772. this._lastX = mouseX;
  19773. this._lastY = mouseY;
  19774. this.target.x += offsetX * this._elasticRateX;
  19775. this.target.y += offsetY * this._elasticRateY;
  19776. this.area && this.checkArea();
  19777. this.target.event(Event.DRAG_MOVE, this.data);
  19778. }
  19779. checkArea() {
  19780. if (this.elasticDistance <= 0) {
  19781. this.backToArea();
  19782. }
  19783. else {
  19784. if (this.target._x < this.area.x) {
  19785. var offsetX = this.area.x - this.target._x;
  19786. }
  19787. else if (this.target._x > this.area.x + this.area.width) {
  19788. offsetX = this.target._x - this.area.x - this.area.width;
  19789. }
  19790. else {
  19791. offsetX = 0;
  19792. }
  19793. this._elasticRateX = Math.max(0, 1 - (offsetX / this.elasticDistance));
  19794. if (this.target._y < this.area.y) {
  19795. var offsetY = this.area.y - this.target.y;
  19796. }
  19797. else if (this.target._y > this.area.y + this.area.height) {
  19798. offsetY = this.target._y - this.area.y - this.area.height;
  19799. }
  19800. else {
  19801. offsetY = 0;
  19802. }
  19803. this._elasticRateY = Math.max(0, 1 - (offsetY / this.elasticDistance));
  19804. }
  19805. }
  19806. backToArea() {
  19807. this.target.x = Math.min(Math.max(this.target._x, this.area.x), this.area.x + this.area.width);
  19808. this.target.y = Math.min(Math.max(this.target._y, this.area.y), this.area.y + this.area.height);
  19809. }
  19810. onStageMouseUp(e) {
  19811. MouseManager.instance.disableMouseEvent = false;
  19812. ILaya.stage.off(Event.MOUSE_UP, this, this.onStageMouseUp);
  19813. ILaya.stage.off(Event.MOUSE_OUT, this, this.onStageMouseUp);
  19814. ILaya.systemTimer.clear(this, this.loop);
  19815. if (this._clickOnly || !this.target)
  19816. return;
  19817. if (this.hasInertia) {
  19818. if (this._offsets.length < 1) {
  19819. this._offsets.push(this._parent.mouseX - this._lastX, this._parent.mouseY - this._lastY);
  19820. }
  19821. this._offsetX = this._offsetY = 0;
  19822. var len = this._offsets.length;
  19823. var n = Math.min(len, 6);
  19824. var m = this._offsets.length - n;
  19825. for (var i = len - 1; i > m; i--) {
  19826. this._offsetY += this._offsets[i--];
  19827. this._offsetX += this._offsets[i];
  19828. }
  19829. this._offsetX = this._offsetX / n * 2;
  19830. this._offsetY = this._offsetY / n * 2;
  19831. if (Math.abs(this._offsetX) > this.maxOffset)
  19832. this._offsetX = this._offsetX > 0 ? this.maxOffset : -this.maxOffset;
  19833. if (Math.abs(this._offsetY) > this.maxOffset)
  19834. this._offsetY = this._offsetY > 0 ? this.maxOffset : -this.maxOffset;
  19835. ILaya.systemTimer.frameLoop(1, this, this.tweenMove);
  19836. }
  19837. else if (this.elasticDistance > 0) {
  19838. this.checkElastic();
  19839. }
  19840. else {
  19841. this.clear();
  19842. }
  19843. }
  19844. checkElastic() {
  19845. var tx = NaN;
  19846. var ty = NaN;
  19847. if (this.target.x < this.area.x)
  19848. tx = this.area.x;
  19849. else if (this.target._x > this.area.x + this.area.width)
  19850. tx = this.area.x + this.area.width;
  19851. if (this.target.y < this.area.y)
  19852. ty = this.area.y;
  19853. else if (this.target._y > this.area.y + this.area.height)
  19854. ty = this.area.y + this.area.height;
  19855. if (!isNaN(tx) || !isNaN(ty)) {
  19856. var obj = {};
  19857. if (!isNaN(tx))
  19858. obj.x = tx;
  19859. if (!isNaN(ty))
  19860. obj.y = ty;
  19861. this._tween = Tween.to(this.target, obj, this.elasticBackTime, Ease.sineOut, Handler.create(this, this.clear), 0, false, false);
  19862. }
  19863. else {
  19864. this.clear();
  19865. }
  19866. }
  19867. tweenMove() {
  19868. this._offsetX *= this.ratio * this._elasticRateX;
  19869. this._offsetY *= this.ratio * this._elasticRateY;
  19870. this.target.x += this._offsetX;
  19871. this.target.y += this._offsetY;
  19872. this.area && this.checkArea();
  19873. this.target.event(Event.DRAG_MOVE, this.data);
  19874. if ((Math.abs(this._offsetX) < 1 && Math.abs(this._offsetY) < 1) || this._elasticRateX < 0.5 || this._elasticRateY < 0.5) {
  19875. ILaya.systemTimer.clear(this, this.tweenMove);
  19876. if (this.elasticDistance > 0)
  19877. this.checkElastic();
  19878. else
  19879. this.clear();
  19880. }
  19881. }
  19882. clear() {
  19883. if (this.target) {
  19884. this.clearTimer();
  19885. var sp = this.target;
  19886. this.target = null;
  19887. this._parent = null;
  19888. sp.event(Event.DRAG_END, this.data);
  19889. }
  19890. }
  19891. }
  19892. class Component {
  19893. constructor() {
  19894. this._id = Utils.getGID();
  19895. this._resetComp();
  19896. }
  19897. get id() {
  19898. return this._id;
  19899. }
  19900. get enabled() {
  19901. return this._enabled;
  19902. }
  19903. set enabled(value) {
  19904. if (this._enabled != value) {
  19905. this._enabled = value;
  19906. if (this.owner) {
  19907. if (value)
  19908. this.owner.activeInHierarchy && this._onEnable();
  19909. else
  19910. this.owner.activeInHierarchy && this._onDisable();
  19911. }
  19912. }
  19913. }
  19914. get isSingleton() {
  19915. return true;
  19916. }
  19917. get destroyed() {
  19918. return this._destroyed;
  19919. }
  19920. _isScript() {
  19921. return false;
  19922. }
  19923. _resetComp() {
  19924. this._indexInList = -1;
  19925. this._enabled = true;
  19926. this._awaked = false;
  19927. this.owner = null;
  19928. }
  19929. _getIndexInList() {
  19930. return this._indexInList;
  19931. }
  19932. _setIndexInList(index) {
  19933. this._indexInList = index;
  19934. }
  19935. _onAdded() {
  19936. }
  19937. _onAwake() {
  19938. }
  19939. _onEnable() {
  19940. }
  19941. _onDisable() {
  19942. }
  19943. _onDestroy() {
  19944. }
  19945. onReset() {
  19946. }
  19947. _parse(data) {
  19948. }
  19949. _cloneTo(dest) {
  19950. }
  19951. _setActive(value) {
  19952. if (value) {
  19953. if (!this._awaked) {
  19954. this._awaked = true;
  19955. this._onAwake();
  19956. }
  19957. this._enabled && this._onEnable();
  19958. }
  19959. else {
  19960. this._enabled && this._onDisable();
  19961. }
  19962. }
  19963. destroy() {
  19964. if (this.owner)
  19965. this.owner._destroyComponent(this);
  19966. }
  19967. _destroy() {
  19968. if (this.owner.activeInHierarchy && this._enabled) {
  19969. this._setActive(false);
  19970. (this._isScript()) && (this.onDisable());
  19971. }
  19972. this._onDestroy();
  19973. this._destroyed = true;
  19974. if (this.onReset !== Component.prototype.onReset) {
  19975. this.onReset();
  19976. this._resetComp();
  19977. Pool.recoverByClass(this);
  19978. }
  19979. else {
  19980. this._resetComp();
  19981. }
  19982. }
  19983. }
  19984. class AnimationBase extends Sprite {
  19985. constructor() {
  19986. super();
  19987. this.wrapMode = 0;
  19988. this._interval = Config.animationInterval;
  19989. this._isReverse = false;
  19990. this._frameRateChanged = false;
  19991. this._setBitUp(Const.DISPLAY);
  19992. }
  19993. play(start = 0, loop = true, name = "") {
  19994. this._isPlaying = true;
  19995. this._actionName = name;
  19996. this.index = (typeof (start) == 'string') ? this._getFrameByLabel(start) : start;
  19997. this.loop = loop;
  19998. this._isReverse = this.wrapMode === AnimationBase.WRAP_REVERSE;
  19999. if (this.index == 0 && this._isReverse) {
  20000. this.index = this.count - 1;
  20001. }
  20002. if (this.interval > 0)
  20003. this.timerLoop(this.interval, this, this._frameLoop, null, true, true);
  20004. }
  20005. get interval() {
  20006. return this._interval;
  20007. }
  20008. set interval(value) {
  20009. if (this._interval != value) {
  20010. this._frameRateChanged = true;
  20011. this._interval = value;
  20012. if (this._isPlaying && value > 0) {
  20013. this.timerLoop(value, this, this._frameLoop, null, true, true);
  20014. }
  20015. }
  20016. }
  20017. _getFrameByLabel(label) {
  20018. for (var i = 0; i < this._count; i++) {
  20019. var item = this._labels[i];
  20020. if (item && item.indexOf(label) > -1)
  20021. return i;
  20022. }
  20023. return 0;
  20024. }
  20025. _frameLoop() {
  20026. if (this._isReverse) {
  20027. this._index--;
  20028. if (this._index < 0) {
  20029. if (this.loop) {
  20030. if (this.wrapMode == AnimationBase.WRAP_PINGPONG) {
  20031. this._index = this._count > 0 ? 1 : 0;
  20032. this._isReverse = false;
  20033. }
  20034. else {
  20035. this._index = this._count - 1;
  20036. }
  20037. this.event(Event.COMPLETE);
  20038. }
  20039. else {
  20040. this._index = 0;
  20041. this.stop();
  20042. this.event(Event.COMPLETE);
  20043. return;
  20044. }
  20045. }
  20046. }
  20047. else {
  20048. this._index++;
  20049. if (this._index >= this._count) {
  20050. if (this.loop) {
  20051. if (this.wrapMode == AnimationBase.WRAP_PINGPONG) {
  20052. this._index = this._count - 2 >= 0 ? this._count - 2 : 0;
  20053. this._isReverse = true;
  20054. }
  20055. else {
  20056. this._index = 0;
  20057. }
  20058. this.event(Event.COMPLETE);
  20059. }
  20060. else {
  20061. this._index--;
  20062. this.stop();
  20063. this.event(Event.COMPLETE);
  20064. return;
  20065. }
  20066. }
  20067. }
  20068. this.index = this._index;
  20069. }
  20070. _setControlNode(node) {
  20071. if (this._controlNode) {
  20072. this._controlNode.off(Event.DISPLAY, this, this._resumePlay);
  20073. this._controlNode.off(Event.UNDISPLAY, this, this._resumePlay);
  20074. }
  20075. this._controlNode = node;
  20076. if (node && node != this) {
  20077. node.on(Event.DISPLAY, this, this._resumePlay);
  20078. node.on(Event.UNDISPLAY, this, this._resumePlay);
  20079. }
  20080. }
  20081. _setDisplay(value) {
  20082. super._setDisplay(value);
  20083. this._resumePlay();
  20084. }
  20085. _resumePlay() {
  20086. if (this._isPlaying) {
  20087. if (this._controlNode.displayedInStage)
  20088. this.play(this._index, this.loop, this._actionName);
  20089. else
  20090. this.clearTimer(this, this._frameLoop);
  20091. }
  20092. }
  20093. stop() {
  20094. this._isPlaying = false;
  20095. this.clearTimer(this, this._frameLoop);
  20096. }
  20097. get isPlaying() {
  20098. return this._isPlaying;
  20099. }
  20100. addLabel(label, index) {
  20101. if (!this._labels)
  20102. this._labels = {};
  20103. if (!this._labels[index])
  20104. this._labels[index] = [];
  20105. this._labels[index].push(label);
  20106. }
  20107. removeLabel(label) {
  20108. if (!label)
  20109. this._labels = null;
  20110. else if (this._labels) {
  20111. for (var name in this._labels) {
  20112. this._removeLabelFromList(this._labels[name], label);
  20113. }
  20114. }
  20115. }
  20116. _removeLabelFromList(list, label) {
  20117. if (!list)
  20118. return;
  20119. for (var i = list.length - 1; i >= 0; i--) {
  20120. if (list[i] == label) {
  20121. list.splice(i, 1);
  20122. }
  20123. }
  20124. }
  20125. gotoAndStop(position) {
  20126. this.index = (typeof (position) == 'string') ? this._getFrameByLabel(position) : position;
  20127. this.stop();
  20128. }
  20129. get index() {
  20130. return this._index;
  20131. }
  20132. set index(value) {
  20133. this._index = value;
  20134. this._displayToIndex(value);
  20135. if (this._labels && this._labels[value]) {
  20136. var tArr = this._labels[value];
  20137. for (var i = 0, len = tArr.length; i < len; i++) {
  20138. this.event(Event.LABEL, tArr[i]);
  20139. }
  20140. }
  20141. }
  20142. _displayToIndex(value) {
  20143. }
  20144. get count() {
  20145. return this._count;
  20146. }
  20147. clear() {
  20148. this.stop();
  20149. this._labels = null;
  20150. return this;
  20151. }
  20152. }
  20153. AnimationBase.WRAP_POSITIVE = 0;
  20154. AnimationBase.WRAP_REVERSE = 1;
  20155. AnimationBase.WRAP_PINGPONG = 2;
  20156. ClassUtils.regClass("laya.display.AnimationBase", AnimationBase);
  20157. ClassUtils.regClass("Laya.AnimationBase", AnimationBase);
  20158. class MathUtil {
  20159. static subtractVector3(l, r, o) {
  20160. o[0] = l[0] - r[0];
  20161. o[1] = l[1] - r[1];
  20162. o[2] = l[2] - r[2];
  20163. }
  20164. static lerp(left, right, amount) {
  20165. return left * (1 - amount) + right * amount;
  20166. }
  20167. static scaleVector3(f, b, e) {
  20168. e[0] = f[0] * b;
  20169. e[1] = f[1] * b;
  20170. e[2] = f[2] * b;
  20171. }
  20172. static lerpVector3(l, r, t, o) {
  20173. var ax = l[0], ay = l[1], az = l[2];
  20174. o[0] = ax + t * (r[0] - ax);
  20175. o[1] = ay + t * (r[1] - ay);
  20176. o[2] = az + t * (r[2] - az);
  20177. }
  20178. static lerpVector4(l, r, t, o) {
  20179. var ax = l[0], ay = l[1], az = l[2], aw = l[3];
  20180. o[0] = ax + t * (r[0] - ax);
  20181. o[1] = ay + t * (r[1] - ay);
  20182. o[2] = az + t * (r[2] - az);
  20183. o[3] = aw + t * (r[3] - aw);
  20184. }
  20185. static slerpQuaternionArray(a, Offset1, b, Offset2, t, out, Offset3) {
  20186. var ax = a[Offset1 + 0], ay = a[Offset1 + 1], az = a[Offset1 + 2], aw = a[Offset1 + 3], bx = b[Offset2 + 0], by = b[Offset2 + 1], bz = b[Offset2 + 2], bw = b[Offset2 + 3];
  20187. var omega, cosom, sinom, scale0, scale1;
  20188. cosom = ax * bx + ay * by + az * bz + aw * bw;
  20189. if (cosom < 0.0) {
  20190. cosom = -cosom;
  20191. bx = -bx;
  20192. by = -by;
  20193. bz = -bz;
  20194. bw = -bw;
  20195. }
  20196. if ((1.0 - cosom) > 0.000001) {
  20197. omega = Math.acos(cosom);
  20198. sinom = Math.sin(omega);
  20199. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  20200. scale1 = Math.sin(t * omega) / sinom;
  20201. }
  20202. else {
  20203. scale0 = 1.0 - t;
  20204. scale1 = t;
  20205. }
  20206. out[Offset3 + 0] = scale0 * ax + scale1 * bx;
  20207. out[Offset3 + 1] = scale0 * ay + scale1 * by;
  20208. out[Offset3 + 2] = scale0 * az + scale1 * bz;
  20209. out[Offset3 + 3] = scale0 * aw + scale1 * bw;
  20210. return out;
  20211. }
  20212. static getRotation(x0, y0, x1, y1) {
  20213. return Math.atan2(y1 - y0, x1 - x0) / Math.PI * 180;
  20214. }
  20215. static sortBigFirst(a, b) {
  20216. if (a == b)
  20217. return 0;
  20218. return b > a ? 1 : -1;
  20219. }
  20220. static sortSmallFirst(a, b) {
  20221. if (a == b)
  20222. return 0;
  20223. return b > a ? -1 : 1;
  20224. }
  20225. static sortNumBigFirst(a, b) {
  20226. return parseFloat(b) - parseFloat(a);
  20227. }
  20228. static sortNumSmallFirst(a, b) {
  20229. return parseFloat(a) - parseFloat(b);
  20230. }
  20231. static sortByKey(key, bigFirst = false, forceNum = true) {
  20232. var _sortFun;
  20233. if (bigFirst) {
  20234. _sortFun = forceNum ? MathUtil.sortNumBigFirst : MathUtil.sortBigFirst;
  20235. }
  20236. else {
  20237. _sortFun = forceNum ? MathUtil.sortNumSmallFirst : MathUtil.sortSmallFirst;
  20238. }
  20239. return function (a, b) {
  20240. return _sortFun(a[key], b[key]);
  20241. };
  20242. }
  20243. }
  20244. class FrameAnimation extends AnimationBase {
  20245. constructor() {
  20246. super();
  20247. if (FrameAnimation._sortIndexFun === null) {
  20248. FrameAnimation._sortIndexFun = MathUtil.sortByKey("index", false, true);
  20249. }
  20250. }
  20251. _setUp(targetDic, animationData) {
  20252. this._targetDic = targetDic;
  20253. this._animationData = animationData;
  20254. this.interval = 1000 / animationData.frameRate;
  20255. if (animationData.parsed) {
  20256. this._count = animationData.count;
  20257. this._labels = animationData.labels;
  20258. this._usedFrames = animationData.animationNewFrames;
  20259. }
  20260. else {
  20261. this._usedFrames = [];
  20262. this._calculateDatas();
  20263. animationData.parsed = true;
  20264. animationData.labels = this._labels;
  20265. animationData.count = this._count;
  20266. animationData.animationNewFrames = this._usedFrames;
  20267. }
  20268. }
  20269. clear() {
  20270. super.clear();
  20271. this._targetDic = null;
  20272. this._animationData = null;
  20273. return this;
  20274. }
  20275. _displayToIndex(value) {
  20276. if (!this._animationData)
  20277. return;
  20278. if (value < 0)
  20279. value = 0;
  20280. if (value > this._count)
  20281. value = this._count;
  20282. var nodes = this._animationData.nodes, i, len = nodes.length;
  20283. for (i = 0; i < len; i++) {
  20284. this._displayNodeToFrame(nodes[i], value);
  20285. }
  20286. }
  20287. _displayNodeToFrame(node, frame, targetDic = null) {
  20288. if (!targetDic)
  20289. targetDic = this._targetDic;
  20290. var target = targetDic[node.target];
  20291. if (!target) {
  20292. return;
  20293. }
  20294. var frames = node.frames, key, propFrames, value;
  20295. var keys = node.keys, i, len = keys.length;
  20296. for (i = 0; i < len; i++) {
  20297. key = keys[i];
  20298. propFrames = frames[key];
  20299. if (propFrames.length > frame) {
  20300. value = propFrames[frame];
  20301. }
  20302. else {
  20303. value = propFrames[propFrames.length - 1];
  20304. }
  20305. target[key] = value;
  20306. }
  20307. var funkeys = node.funkeys;
  20308. len = funkeys.length;
  20309. var funFrames;
  20310. if (len == 0)
  20311. return;
  20312. for (i = 0; i < len; i++) {
  20313. key = funkeys[i];
  20314. funFrames = frames[key];
  20315. if (funFrames[frame] !== undefined) {
  20316. target[key] && target[key].apply(target, funFrames[frame]);
  20317. }
  20318. }
  20319. }
  20320. _calculateDatas() {
  20321. if (!this._animationData)
  20322. return;
  20323. var nodes = this._animationData.nodes, i, len = nodes.length, tNode;
  20324. this._count = 0;
  20325. for (i = 0; i < len; i++) {
  20326. tNode = nodes[i];
  20327. this._calculateKeyFrames(tNode);
  20328. }
  20329. this._count += 1;
  20330. }
  20331. _calculateKeyFrames(node) {
  20332. var keyFrames = node.keyframes, key, tKeyFrames, target = node.target;
  20333. if (!node.frames)
  20334. node.frames = {};
  20335. if (!node.keys)
  20336. node.keys = [];
  20337. else
  20338. node.keys.length = 0;
  20339. if (!node.funkeys)
  20340. node.funkeys = [];
  20341. else
  20342. node.funkeys.length = 0;
  20343. if (!node.initValues)
  20344. node.initValues = {};
  20345. for (key in keyFrames) {
  20346. var isFun = key.indexOf("()") != -1;
  20347. tKeyFrames = keyFrames[key];
  20348. if (isFun)
  20349. key = key.substr(0, key.length - 2);
  20350. if (!node.frames[key]) {
  20351. node.frames[key] = [];
  20352. }
  20353. if (!isFun) {
  20354. if (this._targetDic && this._targetDic[target]) {
  20355. node.initValues[key] = this._targetDic[target][key];
  20356. }
  20357. tKeyFrames.sort(FrameAnimation._sortIndexFun);
  20358. node.keys.push(key);
  20359. this._calculateNodePropFrames(tKeyFrames, node.frames[key], key, target);
  20360. }
  20361. else {
  20362. node.funkeys.push(key);
  20363. var map = node.frames[key];
  20364. for (var i = 0; i < tKeyFrames.length; i++) {
  20365. var temp = tKeyFrames[i];
  20366. map[temp.index] = temp.value;
  20367. if (temp.index > this._count)
  20368. this._count = temp.index;
  20369. }
  20370. }
  20371. }
  20372. }
  20373. resetNodes() {
  20374. if (!this._targetDic)
  20375. return;
  20376. if (!this._animationData)
  20377. return;
  20378. var nodes = this._animationData.nodes, i, len = nodes.length;
  20379. var tNode;
  20380. var initValues;
  20381. for (i = 0; i < len; i++) {
  20382. tNode = nodes[i];
  20383. initValues = tNode.initValues;
  20384. if (!initValues)
  20385. continue;
  20386. var target = this._targetDic[tNode.target];
  20387. if (!target)
  20388. continue;
  20389. var key;
  20390. for (key in initValues) {
  20391. target[key] = initValues[key];
  20392. }
  20393. }
  20394. }
  20395. _calculateNodePropFrames(keyframes, frames, key, target) {
  20396. var i, len = keyframes.length - 1;
  20397. frames.length = keyframes[len].index + 1;
  20398. for (i = 0; i < len; i++) {
  20399. this._dealKeyFrame(keyframes[i]);
  20400. this._calculateFrameValues(keyframes[i], keyframes[i + 1], frames);
  20401. }
  20402. if (len == 0) {
  20403. frames[0] = keyframes[0].value;
  20404. if (this._usedFrames)
  20405. this._usedFrames[keyframes[0].index] = true;
  20406. }
  20407. this._dealKeyFrame(keyframes[i]);
  20408. }
  20409. _dealKeyFrame(keyFrame) {
  20410. if (keyFrame.label && keyFrame.label != "")
  20411. this.addLabel(keyFrame.label, keyFrame.index);
  20412. }
  20413. _calculateFrameValues(startFrame, endFrame, result) {
  20414. var i, easeFun;
  20415. var start = startFrame.index, end = endFrame.index;
  20416. var startValue = startFrame.value;
  20417. var dValue = endFrame.value - startFrame.value;
  20418. var dLen = end - start;
  20419. var frames = this._usedFrames;
  20420. if (end > this._count)
  20421. this._count = end;
  20422. if (startFrame.tween) {
  20423. easeFun = Ease[startFrame.tweenMethod];
  20424. if (easeFun == null)
  20425. easeFun = Ease.linearNone;
  20426. for (i = start; i < end; i++) {
  20427. result[i] = easeFun(i - start, startValue, dValue, dLen);
  20428. if (frames)
  20429. frames[i] = true;
  20430. }
  20431. }
  20432. else {
  20433. for (i = start; i < end; i++) {
  20434. result[i] = startValue;
  20435. }
  20436. }
  20437. if (frames) {
  20438. frames[startFrame.index] = true;
  20439. frames[endFrame.index] = true;
  20440. }
  20441. result[endFrame.index] = endFrame.value;
  20442. }
  20443. }
  20444. ClassUtils.regClass("laya.display.FrameAnimation", FrameAnimation);
  20445. ClassUtils.regClass("Laya.FrameAnimation", FrameAnimation);
  20446. var supportWeakMap = !!WeakMap;
  20447. class WeakObject {
  20448. constructor() {
  20449. this._obj = WeakObject.supportWeakMap ? new Browser.window.WeakMap() : {};
  20450. if (!WeakObject.supportWeakMap)
  20451. WeakObject._maps.push(this);
  20452. }
  20453. static __init__() {
  20454. WeakObject.I = new WeakObject();
  20455. if (!WeakObject.supportWeakMap)
  20456. ILaya.systemTimer.loop(WeakObject.delInterval, null, WeakObject.clearCache);
  20457. }
  20458. static clearCache() {
  20459. for (var i = 0, n = WeakObject._maps.length; i < n; i++) {
  20460. var obj = WeakObject._maps[i];
  20461. obj._obj = {};
  20462. }
  20463. }
  20464. set(key, value) {
  20465. if (key == null)
  20466. return;
  20467. if (WeakObject.supportWeakMap) {
  20468. var objKey = key;
  20469. if (typeof (key) == 'string' || typeof (key) == 'number') {
  20470. objKey = WeakObject._keys[key];
  20471. if (!objKey)
  20472. objKey = WeakObject._keys[key] = { k: key };
  20473. }
  20474. this._obj.set(objKey, value);
  20475. }
  20476. else {
  20477. if (typeof (key) == 'string' || typeof (key) == 'number') {
  20478. this._obj[key] = value;
  20479. }
  20480. else {
  20481. key.$_GID || (key.$_GID = Utils.getGID());
  20482. this._obj[key.$_GID] = value;
  20483. }
  20484. }
  20485. }
  20486. get(key) {
  20487. if (key == null)
  20488. return null;
  20489. if (WeakObject.supportWeakMap) {
  20490. var objKey = (typeof (key) == 'string' || typeof (key) == 'number') ? WeakObject._keys[key] : key;
  20491. if (!objKey)
  20492. return null;
  20493. return this._obj.get(objKey);
  20494. }
  20495. else {
  20496. if (typeof (key) == 'string' || typeof (key) == 'number')
  20497. return this._obj[key];
  20498. return this._obj[key.$_GID];
  20499. }
  20500. }
  20501. del(key) {
  20502. if (key == null)
  20503. return;
  20504. if (WeakObject.supportWeakMap) {
  20505. var objKey = (typeof (key) == 'string' || typeof (key) == 'number') ? WeakObject._keys[key] : key;
  20506. if (!objKey)
  20507. return;
  20508. this._obj.delete(objKey);
  20509. }
  20510. else {
  20511. if (typeof (key) == 'string' || typeof (key) == 'number')
  20512. delete this._obj[key];
  20513. else
  20514. delete this._obj[this._obj.$_GID];
  20515. }
  20516. }
  20517. has(key) {
  20518. if (key == null)
  20519. return false;
  20520. if (WeakObject.supportWeakMap) {
  20521. var objKey = (typeof (key) == 'string' || typeof (key) == 'number') ? WeakObject._keys[key] : key;
  20522. return this._obj.has(objKey);
  20523. }
  20524. else {
  20525. if (typeof (key) == 'string' || typeof (key) == 'number')
  20526. return this._obj[key] != null;
  20527. return this._obj[this._obj.$_GID] != null;
  20528. }
  20529. }
  20530. }
  20531. WeakObject.supportWeakMap = supportWeakMap;
  20532. WeakObject.delInterval = 10 * 60 * 1000;
  20533. WeakObject._keys = {};
  20534. WeakObject._maps = [];
  20535. class SceneUtils {
  20536. static __init() {
  20537. SceneUtils._funMap = new WeakObject();
  20538. }
  20539. static getBindFun(value) {
  20540. var fun = SceneUtils._funMap.get(value);
  20541. if (fun == null) {
  20542. var temp = "\"" + value + "\"";
  20543. temp = temp.replace(/^"\${|}"$/g, "").replace(/\${/g, "\"+").replace(/}/g, "+\"");
  20544. var str = "(function(data){if(data==null)return;with(data){try{\nreturn " + temp + "\n}catch(e){}}})";
  20545. fun = window.Laya._runScript(str);
  20546. SceneUtils._funMap.set(value, fun);
  20547. }
  20548. return fun;
  20549. }
  20550. static createByData(root, uiView) {
  20551. var tInitTool = InitTool.create();
  20552. root = SceneUtils.createComp(uiView, root, root, null, tInitTool);
  20553. root._setBit(Const.NOT_READY, true);
  20554. if ("_idMap" in root) {
  20555. root["_idMap"] = tInitTool._idMap;
  20556. }
  20557. if (uiView.animations) {
  20558. var anilist = [];
  20559. var animations = uiView.animations;
  20560. var i, len = animations.length;
  20561. var tAni;
  20562. var tAniO;
  20563. for (i = 0; i < len; i++) {
  20564. tAni = new FrameAnimation();
  20565. tAniO = animations[i];
  20566. tAni._setUp(tInitTool._idMap, tAniO);
  20567. root[tAniO.name] = tAni;
  20568. tAni._setControlNode(root);
  20569. switch (tAniO.action) {
  20570. case 1:
  20571. tAni.play(0, false);
  20572. break;
  20573. case 2:
  20574. tAni.play(0, true);
  20575. break;
  20576. }
  20577. anilist.push(tAni);
  20578. }
  20579. root._aniList = anilist;
  20580. }
  20581. if (root._$componentType === "Scene" && root._width > 0 && uiView.props.hitTestPrior == null && !root.mouseThrough)
  20582. root.hitTestPrior = true;
  20583. tInitTool.beginLoad(root);
  20584. return root;
  20585. }
  20586. static createInitTool() {
  20587. return InitTool.create();
  20588. }
  20589. static createComp(uiView, comp = null, view = null, dataMap = null, initTool = null) {
  20590. if (uiView.type == "Scene3D" || uiView.type == "Sprite3D") {
  20591. var outBatchSprits = [];
  20592. var scene3D = ILaya.Laya["Utils3D"]._createSceneByJsonForMaker(uiView, outBatchSprits, initTool);
  20593. if (uiView.type == "Sprite3D")
  20594. ILaya.Laya["StaticBatchManager"].combine(scene3D, outBatchSprits);
  20595. else
  20596. ILaya.Laya["StaticBatchManager"].combine(null, outBatchSprits);
  20597. return scene3D;
  20598. }
  20599. comp = comp || SceneUtils.getCompInstance(uiView);
  20600. if (!comp) {
  20601. if (uiView.props && uiView.props.runtime)
  20602. console.warn("runtime not found:" + uiView.props.runtime);
  20603. else
  20604. console.warn("can not create:" + uiView.type);
  20605. return null;
  20606. }
  20607. var child = uiView.child;
  20608. if (child) {
  20609. var isList = comp["_$componentType"] == "List";
  20610. for (var i = 0, n = child.length; i < n; i++) {
  20611. var node = child[i];
  20612. if ('itemRender' in comp && (node.props.name == "render" || node.props.renderType === "render")) {
  20613. comp["itemRender"] = node;
  20614. }
  20615. else if (node.type == "Graphic") {
  20616. ILaya.ClassUtils._addGraphicsToSprite(node, comp);
  20617. }
  20618. else if (ILaya.ClassUtils._isDrawType(node.type)) {
  20619. ILaya.ClassUtils._addGraphicToSprite(node, comp, true);
  20620. }
  20621. else {
  20622. if (isList) {
  20623. var arr = [];
  20624. var tChild = SceneUtils.createComp(node, null, view, arr, initTool);
  20625. if (arr.length)
  20626. tChild["_$bindData"] = arr;
  20627. }
  20628. else {
  20629. tChild = SceneUtils.createComp(node, null, view, dataMap, initTool);
  20630. }
  20631. if (node.type == "Script") {
  20632. if (tChild instanceof Component) {
  20633. comp._addComponentInstance(tChild);
  20634. }
  20635. else {
  20636. if ("owner" in tChild) {
  20637. tChild["owner"] = comp;
  20638. }
  20639. else if ("target" in tChild) {
  20640. tChild["target"] = comp;
  20641. }
  20642. }
  20643. }
  20644. else if (node.props.renderType == "mask" || node.props.name == "mask") {
  20645. comp.mask = tChild;
  20646. }
  20647. else {
  20648. tChild instanceof Node && comp.addChild(tChild);
  20649. }
  20650. }
  20651. }
  20652. }
  20653. var props = uiView.props;
  20654. for (var prop in props) {
  20655. var value = props[prop];
  20656. if (typeof (value) == 'string' && (value.indexOf("@node:") >= 0 || value.indexOf("@Prefab:") >= 0)) {
  20657. if (initTool) {
  20658. initTool.addNodeRef(comp, prop, value);
  20659. }
  20660. }
  20661. else
  20662. SceneUtils.setCompValue(comp, prop, value, view, dataMap);
  20663. }
  20664. if (comp._afterInited) {
  20665. comp._afterInited();
  20666. }
  20667. if (uiView.compId && initTool && initTool._idMap) {
  20668. initTool._idMap[uiView.compId] = comp;
  20669. }
  20670. return comp;
  20671. }
  20672. static setCompValue(comp, prop, value, view = null, dataMap = null) {
  20673. if (typeof (value) == 'string' && value.indexOf("${") > -1) {
  20674. SceneUtils._sheet || (SceneUtils._sheet = ILaya.ClassUtils.getClass("laya.data.Table"));
  20675. if (!SceneUtils._sheet) {
  20676. console.warn("Can not find class Sheet");
  20677. return;
  20678. }
  20679. if (dataMap) {
  20680. dataMap.push(comp, prop, value);
  20681. }
  20682. else if (view) {
  20683. if (value.indexOf("].") == -1) {
  20684. value = value.replace(".", "[0].");
  20685. }
  20686. var watcher = new DataWatcher(comp, prop, value);
  20687. watcher.exe(view);
  20688. var one, temp;
  20689. var str = value.replace(/\[.*?\]\./g, ".");
  20690. while ((one = SceneUtils._parseWatchData.exec(str)) != null) {
  20691. var key1 = one[1];
  20692. while ((temp = SceneUtils._parseKeyWord.exec(key1)) != null) {
  20693. var key2 = temp[0];
  20694. var arr = (view._watchMap[key2] || (view._watchMap[key2] = []));
  20695. arr.push(watcher);
  20696. SceneUtils._sheet.I.notifer.on(key2, view, view.changeData, [key2]);
  20697. }
  20698. arr = (view._watchMap[key1] || (view._watchMap[key1] = []));
  20699. arr.push(watcher);
  20700. SceneUtils._sheet.I.notifer.on(key1, view, view.changeData, [key1]);
  20701. }
  20702. }
  20703. return;
  20704. }
  20705. if (prop === "var" && view) {
  20706. view[value] = comp;
  20707. }
  20708. else {
  20709. comp[prop] = (value === "true" ? true : (value === "false" ? false : value));
  20710. }
  20711. }
  20712. static getCompInstance(json) {
  20713. if (json.type == "UIView") {
  20714. if (json.props && json.props.pageData) {
  20715. return SceneUtils.createByData(null, json.props.pageData);
  20716. }
  20717. }
  20718. var runtime = (json.props && json.props.runtime) || json.type;
  20719. var compClass = ILaya.ClassUtils.getClass(runtime);
  20720. if (!compClass)
  20721. throw "Can not find class " + runtime;
  20722. if (json.type === "Script" && compClass.prototype._doAwake) {
  20723. var comp = Pool.createByClass(compClass);
  20724. comp._destroyed = false;
  20725. return comp;
  20726. }
  20727. if (json.props && "renderType" in json.props && json.props["renderType"] == "instance") {
  20728. if (!compClass["instance"])
  20729. compClass["instance"] = new compClass();
  20730. return compClass["instance"];
  20731. }
  20732. return new compClass();
  20733. }
  20734. }
  20735. SceneUtils._parseWatchData = /\${(.*?)}/g;
  20736. SceneUtils._parseKeyWord = /[a-zA-Z_][a-zA-Z0-9_]*(?:(?:\.[a-zA-Z_][a-zA-Z0-9_]*)+)/g;
  20737. class DataWatcher {
  20738. constructor(comp, prop, value) {
  20739. this.comp = comp;
  20740. this.prop = prop;
  20741. this.value = value;
  20742. }
  20743. exe(view) {
  20744. var fun = SceneUtils.getBindFun(this.value);
  20745. this.comp[this.prop] = fun.call(this, view);
  20746. }
  20747. }
  20748. class InitTool {
  20749. reset() {
  20750. this._nodeRefList = null;
  20751. this._initList = null;
  20752. this._idMap = null;
  20753. this._loadList = null;
  20754. this._scene = null;
  20755. }
  20756. recover() {
  20757. this.reset();
  20758. Pool.recover("InitTool", this);
  20759. }
  20760. static create() {
  20761. var tool = Pool.getItemByClass("InitTool", InitTool);
  20762. tool._idMap = [];
  20763. return tool;
  20764. }
  20765. addLoadRes(url, type = null) {
  20766. if (!this._loadList)
  20767. this._loadList = [];
  20768. if (!type) {
  20769. this._loadList.push(url);
  20770. }
  20771. else {
  20772. this._loadList.push({ url: url, type: type });
  20773. }
  20774. }
  20775. addNodeRef(node, prop, referStr) {
  20776. if (!this._nodeRefList)
  20777. this._nodeRefList = [];
  20778. this._nodeRefList.push([node, prop, referStr]);
  20779. if (referStr.indexOf("@Prefab:") >= 0) {
  20780. this.addLoadRes(referStr.replace("@Prefab:", ""), Loader.PREFAB);
  20781. }
  20782. }
  20783. setNodeRef() {
  20784. if (!this._nodeRefList)
  20785. return;
  20786. if (!this._idMap) {
  20787. this._nodeRefList = null;
  20788. return;
  20789. }
  20790. var i, len;
  20791. len = this._nodeRefList.length;
  20792. var tRefInfo;
  20793. for (i = 0; i < len; i++) {
  20794. tRefInfo = this._nodeRefList[i];
  20795. tRefInfo[0][tRefInfo[1]] = this.getReferData(tRefInfo[2]);
  20796. }
  20797. this._nodeRefList = null;
  20798. }
  20799. getReferData(referStr) {
  20800. if (referStr.indexOf("@Prefab:") >= 0) {
  20801. var prefab;
  20802. prefab = Loader.getRes(referStr.replace("@Prefab:", ""));
  20803. return prefab;
  20804. }
  20805. else if (referStr.indexOf("@arr:") >= 0) {
  20806. referStr = referStr.replace("@arr:", "");
  20807. var list;
  20808. list = referStr.split(",");
  20809. var i, len;
  20810. var tStr;
  20811. len = list.length;
  20812. for (i = 0; i < len; i++) {
  20813. tStr = list[i];
  20814. if (tStr) {
  20815. list[i] = this._idMap[tStr.replace("@node:", "")];
  20816. }
  20817. else {
  20818. list[i] = null;
  20819. }
  20820. }
  20821. return list;
  20822. }
  20823. else {
  20824. return this._idMap[referStr.replace("@node:", "")];
  20825. }
  20826. }
  20827. addInitItem(item) {
  20828. if (!this._initList)
  20829. this._initList = [];
  20830. this._initList.push(item);
  20831. }
  20832. doInits() {
  20833. if (!this._initList)
  20834. return;
  20835. this._initList = null;
  20836. }
  20837. finish() {
  20838. this.setNodeRef();
  20839. this.doInits();
  20840. this._scene._setBit(Const.NOT_READY, false);
  20841. if (this._scene.parent && this._scene.parent.activeInHierarchy && this._scene.active)
  20842. this._scene._processActive();
  20843. this._scene.event("onViewCreated");
  20844. this.recover();
  20845. }
  20846. beginLoad(scene) {
  20847. this._scene = scene;
  20848. if (!this._loadList || this._loadList.length < 1) {
  20849. this.finish();
  20850. }
  20851. else {
  20852. ILaya.loader.load(this._loadList, Handler.create(this, this.finish));
  20853. }
  20854. }
  20855. }
  20856. class IStatRender {
  20857. show(x = 0, y = 0) {
  20858. }
  20859. enable() {
  20860. }
  20861. hide() {
  20862. }
  20863. set_onclick(fn) {
  20864. }
  20865. isCanvasRender() {
  20866. return true;
  20867. }
  20868. renderNotCanvas(ctx, x, y) { }
  20869. }
  20870. class StatUI extends IStatRender {
  20871. constructor() {
  20872. super(...arguments);
  20873. this._show = false;
  20874. this._useCanvas = false;
  20875. this._height = 100;
  20876. this._view = [];
  20877. }
  20878. show(x = 0, y = 0) {
  20879. if (!Browser.onMiniGame && !ILaya.Render.isConchApp && !Browser.onBDMiniGame && !Browser.onKGMiniGame && !Browser.onQGMiniGame && !Browser.onQQMiniGame && !Browser.onAlipayMiniGame)
  20880. this._useCanvas = true;
  20881. this._show = true;
  20882. Stat._fpsData.length = 60;
  20883. this._view[0] = { title: "FPS(Canvas)", value: "_fpsStr", color: "yellow", units: "int" };
  20884. this._view[1] = { title: "Sprite", value: "_spriteStr", color: "white", units: "int" };
  20885. this._view[2] = { title: "RenderBatches", value: "renderBatches", color: "white", units: "int" };
  20886. this._view[3] = { title: "SavedRenderBatches", value: "savedRenderBatches", color: "white", units: "int" };
  20887. this._view[4] = { title: "CPUMemory", value: "cpuMemory", color: "yellow", units: "M" };
  20888. this._view[5] = { title: "GPUMemory", value: "gpuMemory", color: "yellow", units: "M" };
  20889. this._view[6] = { title: "Shader", value: "shaderCall", color: "white", units: "int" };
  20890. if (!Render.is3DMode) {
  20891. this._view[0].title = "FPS(WebGL)";
  20892. this._view[7] = { title: "Canvas", value: "_canvasStr", color: "white", units: "int" };
  20893. }
  20894. else {
  20895. this._view[0].title = "FPS(3D)";
  20896. this._view[7] = { title: "TriFaces", value: "trianglesFaces", color: "white", units: "int" };
  20897. this._view[8] = { title: "FrustumCulling", value: "frustumCulling", color: "white", units: "int" };
  20898. this._view[9] = { title: "OctreeNodeCulling", value: "octreeNodeCulling", color: "white", units: "int" };
  20899. }
  20900. if (this._useCanvas) {
  20901. this.createUIPre(x, y);
  20902. }
  20903. else
  20904. this.createUI(x, y);
  20905. this.enable();
  20906. }
  20907. createUIPre(x, y) {
  20908. var pixel = Browser.pixelRatio;
  20909. this._width = pixel * 180;
  20910. this._vx = pixel * 120;
  20911. this._height = pixel * (this._view.length * 12 + 3 * pixel) + 4;
  20912. StatUI._fontSize = 12 * pixel;
  20913. for (var i = 0; i < this._view.length; i++) {
  20914. this._view[i].x = 4;
  20915. this._view[i].y = i * StatUI._fontSize + 2 * pixel;
  20916. }
  20917. if (!this._canvas) {
  20918. this._canvas = new HTMLCanvas(true);
  20919. this._canvas.size(this._width, this._height);
  20920. this._ctx = this._canvas.getContext('2d');
  20921. this._ctx.textBaseline = "top";
  20922. this._ctx.font = StatUI._fontSize + "px Arial";
  20923. this._canvas.source.style.cssText = "pointer-events:none;background:rgba(150,150,150,0.8);z-index:100000;position: absolute;direction:ltr;left:" + x + "px;top:" + y + "px;width:" + (this._width / pixel) + "px;height:" + (this._height / pixel) + "px;";
  20924. }
  20925. if (!Browser.onKGMiniGame) {
  20926. Browser.container.appendChild(this._canvas.source);
  20927. }
  20928. this._first = true;
  20929. this.loop();
  20930. this._first = false;
  20931. }
  20932. createUI(x, y) {
  20933. var stat = this._sp;
  20934. var pixel = Browser.pixelRatio;
  20935. if (!stat) {
  20936. stat = new Sprite();
  20937. this._leftText = new Text();
  20938. this._leftText.pos(5, 5);
  20939. this._leftText.color = "#ffffff";
  20940. stat.addChild(this._leftText);
  20941. this._txt = new Text();
  20942. this._txt.pos(130 * pixel, 5);
  20943. this._txt.color = "#ffffff";
  20944. stat.addChild(this._txt);
  20945. this._sp = stat;
  20946. }
  20947. stat.pos(x, y);
  20948. var text = "";
  20949. for (var i = 0; i < this._view.length; i++) {
  20950. var one = this._view[i];
  20951. text += one.title + "\n";
  20952. }
  20953. this._leftText.text = text;
  20954. var width = pixel * 138;
  20955. var height = pixel * (this._view.length * 12 + 3 * pixel) + 4;
  20956. this._txt.fontSize = StatUI._fontSize * pixel;
  20957. this._leftText.fontSize = StatUI._fontSize * pixel;
  20958. stat.size(width, height);
  20959. stat.graphics.clear();
  20960. stat.graphics.alpha(0.5);
  20961. stat.graphics.drawRect(0, 0, width + 110, height + 30, "#999999");
  20962. stat.graphics.alpha(2);
  20963. this.loop();
  20964. }
  20965. enable() {
  20966. ILaya.systemTimer.frameLoop(1, this, this.loop);
  20967. }
  20968. hide() {
  20969. this._show = false;
  20970. ILaya.systemTimer.clear(this, this.loop);
  20971. if (this._canvas) {
  20972. Browser.removeElement(this._canvas.source);
  20973. }
  20974. }
  20975. set_onclick(fn) {
  20976. if (this._sp) {
  20977. this._sp.on("click", this._sp, fn);
  20978. }
  20979. if (this._canvas) {
  20980. this._canvas.source.onclick = fn;
  20981. this._canvas.source.style.pointerEvents = '';
  20982. }
  20983. }
  20984. loop() {
  20985. Stat._count++;
  20986. var timer = Browser.now();
  20987. if (timer - Stat._timer < 1000)
  20988. return;
  20989. var count = Stat._count;
  20990. Stat.FPS = Math.round((count * 1000) / (timer - Stat._timer));
  20991. if (this._show) {
  20992. Stat.trianglesFaces = Math.round(Stat.trianglesFaces / count);
  20993. if (!this._useCanvas) {
  20994. Stat.renderBatches = Math.round(Stat.renderBatches / count) - 1;
  20995. }
  20996. else {
  20997. Stat.renderBatches = Math.round(Stat.renderBatches / count);
  20998. }
  20999. Stat.savedRenderBatches = Math.round(Stat.savedRenderBatches / count);
  21000. Stat.shaderCall = Math.round(Stat.shaderCall / count);
  21001. Stat.spriteRenderUseCacheCount = Math.round(Stat.spriteRenderUseCacheCount / count);
  21002. Stat.canvasNormal = Math.round(Stat.canvasNormal / count);
  21003. Stat.canvasBitmap = Math.round(Stat.canvasBitmap / count);
  21004. Stat.canvasReCache = Math.ceil(Stat.canvasReCache / count);
  21005. Stat.frustumCulling = Math.round(Stat.frustumCulling / count);
  21006. Stat.octreeNodeCulling = Math.round(Stat.octreeNodeCulling / count);
  21007. var delay = Stat.FPS > 0 ? Math.floor(1000 / Stat.FPS).toString() : " ";
  21008. Stat._fpsStr = Stat.FPS + (Stat.renderSlow ? " slow" : "") + " " + delay;
  21009. Stat._spriteStr = Stat.spriteCount + (Stat.spriteRenderUseCacheCount ? ("/" + Stat.spriteRenderUseCacheCount) : '');
  21010. Stat._canvasStr = Stat.canvasReCache + "/" + Stat.canvasNormal + "/" + Stat.canvasBitmap;
  21011. Stat.cpuMemory = Resource.cpuMemory;
  21012. Stat.gpuMemory = Resource.gpuMemory;
  21013. if (this._useCanvas) {
  21014. this.renderInfoPre();
  21015. }
  21016. else
  21017. this.renderInfo();
  21018. Stat.clear();
  21019. }
  21020. Stat._count = 0;
  21021. Stat._timer = timer;
  21022. }
  21023. renderInfoPre() {
  21024. var i = 0;
  21025. var one;
  21026. var value;
  21027. if (this._canvas) {
  21028. var ctx = this._ctx;
  21029. ctx.clearRect(this._first ? 0 : this._vx, 0, this._width, this._height);
  21030. for (i = 0; i < this._view.length; i++) {
  21031. one = this._view[i];
  21032. if (this._first) {
  21033. ctx.fillStyle = "white";
  21034. ctx.fillText(one.title, one.x, one.y);
  21035. }
  21036. ctx.fillStyle = one.color;
  21037. value = Stat[one.value];
  21038. (one.units == "M") && (value = Math.floor(value / (1024 * 1024) * 100) / 100 + " M");
  21039. ctx.fillText(value + "", one.x + this._vx, one.y);
  21040. }
  21041. }
  21042. }
  21043. renderInfo() {
  21044. var text = "";
  21045. for (var i = 0; i < this._view.length; i++) {
  21046. var one = this._view[i];
  21047. var value = Stat[one.value];
  21048. (one.units == "M") && (value = Math.floor(value / (1024 * 1024) * 100) / 100 + " M");
  21049. (one.units == "K") && (value = Math.floor(value / (1024) * 100) / 100 + " K");
  21050. text += value + "\n";
  21051. }
  21052. this._txt.text = text;
  21053. }
  21054. isCanvasRender() {
  21055. return this._useCanvas;
  21056. }
  21057. renderNotCanvas(ctx, x, y) {
  21058. this._show && this._sp && this._sp.render(ctx, 0, 0);
  21059. }
  21060. }
  21061. StatUI._fontSize = 12;
  21062. class Timer {
  21063. constructor(autoActive = true) {
  21064. this.scale = 1;
  21065. this.currTimer = Date.now();
  21066. this.currFrame = 0;
  21067. this._delta = 0;
  21068. this._lastTimer = Date.now();
  21069. this._map = [];
  21070. this._handlers = [];
  21071. this._temp = [];
  21072. this._count = 0;
  21073. autoActive && Timer.gSysTimer && Timer.gSysTimer.frameLoop(1, this, this._update);
  21074. }
  21075. get delta() {
  21076. return this._delta;
  21077. }
  21078. _update() {
  21079. if (this.scale <= 0) {
  21080. this._lastTimer = Date.now();
  21081. this._delta = 0;
  21082. return;
  21083. }
  21084. var frame = this.currFrame = this.currFrame + this.scale;
  21085. var now = Date.now();
  21086. var awake = (now - this._lastTimer) > 30000;
  21087. this._delta = (now - this._lastTimer) * this.scale;
  21088. var timer = this.currTimer = this.currTimer + this._delta;
  21089. this._lastTimer = now;
  21090. var handlers = this._handlers;
  21091. this._count = 0;
  21092. for (var i = 0, n = handlers.length; i < n; i++) {
  21093. var handler = handlers[i];
  21094. if (handler.method !== null) {
  21095. var t = handler.userFrame ? frame : timer;
  21096. if (t >= handler.exeTime) {
  21097. if (handler.repeat) {
  21098. if (!handler.jumpFrame || awake) {
  21099. handler.exeTime += handler.delay;
  21100. handler.run(false);
  21101. if (t > handler.exeTime) {
  21102. handler.exeTime += Math.ceil((t - handler.exeTime) / handler.delay) * handler.delay;
  21103. }
  21104. }
  21105. else {
  21106. while (t >= handler.exeTime) {
  21107. handler.exeTime += handler.delay;
  21108. handler.run(false);
  21109. }
  21110. }
  21111. }
  21112. else {
  21113. handler.run(true);
  21114. }
  21115. }
  21116. }
  21117. else {
  21118. this._count++;
  21119. }
  21120. }
  21121. if (this._count > 30 || frame % 200 === 0)
  21122. this._clearHandlers();
  21123. }
  21124. _clearHandlers() {
  21125. var handlers = this._handlers;
  21126. for (var i = 0, n = handlers.length; i < n; i++) {
  21127. var handler = handlers[i];
  21128. if (handler.method !== null)
  21129. this._temp.push(handler);
  21130. else
  21131. this._recoverHandler(handler);
  21132. }
  21133. this._handlers = this._temp;
  21134. handlers.length = 0;
  21135. this._temp = handlers;
  21136. }
  21137. _recoverHandler(handler) {
  21138. if (this._map[handler.key] == handler)
  21139. this._map[handler.key] = null;
  21140. handler.clear();
  21141. Timer._pool.push(handler);
  21142. }
  21143. _create(useFrame, repeat, delay, caller, method, args, coverBefore) {
  21144. if (!delay) {
  21145. method.apply(caller, args);
  21146. return null;
  21147. }
  21148. if (coverBefore) {
  21149. var handler = this._getHandler(caller, method);
  21150. if (handler) {
  21151. handler.repeat = repeat;
  21152. handler.userFrame = useFrame;
  21153. handler.delay = delay;
  21154. handler.caller = caller;
  21155. handler.method = method;
  21156. handler.args = args;
  21157. handler.exeTime = delay + (useFrame ? this.currFrame : this.currTimer + Date.now() - this._lastTimer);
  21158. return handler;
  21159. }
  21160. }
  21161. handler = Timer._pool.length > 0 ? Timer._pool.pop() : new TimerHandler();
  21162. handler.repeat = repeat;
  21163. handler.userFrame = useFrame;
  21164. handler.delay = delay;
  21165. handler.caller = caller;
  21166. handler.method = method;
  21167. handler.args = args;
  21168. handler.exeTime = delay + (useFrame ? this.currFrame : this.currTimer + Date.now() - this._lastTimer);
  21169. this._indexHandler(handler);
  21170. this._handlers.push(handler);
  21171. return handler;
  21172. }
  21173. _indexHandler(handler) {
  21174. var caller = handler.caller;
  21175. var method = handler.method;
  21176. var cid = caller ? caller.$_GID || (caller.$_GID = ILaya.Utils.getGID()) : 0;
  21177. var mid = method.$_TID || (method.$_TID = (Timer._mid++) * 100000);
  21178. handler.key = cid + mid;
  21179. this._map[handler.key] = handler;
  21180. }
  21181. once(delay, caller, method, args = null, coverBefore = true) {
  21182. this._create(false, false, delay, caller, method, args, coverBefore);
  21183. }
  21184. loop(delay, caller, method, args = null, coverBefore = true, jumpFrame = false) {
  21185. var handler = this._create(false, true, delay, caller, method, args, coverBefore);
  21186. if (handler)
  21187. handler.jumpFrame = jumpFrame;
  21188. }
  21189. frameOnce(delay, caller, method, args = null, coverBefore = true) {
  21190. this._create(true, false, delay, caller, method, args, coverBefore);
  21191. }
  21192. frameLoop(delay, caller, method, args = null, coverBefore = true) {
  21193. this._create(true, true, delay, caller, method, args, coverBefore);
  21194. }
  21195. toString() {
  21196. return " handlers:" + this._handlers.length + " pool:" + Timer._pool.length;
  21197. }
  21198. clear(caller, method) {
  21199. var handler = this._getHandler(caller, method);
  21200. if (handler) {
  21201. this._map[handler.key] = null;
  21202. handler.key = 0;
  21203. handler.clear();
  21204. }
  21205. }
  21206. clearAll(caller) {
  21207. if (!caller)
  21208. return;
  21209. for (var i = 0, n = this._handlers.length; i < n; i++) {
  21210. var handler = this._handlers[i];
  21211. if (handler.caller === caller) {
  21212. this._map[handler.key] = null;
  21213. handler.key = 0;
  21214. handler.clear();
  21215. }
  21216. }
  21217. }
  21218. _getHandler(caller, method) {
  21219. var cid = caller ? caller.$_GID || (caller.$_GID = ILaya.Utils.getGID()) : 0;
  21220. var mid = method.$_TID || (method.$_TID = (Timer._mid++) * 100000);
  21221. return this._map[cid + mid];
  21222. }
  21223. callLater(caller, method, args = null) {
  21224. CallLater.I.callLater(caller, method, args);
  21225. }
  21226. runCallLater(caller, method) {
  21227. CallLater.I.runCallLater(caller, method);
  21228. }
  21229. runTimer(caller, method) {
  21230. var handler = this._getHandler(caller, method);
  21231. if (handler && handler.method != null) {
  21232. this._map[handler.key] = null;
  21233. handler.run(true);
  21234. }
  21235. }
  21236. pause() {
  21237. this.scale = 0;
  21238. }
  21239. resume() {
  21240. this.scale = 1;
  21241. }
  21242. }
  21243. Timer.gSysTimer = null;
  21244. Timer._pool = [];
  21245. Timer._mid = 1;
  21246. class TimerHandler {
  21247. clear() {
  21248. this.caller = null;
  21249. this.method = null;
  21250. this.args = null;
  21251. }
  21252. run(withClear) {
  21253. var caller = this.caller;
  21254. if (caller && caller.destroyed)
  21255. return this.clear();
  21256. var method = this.method;
  21257. var args = this.args;
  21258. withClear && this.clear();
  21259. if (method == null)
  21260. return;
  21261. args ? method.apply(caller, args) : method.call(caller);
  21262. }
  21263. }
  21264. class SkinSV extends Value2D {
  21265. constructor(type) {
  21266. super(ShaderDefines2D.SKINMESH, 0);
  21267. this.offsetX = 300;
  21268. this.offsetY = 0;
  21269. var gl = WebGLContext.mainContext;
  21270. var _vlen = 8 * CONST3D2D.BYTES_PE;
  21271. this.position = [2, gl.FLOAT, false, _vlen, 0];
  21272. this.texcoord = [2, gl.FLOAT, false, _vlen, 2 * CONST3D2D.BYTES_PE];
  21273. this.color = [4, gl.FLOAT, false, _vlen, 4 * CONST3D2D.BYTES_PE];
  21274. }
  21275. }
  21276. class PrimitiveSV extends Value2D {
  21277. constructor(args) {
  21278. super(ShaderDefines2D.PRIMITIVE, 0);
  21279. this._attribLocation = ['position', 0, 'attribColor', 1];
  21280. }
  21281. }
  21282. class TextureSV extends Value2D {
  21283. constructor(subID = 0) {
  21284. super(ShaderDefines2D.TEXTURE2D, subID);
  21285. this.strength = 0;
  21286. this.blurInfo = null;
  21287. this.colorMat = null;
  21288. this.colorAlpha = null;
  21289. this._attribLocation = ['posuv', 0, 'attribColor', 1, 'attribFlags', 2];
  21290. }
  21291. clear() {
  21292. this.texture = null;
  21293. this.shader = null;
  21294. this.defines._value = this.subID + (WebGL.shaderHighPrecision ? ShaderDefines2D.SHADERDEFINE_FSHIGHPRECISION : 0);
  21295. }
  21296. }
  21297. class InlcudeFile {
  21298. constructor(txt) {
  21299. this.codes = {};
  21300. this.funs = {};
  21301. this.curUseID = -1;
  21302. this.funnames = "";
  21303. this.script = txt;
  21304. var begin = 0, ofs, end;
  21305. while (true) {
  21306. begin = txt.indexOf("#begin", begin);
  21307. if (begin < 0)
  21308. break;
  21309. end = begin + 5;
  21310. while (true) {
  21311. end = txt.indexOf("#end", end);
  21312. if (end < 0)
  21313. break;
  21314. if (txt.charAt(end + 4) === 'i')
  21315. end += 5;
  21316. else
  21317. break;
  21318. }
  21319. if (end < 0) {
  21320. throw "add include err,no #end:" + txt;
  21321. }
  21322. ofs = txt.indexOf('\n', begin);
  21323. var words = ILaya.ShaderCompile.splitToWords(txt.substr(begin, ofs - begin), null);
  21324. if (words[1] == 'code') {
  21325. this.codes[words[2]] = txt.substr(ofs + 1, end - ofs - 1);
  21326. }
  21327. else if (words[1] == 'function') {
  21328. ofs = txt.indexOf("function", begin);
  21329. ofs += "function".length;
  21330. this.funs[words[3]] = txt.substr(ofs + 1, end - ofs - 1);
  21331. this.funnames += words[3] + ";";
  21332. }
  21333. begin = end + 1;
  21334. }
  21335. }
  21336. getWith(name = null) {
  21337. var r = name ? this.codes[name] : this.script;
  21338. if (!r) {
  21339. throw "get with error:" + name;
  21340. }
  21341. return r;
  21342. }
  21343. getFunsScript(funsdef) {
  21344. var r = "";
  21345. for (var i in this.funs) {
  21346. if (funsdef.indexOf(i + ";") >= 0) {
  21347. r += this.funs[i];
  21348. }
  21349. }
  21350. return r;
  21351. }
  21352. }
  21353. class ShaderNode {
  21354. constructor(includefiles) {
  21355. this.childs = [];
  21356. this.text = "";
  21357. this.useFuns = "";
  21358. this.z = 0;
  21359. this.includefiles = includefiles;
  21360. }
  21361. setParent(parent) {
  21362. parent.childs.push(this);
  21363. this.z = parent.z + 1;
  21364. this.parent = parent;
  21365. }
  21366. setCondition(condition, type) {
  21367. if (condition) {
  21368. this.conditionType = type;
  21369. condition = condition.replace(/(\s*$)/g, "");
  21370. this.condition = function () {
  21371. return this[condition];
  21372. };
  21373. this.condition.__condition = condition;
  21374. }
  21375. }
  21376. toscript(def, out) {
  21377. return this._toscript(def, out, ++ShaderNode.__id);
  21378. }
  21379. _toscript(def, out, id) {
  21380. if (this.childs.length < 1 && !this.text)
  21381. return out;
  21382. var outIndex = out.length;
  21383. if (this.condition) {
  21384. var ifdef = !!this.condition.call(def);
  21385. this.conditionType === ILaya.ShaderCompile.IFDEF_ELSE && (ifdef = !ifdef);
  21386. if (!ifdef)
  21387. return out;
  21388. }
  21389. this.text && out.push(this.text);
  21390. this.childs.length > 0 && this.childs.forEach(function (o, index, arr) {
  21391. o._toscript(def, out, id);
  21392. });
  21393. if (this.includefiles.length > 0 && this.useFuns.length > 0) {
  21394. var funsCode;
  21395. for (var i = 0, n = this.includefiles.length; i < n; i++) {
  21396. if (this.includefiles[i].curUseID == id) {
  21397. continue;
  21398. }
  21399. funsCode = this.includefiles[i].file.getFunsScript(this.useFuns);
  21400. if (funsCode.length > 0) {
  21401. this.includefiles[i].curUseID = id;
  21402. out[0] = funsCode + out[0];
  21403. }
  21404. }
  21405. }
  21406. return out;
  21407. }
  21408. }
  21409. ShaderNode.__id = 1;
  21410. class ShaderCompile {
  21411. constructor(vs, ps, nameMap) {
  21412. this.defs = {};
  21413. let _this = this;
  21414. function _compile(script) {
  21415. script = script.replace(ShaderCompile._clearCR, "");
  21416. var includefiles = [];
  21417. var top = new ShaderNode(includefiles);
  21418. _this._compileToTree(top, script.split('\n'), 0, includefiles, _this.defs);
  21419. return top;
  21420. }
  21421. var startTime = Date.now();
  21422. this._VS = _compile(vs);
  21423. this._PS = _compile(ps);
  21424. this._nameMap = nameMap;
  21425. if ((Date.now() - startTime) > 2)
  21426. console.log("ShaderCompile use time:" + (Date.now() - startTime) + " size:" + vs.length + "/" + ps.length);
  21427. }
  21428. static __init__() {
  21429. var gl = LayaGL.instance;
  21430. ShaderCompile.shaderParamsMap = { "float": gl.FLOAT, "int": gl.INT, "bool": gl.BOOL, "vec2": gl.FLOAT_VEC2, "vec3": gl.FLOAT_VEC3, "vec4": gl.FLOAT_VEC4, "ivec2": gl.INT_VEC2, "ivec3": gl.INT_VEC3, "ivec4": gl.INT_VEC4, "bvec2": gl.BOOL_VEC2, "bvec3": gl.BOOL_VEC3, "bvec4": gl.BOOL_VEC4, "mat2": gl.FLOAT_MAT2, "mat3": gl.FLOAT_MAT3, "mat4": gl.FLOAT_MAT4, "sampler2D": gl.SAMPLER_2D, "samplerCube": gl.SAMPLER_CUBE };
  21431. }
  21432. static _parseOne(attributes, uniforms, words, i, word, b) {
  21433. var one = { type: ShaderCompile.shaderParamsMap[words[i + 1]], name: words[i + 2], size: isNaN(parseInt(words[i + 3])) ? 1 : parseInt(words[i + 3]) };
  21434. if (b) {
  21435. if (word == "attribute") {
  21436. attributes.push(one);
  21437. }
  21438. else {
  21439. uniforms.push(one);
  21440. }
  21441. }
  21442. if (words[i + 3] == ':') {
  21443. one.type = words[i + 4];
  21444. i += 2;
  21445. }
  21446. i += 2;
  21447. return i;
  21448. }
  21449. static addInclude(fileName, txt) {
  21450. if (!txt || txt.length === 0)
  21451. throw new Error("add shader include file err:" + fileName);
  21452. if (ShaderCompile.includes[fileName])
  21453. throw new Error("add shader include file err, has add:" + fileName);
  21454. ShaderCompile.includes[fileName] = new InlcudeFile(txt);
  21455. }
  21456. static preGetParams(vs, ps) {
  21457. var text = [vs, ps];
  21458. var result = {};
  21459. var attributes = [];
  21460. var uniforms = [];
  21461. var definesInfo = {};
  21462. var definesName = [];
  21463. result.attributes = attributes;
  21464. result.uniforms = uniforms;
  21465. result.defines = definesInfo;
  21466. var i, n;
  21467. for (var s = 0; s < 2; s++) {
  21468. text[s] = text[s].replace(ShaderCompile._removeAnnotation, "");
  21469. var words = text[s].match(ShaderCompile._reg);
  21470. var tempelse;
  21471. for (i = 0, n = words.length; i < n; i++) {
  21472. var word = words[i];
  21473. if (word != "attribute" && word != "uniform") {
  21474. if (word == "#define") {
  21475. word = words[++i];
  21476. definesName[word] = 1;
  21477. continue;
  21478. }
  21479. else if (word == "#ifdef") {
  21480. tempelse = words[++i];
  21481. var def = definesInfo[tempelse] = definesInfo[tempelse] || [];
  21482. for (i++; i < n; i++) {
  21483. word = words[i];
  21484. if (word != "attribute" && word != "uniform") {
  21485. if (word == "#else") {
  21486. for (i++; i < n; i++) {
  21487. word = words[i];
  21488. if (word != "attribute" && word != "uniform") {
  21489. if (word == "#endif") {
  21490. break;
  21491. }
  21492. continue;
  21493. }
  21494. i = ShaderCompile._parseOne(attributes, uniforms, words, i, word, !definesName[tempelse]);
  21495. }
  21496. }
  21497. continue;
  21498. }
  21499. i = ShaderCompile._parseOne(attributes, uniforms, words, i, word, definesName[tempelse]);
  21500. }
  21501. }
  21502. continue;
  21503. }
  21504. i = ShaderCompile._parseOne(attributes, uniforms, words, i, word, true);
  21505. }
  21506. }
  21507. return result;
  21508. }
  21509. static splitToWords(str, block) {
  21510. var out = [];
  21511. var c;
  21512. var ofs = -1;
  21513. var word;
  21514. for (var i = 0, n = str.length; i < n; i++) {
  21515. c = str.charAt(i);
  21516. if (" \t=+-*/&%!<>()'\",;".indexOf(c) >= 0) {
  21517. if (ofs >= 0 && (i - ofs) > 1) {
  21518. word = str.substr(ofs, i - ofs);
  21519. out.push(word);
  21520. }
  21521. if (c == '"' || c == "'") {
  21522. var ofs2 = str.indexOf(c, i + 1);
  21523. if (ofs2 < 0) {
  21524. throw "Sharder err:" + str;
  21525. }
  21526. out.push(str.substr(i + 1, ofs2 - i - 1));
  21527. i = ofs2;
  21528. ofs = -1;
  21529. continue;
  21530. }
  21531. if (c == '(' && block && out.length > 0) {
  21532. word = out[out.length - 1] + ";";
  21533. if ("vec4;main;".indexOf(word) < 0)
  21534. block.useFuns += word;
  21535. }
  21536. ofs = -1;
  21537. continue;
  21538. }
  21539. if (ofs < 0)
  21540. ofs = i;
  21541. }
  21542. if (ofs < n && (n - ofs) > 1) {
  21543. word = str.substr(ofs, n - ofs);
  21544. out.push(word);
  21545. }
  21546. return out;
  21547. }
  21548. _compileToTree(parent, lines, start, includefiles, defs) {
  21549. var node, preNode;
  21550. var text, name, fname;
  21551. var ofs, words, noUseNode;
  21552. var i, n, j;
  21553. for (i = start; i < lines.length; i++) {
  21554. text = lines[i];
  21555. if (text.length < 1)
  21556. continue;
  21557. ofs = text.indexOf("//");
  21558. if (ofs === 0)
  21559. continue;
  21560. if (ofs >= 0)
  21561. text = text.substr(0, ofs);
  21562. node = noUseNode || new ShaderNode(includefiles);
  21563. noUseNode = null;
  21564. node.text = text;
  21565. node.noCompile = true;
  21566. if ((ofs = text.indexOf("#")) >= 0) {
  21567. name = "#";
  21568. for (j = ofs + 1, n = text.length; j < n; j++) {
  21569. var c = text.charAt(j);
  21570. if (c === ' ' || c === '\t' || c === '?')
  21571. break;
  21572. name += c;
  21573. }
  21574. node.name = name;
  21575. switch (name) {
  21576. case "#ifdef":
  21577. case "#ifndef":
  21578. node.src = text;
  21579. node.noCompile = text.match(/[!&|()=<>]/) != null;
  21580. if (!node.noCompile) {
  21581. words = text.replace(/^\s*/, '').split(/\s+/);
  21582. node.setCondition(words[1], name === "#ifdef" ? ShaderCompile.IFDEF_YES : ShaderCompile.IFDEF_ELSE);
  21583. node.text = "//" + node.text;
  21584. }
  21585. else {
  21586. console.log("function():Boolean{return " + text.substr(ofs + node.name.length) + "}");
  21587. }
  21588. node.setParent(parent);
  21589. parent = node;
  21590. if (defs) {
  21591. words = text.substr(j).split(ShaderCompile._splitToWordExps3);
  21592. for (j = 0; j < words.length; j++) {
  21593. text = words[j];
  21594. text.length && (defs[text] = true);
  21595. }
  21596. }
  21597. continue;
  21598. case "#if":
  21599. node.src = text;
  21600. node.noCompile = true;
  21601. node.setParent(parent);
  21602. parent = node;
  21603. if (defs) {
  21604. words = text.substr(j).split(ShaderCompile._splitToWordExps3);
  21605. for (j = 0; j < words.length; j++) {
  21606. text = words[j];
  21607. text.length && text != "defined" && (defs[text] = true);
  21608. }
  21609. }
  21610. continue;
  21611. case "#else":
  21612. node.src = text;
  21613. parent = parent.parent;
  21614. preNode = parent.childs[parent.childs.length - 1];
  21615. node.noCompile = preNode.noCompile;
  21616. if (!node.noCompile) {
  21617. node.condition = preNode.condition;
  21618. node.conditionType = preNode.conditionType == ShaderCompile.IFDEF_YES ? ShaderCompile.IFDEF_ELSE : ShaderCompile.IFDEF_YES;
  21619. node.text = "//" + node.text + " " + preNode.text + " " + node.conditionType;
  21620. }
  21621. node.setParent(parent);
  21622. parent = node;
  21623. continue;
  21624. case "#endif":
  21625. parent = parent.parent;
  21626. preNode = parent.childs[parent.childs.length - 1];
  21627. node.noCompile = preNode.noCompile;
  21628. if (!node.noCompile) {
  21629. node.text = "//" + node.text;
  21630. }
  21631. node.setParent(parent);
  21632. continue;
  21633. case "#include":
  21634. words = ShaderCompile.splitToWords(text, null);
  21635. var inlcudeFile = ShaderCompile.includes[words[1]];
  21636. if (!inlcudeFile) {
  21637. throw "ShaderCompile error no this include file:" + words[1];
  21638. }
  21639. if ((ofs = words[0].indexOf("?")) < 0) {
  21640. node.setParent(parent);
  21641. text = inlcudeFile.getWith(words[2] == 'with' ? words[3] : null);
  21642. this._compileToTree(node, text.split('\n'), 0, includefiles, defs);
  21643. node.text = "";
  21644. continue;
  21645. }
  21646. node.setCondition(words[0].substr(ofs + 1), ShaderCompile.IFDEF_YES);
  21647. node.text = inlcudeFile.getWith(words[2] == 'with' ? words[3] : null);
  21648. break;
  21649. case "#import":
  21650. words = ShaderCompile.splitToWords(text, null);
  21651. fname = words[1];
  21652. includefiles.push({ node: node, file: ShaderCompile.includes[fname], ofs: node.text.length });
  21653. continue;
  21654. }
  21655. }
  21656. else {
  21657. preNode = parent.childs[parent.childs.length - 1];
  21658. if (preNode && !preNode.name) {
  21659. includefiles.length > 0 && ShaderCompile.splitToWords(text, preNode);
  21660. noUseNode = node;
  21661. preNode.text += "\n" + text;
  21662. continue;
  21663. }
  21664. includefiles.length > 0 && ShaderCompile.splitToWords(text, node);
  21665. }
  21666. node.setParent(parent);
  21667. }
  21668. }
  21669. createShader(define, shaderName, createShader, bindAttrib) {
  21670. var defMap = {};
  21671. var defineStr = "";
  21672. if (define) {
  21673. for (var i in define) {
  21674. defineStr += "#define " + i + "\n";
  21675. defMap[i] = true;
  21676. }
  21677. }
  21678. var vs = this._VS.toscript(defMap, []);
  21679. var ps = this._PS.toscript(defMap, []);
  21680. return (createShader || Shader.create)(defineStr + vs.join('\n'), defineStr + ps.join('\n'), shaderName, this._nameMap, bindAttrib);
  21681. }
  21682. }
  21683. ShaderCompile.IFDEF_NO = 0;
  21684. ShaderCompile.IFDEF_YES = 1;
  21685. ShaderCompile.IFDEF_ELSE = 2;
  21686. ShaderCompile.IFDEF_PARENT = 3;
  21687. ShaderCompile._removeAnnotation = new RegExp("(/\\*([^*]|[\\r\\\n]|(\\*+([^*/]|[\\r\\n])))*\\*+/)|(//.*)", "g");
  21688. ShaderCompile._reg = new RegExp("(\".*\")|('.*')|([#\\w\\*-\\.+/()=<>{}\\\\]+)|([,;:\\\\])", "g");
  21689. ShaderCompile._splitToWordExps = new RegExp("[(\".*\")]+|[('.*')]+|([ \\t=\\+\\-*/&%!<>!%\(\),;])", "g");
  21690. ShaderCompile.includes = {};
  21691. ShaderCompile._clearCR = new RegExp("\r", "g");
  21692. ShaderCompile._splitToWordExps3 = new RegExp("[ \\t=\\+\\-*/&%!<>!%\(\),;\\|]", "g");
  21693. class WorkerLoader extends EventDispatcher {
  21694. constructor() {
  21695. super();
  21696. this.worker = new Worker(WorkerLoader.workerPath);
  21697. let me = this;
  21698. this.worker.onmessage = function (evt) {
  21699. me.workerMessage(evt.data);
  21700. };
  21701. }
  21702. static __init__() {
  21703. if (WorkerLoader._preLoadFun != null)
  21704. return false;
  21705. if (!Worker)
  21706. return false;
  21707. WorkerLoader._preLoadFun = Loader["prototype"]["_loadImage"];
  21708. Loader["prototype"]["_loadImage"] = WorkerLoader["prototype"]["_loadImage"];
  21709. if (!WorkerLoader.I)
  21710. WorkerLoader.I = new WorkerLoader();
  21711. return true;
  21712. }
  21713. static workerSupported() {
  21714. return Worker ? true : false;
  21715. }
  21716. static enableWorkerLoader() {
  21717. if (!WorkerLoader._tryEnabled) {
  21718. WorkerLoader.enable = true;
  21719. WorkerLoader._tryEnabled = true;
  21720. }
  21721. }
  21722. static set enable(value) {
  21723. if (WorkerLoader._enable != value) {
  21724. WorkerLoader._enable = value;
  21725. if (value && WorkerLoader._preLoadFun == null)
  21726. WorkerLoader._enable = WorkerLoader.__init__();
  21727. }
  21728. }
  21729. static get enable() {
  21730. return WorkerLoader._enable;
  21731. }
  21732. workerMessage(data) {
  21733. if (data) {
  21734. switch (data.type) {
  21735. case "Image":
  21736. this.imageLoaded(data);
  21737. break;
  21738. case "Disable":
  21739. WorkerLoader.enable = false;
  21740. break;
  21741. }
  21742. }
  21743. }
  21744. imageLoaded(data) {
  21745. if (!data.dataType || data.dataType != "imageBitmap") {
  21746. this.event(data.url, null);
  21747. return;
  21748. }
  21749. var imageData = data.imageBitmap;
  21750. var tex = new Texture2D();
  21751. tex.loadImageSource(imageData);
  21752. console.log("load:", data.url);
  21753. this.event(data.url, tex);
  21754. }
  21755. loadImage(url) {
  21756. this.worker.postMessage(url);
  21757. }
  21758. _loadImage(url) {
  21759. var _this = this;
  21760. if (!this._useWorkerLoader || !WorkerLoader._enable) {
  21761. WorkerLoader._preLoadFun.call(_this, url);
  21762. return;
  21763. }
  21764. url = URL.formatURL(url);
  21765. function clear() {
  21766. WorkerLoader.I.off(url, _this, onload);
  21767. }
  21768. var onload = function (image) {
  21769. clear();
  21770. if (image) {
  21771. _this["onLoaded"](image);
  21772. }
  21773. else {
  21774. WorkerLoader._preLoadFun.call(_this, url);
  21775. }
  21776. };
  21777. WorkerLoader.I.on(url, _this, onload);
  21778. WorkerLoader.I.loadImage(url);
  21779. }
  21780. }
  21781. WorkerLoader.workerPath = "libs/workerloader.js";
  21782. WorkerLoader._enable = false;
  21783. WorkerLoader._tryEnabled = false;
  21784. class Mouse {
  21785. static set cursor(cursorStr) {
  21786. Mouse._style.cursor = cursorStr;
  21787. }
  21788. static get cursor() {
  21789. return Mouse._style.cursor;
  21790. }
  21791. static __init__() {
  21792. }
  21793. static hide() {
  21794. if (Mouse.cursor != "none") {
  21795. Mouse._preCursor = Mouse.cursor;
  21796. Mouse.cursor = "none";
  21797. }
  21798. }
  21799. static show() {
  21800. if (Mouse.cursor == "none") {
  21801. if (Mouse._preCursor) {
  21802. Mouse.cursor = Mouse._preCursor;
  21803. }
  21804. else {
  21805. Mouse.cursor = "auto";
  21806. }
  21807. }
  21808. }
  21809. }
  21810. class MeshParticle2D extends Mesh2D {
  21811. constructor(maxNum) {
  21812. super(MeshParticle2D.const_stride, maxNum * 4 * MeshParticle2D.const_stride, 4);
  21813. this.canReuse = true;
  21814. this.setAttributes(MeshParticle2D._fixattriInfo);
  21815. this.createQuadIB(maxNum);
  21816. this._quadNum = maxNum;
  21817. }
  21818. static __init__() {
  21819. var gl = LayaGL.instance;
  21820. MeshParticle2D._fixattriInfo = [gl.FLOAT, 4, 0,
  21821. gl.FLOAT, 3, 16,
  21822. gl.FLOAT, 3, 28,
  21823. gl.FLOAT, 4, 40,
  21824. gl.FLOAT, 4, 56,
  21825. gl.FLOAT, 3, 72,
  21826. gl.FLOAT, 2, 84,
  21827. gl.FLOAT, 4, 92,
  21828. gl.FLOAT, 1, 108,
  21829. gl.FLOAT, 1, 112];
  21830. }
  21831. setMaxParticleNum(maxNum) {
  21832. this._vb._resizeBuffer(maxNum * 4 * MeshParticle2D.const_stride, false);
  21833. this.createQuadIB(maxNum);
  21834. }
  21835. static getAMesh(maxNum) {
  21836. if (MeshParticle2D._POOL.length) {
  21837. var ret = MeshParticle2D._POOL.pop();
  21838. ret.setMaxParticleNum(maxNum);
  21839. return ret;
  21840. }
  21841. return new MeshParticle2D(maxNum);
  21842. }
  21843. releaseMesh() {
  21844. this._vb.setByteLength(0);
  21845. this.vertNum = 0;
  21846. this.indexNum = 0;
  21847. MeshParticle2D._POOL.push(this);
  21848. }
  21849. destroy() {
  21850. this._ib.destroy();
  21851. this._vb.destroy();
  21852. this._vb.deleteBuffer();
  21853. }
  21854. }
  21855. MeshParticle2D.const_stride = 116;
  21856. MeshParticle2D._POOL = [];
  21857. class HTMLImage extends Bitmap {
  21858. }
  21859. HTMLImage.create = function (width, height, format) {
  21860. var tex = new Texture2D(width, height, format, false, false);
  21861. tex.wrapModeU = BaseTexture.WARPMODE_CLAMP;
  21862. tex.wrapModeV = BaseTexture.WARPMODE_CLAMP;
  21863. return tex;
  21864. };
  21865. class Laya {
  21866. static __init(_classs) {
  21867. _classs.forEach(function (o) { o.__init$ && o.__init$(); });
  21868. }
  21869. static init(width, height, ...plugins) {
  21870. if (Laya._isinit)
  21871. return;
  21872. Laya._isinit = true;
  21873. ArrayBuffer.prototype.slice || (ArrayBuffer.prototype.slice = Laya._arrayBufferSlice);
  21874. Browser.__init__();
  21875. var mainCanv = Browser.mainCanvas = new HTMLCanvas(true);
  21876. var style = mainCanv.source.style;
  21877. style.position = 'absolute';
  21878. style.top = style.left = "0px";
  21879. style.background = "#000000";
  21880. if (!Browser.onKGMiniGame && !Browser.onAlipayMiniGame) {
  21881. Browser.container.appendChild(mainCanv.source);
  21882. }
  21883. Browser.canvas = new HTMLCanvas(true);
  21884. Browser.context = Browser.canvas.getContext('2d');
  21885. Browser.supportWebAudio = SoundManager.__init__();
  21886. Browser.supportLocalStorage = LocalStorage.__init__();
  21887. Laya.systemTimer = new Timer(false);
  21888. exports.systemTimer = Timer.gSysTimer = Laya.systemTimer;
  21889. Laya.startTimer = new Timer(false);
  21890. Laya.physicsTimer = new Timer(false);
  21891. Laya.updateTimer = new Timer(false);
  21892. Laya.lateTimer = new Timer(false);
  21893. Laya.timer = new Timer(false);
  21894. exports.startTimer = ILaya.startTimer = Laya.startTimer;
  21895. exports.lateTimer = ILaya.lateTimer = Laya.lateTimer;
  21896. exports.updateTimer = ILaya.updateTimer = Laya.updateTimer;
  21897. ILaya.systemTimer = Laya.systemTimer;
  21898. exports.timer = ILaya.timer = Laya.timer;
  21899. exports.physicsTimer = ILaya.physicsTimer = Laya.physicsTimer;
  21900. Laya.loader = new LoaderManager();
  21901. ILaya.Laya = Laya;
  21902. exports.loader = ILaya.loader = Laya.loader;
  21903. WeakObject.__init__();
  21904. SceneUtils.__init();
  21905. Mouse.__init__();
  21906. WebGL.inner_enable();
  21907. if (plugins) {
  21908. for (var i = 0, n = plugins.length; i < n; i++) {
  21909. if (plugins[i] && plugins[i].enable) {
  21910. plugins[i].enable();
  21911. }
  21912. }
  21913. }
  21914. if (ILaya.Render.isConchApp) {
  21915. Laya.enableNative();
  21916. }
  21917. Laya.enableWebGLPlus();
  21918. CacheManger.beginCheck();
  21919. exports.stage = Laya.stage = new Stage();
  21920. ILaya.stage = Laya.stage;
  21921. Utils.gStage = Laya.stage;
  21922. URL.rootPath = URL._basePath = Laya._getUrlPath();
  21923. MeshQuadTexture.__int__();
  21924. MeshVG.__init__();
  21925. MeshTexture.__init__();
  21926. Laya.render = new Render(0, 0, Browser.mainCanvas);
  21927. exports.render = Laya.render;
  21928. Laya.stage.size(width, height);
  21929. window.stage = Laya.stage;
  21930. WebGLContext.__init__();
  21931. MeshParticle2D.__init__();
  21932. ShaderCompile.__init__();
  21933. RenderSprite.__init__();
  21934. KeyBoardManager.__init__();
  21935. MouseManager.instance.__init__(Laya.stage, Render.canvas);
  21936. Input.__init__();
  21937. SoundManager.autoStopMusic = true;
  21938. Stat._StatRender = new StatUI();
  21939. Value2D._initone(ShaderDefines2D.TEXTURE2D, TextureSV);
  21940. Value2D._initone(ShaderDefines2D.TEXTURE2D | ShaderDefines2D.FILTERGLOW, TextureSV);
  21941. Value2D._initone(ShaderDefines2D.PRIMITIVE, PrimitiveSV);
  21942. Value2D._initone(ShaderDefines2D.SKINMESH, SkinSV);
  21943. return Render.canvas;
  21944. }
  21945. static _getUrlPath() {
  21946. var location = Browser.window.location;
  21947. var pathName = location.pathname;
  21948. pathName = pathName.charAt(2) == ':' ? pathName.substring(1) : pathName;
  21949. return URL.getPath(location.protocol == "file:" ? pathName : location.protocol + "//" + location.host + location.pathname);
  21950. }
  21951. static _arrayBufferSlice(start, end) {
  21952. var arr = this;
  21953. var arrU8List = new Uint8Array(arr, start, end - start);
  21954. var newU8List = new Uint8Array(arrU8List.length);
  21955. newU8List.set(arrU8List);
  21956. return newU8List.buffer;
  21957. }
  21958. static set alertGlobalError(value) {
  21959. var erralert = 0;
  21960. if (value) {
  21961. Browser.window.onerror = function (msg, url, line, column, detail) {
  21962. if (erralert++ < 5 && detail)
  21963. this.alert("出错啦,请把此信息截图给研发商\n" + msg + "\n" + detail.stack);
  21964. };
  21965. }
  21966. else {
  21967. Browser.window.onerror = null;
  21968. }
  21969. }
  21970. static _runScript(script) {
  21971. return Browser.window[Laya._evcode](script);
  21972. }
  21973. static enableDebugPanel(debugJsPath = "libs/laya.debugtool.js") {
  21974. if (!window['Laya']["DebugPanel"]) {
  21975. var script = Browser.createElement("script");
  21976. script.onload = function () {
  21977. window['Laya']["DebugPanel"].enable();
  21978. };
  21979. script.src = debugJsPath;
  21980. Browser.document.body.appendChild(script);
  21981. }
  21982. else {
  21983. window['Laya']["DebugPanel"].enable();
  21984. }
  21985. }
  21986. static enableWebGLPlus() {
  21987. WebGLContext.__init_native();
  21988. }
  21989. static enableNative() {
  21990. if (Laya.isNativeRender_enable)
  21991. return;
  21992. Laya.isNativeRender_enable = true;
  21993. Shader.prototype.uploadTexture2D = function (value) {
  21994. var gl = LayaGL.instance;
  21995. gl.bindTexture(gl.TEXTURE_2D, value);
  21996. };
  21997. RenderState2D.width = Browser.window.innerWidth;
  21998. RenderState2D.height = Browser.window.innerHeight;
  21999. Browser.measureText = function (txt, font) {
  22000. window["conchTextCanvas"].font = font;
  22001. return window["conchTextCanvas"].measureText(txt);
  22002. };
  22003. Stage.clear = function (color) {
  22004. Context.set2DRenderConfig();
  22005. var c = ColorUtils.create(color).arrColor;
  22006. var gl = LayaGL.instance;
  22007. if (c)
  22008. gl.clearColor(c[0], c[1], c[2], c[3]);
  22009. gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
  22010. RenderState2D.clear();
  22011. };
  22012. Sprite.drawToCanvas = Sprite.drawToTexture = function (sprite, _renderType, canvasWidth, canvasHeight, offsetX, offsetY) {
  22013. offsetX -= sprite.x;
  22014. offsetY -= sprite.y;
  22015. offsetX |= 0;
  22016. offsetY |= 0;
  22017. canvasWidth |= 0;
  22018. canvasHeight |= 0;
  22019. var canv = new HTMLCanvas(false);
  22020. var ctx = canv.getContext('2d');
  22021. canv.size(canvasWidth, canvasHeight);
  22022. ctx.asBitmap = true;
  22023. ctx._targets.start();
  22024. RenderSprite.renders[_renderType]._fun(sprite, ctx, offsetX, offsetY);
  22025. ctx.flush();
  22026. ctx._targets.end();
  22027. ctx._targets.restore();
  22028. return canv;
  22029. };
  22030. Object["defineProperty"](RenderTexture2D.prototype, "uv", {
  22031. "get": function () {
  22032. return this._uv;
  22033. },
  22034. "set": function (v) {
  22035. this._uv = v;
  22036. }
  22037. });
  22038. HTMLCanvas.prototype.getTexture = function () {
  22039. if (!this._texture) {
  22040. this._texture = this.context._targets;
  22041. this._texture.uv = RenderTexture2D.flipyuv;
  22042. this._texture.bitmap = this._texture;
  22043. }
  22044. return this._texture;
  22045. };
  22046. }
  22047. }
  22048. Laya.stage = null;
  22049. Laya.systemTimer = null;
  22050. Laya.startTimer = null;
  22051. Laya.physicsTimer = null;
  22052. Laya.updateTimer = null;
  22053. Laya.lateTimer = null;
  22054. Laya.timer = null;
  22055. Laya.loader = null;
  22056. Laya.version = "2.3.1";
  22057. Laya._isinit = false;
  22058. Laya.isWXOpenDataContext = false;
  22059. Laya.isWXPosMsg = false;
  22060. Laya.__classmap = null;
  22061. Laya.Config = Config;
  22062. Laya.TextRender = TextRender;
  22063. Laya.EventDispatcher = EventDispatcher;
  22064. Laya.SoundChannel = SoundChannel;
  22065. Laya.Stage = Stage;
  22066. Laya.Render = Render;
  22067. Laya.Browser = Browser;
  22068. Laya.Sprite = Sprite;
  22069. Laya.Node = Node;
  22070. Laya.Context = Context;
  22071. Laya.WebGL = WebGL;
  22072. Laya.Handler = Handler;
  22073. Laya.RunDriver = RunDriver;
  22074. Laya.Utils = Utils;
  22075. Laya.Input = Input;
  22076. Laya.Loader = Loader;
  22077. Laya.LocalStorage = LocalStorage;
  22078. Laya.SoundManager = SoundManager;
  22079. Laya.URL = URL;
  22080. Laya.Event = Event;
  22081. Laya.Matrix = Matrix;
  22082. Laya.HTMLImage = HTMLImage;
  22083. Laya.Laya = Laya;
  22084. Laya._evcode = "eva" + "l";
  22085. Laya.isNativeRender_enable = false;
  22086. Laya.__classmap = ILaya.__classMap;
  22087. ILaya.Timer = Timer;
  22088. ILaya.Dragging = Dragging;
  22089. ILaya.GraphicsBounds = GraphicsBounds;
  22090. ILaya.Sprite = Sprite;
  22091. ILaya.TextRender = TextRender;
  22092. ILaya.Loader = Loader;
  22093. ILaya.TTFLoader = TTFLoader;
  22094. ILaya.WebAudioSound = WebAudioSound;
  22095. ILaya.SoundManager = SoundManager;
  22096. ILaya.ShaderCompile = ShaderCompile;
  22097. ILaya.ClassUtils = ClassUtils;
  22098. ILaya.SceneUtils = SceneUtils;
  22099. ILaya.Context = Context;
  22100. ILaya.Render = Render;
  22101. ILaya.MouseManager = MouseManager;
  22102. ILaya.Text = Text;
  22103. ILaya.Browser = Browser;
  22104. ILaya.WebGL = WebGL;
  22105. ILaya.AudioSound = AudioSound;
  22106. ILaya.Pool = Pool;
  22107. ILaya.Utils = Utils;
  22108. ILaya.Graphics = Graphics;
  22109. ILaya.Submit = Submit;
  22110. ILaya.Stage = Stage;
  22111. ILaya.Resource = Resource;
  22112. ILaya.WorkerLoader = WorkerLoader;
  22113. var libs = window._layalibs;
  22114. if (libs) {
  22115. libs.sort(function (a, b) {
  22116. return a.i - b.i;
  22117. });
  22118. for (var j = 0; j < libs.length; j++) {
  22119. libs[j].f(window, window.document, Laya);
  22120. }
  22121. }
  22122. let win = window;
  22123. if (win.Laya) {
  22124. win.Laya.Laya = Laya;
  22125. Object.assign(win.Laya, Laya);
  22126. }
  22127. else
  22128. win.Laya = Laya;
  22129. var __init = Laya.__init;
  22130. var init = Laya.init;
  22131. var version = Laya.version;
  22132. var isWXOpenDataContext;
  22133. var isWXPosMsg;
  22134. var alertGlobalError = Laya.alertGlobalError;
  22135. var enableDebugPanel = Laya.enableDebugPanel;
  22136. function _static(_class, def) {
  22137. for (var i = 0, sz = def.length; i < sz; i += 2) {
  22138. if (def[i] == 'length')
  22139. _class.length = def[i + 1].call(_class);
  22140. else {
  22141. function tmp() {
  22142. var name = def[i];
  22143. var getfn = def[i + 1];
  22144. Object.defineProperty(_class, name, {
  22145. get: function () { delete this[name]; return this[name] = getfn.call(this); },
  22146. set: function (v) { delete this[name]; this[name] = v; }, enumerable: true, configurable: true
  22147. });
  22148. }
  22149. tmp();
  22150. }
  22151. }
  22152. }
  22153. class CommonScript extends Component {
  22154. get isSingleton() {
  22155. return false;
  22156. }
  22157. constructor() {
  22158. super();
  22159. }
  22160. onAwake() {
  22161. }
  22162. onEnable() {
  22163. }
  22164. onStart() {
  22165. }
  22166. onUpdate() {
  22167. }
  22168. onLateUpdate() {
  22169. }
  22170. onDisable() {
  22171. }
  22172. onDestroy() {
  22173. }
  22174. }
  22175. class Script extends Component {
  22176. get isSingleton() {
  22177. return false;
  22178. }
  22179. _onAwake() {
  22180. this.onAwake();
  22181. if (this.onStart !== Script.prototype.onStart) {
  22182. ILaya.startTimer.callLater(this, this.onStart);
  22183. }
  22184. }
  22185. _onEnable() {
  22186. var proto = Script.prototype;
  22187. if (this.onTriggerEnter !== proto.onTriggerEnter) {
  22188. this.owner.on(Event.TRIGGER_ENTER, this, this.onTriggerEnter);
  22189. }
  22190. if (this.onTriggerStay !== proto.onTriggerStay) {
  22191. this.owner.on(Event.TRIGGER_STAY, this, this.onTriggerStay);
  22192. }
  22193. if (this.onTriggerExit !== proto.onTriggerExit) {
  22194. this.owner.on(Event.TRIGGER_EXIT, this, this.onTriggerExit);
  22195. }
  22196. if (this.onMouseDown !== proto.onMouseDown) {
  22197. this.owner.on(Event.MOUSE_DOWN, this, this.onMouseDown);
  22198. }
  22199. if (this.onMouseUp !== proto.onMouseUp) {
  22200. this.owner.on(Event.MOUSE_UP, this, this.onMouseUp);
  22201. }
  22202. if (this.onClick !== proto.onClick) {
  22203. this.owner.on(Event.CLICK, this, this.onClick);
  22204. }
  22205. if (this.onStageMouseDown !== proto.onStageMouseDown) {
  22206. ILaya.stage.on(Event.MOUSE_DOWN, this, this.onStageMouseDown);
  22207. }
  22208. if (this.onStageMouseUp !== proto.onStageMouseUp) {
  22209. ILaya.stage.on(Event.MOUSE_UP, this, this.onStageMouseUp);
  22210. }
  22211. if (this.onStageClick !== proto.onStageClick) {
  22212. ILaya.stage.on(Event.CLICK, this, this.onStageClick);
  22213. }
  22214. if (this.onStageMouseMove !== proto.onStageMouseMove) {
  22215. ILaya.stage.on(Event.MOUSE_MOVE, this, this.onStageMouseMove);
  22216. }
  22217. if (this.onDoubleClick !== proto.onDoubleClick) {
  22218. this.owner.on(Event.DOUBLE_CLICK, this, this.onDoubleClick);
  22219. }
  22220. if (this.onRightClick !== proto.onRightClick) {
  22221. this.owner.on(Event.RIGHT_CLICK, this, this.onRightClick);
  22222. }
  22223. if (this.onMouseMove !== proto.onMouseMove) {
  22224. this.owner.on(Event.MOUSE_MOVE, this, this.onMouseMove);
  22225. }
  22226. if (this.onMouseOver !== proto.onMouseOver) {
  22227. this.owner.on(Event.MOUSE_OVER, this, this.onMouseOver);
  22228. }
  22229. if (this.onMouseOut !== proto.onMouseOut) {
  22230. this.owner.on(Event.MOUSE_OUT, this, this.onMouseOut);
  22231. }
  22232. if (this.onKeyDown !== proto.onKeyDown) {
  22233. ILaya.stage.on(Event.KEY_DOWN, this, this.onKeyDown);
  22234. }
  22235. if (this.onKeyPress !== proto.onKeyPress) {
  22236. ILaya.stage.on(Event.KEY_PRESS, this, this.onKeyPress);
  22237. }
  22238. if (this.onKeyUp !== proto.onKeyUp) {
  22239. ILaya.stage.on(Event.KEY_UP, this, this.onKeyUp);
  22240. }
  22241. if (this.onUpdate !== proto.onUpdate) {
  22242. ILaya.updateTimer.frameLoop(1, this, this.onUpdate);
  22243. }
  22244. if (this.onLateUpdate !== proto.onLateUpdate) {
  22245. ILaya.lateTimer.frameLoop(1, this, this.onLateUpdate);
  22246. }
  22247. if (this.onPreRender !== proto.onPreRender) {
  22248. ILaya.lateTimer.frameLoop(1, this, this.onPreRender);
  22249. }
  22250. }
  22251. _onDisable() {
  22252. this.owner.offAllCaller(this);
  22253. ILaya.stage.offAllCaller(this);
  22254. ILaya.startTimer.clearAll(this);
  22255. ILaya.updateTimer.clearAll(this);
  22256. ILaya.lateTimer.clearAll(this);
  22257. }
  22258. _isScript() {
  22259. return true;
  22260. }
  22261. _onDestroy() {
  22262. this.onDestroy();
  22263. }
  22264. onAwake() {
  22265. }
  22266. onEnable() {
  22267. }
  22268. onStart() {
  22269. }
  22270. onTriggerEnter(other, self, contact) {
  22271. }
  22272. onTriggerStay(other, self, contact) {
  22273. }
  22274. onTriggerExit(other, self, contact) {
  22275. }
  22276. onMouseDown(e) {
  22277. }
  22278. onMouseUp(e) {
  22279. }
  22280. onClick(e) {
  22281. }
  22282. onStageMouseDown(e) {
  22283. }
  22284. onStageMouseUp(e) {
  22285. }
  22286. onStageClick(e) {
  22287. }
  22288. onStageMouseMove(e) {
  22289. }
  22290. onDoubleClick(e) {
  22291. }
  22292. onRightClick(e) {
  22293. }
  22294. onMouseMove(e) {
  22295. }
  22296. onMouseOver(e) {
  22297. }
  22298. onMouseOut(e) {
  22299. }
  22300. onKeyDown(e) {
  22301. }
  22302. onKeyPress(e) {
  22303. }
  22304. onKeyUp(e) {
  22305. }
  22306. onUpdate() {
  22307. }
  22308. onLateUpdate() {
  22309. }
  22310. onPreRender() {
  22311. }
  22312. onPostRender() {
  22313. }
  22314. onDisable() {
  22315. }
  22316. onDestroy() {
  22317. }
  22318. }
  22319. class GraphicAnimation extends FrameAnimation {
  22320. constructor() {
  22321. super(...arguments);
  22322. this._nodeIDAniDic = {};
  22323. }
  22324. _parseNodeList(uiView) {
  22325. if (!this._nodeList)
  22326. this._nodeList = [];
  22327. this._nodeDefaultProps[uiView.compId] = uiView.props;
  22328. if (uiView.compId)
  22329. this._nodeList.push(uiView.compId);
  22330. var childs = uiView.child;
  22331. if (childs) {
  22332. var i, len = childs.length;
  22333. for (i = 0; i < len; i++) {
  22334. this._parseNodeList(childs[i]);
  22335. }
  22336. }
  22337. }
  22338. _calGraphicData(aniData) {
  22339. this._setUp(null, aniData);
  22340. this._createGraphicData();
  22341. if (this._nodeIDAniDic) {
  22342. var key;
  22343. for (key in this._nodeIDAniDic) {
  22344. this._nodeIDAniDic[key] = null;
  22345. }
  22346. }
  22347. }
  22348. _createGraphicData() {
  22349. var gList = [];
  22350. var i, len = this.count;
  22351. var animationDataNew = this._usedFrames;
  22352. if (!animationDataNew)
  22353. animationDataNew = [];
  22354. var preGraphic;
  22355. for (i = 0; i < len; i++) {
  22356. if (animationDataNew[i] || !preGraphic) {
  22357. preGraphic = this._createFrameGraphic(i);
  22358. }
  22359. gList.push(preGraphic);
  22360. }
  22361. this._gList = gList;
  22362. }
  22363. _createFrameGraphic(frame) {
  22364. var g = new Graphics();
  22365. if (!GraphicAnimation._rootMatrix)
  22366. GraphicAnimation._rootMatrix = new Matrix();
  22367. this._updateNodeGraphic(this._rootNode, frame, GraphicAnimation._rootMatrix, g);
  22368. return g;
  22369. }
  22370. _updateNodeGraphic(node, frame, parentTransfrom, g, alpha = 1) {
  22371. var tNodeG;
  22372. tNodeG = this._nodeGDic[node.compId] = this._getNodeGraphicData(node.compId, frame, this._nodeGDic[node.compId]);
  22373. if (!tNodeG.resultTransform)
  22374. tNodeG.resultTransform = new Matrix();
  22375. var tResultTransform;
  22376. tResultTransform = tNodeG.resultTransform;
  22377. Matrix.mul(tNodeG.transform, parentTransfrom, tResultTransform);
  22378. var tTex;
  22379. var tGraphicAlpha = tNodeG.alpha * alpha;
  22380. if (tGraphicAlpha < 0.01)
  22381. return;
  22382. if (tNodeG.skin) {
  22383. tTex = this._getTextureByUrl(tNodeG.skin);
  22384. if (tTex) {
  22385. if (tResultTransform._checkTransform()) {
  22386. g.drawTexture(tTex, 0, 0, tNodeG.width, tNodeG.height, tResultTransform, tGraphicAlpha);
  22387. tNodeG.resultTransform = null;
  22388. }
  22389. else {
  22390. g.drawTexture(tTex, tResultTransform.tx, tResultTransform.ty, tNodeG.width, tNodeG.height, null, tGraphicAlpha);
  22391. }
  22392. }
  22393. }
  22394. var childs = node.child;
  22395. if (!childs)
  22396. return;
  22397. var i, len;
  22398. len = childs.length;
  22399. for (i = 0; i < len; i++) {
  22400. this._updateNodeGraphic(childs[i], frame, tResultTransform, g, tGraphicAlpha);
  22401. }
  22402. }
  22403. _updateNoChilds(tNodeG, g) {
  22404. if (!tNodeG.skin)
  22405. return;
  22406. var tTex = this._getTextureByUrl(tNodeG.skin);
  22407. if (!tTex)
  22408. return;
  22409. var tTransform = tNodeG.transform;
  22410. tTransform._checkTransform();
  22411. var onlyTranslate;
  22412. onlyTranslate = !tTransform._bTransform;
  22413. if (!onlyTranslate) {
  22414. g.drawTexture(tTex, 0, 0, tNodeG.width, tNodeG.height, tTransform.clone(), tNodeG.alpha);
  22415. }
  22416. else {
  22417. g.drawTexture(tTex, tTransform.tx, tTransform.ty, tNodeG.width, tNodeG.height, null, tNodeG.alpha);
  22418. }
  22419. }
  22420. _updateNodeGraphic2(node, frame, g) {
  22421. var tNodeG;
  22422. tNodeG = this._nodeGDic[node.compId] = this._getNodeGraphicData(node.compId, frame, this._nodeGDic[node.compId]);
  22423. if (!node.child) {
  22424. this._updateNoChilds(tNodeG, g);
  22425. return;
  22426. }
  22427. var tTransform = tNodeG.transform;
  22428. tTransform._checkTransform();
  22429. var onlyTranslate;
  22430. onlyTranslate = !tTransform._bTransform;
  22431. var hasTrans;
  22432. hasTrans = onlyTranslate && (tTransform.tx != 0 || tTransform.ty != 0);
  22433. var ifSave;
  22434. ifSave = (tTransform._bTransform) || tNodeG.alpha != 1;
  22435. if (ifSave)
  22436. g.save();
  22437. if (tNodeG.alpha != 1)
  22438. g.alpha(tNodeG.alpha);
  22439. if (!onlyTranslate)
  22440. g.transform(tTransform.clone());
  22441. else if (hasTrans)
  22442. g.translate(tTransform.tx, tTransform.ty);
  22443. var childs = node.child;
  22444. var tTex;
  22445. if (tNodeG.skin) {
  22446. tTex = this._getTextureByUrl(tNodeG.skin);
  22447. if (tTex) {
  22448. g.drawImage(tTex, 0, 0, tNodeG.width, tNodeG.height);
  22449. }
  22450. }
  22451. if (childs) {
  22452. var i, len;
  22453. len = childs.length;
  22454. for (i = 0; i < len; i++) {
  22455. this._updateNodeGraphic2(childs[i], frame, g);
  22456. }
  22457. }
  22458. if (ifSave) {
  22459. g.restore();
  22460. }
  22461. else {
  22462. if (!onlyTranslate) {
  22463. g.transform(tTransform.clone().invert());
  22464. }
  22465. else if (hasTrans) {
  22466. g.translate(-tTransform.tx, -tTransform.ty);
  22467. }
  22468. }
  22469. }
  22470. _calculateKeyFrames(node) {
  22471. super._calculateKeyFrames(node);
  22472. this._nodeIDAniDic[node.target] = node;
  22473. }
  22474. getNodeDataByID(nodeID) {
  22475. return this._nodeIDAniDic[nodeID];
  22476. }
  22477. _getParams(obj, params, frame, obj2) {
  22478. var rst = GraphicAnimation._temParam;
  22479. rst.length = params.length;
  22480. var i, len = params.length;
  22481. for (i = 0; i < len; i++) {
  22482. rst[i] = this._getObjVar(obj, params[i][0], frame, params[i][1], obj2);
  22483. }
  22484. return rst;
  22485. }
  22486. _getObjVar(obj, key, frame, noValue, obj2) {
  22487. if (key in obj) {
  22488. var vArr = obj[key];
  22489. if (frame >= vArr.length)
  22490. frame = vArr.length - 1;
  22491. return obj[key][frame];
  22492. }
  22493. if (key in obj2) {
  22494. return obj2[key];
  22495. }
  22496. return noValue;
  22497. }
  22498. _getNodeGraphicData(nodeID, frame, rst) {
  22499. if (!rst)
  22500. rst = new GraphicNode();
  22501. if (!rst.transform) {
  22502. rst.transform = new Matrix();
  22503. }
  22504. else {
  22505. rst.transform.identity();
  22506. }
  22507. var node = this.getNodeDataByID(nodeID);
  22508. if (!node)
  22509. return rst;
  22510. var frameData = node.frames;
  22511. var params = this._getParams(frameData, GraphicAnimation._drawTextureCmd, frame, this._nodeDefaultProps[nodeID]);
  22512. var url = params[0];
  22513. var width, height;
  22514. var px = params[5], py = params[6];
  22515. var aX = params[13], aY = params[14];
  22516. var sx = params[7], sy = params[8];
  22517. var rotate = params[9];
  22518. var skewX = params[11], skewY = params[12];
  22519. width = params[3];
  22520. height = params[4];
  22521. if (width == 0 || height == 0)
  22522. url = null;
  22523. if (width == -1)
  22524. width = 0;
  22525. if (height == -1)
  22526. height = 0;
  22527. var tex;
  22528. rst.skin = url;
  22529. rst.width = width;
  22530. rst.height = height;
  22531. if (url) {
  22532. tex = this._getTextureByUrl(url);
  22533. if (tex) {
  22534. if (!width)
  22535. width = tex.sourceWidth;
  22536. if (!height)
  22537. height = tex.sourceHeight;
  22538. }
  22539. else {
  22540. console.warn("lost skin:", url, ",you may load pics first");
  22541. }
  22542. }
  22543. rst.alpha = params[10];
  22544. var m = rst.transform;
  22545. if (aX != 0) {
  22546. px = aX * width;
  22547. }
  22548. if (aY != 0) {
  22549. py = aY * height;
  22550. }
  22551. if (px != 0 || py != 0) {
  22552. m.translate(-px, -py);
  22553. }
  22554. var tm = null;
  22555. if (rotate || sx !== 1 || sy !== 1 || skewX || skewY) {
  22556. tm = GraphicAnimation._tempMt;
  22557. tm.identity();
  22558. tm._bTransform = true;
  22559. var skx = (rotate - skewX) * 0.0174532922222222;
  22560. var sky = (rotate + skewY) * 0.0174532922222222;
  22561. var cx = Math.cos(sky);
  22562. var ssx = Math.sin(sky);
  22563. var cy = Math.sin(skx);
  22564. var ssy = Math.cos(skx);
  22565. tm.a = sx * cx;
  22566. tm.b = sx * ssx;
  22567. tm.c = -sy * cy;
  22568. tm.d = sy * ssy;
  22569. tm.tx = tm.ty = 0;
  22570. }
  22571. if (tm) {
  22572. m = Matrix.mul(m, tm, m);
  22573. }
  22574. m.translate(params[1], params[2]);
  22575. return rst;
  22576. }
  22577. _getTextureByUrl(url) {
  22578. return Loader.getRes(url);
  22579. }
  22580. setAniData(uiView, aniName = null) {
  22581. if (uiView.animations) {
  22582. this._nodeDefaultProps = {};
  22583. this._nodeGDic = {};
  22584. if (this._nodeList)
  22585. this._nodeList.length = 0;
  22586. this._rootNode = uiView;
  22587. this._parseNodeList(uiView);
  22588. var aniDic = {};
  22589. var anilist = [];
  22590. var animations = uiView.animations;
  22591. var i, len = animations.length;
  22592. var tAniO;
  22593. for (i = 0; i < len; i++) {
  22594. tAniO = animations[i];
  22595. this._labels = null;
  22596. if (aniName && aniName != tAniO.name) {
  22597. continue;
  22598. }
  22599. if (!tAniO)
  22600. continue;
  22601. try {
  22602. this._calGraphicData(tAniO);
  22603. }
  22604. catch (e) {
  22605. console.warn("parse animation fail:" + tAniO.name + ",empty animation created");
  22606. this._gList = [];
  22607. }
  22608. var frameO = {};
  22609. frameO.interval = 1000 / tAniO["frameRate"];
  22610. frameO.frames = this._gList;
  22611. frameO.labels = this._labels;
  22612. frameO.name = tAniO.name;
  22613. anilist.push(frameO);
  22614. aniDic[tAniO.name] = frameO;
  22615. }
  22616. this.animationList = anilist;
  22617. this.animationDic = aniDic;
  22618. }
  22619. GraphicAnimation._temParam.length = 0;
  22620. }
  22621. parseByData(aniData) {
  22622. var rootNode, aniO;
  22623. rootNode = aniData.nodeRoot;
  22624. aniO = aniData.aniO;
  22625. delete aniData.nodeRoot;
  22626. delete aniData.aniO;
  22627. this._nodeDefaultProps = {};
  22628. this._nodeGDic = {};
  22629. if (this._nodeList)
  22630. this._nodeList.length = 0;
  22631. this._rootNode = rootNode;
  22632. this._parseNodeList(rootNode);
  22633. this._labels = null;
  22634. try {
  22635. this._calGraphicData(aniO);
  22636. }
  22637. catch (e) {
  22638. console.warn("parse animation fail:" + aniO.name + ",empty animation created");
  22639. this._gList = [];
  22640. }
  22641. var frameO = aniData;
  22642. frameO.interval = 1000 / aniO["frameRate"];
  22643. frameO.frames = this._gList;
  22644. frameO.labels = this._labels;
  22645. frameO.name = aniO.name;
  22646. return frameO;
  22647. }
  22648. setUpAniData(uiView) {
  22649. if (uiView.animations) {
  22650. var aniDic = {};
  22651. var anilist = [];
  22652. var animations = uiView.animations;
  22653. var i, len = animations.length;
  22654. var tAniO;
  22655. for (i = 0; i < len; i++) {
  22656. tAniO = animations[i];
  22657. if (!tAniO)
  22658. continue;
  22659. var frameO = {};
  22660. frameO.name = tAniO.name;
  22661. frameO.aniO = tAniO;
  22662. frameO.nodeRoot = uiView;
  22663. anilist.push(frameO);
  22664. aniDic[tAniO.name] = frameO;
  22665. }
  22666. this.animationList = anilist;
  22667. this.animationDic = aniDic;
  22668. }
  22669. }
  22670. _clear() {
  22671. this.animationList = null;
  22672. this.animationDic = null;
  22673. this._gList = null;
  22674. this._nodeGDic = null;
  22675. }
  22676. static parseAnimationByData(animationObject) {
  22677. if (!GraphicAnimation._I)
  22678. GraphicAnimation._I = new GraphicAnimation();
  22679. var rst;
  22680. rst = GraphicAnimation._I.parseByData(animationObject);
  22681. GraphicAnimation._I._clear();
  22682. return rst;
  22683. }
  22684. static parseAnimationData(aniData) {
  22685. if (!GraphicAnimation._I)
  22686. GraphicAnimation._I = new GraphicAnimation();
  22687. GraphicAnimation._I.setUpAniData(aniData);
  22688. var rst;
  22689. rst = {};
  22690. rst.animationList = GraphicAnimation._I.animationList;
  22691. rst.animationDic = GraphicAnimation._I.animationDic;
  22692. GraphicAnimation._I._clear();
  22693. return rst;
  22694. }
  22695. }
  22696. GraphicAnimation._drawTextureCmd = [["skin", null], ["x", 0], ["y", 0], ["width", -1], ["height", -1], ["pivotX", 0], ["pivotY", 0], ["scaleX", 1], ["scaleY", 1], ["rotation", 0], ["alpha", 1], ["skewX", 0], ["skewY", 0], ["anchorX", 0], ["anchorY", 0]];
  22697. GraphicAnimation._temParam = [];
  22698. GraphicAnimation._tempMt = new Matrix();
  22699. class GraphicNode {
  22700. constructor() {
  22701. this.alpha = 1;
  22702. }
  22703. }
  22704. class Animation extends AnimationBase {
  22705. constructor() {
  22706. super();
  22707. this._setControlNode(this);
  22708. }
  22709. destroy(destroyChild = true) {
  22710. this.stop();
  22711. super.destroy(destroyChild);
  22712. this._frames = null;
  22713. this._labels = null;
  22714. }
  22715. play(start = 0, loop = true, name = "") {
  22716. if (name)
  22717. this._setFramesFromCache(name, true);
  22718. super.play(start, loop, name);
  22719. }
  22720. _setFramesFromCache(name, showWarn = false) {
  22721. if (this._url)
  22722. name = this._url + "#" + name;
  22723. if (name && Animation.framesMap[name]) {
  22724. var tAniO = Animation.framesMap[name];
  22725. if (tAniO instanceof Array) {
  22726. this._frames = Animation.framesMap[name];
  22727. this._count = this._frames.length;
  22728. }
  22729. else {
  22730. if (tAniO.nodeRoot) {
  22731. Animation.framesMap[name] = GraphicAnimation.parseAnimationByData(tAniO);
  22732. tAniO = Animation.framesMap[name];
  22733. }
  22734. this._frames = tAniO.frames;
  22735. this._count = this._frames.length;
  22736. if (!this._frameRateChanged)
  22737. this._interval = tAniO.interval;
  22738. this._labels = this._copyLabels(tAniO.labels);
  22739. }
  22740. return true;
  22741. }
  22742. else {
  22743. if (showWarn)
  22744. console.log("ani not found:", name);
  22745. }
  22746. return false;
  22747. }
  22748. _copyLabels(labels) {
  22749. if (!labels)
  22750. return null;
  22751. var rst;
  22752. rst = {};
  22753. var key;
  22754. for (key in labels) {
  22755. rst[key] = Utils.copyArray([], labels[key]);
  22756. }
  22757. return rst;
  22758. }
  22759. _frameLoop() {
  22760. if (this._visible && this._style.alpha > 0.01 && this._frames) {
  22761. super._frameLoop();
  22762. }
  22763. }
  22764. _displayToIndex(value) {
  22765. if (this._frames)
  22766. this.graphics = this._frames[value];
  22767. }
  22768. get frames() {
  22769. return this._frames;
  22770. }
  22771. set frames(value) {
  22772. this._frames = value;
  22773. if (value) {
  22774. this._count = value.length;
  22775. if (this._actionName)
  22776. this._setFramesFromCache(this._actionName, true);
  22777. this.index = this._index;
  22778. }
  22779. }
  22780. set source(value) {
  22781. if (value.indexOf(".ani") > -1)
  22782. this.loadAnimation(value);
  22783. else if (value.indexOf(".json") > -1 || value.indexOf("als") > -1 || value.indexOf("atlas") > -1)
  22784. this.loadAtlas(value);
  22785. else
  22786. this.loadImages(value.split(","));
  22787. }
  22788. set autoAnimation(value) {
  22789. this.play(0, true, value);
  22790. }
  22791. set autoPlay(value) {
  22792. if (value)
  22793. this.play();
  22794. else
  22795. this.stop();
  22796. }
  22797. clear() {
  22798. super.clear();
  22799. this.stop();
  22800. this.graphics = null;
  22801. this._frames = null;
  22802. this._labels = null;
  22803. return this;
  22804. }
  22805. loadImages(urls, cacheName = "") {
  22806. this._url = "";
  22807. if (!this._setFramesFromCache(cacheName)) {
  22808. this.frames = Animation.framesMap[cacheName] ? Animation.framesMap[cacheName] : Animation.createFrames(urls, cacheName);
  22809. }
  22810. return this;
  22811. }
  22812. loadAtlas(url, loaded = null, cacheName = "") {
  22813. this._url = "";
  22814. var _this = this;
  22815. if (!_this._setFramesFromCache(cacheName)) {
  22816. function onLoaded(loadUrl) {
  22817. if (url === loadUrl) {
  22818. _this.frames = Animation.framesMap[cacheName] ? Animation.framesMap[cacheName] : Animation.createFrames(url, cacheName);
  22819. if (loaded)
  22820. loaded.run();
  22821. }
  22822. }
  22823. if (Loader.getAtlas(url))
  22824. onLoaded(url);
  22825. else
  22826. ILaya.loader.load(url, Handler.create(null, onLoaded, [url]), null, Loader.ATLAS);
  22827. }
  22828. return this;
  22829. }
  22830. loadAnimation(url, loaded = null, atlas = null) {
  22831. this._url = url;
  22832. var _this = this;
  22833. if (!this._actionName)
  22834. this._actionName = "";
  22835. if (!_this._setFramesFromCache(this._actionName)) {
  22836. if (!atlas || Loader.getAtlas(atlas)) {
  22837. this._loadAnimationData(url, loaded, atlas);
  22838. }
  22839. else {
  22840. ILaya.loader.load(atlas, Handler.create(this, this._loadAnimationData, [url, loaded, atlas]), null, Loader.ATLAS);
  22841. }
  22842. }
  22843. else {
  22844. _this._setFramesFromCache(this._actionName, true);
  22845. this.index = 0;
  22846. if (loaded)
  22847. loaded.run();
  22848. }
  22849. return this;
  22850. }
  22851. _loadAnimationData(url, loaded = null, atlas = null) {
  22852. if (atlas && !Loader.getAtlas(atlas)) {
  22853. console.warn("atlas load fail:" + atlas);
  22854. return;
  22855. }
  22856. var _this = this;
  22857. function onLoaded(loadUrl) {
  22858. if (!Loader.getRes(loadUrl)) {
  22859. if (Animation.framesMap[url + "#"]) {
  22860. _this._setFramesFromCache(_this._actionName, true);
  22861. _this.index = 0;
  22862. _this._resumePlay();
  22863. if (loaded)
  22864. loaded.run();
  22865. }
  22866. return;
  22867. }
  22868. if (url === loadUrl) {
  22869. var tAniO;
  22870. if (!Animation.framesMap[url + "#"]) {
  22871. var aniData = GraphicAnimation.parseAnimationData(Loader.getRes(url));
  22872. if (!aniData)
  22873. return;
  22874. var aniList = aniData.animationList;
  22875. var i, len = aniList.length;
  22876. var defaultO;
  22877. for (i = 0; i < len; i++) {
  22878. tAniO = aniList[i];
  22879. Animation.framesMap[url + "#" + tAniO.name] = tAniO;
  22880. if (!defaultO)
  22881. defaultO = tAniO;
  22882. }
  22883. if (defaultO) {
  22884. Animation.framesMap[url + "#"] = defaultO;
  22885. _this._setFramesFromCache(_this._actionName, true);
  22886. _this.index = 0;
  22887. }
  22888. _this._resumePlay();
  22889. }
  22890. else {
  22891. _this._setFramesFromCache(_this._actionName, true);
  22892. _this.index = 0;
  22893. _this._resumePlay();
  22894. }
  22895. if (loaded)
  22896. loaded.run();
  22897. }
  22898. Loader.clearRes(url);
  22899. }
  22900. if (Loader.getRes(url))
  22901. onLoaded(url);
  22902. else
  22903. ILaya.loader.load(url, Handler.create(null, onLoaded, [url]), null, Loader.JSON);
  22904. }
  22905. static createFrames(url, name) {
  22906. var arr;
  22907. if (typeof (url) == 'string') {
  22908. var atlas = Loader.getAtlas(url);
  22909. if (atlas && atlas.length) {
  22910. arr = [];
  22911. for (var i = 0, n = atlas.length; i < n; i++) {
  22912. var g = new Graphics();
  22913. g.drawImage(Loader.getRes(atlas[i]), 0, 0);
  22914. arr.push(g);
  22915. }
  22916. }
  22917. }
  22918. else if (url instanceof Array) {
  22919. arr = [];
  22920. for (i = 0, n = url.length; i < n; i++) {
  22921. g = new Graphics();
  22922. g.loadImage(url[i], 0, 0);
  22923. arr.push(g);
  22924. }
  22925. }
  22926. if (name)
  22927. Animation.framesMap[name] = arr;
  22928. return arr;
  22929. }
  22930. static clearCache(key) {
  22931. var cache = Animation.framesMap;
  22932. var val;
  22933. var key2 = key + "#";
  22934. for (val in cache) {
  22935. if (val === key || val.indexOf(key2) === 0) {
  22936. delete Animation.framesMap[val];
  22937. }
  22938. }
  22939. }
  22940. }
  22941. Animation.framesMap = {};
  22942. ILaya.regClass(Animation);
  22943. ClassUtils.regClass("laya.display.Animation", Animation);
  22944. ClassUtils.regClass("Laya.Animation", Animation);
  22945. class EffectAnimation extends FrameAnimation {
  22946. constructor() {
  22947. super(...arguments);
  22948. this._initData = {};
  22949. }
  22950. set target(v) {
  22951. if (this._target)
  22952. this._target.off(EffectAnimation.EFFECT_BEGIN, this, this._onOtherBegin);
  22953. this._target = v;
  22954. if (this._target)
  22955. this._target.on(EffectAnimation.EFFECT_BEGIN, this, this._onOtherBegin);
  22956. this._addEvent();
  22957. }
  22958. get target() {
  22959. return this._target;
  22960. }
  22961. _onOtherBegin(effect) {
  22962. if (effect === this)
  22963. return;
  22964. this.stop();
  22965. }
  22966. set playEvent(event) {
  22967. this._playEvent = event;
  22968. if (!event)
  22969. return;
  22970. this._addEvent();
  22971. }
  22972. _addEvent() {
  22973. if (!this._target || !this._playEvent)
  22974. return;
  22975. this._setControlNode(this._target);
  22976. this._target.on(this._playEvent, this, this._onPlayAction);
  22977. }
  22978. _onPlayAction() {
  22979. this.play(0, false);
  22980. }
  22981. play(start = 0, loop = true, name = "") {
  22982. if (!this._target)
  22983. return;
  22984. this._target.event(EffectAnimation.EFFECT_BEGIN, [this]);
  22985. this._recordInitData();
  22986. super.play(start, loop, name);
  22987. }
  22988. _recordInitData() {
  22989. if (!this._aniKeys)
  22990. return;
  22991. var i, len;
  22992. len = this._aniKeys.length;
  22993. var key;
  22994. for (i = 0; i < len; i++) {
  22995. key = this._aniKeys[i];
  22996. this._initData[key] = this._target[key];
  22997. }
  22998. }
  22999. set effectClass(classStr) {
  23000. this._effectClass = ClassUtils.getClass(classStr);
  23001. if (this._effectClass) {
  23002. var uiData = this._effectClass["uiView"];
  23003. if (uiData) {
  23004. var aniData = uiData["animations"];
  23005. if (aniData && aniData[0]) {
  23006. var data = aniData[0];
  23007. this._setUp({}, data);
  23008. if (data.nodes && data.nodes[0]) {
  23009. this._aniKeys = data.nodes[0].keys;
  23010. }
  23011. }
  23012. }
  23013. }
  23014. }
  23015. set effectData(uiData) {
  23016. if (uiData) {
  23017. var aniData = uiData["animations"];
  23018. if (aniData && aniData[0]) {
  23019. var data = aniData[0];
  23020. this._setUp({}, data);
  23021. if (data.nodes && data.nodes[0]) {
  23022. this._aniKeys = data.nodes[0].keys;
  23023. }
  23024. }
  23025. }
  23026. }
  23027. _displayToIndex(value) {
  23028. if (!this._animationData)
  23029. return;
  23030. if (value < 0)
  23031. value = 0;
  23032. if (value > this._count)
  23033. value = this._count;
  23034. var nodes = this._animationData.nodes, i, len = nodes.length;
  23035. len = len > 1 ? 1 : len;
  23036. for (i = 0; i < len; i++) {
  23037. this._displayNodeToFrame(nodes[i], value);
  23038. }
  23039. }
  23040. _displayNodeToFrame(node, frame, targetDic = null) {
  23041. if (!this._target)
  23042. return;
  23043. var target = this._target;
  23044. var frames = node.frames, key, propFrames, value;
  23045. var keys = node.keys, i, len = keys.length;
  23046. var secondFrames = node.secondFrames;
  23047. var tSecondFrame;
  23048. var easeFun;
  23049. var tKeyFrames;
  23050. var startFrame;
  23051. var endFrame;
  23052. for (i = 0; i < len; i++) {
  23053. key = keys[i];
  23054. propFrames = frames[key];
  23055. tSecondFrame = secondFrames[key];
  23056. if (tSecondFrame == -1) {
  23057. value = this._initData[key];
  23058. }
  23059. else {
  23060. if (frame < tSecondFrame) {
  23061. tKeyFrames = node.keyframes[key];
  23062. startFrame = tKeyFrames[0];
  23063. if (startFrame.tween) {
  23064. easeFun = Ease[startFrame.tweenMethod];
  23065. if (easeFun == null)
  23066. easeFun = Ease.linearNone;
  23067. endFrame = tKeyFrames[1];
  23068. value = easeFun(frame, this._initData[key], endFrame.value - this._initData[key], endFrame.index);
  23069. }
  23070. else {
  23071. value = this._initData[key];
  23072. }
  23073. }
  23074. else {
  23075. if (propFrames.length > frame)
  23076. value = propFrames[frame];
  23077. else
  23078. value = propFrames[propFrames.length - 1];
  23079. }
  23080. }
  23081. target[key] = value;
  23082. }
  23083. }
  23084. _calculateKeyFrames(node) {
  23085. super._calculateKeyFrames(node);
  23086. var keyFrames = node.keyframes, key, tKeyFrames, target = node.target;
  23087. var secondFrames = {};
  23088. node.secondFrames = secondFrames;
  23089. for (key in keyFrames) {
  23090. tKeyFrames = keyFrames[key];
  23091. if (tKeyFrames.length <= 1)
  23092. secondFrames[key] = -1;
  23093. else
  23094. secondFrames[key] = tKeyFrames[1].index;
  23095. }
  23096. }
  23097. }
  23098. EffectAnimation.EFFECT_BEGIN = "effectbegin";
  23099. ClassUtils.regClass("laya.display.EffectAnimation", EffectAnimation);
  23100. ClassUtils.regClass("Laya.EffectAnimation", EffectAnimation);
  23101. class SceneLoader extends EventDispatcher {
  23102. constructor() {
  23103. super();
  23104. this._completeHandler = new Handler(this, this.onOneLoadComplete);
  23105. this.reset();
  23106. }
  23107. reset() {
  23108. this._toLoadList = [];
  23109. this._isLoading = false;
  23110. this.totalCount = 0;
  23111. }
  23112. get leftCount() {
  23113. if (this._isLoading)
  23114. return this._toLoadList.length + 1;
  23115. return this._toLoadList.length;
  23116. }
  23117. get loadedCount() {
  23118. return this.totalCount - this.leftCount;
  23119. }
  23120. load(url, is3D = false, ifCheck = true) {
  23121. if (url instanceof Array) {
  23122. var i, len;
  23123. len = url.length;
  23124. for (i = 0; i < len; i++) {
  23125. this._addToLoadList(url[i], is3D);
  23126. }
  23127. }
  23128. else {
  23129. this._addToLoadList(url, is3D);
  23130. }
  23131. if (ifCheck)
  23132. this._checkNext();
  23133. }
  23134. _addToLoadList(url, is3D = false) {
  23135. if (this._toLoadList.indexOf(url) >= 0)
  23136. return;
  23137. if (Loader.getRes(url))
  23138. return;
  23139. if (is3D) {
  23140. this._toLoadList.push({ url: url });
  23141. }
  23142. else
  23143. this._toLoadList.push(url);
  23144. this.totalCount++;
  23145. }
  23146. _checkNext() {
  23147. if (!this._isLoading) {
  23148. if (this._toLoadList.length == 0) {
  23149. this.event(Event.COMPLETE);
  23150. return;
  23151. }
  23152. var tItem;
  23153. tItem = this._toLoadList.pop();
  23154. if (typeof (tItem) == 'string') {
  23155. this.loadOne(tItem);
  23156. }
  23157. else {
  23158. this.loadOne(tItem.url, true);
  23159. }
  23160. }
  23161. }
  23162. loadOne(url, is3D = false) {
  23163. this._curUrl = url;
  23164. var type = Utils.getFileExtension(this._curUrl);
  23165. if (is3D) {
  23166. ILaya.loader.create(url, this._completeHandler);
  23167. }
  23168. else if (SceneLoader.LoadableExtensions[type]) {
  23169. ILaya.loader.load(url, this._completeHandler, null, SceneLoader.LoadableExtensions[type]);
  23170. }
  23171. else if (url != AtlasInfoManager.getFileLoadPath(url) || SceneLoader.No3dLoadTypes[type] || !LoaderManager.createMap[type]) {
  23172. ILaya.loader.load(url, this._completeHandler);
  23173. }
  23174. else {
  23175. ILaya.loader.create(url, this._completeHandler);
  23176. }
  23177. }
  23178. onOneLoadComplete() {
  23179. this._isLoading = false;
  23180. if (!Loader.getRes(this._curUrl)) {
  23181. console.log("Fail to load:", this._curUrl);
  23182. }
  23183. var type = Utils.getFileExtension(this._curUrl);
  23184. if (SceneLoader.LoadableExtensions[type]) {
  23185. var dataO;
  23186. dataO = Loader.getRes(this._curUrl);
  23187. if (dataO && (dataO instanceof Prefab)) {
  23188. dataO = dataO.json;
  23189. }
  23190. if (dataO) {
  23191. if (dataO.loadList) {
  23192. this.load(dataO.loadList, false, false);
  23193. }
  23194. if (dataO.loadList3D) {
  23195. this.load(dataO.loadList3D, true, false);
  23196. }
  23197. }
  23198. }
  23199. if (type == "sk") {
  23200. this.load(this._curUrl.replace(".sk", ".png"), false, false);
  23201. }
  23202. this.event(Event.PROGRESS, this.getProgress());
  23203. this._checkNext();
  23204. }
  23205. getProgress() {
  23206. return this.loadedCount / this.totalCount;
  23207. }
  23208. }
  23209. SceneLoader.LoadableExtensions = { "scene": Loader.JSON, "scene3d": Loader.JSON, "ani": Loader.JSON, "ui": Loader.JSON, "prefab": Loader.PREFAB };
  23210. SceneLoader.No3dLoadTypes = { "png": true, "jpg": true, "txt": true };
  23211. class Scene extends Sprite {
  23212. constructor(createChildren = true) {
  23213. super();
  23214. this.autoDestroyAtClosed = false;
  23215. this.url = null;
  23216. this._viewCreated = false;
  23217. this._$componentType = "Scene";
  23218. this._setBit(Const.NOT_READY, true);
  23219. Scene.unDestroyedScenes.push(this);
  23220. this._scene = this;
  23221. if (createChildren)
  23222. this.createChildren();
  23223. }
  23224. createChildren() {
  23225. }
  23226. static setUIMap(url) {
  23227. let uimap = ILaya.loader.getRes(url);
  23228. if (uimap) {
  23229. for (let key in uimap) {
  23230. ILaya.Loader.loadedMap[URL.formatURL(key + ".scene")] = uimap[key];
  23231. }
  23232. }
  23233. else {
  23234. throw "请提前加载uimap的json,再使用该接口设置!";
  23235. }
  23236. }
  23237. loadScene(path) {
  23238. var url = path.indexOf(".") > -1 ? path : path + ".scene";
  23239. var view = ILaya.loader.getRes(url);
  23240. if (view) {
  23241. this.createView(view);
  23242. }
  23243. else {
  23244. ILaya.loader.resetProgress();
  23245. var loader = new SceneLoader();
  23246. loader.on(Event.COMPLETE, this, this._onSceneLoaded, [url]);
  23247. loader.load(url);
  23248. }
  23249. }
  23250. _onSceneLoaded(url) {
  23251. this.createView(ILaya.Loader.getRes(url));
  23252. }
  23253. createView(view) {
  23254. if (view && !this._viewCreated) {
  23255. this._viewCreated = true;
  23256. SceneUtils.createByData(this, view);
  23257. }
  23258. }
  23259. getNodeByID(id) {
  23260. if (this._idMap)
  23261. return this._idMap[id];
  23262. return null;
  23263. }
  23264. open(closeOther = true, param = null) {
  23265. if (closeOther)
  23266. Scene.closeAll();
  23267. Scene.root.addChild(this);
  23268. this.onOpened(param);
  23269. }
  23270. onOpened(param) {
  23271. }
  23272. close(type = null) {
  23273. this.onClosed(type);
  23274. if (this.autoDestroyAtClosed)
  23275. this.destroy();
  23276. else
  23277. this.removeSelf();
  23278. }
  23279. onClosed(type = null) {
  23280. }
  23281. destroy(destroyChild = true) {
  23282. this._idMap = null;
  23283. super.destroy(destroyChild);
  23284. var list = Scene.unDestroyedScenes;
  23285. for (var i = list.length - 1; i > -1; i--) {
  23286. if (list[i] === this) {
  23287. list.splice(i, 1);
  23288. return;
  23289. }
  23290. }
  23291. }
  23292. set scaleX(value) {
  23293. if (super.get_scaleX() == value)
  23294. return;
  23295. super.set_scaleX(value);
  23296. this.event(Event.RESIZE);
  23297. }
  23298. get scaleX() {
  23299. return super.scaleX;
  23300. }
  23301. set scaleY(value) {
  23302. if (super.get_scaleY() == value)
  23303. return;
  23304. super.set_scaleY(value);
  23305. this.event(Event.RESIZE);
  23306. }
  23307. get scaleY() {
  23308. return super.scaleY;
  23309. }
  23310. get width() {
  23311. if (this._width)
  23312. return this._width;
  23313. var max = 0;
  23314. for (var i = this.numChildren - 1; i > -1; i--) {
  23315. var comp = this.getChildAt(i);
  23316. if (comp._visible) {
  23317. max = Math.max(comp._x + comp.width * comp.scaleX, max);
  23318. }
  23319. }
  23320. return max;
  23321. }
  23322. set width(value) {
  23323. if (super.get_width() == value)
  23324. return;
  23325. super.set_width(value);
  23326. this.callLater(this._sizeChanged);
  23327. }
  23328. get height() {
  23329. if (this._height)
  23330. return this._height;
  23331. var max = 0;
  23332. for (var i = this.numChildren - 1; i > -1; i--) {
  23333. var comp = this.getChildAt(i);
  23334. if (comp._visible) {
  23335. max = Math.max(comp._y + comp.height * comp.scaleY, max);
  23336. }
  23337. }
  23338. return max;
  23339. }
  23340. set height(value) {
  23341. if (super.get_height() == value)
  23342. return;
  23343. super.set_height(value);
  23344. this.callLater(this._sizeChanged);
  23345. }
  23346. _sizeChanged() {
  23347. this.event(Event.RESIZE);
  23348. }
  23349. static get root() {
  23350. if (!Scene._root) {
  23351. Scene._root = ILaya.stage.addChild(new Sprite());
  23352. Scene._root.name = "root";
  23353. ILaya.stage.on("resize", null, () => {
  23354. Scene._root.size(ILaya.stage.width, ILaya.stage.height);
  23355. Scene._root.event(Event.RESIZE);
  23356. });
  23357. Scene._root.size(ILaya.stage.width, ILaya.stage.height);
  23358. Scene._root.event(Event.RESIZE);
  23359. }
  23360. return Scene._root;
  23361. }
  23362. get timer() {
  23363. return this._timer || ILaya.timer;
  23364. }
  23365. set timer(value) {
  23366. this._timer = value;
  23367. }
  23368. static load(url, complete = null, progress = null) {
  23369. ILaya.loader.resetProgress();
  23370. var loader = new SceneLoader();
  23371. loader.on(Event.PROGRESS, null, onProgress);
  23372. loader.once(Event.COMPLETE, null, create);
  23373. loader.load(url);
  23374. function onProgress(value) {
  23375. if (Scene._loadPage)
  23376. Scene._loadPage.event("progress", value);
  23377. progress && progress.runWith(value);
  23378. }
  23379. function create() {
  23380. loader.off(Event.PROGRESS, null, onProgress);
  23381. var obj = ILaya.Loader.getRes(url);
  23382. if (!obj)
  23383. throw "Can not find scene:" + url;
  23384. if (!obj.props)
  23385. throw "Scene data is error:" + url;
  23386. var runtime = obj.props.runtime ? obj.props.runtime : obj.type;
  23387. var clas = ILaya.ClassUtils.getClass(runtime);
  23388. if (obj.props.renderType == "instance") {
  23389. var scene = clas.instance || (clas.instance = new clas());
  23390. }
  23391. else {
  23392. scene = new clas();
  23393. }
  23394. if (scene && scene instanceof Node) {
  23395. scene.url = url;
  23396. if (!scene._getBit(Const.NOT_READY)) {
  23397. complete && complete.runWith(scene);
  23398. }
  23399. else {
  23400. scene.on("onViewCreated", null, function () {
  23401. complete && complete.runWith(scene);
  23402. });
  23403. scene.createView(obj);
  23404. }
  23405. Scene.hideLoadingPage();
  23406. }
  23407. else {
  23408. throw "Can not find scene:" + runtime;
  23409. }
  23410. }
  23411. }
  23412. static open(url, closeOther = true, param = null, complete = null, progress = null) {
  23413. if (param instanceof Handler) {
  23414. var temp = complete;
  23415. complete = param;
  23416. param = temp;
  23417. }
  23418. Scene.showLoadingPage();
  23419. Scene.load(url, Handler.create(null, this._onSceneLoaded, [closeOther, complete, param]), progress);
  23420. }
  23421. static _onSceneLoaded(closeOther, complete, param, scene) {
  23422. scene.open(closeOther, param);
  23423. if (complete)
  23424. complete.runWith(scene);
  23425. }
  23426. static close(url, name = "") {
  23427. var flag = false;
  23428. var list = Scene.unDestroyedScenes;
  23429. for (var i = 0, n = list.length; i < n; i++) {
  23430. var scene = list[i];
  23431. if (scene && scene.parent && scene.url === url && scene.name == name) {
  23432. scene.close();
  23433. flag = true;
  23434. }
  23435. }
  23436. return flag;
  23437. }
  23438. static closeAll() {
  23439. var root = Scene.root;
  23440. for (var i = 0, n = root.numChildren; i < n; i++) {
  23441. var scene = root.getChildAt(0);
  23442. if (scene instanceof Scene)
  23443. scene.close();
  23444. else
  23445. scene.removeSelf();
  23446. }
  23447. }
  23448. static destroy(url, name = "") {
  23449. var flag = false;
  23450. var list = Scene.unDestroyedScenes;
  23451. for (var i = 0, n = list.length; i < n; i++) {
  23452. var scene = list[i];
  23453. if (scene.url === url && scene.name == name) {
  23454. scene.destroy();
  23455. flag = true;
  23456. }
  23457. }
  23458. return flag;
  23459. }
  23460. static gc() {
  23461. Resource.destroyUnusedResources();
  23462. }
  23463. static setLoadingPage(loadPage) {
  23464. if (Scene._loadPage != loadPage) {
  23465. Scene._loadPage = loadPage;
  23466. }
  23467. }
  23468. static showLoadingPage(param = null, delay = 500) {
  23469. if (Scene._loadPage) {
  23470. ILaya.systemTimer.clear(null, Scene._showLoading);
  23471. ILaya.systemTimer.clear(null, Scene._hideLoading);
  23472. ILaya.systemTimer.once(delay, null, Scene._showLoading, [param], false);
  23473. }
  23474. }
  23475. static _showLoading(param) {
  23476. ILaya.stage.addChild(Scene._loadPage);
  23477. Scene._loadPage.onOpened(param);
  23478. }
  23479. static _hideLoading() {
  23480. Scene._loadPage.close();
  23481. }
  23482. static hideLoadingPage(delay = 500) {
  23483. if (Scene._loadPage) {
  23484. ILaya.systemTimer.clear(null, Scene._showLoading);
  23485. ILaya.systemTimer.clear(null, Scene._hideLoading);
  23486. ILaya.systemTimer.once(delay, null, Scene._hideLoading);
  23487. }
  23488. }
  23489. }
  23490. Scene.unDestroyedScenes = [];
  23491. ILaya.regClass(Scene);
  23492. ClassUtils.regClass("laya.display.Scene", Scene);
  23493. ClassUtils.regClass("Laya.Scene", Scene);
  23494. class DrawParticleCmd {
  23495. static create(_temp) {
  23496. var cmd = Pool.getItemByClass("DrawParticleCmd", DrawParticleCmd);
  23497. cmd._templ = _temp;
  23498. return cmd;
  23499. }
  23500. recover() {
  23501. this._templ = null;
  23502. Pool.recover("DrawParticleCmd", this);
  23503. }
  23504. run(context, gx, gy) {
  23505. context.drawParticle(gx, gy, this._templ);
  23506. }
  23507. get cmdID() {
  23508. return DrawParticleCmd.ID;
  23509. }
  23510. }
  23511. DrawParticleCmd.ID = "DrawParticleCmd";
  23512. class FilterSetterBase {
  23513. constructor() {
  23514. }
  23515. paramChanged() {
  23516. Laya.systemTimer.callLater(this, this.buildFilter);
  23517. }
  23518. buildFilter() {
  23519. if (this._target) {
  23520. this.addFilter(this._target);
  23521. }
  23522. }
  23523. addFilter(sprite) {
  23524. if (!sprite)
  23525. return;
  23526. if (!sprite.filters) {
  23527. sprite.filters = [this._filter];
  23528. }
  23529. else {
  23530. var preFilters;
  23531. preFilters = sprite.filters;
  23532. if (preFilters.indexOf(this._filter) < 0) {
  23533. preFilters.push(this._filter);
  23534. sprite.filters = Utils.copyArray([], preFilters);
  23535. }
  23536. }
  23537. }
  23538. removeFilter(sprite) {
  23539. if (!sprite)
  23540. return;
  23541. sprite.filters = null;
  23542. }
  23543. set target(value) {
  23544. if (this._target != value) {
  23545. this._target = value;
  23546. this.paramChanged();
  23547. }
  23548. }
  23549. }
  23550. class BlurFilterGLRender {
  23551. render(rt, ctx, width, height, filter) {
  23552. var shaderValue = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  23553. this.setShaderInfo(shaderValue, filter, rt.width, rt.height);
  23554. ctx.drawTarget(rt, 0, 0, width, height, Matrix.EMPTY.identity(), shaderValue);
  23555. }
  23556. setShaderInfo(shader, filter, w, h) {
  23557. shader.defines.add(Filter.BLUR);
  23558. var sv = shader;
  23559. BlurFilterGLRender.blurinfo[0] = w;
  23560. BlurFilterGLRender.blurinfo[1] = h;
  23561. sv.blurInfo = BlurFilterGLRender.blurinfo;
  23562. var sigma = filter.strength / 3.0;
  23563. var sigma2 = sigma * sigma;
  23564. filter.strength_sig2_2sig2_gauss1[0] = filter.strength;
  23565. filter.strength_sig2_2sig2_gauss1[1] = sigma2;
  23566. filter.strength_sig2_2sig2_gauss1[2] = 2.0 * sigma2;
  23567. filter.strength_sig2_2sig2_gauss1[3] = 1.0 / (2.0 * Math.PI * sigma2);
  23568. sv.strength_sig2_2sig2_gauss1 = filter.strength_sig2_2sig2_gauss1;
  23569. }
  23570. }
  23571. BlurFilterGLRender.blurinfo = new Array(2);
  23572. class BlurFilter extends Filter {
  23573. constructor(strength = 4) {
  23574. super();
  23575. this.strength_sig2_2sig2_gauss1 = [];
  23576. this.strength = strength;
  23577. this._glRender = new BlurFilterGLRender();
  23578. }
  23579. get type() {
  23580. return Filter.BLUR;
  23581. }
  23582. getStrenth_sig2_2sig2_native() {
  23583. if (!this.strength_sig2_native) {
  23584. this.strength_sig2_native = new Float32Array(4);
  23585. }
  23586. var sigma = this.strength / 3.0;
  23587. var sigma2 = sigma * sigma;
  23588. this.strength_sig2_native[0] = this.strength;
  23589. this.strength_sig2_native[1] = sigma2;
  23590. this.strength_sig2_native[2] = 2.0 * sigma2;
  23591. this.strength_sig2_native[3] = 1.0 / (2.0 * Math.PI * sigma2);
  23592. return this.strength_sig2_native;
  23593. }
  23594. }
  23595. class BlurFilterSetter extends FilterSetterBase {
  23596. constructor() {
  23597. super();
  23598. this._strength = 4;
  23599. this._filter = new BlurFilter(this.strength);
  23600. }
  23601. buildFilter() {
  23602. this._filter = new BlurFilter(this.strength);
  23603. super.buildFilter();
  23604. }
  23605. get strength() {
  23606. return this._strength;
  23607. }
  23608. set strength(value) {
  23609. this._strength = value;
  23610. }
  23611. }
  23612. class ButtonEffect {
  23613. constructor() {
  23614. this._curState = 0;
  23615. this.effectScale = 1.5;
  23616. this.tweenTime = 300;
  23617. }
  23618. set target(tar) {
  23619. this._tar = tar;
  23620. tar.on(Event.MOUSE_DOWN, this, this.toChangedState);
  23621. tar.on(Event.MOUSE_UP, this, this.toInitState);
  23622. tar.on(Event.MOUSE_OUT, this, this.toInitState);
  23623. }
  23624. toChangedState() {
  23625. this._curState = 1;
  23626. if (this._curTween)
  23627. Tween.clear(this._curTween);
  23628. this._curTween = Tween.to(this._tar, { scaleX: this.effectScale, scaleY: this.effectScale }, this.tweenTime, Ease[this.effectEase], Handler.create(this, this.tweenComplete));
  23629. }
  23630. toInitState() {
  23631. if (this._curState == 2)
  23632. return;
  23633. if (this._curTween)
  23634. Tween.clear(this._curTween);
  23635. this._curState = 2;
  23636. this._curTween = Tween.to(this._tar, { scaleX: 1, scaleY: 1 }, this.tweenTime, Ease[this.backEase], Handler.create(this, this.tweenComplete));
  23637. }
  23638. tweenComplete() {
  23639. this._curState = 0;
  23640. this._curTween = null;
  23641. }
  23642. }
  23643. class ColorFilterSetter extends FilterSetterBase {
  23644. constructor() {
  23645. super();
  23646. this._brightness = 0;
  23647. this._contrast = 0;
  23648. this._saturation = 0;
  23649. this._hue = 0;
  23650. this._red = 0;
  23651. this._green = 0;
  23652. this._blue = 0;
  23653. this._alpha = 0;
  23654. this._filter = new ColorFilter();
  23655. }
  23656. buildFilter() {
  23657. this._filter.reset();
  23658. this._filter.color(this.red, this.green, this.blue, this.alpha);
  23659. this._filter.adjustHue(this.hue);
  23660. this._filter.adjustContrast(this.contrast);
  23661. this._filter.adjustBrightness(this.brightness);
  23662. this._filter.adjustSaturation(this.saturation);
  23663. super.buildFilter();
  23664. }
  23665. get brightness() {
  23666. return this._brightness;
  23667. }
  23668. set brightness(value) {
  23669. this._brightness = value;
  23670. this.paramChanged();
  23671. }
  23672. get contrast() {
  23673. return this._contrast;
  23674. }
  23675. set contrast(value) {
  23676. this._contrast = value;
  23677. this.paramChanged();
  23678. }
  23679. get saturation() {
  23680. return this._saturation;
  23681. }
  23682. set saturation(value) {
  23683. this._saturation = value;
  23684. this.paramChanged();
  23685. }
  23686. get hue() {
  23687. return this._hue;
  23688. }
  23689. set hue(value) {
  23690. this._hue = value;
  23691. this.paramChanged();
  23692. }
  23693. get red() {
  23694. return this._red;
  23695. }
  23696. set red(value) {
  23697. this._red = value;
  23698. this.paramChanged();
  23699. }
  23700. get green() {
  23701. return this._green;
  23702. }
  23703. set green(value) {
  23704. this._green = value;
  23705. this.paramChanged();
  23706. }
  23707. get blue() {
  23708. return this._blue;
  23709. }
  23710. set blue(value) {
  23711. this._blue = value;
  23712. this.paramChanged();
  23713. }
  23714. get color() {
  23715. return this._color;
  23716. }
  23717. set color(value) {
  23718. this._color = value;
  23719. var colorO;
  23720. colorO = ColorUtils.create(value);
  23721. this._red = colorO.arrColor[0] * 255;
  23722. this._green = colorO.arrColor[1] * 255;
  23723. this._blue = colorO.arrColor[2] * 255;
  23724. this.paramChanged();
  23725. }
  23726. get alpha() {
  23727. return this._alpha;
  23728. }
  23729. set alpha(value) {
  23730. this._alpha = value;
  23731. this.paramChanged();
  23732. }
  23733. }
  23734. class EffectBase extends Component {
  23735. constructor() {
  23736. super(...arguments);
  23737. this.duration = 1000;
  23738. this.delay = 0;
  23739. this.repeat = 0;
  23740. this.autoDestroyAtComplete = true;
  23741. }
  23742. _onAwake() {
  23743. this.target = this.target || this.owner;
  23744. if (this.autoDestroyAtComplete)
  23745. this._comlete = Handler.create(this.target, this.target.destroy, null, false);
  23746. if (this.eventName)
  23747. this.owner.on(this.eventName, this, this._exeTween);
  23748. else
  23749. this._exeTween();
  23750. }
  23751. _exeTween() {
  23752. this._tween = this._doTween();
  23753. this._tween.repeat = this.repeat;
  23754. }
  23755. _doTween() {
  23756. return null;
  23757. }
  23758. onReset() {
  23759. this.duration = 1000;
  23760. this.delay = 0;
  23761. this.repeat = 0;
  23762. this.ease = null;
  23763. this.target = null;
  23764. if (this.eventName) {
  23765. this.owner.off(this.eventName, this, this._exeTween);
  23766. this.eventName = null;
  23767. }
  23768. if (this._comlete) {
  23769. this._comlete.recover();
  23770. this._comlete = null;
  23771. }
  23772. if (this._tween) {
  23773. this._tween.clear();
  23774. this._tween = null;
  23775. }
  23776. }
  23777. }
  23778. class FadeIn extends EffectBase {
  23779. _doTween() {
  23780. this.target.alpha = 0;
  23781. return Tween.to(this.target, { alpha: 1 }, this.duration, Ease[this.ease], this._comlete, this.delay);
  23782. }
  23783. }
  23784. class FadeOut extends EffectBase {
  23785. _doTween() {
  23786. this.target.alpha = 1;
  23787. return Tween.to(this.target, { alpha: 0 }, this.duration, Ease[this.ease], this._comlete, this.delay);
  23788. }
  23789. }
  23790. class GlowFilterGLRender {
  23791. setShaderInfo(shader, w, h, data) {
  23792. shader.defines.add(data.type);
  23793. var sv = shader;
  23794. sv.u_blurInfo1 = data._sv_blurInfo1;
  23795. var info2 = data._sv_blurInfo2;
  23796. info2[0] = w;
  23797. info2[1] = h;
  23798. sv.u_blurInfo2 = info2;
  23799. sv.u_color = data.getColor();
  23800. }
  23801. render(rt, ctx, width, height, filter) {
  23802. var w = width, h = height;
  23803. var svBlur = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  23804. this.setShaderInfo(svBlur, w, h, filter);
  23805. var svCP = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  23806. var matI = Matrix.TEMP.identity();
  23807. ctx.drawTarget(rt, 0, 0, w, h, matI, svBlur);
  23808. ctx.drawTarget(rt, 0, 0, w, h, matI, svCP);
  23809. }
  23810. }
  23811. class GlowFilter extends Filter {
  23812. constructor(color, blur = 4, offX = 6, offY = 6) {
  23813. super();
  23814. this._elements = new Float32Array(9);
  23815. this._sv_blurInfo1 = new Array(4);
  23816. this._sv_blurInfo2 = [0, 0, 1, 0];
  23817. this._color = new ColorUtils(color);
  23818. this.blur = Math.min(blur, 20);
  23819. this.offX = offX;
  23820. this.offY = offY;
  23821. this._sv_blurInfo1[0] = this._sv_blurInfo1[1] = this.blur;
  23822. this._sv_blurInfo1[2] = offX;
  23823. this._sv_blurInfo1[3] = -offY;
  23824. this._glRender = new GlowFilterGLRender();
  23825. }
  23826. get type() {
  23827. return BlurFilter.GLOW;
  23828. }
  23829. get offY() {
  23830. return this._elements[6];
  23831. }
  23832. set offY(value) {
  23833. this._elements[6] = value;
  23834. this._sv_blurInfo1[3] = -value;
  23835. }
  23836. get offX() {
  23837. return this._elements[5];
  23838. }
  23839. set offX(value) {
  23840. this._elements[5] = value;
  23841. this._sv_blurInfo1[2] = value;
  23842. }
  23843. getColor() {
  23844. return this._color.arrColor;
  23845. }
  23846. get blur() {
  23847. return this._elements[4];
  23848. }
  23849. set blur(value) {
  23850. this._elements[4] = value;
  23851. this._sv_blurInfo1[0] = this._sv_blurInfo1[1] = value;
  23852. }
  23853. getColorNative() {
  23854. if (!this._color_native) {
  23855. this._color_native = new Float32Array(4);
  23856. }
  23857. var color = this.getColor();
  23858. this._color_native[0] = color[0];
  23859. this._color_native[1] = color[1];
  23860. this._color_native[2] = color[2];
  23861. this._color_native[3] = color[3];
  23862. return this._color_native;
  23863. }
  23864. getBlurInfo1Native() {
  23865. if (!this._blurInof1_native) {
  23866. this._blurInof1_native = new Float32Array(4);
  23867. }
  23868. this._blurInof1_native[0] = this._blurInof1_native[1] = this.blur;
  23869. this._blurInof1_native[2] = this.offX;
  23870. this._blurInof1_native[3] = this.offY;
  23871. return this._blurInof1_native;
  23872. }
  23873. getBlurInfo2Native() {
  23874. if (!this._blurInof2_native) {
  23875. this._blurInof2_native = new Float32Array(4);
  23876. }
  23877. this._blurInof2_native[2] = 1;
  23878. return this._blurInof2_native;
  23879. }
  23880. }
  23881. class GlowFilterSetter extends FilterSetterBase {
  23882. constructor() {
  23883. super();
  23884. this._color = "#ff0000";
  23885. this._blur = 4;
  23886. this._offX = 6;
  23887. this._offY = 6;
  23888. this._filter = new GlowFilter(this._color);
  23889. }
  23890. buildFilter() {
  23891. this._filter = new GlowFilter(this.color, this.blur, this.offX, this.offY);
  23892. super.buildFilter();
  23893. }
  23894. get color() {
  23895. return this._color;
  23896. }
  23897. set color(value) {
  23898. this._color = value;
  23899. this.paramChanged();
  23900. }
  23901. get blur() {
  23902. return this._blur;
  23903. }
  23904. set blur(value) {
  23905. this._blur = value;
  23906. this.paramChanged();
  23907. }
  23908. get offX() {
  23909. return this._offX;
  23910. }
  23911. set offX(value) {
  23912. this._offX = value;
  23913. this.paramChanged();
  23914. }
  23915. get offY() {
  23916. return this._offY;
  23917. }
  23918. set offY(value) {
  23919. this._offY = value;
  23920. this.paramChanged();
  23921. }
  23922. }
  23923. class KeyLocation {
  23924. }
  23925. KeyLocation.STANDARD = 0;
  23926. KeyLocation.LEFT = 1;
  23927. KeyLocation.RIGHT = 2;
  23928. KeyLocation.NUM_PAD = 3;
  23929. class Keyboard {
  23930. }
  23931. Keyboard.NUMBER_0 = 48;
  23932. Keyboard.NUMBER_1 = 49;
  23933. Keyboard.NUMBER_2 = 50;
  23934. Keyboard.NUMBER_3 = 51;
  23935. Keyboard.NUMBER_4 = 52;
  23936. Keyboard.NUMBER_5 = 53;
  23937. Keyboard.NUMBER_6 = 54;
  23938. Keyboard.NUMBER_7 = 55;
  23939. Keyboard.NUMBER_8 = 56;
  23940. Keyboard.NUMBER_9 = 57;
  23941. Keyboard.A = 65;
  23942. Keyboard.B = 66;
  23943. Keyboard.C = 67;
  23944. Keyboard.D = 68;
  23945. Keyboard.E = 69;
  23946. Keyboard.F = 70;
  23947. Keyboard.G = 71;
  23948. Keyboard.H = 72;
  23949. Keyboard.I = 73;
  23950. Keyboard.J = 74;
  23951. Keyboard.K = 75;
  23952. Keyboard.L = 76;
  23953. Keyboard.M = 77;
  23954. Keyboard.N = 78;
  23955. Keyboard.O = 79;
  23956. Keyboard.P = 80;
  23957. Keyboard.Q = 81;
  23958. Keyboard.R = 82;
  23959. Keyboard.S = 83;
  23960. Keyboard.T = 84;
  23961. Keyboard.U = 85;
  23962. Keyboard.V = 86;
  23963. Keyboard.W = 87;
  23964. Keyboard.X = 88;
  23965. Keyboard.Y = 89;
  23966. Keyboard.Z = 90;
  23967. Keyboard.F1 = 112;
  23968. Keyboard.F2 = 113;
  23969. Keyboard.F3 = 114;
  23970. Keyboard.F4 = 115;
  23971. Keyboard.F5 = 116;
  23972. Keyboard.F6 = 117;
  23973. Keyboard.F7 = 118;
  23974. Keyboard.F8 = 119;
  23975. Keyboard.F9 = 120;
  23976. Keyboard.F10 = 121;
  23977. Keyboard.F11 = 122;
  23978. Keyboard.F12 = 123;
  23979. Keyboard.F13 = 124;
  23980. Keyboard.F14 = 125;
  23981. Keyboard.F15 = 126;
  23982. Keyboard.NUMPAD = 21;
  23983. Keyboard.NUMPAD_0 = 96;
  23984. Keyboard.NUMPAD_1 = 97;
  23985. Keyboard.NUMPAD_2 = 98;
  23986. Keyboard.NUMPAD_3 = 99;
  23987. Keyboard.NUMPAD_4 = 100;
  23988. Keyboard.NUMPAD_5 = 101;
  23989. Keyboard.NUMPAD_6 = 102;
  23990. Keyboard.NUMPAD_7 = 103;
  23991. Keyboard.NUMPAD_8 = 104;
  23992. Keyboard.NUMPAD_9 = 105;
  23993. Keyboard.NUMPAD_ADD = 107;
  23994. Keyboard.NUMPAD_DECIMAL = 110;
  23995. Keyboard.NUMPAD_DIVIDE = 111;
  23996. Keyboard.NUMPAD_ENTER = 108;
  23997. Keyboard.NUMPAD_MULTIPLY = 106;
  23998. Keyboard.NUMPAD_SUBTRACT = 109;
  23999. Keyboard.SEMICOLON = 186;
  24000. Keyboard.EQUAL = 187;
  24001. Keyboard.COMMA = 188;
  24002. Keyboard.MINUS = 189;
  24003. Keyboard.PERIOD = 190;
  24004. Keyboard.SLASH = 191;
  24005. Keyboard.BACKQUOTE = 192;
  24006. Keyboard.LEFTBRACKET = 219;
  24007. Keyboard.BACKSLASH = 220;
  24008. Keyboard.RIGHTBRACKET = 221;
  24009. Keyboard.QUOTE = 222;
  24010. Keyboard.ALTERNATE = 18;
  24011. Keyboard.BACKSPACE = 8;
  24012. Keyboard.CAPS_LOCK = 20;
  24013. Keyboard.COMMAND = 15;
  24014. Keyboard.CONTROL = 17;
  24015. Keyboard.DELETE = 46;
  24016. Keyboard.ENTER = 13;
  24017. Keyboard.ESCAPE = 27;
  24018. Keyboard.PAGE_UP = 33;
  24019. Keyboard.PAGE_DOWN = 34;
  24020. Keyboard.END = 35;
  24021. Keyboard.HOME = 36;
  24022. Keyboard.LEFT = 37;
  24023. Keyboard.UP = 38;
  24024. Keyboard.RIGHT = 39;
  24025. Keyboard.DOWN = 40;
  24026. Keyboard.SHIFT = 16;
  24027. Keyboard.SPACE = 32;
  24028. Keyboard.TAB = 9;
  24029. Keyboard.INSERT = 45;
  24030. class CommandEncoder {
  24031. constructor(layagl, reserveSize, adjustSize, isSyncToRenderThread) {
  24032. this._idata = [];
  24033. }
  24034. getArrayData() {
  24035. return this._idata;
  24036. }
  24037. getPtrID() {
  24038. return 0;
  24039. }
  24040. beginEncoding() {
  24041. }
  24042. endEncoding() {
  24043. }
  24044. clearEncoding() {
  24045. this._idata.length = 0;
  24046. }
  24047. getCount() {
  24048. return this._idata.length;
  24049. }
  24050. add_ShaderValue(o) {
  24051. this._idata.push(o);
  24052. }
  24053. addShaderUniform(one) {
  24054. this.add_ShaderValue(one);
  24055. }
  24056. }
  24057. class LayaGLRunner {
  24058. static uploadShaderUniforms(layaGL, commandEncoder, shaderData, uploadUnTexture) {
  24059. var data = shaderData._data;
  24060. var shaderUniform = commandEncoder.getArrayData();
  24061. var shaderCall = 0;
  24062. for (var i = 0, n = shaderUniform.length; i < n; i++) {
  24063. var one = shaderUniform[i];
  24064. if (uploadUnTexture || one.textureID !== -1) {
  24065. var value = data[one.dataOffset];
  24066. if (value != null)
  24067. shaderCall += one.fun.call(one.caller, one, value);
  24068. }
  24069. }
  24070. return shaderCall;
  24071. }
  24072. static uploadCustomUniform(layaGL, custom, index, data) {
  24073. var shaderCall = 0;
  24074. var one = custom[index];
  24075. if (one && data != null)
  24076. shaderCall += one.fun.call(one.caller, one, data);
  24077. return shaderCall;
  24078. }
  24079. static uploadShaderUniformsForNative(layaGL, commandEncoder, shaderData) {
  24080. var nType = LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_ID;
  24081. if (shaderData._runtimeCopyValues.length > 0) {
  24082. nType = LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_DATA;
  24083. }
  24084. var data = shaderData._data;
  24085. return LayaGL.instance.uploadShaderUniforms(commandEncoder, data, nType);
  24086. }
  24087. }
  24088. class QuickTestTool {
  24089. constructor() {
  24090. }
  24091. static getMCDName(type) {
  24092. return QuickTestTool._typeToNameDic[type];
  24093. }
  24094. static showRenderTypeInfo(type, force = false) {
  24095. if (!force && QuickTestTool.showedDic[type])
  24096. return;
  24097. QuickTestTool.showedDic[type] = true;
  24098. if (!QuickTestTool._rendertypeToStrDic[type]) {
  24099. var arr = [];
  24100. var tType;
  24101. tType = 1;
  24102. while (tType <= type) {
  24103. if (tType & type) {
  24104. arr.push(QuickTestTool.getMCDName(tType & type));
  24105. }
  24106. tType = tType << 1;
  24107. }
  24108. QuickTestTool._rendertypeToStrDic[type] = arr.join(",");
  24109. }
  24110. console.log("cmd:", QuickTestTool._rendertypeToStrDic[type]);
  24111. }
  24112. static __init__() {
  24113. QuickTestTool._typeToNameDic[SpriteConst.ALPHA] = "ALPHA";
  24114. QuickTestTool._typeToNameDic[SpriteConst.TRANSFORM] = "TRANSFORM";
  24115. QuickTestTool._typeToNameDic[SpriteConst.TEXTURE] = "TEXTURE";
  24116. QuickTestTool._typeToNameDic[SpriteConst.GRAPHICS] = "GRAPHICS";
  24117. QuickTestTool._typeToNameDic[SpriteConst.ONECHILD] = "ONECHILD";
  24118. QuickTestTool._typeToNameDic[SpriteConst.CHILDS] = "CHILDS";
  24119. QuickTestTool._typeToNameDic[SpriteConst.TRANSFORM | SpriteConst.ALPHA] = "TRANSFORM|ALPHA";
  24120. QuickTestTool._typeToNameDic[SpriteConst.CANVAS] = "CANVAS";
  24121. QuickTestTool._typeToNameDic[SpriteConst.BLEND] = "BLEND";
  24122. QuickTestTool._typeToNameDic[SpriteConst.FILTERS] = "FILTERS";
  24123. QuickTestTool._typeToNameDic[SpriteConst.MASK] = "MASK";
  24124. QuickTestTool._typeToNameDic[SpriteConst.CLIP] = "CLIP";
  24125. QuickTestTool._typeToNameDic[SpriteConst.LAYAGL3D] = "LAYAGL3D";
  24126. }
  24127. render(context, x, y) {
  24128. QuickTestTool._addType(this._renderType);
  24129. QuickTestTool.showRenderTypeInfo(this._renderType);
  24130. RenderSprite.renders[this._renderType]._fun(this, context, x + this._x, y + this._y);
  24131. this._repaint = 0;
  24132. }
  24133. _stageRender(context, x, y) {
  24134. QuickTestTool._countStart();
  24135. QuickTestTool._PreStageRender.call(ILaya.stage, context, x, y);
  24136. QuickTestTool._countEnd();
  24137. }
  24138. static _countStart() {
  24139. var key;
  24140. for (key in QuickTestTool._countDic) {
  24141. QuickTestTool._countDic[key] = 0;
  24142. }
  24143. }
  24144. static _countEnd() {
  24145. QuickTestTool._i++;
  24146. if (QuickTestTool._i > 60) {
  24147. QuickTestTool.showCountInfo();
  24148. QuickTestTool._i = 0;
  24149. }
  24150. }
  24151. static _addType(type) {
  24152. if (!QuickTestTool._countDic[type]) {
  24153. QuickTestTool._countDic[type] = 1;
  24154. }
  24155. else {
  24156. QuickTestTool._countDic[type] += 1;
  24157. }
  24158. }
  24159. static showCountInfo() {
  24160. console.log("===================");
  24161. var key;
  24162. for (key in QuickTestTool._countDic) {
  24163. console.log("count:" + QuickTestTool._countDic[key]);
  24164. QuickTestTool.showRenderTypeInfo(key, true);
  24165. }
  24166. }
  24167. static enableQuickTest() {
  24168. QuickTestTool.__init__();
  24169. Sprite["prototype"]["render"] = QuickTestTool["prototype"]["render"];
  24170. QuickTestTool._PreStageRender = Stage["prototype"]["render"];
  24171. Stage["prototype"]["render"] = QuickTestTool["prototype"]["_stageRender"];
  24172. }
  24173. }
  24174. QuickTestTool.showedDic = {};
  24175. QuickTestTool._rendertypeToStrDic = {};
  24176. QuickTestTool._typeToNameDic = {};
  24177. QuickTestTool._countDic = {};
  24178. QuickTestTool._i = 0;
  24179. class Sound extends EventDispatcher {
  24180. load(url) {
  24181. }
  24182. play(startTime = 0, loops = 0) {
  24183. return null;
  24184. }
  24185. get duration() {
  24186. return 0;
  24187. }
  24188. dispose() {
  24189. }
  24190. }
  24191. class SoundNode extends Sprite {
  24192. constructor() {
  24193. super();
  24194. this.visible = false;
  24195. this.on(Event.ADDED, this, this._onParentChange);
  24196. this.on(Event.REMOVED, this, this._onParentChange);
  24197. }
  24198. _onParentChange() {
  24199. this.target = this.parent;
  24200. }
  24201. play(loops = 1, complete = null) {
  24202. if (isNaN(loops)) {
  24203. loops = 1;
  24204. }
  24205. if (!this.url)
  24206. return;
  24207. this.stop();
  24208. this._channel = SoundManager.playSound(this.url, loops, complete);
  24209. }
  24210. stop() {
  24211. if (this._channel && !this._channel.isStopped) {
  24212. this._channel.stop();
  24213. }
  24214. this._channel = null;
  24215. }
  24216. _setPlayAction(tar, event, action, add = true) {
  24217. if (!this[action])
  24218. return;
  24219. if (!tar)
  24220. return;
  24221. if (add) {
  24222. tar.on(event, this, this[action]);
  24223. }
  24224. else {
  24225. tar.off(event, this, this[action]);
  24226. }
  24227. }
  24228. _setPlayActions(tar, events, action, add = true) {
  24229. if (!tar)
  24230. return;
  24231. if (!events)
  24232. return;
  24233. var eventArr = events.split(",");
  24234. var i, len;
  24235. len = eventArr.length;
  24236. for (i = 0; i < len; i++) {
  24237. this._setPlayAction(tar, eventArr[i], action, add);
  24238. }
  24239. }
  24240. set playEvent(events) {
  24241. this._playEvents = events;
  24242. if (!events)
  24243. return;
  24244. if (this._tar) {
  24245. this._setPlayActions(this._tar, events, "play");
  24246. }
  24247. }
  24248. set target(tar) {
  24249. if (this._tar) {
  24250. this._setPlayActions(this._tar, this._playEvents, "play", false);
  24251. this._setPlayActions(this._tar, this._stopEvents, "stop", false);
  24252. }
  24253. this._tar = tar;
  24254. if (this._tar) {
  24255. this._setPlayActions(this._tar, this._playEvents, "play", true);
  24256. this._setPlayActions(this._tar, this._stopEvents, "stop", true);
  24257. }
  24258. }
  24259. set stopEvent(events) {
  24260. this._stopEvents = events;
  24261. if (!events)
  24262. return;
  24263. if (this._tar) {
  24264. this._setPlayActions(this._tar, events, "stop");
  24265. }
  24266. }
  24267. }
  24268. class ResourceVersion {
  24269. static enable(manifestFile, callback, type = 2) {
  24270. ResourceVersion.type = type;
  24271. ILaya.loader.load(manifestFile, Handler.create(null, ResourceVersion.onManifestLoaded, [callback]), null, Loader.JSON);
  24272. }
  24273. static onManifestLoaded(callback, data) {
  24274. ResourceVersion.manifest = data;
  24275. URL.customFormat = ResourceVersion.addVersionPrefix;
  24276. callback.run();
  24277. if (!data) {
  24278. console.warn("资源版本清单文件不存在,不使用资源版本管理。忽略ERR_FILE_NOT_FOUND错误。");
  24279. }
  24280. }
  24281. static addVersionPrefix(originURL) {
  24282. originURL = URL.getAdptedFilePath(originURL);
  24283. if (ResourceVersion.manifest && ResourceVersion.manifest[originURL]) {
  24284. if (ResourceVersion.type == ResourceVersion.FILENAME_VERSION)
  24285. return ResourceVersion.manifest[originURL];
  24286. return ResourceVersion.manifest[originURL] + "/" + originURL;
  24287. }
  24288. return originURL;
  24289. }
  24290. }
  24291. ResourceVersion.FOLDER_VERSION = 1;
  24292. ResourceVersion.FILENAME_VERSION = 2;
  24293. ResourceVersion.type = ResourceVersion.FOLDER_VERSION;
  24294. class Socket extends EventDispatcher {
  24295. constructor(host = null, port = 0, byteClass = null, protocols = null) {
  24296. super();
  24297. this.disableInput = false;
  24298. this.protocols = [];
  24299. this._byteClass = byteClass ? byteClass : Byte;
  24300. this.protocols = protocols;
  24301. this.endian = Socket.BIG_ENDIAN;
  24302. if (host && port > 0 && port < 65535)
  24303. this.connect(host, port);
  24304. }
  24305. get input() {
  24306. return this._input;
  24307. }
  24308. get output() {
  24309. return this._output;
  24310. }
  24311. get connected() {
  24312. return this._connected;
  24313. }
  24314. get endian() {
  24315. return this._endian;
  24316. }
  24317. set endian(value) {
  24318. this._endian = value;
  24319. if (this._input != null)
  24320. this._input.endian = value;
  24321. if (this._output != null)
  24322. this._output.endian = value;
  24323. }
  24324. connect(host, port) {
  24325. var url = "ws://" + host + ":" + port;
  24326. this.connectByUrl(url);
  24327. }
  24328. connectByUrl(url) {
  24329. if (this._socket != null)
  24330. this.close();
  24331. this._socket && this.cleanSocket();
  24332. if (!this.protocols || this.protocols.length == 0) {
  24333. this._socket = new Browser.window.WebSocket(url);
  24334. }
  24335. else {
  24336. this._socket = new Browser.window.WebSocket(url, this.protocols);
  24337. }
  24338. this._socket.binaryType = "arraybuffer";
  24339. this._output = new this._byteClass();
  24340. this._output.endian = this.endian;
  24341. this._input = new this._byteClass();
  24342. this._input.endian = this.endian;
  24343. this._addInputPosition = 0;
  24344. this._socket.onopen = (e) => {
  24345. this._onOpen(e);
  24346. };
  24347. this._socket.onmessage = (msg) => {
  24348. this._onMessage(msg);
  24349. };
  24350. this._socket.onclose = (e) => {
  24351. this._onClose(e);
  24352. };
  24353. this._socket.onerror = (e) => {
  24354. this._onError(e);
  24355. };
  24356. }
  24357. cleanSocket() {
  24358. this.close();
  24359. this._connected = false;
  24360. this._socket.onopen = null;
  24361. this._socket.onmessage = null;
  24362. this._socket.onclose = null;
  24363. this._socket.onerror = null;
  24364. this._socket = null;
  24365. }
  24366. close() {
  24367. if (this._socket != null) {
  24368. try {
  24369. this._socket.close();
  24370. }
  24371. catch (e) {
  24372. }
  24373. }
  24374. }
  24375. _onOpen(e) {
  24376. this._connected = true;
  24377. this.event(Event.OPEN, e);
  24378. }
  24379. _onMessage(msg) {
  24380. if (!msg || !msg.data)
  24381. return;
  24382. var data = msg.data;
  24383. if (this.disableInput && data) {
  24384. this.event(Event.MESSAGE, data);
  24385. return;
  24386. }
  24387. if (this._input.length > 0 && this._input.bytesAvailable < 1) {
  24388. this._input.clear();
  24389. this._addInputPosition = 0;
  24390. }
  24391. var pre = this._input.pos;
  24392. !this._addInputPosition && (this._addInputPosition = 0);
  24393. this._input.pos = this._addInputPosition;
  24394. if (data) {
  24395. if (typeof (data) == 'string') {
  24396. this._input.writeUTFBytes(data);
  24397. }
  24398. else {
  24399. this._input.writeArrayBuffer(data);
  24400. }
  24401. this._addInputPosition = this._input.pos;
  24402. this._input.pos = pre;
  24403. }
  24404. this.event(Event.MESSAGE, data);
  24405. }
  24406. _onClose(e) {
  24407. this._connected = false;
  24408. this.event(Event.CLOSE, e);
  24409. }
  24410. _onError(e) {
  24411. this.event(Event.ERROR, e);
  24412. }
  24413. send(data) {
  24414. this._socket.send(data);
  24415. }
  24416. flush() {
  24417. if (this._output && this._output.length > 0) {
  24418. var evt;
  24419. try {
  24420. this._socket && this._socket.send(this._output.__getBuffer().slice(0, this._output.length));
  24421. }
  24422. catch (e) {
  24423. evt = e;
  24424. }
  24425. this._output.endian = this.endian;
  24426. this._output.clear();
  24427. if (evt)
  24428. this.event(Event.ERROR, evt);
  24429. }
  24430. }
  24431. }
  24432. Socket.LITTLE_ENDIAN = "littleEndian";
  24433. Socket.BIG_ENDIAN = "bigEndian";
  24434. class System {
  24435. static changeDefinition(name, classObj) {
  24436. window.Laya[name] = classObj;
  24437. var str = name + "=classObj";
  24438. window['eval'](str);
  24439. }
  24440. }
  24441. class HTMLChar {
  24442. constructor() {
  24443. this.reset();
  24444. }
  24445. setData(char, w, h, style) {
  24446. this.char = char;
  24447. this.charNum = char.charCodeAt(0);
  24448. this.x = this.y = 0;
  24449. this.width = w;
  24450. this.height = h;
  24451. this.style = style;
  24452. this.isWord = !HTMLChar._isWordRegExp.test(char);
  24453. return this;
  24454. }
  24455. reset() {
  24456. this.x = this.y = this.width = this.height = 0;
  24457. this.isWord = false;
  24458. this.char = null;
  24459. this.charNum = 0;
  24460. this.style = null;
  24461. return this;
  24462. }
  24463. recover() {
  24464. Pool.recover("HTMLChar", this.reset());
  24465. }
  24466. static create() {
  24467. return Pool.getItemByClass("HTMLChar", HTMLChar);
  24468. }
  24469. _isChar() {
  24470. return true;
  24471. }
  24472. _getCSSStyle() {
  24473. return this.style;
  24474. }
  24475. }
  24476. HTMLChar._isWordRegExp = new RegExp("[\\w\.]", "");
  24477. class Log {
  24478. static enable() {
  24479. if (!Log._logdiv) {
  24480. Log._logdiv = Browser.createElement('div');
  24481. Log._logdiv.style.cssText = "border:white;padding:4px;overflow-y:auto;z-index:1000000;background:rgba(100,100,100,0.6);color:white;position: absolute;left:0px;top:0px;width:50%;height:50%;";
  24482. Browser.document.body.appendChild(Log._logdiv);
  24483. Log._btn = Browser.createElement("button");
  24484. Log._btn.innerText = "Hide";
  24485. Log._btn.style.cssText = "z-index:1000001;position: absolute;left:10px;top:10px;";
  24486. Log._btn.onclick = Log.toggle;
  24487. Browser.document.body.appendChild(Log._btn);
  24488. }
  24489. }
  24490. static toggle() {
  24491. var style = Log._logdiv.style;
  24492. if (style.display === "") {
  24493. Log._btn.innerText = "Show";
  24494. style.display = "none";
  24495. }
  24496. else {
  24497. Log._btn.innerText = "Hide";
  24498. style.display = "";
  24499. }
  24500. }
  24501. static print(value) {
  24502. if (Log._logdiv) {
  24503. if (Log._count >= Log.maxCount)
  24504. Log.clear();
  24505. Log._count++;
  24506. Log._logdiv.innerText += value + "\n";
  24507. if (Log.autoScrollToBottom) {
  24508. if (Log._logdiv.scrollHeight - Log._logdiv.scrollTop - Log._logdiv.clientHeight < 50) {
  24509. Log._logdiv.scrollTop = Log._logdiv.scrollHeight;
  24510. }
  24511. }
  24512. }
  24513. }
  24514. static clear() {
  24515. Log._logdiv.innerText = "";
  24516. Log._count = 0;
  24517. }
  24518. }
  24519. Log._count = 0;
  24520. Log.maxCount = 50;
  24521. Log.autoScrollToBottom = true;
  24522. let DATANUM = 300;
  24523. class PerfData {
  24524. constructor(id, color, name, scale) {
  24525. this.scale = 1.0;
  24526. this.datas = new Array(DATANUM);
  24527. this.datapos = 0;
  24528. this.id = id;
  24529. this.color = color;
  24530. this.name = name;
  24531. this.scale = scale;
  24532. }
  24533. addData(v) {
  24534. this.datas[this.datapos] = v;
  24535. this.datapos++;
  24536. this.datapos %= DATANUM;
  24537. }
  24538. }
  24539. class PerfHUD extends Sprite {
  24540. constructor() {
  24541. super();
  24542. this.datas = [];
  24543. this.xdata = new Array(PerfHUD.DATANUM);
  24544. this.ydata = new Array(PerfHUD.DATANUM);
  24545. this.hud_width = 800;
  24546. this.hud_height = 200;
  24547. this.gMinV = 0;
  24548. this.gMaxV = 100;
  24549. this.textSpace = 40;
  24550. this.sttm = 0;
  24551. PerfHUD.inst = this;
  24552. this._renderType |= SpriteConst.CUSTOM;
  24553. this._setRenderType(this._renderType);
  24554. this._setCustomRender();
  24555. this.addDataDef(0, 0xffffff, 'frame', 1.0);
  24556. this.addDataDef(1, 0x00ff00, 'update', 1.0);
  24557. this.addDataDef(2, 0xff0000, 'flush', 1.0);
  24558. PerfHUD._now = performance ? performance.now.bind(performance) : Date.now;
  24559. }
  24560. now() {
  24561. return PerfHUD._now();
  24562. }
  24563. start() {
  24564. this.sttm = PerfHUD._now();
  24565. }
  24566. end(i) {
  24567. var dt = PerfHUD._now() - this.sttm;
  24568. this.updateValue(i, dt);
  24569. }
  24570. config(w, h) {
  24571. this.hud_width = w;
  24572. this.hud_height = h;
  24573. }
  24574. addDataDef(id, color, name, scale) {
  24575. this.datas[id] = new PerfData(id, color, name, scale);
  24576. }
  24577. updateValue(id, v) {
  24578. this.datas[id].addData(v);
  24579. }
  24580. v2y(v) {
  24581. var bb = this._y + this.hud_height * (1 - (v - this.gMinV) / this.gMaxV);
  24582. return this._y + this.hud_height * (1 - (v - this.gMinV) / this.gMaxV);
  24583. }
  24584. drawHLine(ctx, v, color, text) {
  24585. var sx = this._x;
  24586. var ex = this._x + this.hud_width;
  24587. var sy = this.v2y(v);
  24588. ctx.fillText(text, sx, sy - 6, null, 'green', null);
  24589. sx += this.textSpace;
  24590. ctx.fillStyle = color;
  24591. ctx.fillRect(sx, sy, this._x + this.hud_width, 1, null);
  24592. }
  24593. customRender(ctx, x, y) {
  24594. var now = performance.now();
  24595. if (PerfHUD._lastTm <= 0)
  24596. PerfHUD._lastTm = now;
  24597. this.updateValue(0, now - PerfHUD._lastTm);
  24598. PerfHUD._lastTm = now;
  24599. ctx.save();
  24600. ctx.fillRect(this._x, this._y, this.hud_width, this.hud_height + 4, '#000000cc');
  24601. ctx.globalAlpha = 0.9;
  24602. this.drawHLine(ctx, 0, 'green', ' 0');
  24603. this.drawHLine(ctx, 10, 'green', ' 10');
  24604. this.drawHLine(ctx, 16.667, 'red', ' ');
  24605. this.drawHLine(ctx, 20, 'green', '50|20');
  24606. this.drawHLine(ctx, 16.667 * 2, 'yellow', '');
  24607. this.drawHLine(ctx, 16.667 * 3, 'yellow', '');
  24608. this.drawHLine(ctx, 16.667 * 4, 'yellow', '');
  24609. this.drawHLine(ctx, 50, 'green', '20|50');
  24610. this.drawHLine(ctx, 100, 'green', '10|100');
  24611. for (var di = 0, sz = this.datas.length; di < sz; di++) {
  24612. var cd = this.datas[di];
  24613. if (!cd)
  24614. continue;
  24615. var dtlen = cd.datas.length;
  24616. var dx = (this.hud_width - this.textSpace) / dtlen;
  24617. var cx = cd.datapos;
  24618. var _cx = this._x + this.textSpace;
  24619. ctx.fillStyle = cd.color;
  24620. for (var dtsz = dtlen; cx < dtsz; cx++) {
  24621. var sty = this.v2y(cd.datas[cx] * cd.scale);
  24622. ctx.fillRect(_cx, sty, dx, this.hud_height + this._y - sty, null);
  24623. _cx += dx;
  24624. }
  24625. for (cx = 0; cx < cd.datapos; cx++) {
  24626. sty = this.v2y(cd.datas[cx] * cd.scale);
  24627. ctx.fillRect(_cx, sty, dx, this.hud_height + this._y - sty, null);
  24628. _cx += dx;
  24629. }
  24630. }
  24631. ctx.restore();
  24632. }
  24633. }
  24634. PerfHUD._lastTm = 0;
  24635. PerfHUD._now = null;
  24636. PerfHUD.DATANUM = 300;
  24637. PerfHUD.drawTexTm = 0;
  24638. class PoolCache {
  24639. constructor() {
  24640. this.maxCount = 1000;
  24641. }
  24642. getCacheList() {
  24643. return Pool.getPoolBySign(this.sign);
  24644. }
  24645. tryDispose(force) {
  24646. var list;
  24647. list = Pool.getPoolBySign(this.sign);
  24648. if (list.length > this.maxCount) {
  24649. list.splice(this.maxCount, list.length - this.maxCount);
  24650. }
  24651. }
  24652. static addPoolCacheManager(sign, maxCount = 100) {
  24653. var cache;
  24654. cache = new PoolCache();
  24655. cache.sign = sign;
  24656. cache.maxCount = maxCount;
  24657. CacheManger.regCacheByFunction(Utils.bind(cache.tryDispose, cache), Utils.bind(cache.getCacheList, cache));
  24658. }
  24659. }
  24660. class TimeLine extends EventDispatcher {
  24661. constructor() {
  24662. super(...arguments);
  24663. this._tweenDic = {};
  24664. this._tweenDataList = [];
  24665. this._currTime = 0;
  24666. this._lastTime = 0;
  24667. this._startTime = 0;
  24668. this._index = 0;
  24669. this._gidIndex = 0;
  24670. this._firstTweenDic = {};
  24671. this._startTimeSort = false;
  24672. this._endTimeSort = false;
  24673. this._loopKey = false;
  24674. this.scale = 1;
  24675. this._frameRate = 60;
  24676. this._frameIndex = 0;
  24677. this._total = 0;
  24678. }
  24679. static to(target, props, duration, ease = null, offset = 0) {
  24680. return (new TimeLine()).to(target, props, duration, ease, offset);
  24681. }
  24682. static from(target, props, duration, ease = null, offset = 0) {
  24683. return (new TimeLine()).from(target, props, duration, ease, offset);
  24684. }
  24685. to(target, props, duration, ease = null, offset = 0) {
  24686. return this._create(target, props, duration, ease, offset, true);
  24687. }
  24688. from(target, props, duration, ease = null, offset = 0) {
  24689. return this._create(target, props, duration, ease, offset, false);
  24690. }
  24691. _create(target, props, duration, ease, offset, isTo) {
  24692. var tTweenData = Pool.getItemByClass("tweenData", tweenData);
  24693. tTweenData.isTo = isTo;
  24694. tTweenData.type = 0;
  24695. tTweenData.target = target;
  24696. tTweenData.duration = duration;
  24697. tTweenData.data = props;
  24698. tTweenData.startTime = this._startTime + offset;
  24699. tTweenData.endTime = tTweenData.startTime + tTweenData.duration;
  24700. tTweenData.ease = ease;
  24701. this._startTime = Math.max(tTweenData.endTime, this._startTime);
  24702. this._tweenDataList.push(tTweenData);
  24703. this._startTimeSort = true;
  24704. this._endTimeSort = true;
  24705. return this;
  24706. }
  24707. addLabel(label, offset) {
  24708. var tTweenData = Pool.getItemByClass("tweenData", tweenData);
  24709. tTweenData.type = 1;
  24710. tTweenData.data = label;
  24711. tTweenData.endTime = tTweenData.startTime = this._startTime + offset;
  24712. this._labelDic || (this._labelDic = {});
  24713. this._labelDic[label] = tTweenData;
  24714. this._tweenDataList.push(tTweenData);
  24715. return this;
  24716. }
  24717. removeLabel(label) {
  24718. if (this._labelDic && this._labelDic[label]) {
  24719. var tTweenData = this._labelDic[label];
  24720. if (tTweenData) {
  24721. var tIndex = this._tweenDataList.indexOf(tTweenData);
  24722. if (tIndex > -1) {
  24723. this._tweenDataList.splice(tIndex, 1);
  24724. }
  24725. }
  24726. delete this._labelDic[label];
  24727. }
  24728. }
  24729. gotoTime(time) {
  24730. if (this._tweenDataList == null || this._tweenDataList.length == 0)
  24731. return;
  24732. var tTween;
  24733. var tObject;
  24734. for (var p in this._firstTweenDic) {
  24735. tObject = this._firstTweenDic[p];
  24736. if (tObject) {
  24737. for (var tDataP in tObject) {
  24738. if (tDataP in tObject.diyTarget) {
  24739. tObject.diyTarget[tDataP] = tObject[tDataP];
  24740. }
  24741. }
  24742. }
  24743. }
  24744. for (p in this._tweenDic) {
  24745. tTween = this._tweenDic[p];
  24746. tTween.clear();
  24747. delete this._tweenDic[p];
  24748. }
  24749. this._index = 0;
  24750. this._gidIndex = 0;
  24751. this._currTime = time;
  24752. this._lastTime = Browser.now();
  24753. var tTweenDataCopyList;
  24754. if (this._endTweenDataList == null || this._endTimeSort) {
  24755. this._endTimeSort = false;
  24756. this._endTweenDataList = tTweenDataCopyList = this._tweenDataList.concat();
  24757. function Compare(paraA, paraB) {
  24758. if (paraA.endTime > paraB.endTime) {
  24759. return 1;
  24760. }
  24761. else if (paraA.endTime < paraB.endTime) {
  24762. return -1;
  24763. }
  24764. else {
  24765. return 0;
  24766. }
  24767. }
  24768. tTweenDataCopyList.sort(Compare);
  24769. }
  24770. else {
  24771. tTweenDataCopyList = this._endTweenDataList;
  24772. }
  24773. var tTweenData;
  24774. for (var i = 0, n = tTweenDataCopyList.length; i < n; i++) {
  24775. tTweenData = tTweenDataCopyList[i];
  24776. if (tTweenData.type == 0) {
  24777. if (time >= tTweenData.endTime) {
  24778. this._index = Math.max(this._index, i + 1);
  24779. var props = tTweenData.data;
  24780. if (tTweenData.isTo) {
  24781. for (var tP in props) {
  24782. tTweenData.target[tP] = props[tP];
  24783. }
  24784. }
  24785. }
  24786. else {
  24787. break;
  24788. }
  24789. }
  24790. }
  24791. for (i = 0, n = this._tweenDataList.length; i < n; i++) {
  24792. tTweenData = this._tweenDataList[i];
  24793. if (tTweenData.type == 0) {
  24794. if (time >= tTweenData.startTime && time < tTweenData.endTime) {
  24795. this._index = Math.max(this._index, i + 1);
  24796. this._gidIndex++;
  24797. tTween = Pool.getItemByClass("tween", Tween);
  24798. tTween._create(tTweenData.target, tTweenData.data, tTweenData.duration, tTweenData.ease, Handler.create(this, this._animComplete, [this._gidIndex]), 0, false, tTweenData.isTo, true, false);
  24799. tTween.setStartTime(this._currTime - (time - tTweenData.startTime));
  24800. tTween._updateEase(this._currTime);
  24801. tTween.gid = this._gidIndex;
  24802. this._tweenDic[this._gidIndex] = tTween;
  24803. }
  24804. }
  24805. }
  24806. }
  24807. gotoLabel(Label) {
  24808. if (this._labelDic == null)
  24809. return;
  24810. var tLabelData = this._labelDic[Label];
  24811. if (tLabelData)
  24812. this.gotoTime(tLabelData.startTime);
  24813. }
  24814. pause() {
  24815. ILaya.timer.clear(this, this._update);
  24816. }
  24817. resume() {
  24818. this.play(this._currTime, this._loopKey);
  24819. }
  24820. play(timeOrLabel = 0, loop = false) {
  24821. if (!this._tweenDataList)
  24822. return;
  24823. if (this._startTimeSort) {
  24824. this._startTimeSort = false;
  24825. function Compare(paraA, paraB) {
  24826. if (paraA.startTime > paraB.startTime) {
  24827. return 1;
  24828. }
  24829. else if (paraA.startTime < paraB.startTime) {
  24830. return -1;
  24831. }
  24832. else {
  24833. return 0;
  24834. }
  24835. }
  24836. this._tweenDataList.sort(Compare);
  24837. for (var i = 0, n = this._tweenDataList.length; i < n; i++) {
  24838. var tTweenData = this._tweenDataList[i];
  24839. if (tTweenData != null && tTweenData.type == 0) {
  24840. var tTarget = tTweenData.target;
  24841. var gid = (tTarget.$_GID || (tTarget.$_GID = Utils.getGID()));
  24842. var tSrcData = null;
  24843. if (this._firstTweenDic[gid] == null) {
  24844. tSrcData = {};
  24845. tSrcData.diyTarget = tTarget;
  24846. this._firstTweenDic[gid] = tSrcData;
  24847. }
  24848. else {
  24849. tSrcData = this._firstTweenDic[gid];
  24850. }
  24851. for (var p in tTweenData.data) {
  24852. if (tSrcData[p] == null) {
  24853. tSrcData[p] = tTarget[p];
  24854. }
  24855. }
  24856. }
  24857. }
  24858. }
  24859. if (typeof (timeOrLabel) == 'string') {
  24860. this.gotoLabel(timeOrLabel);
  24861. }
  24862. else {
  24863. this.gotoTime(timeOrLabel);
  24864. }
  24865. this._loopKey = loop;
  24866. this._lastTime = Browser.now();
  24867. ILaya.timer.frameLoop(1, this, this._update);
  24868. }
  24869. _update() {
  24870. if (this._currTime >= this._startTime) {
  24871. if (this._loopKey) {
  24872. this._complete();
  24873. if (!this._tweenDataList)
  24874. return;
  24875. this.gotoTime(0);
  24876. }
  24877. else {
  24878. for (var p in this._tweenDic) {
  24879. tTween = this._tweenDic[p];
  24880. tTween.complete();
  24881. }
  24882. this.pause();
  24883. this._complete();
  24884. return;
  24885. }
  24886. }
  24887. var tNow = Browser.now();
  24888. var tFrameTime = tNow - this._lastTime;
  24889. var tCurrTime = this._currTime += tFrameTime * this.scale;
  24890. this._lastTime = tNow;
  24891. for (p in this._tweenDic) {
  24892. tTween = this._tweenDic[p];
  24893. tTween._updateEase(tCurrTime);
  24894. }
  24895. var tTween;
  24896. if (this._tweenDataList.length != 0 && this._index < this._tweenDataList.length) {
  24897. var tTweenData = this._tweenDataList[this._index];
  24898. if (tCurrTime >= tTweenData.startTime) {
  24899. this._index++;
  24900. if (tTweenData.type == 0) {
  24901. this._gidIndex++;
  24902. tTween = Pool.getItemByClass("tween", Tween);
  24903. tTween._create(tTweenData.target, tTweenData.data, tTweenData.duration, tTweenData.ease, Handler.create(this, this._animComplete, [this._gidIndex]), 0, false, tTweenData.isTo, true, false);
  24904. tTween.setStartTime(tCurrTime);
  24905. tTween.gid = this._gidIndex;
  24906. this._tweenDic[this._gidIndex] = tTween;
  24907. tTween._updateEase(tCurrTime);
  24908. }
  24909. else {
  24910. this.event(Event.LABEL, tTweenData.data);
  24911. }
  24912. }
  24913. }
  24914. }
  24915. _animComplete(index) {
  24916. var tTween = this._tweenDic[index];
  24917. if (tTween)
  24918. delete this._tweenDic[index];
  24919. }
  24920. _complete() {
  24921. this.event(Event.COMPLETE);
  24922. }
  24923. get index() {
  24924. return this._frameIndex;
  24925. }
  24926. set index(value) {
  24927. this._frameIndex = value;
  24928. this.gotoTime(this._frameIndex / this._frameRate * 1000);
  24929. }
  24930. get total() {
  24931. this._total = Math.floor(this._startTime / 1000 * this._frameRate);
  24932. return this._total;
  24933. }
  24934. reset() {
  24935. var p;
  24936. if (this._labelDic) {
  24937. for (p in this._labelDic) {
  24938. delete this._labelDic[p];
  24939. }
  24940. }
  24941. var tTween;
  24942. for (p in this._tweenDic) {
  24943. tTween = this._tweenDic[p];
  24944. tTween.clear();
  24945. delete this._tweenDic[p];
  24946. }
  24947. for (p in this._firstTweenDic) {
  24948. delete this._firstTweenDic[p];
  24949. }
  24950. this._endTweenDataList = null;
  24951. if (this._tweenDataList && this._tweenDataList.length) {
  24952. var i, len;
  24953. len = this._tweenDataList.length;
  24954. for (i = 0; i < len; i++) {
  24955. if (this._tweenDataList[i])
  24956. this._tweenDataList[i].destroy();
  24957. }
  24958. }
  24959. this._tweenDataList.length = 0;
  24960. this._currTime = 0;
  24961. this._lastTime = 0;
  24962. this._startTime = 0;
  24963. this._index = 0;
  24964. this._gidIndex = 0;
  24965. this.scale = 1;
  24966. ILaya.timer.clear(this, this._update);
  24967. }
  24968. destroy() {
  24969. this.reset();
  24970. this._labelDic = null;
  24971. this._tweenDic = null;
  24972. this._tweenDataList = null;
  24973. this._firstTweenDic = null;
  24974. }
  24975. }
  24976. class tweenData {
  24977. constructor() {
  24978. this.type = 0;
  24979. this.isTo = true;
  24980. }
  24981. destroy() {
  24982. this.target = null;
  24983. this.ease = null;
  24984. this.data = null;
  24985. this.isTo = true;
  24986. this.type = 0;
  24987. Pool.recover("tweenData", this);
  24988. }
  24989. }
  24990. class ShaderValue {
  24991. constructor() {
  24992. }
  24993. }
  24994. class ArabicReshaper {
  24995. characterMapContains(c) {
  24996. for (var i = 0; i < ArabicReshaper.charsMap.length; ++i) {
  24997. if (ArabicReshaper.charsMap[i][0] === c) {
  24998. return true;
  24999. }
  25000. }
  25001. return false;
  25002. }
  25003. getCharRep(c) {
  25004. for (var i = 0; i < ArabicReshaper.charsMap.length; ++i) {
  25005. if (ArabicReshaper.charsMap[i][0] === c) {
  25006. return ArabicReshaper.charsMap[i];
  25007. }
  25008. }
  25009. return false;
  25010. }
  25011. getCombCharRep(c1, c2) {
  25012. for (var i = 0; i < ArabicReshaper.combCharsMap.length; ++i) {
  25013. if (ArabicReshaper.combCharsMap[i][0][0] === c1 && ArabicReshaper.combCharsMap[i][0][1] === c2) {
  25014. return ArabicReshaper.combCharsMap[i];
  25015. }
  25016. }
  25017. return false;
  25018. }
  25019. isTransparent(c) {
  25020. for (var i = 0; i < ArabicReshaper.transChars.length; ++i) {
  25021. if (ArabicReshaper.transChars[i] === c) {
  25022. return true;
  25023. }
  25024. }
  25025. return false;
  25026. }
  25027. getOriginalCharsFromCode(code) {
  25028. var j;
  25029. for (j = 0; j < ArabicReshaper.charsMap.length; ++j) {
  25030. if (ArabicReshaper.charsMap[j].indexOf(code) > -1) {
  25031. return String.fromCharCode(ArabicReshaper.charsMap[j][0]);
  25032. }
  25033. }
  25034. for (j = 0; j < ArabicReshaper.combCharsMap.length; ++j) {
  25035. if (ArabicReshaper.combCharsMap[j].indexOf(code) > -1) {
  25036. return String.fromCharCode(ArabicReshaper.combCharsMap[j][0][0]) +
  25037. String.fromCharCode(ArabicReshaper.combCharsMap[j][0][1]);
  25038. }
  25039. }
  25040. return String.fromCharCode(code);
  25041. }
  25042. convertArabic(normal) {
  25043. var crep, combcrep, shaped = '';
  25044. for (var i = 0; i < normal.length; ++i) {
  25045. var current = normal.charCodeAt(i);
  25046. if (this.characterMapContains(current)) {
  25047. var prev = null, next = null, prevID = i - 1, nextID = i + 1;
  25048. for (; prevID >= 0; --prevID) {
  25049. if (!this.isTransparent(normal.charCodeAt(prevID))) {
  25050. break;
  25051. }
  25052. }
  25053. prev = (prevID >= 0) ? normal.charCodeAt(prevID) : null;
  25054. crep = prev ? this.getCharRep(prev) : false;
  25055. if (!crep || crep[2] == null && crep[3] == null) {
  25056. prev = null;
  25057. }
  25058. for (; nextID < normal.length; ++nextID) {
  25059. if (!this.isTransparent(normal.charCodeAt(nextID))) {
  25060. break;
  25061. }
  25062. }
  25063. next = (nextID < normal.length) ? normal.charCodeAt(nextID) : null;
  25064. crep = next ? this.getCharRep(next) : false;
  25065. if (!crep || crep[3] == null && crep[4] == null) {
  25066. next = null;
  25067. }
  25068. if (current === 0x0644 && next != null &&
  25069. (next === 0x0622 || next === 0x0623 || next === 0x0625 || next === 0x0627)) {
  25070. combcrep = this.getCombCharRep(current, next);
  25071. if (prev != null) {
  25072. shaped += String.fromCharCode(combcrep[4]);
  25073. }
  25074. else {
  25075. shaped += String.fromCharCode(combcrep[1]);
  25076. }
  25077. ++i;
  25078. continue;
  25079. }
  25080. crep = this.getCharRep(current);
  25081. if (prev != null && next != null && crep[3] != null) {
  25082. shaped += String.fromCharCode(crep[3]);
  25083. continue;
  25084. }
  25085. else if (prev != null && crep[4] != null) {
  25086. shaped += String.fromCharCode(crep[4]);
  25087. continue;
  25088. }
  25089. else if (next != null && crep[2] != null) {
  25090. shaped += String.fromCharCode(crep[2]);
  25091. continue;
  25092. }
  25093. else {
  25094. shaped += String.fromCharCode(crep[1]);
  25095. }
  25096. }
  25097. else {
  25098. shaped += String.fromCharCode(current);
  25099. }
  25100. }
  25101. return shaped;
  25102. }
  25103. convertArabicBack(apfb) {
  25104. var toReturn = '', selectedChar;
  25105. var i;
  25106. for (i = 0; i < apfb.length; ++i) {
  25107. selectedChar = apfb.charCodeAt(i);
  25108. toReturn += this.getOriginalCharsFromCode(selectedChar);
  25109. }
  25110. return toReturn;
  25111. }
  25112. }
  25113. ArabicReshaper.charsMap = [[0x0621, 0xFE80, null, null, null],
  25114. [0x0622, 0xFE81, null, null, 0xFE82],
  25115. [0x0623, 0xFE83, null, null, 0xFE84],
  25116. [0x0624, 0xFE85, null, null, 0xFE86],
  25117. [0x0625, 0xFE87, null, null, 0xFE88],
  25118. [0x0626, 0xFE89, 0xFE8B, 0xFE8C, 0xFE8A],
  25119. [0x0627, 0xFE8D, null, null, 0xFE8E],
  25120. [0x0628, 0xFE8F, 0xFE91, 0xFE92, 0xFE90],
  25121. [0x0629, 0xFE93, null, null, 0xFE94],
  25122. [0x062A, 0xFE95, 0xFE97, 0xFE98, 0xFE96],
  25123. [0x062B, 0xFE99, 0xFE9B, 0xFE9C, 0xFE9A],
  25124. [0x062C, 0xFE9D, 0xFE9F, 0xFEA0, 0xFE9E],
  25125. [0x062D, 0xFEA1, 0xFEA3, 0xFEA4, 0xFEA2],
  25126. [0x062E, 0xFEA5, 0xFEA7, 0xFEA8, 0xFEA6],
  25127. [0x062F, 0xFEA9, null, null, 0xFEAA],
  25128. [0x0630, 0xFEAB, null, null, 0xFEAC],
  25129. [0x0631, 0xFEAD, null, null, 0xFEAE],
  25130. [0x0632, 0xFEAF, null, null, 0xFEB0],
  25131. [0x0633, 0xFEB1, 0xFEB3, 0xFEB4, 0xFEB2],
  25132. [0x0634, 0xFEB5, 0xFEB7, 0xFEB8, 0xFEB6],
  25133. [0x0635, 0xFEB9, 0xFEBB, 0xFEBC, 0xFEBA],
  25134. [0x0636, 0xFEBD, 0xFEBF, 0xFEC0, 0xFEBE],
  25135. [0x0637, 0xFEC1, 0xFEC3, 0xFEC4, 0xFEC2],
  25136. [0x0638, 0xFEC5, 0xFEC7, 0xFEC8, 0xFEC6],
  25137. [0x0639, 0xFEC9, 0xFECB, 0xFECC, 0xFECA],
  25138. [0x063A, 0xFECD, 0xFECF, 0xFED0, 0xFECE],
  25139. [0x0640, 0x0640, 0x0640, 0x0640, 0x0640],
  25140. [0x0641, 0xFED1, 0xFED3, 0xFED4, 0xFED2],
  25141. [0x0642, 0xFED5, 0xFED7, 0xFED8, 0xFED6],
  25142. [0x0643, 0xFED9, 0xFEDB, 0xFEDC, 0xFEDA],
  25143. [0x0644, 0xFEDD, 0xFEDF, 0xFEE0, 0xFEDE],
  25144. [0x0645, 0xFEE1, 0xFEE3, 0xFEE4, 0xFEE2],
  25145. [0x0646, 0xFEE5, 0xFEE7, 0xFEE8, 0xFEE6],
  25146. [0x0647, 0xFEE9, 0xFEEB, 0xFEEC, 0xFEEA],
  25147. [0x0648, 0xFEED, null, null, 0xFEEE],
  25148. [0x0649, 0xFEEF, null, null, 0xFEF0],
  25149. [0x064A, 0xFEF1, 0xFEF3, 0xFEF4, 0xFEF2],
  25150. [0x067E, 0xFB56, 0xFB58, 0xFB59, 0xFB57],
  25151. [0x06CC, 0xFBFC, 0xFBFE, 0xFBFF, 0xFBFD],
  25152. [0x0686, 0xFB7A, 0xFB7C, 0xFB7D, 0xFB7B],
  25153. [0x06A9, 0xFB8E, 0xFB90, 0xFB91, 0xFB8F],
  25154. [0x06AF, 0xFB92, 0xFB94, 0xFB95, 0xFB93],
  25155. [0x0698, 0xFB8A, null, null, 0xFB8B]];
  25156. ArabicReshaper.combCharsMap = [[[0x0644, 0x0622], 0xFEF5, null, null, 0xFEF6],
  25157. [[0x0644, 0x0623], 0xFEF7, null, null, 0xFEF8],
  25158. [[0x0644, 0x0625], 0xFEF9, null, null, 0xFEFA],
  25159. [[0x0644, 0x0627], 0xFEFB, null, null, 0xFEFC]];
  25160. ArabicReshaper.transChars = [0x0610,
  25161. 0x0612,
  25162. 0x0613,
  25163. 0x0614,
  25164. 0x0615,
  25165. 0x064B,
  25166. 0x064C,
  25167. 0x064D,
  25168. 0x064E,
  25169. 0x064F,
  25170. 0x0650,
  25171. 0x0651,
  25172. 0x0652,
  25173. 0x0653,
  25174. 0x0654,
  25175. 0x0655,
  25176. 0x0656,
  25177. 0x0657,
  25178. 0x0658,
  25179. 0x0670,
  25180. 0x06D6,
  25181. 0x06D7,
  25182. 0x06D8,
  25183. 0x06D9,
  25184. 0x06DA,
  25185. 0x06DB,
  25186. 0x06DC,
  25187. 0x06DF,
  25188. 0x06E0,
  25189. 0x06E1,
  25190. 0x06E2,
  25191. 0x06E3,
  25192. 0x06E4,
  25193. 0x06E7,
  25194. 0x06E8,
  25195. 0x06EA,
  25196. 0x06EB,
  25197. 0x06EC,
  25198. 0x06ED];
  25199. class MatirxArray {
  25200. static ArrayMul(a, b, o) {
  25201. if (!a) {
  25202. MatirxArray.copyArray(b, o);
  25203. return;
  25204. }
  25205. if (!b) {
  25206. MatirxArray.copyArray(a, o);
  25207. return;
  25208. }
  25209. var ai0, ai1, ai2, ai3;
  25210. for (var i = 0; i < 4; i++) {
  25211. ai0 = a[i];
  25212. ai1 = a[i + 4];
  25213. ai2 = a[i + 8];
  25214. ai3 = a[i + 12];
  25215. o[i] = ai0 * b[0] + ai1 * b[1] + ai2 * b[2] + ai3 * b[3];
  25216. o[i + 4] = ai0 * b[4] + ai1 * b[5] + ai2 * b[6] + ai3 * b[7];
  25217. o[i + 8] = ai0 * b[8] + ai1 * b[9] + ai2 * b[10] + ai3 * b[11];
  25218. o[i + 12] = ai0 * b[12] + ai1 * b[13] + ai2 * b[14] + ai3 * b[15];
  25219. }
  25220. }
  25221. static copyArray(f, t) {
  25222. if (!f)
  25223. return;
  25224. if (!t)
  25225. return;
  25226. for (var i = 0; i < f.length; i++) {
  25227. t[i] = f[i];
  25228. }
  25229. }
  25230. }
  25231. exports.AlphaCmd = AlphaCmd;
  25232. exports.Animation = Animation;
  25233. exports.AnimationBase = AnimationBase;
  25234. exports.ArabicReshaper = ArabicReshaper;
  25235. exports.AtlasGrid = AtlasGrid;
  25236. exports.AtlasInfoManager = AtlasInfoManager;
  25237. exports.AudioSound = AudioSound;
  25238. exports.AudioSoundChannel = AudioSoundChannel;
  25239. exports.BasePoly = BasePoly;
  25240. exports.BaseShader = BaseShader;
  25241. exports.BaseTexture = BaseTexture;
  25242. exports.Bezier = Bezier;
  25243. exports.Bitmap = Bitmap;
  25244. exports.BitmapFont = BitmapFont;
  25245. exports.BlendMode = BlendMode;
  25246. exports.BlurFilter = BlurFilter;
  25247. exports.BlurFilterGLRender = BlurFilterGLRender;
  25248. exports.BlurFilterSetter = BlurFilterSetter;
  25249. exports.BoundsStyle = BoundsStyle;
  25250. exports.Browser = Browser;
  25251. exports.Buffer = Buffer;
  25252. exports.Buffer2D = Buffer2D;
  25253. exports.BufferState2D = BufferState2D;
  25254. exports.BufferStateBase = BufferStateBase;
  25255. exports.ButtonEffect = ButtonEffect;
  25256. exports.Byte = Byte;
  25257. exports.CONST3D2D = CONST3D2D;
  25258. exports.CacheManger = CacheManger;
  25259. exports.CacheStyle = CacheStyle;
  25260. exports.CallLater = CallLater;
  25261. exports.CharRenderInfo = CharRenderInfo;
  25262. exports.CharRender_Canvas = CharRender_Canvas;
  25263. exports.CharRender_Native = CharRender_Native;
  25264. exports.CharSubmitCache = CharSubmitCache;
  25265. exports.ClassUtils = ClassUtils;
  25266. exports.ClipRectCmd = ClipRectCmd;
  25267. exports.ColorFilter = ColorFilter;
  25268. exports.ColorFilterSetter = ColorFilterSetter;
  25269. exports.ColorUtils = ColorUtils;
  25270. exports.CommandEncoder = CommandEncoder;
  25271. exports.CommonScript = CommonScript;
  25272. exports.Component = Component;
  25273. exports.Config = Config;
  25274. exports.Const = Const;
  25275. exports.Context = Context;
  25276. exports.Dragging = Dragging;
  25277. exports.Draw9GridTexture = Draw9GridTexture;
  25278. exports.DrawCircleCmd = DrawCircleCmd;
  25279. exports.DrawCurvesCmd = DrawCurvesCmd;
  25280. exports.DrawImageCmd = DrawImageCmd;
  25281. exports.DrawLineCmd = DrawLineCmd;
  25282. exports.DrawLinesCmd = DrawLinesCmd;
  25283. exports.DrawParticleCmd = DrawParticleCmd;
  25284. exports.DrawPathCmd = DrawPathCmd;
  25285. exports.DrawPieCmd = DrawPieCmd;
  25286. exports.DrawPolyCmd = DrawPolyCmd;
  25287. exports.DrawRectCmd = DrawRectCmd;
  25288. exports.DrawStyle = DrawStyle;
  25289. exports.DrawTextureCmd = DrawTextureCmd;
  25290. exports.DrawTexturesCmd = DrawTexturesCmd;
  25291. exports.DrawTrianglesCmd = DrawTrianglesCmd;
  25292. exports.Earcut = Earcut;
  25293. exports.EarcutNode = EarcutNode;
  25294. exports.Ease = Ease;
  25295. exports.EffectAnimation = EffectAnimation;
  25296. exports.EffectBase = EffectBase;
  25297. exports.Event = Event;
  25298. exports.EventDispatcher = EventDispatcher;
  25299. exports.FadeIn = FadeIn;
  25300. exports.FadeOut = FadeOut;
  25301. exports.FillTextCmd = FillTextCmd;
  25302. exports.FillTextureCmd = FillTextureCmd;
  25303. exports.Filter = Filter;
  25304. exports.FilterSetterBase = FilterSetterBase;
  25305. exports.FontInfo = FontInfo;
  25306. exports.FrameAnimation = FrameAnimation;
  25307. exports.GlowFilter = GlowFilter;
  25308. exports.GlowFilterGLRender = GlowFilterGLRender;
  25309. exports.GlowFilterSetter = GlowFilterSetter;
  25310. exports.GrahamScan = GrahamScan;
  25311. exports.GraphicAnimation = GraphicAnimation;
  25312. exports.Graphics = Graphics;
  25313. exports.GraphicsBounds = GraphicsBounds;
  25314. exports.HTMLCanvas = HTMLCanvas;
  25315. exports.HTMLChar = HTMLChar;
  25316. exports.HTMLImage = HTMLImage;
  25317. exports.Handler = Handler;
  25318. exports.HitArea = HitArea;
  25319. exports.HttpRequest = HttpRequest;
  25320. exports.ICharRender = ICharRender;
  25321. exports.ILaya = ILaya;
  25322. exports.IStatRender = IStatRender;
  25323. exports.IndexBuffer2D = IndexBuffer2D;
  25324. exports.InlcudeFile = InlcudeFile;
  25325. exports.Input = Input;
  25326. exports.KeyBoardManager = KeyBoardManager;
  25327. exports.KeyLocation = KeyLocation;
  25328. exports.Keyboard = Keyboard;
  25329. exports.Laya = Laya;
  25330. exports.LayaGL = LayaGL;
  25331. exports.LayaGLQuickRunner = LayaGLQuickRunner;
  25332. exports.LayaGLRunner = LayaGLRunner;
  25333. exports.LayaGPU = LayaGPU;
  25334. exports.Loader = Loader;
  25335. exports.LoaderManager = LoaderManager;
  25336. exports.LocalStorage = LocalStorage;
  25337. exports.Log = Log;
  25338. exports.MathUtil = MathUtil;
  25339. exports.MatirxArray = MatirxArray;
  25340. exports.Matrix = Matrix;
  25341. exports.Mesh2D = Mesh2D;
  25342. exports.MeshParticle2D = MeshParticle2D;
  25343. exports.MeshQuadTexture = MeshQuadTexture;
  25344. exports.MeshTexture = MeshTexture;
  25345. exports.MeshVG = MeshVG;
  25346. exports.Mouse = Mouse;
  25347. exports.MouseManager = MouseManager;
  25348. exports.Node = Node;
  25349. exports.Path = Path;
  25350. exports.PerfData = PerfData;
  25351. exports.PerfHUD = PerfHUD;
  25352. exports.Point = Point;
  25353. exports.Pool = Pool;
  25354. exports.PoolCache = PoolCache;
  25355. exports.Prefab = Prefab;
  25356. exports.PrimitiveSV = PrimitiveSV;
  25357. exports.QuickTestTool = QuickTestTool;
  25358. exports.Rectangle = Rectangle;
  25359. exports.Render = Render;
  25360. exports.RenderInfo = RenderInfo;
  25361. exports.RenderSprite = RenderSprite;
  25362. exports.RenderState2D = RenderState2D;
  25363. exports.RenderTexture2D = RenderTexture2D;
  25364. exports.Resource = Resource;
  25365. exports.ResourceVersion = ResourceVersion;
  25366. exports.RestoreCmd = RestoreCmd;
  25367. exports.RotateCmd = RotateCmd;
  25368. exports.RunDriver = RunDriver;
  25369. exports.SaveBase = SaveBase;
  25370. exports.SaveClipRect = SaveClipRect;
  25371. exports.SaveCmd = SaveCmd;
  25372. exports.SaveMark = SaveMark;
  25373. exports.SaveTransform = SaveTransform;
  25374. exports.SaveTranslate = SaveTranslate;
  25375. exports.ScaleCmd = ScaleCmd;
  25376. exports.Scene = Scene;
  25377. exports.SceneLoader = SceneLoader;
  25378. exports.SceneUtils = SceneUtils;
  25379. exports.Script = Script;
  25380. exports.Shader = Shader;
  25381. exports.Shader2D = Shader2D;
  25382. exports.Shader2X = Shader2X;
  25383. exports.ShaderCompile = ShaderCompile;
  25384. exports.ShaderDefines2D = ShaderDefines2D;
  25385. exports.ShaderDefinesBase = ShaderDefinesBase;
  25386. exports.ShaderNode = ShaderNode;
  25387. exports.ShaderValue = ShaderValue;
  25388. exports.SkinMeshBuffer = SkinMeshBuffer;
  25389. exports.SkinSV = SkinSV;
  25390. exports.Socket = Socket;
  25391. exports.Sound = Sound;
  25392. exports.SoundChannel = SoundChannel;
  25393. exports.SoundManager = SoundManager;
  25394. exports.SoundNode = SoundNode;
  25395. exports.Sprite = Sprite;
  25396. exports.SpriteConst = SpriteConst;
  25397. exports.SpriteStyle = SpriteStyle;
  25398. exports.Stage = Stage;
  25399. exports.Stat = Stat;
  25400. exports.StatUI = StatUI;
  25401. exports.StringKey = StringKey;
  25402. exports.Submit = Submit;
  25403. exports.SubmitBase = SubmitBase;
  25404. exports.SubmitCMD = SubmitCMD;
  25405. exports.SubmitCanvas = SubmitCanvas;
  25406. exports.SubmitKey = SubmitKey;
  25407. exports.SubmitTarget = SubmitTarget;
  25408. exports.SubmitTexture = SubmitTexture;
  25409. exports.System = System;
  25410. exports.TTFLoader = TTFLoader;
  25411. exports.Text = Text;
  25412. exports.TextAtlas = TextAtlas;
  25413. exports.TextRender = TextRender;
  25414. exports.TextStyle = TextStyle;
  25415. exports.TextTexture = TextTexture;
  25416. exports.Texture = Texture;
  25417. exports.Texture2D = Texture2D;
  25418. exports.TextureSV = TextureSV;
  25419. exports.TimeLine = TimeLine;
  25420. exports.Timer = Timer;
  25421. exports.TouchManager = TouchManager;
  25422. exports.TransformCmd = TransformCmd;
  25423. exports.TranslateCmd = TranslateCmd;
  25424. exports.Tween = Tween;
  25425. exports.URL = URL;
  25426. exports.Utils = Utils;
  25427. exports.Value2D = Value2D;
  25428. exports.VectorGraphManager = VectorGraphManager;
  25429. exports.VertexArrayObject = VertexArrayObject;
  25430. exports.VertexBuffer2D = VertexBuffer2D;
  25431. exports.WeakObject = WeakObject;
  25432. exports.WebAudioSound = WebAudioSound;
  25433. exports.WebAudioSoundChannel = WebAudioSoundChannel;
  25434. exports.WebGL = WebGL;
  25435. exports.WebGLCacheAsNormalCanvas = WebGLCacheAsNormalCanvas;
  25436. exports.WebGLContext = WebGLContext;
  25437. exports.WebGLRTMgr = WebGLRTMgr;
  25438. exports.WordText = WordText;
  25439. exports.WorkerLoader = WorkerLoader;
  25440. exports.__init = __init;
  25441. exports._static = _static;
  25442. exports.alertGlobalError = alertGlobalError;
  25443. exports.enableDebugPanel = enableDebugPanel;
  25444. exports.init = init;
  25445. exports.isWXOpenDataContext = isWXOpenDataContext;
  25446. exports.isWXPosMsg = isWXPosMsg;
  25447. exports.version = version;
  25448. exports.static=_static;
  25449. return exports;
  25450. }({}));