babylon.canvas2d.js 813 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488
  1. BABYLON.Effect.ShadersStore['ellipse2dPixelShader'] = "varying vec4 vColor;\nvoid main(void) {\ngl_FragColor=vColor;\n}";
  2. BABYLON.Effect.ShadersStore['ellipse2dVertexShader'] = "\n#ifdef Instanced\n#define att attribute\n#else\n#define att uniform\n#endif\nattribute float index;\natt vec2 zBias;\natt vec4 transformX;\natt vec4 transformY;\natt float opacity;\n#ifdef Border\natt float borderThickness;\n#endif\n#ifdef FillSolid\natt vec4 fillSolidColor;\n#endif\n#ifdef BorderSolid\natt vec4 borderSolidColor;\n#endif\n#ifdef FillGradient\natt vec4 fillGradientColor1;\natt vec4 fillGradientColor2;\natt vec4 fillGradientTY;\n#endif\n#ifdef BorderGradient\natt vec4 borderGradientColor1;\natt vec4 borderGradientColor2;\natt vec4 borderGradientTY;\n#endif\n\natt vec3 properties;\n#define TWOPI 6.28318530\n\nvarying vec2 vUV;\nvarying vec4 vColor;\nvoid main(void) {\nvec2 pos2;\n#ifdef Border\nfloat w=properties.x;\nfloat h=properties.y;\nfloat ms=properties.z;\nvec2 borderOffset=vec2(1.0,1.0);\nfloat segi=index;\nif (index<ms) {\nborderOffset=vec2(1.0-(borderThickness*2.0/w),1.0-(borderThickness*2.0/h));\n}\nelse {\nsegi-=ms;\n}\nfloat angle=TWOPI*segi/ms;\npos2.x=(cos(angle)/2.0)+0.5;\npos2.y=(sin(angle)/2.0)+0.5;\npos2.x=((pos2.x-0.5)*borderOffset.x)+0.5;\npos2.y=((pos2.y-0.5)*borderOffset.y)+0.5;\n#else\nif (index == 0.0) {\npos2=vec2(0.5,0.5);\n}\nelse {\nfloat ms=properties.z;\nfloat angle=TWOPI*(index-1.0)/ms;\npos2.x=(cos(angle)/2.0)+0.5;\npos2.y=(sin(angle)/2.0)+0.5;\n}\n#endif\n#ifdef FillSolid\nvColor=fillSolidColor;\n#endif\n#ifdef BorderSolid\nvColor=borderSolidColor;\n#endif\n#ifdef FillGradient\nfloat v=dot(vec4(pos2.xy,1,1),fillGradientTY);\nvColor=mix(fillGradientColor2,fillGradientColor1,v); \n#endif\n#ifdef BorderGradient\nfloat v=dot(vec4(pos2.xy,1,1),borderGradientTY);\nvColor=mix(borderGradientColor2,borderGradientColor1,v); \n#endif\nvColor.a*=opacity;\nvec4 pos;\npos.xy=pos2.xy*properties.xy;\npos.z=1.0;\npos.w=1.0;\ngl_Position=vec4(dot(pos,transformX),dot(pos,transformY),zBias.x,1);\n}";
  3. BABYLON.Effect.ShadersStore['lines2dPixelShader'] = "varying vec4 vColor;\nvoid main(void) {\ngl_FragColor=vColor;\n}";
  4. BABYLON.Effect.ShadersStore['lines2dVertexShader'] = "\n#ifdef Instanced\n#define att attribute\n#else\n#define att uniform\n#endif\nattribute vec2 position;\natt vec2 zBias;\natt vec4 transformX;\natt vec4 transformY;\natt float opacity;\n#ifdef FillSolid\natt vec4 fillSolidColor;\n#endif\n#ifdef BorderSolid\natt vec4 borderSolidColor;\n#endif\n#ifdef FillGradient\natt vec2 boundingMin;\natt vec2 boundingMax;\natt vec4 fillGradientColor1;\natt vec4 fillGradientColor2;\natt vec4 fillGradientTY;\n#endif\n#ifdef BorderGradient\natt vec4 borderGradientColor1;\natt vec4 borderGradientColor2;\natt vec4 borderGradientTY;\n#endif\n#define TWOPI 6.28318530\n\nvarying vec2 vUV;\nvarying vec4 vColor;\nvoid main(void) {\n#ifdef FillSolid\nvColor=fillSolidColor;\n#endif\n#ifdef BorderSolid\nvColor=borderSolidColor;\n#endif\n#ifdef FillGradient\nfloat v=dot(vec4((position.xy-boundingMin)/(boundingMax-boundingMin),1,1),fillGradientTY);\nvColor=mix(fillGradientColor2,fillGradientColor1,v); \n#endif\n#ifdef BorderGradient\nfloat v=dot(vec4((position.xy-boundingMin)/(boundingMax-boundingMin),1,1),borderGradientTY);\nvColor=mix(borderGradientColor2,borderGradientColor1,v); \n#endif\nvColor.a*=opacity;\nvec4 pos;\npos.xy=position.xy;\npos.z=1.0;\npos.w=1.0;\ngl_Position=vec4(dot(pos,transformX),dot(pos,transformY),zBias.x,1);\n}";
  5. BABYLON.Effect.ShadersStore['rect2dPixelShader'] = "varying vec4 vColor;\nvoid main(void) {\ngl_FragColor=vColor;\n}";
  6. BABYLON.Effect.ShadersStore['rect2dVertexShader'] = "\n#ifdef Instanced\n#define att attribute\n#else\n#define att uniform\n#endif\nattribute float index;\natt vec2 zBias;\natt vec4 transformX;\natt vec4 transformY;\natt float opacity;\n#ifdef Border\natt float borderThickness;\n#endif\n#ifdef FillSolid\natt vec4 fillSolidColor;\n#endif\n#ifdef BorderSolid\natt vec4 borderSolidColor;\n#endif\n#ifdef FillGradient\natt vec4 fillGradientColor1;\natt vec4 fillGradientColor2;\natt vec4 fillGradientTY;\n#endif\n#ifdef BorderGradient\natt vec4 borderGradientColor1;\natt vec4 borderGradientColor2;\natt vec4 borderGradientTY;\n#endif\n\natt vec3 properties;\n\n#define rsub0 17.0\n#define rsub1 33.0\n#define rsub2 49.0\n#define rsub3 65.0\n#define rsub 64.0\n#define TWOPI 6.28318530\n\nvarying vec2 vUV;\nvarying vec4 vColor;\nvoid main(void) {\nvec2 pos2;\n\nif (properties.z == 0.0) {\n#ifdef Border\nfloat w=properties.x;\nfloat h=properties.y;\nvec2 borderOffset=vec2(1.0,1.0);\nfloat segi=index;\nif (index<4.0) {\nborderOffset=vec2(1.0-(borderThickness*2.0/w),1.0-(borderThickness*2.0/h));\n}\nelse {\nsegi-=4.0;\n}\nif (segi == 0.0) {\npos2=vec2(1.0,1.0);\n} \nelse if (segi == 1.0) {\npos2=vec2(1.0,0.0);\n}\nelse if (segi == 2.0) {\npos2=vec2(0.0,0.0);\n} \nelse {\npos2=vec2(0.0,1.0);\n}\npos2.x=((pos2.x-0.5)*borderOffset.x)+0.5;\npos2.y=((pos2.y-0.5)*borderOffset.y)+0.5;\n#else\nif (index == 0.0) {\npos2=vec2(0.5,0.5);\n}\nelse if (index == 1.0) {\npos2=vec2(1.0,1.0);\n}\nelse if (index == 2.0) {\npos2=vec2(1.0,0.0);\n}\nelse if (index == 3.0) {\npos2=vec2(0.0,0.0);\n}\nelse {\npos2=vec2(0.0,1.0);\n}\n#endif\n}\nelse\n{\n#ifdef Border\nfloat w=properties.x;\nfloat h=properties.y;\nfloat r=properties.z;\nfloat nru=r/w;\nfloat nrv=r/h;\nvec2 borderOffset=vec2(1.0,1.0);\nfloat segi=index;\nif (index<rsub) {\nborderOffset=vec2(1.0-(borderThickness*2.0/w),1.0-(borderThickness*2.0/h));\n}\nelse {\nsegi-=rsub;\n}\n\nif (segi<rsub0) {\npos2=vec2(1.0-nru,nrv);\n}\n\nelse if (segi<rsub1) {\npos2=vec2(nru,nrv);\n}\n\nelse if (segi<rsub2) {\npos2=vec2(nru,1.0-nrv);\n}\n\nelse {\npos2=vec2(1.0-nru,1.0-nrv);\n}\nfloat angle=TWOPI-((index-1.0)*TWOPI/(rsub-0.5));\npos2.x+=cos(angle)*nru;\npos2.y+=sin(angle)*nrv;\npos2.x=((pos2.x-0.5)*borderOffset.x)+0.5;\npos2.y=((pos2.y-0.5)*borderOffset.y)+0.5;\n#else\nif (index == 0.0) {\npos2=vec2(0.5,0.5);\n}\nelse {\nfloat w=properties.x;\nfloat h=properties.y;\nfloat r=properties.z;\nfloat nru=r/w;\nfloat nrv=r/h;\n\nif (index<rsub0) {\npos2=vec2(1.0-nru,nrv);\n}\n\nelse if (index<rsub1) {\npos2=vec2(nru,nrv);\n}\n\nelse if (index<rsub2) {\npos2=vec2(nru,1.0-nrv);\n}\n\nelse {\npos2=vec2(1.0-nru,1.0-nrv);\n}\nfloat angle=TWOPI-((index-1.0)*TWOPI/(rsub-0.5));\npos2.x+=cos(angle)*nru;\npos2.y+=sin(angle)*nrv;\n}\n#endif\n}\n#ifdef FillSolid\nvColor=fillSolidColor;\n#endif\n#ifdef BorderSolid\nvColor=borderSolidColor;\n#endif\n#ifdef FillGradient\nfloat v=dot(vec4(pos2.xy,1,1),fillGradientTY);\nvColor=mix(fillGradientColor2,fillGradientColor1,v); \n#endif\n#ifdef BorderGradient\nfloat v=dot(vec4(pos2.xy,1,1),borderGradientTY);\nvColor=mix(borderGradientColor2,borderGradientColor1,v); \n#endif\nvColor.a*=opacity;\nvec4 pos;\npos.xy=pos2.xy*properties.xy;\npos.z=1.0;\npos.w=1.0;\ngl_Position=vec4(dot(pos,transformX),dot(pos,transformY),zBias.x,1);\n}";
  7. BABYLON.Effect.ShadersStore['sprite2dPixelShader'] = "varying vec2 vUV;\nvarying float vOpacity;\n#ifdef Scale9\nvarying vec2 vTopLeftUV;\nvarying vec2 vBottomRightUV;\nvarying vec4 vScale9;\nvarying vec2 vScaleFactor;\n#endif\nuniform bool alphaTest;\nuniform sampler2D diffuseSampler;\nvoid main(void) {\nvec2 uv=vUV;\n#ifdef Scale9\nvec2 sizeUV=vBottomRightUV-vTopLeftUV;\n\nfloat leftPartUV=vTopLeftUV.x+(vScale9.x/vScaleFactor.x);\nfloat rightPartUV=vTopLeftUV.x+sizeUV.x-((sizeUV.x-vScale9.z)/vScaleFactor.x);\nif (vUV.x<leftPartUV) {\nuv.x=vTopLeftUV.x+((vUV.x- vTopLeftUV.x)*vScaleFactor.x);\n}\nelse if (vUV.x>rightPartUV) {\nuv.x=vTopLeftUV.x+vScale9.z+((vUV.x-rightPartUV)*vScaleFactor.x);\n}\nelse {\nfloat r=(vUV.x-leftPartUV)/(rightPartUV-leftPartUV);\nuv.x=vTopLeftUV.x+vScale9.x+((vScale9.z-vScale9.x)*r);\n}\n\nfloat topPartUV=(vTopLeftUV.y+(vScale9.y/vScaleFactor.y));\nfloat bottomPartUV=(vTopLeftUV.y+sizeUV.y-((sizeUV.y-vScale9.w)/vScaleFactor.y));\nif (vUV.y<topPartUV) {\nuv.y=vTopLeftUV.y+((vUV.y-vTopLeftUV.y)*vScaleFactor.y);\n}\nelse if (vUV.y>bottomPartUV) {\nuv.y=vTopLeftUV.y+vScale9.w+((vUV.y-bottomPartUV)*vScaleFactor.y);\n}\nelse {\nfloat r=(vUV.y-topPartUV)/(bottomPartUV-topPartUV);\nuv.y=vTopLeftUV.y+vScale9.y+((vScale9.w-vScale9.y)*r);\n}\n#endif\nvec4 color=texture2D(diffuseSampler,uv);\nif (alphaTest)\n{\nif (color.a<0.95) {\ndiscard;\n}\n}\ncolor.a*=vOpacity;\ngl_FragColor=color;\n}";
  8. BABYLON.Effect.ShadersStore['sprite2dVertexShader'] = "\n#ifdef Instanced\n#define att attribute\n#else\n#define att uniform\n#endif\n\nattribute float index;\natt vec2 topLeftUV;\natt vec2 sizeUV;\n#ifdef Scale9\natt vec2 scaleFactor;\n#endif\natt vec2 textureSize;\n\natt vec3 properties;\n#ifdef Scale9\natt vec4 scale9;\n#endif\natt vec2 zBias;\natt vec4 transformX;\natt vec4 transformY;\natt float opacity;\n\n\nvarying vec2 vUV;\nvarying float vOpacity;\n#ifdef Scale9\nvarying vec2 vTopLeftUV;\nvarying vec2 vBottomRightUV;\nvarying vec4 vScale9;\nvarying vec2 vScaleFactor;\n#endif\nvoid main(void) {\nvec2 pos2;\nfloat frame=properties.x;\nfloat invertY=properties.y;\nfloat alignToPixel=properties.z;\n\nif (index == 0.0) {\npos2=vec2(0.0,0.0);\nvUV=vec2(topLeftUV.x+(frame*sizeUV.x),topLeftUV.y);\n}\n\nelse if (index == 1.0) {\npos2=vec2(0.0,1.0);\nvUV=vec2(topLeftUV.x+(frame*sizeUV.x),(topLeftUV.y+sizeUV.y));\n}\n\nelse if (index == 2.0) {\npos2=vec2( 1.0,1.0);\nvUV=vec2(topLeftUV.x+sizeUV.x+(frame*sizeUV.x),(topLeftUV.y+sizeUV.y));\n}\n\nelse if (index == 3.0) {\npos2=vec2( 1.0,0.0);\nvUV=vec2(topLeftUV.x+sizeUV.x+(frame*sizeUV.x),topLeftUV.y);\n}\nif (invertY == 1.0) {\nvUV.y=1.0-vUV.y;\n}\nvec4 pos;\nif (alignToPixel == 1.0)\n{\npos.xy=floor(pos2.xy*sizeUV*textureSize);\n} else {\npos.xy=pos2.xy*sizeUV*textureSize;\n}\n#ifdef Scale9\nif (invertY == 1.0) {\nvTopLeftUV=vec2(topLeftUV.x,1.0-(topLeftUV.y+sizeUV.y));\nvBottomRightUV=vec2(topLeftUV.x+sizeUV.x,1.0-topLeftUV.y);\nvScale9=vec4(scale9.x,sizeUV.y-scale9.w,scale9.z,sizeUV.y-scale9.y);\n}\nelse {\nvTopLeftUV=topLeftUV;\nvBottomRightUV=vec2(topLeftUV.x,topLeftUV.y+sizeUV.y);\nvScale9=scale9;\n}\nvScaleFactor=scaleFactor;\n#endif\nvOpacity=opacity;\npos.z=1.0;\npos.w=1.0;\ngl_Position=vec4(dot(pos,transformX),dot(pos,transformY),zBias.x,1);\n} ";
  9. BABYLON.Effect.ShadersStore['text2dPixelShader'] = "\nvarying vec4 vColor;\nvarying vec2 vUV;\n\nuniform sampler2D diffuseSampler;\nvoid main(void) {\n#ifdef SignedDistanceField\nfloat dist=texture2D(diffuseSampler,vUV).r;\nif (dist<0.5) {\ndiscard;\n}\n\n\n\n\n\ngl_FragColor=vec4(vColor.xyz*dist,1.0);\n#else\nvec4 color=texture2D(diffuseSampler,vUV);\ngl_FragColor=color*vColor;\n#endif\n}";
  10. BABYLON.Effect.ShadersStore['text2dVertexShader'] = "\n#ifdef Instanced\n#define att attribute\n#else\n#define att uniform\n#endif\n\nattribute float index;\natt vec2 zBias;\natt vec4 transformX;\natt vec4 transformY;\natt float opacity;\natt vec2 topLeftUV;\natt vec2 sizeUV;\natt vec2 textureSize;\natt vec4 color;\natt float superSampleFactor;\n\nvarying vec2 vUV;\nvarying vec4 vColor;\nvoid main(void) {\nvec2 pos2;\n\nif (index == 0.0) {\npos2=vec2(0.0,0.0);\nvUV=vec2(topLeftUV.x,topLeftUV.y+sizeUV.y);\n}\n\nelse if (index == 1.0) {\npos2=vec2(0.0,1.0);\nvUV=vec2(topLeftUV.x,topLeftUV.y);\n}\n\nelse if (index == 2.0) {\npos2=vec2(1.0,1.0);\nvUV=vec2(topLeftUV.x+sizeUV.x,topLeftUV.y);\n}\n\nelse if (index == 3.0) {\npos2=vec2(1.0,0.0);\nvUV=vec2(topLeftUV.x+sizeUV.x,topLeftUV.y+sizeUV.y);\n}\n\nvUV=(floor(vUV*textureSize)+vec2(0.0,0.0))/textureSize;\nvColor=color;\nvColor.a*=opacity;\nvec4 pos;\npos.xy=floor(pos2.xy*superSampleFactor*sizeUV*textureSize); \npos.z=1.0;\npos.w=1.0;\ngl_Position=vec4(dot(pos,transformX),dot(pos,transformY),zBias.x,1);\n}";
  11. var BABYLON;
  12. (function (BABYLON) {
  13. var PropertyChangedInfo = (function () {
  14. function PropertyChangedInfo() {
  15. }
  16. return PropertyChangedInfo;
  17. }());
  18. BABYLON.PropertyChangedInfo = PropertyChangedInfo;
  19. /**
  20. * The purpose of this class is to provide a base implementation of the IPropertyChanged interface for the user to avoid rewriting a code needlessly.
  21. * Typical use of this class is to check for equality in a property set(), then call the onPropertyChanged method if values are different after the new value is set. The protected method will notify observers of the change.
  22. * Remark: onPropertyChanged detects reentrant code and acts in a way to make sure everything is fine, fast and allocation friendly (when there no reentrant code which should be 99% of the time)
  23. */
  24. var PropertyChangedBase = (function () {
  25. function PropertyChangedBase() {
  26. this._propertyChanged = null;
  27. }
  28. /**
  29. * Protected method to call when there's a change of value in a property set
  30. * @param propName the name of the concerned property
  31. * @param oldValue its old value
  32. * @param newValue its new value
  33. * @param mask an optional observable mask
  34. */
  35. PropertyChangedBase.prototype.onPropertyChanged = function (propName, oldValue, newValue, mask) {
  36. if (this.propertyChanged.hasObservers()) {
  37. var pci = PropertyChangedBase.calling ? new PropertyChangedInfo() : PropertyChangedBase.pci;
  38. pci.oldValue = oldValue;
  39. pci.newValue = newValue;
  40. pci.propertyName = propName;
  41. try {
  42. PropertyChangedBase.calling = true;
  43. this.propertyChanged.notifyObservers(pci, mask);
  44. }
  45. finally {
  46. PropertyChangedBase.calling = false;
  47. }
  48. }
  49. };
  50. Object.defineProperty(PropertyChangedBase.prototype, "propertyChanged", {
  51. /**
  52. * An observable that is triggered when a property (using of the XXXXLevelProperty decorator) has its value changing.
  53. * You can add an observer that will be triggered only for a given set of Properties using the Mask feature of the Observable and the corresponding Prim2DPropInfo.flagid value (e.g. Prim2DBase.positionProperty.flagid|Prim2DBase.rotationProperty.flagid to be notified only about position or rotation change)
  54. */
  55. get: function () {
  56. if (!this._propertyChanged) {
  57. this._propertyChanged = new BABYLON.Observable();
  58. }
  59. return this._propertyChanged;
  60. },
  61. enumerable: true,
  62. configurable: true
  63. });
  64. return PropertyChangedBase;
  65. }());
  66. PropertyChangedBase.pci = new PropertyChangedInfo();
  67. PropertyChangedBase.calling = false;
  68. BABYLON.PropertyChangedBase = PropertyChangedBase;
  69. })(BABYLON || (BABYLON = {}));
  70. //# sourceMappingURL=babylon.IPropertyChanged.js.map
  71. var __extends = (this && this.__extends) || function (d, b) {
  72. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  73. function __() { this.constructor = d; }
  74. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  75. };
  76. var BABYLON;
  77. (function (BABYLON) {
  78. /**
  79. * Class for the ObservableArray.onArrayChanged observable
  80. */
  81. var ArrayChanged = (function () {
  82. function ArrayChanged() {
  83. this.action = 0;
  84. this.newItems = new Array();
  85. this.removedItems = new Array();
  86. this.changedItems = new Array();
  87. this.newStartingIndex = -1;
  88. this.removedStartingIndex = -1;
  89. }
  90. Object.defineProperty(ArrayChanged, "clearAction", {
  91. /**
  92. * The content of the array was totally cleared
  93. */
  94. get: function () {
  95. return ArrayChanged._clearAction;
  96. },
  97. enumerable: true,
  98. configurable: true
  99. });
  100. Object.defineProperty(ArrayChanged, "newItemsAction", {
  101. /**
  102. * A new item was added, the newItems field contains the key/value pairs
  103. */
  104. get: function () {
  105. return ArrayChanged._newItemsAction;
  106. },
  107. enumerable: true,
  108. configurable: true
  109. });
  110. Object.defineProperty(ArrayChanged, "removedItemsAction", {
  111. /**
  112. * An existing item was removed, the removedKey field contains its key
  113. */
  114. get: function () {
  115. return ArrayChanged._removedItemsAction;
  116. },
  117. enumerable: true,
  118. configurable: true
  119. });
  120. Object.defineProperty(ArrayChanged, "changedItemAction", {
  121. /**
  122. * One or many items in the array were changed, the
  123. */
  124. get: function () {
  125. return ArrayChanged._changedItemAction;
  126. },
  127. enumerable: true,
  128. configurable: true
  129. });
  130. Object.defineProperty(ArrayChanged, "replacedArrayAction", {
  131. /**
  132. * The array's content was totally changed
  133. * Depending on the method that used this mode the ChangedArray object may contains more information
  134. */
  135. get: function () {
  136. return ArrayChanged._replacedArrayAction;
  137. },
  138. enumerable: true,
  139. configurable: true
  140. });
  141. Object.defineProperty(ArrayChanged, "lengthChangedAction", {
  142. /**
  143. * The length of the array changed
  144. */
  145. get: function () {
  146. return ArrayChanged._lengthChangedAction;
  147. },
  148. enumerable: true,
  149. configurable: true
  150. });
  151. ArrayChanged.prototype.clear = function () {
  152. this.action = 0;
  153. this.newItems.splice(0);
  154. this.removedItems.splice(0);
  155. this.changedItems.splice(0);
  156. this.removedStartingIndex = this.removedStartingIndex = this.changedStartingIndex = 0;
  157. };
  158. return ArrayChanged;
  159. }());
  160. ArrayChanged._clearAction = 0x1;
  161. ArrayChanged._newItemsAction = 0x2;
  162. ArrayChanged._removedItemsAction = 0x4;
  163. ArrayChanged._replacedArrayAction = 0x8;
  164. ArrayChanged._lengthChangedAction = 0x10;
  165. ArrayChanged._changedItemAction = 0x20;
  166. BABYLON.ArrayChanged = ArrayChanged;
  167. var OAWatchedObjectChangedInfo = (function () {
  168. function OAWatchedObjectChangedInfo() {
  169. }
  170. return OAWatchedObjectChangedInfo;
  171. }());
  172. BABYLON.OAWatchedObjectChangedInfo = OAWatchedObjectChangedInfo;
  173. /**
  174. * This class mimics the Javascript Array and TypeScript Array<T> classes, adding new features concerning the Observable pattern.
  175. *
  176. */
  177. var ObservableArray = (function (_super) {
  178. __extends(ObservableArray, _super);
  179. /**
  180. * Create an Observable Array.
  181. * @param watchObjectsPropertyChange
  182. * @param array and optional array that will be encapsulated by this ObservableArray instance. That's right, it's NOT a copy!
  183. */
  184. function ObservableArray(watchObjectsPropertyChange, array) {
  185. var _this = _super.call(this) || this;
  186. _this.dci = new ArrayChanged();
  187. _this._callingArrayChanged = false;
  188. _this._array = (array != null) ? array : new Array();
  189. _this.dci = new ArrayChanged();
  190. _this._callingArrayChanged = false;
  191. _this._arrayChanged = null;
  192. _this._callingWatchedObjectChanged = false;
  193. _this._watchObjectsPropertyChange = watchObjectsPropertyChange;
  194. _this._watchedObjectList = _this._watchObjectsPropertyChange ? new BABYLON.StringDictionary() : null;
  195. _this._woci = new OAWatchedObjectChangedInfo();
  196. return _this;
  197. }
  198. Object.defineProperty(ObservableArray.prototype, "length", {
  199. /**
  200. * Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.
  201. */
  202. get: function () {
  203. return this._array.length;
  204. },
  205. set: function (value) {
  206. if (value === this._array.length) {
  207. return;
  208. }
  209. var oldLength = this._array.length;
  210. this._array.length = value;
  211. this.onPropertyChanged("length", oldLength, this._array.length);
  212. },
  213. enumerable: true,
  214. configurable: true
  215. });
  216. ObservableArray.prototype.getAt = function (index) {
  217. return this._array[index];
  218. };
  219. ObservableArray.prototype.setAt = function (index, value) {
  220. if (index < 0) {
  221. return false;
  222. }
  223. var insertion = (index >= this._array.length) || this._array[index] === undefined;
  224. var oldLength = 0;
  225. if (insertion) {
  226. oldLength = this._array.length;
  227. }
  228. else if (this._watchObjectsPropertyChange) {
  229. this._removeWatchedElement(this._array[index]);
  230. }
  231. this._array[index] = value;
  232. if (this._watchObjectsPropertyChange) {
  233. this._addWatchedElement(value);
  234. }
  235. if (insertion) {
  236. this.onPropertyChanged("length", oldLength, this._array.length);
  237. }
  238. var ac = this.getArrayChangedObject();
  239. if (ac) {
  240. ac.action = insertion ? ArrayChanged.newItemsAction : ArrayChanged.changedItemAction;
  241. if (insertion) {
  242. ac.newItems.splice(0, ac.newItems.length, { index: index, value: value });
  243. ac.newStartingIndex = index;
  244. ac.changedItems.splice(0);
  245. }
  246. else {
  247. ac.newItems.splice(0);
  248. ac.changedStartingIndex = index;
  249. ac.changedItems.splice(0, ac.changedItems.length, { index: index, value: value });
  250. }
  251. ac.removedItems.splice(0);
  252. ac.removedStartingIndex = -1;
  253. this.callArrayChanged(ac);
  254. }
  255. };
  256. /**
  257. * Returns a string representation of an array.
  258. */
  259. ObservableArray.prototype.toString = function () {
  260. return this._array.toString();
  261. };
  262. ObservableArray.prototype.toLocaleString = function () {
  263. return this._array.toLocaleString();
  264. };
  265. /**
  266. * Appends new elements to an array, and returns the new length of the array.
  267. * @param items New elements of the Array.
  268. */
  269. ObservableArray.prototype.push = function () {
  270. var items = [];
  271. for (var _i = 0; _i < arguments.length; _i++) {
  272. items[_i] = arguments[_i];
  273. }
  274. var oldLength = this._array.length;
  275. var n = (_a = this._array).push.apply(_a, items);
  276. if (this._watchObjectsPropertyChange) {
  277. this._addWatchedElement.apply(this, items);
  278. }
  279. this.onPropertyChanged("length", oldLength, this._array.length);
  280. var ac = this.getArrayChangedObject();
  281. if (ac) {
  282. ac.action = ArrayChanged.newItemsAction;
  283. ac.newStartingIndex = oldLength;
  284. this.feedNotifArray.apply(this, [ac.newItems, oldLength].concat(items));
  285. this.callArrayChanged(ac);
  286. }
  287. return n;
  288. var _a;
  289. };
  290. /**
  291. * Removes the last element from an array and returns it.
  292. */
  293. ObservableArray.prototype.pop = function () {
  294. var firstRemove = this._array.length - 1;
  295. var res = this._array.pop();
  296. if (res && this._watchObjectsPropertyChange) {
  297. this._removeWatchedElement(res);
  298. }
  299. if (firstRemove !== -1) {
  300. this.onPropertyChanged("length", this._array.length + 1, this._array.length);
  301. var ac = this.getArrayChangedObject();
  302. if (ac) {
  303. ac.action = ArrayChanged.removedItemsAction;
  304. ac.removedStartingIndex = firstRemove;
  305. this.feedNotifArray(ac.removedItems, firstRemove, res);
  306. }
  307. }
  308. return res;
  309. };
  310. /**
  311. * Combines two or more arrays.
  312. * @param items Additional items to add to the end of array1.
  313. */
  314. ObservableArray.prototype.concat = function () {
  315. var items = [];
  316. for (var _i = 0; _i < arguments.length; _i++) {
  317. items[_i] = arguments[_i];
  318. }
  319. return new ObservableArray(this._watchObjectsPropertyChange, (_a = this._array).concat.apply(_a, items));
  320. var _a;
  321. };
  322. /**
  323. * Adds all the elements of an array separated by the specified separator string.
  324. * @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.
  325. */
  326. ObservableArray.prototype.join = function (separator) {
  327. return this._array.join(separator);
  328. };
  329. /**
  330. * Reverses the elements in an Array.
  331. * The arrayChanged action is
  332. */
  333. ObservableArray.prototype.reverse = function () {
  334. var res = this._array.reverse();
  335. var ac = this.getArrayChangedObject();
  336. ac.action = ArrayChanged.replacedArrayAction;
  337. return res;
  338. };
  339. /**
  340. * Removes the first element from an array and returns it, shift all subsequents element one element before.
  341. * The ArrayChange action is replacedArrayAction, the whole array changes and must be reevaluate as such, the removed element is in removedItems.
  342. *
  343. */
  344. ObservableArray.prototype.shift = function () {
  345. var oldLength = this._array.length;
  346. var res = this._array.shift();
  347. if (this._watchedObjectChanged && res != null) {
  348. this._removeWatchedElement(res);
  349. }
  350. if (oldLength !== 0) {
  351. this.onPropertyChanged("length", oldLength, this._array.length);
  352. var ac = this.getArrayChangedObject();
  353. if (ac) {
  354. ac.action = ArrayChanged.replacedArrayAction;
  355. ac.removedItems.splice(0, ac.removedItems.length, { index: 0, value: res });
  356. ac.newItems.splice(0);
  357. ac.changedItems.splice(0);
  358. ac.removedStartingIndex = 0;
  359. this.callArrayChanged(ac);
  360. }
  361. }
  362. return res;
  363. };
  364. /**
  365. * Returns a section of an array.
  366. * @param start The beginning of the specified portion of the array.
  367. * @param end The end of the specified portion of the array.
  368. */
  369. ObservableArray.prototype.slice = function (start, end) {
  370. return new ObservableArray(this._watchObjectsPropertyChange, this._array.slice(start, end));
  371. };
  372. /**
  373. * Sorts an array.
  374. * @param compareFn The name of the function used to determine the order of the elements. If omitted, the elements are sorted in ascending, ASCII character order.
  375. * On the contrary of the Javascript Array's implementation, this method returns nothing
  376. */
  377. ObservableArray.prototype.sort = function (compareFn) {
  378. var oldLength = this._array.length;
  379. this._array.sort(compareFn);
  380. if (oldLength !== 0) {
  381. var ac = this.getArrayChangedObject();
  382. if (ac) {
  383. ac.clear();
  384. ac.action = ArrayChanged.replacedArrayAction;
  385. this.callArrayChanged(ac);
  386. }
  387. }
  388. };
  389. /**
  390. * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
  391. * @param start The zero-based location in the array from which to start removing elements.
  392. * @param deleteCount The number of elements to remove.
  393. * @param items Elements to insert into the array in place of the deleted elements.
  394. */
  395. ObservableArray.prototype.splice = function (start, deleteCount) {
  396. var items = [];
  397. for (var _i = 2; _i < arguments.length; _i++) {
  398. items[_i - 2] = arguments[_i];
  399. }
  400. var oldLength = this._array.length;
  401. if (this._watchObjectsPropertyChange) {
  402. for (var i = start; i < start + deleteCount; i++) {
  403. var val = this._array[i];
  404. if (this._watchObjectsPropertyChange && val != null) {
  405. this._removeWatchedElement(val);
  406. }
  407. }
  408. }
  409. var res = (_a = this._array).splice.apply(_a, [start, deleteCount].concat(items));
  410. if (this._watchObjectsPropertyChange) {
  411. this._addWatchedElement.apply(this, items);
  412. }
  413. if (oldLength !== this._array.length) {
  414. this.onPropertyChanged("length", oldLength, this._array.length);
  415. }
  416. var ac = this.getArrayChangedObject();
  417. if (ac) {
  418. ac.clear();
  419. ac.action = ArrayChanged.replacedArrayAction;
  420. this.callArrayChanged(ac);
  421. }
  422. return res;
  423. var _a;
  424. };
  425. /**
  426. * Inserts new elements at the start of an array.
  427. * @param items Elements to insert at the start of the Array.
  428. * The ChangedArray action is replacedArrayAction, newItems contains the list of the added items
  429. */
  430. ObservableArray.prototype.unshift = function () {
  431. var items = [];
  432. for (var _i = 0; _i < arguments.length; _i++) {
  433. items[_i] = arguments[_i];
  434. }
  435. var oldLength = this._array.length;
  436. var res = (_a = this._array).unshift.apply(_a, items);
  437. if (this._watchObjectsPropertyChange) {
  438. this._addWatchedElement.apply(this, items);
  439. }
  440. this.onPropertyChanged("length", oldLength, this._array.length);
  441. var ac = this.getArrayChangedObject();
  442. if (ac) {
  443. ac.clear();
  444. ac.action = ArrayChanged.replacedArrayAction;
  445. ac.newStartingIndex = 0, this.feedNotifArray.apply(this, [ac.newItems, 0].concat(items));
  446. this.callArrayChanged(ac);
  447. }
  448. return res;
  449. var _a;
  450. };
  451. /**
  452. * Returns the index of the first occurrence of a value in an array.
  453. * @param searchElement The value to locate in the array.
  454. * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
  455. */
  456. ObservableArray.prototype.indexOf = function (searchElement, fromIndex) {
  457. return this._array.indexOf(searchElement, fromIndex);
  458. };
  459. /**
  460. * Returns the index of the last occurrence of a specified value in an array.
  461. * @param searchElement The value to locate in the array.
  462. * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array.
  463. */
  464. ObservableArray.prototype.lastIndexOf = function (searchElement, fromIndex) {
  465. return this._array.lastIndexOf(searchElement, fromIndex);
  466. };
  467. /**
  468. * Determines whether all the members of an array satisfy the specified test.
  469. * @param callbackfn A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array.
  470. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
  471. */
  472. ObservableArray.prototype.every = function (callbackfn, thisArg) {
  473. return this._array.every(callbackfn, thisArg);
  474. };
  475. /**
  476. * Determines whether the specified callback function returns true for any element of an array.
  477. * @param callbackfn A function that accepts up to three arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array.
  478. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
  479. */
  480. ObservableArray.prototype.some = function (callbackfn, thisArg) {
  481. return this._array.some(callbackfn, thisArg);
  482. };
  483. /**
  484. * Performs the specified action for each element in an array.
  485. * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
  486. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
  487. */
  488. ObservableArray.prototype.forEach = function (callbackfn, thisArg) {
  489. return this._array.forEach(callbackfn, thisArg);
  490. };
  491. /**
  492. * Calls a defined callback function on each element of an array, and returns an array that contains the results.
  493. * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
  494. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
  495. */
  496. ObservableArray.prototype.map = function (callbackfn, thisArg) {
  497. return this._array.map(callbackfn, thisArg);
  498. };
  499. /**
  500. * Returns the elements of an array that meet the condition specified in a callback function.
  501. * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.
  502. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
  503. */
  504. ObservableArray.prototype.filter = function (callbackfn, thisArg) {
  505. return this._array.filter(callbackfn, thisArg);
  506. };
  507. /**
  508. * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
  509. * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
  510. * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
  511. */
  512. ObservableArray.prototype.reduce = function (callbackfn, initialValue) {
  513. return this._array.reduce(callbackfn);
  514. };
  515. /**
  516. * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
  517. * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
  518. * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
  519. */
  520. ObservableArray.prototype.reduceRight = function (callbackfn, initialValue) {
  521. return this._array.reduceRight(callbackfn);
  522. };
  523. Object.defineProperty(ObservableArray.prototype, "arrayChanged", {
  524. get: function () {
  525. if (!this._arrayChanged) {
  526. this._arrayChanged = new BABYLON.Observable();
  527. }
  528. return this._arrayChanged;
  529. },
  530. enumerable: true,
  531. configurable: true
  532. });
  533. ObservableArray.prototype.getArrayChangedObject = function () {
  534. if (this._arrayChanged && this._arrayChanged.hasObservers()) {
  535. var ac = this._callingArrayChanged ? new ArrayChanged() : this.dci;
  536. return ac;
  537. }
  538. return null;
  539. };
  540. ObservableArray.prototype.feedNotifArray = function (array, startindIndex) {
  541. var items = [];
  542. for (var _i = 2; _i < arguments.length; _i++) {
  543. items[_i - 2] = arguments[_i];
  544. }
  545. array.splice(0);
  546. for (var i = 0; i < items.length; i++) {
  547. var value = this._array[i + startindIndex];
  548. if (value !== undefined) {
  549. array.push({ index: i + startindIndex, value: value });
  550. }
  551. }
  552. };
  553. ObservableArray.prototype.callArrayChanged = function (ac) {
  554. try {
  555. this._callingArrayChanged = true;
  556. this.arrayChanged.notifyObservers(ac, ac.action);
  557. }
  558. finally {
  559. this._callingArrayChanged = false;
  560. }
  561. };
  562. Object.defineProperty(ObservableArray.prototype, "watchedObjectChanged", {
  563. get: function () {
  564. if (!this._watchedObjectChanged) {
  565. this._watchedObjectChanged = new BABYLON.Observable();
  566. }
  567. return this._watchedObjectChanged;
  568. },
  569. enumerable: true,
  570. configurable: true
  571. });
  572. ObservableArray.prototype._addWatchedElement = function () {
  573. var _this = this;
  574. var items = [];
  575. for (var _i = 0; _i < arguments.length; _i++) {
  576. items[_i] = arguments[_i];
  577. }
  578. var _loop_1 = function (curItem) {
  579. if (curItem["propertyChanged"]) {
  580. var key_1 = curItem["__ObsArrayObjID__"];
  581. // The object may already be part of another ObsArray, so there already be a valid ID
  582. if (!key_1) {
  583. key_1 = BABYLON.Tools.RandomId();
  584. curItem["__ObsArrayObjID__"] = key_1;
  585. }
  586. this_1._watchedObjectList.add(key_1, curItem.propertyChanged.add(function (e, d) {
  587. _this.onWatchedObjectChanged(key_1, curItem, e);
  588. }));
  589. }
  590. };
  591. var this_1 = this;
  592. for (var _a = 0, items_1 = items; _a < items_1.length; _a++) {
  593. var curItem = items_1[_a];
  594. _loop_1(curItem);
  595. }
  596. };
  597. ObservableArray.prototype._removeWatchedElement = function () {
  598. var items = [];
  599. for (var _i = 0; _i < arguments.length; _i++) {
  600. items[_i] = arguments[_i];
  601. }
  602. for (var _a = 0, items_2 = items; _a < items_2.length; _a++) {
  603. var curItem = items_2[_a];
  604. var key = curItem["__ObsArrayObjID__"];
  605. if (key != null) {
  606. var observer = this._watchedObjectList.getAndRemove(key);
  607. curItem.propertyChanged.remove(observer);
  608. }
  609. }
  610. };
  611. ObservableArray.prototype.onWatchedObjectChanged = function (key, object, propChanged) {
  612. if (this._watchedObjectChanged && this._watchedObjectChanged.hasObservers()) {
  613. var woci = this._callingWatchedObjectChanged ? new OAWatchedObjectChangedInfo() : this._woci;
  614. woci.object = object;
  615. woci.propertyChanged = propChanged;
  616. try {
  617. this._callingWatchedObjectChanged = true;
  618. this.watchedObjectChanged.notifyObservers(woci);
  619. }
  620. finally {
  621. this._callingWatchedObjectChanged = false;
  622. }
  623. }
  624. };
  625. return ObservableArray;
  626. }(BABYLON.PropertyChangedBase));
  627. BABYLON.ObservableArray = ObservableArray;
  628. })(BABYLON || (BABYLON = {}));
  629. //# sourceMappingURL=babylon.observableArray.js.map
  630. var __extends = (this && this.__extends) || function (d, b) {
  631. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  632. function __() { this.constructor = d; }
  633. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  634. };
  635. var BABYLON;
  636. (function (BABYLON) {
  637. /**
  638. * Class for the ObservableStringDictionary.onDictionaryChanged observable
  639. */
  640. var DictionaryChanged = (function () {
  641. function DictionaryChanged() {
  642. }
  643. Object.defineProperty(DictionaryChanged, "clearAction", {
  644. /**
  645. * The content of the dictionary was totally cleared
  646. */
  647. get: function () {
  648. return DictionaryChanged._clearAction;
  649. },
  650. enumerable: true,
  651. configurable: true
  652. });
  653. Object.defineProperty(DictionaryChanged, "newItemAction", {
  654. /**
  655. * A new item was added, the newItem field contains the key/value pair
  656. */
  657. get: function () {
  658. return DictionaryChanged._newItemAction;
  659. },
  660. enumerable: true,
  661. configurable: true
  662. });
  663. Object.defineProperty(DictionaryChanged, "removedItemAction", {
  664. /**
  665. * An existing item was removed, the removedKey field contains its key
  666. */
  667. get: function () {
  668. return DictionaryChanged._removedItemAction;
  669. },
  670. enumerable: true,
  671. configurable: true
  672. });
  673. Object.defineProperty(DictionaryChanged, "itemValueChangedAction", {
  674. /**
  675. * An existing item had a value change, the changedItem field contains the key/value
  676. */
  677. get: function () {
  678. return DictionaryChanged._itemValueChangedAction;
  679. },
  680. enumerable: true,
  681. configurable: true
  682. });
  683. Object.defineProperty(DictionaryChanged, "replacedAction", {
  684. /**
  685. * The dictionary's content was reset and replaced by the content of another dictionary.
  686. * DictionaryChanged<T> contains no further information about this action
  687. */
  688. get: function () {
  689. return DictionaryChanged._replacedAction;
  690. },
  691. enumerable: true,
  692. configurable: true
  693. });
  694. return DictionaryChanged;
  695. }());
  696. DictionaryChanged._clearAction = 0x1;
  697. DictionaryChanged._newItemAction = 0x2;
  698. DictionaryChanged._removedItemAction = 0x4;
  699. DictionaryChanged._itemValueChangedAction = 0x8;
  700. DictionaryChanged._replacedAction = 0x10;
  701. BABYLON.DictionaryChanged = DictionaryChanged;
  702. var OSDWatchedObjectChangedInfo = (function () {
  703. function OSDWatchedObjectChangedInfo() {
  704. }
  705. return OSDWatchedObjectChangedInfo;
  706. }());
  707. BABYLON.OSDWatchedObjectChangedInfo = OSDWatchedObjectChangedInfo;
  708. var ObservableStringDictionary = (function (_super) {
  709. __extends(ObservableStringDictionary, _super);
  710. function ObservableStringDictionary(watchObjectsPropertyChange) {
  711. var _this = _super.call(this) || this;
  712. _this._propertyChanged = null;
  713. _this._dictionaryChanged = null;
  714. _this.dci = new DictionaryChanged();
  715. _this._callingDicChanged = false;
  716. _this._watchedObjectChanged = null;
  717. _this._callingWatchedObjectChanged = false;
  718. _this._woci = new OSDWatchedObjectChangedInfo();
  719. _this._watchObjectsPropertyChange = watchObjectsPropertyChange;
  720. _this._watchedObjectList = _this._watchObjectsPropertyChange ? new BABYLON.StringDictionary() : null;
  721. return _this;
  722. }
  723. /**
  724. * This will clear this dictionary and copy the content from the 'source' one.
  725. * If the T value is a custom object, it won't be copied/cloned, the same object will be used
  726. * @param source the dictionary to take the content from and copy to this dictionary
  727. */
  728. ObservableStringDictionary.prototype.copyFrom = function (source) {
  729. var _this = this;
  730. var oldCount = this.count;
  731. // Don't rely on this class' implementation for clear/add otherwise tons of notification will be thrown
  732. _super.prototype.clear.call(this);
  733. source.forEach(function (t, v) { return _this._add(t, v, false, _this._watchObjectsPropertyChange); });
  734. this.onDictionaryChanged(DictionaryChanged.replacedAction, null, null, null);
  735. this.onPropertyChanged("count", oldCount, this.count);
  736. };
  737. /**
  738. * Get a value from its key or add it if it doesn't exist.
  739. * This method will ensure you that a given key/data will be present in the dictionary.
  740. * @param key the given key to get the matching value from
  741. * @param factory the factory that will create the value if the key is not present in the dictionary.
  742. * The factory will only be invoked if there's no data for the given key.
  743. * @return the value corresponding to the key.
  744. */
  745. ObservableStringDictionary.prototype.getOrAddWithFactory = function (key, factory) {
  746. var _this = this;
  747. var val = _super.prototype.getOrAddWithFactory.call(this, key, function (k) {
  748. var v = factory(key);
  749. _this._add(key, v, true, _this._watchObjectsPropertyChange);
  750. return v;
  751. });
  752. return val;
  753. };
  754. /**
  755. * Add a new key and its corresponding value
  756. * @param key the key to add
  757. * @param value the value corresponding to the key
  758. * @return true if the operation completed successfully, false if we couldn't insert the key/value because there was already this key in the dictionary
  759. */
  760. ObservableStringDictionary.prototype.add = function (key, value) {
  761. return this._add(key, value, true, true);
  762. };
  763. ObservableStringDictionary.prototype.getAndRemove = function (key) {
  764. var val = _super.prototype.get.call(this, key);
  765. this._remove(key, true, val);
  766. return val;
  767. };
  768. ObservableStringDictionary.prototype._add = function (key, value, fireNotif, registerWatcher) {
  769. if (_super.prototype.add.call(this, key, value)) {
  770. if (fireNotif) {
  771. this.onDictionaryChanged(DictionaryChanged.newItemAction, { key: key, value: value }, null, null);
  772. this.onPropertyChanged("count", this.count - 1, this.count);
  773. }
  774. if (registerWatcher) {
  775. this._addWatchedElement(key, value);
  776. }
  777. return true;
  778. }
  779. return false;
  780. };
  781. ObservableStringDictionary.prototype._addWatchedElement = function (key, el) {
  782. var _this = this;
  783. if (el["propertyChanged"]) {
  784. this._watchedObjectList.add(key, el.propertyChanged.add(function (e, d) {
  785. _this.onWatchedObjectChanged(key, el, e);
  786. }));
  787. }
  788. };
  789. ObservableStringDictionary.prototype._removeWatchedElement = function (key, el) {
  790. var observer = this._watchedObjectList.getAndRemove(key);
  791. if (el["propertyChanged"]) {
  792. el.propertyChanged.remove(observer);
  793. }
  794. };
  795. ObservableStringDictionary.prototype.set = function (key, value) {
  796. var oldValue = this.get(key);
  797. if (this._watchObjectsPropertyChange) {
  798. this._removeWatchedElement(key, oldValue);
  799. }
  800. if (_super.prototype.set.call(this, key, value)) {
  801. this.onDictionaryChanged(DictionaryChanged.itemValueChangedAction, null, null, { key: key, oldValue: oldValue, newValue: value });
  802. this._addWatchedElement(key, value);
  803. return true;
  804. }
  805. return false;
  806. };
  807. /**
  808. * Remove a key/value from the dictionary.
  809. * @param key the key to remove
  810. * @return true if the item was successfully deleted, false if no item with such key exist in the dictionary
  811. */
  812. ObservableStringDictionary.prototype.remove = function (key) {
  813. return this._remove(key, true);
  814. };
  815. ObservableStringDictionary.prototype._remove = function (key, fireNotif, element) {
  816. if (!element) {
  817. element = this.get(key);
  818. }
  819. if (!element) {
  820. return false;
  821. }
  822. if (_super.prototype.remove.call(this, key) === undefined) {
  823. return false;
  824. }
  825. this.onDictionaryChanged(DictionaryChanged.removedItemAction, null, key, null);
  826. this.onPropertyChanged("count", this.count + 1, this.count);
  827. if (this._watchObjectsPropertyChange) {
  828. this._removeWatchedElement(key, element);
  829. }
  830. return true;
  831. };
  832. /**
  833. * Clear the whole content of the dictionary
  834. */
  835. ObservableStringDictionary.prototype.clear = function () {
  836. var _this = this;
  837. this._watchedObjectList.forEach(function (k, v) {
  838. var el = _this.get(k);
  839. _this._removeWatchedElement(k, el);
  840. });
  841. this._watchedObjectList.clear();
  842. var oldCount = this.count;
  843. _super.prototype.clear.call(this);
  844. this.onDictionaryChanged(DictionaryChanged.clearAction, null, null, null);
  845. this.onPropertyChanged("count", oldCount, 0);
  846. };
  847. Object.defineProperty(ObservableStringDictionary.prototype, "propertyChanged", {
  848. get: function () {
  849. if (!this._propertyChanged) {
  850. this._propertyChanged = new BABYLON.Observable();
  851. }
  852. return this._propertyChanged;
  853. },
  854. enumerable: true,
  855. configurable: true
  856. });
  857. ObservableStringDictionary.prototype.onPropertyChanged = function (propName, oldValue, newValue, mask) {
  858. if (this._propertyChanged && this._propertyChanged.hasObservers()) {
  859. var pci = ObservableStringDictionary.callingPropChanged ? new BABYLON.PropertyChangedInfo() : ObservableStringDictionary.pci;
  860. pci.oldValue = oldValue;
  861. pci.newValue = newValue;
  862. pci.propertyName = propName;
  863. try {
  864. ObservableStringDictionary.callingPropChanged = true;
  865. this.propertyChanged.notifyObservers(pci, mask);
  866. }
  867. finally {
  868. ObservableStringDictionary.callingPropChanged = false;
  869. }
  870. }
  871. };
  872. Object.defineProperty(ObservableStringDictionary.prototype, "dictionaryChanged", {
  873. get: function () {
  874. if (!this._dictionaryChanged) {
  875. this._dictionaryChanged = new BABYLON.Observable();
  876. }
  877. return this._dictionaryChanged;
  878. },
  879. enumerable: true,
  880. configurable: true
  881. });
  882. ObservableStringDictionary.prototype.onDictionaryChanged = function (action, newItem, removedKey, changedItem) {
  883. if (this._dictionaryChanged && this._dictionaryChanged.hasObservers()) {
  884. var dci = this._callingDicChanged ? new DictionaryChanged() : this.dci;
  885. dci.action = action;
  886. dci.newItem = newItem;
  887. dci.removedKey = removedKey;
  888. dci.changedItem = changedItem;
  889. try {
  890. this._callingDicChanged = true;
  891. this.dictionaryChanged.notifyObservers(dci, action);
  892. }
  893. finally {
  894. this._callingDicChanged = false;
  895. }
  896. }
  897. };
  898. Object.defineProperty(ObservableStringDictionary.prototype, "watchedObjectChanged", {
  899. get: function () {
  900. if (!this._watchedObjectChanged) {
  901. this._watchedObjectChanged = new BABYLON.Observable();
  902. }
  903. return this._watchedObjectChanged;
  904. },
  905. enumerable: true,
  906. configurable: true
  907. });
  908. ObservableStringDictionary.prototype.onWatchedObjectChanged = function (key, object, propChanged) {
  909. if (this._watchedObjectChanged && this._watchedObjectChanged.hasObservers()) {
  910. var woci = this._callingWatchedObjectChanged ? new OSDWatchedObjectChangedInfo() : this._woci;
  911. woci.key = key;
  912. woci.object = object;
  913. woci.propertyChanged = propChanged;
  914. try {
  915. this._callingWatchedObjectChanged = true;
  916. this.watchedObjectChanged.notifyObservers(woci);
  917. }
  918. finally {
  919. this._callingWatchedObjectChanged = false;
  920. }
  921. }
  922. };
  923. return ObservableStringDictionary;
  924. }(BABYLON.StringDictionary));
  925. ObservableStringDictionary.pci = new BABYLON.PropertyChangedInfo();
  926. ObservableStringDictionary.callingPropChanged = false;
  927. BABYLON.ObservableStringDictionary = ObservableStringDictionary;
  928. })(BABYLON || (BABYLON = {}));
  929. //# sourceMappingURL=babylon.observableStringDictionary.js.map
  930. var __extends = (this && this.__extends) || function (d, b) {
  931. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  932. function __() { this.constructor = d; }
  933. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  934. };
  935. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  936. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  937. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  938. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  939. return c > 3 && r && Object.defineProperty(target, key, r), r;
  940. };
  941. var BABYLON;
  942. (function (BABYLON) {
  943. /**
  944. * This class given information about a given character.
  945. */
  946. var CharInfo = (function () {
  947. function CharInfo() {
  948. }
  949. return CharInfo;
  950. }());
  951. BABYLON.CharInfo = CharInfo;
  952. /**
  953. * This is an abstract base class to hold a Texture that will contain a FontMap
  954. */
  955. var BaseFontTexture = (function (_super) {
  956. __extends(BaseFontTexture, _super);
  957. function BaseFontTexture(url, scene, noMipmap, invertY, samplingMode) {
  958. if (noMipmap === void 0) { noMipmap = false; }
  959. if (invertY === void 0) { invertY = true; }
  960. if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
  961. var _this = _super.call(this, url, scene, noMipmap, invertY, samplingMode) || this;
  962. _this._cachedFontId = null;
  963. _this._charInfos = new BABYLON.StringDictionary();
  964. return _this;
  965. }
  966. Object.defineProperty(BaseFontTexture.prototype, "isSuperSampled", {
  967. /**
  968. * Is the Font is using Super Sampling (each font texel is doubled).
  969. */
  970. get: function () {
  971. return this._superSample;
  972. },
  973. enumerable: true,
  974. configurable: true
  975. });
  976. Object.defineProperty(BaseFontTexture.prototype, "isSignedDistanceField", {
  977. /**
  978. * Is the Font was rendered using the Signed Distance Field algorithm
  979. * @returns {}
  980. */
  981. get: function () {
  982. return this._signedDistanceField;
  983. },
  984. enumerable: true,
  985. configurable: true
  986. });
  987. Object.defineProperty(BaseFontTexture.prototype, "spaceWidth", {
  988. /**
  989. * Get the Width (in pixel) of the Space character
  990. */
  991. get: function () {
  992. return this._spaceWidth;
  993. },
  994. enumerable: true,
  995. configurable: true
  996. });
  997. Object.defineProperty(BaseFontTexture.prototype, "lineHeight", {
  998. /**
  999. * Get the Line height (in pixel)
  1000. */
  1001. get: function () {
  1002. return this._lineHeight;
  1003. },
  1004. enumerable: true,
  1005. configurable: true
  1006. });
  1007. /**
  1008. * Measure the width/height that will take a given text
  1009. * @param text the text to measure
  1010. * @param tabulationSize the size (in space character) of the tabulation character, default value must be 4
  1011. */
  1012. BaseFontTexture.prototype.measureText = function (text, tabulationSize) {
  1013. var maxWidth = 0;
  1014. var curWidth = 0;
  1015. var lineCount = 1;
  1016. var charxpos = 0;
  1017. // Parse each char of the string
  1018. for (var _i = 0, text_1 = text; _i < text_1.length; _i++) {
  1019. var char = text_1[_i];
  1020. // Next line feed?
  1021. if (char === "\n") {
  1022. maxWidth = Math.max(maxWidth, curWidth);
  1023. charxpos = 0;
  1024. curWidth = 0;
  1025. ++lineCount;
  1026. continue;
  1027. }
  1028. // Tabulation ?
  1029. if (char === "\t") {
  1030. var nextPos = charxpos + tabulationSize;
  1031. nextPos = nextPos - (nextPos % tabulationSize);
  1032. curWidth += (nextPos - charxpos) * this.spaceWidth;
  1033. charxpos = nextPos;
  1034. continue;
  1035. }
  1036. if (char < " ") {
  1037. continue;
  1038. }
  1039. var ci = this.getChar(char);
  1040. if (!ci) {
  1041. throw new Error("Character " + char + " is not supported by FontTexture " + this.name);
  1042. }
  1043. curWidth += ci.charWidth;
  1044. ++charxpos;
  1045. }
  1046. maxWidth = Math.max(maxWidth, curWidth);
  1047. return new BABYLON.Size(maxWidth, lineCount * this.lineHeight);
  1048. };
  1049. return BaseFontTexture;
  1050. }(BABYLON.Texture));
  1051. BABYLON.BaseFontTexture = BaseFontTexture;
  1052. var BitmapFontInfo = (function () {
  1053. function BitmapFontInfo() {
  1054. this.kerningDic = new BABYLON.StringDictionary();
  1055. this.charDic = new BABYLON.StringDictionary();
  1056. }
  1057. return BitmapFontInfo;
  1058. }());
  1059. BABYLON.BitmapFontInfo = BitmapFontInfo;
  1060. var BitmapFontTexture = (function (_super) {
  1061. __extends(BitmapFontTexture, _super);
  1062. function BitmapFontTexture(scene, bmFontUrl, textureUrl, noMipmap, invertY, samplingMode, onLoad, onError) {
  1063. if (textureUrl === void 0) { textureUrl = null; }
  1064. if (noMipmap === void 0) { noMipmap = false; }
  1065. if (invertY === void 0) { invertY = true; }
  1066. if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
  1067. if (onLoad === void 0) { onLoad = null; }
  1068. if (onError === void 0) { onError = null; }
  1069. var _this = _super.call(this, null, scene, noMipmap, invertY, samplingMode) || this;
  1070. _this._usedCounter = 1;
  1071. var xhr = new XMLHttpRequest();
  1072. xhr.onreadystatechange = function () {
  1073. if (xhr.readyState === XMLHttpRequest.DONE) {
  1074. if (xhr.status === 200) {
  1075. var ext = bmFontUrl.split('.').pop().split(/\#|\?/)[0];
  1076. var plugins = BitmapFontTexture.plugins.get(ext.toLocaleLowerCase());
  1077. if (!plugins) {
  1078. if (onError) {
  1079. onError("couldn't find a plugin for this file extension", -1);
  1080. }
  1081. return;
  1082. }
  1083. var _loop_1 = function (p) {
  1084. var ret = p.loadFont(xhr.response, scene, invertY);
  1085. if (ret) {
  1086. var bfi = ret.bfi;
  1087. if (textureUrl != null) {
  1088. bfi.textureUrl = textureUrl;
  1089. }
  1090. else {
  1091. var baseUrl = bmFontUrl.substr(0, bmFontUrl.lastIndexOf("/") + 1);
  1092. bfi.textureUrl = baseUrl + bfi.textureFile;
  1093. }
  1094. _this._texture = scene.getEngine().createTexture(bfi.textureUrl, noMipmap, invertY, scene, samplingMode, function () {
  1095. if (ret.bfi && onLoad) {
  1096. onLoad();
  1097. }
  1098. });
  1099. _this._lineHeight = bfi.lineHeight;
  1100. _this._charInfos.copyFrom(bfi.charDic);
  1101. var ci = _this.getChar(" ");
  1102. if (ci) {
  1103. _this._spaceWidth = ci.charWidth;
  1104. }
  1105. else {
  1106. _this._charInfos.first(function (k, v) { return _this._spaceWidth = v.charWidth; });
  1107. }
  1108. if (!ret.bfi && onError) {
  1109. onError(ret.errorMsg, ret.errorCode);
  1110. }
  1111. return { value: void 0 };
  1112. }
  1113. };
  1114. for (var _i = 0, plugins_1 = plugins; _i < plugins_1.length; _i++) {
  1115. var p = plugins_1[_i];
  1116. var state_1 = _loop_1(p);
  1117. if (typeof state_1 === "object")
  1118. return state_1.value;
  1119. }
  1120. if (onError) {
  1121. onError("No plugin to load this BMFont file format", -1);
  1122. }
  1123. }
  1124. else {
  1125. if (onError) {
  1126. onError("Couldn't load file through HTTP Request, HTTP Status " + xhr.status, xhr.status);
  1127. }
  1128. }
  1129. }
  1130. };
  1131. xhr.open("GET", bmFontUrl, true);
  1132. xhr.send();
  1133. return _this;
  1134. }
  1135. BitmapFontTexture.GetCachedFontTexture = function (scene, fontTexture) {
  1136. var dic = scene.getOrAddExternalDataWithFactory("BitmapFontTextureCache", function () { return new BABYLON.StringDictionary(); });
  1137. var ft = dic.get(fontTexture.uid);
  1138. if (ft) {
  1139. ++ft._usedCounter;
  1140. return ft;
  1141. }
  1142. dic.add(fontTexture.uid, fontTexture);
  1143. return ft;
  1144. };
  1145. BitmapFontTexture.ReleaseCachedFontTexture = function (scene, fontTexture) {
  1146. var dic = scene.getExternalData("BitmapFontTextureCache");
  1147. if (!dic) {
  1148. return;
  1149. }
  1150. var font = dic.get(fontTexture.uid);
  1151. if (--font._usedCounter === 0) {
  1152. dic.remove(fontTexture.uid);
  1153. font.dispose();
  1154. }
  1155. };
  1156. Object.defineProperty(BitmapFontTexture.prototype, "isDynamicFontTexture", {
  1157. /**
  1158. * Is the font dynamically updated, if true is returned then you have to call the update() before using the font in rendering if new character were adding using getChar()
  1159. */
  1160. get: function () {
  1161. return false;
  1162. },
  1163. enumerable: true,
  1164. configurable: true
  1165. });
  1166. /**
  1167. * This method does nothing for a BitmapFontTexture object as it's a static texture
  1168. */
  1169. BitmapFontTexture.prototype.update = function () {
  1170. };
  1171. /**
  1172. * Retrieve the CharInfo object for a given character
  1173. * @param char the character to retrieve the CharInfo object from (e.g.: "A", "a", etc.)
  1174. */
  1175. BitmapFontTexture.prototype.getChar = function (char) {
  1176. return this._charInfos.get(char);
  1177. };
  1178. /**
  1179. * For FontTexture retrieved using GetCachedFontTexture, use this method when you transfer this object's lifetime to another party in order to share this resource.
  1180. * When the other party is done with this object, decCachedFontTextureCounter must be called.
  1181. */
  1182. BitmapFontTexture.prototype.incCachedFontTextureCounter = function () {
  1183. ++this._usedCounter;
  1184. };
  1185. /**
  1186. * Use this method only in conjunction with incCachedFontTextureCounter, call it when you no longer need to use this shared resource.
  1187. */
  1188. BitmapFontTexture.prototype.decCachedFontTextureCounter = function () {
  1189. var dic = this.getScene().getExternalData("BitmapFontTextureCache");
  1190. if (!dic) {
  1191. return;
  1192. }
  1193. if (--this._usedCounter === 0) {
  1194. dic.remove(this._cachedFontId);
  1195. this.dispose();
  1196. }
  1197. };
  1198. BitmapFontTexture.addLoader = function (fileExtension, plugin) {
  1199. var a = BitmapFontTexture.plugins.getOrAddWithFactory(fileExtension.toLocaleLowerCase(), function () { return new Array(); });
  1200. a.push(plugin);
  1201. };
  1202. return BitmapFontTexture;
  1203. }(BaseFontTexture));
  1204. BitmapFontTexture.plugins = new BABYLON.StringDictionary();
  1205. BABYLON.BitmapFontTexture = BitmapFontTexture;
  1206. /**
  1207. * This class is a special kind of texture which generates on the fly characters of a given css style "fontName".
  1208. * The generated texture will be updated when new characters will be retrieved using the getChar() method, but you have
  1209. * to call the update() method for the texture to fetch these changes, you can harmlessly call update any time you want, if no
  1210. * change were made, nothing will happen.
  1211. * The Font Texture can be rendered in three modes: normal size, super sampled size (x2) or using Signed Distance Field rendering.
  1212. * Signed Distance Field should be prefered because the texture can be rendered using AlphaTest instead of Transparency, which is way more faster. More about SDF here (http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf).
  1213. * The only flaw of SDF is that the rendering quality may not be the best or the edges too sharp is the font thickness is too thin.
  1214. */
  1215. var FontTexture = (function (_super) {
  1216. __extends(FontTexture, _super);
  1217. /**
  1218. * Create a new instance of the FontTexture class
  1219. * @param name the name of the texture
  1220. * @param font the font to use, use the W3C CSS notation
  1221. * @param scene the scene that owns the texture
  1222. * @param maxCharCount the approximative maximum count of characters that could fit in the texture. This is an approximation because most of the fonts are proportional (each char has its own Width). The 'W' character's width is used to compute the size of the texture based on the given maxCharCount
  1223. * @param samplingMode the texture sampling mode
  1224. * @param superSample if true the FontTexture will be created with a font of a size twice bigger than the given one but all properties (lineHeight, charWidth, etc.) will be according to the original size. This is made to improve the text quality.
  1225. */
  1226. function FontTexture(name, font, scene, maxCharCount, samplingMode, superSample, signedDistanceField) {
  1227. if (maxCharCount === void 0) { maxCharCount = 200; }
  1228. if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
  1229. if (superSample === void 0) { superSample = false; }
  1230. if (signedDistanceField === void 0) { signedDistanceField = false; }
  1231. var _this = _super.call(this, null, scene, true, false, samplingMode) || this;
  1232. _this._curCharCount = 0;
  1233. _this._lastUpdateCharCount = -1;
  1234. _this._usedCounter = 1;
  1235. _this.name = name;
  1236. _this.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
  1237. _this.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
  1238. _this._sdfScale = 8;
  1239. _this._signedDistanceField = signedDistanceField;
  1240. _this._superSample = false;
  1241. // SDF will use supersample no matter what, the resolution is otherwise too poor to produce correct result
  1242. if (superSample || signedDistanceField) {
  1243. var sfont = _this.getSuperSampleFont(font);
  1244. if (sfont) {
  1245. _this._superSample = true;
  1246. font = sfont;
  1247. }
  1248. }
  1249. // First canvas creation to determine the size of the texture to create
  1250. _this._canvas = document.createElement("canvas");
  1251. _this._context = _this._canvas.getContext("2d");
  1252. _this._context.font = font;
  1253. _this._context.fillStyle = "white";
  1254. _this._context.textBaseline = "top";
  1255. var res = _this.getFontHeight(font);
  1256. _this._lineHeightSuper = res.height; //+4;
  1257. _this._lineHeight = _this._superSample ? (Math.ceil(_this._lineHeightSuper / 2)) : _this._lineHeightSuper;
  1258. _this._offset = res.offset - 1;
  1259. _this._xMargin = 1 + Math.ceil(_this._lineHeightSuper / 15); // Right now this empiric formula seems to work...
  1260. _this._yMargin = _this._xMargin;
  1261. var maxCharWidth = _this._context.measureText("W").width;
  1262. _this._spaceWidthSuper = _this._context.measureText(" ").width;
  1263. _this._spaceWidth = _this._superSample ? (_this._spaceWidthSuper / 2) : _this._spaceWidthSuper;
  1264. // This is an approximate size, but should always be able to fit at least the maxCharCount
  1265. var totalEstSurface = (_this._lineHeightSuper + _this._yMargin) * (maxCharWidth + _this._xMargin) * maxCharCount;
  1266. var edge = Math.sqrt(totalEstSurface);
  1267. var textSize = Math.pow(2, Math.ceil(Math.log(edge) / Math.log(2)));
  1268. // Create the texture that will store the font characters
  1269. _this._texture = scene.getEngine().createDynamicTexture(textSize, textSize, false, samplingMode);
  1270. var textureSize = _this.getSize();
  1271. _this.hasAlpha = _this._signedDistanceField === false;
  1272. // Recreate a new canvas with the final size: the one matching the texture (resizing the previous one doesn't work as one would expect...)
  1273. _this._canvas = document.createElement("canvas");
  1274. _this._canvas.width = textureSize.width;
  1275. _this._canvas.height = textureSize.height;
  1276. _this._context = _this._canvas.getContext("2d");
  1277. _this._context.textBaseline = "top";
  1278. _this._context.font = font;
  1279. _this._context.fillStyle = "white";
  1280. _this._context.imageSmoothingEnabled = false;
  1281. _this._context.clearRect(0, 0, textureSize.width, textureSize.height);
  1282. // Create a canvas for the signed distance field mode, we only have to store one char, the purpose is to render a char scaled _sdfScale times
  1283. // into this 2D context, then get the bitmap data, create the sdf char and push the result in the _context (which hold the whole Font Texture content)
  1284. // So you can see this context as an intermediate one, because it is.
  1285. if (_this._signedDistanceField) {
  1286. var sdfC = document.createElement("canvas");
  1287. var s = _this._sdfScale;
  1288. sdfC.width = maxCharWidth * s;
  1289. sdfC.height = _this._lineHeightSuper * s;
  1290. var sdfCtx = sdfC.getContext("2d");
  1291. sdfCtx.scale(s, s);
  1292. sdfCtx.textBaseline = "top";
  1293. sdfCtx.font = font;
  1294. sdfCtx.fillStyle = "white";
  1295. sdfCtx.imageSmoothingEnabled = false;
  1296. _this._sdfCanvas = sdfC;
  1297. _this._sdfContext = sdfCtx;
  1298. }
  1299. _this._currentFreePosition = BABYLON.Vector2.Zero();
  1300. // Add the basic ASCII based characters
  1301. for (var i = 0x20; i < 0x7F; i++) {
  1302. var c = String.fromCharCode(i);
  1303. _this.getChar(c);
  1304. }
  1305. _this.update();
  1306. return _this;
  1307. }
  1308. Object.defineProperty(FontTexture.prototype, "isDynamicFontTexture", {
  1309. get: function () {
  1310. return true;
  1311. },
  1312. enumerable: true,
  1313. configurable: true
  1314. });
  1315. FontTexture.GetCachedFontTexture = function (scene, fontName, supersample, signedDistanceField) {
  1316. if (supersample === void 0) { supersample = false; }
  1317. if (signedDistanceField === void 0) { signedDistanceField = false; }
  1318. var dic = scene.getOrAddExternalDataWithFactory("FontTextureCache", function () { return new BABYLON.StringDictionary(); });
  1319. var lfn = fontName.toLocaleLowerCase() + (supersample ? "_+SS" : "_-SS") + (signedDistanceField ? "_+SDF" : "_-SDF");
  1320. var ft = dic.get(lfn);
  1321. if (ft) {
  1322. ++ft._usedCounter;
  1323. return ft;
  1324. }
  1325. ft = new FontTexture(null, fontName, scene, supersample ? 100 : 200, BABYLON.Texture.BILINEAR_SAMPLINGMODE, supersample, signedDistanceField);
  1326. ft._cachedFontId = lfn;
  1327. dic.add(lfn, ft);
  1328. return ft;
  1329. };
  1330. FontTexture.ReleaseCachedFontTexture = function (scene, fontName, supersample, signedDistanceField) {
  1331. if (supersample === void 0) { supersample = false; }
  1332. if (signedDistanceField === void 0) { signedDistanceField = false; }
  1333. var dic = scene.getExternalData("FontTextureCache");
  1334. if (!dic) {
  1335. return;
  1336. }
  1337. var lfn = fontName.toLocaleLowerCase() + (supersample ? "_+SS" : "_-SS") + (signedDistanceField ? "_+SDF" : "_-SDF");
  1338. var font = dic.get(lfn);
  1339. if (--font._usedCounter === 0) {
  1340. dic.remove(lfn);
  1341. font.dispose();
  1342. }
  1343. };
  1344. /**
  1345. * Make sure the given char is present in the font map.
  1346. * @param char the character to get or add
  1347. * @return the CharInfo instance corresponding to the given character
  1348. */
  1349. FontTexture.prototype.getChar = function (char) {
  1350. if (char.length !== 1) {
  1351. return null;
  1352. }
  1353. var info = this._charInfos.get(char);
  1354. if (info) {
  1355. return info;
  1356. }
  1357. info = new CharInfo();
  1358. var measure = this._context.measureText(char);
  1359. var textureSize = this.getSize();
  1360. // we reached the end of the current line?
  1361. var width = Math.round(measure.width);
  1362. if (this._currentFreePosition.x + width + this._xMargin > textureSize.width) {
  1363. this._currentFreePosition.x = 0;
  1364. this._currentFreePosition.y += this._lineHeightSuper + this._yMargin;
  1365. // No more room?
  1366. if (this._currentFreePosition.y > textureSize.height) {
  1367. return this.getChar("!");
  1368. }
  1369. }
  1370. // In sdf mode we render the character in an intermediate 2D context which scale the character this._sdfScale times (which is required to compute the sdf map accurately)
  1371. if (this._signedDistanceField) {
  1372. this._sdfContext.clearRect(0, 0, this._sdfCanvas.width, this._sdfCanvas.height);
  1373. this._sdfContext.fillText(char, 0, -this._offset);
  1374. var data = this._sdfContext.getImageData(0, 0, width * this._sdfScale, this._sdfCanvas.height);
  1375. var res = this._computeSDFChar(data);
  1376. this._context.putImageData(res, this._currentFreePosition.x, this._currentFreePosition.y);
  1377. }
  1378. else {
  1379. // Draw the character in the HTML canvas
  1380. this._context.fillText(char, this._currentFreePosition.x, this._currentFreePosition.y - this._offset);
  1381. }
  1382. // Fill the CharInfo object
  1383. info.topLeftUV = new BABYLON.Vector2(this._currentFreePosition.x / textureSize.width, this._currentFreePosition.y / textureSize.height);
  1384. info.bottomRightUV = new BABYLON.Vector2((this._currentFreePosition.x + width) / textureSize.width, info.topLeftUV.y + ((this._lineHeightSuper + 2) / textureSize.height));
  1385. if (this._signedDistanceField) {
  1386. var off = 1 / textureSize.width;
  1387. info.topLeftUV.addInPlace(new BABYLON.Vector2(off, off));
  1388. info.bottomRightUV.addInPlace(new BABYLON.Vector2(off, off));
  1389. }
  1390. info.charWidth = this._superSample ? (width / 2) : width;
  1391. // Add the info structure
  1392. this._charInfos.add(char, info);
  1393. this._curCharCount++;
  1394. // Set the next position
  1395. this._currentFreePosition.x += width + this._xMargin;
  1396. return info;
  1397. };
  1398. FontTexture.prototype._computeSDFChar = function (source) {
  1399. var scl = this._sdfScale;
  1400. var sw = source.width;
  1401. var sh = source.height;
  1402. var dw = sw / scl;
  1403. var dh = sh / scl;
  1404. var roffx = 0;
  1405. var roffy = 0;
  1406. // We shouldn't look beyond half of the biggest between width and height
  1407. var radius = scl;
  1408. var br = radius - 1;
  1409. var lookupSrc = function (dx, dy, offX, offY, lookVis) {
  1410. var sx = dx * scl;
  1411. var sy = dy * scl;
  1412. // Looking out of the area? return true to make the test going on
  1413. if (((sx + offX) < 0) || ((sx + offX) >= sw) || ((sy + offY) < 0) || ((sy + offY) >= sh)) {
  1414. return true;
  1415. }
  1416. // Get the pixel we want
  1417. var val = source.data[(((sy + offY) * sw) + (sx + offX)) * 4];
  1418. var res = (val > 0) === lookVis;
  1419. if (!res) {
  1420. roffx = offX;
  1421. roffy = offY;
  1422. }
  1423. return res;
  1424. };
  1425. var lookupArea = function (dx, dy, lookVis) {
  1426. // Fast rejection test, if we have the same result in N, S, W, E at a distance which is the radius-1 then it means the data will be consistent in this area. That's because we've scale the rendering of the letter "radius" times, so a letter's pixel will be at least radius wide
  1427. if (lookupSrc(dx, dy, 0, br, lookVis) &&
  1428. lookupSrc(dx, dy, 0, -br, lookVis) &&
  1429. lookupSrc(dx, dy, -br, 0, lookVis) &&
  1430. lookupSrc(dx, dy, br, 0, lookVis)) {
  1431. return 0;
  1432. }
  1433. for (var i = 1; i <= radius; i++) {
  1434. // Quick test N, S, W, E
  1435. if (!lookupSrc(dx, dy, 0, i, lookVis) || !lookupSrc(dx, dy, 0, -i, lookVis) || !lookupSrc(dx, dy, -i, 0, lookVis) || !lookupSrc(dx, dy, i, 0, lookVis)) {
  1436. return i * i; // Squared Distance is simple to compute in this case
  1437. }
  1438. // Test the frame area (except the N, S, W, E spots) from the nearest point from the center to the further one
  1439. for (var j = 1; j <= i; j++) {
  1440. if (!lookupSrc(dx, dy, -j, i, lookVis) || !lookupSrc(dx, dy, j, i, lookVis) ||
  1441. !lookupSrc(dx, dy, i, -j, lookVis) || !lookupSrc(dx, dy, i, j, lookVis) ||
  1442. !lookupSrc(dx, dy, -j, -i, lookVis) || !lookupSrc(dx, dy, j, -i, lookVis) ||
  1443. !lookupSrc(dx, dy, -i, -j, lookVis) || !lookupSrc(dx, dy, -i, j, lookVis)) {
  1444. // We found the nearest texel having and opposite state, store the squared length
  1445. var res_1 = (i * i) + (j * j);
  1446. var count = 1;
  1447. // To improve quality we will sample the texels around this one, so it's 8 samples, we consider only the one having an opposite state, add them to the current res and will will compute the average at the end
  1448. if (!lookupSrc(dx, dy, roffx - 1, roffy, lookVis)) {
  1449. res_1 += (roffx - 1) * (roffx - 1) + roffy * roffy;
  1450. ++count;
  1451. }
  1452. if (!lookupSrc(dx, dy, roffx + 1, roffy, lookVis)) {
  1453. res_1 += (roffx + 1) * (roffx + 1) + roffy * roffy;
  1454. ++count;
  1455. }
  1456. if (!lookupSrc(dx, dy, roffx, roffy - 1, lookVis)) {
  1457. res_1 += roffx * roffx + (roffy - 1) * (roffy - 1);
  1458. ++count;
  1459. }
  1460. if (!lookupSrc(dx, dy, roffx, roffy + 1, lookVis)) {
  1461. res_1 += roffx * roffx + (roffy + 1) * (roffy + 1);
  1462. ++count;
  1463. }
  1464. if (!lookupSrc(dx, dy, roffx - 1, roffy - 1, lookVis)) {
  1465. res_1 += (roffx - 1) * (roffx - 1) + (roffy - 1) * (roffy - 1);
  1466. ++count;
  1467. }
  1468. if (!lookupSrc(dx, dy, roffx + 1, roffy + 1, lookVis)) {
  1469. res_1 += (roffx + 1) * (roffx + 1) + (roffy + 1) * (roffy + 1);
  1470. ++count;
  1471. }
  1472. if (!lookupSrc(dx, dy, roffx + 1, roffy - 1, lookVis)) {
  1473. res_1 += (roffx + 1) * (roffx + 1) + (roffy - 1) * (roffy - 1);
  1474. ++count;
  1475. }
  1476. if (!lookupSrc(dx, dy, roffx - 1, roffy + 1, lookVis)) {
  1477. res_1 += (roffx - 1) * (roffx - 1) + (roffy + 1) * (roffy + 1);
  1478. ++count;
  1479. }
  1480. // Compute the average based on the accumulated distance
  1481. return res_1 / count;
  1482. }
  1483. }
  1484. }
  1485. return 0;
  1486. };
  1487. var tmp = new Array(dw * dh);
  1488. for (var y = 0; y < dh; y++) {
  1489. for (var x = 0; x < dw; x++) {
  1490. var curState = lookupSrc(x, y, 0, 0, true);
  1491. var d = lookupArea(x, y, curState);
  1492. if (d === 0) {
  1493. d = radius * radius * 2;
  1494. }
  1495. tmp[(y * dw) + x] = curState ? d : -d;
  1496. }
  1497. }
  1498. var res = this._context.createImageData(dw, dh);
  1499. var size = dw * dh;
  1500. for (var j = 0; j < size; j++) {
  1501. var d = tmp[j];
  1502. var sign = (d < 0) ? -1 : 1;
  1503. d = Math.sqrt(Math.abs(d)) * sign;
  1504. d *= 127.5 / radius;
  1505. d += 127.5;
  1506. if (d < 0) {
  1507. d = 0;
  1508. }
  1509. else if (d > 255) {
  1510. d = 255;
  1511. }
  1512. d += 0.5;
  1513. res.data[j * 4 + 0] = d;
  1514. res.data[j * 4 + 1] = d;
  1515. res.data[j * 4 + 2] = d;
  1516. res.data[j * 4 + 3] = 255;
  1517. }
  1518. return res;
  1519. };
  1520. FontTexture.prototype.getSuperSampleFont = function (font) {
  1521. // Eternal thank to http://stackoverflow.com/a/10136041/802124
  1522. var regex = /^\s*(?=(?:(?:[-a-z]+\s*){0,2}(italic|oblique))?)(?=(?:(?:[-a-z]+\s*){0,2}(small-caps))?)(?=(?:(?:[-a-z]+\s*){0,2}(bold(?:er)?|lighter|[1-9]00))?)(?:(?:normal|\1|\2|\3)\s*){0,3}((?:xx?-)?(?:small|large)|medium|smaller|larger|[.\d]+(?:\%|in|[cem]m|ex|p[ctx]))(?:\s*\/\s*(normal|[.\d]+(?:\%|in|[cem]m|ex|p[ctx])))?\s*([-,\"\sa-z]+?)\s*$/;
  1523. var res = font.toLocaleLowerCase().match(regex);
  1524. if (res == null) {
  1525. return null;
  1526. }
  1527. var size = parseInt(res[4]);
  1528. res[4] = (size * 2).toString() + (res[4].match(/\D+/) || []).pop();
  1529. var newFont = "";
  1530. for (var j = 1; j < res.length; j++) {
  1531. if (res[j] != null) {
  1532. newFont += res[j] + " ";
  1533. }
  1534. }
  1535. return newFont;
  1536. };
  1537. // More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/
  1538. FontTexture.prototype.getFontHeight = function (font) {
  1539. var fontDraw = document.createElement("canvas");
  1540. var ctx = fontDraw.getContext('2d');
  1541. ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);
  1542. ctx.textBaseline = 'top';
  1543. ctx.fillStyle = 'white';
  1544. ctx.font = font;
  1545. ctx.fillText('jH|', 0, 0);
  1546. var pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;
  1547. var start = -1;
  1548. var end = -1;
  1549. for (var row = 0; row < fontDraw.height; row++) {
  1550. for (var column = 0; column < fontDraw.width; column++) {
  1551. var index = (row * fontDraw.width + column) * 4;
  1552. if (pixels[index] === 0) {
  1553. if (column === fontDraw.width - 1 && start !== -1) {
  1554. end = row;
  1555. row = fontDraw.height;
  1556. break;
  1557. }
  1558. continue;
  1559. }
  1560. else {
  1561. if (start === -1) {
  1562. start = row;
  1563. }
  1564. break;
  1565. }
  1566. }
  1567. }
  1568. return { height: (end - start) + 1, offset: start - 1 };
  1569. };
  1570. Object.defineProperty(FontTexture.prototype, "canRescale", {
  1571. get: function () {
  1572. return false;
  1573. },
  1574. enumerable: true,
  1575. configurable: true
  1576. });
  1577. FontTexture.prototype.getContext = function () {
  1578. return this._context;
  1579. };
  1580. /**
  1581. * Call this method when you've call getChar() at least one time, this will update the texture if needed.
  1582. * Don't be afraid to call it, if no new character was added, this method simply does nothing.
  1583. */
  1584. FontTexture.prototype.update = function () {
  1585. // Update only if there's new char added since the previous update
  1586. if (this._lastUpdateCharCount < this._curCharCount) {
  1587. this.getScene().getEngine().updateDynamicTexture(this._texture, this._canvas, false, true);
  1588. this._lastUpdateCharCount = this._curCharCount;
  1589. }
  1590. };
  1591. // cloning should be prohibited, there's no point to duplicate this texture at all
  1592. FontTexture.prototype.clone = function () {
  1593. return null;
  1594. };
  1595. /**
  1596. * For FontTexture retrieved using GetCachedFontTexture, use this method when you transfer this object's lifetime to another party in order to share this resource.
  1597. * When the other party is done with this object, decCachedFontTextureCounter must be called.
  1598. */
  1599. FontTexture.prototype.incCachedFontTextureCounter = function () {
  1600. ++this._usedCounter;
  1601. };
  1602. /**
  1603. * Use this method only in conjunction with incCachedFontTextureCounter, call it when you no longer need to use this shared resource.
  1604. */
  1605. FontTexture.prototype.decCachedFontTextureCounter = function () {
  1606. var dic = this.getScene().getExternalData("FontTextureCache");
  1607. if (!dic) {
  1608. return;
  1609. }
  1610. if (--this._usedCounter === 0) {
  1611. dic.remove(this._cachedFontId);
  1612. this.dispose();
  1613. }
  1614. };
  1615. return FontTexture;
  1616. }(BaseFontTexture));
  1617. BABYLON.FontTexture = FontTexture;
  1618. /**
  1619. * Orginial code from cocos2d-js, converted to TypeScript by Nockawa
  1620. * Load the Text version of the BMFont format, no XML or binary supported, just plain old text
  1621. */
  1622. var BMFontLoaderTxt = BMFontLoaderTxt_1 = (function () {
  1623. function BMFontLoaderTxt() {
  1624. }
  1625. BMFontLoaderTxt.prototype._parseStrToObj = function (str) {
  1626. var arr = str.match(BMFontLoaderTxt_1.ITEM_EXP);
  1627. if (!arr) {
  1628. return null;
  1629. }
  1630. var obj = {};
  1631. for (var i = 0, li = arr.length; i < li; i++) {
  1632. var tempStr = arr[i];
  1633. var index = tempStr.indexOf("=");
  1634. var key = tempStr.substring(0, index);
  1635. var value = tempStr.substring(index + 1);
  1636. if (value.match(BMFontLoaderTxt_1.INT_EXP))
  1637. value = parseInt(value);
  1638. else if (value[0] === '"')
  1639. value = value.substring(1, value.length - 1);
  1640. obj[key] = value;
  1641. }
  1642. return obj;
  1643. };
  1644. BMFontLoaderTxt.prototype._buildCharInfo = function (initialLine, obj, textureSize, invertY, chars) {
  1645. var char = null;
  1646. var x = null;
  1647. var y = null;
  1648. var xadv = null;
  1649. var width = null;
  1650. var height = null;
  1651. var ci = new CharInfo();
  1652. for (var key in obj) {
  1653. var value = obj[key];
  1654. switch (key) {
  1655. case "id":
  1656. char = String.fromCharCode(value);
  1657. break;
  1658. case "x":
  1659. x = value;
  1660. break;
  1661. case "y":
  1662. y = value;
  1663. break;
  1664. case "width":
  1665. width = value;
  1666. break;
  1667. case "height":
  1668. height = value;
  1669. break;
  1670. case "xadvance":
  1671. xadv = value;
  1672. break;
  1673. }
  1674. }
  1675. if (x != null && y != null && width != null && height != null && char != null) {
  1676. if (xadv) {
  1677. width = xadv;
  1678. }
  1679. if (invertY) {
  1680. ci.topLeftUV = new BABYLON.Vector2(1 - (x / textureSize.width), 1 - (y / textureSize.height));
  1681. ci.bottomRightUV = new BABYLON.Vector2(1 - ((x + width) / textureSize.width), 1 - ((y + height) / textureSize.height));
  1682. }
  1683. else {
  1684. ci.topLeftUV = new BABYLON.Vector2(x / textureSize.width, y / textureSize.height);
  1685. ci.bottomRightUV = new BABYLON.Vector2((x + width) / textureSize.width, (y + height) / textureSize.height);
  1686. }
  1687. ci.charWidth = width;
  1688. chars.add(char, ci);
  1689. }
  1690. else {
  1691. console.log("Error while parsing line " + initialLine);
  1692. }
  1693. };
  1694. BMFontLoaderTxt.prototype.loadFont = function (fontContent, scene, invertY) {
  1695. var fontStr = fontContent;
  1696. var bfi = new BitmapFontInfo();
  1697. var errorCode = 0;
  1698. var errorMsg = "OK";
  1699. //padding
  1700. var info = fontStr.match(BMFontLoaderTxt_1.INFO_EXP);
  1701. var infoObj = this._parseStrToObj(info[0]);
  1702. if (!infoObj) {
  1703. return null;
  1704. }
  1705. var paddingArr = infoObj["padding"].split(",");
  1706. bfi.padding = new BABYLON.Vector4(parseInt(paddingArr[0]), parseInt(paddingArr[1]), parseInt(paddingArr[2]), parseInt(paddingArr[3]));
  1707. //common
  1708. var commonObj = this._parseStrToObj(fontStr.match(BMFontLoaderTxt_1.COMMON_EXP)[0]);
  1709. bfi.lineHeight = commonObj["lineHeight"];
  1710. bfi.textureSize = new BABYLON.Size(commonObj["scaleW"], commonObj["scaleH"]);
  1711. var maxTextureSize = scene.getEngine()._gl.getParameter(0xd33);
  1712. if (commonObj["scaleW"] > maxTextureSize.width || commonObj["scaleH"] > maxTextureSize.height) {
  1713. errorMsg = "FontMap texture's size is bigger than what WebGL supports";
  1714. errorCode = -1;
  1715. }
  1716. else {
  1717. if (commonObj["pages"] !== 1) {
  1718. errorMsg = "FontMap must contain one page only.";
  1719. errorCode = -1;
  1720. }
  1721. else {
  1722. //page
  1723. var pageObj = this._parseStrToObj(fontStr.match(BMFontLoaderTxt_1.PAGE_EXP)[0]);
  1724. if (pageObj["id"] !== 0) {
  1725. errorMsg = "Only one page of ID 0 is supported";
  1726. errorCode = -1;
  1727. }
  1728. else {
  1729. bfi.textureFile = pageObj["file"];
  1730. //char
  1731. var charLines = fontStr.match(BMFontLoaderTxt_1.CHAR_EXP);
  1732. for (var i = 0, li = charLines.length; i < li; i++) {
  1733. var charObj = this._parseStrToObj(charLines[i]);
  1734. this._buildCharInfo(charLines[i], charObj, bfi.textureSize, invertY, bfi.charDic);
  1735. }
  1736. //kerning
  1737. var kerningLines = fontStr.match(BMFontLoaderTxt_1.KERNING_EXP);
  1738. if (kerningLines) {
  1739. for (var i = 0, li = kerningLines.length; i < li; i++) {
  1740. var kerningObj = this._parseStrToObj(kerningLines[i]);
  1741. bfi.kerningDic.add(((kerningObj["first"] << 16) | (kerningObj["second"] & 0xffff)).toString(), kerningObj["amount"]);
  1742. }
  1743. }
  1744. }
  1745. }
  1746. }
  1747. return { bfi: bfi, errorCode: errorCode, errorMsg: errorMsg };
  1748. };
  1749. return BMFontLoaderTxt;
  1750. }());
  1751. BMFontLoaderTxt.INFO_EXP = /info [^\r\n]*(\r\n|$)/gi;
  1752. BMFontLoaderTxt.COMMON_EXP = /common [^\n]*(\n|$)/gi;
  1753. BMFontLoaderTxt.PAGE_EXP = /page [^\n]*(\n|$)/gi;
  1754. BMFontLoaderTxt.CHAR_EXP = /char [^\n]*(\n|$)/gi;
  1755. BMFontLoaderTxt.KERNING_EXP = /kerning [^\n]*(\n|$)/gi;
  1756. BMFontLoaderTxt.ITEM_EXP = /\w+=[^ \r\n]+/gi;
  1757. BMFontLoaderTxt.INT_EXP = /^[\-]?\d+$/;
  1758. BMFontLoaderTxt = BMFontLoaderTxt_1 = __decorate([
  1759. BitmapFontLoaderPlugin("fnt", new BMFontLoaderTxt_1())
  1760. ], BMFontLoaderTxt);
  1761. ;
  1762. function BitmapFontLoaderPlugin(fileExtension, plugin) {
  1763. return function () {
  1764. BitmapFontTexture.addLoader(fileExtension, plugin);
  1765. };
  1766. }
  1767. BABYLON.BitmapFontLoaderPlugin = BitmapFontLoaderPlugin;
  1768. var BMFontLoaderTxt_1;
  1769. })(BABYLON || (BABYLON = {}));
  1770. //# sourceMappingURL=babylon.fontTexture.js.map
  1771. var BABYLON;
  1772. (function (BABYLON) {
  1773. /**
  1774. * Stores 2D Bounding Information.
  1775. * This class handles a circle area and a bounding rectangle one.
  1776. */
  1777. var BoundingInfo2D = (function () {
  1778. function BoundingInfo2D() {
  1779. this.radius = 0;
  1780. this.center = BABYLON.Vector2.Zero();
  1781. this.extent = BABYLON.Vector2.Zero();
  1782. }
  1783. /**
  1784. * Create a BoundingInfo2D object from a given size
  1785. * @param size the size that will be used to set the extend, radius will be computed from it.
  1786. */
  1787. BoundingInfo2D.CreateFromSize = function (size) {
  1788. var r = new BoundingInfo2D();
  1789. BoundingInfo2D.CreateFromSizeToRef(size, r);
  1790. return r;
  1791. };
  1792. /**
  1793. * Create a BoundingInfo2D object from a given radius
  1794. * @param radius the radius to use, the extent will be computed from it.
  1795. */
  1796. BoundingInfo2D.CreateFromRadius = function (radius) {
  1797. var r = new BoundingInfo2D();
  1798. BoundingInfo2D.CreateFromRadiusToRef(radius, r);
  1799. return r;
  1800. };
  1801. /**
  1802. * Create a BoundingInfo2D object from a list of points.
  1803. * The resulted object will be the smallest bounding area that includes all the given points.
  1804. * @param points an array of points to compute the bounding object from.
  1805. */
  1806. BoundingInfo2D.CreateFromPoints = function (points) {
  1807. var r = new BoundingInfo2D();
  1808. BoundingInfo2D.CreateFromPointsToRef(points, r);
  1809. return r;
  1810. };
  1811. /**
  1812. * Update a BoundingInfo2D object using the given Size as input
  1813. * @param size the bounding data will be computed from this size.
  1814. * @param b must be a valid/allocated object, it will contain the result of the operation
  1815. */
  1816. BoundingInfo2D.CreateFromSizeToRef = function (size, b) {
  1817. if (!size) {
  1818. size = BABYLON.Size.Zero();
  1819. }
  1820. b.center.x = +size.width / 2;
  1821. b.center.y = +size.height / 2;
  1822. b.extent.x = b.center.x;
  1823. b.extent.y = b.center.y;
  1824. b.radius = b.extent.length();
  1825. };
  1826. /**
  1827. * Update a BoundingInfo2D object using the given radius as input
  1828. * @param radius the bounding data will be computed from this radius
  1829. * @param b must be a valid/allocated object, it will contain the result of the operation
  1830. */
  1831. BoundingInfo2D.CreateFromRadiusToRef = function (radius, b) {
  1832. b.center.x = b.center.y = 0;
  1833. var r = +radius;
  1834. b.extent.x = r;
  1835. b.extent.y = r;
  1836. b.radius = r;
  1837. };
  1838. /**
  1839. * Update a BoundingInfo2D object using the given points array as input
  1840. * @param points the point array to use to update the bounding data
  1841. * @param b must be a valid/allocated object, it will contain the result of the operation
  1842. */
  1843. BoundingInfo2D.CreateFromPointsToRef = function (points, b) {
  1844. var xmin = Number.MAX_VALUE, ymin = Number.MAX_VALUE, xmax = Number.MIN_VALUE, ymax = Number.MIN_VALUE;
  1845. for (var _i = 0, points_1 = points; _i < points_1.length; _i++) {
  1846. var p = points_1[_i];
  1847. xmin = Math.min(p.x, xmin);
  1848. xmax = Math.max(p.x, xmax);
  1849. ymin = Math.min(p.y, ymin);
  1850. ymax = Math.max(p.y, ymax);
  1851. }
  1852. BoundingInfo2D.CreateFromMinMaxToRef(xmin, xmax, ymin, ymax, b);
  1853. };
  1854. /**
  1855. * Update a BoundingInfo2D object using the given min/max values as input
  1856. * @param xmin the smallest x coordinate
  1857. * @param xmax the biggest x coordinate
  1858. * @param ymin the smallest y coordinate
  1859. * @param ymax the buggest y coordinate
  1860. * @param b must be a valid/allocated object, it will contain the result of the operation
  1861. */
  1862. BoundingInfo2D.CreateFromMinMaxToRef = function (xmin, xmax, ymin, ymax, b) {
  1863. var w = xmax - xmin;
  1864. var h = ymax - ymin;
  1865. b.center = new BABYLON.Vector2(xmin + w / 2, ymin + h / 2);
  1866. b.extent = new BABYLON.Vector2(xmax - b.center.x, ymax - b.center.y);
  1867. b.radius = b.extent.length();
  1868. };
  1869. /**
  1870. * Duplicate this instance and return a new one
  1871. * @return the duplicated instance
  1872. */
  1873. BoundingInfo2D.prototype.clone = function () {
  1874. var r = new BoundingInfo2D();
  1875. r.center = this.center.clone();
  1876. r.radius = this.radius;
  1877. r.extent = this.extent.clone();
  1878. return r;
  1879. };
  1880. BoundingInfo2D.prototype.clear = function () {
  1881. this.center.copyFromFloats(0, 0);
  1882. this.radius = 0;
  1883. this.extent.copyFromFloats(0, 0);
  1884. };
  1885. BoundingInfo2D.prototype.copyFrom = function (src) {
  1886. this.center.copyFrom(src.center);
  1887. this.radius = src.radius;
  1888. this.extent.copyFrom(src.extent);
  1889. };
  1890. /**
  1891. * return the max extend of the bounding info
  1892. */
  1893. BoundingInfo2D.prototype.max = function () {
  1894. var r = BABYLON.Vector2.Zero();
  1895. this.maxToRef(r);
  1896. return r;
  1897. };
  1898. /**
  1899. * return the min/max extend of the bounding info.
  1900. * x, y, z, w are left, bottom, right and top
  1901. */
  1902. BoundingInfo2D.prototype.minMax = function () {
  1903. var r = BABYLON.Vector4.Zero();
  1904. this.minMaxToRef(r);
  1905. return r;
  1906. };
  1907. /**
  1908. * Update a vector2 with the max extend of the bounding info
  1909. * @param result must be a valid/allocated vector2 that will contain the result of the operation
  1910. */
  1911. BoundingInfo2D.prototype.maxToRef = function (result) {
  1912. result.x = this.center.x + this.extent.x;
  1913. result.y = this.center.y + this.extent.y;
  1914. };
  1915. /**
  1916. * Update a vector4 with the min/max extend of the bounding info
  1917. * x, y, z, w are left, bottom, right and top
  1918. * @param result must be a valid/allocated vector4 that will contain the result of the operation
  1919. */
  1920. BoundingInfo2D.prototype.minMaxToRef = function (result) {
  1921. result.x = this.center.x - this.extent.x;
  1922. result.y = this.center.y - this.extent.y;
  1923. result.z = this.center.x + this.extent.x;
  1924. result.w = this.center.y + this.extent.y;
  1925. };
  1926. /**
  1927. * Return the size of the boundingInfo rect surface
  1928. */
  1929. BoundingInfo2D.prototype.size = function () {
  1930. var r = BABYLON.Size.Zero();
  1931. this.sizeToRef(r);
  1932. return r;
  1933. };
  1934. /**
  1935. * Stores in the result object the size of the boundingInfo rect surface
  1936. * @param result
  1937. */
  1938. BoundingInfo2D.prototype.sizeToRef = function (result) {
  1939. result.width = this.extent.x * 2;
  1940. result.height = this.extent.y * 2;
  1941. };
  1942. /**
  1943. * Inflate the boundingInfo with the given vector
  1944. * @param offset the extent will be incremented with offset and the radius will be computed again
  1945. */
  1946. BoundingInfo2D.prototype.inflate = function (offset) {
  1947. this.extent.addInPlace(offset);
  1948. this.radius = this.extent.length();
  1949. };
  1950. /**
  1951. * Apply a transformation matrix to this BoundingInfo2D and return a new instance containing the result
  1952. * @param matrix the transformation matrix to apply
  1953. * @return the new instance containing the result of the transformation applied on this BoundingInfo2D
  1954. */
  1955. BoundingInfo2D.prototype.transform = function (matrix) {
  1956. var r = new BoundingInfo2D();
  1957. this.transformToRef(matrix, r);
  1958. return r;
  1959. };
  1960. /**
  1961. * Compute the union of this BoundingInfo2D with a given one, returns a new BoundingInfo2D as a result
  1962. * @param other the second BoundingInfo2D to compute the union with this one
  1963. * @return a new instance containing the result of the union
  1964. */
  1965. BoundingInfo2D.prototype.union = function (other) {
  1966. var r = new BoundingInfo2D();
  1967. this.unionToRef(other, r);
  1968. return r;
  1969. };
  1970. /**
  1971. * Transform this BoundingInfo2D with a given matrix and store the result in an existing BoundingInfo2D instance.
  1972. * This is a GC friendly version, try to use it as much as possible, specially if your transformation is inside a loop, allocate the result object once for good outside of the loop and use it every time.
  1973. * @param matrix The matrix to use to compute the transformation
  1974. * @param result A VALID (i.e. allocated) BoundingInfo2D object where the result will be stored
  1975. */
  1976. BoundingInfo2D.prototype.transformToRef = function (matrix, result) {
  1977. // Construct a bounding box based on the extent values
  1978. var p = BoundingInfo2D._transform;
  1979. p[0].x = this.center.x + this.extent.x;
  1980. p[0].y = this.center.y + this.extent.y;
  1981. p[1].x = this.center.x + this.extent.x;
  1982. p[1].y = this.center.y - this.extent.y;
  1983. p[2].x = this.center.x - this.extent.x;
  1984. p[2].y = this.center.y - this.extent.y;
  1985. p[3].x = this.center.x - this.extent.x;
  1986. p[3].y = this.center.y + this.extent.y;
  1987. // Transform the four points of the bounding box with the matrix
  1988. for (var i = 0; i < 4; i++) {
  1989. BABYLON.Vector2.TransformToRef(p[i], matrix, p[i]);
  1990. }
  1991. BoundingInfo2D.CreateFromPointsToRef(p, result);
  1992. };
  1993. /**
  1994. * Compute the union of this BoundingInfo2D with another one and store the result in a third valid BoundingInfo2D object
  1995. * This is a GC friendly version, try to use it as much as possible, specially if your transformation is inside a loop, allocate the result object once for good outside of the loop and use it every time.
  1996. * @param other the second object used to compute the union
  1997. * @param result a VALID BoundingInfo2D instance (i.e. allocated) where the result will be stored
  1998. */
  1999. BoundingInfo2D.prototype.unionToRef = function (other, result) {
  2000. var xmax = Math.max(this.center.x + this.extent.x, other.center.x + other.extent.x);
  2001. var ymax = Math.max(this.center.y + this.extent.y, other.center.y + other.extent.y);
  2002. var xmin = Math.min(this.center.x - this.extent.x, other.center.x - other.extent.x);
  2003. var ymin = Math.min(this.center.y - this.extent.y, other.center.y - other.extent.y);
  2004. BoundingInfo2D.CreateFromMinMaxToRef(xmin, xmax, ymin, ymax, result);
  2005. };
  2006. /**
  2007. * Check if the given point is inside the BoundingInfo.
  2008. * The test is first made on the radius, then inside the rectangle described by the extent
  2009. * @param pickPosition the position to test
  2010. * @return true if the point is inside, false otherwise
  2011. */
  2012. BoundingInfo2D.prototype.doesIntersect = function (pickPosition) {
  2013. // is it inside the radius?
  2014. var pickLocal = pickPosition.subtract(this.center);
  2015. if (pickLocal.lengthSquared() <= (this.radius * this.radius)) {
  2016. // is it inside the rectangle?
  2017. return ((Math.abs(pickLocal.x) <= this.extent.x) && (Math.abs(pickLocal.y) <= this.extent.y));
  2018. }
  2019. return false;
  2020. };
  2021. return BoundingInfo2D;
  2022. }());
  2023. BoundingInfo2D._transform = new Array(BABYLON.Vector2.Zero(), BABYLON.Vector2.Zero(), BABYLON.Vector2.Zero(), BABYLON.Vector2.Zero());
  2024. BABYLON.BoundingInfo2D = BoundingInfo2D;
  2025. })(BABYLON || (BABYLON = {}));
  2026. //# sourceMappingURL=babylon.bounding2d.js.map
  2027. var __extends = (this && this.__extends) || function (d, b) {
  2028. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  2029. function __() { this.constructor = d; }
  2030. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2031. };
  2032. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2033. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  2034. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  2035. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  2036. return c > 3 && r && Object.defineProperty(target, key, r), r;
  2037. };
  2038. var BABYLON;
  2039. (function (BABYLON) {
  2040. var LayoutEngineBase = (function () {
  2041. function LayoutEngineBase() {
  2042. this.layoutDirtyOnPropertyChangedMask = 0;
  2043. }
  2044. LayoutEngineBase.prototype.updateLayout = function (prim) {
  2045. };
  2046. Object.defineProperty(LayoutEngineBase.prototype, "isChildPositionAllowed", {
  2047. get: function () {
  2048. return false;
  2049. },
  2050. enumerable: true,
  2051. configurable: true
  2052. });
  2053. LayoutEngineBase.prototype.isLocked = function () {
  2054. return this._isLocked;
  2055. };
  2056. LayoutEngineBase.prototype.lock = function () {
  2057. if (this._isLocked) {
  2058. return false;
  2059. }
  2060. this._isLocked = true;
  2061. return true;
  2062. };
  2063. return LayoutEngineBase;
  2064. }());
  2065. LayoutEngineBase = __decorate([
  2066. BABYLON.className("LayoutEngineBase", "BABYLON")
  2067. ], LayoutEngineBase);
  2068. BABYLON.LayoutEngineBase = LayoutEngineBase;
  2069. var CanvasLayoutEngine = CanvasLayoutEngine_1 = (function (_super) {
  2070. __extends(CanvasLayoutEngine, _super);
  2071. /**
  2072. * The default Layout Engine, primitive are positioning into a Canvas, using their x/y coordinates.
  2073. * This layout must be used as a Singleton through the CanvasLayoutEngine.Singleton property.
  2074. */
  2075. function CanvasLayoutEngine() {
  2076. return _super.apply(this, arguments) || this;
  2077. }
  2078. // A very simple (no) layout computing...
  2079. // The Canvas and its direct children gets the Canvas' size as Layout Area
  2080. // Indirect children have their Layout Area to the actualSize (margin area) of their parent
  2081. CanvasLayoutEngine.prototype.updateLayout = function (prim) {
  2082. // If this prim is layoutDiry we update its layoutArea and also the one of its direct children
  2083. if (prim._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty)) {
  2084. for (var _i = 0, _a = prim.children; _i < _a.length; _i++) {
  2085. var child = _a[_i];
  2086. this._doUpdate(child);
  2087. }
  2088. prim._clearFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  2089. }
  2090. };
  2091. CanvasLayoutEngine.prototype._doUpdate = function (prim) {
  2092. // Canvas ?
  2093. if (prim instanceof BABYLON.Canvas2D) {
  2094. prim.layoutArea = prim.actualSize; //.multiplyByFloats(prim.scaleX, prim.scaleY);
  2095. }
  2096. else if (prim.parent instanceof BABYLON.Canvas2D) {
  2097. prim.layoutArea = prim.owner.actualSize; //.multiplyByFloats(prim.owner.scaleX, prim.owner.scaleY);
  2098. }
  2099. else {
  2100. prim.layoutArea = prim.parent.contentArea;
  2101. }
  2102. };
  2103. Object.defineProperty(CanvasLayoutEngine.prototype, "isChildPositionAllowed", {
  2104. get: function () {
  2105. return true;
  2106. },
  2107. enumerable: true,
  2108. configurable: true
  2109. });
  2110. return CanvasLayoutEngine;
  2111. }(LayoutEngineBase));
  2112. CanvasLayoutEngine.Singleton = new CanvasLayoutEngine_1();
  2113. CanvasLayoutEngine = CanvasLayoutEngine_1 = __decorate([
  2114. BABYLON.className("CanvasLayoutEngine", "BABYLON")
  2115. ], CanvasLayoutEngine);
  2116. BABYLON.CanvasLayoutEngine = CanvasLayoutEngine;
  2117. var StackPanelLayoutEngine = StackPanelLayoutEngine_1 = (function (_super) {
  2118. __extends(StackPanelLayoutEngine, _super);
  2119. function StackPanelLayoutEngine() {
  2120. var _this = _super.call(this) || this;
  2121. _this._isHorizontal = true;
  2122. _this.layoutDirtyOnPropertyChangedMask = BABYLON.Prim2DBase.sizeProperty.flagId;
  2123. return _this;
  2124. }
  2125. Object.defineProperty(StackPanelLayoutEngine, "Horizontal", {
  2126. get: function () {
  2127. if (!StackPanelLayoutEngine_1._horizontal) {
  2128. StackPanelLayoutEngine_1._horizontal = new StackPanelLayoutEngine_1();
  2129. StackPanelLayoutEngine_1._horizontal.isHorizontal = true;
  2130. StackPanelLayoutEngine_1._horizontal.lock();
  2131. }
  2132. return StackPanelLayoutEngine_1._horizontal;
  2133. },
  2134. enumerable: true,
  2135. configurable: true
  2136. });
  2137. Object.defineProperty(StackPanelLayoutEngine, "Vertical", {
  2138. get: function () {
  2139. if (!StackPanelLayoutEngine_1._vertical) {
  2140. StackPanelLayoutEngine_1._vertical = new StackPanelLayoutEngine_1();
  2141. StackPanelLayoutEngine_1._vertical.isHorizontal = false;
  2142. StackPanelLayoutEngine_1._vertical.lock();
  2143. }
  2144. return StackPanelLayoutEngine_1._vertical;
  2145. },
  2146. enumerable: true,
  2147. configurable: true
  2148. });
  2149. Object.defineProperty(StackPanelLayoutEngine.prototype, "isHorizontal", {
  2150. get: function () {
  2151. return this._isHorizontal;
  2152. },
  2153. set: function (val) {
  2154. if (this.isLocked()) {
  2155. return;
  2156. }
  2157. this._isHorizontal = val;
  2158. },
  2159. enumerable: true,
  2160. configurable: true
  2161. });
  2162. StackPanelLayoutEngine.prototype.updateLayout = function (prim) {
  2163. if (prim._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty)) {
  2164. var x = 0;
  2165. var y = 0;
  2166. var h = this.isHorizontal;
  2167. var max = 0;
  2168. for (var _i = 0, _a = prim.children; _i < _a.length; _i++) {
  2169. var child = _a[_i];
  2170. if (child._isFlagSet(BABYLON.SmartPropertyPrim.flagNoPartOfLayout)) {
  2171. continue;
  2172. }
  2173. var layoutArea = void 0;
  2174. if (child._hasMargin) {
  2175. child.margin.computeWithAlignment(prim.layoutArea, child.actualSize, child.marginAlignment, StackPanelLayoutEngine_1.dstOffset, StackPanelLayoutEngine_1.dstArea, true);
  2176. layoutArea = StackPanelLayoutEngine_1.dstArea.clone();
  2177. child.layoutArea = layoutArea;
  2178. }
  2179. else {
  2180. layoutArea = child.layoutArea;
  2181. child.margin.computeArea(child.actualSize, layoutArea);
  2182. }
  2183. max = Math.max(max, h ? layoutArea.height : layoutArea.width);
  2184. }
  2185. for (var _b = 0, _c = prim.children; _b < _c.length; _b++) {
  2186. var child = _c[_b];
  2187. if (child._isFlagSet(BABYLON.SmartPropertyPrim.flagNoPartOfLayout)) {
  2188. continue;
  2189. }
  2190. child.layoutAreaPos = new BABYLON.Vector2(x, y);
  2191. var layoutArea = child.layoutArea;
  2192. if (h) {
  2193. x += layoutArea.width;
  2194. child.layoutArea = new BABYLON.Size(layoutArea.width, max);
  2195. }
  2196. else {
  2197. y += layoutArea.height;
  2198. child.layoutArea = new BABYLON.Size(max, layoutArea.height);
  2199. }
  2200. }
  2201. prim._clearFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  2202. }
  2203. };
  2204. Object.defineProperty(StackPanelLayoutEngine.prototype, "isChildPositionAllowed", {
  2205. get: function () {
  2206. return false;
  2207. },
  2208. enumerable: true,
  2209. configurable: true
  2210. });
  2211. return StackPanelLayoutEngine;
  2212. }(LayoutEngineBase));
  2213. StackPanelLayoutEngine._horizontal = null;
  2214. StackPanelLayoutEngine._vertical = null;
  2215. StackPanelLayoutEngine.dstOffset = BABYLON.Vector4.Zero();
  2216. StackPanelLayoutEngine.dstArea = BABYLON.Size.Zero();
  2217. StackPanelLayoutEngine = StackPanelLayoutEngine_1 = __decorate([
  2218. BABYLON.className("StackPanelLayoutEngine", "BABYLON")
  2219. ], StackPanelLayoutEngine);
  2220. BABYLON.StackPanelLayoutEngine = StackPanelLayoutEngine;
  2221. var CanvasLayoutEngine_1, StackPanelLayoutEngine_1;
  2222. })(BABYLON || (BABYLON = {}));
  2223. //# sourceMappingURL=babylon.canvas2dLayoutEngine.js.map
  2224. var __extends = (this && this.__extends) || function (d, b) {
  2225. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  2226. function __() { this.constructor = d; }
  2227. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2228. };
  2229. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2230. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  2231. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  2232. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  2233. return c > 3 && r && Object.defineProperty(target, key, r), r;
  2234. };
  2235. var BABYLON;
  2236. (function (BABYLON) {
  2237. /**
  2238. * Base class implementing the ILocable interface.
  2239. * The particularity of this class is to call the protected onLock() method when the instance is about to be locked for good.
  2240. */
  2241. var LockableBase = (function () {
  2242. function LockableBase() {
  2243. }
  2244. LockableBase.prototype.isLocked = function () {
  2245. return this._isLocked;
  2246. };
  2247. LockableBase.prototype.lock = function () {
  2248. if (this._isLocked) {
  2249. return true;
  2250. }
  2251. this.onLock();
  2252. this._isLocked = true;
  2253. return false;
  2254. };
  2255. /**
  2256. * Protected handler that will be called when the instance is about to be locked.
  2257. */
  2258. LockableBase.prototype.onLock = function () {
  2259. };
  2260. return LockableBase;
  2261. }());
  2262. BABYLON.LockableBase = LockableBase;
  2263. var SolidColorBrush2D = (function (_super) {
  2264. __extends(SolidColorBrush2D, _super);
  2265. function SolidColorBrush2D(color, lock) {
  2266. if (lock === void 0) { lock = false; }
  2267. var _this = _super.call(this) || this;
  2268. _this._color = color;
  2269. if (lock) {
  2270. {
  2271. _this.lock();
  2272. }
  2273. }
  2274. return _this;
  2275. }
  2276. /**
  2277. * Return true if the brush is transparent, false if it's totally opaque
  2278. */
  2279. SolidColorBrush2D.prototype.isTransparent = function () {
  2280. return this._color && this._color.a < 1.0;
  2281. };
  2282. Object.defineProperty(SolidColorBrush2D.prototype, "color", {
  2283. /**
  2284. * The color used by this instance to render
  2285. * @returns the color object. Note that it's not a clone of the actual object stored in the instance so you MUST NOT modify it, otherwise unexpected behavior might occurs.
  2286. */
  2287. get: function () {
  2288. return this._color;
  2289. },
  2290. set: function (value) {
  2291. if (this.isLocked()) {
  2292. return;
  2293. }
  2294. this._color = value;
  2295. },
  2296. enumerable: true,
  2297. configurable: true
  2298. });
  2299. /**
  2300. * Return a unique identifier of the instance, which is simply the hexadecimal representation (CSS Style) of the solid color.
  2301. */
  2302. SolidColorBrush2D.prototype.toString = function () {
  2303. return this._color.toHexString();
  2304. };
  2305. return SolidColorBrush2D;
  2306. }(LockableBase));
  2307. SolidColorBrush2D = __decorate([
  2308. BABYLON.className("SolidColorBrush2D", "BABYLON")
  2309. ], SolidColorBrush2D);
  2310. BABYLON.SolidColorBrush2D = SolidColorBrush2D;
  2311. var GradientColorBrush2D = (function (_super) {
  2312. __extends(GradientColorBrush2D, _super);
  2313. function GradientColorBrush2D(color1, color2, translation, rotation, scale, lock) {
  2314. if (translation === void 0) { translation = BABYLON.Vector2.Zero(); }
  2315. if (rotation === void 0) { rotation = 0; }
  2316. if (scale === void 0) { scale = 1; }
  2317. if (lock === void 0) { lock = false; }
  2318. var _this = _super.call(this) || this;
  2319. _this._color1 = color1;
  2320. _this._color2 = color2;
  2321. _this._translation = translation;
  2322. _this._rotation = rotation;
  2323. _this._scale = scale;
  2324. if (lock) {
  2325. _this.lock();
  2326. }
  2327. return _this;
  2328. }
  2329. /**
  2330. * Return true if the brush is transparent, false if it's totally opaque
  2331. */
  2332. GradientColorBrush2D.prototype.isTransparent = function () {
  2333. return (this._color1 && this._color1.a < 1.0) || (this._color2 && this._color2.a < 1.0);
  2334. };
  2335. Object.defineProperty(GradientColorBrush2D.prototype, "color1", {
  2336. /**
  2337. * First color, the blend will start from this color
  2338. */
  2339. get: function () {
  2340. return this._color1;
  2341. },
  2342. set: function (value) {
  2343. if (this.isLocked()) {
  2344. return;
  2345. }
  2346. this._color1 = value;
  2347. },
  2348. enumerable: true,
  2349. configurable: true
  2350. });
  2351. Object.defineProperty(GradientColorBrush2D.prototype, "color2", {
  2352. /**
  2353. * Second color, the blend will end to this color
  2354. */
  2355. get: function () {
  2356. return this._color2;
  2357. },
  2358. set: function (value) {
  2359. if (this.isLocked()) {
  2360. return;
  2361. }
  2362. this._color2 = value;
  2363. },
  2364. enumerable: true,
  2365. configurable: true
  2366. });
  2367. Object.defineProperty(GradientColorBrush2D.prototype, "translation", {
  2368. /**
  2369. * Translation vector to apply on the blend
  2370. * Default is [0;0]
  2371. */
  2372. get: function () {
  2373. return this._translation;
  2374. },
  2375. set: function (value) {
  2376. if (this.isLocked()) {
  2377. return;
  2378. }
  2379. this._translation = value;
  2380. },
  2381. enumerable: true,
  2382. configurable: true
  2383. });
  2384. Object.defineProperty(GradientColorBrush2D.prototype, "rotation", {
  2385. /**
  2386. * Rotation in radian to apply to the brush
  2387. * Default direction of the brush is vertical, you can change this using this property.
  2388. * Default is 0.
  2389. */
  2390. get: function () {
  2391. return this._rotation;
  2392. },
  2393. set: function (value) {
  2394. if (this.isLocked()) {
  2395. return;
  2396. }
  2397. this._rotation = value;
  2398. },
  2399. enumerable: true,
  2400. configurable: true
  2401. });
  2402. Object.defineProperty(GradientColorBrush2D.prototype, "scale", {
  2403. /**
  2404. * Scale factor to apply to the gradient.
  2405. * Default is 1: no scale.
  2406. */
  2407. get: function () {
  2408. return this._scale;
  2409. },
  2410. set: function (value) {
  2411. if (this.isLocked()) {
  2412. return;
  2413. }
  2414. this._scale = value;
  2415. },
  2416. enumerable: true,
  2417. configurable: true
  2418. });
  2419. /**
  2420. * Return a string describing the brush
  2421. */
  2422. GradientColorBrush2D.prototype.toString = function () {
  2423. return "C1:" + this._color1 + ";C2:" + this._color2 + ";T:" + this._translation.toString() + ";R:" + this._rotation + ";S:" + this._scale + ";";
  2424. };
  2425. /**
  2426. * Build a unique key string for the given parameters
  2427. */
  2428. GradientColorBrush2D.BuildKey = function (color1, color2, translation, rotation, scale) {
  2429. return "C1:" + color1 + ";C2:" + color2 + ";T:" + translation.toString() + ";R:" + rotation + ";S:" + scale + ";";
  2430. };
  2431. return GradientColorBrush2D;
  2432. }(LockableBase));
  2433. GradientColorBrush2D = __decorate([
  2434. BABYLON.className("GradientColorBrush2D", "BABYLON")
  2435. ], GradientColorBrush2D);
  2436. BABYLON.GradientColorBrush2D = GradientColorBrush2D;
  2437. })(BABYLON || (BABYLON = {}));
  2438. //# sourceMappingURL=babylon.brushes2d.js.map
  2439. var __extends = (this && this.__extends) || function (d, b) {
  2440. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  2441. function __() { this.constructor = d; }
  2442. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2443. };
  2444. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2445. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  2446. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  2447. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  2448. return c > 3 && r && Object.defineProperty(target, key, r), r;
  2449. };
  2450. var BABYLON;
  2451. (function (BABYLON) {
  2452. var Prim2DClassInfo = (function () {
  2453. function Prim2DClassInfo() {
  2454. }
  2455. return Prim2DClassInfo;
  2456. }());
  2457. BABYLON.Prim2DClassInfo = Prim2DClassInfo;
  2458. var Prim2DPropInfo = (function () {
  2459. function Prim2DPropInfo() {
  2460. }
  2461. return Prim2DPropInfo;
  2462. }());
  2463. Prim2DPropInfo.PROPKIND_MODEL = 1;
  2464. Prim2DPropInfo.PROPKIND_INSTANCE = 2;
  2465. Prim2DPropInfo.PROPKIND_DYNAMIC = 3;
  2466. BABYLON.Prim2DPropInfo = Prim2DPropInfo;
  2467. var ClassTreeInfo = (function () {
  2468. function ClassTreeInfo(baseClass, type, classContentFactory) {
  2469. this._baseClass = baseClass;
  2470. this._type = type;
  2471. this._subClasses = new Array();
  2472. this._levelContent = new BABYLON.StringDictionary();
  2473. this._classContentFactory = classContentFactory;
  2474. }
  2475. Object.defineProperty(ClassTreeInfo.prototype, "classContent", {
  2476. get: function () {
  2477. if (!this._classContent) {
  2478. this._classContent = this._classContentFactory(this._baseClass ? this._baseClass.classContent : null);
  2479. }
  2480. return this._classContent;
  2481. },
  2482. enumerable: true,
  2483. configurable: true
  2484. });
  2485. Object.defineProperty(ClassTreeInfo.prototype, "type", {
  2486. get: function () {
  2487. return this._type;
  2488. },
  2489. enumerable: true,
  2490. configurable: true
  2491. });
  2492. Object.defineProperty(ClassTreeInfo.prototype, "levelContent", {
  2493. get: function () {
  2494. return this._levelContent;
  2495. },
  2496. enumerable: true,
  2497. configurable: true
  2498. });
  2499. Object.defineProperty(ClassTreeInfo.prototype, "fullContent", {
  2500. get: function () {
  2501. if (!this._fullContent) {
  2502. var dic_1 = new BABYLON.StringDictionary();
  2503. var curLevel = this;
  2504. while (curLevel) {
  2505. curLevel.levelContent.forEach(function (k, v) { return dic_1.add(k, v); });
  2506. curLevel = curLevel._baseClass;
  2507. }
  2508. this._fullContent = dic_1;
  2509. }
  2510. return this._fullContent;
  2511. },
  2512. enumerable: true,
  2513. configurable: true
  2514. });
  2515. ClassTreeInfo.prototype.getLevelOf = function (type) {
  2516. // Are we already there?
  2517. if (type === this._type) {
  2518. return this;
  2519. }
  2520. var baseProto = Object.getPrototypeOf(type);
  2521. var curProtoContent = this.getOrAddType(Object.getPrototypeOf(baseProto), baseProto);
  2522. if (!curProtoContent) {
  2523. this.getLevelOf(baseProto);
  2524. }
  2525. return this.getOrAddType(baseProto, type);
  2526. };
  2527. ClassTreeInfo.prototype.getOrAddType = function (baseType, type) {
  2528. // Are we at the level corresponding to the baseType?
  2529. // If so, get or add the level we're looking for
  2530. if (baseType === this._type) {
  2531. for (var _i = 0, _a = this._subClasses; _i < _a.length; _i++) {
  2532. var subType = _a[_i];
  2533. if (subType.type === type) {
  2534. return subType.node;
  2535. }
  2536. }
  2537. var node = new ClassTreeInfo(this, type, this._classContentFactory);
  2538. var info = { type: type, node: node };
  2539. this._subClasses.push(info);
  2540. return info.node;
  2541. }
  2542. // Recurse down to keep looking for the node corresponding to the baseTypeName
  2543. for (var _b = 0, _c = this._subClasses; _b < _c.length; _b++) {
  2544. var subType = _c[_b];
  2545. var info = subType.node.getOrAddType(baseType, type);
  2546. if (info) {
  2547. return info;
  2548. }
  2549. }
  2550. return null;
  2551. };
  2552. ClassTreeInfo.get = function (type) {
  2553. var dic = type["__classTreeInfo"];
  2554. if (!dic) {
  2555. return null;
  2556. }
  2557. return dic.getLevelOf(type);
  2558. };
  2559. ClassTreeInfo.getOrRegister = function (type, classContentFactory) {
  2560. var dic = type["__classTreeInfo"];
  2561. if (!dic) {
  2562. dic = new ClassTreeInfo(null, type, classContentFactory);
  2563. type["__classTreeInfo"] = dic;
  2564. }
  2565. return dic;
  2566. };
  2567. return ClassTreeInfo;
  2568. }());
  2569. BABYLON.ClassTreeInfo = ClassTreeInfo;
  2570. var DataBinding = DataBinding_1 = (function () {
  2571. function DataBinding() {
  2572. this._converter = null;
  2573. this._mode = DataBinding_1.MODE_DEFAULT;
  2574. this._uiElementId = null;
  2575. this._dataSource = null;
  2576. this._currentDataSource = null;
  2577. this._propertyPathName = null;
  2578. this._stringFormat = null;
  2579. this._updateSourceTrigger = DataBinding_1.UPDATESOURCETRIGGER_PROPERTYCHANGED;
  2580. this._boundTo = null;
  2581. this._owner = null;
  2582. this._updateCounter = 0;
  2583. }
  2584. Object.defineProperty(DataBinding.prototype, "converter", {
  2585. /**
  2586. * Provide a callback that will convert the value obtained by the Data Binding to the type of the SmartProperty it's bound to.
  2587. * If no value are set, then it's assumed that the sourceValue is of the same type as the SmartProperty's one.
  2588. * If the SmartProperty type is a basic data type (string, boolean or number) and no converter is specified but the sourceValue is of a different type, the conversion will be implicitly made, if possible.
  2589. * @param sourceValue the source object retrieve by the Data Binding mechanism
  2590. * @returns the object of a compatible type with the SmartProperty it's bound to
  2591. */
  2592. get: function () {
  2593. return this._converter;
  2594. },
  2595. set: function (value) {
  2596. if (this._converter === value) {
  2597. return;
  2598. }
  2599. this._converter = value;
  2600. },
  2601. enumerable: true,
  2602. configurable: true
  2603. });
  2604. Object.defineProperty(DataBinding.prototype, "mode", {
  2605. /**
  2606. * Set the mode to use for the data flow in the binding. Set one of the MODE_xxx static member of this class. If not specified then MODE_DEFAULT will be used
  2607. */
  2608. get: function () {
  2609. if (this._mode === DataBinding_1.MODE_DEFAULT) {
  2610. return this._boundTo.bindingMode;
  2611. }
  2612. return this._mode;
  2613. },
  2614. set: function (value) {
  2615. if (this._mode === value) {
  2616. return;
  2617. }
  2618. this._mode = value;
  2619. },
  2620. enumerable: true,
  2621. configurable: true
  2622. });
  2623. Object.defineProperty(DataBinding.prototype, "uiElementId", {
  2624. /**
  2625. * You can override the Data Source object with this member which is the Id of a uiElement existing in the UI Logical tree.
  2626. * If not set and source no set too, then the dataSource property will be used.
  2627. */
  2628. get: function () {
  2629. return this._uiElementId;
  2630. },
  2631. set: function (value) {
  2632. if (this._uiElementId === value) {
  2633. return;
  2634. }
  2635. this._uiElementId = value;
  2636. },
  2637. enumerable: true,
  2638. configurable: true
  2639. });
  2640. Object.defineProperty(DataBinding.prototype, "dataSource", {
  2641. /**
  2642. * You can override the Data Source object with this member which is the source object to use directly.
  2643. * If not set and uiElement no set too, then the dataSource property of the SmartPropertyBase object will be used.
  2644. */
  2645. get: function () {
  2646. return this._dataSource;
  2647. },
  2648. set: function (value) {
  2649. if (this._dataSource === value) {
  2650. return;
  2651. }
  2652. this._dataSource = value;
  2653. },
  2654. enumerable: true,
  2655. configurable: true
  2656. });
  2657. Object.defineProperty(DataBinding.prototype, "propertyPathName", {
  2658. /**
  2659. * The path & name of the property to get from the source object.
  2660. * Once the Source object is evaluated (it's either the one got from uiElementId, source or dataSource) you can specify which property of this object is the value to bind to the smartProperty.
  2661. * If nothing is set then the source object will be used.
  2662. * You can specify an indirect property using the format "firstProperty.indirectProperty" like "address.postalCode" if the source is a Customer object which contains an address property and the Address class contains a postalCode property.
  2663. * If the property is an Array and you want to address a particular element then use the 'arrayProperty[index]' notation. For example "phoneNumbers[0]" to get the first element of the phoneNumber property which is an array.
  2664. */
  2665. get: function () {
  2666. return this._propertyPathName;
  2667. },
  2668. set: function (value) {
  2669. if (this._propertyPathName === value) {
  2670. return;
  2671. }
  2672. if (this._owner) {
  2673. }
  2674. this._propertyPathName = value;
  2675. if (this._owner) {
  2676. }
  2677. },
  2678. enumerable: true,
  2679. configurable: true
  2680. });
  2681. Object.defineProperty(DataBinding.prototype, "stringFormat", {
  2682. /**
  2683. * If the Smart Property is of the string type, you can use the string interpolation notation to provide how the sourceValue will be formatted, reference to the source value must be made via the token: ${value}. For instance `Customer Name: ${value}`
  2684. */
  2685. get: function () {
  2686. return this._stringFormat;
  2687. },
  2688. set: function (value) {
  2689. if (this._stringFormat === value) {
  2690. return;
  2691. }
  2692. this._stringFormat = value;
  2693. },
  2694. enumerable: true,
  2695. configurable: true
  2696. });
  2697. Object.defineProperty(DataBinding.prototype, "updateSourceTrigger", {
  2698. /**
  2699. * Specify how the source should be updated, use one of the UPDATESOURCETRIGGER_xxx member of this class, if not specified then UPDATESOURCETRIGGER_DEFAULT will be used.
  2700. */
  2701. get: function () {
  2702. return this._updateSourceTrigger;
  2703. },
  2704. set: function (value) {
  2705. if (this._updateSourceTrigger === value) {
  2706. return;
  2707. }
  2708. this._updateSourceTrigger = value;
  2709. },
  2710. enumerable: true,
  2711. configurable: true
  2712. });
  2713. DataBinding.prototype.canUpdateTarget = function (resetUpdateCounter) {
  2714. if (resetUpdateCounter) {
  2715. this._updateCounter = 0;
  2716. }
  2717. var mode = this.mode;
  2718. if (mode === DataBinding_1.MODE_ONETIME) {
  2719. return this._updateCounter === 0;
  2720. }
  2721. if (mode === DataBinding_1.MODE_ONEWAYTOSOURCE) {
  2722. return false;
  2723. }
  2724. return true;
  2725. };
  2726. DataBinding.prototype.updateTarget = function () {
  2727. var value = this._getActualDataSource();
  2728. var properties = this.propertyPathName.split(".");
  2729. for (var _i = 0, properties_1 = properties; _i < properties_1.length; _i++) {
  2730. var propertyName = properties_1[_i];
  2731. value = value[propertyName];
  2732. }
  2733. this._storeBoundValue(this._owner, value);
  2734. };
  2735. DataBinding.prototype._storeBoundValue = function (watcher, value) {
  2736. if ((++this._updateCounter > 1) && (this.mode === DataBinding_1.MODE_ONETIME)) {
  2737. return;
  2738. }
  2739. var newValue = value;
  2740. if (this._converter) {
  2741. newValue = this._converter(value);
  2742. }
  2743. if (this._stringFormat) {
  2744. newValue = this._stringFormat(newValue);
  2745. }
  2746. watcher[this._boundTo.name] = newValue;
  2747. };
  2748. DataBinding.prototype._getActualDataSource = function () {
  2749. if (this.dataSource) {
  2750. return this.dataSource;
  2751. }
  2752. if (this.uiElementId) {
  2753. // TODO Find UIElement
  2754. return null;
  2755. }
  2756. return this._owner.dataSource;
  2757. };
  2758. DataBinding.prototype._registerDataSource = function (updateTarget) {
  2759. var ds = this._getActualDataSource();
  2760. if (ds === this._currentDataSource) {
  2761. return;
  2762. }
  2763. if (this._currentDataSource) {
  2764. BindingHelper.unregisterDataSource(this._currentDataSource, this, 0);
  2765. }
  2766. if (ds) {
  2767. BindingHelper.registerDataSource(ds, this);
  2768. if (updateTarget && this.canUpdateTarget(true)) {
  2769. this.updateTarget();
  2770. }
  2771. }
  2772. this._currentDataSource = ds;
  2773. };
  2774. DataBinding.prototype._unregisterDataSource = function () {
  2775. var ds = this._getActualDataSource();
  2776. if (ds) {
  2777. BindingHelper.unregisterDataSource(ds, this, 0);
  2778. }
  2779. };
  2780. return DataBinding;
  2781. }());
  2782. /**
  2783. * Use the mode specified in the SmartProperty declaration
  2784. */
  2785. DataBinding.MODE_DEFAULT = 1;
  2786. /**
  2787. * Update the binding target only once when the Smart Property's value is first accessed
  2788. */
  2789. DataBinding.MODE_ONETIME = 2;
  2790. /**
  2791. * Update the smart property when the source changes.
  2792. * The source won't be updated if the smart property value is set.
  2793. */
  2794. DataBinding.MODE_ONEWAY = 3;
  2795. /**
  2796. * Only update the source when the target's data is changing.
  2797. */
  2798. DataBinding.MODE_ONEWAYTOSOURCE = 4;
  2799. /**
  2800. * Update the bind target when the source changes and update the source when the Smart Property value is set.
  2801. */
  2802. DataBinding.MODE_TWOWAY = 5;
  2803. /**
  2804. * Use the Update Source Trigger defined in the SmartProperty declaration
  2805. */
  2806. DataBinding.UPDATESOURCETRIGGER_DEFAULT = 1;
  2807. /**
  2808. * Update the source as soon as the Smart Property has a value change
  2809. */
  2810. DataBinding.UPDATESOURCETRIGGER_PROPERTYCHANGED = 2;
  2811. /**
  2812. * Update the source when the binding target loses focus
  2813. */
  2814. DataBinding.UPDATESOURCETRIGGER_LOSTFOCUS = 3;
  2815. /**
  2816. * Update the source will be made by explicitly calling the UpdateFromDataSource method
  2817. */
  2818. DataBinding.UPDATESOURCETRIGGER_EXPLICIT = 4;
  2819. DataBinding = DataBinding_1 = __decorate([
  2820. BABYLON.className("DataBinding", "BABYLON")
  2821. ], DataBinding);
  2822. BABYLON.DataBinding = DataBinding;
  2823. var SmartPropertyBase = SmartPropertyBase_1 = (function (_super) {
  2824. __extends(SmartPropertyBase, _super);
  2825. function SmartPropertyBase() {
  2826. var _this = _super.call(this) || this;
  2827. _this._dataSource = null;
  2828. _this._dataSourceObserver = null;
  2829. _this._instanceDirtyFlags = 0;
  2830. _this._isDisposed = false;
  2831. _this._bindings = null;
  2832. _this._hasBinding = 0;
  2833. _this._bindingSourceChanged = 0;
  2834. _this._disposeObservable = null;
  2835. return _this;
  2836. }
  2837. Object.defineProperty(SmartPropertyBase.prototype, "disposeObservable", {
  2838. get: function () {
  2839. if (!this._disposeObservable) {
  2840. this._disposeObservable = new BABYLON.Observable();
  2841. }
  2842. return this._disposeObservable;
  2843. },
  2844. enumerable: true,
  2845. configurable: true
  2846. });
  2847. Object.defineProperty(SmartPropertyBase.prototype, "isDisposed", {
  2848. /**
  2849. * Check if the object is disposed or not.
  2850. * @returns true if the object is dispose, false otherwise.
  2851. */
  2852. get: function () {
  2853. return this._isDisposed;
  2854. },
  2855. enumerable: true,
  2856. configurable: true
  2857. });
  2858. /**
  2859. * Disposable pattern, this method must be overloaded by derived types in order to clean up hardware related resources.
  2860. * @returns false if the object is already dispose, true otherwise. Your implementation must call super.dispose() and check for a false return and return immediately if it's the case.
  2861. */
  2862. SmartPropertyBase.prototype.dispose = function () {
  2863. if (this.isDisposed) {
  2864. return false;
  2865. }
  2866. if (this._disposeObservable && this._disposeObservable.hasObservers()) {
  2867. this._disposeObservable.notifyObservers(this);
  2868. }
  2869. this._isDisposed = true;
  2870. return true;
  2871. };
  2872. /**
  2873. * Check if a given set of properties are dirty or not.
  2874. * @param flags a ORed combination of Prim2DPropInfo.flagId values
  2875. * @return true if at least one property is dirty, false if none of them are.
  2876. */
  2877. SmartPropertyBase.prototype.checkPropertiesDirty = function (flags) {
  2878. return (this._instanceDirtyFlags & flags) !== 0;
  2879. };
  2880. /**
  2881. * Clear a given set of properties.
  2882. * @param flags a ORed combination of Prim2DPropInfo.flagId values
  2883. * @return the new set of property still marked as dirty
  2884. */
  2885. SmartPropertyBase.prototype.clearPropertiesDirty = function (flags) {
  2886. this._instanceDirtyFlags &= ~flags;
  2887. return this._instanceDirtyFlags;
  2888. };
  2889. SmartPropertyBase.prototype._resetPropertiesDirty = function () {
  2890. this._instanceDirtyFlags = 0;
  2891. };
  2892. /**
  2893. * Add an externally attached data from its key.
  2894. * This method call will fail and return false, if such key already exists.
  2895. * If you don't care and just want to get the data no matter what, use the more convenient getOrAddExternalDataWithFactory() method.
  2896. * @param key the unique key that identifies the data
  2897. * @param data the data object to associate to the key for this Engine instance
  2898. * @return true if no such key were already present and the data was added successfully, false otherwise
  2899. */
  2900. SmartPropertyBase.prototype.addExternalData = function (key, data) {
  2901. if (!this._externalData) {
  2902. this._externalData = new BABYLON.StringDictionary();
  2903. }
  2904. return this._externalData.add(key, data);
  2905. };
  2906. /**
  2907. * Get an externally attached data from its key
  2908. * @param key the unique key that identifies the data
  2909. * @return the associated data, if present (can be null), or undefined if not present
  2910. */
  2911. SmartPropertyBase.prototype.getExternalData = function (key) {
  2912. if (!this._externalData) {
  2913. return null;
  2914. }
  2915. return this._externalData.get(key);
  2916. };
  2917. /**
  2918. * Get an externally attached data from its key, create it using a factory if it's not already present
  2919. * @param key the unique key that identifies the data
  2920. * @param factory the factory that will be called to create the instance if and only if it doesn't exists
  2921. * @return the associated data, can be null if the factory returned null.
  2922. */
  2923. SmartPropertyBase.prototype.getOrAddExternalDataWithFactory = function (key, factory) {
  2924. if (!this._externalData) {
  2925. this._externalData = new BABYLON.StringDictionary();
  2926. }
  2927. return this._externalData.getOrAddWithFactory(key, factory);
  2928. };
  2929. /**
  2930. * Remove an externally attached data from the Engine instance
  2931. * @param key the unique key that identifies the data
  2932. * @return true if the data was successfully removed, false if it doesn't exist
  2933. */
  2934. SmartPropertyBase.prototype.removeExternalData = function (key) {
  2935. if (!this._externalData) {
  2936. return false;
  2937. }
  2938. return this._externalData.remove(key);
  2939. };
  2940. SmartPropertyBase._hookProperty = function (propId, piStore, kind, settings) {
  2941. return function (target, propName, descriptor) {
  2942. if (!settings) {
  2943. settings = {};
  2944. }
  2945. var propInfo = SmartPropertyBase_1._createPropInfo(target, propName, propId, kind, settings);
  2946. if (piStore) {
  2947. piStore(propInfo);
  2948. }
  2949. var getter = descriptor.get, setter = descriptor.set;
  2950. var typeLevelCompare = (settings.typeLevelCompare !== undefined) ? settings.typeLevelCompare : false;
  2951. // Overload the property setter implementation to add our own logic
  2952. descriptor.set = function (val) {
  2953. if (!setter) {
  2954. throw Error("Property '" + propInfo.name + "' of type '" + BABYLON.Tools.getFullClassName(this) + "' has no setter defined but was invoked as if it had one.");
  2955. }
  2956. // check for disposed first, do nothing
  2957. if (this.isDisposed) {
  2958. return;
  2959. }
  2960. var curVal = getter.call(this);
  2961. if (SmartPropertyBase_1._checkUnchanged(curVal, val)) {
  2962. return;
  2963. }
  2964. // Cast the object we're working one
  2965. var prim = this;
  2966. // Change the value
  2967. setter.call(this, val);
  2968. // Notify change, dirty flags update
  2969. prim._handlePropChanged(curVal, val, propName, propInfo, typeLevelCompare);
  2970. };
  2971. };
  2972. };
  2973. SmartPropertyBase._createPropInfo = function (target, propName, propId, kind, settings) {
  2974. var dic = ClassTreeInfo.getOrRegister(target, function () { return new Prim2DClassInfo(); });
  2975. var node = dic.getLevelOf(target);
  2976. var propInfo = node.levelContent.get(propId.toString());
  2977. if (propInfo) {
  2978. throw new Error("The ID " + propId + " is already taken by another property declaration named: " + propInfo.name);
  2979. }
  2980. // Create, setup and add the PropInfo object to our prop dictionary
  2981. propInfo = new Prim2DPropInfo();
  2982. propInfo.id = propId;
  2983. propInfo.flagId = Math.pow(2, propId);
  2984. propInfo.kind = kind;
  2985. propInfo.name = propName;
  2986. propInfo.bindingMode = (settings.bindingMode !== undefined) ? settings.bindingMode : DataBinding.MODE_TWOWAY;
  2987. propInfo.bindingUpdateSourceTrigger = (settings.bindingUpdateSourceTrigger !== undefined) ? settings.bindingUpdateSourceTrigger : DataBinding.UPDATESOURCETRIGGER_PROPERTYCHANGED;
  2988. propInfo.dirtyBoundingInfo = (settings.dirtyBoundingInfo !== undefined) ? settings.dirtyBoundingInfo : false;
  2989. propInfo.dirtyParentBoundingInfo = (settings.dirtyParentBoundingBox !== undefined) ? settings.dirtyParentBoundingBox : false;
  2990. propInfo.typeLevelCompare = (settings.typeLevelCompare !== undefined) ? settings.typeLevelCompare : false;
  2991. node.levelContent.add(propName, propInfo);
  2992. return propInfo;
  2993. };
  2994. Object.defineProperty(SmartPropertyBase.prototype, "propDic", {
  2995. /**
  2996. * Access the dictionary of properties metadata. Only properties decorated with XXXXLevelProperty are concerned
  2997. * @returns the dictionary, the key is the property name as declared in Javascript, the value is the metadata object
  2998. */
  2999. get: function () {
  3000. if (!this._propInfo) {
  3001. var cti = ClassTreeInfo.get(Object.getPrototypeOf(this));
  3002. if (!cti) {
  3003. throw new Error("Can't access the propDic member in class definition, is this class SmartPropertyPrim based?");
  3004. }
  3005. this._propInfo = cti.fullContent;
  3006. }
  3007. return this._propInfo;
  3008. },
  3009. enumerable: true,
  3010. configurable: true
  3011. });
  3012. SmartPropertyBase._checkUnchanged = function (curValue, newValue) {
  3013. // Nothing to nothing: nothing to do!
  3014. if ((curValue === null && newValue === null) || (curValue === undefined && newValue === undefined)) {
  3015. return true;
  3016. }
  3017. // Check value unchanged
  3018. if ((curValue != null) && (newValue != null)) {
  3019. if (typeof (curValue.equals) == "function") {
  3020. if (curValue.equals(newValue)) {
  3021. return true;
  3022. }
  3023. }
  3024. else {
  3025. if (curValue === newValue) {
  3026. return true;
  3027. }
  3028. }
  3029. }
  3030. return false;
  3031. };
  3032. SmartPropertyBase.prototype._handlePropChanged = function (curValue, newValue, propName, propInfo, typeLevelCompare) {
  3033. // Trigger property changed
  3034. var info = SmartPropertyBase_1.propChangeGuarding ? new BABYLON.PropertyChangedInfo() : SmartPropertyPrim.propChangedInfo;
  3035. info.oldValue = curValue;
  3036. info.newValue = newValue;
  3037. info.propertyName = propName;
  3038. var propMask = propInfo ? propInfo.flagId : -1;
  3039. try {
  3040. SmartPropertyBase_1.propChangeGuarding = true;
  3041. this.propertyChanged.notifyObservers(info, propMask);
  3042. }
  3043. finally {
  3044. SmartPropertyBase_1.propChangeGuarding = false;
  3045. }
  3046. };
  3047. SmartPropertyBase.prototype._triggerPropertyChanged = function (propInfo, newValue) {
  3048. if (this.isDisposed) {
  3049. return;
  3050. }
  3051. if (!propInfo) {
  3052. return;
  3053. }
  3054. this._handlePropChanged(undefined, newValue, propInfo.name, propInfo, propInfo.typeLevelCompare);
  3055. };
  3056. Object.defineProperty(SmartPropertyBase.prototype, "dataSource", {
  3057. /**
  3058. * Set the object from which Smart Properties using Binding will take/update their data from/to.
  3059. * When the object is part of a graph (with parent/children relationship) if the dataSource of a given instance is not specified, then the parent's one is used.
  3060. */
  3061. get: function () {
  3062. // Don't access to _dataSource directly but via a call to the _getDataSource method which can be overloaded in inherited classes
  3063. return this._getDataSource();
  3064. },
  3065. set: function (value) {
  3066. if (this._dataSource === value) {
  3067. return;
  3068. }
  3069. var oldValue = this._dataSource;
  3070. this._dataSource = value;
  3071. if (this._bindings && value != null) {
  3072. // Register the bindings
  3073. for (var _i = 0, _a = this._bindings; _i < _a.length; _i++) {
  3074. var binding = _a[_i];
  3075. if (binding != null) {
  3076. binding._registerDataSource(true);
  3077. }
  3078. }
  3079. }
  3080. this.onPropertyChanged("dataSource", oldValue, value);
  3081. },
  3082. enumerable: true,
  3083. configurable: true
  3084. });
  3085. // Inheriting classes can overload this method to provides additional logic for dataSource access
  3086. SmartPropertyBase.prototype._getDataSource = function () {
  3087. return this._dataSource;
  3088. };
  3089. SmartPropertyBase.prototype.createSimpleDataBinding = function (propInfo, propertyPathName, mode) {
  3090. if (mode === void 0) { mode = DataBinding.MODE_DEFAULT; }
  3091. var binding = new DataBinding();
  3092. binding.propertyPathName = propertyPathName;
  3093. binding.mode = mode;
  3094. return this.createDataBinding(propInfo, binding);
  3095. };
  3096. SmartPropertyBase.prototype.createDataBinding = function (propInfo, binding) {
  3097. if (!this._bindings) {
  3098. this._bindings = new Array();
  3099. }
  3100. if (!binding || binding._owner != null) {
  3101. throw Error("A valid/unused Binding must be passed.");
  3102. }
  3103. // Unregister a potentially existing binding for this property
  3104. this.removeDataBinding(propInfo);
  3105. // register the binding
  3106. binding._owner = this;
  3107. binding._boundTo = propInfo;
  3108. this._bindings[propInfo.id] = binding;
  3109. this._hasBinding |= propInfo.flagId;
  3110. binding._registerDataSource(true);
  3111. return binding;
  3112. };
  3113. SmartPropertyBase.prototype.removeDataBinding = function (propInfo) {
  3114. if ((this._hasBinding & propInfo.flagId) === 0) {
  3115. return false;
  3116. }
  3117. var curBinding = this._bindings[propInfo.id];
  3118. curBinding._unregisterDataSource();
  3119. this._bindings[propInfo.id] = null;
  3120. this._hasBinding &= ~propInfo.flagId;
  3121. return true;
  3122. };
  3123. SmartPropertyBase.prototype.updateFromDataSource = function () {
  3124. for (var _i = 0, _a = this._bindings; _i < _a.length; _i++) {
  3125. var binding = _a[_i];
  3126. if (binding) {
  3127. }
  3128. }
  3129. };
  3130. return SmartPropertyBase;
  3131. }(BABYLON.PropertyChangedBase));
  3132. SmartPropertyBase.propChangedInfo = new BABYLON.PropertyChangedInfo();
  3133. SmartPropertyBase.propChangeGuarding = false;
  3134. SmartPropertyBase = SmartPropertyBase_1 = __decorate([
  3135. BABYLON.className("SmartPropertyBase", "BABYLON")
  3136. ], SmartPropertyBase);
  3137. BABYLON.SmartPropertyBase = SmartPropertyBase;
  3138. var BindingInfo = (function () {
  3139. function BindingInfo(binding, level, isLast) {
  3140. this.binding = binding;
  3141. this.level = level;
  3142. this.isLast = isLast;
  3143. }
  3144. return BindingInfo;
  3145. }());
  3146. var MonitoredObjectData = (function () {
  3147. function MonitoredObjectData(monitoredObject) {
  3148. var _this = this;
  3149. this.monitoredObject = monitoredObject;
  3150. this.monitoredIntermediateProperties = new BABYLON.StringDictionary();
  3151. this.observer = this.monitoredObject.propertyChanged.add(function (e, s) { _this.propertyChangedHandler(e.propertyName, e.oldValue, e.newValue); });
  3152. this.boundProperties = new BABYLON.StringDictionary();
  3153. this.monitoredIntermediateMask = 0;
  3154. this.boundPropertiesMask = 0;
  3155. }
  3156. MonitoredObjectData.prototype.propertyChangedHandler = function (propName, oldValue, newValue) {
  3157. var propId = BindingHelper._getPropertyID(this.monitoredObject, propName);
  3158. var propIdStr = propId.toString();
  3159. // Loop through all the registered bindings for this property that had a value change
  3160. if ((this.boundPropertiesMask & propId) !== 0) {
  3161. var bindingInfos = this.boundProperties.get(propIdStr);
  3162. for (var _i = 0, bindingInfos_1 = bindingInfos; _i < bindingInfos_1.length; _i++) {
  3163. var bi = bindingInfos_1[_i];
  3164. if (!bi.isLast) {
  3165. BindingHelper.unregisterDataSource(this.monitoredObject, bi.binding, bi.level);
  3166. BindingHelper.registerDataSource(bi.binding._currentDataSource, bi.binding);
  3167. }
  3168. if (bi.binding.canUpdateTarget(false)) {
  3169. bi.binding.updateTarget();
  3170. }
  3171. }
  3172. }
  3173. };
  3174. return MonitoredObjectData;
  3175. }());
  3176. var BindingHelper = (function () {
  3177. function BindingHelper() {
  3178. }
  3179. BindingHelper.registerDataSource = function (dataSource, binding) {
  3180. var properties = binding.propertyPathName.split(".");
  3181. var ownerMod = null;
  3182. var ownerInterPropId = 0;
  3183. var propertyOwner = dataSource;
  3184. var _loop_1 = function (i) {
  3185. var propName = properties[i];
  3186. var propId = BindingHelper._getPropertyID(propertyOwner, propName);
  3187. var propIdStr = propId.toString();
  3188. var mod = void 0;
  3189. if (ownerMod) {
  3190. var o_1 = ownerMod;
  3191. var po_1 = propertyOwner;
  3192. var oii_1 = ownerInterPropId;
  3193. mod = ownerMod.monitoredIntermediateProperties.getOrAddWithFactory(oii_1.toString(), function (k) {
  3194. o_1.monitoredIntermediateMask |= oii_1;
  3195. return BindingHelper._getMonitoredObjectData(po_1);
  3196. });
  3197. }
  3198. else {
  3199. mod = BindingHelper._getMonitoredObjectData(propertyOwner);
  3200. }
  3201. var m = mod;
  3202. var bindingInfos = mod.boundProperties.getOrAddWithFactory(propIdStr, function (k) {
  3203. m.boundPropertiesMask |= propId;
  3204. return new Array();
  3205. });
  3206. var bi = BABYLON.Tools.first(bindingInfos, function (cbi) { return cbi.binding === binding; });
  3207. if (!bi) {
  3208. bindingInfos.push(new BindingInfo(binding, i, (i + 1) === properties.length));
  3209. }
  3210. ownerMod = mod;
  3211. ownerInterPropId = propId;
  3212. propertyOwner = propertyOwner[propName];
  3213. };
  3214. for (var i = 0; i < properties.length; i++) {
  3215. _loop_1(i);
  3216. }
  3217. };
  3218. BindingHelper.unregisterDataSource = function (dataSource, binding, level) {
  3219. var properties = binding.propertyPathName.split(".");
  3220. var propertyOwner = dataSource;
  3221. var mod = BindingHelper._getMonitoredObjectData(propertyOwner);
  3222. for (var i = 0; i < properties.length; i++) {
  3223. var propName = properties[i];
  3224. var propId = BindingHelper._getPropertyID(propertyOwner, propName);
  3225. var propIdStr = propId.toString();
  3226. if (i >= level) {
  3227. mod = BindingHelper._unregisterBinding(mod, propId, binding);
  3228. }
  3229. else {
  3230. mod = mod.monitoredIntermediateProperties.get(propIdStr);
  3231. }
  3232. propertyOwner = propertyOwner[propName];
  3233. }
  3234. };
  3235. BindingHelper._unregisterBinding = function (mod, propertyID, binding) {
  3236. var propertyIDStr = propertyID.toString();
  3237. var res = null;
  3238. // Check if the property is registered as an intermediate and remove it
  3239. if ((mod.monitoredIntermediateMask & propertyID) !== 0) {
  3240. res = mod.monitoredIntermediateProperties.get(propertyIDStr);
  3241. mod.monitoredIntermediateProperties.remove(propertyIDStr);
  3242. // Update the mask
  3243. mod.monitoredIntermediateMask &= ~propertyID;
  3244. }
  3245. // Check if the property is registered as a final property and remove it
  3246. if ((mod.boundPropertiesMask & propertyID) !== 0) {
  3247. var bindingInfos = mod.boundProperties.get(propertyIDStr);
  3248. // Find the binding and remove it
  3249. var bi = BABYLON.Tools.first(bindingInfos, function (cbi) { return cbi.binding === binding; });
  3250. if (bi) {
  3251. var bii = bindingInfos.indexOf(bi);
  3252. bindingInfos.splice(bii, 1);
  3253. }
  3254. // If the array is empty, update the mask
  3255. if (bindingInfos.length === 0) {
  3256. mod.boundPropertiesMask &= ~propertyID;
  3257. }
  3258. }
  3259. // Check if the MOD is empty and unregister the observer and remove it from the list of MODs
  3260. if (mod.boundPropertiesMask === 0 && mod.monitoredIntermediateMask === 0) {
  3261. // Unregister the observer on Property Change
  3262. mod.monitoredObject.propertyChanged.remove(mod.observer);
  3263. // Remove the MOD from the dic
  3264. var objectId = BindingHelper._getObjectId(mod.monitoredObject);
  3265. BindingHelper._monitoredObjects.remove(objectId);
  3266. }
  3267. return res;
  3268. };
  3269. BindingHelper._getMonitoredObjectData = function (object) {
  3270. var objectId = BindingHelper._getObjectId(object);
  3271. var mod = BindingHelper._monitoredObjects.getOrAddWithFactory(objectId, function (k) { return new MonitoredObjectData(object); });
  3272. return mod;
  3273. };
  3274. BindingHelper._getObjectId = function (obj) {
  3275. var id = obj["__bindingHelperObjectId__"];
  3276. if (id == null) {
  3277. id = BABYLON.Tools.RandomId();
  3278. obj["__bindingHelperObjectId__"] = id;
  3279. return id;
  3280. }
  3281. return id;
  3282. };
  3283. BindingHelper._getObjectTypePropertyIDs = function (obj) {
  3284. var fullName = BABYLON.Tools.getFullClassName(obj);
  3285. if (!fullName) {
  3286. throw Error("Types involved in Data Binding must be decorated with the @className decorator");
  3287. }
  3288. var d = BindingHelper._propertiesID.getOrAddWithFactory(fullName, function () { return new BABYLON.StringDictionary(); });
  3289. return d;
  3290. };
  3291. BindingHelper._getPropertyID = function (object, propName) {
  3292. var otd = BindingHelper._getObjectTypePropertyIDs(object);
  3293. // Make sure we have a WatchedPropertyData for this property of this object type. This will contains the flagIg of the watched property.
  3294. // We use this flagId to flag for each watched instance which properties are watched, as final or intermediate and which directions are used
  3295. var propData = otd.getOrAddWithFactory(propName, function (k) { return 1 << otd.count; });
  3296. return propData;
  3297. };
  3298. return BindingHelper;
  3299. }());
  3300. BindingHelper._propertiesID = new BABYLON.StringDictionary();
  3301. BindingHelper._monitoredObjects = new BABYLON.StringDictionary();
  3302. var SmartPropertyPrim = SmartPropertyPrim_1 = (function (_super) {
  3303. __extends(SmartPropertyPrim, _super);
  3304. function SmartPropertyPrim() {
  3305. var _this = _super.call(this) || this;
  3306. _this._flags = 0;
  3307. _this._modelKey = null;
  3308. _this._levelBoundingInfo = new BABYLON.BoundingInfo2D();
  3309. _this._boundingInfo = new BABYLON.BoundingInfo2D();
  3310. _this.animations = new Array();
  3311. return _this;
  3312. }
  3313. /**
  3314. * Disposable pattern, this method must be overloaded by derived types in order to clean up hardware related resources.
  3315. * @returns false if the object is already dispose, true otherwise. Your implementation must call super.dispose() and check for a false return and return immediately if it's the case.
  3316. */
  3317. SmartPropertyPrim.prototype.dispose = function () {
  3318. if (this.isDisposed) {
  3319. return false;
  3320. }
  3321. _super.prototype.dispose.call(this);
  3322. // Don't set to null, it may upset somebody...
  3323. this.animations.splice(0);
  3324. return true;
  3325. };
  3326. /**
  3327. * Returns as a new array populated with the Animatable used by the primitive. Must be overloaded by derived primitives.
  3328. * Look at Sprite2D for more information
  3329. */
  3330. SmartPropertyPrim.prototype.getAnimatables = function () {
  3331. return new Array();
  3332. };
  3333. Object.defineProperty(SmartPropertyPrim.prototype, "modelKey", {
  3334. /**
  3335. * Property giving the Model Key associated to the property.
  3336. * This value is constructed from the type of the primitive and all the name/value of its properties declared with the modelLevelProperty decorator
  3337. * @returns the model key string.
  3338. */
  3339. get: function () {
  3340. var _this = this;
  3341. // No need to compute it?
  3342. if (!this._isFlagSet(SmartPropertyPrim_1.flagModelDirty) && this._modelKey) {
  3343. return this._modelKey;
  3344. }
  3345. var modelKey = "Class:" + BABYLON.Tools.getClassName(this) + ";";
  3346. var propDic = this.propDic;
  3347. propDic.forEach(function (k, v) {
  3348. if (v.kind === Prim2DPropInfo.PROPKIND_MODEL) {
  3349. var propVal = _this[v.name];
  3350. // Special case, array, this WON'T WORK IN ALL CASES, all entries have to be of the same type and it must be a BJS well known one
  3351. if (propVal && propVal.constructor === Array) {
  3352. var firstVal = propVal[0];
  3353. if (!firstVal) {
  3354. propVal = 0;
  3355. }
  3356. else {
  3357. propVal = BABYLON.Tools.hashCodeFromStream(BABYLON.Tools.arrayOrStringFeeder(propVal));
  3358. }
  3359. }
  3360. var value = "[null]";
  3361. if (propVal != null) {
  3362. if (v.typeLevelCompare) {
  3363. value = BABYLON.Tools.getClassName(propVal);
  3364. }
  3365. else {
  3366. if (propVal instanceof BABYLON.BaseTexture) {
  3367. value = propVal.uid;
  3368. }
  3369. else {
  3370. value = propVal.toString();
  3371. }
  3372. }
  3373. }
  3374. modelKey += v.name + ":" + value + ";";
  3375. }
  3376. });
  3377. this._clearFlags(SmartPropertyPrim_1.flagModelDirty);
  3378. this._modelKey = modelKey;
  3379. return modelKey;
  3380. },
  3381. enumerable: true,
  3382. configurable: true
  3383. });
  3384. Object.defineProperty(SmartPropertyPrim.prototype, "isDirty", {
  3385. /**
  3386. * States if the Primitive is dirty and should be rendered again next time.
  3387. * @returns true is dirty, false otherwise
  3388. */
  3389. get: function () {
  3390. return (this._instanceDirtyFlags !== 0) || this._areSomeFlagsSet(SmartPropertyPrim_1.flagModelDirty | SmartPropertyPrim_1.flagPositioningDirty | SmartPropertyPrim_1.flagLayoutDirty);
  3391. },
  3392. enumerable: true,
  3393. configurable: true
  3394. });
  3395. SmartPropertyPrim.prototype._boundingBoxDirty = function () {
  3396. this._setFlags(SmartPropertyPrim_1.flagLevelBoundingInfoDirty);
  3397. // Escalate the dirty flag in the instance hierarchy, stop when a renderable group is found or at the end
  3398. if (this instanceof BABYLON.Prim2DBase) {
  3399. var curprim = this;
  3400. while (curprim) {
  3401. curprim._setFlags(SmartPropertyPrim_1.flagBoundingInfoDirty);
  3402. if (curprim.isSizeAuto) {
  3403. curprim.onPrimitivePropertyDirty(BABYLON.Prim2DBase.sizeProperty.flagId);
  3404. curprim._setFlags(SmartPropertyPrim_1.flagPositioningDirty);
  3405. }
  3406. if (curprim instanceof BABYLON.Group2D) {
  3407. if (curprim.isRenderableGroup) {
  3408. break;
  3409. }
  3410. }
  3411. curprim = curprim.parent;
  3412. }
  3413. }
  3414. };
  3415. SmartPropertyPrim.prototype._handlePropChanged = function (curValue, newValue, propName, propInfo, typeLevelCompare) {
  3416. _super.prototype._handlePropChanged.call(this, curValue, newValue, propName, propInfo, typeLevelCompare);
  3417. // If the property change also dirty the boundingInfo, update the boundingInfo dirty flags
  3418. if (propInfo.dirtyBoundingInfo) {
  3419. this._boundingBoxDirty();
  3420. }
  3421. else if (propInfo.dirtyParentBoundingInfo) {
  3422. var p = this._parent;
  3423. if (p != null) {
  3424. p._boundingBoxDirty();
  3425. }
  3426. }
  3427. // If the property belong to a group, check if it's a cached one, and dirty its render sprite accordingly
  3428. if (this instanceof BABYLON.Group2D && this._renderableData) {
  3429. this.handleGroupChanged(propInfo);
  3430. }
  3431. // Check for parent layout dirty
  3432. if (this instanceof BABYLON.Prim2DBase) {
  3433. var p = this._parent;
  3434. if (p != null && p.layoutEngine && (p.layoutEngine.layoutDirtyOnPropertyChangedMask & propInfo.flagId) !== 0) {
  3435. p._setLayoutDirty();
  3436. }
  3437. }
  3438. // For type level compare, if there's a change of type it's a change of model, otherwise we issue an instance change
  3439. var instanceDirty = false;
  3440. if (typeLevelCompare && curValue != null && newValue != null) {
  3441. var cvProto = curValue.__proto__;
  3442. var nvProto = newValue.__proto__;
  3443. instanceDirty = (cvProto === nvProto);
  3444. }
  3445. // Set the dirty flags
  3446. if (!instanceDirty && (propInfo.kind === Prim2DPropInfo.PROPKIND_MODEL)) {
  3447. if (!this.isDirty) {
  3448. this._setFlags(SmartPropertyPrim_1.flagModelDirty);
  3449. }
  3450. }
  3451. else if (instanceDirty || (propInfo.kind === Prim2DPropInfo.PROPKIND_INSTANCE) || (propInfo.kind === Prim2DPropInfo.PROPKIND_DYNAMIC)) {
  3452. var propMask = propInfo.flagId;
  3453. this.onPrimitivePropertyDirty(propMask);
  3454. }
  3455. };
  3456. SmartPropertyPrim.prototype.onPrimitivePropertyDirty = function (propFlagId) {
  3457. this.onPrimBecomesDirty();
  3458. this._instanceDirtyFlags |= propFlagId;
  3459. };
  3460. SmartPropertyPrim.prototype.handleGroupChanged = function (prop) {
  3461. };
  3462. SmartPropertyPrim.prototype._resetPropertiesDirty = function () {
  3463. _super.prototype._resetPropertiesDirty.call(this);
  3464. this._clearFlags(SmartPropertyPrim_1.flagPrimInDirtyList | SmartPropertyPrim_1.flagNeedRefresh);
  3465. };
  3466. Object.defineProperty(SmartPropertyPrim.prototype, "levelBoundingInfo", {
  3467. /**
  3468. * Retrieve the boundingInfo for this Primitive, computed based on the primitive itself and NOT its children
  3469. */
  3470. get: function () {
  3471. if (this._isFlagSet(SmartPropertyPrim_1.flagLevelBoundingInfoDirty)) {
  3472. this.updateLevelBoundingInfo();
  3473. this._clearFlags(SmartPropertyPrim_1.flagLevelBoundingInfoDirty);
  3474. }
  3475. return this._levelBoundingInfo;
  3476. },
  3477. enumerable: true,
  3478. configurable: true
  3479. });
  3480. /**
  3481. * This method must be overridden by a given Primitive implementation to compute its boundingInfo
  3482. */
  3483. SmartPropertyPrim.prototype.updateLevelBoundingInfo = function () {
  3484. };
  3485. /**
  3486. * Property method called when the Primitive becomes dirty
  3487. */
  3488. SmartPropertyPrim.prototype.onPrimBecomesDirty = function () {
  3489. };
  3490. /**
  3491. * Check if a given flag is set
  3492. * @param flag the flag value
  3493. * @return true if set, false otherwise
  3494. */
  3495. SmartPropertyPrim.prototype._isFlagSet = function (flag) {
  3496. return (this._flags & flag) !== 0;
  3497. };
  3498. /**
  3499. * Check if all given flags are set
  3500. * @param flags the flags ORed
  3501. * @return true if all the flags are set, false otherwise
  3502. */
  3503. SmartPropertyPrim.prototype._areAllFlagsSet = function (flags) {
  3504. return (this._flags & flags) === flags;
  3505. };
  3506. /**
  3507. * Check if at least one flag of the given flags is set
  3508. * @param flags the flags ORed
  3509. * @return true if at least one flag is set, false otherwise
  3510. */
  3511. SmartPropertyPrim.prototype._areSomeFlagsSet = function (flags) {
  3512. return (this._flags & flags) !== 0;
  3513. };
  3514. /**
  3515. * Clear the given flags
  3516. * @param flags the flags to clear
  3517. */
  3518. SmartPropertyPrim.prototype._clearFlags = function (flags) {
  3519. this._flags &= ~flags;
  3520. };
  3521. /**
  3522. * Set the given flags to true state
  3523. * @param flags the flags ORed to set
  3524. * @return the flags state before this call
  3525. */
  3526. SmartPropertyPrim.prototype._setFlags = function (flags) {
  3527. var cur = this._flags;
  3528. this._flags |= flags;
  3529. return cur;
  3530. };
  3531. /**
  3532. * Change the state of the given flags
  3533. * @param flags the flags ORed to change
  3534. * @param state true to set them, false to clear them
  3535. */
  3536. SmartPropertyPrim.prototype._changeFlags = function (flags, state) {
  3537. if (state) {
  3538. this._flags |= flags;
  3539. }
  3540. else {
  3541. this._flags &= ~flags;
  3542. }
  3543. };
  3544. return SmartPropertyPrim;
  3545. }(SmartPropertyBase));
  3546. SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT = 0;
  3547. SmartPropertyPrim.flagNoPartOfLayout = 0x0000001; // set if the primitive's position/size must not be computed by Layout Engine
  3548. SmartPropertyPrim.flagLevelBoundingInfoDirty = 0x0000002; // set if the primitive's level bounding box (not including children) is dirty
  3549. SmartPropertyPrim.flagModelDirty = 0x0000004; // set if the model must be changed
  3550. SmartPropertyPrim.flagLayoutDirty = 0x0000008; // set if the layout must be computed
  3551. SmartPropertyPrim.flagLevelVisible = 0x0000010; // set if the primitive is set as visible for its level only
  3552. SmartPropertyPrim.flagBoundingInfoDirty = 0x0000020; // set if the primitive's overall bounding box (including children) is dirty
  3553. SmartPropertyPrim.flagIsPickable = 0x0000040; // set if the primitive can be picked during interaction
  3554. SmartPropertyPrim.flagIsVisible = 0x0000080; // set if the primitive is concretely visible (use the levelVisible of parents)
  3555. SmartPropertyPrim.flagVisibilityChanged = 0x0000100; // set if there was a transition between visible/hidden status
  3556. SmartPropertyPrim.flagPositioningDirty = 0x0000200; // set if the primitive positioning must be computed
  3557. SmartPropertyPrim.flagTrackedGroup = 0x0000400; // set if the group2D is tracking a scene node
  3558. SmartPropertyPrim.flagWorldCacheChanged = 0x0000800; // set if the cached bitmap of a world space canvas changed
  3559. SmartPropertyPrim.flagChildrenFlatZOrder = 0x0001000; // set if all the children (direct and indirect) will share the same Z-Order
  3560. SmartPropertyPrim.flagZOrderDirty = 0x0002000; // set if the Z-Order for this prim and its children must be recomputed
  3561. SmartPropertyPrim.flagActualOpacityDirty = 0x0004000; // set if the actualOpactity should be recomputed
  3562. SmartPropertyPrim.flagPrimInDirtyList = 0x0008000; // set if the primitive is in the primDirtyList
  3563. SmartPropertyPrim.flagIsContainer = 0x0010000; // set if the primitive is a container
  3564. SmartPropertyPrim.flagNeedRefresh = 0x0020000; // set if the primitive wasn't successful at refresh
  3565. SmartPropertyPrim.flagActualScaleDirty = 0x0040000; // set if the actualScale property needs to be recomputed
  3566. SmartPropertyPrim.flagDontInheritParentScale = 0x0080000; // set if the actualScale must not use its parent's scale to be computed
  3567. SmartPropertyPrim.flagGlobalTransformDirty = 0x0100000; // set if the global transform must be recomputed due to a local transform change
  3568. SmartPropertyPrim.flagLayoutBoundingInfoDirty = 0x0200000; // set if the layout bounding info is dirty
  3569. SmartPropertyPrim = SmartPropertyPrim_1 = __decorate([
  3570. BABYLON.className("SmartPropertyPrim", "BABYLON")
  3571. ], SmartPropertyPrim);
  3572. BABYLON.SmartPropertyPrim = SmartPropertyPrim;
  3573. function dependencyProperty(propId, piStore, mode, updateSourceTrigger) {
  3574. if (mode === void 0) { mode = DataBinding.MODE_TWOWAY; }
  3575. if (updateSourceTrigger === void 0) { updateSourceTrigger = DataBinding.UPDATESOURCETRIGGER_PROPERTYCHANGED; }
  3576. return SmartPropertyBase._hookProperty(propId, piStore, Prim2DPropInfo.PROPKIND_DYNAMIC, { bindingMode: mode, bindingUpdateSourceTrigger: updateSourceTrigger });
  3577. }
  3578. BABYLON.dependencyProperty = dependencyProperty;
  3579. function modelLevelProperty(propId, piStore, typeLevelCompare, dirtyBoundingInfo, dirtyParentBoundingBox) {
  3580. if (typeLevelCompare === void 0) { typeLevelCompare = false; }
  3581. if (dirtyBoundingInfo === void 0) { dirtyBoundingInfo = false; }
  3582. if (dirtyParentBoundingBox === void 0) { dirtyParentBoundingBox = false; }
  3583. return SmartPropertyBase._hookProperty(propId, piStore, Prim2DPropInfo.PROPKIND_MODEL, { typeLevelCompare: typeLevelCompare, dirtyBoundingInfo: dirtyBoundingInfo, dirtyParentBoundingBox: dirtyParentBoundingBox });
  3584. }
  3585. BABYLON.modelLevelProperty = modelLevelProperty;
  3586. function instanceLevelProperty(propId, piStore, typeLevelCompare, dirtyBoundingInfo, dirtyParentBoundingBox) {
  3587. if (typeLevelCompare === void 0) { typeLevelCompare = false; }
  3588. if (dirtyBoundingInfo === void 0) { dirtyBoundingInfo = false; }
  3589. if (dirtyParentBoundingBox === void 0) { dirtyParentBoundingBox = false; }
  3590. return SmartPropertyBase._hookProperty(propId, piStore, Prim2DPropInfo.PROPKIND_INSTANCE, { typeLevelCompare: typeLevelCompare, dirtyBoundingInfo: dirtyBoundingInfo, dirtyParentBoundingBox: dirtyParentBoundingBox });
  3591. }
  3592. BABYLON.instanceLevelProperty = instanceLevelProperty;
  3593. function dynamicLevelProperty(propId, piStore, typeLevelCompare, dirtyBoundingInfo, dirtyParentBoundingBox) {
  3594. if (typeLevelCompare === void 0) { typeLevelCompare = false; }
  3595. if (dirtyBoundingInfo === void 0) { dirtyBoundingInfo = false; }
  3596. if (dirtyParentBoundingBox === void 0) { dirtyParentBoundingBox = false; }
  3597. return SmartPropertyBase._hookProperty(propId, piStore, Prim2DPropInfo.PROPKIND_DYNAMIC, { typeLevelCompare: typeLevelCompare, dirtyBoundingInfo: dirtyBoundingInfo, dirtyParentBoundingBox: dirtyParentBoundingBox });
  3598. }
  3599. BABYLON.dynamicLevelProperty = dynamicLevelProperty;
  3600. var DataBinding_1, SmartPropertyBase_1, SmartPropertyPrim_1;
  3601. })(BABYLON || (BABYLON = {}));
  3602. //# sourceMappingURL=babylon.smartPropertyPrim.js.map
  3603. var __extends = (this && this.__extends) || function (d, b) {
  3604. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3605. function __() { this.constructor = d; }
  3606. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3607. };
  3608. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  3609. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  3610. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  3611. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  3612. return c > 3 && r && Object.defineProperty(target, key, r), r;
  3613. };
  3614. var BABYLON;
  3615. (function (BABYLON) {
  3616. var PrepareRender2DContext = (function () {
  3617. function PrepareRender2DContext() {
  3618. this.forceRefreshPrimitive = false;
  3619. }
  3620. return PrepareRender2DContext;
  3621. }());
  3622. BABYLON.PrepareRender2DContext = PrepareRender2DContext;
  3623. var Render2DContext = (function () {
  3624. function Render2DContext(renderMode) {
  3625. this._renderMode = renderMode;
  3626. this.useInstancing = false;
  3627. this.groupInfoPartData = null;
  3628. this.partDataStartIndex = this.partDataEndIndex = null;
  3629. this.instancedBuffers = null;
  3630. }
  3631. Object.defineProperty(Render2DContext.prototype, "renderMode", {
  3632. /**
  3633. * Define which render Mode should be used to render the primitive: one of Render2DContext.RenderModeXxxx property
  3634. */
  3635. get: function () {
  3636. return this._renderMode;
  3637. },
  3638. enumerable: true,
  3639. configurable: true
  3640. });
  3641. Object.defineProperty(Render2DContext, "RenderModeOpaque", {
  3642. /**
  3643. * The set of primitives to render is opaque.
  3644. * This is the first rendering pass. All Opaque primitives are rendered. Depth Compare and Write are both enabled.
  3645. */
  3646. get: function () {
  3647. return Render2DContext._renderModeOpaque;
  3648. },
  3649. enumerable: true,
  3650. configurable: true
  3651. });
  3652. Object.defineProperty(Render2DContext, "RenderModeAlphaTest", {
  3653. /**
  3654. * The set of primitives to render is using Alpha Test (aka masking).
  3655. * Alpha Blend is enabled, the AlphaMode must be manually set, the render occurs after the RenderModeOpaque and is depth independent (i.e. primitives are not sorted by depth). Depth Compare and Write are both enabled.
  3656. */
  3657. get: function () {
  3658. return Render2DContext._renderModeAlphaTest;
  3659. },
  3660. enumerable: true,
  3661. configurable: true
  3662. });
  3663. Object.defineProperty(Render2DContext, "RenderModeTransparent", {
  3664. /**
  3665. * The set of primitives to render is transparent.
  3666. * Alpha Blend is enabled, the AlphaMode must be manually set, the render occurs after the RenderModeAlphaTest and is depth dependent (i.e. primitives are stored by depth and rendered back to front). Depth Compare is on, but Depth write is Off.
  3667. */
  3668. get: function () {
  3669. return Render2DContext._renderModeTransparent;
  3670. },
  3671. enumerable: true,
  3672. configurable: true
  3673. });
  3674. return Render2DContext;
  3675. }());
  3676. Render2DContext._renderModeOpaque = 1;
  3677. Render2DContext._renderModeAlphaTest = 2;
  3678. Render2DContext._renderModeTransparent = 3;
  3679. BABYLON.Render2DContext = Render2DContext;
  3680. /**
  3681. * This class store information for the pointerEventObservable Observable.
  3682. * The Observable is divided into many sub events (using the Mask feature of the Observable pattern): PointerOver, PointerEnter, PointerDown, PointerMouseWheel, PointerMove, PointerUp, PointerDown, PointerLeave, PointerGotCapture and PointerLostCapture.
  3683. */
  3684. var PrimitivePointerInfo = (function () {
  3685. function PrimitivePointerInfo() {
  3686. this.primitivePointerPos = BABYLON.Vector2.Zero();
  3687. this.tilt = BABYLON.Vector2.Zero();
  3688. this.cancelBubble = false;
  3689. }
  3690. Object.defineProperty(PrimitivePointerInfo, "PointerOver", {
  3691. // The behavior is based on the HTML specifications of the Pointer Events (https://www.w3.org/TR/pointerevents/#list-of-pointer-events). This is not 100% compliant and not meant to be, but still, it's based on these specs for most use cases to be programmed the same way (as closest as possible) as it would have been in HTML.
  3692. /**
  3693. * This event type is raised when a pointing device is moved into the hit test boundaries of a primitive.
  3694. * Bubbles: yes
  3695. */
  3696. get: function () {
  3697. return PrimitivePointerInfo._pointerOver;
  3698. },
  3699. enumerable: true,
  3700. configurable: true
  3701. });
  3702. Object.defineProperty(PrimitivePointerInfo, "PointerEnter", {
  3703. /**
  3704. * This event type is raised when a pointing device is moved into the hit test boundaries of a primitive or one of its descendants.
  3705. * Bubbles: no
  3706. */
  3707. get: function () {
  3708. return PrimitivePointerInfo._pointerEnter;
  3709. },
  3710. enumerable: true,
  3711. configurable: true
  3712. });
  3713. Object.defineProperty(PrimitivePointerInfo, "PointerDown", {
  3714. /**
  3715. * This event type is raised when a pointer enters the active button state (non-zero value in the buttons property). For mouse it's when the device transitions from no buttons depressed to at least one button depressed. For touch/pen this is when a physical contact is made.
  3716. * Bubbles: yes
  3717. */
  3718. get: function () {
  3719. return PrimitivePointerInfo._pointerDown;
  3720. },
  3721. enumerable: true,
  3722. configurable: true
  3723. });
  3724. Object.defineProperty(PrimitivePointerInfo, "PointerMouseWheel", {
  3725. /**
  3726. * This event type is raised when the pointer is a mouse and it's wheel is rolling
  3727. * Bubbles: yes
  3728. */
  3729. get: function () {
  3730. return PrimitivePointerInfo._pointerMouseWheel;
  3731. },
  3732. enumerable: true,
  3733. configurable: true
  3734. });
  3735. Object.defineProperty(PrimitivePointerInfo, "PointerMove", {
  3736. /**
  3737. * This event type is raised when a pointer change coordinates or when a pointer changes button state, pressure, tilt, or contact geometry and the circumstances produce no other pointers events.
  3738. * Bubbles: yes
  3739. */
  3740. get: function () {
  3741. return PrimitivePointerInfo._pointerMove;
  3742. },
  3743. enumerable: true,
  3744. configurable: true
  3745. });
  3746. Object.defineProperty(PrimitivePointerInfo, "PointerUp", {
  3747. /**
  3748. * This event type is raised when the pointer leaves the active buttons states (zero value in the buttons property). For mouse, this is when the device transitions from at least one button depressed to no buttons depressed. For touch/pen, this is when physical contact is removed.
  3749. * Bubbles: yes
  3750. */
  3751. get: function () {
  3752. return PrimitivePointerInfo._pointerUp;
  3753. },
  3754. enumerable: true,
  3755. configurable: true
  3756. });
  3757. Object.defineProperty(PrimitivePointerInfo, "PointerOut", {
  3758. /**
  3759. * This event type is raised when a pointing device is moved out of the hit test the boundaries of a primitive.
  3760. * Bubbles: yes
  3761. */
  3762. get: function () {
  3763. return PrimitivePointerInfo._pointerOut;
  3764. },
  3765. enumerable: true,
  3766. configurable: true
  3767. });
  3768. Object.defineProperty(PrimitivePointerInfo, "PointerLeave", {
  3769. /**
  3770. * This event type is raised when a pointing device is moved out of the hit test boundaries of a primitive and all its descendants.
  3771. * Bubbles: no
  3772. */
  3773. get: function () {
  3774. return PrimitivePointerInfo._pointerLeave;
  3775. },
  3776. enumerable: true,
  3777. configurable: true
  3778. });
  3779. Object.defineProperty(PrimitivePointerInfo, "PointerGotCapture", {
  3780. /**
  3781. * This event type is raised when a primitive receives the pointer capture. This event is fired at the element that is receiving pointer capture. Subsequent events for that pointer will be fired at this element.
  3782. * Bubbles: yes
  3783. */
  3784. get: function () {
  3785. return PrimitivePointerInfo._pointerGotCapture;
  3786. },
  3787. enumerable: true,
  3788. configurable: true
  3789. });
  3790. Object.defineProperty(PrimitivePointerInfo, "PointerLostCapture", {
  3791. /**
  3792. * This event type is raised after pointer capture is released for a pointer.
  3793. * Bubbles: yes
  3794. */
  3795. get: function () {
  3796. return PrimitivePointerInfo._pointerLostCapture;
  3797. },
  3798. enumerable: true,
  3799. configurable: true
  3800. });
  3801. Object.defineProperty(PrimitivePointerInfo, "MouseWheelPrecision", {
  3802. get: function () {
  3803. return PrimitivePointerInfo._mouseWheelPrecision;
  3804. },
  3805. enumerable: true,
  3806. configurable: true
  3807. });
  3808. PrimitivePointerInfo.prototype.updateRelatedTarget = function (prim, primPointerPos) {
  3809. this.relatedTarget = prim;
  3810. this.relatedTargetPointerPos = primPointerPos;
  3811. };
  3812. PrimitivePointerInfo.getEventTypeName = function (mask) {
  3813. switch (mask) {
  3814. case PrimitivePointerInfo.PointerOver: return "PointerOver";
  3815. case PrimitivePointerInfo.PointerEnter: return "PointerEnter";
  3816. case PrimitivePointerInfo.PointerDown: return "PointerDown";
  3817. case PrimitivePointerInfo.PointerMouseWheel: return "PointerMouseWheel";
  3818. case PrimitivePointerInfo.PointerMove: return "PointerMove";
  3819. case PrimitivePointerInfo.PointerUp: return "PointerUp";
  3820. case PrimitivePointerInfo.PointerOut: return "PointerOut";
  3821. case PrimitivePointerInfo.PointerLeave: return "PointerLeave";
  3822. case PrimitivePointerInfo.PointerGotCapture: return "PointerGotCapture";
  3823. case PrimitivePointerInfo.PointerLostCapture: return "PointerLostCapture";
  3824. }
  3825. };
  3826. return PrimitivePointerInfo;
  3827. }());
  3828. PrimitivePointerInfo._pointerOver = 0x0001;
  3829. PrimitivePointerInfo._pointerEnter = 0x0002;
  3830. PrimitivePointerInfo._pointerDown = 0x0004;
  3831. PrimitivePointerInfo._pointerMouseWheel = 0x0008;
  3832. PrimitivePointerInfo._pointerMove = 0x0010;
  3833. PrimitivePointerInfo._pointerUp = 0x0020;
  3834. PrimitivePointerInfo._pointerOut = 0x0040;
  3835. PrimitivePointerInfo._pointerLeave = 0x0080;
  3836. PrimitivePointerInfo._pointerGotCapture = 0x0100;
  3837. PrimitivePointerInfo._pointerLostCapture = 0x0200;
  3838. PrimitivePointerInfo._mouseWheelPrecision = 3.0;
  3839. BABYLON.PrimitivePointerInfo = PrimitivePointerInfo;
  3840. /**
  3841. * Defines the horizontal and vertical alignment information for a Primitive.
  3842. */
  3843. var PrimitiveAlignment = PrimitiveAlignment_1 = (function () {
  3844. function PrimitiveAlignment(changeCallback) {
  3845. this._changedCallback = changeCallback;
  3846. this._horizontal = PrimitiveAlignment_1.AlignLeft;
  3847. this._vertical = PrimitiveAlignment_1.AlignBottom;
  3848. }
  3849. Object.defineProperty(PrimitiveAlignment, "AlignLeft", {
  3850. /**
  3851. * Alignment is made relative to the left edge of the Primitive. Valid for horizontal alignment only.
  3852. */
  3853. get: function () { return PrimitiveAlignment_1._AlignLeft; },
  3854. enumerable: true,
  3855. configurable: true
  3856. });
  3857. Object.defineProperty(PrimitiveAlignment, "AlignTop", {
  3858. /**
  3859. * Alignment is made relative to the top edge of the Primitive. Valid for vertical alignment only.
  3860. */
  3861. get: function () { return PrimitiveAlignment_1._AlignTop; },
  3862. enumerable: true,
  3863. configurable: true
  3864. });
  3865. Object.defineProperty(PrimitiveAlignment, "AlignRight", {
  3866. /**
  3867. * Alignment is made relative to the right edge of the Primitive. Valid for horizontal alignment only.
  3868. */
  3869. get: function () { return PrimitiveAlignment_1._AlignRight; },
  3870. enumerable: true,
  3871. configurable: true
  3872. });
  3873. Object.defineProperty(PrimitiveAlignment, "AlignBottom", {
  3874. /**
  3875. * Alignment is made relative to the bottom edge of the Primitive. Valid for vertical alignment only.
  3876. */
  3877. get: function () { return PrimitiveAlignment_1._AlignBottom; },
  3878. enumerable: true,
  3879. configurable: true
  3880. });
  3881. Object.defineProperty(PrimitiveAlignment, "AlignCenter", {
  3882. /**
  3883. * Alignment is made to center the content from equal distance to the opposite edges of the Primitive
  3884. */
  3885. get: function () { return PrimitiveAlignment_1._AlignCenter; },
  3886. enumerable: true,
  3887. configurable: true
  3888. });
  3889. Object.defineProperty(PrimitiveAlignment, "AlignStretch", {
  3890. /**
  3891. * The content is stretched toward the opposite edges of the Primitive
  3892. */
  3893. get: function () { return PrimitiveAlignment_1._AlignStretch; },
  3894. enumerable: true,
  3895. configurable: true
  3896. });
  3897. Object.defineProperty(PrimitiveAlignment.prototype, "horizontal", {
  3898. /**
  3899. * Get/set the horizontal alignment. Use one of the AlignXXX static properties of this class
  3900. */
  3901. get: function () {
  3902. return this._horizontal;
  3903. },
  3904. set: function (value) {
  3905. if (this._horizontal === value) {
  3906. return;
  3907. }
  3908. this._horizontal = value;
  3909. this.onChangeCallback();
  3910. },
  3911. enumerable: true,
  3912. configurable: true
  3913. });
  3914. Object.defineProperty(PrimitiveAlignment.prototype, "vertical", {
  3915. /**
  3916. * Get/set the vertical alignment. Use one of the AlignXXX static properties of this class
  3917. */
  3918. get: function () {
  3919. return this._vertical;
  3920. },
  3921. set: function (value) {
  3922. if (this._vertical === value) {
  3923. return;
  3924. }
  3925. this._vertical = value;
  3926. this.onChangeCallback();
  3927. },
  3928. enumerable: true,
  3929. configurable: true
  3930. });
  3931. PrimitiveAlignment.prototype.onChangeCallback = function () {
  3932. if (this._changedCallback) {
  3933. this._changedCallback();
  3934. }
  3935. };
  3936. /**
  3937. * Set the horizontal alignment from a string value.
  3938. * @param text can be either: 'left','right','center','stretch'
  3939. */
  3940. PrimitiveAlignment.prototype.setHorizontal = function (text) {
  3941. var v = text.trim().toLocaleLowerCase();
  3942. switch (v) {
  3943. case "left":
  3944. this.horizontal = PrimitiveAlignment_1.AlignLeft;
  3945. return;
  3946. case "right":
  3947. this.horizontal = PrimitiveAlignment_1.AlignRight;
  3948. return;
  3949. case "center":
  3950. this.horizontal = PrimitiveAlignment_1.AlignCenter;
  3951. return;
  3952. case "stretch":
  3953. this.horizontal = PrimitiveAlignment_1.AlignStretch;
  3954. return;
  3955. }
  3956. };
  3957. /**
  3958. * Set the vertical alignment from a string value.
  3959. * @param text can be either: 'top','bottom','center','stretch'
  3960. */
  3961. PrimitiveAlignment.prototype.setVertical = function (text) {
  3962. var v = text.trim().toLocaleLowerCase();
  3963. switch (v) {
  3964. case "top":
  3965. this.vertical = PrimitiveAlignment_1.AlignTop;
  3966. return;
  3967. case "bottom":
  3968. this.vertical = PrimitiveAlignment_1.AlignBottom;
  3969. return;
  3970. case "center":
  3971. this.vertical = PrimitiveAlignment_1.AlignCenter;
  3972. return;
  3973. case "stretch":
  3974. this.vertical = PrimitiveAlignment_1.AlignStretch;
  3975. return;
  3976. }
  3977. };
  3978. /**
  3979. * Set the horizontal and or vertical alignments from a string value.
  3980. * @param text can be: [<h:|horizontal:><left|right|center|stretch>], [<v:|vertical:><top|bottom|center|stretch>]
  3981. */
  3982. PrimitiveAlignment.prototype.fromString = function (value) {
  3983. var m = value.trim().split(",");
  3984. if (m.length === 1) {
  3985. this.setHorizontal(m[0]);
  3986. this.setVertical(m[0]);
  3987. }
  3988. else {
  3989. for (var _i = 0, m_1 = m; _i < m_1.length; _i++) {
  3990. var v = m_1[_i];
  3991. v = v.toLocaleLowerCase().trim();
  3992. // Horizontal
  3993. var i = v.indexOf("h:");
  3994. if (i === -1) {
  3995. i = v.indexOf("horizontal:");
  3996. }
  3997. if (i !== -1) {
  3998. v = v.substr(v.indexOf(":") + 1);
  3999. this.setHorizontal(v);
  4000. continue;
  4001. }
  4002. // Vertical
  4003. i = v.indexOf("v:");
  4004. if (i === -1) {
  4005. i = v.indexOf("vertical:");
  4006. }
  4007. if (i !== -1) {
  4008. v = v.substr(v.indexOf(":") + 1);
  4009. this.setVertical(v);
  4010. continue;
  4011. }
  4012. }
  4013. }
  4014. };
  4015. PrimitiveAlignment.prototype.copyFrom = function (pa) {
  4016. this._horizontal = pa._horizontal;
  4017. this._vertical = pa._vertical;
  4018. this.onChangeCallback();
  4019. };
  4020. Object.defineProperty(PrimitiveAlignment.prototype, "isDefault", {
  4021. get: function () {
  4022. return this.horizontal === PrimitiveAlignment_1.AlignLeft && this.vertical === PrimitiveAlignment_1.AlignBottom;
  4023. },
  4024. enumerable: true,
  4025. configurable: true
  4026. });
  4027. return PrimitiveAlignment;
  4028. }());
  4029. PrimitiveAlignment._AlignLeft = 1;
  4030. PrimitiveAlignment._AlignTop = 1; // Same as left
  4031. PrimitiveAlignment._AlignRight = 2;
  4032. PrimitiveAlignment._AlignBottom = 2; // Same as right
  4033. PrimitiveAlignment._AlignCenter = 3;
  4034. PrimitiveAlignment._AlignStretch = 4;
  4035. PrimitiveAlignment = PrimitiveAlignment_1 = __decorate([
  4036. BABYLON.className("PrimitiveAlignment", "BABYLON")
  4037. ], PrimitiveAlignment);
  4038. BABYLON.PrimitiveAlignment = PrimitiveAlignment;
  4039. /**
  4040. * Stores information about a Primitive that was intersected
  4041. */
  4042. var PrimitiveIntersectedInfo = (function () {
  4043. function PrimitiveIntersectedInfo(prim, intersectionLocation) {
  4044. this.prim = prim;
  4045. this.intersectionLocation = intersectionLocation;
  4046. }
  4047. return PrimitiveIntersectedInfo;
  4048. }());
  4049. BABYLON.PrimitiveIntersectedInfo = PrimitiveIntersectedInfo;
  4050. /**
  4051. * Define a thickness toward every edges of a Primitive to allow margin and padding.
  4052. * The thickness can be expressed as pixels, percentages, inherit the value of the parent primitive or be auto.
  4053. */
  4054. var PrimitiveThickness = PrimitiveThickness_1 = (function () {
  4055. function PrimitiveThickness(parentAccess, changedCallback) {
  4056. this._parentAccess = parentAccess;
  4057. this._changedCallback = changedCallback;
  4058. this._pixels = new Array(4);
  4059. this._percentages = new Array(4);
  4060. this._setType(0, PrimitiveThickness_1.Auto);
  4061. this._setType(1, PrimitiveThickness_1.Auto);
  4062. this._setType(2, PrimitiveThickness_1.Auto);
  4063. this._setType(3, PrimitiveThickness_1.Auto);
  4064. this._pixels[0] = 0;
  4065. this._pixels[1] = 0;
  4066. this._pixels[2] = 0;
  4067. this._pixels[3] = 0;
  4068. }
  4069. /**
  4070. * Set the thickness from a string value
  4071. * @param thickness format is "top: <value>, left:<value>, right:<value>, bottom:<value>" or "<value>" (same for all edges) each are optional, auto will be set if it's omitted.
  4072. * Values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  4073. */
  4074. PrimitiveThickness.prototype.fromString = function (thickness) {
  4075. this._clear();
  4076. var m = thickness.trim().split(",");
  4077. // Special case, one value to apply to all edges
  4078. if (m.length === 1 && thickness.indexOf(":") === -1) {
  4079. this._setStringValue(m[0], 0, false);
  4080. this._setStringValue(m[0], 1, false);
  4081. this._setStringValue(m[0], 2, false);
  4082. this._setStringValue(m[0], 3, false);
  4083. this.onChangeCallback();
  4084. return;
  4085. }
  4086. var res = false;
  4087. for (var _i = 0, m_2 = m; _i < m_2.length; _i++) {
  4088. var cm = m_2[_i];
  4089. res = this._extractString(cm, false) || res;
  4090. }
  4091. if (!res) {
  4092. throw new Error("Can't parse the string to create a PrimitiveMargin object, format must be: 'top: <value>, left:<value>, right:<value>, bottom:<value>");
  4093. }
  4094. // Check the margin that weren't set and set them in auto
  4095. if ((this._flags & 0x000F) === 0)
  4096. this._flags |= PrimitiveThickness_1.Pixel << 0;
  4097. if ((this._flags & 0x00F0) === 0)
  4098. this._flags |= PrimitiveThickness_1.Pixel << 4;
  4099. if ((this._flags & 0x0F00) === 0)
  4100. this._flags |= PrimitiveThickness_1.Pixel << 8;
  4101. if ((this._flags & 0xF000) === 0)
  4102. this._flags |= PrimitiveThickness_1.Pixel << 12;
  4103. this.onChangeCallback();
  4104. };
  4105. /**
  4106. * Set the thickness from multiple string
  4107. * Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  4108. * @param top the top thickness to set
  4109. * @param left the left thickness to set
  4110. * @param right the right thickness to set
  4111. * @param bottom the bottom thickness to set
  4112. */
  4113. PrimitiveThickness.prototype.fromStrings = function (top, left, right, bottom) {
  4114. this._clear();
  4115. this._setStringValue(top, 0, false);
  4116. this._setStringValue(left, 1, false);
  4117. this._setStringValue(right, 2, false);
  4118. this._setStringValue(bottom, 3, false);
  4119. this.onChangeCallback();
  4120. return this;
  4121. };
  4122. /**
  4123. * Set the thickness from pixel values
  4124. * @param top the top thickness in pixels to set
  4125. * @param left the left thickness in pixels to set
  4126. * @param right the right thickness in pixels to set
  4127. * @param bottom the bottom thickness in pixels to set
  4128. */
  4129. PrimitiveThickness.prototype.fromPixels = function (top, left, right, bottom) {
  4130. this._clear();
  4131. this._pixels[0] = top;
  4132. this._pixels[1] = left;
  4133. this._pixels[2] = right;
  4134. this._pixels[3] = bottom;
  4135. this.onChangeCallback();
  4136. return this;
  4137. };
  4138. /**
  4139. * Apply the same pixel value to all edges
  4140. * @param margin the value to set, in pixels.
  4141. */
  4142. PrimitiveThickness.prototype.fromUniformPixels = function (margin) {
  4143. this._clear();
  4144. this._pixels[0] = margin;
  4145. this._pixels[1] = margin;
  4146. this._pixels[2] = margin;
  4147. this._pixels[3] = margin;
  4148. this.onChangeCallback();
  4149. return this;
  4150. };
  4151. PrimitiveThickness.prototype.copyFrom = function (pt) {
  4152. this._clear();
  4153. for (var i = 0; i < 4; i++) {
  4154. this._pixels[i] = pt._pixels[i];
  4155. this._percentages[i] = pt._percentages[i];
  4156. }
  4157. this._flags = pt._flags;
  4158. this.onChangeCallback();
  4159. };
  4160. /**
  4161. * Set all edges in auto
  4162. */
  4163. PrimitiveThickness.prototype.auto = function () {
  4164. this._clear();
  4165. this._flags = (PrimitiveThickness_1.Auto << 0) | (PrimitiveThickness_1.Auto << 4) | (PrimitiveThickness_1.Auto << 8) | (PrimitiveThickness_1.Auto << 12);
  4166. this._pixels[0] = 0;
  4167. this._pixels[1] = 0;
  4168. this._pixels[2] = 0;
  4169. this._pixels[3] = 0;
  4170. this.onChangeCallback();
  4171. return this;
  4172. };
  4173. PrimitiveThickness.prototype._clear = function () {
  4174. this._flags = 0;
  4175. this._pixels[0] = 0;
  4176. this._pixels[1] = 0;
  4177. this._pixels[2] = 0;
  4178. this._pixels[3] = 0;
  4179. this._percentages[0] = null;
  4180. this._percentages[1] = null;
  4181. this._percentages[2] = null;
  4182. this._percentages[3] = null;
  4183. };
  4184. PrimitiveThickness.prototype._extractString = function (value, emitChanged) {
  4185. var v = value.trim().toLocaleLowerCase();
  4186. if (v.indexOf("top:") === 0) {
  4187. v = v.substr(4).trim();
  4188. return this._setStringValue(v, 0, emitChanged);
  4189. }
  4190. if (v.indexOf("left:") === 0) {
  4191. v = v.substr(5).trim();
  4192. return this._setStringValue(v, 1, emitChanged);
  4193. }
  4194. if (v.indexOf("right:") === 0) {
  4195. v = v.substr(6).trim();
  4196. return this._setStringValue(v, 2, emitChanged);
  4197. }
  4198. if (v.indexOf("bottom:") === 0) {
  4199. v = v.substr(7).trim();
  4200. return this._setStringValue(v, 3, emitChanged);
  4201. }
  4202. return false;
  4203. };
  4204. PrimitiveThickness.prototype._setStringValue = function (value, index, emitChanged) {
  4205. // Check for auto
  4206. var v = value.trim().toLocaleLowerCase();
  4207. if (v === "auto") {
  4208. if (this._isType(index, PrimitiveThickness_1.Auto)) {
  4209. return true;
  4210. }
  4211. this._setType(index, PrimitiveThickness_1.Auto);
  4212. this._pixels[index] = 0;
  4213. if (emitChanged) {
  4214. this.onChangeCallback();
  4215. }
  4216. }
  4217. else if (v === "inherit") {
  4218. if (this._isType(index, PrimitiveThickness_1.Inherit)) {
  4219. return true;
  4220. }
  4221. this._setType(index, PrimitiveThickness_1.Inherit);
  4222. this._pixels[index] = null;
  4223. if (emitChanged) {
  4224. this.onChangeCallback();
  4225. }
  4226. }
  4227. else {
  4228. var pI = v.indexOf("%");
  4229. // Check for percentage
  4230. if (pI !== -1) {
  4231. var n_1 = v.substr(0, pI);
  4232. var number_1 = Math.round(Number(n_1)) / 100; // Normalize the percentage to [0;1] with a 0.01 precision
  4233. if (this._isType(index, PrimitiveThickness_1.Percentage) && (this._percentages[index] === number_1)) {
  4234. return true;
  4235. }
  4236. this._setType(index, PrimitiveThickness_1.Percentage);
  4237. if (isNaN(number_1)) {
  4238. return false;
  4239. }
  4240. this._percentages[index] = number_1;
  4241. if (emitChanged) {
  4242. this.onChangeCallback();
  4243. }
  4244. return true;
  4245. }
  4246. // Check for pixel
  4247. var n = void 0;
  4248. pI = v.indexOf("px");
  4249. if (pI !== -1) {
  4250. n = v.substr(0, pI).trim();
  4251. }
  4252. else {
  4253. n = v;
  4254. }
  4255. var number = Number(n);
  4256. if (this._isType(index, PrimitiveThickness_1.Pixel) && (this._pixels[index] === number)) {
  4257. return true;
  4258. }
  4259. if (isNaN(number)) {
  4260. return false;
  4261. }
  4262. this._pixels[index] = number;
  4263. this._setType(index, PrimitiveThickness_1.Pixel);
  4264. if (emitChanged) {
  4265. this.onChangeCallback();
  4266. }
  4267. return true;
  4268. }
  4269. };
  4270. PrimitiveThickness.prototype._setPixels = function (value, index, emitChanged) {
  4271. // Round the value because, well, it's the thing to do! Otherwise we'll have sub-pixel stuff, and the no change comparison just below will almost never work for PrimitiveThickness values inside a hierarchy of Primitives
  4272. value = Math.round(value);
  4273. if (this._isType(index, PrimitiveThickness_1.Pixel) && this._pixels[index] === value) {
  4274. return;
  4275. }
  4276. this._setType(index, PrimitiveThickness_1.Pixel);
  4277. this._pixels[index] = value;
  4278. if (emitChanged) {
  4279. this.onChangeCallback();
  4280. }
  4281. };
  4282. PrimitiveThickness.prototype._setPercentage = function (value, index, emitChanged) {
  4283. // Clip Value to bounds
  4284. value = Math.min(1, value);
  4285. value = Math.max(0, value);
  4286. value = Math.round(value * 100) / 100; // 0.01 precision
  4287. if (this._isType(index, PrimitiveThickness_1.Percentage) && this._percentages[index] === value) {
  4288. return;
  4289. }
  4290. this._setType(index, PrimitiveThickness_1.Percentage);
  4291. this._percentages[index] = value;
  4292. if (emitChanged) {
  4293. this.onChangeCallback();
  4294. }
  4295. };
  4296. PrimitiveThickness.prototype._getStringValue = function (index) {
  4297. var f = (this._flags >> (index * 4)) & 0xF;
  4298. switch (f) {
  4299. case PrimitiveThickness_1.Auto:
  4300. return "auto";
  4301. case PrimitiveThickness_1.Pixel:
  4302. return this._pixels[index] + "px";
  4303. case PrimitiveThickness_1.Percentage:
  4304. return this._percentages[index] * 100 + "%";
  4305. case PrimitiveThickness_1.Inherit:
  4306. return "inherit";
  4307. }
  4308. return "";
  4309. };
  4310. PrimitiveThickness.prototype._isType = function (index, type) {
  4311. var f = (this._flags >> (index * 4)) & 0xF;
  4312. return f === type;
  4313. };
  4314. PrimitiveThickness.prototype._getType = function (index, processInherit) {
  4315. var t = (this._flags >> (index * 4)) & 0xF;
  4316. if (processInherit && (t === PrimitiveThickness_1.Inherit)) {
  4317. var p = this._parentAccess();
  4318. if (p) {
  4319. return p._getType(index, true);
  4320. }
  4321. return PrimitiveThickness_1.Auto;
  4322. }
  4323. return t;
  4324. };
  4325. PrimitiveThickness.prototype._setType = function (index, type) {
  4326. this._flags &= ~(0xF << (index * 4));
  4327. this._flags |= type << (index * 4);
  4328. };
  4329. PrimitiveThickness.prototype.setTop = function (value) {
  4330. if (typeof value === "string") {
  4331. this._setStringValue(value, 0, true);
  4332. }
  4333. else {
  4334. this.topPixels = value;
  4335. }
  4336. };
  4337. PrimitiveThickness.prototype.setLeft = function (value) {
  4338. if (typeof value === "string") {
  4339. this._setStringValue(value, 1, true);
  4340. }
  4341. else {
  4342. this.leftPixels = value;
  4343. }
  4344. };
  4345. PrimitiveThickness.prototype.setRight = function (value) {
  4346. if (typeof value === "string") {
  4347. this._setStringValue(value, 2, true);
  4348. }
  4349. else {
  4350. this.rightPixels = value;
  4351. }
  4352. };
  4353. PrimitiveThickness.prototype.setBottom = function (value) {
  4354. if (typeof value === "string") {
  4355. this._setStringValue(value, 3, true);
  4356. }
  4357. else {
  4358. this.bottomPixels = value;
  4359. }
  4360. };
  4361. Object.defineProperty(PrimitiveThickness.prototype, "top", {
  4362. /**
  4363. * Get/set the top thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  4364. */
  4365. get: function () {
  4366. return this._getStringValue(0);
  4367. },
  4368. set: function (value) {
  4369. this._setStringValue(value, 0, true);
  4370. },
  4371. enumerable: true,
  4372. configurable: true
  4373. });
  4374. Object.defineProperty(PrimitiveThickness.prototype, "left", {
  4375. /**
  4376. * Get/set the left thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  4377. */
  4378. get: function () {
  4379. return this._getStringValue(1);
  4380. },
  4381. set: function (value) {
  4382. this._setStringValue(value, 1, true);
  4383. },
  4384. enumerable: true,
  4385. configurable: true
  4386. });
  4387. Object.defineProperty(PrimitiveThickness.prototype, "right", {
  4388. /**
  4389. * Get/set the right thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  4390. */
  4391. get: function () {
  4392. return this._getStringValue(2);
  4393. },
  4394. set: function (value) {
  4395. this._setStringValue(value, 2, true);
  4396. },
  4397. enumerable: true,
  4398. configurable: true
  4399. });
  4400. Object.defineProperty(PrimitiveThickness.prototype, "bottom", {
  4401. /**
  4402. * Get/set the bottom thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  4403. */
  4404. get: function () {
  4405. return this._getStringValue(3);
  4406. },
  4407. set: function (value) {
  4408. this._setStringValue(value, 3, true);
  4409. },
  4410. enumerable: true,
  4411. configurable: true
  4412. });
  4413. Object.defineProperty(PrimitiveThickness.prototype, "topPixels", {
  4414. /**
  4415. * Get/set the top thickness in pixel.
  4416. */
  4417. get: function () {
  4418. return this._pixels[0];
  4419. },
  4420. set: function (value) {
  4421. this._setPixels(value, 0, true);
  4422. },
  4423. enumerable: true,
  4424. configurable: true
  4425. });
  4426. Object.defineProperty(PrimitiveThickness.prototype, "leftPixels", {
  4427. /**
  4428. * Get/set the left thickness in pixel.
  4429. */
  4430. get: function () {
  4431. return this._pixels[1];
  4432. },
  4433. set: function (value) {
  4434. this._setPixels(value, 1, true);
  4435. },
  4436. enumerable: true,
  4437. configurable: true
  4438. });
  4439. Object.defineProperty(PrimitiveThickness.prototype, "rightPixels", {
  4440. /**
  4441. * Get/set the right thickness in pixel.
  4442. */
  4443. get: function () {
  4444. return this._pixels[2];
  4445. },
  4446. set: function (value) {
  4447. this._setPixels(value, 2, true);
  4448. },
  4449. enumerable: true,
  4450. configurable: true
  4451. });
  4452. Object.defineProperty(PrimitiveThickness.prototype, "bottomPixels", {
  4453. /**
  4454. * Get/set the bottom thickness in pixel.
  4455. */
  4456. get: function () {
  4457. return this._pixels[3];
  4458. },
  4459. set: function (value) {
  4460. this._setPixels(value, 3, true);
  4461. },
  4462. enumerable: true,
  4463. configurable: true
  4464. });
  4465. Object.defineProperty(PrimitiveThickness.prototype, "topPercentage", {
  4466. /**
  4467. * Get/set the top thickness in percentage.
  4468. * The get will return a valid value only if the edge type is percentage.
  4469. * The Set will change the edge mode if needed
  4470. */
  4471. get: function () {
  4472. return this._percentages[0];
  4473. },
  4474. set: function (value) {
  4475. this._setPercentage(value, 0, true);
  4476. },
  4477. enumerable: true,
  4478. configurable: true
  4479. });
  4480. Object.defineProperty(PrimitiveThickness.prototype, "leftPercentage", {
  4481. /**
  4482. * Get/set the left thickness in percentage.
  4483. * The get will return a valid value only if the edge mode is percentage.
  4484. * The Set will change the edge mode if needed
  4485. */
  4486. get: function () {
  4487. return this._percentages[1];
  4488. },
  4489. set: function (value) {
  4490. this._setPercentage(value, 1, true);
  4491. },
  4492. enumerable: true,
  4493. configurable: true
  4494. });
  4495. Object.defineProperty(PrimitiveThickness.prototype, "rightPercentage", {
  4496. /**
  4497. * Get/set the right thickness in percentage.
  4498. * The get will return a valid value only if the edge mode is percentage.
  4499. * The Set will change the edge mode if needed
  4500. */
  4501. get: function () {
  4502. return this._percentages[2];
  4503. },
  4504. set: function (value) {
  4505. this._setPercentage(value, 2, true);
  4506. },
  4507. enumerable: true,
  4508. configurable: true
  4509. });
  4510. Object.defineProperty(PrimitiveThickness.prototype, "bottomPercentage", {
  4511. /**
  4512. * Get/set the bottom thickness in percentage.
  4513. * The get will return a valid value only if the edge mode is percentage.
  4514. * The Set will change the edge mode if needed
  4515. */
  4516. get: function () {
  4517. return this._percentages[3];
  4518. },
  4519. set: function (value) {
  4520. this._setPercentage(value, 3, true);
  4521. },
  4522. enumerable: true,
  4523. configurable: true
  4524. });
  4525. Object.defineProperty(PrimitiveThickness.prototype, "topMode", {
  4526. /**
  4527. * Get/set the top mode. The setter shouldn't be used, other setters with value should be preferred
  4528. */
  4529. get: function () {
  4530. return this._getType(0, false);
  4531. },
  4532. set: function (mode) {
  4533. this._setType(0, mode);
  4534. },
  4535. enumerable: true,
  4536. configurable: true
  4537. });
  4538. Object.defineProperty(PrimitiveThickness.prototype, "leftMode", {
  4539. /**
  4540. * Get/set the left mode. The setter shouldn't be used, other setters with value should be preferred
  4541. */
  4542. get: function () {
  4543. return this._getType(1, false);
  4544. },
  4545. set: function (mode) {
  4546. this._setType(1, mode);
  4547. },
  4548. enumerable: true,
  4549. configurable: true
  4550. });
  4551. Object.defineProperty(PrimitiveThickness.prototype, "rightMode", {
  4552. /**
  4553. * Get/set the right mode. The setter shouldn't be used, other setters with value should be preferred
  4554. */
  4555. get: function () {
  4556. return this._getType(2, false);
  4557. },
  4558. set: function (mode) {
  4559. this._setType(2, mode);
  4560. },
  4561. enumerable: true,
  4562. configurable: true
  4563. });
  4564. Object.defineProperty(PrimitiveThickness.prototype, "bottomMode", {
  4565. /**
  4566. * Get/set the bottom mode. The setter shouldn't be used, other setters with value should be preferred
  4567. */
  4568. get: function () {
  4569. return this._getType(3, false);
  4570. },
  4571. set: function (mode) {
  4572. this._setType(3, mode);
  4573. },
  4574. enumerable: true,
  4575. configurable: true
  4576. });
  4577. Object.defineProperty(PrimitiveThickness.prototype, "isDefault", {
  4578. get: function () {
  4579. return this._flags === 0x1111;
  4580. },
  4581. enumerable: true,
  4582. configurable: true
  4583. });
  4584. PrimitiveThickness.prototype._computePixels = function (index, sourceArea, emitChanged) {
  4585. var type = this._getType(index, false);
  4586. if (type === PrimitiveThickness_1.Inherit) {
  4587. this._parentAccess()._computePixels(index, sourceArea, emitChanged);
  4588. return;
  4589. }
  4590. if (type !== PrimitiveThickness_1.Percentage) {
  4591. return;
  4592. }
  4593. var pixels = ((index === 0 || index === 3) ? sourceArea.height : sourceArea.width) * this._percentages[index];
  4594. this._pixels[index] = pixels;
  4595. if (emitChanged) {
  4596. this.onChangeCallback();
  4597. }
  4598. };
  4599. PrimitiveThickness.prototype.onChangeCallback = function () {
  4600. if (this._changedCallback) {
  4601. this._changedCallback();
  4602. }
  4603. };
  4604. /**
  4605. * Compute the positioning/size of an area considering the thickness of this object and a given alignment
  4606. * @param sourceArea the source area where the content must be sized/positioned
  4607. * @param contentSize the content size to position/resize
  4608. * @param alignment the alignment setting
  4609. * @param dstOffset the position of the content, x, y, z, w are left, bottom, right, top
  4610. * @param dstArea the new size of the content
  4611. */
  4612. PrimitiveThickness.prototype.computeWithAlignment = function (sourceArea, contentSize, alignment, dstOffset, dstArea, computeLayoutArea) {
  4613. if (computeLayoutArea === void 0) { computeLayoutArea = false; }
  4614. // Fetch some data
  4615. var topType = this._getType(0, true);
  4616. var leftType = this._getType(1, true);
  4617. var rightType = this._getType(2, true);
  4618. var bottomType = this._getType(3, true);
  4619. var hasWidth = contentSize && (contentSize.width != null);
  4620. var hasHeight = contentSize && (contentSize.height != null);
  4621. var width = hasWidth ? contentSize.width : 0;
  4622. var height = hasHeight ? contentSize.height : 0;
  4623. var isTopAuto = topType === PrimitiveThickness_1.Auto;
  4624. var isLeftAuto = leftType === PrimitiveThickness_1.Auto;
  4625. var isRightAuto = rightType === PrimitiveThickness_1.Auto;
  4626. var isBottomAuto = bottomType === PrimitiveThickness_1.Auto;
  4627. switch (alignment.horizontal) {
  4628. case PrimitiveAlignment.AlignLeft:
  4629. {
  4630. if (isLeftAuto) {
  4631. dstOffset.x = 0;
  4632. }
  4633. else {
  4634. this._computePixels(1, sourceArea, true);
  4635. dstOffset.x = this.leftPixels;
  4636. }
  4637. dstArea.width = width;
  4638. if (computeLayoutArea) {
  4639. dstArea.width += this.leftPixels;
  4640. }
  4641. dstOffset.z = sourceArea.width - (dstOffset.x + width);
  4642. break;
  4643. }
  4644. case PrimitiveAlignment.AlignRight:
  4645. {
  4646. if (isRightAuto) {
  4647. dstOffset.x = Math.round(sourceArea.width - width);
  4648. }
  4649. else {
  4650. this._computePixels(2, sourceArea, true);
  4651. dstOffset.x = Math.round(sourceArea.width - (width + this.rightPixels));
  4652. }
  4653. dstArea.width = width;
  4654. if (computeLayoutArea) {
  4655. dstArea.width += this.rightPixels;
  4656. }
  4657. dstOffset.z = this.rightPixels;
  4658. break;
  4659. }
  4660. case PrimitiveAlignment.AlignStretch:
  4661. {
  4662. if (isLeftAuto) {
  4663. dstOffset.x = 0;
  4664. }
  4665. else {
  4666. this._computePixels(1, sourceArea, true);
  4667. dstOffset.x = this.leftPixels;
  4668. }
  4669. var right = 0;
  4670. if (!isRightAuto) {
  4671. this._computePixels(2, sourceArea, true);
  4672. right = this.rightPixels;
  4673. }
  4674. dstArea.width = sourceArea.width - (dstOffset.x + right);
  4675. dstOffset.z = this.rightPixels;
  4676. break;
  4677. }
  4678. case PrimitiveAlignment.AlignCenter:
  4679. {
  4680. if (!isLeftAuto) {
  4681. this._computePixels(1, sourceArea, true);
  4682. }
  4683. if (!isRightAuto) {
  4684. this._computePixels(2, sourceArea, true);
  4685. }
  4686. var offset = (isLeftAuto ? 0 : this.leftPixels) - (isRightAuto ? 0 : this.rightPixels);
  4687. dstOffset.x = Math.round(((sourceArea.width - width) / 2) + offset);
  4688. dstArea.width = width;
  4689. dstOffset.z = sourceArea.width - (dstOffset.x + width);
  4690. break;
  4691. }
  4692. }
  4693. switch (alignment.vertical) {
  4694. case PrimitiveAlignment.AlignTop:
  4695. {
  4696. if (isTopAuto) {
  4697. dstOffset.y = sourceArea.height - height;
  4698. }
  4699. else {
  4700. this._computePixels(0, sourceArea, true);
  4701. dstOffset.y = Math.round(sourceArea.height - (height + this.topPixels));
  4702. }
  4703. dstArea.height = height;
  4704. if (computeLayoutArea) {
  4705. dstArea.height += this.topPixels;
  4706. }
  4707. dstOffset.w = this.topPixels;
  4708. break;
  4709. }
  4710. case PrimitiveAlignment.AlignBottom:
  4711. {
  4712. if (isBottomAuto) {
  4713. dstOffset.y = 0;
  4714. }
  4715. else {
  4716. this._computePixels(3, sourceArea, true);
  4717. dstOffset.y = this.bottomPixels;
  4718. }
  4719. dstArea.height = height;
  4720. if (computeLayoutArea) {
  4721. dstArea.height += this.bottomPixels;
  4722. }
  4723. dstOffset.w = sourceArea.height - (dstOffset.y + height);
  4724. break;
  4725. }
  4726. case PrimitiveAlignment.AlignStretch:
  4727. {
  4728. if (isBottomAuto) {
  4729. dstOffset.y = 0;
  4730. }
  4731. else {
  4732. this._computePixels(3, sourceArea, true);
  4733. dstOffset.y = this.bottomPixels;
  4734. }
  4735. var top_1 = 0;
  4736. if (!isTopAuto) {
  4737. this._computePixels(0, sourceArea, true);
  4738. top_1 = this.topPixels;
  4739. }
  4740. dstArea.height = sourceArea.height - (dstOffset.y + top_1);
  4741. dstOffset.w = this.topPixels;
  4742. break;
  4743. }
  4744. case PrimitiveAlignment.AlignCenter:
  4745. {
  4746. if (!isTopAuto) {
  4747. this._computePixels(0, sourceArea, true);
  4748. }
  4749. if (!isBottomAuto) {
  4750. this._computePixels(3, sourceArea, true);
  4751. }
  4752. var offset = (isBottomAuto ? 0 : this.bottomPixels) - (isTopAuto ? 0 : this.topPixels);
  4753. dstOffset.y = Math.round(((sourceArea.height - height) / 2) + offset);
  4754. dstArea.height = height;
  4755. dstOffset.w = sourceArea.height - (dstOffset.y + height);
  4756. break;
  4757. }
  4758. }
  4759. };
  4760. /**
  4761. * Compute an area and its position considering this thickness properties based on a given source area
  4762. * @param sourceArea the source area
  4763. * @param dstOffset the position of the resulting area
  4764. * @param dstArea the size of the resulting area
  4765. */
  4766. PrimitiveThickness.prototype.compute = function (sourceArea, dstOffset, dstArea) {
  4767. this._computePixels(0, sourceArea, true);
  4768. this._computePixels(1, sourceArea, true);
  4769. this._computePixels(2, sourceArea, true);
  4770. this._computePixels(3, sourceArea, true);
  4771. dstOffset.x = this.leftPixels;
  4772. dstArea.width = sourceArea.width - (dstOffset.x + this.rightPixels);
  4773. dstOffset.y = this.bottomPixels;
  4774. dstArea.height = sourceArea.height - (dstOffset.y + this.topPixels);
  4775. dstOffset.z = this.rightPixels;
  4776. dstOffset.w = this.topPixels;
  4777. };
  4778. /**
  4779. * Compute an area considering this thickness properties based on a given source area
  4780. * @param sourceArea the source area
  4781. * @param result the resulting area
  4782. */
  4783. PrimitiveThickness.prototype.computeArea = function (sourceArea, result) {
  4784. this._computePixels(0, sourceArea, true);
  4785. this._computePixels(1, sourceArea, true);
  4786. this._computePixels(2, sourceArea, true);
  4787. this._computePixels(3, sourceArea, true);
  4788. result.width = this.leftPixels + sourceArea.width + this.rightPixels;
  4789. result.height = this.bottomPixels + sourceArea.height + this.topPixels;
  4790. };
  4791. PrimitiveThickness.prototype.enlarge = function (sourceArea, dstOffset, enlargedArea) {
  4792. this._computePixels(0, sourceArea, true);
  4793. this._computePixels(1, sourceArea, true);
  4794. this._computePixels(2, sourceArea, true);
  4795. this._computePixels(3, sourceArea, true);
  4796. dstOffset.x = this.leftPixels;
  4797. enlargedArea.width = sourceArea.width + (dstOffset.x + this.rightPixels);
  4798. dstOffset.y = this.bottomPixels;
  4799. enlargedArea.height = sourceArea.height + (dstOffset.y + this.topPixels);
  4800. dstOffset.z = this.rightPixels;
  4801. dstOffset.w = this.topPixels;
  4802. };
  4803. return PrimitiveThickness;
  4804. }());
  4805. PrimitiveThickness.Auto = 0x1;
  4806. PrimitiveThickness.Inherit = 0x2;
  4807. PrimitiveThickness.Percentage = 0x4;
  4808. PrimitiveThickness.Pixel = 0x8;
  4809. PrimitiveThickness = PrimitiveThickness_1 = __decorate([
  4810. BABYLON.className("PrimitiveThickness", "BABYLON")
  4811. ], PrimitiveThickness);
  4812. BABYLON.PrimitiveThickness = PrimitiveThickness;
  4813. /**
  4814. * Main class used for the Primitive Intersection API
  4815. */
  4816. var IntersectInfo2D = (function () {
  4817. function IntersectInfo2D() {
  4818. this.findFirstOnly = false;
  4819. this.intersectHidden = false;
  4820. this.pickPosition = BABYLON.Vector2.Zero();
  4821. }
  4822. Object.defineProperty(IntersectInfo2D.prototype, "isIntersected", {
  4823. /**
  4824. * true if at least one primitive intersected during the test
  4825. */
  4826. get: function () {
  4827. return this.intersectedPrimitives && this.intersectedPrimitives.length > 0;
  4828. },
  4829. enumerable: true,
  4830. configurable: true
  4831. });
  4832. IntersectInfo2D.prototype.isPrimIntersected = function (prim) {
  4833. for (var _i = 0, _a = this.intersectedPrimitives; _i < _a.length; _i++) {
  4834. var cur = _a[_i];
  4835. if (cur.prim === prim) {
  4836. return cur.intersectionLocation;
  4837. }
  4838. }
  4839. return null;
  4840. };
  4841. // Internals, don't use
  4842. IntersectInfo2D.prototype._exit = function (firstLevel) {
  4843. if (firstLevel) {
  4844. this._globalPickPosition = null;
  4845. }
  4846. };
  4847. return IntersectInfo2D;
  4848. }());
  4849. BABYLON.IntersectInfo2D = IntersectInfo2D;
  4850. var Prim2DBase = Prim2DBase_1 = (function (_super) {
  4851. __extends(Prim2DBase, _super);
  4852. function Prim2DBase(settings) {
  4853. var _this;
  4854. // Avoid checking every time if the object exists
  4855. if (settings == null) {
  4856. settings = {};
  4857. }
  4858. // BASE CLASS CALL
  4859. _this = _super.call(this) || this;
  4860. // Fetch the owner, parent. There're many ways to do it and we can end up with nothing for both
  4861. var owner;
  4862. var parent;
  4863. if (Prim2DBase_1._isCanvasInit) {
  4864. owner = _this;
  4865. parent = null;
  4866. _this._canvasPreInit(settings);
  4867. }
  4868. else {
  4869. if (settings.parent != null) {
  4870. parent = settings.parent;
  4871. owner = settings.parent.owner;
  4872. if (!owner) {
  4873. throw new Error("Parent " + parent.id + " of " + settings.id + " doesn't have a valid owner!");
  4874. }
  4875. if (!(_this instanceof BABYLON.Group2D) && !(_this instanceof BABYLON.Sprite2D && settings.id != null && settings.id.indexOf("__cachedSpriteOfGroup__") === 0) && (owner.cachingStrategy === BABYLON.Canvas2D.CACHESTRATEGY_TOPLEVELGROUPS) && (parent === owner)) {
  4876. throw new Error("Can't create a primitive with the canvas as direct parent when the caching strategy is TOPLEVELGROUPS. You need to create a Group below the canvas and use it as the parent for the primitive");
  4877. }
  4878. }
  4879. }
  4880. // Fields initialization
  4881. _this._layoutEngine = BABYLON.CanvasLayoutEngine.Singleton;
  4882. _this._size = null; //Size.Zero();
  4883. _this._scale = new BABYLON.Vector2(1, 1);
  4884. _this._actualSize = null;
  4885. _this._boundingSize = BABYLON.Size.Zero();
  4886. _this._layoutArea = BABYLON.Size.Zero();
  4887. _this._layoutAreaPos = null;
  4888. _this._layoutBoundingInfo = null;
  4889. _this._marginOffset = BABYLON.Vector4.Zero();
  4890. _this._paddingOffset = BABYLON.Vector4.Zero();
  4891. _this._parentPaddingOffset = BABYLON.Vector2.Zero();
  4892. _this._parentContentArea = BABYLON.Size.Zero();
  4893. _this._lastAutoSizeArea = BABYLON.Size.Zero();
  4894. _this._contentArea = new BABYLON.Size(null, null);
  4895. _this._pointerEventObservable = new BABYLON.Observable();
  4896. _this._boundingInfo = new BABYLON.BoundingInfo2D();
  4897. _this._owner = owner;
  4898. _this._parent = null;
  4899. _this._margin = null;
  4900. _this._padding = null;
  4901. _this._marginAlignment = null;
  4902. _this._id = settings.id;
  4903. _this._children = new Array();
  4904. _this._localTransform = new BABYLON.Matrix();
  4905. _this._globalTransform = null;
  4906. _this._invGlobalTransform = null;
  4907. _this._globalTransformProcessStep = 0;
  4908. _this._globalTransformStep = 0;
  4909. _this._renderGroup = null;
  4910. _this._primLinearPosition = 0;
  4911. _this._manualZOrder = null;
  4912. _this._zOrder = 0;
  4913. _this._zMax = 0;
  4914. _this._firstZDirtyIndex = Prim2DBase_1._bigInt;
  4915. _this._actualOpacity = 0;
  4916. _this._actualScale = BABYLON.Vector2.Zero();
  4917. _this._displayDebugAreas = false;
  4918. _this._debugAreaGroup = null;
  4919. var isPickable = true;
  4920. var isContainer = true;
  4921. if (settings.isPickable !== undefined) {
  4922. isPickable = settings.isPickable;
  4923. }
  4924. if (settings.isContainer !== undefined) {
  4925. isContainer = settings.isContainer;
  4926. }
  4927. if (settings.dontInheritParentScale) {
  4928. _this._setFlags(BABYLON.SmartPropertyPrim.flagDontInheritParentScale);
  4929. }
  4930. _this._setFlags((isPickable ? BABYLON.SmartPropertyPrim.flagIsPickable : 0) | BABYLON.SmartPropertyPrim.flagBoundingInfoDirty | BABYLON.SmartPropertyPrim.flagActualOpacityDirty | (isContainer ? BABYLON.SmartPropertyPrim.flagIsContainer : 0) | BABYLON.SmartPropertyPrim.flagActualScaleDirty | BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty);
  4931. if (settings.opacity != null) {
  4932. _this._opacity = settings.opacity;
  4933. }
  4934. else {
  4935. _this._opacity = 1;
  4936. }
  4937. _this._updateRenderMode();
  4938. if (settings.childrenFlatZOrder) {
  4939. _this._setFlags(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  4940. }
  4941. // If the parent is given, initialize the hierarchy/owner related data
  4942. if (parent != null) {
  4943. parent.addChild(_this);
  4944. _this._hierarchyDepth = parent._hierarchyDepth + 1;
  4945. _this._patchHierarchy(parent.owner);
  4946. }
  4947. // If it's a group, detect its own states
  4948. if (_this.owner && _this instanceof BABYLON.Group2D) {
  4949. var group = _this;
  4950. group.detectGroupStates();
  4951. }
  4952. // Time to insert children if some are specified
  4953. if (settings.children != null) {
  4954. for (var _i = 0, _a = settings.children; _i < _a.length; _i++) {
  4955. var child = _a[_i];
  4956. _this.addChild(child);
  4957. // Good time to patch the hierarchy, it won't go very far if there's no need to
  4958. if (_this.owner != null && _this._hierarchyDepth != null) {
  4959. child._patchHierarchy(_this.owner);
  4960. }
  4961. }
  4962. }
  4963. if (settings.zOrder != null) {
  4964. _this.zOrder = settings.zOrder;
  4965. }
  4966. // Set the model related properties
  4967. if (settings.position != null) {
  4968. _this.position = settings.position;
  4969. }
  4970. else if (settings.x != null || settings.y != null) {
  4971. _this.position = new BABYLON.Vector2(settings.x || 0, settings.y || 0);
  4972. }
  4973. else {
  4974. _this._position = null;
  4975. }
  4976. _this.rotation = (settings.rotation == null) ? 0 : settings.rotation;
  4977. if (settings.scale != null) {
  4978. _this.scale = settings.scale;
  4979. }
  4980. else {
  4981. if (settings.scaleX != null) {
  4982. _this.scaleX = settings.scaleX;
  4983. }
  4984. if (settings.scaleY != null) {
  4985. _this.scaleY = settings.scaleY;
  4986. }
  4987. }
  4988. _this.levelVisible = (settings.isVisible == null) ? true : settings.isVisible;
  4989. _this.origin = settings.origin || new BABYLON.Vector2(0.5, 0.5);
  4990. // Layout Engine
  4991. if (settings.layoutEngine != null) {
  4992. if (typeof settings.layoutEngine === "string") {
  4993. var name_1 = settings.layoutEngine.toLocaleLowerCase().trim();
  4994. if (name_1 === "canvas" || name_1 === "canvaslayoutengine") {
  4995. _this.layoutEngine = BABYLON.CanvasLayoutEngine.Singleton;
  4996. }
  4997. else if (name_1.indexOf("stackpanel") === 0 || name_1.indexOf("horizontalstackpanel") === 0) {
  4998. _this.layoutEngine = BABYLON.StackPanelLayoutEngine.Horizontal;
  4999. }
  5000. else if (name_1.indexOf("verticalstackpanel") === 0) {
  5001. _this.layoutEngine = BABYLON.StackPanelLayoutEngine.Vertical;
  5002. }
  5003. }
  5004. else if (settings.layoutEngine instanceof BABYLON.LayoutEngineBase) {
  5005. _this.layoutEngine = settings.layoutEngine;
  5006. }
  5007. }
  5008. // Set the layout/margin stuffs
  5009. if (settings.marginTop) {
  5010. _this.margin.setTop(settings.marginTop);
  5011. }
  5012. if (settings.marginLeft) {
  5013. _this.margin.setLeft(settings.marginLeft);
  5014. }
  5015. if (settings.marginRight) {
  5016. _this.margin.setRight(settings.marginRight);
  5017. }
  5018. if (settings.marginBottom) {
  5019. _this.margin.setBottom(settings.marginBottom);
  5020. }
  5021. if (settings.margin) {
  5022. if (typeof settings.margin === "string") {
  5023. _this.margin.fromString(settings.margin);
  5024. }
  5025. else {
  5026. _this.margin.fromUniformPixels(settings.margin);
  5027. }
  5028. }
  5029. if (settings.marginHAlignment) {
  5030. _this.marginAlignment.horizontal = settings.marginHAlignment;
  5031. }
  5032. if (settings.marginVAlignment) {
  5033. _this.marginAlignment.vertical = settings.marginVAlignment;
  5034. }
  5035. if (settings.marginAlignment) {
  5036. _this.marginAlignment.fromString(settings.marginAlignment);
  5037. }
  5038. if (settings.paddingTop) {
  5039. _this.padding.setTop(settings.paddingTop);
  5040. }
  5041. if (settings.paddingLeft) {
  5042. _this.padding.setLeft(settings.paddingLeft);
  5043. }
  5044. if (settings.paddingRight) {
  5045. _this.padding.setRight(settings.paddingRight);
  5046. }
  5047. if (settings.paddingBottom) {
  5048. _this.padding.setBottom(settings.paddingBottom);
  5049. }
  5050. if (settings.padding) {
  5051. _this.padding.fromString(settings.padding);
  5052. }
  5053. // Dirty layout and positioning
  5054. _this._parentLayoutDirty();
  5055. _this._positioningDirty();
  5056. return _this;
  5057. }
  5058. Object.defineProperty(Prim2DBase.prototype, "actionManager", {
  5059. get: function () {
  5060. if (!this._actionManager) {
  5061. this._actionManager = new BABYLON.ActionManager(this.owner.scene);
  5062. }
  5063. return this._actionManager;
  5064. },
  5065. enumerable: true,
  5066. configurable: true
  5067. });
  5068. /**
  5069. * From 'this' primitive, traverse up (from parent to parent) until the given predicate is true
  5070. * @param predicate the predicate to test on each parent
  5071. * @return the first primitive where the predicate was successful
  5072. */
  5073. Prim2DBase.prototype.traverseUp = function (predicate) {
  5074. var p = this;
  5075. while (p != null) {
  5076. if (predicate(p)) {
  5077. return p;
  5078. }
  5079. p = p._parent;
  5080. }
  5081. return null;
  5082. };
  5083. Object.defineProperty(Prim2DBase.prototype, "owner", {
  5084. /**
  5085. * Retrieve the owner Canvas2D
  5086. */
  5087. get: function () {
  5088. return this._owner;
  5089. },
  5090. enumerable: true,
  5091. configurable: true
  5092. });
  5093. Object.defineProperty(Prim2DBase.prototype, "parent", {
  5094. /**
  5095. * Get the parent primitive (can be the Canvas, only the Canvas has no parent)
  5096. */
  5097. get: function () {
  5098. return this._parent;
  5099. },
  5100. enumerable: true,
  5101. configurable: true
  5102. });
  5103. Object.defineProperty(Prim2DBase.prototype, "children", {
  5104. /**
  5105. * The array of direct children primitives
  5106. */
  5107. get: function () {
  5108. return this._children;
  5109. },
  5110. enumerable: true,
  5111. configurable: true
  5112. });
  5113. Object.defineProperty(Prim2DBase.prototype, "id", {
  5114. /**
  5115. * The identifier of this primitive, may not be unique, it's for information purpose only
  5116. */
  5117. get: function () {
  5118. return this._id;
  5119. },
  5120. set: function (value) {
  5121. if (this._id === value) {
  5122. return;
  5123. }
  5124. var oldValue = this._id;
  5125. this.onPropertyChanged("id", oldValue, this._id);
  5126. },
  5127. enumerable: true,
  5128. configurable: true
  5129. });
  5130. Object.defineProperty(Prim2DBase.prototype, "actualPosition", {
  5131. get: function () {
  5132. if (this._actualPosition != null) {
  5133. return this._actualPosition;
  5134. }
  5135. if (this._position != null) {
  5136. return this._position;
  5137. }
  5138. // At least return 0,0, we can't return null on actualPosition
  5139. return Prim2DBase_1._nullPosition;
  5140. },
  5141. /**
  5142. * DO NOT INVOKE for internal purpose only
  5143. */
  5144. set: function (val) {
  5145. this._actualPosition = val;
  5146. },
  5147. enumerable: true,
  5148. configurable: true
  5149. });
  5150. Object.defineProperty(Prim2DBase.prototype, "actualX", {
  5151. /**
  5152. * Shortcut to actualPosition.x
  5153. */
  5154. get: function () {
  5155. return this.actualPosition.x;
  5156. },
  5157. set: function (val) {
  5158. this._actualPosition.x = val;
  5159. this._triggerPropertyChanged(Prim2DBase_1.actualPositionProperty, this._actualPosition);
  5160. },
  5161. enumerable: true,
  5162. configurable: true
  5163. });
  5164. Object.defineProperty(Prim2DBase.prototype, "actualY", {
  5165. /**
  5166. * Shortcut to actualPosition.y
  5167. */
  5168. get: function () {
  5169. return this.actualPosition.y;
  5170. },
  5171. set: function (val) {
  5172. this._actualPosition.y = val;
  5173. this._triggerPropertyChanged(Prim2DBase_1.actualPositionProperty, this._actualPosition);
  5174. },
  5175. enumerable: true,
  5176. configurable: true
  5177. });
  5178. Object.defineProperty(Prim2DBase.prototype, "position", {
  5179. /**
  5180. * Position of the primitive, relative to its parent.
  5181. * BEWARE: if you change only position.x or y it won't trigger a property change and you won't have the expected behavior.
  5182. * Use this property to set a new Vector2 object, otherwise to change only the x/y use Prim2DBase.x or y properties.
  5183. * Setting this property may have no effect is specific alignment are in effect.
  5184. */
  5185. get: function () {
  5186. if (!this._position) {
  5187. this._position = BABYLON.Vector2.Zero();
  5188. }
  5189. return this._position;
  5190. },
  5191. set: function (value) {
  5192. if (!this._checkPositionChange()) {
  5193. return;
  5194. }
  5195. this._position = value;
  5196. this._triggerPropertyChanged(Prim2DBase_1.actualPositionProperty, value);
  5197. },
  5198. enumerable: true,
  5199. configurable: true
  5200. });
  5201. Object.defineProperty(Prim2DBase.prototype, "x", {
  5202. /**
  5203. * Direct access to the position.x value of the primitive
  5204. * Use this property when you only want to change one component of the position property
  5205. */
  5206. get: function () {
  5207. if (!this._position) {
  5208. return null;
  5209. }
  5210. return this._position.x;
  5211. },
  5212. set: function (value) {
  5213. if (!this._checkPositionChange()) {
  5214. return;
  5215. }
  5216. if (!this._position) {
  5217. this._position = BABYLON.Vector2.Zero();
  5218. }
  5219. if (this._position.x === value) {
  5220. return;
  5221. }
  5222. this._position.x = value;
  5223. this._triggerPropertyChanged(Prim2DBase_1.positionProperty, value);
  5224. this._triggerPropertyChanged(Prim2DBase_1.actualPositionProperty, value);
  5225. },
  5226. enumerable: true,
  5227. configurable: true
  5228. });
  5229. Object.defineProperty(Prim2DBase.prototype, "y", {
  5230. /**
  5231. * Direct access to the position.y value of the primitive
  5232. * Use this property when you only want to change one component of the position property
  5233. */
  5234. get: function () {
  5235. if (!this._position) {
  5236. return null;
  5237. }
  5238. return this._position.y;
  5239. },
  5240. set: function (value) {
  5241. if (!this._checkPositionChange()) {
  5242. return;
  5243. }
  5244. if (!this._position) {
  5245. this._position = BABYLON.Vector2.Zero();
  5246. }
  5247. if (this._position.y === value) {
  5248. return;
  5249. }
  5250. this._position.y = value;
  5251. this._triggerPropertyChanged(Prim2DBase_1.positionProperty, value);
  5252. this._triggerPropertyChanged(Prim2DBase_1.actualPositionProperty, value);
  5253. },
  5254. enumerable: true,
  5255. configurable: true
  5256. });
  5257. Object.defineProperty(Prim2DBase.prototype, "size", {
  5258. /**
  5259. * Size of the primitive or its bounding area
  5260. * BEWARE: if you change only size.width or height it won't trigger a property change and you won't have the expected behavior.
  5261. * Use this property to set a new Size object, otherwise to change only the width/height use Prim2DBase.width or height properties.
  5262. */
  5263. get: function () {
  5264. return this.internalGetSize();
  5265. },
  5266. set: function (value) {
  5267. this.internalSetSize(value);
  5268. },
  5269. enumerable: true,
  5270. configurable: true
  5271. });
  5272. Prim2DBase.prototype.internalGetSize = function () {
  5273. if (!this._size || this._size.width == null || this._size.height == null) {
  5274. if (Prim2DBase_1.boundinbBoxReentrency) {
  5275. return Prim2DBase_1.nullSize;
  5276. }
  5277. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagBoundingInfoDirty)) {
  5278. return this._boundingSize;
  5279. }
  5280. Prim2DBase_1.boundinbBoxReentrency = true;
  5281. var b = this.boundingInfo;
  5282. Prim2DBase_1.boundinbBoxReentrency = false;
  5283. return this._boundingSize;
  5284. }
  5285. return this._size;
  5286. };
  5287. Prim2DBase.prototype.internalSetSize = function (value) {
  5288. this._size = value;
  5289. };
  5290. Object.defineProperty(Prim2DBase.prototype, "width", {
  5291. /**
  5292. * Direct access to the size.width value of the primitive
  5293. * Use this property when you only want to change one component of the size property
  5294. */
  5295. get: function () {
  5296. if (!this.size) {
  5297. return null;
  5298. }
  5299. return this.size.width;
  5300. },
  5301. set: function (value) {
  5302. if (this.size && this.size.width === value) {
  5303. return;
  5304. }
  5305. if (!this.size) {
  5306. this.size = new BABYLON.Size(value, 0);
  5307. }
  5308. else {
  5309. this.size.width = value;
  5310. }
  5311. this._triggerPropertyChanged(Prim2DBase_1.sizeProperty, value);
  5312. this._positioningDirty();
  5313. },
  5314. enumerable: true,
  5315. configurable: true
  5316. });
  5317. Object.defineProperty(Prim2DBase.prototype, "height", {
  5318. /**
  5319. * Direct access to the size.height value of the primitive
  5320. * Use this property when you only want to change one component of the size property
  5321. */
  5322. get: function () {
  5323. if (!this.size) {
  5324. return null;
  5325. }
  5326. return this.size.height;
  5327. },
  5328. set: function (value) {
  5329. if (this.size && this.size.height === value) {
  5330. return;
  5331. }
  5332. if (!this.size) {
  5333. this.size = new BABYLON.Size(0, value);
  5334. }
  5335. else {
  5336. this.size.height = value;
  5337. }
  5338. this._triggerPropertyChanged(Prim2DBase_1.sizeProperty, value);
  5339. this._positioningDirty();
  5340. },
  5341. enumerable: true,
  5342. configurable: true
  5343. });
  5344. Object.defineProperty(Prim2DBase.prototype, "rotation", {
  5345. get: function () {
  5346. return this._rotation;
  5347. },
  5348. set: function (value) {
  5349. this._rotation = value;
  5350. },
  5351. enumerable: true,
  5352. configurable: true
  5353. });
  5354. Object.defineProperty(Prim2DBase.prototype, "scale", {
  5355. get: function () {
  5356. return this._scale.x;
  5357. },
  5358. set: function (value) {
  5359. this._scale.x = this._scale.y = value;
  5360. this._setFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  5361. this._spreadActualScaleDirty();
  5362. },
  5363. enumerable: true,
  5364. configurable: true
  5365. });
  5366. Object.defineProperty(Prim2DBase.prototype, "actualSize", {
  5367. /**
  5368. * Return the size of the primitive as it's being rendered into the target.
  5369. * This value may be different of the size property when layout/alignment is used or specific primitive types can implement a custom logic through this property.
  5370. * BEWARE: don't use the setter, it's for internal purpose only
  5371. * Note to implementers: you have to override this property and declare if necessary a @xxxxInstanceLevel decorator
  5372. */
  5373. get: function () {
  5374. if (this._actualSize) {
  5375. return this._actualSize;
  5376. }
  5377. return this._size;
  5378. },
  5379. set: function (value) {
  5380. if (this._actualSize.equals(value)) {
  5381. return;
  5382. }
  5383. this._actualSize = value;
  5384. },
  5385. enumerable: true,
  5386. configurable: true
  5387. });
  5388. Object.defineProperty(Prim2DBase.prototype, "actualWidth", {
  5389. /**
  5390. * Shortcut to actualSize.width
  5391. */
  5392. get: function () {
  5393. return this.actualSize.width;
  5394. },
  5395. set: function (val) {
  5396. this._actualSize.width = val;
  5397. this._triggerPropertyChanged(Prim2DBase_1.actualSizeProperty, this._actualSize);
  5398. },
  5399. enumerable: true,
  5400. configurable: true
  5401. });
  5402. Object.defineProperty(Prim2DBase.prototype, "actualHeight", {
  5403. /**
  5404. * Shortcut to actualPosition.height
  5405. */
  5406. get: function () {
  5407. return this.actualSize.height;
  5408. },
  5409. set: function (val) {
  5410. this._actualSize.height = val;
  5411. this._triggerPropertyChanged(Prim2DBase_1.actualPositionProperty, this._actualSize);
  5412. },
  5413. enumerable: true,
  5414. configurable: true
  5415. });
  5416. Object.defineProperty(Prim2DBase.prototype, "actualZOffset", {
  5417. get: function () {
  5418. if (this._manualZOrder != null) {
  5419. return this._manualZOrder;
  5420. }
  5421. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  5422. this._updateZOrder();
  5423. }
  5424. return (1 - this._zOrder);
  5425. },
  5426. enumerable: true,
  5427. configurable: true
  5428. });
  5429. Object.defineProperty(Prim2DBase.prototype, "minSize", {
  5430. /**
  5431. * Get or set the minimal size the Layout Engine should respect when computing the primitive's actualSize.
  5432. * The Primitive's size won't be less than specified.
  5433. * The default value depends of the Primitive type
  5434. */
  5435. get: function () {
  5436. return this._minSize;
  5437. },
  5438. set: function (value) {
  5439. if (this._minSize && value && this._minSize.equals(value)) {
  5440. return;
  5441. }
  5442. this._minSize = value;
  5443. this._parentLayoutDirty();
  5444. },
  5445. enumerable: true,
  5446. configurable: true
  5447. });
  5448. Object.defineProperty(Prim2DBase.prototype, "maxSize", {
  5449. /**
  5450. * Get or set the maximal size the Layout Engine should respect when computing the primitive's actualSize.
  5451. * The Primitive's size won't be more than specified.
  5452. * The default value depends of the Primitive type
  5453. */
  5454. get: function () {
  5455. return this._maxSize;
  5456. },
  5457. set: function (value) {
  5458. if (this._maxSize && value && this._maxSize.equals(value)) {
  5459. return;
  5460. }
  5461. this._maxSize = value;
  5462. this._parentLayoutDirty();
  5463. },
  5464. enumerable: true,
  5465. configurable: true
  5466. });
  5467. Object.defineProperty(Prim2DBase.prototype, "origin", {
  5468. /**
  5469. * The origin defines the normalized coordinate of the center of the primitive, from the bottom/left corner.
  5470. * The origin is used only to compute transformation of the primitive, it has no meaning in the primitive local frame of reference
  5471. * For instance:
  5472. * 0,0 means the center is bottom/left. Which is the default for Canvas2D instances
  5473. * 0.5,0.5 means the center is at the center of the primitive, which is default of all types of Primitives
  5474. * 0,1 means the center is top/left
  5475. * @returns The normalized center.
  5476. */
  5477. get: function () {
  5478. return this._origin;
  5479. },
  5480. set: function (value) {
  5481. this._origin = value;
  5482. },
  5483. enumerable: true,
  5484. configurable: true
  5485. });
  5486. Object.defineProperty(Prim2DBase.prototype, "levelVisible", {
  5487. get: function () {
  5488. return this._isFlagSet(BABYLON.SmartPropertyPrim.flagLevelVisible);
  5489. },
  5490. set: function (value) {
  5491. this._changeFlags(BABYLON.SmartPropertyPrim.flagLevelVisible, value);
  5492. },
  5493. enumerable: true,
  5494. configurable: true
  5495. });
  5496. Object.defineProperty(Prim2DBase.prototype, "isVisible", {
  5497. get: function () {
  5498. return this._isFlagSet(BABYLON.SmartPropertyPrim.flagIsVisible);
  5499. },
  5500. set: function (value) {
  5501. this._changeFlags(BABYLON.SmartPropertyPrim.flagIsVisible, value);
  5502. },
  5503. enumerable: true,
  5504. configurable: true
  5505. });
  5506. Object.defineProperty(Prim2DBase.prototype, "zOrder", {
  5507. get: function () {
  5508. return this._manualZOrder;
  5509. },
  5510. set: function (value) {
  5511. if (this._manualZOrder === value) {
  5512. return;
  5513. }
  5514. this._manualZOrder = value;
  5515. this.onZOrderChanged();
  5516. if (this._actualZOrderChangedObservable && this._actualZOrderChangedObservable.hasObservers()) {
  5517. this._actualZOrderChangedObservable.notifyObservers(value);
  5518. }
  5519. },
  5520. enumerable: true,
  5521. configurable: true
  5522. });
  5523. Object.defineProperty(Prim2DBase.prototype, "isManualZOrder", {
  5524. get: function () {
  5525. return this._manualZOrder != null;
  5526. },
  5527. enumerable: true,
  5528. configurable: true
  5529. });
  5530. Object.defineProperty(Prim2DBase.prototype, "margin", {
  5531. get: function () {
  5532. var _this = this;
  5533. if (!this._margin) {
  5534. this._margin = new PrimitiveThickness(function () {
  5535. if (!_this.parent) {
  5536. return null;
  5537. }
  5538. return _this.parent.margin;
  5539. }, function () { return _this._positioningDirty(); });
  5540. }
  5541. return this._margin;
  5542. },
  5543. set: function (value) {
  5544. this.margin.copyFrom(value);
  5545. },
  5546. enumerable: true,
  5547. configurable: true
  5548. });
  5549. Object.defineProperty(Prim2DBase.prototype, "_hasMargin", {
  5550. /**
  5551. * Check for both margin and marginAlignment, return true if at least one of them is specified with a non default value
  5552. */
  5553. get: function () {
  5554. return (this._margin !== null && !this._margin.isDefault) || (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  5555. },
  5556. enumerable: true,
  5557. configurable: true
  5558. });
  5559. Object.defineProperty(Prim2DBase.prototype, "padding", {
  5560. get: function () {
  5561. var _this = this;
  5562. if (!this._padding) {
  5563. this._padding = new PrimitiveThickness(function () {
  5564. if (!_this.parent) {
  5565. return null;
  5566. }
  5567. return _this.parent.padding;
  5568. }, function () { return _this._positioningDirty(); });
  5569. }
  5570. return this._padding;
  5571. },
  5572. set: function (value) {
  5573. this.padding.copyFrom(value);
  5574. },
  5575. enumerable: true,
  5576. configurable: true
  5577. });
  5578. Object.defineProperty(Prim2DBase.prototype, "_hasPadding", {
  5579. get: function () {
  5580. return this._padding !== null && !this._padding.isDefault;
  5581. },
  5582. enumerable: true,
  5583. configurable: true
  5584. });
  5585. Object.defineProperty(Prim2DBase.prototype, "marginAlignment", {
  5586. get: function () {
  5587. var _this = this;
  5588. if (!this._marginAlignment) {
  5589. this._marginAlignment = new PrimitiveAlignment(function () { return _this._positioningDirty(); });
  5590. }
  5591. return this._marginAlignment;
  5592. },
  5593. set: function (value) {
  5594. this.marginAlignment.copyFrom(value);
  5595. },
  5596. enumerable: true,
  5597. configurable: true
  5598. });
  5599. Object.defineProperty(Prim2DBase.prototype, "_hasMarginAlignment", {
  5600. /**
  5601. * Check if there a marginAlignment specified (non null and not default)
  5602. */
  5603. get: function () {
  5604. return (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  5605. },
  5606. enumerable: true,
  5607. configurable: true
  5608. });
  5609. Object.defineProperty(Prim2DBase.prototype, "opacity", {
  5610. get: function () {
  5611. return this._opacity;
  5612. },
  5613. set: function (value) {
  5614. if (value < 0) {
  5615. value = 0;
  5616. }
  5617. else if (value > 1) {
  5618. value = 1;
  5619. }
  5620. if (this._opacity === value) {
  5621. return;
  5622. }
  5623. this._opacity = value;
  5624. this._setFlags(BABYLON.SmartPropertyPrim.flagActualOpacityDirty);
  5625. this._spreadActualOpacityChanged();
  5626. this._updateRenderMode();
  5627. },
  5628. enumerable: true,
  5629. configurable: true
  5630. });
  5631. Object.defineProperty(Prim2DBase.prototype, "scaleX", {
  5632. get: function () {
  5633. return this._scale.x;
  5634. },
  5635. set: function (value) {
  5636. this._scale.x = value;
  5637. this._setFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  5638. this._spreadActualScaleDirty();
  5639. },
  5640. enumerable: true,
  5641. configurable: true
  5642. });
  5643. Object.defineProperty(Prim2DBase.prototype, "scaleY", {
  5644. get: function () {
  5645. return this._scale.y;
  5646. },
  5647. set: function (value) {
  5648. this._scale.y = value;
  5649. this._setFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  5650. this._spreadActualScaleDirty();
  5651. },
  5652. enumerable: true,
  5653. configurable: true
  5654. });
  5655. Prim2DBase.prototype._spreadActualScaleDirty = function () {
  5656. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5657. var child = _a[_i];
  5658. child._setFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  5659. child._spreadActualScaleDirty();
  5660. }
  5661. };
  5662. Object.defineProperty(Prim2DBase.prototype, "actualScale", {
  5663. /**
  5664. * Returns the actual scale of this Primitive, the value is computed from the scale property of this primitive, multiplied by the actualScale of its parent one (if any). The Vector2 object returned contains the scale for both X and Y axis
  5665. */
  5666. get: function () {
  5667. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagActualScaleDirty)) {
  5668. var cur = this._isFlagSet(BABYLON.SmartPropertyPrim.flagDontInheritParentScale) ? null : this.parent;
  5669. var sx = this.scaleX;
  5670. var sy = this.scaleY;
  5671. while (cur) {
  5672. sx *= cur.scaleX;
  5673. sy *= cur.scaleY;
  5674. cur = cur._isFlagSet(BABYLON.SmartPropertyPrim.flagDontInheritParentScale) ? null : cur.parent;
  5675. }
  5676. this._actualScale.copyFromFloats(sx, sy);
  5677. this._clearFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  5678. }
  5679. return this._actualScale;
  5680. },
  5681. enumerable: true,
  5682. configurable: true
  5683. });
  5684. Object.defineProperty(Prim2DBase.prototype, "actualScaleX", {
  5685. /**
  5686. * Get the actual Scale of the X axis, shortcut for this.actualScale.x
  5687. */
  5688. get: function () {
  5689. return this.actualScale.x;
  5690. },
  5691. enumerable: true,
  5692. configurable: true
  5693. });
  5694. Object.defineProperty(Prim2DBase.prototype, "actualScaleY", {
  5695. /**
  5696. * Get the actual Scale of the Y axis, shortcut for this.actualScale.y
  5697. */
  5698. get: function () {
  5699. return this.actualScale.y;
  5700. },
  5701. enumerable: true,
  5702. configurable: true
  5703. });
  5704. Object.defineProperty(Prim2DBase.prototype, "actualOpacity", {
  5705. /**
  5706. * Get the actual opacity level, this property is computed from the opacity property, multiplied by the actualOpacity of its parent (if any)
  5707. */
  5708. get: function () {
  5709. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagActualOpacityDirty)) {
  5710. var cur = this.parent;
  5711. var op = this.opacity;
  5712. while (cur) {
  5713. op *= cur.opacity;
  5714. cur = cur.parent;
  5715. }
  5716. this._actualOpacity = op;
  5717. this._clearFlags(BABYLON.SmartPropertyPrim.flagActualOpacityDirty);
  5718. }
  5719. return this._actualOpacity;
  5720. },
  5721. enumerable: true,
  5722. configurable: true
  5723. });
  5724. Object.defineProperty(Prim2DBase.prototype, "layoutEngine", {
  5725. /**
  5726. * Get/set the layout engine to use for this primitive.
  5727. * The default layout engine is the CanvasLayoutEngine.
  5728. */
  5729. get: function () {
  5730. if (!this._layoutEngine) {
  5731. this._layoutEngine = BABYLON.CanvasLayoutEngine.Singleton;
  5732. }
  5733. return this._layoutEngine;
  5734. },
  5735. set: function (value) {
  5736. if (this._layoutEngine === value) {
  5737. return;
  5738. }
  5739. this._changeLayoutEngine(value);
  5740. },
  5741. enumerable: true,
  5742. configurable: true
  5743. });
  5744. Object.defineProperty(Prim2DBase.prototype, "layoutArea", {
  5745. /**
  5746. * Get/set the layout are of this primitive.
  5747. * The Layout area is the zone allocated by the Layout Engine for this particular primitive. Margins/Alignment will be computed based on this area.
  5748. * The setter should only be called by a Layout Engine class.
  5749. */
  5750. get: function () {
  5751. return this._layoutArea;
  5752. },
  5753. set: function (val) {
  5754. if (this._layoutArea.equals(val)) {
  5755. return;
  5756. }
  5757. this._positioningDirty();
  5758. if (this.parent) {
  5759. this.parent._setFlags(BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty | BABYLON.SmartPropertyPrim.flagGlobalTransformDirty);
  5760. }
  5761. this._layoutArea = val;
  5762. },
  5763. enumerable: true,
  5764. configurable: true
  5765. });
  5766. Object.defineProperty(Prim2DBase.prototype, "layoutAreaPos", {
  5767. /**
  5768. * Get/set the layout area position (relative to the parent primitive).
  5769. * The setter should only be called by a Layout Engine class.
  5770. */
  5771. get: function () {
  5772. if (!this._layoutAreaPos) {
  5773. this._layoutAreaPos = BABYLON.Vector2.Zero();
  5774. }
  5775. return this._layoutAreaPos;
  5776. },
  5777. set: function (val) {
  5778. if (this._layoutAreaPos && this._layoutAreaPos.equals(val)) {
  5779. return;
  5780. }
  5781. if (this.parent) {
  5782. this.parent._setFlags(BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty | BABYLON.SmartPropertyPrim.flagGlobalTransformDirty);
  5783. }
  5784. this._positioningDirty();
  5785. this._layoutAreaPos = val;
  5786. },
  5787. enumerable: true,
  5788. configurable: true
  5789. });
  5790. Object.defineProperty(Prim2DBase.prototype, "isPickable", {
  5791. /**
  5792. * Define if the Primitive can be subject to intersection test or not (default is true)
  5793. */
  5794. get: function () {
  5795. return this._isFlagSet(BABYLON.SmartPropertyPrim.flagIsPickable);
  5796. },
  5797. set: function (value) {
  5798. this._changeFlags(BABYLON.SmartPropertyPrim.flagIsPickable, value);
  5799. },
  5800. enumerable: true,
  5801. configurable: true
  5802. });
  5803. Object.defineProperty(Prim2DBase.prototype, "isContainer", {
  5804. /**
  5805. * Define if the Primitive acts as a container or not
  5806. * A container will encapsulate its children for interaction event.
  5807. * If it's not a container events will be process down to children if the primitive is not pickable.
  5808. * Default value is true
  5809. */
  5810. get: function () {
  5811. return this._isFlagSet(BABYLON.SmartPropertyPrim.flagIsContainer);
  5812. },
  5813. set: function (value) {
  5814. this._changeFlags(BABYLON.SmartPropertyPrim.flagIsContainer, value);
  5815. },
  5816. enumerable: true,
  5817. configurable: true
  5818. });
  5819. Object.defineProperty(Prim2DBase.prototype, "hierarchyDepth", {
  5820. /**
  5821. * Return the depth level of the Primitive into the Canvas' Graph. A Canvas will be 0, its direct children 1, and so on.
  5822. */
  5823. get: function () {
  5824. return this._hierarchyDepth;
  5825. },
  5826. enumerable: true,
  5827. configurable: true
  5828. });
  5829. Object.defineProperty(Prim2DBase.prototype, "renderGroup", {
  5830. /**
  5831. * Retrieve the Group that is responsible to render this primitive
  5832. */
  5833. get: function () {
  5834. return this._renderGroup;
  5835. },
  5836. enumerable: true,
  5837. configurable: true
  5838. });
  5839. Object.defineProperty(Prim2DBase.prototype, "globalTransform", {
  5840. /**
  5841. * Get the global transformation matrix of the primitive
  5842. */
  5843. get: function () {
  5844. this._updateLocalTransform();
  5845. return this._globalTransform;
  5846. },
  5847. enumerable: true,
  5848. configurable: true
  5849. });
  5850. /**
  5851. * return the global position of the primitive, relative to its canvas
  5852. */
  5853. Prim2DBase.prototype.getGlobalPosition = function () {
  5854. var v = new BABYLON.Vector2(0, 0);
  5855. this.getGlobalPositionByRef(v);
  5856. return v;
  5857. };
  5858. /**
  5859. * return the global position of the primitive, relative to its canvas
  5860. * @param v the valid Vector2 object where the global position will be stored
  5861. */
  5862. Prim2DBase.prototype.getGlobalPositionByRef = function (v) {
  5863. v.x = this.globalTransform.m[12];
  5864. v.y = this.globalTransform.m[13];
  5865. };
  5866. Object.defineProperty(Prim2DBase.prototype, "invGlobalTransform", {
  5867. /**
  5868. * Get invert of the global transformation matrix of the primitive
  5869. */
  5870. get: function () {
  5871. this._updateLocalTransform();
  5872. return this._invGlobalTransform;
  5873. },
  5874. enumerable: true,
  5875. configurable: true
  5876. });
  5877. Object.defineProperty(Prim2DBase.prototype, "localTransform", {
  5878. /**
  5879. * Get the local transformation of the primitive
  5880. */
  5881. get: function () {
  5882. this._updateLocalTransform();
  5883. return this._localTransform;
  5884. },
  5885. enumerable: true,
  5886. configurable: true
  5887. });
  5888. Object.defineProperty(Prim2DBase.prototype, "boundingInfo", {
  5889. /**
  5890. * Get the boundingInfo associated to the primitive and its children.
  5891. * The value is supposed to be always up to date
  5892. */
  5893. get: function () {
  5894. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagBoundingInfoDirty)) {
  5895. if (this.owner) {
  5896. this.owner.boundingInfoRecomputeCounter.addCount(1, false);
  5897. }
  5898. var sizedByContent = this.isSizedByContent;
  5899. if (sizedByContent) {
  5900. this._boundingInfo.clear();
  5901. }
  5902. else {
  5903. this._boundingInfo.copyFrom(this.levelBoundingInfo);
  5904. }
  5905. var bi = this._boundingInfo;
  5906. var tps = new BABYLON.BoundingInfo2D();
  5907. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5908. var curChild = _a[_i];
  5909. var bb = curChild.boundingInfo;
  5910. bb.transformToRef(curChild.localTransform, tps);
  5911. bi.unionToRef(tps, bi);
  5912. }
  5913. // If the size is determined by the content we have to update the contentArea
  5914. // and compute the size considering the padding (if any)
  5915. if (sizedByContent) {
  5916. bi.maxToRef(Prim2DBase_1._bMax);
  5917. this._contentArea.width = Prim2DBase_1._bMax.x;
  5918. this._contentArea.height = Prim2DBase_1._bMax.y;
  5919. if (this._hasPadding) {
  5920. var padding = this.padding;
  5921. var mm = Prim2DBase_1._bMinMax;
  5922. bi.minMaxToRef(mm);
  5923. mm.z += padding.leftPixels + padding.rightPixels;
  5924. mm.w += padding.bottomPixels + padding.topPixels;
  5925. this._paddingOffset.copyFromFloats(padding.leftPixels, padding.bottomPixels, padding.rightPixels, padding.topPixels);
  5926. BABYLON.BoundingInfo2D.CreateFromMinMaxToRef(mm.x, mm.z, mm.y, mm.w, bi);
  5927. }
  5928. }
  5929. this._boundingInfo.sizeToRef(Prim2DBase_1._bSize);
  5930. this._boundingSize.copyFromFloats((!this._size || this._size.width == null) ? Math.ceil(Prim2DBase_1._bSize.width) : this._size.width, (!this._size || this._size.height == null) ? Math.ceil(Prim2DBase_1._bSize.height) : this._size.height);
  5931. this._clearFlags(BABYLON.SmartPropertyPrim.flagBoundingInfoDirty);
  5932. }
  5933. return this._boundingInfo;
  5934. },
  5935. enumerable: true,
  5936. configurable: true
  5937. });
  5938. Object.defineProperty(Prim2DBase.prototype, "layoutBoundingInfo", {
  5939. /**
  5940. * Get the boundingInfo of the primitive's content arranged by a layout Engine
  5941. * If a particular child is not arranged by layout, it's boundingInfo is used instead to produce something as accurate as possible
  5942. */
  5943. get: function () {
  5944. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty)) {
  5945. if (!this._layoutBoundingInfo) {
  5946. this._layoutBoundingInfo = new BABYLON.BoundingInfo2D();
  5947. }
  5948. if (this.isSizedByContent) {
  5949. this._layoutBoundingInfo.clear();
  5950. }
  5951. else {
  5952. this._layoutBoundingInfo.copyFrom(this.levelBoundingInfo);
  5953. }
  5954. var bi = this._layoutBoundingInfo;
  5955. var tps = new BABYLON.BoundingInfo2D();
  5956. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5957. var curChild = _a[_i];
  5958. var bb = void 0;
  5959. if (curChild._layoutAreaPos) {
  5960. var s = curChild._layoutArea;
  5961. BABYLON.BoundingInfo2D.CreateFromMinMaxToRef(0, s.width, 0, s.height, Prim2DBase_1._tpsBB);
  5962. bb = Prim2DBase_1._tpsBB;
  5963. }
  5964. else {
  5965. bb = curChild.boundingInfo;
  5966. }
  5967. bb.transformToRef(curChild.localTransform, tps);
  5968. bi.unionToRef(tps, bi);
  5969. }
  5970. this._clearFlags(BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty);
  5971. }
  5972. return this._layoutBoundingInfo;
  5973. },
  5974. enumerable: true,
  5975. configurable: true
  5976. });
  5977. Object.defineProperty(Prim2DBase.prototype, "isSizeAuto", {
  5978. /**
  5979. * Determine if the size is automatically computed or fixed because manually specified.
  5980. * Use the actualSize property to get the final/real size of the primitive
  5981. * @returns true if the size is automatically computed, false if it were manually specified.
  5982. */
  5983. get: function () {
  5984. return this._size == null;
  5985. },
  5986. enumerable: true,
  5987. configurable: true
  5988. });
  5989. Object.defineProperty(Prim2DBase.prototype, "isSizedByContent", {
  5990. /**
  5991. * Return true if this prim has an auto size which is set by the children's global bounding box
  5992. */
  5993. get: function () {
  5994. return (this._size == null) && (this._children.length > 0);
  5995. },
  5996. enumerable: true,
  5997. configurable: true
  5998. });
  5999. Object.defineProperty(Prim2DBase.prototype, "isPositionAuto", {
  6000. /**
  6001. * Determine if the position is automatically computed or fixed because manually specified.
  6002. * Use the actualPosition property to get the final/real position of the primitive
  6003. * @returns true if the position is automatically computed, false if it were manually specified.
  6004. */
  6005. get: function () {
  6006. return this._position == null;
  6007. },
  6008. enumerable: true,
  6009. configurable: true
  6010. });
  6011. Object.defineProperty(Prim2DBase.prototype, "pointerEventObservable", {
  6012. /**
  6013. * Interaction with the primitive can be create using this Observable. See the PrimitivePointerInfo class for more information
  6014. */
  6015. get: function () {
  6016. return this._pointerEventObservable;
  6017. },
  6018. enumerable: true,
  6019. configurable: true
  6020. });
  6021. Object.defineProperty(Prim2DBase.prototype, "zActualOrderChangedObservable", {
  6022. get: function () {
  6023. if (!this._actualZOrderChangedObservable) {
  6024. this._actualZOrderChangedObservable = new BABYLON.Observable();
  6025. }
  6026. return this._actualZOrderChangedObservable;
  6027. },
  6028. enumerable: true,
  6029. configurable: true
  6030. });
  6031. Object.defineProperty(Prim2DBase.prototype, "displayDebugAreas", {
  6032. get: function () {
  6033. return this._displayDebugAreas;
  6034. },
  6035. set: function (value) {
  6036. if (this._displayDebugAreas === value) {
  6037. return;
  6038. }
  6039. if (value === false) {
  6040. this._debugAreaGroup.dispose();
  6041. this._debugAreaGroup = null;
  6042. }
  6043. else {
  6044. var layoutFill = "#F0808040"; // Red - Layout area
  6045. var layoutBorder = "#F08080FF";
  6046. var marginFill = "#F0F04040"; // Yellow - Margin area
  6047. var marginBorder = "#F0F040FF";
  6048. var paddingFill = "#F040F040"; // Magenta - Padding Area
  6049. var paddingBorder = "#F040F0FF";
  6050. var contentFill = "#40F0F040"; // Cyan - Content area
  6051. var contentBorder = "#40F0F0FF";
  6052. var s = new BABYLON.Size(10, 10);
  6053. var p = BABYLON.Vector2.Zero();
  6054. this._debugAreaGroup = new BABYLON.Group2D({ dontInheritParentScale: true,
  6055. parent: (this.parent != null) ? this.parent : this, id: "###DEBUG AREA GROUP###", children: [
  6056. new BABYLON.Group2D({
  6057. id: "###Layout Area###", position: p, size: s, children: [
  6058. new BABYLON.Rectangle2D({ id: "###Layout Frame###", position: BABYLON.Vector2.Zero(), size: s, fill: null, border: layoutBorder }),
  6059. new BABYLON.Rectangle2D({ id: "###Layout Top###", position: BABYLON.Vector2.Zero(), size: s, fill: layoutFill }),
  6060. new BABYLON.Rectangle2D({ id: "###Layout Left###", position: BABYLON.Vector2.Zero(), size: s, fill: layoutFill }),
  6061. new BABYLON.Rectangle2D({ id: "###Layout Right###", position: BABYLON.Vector2.Zero(), size: s, fill: layoutFill }),
  6062. new BABYLON.Rectangle2D({ id: "###Layout Bottom###", position: BABYLON.Vector2.Zero(), size: s, fill: layoutFill })
  6063. ]
  6064. }),
  6065. new BABYLON.Group2D({
  6066. id: "###Margin Area###", position: p, size: s, children: [
  6067. new BABYLON.Rectangle2D({ id: "###Margin Frame###", position: BABYLON.Vector2.Zero(), size: s, fill: null, border: marginBorder }),
  6068. new BABYLON.Rectangle2D({ id: "###Margin Top###", position: BABYLON.Vector2.Zero(), size: s, fill: marginFill }),
  6069. new BABYLON.Rectangle2D({ id: "###Margin Left###", position: BABYLON.Vector2.Zero(), size: s, fill: marginFill }),
  6070. new BABYLON.Rectangle2D({ id: "###Margin Right###", position: BABYLON.Vector2.Zero(), size: s, fill: marginFill }),
  6071. new BABYLON.Rectangle2D({ id: "###Margin Bottom###", position: BABYLON.Vector2.Zero(), size: s, fill: marginFill })
  6072. ]
  6073. }),
  6074. new BABYLON.Group2D({
  6075. id: "###Padding Area###", position: p, size: s, children: [
  6076. new BABYLON.Rectangle2D({ id: "###Padding Frame###", position: BABYLON.Vector2.Zero(), size: s, fill: null, border: paddingBorder }),
  6077. new BABYLON.Rectangle2D({ id: "###Padding Top###", position: BABYLON.Vector2.Zero(), size: s, fill: paddingFill }),
  6078. new BABYLON.Rectangle2D({ id: "###Padding Left###", position: BABYLON.Vector2.Zero(), size: s, fill: paddingFill }),
  6079. new BABYLON.Rectangle2D({ id: "###Padding Right###", position: BABYLON.Vector2.Zero(), size: s, fill: paddingFill }),
  6080. new BABYLON.Rectangle2D({ id: "###Padding Bottom###", position: BABYLON.Vector2.Zero(), size: s, fill: paddingFill })
  6081. ]
  6082. }),
  6083. new BABYLON.Group2D({
  6084. id: "###Content Area###", position: p, size: s, children: [
  6085. new BABYLON.Rectangle2D({ id: "###Content Frame###", position: BABYLON.Vector2.Zero(), size: s, fill: null, border: contentBorder }),
  6086. new BABYLON.Rectangle2D({ id: "###Content Top###", position: BABYLON.Vector2.Zero(), size: s, fill: contentFill }),
  6087. new BABYLON.Rectangle2D({ id: "###Content Left###", position: BABYLON.Vector2.Zero(), size: s, fill: contentFill }),
  6088. new BABYLON.Rectangle2D({ id: "###Content Right###", position: BABYLON.Vector2.Zero(), size: s, fill: contentFill }),
  6089. new BABYLON.Rectangle2D({ id: "###Content Bottom###", position: BABYLON.Vector2.Zero(), size: s, fill: contentFill })
  6090. ]
  6091. })
  6092. ]
  6093. });
  6094. this._debugAreaGroup._setFlags(BABYLON.SmartPropertyPrim.flagNoPartOfLayout);
  6095. this._updateDebugArea();
  6096. }
  6097. this._displayDebugAreas = value;
  6098. },
  6099. enumerable: true,
  6100. configurable: true
  6101. });
  6102. Prim2DBase.prototype._updateDebugArea = function () {
  6103. var areaNames = ["Layout", "Margin", "Padding", "Content"];
  6104. var areaZones = ["Area", "Frame", "Top", "Left", "Right", "Bottom"];
  6105. var prims = new Array(4);
  6106. // Get all the primitives used to display the areas
  6107. for (var i = 0; i < 4; i++) {
  6108. prims[i] = new Array(6);
  6109. for (var j = 0; j < 6; j++) {
  6110. prims[i][j] = this._debugAreaGroup.findById("###" + areaNames[i] + " " + areaZones[j] + "###");
  6111. if (j > 1) {
  6112. prims[i][j].levelVisible = false;
  6113. }
  6114. }
  6115. }
  6116. // Update the visibility status of layout/margin/padding
  6117. var hasLayout = this._layoutAreaPos != null;
  6118. var hasPos = (this.actualPosition.x !== 0) || (this.actualPosition.y !== 0);
  6119. var hasMargin = this._hasMargin;
  6120. var hasPadding = this._hasPadding;
  6121. prims[0][0].levelVisible = hasLayout;
  6122. prims[1][0].levelVisible = hasMargin;
  6123. prims[2][0].levelVisible = hasPadding;
  6124. prims[3][0].levelVisible = true;
  6125. // Current offset
  6126. var curOffset = BABYLON.Vector2.Zero();
  6127. // Store the area info of the layout area
  6128. var curAreaIndex = 0;
  6129. // Store data about each area
  6130. var areaInfo = new Array(4);
  6131. var storeAreaInfo = function (pos, size) {
  6132. var min = pos.clone();
  6133. var max = pos.clone();
  6134. if (size.width > 0) {
  6135. max.x += size.width;
  6136. }
  6137. if (size.height > 0) {
  6138. max.y += size.height;
  6139. }
  6140. areaInfo[curAreaIndex++] = { off: pos, size: size, min: min, max: max };
  6141. };
  6142. var isCanvas = this instanceof BABYLON.Canvas2D;
  6143. var marginH = this._marginOffset.x + this._marginOffset.z;
  6144. var marginV = this._marginOffset.y + this._marginOffset.w;
  6145. var actualSize = this.actualSize.multiplyByFloats(isCanvas ? 1 : this.scaleX, isCanvas ? 1 : this.scaleY);
  6146. var w = hasLayout ? (this.layoutAreaPos.x + this.layoutArea.width) : (marginH + actualSize.width);
  6147. var h = hasLayout ? (this.layoutAreaPos.y + this.layoutArea.height) : (marginV + actualSize.height);
  6148. var pos = (!hasLayout && !hasMargin && !hasPadding && hasPos) ? this.actualPosition : BABYLON.Vector2.Zero();
  6149. storeAreaInfo(pos, new BABYLON.Size(w, h));
  6150. // Compute the layout related data
  6151. if (hasLayout) {
  6152. var layoutOffset = this.layoutAreaPos.clone();
  6153. storeAreaInfo(layoutOffset, (hasMargin || hasPadding) ? this.layoutArea.clone() : actualSize.clone());
  6154. curOffset = layoutOffset.clone();
  6155. }
  6156. // Compute margin data
  6157. if (hasMargin) {
  6158. var marginOffset = curOffset.clone();
  6159. marginOffset.x += this._marginOffset.x;
  6160. marginOffset.y += this._marginOffset.y;
  6161. var marginArea = actualSize;
  6162. storeAreaInfo(marginOffset, marginArea);
  6163. curOffset = marginOffset.clone();
  6164. }
  6165. if (hasPadding) {
  6166. var contentOffset = curOffset.clone();
  6167. contentOffset.x += this._paddingOffset.x;
  6168. contentOffset.y += this._paddingOffset.y;
  6169. var contentArea = this.contentArea;
  6170. storeAreaInfo(contentOffset, contentArea);
  6171. curOffset = curOffset.add(contentOffset);
  6172. }
  6173. // Helper function that set the pos and size of a given prim
  6174. var setArea = function (i, j, pos, size) {
  6175. prims[i][j].position = pos;
  6176. prims[i][j].size = size;
  6177. };
  6178. var setFullRect = function (i, pos, size) {
  6179. var plist = prims[i];
  6180. plist[2].levelVisible = true;
  6181. plist[3].levelVisible = false;
  6182. plist[4].levelVisible = false;
  6183. plist[5].levelVisible = false;
  6184. setArea(i, 1, pos, size);
  6185. setArea(i, 2, pos, size);
  6186. };
  6187. var setQuadRect = function (i, areaIndex) {
  6188. var plist = prims[i];
  6189. plist[2].levelVisible = true;
  6190. plist[3].levelVisible = true;
  6191. plist[4].levelVisible = true;
  6192. plist[5].levelVisible = true;
  6193. var ca = areaInfo[areaIndex];
  6194. var na = areaInfo[areaIndex + 1];
  6195. var tp = new BABYLON.Vector2(ca.min.x, na.max.y);
  6196. var ts = new BABYLON.Size(ca.size.width, ca.max.y - tp.y);
  6197. var lp = new BABYLON.Vector2(ca.min.x, na.min.y);
  6198. var ls = new BABYLON.Size(na.min.x - ca.min.x, na.max.y - na.min.y);
  6199. var rp = new BABYLON.Vector2(na.max.x, na.min.y);
  6200. var rs = new BABYLON.Size(ca.max.x - na.max.x, na.max.y - na.min.y);
  6201. var bp = new BABYLON.Vector2(ca.min.x, ca.min.y);
  6202. var bs = new BABYLON.Size(ca.size.width, na.min.y - ca.min.y);
  6203. // Frame
  6204. plist[1].position = ca.off;
  6205. plist[1].size = ca.size;
  6206. // Top rect
  6207. plist[2].position = tp;
  6208. plist[2].size = ts;
  6209. // Left rect
  6210. plist[3].position = lp;
  6211. plist[3].size = ls;
  6212. // Right rect
  6213. plist[4].position = rp;
  6214. plist[4].size = rs;
  6215. // Bottom rect
  6216. plist[5].position = bp;
  6217. plist[5].size = bs;
  6218. };
  6219. var areaCount = curAreaIndex;
  6220. curAreaIndex = 0;
  6221. // Available zones
  6222. var availableZones = [false, hasLayout, hasMargin, hasPadding, true];
  6223. for (var k = 1; k < 5; k++) {
  6224. if (availableZones[k]) {
  6225. var ai = areaInfo[curAreaIndex];
  6226. setArea(k - 1, 0, BABYLON.Vector2.Zero(), ai.size);
  6227. // setArea(k-1, 1, Vector2.Zero(), ai.size);
  6228. if (k === 4) {
  6229. setFullRect(k - 1, ai.off, ai.size);
  6230. }
  6231. else {
  6232. setQuadRect(k - 1, curAreaIndex);
  6233. }
  6234. ++curAreaIndex;
  6235. }
  6236. }
  6237. };
  6238. Prim2DBase.prototype.findById = function (id) {
  6239. if (this._id === id) {
  6240. return this;
  6241. }
  6242. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  6243. var child = _a[_i];
  6244. var r = child.findById(id);
  6245. if (r != null) {
  6246. return r;
  6247. }
  6248. }
  6249. };
  6250. Prim2DBase.prototype.onZOrderChanged = function () {
  6251. };
  6252. Prim2DBase.prototype.levelIntersect = function (intersectInfo) {
  6253. return false;
  6254. };
  6255. /**
  6256. * Capture all the Events of the given PointerId for this primitive.
  6257. * Don't forget to call releasePointerEventsCapture when done.
  6258. * @param pointerId the Id of the pointer to capture the events from.
  6259. */
  6260. Prim2DBase.prototype.setPointerEventCapture = function (pointerId) {
  6261. return this.owner._setPointerCapture(pointerId, this);
  6262. };
  6263. /**
  6264. * Release a captured pointer made with setPointerEventCapture.
  6265. * @param pointerId the Id of the pointer to release the capture from.
  6266. */
  6267. Prim2DBase.prototype.releasePointerEventsCapture = function (pointerId) {
  6268. return this.owner._releasePointerCapture(pointerId, this);
  6269. };
  6270. Prim2DBase.prototype.intersect = function (intersectInfo) {
  6271. if (!intersectInfo) {
  6272. return false;
  6273. }
  6274. // If this is null it means this method is call for the first level, initialize stuffs
  6275. var firstLevel = !intersectInfo._globalPickPosition;
  6276. if (firstLevel) {
  6277. // Compute the pickPosition in global space and use it to find the local position for each level down, always relative from the world to get the maximum accuracy (and speed). The other way would have been to compute in local every level down relative to its parent's local, which wouldn't be as accurate (even if javascript number is 80bits accurate).
  6278. intersectInfo._globalPickPosition = BABYLON.Vector2.Zero();
  6279. BABYLON.Vector2.TransformToRef(intersectInfo.pickPosition, this.globalTransform, intersectInfo._globalPickPosition);
  6280. intersectInfo._localPickPosition = intersectInfo.pickPosition.clone();
  6281. intersectInfo.intersectedPrimitives = new Array();
  6282. intersectInfo.topMostIntersectedPrimitive = null;
  6283. }
  6284. if (!Prim2DBase_1._bypassGroup2DExclusion && this instanceof BABYLON.Group2D && this.isCachedGroup && !this.isRenderableGroup) {
  6285. // Important to call this before each return to allow a good recursion next time this intersectInfo is reused
  6286. intersectInfo._exit(firstLevel);
  6287. return false;
  6288. }
  6289. if (!intersectInfo.intersectHidden && !this.isVisible) {
  6290. // Important to call this before each return to allow a good recursion next time this intersectInfo is reused
  6291. intersectInfo._exit(firstLevel);
  6292. return false;
  6293. }
  6294. var id = this.id;
  6295. if (id != null && id.indexOf("__cachedSpriteOfGroup__") === 0) {
  6296. try {
  6297. Prim2DBase_1._bypassGroup2DExclusion = true;
  6298. var ownerGroup = this.getExternalData("__cachedGroup__");
  6299. return ownerGroup.intersect(intersectInfo);
  6300. }
  6301. finally {
  6302. Prim2DBase_1._bypassGroup2DExclusion = false;
  6303. }
  6304. }
  6305. // If we're testing a cachedGroup, we must reject pointer outside its levelBoundingInfo because children primitives could be partially clipped outside so we must not accept them as intersected when it's the case (because they're not visually visible).
  6306. var isIntersectionTest = false;
  6307. if (this instanceof BABYLON.Group2D) {
  6308. var g = this;
  6309. isIntersectionTest = g.isCachedGroup;
  6310. }
  6311. if (isIntersectionTest && !this.levelBoundingInfo.doesIntersect(intersectInfo._localPickPosition)) {
  6312. // Important to call this before each return to allow a good recursion next time this intersectInfo is reused
  6313. intersectInfo._exit(firstLevel);
  6314. return false;
  6315. }
  6316. // Fast rejection test with boundingInfo
  6317. if (this.isPickable && !this.boundingInfo.doesIntersect(intersectInfo._localPickPosition)) {
  6318. // Important to call this before each return to allow a good recursion next time this intersectInfo is reused
  6319. intersectInfo._exit(firstLevel);
  6320. return false;
  6321. }
  6322. // We hit the boundingInfo that bounds this primitive and its children, now we have to test on the primitive of this level
  6323. var levelIntersectRes = false;
  6324. if (this.isPickable) {
  6325. levelIntersectRes = this.levelIntersect(intersectInfo);
  6326. if (levelIntersectRes) {
  6327. var pii = new PrimitiveIntersectedInfo(this, intersectInfo._localPickPosition.clone());
  6328. intersectInfo.intersectedPrimitives.push(pii);
  6329. if (!intersectInfo.topMostIntersectedPrimitive || (intersectInfo.topMostIntersectedPrimitive.prim.actualZOffset > pii.prim.actualZOffset)) {
  6330. intersectInfo.topMostIntersectedPrimitive = pii;
  6331. }
  6332. // If we must stop at the first intersection, we're done, quit!
  6333. if (intersectInfo.findFirstOnly) {
  6334. intersectInfo._exit(firstLevel);
  6335. return true;
  6336. }
  6337. }
  6338. }
  6339. // Recurse to children if needed
  6340. if (!levelIntersectRes || !intersectInfo.findFirstOnly) {
  6341. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  6342. var curChild = _a[_i];
  6343. // Don't test primitive not pick able or if it's hidden and we don't test hidden ones
  6344. if ((!curChild.isPickable && curChild.isContainer) || (!intersectInfo.intersectHidden && !curChild.isVisible)) {
  6345. continue;
  6346. }
  6347. // Must compute the localPickLocation for the children level
  6348. BABYLON.Vector2.TransformToRef(intersectInfo._globalPickPosition, curChild.invGlobalTransform, intersectInfo._localPickPosition);
  6349. // If we got an intersection with the child and we only need to find the first one, quit!
  6350. if (curChild.intersect(intersectInfo) && intersectInfo.findFirstOnly) {
  6351. intersectInfo._exit(firstLevel);
  6352. return true;
  6353. }
  6354. }
  6355. }
  6356. intersectInfo._exit(firstLevel);
  6357. return intersectInfo.isIntersected;
  6358. };
  6359. /**
  6360. * Move a child object into a new position regarding its siblings to change its rendering order.
  6361. * You can also use the shortcut methods to move top/bottom: moveChildToTop, moveChildToBottom, moveToTop, moveToBottom.
  6362. * @param child the object to move
  6363. * @param previous the object which will be before "child", if child has to be the first among sibling, set "previous" to null.
  6364. */
  6365. Prim2DBase.prototype.moveChild = function (child, previous) {
  6366. if (child.parent !== this) {
  6367. return false;
  6368. }
  6369. var childIndex = this._children.indexOf(child);
  6370. var prevIndex = previous ? this._children.indexOf(previous) : -1;
  6371. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder)) {
  6372. this._setFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  6373. this._firstZDirtyIndex = Math.min(this._firstZDirtyIndex, prevIndex + 1);
  6374. }
  6375. this._children.splice(prevIndex + 1, 0, this._children.splice(childIndex, 1)[0]);
  6376. return true;
  6377. };
  6378. /**
  6379. * Move the given child so it's displayed on the top of all its siblings
  6380. * @param child the primitive to move to the top
  6381. */
  6382. Prim2DBase.prototype.moveChildToTop = function (child) {
  6383. return this.moveChild(child, this._children[this._children.length - 1]);
  6384. };
  6385. /**
  6386. * Move the given child so it's displayed on the bottom of all its siblings
  6387. * @param child the primitive to move to the top
  6388. */
  6389. Prim2DBase.prototype.moveChildToBottom = function (child) {
  6390. return this.moveChild(child, null);
  6391. };
  6392. /**
  6393. * Move this primitive to be at the top among all its sibling
  6394. */
  6395. Prim2DBase.prototype.moveToTop = function () {
  6396. if (this.parent == null) {
  6397. return false;
  6398. }
  6399. return this.parent.moveChildToTop(this);
  6400. };
  6401. /**
  6402. * Move this primitive to be at the bottom among all its sibling
  6403. */
  6404. Prim2DBase.prototype.moveToBottom = function () {
  6405. if (this.parent == null) {
  6406. return false;
  6407. }
  6408. return this.parent.moveChildToBottom(this);
  6409. };
  6410. Prim2DBase.prototype.addChild = function (child) {
  6411. child._parent = this;
  6412. this._boundingBoxDirty();
  6413. var flat = this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  6414. if (flat) {
  6415. child._setFlags(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  6416. child._setZOrder(this._zOrder, true);
  6417. child._zMax = this._zOrder;
  6418. }
  6419. else {
  6420. this._setFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  6421. }
  6422. var length = this._children.push(child);
  6423. this._firstZDirtyIndex = Math.min(this._firstZDirtyIndex, length - 1);
  6424. };
  6425. /**
  6426. * Dispose the primitive, remove it from its parent.
  6427. */
  6428. Prim2DBase.prototype.dispose = function () {
  6429. if (!_super.prototype.dispose.call(this)) {
  6430. return false;
  6431. }
  6432. if (this._pointerEventObservable) {
  6433. this._pointerEventObservable.clear();
  6434. this._pointerEventObservable = null;
  6435. }
  6436. if (this._actionManager) {
  6437. this._actionManager.dispose();
  6438. this._actionManager = null;
  6439. }
  6440. this.owner.scene.stopAnimation(this);
  6441. // If there's a parent, remove this object from its parent list
  6442. if (this._parent) {
  6443. if (this instanceof BABYLON.Group2D) {
  6444. var g = this;
  6445. if (g.isRenderableGroup) {
  6446. var parentRenderable = this.parent.traverseUp(function (p) { return (p instanceof BABYLON.Group2D && p.isRenderableGroup); });
  6447. if (parentRenderable != null) {
  6448. var l = parentRenderable._renderableData._childrenRenderableGroups;
  6449. var i_1 = l.indexOf(g);
  6450. if (i_1 !== -1) {
  6451. l.splice(i_1, 1);
  6452. }
  6453. }
  6454. }
  6455. }
  6456. var i = this._parent._children.indexOf(this);
  6457. if (i !== undefined) {
  6458. this._parent._children.splice(i, 1);
  6459. }
  6460. this._parent = null;
  6461. }
  6462. // Recurse dispose to children
  6463. if (this._children) {
  6464. while (this._children.length > 0) {
  6465. this._children[this._children.length - 1].dispose();
  6466. }
  6467. }
  6468. return true;
  6469. };
  6470. Prim2DBase.prototype.onPrimBecomesDirty = function () {
  6471. if (this._renderGroup && !this._isFlagSet(BABYLON.SmartPropertyPrim.flagPrimInDirtyList)) {
  6472. this._renderGroup._addPrimToDirtyList(this);
  6473. this._setFlags(BABYLON.SmartPropertyPrim.flagPrimInDirtyList);
  6474. }
  6475. };
  6476. Prim2DBase.prototype._needPrepare = function () {
  6477. return this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagVisibilityChanged | BABYLON.SmartPropertyPrim.flagModelDirty | BABYLON.SmartPropertyPrim.flagNeedRefresh) || (this._instanceDirtyFlags !== 0) || (this._globalTransformProcessStep !== this._globalTransformStep);
  6478. };
  6479. Prim2DBase.prototype._prepareRender = function (context) {
  6480. this._prepareRenderPre(context);
  6481. this._prepareRenderPost(context);
  6482. };
  6483. Prim2DBase.prototype._prepareRenderPre = function (context) {
  6484. };
  6485. Prim2DBase.prototype._prepareRenderPost = function (context) {
  6486. // Don't recurse if it's a renderable group, the content will be processed by the group itself
  6487. if (this instanceof BABYLON.Group2D) {
  6488. var self = this;
  6489. if (self.isRenderableGroup) {
  6490. return;
  6491. }
  6492. }
  6493. // Check if we need to recurse the prepare to children primitives
  6494. // - must have children
  6495. // - the global transform of this level have changed, or
  6496. // - the visible state of primitive has changed
  6497. if (this._children.length > 0 && ((this._globalTransformProcessStep !== this._globalTransformStep) ||
  6498. this.checkPropertiesDirty(Prim2DBase_1.isVisibleProperty.flagId))) {
  6499. this._children.forEach(function (c) {
  6500. // As usual stop the recursion if we meet a renderable group
  6501. if (!(c instanceof BABYLON.Group2D && c.isRenderableGroup)) {
  6502. c._prepareRender(context);
  6503. }
  6504. });
  6505. }
  6506. // Finally reset the dirty flags as we've processed everything
  6507. this._clearFlags(BABYLON.SmartPropertyPrim.flagModelDirty);
  6508. this._instanceDirtyFlags = 0;
  6509. };
  6510. Prim2DBase.prototype._canvasPreInit = function (settings) {
  6511. };
  6512. Prim2DBase.CheckParent = function (parent) {
  6513. //if (!Prim2DBase._isCanvasInit && !parent) {
  6514. // throw new Error("A Primitive needs a valid Parent, it can be any kind of Primitives based types, even the Canvas (with the exception that only Group2D can be direct child of a Canvas if the cache strategy used is TOPLEVELGROUPS)");
  6515. //}
  6516. };
  6517. Prim2DBase.prototype.updateCachedStatesOf = function (list, recurse) {
  6518. for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
  6519. var cur = list_1[_i];
  6520. cur.updateCachedStates(recurse);
  6521. }
  6522. };
  6523. Prim2DBase.prototype._parentLayoutDirty = function () {
  6524. if (!this._parent || this._parent.isDisposed) {
  6525. return;
  6526. }
  6527. this._parent._setLayoutDirty();
  6528. };
  6529. Prim2DBase.prototype._setLayoutDirty = function () {
  6530. this.onPrimBecomesDirty();
  6531. this._setFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  6532. };
  6533. Prim2DBase.prototype._checkPositionChange = function () {
  6534. if (this.parent && this.parent.layoutEngine.isChildPositionAllowed === false) {
  6535. console.log("Can't manually set the position of " + this.id + ", the Layout Engine of its parent doesn't allow it");
  6536. return false;
  6537. }
  6538. return true;
  6539. };
  6540. Prim2DBase.prototype._positioningDirty = function () {
  6541. this.onPrimBecomesDirty();
  6542. this._setFlags(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  6543. };
  6544. Prim2DBase.prototype._spreadActualOpacityChanged = function () {
  6545. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  6546. var child = _a[_i];
  6547. child._setFlags(BABYLON.SmartPropertyPrim.flagActualOpacityDirty);
  6548. child._updateRenderMode();
  6549. child.onPrimBecomesDirty();
  6550. child._spreadActualOpacityChanged();
  6551. }
  6552. };
  6553. Prim2DBase.prototype._changeLayoutEngine = function (engine) {
  6554. this._layoutEngine = engine;
  6555. };
  6556. Prim2DBase.prototype._updateLocalTransform = function () {
  6557. var tflags = Prim2DBase_1.actualPositionProperty.flagId | Prim2DBase_1.rotationProperty.flagId | Prim2DBase_1.scaleProperty.flagId | Prim2DBase_1.scaleXProperty.flagId | Prim2DBase_1.scaleYProperty.flagId | Prim2DBase_1.originProperty.flagId;
  6558. if (this.checkPropertiesDirty(tflags)) {
  6559. if (this.owner) {
  6560. this.owner.addupdateLocalTransformCounter(1);
  6561. }
  6562. var rot = BABYLON.Quaternion.RotationAxis(new BABYLON.Vector3(0, 0, 1), this._rotation);
  6563. var local;
  6564. var pos = this._position ? this.position : this.layoutAreaPos;
  6565. if (this._origin.x === 0 && this._origin.y === 0) {
  6566. local = BABYLON.Matrix.Compose(new BABYLON.Vector3(this._scale.x, this._scale.y, 1), rot, new BABYLON.Vector3(pos.x + this._marginOffset.x, pos.y + this._marginOffset.y, 0));
  6567. this._localTransform = local;
  6568. }
  6569. else {
  6570. // -Origin offset
  6571. var as = this.actualSize;
  6572. BABYLON.Matrix.TranslationToRef((-as.width * this._origin.x), (-as.height * this._origin.y), 0, Prim2DBase_1._t0);
  6573. // -Origin * rotation
  6574. rot.toRotationMatrix(Prim2DBase_1._t1);
  6575. Prim2DBase_1._t0.multiplyToRef(Prim2DBase_1._t1, Prim2DBase_1._t2);
  6576. // -Origin * rotation * scale
  6577. BABYLON.Matrix.ScalingToRef(this._scale.x, this._scale.y, 1, Prim2DBase_1._t0);
  6578. Prim2DBase_1._t2.multiplyToRef(Prim2DBase_1._t0, Prim2DBase_1._t1);
  6579. // -Origin * rotation * scale * (Origin + Position)
  6580. BABYLON.Matrix.TranslationToRef((as.width * this._origin.x) + pos.x + this._marginOffset.x, (as.height * this._origin.y) + pos.y + this._marginOffset.y, 0, Prim2DBase_1._t2);
  6581. Prim2DBase_1._t1.multiplyToRef(Prim2DBase_1._t2, this._localTransform);
  6582. }
  6583. this.clearPropertiesDirty(tflags);
  6584. this._setFlags(BABYLON.SmartPropertyPrim.flagGlobalTransformDirty);
  6585. return true;
  6586. }
  6587. return false;
  6588. };
  6589. Prim2DBase.prototype.updateCachedStates = function (recurse) {
  6590. if (this.isDisposed) {
  6591. return;
  6592. }
  6593. this.owner.addCachedGroupRenderCounter(1);
  6594. // Check if the parent is synced
  6595. if (this._parent && ((this._parent._globalTransformProcessStep !== this.owner._globalTransformProcessStep) || this._parent._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagLayoutDirty | BABYLON.SmartPropertyPrim.flagPositioningDirty | BABYLON.SmartPropertyPrim.flagZOrderDirty))) {
  6596. this._parent.updateCachedStates(false);
  6597. }
  6598. // Update Z-Order if needed
  6599. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  6600. this._updateZOrder();
  6601. }
  6602. // Update actualSize only if there' not positioning to recompute and the size changed
  6603. // Otherwise positioning will take care of it.
  6604. var sizeDirty = this.checkPropertiesDirty(Prim2DBase_1.sizeProperty.flagId);
  6605. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty) && !this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty) && sizeDirty) {
  6606. var size = this.size;
  6607. if (size) {
  6608. if (this.size.width != null) {
  6609. this.actualSize.width = this.size.width;
  6610. }
  6611. if (this.size.height != null) {
  6612. this.actualSize.height = this.size.height;
  6613. }
  6614. this.clearPropertiesDirty(Prim2DBase_1.sizeProperty.flagId);
  6615. }
  6616. }
  6617. var positioningDirty = this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  6618. var positioningComputed = positioningDirty && !this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  6619. // Check for layout update
  6620. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty)) {
  6621. this.owner.addUpdateLayoutCounter(1);
  6622. this._layoutEngine.updateLayout(this);
  6623. this._clearFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  6624. }
  6625. var autoContentChanged = false;
  6626. if (this.isSizeAuto) {
  6627. if (!this._lastAutoSizeArea) {
  6628. autoContentChanged = this.actualSize !== null;
  6629. }
  6630. else {
  6631. autoContentChanged = (!this._lastAutoSizeArea.equals(this.actualSize));
  6632. }
  6633. }
  6634. // Check for positioning update
  6635. if (!positioningComputed && (autoContentChanged || sizeDirty || this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty) || (this._parent && !this._parent.contentArea.equals(this._parentContentArea)))) {
  6636. this._updatePositioning();
  6637. this._clearFlags(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  6638. if (sizeDirty) {
  6639. this.clearPropertiesDirty(Prim2DBase_1.sizeProperty.flagId);
  6640. }
  6641. positioningComputed = true;
  6642. }
  6643. if (positioningComputed && this._parent) {
  6644. this._parentContentArea.copyFrom(this._parent.contentArea);
  6645. }
  6646. // Check if we must update this prim
  6647. if (this === this.owner || this._globalTransformProcessStep !== this.owner._globalTransformProcessStep) {
  6648. this.owner.addUpdateGlobalTransformCounter(1);
  6649. var curVisibleState = this.isVisible;
  6650. this.isVisible = (!this._parent || this._parent.isVisible) && this.levelVisible;
  6651. // Detect a change of visibility
  6652. this._changeFlags(BABYLON.SmartPropertyPrim.flagVisibilityChanged, curVisibleState !== this.isVisible);
  6653. // Get/compute the localTransform
  6654. var localDirty = this._updateLocalTransform();
  6655. var parentPaddingChanged = false;
  6656. var parentPaddingOffset = Prim2DBase_1._v0;
  6657. if (this._parent) {
  6658. parentPaddingOffset = new BABYLON.Vector2(this._parent._paddingOffset.x, this._parent._paddingOffset.y);
  6659. parentPaddingChanged = !parentPaddingOffset.equals(this._parentPaddingOffset);
  6660. }
  6661. // Check if there are changes in the parent that will force us to update the global matrix
  6662. var parentDirty = (this._parent != null) ? (this._parent._globalTransformStep !== this._parentTransformStep) : false;
  6663. // Check if we have to update the globalTransform
  6664. if (!this._globalTransform || localDirty || parentDirty || parentPaddingChanged || this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagGlobalTransformDirty)) {
  6665. var globalTransform = this._parent ? this._parent._globalTransform : null;
  6666. var localTransform = void 0;
  6667. Prim2DBase_1._transMtx.copyFrom(this._localTransform);
  6668. Prim2DBase_1._transMtx.m[12] += parentPaddingOffset.x;
  6669. Prim2DBase_1._transMtx.m[13] += parentPaddingOffset.y;
  6670. localTransform = Prim2DBase_1._transMtx;
  6671. this._globalTransform = this._parent ? localTransform.multiply(globalTransform) : localTransform.clone();
  6672. this._invGlobalTransform = BABYLON.Matrix.Invert(this._globalTransform);
  6673. this._globalTransformStep = this.owner._globalTransformProcessStep + 1;
  6674. this._parentTransformStep = this._parent ? this._parent._globalTransformStep : 0;
  6675. this._clearFlags(BABYLON.SmartPropertyPrim.flagGlobalTransformDirty);
  6676. }
  6677. this._globalTransformProcessStep = this.owner._globalTransformProcessStep;
  6678. }
  6679. if (recurse) {
  6680. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  6681. var child = _a[_i];
  6682. // Stop the recursion if we meet a renderable group
  6683. child.updateCachedStates(!(child instanceof BABYLON.Group2D && child.isRenderableGroup));
  6684. }
  6685. }
  6686. };
  6687. Prim2DBase.prototype._updatePositioning = function () {
  6688. if (this.owner) {
  6689. this.owner.addUpdatePositioningCounter(1);
  6690. }
  6691. // From this point we assume that the primitive layoutArea is computed and up to date.
  6692. // We know have to :
  6693. // 1. Determine the PaddingArea and the ActualPosition based on the margin/marginAlignment properties, which will also set the size property of the primitive
  6694. // 2. Determine the contentArea based on the padding property.
  6695. var isSizeAuto = this.isSizeAuto;
  6696. // Auto Create PaddingArea if there's no actualSize on width&|height to allocate the whole content available to the paddingArea where the actualSize is null
  6697. if (!this._hasMarginAlignment && (isSizeAuto || (this.actualSize.width == null || this.actualSize.height == null))) {
  6698. if (isSizeAuto || this.actualSize.width == null) {
  6699. this.marginAlignment.horizontal = PrimitiveAlignment.AlignStretch;
  6700. }
  6701. if (isSizeAuto || this.actualSize.height == null) {
  6702. this.marginAlignment.vertical = PrimitiveAlignment.AlignStretch;
  6703. }
  6704. }
  6705. // Apply margin
  6706. if (this._hasMargin) {
  6707. this.margin.computeWithAlignment(this.layoutArea, this.size || this.actualSize, this.marginAlignment, this._marginOffset, Prim2DBase_1._size);
  6708. this.actualSize = Prim2DBase_1._size.clone();
  6709. }
  6710. if (this._hasPadding) {
  6711. // Two cases from here: the size of the Primitive is Auto, its content can't be shrink, so we resize the primitive itself
  6712. if (isSizeAuto) {
  6713. // Changing the padding has resize the prim, which forces us to recompute margin again
  6714. if (this._hasMargin) {
  6715. this.margin.computeWithAlignment(this.layoutArea, Prim2DBase_1._size, this.marginAlignment, this._marginOffset, Prim2DBase_1._size);
  6716. }
  6717. }
  6718. else {
  6719. this._getInitialContentAreaToRef(this.actualSize, Prim2DBase_1._icZone, Prim2DBase_1._icArea);
  6720. Prim2DBase_1._icArea.width = Math.max(0, Prim2DBase_1._icArea.width);
  6721. Prim2DBase_1._icArea.height = Math.max(0, Prim2DBase_1._icArea.height);
  6722. this.padding.compute(Prim2DBase_1._icArea, this._paddingOffset, Prim2DBase_1._size);
  6723. this._paddingOffset.x += Prim2DBase_1._icZone.x;
  6724. this._paddingOffset.y += Prim2DBase_1._icZone.y;
  6725. this._paddingOffset.z -= Prim2DBase_1._icZone.z;
  6726. this._paddingOffset.w -= Prim2DBase_1._icZone.w;
  6727. this._contentArea.copyFrom(Prim2DBase_1._size);
  6728. }
  6729. }
  6730. else {
  6731. this._getInitialContentAreaToRef(this.actualSize, Prim2DBase_1._icZone, Prim2DBase_1._icArea);
  6732. Prim2DBase_1._icArea.width = Math.max(0, Prim2DBase_1._icArea.width);
  6733. Prim2DBase_1._icArea.height = Math.max(0, Prim2DBase_1._icArea.height);
  6734. this._paddingOffset.x = Prim2DBase_1._icZone.x;
  6735. this._paddingOffset.y = Prim2DBase_1._icZone.y;
  6736. this._paddingOffset.z = Prim2DBase_1._icZone.z;
  6737. this._paddingOffset.w = Prim2DBase_1._icZone.w;
  6738. this._contentArea.copyFrom(Prim2DBase_1._icArea);
  6739. }
  6740. if (!this._position) {
  6741. var aPos = new BABYLON.Vector2(this.layoutAreaPos.x + this._marginOffset.x, this.layoutAreaPos.y + this._marginOffset.y);
  6742. this.actualPosition = aPos;
  6743. }
  6744. if (isSizeAuto) {
  6745. this._lastAutoSizeArea = this.actualSize;
  6746. }
  6747. if (this.displayDebugAreas) {
  6748. this._updateDebugArea();
  6749. }
  6750. };
  6751. Object.defineProperty(Prim2DBase.prototype, "contentArea", {
  6752. /**
  6753. * Get the content are of this primitive, this area is computed using the padding property and also possibly the primitive type itself.
  6754. * Children of this primitive will be positioned relative to the bottom/left corner of this area.
  6755. */
  6756. get: function () {
  6757. if (!this._size || this._size.width == null || this._size.height == null) {
  6758. if (Prim2DBase_1.boundinbBoxReentrency) {
  6759. return Prim2DBase_1.nullSize;
  6760. }
  6761. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagBoundingInfoDirty)) {
  6762. return this._boundingSize;
  6763. }
  6764. Prim2DBase_1.boundinbBoxReentrency = true;
  6765. var b = this.boundingInfo;
  6766. Prim2DBase_1.boundinbBoxReentrency = false;
  6767. return this._contentArea;
  6768. }
  6769. else
  6770. // Check for positioning update
  6771. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty)) {
  6772. this._updatePositioning();
  6773. this._clearFlags(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  6774. }
  6775. return this._contentArea;
  6776. },
  6777. enumerable: true,
  6778. configurable: true
  6779. });
  6780. Prim2DBase.prototype._patchHierarchy = function (owner) {
  6781. this._owner = owner;
  6782. // The only place we initialize the _renderGroup is this method, if it's set, we already been there, no need to execute more
  6783. if (this._renderGroup != null) {
  6784. return;
  6785. }
  6786. if (this instanceof BABYLON.Group2D) {
  6787. var group = this;
  6788. group.detectGroupStates();
  6789. if (group._trackedNode && !group._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  6790. group.owner._registerTrackedNode(this);
  6791. }
  6792. }
  6793. this._renderGroup = this.traverseUp(function (p) { return p instanceof BABYLON.Group2D && p.isRenderableGroup; });
  6794. if (this._parent) {
  6795. this._parentLayoutDirty();
  6796. }
  6797. // Make sure the prim is in the dirtyList if it should be
  6798. if (this._renderGroup && this.isDirty) {
  6799. var list = this._renderGroup._renderableData._primDirtyList;
  6800. var i = list.indexOf(this);
  6801. if (i === -1) {
  6802. list.push(this);
  6803. }
  6804. }
  6805. // Recurse
  6806. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  6807. var child = _a[_i];
  6808. child._hierarchyDepth = this._hierarchyDepth + 1;
  6809. child._patchHierarchy(owner);
  6810. }
  6811. };
  6812. Prim2DBase.prototype._updateZOrder = function () {
  6813. var prevLinPos = this._primLinearPosition;
  6814. var startI = 0;
  6815. var startZ = this._zOrder;
  6816. // We must start rebuilding Z-Order from the Prim before the first one that changed, because we know its Z-Order is correct, so are its children, but it's better to recompute everything from this point instead of finding the last valid children
  6817. var childrenCount = this._children.length;
  6818. if (this._firstZDirtyIndex > 0) {
  6819. if ((this._firstZDirtyIndex - 1) < childrenCount) {
  6820. var prevPrim = this._children[this._firstZDirtyIndex - 1];
  6821. prevLinPos = prevPrim._primLinearPosition;
  6822. startI = this._firstZDirtyIndex - 1;
  6823. startZ = prevPrim._zOrder;
  6824. }
  6825. }
  6826. var startPos = prevLinPos;
  6827. // Update the linear position of the primitive from the first one to the last inside this primitive, compute the total number of prim traversed
  6828. Prim2DBase_1._totalCount = 0;
  6829. for (var i = startI; i < childrenCount; i++) {
  6830. var child = this._children[i];
  6831. prevLinPos = child._updatePrimitiveLinearPosition(prevLinPos);
  6832. }
  6833. // Compute the new Z-Order for all the primitives
  6834. // Add 20% to the current total count to reserve space for future insertions, except if we're rebuilding due to a zMinDelta reached
  6835. var zDelta = (this._zMax - startZ) / (Prim2DBase_1._totalCount * (Prim2DBase_1._zRebuildReentrency ? 1 : 1.2));
  6836. // If the computed delta is less than the smallest allowed by the depth buffer, we rebuild the Z-Order from the very beginning of the primitive's children (that is, the first) to redistribute uniformly the Z.
  6837. if (zDelta < BABYLON.Canvas2D._zMinDelta) {
  6838. // Check for re-entrance, if the flag is true we already attempted a rebuild but couldn't get a better zDelta, go up in the hierarchy to rebuilt one level up, hoping to get this time a decent delta, otherwise, recurse until we got it or when no parent is reached, which would mean the canvas would have more than 16 millions of primitives...
  6839. if (Prim2DBase_1._zRebuildReentrency) {
  6840. var p = this._parent;
  6841. if (p == null) {
  6842. // Can't find a good Z delta and we're in the canvas, which mean we're dealing with too many objects (which should never happen, but well...)
  6843. console.log("Can't compute Z-Order for " + this.id + "'s children, zDelta is too small, Z-Order is now in an unstable state");
  6844. Prim2DBase_1._zRebuildReentrency = false;
  6845. return;
  6846. }
  6847. p._firstZDirtyIndex = 0;
  6848. return p._updateZOrder();
  6849. }
  6850. Prim2DBase_1._zRebuildReentrency = true;
  6851. this._firstZDirtyIndex = 0;
  6852. this._updateZOrder();
  6853. Prim2DBase_1._zRebuildReentrency = false;
  6854. }
  6855. for (var i = startI; i < childrenCount; i++) {
  6856. var child = this._children[i];
  6857. child._updatePrimitiveZOrder(startPos, startZ, zDelta);
  6858. }
  6859. // Notify the Observers that we found during the Z change (we do it after to avoid any kind of re-entrance)
  6860. for (var _i = 0, _a = Prim2DBase_1._zOrderChangedNotifList; _i < _a.length; _i++) {
  6861. var p = _a[_i];
  6862. p._actualZOrderChangedObservable.notifyObservers(p.actualZOffset);
  6863. }
  6864. Prim2DBase_1._zOrderChangedNotifList.splice(0);
  6865. this._firstZDirtyIndex = Prim2DBase_1._bigInt;
  6866. this._clearFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  6867. };
  6868. Prim2DBase.prototype._updatePrimitiveLinearPosition = function (prevLinPos) {
  6869. if (this.isManualZOrder) {
  6870. return prevLinPos;
  6871. }
  6872. this._primLinearPosition = ++prevLinPos;
  6873. Prim2DBase_1._totalCount++;
  6874. // Check for the FlatZOrder, which means the children won't have a dedicated Z-Order but will all share the same (unique) one.
  6875. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder)) {
  6876. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  6877. var child = _a[_i];
  6878. prevLinPos = child._updatePrimitiveLinearPosition(prevLinPos);
  6879. }
  6880. }
  6881. return prevLinPos;
  6882. };
  6883. Prim2DBase.prototype._updatePrimitiveZOrder = function (startPos, startZ, deltaZ) {
  6884. if (this.isManualZOrder) {
  6885. return null;
  6886. }
  6887. var newZ = startZ + ((this._primLinearPosition - startPos) * deltaZ);
  6888. var isFlat = this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  6889. this._setZOrder(newZ, false);
  6890. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  6891. this._firstZDirtyIndex = Prim2DBase_1._bigInt;
  6892. this._clearFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  6893. }
  6894. var curZ = newZ;
  6895. // Check for the FlatZOrder, which means the children won't have a dedicated Z-Order but will all share the same (unique) one.
  6896. if (isFlat) {
  6897. if (this._children.length > 0) {
  6898. //let childrenZOrder = startZ + ((this._children[0]._primLinearPosition - startPos) * deltaZ);
  6899. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  6900. var child = _a[_i];
  6901. child._updatePrimitiveFlatZOrder(this._zOrder);
  6902. }
  6903. }
  6904. }
  6905. else {
  6906. for (var _b = 0, _c = this._children; _b < _c.length; _b++) {
  6907. var child = _c[_b];
  6908. var r = child._updatePrimitiveZOrder(startPos, startZ, deltaZ);
  6909. if (r != null) {
  6910. curZ = r;
  6911. }
  6912. }
  6913. }
  6914. this._zMax = isFlat ? newZ : (curZ + deltaZ);
  6915. return curZ;
  6916. };
  6917. Prim2DBase.prototype._updatePrimitiveFlatZOrder = function (newZ) {
  6918. if (this.isManualZOrder) {
  6919. return;
  6920. }
  6921. this._setZOrder(newZ, false);
  6922. this._zMax = newZ;
  6923. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  6924. this._firstZDirtyIndex = Prim2DBase_1._bigInt;
  6925. this._clearFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  6926. }
  6927. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  6928. var child = _a[_i];
  6929. child._updatePrimitiveFlatZOrder(newZ);
  6930. }
  6931. };
  6932. Prim2DBase.prototype._setZOrder = function (newZ, directEmit) {
  6933. if (newZ !== this._zOrder) {
  6934. this._zOrder = newZ;
  6935. this.onPrimBecomesDirty();
  6936. this.onZOrderChanged();
  6937. if (this._actualZOrderChangedObservable && this._actualZOrderChangedObservable.hasObservers()) {
  6938. if (directEmit) {
  6939. this._actualZOrderChangedObservable.notifyObservers(newZ);
  6940. }
  6941. else {
  6942. Prim2DBase_1._zOrderChangedNotifList.push(this);
  6943. }
  6944. }
  6945. }
  6946. };
  6947. Prim2DBase.prototype._updateRenderMode = function () {
  6948. };
  6949. /**
  6950. * This method is used to alter the contentArea of the Primitive before margin is applied.
  6951. * In most of the case you won't need to override this method, but it can prove some usefulness, check the Rectangle2D class for a concrete application.
  6952. * @param primSize the current size of the primitive
  6953. * @param initialContentPosition the position of the initial content area to compute, a valid object is passed, you have to set its properties. PLEASE ROUND the values, we're talking about pixels and fraction of them is not a good thing! x, y, z, w area left, bottom, right, top
  6954. * @param initialContentArea the size of the initial content area to compute, a valid object is passed, you have to set its properties. PLEASE ROUND the values, we're talking about pixels and fraction of them is not a good thing!
  6955. */
  6956. Prim2DBase.prototype._getInitialContentAreaToRef = function (primSize, initialContentPosition, initialContentArea) {
  6957. initialContentArea.copyFrom(primSize);
  6958. initialContentPosition.x = initialContentPosition.y = initialContentPosition.z = initialContentPosition.w = 0;
  6959. };
  6960. /**
  6961. * This method is used to calculate the new size of the primitive based on the content which must stay the same
  6962. * Check the Rectangle2D implementation for a concrete application.
  6963. * @param primSize the current size of the primitive
  6964. * @param newPrimSize the new size of the primitive. PLEASE ROUND THE values, we're talking about pixels and fraction of them are not our friends!
  6965. */
  6966. Prim2DBase.prototype._getActualSizeFromContentToRef = function (primSize, newPrimSize) {
  6967. newPrimSize.copyFrom(primSize);
  6968. };
  6969. return Prim2DBase;
  6970. }(BABYLON.SmartPropertyPrim));
  6971. Prim2DBase.PRIM2DBASE_PROPCOUNT = 25;
  6972. Prim2DBase._bigInt = Math.pow(2, 30);
  6973. Prim2DBase._nullPosition = BABYLON.Vector2.Zero();
  6974. Prim2DBase.boundinbBoxReentrency = false;
  6975. Prim2DBase.nullSize = BABYLON.Size.Zero();
  6976. Prim2DBase._bMinMax = BABYLON.Vector4.Zero();
  6977. Prim2DBase._bMax = BABYLON.Vector2.Zero();
  6978. Prim2DBase._bSize = BABYLON.Size.Zero();
  6979. Prim2DBase._tpsBB = new BABYLON.BoundingInfo2D();
  6980. /**
  6981. * Make an intersection test with the primitive, all inputs/outputs are stored in the IntersectInfo2D class, see its documentation for more information.
  6982. * @param intersectInfo contains the settings of the intersection to perform, to setup before calling this method as well as the result, available after a call to this method.
  6983. */
  6984. Prim2DBase._bypassGroup2DExclusion = false;
  6985. Prim2DBase._isCanvasInit = false;
  6986. Prim2DBase._t0 = new BABYLON.Matrix();
  6987. Prim2DBase._t1 = new BABYLON.Matrix();
  6988. Prim2DBase._t2 = new BABYLON.Matrix();
  6989. Prim2DBase._v0 = BABYLON.Vector2.Zero(); // Must stay with the value 0,0
  6990. Prim2DBase._transMtx = BABYLON.Matrix.Zero();
  6991. Prim2DBase._icPos = BABYLON.Vector2.Zero();
  6992. Prim2DBase._icZone = BABYLON.Vector4.Zero();
  6993. Prim2DBase._icArea = BABYLON.Size.Zero();
  6994. Prim2DBase._size = BABYLON.Size.Zero();
  6995. Prim2DBase._zOrderChangedNotifList = new Array();
  6996. Prim2DBase._zRebuildReentrency = false;
  6997. Prim2DBase._totalCount = 0;
  6998. __decorate([
  6999. BABYLON.instanceLevelProperty(1, function (pi) { return Prim2DBase_1.actualPositionProperty = pi; }, false, false, true)
  7000. ], Prim2DBase.prototype, "actualPosition", null);
  7001. __decorate([
  7002. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 1, function (pi) { return Prim2DBase_1.actualXProperty = pi; }, false, false, true)
  7003. ], Prim2DBase.prototype, "actualX", null);
  7004. __decorate([
  7005. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 2, function (pi) { return Prim2DBase_1.actualYProperty = pi; }, false, false, true)
  7006. ], Prim2DBase.prototype, "actualY", null);
  7007. __decorate([
  7008. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 3, function (pi) { return Prim2DBase_1.positionProperty = pi; }, false, false, true)
  7009. ], Prim2DBase.prototype, "position", null);
  7010. __decorate([
  7011. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 4, function (pi) { return Prim2DBase_1.xProperty = pi; }, false, false, true)
  7012. ], Prim2DBase.prototype, "x", null);
  7013. __decorate([
  7014. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 5, function (pi) { return Prim2DBase_1.yProperty = pi; }, false, false, true)
  7015. ], Prim2DBase.prototype, "y", null);
  7016. __decorate([
  7017. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 6, function (pi) { return Prim2DBase_1.sizeProperty = pi; }, false, true)
  7018. ], Prim2DBase.prototype, "size", null);
  7019. __decorate([
  7020. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 7, function (pi) { return Prim2DBase_1.widthProperty = pi; }, false, true)
  7021. ], Prim2DBase.prototype, "width", null);
  7022. __decorate([
  7023. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 8, function (pi) { return Prim2DBase_1.heightProperty = pi; }, false, true)
  7024. ], Prim2DBase.prototype, "height", null);
  7025. __decorate([
  7026. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 9, function (pi) { return Prim2DBase_1.rotationProperty = pi; }, false, true)
  7027. ], Prim2DBase.prototype, "rotation", null);
  7028. __decorate([
  7029. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 10, function (pi) { return Prim2DBase_1.scaleProperty = pi; }, false, true)
  7030. ], Prim2DBase.prototype, "scale", null);
  7031. __decorate([
  7032. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 11, function (pi) { return Prim2DBase_1.actualSizeProperty = pi; }, false, true)
  7033. ], Prim2DBase.prototype, "actualSize", null);
  7034. __decorate([
  7035. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 12, function (pi) { return Prim2DBase_1.actualWidthProperty = pi; }, false, true)
  7036. ], Prim2DBase.prototype, "actualWidth", null);
  7037. __decorate([
  7038. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 13, function (pi) { return Prim2DBase_1.actualHeightProperty = pi; }, false, true)
  7039. ], Prim2DBase.prototype, "actualHeight", null);
  7040. __decorate([
  7041. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 14, function (pi) { return Prim2DBase_1.originProperty = pi; }, false, true)
  7042. ], Prim2DBase.prototype, "origin", null);
  7043. __decorate([
  7044. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 15, function (pi) { return Prim2DBase_1.levelVisibleProperty = pi; })
  7045. ], Prim2DBase.prototype, "levelVisible", null);
  7046. __decorate([
  7047. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 16, function (pi) { return Prim2DBase_1.isVisibleProperty = pi; })
  7048. ], Prim2DBase.prototype, "isVisible", null);
  7049. __decorate([
  7050. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 17, function (pi) { return Prim2DBase_1.zOrderProperty = pi; })
  7051. ], Prim2DBase.prototype, "zOrder", null);
  7052. __decorate([
  7053. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 18, function (pi) { return Prim2DBase_1.marginProperty = pi; })
  7054. ], Prim2DBase.prototype, "margin", null);
  7055. __decorate([
  7056. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 19, function (pi) { return Prim2DBase_1.paddingProperty = pi; })
  7057. ], Prim2DBase.prototype, "padding", null);
  7058. __decorate([
  7059. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 20, function (pi) { return Prim2DBase_1.marginAlignmentProperty = pi; })
  7060. ], Prim2DBase.prototype, "marginAlignment", null);
  7061. __decorate([
  7062. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 21, function (pi) { return Prim2DBase_1.opacityProperty = pi; })
  7063. ], Prim2DBase.prototype, "opacity", null);
  7064. __decorate([
  7065. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 22, function (pi) { return Prim2DBase_1.scaleXProperty = pi; }, false, true)
  7066. ], Prim2DBase.prototype, "scaleX", null);
  7067. __decorate([
  7068. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 23, function (pi) { return Prim2DBase_1.scaleYProperty = pi; }, false, true)
  7069. ], Prim2DBase.prototype, "scaleY", null);
  7070. __decorate([
  7071. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 24, function (pi) { return Prim2DBase_1.actualScaleProperty = pi; }, false, true)
  7072. ], Prim2DBase.prototype, "actualScale", null);
  7073. Prim2DBase = Prim2DBase_1 = __decorate([
  7074. BABYLON.className("Prim2DBase", "BABYLON")
  7075. ], Prim2DBase);
  7076. BABYLON.Prim2DBase = Prim2DBase;
  7077. var PrimitiveAlignment_1, PrimitiveThickness_1, Prim2DBase_1;
  7078. })(BABYLON || (BABYLON = {}));
  7079. //# sourceMappingURL=babylon.prim2dBase.js.map
  7080. var __extends = (this && this.__extends) || function (d, b) {
  7081. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  7082. function __() { this.constructor = d; }
  7083. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7084. };
  7085. var BABYLON;
  7086. (function (BABYLON) {
  7087. var GroupInstanceInfo = (function () {
  7088. function GroupInstanceInfo(owner, mrc, partCount) {
  7089. this._partCount = partCount;
  7090. this.owner = owner;
  7091. this.modelRenderCache = mrc;
  7092. this.modelRenderCache.addRef();
  7093. this.partIndexFromId = new BABYLON.StringDictionary();
  7094. this._usedShaderCategories = new Array(partCount);
  7095. this._strides = new Array(partCount);
  7096. this._opaqueData = null;
  7097. this._alphaTestData = null;
  7098. this._transparentData = null;
  7099. this.opaqueDirty = this.alphaTestDirty = this.transparentDirty = this.transparentOrderDirty = false;
  7100. }
  7101. GroupInstanceInfo.prototype.dispose = function () {
  7102. if (this._isDisposed) {
  7103. return false;
  7104. }
  7105. if (this.modelRenderCache) {
  7106. this.modelRenderCache.dispose();
  7107. this.modelRenderCache = null;
  7108. }
  7109. var engine = this.owner.owner.engine;
  7110. if (this._opaqueData) {
  7111. this._opaqueData.forEach(function (d) { return d.dispose(engine); });
  7112. this._opaqueData = null;
  7113. }
  7114. if (this._alphaTestData) {
  7115. this._alphaTestData.forEach(function (d) { return d.dispose(engine); });
  7116. this._alphaTestData = null;
  7117. }
  7118. if (this._transparentData) {
  7119. this._transparentData.forEach(function (d) { return d.dispose(engine); });
  7120. this._transparentData = null;
  7121. }
  7122. this.partIndexFromId = null;
  7123. this._isDisposed = true;
  7124. return true;
  7125. };
  7126. Object.defineProperty(GroupInstanceInfo.prototype, "hasOpaqueData", {
  7127. get: function () {
  7128. return this._opaqueData != null;
  7129. },
  7130. enumerable: true,
  7131. configurable: true
  7132. });
  7133. Object.defineProperty(GroupInstanceInfo.prototype, "hasAlphaTestData", {
  7134. get: function () {
  7135. return this._alphaTestData != null;
  7136. },
  7137. enumerable: true,
  7138. configurable: true
  7139. });
  7140. Object.defineProperty(GroupInstanceInfo.prototype, "hasTransparentData", {
  7141. get: function () {
  7142. return this._transparentData != null;
  7143. },
  7144. enumerable: true,
  7145. configurable: true
  7146. });
  7147. Object.defineProperty(GroupInstanceInfo.prototype, "opaqueData", {
  7148. get: function () {
  7149. if (!this._opaqueData) {
  7150. this._opaqueData = new Array(this._partCount);
  7151. for (var i = 0; i < this._partCount; i++) {
  7152. this._opaqueData[i] = new GroupInfoPartData(this._strides[i]);
  7153. }
  7154. }
  7155. return this._opaqueData;
  7156. },
  7157. enumerable: true,
  7158. configurable: true
  7159. });
  7160. Object.defineProperty(GroupInstanceInfo.prototype, "alphaTestData", {
  7161. get: function () {
  7162. if (!this._alphaTestData) {
  7163. this._alphaTestData = new Array(this._partCount);
  7164. for (var i = 0; i < this._partCount; i++) {
  7165. this._alphaTestData[i] = new GroupInfoPartData(this._strides[i]);
  7166. }
  7167. }
  7168. return this._alphaTestData;
  7169. },
  7170. enumerable: true,
  7171. configurable: true
  7172. });
  7173. Object.defineProperty(GroupInstanceInfo.prototype, "transparentData", {
  7174. get: function () {
  7175. if (!this._transparentData) {
  7176. this._transparentData = new Array(this._partCount);
  7177. for (var i = 0; i < this._partCount; i++) {
  7178. var zoff = this.modelRenderCache._partData[i]._zBiasOffset;
  7179. this._transparentData[i] = new TransparentGroupInfoPartData(this._strides[i], zoff);
  7180. }
  7181. }
  7182. return this._transparentData;
  7183. },
  7184. enumerable: true,
  7185. configurable: true
  7186. });
  7187. GroupInstanceInfo.prototype.sortTransparentData = function () {
  7188. if (!this.transparentOrderDirty) {
  7189. return;
  7190. }
  7191. for (var i = 0; i < this._transparentData.length; i++) {
  7192. var td = this._transparentData[i];
  7193. td._partData.sort();
  7194. }
  7195. this.transparentOrderDirty = false;
  7196. };
  7197. Object.defineProperty(GroupInstanceInfo.prototype, "usedShaderCategories", {
  7198. get: function () {
  7199. return this._usedShaderCategories;
  7200. },
  7201. enumerable: true,
  7202. configurable: true
  7203. });
  7204. Object.defineProperty(GroupInstanceInfo.prototype, "strides", {
  7205. get: function () {
  7206. return this._strides;
  7207. },
  7208. enumerable: true,
  7209. configurable: true
  7210. });
  7211. return GroupInstanceInfo;
  7212. }());
  7213. BABYLON.GroupInstanceInfo = GroupInstanceInfo;
  7214. var TransparentSegment = (function () {
  7215. function TransparentSegment() {
  7216. this.groupInsanceInfo = null;
  7217. this.startZ = 0;
  7218. this.endZ = 0;
  7219. this.startDataIndex = BABYLON.Prim2DBase._bigInt;
  7220. this.endDataIndex = 0;
  7221. this.partBuffers = null;
  7222. }
  7223. TransparentSegment.prototype.dispose = function (engine) {
  7224. if (this.partBuffers) {
  7225. this.partBuffers.forEach(function (b) { return engine._releaseBuffer(b); });
  7226. this.partBuffers.splice(0);
  7227. this.partBuffers = null;
  7228. }
  7229. };
  7230. return TransparentSegment;
  7231. }());
  7232. BABYLON.TransparentSegment = TransparentSegment;
  7233. var GroupInfoPartData = (function () {
  7234. function GroupInfoPartData(stride) {
  7235. this._partData = null;
  7236. this._partBuffer = null;
  7237. this._partBufferSize = 0;
  7238. this._partData = new BABYLON.DynamicFloatArray(stride / 4, 50);
  7239. this._isDisposed = false;
  7240. }
  7241. GroupInfoPartData.prototype.dispose = function (engine) {
  7242. if (this._isDisposed) {
  7243. return false;
  7244. }
  7245. if (this._partBuffer) {
  7246. engine._releaseBuffer(this._partBuffer);
  7247. this._partBuffer = null;
  7248. }
  7249. this._partData = null;
  7250. this._isDisposed = true;
  7251. };
  7252. return GroupInfoPartData;
  7253. }());
  7254. BABYLON.GroupInfoPartData = GroupInfoPartData;
  7255. var TransparentGroupInfoPartData = (function (_super) {
  7256. __extends(TransparentGroupInfoPartData, _super);
  7257. function TransparentGroupInfoPartData(stride, zoff) {
  7258. var _this = _super.call(this, stride) || this;
  7259. _this._partData.compareValueOffset = zoff;
  7260. _this._partData.sortingAscending = false;
  7261. return _this;
  7262. }
  7263. return TransparentGroupInfoPartData;
  7264. }(GroupInfoPartData));
  7265. BABYLON.TransparentGroupInfoPartData = TransparentGroupInfoPartData;
  7266. var ModelRenderCache = (function () {
  7267. function ModelRenderCache(engine, modelKey) {
  7268. this._engine = engine;
  7269. this._modelKey = modelKey;
  7270. this._nextKey = 1;
  7271. this._refCounter = 1;
  7272. this._partData = null;
  7273. }
  7274. ModelRenderCache.prototype.dispose = function () {
  7275. if (--this._refCounter !== 0) {
  7276. return false;
  7277. }
  7278. // Remove the Model Render Cache from the global dictionary
  7279. var edata = this._engine.getExternalData("__BJSCANVAS2D__");
  7280. if (edata) {
  7281. edata.DisposeModelRenderCache(this);
  7282. }
  7283. return true;
  7284. };
  7285. Object.defineProperty(ModelRenderCache.prototype, "isDisposed", {
  7286. get: function () {
  7287. return this._refCounter <= 0;
  7288. },
  7289. enumerable: true,
  7290. configurable: true
  7291. });
  7292. ModelRenderCache.prototype.addRef = function () {
  7293. return ++this._refCounter;
  7294. };
  7295. Object.defineProperty(ModelRenderCache.prototype, "modelKey", {
  7296. get: function () {
  7297. return this._modelKey;
  7298. },
  7299. enumerable: true,
  7300. configurable: true
  7301. });
  7302. /**
  7303. * Render the model instances
  7304. * @param instanceInfo
  7305. * @param context
  7306. * @return must return true is the rendering succeed, false if the rendering couldn't be done (asset's not yet ready, like Effect)
  7307. */
  7308. ModelRenderCache.prototype.render = function (instanceInfo, context) {
  7309. return true;
  7310. };
  7311. ModelRenderCache.prototype.getPartIndexFromId = function (partId) {
  7312. for (var i = 0; i < this._partData.length; i++) {
  7313. if (this._partData[i]._partId === partId) {
  7314. return i;
  7315. }
  7316. }
  7317. return null;
  7318. };
  7319. ModelRenderCache.prototype.loadInstancingAttributes = function (partId, effect) {
  7320. var i = this.getPartIndexFromId(partId);
  7321. if (i === null) {
  7322. return null;
  7323. }
  7324. var ci = this._partsClassInfo[i];
  7325. var categories = this._partData[i]._partUsedCategories;
  7326. var res = ci.classContent.getInstancingAttributeInfos(effect, categories);
  7327. return res;
  7328. };
  7329. ModelRenderCache.prototype.setupUniforms = function (effect, partIndex, data, elementCount) {
  7330. var pd = this._partData[partIndex];
  7331. var offset = (pd._partDataStride / 4) * elementCount;
  7332. var pci = this._partsClassInfo[partIndex];
  7333. var self = this;
  7334. pci.fullContent.forEach(function (k, v) {
  7335. if (!v.category || pd._partUsedCategories.indexOf(v.category) !== -1) {
  7336. switch (v.dataType) {
  7337. case 4 /* float */:
  7338. {
  7339. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  7340. effect.setFloat(v.attributeName, data.buffer[offset + attribOffset]);
  7341. break;
  7342. }
  7343. case 0 /* Vector2 */:
  7344. {
  7345. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  7346. ModelRenderCache.v2.x = data.buffer[offset + attribOffset + 0];
  7347. ModelRenderCache.v2.y = data.buffer[offset + attribOffset + 1];
  7348. effect.setVector2(v.attributeName, ModelRenderCache.v2);
  7349. break;
  7350. }
  7351. case 5 /* Color3 */:
  7352. case 1 /* Vector3 */:
  7353. {
  7354. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  7355. ModelRenderCache.v3.x = data.buffer[offset + attribOffset + 0];
  7356. ModelRenderCache.v3.y = data.buffer[offset + attribOffset + 1];
  7357. ModelRenderCache.v3.z = data.buffer[offset + attribOffset + 2];
  7358. effect.setVector3(v.attributeName, ModelRenderCache.v3);
  7359. break;
  7360. }
  7361. case 6 /* Color4 */:
  7362. case 2 /* Vector4 */:
  7363. {
  7364. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  7365. ModelRenderCache.v4.x = data.buffer[offset + attribOffset + 0];
  7366. ModelRenderCache.v4.y = data.buffer[offset + attribOffset + 1];
  7367. ModelRenderCache.v4.z = data.buffer[offset + attribOffset + 2];
  7368. ModelRenderCache.v4.w = data.buffer[offset + attribOffset + 3];
  7369. effect.setVector4(v.attributeName, ModelRenderCache.v4);
  7370. break;
  7371. }
  7372. default:
  7373. }
  7374. }
  7375. });
  7376. };
  7377. return ModelRenderCache;
  7378. }());
  7379. //setupUniformsLocation(effect: Effect, uniforms: string[], partId: number) {
  7380. // let i = this.getPartIndexFromId(partId);
  7381. // if (i === null) {
  7382. // return null;
  7383. // }
  7384. // let pci = this._partsClassInfo[i];
  7385. // pci.fullContent.forEach((k, v) => {
  7386. // if (uniforms.indexOf(v.attributeName) !== -1) {
  7387. // v.uniformLocation = effect.getUniform(v.attributeName);
  7388. // }
  7389. // });
  7390. //}
  7391. ModelRenderCache.v2 = BABYLON.Vector2.Zero();
  7392. ModelRenderCache.v3 = BABYLON.Vector3.Zero();
  7393. ModelRenderCache.v4 = BABYLON.Vector4.Zero();
  7394. BABYLON.ModelRenderCache = ModelRenderCache;
  7395. var ModelRenderCachePartData = (function () {
  7396. function ModelRenderCachePartData() {
  7397. }
  7398. return ModelRenderCachePartData;
  7399. }());
  7400. BABYLON.ModelRenderCachePartData = ModelRenderCachePartData;
  7401. })(BABYLON || (BABYLON = {}));
  7402. //# sourceMappingURL=babylon.modelRenderCache.js.map
  7403. var __extends = (this && this.__extends) || function (d, b) {
  7404. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  7405. function __() { this.constructor = d; }
  7406. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7407. };
  7408. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  7409. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  7410. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  7411. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  7412. return c > 3 && r && Object.defineProperty(target, key, r), r;
  7413. };
  7414. var BABYLON;
  7415. (function (BABYLON) {
  7416. var InstanceClassInfo = (function () {
  7417. function InstanceClassInfo(base) {
  7418. this._baseInfo = base;
  7419. this._nextOffset = new BABYLON.StringDictionary();
  7420. this._attributes = new Array();
  7421. }
  7422. InstanceClassInfo.prototype.mapProperty = function (propInfo, push) {
  7423. var curOff = this._nextOffset.getOrAdd(InstanceClassInfo._CurCategories, 0);
  7424. propInfo.instanceOffset.add(InstanceClassInfo._CurCategories, this._getBaseOffset(InstanceClassInfo._CurCategories) + curOff);
  7425. //console.log(`[${InstanceClassInfo._CurCategories}] New PropInfo. Category: ${propInfo.category}, Name: ${propInfo.attributeName}, Offset: ${propInfo.instanceOffset.get(InstanceClassInfo._CurCategories)}, Size: ${propInfo.size / 4}`);
  7426. this._nextOffset.set(InstanceClassInfo._CurCategories, curOff + (propInfo.size / 4));
  7427. if (push) {
  7428. this._attributes.push(propInfo);
  7429. }
  7430. };
  7431. InstanceClassInfo.prototype.getInstancingAttributeInfos = function (effect, categories) {
  7432. var catInline = ";" + categories.join(";") + ";";
  7433. var res = new Array();
  7434. var curInfo = this;
  7435. while (curInfo) {
  7436. for (var _i = 0, _a = curInfo._attributes; _i < _a.length; _i++) {
  7437. var attrib = _a[_i];
  7438. // Only map if there's no category assigned to the instance data or if there's a category and it's in the given list
  7439. if (!attrib.category || categories.indexOf(attrib.category) !== -1) {
  7440. var index = effect.getAttributeLocationByName(attrib.attributeName);
  7441. if (index === -1) {
  7442. throw new Error("Attribute " + attrib.attributeName + " was not found in Effect: " + effect.name + ". It's certainly no longer used in the Effect's Shaders");
  7443. }
  7444. var iai = new BABYLON.InstancingAttributeInfo();
  7445. iai.index = index;
  7446. iai.attributeSize = attrib.size / 4; // attrib.size is in byte and we need to store in "component" (i.e float is 1, vec3 is 3)
  7447. iai.offset = attrib.instanceOffset.get(catInline) * 4; // attrib.instanceOffset is in float, iai.offset must be in bytes
  7448. iai.attributeName = attrib.attributeName;
  7449. res.push(iai);
  7450. }
  7451. }
  7452. curInfo = curInfo._baseInfo;
  7453. }
  7454. return res;
  7455. };
  7456. InstanceClassInfo.prototype.getShaderAttributes = function (categories) {
  7457. var res = new Array();
  7458. var curInfo = this;
  7459. while (curInfo) {
  7460. for (var _i = 0, _a = curInfo._attributes; _i < _a.length; _i++) {
  7461. var attrib = _a[_i];
  7462. // Only map if there's no category assigned to the instance data or if there's a category and it's in the given list
  7463. if (!attrib.category || categories.indexOf(attrib.category) !== -1) {
  7464. res.push(attrib.attributeName);
  7465. }
  7466. }
  7467. curInfo = curInfo._baseInfo;
  7468. }
  7469. return res;
  7470. };
  7471. InstanceClassInfo.prototype._getBaseOffset = function (categories) {
  7472. var curOffset = 0;
  7473. var curBase = this._baseInfo;
  7474. while (curBase) {
  7475. curOffset += curBase._nextOffset.getOrAdd(categories, 0);
  7476. curBase = curBase._baseInfo;
  7477. }
  7478. return curOffset;
  7479. };
  7480. return InstanceClassInfo;
  7481. }());
  7482. BABYLON.InstanceClassInfo = InstanceClassInfo;
  7483. var InstancePropInfo = (function () {
  7484. function InstancePropInfo() {
  7485. this.instanceOffset = new BABYLON.StringDictionary();
  7486. }
  7487. InstancePropInfo.prototype.setSize = function (val) {
  7488. if (val instanceof BABYLON.Vector2) {
  7489. this.size = 8;
  7490. this.dataType = 0 /* Vector2 */;
  7491. return;
  7492. }
  7493. if (val instanceof BABYLON.Vector3) {
  7494. this.size = 12;
  7495. this.dataType = 1 /* Vector3 */;
  7496. return;
  7497. }
  7498. if (val instanceof BABYLON.Vector4) {
  7499. this.size = 16;
  7500. this.dataType = 2 /* Vector4 */;
  7501. return;
  7502. }
  7503. if (val instanceof BABYLON.Matrix) {
  7504. throw new Error("Matrix type is not supported by WebGL Instance Buffer, you have to use four Vector4 properties instead");
  7505. }
  7506. if (typeof (val) === "number") {
  7507. this.size = 4;
  7508. this.dataType = 4 /* float */;
  7509. return;
  7510. }
  7511. if (val instanceof BABYLON.Color3) {
  7512. this.size = 12;
  7513. this.dataType = 5 /* Color3 */;
  7514. return;
  7515. }
  7516. if (val instanceof BABYLON.Color4) {
  7517. this.size = 16;
  7518. this.dataType = 6 /* Color4 */;
  7519. return;
  7520. }
  7521. if (val instanceof BABYLON.Size) {
  7522. this.size = 8;
  7523. this.dataType = 7 /* Size */;
  7524. return;
  7525. }
  7526. return;
  7527. };
  7528. InstancePropInfo.prototype.writeData = function (array, offset, val) {
  7529. switch (this.dataType) {
  7530. case 0 /* Vector2 */:
  7531. {
  7532. var v = val;
  7533. array[offset + 0] = v.x;
  7534. array[offset + 1] = v.y;
  7535. break;
  7536. }
  7537. case 1 /* Vector3 */:
  7538. {
  7539. var v = val;
  7540. array[offset + 0] = v.x;
  7541. array[offset + 1] = v.y;
  7542. array[offset + 2] = v.z;
  7543. break;
  7544. }
  7545. case 2 /* Vector4 */:
  7546. {
  7547. var v = val;
  7548. array[offset + 0] = v.x;
  7549. array[offset + 1] = v.y;
  7550. array[offset + 2] = v.z;
  7551. array[offset + 3] = v.w;
  7552. break;
  7553. }
  7554. case 5 /* Color3 */:
  7555. {
  7556. var v = val;
  7557. array[offset + 0] = v.r;
  7558. array[offset + 1] = v.g;
  7559. array[offset + 2] = v.b;
  7560. break;
  7561. }
  7562. case 6 /* Color4 */:
  7563. {
  7564. var v = val;
  7565. array[offset + 0] = v.r;
  7566. array[offset + 1] = v.g;
  7567. array[offset + 2] = v.b;
  7568. array[offset + 3] = v.a;
  7569. break;
  7570. }
  7571. case 4 /* float */:
  7572. {
  7573. var v = val;
  7574. array[offset] = v;
  7575. break;
  7576. }
  7577. case 3 /* Matrix */:
  7578. {
  7579. var v = val;
  7580. for (var i = 0; i < 16; i++) {
  7581. array[offset + i] = v.m[i];
  7582. }
  7583. break;
  7584. }
  7585. case 7 /* Size */:
  7586. {
  7587. var s = val;
  7588. array[offset + 0] = s.width;
  7589. array[offset + 1] = s.height;
  7590. break;
  7591. }
  7592. }
  7593. };
  7594. return InstancePropInfo;
  7595. }());
  7596. BABYLON.InstancePropInfo = InstancePropInfo;
  7597. function instanceData(category, shaderAttributeName) {
  7598. return function (target, propName, descriptor) {
  7599. var dic = BABYLON.ClassTreeInfo.getOrRegister(target, function (base) { return new InstanceClassInfo(base); });
  7600. var node = dic.getLevelOf(target);
  7601. var instanceDataName = propName;
  7602. shaderAttributeName = shaderAttributeName || instanceDataName;
  7603. var info = node.levelContent.get(instanceDataName);
  7604. if (info) {
  7605. throw new Error("The ID " + instanceDataName + " is already taken by another instance data");
  7606. }
  7607. info = new InstancePropInfo();
  7608. info.attributeName = shaderAttributeName;
  7609. info.category = category || null;
  7610. if (info.category) {
  7611. info.delimitedCategory = ";" + info.category + ";";
  7612. }
  7613. node.levelContent.add(instanceDataName, info);
  7614. descriptor.get = function () {
  7615. return null;
  7616. };
  7617. descriptor.set = function (val) {
  7618. // Check that we're not trying to set a property that belongs to a category that is not allowed (current)
  7619. // Quit if it's the case, otherwise we could overwrite data somewhere...
  7620. if (info.category && InstanceClassInfo._CurCategories.indexOf(info.delimitedCategory) === -1) {
  7621. return;
  7622. }
  7623. if (!info.size) {
  7624. info.setSize(val);
  7625. node.classContent.mapProperty(info, true);
  7626. }
  7627. else if (!info.instanceOffset.contains(InstanceClassInfo._CurCategories)) {
  7628. node.classContent.mapProperty(info, false);
  7629. }
  7630. var obj = this;
  7631. if (obj.dataBuffer && obj.dataElements) {
  7632. var offset = obj.dataElements[obj.curElement].offset + info.instanceOffset.get(InstanceClassInfo._CurCategories);
  7633. info.writeData(obj.dataBuffer.buffer, offset, val);
  7634. }
  7635. };
  7636. };
  7637. }
  7638. BABYLON.instanceData = instanceData;
  7639. var InstanceDataBase = (function () {
  7640. function InstanceDataBase(partId, dataElementCount) {
  7641. this.id = partId;
  7642. this.curElement = 0;
  7643. this._dataElementCount = dataElementCount;
  7644. this.renderMode = 0;
  7645. this.arrayLengthChanged = false;
  7646. }
  7647. Object.defineProperty(InstanceDataBase.prototype, "zBias", {
  7648. get: function () {
  7649. return null;
  7650. },
  7651. set: function (value) {
  7652. },
  7653. enumerable: true,
  7654. configurable: true
  7655. });
  7656. Object.defineProperty(InstanceDataBase.prototype, "transformX", {
  7657. get: function () {
  7658. return null;
  7659. },
  7660. set: function (value) {
  7661. },
  7662. enumerable: true,
  7663. configurable: true
  7664. });
  7665. Object.defineProperty(InstanceDataBase.prototype, "transformY", {
  7666. get: function () {
  7667. return null;
  7668. },
  7669. set: function (value) {
  7670. },
  7671. enumerable: true,
  7672. configurable: true
  7673. });
  7674. Object.defineProperty(InstanceDataBase.prototype, "opacity", {
  7675. get: function () {
  7676. return null;
  7677. },
  7678. set: function (value) {
  7679. },
  7680. enumerable: true,
  7681. configurable: true
  7682. });
  7683. InstanceDataBase.prototype.getClassTreeInfo = function () {
  7684. if (!this.typeInfo) {
  7685. this.typeInfo = BABYLON.ClassTreeInfo.get(Object.getPrototypeOf(this));
  7686. }
  7687. return this.typeInfo;
  7688. };
  7689. InstanceDataBase.prototype.allocElements = function () {
  7690. if (!this.dataBuffer || this.dataElements) {
  7691. return;
  7692. }
  7693. var res = new Array(this.dataElementCount);
  7694. for (var i = 0; i < this.dataElementCount; i++) {
  7695. res[i] = this.dataBuffer.allocElement();
  7696. }
  7697. this.dataElements = res;
  7698. };
  7699. InstanceDataBase.prototype.freeElements = function () {
  7700. if (!this.dataElements) {
  7701. return;
  7702. }
  7703. for (var _i = 0, _a = this.dataElements; _i < _a.length; _i++) {
  7704. var ei = _a[_i];
  7705. this.dataBuffer.freeElement(ei);
  7706. }
  7707. this.dataElements = null;
  7708. };
  7709. Object.defineProperty(InstanceDataBase.prototype, "dataElementCount", {
  7710. get: function () {
  7711. return this._dataElementCount;
  7712. },
  7713. set: function (value) {
  7714. if (value === this._dataElementCount) {
  7715. return;
  7716. }
  7717. this.arrayLengthChanged = true;
  7718. this.freeElements();
  7719. this._dataElementCount = value;
  7720. this.allocElements();
  7721. },
  7722. enumerable: true,
  7723. configurable: true
  7724. });
  7725. return InstanceDataBase;
  7726. }());
  7727. __decorate([
  7728. instanceData()
  7729. ], InstanceDataBase.prototype, "zBias", null);
  7730. __decorate([
  7731. instanceData()
  7732. ], InstanceDataBase.prototype, "transformX", null);
  7733. __decorate([
  7734. instanceData()
  7735. ], InstanceDataBase.prototype, "transformY", null);
  7736. __decorate([
  7737. instanceData()
  7738. ], InstanceDataBase.prototype, "opacity", null);
  7739. BABYLON.InstanceDataBase = InstanceDataBase;
  7740. var RenderablePrim2D = RenderablePrim2D_1 = (function (_super) {
  7741. __extends(RenderablePrim2D, _super);
  7742. function RenderablePrim2D(settings) {
  7743. var _this = _super.call(this, settings) || this;
  7744. _this._transparentPrimitiveInfo = null;
  7745. return _this;
  7746. }
  7747. Object.defineProperty(RenderablePrim2D.prototype, "isAlphaTest", {
  7748. get: function () {
  7749. return this._useTextureAlpha() || this._isPrimAlphaTest();
  7750. },
  7751. enumerable: true,
  7752. configurable: true
  7753. });
  7754. Object.defineProperty(RenderablePrim2D.prototype, "isTransparent", {
  7755. get: function () {
  7756. return (this.actualOpacity < 1) || this._shouldUseAlphaFromTexture() || this._isPrimTransparent();
  7757. },
  7758. enumerable: true,
  7759. configurable: true
  7760. });
  7761. Object.defineProperty(RenderablePrim2D.prototype, "renderMode", {
  7762. get: function () {
  7763. return this._renderMode;
  7764. },
  7765. enumerable: true,
  7766. configurable: true
  7767. });
  7768. /**
  7769. * Dispose the primitive and its resources, remove it from its parent
  7770. */
  7771. RenderablePrim2D.prototype.dispose = function () {
  7772. if (!_super.prototype.dispose.call(this)) {
  7773. return false;
  7774. }
  7775. if (this.renderGroup) {
  7776. this.renderGroup._setCacheGroupDirty();
  7777. }
  7778. if (this._transparentPrimitiveInfo) {
  7779. this.renderGroup._renderableData.removeTransparentPrimitiveInfo(this._transparentPrimitiveInfo);
  7780. this._transparentPrimitiveInfo = null;
  7781. }
  7782. if (this._instanceDataParts) {
  7783. this._cleanupInstanceDataParts();
  7784. }
  7785. if (this._modelRenderCache) {
  7786. this._modelRenderCache.dispose();
  7787. this._modelRenderCache = null;
  7788. }
  7789. if (this._instanceDataParts) {
  7790. this._instanceDataParts.forEach(function (p) {
  7791. p.freeElements();
  7792. });
  7793. this._instanceDataParts = null;
  7794. }
  7795. return true;
  7796. };
  7797. RenderablePrim2D.prototype._cleanupInstanceDataParts = function () {
  7798. var gii = null;
  7799. for (var _i = 0, _a = this._instanceDataParts; _i < _a.length; _i++) {
  7800. var part = _a[_i];
  7801. part.freeElements();
  7802. gii = part.groupInstanceInfo;
  7803. }
  7804. if (gii) {
  7805. var usedCount = 0;
  7806. if (gii.hasOpaqueData) {
  7807. var od = gii.opaqueData[0];
  7808. usedCount += od._partData.usedElementCount;
  7809. gii.opaqueDirty = true;
  7810. }
  7811. if (gii.hasAlphaTestData) {
  7812. var atd = gii.alphaTestData[0];
  7813. usedCount += atd._partData.usedElementCount;
  7814. gii.alphaTestDirty = true;
  7815. }
  7816. if (gii.hasTransparentData) {
  7817. var td = gii.transparentData[0];
  7818. usedCount += td._partData.usedElementCount;
  7819. gii.transparentDirty = true;
  7820. }
  7821. if (usedCount === 0 && gii.modelRenderCache != null) {
  7822. this.renderGroup._renderableData._renderGroupInstancesInfo.remove(gii.modelRenderCache.modelKey);
  7823. gii.dispose();
  7824. }
  7825. if (this._modelRenderCache) {
  7826. this._modelRenderCache.dispose();
  7827. this._modelRenderCache = null;
  7828. }
  7829. }
  7830. this._instanceDataParts = null;
  7831. };
  7832. RenderablePrim2D.prototype._prepareRenderPre = function (context) {
  7833. _super.prototype._prepareRenderPre.call(this, context);
  7834. // If the model changed and we have already an instance, we must remove this instance from the obsolete model
  7835. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagModelDirty) && this._instanceDataParts) {
  7836. this._cleanupInstanceDataParts();
  7837. }
  7838. // Need to create the model?
  7839. var setupModelRenderCache = false;
  7840. if (!this._modelRenderCache || this._isFlagSet(BABYLON.SmartPropertyPrim.flagModelDirty)) {
  7841. setupModelRenderCache = this._createModelRenderCache();
  7842. }
  7843. var gii = null;
  7844. var newInstance = false;
  7845. // Need to create the instance data parts?
  7846. if (!this._instanceDataParts) {
  7847. // Yes, flag it for later, more processing will have to be done
  7848. newInstance = true;
  7849. gii = this._createModelDataParts();
  7850. }
  7851. // If the ModelRenderCache is brand new, now is the time to call the implementation's specific setup method to create the rendering resources
  7852. if (setupModelRenderCache) {
  7853. this.setupModelRenderCache(this._modelRenderCache);
  7854. }
  7855. // At this stage we have everything correctly initialized, ModelRenderCache is setup, Model Instance data are good too, they have allocated elements in the Instanced DynamicFloatArray.
  7856. // The last thing to do is check if the instanced related data must be updated because a InstanceLevel property had changed or the primitive visibility changed.
  7857. if (this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagVisibilityChanged | BABYLON.SmartPropertyPrim.flagNeedRefresh) || context.forceRefreshPrimitive || newInstance || (this._instanceDirtyFlags !== 0) || (this._globalTransformProcessStep !== this._globalTransformStep) || this._mustUpdateInstance()) {
  7858. this._updateInstanceDataParts(gii);
  7859. }
  7860. };
  7861. RenderablePrim2D.prototype._createModelRenderCache = function () {
  7862. var _this = this;
  7863. var setupModelRenderCache = false;
  7864. if (this._modelRenderCache) {
  7865. this._modelRenderCache.dispose();
  7866. }
  7867. this._modelRenderCache = this.owner._engineData.GetOrAddModelCache(this.modelKey, function (key) {
  7868. var mrc = _this.createModelRenderCache(key);
  7869. setupModelRenderCache = true;
  7870. return mrc;
  7871. });
  7872. this._clearFlags(BABYLON.SmartPropertyPrim.flagModelDirty);
  7873. // if this is still false it means the MRC already exists, so we add a reference to it
  7874. if (!setupModelRenderCache) {
  7875. this._modelRenderCache.addRef();
  7876. }
  7877. return setupModelRenderCache;
  7878. };
  7879. RenderablePrim2D.prototype._createModelDataParts = function () {
  7880. var _this = this;
  7881. // Create the instance data parts of the primitive and store them
  7882. var parts = this.createInstanceDataParts();
  7883. this._instanceDataParts = parts;
  7884. // Check if the ModelRenderCache for this particular instance is also brand new, initialize it if it's the case
  7885. if (!this._modelRenderCache._partData) {
  7886. this._setupModelRenderCache(parts);
  7887. }
  7888. // The Rendering resources (Effect, VB, IB, Textures) are stored in the ModelRenderCache
  7889. // But it's the RenderGroup that will store all the Instanced related data to render all the primitive it owns.
  7890. // So for a given ModelKey we getOrAdd a GroupInstanceInfo that will store all these data
  7891. var gii = this.renderGroup._renderableData._renderGroupInstancesInfo.getOrAddWithFactory(this.modelKey, function (k) {
  7892. var res = new BABYLON.GroupInstanceInfo(_this.renderGroup, _this._modelRenderCache, _this._modelRenderCache._partData.length);
  7893. for (var j = 0; j < _this._modelRenderCache._partData.length; j++) {
  7894. var part = _this._instanceDataParts[j];
  7895. res.partIndexFromId.add(part.id.toString(), j);
  7896. res.usedShaderCategories[j] = ";" + _this.getUsedShaderCategories(part).join(";") + ";";
  7897. res.strides[j] = _this._modelRenderCache._partData[j]._partDataStride;
  7898. }
  7899. return res;
  7900. });
  7901. // Get the GroupInfoDataPart corresponding to the render category of the part
  7902. var rm = 0;
  7903. var gipd = null;
  7904. if (this.isTransparent) {
  7905. gipd = gii.transparentData;
  7906. rm = BABYLON.Render2DContext.RenderModeTransparent;
  7907. }
  7908. else if (this.isAlphaTest) {
  7909. gipd = gii.alphaTestData;
  7910. rm = BABYLON.Render2DContext.RenderModeAlphaTest;
  7911. }
  7912. else {
  7913. gipd = gii.opaqueData;
  7914. rm = BABYLON.Render2DContext.RenderModeOpaque;
  7915. }
  7916. // For each instance data part of the primitive, allocate the instanced element it needs for render
  7917. for (var i = 0; i < parts.length; i++) {
  7918. var part = parts[i];
  7919. part.dataBuffer = gipd[i]._partData;
  7920. part.allocElements();
  7921. part.renderMode = rm;
  7922. part.groupInstanceInfo = gii;
  7923. }
  7924. return gii;
  7925. };
  7926. RenderablePrim2D.prototype._setupModelRenderCache = function (parts) {
  7927. var ctiArray = new Array();
  7928. this._modelRenderCache._partData = new Array();
  7929. for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
  7930. var dataPart = parts_1[_i];
  7931. var pd = new BABYLON.ModelRenderCachePartData();
  7932. this._modelRenderCache._partData.push(pd);
  7933. var cat = this.getUsedShaderCategories(dataPart);
  7934. var cti = dataPart.getClassTreeInfo();
  7935. // Make sure the instance is visible other the properties won't be set and their size/offset wont be computed
  7936. var curVisible = this.isVisible;
  7937. this.isVisible = true;
  7938. // We manually trigger refreshInstanceData for the only sake of evaluating each instance property size and offset in the instance data, this can only be made at runtime. Once it's done we have all the information to create the instance data buffer.
  7939. //console.log("Build Prop Layout for " + Tools.getClassName(this._instanceDataParts[0]));
  7940. var joinCat = ";" + cat.join(";") + ";";
  7941. pd._partJoinedUsedCategories = joinCat;
  7942. InstanceClassInfo._CurCategories = joinCat;
  7943. var obj = this.beforeRefreshForLayoutConstruction(dataPart);
  7944. if (!this.refreshInstanceDataPart(dataPart)) {
  7945. console.log("Layout construction for " + BABYLON.Tools.getClassName(this._instanceDataParts[0]) + " failed because refresh returned false");
  7946. }
  7947. this.afterRefreshForLayoutConstruction(dataPart, obj);
  7948. this.isVisible = curVisible;
  7949. var size = 0;
  7950. cti.fullContent.forEach(function (k, v) {
  7951. if (!v.category || cat.indexOf(v.category) !== -1) {
  7952. if (v.attributeName === "zBias") {
  7953. pd._zBiasOffset = v.instanceOffset.get(joinCat);
  7954. }
  7955. if (!v.size) {
  7956. console.log("ERROR: Couldn't detect the size of the Property " + v.attributeName + " from type " + BABYLON.Tools.getClassName(cti.type) + ". Property is ignored.");
  7957. }
  7958. else {
  7959. size += v.size;
  7960. }
  7961. }
  7962. });
  7963. pd._partDataStride = size;
  7964. pd._partUsedCategories = cat;
  7965. pd._partId = dataPart.id;
  7966. ctiArray.push(cti);
  7967. }
  7968. this._modelRenderCache._partsClassInfo = ctiArray;
  7969. };
  7970. RenderablePrim2D.prototype.onZOrderChanged = function () {
  7971. if (this.isTransparent && this._transparentPrimitiveInfo) {
  7972. this.renderGroup._renderableData.transparentPrimitiveZChanged(this._transparentPrimitiveInfo);
  7973. var gii = this.renderGroup._renderableData._renderGroupInstancesInfo.get(this.modelKey);
  7974. // Flag the transparentData dirty has will have to sort it again
  7975. gii.transparentOrderDirty = true;
  7976. }
  7977. };
  7978. RenderablePrim2D.prototype._mustUpdateInstance = function () {
  7979. return false;
  7980. };
  7981. RenderablePrim2D.prototype._useTextureAlpha = function () {
  7982. return false;
  7983. };
  7984. RenderablePrim2D.prototype._shouldUseAlphaFromTexture = function () {
  7985. return false;
  7986. };
  7987. RenderablePrim2D.prototype._isPrimAlphaTest = function () {
  7988. return false;
  7989. };
  7990. RenderablePrim2D.prototype._isPrimTransparent = function () {
  7991. return false;
  7992. };
  7993. RenderablePrim2D.prototype._updateInstanceDataParts = function (gii) {
  7994. // Fetch the GroupInstanceInfo if we don't already have it
  7995. var rd = this.renderGroup._renderableData;
  7996. if (!gii) {
  7997. gii = rd._renderGroupInstancesInfo.get(this.modelKey);
  7998. }
  7999. var isTransparent = this.isTransparent;
  8000. var isAlphaTest = this.isAlphaTest;
  8001. var wereTransparent = false;
  8002. // Check a render mode change
  8003. var rmChanged = false;
  8004. if (this._instanceDataParts.length > 0) {
  8005. var firstPart = this._instanceDataParts[0];
  8006. var partRM = firstPart.renderMode;
  8007. var curRM = this.renderMode;
  8008. if (partRM !== curRM) {
  8009. wereTransparent = partRM === BABYLON.Render2DContext.RenderModeTransparent;
  8010. rmChanged = true;
  8011. var gipd = void 0;
  8012. switch (curRM) {
  8013. case BABYLON.Render2DContext.RenderModeTransparent:
  8014. gipd = gii.transparentData;
  8015. break;
  8016. case BABYLON.Render2DContext.RenderModeAlphaTest:
  8017. gipd = gii.alphaTestData;
  8018. break;
  8019. default:
  8020. gipd = gii.opaqueData;
  8021. }
  8022. for (var i = 0; i < this._instanceDataParts.length; i++) {
  8023. var part = this._instanceDataParts[i];
  8024. part.freeElements();
  8025. part.dataBuffer = gipd[i]._partData;
  8026. part.renderMode = curRM;
  8027. }
  8028. }
  8029. }
  8030. // Handle changes related to ZOffset
  8031. var visChanged = this._isFlagSet(BABYLON.SmartPropertyPrim.flagVisibilityChanged);
  8032. if (isTransparent || wereTransparent) {
  8033. // Handle visibility change, which is also triggered when the primitive just got created
  8034. if (visChanged || rmChanged) {
  8035. if (this.isVisible && !wereTransparent) {
  8036. if (!this._transparentPrimitiveInfo) {
  8037. // Add the primitive to the list of transparent ones in the group that render is
  8038. this._transparentPrimitiveInfo = rd.addNewTransparentPrimitiveInfo(this, gii);
  8039. }
  8040. }
  8041. else {
  8042. if (this._transparentPrimitiveInfo) {
  8043. rd.removeTransparentPrimitiveInfo(this._transparentPrimitiveInfo);
  8044. this._transparentPrimitiveInfo = null;
  8045. }
  8046. }
  8047. gii.transparentOrderDirty = true;
  8048. }
  8049. }
  8050. var rebuildTrans = false;
  8051. // For each Instance Data part, refresh it to update the data in the DynamicFloatArray
  8052. for (var _i = 0, _a = this._instanceDataParts; _i < _a.length; _i++) {
  8053. var part = _a[_i];
  8054. var justAllocated = false;
  8055. // Check if we need to allocate data elements (hidden prim which becomes visible again)
  8056. if (!part.dataElements && (visChanged || rmChanged || this.isVisible)) {
  8057. part.allocElements();
  8058. justAllocated = true;
  8059. }
  8060. InstanceClassInfo._CurCategories = gii.usedShaderCategories[gii.partIndexFromId.get(part.id.toString())];
  8061. // Will return false if the instance should not be rendered (not visible or other any reasons)
  8062. part.arrayLengthChanged = false;
  8063. if (!this.refreshInstanceDataPart(part)) {
  8064. // Free the data element
  8065. if (part.dataElements) {
  8066. part.freeElements();
  8067. }
  8068. // The refresh couldn't succeed, push the primitive to be dirty again for the next render
  8069. if (this.isVisible) {
  8070. rd._primNewDirtyList.push(this);
  8071. }
  8072. }
  8073. rebuildTrans = rebuildTrans || part.arrayLengthChanged || justAllocated;
  8074. }
  8075. this._instanceDirtyFlags = 0;
  8076. // Make the appropriate data dirty
  8077. if (isTransparent) {
  8078. gii.transparentDirty = true;
  8079. if (rebuildTrans) {
  8080. rd._transparentListChanged = true;
  8081. }
  8082. }
  8083. else if (isAlphaTest) {
  8084. gii.alphaTestDirty = true;
  8085. }
  8086. else {
  8087. gii.opaqueDirty = true;
  8088. }
  8089. this._clearFlags(BABYLON.SmartPropertyPrim.flagVisibilityChanged); // Reset the flag as we've handled the case
  8090. };
  8091. RenderablePrim2D.prototype._updateTransparentSegmentIndices = function (ts) {
  8092. var minOff = BABYLON.Prim2DBase._bigInt;
  8093. var maxOff = 0;
  8094. for (var _i = 0, _a = this._instanceDataParts; _i < _a.length; _i++) {
  8095. var part = _a[_i];
  8096. if (part && part.dataElements) {
  8097. part.dataBuffer.pack();
  8098. for (var _b = 0, _c = part.dataElements; _b < _c.length; _b++) {
  8099. var el = _c[_b];
  8100. minOff = Math.min(minOff, el.offset);
  8101. maxOff = Math.max(maxOff, el.offset);
  8102. }
  8103. ts.startDataIndex = Math.min(ts.startDataIndex, minOff / part.dataBuffer.stride);
  8104. ts.endDataIndex = Math.max(ts.endDataIndex, (maxOff / part.dataBuffer.stride) + 1); // +1 for exclusive
  8105. }
  8106. }
  8107. };
  8108. // This internal method is mainly used for transparency processing
  8109. RenderablePrim2D.prototype._getNextPrimZOrder = function () {
  8110. var length = this._instanceDataParts.length;
  8111. for (var i = 0; i < length; i++) {
  8112. var part = this._instanceDataParts[i];
  8113. if (part) {
  8114. var stride = part.dataBuffer.stride;
  8115. var lastElementOffset = part.dataElements[part.dataElements.length - 1].offset;
  8116. // check if it's the last in the DFA
  8117. if (part.dataBuffer.totalElementCount * stride <= lastElementOffset) {
  8118. return null;
  8119. }
  8120. // Return the Z of the next primitive that lies in the DFA
  8121. return part.dataBuffer[lastElementOffset + stride + this.modelRenderCache._partData[i]._zBiasOffset];
  8122. }
  8123. }
  8124. return null;
  8125. };
  8126. // This internal method is mainly used for transparency processing
  8127. RenderablePrim2D.prototype._getPrevPrimZOrder = function () {
  8128. var length = this._instanceDataParts.length;
  8129. for (var i = 0; i < length; i++) {
  8130. var part = this._instanceDataParts[i];
  8131. if (part) {
  8132. var stride = part.dataBuffer.stride;
  8133. var firstElementOffset = part.dataElements[0].offset;
  8134. // check if it's the first in the DFA
  8135. if (firstElementOffset === 0) {
  8136. return null;
  8137. }
  8138. // Return the Z of the previous primitive that lies in the DFA
  8139. return part.dataBuffer[firstElementOffset - stride + this.modelRenderCache._partData[i]._zBiasOffset];
  8140. }
  8141. }
  8142. return null;
  8143. };
  8144. /**
  8145. * Transform a given point using the Primitive's origin setting.
  8146. * This method requires the Primitive's actualSize to be accurate
  8147. * @param p the point to transform
  8148. * @param originOffset an offset applied on the current origin before performing the transformation. Depending on which frame of reference your data is expressed you may have to apply a offset. (if you data is expressed from the bottom/left, no offset is required. If it's expressed from the center the a [-0.5;-0.5] offset has to be applied.
  8149. * @param res an allocated Vector2 that will receive the transformed content
  8150. */
  8151. RenderablePrim2D.prototype.transformPointWithOriginByRef = function (p, originOffset, res) {
  8152. var actualSize = this.actualSize;
  8153. res.x = p.x - ((this.origin.x + (originOffset ? originOffset.x : 0)) * actualSize.width);
  8154. res.y = p.y - ((this.origin.y + (originOffset ? originOffset.y : 0)) * actualSize.height);
  8155. };
  8156. RenderablePrim2D.prototype.transformPointWithOriginToRef = function (p, originOffset, res) {
  8157. this.transformPointWithOriginByRef(p, originOffset, res);
  8158. return res;
  8159. };
  8160. /**
  8161. * Get the info for a given effect based on the dataPart metadata
  8162. * @param dataPartId partId in part list to get the info
  8163. * @param vertexBufferAttributes vertex buffer attributes to manually add
  8164. * @param uniforms uniforms to manually add
  8165. * @param useInstanced specified if Instanced Array should be used, if null the engine caps will be used (so true if WebGL supports it, false otherwise), but you have the possibility to override the engine capability. However, if you manually set true but the engine does not support Instanced Array, this method will return null
  8166. */
  8167. RenderablePrim2D.prototype.getDataPartEffectInfo = function (dataPartId, vertexBufferAttributes, uniforms, useInstanced) {
  8168. if (uniforms === void 0) { uniforms = null; }
  8169. if (useInstanced === void 0) { useInstanced = null; }
  8170. var dataPart = BABYLON.Tools.first(this._instanceDataParts, function (i) { return i.id === dataPartId; });
  8171. if (!dataPart) {
  8172. return null;
  8173. }
  8174. var instancedArray = this.owner.supportInstancedArray;
  8175. if (useInstanced != null) {
  8176. // Check if the caller ask for Instanced Array and the engine does not support it, return null if it's the case
  8177. if (useInstanced && instancedArray === false) {
  8178. return null;
  8179. }
  8180. // Use the caller's setting
  8181. instancedArray = useInstanced;
  8182. }
  8183. var cti = dataPart.getClassTreeInfo();
  8184. var categories = this.getUsedShaderCategories(dataPart);
  8185. var att = cti.classContent.getShaderAttributes(categories);
  8186. var defines = "";
  8187. categories.forEach(function (c) { defines += "#define " + c + "\n"; });
  8188. if (instancedArray) {
  8189. defines += "#define Instanced\n";
  8190. }
  8191. return {
  8192. attributes: instancedArray ? vertexBufferAttributes.concat(att) : vertexBufferAttributes,
  8193. uniforms: instancedArray ? (uniforms != null ? uniforms : []) : ((uniforms != null) ? att.concat(uniforms) : (att != null ? att : [])),
  8194. defines: defines
  8195. };
  8196. };
  8197. Object.defineProperty(RenderablePrim2D.prototype, "modelRenderCache", {
  8198. get: function () {
  8199. return this._modelRenderCache;
  8200. },
  8201. enumerable: true,
  8202. configurable: true
  8203. });
  8204. RenderablePrim2D.prototype.createModelRenderCache = function (modelKey) {
  8205. return null;
  8206. };
  8207. RenderablePrim2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  8208. };
  8209. RenderablePrim2D.prototype.createInstanceDataParts = function () {
  8210. return null;
  8211. };
  8212. RenderablePrim2D.prototype.getUsedShaderCategories = function (dataPart) {
  8213. return [];
  8214. };
  8215. RenderablePrim2D.prototype.beforeRefreshForLayoutConstruction = function (part) {
  8216. };
  8217. RenderablePrim2D.prototype.afterRefreshForLayoutConstruction = function (part, obj) {
  8218. };
  8219. RenderablePrim2D.prototype.applyActualScaleOnTransform = function () {
  8220. return true;
  8221. };
  8222. RenderablePrim2D.prototype.refreshInstanceDataPart = function (part) {
  8223. if (!this.isVisible) {
  8224. return false;
  8225. }
  8226. part.isVisible = this.isVisible;
  8227. // Which means, if there's only one data element, we're update it from this method, otherwise it is the responsibility of the derived class to call updateInstanceDataPart as many times as needed, properly (look at Text2D's implementation for more information)
  8228. if (part.dataElementCount === 1) {
  8229. part.curElement = 0;
  8230. this.updateInstanceDataPart(part);
  8231. }
  8232. return true;
  8233. };
  8234. /**
  8235. * Update the instanceDataBase level properties of a part
  8236. * @param part the part to update
  8237. * @param positionOffset to use in multi part per primitive (e.g. the Text2D has N parts for N letter to display), this give the offset to apply (e.g. the position of the letter from the bottom/left corner of the text).
  8238. */
  8239. RenderablePrim2D.prototype.updateInstanceDataPart = function (part, positionOffset) {
  8240. if (positionOffset === void 0) { positionOffset = null; }
  8241. var t = this._globalTransform.multiply(this.renderGroup.invGlobalTransform); // Compute the transformation into the renderGroup's space
  8242. var rgScale = this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagDontInheritParentScale) ? RenderablePrim2D_1._uV : this.renderGroup.actualScale; // We still need to apply the scale of the renderGroup to our rendering, so get it.
  8243. var size = this.renderGroup.viewportSize;
  8244. var zBias = this.actualZOffset;
  8245. var offX = 0;
  8246. var offY = 0;
  8247. // If there's an offset, apply the global transformation matrix on it to get a global offset
  8248. if (positionOffset) {
  8249. offX = positionOffset.x * t.m[0] + positionOffset.y * t.m[4];
  8250. offY = positionOffset.x * t.m[1] + positionOffset.y * t.m[5];
  8251. }
  8252. // Have to convert the coordinates to clip space which is ranged between [-1;1] on X and Y axis, with 0,0 being the left/bottom corner
  8253. // Current coordinates are expressed in renderGroup coordinates ([0, renderGroup.actualSize.width|height]) with 0,0 being at the left/top corner
  8254. // So for X:
  8255. // - tx.x = value * 2 / width: is to switch from [0, renderGroup.width] to [0, 2]
  8256. // - tx.w = (value * 2 / width) - 1: w stores the translation in renderGroup coordinates so (value * 2 / width) to switch to a clip space translation value. - 1 is to offset the overall [0;2] to [-1;1].
  8257. // At last we don't forget to apply the actualScale of the Render Group to tx[0] and ty[1] to propagate scaling correctly
  8258. var w = size.width;
  8259. var h = size.height;
  8260. var invZBias = 1 / zBias;
  8261. var tx = new BABYLON.Vector4(t.m[0] * rgScale.x * 2 /* / w*/, t.m[4] * rgScale.x * 2 /* / w*/, 0 /*t.m[8]*/, ((t.m[12] + offX) * rgScale.x * 2 / w) - 1);
  8262. var ty = new BABYLON.Vector4(t.m[1] * rgScale.y * 2 /* / h*/, t.m[5] * rgScale.y * 2 /* / h*/, 0 /*t.m[9]*/, ((t.m[13] + offY) * rgScale.y * 2 / h) - 1);
  8263. if (!this.applyActualScaleOnTransform()) {
  8264. t.m[0] = tx.x, t.m[4] = tx.y, t.m[12] = tx.w;
  8265. t.m[1] = ty.x, t.m[5] = ty.y, t.m[13] = ty.w;
  8266. var las = this.actualScale;
  8267. t.decompose(RenderablePrim2D_1._s, RenderablePrim2D_1._r, RenderablePrim2D_1._t);
  8268. var scale = new BABYLON.Vector3(RenderablePrim2D_1._s.x / las.x, RenderablePrim2D_1._s.y / las.y, 1);
  8269. t = BABYLON.Matrix.Compose(scale, RenderablePrim2D_1._r, RenderablePrim2D_1._t);
  8270. tx = new BABYLON.Vector4(t.m[0], t.m[4], 0, t.m[12]);
  8271. ty = new BABYLON.Vector4(t.m[1], t.m[5], 0, t.m[13]);
  8272. }
  8273. tx.x /= w;
  8274. tx.y /= w;
  8275. ty.x /= h;
  8276. ty.y /= h;
  8277. part.transformX = tx;
  8278. part.transformY = ty;
  8279. part.opacity = this.actualOpacity;
  8280. // Stores zBias and it's inverse value because that's needed to compute the clip space W coordinate (which is 1/Z, so 1/zBias)
  8281. part.zBias = new BABYLON.Vector2(zBias, invZBias);
  8282. };
  8283. RenderablePrim2D.prototype._updateRenderMode = function () {
  8284. if (this.isTransparent) {
  8285. this._renderMode = BABYLON.Render2DContext.RenderModeTransparent;
  8286. }
  8287. else if (this.isAlphaTest) {
  8288. this._renderMode = BABYLON.Render2DContext.RenderModeAlphaTest;
  8289. }
  8290. else {
  8291. this._renderMode = BABYLON.Render2DContext.RenderModeOpaque;
  8292. }
  8293. };
  8294. return RenderablePrim2D;
  8295. }(BABYLON.Prim2DBase));
  8296. RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT = BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 5;
  8297. RenderablePrim2D._uV = new BABYLON.Vector2(1, 1);
  8298. RenderablePrim2D._s = BABYLON.Vector3.Zero();
  8299. RenderablePrim2D._r = BABYLON.Quaternion.Identity();
  8300. RenderablePrim2D._t = BABYLON.Vector3.Zero();
  8301. RenderablePrim2D._uV3 = new BABYLON.Vector3(1, 1, 1);
  8302. __decorate([
  8303. BABYLON.dynamicLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 0, function (pi) { return RenderablePrim2D_1.isAlphaTestProperty = pi; })
  8304. ], RenderablePrim2D.prototype, "isAlphaTest", null);
  8305. __decorate([
  8306. BABYLON.dynamicLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 1, function (pi) { return RenderablePrim2D_1.isTransparentProperty = pi; })
  8307. ], RenderablePrim2D.prototype, "isTransparent", null);
  8308. RenderablePrim2D = RenderablePrim2D_1 = __decorate([
  8309. BABYLON.className("RenderablePrim2D", "BABYLON")
  8310. ], RenderablePrim2D);
  8311. BABYLON.RenderablePrim2D = RenderablePrim2D;
  8312. var RenderablePrim2D_1;
  8313. })(BABYLON || (BABYLON = {}));
  8314. //# sourceMappingURL=babylon.renderablePrim2d.js.map
  8315. var __extends = (this && this.__extends) || function (d, b) {
  8316. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  8317. function __() { this.constructor = d; }
  8318. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8319. };
  8320. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  8321. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  8322. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  8323. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  8324. return c > 3 && r && Object.defineProperty(target, key, r), r;
  8325. };
  8326. var BABYLON;
  8327. (function (BABYLON) {
  8328. var Shape2D = Shape2D_1 = (function (_super) {
  8329. __extends(Shape2D, _super);
  8330. function Shape2D(settings) {
  8331. var _this = _super.call(this, settings) || this;
  8332. if (!settings) {
  8333. settings = {};
  8334. }
  8335. var borderBrush = null;
  8336. if (settings.border) {
  8337. if (typeof (settings.border) === "string") {
  8338. borderBrush = BABYLON.Canvas2D.GetBrushFromString(settings.border);
  8339. }
  8340. else {
  8341. borderBrush = settings.border;
  8342. }
  8343. }
  8344. var fillBrush = null;
  8345. if (settings.fill) {
  8346. if (typeof (settings.fill) === "string") {
  8347. fillBrush = BABYLON.Canvas2D.GetBrushFromString(settings.fill);
  8348. }
  8349. else {
  8350. fillBrush = settings.fill;
  8351. }
  8352. }
  8353. _this._isTransparent = false;
  8354. _this._oldTransparent = false;
  8355. _this.border = borderBrush;
  8356. _this.fill = fillBrush;
  8357. _this._updateTransparencyStatus();
  8358. _this.borderThickness = settings.borderThickness;
  8359. return _this;
  8360. }
  8361. Object.defineProperty(Shape2D.prototype, "border", {
  8362. get: function () {
  8363. return this._border;
  8364. },
  8365. set: function (value) {
  8366. this._border = value;
  8367. this._updateTransparencyStatus();
  8368. },
  8369. enumerable: true,
  8370. configurable: true
  8371. });
  8372. Object.defineProperty(Shape2D.prototype, "fill", {
  8373. /**
  8374. * Get/set the brush to render the Fill part of the Primitive
  8375. */
  8376. get: function () {
  8377. return this._fill;
  8378. },
  8379. set: function (value) {
  8380. this._fill = value;
  8381. this._updateTransparencyStatus();
  8382. },
  8383. enumerable: true,
  8384. configurable: true
  8385. });
  8386. Object.defineProperty(Shape2D.prototype, "borderThickness", {
  8387. get: function () {
  8388. return this._borderThickness;
  8389. },
  8390. set: function (value) {
  8391. this._borderThickness = value;
  8392. },
  8393. enumerable: true,
  8394. configurable: true
  8395. });
  8396. Shape2D.prototype.getUsedShaderCategories = function (dataPart) {
  8397. var cat = _super.prototype.getUsedShaderCategories.call(this, dataPart);
  8398. // Fill Part
  8399. if (dataPart.id === Shape2D_1.SHAPE2D_FILLPARTID) {
  8400. var fill = this.fill;
  8401. if (fill instanceof BABYLON.SolidColorBrush2D) {
  8402. cat.push(Shape2D_1.SHAPE2D_CATEGORY_FILLSOLID);
  8403. }
  8404. if (fill instanceof BABYLON.GradientColorBrush2D) {
  8405. cat.push(Shape2D_1.SHAPE2D_CATEGORY_FILLGRADIENT);
  8406. }
  8407. }
  8408. // Border Part
  8409. if (dataPart.id === Shape2D_1.SHAPE2D_BORDERPARTID) {
  8410. cat.push(Shape2D_1.SHAPE2D_CATEGORY_BORDER);
  8411. var border = this.border;
  8412. if (border instanceof BABYLON.SolidColorBrush2D) {
  8413. cat.push(Shape2D_1.SHAPE2D_CATEGORY_BORDERSOLID);
  8414. }
  8415. if (border instanceof BABYLON.GradientColorBrush2D) {
  8416. cat.push(Shape2D_1.SHAPE2D_CATEGORY_BORDERGRADIENT);
  8417. }
  8418. }
  8419. return cat;
  8420. };
  8421. Shape2D.prototype.applyActualScaleOnTransform = function () {
  8422. return false;
  8423. };
  8424. Shape2D.prototype.refreshInstanceDataPart = function (part) {
  8425. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  8426. return false;
  8427. }
  8428. // Fill Part
  8429. if (part.id === Shape2D_1.SHAPE2D_FILLPARTID) {
  8430. var d = part;
  8431. if (this.fill) {
  8432. var fill = this.fill;
  8433. if (fill instanceof BABYLON.SolidColorBrush2D) {
  8434. d.fillSolidColor = fill.color;
  8435. }
  8436. else if (fill instanceof BABYLON.GradientColorBrush2D) {
  8437. d.fillGradientColor1 = fill.color1;
  8438. d.fillGradientColor2 = fill.color2;
  8439. var t = BABYLON.Matrix.Compose(new BABYLON.Vector3(fill.scale, fill.scale, fill.scale), BABYLON.Quaternion.RotationAxis(new BABYLON.Vector3(0, 0, 1), fill.rotation), new BABYLON.Vector3(fill.translation.x, fill.translation.y, 0));
  8440. var ty = new BABYLON.Vector4(t.m[1], t.m[5], t.m[9], t.m[13]);
  8441. d.fillGradientTY = ty;
  8442. }
  8443. }
  8444. }
  8445. else if (part.id === Shape2D_1.SHAPE2D_BORDERPARTID) {
  8446. var d = part;
  8447. if (this.border) {
  8448. d.borderThickness = this.borderThickness;
  8449. var border = this.border;
  8450. if (border instanceof BABYLON.SolidColorBrush2D) {
  8451. d.borderSolidColor = border.color;
  8452. }
  8453. else if (border instanceof BABYLON.GradientColorBrush2D) {
  8454. d.borderGradientColor1 = border.color1;
  8455. d.borderGradientColor2 = border.color2;
  8456. var t = BABYLON.Matrix.Compose(new BABYLON.Vector3(border.scale, border.scale, border.scale), BABYLON.Quaternion.RotationAxis(new BABYLON.Vector3(0, 0, 1), border.rotation), new BABYLON.Vector3(border.translation.x, border.translation.y, 0));
  8457. var ty = new BABYLON.Vector4(t.m[1], t.m[5], t.m[9], t.m[13]);
  8458. d.borderGradientTY = ty;
  8459. }
  8460. }
  8461. }
  8462. return true;
  8463. };
  8464. Shape2D.prototype._updateTransparencyStatus = function () {
  8465. this._isTransparent = (this._border && this._border.isTransparent()) || (this._fill && this._fill.isTransparent()) || (this.actualOpacity < 1);
  8466. if (this._isTransparent !== this._oldTransparent) {
  8467. this._oldTransparent = this._isTransparent;
  8468. this._updateRenderMode();
  8469. }
  8470. };
  8471. Shape2D.prototype._mustUpdateInstance = function () {
  8472. var res = this._oldTransparent !== this._isTransparent;
  8473. if (res) {
  8474. this._updateRenderMode();
  8475. this._oldTransparent = this._isTransparent;
  8476. }
  8477. return res;
  8478. };
  8479. Shape2D.prototype._isPrimTransparent = function () {
  8480. return this._isTransparent;
  8481. };
  8482. return Shape2D;
  8483. }(BABYLON.RenderablePrim2D));
  8484. Shape2D.SHAPE2D_BORDERPARTID = 1;
  8485. Shape2D.SHAPE2D_FILLPARTID = 2;
  8486. Shape2D.SHAPE2D_CATEGORY_BORDER = "Border";
  8487. Shape2D.SHAPE2D_CATEGORY_BORDERSOLID = "BorderSolid";
  8488. Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT = "BorderGradient";
  8489. Shape2D.SHAPE2D_CATEGORY_FILLSOLID = "FillSolid";
  8490. Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT = "FillGradient";
  8491. Shape2D.SHAPE2D_PROPCOUNT = BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 5;
  8492. __decorate([
  8493. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 1, function (pi) { return Shape2D_1.borderProperty = pi; }, true)
  8494. ], Shape2D.prototype, "border", null);
  8495. __decorate([
  8496. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 2, function (pi) { return Shape2D_1.fillProperty = pi; }, true)
  8497. ], Shape2D.prototype, "fill", null);
  8498. __decorate([
  8499. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 3, function (pi) { return Shape2D_1.borderThicknessProperty = pi; })
  8500. ], Shape2D.prototype, "borderThickness", null);
  8501. Shape2D = Shape2D_1 = __decorate([
  8502. BABYLON.className("Shape2D", "BABYLON")
  8503. ], Shape2D);
  8504. BABYLON.Shape2D = Shape2D;
  8505. var Shape2DInstanceData = (function (_super) {
  8506. __extends(Shape2DInstanceData, _super);
  8507. function Shape2DInstanceData() {
  8508. return _super.apply(this, arguments) || this;
  8509. }
  8510. Object.defineProperty(Shape2DInstanceData.prototype, "fillSolidColor", {
  8511. // FILL ATTRIBUTES
  8512. get: function () {
  8513. return null;
  8514. },
  8515. set: function (value) {
  8516. },
  8517. enumerable: true,
  8518. configurable: true
  8519. });
  8520. Object.defineProperty(Shape2DInstanceData.prototype, "fillGradientColor1", {
  8521. get: function () {
  8522. return null;
  8523. },
  8524. set: function (value) {
  8525. },
  8526. enumerable: true,
  8527. configurable: true
  8528. });
  8529. Object.defineProperty(Shape2DInstanceData.prototype, "fillGradientColor2", {
  8530. get: function () {
  8531. return null;
  8532. },
  8533. set: function (value) {
  8534. },
  8535. enumerable: true,
  8536. configurable: true
  8537. });
  8538. Object.defineProperty(Shape2DInstanceData.prototype, "fillGradientTY", {
  8539. get: function () {
  8540. return null;
  8541. },
  8542. set: function (value) {
  8543. },
  8544. enumerable: true,
  8545. configurable: true
  8546. });
  8547. Object.defineProperty(Shape2DInstanceData.prototype, "borderThickness", {
  8548. // BORDER ATTRIBUTES
  8549. get: function () {
  8550. return null;
  8551. },
  8552. set: function (value) {
  8553. },
  8554. enumerable: true,
  8555. configurable: true
  8556. });
  8557. Object.defineProperty(Shape2DInstanceData.prototype, "borderSolidColor", {
  8558. get: function () {
  8559. return null;
  8560. },
  8561. set: function (value) {
  8562. },
  8563. enumerable: true,
  8564. configurable: true
  8565. });
  8566. Object.defineProperty(Shape2DInstanceData.prototype, "borderGradientColor1", {
  8567. get: function () {
  8568. return null;
  8569. },
  8570. set: function (value) {
  8571. },
  8572. enumerable: true,
  8573. configurable: true
  8574. });
  8575. Object.defineProperty(Shape2DInstanceData.prototype, "borderGradientColor2", {
  8576. get: function () {
  8577. return null;
  8578. },
  8579. set: function (value) {
  8580. },
  8581. enumerable: true,
  8582. configurable: true
  8583. });
  8584. Object.defineProperty(Shape2DInstanceData.prototype, "borderGradientTY", {
  8585. get: function () {
  8586. return null;
  8587. },
  8588. set: function (value) {
  8589. },
  8590. enumerable: true,
  8591. configurable: true
  8592. });
  8593. return Shape2DInstanceData;
  8594. }(BABYLON.InstanceDataBase));
  8595. __decorate([
  8596. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLSOLID)
  8597. ], Shape2DInstanceData.prototype, "fillSolidColor", null);
  8598. __decorate([
  8599. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  8600. ], Shape2DInstanceData.prototype, "fillGradientColor1", null);
  8601. __decorate([
  8602. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  8603. ], Shape2DInstanceData.prototype, "fillGradientColor2", null);
  8604. __decorate([
  8605. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  8606. ], Shape2DInstanceData.prototype, "fillGradientTY", null);
  8607. __decorate([
  8608. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDER)
  8609. ], Shape2DInstanceData.prototype, "borderThickness", null);
  8610. __decorate([
  8611. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERSOLID)
  8612. ], Shape2DInstanceData.prototype, "borderSolidColor", null);
  8613. __decorate([
  8614. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT)
  8615. ], Shape2DInstanceData.prototype, "borderGradientColor1", null);
  8616. __decorate([
  8617. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT)
  8618. ], Shape2DInstanceData.prototype, "borderGradientColor2", null);
  8619. __decorate([
  8620. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT)
  8621. ], Shape2DInstanceData.prototype, "borderGradientTY", null);
  8622. BABYLON.Shape2DInstanceData = Shape2DInstanceData;
  8623. var Shape2D_1;
  8624. })(BABYLON || (BABYLON = {}));
  8625. //# sourceMappingURL=babylon.shape2d.js.map
  8626. var __extends = (this && this.__extends) || function (d, b) {
  8627. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  8628. function __() { this.constructor = d; }
  8629. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8630. };
  8631. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  8632. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  8633. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  8634. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  8635. return c > 3 && r && Object.defineProperty(target, key, r), r;
  8636. };
  8637. var BABYLON;
  8638. (function (BABYLON) {
  8639. var Group2D = Group2D_1 = (function (_super) {
  8640. __extends(Group2D, _super);
  8641. /**
  8642. * Create an Logical or Renderable Group.
  8643. * @param settings a combination of settings, possible ones are
  8644. * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
  8645. * - children: an array of direct children
  8646. * - id a text identifier, for information purpose
  8647. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  8648. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  8649. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  8650. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  8651. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  8652. * - zOrder: override the zOrder with the specified value
  8653. * - origin: define the normalized origin point location, default [0.5;0.5]
  8654. * - size: the size of the group. Alternatively the width and height properties can be set. If null the size will be computed from its content, default is null.
  8655. * - cacheBehavior: Define how the group should behave regarding the Canvas's cache strategy, default is Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY
  8656. * - layoutEngine: either an instance of a layout engine based class (StackPanel.Vertical, StackPanel.Horizontal) or a string ('canvas' for Canvas layout, 'StackPanel' or 'HorizontalStackPanel' for horizontal Stack Panel layout, 'VerticalStackPanel' for vertical Stack Panel layout).
  8657. * - isVisible: true if the group must be visible, false for hidden. Default is true.
  8658. * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
  8659. * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
  8660. * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
  8661. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8662. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8663. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8664. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8665. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  8666. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  8667. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  8668. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  8669. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8670. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8671. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8672. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8673. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  8674. */
  8675. function Group2D(settings) {
  8676. var _this;
  8677. if (settings == null) {
  8678. settings = {};
  8679. }
  8680. if (settings.origin == null) {
  8681. settings.origin = new BABYLON.Vector2(0, 0);
  8682. }
  8683. _this = _super.call(this, settings) || this;
  8684. var size = (!settings.size && !settings.width && !settings.height) ? null : (settings.size || (new BABYLON.Size(settings.width || 0, settings.height || 0)));
  8685. _this._trackedNode = (settings.trackNode == null) ? null : settings.trackNode;
  8686. if (_this._trackedNode && _this.owner) {
  8687. _this.owner._registerTrackedNode(_this);
  8688. }
  8689. _this._cacheBehavior = (settings.cacheBehavior == null) ? Group2D_1.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY : settings.cacheBehavior;
  8690. var rd = _this._renderableData;
  8691. if (rd) {
  8692. rd._noResizeOnScale = (_this.cacheBehavior & Group2D_1.GROUPCACHEBEHAVIOR_NORESIZEONSCALE) !== 0;
  8693. }
  8694. _this.size = size;
  8695. _this._viewportPosition = BABYLON.Vector2.Zero();
  8696. _this._viewportSize = BABYLON.Size.Zero();
  8697. return _this;
  8698. }
  8699. Group2D._createCachedCanvasGroup = function (owner) {
  8700. var g = new Group2D_1({ parent: owner, id: "__cachedCanvasGroup__", position: BABYLON.Vector2.Zero(), origin: BABYLON.Vector2.Zero(), size: null, isVisible: true, isPickable: false, dontInheritParentScale: true });
  8701. return g;
  8702. };
  8703. Group2D.prototype.applyCachedTexture = function (vertexData, material) {
  8704. this._bindCacheTarget();
  8705. if (vertexData) {
  8706. var uv = vertexData.uvs;
  8707. var nodeuv = this._renderableData._cacheNodeUVs;
  8708. for (var i = 0; i < 4; i++) {
  8709. uv[i * 2 + 0] = nodeuv[i].x;
  8710. uv[i * 2 + 1] = nodeuv[i].y;
  8711. }
  8712. }
  8713. if (material) {
  8714. material.diffuseTexture = this._renderableData._cacheTexture;
  8715. material.emissiveColor = new BABYLON.Color3(1, 1, 1);
  8716. }
  8717. this._renderableData._cacheTexture.hasAlpha = true;
  8718. this._unbindCacheTarget();
  8719. };
  8720. Object.defineProperty(Group2D.prototype, "cachedRect", {
  8721. /**
  8722. * Allow you to access the information regarding the cached rectangle of the Group2D into the MapTexture.
  8723. * If the `noWorldSpaceNode` options was used at the creation of a WorldSpaceCanvas, the rendering of the canvas must be made by the caller, so typically you want to bind the cacheTexture property to some material/mesh and you MUST use the Group2D.cachedUVs property to get the UV coordinates to use for your quad that will display the Canvas and NOT the PackedRect.UVs property which are incorrect because the allocated surface may be bigger (due to over-provisioning or shrinking without deallocating) than what the Group is actually using.
  8724. */
  8725. get: function () {
  8726. if (!this._renderableData) {
  8727. return null;
  8728. }
  8729. return this._renderableData._cacheNode;
  8730. },
  8731. enumerable: true,
  8732. configurable: true
  8733. });
  8734. Object.defineProperty(Group2D.prototype, "cachedUVs", {
  8735. /**
  8736. * The UVs into the MapTexture that map the cached group
  8737. */
  8738. get: function () {
  8739. if (!this._renderableData) {
  8740. return null;
  8741. }
  8742. return this._renderableData._cacheNodeUVs;
  8743. },
  8744. enumerable: true,
  8745. configurable: true
  8746. });
  8747. Object.defineProperty(Group2D.prototype, "cachedUVsChanged", {
  8748. get: function () {
  8749. if (!this._renderableData) {
  8750. return null;
  8751. }
  8752. if (!this._renderableData._cacheNodeUVsChangedObservable) {
  8753. this._renderableData._cacheNodeUVsChangedObservable = new BABYLON.Observable();
  8754. }
  8755. return this._renderableData._cacheNodeUVsChangedObservable;
  8756. },
  8757. enumerable: true,
  8758. configurable: true
  8759. });
  8760. Object.defineProperty(Group2D.prototype, "cacheTexture", {
  8761. /**
  8762. * Access the texture that maintains a cached version of the Group2D.
  8763. * This is useful only if you're not using a WorldSpaceNode for your WorldSpace Canvas and therefore need to perform the rendering yourself.
  8764. */
  8765. get: function () {
  8766. if (!this._renderableData) {
  8767. return null;
  8768. }
  8769. return this._renderableData._cacheTexture;
  8770. },
  8771. enumerable: true,
  8772. configurable: true
  8773. });
  8774. /**
  8775. * Call this method to remove this Group and its children from the Canvas
  8776. */
  8777. Group2D.prototype.dispose = function () {
  8778. if (!_super.prototype.dispose.call(this)) {
  8779. return false;
  8780. }
  8781. if (this._trackedNode != null) {
  8782. this.owner._unregisterTrackedNode(this);
  8783. this._trackedNode = null;
  8784. }
  8785. if (this._renderableData) {
  8786. this._renderableData.dispose(this.owner);
  8787. this._renderableData = null;
  8788. }
  8789. return true;
  8790. };
  8791. Object.defineProperty(Group2D.prototype, "isRenderableGroup", {
  8792. /**
  8793. * @returns Returns true if the Group render content, false if it's a logical group only
  8794. */
  8795. get: function () {
  8796. return this._isRenderableGroup;
  8797. },
  8798. enumerable: true,
  8799. configurable: true
  8800. });
  8801. Object.defineProperty(Group2D.prototype, "isCachedGroup", {
  8802. /**
  8803. * @returns only meaningful for isRenderableGroup, will be true if the content of the Group is cached into a texture, false if it's rendered every time
  8804. */
  8805. get: function () {
  8806. return this._isCachedGroup;
  8807. },
  8808. enumerable: true,
  8809. configurable: true
  8810. });
  8811. Object.defineProperty(Group2D.prototype, "size", {
  8812. get: function () {
  8813. return this._size;
  8814. },
  8815. /**
  8816. * Get/Set the size of the group. If null the size of the group will be determine from its content.
  8817. * BEWARE: if the Group is a RenderableGroup and its content is cache the texture will be resized each time the group is getting bigger. For performance reason the opposite won't be true: the texture won't shrink if the group does.
  8818. */
  8819. set: function (val) {
  8820. this._size = val;
  8821. },
  8822. enumerable: true,
  8823. configurable: true
  8824. });
  8825. Object.defineProperty(Group2D.prototype, "viewportSize", {
  8826. get: function () {
  8827. return this._viewportSize;
  8828. },
  8829. enumerable: true,
  8830. configurable: true
  8831. });
  8832. Object.defineProperty(Group2D.prototype, "actualSize", {
  8833. get: function () {
  8834. // The computed size will be floor on both width and height
  8835. var actualSize;
  8836. // Return the actualSize if set
  8837. if (this._actualSize) {
  8838. return this._actualSize;
  8839. }
  8840. // Return the size if set by the user
  8841. if (this._size) {
  8842. actualSize = new BABYLON.Size(Math.ceil(this._size.width), Math.ceil(this._size.height));
  8843. }
  8844. else {
  8845. var m = this.layoutBoundingInfo.max();
  8846. actualSize = new BABYLON.Size(Math.ceil(m.x), Math.ceil(m.y));
  8847. }
  8848. // Compare the size with the one we previously had, if it differs we set the property dirty and trigger a GroupChanged to synchronize a displaySprite (if any)
  8849. if (!actualSize.equals(this._actualSize)) {
  8850. this.onPrimitivePropertyDirty(Group2D_1.actualSizeProperty.flagId);
  8851. this._actualSize = actualSize;
  8852. this.handleGroupChanged(Group2D_1.actualSizeProperty);
  8853. }
  8854. return actualSize;
  8855. },
  8856. set: function (value) {
  8857. this._actualSize = value;
  8858. },
  8859. enumerable: true,
  8860. configurable: true
  8861. });
  8862. Object.defineProperty(Group2D.prototype, "cacheBehavior", {
  8863. /**
  8864. * Get/set the Cache Behavior, used in case the Canvas Cache Strategy is set to CACHESTRATEGY_ALLGROUPS. Can be either GROUPCACHEBEHAVIOR_CACHEINPARENTGROUP, GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE or GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY. See their documentation for more information.
  8865. * GROUPCACHEBEHAVIOR_NORESIZEONSCALE can also be set if you set it at creation time.
  8866. * It is critical to understand than you HAVE TO play with this behavior in order to achieve a good performance/memory ratio. Caching all groups would certainly be the worst strategy of all.
  8867. */
  8868. get: function () {
  8869. return this._cacheBehavior;
  8870. },
  8871. enumerable: true,
  8872. configurable: true
  8873. });
  8874. Group2D.prototype._addPrimToDirtyList = function (prim) {
  8875. this._renderableData._primDirtyList.push(prim);
  8876. };
  8877. Group2D.prototype._renderCachedCanvas = function () {
  8878. this.owner._addGroupRenderCount(1);
  8879. this.updateCachedStates(true);
  8880. var context = new BABYLON.PrepareRender2DContext();
  8881. this._prepareGroupRender(context);
  8882. this._groupRender();
  8883. };
  8884. Object.defineProperty(Group2D.prototype, "trackedNode", {
  8885. /**
  8886. * Get/set the Scene's Node that should be tracked, the group's position will follow the projected position of the Node.
  8887. */
  8888. get: function () {
  8889. return this._trackedNode;
  8890. },
  8891. set: function (val) {
  8892. if (val != null) {
  8893. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  8894. this.owner._registerTrackedNode(this);
  8895. }
  8896. this._trackedNode = val;
  8897. }
  8898. else {
  8899. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  8900. this.owner._unregisterTrackedNode(this);
  8901. }
  8902. this._trackedNode = null;
  8903. }
  8904. },
  8905. enumerable: true,
  8906. configurable: true
  8907. });
  8908. Group2D.prototype.levelIntersect = function (intersectInfo) {
  8909. // If we've made it so far it means the boundingInfo intersection test succeed, the Group2D is shaped the same, so we always return true
  8910. return true;
  8911. };
  8912. Group2D.prototype.updateLevelBoundingInfo = function () {
  8913. var size;
  8914. // If the size is set by the user, the boundingInfo is computed from this value
  8915. if (this.size) {
  8916. size = this.size;
  8917. }
  8918. else {
  8919. size = new BABYLON.Size(0, 0);
  8920. }
  8921. BABYLON.BoundingInfo2D.CreateFromSizeToRef(size, this._levelBoundingInfo);
  8922. };
  8923. // Method called only on renderable groups to prepare the rendering
  8924. Group2D.prototype._prepareGroupRender = function (context) {
  8925. var sortedDirtyList = null;
  8926. // Update the Global Transformation and visibility status of the changed primitives
  8927. var rd = this._renderableData;
  8928. if ((rd._primDirtyList.length > 0) || context.forceRefreshPrimitive) {
  8929. sortedDirtyList = rd._primDirtyList.sort(function (a, b) { return a.hierarchyDepth - b.hierarchyDepth; });
  8930. this.updateCachedStatesOf(sortedDirtyList, true);
  8931. }
  8932. var s = this.actualSize;
  8933. var a = this.actualScale;
  8934. var sw = Math.ceil(s.width * a.x);
  8935. var sh = Math.ceil(s.height * a.y);
  8936. // The dimension must be overridden when using the designSize feature, the ratio is maintain to compute a uniform scale, which is mandatory but if the designSize's ratio is different from the rendering surface's ratio, content will be clipped in some cases.
  8937. // So we set the width/height to the rendering's one because that's what we want for the viewport!
  8938. if ((this instanceof BABYLON.Canvas2D || this.id === "__cachedCanvasGroup__") && this.owner.designSize != null) {
  8939. sw = this.owner.engine.getRenderWidth();
  8940. sh = this.owner.engine.getRenderHeight();
  8941. }
  8942. // Setup the size of the rendering viewport
  8943. // In non cache mode, we're rendering directly to the rendering canvas, in this case we have to detect if the canvas size changed since the previous iteration, if it's the case all primitives must be prepared again because their transformation must be recompute
  8944. if (!this._isCachedGroup) {
  8945. // Compute the WebGL viewport's location/size
  8946. var t = this._globalTransform.getTranslation();
  8947. var rs = this.owner._renderingSize;
  8948. sh = Math.min(sh, rs.height - t.y);
  8949. sw = Math.min(sw, rs.width - t.x);
  8950. var x = t.x;
  8951. var y = t.y;
  8952. // The viewport where we're rendering must be the size of the canvas if this one fit in the rendering screen or clipped to the screen dimensions if needed
  8953. this._viewportPosition.x = x;
  8954. this._viewportPosition.y = y;
  8955. }
  8956. // For a cachedGroup we also check of the group's actualSize is changing, if it's the case then the rendering zone will be change so we also have to dirty all primitives to prepare them again.
  8957. if (this._viewportSize.width !== sw || this._viewportSize.height !== sh) {
  8958. context.forceRefreshPrimitive = true;
  8959. this._viewportSize.width = sw;
  8960. this._viewportSize.height = sh;
  8961. }
  8962. if ((rd._primDirtyList.length > 0) || context.forceRefreshPrimitive) {
  8963. // If the group is cached, set the dirty flag to true because of the incoming changes
  8964. this._cacheGroupDirty = this._isCachedGroup;
  8965. rd._primNewDirtyList.splice(0);
  8966. // If it's a force refresh, prepare all the children
  8967. if (context.forceRefreshPrimitive) {
  8968. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  8969. var p = _a[_i];
  8970. p._prepareRender(context);
  8971. }
  8972. }
  8973. else {
  8974. // Each primitive that changed at least once was added into the primDirtyList, we have to sort this level using
  8975. // the hierarchyDepth in order to prepare primitives from top to bottom
  8976. if (!sortedDirtyList) {
  8977. sortedDirtyList = rd._primDirtyList.sort(function (a, b) { return a.hierarchyDepth - b.hierarchyDepth; });
  8978. }
  8979. sortedDirtyList.forEach(function (p) {
  8980. // We need to check if prepare is needed because even if the primitive is in the dirtyList, its parent primitive may also have been modified, then prepared, then recurse on its children primitives (this one for instance) if the changes where impacting them.
  8981. // For instance: a Rect's position change, the position of its children primitives will also change so a prepare will be call on them. If a child was in the dirtyList we will avoid a second prepare by making this check.
  8982. if (!p.isDisposed && p._needPrepare()) {
  8983. p._prepareRender(context);
  8984. }
  8985. });
  8986. }
  8987. // Everything is updated, clear the dirty list
  8988. rd._primDirtyList.forEach(function (p) {
  8989. if (rd._primNewDirtyList.indexOf(p) === -1) {
  8990. p._resetPropertiesDirty();
  8991. }
  8992. else {
  8993. p._setFlags(BABYLON.SmartPropertyPrim.flagNeedRefresh);
  8994. }
  8995. });
  8996. rd._primDirtyList.splice(0);
  8997. rd._primDirtyList = rd._primDirtyList.concat(rd._primNewDirtyList);
  8998. }
  8999. // A renderable group has a list of direct children that are also renderable groups, we recurse on them to also prepare them
  9000. rd._childrenRenderableGroups.forEach(function (g) {
  9001. g._prepareGroupRender(context);
  9002. });
  9003. };
  9004. Group2D.prototype._groupRender = function () {
  9005. var _this = this;
  9006. var engine = this.owner.engine;
  9007. var failedCount = 0;
  9008. // First recurse to children render group to render them (in their cache or on screen)
  9009. for (var _i = 0, _a = this._renderableData._childrenRenderableGroups; _i < _a.length; _i++) {
  9010. var childGroup = _a[_i];
  9011. childGroup._groupRender();
  9012. }
  9013. // Render the primitives if needed: either if we don't cache the content or if the content is cached but has changed
  9014. if (!this.isCachedGroup || this._cacheGroupDirty) {
  9015. this.owner._addGroupRenderCount(1);
  9016. if (this.isCachedGroup) {
  9017. this._bindCacheTarget();
  9018. }
  9019. else {
  9020. var curVP = engine.setDirectViewport(this._viewportPosition.x, this._viewportPosition.y, this._viewportSize.width, this._viewportSize.height);
  9021. }
  9022. var curAlphaTest = engine.getAlphaTesting() === true;
  9023. var curDepthWrite = engine.getDepthWrite() === true;
  9024. // ===================================================================
  9025. // First pass, update the InstancedArray and render Opaque primitives
  9026. // Disable Alpha Testing, Enable Depth Write
  9027. engine.setAlphaTesting(false);
  9028. engine.setDepthWrite(true);
  9029. // For each different model of primitive to render
  9030. var context_1 = new BABYLON.Render2DContext(BABYLON.Render2DContext.RenderModeOpaque);
  9031. this._renderableData._renderGroupInstancesInfo.forEach(function (k, v) {
  9032. // Prepare the context object, update the WebGL Instanced Array buffer if needed
  9033. var renderCount = _this._prepareContext(engine, context_1, v);
  9034. // If null is returned, there's no opaque data to render
  9035. if (renderCount === null) {
  9036. return;
  9037. }
  9038. // Submit render only if we have something to render (everything may be hidden and the floatarray empty)
  9039. if (!_this.owner.supportInstancedArray || renderCount > 0) {
  9040. // render all the instances of this model, if the render method returns true then our instances are no longer dirty
  9041. var renderFailed = !v.modelRenderCache.render(v, context_1);
  9042. // Update dirty flag/related
  9043. v.opaqueDirty = renderFailed;
  9044. failedCount += renderFailed ? 1 : 0;
  9045. }
  9046. });
  9047. // =======================================================================
  9048. // Second pass, update the InstancedArray and render AlphaTest primitives
  9049. // Enable Alpha Testing, Enable Depth Write
  9050. engine.setAlphaTesting(true);
  9051. engine.setDepthWrite(true);
  9052. // For each different model of primitive to render
  9053. context_1 = new BABYLON.Render2DContext(BABYLON.Render2DContext.RenderModeAlphaTest);
  9054. this._renderableData._renderGroupInstancesInfo.forEach(function (k, v) {
  9055. // Prepare the context object, update the WebGL Instanced Array buffer if needed
  9056. var renderCount = _this._prepareContext(engine, context_1, v);
  9057. // If null is returned, there's no opaque data to render
  9058. if (renderCount === null) {
  9059. return;
  9060. }
  9061. // Submit render only if we have something to render (everything may be hidden and the floatarray empty)
  9062. if (!_this.owner.supportInstancedArray || renderCount > 0) {
  9063. // render all the instances of this model, if the render method returns true then our instances are no longer dirty
  9064. var renderFailed = !v.modelRenderCache.render(v, context_1);
  9065. // Update dirty flag/related
  9066. v.opaqueDirty = renderFailed;
  9067. failedCount += renderFailed ? 1 : 0;
  9068. }
  9069. });
  9070. // =======================================================================
  9071. // Third pass, transparent primitive rendering
  9072. // Enable Alpha Testing, Disable Depth Write
  9073. engine.setAlphaTesting(true);
  9074. engine.setDepthWrite(false);
  9075. // First Check if the transparent List change so we can update the TransparentSegment and PartData (sort if needed)
  9076. if (this._renderableData._transparentListChanged) {
  9077. this._updateTransparentData();
  9078. }
  9079. // From this point on we have up to date data to render, so let's go
  9080. failedCount += this._renderTransparentData();
  9081. // =======================================================================
  9082. // Unbind target/restore viewport setting, clear dirty flag, and quit
  9083. // The group's content is no longer dirty
  9084. this._cacheGroupDirty = failedCount !== 0;
  9085. if (this.isCachedGroup) {
  9086. this._unbindCacheTarget();
  9087. }
  9088. else {
  9089. if (curVP) {
  9090. engine.setViewport(curVP);
  9091. }
  9092. }
  9093. // Restore saved states
  9094. engine.setAlphaTesting(curAlphaTest);
  9095. engine.setDepthWrite(curDepthWrite);
  9096. }
  9097. };
  9098. Group2D.prototype._setCacheGroupDirty = function () {
  9099. this._cacheGroupDirty = true;
  9100. };
  9101. Group2D.prototype._updateTransparentData = function () {
  9102. this.owner._addUpdateTransparentDataCount(1);
  9103. var rd = this._renderableData;
  9104. // Sort all the primitive from their depth, max (bottom) to min (top)
  9105. rd._transparentPrimitives.sort(function (a, b) { return b._primitive.actualZOffset - a._primitive.actualZOffset; });
  9106. var checkAndAddPrimInSegment = function (seg, tpiI) {
  9107. var tpi = rd._transparentPrimitives[tpiI];
  9108. // Fast rejection: if gii are different
  9109. if (seg.groupInsanceInfo !== tpi._groupInstanceInfo) {
  9110. return false;
  9111. }
  9112. //let tpiZ = tpi._primitive.actualZOffset;
  9113. // We've made it so far, the tpi can be part of the segment, add it
  9114. tpi._transparentSegment = seg;
  9115. tpi._primitive._updateTransparentSegmentIndices(seg);
  9116. return true;
  9117. };
  9118. // Free the existing TransparentSegments
  9119. for (var _i = 0, _a = rd._transparentSegments; _i < _a.length; _i++) {
  9120. var ts = _a[_i];
  9121. ts.dispose(this.owner.engine);
  9122. }
  9123. rd._transparentSegments.splice(0);
  9124. var prevSeg = null;
  9125. for (var tpiI = 0; tpiI < rd._transparentPrimitives.length; tpiI++) {
  9126. var tpi = rd._transparentPrimitives[tpiI];
  9127. // Check if the Data in which the primitive is stored is not sorted properly
  9128. if (tpi._groupInstanceInfo.transparentOrderDirty) {
  9129. tpi._groupInstanceInfo.sortTransparentData();
  9130. }
  9131. // Reset the segment, we have to create/rebuild it
  9132. tpi._transparentSegment = null;
  9133. // If there's a previous valid segment, check if this prim can be part of it
  9134. if (prevSeg) {
  9135. checkAndAddPrimInSegment(prevSeg, tpiI);
  9136. }
  9137. // If we couldn't insert in the adjacent segments, he have to create one
  9138. if (!tpi._transparentSegment) {
  9139. var ts = new BABYLON.TransparentSegment();
  9140. ts.groupInsanceInfo = tpi._groupInstanceInfo;
  9141. var prim = tpi._primitive;
  9142. ts.startZ = prim.actualZOffset;
  9143. prim._updateTransparentSegmentIndices(ts);
  9144. ts.endZ = ts.startZ;
  9145. tpi._transparentSegment = ts;
  9146. rd._transparentSegments.push(ts);
  9147. }
  9148. // Update prevSeg
  9149. prevSeg = tpi._transparentSegment;
  9150. }
  9151. //rd._firstChangedPrim = null;
  9152. rd._transparentListChanged = false;
  9153. };
  9154. Group2D.prototype._renderTransparentData = function () {
  9155. var failedCount = 0;
  9156. var context = new BABYLON.Render2DContext(BABYLON.Render2DContext.RenderModeTransparent);
  9157. var rd = this._renderableData;
  9158. var useInstanced = this.owner.supportInstancedArray;
  9159. var length = rd._transparentSegments.length;
  9160. for (var i = 0; i < length; i++) {
  9161. context.instancedBuffers = null;
  9162. var ts = rd._transparentSegments[i];
  9163. var gii = ts.groupInsanceInfo;
  9164. var mrc = gii.modelRenderCache;
  9165. var engine = this.owner.engine;
  9166. var count = ts.endDataIndex - ts.startDataIndex;
  9167. // Use Instanced Array if it's supported and if there's at least minPartCountToUseInstancedArray prims to draw.
  9168. // We don't want to create an Instanced Buffer for less that minPartCountToUseInstancedArray prims
  9169. if (useInstanced && count >= this.owner.minPartCountToUseInstancedArray) {
  9170. if (!ts.partBuffers) {
  9171. var buffers = new Array();
  9172. for (var j = 0; j < gii.transparentData.length; j++) {
  9173. var gitd = gii.transparentData[j];
  9174. var dfa = gitd._partData;
  9175. var data = dfa.pack();
  9176. var stride = dfa.stride;
  9177. var neededSize = count * stride * 4;
  9178. var buffer = engine.createInstancesBuffer(neededSize); // Create + bind
  9179. var segData = data.subarray(ts.startDataIndex * stride, ts.endDataIndex * stride);
  9180. engine.updateArrayBuffer(segData);
  9181. buffers.push(buffer);
  9182. }
  9183. ts.partBuffers = buffers;
  9184. }
  9185. else if (gii.transparentDirty) {
  9186. for (var j = 0; j < gii.transparentData.length; j++) {
  9187. var gitd = gii.transparentData[j];
  9188. var dfa = gitd._partData;
  9189. var data = dfa.pack();
  9190. var stride = dfa.stride;
  9191. var buffer = ts.partBuffers[j];
  9192. var segData = data.subarray(ts.startDataIndex * stride, ts.endDataIndex * stride);
  9193. engine.bindArrayBuffer(buffer);
  9194. engine.updateArrayBuffer(segData);
  9195. }
  9196. }
  9197. context.useInstancing = true;
  9198. context.instancesCount = count;
  9199. context.instancedBuffers = ts.partBuffers;
  9200. context.groupInfoPartData = gii.transparentData;
  9201. var renderFailed = !mrc.render(gii, context);
  9202. failedCount += renderFailed ? 1 : 0;
  9203. }
  9204. else {
  9205. context.useInstancing = false;
  9206. context.partDataStartIndex = ts.startDataIndex;
  9207. context.partDataEndIndex = ts.endDataIndex;
  9208. context.groupInfoPartData = gii.transparentData;
  9209. var renderFailed = !mrc.render(gii, context);
  9210. failedCount += renderFailed ? 1 : 0;
  9211. }
  9212. }
  9213. return failedCount;
  9214. };
  9215. Group2D.prototype._prepareContext = function (engine, context, gii) {
  9216. var gipd = null;
  9217. var setDirty;
  9218. var getDirty;
  9219. // Render Mode specifics
  9220. switch (context.renderMode) {
  9221. case BABYLON.Render2DContext.RenderModeOpaque:
  9222. {
  9223. if (!gii.hasOpaqueData) {
  9224. return null;
  9225. }
  9226. setDirty = function (dirty) { gii.opaqueDirty = dirty; };
  9227. getDirty = function () { return gii.opaqueDirty; };
  9228. context.groupInfoPartData = gii.opaqueData;
  9229. gipd = gii.opaqueData;
  9230. break;
  9231. }
  9232. case BABYLON.Render2DContext.RenderModeAlphaTest:
  9233. {
  9234. if (!gii.hasAlphaTestData) {
  9235. return null;
  9236. }
  9237. setDirty = function (dirty) { gii.alphaTestDirty = dirty; };
  9238. getDirty = function () { return gii.alphaTestDirty; };
  9239. context.groupInfoPartData = gii.alphaTestData;
  9240. gipd = gii.alphaTestData;
  9241. break;
  9242. }
  9243. default:
  9244. throw new Error("_prepareContext is only for opaque or alphaTest");
  9245. }
  9246. var renderCount = 0;
  9247. // This part will pack the dynamicfloatarray and update the instanced array WebGLBufffer
  9248. // Skip it if instanced arrays are not supported
  9249. if (this.owner.supportInstancedArray) {
  9250. // Flag for instancing
  9251. context.useInstancing = true;
  9252. // Make sure all the WebGLBuffers of the Instanced Array are created/up to date for the parts to render.
  9253. for (var i = 0; i < gipd.length; i++) {
  9254. var pid = gipd[i];
  9255. // If the instances of the model was changed, pack the data
  9256. var array = pid._partData;
  9257. var instanceData_1 = array.pack();
  9258. renderCount += array.usedElementCount;
  9259. // Compute the size the instance buffer should have
  9260. var neededSize = array.usedElementCount * array.stride * 4;
  9261. // Check if we have to (re)create the instancesBuffer because there's none or the size is too small
  9262. if (!pid._partBuffer || (pid._partBufferSize < neededSize)) {
  9263. if (pid._partBuffer) {
  9264. engine.deleteInstancesBuffer(pid._partBuffer);
  9265. }
  9266. pid._partBuffer = engine.createInstancesBuffer(neededSize); // Create + bind
  9267. pid._partBufferSize = neededSize;
  9268. setDirty(false);
  9269. // Update the WebGL buffer to match the new content of the instances data
  9270. engine.updateArrayBuffer(instanceData_1);
  9271. }
  9272. else if (getDirty()) {
  9273. // Update the WebGL buffer to match the new content of the instances data
  9274. engine.bindArrayBuffer(pid._partBuffer);
  9275. engine.updateArrayBuffer(instanceData_1);
  9276. }
  9277. }
  9278. setDirty(false);
  9279. }
  9280. else {
  9281. context.partDataStartIndex = 0;
  9282. // Find the first valid object to get the count
  9283. if (context.groupInfoPartData.length > 0) {
  9284. var i = 0;
  9285. while (!context.groupInfoPartData[i]) {
  9286. i++;
  9287. }
  9288. context.partDataEndIndex = context.groupInfoPartData[i]._partData.usedElementCount;
  9289. }
  9290. }
  9291. return renderCount;
  9292. };
  9293. Group2D.prototype._setRenderingScale = function (scale) {
  9294. if (this._renderableData._renderingScale === scale) {
  9295. return;
  9296. }
  9297. this._renderableData._renderingScale = scale;
  9298. };
  9299. Group2D.prototype._bindCacheTarget = function () {
  9300. var curWidth;
  9301. var curHeight;
  9302. var rd = this._renderableData;
  9303. var rs = rd._renderingScale;
  9304. var noResizeScale = rd._noResizeOnScale;
  9305. var isCanvas = this.parent == null;
  9306. var scale;
  9307. if (noResizeScale) {
  9308. scale = isCanvas ? Group2D_1._uV : this.parent.actualScale;
  9309. }
  9310. else {
  9311. scale = this.actualScale;
  9312. }
  9313. if (isCanvas && this.owner.cachingStrategy === BABYLON.Canvas2D.CACHESTRATEGY_CANVAS && this.owner.isScreenSpace) {
  9314. if (this.owner.designSize || this.owner.fitRenderingDevice) {
  9315. Group2D_1._s.width = this.owner.engine.getRenderWidth();
  9316. Group2D_1._s.height = this.owner.engine.getRenderHeight();
  9317. }
  9318. else {
  9319. Group2D_1._s.copyFrom(this.owner.size);
  9320. }
  9321. }
  9322. else {
  9323. Group2D_1._s.width = Math.ceil(this.actualSize.width * scale.x * rs);
  9324. Group2D_1._s.height = Math.ceil(this.actualSize.height * scale.y * rs);
  9325. }
  9326. var sizeChanged = !Group2D_1._s.equals(rd._cacheSize);
  9327. if (rd._cacheNode) {
  9328. var size = rd._cacheNode.contentSize;
  9329. // Check if we have to deallocate because the size is too small
  9330. if ((size.width < Group2D_1._s.width) || (size.height < Group2D_1._s.height)) {
  9331. // For Screen space: over-provisioning of 7% more to avoid frequent resizing for few pixels...
  9332. // For World space: no over-provisioning
  9333. var overprovisioning = this.owner.isScreenSpace ? 1.07 : 1;
  9334. curWidth = Math.floor(Group2D_1._s.width * overprovisioning);
  9335. curHeight = Math.floor(Group2D_1._s.height * overprovisioning);
  9336. //console.log(`[${this._globalTransformProcessStep}] Resize group ${this.id}, width: ${curWidth}, height: ${curHeight}`);
  9337. rd._cacheTexture.freeRect(rd._cacheNode);
  9338. rd._cacheNode = null;
  9339. }
  9340. }
  9341. if (!rd._cacheNode) {
  9342. // Check if we have to allocate a rendering zone in the global cache texture
  9343. var res = this.owner._allocateGroupCache(this, this.parent && this.parent.renderGroup, curWidth ? new BABYLON.Size(curWidth, curHeight) : null, rd._useMipMap, rd._anisotropicLevel);
  9344. rd._cacheNode = res.node;
  9345. rd._cacheTexture = res.texture;
  9346. if (rd._cacheRenderSprite) {
  9347. rd._cacheRenderSprite.dispose();
  9348. }
  9349. rd._cacheRenderSprite = res.sprite;
  9350. sizeChanged = true;
  9351. }
  9352. if (sizeChanged) {
  9353. rd._cacheSize.copyFrom(Group2D_1._s);
  9354. rd._cacheNodeUVs = rd._cacheNode.getUVsForCustomSize(rd._cacheSize);
  9355. if (rd._cacheNodeUVsChangedObservable && rd._cacheNodeUVsChangedObservable.hasObservers()) {
  9356. rd._cacheNodeUVsChangedObservable.notifyObservers(rd._cacheNodeUVs);
  9357. }
  9358. this._setFlags(BABYLON.SmartPropertyPrim.flagWorldCacheChanged);
  9359. }
  9360. var n = rd._cacheNode;
  9361. rd._cacheTexture.bindTextureForPosSize(n.pos, Group2D_1._s, true);
  9362. };
  9363. Group2D.prototype._unbindCacheTarget = function () {
  9364. if (this._renderableData._cacheTexture) {
  9365. this._renderableData._cacheTexture.unbindTexture();
  9366. }
  9367. };
  9368. Group2D.prototype._spreadActualScaleDirty = function () {
  9369. if (this._renderableData && this._renderableData._cacheRenderSprite) {
  9370. this.handleGroupChanged(BABYLON.Prim2DBase.actualScaleProperty);
  9371. }
  9372. _super.prototype._spreadActualScaleDirty.call(this);
  9373. };
  9374. Group2D.prototype.handleGroupChanged = function (prop) {
  9375. // This method is only for cachedGroup
  9376. var rd = this._renderableData;
  9377. if (!rd) {
  9378. return;
  9379. }
  9380. var cachedSprite = rd._cacheRenderSprite;
  9381. if (!this.isCachedGroup || !cachedSprite) {
  9382. return;
  9383. }
  9384. // For now we only support these property changes
  9385. // TODO: add more! :)
  9386. switch (prop.id) {
  9387. case BABYLON.Prim2DBase.actualPositionProperty.id:
  9388. cachedSprite.actualPosition = this.actualPosition.clone();
  9389. if (cachedSprite.position != null) {
  9390. cachedSprite.position = cachedSprite.actualPosition.clone();
  9391. }
  9392. break;
  9393. case BABYLON.Prim2DBase.rotationProperty.id:
  9394. cachedSprite.rotation = this.rotation;
  9395. break;
  9396. case BABYLON.Prim2DBase.scaleProperty.id:
  9397. cachedSprite.scale = this.scale;
  9398. break;
  9399. case BABYLON.Prim2DBase.originProperty.id:
  9400. cachedSprite.origin = this.origin.clone();
  9401. break;
  9402. case Group2D_1.actualSizeProperty.id:
  9403. cachedSprite.size = this.actualSize.clone();
  9404. break;
  9405. }
  9406. };
  9407. Group2D.prototype.detectGroupStates = function () {
  9408. var isCanvas = this instanceof BABYLON.Canvas2D;
  9409. var canvasStrat = this.owner.cachingStrategy;
  9410. // In Don't Cache mode, only the canvas is renderable, all the other groups are logical. There are not a single cached group.
  9411. if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_DONTCACHE) {
  9412. this._isRenderableGroup = isCanvas;
  9413. this._isCachedGroup = false;
  9414. }
  9415. else if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_CANVAS) {
  9416. if (isCanvas) {
  9417. this._isRenderableGroup = true;
  9418. this._isCachedGroup = true;
  9419. }
  9420. else {
  9421. this._isRenderableGroup = this.id === "__cachedCanvasGroup__";
  9422. this._isCachedGroup = false;
  9423. }
  9424. }
  9425. else if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_TOPLEVELGROUPS) {
  9426. if (isCanvas) {
  9427. this._isRenderableGroup = true;
  9428. this._isCachedGroup = false;
  9429. }
  9430. else {
  9431. if (this.hierarchyDepth === 1) {
  9432. this._isRenderableGroup = true;
  9433. this._isCachedGroup = true;
  9434. }
  9435. else {
  9436. this._isRenderableGroup = false;
  9437. this._isCachedGroup = false;
  9438. }
  9439. }
  9440. }
  9441. else if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_ALLGROUPS) {
  9442. if (isCanvas) {
  9443. this._isRenderableGroup = true;
  9444. this._isCachedGroup = false;
  9445. }
  9446. else {
  9447. var gcb = this.cacheBehavior & Group2D_1.GROUPCACHEBEHAVIOR_OPTIONMASK;
  9448. if ((gcb === Group2D_1.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE) || (gcb === Group2D_1.GROUPCACHEBEHAVIOR_CACHEINPARENTGROUP)) {
  9449. this._isRenderableGroup = gcb === Group2D_1.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE;
  9450. this._isCachedGroup = false;
  9451. }
  9452. if (gcb === Group2D_1.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY) {
  9453. this._isRenderableGroup = true;
  9454. this._isCachedGroup = true;
  9455. }
  9456. }
  9457. }
  9458. if (this._isRenderableGroup) {
  9459. // Yes, we do need that check, trust me, unfortunately we can call _detectGroupStates many time on the same object...
  9460. if (!this._renderableData) {
  9461. this._renderableData = new RenderableGroupData();
  9462. }
  9463. }
  9464. // If the group is tagged as renderable we add it to the renderable tree
  9465. if (this._isCachedGroup) {
  9466. this._renderableData._noResizeOnScale = (this.cacheBehavior & Group2D_1.GROUPCACHEBEHAVIOR_NORESIZEONSCALE) !== 0;
  9467. var cur = this.parent;
  9468. while (cur) {
  9469. if (cur instanceof Group2D_1 && cur._isRenderableGroup) {
  9470. if (cur._renderableData._childrenRenderableGroups.indexOf(this) === -1) {
  9471. cur._renderableData._childrenRenderableGroups.push(this);
  9472. }
  9473. break;
  9474. }
  9475. cur = cur.parent;
  9476. }
  9477. }
  9478. };
  9479. return Group2D;
  9480. }(BABYLON.Prim2DBase));
  9481. Group2D.GROUP2D_PROPCOUNT = BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 5;
  9482. /**
  9483. * Default behavior, the group will use the caching strategy defined at the Canvas Level
  9484. */
  9485. Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY = 0;
  9486. /**
  9487. * When used, this group's content won't be cached, no matter which strategy used.
  9488. * If the group is part of a WorldSpace Canvas, its content will be drawn in the Canvas cache bitmap.
  9489. */
  9490. Group2D.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE = 1;
  9491. /**
  9492. * When used, the group's content will be cached in the nearest cached parent group/canvas
  9493. */
  9494. Group2D.GROUPCACHEBEHAVIOR_CACHEINPARENTGROUP = 2;
  9495. /**
  9496. * You can specify this behavior to any cached Group2D to indicate that you don't want the cached content to be resized when the Group's actualScale is changing. It will draw the content stretched or shrink which is faster than a resize. This setting is obviously for performance consideration, don't use it if you want the best rendering quality
  9497. */
  9498. Group2D.GROUPCACHEBEHAVIOR_NORESIZEONSCALE = 0x100;
  9499. Group2D.GROUPCACHEBEHAVIOR_OPTIONMASK = 0xFF;
  9500. Group2D._uV = new BABYLON.Vector2(1, 1);
  9501. Group2D._s = BABYLON.Size.Zero();
  9502. Group2D._unS = new BABYLON.Vector2(1, 1);
  9503. __decorate([
  9504. BABYLON.instanceLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 1, function (pi) { return Group2D_1.sizeProperty = pi; }, false, true)
  9505. ], Group2D.prototype, "size", null);
  9506. __decorate([
  9507. BABYLON.instanceLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 2, function (pi) { return Group2D_1.actualSizeProperty = pi; })
  9508. ], Group2D.prototype, "actualSize", null);
  9509. Group2D = Group2D_1 = __decorate([
  9510. BABYLON.className("Group2D", "BABYLON")
  9511. ], Group2D);
  9512. BABYLON.Group2D = Group2D;
  9513. var RenderableGroupData = (function () {
  9514. function RenderableGroupData() {
  9515. this._primDirtyList = new Array();
  9516. this._primNewDirtyList = new Array();
  9517. this._childrenRenderableGroups = new Array();
  9518. this._renderGroupInstancesInfo = new BABYLON.StringDictionary();
  9519. this._transparentPrimitives = new Array();
  9520. this._transparentSegments = new Array();
  9521. this._transparentListChanged = false;
  9522. this._cacheNode = null;
  9523. this._cacheTexture = null;
  9524. this._cacheRenderSprite = null;
  9525. this._renderingScale = 1;
  9526. this._cacheNodeUVs = null;
  9527. this._cacheNodeUVsChangedObservable = null;
  9528. this._cacheSize = BABYLON.Size.Zero();
  9529. this._useMipMap = false;
  9530. this._anisotropicLevel = 1;
  9531. this._noResizeOnScale = false;
  9532. }
  9533. RenderableGroupData.prototype.dispose = function (owner) {
  9534. var engine = owner.engine;
  9535. if (this._cacheRenderSprite) {
  9536. this._cacheRenderSprite.dispose();
  9537. this._cacheRenderSprite = null;
  9538. }
  9539. if (this._cacheTexture && this._cacheNode) {
  9540. this._cacheTexture.freeRect(this._cacheNode);
  9541. this._cacheTexture = null;
  9542. this._cacheNode = null;
  9543. }
  9544. if (this._primDirtyList) {
  9545. this._primDirtyList.splice(0);
  9546. this._primDirtyList = null;
  9547. }
  9548. if (this._renderGroupInstancesInfo) {
  9549. this._renderGroupInstancesInfo.forEach(function (k, v) {
  9550. v.dispose();
  9551. });
  9552. this._renderGroupInstancesInfo = null;
  9553. }
  9554. if (this._cacheNodeUVsChangedObservable) {
  9555. this._cacheNodeUVsChangedObservable.clear();
  9556. this._cacheNodeUVsChangedObservable = null;
  9557. }
  9558. if (this._transparentSegments) {
  9559. for (var _i = 0, _a = this._transparentSegments; _i < _a.length; _i++) {
  9560. var ts = _a[_i];
  9561. ts.dispose(engine);
  9562. }
  9563. this._transparentSegments.splice(0);
  9564. this._transparentSegments = null;
  9565. }
  9566. };
  9567. RenderableGroupData.prototype.addNewTransparentPrimitiveInfo = function (prim, gii) {
  9568. var tpi = new TransparentPrimitiveInfo();
  9569. tpi._primitive = prim;
  9570. tpi._groupInstanceInfo = gii;
  9571. tpi._transparentSegment = null;
  9572. this._transparentPrimitives.push(tpi);
  9573. this._transparentListChanged = true;
  9574. return tpi;
  9575. };
  9576. RenderableGroupData.prototype.removeTransparentPrimitiveInfo = function (tpi) {
  9577. var index = this._transparentPrimitives.indexOf(tpi);
  9578. if (index !== -1) {
  9579. this._transparentPrimitives.splice(index, 1);
  9580. this._transparentListChanged = true;
  9581. }
  9582. };
  9583. RenderableGroupData.prototype.transparentPrimitiveZChanged = function (tpi) {
  9584. this._transparentListChanged = true;
  9585. //this.updateSmallestZChangedPrim(tpi);
  9586. };
  9587. return RenderableGroupData;
  9588. }());
  9589. BABYLON.RenderableGroupData = RenderableGroupData;
  9590. var TransparentPrimitiveInfo = (function () {
  9591. function TransparentPrimitiveInfo() {
  9592. }
  9593. return TransparentPrimitiveInfo;
  9594. }());
  9595. BABYLON.TransparentPrimitiveInfo = TransparentPrimitiveInfo;
  9596. var Group2D_1;
  9597. })(BABYLON || (BABYLON = {}));
  9598. //# sourceMappingURL=babylon.group2d.js.map
  9599. var __extends = (this && this.__extends) || function (d, b) {
  9600. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  9601. function __() { this.constructor = d; }
  9602. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9603. };
  9604. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  9605. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  9606. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  9607. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  9608. return c > 3 && r && Object.defineProperty(target, key, r), r;
  9609. };
  9610. var BABYLON;
  9611. (function (BABYLON) {
  9612. var Rectangle2DRenderCache = (function (_super) {
  9613. __extends(Rectangle2DRenderCache, _super);
  9614. function Rectangle2DRenderCache(engine, modelKey) {
  9615. var _this = _super.call(this, engine, modelKey) || this;
  9616. _this.effectsReady = false;
  9617. _this.fillVB = null;
  9618. _this.fillIB = null;
  9619. _this.fillIndicesCount = 0;
  9620. _this.instancingFillAttributes = null;
  9621. _this.effectFill = null;
  9622. _this.effectFillInstanced = null;
  9623. _this.borderVB = null;
  9624. _this.borderIB = null;
  9625. _this.borderIndicesCount = 0;
  9626. _this.instancingBorderAttributes = null;
  9627. _this.effectBorder = null;
  9628. _this.effectBorderInstanced = null;
  9629. return _this;
  9630. }
  9631. Rectangle2DRenderCache.prototype.render = function (instanceInfo, context) {
  9632. // Do nothing if the shader is still loading/preparing
  9633. if (!this.effectsReady) {
  9634. if ((this.effectFill && (!this.effectFill.isReady() || (this.effectFillInstanced && !this.effectFillInstanced.isReady()))) ||
  9635. (this.effectBorder && (!this.effectBorder.isReady() || (this.effectBorderInstanced && !this.effectBorderInstanced.isReady())))) {
  9636. return false;
  9637. }
  9638. this.effectsReady = true;
  9639. }
  9640. var canvas = instanceInfo.owner.owner;
  9641. var engine = canvas.engine;
  9642. var depthFunction = 0;
  9643. if (this.effectFill && this.effectBorder) {
  9644. depthFunction = engine.getDepthFunction();
  9645. engine.setDepthFunctionToLessOrEqual();
  9646. }
  9647. var curAlphaMode = engine.getAlphaMode();
  9648. if (this.effectFill) {
  9649. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_FILLPARTID.toString());
  9650. var pid = context.groupInfoPartData[partIndex];
  9651. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  9652. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  9653. }
  9654. var effect = context.useInstancing ? this.effectFillInstanced : this.effectFill;
  9655. engine.enableEffect(effect);
  9656. engine.bindBuffersDirectly(this.fillVB, this.fillIB, [1], 4, effect);
  9657. if (context.useInstancing) {
  9658. if (!this.instancingFillAttributes) {
  9659. this.instancingFillAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_FILLPARTID, effect);
  9660. }
  9661. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  9662. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  9663. canvas._addDrawCallCount(1, context.renderMode);
  9664. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingFillAttributes);
  9665. engine.draw(true, 0, this.fillIndicesCount, count);
  9666. engine.unbindInstanceAttributes();
  9667. }
  9668. else {
  9669. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  9670. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  9671. this.setupUniforms(effect, partIndex, pid._partData, i);
  9672. engine.draw(true, 0, this.fillIndicesCount);
  9673. }
  9674. }
  9675. }
  9676. if (this.effectBorder) {
  9677. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_BORDERPARTID.toString());
  9678. var pid = context.groupInfoPartData[partIndex];
  9679. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  9680. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  9681. }
  9682. var effect = context.useInstancing ? this.effectBorderInstanced : this.effectBorder;
  9683. engine.enableEffect(effect);
  9684. engine.bindBuffersDirectly(this.borderVB, this.borderIB, [1], 4, effect);
  9685. if (context.useInstancing) {
  9686. if (!this.instancingBorderAttributes) {
  9687. this.instancingBorderAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, effect);
  9688. }
  9689. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  9690. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  9691. canvas._addDrawCallCount(1, context.renderMode);
  9692. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingBorderAttributes);
  9693. engine.draw(true, 0, this.borderIndicesCount, count);
  9694. engine.unbindInstanceAttributes();
  9695. }
  9696. else {
  9697. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  9698. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  9699. this.setupUniforms(effect, partIndex, pid._partData, i);
  9700. engine.draw(true, 0, this.borderIndicesCount);
  9701. }
  9702. }
  9703. }
  9704. engine.setAlphaMode(curAlphaMode, true);
  9705. if (this.effectFill && this.effectBorder) {
  9706. engine.setDepthFunction(depthFunction);
  9707. }
  9708. return true;
  9709. };
  9710. Rectangle2DRenderCache.prototype.dispose = function () {
  9711. if (!_super.prototype.dispose.call(this)) {
  9712. return false;
  9713. }
  9714. if (this.fillVB) {
  9715. this._engine._releaseBuffer(this.fillVB);
  9716. this.fillVB = null;
  9717. }
  9718. if (this.fillIB) {
  9719. this._engine._releaseBuffer(this.fillIB);
  9720. this.fillIB = null;
  9721. }
  9722. this.effectFill = null;
  9723. this.effectFillInstanced = null;
  9724. this.effectBorder = null;
  9725. this.effectBorderInstanced = null;
  9726. if (this.borderVB) {
  9727. this._engine._releaseBuffer(this.borderVB);
  9728. this.borderVB = null;
  9729. }
  9730. if (this.borderIB) {
  9731. this._engine._releaseBuffer(this.borderIB);
  9732. this.borderIB = null;
  9733. }
  9734. return true;
  9735. };
  9736. return Rectangle2DRenderCache;
  9737. }(BABYLON.ModelRenderCache));
  9738. BABYLON.Rectangle2DRenderCache = Rectangle2DRenderCache;
  9739. var Rectangle2DInstanceData = (function (_super) {
  9740. __extends(Rectangle2DInstanceData, _super);
  9741. function Rectangle2DInstanceData(partId) {
  9742. return _super.call(this, partId, 1) || this;
  9743. }
  9744. Object.defineProperty(Rectangle2DInstanceData.prototype, "properties", {
  9745. get: function () {
  9746. return null;
  9747. },
  9748. set: function (value) {
  9749. },
  9750. enumerable: true,
  9751. configurable: true
  9752. });
  9753. return Rectangle2DInstanceData;
  9754. }(BABYLON.Shape2DInstanceData));
  9755. __decorate([
  9756. BABYLON.instanceData()
  9757. ], Rectangle2DInstanceData.prototype, "properties", null);
  9758. BABYLON.Rectangle2DInstanceData = Rectangle2DInstanceData;
  9759. var Rectangle2D = Rectangle2D_1 = (function (_super) {
  9760. __extends(Rectangle2D, _super);
  9761. /**
  9762. * Create an Rectangle 2D Shape primitive. May be a sharp rectangle (with sharp corners), or a rounded one.
  9763. * @param settings a combination of settings, possible ones are
  9764. * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
  9765. * - children: an array of direct children
  9766. * - id a text identifier, for information purpose
  9767. * - position: the X & Y positions relative to its parent. Alternatively the x and y settings can be set. Default is [0;0]
  9768. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  9769. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  9770. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  9771. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  9772. * - zOrder: override the zOrder with the specified value
  9773. * - origin: define the normalized origin point location, default [0.5;0.5]
  9774. * - size: the size of the group. Alternatively the width and height settings can be set. Default will be [10;10].
  9775. * - roundRadius: if the rectangle has rounded corner, set their radius, default is 0 (to get a sharp edges rectangle).
  9776. * - fill: the brush used to draw the fill content of the rectangle, you can set null to draw nothing (but you will have to set a border brush), default is a SolidColorBrush of plain white. can also be a string value (see Canvas2D.GetBrushFromString)
  9777. * - border: the brush used to draw the border of the rectangle, you can set null to draw nothing (but you will have to set a fill brush), default is null. can also be a string value (see Canvas2D.GetBrushFromString)
  9778. * - borderThickness: the thickness of the drawn border, default is 1.
  9779. * - isVisible: true if the primitive must be visible, false for hidden. Default is true.
  9780. * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
  9781. * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
  9782. * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
  9783. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9784. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9785. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9786. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9787. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  9788. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  9789. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  9790. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  9791. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9792. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9793. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9794. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9795. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  9796. */
  9797. function Rectangle2D(settings) {
  9798. var _this;
  9799. // Avoid checking every time if the object exists
  9800. if (settings == null) {
  9801. settings = {};
  9802. }
  9803. _this = _super.call(this, settings) || this;
  9804. if (settings.size != null) {
  9805. _this.size = settings.size;
  9806. }
  9807. else if (settings.width || settings.height) {
  9808. var size = new BABYLON.Size(settings.width, settings.height);
  9809. _this.size = size;
  9810. }
  9811. //let size = settings.size || (new Size((settings.width === null) ? null : (settings.width || 10), (settings.height === null) ? null : (settings.height || 10)));
  9812. var roundRadius = (settings.roundRadius == null) ? 0 : settings.roundRadius;
  9813. var borderThickness = (settings.borderThickness == null) ? 1 : settings.borderThickness;
  9814. //this.size = size;
  9815. _this.roundRadius = roundRadius;
  9816. _this.borderThickness = borderThickness;
  9817. return _this;
  9818. }
  9819. Object.defineProperty(Rectangle2D.prototype, "actualSize", {
  9820. get: function () {
  9821. if (this._actualSize) {
  9822. return this._actualSize;
  9823. }
  9824. return this.size;
  9825. },
  9826. set: function (value) {
  9827. this._actualSize = value;
  9828. },
  9829. enumerable: true,
  9830. configurable: true
  9831. });
  9832. Object.defineProperty(Rectangle2D.prototype, "notRounded", {
  9833. get: function () {
  9834. return this._notRounded;
  9835. },
  9836. set: function (value) {
  9837. this._notRounded = value;
  9838. },
  9839. enumerable: true,
  9840. configurable: true
  9841. });
  9842. Object.defineProperty(Rectangle2D.prototype, "roundRadius", {
  9843. get: function () {
  9844. return this._roundRadius;
  9845. },
  9846. set: function (value) {
  9847. this._roundRadius = value;
  9848. this.notRounded = value === 0;
  9849. this._positioningDirty();
  9850. },
  9851. enumerable: true,
  9852. configurable: true
  9853. });
  9854. Rectangle2D.prototype.levelIntersect = function (intersectInfo) {
  9855. // If we got there it mean the boundingInfo intersection succeed, if the rectangle has not roundRadius, it means it succeed!
  9856. if (this.notRounded) {
  9857. return true;
  9858. }
  9859. // If we got so far it means the bounding box at least passed, so we know it's inside the bounding rectangle, but it can be outside the roundedRectangle.
  9860. // The easiest way is to check if the point is inside on of the four corners area (a little square of roundRadius size at the four corners)
  9861. // If it's the case for one, check if the mouse is located in the quarter that we care about (the one who is visible) then finally make a distance check with the roundRadius radius to see if it's inside the circle quarter or outside.
  9862. // First let remove the origin out the equation, to have the rectangle with an origin at bottom/left
  9863. var size = this.size;
  9864. Rectangle2D_1._i0.x = intersectInfo._localPickPosition.x;
  9865. Rectangle2D_1._i0.y = intersectInfo._localPickPosition.y;
  9866. var rr = this.roundRadius;
  9867. var rrs = rr * rr;
  9868. // Check if the point is in the bottom/left quarter area
  9869. Rectangle2D_1._i1.x = rr;
  9870. Rectangle2D_1._i1.y = rr;
  9871. if (Rectangle2D_1._i0.x <= Rectangle2D_1._i1.x && Rectangle2D_1._i0.y <= Rectangle2D_1._i1.y) {
  9872. // Compute the intersection point in the quarter local space
  9873. Rectangle2D_1._i2.x = Rectangle2D_1._i0.x - Rectangle2D_1._i1.x;
  9874. Rectangle2D_1._i2.y = Rectangle2D_1._i0.y - Rectangle2D_1._i1.y;
  9875. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  9876. return Rectangle2D_1._i2.lengthSquared() <= rrs;
  9877. }
  9878. // Check if the point is in the top/left quarter area
  9879. Rectangle2D_1._i1.x = rr;
  9880. Rectangle2D_1._i1.y = size.height - rr;
  9881. if (Rectangle2D_1._i0.x <= Rectangle2D_1._i1.x && Rectangle2D_1._i0.y >= Rectangle2D_1._i1.y) {
  9882. // Compute the intersection point in the quarter local space
  9883. Rectangle2D_1._i2.x = Rectangle2D_1._i0.x - Rectangle2D_1._i1.x;
  9884. Rectangle2D_1._i2.y = Rectangle2D_1._i0.y - Rectangle2D_1._i1.y;
  9885. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  9886. return Rectangle2D_1._i2.lengthSquared() <= rrs;
  9887. }
  9888. // Check if the point is in the top/right quarter area
  9889. Rectangle2D_1._i1.x = size.width - rr;
  9890. Rectangle2D_1._i1.y = size.height - rr;
  9891. if (Rectangle2D_1._i0.x >= Rectangle2D_1._i1.x && Rectangle2D_1._i0.y >= Rectangle2D_1._i1.y) {
  9892. // Compute the intersection point in the quarter local space
  9893. Rectangle2D_1._i2.x = Rectangle2D_1._i0.x - Rectangle2D_1._i1.x;
  9894. Rectangle2D_1._i2.y = Rectangle2D_1._i0.y - Rectangle2D_1._i1.y;
  9895. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  9896. return Rectangle2D_1._i2.lengthSquared() <= rrs;
  9897. }
  9898. // Check if the point is in the bottom/right quarter area
  9899. Rectangle2D_1._i1.x = size.width - rr;
  9900. Rectangle2D_1._i1.y = rr;
  9901. if (Rectangle2D_1._i0.x >= Rectangle2D_1._i1.x && Rectangle2D_1._i0.y <= Rectangle2D_1._i1.y) {
  9902. // Compute the intersection point in the quarter local space
  9903. Rectangle2D_1._i2.x = Rectangle2D_1._i0.x - Rectangle2D_1._i1.x;
  9904. Rectangle2D_1._i2.y = Rectangle2D_1._i0.y - Rectangle2D_1._i1.y;
  9905. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  9906. return Rectangle2D_1._i2.lengthSquared() <= rrs;
  9907. }
  9908. // At any other locations the point is guarantied to be inside
  9909. return true;
  9910. };
  9911. Rectangle2D.prototype.updateLevelBoundingInfo = function () {
  9912. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.actualSize, this._levelBoundingInfo);
  9913. };
  9914. Rectangle2D.prototype.createModelRenderCache = function (modelKey) {
  9915. var renderCache = new Rectangle2DRenderCache(this.owner.engine, modelKey);
  9916. return renderCache;
  9917. };
  9918. Rectangle2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  9919. var renderCache = modelRenderCache;
  9920. var engine = this.owner.engine;
  9921. // Need to create WebGL resources for fill part?
  9922. if (this.fill) {
  9923. var vbSize = ((this.notRounded ? 1 : Rectangle2D_1.roundSubdivisions) * 4) + 1;
  9924. var vb = new Float32Array(vbSize);
  9925. for (var i = 0; i < vbSize; i++) {
  9926. vb[i] = i;
  9927. }
  9928. renderCache.fillVB = engine.createVertexBuffer(vb);
  9929. var triCount = vbSize - 1;
  9930. var ib = new Float32Array(triCount * 3);
  9931. for (var i = 0; i < triCount; i++) {
  9932. ib[i * 3 + 0] = 0;
  9933. ib[i * 3 + 2] = i + 1;
  9934. ib[i * 3 + 1] = i + 2;
  9935. }
  9936. ib[triCount * 3 - 2] = 1;
  9937. renderCache.fillIB = engine.createIndexBuffer(ib);
  9938. renderCache.fillIndicesCount = triCount * 3;
  9939. // Get the instanced version of the effect, if the engine does not support it, null is return and we'll only draw on by one
  9940. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, true);
  9941. if (ei) {
  9942. renderCache.effectFillInstanced = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9943. }
  9944. // Get the non instanced version
  9945. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, false);
  9946. renderCache.effectFill = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9947. }
  9948. // Need to create WebGL resource for border part?
  9949. if (this.border) {
  9950. var vbSize = (this.notRounded ? 1 : Rectangle2D_1.roundSubdivisions) * 4 * 2;
  9951. var vb = new Float32Array(vbSize);
  9952. for (var i = 0; i < vbSize; i++) {
  9953. vb[i] = i;
  9954. }
  9955. renderCache.borderVB = engine.createVertexBuffer(vb);
  9956. var triCount = vbSize;
  9957. var rs = triCount / 2;
  9958. var ib = new Float32Array(triCount * 3);
  9959. for (var i = 0; i < rs; i++) {
  9960. var r0 = i;
  9961. var r1 = (i + 1) % rs;
  9962. ib[i * 6 + 0] = rs + r1;
  9963. ib[i * 6 + 1] = rs + r0;
  9964. ib[i * 6 + 2] = r0;
  9965. ib[i * 6 + 3] = r1;
  9966. ib[i * 6 + 4] = rs + r1;
  9967. ib[i * 6 + 5] = r0;
  9968. }
  9969. renderCache.borderIB = engine.createIndexBuffer(ib);
  9970. renderCache.borderIndicesCount = triCount * 3;
  9971. // Get the instanced version of the effect, if the engine does not support it, null is return and we'll only draw on by one
  9972. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, true);
  9973. if (ei) {
  9974. renderCache.effectBorderInstanced = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9975. }
  9976. // Get the non instanced version
  9977. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, false);
  9978. renderCache.effectBorder = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9979. }
  9980. return renderCache;
  9981. };
  9982. // We override this method because if there's a roundRadius set, we will reduce the initial Content Area to make sure the computed area won't intersect with the shape contour. The formula is simple: we shrink the incoming size by the amount of the roundRadius
  9983. Rectangle2D.prototype._getInitialContentAreaToRef = function (primSize, initialContentPosition, initialContentArea) {
  9984. // Fall back to default implementation if there's no round Radius
  9985. if (this._notRounded) {
  9986. _super.prototype._getInitialContentAreaToRef.call(this, primSize, initialContentPosition, initialContentArea);
  9987. }
  9988. else {
  9989. var rr = Math.round((this.roundRadius - (this.roundRadius / Math.sqrt(2))) * 1.3);
  9990. initialContentPosition.x = initialContentPosition.y = rr;
  9991. initialContentArea.width = Math.max(0, primSize.width - (rr * 2));
  9992. initialContentArea.height = Math.max(0, primSize.height - (rr * 2));
  9993. initialContentPosition.z = primSize.width - (initialContentPosition.x + initialContentArea.width);
  9994. initialContentPosition.w = primSize.height - (initialContentPosition.y + initialContentArea.height);
  9995. }
  9996. };
  9997. Rectangle2D.prototype._getActualSizeFromContentToRef = function (primSize, newPrimSize) {
  9998. // Fall back to default implementation if there's no round Radius
  9999. if (this._notRounded) {
  10000. _super.prototype._getActualSizeFromContentToRef.call(this, primSize, newPrimSize);
  10001. }
  10002. else {
  10003. var rr = Math.round((this.roundRadius - (this.roundRadius / Math.sqrt(2))) * 1.3);
  10004. newPrimSize.copyFrom(primSize);
  10005. newPrimSize.width += rr * 2;
  10006. newPrimSize.height += rr * 2;
  10007. }
  10008. };
  10009. Rectangle2D.prototype.createInstanceDataParts = function () {
  10010. var res = new Array();
  10011. if (this.border) {
  10012. res.push(new Rectangle2DInstanceData(BABYLON.Shape2D.SHAPE2D_BORDERPARTID));
  10013. }
  10014. if (this.fill) {
  10015. res.push(new Rectangle2DInstanceData(BABYLON.Shape2D.SHAPE2D_FILLPARTID));
  10016. }
  10017. return res;
  10018. };
  10019. Rectangle2D.prototype.refreshInstanceDataPart = function (part) {
  10020. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  10021. return false;
  10022. }
  10023. if (part.id === BABYLON.Shape2D.SHAPE2D_BORDERPARTID) {
  10024. var d = part;
  10025. var size = this.actualSize;
  10026. var s = this.actualScale;
  10027. d.properties = new BABYLON.Vector3(size.width * s.x, size.height * s.y, this.roundRadius || 0);
  10028. }
  10029. else if (part.id === BABYLON.Shape2D.SHAPE2D_FILLPARTID) {
  10030. var d = part;
  10031. var size = this.actualSize;
  10032. var s = this.actualScale;
  10033. d.properties = new BABYLON.Vector3(size.width * s.x, size.height * s.y, this.roundRadius || 0);
  10034. }
  10035. return true;
  10036. };
  10037. return Rectangle2D;
  10038. }(BABYLON.Shape2D));
  10039. Rectangle2D._i0 = BABYLON.Vector2.Zero();
  10040. Rectangle2D._i1 = BABYLON.Vector2.Zero();
  10041. Rectangle2D._i2 = BABYLON.Vector2.Zero();
  10042. Rectangle2D.roundSubdivisions = 16;
  10043. __decorate([
  10044. BABYLON.instanceLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 1, function (pi) { return Rectangle2D_1.actualSizeProperty = pi; }, false, true)
  10045. ], Rectangle2D.prototype, "actualSize", null);
  10046. __decorate([
  10047. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 2, function (pi) { return Rectangle2D_1.notRoundedProperty = pi; })
  10048. ], Rectangle2D.prototype, "notRounded", null);
  10049. __decorate([
  10050. BABYLON.instanceLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 3, function (pi) { return Rectangle2D_1.roundRadiusProperty = pi; })
  10051. ], Rectangle2D.prototype, "roundRadius", null);
  10052. Rectangle2D = Rectangle2D_1 = __decorate([
  10053. BABYLON.className("Rectangle2D", "BABYLON")
  10054. ], Rectangle2D);
  10055. BABYLON.Rectangle2D = Rectangle2D;
  10056. var Rectangle2D_1;
  10057. })(BABYLON || (BABYLON = {}));
  10058. //# sourceMappingURL=babylon.rectangle2d.js.map
  10059. var __extends = (this && this.__extends) || function (d, b) {
  10060. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  10061. function __() { this.constructor = d; }
  10062. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10063. };
  10064. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  10065. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  10066. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  10067. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  10068. return c > 3 && r && Object.defineProperty(target, key, r), r;
  10069. };
  10070. var BABYLON;
  10071. (function (BABYLON) {
  10072. var Ellipse2DRenderCache = (function (_super) {
  10073. __extends(Ellipse2DRenderCache, _super);
  10074. function Ellipse2DRenderCache(engine, modelKey) {
  10075. var _this = _super.call(this, engine, modelKey) || this;
  10076. _this.effectsReady = false;
  10077. _this.fillVB = null;
  10078. _this.fillIB = null;
  10079. _this.fillIndicesCount = 0;
  10080. _this.instancingFillAttributes = null;
  10081. _this.effectFillInstanced = null;
  10082. _this.effectFill = null;
  10083. _this.borderVB = null;
  10084. _this.borderIB = null;
  10085. _this.borderIndicesCount = 0;
  10086. _this.instancingBorderAttributes = null;
  10087. _this.effectBorderInstanced = null;
  10088. _this.effectBorder = null;
  10089. return _this;
  10090. }
  10091. Ellipse2DRenderCache.prototype.render = function (instanceInfo, context) {
  10092. // Do nothing if the shader is still loading/preparing
  10093. if (!this.effectsReady) {
  10094. if ((this.effectFill && (!this.effectFill.isReady() || (this.effectFillInstanced && !this.effectFillInstanced.isReady()))) ||
  10095. (this.effectBorder && (!this.effectBorder.isReady() || (this.effectBorderInstanced && !this.effectBorderInstanced.isReady())))) {
  10096. return false;
  10097. }
  10098. this.effectsReady = true;
  10099. }
  10100. var canvas = instanceInfo.owner.owner;
  10101. var engine = canvas.engine;
  10102. var depthFunction = 0;
  10103. if (this.effectFill && this.effectBorder) {
  10104. depthFunction = engine.getDepthFunction();
  10105. engine.setDepthFunctionToLessOrEqual();
  10106. }
  10107. var curAlphaMode = engine.getAlphaMode();
  10108. if (this.effectFill) {
  10109. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_FILLPARTID.toString());
  10110. var pid = context.groupInfoPartData[partIndex];
  10111. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  10112. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  10113. }
  10114. var effect = context.useInstancing ? this.effectFillInstanced : this.effectFill;
  10115. engine.enableEffect(effect);
  10116. engine.bindBuffersDirectly(this.fillVB, this.fillIB, [1], 4, effect);
  10117. if (context.useInstancing) {
  10118. if (!this.instancingFillAttributes) {
  10119. this.instancingFillAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_FILLPARTID, effect);
  10120. }
  10121. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  10122. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  10123. canvas._addDrawCallCount(1, context.renderMode);
  10124. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingFillAttributes);
  10125. engine.draw(true, 0, this.fillIndicesCount, count);
  10126. engine.unbindInstanceAttributes();
  10127. }
  10128. else {
  10129. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  10130. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  10131. this.setupUniforms(effect, partIndex, pid._partData, i);
  10132. engine.draw(true, 0, this.fillIndicesCount);
  10133. }
  10134. }
  10135. }
  10136. if (this.effectBorder) {
  10137. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_BORDERPARTID.toString());
  10138. var pid = context.groupInfoPartData[partIndex];
  10139. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  10140. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  10141. }
  10142. var effect = context.useInstancing ? this.effectBorderInstanced : this.effectBorder;
  10143. engine.enableEffect(effect);
  10144. engine.bindBuffersDirectly(this.borderVB, this.borderIB, [1], 4, effect);
  10145. if (context.useInstancing) {
  10146. if (!this.instancingBorderAttributes) {
  10147. this.instancingBorderAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, effect);
  10148. }
  10149. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  10150. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  10151. canvas._addDrawCallCount(1, context.renderMode);
  10152. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingBorderAttributes);
  10153. engine.draw(true, 0, this.borderIndicesCount, count);
  10154. engine.unbindInstanceAttributes();
  10155. }
  10156. else {
  10157. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  10158. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  10159. this.setupUniforms(effect, partIndex, pid._partData, i);
  10160. engine.draw(true, 0, this.borderIndicesCount);
  10161. }
  10162. }
  10163. }
  10164. engine.setAlphaMode(curAlphaMode, true);
  10165. if (this.effectFill && this.effectBorder) {
  10166. engine.setDepthFunction(depthFunction);
  10167. }
  10168. return true;
  10169. };
  10170. Ellipse2DRenderCache.prototype.dispose = function () {
  10171. if (!_super.prototype.dispose.call(this)) {
  10172. return false;
  10173. }
  10174. if (this.fillVB) {
  10175. this._engine._releaseBuffer(this.fillVB);
  10176. this.fillVB = null;
  10177. }
  10178. if (this.fillIB) {
  10179. this._engine._releaseBuffer(this.fillIB);
  10180. this.fillIB = null;
  10181. }
  10182. this.effectFill = null;
  10183. this.effectFillInstanced = null;
  10184. this.effectBorder = null;
  10185. this.effectBorderInstanced = null;
  10186. if (this.borderVB) {
  10187. this._engine._releaseBuffer(this.borderVB);
  10188. this.borderVB = null;
  10189. }
  10190. if (this.borderIB) {
  10191. this._engine._releaseBuffer(this.borderIB);
  10192. this.borderIB = null;
  10193. }
  10194. return true;
  10195. };
  10196. return Ellipse2DRenderCache;
  10197. }(BABYLON.ModelRenderCache));
  10198. BABYLON.Ellipse2DRenderCache = Ellipse2DRenderCache;
  10199. var Ellipse2DInstanceData = (function (_super) {
  10200. __extends(Ellipse2DInstanceData, _super);
  10201. function Ellipse2DInstanceData(partId) {
  10202. return _super.call(this, partId, 1) || this;
  10203. }
  10204. Object.defineProperty(Ellipse2DInstanceData.prototype, "properties", {
  10205. get: function () {
  10206. return null;
  10207. },
  10208. set: function (value) {
  10209. },
  10210. enumerable: true,
  10211. configurable: true
  10212. });
  10213. return Ellipse2DInstanceData;
  10214. }(BABYLON.Shape2DInstanceData));
  10215. __decorate([
  10216. BABYLON.instanceData()
  10217. ], Ellipse2DInstanceData.prototype, "properties", null);
  10218. BABYLON.Ellipse2DInstanceData = Ellipse2DInstanceData;
  10219. var Ellipse2D = Ellipse2D_1 = (function (_super) {
  10220. __extends(Ellipse2D, _super);
  10221. /**
  10222. * Create an Ellipse 2D Shape primitive
  10223. * @param settings a combination of settings, possible ones are
  10224. * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
  10225. * - children: an array of direct children
  10226. * - id: a text identifier, for information purpose
  10227. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  10228. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  10229. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  10230. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  10231. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  10232. * - zOrder: override the zOrder with the specified value
  10233. * - origin: define the normalized origin point location, default [0.5;0.5]
  10234. * - size: the size of the group. Alternatively the width and height properties can be set. Default will be [10;10].
  10235. * - subdivision: the number of subdivision to create the ellipse perimeter, default is 64.
  10236. * - fill: the brush used to draw the fill content of the ellipse, you can set null to draw nothing (but you will have to set a border brush), default is a SolidColorBrush of plain white. can also be a string value (see Canvas2D.GetBrushFromString)
  10237. * - border: the brush used to draw the border of the ellipse, you can set null to draw nothing (but you will have to set a fill brush), default is null. can be a string value (see Canvas2D.GetBrushFromString)
  10238. * - borderThickness: the thickness of the drawn border, default is 1.
  10239. * - isVisible: true if the group must be visible, false for hidden. Default is true.
  10240. * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
  10241. * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
  10242. * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
  10243. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10244. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10245. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10246. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10247. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  10248. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  10249. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  10250. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  10251. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10252. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10253. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10254. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10255. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  10256. */
  10257. function Ellipse2D(settings) {
  10258. var _this;
  10259. // Avoid checking every time if the object exists
  10260. if (settings == null) {
  10261. settings = {};
  10262. }
  10263. _this = _super.call(this, settings) || this;
  10264. if (settings.size != null) {
  10265. _this.size = settings.size;
  10266. }
  10267. else if (settings.width || settings.height) {
  10268. var size = new BABYLON.Size(settings.width, settings.height);
  10269. _this.size = size;
  10270. }
  10271. var sub = (settings.subdivisions == null) ? 64 : settings.subdivisions;
  10272. _this.subdivisions = sub;
  10273. return _this;
  10274. }
  10275. Object.defineProperty(Ellipse2D.prototype, "actualSize", {
  10276. get: function () {
  10277. if (this._actualSize) {
  10278. return this._actualSize;
  10279. }
  10280. return this.size;
  10281. },
  10282. set: function (value) {
  10283. this._actualSize = value;
  10284. },
  10285. enumerable: true,
  10286. configurable: true
  10287. });
  10288. Object.defineProperty(Ellipse2D.prototype, "subdivisions", {
  10289. get: function () {
  10290. return this._subdivisions;
  10291. },
  10292. set: function (value) {
  10293. this._subdivisions = value;
  10294. },
  10295. enumerable: true,
  10296. configurable: true
  10297. });
  10298. Ellipse2D.prototype.levelIntersect = function (intersectInfo) {
  10299. var w = this.size.width / 2;
  10300. var h = this.size.height / 2;
  10301. var x = intersectInfo._localPickPosition.x - w;
  10302. var y = intersectInfo._localPickPosition.y - h;
  10303. return ((x * x) / (w * w) + (y * y) / (h * h)) <= 1;
  10304. };
  10305. Ellipse2D.prototype.updateLevelBoundingInfo = function () {
  10306. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.actualSize, this._levelBoundingInfo);
  10307. };
  10308. Ellipse2D.prototype.createModelRenderCache = function (modelKey) {
  10309. var renderCache = new Ellipse2DRenderCache(this.owner.engine, modelKey);
  10310. return renderCache;
  10311. };
  10312. Ellipse2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  10313. var renderCache = modelRenderCache;
  10314. var engine = this.owner.engine;
  10315. // Need to create WebGL resources for fill part?
  10316. if (this.fill) {
  10317. var vbSize = this.subdivisions + 1;
  10318. var vb = new Float32Array(vbSize);
  10319. for (var i = 0; i < vbSize; i++) {
  10320. vb[i] = i;
  10321. }
  10322. renderCache.fillVB = engine.createVertexBuffer(vb);
  10323. var triCount = vbSize - 1;
  10324. var ib = new Float32Array(triCount * 3);
  10325. for (var i = 0; i < triCount; i++) {
  10326. ib[i * 3 + 0] = 0;
  10327. ib[i * 3 + 2] = i + 1;
  10328. ib[i * 3 + 1] = i + 2;
  10329. }
  10330. ib[triCount * 3 - 2] = 1;
  10331. renderCache.fillIB = engine.createIndexBuffer(ib);
  10332. renderCache.fillIndicesCount = triCount * 3;
  10333. // Get the instanced version of the effect, if the engine does not support it, null is return and we'll only draw on by one
  10334. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, true);
  10335. if (ei) {
  10336. renderCache.effectFillInstanced = engine.createEffect({ vertex: "ellipse2d", fragment: "ellipse2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  10337. }
  10338. // Get the non instanced version
  10339. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, false);
  10340. renderCache.effectFill = engine.createEffect({ vertex: "ellipse2d", fragment: "ellipse2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  10341. }
  10342. // Need to create WebGL resource for border part?
  10343. if (this.border) {
  10344. var vbSize = this.subdivisions * 2;
  10345. var vb = new Float32Array(vbSize);
  10346. for (var i = 0; i < vbSize; i++) {
  10347. vb[i] = i;
  10348. }
  10349. renderCache.borderVB = engine.createVertexBuffer(vb);
  10350. var triCount = vbSize;
  10351. var rs = triCount / 2;
  10352. var ib = new Float32Array(triCount * 3);
  10353. for (var i = 0; i < rs; i++) {
  10354. var r0 = i;
  10355. var r1 = (i + 1) % rs;
  10356. ib[i * 6 + 0] = rs + r1;
  10357. ib[i * 6 + 1] = rs + r0;
  10358. ib[i * 6 + 2] = r0;
  10359. ib[i * 6 + 3] = r1;
  10360. ib[i * 6 + 4] = rs + r1;
  10361. ib[i * 6 + 5] = r0;
  10362. }
  10363. renderCache.borderIB = engine.createIndexBuffer(ib);
  10364. renderCache.borderIndicesCount = (triCount * 3);
  10365. // Get the instanced version of the effect, if the engine does not support it, null is return and we'll only draw on by one
  10366. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, true);
  10367. if (ei) {
  10368. renderCache.effectBorderInstanced = engine.createEffect("ellipse2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  10369. }
  10370. // Get the non instanced version
  10371. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, false);
  10372. renderCache.effectBorder = engine.createEffect("ellipse2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  10373. }
  10374. return renderCache;
  10375. };
  10376. Ellipse2D.prototype.createInstanceDataParts = function () {
  10377. var res = new Array();
  10378. if (this.border) {
  10379. res.push(new Ellipse2DInstanceData(BABYLON.Shape2D.SHAPE2D_BORDERPARTID));
  10380. }
  10381. if (this.fill) {
  10382. res.push(new Ellipse2DInstanceData(BABYLON.Shape2D.SHAPE2D_FILLPARTID));
  10383. }
  10384. return res;
  10385. };
  10386. Ellipse2D.prototype.refreshInstanceDataPart = function (part) {
  10387. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  10388. return false;
  10389. }
  10390. if (part.id === BABYLON.Shape2D.SHAPE2D_BORDERPARTID) {
  10391. var d = part;
  10392. var size = this.actualSize;
  10393. var s = this.actualScale;
  10394. d.properties = new BABYLON.Vector3(size.width * s.x, size.height * s.y, this.subdivisions);
  10395. }
  10396. else if (part.id === BABYLON.Shape2D.SHAPE2D_FILLPARTID) {
  10397. var d = part;
  10398. var size = this.actualSize;
  10399. var s = this.actualScale;
  10400. d.properties = new BABYLON.Vector3(size.width * s.x, size.height * s.y, this.subdivisions);
  10401. }
  10402. return true;
  10403. };
  10404. return Ellipse2D;
  10405. }(BABYLON.Shape2D));
  10406. __decorate([
  10407. BABYLON.instanceLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 1, function (pi) { return Ellipse2D_1.acutalSizeProperty = pi; }, false, true)
  10408. ], Ellipse2D.prototype, "actualSize", null);
  10409. __decorate([
  10410. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 2, function (pi) { return Ellipse2D_1.subdivisionsProperty = pi; })
  10411. ], Ellipse2D.prototype, "subdivisions", null);
  10412. Ellipse2D = Ellipse2D_1 = __decorate([
  10413. BABYLON.className("Ellipse2D", "BABYLON")
  10414. ], Ellipse2D);
  10415. BABYLON.Ellipse2D = Ellipse2D;
  10416. var Ellipse2D_1;
  10417. })(BABYLON || (BABYLON = {}));
  10418. //# sourceMappingURL=babylon.ellipse2d.js.map
  10419. var __extends = (this && this.__extends) || function (d, b) {
  10420. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  10421. function __() { this.constructor = d; }
  10422. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10423. };
  10424. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  10425. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  10426. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  10427. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  10428. return c > 3 && r && Object.defineProperty(target, key, r), r;
  10429. };
  10430. var BABYLON;
  10431. (function (BABYLON) {
  10432. var Sprite2DRenderCache = (function (_super) {
  10433. __extends(Sprite2DRenderCache, _super);
  10434. function Sprite2DRenderCache() {
  10435. var _this = _super.apply(this, arguments) || this;
  10436. _this.effectsReady = false;
  10437. _this.vb = null;
  10438. _this.ib = null;
  10439. _this.instancingAttributes = null;
  10440. _this.texture = null;
  10441. _this.effect = null;
  10442. _this.effectInstanced = null;
  10443. return _this;
  10444. }
  10445. Sprite2DRenderCache.prototype.render = function (instanceInfo, context) {
  10446. // Do nothing if the shader is still loading/preparing
  10447. if (!this.effectsReady) {
  10448. if ((this.effect && (!this.effect.isReady() || (this.effectInstanced && !this.effectInstanced.isReady())))) {
  10449. return false;
  10450. }
  10451. this.effectsReady = true;
  10452. }
  10453. // Compute the offset locations of the attributes in the vertex shader that will be mapped to the instance buffer data
  10454. var canvas = instanceInfo.owner.owner;
  10455. var engine = canvas.engine;
  10456. var cur = engine.getAlphaMode();
  10457. var effect = context.useInstancing ? this.effectInstanced : this.effect;
  10458. engine.enableEffect(effect);
  10459. effect.setTexture("diffuseSampler", this.texture);
  10460. engine.bindBuffersDirectly(this.vb, this.ib, [1], 4, effect);
  10461. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  10462. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  10463. }
  10464. effect.setBool("alphaTest", context.renderMode === BABYLON.Render2DContext.RenderModeAlphaTest);
  10465. var pid = context.groupInfoPartData[0];
  10466. if (context.useInstancing) {
  10467. if (!this.instancingAttributes) {
  10468. this.instancingAttributes = this.loadInstancingAttributes(Sprite2D.SPRITE2D_MAINPARTID, effect);
  10469. }
  10470. var glBuffer = context.instancedBuffers ? context.instancedBuffers[0] : pid._partBuffer;
  10471. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  10472. canvas._addDrawCallCount(1, context.renderMode);
  10473. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingAttributes);
  10474. engine.draw(true, 0, 6, count);
  10475. engine.unbindInstanceAttributes();
  10476. }
  10477. else {
  10478. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  10479. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  10480. this.setupUniforms(effect, 0, pid._partData, i);
  10481. engine.draw(true, 0, 6);
  10482. }
  10483. }
  10484. engine.setAlphaMode(cur, true);
  10485. return true;
  10486. };
  10487. Sprite2DRenderCache.prototype.dispose = function () {
  10488. if (!_super.prototype.dispose.call(this)) {
  10489. return false;
  10490. }
  10491. if (this.vb) {
  10492. this._engine._releaseBuffer(this.vb);
  10493. this.vb = null;
  10494. }
  10495. if (this.ib) {
  10496. this._engine._releaseBuffer(this.ib);
  10497. this.ib = null;
  10498. }
  10499. //if (this.texture) {
  10500. // this.texture.dispose();
  10501. // this.texture = null;
  10502. //}
  10503. this.effect = null;
  10504. this.effectInstanced = null;
  10505. return true;
  10506. };
  10507. return Sprite2DRenderCache;
  10508. }(BABYLON.ModelRenderCache));
  10509. BABYLON.Sprite2DRenderCache = Sprite2DRenderCache;
  10510. var Sprite2D = Sprite2D_1 = (function (_super) {
  10511. __extends(Sprite2D, _super);
  10512. /**
  10513. * Create an 2D Sprite primitive
  10514. * @param texture the texture that stores the sprite to render
  10515. * @param settings a combination of settings, possible ones are
  10516. * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
  10517. * - children: an array of direct children
  10518. * - id a text identifier, for information purpose
  10519. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  10520. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  10521. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  10522. * - size: the size of the sprite displayed in the canvas, if not specified the spriteSize will be used
  10523. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  10524. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  10525. * - zOrder: override the zOrder with the specified value
  10526. * - origin: define the normalized origin point location, default [0.5;0.5]
  10527. * - spriteSize: the size of the sprite (in pixels) as it is stored in the texture, if null the size of the given texture will be used, default is null.
  10528. * - spriteLocation: the location (in pixels) in the texture of the top/left corner of the Sprite to display, default is null (0,0)
  10529. * - spriteScaleFactor: DEPRECATED. Old behavior: say you want to display a sprite twice as big as its bitmap which is 64,64, you set the spriteSize to 128,128 and have to set the spriteScaleFactory to 0.5,0.5 in order to address only the 64,64 pixels of the bitmaps. Default is 1,1.
  10530. * - scale9: draw the sprite as a Scale9 sprite, see http://yannickloriot.com/2013/03/9-patch-technique-in-cocos2d/ for more info. x, y, w, z are left, bottom, right, top coordinate of the resizable box
  10531. * - invertY: if true the texture Y will be inverted, default is false.
  10532. * - alignToPixel: if true the sprite's texels will be aligned to the rendering viewport pixels, ensuring the best rendering quality but slow animations won't be done as smooth as if you set false. If false a texel could lies between two pixels, being blended by the texture sampling mode you choose, the rendering result won't be as good, but very slow animation will be overall better looking. Default is true: content will be aligned.
  10533. * - isVisible: true if the sprite must be visible, false for hidden. Default is true.
  10534. * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
  10535. * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
  10536. * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
  10537. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10538. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10539. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10540. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10541. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  10542. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  10543. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  10544. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  10545. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10546. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10547. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10548. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10549. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  10550. */
  10551. function Sprite2D(texture, settings) {
  10552. var _this;
  10553. if (!settings) {
  10554. settings = {};
  10555. }
  10556. _this = _super.call(this, settings) || this;
  10557. _this.texture = texture;
  10558. _this.texture.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
  10559. _this.texture.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
  10560. _this._useSize = false;
  10561. _this.spriteSize = (settings.spriteSize != null) ? settings.spriteSize.clone() : null;
  10562. _this.spriteLocation = (settings.spriteLocation != null) ? settings.spriteLocation.clone() : new BABYLON.Vector2(0, 0);
  10563. if (settings.size != null) {
  10564. _this.size = settings.size;
  10565. }
  10566. _this.spriteFrame = 0;
  10567. _this.invertY = (settings.invertY == null) ? false : settings.invertY;
  10568. _this.alignToPixel = (settings.alignToPixel == null) ? true : settings.alignToPixel;
  10569. _this.useAlphaFromTexture = true;
  10570. _this._scale9 = (settings.scale9 != null) ? settings.scale9.clone() : null;
  10571. // If the user doesn't set a size, we'll use the texture's one, but if the texture is not loading, we HAVE to set a temporary dummy size otherwise the positioning engine will switch the marginAlignement to stretch/stretch, and WE DON'T WANT THAT.
  10572. // The fucking delayed texture sprite bug is fixed!
  10573. if (settings.spriteSize == null) {
  10574. _this.spriteSize = new BABYLON.Size(10, 10);
  10575. }
  10576. if (settings.spriteSize == null || !texture.isReady()) {
  10577. if (texture.isReady()) {
  10578. var s = texture.getBaseSize();
  10579. _this.spriteSize = new BABYLON.Size(s.width, s.height);
  10580. _this._updateSpriteScaleFactor();
  10581. }
  10582. else {
  10583. texture.onLoadObservable.add(function () {
  10584. if (settings.spriteSize == null) {
  10585. var s = texture.getBaseSize();
  10586. _this.spriteSize = new BABYLON.Size(s.width, s.height);
  10587. }
  10588. _this._updateSpriteScaleFactor();
  10589. _this._positioningDirty();
  10590. _this._setLayoutDirty();
  10591. _this._instanceDirtyFlags |= BABYLON.Prim2DBase.originProperty.flagId | Sprite2D_1.textureProperty.flagId; // To make sure the sprite is issued again for render
  10592. });
  10593. }
  10594. }
  10595. return _this;
  10596. }
  10597. Object.defineProperty(Sprite2D.prototype, "texture", {
  10598. get: function () {
  10599. return this._texture;
  10600. },
  10601. set: function (value) {
  10602. this._texture = value;
  10603. this._oldTextureHasAlpha = this._texture && this.texture.hasAlpha;
  10604. },
  10605. enumerable: true,
  10606. configurable: true
  10607. });
  10608. Object.defineProperty(Sprite2D.prototype, "useAlphaFromTexture", {
  10609. get: function () {
  10610. return this._useAlphaFromTexture;
  10611. },
  10612. set: function (value) {
  10613. if (this._useAlphaFromTexture === value) {
  10614. return;
  10615. }
  10616. this._useAlphaFromTexture = value;
  10617. this._updateRenderMode();
  10618. },
  10619. enumerable: true,
  10620. configurable: true
  10621. });
  10622. Object.defineProperty(Sprite2D.prototype, "size", {
  10623. get: function () {
  10624. if (this._size == null) {
  10625. return this.spriteSize;
  10626. }
  10627. return this.internalGetSize();
  10628. },
  10629. set: function (value) {
  10630. this._useSize = value != null;
  10631. this.internalSetSize(value);
  10632. this._updateSpriteScaleFactor();
  10633. },
  10634. enumerable: true,
  10635. configurable: true
  10636. });
  10637. Object.defineProperty(Sprite2D.prototype, "actualSize", {
  10638. get: function () {
  10639. if (this._actualSize) {
  10640. return this._actualSize;
  10641. }
  10642. return this.size;
  10643. },
  10644. set: function (value) {
  10645. this._actualSize = value;
  10646. },
  10647. enumerable: true,
  10648. configurable: true
  10649. });
  10650. Object.defineProperty(Sprite2D.prototype, "spriteSize", {
  10651. get: function () {
  10652. return this._spriteSize;
  10653. },
  10654. set: function (value) {
  10655. this._spriteSize = value;
  10656. this._updateSpriteScaleFactor();
  10657. },
  10658. enumerable: true,
  10659. configurable: true
  10660. });
  10661. Object.defineProperty(Sprite2D.prototype, "spriteLocation", {
  10662. get: function () {
  10663. return this._spriteLocation;
  10664. },
  10665. set: function (value) {
  10666. this._spriteLocation = value;
  10667. },
  10668. enumerable: true,
  10669. configurable: true
  10670. });
  10671. Object.defineProperty(Sprite2D.prototype, "spriteFrame", {
  10672. get: function () {
  10673. return this._spriteFrame;
  10674. },
  10675. set: function (value) {
  10676. this._spriteFrame = value;
  10677. },
  10678. enumerable: true,
  10679. configurable: true
  10680. });
  10681. Object.defineProperty(Sprite2D.prototype, "invertY", {
  10682. get: function () {
  10683. return this._invertY;
  10684. },
  10685. set: function (value) {
  10686. this._invertY = value;
  10687. },
  10688. enumerable: true,
  10689. configurable: true
  10690. });
  10691. Object.defineProperty(Sprite2D.prototype, "isScale9", {
  10692. get: function () {
  10693. return this._scale9 !== null;
  10694. },
  10695. enumerable: true,
  10696. configurable: true
  10697. });
  10698. Object.defineProperty(Sprite2D.prototype, "alignToPixel", {
  10699. //@instanceLevelProperty(RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 7, pi => Sprite2D.spriteScaleFactorProperty = pi)
  10700. ///**
  10701. // * Get/set the sprite location (in pixels) in the texture
  10702. // */
  10703. //public get spriteScaleFactor(): Vector2 {
  10704. // return this._spriteScaleFactor;
  10705. //}
  10706. //public set spriteScaleFactor(value: Vector2) {
  10707. // this._spriteScaleFactor = value;
  10708. //}
  10709. /**
  10710. * Get/set if the sprite rendering should be aligned to the target rendering device pixel or not
  10711. */
  10712. get: function () {
  10713. return this._alignToPixel;
  10714. },
  10715. set: function (value) {
  10716. this._alignToPixel = value;
  10717. },
  10718. enumerable: true,
  10719. configurable: true
  10720. });
  10721. Sprite2D.prototype.updateLevelBoundingInfo = function () {
  10722. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.size, this._levelBoundingInfo);
  10723. };
  10724. /**
  10725. * Get the animatable array (see http://doc.babylonjs.com/tutorials/Animations)
  10726. */
  10727. Sprite2D.prototype.getAnimatables = function () {
  10728. var res = new Array();
  10729. if (this.texture && this.texture.animations && this.texture.animations.length > 0) {
  10730. res.push(this.texture);
  10731. }
  10732. return res;
  10733. };
  10734. Sprite2D.prototype.levelIntersect = function (intersectInfo) {
  10735. // If we've made it so far it means the boundingInfo intersection test succeed, the Sprite2D is shaped the same, so we always return true
  10736. return true;
  10737. };
  10738. Object.defineProperty(Sprite2D.prototype, "isSizeAuto", {
  10739. get: function () {
  10740. return this.size == null;
  10741. },
  10742. enumerable: true,
  10743. configurable: true
  10744. });
  10745. Sprite2D.prototype.createModelRenderCache = function (modelKey) {
  10746. var renderCache = new Sprite2DRenderCache(this.owner.engine, modelKey);
  10747. return renderCache;
  10748. };
  10749. Sprite2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  10750. var renderCache = modelRenderCache;
  10751. var engine = this.owner.engine;
  10752. var vb = new Float32Array(4);
  10753. for (var i = 0; i < 4; i++) {
  10754. vb[i] = i;
  10755. }
  10756. renderCache.vb = engine.createVertexBuffer(vb);
  10757. var ib = new Float32Array(6);
  10758. ib[0] = 0;
  10759. ib[1] = 2;
  10760. ib[2] = 1;
  10761. ib[3] = 0;
  10762. ib[4] = 3;
  10763. ib[5] = 2;
  10764. renderCache.ib = engine.createIndexBuffer(ib);
  10765. renderCache.texture = this.texture;
  10766. // Get the instanced version of the effect, if the engine does not support it, null is return and we'll only draw on by one
  10767. var ei = this.getDataPartEffectInfo(Sprite2D_1.SPRITE2D_MAINPARTID, ["index"], ["alphaTest"], true);
  10768. if (ei) {
  10769. renderCache.effectInstanced = engine.createEffect("sprite2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  10770. }
  10771. ei = this.getDataPartEffectInfo(Sprite2D_1.SPRITE2D_MAINPARTID, ["index"], ["alphaTest"], false);
  10772. renderCache.effect = engine.createEffect("sprite2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  10773. return renderCache;
  10774. };
  10775. Sprite2D.prototype.getUsedShaderCategories = function (dataPart) {
  10776. var cat = _super.prototype.getUsedShaderCategories.call(this, dataPart);
  10777. if (dataPart.id === Sprite2D_1.SPRITE2D_MAINPARTID) {
  10778. var useScale9 = this._scale9 != null;
  10779. if (useScale9) {
  10780. cat.push(Sprite2D_1.SHAPE2D_CATEGORY_SCALE9);
  10781. }
  10782. }
  10783. return cat;
  10784. };
  10785. Sprite2D.prototype.createInstanceDataParts = function () {
  10786. return [new Sprite2DInstanceData(Sprite2D_1.SPRITE2D_MAINPARTID)];
  10787. };
  10788. Sprite2D.prototype.beforeRefreshForLayoutConstruction = function (part) {
  10789. Sprite2D_1.layoutConstructMode = true;
  10790. };
  10791. // if obj contains something, we restore the _text property
  10792. Sprite2D.prototype.afterRefreshForLayoutConstruction = function (part, obj) {
  10793. Sprite2D_1.layoutConstructMode = false;
  10794. };
  10795. Sprite2D.prototype.refreshInstanceDataPart = function (part) {
  10796. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  10797. return false;
  10798. }
  10799. if (!this.texture.isReady() && !Sprite2D_1.layoutConstructMode) {
  10800. return false;
  10801. }
  10802. if (part.id === Sprite2D_1.SPRITE2D_MAINPARTID) {
  10803. var d = this._instanceDataParts[0];
  10804. if (Sprite2D_1.layoutConstructMode) {
  10805. d.topLeftUV = BABYLON.Vector2.Zero();
  10806. d.sizeUV = BABYLON.Vector2.Zero();
  10807. d.properties = BABYLON.Vector3.Zero();
  10808. d.textureSize = BABYLON.Vector2.Zero();
  10809. d.scaleFactor = BABYLON.Vector2.Zero();
  10810. if (this.isScale9) {
  10811. d.scale9 = BABYLON.Vector4.Zero();
  10812. }
  10813. }
  10814. else {
  10815. var ts = this.texture.getBaseSize();
  10816. var ss = this.spriteSize;
  10817. var sl = this.spriteLocation;
  10818. var ssf = this.actualScale;
  10819. d.topLeftUV = new BABYLON.Vector2(sl.x / ts.width, sl.y / ts.height);
  10820. var suv = new BABYLON.Vector2(ss.width / ts.width, ss.height / ts.height);
  10821. d.sizeUV = suv;
  10822. d.scaleFactor = ssf;
  10823. Sprite2D_1._prop.x = this.spriteFrame;
  10824. Sprite2D_1._prop.y = this.invertY ? 1 : 0;
  10825. Sprite2D_1._prop.z = this.alignToPixel ? 1 : 0;
  10826. d.properties = Sprite2D_1._prop;
  10827. d.textureSize = new BABYLON.Vector2(ts.width, ts.height);
  10828. var scale9 = this._scale9;
  10829. if (scale9 != null) {
  10830. var normalizedScale9 = new BABYLON.Vector4(scale9.x * suv.x / ss.width, scale9.y * suv.y / ss.height, scale9.z * suv.x / ss.width, scale9.w * suv.y / ss.height);
  10831. d.scale9 = normalizedScale9;
  10832. }
  10833. }
  10834. }
  10835. return true;
  10836. };
  10837. Sprite2D.prototype._mustUpdateInstance = function () {
  10838. var res = this._oldTextureHasAlpha !== (this.texture != null && this.texture.hasAlpha);
  10839. this._oldTextureHasAlpha = this.texture != null && this.texture.hasAlpha;
  10840. if (res) {
  10841. this._updateRenderMode();
  10842. }
  10843. return res;
  10844. };
  10845. Sprite2D.prototype._useTextureAlpha = function () {
  10846. return this.texture != null && this.texture.hasAlpha;
  10847. };
  10848. Sprite2D.prototype._shouldUseAlphaFromTexture = function () {
  10849. return this.texture != null && this.texture.hasAlpha && this.useAlphaFromTexture;
  10850. };
  10851. Sprite2D.prototype._updateSpriteScaleFactor = function () {
  10852. if (!this._useSize) {
  10853. return;
  10854. }
  10855. var sS = this.spriteSize;
  10856. var s = this.size;
  10857. if (s == null || sS == null) {
  10858. return;
  10859. }
  10860. this.scaleX = s.width / sS.width;
  10861. this.scaleY = s.height / sS.height;
  10862. };
  10863. return Sprite2D;
  10864. }(BABYLON.RenderablePrim2D));
  10865. Sprite2D.SPRITE2D_MAINPARTID = 1;
  10866. Sprite2D.SHAPE2D_CATEGORY_SCALE9 = "Scale9";
  10867. Sprite2D._prop = BABYLON.Vector3.Zero();
  10868. Sprite2D.layoutConstructMode = false;
  10869. __decorate([
  10870. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 1, function (pi) { return Sprite2D_1.textureProperty = pi; })
  10871. ], Sprite2D.prototype, "texture", null);
  10872. __decorate([
  10873. BABYLON.dynamicLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 2, function (pi) { return Sprite2D_1.useAlphaFromTextureProperty = pi; })
  10874. ], Sprite2D.prototype, "useAlphaFromTexture", null);
  10875. __decorate([
  10876. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 3, function (pi) { return Sprite2D_1.actualSizeProperty = pi; }, false, true)
  10877. ], Sprite2D.prototype, "actualSize", null);
  10878. __decorate([
  10879. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 4, function (pi) { return Sprite2D_1.spriteSizeProperty = pi; })
  10880. ], Sprite2D.prototype, "spriteSize", null);
  10881. __decorate([
  10882. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 5, function (pi) { return Sprite2D_1.spriteLocationProperty = pi; })
  10883. ], Sprite2D.prototype, "spriteLocation", null);
  10884. __decorate([
  10885. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 6, function (pi) { return Sprite2D_1.spriteFrameProperty = pi; })
  10886. ], Sprite2D.prototype, "spriteFrame", null);
  10887. __decorate([
  10888. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 7, function (pi) { return Sprite2D_1.invertYProperty = pi; })
  10889. ], Sprite2D.prototype, "invertY", null);
  10890. __decorate([
  10891. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 8, function (pi) { return Sprite2D_1.spriteScale9Property = pi; })
  10892. ], Sprite2D.prototype, "isScale9", null);
  10893. Sprite2D = Sprite2D_1 = __decorate([
  10894. BABYLON.className("Sprite2D", "BABYLON")
  10895. ], Sprite2D);
  10896. BABYLON.Sprite2D = Sprite2D;
  10897. var Sprite2DInstanceData = (function (_super) {
  10898. __extends(Sprite2DInstanceData, _super);
  10899. function Sprite2DInstanceData(partId) {
  10900. return _super.call(this, partId, 1) || this;
  10901. }
  10902. Object.defineProperty(Sprite2DInstanceData.prototype, "topLeftUV", {
  10903. get: function () {
  10904. return null;
  10905. },
  10906. set: function (value) {
  10907. },
  10908. enumerable: true,
  10909. configurable: true
  10910. });
  10911. Object.defineProperty(Sprite2DInstanceData.prototype, "sizeUV", {
  10912. get: function () {
  10913. return null;
  10914. },
  10915. set: function (value) {
  10916. },
  10917. enumerable: true,
  10918. configurable: true
  10919. });
  10920. Object.defineProperty(Sprite2DInstanceData.prototype, "scaleFactor", {
  10921. get: function () {
  10922. return null;
  10923. },
  10924. set: function (value) {
  10925. },
  10926. enumerable: true,
  10927. configurable: true
  10928. });
  10929. Object.defineProperty(Sprite2DInstanceData.prototype, "textureSize", {
  10930. get: function () {
  10931. return null;
  10932. },
  10933. set: function (value) {
  10934. },
  10935. enumerable: true,
  10936. configurable: true
  10937. });
  10938. Object.defineProperty(Sprite2DInstanceData.prototype, "properties", {
  10939. // 3 floats being:
  10940. // - x: frame number to display
  10941. // - y: invertY setting
  10942. // - z: alignToPixel setting
  10943. get: function () {
  10944. return null;
  10945. },
  10946. set: function (value) {
  10947. },
  10948. enumerable: true,
  10949. configurable: true
  10950. });
  10951. Object.defineProperty(Sprite2DInstanceData.prototype, "scale9", {
  10952. get: function () {
  10953. return null;
  10954. },
  10955. set: function (value) {
  10956. },
  10957. enumerable: true,
  10958. configurable: true
  10959. });
  10960. return Sprite2DInstanceData;
  10961. }(BABYLON.InstanceDataBase));
  10962. __decorate([
  10963. BABYLON.instanceData()
  10964. ], Sprite2DInstanceData.prototype, "topLeftUV", null);
  10965. __decorate([
  10966. BABYLON.instanceData()
  10967. ], Sprite2DInstanceData.prototype, "sizeUV", null);
  10968. __decorate([
  10969. BABYLON.instanceData(Sprite2D.SHAPE2D_CATEGORY_SCALE9)
  10970. ], Sprite2DInstanceData.prototype, "scaleFactor", null);
  10971. __decorate([
  10972. BABYLON.instanceData()
  10973. ], Sprite2DInstanceData.prototype, "textureSize", null);
  10974. __decorate([
  10975. BABYLON.instanceData()
  10976. ], Sprite2DInstanceData.prototype, "properties", null);
  10977. __decorate([
  10978. BABYLON.instanceData(Sprite2D.SHAPE2D_CATEGORY_SCALE9)
  10979. ], Sprite2DInstanceData.prototype, "scale9", null);
  10980. BABYLON.Sprite2DInstanceData = Sprite2DInstanceData;
  10981. var Sprite2D_1;
  10982. })(BABYLON || (BABYLON = {}));
  10983. //# sourceMappingURL=babylon.sprite2d.js.map
  10984. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  10985. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  10986. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  10987. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  10988. return c > 3 && r && Object.defineProperty(target, key, r), r;
  10989. };
  10990. var BABYLON;
  10991. (function (BABYLON) {
  10992. /**
  10993. * This class will contains information about a sub picture present in an Atlas Picture.
  10994. */
  10995. var AtlasSubPictureInfo = (function () {
  10996. function AtlasSubPictureInfo() {
  10997. }
  10998. return AtlasSubPictureInfo;
  10999. }());
  11000. BABYLON.AtlasSubPictureInfo = AtlasSubPictureInfo;
  11001. /**
  11002. * This class represent an Atlas Picture, it contains the information of all the sub pictures and the Texture that stores the bitmap.
  11003. * You get an instance of this class using methods of the AtlasPictureInfoFactory
  11004. */
  11005. var AtlasPictureInfo = (function () {
  11006. function AtlasPictureInfo() {
  11007. }
  11008. /**
  11009. * Creates many sprite from the Atlas Picture
  11010. * @param filterCallback a predicate if true is returned then the corresponding sub picture will be used to create a sprite.
  11011. * The Predicate has many parameters:
  11012. * - index: just an index incremented at each sub picture submitted for Sprite creation
  11013. * - name: the sub picture's name
  11014. * - aspi: the AtlasSubPictureInfo corresponding to the submitted sub picture
  11015. * - settings: the Sprite2D creation settings, you can alter this JSON object but BEWARE, the alterations will be kept for subsequent Sprite2D creations!
  11016. * @param spriteSettings The Sprite2D settings to use for Sprite creation, this JSON object will be passed to the filterCallback for you to alter it, if needed.
  11017. */
  11018. AtlasPictureInfo.prototype.createSprites = function (filterCallback, spriteSettings) {
  11019. var _this = this;
  11020. var res = new Array();
  11021. var index = 0;
  11022. this.subPictures.forEach(function (k, v) {
  11023. if (!filterCallback || filterCallback(index++, k, v, spriteSettings)) {
  11024. var s = _this.createSprite(k, spriteSettings);
  11025. if (s) {
  11026. res.push(s);
  11027. }
  11028. }
  11029. });
  11030. return res;
  11031. };
  11032. /**
  11033. * Create one Sprite from a sub picture
  11034. * @param subPictureName the name of the sub picture to use
  11035. * @param spriteSettings the Sprite2D settings to use for the Sprite instance creation
  11036. */
  11037. AtlasPictureInfo.prototype.createSprite = function (subPictureName, spriteSettings) {
  11038. var spi = this.subPictures.get(subPictureName);
  11039. if (!spi) {
  11040. return null;
  11041. }
  11042. if (!spriteSettings) {
  11043. spriteSettings = {};
  11044. }
  11045. var s = spriteSettings;
  11046. s.id = subPictureName;
  11047. s.spriteLocation = spi.location;
  11048. s.spriteSize = spi.size;
  11049. var sprite = new BABYLON.Sprite2D(this.texture, spriteSettings);
  11050. return sprite;
  11051. };
  11052. return AtlasPictureInfo;
  11053. }());
  11054. BABYLON.AtlasPictureInfo = AtlasPictureInfo;
  11055. /**
  11056. * This if the Factory class containing static method to create Atlas Pictures Info objects or add new loaders
  11057. */
  11058. var AtlasPictureInfoFactory = (function () {
  11059. function AtlasPictureInfoFactory() {
  11060. }
  11061. /**
  11062. * Add a custom loader
  11063. * @param fileExtension must be the file extension (without the dot) of the file that is loaded by this loader (e.g.: json)
  11064. * @param plugin the instance of the loader
  11065. */
  11066. AtlasPictureInfoFactory.addLoader = function (fileExtension, plugin) {
  11067. var a = AtlasPictureInfoFactory.plugins.getOrAddWithFactory(fileExtension.toLocaleLowerCase(), function () { return new Array(); });
  11068. a.push(plugin);
  11069. };
  11070. /**
  11071. * Load an Atlas Picture Info object from a data file at a given url and with a given texture
  11072. * @param texture the texture containing the atlas bitmap
  11073. * @param url the URL of the Atlas Info data file
  11074. * @param onLoad a callback that will be called when the AtlasPictureInfo object will be loaded and ready
  11075. * @param onError a callback that will be called in case of error
  11076. */
  11077. AtlasPictureInfoFactory.loadFromUrl = function (texture, url, onLoad, onError) {
  11078. if (onError === void 0) { onError = null; }
  11079. var xhr = new XMLHttpRequest();
  11080. xhr.onreadystatechange = function () {
  11081. if (xhr.readyState === XMLHttpRequest.DONE) {
  11082. if (xhr.status === 200) {
  11083. var ext = url.split('.').pop().split(/\#|\?/)[0];
  11084. var plugins = AtlasPictureInfoFactory.plugins.get(ext.toLocaleLowerCase());
  11085. if (!plugins) {
  11086. if (onError) {
  11087. onError("couldn't find a plugin for this file extension", -1);
  11088. }
  11089. return;
  11090. }
  11091. for (var _i = 0, plugins_1 = plugins; _i < plugins_1.length; _i++) {
  11092. var p = plugins_1[_i];
  11093. var ret = p.loadFile(xhr.response);
  11094. if (ret) {
  11095. if (ret.api) {
  11096. ret.api.texture = texture;
  11097. if (onLoad) {
  11098. onLoad(ret.api);
  11099. }
  11100. }
  11101. else if (onError) {
  11102. onError(ret.errorMsg, ret.errorCode);
  11103. }
  11104. return;
  11105. }
  11106. }
  11107. if (onError) {
  11108. onError("No plugin to load this Atlas Data file format", -1);
  11109. }
  11110. }
  11111. else {
  11112. if (onError) {
  11113. onError("Couldn't load file through HTTP Request, HTTP Status " + xhr.status, xhr.status);
  11114. }
  11115. }
  11116. }
  11117. };
  11118. xhr.open("GET", url, true);
  11119. xhr.send();
  11120. return null;
  11121. };
  11122. return AtlasPictureInfoFactory;
  11123. }());
  11124. AtlasPictureInfoFactory.plugins = new BABYLON.StringDictionary();
  11125. BABYLON.AtlasPictureInfoFactory = AtlasPictureInfoFactory;
  11126. // Loader class for the TexturePacker's JSON Array data format
  11127. var JSONArrayLoader = JSONArrayLoader_1 = (function () {
  11128. function JSONArrayLoader() {
  11129. }
  11130. JSONArrayLoader.prototype.loadFile = function (content) {
  11131. var errorMsg = null;
  11132. var errorCode = 0;
  11133. var root = null;
  11134. var api = null;
  11135. try {
  11136. var frames_1;
  11137. var meta = void 0;
  11138. try {
  11139. root = JSON.parse(content);
  11140. frames_1 = root.frames;
  11141. meta = root.meta;
  11142. if (!frames_1 || !meta) {
  11143. throw Error("Not a JSON Array file format");
  11144. }
  11145. }
  11146. catch (ex1) {
  11147. return null;
  11148. }
  11149. api = new AtlasPictureInfo();
  11150. api.atlasSize = new BABYLON.Size(meta.size.w, meta.size.h);
  11151. api.subPictures = new BABYLON.StringDictionary();
  11152. for (var _i = 0, frames_2 = frames_1; _i < frames_2.length; _i++) {
  11153. var f = frames_2[_i];
  11154. var aspi = new AtlasSubPictureInfo();
  11155. aspi.name = f.filename;
  11156. aspi.location = new BABYLON.Vector2(f.frame.x, api.atlasSize.height - (f.frame.y + f.frame.h));
  11157. aspi.size = new BABYLON.Size(f.frame.w, f.frame.h);
  11158. api.subPictures.add(aspi.name, aspi);
  11159. }
  11160. }
  11161. catch (ex2) {
  11162. errorMsg = "Unknown Exception: " + ex2;
  11163. errorCode = -2;
  11164. }
  11165. return { api: api, errorMsg: errorMsg, errorCode: errorCode };
  11166. };
  11167. return JSONArrayLoader;
  11168. }());
  11169. JSONArrayLoader = JSONArrayLoader_1 = __decorate([
  11170. AtlasLoaderPlugin("json", new JSONArrayLoader_1())
  11171. ], JSONArrayLoader);
  11172. /**
  11173. * Use this decorator when you declare an Atlas Loader Class for the loader to register itself automatically.
  11174. * @param fileExtension the extension of the file that the plugin is loading (there can be many plugin for the same extension)
  11175. * @param plugin an instance of the plugin class to add to the AtlasPictureInfoFactory
  11176. */
  11177. function AtlasLoaderPlugin(fileExtension, plugin) {
  11178. return function () {
  11179. AtlasPictureInfoFactory.addLoader(fileExtension, plugin);
  11180. };
  11181. }
  11182. BABYLON.AtlasLoaderPlugin = AtlasLoaderPlugin;
  11183. var JSONArrayLoader_1;
  11184. })(BABYLON || (BABYLON = {}));
  11185. var __extends = (this && this.__extends) || function (d, b) {
  11186. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  11187. function __() { this.constructor = d; }
  11188. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  11189. };
  11190. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  11191. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  11192. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  11193. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  11194. return c > 3 && r && Object.defineProperty(target, key, r), r;
  11195. };
  11196. var BABYLON;
  11197. (function (BABYLON) {
  11198. var Text2DRenderCache = (function (_super) {
  11199. __extends(Text2DRenderCache, _super);
  11200. function Text2DRenderCache() {
  11201. var _this = _super.apply(this, arguments) || this;
  11202. _this.effectsReady = false;
  11203. _this.vb = null;
  11204. _this.ib = null;
  11205. _this.instancingAttributes = null;
  11206. _this.fontTexture = null;
  11207. _this.effect = null;
  11208. _this.effectInstanced = null;
  11209. return _this;
  11210. }
  11211. Text2DRenderCache.prototype.render = function (instanceInfo, context) {
  11212. // Do nothing if the shader is still loading/preparing
  11213. if (!this.effectsReady) {
  11214. if ((this.effect && (!this.effect.isReady() || (this.effectInstanced && !this.effectInstanced.isReady())))) {
  11215. return false;
  11216. }
  11217. this.effectsReady = true;
  11218. }
  11219. var canvas = instanceInfo.owner.owner;
  11220. var engine = canvas.engine;
  11221. this.fontTexture.update();
  11222. var effect = context.useInstancing ? this.effectInstanced : this.effect;
  11223. engine.enableEffect(effect);
  11224. effect.setTexture("diffuseSampler", this.fontTexture);
  11225. engine.bindBuffersDirectly(this.vb, this.ib, [1], 4, effect);
  11226. var sdf = this.fontTexture.isSignedDistanceField;
  11227. // Enable alpha mode only if the texture is not using SDF, SDF is rendered in AlphaTest mode, which mean no alpha blend
  11228. var curAlphaMode;
  11229. if (!sdf) {
  11230. curAlphaMode = engine.getAlphaMode();
  11231. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  11232. }
  11233. var pid = context.groupInfoPartData[0];
  11234. if (context.useInstancing) {
  11235. if (!this.instancingAttributes) {
  11236. this.instancingAttributes = this.loadInstancingAttributes(Text2D.TEXT2D_MAINPARTID, effect);
  11237. }
  11238. var glBuffer = context.instancedBuffers ? context.instancedBuffers[0] : pid._partBuffer;
  11239. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  11240. canvas._addDrawCallCount(1, context.renderMode);
  11241. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingAttributes);
  11242. engine.draw(true, 0, 6, count);
  11243. engine.unbindInstanceAttributes();
  11244. }
  11245. else {
  11246. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  11247. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  11248. this.setupUniforms(effect, 0, pid._partData, i);
  11249. engine.draw(true, 0, 6);
  11250. }
  11251. }
  11252. if (!sdf) {
  11253. engine.setAlphaMode(curAlphaMode, true);
  11254. }
  11255. return true;
  11256. };
  11257. Text2DRenderCache.prototype.dispose = function () {
  11258. if (!_super.prototype.dispose.call(this)) {
  11259. return false;
  11260. }
  11261. if (this.vb) {
  11262. this._engine._releaseBuffer(this.vb);
  11263. this.vb = null;
  11264. }
  11265. if (this.ib) {
  11266. this._engine._releaseBuffer(this.ib);
  11267. this.ib = null;
  11268. }
  11269. if (this.fontTexture) {
  11270. this.fontTexture.decCachedFontTextureCounter();
  11271. this.fontTexture = null;
  11272. }
  11273. this.effect = null;
  11274. this.effectInstanced = null;
  11275. return true;
  11276. };
  11277. return Text2DRenderCache;
  11278. }(BABYLON.ModelRenderCache));
  11279. BABYLON.Text2DRenderCache = Text2DRenderCache;
  11280. var Text2DInstanceData = (function (_super) {
  11281. __extends(Text2DInstanceData, _super);
  11282. function Text2DInstanceData(partId, dataElementCount) {
  11283. return _super.call(this, partId, dataElementCount) || this;
  11284. }
  11285. Object.defineProperty(Text2DInstanceData.prototype, "topLeftUV", {
  11286. get: function () {
  11287. return null;
  11288. },
  11289. set: function (value) {
  11290. },
  11291. enumerable: true,
  11292. configurable: true
  11293. });
  11294. Object.defineProperty(Text2DInstanceData.prototype, "sizeUV", {
  11295. get: function () {
  11296. return null;
  11297. },
  11298. set: function (value) {
  11299. },
  11300. enumerable: true,
  11301. configurable: true
  11302. });
  11303. Object.defineProperty(Text2DInstanceData.prototype, "textureSize", {
  11304. get: function () {
  11305. return null;
  11306. },
  11307. set: function (value) {
  11308. },
  11309. enumerable: true,
  11310. configurable: true
  11311. });
  11312. Object.defineProperty(Text2DInstanceData.prototype, "color", {
  11313. get: function () {
  11314. return null;
  11315. },
  11316. set: function (value) {
  11317. },
  11318. enumerable: true,
  11319. configurable: true
  11320. });
  11321. Object.defineProperty(Text2DInstanceData.prototype, "superSampleFactor", {
  11322. get: function () {
  11323. return null;
  11324. },
  11325. set: function (value) {
  11326. },
  11327. enumerable: true,
  11328. configurable: true
  11329. });
  11330. return Text2DInstanceData;
  11331. }(BABYLON.InstanceDataBase));
  11332. __decorate([
  11333. BABYLON.instanceData()
  11334. ], Text2DInstanceData.prototype, "topLeftUV", null);
  11335. __decorate([
  11336. BABYLON.instanceData()
  11337. ], Text2DInstanceData.prototype, "sizeUV", null);
  11338. __decorate([
  11339. BABYLON.instanceData()
  11340. ], Text2DInstanceData.prototype, "textureSize", null);
  11341. __decorate([
  11342. BABYLON.instanceData()
  11343. ], Text2DInstanceData.prototype, "color", null);
  11344. __decorate([
  11345. BABYLON.instanceData()
  11346. ], Text2DInstanceData.prototype, "superSampleFactor", null);
  11347. BABYLON.Text2DInstanceData = Text2DInstanceData;
  11348. var Text2D = Text2D_1 = (function (_super) {
  11349. __extends(Text2D, _super);
  11350. /**
  11351. * Create a Text primitive
  11352. * @param text the text to display
  11353. * @param settings a combination of settings, possible ones are
  11354. * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
  11355. * - children: an array of direct children
  11356. * - id a text identifier, for information purpose
  11357. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  11358. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  11359. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  11360. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  11361. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  11362. * - zOrder: override the zOrder with the specified value
  11363. * - origin: define the normalized origin point location, default [0.5;0.5]
  11364. * - fontName: the name/size/style of the font to use, following the CSS notation. Default is "12pt Arial".
  11365. * - fontSuperSample: if true the text will be rendered with a superSampled font (the font is twice the given size). Use this settings if the text lies in world space or if it's scaled in.
  11366. * - signedDistanceField: if true the text will be rendered using the SignedDistanceField technique. This technique has the advantage to be rendered order independent (then much less drawing calls), but only works on font that are a little more than one pixel wide on the screen but the rendering quality is excellent whatever the font size is on the screen (which is the purpose of this technique). Outlining/Shadow is not supported right now. If you can, you should use this mode, the quality and the performances are the best. Note that fontSuperSample has no effect when this mode is on.
  11367. * - defaultFontColor: the color by default to apply on each letter of the text to display, default is plain white.
  11368. * - areaSize: the size of the area in which to display the text, default is auto-fit from text content.
  11369. * - tabulationSize: number of space character to insert when a tabulation is encountered, default is 4
  11370. * - isVisible: true if the text must be visible, false for hidden. Default is true.
  11371. * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
  11372. * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
  11373. * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
  11374. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  11375. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  11376. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  11377. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  11378. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  11379. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  11380. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  11381. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  11382. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  11383. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  11384. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  11385. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  11386. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  11387. */
  11388. function Text2D(text, settings) {
  11389. var _this;
  11390. if (!settings) {
  11391. settings = {};
  11392. }
  11393. _this = _super.call(this, settings) || this;
  11394. if (settings.bitmapFontTexture != null) {
  11395. _this._fontTexture = settings.bitmapFontTexture;
  11396. _this._fontName = null;
  11397. _this._fontSuperSample = false;
  11398. _this._fontSDF = false;
  11399. }
  11400. else {
  11401. _this._fontName = (settings.fontName == null) ? "12pt Arial" : settings.fontName;
  11402. _this._fontSuperSample = (settings.fontSuperSample != null && settings.fontSuperSample);
  11403. _this._fontSDF = (settings.fontSignedDistanceField != null && settings.fontSignedDistanceField);
  11404. }
  11405. _this.defaultFontColor = (settings.defaultFontColor == null) ? new BABYLON.Color4(1, 1, 1, 1) : settings.defaultFontColor;
  11406. _this._tabulationSize = (settings.tabulationSize == null) ? 4 : settings.tabulationSize;
  11407. _this._textSize = null;
  11408. _this.text = text;
  11409. _this.size = (settings.size == null) ? null : settings.size;
  11410. _this._updateRenderMode();
  11411. return _this;
  11412. }
  11413. Object.defineProperty(Text2D.prototype, "fontName", {
  11414. get: function () {
  11415. return this._fontName;
  11416. },
  11417. set: function (value) {
  11418. if (this._fontName) {
  11419. throw new Error("Font Name change is not supported right now.");
  11420. }
  11421. this._fontName = value;
  11422. },
  11423. enumerable: true,
  11424. configurable: true
  11425. });
  11426. Object.defineProperty(Text2D.prototype, "defaultFontColor", {
  11427. get: function () {
  11428. return this._defaultFontColor;
  11429. },
  11430. set: function (value) {
  11431. this._defaultFontColor = value;
  11432. },
  11433. enumerable: true,
  11434. configurable: true
  11435. });
  11436. Object.defineProperty(Text2D.prototype, "text", {
  11437. get: function () {
  11438. return this._text;
  11439. },
  11440. set: function (value) {
  11441. if (!value) {
  11442. value = "";
  11443. }
  11444. this._text = value;
  11445. this._textSize = null; // A change of text will reset the TextSize which will be recomputed next time it's used
  11446. this._size = null;
  11447. this._updateCharCount();
  11448. // Trigger a textSize to for a sizeChange if necessary, which is needed for layout to recompute
  11449. var s = this.textSize;
  11450. },
  11451. enumerable: true,
  11452. configurable: true
  11453. });
  11454. Object.defineProperty(Text2D.prototype, "size", {
  11455. get: function () {
  11456. if (this._size != null) {
  11457. return this._size;
  11458. }
  11459. return this.textSize;
  11460. },
  11461. set: function (value) {
  11462. this._size = value;
  11463. },
  11464. enumerable: true,
  11465. configurable: true
  11466. });
  11467. Object.defineProperty(Text2D.prototype, "fontSuperSample", {
  11468. get: function () {
  11469. return this._fontTexture && this._fontTexture.isSuperSampled;
  11470. },
  11471. enumerable: true,
  11472. configurable: true
  11473. });
  11474. Object.defineProperty(Text2D.prototype, "fontSignedDistanceField", {
  11475. get: function () {
  11476. return this._fontTexture && this._fontTexture.isSignedDistanceField;
  11477. },
  11478. enumerable: true,
  11479. configurable: true
  11480. });
  11481. Object.defineProperty(Text2D.prototype, "isSizeAuto", {
  11482. get: function () {
  11483. return false;
  11484. },
  11485. enumerable: true,
  11486. configurable: true
  11487. });
  11488. Object.defineProperty(Text2D.prototype, "actualSize", {
  11489. /**
  11490. * Get the actual size of the Text2D primitive
  11491. */
  11492. get: function () {
  11493. if (this._actualSize) {
  11494. return this._actualSize;
  11495. }
  11496. return this.size;
  11497. },
  11498. enumerable: true,
  11499. configurable: true
  11500. });
  11501. Object.defineProperty(Text2D.prototype, "textSize", {
  11502. /**
  11503. * Get the area that bounds the text associated to the primitive
  11504. */
  11505. get: function () {
  11506. if (!this._textSize) {
  11507. if (this.owner && this._text) {
  11508. var newSize = this.fontTexture.measureText(this._text, this._tabulationSize);
  11509. if (!newSize.equals(this._textSize)) {
  11510. this.onPrimitivePropertyDirty(BABYLON.Prim2DBase.sizeProperty.flagId);
  11511. this._positioningDirty();
  11512. }
  11513. this._textSize = newSize;
  11514. }
  11515. else {
  11516. return Text2D_1.nullSize;
  11517. }
  11518. }
  11519. return this._textSize;
  11520. },
  11521. enumerable: true,
  11522. configurable: true
  11523. });
  11524. Object.defineProperty(Text2D.prototype, "fontTexture", {
  11525. get: function () {
  11526. if (this._fontTexture) {
  11527. return this._fontTexture;
  11528. }
  11529. if (this.fontName == null || this.owner == null || this.owner.scene == null) {
  11530. return null;
  11531. }
  11532. this._fontTexture = BABYLON.FontTexture.GetCachedFontTexture(this.owner.scene, this.fontName, this._fontSuperSample, this._fontSDF);
  11533. return this._fontTexture;
  11534. },
  11535. enumerable: true,
  11536. configurable: true
  11537. });
  11538. /**
  11539. * Dispose the primitive, remove it from its parent
  11540. */
  11541. Text2D.prototype.dispose = function () {
  11542. if (!_super.prototype.dispose.call(this)) {
  11543. return false;
  11544. }
  11545. if (this._fontTexture) {
  11546. BABYLON.FontTexture.ReleaseCachedFontTexture(this.owner.scene, this.fontName, this._fontSuperSample, this._fontSDF);
  11547. this._fontTexture = null;
  11548. }
  11549. return true;
  11550. };
  11551. Text2D.prototype.updateLevelBoundingInfo = function () {
  11552. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.actualSize, this._levelBoundingInfo);
  11553. };
  11554. Text2D.prototype.levelIntersect = function (intersectInfo) {
  11555. // For now I can't do something better that boundingInfo is a hit, detecting an intersection on a particular letter would be possible, but do we really need it? Not for now...
  11556. return true;
  11557. };
  11558. Text2D.prototype.createModelRenderCache = function (modelKey) {
  11559. var renderCache = new Text2DRenderCache(this.owner.engine, modelKey);
  11560. return renderCache;
  11561. };
  11562. Text2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  11563. var renderCache = modelRenderCache;
  11564. var engine = this.owner.engine;
  11565. renderCache.fontTexture = this.fontTexture;
  11566. renderCache.fontTexture.incCachedFontTextureCounter();
  11567. var vb = new Float32Array(4);
  11568. for (var i = 0; i < 4; i++) {
  11569. vb[i] = i;
  11570. }
  11571. renderCache.vb = engine.createVertexBuffer(vb);
  11572. var ib = new Float32Array(6);
  11573. ib[0] = 0;
  11574. ib[1] = 2;
  11575. ib[2] = 1;
  11576. ib[3] = 0;
  11577. ib[4] = 3;
  11578. ib[5] = 2;
  11579. renderCache.ib = engine.createIndexBuffer(ib);
  11580. // Get the instanced version of the effect, if the engine does not support it, null is return and we'll only draw on by one
  11581. var ei = this.getDataPartEffectInfo(Text2D_1.TEXT2D_MAINPARTID, ["index"], null, true);
  11582. if (ei) {
  11583. renderCache.effectInstanced = engine.createEffect("text2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  11584. }
  11585. ei = this.getDataPartEffectInfo(Text2D_1.TEXT2D_MAINPARTID, ["index"], null, false);
  11586. renderCache.effect = engine.createEffect("text2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  11587. return renderCache;
  11588. };
  11589. Text2D.prototype.createInstanceDataParts = function () {
  11590. return [new Text2DInstanceData(Text2D_1.TEXT2D_MAINPARTID, this._charCount)];
  11591. };
  11592. // Looks like a hack!? Yes! Because that's what it is!
  11593. // For the InstanceData layer to compute correctly we need to set all the properties involved, which won't be the case if there's no text
  11594. // This method is called before the layout construction for us to detect this case, set some text and return the initial one to restore it after (there can be some text without char to display, say "\t\n" for instance)
  11595. Text2D.prototype.beforeRefreshForLayoutConstruction = function (part) {
  11596. if (!this._charCount) {
  11597. var curText = this._text;
  11598. this.text = "A";
  11599. return curText;
  11600. }
  11601. };
  11602. // if obj contains something, we restore the _text property
  11603. Text2D.prototype.afterRefreshForLayoutConstruction = function (part, obj) {
  11604. if (obj !== undefined) {
  11605. this.text = obj;
  11606. }
  11607. };
  11608. Text2D.prototype.getUsedShaderCategories = function (dataPart) {
  11609. var cat = _super.prototype.getUsedShaderCategories.call(this, dataPart);
  11610. if (this._fontSDF) {
  11611. cat.push(Text2D_1.TEXT2D_CATEGORY_SDF);
  11612. }
  11613. return cat;
  11614. };
  11615. Text2D.prototype.refreshInstanceDataPart = function (part) {
  11616. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  11617. return false;
  11618. }
  11619. if (part.id === Text2D_1.TEXT2D_MAINPARTID) {
  11620. var d = part;
  11621. var texture = this.fontTexture;
  11622. var superSampleFactor = texture.isSuperSampled ? 0.5 : 1;
  11623. var ts = texture.getSize();
  11624. var offset = BABYLON.Vector2.Zero();
  11625. var lh = this.fontTexture.lineHeight;
  11626. offset.y = ((this.textSize.height / lh) - 1) * lh; // Origin is bottom, not top, so the offset is starting with a y that is the top location of the text
  11627. var charxpos = 0;
  11628. d.dataElementCount = this._charCount;
  11629. d.curElement = 0;
  11630. for (var _i = 0, _a = this.text; _i < _a.length; _i++) {
  11631. var char = _a[_i];
  11632. // Line feed
  11633. if (char === "\n") {
  11634. offset.x = 0;
  11635. offset.y -= texture.lineHeight;
  11636. }
  11637. // Tabulation ?
  11638. if (char === "\t") {
  11639. var nextPos = charxpos + this._tabulationSize;
  11640. nextPos = nextPos - (nextPos % this._tabulationSize);
  11641. offset.x += (nextPos - charxpos) * texture.spaceWidth;
  11642. charxpos = nextPos;
  11643. continue;
  11644. }
  11645. if (char < " ") {
  11646. continue;
  11647. }
  11648. this.updateInstanceDataPart(d, offset);
  11649. var ci = texture.getChar(char);
  11650. offset.x += ci.charWidth;
  11651. d.topLeftUV = ci.topLeftUV;
  11652. var suv = ci.bottomRightUV.subtract(ci.topLeftUV);
  11653. d.sizeUV = suv;
  11654. d.textureSize = new BABYLON.Vector2(ts.width, ts.height);
  11655. d.color = this.defaultFontColor;
  11656. d.superSampleFactor = superSampleFactor;
  11657. ++d.curElement;
  11658. }
  11659. }
  11660. return true;
  11661. };
  11662. Text2D.prototype._updateCharCount = function () {
  11663. var count = 0;
  11664. for (var _i = 0, _a = this._text; _i < _a.length; _i++) {
  11665. var char = _a[_i];
  11666. if (char === "\r" || char === "\n" || char === "\t" || char < " ") {
  11667. continue;
  11668. }
  11669. ++count;
  11670. }
  11671. this._charCount = count;
  11672. };
  11673. Text2D.prototype._useTextureAlpha = function () {
  11674. return this._fontSDF;
  11675. };
  11676. Text2D.prototype._shouldUseAlphaFromTexture = function () {
  11677. return !this._fontSDF;
  11678. };
  11679. return Text2D;
  11680. }(BABYLON.RenderablePrim2D));
  11681. Text2D.TEXT2D_MAINPARTID = 1;
  11682. Text2D.TEXT2D_CATEGORY_SDF = "SignedDistanceField";
  11683. __decorate([
  11684. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 1, function (pi) { return Text2D_1.fontProperty = pi; }, false, true)
  11685. ], Text2D.prototype, "fontName", null);
  11686. __decorate([
  11687. BABYLON.dynamicLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 2, function (pi) { return Text2D_1.defaultFontColorProperty = pi; })
  11688. ], Text2D.prototype, "defaultFontColor", null);
  11689. __decorate([
  11690. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 3, function (pi) { return Text2D_1.textProperty = pi; }, false, true)
  11691. ], Text2D.prototype, "text", null);
  11692. __decorate([
  11693. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 4, function (pi) { return Text2D_1.sizeProperty = pi; })
  11694. ], Text2D.prototype, "size", null);
  11695. __decorate([
  11696. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 5, function (pi) { return Text2D_1.fontSuperSampleProperty = pi; }, false, false)
  11697. ], Text2D.prototype, "fontSuperSample", null);
  11698. __decorate([
  11699. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 6, function (pi) { return Text2D_1.fontSuperSampleProperty = pi; }, false, false)
  11700. ], Text2D.prototype, "fontSignedDistanceField", null);
  11701. Text2D = Text2D_1 = __decorate([
  11702. BABYLON.className("Text2D", "BABYLON")
  11703. ], Text2D);
  11704. BABYLON.Text2D = Text2D;
  11705. var Text2D_1;
  11706. })(BABYLON || (BABYLON = {}));
  11707. var __extends = (this && this.__extends) || function (d, b) {
  11708. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  11709. function __() { this.constructor = d; }
  11710. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  11711. };
  11712. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  11713. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  11714. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  11715. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  11716. return c > 3 && r && Object.defineProperty(target, key, r), r;
  11717. };
  11718. var BABYLON;
  11719. (function (BABYLON) {
  11720. var Lines2DRenderCache = (function (_super) {
  11721. __extends(Lines2DRenderCache, _super);
  11722. function Lines2DRenderCache(engine, modelKey) {
  11723. var _this = _super.call(this, engine, modelKey) || this;
  11724. _this.effectsReady = false;
  11725. _this.fillVB = null;
  11726. _this.fillIB = null;
  11727. _this.fillIndicesCount = 0;
  11728. _this.instancingFillAttributes = null;
  11729. _this.effectFill = null;
  11730. _this.effectFillInstanced = null;
  11731. _this.borderVB = null;
  11732. _this.borderIB = null;
  11733. _this.borderIndicesCount = 0;
  11734. _this.instancingBorderAttributes = null;
  11735. _this.effectBorder = null;
  11736. _this.effectBorderInstanced = null;
  11737. return _this;
  11738. }
  11739. Lines2DRenderCache.prototype.render = function (instanceInfo, context) {
  11740. // Do nothing if the shader is still loading/preparing
  11741. if (!this.effectsReady) {
  11742. if ((this.effectFill && (!this.effectFill.isReady() || (this.effectFillInstanced && !this.effectFillInstanced.isReady()))) ||
  11743. (this.effectBorder && (!this.effectBorder.isReady() || (this.effectBorderInstanced && !this.effectBorderInstanced.isReady())))) {
  11744. return false;
  11745. }
  11746. this.effectsReady = true;
  11747. }
  11748. var canvas = instanceInfo.owner.owner;
  11749. var engine = canvas.engine;
  11750. var depthFunction = 0;
  11751. if (this.effectFill && this.effectBorder) {
  11752. depthFunction = engine.getDepthFunction();
  11753. engine.setDepthFunctionToLessOrEqual();
  11754. }
  11755. var curAlphaMode = engine.getAlphaMode();
  11756. if (this.effectFill) {
  11757. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_FILLPARTID.toString());
  11758. var pid = context.groupInfoPartData[partIndex];
  11759. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  11760. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  11761. }
  11762. var effect = context.useInstancing ? this.effectFillInstanced : this.effectFill;
  11763. engine.enableEffect(effect);
  11764. engine.bindBuffersDirectly(this.fillVB, this.fillIB, [2], 2 * 4, effect);
  11765. if (context.useInstancing) {
  11766. if (!this.instancingFillAttributes) {
  11767. this.instancingFillAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_FILLPARTID, effect);
  11768. }
  11769. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  11770. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  11771. canvas._addDrawCallCount(1, context.renderMode);
  11772. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingFillAttributes);
  11773. engine.draw(true, 0, this.fillIndicesCount, count);
  11774. engine.unbindInstanceAttributes();
  11775. }
  11776. else {
  11777. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  11778. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  11779. this.setupUniforms(effect, partIndex, pid._partData, i);
  11780. engine.draw(true, 0, this.fillIndicesCount);
  11781. }
  11782. }
  11783. }
  11784. if (this.effectBorder) {
  11785. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_BORDERPARTID.toString());
  11786. var pid = context.groupInfoPartData[partIndex];
  11787. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  11788. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  11789. }
  11790. var effect = context.useInstancing ? this.effectBorderInstanced : this.effectBorder;
  11791. engine.enableEffect(effect);
  11792. engine.bindBuffersDirectly(this.borderVB, this.borderIB, [2], 2 * 4, effect);
  11793. if (context.useInstancing) {
  11794. if (!this.instancingBorderAttributes) {
  11795. this.instancingBorderAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, effect);
  11796. }
  11797. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  11798. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  11799. canvas._addDrawCallCount(1, context.renderMode);
  11800. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingBorderAttributes);
  11801. engine.draw(true, 0, this.borderIndicesCount, count);
  11802. engine.unbindInstanceAttributes();
  11803. }
  11804. else {
  11805. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  11806. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  11807. this.setupUniforms(effect, partIndex, pid._partData, i);
  11808. engine.draw(true, 0, this.borderIndicesCount);
  11809. }
  11810. }
  11811. }
  11812. engine.setAlphaMode(curAlphaMode, true);
  11813. if (this.effectFill && this.effectBorder) {
  11814. engine.setDepthFunction(depthFunction);
  11815. }
  11816. return true;
  11817. };
  11818. Lines2DRenderCache.prototype.dispose = function () {
  11819. if (!_super.prototype.dispose.call(this)) {
  11820. return false;
  11821. }
  11822. if (this.fillVB) {
  11823. this._engine._releaseBuffer(this.fillVB);
  11824. this.fillVB = null;
  11825. }
  11826. if (this.fillIB) {
  11827. this._engine._releaseBuffer(this.fillIB);
  11828. this.fillIB = null;
  11829. }
  11830. this.effectFill = null;
  11831. this.effectFillInstanced = null;
  11832. this.effectBorder = null;
  11833. this.effectBorderInstanced = null;
  11834. if (this.borderVB) {
  11835. this._engine._releaseBuffer(this.borderVB);
  11836. this.borderVB = null;
  11837. }
  11838. if (this.borderIB) {
  11839. this._engine._releaseBuffer(this.borderIB);
  11840. this.borderIB = null;
  11841. }
  11842. return true;
  11843. };
  11844. return Lines2DRenderCache;
  11845. }(BABYLON.ModelRenderCache));
  11846. BABYLON.Lines2DRenderCache = Lines2DRenderCache;
  11847. var Lines2DInstanceData = (function (_super) {
  11848. __extends(Lines2DInstanceData, _super);
  11849. function Lines2DInstanceData(partId) {
  11850. return _super.call(this, partId, 1) || this;
  11851. }
  11852. Object.defineProperty(Lines2DInstanceData.prototype, "boundingMin", {
  11853. get: function () {
  11854. return null;
  11855. },
  11856. set: function (value) {
  11857. },
  11858. enumerable: true,
  11859. configurable: true
  11860. });
  11861. Object.defineProperty(Lines2DInstanceData.prototype, "boundingMax", {
  11862. get: function () {
  11863. return null;
  11864. },
  11865. set: function (value) {
  11866. },
  11867. enumerable: true,
  11868. configurable: true
  11869. });
  11870. return Lines2DInstanceData;
  11871. }(BABYLON.Shape2DInstanceData));
  11872. __decorate([
  11873. BABYLON.instanceData(BABYLON.Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  11874. ], Lines2DInstanceData.prototype, "boundingMin", null);
  11875. __decorate([
  11876. BABYLON.instanceData(BABYLON.Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  11877. ], Lines2DInstanceData.prototype, "boundingMax", null);
  11878. BABYLON.Lines2DInstanceData = Lines2DInstanceData;
  11879. var Lines2D = Lines2D_1 = (function (_super) {
  11880. __extends(Lines2D, _super);
  11881. /**
  11882. * Create an 2D Lines Shape primitive. The defined lines may be opened or closed (see below)
  11883. * @param points an array that describe the points to use to draw the line, must contain at least two entries.
  11884. * @param settings a combination of settings, possible ones are
  11885. * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
  11886. * - children: an array of direct children
  11887. * - id a text identifier, for information purpose
  11888. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  11889. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  11890. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  11891. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  11892. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  11893. * - zOrder: override the zOrder with the specified value
  11894. * - origin: define the normalized origin point location, default [0.5;0.5]
  11895. * - fillThickness: the thickness of the fill part of the line, can be null to draw nothing (but a border brush must be given), default is 1.
  11896. * - closed: if false the lines are said to be opened, the first point and the latest DON'T connect. if true the lines are said to be closed, the first and last point will be connected by a line. For instance you can define the 4 points of a rectangle, if you set closed to true a 4 edges rectangle will be drawn. If you set false, only three edges will be drawn, the edge formed by the first and last point won't exist. Default is false.
  11897. * - startCap: Draw a cap of the given type at the start of the first line, you can't define a Cap if the Lines2D is closed. Default is Lines2D.NoCap.
  11898. * - endCap: Draw a cap of the given type at the end of the last line, you can't define a Cap if the Lines2D is closed. Default is Lines2D.NoCap.
  11899. * - fill: the brush used to draw the fill content of the lines, you can set null to draw nothing (but you will have to set a border brush), default is a SolidColorBrush of plain white. can be a string value (see Canvas2D.GetBrushFromString)
  11900. * - border: the brush used to draw the border of the lines, you can set null to draw nothing (but you will have to set a fill brush), default is null. can be a string value (see Canvas2D.GetBrushFromString)
  11901. * - borderThickness: the thickness of the drawn border, default is 1.
  11902. * - isVisible: true if the primitive must be visible, false for hidden. Default is true.
  11903. * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
  11904. * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
  11905. * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
  11906. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  11907. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  11908. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  11909. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  11910. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  11911. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  11912. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  11913. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  11914. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  11915. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  11916. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  11917. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  11918. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  11919. */
  11920. function Lines2D(points, settings) {
  11921. var _this;
  11922. if (!settings) {
  11923. settings = {};
  11924. }
  11925. _this = _super.call(this, settings) || this;
  11926. _this._fillVB = null;
  11927. _this._fillIB = null;
  11928. _this._borderVB = null;
  11929. _this._borderIB = null;
  11930. _this._size = BABYLON.Size.Zero();
  11931. _this._boundingMin = null;
  11932. _this._boundingMax = null;
  11933. var fillThickness = (settings.fillThickness == null) ? 1 : settings.fillThickness;
  11934. var startCap = (settings.startCap == null) ? 0 : settings.startCap;
  11935. var endCap = (settings.endCap == null) ? 0 : settings.endCap;
  11936. var closed = (settings.closed == null) ? false : settings.closed;
  11937. _this.points = points;
  11938. _this.fillThickness = fillThickness;
  11939. _this.startCap = startCap;
  11940. _this.endCap = endCap;
  11941. _this.closed = closed;
  11942. return _this;
  11943. }
  11944. Object.defineProperty(Lines2D, "NoCap", {
  11945. /**
  11946. * No Cap to apply on the extremity
  11947. */
  11948. get: function () { return Lines2D_1._noCap; },
  11949. enumerable: true,
  11950. configurable: true
  11951. });
  11952. Object.defineProperty(Lines2D, "RoundCap", {
  11953. /**
  11954. * A round cap, will use the line thickness as diameter
  11955. */
  11956. get: function () { return Lines2D_1._roundCap; },
  11957. enumerable: true,
  11958. configurable: true
  11959. });
  11960. Object.defineProperty(Lines2D, "TriangleCap", {
  11961. /**
  11962. * Creates a triangle at the extremity.
  11963. */
  11964. get: function () { return Lines2D_1._triangleCap; },
  11965. enumerable: true,
  11966. configurable: true
  11967. });
  11968. Object.defineProperty(Lines2D, "SquareAnchorCap", {
  11969. /**
  11970. * Creates a Square anchor at the extremity, the square size is twice the thickness of the line
  11971. */
  11972. get: function () { return Lines2D_1._squareAnchorCap; },
  11973. enumerable: true,
  11974. configurable: true
  11975. });
  11976. Object.defineProperty(Lines2D, "RoundAnchorCap", {
  11977. /**
  11978. * Creates a round anchor at the extremity, the diameter is twice the thickness of the line
  11979. */
  11980. get: function () { return Lines2D_1._roundAnchorCap; },
  11981. enumerable: true,
  11982. configurable: true
  11983. });
  11984. Object.defineProperty(Lines2D, "DiamondAnchorCap", {
  11985. /**
  11986. * Creates a diamond anchor at the extremity.
  11987. */
  11988. get: function () { return Lines2D_1._diamondAnchorCap; },
  11989. enumerable: true,
  11990. configurable: true
  11991. });
  11992. Object.defineProperty(Lines2D, "ArrowCap", {
  11993. /**
  11994. * Creates an arrow anchor at the extremity. the arrow base size is twice the thickness of the line
  11995. */
  11996. get: function () { return Lines2D_1._arrowCap; },
  11997. enumerable: true,
  11998. configurable: true
  11999. });
  12000. Object.defineProperty(Lines2D.prototype, "points", {
  12001. get: function () {
  12002. return this._points;
  12003. },
  12004. set: function (value) {
  12005. this._points = value;
  12006. this._contour = null;
  12007. this._boundingBoxDirty();
  12008. },
  12009. enumerable: true,
  12010. configurable: true
  12011. });
  12012. Object.defineProperty(Lines2D.prototype, "fillThickness", {
  12013. get: function () {
  12014. return this._fillThickness;
  12015. },
  12016. set: function (value) {
  12017. this._fillThickness = value;
  12018. },
  12019. enumerable: true,
  12020. configurable: true
  12021. });
  12022. Object.defineProperty(Lines2D.prototype, "closed", {
  12023. get: function () {
  12024. return this._closed;
  12025. },
  12026. set: function (value) {
  12027. this._closed = value;
  12028. },
  12029. enumerable: true,
  12030. configurable: true
  12031. });
  12032. Object.defineProperty(Lines2D.prototype, "startCap", {
  12033. get: function () {
  12034. return this._startCap;
  12035. },
  12036. set: function (value) {
  12037. this._startCap = value;
  12038. },
  12039. enumerable: true,
  12040. configurable: true
  12041. });
  12042. Object.defineProperty(Lines2D.prototype, "endCap", {
  12043. get: function () {
  12044. return this._endCap;
  12045. },
  12046. set: function (value) {
  12047. this._endCap = value;
  12048. },
  12049. enumerable: true,
  12050. configurable: true
  12051. });
  12052. Lines2D.prototype.levelIntersect = function (intersectInfo) {
  12053. var _this = this;
  12054. if (this._contour == null) {
  12055. this._computeLines2D();
  12056. }
  12057. var pl = this.points.length;
  12058. var l = this.closed ? pl + 1 : pl;
  12059. var p = intersectInfo._localPickPosition;
  12060. this.transformPointWithOriginToRef(this._contour[0], null, Lines2D_1._prevA);
  12061. this.transformPointWithOriginToRef(this._contour[1], null, Lines2D_1._prevB);
  12062. for (var i = 1; i < l; i++) {
  12063. this.transformPointWithOriginToRef(this._contour[(i % pl) * 2 + 0], null, Lines2D_1._curA);
  12064. this.transformPointWithOriginToRef(this._contour[(i % pl) * 2 + 1], null, Lines2D_1._curB);
  12065. if (BABYLON.Vector2.PointInTriangle(p, Lines2D_1._prevA, Lines2D_1._prevB, Lines2D_1._curA)) {
  12066. return true;
  12067. }
  12068. if (BABYLON.Vector2.PointInTriangle(p, Lines2D_1._curA, Lines2D_1._prevB, Lines2D_1._curB)) {
  12069. return true;
  12070. }
  12071. Lines2D_1._prevA.x = Lines2D_1._curA.x;
  12072. Lines2D_1._prevA.y = Lines2D_1._curA.y;
  12073. Lines2D_1._prevB.x = Lines2D_1._curB.x;
  12074. Lines2D_1._prevB.y = Lines2D_1._curB.y;
  12075. }
  12076. var capIntersect = function (tri, points) {
  12077. var l = tri.length;
  12078. for (var i = 0; i < l; i += 3) {
  12079. Lines2D_1._curA.x = points[tri[i + 0] * 2 + 0];
  12080. Lines2D_1._curA.y = points[tri[i + 0] * 2 + 1];
  12081. _this.transformPointWithOriginToRef(Lines2D_1._curA, null, Lines2D_1._curB);
  12082. Lines2D_1._curA.x = points[tri[i + 1] * 2 + 0];
  12083. Lines2D_1._curA.y = points[tri[i + 1] * 2 + 1];
  12084. _this.transformPointWithOriginToRef(Lines2D_1._curA, null, Lines2D_1._prevA);
  12085. Lines2D_1._curA.x = points[tri[i + 2] * 2 + 0];
  12086. Lines2D_1._curA.y = points[tri[i + 2] * 2 + 1];
  12087. _this.transformPointWithOriginToRef(Lines2D_1._curA, null, Lines2D_1._prevB);
  12088. if (BABYLON.Vector2.PointInTriangle(p, Lines2D_1._prevA, Lines2D_1._prevB, Lines2D_1._curB)) {
  12089. return true;
  12090. }
  12091. }
  12092. return false;
  12093. };
  12094. if (this._startCapTriIndices) {
  12095. if (this._startCapTriIndices && capIntersect(this._startCapTriIndices, this._startCapContour)) {
  12096. return true;
  12097. }
  12098. if (this._endCapTriIndices && capIntersect(this._endCapTriIndices, this._endCapContour)) {
  12099. return true;
  12100. }
  12101. }
  12102. return false;
  12103. };
  12104. Object.defineProperty(Lines2D.prototype, "boundingMin", {
  12105. get: function () {
  12106. if (!this._boundingMin) {
  12107. this._computeLines2D();
  12108. }
  12109. return this._boundingMin;
  12110. },
  12111. enumerable: true,
  12112. configurable: true
  12113. });
  12114. Object.defineProperty(Lines2D.prototype, "boundingMax", {
  12115. get: function () {
  12116. if (!this._boundingMax) {
  12117. this._computeLines2D();
  12118. }
  12119. return this._boundingMax;
  12120. },
  12121. enumerable: true,
  12122. configurable: true
  12123. });
  12124. Lines2D.prototype.getUsedShaderCategories = function (dataPart) {
  12125. var res = _super.prototype.getUsedShaderCategories.call(this, dataPart);
  12126. // Remove the BORDER category, we don't use it in the VertexShader
  12127. var i = res.indexOf(BABYLON.Shape2D.SHAPE2D_CATEGORY_BORDER);
  12128. if (i !== -1) {
  12129. res.splice(i, 1);
  12130. }
  12131. return res;
  12132. };
  12133. Lines2D.prototype.updateLevelBoundingInfo = function () {
  12134. if (!this._boundingMin) {
  12135. this._computeLines2D();
  12136. }
  12137. BABYLON.BoundingInfo2D.CreateFromMinMaxToRef(this._boundingMin.x, this._boundingMax.x, this._boundingMin.y, this._boundingMax.y, this._levelBoundingInfo);
  12138. };
  12139. Lines2D.prototype.createModelRenderCache = function (modelKey) {
  12140. var renderCache = new Lines2DRenderCache(this.owner.engine, modelKey);
  12141. return renderCache;
  12142. };
  12143. ///////////////////////////////////////////////////////////////////////////////////
  12144. // Methods for Lines building
  12145. Lines2D.prototype._perp = function (v, res) {
  12146. res.x = v.y;
  12147. res.y = -v.x;
  12148. };
  12149. ;
  12150. Lines2D.prototype._direction = function (a, b, res) {
  12151. a.subtractToRef(b, res);
  12152. res.normalize();
  12153. };
  12154. Lines2D.prototype._computeMiter = function (tangent, miter, a, b) {
  12155. a.addToRef(b, tangent);
  12156. tangent.normalize();
  12157. miter.x = -tangent.y;
  12158. miter.y = tangent.x;
  12159. Lines2D_1._miterTps.x = -a.y;
  12160. Lines2D_1._miterTps.y = a.x;
  12161. return 1 / BABYLON.Vector2.Dot(miter, Lines2D_1._miterTps);
  12162. };
  12163. Lines2D.prototype._intersect = function (x1, y1, x2, y2, x3, y3, x4, y4) {
  12164. var d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
  12165. if (d === 0)
  12166. return false;
  12167. var xi = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d; // Intersection point is xi/yi, just in case...
  12168. //let yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d; // That's why I left it commented
  12169. if (xi < Math.min(x1, x2) || xi > Math.max(x1, x2))
  12170. return false;
  12171. if (xi < Math.min(x3, x4) || xi > Math.max(x3, x4))
  12172. return false;
  12173. return true;
  12174. };
  12175. Lines2D.prototype._updateMinMax = function (array, offset) {
  12176. if (offset >= array.length) {
  12177. return;
  12178. }
  12179. this._boundingMin.x = Math.min(this._boundingMin.x, array[offset]);
  12180. this._boundingMax.x = Math.max(this._boundingMax.x, array[offset]);
  12181. this._boundingMin.y = Math.min(this._boundingMin.y, array[offset + 1]);
  12182. this._boundingMax.y = Math.max(this._boundingMax.y, array[offset + 1]);
  12183. };
  12184. Lines2D.prototype._store = function (array, contour, index, max, p, n, halfThickness, borderThickness, detectFlip) {
  12185. var borderMode = borderThickness != null && !isNaN(borderThickness);
  12186. var off = index * (borderMode ? 8 : 4);
  12187. // Mandatory because we'll be out of bound in case of closed line, for the very last point (which is a duplicate of the first that we don't store in the vb)
  12188. if (off >= array.length) {
  12189. return;
  12190. }
  12191. // Store start/end normal, we need it for the cap construction
  12192. if (index === 0) {
  12193. this._perp(n, Lines2D_1._startDir);
  12194. }
  12195. else if (index === max - 1) {
  12196. this._perp(n, Lines2D_1._endDir);
  12197. Lines2D_1._endDir.x *= -1;
  12198. Lines2D_1._endDir.y *= -1;
  12199. }
  12200. var swap = false;
  12201. array[off + 0] = p.x + n.x * halfThickness;
  12202. array[off + 1] = p.y + n.y * halfThickness;
  12203. array[off + 2] = p.x + n.x * -halfThickness;
  12204. array[off + 3] = p.y + n.y * -halfThickness;
  12205. this._updateMinMax(array, off);
  12206. this._updateMinMax(array, off + 2);
  12207. // If an index is given we check if the two segments formed between [index+0;detectFlip+0] and [index+2;detectFlip+2] intersect themselves.
  12208. // It should not be the case, they should be parallel, so if they cross, we switch the order of storage to ensure we'll have parallel lines
  12209. if (detectFlip != 0) {
  12210. // Flip if intersect
  12211. var flipOff = detectFlip * (borderMode ? 8 : 4);
  12212. if (this._intersect(array[off + 0], array[off + 1], array[flipOff + 0], array[flipOff + 1], array[off + 2], array[off + 3], array[flipOff + 2], array[flipOff + 3])) {
  12213. swap = true;
  12214. var tps = array[off + 0];
  12215. array[off + 0] = array[off + 2];
  12216. array[off + 2] = tps;
  12217. tps = array[off + 1];
  12218. array[off + 1] = array[off + 3];
  12219. array[off + 3] = tps;
  12220. }
  12221. }
  12222. if (borderMode) {
  12223. var t = halfThickness + borderThickness;
  12224. array[off + 4] = p.x + n.x * (swap ? -t : t);
  12225. array[off + 5] = p.y + n.y * (swap ? -t : t);
  12226. array[off + 6] = p.x + n.x * (swap ? t : -t);
  12227. array[off + 7] = p.y + n.y * (swap ? t : -t);
  12228. this._updateMinMax(array, off + 4);
  12229. this._updateMinMax(array, off + 6);
  12230. }
  12231. if (contour) {
  12232. off += borderMode ? 4 : 0;
  12233. contour.push(new BABYLON.Vector2(array[off + 0], array[off + 1]));
  12234. contour.push(new BABYLON.Vector2(array[off + 2], array[off + 3]));
  12235. }
  12236. };
  12237. Lines2D.prototype._getCapSize = function (type, border) {
  12238. if (border === void 0) { border = false; }
  12239. var sd = Lines2D_1._roundCapSubDiv;
  12240. // If no array given, we call this to get the size
  12241. var vbsize = 0, ibsize = 0;
  12242. switch (type) {
  12243. case Lines2D_1.NoCap:
  12244. {
  12245. // If the line is not close and we're computing border, we add the size to generate the edge border
  12246. if (!this.closed && border) {
  12247. vbsize = 4;
  12248. ibsize = 6;
  12249. }
  12250. else {
  12251. vbsize = ibsize = 0;
  12252. }
  12253. break;
  12254. }
  12255. case Lines2D_1.RoundCap:
  12256. {
  12257. if (border) {
  12258. vbsize = sd;
  12259. ibsize = (sd - 2) * 3;
  12260. }
  12261. else {
  12262. vbsize = (sd / 2) + 1;
  12263. ibsize = (sd / 2) * 3;
  12264. }
  12265. break;
  12266. }
  12267. case Lines2D_1.ArrowCap:
  12268. {
  12269. if (border) {
  12270. vbsize = 12;
  12271. ibsize = 24;
  12272. }
  12273. else {
  12274. vbsize = 3;
  12275. ibsize = 3;
  12276. }
  12277. break;
  12278. }
  12279. case Lines2D_1.TriangleCap:
  12280. {
  12281. if (border) {
  12282. vbsize = 6;
  12283. ibsize = 12;
  12284. }
  12285. else {
  12286. vbsize = 3;
  12287. ibsize = 3;
  12288. }
  12289. break;
  12290. }
  12291. case Lines2D_1.DiamondAnchorCap:
  12292. {
  12293. if (border) {
  12294. vbsize = 10;
  12295. ibsize = 24;
  12296. }
  12297. else {
  12298. vbsize = 5;
  12299. ibsize = 9;
  12300. }
  12301. break;
  12302. }
  12303. case Lines2D_1.SquareAnchorCap:
  12304. {
  12305. if (border) {
  12306. vbsize = 12;
  12307. ibsize = 30;
  12308. }
  12309. else {
  12310. vbsize = 4;
  12311. ibsize = 6;
  12312. }
  12313. break;
  12314. }
  12315. case Lines2D_1.RoundAnchorCap:
  12316. {
  12317. if (border) {
  12318. vbsize = sd * 2;
  12319. ibsize = (sd - 1) * 6;
  12320. }
  12321. else {
  12322. vbsize = sd + 1;
  12323. ibsize = (sd + 1) * 3;
  12324. }
  12325. break;
  12326. }
  12327. }
  12328. return { vbsize: vbsize * 2, ibsize: ibsize };
  12329. };
  12330. Lines2D.prototype._storeVertex = function (vb, baseOffset, index, basePos, rotation, vertex, contour) {
  12331. var c = Math.cos(rotation);
  12332. var s = Math.sin(rotation);
  12333. Lines2D_1._tpsV.x = (c * vertex.x) + (-s * vertex.y) + basePos.x;
  12334. Lines2D_1._tpsV.y = (s * vertex.x) + (c * vertex.y) + basePos.y;
  12335. var offset = baseOffset + (index * 2);
  12336. vb[offset + 0] = Lines2D_1._tpsV.x;
  12337. vb[offset + 1] = Lines2D_1._tpsV.y;
  12338. if (contour) {
  12339. contour.push(Lines2D_1._tpsV.x);
  12340. contour.push(Lines2D_1._tpsV.y);
  12341. }
  12342. this._updateMinMax(vb, offset);
  12343. return (baseOffset + index * 2) / 2;
  12344. };
  12345. Lines2D.prototype._storeIndex = function (ib, baseOffset, index, vertexIndex) {
  12346. ib[baseOffset + index] = vertexIndex;
  12347. };
  12348. Lines2D.prototype._buildCap = function (vb, vbi, ib, ibi, pos, thickness, borderThickness, type, capDir, contour) {
  12349. // Compute the transformation from the direction of the cap to build relative to our default orientation [1;0] (our cap are by default pointing toward right, horizontal
  12350. var sd = Lines2D_1._roundCapSubDiv;
  12351. var dir = new BABYLON.Vector2(1, 0);
  12352. var angle = Math.atan2(capDir.y, capDir.x) - Math.atan2(dir.y, dir.x);
  12353. var ht = thickness / 2;
  12354. var t = thickness;
  12355. var borderMode = borderThickness != null;
  12356. var bt = borderThickness;
  12357. switch (type) {
  12358. case Lines2D_1.NoCap:
  12359. if (borderMode && !this.closed) {
  12360. var vi = 0;
  12361. var ii = 0;
  12362. var v1 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, ht + bt), contour);
  12363. var v2 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(bt, ht + bt), contour);
  12364. var v3 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(bt, -(ht + bt)), contour);
  12365. var v4 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -(ht + bt)), contour);
  12366. this._storeIndex(ib, ibi, ii++, v1);
  12367. this._storeIndex(ib, ibi, ii++, v2);
  12368. this._storeIndex(ib, ibi, ii++, v3);
  12369. this._storeIndex(ib, ibi, ii++, v1);
  12370. this._storeIndex(ib, ibi, ii++, v3);
  12371. this._storeIndex(ib, ibi, ii++, v4);
  12372. }
  12373. break;
  12374. case Lines2D_1.ArrowCap:
  12375. ht *= 2;
  12376. case Lines2D_1.TriangleCap:
  12377. {
  12378. if (borderMode) {
  12379. var f = type === Lines2D_1.TriangleCap ? bt : Math.sqrt(bt * bt * 2);
  12380. var v1 = this._storeVertex(vb, vbi, 0, pos, angle, new BABYLON.Vector2(0, ht), null);
  12381. var v2 = this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(ht, 0), null);
  12382. var v3 = this._storeVertex(vb, vbi, 2, pos, angle, new BABYLON.Vector2(0, -ht), null);
  12383. var v4 = this._storeVertex(vb, vbi, 3, pos, angle, new BABYLON.Vector2(0, ht + f), contour);
  12384. var v5 = this._storeVertex(vb, vbi, 4, pos, angle, new BABYLON.Vector2(ht + f, 0), contour);
  12385. var v6 = this._storeVertex(vb, vbi, 5, pos, angle, new BABYLON.Vector2(0, -(ht + f)), contour);
  12386. var ii = 0;
  12387. this._storeIndex(ib, ibi, ii++, v1);
  12388. this._storeIndex(ib, ibi, ii++, v4);
  12389. this._storeIndex(ib, ibi, ii++, v5);
  12390. this._storeIndex(ib, ibi, ii++, v1);
  12391. this._storeIndex(ib, ibi, ii++, v5);
  12392. this._storeIndex(ib, ibi, ii++, v2);
  12393. this._storeIndex(ib, ibi, ii++, v6);
  12394. this._storeIndex(ib, ibi, ii++, v3);
  12395. this._storeIndex(ib, ibi, ii++, v2);
  12396. this._storeIndex(ib, ibi, ii++, v6);
  12397. this._storeIndex(ib, ibi, ii++, v2);
  12398. this._storeIndex(ib, ibi, ii++, v5);
  12399. if (type === Lines2D_1.ArrowCap) {
  12400. var rht = thickness / 2;
  12401. var v10 = this._storeVertex(vb, vbi, 9, pos, angle, new BABYLON.Vector2(0, -(rht + bt)), null);
  12402. var v12 = this._storeVertex(vb, vbi, 11, pos, angle, new BABYLON.Vector2(-bt, -(ht + f)), contour);
  12403. var v11 = this._storeVertex(vb, vbi, 10, pos, angle, new BABYLON.Vector2(-bt, -(rht + bt)), contour);
  12404. var v7 = this._storeVertex(vb, vbi, 6, pos, angle, new BABYLON.Vector2(0, rht + bt), null);
  12405. var v8 = this._storeVertex(vb, vbi, 7, pos, angle, new BABYLON.Vector2(-bt, rht + bt), contour);
  12406. var v9 = this._storeVertex(vb, vbi, 8, pos, angle, new BABYLON.Vector2(-bt, ht + f), contour);
  12407. this._storeIndex(ib, ibi, ii++, v7);
  12408. this._storeIndex(ib, ibi, ii++, v8);
  12409. this._storeIndex(ib, ibi, ii++, v9);
  12410. this._storeIndex(ib, ibi, ii++, v7);
  12411. this._storeIndex(ib, ibi, ii++, v9);
  12412. this._storeIndex(ib, ibi, ii++, v4);
  12413. this._storeIndex(ib, ibi, ii++, v10);
  12414. this._storeIndex(ib, ibi, ii++, v12);
  12415. this._storeIndex(ib, ibi, ii++, v11);
  12416. this._storeIndex(ib, ibi, ii++, v10);
  12417. this._storeIndex(ib, ibi, ii++, v6);
  12418. this._storeIndex(ib, ibi, ii++, v12);
  12419. }
  12420. }
  12421. else {
  12422. var v1 = this._storeVertex(vb, vbi, 0, pos, angle, new BABYLON.Vector2(0, ht), contour);
  12423. var v2 = this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(ht, 0), contour);
  12424. var v3 = this._storeVertex(vb, vbi, 2, pos, angle, new BABYLON.Vector2(0, -ht), contour);
  12425. this._storeIndex(ib, ibi, 0, v1);
  12426. this._storeIndex(ib, ibi, 1, v2);
  12427. this._storeIndex(ib, ibi, 2, v3);
  12428. }
  12429. break;
  12430. }
  12431. case Lines2D_1.RoundCap:
  12432. {
  12433. if (borderMode) {
  12434. var curA = -Math.PI / 2;
  12435. var incA = Math.PI / (sd / 2 - 1);
  12436. var ii = 0;
  12437. for (var i = 0; i < (sd / 2); i++) {
  12438. var v1 = this._storeVertex(vb, vbi, i * 2 + 0, pos, angle, new BABYLON.Vector2(Math.cos(curA) * ht, Math.sin(curA) * ht), null);
  12439. var v2 = this._storeVertex(vb, vbi, i * 2 + 1, pos, angle, new BABYLON.Vector2(Math.cos(curA) * (ht + bt), Math.sin(curA) * (ht + bt)), contour);
  12440. if (i > 0) {
  12441. this._storeIndex(ib, ibi, ii++, v1 - 2);
  12442. this._storeIndex(ib, ibi, ii++, v2 - 2);
  12443. this._storeIndex(ib, ibi, ii++, v2);
  12444. this._storeIndex(ib, ibi, ii++, v1 - 2);
  12445. this._storeIndex(ib, ibi, ii++, v2);
  12446. this._storeIndex(ib, ibi, ii++, v1);
  12447. }
  12448. curA += incA;
  12449. }
  12450. }
  12451. else {
  12452. var c = this._storeVertex(vb, vbi, 0, pos, angle, new BABYLON.Vector2(0, 0), null);
  12453. var curA = -Math.PI / 2;
  12454. var incA = Math.PI / (sd / 2 - 1);
  12455. this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(Math.cos(curA) * ht, Math.sin(curA) * ht), null);
  12456. curA += incA;
  12457. for (var i = 1; i < (sd / 2); i++) {
  12458. var v2 = this._storeVertex(vb, vbi, i + 1, pos, angle, new BABYLON.Vector2(Math.cos(curA) * ht, Math.sin(curA) * ht), contour);
  12459. this._storeIndex(ib, ibi, i * 3 + 0, c);
  12460. this._storeIndex(ib, ibi, i * 3 + 1, v2 - 1);
  12461. this._storeIndex(ib, ibi, i * 3 + 2, v2);
  12462. curA += incA;
  12463. }
  12464. }
  12465. break;
  12466. }
  12467. case Lines2D_1.SquareAnchorCap:
  12468. {
  12469. var vi = 0;
  12470. var c = borderMode ? null : contour;
  12471. var v1 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, t), c);
  12472. var v2 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2, t), c);
  12473. var v3 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2, -t), c);
  12474. var v4 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -t), c);
  12475. if (borderMode) {
  12476. var v5 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, ht + bt), null);
  12477. var v6 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, ht + bt), contour);
  12478. var v7 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, t + bt), contour);
  12479. var v8 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2 + bt, t + bt), contour);
  12480. var v9 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2 + bt, -(t + bt)), contour);
  12481. var v10 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, -(t + bt)), contour);
  12482. var v11 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, -(ht + bt)), contour);
  12483. var v12 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -(ht + bt)), null);
  12484. var ii = 0;
  12485. this._storeIndex(ib, ibi, ii++, v6);
  12486. this._storeIndex(ib, ibi, ii++, v1);
  12487. this._storeIndex(ib, ibi, ii++, v5);
  12488. this._storeIndex(ib, ibi, ii++, v6);
  12489. this._storeIndex(ib, ibi, ii++, v7);
  12490. this._storeIndex(ib, ibi, ii++, v1);
  12491. this._storeIndex(ib, ibi, ii++, v1);
  12492. this._storeIndex(ib, ibi, ii++, v7);
  12493. this._storeIndex(ib, ibi, ii++, v8);
  12494. this._storeIndex(ib, ibi, ii++, v1);
  12495. this._storeIndex(ib, ibi, ii++, v8);
  12496. this._storeIndex(ib, ibi, ii++, v2);
  12497. this._storeIndex(ib, ibi, ii++, v2);
  12498. this._storeIndex(ib, ibi, ii++, v8);
  12499. this._storeIndex(ib, ibi, ii++, v9);
  12500. this._storeIndex(ib, ibi, ii++, v2);
  12501. this._storeIndex(ib, ibi, ii++, v9);
  12502. this._storeIndex(ib, ibi, ii++, v3);
  12503. this._storeIndex(ib, ibi, ii++, v3);
  12504. this._storeIndex(ib, ibi, ii++, v9);
  12505. this._storeIndex(ib, ibi, ii++, v10);
  12506. this._storeIndex(ib, ibi, ii++, v3);
  12507. this._storeIndex(ib, ibi, ii++, v10);
  12508. this._storeIndex(ib, ibi, ii++, v4);
  12509. this._storeIndex(ib, ibi, ii++, v10);
  12510. this._storeIndex(ib, ibi, ii++, v11);
  12511. this._storeIndex(ib, ibi, ii++, v4);
  12512. this._storeIndex(ib, ibi, ii++, v11);
  12513. this._storeIndex(ib, ibi, ii++, v12);
  12514. this._storeIndex(ib, ibi, ii++, v4);
  12515. }
  12516. else {
  12517. this._storeIndex(ib, ibi, 0, v1);
  12518. this._storeIndex(ib, ibi, 1, v2);
  12519. this._storeIndex(ib, ibi, 2, v3);
  12520. this._storeIndex(ib, ibi, 3, v1);
  12521. this._storeIndex(ib, ibi, 4, v3);
  12522. this._storeIndex(ib, ibi, 5, v4);
  12523. }
  12524. break;
  12525. }
  12526. case Lines2D_1.RoundAnchorCap:
  12527. {
  12528. var cpos = Math.sqrt(t * t - ht * ht);
  12529. var center = new BABYLON.Vector2(cpos, 0);
  12530. var curA = BABYLON.Tools.ToRadians(-150);
  12531. var incA = BABYLON.Tools.ToRadians(300) / (sd - 1);
  12532. if (borderMode) {
  12533. var ii = 0;
  12534. for (var i = 0; i < sd; i++) {
  12535. var v1 = this._storeVertex(vb, vbi, i * 2 + 0, pos, angle, new BABYLON.Vector2(cpos + Math.cos(curA) * t, Math.sin(curA) * t), null);
  12536. var v2 = this._storeVertex(vb, vbi, i * 2 + 1, pos, angle, new BABYLON.Vector2(cpos + Math.cos(curA) * (t + bt), Math.sin(curA) * (t + bt)), contour);
  12537. if (i > 0) {
  12538. this._storeIndex(ib, ibi, ii++, v1 - 2);
  12539. this._storeIndex(ib, ibi, ii++, v2 - 2);
  12540. this._storeIndex(ib, ibi, ii++, v2);
  12541. this._storeIndex(ib, ibi, ii++, v1 - 2);
  12542. this._storeIndex(ib, ibi, ii++, v2);
  12543. this._storeIndex(ib, ibi, ii++, v1);
  12544. }
  12545. curA += incA;
  12546. }
  12547. }
  12548. else {
  12549. var c = this._storeVertex(vb, vbi, 0, pos, angle, center, null);
  12550. this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(cpos + Math.cos(curA) * t, Math.sin(curA) * t), null);
  12551. curA += incA;
  12552. for (var i = 1; i < sd; i++) {
  12553. var v2 = this._storeVertex(vb, vbi, i + 1, pos, angle, new BABYLON.Vector2(cpos + Math.cos(curA) * t, Math.sin(curA) * t), contour);
  12554. this._storeIndex(ib, ibi, i * 3 + 0, c);
  12555. this._storeIndex(ib, ibi, i * 3 + 1, v2 - 1);
  12556. this._storeIndex(ib, ibi, i * 3 + 2, v2);
  12557. curA += incA;
  12558. }
  12559. this._storeIndex(ib, ibi, sd * 3 + 0, c);
  12560. this._storeIndex(ib, ibi, sd * 3 + 1, c + 1);
  12561. this._storeIndex(ib, ibi, sd * 3 + 2, c + sd);
  12562. }
  12563. break;
  12564. }
  12565. case Lines2D_1.DiamondAnchorCap:
  12566. {
  12567. var vi = 0;
  12568. var c = borderMode ? null : contour;
  12569. var v1 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, ht), c);
  12570. var v2 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, t), c);
  12571. var v3 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht * 3, 0), c);
  12572. var v4 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, -t), c);
  12573. var v5 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -ht), c);
  12574. if (borderMode) {
  12575. var f = Math.sqrt(bt * bt * 2);
  12576. var v6 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-f, ht), contour);
  12577. var v7 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, t + f), contour);
  12578. var v8 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht * 3 + f, 0), contour);
  12579. var v9 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, -(t + f)), contour);
  12580. var v10 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-f, -ht), contour);
  12581. var ii = 0;
  12582. this._storeIndex(ib, ibi, ii++, v6);
  12583. this._storeIndex(ib, ibi, ii++, v7);
  12584. this._storeIndex(ib, ibi, ii++, v1);
  12585. this._storeIndex(ib, ibi, ii++, v1);
  12586. this._storeIndex(ib, ibi, ii++, v7);
  12587. this._storeIndex(ib, ibi, ii++, v2);
  12588. this._storeIndex(ib, ibi, ii++, v2);
  12589. this._storeIndex(ib, ibi, ii++, v7);
  12590. this._storeIndex(ib, ibi, ii++, v8);
  12591. this._storeIndex(ib, ibi, ii++, v2);
  12592. this._storeIndex(ib, ibi, ii++, v8);
  12593. this._storeIndex(ib, ibi, ii++, v3);
  12594. this._storeIndex(ib, ibi, ii++, v3);
  12595. this._storeIndex(ib, ibi, ii++, v8);
  12596. this._storeIndex(ib, ibi, ii++, v9);
  12597. this._storeIndex(ib, ibi, ii++, v3);
  12598. this._storeIndex(ib, ibi, ii++, v9);
  12599. this._storeIndex(ib, ibi, ii++, v4);
  12600. this._storeIndex(ib, ibi, ii++, v4);
  12601. this._storeIndex(ib, ibi, ii++, v9);
  12602. this._storeIndex(ib, ibi, ii++, v10);
  12603. this._storeIndex(ib, ibi, ii++, v4);
  12604. this._storeIndex(ib, ibi, ii++, v10);
  12605. this._storeIndex(ib, ibi, ii++, v5);
  12606. }
  12607. else {
  12608. this._storeIndex(ib, ibi, 0, v1);
  12609. this._storeIndex(ib, ibi, 1, v2);
  12610. this._storeIndex(ib, ibi, 2, v3);
  12611. this._storeIndex(ib, ibi, 3, v1);
  12612. this._storeIndex(ib, ibi, 4, v3);
  12613. this._storeIndex(ib, ibi, 5, v5);
  12614. this._storeIndex(ib, ibi, 6, v5);
  12615. this._storeIndex(ib, ibi, 7, v3);
  12616. this._storeIndex(ib, ibi, 8, v4);
  12617. }
  12618. break;
  12619. }
  12620. }
  12621. return null;
  12622. };
  12623. Lines2D.prototype._buildLine = function (vb, contour, ht, bt) {
  12624. var lineA = BABYLON.Vector2.Zero();
  12625. var lineB = BABYLON.Vector2.Zero();
  12626. var tangent = BABYLON.Vector2.Zero();
  12627. var miter = BABYLON.Vector2.Zero();
  12628. var curNormal = null;
  12629. if (this.closed) {
  12630. this.points.push(this.points[0]);
  12631. }
  12632. var total = this.points.length;
  12633. for (var i = 1; i < total; i++) {
  12634. var last = this.points[i - 1];
  12635. var cur = this.points[i];
  12636. var next = (i < (this.points.length - 1)) ? this.points[i + 1] : null;
  12637. this._direction(cur, last, lineA);
  12638. if (!curNormal) {
  12639. curNormal = BABYLON.Vector2.Zero();
  12640. this._perp(lineA, curNormal);
  12641. }
  12642. if (i === 1) {
  12643. this._store(vb, contour, 0, total, this.points[0], curNormal, ht, bt);
  12644. }
  12645. if (!next) {
  12646. this._perp(lineA, curNormal);
  12647. this._store(vb, contour, i, total, this.points[i], curNormal, ht, bt, i - 1);
  12648. }
  12649. else {
  12650. this._direction(next, cur, lineB);
  12651. var miterLen = this._computeMiter(tangent, miter, lineA, lineB);
  12652. this._store(vb, contour, i, total, this.points[i], miter, miterLen * ht, miterLen * bt, i - 1);
  12653. }
  12654. }
  12655. if (this.points.length > 2 && this.closed) {
  12656. var last2 = this.points[total - 2];
  12657. var cur2 = this.points[0];
  12658. var next2 = this.points[1];
  12659. this._direction(cur2, last2, lineA);
  12660. this._direction(next2, cur2, lineB);
  12661. this._perp(lineA, curNormal);
  12662. var miterLen2 = this._computeMiter(tangent, miter, lineA, lineB);
  12663. this._store(vb, null, 0, total, this.points[0], miter, miterLen2 * ht, miterLen2 * bt, 1);
  12664. // Patch contour
  12665. if (contour) {
  12666. var off = (bt == null) ? 0 : 4;
  12667. contour[0].x = vb[off + 0];
  12668. contour[0].y = vb[off + 1];
  12669. contour[1].x = vb[off + 2];
  12670. contour[1].y = vb[off + 3];
  12671. }
  12672. }
  12673. // Remove the point we added at the beginning
  12674. if (this.closed) {
  12675. this.points.splice(total - 1);
  12676. }
  12677. };
  12678. // Methods for Lines building
  12679. ///////////////////////////////////////////////////////////////////////////////////
  12680. Lines2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  12681. var renderCache = modelRenderCache;
  12682. var engine = this.owner.engine;
  12683. if (this._fillVB === null) {
  12684. this._computeLines2D();
  12685. }
  12686. // Need to create WebGL resources for fill part?
  12687. if (this.fill) {
  12688. renderCache.fillVB = engine.createVertexBuffer(this._fillVB);
  12689. renderCache.fillIB = engine.createIndexBuffer(this._fillIB);
  12690. renderCache.fillIndicesCount = this._fillIB.length;
  12691. // Get the instanced version of the effect, if the engine does not support it, null is return and we'll only draw on by one
  12692. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["position"], null, true);
  12693. if (ei) {
  12694. renderCache.effectFillInstanced = engine.createEffect("lines2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  12695. }
  12696. // Get the non instanced version
  12697. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["position"], null, false);
  12698. renderCache.effectFill = engine.createEffect("lines2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  12699. }
  12700. // Need to create WebGL resources for border part?
  12701. if (this.border) {
  12702. renderCache.borderVB = engine.createVertexBuffer(this._borderVB);
  12703. renderCache.borderIB = engine.createIndexBuffer(this._borderIB);
  12704. renderCache.borderIndicesCount = this._borderIB.length;
  12705. // Get the instanced version of the effect, if the engine does not support it, null is return and we'll only draw on by one
  12706. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["position"], null, true);
  12707. if (ei) {
  12708. renderCache.effectBorderInstanced = engine.createEffect({ vertex: "lines2d", fragment: "lines2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  12709. }
  12710. // Get the non instanced version
  12711. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["position"], null, false);
  12712. renderCache.effectBorder = engine.createEffect({ vertex: "lines2d", fragment: "lines2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  12713. }
  12714. this._fillVB = null;
  12715. this._fillIB = null;
  12716. this._borderVB = null;
  12717. this._borderIB = null;
  12718. return renderCache;
  12719. };
  12720. Lines2D.prototype._computeLines2D = function () {
  12721. // Init min/max because their being computed here
  12722. this._boundingMin = new BABYLON.Vector2(Number.MAX_VALUE, Number.MAX_VALUE);
  12723. this._boundingMax = new BABYLON.Vector2(Number.MIN_VALUE, Number.MIN_VALUE);
  12724. var contour = new Array();
  12725. var startCapContour = new Array();
  12726. var endCapContour = new Array();
  12727. // Need to create WebGL resources for fill part?
  12728. if (this.fill) {
  12729. var startCapInfo = this._getCapSize(this.startCap);
  12730. var endCapInfo = this._getCapSize(this.endCap);
  12731. var count = this.points.length;
  12732. var vbSize = (count * 2 * 2) + startCapInfo.vbsize + endCapInfo.vbsize;
  12733. this._fillVB = new Float32Array(vbSize);
  12734. var vb = this._fillVB;
  12735. var ht = this.fillThickness / 2;
  12736. var total = this.points.length;
  12737. this._buildLine(vb, this.border ? null : contour, ht);
  12738. var max = total * 2;
  12739. var triCount = (count - (this.closed ? 0 : 1)) * 2;
  12740. this._fillIB = new Float32Array(triCount * 3 + startCapInfo.ibsize + endCapInfo.ibsize);
  12741. var ib = this._fillIB;
  12742. for (var i = 0; i < triCount; i += 2) {
  12743. ib[i * 3 + 0] = i + 0;
  12744. ib[i * 3 + 1] = i + 1;
  12745. ib[i * 3 + 2] = (i + 2) % max;
  12746. ib[i * 3 + 3] = i + 1;
  12747. ib[i * 3 + 4] = (i + 3) % max;
  12748. ib[i * 3 + 5] = (i + 2) % max;
  12749. }
  12750. this._buildCap(vb, count * 2 * 2, ib, triCount * 3, this.points[0], this.fillThickness, null, this.startCap, Lines2D_1._startDir, this.border ? null : startCapContour);
  12751. this._buildCap(vb, (count * 2 * 2) + startCapInfo.vbsize, ib, (triCount * 3) + startCapInfo.ibsize, this.points[total - 1], this.fillThickness, null, this.endCap, Lines2D_1._endDir, this.border ? null : startCapContour);
  12752. }
  12753. // Need to create WebGL resources for border part?
  12754. if (this.border) {
  12755. var startCapInfo = this._getCapSize(this.startCap, true);
  12756. var endCapInfo = this._getCapSize(this.endCap, true);
  12757. var count = this.points.length;
  12758. var vbSize = (count * 2 * 2 * 2) + startCapInfo.vbsize + endCapInfo.vbsize;
  12759. this._borderVB = new Float32Array(vbSize);
  12760. var vb = this._borderVB;
  12761. var ht = this.fillThickness / 2;
  12762. var bt = this.borderThickness;
  12763. var total = this.points.length;
  12764. this._buildLine(vb, contour, ht, bt);
  12765. var max = total * 2 * 2;
  12766. var triCount = (count - (this.closed ? 0 : 1)) * 2 * 2;
  12767. this._borderIB = new Float32Array(triCount * 3 + startCapInfo.ibsize + endCapInfo.ibsize);
  12768. var ib = this._borderIB;
  12769. for (var i = 0; i < triCount; i += 4) {
  12770. ib[i * 3 + 0] = i + 0;
  12771. ib[i * 3 + 1] = i + 2;
  12772. ib[i * 3 + 2] = (i + 6) % max;
  12773. ib[i * 3 + 3] = i + 0;
  12774. ib[i * 3 + 4] = (i + 6) % max;
  12775. ib[i * 3 + 5] = (i + 4) % max;
  12776. ib[i * 3 + 6] = i + 3;
  12777. ib[i * 3 + 7] = i + 1;
  12778. ib[i * 3 + 8] = (i + 5) % max;
  12779. ib[i * 3 + 9] = i + 3;
  12780. ib[i * 3 + 10] = (i + 5) % max;
  12781. ib[i * 3 + 11] = (i + 7) % max;
  12782. }
  12783. this._buildCap(vb, count * 2 * 2 * 2, ib, triCount * 3, this.points[0], this.fillThickness, this.borderThickness, this.startCap, Lines2D_1._startDir, startCapContour);
  12784. this._buildCap(vb, (count * 2 * 2 * 2) + startCapInfo.vbsize, ib, (triCount * 3) + startCapInfo.ibsize, this.points[total - 1], this.fillThickness, this.borderThickness, this.endCap, Lines2D_1._endDir, endCapContour);
  12785. }
  12786. this._contour = contour;
  12787. if (startCapContour.length > 0) {
  12788. var startCapTri = Earcut.earcut(startCapContour, null, 2);
  12789. this._startCapTriIndices = startCapTri;
  12790. this._startCapContour = startCapContour;
  12791. }
  12792. else {
  12793. this._startCapTriIndices = null;
  12794. this._startCapContour = null;
  12795. }
  12796. if (endCapContour.length > 0) {
  12797. var endCapTri = Earcut.earcut(endCapContour, null, 2);
  12798. this._endCapContour = endCapContour;
  12799. this._endCapTriIndices = endCapTri;
  12800. }
  12801. else {
  12802. this._endCapContour = null;
  12803. this._endCapTriIndices = null;
  12804. }
  12805. var bs = this._boundingMax.subtract(this._boundingMin);
  12806. this._size.width = bs.x;
  12807. this._size.height = bs.y;
  12808. };
  12809. Object.defineProperty(Lines2D.prototype, "size", {
  12810. get: function () {
  12811. if (this._size == null) {
  12812. this._computeLines2D();
  12813. }
  12814. return this._size;
  12815. },
  12816. enumerable: true,
  12817. configurable: true
  12818. });
  12819. Lines2D.prototype.createInstanceDataParts = function () {
  12820. var res = new Array();
  12821. if (this.border) {
  12822. res.push(new Lines2DInstanceData(BABYLON.Shape2D.SHAPE2D_BORDERPARTID));
  12823. }
  12824. if (this.fill) {
  12825. res.push(new Lines2DInstanceData(BABYLON.Shape2D.SHAPE2D_FILLPARTID));
  12826. }
  12827. return res;
  12828. };
  12829. Lines2D.prototype.applyActualScaleOnTransform = function () {
  12830. return true;
  12831. };
  12832. Lines2D.prototype.refreshInstanceDataPart = function (part) {
  12833. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  12834. return false;
  12835. }
  12836. if (part.id === BABYLON.Shape2D.SHAPE2D_BORDERPARTID) {
  12837. var d = part;
  12838. if (this.border instanceof BABYLON.GradientColorBrush2D) {
  12839. d.boundingMin = this.boundingMin;
  12840. d.boundingMax = this.boundingMax;
  12841. }
  12842. }
  12843. else if (part.id === BABYLON.Shape2D.SHAPE2D_FILLPARTID) {
  12844. var d = part;
  12845. if (this.fill instanceof BABYLON.GradientColorBrush2D) {
  12846. d.boundingMin = this.boundingMin;
  12847. d.boundingMax = this.boundingMax;
  12848. }
  12849. }
  12850. return true;
  12851. };
  12852. return Lines2D;
  12853. }(BABYLON.Shape2D));
  12854. Lines2D._prevA = BABYLON.Vector2.Zero();
  12855. Lines2D._prevB = BABYLON.Vector2.Zero();
  12856. Lines2D._curA = BABYLON.Vector2.Zero();
  12857. Lines2D._curB = BABYLON.Vector2.Zero();
  12858. Lines2D._miterTps = BABYLON.Vector2.Zero();
  12859. Lines2D._startDir = BABYLON.Vector2.Zero();
  12860. Lines2D._endDir = BABYLON.Vector2.Zero();
  12861. Lines2D._tpsV = BABYLON.Vector2.Zero();
  12862. Lines2D._noCap = 0;
  12863. Lines2D._roundCap = 1;
  12864. Lines2D._triangleCap = 2;
  12865. Lines2D._squareAnchorCap = 3;
  12866. Lines2D._roundAnchorCap = 4;
  12867. Lines2D._diamondAnchorCap = 5;
  12868. Lines2D._arrowCap = 6;
  12869. Lines2D._roundCapSubDiv = 36;
  12870. __decorate([
  12871. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 1, function (pi) { return Lines2D_1.pointsProperty = pi; })
  12872. ], Lines2D.prototype, "points", null);
  12873. __decorate([
  12874. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 2, function (pi) { return Lines2D_1.fillThicknessProperty = pi; })
  12875. ], Lines2D.prototype, "fillThickness", null);
  12876. __decorate([
  12877. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 3, function (pi) { return Lines2D_1.closedProperty = pi; })
  12878. ], Lines2D.prototype, "closed", null);
  12879. __decorate([
  12880. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 4, function (pi) { return Lines2D_1.startCapProperty = pi; })
  12881. ], Lines2D.prototype, "startCap", null);
  12882. __decorate([
  12883. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 5, function (pi) { return Lines2D_1.endCapProperty = pi; })
  12884. ], Lines2D.prototype, "endCap", null);
  12885. Lines2D = Lines2D_1 = __decorate([
  12886. BABYLON.className("Lines2D", "BABYLON")
  12887. ], Lines2D);
  12888. BABYLON.Lines2D = Lines2D;
  12889. var Lines2D_1;
  12890. })(BABYLON || (BABYLON = {}));
  12891. var __extends = (this && this.__extends) || function (d, b) {
  12892. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  12893. function __() { this.constructor = d; }
  12894. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  12895. };
  12896. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  12897. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  12898. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  12899. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  12900. return c > 3 && r && Object.defineProperty(target, key, r), r;
  12901. };
  12902. var BABYLON;
  12903. (function (BABYLON) {
  12904. // This class contains data that lifetime is bounding to the Babylon Engine object
  12905. var Canvas2DEngineBoundData = (function () {
  12906. function Canvas2DEngineBoundData() {
  12907. this._modelCache = new BABYLON.StringDictionary();
  12908. }
  12909. Canvas2DEngineBoundData.prototype.GetOrAddModelCache = function (key, factory) {
  12910. return this._modelCache.getOrAddWithFactory(key, factory);
  12911. };
  12912. Canvas2DEngineBoundData.prototype.DisposeModelRenderCache = function (modelRenderCache) {
  12913. if (!modelRenderCache.isDisposed) {
  12914. return false;
  12915. }
  12916. this._modelCache.remove(modelRenderCache.modelKey);
  12917. return true;
  12918. };
  12919. return Canvas2DEngineBoundData;
  12920. }());
  12921. BABYLON.Canvas2DEngineBoundData = Canvas2DEngineBoundData;
  12922. var Canvas2D = Canvas2D_1 = (function (_super) {
  12923. __extends(Canvas2D, _super);
  12924. function Canvas2D(scene, settings) {
  12925. var _this = _super.call(this, settings) || this;
  12926. /**
  12927. * If you set your own WorldSpaceNode to display the Canvas2D you have to provide your own implementation of this method which computes the local position in the Canvas based on the given 3D World one.
  12928. * Beware that you have to take under consideration the origin in your calculations! Good luck!
  12929. */
  12930. _this.worldSpaceToNodeLocal = function (worldPos) {
  12931. var node = _this._worldSpaceNode;
  12932. if (!node) {
  12933. return;
  12934. }
  12935. var mtx = node.getWorldMatrix().clone();
  12936. mtx.invert();
  12937. var v = BABYLON.Vector3.TransformCoordinates(worldPos, mtx);
  12938. var res = new BABYLON.Vector2(v.x, v.y);
  12939. var size = _this.actualSize;
  12940. res.x += size.width * 0.5; // res is centered, make it relative to bottom/left
  12941. res.y += size.height * 0.5;
  12942. return res;
  12943. };
  12944. /**
  12945. * If you use a custom WorldSpaceCanvasNode you have to override this property to update the UV of your object to reflect the changes due to a resizing of the cached bitmap
  12946. */
  12947. _this.worldSpaceCacheChanged = function () {
  12948. var plane = _this.worldSpaceCanvasNode;
  12949. var vd = BABYLON.VertexData.ExtractFromMesh(plane); //new VertexData();
  12950. vd.uvs = new Float32Array(8);
  12951. var material = plane.material;
  12952. var tex = _this._renderableData._cacheTexture;
  12953. if (material.diffuseTexture !== tex) {
  12954. material.diffuseTexture = tex;
  12955. tex.hasAlpha = true;
  12956. }
  12957. var nodeuv = _this._renderableData._cacheNodeUVs;
  12958. for (var i = 0; i < 4; i++) {
  12959. vd.uvs[i * 2 + 0] = nodeuv[i].x;
  12960. vd.uvs[i * 2 + 1] = nodeuv[i].y;
  12961. }
  12962. vd.applyToMesh(plane);
  12963. };
  12964. _this._notifDebugMode = false;
  12965. /**
  12966. * Instanced Array will be create if there's at least this number of parts/prim that can fit into it
  12967. */
  12968. _this.minPartCountToUseInstancedArray = 5;
  12969. _this._mapCounter = 0;
  12970. _this._drawCallsOpaqueCounter = new BABYLON.PerfCounter();
  12971. _this._drawCallsAlphaTestCounter = new BABYLON.PerfCounter();
  12972. _this._drawCallsTransparentCounter = new BABYLON.PerfCounter();
  12973. _this._groupRenderCounter = new BABYLON.PerfCounter();
  12974. _this._updateTransparentDataCounter = new BABYLON.PerfCounter();
  12975. _this._cachedGroupRenderCounter = new BABYLON.PerfCounter();
  12976. _this._updateCachedStateCounter = new BABYLON.PerfCounter();
  12977. _this._updateLayoutCounter = new BABYLON.PerfCounter();
  12978. _this._updatePositioningCounter = new BABYLON.PerfCounter();
  12979. _this._updateLocalTransformCounter = new BABYLON.PerfCounter();
  12980. _this._updateGlobalTransformCounter = new BABYLON.PerfCounter();
  12981. _this._boundingInfoRecomputeCounter = new BABYLON.PerfCounter();
  12982. _this._uid = null;
  12983. _this._cachedCanvasGroup = null;
  12984. _this._renderingGroupObserver = null;
  12985. _this._beforeRenderObserver = null;
  12986. _this._afterRenderObserver = null;
  12987. _this._profileInfoText = null;
  12988. BABYLON.Prim2DBase._isCanvasInit = false;
  12989. if (!settings) {
  12990. settings = {};
  12991. }
  12992. if (_this._cachingStrategy !== Canvas2D_1.CACHESTRATEGY_TOPLEVELGROUPS) {
  12993. _this._background = new BABYLON.Rectangle2D({ parent: _this, id: "###CANVAS BACKGROUND###", size: settings.size }); //TODO CHECK when size is null
  12994. _this._background.zOrder = 1.0;
  12995. _this._background.isPickable = false;
  12996. _this._background.origin = BABYLON.Vector2.Zero();
  12997. _this._background.levelVisible = false;
  12998. if (settings.backgroundRoundRadius != null) {
  12999. _this.backgroundRoundRadius = settings.backgroundRoundRadius;
  13000. }
  13001. if (settings.backgroundBorder != null) {
  13002. if (typeof (settings.backgroundBorder) === "string") {
  13003. _this.backgroundBorder = Canvas2D_1.GetBrushFromString(settings.backgroundBorder);
  13004. }
  13005. else {
  13006. _this.backgroundBorder = settings.backgroundBorder;
  13007. }
  13008. }
  13009. if (settings.backgroundBorderThickNess != null) {
  13010. _this.backgroundBorderThickness = settings.backgroundBorderThickNess;
  13011. }
  13012. if (settings.backgroundFill != null) {
  13013. if (typeof (settings.backgroundFill) === "string") {
  13014. _this.backgroundFill = Canvas2D_1.GetBrushFromString(settings.backgroundFill);
  13015. }
  13016. else {
  13017. _this.backgroundFill = settings.backgroundFill;
  13018. }
  13019. }
  13020. // Put a handler to resize the background whenever the canvas is resizing
  13021. _this.propertyChanged.add(function (e, s) {
  13022. if (e.propertyName === "size") {
  13023. _this._background.size = _this.size;
  13024. }
  13025. }, BABYLON.Group2D.sizeProperty.flagId);
  13026. _this._background._patchHierarchy(_this);
  13027. }
  13028. var engine = scene.getEngine();
  13029. _this.__engineData = engine.getOrAddExternalDataWithFactory("__BJSCANVAS2D__", function (k) { return new Canvas2DEngineBoundData(); });
  13030. _this._primPointerInfo = new BABYLON.PrimitivePointerInfo();
  13031. _this._capturedPointers = new BABYLON.StringDictionary();
  13032. _this._pickStartingPosition = BABYLON.Vector2.Zero();
  13033. _this._hierarchyLevelMaxSiblingCount = 50;
  13034. _this._hierarchyDepth = 0;
  13035. _this._zOrder = 0;
  13036. _this._zMax = 1;
  13037. _this._scene = scene;
  13038. _this._engine = engine;
  13039. _this._renderingSize = new BABYLON.Size(0, 0);
  13040. _this._designSize = settings.designSize || null;
  13041. _this._designUseHorizAxis = settings.designUseHorizAxis === true;
  13042. if (!_this._trackedGroups) {
  13043. _this._trackedGroups = new Array();
  13044. }
  13045. _this._maxAdaptiveWorldSpaceCanvasSize = null;
  13046. _this._groupCacheMaps = new BABYLON.StringDictionary();
  13047. _this._patchHierarchy(_this);
  13048. var enableInteraction = (settings.enableInteraction == null) ? true : settings.enableInteraction;
  13049. _this._fitRenderingDevice = !settings.size;
  13050. if (!settings.size) {
  13051. settings.size = new BABYLON.Size(engine.getRenderWidth(), engine.getRenderHeight());
  13052. }
  13053. // Register scene dispose to also dispose the canvas when it'll happens
  13054. scene.onDisposeObservable.add(function (d, s) {
  13055. _this.dispose();
  13056. });
  13057. if (_this._isScreenSpace) {
  13058. if (settings.renderingPhase) {
  13059. if (!settings.renderingPhase.camera || settings.renderingPhase.renderingGroupID == null) {
  13060. throw Error("You have to specify a valid camera and renderingGroup");
  13061. }
  13062. _this._renderingGroupObserver = _this._scene.onRenderingGroupObservable.add(function (e, s) {
  13063. if ((_this._scene.activeCamera === settings.renderingPhase.camera) && (e.renderStage === BABYLON.RenderingGroupInfo.STAGE_POSTTRANSPARENT)) {
  13064. _this._engine.clear(null, false, true, true);
  13065. _this._render();
  13066. }
  13067. }, Math.pow(2, settings.renderingPhase.renderingGroupID));
  13068. }
  13069. else {
  13070. _this._afterRenderObserver = _this._scene.onAfterRenderObservable.add(function (d, s) {
  13071. _this._engine.clear(null, false, true, true);
  13072. _this._render();
  13073. });
  13074. }
  13075. }
  13076. else {
  13077. _this._beforeRenderObserver = _this._scene.onBeforeRenderObservable.add(function (d, s) {
  13078. _this._render();
  13079. });
  13080. }
  13081. _this._supprtInstancedArray = _this._engine.getCaps().instancedArrays !== null;
  13082. //this._supprtInstancedArray = false; // TODO REMOVE!!!
  13083. _this._setupInteraction(enableInteraction);
  13084. // Register this instance
  13085. Canvas2D_1._INSTANCES.push(_this);
  13086. return _this;
  13087. }
  13088. Object.defineProperty(Canvas2D.prototype, "drawCallsOpaqueCounter", {
  13089. get: function () {
  13090. return this._drawCallsOpaqueCounter;
  13091. },
  13092. enumerable: true,
  13093. configurable: true
  13094. });
  13095. Object.defineProperty(Canvas2D.prototype, "drawCallsAlphaTestCounter", {
  13096. get: function () {
  13097. return this._drawCallsAlphaTestCounter;
  13098. },
  13099. enumerable: true,
  13100. configurable: true
  13101. });
  13102. Object.defineProperty(Canvas2D.prototype, "drawCallsTransparentCounter", {
  13103. get: function () {
  13104. return this._drawCallsTransparentCounter;
  13105. },
  13106. enumerable: true,
  13107. configurable: true
  13108. });
  13109. Object.defineProperty(Canvas2D.prototype, "groupRenderCounter", {
  13110. get: function () {
  13111. return this._groupRenderCounter;
  13112. },
  13113. enumerable: true,
  13114. configurable: true
  13115. });
  13116. Object.defineProperty(Canvas2D.prototype, "updateTransparentDataCounter", {
  13117. get: function () {
  13118. return this._updateTransparentDataCounter;
  13119. },
  13120. enumerable: true,
  13121. configurable: true
  13122. });
  13123. Object.defineProperty(Canvas2D.prototype, "cachedGroupRenderCounter", {
  13124. get: function () {
  13125. return this._cachedGroupRenderCounter;
  13126. },
  13127. enumerable: true,
  13128. configurable: true
  13129. });
  13130. Object.defineProperty(Canvas2D.prototype, "updateCachedStateCounter", {
  13131. get: function () {
  13132. return this._updateCachedStateCounter;
  13133. },
  13134. enumerable: true,
  13135. configurable: true
  13136. });
  13137. Object.defineProperty(Canvas2D.prototype, "updateLayoutCounter", {
  13138. get: function () {
  13139. return this._updateLayoutCounter;
  13140. },
  13141. enumerable: true,
  13142. configurable: true
  13143. });
  13144. Object.defineProperty(Canvas2D.prototype, "updatePositioningCounter", {
  13145. get: function () {
  13146. return this._updatePositioningCounter;
  13147. },
  13148. enumerable: true,
  13149. configurable: true
  13150. });
  13151. Object.defineProperty(Canvas2D.prototype, "updateLocalTransformCounter", {
  13152. get: function () {
  13153. return this._updateLocalTransformCounter;
  13154. },
  13155. enumerable: true,
  13156. configurable: true
  13157. });
  13158. Object.defineProperty(Canvas2D.prototype, "updateGlobalTransformCounter", {
  13159. get: function () {
  13160. return this._updateGlobalTransformCounter;
  13161. },
  13162. enumerable: true,
  13163. configurable: true
  13164. });
  13165. Object.defineProperty(Canvas2D.prototype, "boundingInfoRecomputeCounter", {
  13166. get: function () {
  13167. return this._boundingInfoRecomputeCounter;
  13168. },
  13169. enumerable: true,
  13170. configurable: true
  13171. });
  13172. Object.defineProperty(Canvas2D, "instances", {
  13173. get: function () {
  13174. return Canvas2D_1._INSTANCES;
  13175. },
  13176. enumerable: true,
  13177. configurable: true
  13178. });
  13179. Canvas2D.prototype._canvasPreInit = function (settings) {
  13180. var cachingStrategy = (settings.cachingStrategy == null) ? Canvas2D_1.CACHESTRATEGY_DONTCACHE : settings.cachingStrategy;
  13181. this._cachingStrategy = cachingStrategy;
  13182. this._isScreenSpace = (settings.isScreenSpace == null) ? true : settings.isScreenSpace;
  13183. };
  13184. Canvas2D.prototype._setupInteraction = function (enable) {
  13185. var _this = this;
  13186. // No change detection
  13187. if (enable === this._interactionEnabled) {
  13188. return;
  13189. }
  13190. // Set the new state
  13191. this._interactionEnabled = enable;
  13192. // ScreenSpace mode
  13193. if (this._isScreenSpace) {
  13194. // Disable interaction
  13195. if (!enable) {
  13196. if (this._scenePrePointerObserver) {
  13197. this.scene.onPrePointerObservable.remove(this._scenePrePointerObserver);
  13198. this._scenePrePointerObserver = null;
  13199. }
  13200. return;
  13201. }
  13202. // Enable Interaction
  13203. // Register the observable
  13204. this._scenePrePointerObserver = this.scene.onPrePointerObservable.add(function (e, s) {
  13205. if (_this.isVisible === false) {
  13206. return;
  13207. }
  13208. var hs = 1 / _this.engine.getHardwareScalingLevel();
  13209. var localPos = e.localPosition.multiplyByFloats(hs, hs);
  13210. _this._handlePointerEventForInteraction(e, localPos, s);
  13211. });
  13212. }
  13213. else {
  13214. var scene = this.scene;
  13215. if (enable) {
  13216. scene.constantlyUpdateMeshUnderPointer = true;
  13217. this._scenePointerObserver = scene.onPointerObservable.add(function (e, s) {
  13218. if (_this.isVisible === false) {
  13219. return;
  13220. }
  13221. if (e.pickInfo.hit && e.pickInfo.pickedMesh === _this._worldSpaceNode && _this.worldSpaceToNodeLocal) {
  13222. var localPos = _this.worldSpaceToNodeLocal(e.pickInfo.pickedPoint);
  13223. _this._handlePointerEventForInteraction(e, localPos, s);
  13224. }
  13225. });
  13226. }
  13227. else {
  13228. if (this._scenePointerObserver) {
  13229. this.scene.onPointerObservable.remove(this._scenePointerObserver);
  13230. this._scenePointerObserver = null;
  13231. }
  13232. }
  13233. }
  13234. };
  13235. /**
  13236. * Internal method, you should use the Prim2DBase version instead
  13237. */
  13238. Canvas2D.prototype._setPointerCapture = function (pointerId, primitive) {
  13239. if (this.isPointerCaptured(pointerId)) {
  13240. return false;
  13241. }
  13242. // Try to capture the pointer on the HTML side
  13243. try {
  13244. this.engine.getRenderingCanvas().setPointerCapture(pointerId);
  13245. }
  13246. catch (e) {
  13247. }
  13248. this._primPointerInfo.updateRelatedTarget(primitive, BABYLON.Vector2.Zero());
  13249. this._bubbleNotifyPrimPointerObserver(primitive, BABYLON.PrimitivePointerInfo.PointerGotCapture, null);
  13250. this._capturedPointers.add(pointerId.toString(), primitive);
  13251. return true;
  13252. };
  13253. /**
  13254. * Internal method, you should use the Prim2DBase version instead
  13255. */
  13256. Canvas2D.prototype._releasePointerCapture = function (pointerId, primitive) {
  13257. if (this._capturedPointers.get(pointerId.toString()) !== primitive) {
  13258. return false;
  13259. }
  13260. // Try to release the pointer on the HTML side
  13261. try {
  13262. this.engine.getRenderingCanvas().releasePointerCapture(pointerId);
  13263. }
  13264. catch (e) {
  13265. }
  13266. this._primPointerInfo.updateRelatedTarget(primitive, BABYLON.Vector2.Zero());
  13267. this._bubbleNotifyPrimPointerObserver(primitive, BABYLON.PrimitivePointerInfo.PointerLostCapture, null);
  13268. this._capturedPointers.remove(pointerId.toString());
  13269. return true;
  13270. };
  13271. /**
  13272. * Determine if the given pointer is captured or not
  13273. * @param pointerId the Id of the pointer
  13274. * @return true if it's captured, false otherwise
  13275. */
  13276. Canvas2D.prototype.isPointerCaptured = function (pointerId) {
  13277. return this._capturedPointers.contains(pointerId.toString());
  13278. };
  13279. Canvas2D.prototype.getCapturedPrimitive = function (pointerId) {
  13280. // Avoid unnecessary lookup
  13281. if (this._capturedPointers.count === 0) {
  13282. return null;
  13283. }
  13284. return this._capturedPointers.get(pointerId.toString());
  13285. };
  13286. Canvas2D.prototype._handlePointerEventForInteraction = function (eventData, localPosition, eventState) {
  13287. // Dispose check
  13288. if (this.isDisposed) {
  13289. return;
  13290. }
  13291. // Update the this._primPointerInfo structure we'll send to observers using the PointerEvent data
  13292. if (!this._updatePointerInfo(eventData, localPosition)) {
  13293. return;
  13294. }
  13295. var capturedPrim = this.getCapturedPrimitive(this._primPointerInfo.pointerId);
  13296. // Make sure the intersection list is up to date, we maintain this list either in response of a mouse event (here) or before rendering the canvas.
  13297. // Why before rendering the canvas? because some primitives may move and get away/under the mouse cursor (which is not moving). So we need to update at both location in order to always have an accurate list, which is needed for the hover state change.
  13298. this._updateIntersectionList(this._primPointerInfo.canvasPointerPos, capturedPrim !== null, true);
  13299. // Update the over status, same as above, it's could be done here or during rendering, but will be performed only once per render frame
  13300. this._updateOverStatus(true);
  13301. // Check if we have nothing to raise
  13302. if (!this._actualOverPrimitive && !capturedPrim) {
  13303. return;
  13304. }
  13305. // Update the relatedTarget info with the over primitive or the captured one (if any)
  13306. var targetPrim = capturedPrim || this._actualOverPrimitive.prim;
  13307. var targetPointerPos = capturedPrim ? this._primPointerInfo.canvasPointerPos.subtract(new BABYLON.Vector2(targetPrim.globalTransform.m[12], targetPrim.globalTransform.m[13])) : this._actualOverPrimitive.intersectionLocation;
  13308. this._primPointerInfo.updateRelatedTarget(targetPrim, targetPointerPos);
  13309. // Analyze the pointer event type and fire proper events on the primitive
  13310. var skip = false;
  13311. if (eventData.type === BABYLON.PointerEventTypes.POINTERWHEEL) {
  13312. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerMouseWheel, eventData);
  13313. }
  13314. else if (eventData.type === BABYLON.PointerEventTypes.POINTERMOVE) {
  13315. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerMove, eventData);
  13316. }
  13317. else if (eventData.type === BABYLON.PointerEventTypes.POINTERDOWN) {
  13318. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerDown, eventData);
  13319. }
  13320. else if (eventData.type === BABYLON.PointerEventTypes.POINTERUP) {
  13321. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerUp, eventData);
  13322. }
  13323. eventState.skipNextObservers = skip;
  13324. };
  13325. Canvas2D.prototype._updatePointerInfo = function (eventData, localPosition) {
  13326. var s = this.scale;
  13327. var pii = this._primPointerInfo;
  13328. pii.cancelBubble = false;
  13329. if (!pii.canvasPointerPos) {
  13330. pii.canvasPointerPos = BABYLON.Vector2.Zero();
  13331. }
  13332. var camera = this._scene.cameraToUseForPointers || this._scene.activeCamera;
  13333. if (!camera || !camera.viewport) {
  13334. return false;
  13335. }
  13336. var engine = this._scene.getEngine();
  13337. if (this._isScreenSpace) {
  13338. var cameraViewport = camera.viewport;
  13339. var viewport = cameraViewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight());
  13340. // Moving coordinates to local viewport world
  13341. var x = localPosition.x - viewport.x;
  13342. var y = localPosition.y - viewport.y;
  13343. pii.canvasPointerPos.x = (x - this.actualPosition.x) / s;
  13344. pii.canvasPointerPos.y = (engine.getRenderHeight() - y - this.actualPosition.y) / s;
  13345. }
  13346. else {
  13347. pii.canvasPointerPos.x = localPosition.x / s;
  13348. pii.canvasPointerPos.y = localPosition.y / s;
  13349. }
  13350. //console.log(`UpdatePointerInfo for ${this.id}, X:${pii.canvasPointerPos.x}, Y:${pii.canvasPointerPos.y}`);
  13351. pii.mouseWheelDelta = 0;
  13352. if (eventData.type === BABYLON.PointerEventTypes.POINTERWHEEL) {
  13353. var event = eventData.event;
  13354. if (event.wheelDelta) {
  13355. pii.mouseWheelDelta = event.wheelDelta / (BABYLON.PrimitivePointerInfo.MouseWheelPrecision * 40);
  13356. }
  13357. else if (event.detail) {
  13358. pii.mouseWheelDelta = -event.detail / BABYLON.PrimitivePointerInfo.MouseWheelPrecision;
  13359. }
  13360. }
  13361. else {
  13362. var pe = eventData.event;
  13363. pii.ctrlKey = pe.ctrlKey;
  13364. pii.altKey = pe.altKey;
  13365. pii.shiftKey = pe.shiftKey;
  13366. pii.metaKey = pe.metaKey;
  13367. pii.button = pe.button;
  13368. pii.buttons = pe.buttons;
  13369. pii.pointerId = pe.pointerId;
  13370. pii.width = pe.width;
  13371. pii.height = pe.height;
  13372. pii.presssure = pe.pressure;
  13373. pii.tilt.x = pe.tiltX;
  13374. pii.tilt.y = pe.tiltY;
  13375. pii.isCaptured = this.getCapturedPrimitive(pe.pointerId) !== null;
  13376. }
  13377. return true;
  13378. };
  13379. Canvas2D.prototype._updateIntersectionList = function (mouseLocalPos, isCapture, force) {
  13380. if (!force && (this.scene.getRenderId() === this._intersectionRenderId)) {
  13381. return;
  13382. }
  13383. // A little safe guard, it might happens than the event is triggered before the first render and nothing is computed, this simple check will make sure everything will be fine
  13384. if (!this._globalTransform) {
  13385. this.updateCachedStates(true);
  13386. }
  13387. var ii = Canvas2D_1._interInfo;
  13388. ii.pickPosition.x = mouseLocalPos.x;
  13389. ii.pickPosition.y = mouseLocalPos.y;
  13390. ii.findFirstOnly = false;
  13391. // Fast rejection: test if the mouse pointer is outside the canvas's bounding Info
  13392. if (!isCapture && !this.levelBoundingInfo.doesIntersect(ii.pickPosition)) {
  13393. // Reset intersection info as we don't hit anything
  13394. ii.intersectedPrimitives = new Array();
  13395. ii.topMostIntersectedPrimitive = null;
  13396. }
  13397. else {
  13398. // The pointer is inside the Canvas, do an intersection test
  13399. this.intersect(ii);
  13400. // Sort primitives to get them from top to bottom
  13401. ii.intersectedPrimitives = ii.intersectedPrimitives.sort(function (a, b) { return a.prim.actualZOffset - b.prim.actualZOffset; });
  13402. }
  13403. {
  13404. // Update prev/actual intersection info, fire "overPrim" property change if needed
  13405. this._previousIntersectionList = this._actualIntersectionList;
  13406. this._actualIntersectionList = ii.intersectedPrimitives;
  13407. this._previousOverPrimitive = this._actualOverPrimitive;
  13408. this._actualOverPrimitive = ii.topMostIntersectedPrimitive;
  13409. var prev = (this._previousOverPrimitive != null) ? this._previousOverPrimitive.prim : null;
  13410. var actual = (this._actualOverPrimitive != null) ? this._actualOverPrimitive.prim : null;
  13411. if (prev !== actual) {
  13412. this.onPropertyChanged("overPrim", this._previousOverPrimitive ? this._previousOverPrimitive.prim : null, this._actualOverPrimitive ? this._actualOverPrimitive.prim : null);
  13413. }
  13414. }
  13415. this._intersectionRenderId = this.scene.getRenderId();
  13416. };
  13417. // Based on the previousIntersectionList and the actualInstersectionList we can determined which primitives are being hover state or loosing it
  13418. Canvas2D.prototype._updateOverStatus = function (force) {
  13419. if ((!force && (this.scene.getRenderId() === this._hoverStatusRenderId)) || !this._previousIntersectionList || !this._actualIntersectionList) {
  13420. return;
  13421. }
  13422. // Detect a change of over
  13423. var prevPrim = this._previousOverPrimitive ? this._previousOverPrimitive.prim : null;
  13424. var actualPrim = this._actualOverPrimitive ? this._actualOverPrimitive.prim : null;
  13425. if (prevPrim !== actualPrim) {
  13426. // Detect if the current pointer is captured, only fire event if they belong to the capture primitive
  13427. var capturedPrim = this.getCapturedPrimitive(this._primPointerInfo.pointerId);
  13428. // See the NOTE section of: https://www.w3.org/TR/pointerevents/#setting-pointer-capture
  13429. if (capturedPrim) {
  13430. if (capturedPrim === prevPrim) {
  13431. this._primPointerInfo.updateRelatedTarget(prevPrim, this._previousOverPrimitive.intersectionLocation);
  13432. this._bubbleNotifyPrimPointerObserver(prevPrim, BABYLON.PrimitivePointerInfo.PointerOut, null);
  13433. }
  13434. else if (capturedPrim === actualPrim) {
  13435. this._primPointerInfo.updateRelatedTarget(actualPrim, this._actualOverPrimitive.intersectionLocation);
  13436. this._bubbleNotifyPrimPointerObserver(actualPrim, BABYLON.PrimitivePointerInfo.PointerOver, null);
  13437. }
  13438. }
  13439. else {
  13440. var _loop_1 = function (prev) {
  13441. if (!BABYLON.Tools.first(this_1._actualIntersectionList, function (pii) { return pii.prim === prev.prim; })) {
  13442. this_1._primPointerInfo.updateRelatedTarget(prev.prim, prev.intersectionLocation);
  13443. this_1._bubbleNotifyPrimPointerObserver(prev.prim, BABYLON.PrimitivePointerInfo.PointerOut, null);
  13444. }
  13445. };
  13446. var this_1 = this;
  13447. // Check for Out & Leave
  13448. for (var _i = 0, _a = this._previousIntersectionList; _i < _a.length; _i++) {
  13449. var prev = _a[_i];
  13450. _loop_1(prev);
  13451. }
  13452. var _loop_2 = function (actual) {
  13453. if (!BABYLON.Tools.first(this_2._previousIntersectionList, function (pii) { return pii.prim === actual.prim; })) {
  13454. this_2._primPointerInfo.updateRelatedTarget(actual.prim, actual.intersectionLocation);
  13455. this_2._bubbleNotifyPrimPointerObserver(actual.prim, BABYLON.PrimitivePointerInfo.PointerOver, null);
  13456. }
  13457. };
  13458. var this_2 = this;
  13459. // Check for Over & Enter
  13460. for (var _b = 0, _c = this._actualIntersectionList; _b < _c.length; _b++) {
  13461. var actual = _c[_b];
  13462. _loop_2(actual);
  13463. }
  13464. }
  13465. }
  13466. this._hoverStatusRenderId = this.scene.getRenderId();
  13467. };
  13468. Canvas2D.prototype._updatePrimPointerPos = function (prim) {
  13469. if (this._primPointerInfo.isCaptured) {
  13470. this._primPointerInfo.primitivePointerPos = this._primPointerInfo.relatedTargetPointerPos;
  13471. }
  13472. else {
  13473. for (var _i = 0, _a = this._actualIntersectionList; _i < _a.length; _i++) {
  13474. var pii = _a[_i];
  13475. if (pii.prim === prim) {
  13476. this._primPointerInfo.primitivePointerPos = pii.intersectionLocation;
  13477. return;
  13478. }
  13479. }
  13480. }
  13481. };
  13482. Canvas2D.prototype._debugExecObserver = function (prim, mask) {
  13483. if (!this._notifDebugMode) {
  13484. return;
  13485. }
  13486. var debug = "";
  13487. for (var i = 0; i < prim.hierarchyDepth; i++) {
  13488. debug += " ";
  13489. }
  13490. var pii = this._primPointerInfo;
  13491. debug += "[RID:" + this.scene.getRenderId() + "] [" + prim.hierarchyDepth + "] event:" + BABYLON.PrimitivePointerInfo.getEventTypeName(mask) + ", id: " + prim.id + " (" + BABYLON.Tools.getClassName(prim) + "), primPos: " + pii.primitivePointerPos.toString() + ", canvasPos: " + pii.canvasPointerPos.toString() + ", relatedTarget: " + pii.relatedTarget.id;
  13492. console.log(debug);
  13493. };
  13494. Canvas2D.prototype._bubbleNotifyPrimPointerObserver = function (prim, mask, eventData) {
  13495. var ppi = this._primPointerInfo;
  13496. var event = eventData ? eventData.event : null;
  13497. var cur = prim;
  13498. while (cur && !cur.isDisposed) {
  13499. this._updatePrimPointerPos(cur);
  13500. // For the first level we have to fire Enter or Leave for corresponding Over or Out
  13501. if (cur === prim) {
  13502. // Fire the proper notification
  13503. if (mask === BABYLON.PrimitivePointerInfo.PointerOver) {
  13504. this._debugExecObserver(prim, BABYLON.PrimitivePointerInfo.PointerEnter);
  13505. prim._pointerEventObservable.notifyObservers(ppi, BABYLON.PrimitivePointerInfo.PointerEnter);
  13506. }
  13507. else if (mask === BABYLON.PrimitivePointerInfo.PointerOut) {
  13508. this._debugExecObserver(prim, BABYLON.PrimitivePointerInfo.PointerLeave);
  13509. prim._pointerEventObservable.notifyObservers(ppi, BABYLON.PrimitivePointerInfo.PointerLeave);
  13510. }
  13511. }
  13512. // Exec the observers
  13513. this._debugExecObserver(cur, mask);
  13514. if (!cur._pointerEventObservable.notifyObservers(ppi, mask) && eventData instanceof BABYLON.PointerInfoPre) {
  13515. eventData.skipOnPointerObservable = true;
  13516. return false;
  13517. }
  13518. this._triggerActionManager(cur, ppi, mask, event);
  13519. // Bubble canceled? If we're not executing PointerOver or PointerOut, quit immediately
  13520. // If it's PointerOver/Out we have to trigger PointerEnter/Leave no matter what
  13521. if (ppi.cancelBubble) {
  13522. return false;
  13523. }
  13524. // Loop to the parent
  13525. cur = cur.parent;
  13526. }
  13527. return true;
  13528. };
  13529. Canvas2D.prototype._triggerActionManager = function (prim, ppi, mask, eventData) {
  13530. var _this = this;
  13531. // A little safe guard, it might happens than the event is triggered before the first render and nothing is computed, this simple check will make sure everything will be fine
  13532. if (!this._globalTransform) {
  13533. this.updateCachedStates(true);
  13534. }
  13535. // Process Trigger related to PointerDown
  13536. if ((mask & BABYLON.PrimitivePointerInfo.PointerDown) !== 0) {
  13537. // On pointer down, record the current position and time to be able to trick PickTrigger and LongPressTrigger
  13538. this._pickStartingPosition = ppi.primitivePointerPos.clone();
  13539. this._pickStartingTime = new Date().getTime();
  13540. this._pickedDownPrim = null;
  13541. if (prim.actionManager) {
  13542. this._pickedDownPrim = prim;
  13543. if (prim.actionManager.hasPickTriggers) {
  13544. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  13545. switch (eventData.button) {
  13546. case 0:
  13547. prim.actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger, actionEvent);
  13548. break;
  13549. case 1:
  13550. prim.actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger, actionEvent);
  13551. break;
  13552. case 2:
  13553. prim.actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger, actionEvent);
  13554. break;
  13555. }
  13556. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPickDownTrigger, actionEvent);
  13557. }
  13558. if (prim.actionManager.hasSpecificTrigger(BABYLON.ActionManager.OnLongPressTrigger)) {
  13559. window.setTimeout(function () {
  13560. var ppi = _this._primPointerInfo;
  13561. var capturedPrim = _this.getCapturedPrimitive(ppi.pointerId);
  13562. _this._updateIntersectionList(ppi.canvasPointerPos, capturedPrim !== null, true);
  13563. _this._updateOverStatus(false);
  13564. var ii = new BABYLON.IntersectInfo2D();
  13565. ii.pickPosition = ppi.canvasPointerPos.clone();
  13566. ii.findFirstOnly = false;
  13567. _this.intersect(ii);
  13568. if (ii.isPrimIntersected(prim) !== null) {
  13569. if (prim.actionManager) {
  13570. if (_this._pickStartingTime !== 0 && ((new Date().getTime() - _this._pickStartingTime) > BABYLON.ActionManager.LongPressDelay) && (Math.abs(_this._pickStartingPosition.x - ii.pickPosition.x) < BABYLON.ActionManager.DragMovementThreshold && Math.abs(_this._pickStartingPosition.y - ii.pickPosition.y) < BABYLON.ActionManager.DragMovementThreshold)) {
  13571. _this._pickStartingTime = 0;
  13572. prim.actionManager.processTrigger(BABYLON.ActionManager.OnLongPressTrigger, BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData));
  13573. }
  13574. }
  13575. }
  13576. }, BABYLON.ActionManager.LongPressDelay);
  13577. }
  13578. }
  13579. }
  13580. else if ((mask & BABYLON.PrimitivePointerInfo.PointerUp) !== 0) {
  13581. this._pickStartingTime = 0;
  13582. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  13583. if (prim.actionManager) {
  13584. // OnPickUpTrigger
  13585. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPickUpTrigger, actionEvent);
  13586. // OnPickTrigger
  13587. if (Math.abs(this._pickStartingPosition.x - ppi.canvasPointerPos.x) < BABYLON.ActionManager.DragMovementThreshold && Math.abs(this._pickStartingPosition.y - ppi.canvasPointerPos.y) < BABYLON.ActionManager.DragMovementThreshold) {
  13588. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger, actionEvent);
  13589. }
  13590. }
  13591. // OnPickOutTrigger
  13592. if (this._pickedDownPrim && this._pickedDownPrim.actionManager && (this._pickedDownPrim !== prim)) {
  13593. this._pickedDownPrim.actionManager.processTrigger(BABYLON.ActionManager.OnPickOutTrigger, actionEvent);
  13594. }
  13595. }
  13596. else if ((mask & BABYLON.PrimitivePointerInfo.PointerOver) !== 0) {
  13597. if (prim.actionManager) {
  13598. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  13599. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOverTrigger, actionEvent);
  13600. }
  13601. }
  13602. else if ((mask & BABYLON.PrimitivePointerInfo.PointerOut) !== 0) {
  13603. if (prim.actionManager) {
  13604. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  13605. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOutTrigger, actionEvent);
  13606. }
  13607. }
  13608. };
  13609. /**
  13610. * Don't forget to call the dispose method when you're done with the Canvas instance.
  13611. * But don't worry, if you dispose its scene, the canvas will be automatically disposed too.
  13612. */
  13613. Canvas2D.prototype.dispose = function () {
  13614. if (!_super.prototype.dispose.call(this)) {
  13615. return false;
  13616. }
  13617. if (this._profilingCanvas) {
  13618. this._profilingCanvas.dispose();
  13619. this._profilingCanvas = null;
  13620. }
  13621. if (this.interactionEnabled) {
  13622. this._setupInteraction(false);
  13623. }
  13624. if (this._renderingGroupObserver) {
  13625. this._scene.onRenderingGroupObservable.remove(this._renderingGroupObserver);
  13626. this._renderingGroupObserver = null;
  13627. }
  13628. if (this._beforeRenderObserver) {
  13629. this._scene.onBeforeRenderObservable.remove(this._beforeRenderObserver);
  13630. this._beforeRenderObserver = null;
  13631. }
  13632. if (this._afterRenderObserver) {
  13633. this._scene.onAfterRenderObservable.remove(this._afterRenderObserver);
  13634. this._afterRenderObserver = null;
  13635. }
  13636. if (this._groupCacheMaps) {
  13637. this._groupCacheMaps.forEach(function (k, m) { return m.forEach(function (e) { return e.dispose(); }); });
  13638. this._groupCacheMaps = null;
  13639. }
  13640. // Unregister this instance
  13641. var index = Canvas2D_1._INSTANCES.indexOf(this);
  13642. if (index > -1) {
  13643. Canvas2D_1._INSTANCES.splice(index, 1);
  13644. }
  13645. return true;
  13646. };
  13647. Object.defineProperty(Canvas2D.prototype, "scene", {
  13648. /**
  13649. * Accessor to the Scene that owns the Canvas
  13650. * @returns The instance of the Scene object
  13651. */
  13652. get: function () {
  13653. return this._scene;
  13654. },
  13655. enumerable: true,
  13656. configurable: true
  13657. });
  13658. Object.defineProperty(Canvas2D.prototype, "engine", {
  13659. /**
  13660. * Accessor to the Engine that drives the Scene used by this Canvas
  13661. * @returns The instance of the Engine object
  13662. */
  13663. get: function () {
  13664. return this._engine;
  13665. },
  13666. enumerable: true,
  13667. configurable: true
  13668. });
  13669. Object.defineProperty(Canvas2D.prototype, "uid", {
  13670. /**
  13671. * return a unique identifier for the Canvas2D
  13672. */
  13673. get: function () {
  13674. if (!this._uid) {
  13675. this._uid = BABYLON.Tools.RandomId();
  13676. }
  13677. return this._uid;
  13678. },
  13679. enumerable: true,
  13680. configurable: true
  13681. });
  13682. Object.defineProperty(Canvas2D.prototype, "renderObservable", {
  13683. /**
  13684. * And observable called during the Canvas rendering process.
  13685. * This observable is called twice per render, each time with a different mask:
  13686. * - 1: before render is executed
  13687. * - 2: after render is executed
  13688. */
  13689. get: function () {
  13690. if (!this._renderObservable) {
  13691. this._renderObservable = new BABYLON.Observable();
  13692. }
  13693. return this._renderObservable;
  13694. },
  13695. enumerable: true,
  13696. configurable: true
  13697. });
  13698. Object.defineProperty(Canvas2D.prototype, "cachingStrategy", {
  13699. /**
  13700. * Accessor of the Caching Strategy used by this Canvas.
  13701. * See Canvas2D.CACHESTRATEGY_xxxx static members for more information
  13702. * @returns the value corresponding to the used strategy.
  13703. */
  13704. get: function () {
  13705. return this._cachingStrategy;
  13706. },
  13707. enumerable: true,
  13708. configurable: true
  13709. });
  13710. Object.defineProperty(Canvas2D.prototype, "isScreenSpace", {
  13711. /**
  13712. * Return true if the Canvas is a Screen Space one, false if it's a World Space one.
  13713. * @returns {}
  13714. */
  13715. get: function () {
  13716. return this._isScreenSpace;
  13717. },
  13718. enumerable: true,
  13719. configurable: true
  13720. });
  13721. Object.defineProperty(Canvas2D.prototype, "worldSpaceCanvasNode", {
  13722. /**
  13723. * Only valid for World Space Canvas, returns the scene node that displays the canvas
  13724. */
  13725. get: function () {
  13726. return this._worldSpaceNode;
  13727. },
  13728. set: function (val) {
  13729. this._worldSpaceNode = val;
  13730. },
  13731. enumerable: true,
  13732. configurable: true
  13733. });
  13734. Object.defineProperty(Canvas2D.prototype, "supportInstancedArray", {
  13735. /**
  13736. * Check if the WebGL Instanced Array extension is supported or not
  13737. */
  13738. get: function () {
  13739. return this._supprtInstancedArray;
  13740. },
  13741. enumerable: true,
  13742. configurable: true
  13743. });
  13744. Object.defineProperty(Canvas2D.prototype, "backgroundFill", {
  13745. /**
  13746. * Property that defines the fill object used to draw the background of the Canvas.
  13747. * Note that Canvas with a Caching Strategy of
  13748. * @returns If the background is not set, null will be returned, otherwise a valid fill object is returned.
  13749. */
  13750. get: function () {
  13751. if (!this._background || !this._background.isVisible) {
  13752. return null;
  13753. }
  13754. return this._background.fill;
  13755. },
  13756. set: function (value) {
  13757. this.checkBackgroundAvailability();
  13758. if (value === this._background.fill) {
  13759. return;
  13760. }
  13761. this._background.fill = value;
  13762. this._background.levelVisible = true;
  13763. },
  13764. enumerable: true,
  13765. configurable: true
  13766. });
  13767. Object.defineProperty(Canvas2D.prototype, "backgroundBorder", {
  13768. /**
  13769. * Property that defines the border object used to draw the background of the Canvas.
  13770. * @returns If the background is not set, null will be returned, otherwise a valid border object is returned.
  13771. */
  13772. get: function () {
  13773. if (!this._background || !this._background.isVisible) {
  13774. return null;
  13775. }
  13776. return this._background.border;
  13777. },
  13778. set: function (value) {
  13779. this.checkBackgroundAvailability();
  13780. if (value === this._background.border) {
  13781. return;
  13782. }
  13783. this._background.border = value;
  13784. this._background.levelVisible = true;
  13785. },
  13786. enumerable: true,
  13787. configurable: true
  13788. });
  13789. Object.defineProperty(Canvas2D.prototype, "backgroundBorderThickness", {
  13790. /**
  13791. * Property that defines the thickness of the border object used to draw the background of the Canvas.
  13792. * @returns If the background is not set, null will be returned, otherwise a valid number matching the thickness is returned.
  13793. */
  13794. get: function () {
  13795. if (!this._background || !this._background.isVisible) {
  13796. return null;
  13797. }
  13798. return this._background.borderThickness;
  13799. },
  13800. set: function (value) {
  13801. this.checkBackgroundAvailability();
  13802. if (value === this._background.borderThickness) {
  13803. return;
  13804. }
  13805. this._background.borderThickness = value;
  13806. },
  13807. enumerable: true,
  13808. configurable: true
  13809. });
  13810. Object.defineProperty(Canvas2D.prototype, "backgroundRoundRadius", {
  13811. /**
  13812. * You can set the roundRadius of the background
  13813. * @returns The current roundRadius
  13814. */
  13815. get: function () {
  13816. if (!this._background || !this._background.isVisible) {
  13817. return null;
  13818. }
  13819. return this._background.roundRadius;
  13820. },
  13821. set: function (value) {
  13822. this.checkBackgroundAvailability();
  13823. if (value === this._background.roundRadius) {
  13824. return;
  13825. }
  13826. this._background.roundRadius = value;
  13827. this._background.levelVisible = true;
  13828. },
  13829. enumerable: true,
  13830. configurable: true
  13831. });
  13832. Object.defineProperty(Canvas2D.prototype, "interactionEnabled", {
  13833. /**
  13834. * Enable/Disable interaction for this Canvas
  13835. * When enabled the Prim2DBase.pointerEventObservable property will notified when appropriate events occur
  13836. */
  13837. get: function () {
  13838. return this._interactionEnabled;
  13839. },
  13840. set: function (enable) {
  13841. this._setupInteraction(enable);
  13842. },
  13843. enumerable: true,
  13844. configurable: true
  13845. });
  13846. Object.defineProperty(Canvas2D.prototype, "fitRenderingDevice", {
  13847. get: function () {
  13848. return this._fitRenderingDevice;
  13849. },
  13850. enumerable: true,
  13851. configurable: true
  13852. });
  13853. Object.defineProperty(Canvas2D.prototype, "designSize", {
  13854. get: function () {
  13855. return this._designSize;
  13856. },
  13857. enumerable: true,
  13858. configurable: true
  13859. });
  13860. Object.defineProperty(Canvas2D.prototype, "designSizeUseHorizAxis", {
  13861. get: function () {
  13862. return this._designUseHorizAxis;
  13863. },
  13864. enumerable: true,
  13865. configurable: true
  13866. });
  13867. Object.defineProperty(Canvas2D.prototype, "overPrim", {
  13868. /**
  13869. * Return
  13870. */
  13871. get: function () {
  13872. if (this._actualIntersectionList && this._actualIntersectionList.length > 0) {
  13873. return this._actualIntersectionList[0].prim;
  13874. }
  13875. return null;
  13876. },
  13877. enumerable: true,
  13878. configurable: true
  13879. });
  13880. Object.defineProperty(Canvas2D.prototype, "_engineData", {
  13881. /**
  13882. * Access the babylon.js' engine bound data, do not invoke this method, it's for internal purpose only
  13883. * @returns {}
  13884. */
  13885. get: function () {
  13886. return this.__engineData;
  13887. },
  13888. enumerable: true,
  13889. configurable: true
  13890. });
  13891. Canvas2D.prototype.createCanvasProfileInfoCanvas = function () {
  13892. if (this._profilingCanvas) {
  13893. return this._profilingCanvas;
  13894. }
  13895. var canvas = new ScreenSpaceCanvas2D(this.scene, {
  13896. id: "ProfileInfoCanvas", cachingStrategy: Canvas2D_1.CACHESTRATEGY_DONTCACHE, children: [
  13897. new BABYLON.Rectangle2D({
  13898. id: "ProfileBorder", border: "#FFFFFFFF", borderThickness: 2, roundRadius: 5, fill: "#C04040C0", marginAlignment: "h: left, v: top", margin: "10", padding: "10", children: [
  13899. new BABYLON.Text2D("Stats", { id: "ProfileInfoText", marginAlignment: "h: left, v: top", fontName: "12pt Lucida Console", fontSignedDistanceField: true })
  13900. ]
  13901. })
  13902. ]
  13903. });
  13904. this._profileInfoText = canvas.findById("ProfileInfoText");
  13905. this._profilingCanvas = canvas;
  13906. return canvas;
  13907. };
  13908. Canvas2D.prototype.checkBackgroundAvailability = function () {
  13909. if (this._cachingStrategy === Canvas2D_1.CACHESTRATEGY_TOPLEVELGROUPS) {
  13910. throw Error("Can't use Canvas Background with the caching strategy TOPLEVELGROUPS");
  13911. }
  13912. };
  13913. Canvas2D.prototype._initPerfMetrics = function () {
  13914. this._drawCallsOpaqueCounter.fetchNewFrame();
  13915. this._drawCallsAlphaTestCounter.fetchNewFrame();
  13916. this._drawCallsTransparentCounter.fetchNewFrame();
  13917. this._groupRenderCounter.fetchNewFrame();
  13918. this._updateTransparentDataCounter.fetchNewFrame();
  13919. this._cachedGroupRenderCounter.fetchNewFrame();
  13920. this._updateCachedStateCounter.fetchNewFrame();
  13921. this._updateLayoutCounter.fetchNewFrame();
  13922. this._updatePositioningCounter.fetchNewFrame();
  13923. this._updateLocalTransformCounter.fetchNewFrame();
  13924. this._updateGlobalTransformCounter.fetchNewFrame();
  13925. this._boundingInfoRecomputeCounter.fetchNewFrame();
  13926. };
  13927. Canvas2D.prototype._fetchPerfMetrics = function () {
  13928. this._drawCallsOpaqueCounter.addCount(0, true);
  13929. this._drawCallsAlphaTestCounter.addCount(0, true);
  13930. this._drawCallsTransparentCounter.addCount(0, true);
  13931. this._groupRenderCounter.addCount(0, true);
  13932. this._updateTransparentDataCounter.addCount(0, true);
  13933. this._cachedGroupRenderCounter.addCount(0, true);
  13934. this._updateCachedStateCounter.addCount(0, true);
  13935. this._updateLayoutCounter.addCount(0, true);
  13936. this._updatePositioningCounter.addCount(0, true);
  13937. this._updateLocalTransformCounter.addCount(0, true);
  13938. this._updateGlobalTransformCounter.addCount(0, true);
  13939. this._boundingInfoRecomputeCounter.addCount(0, true);
  13940. };
  13941. Canvas2D.prototype._updateProfileCanvas = function () {
  13942. if (this._profileInfoText == null) {
  13943. return;
  13944. }
  13945. var format = function (v) { return (Math.round(v * 100) / 100).toString(); };
  13946. var p = "Draw Calls:\n" +
  13947. (" - Opaque: " + format(this.drawCallsOpaqueCounter.current) + ", (avg:" + format(this.drawCallsOpaqueCounter.lastSecAverage) + ", t:" + format(this.drawCallsOpaqueCounter.total) + ")\n") +
  13948. (" - AlphaTest: " + format(this.drawCallsAlphaTestCounter.current) + ", (avg:" + format(this.drawCallsAlphaTestCounter.lastSecAverage) + ", t:" + format(this.drawCallsAlphaTestCounter.total) + ")\n") +
  13949. (" - Transparent: " + format(this.drawCallsTransparentCounter.current) + ", (avg:" + format(this.drawCallsTransparentCounter.lastSecAverage) + ", t:" + format(this.drawCallsTransparentCounter.total) + ")\n") +
  13950. ("Group Render: " + this.groupRenderCounter.current + ", (avg:" + format(this.groupRenderCounter.lastSecAverage) + ", t:" + format(this.groupRenderCounter.total) + ")\n") +
  13951. ("Update Transparent Data: " + this.updateTransparentDataCounter.current + ", (avg:" + format(this.updateTransparentDataCounter.lastSecAverage) + ", t:" + format(this.updateTransparentDataCounter.total) + ")\n") +
  13952. ("Cached Group Render: " + this.cachedGroupRenderCounter.current + ", (avg:" + format(this.cachedGroupRenderCounter.lastSecAverage) + ", t:" + format(this.cachedGroupRenderCounter.total) + ")\n") +
  13953. ("Update Cached States: " + this.updateCachedStateCounter.current + ", (avg:" + format(this.updateCachedStateCounter.lastSecAverage) + ", t:" + format(this.updateCachedStateCounter.total) + ")\n") +
  13954. (" - Update Layout: " + this.updateLayoutCounter.current + ", (avg:" + format(this.updateLayoutCounter.lastSecAverage) + ", t:" + format(this.updateLayoutCounter.total) + ")\n") +
  13955. (" - Update Positioning: " + this.updatePositioningCounter.current + ", (avg:" + format(this.updatePositioningCounter.lastSecAverage) + ", t:" + format(this.updatePositioningCounter.total) + ")\n") +
  13956. (" - Update Local Trans: " + this.updateLocalTransformCounter.current + ", (avg:" + format(this.updateLocalTransformCounter.lastSecAverage) + ", t:" + format(this.updateLocalTransformCounter.total) + ")\n") +
  13957. (" - Update Global Trans: " + this.updateGlobalTransformCounter.current + ", (avg:" + format(this.updateGlobalTransformCounter.lastSecAverage) + ", t:" + format(this.updateGlobalTransformCounter.total) + ")\n") +
  13958. (" - BoundingInfo Recompute: " + this.boundingInfoRecomputeCounter.current + ", (avg:" + format(this.boundingInfoRecomputeCounter.lastSecAverage) + ", t:" + format(this.boundingInfoRecomputeCounter.total) + ")");
  13959. this._profileInfoText.text = p;
  13960. };
  13961. Canvas2D.prototype._addDrawCallCount = function (count, renderMode) {
  13962. switch (renderMode) {
  13963. case BABYLON.Render2DContext.RenderModeOpaque:
  13964. this._drawCallsOpaqueCounter.addCount(count, false);
  13965. return;
  13966. case BABYLON.Render2DContext.RenderModeAlphaTest:
  13967. this._drawCallsAlphaTestCounter.addCount(count, false);
  13968. return;
  13969. case BABYLON.Render2DContext.RenderModeTransparent:
  13970. this._drawCallsTransparentCounter.addCount(count, false);
  13971. return;
  13972. }
  13973. };
  13974. Canvas2D.prototype._addGroupRenderCount = function (count) {
  13975. this._groupRenderCounter.addCount(count, false);
  13976. };
  13977. Canvas2D.prototype._addUpdateTransparentDataCount = function (count) {
  13978. this._updateTransparentDataCounter.addCount(count, false);
  13979. };
  13980. Canvas2D.prototype.addCachedGroupRenderCounter = function (count) {
  13981. this._cachedGroupRenderCounter.addCount(count, false);
  13982. };
  13983. Canvas2D.prototype.addUpdateCachedStateCounter = function (count) {
  13984. this._updateCachedStateCounter.addCount(count, false);
  13985. };
  13986. Canvas2D.prototype.addUpdateLayoutCounter = function (count) {
  13987. this._updateLayoutCounter.addCount(count, false);
  13988. };
  13989. Canvas2D.prototype.addUpdatePositioningCounter = function (count) {
  13990. this._updatePositioningCounter.addCount(count, false);
  13991. };
  13992. Canvas2D.prototype.addupdateLocalTransformCounter = function (count) {
  13993. this._updateLocalTransformCounter.addCount(count, false);
  13994. };
  13995. Canvas2D.prototype.addUpdateGlobalTransformCounter = function (count) {
  13996. this._updateGlobalTransformCounter.addCount(count, false);
  13997. };
  13998. Canvas2D.prototype._updateTrackedNodes = function () {
  13999. // Get the used camera
  14000. var cam = this.scene.cameraToUseForPointers || this.scene.activeCamera;
  14001. // Compute some matrix stuff
  14002. cam.getViewMatrix().multiplyToRef(cam.getProjectionMatrix(), Canvas2D_1._m);
  14003. var rh = this.engine.getRenderHeight();
  14004. var v = cam.viewport.toGlobal(this.engine.getRenderWidth(), rh);
  14005. // Compute the screen position of each group that track a given scene node
  14006. for (var _i = 0, _a = this._trackedGroups; _i < _a.length; _i++) {
  14007. var group = _a[_i];
  14008. if (group.isDisposed) {
  14009. continue;
  14010. }
  14011. var node = group.trackedNode;
  14012. var worldMtx = node.getWorldMatrix();
  14013. var proj = BABYLON.Vector3.Project(Canvas2D_1._v, worldMtx, Canvas2D_1._m, v);
  14014. // Set the visibility state accordingly, if the position is outside the frustum (well on the Z planes only...) set the group to hidden
  14015. group.levelVisible = proj.z >= 0 && proj.z < 1.0;
  14016. var s = this.scale;
  14017. group.x = Math.round(proj.x / s);
  14018. group.y = Math.round((rh - proj.y) / s);
  14019. }
  14020. // If it's a WorldSpaceCanvas and it's tracking a node, let's update the WSC transformation data
  14021. if (this._trackNode) {
  14022. var rot = null;
  14023. var scale = null;
  14024. var worldmtx = this._trackNode.getWorldMatrix();
  14025. var pos = worldmtx.getTranslation().add(this._trackNodeOffset);
  14026. var wsc = this;
  14027. var wsn = wsc.worldSpaceCanvasNode;
  14028. if (this._trackNodeBillboard) {
  14029. var viewMtx = cam.getViewMatrix().clone().invert();
  14030. viewMtx.decompose(Canvas2D_1.tS, Canvas2D_1.tR, Canvas2D_1.tT);
  14031. rot = Canvas2D_1.tR.clone();
  14032. }
  14033. worldmtx.decompose(Canvas2D_1.tS, Canvas2D_1.tR, Canvas2D_1.tT);
  14034. var mtx = BABYLON.Matrix.Compose(Canvas2D_1.tS, Canvas2D_1.tR, BABYLON.Vector3.Zero());
  14035. pos = worldmtx.getTranslation().add(BABYLON.Vector3.TransformCoordinates(this._trackNodeOffset, mtx));
  14036. if (Canvas2D_1.tS.lengthSquared() !== 1) {
  14037. scale = Canvas2D_1.tS.clone();
  14038. }
  14039. if (!this._trackNodeBillboard) {
  14040. rot = Canvas2D_1.tR.clone();
  14041. }
  14042. if (wsn instanceof BABYLON.AbstractMesh) {
  14043. wsn.position = pos;
  14044. wsn.rotationQuaternion = rot;
  14045. if (scale) {
  14046. wsn.scaling = scale;
  14047. }
  14048. }
  14049. }
  14050. };
  14051. /**
  14052. * Call this method change you want to have layout related data computed and up to date (layout area, primitive area, local/global transformation matrices)
  14053. */
  14054. Canvas2D.prototype.updateCanvasLayout = function (forceRecompute) {
  14055. this._updateCanvasState(forceRecompute);
  14056. };
  14057. Canvas2D.prototype._updateAdaptiveSizeWorldCanvas = function () {
  14058. if (this._globalTransformStep < 2) {
  14059. return;
  14060. }
  14061. var n = this.worldSpaceCanvasNode;
  14062. var bi = n.getBoundingInfo().boundingBox;
  14063. var v = bi.vectorsWorld;
  14064. var cam = this.scene.cameraToUseForPointers || this.scene.activeCamera;
  14065. cam.getViewMatrix().multiplyToRef(cam.getProjectionMatrix(), Canvas2D_1._m);
  14066. var vp = cam.viewport.toGlobal(this.engine.getRenderWidth(), this.engine.getRenderHeight());
  14067. var projPoints = new Array(4);
  14068. for (var i = 0; i < 4; i++) {
  14069. projPoints[i] = BABYLON.Vector3.Project(v[i], Canvas2D_1._mI, Canvas2D_1._m, vp);
  14070. }
  14071. var left = projPoints[3].subtract(projPoints[0]).length();
  14072. var top = projPoints[3].subtract(projPoints[1]).length();
  14073. var right = projPoints[1].subtract(projPoints[2]).length();
  14074. var bottom = projPoints[2].subtract(projPoints[0]).length();
  14075. var w = Math.round(Math.max(top, bottom));
  14076. var h = Math.round(Math.max(right, left));
  14077. var isW = w > h;
  14078. // Basically if it's under 256 we use 256, otherwise we take the biggest power of 2
  14079. var edge = Math.max(w, h);
  14080. if (edge < 256) {
  14081. edge = 256;
  14082. }
  14083. else {
  14084. edge = Math.pow(2, Math.ceil(Math.log(edge) / Math.log(2)));
  14085. }
  14086. // Clip values if needed
  14087. edge = Math.min(edge, this._maxAdaptiveWorldSpaceCanvasSize);
  14088. var newScale = edge / ((isW) ? this.size.width : this.size.height);
  14089. if (newScale !== this.scale) {
  14090. var scale = newScale;
  14091. // console.log(`New adaptive scale for Canvas ${this.id}, w: ${w}, h: ${h}, scale: ${scale}, edge: ${edge}, isW: ${isW}`);
  14092. this._setRenderingScale(scale);
  14093. }
  14094. };
  14095. Canvas2D.prototype._updateCanvasState = function (forceRecompute) {
  14096. // Check if the update has already been made for this render Frame
  14097. if (!forceRecompute && this.scene.getRenderId() === this._updateRenderId) {
  14098. return;
  14099. }
  14100. // Detect a change of rendering size
  14101. var renderingSizeChanged = false;
  14102. var newWidth = this.engine.getRenderWidth();
  14103. if (newWidth !== this._renderingSize.width) {
  14104. renderingSizeChanged = true;
  14105. }
  14106. this._renderingSize.width = newWidth;
  14107. var newHeight = this.engine.getRenderHeight();
  14108. if (newHeight !== this._renderingSize.height) {
  14109. renderingSizeChanged = true;
  14110. }
  14111. this._renderingSize.height = newHeight;
  14112. // If the canvas fit the rendering size and it changed, update
  14113. if (renderingSizeChanged && this._fitRenderingDevice) {
  14114. this._actualSize = this._renderingSize.clone();
  14115. this._size = this._renderingSize.clone();
  14116. if (this._background) {
  14117. this._background.size = this.size;
  14118. }
  14119. // Dirty the Layout at the Canvas level to recompute as the size changed
  14120. this._setLayoutDirty();
  14121. }
  14122. // If there's a design size, update the scale according to the renderingSize
  14123. if (this._designSize) {
  14124. var scale = void 0;
  14125. if (this._designUseHorizAxis) {
  14126. scale = this._renderingSize.width / this._designSize.width;
  14127. }
  14128. else {
  14129. scale = this._renderingSize.height / this._designSize.height;
  14130. }
  14131. this.size = this._designSize.clone();
  14132. this.actualSize = this._designSize.clone();
  14133. this.scale = scale;
  14134. }
  14135. var context = new BABYLON.PrepareRender2DContext();
  14136. ++this._globalTransformProcessStep;
  14137. this.updateCachedStates(false);
  14138. this._prepareGroupRender(context);
  14139. this._updateRenderId = this.scene.getRenderId();
  14140. };
  14141. /**
  14142. * Method that renders the Canvas, you should not invoke
  14143. */
  14144. Canvas2D.prototype._render = function () {
  14145. this._initPerfMetrics();
  14146. if (this._renderObservable && this._renderObservable.hasObservers()) {
  14147. this._renderObservable.notifyObservers(this, Canvas2D_1.RENDEROBSERVABLE_PRE);
  14148. }
  14149. this._updateCanvasState(false);
  14150. this._updateTrackedNodes();
  14151. // Nothing to do is the Canvas is not visible
  14152. if (this.isVisible === false) {
  14153. return;
  14154. }
  14155. if (!this._isScreenSpace) {
  14156. this._updateAdaptiveSizeWorldCanvas();
  14157. }
  14158. this._updateCanvasState(false);
  14159. if (this._primPointerInfo.canvasPointerPos) {
  14160. this._updateIntersectionList(this._primPointerInfo.canvasPointerPos, false, false);
  14161. this._updateOverStatus(false);
  14162. }
  14163. this.engine.setState(false);
  14164. this._groupRender();
  14165. if (!this._isScreenSpace) {
  14166. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagWorldCacheChanged)) {
  14167. this.worldSpaceCacheChanged();
  14168. this._clearFlags(BABYLON.SmartPropertyPrim.flagWorldCacheChanged);
  14169. }
  14170. }
  14171. // If the canvas is cached at canvas level, we must manually render the sprite that will display its content
  14172. if (this._cachingStrategy === Canvas2D_1.CACHESTRATEGY_CANVAS && this._cachedCanvasGroup) {
  14173. this._cachedCanvasGroup._renderCachedCanvas();
  14174. }
  14175. this._fetchPerfMetrics();
  14176. this._updateProfileCanvas();
  14177. if (this._renderObservable && this._renderObservable.hasObservers()) {
  14178. this._renderObservable.notifyObservers(this, Canvas2D_1.RENDEROBSERVABLE_POST);
  14179. }
  14180. };
  14181. /**
  14182. * Internal method that allocate a cache for the given group.
  14183. * Caching is made using a collection of MapTexture where many groups have their bitmap cache stored inside.
  14184. * @param group The group to allocate the cache of.
  14185. * @return custom type with the PackedRect instance giving information about the cache location into the texture and also the MapTexture instance that stores the cache.
  14186. */
  14187. Canvas2D.prototype._allocateGroupCache = function (group, parent, minSize, useMipMap, anisotropicLevel) {
  14188. if (useMipMap === void 0) { useMipMap = false; }
  14189. if (anisotropicLevel === void 0) { anisotropicLevel = 1; }
  14190. var key = (useMipMap ? "MipMap" : "NoMipMap") + "_" + anisotropicLevel;
  14191. var rd = group._renderableData;
  14192. var noResizeScale = rd._noResizeOnScale;
  14193. var isCanvas = parent == null;
  14194. var scale;
  14195. if (noResizeScale) {
  14196. scale = isCanvas ? Canvas2D_1._unS : group.parent.actualScale;
  14197. }
  14198. else {
  14199. scale = group.actualScale;
  14200. }
  14201. // Determine size
  14202. var size = group.actualSize;
  14203. size = new BABYLON.Size(Math.ceil(size.width * scale.x), Math.ceil(size.height * scale.y));
  14204. var originalSize = size.clone();
  14205. if (minSize) {
  14206. size.width = Math.max(minSize.width, size.width);
  14207. size.height = Math.max(minSize.height, size.height);
  14208. }
  14209. var mapArray = this._groupCacheMaps.getOrAddWithFactory(key, function () { return new Array(); });
  14210. // Try to find a spot in one of the cached texture
  14211. var res = null;
  14212. var map;
  14213. for (var _i = 0, mapArray_1 = mapArray; _i < mapArray_1.length; _i++) {
  14214. var _map = mapArray_1[_i];
  14215. map = _map;
  14216. var node = map.allocateRect(size);
  14217. if (node) {
  14218. res = { node: node, texture: map };
  14219. break;
  14220. }
  14221. }
  14222. // Couldn't find a map that could fit the rect, create a new map for it
  14223. if (!res) {
  14224. var mapSize = new BABYLON.Size(Canvas2D_1._groupTextureCacheSize, Canvas2D_1._groupTextureCacheSize);
  14225. // Check if the predefined size would fit, other create a custom size using the nearest bigger power of 2
  14226. if (size.width > mapSize.width || size.height > mapSize.height) {
  14227. mapSize.width = Math.pow(2, Math.ceil(Math.log(size.width) / Math.log(2)));
  14228. mapSize.height = Math.pow(2, Math.ceil(Math.log(size.height) / Math.log(2)));
  14229. }
  14230. var id = "groupsMapChache" + this._mapCounter++ + "forCanvas" + this.id;
  14231. map = new BABYLON.MapTexture(id, this._scene, mapSize, useMipMap ? BABYLON.Texture.TRILINEAR_SAMPLINGMODE : BABYLON.Texture.BILINEAR_SAMPLINGMODE, useMipMap);
  14232. map.hasAlpha = true;
  14233. map.anisotropicFilteringLevel = 4;
  14234. mapArray.splice(0, 0, map);
  14235. var node = map.allocateRect(size);
  14236. res = { node: node, texture: map };
  14237. }
  14238. // Check if we have to create a Sprite that will display the content of the Canvas which is cached.
  14239. // Don't do it in case of the group being a worldspace canvas (because its texture is bound to a WorldSpaceCanvas node)
  14240. if (group !== this || this._isScreenSpace) {
  14241. var node = res.node;
  14242. // Special case if the canvas is entirely cached: create a group that will have a single sprite it will be rendered specifically at the very end of the rendering process
  14243. var sprite = void 0;
  14244. if (this._cachingStrategy === Canvas2D_1.CACHESTRATEGY_CANVAS) {
  14245. if (this._cachedCanvasGroup) {
  14246. this._cachedCanvasGroup.dispose();
  14247. }
  14248. this._cachedCanvasGroup = BABYLON.Group2D._createCachedCanvasGroup(this);
  14249. sprite = new BABYLON.Sprite2D(map, { parent: this._cachedCanvasGroup, id: "__cachedCanvasSprite__", spriteSize: originalSize, spriteLocation: node.pos });
  14250. sprite.zOrder = 1;
  14251. sprite.origin = BABYLON.Vector2.Zero();
  14252. }
  14253. else {
  14254. sprite = new BABYLON.Sprite2D(map, { parent: parent, id: "__cachedSpriteOfGroup__" + group.id, x: group.actualPosition.x, y: group.actualPosition.y, spriteSize: originalSize, spriteLocation: node.pos, dontInheritParentScale: true });
  14255. sprite.origin = group.origin.clone();
  14256. sprite.addExternalData("__cachedGroup__", group);
  14257. sprite.pointerEventObservable.add(function (e, s) {
  14258. if (group.pointerEventObservable !== null) {
  14259. group.pointerEventObservable.notifyObservers(e, s.mask);
  14260. }
  14261. });
  14262. res.sprite = sprite;
  14263. }
  14264. if (sprite && noResizeScale) {
  14265. var relScale = isCanvas ? group.actualScale : group.actualScale.divide(group.parent.actualScale);
  14266. sprite.scaleX = relScale.x;
  14267. sprite.scaleY = relScale.y;
  14268. }
  14269. }
  14270. return res;
  14271. };
  14272. /**
  14273. * Internal method used to register a Scene Node to track position for the given group
  14274. * Do not invoke this method, for internal purpose only.
  14275. * @param group the group to track its associated Scene Node
  14276. */
  14277. Canvas2D.prototype._registerTrackedNode = function (group) {
  14278. if (group._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  14279. return;
  14280. }
  14281. if (!this._trackedGroups) {
  14282. this._trackedGroups = new Array();
  14283. }
  14284. this._trackedGroups.push(group);
  14285. group._setFlags(BABYLON.SmartPropertyPrim.flagTrackedGroup);
  14286. };
  14287. /**
  14288. * Internal method used to unregister a tracked Scene Node
  14289. * Do not invoke this method, it's for internal purpose only.
  14290. * @param group the group to unregister its tracked Scene Node from.
  14291. */
  14292. Canvas2D.prototype._unregisterTrackedNode = function (group) {
  14293. if (!group._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  14294. return;
  14295. }
  14296. var i = this._trackedGroups.indexOf(group);
  14297. if (i !== -1) {
  14298. this._trackedGroups.splice(i, 1);
  14299. }
  14300. group._clearFlags(BABYLON.SmartPropertyPrim.flagTrackedGroup);
  14301. };
  14302. /**
  14303. * Get a Solid Color Brush instance matching the given color.
  14304. * @param color The color to retrieve
  14305. * @return A shared instance of the SolidColorBrush2D class that use the given color
  14306. */
  14307. Canvas2D.GetSolidColorBrush = function (color) {
  14308. return Canvas2D_1._solidColorBrushes.getOrAddWithFactory(color.toHexString(), function () { return new BABYLON.SolidColorBrush2D(color.clone(), true); });
  14309. };
  14310. /**
  14311. * Get a Solid Color Brush instance matching the given color expressed as a CSS formatted hexadecimal value.
  14312. * @param color The color to retrieve
  14313. * @return A shared instance of the SolidColorBrush2D class that uses the given color
  14314. */
  14315. Canvas2D.GetSolidColorBrushFromHex = function (hexValue) {
  14316. return Canvas2D_1._solidColorBrushes.getOrAddWithFactory(hexValue, function () { return new BABYLON.SolidColorBrush2D(BABYLON.Color4.FromHexString(hexValue), true); });
  14317. };
  14318. /**
  14319. * Get a Gradient Color Brush
  14320. * @param color1 starting color
  14321. * @param color2 engine color
  14322. * @param translation translation vector to apply. default is [0;0]
  14323. * @param rotation rotation in radian to apply to the brush, initial direction is top to bottom. rotation is counter clockwise. default is 0.
  14324. * @param scale scaling factor to apply. default is 1.
  14325. */
  14326. Canvas2D.GetGradientColorBrush = function (color1, color2, translation, rotation, scale) {
  14327. if (translation === void 0) { translation = BABYLON.Vector2.Zero(); }
  14328. if (rotation === void 0) { rotation = 0; }
  14329. if (scale === void 0) { scale = 1; }
  14330. return Canvas2D_1._gradientColorBrushes.getOrAddWithFactory(BABYLON.GradientColorBrush2D.BuildKey(color1, color2, translation, rotation, scale), function () { return new BABYLON.GradientColorBrush2D(color1, color2, translation, rotation, scale, true); });
  14331. };
  14332. /**
  14333. * Create a solid or gradient brush from a string value.
  14334. * @param brushString should be either
  14335. * - "solid: #RRGGBBAA" or "#RRGGBBAA"
  14336. * - "gradient: #FF808080, #FFFFFFF[, [10:20], 180, 1]" for color1, color2, translation, rotation (degree), scale. The last three are optionals, but if specified must be is this order. "gradient:" can be omitted.
  14337. */
  14338. Canvas2D.GetBrushFromString = function (brushString) {
  14339. // Note: yes, I hate/don't know RegEx.. Feel free to add your contribution to the cause!
  14340. brushString = brushString.trim();
  14341. var split = brushString.split(",");
  14342. // Solid, formatted as: "[solid:]#FF808080"
  14343. if (split.length === 1) {
  14344. var value = null;
  14345. if (brushString.indexOf("solid:") === 0) {
  14346. value = brushString.substr(6).trim();
  14347. }
  14348. else if (brushString.indexOf("#") === 0) {
  14349. value = brushString;
  14350. }
  14351. else {
  14352. return null;
  14353. }
  14354. return Canvas2D_1.GetSolidColorBrushFromHex(value);
  14355. }
  14356. else {
  14357. if (split[0].indexOf("gradient:") === 0) {
  14358. split[0] = split[0].substr(9).trim();
  14359. }
  14360. try {
  14361. var start = BABYLON.Color4.FromHexString(split[0].trim());
  14362. var end = BABYLON.Color4.FromHexString(split[1].trim());
  14363. var t = BABYLON.Vector2.Zero();
  14364. if (split.length > 2) {
  14365. var v = split[2].trim();
  14366. if (v.charAt(0) !== "[" || v.charAt(v.length - 1) !== "]") {
  14367. return null;
  14368. }
  14369. var sep = v.indexOf(":");
  14370. var x = parseFloat(v.substr(1, sep));
  14371. var y = parseFloat(v.substr(sep + 1, v.length - (sep + 1)));
  14372. t = new BABYLON.Vector2(x, y);
  14373. }
  14374. var r = 0;
  14375. if (split.length > 3) {
  14376. r = BABYLON.Tools.ToRadians(parseFloat(split[3].trim()));
  14377. }
  14378. var s = 1;
  14379. if (split.length > 4) {
  14380. s = parseFloat(split[4].trim());
  14381. }
  14382. return Canvas2D_1.GetGradientColorBrush(start, end, t, r, s);
  14383. }
  14384. catch (e) {
  14385. return null;
  14386. }
  14387. }
  14388. };
  14389. return Canvas2D;
  14390. }(BABYLON.Group2D));
  14391. /**
  14392. * In this strategy only the direct children groups of the Canvas will be cached, their whole content (whatever the sub groups they have) into a single bitmap.
  14393. * This strategy doesn't allow primitives added directly as children of the Canvas.
  14394. * You typically want to use this strategy of a screenSpace fullscreen canvas: you don't want a bitmap cache taking the whole screen resolution but still want the main contents (say UI in the topLeft and rightBottom for instance) to be efficiently cached.
  14395. */
  14396. Canvas2D.CACHESTRATEGY_TOPLEVELGROUPS = 1;
  14397. /**
  14398. * In this strategy each group will have its own cache bitmap (except if a given group explicitly defines the DONTCACHEOVERRIDE or CACHEINPARENTGROUP behaviors).
  14399. * This strategy is typically used if the canvas has some groups that are frequently animated. Unchanged ones will have a steady cache and the others will be refreshed when they change, reducing the redraw operation count to their content only.
  14400. * When using this strategy, group instances can rely on the DONTCACHEOVERRIDE or CACHEINPARENTGROUP behaviors to minimize the amount of cached bitmaps.
  14401. * Note that in this mode the Canvas itself is not cached, it only contains the sprites of its direct children group to render, there's no point to cache the whole canvas, sprites will be rendered pretty efficiently, the memory cost would be too great for the value of it.
  14402. */
  14403. Canvas2D.CACHESTRATEGY_ALLGROUPS = 2;
  14404. /**
  14405. * In this strategy the whole canvas is cached into a single bitmap containing every primitives it owns, at the exception of the ones that are owned by a group having the DONTCACHEOVERRIDE behavior (these primitives will be directly drawn to the viewport at each render for screenSpace Canvas or be part of the Canvas cache bitmap for worldSpace Canvas).
  14406. */
  14407. Canvas2D.CACHESTRATEGY_CANVAS = 3;
  14408. /**
  14409. * This strategy is used to recompose/redraw the canvas entirely at each viewport render.
  14410. * Use this strategy if memory is a concern above rendering performances and/or if the canvas is frequently animated (hence reducing the benefits of caching).
  14411. * Note that you can't use this strategy for WorldSpace Canvas, they need at least a top level group caching.
  14412. */
  14413. Canvas2D.CACHESTRATEGY_DONTCACHE = 4;
  14414. /**
  14415. * Observable Mask to be notified before rendering is made
  14416. */
  14417. Canvas2D.RENDEROBSERVABLE_PRE = 1;
  14418. /**
  14419. * Observable Mask to be notified after rendering is made
  14420. */
  14421. Canvas2D.RENDEROBSERVABLE_POST = 2;
  14422. Canvas2D._INSTANCES = [];
  14423. Canvas2D._zMinDelta = 1 / (Math.pow(2, 24) - 1);
  14424. Canvas2D._interInfo = new BABYLON.IntersectInfo2D();
  14425. Canvas2D._v = BABYLON.Vector3.Zero(); // Must stay zero
  14426. Canvas2D._m = BABYLON.Matrix.Identity();
  14427. Canvas2D._mI = BABYLON.Matrix.Identity(); // Must stay identity
  14428. Canvas2D.tS = BABYLON.Vector3.Zero();
  14429. Canvas2D.tT = BABYLON.Vector3.Zero();
  14430. Canvas2D.tR = BABYLON.Quaternion.Identity();
  14431. /**
  14432. * Define the default size used for both the width and height of a MapTexture to allocate.
  14433. * Note that some MapTexture might be bigger than this size if the first node to allocate is bigger in width or height
  14434. */
  14435. Canvas2D._groupTextureCacheSize = 1024;
  14436. Canvas2D._solidColorBrushes = new BABYLON.StringDictionary();
  14437. Canvas2D._gradientColorBrushes = new BABYLON.StringDictionary();
  14438. Canvas2D = Canvas2D_1 = __decorate([
  14439. BABYLON.className("Canvas2D", "BABYLON")
  14440. ], Canvas2D);
  14441. BABYLON.Canvas2D = Canvas2D;
  14442. var WorldSpaceCanvas2D = (function (_super) {
  14443. __extends(WorldSpaceCanvas2D, _super);
  14444. /**
  14445. * Create a new 2D WorldSpace Rendering Canvas, it is a 2D rectangle that has a size (width/height) and a world transformation information to place it in the world space.
  14446. * This kind of canvas can't have its Primitives directly drawn in the Viewport, they need to be cached in a bitmap at some point, as a consequence the DONT_CACHE strategy is unavailable. For now only CACHESTRATEGY_CANVAS is supported, but the remaining strategies will be soon.
  14447. * @param scene the Scene that owns the Canvas
  14448. * @param size the dimension of the Canvas in World Space
  14449. * @param settings a combination of settings, possible ones are
  14450. * - children: an array of direct children primitives
  14451. * - id: a text identifier, for information purpose only, default is null.
  14452. * - unitScaleFactor: if specified the created canvas will be with a width of size.width*unitScaleFactor and a height of size.height.unitScaleFactor. If not specified, the unit of 1 is used. You can use this setting when you're dealing with a 3D world with small coordinates and you need a Canvas having bigger coordinates (typically to display text with better quality).
  14453. * - worldPosition the position of the Canvas in World Space, default is [0,0,0]
  14454. * - worldRotation the rotation of the Canvas in World Space, default is Quaternion.Identity()
  14455. * - trackNode: if you want the WorldSpaceCanvas to track the position/rotation/scale of a given Scene Node, use this setting to specify the Node to track
  14456. * - trackNodeOffset: if you use trackNode you may want to specify a 3D Offset to apply to shift the Canvas
  14457. * - trackNodeBillboard: if true the WorldSpaceCanvas will always face the screen
  14458. * - sideOrientation: Unexpected behavior occur if the value is different from Mesh.DEFAULTSIDE right now, so please use this one, which is the default.
  14459. * - cachingStrategy Must be CACHESTRATEGY_CANVAS for now, which is the default.
  14460. * - enableInteraction: if true the pointer events will be listened and rerouted to the appropriate primitives of the Canvas2D through the Prim2DBase.onPointerEventObservable observable property. Default is false (the opposite of ScreenSpace).
  14461. * - isVisible: true if the canvas must be visible, false for hidden. Default is true.
  14462. * - backgroundRoundRadius: the round radius of the background, either backgroundFill or backgroundBorder must be specified.
  14463. * - backgroundFill: the brush to use to create a background fill for the canvas. can be a string value (see Canvas2D.GetBrushFromString) or a IBrush2D instance.
  14464. * - backgroundBorder: the brush to use to create a background border for the canvas. can be a string value (see Canvas2D.GetBrushFromString) or a IBrush2D instance.
  14465. * - backgroundBorderThickness: if a backgroundBorder is specified, its thickness can be set using this property
  14466. * - customWorldSpaceNode: if specified the Canvas will be rendered in this given Node. But it's the responsibility of the caller to set the "worldSpaceToNodeLocal" property to compute the hit of the mouse ray into the node (in world coordinate system) as well as rendering the cached bitmap in the node itself. The properties cachedRect and cachedTexture of Group2D will give you what you need to do that.
  14467. * - maxAdaptiveCanvasSize: set the max size (width and height) of the bitmap that will contain the cached version of the WorldSpace Canvas. Default is 1024 or less if it's not supported. In any case the value you give will be clipped by the maximum that WebGL supports on the running device. You can set any size, more than 1024 if you want, but testing proved it's a good max value for non "retina" like screens.
  14468. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  14469. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  14470. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  14471. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  14472. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  14473. */
  14474. function WorldSpaceCanvas2D(scene, size, settings) {
  14475. var _this;
  14476. BABYLON.Prim2DBase._isCanvasInit = true;
  14477. var s = settings;
  14478. s.isScreenSpace = false;
  14479. if (settings.unitScaleFactor != null) {
  14480. s.size = size.multiplyByFloats(settings.unitScaleFactor, settings.unitScaleFactor);
  14481. }
  14482. else {
  14483. s.size = size.clone();
  14484. }
  14485. settings.cachingStrategy = (settings.cachingStrategy == null) ? Canvas2D.CACHESTRATEGY_CANVAS : settings.cachingStrategy;
  14486. if (settings.cachingStrategy !== Canvas2D.CACHESTRATEGY_CANVAS) {
  14487. throw new Error("Right now only the CACHESTRATEGY_CANVAS cache Strategy is supported for WorldSpace Canvas. More will come soon!");
  14488. }
  14489. _this = _super.call(this, scene, settings) || this;
  14490. BABYLON.Prim2DBase._isCanvasInit = false;
  14491. _this._renderableData._useMipMap = true;
  14492. _this._renderableData._anisotropicLevel = 8;
  14493. //if (cachingStrategy === Canvas2D.CACHESTRATEGY_DONTCACHE) {
  14494. // throw new Error("CACHESTRATEGY_DONTCACHE cache Strategy can't be used for WorldSpace Canvas");
  14495. //}
  14496. if (settings.trackNode != null) {
  14497. _this._trackNode = settings.trackNode;
  14498. _this._trackNodeOffset = (settings.trackNodeOffset != null) ? settings.trackNodeOffset : BABYLON.Vector3.Zero();
  14499. _this._trackNodeBillboard = (settings.trackNodeBillboard != null) ? settings.trackNodeBillboard : false;
  14500. }
  14501. else {
  14502. _this._trackNode = null;
  14503. _this._trackNodeOffset = null;
  14504. _this._trackNodeBillboard = false;
  14505. }
  14506. var createWorldSpaceNode = !settings || (settings.customWorldSpaceNode == null);
  14507. _this._customWorldSpaceNode = !createWorldSpaceNode;
  14508. var id = settings ? settings.id || null : null;
  14509. // Set the max size of texture allowed for the adaptive render of the world space canvas cached bitmap
  14510. var capMaxTextSize = _this.engine.getCaps().maxRenderTextureSize;
  14511. var defaultTextSize = (Math.min(capMaxTextSize, 1024)); // Default is 1K if allowed otherwise the max allowed
  14512. if (settings.maxAdaptiveCanvasSize == null) {
  14513. _this._maxAdaptiveWorldSpaceCanvasSize = defaultTextSize;
  14514. }
  14515. else {
  14516. // We still clip the given value with the max allowed, the user may not be aware of these limitations
  14517. _this._maxAdaptiveWorldSpaceCanvasSize = Math.min(settings.maxAdaptiveCanvasSize, capMaxTextSize);
  14518. }
  14519. if (createWorldSpaceNode) {
  14520. var plane = new BABYLON.WorldSpaceCanvas2DNode(id, scene, _this);
  14521. var vertexData = BABYLON.VertexData.CreatePlane({
  14522. width: size.width,
  14523. height: size.height,
  14524. sideOrientation: settings && settings.sideOrientation || BABYLON.Mesh.DEFAULTSIDE
  14525. });
  14526. var mtl = new BABYLON.StandardMaterial(id + "_Material", scene);
  14527. _this.applyCachedTexture(vertexData, mtl);
  14528. vertexData.applyToMesh(plane, true);
  14529. mtl.specularColor = new BABYLON.Color3(0, 0, 0);
  14530. mtl.disableLighting = true;
  14531. mtl.useAlphaFromDiffuseTexture = true;
  14532. plane.position = settings && settings.worldPosition || BABYLON.Vector3.Zero();
  14533. plane.rotationQuaternion = settings && settings.worldRotation || BABYLON.Quaternion.Identity();
  14534. plane.material = mtl;
  14535. _this._worldSpaceNode = plane;
  14536. }
  14537. else {
  14538. _this._worldSpaceNode = settings.customWorldSpaceNode;
  14539. _this.applyCachedTexture(null, null);
  14540. }
  14541. _this.propertyChanged.add(function (e, st) {
  14542. var mesh = _this._worldSpaceNode;
  14543. if (mesh) {
  14544. mesh.isVisible = e.newValue;
  14545. }
  14546. }, BABYLON.Prim2DBase.isVisibleProperty.flagId);
  14547. return _this;
  14548. }
  14549. WorldSpaceCanvas2D.prototype.dispose = function () {
  14550. if (!_super.prototype.dispose.call(this)) {
  14551. return false;
  14552. }
  14553. if (!this._customWorldSpaceNode && this._worldSpaceNode) {
  14554. this._worldSpaceNode.dispose();
  14555. this._worldSpaceNode = null;
  14556. }
  14557. };
  14558. return WorldSpaceCanvas2D;
  14559. }(Canvas2D));
  14560. WorldSpaceCanvas2D = __decorate([
  14561. BABYLON.className("WorldSpaceCanvas2D", "BABYLON")
  14562. ], WorldSpaceCanvas2D);
  14563. BABYLON.WorldSpaceCanvas2D = WorldSpaceCanvas2D;
  14564. var ScreenSpaceCanvas2D = (function (_super) {
  14565. __extends(ScreenSpaceCanvas2D, _super);
  14566. /**
  14567. * Create a new 2D ScreenSpace Rendering Canvas, it is a 2D rectangle that has a size (width/height) and a position relative to the bottom/left corner of the screen.
  14568. * ScreenSpace Canvas will be drawn in the Viewport as a 2D Layer lying to the top of the 3D Scene. Typically used for traditional UI.
  14569. * All caching strategies will be available.
  14570. * PLEASE NOTE: the origin of a Screen Space Canvas is set to [0;0] (bottom/left) which is different than the default origin of a Primitive which is centered [0.5;0.5]
  14571. * @param scene the Scene that owns the Canvas
  14572. * @param settings a combination of settings, possible ones are
  14573. * - children: an array of direct children primitives
  14574. * - id: a text identifier, for information purpose only
  14575. * - x: the position along the x axis (horizontal), relative to the left edge of the viewport. you can alternatively use the position setting.
  14576. * - y: the position along the y axis (vertically), relative to the bottom edge of the viewport. you can alternatively use the position setting.
  14577. * - position: the position of the canvas, relative from the bottom/left of the scene's viewport. Alternatively you can set the x and y properties directly. Default value is [0, 0]
  14578. * - width: the width of the Canvas. you can alternatively use the size setting.
  14579. * - height: the height of the Canvas. you can alternatively use the size setting.
  14580. * - size: the Size of the canvas. Alternatively the width and height properties can be set. If null two behaviors depend on the cachingStrategy: if it's CACHESTRATEGY_CACHECANVAS then it will always auto-fit the rendering device, in all the other modes it will fit the content of the Canvas
  14581. * - renderingPhase: you can specify for which camera and which renderGroup this canvas will render to enable interleaving of 3D/2D content through the use of renderinGroup. As a rendering Group is rendered for each camera, you have to specify in the scope of which camera you want the canvas' render to be made. Default behavior will render the Canvas at the very end of the render loop.
  14582. * - designSize: if you want to set the canvas content based on fixed coordinates whatever the final canvas dimension would be, set this. For instance a designSize of 360*640 will give you the possibility to specify all the children element in this frame. The Canvas' true size will be the HTMLCanvas' size: for instance it could be 720*1280, then a uniform scale of 2 will be applied on the Canvas to keep the absolute coordinates working as expecting. If the ratios of the designSize and the true Canvas size are not the same, then the scale is computed following the designUseHorizAxis member by using either the size of the horizontal axis or the vertical axis.
  14583. * - designUseHorizAxis: you can set this member if you use designSize to specify which axis is priority to compute the scale when the ratio of the canvas' size is different from the designSize's one.
  14584. * - cachingStrategy: either CACHESTRATEGY_TOPLEVELGROUPS, CACHESTRATEGY_ALLGROUPS, CACHESTRATEGY_CANVAS, CACHESTRATEGY_DONTCACHE. Please refer to their respective documentation for more information. Default is Canvas2D.CACHESTRATEGY_DONTCACHE
  14585. * - enableInteraction: if true the pointer events will be listened and rerouted to the appropriate primitives of the Canvas2D through the Prim2DBase.onPointerEventObservable observable property. Default is true.
  14586. * - isVisible: true if the canvas must be visible, false for hidden. Default is true.
  14587. * - backgroundRoundRadius: the round radius of the background, either backgroundFill or backgroundBorder must be specified.
  14588. * - backgroundFill: the brush to use to create a background fill for the canvas. can be a string value (see BABYLON.Canvas2D.GetBrushFromString) or a IBrush2D instance.
  14589. * - backgroundBorder: the brush to use to create a background border for the canvas. can be a string value (see BABYLON.Canvas2D.GetBrushFromString) or a IBrush2D instance.
  14590. * - backgroundBorderThickness: if a backgroundBorder is specified, its thickness can be set using this property
  14591. * - customWorldSpaceNode: if specified the Canvas will be rendered in this given Node. But it's the responsibility of the caller to set the "worldSpaceToNodeLocal" property to compute the hit of the mouse ray into the node (in world coordinate system) as well as rendering the cached bitmap in the node itself. The properties cachedRect and cachedTexture of Group2D will give you what you need to do that.
  14592. * - paddingTop: top padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  14593. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  14594. * - paddingRight: right padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  14595. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  14596. * - padding: top, left, right and bottom padding formatted as a single string (see BABYLON.PrimitiveThickness.fromString)
  14597. */
  14598. function ScreenSpaceCanvas2D(scene, settings) {
  14599. var _this;
  14600. BABYLON.Prim2DBase._isCanvasInit = true;
  14601. _this = _super.call(this, scene, settings) || this;
  14602. return _this;
  14603. }
  14604. return ScreenSpaceCanvas2D;
  14605. }(Canvas2D));
  14606. ScreenSpaceCanvas2D = __decorate([
  14607. BABYLON.className("ScreenSpaceCanvas2D", "BABYLON")
  14608. ], ScreenSpaceCanvas2D);
  14609. BABYLON.ScreenSpaceCanvas2D = ScreenSpaceCanvas2D;
  14610. var Canvas2D_1;
  14611. })(BABYLON || (BABYLON = {}));
  14612. var __extends = (this && this.__extends) || function (d, b) {
  14613. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14614. function __() { this.constructor = d; }
  14615. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14616. };
  14617. var BABYLON;
  14618. (function (BABYLON) {
  14619. /**
  14620. * This is the class that is used to display a World Space Canvas into a 3D scene
  14621. */
  14622. var WorldSpaceCanvas2DNode = (function (_super) {
  14623. __extends(WorldSpaceCanvas2DNode, _super);
  14624. function WorldSpaceCanvas2DNode(name, scene, canvas) {
  14625. var _this = _super.call(this, name, scene) || this;
  14626. _this._canvas = canvas;
  14627. return _this;
  14628. }
  14629. WorldSpaceCanvas2DNode.prototype.dispose = function () {
  14630. _super.prototype.dispose.call(this);
  14631. if (this._canvas) {
  14632. this._canvas.dispose();
  14633. this._canvas = null;
  14634. }
  14635. };
  14636. return WorldSpaceCanvas2DNode;
  14637. }(BABYLON.Mesh));
  14638. BABYLON.WorldSpaceCanvas2DNode = WorldSpaceCanvas2DNode;
  14639. })(BABYLON || (BABYLON = {}));
  14640. var __extends = (this && this.__extends) || function (d, b) {
  14641. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14642. function __() { this.constructor = d; }
  14643. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14644. };
  14645. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14646. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14647. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14648. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  14649. return c > 3 && r && Object.defineProperty(target, key, r), r;
  14650. };
  14651. var BABYLON;
  14652. (function (BABYLON) {
  14653. var Command = (function () {
  14654. function Command(execute, canExecute) {
  14655. if (!execute) {
  14656. throw Error("At least an execute lambda must be given at Command creation time");
  14657. }
  14658. this._canExecuteChanged = null;
  14659. this._lastCanExecuteResult = null;
  14660. this.execute = execute;
  14661. this.canExecute = canExecute;
  14662. }
  14663. Command.prototype.canExecute = function (parameter) {
  14664. var res = true;
  14665. if (this._canExecute) {
  14666. res = this._canExecute(parameter);
  14667. }
  14668. if (res !== this._lastCanExecuteResult) {
  14669. if (this._canExecuteChanged && this._canExecuteChanged.hasObservers()) {
  14670. this._canExecuteChanged.notifyObservers(null);
  14671. }
  14672. this._lastCanExecuteResult = res;
  14673. }
  14674. return res;
  14675. };
  14676. Command.prototype.execute = function (parameter) {
  14677. this._execute(parameter);
  14678. };
  14679. Object.defineProperty(Command.prototype, "canExecuteChanged", {
  14680. get: function () {
  14681. if (!this._canExecuteChanged) {
  14682. this._canExecuteChanged = new BABYLON.Observable();
  14683. }
  14684. return this._canExecuteChanged;
  14685. },
  14686. enumerable: true,
  14687. configurable: true
  14688. });
  14689. return Command;
  14690. }());
  14691. BABYLON.Command = Command;
  14692. var UIElement = (function (_super) {
  14693. __extends(UIElement, _super);
  14694. function UIElement(settings) {
  14695. var _this = _super.call(this) || this;
  14696. if (!settings) {
  14697. throw Error("A settings object must be passed with at least either a parent or owner parameter");
  14698. }
  14699. var type = BABYLON.Tools.getFullClassName(_this);
  14700. _this._ownerWindow = null;
  14701. _this._parent = null;
  14702. _this._visualPlaceholder = null;
  14703. _this._visualTemplateRoot = null;
  14704. _this._visualChildrenPlaceholder = null;
  14705. _this._hierarchyDepth = 0;
  14706. _this._renderingTemplateName = (settings.templateName != null) ? settings.templateName : GUIManager.DefaultTemplateName;
  14707. _this._style = (settings.styleName != null) ? GUIManager.getStyle(type, settings.styleName) : null;
  14708. _this._flags = 0;
  14709. _this._id = (settings.id != null) ? settings.id : null;
  14710. _this._uid = null;
  14711. _this._width = (settings.width != null) ? settings.width : null;
  14712. _this._height = (settings.height != null) ? settings.height : null;
  14713. _this._minWidth = (settings.minWidth != null) ? settings.minWidth : 0;
  14714. _this._minHeight = (settings.minHeight != null) ? settings.minHeight : 0;
  14715. _this._maxWidth = (settings.maxWidth != null) ? settings.maxWidth : Number.MAX_VALUE;
  14716. _this._maxHeight = (settings.maxHeight != null) ? settings.maxHeight : Number.MAX_VALUE;
  14717. _this._margin = null;
  14718. _this._padding = null;
  14719. _this._marginAlignment = null;
  14720. _this._setFlags(UIElement.flagIsVisible | UIElement.flagIsEnabled);
  14721. // Default Margin Alignment for UIElement is stretch for horizontal/vertical and not left/bottom (which is the default for Canvas2D Primitives)
  14722. //this.marginAlignment.horizontal = PrimitiveAlignment.AlignStretch;
  14723. //this.marginAlignment.vertical = PrimitiveAlignment.AlignStretch;
  14724. // Set the layout/margin stuffs
  14725. if (settings.marginTop) {
  14726. _this.margin.setTop(settings.marginTop);
  14727. }
  14728. if (settings.marginLeft) {
  14729. _this.margin.setLeft(settings.marginLeft);
  14730. }
  14731. if (settings.marginRight) {
  14732. _this.margin.setRight(settings.marginRight);
  14733. }
  14734. if (settings.marginBottom) {
  14735. _this.margin.setBottom(settings.marginBottom);
  14736. }
  14737. if (settings.margin) {
  14738. if (typeof settings.margin === "string") {
  14739. _this.margin.fromString(settings.margin);
  14740. }
  14741. else {
  14742. _this.margin.fromUniformPixels(settings.margin);
  14743. }
  14744. }
  14745. if (settings.marginHAlignment) {
  14746. _this.marginAlignment.horizontal = settings.marginHAlignment;
  14747. }
  14748. if (settings.marginVAlignment) {
  14749. _this.marginAlignment.vertical = settings.marginVAlignment;
  14750. }
  14751. if (settings.marginAlignment) {
  14752. _this.marginAlignment.fromString(settings.marginAlignment);
  14753. }
  14754. if (settings.paddingTop) {
  14755. _this.padding.setTop(settings.paddingTop);
  14756. }
  14757. if (settings.paddingLeft) {
  14758. _this.padding.setLeft(settings.paddingLeft);
  14759. }
  14760. if (settings.paddingRight) {
  14761. _this.padding.setRight(settings.paddingRight);
  14762. }
  14763. if (settings.paddingBottom) {
  14764. _this.padding.setBottom(settings.paddingBottom);
  14765. }
  14766. if (settings.padding) {
  14767. _this.padding.fromString(settings.padding);
  14768. }
  14769. if (settings.paddingHAlignment) {
  14770. _this.paddingAlignment.horizontal = settings.paddingHAlignment;
  14771. }
  14772. if (settings.paddingVAlignment) {
  14773. _this.paddingAlignment.vertical = settings.paddingVAlignment;
  14774. }
  14775. if (settings.paddingAlignment) {
  14776. _this.paddingAlignment.fromString(settings.paddingAlignment);
  14777. }
  14778. if (settings.parent != null) {
  14779. _this._parent = settings.parent;
  14780. _this._hierarchyDepth = _this._parent._hierarchyDepth + 1;
  14781. }
  14782. return _this;
  14783. }
  14784. Object.defineProperty(UIElement, "enabledState", {
  14785. get: function () {
  14786. return UIElement._enableState;
  14787. },
  14788. enumerable: true,
  14789. configurable: true
  14790. });
  14791. Object.defineProperty(UIElement, "disabledState", {
  14792. get: function () {
  14793. return UIElement._disabledState;
  14794. },
  14795. enumerable: true,
  14796. configurable: true
  14797. });
  14798. Object.defineProperty(UIElement, "mouseOverState", {
  14799. get: function () {
  14800. return UIElement._mouseOverState;
  14801. },
  14802. enumerable: true,
  14803. configurable: true
  14804. });
  14805. UIElement.prototype.dispose = function () {
  14806. if (this.isDisposed) {
  14807. return false;
  14808. }
  14809. if (this._renderingTemplate) {
  14810. this._renderingTemplate.detach();
  14811. this._renderingTemplate = null;
  14812. }
  14813. _super.prototype.dispose.call(this);
  14814. // Don't set to null, it may upset somebody...
  14815. this.animations.splice(0);
  14816. return true;
  14817. };
  14818. /**
  14819. * Returns as a new array populated with the Animatable used by the primitive. Must be overloaded by derived primitives.
  14820. * Look at Sprite2D for more information
  14821. */
  14822. UIElement.prototype.getAnimatables = function () {
  14823. return new Array();
  14824. };
  14825. // TODO
  14826. // PROPERTIES
  14827. // Style
  14828. // Id
  14829. // Parent/Children
  14830. // ActualWidth/Height, MinWidth/Height, MaxWidth/Height,
  14831. // Alignment/Margin
  14832. // Visibility, IsVisible
  14833. // IsEnabled (is false, control is disabled, no interaction and a specific render state)
  14834. // CacheMode of Visual Elements
  14835. // Focusable/IsFocused
  14836. // IsPointerCaptured, CapturePointer, IsPointerDirectlyOver, IsPointerOver. De-correlate mouse, stylus, touch?
  14837. // ContextMenu
  14838. // Cursor
  14839. // DesiredSize
  14840. // IsInputEnable ?
  14841. // Opacity, OpacityMask ?
  14842. // SnapToDevicePixels
  14843. // Tag
  14844. // ToolTip
  14845. // METHODS
  14846. // BringIntoView (for scrollable content, to move the scroll to bring the given element visible in the parent's area)
  14847. // Capture/ReleaseCapture (mouse, touch, stylus)
  14848. // Focus
  14849. // PointFrom/ToScreen to translate coordinates
  14850. // EVENTS
  14851. // ContextMenuOpening/Closing/Changed
  14852. // DragEnter/LeaveOver, Drop
  14853. // Got/LostFocus
  14854. // IsEnabledChanged
  14855. // IsPointerOver/DirectlyOverChanged
  14856. // IsVisibleChanged
  14857. // KeyDown/Up
  14858. // LayoutUpdated ?
  14859. // Pointer related events
  14860. // SizeChanged
  14861. // ToolTipOpening/Closing
  14862. UIElement.prototype.findById = function (id) {
  14863. if (this._id === id) {
  14864. return this;
  14865. }
  14866. var children = this._getChildren();
  14867. for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
  14868. var child = children_1[_i];
  14869. var r = child.findById(id);
  14870. if (r != null) {
  14871. return r;
  14872. }
  14873. }
  14874. };
  14875. Object.defineProperty(UIElement.prototype, "ownerWindow", {
  14876. get: function () {
  14877. return this._ownerWindow;
  14878. },
  14879. enumerable: true,
  14880. configurable: true
  14881. });
  14882. Object.defineProperty(UIElement.prototype, "style", {
  14883. get: function () {
  14884. if (!this.style) {
  14885. return GUIManager.DefaultStyleName;
  14886. }
  14887. return this._style.name;
  14888. },
  14889. set: function (value) {
  14890. if (this._style && (this._style.name === value)) {
  14891. return;
  14892. }
  14893. var newStyle = null;
  14894. if (value) {
  14895. newStyle = GUIManager.getStyle(BABYLON.Tools.getFullClassName(this), value);
  14896. if (!newStyle) {
  14897. throw Error("Couldn't find Style " + value + " for UIElement " + BABYLON.Tools.getFullClassName(this));
  14898. }
  14899. }
  14900. if (this._style) {
  14901. this._style.removeStyle(this);
  14902. }
  14903. if (newStyle) {
  14904. newStyle.applyStyle(this);
  14905. }
  14906. this._style = newStyle;
  14907. },
  14908. enumerable: true,
  14909. configurable: true
  14910. });
  14911. Object.defineProperty(UIElement.prototype, "id", {
  14912. /**
  14913. * A string that identifies the UIElement.
  14914. * The id is optional and there's possible collision with other UIElement's id as the uniqueness is not supported.
  14915. */
  14916. get: function () {
  14917. return this._id;
  14918. },
  14919. set: function (value) {
  14920. if (this._id === value) {
  14921. return;
  14922. }
  14923. this._id = value;
  14924. },
  14925. enumerable: true,
  14926. configurable: true
  14927. });
  14928. Object.defineProperty(UIElement.prototype, "uid", {
  14929. /**
  14930. * Return a unique id automatically generated.
  14931. * This property is mainly used for serialization to ensure a perfect way of identifying a UIElement
  14932. */
  14933. get: function () {
  14934. if (!this._uid) {
  14935. this._uid = BABYLON.Tools.RandomId();
  14936. }
  14937. return this._uid;
  14938. },
  14939. enumerable: true,
  14940. configurable: true
  14941. });
  14942. Object.defineProperty(UIElement.prototype, "hierarchyDepth", {
  14943. get: function () {
  14944. return this._hierarchyDepth;
  14945. },
  14946. enumerable: true,
  14947. configurable: true
  14948. });
  14949. Object.defineProperty(UIElement.prototype, "parent", {
  14950. get: function () {
  14951. return this._parent;
  14952. },
  14953. set: function (value) {
  14954. this._parent = value;
  14955. },
  14956. enumerable: true,
  14957. configurable: true
  14958. });
  14959. Object.defineProperty(UIElement.prototype, "width", {
  14960. get: function () {
  14961. return this._width;
  14962. },
  14963. set: function (value) {
  14964. this._width = value;
  14965. },
  14966. enumerable: true,
  14967. configurable: true
  14968. });
  14969. Object.defineProperty(UIElement.prototype, "height", {
  14970. get: function () {
  14971. return this._height;
  14972. },
  14973. set: function (value) {
  14974. this._height = value;
  14975. },
  14976. enumerable: true,
  14977. configurable: true
  14978. });
  14979. Object.defineProperty(UIElement.prototype, "minWidth", {
  14980. get: function () {
  14981. return this._minWidth;
  14982. },
  14983. set: function (value) {
  14984. this._minWidth = value;
  14985. },
  14986. enumerable: true,
  14987. configurable: true
  14988. });
  14989. Object.defineProperty(UIElement.prototype, "minHheight", {
  14990. get: function () {
  14991. return this._minHeight;
  14992. },
  14993. enumerable: true,
  14994. configurable: true
  14995. });
  14996. Object.defineProperty(UIElement.prototype, "minHeight", {
  14997. set: function (value) {
  14998. this._minHeight = value;
  14999. },
  15000. enumerable: true,
  15001. configurable: true
  15002. });
  15003. Object.defineProperty(UIElement.prototype, "maxWidth", {
  15004. get: function () {
  15005. return this._maxWidth;
  15006. },
  15007. set: function (value) {
  15008. this._maxWidth = value;
  15009. },
  15010. enumerable: true,
  15011. configurable: true
  15012. });
  15013. Object.defineProperty(UIElement.prototype, "maxHeight", {
  15014. get: function () {
  15015. return this._maxHeight;
  15016. },
  15017. set: function (value) {
  15018. this._maxHeight = value;
  15019. },
  15020. enumerable: true,
  15021. configurable: true
  15022. });
  15023. Object.defineProperty(UIElement.prototype, "actualWidth", {
  15024. get: function () {
  15025. return this._actualWidth;
  15026. },
  15027. set: function (value) {
  15028. this._actualWidth = value;
  15029. },
  15030. enumerable: true,
  15031. configurable: true
  15032. });
  15033. Object.defineProperty(UIElement.prototype, "actualHeight", {
  15034. get: function () {
  15035. return this._actualHeight;
  15036. },
  15037. set: function (value) {
  15038. this._actualHeight = value;
  15039. },
  15040. enumerable: true,
  15041. configurable: true
  15042. });
  15043. Object.defineProperty(UIElement.prototype, "margin", {
  15044. get: function () {
  15045. var _this = this;
  15046. if (!this._margin) {
  15047. this._margin = new BABYLON.PrimitiveThickness(function () {
  15048. if (!_this.parent) {
  15049. return null;
  15050. }
  15051. return _this.parent.margin;
  15052. });
  15053. }
  15054. return this._margin;
  15055. },
  15056. set: function (value) {
  15057. this.margin.copyFrom(value);
  15058. },
  15059. enumerable: true,
  15060. configurable: true
  15061. });
  15062. Object.defineProperty(UIElement.prototype, "_hasMargin", {
  15063. get: function () {
  15064. return (this._margin !== null && !this._margin.isDefault) || (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  15065. },
  15066. enumerable: true,
  15067. configurable: true
  15068. });
  15069. Object.defineProperty(UIElement.prototype, "padding", {
  15070. get: function () {
  15071. var _this = this;
  15072. if (!this._padding) {
  15073. this._padding = new BABYLON.PrimitiveThickness(function () {
  15074. if (!_this.parent) {
  15075. return null;
  15076. }
  15077. return _this.parent.padding;
  15078. });
  15079. }
  15080. return this._padding;
  15081. },
  15082. set: function (value) {
  15083. this.padding.copyFrom(value);
  15084. },
  15085. enumerable: true,
  15086. configurable: true
  15087. });
  15088. Object.defineProperty(UIElement.prototype, "_hasPadding", {
  15089. get: function () {
  15090. return this._padding !== null && !this._padding.isDefault;
  15091. },
  15092. enumerable: true,
  15093. configurable: true
  15094. });
  15095. Object.defineProperty(UIElement.prototype, "marginAlignment", {
  15096. get: function () {
  15097. if (!this._marginAlignment) {
  15098. this._marginAlignment = new BABYLON.PrimitiveAlignment();
  15099. }
  15100. return this._marginAlignment;
  15101. },
  15102. set: function (value) {
  15103. this.marginAlignment.copyFrom(value);
  15104. },
  15105. enumerable: true,
  15106. configurable: true
  15107. });
  15108. Object.defineProperty(UIElement.prototype, "_hasMarginAlignment", {
  15109. /**
  15110. * Check if there a marginAlignment specified (non null and not default)
  15111. */
  15112. get: function () {
  15113. return (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  15114. },
  15115. enumerable: true,
  15116. configurable: true
  15117. });
  15118. Object.defineProperty(UIElement.prototype, "paddingAlignment", {
  15119. get: function () {
  15120. if (!this._paddingAlignment) {
  15121. this._paddingAlignment = new BABYLON.PrimitiveAlignment();
  15122. }
  15123. return this._paddingAlignment;
  15124. },
  15125. set: function (value) {
  15126. this.paddingAlignment.copyFrom(value);
  15127. },
  15128. enumerable: true,
  15129. configurable: true
  15130. });
  15131. Object.defineProperty(UIElement.prototype, "_hasPaddingAlignment", {
  15132. /**
  15133. * Check if there a marginAlignment specified (non null and not default)
  15134. */
  15135. get: function () {
  15136. return (this._paddingAlignment !== null && !this._paddingAlignment.isDefault);
  15137. },
  15138. enumerable: true,
  15139. configurable: true
  15140. });
  15141. Object.defineProperty(UIElement.prototype, "isVisible", {
  15142. get: function () {
  15143. return this._isFlagSet(UIElement.flagIsVisible);
  15144. },
  15145. set: function (value) {
  15146. if (this.isVisible === value) {
  15147. return;
  15148. }
  15149. this._visualPlaceholder.levelVisible = value;
  15150. this._changeFlags(UIElement.flagIsVisible, value);
  15151. },
  15152. enumerable: true,
  15153. configurable: true
  15154. });
  15155. Object.defineProperty(UIElement.prototype, "isEnabled", {
  15156. get: function () {
  15157. return this._isFlagSet(UIElement.flagIsEnabled);
  15158. },
  15159. set: function (value) {
  15160. this._changeFlags(UIElement.flagIsEnabled, value);
  15161. },
  15162. enumerable: true,
  15163. configurable: true
  15164. });
  15165. Object.defineProperty(UIElement.prototype, "isFocused", {
  15166. get: function () {
  15167. return this._isFlagSet(UIElement.flagIsFocus);
  15168. },
  15169. set: function (value) {
  15170. // If the UIElement doesn't accept focus, set it on its parent
  15171. if (!this.isFocusable) {
  15172. var p = this.parent;
  15173. if (!p) {
  15174. return;
  15175. }
  15176. p.isFocused = value;
  15177. }
  15178. // If the focus is being set, notify the Focus Manager
  15179. if (value) {
  15180. this.ownerWindow.focusManager.setFocusOn(this, this.getFocusScope());
  15181. }
  15182. this._changeFlags(UIElement.flagIsFocus, value);
  15183. },
  15184. enumerable: true,
  15185. configurable: true
  15186. });
  15187. Object.defineProperty(UIElement.prototype, "isMouseOver", {
  15188. get: function () {
  15189. return this._isFlagSet(UIElement.flagIsMouseOver);
  15190. },
  15191. set: function (value) {
  15192. this._changeFlags(UIElement.flagIsMouseOver, value);
  15193. },
  15194. enumerable: true,
  15195. configurable: true
  15196. });
  15197. Object.defineProperty(UIElement.prototype, "isFocusScope", {
  15198. get: function () {
  15199. return this._isFlagSet(UIElement.flagIsFocusScope);
  15200. },
  15201. set: function (value) {
  15202. this._changeFlags(UIElement.flagIsFocusScope, value);
  15203. },
  15204. enumerable: true,
  15205. configurable: true
  15206. });
  15207. Object.defineProperty(UIElement.prototype, "isFocusable", {
  15208. get: function () {
  15209. return this._isFlagSet(UIElement.flagIsFocusable);
  15210. },
  15211. set: function (value) {
  15212. this._changeFlags(UIElement.flagIsFocusable, value);
  15213. },
  15214. enumerable: true,
  15215. configurable: true
  15216. });
  15217. // Look for the nearest parent which is the focus scope. Should always return something as the Window UIElement which is the root of all UI Tree is focus scope (unless the user disable it)
  15218. UIElement.prototype.getFocusScope = function () {
  15219. if (this.isFocusScope) {
  15220. return this;
  15221. }
  15222. var p = this.parent;
  15223. if (!p) {
  15224. return null;
  15225. }
  15226. return p.getFocusScope();
  15227. };
  15228. /**
  15229. * Check if a given flag is set
  15230. * @param flag the flag value
  15231. * @return true if set, false otherwise
  15232. */
  15233. UIElement.prototype._isFlagSet = function (flag) {
  15234. return (this._flags & flag) !== 0;
  15235. };
  15236. /**
  15237. * Check if all given flags are set
  15238. * @param flags the flags ORed
  15239. * @return true if all the flags are set, false otherwise
  15240. */
  15241. UIElement.prototype._areAllFlagsSet = function (flags) {
  15242. return (this._flags & flags) === flags;
  15243. };
  15244. /**
  15245. * Check if at least one flag of the given flags is set
  15246. * @param flags the flags ORed
  15247. * @return true if at least one flag is set, false otherwise
  15248. */
  15249. UIElement.prototype._areSomeFlagsSet = function (flags) {
  15250. return (this._flags & flags) !== 0;
  15251. };
  15252. /**
  15253. * Clear the given flags
  15254. * @param flags the flags to clear
  15255. */
  15256. UIElement.prototype._clearFlags = function (flags) {
  15257. this._flags &= ~flags;
  15258. };
  15259. /**
  15260. * Set the given flags to true state
  15261. * @param flags the flags ORed to set
  15262. * @return the flags state before this call
  15263. */
  15264. UIElement.prototype._setFlags = function (flags) {
  15265. var cur = this._flags;
  15266. this._flags |= flags;
  15267. return cur;
  15268. };
  15269. /**
  15270. * Change the state of the given flags
  15271. * @param flags the flags ORed to change
  15272. * @param state true to set them, false to clear them
  15273. */
  15274. UIElement.prototype._changeFlags = function (flags, state) {
  15275. if (state) {
  15276. this._flags |= flags;
  15277. }
  15278. else {
  15279. this._flags &= ~flags;
  15280. }
  15281. };
  15282. UIElement.prototype._assignTemplate = function (templateName) {
  15283. if (!templateName) {
  15284. templateName = GUIManager.DefaultTemplateName;
  15285. }
  15286. var className = BABYLON.Tools.getFullClassName(this);
  15287. if (!className) {
  15288. throw Error("Couldn't access class name of this UIElement, you have to decorate the type with the className decorator");
  15289. }
  15290. var factory = GUIManager.getRenderingTemplate(className, templateName);
  15291. if (!factory) {
  15292. throw Error("Couldn't get the renderingTemplate " + templateName + " of class " + className);
  15293. }
  15294. this._renderingTemplateName = templateName;
  15295. this._renderingTemplate = factory();
  15296. this._renderingTemplate.attach(this);
  15297. };
  15298. UIElement.prototype._createVisualTree = function () {
  15299. var parentPrim = this.ownerWindow.canvas;
  15300. if (this.parent) {
  15301. parentPrim = this.parent.visualChildrenPlaceholder;
  15302. }
  15303. if (!this._renderingTemplate) {
  15304. this._assignTemplate(this._renderingTemplateName);
  15305. }
  15306. this._visualPlaceholder = new BABYLON.Group2D({ parent: parentPrim, id: "GUI " + BABYLON.Tools.getClassName(this) + " RootGroup of " + this.id });
  15307. var p = this._visualPlaceholder;
  15308. p.addExternalData("_GUIOwnerElement_", this);
  15309. p.dataSource = this;
  15310. p.createSimpleDataBinding(BABYLON.Prim2DBase.widthProperty, "width", BABYLON.DataBinding.MODE_ONEWAY);
  15311. p.createSimpleDataBinding(BABYLON.Prim2DBase.heightProperty, "height", BABYLON.DataBinding.MODE_ONEWAY);
  15312. p.createSimpleDataBinding(BABYLON.Prim2DBase.actualWidthProperty, "actualWidth", BABYLON.DataBinding.MODE_ONEWAYTOSOURCE);
  15313. p.createSimpleDataBinding(BABYLON.Prim2DBase.actualHeightProperty, "actualHeight", BABYLON.DataBinding.MODE_ONEWAYTOSOURCE);
  15314. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginProperty, "margin", BABYLON.DataBinding.MODE_ONEWAY);
  15315. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginAlignmentProperty, "marginAlignment", BABYLON.DataBinding.MODE_ONEWAY);
  15316. this.createVisualTree();
  15317. };
  15318. UIElement.prototype._patchUIElement = function (ownerWindow, parent) {
  15319. if (ownerWindow) {
  15320. if (!this._ownerWindow) {
  15321. ownerWindow._registerVisualToBuild(this);
  15322. }
  15323. this._ownerWindow = ownerWindow;
  15324. }
  15325. this._parent = parent;
  15326. if (parent) {
  15327. this._hierarchyDepth = parent.hierarchyDepth + 1;
  15328. }
  15329. var children = this._getChildren();
  15330. if (children) {
  15331. for (var _i = 0, children_2 = children; _i < children_2.length; _i++) {
  15332. var curChild = children_2[_i];
  15333. curChild._patchUIElement(ownerWindow, this);
  15334. }
  15335. }
  15336. };
  15337. // Overload the SmartPropertyBase's method to provide the additional logic of returning the parent's dataSource if there's no dataSource specified at this level.
  15338. UIElement.prototype._getDataSource = function () {
  15339. var levelDS = _super.prototype._getDataSource.call(this);
  15340. if (levelDS != null) {
  15341. return levelDS;
  15342. }
  15343. var p = this.parent;
  15344. if (p != null) {
  15345. return p.dataSource;
  15346. }
  15347. return null;
  15348. };
  15349. UIElement.prototype.createVisualTree = function () {
  15350. var res = this._renderingTemplate.createVisualTree(this, this._visualPlaceholder);
  15351. this._visualTemplateRoot = res.root;
  15352. this._visualChildrenPlaceholder = res.contentPlaceholder;
  15353. };
  15354. Object.defineProperty(UIElement.prototype, "visualPlaceholder", {
  15355. get: function () {
  15356. return this._visualPlaceholder;
  15357. },
  15358. enumerable: true,
  15359. configurable: true
  15360. });
  15361. Object.defineProperty(UIElement.prototype, "visualTemplateRoot", {
  15362. get: function () {
  15363. return this._visualTemplateRoot;
  15364. },
  15365. enumerable: true,
  15366. configurable: true
  15367. });
  15368. Object.defineProperty(UIElement.prototype, "visualChildrenPlaceholder", {
  15369. get: function () {
  15370. return this._visualChildrenPlaceholder;
  15371. },
  15372. enumerable: true,
  15373. configurable: true
  15374. });
  15375. Object.defineProperty(UIElement.prototype, "_position", {
  15376. get: function () { return null; } // TODO use abstract keyword when TS 2.0 will be approved
  15377. ,
  15378. enumerable: true,
  15379. configurable: true
  15380. });
  15381. return UIElement;
  15382. }(BABYLON.SmartPropertyBase));
  15383. UIElement.UIELEMENT_PROPCOUNT = 16;
  15384. UIElement.flagVisualToBuild = 0x0000001;
  15385. UIElement.flagIsVisible = 0x0000002;
  15386. UIElement.flagIsFocus = 0x0000004;
  15387. UIElement.flagIsFocusScope = 0x0000008;
  15388. UIElement.flagIsFocusable = 0x0000010;
  15389. UIElement.flagIsEnabled = 0x0000020;
  15390. UIElement.flagIsMouseOver = 0x0000040;
  15391. UIElement._enableState = "Enabled";
  15392. UIElement._disabledState = "Disabled";
  15393. UIElement._mouseOverState = "MouseOver";
  15394. __decorate([
  15395. BABYLON.dependencyProperty(0, function (pi) { return UIElement.parentProperty = pi; })
  15396. ], UIElement.prototype, "parent", null);
  15397. __decorate([
  15398. BABYLON.dependencyProperty(1, function (pi) { return UIElement.widthProperty = pi; })
  15399. ], UIElement.prototype, "width", null);
  15400. __decorate([
  15401. BABYLON.dependencyProperty(2, function (pi) { return UIElement.heightProperty = pi; })
  15402. ], UIElement.prototype, "height", null);
  15403. __decorate([
  15404. BABYLON.dependencyProperty(3, function (pi) { return UIElement.minWidthProperty = pi; })
  15405. ], UIElement.prototype, "minWidth", null);
  15406. __decorate([
  15407. BABYLON.dependencyProperty(4, function (pi) { return UIElement.minHeightProperty = pi; })
  15408. ], UIElement.prototype, "minHheight", null);
  15409. __decorate([
  15410. BABYLON.dependencyProperty(5, function (pi) { return UIElement.maxWidthProperty = pi; })
  15411. ], UIElement.prototype, "maxWidth", null);
  15412. __decorate([
  15413. BABYLON.dependencyProperty(6, function (pi) { return UIElement.maxHeightProperty = pi; })
  15414. ], UIElement.prototype, "maxHeight", null);
  15415. __decorate([
  15416. BABYLON.dependencyProperty(7, function (pi) { return UIElement.actualWidthProperty = pi; })
  15417. ], UIElement.prototype, "actualWidth", null);
  15418. __decorate([
  15419. BABYLON.dependencyProperty(8, function (pi) { return UIElement.actualHeightProperty = pi; })
  15420. ], UIElement.prototype, "actualHeight", null);
  15421. __decorate([
  15422. BABYLON.dynamicLevelProperty(9, function (pi) { return UIElement.marginProperty = pi; })
  15423. ], UIElement.prototype, "margin", null);
  15424. __decorate([
  15425. BABYLON.dynamicLevelProperty(10, function (pi) { return UIElement.paddingProperty = pi; })
  15426. ], UIElement.prototype, "padding", null);
  15427. __decorate([
  15428. BABYLON.dynamicLevelProperty(11, function (pi) { return UIElement.marginAlignmentProperty = pi; })
  15429. ], UIElement.prototype, "marginAlignment", null);
  15430. __decorate([
  15431. BABYLON.dynamicLevelProperty(12, function (pi) { return UIElement.paddingAlignmentProperty = pi; })
  15432. ], UIElement.prototype, "paddingAlignment", null);
  15433. __decorate([
  15434. BABYLON.dynamicLevelProperty(13, function (pi) { return UIElement.isEnabledProperty = pi; })
  15435. ], UIElement.prototype, "isEnabled", null);
  15436. __decorate([
  15437. BABYLON.dynamicLevelProperty(14, function (pi) { return UIElement.isFocusedProperty = pi; })
  15438. ], UIElement.prototype, "isFocused", null);
  15439. __decorate([
  15440. BABYLON.dynamicLevelProperty(15, function (pi) { return UIElement.isMouseOverProperty = pi; })
  15441. ], UIElement.prototype, "isMouseOver", null);
  15442. BABYLON.UIElement = UIElement;
  15443. var UIElementStyle = (function () {
  15444. function UIElementStyle() {
  15445. }
  15446. Object.defineProperty(UIElementStyle.prototype, "name", {
  15447. get: function () { return null; } // TODO use abstract keyword when TS 2.0 will be approved
  15448. ,
  15449. enumerable: true,
  15450. configurable: true
  15451. });
  15452. return UIElementStyle;
  15453. }());
  15454. BABYLON.UIElementStyle = UIElementStyle;
  15455. var GUIManager = (function () {
  15456. function GUIManager() {
  15457. }
  15458. /////////////////////////////////////////////////////////////////////////////////////////////////////
  15459. // DATA TEMPLATE MANAGER
  15460. GUIManager.registerDataTemplate = function (className, factory) {
  15461. };
  15462. // DATA TEMPLATE MANAGER
  15463. /////////////////////////////////////////////////////////////////////////////////////////////////////
  15464. /////////////////////////////////////////////////////////////////////////////////////////////////////
  15465. // STYLE MANAGER
  15466. GUIManager.getStyle = function (uiElType, styleName) {
  15467. var styles = GUIManager.stylesByUIElement.get(uiElType);
  15468. if (!styles) {
  15469. throw Error("The type " + uiElType + " is unknown, no style were registered for it.");
  15470. }
  15471. var style = styles.get(styleName);
  15472. if (!style) {
  15473. throw Error("Couldn't find Template " + styleName + " of UIElement type " + uiElType);
  15474. }
  15475. return style;
  15476. };
  15477. GUIManager.registerStyle = function (uiElType, templateName, style) {
  15478. var templates = GUIManager.stylesByUIElement.getOrAddWithFactory(uiElType, function () { return new BABYLON.StringDictionary(); });
  15479. if (templates.contains(templateName)) {
  15480. templates[templateName] = style;
  15481. }
  15482. else {
  15483. templates.add(templateName, style);
  15484. }
  15485. };
  15486. Object.defineProperty(GUIManager, "DefaultStyleName", {
  15487. get: function () {
  15488. return GUIManager._defaultStyleName;
  15489. },
  15490. set: function (value) {
  15491. GUIManager._defaultStyleName = value;
  15492. },
  15493. enumerable: true,
  15494. configurable: true
  15495. });
  15496. // STYLE MANAGER
  15497. /////////////////////////////////////////////////////////////////////////////////////////////////////
  15498. /////////////////////////////////////////////////////////////////////////////////////////////////////
  15499. // RENDERING TEMPLATE MANAGER
  15500. GUIManager.getRenderingTemplate = function (uiElType, templateName) {
  15501. var templates = GUIManager.renderingTemplatesByUIElement.get(uiElType);
  15502. if (!templates) {
  15503. throw Error("The type " + uiElType + " is unknown, no Rendering Template were registered for it.");
  15504. }
  15505. var templateFactory = templates.get(templateName);
  15506. if (!templateFactory) {
  15507. throw Error("Couldn't find Template " + templateName + " of UI Element type " + uiElType);
  15508. }
  15509. return templateFactory;
  15510. };
  15511. GUIManager.registerRenderingTemplate = function (uiElType, templateName, factory) {
  15512. var templates = GUIManager.renderingTemplatesByUIElement.getOrAddWithFactory(uiElType, function () { return new BABYLON.StringDictionary(); });
  15513. if (templates.contains(templateName)) {
  15514. templates[templateName] = factory;
  15515. }
  15516. else {
  15517. templates.add(templateName, factory);
  15518. }
  15519. };
  15520. Object.defineProperty(GUIManager, "DefaultTemplateName", {
  15521. get: function () {
  15522. return GUIManager._defaultTemplateName;
  15523. },
  15524. set: function (value) {
  15525. GUIManager._defaultTemplateName = value;
  15526. },
  15527. enumerable: true,
  15528. configurable: true
  15529. });
  15530. return GUIManager;
  15531. }());
  15532. GUIManager.stylesByUIElement = new BABYLON.StringDictionary();
  15533. GUIManager.renderingTemplatesByUIElement = new BABYLON.StringDictionary();
  15534. // RENDERING TEMPLATE MANAGER
  15535. /////////////////////////////////////////////////////////////////////////////////////////////////////
  15536. GUIManager._defaultTemplateName = "Default";
  15537. GUIManager._defaultStyleName = "Default";
  15538. BABYLON.GUIManager = GUIManager;
  15539. var UIElementRenderingTemplateBase = (function () {
  15540. function UIElementRenderingTemplateBase() {
  15541. }
  15542. UIElementRenderingTemplateBase.prototype.attach = function (owner) {
  15543. this._owner = owner;
  15544. };
  15545. UIElementRenderingTemplateBase.prototype.detach = function () {
  15546. };
  15547. Object.defineProperty(UIElementRenderingTemplateBase.prototype, "owner", {
  15548. get: function () {
  15549. return this._owner;
  15550. },
  15551. enumerable: true,
  15552. configurable: true
  15553. });
  15554. return UIElementRenderingTemplateBase;
  15555. }());
  15556. BABYLON.UIElementRenderingTemplateBase = UIElementRenderingTemplateBase;
  15557. function registerWindowRenderingTemplate(uiElType, templateName, factory) {
  15558. return function () {
  15559. GUIManager.registerRenderingTemplate(uiElType, templateName, factory);
  15560. };
  15561. }
  15562. BABYLON.registerWindowRenderingTemplate = registerWindowRenderingTemplate;
  15563. })(BABYLON || (BABYLON = {}));
  15564. var __extends = (this && this.__extends) || function (d, b) {
  15565. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  15566. function __() { this.constructor = d; }
  15567. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15568. };
  15569. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  15570. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  15571. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  15572. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  15573. return c > 3 && r && Object.defineProperty(target, key, r), r;
  15574. };
  15575. var BABYLON;
  15576. (function (BABYLON) {
  15577. var StackPanel = StackPanel_1 = (function (_super) {
  15578. __extends(StackPanel, _super);
  15579. function StackPanel(settings) {
  15580. var _this;
  15581. if (!settings) {
  15582. settings = {};
  15583. }
  15584. _this = _super.call(this, settings) || this;
  15585. _this.isOrientationHorizontal = (settings.isOrientationHorizontal == null) ? true : settings.isOrientationHorizontal;
  15586. _this._children = new Array();
  15587. if (settings.children != null) {
  15588. for (var _i = 0, _a = settings.children; _i < _a.length; _i++) {
  15589. var child = _a[_i];
  15590. _this._children.push(child);
  15591. }
  15592. }
  15593. return _this;
  15594. }
  15595. Object.defineProperty(StackPanel.prototype, "isOrientationHorizontal", {
  15596. get: function () {
  15597. return this._isOrientationHorizontal;
  15598. },
  15599. set: function (value) {
  15600. this._isOrientationHorizontal = value;
  15601. },
  15602. enumerable: true,
  15603. configurable: true
  15604. });
  15605. StackPanel.prototype.createVisualTree = function () {
  15606. _super.prototype.createVisualTree.call(this);
  15607. // A StackPanel Control has a Group2D, child of the visualPlaceHolder, which is the Children placeholder.
  15608. // The Children UIElement Tree will be create inside this placeholder.
  15609. this._childrenPlaceholder = new BABYLON.Group2D({ parent: this._visualPlaceholder, id: "StackPanel Children Placeholder of " + this.id });
  15610. var p = this._childrenPlaceholder;
  15611. p.layoutEngine = this.isOrientationHorizontal ? BABYLON.StackPanelLayoutEngine.Horizontal : BABYLON.StackPanelLayoutEngine.Vertical;
  15612. // The UIElement padding properties (padding and paddingAlignment) are bound to the Group2D Children placeholder, we bound to the Margin properties as the Group2D acts as an inner element already, so margin of inner is padding.
  15613. p.dataSource = this;
  15614. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginProperty, "padding", BABYLON.DataBinding.MODE_ONEWAY);
  15615. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginAlignmentProperty, "paddingAlignment", BABYLON.DataBinding.MODE_ONEWAY);
  15616. // The UIElement set the childrenPlaceholder with the visual returned by the renderingTemplate.
  15617. // But it's not the case for a StackPanel, the placeholder of UIElement Children (the content)
  15618. this._visualChildrenPlaceholder = this._childrenPlaceholder;
  15619. };
  15620. Object.defineProperty(StackPanel.prototype, "children", {
  15621. get: function () {
  15622. return this._children;
  15623. },
  15624. enumerable: true,
  15625. configurable: true
  15626. });
  15627. StackPanel.prototype._getChildren = function () {
  15628. return this.children;
  15629. };
  15630. return StackPanel;
  15631. }(BABYLON.UIElement));
  15632. StackPanel.STACKPANEL_PROPCOUNT = BABYLON.UIElement.UIELEMENT_PROPCOUNT + 3;
  15633. __decorate([
  15634. BABYLON.dependencyProperty(StackPanel_1.STACKPANEL_PROPCOUNT + 0, function (pi) { return StackPanel_1.orientationHorizontalProperty = pi; })
  15635. ], StackPanel.prototype, "isOrientationHorizontal", null);
  15636. StackPanel = StackPanel_1 = __decorate([
  15637. BABYLON.className("StackPanel", "BABYLON")
  15638. ], StackPanel);
  15639. BABYLON.StackPanel = StackPanel;
  15640. var DefaultStackPanelRenderingTemplate = DefaultStackPanelRenderingTemplate_1 = (function (_super) {
  15641. __extends(DefaultStackPanelRenderingTemplate, _super);
  15642. function DefaultStackPanelRenderingTemplate() {
  15643. return _super.apply(this, arguments) || this;
  15644. }
  15645. DefaultStackPanelRenderingTemplate.prototype.createVisualTree = function (owner, visualPlaceholder) {
  15646. return { root: visualPlaceholder, contentPlaceholder: visualPlaceholder };
  15647. };
  15648. DefaultStackPanelRenderingTemplate.prototype.attach = function (owner) {
  15649. _super.prototype.attach.call(this, owner);
  15650. };
  15651. return DefaultStackPanelRenderingTemplate;
  15652. }(BABYLON.UIElementRenderingTemplateBase));
  15653. DefaultStackPanelRenderingTemplate = DefaultStackPanelRenderingTemplate_1 = __decorate([
  15654. BABYLON.registerWindowRenderingTemplate("BABYLON.StackPanel", "Default", function () { return new DefaultStackPanelRenderingTemplate_1(); })
  15655. ], DefaultStackPanelRenderingTemplate);
  15656. BABYLON.DefaultStackPanelRenderingTemplate = DefaultStackPanelRenderingTemplate;
  15657. var StackPanel_1, DefaultStackPanelRenderingTemplate_1;
  15658. })(BABYLON || (BABYLON = {}));
  15659. var __extends = (this && this.__extends) || function (d, b) {
  15660. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  15661. function __() { this.constructor = d; }
  15662. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15663. };
  15664. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  15665. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  15666. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  15667. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  15668. return c > 3 && r && Object.defineProperty(target, key, r), r;
  15669. };
  15670. var BABYLON;
  15671. (function (BABYLON) {
  15672. var Control = Control_1 = (function (_super) {
  15673. __extends(Control, _super);
  15674. function Control(settings) {
  15675. return _super.call(this, settings) || this;
  15676. }
  15677. Object.defineProperty(Control.prototype, "background", {
  15678. get: function () {
  15679. if (!this._background) {
  15680. this._background = new BABYLON.ObservableStringDictionary(false);
  15681. }
  15682. return this._background;
  15683. },
  15684. set: function (value) {
  15685. this.background.copyFrom(value);
  15686. },
  15687. enumerable: true,
  15688. configurable: true
  15689. });
  15690. Object.defineProperty(Control.prototype, "border", {
  15691. get: function () {
  15692. return this._border;
  15693. },
  15694. set: function (value) {
  15695. this._border = value;
  15696. },
  15697. enumerable: true,
  15698. configurable: true
  15699. });
  15700. Object.defineProperty(Control.prototype, "borderThickness", {
  15701. get: function () {
  15702. return this._borderThickness;
  15703. },
  15704. set: function (value) {
  15705. this._borderThickness = value;
  15706. },
  15707. enumerable: true,
  15708. configurable: true
  15709. });
  15710. Object.defineProperty(Control.prototype, "fontName", {
  15711. get: function () {
  15712. return this._fontName;
  15713. },
  15714. set: function (value) {
  15715. this._fontName = value;
  15716. },
  15717. enumerable: true,
  15718. configurable: true
  15719. });
  15720. Object.defineProperty(Control.prototype, "foreground", {
  15721. get: function () {
  15722. return this._foreground;
  15723. },
  15724. set: function (value) {
  15725. this._foreground = value;
  15726. },
  15727. enumerable: true,
  15728. configurable: true
  15729. });
  15730. return Control;
  15731. }(BABYLON.UIElement));
  15732. Control.CONTROL_PROPCOUNT = BABYLON.UIElement.UIELEMENT_PROPCOUNT + 5;
  15733. __decorate([
  15734. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 0, function (pi) { return Control_1.backgroundProperty = pi; })
  15735. ], Control.prototype, "background", null);
  15736. __decorate([
  15737. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 1, function (pi) { return Control_1.borderProperty = pi; })
  15738. ], Control.prototype, "border", null);
  15739. __decorate([
  15740. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 2, function (pi) { return Control_1.borderThicknessProperty = pi; })
  15741. ], Control.prototype, "borderThickness", null);
  15742. __decorate([
  15743. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 3, function (pi) { return Control_1.fontNameProperty = pi; })
  15744. ], Control.prototype, "fontName", null);
  15745. __decorate([
  15746. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 4, function (pi) { return Control_1.foregroundProperty = pi; })
  15747. ], Control.prototype, "foreground", null);
  15748. Control = Control_1 = __decorate([
  15749. BABYLON.className("Control", "BABYLON")
  15750. ], Control);
  15751. BABYLON.Control = Control;
  15752. var Control_1;
  15753. })(BABYLON || (BABYLON = {}));
  15754. var __extends = (this && this.__extends) || function (d, b) {
  15755. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  15756. function __() { this.constructor = d; }
  15757. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15758. };
  15759. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  15760. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  15761. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  15762. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  15763. return c > 3 && r && Object.defineProperty(target, key, r), r;
  15764. };
  15765. var BABYLON;
  15766. (function (BABYLON) {
  15767. var ContentControl = ContentControl_1 = (function (_super) {
  15768. __extends(ContentControl, _super);
  15769. function ContentControl(settings) {
  15770. var _this;
  15771. if (!settings) {
  15772. settings = {};
  15773. }
  15774. _this = _super.call(this, settings) || this;
  15775. if (settings.content != null) {
  15776. _this._content = settings.content;
  15777. }
  15778. return _this;
  15779. }
  15780. ContentControl.prototype.dispose = function () {
  15781. if (this.isDisposed) {
  15782. return false;
  15783. }
  15784. if (this.content && this.content.dispose) {
  15785. this.content.dispose();
  15786. this.content = null;
  15787. }
  15788. if (this.__contentUIElement) {
  15789. this.__contentUIElement.dispose();
  15790. this.__contentUIElement = null;
  15791. }
  15792. _super.prototype.dispose.call(this);
  15793. return true;
  15794. };
  15795. Object.defineProperty(ContentControl.prototype, "content", {
  15796. get: function () {
  15797. return this._content;
  15798. },
  15799. set: function (value) {
  15800. this._content = value;
  15801. },
  15802. enumerable: true,
  15803. configurable: true
  15804. });
  15805. Object.defineProperty(ContentControl.prototype, "_contentUIElement", {
  15806. get: function () {
  15807. if (!this.__contentUIElement) {
  15808. this._buildContentUIElement();
  15809. }
  15810. return this.__contentUIElement;
  15811. },
  15812. enumerable: true,
  15813. configurable: true
  15814. });
  15815. ContentControl.prototype._createVisualTree = function () {
  15816. // Base implementation will create the Group2D for the Visual Placeholder and its Visual Tree
  15817. _super.prototype._createVisualTree.call(this);
  15818. // A Content Control has a Group2D, child of the visualPlaceHolder, which is the Content placeholder.
  15819. // The Content UIElement Tree will be create inside this placeholder.
  15820. this._contentPlaceholder = new BABYLON.Group2D({ parent: this._visualPlaceholder, id: "ContentControl Content Placeholder of " + this.id });
  15821. var p = this._contentPlaceholder;
  15822. // The UIElement padding properties (padding and paddingAlignment) are bound to the Group2D Content placeholder, we bound to the Margin properties as the Group2D acts as an inner element already, so margin of inner is padding.
  15823. p.dataSource = this;
  15824. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginProperty, "padding", BABYLON.DataBinding.MODE_ONEWAY);
  15825. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginAlignmentProperty, "paddingAlignment", BABYLON.DataBinding.MODE_ONEWAY);
  15826. // The UIElement set the childrenPlaceholder with the visual returned by the renderingTemplate.
  15827. // But it's not the case for a ContentControl, the placeholder of UIElement Children (the content)
  15828. this._visualChildrenPlaceholder = this._contentPlaceholder;
  15829. };
  15830. ContentControl.prototype._buildContentUIElement = function () {
  15831. var c = this._content;
  15832. this.__contentUIElement = null;
  15833. // Already a UIElement
  15834. if (c instanceof BABYLON.UIElement) {
  15835. this.__contentUIElement = c;
  15836. }
  15837. else if ((typeof c === "string") || (typeof c === "boolean") || (typeof c === "number")) {
  15838. var l = new BABYLON.Label({ parent: this, id: "Content of " + this.id });
  15839. var binding = new BABYLON.DataBinding();
  15840. binding.propertyPathName = "content";
  15841. binding.stringFormat = function (v) { return "" + v; };
  15842. binding.dataSource = this;
  15843. l.createDataBinding(BABYLON.Label.textProperty, binding);
  15844. this.__contentUIElement = l;
  15845. }
  15846. else {
  15847. }
  15848. if (this.__contentUIElement) {
  15849. this.__contentUIElement._patchUIElement(this.ownerWindow, this);
  15850. }
  15851. };
  15852. ContentControl.prototype._getChildren = function () {
  15853. var children = new Array();
  15854. if (this.content) {
  15855. children.push(this._contentUIElement);
  15856. }
  15857. return children;
  15858. };
  15859. return ContentControl;
  15860. }(BABYLON.Control));
  15861. ContentControl.CONTENTCONTROL_PROPCOUNT = BABYLON.Control.CONTROL_PROPCOUNT + 2;
  15862. __decorate([
  15863. BABYLON.dependencyProperty(BABYLON.Control.CONTROL_PROPCOUNT + 0, function (pi) { return ContentControl_1.contentProperty = pi; })
  15864. ], ContentControl.prototype, "content", null);
  15865. ContentControl = ContentControl_1 = __decorate([
  15866. BABYLON.className("ContentControl", "BABYLON")
  15867. ], ContentControl);
  15868. BABYLON.ContentControl = ContentControl;
  15869. var ContentControl_1;
  15870. })(BABYLON || (BABYLON = {}));
  15871. var __extends = (this && this.__extends) || function (d, b) {
  15872. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  15873. function __() { this.constructor = d; }
  15874. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15875. };
  15876. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  15877. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  15878. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  15879. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  15880. return c > 3 && r && Object.defineProperty(target, key, r), r;
  15881. };
  15882. var BABYLON;
  15883. (function (BABYLON) {
  15884. var FocusScopeData = (function () {
  15885. function FocusScopeData(focusScope) {
  15886. this.focusScope = focusScope;
  15887. this.focusedElement = null;
  15888. }
  15889. return FocusScopeData;
  15890. }());
  15891. var FocusManager = (function () {
  15892. function FocusManager() {
  15893. this._focusScopes = new BABYLON.StringDictionary();
  15894. this._rootScope = new FocusScopeData(null);
  15895. this._activeScope = null;
  15896. }
  15897. FocusManager.prototype.setFocusOn = function (el, focusScope) {
  15898. var fsd = (focusScope != null) ? this._focusScopes.getOrAddWithFactory(focusScope.uid, function (k) { return new FocusScopeData(focusScope); }) : this._rootScope;
  15899. if (fsd.focusedElement !== el) {
  15900. // Remove focus from current
  15901. if (fsd.focusedElement) {
  15902. fsd.focusedElement.isFocused = false;
  15903. }
  15904. fsd.focusedElement = el;
  15905. }
  15906. if (this._activeScope !== fsd) {
  15907. this._activeScope = fsd;
  15908. }
  15909. };
  15910. return FocusManager;
  15911. }());
  15912. BABYLON.FocusManager = FocusManager;
  15913. var GUISceneData = (function () {
  15914. function GUISceneData(scene) {
  15915. this.scene = scene;
  15916. this.screenSpaceCanvas = new BABYLON.ScreenSpaceCanvas2D(scene, { id: "GUI Canvas", cachingStrategy: BABYLON.Canvas2D.CACHESTRATEGY_DONTCACHE });
  15917. this.focusManager = new FocusManager();
  15918. }
  15919. return GUISceneData;
  15920. }());
  15921. var Window = Window_1 = (function (_super) {
  15922. __extends(Window, _super);
  15923. function Window(scene, settings) {
  15924. var _this;
  15925. if (!settings) {
  15926. settings = {};
  15927. }
  15928. _this = _super.call(this, settings) || this;
  15929. // Per default a Window is focus scope
  15930. _this.isFocusScope = true;
  15931. _this.isActive = false;
  15932. if (!_this._UIElementVisualToBuildList) {
  15933. _this._UIElementVisualToBuildList = new Array();
  15934. }
  15935. // Patch the owner and also the parent property through the whole tree
  15936. _this._patchUIElement(_this, null);
  15937. // Screen Space UI
  15938. if (!settings.worldPosition && !settings.worldRotation) {
  15939. _this._sceneData = Window_1.getSceneData(scene);
  15940. _this._canvas = _this._sceneData.screenSpaceCanvas;
  15941. _this._isWorldSpaceCanvas = false;
  15942. _this._left = (settings.left != null) ? settings.left : 0;
  15943. _this._bottom = (settings.bottom != null) ? settings.bottom : 0;
  15944. }
  15945. else {
  15946. var w = (settings.width == null) ? 100 : settings.width;
  15947. var h = (settings.height == null) ? 100 : settings.height;
  15948. var wpos = (settings.worldPosition == null) ? BABYLON.Vector3.Zero() : settings.worldPosition;
  15949. var wrot = (settings.worldRotation == null) ? BABYLON.Quaternion.Identity() : settings.worldRotation;
  15950. _this._canvas = new BABYLON.WorldSpaceCanvas2D(scene, new BABYLON.Size(w, h), { id: "GUI Canvas", cachingStrategy: BABYLON.Canvas2D.CACHESTRATEGY_DONTCACHE, worldPosition: wpos, worldRotation: wrot });
  15951. _this._isWorldSpaceCanvas = true;
  15952. }
  15953. _this._renderObserver = _this._canvas.renderObservable.add(function (e, s) { return _this._canvasPreRender(); }, BABYLON.Canvas2D.RENDEROBSERVABLE_PRE);
  15954. _this._disposeObserver = _this._canvas.disposeObservable.add(function (e, s) { return _this._canvasDisposed(); });
  15955. _this._canvas.propertyChanged.add(function (e, s) {
  15956. if (e.propertyName === "overPrim") {
  15957. _this._overPrimChanged(e.oldValue, e.newValue);
  15958. }
  15959. });
  15960. _this._mouseOverUIElement = null;
  15961. return _this;
  15962. }
  15963. Object.defineProperty(Window.prototype, "canvas", {
  15964. get: function () {
  15965. return this._canvas;
  15966. },
  15967. enumerable: true,
  15968. configurable: true
  15969. });
  15970. Object.defineProperty(Window.prototype, "left", {
  15971. get: function () {
  15972. return this._left;
  15973. },
  15974. set: function (value) {
  15975. var old = new BABYLON.Vector2(this._left, this._bottom);
  15976. this._left = value;
  15977. this.onPropertyChanged("_position", old, this._position);
  15978. },
  15979. enumerable: true,
  15980. configurable: true
  15981. });
  15982. Object.defineProperty(Window.prototype, "bottom", {
  15983. get: function () {
  15984. return this._bottom;
  15985. },
  15986. set: function (value) {
  15987. var old = new BABYLON.Vector2(this._left, this._bottom);
  15988. this._bottom = value;
  15989. this.onPropertyChanged("_position", old, this._position);
  15990. },
  15991. enumerable: true,
  15992. configurable: true
  15993. });
  15994. Object.defineProperty(Window.prototype, "position", {
  15995. get: function () {
  15996. return this._position;
  15997. },
  15998. set: function (value) {
  15999. this._left = value.x;
  16000. this._bottom = value.y;
  16001. },
  16002. enumerable: true,
  16003. configurable: true
  16004. });
  16005. Object.defineProperty(Window.prototype, "isActive", {
  16006. get: function () {
  16007. return this._isActive;
  16008. },
  16009. set: function (value) {
  16010. this._isActive = value;
  16011. },
  16012. enumerable: true,
  16013. configurable: true
  16014. });
  16015. Object.defineProperty(Window.prototype, "focusManager", {
  16016. get: function () {
  16017. return this._sceneData.focusManager;
  16018. },
  16019. enumerable: true,
  16020. configurable: true
  16021. });
  16022. Object.defineProperty(Window.prototype, "_position", {
  16023. get: function () {
  16024. return new BABYLON.Vector2(this.left, this.bottom);
  16025. },
  16026. enumerable: true,
  16027. configurable: true
  16028. });
  16029. Window.prototype.createVisualTree = function () {
  16030. _super.prototype.createVisualTree.call(this);
  16031. var p = this._visualPlaceholder;
  16032. p.createSimpleDataBinding(BABYLON.Group2D.positionProperty, "position");
  16033. };
  16034. Window.prototype._registerVisualToBuild = function (uiel) {
  16035. if (uiel._isFlagSet(BABYLON.UIElement.flagVisualToBuild)) {
  16036. return;
  16037. }
  16038. if (!this._UIElementVisualToBuildList) {
  16039. this._UIElementVisualToBuildList = new Array();
  16040. }
  16041. this._UIElementVisualToBuildList.push(uiel);
  16042. uiel._setFlags(BABYLON.UIElement.flagVisualToBuild);
  16043. };
  16044. Window.prototype._overPrimChanged = function (oldPrim, newPrim) {
  16045. var curOverEl = this._mouseOverUIElement;
  16046. var newOverEl = null;
  16047. var curGroup = newPrim ? newPrim.traverseUp(function (p) { return p instanceof BABYLON.Group2D; }) : null;
  16048. while (curGroup) {
  16049. var uiel = curGroup.getExternalData("_GUIOwnerElement_");
  16050. if (uiel) {
  16051. newOverEl = uiel;
  16052. break;
  16053. }
  16054. curGroup = curGroup.parent ? curGroup.parent.traverseUp(function (p) { return p instanceof BABYLON.Group2D; }) : null;
  16055. }
  16056. if (curOverEl === newOverEl) {
  16057. return;
  16058. }
  16059. if (curOverEl) {
  16060. curOverEl.isMouseOver = false;
  16061. }
  16062. if (newOverEl) {
  16063. newOverEl.isMouseOver = true;
  16064. }
  16065. this._mouseOverUIElement = newOverEl;
  16066. };
  16067. Window.prototype._canvasPreRender = function () {
  16068. // Check if we have visual to create
  16069. if (this._UIElementVisualToBuildList.length > 0) {
  16070. // Sort the UI Element to get the highest (so lowest hierarchy depth) in the hierarchy tree first
  16071. var sortedElementList = this._UIElementVisualToBuildList.sort(function (a, b) { return a.hierarchyDepth - b.hierarchyDepth; });
  16072. for (var _i = 0, sortedElementList_1 = sortedElementList; _i < sortedElementList_1.length; _i++) {
  16073. var el = sortedElementList_1[_i];
  16074. el._createVisualTree();
  16075. }
  16076. this._UIElementVisualToBuildList.splice(0);
  16077. }
  16078. };
  16079. Window.prototype._canvasDisposed = function () {
  16080. this._canvas.disposeObservable.remove(this._disposeObserver);
  16081. this._canvas.renderObservable.remove(this._renderObserver);
  16082. };
  16083. Window.getSceneData = function (scene) {
  16084. return Window_1._sceneData.getOrAddWithFactory(scene.uid, function (k) { return new GUISceneData(scene); });
  16085. };
  16086. return Window;
  16087. }(BABYLON.ContentControl));
  16088. Window.WINDOW_PROPCOUNT = BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 4;
  16089. Window._sceneData = new BABYLON.StringDictionary();
  16090. __decorate([
  16091. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 0, function (pi) { return Window_1.leftProperty = pi; })
  16092. ], Window.prototype, "left", null);
  16093. __decorate([
  16094. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 1, function (pi) { return Window_1.bottomProperty = pi; })
  16095. ], Window.prototype, "bottom", null);
  16096. __decorate([
  16097. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 2, function (pi) { return Window_1.positionProperty = pi; })
  16098. ], Window.prototype, "position", null);
  16099. __decorate([
  16100. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 3, function (pi) { return Window_1.isActiveProperty = pi; })
  16101. ], Window.prototype, "isActive", null);
  16102. Window = Window_1 = __decorate([
  16103. BABYLON.className("Window", "BABYLON")
  16104. ], Window);
  16105. BABYLON.Window = Window;
  16106. var DefaultWindowRenderingTemplate = DefaultWindowRenderingTemplate_1 = (function (_super) {
  16107. __extends(DefaultWindowRenderingTemplate, _super);
  16108. function DefaultWindowRenderingTemplate() {
  16109. return _super.apply(this, arguments) || this;
  16110. }
  16111. DefaultWindowRenderingTemplate.prototype.createVisualTree = function (owner, visualPlaceholder) {
  16112. var r = new BABYLON.Rectangle2D({ parent: visualPlaceholder, fill: "#808080FF" });
  16113. return { root: r, contentPlaceholder: r };
  16114. };
  16115. return DefaultWindowRenderingTemplate;
  16116. }(BABYLON.UIElementRenderingTemplateBase));
  16117. DefaultWindowRenderingTemplate = DefaultWindowRenderingTemplate_1 = __decorate([
  16118. BABYLON.registerWindowRenderingTemplate("BABYLON.Window", "Default", function () { return new DefaultWindowRenderingTemplate_1(); })
  16119. ], DefaultWindowRenderingTemplate);
  16120. BABYLON.DefaultWindowRenderingTemplate = DefaultWindowRenderingTemplate;
  16121. var Window_1, DefaultWindowRenderingTemplate_1;
  16122. })(BABYLON || (BABYLON = {}));
  16123. var __extends = (this && this.__extends) || function (d, b) {
  16124. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  16125. function __() { this.constructor = d; }
  16126. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16127. };
  16128. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  16129. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  16130. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  16131. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  16132. return c > 3 && r && Object.defineProperty(target, key, r), r;
  16133. };
  16134. var BABYLON;
  16135. (function (BABYLON) {
  16136. var Label = Label_1 = (function (_super) {
  16137. __extends(Label, _super);
  16138. function Label(settings) {
  16139. var _this;
  16140. if (!settings) {
  16141. settings = {};
  16142. }
  16143. _this = _super.call(this, settings) || this;
  16144. if (settings.text != null) {
  16145. _this.text = settings.text;
  16146. }
  16147. return _this;
  16148. }
  16149. Object.defineProperty(Label.prototype, "_position", {
  16150. get: function () {
  16151. return BABYLON.Vector2.Zero();
  16152. },
  16153. enumerable: true,
  16154. configurable: true
  16155. });
  16156. Label.prototype._getChildren = function () {
  16157. return Label_1._emptyArray;
  16158. };
  16159. Label.prototype.createVisualTree = function () {
  16160. _super.prototype.createVisualTree.call(this);
  16161. var p = this._visualChildrenPlaceholder;
  16162. };
  16163. Object.defineProperty(Label.prototype, "text", {
  16164. get: function () {
  16165. return this._text;
  16166. },
  16167. set: function (value) {
  16168. this._text = value;
  16169. },
  16170. enumerable: true,
  16171. configurable: true
  16172. });
  16173. return Label;
  16174. }(BABYLON.Control));
  16175. Label._emptyArray = new Array();
  16176. __decorate([
  16177. BABYLON.dependencyProperty(BABYLON.Control.CONTROL_PROPCOUNT + 0, function (pi) { return Label_1.textProperty = pi; })
  16178. ], Label.prototype, "text", null);
  16179. Label = Label_1 = __decorate([
  16180. BABYLON.className("Label", "BABYLON")
  16181. ], Label);
  16182. BABYLON.Label = Label;
  16183. var DefaultLabelRenderingTemplate = DefaultLabelRenderingTemplate_1 = (function (_super) {
  16184. __extends(DefaultLabelRenderingTemplate, _super);
  16185. function DefaultLabelRenderingTemplate() {
  16186. return _super.apply(this, arguments) || this;
  16187. }
  16188. DefaultLabelRenderingTemplate.prototype.createVisualTree = function (owner, visualPlaceholder) {
  16189. var r = new BABYLON.Text2D("", { parent: visualPlaceholder });
  16190. r.createSimpleDataBinding(BABYLON.Text2D.textProperty, "text");
  16191. r.dataSource = owner;
  16192. return { root: r, contentPlaceholder: r };
  16193. };
  16194. return DefaultLabelRenderingTemplate;
  16195. }(BABYLON.UIElementRenderingTemplateBase));
  16196. DefaultLabelRenderingTemplate = DefaultLabelRenderingTemplate_1 = __decorate([
  16197. BABYLON.registerWindowRenderingTemplate("BABYLON.Label", "Default", function () { return new DefaultLabelRenderingTemplate_1(); })
  16198. ], DefaultLabelRenderingTemplate);
  16199. BABYLON.DefaultLabelRenderingTemplate = DefaultLabelRenderingTemplate;
  16200. var Label_1, DefaultLabelRenderingTemplate_1;
  16201. })(BABYLON || (BABYLON = {}));
  16202. var __extends = (this && this.__extends) || function (d, b) {
  16203. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  16204. function __() { this.constructor = d; }
  16205. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16206. };
  16207. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  16208. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  16209. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  16210. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  16211. return c > 3 && r && Object.defineProperty(target, key, r), r;
  16212. };
  16213. var BABYLON;
  16214. (function (BABYLON) {
  16215. var Button = Button_1 = (function (_super) {
  16216. __extends(Button, _super);
  16217. function Button(settings) {
  16218. var _this;
  16219. if (!settings) {
  16220. settings = {};
  16221. }
  16222. _this = _super.call(this, settings) || this;
  16223. if (settings.paddingAlignment == null) {
  16224. _this.paddingAlignment.horizontal = BABYLON.PrimitiveAlignment.AlignCenter;
  16225. _this.paddingAlignment.vertical = BABYLON.PrimitiveAlignment.AlignCenter;
  16226. }
  16227. _this._normalStateBackground = new BABYLON.ObservableStringDictionary(false);
  16228. _this._normalStateBorder = new BABYLON.ObservableStringDictionary(false);
  16229. _this._defaultStateBackground = new BABYLON.ObservableStringDictionary(false);
  16230. _this._defaultStateBorder = new BABYLON.ObservableStringDictionary(false);
  16231. _this._normalStateBackground.add(BABYLON.UIElement.enabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#337AB7FF"));
  16232. _this._normalStateBackground.add(BABYLON.UIElement.disabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#7BA9D0FF"));
  16233. _this._normalStateBackground.add(BABYLON.UIElement.mouseOverState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#286090FF"));
  16234. _this._normalStateBackground.add(Button_1.pushedState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#1E496EFF"));
  16235. _this._normalStateBorder.add(BABYLON.UIElement.enabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#2E6DA4FF"));
  16236. _this._normalStateBorder.add(BABYLON.UIElement.disabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#77A0C4FF"));
  16237. _this._normalStateBorder.add(BABYLON.UIElement.mouseOverState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#204D74FF"));
  16238. _this._normalStateBorder.add(Button_1.pushedState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#2E5D9EFF"));
  16239. _this._defaultStateBackground.add(BABYLON.UIElement.enabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#FFFFFFFF"));
  16240. _this._defaultStateBackground.add(BABYLON.UIElement.disabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#FFFFFFFF"));
  16241. _this._defaultStateBackground.add(BABYLON.UIElement.mouseOverState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#E6E6E6FF"));
  16242. _this._defaultStateBackground.add(Button_1.pushedState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#D4D4D4FF"));
  16243. _this._defaultStateBorder.add(BABYLON.UIElement.enabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#CCCCCCFF"));
  16244. _this._defaultStateBorder.add(BABYLON.UIElement.disabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#DEDEDEFF"));
  16245. _this._defaultStateBorder.add(BABYLON.UIElement.mouseOverState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#ADADADFF"));
  16246. _this._defaultStateBorder.add(Button_1.pushedState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#6C8EC5FF"));
  16247. return _this;
  16248. }
  16249. Object.defineProperty(Button, "pushedState", {
  16250. get: function () {
  16251. return Button_1._pushedState;
  16252. },
  16253. enumerable: true,
  16254. configurable: true
  16255. });
  16256. Object.defineProperty(Button.prototype, "isPushed", {
  16257. get: function () {
  16258. return this._isPushed;
  16259. },
  16260. set: function (value) {
  16261. this._isPushed = value;
  16262. },
  16263. enumerable: true,
  16264. configurable: true
  16265. });
  16266. Object.defineProperty(Button.prototype, "isDefault", {
  16267. get: function () {
  16268. return this._isDefault;
  16269. },
  16270. set: function (value) {
  16271. this._isDefault = value;
  16272. },
  16273. enumerable: true,
  16274. configurable: true
  16275. });
  16276. Object.defineProperty(Button.prototype, "isOutline", {
  16277. get: function () {
  16278. return this._isOutline;
  16279. },
  16280. set: function (value) {
  16281. this._isOutline = value;
  16282. },
  16283. enumerable: true,
  16284. configurable: true
  16285. });
  16286. Object.defineProperty(Button.prototype, "clickObservable", {
  16287. get: function () {
  16288. if (!this._clickObservable) {
  16289. this._clickObservable = new BABYLON.Observable();
  16290. }
  16291. return this._clickObservable;
  16292. },
  16293. enumerable: true,
  16294. configurable: true
  16295. });
  16296. Button.prototype._raiseClick = function () {
  16297. if (this._clickObservable && this._clickObservable.hasObservers()) {
  16298. this._clickObservable.notifyObservers(this);
  16299. }
  16300. };
  16301. Button.prototype.createVisualTree = function () {
  16302. var _this = this;
  16303. _super.prototype.createVisualTree.call(this);
  16304. var p = this._visualPlaceholder;
  16305. p.pointerEventObservable.add(function (e, s) {
  16306. // check if input must be discarded
  16307. if (!_this.isVisible || !_this.isEnabled) {
  16308. return;
  16309. }
  16310. // We reject an event coming from the placeholder because it means it's on an empty spot, so it's not valid.
  16311. if (e.relatedTarget === _this._visualPlaceholder) {
  16312. return;
  16313. }
  16314. if (s.mask === BABYLON.PrimitivePointerInfo.PointerUp) {
  16315. _this._raiseClick();
  16316. _this.isPushed = false;
  16317. }
  16318. else if (s.mask === BABYLON.PrimitivePointerInfo.PointerDown) {
  16319. _this.isPushed = true;
  16320. _this.isFocused = true;
  16321. }
  16322. }, BABYLON.PrimitivePointerInfo.PointerUp | BABYLON.PrimitivePointerInfo.PointerDown);
  16323. };
  16324. Object.defineProperty(Button.prototype, "normalStateBackground", {
  16325. get: function () {
  16326. return this._normalStateBackground;
  16327. },
  16328. enumerable: true,
  16329. configurable: true
  16330. });
  16331. Object.defineProperty(Button.prototype, "defaultStateBackground", {
  16332. get: function () {
  16333. return this._defaultStateBackground;
  16334. },
  16335. enumerable: true,
  16336. configurable: true
  16337. });
  16338. Object.defineProperty(Button.prototype, "normalStateBorder", {
  16339. get: function () {
  16340. return this._normalStateBorder;
  16341. },
  16342. enumerable: true,
  16343. configurable: true
  16344. });
  16345. Object.defineProperty(Button.prototype, "defaultStateBorder", {
  16346. get: function () {
  16347. return this._defaultStateBorder;
  16348. },
  16349. enumerable: true,
  16350. configurable: true
  16351. });
  16352. return Button;
  16353. }(BABYLON.ContentControl));
  16354. Button.BUTTON_PROPCOUNT = BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 3;
  16355. Button._pushedState = "Pushed";
  16356. __decorate([
  16357. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTROL_PROPCOUNT + 0, function (pi) { return Button_1.isPushedProperty = pi; })
  16358. ], Button.prototype, "isPushed", null);
  16359. __decorate([
  16360. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTROL_PROPCOUNT + 1, function (pi) { return Button_1.isDefaultProperty = pi; })
  16361. ], Button.prototype, "isDefault", null);
  16362. __decorate([
  16363. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTROL_PROPCOUNT + 2, function (pi) { return Button_1.isOutlineProperty = pi; })
  16364. ], Button.prototype, "isOutline", null);
  16365. Button = Button_1 = __decorate([
  16366. BABYLON.className("Button", "BABYLON")
  16367. ], Button);
  16368. BABYLON.Button = Button;
  16369. var DefaultButtonRenderingTemplate = DefaultButtonRenderingTemplate_1 = (function (_super) {
  16370. __extends(DefaultButtonRenderingTemplate, _super);
  16371. function DefaultButtonRenderingTemplate() {
  16372. return _super.apply(this, arguments) || this;
  16373. }
  16374. DefaultButtonRenderingTemplate.prototype.createVisualTree = function (owner, visualPlaceholder) {
  16375. this._rect = new BABYLON.Rectangle2D({ parent: visualPlaceholder, fill: "#FF8080FF", border: "#FF8080FF", roundRadius: 10, borderThickness: 2 });
  16376. this.stateChange();
  16377. return { root: this._rect, contentPlaceholder: this._rect };
  16378. };
  16379. DefaultButtonRenderingTemplate.prototype.attach = function (owner) {
  16380. var _this = this;
  16381. _super.prototype.attach.call(this, owner);
  16382. this.owner.propertyChanged.add(function (e, s) { return _this.stateChange(); }, BABYLON.UIElement.isEnabledProperty.flagId |
  16383. BABYLON.UIElement.isFocusedProperty.flagId |
  16384. BABYLON.UIElement.isMouseOverProperty.flagId |
  16385. Button.isDefaultProperty.flagId |
  16386. Button.isOutlineProperty.flagId |
  16387. Button.isPushedProperty.flagId);
  16388. // Register for brush change and update the Visual
  16389. var button = owner;
  16390. button.normalStateBackground.dictionaryChanged.add(function (e, c) { return _this.stateChange(); });
  16391. button.normalStateBorder.dictionaryChanged.add(function (e, c) { return _this.stateChange(); });
  16392. button.defaultStateBackground.dictionaryChanged.add(function (e, c) { return _this.stateChange(); });
  16393. button.defaultStateBorder.dictionaryChanged.add(function (e, c) { return _this.stateChange(); });
  16394. };
  16395. DefaultButtonRenderingTemplate.prototype.stateChange = function () {
  16396. //console.log("state changed");
  16397. var b = this.owner;
  16398. var state = BABYLON.UIElement.enabledState;
  16399. var bg = b.isDefault ? b.defaultStateBackground.get(state) : b.normalStateBackground.get(state);
  16400. var bd = b.isDefault ? b.defaultStateBorder.get(state) : b.normalStateBorder.get(state);
  16401. if (b.isPushed) {
  16402. state = Button.pushedState;
  16403. if (b.isDefault) {
  16404. bg = b.defaultStateBackground.get(state);
  16405. bd = b.defaultStateBorder.get(state);
  16406. }
  16407. else {
  16408. bg = b.normalStateBackground.get(state);
  16409. bd = b.normalStateBorder.get(state);
  16410. }
  16411. }
  16412. else if (b.isMouseOver) {
  16413. state = BABYLON.UIElement.mouseOverState;
  16414. if (b.isDefault) {
  16415. bg = b.defaultStateBackground.get(state);
  16416. bd = b.defaultStateBorder.get(state);
  16417. }
  16418. else {
  16419. bg = b.normalStateBackground.get(state);
  16420. bd = b.normalStateBorder.get(state);
  16421. }
  16422. }
  16423. else if (!b.isEnabled) {
  16424. state = BABYLON.UIElement.disabledState;
  16425. if (b.isDefault) {
  16426. bg = b.defaultStateBackground.get(state);
  16427. bd = b.defaultStateBorder.get(state);
  16428. }
  16429. else {
  16430. bg = b.normalStateBackground.get(state);
  16431. bd = b.normalStateBorder.get(state);
  16432. }
  16433. }
  16434. this._rect.fill = bg;
  16435. this._rect.border = bd;
  16436. };
  16437. return DefaultButtonRenderingTemplate;
  16438. }(BABYLON.UIElementRenderingTemplateBase));
  16439. DefaultButtonRenderingTemplate = DefaultButtonRenderingTemplate_1 = __decorate([
  16440. BABYLON.registerWindowRenderingTemplate("BABYLON.Button", "Default", function () { return new DefaultButtonRenderingTemplate_1(); })
  16441. ], DefaultButtonRenderingTemplate);
  16442. BABYLON.DefaultButtonRenderingTemplate = DefaultButtonRenderingTemplate;
  16443. var Button_1, DefaultButtonRenderingTemplate_1;
  16444. })(BABYLON || (BABYLON = {}));