babylon.canvas2d.js 750 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216
  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;\nuniform bool alphaTest;\nuniform sampler2D diffuseSampler;\nvoid main(void) {\nvec4 color=texture2D(diffuseSampler,vUV);\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;\natt vec2 scaleFactor;\natt vec2 textureSize;\n\natt vec3 properties;\natt vec2 zBias;\natt vec4 transformX;\natt vec4 transformY;\natt float opacity;\n\n\nvarying vec2 vUV;\nvarying float vOpacity;\nvoid main(void) {\nvec2 pos2;\n\nvec2 off=vec2(0.0,0.0);\nvec2 sfSizeUV=sizeUV*scaleFactor;\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*sfSizeUV.x)+off.x,topLeftUV.y-off.y);\n}\n\nelse if (index == 1.0) {\npos2=vec2(0.0,1.0);\nvUV=vec2(topLeftUV.x+(frame*sfSizeUV.x)+off.x,(topLeftUV.y+sfSizeUV.y));\n}\n\nelse if (index == 2.0) {\npos2=vec2( 1.0,1.0);\nvUV=vec2(topLeftUV.x+sfSizeUV.x+(frame*sfSizeUV.x),(topLeftUV.y+sfSizeUV.y));\n}\n\nelse if (index == 3.0) {\npos2=vec2( 1.0,0.0);\nvUV=vec2(topLeftUV.x+sfSizeUV.x+(frame*sfSizeUV.x),topLeftUV.y-off.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}\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 BABYLON;
  931. (function (BABYLON) {
  932. /**
  933. * Stores 2D Bounding Information.
  934. * This class handles a circle area and a bounding rectangle one.
  935. */
  936. var BoundingInfo2D = (function () {
  937. function BoundingInfo2D() {
  938. this.radius = 0;
  939. this.center = BABYLON.Vector2.Zero();
  940. this.extent = BABYLON.Vector2.Zero();
  941. }
  942. /**
  943. * Create a BoundingInfo2D object from a given size
  944. * @param size the size that will be used to set the extend, radius will be computed from it.
  945. */
  946. BoundingInfo2D.CreateFromSize = function (size) {
  947. var r = new BoundingInfo2D();
  948. BoundingInfo2D.CreateFromSizeToRef(size, r);
  949. return r;
  950. };
  951. /**
  952. * Create a BoundingInfo2D object from a given radius
  953. * @param radius the radius to use, the extent will be computed from it.
  954. */
  955. BoundingInfo2D.CreateFromRadius = function (radius) {
  956. var r = new BoundingInfo2D();
  957. BoundingInfo2D.CreateFromRadiusToRef(radius, r);
  958. return r;
  959. };
  960. /**
  961. * Create a BoundingInfo2D object from a list of points.
  962. * The resulted object will be the smallest bounding area that includes all the given points.
  963. * @param points an array of points to compute the bounding object from.
  964. */
  965. BoundingInfo2D.CreateFromPoints = function (points) {
  966. var r = new BoundingInfo2D();
  967. BoundingInfo2D.CreateFromPointsToRef(points, r);
  968. return r;
  969. };
  970. /**
  971. * Update a BoundingInfo2D object using the given Size as input
  972. * @param size the bounding data will be computed from this size.
  973. * @param b must be a valid/allocated object, it will contain the result of the operation
  974. */
  975. BoundingInfo2D.CreateFromSizeToRef = function (size, b) {
  976. if (!size) {
  977. size = BABYLON.Size.Zero();
  978. }
  979. b.center.x = +size.width / 2;
  980. b.center.y = +size.height / 2;
  981. b.extent.x = b.center.x;
  982. b.extent.y = b.center.y;
  983. b.radius = b.extent.length();
  984. };
  985. /**
  986. * Update a BoundingInfo2D object using the given radius as input
  987. * @param radius the bounding data will be computed from this radius
  988. * @param b must be a valid/allocated object, it will contain the result of the operation
  989. */
  990. BoundingInfo2D.CreateFromRadiusToRef = function (radius, b) {
  991. b.center.x = b.center.y = 0;
  992. var r = +radius;
  993. b.extent.x = r;
  994. b.extent.y = r;
  995. b.radius = r;
  996. };
  997. /**
  998. * Update a BoundingInfo2D object using the given points array as input
  999. * @param points the point array to use to update the bounding data
  1000. * @param b must be a valid/allocated object, it will contain the result of the operation
  1001. */
  1002. BoundingInfo2D.CreateFromPointsToRef = function (points, b) {
  1003. var xmin = Number.MAX_VALUE, ymin = Number.MAX_VALUE, xmax = Number.MIN_VALUE, ymax = Number.MIN_VALUE;
  1004. for (var _i = 0, points_1 = points; _i < points_1.length; _i++) {
  1005. var p = points_1[_i];
  1006. xmin = Math.min(p.x, xmin);
  1007. xmax = Math.max(p.x, xmax);
  1008. ymin = Math.min(p.y, ymin);
  1009. ymax = Math.max(p.y, ymax);
  1010. }
  1011. BoundingInfo2D.CreateFromMinMaxToRef(xmin, xmax, ymin, ymax, b);
  1012. };
  1013. /**
  1014. * Update a BoundingInfo2D object using the given min/max values as input
  1015. * @param xmin the smallest x coordinate
  1016. * @param xmax the biggest x coordinate
  1017. * @param ymin the smallest y coordinate
  1018. * @param ymax the buggest y coordinate
  1019. * @param b must be a valid/allocated object, it will contain the result of the operation
  1020. */
  1021. BoundingInfo2D.CreateFromMinMaxToRef = function (xmin, xmax, ymin, ymax, b) {
  1022. var w = xmax - xmin;
  1023. var h = ymax - ymin;
  1024. b.center = new BABYLON.Vector2(xmin + w / 2, ymin + h / 2);
  1025. b.extent = new BABYLON.Vector2(xmax - b.center.x, ymax - b.center.y);
  1026. b.radius = b.extent.length();
  1027. };
  1028. /**
  1029. * Duplicate this instance and return a new one
  1030. * @return the duplicated instance
  1031. */
  1032. BoundingInfo2D.prototype.clone = function () {
  1033. var r = new BoundingInfo2D();
  1034. r.center = this.center.clone();
  1035. r.radius = this.radius;
  1036. r.extent = this.extent.clone();
  1037. return r;
  1038. };
  1039. BoundingInfo2D.prototype.clear = function () {
  1040. this.center.copyFromFloats(0, 0);
  1041. this.radius = 0;
  1042. this.extent.copyFromFloats(0, 0);
  1043. };
  1044. BoundingInfo2D.prototype.copyFrom = function (src) {
  1045. this.center.copyFrom(src.center);
  1046. this.radius = src.radius;
  1047. this.extent.copyFrom(src.extent);
  1048. };
  1049. /**
  1050. * return the max extend of the bounding info
  1051. */
  1052. BoundingInfo2D.prototype.max = function () {
  1053. var r = BABYLON.Vector2.Zero();
  1054. this.maxToRef(r);
  1055. return r;
  1056. };
  1057. /**
  1058. * Update a vector2 with the max extend of the bounding info
  1059. * @param result must be a valid/allocated vector2 that will contain the result of the operation
  1060. */
  1061. BoundingInfo2D.prototype.maxToRef = function (result) {
  1062. result.x = this.center.x + this.extent.x;
  1063. result.y = this.center.y + this.extent.y;
  1064. };
  1065. /**
  1066. * Apply a transformation matrix to this BoundingInfo2D and return a new instance containing the result
  1067. * @param matrix the transformation matrix to apply
  1068. * @return the new instance containing the result of the transformation applied on this BoundingInfo2D
  1069. */
  1070. BoundingInfo2D.prototype.transform = function (matrix) {
  1071. var r = new BoundingInfo2D();
  1072. this.transformToRef(matrix, r);
  1073. return r;
  1074. };
  1075. /**
  1076. * Compute the union of this BoundingInfo2D with a given one, returns a new BoundingInfo2D as a result
  1077. * @param other the second BoundingInfo2D to compute the union with this one
  1078. * @return a new instance containing the result of the union
  1079. */
  1080. BoundingInfo2D.prototype.union = function (other) {
  1081. var r = new BoundingInfo2D();
  1082. this.unionToRef(other, r);
  1083. return r;
  1084. };
  1085. /**
  1086. * Transform this BoundingInfo2D with a given matrix and store the result in an existing BoundingInfo2D instance.
  1087. * 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.
  1088. * @param matrix The matrix to use to compute the transformation
  1089. * @param result A VALID (i.e. allocated) BoundingInfo2D object where the result will be stored
  1090. */
  1091. BoundingInfo2D.prototype.transformToRef = function (matrix, result) {
  1092. // Construct a bounding box based on the extent values
  1093. var p = BoundingInfo2D._transform;
  1094. p[0].x = this.center.x + this.extent.x;
  1095. p[0].y = this.center.y + this.extent.y;
  1096. p[1].x = this.center.x + this.extent.x;
  1097. p[1].y = this.center.y - this.extent.y;
  1098. p[2].x = this.center.x - this.extent.x;
  1099. p[2].y = this.center.y - this.extent.y;
  1100. p[3].x = this.center.x - this.extent.x;
  1101. p[3].y = this.center.y + this.extent.y;
  1102. // Transform the four points of the bounding box with the matrix
  1103. for (var i = 0; i < 4; i++) {
  1104. BABYLON.Vector2.TransformToRef(p[i], matrix, p[i]);
  1105. }
  1106. BoundingInfo2D.CreateFromPointsToRef(p, result);
  1107. };
  1108. /**
  1109. * Compute the union of this BoundingInfo2D with another one and store the result in a third valid BoundingInfo2D object
  1110. * 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.
  1111. * @param other the second object used to compute the union
  1112. * @param result a VALID BoundingInfo2D instance (i.e. allocated) where the result will be stored
  1113. */
  1114. BoundingInfo2D.prototype.unionToRef = function (other, result) {
  1115. var xmax = Math.max(this.center.x + this.extent.x, other.center.x + other.extent.x);
  1116. var ymax = Math.max(this.center.y + this.extent.y, other.center.y + other.extent.y);
  1117. var xmin = Math.min(this.center.x - this.extent.x, other.center.x - other.extent.x);
  1118. var ymin = Math.min(this.center.y - this.extent.y, other.center.y - other.extent.y);
  1119. BoundingInfo2D.CreateFromMinMaxToRef(xmin, xmax, ymin, ymax, result);
  1120. };
  1121. /**
  1122. * Check if the given point is inside the BoundingInfo.
  1123. * The test is first made on the radius, then inside the rectangle described by the extent
  1124. * @param pickPosition the position to test
  1125. * @return true if the point is inside, false otherwise
  1126. */
  1127. BoundingInfo2D.prototype.doesIntersect = function (pickPosition) {
  1128. // is it inside the radius?
  1129. var pickLocal = pickPosition.subtract(this.center);
  1130. if (pickLocal.lengthSquared() <= (this.radius * this.radius)) {
  1131. // is it inside the rectangle?
  1132. return ((Math.abs(pickLocal.x) <= this.extent.x) && (Math.abs(pickLocal.y) <= this.extent.y));
  1133. }
  1134. return false;
  1135. };
  1136. return BoundingInfo2D;
  1137. }());
  1138. BoundingInfo2D._transform = new Array(BABYLON.Vector2.Zero(), BABYLON.Vector2.Zero(), BABYLON.Vector2.Zero(), BABYLON.Vector2.Zero());
  1139. BABYLON.BoundingInfo2D = BoundingInfo2D;
  1140. })(BABYLON || (BABYLON = {}));
  1141. //# sourceMappingURL=babylon.bounding2d.js.map
  1142. var __extends = (this && this.__extends) || function (d, b) {
  1143. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  1144. function __() { this.constructor = d; }
  1145. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1146. };
  1147. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  1148. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  1149. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  1150. 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;
  1151. return c > 3 && r && Object.defineProperty(target, key, r), r;
  1152. };
  1153. var BABYLON;
  1154. (function (BABYLON) {
  1155. var LayoutEngineBase = (function () {
  1156. function LayoutEngineBase() {
  1157. this.layoutDirtyOnPropertyChangedMask = 0;
  1158. }
  1159. LayoutEngineBase.prototype.updateLayout = function (prim) {
  1160. };
  1161. Object.defineProperty(LayoutEngineBase.prototype, "isChildPositionAllowed", {
  1162. get: function () {
  1163. return false;
  1164. },
  1165. enumerable: true,
  1166. configurable: true
  1167. });
  1168. LayoutEngineBase.prototype.isLocked = function () {
  1169. return this._isLocked;
  1170. };
  1171. LayoutEngineBase.prototype.lock = function () {
  1172. if (this._isLocked) {
  1173. return false;
  1174. }
  1175. this._isLocked = true;
  1176. return true;
  1177. };
  1178. return LayoutEngineBase;
  1179. }());
  1180. LayoutEngineBase = __decorate([
  1181. BABYLON.className("LayoutEngineBase", "BABYLON")
  1182. ], LayoutEngineBase);
  1183. BABYLON.LayoutEngineBase = LayoutEngineBase;
  1184. var CanvasLayoutEngine = CanvasLayoutEngine_1 = (function (_super) {
  1185. __extends(CanvasLayoutEngine, _super);
  1186. /**
  1187. * The default Layout Engine, primitive are positioning into a Canvas, using their x/y coordinates.
  1188. * This layout must be used as a Singleton through the CanvasLayoutEngine.Singleton property.
  1189. */
  1190. function CanvasLayoutEngine() {
  1191. return _super.apply(this, arguments) || this;
  1192. }
  1193. // A very simple (no) layout computing...
  1194. // The Canvas and its direct children gets the Canvas' size as Layout Area
  1195. // Indirect children have their Layout Area to the actualSize (margin area) of their parent
  1196. CanvasLayoutEngine.prototype.updateLayout = function (prim) {
  1197. // If this prim is layoutDiry we update its layoutArea and also the one of its direct children
  1198. if (prim._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty)) {
  1199. for (var _i = 0, _a = prim.children; _i < _a.length; _i++) {
  1200. var child = _a[_i];
  1201. this._doUpdate(child);
  1202. }
  1203. prim._clearFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  1204. }
  1205. };
  1206. CanvasLayoutEngine.prototype._doUpdate = function (prim) {
  1207. // Canvas ?
  1208. if (prim instanceof BABYLON.Canvas2D) {
  1209. prim.layoutArea = prim.actualSize; //.multiplyByFloats(prim.scaleX, prim.scaleY);
  1210. }
  1211. else if (prim.parent instanceof BABYLON.Canvas2D) {
  1212. prim.layoutArea = prim.owner.actualSize; //.multiplyByFloats(prim.owner.scaleX, prim.owner.scaleY);
  1213. }
  1214. else {
  1215. prim.layoutArea = prim.parent.contentArea;
  1216. }
  1217. };
  1218. Object.defineProperty(CanvasLayoutEngine.prototype, "isChildPositionAllowed", {
  1219. get: function () {
  1220. return true;
  1221. },
  1222. enumerable: true,
  1223. configurable: true
  1224. });
  1225. return CanvasLayoutEngine;
  1226. }(LayoutEngineBase));
  1227. CanvasLayoutEngine.Singleton = new CanvasLayoutEngine_1();
  1228. CanvasLayoutEngine = CanvasLayoutEngine_1 = __decorate([
  1229. BABYLON.className("CanvasLayoutEngine", "BABYLON")
  1230. ], CanvasLayoutEngine);
  1231. BABYLON.CanvasLayoutEngine = CanvasLayoutEngine;
  1232. var StackPanelLayoutEngine = StackPanelLayoutEngine_1 = (function (_super) {
  1233. __extends(StackPanelLayoutEngine, _super);
  1234. function StackPanelLayoutEngine() {
  1235. var _this = _super.call(this) || this;
  1236. _this._isHorizontal = true;
  1237. _this.layoutDirtyOnPropertyChangedMask = BABYLON.Prim2DBase.sizeProperty.flagId;
  1238. return _this;
  1239. }
  1240. Object.defineProperty(StackPanelLayoutEngine, "Horizontal", {
  1241. get: function () {
  1242. if (!StackPanelLayoutEngine_1._horizontal) {
  1243. StackPanelLayoutEngine_1._horizontal = new StackPanelLayoutEngine_1();
  1244. StackPanelLayoutEngine_1._horizontal.isHorizontal = true;
  1245. StackPanelLayoutEngine_1._horizontal.lock();
  1246. }
  1247. return StackPanelLayoutEngine_1._horizontal;
  1248. },
  1249. enumerable: true,
  1250. configurable: true
  1251. });
  1252. Object.defineProperty(StackPanelLayoutEngine, "Vertical", {
  1253. get: function () {
  1254. if (!StackPanelLayoutEngine_1._vertical) {
  1255. StackPanelLayoutEngine_1._vertical = new StackPanelLayoutEngine_1();
  1256. StackPanelLayoutEngine_1._vertical.isHorizontal = false;
  1257. StackPanelLayoutEngine_1._vertical.lock();
  1258. }
  1259. return StackPanelLayoutEngine_1._vertical;
  1260. },
  1261. enumerable: true,
  1262. configurable: true
  1263. });
  1264. Object.defineProperty(StackPanelLayoutEngine.prototype, "isHorizontal", {
  1265. get: function () {
  1266. return this._isHorizontal;
  1267. },
  1268. set: function (val) {
  1269. if (this.isLocked()) {
  1270. return;
  1271. }
  1272. this._isHorizontal = val;
  1273. },
  1274. enumerable: true,
  1275. configurable: true
  1276. });
  1277. StackPanelLayoutEngine.prototype.updateLayout = function (prim) {
  1278. if (prim._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty)) {
  1279. var x = 0;
  1280. var y = 0;
  1281. var h = this.isHorizontal;
  1282. var max = 0;
  1283. for (var _i = 0, _a = prim.children; _i < _a.length; _i++) {
  1284. var child = _a[_i];
  1285. if (child._isFlagSet(BABYLON.SmartPropertyPrim.flagNoPartOfLayout)) {
  1286. continue;
  1287. }
  1288. var layoutArea = void 0;
  1289. if (child._hasMargin) {
  1290. child.margin.computeWithAlignment(prim.layoutArea, child.actualSize, child.marginAlignment, StackPanelLayoutEngine_1.dstOffset, StackPanelLayoutEngine_1.dstArea, true);
  1291. layoutArea = StackPanelLayoutEngine_1.dstArea.clone();
  1292. child.layoutArea = layoutArea;
  1293. }
  1294. else {
  1295. layoutArea = child.layoutArea;
  1296. child.margin.computeArea(child.actualSize, layoutArea);
  1297. }
  1298. max = Math.max(max, h ? layoutArea.height : layoutArea.width);
  1299. }
  1300. for (var _b = 0, _c = prim.children; _b < _c.length; _b++) {
  1301. var child = _c[_b];
  1302. if (child._isFlagSet(BABYLON.SmartPropertyPrim.flagNoPartOfLayout)) {
  1303. continue;
  1304. }
  1305. child.layoutAreaPos = new BABYLON.Vector2(x, y);
  1306. var layoutArea = child.layoutArea;
  1307. if (h) {
  1308. x += layoutArea.width;
  1309. child.layoutArea = new BABYLON.Size(layoutArea.width, max);
  1310. }
  1311. else {
  1312. y += layoutArea.height;
  1313. child.layoutArea = new BABYLON.Size(max, layoutArea.height);
  1314. }
  1315. }
  1316. prim._clearFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  1317. }
  1318. };
  1319. Object.defineProperty(StackPanelLayoutEngine.prototype, "isChildPositionAllowed", {
  1320. get: function () {
  1321. return false;
  1322. },
  1323. enumerable: true,
  1324. configurable: true
  1325. });
  1326. return StackPanelLayoutEngine;
  1327. }(LayoutEngineBase));
  1328. StackPanelLayoutEngine._horizontal = null;
  1329. StackPanelLayoutEngine._vertical = null;
  1330. StackPanelLayoutEngine.dstOffset = BABYLON.Vector4.Zero();
  1331. StackPanelLayoutEngine.dstArea = BABYLON.Size.Zero();
  1332. StackPanelLayoutEngine = StackPanelLayoutEngine_1 = __decorate([
  1333. BABYLON.className("StackPanelLayoutEngine", "BABYLON")
  1334. ], StackPanelLayoutEngine);
  1335. BABYLON.StackPanelLayoutEngine = StackPanelLayoutEngine;
  1336. var CanvasLayoutEngine_1, StackPanelLayoutEngine_1;
  1337. })(BABYLON || (BABYLON = {}));
  1338. //# sourceMappingURL=babylon.canvas2dLayoutEngine.js.map
  1339. var __extends = (this && this.__extends) || function (d, b) {
  1340. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  1341. function __() { this.constructor = d; }
  1342. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1343. };
  1344. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  1345. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  1346. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  1347. 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;
  1348. return c > 3 && r && Object.defineProperty(target, key, r), r;
  1349. };
  1350. var BABYLON;
  1351. (function (BABYLON) {
  1352. /**
  1353. * Base class implementing the ILocable interface.
  1354. * The particularity of this class is to call the protected onLock() method when the instance is about to be locked for good.
  1355. */
  1356. var LockableBase = (function () {
  1357. function LockableBase() {
  1358. }
  1359. LockableBase.prototype.isLocked = function () {
  1360. return this._isLocked;
  1361. };
  1362. LockableBase.prototype.lock = function () {
  1363. if (this._isLocked) {
  1364. return true;
  1365. }
  1366. this.onLock();
  1367. this._isLocked = true;
  1368. return false;
  1369. };
  1370. /**
  1371. * Protected handler that will be called when the instance is about to be locked.
  1372. */
  1373. LockableBase.prototype.onLock = function () {
  1374. };
  1375. return LockableBase;
  1376. }());
  1377. BABYLON.LockableBase = LockableBase;
  1378. var SolidColorBrush2D = (function (_super) {
  1379. __extends(SolidColorBrush2D, _super);
  1380. function SolidColorBrush2D(color, lock) {
  1381. if (lock === void 0) { lock = false; }
  1382. var _this = _super.call(this) || this;
  1383. _this._color = color;
  1384. if (lock) {
  1385. {
  1386. _this.lock();
  1387. }
  1388. }
  1389. return _this;
  1390. }
  1391. /**
  1392. * Return true if the brush is transparent, false if it's totally opaque
  1393. */
  1394. SolidColorBrush2D.prototype.isTransparent = function () {
  1395. return this._color && this._color.a < 1.0;
  1396. };
  1397. Object.defineProperty(SolidColorBrush2D.prototype, "color", {
  1398. /**
  1399. * The color used by this instance to render
  1400. * @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.
  1401. */
  1402. get: function () {
  1403. return this._color;
  1404. },
  1405. set: function (value) {
  1406. if (this.isLocked()) {
  1407. return;
  1408. }
  1409. this._color = value;
  1410. },
  1411. enumerable: true,
  1412. configurable: true
  1413. });
  1414. /**
  1415. * Return a unique identifier of the instance, which is simply the hexadecimal representation (CSS Style) of the solid color.
  1416. */
  1417. SolidColorBrush2D.prototype.toString = function () {
  1418. return this._color.toHexString();
  1419. };
  1420. return SolidColorBrush2D;
  1421. }(LockableBase));
  1422. SolidColorBrush2D = __decorate([
  1423. BABYLON.className("SolidColorBrush2D", "BABYLON")
  1424. ], SolidColorBrush2D);
  1425. BABYLON.SolidColorBrush2D = SolidColorBrush2D;
  1426. var GradientColorBrush2D = (function (_super) {
  1427. __extends(GradientColorBrush2D, _super);
  1428. function GradientColorBrush2D(color1, color2, translation, rotation, scale, lock) {
  1429. if (translation === void 0) { translation = BABYLON.Vector2.Zero(); }
  1430. if (rotation === void 0) { rotation = 0; }
  1431. if (scale === void 0) { scale = 1; }
  1432. if (lock === void 0) { lock = false; }
  1433. var _this = _super.call(this) || this;
  1434. _this._color1 = color1;
  1435. _this._color2 = color2;
  1436. _this._translation = translation;
  1437. _this._rotation = rotation;
  1438. _this._scale = scale;
  1439. if (lock) {
  1440. _this.lock();
  1441. }
  1442. return _this;
  1443. }
  1444. /**
  1445. * Return true if the brush is transparent, false if it's totally opaque
  1446. */
  1447. GradientColorBrush2D.prototype.isTransparent = function () {
  1448. return (this._color1 && this._color1.a < 1.0) || (this._color2 && this._color2.a < 1.0);
  1449. };
  1450. Object.defineProperty(GradientColorBrush2D.prototype, "color1", {
  1451. /**
  1452. * First color, the blend will start from this color
  1453. */
  1454. get: function () {
  1455. return this._color1;
  1456. },
  1457. set: function (value) {
  1458. if (this.isLocked()) {
  1459. return;
  1460. }
  1461. this._color1 = value;
  1462. },
  1463. enumerable: true,
  1464. configurable: true
  1465. });
  1466. Object.defineProperty(GradientColorBrush2D.prototype, "color2", {
  1467. /**
  1468. * Second color, the blend will end to this color
  1469. */
  1470. get: function () {
  1471. return this._color2;
  1472. },
  1473. set: function (value) {
  1474. if (this.isLocked()) {
  1475. return;
  1476. }
  1477. this._color2 = value;
  1478. },
  1479. enumerable: true,
  1480. configurable: true
  1481. });
  1482. Object.defineProperty(GradientColorBrush2D.prototype, "translation", {
  1483. /**
  1484. * Translation vector to apply on the blend
  1485. * Default is [0;0]
  1486. */
  1487. get: function () {
  1488. return this._translation;
  1489. },
  1490. set: function (value) {
  1491. if (this.isLocked()) {
  1492. return;
  1493. }
  1494. this._translation = value;
  1495. },
  1496. enumerable: true,
  1497. configurable: true
  1498. });
  1499. Object.defineProperty(GradientColorBrush2D.prototype, "rotation", {
  1500. /**
  1501. * Rotation in radian to apply to the brush
  1502. * Default direction of the brush is vertical, you can change this using this property.
  1503. * Default is 0.
  1504. */
  1505. get: function () {
  1506. return this._rotation;
  1507. },
  1508. set: function (value) {
  1509. if (this.isLocked()) {
  1510. return;
  1511. }
  1512. this._rotation = value;
  1513. },
  1514. enumerable: true,
  1515. configurable: true
  1516. });
  1517. Object.defineProperty(GradientColorBrush2D.prototype, "scale", {
  1518. /**
  1519. * Scale factor to apply to the gradient.
  1520. * Default is 1: no scale.
  1521. */
  1522. get: function () {
  1523. return this._scale;
  1524. },
  1525. set: function (value) {
  1526. if (this.isLocked()) {
  1527. return;
  1528. }
  1529. this._scale = value;
  1530. },
  1531. enumerable: true,
  1532. configurable: true
  1533. });
  1534. /**
  1535. * Return a string describing the brush
  1536. */
  1537. GradientColorBrush2D.prototype.toString = function () {
  1538. return "C1:" + this._color1 + ";C2:" + this._color2 + ";T:" + this._translation.toString() + ";R:" + this._rotation + ";S:" + this._scale + ";";
  1539. };
  1540. /**
  1541. * Build a unique key string for the given parameters
  1542. */
  1543. GradientColorBrush2D.BuildKey = function (color1, color2, translation, rotation, scale) {
  1544. return "C1:" + color1 + ";C2:" + color2 + ";T:" + translation.toString() + ";R:" + rotation + ";S:" + scale + ";";
  1545. };
  1546. return GradientColorBrush2D;
  1547. }(LockableBase));
  1548. GradientColorBrush2D = __decorate([
  1549. BABYLON.className("GradientColorBrush2D", "BABYLON")
  1550. ], GradientColorBrush2D);
  1551. BABYLON.GradientColorBrush2D = GradientColorBrush2D;
  1552. })(BABYLON || (BABYLON = {}));
  1553. //# sourceMappingURL=babylon.brushes2d.js.map
  1554. var __extends = (this && this.__extends) || function (d, b) {
  1555. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  1556. function __() { this.constructor = d; }
  1557. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1558. };
  1559. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  1560. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  1561. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  1562. 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;
  1563. return c > 3 && r && Object.defineProperty(target, key, r), r;
  1564. };
  1565. var BABYLON;
  1566. (function (BABYLON) {
  1567. var Prim2DClassInfo = (function () {
  1568. function Prim2DClassInfo() {
  1569. }
  1570. return Prim2DClassInfo;
  1571. }());
  1572. BABYLON.Prim2DClassInfo = Prim2DClassInfo;
  1573. var Prim2DPropInfo = (function () {
  1574. function Prim2DPropInfo() {
  1575. }
  1576. return Prim2DPropInfo;
  1577. }());
  1578. Prim2DPropInfo.PROPKIND_MODEL = 1;
  1579. Prim2DPropInfo.PROPKIND_INSTANCE = 2;
  1580. Prim2DPropInfo.PROPKIND_DYNAMIC = 3;
  1581. BABYLON.Prim2DPropInfo = Prim2DPropInfo;
  1582. var ClassTreeInfo = (function () {
  1583. function ClassTreeInfo(baseClass, type, classContentFactory) {
  1584. this._baseClass = baseClass;
  1585. this._type = type;
  1586. this._subClasses = new Array();
  1587. this._levelContent = new BABYLON.StringDictionary();
  1588. this._classContentFactory = classContentFactory;
  1589. }
  1590. Object.defineProperty(ClassTreeInfo.prototype, "classContent", {
  1591. get: function () {
  1592. if (!this._classContent) {
  1593. this._classContent = this._classContentFactory(this._baseClass ? this._baseClass.classContent : null);
  1594. }
  1595. return this._classContent;
  1596. },
  1597. enumerable: true,
  1598. configurable: true
  1599. });
  1600. Object.defineProperty(ClassTreeInfo.prototype, "type", {
  1601. get: function () {
  1602. return this._type;
  1603. },
  1604. enumerable: true,
  1605. configurable: true
  1606. });
  1607. Object.defineProperty(ClassTreeInfo.prototype, "levelContent", {
  1608. get: function () {
  1609. return this._levelContent;
  1610. },
  1611. enumerable: true,
  1612. configurable: true
  1613. });
  1614. Object.defineProperty(ClassTreeInfo.prototype, "fullContent", {
  1615. get: function () {
  1616. if (!this._fullContent) {
  1617. var dic_1 = new BABYLON.StringDictionary();
  1618. var curLevel = this;
  1619. while (curLevel) {
  1620. curLevel.levelContent.forEach(function (k, v) { return dic_1.add(k, v); });
  1621. curLevel = curLevel._baseClass;
  1622. }
  1623. this._fullContent = dic_1;
  1624. }
  1625. return this._fullContent;
  1626. },
  1627. enumerable: true,
  1628. configurable: true
  1629. });
  1630. ClassTreeInfo.prototype.getLevelOf = function (type) {
  1631. // Are we already there?
  1632. if (type === this._type) {
  1633. return this;
  1634. }
  1635. var baseProto = Object.getPrototypeOf(type);
  1636. var curProtoContent = this.getOrAddType(Object.getPrototypeOf(baseProto), baseProto);
  1637. if (!curProtoContent) {
  1638. this.getLevelOf(baseProto);
  1639. }
  1640. return this.getOrAddType(baseProto, type);
  1641. };
  1642. ClassTreeInfo.prototype.getOrAddType = function (baseType, type) {
  1643. // Are we at the level corresponding to the baseType?
  1644. // If so, get or add the level we're looking for
  1645. if (baseType === this._type) {
  1646. for (var _i = 0, _a = this._subClasses; _i < _a.length; _i++) {
  1647. var subType = _a[_i];
  1648. if (subType.type === type) {
  1649. return subType.node;
  1650. }
  1651. }
  1652. var node = new ClassTreeInfo(this, type, this._classContentFactory);
  1653. var info = { type: type, node: node };
  1654. this._subClasses.push(info);
  1655. return info.node;
  1656. }
  1657. // Recurse down to keep looking for the node corresponding to the baseTypeName
  1658. for (var _b = 0, _c = this._subClasses; _b < _c.length; _b++) {
  1659. var subType = _c[_b];
  1660. var info = subType.node.getOrAddType(baseType, type);
  1661. if (info) {
  1662. return info;
  1663. }
  1664. }
  1665. return null;
  1666. };
  1667. ClassTreeInfo.get = function (type) {
  1668. var dic = type["__classTreeInfo"];
  1669. if (!dic) {
  1670. return null;
  1671. }
  1672. return dic.getLevelOf(type);
  1673. };
  1674. ClassTreeInfo.getOrRegister = function (type, classContentFactory) {
  1675. var dic = type["__classTreeInfo"];
  1676. if (!dic) {
  1677. dic = new ClassTreeInfo(null, type, classContentFactory);
  1678. type["__classTreeInfo"] = dic;
  1679. }
  1680. return dic;
  1681. };
  1682. return ClassTreeInfo;
  1683. }());
  1684. BABYLON.ClassTreeInfo = ClassTreeInfo;
  1685. var DataBinding = DataBinding_1 = (function () {
  1686. function DataBinding() {
  1687. this._converter = null;
  1688. this._mode = DataBinding_1.MODE_DEFAULT;
  1689. this._uiElementId = null;
  1690. this._dataSource = null;
  1691. this._currentDataSource = null;
  1692. this._propertyPathName = null;
  1693. this._stringFormat = null;
  1694. this._updateSourceTrigger = DataBinding_1.UPDATESOURCETRIGGER_PROPERTYCHANGED;
  1695. this._boundTo = null;
  1696. this._owner = null;
  1697. this._updateCounter = 0;
  1698. }
  1699. Object.defineProperty(DataBinding.prototype, "converter", {
  1700. /**
  1701. * Provide a callback that will convert the value obtained by the Data Binding to the type of the SmartProperty it's bound to.
  1702. * If no value are set, then it's assumed that the sourceValue is of the same type as the SmartProperty's one.
  1703. * 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.
  1704. * @param sourceValue the source object retrieve by the Data Binding mechanism
  1705. * @returns the object of a compatible type with the SmartProperty it's bound to
  1706. */
  1707. get: function () {
  1708. return this._converter;
  1709. },
  1710. set: function (value) {
  1711. if (this._converter === value) {
  1712. return;
  1713. }
  1714. this._converter = value;
  1715. },
  1716. enumerable: true,
  1717. configurable: true
  1718. });
  1719. Object.defineProperty(DataBinding.prototype, "mode", {
  1720. /**
  1721. * 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
  1722. */
  1723. get: function () {
  1724. if (this._mode === DataBinding_1.MODE_DEFAULT) {
  1725. return this._boundTo.bindingMode;
  1726. }
  1727. return this._mode;
  1728. },
  1729. set: function (value) {
  1730. if (this._mode === value) {
  1731. return;
  1732. }
  1733. this._mode = value;
  1734. },
  1735. enumerable: true,
  1736. configurable: true
  1737. });
  1738. Object.defineProperty(DataBinding.prototype, "uiElementId", {
  1739. /**
  1740. * You can override the Data Source object with this member which is the Id of a uiElement existing in the UI Logical tree.
  1741. * If not set and source no set too, then the dataSource property will be used.
  1742. */
  1743. get: function () {
  1744. return this._uiElementId;
  1745. },
  1746. set: function (value) {
  1747. if (this._uiElementId === value) {
  1748. return;
  1749. }
  1750. this._uiElementId = value;
  1751. },
  1752. enumerable: true,
  1753. configurable: true
  1754. });
  1755. Object.defineProperty(DataBinding.prototype, "dataSource", {
  1756. /**
  1757. * You can override the Data Source object with this member which is the source object to use directly.
  1758. * If not set and uiElement no set too, then the dataSource property of the SmartPropertyBase object will be used.
  1759. */
  1760. get: function () {
  1761. return this._dataSource;
  1762. },
  1763. set: function (value) {
  1764. if (this._dataSource === value) {
  1765. return;
  1766. }
  1767. this._dataSource = value;
  1768. },
  1769. enumerable: true,
  1770. configurable: true
  1771. });
  1772. Object.defineProperty(DataBinding.prototype, "propertyPathName", {
  1773. /**
  1774. * The path & name of the property to get from the source object.
  1775. * 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.
  1776. * If nothing is set then the source object will be used.
  1777. * 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.
  1778. * 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.
  1779. */
  1780. get: function () {
  1781. return this._propertyPathName;
  1782. },
  1783. set: function (value) {
  1784. if (this._propertyPathName === value) {
  1785. return;
  1786. }
  1787. if (this._owner) {
  1788. }
  1789. this._propertyPathName = value;
  1790. if (this._owner) {
  1791. }
  1792. },
  1793. enumerable: true,
  1794. configurable: true
  1795. });
  1796. Object.defineProperty(DataBinding.prototype, "stringFormat", {
  1797. /**
  1798. * 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}`
  1799. */
  1800. get: function () {
  1801. return this._stringFormat;
  1802. },
  1803. set: function (value) {
  1804. if (this._stringFormat === value) {
  1805. return;
  1806. }
  1807. this._stringFormat = value;
  1808. },
  1809. enumerable: true,
  1810. configurable: true
  1811. });
  1812. Object.defineProperty(DataBinding.prototype, "updateSourceTrigger", {
  1813. /**
  1814. * 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.
  1815. */
  1816. get: function () {
  1817. return this._updateSourceTrigger;
  1818. },
  1819. set: function (value) {
  1820. if (this._updateSourceTrigger === value) {
  1821. return;
  1822. }
  1823. this._updateSourceTrigger = value;
  1824. },
  1825. enumerable: true,
  1826. configurable: true
  1827. });
  1828. DataBinding.prototype.canUpdateTarget = function (resetUpdateCounter) {
  1829. if (resetUpdateCounter) {
  1830. this._updateCounter = 0;
  1831. }
  1832. var mode = this.mode;
  1833. if (mode === DataBinding_1.MODE_ONETIME) {
  1834. return this._updateCounter === 0;
  1835. }
  1836. if (mode === DataBinding_1.MODE_ONEWAYTOSOURCE) {
  1837. return false;
  1838. }
  1839. return true;
  1840. };
  1841. DataBinding.prototype.updateTarget = function () {
  1842. var value = this._getActualDataSource();
  1843. var properties = this.propertyPathName.split(".");
  1844. for (var _i = 0, properties_1 = properties; _i < properties_1.length; _i++) {
  1845. var propertyName = properties_1[_i];
  1846. value = value[propertyName];
  1847. }
  1848. this._storeBoundValue(this._owner, value);
  1849. };
  1850. DataBinding.prototype._storeBoundValue = function (watcher, value) {
  1851. if ((++this._updateCounter > 1) && (this.mode === DataBinding_1.MODE_ONETIME)) {
  1852. return;
  1853. }
  1854. var newValue = value;
  1855. if (this._converter) {
  1856. newValue = this._converter(value);
  1857. }
  1858. if (this._stringFormat) {
  1859. newValue = this._stringFormat(newValue);
  1860. }
  1861. watcher[this._boundTo.name] = newValue;
  1862. };
  1863. DataBinding.prototype._getActualDataSource = function () {
  1864. if (this.dataSource) {
  1865. return this.dataSource;
  1866. }
  1867. if (this.uiElementId) {
  1868. // TODO Find UIElement
  1869. return null;
  1870. }
  1871. return this._owner.dataSource;
  1872. };
  1873. DataBinding.prototype._registerDataSource = function (updateTarget) {
  1874. var ds = this._getActualDataSource();
  1875. if (ds === this._currentDataSource) {
  1876. return;
  1877. }
  1878. if (this._currentDataSource) {
  1879. BindingHelper.unregisterDataSource(this._currentDataSource, this, 0);
  1880. }
  1881. if (ds) {
  1882. BindingHelper.registerDataSource(ds, this);
  1883. if (updateTarget && this.canUpdateTarget(true)) {
  1884. this.updateTarget();
  1885. }
  1886. }
  1887. this._currentDataSource = ds;
  1888. };
  1889. DataBinding.prototype._unregisterDataSource = function () {
  1890. var ds = this._getActualDataSource();
  1891. if (ds) {
  1892. BindingHelper.unregisterDataSource(ds, this, 0);
  1893. }
  1894. };
  1895. return DataBinding;
  1896. }());
  1897. /**
  1898. * Use the mode specified in the SmartProperty declaration
  1899. */
  1900. DataBinding.MODE_DEFAULT = 1;
  1901. /**
  1902. * Update the binding target only once when the Smart Property's value is first accessed
  1903. */
  1904. DataBinding.MODE_ONETIME = 2;
  1905. /**
  1906. * Update the smart property when the source changes.
  1907. * The source won't be updated if the smart property value is set.
  1908. */
  1909. DataBinding.MODE_ONEWAY = 3;
  1910. /**
  1911. * Only update the source when the target's data is changing.
  1912. */
  1913. DataBinding.MODE_ONEWAYTOSOURCE = 4;
  1914. /**
  1915. * Update the bind target when the source changes and update the source when the Smart Property value is set.
  1916. */
  1917. DataBinding.MODE_TWOWAY = 5;
  1918. /**
  1919. * Use the Update Source Trigger defined in the SmartProperty declaration
  1920. */
  1921. DataBinding.UPDATESOURCETRIGGER_DEFAULT = 1;
  1922. /**
  1923. * Update the source as soon as the Smart Property has a value change
  1924. */
  1925. DataBinding.UPDATESOURCETRIGGER_PROPERTYCHANGED = 2;
  1926. /**
  1927. * Update the source when the binding target loses focus
  1928. */
  1929. DataBinding.UPDATESOURCETRIGGER_LOSTFOCUS = 3;
  1930. /**
  1931. * Update the source will be made by explicitly calling the UpdateFromDataSource method
  1932. */
  1933. DataBinding.UPDATESOURCETRIGGER_EXPLICIT = 4;
  1934. DataBinding = DataBinding_1 = __decorate([
  1935. BABYLON.className("DataBinding", "BABYLON")
  1936. ], DataBinding);
  1937. BABYLON.DataBinding = DataBinding;
  1938. var SmartPropertyBase = SmartPropertyBase_1 = (function (_super) {
  1939. __extends(SmartPropertyBase, _super);
  1940. function SmartPropertyBase() {
  1941. var _this = _super.call(this) || this;
  1942. _this._dataSource = null;
  1943. _this._dataSourceObserver = null;
  1944. _this._instanceDirtyFlags = 0;
  1945. _this._isDisposed = false;
  1946. _this._bindings = null;
  1947. _this._hasBinding = 0;
  1948. _this._bindingSourceChanged = 0;
  1949. _this._disposeObservable = null;
  1950. return _this;
  1951. }
  1952. Object.defineProperty(SmartPropertyBase.prototype, "disposeObservable", {
  1953. get: function () {
  1954. if (!this._disposeObservable) {
  1955. this._disposeObservable = new BABYLON.Observable();
  1956. }
  1957. return this._disposeObservable;
  1958. },
  1959. enumerable: true,
  1960. configurable: true
  1961. });
  1962. Object.defineProperty(SmartPropertyBase.prototype, "isDisposed", {
  1963. /**
  1964. * Check if the object is disposed or not.
  1965. * @returns true if the object is dispose, false otherwise.
  1966. */
  1967. get: function () {
  1968. return this._isDisposed;
  1969. },
  1970. enumerable: true,
  1971. configurable: true
  1972. });
  1973. /**
  1974. * Disposable pattern, this method must be overloaded by derived types in order to clean up hardware related resources.
  1975. * @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.
  1976. */
  1977. SmartPropertyBase.prototype.dispose = function () {
  1978. if (this.isDisposed) {
  1979. return false;
  1980. }
  1981. if (this._disposeObservable && this._disposeObservable.hasObservers()) {
  1982. this._disposeObservable.notifyObservers(this);
  1983. }
  1984. this._isDisposed = true;
  1985. return true;
  1986. };
  1987. /**
  1988. * Check if a given set of properties are dirty or not.
  1989. * @param flags a ORed combination of Prim2DPropInfo.flagId values
  1990. * @return true if at least one property is dirty, false if none of them are.
  1991. */
  1992. SmartPropertyBase.prototype.checkPropertiesDirty = function (flags) {
  1993. return (this._instanceDirtyFlags & flags) !== 0;
  1994. };
  1995. /**
  1996. * Clear a given set of properties.
  1997. * @param flags a ORed combination of Prim2DPropInfo.flagId values
  1998. * @return the new set of property still marked as dirty
  1999. */
  2000. SmartPropertyBase.prototype.clearPropertiesDirty = function (flags) {
  2001. this._instanceDirtyFlags &= ~flags;
  2002. return this._instanceDirtyFlags;
  2003. };
  2004. SmartPropertyBase.prototype._resetPropertiesDirty = function () {
  2005. this._instanceDirtyFlags = 0;
  2006. };
  2007. /**
  2008. * Add an externally attached data from its key.
  2009. * This method call will fail and return false, if such key already exists.
  2010. * If you don't care and just want to get the data no matter what, use the more convenient getOrAddExternalDataWithFactory() method.
  2011. * @param key the unique key that identifies the data
  2012. * @param data the data object to associate to the key for this Engine instance
  2013. * @return true if no such key were already present and the data was added successfully, false otherwise
  2014. */
  2015. SmartPropertyBase.prototype.addExternalData = function (key, data) {
  2016. if (!this._externalData) {
  2017. this._externalData = new BABYLON.StringDictionary();
  2018. }
  2019. return this._externalData.add(key, data);
  2020. };
  2021. /**
  2022. * Get an externally attached data from its key
  2023. * @param key the unique key that identifies the data
  2024. * @return the associated data, if present (can be null), or undefined if not present
  2025. */
  2026. SmartPropertyBase.prototype.getExternalData = function (key) {
  2027. if (!this._externalData) {
  2028. return null;
  2029. }
  2030. return this._externalData.get(key);
  2031. };
  2032. /**
  2033. * Get an externally attached data from its key, create it using a factory if it's not already present
  2034. * @param key the unique key that identifies the data
  2035. * @param factory the factory that will be called to create the instance if and only if it doesn't exists
  2036. * @return the associated data, can be null if the factory returned null.
  2037. */
  2038. SmartPropertyBase.prototype.getOrAddExternalDataWithFactory = function (key, factory) {
  2039. if (!this._externalData) {
  2040. this._externalData = new BABYLON.StringDictionary();
  2041. }
  2042. return this._externalData.getOrAddWithFactory(key, factory);
  2043. };
  2044. /**
  2045. * Remove an externally attached data from the Engine instance
  2046. * @param key the unique key that identifies the data
  2047. * @return true if the data was successfully removed, false if it doesn't exist
  2048. */
  2049. SmartPropertyBase.prototype.removeExternalData = function (key) {
  2050. if (!this._externalData) {
  2051. return false;
  2052. }
  2053. return this._externalData.remove(key);
  2054. };
  2055. SmartPropertyBase._hookProperty = function (propId, piStore, kind, settings) {
  2056. return function (target, propName, descriptor) {
  2057. if (!settings) {
  2058. settings = {};
  2059. }
  2060. var propInfo = SmartPropertyBase_1._createPropInfo(target, propName, propId, kind, settings);
  2061. if (piStore) {
  2062. piStore(propInfo);
  2063. }
  2064. var getter = descriptor.get, setter = descriptor.set;
  2065. var typeLevelCompare = (settings.typeLevelCompare !== undefined) ? settings.typeLevelCompare : false;
  2066. // Overload the property setter implementation to add our own logic
  2067. descriptor.set = function (val) {
  2068. if (!setter) {
  2069. throw Error("Property '" + propInfo.name + "' of type '" + BABYLON.Tools.getFullClassName(this) + "' has no setter defined but was invoked as if it had one.");
  2070. }
  2071. // check for disposed first, do nothing
  2072. if (this.isDisposed) {
  2073. return;
  2074. }
  2075. var curVal = getter.call(this);
  2076. if (SmartPropertyBase_1._checkUnchanged(curVal, val)) {
  2077. return;
  2078. }
  2079. // Cast the object we're working one
  2080. var prim = this;
  2081. // Change the value
  2082. setter.call(this, val);
  2083. // Notify change, dirty flags update
  2084. prim._handlePropChanged(curVal, val, propName, propInfo, typeLevelCompare);
  2085. };
  2086. };
  2087. };
  2088. SmartPropertyBase._createPropInfo = function (target, propName, propId, kind, settings) {
  2089. var dic = ClassTreeInfo.getOrRegister(target, function () { return new Prim2DClassInfo(); });
  2090. var node = dic.getLevelOf(target);
  2091. var propInfo = node.levelContent.get(propId.toString());
  2092. if (propInfo) {
  2093. throw new Error("The ID " + propId + " is already taken by another property declaration named: " + propInfo.name);
  2094. }
  2095. // Create, setup and add the PropInfo object to our prop dictionary
  2096. propInfo = new Prim2DPropInfo();
  2097. propInfo.id = propId;
  2098. propInfo.flagId = Math.pow(2, propId);
  2099. propInfo.kind = kind;
  2100. propInfo.name = propName;
  2101. propInfo.bindingMode = (settings.bindingMode !== undefined) ? settings.bindingMode : DataBinding.MODE_TWOWAY;
  2102. propInfo.bindingUpdateSourceTrigger = (settings.bindingUpdateSourceTrigger !== undefined) ? settings.bindingUpdateSourceTrigger : DataBinding.UPDATESOURCETRIGGER_PROPERTYCHANGED;
  2103. propInfo.dirtyBoundingInfo = (settings.dirtyBoundingInfo !== undefined) ? settings.dirtyBoundingInfo : false;
  2104. propInfo.dirtyParentBoundingInfo = (settings.dirtyParentBoundingBox !== undefined) ? settings.dirtyParentBoundingBox : false;
  2105. propInfo.typeLevelCompare = (settings.typeLevelCompare !== undefined) ? settings.typeLevelCompare : false;
  2106. node.levelContent.add(propName, propInfo);
  2107. return propInfo;
  2108. };
  2109. Object.defineProperty(SmartPropertyBase.prototype, "propDic", {
  2110. /**
  2111. * Access the dictionary of properties metadata. Only properties decorated with XXXXLevelProperty are concerned
  2112. * @returns the dictionary, the key is the property name as declared in Javascript, the value is the metadata object
  2113. */
  2114. get: function () {
  2115. if (!this._propInfo) {
  2116. var cti = ClassTreeInfo.get(Object.getPrototypeOf(this));
  2117. if (!cti) {
  2118. throw new Error("Can't access the propDic member in class definition, is this class SmartPropertyPrim based?");
  2119. }
  2120. this._propInfo = cti.fullContent;
  2121. }
  2122. return this._propInfo;
  2123. },
  2124. enumerable: true,
  2125. configurable: true
  2126. });
  2127. SmartPropertyBase._checkUnchanged = function (curValue, newValue) {
  2128. // Nothing to nothing: nothing to do!
  2129. if ((curValue === null && newValue === null) || (curValue === undefined && newValue === undefined)) {
  2130. return true;
  2131. }
  2132. // Check value unchanged
  2133. if ((curValue != null) && (newValue != null)) {
  2134. if (typeof (curValue.equals) == "function") {
  2135. if (curValue.equals(newValue)) {
  2136. return true;
  2137. }
  2138. }
  2139. else {
  2140. if (curValue === newValue) {
  2141. return true;
  2142. }
  2143. }
  2144. }
  2145. return false;
  2146. };
  2147. SmartPropertyBase.prototype._handlePropChanged = function (curValue, newValue, propName, propInfo, typeLevelCompare) {
  2148. // Trigger property changed
  2149. var info = SmartPropertyBase_1.propChangeGuarding ? new BABYLON.PropertyChangedInfo() : SmartPropertyPrim.propChangedInfo;
  2150. info.oldValue = curValue;
  2151. info.newValue = newValue;
  2152. info.propertyName = propName;
  2153. var propMask = propInfo ? propInfo.flagId : -1;
  2154. try {
  2155. SmartPropertyBase_1.propChangeGuarding = true;
  2156. this.propertyChanged.notifyObservers(info, propMask);
  2157. }
  2158. finally {
  2159. SmartPropertyBase_1.propChangeGuarding = false;
  2160. }
  2161. };
  2162. SmartPropertyBase.prototype._triggerPropertyChanged = function (propInfo, newValue) {
  2163. if (this.isDisposed) {
  2164. return;
  2165. }
  2166. if (!propInfo) {
  2167. return;
  2168. }
  2169. this._handlePropChanged(undefined, newValue, propInfo.name, propInfo, propInfo.typeLevelCompare);
  2170. };
  2171. Object.defineProperty(SmartPropertyBase.prototype, "dataSource", {
  2172. /**
  2173. * Set the object from which Smart Properties using Binding will take/update their data from/to.
  2174. * 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.
  2175. */
  2176. get: function () {
  2177. // Don't access to _dataSource directly but via a call to the _getDataSource method which can be overloaded in inherited classes
  2178. return this._getDataSource();
  2179. },
  2180. set: function (value) {
  2181. if (this._dataSource === value) {
  2182. return;
  2183. }
  2184. var oldValue = this._dataSource;
  2185. this._dataSource = value;
  2186. if (this._bindings && value != null) {
  2187. // Register the bindings
  2188. for (var _i = 0, _a = this._bindings; _i < _a.length; _i++) {
  2189. var binding = _a[_i];
  2190. if (binding != null) {
  2191. binding._registerDataSource(true);
  2192. }
  2193. }
  2194. }
  2195. this.onPropertyChanged("dataSource", oldValue, value);
  2196. },
  2197. enumerable: true,
  2198. configurable: true
  2199. });
  2200. // Inheriting classes can overload this method to provides additional logic for dataSource access
  2201. SmartPropertyBase.prototype._getDataSource = function () {
  2202. return this._dataSource;
  2203. };
  2204. SmartPropertyBase.prototype.createSimpleDataBinding = function (propInfo, propertyPathName, mode) {
  2205. if (mode === void 0) { mode = DataBinding.MODE_DEFAULT; }
  2206. var binding = new DataBinding();
  2207. binding.propertyPathName = propertyPathName;
  2208. binding.mode = mode;
  2209. return this.createDataBinding(propInfo, binding);
  2210. };
  2211. SmartPropertyBase.prototype.createDataBinding = function (propInfo, binding) {
  2212. if (!this._bindings) {
  2213. this._bindings = new Array();
  2214. }
  2215. if (!binding || binding._owner != null) {
  2216. throw Error("A valid/unused Binding must be passed.");
  2217. }
  2218. // Unregister a potentially existing binding for this property
  2219. this.removeDataBinding(propInfo);
  2220. // register the binding
  2221. binding._owner = this;
  2222. binding._boundTo = propInfo;
  2223. this._bindings[propInfo.id] = binding;
  2224. this._hasBinding |= propInfo.flagId;
  2225. binding._registerDataSource(true);
  2226. return binding;
  2227. };
  2228. SmartPropertyBase.prototype.removeDataBinding = function (propInfo) {
  2229. if ((this._hasBinding & propInfo.flagId) === 0) {
  2230. return false;
  2231. }
  2232. var curBinding = this._bindings[propInfo.id];
  2233. curBinding._unregisterDataSource();
  2234. this._bindings[propInfo.id] = null;
  2235. this._hasBinding &= ~propInfo.flagId;
  2236. return true;
  2237. };
  2238. SmartPropertyBase.prototype.updateFromDataSource = function () {
  2239. for (var _i = 0, _a = this._bindings; _i < _a.length; _i++) {
  2240. var binding = _a[_i];
  2241. if (binding) {
  2242. }
  2243. }
  2244. };
  2245. return SmartPropertyBase;
  2246. }(BABYLON.PropertyChangedBase));
  2247. SmartPropertyBase.propChangedInfo = new BABYLON.PropertyChangedInfo();
  2248. SmartPropertyBase.propChangeGuarding = false;
  2249. SmartPropertyBase = SmartPropertyBase_1 = __decorate([
  2250. BABYLON.className("SmartPropertyBase", "BABYLON")
  2251. ], SmartPropertyBase);
  2252. BABYLON.SmartPropertyBase = SmartPropertyBase;
  2253. var BindingInfo = (function () {
  2254. function BindingInfo(binding, level, isLast) {
  2255. this.binding = binding;
  2256. this.level = level;
  2257. this.isLast = isLast;
  2258. }
  2259. return BindingInfo;
  2260. }());
  2261. var MonitoredObjectData = (function () {
  2262. function MonitoredObjectData(monitoredObject) {
  2263. var _this = this;
  2264. this.monitoredObject = monitoredObject;
  2265. this.monitoredIntermediateProperties = new BABYLON.StringDictionary();
  2266. this.observer = this.monitoredObject.propertyChanged.add(function (e, s) { _this.propertyChangedHandler(e.propertyName, e.oldValue, e.newValue); });
  2267. this.boundProperties = new BABYLON.StringDictionary();
  2268. this.monitoredIntermediateMask = 0;
  2269. this.boundPropertiesMask = 0;
  2270. }
  2271. MonitoredObjectData.prototype.propertyChangedHandler = function (propName, oldValue, newValue) {
  2272. var propId = BindingHelper._getPropertyID(this.monitoredObject, propName);
  2273. var propIdStr = propId.toString();
  2274. // Loop through all the registered bindings for this property that had a value change
  2275. if ((this.boundPropertiesMask & propId) !== 0) {
  2276. var bindingInfos = this.boundProperties.get(propIdStr);
  2277. for (var _i = 0, bindingInfos_1 = bindingInfos; _i < bindingInfos_1.length; _i++) {
  2278. var bi = bindingInfos_1[_i];
  2279. if (!bi.isLast) {
  2280. BindingHelper.unregisterDataSource(this.monitoredObject, bi.binding, bi.level);
  2281. BindingHelper.registerDataSource(bi.binding._currentDataSource, bi.binding);
  2282. }
  2283. if (bi.binding.canUpdateTarget(false)) {
  2284. bi.binding.updateTarget();
  2285. }
  2286. }
  2287. }
  2288. };
  2289. return MonitoredObjectData;
  2290. }());
  2291. var BindingHelper = (function () {
  2292. function BindingHelper() {
  2293. }
  2294. BindingHelper.registerDataSource = function (dataSource, binding) {
  2295. var properties = binding.propertyPathName.split(".");
  2296. var ownerMod = null;
  2297. var ownerInterPropId = 0;
  2298. var propertyOwner = dataSource;
  2299. var _loop_1 = function (i) {
  2300. var propName = properties[i];
  2301. var propId = BindingHelper._getPropertyID(propertyOwner, propName);
  2302. var propIdStr = propId.toString();
  2303. var mod = void 0;
  2304. if (ownerMod) {
  2305. var o_1 = ownerMod;
  2306. var po_1 = propertyOwner;
  2307. var oii_1 = ownerInterPropId;
  2308. mod = ownerMod.monitoredIntermediateProperties.getOrAddWithFactory(oii_1.toString(), function (k) {
  2309. o_1.monitoredIntermediateMask |= oii_1;
  2310. return BindingHelper._getMonitoredObjectData(po_1);
  2311. });
  2312. }
  2313. else {
  2314. mod = BindingHelper._getMonitoredObjectData(propertyOwner);
  2315. }
  2316. var m = mod;
  2317. var bindingInfos = mod.boundProperties.getOrAddWithFactory(propIdStr, function (k) {
  2318. m.boundPropertiesMask |= propId;
  2319. return new Array();
  2320. });
  2321. var bi = BABYLON.Tools.first(bindingInfos, function (cbi) { return cbi.binding === binding; });
  2322. if (!bi) {
  2323. bindingInfos.push(new BindingInfo(binding, i, (i + 1) === properties.length));
  2324. }
  2325. ownerMod = mod;
  2326. ownerInterPropId = propId;
  2327. propertyOwner = propertyOwner[propName];
  2328. };
  2329. for (var i = 0; i < properties.length; i++) {
  2330. _loop_1(i);
  2331. }
  2332. };
  2333. BindingHelper.unregisterDataSource = function (dataSource, binding, level) {
  2334. var properties = binding.propertyPathName.split(".");
  2335. var propertyOwner = dataSource;
  2336. var mod = BindingHelper._getMonitoredObjectData(propertyOwner);
  2337. for (var i = 0; i < properties.length; i++) {
  2338. var propName = properties[i];
  2339. var propId = BindingHelper._getPropertyID(propertyOwner, propName);
  2340. var propIdStr = propId.toString();
  2341. if (i >= level) {
  2342. mod = BindingHelper._unregisterBinding(mod, propId, binding);
  2343. }
  2344. else {
  2345. mod = mod.monitoredIntermediateProperties.get(propIdStr);
  2346. }
  2347. propertyOwner = propertyOwner[propName];
  2348. }
  2349. };
  2350. BindingHelper._unregisterBinding = function (mod, propertyID, binding) {
  2351. var propertyIDStr = propertyID.toString();
  2352. var res = null;
  2353. // Check if the property is registered as an intermediate and remove it
  2354. if ((mod.monitoredIntermediateMask & propertyID) !== 0) {
  2355. res = mod.monitoredIntermediateProperties.get(propertyIDStr);
  2356. mod.monitoredIntermediateProperties.remove(propertyIDStr);
  2357. // Update the mask
  2358. mod.monitoredIntermediateMask &= ~propertyID;
  2359. }
  2360. // Check if the property is registered as a final property and remove it
  2361. if ((mod.boundPropertiesMask & propertyID) !== 0) {
  2362. var bindingInfos = mod.boundProperties.get(propertyIDStr);
  2363. // Find the binding and remove it
  2364. var bi = BABYLON.Tools.first(bindingInfos, function (cbi) { return cbi.binding === binding; });
  2365. if (bi) {
  2366. var bii = bindingInfos.indexOf(bi);
  2367. bindingInfos.splice(bii, 1);
  2368. }
  2369. // If the array is empty, update the mask
  2370. if (bindingInfos.length === 0) {
  2371. mod.boundPropertiesMask &= ~propertyID;
  2372. }
  2373. }
  2374. // Check if the MOD is empty and unregister the observer and remove it from the list of MODs
  2375. if (mod.boundPropertiesMask === 0 && mod.monitoredIntermediateMask === 0) {
  2376. // Unregister the observer on Property Change
  2377. mod.monitoredObject.propertyChanged.remove(mod.observer);
  2378. // Remove the MOD from the dic
  2379. var objectId = BindingHelper._getObjectId(mod.monitoredObject);
  2380. BindingHelper._monitoredObjects.remove(objectId);
  2381. }
  2382. return res;
  2383. };
  2384. BindingHelper._getMonitoredObjectData = function (object) {
  2385. var objectId = BindingHelper._getObjectId(object);
  2386. var mod = BindingHelper._monitoredObjects.getOrAddWithFactory(objectId, function (k) { return new MonitoredObjectData(object); });
  2387. return mod;
  2388. };
  2389. BindingHelper._getObjectId = function (obj) {
  2390. var id = obj["__bindingHelperObjectId__"];
  2391. if (id == null) {
  2392. id = BABYLON.Tools.RandomId();
  2393. obj["__bindingHelperObjectId__"] = id;
  2394. return id;
  2395. }
  2396. return id;
  2397. };
  2398. BindingHelper._getObjectTypePropertyIDs = function (obj) {
  2399. var fullName = BABYLON.Tools.getFullClassName(obj);
  2400. if (!fullName) {
  2401. throw Error("Types involved in Data Binding must be decorated with the @className decorator");
  2402. }
  2403. var d = BindingHelper._propertiesID.getOrAddWithFactory(fullName, function () { return new BABYLON.StringDictionary(); });
  2404. return d;
  2405. };
  2406. BindingHelper._getPropertyID = function (object, propName) {
  2407. var otd = BindingHelper._getObjectTypePropertyIDs(object);
  2408. // Make sure we have a WatchedPropertyData for this property of this object type. This will contains the flagIg of the watched property.
  2409. // We use this flagId to flag for each watched instance which properties are watched, as final or intermediate and which directions are used
  2410. var propData = otd.getOrAddWithFactory(propName, function (k) { return 1 << otd.count; });
  2411. return propData;
  2412. };
  2413. return BindingHelper;
  2414. }());
  2415. BindingHelper._propertiesID = new BABYLON.StringDictionary();
  2416. BindingHelper._monitoredObjects = new BABYLON.StringDictionary();
  2417. var SmartPropertyPrim = SmartPropertyPrim_1 = (function (_super) {
  2418. __extends(SmartPropertyPrim, _super);
  2419. function SmartPropertyPrim() {
  2420. var _this = _super.call(this) || this;
  2421. _this._flags = 0;
  2422. _this._modelKey = null;
  2423. _this._levelBoundingInfo = new BABYLON.BoundingInfo2D();
  2424. _this._boundingInfo = new BABYLON.BoundingInfo2D();
  2425. _this.animations = new Array();
  2426. return _this;
  2427. }
  2428. /**
  2429. * Disposable pattern, this method must be overloaded by derived types in order to clean up hardware related resources.
  2430. * @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.
  2431. */
  2432. SmartPropertyPrim.prototype.dispose = function () {
  2433. if (this.isDisposed) {
  2434. return false;
  2435. }
  2436. _super.prototype.dispose.call(this);
  2437. // Don't set to null, it may upset somebody...
  2438. this.animations.splice(0);
  2439. return true;
  2440. };
  2441. /**
  2442. * Returns as a new array populated with the Animatable used by the primitive. Must be overloaded by derived primitives.
  2443. * Look at Sprite2D for more information
  2444. */
  2445. SmartPropertyPrim.prototype.getAnimatables = function () {
  2446. return new Array();
  2447. };
  2448. Object.defineProperty(SmartPropertyPrim.prototype, "modelKey", {
  2449. /**
  2450. * Property giving the Model Key associated to the property.
  2451. * This value is constructed from the type of the primitive and all the name/value of its properties declared with the modelLevelProperty decorator
  2452. * @returns the model key string.
  2453. */
  2454. get: function () {
  2455. var _this = this;
  2456. // No need to compute it?
  2457. if (!this._isFlagSet(SmartPropertyPrim_1.flagModelDirty) && this._modelKey) {
  2458. return this._modelKey;
  2459. }
  2460. var modelKey = "Class:" + BABYLON.Tools.getClassName(this) + ";";
  2461. var propDic = this.propDic;
  2462. propDic.forEach(function (k, v) {
  2463. if (v.kind === Prim2DPropInfo.PROPKIND_MODEL) {
  2464. var propVal = _this[v.name];
  2465. // 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
  2466. if (propVal && propVal.constructor === Array) {
  2467. var firstVal = propVal[0];
  2468. if (!firstVal) {
  2469. propVal = 0;
  2470. }
  2471. else {
  2472. propVal = BABYLON.Tools.hashCodeFromStream(BABYLON.Tools.arrayOrStringFeeder(propVal));
  2473. }
  2474. }
  2475. var value = "[null]";
  2476. if (propVal != null) {
  2477. if (v.typeLevelCompare) {
  2478. value = BABYLON.Tools.getClassName(propVal);
  2479. }
  2480. else {
  2481. if (propVal instanceof BABYLON.BaseTexture) {
  2482. value = propVal.uid;
  2483. }
  2484. else {
  2485. value = propVal.toString();
  2486. }
  2487. }
  2488. }
  2489. modelKey += v.name + ":" + value + ";";
  2490. }
  2491. });
  2492. this._clearFlags(SmartPropertyPrim_1.flagModelDirty);
  2493. this._modelKey = modelKey;
  2494. return modelKey;
  2495. },
  2496. enumerable: true,
  2497. configurable: true
  2498. });
  2499. Object.defineProperty(SmartPropertyPrim.prototype, "isDirty", {
  2500. /**
  2501. * States if the Primitive is dirty and should be rendered again next time.
  2502. * @returns true is dirty, false otherwise
  2503. */
  2504. get: function () {
  2505. return (this._instanceDirtyFlags !== 0) || this._areSomeFlagsSet(SmartPropertyPrim_1.flagModelDirty | SmartPropertyPrim_1.flagPositioningDirty | SmartPropertyPrim_1.flagLayoutDirty);
  2506. },
  2507. enumerable: true,
  2508. configurable: true
  2509. });
  2510. SmartPropertyPrim.prototype._boundingBoxDirty = function () {
  2511. this._setFlags(SmartPropertyPrim_1.flagLevelBoundingInfoDirty);
  2512. // Escalate the dirty flag in the instance hierarchy, stop when a renderable group is found or at the end
  2513. if (this instanceof BABYLON.Prim2DBase) {
  2514. var curprim = this;
  2515. while (curprim) {
  2516. curprim._setFlags(SmartPropertyPrim_1.flagBoundingInfoDirty);
  2517. if (curprim.isSizeAuto) {
  2518. curprim.onPrimitivePropertyDirty(BABYLON.Prim2DBase.sizeProperty.flagId);
  2519. curprim._setFlags(SmartPropertyPrim_1.flagPositioningDirty);
  2520. }
  2521. if (curprim instanceof BABYLON.Group2D) {
  2522. if (curprim.isRenderableGroup) {
  2523. break;
  2524. }
  2525. }
  2526. curprim = curprim.parent;
  2527. }
  2528. }
  2529. };
  2530. SmartPropertyPrim.prototype._handlePropChanged = function (curValue, newValue, propName, propInfo, typeLevelCompare) {
  2531. _super.prototype._handlePropChanged.call(this, curValue, newValue, propName, propInfo, typeLevelCompare);
  2532. // If the property change also dirty the boundingInfo, update the boundingInfo dirty flags
  2533. if (propInfo.dirtyBoundingInfo) {
  2534. this._boundingBoxDirty();
  2535. }
  2536. else if (propInfo.dirtyParentBoundingInfo) {
  2537. var p = this._parent;
  2538. if (p != null) {
  2539. p._boundingBoxDirty();
  2540. }
  2541. }
  2542. // If the property belong to a group, check if it's a cached one, and dirty its render sprite accordingly
  2543. if (this instanceof BABYLON.Group2D && this._renderableData) {
  2544. this.handleGroupChanged(propInfo);
  2545. }
  2546. // Check for parent layout dirty
  2547. if (this instanceof BABYLON.Prim2DBase) {
  2548. var p = this._parent;
  2549. if (p != null && p.layoutEngine && (p.layoutEngine.layoutDirtyOnPropertyChangedMask & propInfo.flagId) !== 0) {
  2550. p._setLayoutDirty();
  2551. }
  2552. }
  2553. // For type level compare, if there's a change of type it's a change of model, otherwise we issue an instance change
  2554. var instanceDirty = false;
  2555. if (typeLevelCompare && curValue != null && newValue != null) {
  2556. var cvProto = curValue.__proto__;
  2557. var nvProto = newValue.__proto__;
  2558. instanceDirty = (cvProto === nvProto);
  2559. }
  2560. // Set the dirty flags
  2561. if (!instanceDirty && (propInfo.kind === Prim2DPropInfo.PROPKIND_MODEL)) {
  2562. if (!this.isDirty) {
  2563. this._setFlags(SmartPropertyPrim_1.flagModelDirty);
  2564. }
  2565. }
  2566. else if (instanceDirty || (propInfo.kind === Prim2DPropInfo.PROPKIND_INSTANCE) || (propInfo.kind === Prim2DPropInfo.PROPKIND_DYNAMIC)) {
  2567. var propMask = propInfo.flagId;
  2568. this.onPrimitivePropertyDirty(propMask);
  2569. }
  2570. };
  2571. SmartPropertyPrim.prototype.onPrimitivePropertyDirty = function (propFlagId) {
  2572. this.onPrimBecomesDirty();
  2573. this._instanceDirtyFlags |= propFlagId;
  2574. };
  2575. SmartPropertyPrim.prototype.handleGroupChanged = function (prop) {
  2576. };
  2577. SmartPropertyPrim.prototype._resetPropertiesDirty = function () {
  2578. _super.prototype._resetPropertiesDirty.call(this);
  2579. this._clearFlags(SmartPropertyPrim_1.flagPrimInDirtyList | SmartPropertyPrim_1.flagNeedRefresh);
  2580. };
  2581. Object.defineProperty(SmartPropertyPrim.prototype, "levelBoundingInfo", {
  2582. /**
  2583. * Retrieve the boundingInfo for this Primitive, computed based on the primitive itself and NOT its children
  2584. */
  2585. get: function () {
  2586. if (this._isFlagSet(SmartPropertyPrim_1.flagLevelBoundingInfoDirty)) {
  2587. this.updateLevelBoundingInfo();
  2588. this._clearFlags(SmartPropertyPrim_1.flagLevelBoundingInfoDirty);
  2589. }
  2590. return this._levelBoundingInfo;
  2591. },
  2592. enumerable: true,
  2593. configurable: true
  2594. });
  2595. /**
  2596. * This method must be overridden by a given Primitive implementation to compute its boundingInfo
  2597. */
  2598. SmartPropertyPrim.prototype.updateLevelBoundingInfo = function () {
  2599. };
  2600. /**
  2601. * Property method called when the Primitive becomes dirty
  2602. */
  2603. SmartPropertyPrim.prototype.onPrimBecomesDirty = function () {
  2604. };
  2605. /**
  2606. * Check if a given flag is set
  2607. * @param flag the flag value
  2608. * @return true if set, false otherwise
  2609. */
  2610. SmartPropertyPrim.prototype._isFlagSet = function (flag) {
  2611. return (this._flags & flag) !== 0;
  2612. };
  2613. /**
  2614. * Check if all given flags are set
  2615. * @param flags the flags ORed
  2616. * @return true if all the flags are set, false otherwise
  2617. */
  2618. SmartPropertyPrim.prototype._areAllFlagsSet = function (flags) {
  2619. return (this._flags & flags) === flags;
  2620. };
  2621. /**
  2622. * Check if at least one flag of the given flags is set
  2623. * @param flags the flags ORed
  2624. * @return true if at least one flag is set, false otherwise
  2625. */
  2626. SmartPropertyPrim.prototype._areSomeFlagsSet = function (flags) {
  2627. return (this._flags & flags) !== 0;
  2628. };
  2629. /**
  2630. * Clear the given flags
  2631. * @param flags the flags to clear
  2632. */
  2633. SmartPropertyPrim.prototype._clearFlags = function (flags) {
  2634. this._flags &= ~flags;
  2635. };
  2636. /**
  2637. * Set the given flags to true state
  2638. * @param flags the flags ORed to set
  2639. * @return the flags state before this call
  2640. */
  2641. SmartPropertyPrim.prototype._setFlags = function (flags) {
  2642. var cur = this._flags;
  2643. this._flags |= flags;
  2644. return cur;
  2645. };
  2646. /**
  2647. * Change the state of the given flags
  2648. * @param flags the flags ORed to change
  2649. * @param state true to set them, false to clear them
  2650. */
  2651. SmartPropertyPrim.prototype._changeFlags = function (flags, state) {
  2652. if (state) {
  2653. this._flags |= flags;
  2654. }
  2655. else {
  2656. this._flags &= ~flags;
  2657. }
  2658. };
  2659. return SmartPropertyPrim;
  2660. }(SmartPropertyBase));
  2661. SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT = 0;
  2662. SmartPropertyPrim.flagNoPartOfLayout = 0x0000001; // set if the primitive's position/size must not be computed by Layout Engine
  2663. SmartPropertyPrim.flagLevelBoundingInfoDirty = 0x0000002; // set if the primitive's level bounding box (not including children) is dirty
  2664. SmartPropertyPrim.flagModelDirty = 0x0000004; // set if the model must be changed
  2665. SmartPropertyPrim.flagLayoutDirty = 0x0000008; // set if the layout must be computed
  2666. SmartPropertyPrim.flagLevelVisible = 0x0000010; // set if the primitive is set as visible for its level only
  2667. SmartPropertyPrim.flagBoundingInfoDirty = 0x0000020; // set if the primitive's overall bounding box (including children) is dirty
  2668. SmartPropertyPrim.flagIsPickable = 0x0000040; // set if the primitive can be picked during interaction
  2669. SmartPropertyPrim.flagIsVisible = 0x0000080; // set if the primitive is concretely visible (use the levelVisible of parents)
  2670. SmartPropertyPrim.flagVisibilityChanged = 0x0000100; // set if there was a transition between visible/hidden status
  2671. SmartPropertyPrim.flagPositioningDirty = 0x0000200; // set if the primitive positioning must be computed
  2672. SmartPropertyPrim.flagTrackedGroup = 0x0000400; // set if the group2D is tracking a scene node
  2673. SmartPropertyPrim.flagWorldCacheChanged = 0x0000800; // set if the cached bitmap of a world space canvas changed
  2674. SmartPropertyPrim.flagChildrenFlatZOrder = 0x0001000; // set if all the children (direct and indirect) will share the same Z-Order
  2675. SmartPropertyPrim.flagZOrderDirty = 0x0002000; // set if the Z-Order for this prim and its children must be recomputed
  2676. SmartPropertyPrim.flagActualOpacityDirty = 0x0004000; // set if the actualOpactity should be recomputed
  2677. SmartPropertyPrim.flagPrimInDirtyList = 0x0008000; // set if the primitive is in the primDirtyList
  2678. SmartPropertyPrim.flagIsContainer = 0x0010000; // set if the primitive is a container
  2679. SmartPropertyPrim.flagNeedRefresh = 0x0020000; // set if the primitive wasn't successful at refresh
  2680. SmartPropertyPrim.flagActualScaleDirty = 0x0040000; // set if the actualScale property needs to be recomputed
  2681. SmartPropertyPrim.flagDontInheritParentScale = 0x0080000; // set if the actualScale must not use its parent's scale to be computed
  2682. SmartPropertyPrim.flagGlobalTransformDirty = 0x0100000; // set if the global transform must be recomputed due to a local transform change
  2683. SmartPropertyPrim.flagLayoutBoundingInfoDirty = 0x0200000; // set if the layout bounding info is dirty
  2684. SmartPropertyPrim = SmartPropertyPrim_1 = __decorate([
  2685. BABYLON.className("SmartPropertyPrim", "BABYLON")
  2686. ], SmartPropertyPrim);
  2687. BABYLON.SmartPropertyPrim = SmartPropertyPrim;
  2688. function dependencyProperty(propId, piStore, mode, updateSourceTrigger) {
  2689. if (mode === void 0) { mode = DataBinding.MODE_TWOWAY; }
  2690. if (updateSourceTrigger === void 0) { updateSourceTrigger = DataBinding.UPDATESOURCETRIGGER_PROPERTYCHANGED; }
  2691. return SmartPropertyBase._hookProperty(propId, piStore, Prim2DPropInfo.PROPKIND_DYNAMIC, { bindingMode: mode, bindingUpdateSourceTrigger: updateSourceTrigger });
  2692. }
  2693. BABYLON.dependencyProperty = dependencyProperty;
  2694. function modelLevelProperty(propId, piStore, typeLevelCompare, dirtyBoundingInfo, dirtyParentBoundingBox) {
  2695. if (typeLevelCompare === void 0) { typeLevelCompare = false; }
  2696. if (dirtyBoundingInfo === void 0) { dirtyBoundingInfo = false; }
  2697. if (dirtyParentBoundingBox === void 0) { dirtyParentBoundingBox = false; }
  2698. return SmartPropertyBase._hookProperty(propId, piStore, Prim2DPropInfo.PROPKIND_MODEL, { typeLevelCompare: typeLevelCompare, dirtyBoundingInfo: dirtyBoundingInfo, dirtyParentBoundingBox: dirtyParentBoundingBox });
  2699. }
  2700. BABYLON.modelLevelProperty = modelLevelProperty;
  2701. function instanceLevelProperty(propId, piStore, typeLevelCompare, dirtyBoundingInfo, dirtyParentBoundingBox) {
  2702. if (typeLevelCompare === void 0) { typeLevelCompare = false; }
  2703. if (dirtyBoundingInfo === void 0) { dirtyBoundingInfo = false; }
  2704. if (dirtyParentBoundingBox === void 0) { dirtyParentBoundingBox = false; }
  2705. return SmartPropertyBase._hookProperty(propId, piStore, Prim2DPropInfo.PROPKIND_INSTANCE, { typeLevelCompare: typeLevelCompare, dirtyBoundingInfo: dirtyBoundingInfo, dirtyParentBoundingBox: dirtyParentBoundingBox });
  2706. }
  2707. BABYLON.instanceLevelProperty = instanceLevelProperty;
  2708. function dynamicLevelProperty(propId, piStore, typeLevelCompare, dirtyBoundingInfo, dirtyParentBoundingBox) {
  2709. if (typeLevelCompare === void 0) { typeLevelCompare = false; }
  2710. if (dirtyBoundingInfo === void 0) { dirtyBoundingInfo = false; }
  2711. if (dirtyParentBoundingBox === void 0) { dirtyParentBoundingBox = false; }
  2712. return SmartPropertyBase._hookProperty(propId, piStore, Prim2DPropInfo.PROPKIND_DYNAMIC, { typeLevelCompare: typeLevelCompare, dirtyBoundingInfo: dirtyBoundingInfo, dirtyParentBoundingBox: dirtyParentBoundingBox });
  2713. }
  2714. BABYLON.dynamicLevelProperty = dynamicLevelProperty;
  2715. var DataBinding_1, SmartPropertyBase_1, SmartPropertyPrim_1;
  2716. })(BABYLON || (BABYLON = {}));
  2717. //# sourceMappingURL=babylon.smartPropertyPrim.js.map
  2718. var __extends = (this && this.__extends) || function (d, b) {
  2719. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  2720. function __() { this.constructor = d; }
  2721. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2722. };
  2723. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2724. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  2725. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  2726. 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;
  2727. return c > 3 && r && Object.defineProperty(target, key, r), r;
  2728. };
  2729. var BABYLON;
  2730. (function (BABYLON) {
  2731. var PrepareRender2DContext = (function () {
  2732. function PrepareRender2DContext() {
  2733. this.forceRefreshPrimitive = false;
  2734. }
  2735. return PrepareRender2DContext;
  2736. }());
  2737. BABYLON.PrepareRender2DContext = PrepareRender2DContext;
  2738. var Render2DContext = (function () {
  2739. function Render2DContext(renderMode) {
  2740. this._renderMode = renderMode;
  2741. this.useInstancing = false;
  2742. this.groupInfoPartData = null;
  2743. this.partDataStartIndex = this.partDataEndIndex = null;
  2744. this.instancedBuffers = null;
  2745. }
  2746. Object.defineProperty(Render2DContext.prototype, "renderMode", {
  2747. /**
  2748. * Define which render Mode should be used to render the primitive: one of Render2DContext.RenderModeXxxx property
  2749. */
  2750. get: function () {
  2751. return this._renderMode;
  2752. },
  2753. enumerable: true,
  2754. configurable: true
  2755. });
  2756. Object.defineProperty(Render2DContext, "RenderModeOpaque", {
  2757. /**
  2758. * The set of primitives to render is opaque.
  2759. * This is the first rendering pass. All Opaque primitives are rendered. Depth Compare and Write are both enabled.
  2760. */
  2761. get: function () {
  2762. return Render2DContext._renderModeOpaque;
  2763. },
  2764. enumerable: true,
  2765. configurable: true
  2766. });
  2767. Object.defineProperty(Render2DContext, "RenderModeAlphaTest", {
  2768. /**
  2769. * The set of primitives to render is using Alpha Test (aka masking).
  2770. * 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.
  2771. */
  2772. get: function () {
  2773. return Render2DContext._renderModeAlphaTest;
  2774. },
  2775. enumerable: true,
  2776. configurable: true
  2777. });
  2778. Object.defineProperty(Render2DContext, "RenderModeTransparent", {
  2779. /**
  2780. * The set of primitives to render is transparent.
  2781. * 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.
  2782. */
  2783. get: function () {
  2784. return Render2DContext._renderModeTransparent;
  2785. },
  2786. enumerable: true,
  2787. configurable: true
  2788. });
  2789. return Render2DContext;
  2790. }());
  2791. Render2DContext._renderModeOpaque = 1;
  2792. Render2DContext._renderModeAlphaTest = 2;
  2793. Render2DContext._renderModeTransparent = 3;
  2794. BABYLON.Render2DContext = Render2DContext;
  2795. /**
  2796. * This class store information for the pointerEventObservable Observable.
  2797. * 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.
  2798. */
  2799. var PrimitivePointerInfo = (function () {
  2800. function PrimitivePointerInfo() {
  2801. this.primitivePointerPos = BABYLON.Vector2.Zero();
  2802. this.tilt = BABYLON.Vector2.Zero();
  2803. this.cancelBubble = false;
  2804. }
  2805. Object.defineProperty(PrimitivePointerInfo, "PointerOver", {
  2806. // 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.
  2807. /**
  2808. * This event type is raised when a pointing device is moved into the hit test boundaries of a primitive.
  2809. * Bubbles: yes
  2810. */
  2811. get: function () {
  2812. return PrimitivePointerInfo._pointerOver;
  2813. },
  2814. enumerable: true,
  2815. configurable: true
  2816. });
  2817. Object.defineProperty(PrimitivePointerInfo, "PointerEnter", {
  2818. /**
  2819. * This event type is raised when a pointing device is moved into the hit test boundaries of a primitive or one of its descendants.
  2820. * Bubbles: no
  2821. */
  2822. get: function () {
  2823. return PrimitivePointerInfo._pointerEnter;
  2824. },
  2825. enumerable: true,
  2826. configurable: true
  2827. });
  2828. Object.defineProperty(PrimitivePointerInfo, "PointerDown", {
  2829. /**
  2830. * 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.
  2831. * Bubbles: yes
  2832. */
  2833. get: function () {
  2834. return PrimitivePointerInfo._pointerDown;
  2835. },
  2836. enumerable: true,
  2837. configurable: true
  2838. });
  2839. Object.defineProperty(PrimitivePointerInfo, "PointerMouseWheel", {
  2840. /**
  2841. * This event type is raised when the pointer is a mouse and it's wheel is rolling
  2842. * Bubbles: yes
  2843. */
  2844. get: function () {
  2845. return PrimitivePointerInfo._pointerMouseWheel;
  2846. },
  2847. enumerable: true,
  2848. configurable: true
  2849. });
  2850. Object.defineProperty(PrimitivePointerInfo, "PointerMove", {
  2851. /**
  2852. * 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.
  2853. * Bubbles: yes
  2854. */
  2855. get: function () {
  2856. return PrimitivePointerInfo._pointerMove;
  2857. },
  2858. enumerable: true,
  2859. configurable: true
  2860. });
  2861. Object.defineProperty(PrimitivePointerInfo, "PointerUp", {
  2862. /**
  2863. * 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.
  2864. * Bubbles: yes
  2865. */
  2866. get: function () {
  2867. return PrimitivePointerInfo._pointerUp;
  2868. },
  2869. enumerable: true,
  2870. configurable: true
  2871. });
  2872. Object.defineProperty(PrimitivePointerInfo, "PointerOut", {
  2873. /**
  2874. * This event type is raised when a pointing device is moved out of the hit test the boundaries of a primitive.
  2875. * Bubbles: yes
  2876. */
  2877. get: function () {
  2878. return PrimitivePointerInfo._pointerOut;
  2879. },
  2880. enumerable: true,
  2881. configurable: true
  2882. });
  2883. Object.defineProperty(PrimitivePointerInfo, "PointerLeave", {
  2884. /**
  2885. * This event type is raised when a pointing device is moved out of the hit test boundaries of a primitive and all its descendants.
  2886. * Bubbles: no
  2887. */
  2888. get: function () {
  2889. return PrimitivePointerInfo._pointerLeave;
  2890. },
  2891. enumerable: true,
  2892. configurable: true
  2893. });
  2894. Object.defineProperty(PrimitivePointerInfo, "PointerGotCapture", {
  2895. /**
  2896. * 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.
  2897. * Bubbles: yes
  2898. */
  2899. get: function () {
  2900. return PrimitivePointerInfo._pointerGotCapture;
  2901. },
  2902. enumerable: true,
  2903. configurable: true
  2904. });
  2905. Object.defineProperty(PrimitivePointerInfo, "PointerLostCapture", {
  2906. /**
  2907. * This event type is raised after pointer capture is released for a pointer.
  2908. * Bubbles: yes
  2909. */
  2910. get: function () {
  2911. return PrimitivePointerInfo._pointerLostCapture;
  2912. },
  2913. enumerable: true,
  2914. configurable: true
  2915. });
  2916. Object.defineProperty(PrimitivePointerInfo, "MouseWheelPrecision", {
  2917. get: function () {
  2918. return PrimitivePointerInfo._mouseWheelPrecision;
  2919. },
  2920. enumerable: true,
  2921. configurable: true
  2922. });
  2923. PrimitivePointerInfo.prototype.updateRelatedTarget = function (prim, primPointerPos) {
  2924. this.relatedTarget = prim;
  2925. this.relatedTargetPointerPos = primPointerPos;
  2926. };
  2927. PrimitivePointerInfo.getEventTypeName = function (mask) {
  2928. switch (mask) {
  2929. case PrimitivePointerInfo.PointerOver: return "PointerOver";
  2930. case PrimitivePointerInfo.PointerEnter: return "PointerEnter";
  2931. case PrimitivePointerInfo.PointerDown: return "PointerDown";
  2932. case PrimitivePointerInfo.PointerMouseWheel: return "PointerMouseWheel";
  2933. case PrimitivePointerInfo.PointerMove: return "PointerMove";
  2934. case PrimitivePointerInfo.PointerUp: return "PointerUp";
  2935. case PrimitivePointerInfo.PointerOut: return "PointerOut";
  2936. case PrimitivePointerInfo.PointerLeave: return "PointerLeave";
  2937. case PrimitivePointerInfo.PointerGotCapture: return "PointerGotCapture";
  2938. case PrimitivePointerInfo.PointerLostCapture: return "PointerLostCapture";
  2939. }
  2940. };
  2941. return PrimitivePointerInfo;
  2942. }());
  2943. PrimitivePointerInfo._pointerOver = 0x0001;
  2944. PrimitivePointerInfo._pointerEnter = 0x0002;
  2945. PrimitivePointerInfo._pointerDown = 0x0004;
  2946. PrimitivePointerInfo._pointerMouseWheel = 0x0008;
  2947. PrimitivePointerInfo._pointerMove = 0x0010;
  2948. PrimitivePointerInfo._pointerUp = 0x0020;
  2949. PrimitivePointerInfo._pointerOut = 0x0040;
  2950. PrimitivePointerInfo._pointerLeave = 0x0080;
  2951. PrimitivePointerInfo._pointerGotCapture = 0x0100;
  2952. PrimitivePointerInfo._pointerLostCapture = 0x0200;
  2953. PrimitivePointerInfo._mouseWheelPrecision = 3.0;
  2954. BABYLON.PrimitivePointerInfo = PrimitivePointerInfo;
  2955. /**
  2956. * Defines the horizontal and vertical alignment information for a Primitive.
  2957. */
  2958. var PrimitiveAlignment = PrimitiveAlignment_1 = (function () {
  2959. function PrimitiveAlignment(changeCallback) {
  2960. this._changedCallback = changeCallback;
  2961. this._horizontal = PrimitiveAlignment_1.AlignLeft;
  2962. this._vertical = PrimitiveAlignment_1.AlignBottom;
  2963. }
  2964. Object.defineProperty(PrimitiveAlignment, "AlignLeft", {
  2965. /**
  2966. * Alignment is made relative to the left edge of the Primitive. Valid for horizontal alignment only.
  2967. */
  2968. get: function () { return PrimitiveAlignment_1._AlignLeft; },
  2969. enumerable: true,
  2970. configurable: true
  2971. });
  2972. Object.defineProperty(PrimitiveAlignment, "AlignTop", {
  2973. /**
  2974. * Alignment is made relative to the top edge of the Primitive. Valid for vertical alignment only.
  2975. */
  2976. get: function () { return PrimitiveAlignment_1._AlignTop; },
  2977. enumerable: true,
  2978. configurable: true
  2979. });
  2980. Object.defineProperty(PrimitiveAlignment, "AlignRight", {
  2981. /**
  2982. * Alignment is made relative to the right edge of the Primitive. Valid for horizontal alignment only.
  2983. */
  2984. get: function () { return PrimitiveAlignment_1._AlignRight; },
  2985. enumerable: true,
  2986. configurable: true
  2987. });
  2988. Object.defineProperty(PrimitiveAlignment, "AlignBottom", {
  2989. /**
  2990. * Alignment is made relative to the bottom edge of the Primitive. Valid for vertical alignment only.
  2991. */
  2992. get: function () { return PrimitiveAlignment_1._AlignBottom; },
  2993. enumerable: true,
  2994. configurable: true
  2995. });
  2996. Object.defineProperty(PrimitiveAlignment, "AlignCenter", {
  2997. /**
  2998. * Alignment is made to center the content from equal distance to the opposite edges of the Primitive
  2999. */
  3000. get: function () { return PrimitiveAlignment_1._AlignCenter; },
  3001. enumerable: true,
  3002. configurable: true
  3003. });
  3004. Object.defineProperty(PrimitiveAlignment, "AlignStretch", {
  3005. /**
  3006. * The content is stretched toward the opposite edges of the Primitive
  3007. */
  3008. get: function () { return PrimitiveAlignment_1._AlignStretch; },
  3009. enumerable: true,
  3010. configurable: true
  3011. });
  3012. Object.defineProperty(PrimitiveAlignment.prototype, "horizontal", {
  3013. /**
  3014. * Get/set the horizontal alignment. Use one of the AlignXXX static properties of this class
  3015. */
  3016. get: function () {
  3017. return this._horizontal;
  3018. },
  3019. set: function (value) {
  3020. if (this._horizontal === value) {
  3021. return;
  3022. }
  3023. this._horizontal = value;
  3024. this.onChangeCallback();
  3025. },
  3026. enumerable: true,
  3027. configurable: true
  3028. });
  3029. Object.defineProperty(PrimitiveAlignment.prototype, "vertical", {
  3030. /**
  3031. * Get/set the vertical alignment. Use one of the AlignXXX static properties of this class
  3032. */
  3033. get: function () {
  3034. return this._vertical;
  3035. },
  3036. set: function (value) {
  3037. if (this._vertical === value) {
  3038. return;
  3039. }
  3040. this._vertical = value;
  3041. this.onChangeCallback();
  3042. },
  3043. enumerable: true,
  3044. configurable: true
  3045. });
  3046. PrimitiveAlignment.prototype.onChangeCallback = function () {
  3047. if (this._changedCallback) {
  3048. this._changedCallback();
  3049. }
  3050. };
  3051. /**
  3052. * Set the horizontal alignment from a string value.
  3053. * @param text can be either: 'left','right','center','stretch'
  3054. */
  3055. PrimitiveAlignment.prototype.setHorizontal = function (text) {
  3056. var v = text.trim().toLocaleLowerCase();
  3057. switch (v) {
  3058. case "left":
  3059. this.horizontal = PrimitiveAlignment_1.AlignLeft;
  3060. return;
  3061. case "right":
  3062. this.horizontal = PrimitiveAlignment_1.AlignRight;
  3063. return;
  3064. case "center":
  3065. this.horizontal = PrimitiveAlignment_1.AlignCenter;
  3066. return;
  3067. case "stretch":
  3068. this.horizontal = PrimitiveAlignment_1.AlignStretch;
  3069. return;
  3070. }
  3071. };
  3072. /**
  3073. * Set the vertical alignment from a string value.
  3074. * @param text can be either: 'top','bottom','center','stretch'
  3075. */
  3076. PrimitiveAlignment.prototype.setVertical = function (text) {
  3077. var v = text.trim().toLocaleLowerCase();
  3078. switch (v) {
  3079. case "top":
  3080. this.vertical = PrimitiveAlignment_1.AlignTop;
  3081. return;
  3082. case "bottom":
  3083. this.vertical = PrimitiveAlignment_1.AlignBottom;
  3084. return;
  3085. case "center":
  3086. this.vertical = PrimitiveAlignment_1.AlignCenter;
  3087. return;
  3088. case "stretch":
  3089. this.vertical = PrimitiveAlignment_1.AlignStretch;
  3090. return;
  3091. }
  3092. };
  3093. /**
  3094. * Set the horizontal and or vertical alignments from a string value.
  3095. * @param text can be: [<h:|horizontal:><left|right|center|stretch>], [<v:|vertical:><top|bottom|center|stretch>]
  3096. */
  3097. PrimitiveAlignment.prototype.fromString = function (value) {
  3098. var m = value.trim().split(",");
  3099. if (m.length === 1) {
  3100. this.setHorizontal(m[0]);
  3101. this.setVertical(m[0]);
  3102. }
  3103. else {
  3104. for (var _i = 0, m_1 = m; _i < m_1.length; _i++) {
  3105. var v = m_1[_i];
  3106. v = v.toLocaleLowerCase().trim();
  3107. // Horizontal
  3108. var i = v.indexOf("h:");
  3109. if (i === -1) {
  3110. i = v.indexOf("horizontal:");
  3111. }
  3112. if (i !== -1) {
  3113. v = v.substr(v.indexOf(":") + 1);
  3114. this.setHorizontal(v);
  3115. continue;
  3116. }
  3117. // Vertical
  3118. i = v.indexOf("v:");
  3119. if (i === -1) {
  3120. i = v.indexOf("vertical:");
  3121. }
  3122. if (i !== -1) {
  3123. v = v.substr(v.indexOf(":") + 1);
  3124. this.setVertical(v);
  3125. continue;
  3126. }
  3127. }
  3128. }
  3129. };
  3130. PrimitiveAlignment.prototype.copyFrom = function (pa) {
  3131. this._horizontal = pa._horizontal;
  3132. this._vertical = pa._vertical;
  3133. this.onChangeCallback();
  3134. };
  3135. Object.defineProperty(PrimitiveAlignment.prototype, "isDefault", {
  3136. get: function () {
  3137. return this.horizontal === PrimitiveAlignment_1.AlignLeft && this.vertical === PrimitiveAlignment_1.AlignBottom;
  3138. },
  3139. enumerable: true,
  3140. configurable: true
  3141. });
  3142. return PrimitiveAlignment;
  3143. }());
  3144. PrimitiveAlignment._AlignLeft = 1;
  3145. PrimitiveAlignment._AlignTop = 1; // Same as left
  3146. PrimitiveAlignment._AlignRight = 2;
  3147. PrimitiveAlignment._AlignBottom = 2; // Same as right
  3148. PrimitiveAlignment._AlignCenter = 3;
  3149. PrimitiveAlignment._AlignStretch = 4;
  3150. PrimitiveAlignment = PrimitiveAlignment_1 = __decorate([
  3151. BABYLON.className("PrimitiveAlignment", "BABYLON")
  3152. ], PrimitiveAlignment);
  3153. BABYLON.PrimitiveAlignment = PrimitiveAlignment;
  3154. /**
  3155. * Stores information about a Primitive that was intersected
  3156. */
  3157. var PrimitiveIntersectedInfo = (function () {
  3158. function PrimitiveIntersectedInfo(prim, intersectionLocation) {
  3159. this.prim = prim;
  3160. this.intersectionLocation = intersectionLocation;
  3161. }
  3162. return PrimitiveIntersectedInfo;
  3163. }());
  3164. BABYLON.PrimitiveIntersectedInfo = PrimitiveIntersectedInfo;
  3165. /**
  3166. * Define a thickness toward every edges of a Primitive to allow margin and padding.
  3167. * The thickness can be expressed as pixels, percentages, inherit the value of the parent primitive or be auto.
  3168. */
  3169. var PrimitiveThickness = PrimitiveThickness_1 = (function () {
  3170. function PrimitiveThickness(parentAccess, changedCallback) {
  3171. this._parentAccess = parentAccess;
  3172. this._changedCallback = changedCallback;
  3173. this._pixels = new Array(4);
  3174. this._percentages = new Array(4);
  3175. this._setType(0, PrimitiveThickness_1.Auto);
  3176. this._setType(1, PrimitiveThickness_1.Auto);
  3177. this._setType(2, PrimitiveThickness_1.Auto);
  3178. this._setType(3, PrimitiveThickness_1.Auto);
  3179. this._pixels[0] = 0;
  3180. this._pixels[1] = 0;
  3181. this._pixels[2] = 0;
  3182. this._pixels[3] = 0;
  3183. }
  3184. /**
  3185. * Set the thickness from a string value
  3186. * @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.
  3187. * Values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  3188. */
  3189. PrimitiveThickness.prototype.fromString = function (thickness) {
  3190. this._clear();
  3191. var m = thickness.trim().split(",");
  3192. // Special case, one value to apply to all edges
  3193. if (m.length === 1 && thickness.indexOf(":") === -1) {
  3194. this._setStringValue(m[0], 0, false);
  3195. this._setStringValue(m[0], 1, false);
  3196. this._setStringValue(m[0], 2, false);
  3197. this._setStringValue(m[0], 3, false);
  3198. this.onChangeCallback();
  3199. return;
  3200. }
  3201. var res = false;
  3202. for (var _i = 0, m_2 = m; _i < m_2.length; _i++) {
  3203. var cm = m_2[_i];
  3204. res = this._extractString(cm, false) || res;
  3205. }
  3206. if (!res) {
  3207. throw new Error("Can't parse the string to create a PrimitiveMargin object, format must be: 'top: <value>, left:<value>, right:<value>, bottom:<value>");
  3208. }
  3209. // Check the margin that weren't set and set them in auto
  3210. if ((this._flags & 0x000F) === 0)
  3211. this._flags |= PrimitiveThickness_1.Pixel << 0;
  3212. if ((this._flags & 0x00F0) === 0)
  3213. this._flags |= PrimitiveThickness_1.Pixel << 4;
  3214. if ((this._flags & 0x0F00) === 0)
  3215. this._flags |= PrimitiveThickness_1.Pixel << 8;
  3216. if ((this._flags & 0xF000) === 0)
  3217. this._flags |= PrimitiveThickness_1.Pixel << 12;
  3218. this.onChangeCallback();
  3219. };
  3220. /**
  3221. * Set the thickness from multiple string
  3222. * Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  3223. * @param top the top thickness to set
  3224. * @param left the left thickness to set
  3225. * @param right the right thickness to set
  3226. * @param bottom the bottom thickness to set
  3227. */
  3228. PrimitiveThickness.prototype.fromStrings = function (top, left, right, bottom) {
  3229. this._clear();
  3230. this._setStringValue(top, 0, false);
  3231. this._setStringValue(left, 1, false);
  3232. this._setStringValue(right, 2, false);
  3233. this._setStringValue(bottom, 3, false);
  3234. this.onChangeCallback();
  3235. return this;
  3236. };
  3237. /**
  3238. * Set the thickness from pixel values
  3239. * @param top the top thickness in pixels to set
  3240. * @param left the left thickness in pixels to set
  3241. * @param right the right thickness in pixels to set
  3242. * @param bottom the bottom thickness in pixels to set
  3243. */
  3244. PrimitiveThickness.prototype.fromPixels = function (top, left, right, bottom) {
  3245. this._clear();
  3246. this._pixels[0] = top;
  3247. this._pixels[1] = left;
  3248. this._pixels[2] = right;
  3249. this._pixels[3] = bottom;
  3250. this.onChangeCallback();
  3251. return this;
  3252. };
  3253. /**
  3254. * Apply the same pixel value to all edges
  3255. * @param margin the value to set, in pixels.
  3256. */
  3257. PrimitiveThickness.prototype.fromUniformPixels = function (margin) {
  3258. this._clear();
  3259. this._pixels[0] = margin;
  3260. this._pixels[1] = margin;
  3261. this._pixels[2] = margin;
  3262. this._pixels[3] = margin;
  3263. this.onChangeCallback();
  3264. return this;
  3265. };
  3266. PrimitiveThickness.prototype.copyFrom = function (pt) {
  3267. this._clear();
  3268. for (var i = 0; i < 4; i++) {
  3269. this._pixels[i] = pt._pixels[i];
  3270. this._percentages[i] = pt._percentages[i];
  3271. }
  3272. this._flags = pt._flags;
  3273. this.onChangeCallback();
  3274. };
  3275. /**
  3276. * Set all edges in auto
  3277. */
  3278. PrimitiveThickness.prototype.auto = function () {
  3279. this._clear();
  3280. this._flags = (PrimitiveThickness_1.Auto << 0) | (PrimitiveThickness_1.Auto << 4) | (PrimitiveThickness_1.Auto << 8) | (PrimitiveThickness_1.Auto << 12);
  3281. this._pixels[0] = 0;
  3282. this._pixels[1] = 0;
  3283. this._pixels[2] = 0;
  3284. this._pixels[3] = 0;
  3285. this.onChangeCallback();
  3286. return this;
  3287. };
  3288. PrimitiveThickness.prototype._clear = function () {
  3289. this._flags = 0;
  3290. this._pixels[0] = 0;
  3291. this._pixels[1] = 0;
  3292. this._pixels[2] = 0;
  3293. this._pixels[3] = 0;
  3294. this._percentages[0] = null;
  3295. this._percentages[1] = null;
  3296. this._percentages[2] = null;
  3297. this._percentages[3] = null;
  3298. };
  3299. PrimitiveThickness.prototype._extractString = function (value, emitChanged) {
  3300. var v = value.trim().toLocaleLowerCase();
  3301. if (v.indexOf("top:") === 0) {
  3302. v = v.substr(4).trim();
  3303. return this._setStringValue(v, 0, emitChanged);
  3304. }
  3305. if (v.indexOf("left:") === 0) {
  3306. v = v.substr(5).trim();
  3307. return this._setStringValue(v, 1, emitChanged);
  3308. }
  3309. if (v.indexOf("right:") === 0) {
  3310. v = v.substr(6).trim();
  3311. return this._setStringValue(v, 2, emitChanged);
  3312. }
  3313. if (v.indexOf("bottom:") === 0) {
  3314. v = v.substr(7).trim();
  3315. return this._setStringValue(v, 3, emitChanged);
  3316. }
  3317. return false;
  3318. };
  3319. PrimitiveThickness.prototype._setStringValue = function (value, index, emitChanged) {
  3320. // Check for auto
  3321. var v = value.trim().toLocaleLowerCase();
  3322. if (v === "auto") {
  3323. if (this._isType(index, PrimitiveThickness_1.Auto)) {
  3324. return true;
  3325. }
  3326. this._setType(index, PrimitiveThickness_1.Auto);
  3327. this._pixels[index] = 0;
  3328. if (emitChanged) {
  3329. this.onChangeCallback();
  3330. }
  3331. }
  3332. else if (v === "inherit") {
  3333. if (this._isType(index, PrimitiveThickness_1.Inherit)) {
  3334. return true;
  3335. }
  3336. this._setType(index, PrimitiveThickness_1.Inherit);
  3337. this._pixels[index] = null;
  3338. if (emitChanged) {
  3339. this.onChangeCallback();
  3340. }
  3341. }
  3342. else {
  3343. var pI = v.indexOf("%");
  3344. // Check for percentage
  3345. if (pI !== -1) {
  3346. var n_1 = v.substr(0, pI);
  3347. var number_1 = Math.round(Number(n_1)) / 100; // Normalize the percentage to [0;1] with a 0.01 precision
  3348. if (this._isType(index, PrimitiveThickness_1.Percentage) && (this._percentages[index] === number_1)) {
  3349. return true;
  3350. }
  3351. this._setType(index, PrimitiveThickness_1.Percentage);
  3352. if (isNaN(number_1)) {
  3353. return false;
  3354. }
  3355. this._percentages[index] = number_1;
  3356. if (emitChanged) {
  3357. this.onChangeCallback();
  3358. }
  3359. return true;
  3360. }
  3361. // Check for pixel
  3362. var n = void 0;
  3363. pI = v.indexOf("px");
  3364. if (pI !== -1) {
  3365. n = v.substr(0, pI).trim();
  3366. }
  3367. else {
  3368. n = v;
  3369. }
  3370. var number = Number(n);
  3371. if (this._isType(index, PrimitiveThickness_1.Pixel) && (this._pixels[index] === number)) {
  3372. return true;
  3373. }
  3374. if (isNaN(number)) {
  3375. return false;
  3376. }
  3377. this._pixels[index] = number;
  3378. this._setType(index, PrimitiveThickness_1.Pixel);
  3379. if (emitChanged) {
  3380. this.onChangeCallback();
  3381. }
  3382. return true;
  3383. }
  3384. };
  3385. PrimitiveThickness.prototype._setPixels = function (value, index, emitChanged) {
  3386. // 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
  3387. value = Math.round(value);
  3388. if (this._isType(index, PrimitiveThickness_1.Pixel) && this._pixels[index] === value) {
  3389. return;
  3390. }
  3391. this._setType(index, PrimitiveThickness_1.Pixel);
  3392. this._pixels[index] = value;
  3393. if (emitChanged) {
  3394. this.onChangeCallback();
  3395. }
  3396. };
  3397. PrimitiveThickness.prototype._setPercentage = function (value, index, emitChanged) {
  3398. // Clip Value to bounds
  3399. value = Math.min(1, value);
  3400. value = Math.max(0, value);
  3401. value = Math.round(value * 100) / 100; // 0.01 precision
  3402. if (this._isType(index, PrimitiveThickness_1.Percentage) && this._percentages[index] === value) {
  3403. return;
  3404. }
  3405. this._setType(index, PrimitiveThickness_1.Percentage);
  3406. this._percentages[index] = value;
  3407. if (emitChanged) {
  3408. this.onChangeCallback();
  3409. }
  3410. };
  3411. PrimitiveThickness.prototype._getStringValue = function (index) {
  3412. var f = (this._flags >> (index * 4)) & 0xF;
  3413. switch (f) {
  3414. case PrimitiveThickness_1.Auto:
  3415. return "auto";
  3416. case PrimitiveThickness_1.Pixel:
  3417. return this._pixels[index] + "px";
  3418. case PrimitiveThickness_1.Percentage:
  3419. return this._percentages[index] * 100 + "%";
  3420. case PrimitiveThickness_1.Inherit:
  3421. return "inherit";
  3422. }
  3423. return "";
  3424. };
  3425. PrimitiveThickness.prototype._isType = function (index, type) {
  3426. var f = (this._flags >> (index * 4)) & 0xF;
  3427. return f === type;
  3428. };
  3429. PrimitiveThickness.prototype._getType = function (index, processInherit) {
  3430. var t = (this._flags >> (index * 4)) & 0xF;
  3431. if (processInherit && (t === PrimitiveThickness_1.Inherit)) {
  3432. var p = this._parentAccess();
  3433. if (p) {
  3434. return p._getType(index, true);
  3435. }
  3436. return PrimitiveThickness_1.Auto;
  3437. }
  3438. return t;
  3439. };
  3440. PrimitiveThickness.prototype._setType = function (index, type) {
  3441. this._flags &= ~(0xF << (index * 4));
  3442. this._flags |= type << (index * 4);
  3443. };
  3444. PrimitiveThickness.prototype.setTop = function (value) {
  3445. if (typeof value === "string") {
  3446. this._setStringValue(value, 0, true);
  3447. }
  3448. else {
  3449. this.topPixels = value;
  3450. }
  3451. };
  3452. PrimitiveThickness.prototype.setLeft = function (value) {
  3453. if (typeof value === "string") {
  3454. this._setStringValue(value, 1, true);
  3455. }
  3456. else {
  3457. this.leftPixels = value;
  3458. }
  3459. };
  3460. PrimitiveThickness.prototype.setRight = function (value) {
  3461. if (typeof value === "string") {
  3462. this._setStringValue(value, 2, true);
  3463. }
  3464. else {
  3465. this.rightPixels = value;
  3466. }
  3467. };
  3468. PrimitiveThickness.prototype.setBottom = function (value) {
  3469. if (typeof value === "string") {
  3470. this._setStringValue(value, 3, true);
  3471. }
  3472. else {
  3473. this.bottomPixels = value;
  3474. }
  3475. };
  3476. Object.defineProperty(PrimitiveThickness.prototype, "top", {
  3477. /**
  3478. * Get/set the top thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  3479. */
  3480. get: function () {
  3481. return this._getStringValue(0);
  3482. },
  3483. set: function (value) {
  3484. this._setStringValue(value, 0, true);
  3485. },
  3486. enumerable: true,
  3487. configurable: true
  3488. });
  3489. Object.defineProperty(PrimitiveThickness.prototype, "left", {
  3490. /**
  3491. * Get/set the left thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  3492. */
  3493. get: function () {
  3494. return this._getStringValue(1);
  3495. },
  3496. set: function (value) {
  3497. this._setStringValue(value, 1, true);
  3498. },
  3499. enumerable: true,
  3500. configurable: true
  3501. });
  3502. Object.defineProperty(PrimitiveThickness.prototype, "right", {
  3503. /**
  3504. * Get/set the right thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  3505. */
  3506. get: function () {
  3507. return this._getStringValue(2);
  3508. },
  3509. set: function (value) {
  3510. this._setStringValue(value, 2, true);
  3511. },
  3512. enumerable: true,
  3513. configurable: true
  3514. });
  3515. Object.defineProperty(PrimitiveThickness.prototype, "bottom", {
  3516. /**
  3517. * Get/set the bottom thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  3518. */
  3519. get: function () {
  3520. return this._getStringValue(3);
  3521. },
  3522. set: function (value) {
  3523. this._setStringValue(value, 3, true);
  3524. },
  3525. enumerable: true,
  3526. configurable: true
  3527. });
  3528. Object.defineProperty(PrimitiveThickness.prototype, "topPixels", {
  3529. /**
  3530. * Get/set the top thickness in pixel.
  3531. */
  3532. get: function () {
  3533. return this._pixels[0];
  3534. },
  3535. set: function (value) {
  3536. this._setPixels(value, 0, true);
  3537. },
  3538. enumerable: true,
  3539. configurable: true
  3540. });
  3541. Object.defineProperty(PrimitiveThickness.prototype, "leftPixels", {
  3542. /**
  3543. * Get/set the left thickness in pixel.
  3544. */
  3545. get: function () {
  3546. return this._pixels[1];
  3547. },
  3548. set: function (value) {
  3549. this._setPixels(value, 1, true);
  3550. },
  3551. enumerable: true,
  3552. configurable: true
  3553. });
  3554. Object.defineProperty(PrimitiveThickness.prototype, "rightPixels", {
  3555. /**
  3556. * Get/set the right thickness in pixel.
  3557. */
  3558. get: function () {
  3559. return this._pixels[2];
  3560. },
  3561. set: function (value) {
  3562. this._setPixels(value, 2, true);
  3563. },
  3564. enumerable: true,
  3565. configurable: true
  3566. });
  3567. Object.defineProperty(PrimitiveThickness.prototype, "bottomPixels", {
  3568. /**
  3569. * Get/set the bottom thickness in pixel.
  3570. */
  3571. get: function () {
  3572. return this._pixels[3];
  3573. },
  3574. set: function (value) {
  3575. this._setPixels(value, 3, true);
  3576. },
  3577. enumerable: true,
  3578. configurable: true
  3579. });
  3580. Object.defineProperty(PrimitiveThickness.prototype, "topPercentage", {
  3581. /**
  3582. * Get/set the top thickness in percentage.
  3583. * The get will return a valid value only if the edge type is percentage.
  3584. * The Set will change the edge mode if needed
  3585. */
  3586. get: function () {
  3587. return this._percentages[0];
  3588. },
  3589. set: function (value) {
  3590. this._setPercentage(value, 0, true);
  3591. },
  3592. enumerable: true,
  3593. configurable: true
  3594. });
  3595. Object.defineProperty(PrimitiveThickness.prototype, "leftPercentage", {
  3596. /**
  3597. * Get/set the left thickness in percentage.
  3598. * The get will return a valid value only if the edge mode is percentage.
  3599. * The Set will change the edge mode if needed
  3600. */
  3601. get: function () {
  3602. return this._percentages[1];
  3603. },
  3604. set: function (value) {
  3605. this._setPercentage(value, 1, true);
  3606. },
  3607. enumerable: true,
  3608. configurable: true
  3609. });
  3610. Object.defineProperty(PrimitiveThickness.prototype, "rightPercentage", {
  3611. /**
  3612. * Get/set the right thickness in percentage.
  3613. * The get will return a valid value only if the edge mode is percentage.
  3614. * The Set will change the edge mode if needed
  3615. */
  3616. get: function () {
  3617. return this._percentages[2];
  3618. },
  3619. set: function (value) {
  3620. this._setPercentage(value, 2, true);
  3621. },
  3622. enumerable: true,
  3623. configurable: true
  3624. });
  3625. Object.defineProperty(PrimitiveThickness.prototype, "bottomPercentage", {
  3626. /**
  3627. * Get/set the bottom thickness in percentage.
  3628. * The get will return a valid value only if the edge mode is percentage.
  3629. * The Set will change the edge mode if needed
  3630. */
  3631. get: function () {
  3632. return this._percentages[3];
  3633. },
  3634. set: function (value) {
  3635. this._setPercentage(value, 3, true);
  3636. },
  3637. enumerable: true,
  3638. configurable: true
  3639. });
  3640. Object.defineProperty(PrimitiveThickness.prototype, "topMode", {
  3641. /**
  3642. * Get/set the top mode. The setter shouldn't be used, other setters with value should be preferred
  3643. */
  3644. get: function () {
  3645. return this._getType(0, false);
  3646. },
  3647. set: function (mode) {
  3648. this._setType(0, mode);
  3649. },
  3650. enumerable: true,
  3651. configurable: true
  3652. });
  3653. Object.defineProperty(PrimitiveThickness.prototype, "leftMode", {
  3654. /**
  3655. * Get/set the left mode. The setter shouldn't be used, other setters with value should be preferred
  3656. */
  3657. get: function () {
  3658. return this._getType(1, false);
  3659. },
  3660. set: function (mode) {
  3661. this._setType(1, mode);
  3662. },
  3663. enumerable: true,
  3664. configurable: true
  3665. });
  3666. Object.defineProperty(PrimitiveThickness.prototype, "rightMode", {
  3667. /**
  3668. * Get/set the right mode. The setter shouldn't be used, other setters with value should be preferred
  3669. */
  3670. get: function () {
  3671. return this._getType(2, false);
  3672. },
  3673. set: function (mode) {
  3674. this._setType(2, mode);
  3675. },
  3676. enumerable: true,
  3677. configurable: true
  3678. });
  3679. Object.defineProperty(PrimitiveThickness.prototype, "bottomMode", {
  3680. /**
  3681. * Get/set the bottom mode. The setter shouldn't be used, other setters with value should be preferred
  3682. */
  3683. get: function () {
  3684. return this._getType(3, false);
  3685. },
  3686. set: function (mode) {
  3687. this._setType(3, mode);
  3688. },
  3689. enumerable: true,
  3690. configurable: true
  3691. });
  3692. Object.defineProperty(PrimitiveThickness.prototype, "isDefault", {
  3693. get: function () {
  3694. return this._flags === 0x1111;
  3695. },
  3696. enumerable: true,
  3697. configurable: true
  3698. });
  3699. PrimitiveThickness.prototype._computePixels = function (index, sourceArea, emitChanged) {
  3700. var type = this._getType(index, false);
  3701. if (type === PrimitiveThickness_1.Inherit) {
  3702. this._parentAccess()._computePixels(index, sourceArea, emitChanged);
  3703. return;
  3704. }
  3705. if (type !== PrimitiveThickness_1.Percentage) {
  3706. return;
  3707. }
  3708. var pixels = ((index === 0 || index === 3) ? sourceArea.height : sourceArea.width) * this._percentages[index];
  3709. this._pixels[index] = pixels;
  3710. if (emitChanged) {
  3711. this.onChangeCallback();
  3712. }
  3713. };
  3714. PrimitiveThickness.prototype.onChangeCallback = function () {
  3715. if (this._changedCallback) {
  3716. this._changedCallback();
  3717. }
  3718. };
  3719. /**
  3720. * Compute the positioning/size of an area considering the thickness of this object and a given alignment
  3721. * @param sourceArea the source area where the content must be sized/positioned
  3722. * @param contentSize the content size to position/resize
  3723. * @param alignment the alignment setting
  3724. * @param dstOffset the position of the content, x, y, z, w are left, bottom, right, top
  3725. * @param dstArea the new size of the content
  3726. */
  3727. PrimitiveThickness.prototype.computeWithAlignment = function (sourceArea, contentSize, alignment, dstOffset, dstArea, computeLayoutArea) {
  3728. if (computeLayoutArea === void 0) { computeLayoutArea = false; }
  3729. // Fetch some data
  3730. var topType = this._getType(0, true);
  3731. var leftType = this._getType(1, true);
  3732. var rightType = this._getType(2, true);
  3733. var bottomType = this._getType(3, true);
  3734. var hasWidth = contentSize && (contentSize.width != null);
  3735. var hasHeight = contentSize && (contentSize.height != null);
  3736. var width = hasWidth ? contentSize.width : 0;
  3737. var height = hasHeight ? contentSize.height : 0;
  3738. var isTopAuto = topType === PrimitiveThickness_1.Auto;
  3739. var isLeftAuto = leftType === PrimitiveThickness_1.Auto;
  3740. var isRightAuto = rightType === PrimitiveThickness_1.Auto;
  3741. var isBottomAuto = bottomType === PrimitiveThickness_1.Auto;
  3742. switch (alignment.horizontal) {
  3743. case PrimitiveAlignment.AlignLeft:
  3744. {
  3745. if (isLeftAuto) {
  3746. dstOffset.x = 0;
  3747. }
  3748. else {
  3749. this._computePixels(1, sourceArea, true);
  3750. dstOffset.x = this.leftPixels;
  3751. }
  3752. dstArea.width = width;
  3753. if (computeLayoutArea) {
  3754. dstArea.width += this.leftPixels;
  3755. }
  3756. dstOffset.z = sourceArea.width - (dstOffset.x + width);
  3757. break;
  3758. }
  3759. case PrimitiveAlignment.AlignRight:
  3760. {
  3761. if (isRightAuto) {
  3762. dstOffset.x = Math.round(sourceArea.width - width);
  3763. }
  3764. else {
  3765. this._computePixels(2, sourceArea, true);
  3766. dstOffset.x = Math.round(sourceArea.width - (width + this.rightPixels));
  3767. }
  3768. dstArea.width = width;
  3769. if (computeLayoutArea) {
  3770. dstArea.width += this.rightPixels;
  3771. }
  3772. dstOffset.z = this.rightPixels;
  3773. break;
  3774. }
  3775. case PrimitiveAlignment.AlignStretch:
  3776. {
  3777. if (isLeftAuto) {
  3778. dstOffset.x = 0;
  3779. }
  3780. else {
  3781. this._computePixels(1, sourceArea, true);
  3782. dstOffset.x = this.leftPixels;
  3783. }
  3784. var right = 0;
  3785. if (!isRightAuto) {
  3786. this._computePixels(2, sourceArea, true);
  3787. right = this.rightPixels;
  3788. }
  3789. dstArea.width = sourceArea.width - (dstOffset.x + right);
  3790. dstOffset.z = this.rightPixels;
  3791. break;
  3792. }
  3793. case PrimitiveAlignment.AlignCenter:
  3794. {
  3795. if (!isLeftAuto) {
  3796. this._computePixels(1, sourceArea, true);
  3797. }
  3798. if (!isRightAuto) {
  3799. this._computePixels(2, sourceArea, true);
  3800. }
  3801. var offset = (isLeftAuto ? 0 : this.leftPixels) - (isRightAuto ? 0 : this.rightPixels);
  3802. dstOffset.x = Math.round(((sourceArea.width - width) / 2) + offset);
  3803. dstArea.width = width;
  3804. dstOffset.z = sourceArea.width - (dstOffset.x + width);
  3805. break;
  3806. }
  3807. }
  3808. switch (alignment.vertical) {
  3809. case PrimitiveAlignment.AlignTop:
  3810. {
  3811. if (isTopAuto) {
  3812. dstOffset.y = sourceArea.height - height;
  3813. }
  3814. else {
  3815. this._computePixels(0, sourceArea, true);
  3816. dstOffset.y = Math.round(sourceArea.height - (height + this.topPixels));
  3817. }
  3818. dstArea.height = height;
  3819. if (computeLayoutArea) {
  3820. dstArea.height += this.topPixels;
  3821. }
  3822. dstOffset.w = this.topPixels;
  3823. break;
  3824. }
  3825. case PrimitiveAlignment.AlignBottom:
  3826. {
  3827. if (isBottomAuto) {
  3828. dstOffset.y = 0;
  3829. }
  3830. else {
  3831. this._computePixels(3, sourceArea, true);
  3832. dstOffset.y = this.bottomPixels;
  3833. }
  3834. dstArea.height = height;
  3835. if (computeLayoutArea) {
  3836. dstArea.height += this.bottomPixels;
  3837. }
  3838. dstOffset.w = sourceArea.height - (dstOffset.y + height);
  3839. break;
  3840. }
  3841. case PrimitiveAlignment.AlignStretch:
  3842. {
  3843. if (isBottomAuto) {
  3844. dstOffset.y = 0;
  3845. }
  3846. else {
  3847. this._computePixels(3, sourceArea, true);
  3848. dstOffset.y = this.bottomPixels;
  3849. }
  3850. var top_1 = 0;
  3851. if (!isTopAuto) {
  3852. this._computePixels(0, sourceArea, true);
  3853. top_1 = this.topPixels;
  3854. }
  3855. dstArea.height = sourceArea.height - (dstOffset.y + top_1);
  3856. dstOffset.w = this.topPixels;
  3857. break;
  3858. }
  3859. case PrimitiveAlignment.AlignCenter:
  3860. {
  3861. if (!isTopAuto) {
  3862. this._computePixels(0, sourceArea, true);
  3863. }
  3864. if (!isBottomAuto) {
  3865. this._computePixels(3, sourceArea, true);
  3866. }
  3867. var offset = (isBottomAuto ? 0 : this.bottomPixels) - (isTopAuto ? 0 : this.topPixels);
  3868. dstOffset.y = Math.round(((sourceArea.height - height) / 2) + offset);
  3869. dstArea.height = height;
  3870. dstOffset.w = sourceArea.height - (dstOffset.y + height);
  3871. break;
  3872. }
  3873. }
  3874. };
  3875. /**
  3876. * Compute an area and its position considering this thickness properties based on a given source area
  3877. * @param sourceArea the source area
  3878. * @param dstOffset the position of the resulting area
  3879. * @param dstArea the size of the resulting area
  3880. */
  3881. PrimitiveThickness.prototype.compute = function (sourceArea, dstOffset, dstArea) {
  3882. this._computePixels(0, sourceArea, true);
  3883. this._computePixels(1, sourceArea, true);
  3884. this._computePixels(2, sourceArea, true);
  3885. this._computePixels(3, sourceArea, true);
  3886. dstOffset.x = this.leftPixels;
  3887. dstArea.width = sourceArea.width - (dstOffset.x + this.rightPixels);
  3888. dstOffset.y = this.bottomPixels;
  3889. dstArea.height = sourceArea.height - (dstOffset.y + this.topPixels);
  3890. dstOffset.z = this.rightPixels;
  3891. dstOffset.w = this.topPixels;
  3892. };
  3893. /**
  3894. * Compute an area considering this thickness properties based on a given source area
  3895. * @param sourceArea the source area
  3896. * @param result the resulting area
  3897. */
  3898. PrimitiveThickness.prototype.computeArea = function (sourceArea, result) {
  3899. this._computePixels(0, sourceArea, true);
  3900. this._computePixels(1, sourceArea, true);
  3901. this._computePixels(2, sourceArea, true);
  3902. this._computePixels(3, sourceArea, true);
  3903. result.width = this.leftPixels + sourceArea.width + this.rightPixels;
  3904. result.height = this.bottomPixels + sourceArea.height + this.topPixels;
  3905. };
  3906. PrimitiveThickness.prototype.enlarge = function (sourceArea, dstOffset, enlargedArea) {
  3907. this._computePixels(0, sourceArea, true);
  3908. this._computePixels(1, sourceArea, true);
  3909. this._computePixels(2, sourceArea, true);
  3910. this._computePixels(3, sourceArea, true);
  3911. dstOffset.x = this.leftPixels;
  3912. enlargedArea.width = sourceArea.width + (dstOffset.x + this.rightPixels);
  3913. dstOffset.y = this.bottomPixels;
  3914. enlargedArea.height = sourceArea.height + (dstOffset.y + this.topPixels);
  3915. dstOffset.z = this.rightPixels;
  3916. dstOffset.w = this.topPixels;
  3917. };
  3918. return PrimitiveThickness;
  3919. }());
  3920. PrimitiveThickness.Auto = 0x1;
  3921. PrimitiveThickness.Inherit = 0x2;
  3922. PrimitiveThickness.Percentage = 0x4;
  3923. PrimitiveThickness.Pixel = 0x8;
  3924. PrimitiveThickness = PrimitiveThickness_1 = __decorate([
  3925. BABYLON.className("PrimitiveThickness", "BABYLON")
  3926. ], PrimitiveThickness);
  3927. BABYLON.PrimitiveThickness = PrimitiveThickness;
  3928. /**
  3929. * Main class used for the Primitive Intersection API
  3930. */
  3931. var IntersectInfo2D = (function () {
  3932. function IntersectInfo2D() {
  3933. this.findFirstOnly = false;
  3934. this.intersectHidden = false;
  3935. this.pickPosition = BABYLON.Vector2.Zero();
  3936. }
  3937. Object.defineProperty(IntersectInfo2D.prototype, "isIntersected", {
  3938. /**
  3939. * true if at least one primitive intersected during the test
  3940. */
  3941. get: function () {
  3942. return this.intersectedPrimitives && this.intersectedPrimitives.length > 0;
  3943. },
  3944. enumerable: true,
  3945. configurable: true
  3946. });
  3947. IntersectInfo2D.prototype.isPrimIntersected = function (prim) {
  3948. for (var _i = 0, _a = this.intersectedPrimitives; _i < _a.length; _i++) {
  3949. var cur = _a[_i];
  3950. if (cur.prim === prim) {
  3951. return cur.intersectionLocation;
  3952. }
  3953. }
  3954. return null;
  3955. };
  3956. // Internals, don't use
  3957. IntersectInfo2D.prototype._exit = function (firstLevel) {
  3958. if (firstLevel) {
  3959. this._globalPickPosition = null;
  3960. }
  3961. };
  3962. return IntersectInfo2D;
  3963. }());
  3964. BABYLON.IntersectInfo2D = IntersectInfo2D;
  3965. var Prim2DBase = Prim2DBase_1 = (function (_super) {
  3966. __extends(Prim2DBase, _super);
  3967. function Prim2DBase(settings) {
  3968. var _this;
  3969. // Avoid checking every time if the object exists
  3970. if (settings == null) {
  3971. settings = {};
  3972. }
  3973. // BASE CLASS CALL
  3974. _this = _super.call(this) || this;
  3975. // Fetch the owner, parent. There're many ways to do it and we can end up with nothing for both
  3976. var owner;
  3977. var parent;
  3978. if (Prim2DBase_1._isCanvasInit) {
  3979. owner = _this;
  3980. parent = null;
  3981. _this._canvasPreInit(settings);
  3982. }
  3983. else {
  3984. if (settings.parent != null) {
  3985. parent = settings.parent;
  3986. owner = settings.parent.owner;
  3987. if (!owner) {
  3988. throw new Error("Parent " + parent.id + " of " + settings.id + " doesn't have a valid owner!");
  3989. }
  3990. 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)) {
  3991. 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");
  3992. }
  3993. }
  3994. }
  3995. // Fields initialization
  3996. _this._layoutEngine = BABYLON.CanvasLayoutEngine.Singleton;
  3997. _this._size = null; //Size.Zero();
  3998. _this._scale = new BABYLON.Vector2(1, 1);
  3999. _this._actualSize = null;
  4000. _this._boundingSize = BABYLON.Size.Zero();
  4001. _this._layoutArea = BABYLON.Size.Zero();
  4002. _this._layoutAreaPos = null;
  4003. _this._layoutBoundingInfo = null;
  4004. _this._marginOffset = BABYLON.Vector4.Zero();
  4005. _this._paddingOffset = BABYLON.Vector4.Zero();
  4006. _this._parentPaddingOffset = BABYLON.Vector2.Zero();
  4007. _this._parentContentArea = BABYLON.Size.Zero();
  4008. _this._lastAutoSizeArea = BABYLON.Size.Zero();
  4009. _this._contentArea = new BABYLON.Size(null, null);
  4010. _this._pointerEventObservable = new BABYLON.Observable();
  4011. _this._boundingInfo = new BABYLON.BoundingInfo2D();
  4012. _this._owner = owner;
  4013. _this._parent = null;
  4014. _this._margin = null;
  4015. _this._padding = null;
  4016. _this._marginAlignment = null;
  4017. _this._id = settings.id;
  4018. _this._children = new Array();
  4019. _this._localTransform = new BABYLON.Matrix();
  4020. _this._globalTransform = null;
  4021. _this._invGlobalTransform = null;
  4022. _this._globalTransformProcessStep = 0;
  4023. _this._globalTransformStep = 0;
  4024. _this._renderGroup = null;
  4025. _this._primLinearPosition = 0;
  4026. _this._manualZOrder = null;
  4027. _this._zOrder = 0;
  4028. _this._zMax = 0;
  4029. _this._firstZDirtyIndex = Prim2DBase_1._bigInt;
  4030. _this._actualOpacity = 0;
  4031. _this._actualScale = BABYLON.Vector2.Zero();
  4032. _this._displayDebugAreas = false;
  4033. _this._debugAreaGroup = null;
  4034. var isPickable = true;
  4035. var isContainer = true;
  4036. if (settings.isPickable !== undefined) {
  4037. isPickable = settings.isPickable;
  4038. }
  4039. if (settings.isContainer !== undefined) {
  4040. isContainer = settings.isContainer;
  4041. }
  4042. if (settings.dontInheritParentScale) {
  4043. _this._setFlags(BABYLON.SmartPropertyPrim.flagDontInheritParentScale);
  4044. }
  4045. _this._setFlags((isPickable ? BABYLON.SmartPropertyPrim.flagIsPickable : 0) | BABYLON.SmartPropertyPrim.flagBoundingInfoDirty | BABYLON.SmartPropertyPrim.flagActualOpacityDirty | (isContainer ? BABYLON.SmartPropertyPrim.flagIsContainer : 0) | BABYLON.SmartPropertyPrim.flagActualScaleDirty | BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty);
  4046. if (settings.opacity != null) {
  4047. _this._opacity = settings.opacity;
  4048. }
  4049. else {
  4050. _this._opacity = 1;
  4051. }
  4052. _this._updateRenderMode();
  4053. if (settings.childrenFlatZOrder) {
  4054. _this._setFlags(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  4055. }
  4056. // If the parent is given, initialize the hierarchy/owner related data
  4057. if (parent != null) {
  4058. parent.addChild(_this);
  4059. _this._hierarchyDepth = parent._hierarchyDepth + 1;
  4060. _this._patchHierarchy(parent.owner);
  4061. }
  4062. // If it's a group, detect its own states
  4063. if (_this.owner && _this instanceof BABYLON.Group2D) {
  4064. var group = _this;
  4065. group.detectGroupStates();
  4066. }
  4067. // Time to insert children if some are specified
  4068. if (settings.children != null) {
  4069. for (var _i = 0, _a = settings.children; _i < _a.length; _i++) {
  4070. var child = _a[_i];
  4071. _this.addChild(child);
  4072. // Good time to patch the hierarchy, it won't go very far if there's no need to
  4073. if (_this.owner != null) {
  4074. child._patchHierarchy(_this.owner);
  4075. }
  4076. }
  4077. }
  4078. if (settings.zOrder != null) {
  4079. _this.zOrder = settings.zOrder;
  4080. }
  4081. // Set the model related properties
  4082. if (settings.position != null) {
  4083. _this.position = settings.position;
  4084. }
  4085. else if (settings.x != null || settings.y != null) {
  4086. _this.position = new BABYLON.Vector2(settings.x || 0, settings.y || 0);
  4087. }
  4088. else {
  4089. _this._position = null;
  4090. }
  4091. _this.rotation = (settings.rotation == null) ? 0 : settings.rotation;
  4092. if (settings.scale != null) {
  4093. _this.scale = settings.scale;
  4094. }
  4095. else {
  4096. if (settings.scaleX != null) {
  4097. _this.scaleX = settings.scaleX;
  4098. }
  4099. if (settings.scaleY != null) {
  4100. _this.scaleY = settings.scaleY;
  4101. }
  4102. }
  4103. _this.levelVisible = (settings.isVisible == null) ? true : settings.isVisible;
  4104. _this.origin = settings.origin || new BABYLON.Vector2(0.5, 0.5);
  4105. // Layout Engine
  4106. if (settings.layoutEngine != null) {
  4107. if (typeof settings.layoutEngine === "string") {
  4108. var name_1 = settings.layoutEngine.toLocaleLowerCase().trim();
  4109. if (name_1 === "canvas" || name_1 === "canvaslayoutengine") {
  4110. _this.layoutEngine = BABYLON.CanvasLayoutEngine.Singleton;
  4111. }
  4112. else if (name_1.indexOf("stackpanel") === 0 || name_1.indexOf("horizontalstackpanel") === 0) {
  4113. _this.layoutEngine = BABYLON.StackPanelLayoutEngine.Horizontal;
  4114. }
  4115. else if (name_1.indexOf("verticalstackpanel") === 0) {
  4116. _this.layoutEngine = BABYLON.StackPanelLayoutEngine.Vertical;
  4117. }
  4118. }
  4119. else if (settings.layoutEngine instanceof BABYLON.LayoutEngineBase) {
  4120. _this.layoutEngine = settings.layoutEngine;
  4121. }
  4122. }
  4123. // Set the layout/margin stuffs
  4124. if (settings.marginTop) {
  4125. _this.margin.setTop(settings.marginTop);
  4126. }
  4127. if (settings.marginLeft) {
  4128. _this.margin.setLeft(settings.marginLeft);
  4129. }
  4130. if (settings.marginRight) {
  4131. _this.margin.setRight(settings.marginRight);
  4132. }
  4133. if (settings.marginBottom) {
  4134. _this.margin.setBottom(settings.marginBottom);
  4135. }
  4136. if (settings.margin) {
  4137. if (typeof settings.margin === "string") {
  4138. _this.margin.fromString(settings.margin);
  4139. }
  4140. else {
  4141. _this.margin.fromUniformPixels(settings.margin);
  4142. }
  4143. }
  4144. if (settings.marginHAlignment) {
  4145. _this.marginAlignment.horizontal = settings.marginHAlignment;
  4146. }
  4147. if (settings.marginVAlignment) {
  4148. _this.marginAlignment.vertical = settings.marginVAlignment;
  4149. }
  4150. if (settings.marginAlignment) {
  4151. _this.marginAlignment.fromString(settings.marginAlignment);
  4152. }
  4153. if (settings.paddingTop) {
  4154. _this.padding.setTop(settings.paddingTop);
  4155. }
  4156. if (settings.paddingLeft) {
  4157. _this.padding.setLeft(settings.paddingLeft);
  4158. }
  4159. if (settings.paddingRight) {
  4160. _this.padding.setRight(settings.paddingRight);
  4161. }
  4162. if (settings.paddingBottom) {
  4163. _this.padding.setBottom(settings.paddingBottom);
  4164. }
  4165. if (settings.padding) {
  4166. _this.padding.fromString(settings.padding);
  4167. }
  4168. // Dirty layout and positioning
  4169. _this._parentLayoutDirty();
  4170. _this._positioningDirty();
  4171. return _this;
  4172. }
  4173. Object.defineProperty(Prim2DBase.prototype, "actionManager", {
  4174. get: function () {
  4175. if (!this._actionManager) {
  4176. this._actionManager = new BABYLON.ActionManager(this.owner.scene);
  4177. }
  4178. return this._actionManager;
  4179. },
  4180. enumerable: true,
  4181. configurable: true
  4182. });
  4183. /**
  4184. * From 'this' primitive, traverse up (from parent to parent) until the given predicate is true
  4185. * @param predicate the predicate to test on each parent
  4186. * @return the first primitive where the predicate was successful
  4187. */
  4188. Prim2DBase.prototype.traverseUp = function (predicate) {
  4189. var p = this;
  4190. while (p != null) {
  4191. if (predicate(p)) {
  4192. return p;
  4193. }
  4194. p = p._parent;
  4195. }
  4196. return null;
  4197. };
  4198. Object.defineProperty(Prim2DBase.prototype, "owner", {
  4199. /**
  4200. * Retrieve the owner Canvas2D
  4201. */
  4202. get: function () {
  4203. return this._owner;
  4204. },
  4205. enumerable: true,
  4206. configurable: true
  4207. });
  4208. Object.defineProperty(Prim2DBase.prototype, "parent", {
  4209. /**
  4210. * Get the parent primitive (can be the Canvas, only the Canvas has no parent)
  4211. */
  4212. get: function () {
  4213. return this._parent;
  4214. },
  4215. enumerable: true,
  4216. configurable: true
  4217. });
  4218. Object.defineProperty(Prim2DBase.prototype, "children", {
  4219. /**
  4220. * The array of direct children primitives
  4221. */
  4222. get: function () {
  4223. return this._children;
  4224. },
  4225. enumerable: true,
  4226. configurable: true
  4227. });
  4228. Object.defineProperty(Prim2DBase.prototype, "id", {
  4229. /**
  4230. * The identifier of this primitive, may not be unique, it's for information purpose only
  4231. */
  4232. get: function () {
  4233. return this._id;
  4234. },
  4235. set: function (value) {
  4236. if (this._id === value) {
  4237. return;
  4238. }
  4239. var oldValue = this._id;
  4240. this.onPropertyChanged("id", oldValue, this._id);
  4241. },
  4242. enumerable: true,
  4243. configurable: true
  4244. });
  4245. Object.defineProperty(Prim2DBase.prototype, "actualPosition", {
  4246. get: function () {
  4247. if (this._actualPosition != null) {
  4248. return this._actualPosition;
  4249. }
  4250. if (this._position != null) {
  4251. return this._position;
  4252. }
  4253. // At least return 0,0, we can't return null on actualPosition
  4254. return Prim2DBase_1._nullPosition;
  4255. },
  4256. /**
  4257. * DO NOT INVOKE for internal purpose only
  4258. */
  4259. set: function (val) {
  4260. this._actualPosition = val;
  4261. },
  4262. enumerable: true,
  4263. configurable: true
  4264. });
  4265. Object.defineProperty(Prim2DBase.prototype, "actualX", {
  4266. /**
  4267. * Shortcut to actualPosition.x
  4268. */
  4269. get: function () {
  4270. return this.actualPosition.x;
  4271. },
  4272. set: function (val) {
  4273. this._actualPosition.x = val;
  4274. this._triggerPropertyChanged(Prim2DBase_1.actualPositionProperty, this._actualPosition);
  4275. },
  4276. enumerable: true,
  4277. configurable: true
  4278. });
  4279. Object.defineProperty(Prim2DBase.prototype, "actualY", {
  4280. /**
  4281. * Shortcut to actualPosition.y
  4282. */
  4283. get: function () {
  4284. return this.actualPosition.y;
  4285. },
  4286. set: function (val) {
  4287. this._actualPosition.y = val;
  4288. this._triggerPropertyChanged(Prim2DBase_1.actualPositionProperty, this._actualPosition);
  4289. },
  4290. enumerable: true,
  4291. configurable: true
  4292. });
  4293. Object.defineProperty(Prim2DBase.prototype, "position", {
  4294. /**
  4295. * Position of the primitive, relative to its parent.
  4296. * BEWARE: if you change only position.x or y it won't trigger a property change and you won't have the expected behavior.
  4297. * Use this property to set a new Vector2 object, otherwise to change only the x/y use Prim2DBase.x or y properties.
  4298. * Setting this property may have no effect is specific alignment are in effect.
  4299. */
  4300. get: function () {
  4301. if (!this._position) {
  4302. this._position = BABYLON.Vector2.Zero();
  4303. }
  4304. return this._position;
  4305. },
  4306. set: function (value) {
  4307. if (!this._checkPositionChange()) {
  4308. return;
  4309. }
  4310. this._position = value;
  4311. this._triggerPropertyChanged(Prim2DBase_1.actualPositionProperty, value);
  4312. },
  4313. enumerable: true,
  4314. configurable: true
  4315. });
  4316. Object.defineProperty(Prim2DBase.prototype, "x", {
  4317. /**
  4318. * Direct access to the position.x value of the primitive
  4319. * Use this property when you only want to change one component of the position property
  4320. */
  4321. get: function () {
  4322. if (!this._position) {
  4323. return null;
  4324. }
  4325. return this._position.x;
  4326. },
  4327. set: function (value) {
  4328. if (!this._checkPositionChange()) {
  4329. return;
  4330. }
  4331. if (!this._position) {
  4332. this._position = BABYLON.Vector2.Zero();
  4333. }
  4334. if (this._position.x === value) {
  4335. return;
  4336. }
  4337. this._position.x = value;
  4338. this._triggerPropertyChanged(Prim2DBase_1.positionProperty, value);
  4339. this._triggerPropertyChanged(Prim2DBase_1.actualPositionProperty, value);
  4340. },
  4341. enumerable: true,
  4342. configurable: true
  4343. });
  4344. Object.defineProperty(Prim2DBase.prototype, "y", {
  4345. /**
  4346. * Direct access to the position.y value of the primitive
  4347. * Use this property when you only want to change one component of the position property
  4348. */
  4349. get: function () {
  4350. if (!this._position) {
  4351. return null;
  4352. }
  4353. return this._position.y;
  4354. },
  4355. set: function (value) {
  4356. if (!this._checkPositionChange()) {
  4357. return;
  4358. }
  4359. if (!this._position) {
  4360. this._position = BABYLON.Vector2.Zero();
  4361. }
  4362. if (this._position.y === value) {
  4363. return;
  4364. }
  4365. this._position.y = value;
  4366. this._triggerPropertyChanged(Prim2DBase_1.positionProperty, value);
  4367. this._triggerPropertyChanged(Prim2DBase_1.actualPositionProperty, value);
  4368. },
  4369. enumerable: true,
  4370. configurable: true
  4371. });
  4372. Object.defineProperty(Prim2DBase.prototype, "size", {
  4373. /**
  4374. * Size of the primitive or its bounding area
  4375. * BEWARE: if you change only size.width or height it won't trigger a property change and you won't have the expected behavior.
  4376. * Use this property to set a new Size object, otherwise to change only the width/height use Prim2DBase.width or height properties.
  4377. */
  4378. get: function () {
  4379. if (!this._size || this._size.width == null || this._size.height == null) {
  4380. if (Prim2DBase_1.boundinbBoxReentrency) {
  4381. return Prim2DBase_1.nullSize;
  4382. }
  4383. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagBoundingInfoDirty)) {
  4384. return this._boundingSize;
  4385. }
  4386. Prim2DBase_1.boundinbBoxReentrency = true;
  4387. var b = this.boundingInfo;
  4388. Prim2DBase_1.boundinbBoxReentrency = false;
  4389. return this._boundingSize;
  4390. }
  4391. return this._size;
  4392. },
  4393. set: function (value) {
  4394. this._size = value;
  4395. },
  4396. enumerable: true,
  4397. configurable: true
  4398. });
  4399. Object.defineProperty(Prim2DBase.prototype, "width", {
  4400. /**
  4401. * Direct access to the size.width value of the primitive
  4402. * Use this property when you only want to change one component of the size property
  4403. */
  4404. get: function () {
  4405. if (!this.size) {
  4406. return null;
  4407. }
  4408. return this.size.width;
  4409. },
  4410. set: function (value) {
  4411. if (this.size && this.size.width === value) {
  4412. return;
  4413. }
  4414. if (!this.size) {
  4415. this.size = new BABYLON.Size(value, 0);
  4416. }
  4417. else {
  4418. this.size.width = value;
  4419. }
  4420. this._triggerPropertyChanged(Prim2DBase_1.sizeProperty, value);
  4421. this._positioningDirty();
  4422. },
  4423. enumerable: true,
  4424. configurable: true
  4425. });
  4426. Object.defineProperty(Prim2DBase.prototype, "height", {
  4427. /**
  4428. * Direct access to the size.height value of the primitive
  4429. * Use this property when you only want to change one component of the size property
  4430. */
  4431. get: function () {
  4432. if (!this.size) {
  4433. return null;
  4434. }
  4435. return this.size.height;
  4436. },
  4437. set: function (value) {
  4438. if (this.size && this.size.height === value) {
  4439. return;
  4440. }
  4441. if (!this.size) {
  4442. this.size = new BABYLON.Size(0, value);
  4443. }
  4444. else {
  4445. this.size.height = value;
  4446. }
  4447. this._triggerPropertyChanged(Prim2DBase_1.sizeProperty, value);
  4448. this._positioningDirty();
  4449. },
  4450. enumerable: true,
  4451. configurable: true
  4452. });
  4453. Object.defineProperty(Prim2DBase.prototype, "rotation", {
  4454. get: function () {
  4455. return this._rotation;
  4456. },
  4457. set: function (value) {
  4458. this._rotation = value;
  4459. },
  4460. enumerable: true,
  4461. configurable: true
  4462. });
  4463. Object.defineProperty(Prim2DBase.prototype, "scale", {
  4464. get: function () {
  4465. return this._scale.x;
  4466. },
  4467. set: function (value) {
  4468. this._scale.x = this._scale.y = value;
  4469. this._setFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  4470. this._spreadActualScaleDirty();
  4471. },
  4472. enumerable: true,
  4473. configurable: true
  4474. });
  4475. Object.defineProperty(Prim2DBase.prototype, "actualSize", {
  4476. /**
  4477. * Return the size of the primitive as it's being rendered into the target.
  4478. * 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.
  4479. * BEWARE: don't use the setter, it's for internal purpose only
  4480. * Note to implementers: you have to override this property and declare if necessary a @xxxxInstanceLevel decorator
  4481. */
  4482. get: function () {
  4483. if (this._actualSize) {
  4484. return this._actualSize;
  4485. }
  4486. return this._size;
  4487. },
  4488. set: function (value) {
  4489. if (this._actualSize.equals(value)) {
  4490. return;
  4491. }
  4492. this._actualSize = value;
  4493. },
  4494. enumerable: true,
  4495. configurable: true
  4496. });
  4497. Object.defineProperty(Prim2DBase.prototype, "actualWidth", {
  4498. /**
  4499. * Shortcut to actualSize.width
  4500. */
  4501. get: function () {
  4502. return this.actualSize.width;
  4503. },
  4504. set: function (val) {
  4505. this._actualSize.width = val;
  4506. this._triggerPropertyChanged(Prim2DBase_1.actualSizeProperty, this._actualSize);
  4507. },
  4508. enumerable: true,
  4509. configurable: true
  4510. });
  4511. Object.defineProperty(Prim2DBase.prototype, "actualHeight", {
  4512. /**
  4513. * Shortcut to actualPosition.height
  4514. */
  4515. get: function () {
  4516. return this.actualSize.height;
  4517. },
  4518. set: function (val) {
  4519. this._actualSize.height = val;
  4520. this._triggerPropertyChanged(Prim2DBase_1.actualPositionProperty, this._actualSize);
  4521. },
  4522. enumerable: true,
  4523. configurable: true
  4524. });
  4525. Object.defineProperty(Prim2DBase.prototype, "actualZOffset", {
  4526. get: function () {
  4527. if (this._manualZOrder != null) {
  4528. return this._manualZOrder;
  4529. }
  4530. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  4531. this._updateZOrder();
  4532. }
  4533. return (1 - this._zOrder);
  4534. },
  4535. enumerable: true,
  4536. configurable: true
  4537. });
  4538. Object.defineProperty(Prim2DBase.prototype, "minSize", {
  4539. /**
  4540. * Get or set the minimal size the Layout Engine should respect when computing the primitive's actualSize.
  4541. * The Primitive's size won't be less than specified.
  4542. * The default value depends of the Primitive type
  4543. */
  4544. get: function () {
  4545. return this._minSize;
  4546. },
  4547. set: function (value) {
  4548. if (this._minSize && value && this._minSize.equals(value)) {
  4549. return;
  4550. }
  4551. this._minSize = value;
  4552. this._parentLayoutDirty();
  4553. },
  4554. enumerable: true,
  4555. configurable: true
  4556. });
  4557. Object.defineProperty(Prim2DBase.prototype, "maxSize", {
  4558. /**
  4559. * Get or set the maximal size the Layout Engine should respect when computing the primitive's actualSize.
  4560. * The Primitive's size won't be more than specified.
  4561. * The default value depends of the Primitive type
  4562. */
  4563. get: function () {
  4564. return this._maxSize;
  4565. },
  4566. set: function (value) {
  4567. if (this._maxSize && value && this._maxSize.equals(value)) {
  4568. return;
  4569. }
  4570. this._maxSize = value;
  4571. this._parentLayoutDirty();
  4572. },
  4573. enumerable: true,
  4574. configurable: true
  4575. });
  4576. Object.defineProperty(Prim2DBase.prototype, "origin", {
  4577. /**
  4578. * The origin defines the normalized coordinate of the center of the primitive, from the bottom/left corner.
  4579. * The origin is used only to compute transformation of the primitive, it has no meaning in the primitive local frame of reference
  4580. * For instance:
  4581. * 0,0 means the center is bottom/left. Which is the default for Canvas2D instances
  4582. * 0.5,0.5 means the center is at the center of the primitive, which is default of all types of Primitives
  4583. * 0,1 means the center is top/left
  4584. * @returns The normalized center.
  4585. */
  4586. get: function () {
  4587. return this._origin;
  4588. },
  4589. set: function (value) {
  4590. this._origin = value;
  4591. },
  4592. enumerable: true,
  4593. configurable: true
  4594. });
  4595. Object.defineProperty(Prim2DBase.prototype, "levelVisible", {
  4596. get: function () {
  4597. return this._isFlagSet(BABYLON.SmartPropertyPrim.flagLevelVisible);
  4598. },
  4599. set: function (value) {
  4600. this._changeFlags(BABYLON.SmartPropertyPrim.flagLevelVisible, value);
  4601. },
  4602. enumerable: true,
  4603. configurable: true
  4604. });
  4605. Object.defineProperty(Prim2DBase.prototype, "isVisible", {
  4606. get: function () {
  4607. return this._isFlagSet(BABYLON.SmartPropertyPrim.flagIsVisible);
  4608. },
  4609. set: function (value) {
  4610. this._changeFlags(BABYLON.SmartPropertyPrim.flagIsVisible, value);
  4611. },
  4612. enumerable: true,
  4613. configurable: true
  4614. });
  4615. Object.defineProperty(Prim2DBase.prototype, "zOrder", {
  4616. get: function () {
  4617. return this._manualZOrder;
  4618. },
  4619. set: function (value) {
  4620. if (this._manualZOrder === value) {
  4621. return;
  4622. }
  4623. this._manualZOrder = value;
  4624. this.onZOrderChanged();
  4625. if (this._actualZOrderChangedObservable && this._actualZOrderChangedObservable.hasObservers()) {
  4626. this._actualZOrderChangedObservable.notifyObservers(value);
  4627. }
  4628. },
  4629. enumerable: true,
  4630. configurable: true
  4631. });
  4632. Object.defineProperty(Prim2DBase.prototype, "isManualZOrder", {
  4633. get: function () {
  4634. return this._manualZOrder != null;
  4635. },
  4636. enumerable: true,
  4637. configurable: true
  4638. });
  4639. Object.defineProperty(Prim2DBase.prototype, "margin", {
  4640. get: function () {
  4641. var _this = this;
  4642. if (!this._margin) {
  4643. this._margin = new PrimitiveThickness(function () {
  4644. if (!_this.parent) {
  4645. return null;
  4646. }
  4647. return _this.parent.margin;
  4648. }, function () { return _this._positioningDirty(); });
  4649. }
  4650. return this._margin;
  4651. },
  4652. set: function (value) {
  4653. this.margin.copyFrom(value);
  4654. },
  4655. enumerable: true,
  4656. configurable: true
  4657. });
  4658. Object.defineProperty(Prim2DBase.prototype, "_hasMargin", {
  4659. /**
  4660. * Check for both margin and marginAlignment, return true if at least one of them is specified with a non default value
  4661. */
  4662. get: function () {
  4663. return (this._margin !== null && !this._margin.isDefault) || (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  4664. },
  4665. enumerable: true,
  4666. configurable: true
  4667. });
  4668. Object.defineProperty(Prim2DBase.prototype, "padding", {
  4669. get: function () {
  4670. var _this = this;
  4671. if (!this._padding) {
  4672. this._padding = new PrimitiveThickness(function () {
  4673. if (!_this.parent) {
  4674. return null;
  4675. }
  4676. return _this.parent.padding;
  4677. }, function () { return _this._positioningDirty(); });
  4678. }
  4679. return this._padding;
  4680. },
  4681. set: function (value) {
  4682. this.padding.copyFrom(value);
  4683. },
  4684. enumerable: true,
  4685. configurable: true
  4686. });
  4687. Object.defineProperty(Prim2DBase.prototype, "_hasPadding", {
  4688. get: function () {
  4689. return this._padding !== null && !this._padding.isDefault;
  4690. },
  4691. enumerable: true,
  4692. configurable: true
  4693. });
  4694. Object.defineProperty(Prim2DBase.prototype, "marginAlignment", {
  4695. get: function () {
  4696. var _this = this;
  4697. if (!this._marginAlignment) {
  4698. this._marginAlignment = new PrimitiveAlignment(function () { return _this._positioningDirty(); });
  4699. }
  4700. return this._marginAlignment;
  4701. },
  4702. set: function (value) {
  4703. this.marginAlignment.copyFrom(value);
  4704. },
  4705. enumerable: true,
  4706. configurable: true
  4707. });
  4708. Object.defineProperty(Prim2DBase.prototype, "_hasMarginAlignment", {
  4709. /**
  4710. * Check if there a marginAlignment specified (non null and not default)
  4711. */
  4712. get: function () {
  4713. return (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  4714. },
  4715. enumerable: true,
  4716. configurable: true
  4717. });
  4718. Object.defineProperty(Prim2DBase.prototype, "opacity", {
  4719. get: function () {
  4720. return this._opacity;
  4721. },
  4722. set: function (value) {
  4723. if (value < 0) {
  4724. value = 0;
  4725. }
  4726. else if (value > 1) {
  4727. value = 1;
  4728. }
  4729. if (this._opacity === value) {
  4730. return;
  4731. }
  4732. this._opacity = value;
  4733. this._setFlags(BABYLON.SmartPropertyPrim.flagActualOpacityDirty);
  4734. this._spreadActualOpacityChanged();
  4735. this._updateRenderMode();
  4736. },
  4737. enumerable: true,
  4738. configurable: true
  4739. });
  4740. Object.defineProperty(Prim2DBase.prototype, "scaleX", {
  4741. get: function () {
  4742. return this._scale.x;
  4743. },
  4744. set: function (value) {
  4745. this._scale.x = value;
  4746. this._setFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  4747. this._spreadActualScaleDirty();
  4748. },
  4749. enumerable: true,
  4750. configurable: true
  4751. });
  4752. Object.defineProperty(Prim2DBase.prototype, "scaleY", {
  4753. get: function () {
  4754. return this._scale.y;
  4755. },
  4756. set: function (value) {
  4757. this._scale.y = value;
  4758. this._setFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  4759. this._spreadActualScaleDirty();
  4760. },
  4761. enumerable: true,
  4762. configurable: true
  4763. });
  4764. Prim2DBase.prototype._spreadActualScaleDirty = function () {
  4765. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  4766. var child = _a[_i];
  4767. child._setFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  4768. child._spreadActualScaleDirty();
  4769. }
  4770. };
  4771. Object.defineProperty(Prim2DBase.prototype, "actualScale", {
  4772. /**
  4773. * 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
  4774. */
  4775. get: function () {
  4776. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagActualScaleDirty)) {
  4777. var cur = this._isFlagSet(BABYLON.SmartPropertyPrim.flagDontInheritParentScale) ? null : this.parent;
  4778. var sx = this.scaleX;
  4779. var sy = this.scaleY;
  4780. while (cur) {
  4781. sx *= cur.scaleX;
  4782. sy *= cur.scaleY;
  4783. cur = cur._isFlagSet(BABYLON.SmartPropertyPrim.flagDontInheritParentScale) ? null : cur.parent;
  4784. }
  4785. this._actualScale.copyFromFloats(sx, sy);
  4786. this._clearFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  4787. }
  4788. return this._actualScale;
  4789. },
  4790. enumerable: true,
  4791. configurable: true
  4792. });
  4793. Object.defineProperty(Prim2DBase.prototype, "actualScaleX", {
  4794. /**
  4795. * Get the actual Scale of the X axis, shortcut for this.actualScale.x
  4796. */
  4797. get: function () {
  4798. return this.actualScale.x;
  4799. },
  4800. enumerable: true,
  4801. configurable: true
  4802. });
  4803. Object.defineProperty(Prim2DBase.prototype, "actualScaleY", {
  4804. /**
  4805. * Get the actual Scale of the Y axis, shortcut for this.actualScale.y
  4806. */
  4807. get: function () {
  4808. return this.actualScale.y;
  4809. },
  4810. enumerable: true,
  4811. configurable: true
  4812. });
  4813. Object.defineProperty(Prim2DBase.prototype, "actualOpacity", {
  4814. /**
  4815. * Get the actual opacity level, this property is computed from the opacity property, multiplied by the actualOpacity of its parent (if any)
  4816. */
  4817. get: function () {
  4818. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagActualOpacityDirty)) {
  4819. var cur = this.parent;
  4820. var op = this.opacity;
  4821. while (cur) {
  4822. op *= cur.opacity;
  4823. cur = cur.parent;
  4824. }
  4825. this._actualOpacity = op;
  4826. this._clearFlags(BABYLON.SmartPropertyPrim.flagActualOpacityDirty);
  4827. }
  4828. return this._actualOpacity;
  4829. },
  4830. enumerable: true,
  4831. configurable: true
  4832. });
  4833. Object.defineProperty(Prim2DBase.prototype, "layoutEngine", {
  4834. /**
  4835. * Get/set the layout engine to use for this primitive.
  4836. * The default layout engine is the CanvasLayoutEngine.
  4837. */
  4838. get: function () {
  4839. if (!this._layoutEngine) {
  4840. this._layoutEngine = BABYLON.CanvasLayoutEngine.Singleton;
  4841. }
  4842. return this._layoutEngine;
  4843. },
  4844. set: function (value) {
  4845. if (this._layoutEngine === value) {
  4846. return;
  4847. }
  4848. this._changeLayoutEngine(value);
  4849. },
  4850. enumerable: true,
  4851. configurable: true
  4852. });
  4853. Object.defineProperty(Prim2DBase.prototype, "layoutArea", {
  4854. /**
  4855. * Get/set the layout are of this primitive.
  4856. * The Layout area is the zone allocated by the Layout Engine for this particular primitive. Margins/Alignment will be computed based on this area.
  4857. * The setter should only be called by a Layout Engine class.
  4858. */
  4859. get: function () {
  4860. return this._layoutArea;
  4861. },
  4862. set: function (val) {
  4863. if (this._layoutArea.equals(val)) {
  4864. return;
  4865. }
  4866. this._positioningDirty();
  4867. if (this.parent) {
  4868. this.parent._setFlags(BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty | BABYLON.SmartPropertyPrim.flagGlobalTransformDirty);
  4869. }
  4870. this._layoutArea = val;
  4871. },
  4872. enumerable: true,
  4873. configurable: true
  4874. });
  4875. Object.defineProperty(Prim2DBase.prototype, "layoutAreaPos", {
  4876. /**
  4877. * Get/set the layout area position (relative to the parent primitive).
  4878. * The setter should only be called by a Layout Engine class.
  4879. */
  4880. get: function () {
  4881. if (!this._layoutAreaPos) {
  4882. this._layoutAreaPos = BABYLON.Vector2.Zero();
  4883. }
  4884. return this._layoutAreaPos;
  4885. },
  4886. set: function (val) {
  4887. if (this._layoutAreaPos && this._layoutAreaPos.equals(val)) {
  4888. return;
  4889. }
  4890. if (this.parent) {
  4891. this.parent._setFlags(BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty | BABYLON.SmartPropertyPrim.flagGlobalTransformDirty);
  4892. }
  4893. this._positioningDirty();
  4894. this._layoutAreaPos = val;
  4895. },
  4896. enumerable: true,
  4897. configurable: true
  4898. });
  4899. Object.defineProperty(Prim2DBase.prototype, "isPickable", {
  4900. /**
  4901. * Define if the Primitive can be subject to intersection test or not (default is true)
  4902. */
  4903. get: function () {
  4904. return this._isFlagSet(BABYLON.SmartPropertyPrim.flagIsPickable);
  4905. },
  4906. set: function (value) {
  4907. this._changeFlags(BABYLON.SmartPropertyPrim.flagIsPickable, value);
  4908. },
  4909. enumerable: true,
  4910. configurable: true
  4911. });
  4912. Object.defineProperty(Prim2DBase.prototype, "isContainer", {
  4913. /**
  4914. * Define if the Primitive acts as a container or not
  4915. * A container will encapsulate its children for interaction event.
  4916. * If it's not a container events will be process down to children if the primitive is not pickable.
  4917. * Default value is true
  4918. */
  4919. get: function () {
  4920. return this._isFlagSet(BABYLON.SmartPropertyPrim.flagIsContainer);
  4921. },
  4922. set: function (value) {
  4923. this._changeFlags(BABYLON.SmartPropertyPrim.flagIsContainer, value);
  4924. },
  4925. enumerable: true,
  4926. configurable: true
  4927. });
  4928. Object.defineProperty(Prim2DBase.prototype, "hierarchyDepth", {
  4929. /**
  4930. * Return the depth level of the Primitive into the Canvas' Graph. A Canvas will be 0, its direct children 1, and so on.
  4931. */
  4932. get: function () {
  4933. return this._hierarchyDepth;
  4934. },
  4935. enumerable: true,
  4936. configurable: true
  4937. });
  4938. Object.defineProperty(Prim2DBase.prototype, "renderGroup", {
  4939. /**
  4940. * Retrieve the Group that is responsible to render this primitive
  4941. */
  4942. get: function () {
  4943. return this._renderGroup;
  4944. },
  4945. enumerable: true,
  4946. configurable: true
  4947. });
  4948. Object.defineProperty(Prim2DBase.prototype, "globalTransform", {
  4949. /**
  4950. * Get the global transformation matrix of the primitive
  4951. */
  4952. get: function () {
  4953. this._updateLocalTransform();
  4954. return this._globalTransform;
  4955. },
  4956. enumerable: true,
  4957. configurable: true
  4958. });
  4959. /**
  4960. * return the global position of the primitive, relative to its canvas
  4961. */
  4962. Prim2DBase.prototype.getGlobalPosition = function () {
  4963. var v = new BABYLON.Vector2(0, 0);
  4964. this.getGlobalPositionByRef(v);
  4965. return v;
  4966. };
  4967. /**
  4968. * return the global position of the primitive, relative to its canvas
  4969. * @param v the valid Vector2 object where the global position will be stored
  4970. */
  4971. Prim2DBase.prototype.getGlobalPositionByRef = function (v) {
  4972. v.x = this.globalTransform.m[12];
  4973. v.y = this.globalTransform.m[13];
  4974. };
  4975. Object.defineProperty(Prim2DBase.prototype, "invGlobalTransform", {
  4976. /**
  4977. * Get invert of the global transformation matrix of the primitive
  4978. */
  4979. get: function () {
  4980. this._updateLocalTransform();
  4981. return this._invGlobalTransform;
  4982. },
  4983. enumerable: true,
  4984. configurable: true
  4985. });
  4986. Object.defineProperty(Prim2DBase.prototype, "localTransform", {
  4987. /**
  4988. * Get the local transformation of the primitive
  4989. */
  4990. get: function () {
  4991. this._updateLocalTransform();
  4992. return this._localTransform;
  4993. },
  4994. enumerable: true,
  4995. configurable: true
  4996. });
  4997. Object.defineProperty(Prim2DBase.prototype, "boundingInfo", {
  4998. /**
  4999. * Get the boundingInfo associated to the primitive and its children.
  5000. * The value is supposed to be always up to date
  5001. */
  5002. get: function () {
  5003. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagBoundingInfoDirty)) {
  5004. if (this.owner) {
  5005. this.owner.boundingInfoRecomputeCounter.addCount(1, false);
  5006. }
  5007. if (this.isSizedByContent) {
  5008. this._boundingInfo.clear();
  5009. }
  5010. else {
  5011. this._boundingInfo.copyFrom(this.levelBoundingInfo);
  5012. }
  5013. var bi = this._boundingInfo;
  5014. var tps = new BABYLON.BoundingInfo2D();
  5015. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5016. var curChild = _a[_i];
  5017. var bb = curChild.boundingInfo;
  5018. bb.transformToRef(curChild.localTransform, tps);
  5019. bi.unionToRef(tps, bi);
  5020. }
  5021. this._boundingInfo.maxToRef(Prim2DBase_1._bMax);
  5022. this._boundingSize.copyFromFloats((!this._size || this._size.width == null) ? Math.ceil(Prim2DBase_1._bMax.x) : this._size.width, (!this._size || this._size.height == null) ? Math.ceil(Prim2DBase_1._bMax.y) : this._size.height);
  5023. this._clearFlags(BABYLON.SmartPropertyPrim.flagBoundingInfoDirty);
  5024. }
  5025. return this._boundingInfo;
  5026. },
  5027. enumerable: true,
  5028. configurable: true
  5029. });
  5030. Object.defineProperty(Prim2DBase.prototype, "layoutBoundingInfo", {
  5031. /**
  5032. * Get the boundingInfo of the primitive's content arranged by a layout Engine
  5033. * If a particular child is not arranged by layout, it's boundingInfo is used instead to produce something as accurate as possible
  5034. */
  5035. get: function () {
  5036. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty)) {
  5037. if (!this._layoutBoundingInfo) {
  5038. this._layoutBoundingInfo = new BABYLON.BoundingInfo2D();
  5039. }
  5040. if (this.isSizedByContent) {
  5041. this._layoutBoundingInfo.clear();
  5042. }
  5043. else {
  5044. this._layoutBoundingInfo.copyFrom(this.levelBoundingInfo);
  5045. }
  5046. var bi = this._layoutBoundingInfo;
  5047. var tps = new BABYLON.BoundingInfo2D();
  5048. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5049. var curChild = _a[_i];
  5050. var bb = void 0;
  5051. if (curChild._layoutAreaPos) {
  5052. var s = curChild._layoutArea;
  5053. BABYLON.BoundingInfo2D.CreateFromMinMaxToRef(0, s.width, 0, s.height, Prim2DBase_1._tpsBB);
  5054. bb = Prim2DBase_1._tpsBB;
  5055. }
  5056. else {
  5057. bb = curChild.boundingInfo;
  5058. }
  5059. bb.transformToRef(curChild.localTransform, tps);
  5060. bi.unionToRef(tps, bi);
  5061. }
  5062. this._clearFlags(BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty);
  5063. }
  5064. return this._layoutBoundingInfo;
  5065. },
  5066. enumerable: true,
  5067. configurable: true
  5068. });
  5069. Object.defineProperty(Prim2DBase.prototype, "isSizeAuto", {
  5070. /**
  5071. * Determine if the size is automatically computed or fixed because manually specified.
  5072. * Use the actualSize property to get the final/real size of the primitive
  5073. * @returns true if the size is automatically computed, false if it were manually specified.
  5074. */
  5075. get: function () {
  5076. return this._size == null;
  5077. },
  5078. enumerable: true,
  5079. configurable: true
  5080. });
  5081. Object.defineProperty(Prim2DBase.prototype, "isSizedByContent", {
  5082. /**
  5083. * Return true if this prim has an auto size which is set by the children's global bounding box
  5084. */
  5085. get: function () {
  5086. return (this._size == null) && (this._children.length > 0);
  5087. },
  5088. enumerable: true,
  5089. configurable: true
  5090. });
  5091. Object.defineProperty(Prim2DBase.prototype, "isPositionAuto", {
  5092. /**
  5093. * Determine if the position is automatically computed or fixed because manually specified.
  5094. * Use the actualPosition property to get the final/real position of the primitive
  5095. * @returns true if the position is automatically computed, false if it were manually specified.
  5096. */
  5097. get: function () {
  5098. return this._position == null;
  5099. },
  5100. enumerable: true,
  5101. configurable: true
  5102. });
  5103. Object.defineProperty(Prim2DBase.prototype, "pointerEventObservable", {
  5104. /**
  5105. * Interaction with the primitive can be create using this Observable. See the PrimitivePointerInfo class for more information
  5106. */
  5107. get: function () {
  5108. return this._pointerEventObservable;
  5109. },
  5110. enumerable: true,
  5111. configurable: true
  5112. });
  5113. Object.defineProperty(Prim2DBase.prototype, "zActualOrderChangedObservable", {
  5114. get: function () {
  5115. if (!this._actualZOrderChangedObservable) {
  5116. this._actualZOrderChangedObservable = new BABYLON.Observable();
  5117. }
  5118. return this._actualZOrderChangedObservable;
  5119. },
  5120. enumerable: true,
  5121. configurable: true
  5122. });
  5123. Object.defineProperty(Prim2DBase.prototype, "displayDebugAreas", {
  5124. get: function () {
  5125. return this._displayDebugAreas;
  5126. },
  5127. set: function (value) {
  5128. if (this._displayDebugAreas === value) {
  5129. return;
  5130. }
  5131. if (value === false) {
  5132. this._debugAreaGroup.dispose();
  5133. this._debugAreaGroup = null;
  5134. }
  5135. else {
  5136. var layoutFill = "#F0808040"; // Red - Layout area
  5137. var layoutBorder = "#F08080FF";
  5138. var marginFill = "#F0F04040"; // Yellow - Margin area
  5139. var marginBorder = "#F0F040FF";
  5140. var paddingFill = "#F040F040"; // Magenta - Padding Area
  5141. var paddingBorder = "#F040F0FF";
  5142. var contentFill = "#40F0F040"; // Cyan - Content area
  5143. var contentBorder = "#40F0F0FF";
  5144. var s = new BABYLON.Size(10, 10);
  5145. var p = BABYLON.Vector2.Zero();
  5146. this._debugAreaGroup = new BABYLON.Group2D({ dontInheritParentScale: true,
  5147. parent: (this.parent != null) ? this.parent : this, id: "###DEBUG AREA GROUP###", children: [
  5148. new BABYLON.Group2D({
  5149. id: "###Layout Area###", position: p, size: s, children: [
  5150. new BABYLON.Rectangle2D({ id: "###Layout Frame###", position: BABYLON.Vector2.Zero(), size: s, fill: null, border: layoutBorder }),
  5151. new BABYLON.Rectangle2D({ id: "###Layout Top###", position: BABYLON.Vector2.Zero(), size: s, fill: layoutFill }),
  5152. new BABYLON.Rectangle2D({ id: "###Layout Left###", position: BABYLON.Vector2.Zero(), size: s, fill: layoutFill }),
  5153. new BABYLON.Rectangle2D({ id: "###Layout Right###", position: BABYLON.Vector2.Zero(), size: s, fill: layoutFill }),
  5154. new BABYLON.Rectangle2D({ id: "###Layout Bottom###", position: BABYLON.Vector2.Zero(), size: s, fill: layoutFill })
  5155. ]
  5156. }),
  5157. new BABYLON.Group2D({
  5158. id: "###Margin Area###", position: p, size: s, children: [
  5159. new BABYLON.Rectangle2D({ id: "###Margin Frame###", position: BABYLON.Vector2.Zero(), size: s, fill: null, border: marginBorder }),
  5160. new BABYLON.Rectangle2D({ id: "###Margin Top###", position: BABYLON.Vector2.Zero(), size: s, fill: marginFill }),
  5161. new BABYLON.Rectangle2D({ id: "###Margin Left###", position: BABYLON.Vector2.Zero(), size: s, fill: marginFill }),
  5162. new BABYLON.Rectangle2D({ id: "###Margin Right###", position: BABYLON.Vector2.Zero(), size: s, fill: marginFill }),
  5163. new BABYLON.Rectangle2D({ id: "###Margin Bottom###", position: BABYLON.Vector2.Zero(), size: s, fill: marginFill })
  5164. ]
  5165. }),
  5166. new BABYLON.Group2D({
  5167. id: "###Padding Area###", position: p, size: s, children: [
  5168. new BABYLON.Rectangle2D({ id: "###Padding Frame###", position: BABYLON.Vector2.Zero(), size: s, fill: null, border: paddingBorder }),
  5169. new BABYLON.Rectangle2D({ id: "###Padding Top###", position: BABYLON.Vector2.Zero(), size: s, fill: paddingFill }),
  5170. new BABYLON.Rectangle2D({ id: "###Padding Left###", position: BABYLON.Vector2.Zero(), size: s, fill: paddingFill }),
  5171. new BABYLON.Rectangle2D({ id: "###Padding Right###", position: BABYLON.Vector2.Zero(), size: s, fill: paddingFill }),
  5172. new BABYLON.Rectangle2D({ id: "###Padding Bottom###", position: BABYLON.Vector2.Zero(), size: s, fill: paddingFill })
  5173. ]
  5174. }),
  5175. new BABYLON.Group2D({
  5176. id: "###Content Area###", position: p, size: s, children: [
  5177. new BABYLON.Rectangle2D({ id: "###Content Frame###", position: BABYLON.Vector2.Zero(), size: s, fill: null, border: contentBorder }),
  5178. new BABYLON.Rectangle2D({ id: "###Content Top###", position: BABYLON.Vector2.Zero(), size: s, fill: contentFill }),
  5179. new BABYLON.Rectangle2D({ id: "###Content Left###", position: BABYLON.Vector2.Zero(), size: s, fill: contentFill }),
  5180. new BABYLON.Rectangle2D({ id: "###Content Right###", position: BABYLON.Vector2.Zero(), size: s, fill: contentFill }),
  5181. new BABYLON.Rectangle2D({ id: "###Content Bottom###", position: BABYLON.Vector2.Zero(), size: s, fill: contentFill })
  5182. ]
  5183. })
  5184. ]
  5185. });
  5186. this._debugAreaGroup._setFlags(BABYLON.SmartPropertyPrim.flagNoPartOfLayout);
  5187. this._updateDebugArea();
  5188. }
  5189. this._displayDebugAreas = value;
  5190. },
  5191. enumerable: true,
  5192. configurable: true
  5193. });
  5194. Prim2DBase.prototype._updateDebugArea = function () {
  5195. var areaNames = ["Layout", "Margin", "Padding", "Content"];
  5196. var areaZones = ["Area", "Frame", "Top", "Left", "Right", "Bottom"];
  5197. var prims = new Array(4);
  5198. // Get all the primitives used to display the areas
  5199. for (var i = 0; i < 4; i++) {
  5200. prims[i] = new Array(6);
  5201. for (var j = 0; j < 6; j++) {
  5202. prims[i][j] = this._debugAreaGroup.findById("###" + areaNames[i] + " " + areaZones[j] + "###");
  5203. if (j > 1) {
  5204. prims[i][j].levelVisible = false;
  5205. }
  5206. }
  5207. }
  5208. // Update the visibility status of layout/margin/padding
  5209. var hasLayout = this._layoutAreaPos != null;
  5210. var hasPos = (this.actualPosition.x !== 0) || (this.actualPosition.y !== 0);
  5211. var hasMargin = this._hasMargin;
  5212. var hasPadding = this._hasPadding;
  5213. prims[0][0].levelVisible = hasLayout;
  5214. prims[1][0].levelVisible = hasMargin;
  5215. prims[2][0].levelVisible = hasPadding;
  5216. prims[3][0].levelVisible = true;
  5217. // Current offset
  5218. var curOffset = BABYLON.Vector2.Zero();
  5219. // Store the area info of the layout area
  5220. var curAreaIndex = 0;
  5221. // Store data about each area
  5222. var areaInfo = new Array(4);
  5223. var storeAreaInfo = function (pos, size) {
  5224. var min = pos.clone();
  5225. var max = pos.clone();
  5226. if (size.width > 0) {
  5227. max.x += size.width;
  5228. }
  5229. if (size.height > 0) {
  5230. max.y += size.height;
  5231. }
  5232. areaInfo[curAreaIndex++] = { off: pos, size: size, min: min, max: max };
  5233. };
  5234. var isCanvas = this instanceof BABYLON.Canvas2D;
  5235. var marginH = this._marginOffset.x + this._marginOffset.z;
  5236. var marginV = this._marginOffset.y + this._marginOffset.w;
  5237. var actualSize = this.actualSize.multiplyByFloats(isCanvas ? 1 : this.scaleX, isCanvas ? 1 : this.scaleY);
  5238. var w = hasLayout ? (this.layoutAreaPos.x + this.layoutArea.width) : (marginH + actualSize.width);
  5239. var h = hasLayout ? (this.layoutAreaPos.y + this.layoutArea.height) : (marginV + actualSize.height);
  5240. var pos = (!hasLayout && !hasMargin && !hasPadding && hasPos) ? this.actualPosition : BABYLON.Vector2.Zero();
  5241. storeAreaInfo(pos, new BABYLON.Size(w, h));
  5242. // Compute the layout related data
  5243. if (hasLayout) {
  5244. var layoutOffset = this.layoutAreaPos.clone();
  5245. storeAreaInfo(layoutOffset, (hasMargin || hasPadding) ? this.layoutArea.clone() : actualSize.clone());
  5246. curOffset = layoutOffset.clone();
  5247. }
  5248. // Compute margin data
  5249. if (hasMargin) {
  5250. var marginOffset = curOffset.clone();
  5251. marginOffset.x += this._marginOffset.x;
  5252. marginOffset.y += this._marginOffset.y;
  5253. var marginArea = actualSize;
  5254. storeAreaInfo(marginOffset, marginArea);
  5255. curOffset = marginOffset.clone();
  5256. }
  5257. if (hasPadding) {
  5258. var contentOffset = curOffset.clone();
  5259. contentOffset.x += this._paddingOffset.x;
  5260. contentOffset.y += this._paddingOffset.y;
  5261. var contentArea = this.contentArea;
  5262. storeAreaInfo(contentOffset, contentArea);
  5263. curOffset = curOffset.add(contentOffset);
  5264. }
  5265. // Helper function that set the pos and size of a given prim
  5266. var setArea = function (i, j, pos, size) {
  5267. prims[i][j].position = pos;
  5268. prims[i][j].size = size;
  5269. };
  5270. var setFullRect = function (i, pos, size) {
  5271. var plist = prims[i];
  5272. plist[2].levelVisible = true;
  5273. plist[3].levelVisible = false;
  5274. plist[4].levelVisible = false;
  5275. plist[5].levelVisible = false;
  5276. setArea(i, 1, pos, size);
  5277. setArea(i, 2, pos, size);
  5278. };
  5279. var setQuadRect = function (i, areaIndex) {
  5280. var plist = prims[i];
  5281. plist[2].levelVisible = true;
  5282. plist[3].levelVisible = true;
  5283. plist[4].levelVisible = true;
  5284. plist[5].levelVisible = true;
  5285. var ca = areaInfo[areaIndex];
  5286. var na = areaInfo[areaIndex + 1];
  5287. var tp = new BABYLON.Vector2(ca.min.x, na.max.y);
  5288. var ts = new BABYLON.Size(ca.size.width, ca.max.y - tp.y);
  5289. var lp = new BABYLON.Vector2(ca.min.x, na.min.y);
  5290. var ls = new BABYLON.Size(na.min.x - ca.min.x, na.max.y - na.min.y);
  5291. var rp = new BABYLON.Vector2(na.max.x, na.min.y);
  5292. var rs = new BABYLON.Size(ca.max.x - na.max.x, na.max.y - na.min.y);
  5293. var bp = new BABYLON.Vector2(ca.min.x, ca.min.y);
  5294. var bs = new BABYLON.Size(ca.size.width, na.min.y - ca.min.y);
  5295. // Frame
  5296. plist[1].position = ca.off;
  5297. plist[1].size = ca.size;
  5298. // Top rect
  5299. plist[2].position = tp;
  5300. plist[2].size = ts;
  5301. // Left rect
  5302. plist[3].position = lp;
  5303. plist[3].size = ls;
  5304. // Right rect
  5305. plist[4].position = rp;
  5306. plist[4].size = rs;
  5307. // Bottom rect
  5308. plist[5].position = bp;
  5309. plist[5].size = bs;
  5310. };
  5311. var areaCount = curAreaIndex;
  5312. curAreaIndex = 0;
  5313. // Available zones
  5314. var availableZones = [false, hasLayout, hasMargin, hasPadding, true];
  5315. for (var k = 1; k < 5; k++) {
  5316. if (availableZones[k]) {
  5317. var ai = areaInfo[curAreaIndex];
  5318. setArea(k - 1, 0, BABYLON.Vector2.Zero(), ai.size);
  5319. // setArea(k-1, 1, Vector2.Zero(), ai.size);
  5320. if (k === 4) {
  5321. setFullRect(k - 1, ai.off, ai.size);
  5322. }
  5323. else {
  5324. setQuadRect(k - 1, curAreaIndex);
  5325. }
  5326. ++curAreaIndex;
  5327. }
  5328. }
  5329. };
  5330. Prim2DBase.prototype.findById = function (id) {
  5331. if (this._id === id) {
  5332. return this;
  5333. }
  5334. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5335. var child = _a[_i];
  5336. var r = child.findById(id);
  5337. if (r != null) {
  5338. return r;
  5339. }
  5340. }
  5341. };
  5342. Prim2DBase.prototype.onZOrderChanged = function () {
  5343. };
  5344. Prim2DBase.prototype.levelIntersect = function (intersectInfo) {
  5345. return false;
  5346. };
  5347. /**
  5348. * Capture all the Events of the given PointerId for this primitive.
  5349. * Don't forget to call releasePointerEventsCapture when done.
  5350. * @param pointerId the Id of the pointer to capture the events from.
  5351. */
  5352. Prim2DBase.prototype.setPointerEventCapture = function (pointerId) {
  5353. return this.owner._setPointerCapture(pointerId, this);
  5354. };
  5355. /**
  5356. * Release a captured pointer made with setPointerEventCapture.
  5357. * @param pointerId the Id of the pointer to release the capture from.
  5358. */
  5359. Prim2DBase.prototype.releasePointerEventsCapture = function (pointerId) {
  5360. return this.owner._releasePointerCapture(pointerId, this);
  5361. };
  5362. Prim2DBase.prototype.intersect = function (intersectInfo) {
  5363. if (!intersectInfo) {
  5364. return false;
  5365. }
  5366. // If this is null it means this method is call for the first level, initialize stuffs
  5367. var firstLevel = !intersectInfo._globalPickPosition;
  5368. if (firstLevel) {
  5369. // 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).
  5370. intersectInfo._globalPickPosition = BABYLON.Vector2.Zero();
  5371. BABYLON.Vector2.TransformToRef(intersectInfo.pickPosition, this.globalTransform, intersectInfo._globalPickPosition);
  5372. intersectInfo._localPickPosition = intersectInfo.pickPosition.clone();
  5373. intersectInfo.intersectedPrimitives = new Array();
  5374. intersectInfo.topMostIntersectedPrimitive = null;
  5375. }
  5376. if (!Prim2DBase_1._bypassGroup2DExclusion && this instanceof BABYLON.Group2D && this.isCachedGroup && !this.isRenderableGroup) {
  5377. // Important to call this before each return to allow a good recursion next time this intersectInfo is reused
  5378. intersectInfo._exit(firstLevel);
  5379. return false;
  5380. }
  5381. if (!intersectInfo.intersectHidden && !this.isVisible) {
  5382. // Important to call this before each return to allow a good recursion next time this intersectInfo is reused
  5383. intersectInfo._exit(firstLevel);
  5384. return false;
  5385. }
  5386. var id = this.id;
  5387. if (id != null && id.indexOf("__cachedSpriteOfGroup__") === 0) {
  5388. try {
  5389. Prim2DBase_1._bypassGroup2DExclusion = true;
  5390. var ownerGroup = this.getExternalData("__cachedGroup__");
  5391. return ownerGroup.intersect(intersectInfo);
  5392. }
  5393. finally {
  5394. Prim2DBase_1._bypassGroup2DExclusion = false;
  5395. }
  5396. }
  5397. // 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).
  5398. var isIntersectionTest = false;
  5399. if (this instanceof BABYLON.Group2D) {
  5400. var g = this;
  5401. isIntersectionTest = g.isCachedGroup;
  5402. }
  5403. if (isIntersectionTest && !this.levelBoundingInfo.doesIntersect(intersectInfo._localPickPosition)) {
  5404. // Important to call this before each return to allow a good recursion next time this intersectInfo is reused
  5405. intersectInfo._exit(firstLevel);
  5406. return false;
  5407. }
  5408. // Fast rejection test with boundingInfo
  5409. if (this.isPickable && !this.boundingInfo.doesIntersect(intersectInfo._localPickPosition)) {
  5410. // Important to call this before each return to allow a good recursion next time this intersectInfo is reused
  5411. intersectInfo._exit(firstLevel);
  5412. return false;
  5413. }
  5414. // We hit the boundingInfo that bounds this primitive and its children, now we have to test on the primitive of this level
  5415. var levelIntersectRes = false;
  5416. if (this.isPickable) {
  5417. levelIntersectRes = this.levelIntersect(intersectInfo);
  5418. if (levelIntersectRes) {
  5419. var pii = new PrimitiveIntersectedInfo(this, intersectInfo._localPickPosition.clone());
  5420. intersectInfo.intersectedPrimitives.push(pii);
  5421. if (!intersectInfo.topMostIntersectedPrimitive || (intersectInfo.topMostIntersectedPrimitive.prim.actualZOffset > pii.prim.actualZOffset)) {
  5422. intersectInfo.topMostIntersectedPrimitive = pii;
  5423. }
  5424. // If we must stop at the first intersection, we're done, quit!
  5425. if (intersectInfo.findFirstOnly) {
  5426. intersectInfo._exit(firstLevel);
  5427. return true;
  5428. }
  5429. }
  5430. }
  5431. // Recurse to children if needed
  5432. if (!levelIntersectRes || !intersectInfo.findFirstOnly) {
  5433. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5434. var curChild = _a[_i];
  5435. // Don't test primitive not pick able or if it's hidden and we don't test hidden ones
  5436. if ((!curChild.isPickable && curChild.isContainer) || (!intersectInfo.intersectHidden && !curChild.isVisible)) {
  5437. continue;
  5438. }
  5439. // Must compute the localPickLocation for the children level
  5440. BABYLON.Vector2.TransformToRef(intersectInfo._globalPickPosition, curChild.invGlobalTransform, intersectInfo._localPickPosition);
  5441. // If we got an intersection with the child and we only need to find the first one, quit!
  5442. if (curChild.intersect(intersectInfo) && intersectInfo.findFirstOnly) {
  5443. intersectInfo._exit(firstLevel);
  5444. return true;
  5445. }
  5446. }
  5447. }
  5448. intersectInfo._exit(firstLevel);
  5449. return intersectInfo.isIntersected;
  5450. };
  5451. /**
  5452. * Move a child object into a new position regarding its siblings to change its rendering order.
  5453. * You can also use the shortcut methods to move top/bottom: moveChildToTop, moveChildToBottom, moveToTop, moveToBottom.
  5454. * @param child the object to move
  5455. * @param previous the object which will be before "child", if child has to be the first among sibling, set "previous" to null.
  5456. */
  5457. Prim2DBase.prototype.moveChild = function (child, previous) {
  5458. if (child.parent !== this) {
  5459. return false;
  5460. }
  5461. var childIndex = this._children.indexOf(child);
  5462. var prevIndex = previous ? this._children.indexOf(previous) : -1;
  5463. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder)) {
  5464. this._setFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  5465. this._firstZDirtyIndex = Math.min(this._firstZDirtyIndex, prevIndex + 1);
  5466. }
  5467. this._children.splice(prevIndex + 1, 0, this._children.splice(childIndex, 1)[0]);
  5468. return true;
  5469. };
  5470. /**
  5471. * Move the given child so it's displayed on the top of all its siblings
  5472. * @param child the primitive to move to the top
  5473. */
  5474. Prim2DBase.prototype.moveChildToTop = function (child) {
  5475. return this.moveChild(child, this._children[this._children.length - 1]);
  5476. };
  5477. /**
  5478. * Move the given child so it's displayed on the bottom of all its siblings
  5479. * @param child the primitive to move to the top
  5480. */
  5481. Prim2DBase.prototype.moveChildToBottom = function (child) {
  5482. return this.moveChild(child, null);
  5483. };
  5484. /**
  5485. * Move this primitive to be at the top among all its sibling
  5486. */
  5487. Prim2DBase.prototype.moveToTop = function () {
  5488. if (this.parent == null) {
  5489. return false;
  5490. }
  5491. return this.parent.moveChildToTop(this);
  5492. };
  5493. /**
  5494. * Move this primitive to be at the bottom among all its sibling
  5495. */
  5496. Prim2DBase.prototype.moveToBottom = function () {
  5497. if (this.parent == null) {
  5498. return false;
  5499. }
  5500. return this.parent.moveChildToBottom(this);
  5501. };
  5502. Prim2DBase.prototype.addChild = function (child) {
  5503. child._parent = this;
  5504. this._boundingBoxDirty();
  5505. var flat = this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  5506. if (flat) {
  5507. child._setFlags(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  5508. child._setZOrder(this._zOrder, true);
  5509. child._zMax = this._zOrder;
  5510. }
  5511. else {
  5512. this._setFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  5513. }
  5514. var length = this._children.push(child);
  5515. this._firstZDirtyIndex = Math.min(this._firstZDirtyIndex, length - 1);
  5516. };
  5517. /**
  5518. * Dispose the primitive, remove it from its parent.
  5519. */
  5520. Prim2DBase.prototype.dispose = function () {
  5521. if (!_super.prototype.dispose.call(this)) {
  5522. return false;
  5523. }
  5524. if (this._pointerEventObservable) {
  5525. this._pointerEventObservable.clear();
  5526. this._pointerEventObservable = null;
  5527. }
  5528. if (this._actionManager) {
  5529. this._actionManager.dispose();
  5530. this._actionManager = null;
  5531. }
  5532. // If there's a parent, remove this object from its parent list
  5533. if (this._parent) {
  5534. if (this instanceof BABYLON.Group2D) {
  5535. var g = this;
  5536. if (g.isRenderableGroup) {
  5537. var parentRenderable = this.parent.traverseUp(function (p) { return (p instanceof BABYLON.Group2D && p.isRenderableGroup); });
  5538. if (parentRenderable != null) {
  5539. var l = parentRenderable._renderableData._childrenRenderableGroups;
  5540. var i_1 = l.indexOf(g);
  5541. if (i_1 !== -1) {
  5542. l.splice(i_1, 1);
  5543. }
  5544. }
  5545. }
  5546. }
  5547. var i = this._parent._children.indexOf(this);
  5548. if (i !== undefined) {
  5549. this._parent._children.splice(i, 1);
  5550. }
  5551. this._parent = null;
  5552. }
  5553. // Recurse dispose to children
  5554. if (this._children) {
  5555. while (this._children.length > 0) {
  5556. this._children[this._children.length - 1].dispose();
  5557. }
  5558. }
  5559. return true;
  5560. };
  5561. Prim2DBase.prototype.onPrimBecomesDirty = function () {
  5562. if (this._renderGroup && !this._isFlagSet(BABYLON.SmartPropertyPrim.flagPrimInDirtyList)) {
  5563. this._renderGroup._addPrimToDirtyList(this);
  5564. this._setFlags(BABYLON.SmartPropertyPrim.flagPrimInDirtyList);
  5565. }
  5566. };
  5567. Prim2DBase.prototype._needPrepare = function () {
  5568. return this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagVisibilityChanged | BABYLON.SmartPropertyPrim.flagModelDirty | BABYLON.SmartPropertyPrim.flagNeedRefresh) || (this._instanceDirtyFlags !== 0) || (this._globalTransformProcessStep !== this._globalTransformStep);
  5569. };
  5570. Prim2DBase.prototype._prepareRender = function (context) {
  5571. this._prepareRenderPre(context);
  5572. this._prepareRenderPost(context);
  5573. };
  5574. Prim2DBase.prototype._prepareRenderPre = function (context) {
  5575. };
  5576. Prim2DBase.prototype._prepareRenderPost = function (context) {
  5577. // Don't recurse if it's a renderable group, the content will be processed by the group itself
  5578. if (this instanceof BABYLON.Group2D) {
  5579. var self = this;
  5580. if (self.isRenderableGroup) {
  5581. return;
  5582. }
  5583. }
  5584. // Check if we need to recurse the prepare to children primitives
  5585. // - must have children
  5586. // - the global transform of this level have changed, or
  5587. // - the visible state of primitive has changed
  5588. if (this._children.length > 0 && ((this._globalTransformProcessStep !== this._globalTransformStep) ||
  5589. this.checkPropertiesDirty(Prim2DBase_1.isVisibleProperty.flagId))) {
  5590. this._children.forEach(function (c) {
  5591. // As usual stop the recursion if we meet a renderable group
  5592. if (!(c instanceof BABYLON.Group2D && c.isRenderableGroup)) {
  5593. c._prepareRender(context);
  5594. }
  5595. });
  5596. }
  5597. // Finally reset the dirty flags as we've processed everything
  5598. this._clearFlags(BABYLON.SmartPropertyPrim.flagModelDirty);
  5599. this._instanceDirtyFlags = 0;
  5600. };
  5601. Prim2DBase.prototype._canvasPreInit = function (settings) {
  5602. };
  5603. Prim2DBase.CheckParent = function (parent) {
  5604. //if (!Prim2DBase._isCanvasInit && !parent) {
  5605. // 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)");
  5606. //}
  5607. };
  5608. Prim2DBase.prototype.updateCachedStatesOf = function (list, recurse) {
  5609. for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
  5610. var cur = list_1[_i];
  5611. cur.updateCachedStates(recurse);
  5612. }
  5613. };
  5614. Prim2DBase.prototype._parentLayoutDirty = function () {
  5615. if (!this._parent || this._parent.isDisposed) {
  5616. return;
  5617. }
  5618. this._parent._setLayoutDirty();
  5619. };
  5620. Prim2DBase.prototype._setLayoutDirty = function () {
  5621. this.onPrimBecomesDirty();
  5622. this._setFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  5623. };
  5624. Prim2DBase.prototype._checkPositionChange = function () {
  5625. if (this.parent && this.parent.layoutEngine.isChildPositionAllowed === false) {
  5626. console.log("Can't manually set the position of " + this.id + ", the Layout Engine of its parent doesn't allow it");
  5627. return false;
  5628. }
  5629. return true;
  5630. };
  5631. Prim2DBase.prototype._positioningDirty = function () {
  5632. this.onPrimBecomesDirty();
  5633. this._setFlags(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5634. };
  5635. Prim2DBase.prototype._spreadActualOpacityChanged = function () {
  5636. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5637. var child = _a[_i];
  5638. child._setFlags(BABYLON.SmartPropertyPrim.flagActualOpacityDirty);
  5639. child._updateRenderMode();
  5640. child.onPrimBecomesDirty();
  5641. child._spreadActualOpacityChanged();
  5642. }
  5643. };
  5644. Prim2DBase.prototype._changeLayoutEngine = function (engine) {
  5645. this._layoutEngine = engine;
  5646. };
  5647. Prim2DBase.prototype._updateLocalTransform = function () {
  5648. 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;
  5649. if (this.checkPropertiesDirty(tflags)) {
  5650. if (this.owner) {
  5651. this.owner.addupdateLocalTransformCounter(1);
  5652. }
  5653. var rot = BABYLON.Quaternion.RotationAxis(new BABYLON.Vector3(0, 0, 1), this._rotation);
  5654. var local;
  5655. var pos = this._position ? this.position : this.layoutAreaPos;
  5656. if (this._origin.x === 0 && this._origin.y === 0) {
  5657. 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));
  5658. this._localTransform = local;
  5659. }
  5660. else {
  5661. // -Origin offset
  5662. var as = this.actualSize;
  5663. BABYLON.Matrix.TranslationToRef((-as.width * this._origin.x), (-as.height * this._origin.y), 0, Prim2DBase_1._t0);
  5664. // -Origin * rotation
  5665. rot.toRotationMatrix(Prim2DBase_1._t1);
  5666. Prim2DBase_1._t0.multiplyToRef(Prim2DBase_1._t1, Prim2DBase_1._t2);
  5667. // -Origin * rotation * scale
  5668. BABYLON.Matrix.ScalingToRef(this._scale.x, this._scale.y, 1, Prim2DBase_1._t0);
  5669. Prim2DBase_1._t2.multiplyToRef(Prim2DBase_1._t0, Prim2DBase_1._t1);
  5670. // -Origin * rotation * scale * (Origin + Position)
  5671. 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);
  5672. Prim2DBase_1._t1.multiplyToRef(Prim2DBase_1._t2, this._localTransform);
  5673. }
  5674. this.clearPropertiesDirty(tflags);
  5675. this._setFlags(BABYLON.SmartPropertyPrim.flagGlobalTransformDirty);
  5676. return true;
  5677. }
  5678. return false;
  5679. };
  5680. Prim2DBase.prototype.updateCachedStates = function (recurse) {
  5681. if (this.isDisposed) {
  5682. return;
  5683. }
  5684. this.owner.addCachedGroupRenderCounter(1);
  5685. // Check if the parent is synced
  5686. if (this._parent && ((this._parent._globalTransformProcessStep !== this.owner._globalTransformProcessStep) || this._parent._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagLayoutDirty | BABYLON.SmartPropertyPrim.flagPositioningDirty | BABYLON.SmartPropertyPrim.flagZOrderDirty))) {
  5687. this._parent.updateCachedStates(false);
  5688. }
  5689. // Update Z-Order if needed
  5690. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  5691. this._updateZOrder();
  5692. }
  5693. // Update actualSize only if there' not positioning to recompute and the size changed
  5694. // Otherwise positioning will take care of it.
  5695. var sizeDirty = this.checkPropertiesDirty(Prim2DBase_1.sizeProperty.flagId);
  5696. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty) && !this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty) && sizeDirty) {
  5697. var size = this.size;
  5698. if (size) {
  5699. if (this.size.width != null) {
  5700. this.actualSize.width = this.size.width;
  5701. }
  5702. if (this.size.height != null) {
  5703. this.actualSize.height = this.size.height;
  5704. }
  5705. this.clearPropertiesDirty(Prim2DBase_1.sizeProperty.flagId);
  5706. }
  5707. }
  5708. var positioningDirty = this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5709. var positioningComputed = positioningDirty && !this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5710. // Check for layout update
  5711. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty)) {
  5712. this.owner.addUpdateLayoutCounter(1);
  5713. this._layoutEngine.updateLayout(this);
  5714. this._clearFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  5715. }
  5716. var autoContentChanged = false;
  5717. if (this.isSizeAuto) {
  5718. if (!this._lastAutoSizeArea) {
  5719. autoContentChanged = this.actualSize !== null;
  5720. }
  5721. else {
  5722. autoContentChanged = (!this._lastAutoSizeArea.equals(this.actualSize));
  5723. }
  5724. }
  5725. // Check for positioning update
  5726. if (!positioningComputed && (autoContentChanged || sizeDirty || this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty) || (this._parent && !this._parent.contentArea.equals(this._parentContentArea)))) {
  5727. this._updatePositioning();
  5728. this._clearFlags(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5729. if (sizeDirty) {
  5730. this.clearPropertiesDirty(Prim2DBase_1.sizeProperty.flagId);
  5731. }
  5732. positioningComputed = true;
  5733. }
  5734. if (positioningComputed && this._parent) {
  5735. this._parentContentArea.copyFrom(this._parent.contentArea);
  5736. }
  5737. // Check if we must update this prim
  5738. if (this === this.owner || this._globalTransformProcessStep !== this.owner._globalTransformProcessStep) {
  5739. this.owner.addUpdateGlobalTransformCounter(1);
  5740. var curVisibleState = this.isVisible;
  5741. this.isVisible = (!this._parent || this._parent.isVisible) && this.levelVisible;
  5742. // Detect a change of visibility
  5743. this._changeFlags(BABYLON.SmartPropertyPrim.flagVisibilityChanged, curVisibleState !== this.isVisible);
  5744. // Get/compute the localTransform
  5745. var localDirty = this._updateLocalTransform();
  5746. var parentPaddingChanged = false;
  5747. var parentPaddingOffset = Prim2DBase_1._v0;
  5748. if (this._parent) {
  5749. parentPaddingOffset = new BABYLON.Vector2(this._parent._paddingOffset.x, this._parent._paddingOffset.y);
  5750. parentPaddingChanged = !parentPaddingOffset.equals(this._parentPaddingOffset);
  5751. }
  5752. // Check if there are changes in the parent that will force us to update the global matrix
  5753. var parentDirty = (this._parent != null) ? (this._parent._globalTransformStep !== this._parentTransformStep) : false;
  5754. // Check if we have to update the globalTransform
  5755. if (!this._globalTransform || localDirty || parentDirty || parentPaddingChanged || this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagGlobalTransformDirty)) {
  5756. var globalTransform = this._parent ? this._parent._globalTransform : null;
  5757. var localTransform = void 0;
  5758. Prim2DBase_1._transMtx.copyFrom(this._localTransform);
  5759. Prim2DBase_1._transMtx.m[12] += parentPaddingOffset.x;
  5760. Prim2DBase_1._transMtx.m[13] += parentPaddingOffset.y;
  5761. localTransform = Prim2DBase_1._transMtx;
  5762. this._globalTransform = this._parent ? localTransform.multiply(globalTransform) : localTransform.clone();
  5763. this._invGlobalTransform = BABYLON.Matrix.Invert(this._globalTransform);
  5764. this._globalTransformStep = this.owner._globalTransformProcessStep + 1;
  5765. this._parentTransformStep = this._parent ? this._parent._globalTransformStep : 0;
  5766. this._clearFlags(BABYLON.SmartPropertyPrim.flagGlobalTransformDirty);
  5767. }
  5768. this._globalTransformProcessStep = this.owner._globalTransformProcessStep;
  5769. }
  5770. if (recurse) {
  5771. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5772. var child = _a[_i];
  5773. // Stop the recursion if we meet a renderable group
  5774. child.updateCachedStates(!(child instanceof BABYLON.Group2D && child.isRenderableGroup));
  5775. }
  5776. }
  5777. };
  5778. Prim2DBase.prototype._updatePositioning = function () {
  5779. if (this.owner) {
  5780. this.owner.addUpdatePositioningCounter(1);
  5781. }
  5782. // From this point we assume that the primitive layoutArea is computed and up to date.
  5783. // We know have to :
  5784. // 1. Determine the PaddingArea and the ActualPosition based on the margin/marginAlignment properties, which will also set the size property of the primitive
  5785. // 2. Determine the contentArea based on the padding property.
  5786. var isSizeAuto = this.isSizeAuto;
  5787. // 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
  5788. if (!this._hasMarginAlignment && (isSizeAuto || (this.actualSize.width == null || this.actualSize.height == null))) {
  5789. if (isSizeAuto || this.actualSize.width == null) {
  5790. this.marginAlignment.horizontal = PrimitiveAlignment.AlignStretch;
  5791. }
  5792. if (isSizeAuto || this.actualSize.height == null) {
  5793. this.marginAlignment.vertical = PrimitiveAlignment.AlignStretch;
  5794. }
  5795. }
  5796. // Apply margin
  5797. if (this._hasMargin) {
  5798. this.margin.computeWithAlignment(this.layoutArea, this.size || this.actualSize, this.marginAlignment, this._marginOffset, Prim2DBase_1._size);
  5799. this.actualSize = Prim2DBase_1._size.clone();
  5800. }
  5801. if (this._hasPadding) {
  5802. // Two cases from here: the size of the Primitive is Auto, its content can't be shrink, so we resize the primitive itself
  5803. if (isSizeAuto) {
  5804. var content = this.size.clone();
  5805. this._getActualSizeFromContentToRef(content, Prim2DBase_1._icArea);
  5806. this.padding.enlarge(Prim2DBase_1._icArea, this._paddingOffset, Prim2DBase_1._size);
  5807. this._contentArea.copyFrom(content);
  5808. this.actualSize = Prim2DBase_1._size.clone();
  5809. // Changing the padding has resize the prim, which forces us to recompute margin again
  5810. if (this._hasMargin) {
  5811. this.margin.computeWithAlignment(this.layoutArea, Prim2DBase_1._size, this.marginAlignment, this._marginOffset, Prim2DBase_1._size);
  5812. }
  5813. }
  5814. else {
  5815. this._getInitialContentAreaToRef(this.actualSize, Prim2DBase_1._icZone, Prim2DBase_1._icArea);
  5816. Prim2DBase_1._icArea.width = Math.max(0, Prim2DBase_1._icArea.width);
  5817. Prim2DBase_1._icArea.height = Math.max(0, Prim2DBase_1._icArea.height);
  5818. this.padding.compute(Prim2DBase_1._icArea, this._paddingOffset, Prim2DBase_1._size);
  5819. this._paddingOffset.x += Prim2DBase_1._icZone.x;
  5820. this._paddingOffset.y += Prim2DBase_1._icZone.y;
  5821. this._paddingOffset.z -= Prim2DBase_1._icZone.z;
  5822. this._paddingOffset.w -= Prim2DBase_1._icZone.w;
  5823. this._contentArea.copyFrom(Prim2DBase_1._size);
  5824. }
  5825. }
  5826. else {
  5827. this._getInitialContentAreaToRef(this.actualSize, Prim2DBase_1._icZone, Prim2DBase_1._icArea);
  5828. Prim2DBase_1._icArea.width = Math.max(0, Prim2DBase_1._icArea.width);
  5829. Prim2DBase_1._icArea.height = Math.max(0, Prim2DBase_1._icArea.height);
  5830. this._paddingOffset.x = Prim2DBase_1._icZone.x;
  5831. this._paddingOffset.y = Prim2DBase_1._icZone.y;
  5832. this._paddingOffset.z = Prim2DBase_1._icZone.z;
  5833. this._paddingOffset.w = Prim2DBase_1._icZone.w;
  5834. this._contentArea.copyFrom(Prim2DBase_1._icArea);
  5835. }
  5836. if (!this._position) {
  5837. var aPos = new BABYLON.Vector2(this.layoutAreaPos.x + this._marginOffset.x, this.layoutAreaPos.y + this._marginOffset.y);
  5838. this.actualPosition = aPos;
  5839. }
  5840. if (isSizeAuto) {
  5841. this._lastAutoSizeArea = this.actualSize;
  5842. }
  5843. if (this.displayDebugAreas) {
  5844. this._updateDebugArea();
  5845. }
  5846. };
  5847. Object.defineProperty(Prim2DBase.prototype, "contentArea", {
  5848. /**
  5849. * Get the content are of this primitive, this area is computed using the padding property and also possibly the primitive type itself.
  5850. * Children of this primitive will be positioned relative to the bottom/left corner of this area.
  5851. */
  5852. get: function () {
  5853. // Check for positioning update
  5854. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty)) {
  5855. this._updatePositioning();
  5856. this._clearFlags(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5857. }
  5858. return this._contentArea;
  5859. },
  5860. enumerable: true,
  5861. configurable: true
  5862. });
  5863. Prim2DBase.prototype._patchHierarchy = function (owner) {
  5864. this._owner = owner;
  5865. // The only place we initialize the _renderGroup is this method, if it's set, we already been there, no need to execute more
  5866. if (this._renderGroup != null) {
  5867. return;
  5868. }
  5869. if (this instanceof BABYLON.Group2D) {
  5870. var group = this;
  5871. group.detectGroupStates();
  5872. if (group._trackedNode && !group._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  5873. group.owner._registerTrackedNode(this);
  5874. }
  5875. }
  5876. this._renderGroup = this.traverseUp(function (p) { return p instanceof BABYLON.Group2D && p.isRenderableGroup; });
  5877. if (this._parent) {
  5878. this._parentLayoutDirty();
  5879. }
  5880. // Make sure the prim is in the dirtyList if it should be
  5881. if (this._renderGroup && this.isDirty) {
  5882. var list = this._renderGroup._renderableData._primDirtyList;
  5883. var i = list.indexOf(this);
  5884. if (i === -1) {
  5885. list.push(this);
  5886. }
  5887. }
  5888. // Recurse
  5889. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5890. var child = _a[_i];
  5891. child._hierarchyDepth = this._hierarchyDepth + 1;
  5892. child._patchHierarchy(owner);
  5893. }
  5894. };
  5895. Prim2DBase.prototype._updateZOrder = function () {
  5896. var prevLinPos = this._primLinearPosition;
  5897. var startI = 0;
  5898. var startZ = this._zOrder;
  5899. // 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
  5900. var childrenCount = this._children.length;
  5901. if (this._firstZDirtyIndex > 0) {
  5902. if ((this._firstZDirtyIndex - 1) < childrenCount) {
  5903. var prevPrim = this._children[this._firstZDirtyIndex - 1];
  5904. prevLinPos = prevPrim._primLinearPosition;
  5905. startI = this._firstZDirtyIndex - 1;
  5906. startZ = prevPrim._zOrder;
  5907. }
  5908. }
  5909. var startPos = prevLinPos;
  5910. // Update the linear position of the primitive from the first one to the last inside this primitive, compute the total number of prim traversed
  5911. Prim2DBase_1._totalCount = 0;
  5912. for (var i = startI; i < childrenCount; i++) {
  5913. var child = this._children[i];
  5914. prevLinPos = child._updatePrimitiveLinearPosition(prevLinPos);
  5915. }
  5916. // Compute the new Z-Order for all the primitives
  5917. // Add 20% to the current total count to reserve space for future insertions, except if we're rebuilding due to a zMinDelta reached
  5918. var zDelta = (this._zMax - startZ) / (Prim2DBase_1._totalCount * (Prim2DBase_1._zRebuildReentrency ? 1 : 1.2));
  5919. // 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.
  5920. if (zDelta < BABYLON.Canvas2D._zMinDelta) {
  5921. // 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...
  5922. if (Prim2DBase_1._zRebuildReentrency) {
  5923. var p = this._parent;
  5924. if (p == null) {
  5925. // 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...)
  5926. console.log("Can't compute Z-Order for " + this.id + "'s children, zDelta is too small, Z-Order is now in an unstable state");
  5927. Prim2DBase_1._zRebuildReentrency = false;
  5928. return;
  5929. }
  5930. p._firstZDirtyIndex = 0;
  5931. return p._updateZOrder();
  5932. }
  5933. Prim2DBase_1._zRebuildReentrency = true;
  5934. this._firstZDirtyIndex = 0;
  5935. this._updateZOrder();
  5936. Prim2DBase_1._zRebuildReentrency = false;
  5937. }
  5938. for (var i = startI; i < childrenCount; i++) {
  5939. var child = this._children[i];
  5940. child._updatePrimitiveZOrder(startPos, startZ, zDelta);
  5941. }
  5942. // Notify the Observers that we found during the Z change (we do it after to avoid any kind of re-entrance)
  5943. for (var _i = 0, _a = Prim2DBase_1._zOrderChangedNotifList; _i < _a.length; _i++) {
  5944. var p = _a[_i];
  5945. p._actualZOrderChangedObservable.notifyObservers(p.actualZOffset);
  5946. }
  5947. Prim2DBase_1._zOrderChangedNotifList.splice(0);
  5948. this._firstZDirtyIndex = Prim2DBase_1._bigInt;
  5949. this._clearFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  5950. };
  5951. Prim2DBase.prototype._updatePrimitiveLinearPosition = function (prevLinPos) {
  5952. if (this.isManualZOrder) {
  5953. return prevLinPos;
  5954. }
  5955. this._primLinearPosition = ++prevLinPos;
  5956. Prim2DBase_1._totalCount++;
  5957. // Check for the FlatZOrder, which means the children won't have a dedicated Z-Order but will all share the same (unique) one.
  5958. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder)) {
  5959. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5960. var child = _a[_i];
  5961. prevLinPos = child._updatePrimitiveLinearPosition(prevLinPos);
  5962. }
  5963. }
  5964. return prevLinPos;
  5965. };
  5966. Prim2DBase.prototype._updatePrimitiveZOrder = function (startPos, startZ, deltaZ) {
  5967. if (this.isManualZOrder) {
  5968. return null;
  5969. }
  5970. var newZ = startZ + ((this._primLinearPosition - startPos) * deltaZ);
  5971. var isFlat = this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  5972. this._setZOrder(newZ, false);
  5973. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  5974. this._firstZDirtyIndex = Prim2DBase_1._bigInt;
  5975. this._clearFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  5976. }
  5977. var curZ = newZ;
  5978. // Check for the FlatZOrder, which means the children won't have a dedicated Z-Order but will all share the same (unique) one.
  5979. if (isFlat) {
  5980. if (this._children.length > 0) {
  5981. //let childrenZOrder = startZ + ((this._children[0]._primLinearPosition - startPos) * deltaZ);
  5982. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5983. var child = _a[_i];
  5984. child._updatePrimitiveFlatZOrder(this._zOrder);
  5985. }
  5986. }
  5987. }
  5988. else {
  5989. for (var _b = 0, _c = this._children; _b < _c.length; _b++) {
  5990. var child = _c[_b];
  5991. var r = child._updatePrimitiveZOrder(startPos, startZ, deltaZ);
  5992. if (r != null) {
  5993. curZ = r;
  5994. }
  5995. }
  5996. }
  5997. this._zMax = isFlat ? newZ : (curZ + deltaZ);
  5998. return curZ;
  5999. };
  6000. Prim2DBase.prototype._updatePrimitiveFlatZOrder = function (newZ) {
  6001. if (this.isManualZOrder) {
  6002. return;
  6003. }
  6004. this._setZOrder(newZ, false);
  6005. this._zMax = newZ;
  6006. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  6007. this._firstZDirtyIndex = Prim2DBase_1._bigInt;
  6008. this._clearFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  6009. }
  6010. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  6011. var child = _a[_i];
  6012. child._updatePrimitiveFlatZOrder(newZ);
  6013. }
  6014. };
  6015. Prim2DBase.prototype._setZOrder = function (newZ, directEmit) {
  6016. if (newZ !== this._zOrder) {
  6017. this._zOrder = newZ;
  6018. this.onPrimBecomesDirty();
  6019. this.onZOrderChanged();
  6020. if (this._actualZOrderChangedObservable && this._actualZOrderChangedObservable.hasObservers()) {
  6021. if (directEmit) {
  6022. this._actualZOrderChangedObservable.notifyObservers(newZ);
  6023. }
  6024. else {
  6025. Prim2DBase_1._zOrderChangedNotifList.push(this);
  6026. }
  6027. }
  6028. }
  6029. };
  6030. Prim2DBase.prototype._updateRenderMode = function () {
  6031. };
  6032. /**
  6033. * This method is used to alter the contentArea of the Primitive before margin is applied.
  6034. * 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.
  6035. * @param primSize the current size of the primitive
  6036. * @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
  6037. * @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!
  6038. */
  6039. Prim2DBase.prototype._getInitialContentAreaToRef = function (primSize, initialContentPosition, initialContentArea) {
  6040. initialContentArea.copyFrom(primSize);
  6041. initialContentPosition.x = initialContentPosition.y = initialContentPosition.z = initialContentPosition.w = 0;
  6042. };
  6043. /**
  6044. * This method is used to calculate the new size of the primitive based on the content which must stay the same
  6045. * Check the Rectangle2D implementation for a concrete application.
  6046. * @param primSize the current size of the primitive
  6047. * @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!
  6048. */
  6049. Prim2DBase.prototype._getActualSizeFromContentToRef = function (primSize, newPrimSize) {
  6050. newPrimSize.copyFrom(primSize);
  6051. };
  6052. return Prim2DBase;
  6053. }(BABYLON.SmartPropertyPrim));
  6054. Prim2DBase.PRIM2DBASE_PROPCOUNT = 25;
  6055. Prim2DBase._bigInt = Math.pow(2, 30);
  6056. Prim2DBase._nullPosition = BABYLON.Vector2.Zero();
  6057. Prim2DBase.boundinbBoxReentrency = false;
  6058. Prim2DBase.nullSize = BABYLON.Size.Zero();
  6059. Prim2DBase._bMax = BABYLON.Vector2.Zero();
  6060. Prim2DBase._tpsBB = new BABYLON.BoundingInfo2D();
  6061. /**
  6062. * Make an intersection test with the primitive, all inputs/outputs are stored in the IntersectInfo2D class, see its documentation for more information.
  6063. * @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.
  6064. */
  6065. Prim2DBase._bypassGroup2DExclusion = false;
  6066. Prim2DBase._isCanvasInit = false;
  6067. Prim2DBase._t0 = new BABYLON.Matrix();
  6068. Prim2DBase._t1 = new BABYLON.Matrix();
  6069. Prim2DBase._t2 = new BABYLON.Matrix();
  6070. Prim2DBase._v0 = BABYLON.Vector2.Zero(); // Must stay with the value 0,0
  6071. Prim2DBase._transMtx = BABYLON.Matrix.Zero();
  6072. Prim2DBase._icPos = BABYLON.Vector2.Zero();
  6073. Prim2DBase._icZone = BABYLON.Vector4.Zero();
  6074. Prim2DBase._icArea = BABYLON.Size.Zero();
  6075. Prim2DBase._size = BABYLON.Size.Zero();
  6076. Prim2DBase._zOrderChangedNotifList = new Array();
  6077. Prim2DBase._zRebuildReentrency = false;
  6078. Prim2DBase._totalCount = 0;
  6079. __decorate([
  6080. BABYLON.instanceLevelProperty(1, function (pi) { return Prim2DBase_1.actualPositionProperty = pi; }, false, false, true)
  6081. ], Prim2DBase.prototype, "actualPosition", null);
  6082. __decorate([
  6083. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 1, function (pi) { return Prim2DBase_1.actualXProperty = pi; }, false, false, true)
  6084. ], Prim2DBase.prototype, "actualX", null);
  6085. __decorate([
  6086. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 2, function (pi) { return Prim2DBase_1.actualYProperty = pi; }, false, false, true)
  6087. ], Prim2DBase.prototype, "actualY", null);
  6088. __decorate([
  6089. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 3, function (pi) { return Prim2DBase_1.positionProperty = pi; }, false, false, true)
  6090. ], Prim2DBase.prototype, "position", null);
  6091. __decorate([
  6092. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 4, function (pi) { return Prim2DBase_1.xProperty = pi; }, false, false, true)
  6093. ], Prim2DBase.prototype, "x", null);
  6094. __decorate([
  6095. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 5, function (pi) { return Prim2DBase_1.yProperty = pi; }, false, false, true)
  6096. ], Prim2DBase.prototype, "y", null);
  6097. __decorate([
  6098. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 6, function (pi) { return Prim2DBase_1.sizeProperty = pi; }, false, true)
  6099. ], Prim2DBase.prototype, "size", null);
  6100. __decorate([
  6101. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 7, function (pi) { return Prim2DBase_1.widthProperty = pi; }, false, true)
  6102. ], Prim2DBase.prototype, "width", null);
  6103. __decorate([
  6104. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 8, function (pi) { return Prim2DBase_1.heightProperty = pi; }, false, true)
  6105. ], Prim2DBase.prototype, "height", null);
  6106. __decorate([
  6107. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 9, function (pi) { return Prim2DBase_1.rotationProperty = pi; }, false, true)
  6108. ], Prim2DBase.prototype, "rotation", null);
  6109. __decorate([
  6110. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 10, function (pi) { return Prim2DBase_1.scaleProperty = pi; }, false, true)
  6111. ], Prim2DBase.prototype, "scale", null);
  6112. __decorate([
  6113. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 11, function (pi) { return Prim2DBase_1.actualSizeProperty = pi; }, false, true)
  6114. ], Prim2DBase.prototype, "actualSize", null);
  6115. __decorate([
  6116. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 12, function (pi) { return Prim2DBase_1.actualWidthProperty = pi; }, false, true)
  6117. ], Prim2DBase.prototype, "actualWidth", null);
  6118. __decorate([
  6119. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 13, function (pi) { return Prim2DBase_1.actualHeightProperty = pi; }, false, true)
  6120. ], Prim2DBase.prototype, "actualHeight", null);
  6121. __decorate([
  6122. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 14, function (pi) { return Prim2DBase_1.originProperty = pi; }, false, true)
  6123. ], Prim2DBase.prototype, "origin", null);
  6124. __decorate([
  6125. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 15, function (pi) { return Prim2DBase_1.levelVisibleProperty = pi; })
  6126. ], Prim2DBase.prototype, "levelVisible", null);
  6127. __decorate([
  6128. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 16, function (pi) { return Prim2DBase_1.isVisibleProperty = pi; })
  6129. ], Prim2DBase.prototype, "isVisible", null);
  6130. __decorate([
  6131. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 17, function (pi) { return Prim2DBase_1.zOrderProperty = pi; })
  6132. ], Prim2DBase.prototype, "zOrder", null);
  6133. __decorate([
  6134. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 18, function (pi) { return Prim2DBase_1.marginProperty = pi; })
  6135. ], Prim2DBase.prototype, "margin", null);
  6136. __decorate([
  6137. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 19, function (pi) { return Prim2DBase_1.paddingProperty = pi; })
  6138. ], Prim2DBase.prototype, "padding", null);
  6139. __decorate([
  6140. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 20, function (pi) { return Prim2DBase_1.marginAlignmentProperty = pi; })
  6141. ], Prim2DBase.prototype, "marginAlignment", null);
  6142. __decorate([
  6143. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 21, function (pi) { return Prim2DBase_1.opacityProperty = pi; })
  6144. ], Prim2DBase.prototype, "opacity", null);
  6145. __decorate([
  6146. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 22, function (pi) { return Prim2DBase_1.scaleXProperty = pi; }, false, true)
  6147. ], Prim2DBase.prototype, "scaleX", null);
  6148. __decorate([
  6149. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 23, function (pi) { return Prim2DBase_1.scaleYProperty = pi; }, false, true)
  6150. ], Prim2DBase.prototype, "scaleY", null);
  6151. __decorate([
  6152. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 24, function (pi) { return Prim2DBase_1.actualScaleProperty = pi; }, false, true)
  6153. ], Prim2DBase.prototype, "actualScale", null);
  6154. Prim2DBase = Prim2DBase_1 = __decorate([
  6155. BABYLON.className("Prim2DBase", "BABYLON")
  6156. ], Prim2DBase);
  6157. BABYLON.Prim2DBase = Prim2DBase;
  6158. var PrimitiveAlignment_1, PrimitiveThickness_1, Prim2DBase_1;
  6159. })(BABYLON || (BABYLON = {}));
  6160. //# sourceMappingURL=babylon.prim2dBase.js.map
  6161. var __extends = (this && this.__extends) || function (d, b) {
  6162. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  6163. function __() { this.constructor = d; }
  6164. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6165. };
  6166. var BABYLON;
  6167. (function (BABYLON) {
  6168. var GroupInstanceInfo = (function () {
  6169. function GroupInstanceInfo(owner, mrc, partCount) {
  6170. this._partCount = partCount;
  6171. this.owner = owner;
  6172. this.modelRenderCache = mrc;
  6173. this.modelRenderCache.addRef();
  6174. this.partIndexFromId = new BABYLON.StringDictionary();
  6175. this._usedShaderCategories = new Array(partCount);
  6176. this._strides = new Array(partCount);
  6177. this._opaqueData = null;
  6178. this._alphaTestData = null;
  6179. this._transparentData = null;
  6180. this.opaqueDirty = this.alphaTestDirty = this.transparentDirty = this.transparentOrderDirty = false;
  6181. }
  6182. GroupInstanceInfo.prototype.dispose = function () {
  6183. if (this._isDisposed) {
  6184. return false;
  6185. }
  6186. if (this.modelRenderCache) {
  6187. this.modelRenderCache.dispose();
  6188. this.modelRenderCache = null;
  6189. }
  6190. var engine = this.owner.owner.engine;
  6191. if (this._opaqueData) {
  6192. this._opaqueData.forEach(function (d) { return d.dispose(engine); });
  6193. this._opaqueData = null;
  6194. }
  6195. if (this._alphaTestData) {
  6196. this._alphaTestData.forEach(function (d) { return d.dispose(engine); });
  6197. this._alphaTestData = null;
  6198. }
  6199. if (this._transparentData) {
  6200. this._transparentData.forEach(function (d) { return d.dispose(engine); });
  6201. this._transparentData = null;
  6202. }
  6203. this.partIndexFromId = null;
  6204. this._isDisposed = true;
  6205. return true;
  6206. };
  6207. Object.defineProperty(GroupInstanceInfo.prototype, "hasOpaqueData", {
  6208. get: function () {
  6209. return this._opaqueData != null;
  6210. },
  6211. enumerable: true,
  6212. configurable: true
  6213. });
  6214. Object.defineProperty(GroupInstanceInfo.prototype, "hasAlphaTestData", {
  6215. get: function () {
  6216. return this._alphaTestData != null;
  6217. },
  6218. enumerable: true,
  6219. configurable: true
  6220. });
  6221. Object.defineProperty(GroupInstanceInfo.prototype, "hasTransparentData", {
  6222. get: function () {
  6223. return this._transparentData != null;
  6224. },
  6225. enumerable: true,
  6226. configurable: true
  6227. });
  6228. Object.defineProperty(GroupInstanceInfo.prototype, "opaqueData", {
  6229. get: function () {
  6230. if (!this._opaqueData) {
  6231. this._opaqueData = new Array(this._partCount);
  6232. for (var i = 0; i < this._partCount; i++) {
  6233. this._opaqueData[i] = new GroupInfoPartData(this._strides[i]);
  6234. }
  6235. }
  6236. return this._opaqueData;
  6237. },
  6238. enumerable: true,
  6239. configurable: true
  6240. });
  6241. Object.defineProperty(GroupInstanceInfo.prototype, "alphaTestData", {
  6242. get: function () {
  6243. if (!this._alphaTestData) {
  6244. this._alphaTestData = new Array(this._partCount);
  6245. for (var i = 0; i < this._partCount; i++) {
  6246. this._alphaTestData[i] = new GroupInfoPartData(this._strides[i]);
  6247. }
  6248. }
  6249. return this._alphaTestData;
  6250. },
  6251. enumerable: true,
  6252. configurable: true
  6253. });
  6254. Object.defineProperty(GroupInstanceInfo.prototype, "transparentData", {
  6255. get: function () {
  6256. if (!this._transparentData) {
  6257. this._transparentData = new Array(this._partCount);
  6258. for (var i = 0; i < this._partCount; i++) {
  6259. var zoff = this.modelRenderCache._partData[i]._zBiasOffset;
  6260. this._transparentData[i] = new TransparentGroupInfoPartData(this._strides[i], zoff);
  6261. }
  6262. }
  6263. return this._transparentData;
  6264. },
  6265. enumerable: true,
  6266. configurable: true
  6267. });
  6268. GroupInstanceInfo.prototype.sortTransparentData = function () {
  6269. if (!this.transparentOrderDirty) {
  6270. return;
  6271. }
  6272. for (var i = 0; i < this._transparentData.length; i++) {
  6273. var td = this._transparentData[i];
  6274. td._partData.sort();
  6275. }
  6276. this.transparentOrderDirty = false;
  6277. };
  6278. Object.defineProperty(GroupInstanceInfo.prototype, "usedShaderCategories", {
  6279. get: function () {
  6280. return this._usedShaderCategories;
  6281. },
  6282. enumerable: true,
  6283. configurable: true
  6284. });
  6285. Object.defineProperty(GroupInstanceInfo.prototype, "strides", {
  6286. get: function () {
  6287. return this._strides;
  6288. },
  6289. enumerable: true,
  6290. configurable: true
  6291. });
  6292. return GroupInstanceInfo;
  6293. }());
  6294. BABYLON.GroupInstanceInfo = GroupInstanceInfo;
  6295. var TransparentSegment = (function () {
  6296. function TransparentSegment() {
  6297. this.groupInsanceInfo = null;
  6298. this.startZ = 0;
  6299. this.endZ = 0;
  6300. this.startDataIndex = BABYLON.Prim2DBase._bigInt;
  6301. this.endDataIndex = 0;
  6302. this.partBuffers = null;
  6303. }
  6304. TransparentSegment.prototype.dispose = function (engine) {
  6305. if (this.partBuffers) {
  6306. this.partBuffers.forEach(function (b) { return engine._releaseBuffer(b); });
  6307. this.partBuffers.splice(0);
  6308. this.partBuffers = null;
  6309. }
  6310. };
  6311. return TransparentSegment;
  6312. }());
  6313. BABYLON.TransparentSegment = TransparentSegment;
  6314. var GroupInfoPartData = (function () {
  6315. function GroupInfoPartData(stride) {
  6316. this._partData = null;
  6317. this._partBuffer = null;
  6318. this._partBufferSize = 0;
  6319. this._partData = new BABYLON.DynamicFloatArray(stride / 4, 50);
  6320. this._isDisposed = false;
  6321. }
  6322. GroupInfoPartData.prototype.dispose = function (engine) {
  6323. if (this._isDisposed) {
  6324. return false;
  6325. }
  6326. if (this._partBuffer) {
  6327. engine._releaseBuffer(this._partBuffer);
  6328. this._partBuffer = null;
  6329. }
  6330. this._partData = null;
  6331. this._isDisposed = true;
  6332. };
  6333. return GroupInfoPartData;
  6334. }());
  6335. BABYLON.GroupInfoPartData = GroupInfoPartData;
  6336. var TransparentGroupInfoPartData = (function (_super) {
  6337. __extends(TransparentGroupInfoPartData, _super);
  6338. function TransparentGroupInfoPartData(stride, zoff) {
  6339. var _this = _super.call(this, stride) || this;
  6340. _this._partData.compareValueOffset = zoff;
  6341. _this._partData.sortingAscending = false;
  6342. return _this;
  6343. }
  6344. return TransparentGroupInfoPartData;
  6345. }(GroupInfoPartData));
  6346. BABYLON.TransparentGroupInfoPartData = TransparentGroupInfoPartData;
  6347. var ModelRenderCache = (function () {
  6348. function ModelRenderCache(engine, modelKey) {
  6349. this._engine = engine;
  6350. this._modelKey = modelKey;
  6351. this._nextKey = 1;
  6352. this._refCounter = 1;
  6353. this._partData = null;
  6354. }
  6355. ModelRenderCache.prototype.dispose = function () {
  6356. if (--this._refCounter !== 0) {
  6357. return false;
  6358. }
  6359. // Remove the Model Render Cache from the global dictionary
  6360. var edata = this._engine.getExternalData("__BJSCANVAS2D__");
  6361. if (edata) {
  6362. edata.DisposeModelRenderCache(this);
  6363. }
  6364. return true;
  6365. };
  6366. Object.defineProperty(ModelRenderCache.prototype, "isDisposed", {
  6367. get: function () {
  6368. return this._refCounter <= 0;
  6369. },
  6370. enumerable: true,
  6371. configurable: true
  6372. });
  6373. ModelRenderCache.prototype.addRef = function () {
  6374. return ++this._refCounter;
  6375. };
  6376. Object.defineProperty(ModelRenderCache.prototype, "modelKey", {
  6377. get: function () {
  6378. return this._modelKey;
  6379. },
  6380. enumerable: true,
  6381. configurable: true
  6382. });
  6383. /**
  6384. * Render the model instances
  6385. * @param instanceInfo
  6386. * @param context
  6387. * @return must return true is the rendering succeed, false if the rendering couldn't be done (asset's not yet ready, like Effect)
  6388. */
  6389. ModelRenderCache.prototype.render = function (instanceInfo, context) {
  6390. return true;
  6391. };
  6392. ModelRenderCache.prototype.getPartIndexFromId = function (partId) {
  6393. for (var i = 0; i < this._partData.length; i++) {
  6394. if (this._partData[i]._partId === partId) {
  6395. return i;
  6396. }
  6397. }
  6398. return null;
  6399. };
  6400. ModelRenderCache.prototype.loadInstancingAttributes = function (partId, effect) {
  6401. var i = this.getPartIndexFromId(partId);
  6402. if (i === null) {
  6403. return null;
  6404. }
  6405. var ci = this._partsClassInfo[i];
  6406. var categories = this._partData[i]._partUsedCategories;
  6407. var res = ci.classContent.getInstancingAttributeInfos(effect, categories);
  6408. return res;
  6409. };
  6410. ModelRenderCache.prototype.setupUniforms = function (effect, partIndex, data, elementCount) {
  6411. var pd = this._partData[partIndex];
  6412. var offset = (pd._partDataStride / 4) * elementCount;
  6413. var pci = this._partsClassInfo[partIndex];
  6414. var self = this;
  6415. pci.fullContent.forEach(function (k, v) {
  6416. if (!v.category || pd._partUsedCategories.indexOf(v.category) !== -1) {
  6417. switch (v.dataType) {
  6418. case 4 /* float */:
  6419. {
  6420. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  6421. effect.setFloat(v.attributeName, data.buffer[offset + attribOffset]);
  6422. break;
  6423. }
  6424. case 0 /* Vector2 */:
  6425. {
  6426. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  6427. ModelRenderCache.v2.x = data.buffer[offset + attribOffset + 0];
  6428. ModelRenderCache.v2.y = data.buffer[offset + attribOffset + 1];
  6429. effect.setVector2(v.attributeName, ModelRenderCache.v2);
  6430. break;
  6431. }
  6432. case 5 /* Color3 */:
  6433. case 1 /* Vector3 */:
  6434. {
  6435. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  6436. ModelRenderCache.v3.x = data.buffer[offset + attribOffset + 0];
  6437. ModelRenderCache.v3.y = data.buffer[offset + attribOffset + 1];
  6438. ModelRenderCache.v3.z = data.buffer[offset + attribOffset + 2];
  6439. effect.setVector3(v.attributeName, ModelRenderCache.v3);
  6440. break;
  6441. }
  6442. case 6 /* Color4 */:
  6443. case 2 /* Vector4 */:
  6444. {
  6445. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  6446. ModelRenderCache.v4.x = data.buffer[offset + attribOffset + 0];
  6447. ModelRenderCache.v4.y = data.buffer[offset + attribOffset + 1];
  6448. ModelRenderCache.v4.z = data.buffer[offset + attribOffset + 2];
  6449. ModelRenderCache.v4.w = data.buffer[offset + attribOffset + 3];
  6450. effect.setVector4(v.attributeName, ModelRenderCache.v4);
  6451. break;
  6452. }
  6453. default:
  6454. }
  6455. }
  6456. });
  6457. };
  6458. return ModelRenderCache;
  6459. }());
  6460. //setupUniformsLocation(effect: Effect, uniforms: string[], partId: number) {
  6461. // let i = this.getPartIndexFromId(partId);
  6462. // if (i === null) {
  6463. // return null;
  6464. // }
  6465. // let pci = this._partsClassInfo[i];
  6466. // pci.fullContent.forEach((k, v) => {
  6467. // if (uniforms.indexOf(v.attributeName) !== -1) {
  6468. // v.uniformLocation = effect.getUniform(v.attributeName);
  6469. // }
  6470. // });
  6471. //}
  6472. ModelRenderCache.v2 = BABYLON.Vector2.Zero();
  6473. ModelRenderCache.v3 = BABYLON.Vector3.Zero();
  6474. ModelRenderCache.v4 = BABYLON.Vector4.Zero();
  6475. BABYLON.ModelRenderCache = ModelRenderCache;
  6476. var ModelRenderCachePartData = (function () {
  6477. function ModelRenderCachePartData() {
  6478. }
  6479. return ModelRenderCachePartData;
  6480. }());
  6481. BABYLON.ModelRenderCachePartData = ModelRenderCachePartData;
  6482. })(BABYLON || (BABYLON = {}));
  6483. //# sourceMappingURL=babylon.modelRenderCache.js.map
  6484. var __extends = (this && this.__extends) || function (d, b) {
  6485. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  6486. function __() { this.constructor = d; }
  6487. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6488. };
  6489. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  6490. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  6491. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  6492. 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;
  6493. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6494. };
  6495. var BABYLON;
  6496. (function (BABYLON) {
  6497. var InstanceClassInfo = (function () {
  6498. function InstanceClassInfo(base) {
  6499. this._baseInfo = base;
  6500. this._nextOffset = new BABYLON.StringDictionary();
  6501. this._attributes = new Array();
  6502. }
  6503. InstanceClassInfo.prototype.mapProperty = function (propInfo, push) {
  6504. var curOff = this._nextOffset.getOrAdd(InstanceClassInfo._CurCategories, 0);
  6505. propInfo.instanceOffset.add(InstanceClassInfo._CurCategories, this._getBaseOffset(InstanceClassInfo._CurCategories) + curOff);
  6506. //console.log(`[${InstanceClassInfo._CurCategories}] New PropInfo. Category: ${propInfo.category}, Name: ${propInfo.attributeName}, Offset: ${propInfo.instanceOffset.get(InstanceClassInfo._CurCategories)}, Size: ${propInfo.size / 4}`);
  6507. this._nextOffset.set(InstanceClassInfo._CurCategories, curOff + (propInfo.size / 4));
  6508. if (push) {
  6509. this._attributes.push(propInfo);
  6510. }
  6511. };
  6512. InstanceClassInfo.prototype.getInstancingAttributeInfos = function (effect, categories) {
  6513. var catInline = ";" + categories.join(";") + ";";
  6514. var res = new Array();
  6515. var curInfo = this;
  6516. while (curInfo) {
  6517. for (var _i = 0, _a = curInfo._attributes; _i < _a.length; _i++) {
  6518. var attrib = _a[_i];
  6519. // 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
  6520. if (!attrib.category || categories.indexOf(attrib.category) !== -1) {
  6521. var index = effect.getAttributeLocationByName(attrib.attributeName);
  6522. var iai = new BABYLON.InstancingAttributeInfo();
  6523. iai.index = index;
  6524. 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)
  6525. iai.offset = attrib.instanceOffset.get(catInline) * 4; // attrib.instanceOffset is in float, iai.offset must be in bytes
  6526. iai.attributeName = attrib.attributeName;
  6527. res.push(iai);
  6528. }
  6529. }
  6530. curInfo = curInfo._baseInfo;
  6531. }
  6532. return res;
  6533. };
  6534. InstanceClassInfo.prototype.getShaderAttributes = function (categories) {
  6535. var res = new Array();
  6536. var curInfo = this;
  6537. while (curInfo) {
  6538. for (var _i = 0, _a = curInfo._attributes; _i < _a.length; _i++) {
  6539. var attrib = _a[_i];
  6540. // 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
  6541. if (!attrib.category || categories.indexOf(attrib.category) !== -1) {
  6542. res.push(attrib.attributeName);
  6543. }
  6544. }
  6545. curInfo = curInfo._baseInfo;
  6546. }
  6547. return res;
  6548. };
  6549. InstanceClassInfo.prototype._getBaseOffset = function (categories) {
  6550. var curOffset = 0;
  6551. var curBase = this._baseInfo;
  6552. while (curBase) {
  6553. curOffset += curBase._nextOffset.getOrAdd(categories, 0);
  6554. curBase = curBase._baseInfo;
  6555. }
  6556. return curOffset;
  6557. };
  6558. return InstanceClassInfo;
  6559. }());
  6560. BABYLON.InstanceClassInfo = InstanceClassInfo;
  6561. var InstancePropInfo = (function () {
  6562. function InstancePropInfo() {
  6563. this.instanceOffset = new BABYLON.StringDictionary();
  6564. }
  6565. InstancePropInfo.prototype.setSize = function (val) {
  6566. if (val instanceof BABYLON.Vector2) {
  6567. this.size = 8;
  6568. this.dataType = 0 /* Vector2 */;
  6569. return;
  6570. }
  6571. if (val instanceof BABYLON.Vector3) {
  6572. this.size = 12;
  6573. this.dataType = 1 /* Vector3 */;
  6574. return;
  6575. }
  6576. if (val instanceof BABYLON.Vector4) {
  6577. this.size = 16;
  6578. this.dataType = 2 /* Vector4 */;
  6579. return;
  6580. }
  6581. if (val instanceof BABYLON.Matrix) {
  6582. throw new Error("Matrix type is not supported by WebGL Instance Buffer, you have to use four Vector4 properties instead");
  6583. }
  6584. if (typeof (val) === "number") {
  6585. this.size = 4;
  6586. this.dataType = 4 /* float */;
  6587. return;
  6588. }
  6589. if (val instanceof BABYLON.Color3) {
  6590. this.size = 12;
  6591. this.dataType = 5 /* Color3 */;
  6592. return;
  6593. }
  6594. if (val instanceof BABYLON.Color4) {
  6595. this.size = 16;
  6596. this.dataType = 6 /* Color4 */;
  6597. return;
  6598. }
  6599. if (val instanceof BABYLON.Size) {
  6600. this.size = 8;
  6601. this.dataType = 7 /* Size */;
  6602. return;
  6603. }
  6604. return;
  6605. };
  6606. InstancePropInfo.prototype.writeData = function (array, offset, val) {
  6607. switch (this.dataType) {
  6608. case 0 /* Vector2 */:
  6609. {
  6610. var v = val;
  6611. array[offset + 0] = v.x;
  6612. array[offset + 1] = v.y;
  6613. break;
  6614. }
  6615. case 1 /* Vector3 */:
  6616. {
  6617. var v = val;
  6618. array[offset + 0] = v.x;
  6619. array[offset + 1] = v.y;
  6620. array[offset + 2] = v.z;
  6621. break;
  6622. }
  6623. case 2 /* Vector4 */:
  6624. {
  6625. var v = val;
  6626. array[offset + 0] = v.x;
  6627. array[offset + 1] = v.y;
  6628. array[offset + 2] = v.z;
  6629. array[offset + 3] = v.w;
  6630. break;
  6631. }
  6632. case 5 /* Color3 */:
  6633. {
  6634. var v = val;
  6635. array[offset + 0] = v.r;
  6636. array[offset + 1] = v.g;
  6637. array[offset + 2] = v.b;
  6638. break;
  6639. }
  6640. case 6 /* Color4 */:
  6641. {
  6642. var v = val;
  6643. array[offset + 0] = v.r;
  6644. array[offset + 1] = v.g;
  6645. array[offset + 2] = v.b;
  6646. array[offset + 3] = v.a;
  6647. break;
  6648. }
  6649. case 4 /* float */:
  6650. {
  6651. var v = val;
  6652. array[offset] = v;
  6653. break;
  6654. }
  6655. case 3 /* Matrix */:
  6656. {
  6657. var v = val;
  6658. for (var i = 0; i < 16; i++) {
  6659. array[offset + i] = v.m[i];
  6660. }
  6661. break;
  6662. }
  6663. case 7 /* Size */:
  6664. {
  6665. var s = val;
  6666. array[offset + 0] = s.width;
  6667. array[offset + 1] = s.height;
  6668. break;
  6669. }
  6670. }
  6671. };
  6672. return InstancePropInfo;
  6673. }());
  6674. BABYLON.InstancePropInfo = InstancePropInfo;
  6675. function instanceData(category, shaderAttributeName) {
  6676. return function (target, propName, descriptor) {
  6677. var dic = BABYLON.ClassTreeInfo.getOrRegister(target, function (base) { return new InstanceClassInfo(base); });
  6678. var node = dic.getLevelOf(target);
  6679. var instanceDataName = propName;
  6680. shaderAttributeName = shaderAttributeName || instanceDataName;
  6681. var info = node.levelContent.get(instanceDataName);
  6682. if (info) {
  6683. throw new Error("The ID " + instanceDataName + " is already taken by another instance data");
  6684. }
  6685. info = new InstancePropInfo();
  6686. info.attributeName = shaderAttributeName;
  6687. info.category = category || null;
  6688. if (info.category) {
  6689. info.delimitedCategory = ";" + info.category + ";";
  6690. }
  6691. node.levelContent.add(instanceDataName, info);
  6692. descriptor.get = function () {
  6693. return null;
  6694. };
  6695. descriptor.set = function (val) {
  6696. // Check that we're not trying to set a property that belongs to a category that is not allowed (current)
  6697. // Quit if it's the case, otherwise we could overwrite data somewhere...
  6698. if (info.category && InstanceClassInfo._CurCategories.indexOf(info.delimitedCategory) === -1) {
  6699. return;
  6700. }
  6701. if (!info.size) {
  6702. info.setSize(val);
  6703. node.classContent.mapProperty(info, true);
  6704. }
  6705. else if (!info.instanceOffset.contains(InstanceClassInfo._CurCategories)) {
  6706. node.classContent.mapProperty(info, false);
  6707. }
  6708. var obj = this;
  6709. if (obj.dataBuffer && obj.dataElements) {
  6710. var offset = obj.dataElements[obj.curElement].offset + info.instanceOffset.get(InstanceClassInfo._CurCategories);
  6711. info.writeData(obj.dataBuffer.buffer, offset, val);
  6712. }
  6713. };
  6714. };
  6715. }
  6716. BABYLON.instanceData = instanceData;
  6717. var InstanceDataBase = (function () {
  6718. function InstanceDataBase(partId, dataElementCount) {
  6719. this.id = partId;
  6720. this.curElement = 0;
  6721. this._dataElementCount = dataElementCount;
  6722. this.renderMode = 0;
  6723. this.arrayLengthChanged = false;
  6724. }
  6725. Object.defineProperty(InstanceDataBase.prototype, "zBias", {
  6726. get: function () {
  6727. return null;
  6728. },
  6729. set: function (value) {
  6730. },
  6731. enumerable: true,
  6732. configurable: true
  6733. });
  6734. Object.defineProperty(InstanceDataBase.prototype, "transformX", {
  6735. get: function () {
  6736. return null;
  6737. },
  6738. set: function (value) {
  6739. },
  6740. enumerable: true,
  6741. configurable: true
  6742. });
  6743. Object.defineProperty(InstanceDataBase.prototype, "transformY", {
  6744. get: function () {
  6745. return null;
  6746. },
  6747. set: function (value) {
  6748. },
  6749. enumerable: true,
  6750. configurable: true
  6751. });
  6752. Object.defineProperty(InstanceDataBase.prototype, "opacity", {
  6753. get: function () {
  6754. return null;
  6755. },
  6756. set: function (value) {
  6757. },
  6758. enumerable: true,
  6759. configurable: true
  6760. });
  6761. InstanceDataBase.prototype.getClassTreeInfo = function () {
  6762. if (!this.typeInfo) {
  6763. this.typeInfo = BABYLON.ClassTreeInfo.get(Object.getPrototypeOf(this));
  6764. }
  6765. return this.typeInfo;
  6766. };
  6767. InstanceDataBase.prototype.allocElements = function () {
  6768. if (!this.dataBuffer || this.dataElements) {
  6769. return;
  6770. }
  6771. var res = new Array(this.dataElementCount);
  6772. for (var i = 0; i < this.dataElementCount; i++) {
  6773. res[i] = this.dataBuffer.allocElement();
  6774. }
  6775. this.dataElements = res;
  6776. };
  6777. InstanceDataBase.prototype.freeElements = function () {
  6778. if (!this.dataElements) {
  6779. return;
  6780. }
  6781. for (var _i = 0, _a = this.dataElements; _i < _a.length; _i++) {
  6782. var ei = _a[_i];
  6783. this.dataBuffer.freeElement(ei);
  6784. }
  6785. this.dataElements = null;
  6786. };
  6787. Object.defineProperty(InstanceDataBase.prototype, "dataElementCount", {
  6788. get: function () {
  6789. return this._dataElementCount;
  6790. },
  6791. set: function (value) {
  6792. if (value === this._dataElementCount) {
  6793. return;
  6794. }
  6795. this.arrayLengthChanged = true;
  6796. this.freeElements();
  6797. this._dataElementCount = value;
  6798. this.allocElements();
  6799. },
  6800. enumerable: true,
  6801. configurable: true
  6802. });
  6803. return InstanceDataBase;
  6804. }());
  6805. __decorate([
  6806. instanceData()
  6807. ], InstanceDataBase.prototype, "zBias", null);
  6808. __decorate([
  6809. instanceData()
  6810. ], InstanceDataBase.prototype, "transformX", null);
  6811. __decorate([
  6812. instanceData()
  6813. ], InstanceDataBase.prototype, "transformY", null);
  6814. __decorate([
  6815. instanceData()
  6816. ], InstanceDataBase.prototype, "opacity", null);
  6817. BABYLON.InstanceDataBase = InstanceDataBase;
  6818. var RenderablePrim2D = RenderablePrim2D_1 = (function (_super) {
  6819. __extends(RenderablePrim2D, _super);
  6820. function RenderablePrim2D(settings) {
  6821. var _this = _super.call(this, settings) || this;
  6822. _this._transparentPrimitiveInfo = null;
  6823. return _this;
  6824. }
  6825. Object.defineProperty(RenderablePrim2D.prototype, "isAlphaTest", {
  6826. get: function () {
  6827. return this._useTextureAlpha() || this._isPrimAlphaTest();
  6828. },
  6829. enumerable: true,
  6830. configurable: true
  6831. });
  6832. Object.defineProperty(RenderablePrim2D.prototype, "isTransparent", {
  6833. get: function () {
  6834. return (this.actualOpacity < 1) || this._shouldUseAlphaFromTexture() || this._isPrimTransparent();
  6835. },
  6836. enumerable: true,
  6837. configurable: true
  6838. });
  6839. Object.defineProperty(RenderablePrim2D.prototype, "renderMode", {
  6840. get: function () {
  6841. return this._renderMode;
  6842. },
  6843. enumerable: true,
  6844. configurable: true
  6845. });
  6846. /**
  6847. * Dispose the primitive and its resources, remove it from its parent
  6848. */
  6849. RenderablePrim2D.prototype.dispose = function () {
  6850. if (!_super.prototype.dispose.call(this)) {
  6851. return false;
  6852. }
  6853. if (this.renderGroup) {
  6854. this.renderGroup._setCacheGroupDirty();
  6855. }
  6856. if (this._transparentPrimitiveInfo) {
  6857. this.renderGroup._renderableData.removeTransparentPrimitiveInfo(this._transparentPrimitiveInfo);
  6858. this._transparentPrimitiveInfo = null;
  6859. }
  6860. if (this._instanceDataParts) {
  6861. this._cleanupInstanceDataParts();
  6862. }
  6863. if (this._modelRenderCache) {
  6864. this._modelRenderCache.dispose();
  6865. this._modelRenderCache = null;
  6866. }
  6867. if (this._instanceDataParts) {
  6868. this._instanceDataParts.forEach(function (p) {
  6869. p.freeElements();
  6870. });
  6871. this._instanceDataParts = null;
  6872. }
  6873. return true;
  6874. };
  6875. RenderablePrim2D.prototype._cleanupInstanceDataParts = function () {
  6876. var gii = null;
  6877. for (var _i = 0, _a = this._instanceDataParts; _i < _a.length; _i++) {
  6878. var part = _a[_i];
  6879. part.freeElements();
  6880. gii = part.groupInstanceInfo;
  6881. }
  6882. if (gii) {
  6883. var usedCount = 0;
  6884. if (gii.hasOpaqueData) {
  6885. var od = gii.opaqueData[0];
  6886. usedCount += od._partData.usedElementCount;
  6887. gii.opaqueDirty = true;
  6888. }
  6889. if (gii.hasAlphaTestData) {
  6890. var atd = gii.alphaTestData[0];
  6891. usedCount += atd._partData.usedElementCount;
  6892. gii.alphaTestDirty = true;
  6893. }
  6894. if (gii.hasTransparentData) {
  6895. var td = gii.transparentData[0];
  6896. usedCount += td._partData.usedElementCount;
  6897. gii.transparentDirty = true;
  6898. }
  6899. if (usedCount === 0 && gii.modelRenderCache != null) {
  6900. this.renderGroup._renderableData._renderGroupInstancesInfo.remove(gii.modelRenderCache.modelKey);
  6901. gii.dispose();
  6902. }
  6903. if (this._modelRenderCache) {
  6904. this._modelRenderCache.dispose();
  6905. this._modelRenderCache = null;
  6906. }
  6907. }
  6908. this._instanceDataParts = null;
  6909. };
  6910. RenderablePrim2D.prototype._prepareRenderPre = function (context) {
  6911. _super.prototype._prepareRenderPre.call(this, context);
  6912. // If the model changed and we have already an instance, we must remove this instance from the obsolete model
  6913. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagModelDirty) && this._instanceDataParts) {
  6914. this._cleanupInstanceDataParts();
  6915. }
  6916. // Need to create the model?
  6917. var setupModelRenderCache = false;
  6918. if (!this._modelRenderCache || this._isFlagSet(BABYLON.SmartPropertyPrim.flagModelDirty)) {
  6919. setupModelRenderCache = this._createModelRenderCache();
  6920. }
  6921. var gii = null;
  6922. var newInstance = false;
  6923. // Need to create the instance data parts?
  6924. if (!this._instanceDataParts) {
  6925. // Yes, flag it for later, more processing will have to be done
  6926. newInstance = true;
  6927. gii = this._createModelDataParts();
  6928. }
  6929. // If the ModelRenderCache is brand new, now is the time to call the implementation's specific setup method to create the rendering resources
  6930. if (setupModelRenderCache) {
  6931. this.setupModelRenderCache(this._modelRenderCache);
  6932. }
  6933. // 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.
  6934. // 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.
  6935. if (this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagVisibilityChanged | BABYLON.SmartPropertyPrim.flagNeedRefresh) || context.forceRefreshPrimitive || newInstance || (this._instanceDirtyFlags !== 0) || (this._globalTransformProcessStep !== this._globalTransformStep) || this._mustUpdateInstance()) {
  6936. this._updateInstanceDataParts(gii);
  6937. }
  6938. };
  6939. RenderablePrim2D.prototype._createModelRenderCache = function () {
  6940. var _this = this;
  6941. var setupModelRenderCache = false;
  6942. if (this._modelRenderCache) {
  6943. this._modelRenderCache.dispose();
  6944. }
  6945. this._modelRenderCache = this.owner._engineData.GetOrAddModelCache(this.modelKey, function (key) {
  6946. var mrc = _this.createModelRenderCache(key);
  6947. setupModelRenderCache = true;
  6948. return mrc;
  6949. });
  6950. this._clearFlags(BABYLON.SmartPropertyPrim.flagModelDirty);
  6951. // if this is still false it means the MRC already exists, so we add a reference to it
  6952. if (!setupModelRenderCache) {
  6953. this._modelRenderCache.addRef();
  6954. }
  6955. return setupModelRenderCache;
  6956. };
  6957. RenderablePrim2D.prototype._createModelDataParts = function () {
  6958. var _this = this;
  6959. // Create the instance data parts of the primitive and store them
  6960. var parts = this.createInstanceDataParts();
  6961. this._instanceDataParts = parts;
  6962. // Check if the ModelRenderCache for this particular instance is also brand new, initialize it if it's the case
  6963. if (!this._modelRenderCache._partData) {
  6964. this._setupModelRenderCache(parts);
  6965. }
  6966. // The Rendering resources (Effect, VB, IB, Textures) are stored in the ModelRenderCache
  6967. // But it's the RenderGroup that will store all the Instanced related data to render all the primitive it owns.
  6968. // So for a given ModelKey we getOrAdd a GroupInstanceInfo that will store all these data
  6969. var gii = this.renderGroup._renderableData._renderGroupInstancesInfo.getOrAddWithFactory(this.modelKey, function (k) {
  6970. var res = new BABYLON.GroupInstanceInfo(_this.renderGroup, _this._modelRenderCache, _this._modelRenderCache._partData.length);
  6971. for (var j = 0; j < _this._modelRenderCache._partData.length; j++) {
  6972. var part = _this._instanceDataParts[j];
  6973. res.partIndexFromId.add(part.id.toString(), j);
  6974. res.usedShaderCategories[j] = ";" + _this.getUsedShaderCategories(part).join(";") + ";";
  6975. res.strides[j] = _this._modelRenderCache._partData[j]._partDataStride;
  6976. }
  6977. return res;
  6978. });
  6979. // Get the GroupInfoDataPart corresponding to the render category of the part
  6980. var rm = 0;
  6981. var gipd = null;
  6982. if (this.isTransparent) {
  6983. gipd = gii.transparentData;
  6984. rm = BABYLON.Render2DContext.RenderModeTransparent;
  6985. }
  6986. else if (this.isAlphaTest) {
  6987. gipd = gii.alphaTestData;
  6988. rm = BABYLON.Render2DContext.RenderModeAlphaTest;
  6989. }
  6990. else {
  6991. gipd = gii.opaqueData;
  6992. rm = BABYLON.Render2DContext.RenderModeOpaque;
  6993. }
  6994. // For each instance data part of the primitive, allocate the instanced element it needs for render
  6995. for (var i = 0; i < parts.length; i++) {
  6996. var part = parts[i];
  6997. part.dataBuffer = gipd[i]._partData;
  6998. part.allocElements();
  6999. part.renderMode = rm;
  7000. part.groupInstanceInfo = gii;
  7001. }
  7002. return gii;
  7003. };
  7004. RenderablePrim2D.prototype._setupModelRenderCache = function (parts) {
  7005. var ctiArray = new Array();
  7006. this._modelRenderCache._partData = new Array();
  7007. for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
  7008. var dataPart = parts_1[_i];
  7009. var pd = new BABYLON.ModelRenderCachePartData();
  7010. this._modelRenderCache._partData.push(pd);
  7011. var cat = this.getUsedShaderCategories(dataPart);
  7012. var cti = dataPart.getClassTreeInfo();
  7013. // Make sure the instance is visible other the properties won't be set and their size/offset wont be computed
  7014. var curVisible = this.isVisible;
  7015. this.isVisible = true;
  7016. // 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.
  7017. //console.log("Build Prop Layout for " + Tools.getClassName(this._instanceDataParts[0]));
  7018. var joinCat = ";" + cat.join(";") + ";";
  7019. pd._partJoinedUsedCategories = joinCat;
  7020. InstanceClassInfo._CurCategories = joinCat;
  7021. var obj = this.beforeRefreshForLayoutConstruction(dataPart);
  7022. if (!this.refreshInstanceDataPart(dataPart)) {
  7023. console.log("Layout construction for " + BABYLON.Tools.getClassName(this._instanceDataParts[0]) + " failed because refresh returned false");
  7024. }
  7025. this.afterRefreshForLayoutConstruction(dataPart, obj);
  7026. this.isVisible = curVisible;
  7027. var size = 0;
  7028. cti.fullContent.forEach(function (k, v) {
  7029. if (!v.category || cat.indexOf(v.category) !== -1) {
  7030. if (v.attributeName === "zBias") {
  7031. pd._zBiasOffset = v.instanceOffset.get(joinCat);
  7032. }
  7033. if (!v.size) {
  7034. console.log("ERROR: Couldn't detect the size of the Property " + v.attributeName + " from type " + BABYLON.Tools.getClassName(cti.type) + ". Property is ignored.");
  7035. }
  7036. else {
  7037. size += v.size;
  7038. }
  7039. }
  7040. });
  7041. pd._partDataStride = size;
  7042. pd._partUsedCategories = cat;
  7043. pd._partId = dataPart.id;
  7044. ctiArray.push(cti);
  7045. }
  7046. this._modelRenderCache._partsClassInfo = ctiArray;
  7047. };
  7048. RenderablePrim2D.prototype.onZOrderChanged = function () {
  7049. if (this.isTransparent && this._transparentPrimitiveInfo) {
  7050. this.renderGroup._renderableData.transparentPrimitiveZChanged(this._transparentPrimitiveInfo);
  7051. var gii = this.renderGroup._renderableData._renderGroupInstancesInfo.get(this.modelKey);
  7052. // Flag the transparentData dirty has will have to sort it again
  7053. gii.transparentOrderDirty = true;
  7054. }
  7055. };
  7056. RenderablePrim2D.prototype._mustUpdateInstance = function () {
  7057. return false;
  7058. };
  7059. RenderablePrim2D.prototype._useTextureAlpha = function () {
  7060. return false;
  7061. };
  7062. RenderablePrim2D.prototype._shouldUseAlphaFromTexture = function () {
  7063. return false;
  7064. };
  7065. RenderablePrim2D.prototype._isPrimAlphaTest = function () {
  7066. return false;
  7067. };
  7068. RenderablePrim2D.prototype._isPrimTransparent = function () {
  7069. return false;
  7070. };
  7071. RenderablePrim2D.prototype._updateInstanceDataParts = function (gii) {
  7072. // Fetch the GroupInstanceInfo if we don't already have it
  7073. var rd = this.renderGroup._renderableData;
  7074. if (!gii) {
  7075. gii = rd._renderGroupInstancesInfo.get(this.modelKey);
  7076. }
  7077. var isTransparent = this.isTransparent;
  7078. var isAlphaTest = this.isAlphaTest;
  7079. var wereTransparent = false;
  7080. // Check a render mode change
  7081. var rmChanged = false;
  7082. if (this._instanceDataParts.length > 0) {
  7083. var firstPart = this._instanceDataParts[0];
  7084. var partRM = firstPart.renderMode;
  7085. var curRM = this.renderMode;
  7086. if (partRM !== curRM) {
  7087. wereTransparent = partRM === BABYLON.Render2DContext.RenderModeTransparent;
  7088. rmChanged = true;
  7089. var gipd = void 0;
  7090. switch (curRM) {
  7091. case BABYLON.Render2DContext.RenderModeTransparent:
  7092. gipd = gii.transparentData;
  7093. break;
  7094. case BABYLON.Render2DContext.RenderModeAlphaTest:
  7095. gipd = gii.alphaTestData;
  7096. break;
  7097. default:
  7098. gipd = gii.opaqueData;
  7099. }
  7100. for (var i = 0; i < this._instanceDataParts.length; i++) {
  7101. var part = this._instanceDataParts[i];
  7102. part.freeElements();
  7103. part.dataBuffer = gipd[i]._partData;
  7104. part.renderMode = curRM;
  7105. }
  7106. }
  7107. }
  7108. // Handle changes related to ZOffset
  7109. var visChanged = this._isFlagSet(BABYLON.SmartPropertyPrim.flagVisibilityChanged);
  7110. if (isTransparent || wereTransparent) {
  7111. // Handle visibility change, which is also triggered when the primitive just got created
  7112. if (visChanged || rmChanged) {
  7113. if (this.isVisible && !wereTransparent) {
  7114. if (!this._transparentPrimitiveInfo) {
  7115. // Add the primitive to the list of transparent ones in the group that render is
  7116. this._transparentPrimitiveInfo = rd.addNewTransparentPrimitiveInfo(this, gii);
  7117. }
  7118. }
  7119. else {
  7120. if (this._transparentPrimitiveInfo) {
  7121. rd.removeTransparentPrimitiveInfo(this._transparentPrimitiveInfo);
  7122. this._transparentPrimitiveInfo = null;
  7123. }
  7124. }
  7125. gii.transparentOrderDirty = true;
  7126. }
  7127. }
  7128. var rebuildTrans = false;
  7129. // For each Instance Data part, refresh it to update the data in the DynamicFloatArray
  7130. for (var _i = 0, _a = this._instanceDataParts; _i < _a.length; _i++) {
  7131. var part = _a[_i];
  7132. var justAllocated = false;
  7133. // Check if we need to allocate data elements (hidden prim which becomes visible again)
  7134. if (!part.dataElements && (visChanged || rmChanged || this.isVisible)) {
  7135. part.allocElements();
  7136. justAllocated = true;
  7137. }
  7138. InstanceClassInfo._CurCategories = gii.usedShaderCategories[gii.partIndexFromId.get(part.id.toString())];
  7139. // Will return false if the instance should not be rendered (not visible or other any reasons)
  7140. part.arrayLengthChanged = false;
  7141. if (!this.refreshInstanceDataPart(part)) {
  7142. // Free the data element
  7143. if (part.dataElements) {
  7144. part.freeElements();
  7145. }
  7146. // The refresh couldn't succeed, push the primitive to be dirty again for the next render
  7147. if (this.isVisible) {
  7148. rd._primNewDirtyList.push(this);
  7149. }
  7150. }
  7151. rebuildTrans = rebuildTrans || part.arrayLengthChanged || justAllocated;
  7152. }
  7153. this._instanceDirtyFlags = 0;
  7154. // Make the appropriate data dirty
  7155. if (isTransparent) {
  7156. gii.transparentDirty = true;
  7157. if (rebuildTrans) {
  7158. rd._transparentListChanged = true;
  7159. }
  7160. }
  7161. else if (isAlphaTest) {
  7162. gii.alphaTestDirty = true;
  7163. }
  7164. else {
  7165. gii.opaqueDirty = true;
  7166. }
  7167. this._clearFlags(BABYLON.SmartPropertyPrim.flagVisibilityChanged); // Reset the flag as we've handled the case
  7168. };
  7169. RenderablePrim2D.prototype._updateTransparentSegmentIndices = function (ts) {
  7170. var minOff = BABYLON.Prim2DBase._bigInt;
  7171. var maxOff = 0;
  7172. for (var _i = 0, _a = this._instanceDataParts; _i < _a.length; _i++) {
  7173. var part = _a[_i];
  7174. if (part && part.dataElements) {
  7175. part.dataBuffer.pack();
  7176. for (var _b = 0, _c = part.dataElements; _b < _c.length; _b++) {
  7177. var el = _c[_b];
  7178. minOff = Math.min(minOff, el.offset);
  7179. maxOff = Math.max(maxOff, el.offset);
  7180. }
  7181. ts.startDataIndex = Math.min(ts.startDataIndex, minOff / part.dataBuffer.stride);
  7182. ts.endDataIndex = Math.max(ts.endDataIndex, (maxOff / part.dataBuffer.stride) + 1); // +1 for exclusive
  7183. }
  7184. }
  7185. };
  7186. // This internal method is mainly used for transparency processing
  7187. RenderablePrim2D.prototype._getNextPrimZOrder = function () {
  7188. var length = this._instanceDataParts.length;
  7189. for (var i = 0; i < length; i++) {
  7190. var part = this._instanceDataParts[i];
  7191. if (part) {
  7192. var stride = part.dataBuffer.stride;
  7193. var lastElementOffset = part.dataElements[part.dataElements.length - 1].offset;
  7194. // check if it's the last in the DFA
  7195. if (part.dataBuffer.totalElementCount * stride <= lastElementOffset) {
  7196. return null;
  7197. }
  7198. // Return the Z of the next primitive that lies in the DFA
  7199. return part.dataBuffer[lastElementOffset + stride + this.modelRenderCache._partData[i]._zBiasOffset];
  7200. }
  7201. }
  7202. return null;
  7203. };
  7204. // This internal method is mainly used for transparency processing
  7205. RenderablePrim2D.prototype._getPrevPrimZOrder = function () {
  7206. var length = this._instanceDataParts.length;
  7207. for (var i = 0; i < length; i++) {
  7208. var part = this._instanceDataParts[i];
  7209. if (part) {
  7210. var stride = part.dataBuffer.stride;
  7211. var firstElementOffset = part.dataElements[0].offset;
  7212. // check if it's the first in the DFA
  7213. if (firstElementOffset === 0) {
  7214. return null;
  7215. }
  7216. // Return the Z of the previous primitive that lies in the DFA
  7217. return part.dataBuffer[firstElementOffset - stride + this.modelRenderCache._partData[i]._zBiasOffset];
  7218. }
  7219. }
  7220. return null;
  7221. };
  7222. /**
  7223. * Transform a given point using the Primitive's origin setting.
  7224. * This method requires the Primitive's actualSize to be accurate
  7225. * @param p the point to transform
  7226. * @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.
  7227. * @param res an allocated Vector2 that will receive the transformed content
  7228. */
  7229. RenderablePrim2D.prototype.transformPointWithOriginByRef = function (p, originOffset, res) {
  7230. var actualSize = this.actualSize;
  7231. res.x = p.x - ((this.origin.x + (originOffset ? originOffset.x : 0)) * actualSize.width);
  7232. res.y = p.y - ((this.origin.y + (originOffset ? originOffset.y : 0)) * actualSize.height);
  7233. };
  7234. RenderablePrim2D.prototype.transformPointWithOriginToRef = function (p, originOffset, res) {
  7235. this.transformPointWithOriginByRef(p, originOffset, res);
  7236. return res;
  7237. };
  7238. /**
  7239. * Get the info for a given effect based on the dataPart metadata
  7240. * @param dataPartId partId in part list to get the info
  7241. * @param vertexBufferAttributes vertex buffer attributes to manually add
  7242. * @param uniforms uniforms to manually add
  7243. * @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
  7244. */
  7245. RenderablePrim2D.prototype.getDataPartEffectInfo = function (dataPartId, vertexBufferAttributes, uniforms, useInstanced) {
  7246. if (uniforms === void 0) { uniforms = null; }
  7247. if (useInstanced === void 0) { useInstanced = null; }
  7248. var dataPart = BABYLON.Tools.first(this._instanceDataParts, function (i) { return i.id === dataPartId; });
  7249. if (!dataPart) {
  7250. return null;
  7251. }
  7252. var instancedArray = this.owner.supportInstancedArray;
  7253. if (useInstanced != null) {
  7254. // Check if the caller ask for Instanced Array and the engine does not support it, return null if it's the case
  7255. if (useInstanced && instancedArray === false) {
  7256. return null;
  7257. }
  7258. // Use the caller's setting
  7259. instancedArray = useInstanced;
  7260. }
  7261. var cti = dataPart.getClassTreeInfo();
  7262. var categories = this.getUsedShaderCategories(dataPart);
  7263. var att = cti.classContent.getShaderAttributes(categories);
  7264. var defines = "";
  7265. categories.forEach(function (c) { defines += "#define " + c + "\n"; });
  7266. if (instancedArray) {
  7267. defines += "#define Instanced\n";
  7268. }
  7269. return {
  7270. attributes: instancedArray ? vertexBufferAttributes.concat(att) : vertexBufferAttributes,
  7271. uniforms: instancedArray ? (uniforms != null ? uniforms : []) : ((uniforms != null) ? att.concat(uniforms) : (att != null ? att : [])),
  7272. defines: defines
  7273. };
  7274. };
  7275. Object.defineProperty(RenderablePrim2D.prototype, "modelRenderCache", {
  7276. get: function () {
  7277. return this._modelRenderCache;
  7278. },
  7279. enumerable: true,
  7280. configurable: true
  7281. });
  7282. RenderablePrim2D.prototype.createModelRenderCache = function (modelKey) {
  7283. return null;
  7284. };
  7285. RenderablePrim2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  7286. };
  7287. RenderablePrim2D.prototype.createInstanceDataParts = function () {
  7288. return null;
  7289. };
  7290. RenderablePrim2D.prototype.getUsedShaderCategories = function (dataPart) {
  7291. return [];
  7292. };
  7293. RenderablePrim2D.prototype.beforeRefreshForLayoutConstruction = function (part) {
  7294. };
  7295. RenderablePrim2D.prototype.afterRefreshForLayoutConstruction = function (part, obj) {
  7296. };
  7297. RenderablePrim2D.prototype.applyActualScaleOnTransform = function () {
  7298. return true;
  7299. };
  7300. RenderablePrim2D.prototype.refreshInstanceDataPart = function (part) {
  7301. if (!this.isVisible) {
  7302. return false;
  7303. }
  7304. part.isVisible = this.isVisible;
  7305. // 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)
  7306. if (part.dataElementCount === 1) {
  7307. part.curElement = 0;
  7308. this.updateInstanceDataPart(part);
  7309. }
  7310. return true;
  7311. };
  7312. /**
  7313. * Update the instanceDataBase level properties of a part
  7314. * @param part the part to update
  7315. * @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).
  7316. */
  7317. RenderablePrim2D.prototype.updateInstanceDataPart = function (part, positionOffset) {
  7318. if (positionOffset === void 0) { positionOffset = null; }
  7319. var t = this._globalTransform.multiply(this.renderGroup.invGlobalTransform); // Compute the transformation into the renderGroup's space
  7320. 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.
  7321. if (!this.applyActualScaleOnTransform() || rgScale.x !== 1 || rgScale.y !== 1) {
  7322. t.decompose(RenderablePrim2D_1._s, RenderablePrim2D_1._r, RenderablePrim2D_1._t);
  7323. t = BABYLON.Matrix.Compose((!this.applyActualScaleOnTransform() ? RenderablePrim2D_1._uV3.divide(new BABYLON.Vector3(rgScale.x, rgScale.y, 1)) : RenderablePrim2D_1._s), RenderablePrim2D_1._r, RenderablePrim2D_1._t);
  7324. }
  7325. //let rgScale = (this._areSomeFlagsSet(SmartPropertyPrim.flagDontInheritParentScale) || !this.applyActualScaleOnTransform()) ? RenderablePrim2D._uV : this.renderGroup.actualScale; // We still need to apply the scale of the renderGroup to our rendering, so get it.
  7326. var size = this.renderGroup.viewportSize;
  7327. var zBias = this.actualZOffset;
  7328. var offX = 0;
  7329. var offY = 0;
  7330. // If there's an offset, apply the global transformation matrix on it to get a global offset
  7331. if (positionOffset) {
  7332. offX = positionOffset.x * t.m[0] + positionOffset.y * t.m[4];
  7333. offY = positionOffset.x * t.m[1] + positionOffset.y * t.m[5];
  7334. }
  7335. // 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
  7336. // Current coordinates are expressed in renderGroup coordinates ([0, renderGroup.actualSize.width|height]) with 0,0 being at the left/top corner
  7337. // So for X:
  7338. // - tx.x = value * 2 / width: is to switch from [0, renderGroup.width] to [0, 2]
  7339. // - 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].
  7340. // At last we don't forget to apply the actualScale of the Render Group to tx[0] and ty[1] to propagate scaling correctly
  7341. var w = size.width;
  7342. var h = size.height;
  7343. var invZBias = 1 / zBias;
  7344. var tx = new BABYLON.Vector4(t.m[0] * 2 / w, t.m[4] * 2 / w, 0 /*t.m[8]*/, ((t.m[12] + offX) * 2 / w) - 1);
  7345. var ty = new BABYLON.Vector4(t.m[1] * 2 / h, t.m[5] * 2 / h, 0 /*t.m[9]*/, ((t.m[13] + offY) * 2 / h) - 1);
  7346. part.transformX = tx;
  7347. part.transformY = ty;
  7348. part.opacity = this.actualOpacity;
  7349. // 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)
  7350. part.zBias = new BABYLON.Vector2(zBias, invZBias);
  7351. };
  7352. RenderablePrim2D.prototype._updateRenderMode = function () {
  7353. if (this.isTransparent) {
  7354. this._renderMode = BABYLON.Render2DContext.RenderModeTransparent;
  7355. }
  7356. else if (this.isAlphaTest) {
  7357. this._renderMode = BABYLON.Render2DContext.RenderModeAlphaTest;
  7358. }
  7359. else {
  7360. this._renderMode = BABYLON.Render2DContext.RenderModeOpaque;
  7361. }
  7362. };
  7363. return RenderablePrim2D;
  7364. }(BABYLON.Prim2DBase));
  7365. RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT = BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 5;
  7366. RenderablePrim2D._uV = new BABYLON.Vector2(1, 1);
  7367. RenderablePrim2D._s = BABYLON.Vector3.Zero();
  7368. RenderablePrim2D._r = BABYLON.Quaternion.Identity();
  7369. RenderablePrim2D._t = BABYLON.Vector3.Zero();
  7370. RenderablePrim2D._uV3 = new BABYLON.Vector3(1, 1, 1);
  7371. __decorate([
  7372. BABYLON.dynamicLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 0, function (pi) { return RenderablePrim2D_1.isAlphaTestProperty = pi; })
  7373. ], RenderablePrim2D.prototype, "isAlphaTest", null);
  7374. __decorate([
  7375. BABYLON.dynamicLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 1, function (pi) { return RenderablePrim2D_1.isTransparentProperty = pi; })
  7376. ], RenderablePrim2D.prototype, "isTransparent", null);
  7377. RenderablePrim2D = RenderablePrim2D_1 = __decorate([
  7378. BABYLON.className("RenderablePrim2D", "BABYLON")
  7379. ], RenderablePrim2D);
  7380. BABYLON.RenderablePrim2D = RenderablePrim2D;
  7381. var RenderablePrim2D_1;
  7382. })(BABYLON || (BABYLON = {}));
  7383. //# sourceMappingURL=babylon.renderablePrim2d.js.map
  7384. var __extends = (this && this.__extends) || function (d, b) {
  7385. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  7386. function __() { this.constructor = d; }
  7387. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7388. };
  7389. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  7390. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  7391. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  7392. 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;
  7393. return c > 3 && r && Object.defineProperty(target, key, r), r;
  7394. };
  7395. var BABYLON;
  7396. (function (BABYLON) {
  7397. var Shape2D = Shape2D_1 = (function (_super) {
  7398. __extends(Shape2D, _super);
  7399. function Shape2D(settings) {
  7400. var _this = _super.call(this, settings) || this;
  7401. if (!settings) {
  7402. settings = {};
  7403. }
  7404. var borderBrush = null;
  7405. if (settings.border) {
  7406. if (typeof (settings.border) === "string") {
  7407. borderBrush = BABYLON.Canvas2D.GetBrushFromString(settings.border);
  7408. }
  7409. else {
  7410. borderBrush = settings.border;
  7411. }
  7412. }
  7413. var fillBrush = null;
  7414. if (settings.fill) {
  7415. if (typeof (settings.fill) === "string") {
  7416. fillBrush = BABYLON.Canvas2D.GetBrushFromString(settings.fill);
  7417. }
  7418. else {
  7419. fillBrush = settings.fill;
  7420. }
  7421. }
  7422. _this._isTransparent = false;
  7423. _this._oldTransparent = false;
  7424. _this.border = borderBrush;
  7425. _this.fill = fillBrush;
  7426. _this._updateTransparencyStatus();
  7427. _this.borderThickness = settings.borderThickness;
  7428. return _this;
  7429. }
  7430. Object.defineProperty(Shape2D.prototype, "border", {
  7431. get: function () {
  7432. return this._border;
  7433. },
  7434. set: function (value) {
  7435. this._border = value;
  7436. this._updateTransparencyStatus();
  7437. },
  7438. enumerable: true,
  7439. configurable: true
  7440. });
  7441. Object.defineProperty(Shape2D.prototype, "fill", {
  7442. /**
  7443. * Get/set the brush to render the Fill part of the Primitive
  7444. */
  7445. get: function () {
  7446. return this._fill;
  7447. },
  7448. set: function (value) {
  7449. this._fill = value;
  7450. this._updateTransparencyStatus();
  7451. },
  7452. enumerable: true,
  7453. configurable: true
  7454. });
  7455. Object.defineProperty(Shape2D.prototype, "borderThickness", {
  7456. get: function () {
  7457. return this._borderThickness;
  7458. },
  7459. set: function (value) {
  7460. this._borderThickness = value;
  7461. },
  7462. enumerable: true,
  7463. configurable: true
  7464. });
  7465. Shape2D.prototype.getUsedShaderCategories = function (dataPart) {
  7466. var cat = _super.prototype.getUsedShaderCategories.call(this, dataPart);
  7467. // Fill Part
  7468. if (dataPart.id === Shape2D_1.SHAPE2D_FILLPARTID) {
  7469. var fill = this.fill;
  7470. if (fill instanceof BABYLON.SolidColorBrush2D) {
  7471. cat.push(Shape2D_1.SHAPE2D_CATEGORY_FILLSOLID);
  7472. }
  7473. if (fill instanceof BABYLON.GradientColorBrush2D) {
  7474. cat.push(Shape2D_1.SHAPE2D_CATEGORY_FILLGRADIENT);
  7475. }
  7476. }
  7477. // Border Part
  7478. if (dataPart.id === Shape2D_1.SHAPE2D_BORDERPARTID) {
  7479. cat.push(Shape2D_1.SHAPE2D_CATEGORY_BORDER);
  7480. var border = this.border;
  7481. if (border instanceof BABYLON.SolidColorBrush2D) {
  7482. cat.push(Shape2D_1.SHAPE2D_CATEGORY_BORDERSOLID);
  7483. }
  7484. if (border instanceof BABYLON.GradientColorBrush2D) {
  7485. cat.push(Shape2D_1.SHAPE2D_CATEGORY_BORDERGRADIENT);
  7486. }
  7487. }
  7488. return cat;
  7489. };
  7490. Shape2D.prototype.applyActualScaleOnTransform = function () {
  7491. return false;
  7492. };
  7493. Shape2D.prototype.refreshInstanceDataPart = function (part) {
  7494. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  7495. return false;
  7496. }
  7497. // Fill Part
  7498. if (part.id === Shape2D_1.SHAPE2D_FILLPARTID) {
  7499. var d = part;
  7500. if (this.fill) {
  7501. var fill = this.fill;
  7502. if (fill instanceof BABYLON.SolidColorBrush2D) {
  7503. d.fillSolidColor = fill.color;
  7504. }
  7505. else if (fill instanceof BABYLON.GradientColorBrush2D) {
  7506. d.fillGradientColor1 = fill.color1;
  7507. d.fillGradientColor2 = fill.color2;
  7508. 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));
  7509. var ty = new BABYLON.Vector4(t.m[1], t.m[5], t.m[9], t.m[13]);
  7510. d.fillGradientTY = ty;
  7511. }
  7512. }
  7513. }
  7514. else if (part.id === Shape2D_1.SHAPE2D_BORDERPARTID) {
  7515. var d = part;
  7516. if (this.border) {
  7517. d.borderThickness = this.borderThickness;
  7518. var border = this.border;
  7519. if (border instanceof BABYLON.SolidColorBrush2D) {
  7520. d.borderSolidColor = border.color;
  7521. }
  7522. else if (border instanceof BABYLON.GradientColorBrush2D) {
  7523. d.borderGradientColor1 = border.color1;
  7524. d.borderGradientColor2 = border.color2;
  7525. 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));
  7526. var ty = new BABYLON.Vector4(t.m[1], t.m[5], t.m[9], t.m[13]);
  7527. d.borderGradientTY = ty;
  7528. }
  7529. }
  7530. }
  7531. return true;
  7532. };
  7533. Shape2D.prototype._updateTransparencyStatus = function () {
  7534. this._isTransparent = (this._border && this._border.isTransparent()) || (this._fill && this._fill.isTransparent()) || (this.actualOpacity < 1);
  7535. if (this._isTransparent !== this._oldTransparent) {
  7536. this._oldTransparent = this._isTransparent;
  7537. this._updateRenderMode();
  7538. }
  7539. };
  7540. Shape2D.prototype._mustUpdateInstance = function () {
  7541. var res = this._oldTransparent !== this._isTransparent;
  7542. if (res) {
  7543. this._updateRenderMode();
  7544. this._oldTransparent = this._isTransparent;
  7545. }
  7546. return res;
  7547. };
  7548. Shape2D.prototype._isPrimTransparent = function () {
  7549. return this._isTransparent;
  7550. };
  7551. return Shape2D;
  7552. }(BABYLON.RenderablePrim2D));
  7553. Shape2D.SHAPE2D_BORDERPARTID = 1;
  7554. Shape2D.SHAPE2D_FILLPARTID = 2;
  7555. Shape2D.SHAPE2D_CATEGORY_BORDER = "Border";
  7556. Shape2D.SHAPE2D_CATEGORY_BORDERSOLID = "BorderSolid";
  7557. Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT = "BorderGradient";
  7558. Shape2D.SHAPE2D_CATEGORY_FILLSOLID = "FillSolid";
  7559. Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT = "FillGradient";
  7560. Shape2D.SHAPE2D_PROPCOUNT = BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 5;
  7561. __decorate([
  7562. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 1, function (pi) { return Shape2D_1.borderProperty = pi; }, true)
  7563. ], Shape2D.prototype, "border", null);
  7564. __decorate([
  7565. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 2, function (pi) { return Shape2D_1.fillProperty = pi; }, true)
  7566. ], Shape2D.prototype, "fill", null);
  7567. __decorate([
  7568. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 3, function (pi) { return Shape2D_1.borderThicknessProperty = pi; })
  7569. ], Shape2D.prototype, "borderThickness", null);
  7570. Shape2D = Shape2D_1 = __decorate([
  7571. BABYLON.className("Shape2D", "BABYLON")
  7572. ], Shape2D);
  7573. BABYLON.Shape2D = Shape2D;
  7574. var Shape2DInstanceData = (function (_super) {
  7575. __extends(Shape2DInstanceData, _super);
  7576. function Shape2DInstanceData() {
  7577. return _super.apply(this, arguments) || this;
  7578. }
  7579. Object.defineProperty(Shape2DInstanceData.prototype, "fillSolidColor", {
  7580. // FILL ATTRIBUTES
  7581. get: function () {
  7582. return null;
  7583. },
  7584. set: function (value) {
  7585. },
  7586. enumerable: true,
  7587. configurable: true
  7588. });
  7589. Object.defineProperty(Shape2DInstanceData.prototype, "fillGradientColor1", {
  7590. get: function () {
  7591. return null;
  7592. },
  7593. set: function (value) {
  7594. },
  7595. enumerable: true,
  7596. configurable: true
  7597. });
  7598. Object.defineProperty(Shape2DInstanceData.prototype, "fillGradientColor2", {
  7599. get: function () {
  7600. return null;
  7601. },
  7602. set: function (value) {
  7603. },
  7604. enumerable: true,
  7605. configurable: true
  7606. });
  7607. Object.defineProperty(Shape2DInstanceData.prototype, "fillGradientTY", {
  7608. get: function () {
  7609. return null;
  7610. },
  7611. set: function (value) {
  7612. },
  7613. enumerable: true,
  7614. configurable: true
  7615. });
  7616. Object.defineProperty(Shape2DInstanceData.prototype, "borderThickness", {
  7617. // BORDER ATTRIBUTES
  7618. get: function () {
  7619. return null;
  7620. },
  7621. set: function (value) {
  7622. },
  7623. enumerable: true,
  7624. configurable: true
  7625. });
  7626. Object.defineProperty(Shape2DInstanceData.prototype, "borderSolidColor", {
  7627. get: function () {
  7628. return null;
  7629. },
  7630. set: function (value) {
  7631. },
  7632. enumerable: true,
  7633. configurable: true
  7634. });
  7635. Object.defineProperty(Shape2DInstanceData.prototype, "borderGradientColor1", {
  7636. get: function () {
  7637. return null;
  7638. },
  7639. set: function (value) {
  7640. },
  7641. enumerable: true,
  7642. configurable: true
  7643. });
  7644. Object.defineProperty(Shape2DInstanceData.prototype, "borderGradientColor2", {
  7645. get: function () {
  7646. return null;
  7647. },
  7648. set: function (value) {
  7649. },
  7650. enumerable: true,
  7651. configurable: true
  7652. });
  7653. Object.defineProperty(Shape2DInstanceData.prototype, "borderGradientTY", {
  7654. get: function () {
  7655. return null;
  7656. },
  7657. set: function (value) {
  7658. },
  7659. enumerable: true,
  7660. configurable: true
  7661. });
  7662. return Shape2DInstanceData;
  7663. }(BABYLON.InstanceDataBase));
  7664. __decorate([
  7665. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLSOLID)
  7666. ], Shape2DInstanceData.prototype, "fillSolidColor", null);
  7667. __decorate([
  7668. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  7669. ], Shape2DInstanceData.prototype, "fillGradientColor1", null);
  7670. __decorate([
  7671. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  7672. ], Shape2DInstanceData.prototype, "fillGradientColor2", null);
  7673. __decorate([
  7674. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  7675. ], Shape2DInstanceData.prototype, "fillGradientTY", null);
  7676. __decorate([
  7677. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDER)
  7678. ], Shape2DInstanceData.prototype, "borderThickness", null);
  7679. __decorate([
  7680. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERSOLID)
  7681. ], Shape2DInstanceData.prototype, "borderSolidColor", null);
  7682. __decorate([
  7683. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT)
  7684. ], Shape2DInstanceData.prototype, "borderGradientColor1", null);
  7685. __decorate([
  7686. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT)
  7687. ], Shape2DInstanceData.prototype, "borderGradientColor2", null);
  7688. __decorate([
  7689. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT)
  7690. ], Shape2DInstanceData.prototype, "borderGradientTY", null);
  7691. BABYLON.Shape2DInstanceData = Shape2DInstanceData;
  7692. var Shape2D_1;
  7693. })(BABYLON || (BABYLON = {}));
  7694. //# sourceMappingURL=babylon.shape2d.js.map
  7695. var __extends = (this && this.__extends) || function (d, b) {
  7696. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  7697. function __() { this.constructor = d; }
  7698. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7699. };
  7700. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  7701. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  7702. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  7703. 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;
  7704. return c > 3 && r && Object.defineProperty(target, key, r), r;
  7705. };
  7706. var BABYLON;
  7707. (function (BABYLON) {
  7708. var Group2D = Group2D_1 = (function (_super) {
  7709. __extends(Group2D, _super);
  7710. /**
  7711. * Create an Logical or Renderable Group.
  7712. * @param settings a combination of settings, possible ones are
  7713. * - 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)
  7714. * - children: an array of direct children
  7715. * - id a text identifier, for information purpose
  7716. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  7717. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  7718. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  7719. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  7720. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  7721. * - zOrder: override the zOrder with the specified value
  7722. * - origin: define the normalized origin point location, default [0.5;0.5]
  7723. * - 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.
  7724. * - cacheBehavior: Define how the group should behave regarding the Canvas's cache strategy, default is Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY
  7725. * - 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).
  7726. * - isVisible: true if the group must be visible, false for hidden. Default is true.
  7727. * - 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.
  7728. * - 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.
  7729. * - 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!
  7730. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7731. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7732. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7733. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7734. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  7735. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  7736. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  7737. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  7738. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7739. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7740. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7741. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7742. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  7743. */
  7744. function Group2D(settings) {
  7745. var _this;
  7746. if (settings == null) {
  7747. settings = {};
  7748. }
  7749. if (settings.origin == null) {
  7750. settings.origin = new BABYLON.Vector2(0, 0);
  7751. }
  7752. _this = _super.call(this, settings) || this;
  7753. var size = (!settings.size && !settings.width && !settings.height) ? null : (settings.size || (new BABYLON.Size(settings.width || 0, settings.height || 0)));
  7754. _this._trackedNode = (settings.trackNode == null) ? null : settings.trackNode;
  7755. if (_this._trackedNode && _this.owner) {
  7756. _this.owner._registerTrackedNode(_this);
  7757. }
  7758. _this._cacheBehavior = (settings.cacheBehavior == null) ? Group2D_1.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY : settings.cacheBehavior;
  7759. var rd = _this._renderableData;
  7760. if (rd) {
  7761. rd._noResizeOnScale = (_this.cacheBehavior & Group2D_1.GROUPCACHEBEHAVIOR_NORESIZEONSCALE) !== 0;
  7762. }
  7763. _this.size = size;
  7764. _this._viewportPosition = BABYLON.Vector2.Zero();
  7765. _this._viewportSize = BABYLON.Size.Zero();
  7766. return _this;
  7767. }
  7768. Group2D._createCachedCanvasGroup = function (owner) {
  7769. 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 });
  7770. return g;
  7771. };
  7772. Group2D.prototype.applyCachedTexture = function (vertexData, material) {
  7773. this._bindCacheTarget();
  7774. if (vertexData) {
  7775. var uv = vertexData.uvs;
  7776. var nodeuv = this._renderableData._cacheNodeUVs;
  7777. for (var i = 0; i < 4; i++) {
  7778. uv[i * 2 + 0] = nodeuv[i].x;
  7779. uv[i * 2 + 1] = nodeuv[i].y;
  7780. }
  7781. }
  7782. if (material) {
  7783. material.diffuseTexture = this._renderableData._cacheTexture;
  7784. material.emissiveColor = new BABYLON.Color3(1, 1, 1);
  7785. }
  7786. this._renderableData._cacheTexture.hasAlpha = true;
  7787. this._unbindCacheTarget();
  7788. };
  7789. Object.defineProperty(Group2D.prototype, "cachedRect", {
  7790. /**
  7791. * Allow you to access the information regarding the cached rectangle of the Group2D into the MapTexture.
  7792. * 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.
  7793. */
  7794. get: function () {
  7795. if (!this._renderableData) {
  7796. return null;
  7797. }
  7798. return this._renderableData._cacheNode;
  7799. },
  7800. enumerable: true,
  7801. configurable: true
  7802. });
  7803. Object.defineProperty(Group2D.prototype, "cachedUVs", {
  7804. /**
  7805. * The UVs into the MapTexture that map the cached group
  7806. */
  7807. get: function () {
  7808. if (!this._renderableData) {
  7809. return null;
  7810. }
  7811. return this._renderableData._cacheNodeUVs;
  7812. },
  7813. enumerable: true,
  7814. configurable: true
  7815. });
  7816. Object.defineProperty(Group2D.prototype, "cachedUVsChanged", {
  7817. get: function () {
  7818. if (!this._renderableData) {
  7819. return null;
  7820. }
  7821. if (!this._renderableData._cacheNodeUVsChangedObservable) {
  7822. this._renderableData._cacheNodeUVsChangedObservable = new BABYLON.Observable();
  7823. }
  7824. return this._renderableData._cacheNodeUVsChangedObservable;
  7825. },
  7826. enumerable: true,
  7827. configurable: true
  7828. });
  7829. Object.defineProperty(Group2D.prototype, "cacheTexture", {
  7830. /**
  7831. * Access the texture that maintains a cached version of the Group2D.
  7832. * This is useful only if you're not using a WorldSpaceNode for your WorldSpace Canvas and therefore need to perform the rendering yourself.
  7833. */
  7834. get: function () {
  7835. if (!this._renderableData) {
  7836. return null;
  7837. }
  7838. return this._renderableData._cacheTexture;
  7839. },
  7840. enumerable: true,
  7841. configurable: true
  7842. });
  7843. /**
  7844. * Call this method to remove this Group and its children from the Canvas
  7845. */
  7846. Group2D.prototype.dispose = function () {
  7847. if (!_super.prototype.dispose.call(this)) {
  7848. return false;
  7849. }
  7850. if (this._trackedNode != null) {
  7851. this.owner._unregisterTrackedNode(this);
  7852. this._trackedNode = null;
  7853. }
  7854. if (this._renderableData) {
  7855. this._renderableData.dispose(this.owner);
  7856. this._renderableData = null;
  7857. }
  7858. return true;
  7859. };
  7860. Object.defineProperty(Group2D.prototype, "isRenderableGroup", {
  7861. /**
  7862. * @returns Returns true if the Group render content, false if it's a logical group only
  7863. */
  7864. get: function () {
  7865. return this._isRenderableGroup;
  7866. },
  7867. enumerable: true,
  7868. configurable: true
  7869. });
  7870. Object.defineProperty(Group2D.prototype, "isCachedGroup", {
  7871. /**
  7872. * @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
  7873. */
  7874. get: function () {
  7875. return this._isCachedGroup;
  7876. },
  7877. enumerable: true,
  7878. configurable: true
  7879. });
  7880. Object.defineProperty(Group2D.prototype, "size", {
  7881. get: function () {
  7882. return this._size;
  7883. },
  7884. /**
  7885. * Get/Set the size of the group. If null the size of the group will be determine from its content.
  7886. * 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.
  7887. */
  7888. set: function (val) {
  7889. this._size = val;
  7890. },
  7891. enumerable: true,
  7892. configurable: true
  7893. });
  7894. Object.defineProperty(Group2D.prototype, "viewportSize", {
  7895. get: function () {
  7896. return this._viewportSize;
  7897. },
  7898. enumerable: true,
  7899. configurable: true
  7900. });
  7901. Object.defineProperty(Group2D.prototype, "actualSize", {
  7902. get: function () {
  7903. // The computed size will be floor on both width and height
  7904. var actualSize;
  7905. // Return the actualSize if set
  7906. if (this._actualSize) {
  7907. return this._actualSize;
  7908. }
  7909. // Return the size if set by the user
  7910. if (this._size) {
  7911. actualSize = new BABYLON.Size(Math.ceil(this._size.width), Math.ceil(this._size.height));
  7912. }
  7913. else {
  7914. var m = this.layoutBoundingInfo.max();
  7915. actualSize = new BABYLON.Size(Math.ceil(m.x), Math.ceil(m.y));
  7916. }
  7917. // 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)
  7918. if (!actualSize.equals(this._actualSize)) {
  7919. this.onPrimitivePropertyDirty(Group2D_1.actualSizeProperty.flagId);
  7920. this._actualSize = actualSize;
  7921. this.handleGroupChanged(Group2D_1.actualSizeProperty);
  7922. }
  7923. return actualSize;
  7924. },
  7925. set: function (value) {
  7926. this._actualSize = value;
  7927. },
  7928. enumerable: true,
  7929. configurable: true
  7930. });
  7931. Object.defineProperty(Group2D.prototype, "cacheBehavior", {
  7932. /**
  7933. * 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.
  7934. * GROUPCACHEBEHAVIOR_NORESIZEONSCALE can also be set if you set it at creation time.
  7935. * 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.
  7936. */
  7937. get: function () {
  7938. return this._cacheBehavior;
  7939. },
  7940. enumerable: true,
  7941. configurable: true
  7942. });
  7943. Group2D.prototype._addPrimToDirtyList = function (prim) {
  7944. this._renderableData._primDirtyList.push(prim);
  7945. };
  7946. Group2D.prototype._renderCachedCanvas = function () {
  7947. this.owner._addGroupRenderCount(1);
  7948. this.updateCachedStates(true);
  7949. var context = new BABYLON.PrepareRender2DContext();
  7950. this._prepareGroupRender(context);
  7951. this._groupRender();
  7952. };
  7953. Object.defineProperty(Group2D.prototype, "trackedNode", {
  7954. /**
  7955. * Get/set the Scene's Node that should be tracked, the group's position will follow the projected position of the Node.
  7956. */
  7957. get: function () {
  7958. return this._trackedNode;
  7959. },
  7960. set: function (val) {
  7961. if (val != null) {
  7962. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  7963. this.owner._registerTrackedNode(this);
  7964. }
  7965. this._trackedNode = val;
  7966. }
  7967. else {
  7968. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  7969. this.owner._unregisterTrackedNode(this);
  7970. }
  7971. this._trackedNode = null;
  7972. }
  7973. },
  7974. enumerable: true,
  7975. configurable: true
  7976. });
  7977. Group2D.prototype.levelIntersect = function (intersectInfo) {
  7978. // 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
  7979. return true;
  7980. };
  7981. Group2D.prototype.updateLevelBoundingInfo = function () {
  7982. var size;
  7983. // If the size is set by the user, the boundingInfo is computed from this value
  7984. if (this.size) {
  7985. size = this.size;
  7986. }
  7987. else {
  7988. size = new BABYLON.Size(0, 0);
  7989. }
  7990. BABYLON.BoundingInfo2D.CreateFromSizeToRef(size, this._levelBoundingInfo);
  7991. };
  7992. // Method called only on renderable groups to prepare the rendering
  7993. Group2D.prototype._prepareGroupRender = function (context) {
  7994. var sortedDirtyList = null;
  7995. // Update the Global Transformation and visibility status of the changed primitives
  7996. var rd = this._renderableData;
  7997. if ((rd._primDirtyList.length > 0) || context.forceRefreshPrimitive) {
  7998. sortedDirtyList = rd._primDirtyList.sort(function (a, b) { return a.hierarchyDepth - b.hierarchyDepth; });
  7999. this.updateCachedStatesOf(sortedDirtyList, true);
  8000. }
  8001. var s = this.actualSize;
  8002. var a = this.actualScale;
  8003. var sw = Math.ceil(s.width * a.x);
  8004. var sh = Math.ceil(s.height * a.y);
  8005. // 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.
  8006. // So we set the width/height to the rendering's one because that's what we want for the viewport!
  8007. if ((this instanceof BABYLON.Canvas2D || this.id === "__cachedCanvasGroup__") && this.owner.designSize != null) {
  8008. sw = this.owner.engine.getRenderWidth();
  8009. sh = this.owner.engine.getRenderHeight();
  8010. }
  8011. // Setup the size of the rendering viewport
  8012. // 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
  8013. if (!this._isCachedGroup) {
  8014. // Compute the WebGL viewport's location/size
  8015. var t = this._globalTransform.getTranslation();
  8016. var rs = this.owner._renderingSize;
  8017. sh = Math.min(sh, rs.height - t.y);
  8018. sw = Math.min(sw, rs.width - t.x);
  8019. var x = t.x;
  8020. var y = t.y;
  8021. // 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
  8022. this._viewportPosition.x = x;
  8023. this._viewportPosition.y = y;
  8024. }
  8025. // 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.
  8026. if (this._viewportSize.width !== sw || this._viewportSize.height !== sh) {
  8027. context.forceRefreshPrimitive = true;
  8028. this._viewportSize.width = sw;
  8029. this._viewportSize.height = sh;
  8030. }
  8031. if ((rd._primDirtyList.length > 0) || context.forceRefreshPrimitive) {
  8032. // If the group is cached, set the dirty flag to true because of the incoming changes
  8033. this._cacheGroupDirty = this._isCachedGroup;
  8034. rd._primNewDirtyList.splice(0);
  8035. // If it's a force refresh, prepare all the children
  8036. if (context.forceRefreshPrimitive) {
  8037. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  8038. var p = _a[_i];
  8039. p._prepareRender(context);
  8040. }
  8041. }
  8042. else {
  8043. // Each primitive that changed at least once was added into the primDirtyList, we have to sort this level using
  8044. // the hierarchyDepth in order to prepare primitives from top to bottom
  8045. if (!sortedDirtyList) {
  8046. sortedDirtyList = rd._primDirtyList.sort(function (a, b) { return a.hierarchyDepth - b.hierarchyDepth; });
  8047. }
  8048. sortedDirtyList.forEach(function (p) {
  8049. // 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.
  8050. // 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.
  8051. if (!p.isDisposed && p._needPrepare()) {
  8052. p._prepareRender(context);
  8053. }
  8054. });
  8055. }
  8056. // Everything is updated, clear the dirty list
  8057. rd._primDirtyList.forEach(function (p) {
  8058. if (rd._primNewDirtyList.indexOf(p) === -1) {
  8059. p._resetPropertiesDirty();
  8060. }
  8061. else {
  8062. p._setFlags(BABYLON.SmartPropertyPrim.flagNeedRefresh);
  8063. }
  8064. });
  8065. rd._primDirtyList.splice(0);
  8066. rd._primDirtyList = rd._primDirtyList.concat(rd._primNewDirtyList);
  8067. }
  8068. // A renderable group has a list of direct children that are also renderable groups, we recurse on them to also prepare them
  8069. rd._childrenRenderableGroups.forEach(function (g) {
  8070. g._prepareGroupRender(context);
  8071. });
  8072. };
  8073. Group2D.prototype._groupRender = function () {
  8074. var _this = this;
  8075. var engine = this.owner.engine;
  8076. var failedCount = 0;
  8077. // First recurse to children render group to render them (in their cache or on screen)
  8078. for (var _i = 0, _a = this._renderableData._childrenRenderableGroups; _i < _a.length; _i++) {
  8079. var childGroup = _a[_i];
  8080. childGroup._groupRender();
  8081. }
  8082. // Render the primitives if needed: either if we don't cache the content or if the content is cached but has changed
  8083. if (!this.isCachedGroup || this._cacheGroupDirty) {
  8084. this.owner._addGroupRenderCount(1);
  8085. if (this.isCachedGroup) {
  8086. this._bindCacheTarget();
  8087. }
  8088. else {
  8089. var curVP = engine.setDirectViewport(this._viewportPosition.x, this._viewportPosition.y, this._viewportSize.width, this._viewportSize.height);
  8090. }
  8091. var curAlphaTest = engine.getAlphaTesting() === true;
  8092. var curDepthWrite = engine.getDepthWrite() === true;
  8093. // ===================================================================
  8094. // First pass, update the InstancedArray and render Opaque primitives
  8095. // Disable Alpha Testing, Enable Depth Write
  8096. engine.setAlphaTesting(false);
  8097. engine.setDepthWrite(true);
  8098. // For each different model of primitive to render
  8099. var context_1 = new BABYLON.Render2DContext(BABYLON.Render2DContext.RenderModeOpaque);
  8100. this._renderableData._renderGroupInstancesInfo.forEach(function (k, v) {
  8101. // Prepare the context object, update the WebGL Instanced Array buffer if needed
  8102. var renderCount = _this._prepareContext(engine, context_1, v);
  8103. // If null is returned, there's no opaque data to render
  8104. if (renderCount === null) {
  8105. return;
  8106. }
  8107. // Submit render only if we have something to render (everything may be hidden and the floatarray empty)
  8108. if (!_this.owner.supportInstancedArray || renderCount > 0) {
  8109. // render all the instances of this model, if the render method returns true then our instances are no longer dirty
  8110. var renderFailed = !v.modelRenderCache.render(v, context_1);
  8111. // Update dirty flag/related
  8112. v.opaqueDirty = renderFailed;
  8113. failedCount += renderFailed ? 1 : 0;
  8114. }
  8115. });
  8116. // =======================================================================
  8117. // Second pass, update the InstancedArray and render AlphaTest primitives
  8118. // Enable Alpha Testing, Enable Depth Write
  8119. engine.setAlphaTesting(true);
  8120. engine.setDepthWrite(true);
  8121. // For each different model of primitive to render
  8122. context_1 = new BABYLON.Render2DContext(BABYLON.Render2DContext.RenderModeAlphaTest);
  8123. this._renderableData._renderGroupInstancesInfo.forEach(function (k, v) {
  8124. // Prepare the context object, update the WebGL Instanced Array buffer if needed
  8125. var renderCount = _this._prepareContext(engine, context_1, v);
  8126. // If null is returned, there's no opaque data to render
  8127. if (renderCount === null) {
  8128. return;
  8129. }
  8130. // Submit render only if we have something to render (everything may be hidden and the floatarray empty)
  8131. if (!_this.owner.supportInstancedArray || renderCount > 0) {
  8132. // render all the instances of this model, if the render method returns true then our instances are no longer dirty
  8133. var renderFailed = !v.modelRenderCache.render(v, context_1);
  8134. // Update dirty flag/related
  8135. v.opaqueDirty = renderFailed;
  8136. failedCount += renderFailed ? 1 : 0;
  8137. }
  8138. });
  8139. // =======================================================================
  8140. // Third pass, transparent primitive rendering
  8141. // Enable Alpha Testing, Disable Depth Write
  8142. engine.setAlphaTesting(true);
  8143. engine.setDepthWrite(false);
  8144. // First Check if the transparent List change so we can update the TransparentSegment and PartData (sort if needed)
  8145. if (this._renderableData._transparentListChanged) {
  8146. this._updateTransparentData();
  8147. }
  8148. // From this point on we have up to date data to render, so let's go
  8149. failedCount += this._renderTransparentData();
  8150. // =======================================================================
  8151. // Unbind target/restore viewport setting, clear dirty flag, and quit
  8152. // The group's content is no longer dirty
  8153. this._cacheGroupDirty = failedCount !== 0;
  8154. if (this.isCachedGroup) {
  8155. this._unbindCacheTarget();
  8156. }
  8157. else {
  8158. if (curVP) {
  8159. engine.setViewport(curVP);
  8160. }
  8161. }
  8162. // Restore saved states
  8163. engine.setAlphaTesting(curAlphaTest);
  8164. engine.setDepthWrite(curDepthWrite);
  8165. }
  8166. };
  8167. Group2D.prototype._setCacheGroupDirty = function () {
  8168. this._cacheGroupDirty = true;
  8169. };
  8170. Group2D.prototype._updateTransparentData = function () {
  8171. this.owner._addUpdateTransparentDataCount(1);
  8172. var rd = this._renderableData;
  8173. // Sort all the primitive from their depth, max (bottom) to min (top)
  8174. rd._transparentPrimitives.sort(function (a, b) { return b._primitive.actualZOffset - a._primitive.actualZOffset; });
  8175. var checkAndAddPrimInSegment = function (seg, tpiI) {
  8176. var tpi = rd._transparentPrimitives[tpiI];
  8177. // Fast rejection: if gii are different
  8178. if (seg.groupInsanceInfo !== tpi._groupInstanceInfo) {
  8179. return false;
  8180. }
  8181. //let tpiZ = tpi._primitive.actualZOffset;
  8182. // We've made it so far, the tpi can be part of the segment, add it
  8183. tpi._transparentSegment = seg;
  8184. tpi._primitive._updateTransparentSegmentIndices(seg);
  8185. return true;
  8186. };
  8187. // Free the existing TransparentSegments
  8188. for (var _i = 0, _a = rd._transparentSegments; _i < _a.length; _i++) {
  8189. var ts = _a[_i];
  8190. ts.dispose(this.owner.engine);
  8191. }
  8192. rd._transparentSegments.splice(0);
  8193. var prevSeg = null;
  8194. for (var tpiI = 0; tpiI < rd._transparentPrimitives.length; tpiI++) {
  8195. var tpi = rd._transparentPrimitives[tpiI];
  8196. // Check if the Data in which the primitive is stored is not sorted properly
  8197. if (tpi._groupInstanceInfo.transparentOrderDirty) {
  8198. tpi._groupInstanceInfo.sortTransparentData();
  8199. }
  8200. // Reset the segment, we have to create/rebuild it
  8201. tpi._transparentSegment = null;
  8202. // If there's a previous valid segment, check if this prim can be part of it
  8203. if (prevSeg) {
  8204. checkAndAddPrimInSegment(prevSeg, tpiI);
  8205. }
  8206. // If we couldn't insert in the adjacent segments, he have to create one
  8207. if (!tpi._transparentSegment) {
  8208. var ts = new BABYLON.TransparentSegment();
  8209. ts.groupInsanceInfo = tpi._groupInstanceInfo;
  8210. var prim = tpi._primitive;
  8211. ts.startZ = prim.actualZOffset;
  8212. prim._updateTransparentSegmentIndices(ts);
  8213. ts.endZ = ts.startZ;
  8214. tpi._transparentSegment = ts;
  8215. rd._transparentSegments.push(ts);
  8216. }
  8217. // Update prevSeg
  8218. prevSeg = tpi._transparentSegment;
  8219. }
  8220. //rd._firstChangedPrim = null;
  8221. rd._transparentListChanged = false;
  8222. };
  8223. Group2D.prototype._renderTransparentData = function () {
  8224. var failedCount = 0;
  8225. var context = new BABYLON.Render2DContext(BABYLON.Render2DContext.RenderModeTransparent);
  8226. var rd = this._renderableData;
  8227. var useInstanced = this.owner.supportInstancedArray;
  8228. var length = rd._transparentSegments.length;
  8229. for (var i = 0; i < length; i++) {
  8230. context.instancedBuffers = null;
  8231. var ts = rd._transparentSegments[i];
  8232. var gii = ts.groupInsanceInfo;
  8233. var mrc = gii.modelRenderCache;
  8234. var engine = this.owner.engine;
  8235. var count = ts.endDataIndex - ts.startDataIndex;
  8236. // Use Instanced Array if it's supported and if there's at least minPartCountToUseInstancedArray prims to draw.
  8237. // We don't want to create an Instanced Buffer for less that minPartCountToUseInstancedArray prims
  8238. if (useInstanced && count >= this.owner.minPartCountToUseInstancedArray) {
  8239. if (!ts.partBuffers) {
  8240. var buffers = new Array();
  8241. for (var j = 0; j < gii.transparentData.length; j++) {
  8242. var gitd = gii.transparentData[j];
  8243. var dfa = gitd._partData;
  8244. var data = dfa.pack();
  8245. var stride = dfa.stride;
  8246. var neededSize = count * stride * 4;
  8247. var buffer = engine.createInstancesBuffer(neededSize); // Create + bind
  8248. var segData = data.subarray(ts.startDataIndex * stride, ts.endDataIndex * stride);
  8249. engine.updateArrayBuffer(segData);
  8250. buffers.push(buffer);
  8251. }
  8252. ts.partBuffers = buffers;
  8253. }
  8254. else if (gii.transparentDirty) {
  8255. for (var j = 0; j < gii.transparentData.length; j++) {
  8256. var gitd = gii.transparentData[j];
  8257. var dfa = gitd._partData;
  8258. var data = dfa.pack();
  8259. var stride = dfa.stride;
  8260. var buffer = ts.partBuffers[j];
  8261. var segData = data.subarray(ts.startDataIndex * stride, ts.endDataIndex * stride);
  8262. engine.bindArrayBuffer(buffer);
  8263. engine.updateArrayBuffer(segData);
  8264. }
  8265. }
  8266. context.useInstancing = true;
  8267. context.instancesCount = count;
  8268. context.instancedBuffers = ts.partBuffers;
  8269. context.groupInfoPartData = gii.transparentData;
  8270. var renderFailed = !mrc.render(gii, context);
  8271. failedCount += renderFailed ? 1 : 0;
  8272. }
  8273. else {
  8274. context.useInstancing = false;
  8275. context.partDataStartIndex = ts.startDataIndex;
  8276. context.partDataEndIndex = ts.endDataIndex;
  8277. context.groupInfoPartData = gii.transparentData;
  8278. var renderFailed = !mrc.render(gii, context);
  8279. failedCount += renderFailed ? 1 : 0;
  8280. }
  8281. }
  8282. return failedCount;
  8283. };
  8284. Group2D.prototype._prepareContext = function (engine, context, gii) {
  8285. var gipd = null;
  8286. var setDirty;
  8287. var getDirty;
  8288. // Render Mode specifics
  8289. switch (context.renderMode) {
  8290. case BABYLON.Render2DContext.RenderModeOpaque:
  8291. {
  8292. if (!gii.hasOpaqueData) {
  8293. return null;
  8294. }
  8295. setDirty = function (dirty) { gii.opaqueDirty = dirty; };
  8296. getDirty = function () { return gii.opaqueDirty; };
  8297. context.groupInfoPartData = gii.opaqueData;
  8298. gipd = gii.opaqueData;
  8299. break;
  8300. }
  8301. case BABYLON.Render2DContext.RenderModeAlphaTest:
  8302. {
  8303. if (!gii.hasAlphaTestData) {
  8304. return null;
  8305. }
  8306. setDirty = function (dirty) { gii.alphaTestDirty = dirty; };
  8307. getDirty = function () { return gii.alphaTestDirty; };
  8308. context.groupInfoPartData = gii.alphaTestData;
  8309. gipd = gii.alphaTestData;
  8310. break;
  8311. }
  8312. default:
  8313. throw new Error("_prepareContext is only for opaque or alphaTest");
  8314. }
  8315. var renderCount = 0;
  8316. // This part will pack the dynamicfloatarray and update the instanced array WebGLBufffer
  8317. // Skip it if instanced arrays are not supported
  8318. if (this.owner.supportInstancedArray) {
  8319. // Flag for instancing
  8320. context.useInstancing = true;
  8321. // Make sure all the WebGLBuffers of the Instanced Array are created/up to date for the parts to render.
  8322. for (var i = 0; i < gipd.length; i++) {
  8323. var pid = gipd[i];
  8324. // If the instances of the model was changed, pack the data
  8325. var array = pid._partData;
  8326. var instanceData_1 = array.pack();
  8327. renderCount += array.usedElementCount;
  8328. // Compute the size the instance buffer should have
  8329. var neededSize = array.usedElementCount * array.stride * 4;
  8330. // Check if we have to (re)create the instancesBuffer because there's none or the size is too small
  8331. if (!pid._partBuffer || (pid._partBufferSize < neededSize)) {
  8332. if (pid._partBuffer) {
  8333. engine.deleteInstancesBuffer(pid._partBuffer);
  8334. }
  8335. pid._partBuffer = engine.createInstancesBuffer(neededSize); // Create + bind
  8336. pid._partBufferSize = neededSize;
  8337. setDirty(false);
  8338. // Update the WebGL buffer to match the new content of the instances data
  8339. engine.updateArrayBuffer(instanceData_1);
  8340. }
  8341. else if (getDirty()) {
  8342. // Update the WebGL buffer to match the new content of the instances data
  8343. engine.bindArrayBuffer(pid._partBuffer);
  8344. engine.updateArrayBuffer(instanceData_1);
  8345. }
  8346. }
  8347. setDirty(false);
  8348. }
  8349. else {
  8350. context.partDataStartIndex = 0;
  8351. // Find the first valid object to get the count
  8352. if (context.groupInfoPartData.length > 0) {
  8353. var i = 0;
  8354. while (!context.groupInfoPartData[i]) {
  8355. i++;
  8356. }
  8357. context.partDataEndIndex = context.groupInfoPartData[i]._partData.usedElementCount;
  8358. }
  8359. }
  8360. return renderCount;
  8361. };
  8362. Group2D.prototype._setRenderingScale = function (scale) {
  8363. if (this._renderableData._renderingScale === scale) {
  8364. return;
  8365. }
  8366. this._renderableData._renderingScale = scale;
  8367. };
  8368. Group2D.prototype._bindCacheTarget = function () {
  8369. var curWidth;
  8370. var curHeight;
  8371. var rd = this._renderableData;
  8372. var rs = rd._renderingScale;
  8373. var noResizeScale = rd._noResizeOnScale;
  8374. var isCanvas = this.parent == null;
  8375. var scale;
  8376. if (noResizeScale) {
  8377. scale = isCanvas ? Group2D_1._uV : this.parent.actualScale;
  8378. }
  8379. else {
  8380. scale = this.actualScale;
  8381. }
  8382. if (isCanvas && this.owner.cachingStrategy === BABYLON.Canvas2D.CACHESTRATEGY_CANVAS && this.owner.isScreenSpace) {
  8383. if (this.owner.designSize || this.owner.fitRenderingDevice) {
  8384. Group2D_1._s.width = this.owner.engine.getRenderWidth();
  8385. Group2D_1._s.height = this.owner.engine.getRenderHeight();
  8386. }
  8387. else {
  8388. Group2D_1._s.copyFrom(this.owner.size);
  8389. }
  8390. }
  8391. else {
  8392. Group2D_1._s.width = Math.ceil(this.actualSize.width * scale.x * rs);
  8393. Group2D_1._s.height = Math.ceil(this.actualSize.height * scale.y * rs);
  8394. }
  8395. var sizeChanged = !Group2D_1._s.equals(rd._cacheSize);
  8396. if (rd._cacheNode) {
  8397. var size = rd._cacheNode.contentSize;
  8398. // Check if we have to deallocate because the size is too small
  8399. if ((size.width < Group2D_1._s.width) || (size.height < Group2D_1._s.height)) {
  8400. // For Screen space: over-provisioning of 7% more to avoid frequent resizing for few pixels...
  8401. // For World space: no over-provisioning
  8402. var overprovisioning = this.owner.isScreenSpace ? 1.07 : 1;
  8403. curWidth = Math.floor(Group2D_1._s.width * overprovisioning);
  8404. curHeight = Math.floor(Group2D_1._s.height * overprovisioning);
  8405. //console.log(`[${this._globalTransformProcessStep}] Resize group ${this.id}, width: ${curWidth}, height: ${curHeight}`);
  8406. rd._cacheTexture.freeRect(rd._cacheNode);
  8407. rd._cacheNode = null;
  8408. }
  8409. }
  8410. if (!rd._cacheNode) {
  8411. // Check if we have to allocate a rendering zone in the global cache texture
  8412. var res = this.owner._allocateGroupCache(this, this.parent && this.parent.renderGroup, curWidth ? new BABYLON.Size(curWidth, curHeight) : null, rd._useMipMap, rd._anisotropicLevel);
  8413. rd._cacheNode = res.node;
  8414. rd._cacheTexture = res.texture;
  8415. if (rd._cacheRenderSprite) {
  8416. rd._cacheRenderSprite.dispose();
  8417. }
  8418. rd._cacheRenderSprite = res.sprite;
  8419. sizeChanged = true;
  8420. }
  8421. if (sizeChanged) {
  8422. rd._cacheSize.copyFrom(Group2D_1._s);
  8423. rd._cacheNodeUVs = rd._cacheNode.getUVsForCustomSize(rd._cacheSize);
  8424. if (rd._cacheNodeUVsChangedObservable && rd._cacheNodeUVsChangedObservable.hasObservers()) {
  8425. rd._cacheNodeUVsChangedObservable.notifyObservers(rd._cacheNodeUVs);
  8426. }
  8427. this._setFlags(BABYLON.SmartPropertyPrim.flagWorldCacheChanged);
  8428. }
  8429. var n = rd._cacheNode;
  8430. rd._cacheTexture.bindTextureForPosSize(n.pos, Group2D_1._s, true);
  8431. };
  8432. Group2D.prototype._unbindCacheTarget = function () {
  8433. if (this._renderableData._cacheTexture) {
  8434. this._renderableData._cacheTexture.unbindTexture();
  8435. }
  8436. };
  8437. Group2D.prototype._spreadActualScaleDirty = function () {
  8438. if (this._renderableData && this._renderableData._cacheRenderSprite) {
  8439. this.handleGroupChanged(BABYLON.Prim2DBase.actualScaleProperty);
  8440. }
  8441. _super.prototype._spreadActualScaleDirty.call(this);
  8442. };
  8443. Group2D.prototype.handleGroupChanged = function (prop) {
  8444. // This method is only for cachedGroup
  8445. var rd = this._renderableData;
  8446. if (!rd) {
  8447. return;
  8448. }
  8449. var cachedSprite = rd._cacheRenderSprite;
  8450. if (!this.isCachedGroup || !cachedSprite) {
  8451. return;
  8452. }
  8453. // For now we only support these property changes
  8454. // TODO: add more! :)
  8455. switch (prop.id) {
  8456. case BABYLON.Prim2DBase.actualPositionProperty.id:
  8457. cachedSprite.actualPosition = this.actualPosition.clone();
  8458. if (cachedSprite.position != null) {
  8459. cachedSprite.position = cachedSprite.actualPosition.clone();
  8460. }
  8461. break;
  8462. case BABYLON.Prim2DBase.rotationProperty.id:
  8463. cachedSprite.rotation = this.rotation;
  8464. break;
  8465. case BABYLON.Prim2DBase.scaleProperty.id:
  8466. cachedSprite.scale = this.scale;
  8467. break;
  8468. case BABYLON.Prim2DBase.originProperty.id:
  8469. cachedSprite.origin = this.origin.clone();
  8470. break;
  8471. case Group2D_1.actualSizeProperty.id:
  8472. cachedSprite.size = this.actualSize.clone();
  8473. break;
  8474. }
  8475. };
  8476. Group2D.prototype.detectGroupStates = function () {
  8477. var isCanvas = this instanceof BABYLON.Canvas2D;
  8478. var canvasStrat = this.owner.cachingStrategy;
  8479. // In Don't Cache mode, only the canvas is renderable, all the other groups are logical. There are not a single cached group.
  8480. if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_DONTCACHE) {
  8481. this._isRenderableGroup = isCanvas;
  8482. this._isCachedGroup = false;
  8483. }
  8484. else if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_CANVAS) {
  8485. if (isCanvas) {
  8486. this._isRenderableGroup = true;
  8487. this._isCachedGroup = true;
  8488. }
  8489. else {
  8490. this._isRenderableGroup = this.id === "__cachedCanvasGroup__";
  8491. this._isCachedGroup = false;
  8492. }
  8493. }
  8494. else if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_TOPLEVELGROUPS) {
  8495. if (isCanvas) {
  8496. this._isRenderableGroup = true;
  8497. this._isCachedGroup = false;
  8498. }
  8499. else {
  8500. if (this.hierarchyDepth === 1) {
  8501. this._isRenderableGroup = true;
  8502. this._isCachedGroup = true;
  8503. }
  8504. else {
  8505. this._isRenderableGroup = false;
  8506. this._isCachedGroup = false;
  8507. }
  8508. }
  8509. }
  8510. else if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_ALLGROUPS) {
  8511. if (isCanvas) {
  8512. this._isRenderableGroup = true;
  8513. this._isCachedGroup = false;
  8514. }
  8515. else {
  8516. var gcb = this.cacheBehavior & Group2D_1.GROUPCACHEBEHAVIOR_OPTIONMASK;
  8517. if ((gcb === Group2D_1.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE) || (gcb === Group2D_1.GROUPCACHEBEHAVIOR_CACHEINPARENTGROUP)) {
  8518. this._isRenderableGroup = gcb === Group2D_1.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE;
  8519. this._isCachedGroup = false;
  8520. }
  8521. if (gcb === Group2D_1.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY) {
  8522. this._isRenderableGroup = true;
  8523. this._isCachedGroup = true;
  8524. }
  8525. }
  8526. }
  8527. if (this._isRenderableGroup) {
  8528. // Yes, we do need that check, trust me, unfortunately we can call _detectGroupStates many time on the same object...
  8529. if (!this._renderableData) {
  8530. this._renderableData = new RenderableGroupData();
  8531. }
  8532. }
  8533. // If the group is tagged as renderable we add it to the renderable tree
  8534. if (this._isCachedGroup) {
  8535. this._renderableData._noResizeOnScale = (this.cacheBehavior & Group2D_1.GROUPCACHEBEHAVIOR_NORESIZEONSCALE) !== 0;
  8536. var cur = this.parent;
  8537. while (cur) {
  8538. if (cur instanceof Group2D_1 && cur._isRenderableGroup) {
  8539. if (cur._renderableData._childrenRenderableGroups.indexOf(this) === -1) {
  8540. cur._renderableData._childrenRenderableGroups.push(this);
  8541. }
  8542. break;
  8543. }
  8544. cur = cur.parent;
  8545. }
  8546. }
  8547. };
  8548. return Group2D;
  8549. }(BABYLON.Prim2DBase));
  8550. Group2D.GROUP2D_PROPCOUNT = BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 5;
  8551. /**
  8552. * Default behavior, the group will use the caching strategy defined at the Canvas Level
  8553. */
  8554. Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY = 0;
  8555. /**
  8556. * When used, this group's content won't be cached, no matter which strategy used.
  8557. * If the group is part of a WorldSpace Canvas, its content will be drawn in the Canvas cache bitmap.
  8558. */
  8559. Group2D.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE = 1;
  8560. /**
  8561. * When used, the group's content will be cached in the nearest cached parent group/canvas
  8562. */
  8563. Group2D.GROUPCACHEBEHAVIOR_CACHEINPARENTGROUP = 2;
  8564. /**
  8565. * 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
  8566. */
  8567. Group2D.GROUPCACHEBEHAVIOR_NORESIZEONSCALE = 0x100;
  8568. Group2D.GROUPCACHEBEHAVIOR_OPTIONMASK = 0xFF;
  8569. Group2D._uV = new BABYLON.Vector2(1, 1);
  8570. Group2D._s = BABYLON.Size.Zero();
  8571. Group2D._unS = new BABYLON.Vector2(1, 1);
  8572. __decorate([
  8573. BABYLON.instanceLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 1, function (pi) { return Group2D_1.sizeProperty = pi; }, false, true)
  8574. ], Group2D.prototype, "size", null);
  8575. __decorate([
  8576. BABYLON.instanceLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 2, function (pi) { return Group2D_1.actualSizeProperty = pi; })
  8577. ], Group2D.prototype, "actualSize", null);
  8578. Group2D = Group2D_1 = __decorate([
  8579. BABYLON.className("Group2D", "BABYLON")
  8580. ], Group2D);
  8581. BABYLON.Group2D = Group2D;
  8582. var RenderableGroupData = (function () {
  8583. function RenderableGroupData() {
  8584. this._primDirtyList = new Array();
  8585. this._primNewDirtyList = new Array();
  8586. this._childrenRenderableGroups = new Array();
  8587. this._renderGroupInstancesInfo = new BABYLON.StringDictionary();
  8588. this._transparentPrimitives = new Array();
  8589. this._transparentSegments = new Array();
  8590. this._transparentListChanged = false;
  8591. this._cacheNode = null;
  8592. this._cacheTexture = null;
  8593. this._cacheRenderSprite = null;
  8594. this._renderingScale = 1;
  8595. this._cacheNodeUVs = null;
  8596. this._cacheNodeUVsChangedObservable = null;
  8597. this._cacheSize = BABYLON.Size.Zero();
  8598. this._useMipMap = false;
  8599. this._anisotropicLevel = 1;
  8600. this._noResizeOnScale = false;
  8601. }
  8602. RenderableGroupData.prototype.dispose = function (owner) {
  8603. var engine = owner.engine;
  8604. if (this._cacheRenderSprite) {
  8605. this._cacheRenderSprite.dispose();
  8606. this._cacheRenderSprite = null;
  8607. }
  8608. if (this._cacheTexture && this._cacheNode) {
  8609. this._cacheTexture.freeRect(this._cacheNode);
  8610. this._cacheTexture = null;
  8611. this._cacheNode = null;
  8612. }
  8613. if (this._primDirtyList) {
  8614. this._primDirtyList.splice(0);
  8615. this._primDirtyList = null;
  8616. }
  8617. if (this._renderGroupInstancesInfo) {
  8618. this._renderGroupInstancesInfo.forEach(function (k, v) {
  8619. v.dispose();
  8620. });
  8621. this._renderGroupInstancesInfo = null;
  8622. }
  8623. if (this._cacheNodeUVsChangedObservable) {
  8624. this._cacheNodeUVsChangedObservable.clear();
  8625. this._cacheNodeUVsChangedObservable = null;
  8626. }
  8627. if (this._transparentSegments) {
  8628. for (var _i = 0, _a = this._transparentSegments; _i < _a.length; _i++) {
  8629. var ts = _a[_i];
  8630. ts.dispose(engine);
  8631. }
  8632. this._transparentSegments.splice(0);
  8633. this._transparentSegments = null;
  8634. }
  8635. };
  8636. RenderableGroupData.prototype.addNewTransparentPrimitiveInfo = function (prim, gii) {
  8637. var tpi = new TransparentPrimitiveInfo();
  8638. tpi._primitive = prim;
  8639. tpi._groupInstanceInfo = gii;
  8640. tpi._transparentSegment = null;
  8641. this._transparentPrimitives.push(tpi);
  8642. this._transparentListChanged = true;
  8643. return tpi;
  8644. };
  8645. RenderableGroupData.prototype.removeTransparentPrimitiveInfo = function (tpi) {
  8646. var index = this._transparentPrimitives.indexOf(tpi);
  8647. if (index !== -1) {
  8648. this._transparentPrimitives.splice(index, 1);
  8649. this._transparentListChanged = true;
  8650. }
  8651. };
  8652. RenderableGroupData.prototype.transparentPrimitiveZChanged = function (tpi) {
  8653. this._transparentListChanged = true;
  8654. //this.updateSmallestZChangedPrim(tpi);
  8655. };
  8656. return RenderableGroupData;
  8657. }());
  8658. BABYLON.RenderableGroupData = RenderableGroupData;
  8659. var TransparentPrimitiveInfo = (function () {
  8660. function TransparentPrimitiveInfo() {
  8661. }
  8662. return TransparentPrimitiveInfo;
  8663. }());
  8664. BABYLON.TransparentPrimitiveInfo = TransparentPrimitiveInfo;
  8665. var Group2D_1;
  8666. })(BABYLON || (BABYLON = {}));
  8667. //# sourceMappingURL=babylon.group2d.js.map
  8668. var __extends = (this && this.__extends) || function (d, b) {
  8669. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  8670. function __() { this.constructor = d; }
  8671. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8672. };
  8673. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  8674. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  8675. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  8676. 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;
  8677. return c > 3 && r && Object.defineProperty(target, key, r), r;
  8678. };
  8679. var BABYLON;
  8680. (function (BABYLON) {
  8681. var Rectangle2DRenderCache = (function (_super) {
  8682. __extends(Rectangle2DRenderCache, _super);
  8683. function Rectangle2DRenderCache(engine, modelKey) {
  8684. var _this = _super.call(this, engine, modelKey) || this;
  8685. _this.effectsReady = false;
  8686. _this.fillVB = null;
  8687. _this.fillIB = null;
  8688. _this.fillIndicesCount = 0;
  8689. _this.instancingFillAttributes = null;
  8690. _this.effectFill = null;
  8691. _this.effectFillInstanced = null;
  8692. _this.borderVB = null;
  8693. _this.borderIB = null;
  8694. _this.borderIndicesCount = 0;
  8695. _this.instancingBorderAttributes = null;
  8696. _this.effectBorder = null;
  8697. _this.effectBorderInstanced = null;
  8698. return _this;
  8699. }
  8700. Rectangle2DRenderCache.prototype.render = function (instanceInfo, context) {
  8701. // Do nothing if the shader is still loading/preparing
  8702. if (!this.effectsReady) {
  8703. if ((this.effectFill && (!this.effectFill.isReady() || (this.effectFillInstanced && !this.effectFillInstanced.isReady()))) ||
  8704. (this.effectBorder && (!this.effectBorder.isReady() || (this.effectBorderInstanced && !this.effectBorderInstanced.isReady())))) {
  8705. return false;
  8706. }
  8707. this.effectsReady = true;
  8708. }
  8709. var canvas = instanceInfo.owner.owner;
  8710. var engine = canvas.engine;
  8711. var depthFunction = 0;
  8712. if (this.effectFill && this.effectBorder) {
  8713. depthFunction = engine.getDepthFunction();
  8714. engine.setDepthFunctionToLessOrEqual();
  8715. }
  8716. var curAlphaMode = engine.getAlphaMode();
  8717. if (this.effectFill) {
  8718. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_FILLPARTID.toString());
  8719. var pid = context.groupInfoPartData[partIndex];
  8720. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  8721. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  8722. }
  8723. var effect = context.useInstancing ? this.effectFillInstanced : this.effectFill;
  8724. engine.enableEffect(effect);
  8725. engine.bindBuffersDirectly(this.fillVB, this.fillIB, [1], 4, effect);
  8726. if (context.useInstancing) {
  8727. if (!this.instancingFillAttributes) {
  8728. this.instancingFillAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_FILLPARTID, effect);
  8729. }
  8730. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  8731. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  8732. canvas._addDrawCallCount(1, context.renderMode);
  8733. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingFillAttributes);
  8734. engine.draw(true, 0, this.fillIndicesCount, count);
  8735. engine.unbindInstanceAttributes();
  8736. }
  8737. else {
  8738. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  8739. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  8740. this.setupUniforms(effect, partIndex, pid._partData, i);
  8741. engine.draw(true, 0, this.fillIndicesCount);
  8742. }
  8743. }
  8744. }
  8745. if (this.effectBorder) {
  8746. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_BORDERPARTID.toString());
  8747. var pid = context.groupInfoPartData[partIndex];
  8748. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  8749. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  8750. }
  8751. var effect = context.useInstancing ? this.effectBorderInstanced : this.effectBorder;
  8752. engine.enableEffect(effect);
  8753. engine.bindBuffersDirectly(this.borderVB, this.borderIB, [1], 4, effect);
  8754. if (context.useInstancing) {
  8755. if (!this.instancingBorderAttributes) {
  8756. this.instancingBorderAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, effect);
  8757. }
  8758. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  8759. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  8760. canvas._addDrawCallCount(1, context.renderMode);
  8761. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingBorderAttributes);
  8762. engine.draw(true, 0, this.borderIndicesCount, count);
  8763. engine.unbindInstanceAttributes();
  8764. }
  8765. else {
  8766. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  8767. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  8768. this.setupUniforms(effect, partIndex, pid._partData, i);
  8769. engine.draw(true, 0, this.borderIndicesCount);
  8770. }
  8771. }
  8772. }
  8773. engine.setAlphaMode(curAlphaMode, true);
  8774. if (this.effectFill && this.effectBorder) {
  8775. engine.setDepthFunction(depthFunction);
  8776. }
  8777. return true;
  8778. };
  8779. Rectangle2DRenderCache.prototype.dispose = function () {
  8780. if (!_super.prototype.dispose.call(this)) {
  8781. return false;
  8782. }
  8783. if (this.fillVB) {
  8784. this._engine._releaseBuffer(this.fillVB);
  8785. this.fillVB = null;
  8786. }
  8787. if (this.fillIB) {
  8788. this._engine._releaseBuffer(this.fillIB);
  8789. this.fillIB = null;
  8790. }
  8791. this.effectFill = null;
  8792. this.effectFillInstanced = null;
  8793. this.effectBorder = null;
  8794. this.effectBorderInstanced = null;
  8795. if (this.borderVB) {
  8796. this._engine._releaseBuffer(this.borderVB);
  8797. this.borderVB = null;
  8798. }
  8799. if (this.borderIB) {
  8800. this._engine._releaseBuffer(this.borderIB);
  8801. this.borderIB = null;
  8802. }
  8803. return true;
  8804. };
  8805. return Rectangle2DRenderCache;
  8806. }(BABYLON.ModelRenderCache));
  8807. BABYLON.Rectangle2DRenderCache = Rectangle2DRenderCache;
  8808. var Rectangle2DInstanceData = (function (_super) {
  8809. __extends(Rectangle2DInstanceData, _super);
  8810. function Rectangle2DInstanceData(partId) {
  8811. return _super.call(this, partId, 1) || this;
  8812. }
  8813. Object.defineProperty(Rectangle2DInstanceData.prototype, "properties", {
  8814. get: function () {
  8815. return null;
  8816. },
  8817. set: function (value) {
  8818. },
  8819. enumerable: true,
  8820. configurable: true
  8821. });
  8822. return Rectangle2DInstanceData;
  8823. }(BABYLON.Shape2DInstanceData));
  8824. __decorate([
  8825. BABYLON.instanceData()
  8826. ], Rectangle2DInstanceData.prototype, "properties", null);
  8827. BABYLON.Rectangle2DInstanceData = Rectangle2DInstanceData;
  8828. var Rectangle2D = Rectangle2D_1 = (function (_super) {
  8829. __extends(Rectangle2D, _super);
  8830. /**
  8831. * Create an Rectangle 2D Shape primitive. May be a sharp rectangle (with sharp corners), or a rounded one.
  8832. * @param settings a combination of settings, possible ones are
  8833. * - 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)
  8834. * - children: an array of direct children
  8835. * - id a text identifier, for information purpose
  8836. * - position: the X & Y positions relative to its parent. Alternatively the x and y settings can be set. Default is [0;0]
  8837. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  8838. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  8839. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  8840. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  8841. * - zOrder: override the zOrder with the specified value
  8842. * - origin: define the normalized origin point location, default [0.5;0.5]
  8843. * - size: the size of the group. Alternatively the width and height settings can be set. Default will be [10;10].
  8844. * - roundRadius: if the rectangle has rounded corner, set their radius, default is 0 (to get a sharp edges rectangle).
  8845. * - 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)
  8846. * - 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)
  8847. * - borderThickness: the thickness of the drawn border, default is 1.
  8848. * - isVisible: true if the primitive must be visible, false for hidden. Default is true.
  8849. * - 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.
  8850. * - 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.
  8851. * - 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!
  8852. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8853. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8854. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8855. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8856. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  8857. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  8858. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  8859. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  8860. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8861. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8862. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8863. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8864. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  8865. */
  8866. function Rectangle2D(settings) {
  8867. var _this;
  8868. // Avoid checking every time if the object exists
  8869. if (settings == null) {
  8870. settings = {};
  8871. }
  8872. _this = _super.call(this, settings) || this;
  8873. if (settings.size != null) {
  8874. _this.size = settings.size;
  8875. }
  8876. else if (settings.width || settings.height) {
  8877. var size = new BABYLON.Size(settings.width, settings.height);
  8878. _this.size = size;
  8879. }
  8880. //let size = settings.size || (new Size((settings.width === null) ? null : (settings.width || 10), (settings.height === null) ? null : (settings.height || 10)));
  8881. var roundRadius = (settings.roundRadius == null) ? 0 : settings.roundRadius;
  8882. var borderThickness = (settings.borderThickness == null) ? 1 : settings.borderThickness;
  8883. //this.size = size;
  8884. _this.roundRadius = roundRadius;
  8885. _this.borderThickness = borderThickness;
  8886. return _this;
  8887. }
  8888. Object.defineProperty(Rectangle2D.prototype, "actualSize", {
  8889. get: function () {
  8890. if (this._actualSize) {
  8891. return this._actualSize;
  8892. }
  8893. return this.size;
  8894. },
  8895. set: function (value) {
  8896. this._actualSize = value;
  8897. },
  8898. enumerable: true,
  8899. configurable: true
  8900. });
  8901. Object.defineProperty(Rectangle2D.prototype, "notRounded", {
  8902. get: function () {
  8903. return this._notRounded;
  8904. },
  8905. set: function (value) {
  8906. this._notRounded = value;
  8907. },
  8908. enumerable: true,
  8909. configurable: true
  8910. });
  8911. Object.defineProperty(Rectangle2D.prototype, "roundRadius", {
  8912. get: function () {
  8913. return this._roundRadius;
  8914. },
  8915. set: function (value) {
  8916. this._roundRadius = value;
  8917. this.notRounded = value === 0;
  8918. this._positioningDirty();
  8919. },
  8920. enumerable: true,
  8921. configurable: true
  8922. });
  8923. Rectangle2D.prototype.levelIntersect = function (intersectInfo) {
  8924. // If we got there it mean the boundingInfo intersection succeed, if the rectangle has not roundRadius, it means it succeed!
  8925. if (this.notRounded) {
  8926. return true;
  8927. }
  8928. // 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.
  8929. // 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)
  8930. // 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.
  8931. // First let remove the origin out the equation, to have the rectangle with an origin at bottom/left
  8932. var size = this.size;
  8933. Rectangle2D_1._i0.x = intersectInfo._localPickPosition.x;
  8934. Rectangle2D_1._i0.y = intersectInfo._localPickPosition.y;
  8935. var rr = this.roundRadius;
  8936. var rrs = rr * rr;
  8937. // Check if the point is in the bottom/left quarter area
  8938. Rectangle2D_1._i1.x = rr;
  8939. Rectangle2D_1._i1.y = rr;
  8940. if (Rectangle2D_1._i0.x <= Rectangle2D_1._i1.x && Rectangle2D_1._i0.y <= Rectangle2D_1._i1.y) {
  8941. // Compute the intersection point in the quarter local space
  8942. Rectangle2D_1._i2.x = Rectangle2D_1._i0.x - Rectangle2D_1._i1.x;
  8943. Rectangle2D_1._i2.y = Rectangle2D_1._i0.y - Rectangle2D_1._i1.y;
  8944. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  8945. return Rectangle2D_1._i2.lengthSquared() <= rrs;
  8946. }
  8947. // Check if the point is in the top/left quarter area
  8948. Rectangle2D_1._i1.x = rr;
  8949. Rectangle2D_1._i1.y = size.height - rr;
  8950. if (Rectangle2D_1._i0.x <= Rectangle2D_1._i1.x && Rectangle2D_1._i0.y >= Rectangle2D_1._i1.y) {
  8951. // Compute the intersection point in the quarter local space
  8952. Rectangle2D_1._i2.x = Rectangle2D_1._i0.x - Rectangle2D_1._i1.x;
  8953. Rectangle2D_1._i2.y = Rectangle2D_1._i0.y - Rectangle2D_1._i1.y;
  8954. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  8955. return Rectangle2D_1._i2.lengthSquared() <= rrs;
  8956. }
  8957. // Check if the point is in the top/right quarter area
  8958. Rectangle2D_1._i1.x = size.width - rr;
  8959. Rectangle2D_1._i1.y = size.height - rr;
  8960. if (Rectangle2D_1._i0.x >= Rectangle2D_1._i1.x && Rectangle2D_1._i0.y >= Rectangle2D_1._i1.y) {
  8961. // Compute the intersection point in the quarter local space
  8962. Rectangle2D_1._i2.x = Rectangle2D_1._i0.x - Rectangle2D_1._i1.x;
  8963. Rectangle2D_1._i2.y = Rectangle2D_1._i0.y - Rectangle2D_1._i1.y;
  8964. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  8965. return Rectangle2D_1._i2.lengthSquared() <= rrs;
  8966. }
  8967. // Check if the point is in the bottom/right quarter area
  8968. Rectangle2D_1._i1.x = size.width - rr;
  8969. Rectangle2D_1._i1.y = rr;
  8970. if (Rectangle2D_1._i0.x >= Rectangle2D_1._i1.x && Rectangle2D_1._i0.y <= Rectangle2D_1._i1.y) {
  8971. // Compute the intersection point in the quarter local space
  8972. Rectangle2D_1._i2.x = Rectangle2D_1._i0.x - Rectangle2D_1._i1.x;
  8973. Rectangle2D_1._i2.y = Rectangle2D_1._i0.y - Rectangle2D_1._i1.y;
  8974. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  8975. return Rectangle2D_1._i2.lengthSquared() <= rrs;
  8976. }
  8977. // At any other locations the point is guarantied to be inside
  8978. return true;
  8979. };
  8980. Rectangle2D.prototype.updateLevelBoundingInfo = function () {
  8981. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.actualSize, this._levelBoundingInfo);
  8982. };
  8983. Rectangle2D.prototype.createModelRenderCache = function (modelKey) {
  8984. var renderCache = new Rectangle2DRenderCache(this.owner.engine, modelKey);
  8985. return renderCache;
  8986. };
  8987. Rectangle2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  8988. var renderCache = modelRenderCache;
  8989. var engine = this.owner.engine;
  8990. // Need to create WebGL resources for fill part?
  8991. if (this.fill) {
  8992. var vbSize = ((this.notRounded ? 1 : Rectangle2D_1.roundSubdivisions) * 4) + 1;
  8993. var vb = new Float32Array(vbSize);
  8994. for (var i = 0; i < vbSize; i++) {
  8995. vb[i] = i;
  8996. }
  8997. renderCache.fillVB = engine.createVertexBuffer(vb);
  8998. var triCount = vbSize - 1;
  8999. var ib = new Float32Array(triCount * 3);
  9000. for (var i = 0; i < triCount; i++) {
  9001. ib[i * 3 + 0] = 0;
  9002. ib[i * 3 + 2] = i + 1;
  9003. ib[i * 3 + 1] = i + 2;
  9004. }
  9005. ib[triCount * 3 - 2] = 1;
  9006. renderCache.fillIB = engine.createIndexBuffer(ib);
  9007. renderCache.fillIndicesCount = triCount * 3;
  9008. // 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
  9009. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, true);
  9010. if (ei) {
  9011. renderCache.effectFillInstanced = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9012. }
  9013. // Get the non instanced version
  9014. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, false);
  9015. renderCache.effectFill = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9016. }
  9017. // Need to create WebGL resource for border part?
  9018. if (this.border) {
  9019. var vbSize = (this.notRounded ? 1 : Rectangle2D_1.roundSubdivisions) * 4 * 2;
  9020. var vb = new Float32Array(vbSize);
  9021. for (var i = 0; i < vbSize; i++) {
  9022. vb[i] = i;
  9023. }
  9024. renderCache.borderVB = engine.createVertexBuffer(vb);
  9025. var triCount = vbSize;
  9026. var rs = triCount / 2;
  9027. var ib = new Float32Array(triCount * 3);
  9028. for (var i = 0; i < rs; i++) {
  9029. var r0 = i;
  9030. var r1 = (i + 1) % rs;
  9031. ib[i * 6 + 0] = rs + r1;
  9032. ib[i * 6 + 1] = rs + r0;
  9033. ib[i * 6 + 2] = r0;
  9034. ib[i * 6 + 3] = r1;
  9035. ib[i * 6 + 4] = rs + r1;
  9036. ib[i * 6 + 5] = r0;
  9037. }
  9038. renderCache.borderIB = engine.createIndexBuffer(ib);
  9039. renderCache.borderIndicesCount = triCount * 3;
  9040. // 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
  9041. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, true);
  9042. if (ei) {
  9043. renderCache.effectBorderInstanced = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9044. }
  9045. // Get the non instanced version
  9046. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, false);
  9047. renderCache.effectBorder = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9048. }
  9049. return renderCache;
  9050. };
  9051. // 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
  9052. Rectangle2D.prototype._getInitialContentAreaToRef = function (primSize, initialContentPosition, initialContentArea) {
  9053. // Fall back to default implementation if there's no round Radius
  9054. if (this._notRounded) {
  9055. _super.prototype._getInitialContentAreaToRef.call(this, primSize, initialContentPosition, initialContentArea);
  9056. }
  9057. else {
  9058. var rr = Math.round((this.roundRadius - (this.roundRadius / Math.sqrt(2))) * 1.3);
  9059. initialContentPosition.x = initialContentPosition.y = rr;
  9060. initialContentArea.width = Math.max(0, primSize.width - (rr * 2));
  9061. initialContentArea.height = Math.max(0, primSize.height - (rr * 2));
  9062. initialContentPosition.z = primSize.width - (initialContentPosition.x + initialContentArea.width);
  9063. initialContentPosition.w = primSize.height - (initialContentPosition.y + initialContentArea.height);
  9064. }
  9065. };
  9066. Rectangle2D.prototype._getActualSizeFromContentToRef = function (primSize, newPrimSize) {
  9067. // Fall back to default implementation if there's no round Radius
  9068. if (this._notRounded) {
  9069. _super.prototype._getActualSizeFromContentToRef.call(this, primSize, newPrimSize);
  9070. }
  9071. else {
  9072. var rr = Math.round((this.roundRadius - (this.roundRadius / Math.sqrt(2))) * 1.3);
  9073. newPrimSize.copyFrom(primSize);
  9074. newPrimSize.width += rr * 2;
  9075. newPrimSize.height += rr * 2;
  9076. }
  9077. };
  9078. Rectangle2D.prototype.createInstanceDataParts = function () {
  9079. var res = new Array();
  9080. if (this.border) {
  9081. res.push(new Rectangle2DInstanceData(BABYLON.Shape2D.SHAPE2D_BORDERPARTID));
  9082. }
  9083. if (this.fill) {
  9084. res.push(new Rectangle2DInstanceData(BABYLON.Shape2D.SHAPE2D_FILLPARTID));
  9085. }
  9086. return res;
  9087. };
  9088. Rectangle2D.prototype.refreshInstanceDataPart = function (part) {
  9089. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  9090. return false;
  9091. }
  9092. if (part.id === BABYLON.Shape2D.SHAPE2D_BORDERPARTID) {
  9093. var d = part;
  9094. var size = this.actualSize;
  9095. var s = this.actualScale;
  9096. d.properties = new BABYLON.Vector3(size.width * s.x, size.height * s.y, this.roundRadius || 0);
  9097. }
  9098. else if (part.id === BABYLON.Shape2D.SHAPE2D_FILLPARTID) {
  9099. var d = part;
  9100. var size = this.actualSize;
  9101. var s = this.actualScale;
  9102. d.properties = new BABYLON.Vector3(size.width * s.x, size.height * s.y, this.roundRadius || 0);
  9103. }
  9104. return true;
  9105. };
  9106. return Rectangle2D;
  9107. }(BABYLON.Shape2D));
  9108. Rectangle2D._i0 = BABYLON.Vector2.Zero();
  9109. Rectangle2D._i1 = BABYLON.Vector2.Zero();
  9110. Rectangle2D._i2 = BABYLON.Vector2.Zero();
  9111. Rectangle2D.roundSubdivisions = 16;
  9112. __decorate([
  9113. BABYLON.instanceLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 1, function (pi) { return Rectangle2D_1.actualSizeProperty = pi; }, false, true)
  9114. ], Rectangle2D.prototype, "actualSize", null);
  9115. __decorate([
  9116. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 2, function (pi) { return Rectangle2D_1.notRoundedProperty = pi; })
  9117. ], Rectangle2D.prototype, "notRounded", null);
  9118. __decorate([
  9119. BABYLON.instanceLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 3, function (pi) { return Rectangle2D_1.roundRadiusProperty = pi; })
  9120. ], Rectangle2D.prototype, "roundRadius", null);
  9121. Rectangle2D = Rectangle2D_1 = __decorate([
  9122. BABYLON.className("Rectangle2D", "BABYLON")
  9123. ], Rectangle2D);
  9124. BABYLON.Rectangle2D = Rectangle2D;
  9125. var Rectangle2D_1;
  9126. })(BABYLON || (BABYLON = {}));
  9127. //# sourceMappingURL=babylon.rectangle2d.js.map
  9128. var __extends = (this && this.__extends) || function (d, b) {
  9129. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  9130. function __() { this.constructor = d; }
  9131. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9132. };
  9133. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  9134. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  9135. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  9136. 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;
  9137. return c > 3 && r && Object.defineProperty(target, key, r), r;
  9138. };
  9139. var BABYLON;
  9140. (function (BABYLON) {
  9141. var Ellipse2DRenderCache = (function (_super) {
  9142. __extends(Ellipse2DRenderCache, _super);
  9143. function Ellipse2DRenderCache(engine, modelKey) {
  9144. var _this = _super.call(this, engine, modelKey) || this;
  9145. _this.effectsReady = false;
  9146. _this.fillVB = null;
  9147. _this.fillIB = null;
  9148. _this.fillIndicesCount = 0;
  9149. _this.instancingFillAttributes = null;
  9150. _this.effectFillInstanced = null;
  9151. _this.effectFill = null;
  9152. _this.borderVB = null;
  9153. _this.borderIB = null;
  9154. _this.borderIndicesCount = 0;
  9155. _this.instancingBorderAttributes = null;
  9156. _this.effectBorderInstanced = null;
  9157. _this.effectBorder = null;
  9158. return _this;
  9159. }
  9160. Ellipse2DRenderCache.prototype.render = function (instanceInfo, context) {
  9161. // Do nothing if the shader is still loading/preparing
  9162. if (!this.effectsReady) {
  9163. if ((this.effectFill && (!this.effectFill.isReady() || (this.effectFillInstanced && !this.effectFillInstanced.isReady()))) ||
  9164. (this.effectBorder && (!this.effectBorder.isReady() || (this.effectBorderInstanced && !this.effectBorderInstanced.isReady())))) {
  9165. return false;
  9166. }
  9167. this.effectsReady = true;
  9168. }
  9169. var canvas = instanceInfo.owner.owner;
  9170. var engine = canvas.engine;
  9171. var depthFunction = 0;
  9172. if (this.effectFill && this.effectBorder) {
  9173. depthFunction = engine.getDepthFunction();
  9174. engine.setDepthFunctionToLessOrEqual();
  9175. }
  9176. var curAlphaMode = engine.getAlphaMode();
  9177. if (this.effectFill) {
  9178. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_FILLPARTID.toString());
  9179. var pid = context.groupInfoPartData[partIndex];
  9180. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  9181. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  9182. }
  9183. var effect = context.useInstancing ? this.effectFillInstanced : this.effectFill;
  9184. engine.enableEffect(effect);
  9185. engine.bindBuffersDirectly(this.fillVB, this.fillIB, [1], 4, effect);
  9186. if (context.useInstancing) {
  9187. if (!this.instancingFillAttributes) {
  9188. this.instancingFillAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_FILLPARTID, effect);
  9189. }
  9190. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  9191. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  9192. canvas._addDrawCallCount(1, context.renderMode);
  9193. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingFillAttributes);
  9194. engine.draw(true, 0, this.fillIndicesCount, count);
  9195. engine.unbindInstanceAttributes();
  9196. }
  9197. else {
  9198. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  9199. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  9200. this.setupUniforms(effect, partIndex, pid._partData, i);
  9201. engine.draw(true, 0, this.fillIndicesCount);
  9202. }
  9203. }
  9204. }
  9205. if (this.effectBorder) {
  9206. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_BORDERPARTID.toString());
  9207. var pid = context.groupInfoPartData[partIndex];
  9208. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  9209. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  9210. }
  9211. var effect = context.useInstancing ? this.effectBorderInstanced : this.effectBorder;
  9212. engine.enableEffect(effect);
  9213. engine.bindBuffersDirectly(this.borderVB, this.borderIB, [1], 4, effect);
  9214. if (context.useInstancing) {
  9215. if (!this.instancingBorderAttributes) {
  9216. this.instancingBorderAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, effect);
  9217. }
  9218. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  9219. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  9220. canvas._addDrawCallCount(1, context.renderMode);
  9221. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingBorderAttributes);
  9222. engine.draw(true, 0, this.borderIndicesCount, count);
  9223. engine.unbindInstanceAttributes();
  9224. }
  9225. else {
  9226. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  9227. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  9228. this.setupUniforms(effect, partIndex, pid._partData, i);
  9229. engine.draw(true, 0, this.borderIndicesCount);
  9230. }
  9231. }
  9232. }
  9233. engine.setAlphaMode(curAlphaMode, true);
  9234. if (this.effectFill && this.effectBorder) {
  9235. engine.setDepthFunction(depthFunction);
  9236. }
  9237. return true;
  9238. };
  9239. Ellipse2DRenderCache.prototype.dispose = function () {
  9240. if (!_super.prototype.dispose.call(this)) {
  9241. return false;
  9242. }
  9243. if (this.fillVB) {
  9244. this._engine._releaseBuffer(this.fillVB);
  9245. this.fillVB = null;
  9246. }
  9247. if (this.fillIB) {
  9248. this._engine._releaseBuffer(this.fillIB);
  9249. this.fillIB = null;
  9250. }
  9251. this.effectFill = null;
  9252. this.effectFillInstanced = null;
  9253. this.effectBorder = null;
  9254. this.effectBorderInstanced = null;
  9255. if (this.borderVB) {
  9256. this._engine._releaseBuffer(this.borderVB);
  9257. this.borderVB = null;
  9258. }
  9259. if (this.borderIB) {
  9260. this._engine._releaseBuffer(this.borderIB);
  9261. this.borderIB = null;
  9262. }
  9263. return true;
  9264. };
  9265. return Ellipse2DRenderCache;
  9266. }(BABYLON.ModelRenderCache));
  9267. BABYLON.Ellipse2DRenderCache = Ellipse2DRenderCache;
  9268. var Ellipse2DInstanceData = (function (_super) {
  9269. __extends(Ellipse2DInstanceData, _super);
  9270. function Ellipse2DInstanceData(partId) {
  9271. return _super.call(this, partId, 1) || this;
  9272. }
  9273. Object.defineProperty(Ellipse2DInstanceData.prototype, "properties", {
  9274. get: function () {
  9275. return null;
  9276. },
  9277. set: function (value) {
  9278. },
  9279. enumerable: true,
  9280. configurable: true
  9281. });
  9282. return Ellipse2DInstanceData;
  9283. }(BABYLON.Shape2DInstanceData));
  9284. __decorate([
  9285. BABYLON.instanceData()
  9286. ], Ellipse2DInstanceData.prototype, "properties", null);
  9287. BABYLON.Ellipse2DInstanceData = Ellipse2DInstanceData;
  9288. var Ellipse2D = Ellipse2D_1 = (function (_super) {
  9289. __extends(Ellipse2D, _super);
  9290. /**
  9291. * Create an Ellipse 2D Shape primitive
  9292. * @param settings a combination of settings, possible ones are
  9293. * - 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)
  9294. * - children: an array of direct children
  9295. * - id: a text identifier, for information purpose
  9296. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  9297. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  9298. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  9299. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  9300. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  9301. * - zOrder: override the zOrder with the specified value
  9302. * - origin: define the normalized origin point location, default [0.5;0.5]
  9303. * - size: the size of the group. Alternatively the width and height properties can be set. Default will be [10;10].
  9304. * - subdivision: the number of subdivision to create the ellipse perimeter, default is 64.
  9305. * - 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)
  9306. * - 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)
  9307. * - borderThickness: the thickness of the drawn border, default is 1.
  9308. * - isVisible: true if the group must be visible, false for hidden. Default is true.
  9309. * - 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.
  9310. * - 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.
  9311. * - 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!
  9312. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9313. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9314. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9315. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9316. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  9317. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  9318. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  9319. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  9320. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9321. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9322. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9323. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9324. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  9325. */
  9326. function Ellipse2D(settings) {
  9327. var _this;
  9328. // Avoid checking every time if the object exists
  9329. if (settings == null) {
  9330. settings = {};
  9331. }
  9332. _this = _super.call(this, settings) || this;
  9333. if (settings.size != null) {
  9334. _this.size = settings.size;
  9335. }
  9336. else if (settings.width || settings.height) {
  9337. var size = new BABYLON.Size(settings.width, settings.height);
  9338. _this.size = size;
  9339. }
  9340. var sub = (settings.subdivisions == null) ? 64 : settings.subdivisions;
  9341. _this.subdivisions = sub;
  9342. return _this;
  9343. }
  9344. Object.defineProperty(Ellipse2D.prototype, "actualSize", {
  9345. get: function () {
  9346. if (this._actualSize) {
  9347. return this._actualSize;
  9348. }
  9349. return this.size;
  9350. },
  9351. set: function (value) {
  9352. this._actualSize = value;
  9353. },
  9354. enumerable: true,
  9355. configurable: true
  9356. });
  9357. Object.defineProperty(Ellipse2D.prototype, "subdivisions", {
  9358. get: function () {
  9359. return this._subdivisions;
  9360. },
  9361. set: function (value) {
  9362. this._subdivisions = value;
  9363. },
  9364. enumerable: true,
  9365. configurable: true
  9366. });
  9367. Ellipse2D.prototype.levelIntersect = function (intersectInfo) {
  9368. var w = this.size.width / 2;
  9369. var h = this.size.height / 2;
  9370. var x = intersectInfo._localPickPosition.x - w;
  9371. var y = intersectInfo._localPickPosition.y - h;
  9372. return ((x * x) / (w * w) + (y * y) / (h * h)) <= 1;
  9373. };
  9374. Ellipse2D.prototype.updateLevelBoundingInfo = function () {
  9375. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.actualSize, this._levelBoundingInfo);
  9376. };
  9377. Ellipse2D.prototype.createModelRenderCache = function (modelKey) {
  9378. var renderCache = new Ellipse2DRenderCache(this.owner.engine, modelKey);
  9379. return renderCache;
  9380. };
  9381. Ellipse2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  9382. var renderCache = modelRenderCache;
  9383. var engine = this.owner.engine;
  9384. // Need to create WebGL resources for fill part?
  9385. if (this.fill) {
  9386. var vbSize = this.subdivisions + 1;
  9387. var vb = new Float32Array(vbSize);
  9388. for (var i = 0; i < vbSize; i++) {
  9389. vb[i] = i;
  9390. }
  9391. renderCache.fillVB = engine.createVertexBuffer(vb);
  9392. var triCount = vbSize - 1;
  9393. var ib = new Float32Array(triCount * 3);
  9394. for (var i = 0; i < triCount; i++) {
  9395. ib[i * 3 + 0] = 0;
  9396. ib[i * 3 + 2] = i + 1;
  9397. ib[i * 3 + 1] = i + 2;
  9398. }
  9399. ib[triCount * 3 - 2] = 1;
  9400. renderCache.fillIB = engine.createIndexBuffer(ib);
  9401. renderCache.fillIndicesCount = triCount * 3;
  9402. // 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
  9403. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, true);
  9404. if (ei) {
  9405. renderCache.effectFillInstanced = engine.createEffect({ vertex: "ellipse2d", fragment: "ellipse2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  9406. }
  9407. // Get the non instanced version
  9408. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, false);
  9409. renderCache.effectFill = engine.createEffect({ vertex: "ellipse2d", fragment: "ellipse2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  9410. }
  9411. // Need to create WebGL resource for border part?
  9412. if (this.border) {
  9413. var vbSize = this.subdivisions * 2;
  9414. var vb = new Float32Array(vbSize);
  9415. for (var i = 0; i < vbSize; i++) {
  9416. vb[i] = i;
  9417. }
  9418. renderCache.borderVB = engine.createVertexBuffer(vb);
  9419. var triCount = vbSize;
  9420. var rs = triCount / 2;
  9421. var ib = new Float32Array(triCount * 3);
  9422. for (var i = 0; i < rs; i++) {
  9423. var r0 = i;
  9424. var r1 = (i + 1) % rs;
  9425. ib[i * 6 + 0] = rs + r1;
  9426. ib[i * 6 + 1] = rs + r0;
  9427. ib[i * 6 + 2] = r0;
  9428. ib[i * 6 + 3] = r1;
  9429. ib[i * 6 + 4] = rs + r1;
  9430. ib[i * 6 + 5] = r0;
  9431. }
  9432. renderCache.borderIB = engine.createIndexBuffer(ib);
  9433. renderCache.borderIndicesCount = (triCount * 3);
  9434. // 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
  9435. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, true);
  9436. if (ei) {
  9437. renderCache.effectBorderInstanced = engine.createEffect("ellipse2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9438. }
  9439. // Get the non instanced version
  9440. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, false);
  9441. renderCache.effectBorder = engine.createEffect("ellipse2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9442. }
  9443. return renderCache;
  9444. };
  9445. Ellipse2D.prototype.createInstanceDataParts = function () {
  9446. var res = new Array();
  9447. if (this.border) {
  9448. res.push(new Ellipse2DInstanceData(BABYLON.Shape2D.SHAPE2D_BORDERPARTID));
  9449. }
  9450. if (this.fill) {
  9451. res.push(new Ellipse2DInstanceData(BABYLON.Shape2D.SHAPE2D_FILLPARTID));
  9452. }
  9453. return res;
  9454. };
  9455. Ellipse2D.prototype.refreshInstanceDataPart = function (part) {
  9456. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  9457. return false;
  9458. }
  9459. if (part.id === BABYLON.Shape2D.SHAPE2D_BORDERPARTID) {
  9460. var d = part;
  9461. var size = this.actualSize;
  9462. var s = this.actualScale;
  9463. d.properties = new BABYLON.Vector3(size.width * s.x, size.height * s.y, this.subdivisions);
  9464. }
  9465. else if (part.id === BABYLON.Shape2D.SHAPE2D_FILLPARTID) {
  9466. var d = part;
  9467. var size = this.actualSize;
  9468. var s = this.actualScale;
  9469. d.properties = new BABYLON.Vector3(size.width * s.x, size.height * s.y, this.subdivisions);
  9470. }
  9471. return true;
  9472. };
  9473. return Ellipse2D;
  9474. }(BABYLON.Shape2D));
  9475. __decorate([
  9476. BABYLON.instanceLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 1, function (pi) { return Ellipse2D_1.acutalSizeProperty = pi; }, false, true)
  9477. ], Ellipse2D.prototype, "actualSize", null);
  9478. __decorate([
  9479. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 2, function (pi) { return Ellipse2D_1.subdivisionsProperty = pi; })
  9480. ], Ellipse2D.prototype, "subdivisions", null);
  9481. Ellipse2D = Ellipse2D_1 = __decorate([
  9482. BABYLON.className("Ellipse2D", "BABYLON")
  9483. ], Ellipse2D);
  9484. BABYLON.Ellipse2D = Ellipse2D;
  9485. var Ellipse2D_1;
  9486. })(BABYLON || (BABYLON = {}));
  9487. //# sourceMappingURL=babylon.ellipse2d.js.map
  9488. var __extends = (this && this.__extends) || function (d, b) {
  9489. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  9490. function __() { this.constructor = d; }
  9491. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9492. };
  9493. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  9494. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  9495. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  9496. 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;
  9497. return c > 3 && r && Object.defineProperty(target, key, r), r;
  9498. };
  9499. var BABYLON;
  9500. (function (BABYLON) {
  9501. var Sprite2DRenderCache = (function (_super) {
  9502. __extends(Sprite2DRenderCache, _super);
  9503. function Sprite2DRenderCache() {
  9504. var _this = _super.apply(this, arguments) || this;
  9505. _this.effectsReady = false;
  9506. _this.vb = null;
  9507. _this.ib = null;
  9508. _this.instancingAttributes = null;
  9509. _this.texture = null;
  9510. _this.effect = null;
  9511. _this.effectInstanced = null;
  9512. return _this;
  9513. }
  9514. Sprite2DRenderCache.prototype.render = function (instanceInfo, context) {
  9515. // Do nothing if the shader is still loading/preparing
  9516. if (!this.effectsReady) {
  9517. if ((this.effect && (!this.effect.isReady() || (this.effectInstanced && !this.effectInstanced.isReady())))) {
  9518. return false;
  9519. }
  9520. this.effectsReady = true;
  9521. }
  9522. // Compute the offset locations of the attributes in the vertex shader that will be mapped to the instance buffer data
  9523. var canvas = instanceInfo.owner.owner;
  9524. var engine = canvas.engine;
  9525. var cur = engine.getAlphaMode();
  9526. var effect = context.useInstancing ? this.effectInstanced : this.effect;
  9527. engine.enableEffect(effect);
  9528. effect.setTexture("diffuseSampler", this.texture);
  9529. engine.bindBuffersDirectly(this.vb, this.ib, [1], 4, effect);
  9530. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  9531. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  9532. }
  9533. effect.setBool("alphaTest", context.renderMode === BABYLON.Render2DContext.RenderModeAlphaTest);
  9534. var pid = context.groupInfoPartData[0];
  9535. if (context.useInstancing) {
  9536. if (!this.instancingAttributes) {
  9537. this.instancingAttributes = this.loadInstancingAttributes(Sprite2D.SPRITE2D_MAINPARTID, effect);
  9538. }
  9539. var glBuffer = context.instancedBuffers ? context.instancedBuffers[0] : pid._partBuffer;
  9540. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  9541. canvas._addDrawCallCount(1, context.renderMode);
  9542. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingAttributes);
  9543. engine.draw(true, 0, 6, count);
  9544. engine.unbindInstanceAttributes();
  9545. }
  9546. else {
  9547. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  9548. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  9549. this.setupUniforms(effect, 0, pid._partData, i);
  9550. engine.draw(true, 0, 6);
  9551. }
  9552. }
  9553. engine.setAlphaMode(cur, true);
  9554. return true;
  9555. };
  9556. Sprite2DRenderCache.prototype.dispose = function () {
  9557. if (!_super.prototype.dispose.call(this)) {
  9558. return false;
  9559. }
  9560. if (this.vb) {
  9561. this._engine._releaseBuffer(this.vb);
  9562. this.vb = null;
  9563. }
  9564. if (this.ib) {
  9565. this._engine._releaseBuffer(this.ib);
  9566. this.ib = null;
  9567. }
  9568. //if (this.texture) {
  9569. // this.texture.dispose();
  9570. // this.texture = null;
  9571. //}
  9572. this.effect = null;
  9573. this.effectInstanced = null;
  9574. return true;
  9575. };
  9576. return Sprite2DRenderCache;
  9577. }(BABYLON.ModelRenderCache));
  9578. BABYLON.Sprite2DRenderCache = Sprite2DRenderCache;
  9579. var Sprite2DInstanceData = (function (_super) {
  9580. __extends(Sprite2DInstanceData, _super);
  9581. function Sprite2DInstanceData(partId) {
  9582. return _super.call(this, partId, 1) || this;
  9583. }
  9584. Object.defineProperty(Sprite2DInstanceData.prototype, "topLeftUV", {
  9585. get: function () {
  9586. return null;
  9587. },
  9588. set: function (value) {
  9589. },
  9590. enumerable: true,
  9591. configurable: true
  9592. });
  9593. Object.defineProperty(Sprite2DInstanceData.prototype, "sizeUV", {
  9594. get: function () {
  9595. return null;
  9596. },
  9597. set: function (value) {
  9598. },
  9599. enumerable: true,
  9600. configurable: true
  9601. });
  9602. Object.defineProperty(Sprite2DInstanceData.prototype, "scaleFactor", {
  9603. get: function () {
  9604. return null;
  9605. },
  9606. set: function (value) {
  9607. },
  9608. enumerable: true,
  9609. configurable: true
  9610. });
  9611. Object.defineProperty(Sprite2DInstanceData.prototype, "textureSize", {
  9612. get: function () {
  9613. return null;
  9614. },
  9615. set: function (value) {
  9616. },
  9617. enumerable: true,
  9618. configurable: true
  9619. });
  9620. Object.defineProperty(Sprite2DInstanceData.prototype, "properties", {
  9621. // 3 floats being:
  9622. // - x: frame number to display
  9623. // - y: invertY setting
  9624. // - z: alignToPixel setting
  9625. get: function () {
  9626. return null;
  9627. },
  9628. set: function (value) {
  9629. },
  9630. enumerable: true,
  9631. configurable: true
  9632. });
  9633. return Sprite2DInstanceData;
  9634. }(BABYLON.InstanceDataBase));
  9635. __decorate([
  9636. BABYLON.instanceData()
  9637. ], Sprite2DInstanceData.prototype, "topLeftUV", null);
  9638. __decorate([
  9639. BABYLON.instanceData()
  9640. ], Sprite2DInstanceData.prototype, "sizeUV", null);
  9641. __decorate([
  9642. BABYLON.instanceData()
  9643. ], Sprite2DInstanceData.prototype, "scaleFactor", null);
  9644. __decorate([
  9645. BABYLON.instanceData()
  9646. ], Sprite2DInstanceData.prototype, "textureSize", null);
  9647. __decorate([
  9648. BABYLON.instanceData()
  9649. ], Sprite2DInstanceData.prototype, "properties", null);
  9650. BABYLON.Sprite2DInstanceData = Sprite2DInstanceData;
  9651. var Sprite2D = Sprite2D_1 = (function (_super) {
  9652. __extends(Sprite2D, _super);
  9653. /**
  9654. * Create an 2D Sprite primitive
  9655. * @param texture the texture that stores the sprite to render
  9656. * @param settings a combination of settings, possible ones are
  9657. * - 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)
  9658. * - children: an array of direct children
  9659. * - id a text identifier, for information purpose
  9660. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  9661. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  9662. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  9663. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  9664. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  9665. * - zOrder: override the zOrder with the specified value
  9666. * - origin: define the normalized origin point location, default [0.5;0.5]
  9667. * - spriteSize: the size of the sprite (in pixels), if null the size of the given texture will be used, default is null.
  9668. * - spriteLocation: the location (in pixels) in the texture of the top/left corner of the Sprite to display, default is null (0,0)
  9669. * - spriteScaleFactor: 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.
  9670. * - invertY: if true the texture Y will be inverted, default is false.
  9671. * - 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.
  9672. * - isVisible: true if the sprite must be visible, false for hidden. Default is true.
  9673. * - 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.
  9674. * - 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.
  9675. * - 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!
  9676. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9677. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9678. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9679. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9680. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  9681. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  9682. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  9683. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  9684. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9685. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9686. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9687. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9688. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  9689. */
  9690. function Sprite2D(texture, settings) {
  9691. var _this;
  9692. if (!settings) {
  9693. settings = {};
  9694. }
  9695. _this = _super.call(this, settings) || this;
  9696. _this.texture = texture;
  9697. _this.texture.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
  9698. _this.texture.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
  9699. _this.size = (settings.spriteSize != null) ? settings.spriteSize.clone() : null;
  9700. _this.spriteLocation = (settings.spriteLocation != null) ? settings.spriteLocation.clone() : new BABYLON.Vector2(0, 0);
  9701. _this.spriteScaleFactor = (settings.spriteScaleFactor != null) ? settings.spriteScaleFactor : new BABYLON.Vector2(1, 1);
  9702. _this.spriteFrame = 0;
  9703. _this.invertY = (settings.invertY == null) ? false : settings.invertY;
  9704. _this.alignToPixel = (settings.alignToPixel == null) ? true : settings.alignToPixel;
  9705. _this.useAlphaFromTexture = true;
  9706. // 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.
  9707. // The fucking delayed texture sprite bug is fixed!
  9708. if (settings.spriteSize == null) {
  9709. _this.size = new BABYLON.Size(10, 10);
  9710. }
  9711. if (settings.spriteSize == null || !texture.isReady()) {
  9712. if (texture.isReady()) {
  9713. var s = texture.getBaseSize();
  9714. _this.size = new BABYLON.Size(s.width, s.height);
  9715. }
  9716. else {
  9717. texture.onLoadObservable.add(function () {
  9718. if (settings.spriteSize == null) {
  9719. var s = texture.getBaseSize();
  9720. _this.size = new BABYLON.Size(s.width, s.height);
  9721. }
  9722. _this._positioningDirty();
  9723. _this._setLayoutDirty();
  9724. _this._instanceDirtyFlags |= BABYLON.Prim2DBase.originProperty.flagId | Sprite2D_1.textureProperty.flagId; // To make sure the sprite is issued again for render
  9725. });
  9726. }
  9727. }
  9728. return _this;
  9729. }
  9730. Object.defineProperty(Sprite2D.prototype, "texture", {
  9731. get: function () {
  9732. return this._texture;
  9733. },
  9734. set: function (value) {
  9735. this._texture = value;
  9736. this._oldTextureHasAlpha = this._texture && this.texture.hasAlpha;
  9737. },
  9738. enumerable: true,
  9739. configurable: true
  9740. });
  9741. Object.defineProperty(Sprite2D.prototype, "useAlphaFromTexture", {
  9742. get: function () {
  9743. return this._useAlphaFromTexture;
  9744. },
  9745. set: function (value) {
  9746. if (this._useAlphaFromTexture === value) {
  9747. return;
  9748. }
  9749. this._useAlphaFromTexture = value;
  9750. this._updateRenderMode();
  9751. },
  9752. enumerable: true,
  9753. configurable: true
  9754. });
  9755. Object.defineProperty(Sprite2D.prototype, "actualSize", {
  9756. get: function () {
  9757. if (this._actualSize) {
  9758. return this._actualSize;
  9759. }
  9760. return this.size;
  9761. },
  9762. set: function (value) {
  9763. this._actualSize = value;
  9764. },
  9765. enumerable: true,
  9766. configurable: true
  9767. });
  9768. Object.defineProperty(Sprite2D.prototype, "spriteLocation", {
  9769. get: function () {
  9770. return this._location;
  9771. },
  9772. set: function (value) {
  9773. this._location = value;
  9774. },
  9775. enumerable: true,
  9776. configurable: true
  9777. });
  9778. Object.defineProperty(Sprite2D.prototype, "spriteFrame", {
  9779. get: function () {
  9780. return this._spriteFrame;
  9781. },
  9782. set: function (value) {
  9783. this._spriteFrame = value;
  9784. },
  9785. enumerable: true,
  9786. configurable: true
  9787. });
  9788. Object.defineProperty(Sprite2D.prototype, "invertY", {
  9789. get: function () {
  9790. return this._invertY;
  9791. },
  9792. set: function (value) {
  9793. this._invertY = value;
  9794. },
  9795. enumerable: true,
  9796. configurable: true
  9797. });
  9798. Object.defineProperty(Sprite2D.prototype, "spriteScaleFactor", {
  9799. get: function () {
  9800. return this._spriteScaleFactor;
  9801. },
  9802. set: function (value) {
  9803. this._spriteScaleFactor = value;
  9804. },
  9805. enumerable: true,
  9806. configurable: true
  9807. });
  9808. /**
  9809. * Sets the scale of the sprite using a BABYLON.Size(w,h).
  9810. * Keeps proportion by taking the maximum of the two scale for x and y.
  9811. * @param {Size} size Size(width,height)
  9812. */
  9813. Sprite2D.prototype.scaleToSize = function (size) {
  9814. var baseSize = this.size;
  9815. if (baseSize == null || !this.texture.isReady()) {
  9816. // we're probably at initiation of the scene, size is not set
  9817. if (this.texture.isReady()) {
  9818. baseSize = this.texture.getBaseSize();
  9819. }
  9820. else {
  9821. // the texture is not ready, wait for it to load before calling scaleToSize again
  9822. var thisObject = this;
  9823. this.texture.onLoadObservable.add(function () {
  9824. thisObject.scaleToSize(size);
  9825. });
  9826. return;
  9827. }
  9828. }
  9829. this.scale = Math.max(size.height / baseSize.height, size.width / baseSize.width);
  9830. };
  9831. Object.defineProperty(Sprite2D.prototype, "alignToPixel", {
  9832. /**
  9833. * Get/set if the sprite rendering should be aligned to the target rendering device pixel or not
  9834. */
  9835. get: function () {
  9836. return this._alignToPixel;
  9837. },
  9838. set: function (value) {
  9839. this._alignToPixel = value;
  9840. },
  9841. enumerable: true,
  9842. configurable: true
  9843. });
  9844. Sprite2D.prototype.updateLevelBoundingInfo = function () {
  9845. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.size, this._levelBoundingInfo);
  9846. };
  9847. /**
  9848. * Get the animatable array (see http://doc.babylonjs.com/tutorials/Animations)
  9849. */
  9850. Sprite2D.prototype.getAnimatables = function () {
  9851. var res = new Array();
  9852. if (this.texture && this.texture.animations && this.texture.animations.length > 0) {
  9853. res.push(this.texture);
  9854. }
  9855. return res;
  9856. };
  9857. Sprite2D.prototype.levelIntersect = function (intersectInfo) {
  9858. // 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
  9859. return true;
  9860. };
  9861. Sprite2D.prototype.createModelRenderCache = function (modelKey) {
  9862. var renderCache = new Sprite2DRenderCache(this.owner.engine, modelKey);
  9863. return renderCache;
  9864. };
  9865. Sprite2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  9866. var renderCache = modelRenderCache;
  9867. var engine = this.owner.engine;
  9868. var vb = new Float32Array(4);
  9869. for (var i = 0; i < 4; i++) {
  9870. vb[i] = i;
  9871. }
  9872. renderCache.vb = engine.createVertexBuffer(vb);
  9873. var ib = new Float32Array(6);
  9874. ib[0] = 0;
  9875. ib[1] = 2;
  9876. ib[2] = 1;
  9877. ib[3] = 0;
  9878. ib[4] = 3;
  9879. ib[5] = 2;
  9880. renderCache.ib = engine.createIndexBuffer(ib);
  9881. renderCache.texture = this.texture;
  9882. // 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
  9883. var ei = this.getDataPartEffectInfo(Sprite2D_1.SPRITE2D_MAINPARTID, ["index"], ["alphaTest"], true);
  9884. if (ei) {
  9885. renderCache.effectInstanced = engine.createEffect("sprite2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  9886. }
  9887. ei = this.getDataPartEffectInfo(Sprite2D_1.SPRITE2D_MAINPARTID, ["index"], ["alphaTest"], false);
  9888. renderCache.effect = engine.createEffect("sprite2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  9889. return renderCache;
  9890. };
  9891. Sprite2D.prototype.createInstanceDataParts = function () {
  9892. return [new Sprite2DInstanceData(Sprite2D_1.SPRITE2D_MAINPARTID)];
  9893. };
  9894. Sprite2D.prototype.beforeRefreshForLayoutConstruction = function (part) {
  9895. Sprite2D_1.layoutConstructMode = true;
  9896. };
  9897. // if obj contains something, we restore the _text property
  9898. Sprite2D.prototype.afterRefreshForLayoutConstruction = function (part, obj) {
  9899. Sprite2D_1.layoutConstructMode = false;
  9900. };
  9901. Sprite2D.prototype.refreshInstanceDataPart = function (part) {
  9902. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  9903. return false;
  9904. }
  9905. if (!this.texture.isReady() && !Sprite2D_1.layoutConstructMode) {
  9906. return false;
  9907. }
  9908. if (part.id === Sprite2D_1.SPRITE2D_MAINPARTID) {
  9909. var d = this._instanceDataParts[0];
  9910. if (Sprite2D_1.layoutConstructMode) {
  9911. d.topLeftUV = BABYLON.Vector2.Zero();
  9912. d.sizeUV = BABYLON.Vector2.Zero();
  9913. d.properties = BABYLON.Vector3.Zero();
  9914. d.textureSize = BABYLON.Vector2.Zero();
  9915. d.scaleFactor = BABYLON.Vector2.Zero();
  9916. }
  9917. else {
  9918. var ts = this.texture.getBaseSize();
  9919. var sl = this.spriteLocation;
  9920. var ss = this.actualSize;
  9921. var ssf = this.spriteScaleFactor;
  9922. d.topLeftUV = new BABYLON.Vector2(sl.x / ts.width, sl.y / ts.height);
  9923. var suv = new BABYLON.Vector2(ss.width / ts.width, ss.height / ts.height);
  9924. d.sizeUV = suv;
  9925. d.scaleFactor = ssf;
  9926. Sprite2D_1._prop.x = this.spriteFrame;
  9927. Sprite2D_1._prop.y = this.invertY ? 1 : 0;
  9928. Sprite2D_1._prop.z = this.alignToPixel ? 1 : 0;
  9929. d.properties = Sprite2D_1._prop;
  9930. d.textureSize = new BABYLON.Vector2(ts.width, ts.height);
  9931. }
  9932. }
  9933. return true;
  9934. };
  9935. Sprite2D.prototype._mustUpdateInstance = function () {
  9936. var res = this._oldTextureHasAlpha !== (this.texture != null && this.texture.hasAlpha);
  9937. this._oldTextureHasAlpha = this.texture != null && this.texture.hasAlpha;
  9938. if (res) {
  9939. this._updateRenderMode();
  9940. }
  9941. return res;
  9942. };
  9943. Sprite2D.prototype._useTextureAlpha = function () {
  9944. return this.texture != null && this.texture.hasAlpha;
  9945. };
  9946. Sprite2D.prototype._shouldUseAlphaFromTexture = function () {
  9947. return this.texture != null && this.texture.hasAlpha && this.useAlphaFromTexture;
  9948. };
  9949. return Sprite2D;
  9950. }(BABYLON.RenderablePrim2D));
  9951. Sprite2D.SPRITE2D_MAINPARTID = 1;
  9952. Sprite2D._prop = BABYLON.Vector3.Zero();
  9953. Sprite2D.layoutConstructMode = false;
  9954. __decorate([
  9955. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 1, function (pi) { return Sprite2D_1.textureProperty = pi; })
  9956. ], Sprite2D.prototype, "texture", null);
  9957. __decorate([
  9958. BABYLON.dynamicLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 2, function (pi) { return Sprite2D_1.useAlphaFromTextureProperty = pi; })
  9959. ], Sprite2D.prototype, "useAlphaFromTexture", null);
  9960. __decorate([
  9961. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 3, function (pi) { return Sprite2D_1.actualSizeProperty = pi; }, false, true)
  9962. ], Sprite2D.prototype, "actualSize", null);
  9963. __decorate([
  9964. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 4, function (pi) { return Sprite2D_1.spriteLocationProperty = pi; })
  9965. ], Sprite2D.prototype, "spriteLocation", null);
  9966. __decorate([
  9967. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 5, function (pi) { return Sprite2D_1.spriteFrameProperty = pi; })
  9968. ], Sprite2D.prototype, "spriteFrame", null);
  9969. __decorate([
  9970. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 6, function (pi) { return Sprite2D_1.invertYProperty = pi; })
  9971. ], Sprite2D.prototype, "invertY", null);
  9972. __decorate([
  9973. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 7, function (pi) { return Sprite2D_1.spriteScaleFactorProperty = pi; })
  9974. ], Sprite2D.prototype, "spriteScaleFactor", null);
  9975. Sprite2D = Sprite2D_1 = __decorate([
  9976. BABYLON.className("Sprite2D", "BABYLON")
  9977. ], Sprite2D);
  9978. BABYLON.Sprite2D = Sprite2D;
  9979. var Sprite2D_1;
  9980. })(BABYLON || (BABYLON = {}));
  9981. //# sourceMappingURL=babylon.sprite2d.js.map
  9982. var __extends = (this && this.__extends) || function (d, b) {
  9983. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  9984. function __() { this.constructor = d; }
  9985. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9986. };
  9987. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  9988. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  9989. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  9990. 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;
  9991. return c > 3 && r && Object.defineProperty(target, key, r), r;
  9992. };
  9993. var BABYLON;
  9994. (function (BABYLON) {
  9995. var Text2DRenderCache = (function (_super) {
  9996. __extends(Text2DRenderCache, _super);
  9997. function Text2DRenderCache() {
  9998. var _this = _super.apply(this, arguments) || this;
  9999. _this.effectsReady = false;
  10000. _this.vb = null;
  10001. _this.ib = null;
  10002. _this.instancingAttributes = null;
  10003. _this.fontTexture = null;
  10004. _this.effect = null;
  10005. _this.effectInstanced = null;
  10006. return _this;
  10007. }
  10008. Text2DRenderCache.prototype.render = function (instanceInfo, context) {
  10009. // Do nothing if the shader is still loading/preparing
  10010. if (!this.effectsReady) {
  10011. if ((this.effect && (!this.effect.isReady() || (this.effectInstanced && !this.effectInstanced.isReady())))) {
  10012. return false;
  10013. }
  10014. this.effectsReady = true;
  10015. }
  10016. var canvas = instanceInfo.owner.owner;
  10017. var engine = canvas.engine;
  10018. this.fontTexture.update();
  10019. var effect = context.useInstancing ? this.effectInstanced : this.effect;
  10020. engine.enableEffect(effect);
  10021. effect.setTexture("diffuseSampler", this.fontTexture);
  10022. engine.bindBuffersDirectly(this.vb, this.ib, [1], 4, effect);
  10023. var sdf = this.fontTexture.isSignedDistanceField;
  10024. // Enable alpha mode only if the texture is not using SDF, SDF is rendered in AlphaTest mode, which mean no alpha blend
  10025. var curAlphaMode;
  10026. if (!sdf) {
  10027. curAlphaMode = engine.getAlphaMode();
  10028. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  10029. }
  10030. var pid = context.groupInfoPartData[0];
  10031. if (context.useInstancing) {
  10032. if (!this.instancingAttributes) {
  10033. this.instancingAttributes = this.loadInstancingAttributes(Text2D.TEXT2D_MAINPARTID, effect);
  10034. }
  10035. var glBuffer = context.instancedBuffers ? context.instancedBuffers[0] : pid._partBuffer;
  10036. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  10037. canvas._addDrawCallCount(1, context.renderMode);
  10038. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingAttributes);
  10039. engine.draw(true, 0, 6, count);
  10040. engine.unbindInstanceAttributes();
  10041. }
  10042. else {
  10043. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  10044. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  10045. this.setupUniforms(effect, 0, pid._partData, i);
  10046. engine.draw(true, 0, 6);
  10047. }
  10048. }
  10049. if (!sdf) {
  10050. engine.setAlphaMode(curAlphaMode, true);
  10051. }
  10052. return true;
  10053. };
  10054. Text2DRenderCache.prototype.dispose = function () {
  10055. if (!_super.prototype.dispose.call(this)) {
  10056. return false;
  10057. }
  10058. if (this.vb) {
  10059. this._engine._releaseBuffer(this.vb);
  10060. this.vb = null;
  10061. }
  10062. if (this.ib) {
  10063. this._engine._releaseBuffer(this.ib);
  10064. this.ib = null;
  10065. }
  10066. if (this.fontTexture) {
  10067. this.fontTexture.decCachedFontTextureCounter();
  10068. this.fontTexture = null;
  10069. }
  10070. this.effect = null;
  10071. this.effectInstanced = null;
  10072. return true;
  10073. };
  10074. return Text2DRenderCache;
  10075. }(BABYLON.ModelRenderCache));
  10076. BABYLON.Text2DRenderCache = Text2DRenderCache;
  10077. var Text2DInstanceData = (function (_super) {
  10078. __extends(Text2DInstanceData, _super);
  10079. function Text2DInstanceData(partId, dataElementCount) {
  10080. return _super.call(this, partId, dataElementCount) || this;
  10081. }
  10082. Object.defineProperty(Text2DInstanceData.prototype, "topLeftUV", {
  10083. get: function () {
  10084. return null;
  10085. },
  10086. set: function (value) {
  10087. },
  10088. enumerable: true,
  10089. configurable: true
  10090. });
  10091. Object.defineProperty(Text2DInstanceData.prototype, "sizeUV", {
  10092. get: function () {
  10093. return null;
  10094. },
  10095. set: function (value) {
  10096. },
  10097. enumerable: true,
  10098. configurable: true
  10099. });
  10100. Object.defineProperty(Text2DInstanceData.prototype, "textureSize", {
  10101. get: function () {
  10102. return null;
  10103. },
  10104. set: function (value) {
  10105. },
  10106. enumerable: true,
  10107. configurable: true
  10108. });
  10109. Object.defineProperty(Text2DInstanceData.prototype, "color", {
  10110. get: function () {
  10111. return null;
  10112. },
  10113. set: function (value) {
  10114. },
  10115. enumerable: true,
  10116. configurable: true
  10117. });
  10118. Object.defineProperty(Text2DInstanceData.prototype, "superSampleFactor", {
  10119. get: function () {
  10120. return null;
  10121. },
  10122. set: function (value) {
  10123. },
  10124. enumerable: true,
  10125. configurable: true
  10126. });
  10127. return Text2DInstanceData;
  10128. }(BABYLON.InstanceDataBase));
  10129. __decorate([
  10130. BABYLON.instanceData()
  10131. ], Text2DInstanceData.prototype, "topLeftUV", null);
  10132. __decorate([
  10133. BABYLON.instanceData()
  10134. ], Text2DInstanceData.prototype, "sizeUV", null);
  10135. __decorate([
  10136. BABYLON.instanceData()
  10137. ], Text2DInstanceData.prototype, "textureSize", null);
  10138. __decorate([
  10139. BABYLON.instanceData()
  10140. ], Text2DInstanceData.prototype, "color", null);
  10141. __decorate([
  10142. BABYLON.instanceData()
  10143. ], Text2DInstanceData.prototype, "superSampleFactor", null);
  10144. BABYLON.Text2DInstanceData = Text2DInstanceData;
  10145. var Text2D = Text2D_1 = (function (_super) {
  10146. __extends(Text2D, _super);
  10147. /**
  10148. * Create a Text primitive
  10149. * @param text the text to display
  10150. * @param settings a combination of settings, possible ones are
  10151. * - 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)
  10152. * - children: an array of direct children
  10153. * - id a text identifier, for information purpose
  10154. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  10155. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  10156. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  10157. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  10158. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  10159. * - zOrder: override the zOrder with the specified value
  10160. * - origin: define the normalized origin point location, default [0.5;0.5]
  10161. * - fontName: the name/size/style of the font to use, following the CSS notation. Default is "12pt Arial".
  10162. * - 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.
  10163. * - 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.
  10164. * - defaultFontColor: the color by default to apply on each letter of the text to display, default is plain white.
  10165. * - areaSize: the size of the area in which to display the text, default is auto-fit from text content.
  10166. * - tabulationSize: number of space character to insert when a tabulation is encountered, default is 4
  10167. * - isVisible: true if the text must be visible, false for hidden. Default is true.
  10168. * - 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.
  10169. * - 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.
  10170. * - 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!
  10171. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10172. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10173. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10174. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10175. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  10176. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  10177. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  10178. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  10179. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10180. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10181. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10182. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10183. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  10184. */
  10185. function Text2D(text, settings) {
  10186. var _this;
  10187. if (!settings) {
  10188. settings = {};
  10189. }
  10190. _this = _super.call(this, settings) || this;
  10191. _this.fontName = (settings.fontName == null) ? "12pt Arial" : settings.fontName;
  10192. _this._fontSuperSample = (settings.fontSuperSample != null && settings.fontSuperSample);
  10193. _this._fontSDF = (settings.fontSignedDistanceField != null && settings.fontSignedDistanceField);
  10194. _this.defaultFontColor = (settings.defaultFontColor == null) ? new BABYLON.Color4(1, 1, 1, 1) : settings.defaultFontColor;
  10195. _this._tabulationSize = (settings.tabulationSize == null) ? 4 : settings.tabulationSize;
  10196. _this._textSize = null;
  10197. _this.text = text;
  10198. _this.size = (settings.size == null) ? null : settings.size;
  10199. _this._updateRenderMode();
  10200. return _this;
  10201. }
  10202. Object.defineProperty(Text2D.prototype, "fontName", {
  10203. get: function () {
  10204. return this._fontName;
  10205. },
  10206. set: function (value) {
  10207. if (this._fontName) {
  10208. throw new Error("Font Name change is not supported right now.");
  10209. }
  10210. this._fontName = value;
  10211. },
  10212. enumerable: true,
  10213. configurable: true
  10214. });
  10215. Object.defineProperty(Text2D.prototype, "defaultFontColor", {
  10216. get: function () {
  10217. return this._defaultFontColor;
  10218. },
  10219. set: function (value) {
  10220. this._defaultFontColor = value;
  10221. },
  10222. enumerable: true,
  10223. configurable: true
  10224. });
  10225. Object.defineProperty(Text2D.prototype, "text", {
  10226. get: function () {
  10227. return this._text;
  10228. },
  10229. set: function (value) {
  10230. if (!value) {
  10231. value = "";
  10232. }
  10233. this._text = value;
  10234. this._textSize = null; // A change of text will reset the TextSize which will be recomputed next time it's used
  10235. this._size = null;
  10236. this._updateCharCount();
  10237. // Trigger a textSize to for a sizeChange if necessary, which is needed for layout to recompute
  10238. var s = this.textSize;
  10239. },
  10240. enumerable: true,
  10241. configurable: true
  10242. });
  10243. Object.defineProperty(Text2D.prototype, "size", {
  10244. get: function () {
  10245. if (this._size != null) {
  10246. return this._size;
  10247. }
  10248. return this.textSize;
  10249. },
  10250. set: function (value) {
  10251. this._size = value;
  10252. },
  10253. enumerable: true,
  10254. configurable: true
  10255. });
  10256. Object.defineProperty(Text2D.prototype, "fontSuperSample", {
  10257. get: function () {
  10258. return this._fontTexture && this._fontTexture.isSuperSampled;
  10259. },
  10260. enumerable: true,
  10261. configurable: true
  10262. });
  10263. Object.defineProperty(Text2D.prototype, "fontSignedDistanceField", {
  10264. get: function () {
  10265. return this._fontTexture && this._fontTexture.isSignedDistanceField;
  10266. },
  10267. enumerable: true,
  10268. configurable: true
  10269. });
  10270. Object.defineProperty(Text2D.prototype, "isSizeAuto", {
  10271. get: function () {
  10272. return false;
  10273. },
  10274. enumerable: true,
  10275. configurable: true
  10276. });
  10277. Object.defineProperty(Text2D.prototype, "actualSize", {
  10278. /**
  10279. * Get the actual size of the Text2D primitive
  10280. */
  10281. get: function () {
  10282. if (this._actualSize) {
  10283. return this._actualSize;
  10284. }
  10285. return this.size;
  10286. },
  10287. enumerable: true,
  10288. configurable: true
  10289. });
  10290. Object.defineProperty(Text2D.prototype, "textSize", {
  10291. /**
  10292. * Get the area that bounds the text associated to the primitive
  10293. */
  10294. get: function () {
  10295. if (!this._textSize) {
  10296. if (this.owner && this._text) {
  10297. var newSize = this.fontTexture.measureText(this._text, this._tabulationSize);
  10298. if (!newSize.equals(this._textSize)) {
  10299. this.onPrimitivePropertyDirty(BABYLON.Prim2DBase.sizeProperty.flagId);
  10300. this._positioningDirty();
  10301. }
  10302. this._textSize = newSize;
  10303. }
  10304. else {
  10305. return Text2D_1.nullSize;
  10306. }
  10307. }
  10308. return this._textSize;
  10309. },
  10310. enumerable: true,
  10311. configurable: true
  10312. });
  10313. Object.defineProperty(Text2D.prototype, "fontTexture", {
  10314. get: function () {
  10315. if (this._fontTexture) {
  10316. return this._fontTexture;
  10317. }
  10318. if (this.fontName == null || this.owner == null || this.owner.scene == null) {
  10319. return null;
  10320. }
  10321. this._fontTexture = BABYLON.FontTexture.GetCachedFontTexture(this.owner.scene, this.fontName, this._fontSuperSample, this._fontSDF);
  10322. return this._fontTexture;
  10323. },
  10324. enumerable: true,
  10325. configurable: true
  10326. });
  10327. /**
  10328. * Dispose the primitive, remove it from its parent
  10329. */
  10330. Text2D.prototype.dispose = function () {
  10331. if (!_super.prototype.dispose.call(this)) {
  10332. return false;
  10333. }
  10334. if (this._fontTexture) {
  10335. BABYLON.FontTexture.ReleaseCachedFontTexture(this.owner.scene, this.fontName, this._fontSuperSample, this._fontSDF);
  10336. this._fontTexture = null;
  10337. }
  10338. return true;
  10339. };
  10340. Text2D.prototype.updateLevelBoundingInfo = function () {
  10341. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.actualSize, this._levelBoundingInfo);
  10342. };
  10343. Text2D.prototype.levelIntersect = function (intersectInfo) {
  10344. // 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...
  10345. return true;
  10346. };
  10347. Text2D.prototype.createModelRenderCache = function (modelKey) {
  10348. var renderCache = new Text2DRenderCache(this.owner.engine, modelKey);
  10349. return renderCache;
  10350. };
  10351. Text2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  10352. var renderCache = modelRenderCache;
  10353. var engine = this.owner.engine;
  10354. renderCache.fontTexture = this.fontTexture;
  10355. renderCache.fontTexture.incCachedFontTextureCounter();
  10356. var vb = new Float32Array(4);
  10357. for (var i = 0; i < 4; i++) {
  10358. vb[i] = i;
  10359. }
  10360. renderCache.vb = engine.createVertexBuffer(vb);
  10361. var ib = new Float32Array(6);
  10362. ib[0] = 0;
  10363. ib[1] = 2;
  10364. ib[2] = 1;
  10365. ib[3] = 0;
  10366. ib[4] = 3;
  10367. ib[5] = 2;
  10368. renderCache.ib = engine.createIndexBuffer(ib);
  10369. // 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
  10370. var ei = this.getDataPartEffectInfo(Text2D_1.TEXT2D_MAINPARTID, ["index"], null, true);
  10371. if (ei) {
  10372. renderCache.effectInstanced = engine.createEffect("text2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  10373. }
  10374. ei = this.getDataPartEffectInfo(Text2D_1.TEXT2D_MAINPARTID, ["index"], null, false);
  10375. renderCache.effect = engine.createEffect("text2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  10376. return renderCache;
  10377. };
  10378. Text2D.prototype.createInstanceDataParts = function () {
  10379. return [new Text2DInstanceData(Text2D_1.TEXT2D_MAINPARTID, this._charCount)];
  10380. };
  10381. // Looks like a hack!? Yes! Because that's what it is!
  10382. // 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
  10383. // 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)
  10384. Text2D.prototype.beforeRefreshForLayoutConstruction = function (part) {
  10385. if (!this._charCount) {
  10386. var curText = this._text;
  10387. this.text = "A";
  10388. return curText;
  10389. }
  10390. };
  10391. // if obj contains something, we restore the _text property
  10392. Text2D.prototype.afterRefreshForLayoutConstruction = function (part, obj) {
  10393. if (obj !== undefined) {
  10394. this.text = obj;
  10395. }
  10396. };
  10397. Text2D.prototype.getUsedShaderCategories = function (dataPart) {
  10398. var cat = _super.prototype.getUsedShaderCategories.call(this, dataPart);
  10399. if (this._fontSDF) {
  10400. cat.push(Text2D_1.TEXT2D_CATEGORY_SDF);
  10401. }
  10402. return cat;
  10403. };
  10404. Text2D.prototype.refreshInstanceDataPart = function (part) {
  10405. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  10406. return false;
  10407. }
  10408. if (part.id === Text2D_1.TEXT2D_MAINPARTID) {
  10409. var d = part;
  10410. var texture = this.fontTexture;
  10411. var superSampleFactor = texture.isSuperSampled ? 0.5 : 1;
  10412. var ts = texture.getSize();
  10413. var offset = BABYLON.Vector2.Zero();
  10414. var lh = this.fontTexture.lineHeight;
  10415. 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
  10416. var charxpos = 0;
  10417. d.dataElementCount = this._charCount;
  10418. d.curElement = 0;
  10419. for (var _i = 0, _a = this.text; _i < _a.length; _i++) {
  10420. var char = _a[_i];
  10421. // Line feed
  10422. if (char === "\n") {
  10423. offset.x = 0;
  10424. offset.y -= texture.lineHeight;
  10425. }
  10426. // Tabulation ?
  10427. if (char === "\t") {
  10428. var nextPos = charxpos + this._tabulationSize;
  10429. nextPos = nextPos - (nextPos % this._tabulationSize);
  10430. offset.x += (nextPos - charxpos) * texture.spaceWidth;
  10431. charxpos = nextPos;
  10432. continue;
  10433. }
  10434. if (char < " ") {
  10435. continue;
  10436. }
  10437. this.updateInstanceDataPart(d, offset);
  10438. var ci = texture.getChar(char);
  10439. offset.x += ci.charWidth;
  10440. d.topLeftUV = ci.topLeftUV;
  10441. var suv = ci.bottomRightUV.subtract(ci.topLeftUV);
  10442. d.sizeUV = suv;
  10443. d.textureSize = new BABYLON.Vector2(ts.width, ts.height);
  10444. d.color = this.defaultFontColor;
  10445. d.superSampleFactor = superSampleFactor;
  10446. ++d.curElement;
  10447. }
  10448. }
  10449. return true;
  10450. };
  10451. Text2D.prototype._updateCharCount = function () {
  10452. var count = 0;
  10453. for (var _i = 0, _a = this._text; _i < _a.length; _i++) {
  10454. var char = _a[_i];
  10455. if (char === "\r" || char === "\n" || char === "\t" || char < " ") {
  10456. continue;
  10457. }
  10458. ++count;
  10459. }
  10460. this._charCount = count;
  10461. };
  10462. Text2D.prototype._useTextureAlpha = function () {
  10463. return this._fontSDF;
  10464. };
  10465. Text2D.prototype._shouldUseAlphaFromTexture = function () {
  10466. return !this._fontSDF;
  10467. };
  10468. return Text2D;
  10469. }(BABYLON.RenderablePrim2D));
  10470. Text2D.TEXT2D_MAINPARTID = 1;
  10471. Text2D.TEXT2D_CATEGORY_SDF = "SignedDistanceField";
  10472. __decorate([
  10473. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 1, function (pi) { return Text2D_1.fontProperty = pi; }, false, true)
  10474. ], Text2D.prototype, "fontName", null);
  10475. __decorate([
  10476. BABYLON.dynamicLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 2, function (pi) { return Text2D_1.defaultFontColorProperty = pi; })
  10477. ], Text2D.prototype, "defaultFontColor", null);
  10478. __decorate([
  10479. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 3, function (pi) { return Text2D_1.textProperty = pi; }, false, true)
  10480. ], Text2D.prototype, "text", null);
  10481. __decorate([
  10482. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 4, function (pi) { return Text2D_1.sizeProperty = pi; })
  10483. ], Text2D.prototype, "size", null);
  10484. __decorate([
  10485. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 5, function (pi) { return Text2D_1.fontSuperSampleProperty = pi; }, false, false)
  10486. ], Text2D.prototype, "fontSuperSample", null);
  10487. __decorate([
  10488. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 6, function (pi) { return Text2D_1.fontSuperSampleProperty = pi; }, false, false)
  10489. ], Text2D.prototype, "fontSignedDistanceField", null);
  10490. Text2D = Text2D_1 = __decorate([
  10491. BABYLON.className("Text2D", "BABYLON")
  10492. ], Text2D);
  10493. BABYLON.Text2D = Text2D;
  10494. var Text2D_1;
  10495. })(BABYLON || (BABYLON = {}));
  10496. //# sourceMappingURL=babylon.text2d.js.map
  10497. var __extends = (this && this.__extends) || function (d, b) {
  10498. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  10499. function __() { this.constructor = d; }
  10500. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10501. };
  10502. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  10503. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  10504. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  10505. 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;
  10506. return c > 3 && r && Object.defineProperty(target, key, r), r;
  10507. };
  10508. var BABYLON;
  10509. (function (BABYLON) {
  10510. var Lines2DRenderCache = (function (_super) {
  10511. __extends(Lines2DRenderCache, _super);
  10512. function Lines2DRenderCache(engine, modelKey) {
  10513. var _this = _super.call(this, engine, modelKey) || this;
  10514. _this.effectsReady = false;
  10515. _this.fillVB = null;
  10516. _this.fillIB = null;
  10517. _this.fillIndicesCount = 0;
  10518. _this.instancingFillAttributes = null;
  10519. _this.effectFill = null;
  10520. _this.effectFillInstanced = null;
  10521. _this.borderVB = null;
  10522. _this.borderIB = null;
  10523. _this.borderIndicesCount = 0;
  10524. _this.instancingBorderAttributes = null;
  10525. _this.effectBorder = null;
  10526. _this.effectBorderInstanced = null;
  10527. return _this;
  10528. }
  10529. Lines2DRenderCache.prototype.render = function (instanceInfo, context) {
  10530. // Do nothing if the shader is still loading/preparing
  10531. if (!this.effectsReady) {
  10532. if ((this.effectFill && (!this.effectFill.isReady() || (this.effectFillInstanced && !this.effectFillInstanced.isReady()))) ||
  10533. (this.effectBorder && (!this.effectBorder.isReady() || (this.effectBorderInstanced && !this.effectBorderInstanced.isReady())))) {
  10534. return false;
  10535. }
  10536. this.effectsReady = true;
  10537. }
  10538. var canvas = instanceInfo.owner.owner;
  10539. var engine = canvas.engine;
  10540. var depthFunction = 0;
  10541. if (this.effectFill && this.effectBorder) {
  10542. depthFunction = engine.getDepthFunction();
  10543. engine.setDepthFunctionToLessOrEqual();
  10544. }
  10545. var curAlphaMode = engine.getAlphaMode();
  10546. if (this.effectFill) {
  10547. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_FILLPARTID.toString());
  10548. var pid = context.groupInfoPartData[partIndex];
  10549. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  10550. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  10551. }
  10552. var effect = context.useInstancing ? this.effectFillInstanced : this.effectFill;
  10553. engine.enableEffect(effect);
  10554. engine.bindBuffersDirectly(this.fillVB, this.fillIB, [2], 2 * 4, effect);
  10555. if (context.useInstancing) {
  10556. if (!this.instancingFillAttributes) {
  10557. this.instancingFillAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_FILLPARTID, effect);
  10558. }
  10559. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  10560. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  10561. canvas._addDrawCallCount(1, context.renderMode);
  10562. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingFillAttributes);
  10563. engine.draw(true, 0, this.fillIndicesCount, count);
  10564. engine.unbindInstanceAttributes();
  10565. }
  10566. else {
  10567. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  10568. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  10569. this.setupUniforms(effect, partIndex, pid._partData, i);
  10570. engine.draw(true, 0, this.fillIndicesCount);
  10571. }
  10572. }
  10573. }
  10574. if (this.effectBorder) {
  10575. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_BORDERPARTID.toString());
  10576. var pid = context.groupInfoPartData[partIndex];
  10577. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  10578. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  10579. }
  10580. var effect = context.useInstancing ? this.effectBorderInstanced : this.effectBorder;
  10581. engine.enableEffect(effect);
  10582. engine.bindBuffersDirectly(this.borderVB, this.borderIB, [2], 2 * 4, effect);
  10583. if (context.useInstancing) {
  10584. if (!this.instancingBorderAttributes) {
  10585. this.instancingBorderAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, effect);
  10586. }
  10587. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  10588. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  10589. canvas._addDrawCallCount(1, context.renderMode);
  10590. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingBorderAttributes);
  10591. engine.draw(true, 0, this.borderIndicesCount, count);
  10592. engine.unbindInstanceAttributes();
  10593. }
  10594. else {
  10595. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  10596. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  10597. this.setupUniforms(effect, partIndex, pid._partData, i);
  10598. engine.draw(true, 0, this.borderIndicesCount);
  10599. }
  10600. }
  10601. }
  10602. engine.setAlphaMode(curAlphaMode, true);
  10603. if (this.effectFill && this.effectBorder) {
  10604. engine.setDepthFunction(depthFunction);
  10605. }
  10606. return true;
  10607. };
  10608. Lines2DRenderCache.prototype.dispose = function () {
  10609. if (!_super.prototype.dispose.call(this)) {
  10610. return false;
  10611. }
  10612. if (this.fillVB) {
  10613. this._engine._releaseBuffer(this.fillVB);
  10614. this.fillVB = null;
  10615. }
  10616. if (this.fillIB) {
  10617. this._engine._releaseBuffer(this.fillIB);
  10618. this.fillIB = null;
  10619. }
  10620. this.effectFill = null;
  10621. this.effectFillInstanced = null;
  10622. this.effectBorder = null;
  10623. this.effectBorderInstanced = null;
  10624. if (this.borderVB) {
  10625. this._engine._releaseBuffer(this.borderVB);
  10626. this.borderVB = null;
  10627. }
  10628. if (this.borderIB) {
  10629. this._engine._releaseBuffer(this.borderIB);
  10630. this.borderIB = null;
  10631. }
  10632. return true;
  10633. };
  10634. return Lines2DRenderCache;
  10635. }(BABYLON.ModelRenderCache));
  10636. BABYLON.Lines2DRenderCache = Lines2DRenderCache;
  10637. var Lines2DInstanceData = (function (_super) {
  10638. __extends(Lines2DInstanceData, _super);
  10639. function Lines2DInstanceData(partId) {
  10640. return _super.call(this, partId, 1) || this;
  10641. }
  10642. Object.defineProperty(Lines2DInstanceData.prototype, "boundingMin", {
  10643. get: function () {
  10644. return null;
  10645. },
  10646. set: function (value) {
  10647. },
  10648. enumerable: true,
  10649. configurable: true
  10650. });
  10651. Object.defineProperty(Lines2DInstanceData.prototype, "boundingMax", {
  10652. get: function () {
  10653. return null;
  10654. },
  10655. set: function (value) {
  10656. },
  10657. enumerable: true,
  10658. configurable: true
  10659. });
  10660. return Lines2DInstanceData;
  10661. }(BABYLON.Shape2DInstanceData));
  10662. __decorate([
  10663. BABYLON.instanceData(BABYLON.Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  10664. ], Lines2DInstanceData.prototype, "boundingMin", null);
  10665. __decorate([
  10666. BABYLON.instanceData(BABYLON.Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  10667. ], Lines2DInstanceData.prototype, "boundingMax", null);
  10668. BABYLON.Lines2DInstanceData = Lines2DInstanceData;
  10669. var Lines2D = Lines2D_1 = (function (_super) {
  10670. __extends(Lines2D, _super);
  10671. /**
  10672. * Create an 2D Lines Shape primitive. The defined lines may be opened or closed (see below)
  10673. * @param points an array that describe the points to use to draw the line, must contain at least two entries.
  10674. * @param settings a combination of settings, possible ones are
  10675. * - 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)
  10676. * - children: an array of direct children
  10677. * - id a text identifier, for information purpose
  10678. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  10679. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  10680. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  10681. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  10682. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  10683. * - zOrder: override the zOrder with the specified value
  10684. * - origin: define the normalized origin point location, default [0.5;0.5]
  10685. * - 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.
  10686. * - 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.
  10687. * - 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.
  10688. * - 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.
  10689. * - 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)
  10690. * - 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)
  10691. * - borderThickness: the thickness of the drawn border, default is 1.
  10692. * - isVisible: true if the primitive must be visible, false for hidden. Default is true.
  10693. * - 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.
  10694. * - 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.
  10695. * - 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!
  10696. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10697. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10698. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10699. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10700. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  10701. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  10702. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  10703. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  10704. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10705. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10706. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10707. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10708. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  10709. */
  10710. function Lines2D(points, settings) {
  10711. var _this;
  10712. if (!settings) {
  10713. settings = {};
  10714. }
  10715. _this = _super.call(this, settings) || this;
  10716. _this._fillVB = null;
  10717. _this._fillIB = null;
  10718. _this._borderVB = null;
  10719. _this._borderIB = null;
  10720. _this._size = BABYLON.Size.Zero();
  10721. _this._boundingMin = null;
  10722. _this._boundingMax = null;
  10723. var fillThickness = (settings.fillThickness == null) ? 1 : settings.fillThickness;
  10724. var startCap = (settings.startCap == null) ? 0 : settings.startCap;
  10725. var endCap = (settings.endCap == null) ? 0 : settings.endCap;
  10726. var closed = (settings.closed == null) ? false : settings.closed;
  10727. _this.points = points;
  10728. _this.fillThickness = fillThickness;
  10729. _this.startCap = startCap;
  10730. _this.endCap = endCap;
  10731. _this.closed = closed;
  10732. return _this;
  10733. }
  10734. Object.defineProperty(Lines2D, "NoCap", {
  10735. /**
  10736. * No Cap to apply on the extremity
  10737. */
  10738. get: function () { return Lines2D_1._noCap; },
  10739. enumerable: true,
  10740. configurable: true
  10741. });
  10742. Object.defineProperty(Lines2D, "RoundCap", {
  10743. /**
  10744. * A round cap, will use the line thickness as diameter
  10745. */
  10746. get: function () { return Lines2D_1._roundCap; },
  10747. enumerable: true,
  10748. configurable: true
  10749. });
  10750. Object.defineProperty(Lines2D, "TriangleCap", {
  10751. /**
  10752. * Creates a triangle at the extremity.
  10753. */
  10754. get: function () { return Lines2D_1._triangleCap; },
  10755. enumerable: true,
  10756. configurable: true
  10757. });
  10758. Object.defineProperty(Lines2D, "SquareAnchorCap", {
  10759. /**
  10760. * Creates a Square anchor at the extremity, the square size is twice the thickness of the line
  10761. */
  10762. get: function () { return Lines2D_1._squareAnchorCap; },
  10763. enumerable: true,
  10764. configurable: true
  10765. });
  10766. Object.defineProperty(Lines2D, "RoundAnchorCap", {
  10767. /**
  10768. * Creates a round anchor at the extremity, the diameter is twice the thickness of the line
  10769. */
  10770. get: function () { return Lines2D_1._roundAnchorCap; },
  10771. enumerable: true,
  10772. configurable: true
  10773. });
  10774. Object.defineProperty(Lines2D, "DiamondAnchorCap", {
  10775. /**
  10776. * Creates a diamond anchor at the extremity.
  10777. */
  10778. get: function () { return Lines2D_1._diamondAnchorCap; },
  10779. enumerable: true,
  10780. configurable: true
  10781. });
  10782. Object.defineProperty(Lines2D, "ArrowCap", {
  10783. /**
  10784. * Creates an arrow anchor at the extremity. the arrow base size is twice the thickness of the line
  10785. */
  10786. get: function () { return Lines2D_1._arrowCap; },
  10787. enumerable: true,
  10788. configurable: true
  10789. });
  10790. Object.defineProperty(Lines2D.prototype, "points", {
  10791. get: function () {
  10792. return this._points;
  10793. },
  10794. set: function (value) {
  10795. this._points = value;
  10796. this._contour = null;
  10797. this._boundingBoxDirty();
  10798. },
  10799. enumerable: true,
  10800. configurable: true
  10801. });
  10802. Object.defineProperty(Lines2D.prototype, "fillThickness", {
  10803. get: function () {
  10804. return this._fillThickness;
  10805. },
  10806. set: function (value) {
  10807. this._fillThickness = value;
  10808. },
  10809. enumerable: true,
  10810. configurable: true
  10811. });
  10812. Object.defineProperty(Lines2D.prototype, "closed", {
  10813. get: function () {
  10814. return this._closed;
  10815. },
  10816. set: function (value) {
  10817. this._closed = value;
  10818. },
  10819. enumerable: true,
  10820. configurable: true
  10821. });
  10822. Object.defineProperty(Lines2D.prototype, "startCap", {
  10823. get: function () {
  10824. return this._startCap;
  10825. },
  10826. set: function (value) {
  10827. this._startCap = value;
  10828. },
  10829. enumerable: true,
  10830. configurable: true
  10831. });
  10832. Object.defineProperty(Lines2D.prototype, "endCap", {
  10833. get: function () {
  10834. return this._endCap;
  10835. },
  10836. set: function (value) {
  10837. this._endCap = value;
  10838. },
  10839. enumerable: true,
  10840. configurable: true
  10841. });
  10842. Lines2D.prototype.levelIntersect = function (intersectInfo) {
  10843. var _this = this;
  10844. if (this._contour == null) {
  10845. this._computeLines2D();
  10846. }
  10847. var pl = this.points.length;
  10848. var l = this.closed ? pl + 1 : pl;
  10849. var p = intersectInfo._localPickPosition;
  10850. this.transformPointWithOriginToRef(this._contour[0], null, Lines2D_1._prevA);
  10851. this.transformPointWithOriginToRef(this._contour[1], null, Lines2D_1._prevB);
  10852. for (var i = 1; i < l; i++) {
  10853. this.transformPointWithOriginToRef(this._contour[(i % pl) * 2 + 0], null, Lines2D_1._curA);
  10854. this.transformPointWithOriginToRef(this._contour[(i % pl) * 2 + 1], null, Lines2D_1._curB);
  10855. if (BABYLON.Vector2.PointInTriangle(p, Lines2D_1._prevA, Lines2D_1._prevB, Lines2D_1._curA)) {
  10856. return true;
  10857. }
  10858. if (BABYLON.Vector2.PointInTriangle(p, Lines2D_1._curA, Lines2D_1._prevB, Lines2D_1._curB)) {
  10859. return true;
  10860. }
  10861. Lines2D_1._prevA.x = Lines2D_1._curA.x;
  10862. Lines2D_1._prevA.y = Lines2D_1._curA.y;
  10863. Lines2D_1._prevB.x = Lines2D_1._curB.x;
  10864. Lines2D_1._prevB.y = Lines2D_1._curB.y;
  10865. }
  10866. var capIntersect = function (tri, points) {
  10867. var l = tri.length;
  10868. for (var i = 0; i < l; i += 3) {
  10869. Lines2D_1._curA.x = points[tri[i + 0] * 2 + 0];
  10870. Lines2D_1._curA.y = points[tri[i + 0] * 2 + 1];
  10871. _this.transformPointWithOriginToRef(Lines2D_1._curA, null, Lines2D_1._curB);
  10872. Lines2D_1._curA.x = points[tri[i + 1] * 2 + 0];
  10873. Lines2D_1._curA.y = points[tri[i + 1] * 2 + 1];
  10874. _this.transformPointWithOriginToRef(Lines2D_1._curA, null, Lines2D_1._prevA);
  10875. Lines2D_1._curA.x = points[tri[i + 2] * 2 + 0];
  10876. Lines2D_1._curA.y = points[tri[i + 2] * 2 + 1];
  10877. _this.transformPointWithOriginToRef(Lines2D_1._curA, null, Lines2D_1._prevB);
  10878. if (BABYLON.Vector2.PointInTriangle(p, Lines2D_1._prevA, Lines2D_1._prevB, Lines2D_1._curB)) {
  10879. return true;
  10880. }
  10881. }
  10882. return false;
  10883. };
  10884. if (this._startCapTriIndices) {
  10885. if (this._startCapTriIndices && capIntersect(this._startCapTriIndices, this._startCapContour)) {
  10886. return true;
  10887. }
  10888. if (this._endCapTriIndices && capIntersect(this._endCapTriIndices, this._endCapContour)) {
  10889. return true;
  10890. }
  10891. }
  10892. return false;
  10893. };
  10894. Object.defineProperty(Lines2D.prototype, "boundingMin", {
  10895. get: function () {
  10896. if (!this._boundingMin) {
  10897. this._computeLines2D();
  10898. }
  10899. return this._boundingMin;
  10900. },
  10901. enumerable: true,
  10902. configurable: true
  10903. });
  10904. Object.defineProperty(Lines2D.prototype, "boundingMax", {
  10905. get: function () {
  10906. if (!this._boundingMax) {
  10907. this._computeLines2D();
  10908. }
  10909. return this._boundingMax;
  10910. },
  10911. enumerable: true,
  10912. configurable: true
  10913. });
  10914. Lines2D.prototype.getUsedShaderCategories = function (dataPart) {
  10915. var res = _super.prototype.getUsedShaderCategories.call(this, dataPart);
  10916. // Remove the BORDER category, we don't use it in the VertexShader
  10917. var i = res.indexOf(BABYLON.Shape2D.SHAPE2D_CATEGORY_BORDER);
  10918. if (i !== -1) {
  10919. res.splice(i, 1);
  10920. }
  10921. return res;
  10922. };
  10923. Lines2D.prototype.updateLevelBoundingInfo = function () {
  10924. if (!this._boundingMin) {
  10925. this._computeLines2D();
  10926. }
  10927. BABYLON.BoundingInfo2D.CreateFromMinMaxToRef(this._boundingMin.x, this._boundingMax.x, this._boundingMin.y, this._boundingMax.y, this._levelBoundingInfo);
  10928. };
  10929. Lines2D.prototype.createModelRenderCache = function (modelKey) {
  10930. var renderCache = new Lines2DRenderCache(this.owner.engine, modelKey);
  10931. return renderCache;
  10932. };
  10933. ///////////////////////////////////////////////////////////////////////////////////
  10934. // Methods for Lines building
  10935. Lines2D.prototype._perp = function (v, res) {
  10936. res.x = v.y;
  10937. res.y = -v.x;
  10938. };
  10939. ;
  10940. Lines2D.prototype._direction = function (a, b, res) {
  10941. a.subtractToRef(b, res);
  10942. res.normalize();
  10943. };
  10944. Lines2D.prototype._computeMiter = function (tangent, miter, a, b) {
  10945. a.addToRef(b, tangent);
  10946. tangent.normalize();
  10947. miter.x = -tangent.y;
  10948. miter.y = tangent.x;
  10949. Lines2D_1._miterTps.x = -a.y;
  10950. Lines2D_1._miterTps.y = a.x;
  10951. return 1 / BABYLON.Vector2.Dot(miter, Lines2D_1._miterTps);
  10952. };
  10953. Lines2D.prototype._intersect = function (x1, y1, x2, y2, x3, y3, x4, y4) {
  10954. var d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
  10955. if (d === 0)
  10956. return false;
  10957. var xi = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d; // Intersection point is xi/yi, just in case...
  10958. //let yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d; // That's why I left it commented
  10959. if (xi < Math.min(x1, x2) || xi > Math.max(x1, x2))
  10960. return false;
  10961. if (xi < Math.min(x3, x4) || xi > Math.max(x3, x4))
  10962. return false;
  10963. return true;
  10964. };
  10965. Lines2D.prototype._updateMinMax = function (array, offset) {
  10966. if (offset >= array.length) {
  10967. return;
  10968. }
  10969. this._boundingMin.x = Math.min(this._boundingMin.x, array[offset]);
  10970. this._boundingMax.x = Math.max(this._boundingMax.x, array[offset]);
  10971. this._boundingMin.y = Math.min(this._boundingMin.y, array[offset + 1]);
  10972. this._boundingMax.y = Math.max(this._boundingMax.y, array[offset + 1]);
  10973. };
  10974. Lines2D.prototype._store = function (array, contour, index, max, p, n, halfThickness, borderThickness, detectFlip) {
  10975. var borderMode = borderThickness != null && !isNaN(borderThickness);
  10976. var off = index * (borderMode ? 8 : 4);
  10977. // 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)
  10978. if (off >= array.length) {
  10979. return;
  10980. }
  10981. // Store start/end normal, we need it for the cap construction
  10982. if (index === 0) {
  10983. this._perp(n, Lines2D_1._startDir);
  10984. }
  10985. else if (index === max - 1) {
  10986. this._perp(n, Lines2D_1._endDir);
  10987. Lines2D_1._endDir.x *= -1;
  10988. Lines2D_1._endDir.y *= -1;
  10989. }
  10990. var swap = false;
  10991. array[off + 0] = p.x + n.x * halfThickness;
  10992. array[off + 1] = p.y + n.y * halfThickness;
  10993. array[off + 2] = p.x + n.x * -halfThickness;
  10994. array[off + 3] = p.y + n.y * -halfThickness;
  10995. this._updateMinMax(array, off);
  10996. this._updateMinMax(array, off + 2);
  10997. // If an index is given we check if the two segments formed between [index+0;detectFlip+0] and [index+2;detectFlip+2] intersect themselves.
  10998. // 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
  10999. if (detectFlip != 0) {
  11000. // Flip if intersect
  11001. var flipOff = detectFlip * (borderMode ? 8 : 4);
  11002. 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])) {
  11003. swap = true;
  11004. var tps = array[off + 0];
  11005. array[off + 0] = array[off + 2];
  11006. array[off + 2] = tps;
  11007. tps = array[off + 1];
  11008. array[off + 1] = array[off + 3];
  11009. array[off + 3] = tps;
  11010. }
  11011. }
  11012. if (borderMode) {
  11013. var t = halfThickness + borderThickness;
  11014. array[off + 4] = p.x + n.x * (swap ? -t : t);
  11015. array[off + 5] = p.y + n.y * (swap ? -t : t);
  11016. array[off + 6] = p.x + n.x * (swap ? t : -t);
  11017. array[off + 7] = p.y + n.y * (swap ? t : -t);
  11018. this._updateMinMax(array, off + 4);
  11019. this._updateMinMax(array, off + 6);
  11020. }
  11021. if (contour) {
  11022. off += borderMode ? 4 : 0;
  11023. contour.push(new BABYLON.Vector2(array[off + 0], array[off + 1]));
  11024. contour.push(new BABYLON.Vector2(array[off + 2], array[off + 3]));
  11025. }
  11026. };
  11027. Lines2D.prototype._getCapSize = function (type, border) {
  11028. if (border === void 0) { border = false; }
  11029. var sd = Lines2D_1._roundCapSubDiv;
  11030. // If no array given, we call this to get the size
  11031. var vbsize = 0, ibsize = 0;
  11032. switch (type) {
  11033. case Lines2D_1.NoCap:
  11034. {
  11035. // If the line is not close and we're computing border, we add the size to generate the edge border
  11036. if (!this.closed && border) {
  11037. vbsize = 4;
  11038. ibsize = 6;
  11039. }
  11040. else {
  11041. vbsize = ibsize = 0;
  11042. }
  11043. break;
  11044. }
  11045. case Lines2D_1.RoundCap:
  11046. {
  11047. if (border) {
  11048. vbsize = sd;
  11049. ibsize = (sd - 2) * 3;
  11050. }
  11051. else {
  11052. vbsize = (sd / 2) + 1;
  11053. ibsize = (sd / 2) * 3;
  11054. }
  11055. break;
  11056. }
  11057. case Lines2D_1.ArrowCap:
  11058. {
  11059. if (border) {
  11060. vbsize = 12;
  11061. ibsize = 24;
  11062. }
  11063. else {
  11064. vbsize = 3;
  11065. ibsize = 3;
  11066. }
  11067. break;
  11068. }
  11069. case Lines2D_1.TriangleCap:
  11070. {
  11071. if (border) {
  11072. vbsize = 6;
  11073. ibsize = 12;
  11074. }
  11075. else {
  11076. vbsize = 3;
  11077. ibsize = 3;
  11078. }
  11079. break;
  11080. }
  11081. case Lines2D_1.DiamondAnchorCap:
  11082. {
  11083. if (border) {
  11084. vbsize = 10;
  11085. ibsize = 24;
  11086. }
  11087. else {
  11088. vbsize = 5;
  11089. ibsize = 9;
  11090. }
  11091. break;
  11092. }
  11093. case Lines2D_1.SquareAnchorCap:
  11094. {
  11095. if (border) {
  11096. vbsize = 12;
  11097. ibsize = 30;
  11098. }
  11099. else {
  11100. vbsize = 4;
  11101. ibsize = 6;
  11102. }
  11103. break;
  11104. }
  11105. case Lines2D_1.RoundAnchorCap:
  11106. {
  11107. if (border) {
  11108. vbsize = sd * 2;
  11109. ibsize = (sd - 1) * 6;
  11110. }
  11111. else {
  11112. vbsize = sd + 1;
  11113. ibsize = (sd + 1) * 3;
  11114. }
  11115. break;
  11116. }
  11117. }
  11118. return { vbsize: vbsize * 2, ibsize: ibsize };
  11119. };
  11120. Lines2D.prototype._storeVertex = function (vb, baseOffset, index, basePos, rotation, vertex, contour) {
  11121. var c = Math.cos(rotation);
  11122. var s = Math.sin(rotation);
  11123. Lines2D_1._tpsV.x = (c * vertex.x) + (-s * vertex.y) + basePos.x;
  11124. Lines2D_1._tpsV.y = (s * vertex.x) + (c * vertex.y) + basePos.y;
  11125. var offset = baseOffset + (index * 2);
  11126. vb[offset + 0] = Lines2D_1._tpsV.x;
  11127. vb[offset + 1] = Lines2D_1._tpsV.y;
  11128. if (contour) {
  11129. contour.push(Lines2D_1._tpsV.x);
  11130. contour.push(Lines2D_1._tpsV.y);
  11131. }
  11132. this._updateMinMax(vb, offset);
  11133. return (baseOffset + index * 2) / 2;
  11134. };
  11135. Lines2D.prototype._storeIndex = function (ib, baseOffset, index, vertexIndex) {
  11136. ib[baseOffset + index] = vertexIndex;
  11137. };
  11138. Lines2D.prototype._buildCap = function (vb, vbi, ib, ibi, pos, thickness, borderThickness, type, capDir, contour) {
  11139. // 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
  11140. var sd = Lines2D_1._roundCapSubDiv;
  11141. var dir = new BABYLON.Vector2(1, 0);
  11142. var angle = Math.atan2(capDir.y, capDir.x) - Math.atan2(dir.y, dir.x);
  11143. var ht = thickness / 2;
  11144. var t = thickness;
  11145. var borderMode = borderThickness != null;
  11146. var bt = borderThickness;
  11147. switch (type) {
  11148. case Lines2D_1.NoCap:
  11149. if (borderMode && !this.closed) {
  11150. var vi = 0;
  11151. var ii = 0;
  11152. var v1 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, ht + bt), contour);
  11153. var v2 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(bt, ht + bt), contour);
  11154. var v3 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(bt, -(ht + bt)), contour);
  11155. var v4 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -(ht + bt)), contour);
  11156. this._storeIndex(ib, ibi, ii++, v1);
  11157. this._storeIndex(ib, ibi, ii++, v2);
  11158. this._storeIndex(ib, ibi, ii++, v3);
  11159. this._storeIndex(ib, ibi, ii++, v1);
  11160. this._storeIndex(ib, ibi, ii++, v3);
  11161. this._storeIndex(ib, ibi, ii++, v4);
  11162. }
  11163. break;
  11164. case Lines2D_1.ArrowCap:
  11165. ht *= 2;
  11166. case Lines2D_1.TriangleCap:
  11167. {
  11168. if (borderMode) {
  11169. var f = type === Lines2D_1.TriangleCap ? bt : Math.sqrt(bt * bt * 2);
  11170. var v1 = this._storeVertex(vb, vbi, 0, pos, angle, new BABYLON.Vector2(0, ht), null);
  11171. var v2 = this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(ht, 0), null);
  11172. var v3 = this._storeVertex(vb, vbi, 2, pos, angle, new BABYLON.Vector2(0, -ht), null);
  11173. var v4 = this._storeVertex(vb, vbi, 3, pos, angle, new BABYLON.Vector2(0, ht + f), contour);
  11174. var v5 = this._storeVertex(vb, vbi, 4, pos, angle, new BABYLON.Vector2(ht + f, 0), contour);
  11175. var v6 = this._storeVertex(vb, vbi, 5, pos, angle, new BABYLON.Vector2(0, -(ht + f)), contour);
  11176. var ii = 0;
  11177. this._storeIndex(ib, ibi, ii++, v1);
  11178. this._storeIndex(ib, ibi, ii++, v4);
  11179. this._storeIndex(ib, ibi, ii++, v5);
  11180. this._storeIndex(ib, ibi, ii++, v1);
  11181. this._storeIndex(ib, ibi, ii++, v5);
  11182. this._storeIndex(ib, ibi, ii++, v2);
  11183. this._storeIndex(ib, ibi, ii++, v6);
  11184. this._storeIndex(ib, ibi, ii++, v3);
  11185. this._storeIndex(ib, ibi, ii++, v2);
  11186. this._storeIndex(ib, ibi, ii++, v6);
  11187. this._storeIndex(ib, ibi, ii++, v2);
  11188. this._storeIndex(ib, ibi, ii++, v5);
  11189. if (type === Lines2D_1.ArrowCap) {
  11190. var rht = thickness / 2;
  11191. var v10 = this._storeVertex(vb, vbi, 9, pos, angle, new BABYLON.Vector2(0, -(rht + bt)), null);
  11192. var v12 = this._storeVertex(vb, vbi, 11, pos, angle, new BABYLON.Vector2(-bt, -(ht + f)), contour);
  11193. var v11 = this._storeVertex(vb, vbi, 10, pos, angle, new BABYLON.Vector2(-bt, -(rht + bt)), contour);
  11194. var v7 = this._storeVertex(vb, vbi, 6, pos, angle, new BABYLON.Vector2(0, rht + bt), null);
  11195. var v8 = this._storeVertex(vb, vbi, 7, pos, angle, new BABYLON.Vector2(-bt, rht + bt), contour);
  11196. var v9 = this._storeVertex(vb, vbi, 8, pos, angle, new BABYLON.Vector2(-bt, ht + f), contour);
  11197. this._storeIndex(ib, ibi, ii++, v7);
  11198. this._storeIndex(ib, ibi, ii++, v8);
  11199. this._storeIndex(ib, ibi, ii++, v9);
  11200. this._storeIndex(ib, ibi, ii++, v7);
  11201. this._storeIndex(ib, ibi, ii++, v9);
  11202. this._storeIndex(ib, ibi, ii++, v4);
  11203. this._storeIndex(ib, ibi, ii++, v10);
  11204. this._storeIndex(ib, ibi, ii++, v12);
  11205. this._storeIndex(ib, ibi, ii++, v11);
  11206. this._storeIndex(ib, ibi, ii++, v10);
  11207. this._storeIndex(ib, ibi, ii++, v6);
  11208. this._storeIndex(ib, ibi, ii++, v12);
  11209. }
  11210. }
  11211. else {
  11212. var v1 = this._storeVertex(vb, vbi, 0, pos, angle, new BABYLON.Vector2(0, ht), contour);
  11213. var v2 = this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(ht, 0), contour);
  11214. var v3 = this._storeVertex(vb, vbi, 2, pos, angle, new BABYLON.Vector2(0, -ht), contour);
  11215. this._storeIndex(ib, ibi, 0, v1);
  11216. this._storeIndex(ib, ibi, 1, v2);
  11217. this._storeIndex(ib, ibi, 2, v3);
  11218. }
  11219. break;
  11220. }
  11221. case Lines2D_1.RoundCap:
  11222. {
  11223. if (borderMode) {
  11224. var curA = -Math.PI / 2;
  11225. var incA = Math.PI / (sd / 2 - 1);
  11226. var ii = 0;
  11227. for (var i = 0; i < (sd / 2); i++) {
  11228. var v1 = this._storeVertex(vb, vbi, i * 2 + 0, pos, angle, new BABYLON.Vector2(Math.cos(curA) * ht, Math.sin(curA) * ht), null);
  11229. 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);
  11230. if (i > 0) {
  11231. this._storeIndex(ib, ibi, ii++, v1 - 2);
  11232. this._storeIndex(ib, ibi, ii++, v2 - 2);
  11233. this._storeIndex(ib, ibi, ii++, v2);
  11234. this._storeIndex(ib, ibi, ii++, v1 - 2);
  11235. this._storeIndex(ib, ibi, ii++, v2);
  11236. this._storeIndex(ib, ibi, ii++, v1);
  11237. }
  11238. curA += incA;
  11239. }
  11240. }
  11241. else {
  11242. var c = this._storeVertex(vb, vbi, 0, pos, angle, new BABYLON.Vector2(0, 0), null);
  11243. var curA = -Math.PI / 2;
  11244. var incA = Math.PI / (sd / 2 - 1);
  11245. this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(Math.cos(curA) * ht, Math.sin(curA) * ht), null);
  11246. curA += incA;
  11247. for (var i = 1; i < (sd / 2); i++) {
  11248. var v2 = this._storeVertex(vb, vbi, i + 1, pos, angle, new BABYLON.Vector2(Math.cos(curA) * ht, Math.sin(curA) * ht), contour);
  11249. this._storeIndex(ib, ibi, i * 3 + 0, c);
  11250. this._storeIndex(ib, ibi, i * 3 + 1, v2 - 1);
  11251. this._storeIndex(ib, ibi, i * 3 + 2, v2);
  11252. curA += incA;
  11253. }
  11254. }
  11255. break;
  11256. }
  11257. case Lines2D_1.SquareAnchorCap:
  11258. {
  11259. var vi = 0;
  11260. var c = borderMode ? null : contour;
  11261. var v1 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, t), c);
  11262. var v2 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2, t), c);
  11263. var v3 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2, -t), c);
  11264. var v4 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -t), c);
  11265. if (borderMode) {
  11266. var v5 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, ht + bt), null);
  11267. var v6 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, ht + bt), contour);
  11268. var v7 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, t + bt), contour);
  11269. var v8 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2 + bt, t + bt), contour);
  11270. var v9 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2 + bt, -(t + bt)), contour);
  11271. var v10 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, -(t + bt)), contour);
  11272. var v11 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, -(ht + bt)), contour);
  11273. var v12 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -(ht + bt)), null);
  11274. var ii = 0;
  11275. this._storeIndex(ib, ibi, ii++, v6);
  11276. this._storeIndex(ib, ibi, ii++, v1);
  11277. this._storeIndex(ib, ibi, ii++, v5);
  11278. this._storeIndex(ib, ibi, ii++, v6);
  11279. this._storeIndex(ib, ibi, ii++, v7);
  11280. this._storeIndex(ib, ibi, ii++, v1);
  11281. this._storeIndex(ib, ibi, ii++, v1);
  11282. this._storeIndex(ib, ibi, ii++, v7);
  11283. this._storeIndex(ib, ibi, ii++, v8);
  11284. this._storeIndex(ib, ibi, ii++, v1);
  11285. this._storeIndex(ib, ibi, ii++, v8);
  11286. this._storeIndex(ib, ibi, ii++, v2);
  11287. this._storeIndex(ib, ibi, ii++, v2);
  11288. this._storeIndex(ib, ibi, ii++, v8);
  11289. this._storeIndex(ib, ibi, ii++, v9);
  11290. this._storeIndex(ib, ibi, ii++, v2);
  11291. this._storeIndex(ib, ibi, ii++, v9);
  11292. this._storeIndex(ib, ibi, ii++, v3);
  11293. this._storeIndex(ib, ibi, ii++, v3);
  11294. this._storeIndex(ib, ibi, ii++, v9);
  11295. this._storeIndex(ib, ibi, ii++, v10);
  11296. this._storeIndex(ib, ibi, ii++, v3);
  11297. this._storeIndex(ib, ibi, ii++, v10);
  11298. this._storeIndex(ib, ibi, ii++, v4);
  11299. this._storeIndex(ib, ibi, ii++, v10);
  11300. this._storeIndex(ib, ibi, ii++, v11);
  11301. this._storeIndex(ib, ibi, ii++, v4);
  11302. this._storeIndex(ib, ibi, ii++, v11);
  11303. this._storeIndex(ib, ibi, ii++, v12);
  11304. this._storeIndex(ib, ibi, ii++, v4);
  11305. }
  11306. else {
  11307. this._storeIndex(ib, ibi, 0, v1);
  11308. this._storeIndex(ib, ibi, 1, v2);
  11309. this._storeIndex(ib, ibi, 2, v3);
  11310. this._storeIndex(ib, ibi, 3, v1);
  11311. this._storeIndex(ib, ibi, 4, v3);
  11312. this._storeIndex(ib, ibi, 5, v4);
  11313. }
  11314. break;
  11315. }
  11316. case Lines2D_1.RoundAnchorCap:
  11317. {
  11318. var cpos = Math.sqrt(t * t - ht * ht);
  11319. var center = new BABYLON.Vector2(cpos, 0);
  11320. var curA = BABYLON.Tools.ToRadians(-150);
  11321. var incA = BABYLON.Tools.ToRadians(300) / (sd - 1);
  11322. if (borderMode) {
  11323. var ii = 0;
  11324. for (var i = 0; i < sd; i++) {
  11325. var v1 = this._storeVertex(vb, vbi, i * 2 + 0, pos, angle, new BABYLON.Vector2(cpos + Math.cos(curA) * t, Math.sin(curA) * t), null);
  11326. 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);
  11327. if (i > 0) {
  11328. this._storeIndex(ib, ibi, ii++, v1 - 2);
  11329. this._storeIndex(ib, ibi, ii++, v2 - 2);
  11330. this._storeIndex(ib, ibi, ii++, v2);
  11331. this._storeIndex(ib, ibi, ii++, v1 - 2);
  11332. this._storeIndex(ib, ibi, ii++, v2);
  11333. this._storeIndex(ib, ibi, ii++, v1);
  11334. }
  11335. curA += incA;
  11336. }
  11337. }
  11338. else {
  11339. var c = this._storeVertex(vb, vbi, 0, pos, angle, center, null);
  11340. this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(cpos + Math.cos(curA) * t, Math.sin(curA) * t), null);
  11341. curA += incA;
  11342. for (var i = 1; i < sd; i++) {
  11343. var v2 = this._storeVertex(vb, vbi, i + 1, pos, angle, new BABYLON.Vector2(cpos + Math.cos(curA) * t, Math.sin(curA) * t), contour);
  11344. this._storeIndex(ib, ibi, i * 3 + 0, c);
  11345. this._storeIndex(ib, ibi, i * 3 + 1, v2 - 1);
  11346. this._storeIndex(ib, ibi, i * 3 + 2, v2);
  11347. curA += incA;
  11348. }
  11349. this._storeIndex(ib, ibi, sd * 3 + 0, c);
  11350. this._storeIndex(ib, ibi, sd * 3 + 1, c + 1);
  11351. this._storeIndex(ib, ibi, sd * 3 + 2, c + sd);
  11352. }
  11353. break;
  11354. }
  11355. case Lines2D_1.DiamondAnchorCap:
  11356. {
  11357. var vi = 0;
  11358. var c = borderMode ? null : contour;
  11359. var v1 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, ht), c);
  11360. var v2 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, t), c);
  11361. var v3 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht * 3, 0), c);
  11362. var v4 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, -t), c);
  11363. var v5 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -ht), c);
  11364. if (borderMode) {
  11365. var f = Math.sqrt(bt * bt * 2);
  11366. var v6 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-f, ht), contour);
  11367. var v7 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, t + f), contour);
  11368. var v8 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht * 3 + f, 0), contour);
  11369. var v9 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, -(t + f)), contour);
  11370. var v10 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-f, -ht), contour);
  11371. var ii = 0;
  11372. this._storeIndex(ib, ibi, ii++, v6);
  11373. this._storeIndex(ib, ibi, ii++, v7);
  11374. this._storeIndex(ib, ibi, ii++, v1);
  11375. this._storeIndex(ib, ibi, ii++, v1);
  11376. this._storeIndex(ib, ibi, ii++, v7);
  11377. this._storeIndex(ib, ibi, ii++, v2);
  11378. this._storeIndex(ib, ibi, ii++, v2);
  11379. this._storeIndex(ib, ibi, ii++, v7);
  11380. this._storeIndex(ib, ibi, ii++, v8);
  11381. this._storeIndex(ib, ibi, ii++, v2);
  11382. this._storeIndex(ib, ibi, ii++, v8);
  11383. this._storeIndex(ib, ibi, ii++, v3);
  11384. this._storeIndex(ib, ibi, ii++, v3);
  11385. this._storeIndex(ib, ibi, ii++, v8);
  11386. this._storeIndex(ib, ibi, ii++, v9);
  11387. this._storeIndex(ib, ibi, ii++, v3);
  11388. this._storeIndex(ib, ibi, ii++, v9);
  11389. this._storeIndex(ib, ibi, ii++, v4);
  11390. this._storeIndex(ib, ibi, ii++, v4);
  11391. this._storeIndex(ib, ibi, ii++, v9);
  11392. this._storeIndex(ib, ibi, ii++, v10);
  11393. this._storeIndex(ib, ibi, ii++, v4);
  11394. this._storeIndex(ib, ibi, ii++, v10);
  11395. this._storeIndex(ib, ibi, ii++, v5);
  11396. }
  11397. else {
  11398. this._storeIndex(ib, ibi, 0, v1);
  11399. this._storeIndex(ib, ibi, 1, v2);
  11400. this._storeIndex(ib, ibi, 2, v3);
  11401. this._storeIndex(ib, ibi, 3, v1);
  11402. this._storeIndex(ib, ibi, 4, v3);
  11403. this._storeIndex(ib, ibi, 5, v5);
  11404. this._storeIndex(ib, ibi, 6, v5);
  11405. this._storeIndex(ib, ibi, 7, v3);
  11406. this._storeIndex(ib, ibi, 8, v4);
  11407. }
  11408. break;
  11409. }
  11410. }
  11411. return null;
  11412. };
  11413. Lines2D.prototype._buildLine = function (vb, contour, ht, bt) {
  11414. var lineA = BABYLON.Vector2.Zero();
  11415. var lineB = BABYLON.Vector2.Zero();
  11416. var tangent = BABYLON.Vector2.Zero();
  11417. var miter = BABYLON.Vector2.Zero();
  11418. var curNormal = null;
  11419. if (this.closed) {
  11420. this.points.push(this.points[0]);
  11421. }
  11422. var total = this.points.length;
  11423. for (var i = 1; i < total; i++) {
  11424. var last = this.points[i - 1];
  11425. var cur = this.points[i];
  11426. var next = (i < (this.points.length - 1)) ? this.points[i + 1] : null;
  11427. this._direction(cur, last, lineA);
  11428. if (!curNormal) {
  11429. curNormal = BABYLON.Vector2.Zero();
  11430. this._perp(lineA, curNormal);
  11431. }
  11432. if (i === 1) {
  11433. this._store(vb, contour, 0, total, this.points[0], curNormal, ht, bt);
  11434. }
  11435. if (!next) {
  11436. this._perp(lineA, curNormal);
  11437. this._store(vb, contour, i, total, this.points[i], curNormal, ht, bt, i - 1);
  11438. }
  11439. else {
  11440. this._direction(next, cur, lineB);
  11441. var miterLen = this._computeMiter(tangent, miter, lineA, lineB);
  11442. this._store(vb, contour, i, total, this.points[i], miter, miterLen * ht, miterLen * bt, i - 1);
  11443. }
  11444. }
  11445. if (this.points.length > 2 && this.closed) {
  11446. var last2 = this.points[total - 2];
  11447. var cur2 = this.points[0];
  11448. var next2 = this.points[1];
  11449. this._direction(cur2, last2, lineA);
  11450. this._direction(next2, cur2, lineB);
  11451. this._perp(lineA, curNormal);
  11452. var miterLen2 = this._computeMiter(tangent, miter, lineA, lineB);
  11453. this._store(vb, null, 0, total, this.points[0], miter, miterLen2 * ht, miterLen2 * bt, 1);
  11454. // Patch contour
  11455. if (contour) {
  11456. var off = (bt == null) ? 0 : 4;
  11457. contour[0].x = vb[off + 0];
  11458. contour[0].y = vb[off + 1];
  11459. contour[1].x = vb[off + 2];
  11460. contour[1].y = vb[off + 3];
  11461. }
  11462. }
  11463. // Remove the point we added at the beginning
  11464. if (this.closed) {
  11465. this.points.splice(total - 1);
  11466. }
  11467. };
  11468. // Methods for Lines building
  11469. ///////////////////////////////////////////////////////////////////////////////////
  11470. Lines2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  11471. var renderCache = modelRenderCache;
  11472. var engine = this.owner.engine;
  11473. if (this._fillVB === null) {
  11474. this._computeLines2D();
  11475. }
  11476. // Need to create WebGL resources for fill part?
  11477. if (this.fill) {
  11478. renderCache.fillVB = engine.createVertexBuffer(this._fillVB);
  11479. renderCache.fillIB = engine.createIndexBuffer(this._fillIB);
  11480. renderCache.fillIndicesCount = this._fillIB.length;
  11481. // 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
  11482. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["position"], null, true);
  11483. if (ei) {
  11484. renderCache.effectFillInstanced = engine.createEffect("lines2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  11485. }
  11486. // Get the non instanced version
  11487. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["position"], null, false);
  11488. renderCache.effectFill = engine.createEffect("lines2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  11489. }
  11490. // Need to create WebGL resources for border part?
  11491. if (this.border) {
  11492. renderCache.borderVB = engine.createVertexBuffer(this._borderVB);
  11493. renderCache.borderIB = engine.createIndexBuffer(this._borderIB);
  11494. renderCache.borderIndicesCount = this._borderIB.length;
  11495. // 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
  11496. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["position"], null, true);
  11497. if (ei) {
  11498. renderCache.effectBorderInstanced = engine.createEffect({ vertex: "lines2d", fragment: "lines2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  11499. }
  11500. // Get the non instanced version
  11501. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["position"], null, false);
  11502. renderCache.effectBorder = engine.createEffect({ vertex: "lines2d", fragment: "lines2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  11503. }
  11504. this._fillVB = null;
  11505. this._fillIB = null;
  11506. this._borderVB = null;
  11507. this._borderIB = null;
  11508. return renderCache;
  11509. };
  11510. Lines2D.prototype._computeLines2D = function () {
  11511. // Init min/max because their being computed here
  11512. this._boundingMin = new BABYLON.Vector2(Number.MAX_VALUE, Number.MAX_VALUE);
  11513. this._boundingMax = new BABYLON.Vector2(Number.MIN_VALUE, Number.MIN_VALUE);
  11514. var contour = new Array();
  11515. var startCapContour = new Array();
  11516. var endCapContour = new Array();
  11517. // Need to create WebGL resources for fill part?
  11518. if (this.fill) {
  11519. var startCapInfo = this._getCapSize(this.startCap);
  11520. var endCapInfo = this._getCapSize(this.endCap);
  11521. var count = this.points.length;
  11522. var vbSize = (count * 2 * 2) + startCapInfo.vbsize + endCapInfo.vbsize;
  11523. this._fillVB = new Float32Array(vbSize);
  11524. var vb = this._fillVB;
  11525. var ht = this.fillThickness / 2;
  11526. var total = this.points.length;
  11527. this._buildLine(vb, this.border ? null : contour, ht);
  11528. var max = total * 2;
  11529. var triCount = (count - (this.closed ? 0 : 1)) * 2;
  11530. this._fillIB = new Float32Array(triCount * 3 + startCapInfo.ibsize + endCapInfo.ibsize);
  11531. var ib = this._fillIB;
  11532. for (var i = 0; i < triCount; i += 2) {
  11533. ib[i * 3 + 0] = i + 0;
  11534. ib[i * 3 + 1] = i + 1;
  11535. ib[i * 3 + 2] = (i + 2) % max;
  11536. ib[i * 3 + 3] = i + 1;
  11537. ib[i * 3 + 4] = (i + 3) % max;
  11538. ib[i * 3 + 5] = (i + 2) % max;
  11539. }
  11540. this._buildCap(vb, count * 2 * 2, ib, triCount * 3, this.points[0], this.fillThickness, null, this.startCap, Lines2D_1._startDir, this.border ? null : startCapContour);
  11541. 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);
  11542. }
  11543. // Need to create WebGL resources for border part?
  11544. if (this.border) {
  11545. var startCapInfo = this._getCapSize(this.startCap, true);
  11546. var endCapInfo = this._getCapSize(this.endCap, true);
  11547. var count = this.points.length;
  11548. var vbSize = (count * 2 * 2 * 2) + startCapInfo.vbsize + endCapInfo.vbsize;
  11549. this._borderVB = new Float32Array(vbSize);
  11550. var vb = this._borderVB;
  11551. var ht = this.fillThickness / 2;
  11552. var bt = this.borderThickness;
  11553. var total = this.points.length;
  11554. this._buildLine(vb, contour, ht, bt);
  11555. var max = total * 2 * 2;
  11556. var triCount = (count - (this.closed ? 0 : 1)) * 2 * 2;
  11557. this._borderIB = new Float32Array(triCount * 3 + startCapInfo.ibsize + endCapInfo.ibsize);
  11558. var ib = this._borderIB;
  11559. for (var i = 0; i < triCount; i += 4) {
  11560. ib[i * 3 + 0] = i + 0;
  11561. ib[i * 3 + 1] = i + 2;
  11562. ib[i * 3 + 2] = (i + 6) % max;
  11563. ib[i * 3 + 3] = i + 0;
  11564. ib[i * 3 + 4] = (i + 6) % max;
  11565. ib[i * 3 + 5] = (i + 4) % max;
  11566. ib[i * 3 + 6] = i + 3;
  11567. ib[i * 3 + 7] = i + 1;
  11568. ib[i * 3 + 8] = (i + 5) % max;
  11569. ib[i * 3 + 9] = i + 3;
  11570. ib[i * 3 + 10] = (i + 5) % max;
  11571. ib[i * 3 + 11] = (i + 7) % max;
  11572. }
  11573. this._buildCap(vb, count * 2 * 2 * 2, ib, triCount * 3, this.points[0], this.fillThickness, this.borderThickness, this.startCap, Lines2D_1._startDir, startCapContour);
  11574. 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);
  11575. }
  11576. this._contour = contour;
  11577. if (startCapContour.length > 0) {
  11578. var startCapTri = Earcut.earcut(startCapContour, null, 2);
  11579. this._startCapTriIndices = startCapTri;
  11580. this._startCapContour = startCapContour;
  11581. }
  11582. else {
  11583. this._startCapTriIndices = null;
  11584. this._startCapContour = null;
  11585. }
  11586. if (endCapContour.length > 0) {
  11587. var endCapTri = Earcut.earcut(endCapContour, null, 2);
  11588. this._endCapContour = endCapContour;
  11589. this._endCapTriIndices = endCapTri;
  11590. }
  11591. else {
  11592. this._endCapContour = null;
  11593. this._endCapTriIndices = null;
  11594. }
  11595. var bs = this._boundingMax.subtract(this._boundingMin);
  11596. this._size.width = bs.x;
  11597. this._size.height = bs.y;
  11598. };
  11599. Object.defineProperty(Lines2D.prototype, "size", {
  11600. get: function () {
  11601. if (this._size == null) {
  11602. this._computeLines2D();
  11603. }
  11604. return this._size;
  11605. },
  11606. enumerable: true,
  11607. configurable: true
  11608. });
  11609. Lines2D.prototype.createInstanceDataParts = function () {
  11610. var res = new Array();
  11611. if (this.border) {
  11612. res.push(new Lines2DInstanceData(BABYLON.Shape2D.SHAPE2D_BORDERPARTID));
  11613. }
  11614. if (this.fill) {
  11615. res.push(new Lines2DInstanceData(BABYLON.Shape2D.SHAPE2D_FILLPARTID));
  11616. }
  11617. return res;
  11618. };
  11619. Lines2D.prototype.applyActualScaleOnTransform = function () {
  11620. return true;
  11621. };
  11622. Lines2D.prototype.refreshInstanceDataPart = function (part) {
  11623. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  11624. return false;
  11625. }
  11626. if (part.id === BABYLON.Shape2D.SHAPE2D_BORDERPARTID) {
  11627. var d = part;
  11628. if (this.border instanceof BABYLON.GradientColorBrush2D) {
  11629. d.boundingMin = this.boundingMin;
  11630. d.boundingMax = this.boundingMax;
  11631. }
  11632. }
  11633. else if (part.id === BABYLON.Shape2D.SHAPE2D_FILLPARTID) {
  11634. var d = part;
  11635. if (this.fill instanceof BABYLON.GradientColorBrush2D) {
  11636. d.boundingMin = this.boundingMin;
  11637. d.boundingMax = this.boundingMax;
  11638. }
  11639. }
  11640. return true;
  11641. };
  11642. return Lines2D;
  11643. }(BABYLON.Shape2D));
  11644. Lines2D._prevA = BABYLON.Vector2.Zero();
  11645. Lines2D._prevB = BABYLON.Vector2.Zero();
  11646. Lines2D._curA = BABYLON.Vector2.Zero();
  11647. Lines2D._curB = BABYLON.Vector2.Zero();
  11648. Lines2D._miterTps = BABYLON.Vector2.Zero();
  11649. Lines2D._startDir = BABYLON.Vector2.Zero();
  11650. Lines2D._endDir = BABYLON.Vector2.Zero();
  11651. Lines2D._tpsV = BABYLON.Vector2.Zero();
  11652. Lines2D._noCap = 0;
  11653. Lines2D._roundCap = 1;
  11654. Lines2D._triangleCap = 2;
  11655. Lines2D._squareAnchorCap = 3;
  11656. Lines2D._roundAnchorCap = 4;
  11657. Lines2D._diamondAnchorCap = 5;
  11658. Lines2D._arrowCap = 6;
  11659. Lines2D._roundCapSubDiv = 36;
  11660. __decorate([
  11661. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 1, function (pi) { return Lines2D_1.pointsProperty = pi; })
  11662. ], Lines2D.prototype, "points", null);
  11663. __decorate([
  11664. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 2, function (pi) { return Lines2D_1.fillThicknessProperty = pi; })
  11665. ], Lines2D.prototype, "fillThickness", null);
  11666. __decorate([
  11667. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 3, function (pi) { return Lines2D_1.closedProperty = pi; })
  11668. ], Lines2D.prototype, "closed", null);
  11669. __decorate([
  11670. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 4, function (pi) { return Lines2D_1.startCapProperty = pi; })
  11671. ], Lines2D.prototype, "startCap", null);
  11672. __decorate([
  11673. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 5, function (pi) { return Lines2D_1.endCapProperty = pi; })
  11674. ], Lines2D.prototype, "endCap", null);
  11675. Lines2D = Lines2D_1 = __decorate([
  11676. BABYLON.className("Lines2D", "BABYLON")
  11677. ], Lines2D);
  11678. BABYLON.Lines2D = Lines2D;
  11679. var Lines2D_1;
  11680. })(BABYLON || (BABYLON = {}));
  11681. var __extends = (this && this.__extends) || function (d, b) {
  11682. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  11683. function __() { this.constructor = d; }
  11684. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  11685. };
  11686. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  11687. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  11688. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  11689. 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;
  11690. return c > 3 && r && Object.defineProperty(target, key, r), r;
  11691. };
  11692. var BABYLON;
  11693. (function (BABYLON) {
  11694. // This class contains data that lifetime is bounding to the Babylon Engine object
  11695. var Canvas2DEngineBoundData = (function () {
  11696. function Canvas2DEngineBoundData() {
  11697. this._modelCache = new BABYLON.StringDictionary();
  11698. }
  11699. Canvas2DEngineBoundData.prototype.GetOrAddModelCache = function (key, factory) {
  11700. return this._modelCache.getOrAddWithFactory(key, factory);
  11701. };
  11702. Canvas2DEngineBoundData.prototype.DisposeModelRenderCache = function (modelRenderCache) {
  11703. if (!modelRenderCache.isDisposed) {
  11704. return false;
  11705. }
  11706. this._modelCache.remove(modelRenderCache.modelKey);
  11707. return true;
  11708. };
  11709. return Canvas2DEngineBoundData;
  11710. }());
  11711. BABYLON.Canvas2DEngineBoundData = Canvas2DEngineBoundData;
  11712. var Canvas2D = Canvas2D_1 = (function (_super) {
  11713. __extends(Canvas2D, _super);
  11714. function Canvas2D(scene, settings) {
  11715. var _this = _super.call(this, settings) || this;
  11716. /**
  11717. * 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.
  11718. * Beware that you have to take under consideration the origin in your calculations! Good luck!
  11719. */
  11720. _this.worldSpaceToNodeLocal = function (worldPos) {
  11721. var node = _this._worldSpaceNode;
  11722. if (!node) {
  11723. return;
  11724. }
  11725. var mtx = node.getWorldMatrix().clone();
  11726. mtx.invert();
  11727. var v = BABYLON.Vector3.TransformCoordinates(worldPos, mtx);
  11728. var res = new BABYLON.Vector2(v.x, v.y);
  11729. var size = _this.actualSize;
  11730. res.x += size.width * 0.5; // res is centered, make it relative to bottom/left
  11731. res.y += size.height * 0.5;
  11732. return res;
  11733. };
  11734. /**
  11735. * 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
  11736. */
  11737. _this.worldSpaceCacheChanged = function () {
  11738. var plane = _this.worldSpaceCanvasNode;
  11739. var vd = BABYLON.VertexData.ExtractFromMesh(plane); //new VertexData();
  11740. vd.uvs = new Float32Array(8);
  11741. var material = plane.material;
  11742. var tex = _this._renderableData._cacheTexture;
  11743. if (material.diffuseTexture !== tex) {
  11744. material.diffuseTexture = tex;
  11745. tex.hasAlpha = true;
  11746. }
  11747. var nodeuv = _this._renderableData._cacheNodeUVs;
  11748. for (var i = 0; i < 4; i++) {
  11749. vd.uvs[i * 2 + 0] = nodeuv[i].x;
  11750. vd.uvs[i * 2 + 1] = nodeuv[i].y;
  11751. }
  11752. vd.applyToMesh(plane);
  11753. };
  11754. _this._notifDebugMode = false;
  11755. /**
  11756. * Instanced Array will be create if there's at least this number of parts/prim that can fit into it
  11757. */
  11758. _this.minPartCountToUseInstancedArray = 5;
  11759. _this._mapCounter = 0;
  11760. _this._drawCallsOpaqueCounter = new BABYLON.PerfCounter();
  11761. _this._drawCallsAlphaTestCounter = new BABYLON.PerfCounter();
  11762. _this._drawCallsTransparentCounter = new BABYLON.PerfCounter();
  11763. _this._groupRenderCounter = new BABYLON.PerfCounter();
  11764. _this._updateTransparentDataCounter = new BABYLON.PerfCounter();
  11765. _this._cachedGroupRenderCounter = new BABYLON.PerfCounter();
  11766. _this._updateCachedStateCounter = new BABYLON.PerfCounter();
  11767. _this._updateLayoutCounter = new BABYLON.PerfCounter();
  11768. _this._updatePositioningCounter = new BABYLON.PerfCounter();
  11769. _this._updateLocalTransformCounter = new BABYLON.PerfCounter();
  11770. _this._updateGlobalTransformCounter = new BABYLON.PerfCounter();
  11771. _this._boundingInfoRecomputeCounter = new BABYLON.PerfCounter();
  11772. _this._uid = null;
  11773. _this._cachedCanvasGroup = null;
  11774. _this._renderingGroupObserver = null;
  11775. _this._beforeRenderObserver = null;
  11776. _this._afterRenderObserver = null;
  11777. _this._profileInfoText = null;
  11778. BABYLON.Prim2DBase._isCanvasInit = false;
  11779. if (!settings) {
  11780. settings = {};
  11781. }
  11782. if (_this._cachingStrategy !== Canvas2D_1.CACHESTRATEGY_TOPLEVELGROUPS) {
  11783. _this._background = new BABYLON.Rectangle2D({ parent: _this, id: "###CANVAS BACKGROUND###", size: settings.size }); //TODO CHECK when size is null
  11784. _this._background.zOrder = 1.0;
  11785. _this._background.isPickable = false;
  11786. _this._background.origin = BABYLON.Vector2.Zero();
  11787. _this._background.levelVisible = false;
  11788. if (settings.backgroundRoundRadius != null) {
  11789. _this.backgroundRoundRadius = settings.backgroundRoundRadius;
  11790. }
  11791. if (settings.backgroundBorder != null) {
  11792. if (typeof (settings.backgroundBorder) === "string") {
  11793. _this.backgroundBorder = Canvas2D_1.GetBrushFromString(settings.backgroundBorder);
  11794. }
  11795. else {
  11796. _this.backgroundBorder = settings.backgroundBorder;
  11797. }
  11798. }
  11799. if (settings.backgroundBorderThickNess != null) {
  11800. _this.backgroundBorderThickness = settings.backgroundBorderThickNess;
  11801. }
  11802. if (settings.backgroundFill != null) {
  11803. if (typeof (settings.backgroundFill) === "string") {
  11804. _this.backgroundFill = Canvas2D_1.GetBrushFromString(settings.backgroundFill);
  11805. }
  11806. else {
  11807. _this.backgroundFill = settings.backgroundFill;
  11808. }
  11809. }
  11810. // Put a handler to resize the background whenever the canvas is resizing
  11811. _this.propertyChanged.add(function (e, s) {
  11812. if (e.propertyName === "size") {
  11813. _this._background.size = _this.size;
  11814. }
  11815. }, BABYLON.Group2D.sizeProperty.flagId);
  11816. _this._background._patchHierarchy(_this);
  11817. }
  11818. var engine = scene.getEngine();
  11819. _this.__engineData = engine.getOrAddExternalDataWithFactory("__BJSCANVAS2D__", function (k) { return new Canvas2DEngineBoundData(); });
  11820. _this._primPointerInfo = new BABYLON.PrimitivePointerInfo();
  11821. _this._capturedPointers = new BABYLON.StringDictionary();
  11822. _this._pickStartingPosition = BABYLON.Vector2.Zero();
  11823. _this._hierarchyLevelMaxSiblingCount = 50;
  11824. _this._hierarchyDepth = 0;
  11825. _this._zOrder = 0;
  11826. _this._zMax = 1;
  11827. _this._scene = scene;
  11828. _this._engine = engine;
  11829. _this._renderingSize = new BABYLON.Size(0, 0);
  11830. _this._designSize = settings.designSize || null;
  11831. _this._designUseHorizAxis = settings.designUseHorizAxis === true;
  11832. _this._trackedGroups = new Array();
  11833. _this._maxAdaptiveWorldSpaceCanvasSize = null;
  11834. _this._groupCacheMaps = new BABYLON.StringDictionary();
  11835. _this._patchHierarchy(_this);
  11836. var enableInteraction = (settings.enableInteraction == null) ? true : settings.enableInteraction;
  11837. _this._fitRenderingDevice = !settings.size;
  11838. if (!settings.size) {
  11839. settings.size = new BABYLON.Size(engine.getRenderWidth(), engine.getRenderHeight());
  11840. }
  11841. // Register scene dispose to also dispose the canvas when it'll happens
  11842. scene.onDisposeObservable.add(function (d, s) {
  11843. _this.dispose();
  11844. });
  11845. if (_this._isScreenSpace) {
  11846. if (settings.renderingPhase) {
  11847. if (!settings.renderingPhase.camera || settings.renderingPhase.renderingGroupID == null) {
  11848. throw Error("You have to specify a valid camera and renderingGroup");
  11849. }
  11850. _this._renderingGroupObserver = _this._scene.onRenderingGroupObservable.add(function (e, s) {
  11851. if ((_this._scene.activeCamera === settings.renderingPhase.camera) && (e.renderStage === BABYLON.RenderingGroupInfo.STAGE_POSTTRANSPARENT)) {
  11852. _this._engine.clear(null, false, true, true);
  11853. _this._render();
  11854. }
  11855. }, Math.pow(2, settings.renderingPhase.renderingGroupID));
  11856. }
  11857. else {
  11858. _this._afterRenderObserver = _this._scene.onAfterRenderObservable.add(function (d, s) {
  11859. _this._engine.clear(null, false, true, true);
  11860. _this._render();
  11861. });
  11862. }
  11863. }
  11864. else {
  11865. _this._beforeRenderObserver = _this._scene.onBeforeRenderObservable.add(function (d, s) {
  11866. _this._render();
  11867. });
  11868. }
  11869. _this._supprtInstancedArray = _this._engine.getCaps().instancedArrays !== null;
  11870. //this._supprtInstancedArray = false; // TODO REMOVE!!!
  11871. _this._setupInteraction(enableInteraction);
  11872. // Register this instance
  11873. Canvas2D_1._INSTANCES.push(_this);
  11874. return _this;
  11875. }
  11876. Object.defineProperty(Canvas2D.prototype, "drawCallsOpaqueCounter", {
  11877. get: function () {
  11878. return this._drawCallsOpaqueCounter;
  11879. },
  11880. enumerable: true,
  11881. configurable: true
  11882. });
  11883. Object.defineProperty(Canvas2D.prototype, "drawCallsAlphaTestCounter", {
  11884. get: function () {
  11885. return this._drawCallsAlphaTestCounter;
  11886. },
  11887. enumerable: true,
  11888. configurable: true
  11889. });
  11890. Object.defineProperty(Canvas2D.prototype, "drawCallsTransparentCounter", {
  11891. get: function () {
  11892. return this._drawCallsTransparentCounter;
  11893. },
  11894. enumerable: true,
  11895. configurable: true
  11896. });
  11897. Object.defineProperty(Canvas2D.prototype, "groupRenderCounter", {
  11898. get: function () {
  11899. return this._groupRenderCounter;
  11900. },
  11901. enumerable: true,
  11902. configurable: true
  11903. });
  11904. Object.defineProperty(Canvas2D.prototype, "updateTransparentDataCounter", {
  11905. get: function () {
  11906. return this._updateTransparentDataCounter;
  11907. },
  11908. enumerable: true,
  11909. configurable: true
  11910. });
  11911. Object.defineProperty(Canvas2D.prototype, "cachedGroupRenderCounter", {
  11912. get: function () {
  11913. return this._cachedGroupRenderCounter;
  11914. },
  11915. enumerable: true,
  11916. configurable: true
  11917. });
  11918. Object.defineProperty(Canvas2D.prototype, "updateCachedStateCounter", {
  11919. get: function () {
  11920. return this._updateCachedStateCounter;
  11921. },
  11922. enumerable: true,
  11923. configurable: true
  11924. });
  11925. Object.defineProperty(Canvas2D.prototype, "updateLayoutCounter", {
  11926. get: function () {
  11927. return this._updateLayoutCounter;
  11928. },
  11929. enumerable: true,
  11930. configurable: true
  11931. });
  11932. Object.defineProperty(Canvas2D.prototype, "updatePositioningCounter", {
  11933. get: function () {
  11934. return this._updatePositioningCounter;
  11935. },
  11936. enumerable: true,
  11937. configurable: true
  11938. });
  11939. Object.defineProperty(Canvas2D.prototype, "updateLocalTransformCounter", {
  11940. get: function () {
  11941. return this._updateLocalTransformCounter;
  11942. },
  11943. enumerable: true,
  11944. configurable: true
  11945. });
  11946. Object.defineProperty(Canvas2D.prototype, "updateGlobalTransformCounter", {
  11947. get: function () {
  11948. return this._updateGlobalTransformCounter;
  11949. },
  11950. enumerable: true,
  11951. configurable: true
  11952. });
  11953. Object.defineProperty(Canvas2D.prototype, "boundingInfoRecomputeCounter", {
  11954. get: function () {
  11955. return this._boundingInfoRecomputeCounter;
  11956. },
  11957. enumerable: true,
  11958. configurable: true
  11959. });
  11960. Object.defineProperty(Canvas2D, "instances", {
  11961. get: function () {
  11962. return Canvas2D_1._INSTANCES;
  11963. },
  11964. enumerable: true,
  11965. configurable: true
  11966. });
  11967. Canvas2D.prototype._canvasPreInit = function (settings) {
  11968. var cachingStrategy = (settings.cachingStrategy == null) ? Canvas2D_1.CACHESTRATEGY_DONTCACHE : settings.cachingStrategy;
  11969. this._cachingStrategy = cachingStrategy;
  11970. this._isScreenSpace = (settings.isScreenSpace == null) ? true : settings.isScreenSpace;
  11971. };
  11972. Canvas2D.prototype._setupInteraction = function (enable) {
  11973. var _this = this;
  11974. // No change detection
  11975. if (enable === this._interactionEnabled) {
  11976. return;
  11977. }
  11978. // Set the new state
  11979. this._interactionEnabled = enable;
  11980. // ScreenSpace mode
  11981. if (this._isScreenSpace) {
  11982. // Disable interaction
  11983. if (!enable) {
  11984. if (this._scenePrePointerObserver) {
  11985. this.scene.onPrePointerObservable.remove(this._scenePrePointerObserver);
  11986. this._scenePrePointerObserver = null;
  11987. }
  11988. return;
  11989. }
  11990. // Enable Interaction
  11991. // Register the observable
  11992. this._scenePrePointerObserver = this.scene.onPrePointerObservable.add(function (e, s) {
  11993. if (_this.isVisible === false) {
  11994. return;
  11995. }
  11996. var hs = 1 / _this.engine.getHardwareScalingLevel();
  11997. var localPos = e.localPosition.multiplyByFloats(hs, hs);
  11998. _this._handlePointerEventForInteraction(e, localPos, s);
  11999. });
  12000. }
  12001. else {
  12002. var scene = this.scene;
  12003. if (enable) {
  12004. scene.constantlyUpdateMeshUnderPointer = true;
  12005. this._scenePointerObserver = scene.onPointerObservable.add(function (e, s) {
  12006. if (_this.isVisible === false) {
  12007. return;
  12008. }
  12009. if (e.pickInfo.hit && e.pickInfo.pickedMesh === _this._worldSpaceNode && _this.worldSpaceToNodeLocal) {
  12010. var localPos = _this.worldSpaceToNodeLocal(e.pickInfo.pickedPoint);
  12011. _this._handlePointerEventForInteraction(e, localPos, s);
  12012. }
  12013. });
  12014. }
  12015. else {
  12016. if (this._scenePointerObserver) {
  12017. this.scene.onPointerObservable.remove(this._scenePointerObserver);
  12018. this._scenePointerObserver = null;
  12019. }
  12020. }
  12021. }
  12022. };
  12023. /**
  12024. * Internal method, you should use the Prim2DBase version instead
  12025. */
  12026. Canvas2D.prototype._setPointerCapture = function (pointerId, primitive) {
  12027. if (this.isPointerCaptured(pointerId)) {
  12028. return false;
  12029. }
  12030. // Try to capture the pointer on the HTML side
  12031. try {
  12032. this.engine.getRenderingCanvas().setPointerCapture(pointerId);
  12033. }
  12034. catch (e) {
  12035. }
  12036. this._primPointerInfo.updateRelatedTarget(primitive, BABYLON.Vector2.Zero());
  12037. this._bubbleNotifyPrimPointerObserver(primitive, BABYLON.PrimitivePointerInfo.PointerGotCapture, null);
  12038. this._capturedPointers.add(pointerId.toString(), primitive);
  12039. return true;
  12040. };
  12041. /**
  12042. * Internal method, you should use the Prim2DBase version instead
  12043. */
  12044. Canvas2D.prototype._releasePointerCapture = function (pointerId, primitive) {
  12045. if (this._capturedPointers.get(pointerId.toString()) !== primitive) {
  12046. return false;
  12047. }
  12048. // Try to release the pointer on the HTML side
  12049. try {
  12050. this.engine.getRenderingCanvas().releasePointerCapture(pointerId);
  12051. }
  12052. catch (e) {
  12053. }
  12054. this._primPointerInfo.updateRelatedTarget(primitive, BABYLON.Vector2.Zero());
  12055. this._bubbleNotifyPrimPointerObserver(primitive, BABYLON.PrimitivePointerInfo.PointerLostCapture, null);
  12056. this._capturedPointers.remove(pointerId.toString());
  12057. return true;
  12058. };
  12059. /**
  12060. * Determine if the given pointer is captured or not
  12061. * @param pointerId the Id of the pointer
  12062. * @return true if it's captured, false otherwise
  12063. */
  12064. Canvas2D.prototype.isPointerCaptured = function (pointerId) {
  12065. return this._capturedPointers.contains(pointerId.toString());
  12066. };
  12067. Canvas2D.prototype.getCapturedPrimitive = function (pointerId) {
  12068. // Avoid unnecessary lookup
  12069. if (this._capturedPointers.count === 0) {
  12070. return null;
  12071. }
  12072. return this._capturedPointers.get(pointerId.toString());
  12073. };
  12074. Canvas2D.prototype._handlePointerEventForInteraction = function (eventData, localPosition, eventState) {
  12075. // Dispose check
  12076. if (this.isDisposed) {
  12077. return;
  12078. }
  12079. // Update the this._primPointerInfo structure we'll send to observers using the PointerEvent data
  12080. if (!this._updatePointerInfo(eventData, localPosition)) {
  12081. return;
  12082. }
  12083. var capturedPrim = this.getCapturedPrimitive(this._primPointerInfo.pointerId);
  12084. // 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.
  12085. // 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.
  12086. this._updateIntersectionList(this._primPointerInfo.canvasPointerPos, capturedPrim !== null, true);
  12087. // 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
  12088. this._updateOverStatus(true);
  12089. // Check if we have nothing to raise
  12090. if (!this._actualOverPrimitive && !capturedPrim) {
  12091. return;
  12092. }
  12093. // Update the relatedTarget info with the over primitive or the captured one (if any)
  12094. var targetPrim = capturedPrim || this._actualOverPrimitive.prim;
  12095. var targetPointerPos = capturedPrim ? this._primPointerInfo.canvasPointerPos.subtract(new BABYLON.Vector2(targetPrim.globalTransform.m[12], targetPrim.globalTransform.m[13])) : this._actualOverPrimitive.intersectionLocation;
  12096. this._primPointerInfo.updateRelatedTarget(targetPrim, targetPointerPos);
  12097. // Analyze the pointer event type and fire proper events on the primitive
  12098. var skip = false;
  12099. if (eventData.type === BABYLON.PointerEventTypes.POINTERWHEEL) {
  12100. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerMouseWheel, eventData);
  12101. }
  12102. else if (eventData.type === BABYLON.PointerEventTypes.POINTERMOVE) {
  12103. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerMove, eventData);
  12104. }
  12105. else if (eventData.type === BABYLON.PointerEventTypes.POINTERDOWN) {
  12106. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerDown, eventData);
  12107. }
  12108. else if (eventData.type === BABYLON.PointerEventTypes.POINTERUP) {
  12109. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerUp, eventData);
  12110. }
  12111. eventState.skipNextObservers = skip;
  12112. };
  12113. Canvas2D.prototype._updatePointerInfo = function (eventData, localPosition) {
  12114. var s = this.scale;
  12115. var pii = this._primPointerInfo;
  12116. pii.cancelBubble = false;
  12117. if (!pii.canvasPointerPos) {
  12118. pii.canvasPointerPos = BABYLON.Vector2.Zero();
  12119. }
  12120. var camera = this._scene.cameraToUseForPointers || this._scene.activeCamera;
  12121. if (!camera || !camera.viewport) {
  12122. return false;
  12123. }
  12124. var engine = this._scene.getEngine();
  12125. if (this._isScreenSpace) {
  12126. var cameraViewport = camera.viewport;
  12127. var viewport = cameraViewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight());
  12128. // Moving coordinates to local viewport world
  12129. var x = localPosition.x - viewport.x;
  12130. var y = localPosition.y - viewport.y;
  12131. pii.canvasPointerPos.x = (x - this.actualPosition.x) / s;
  12132. pii.canvasPointerPos.y = (engine.getRenderHeight() - y - this.actualPosition.y) / s;
  12133. }
  12134. else {
  12135. pii.canvasPointerPos.x = localPosition.x / s;
  12136. pii.canvasPointerPos.y = localPosition.y / s;
  12137. }
  12138. //console.log(`UpdatePointerInfo for ${this.id}, X:${pii.canvasPointerPos.x}, Y:${pii.canvasPointerPos.y}`);
  12139. pii.mouseWheelDelta = 0;
  12140. if (eventData.type === BABYLON.PointerEventTypes.POINTERWHEEL) {
  12141. var event = eventData.event;
  12142. if (event.wheelDelta) {
  12143. pii.mouseWheelDelta = event.wheelDelta / (BABYLON.PrimitivePointerInfo.MouseWheelPrecision * 40);
  12144. }
  12145. else if (event.detail) {
  12146. pii.mouseWheelDelta = -event.detail / BABYLON.PrimitivePointerInfo.MouseWheelPrecision;
  12147. }
  12148. }
  12149. else {
  12150. var pe = eventData.event;
  12151. pii.ctrlKey = pe.ctrlKey;
  12152. pii.altKey = pe.altKey;
  12153. pii.shiftKey = pe.shiftKey;
  12154. pii.metaKey = pe.metaKey;
  12155. pii.button = pe.button;
  12156. pii.buttons = pe.buttons;
  12157. pii.pointerId = pe.pointerId;
  12158. pii.width = pe.width;
  12159. pii.height = pe.height;
  12160. pii.presssure = pe.pressure;
  12161. pii.tilt.x = pe.tiltX;
  12162. pii.tilt.y = pe.tiltY;
  12163. pii.isCaptured = this.getCapturedPrimitive(pe.pointerId) !== null;
  12164. }
  12165. return true;
  12166. };
  12167. Canvas2D.prototype._updateIntersectionList = function (mouseLocalPos, isCapture, force) {
  12168. if (!force && (this.scene.getRenderId() === this._intersectionRenderId)) {
  12169. return;
  12170. }
  12171. // 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
  12172. if (!this._globalTransform) {
  12173. this.updateCachedStates(true);
  12174. }
  12175. var ii = Canvas2D_1._interInfo;
  12176. ii.pickPosition.x = mouseLocalPos.x;
  12177. ii.pickPosition.y = mouseLocalPos.y;
  12178. ii.findFirstOnly = false;
  12179. // Fast rejection: test if the mouse pointer is outside the canvas's bounding Info
  12180. if (!isCapture && !this.levelBoundingInfo.doesIntersect(ii.pickPosition)) {
  12181. // Reset intersection info as we don't hit anything
  12182. ii.intersectedPrimitives = new Array();
  12183. ii.topMostIntersectedPrimitive = null;
  12184. }
  12185. else {
  12186. // The pointer is inside the Canvas, do an intersection test
  12187. this.intersect(ii);
  12188. }
  12189. {
  12190. // Update prev/actual intersection info, fire "overPrim" property change if needed
  12191. this._previousIntersectionList = this._actualIntersectionList;
  12192. this._actualIntersectionList = ii.intersectedPrimitives;
  12193. this._previousOverPrimitive = this._actualOverPrimitive;
  12194. this._actualOverPrimitive = ii.topMostIntersectedPrimitive;
  12195. var prev = (this._previousOverPrimitive != null) ? this._previousOverPrimitive.prim : null;
  12196. var actual = (this._actualOverPrimitive != null) ? this._actualOverPrimitive.prim : null;
  12197. if (prev !== actual) {
  12198. this.onPropertyChanged("overPrim", this._previousOverPrimitive ? this._previousOverPrimitive.prim : null, this._actualOverPrimitive ? this._actualOverPrimitive.prim : null);
  12199. }
  12200. }
  12201. this._intersectionRenderId = this.scene.getRenderId();
  12202. };
  12203. // Based on the previousIntersectionList and the actualInstersectionList we can determined which primitives are being hover state or loosing it
  12204. Canvas2D.prototype._updateOverStatus = function (force) {
  12205. if ((!force && (this.scene.getRenderId() === this._hoverStatusRenderId)) || !this._previousIntersectionList || !this._actualIntersectionList) {
  12206. return;
  12207. }
  12208. // Detect a change of over
  12209. var prevPrim = this._previousOverPrimitive ? this._previousOverPrimitive.prim : null;
  12210. var actualPrim = this._actualOverPrimitive ? this._actualOverPrimitive.prim : null;
  12211. if (prevPrim !== actualPrim) {
  12212. // Detect if the current pointer is captured, only fire event if they belong to the capture primitive
  12213. var capturedPrim = this.getCapturedPrimitive(this._primPointerInfo.pointerId);
  12214. // Notify the previous "over" prim that the pointer is no longer over it
  12215. if ((capturedPrim && capturedPrim === prevPrim) || (!capturedPrim && prevPrim && !prevPrim.isDisposed)) {
  12216. this._primPointerInfo.updateRelatedTarget(prevPrim, this._previousOverPrimitive.intersectionLocation);
  12217. this._bubbleNotifyPrimPointerObserver(prevPrim, BABYLON.PrimitivePointerInfo.PointerOut, null);
  12218. }
  12219. // Notify the new "over" prim that the pointer is over it
  12220. if ((capturedPrim && capturedPrim === actualPrim) || (!capturedPrim && actualPrim)) {
  12221. this._primPointerInfo.updateRelatedTarget(actualPrim, this._actualOverPrimitive.intersectionLocation);
  12222. this._bubbleNotifyPrimPointerObserver(actualPrim, BABYLON.PrimitivePointerInfo.PointerOver, null);
  12223. }
  12224. }
  12225. this._hoverStatusRenderId = this.scene.getRenderId();
  12226. };
  12227. Canvas2D.prototype._updatePrimPointerPos = function (prim) {
  12228. if (this._primPointerInfo.isCaptured) {
  12229. this._primPointerInfo.primitivePointerPos = this._primPointerInfo.relatedTargetPointerPos;
  12230. }
  12231. else {
  12232. for (var _i = 0, _a = this._actualIntersectionList; _i < _a.length; _i++) {
  12233. var pii = _a[_i];
  12234. if (pii.prim === prim) {
  12235. this._primPointerInfo.primitivePointerPos = pii.intersectionLocation;
  12236. return;
  12237. }
  12238. }
  12239. }
  12240. };
  12241. Canvas2D.prototype._debugExecObserver = function (prim, mask) {
  12242. if (!this._notifDebugMode) {
  12243. return;
  12244. }
  12245. var debug = "";
  12246. for (var i = 0; i < prim.hierarchyDepth; i++) {
  12247. debug += " ";
  12248. }
  12249. var pii = this._primPointerInfo;
  12250. 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();
  12251. console.log(debug);
  12252. };
  12253. Canvas2D.prototype._bubbleNotifyPrimPointerObserver = function (prim, mask, eventData) {
  12254. var ppi = this._primPointerInfo;
  12255. var event = eventData ? eventData.event : null;
  12256. // In case of PointerOver/Out we will first notify the parent with PointerEnter/Leave
  12257. if ((mask & (BABYLON.PrimitivePointerInfo.PointerOver | BABYLON.PrimitivePointerInfo.PointerOut)) !== 0) {
  12258. this._notifParents(prim, mask);
  12259. }
  12260. var bubbleCancelled = false;
  12261. var cur = prim;
  12262. while (cur && !cur.isDisposed) {
  12263. // Only trigger the observers if the primitive is intersected (except for out)
  12264. if (!bubbleCancelled) {
  12265. this._updatePrimPointerPos(cur);
  12266. // Exec the observers
  12267. this._debugExecObserver(cur, mask);
  12268. if (!cur._pointerEventObservable.notifyObservers(ppi, mask) && eventData instanceof BABYLON.PointerInfoPre) {
  12269. eventData.skipOnPointerObservable = true;
  12270. return false;
  12271. }
  12272. this._triggerActionManager(cur, ppi, mask, event);
  12273. // Bubble canceled? If we're not executing PointerOver or PointerOut, quit immediately
  12274. // If it's PointerOver/Out we have to trigger PointerEnter/Leave no matter what
  12275. if (ppi.cancelBubble) {
  12276. if ((mask & (BABYLON.PrimitivePointerInfo.PointerOver | BABYLON.PrimitivePointerInfo.PointerOut)) === 0) {
  12277. return false;
  12278. }
  12279. // We're dealing with PointerOver/Out, let's keep looping to fire PointerEnter/Leave, but not Over/Out anymore
  12280. bubbleCancelled = true;
  12281. }
  12282. }
  12283. // If bubble is cancel we didn't update the Primitive Pointer Pos yet, let's do it
  12284. if (bubbleCancelled) {
  12285. this._updatePrimPointerPos(cur);
  12286. }
  12287. // NOTE TO MYSELF, this is commented right now because it doesn't seemed needed but I can't figure out why I put this code in the first place
  12288. //// Trigger a PointerEnter corresponding to the PointerOver
  12289. //if (mask === PrimitivePointerInfo.PointerOver) {
  12290. // this._debugExecObserver(cur, PrimitivePointerInfo.PointerEnter);
  12291. // cur._pointerEventObservable.notifyObservers(ppi, PrimitivePointerInfo.PointerEnter);
  12292. //}
  12293. //// Trigger a PointerLeave corresponding to the PointerOut
  12294. //else if (mask === PrimitivePointerInfo.PointerOut) {
  12295. // this._debugExecObserver(cur, PrimitivePointerInfo.PointerLeave);
  12296. // cur._pointerEventObservable.notifyObservers(ppi, PrimitivePointerInfo.PointerLeave);
  12297. //}
  12298. // Loop to the parent
  12299. cur = cur.parent;
  12300. }
  12301. return true;
  12302. };
  12303. Canvas2D.prototype._triggerActionManager = function (prim, ppi, mask, eventData) {
  12304. var _this = this;
  12305. // 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
  12306. if (!this._globalTransform) {
  12307. this.updateCachedStates(true);
  12308. }
  12309. // Process Trigger related to PointerDown
  12310. if ((mask & BABYLON.PrimitivePointerInfo.PointerDown) !== 0) {
  12311. // On pointer down, record the current position and time to be able to trick PickTrigger and LongPressTrigger
  12312. this._pickStartingPosition = ppi.primitivePointerPos.clone();
  12313. this._pickStartingTime = new Date().getTime();
  12314. this._pickedDownPrim = null;
  12315. if (prim.actionManager) {
  12316. this._pickedDownPrim = prim;
  12317. if (prim.actionManager.hasPickTriggers) {
  12318. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  12319. switch (eventData.button) {
  12320. case 0:
  12321. prim.actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger, actionEvent);
  12322. break;
  12323. case 1:
  12324. prim.actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger, actionEvent);
  12325. break;
  12326. case 2:
  12327. prim.actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger, actionEvent);
  12328. break;
  12329. }
  12330. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPickDownTrigger, actionEvent);
  12331. }
  12332. if (prim.actionManager.hasSpecificTrigger(BABYLON.ActionManager.OnLongPressTrigger)) {
  12333. window.setTimeout(function () {
  12334. var ppi = _this._primPointerInfo;
  12335. var capturedPrim = _this.getCapturedPrimitive(ppi.pointerId);
  12336. _this._updateIntersectionList(ppi.canvasPointerPos, capturedPrim !== null, true);
  12337. _this._updateOverStatus(false);
  12338. var ii = new BABYLON.IntersectInfo2D();
  12339. ii.pickPosition = ppi.canvasPointerPos.clone();
  12340. ii.findFirstOnly = false;
  12341. _this.intersect(ii);
  12342. if (ii.isPrimIntersected(prim) !== null) {
  12343. if (prim.actionManager) {
  12344. 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)) {
  12345. _this._pickStartingTime = 0;
  12346. prim.actionManager.processTrigger(BABYLON.ActionManager.OnLongPressTrigger, BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData));
  12347. }
  12348. }
  12349. }
  12350. }, BABYLON.ActionManager.LongPressDelay);
  12351. }
  12352. }
  12353. }
  12354. else if ((mask & BABYLON.PrimitivePointerInfo.PointerUp) !== 0) {
  12355. this._pickStartingTime = 0;
  12356. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  12357. if (prim.actionManager) {
  12358. // OnPickUpTrigger
  12359. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPickUpTrigger, actionEvent);
  12360. // OnPickTrigger
  12361. if (Math.abs(this._pickStartingPosition.x - ppi.canvasPointerPos.x) < BABYLON.ActionManager.DragMovementThreshold && Math.abs(this._pickStartingPosition.y - ppi.canvasPointerPos.y) < BABYLON.ActionManager.DragMovementThreshold) {
  12362. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger, actionEvent);
  12363. }
  12364. }
  12365. // OnPickOutTrigger
  12366. if (this._pickedDownPrim && this._pickedDownPrim.actionManager && (this._pickedDownPrim !== prim)) {
  12367. this._pickedDownPrim.actionManager.processTrigger(BABYLON.ActionManager.OnPickOutTrigger, actionEvent);
  12368. }
  12369. }
  12370. else if ((mask & BABYLON.PrimitivePointerInfo.PointerOver) !== 0) {
  12371. if (prim.actionManager) {
  12372. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  12373. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOverTrigger, actionEvent);
  12374. }
  12375. }
  12376. else if ((mask & BABYLON.PrimitivePointerInfo.PointerOut) !== 0) {
  12377. if (prim.actionManager) {
  12378. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  12379. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOutTrigger, actionEvent);
  12380. }
  12381. }
  12382. };
  12383. Canvas2D.prototype._notifParents = function (prim, mask) {
  12384. var pii = this._primPointerInfo;
  12385. var curPrim = this;
  12386. while (curPrim) {
  12387. this._updatePrimPointerPos(curPrim);
  12388. // Fire the proper notification
  12389. if (mask === BABYLON.PrimitivePointerInfo.PointerOver) {
  12390. this._debugExecObserver(curPrim, BABYLON.PrimitivePointerInfo.PointerEnter);
  12391. curPrim._pointerEventObservable.notifyObservers(pii, BABYLON.PrimitivePointerInfo.PointerEnter);
  12392. }
  12393. else if (mask === BABYLON.PrimitivePointerInfo.PointerOut) {
  12394. this._debugExecObserver(curPrim, BABYLON.PrimitivePointerInfo.PointerLeave);
  12395. curPrim._pointerEventObservable.notifyObservers(pii, BABYLON.PrimitivePointerInfo.PointerLeave);
  12396. }
  12397. curPrim = curPrim.parent;
  12398. }
  12399. };
  12400. /**
  12401. * Don't forget to call the dispose method when you're done with the Canvas instance.
  12402. * But don't worry, if you dispose its scene, the canvas will be automatically disposed too.
  12403. */
  12404. Canvas2D.prototype.dispose = function () {
  12405. if (!_super.prototype.dispose.call(this)) {
  12406. return false;
  12407. }
  12408. if (this._profilingCanvas) {
  12409. this._profilingCanvas.dispose();
  12410. this._profilingCanvas = null;
  12411. }
  12412. if (this.interactionEnabled) {
  12413. this._setupInteraction(false);
  12414. }
  12415. if (this._renderingGroupObserver) {
  12416. this._scene.onRenderingGroupObservable.remove(this._renderingGroupObserver);
  12417. this._renderingGroupObserver = null;
  12418. }
  12419. if (this._beforeRenderObserver) {
  12420. this._scene.onBeforeRenderObservable.remove(this._beforeRenderObserver);
  12421. this._beforeRenderObserver = null;
  12422. }
  12423. if (this._afterRenderObserver) {
  12424. this._scene.onAfterRenderObservable.remove(this._afterRenderObserver);
  12425. this._afterRenderObserver = null;
  12426. }
  12427. if (this._groupCacheMaps) {
  12428. this._groupCacheMaps.forEach(function (k, m) { return m.forEach(function (e) { return e.dispose(); }); });
  12429. this._groupCacheMaps = null;
  12430. }
  12431. // Unregister this instance
  12432. var index = Canvas2D_1._INSTANCES.indexOf(this);
  12433. if (index > -1) {
  12434. Canvas2D_1._INSTANCES.splice(index, 1);
  12435. }
  12436. return true;
  12437. };
  12438. Object.defineProperty(Canvas2D.prototype, "scene", {
  12439. /**
  12440. * Accessor to the Scene that owns the Canvas
  12441. * @returns The instance of the Scene object
  12442. */
  12443. get: function () {
  12444. return this._scene;
  12445. },
  12446. enumerable: true,
  12447. configurable: true
  12448. });
  12449. Object.defineProperty(Canvas2D.prototype, "engine", {
  12450. /**
  12451. * Accessor to the Engine that drives the Scene used by this Canvas
  12452. * @returns The instance of the Engine object
  12453. */
  12454. get: function () {
  12455. return this._engine;
  12456. },
  12457. enumerable: true,
  12458. configurable: true
  12459. });
  12460. Object.defineProperty(Canvas2D.prototype, "uid", {
  12461. /**
  12462. * return a unique identifier for the Canvas2D
  12463. */
  12464. get: function () {
  12465. if (!this._uid) {
  12466. this._uid = BABYLON.Tools.RandomId();
  12467. }
  12468. return this._uid;
  12469. },
  12470. enumerable: true,
  12471. configurable: true
  12472. });
  12473. Object.defineProperty(Canvas2D.prototype, "renderObservable", {
  12474. /**
  12475. * And observable called during the Canvas rendering process.
  12476. * This observable is called twice per render, each time with a different mask:
  12477. * - 1: before render is executed
  12478. * - 2: after render is executed
  12479. */
  12480. get: function () {
  12481. if (!this._renderObservable) {
  12482. this._renderObservable = new BABYLON.Observable();
  12483. }
  12484. return this._renderObservable;
  12485. },
  12486. enumerable: true,
  12487. configurable: true
  12488. });
  12489. Object.defineProperty(Canvas2D.prototype, "cachingStrategy", {
  12490. /**
  12491. * Accessor of the Caching Strategy used by this Canvas.
  12492. * See Canvas2D.CACHESTRATEGY_xxxx static members for more information
  12493. * @returns the value corresponding to the used strategy.
  12494. */
  12495. get: function () {
  12496. return this._cachingStrategy;
  12497. },
  12498. enumerable: true,
  12499. configurable: true
  12500. });
  12501. Object.defineProperty(Canvas2D.prototype, "isScreenSpace", {
  12502. /**
  12503. * Return true if the Canvas is a Screen Space one, false if it's a World Space one.
  12504. * @returns {}
  12505. */
  12506. get: function () {
  12507. return this._isScreenSpace;
  12508. },
  12509. enumerable: true,
  12510. configurable: true
  12511. });
  12512. Object.defineProperty(Canvas2D.prototype, "worldSpaceCanvasNode", {
  12513. /**
  12514. * Only valid for World Space Canvas, returns the scene node that displays the canvas
  12515. */
  12516. get: function () {
  12517. return this._worldSpaceNode;
  12518. },
  12519. set: function (val) {
  12520. this._worldSpaceNode = val;
  12521. },
  12522. enumerable: true,
  12523. configurable: true
  12524. });
  12525. Object.defineProperty(Canvas2D.prototype, "supportInstancedArray", {
  12526. /**
  12527. * Check if the WebGL Instanced Array extension is supported or not
  12528. */
  12529. get: function () {
  12530. return this._supprtInstancedArray;
  12531. },
  12532. enumerable: true,
  12533. configurable: true
  12534. });
  12535. Object.defineProperty(Canvas2D.prototype, "backgroundFill", {
  12536. /**
  12537. * Property that defines the fill object used to draw the background of the Canvas.
  12538. * Note that Canvas with a Caching Strategy of
  12539. * @returns If the background is not set, null will be returned, otherwise a valid fill object is returned.
  12540. */
  12541. get: function () {
  12542. if (!this._background || !this._background.isVisible) {
  12543. return null;
  12544. }
  12545. return this._background.fill;
  12546. },
  12547. set: function (value) {
  12548. this.checkBackgroundAvailability();
  12549. if (value === this._background.fill) {
  12550. return;
  12551. }
  12552. this._background.fill = value;
  12553. this._background.levelVisible = true;
  12554. },
  12555. enumerable: true,
  12556. configurable: true
  12557. });
  12558. Object.defineProperty(Canvas2D.prototype, "backgroundBorder", {
  12559. /**
  12560. * Property that defines the border object used to draw the background of the Canvas.
  12561. * @returns If the background is not set, null will be returned, otherwise a valid border object is returned.
  12562. */
  12563. get: function () {
  12564. if (!this._background || !this._background.isVisible) {
  12565. return null;
  12566. }
  12567. return this._background.border;
  12568. },
  12569. set: function (value) {
  12570. this.checkBackgroundAvailability();
  12571. if (value === this._background.border) {
  12572. return;
  12573. }
  12574. this._background.border = value;
  12575. this._background.levelVisible = true;
  12576. },
  12577. enumerable: true,
  12578. configurable: true
  12579. });
  12580. Object.defineProperty(Canvas2D.prototype, "backgroundBorderThickness", {
  12581. /**
  12582. * Property that defines the thickness of the border object used to draw the background of the Canvas.
  12583. * @returns If the background is not set, null will be returned, otherwise a valid number matching the thickness is returned.
  12584. */
  12585. get: function () {
  12586. if (!this._background || !this._background.isVisible) {
  12587. return null;
  12588. }
  12589. return this._background.borderThickness;
  12590. },
  12591. set: function (value) {
  12592. this.checkBackgroundAvailability();
  12593. if (value === this._background.borderThickness) {
  12594. return;
  12595. }
  12596. this._background.borderThickness = value;
  12597. },
  12598. enumerable: true,
  12599. configurable: true
  12600. });
  12601. Object.defineProperty(Canvas2D.prototype, "backgroundRoundRadius", {
  12602. /**
  12603. * You can set the roundRadius of the background
  12604. * @returns The current roundRadius
  12605. */
  12606. get: function () {
  12607. if (!this._background || !this._background.isVisible) {
  12608. return null;
  12609. }
  12610. return this._background.roundRadius;
  12611. },
  12612. set: function (value) {
  12613. this.checkBackgroundAvailability();
  12614. if (value === this._background.roundRadius) {
  12615. return;
  12616. }
  12617. this._background.roundRadius = value;
  12618. this._background.levelVisible = true;
  12619. },
  12620. enumerable: true,
  12621. configurable: true
  12622. });
  12623. Object.defineProperty(Canvas2D.prototype, "interactionEnabled", {
  12624. /**
  12625. * Enable/Disable interaction for this Canvas
  12626. * When enabled the Prim2DBase.pointerEventObservable property will notified when appropriate events occur
  12627. */
  12628. get: function () {
  12629. return this._interactionEnabled;
  12630. },
  12631. set: function (enable) {
  12632. this._setupInteraction(enable);
  12633. },
  12634. enumerable: true,
  12635. configurable: true
  12636. });
  12637. Object.defineProperty(Canvas2D.prototype, "fitRenderingDevice", {
  12638. get: function () {
  12639. return this._fitRenderingDevice;
  12640. },
  12641. enumerable: true,
  12642. configurable: true
  12643. });
  12644. Object.defineProperty(Canvas2D.prototype, "designSize", {
  12645. get: function () {
  12646. return this._designSize;
  12647. },
  12648. enumerable: true,
  12649. configurable: true
  12650. });
  12651. Object.defineProperty(Canvas2D.prototype, "designSizeUseHorizAxis", {
  12652. get: function () {
  12653. return this._designUseHorizAxis;
  12654. },
  12655. enumerable: true,
  12656. configurable: true
  12657. });
  12658. Object.defineProperty(Canvas2D.prototype, "overPrim", {
  12659. /**
  12660. * Return
  12661. */
  12662. get: function () {
  12663. return this._actualOverPrimitive ? this._actualOverPrimitive.prim : null;
  12664. },
  12665. enumerable: true,
  12666. configurable: true
  12667. });
  12668. Object.defineProperty(Canvas2D.prototype, "_engineData", {
  12669. /**
  12670. * Access the babylon.js' engine bound data, do not invoke this method, it's for internal purpose only
  12671. * @returns {}
  12672. */
  12673. get: function () {
  12674. return this.__engineData;
  12675. },
  12676. enumerable: true,
  12677. configurable: true
  12678. });
  12679. Canvas2D.prototype.createCanvasProfileInfoCanvas = function () {
  12680. if (this._profilingCanvas) {
  12681. return this._profilingCanvas;
  12682. }
  12683. var canvas = new ScreenSpaceCanvas2D(this.scene, {
  12684. id: "ProfileInfoCanvas", cachingStrategy: Canvas2D_1.CACHESTRATEGY_DONTCACHE, children: [
  12685. new BABYLON.Rectangle2D({
  12686. id: "ProfileBorder", border: "#FFFFFFFF", borderThickness: 2, roundRadius: 5, fill: "#C04040C0", marginAlignment: "h: left, v: top", margin: "10", padding: "10", children: [
  12687. new BABYLON.Text2D("Stats", { id: "ProfileInfoText", marginAlignment: "h: left, v: top", fontName: "12pt Lucida Console", fontSignedDistanceField: true })
  12688. ]
  12689. })
  12690. ]
  12691. });
  12692. this._profileInfoText = canvas.findById("ProfileInfoText");
  12693. this._profilingCanvas = canvas;
  12694. return canvas;
  12695. };
  12696. Canvas2D.prototype.checkBackgroundAvailability = function () {
  12697. if (this._cachingStrategy === Canvas2D_1.CACHESTRATEGY_TOPLEVELGROUPS) {
  12698. throw Error("Can't use Canvas Background with the caching strategy TOPLEVELGROUPS");
  12699. }
  12700. };
  12701. Canvas2D.prototype._initPerfMetrics = function () {
  12702. this._drawCallsOpaqueCounter.fetchNewFrame();
  12703. this._drawCallsAlphaTestCounter.fetchNewFrame();
  12704. this._drawCallsTransparentCounter.fetchNewFrame();
  12705. this._groupRenderCounter.fetchNewFrame();
  12706. this._updateTransparentDataCounter.fetchNewFrame();
  12707. this._cachedGroupRenderCounter.fetchNewFrame();
  12708. this._updateCachedStateCounter.fetchNewFrame();
  12709. this._updateLayoutCounter.fetchNewFrame();
  12710. this._updatePositioningCounter.fetchNewFrame();
  12711. this._updateLocalTransformCounter.fetchNewFrame();
  12712. this._updateGlobalTransformCounter.fetchNewFrame();
  12713. this._boundingInfoRecomputeCounter.fetchNewFrame();
  12714. };
  12715. Canvas2D.prototype._fetchPerfMetrics = function () {
  12716. this._drawCallsOpaqueCounter.addCount(0, true);
  12717. this._drawCallsAlphaTestCounter.addCount(0, true);
  12718. this._drawCallsTransparentCounter.addCount(0, true);
  12719. this._groupRenderCounter.addCount(0, true);
  12720. this._updateTransparentDataCounter.addCount(0, true);
  12721. this._cachedGroupRenderCounter.addCount(0, true);
  12722. this._updateCachedStateCounter.addCount(0, true);
  12723. this._updateLayoutCounter.addCount(0, true);
  12724. this._updatePositioningCounter.addCount(0, true);
  12725. this._updateLocalTransformCounter.addCount(0, true);
  12726. this._updateGlobalTransformCounter.addCount(0, true);
  12727. this._boundingInfoRecomputeCounter.addCount(0, true);
  12728. };
  12729. Canvas2D.prototype._updateProfileCanvas = function () {
  12730. if (this._profileInfoText == null) {
  12731. return;
  12732. }
  12733. var format = function (v) { return (Math.round(v * 100) / 100).toString(); };
  12734. var p = "Draw Calls:\n" +
  12735. (" - Opaque: " + format(this.drawCallsOpaqueCounter.current) + ", (avg:" + format(this.drawCallsOpaqueCounter.lastSecAverage) + ", t:" + format(this.drawCallsOpaqueCounter.total) + ")\n") +
  12736. (" - AlphaTest: " + format(this.drawCallsAlphaTestCounter.current) + ", (avg:" + format(this.drawCallsAlphaTestCounter.lastSecAverage) + ", t:" + format(this.drawCallsAlphaTestCounter.total) + ")\n") +
  12737. (" - Transparent: " + format(this.drawCallsTransparentCounter.current) + ", (avg:" + format(this.drawCallsTransparentCounter.lastSecAverage) + ", t:" + format(this.drawCallsTransparentCounter.total) + ")\n") +
  12738. ("Group Render: " + this.groupRenderCounter.current + ", (avg:" + format(this.groupRenderCounter.lastSecAverage) + ", t:" + format(this.groupRenderCounter.total) + ")\n") +
  12739. ("Update Transparent Data: " + this.updateTransparentDataCounter.current + ", (avg:" + format(this.updateTransparentDataCounter.lastSecAverage) + ", t:" + format(this.updateTransparentDataCounter.total) + ")\n") +
  12740. ("Cached Group Render: " + this.cachedGroupRenderCounter.current + ", (avg:" + format(this.cachedGroupRenderCounter.lastSecAverage) + ", t:" + format(this.cachedGroupRenderCounter.total) + ")\n") +
  12741. ("Update Cached States: " + this.updateCachedStateCounter.current + ", (avg:" + format(this.updateCachedStateCounter.lastSecAverage) + ", t:" + format(this.updateCachedStateCounter.total) + ")\n") +
  12742. (" - Update Layout: " + this.updateLayoutCounter.current + ", (avg:" + format(this.updateLayoutCounter.lastSecAverage) + ", t:" + format(this.updateLayoutCounter.total) + ")\n") +
  12743. (" - Update Positioning: " + this.updatePositioningCounter.current + ", (avg:" + format(this.updatePositioningCounter.lastSecAverage) + ", t:" + format(this.updatePositioningCounter.total) + ")\n") +
  12744. (" - Update Local Trans: " + this.updateLocalTransformCounter.current + ", (avg:" + format(this.updateLocalTransformCounter.lastSecAverage) + ", t:" + format(this.updateLocalTransformCounter.total) + ")\n") +
  12745. (" - Update Global Trans: " + this.updateGlobalTransformCounter.current + ", (avg:" + format(this.updateGlobalTransformCounter.lastSecAverage) + ", t:" + format(this.updateGlobalTransformCounter.total) + ")\n") +
  12746. (" - BoundingInfo Recompute: " + this.boundingInfoRecomputeCounter.current + ", (avg:" + format(this.boundingInfoRecomputeCounter.lastSecAverage) + ", t:" + format(this.boundingInfoRecomputeCounter.total) + ")");
  12747. this._profileInfoText.text = p;
  12748. };
  12749. Canvas2D.prototype._addDrawCallCount = function (count, renderMode) {
  12750. switch (renderMode) {
  12751. case BABYLON.Render2DContext.RenderModeOpaque:
  12752. this._drawCallsOpaqueCounter.addCount(count, false);
  12753. return;
  12754. case BABYLON.Render2DContext.RenderModeAlphaTest:
  12755. this._drawCallsAlphaTestCounter.addCount(count, false);
  12756. return;
  12757. case BABYLON.Render2DContext.RenderModeTransparent:
  12758. this._drawCallsTransparentCounter.addCount(count, false);
  12759. return;
  12760. }
  12761. };
  12762. Canvas2D.prototype._addGroupRenderCount = function (count) {
  12763. this._groupRenderCounter.addCount(count, false);
  12764. };
  12765. Canvas2D.prototype._addUpdateTransparentDataCount = function (count) {
  12766. this._updateTransparentDataCounter.addCount(count, false);
  12767. };
  12768. Canvas2D.prototype.addCachedGroupRenderCounter = function (count) {
  12769. this._cachedGroupRenderCounter.addCount(count, false);
  12770. };
  12771. Canvas2D.prototype.addUpdateCachedStateCounter = function (count) {
  12772. this._updateCachedStateCounter.addCount(count, false);
  12773. };
  12774. Canvas2D.prototype.addUpdateLayoutCounter = function (count) {
  12775. this._updateLayoutCounter.addCount(count, false);
  12776. };
  12777. Canvas2D.prototype.addUpdatePositioningCounter = function (count) {
  12778. this._updatePositioningCounter.addCount(count, false);
  12779. };
  12780. Canvas2D.prototype.addupdateLocalTransformCounter = function (count) {
  12781. this._updateLocalTransformCounter.addCount(count, false);
  12782. };
  12783. Canvas2D.prototype.addUpdateGlobalTransformCounter = function (count) {
  12784. this._updateGlobalTransformCounter.addCount(count, false);
  12785. };
  12786. Canvas2D.prototype._updateTrackedNodes = function () {
  12787. var cam = this.scene.cameraToUseForPointers || this.scene.activeCamera;
  12788. cam.getViewMatrix().multiplyToRef(cam.getProjectionMatrix(), Canvas2D_1._m);
  12789. var rh = this.engine.getRenderHeight();
  12790. var v = cam.viewport.toGlobal(this.engine.getRenderWidth(), rh);
  12791. for (var _i = 0, _a = this._trackedGroups; _i < _a.length; _i++) {
  12792. var group = _a[_i];
  12793. if (group.isDisposed || !group.isVisible) {
  12794. continue;
  12795. }
  12796. var node = group.trackedNode;
  12797. var worldMtx = node.getWorldMatrix();
  12798. var proj = BABYLON.Vector3.Project(Canvas2D_1._v, worldMtx, Canvas2D_1._m, v);
  12799. // Set the visibility state accordingly, if the position is outside the frustum (well on the Z planes only...) set the group to hidden
  12800. group.levelVisible = proj.z >= 0 && proj.z < 1.0;
  12801. var s = this.scale;
  12802. group.x = Math.round(proj.x / s);
  12803. group.y = Math.round((rh - proj.y) / s);
  12804. }
  12805. };
  12806. /**
  12807. * Call this method change you want to have layout related data computed and up to date (layout area, primitive area, local/global transformation matrices)
  12808. */
  12809. Canvas2D.prototype.updateCanvasLayout = function (forceRecompute) {
  12810. this._updateCanvasState(forceRecompute);
  12811. };
  12812. Canvas2D.prototype._updateAdaptiveSizeWorldCanvas = function () {
  12813. if (this._globalTransformStep < 2) {
  12814. return;
  12815. }
  12816. var n = this.worldSpaceCanvasNode;
  12817. var bi = n.getBoundingInfo().boundingBox;
  12818. var v = bi.vectorsWorld;
  12819. var cam = this.scene.cameraToUseForPointers || this.scene.activeCamera;
  12820. cam.getViewMatrix().multiplyToRef(cam.getProjectionMatrix(), Canvas2D_1._m);
  12821. var vp = cam.viewport.toGlobal(this.engine.getRenderWidth(), this.engine.getRenderHeight());
  12822. var projPoints = new Array(4);
  12823. for (var i = 0; i < 4; i++) {
  12824. projPoints[i] = BABYLON.Vector3.Project(v[i], Canvas2D_1._mI, Canvas2D_1._m, vp);
  12825. }
  12826. var left = projPoints[3].subtract(projPoints[0]).length();
  12827. var top = projPoints[3].subtract(projPoints[1]).length();
  12828. var right = projPoints[1].subtract(projPoints[2]).length();
  12829. var bottom = projPoints[2].subtract(projPoints[0]).length();
  12830. var w = Math.round(Math.max(top, bottom));
  12831. var h = Math.round(Math.max(right, left));
  12832. var isW = w > h;
  12833. // Basically if it's under 256 we use 256, otherwise we take the biggest power of 2
  12834. var edge = Math.max(w, h);
  12835. if (edge < 256) {
  12836. edge = 256;
  12837. }
  12838. else {
  12839. edge = Math.pow(2, Math.ceil(Math.log(edge) / Math.log(2)));
  12840. }
  12841. // Clip values if needed
  12842. edge = Math.min(edge, this._maxAdaptiveWorldSpaceCanvasSize);
  12843. var newScale = edge / ((isW) ? this.size.width : this.size.height);
  12844. if (newScale !== this.scale) {
  12845. var scale = newScale;
  12846. // console.log(`New adaptive scale for Canvas ${this.id}, w: ${w}, h: ${h}, scale: ${scale}, edge: ${edge}, isW: ${isW}`);
  12847. this._setRenderingScale(scale);
  12848. }
  12849. };
  12850. Canvas2D.prototype._updateCanvasState = function (forceRecompute) {
  12851. // Check if the update has already been made for this render Frame
  12852. if (!forceRecompute && this.scene.getRenderId() === this._updateRenderId) {
  12853. return;
  12854. }
  12855. // Detect a change of rendering size
  12856. var renderingSizeChanged = false;
  12857. var newWidth = this.engine.getRenderWidth();
  12858. if (newWidth !== this._renderingSize.width) {
  12859. renderingSizeChanged = true;
  12860. }
  12861. this._renderingSize.width = newWidth;
  12862. var newHeight = this.engine.getRenderHeight();
  12863. if (newHeight !== this._renderingSize.height) {
  12864. renderingSizeChanged = true;
  12865. }
  12866. this._renderingSize.height = newHeight;
  12867. // If the canvas fit the rendering size and it changed, update
  12868. if (renderingSizeChanged && this._fitRenderingDevice) {
  12869. this._actualSize = this._renderingSize.clone();
  12870. this._size = this._renderingSize.clone();
  12871. if (this._background) {
  12872. this._background.size = this.size;
  12873. }
  12874. // Dirty the Layout at the Canvas level to recompute as the size changed
  12875. this._setLayoutDirty();
  12876. }
  12877. // If there's a design size, update the scale according to the renderingSize
  12878. if (this._designSize) {
  12879. var scale = void 0;
  12880. if (this._designUseHorizAxis) {
  12881. scale = this._renderingSize.width / this._designSize.width;
  12882. }
  12883. else {
  12884. scale = this._renderingSize.height / this._designSize.height;
  12885. }
  12886. this.size = this._designSize.clone();
  12887. this.actualSize = this._designSize.clone();
  12888. this.scale = scale;
  12889. }
  12890. var context = new BABYLON.PrepareRender2DContext();
  12891. ++this._globalTransformProcessStep;
  12892. this.updateCachedStates(false);
  12893. this._prepareGroupRender(context);
  12894. this._updateRenderId = this.scene.getRenderId();
  12895. };
  12896. /**
  12897. * Method that renders the Canvas, you should not invoke
  12898. */
  12899. Canvas2D.prototype._render = function () {
  12900. this._initPerfMetrics();
  12901. if (this._renderObservable && this._renderObservable.hasObservers()) {
  12902. this._renderObservable.notifyObservers(this, Canvas2D_1.RENDEROBSERVABLE_PRE);
  12903. }
  12904. this._updateCanvasState(false);
  12905. this._updateTrackedNodes();
  12906. // Nothing to do is the Canvas is not visible
  12907. if (this.isVisible === false) {
  12908. return;
  12909. }
  12910. if (!this._isScreenSpace) {
  12911. this._updateAdaptiveSizeWorldCanvas();
  12912. }
  12913. this._updateCanvasState(false);
  12914. if (this._primPointerInfo.canvasPointerPos) {
  12915. this._updateIntersectionList(this._primPointerInfo.canvasPointerPos, false, false);
  12916. this._updateOverStatus(false);
  12917. }
  12918. this.engine.setState(false);
  12919. this._groupRender();
  12920. if (!this._isScreenSpace) {
  12921. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagWorldCacheChanged)) {
  12922. this.worldSpaceCacheChanged();
  12923. this._clearFlags(BABYLON.SmartPropertyPrim.flagWorldCacheChanged);
  12924. }
  12925. }
  12926. // If the canvas is cached at canvas level, we must manually render the sprite that will display its content
  12927. if (this._cachingStrategy === Canvas2D_1.CACHESTRATEGY_CANVAS && this._cachedCanvasGroup) {
  12928. this._cachedCanvasGroup._renderCachedCanvas();
  12929. }
  12930. this._fetchPerfMetrics();
  12931. this._updateProfileCanvas();
  12932. if (this._renderObservable && this._renderObservable.hasObservers()) {
  12933. this._renderObservable.notifyObservers(this, Canvas2D_1.RENDEROBSERVABLE_POST);
  12934. }
  12935. };
  12936. /**
  12937. * Internal method that allocate a cache for the given group.
  12938. * Caching is made using a collection of MapTexture where many groups have their bitmap cache stored inside.
  12939. * @param group The group to allocate the cache of.
  12940. * @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.
  12941. */
  12942. Canvas2D.prototype._allocateGroupCache = function (group, parent, minSize, useMipMap, anisotropicLevel) {
  12943. if (useMipMap === void 0) { useMipMap = false; }
  12944. if (anisotropicLevel === void 0) { anisotropicLevel = 1; }
  12945. var key = (useMipMap ? "MipMap" : "NoMipMap") + "_" + anisotropicLevel;
  12946. var rd = group._renderableData;
  12947. var noResizeScale = rd._noResizeOnScale;
  12948. var isCanvas = parent == null;
  12949. var scale;
  12950. if (noResizeScale) {
  12951. scale = isCanvas ? Canvas2D_1._unS : group.parent.actualScale;
  12952. }
  12953. else {
  12954. scale = group.actualScale;
  12955. }
  12956. // Determine size
  12957. var size = group.actualSize;
  12958. size = new BABYLON.Size(Math.ceil(size.width * scale.x), Math.ceil(size.height * scale.y));
  12959. var originalSize = size.clone();
  12960. if (minSize) {
  12961. size.width = Math.max(minSize.width, size.width);
  12962. size.height = Math.max(minSize.height, size.height);
  12963. }
  12964. var mapArray = this._groupCacheMaps.getOrAddWithFactory(key, function () { return new Array(); });
  12965. // Try to find a spot in one of the cached texture
  12966. var res = null;
  12967. var map;
  12968. for (var _i = 0, mapArray_1 = mapArray; _i < mapArray_1.length; _i++) {
  12969. var _map = mapArray_1[_i];
  12970. map = _map;
  12971. var node = map.allocateRect(size);
  12972. if (node) {
  12973. res = { node: node, texture: map };
  12974. break;
  12975. }
  12976. }
  12977. // Couldn't find a map that could fit the rect, create a new map for it
  12978. if (!res) {
  12979. var mapSize = new BABYLON.Size(Canvas2D_1._groupTextureCacheSize, Canvas2D_1._groupTextureCacheSize);
  12980. // Check if the predefined size would fit, other create a custom size using the nearest bigger power of 2
  12981. if (size.width > mapSize.width || size.height > mapSize.height) {
  12982. mapSize.width = Math.pow(2, Math.ceil(Math.log(size.width) / Math.log(2)));
  12983. mapSize.height = Math.pow(2, Math.ceil(Math.log(size.height) / Math.log(2)));
  12984. }
  12985. var id = "groupsMapChache" + this._mapCounter++ + "forCanvas" + this.id;
  12986. map = new BABYLON.MapTexture(id, this._scene, mapSize, useMipMap ? BABYLON.Texture.TRILINEAR_SAMPLINGMODE : BABYLON.Texture.BILINEAR_SAMPLINGMODE, useMipMap);
  12987. map.hasAlpha = true;
  12988. map.anisotropicFilteringLevel = 4;
  12989. mapArray.splice(0, 0, map);
  12990. var node = map.allocateRect(size);
  12991. res = { node: node, texture: map };
  12992. }
  12993. // Check if we have to create a Sprite that will display the content of the Canvas which is cached.
  12994. // Don't do it in case of the group being a worldspace canvas (because its texture is bound to a WorldSpaceCanvas node)
  12995. if (group !== this || this._isScreenSpace) {
  12996. var node = res.node;
  12997. // 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
  12998. var sprite = void 0;
  12999. if (this._cachingStrategy === Canvas2D_1.CACHESTRATEGY_CANVAS) {
  13000. if (this._cachedCanvasGroup) {
  13001. this._cachedCanvasGroup.dispose();
  13002. }
  13003. this._cachedCanvasGroup = BABYLON.Group2D._createCachedCanvasGroup(this);
  13004. sprite = new BABYLON.Sprite2D(map, { parent: this._cachedCanvasGroup, id: "__cachedCanvasSprite__", spriteSize: originalSize, spriteLocation: node.pos });
  13005. sprite.zOrder = 1;
  13006. sprite.origin = BABYLON.Vector2.Zero();
  13007. }
  13008. else {
  13009. 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 });
  13010. sprite.origin = group.origin.clone();
  13011. sprite.addExternalData("__cachedGroup__", group);
  13012. sprite.pointerEventObservable.add(function (e, s) {
  13013. if (group.pointerEventObservable !== null) {
  13014. group.pointerEventObservable.notifyObservers(e, s.mask);
  13015. }
  13016. });
  13017. res.sprite = sprite;
  13018. }
  13019. if (sprite && noResizeScale) {
  13020. var relScale = isCanvas ? group.actualScale : group.actualScale.divide(group.parent.actualScale);
  13021. sprite.scaleX = relScale.x;
  13022. sprite.scaleY = relScale.y;
  13023. }
  13024. }
  13025. return res;
  13026. };
  13027. /**
  13028. * Internal method used to register a Scene Node to track position for the given group
  13029. * Do not invoke this method, for internal purpose only.
  13030. * @param group the group to track its associated Scene Node
  13031. */
  13032. Canvas2D.prototype._registerTrackedNode = function (group) {
  13033. if (group._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  13034. return;
  13035. }
  13036. this._trackedGroups.push(group);
  13037. group._setFlags(BABYLON.SmartPropertyPrim.flagTrackedGroup);
  13038. };
  13039. /**
  13040. * Internal method used to unregister a tracked Scene Node
  13041. * Do not invoke this method, it's for internal purpose only.
  13042. * @param group the group to unregister its tracked Scene Node from.
  13043. */
  13044. Canvas2D.prototype._unregisterTrackedNode = function (group) {
  13045. if (!group._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  13046. return;
  13047. }
  13048. var i = this._trackedGroups.indexOf(group);
  13049. if (i !== -1) {
  13050. this._trackedGroups.splice(i, 1);
  13051. }
  13052. group._clearFlags(BABYLON.SmartPropertyPrim.flagTrackedGroup);
  13053. };
  13054. /**
  13055. * Get a Solid Color Brush instance matching the given color.
  13056. * @param color The color to retrieve
  13057. * @return A shared instance of the SolidColorBrush2D class that use the given color
  13058. */
  13059. Canvas2D.GetSolidColorBrush = function (color) {
  13060. return Canvas2D_1._solidColorBrushes.getOrAddWithFactory(color.toHexString(), function () { return new BABYLON.SolidColorBrush2D(color.clone(), true); });
  13061. };
  13062. /**
  13063. * Get a Solid Color Brush instance matching the given color expressed as a CSS formatted hexadecimal value.
  13064. * @param color The color to retrieve
  13065. * @return A shared instance of the SolidColorBrush2D class that uses the given color
  13066. */
  13067. Canvas2D.GetSolidColorBrushFromHex = function (hexValue) {
  13068. return Canvas2D_1._solidColorBrushes.getOrAddWithFactory(hexValue, function () { return new BABYLON.SolidColorBrush2D(BABYLON.Color4.FromHexString(hexValue), true); });
  13069. };
  13070. /**
  13071. * Get a Gradient Color Brush
  13072. * @param color1 starting color
  13073. * @param color2 engine color
  13074. * @param translation translation vector to apply. default is [0;0]
  13075. * @param rotation rotation in radian to apply to the brush, initial direction is top to bottom. rotation is counter clockwise. default is 0.
  13076. * @param scale scaling factor to apply. default is 1.
  13077. */
  13078. Canvas2D.GetGradientColorBrush = function (color1, color2, translation, rotation, scale) {
  13079. if (translation === void 0) { translation = BABYLON.Vector2.Zero(); }
  13080. if (rotation === void 0) { rotation = 0; }
  13081. if (scale === void 0) { scale = 1; }
  13082. return Canvas2D_1._gradientColorBrushes.getOrAddWithFactory(BABYLON.GradientColorBrush2D.BuildKey(color1, color2, translation, rotation, scale), function () { return new BABYLON.GradientColorBrush2D(color1, color2, translation, rotation, scale, true); });
  13083. };
  13084. /**
  13085. * Create a solid or gradient brush from a string value.
  13086. * @param brushString should be either
  13087. * - "solid: #RRGGBBAA" or "#RRGGBBAA"
  13088. * - "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.
  13089. */
  13090. Canvas2D.GetBrushFromString = function (brushString) {
  13091. // Note: yes, I hate/don't know RegEx.. Feel free to add your contribution to the cause!
  13092. brushString = brushString.trim();
  13093. var split = brushString.split(",");
  13094. // Solid, formatted as: "[solid:]#FF808080"
  13095. if (split.length === 1) {
  13096. var value = null;
  13097. if (brushString.indexOf("solid:") === 0) {
  13098. value = brushString.substr(6).trim();
  13099. }
  13100. else if (brushString.indexOf("#") === 0) {
  13101. value = brushString;
  13102. }
  13103. else {
  13104. return null;
  13105. }
  13106. return Canvas2D_1.GetSolidColorBrushFromHex(value);
  13107. }
  13108. else {
  13109. if (split[0].indexOf("gradient:") === 0) {
  13110. split[0] = split[0].substr(9).trim();
  13111. }
  13112. try {
  13113. var start = BABYLON.Color4.FromHexString(split[0].trim());
  13114. var end = BABYLON.Color4.FromHexString(split[1].trim());
  13115. var t = BABYLON.Vector2.Zero();
  13116. if (split.length > 2) {
  13117. var v = split[2].trim();
  13118. if (v.charAt(0) !== "[" || v.charAt(v.length - 1) !== "]") {
  13119. return null;
  13120. }
  13121. var sep = v.indexOf(":");
  13122. var x = parseFloat(v.substr(1, sep));
  13123. var y = parseFloat(v.substr(sep + 1, v.length - (sep + 1)));
  13124. t = new BABYLON.Vector2(x, y);
  13125. }
  13126. var r = 0;
  13127. if (split.length > 3) {
  13128. r = BABYLON.Tools.ToRadians(parseFloat(split[3].trim()));
  13129. }
  13130. var s = 1;
  13131. if (split.length > 4) {
  13132. s = parseFloat(split[4].trim());
  13133. }
  13134. return Canvas2D_1.GetGradientColorBrush(start, end, t, r, s);
  13135. }
  13136. catch (e) {
  13137. return null;
  13138. }
  13139. }
  13140. };
  13141. return Canvas2D;
  13142. }(BABYLON.Group2D));
  13143. /**
  13144. * 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.
  13145. * This strategy doesn't allow primitives added directly as children of the Canvas.
  13146. * 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.
  13147. */
  13148. Canvas2D.CACHESTRATEGY_TOPLEVELGROUPS = 1;
  13149. /**
  13150. * In this strategy each group will have its own cache bitmap (except if a given group explicitly defines the DONTCACHEOVERRIDE or CACHEINPARENTGROUP behaviors).
  13151. * 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.
  13152. * When using this strategy, group instances can rely on the DONTCACHEOVERRIDE or CACHEINPARENTGROUP behaviors to minimize the amount of cached bitmaps.
  13153. * 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.
  13154. */
  13155. Canvas2D.CACHESTRATEGY_ALLGROUPS = 2;
  13156. /**
  13157. * 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).
  13158. */
  13159. Canvas2D.CACHESTRATEGY_CANVAS = 3;
  13160. /**
  13161. * This strategy is used to recompose/redraw the canvas entirely at each viewport render.
  13162. * 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).
  13163. * Note that you can't use this strategy for WorldSpace Canvas, they need at least a top level group caching.
  13164. */
  13165. Canvas2D.CACHESTRATEGY_DONTCACHE = 4;
  13166. /**
  13167. * Observable Mask to be notified before rendering is made
  13168. */
  13169. Canvas2D.RENDEROBSERVABLE_PRE = 1;
  13170. /**
  13171. * Observable Mask to be notified after rendering is made
  13172. */
  13173. Canvas2D.RENDEROBSERVABLE_POST = 2;
  13174. Canvas2D._INSTANCES = [];
  13175. Canvas2D._zMinDelta = 1 / (Math.pow(2, 24) - 1);
  13176. Canvas2D._interInfo = new BABYLON.IntersectInfo2D();
  13177. Canvas2D._v = BABYLON.Vector3.Zero(); // Must stay zero
  13178. Canvas2D._m = BABYLON.Matrix.Identity();
  13179. Canvas2D._mI = BABYLON.Matrix.Identity(); // Must stay identity
  13180. /**
  13181. * Define the default size used for both the width and height of a MapTexture to allocate.
  13182. * Note that some MapTexture might be bigger than this size if the first node to allocate is bigger in width or height
  13183. */
  13184. Canvas2D._groupTextureCacheSize = 1024;
  13185. Canvas2D._solidColorBrushes = new BABYLON.StringDictionary();
  13186. Canvas2D._gradientColorBrushes = new BABYLON.StringDictionary();
  13187. Canvas2D = Canvas2D_1 = __decorate([
  13188. BABYLON.className("Canvas2D", "BABYLON")
  13189. ], Canvas2D);
  13190. BABYLON.Canvas2D = Canvas2D;
  13191. var WorldSpaceCanvas2D = (function (_super) {
  13192. __extends(WorldSpaceCanvas2D, _super);
  13193. /**
  13194. * 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.
  13195. * 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.
  13196. * @param scene the Scene that owns the Canvas
  13197. * @param size the dimension of the Canvas in World Space
  13198. * @param settings a combination of settings, possible ones are
  13199. * - children: an array of direct children primitives
  13200. * - id: a text identifier, for information purpose only, default is null.
  13201. * - worldPosition the position of the Canvas in World Space, default is [0,0,0]
  13202. * - worldRotation the rotation of the Canvas in World Space, default is Quaternion.Identity()
  13203. * - sideOrientation: Unexpected behavior occur if the value is different from Mesh.DEFAULTSIDE right now, so please use this one, which is the default.
  13204. * - cachingStrategy Must be CACHESTRATEGY_CANVAS for now, which is the default.
  13205. * - 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).
  13206. * - isVisible: true if the canvas must be visible, false for hidden. Default is true.
  13207. * - backgroundRoundRadius: the round radius of the background, either backgroundFill or backgroundBorder must be specified.
  13208. * - 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.
  13209. * - 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.
  13210. * - backgroundBorderThickness: if a backgroundBorder is specified, its thickness can be set using this property
  13211. * - 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.
  13212. * - 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.
  13213. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  13214. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  13215. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  13216. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  13217. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  13218. */
  13219. function WorldSpaceCanvas2D(scene, size, settings) {
  13220. var _this;
  13221. BABYLON.Prim2DBase._isCanvasInit = true;
  13222. var s = settings;
  13223. s.isScreenSpace = false;
  13224. s.size = size.clone();
  13225. settings.cachingStrategy = (settings.cachingStrategy == null) ? Canvas2D.CACHESTRATEGY_CANVAS : settings.cachingStrategy;
  13226. if (settings.cachingStrategy !== Canvas2D.CACHESTRATEGY_CANVAS) {
  13227. throw new Error("Right now only the CACHESTRATEGY_CANVAS cache Strategy is supported for WorldSpace Canvas. More will come soon!");
  13228. }
  13229. _this = _super.call(this, scene, settings) || this;
  13230. BABYLON.Prim2DBase._isCanvasInit = false;
  13231. _this._renderableData._useMipMap = true;
  13232. _this._renderableData._anisotropicLevel = 8;
  13233. //if (cachingStrategy === Canvas2D.CACHESTRATEGY_DONTCACHE) {
  13234. // throw new Error("CACHESTRATEGY_DONTCACHE cache Strategy can't be used for WorldSpace Canvas");
  13235. //}
  13236. var createWorldSpaceNode = !settings || (settings.customWorldSpaceNode == null);
  13237. _this._customWorldSpaceNode = !createWorldSpaceNode;
  13238. var id = settings ? settings.id || null : null;
  13239. // Set the max size of texture allowed for the adaptive render of the world space canvas cached bitmap
  13240. var capMaxTextSize = _this.engine.getCaps().maxRenderTextureSize;
  13241. var defaultTextSize = (Math.min(capMaxTextSize, 1024)); // Default is 4K if allowed otherwise the max allowed
  13242. if (settings.maxAdaptiveCanvasSize == null) {
  13243. _this._maxAdaptiveWorldSpaceCanvasSize = defaultTextSize;
  13244. }
  13245. else {
  13246. // We still clip the given value with the max allowed, the user may not be aware of these limitations
  13247. _this._maxAdaptiveWorldSpaceCanvasSize = Math.min(settings.maxAdaptiveCanvasSize, capMaxTextSize);
  13248. }
  13249. if (createWorldSpaceNode) {
  13250. var plane = new BABYLON.WorldSpaceCanvas2DNode(id, scene, _this);
  13251. var vertexData = BABYLON.VertexData.CreatePlane({
  13252. width: size.width,
  13253. height: size.height,
  13254. sideOrientation: settings && settings.sideOrientation || BABYLON.Mesh.DEFAULTSIDE
  13255. });
  13256. var mtl = new BABYLON.StandardMaterial(id + "_Material", scene);
  13257. _this.applyCachedTexture(vertexData, mtl);
  13258. vertexData.applyToMesh(plane, true);
  13259. mtl.specularColor = new BABYLON.Color3(0, 0, 0);
  13260. mtl.disableLighting = true;
  13261. mtl.useAlphaFromDiffuseTexture = true;
  13262. plane.position = settings && settings.worldPosition || BABYLON.Vector3.Zero();
  13263. plane.rotationQuaternion = settings && settings.worldRotation || BABYLON.Quaternion.Identity();
  13264. plane.material = mtl;
  13265. _this._worldSpaceNode = plane;
  13266. }
  13267. else {
  13268. _this._worldSpaceNode = settings.customWorldSpaceNode;
  13269. _this.applyCachedTexture(null, null);
  13270. }
  13271. _this.propertyChanged.add(function (e, st) {
  13272. var mesh = _this._worldSpaceNode;
  13273. if (mesh) {
  13274. mesh.isVisible = e.newValue;
  13275. }
  13276. }, BABYLON.Prim2DBase.isVisibleProperty.flagId);
  13277. return _this;
  13278. }
  13279. WorldSpaceCanvas2D.prototype.dispose = function () {
  13280. if (!_super.prototype.dispose.call(this)) {
  13281. return false;
  13282. }
  13283. if (!this._customWorldSpaceNode && this._worldSpaceNode) {
  13284. this._worldSpaceNode.dispose();
  13285. this._worldSpaceNode = null;
  13286. }
  13287. };
  13288. return WorldSpaceCanvas2D;
  13289. }(Canvas2D));
  13290. WorldSpaceCanvas2D = __decorate([
  13291. BABYLON.className("WorldSpaceCanvas2D", "BABYLON")
  13292. ], WorldSpaceCanvas2D);
  13293. BABYLON.WorldSpaceCanvas2D = WorldSpaceCanvas2D;
  13294. var ScreenSpaceCanvas2D = (function (_super) {
  13295. __extends(ScreenSpaceCanvas2D, _super);
  13296. /**
  13297. * 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.
  13298. * 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.
  13299. * All caching strategies will be available.
  13300. * 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]
  13301. * @param scene the Scene that owns the Canvas
  13302. * @param settings a combination of settings, possible ones are
  13303. * - children: an array of direct children primitives
  13304. * - id: a text identifier, for information purpose only
  13305. * - x: the position along the x axis (horizontal), relative to the left edge of the viewport. you can alternatively use the position setting.
  13306. * - y: the position along the y axis (vertically), relative to the bottom edge of the viewport. you can alternatively use the position setting.
  13307. * - 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]
  13308. * - width: the width of the Canvas. you can alternatively use the size setting.
  13309. * - height: the height of the Canvas. you can alternatively use the size setting.
  13310. * - 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
  13311. * - 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.
  13312. * - 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.
  13313. * - 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.
  13314. * - cachingStrategy: either CACHESTRATEGY_TOPLEVELGROUPS, CACHESTRATEGY_ALLGROUPS, CACHESTRATEGY_CANVAS, CACHESTRATEGY_DONTCACHE. Please refer to their respective documentation for more information. Default is Canvas2D.CACHESTRATEGY_DONTCACHE
  13315. * - 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.
  13316. * - isVisible: true if the canvas must be visible, false for hidden. Default is true.
  13317. * - backgroundRoundRadius: the round radius of the background, either backgroundFill or backgroundBorder must be specified.
  13318. * - 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.
  13319. * - 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.
  13320. * - backgroundBorderThickness: if a backgroundBorder is specified, its thickness can be set using this property
  13321. * - 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.
  13322. * - paddingTop: top padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  13323. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  13324. * - paddingRight: right padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  13325. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  13326. * - padding: top, left, right and bottom padding formatted as a single string (see BABYLON.PrimitiveThickness.fromString)
  13327. */
  13328. function ScreenSpaceCanvas2D(scene, settings) {
  13329. var _this;
  13330. BABYLON.Prim2DBase._isCanvasInit = true;
  13331. _this = _super.call(this, scene, settings) || this;
  13332. return _this;
  13333. }
  13334. return ScreenSpaceCanvas2D;
  13335. }(Canvas2D));
  13336. ScreenSpaceCanvas2D = __decorate([
  13337. BABYLON.className("ScreenSpaceCanvas2D", "BABYLON")
  13338. ], ScreenSpaceCanvas2D);
  13339. BABYLON.ScreenSpaceCanvas2D = ScreenSpaceCanvas2D;
  13340. var Canvas2D_1;
  13341. })(BABYLON || (BABYLON = {}));
  13342. var __extends = (this && this.__extends) || function (d, b) {
  13343. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  13344. function __() { this.constructor = d; }
  13345. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13346. };
  13347. var BABYLON;
  13348. (function (BABYLON) {
  13349. /**
  13350. * This is the class that is used to display a World Space Canvas into a 3D scene
  13351. */
  13352. var WorldSpaceCanvas2DNode = (function (_super) {
  13353. __extends(WorldSpaceCanvas2DNode, _super);
  13354. function WorldSpaceCanvas2DNode(name, scene, canvas) {
  13355. var _this = _super.call(this, name, scene) || this;
  13356. _this._canvas = canvas;
  13357. return _this;
  13358. }
  13359. WorldSpaceCanvas2DNode.prototype.dispose = function () {
  13360. _super.prototype.dispose.call(this);
  13361. if (this._canvas) {
  13362. this._canvas.dispose();
  13363. this._canvas = null;
  13364. }
  13365. };
  13366. return WorldSpaceCanvas2DNode;
  13367. }(BABYLON.Mesh));
  13368. BABYLON.WorldSpaceCanvas2DNode = WorldSpaceCanvas2DNode;
  13369. })(BABYLON || (BABYLON = {}));
  13370. var __extends = (this && this.__extends) || function (d, b) {
  13371. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  13372. function __() { this.constructor = d; }
  13373. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13374. };
  13375. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  13376. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  13377. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  13378. 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;
  13379. return c > 3 && r && Object.defineProperty(target, key, r), r;
  13380. };
  13381. var BABYLON;
  13382. (function (BABYLON) {
  13383. var Command = (function () {
  13384. function Command(execute, canExecute) {
  13385. if (!execute) {
  13386. throw Error("At least an execute lambda must be given at Command creation time");
  13387. }
  13388. this._canExecuteChanged = null;
  13389. this._lastCanExecuteResult = null;
  13390. this.execute = execute;
  13391. this.canExecute = canExecute;
  13392. }
  13393. Command.prototype.canExecute = function (parameter) {
  13394. var res = true;
  13395. if (this._canExecute) {
  13396. res = this._canExecute(parameter);
  13397. }
  13398. if (res !== this._lastCanExecuteResult) {
  13399. if (this._canExecuteChanged && this._canExecuteChanged.hasObservers()) {
  13400. this._canExecuteChanged.notifyObservers(null);
  13401. }
  13402. this._lastCanExecuteResult = res;
  13403. }
  13404. return res;
  13405. };
  13406. Command.prototype.execute = function (parameter) {
  13407. this._execute(parameter);
  13408. };
  13409. Object.defineProperty(Command.prototype, "canExecuteChanged", {
  13410. get: function () {
  13411. if (!this._canExecuteChanged) {
  13412. this._canExecuteChanged = new BABYLON.Observable();
  13413. }
  13414. return this._canExecuteChanged;
  13415. },
  13416. enumerable: true,
  13417. configurable: true
  13418. });
  13419. return Command;
  13420. }());
  13421. BABYLON.Command = Command;
  13422. var UIElement = (function (_super) {
  13423. __extends(UIElement, _super);
  13424. function UIElement(settings) {
  13425. var _this = _super.call(this) || this;
  13426. if (!settings) {
  13427. throw Error("A settings object must be passed with at least either a parent or owner parameter");
  13428. }
  13429. var type = BABYLON.Tools.getFullClassName(_this);
  13430. _this._ownerWindow = null;
  13431. _this._parent = null;
  13432. _this._visualPlaceholder = null;
  13433. _this._visualTemplateRoot = null;
  13434. _this._visualChildrenPlaceholder = null;
  13435. _this._hierarchyDepth = 0;
  13436. _this._renderingTemplateName = (settings.templateName != null) ? settings.templateName : GUIManager.DefaultTemplateName;
  13437. _this._style = (settings.styleName != null) ? GUIManager.getStyle(type, settings.styleName) : null;
  13438. _this._flags = 0;
  13439. _this._id = (settings.id != null) ? settings.id : null;
  13440. _this._uid = null;
  13441. _this._width = (settings.width != null) ? settings.width : null;
  13442. _this._height = (settings.height != null) ? settings.height : null;
  13443. _this._minWidth = (settings.minWidth != null) ? settings.minWidth : 0;
  13444. _this._minHeight = (settings.minHeight != null) ? settings.minHeight : 0;
  13445. _this._maxWidth = (settings.maxWidth != null) ? settings.maxWidth : Number.MAX_VALUE;
  13446. _this._maxHeight = (settings.maxHeight != null) ? settings.maxHeight : Number.MAX_VALUE;
  13447. _this._margin = null;
  13448. _this._padding = null;
  13449. _this._marginAlignment = null;
  13450. _this._setFlags(UIElement.flagIsVisible | UIElement.flagIsEnabled);
  13451. // Default Margin Alignment for UIElement is stretch for horizontal/vertical and not left/bottom (which is the default for Canvas2D Primitives)
  13452. //this.marginAlignment.horizontal = PrimitiveAlignment.AlignStretch;
  13453. //this.marginAlignment.vertical = PrimitiveAlignment.AlignStretch;
  13454. // Set the layout/margin stuffs
  13455. if (settings.marginTop) {
  13456. _this.margin.setTop(settings.marginTop);
  13457. }
  13458. if (settings.marginLeft) {
  13459. _this.margin.setLeft(settings.marginLeft);
  13460. }
  13461. if (settings.marginRight) {
  13462. _this.margin.setRight(settings.marginRight);
  13463. }
  13464. if (settings.marginBottom) {
  13465. _this.margin.setBottom(settings.marginBottom);
  13466. }
  13467. if (settings.margin) {
  13468. if (typeof settings.margin === "string") {
  13469. _this.margin.fromString(settings.margin);
  13470. }
  13471. else {
  13472. _this.margin.fromUniformPixels(settings.margin);
  13473. }
  13474. }
  13475. if (settings.marginHAlignment) {
  13476. _this.marginAlignment.horizontal = settings.marginHAlignment;
  13477. }
  13478. if (settings.marginVAlignment) {
  13479. _this.marginAlignment.vertical = settings.marginVAlignment;
  13480. }
  13481. if (settings.marginAlignment) {
  13482. _this.marginAlignment.fromString(settings.marginAlignment);
  13483. }
  13484. if (settings.paddingTop) {
  13485. _this.padding.setTop(settings.paddingTop);
  13486. }
  13487. if (settings.paddingLeft) {
  13488. _this.padding.setLeft(settings.paddingLeft);
  13489. }
  13490. if (settings.paddingRight) {
  13491. _this.padding.setRight(settings.paddingRight);
  13492. }
  13493. if (settings.paddingBottom) {
  13494. _this.padding.setBottom(settings.paddingBottom);
  13495. }
  13496. if (settings.padding) {
  13497. _this.padding.fromString(settings.padding);
  13498. }
  13499. if (settings.paddingHAlignment) {
  13500. _this.paddingAlignment.horizontal = settings.paddingHAlignment;
  13501. }
  13502. if (settings.paddingVAlignment) {
  13503. _this.paddingAlignment.vertical = settings.paddingVAlignment;
  13504. }
  13505. if (settings.paddingAlignment) {
  13506. _this.paddingAlignment.fromString(settings.paddingAlignment);
  13507. }
  13508. if (settings.parent != null) {
  13509. _this._parent = settings.parent;
  13510. _this._hierarchyDepth = _this._parent._hierarchyDepth + 1;
  13511. }
  13512. return _this;
  13513. }
  13514. Object.defineProperty(UIElement, "enabledState", {
  13515. get: function () {
  13516. return UIElement._enableState;
  13517. },
  13518. enumerable: true,
  13519. configurable: true
  13520. });
  13521. Object.defineProperty(UIElement, "disabledState", {
  13522. get: function () {
  13523. return UIElement._disabledState;
  13524. },
  13525. enumerable: true,
  13526. configurable: true
  13527. });
  13528. Object.defineProperty(UIElement, "mouseOverState", {
  13529. get: function () {
  13530. return UIElement._mouseOverState;
  13531. },
  13532. enumerable: true,
  13533. configurable: true
  13534. });
  13535. UIElement.prototype.dispose = function () {
  13536. if (this.isDisposed) {
  13537. return false;
  13538. }
  13539. if (this._renderingTemplate) {
  13540. this._renderingTemplate.detach();
  13541. this._renderingTemplate = null;
  13542. }
  13543. _super.prototype.dispose.call(this);
  13544. // Don't set to null, it may upset somebody...
  13545. this.animations.splice(0);
  13546. return true;
  13547. };
  13548. /**
  13549. * Returns as a new array populated with the Animatable used by the primitive. Must be overloaded by derived primitives.
  13550. * Look at Sprite2D for more information
  13551. */
  13552. UIElement.prototype.getAnimatables = function () {
  13553. return new Array();
  13554. };
  13555. // TODO
  13556. // PROPERTIES
  13557. // Style
  13558. // Id
  13559. // Parent/Children
  13560. // ActualWidth/Height, MinWidth/Height, MaxWidth/Height,
  13561. // Alignment/Margin
  13562. // Visibility, IsVisible
  13563. // IsEnabled (is false, control is disabled, no interaction and a specific render state)
  13564. // CacheMode of Visual Elements
  13565. // Focusable/IsFocused
  13566. // IsPointerCaptured, CapturePointer, IsPointerDirectlyOver, IsPointerOver. De-correlate mouse, stylus, touch?
  13567. // ContextMenu
  13568. // Cursor
  13569. // DesiredSize
  13570. // IsInputEnable ?
  13571. // Opacity, OpacityMask ?
  13572. // SnapToDevicePixels
  13573. // Tag
  13574. // ToolTip
  13575. // METHODS
  13576. // BringIntoView (for scrollable content, to move the scroll to bring the given element visible in the parent's area)
  13577. // Capture/ReleaseCapture (mouse, touch, stylus)
  13578. // Focus
  13579. // PointFrom/ToScreen to translate coordinates
  13580. // EVENTS
  13581. // ContextMenuOpening/Closing/Changed
  13582. // DragEnter/LeaveOver, Drop
  13583. // Got/LostFocus
  13584. // IsEnabledChanged
  13585. // IsPointerOver/DirectlyOverChanged
  13586. // IsVisibleChanged
  13587. // KeyDown/Up
  13588. // LayoutUpdated ?
  13589. // Pointer related events
  13590. // SizeChanged
  13591. // ToolTipOpening/Closing
  13592. UIElement.prototype.findById = function (id) {
  13593. if (this._id === id) {
  13594. return this;
  13595. }
  13596. var children = this._getChildren();
  13597. for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
  13598. var child = children_1[_i];
  13599. var r = child.findById(id);
  13600. if (r != null) {
  13601. return r;
  13602. }
  13603. }
  13604. };
  13605. Object.defineProperty(UIElement.prototype, "ownerWindow", {
  13606. get: function () {
  13607. return this._ownerWindow;
  13608. },
  13609. enumerable: true,
  13610. configurable: true
  13611. });
  13612. Object.defineProperty(UIElement.prototype, "style", {
  13613. get: function () {
  13614. if (!this.style) {
  13615. return GUIManager.DefaultStyleName;
  13616. }
  13617. return this._style.name;
  13618. },
  13619. set: function (value) {
  13620. if (this._style && (this._style.name === value)) {
  13621. return;
  13622. }
  13623. var newStyle = null;
  13624. if (value) {
  13625. newStyle = GUIManager.getStyle(BABYLON.Tools.getFullClassName(this), value);
  13626. if (!newStyle) {
  13627. throw Error("Couldn't find Style " + value + " for UIElement " + BABYLON.Tools.getFullClassName(this));
  13628. }
  13629. }
  13630. if (this._style) {
  13631. this._style.removeStyle(this);
  13632. }
  13633. if (newStyle) {
  13634. newStyle.applyStyle(this);
  13635. }
  13636. this._style = newStyle;
  13637. },
  13638. enumerable: true,
  13639. configurable: true
  13640. });
  13641. Object.defineProperty(UIElement.prototype, "id", {
  13642. /**
  13643. * A string that identifies the UIElement.
  13644. * The id is optional and there's possible collision with other UIElement's id as the uniqueness is not supported.
  13645. */
  13646. get: function () {
  13647. return this._id;
  13648. },
  13649. set: function (value) {
  13650. if (this._id === value) {
  13651. return;
  13652. }
  13653. this._id = value;
  13654. },
  13655. enumerable: true,
  13656. configurable: true
  13657. });
  13658. Object.defineProperty(UIElement.prototype, "uid", {
  13659. /**
  13660. * Return a unique id automatically generated.
  13661. * This property is mainly used for serialization to ensure a perfect way of identifying a UIElement
  13662. */
  13663. get: function () {
  13664. if (!this._uid) {
  13665. this._uid = BABYLON.Tools.RandomId();
  13666. }
  13667. return this._uid;
  13668. },
  13669. enumerable: true,
  13670. configurable: true
  13671. });
  13672. Object.defineProperty(UIElement.prototype, "hierarchyDepth", {
  13673. get: function () {
  13674. return this._hierarchyDepth;
  13675. },
  13676. enumerable: true,
  13677. configurable: true
  13678. });
  13679. Object.defineProperty(UIElement.prototype, "parent", {
  13680. get: function () {
  13681. return this._parent;
  13682. },
  13683. set: function (value) {
  13684. this._parent = value;
  13685. },
  13686. enumerable: true,
  13687. configurable: true
  13688. });
  13689. Object.defineProperty(UIElement.prototype, "width", {
  13690. get: function () {
  13691. return this._width;
  13692. },
  13693. set: function (value) {
  13694. this._width = value;
  13695. },
  13696. enumerable: true,
  13697. configurable: true
  13698. });
  13699. Object.defineProperty(UIElement.prototype, "height", {
  13700. get: function () {
  13701. return this._height;
  13702. },
  13703. set: function (value) {
  13704. this._height = value;
  13705. },
  13706. enumerable: true,
  13707. configurable: true
  13708. });
  13709. Object.defineProperty(UIElement.prototype, "minWidth", {
  13710. get: function () {
  13711. return this._minWidth;
  13712. },
  13713. set: function (value) {
  13714. this._minWidth = value;
  13715. },
  13716. enumerable: true,
  13717. configurable: true
  13718. });
  13719. Object.defineProperty(UIElement.prototype, "minHheight", {
  13720. get: function () {
  13721. return this._minHeight;
  13722. },
  13723. enumerable: true,
  13724. configurable: true
  13725. });
  13726. Object.defineProperty(UIElement.prototype, "minHeight", {
  13727. set: function (value) {
  13728. this._minHeight = value;
  13729. },
  13730. enumerable: true,
  13731. configurable: true
  13732. });
  13733. Object.defineProperty(UIElement.prototype, "maxWidth", {
  13734. get: function () {
  13735. return this._maxWidth;
  13736. },
  13737. set: function (value) {
  13738. this._maxWidth = value;
  13739. },
  13740. enumerable: true,
  13741. configurable: true
  13742. });
  13743. Object.defineProperty(UIElement.prototype, "maxHeight", {
  13744. get: function () {
  13745. return this._maxHeight;
  13746. },
  13747. set: function (value) {
  13748. this._maxHeight = value;
  13749. },
  13750. enumerable: true,
  13751. configurable: true
  13752. });
  13753. Object.defineProperty(UIElement.prototype, "actualWidth", {
  13754. get: function () {
  13755. return this._actualWidth;
  13756. },
  13757. set: function (value) {
  13758. this._actualWidth = value;
  13759. },
  13760. enumerable: true,
  13761. configurable: true
  13762. });
  13763. Object.defineProperty(UIElement.prototype, "actualHeight", {
  13764. get: function () {
  13765. return this._actualHeight;
  13766. },
  13767. set: function (value) {
  13768. this._actualHeight = value;
  13769. },
  13770. enumerable: true,
  13771. configurable: true
  13772. });
  13773. Object.defineProperty(UIElement.prototype, "margin", {
  13774. get: function () {
  13775. var _this = this;
  13776. if (!this._margin) {
  13777. this._margin = new BABYLON.PrimitiveThickness(function () {
  13778. if (!_this.parent) {
  13779. return null;
  13780. }
  13781. return _this.parent.margin;
  13782. });
  13783. }
  13784. return this._margin;
  13785. },
  13786. set: function (value) {
  13787. this.margin.copyFrom(value);
  13788. },
  13789. enumerable: true,
  13790. configurable: true
  13791. });
  13792. Object.defineProperty(UIElement.prototype, "_hasMargin", {
  13793. get: function () {
  13794. return (this._margin !== null && !this._margin.isDefault) || (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  13795. },
  13796. enumerable: true,
  13797. configurable: true
  13798. });
  13799. Object.defineProperty(UIElement.prototype, "padding", {
  13800. get: function () {
  13801. var _this = this;
  13802. if (!this._padding) {
  13803. this._padding = new BABYLON.PrimitiveThickness(function () {
  13804. if (!_this.parent) {
  13805. return null;
  13806. }
  13807. return _this.parent.padding;
  13808. });
  13809. }
  13810. return this._padding;
  13811. },
  13812. set: function (value) {
  13813. this.padding.copyFrom(value);
  13814. },
  13815. enumerable: true,
  13816. configurable: true
  13817. });
  13818. Object.defineProperty(UIElement.prototype, "_hasPadding", {
  13819. get: function () {
  13820. return this._padding !== null && !this._padding.isDefault;
  13821. },
  13822. enumerable: true,
  13823. configurable: true
  13824. });
  13825. Object.defineProperty(UIElement.prototype, "marginAlignment", {
  13826. get: function () {
  13827. if (!this._marginAlignment) {
  13828. this._marginAlignment = new BABYLON.PrimitiveAlignment();
  13829. }
  13830. return this._marginAlignment;
  13831. },
  13832. set: function (value) {
  13833. this.marginAlignment.copyFrom(value);
  13834. },
  13835. enumerable: true,
  13836. configurable: true
  13837. });
  13838. Object.defineProperty(UIElement.prototype, "_hasMarginAlignment", {
  13839. /**
  13840. * Check if there a marginAlignment specified (non null and not default)
  13841. */
  13842. get: function () {
  13843. return (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  13844. },
  13845. enumerable: true,
  13846. configurable: true
  13847. });
  13848. Object.defineProperty(UIElement.prototype, "paddingAlignment", {
  13849. get: function () {
  13850. if (!this._paddingAlignment) {
  13851. this._paddingAlignment = new BABYLON.PrimitiveAlignment();
  13852. }
  13853. return this._paddingAlignment;
  13854. },
  13855. set: function (value) {
  13856. this.paddingAlignment.copyFrom(value);
  13857. },
  13858. enumerable: true,
  13859. configurable: true
  13860. });
  13861. Object.defineProperty(UIElement.prototype, "_hasPaddingAlignment", {
  13862. /**
  13863. * Check if there a marginAlignment specified (non null and not default)
  13864. */
  13865. get: function () {
  13866. return (this._paddingAlignment !== null && !this._paddingAlignment.isDefault);
  13867. },
  13868. enumerable: true,
  13869. configurable: true
  13870. });
  13871. Object.defineProperty(UIElement.prototype, "isVisible", {
  13872. get: function () {
  13873. return this._isFlagSet(UIElement.flagIsVisible);
  13874. },
  13875. set: function (value) {
  13876. if (this.isVisible === value) {
  13877. return;
  13878. }
  13879. this._visualPlaceholder.levelVisible = value;
  13880. this._changeFlags(UIElement.flagIsVisible, value);
  13881. },
  13882. enumerable: true,
  13883. configurable: true
  13884. });
  13885. Object.defineProperty(UIElement.prototype, "isEnabled", {
  13886. get: function () {
  13887. return this._isFlagSet(UIElement.flagIsEnabled);
  13888. },
  13889. set: function (value) {
  13890. this._changeFlags(UIElement.flagIsEnabled, value);
  13891. },
  13892. enumerable: true,
  13893. configurable: true
  13894. });
  13895. Object.defineProperty(UIElement.prototype, "isFocused", {
  13896. get: function () {
  13897. return this._isFlagSet(UIElement.flagIsFocus);
  13898. },
  13899. set: function (value) {
  13900. // If the UIElement doesn't accept focus, set it on its parent
  13901. if (!this.isFocusable) {
  13902. var p = this.parent;
  13903. if (!p) {
  13904. return;
  13905. }
  13906. p.isFocused = value;
  13907. }
  13908. // If the focus is being set, notify the Focus Manager
  13909. if (value) {
  13910. this.ownerWindow.focusManager.setFocusOn(this, this.getFocusScope());
  13911. }
  13912. this._changeFlags(UIElement.flagIsFocus, value);
  13913. },
  13914. enumerable: true,
  13915. configurable: true
  13916. });
  13917. Object.defineProperty(UIElement.prototype, "isMouseOver", {
  13918. get: function () {
  13919. return this._isFlagSet(UIElement.flagIsMouseOver);
  13920. },
  13921. set: function (value) {
  13922. this._changeFlags(UIElement.flagIsMouseOver, value);
  13923. },
  13924. enumerable: true,
  13925. configurable: true
  13926. });
  13927. Object.defineProperty(UIElement.prototype, "isFocusScope", {
  13928. get: function () {
  13929. return this._isFlagSet(UIElement.flagIsFocusScope);
  13930. },
  13931. set: function (value) {
  13932. this._changeFlags(UIElement.flagIsFocusScope, value);
  13933. },
  13934. enumerable: true,
  13935. configurable: true
  13936. });
  13937. Object.defineProperty(UIElement.prototype, "isFocusable", {
  13938. get: function () {
  13939. return this._isFlagSet(UIElement.flagIsFocusable);
  13940. },
  13941. set: function (value) {
  13942. this._changeFlags(UIElement.flagIsFocusable, value);
  13943. },
  13944. enumerable: true,
  13945. configurable: true
  13946. });
  13947. // 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)
  13948. UIElement.prototype.getFocusScope = function () {
  13949. if (this.isFocusScope) {
  13950. return this;
  13951. }
  13952. var p = this.parent;
  13953. if (!p) {
  13954. return null;
  13955. }
  13956. return p.getFocusScope();
  13957. };
  13958. /**
  13959. * Check if a given flag is set
  13960. * @param flag the flag value
  13961. * @return true if set, false otherwise
  13962. */
  13963. UIElement.prototype._isFlagSet = function (flag) {
  13964. return (this._flags & flag) !== 0;
  13965. };
  13966. /**
  13967. * Check if all given flags are set
  13968. * @param flags the flags ORed
  13969. * @return true if all the flags are set, false otherwise
  13970. */
  13971. UIElement.prototype._areAllFlagsSet = function (flags) {
  13972. return (this._flags & flags) === flags;
  13973. };
  13974. /**
  13975. * Check if at least one flag of the given flags is set
  13976. * @param flags the flags ORed
  13977. * @return true if at least one flag is set, false otherwise
  13978. */
  13979. UIElement.prototype._areSomeFlagsSet = function (flags) {
  13980. return (this._flags & flags) !== 0;
  13981. };
  13982. /**
  13983. * Clear the given flags
  13984. * @param flags the flags to clear
  13985. */
  13986. UIElement.prototype._clearFlags = function (flags) {
  13987. this._flags &= ~flags;
  13988. };
  13989. /**
  13990. * Set the given flags to true state
  13991. * @param flags the flags ORed to set
  13992. * @return the flags state before this call
  13993. */
  13994. UIElement.prototype._setFlags = function (flags) {
  13995. var cur = this._flags;
  13996. this._flags |= flags;
  13997. return cur;
  13998. };
  13999. /**
  14000. * Change the state of the given flags
  14001. * @param flags the flags ORed to change
  14002. * @param state true to set them, false to clear them
  14003. */
  14004. UIElement.prototype._changeFlags = function (flags, state) {
  14005. if (state) {
  14006. this._flags |= flags;
  14007. }
  14008. else {
  14009. this._flags &= ~flags;
  14010. }
  14011. };
  14012. UIElement.prototype._assignTemplate = function (templateName) {
  14013. if (!templateName) {
  14014. templateName = GUIManager.DefaultTemplateName;
  14015. }
  14016. var className = BABYLON.Tools.getFullClassName(this);
  14017. if (!className) {
  14018. throw Error("Couldn't access class name of this UIElement, you have to decorate the type with the className decorator");
  14019. }
  14020. var factory = GUIManager.getRenderingTemplate(className, templateName);
  14021. if (!factory) {
  14022. throw Error("Couldn't get the renderingTemplate " + templateName + " of class " + className);
  14023. }
  14024. this._renderingTemplateName = templateName;
  14025. this._renderingTemplate = factory();
  14026. this._renderingTemplate.attach(this);
  14027. };
  14028. UIElement.prototype._createVisualTree = function () {
  14029. var parentPrim = this.ownerWindow.canvas;
  14030. if (this.parent) {
  14031. parentPrim = this.parent.visualChildrenPlaceholder;
  14032. }
  14033. if (!this._renderingTemplate) {
  14034. this._assignTemplate(this._renderingTemplateName);
  14035. }
  14036. this._visualPlaceholder = new BABYLON.Group2D({ parent: parentPrim, id: "GUI " + BABYLON.Tools.getClassName(this) + " RootGroup of " + this.id });
  14037. var p = this._visualPlaceholder;
  14038. p.addExternalData("_GUIOwnerElement_", this);
  14039. p.dataSource = this;
  14040. p.createSimpleDataBinding(BABYLON.Prim2DBase.widthProperty, "width", BABYLON.DataBinding.MODE_ONEWAY);
  14041. p.createSimpleDataBinding(BABYLON.Prim2DBase.heightProperty, "height", BABYLON.DataBinding.MODE_ONEWAY);
  14042. p.createSimpleDataBinding(BABYLON.Prim2DBase.actualWidthProperty, "actualWidth", BABYLON.DataBinding.MODE_ONEWAYTOSOURCE);
  14043. p.createSimpleDataBinding(BABYLON.Prim2DBase.actualHeightProperty, "actualHeight", BABYLON.DataBinding.MODE_ONEWAYTOSOURCE);
  14044. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginProperty, "margin", BABYLON.DataBinding.MODE_ONEWAY);
  14045. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginAlignmentProperty, "marginAlignment", BABYLON.DataBinding.MODE_ONEWAY);
  14046. this.createVisualTree();
  14047. };
  14048. UIElement.prototype._patchUIElement = function (ownerWindow, parent) {
  14049. if (ownerWindow) {
  14050. if (!this._ownerWindow) {
  14051. ownerWindow._registerVisualToBuild(this);
  14052. }
  14053. this._ownerWindow = ownerWindow;
  14054. }
  14055. this._parent = parent;
  14056. if (parent) {
  14057. this._hierarchyDepth = parent.hierarchyDepth + 1;
  14058. }
  14059. var children = this._getChildren();
  14060. if (children) {
  14061. for (var _i = 0, children_2 = children; _i < children_2.length; _i++) {
  14062. var curChild = children_2[_i];
  14063. curChild._patchUIElement(ownerWindow, this);
  14064. }
  14065. }
  14066. };
  14067. // 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.
  14068. UIElement.prototype._getDataSource = function () {
  14069. var levelDS = _super.prototype._getDataSource.call(this);
  14070. if (levelDS != null) {
  14071. return levelDS;
  14072. }
  14073. var p = this.parent;
  14074. if (p != null) {
  14075. return p.dataSource;
  14076. }
  14077. return null;
  14078. };
  14079. UIElement.prototype.createVisualTree = function () {
  14080. var res = this._renderingTemplate.createVisualTree(this, this._visualPlaceholder);
  14081. this._visualTemplateRoot = res.root;
  14082. this._visualChildrenPlaceholder = res.contentPlaceholder;
  14083. };
  14084. Object.defineProperty(UIElement.prototype, "visualPlaceholder", {
  14085. get: function () {
  14086. return this._visualPlaceholder;
  14087. },
  14088. enumerable: true,
  14089. configurable: true
  14090. });
  14091. Object.defineProperty(UIElement.prototype, "visualTemplateRoot", {
  14092. get: function () {
  14093. return this._visualTemplateRoot;
  14094. },
  14095. enumerable: true,
  14096. configurable: true
  14097. });
  14098. Object.defineProperty(UIElement.prototype, "visualChildrenPlaceholder", {
  14099. get: function () {
  14100. return this._visualChildrenPlaceholder;
  14101. },
  14102. enumerable: true,
  14103. configurable: true
  14104. });
  14105. Object.defineProperty(UIElement.prototype, "_position", {
  14106. get: function () { return null; } // TODO use abstract keyword when TS 2.0 will be approved
  14107. ,
  14108. enumerable: true,
  14109. configurable: true
  14110. });
  14111. return UIElement;
  14112. }(BABYLON.SmartPropertyBase));
  14113. UIElement.UIELEMENT_PROPCOUNT = 16;
  14114. UIElement.flagVisualToBuild = 0x0000001;
  14115. UIElement.flagIsVisible = 0x0000002;
  14116. UIElement.flagIsFocus = 0x0000004;
  14117. UIElement.flagIsFocusScope = 0x0000008;
  14118. UIElement.flagIsFocusable = 0x0000010;
  14119. UIElement.flagIsEnabled = 0x0000020;
  14120. UIElement.flagIsMouseOver = 0x0000040;
  14121. UIElement._enableState = "Enabled";
  14122. UIElement._disabledState = "Disabled";
  14123. UIElement._mouseOverState = "MouseOver";
  14124. __decorate([
  14125. BABYLON.dependencyProperty(0, function (pi) { return UIElement.parentProperty = pi; })
  14126. ], UIElement.prototype, "parent", null);
  14127. __decorate([
  14128. BABYLON.dependencyProperty(1, function (pi) { return UIElement.widthProperty = pi; })
  14129. ], UIElement.prototype, "width", null);
  14130. __decorate([
  14131. BABYLON.dependencyProperty(2, function (pi) { return UIElement.heightProperty = pi; })
  14132. ], UIElement.prototype, "height", null);
  14133. __decorate([
  14134. BABYLON.dependencyProperty(3, function (pi) { return UIElement.minWidthProperty = pi; })
  14135. ], UIElement.prototype, "minWidth", null);
  14136. __decorate([
  14137. BABYLON.dependencyProperty(4, function (pi) { return UIElement.minHeightProperty = pi; })
  14138. ], UIElement.prototype, "minHheight", null);
  14139. __decorate([
  14140. BABYLON.dependencyProperty(5, function (pi) { return UIElement.maxWidthProperty = pi; })
  14141. ], UIElement.prototype, "maxWidth", null);
  14142. __decorate([
  14143. BABYLON.dependencyProperty(6, function (pi) { return UIElement.maxHeightProperty = pi; })
  14144. ], UIElement.prototype, "maxHeight", null);
  14145. __decorate([
  14146. BABYLON.dependencyProperty(7, function (pi) { return UIElement.actualWidthProperty = pi; })
  14147. ], UIElement.prototype, "actualWidth", null);
  14148. __decorate([
  14149. BABYLON.dependencyProperty(8, function (pi) { return UIElement.actualHeightProperty = pi; })
  14150. ], UIElement.prototype, "actualHeight", null);
  14151. __decorate([
  14152. BABYLON.dynamicLevelProperty(9, function (pi) { return UIElement.marginProperty = pi; })
  14153. ], UIElement.prototype, "margin", null);
  14154. __decorate([
  14155. BABYLON.dynamicLevelProperty(10, function (pi) { return UIElement.paddingProperty = pi; })
  14156. ], UIElement.prototype, "padding", null);
  14157. __decorate([
  14158. BABYLON.dynamicLevelProperty(11, function (pi) { return UIElement.marginAlignmentProperty = pi; })
  14159. ], UIElement.prototype, "marginAlignment", null);
  14160. __decorate([
  14161. BABYLON.dynamicLevelProperty(12, function (pi) { return UIElement.paddingAlignmentProperty = pi; })
  14162. ], UIElement.prototype, "paddingAlignment", null);
  14163. __decorate([
  14164. BABYLON.dynamicLevelProperty(13, function (pi) { return UIElement.isEnabledProperty = pi; })
  14165. ], UIElement.prototype, "isEnabled", null);
  14166. __decorate([
  14167. BABYLON.dynamicLevelProperty(14, function (pi) { return UIElement.isFocusedProperty = pi; })
  14168. ], UIElement.prototype, "isFocused", null);
  14169. __decorate([
  14170. BABYLON.dynamicLevelProperty(15, function (pi) { return UIElement.isMouseOverProperty = pi; })
  14171. ], UIElement.prototype, "isMouseOver", null);
  14172. BABYLON.UIElement = UIElement;
  14173. var UIElementStyle = (function () {
  14174. function UIElementStyle() {
  14175. }
  14176. Object.defineProperty(UIElementStyle.prototype, "name", {
  14177. get: function () { return null; } // TODO use abstract keyword when TS 2.0 will be approved
  14178. ,
  14179. enumerable: true,
  14180. configurable: true
  14181. });
  14182. return UIElementStyle;
  14183. }());
  14184. BABYLON.UIElementStyle = UIElementStyle;
  14185. var GUIManager = (function () {
  14186. function GUIManager() {
  14187. }
  14188. /////////////////////////////////////////////////////////////////////////////////////////////////////
  14189. // DATA TEMPLATE MANAGER
  14190. GUIManager.registerDataTemplate = function (className, factory) {
  14191. };
  14192. // DATA TEMPLATE MANAGER
  14193. /////////////////////////////////////////////////////////////////////////////////////////////////////
  14194. /////////////////////////////////////////////////////////////////////////////////////////////////////
  14195. // STYLE MANAGER
  14196. GUIManager.getStyle = function (uiElType, styleName) {
  14197. var styles = GUIManager.stylesByUIElement.get(uiElType);
  14198. if (!styles) {
  14199. throw Error("The type " + uiElType + " is unknown, no style were registered for it.");
  14200. }
  14201. var style = styles.get(styleName);
  14202. if (!style) {
  14203. throw Error("Couldn't find Template " + styleName + " of UIElement type " + uiElType);
  14204. }
  14205. return style;
  14206. };
  14207. GUIManager.registerStyle = function (uiElType, templateName, style) {
  14208. var templates = GUIManager.stylesByUIElement.getOrAddWithFactory(uiElType, function () { return new BABYLON.StringDictionary(); });
  14209. if (templates.contains(templateName)) {
  14210. templates[templateName] = style;
  14211. }
  14212. else {
  14213. templates.add(templateName, style);
  14214. }
  14215. };
  14216. Object.defineProperty(GUIManager, "DefaultStyleName", {
  14217. get: function () {
  14218. return GUIManager._defaultStyleName;
  14219. },
  14220. set: function (value) {
  14221. GUIManager._defaultStyleName = value;
  14222. },
  14223. enumerable: true,
  14224. configurable: true
  14225. });
  14226. // STYLE MANAGER
  14227. /////////////////////////////////////////////////////////////////////////////////////////////////////
  14228. /////////////////////////////////////////////////////////////////////////////////////////////////////
  14229. // RENDERING TEMPLATE MANAGER
  14230. GUIManager.getRenderingTemplate = function (uiElType, templateName) {
  14231. var templates = GUIManager.renderingTemplatesByUIElement.get(uiElType);
  14232. if (!templates) {
  14233. throw Error("The type " + uiElType + " is unknown, no Rendering Template were registered for it.");
  14234. }
  14235. var templateFactory = templates.get(templateName);
  14236. if (!templateFactory) {
  14237. throw Error("Couldn't find Template " + templateName + " of UI Element type " + uiElType);
  14238. }
  14239. return templateFactory;
  14240. };
  14241. GUIManager.registerRenderingTemplate = function (uiElType, templateName, factory) {
  14242. var templates = GUIManager.renderingTemplatesByUIElement.getOrAddWithFactory(uiElType, function () { return new BABYLON.StringDictionary(); });
  14243. if (templates.contains(templateName)) {
  14244. templates[templateName] = factory;
  14245. }
  14246. else {
  14247. templates.add(templateName, factory);
  14248. }
  14249. };
  14250. Object.defineProperty(GUIManager, "DefaultTemplateName", {
  14251. get: function () {
  14252. return GUIManager._defaultTemplateName;
  14253. },
  14254. set: function (value) {
  14255. GUIManager._defaultTemplateName = value;
  14256. },
  14257. enumerable: true,
  14258. configurable: true
  14259. });
  14260. return GUIManager;
  14261. }());
  14262. GUIManager.stylesByUIElement = new BABYLON.StringDictionary();
  14263. GUIManager.renderingTemplatesByUIElement = new BABYLON.StringDictionary();
  14264. // RENDERING TEMPLATE MANAGER
  14265. /////////////////////////////////////////////////////////////////////////////////////////////////////
  14266. GUIManager._defaultTemplateName = "Default";
  14267. GUIManager._defaultStyleName = "Default";
  14268. BABYLON.GUIManager = GUIManager;
  14269. var UIElementRenderingTemplateBase = (function () {
  14270. function UIElementRenderingTemplateBase() {
  14271. }
  14272. UIElementRenderingTemplateBase.prototype.attach = function (owner) {
  14273. this._owner = owner;
  14274. };
  14275. UIElementRenderingTemplateBase.prototype.detach = function () {
  14276. };
  14277. Object.defineProperty(UIElementRenderingTemplateBase.prototype, "owner", {
  14278. get: function () {
  14279. return this._owner;
  14280. },
  14281. enumerable: true,
  14282. configurable: true
  14283. });
  14284. return UIElementRenderingTemplateBase;
  14285. }());
  14286. BABYLON.UIElementRenderingTemplateBase = UIElementRenderingTemplateBase;
  14287. function registerWindowRenderingTemplate(uiElType, templateName, factory) {
  14288. return function () {
  14289. GUIManager.registerRenderingTemplate(uiElType, templateName, factory);
  14290. };
  14291. }
  14292. BABYLON.registerWindowRenderingTemplate = registerWindowRenderingTemplate;
  14293. })(BABYLON || (BABYLON = {}));
  14294. var __extends = (this && this.__extends) || function (d, b) {
  14295. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14296. function __() { this.constructor = d; }
  14297. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14298. };
  14299. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14300. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14301. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14302. 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;
  14303. return c > 3 && r && Object.defineProperty(target, key, r), r;
  14304. };
  14305. var BABYLON;
  14306. (function (BABYLON) {
  14307. var StackPanel = StackPanel_1 = (function (_super) {
  14308. __extends(StackPanel, _super);
  14309. function StackPanel(settings) {
  14310. var _this;
  14311. if (!settings) {
  14312. settings = {};
  14313. }
  14314. _this = _super.call(this, settings) || this;
  14315. _this.isOrientationHorizontal = (settings.isOrientationHorizontal == null) ? true : settings.isOrientationHorizontal;
  14316. _this._children = new Array();
  14317. if (settings.children != null) {
  14318. for (var _i = 0, _a = settings.children; _i < _a.length; _i++) {
  14319. var child = _a[_i];
  14320. _this._children.push(child);
  14321. }
  14322. }
  14323. return _this;
  14324. }
  14325. Object.defineProperty(StackPanel.prototype, "isOrientationHorizontal", {
  14326. get: function () {
  14327. return this._isOrientationHorizontal;
  14328. },
  14329. set: function (value) {
  14330. this._isOrientationHorizontal = value;
  14331. },
  14332. enumerable: true,
  14333. configurable: true
  14334. });
  14335. StackPanel.prototype.createVisualTree = function () {
  14336. _super.prototype.createVisualTree.call(this);
  14337. // A StackPanel Control has a Group2D, child of the visualPlaceHolder, which is the Children placeholder.
  14338. // The Children UIElement Tree will be create inside this placeholder.
  14339. this._childrenPlaceholder = new BABYLON.Group2D({ parent: this._visualPlaceholder, id: "StackPanel Children Placeholder of " + this.id });
  14340. var p = this._childrenPlaceholder;
  14341. p.layoutEngine = this.isOrientationHorizontal ? BABYLON.StackPanelLayoutEngine.Horizontal : BABYLON.StackPanelLayoutEngine.Vertical;
  14342. // 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.
  14343. p.dataSource = this;
  14344. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginProperty, "padding", BABYLON.DataBinding.MODE_ONEWAY);
  14345. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginAlignmentProperty, "paddingAlignment", BABYLON.DataBinding.MODE_ONEWAY);
  14346. // The UIElement set the childrenPlaceholder with the visual returned by the renderingTemplate.
  14347. // But it's not the case for a StackPanel, the placeholder of UIElement Children (the content)
  14348. this._visualChildrenPlaceholder = this._childrenPlaceholder;
  14349. };
  14350. Object.defineProperty(StackPanel.prototype, "children", {
  14351. get: function () {
  14352. return this._children;
  14353. },
  14354. enumerable: true,
  14355. configurable: true
  14356. });
  14357. StackPanel.prototype._getChildren = function () {
  14358. return this.children;
  14359. };
  14360. return StackPanel;
  14361. }(BABYLON.UIElement));
  14362. StackPanel.STACKPANEL_PROPCOUNT = BABYLON.UIElement.UIELEMENT_PROPCOUNT + 3;
  14363. __decorate([
  14364. BABYLON.dependencyProperty(StackPanel_1.STACKPANEL_PROPCOUNT + 0, function (pi) { return StackPanel_1.orientationHorizontalProperty = pi; })
  14365. ], StackPanel.prototype, "isOrientationHorizontal", null);
  14366. StackPanel = StackPanel_1 = __decorate([
  14367. BABYLON.className("StackPanel", "BABYLON")
  14368. ], StackPanel);
  14369. BABYLON.StackPanel = StackPanel;
  14370. var DefaultStackPanelRenderingTemplate = DefaultStackPanelRenderingTemplate_1 = (function (_super) {
  14371. __extends(DefaultStackPanelRenderingTemplate, _super);
  14372. function DefaultStackPanelRenderingTemplate() {
  14373. return _super.apply(this, arguments) || this;
  14374. }
  14375. DefaultStackPanelRenderingTemplate.prototype.createVisualTree = function (owner, visualPlaceholder) {
  14376. return { root: visualPlaceholder, contentPlaceholder: visualPlaceholder };
  14377. };
  14378. DefaultStackPanelRenderingTemplate.prototype.attach = function (owner) {
  14379. _super.prototype.attach.call(this, owner);
  14380. };
  14381. return DefaultStackPanelRenderingTemplate;
  14382. }(BABYLON.UIElementRenderingTemplateBase));
  14383. DefaultStackPanelRenderingTemplate = DefaultStackPanelRenderingTemplate_1 = __decorate([
  14384. BABYLON.registerWindowRenderingTemplate("BABYLON.StackPanel", "Default", function () { return new DefaultStackPanelRenderingTemplate_1(); })
  14385. ], DefaultStackPanelRenderingTemplate);
  14386. BABYLON.DefaultStackPanelRenderingTemplate = DefaultStackPanelRenderingTemplate;
  14387. var StackPanel_1, DefaultStackPanelRenderingTemplate_1;
  14388. })(BABYLON || (BABYLON = {}));
  14389. var __extends = (this && this.__extends) || function (d, b) {
  14390. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14391. function __() { this.constructor = d; }
  14392. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14393. };
  14394. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14395. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14396. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14397. 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;
  14398. return c > 3 && r && Object.defineProperty(target, key, r), r;
  14399. };
  14400. var BABYLON;
  14401. (function (BABYLON) {
  14402. var Control = Control_1 = (function (_super) {
  14403. __extends(Control, _super);
  14404. function Control(settings) {
  14405. return _super.call(this, settings) || this;
  14406. }
  14407. Object.defineProperty(Control.prototype, "background", {
  14408. get: function () {
  14409. if (!this._background) {
  14410. this._background = new BABYLON.ObservableStringDictionary(false);
  14411. }
  14412. return this._background;
  14413. },
  14414. set: function (value) {
  14415. this.background.copyFrom(value);
  14416. },
  14417. enumerable: true,
  14418. configurable: true
  14419. });
  14420. Object.defineProperty(Control.prototype, "border", {
  14421. get: function () {
  14422. return this._border;
  14423. },
  14424. set: function (value) {
  14425. this._border = value;
  14426. },
  14427. enumerable: true,
  14428. configurable: true
  14429. });
  14430. Object.defineProperty(Control.prototype, "borderThickness", {
  14431. get: function () {
  14432. return this._borderThickness;
  14433. },
  14434. set: function (value) {
  14435. this._borderThickness = value;
  14436. },
  14437. enumerable: true,
  14438. configurable: true
  14439. });
  14440. Object.defineProperty(Control.prototype, "fontName", {
  14441. get: function () {
  14442. return this._fontName;
  14443. },
  14444. set: function (value) {
  14445. this._fontName = value;
  14446. },
  14447. enumerable: true,
  14448. configurable: true
  14449. });
  14450. Object.defineProperty(Control.prototype, "foreground", {
  14451. get: function () {
  14452. return this._foreground;
  14453. },
  14454. set: function (value) {
  14455. this._foreground = value;
  14456. },
  14457. enumerable: true,
  14458. configurable: true
  14459. });
  14460. return Control;
  14461. }(BABYLON.UIElement));
  14462. Control.CONTROL_PROPCOUNT = BABYLON.UIElement.UIELEMENT_PROPCOUNT + 5;
  14463. __decorate([
  14464. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 0, function (pi) { return Control_1.backgroundProperty = pi; })
  14465. ], Control.prototype, "background", null);
  14466. __decorate([
  14467. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 1, function (pi) { return Control_1.borderProperty = pi; })
  14468. ], Control.prototype, "border", null);
  14469. __decorate([
  14470. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 2, function (pi) { return Control_1.borderThicknessProperty = pi; })
  14471. ], Control.prototype, "borderThickness", null);
  14472. __decorate([
  14473. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 3, function (pi) { return Control_1.fontNameProperty = pi; })
  14474. ], Control.prototype, "fontName", null);
  14475. __decorate([
  14476. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 4, function (pi) { return Control_1.foregroundProperty = pi; })
  14477. ], Control.prototype, "foreground", null);
  14478. Control = Control_1 = __decorate([
  14479. BABYLON.className("Control", "BABYLON")
  14480. ], Control);
  14481. BABYLON.Control = Control;
  14482. var Control_1;
  14483. })(BABYLON || (BABYLON = {}));
  14484. var __extends = (this && this.__extends) || function (d, b) {
  14485. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14486. function __() { this.constructor = d; }
  14487. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14488. };
  14489. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14490. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14491. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14492. 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;
  14493. return c > 3 && r && Object.defineProperty(target, key, r), r;
  14494. };
  14495. var BABYLON;
  14496. (function (BABYLON) {
  14497. var ContentControl = ContentControl_1 = (function (_super) {
  14498. __extends(ContentControl, _super);
  14499. function ContentControl(settings) {
  14500. var _this;
  14501. if (!settings) {
  14502. settings = {};
  14503. }
  14504. _this = _super.call(this, settings) || this;
  14505. if (settings.content != null) {
  14506. _this._content = settings.content;
  14507. }
  14508. return _this;
  14509. }
  14510. ContentControl.prototype.dispose = function () {
  14511. if (this.isDisposed) {
  14512. return false;
  14513. }
  14514. if (this.content && this.content.dispose) {
  14515. this.content.dispose();
  14516. this.content = null;
  14517. }
  14518. if (this.__contentUIElement) {
  14519. this.__contentUIElement.dispose();
  14520. this.__contentUIElement = null;
  14521. }
  14522. _super.prototype.dispose.call(this);
  14523. return true;
  14524. };
  14525. Object.defineProperty(ContentControl.prototype, "content", {
  14526. get: function () {
  14527. return this._content;
  14528. },
  14529. set: function (value) {
  14530. this._content = value;
  14531. },
  14532. enumerable: true,
  14533. configurable: true
  14534. });
  14535. Object.defineProperty(ContentControl.prototype, "_contentUIElement", {
  14536. get: function () {
  14537. if (!this.__contentUIElement) {
  14538. this._buildContentUIElement();
  14539. }
  14540. return this.__contentUIElement;
  14541. },
  14542. enumerable: true,
  14543. configurable: true
  14544. });
  14545. ContentControl.prototype._createVisualTree = function () {
  14546. // Base implementation will create the Group2D for the Visual Placeholder and its Visual Tree
  14547. _super.prototype._createVisualTree.call(this);
  14548. // A Content Control has a Group2D, child of the visualPlaceHolder, which is the Content placeholder.
  14549. // The Content UIElement Tree will be create inside this placeholder.
  14550. this._contentPlaceholder = new BABYLON.Group2D({ parent: this._visualPlaceholder, id: "ContentControl Content Placeholder of " + this.id });
  14551. var p = this._contentPlaceholder;
  14552. // 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.
  14553. p.dataSource = this;
  14554. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginProperty, "padding", BABYLON.DataBinding.MODE_ONEWAY);
  14555. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginAlignmentProperty, "paddingAlignment", BABYLON.DataBinding.MODE_ONEWAY);
  14556. // The UIElement set the childrenPlaceholder with the visual returned by the renderingTemplate.
  14557. // But it's not the case for a ContentControl, the placeholder of UIElement Children (the content)
  14558. this._visualChildrenPlaceholder = this._contentPlaceholder;
  14559. };
  14560. ContentControl.prototype._buildContentUIElement = function () {
  14561. var c = this._content;
  14562. this.__contentUIElement = null;
  14563. // Already a UIElement
  14564. if (c instanceof BABYLON.UIElement) {
  14565. this.__contentUIElement = c;
  14566. }
  14567. else if ((typeof c === "string") || (typeof c === "boolean") || (typeof c === "number")) {
  14568. var l = new BABYLON.Label({ parent: this, id: "Content of " + this.id });
  14569. var binding = new BABYLON.DataBinding();
  14570. binding.propertyPathName = "content";
  14571. binding.stringFormat = function (v) { return "" + v; };
  14572. binding.dataSource = this;
  14573. l.createDataBinding(BABYLON.Label.textProperty, binding);
  14574. this.__contentUIElement = l;
  14575. }
  14576. else {
  14577. }
  14578. if (this.__contentUIElement) {
  14579. this.__contentUIElement._patchUIElement(this.ownerWindow, this);
  14580. }
  14581. };
  14582. ContentControl.prototype._getChildren = function () {
  14583. var children = new Array();
  14584. if (this.content) {
  14585. children.push(this._contentUIElement);
  14586. }
  14587. return children;
  14588. };
  14589. return ContentControl;
  14590. }(BABYLON.Control));
  14591. ContentControl.CONTENTCONTROL_PROPCOUNT = BABYLON.Control.CONTROL_PROPCOUNT + 2;
  14592. __decorate([
  14593. BABYLON.dependencyProperty(BABYLON.Control.CONTROL_PROPCOUNT + 0, function (pi) { return ContentControl_1.contentProperty = pi; })
  14594. ], ContentControl.prototype, "content", null);
  14595. ContentControl = ContentControl_1 = __decorate([
  14596. BABYLON.className("ContentControl", "BABYLON")
  14597. ], ContentControl);
  14598. BABYLON.ContentControl = ContentControl;
  14599. var ContentControl_1;
  14600. })(BABYLON || (BABYLON = {}));
  14601. var __extends = (this && this.__extends) || function (d, b) {
  14602. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14603. function __() { this.constructor = d; }
  14604. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14605. };
  14606. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14607. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14608. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14609. 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;
  14610. return c > 3 && r && Object.defineProperty(target, key, r), r;
  14611. };
  14612. var BABYLON;
  14613. (function (BABYLON) {
  14614. var FocusScopeData = (function () {
  14615. function FocusScopeData(focusScope) {
  14616. this.focusScope = focusScope;
  14617. this.focusedElement = null;
  14618. }
  14619. return FocusScopeData;
  14620. }());
  14621. var FocusManager = (function () {
  14622. function FocusManager() {
  14623. this._focusScopes = new BABYLON.StringDictionary();
  14624. this._rootScope = new FocusScopeData(null);
  14625. this._activeScope = null;
  14626. }
  14627. FocusManager.prototype.setFocusOn = function (el, focusScope) {
  14628. var fsd = (focusScope != null) ? this._focusScopes.getOrAddWithFactory(focusScope.uid, function (k) { return new FocusScopeData(focusScope); }) : this._rootScope;
  14629. if (fsd.focusedElement !== el) {
  14630. // Remove focus from current
  14631. if (fsd.focusedElement) {
  14632. fsd.focusedElement.isFocused = false;
  14633. }
  14634. fsd.focusedElement = el;
  14635. }
  14636. if (this._activeScope !== fsd) {
  14637. this._activeScope = fsd;
  14638. }
  14639. };
  14640. return FocusManager;
  14641. }());
  14642. BABYLON.FocusManager = FocusManager;
  14643. var GUISceneData = (function () {
  14644. function GUISceneData(scene) {
  14645. this.scene = scene;
  14646. this.screenSpaceCanvas = new BABYLON.ScreenSpaceCanvas2D(scene, { id: "GUI Canvas", cachingStrategy: BABYLON.Canvas2D.CACHESTRATEGY_DONTCACHE });
  14647. this.focusManager = new FocusManager();
  14648. }
  14649. return GUISceneData;
  14650. }());
  14651. var Window = Window_1 = (function (_super) {
  14652. __extends(Window, _super);
  14653. function Window(scene, settings) {
  14654. var _this;
  14655. if (!settings) {
  14656. settings = {};
  14657. }
  14658. _this = _super.call(this, settings) || this;
  14659. // Per default a Window is focus scope
  14660. _this.isFocusScope = true;
  14661. _this.isActive = false;
  14662. if (!_this._UIElementVisualToBuildList) {
  14663. _this._UIElementVisualToBuildList = new Array();
  14664. }
  14665. // Patch the owner and also the parent property through the whole tree
  14666. _this._patchUIElement(_this, null);
  14667. // Screen Space UI
  14668. if (!settings.worldPosition && !settings.worldRotation) {
  14669. _this._sceneData = Window_1.getSceneData(scene);
  14670. _this._canvas = _this._sceneData.screenSpaceCanvas;
  14671. _this._isWorldSpaceCanvas = false;
  14672. _this._left = (settings.left != null) ? settings.left : 0;
  14673. _this._bottom = (settings.bottom != null) ? settings.bottom : 0;
  14674. }
  14675. else {
  14676. var w = (settings.width == null) ? 100 : settings.width;
  14677. var h = (settings.height == null) ? 100 : settings.height;
  14678. var wpos = (settings.worldPosition == null) ? BABYLON.Vector3.Zero() : settings.worldPosition;
  14679. var wrot = (settings.worldRotation == null) ? BABYLON.Quaternion.Identity() : settings.worldRotation;
  14680. _this._canvas = new BABYLON.WorldSpaceCanvas2D(scene, new BABYLON.Size(w, h), { id: "GUI Canvas", cachingStrategy: BABYLON.Canvas2D.CACHESTRATEGY_DONTCACHE, worldPosition: wpos, worldRotation: wrot });
  14681. _this._isWorldSpaceCanvas = true;
  14682. }
  14683. _this._renderObserver = _this._canvas.renderObservable.add(function (e, s) { return _this._canvasPreRender(); }, BABYLON.Canvas2D.RENDEROBSERVABLE_PRE);
  14684. _this._disposeObserver = _this._canvas.disposeObservable.add(function (e, s) { return _this._canvasDisposed(); });
  14685. _this._canvas.propertyChanged.add(function (e, s) {
  14686. if (e.propertyName === "overPrim") {
  14687. _this._overPrimChanged(e.oldValue, e.newValue);
  14688. }
  14689. });
  14690. _this._mouseOverUIElement = null;
  14691. return _this;
  14692. }
  14693. Object.defineProperty(Window.prototype, "canvas", {
  14694. get: function () {
  14695. return this._canvas;
  14696. },
  14697. enumerable: true,
  14698. configurable: true
  14699. });
  14700. Object.defineProperty(Window.prototype, "left", {
  14701. get: function () {
  14702. return this._left;
  14703. },
  14704. set: function (value) {
  14705. var old = new BABYLON.Vector2(this._left, this._bottom);
  14706. this._left = value;
  14707. this.onPropertyChanged("_position", old, this._position);
  14708. },
  14709. enumerable: true,
  14710. configurable: true
  14711. });
  14712. Object.defineProperty(Window.prototype, "bottom", {
  14713. get: function () {
  14714. return this._bottom;
  14715. },
  14716. set: function (value) {
  14717. var old = new BABYLON.Vector2(this._left, this._bottom);
  14718. this._bottom = value;
  14719. this.onPropertyChanged("_position", old, this._position);
  14720. },
  14721. enumerable: true,
  14722. configurable: true
  14723. });
  14724. Object.defineProperty(Window.prototype, "position", {
  14725. get: function () {
  14726. return this._position;
  14727. },
  14728. set: function (value) {
  14729. this._left = value.x;
  14730. this._bottom = value.y;
  14731. },
  14732. enumerable: true,
  14733. configurable: true
  14734. });
  14735. Object.defineProperty(Window.prototype, "isActive", {
  14736. get: function () {
  14737. return this._isActive;
  14738. },
  14739. set: function (value) {
  14740. this._isActive = value;
  14741. },
  14742. enumerable: true,
  14743. configurable: true
  14744. });
  14745. Object.defineProperty(Window.prototype, "focusManager", {
  14746. get: function () {
  14747. return this._sceneData.focusManager;
  14748. },
  14749. enumerable: true,
  14750. configurable: true
  14751. });
  14752. Object.defineProperty(Window.prototype, "_position", {
  14753. get: function () {
  14754. return new BABYLON.Vector2(this.left, this.bottom);
  14755. },
  14756. enumerable: true,
  14757. configurable: true
  14758. });
  14759. Window.prototype.createVisualTree = function () {
  14760. _super.prototype.createVisualTree.call(this);
  14761. var p = this._visualPlaceholder;
  14762. p.createSimpleDataBinding(BABYLON.Group2D.positionProperty, "position");
  14763. };
  14764. Window.prototype._registerVisualToBuild = function (uiel) {
  14765. if (uiel._isFlagSet(BABYLON.UIElement.flagVisualToBuild)) {
  14766. return;
  14767. }
  14768. if (!this._UIElementVisualToBuildList) {
  14769. this._UIElementVisualToBuildList = new Array();
  14770. }
  14771. this._UIElementVisualToBuildList.push(uiel);
  14772. uiel._setFlags(BABYLON.UIElement.flagVisualToBuild);
  14773. };
  14774. Window.prototype._overPrimChanged = function (oldPrim, newPrim) {
  14775. var curOverEl = this._mouseOverUIElement;
  14776. var newOverEl = null;
  14777. var curGroup = newPrim ? newPrim.traverseUp(function (p) { return p instanceof BABYLON.Group2D; }) : null;
  14778. while (curGroup) {
  14779. var uiel = curGroup.getExternalData("_GUIOwnerElement_");
  14780. if (uiel) {
  14781. newOverEl = uiel;
  14782. break;
  14783. }
  14784. curGroup = curGroup.parent ? curGroup.parent.traverseUp(function (p) { return p instanceof BABYLON.Group2D; }) : null;
  14785. }
  14786. if (curOverEl === newOverEl) {
  14787. return;
  14788. }
  14789. if (curOverEl) {
  14790. curOverEl.isMouseOver = false;
  14791. }
  14792. if (newOverEl) {
  14793. newOverEl.isMouseOver = true;
  14794. }
  14795. this._mouseOverUIElement = newOverEl;
  14796. };
  14797. Window.prototype._canvasPreRender = function () {
  14798. // Check if we have visual to create
  14799. if (this._UIElementVisualToBuildList.length > 0) {
  14800. // Sort the UI Element to get the highest (so lowest hierarchy depth) in the hierarchy tree first
  14801. var sortedElementList = this._UIElementVisualToBuildList.sort(function (a, b) { return a.hierarchyDepth - b.hierarchyDepth; });
  14802. for (var _i = 0, sortedElementList_1 = sortedElementList; _i < sortedElementList_1.length; _i++) {
  14803. var el = sortedElementList_1[_i];
  14804. el._createVisualTree();
  14805. }
  14806. this._UIElementVisualToBuildList.splice(0);
  14807. }
  14808. };
  14809. Window.prototype._canvasDisposed = function () {
  14810. this._canvas.disposeObservable.remove(this._disposeObserver);
  14811. this._canvas.renderObservable.remove(this._renderObserver);
  14812. };
  14813. Window.getSceneData = function (scene) {
  14814. return Window_1._sceneData.getOrAddWithFactory(scene.uid, function (k) { return new GUISceneData(scene); });
  14815. };
  14816. return Window;
  14817. }(BABYLON.ContentControl));
  14818. Window.WINDOW_PROPCOUNT = BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 4;
  14819. Window._sceneData = new BABYLON.StringDictionary();
  14820. __decorate([
  14821. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 0, function (pi) { return Window_1.leftProperty = pi; })
  14822. ], Window.prototype, "left", null);
  14823. __decorate([
  14824. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 1, function (pi) { return Window_1.bottomProperty = pi; })
  14825. ], Window.prototype, "bottom", null);
  14826. __decorate([
  14827. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 2, function (pi) { return Window_1.positionProperty = pi; })
  14828. ], Window.prototype, "position", null);
  14829. __decorate([
  14830. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 3, function (pi) { return Window_1.isActiveProperty = pi; })
  14831. ], Window.prototype, "isActive", null);
  14832. Window = Window_1 = __decorate([
  14833. BABYLON.className("Window", "BABYLON")
  14834. ], Window);
  14835. BABYLON.Window = Window;
  14836. var DefaultWindowRenderingTemplate = DefaultWindowRenderingTemplate_1 = (function (_super) {
  14837. __extends(DefaultWindowRenderingTemplate, _super);
  14838. function DefaultWindowRenderingTemplate() {
  14839. return _super.apply(this, arguments) || this;
  14840. }
  14841. DefaultWindowRenderingTemplate.prototype.createVisualTree = function (owner, visualPlaceholder) {
  14842. var r = new BABYLON.Rectangle2D({ parent: visualPlaceholder, fill: "#808080FF" });
  14843. return { root: r, contentPlaceholder: r };
  14844. };
  14845. return DefaultWindowRenderingTemplate;
  14846. }(BABYLON.UIElementRenderingTemplateBase));
  14847. DefaultWindowRenderingTemplate = DefaultWindowRenderingTemplate_1 = __decorate([
  14848. BABYLON.registerWindowRenderingTemplate("BABYLON.Window", "Default", function () { return new DefaultWindowRenderingTemplate_1(); })
  14849. ], DefaultWindowRenderingTemplate);
  14850. BABYLON.DefaultWindowRenderingTemplate = DefaultWindowRenderingTemplate;
  14851. var Window_1, DefaultWindowRenderingTemplate_1;
  14852. })(BABYLON || (BABYLON = {}));
  14853. var __extends = (this && this.__extends) || function (d, b) {
  14854. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14855. function __() { this.constructor = d; }
  14856. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14857. };
  14858. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14859. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14860. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14861. 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;
  14862. return c > 3 && r && Object.defineProperty(target, key, r), r;
  14863. };
  14864. var BABYLON;
  14865. (function (BABYLON) {
  14866. var Label = Label_1 = (function (_super) {
  14867. __extends(Label, _super);
  14868. function Label(settings) {
  14869. var _this;
  14870. if (!settings) {
  14871. settings = {};
  14872. }
  14873. _this = _super.call(this, settings) || this;
  14874. if (settings.text != null) {
  14875. _this.text = settings.text;
  14876. }
  14877. return _this;
  14878. }
  14879. Object.defineProperty(Label.prototype, "_position", {
  14880. get: function () {
  14881. return BABYLON.Vector2.Zero();
  14882. },
  14883. enumerable: true,
  14884. configurable: true
  14885. });
  14886. Label.prototype._getChildren = function () {
  14887. return Label_1._emptyArray;
  14888. };
  14889. Label.prototype.createVisualTree = function () {
  14890. _super.prototype.createVisualTree.call(this);
  14891. var p = this._visualChildrenPlaceholder;
  14892. };
  14893. Object.defineProperty(Label.prototype, "text", {
  14894. get: function () {
  14895. return this._text;
  14896. },
  14897. set: function (value) {
  14898. this._text = value;
  14899. },
  14900. enumerable: true,
  14901. configurable: true
  14902. });
  14903. return Label;
  14904. }(BABYLON.Control));
  14905. Label._emptyArray = new Array();
  14906. __decorate([
  14907. BABYLON.dependencyProperty(BABYLON.Control.CONTROL_PROPCOUNT + 0, function (pi) { return Label_1.textProperty = pi; })
  14908. ], Label.prototype, "text", null);
  14909. Label = Label_1 = __decorate([
  14910. BABYLON.className("Label", "BABYLON")
  14911. ], Label);
  14912. BABYLON.Label = Label;
  14913. var DefaultLabelRenderingTemplate = DefaultLabelRenderingTemplate_1 = (function (_super) {
  14914. __extends(DefaultLabelRenderingTemplate, _super);
  14915. function DefaultLabelRenderingTemplate() {
  14916. return _super.apply(this, arguments) || this;
  14917. }
  14918. DefaultLabelRenderingTemplate.prototype.createVisualTree = function (owner, visualPlaceholder) {
  14919. var r = new BABYLON.Text2D("", { parent: visualPlaceholder });
  14920. r.createSimpleDataBinding(BABYLON.Text2D.textProperty, "text");
  14921. r.dataSource = owner;
  14922. return { root: r, contentPlaceholder: r };
  14923. };
  14924. return DefaultLabelRenderingTemplate;
  14925. }(BABYLON.UIElementRenderingTemplateBase));
  14926. DefaultLabelRenderingTemplate = DefaultLabelRenderingTemplate_1 = __decorate([
  14927. BABYLON.registerWindowRenderingTemplate("BABYLON.Label", "Default", function () { return new DefaultLabelRenderingTemplate_1(); })
  14928. ], DefaultLabelRenderingTemplate);
  14929. BABYLON.DefaultLabelRenderingTemplate = DefaultLabelRenderingTemplate;
  14930. var Label_1, DefaultLabelRenderingTemplate_1;
  14931. })(BABYLON || (BABYLON = {}));
  14932. var __extends = (this && this.__extends) || function (d, b) {
  14933. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14934. function __() { this.constructor = d; }
  14935. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14936. };
  14937. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14938. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14939. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14940. 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;
  14941. return c > 3 && r && Object.defineProperty(target, key, r), r;
  14942. };
  14943. var BABYLON;
  14944. (function (BABYLON) {
  14945. var Button = Button_1 = (function (_super) {
  14946. __extends(Button, _super);
  14947. function Button(settings) {
  14948. var _this;
  14949. if (!settings) {
  14950. settings = {};
  14951. }
  14952. _this = _super.call(this, settings) || this;
  14953. if (settings.paddingAlignment == null) {
  14954. _this.paddingAlignment.horizontal = BABYLON.PrimitiveAlignment.AlignCenter;
  14955. _this.paddingAlignment.vertical = BABYLON.PrimitiveAlignment.AlignCenter;
  14956. }
  14957. _this._normalStateBackground = new BABYLON.ObservableStringDictionary(false);
  14958. _this._normalStateBorder = new BABYLON.ObservableStringDictionary(false);
  14959. _this._defaultStateBackground = new BABYLON.ObservableStringDictionary(false);
  14960. _this._defaultStateBorder = new BABYLON.ObservableStringDictionary(false);
  14961. _this._normalStateBackground.add(BABYLON.UIElement.enabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#337AB7FF"));
  14962. _this._normalStateBackground.add(BABYLON.UIElement.disabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#7BA9D0FF"));
  14963. _this._normalStateBackground.add(BABYLON.UIElement.mouseOverState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#286090FF"));
  14964. _this._normalStateBackground.add(Button_1.pushedState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#1E496EFF"));
  14965. _this._normalStateBorder.add(BABYLON.UIElement.enabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#2E6DA4FF"));
  14966. _this._normalStateBorder.add(BABYLON.UIElement.disabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#77A0C4FF"));
  14967. _this._normalStateBorder.add(BABYLON.UIElement.mouseOverState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#204D74FF"));
  14968. _this._normalStateBorder.add(Button_1.pushedState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#2E5D9EFF"));
  14969. _this._defaultStateBackground.add(BABYLON.UIElement.enabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#FFFFFFFF"));
  14970. _this._defaultStateBackground.add(BABYLON.UIElement.disabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#FFFFFFFF"));
  14971. _this._defaultStateBackground.add(BABYLON.UIElement.mouseOverState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#E6E6E6FF"));
  14972. _this._defaultStateBackground.add(Button_1.pushedState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#D4D4D4FF"));
  14973. _this._defaultStateBorder.add(BABYLON.UIElement.enabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#CCCCCCFF"));
  14974. _this._defaultStateBorder.add(BABYLON.UIElement.disabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#DEDEDEFF"));
  14975. _this._defaultStateBorder.add(BABYLON.UIElement.mouseOverState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#ADADADFF"));
  14976. _this._defaultStateBorder.add(Button_1.pushedState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#6C8EC5FF"));
  14977. return _this;
  14978. }
  14979. Object.defineProperty(Button, "pushedState", {
  14980. get: function () {
  14981. return Button_1._pushedState;
  14982. },
  14983. enumerable: true,
  14984. configurable: true
  14985. });
  14986. Object.defineProperty(Button.prototype, "isPushed", {
  14987. get: function () {
  14988. return this._isPushed;
  14989. },
  14990. set: function (value) {
  14991. this._isPushed = value;
  14992. },
  14993. enumerable: true,
  14994. configurable: true
  14995. });
  14996. Object.defineProperty(Button.prototype, "isDefault", {
  14997. get: function () {
  14998. return this._isDefault;
  14999. },
  15000. set: function (value) {
  15001. this._isDefault = value;
  15002. },
  15003. enumerable: true,
  15004. configurable: true
  15005. });
  15006. Object.defineProperty(Button.prototype, "isOutline", {
  15007. get: function () {
  15008. return this._isOutline;
  15009. },
  15010. set: function (value) {
  15011. this._isOutline = value;
  15012. },
  15013. enumerable: true,
  15014. configurable: true
  15015. });
  15016. Object.defineProperty(Button.prototype, "clickObservable", {
  15017. get: function () {
  15018. if (!this._clickObservable) {
  15019. this._clickObservable = new BABYLON.Observable();
  15020. }
  15021. return this._clickObservable;
  15022. },
  15023. enumerable: true,
  15024. configurable: true
  15025. });
  15026. Button.prototype._raiseClick = function () {
  15027. if (this._clickObservable && this._clickObservable.hasObservers()) {
  15028. this._clickObservable.notifyObservers(this);
  15029. }
  15030. };
  15031. Button.prototype.createVisualTree = function () {
  15032. var _this = this;
  15033. _super.prototype.createVisualTree.call(this);
  15034. var p = this._visualPlaceholder;
  15035. p.pointerEventObservable.add(function (e, s) {
  15036. // check if input must be discarded
  15037. if (!_this.isVisible || !_this.isEnabled) {
  15038. return;
  15039. }
  15040. // We reject an event coming from the placeholder because it means it's on an empty spot, so it's not valid.
  15041. if (e.relatedTarget === _this._visualPlaceholder) {
  15042. return;
  15043. }
  15044. if (s.mask === BABYLON.PrimitivePointerInfo.PointerUp) {
  15045. _this._raiseClick();
  15046. _this.isPushed = false;
  15047. }
  15048. else if (s.mask === BABYLON.PrimitivePointerInfo.PointerDown) {
  15049. _this.isPushed = true;
  15050. _this.isFocused = true;
  15051. }
  15052. }, BABYLON.PrimitivePointerInfo.PointerUp | BABYLON.PrimitivePointerInfo.PointerDown);
  15053. };
  15054. Object.defineProperty(Button.prototype, "normalStateBackground", {
  15055. get: function () {
  15056. return this._normalStateBackground;
  15057. },
  15058. enumerable: true,
  15059. configurable: true
  15060. });
  15061. Object.defineProperty(Button.prototype, "defaultStateBackground", {
  15062. get: function () {
  15063. return this._defaultStateBackground;
  15064. },
  15065. enumerable: true,
  15066. configurable: true
  15067. });
  15068. Object.defineProperty(Button.prototype, "normalStateBorder", {
  15069. get: function () {
  15070. return this._normalStateBorder;
  15071. },
  15072. enumerable: true,
  15073. configurable: true
  15074. });
  15075. Object.defineProperty(Button.prototype, "defaultStateBorder", {
  15076. get: function () {
  15077. return this._defaultStateBorder;
  15078. },
  15079. enumerable: true,
  15080. configurable: true
  15081. });
  15082. return Button;
  15083. }(BABYLON.ContentControl));
  15084. Button.BUTTON_PROPCOUNT = BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 3;
  15085. Button._pushedState = "Pushed";
  15086. __decorate([
  15087. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTROL_PROPCOUNT + 0, function (pi) { return Button_1.isPushedProperty = pi; })
  15088. ], Button.prototype, "isPushed", null);
  15089. __decorate([
  15090. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTROL_PROPCOUNT + 1, function (pi) { return Button_1.isDefaultProperty = pi; })
  15091. ], Button.prototype, "isDefault", null);
  15092. __decorate([
  15093. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTROL_PROPCOUNT + 2, function (pi) { return Button_1.isOutlineProperty = pi; })
  15094. ], Button.prototype, "isOutline", null);
  15095. Button = Button_1 = __decorate([
  15096. BABYLON.className("Button", "BABYLON")
  15097. ], Button);
  15098. BABYLON.Button = Button;
  15099. var DefaultButtonRenderingTemplate = DefaultButtonRenderingTemplate_1 = (function (_super) {
  15100. __extends(DefaultButtonRenderingTemplate, _super);
  15101. function DefaultButtonRenderingTemplate() {
  15102. return _super.apply(this, arguments) || this;
  15103. }
  15104. DefaultButtonRenderingTemplate.prototype.createVisualTree = function (owner, visualPlaceholder) {
  15105. this._rect = new BABYLON.Rectangle2D({ parent: visualPlaceholder, fill: "#FF8080FF", border: "#FF8080FF", roundRadius: 10, borderThickness: 2 });
  15106. this.stateChange();
  15107. return { root: this._rect, contentPlaceholder: this._rect };
  15108. };
  15109. DefaultButtonRenderingTemplate.prototype.attach = function (owner) {
  15110. var _this = this;
  15111. _super.prototype.attach.call(this, owner);
  15112. this.owner.propertyChanged.add(function (e, s) { return _this.stateChange(); }, BABYLON.UIElement.isEnabledProperty.flagId |
  15113. BABYLON.UIElement.isFocusedProperty.flagId |
  15114. BABYLON.UIElement.isMouseOverProperty.flagId |
  15115. Button.isDefaultProperty.flagId |
  15116. Button.isOutlineProperty.flagId |
  15117. Button.isPushedProperty.flagId);
  15118. // Register for brush change and update the Visual
  15119. var button = owner;
  15120. button.normalStateBackground.dictionaryChanged.add(function (e, c) { return _this.stateChange(); });
  15121. button.normalStateBorder.dictionaryChanged.add(function (e, c) { return _this.stateChange(); });
  15122. button.defaultStateBackground.dictionaryChanged.add(function (e, c) { return _this.stateChange(); });
  15123. button.defaultStateBorder.dictionaryChanged.add(function (e, c) { return _this.stateChange(); });
  15124. };
  15125. DefaultButtonRenderingTemplate.prototype.stateChange = function () {
  15126. //console.log("state changed");
  15127. var b = this.owner;
  15128. var state = BABYLON.UIElement.enabledState;
  15129. var bg = b.isDefault ? b.defaultStateBackground.get(state) : b.normalStateBackground.get(state);
  15130. var bd = b.isDefault ? b.defaultStateBorder.get(state) : b.normalStateBorder.get(state);
  15131. if (b.isPushed) {
  15132. state = Button.pushedState;
  15133. if (b.isDefault) {
  15134. bg = b.defaultStateBackground.get(state);
  15135. bd = b.defaultStateBorder.get(state);
  15136. }
  15137. else {
  15138. bg = b.normalStateBackground.get(state);
  15139. bd = b.normalStateBorder.get(state);
  15140. }
  15141. }
  15142. else if (b.isMouseOver) {
  15143. state = BABYLON.UIElement.mouseOverState;
  15144. if (b.isDefault) {
  15145. bg = b.defaultStateBackground.get(state);
  15146. bd = b.defaultStateBorder.get(state);
  15147. }
  15148. else {
  15149. bg = b.normalStateBackground.get(state);
  15150. bd = b.normalStateBorder.get(state);
  15151. }
  15152. }
  15153. else if (!b.isEnabled) {
  15154. state = BABYLON.UIElement.disabledState;
  15155. if (b.isDefault) {
  15156. bg = b.defaultStateBackground.get(state);
  15157. bd = b.defaultStateBorder.get(state);
  15158. }
  15159. else {
  15160. bg = b.normalStateBackground.get(state);
  15161. bd = b.normalStateBorder.get(state);
  15162. }
  15163. }
  15164. this._rect.fill = bg;
  15165. this._rect.border = bd;
  15166. };
  15167. return DefaultButtonRenderingTemplate;
  15168. }(BABYLON.UIElementRenderingTemplateBase));
  15169. DefaultButtonRenderingTemplate = DefaultButtonRenderingTemplate_1 = __decorate([
  15170. BABYLON.registerWindowRenderingTemplate("BABYLON.Button", "Default", function () { return new DefaultButtonRenderingTemplate_1(); })
  15171. ], DefaultButtonRenderingTemplate);
  15172. BABYLON.DefaultButtonRenderingTemplate = DefaultButtonRenderingTemplate;
  15173. var Button_1, DefaultButtonRenderingTemplate_1;
  15174. })(BABYLON || (BABYLON = {}));