babylon.canvas2d.js 750 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222
  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. this.owner.scene.stopAnimation(this);
  5533. // If there's a parent, remove this object from its parent list
  5534. if (this._parent) {
  5535. if (this instanceof BABYLON.Group2D) {
  5536. var g = this;
  5537. if (g.isRenderableGroup) {
  5538. var parentRenderable = this.parent.traverseUp(function (p) { return (p instanceof BABYLON.Group2D && p.isRenderableGroup); });
  5539. if (parentRenderable != null) {
  5540. var l = parentRenderable._renderableData._childrenRenderableGroups;
  5541. var i_1 = l.indexOf(g);
  5542. if (i_1 !== -1) {
  5543. l.splice(i_1, 1);
  5544. }
  5545. }
  5546. }
  5547. }
  5548. var i = this._parent._children.indexOf(this);
  5549. if (i !== undefined) {
  5550. this._parent._children.splice(i, 1);
  5551. }
  5552. this._parent = null;
  5553. }
  5554. // Recurse dispose to children
  5555. if (this._children) {
  5556. while (this._children.length > 0) {
  5557. this._children[this._children.length - 1].dispose();
  5558. }
  5559. }
  5560. return true;
  5561. };
  5562. Prim2DBase.prototype.onPrimBecomesDirty = function () {
  5563. if (this._renderGroup && !this._isFlagSet(BABYLON.SmartPropertyPrim.flagPrimInDirtyList)) {
  5564. this._renderGroup._addPrimToDirtyList(this);
  5565. this._setFlags(BABYLON.SmartPropertyPrim.flagPrimInDirtyList);
  5566. }
  5567. };
  5568. Prim2DBase.prototype._needPrepare = function () {
  5569. return this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagVisibilityChanged | BABYLON.SmartPropertyPrim.flagModelDirty | BABYLON.SmartPropertyPrim.flagNeedRefresh) || (this._instanceDirtyFlags !== 0) || (this._globalTransformProcessStep !== this._globalTransformStep);
  5570. };
  5571. Prim2DBase.prototype._prepareRender = function (context) {
  5572. this._prepareRenderPre(context);
  5573. this._prepareRenderPost(context);
  5574. };
  5575. Prim2DBase.prototype._prepareRenderPre = function (context) {
  5576. };
  5577. Prim2DBase.prototype._prepareRenderPost = function (context) {
  5578. // Don't recurse if it's a renderable group, the content will be processed by the group itself
  5579. if (this instanceof BABYLON.Group2D) {
  5580. var self = this;
  5581. if (self.isRenderableGroup) {
  5582. return;
  5583. }
  5584. }
  5585. // Check if we need to recurse the prepare to children primitives
  5586. // - must have children
  5587. // - the global transform of this level have changed, or
  5588. // - the visible state of primitive has changed
  5589. if (this._children.length > 0 && ((this._globalTransformProcessStep !== this._globalTransformStep) ||
  5590. this.checkPropertiesDirty(Prim2DBase_1.isVisibleProperty.flagId))) {
  5591. this._children.forEach(function (c) {
  5592. // As usual stop the recursion if we meet a renderable group
  5593. if (!(c instanceof BABYLON.Group2D && c.isRenderableGroup)) {
  5594. c._prepareRender(context);
  5595. }
  5596. });
  5597. }
  5598. // Finally reset the dirty flags as we've processed everything
  5599. this._clearFlags(BABYLON.SmartPropertyPrim.flagModelDirty);
  5600. this._instanceDirtyFlags = 0;
  5601. };
  5602. Prim2DBase.prototype._canvasPreInit = function (settings) {
  5603. };
  5604. Prim2DBase.CheckParent = function (parent) {
  5605. //if (!Prim2DBase._isCanvasInit && !parent) {
  5606. // 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)");
  5607. //}
  5608. };
  5609. Prim2DBase.prototype.updateCachedStatesOf = function (list, recurse) {
  5610. for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
  5611. var cur = list_1[_i];
  5612. cur.updateCachedStates(recurse);
  5613. }
  5614. };
  5615. Prim2DBase.prototype._parentLayoutDirty = function () {
  5616. if (!this._parent || this._parent.isDisposed) {
  5617. return;
  5618. }
  5619. this._parent._setLayoutDirty();
  5620. };
  5621. Prim2DBase.prototype._setLayoutDirty = function () {
  5622. this.onPrimBecomesDirty();
  5623. this._setFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  5624. };
  5625. Prim2DBase.prototype._checkPositionChange = function () {
  5626. if (this.parent && this.parent.layoutEngine.isChildPositionAllowed === false) {
  5627. console.log("Can't manually set the position of " + this.id + ", the Layout Engine of its parent doesn't allow it");
  5628. return false;
  5629. }
  5630. return true;
  5631. };
  5632. Prim2DBase.prototype._positioningDirty = function () {
  5633. this.onPrimBecomesDirty();
  5634. this._setFlags(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5635. };
  5636. Prim2DBase.prototype._spreadActualOpacityChanged = function () {
  5637. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5638. var child = _a[_i];
  5639. child._setFlags(BABYLON.SmartPropertyPrim.flagActualOpacityDirty);
  5640. child._updateRenderMode();
  5641. child.onPrimBecomesDirty();
  5642. child._spreadActualOpacityChanged();
  5643. }
  5644. };
  5645. Prim2DBase.prototype._changeLayoutEngine = function (engine) {
  5646. this._layoutEngine = engine;
  5647. };
  5648. Prim2DBase.prototype._updateLocalTransform = function () {
  5649. 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;
  5650. if (this.checkPropertiesDirty(tflags)) {
  5651. if (this.owner) {
  5652. this.owner.addupdateLocalTransformCounter(1);
  5653. }
  5654. var rot = BABYLON.Quaternion.RotationAxis(new BABYLON.Vector3(0, 0, 1), this._rotation);
  5655. var local;
  5656. var pos = this._position ? this.position : this.layoutAreaPos;
  5657. if (this._origin.x === 0 && this._origin.y === 0) {
  5658. 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));
  5659. this._localTransform = local;
  5660. }
  5661. else {
  5662. // -Origin offset
  5663. var as = this.actualSize;
  5664. BABYLON.Matrix.TranslationToRef((-as.width * this._origin.x), (-as.height * this._origin.y), 0, Prim2DBase_1._t0);
  5665. // -Origin * rotation
  5666. rot.toRotationMatrix(Prim2DBase_1._t1);
  5667. Prim2DBase_1._t0.multiplyToRef(Prim2DBase_1._t1, Prim2DBase_1._t2);
  5668. // -Origin * rotation * scale
  5669. BABYLON.Matrix.ScalingToRef(this._scale.x, this._scale.y, 1, Prim2DBase_1._t0);
  5670. Prim2DBase_1._t2.multiplyToRef(Prim2DBase_1._t0, Prim2DBase_1._t1);
  5671. // -Origin * rotation * scale * (Origin + Position)
  5672. 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);
  5673. Prim2DBase_1._t1.multiplyToRef(Prim2DBase_1._t2, this._localTransform);
  5674. }
  5675. this.clearPropertiesDirty(tflags);
  5676. this._setFlags(BABYLON.SmartPropertyPrim.flagGlobalTransformDirty);
  5677. return true;
  5678. }
  5679. return false;
  5680. };
  5681. Prim2DBase.prototype.updateCachedStates = function (recurse) {
  5682. if (this.isDisposed) {
  5683. return;
  5684. }
  5685. this.owner.addCachedGroupRenderCounter(1);
  5686. // Check if the parent is synced
  5687. if (this._parent && ((this._parent._globalTransformProcessStep !== this.owner._globalTransformProcessStep) || this._parent._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagLayoutDirty | BABYLON.SmartPropertyPrim.flagPositioningDirty | BABYLON.SmartPropertyPrim.flagZOrderDirty))) {
  5688. this._parent.updateCachedStates(false);
  5689. }
  5690. // Update Z-Order if needed
  5691. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  5692. this._updateZOrder();
  5693. }
  5694. // Update actualSize only if there' not positioning to recompute and the size changed
  5695. // Otherwise positioning will take care of it.
  5696. var sizeDirty = this.checkPropertiesDirty(Prim2DBase_1.sizeProperty.flagId);
  5697. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty) && !this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty) && sizeDirty) {
  5698. var size = this.size;
  5699. if (size) {
  5700. if (this.size.width != null) {
  5701. this.actualSize.width = this.size.width;
  5702. }
  5703. if (this.size.height != null) {
  5704. this.actualSize.height = this.size.height;
  5705. }
  5706. this.clearPropertiesDirty(Prim2DBase_1.sizeProperty.flagId);
  5707. }
  5708. }
  5709. var positioningDirty = this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5710. var positioningComputed = positioningDirty && !this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5711. // Check for layout update
  5712. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty)) {
  5713. this.owner.addUpdateLayoutCounter(1);
  5714. this._layoutEngine.updateLayout(this);
  5715. this._clearFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  5716. }
  5717. var autoContentChanged = false;
  5718. if (this.isSizeAuto) {
  5719. if (!this._lastAutoSizeArea) {
  5720. autoContentChanged = this.actualSize !== null;
  5721. }
  5722. else {
  5723. autoContentChanged = (!this._lastAutoSizeArea.equals(this.actualSize));
  5724. }
  5725. }
  5726. // Check for positioning update
  5727. if (!positioningComputed && (autoContentChanged || sizeDirty || this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty) || (this._parent && !this._parent.contentArea.equals(this._parentContentArea)))) {
  5728. this._updatePositioning();
  5729. this._clearFlags(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5730. if (sizeDirty) {
  5731. this.clearPropertiesDirty(Prim2DBase_1.sizeProperty.flagId);
  5732. }
  5733. positioningComputed = true;
  5734. }
  5735. if (positioningComputed && this._parent) {
  5736. this._parentContentArea.copyFrom(this._parent.contentArea);
  5737. }
  5738. // Check if we must update this prim
  5739. if (this === this.owner || this._globalTransformProcessStep !== this.owner._globalTransformProcessStep) {
  5740. this.owner.addUpdateGlobalTransformCounter(1);
  5741. var curVisibleState = this.isVisible;
  5742. this.isVisible = (!this._parent || this._parent.isVisible) && this.levelVisible;
  5743. // Detect a change of visibility
  5744. this._changeFlags(BABYLON.SmartPropertyPrim.flagVisibilityChanged, curVisibleState !== this.isVisible);
  5745. // Get/compute the localTransform
  5746. var localDirty = this._updateLocalTransform();
  5747. var parentPaddingChanged = false;
  5748. var parentPaddingOffset = Prim2DBase_1._v0;
  5749. if (this._parent) {
  5750. parentPaddingOffset = new BABYLON.Vector2(this._parent._paddingOffset.x, this._parent._paddingOffset.y);
  5751. parentPaddingChanged = !parentPaddingOffset.equals(this._parentPaddingOffset);
  5752. }
  5753. // Check if there are changes in the parent that will force us to update the global matrix
  5754. var parentDirty = (this._parent != null) ? (this._parent._globalTransformStep !== this._parentTransformStep) : false;
  5755. // Check if we have to update the globalTransform
  5756. if (!this._globalTransform || localDirty || parentDirty || parentPaddingChanged || this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagGlobalTransformDirty)) {
  5757. var globalTransform = this._parent ? this._parent._globalTransform : null;
  5758. var localTransform = void 0;
  5759. Prim2DBase_1._transMtx.copyFrom(this._localTransform);
  5760. Prim2DBase_1._transMtx.m[12] += parentPaddingOffset.x;
  5761. Prim2DBase_1._transMtx.m[13] += parentPaddingOffset.y;
  5762. localTransform = Prim2DBase_1._transMtx;
  5763. this._globalTransform = this._parent ? localTransform.multiply(globalTransform) : localTransform.clone();
  5764. this._invGlobalTransform = BABYLON.Matrix.Invert(this._globalTransform);
  5765. this._globalTransformStep = this.owner._globalTransformProcessStep + 1;
  5766. this._parentTransformStep = this._parent ? this._parent._globalTransformStep : 0;
  5767. this._clearFlags(BABYLON.SmartPropertyPrim.flagGlobalTransformDirty);
  5768. }
  5769. this._globalTransformProcessStep = this.owner._globalTransformProcessStep;
  5770. }
  5771. if (recurse) {
  5772. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5773. var child = _a[_i];
  5774. // Stop the recursion if we meet a renderable group
  5775. child.updateCachedStates(!(child instanceof BABYLON.Group2D && child.isRenderableGroup));
  5776. }
  5777. }
  5778. };
  5779. Prim2DBase.prototype._updatePositioning = function () {
  5780. if (this.owner) {
  5781. this.owner.addUpdatePositioningCounter(1);
  5782. }
  5783. // From this point we assume that the primitive layoutArea is computed and up to date.
  5784. // We know have to :
  5785. // 1. Determine the PaddingArea and the ActualPosition based on the margin/marginAlignment properties, which will also set the size property of the primitive
  5786. // 2. Determine the contentArea based on the padding property.
  5787. var isSizeAuto = this.isSizeAuto;
  5788. // 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
  5789. if (!this._hasMarginAlignment && (isSizeAuto || (this.actualSize.width == null || this.actualSize.height == null))) {
  5790. if (isSizeAuto || this.actualSize.width == null) {
  5791. this.marginAlignment.horizontal = PrimitiveAlignment.AlignStretch;
  5792. }
  5793. if (isSizeAuto || this.actualSize.height == null) {
  5794. this.marginAlignment.vertical = PrimitiveAlignment.AlignStretch;
  5795. }
  5796. }
  5797. // Apply margin
  5798. if (this._hasMargin) {
  5799. this.margin.computeWithAlignment(this.layoutArea, this.size || this.actualSize, this.marginAlignment, this._marginOffset, Prim2DBase_1._size);
  5800. this.actualSize = Prim2DBase_1._size.clone();
  5801. }
  5802. if (this._hasPadding) {
  5803. // Two cases from here: the size of the Primitive is Auto, its content can't be shrink, so we resize the primitive itself
  5804. if (isSizeAuto) {
  5805. var content = this.size.clone();
  5806. this._getActualSizeFromContentToRef(content, Prim2DBase_1._icArea);
  5807. this.padding.enlarge(Prim2DBase_1._icArea, this._paddingOffset, Prim2DBase_1._size);
  5808. this._contentArea.copyFrom(content);
  5809. this.actualSize = Prim2DBase_1._size.clone();
  5810. // Changing the padding has resize the prim, which forces us to recompute margin again
  5811. if (this._hasMargin) {
  5812. this.margin.computeWithAlignment(this.layoutArea, Prim2DBase_1._size, this.marginAlignment, this._marginOffset, Prim2DBase_1._size);
  5813. }
  5814. }
  5815. else {
  5816. this._getInitialContentAreaToRef(this.actualSize, Prim2DBase_1._icZone, Prim2DBase_1._icArea);
  5817. Prim2DBase_1._icArea.width = Math.max(0, Prim2DBase_1._icArea.width);
  5818. Prim2DBase_1._icArea.height = Math.max(0, Prim2DBase_1._icArea.height);
  5819. this.padding.compute(Prim2DBase_1._icArea, this._paddingOffset, Prim2DBase_1._size);
  5820. this._paddingOffset.x += Prim2DBase_1._icZone.x;
  5821. this._paddingOffset.y += Prim2DBase_1._icZone.y;
  5822. this._paddingOffset.z -= Prim2DBase_1._icZone.z;
  5823. this._paddingOffset.w -= Prim2DBase_1._icZone.w;
  5824. this._contentArea.copyFrom(Prim2DBase_1._size);
  5825. }
  5826. }
  5827. else {
  5828. this._getInitialContentAreaToRef(this.actualSize, Prim2DBase_1._icZone, Prim2DBase_1._icArea);
  5829. Prim2DBase_1._icArea.width = Math.max(0, Prim2DBase_1._icArea.width);
  5830. Prim2DBase_1._icArea.height = Math.max(0, Prim2DBase_1._icArea.height);
  5831. this._paddingOffset.x = Prim2DBase_1._icZone.x;
  5832. this._paddingOffset.y = Prim2DBase_1._icZone.y;
  5833. this._paddingOffset.z = Prim2DBase_1._icZone.z;
  5834. this._paddingOffset.w = Prim2DBase_1._icZone.w;
  5835. this._contentArea.copyFrom(Prim2DBase_1._icArea);
  5836. }
  5837. if (!this._position) {
  5838. var aPos = new BABYLON.Vector2(this.layoutAreaPos.x + this._marginOffset.x, this.layoutAreaPos.y + this._marginOffset.y);
  5839. this.actualPosition = aPos;
  5840. }
  5841. if (isSizeAuto) {
  5842. this._lastAutoSizeArea = this.actualSize;
  5843. }
  5844. if (this.displayDebugAreas) {
  5845. this._updateDebugArea();
  5846. }
  5847. };
  5848. Object.defineProperty(Prim2DBase.prototype, "contentArea", {
  5849. /**
  5850. * Get the content are of this primitive, this area is computed using the padding property and also possibly the primitive type itself.
  5851. * Children of this primitive will be positioned relative to the bottom/left corner of this area.
  5852. */
  5853. get: function () {
  5854. // Check for positioning update
  5855. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty)) {
  5856. this._updatePositioning();
  5857. this._clearFlags(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5858. }
  5859. return this._contentArea;
  5860. },
  5861. enumerable: true,
  5862. configurable: true
  5863. });
  5864. Prim2DBase.prototype._patchHierarchy = function (owner) {
  5865. this._owner = owner;
  5866. // The only place we initialize the _renderGroup is this method, if it's set, we already been there, no need to execute more
  5867. if (this._renderGroup != null) {
  5868. return;
  5869. }
  5870. if (this instanceof BABYLON.Group2D) {
  5871. var group = this;
  5872. group.detectGroupStates();
  5873. if (group._trackedNode && !group._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  5874. group.owner._registerTrackedNode(this);
  5875. }
  5876. }
  5877. this._renderGroup = this.traverseUp(function (p) { return p instanceof BABYLON.Group2D && p.isRenderableGroup; });
  5878. if (this._parent) {
  5879. this._parentLayoutDirty();
  5880. }
  5881. // Make sure the prim is in the dirtyList if it should be
  5882. if (this._renderGroup && this.isDirty) {
  5883. var list = this._renderGroup._renderableData._primDirtyList;
  5884. var i = list.indexOf(this);
  5885. if (i === -1) {
  5886. list.push(this);
  5887. }
  5888. }
  5889. // Recurse
  5890. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5891. var child = _a[_i];
  5892. child._hierarchyDepth = this._hierarchyDepth + 1;
  5893. child._patchHierarchy(owner);
  5894. }
  5895. };
  5896. Prim2DBase.prototype._updateZOrder = function () {
  5897. var prevLinPos = this._primLinearPosition;
  5898. var startI = 0;
  5899. var startZ = this._zOrder;
  5900. // 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
  5901. var childrenCount = this._children.length;
  5902. if (this._firstZDirtyIndex > 0) {
  5903. if ((this._firstZDirtyIndex - 1) < childrenCount) {
  5904. var prevPrim = this._children[this._firstZDirtyIndex - 1];
  5905. prevLinPos = prevPrim._primLinearPosition;
  5906. startI = this._firstZDirtyIndex - 1;
  5907. startZ = prevPrim._zOrder;
  5908. }
  5909. }
  5910. var startPos = prevLinPos;
  5911. // Update the linear position of the primitive from the first one to the last inside this primitive, compute the total number of prim traversed
  5912. Prim2DBase_1._totalCount = 0;
  5913. for (var i = startI; i < childrenCount; i++) {
  5914. var child = this._children[i];
  5915. prevLinPos = child._updatePrimitiveLinearPosition(prevLinPos);
  5916. }
  5917. // Compute the new Z-Order for all the primitives
  5918. // Add 20% to the current total count to reserve space for future insertions, except if we're rebuilding due to a zMinDelta reached
  5919. var zDelta = (this._zMax - startZ) / (Prim2DBase_1._totalCount * (Prim2DBase_1._zRebuildReentrency ? 1 : 1.2));
  5920. // 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.
  5921. if (zDelta < BABYLON.Canvas2D._zMinDelta) {
  5922. // 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...
  5923. if (Prim2DBase_1._zRebuildReentrency) {
  5924. var p = this._parent;
  5925. if (p == null) {
  5926. // 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...)
  5927. console.log("Can't compute Z-Order for " + this.id + "'s children, zDelta is too small, Z-Order is now in an unstable state");
  5928. Prim2DBase_1._zRebuildReentrency = false;
  5929. return;
  5930. }
  5931. p._firstZDirtyIndex = 0;
  5932. return p._updateZOrder();
  5933. }
  5934. Prim2DBase_1._zRebuildReentrency = true;
  5935. this._firstZDirtyIndex = 0;
  5936. this._updateZOrder();
  5937. Prim2DBase_1._zRebuildReentrency = false;
  5938. }
  5939. for (var i = startI; i < childrenCount; i++) {
  5940. var child = this._children[i];
  5941. child._updatePrimitiveZOrder(startPos, startZ, zDelta);
  5942. }
  5943. // Notify the Observers that we found during the Z change (we do it after to avoid any kind of re-entrance)
  5944. for (var _i = 0, _a = Prim2DBase_1._zOrderChangedNotifList; _i < _a.length; _i++) {
  5945. var p = _a[_i];
  5946. p._actualZOrderChangedObservable.notifyObservers(p.actualZOffset);
  5947. }
  5948. Prim2DBase_1._zOrderChangedNotifList.splice(0);
  5949. this._firstZDirtyIndex = Prim2DBase_1._bigInt;
  5950. this._clearFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  5951. };
  5952. Prim2DBase.prototype._updatePrimitiveLinearPosition = function (prevLinPos) {
  5953. if (this.isManualZOrder) {
  5954. return prevLinPos;
  5955. }
  5956. this._primLinearPosition = ++prevLinPos;
  5957. Prim2DBase_1._totalCount++;
  5958. // Check for the FlatZOrder, which means the children won't have a dedicated Z-Order but will all share the same (unique) one.
  5959. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder)) {
  5960. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5961. var child = _a[_i];
  5962. prevLinPos = child._updatePrimitiveLinearPosition(prevLinPos);
  5963. }
  5964. }
  5965. return prevLinPos;
  5966. };
  5967. Prim2DBase.prototype._updatePrimitiveZOrder = function (startPos, startZ, deltaZ) {
  5968. if (this.isManualZOrder) {
  5969. return null;
  5970. }
  5971. var newZ = startZ + ((this._primLinearPosition - startPos) * deltaZ);
  5972. var isFlat = this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  5973. this._setZOrder(newZ, false);
  5974. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  5975. this._firstZDirtyIndex = Prim2DBase_1._bigInt;
  5976. this._clearFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  5977. }
  5978. var curZ = newZ;
  5979. // Check for the FlatZOrder, which means the children won't have a dedicated Z-Order but will all share the same (unique) one.
  5980. if (isFlat) {
  5981. if (this._children.length > 0) {
  5982. //let childrenZOrder = startZ + ((this._children[0]._primLinearPosition - startPos) * deltaZ);
  5983. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5984. var child = _a[_i];
  5985. child._updatePrimitiveFlatZOrder(this._zOrder);
  5986. }
  5987. }
  5988. }
  5989. else {
  5990. for (var _b = 0, _c = this._children; _b < _c.length; _b++) {
  5991. var child = _c[_b];
  5992. var r = child._updatePrimitiveZOrder(startPos, startZ, deltaZ);
  5993. if (r != null) {
  5994. curZ = r;
  5995. }
  5996. }
  5997. }
  5998. this._zMax = isFlat ? newZ : (curZ + deltaZ);
  5999. return curZ;
  6000. };
  6001. Prim2DBase.prototype._updatePrimitiveFlatZOrder = function (newZ) {
  6002. if (this.isManualZOrder) {
  6003. return;
  6004. }
  6005. this._setZOrder(newZ, false);
  6006. this._zMax = newZ;
  6007. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  6008. this._firstZDirtyIndex = Prim2DBase_1._bigInt;
  6009. this._clearFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  6010. }
  6011. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  6012. var child = _a[_i];
  6013. child._updatePrimitiveFlatZOrder(newZ);
  6014. }
  6015. };
  6016. Prim2DBase.prototype._setZOrder = function (newZ, directEmit) {
  6017. if (newZ !== this._zOrder) {
  6018. this._zOrder = newZ;
  6019. this.onPrimBecomesDirty();
  6020. this.onZOrderChanged();
  6021. if (this._actualZOrderChangedObservable && this._actualZOrderChangedObservable.hasObservers()) {
  6022. if (directEmit) {
  6023. this._actualZOrderChangedObservable.notifyObservers(newZ);
  6024. }
  6025. else {
  6026. Prim2DBase_1._zOrderChangedNotifList.push(this);
  6027. }
  6028. }
  6029. }
  6030. };
  6031. Prim2DBase.prototype._updateRenderMode = function () {
  6032. };
  6033. /**
  6034. * This method is used to alter the contentArea of the Primitive before margin is applied.
  6035. * 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.
  6036. * @param primSize the current size of the primitive
  6037. * @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
  6038. * @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!
  6039. */
  6040. Prim2DBase.prototype._getInitialContentAreaToRef = function (primSize, initialContentPosition, initialContentArea) {
  6041. initialContentArea.copyFrom(primSize);
  6042. initialContentPosition.x = initialContentPosition.y = initialContentPosition.z = initialContentPosition.w = 0;
  6043. };
  6044. /**
  6045. * This method is used to calculate the new size of the primitive based on the content which must stay the same
  6046. * Check the Rectangle2D implementation for a concrete application.
  6047. * @param primSize the current size of the primitive
  6048. * @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!
  6049. */
  6050. Prim2DBase.prototype._getActualSizeFromContentToRef = function (primSize, newPrimSize) {
  6051. newPrimSize.copyFrom(primSize);
  6052. };
  6053. return Prim2DBase;
  6054. }(BABYLON.SmartPropertyPrim));
  6055. Prim2DBase.PRIM2DBASE_PROPCOUNT = 25;
  6056. Prim2DBase._bigInt = Math.pow(2, 30);
  6057. Prim2DBase._nullPosition = BABYLON.Vector2.Zero();
  6058. Prim2DBase.boundinbBoxReentrency = false;
  6059. Prim2DBase.nullSize = BABYLON.Size.Zero();
  6060. Prim2DBase._bMax = BABYLON.Vector2.Zero();
  6061. Prim2DBase._tpsBB = new BABYLON.BoundingInfo2D();
  6062. /**
  6063. * Make an intersection test with the primitive, all inputs/outputs are stored in the IntersectInfo2D class, see its documentation for more information.
  6064. * @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.
  6065. */
  6066. Prim2DBase._bypassGroup2DExclusion = false;
  6067. Prim2DBase._isCanvasInit = false;
  6068. Prim2DBase._t0 = new BABYLON.Matrix();
  6069. Prim2DBase._t1 = new BABYLON.Matrix();
  6070. Prim2DBase._t2 = new BABYLON.Matrix();
  6071. Prim2DBase._v0 = BABYLON.Vector2.Zero(); // Must stay with the value 0,0
  6072. Prim2DBase._transMtx = BABYLON.Matrix.Zero();
  6073. Prim2DBase._icPos = BABYLON.Vector2.Zero();
  6074. Prim2DBase._icZone = BABYLON.Vector4.Zero();
  6075. Prim2DBase._icArea = BABYLON.Size.Zero();
  6076. Prim2DBase._size = BABYLON.Size.Zero();
  6077. Prim2DBase._zOrderChangedNotifList = new Array();
  6078. Prim2DBase._zRebuildReentrency = false;
  6079. Prim2DBase._totalCount = 0;
  6080. __decorate([
  6081. BABYLON.instanceLevelProperty(1, function (pi) { return Prim2DBase_1.actualPositionProperty = pi; }, false, false, true)
  6082. ], Prim2DBase.prototype, "actualPosition", null);
  6083. __decorate([
  6084. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 1, function (pi) { return Prim2DBase_1.actualXProperty = pi; }, false, false, true)
  6085. ], Prim2DBase.prototype, "actualX", null);
  6086. __decorate([
  6087. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 2, function (pi) { return Prim2DBase_1.actualYProperty = pi; }, false, false, true)
  6088. ], Prim2DBase.prototype, "actualY", null);
  6089. __decorate([
  6090. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 3, function (pi) { return Prim2DBase_1.positionProperty = pi; }, false, false, true)
  6091. ], Prim2DBase.prototype, "position", null);
  6092. __decorate([
  6093. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 4, function (pi) { return Prim2DBase_1.xProperty = pi; }, false, false, true)
  6094. ], Prim2DBase.prototype, "x", null);
  6095. __decorate([
  6096. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 5, function (pi) { return Prim2DBase_1.yProperty = pi; }, false, false, true)
  6097. ], Prim2DBase.prototype, "y", null);
  6098. __decorate([
  6099. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 6, function (pi) { return Prim2DBase_1.sizeProperty = pi; }, false, true)
  6100. ], Prim2DBase.prototype, "size", null);
  6101. __decorate([
  6102. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 7, function (pi) { return Prim2DBase_1.widthProperty = pi; }, false, true)
  6103. ], Prim2DBase.prototype, "width", null);
  6104. __decorate([
  6105. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 8, function (pi) { return Prim2DBase_1.heightProperty = pi; }, false, true)
  6106. ], Prim2DBase.prototype, "height", null);
  6107. __decorate([
  6108. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 9, function (pi) { return Prim2DBase_1.rotationProperty = pi; }, false, true)
  6109. ], Prim2DBase.prototype, "rotation", null);
  6110. __decorate([
  6111. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 10, function (pi) { return Prim2DBase_1.scaleProperty = pi; }, false, true)
  6112. ], Prim2DBase.prototype, "scale", null);
  6113. __decorate([
  6114. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 11, function (pi) { return Prim2DBase_1.actualSizeProperty = pi; }, false, true)
  6115. ], Prim2DBase.prototype, "actualSize", null);
  6116. __decorate([
  6117. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 12, function (pi) { return Prim2DBase_1.actualWidthProperty = pi; }, false, true)
  6118. ], Prim2DBase.prototype, "actualWidth", null);
  6119. __decorate([
  6120. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 13, function (pi) { return Prim2DBase_1.actualHeightProperty = pi; }, false, true)
  6121. ], Prim2DBase.prototype, "actualHeight", null);
  6122. __decorate([
  6123. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 14, function (pi) { return Prim2DBase_1.originProperty = pi; }, false, true)
  6124. ], Prim2DBase.prototype, "origin", null);
  6125. __decorate([
  6126. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 15, function (pi) { return Prim2DBase_1.levelVisibleProperty = pi; })
  6127. ], Prim2DBase.prototype, "levelVisible", null);
  6128. __decorate([
  6129. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 16, function (pi) { return Prim2DBase_1.isVisibleProperty = pi; })
  6130. ], Prim2DBase.prototype, "isVisible", null);
  6131. __decorate([
  6132. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 17, function (pi) { return Prim2DBase_1.zOrderProperty = pi; })
  6133. ], Prim2DBase.prototype, "zOrder", null);
  6134. __decorate([
  6135. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 18, function (pi) { return Prim2DBase_1.marginProperty = pi; })
  6136. ], Prim2DBase.prototype, "margin", null);
  6137. __decorate([
  6138. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 19, function (pi) { return Prim2DBase_1.paddingProperty = pi; })
  6139. ], Prim2DBase.prototype, "padding", null);
  6140. __decorate([
  6141. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 20, function (pi) { return Prim2DBase_1.marginAlignmentProperty = pi; })
  6142. ], Prim2DBase.prototype, "marginAlignment", null);
  6143. __decorate([
  6144. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 21, function (pi) { return Prim2DBase_1.opacityProperty = pi; })
  6145. ], Prim2DBase.prototype, "opacity", null);
  6146. __decorate([
  6147. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 22, function (pi) { return Prim2DBase_1.scaleXProperty = pi; }, false, true)
  6148. ], Prim2DBase.prototype, "scaleX", null);
  6149. __decorate([
  6150. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 23, function (pi) { return Prim2DBase_1.scaleYProperty = pi; }, false, true)
  6151. ], Prim2DBase.prototype, "scaleY", null);
  6152. __decorate([
  6153. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 24, function (pi) { return Prim2DBase_1.actualScaleProperty = pi; }, false, true)
  6154. ], Prim2DBase.prototype, "actualScale", null);
  6155. Prim2DBase = Prim2DBase_1 = __decorate([
  6156. BABYLON.className("Prim2DBase", "BABYLON")
  6157. ], Prim2DBase);
  6158. BABYLON.Prim2DBase = Prim2DBase;
  6159. var PrimitiveAlignment_1, PrimitiveThickness_1, Prim2DBase_1;
  6160. })(BABYLON || (BABYLON = {}));
  6161. //# sourceMappingURL=babylon.prim2dBase.js.map
  6162. var __extends = (this && this.__extends) || function (d, b) {
  6163. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  6164. function __() { this.constructor = d; }
  6165. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6166. };
  6167. var BABYLON;
  6168. (function (BABYLON) {
  6169. var GroupInstanceInfo = (function () {
  6170. function GroupInstanceInfo(owner, mrc, partCount) {
  6171. this._partCount = partCount;
  6172. this.owner = owner;
  6173. this.modelRenderCache = mrc;
  6174. this.modelRenderCache.addRef();
  6175. this.partIndexFromId = new BABYLON.StringDictionary();
  6176. this._usedShaderCategories = new Array(partCount);
  6177. this._strides = new Array(partCount);
  6178. this._opaqueData = null;
  6179. this._alphaTestData = null;
  6180. this._transparentData = null;
  6181. this.opaqueDirty = this.alphaTestDirty = this.transparentDirty = this.transparentOrderDirty = false;
  6182. }
  6183. GroupInstanceInfo.prototype.dispose = function () {
  6184. if (this._isDisposed) {
  6185. return false;
  6186. }
  6187. if (this.modelRenderCache) {
  6188. this.modelRenderCache.dispose();
  6189. this.modelRenderCache = null;
  6190. }
  6191. var engine = this.owner.owner.engine;
  6192. if (this._opaqueData) {
  6193. this._opaqueData.forEach(function (d) { return d.dispose(engine); });
  6194. this._opaqueData = null;
  6195. }
  6196. if (this._alphaTestData) {
  6197. this._alphaTestData.forEach(function (d) { return d.dispose(engine); });
  6198. this._alphaTestData = null;
  6199. }
  6200. if (this._transparentData) {
  6201. this._transparentData.forEach(function (d) { return d.dispose(engine); });
  6202. this._transparentData = null;
  6203. }
  6204. this.partIndexFromId = null;
  6205. this._isDisposed = true;
  6206. return true;
  6207. };
  6208. Object.defineProperty(GroupInstanceInfo.prototype, "hasOpaqueData", {
  6209. get: function () {
  6210. return this._opaqueData != null;
  6211. },
  6212. enumerable: true,
  6213. configurable: true
  6214. });
  6215. Object.defineProperty(GroupInstanceInfo.prototype, "hasAlphaTestData", {
  6216. get: function () {
  6217. return this._alphaTestData != null;
  6218. },
  6219. enumerable: true,
  6220. configurable: true
  6221. });
  6222. Object.defineProperty(GroupInstanceInfo.prototype, "hasTransparentData", {
  6223. get: function () {
  6224. return this._transparentData != null;
  6225. },
  6226. enumerable: true,
  6227. configurable: true
  6228. });
  6229. Object.defineProperty(GroupInstanceInfo.prototype, "opaqueData", {
  6230. get: function () {
  6231. if (!this._opaqueData) {
  6232. this._opaqueData = new Array(this._partCount);
  6233. for (var i = 0; i < this._partCount; i++) {
  6234. this._opaqueData[i] = new GroupInfoPartData(this._strides[i]);
  6235. }
  6236. }
  6237. return this._opaqueData;
  6238. },
  6239. enumerable: true,
  6240. configurable: true
  6241. });
  6242. Object.defineProperty(GroupInstanceInfo.prototype, "alphaTestData", {
  6243. get: function () {
  6244. if (!this._alphaTestData) {
  6245. this._alphaTestData = new Array(this._partCount);
  6246. for (var i = 0; i < this._partCount; i++) {
  6247. this._alphaTestData[i] = new GroupInfoPartData(this._strides[i]);
  6248. }
  6249. }
  6250. return this._alphaTestData;
  6251. },
  6252. enumerable: true,
  6253. configurable: true
  6254. });
  6255. Object.defineProperty(GroupInstanceInfo.prototype, "transparentData", {
  6256. get: function () {
  6257. if (!this._transparentData) {
  6258. this._transparentData = new Array(this._partCount);
  6259. for (var i = 0; i < this._partCount; i++) {
  6260. var zoff = this.modelRenderCache._partData[i]._zBiasOffset;
  6261. this._transparentData[i] = new TransparentGroupInfoPartData(this._strides[i], zoff);
  6262. }
  6263. }
  6264. return this._transparentData;
  6265. },
  6266. enumerable: true,
  6267. configurable: true
  6268. });
  6269. GroupInstanceInfo.prototype.sortTransparentData = function () {
  6270. if (!this.transparentOrderDirty) {
  6271. return;
  6272. }
  6273. for (var i = 0; i < this._transparentData.length; i++) {
  6274. var td = this._transparentData[i];
  6275. td._partData.sort();
  6276. }
  6277. this.transparentOrderDirty = false;
  6278. };
  6279. Object.defineProperty(GroupInstanceInfo.prototype, "usedShaderCategories", {
  6280. get: function () {
  6281. return this._usedShaderCategories;
  6282. },
  6283. enumerable: true,
  6284. configurable: true
  6285. });
  6286. Object.defineProperty(GroupInstanceInfo.prototype, "strides", {
  6287. get: function () {
  6288. return this._strides;
  6289. },
  6290. enumerable: true,
  6291. configurable: true
  6292. });
  6293. return GroupInstanceInfo;
  6294. }());
  6295. BABYLON.GroupInstanceInfo = GroupInstanceInfo;
  6296. var TransparentSegment = (function () {
  6297. function TransparentSegment() {
  6298. this.groupInsanceInfo = null;
  6299. this.startZ = 0;
  6300. this.endZ = 0;
  6301. this.startDataIndex = BABYLON.Prim2DBase._bigInt;
  6302. this.endDataIndex = 0;
  6303. this.partBuffers = null;
  6304. }
  6305. TransparentSegment.prototype.dispose = function (engine) {
  6306. if (this.partBuffers) {
  6307. this.partBuffers.forEach(function (b) { return engine._releaseBuffer(b); });
  6308. this.partBuffers.splice(0);
  6309. this.partBuffers = null;
  6310. }
  6311. };
  6312. return TransparentSegment;
  6313. }());
  6314. BABYLON.TransparentSegment = TransparentSegment;
  6315. var GroupInfoPartData = (function () {
  6316. function GroupInfoPartData(stride) {
  6317. this._partData = null;
  6318. this._partBuffer = null;
  6319. this._partBufferSize = 0;
  6320. this._partData = new BABYLON.DynamicFloatArray(stride / 4, 50);
  6321. this._isDisposed = false;
  6322. }
  6323. GroupInfoPartData.prototype.dispose = function (engine) {
  6324. if (this._isDisposed) {
  6325. return false;
  6326. }
  6327. if (this._partBuffer) {
  6328. engine._releaseBuffer(this._partBuffer);
  6329. this._partBuffer = null;
  6330. }
  6331. this._partData = null;
  6332. this._isDisposed = true;
  6333. };
  6334. return GroupInfoPartData;
  6335. }());
  6336. BABYLON.GroupInfoPartData = GroupInfoPartData;
  6337. var TransparentGroupInfoPartData = (function (_super) {
  6338. __extends(TransparentGroupInfoPartData, _super);
  6339. function TransparentGroupInfoPartData(stride, zoff) {
  6340. var _this = _super.call(this, stride) || this;
  6341. _this._partData.compareValueOffset = zoff;
  6342. _this._partData.sortingAscending = false;
  6343. return _this;
  6344. }
  6345. return TransparentGroupInfoPartData;
  6346. }(GroupInfoPartData));
  6347. BABYLON.TransparentGroupInfoPartData = TransparentGroupInfoPartData;
  6348. var ModelRenderCache = (function () {
  6349. function ModelRenderCache(engine, modelKey) {
  6350. this._engine = engine;
  6351. this._modelKey = modelKey;
  6352. this._nextKey = 1;
  6353. this._refCounter = 1;
  6354. this._partData = null;
  6355. }
  6356. ModelRenderCache.prototype.dispose = function () {
  6357. if (--this._refCounter !== 0) {
  6358. return false;
  6359. }
  6360. // Remove the Model Render Cache from the global dictionary
  6361. var edata = this._engine.getExternalData("__BJSCANVAS2D__");
  6362. if (edata) {
  6363. edata.DisposeModelRenderCache(this);
  6364. }
  6365. return true;
  6366. };
  6367. Object.defineProperty(ModelRenderCache.prototype, "isDisposed", {
  6368. get: function () {
  6369. return this._refCounter <= 0;
  6370. },
  6371. enumerable: true,
  6372. configurable: true
  6373. });
  6374. ModelRenderCache.prototype.addRef = function () {
  6375. return ++this._refCounter;
  6376. };
  6377. Object.defineProperty(ModelRenderCache.prototype, "modelKey", {
  6378. get: function () {
  6379. return this._modelKey;
  6380. },
  6381. enumerable: true,
  6382. configurable: true
  6383. });
  6384. /**
  6385. * Render the model instances
  6386. * @param instanceInfo
  6387. * @param context
  6388. * @return must return true is the rendering succeed, false if the rendering couldn't be done (asset's not yet ready, like Effect)
  6389. */
  6390. ModelRenderCache.prototype.render = function (instanceInfo, context) {
  6391. return true;
  6392. };
  6393. ModelRenderCache.prototype.getPartIndexFromId = function (partId) {
  6394. for (var i = 0; i < this._partData.length; i++) {
  6395. if (this._partData[i]._partId === partId) {
  6396. return i;
  6397. }
  6398. }
  6399. return null;
  6400. };
  6401. ModelRenderCache.prototype.loadInstancingAttributes = function (partId, effect) {
  6402. var i = this.getPartIndexFromId(partId);
  6403. if (i === null) {
  6404. return null;
  6405. }
  6406. var ci = this._partsClassInfo[i];
  6407. var categories = this._partData[i]._partUsedCategories;
  6408. var res = ci.classContent.getInstancingAttributeInfos(effect, categories);
  6409. return res;
  6410. };
  6411. ModelRenderCache.prototype.setupUniforms = function (effect, partIndex, data, elementCount) {
  6412. var pd = this._partData[partIndex];
  6413. var offset = (pd._partDataStride / 4) * elementCount;
  6414. var pci = this._partsClassInfo[partIndex];
  6415. var self = this;
  6416. pci.fullContent.forEach(function (k, v) {
  6417. if (!v.category || pd._partUsedCategories.indexOf(v.category) !== -1) {
  6418. switch (v.dataType) {
  6419. case 4 /* float */:
  6420. {
  6421. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  6422. effect.setFloat(v.attributeName, data.buffer[offset + attribOffset]);
  6423. break;
  6424. }
  6425. case 0 /* Vector2 */:
  6426. {
  6427. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  6428. ModelRenderCache.v2.x = data.buffer[offset + attribOffset + 0];
  6429. ModelRenderCache.v2.y = data.buffer[offset + attribOffset + 1];
  6430. effect.setVector2(v.attributeName, ModelRenderCache.v2);
  6431. break;
  6432. }
  6433. case 5 /* Color3 */:
  6434. case 1 /* Vector3 */:
  6435. {
  6436. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  6437. ModelRenderCache.v3.x = data.buffer[offset + attribOffset + 0];
  6438. ModelRenderCache.v3.y = data.buffer[offset + attribOffset + 1];
  6439. ModelRenderCache.v3.z = data.buffer[offset + attribOffset + 2];
  6440. effect.setVector3(v.attributeName, ModelRenderCache.v3);
  6441. break;
  6442. }
  6443. case 6 /* Color4 */:
  6444. case 2 /* Vector4 */:
  6445. {
  6446. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  6447. ModelRenderCache.v4.x = data.buffer[offset + attribOffset + 0];
  6448. ModelRenderCache.v4.y = data.buffer[offset + attribOffset + 1];
  6449. ModelRenderCache.v4.z = data.buffer[offset + attribOffset + 2];
  6450. ModelRenderCache.v4.w = data.buffer[offset + attribOffset + 3];
  6451. effect.setVector4(v.attributeName, ModelRenderCache.v4);
  6452. break;
  6453. }
  6454. default:
  6455. }
  6456. }
  6457. });
  6458. };
  6459. return ModelRenderCache;
  6460. }());
  6461. //setupUniformsLocation(effect: Effect, uniforms: string[], partId: number) {
  6462. // let i = this.getPartIndexFromId(partId);
  6463. // if (i === null) {
  6464. // return null;
  6465. // }
  6466. // let pci = this._partsClassInfo[i];
  6467. // pci.fullContent.forEach((k, v) => {
  6468. // if (uniforms.indexOf(v.attributeName) !== -1) {
  6469. // v.uniformLocation = effect.getUniform(v.attributeName);
  6470. // }
  6471. // });
  6472. //}
  6473. ModelRenderCache.v2 = BABYLON.Vector2.Zero();
  6474. ModelRenderCache.v3 = BABYLON.Vector3.Zero();
  6475. ModelRenderCache.v4 = BABYLON.Vector4.Zero();
  6476. BABYLON.ModelRenderCache = ModelRenderCache;
  6477. var ModelRenderCachePartData = (function () {
  6478. function ModelRenderCachePartData() {
  6479. }
  6480. return ModelRenderCachePartData;
  6481. }());
  6482. BABYLON.ModelRenderCachePartData = ModelRenderCachePartData;
  6483. })(BABYLON || (BABYLON = {}));
  6484. //# sourceMappingURL=babylon.modelRenderCache.js.map
  6485. var __extends = (this && this.__extends) || function (d, b) {
  6486. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  6487. function __() { this.constructor = d; }
  6488. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6489. };
  6490. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  6491. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  6492. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  6493. 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;
  6494. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6495. };
  6496. var BABYLON;
  6497. (function (BABYLON) {
  6498. var InstanceClassInfo = (function () {
  6499. function InstanceClassInfo(base) {
  6500. this._baseInfo = base;
  6501. this._nextOffset = new BABYLON.StringDictionary();
  6502. this._attributes = new Array();
  6503. }
  6504. InstanceClassInfo.prototype.mapProperty = function (propInfo, push) {
  6505. var curOff = this._nextOffset.getOrAdd(InstanceClassInfo._CurCategories, 0);
  6506. propInfo.instanceOffset.add(InstanceClassInfo._CurCategories, this._getBaseOffset(InstanceClassInfo._CurCategories) + curOff);
  6507. //console.log(`[${InstanceClassInfo._CurCategories}] New PropInfo. Category: ${propInfo.category}, Name: ${propInfo.attributeName}, Offset: ${propInfo.instanceOffset.get(InstanceClassInfo._CurCategories)}, Size: ${propInfo.size / 4}`);
  6508. this._nextOffset.set(InstanceClassInfo._CurCategories, curOff + (propInfo.size / 4));
  6509. if (push) {
  6510. this._attributes.push(propInfo);
  6511. }
  6512. };
  6513. InstanceClassInfo.prototype.getInstancingAttributeInfos = function (effect, categories) {
  6514. var catInline = ";" + categories.join(";") + ";";
  6515. var res = new Array();
  6516. var curInfo = this;
  6517. while (curInfo) {
  6518. for (var _i = 0, _a = curInfo._attributes; _i < _a.length; _i++) {
  6519. var attrib = _a[_i];
  6520. // 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
  6521. if (!attrib.category || categories.indexOf(attrib.category) !== -1) {
  6522. var index = effect.getAttributeLocationByName(attrib.attributeName);
  6523. var iai = new BABYLON.InstancingAttributeInfo();
  6524. iai.index = index;
  6525. 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)
  6526. iai.offset = attrib.instanceOffset.get(catInline) * 4; // attrib.instanceOffset is in float, iai.offset must be in bytes
  6527. iai.attributeName = attrib.attributeName;
  6528. res.push(iai);
  6529. }
  6530. }
  6531. curInfo = curInfo._baseInfo;
  6532. }
  6533. return res;
  6534. };
  6535. InstanceClassInfo.prototype.getShaderAttributes = function (categories) {
  6536. var res = new Array();
  6537. var curInfo = this;
  6538. while (curInfo) {
  6539. for (var _i = 0, _a = curInfo._attributes; _i < _a.length; _i++) {
  6540. var attrib = _a[_i];
  6541. // 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
  6542. if (!attrib.category || categories.indexOf(attrib.category) !== -1) {
  6543. res.push(attrib.attributeName);
  6544. }
  6545. }
  6546. curInfo = curInfo._baseInfo;
  6547. }
  6548. return res;
  6549. };
  6550. InstanceClassInfo.prototype._getBaseOffset = function (categories) {
  6551. var curOffset = 0;
  6552. var curBase = this._baseInfo;
  6553. while (curBase) {
  6554. curOffset += curBase._nextOffset.getOrAdd(categories, 0);
  6555. curBase = curBase._baseInfo;
  6556. }
  6557. return curOffset;
  6558. };
  6559. return InstanceClassInfo;
  6560. }());
  6561. BABYLON.InstanceClassInfo = InstanceClassInfo;
  6562. var InstancePropInfo = (function () {
  6563. function InstancePropInfo() {
  6564. this.instanceOffset = new BABYLON.StringDictionary();
  6565. }
  6566. InstancePropInfo.prototype.setSize = function (val) {
  6567. if (val instanceof BABYLON.Vector2) {
  6568. this.size = 8;
  6569. this.dataType = 0 /* Vector2 */;
  6570. return;
  6571. }
  6572. if (val instanceof BABYLON.Vector3) {
  6573. this.size = 12;
  6574. this.dataType = 1 /* Vector3 */;
  6575. return;
  6576. }
  6577. if (val instanceof BABYLON.Vector4) {
  6578. this.size = 16;
  6579. this.dataType = 2 /* Vector4 */;
  6580. return;
  6581. }
  6582. if (val instanceof BABYLON.Matrix) {
  6583. throw new Error("Matrix type is not supported by WebGL Instance Buffer, you have to use four Vector4 properties instead");
  6584. }
  6585. if (typeof (val) === "number") {
  6586. this.size = 4;
  6587. this.dataType = 4 /* float */;
  6588. return;
  6589. }
  6590. if (val instanceof BABYLON.Color3) {
  6591. this.size = 12;
  6592. this.dataType = 5 /* Color3 */;
  6593. return;
  6594. }
  6595. if (val instanceof BABYLON.Color4) {
  6596. this.size = 16;
  6597. this.dataType = 6 /* Color4 */;
  6598. return;
  6599. }
  6600. if (val instanceof BABYLON.Size) {
  6601. this.size = 8;
  6602. this.dataType = 7 /* Size */;
  6603. return;
  6604. }
  6605. return;
  6606. };
  6607. InstancePropInfo.prototype.writeData = function (array, offset, val) {
  6608. switch (this.dataType) {
  6609. case 0 /* Vector2 */:
  6610. {
  6611. var v = val;
  6612. array[offset + 0] = v.x;
  6613. array[offset + 1] = v.y;
  6614. break;
  6615. }
  6616. case 1 /* Vector3 */:
  6617. {
  6618. var v = val;
  6619. array[offset + 0] = v.x;
  6620. array[offset + 1] = v.y;
  6621. array[offset + 2] = v.z;
  6622. break;
  6623. }
  6624. case 2 /* Vector4 */:
  6625. {
  6626. var v = val;
  6627. array[offset + 0] = v.x;
  6628. array[offset + 1] = v.y;
  6629. array[offset + 2] = v.z;
  6630. array[offset + 3] = v.w;
  6631. break;
  6632. }
  6633. case 5 /* Color3 */:
  6634. {
  6635. var v = val;
  6636. array[offset + 0] = v.r;
  6637. array[offset + 1] = v.g;
  6638. array[offset + 2] = v.b;
  6639. break;
  6640. }
  6641. case 6 /* Color4 */:
  6642. {
  6643. var v = val;
  6644. array[offset + 0] = v.r;
  6645. array[offset + 1] = v.g;
  6646. array[offset + 2] = v.b;
  6647. array[offset + 3] = v.a;
  6648. break;
  6649. }
  6650. case 4 /* float */:
  6651. {
  6652. var v = val;
  6653. array[offset] = v;
  6654. break;
  6655. }
  6656. case 3 /* Matrix */:
  6657. {
  6658. var v = val;
  6659. for (var i = 0; i < 16; i++) {
  6660. array[offset + i] = v.m[i];
  6661. }
  6662. break;
  6663. }
  6664. case 7 /* Size */:
  6665. {
  6666. var s = val;
  6667. array[offset + 0] = s.width;
  6668. array[offset + 1] = s.height;
  6669. break;
  6670. }
  6671. }
  6672. };
  6673. return InstancePropInfo;
  6674. }());
  6675. BABYLON.InstancePropInfo = InstancePropInfo;
  6676. function instanceData(category, shaderAttributeName) {
  6677. return function (target, propName, descriptor) {
  6678. var dic = BABYLON.ClassTreeInfo.getOrRegister(target, function (base) { return new InstanceClassInfo(base); });
  6679. var node = dic.getLevelOf(target);
  6680. var instanceDataName = propName;
  6681. shaderAttributeName = shaderAttributeName || instanceDataName;
  6682. var info = node.levelContent.get(instanceDataName);
  6683. if (info) {
  6684. throw new Error("The ID " + instanceDataName + " is already taken by another instance data");
  6685. }
  6686. info = new InstancePropInfo();
  6687. info.attributeName = shaderAttributeName;
  6688. info.category = category || null;
  6689. if (info.category) {
  6690. info.delimitedCategory = ";" + info.category + ";";
  6691. }
  6692. node.levelContent.add(instanceDataName, info);
  6693. descriptor.get = function () {
  6694. return null;
  6695. };
  6696. descriptor.set = function (val) {
  6697. // Check that we're not trying to set a property that belongs to a category that is not allowed (current)
  6698. // Quit if it's the case, otherwise we could overwrite data somewhere...
  6699. if (info.category && InstanceClassInfo._CurCategories.indexOf(info.delimitedCategory) === -1) {
  6700. return;
  6701. }
  6702. if (!info.size) {
  6703. info.setSize(val);
  6704. node.classContent.mapProperty(info, true);
  6705. }
  6706. else if (!info.instanceOffset.contains(InstanceClassInfo._CurCategories)) {
  6707. node.classContent.mapProperty(info, false);
  6708. }
  6709. var obj = this;
  6710. if (obj.dataBuffer && obj.dataElements) {
  6711. var offset = obj.dataElements[obj.curElement].offset + info.instanceOffset.get(InstanceClassInfo._CurCategories);
  6712. info.writeData(obj.dataBuffer.buffer, offset, val);
  6713. }
  6714. };
  6715. };
  6716. }
  6717. BABYLON.instanceData = instanceData;
  6718. var InstanceDataBase = (function () {
  6719. function InstanceDataBase(partId, dataElementCount) {
  6720. this.id = partId;
  6721. this.curElement = 0;
  6722. this._dataElementCount = dataElementCount;
  6723. this.renderMode = 0;
  6724. this.arrayLengthChanged = false;
  6725. }
  6726. Object.defineProperty(InstanceDataBase.prototype, "zBias", {
  6727. get: function () {
  6728. return null;
  6729. },
  6730. set: function (value) {
  6731. },
  6732. enumerable: true,
  6733. configurable: true
  6734. });
  6735. Object.defineProperty(InstanceDataBase.prototype, "transformX", {
  6736. get: function () {
  6737. return null;
  6738. },
  6739. set: function (value) {
  6740. },
  6741. enumerable: true,
  6742. configurable: true
  6743. });
  6744. Object.defineProperty(InstanceDataBase.prototype, "transformY", {
  6745. get: function () {
  6746. return null;
  6747. },
  6748. set: function (value) {
  6749. },
  6750. enumerable: true,
  6751. configurable: true
  6752. });
  6753. Object.defineProperty(InstanceDataBase.prototype, "opacity", {
  6754. get: function () {
  6755. return null;
  6756. },
  6757. set: function (value) {
  6758. },
  6759. enumerable: true,
  6760. configurable: true
  6761. });
  6762. InstanceDataBase.prototype.getClassTreeInfo = function () {
  6763. if (!this.typeInfo) {
  6764. this.typeInfo = BABYLON.ClassTreeInfo.get(Object.getPrototypeOf(this));
  6765. }
  6766. return this.typeInfo;
  6767. };
  6768. InstanceDataBase.prototype.allocElements = function () {
  6769. if (!this.dataBuffer || this.dataElements) {
  6770. return;
  6771. }
  6772. var res = new Array(this.dataElementCount);
  6773. for (var i = 0; i < this.dataElementCount; i++) {
  6774. res[i] = this.dataBuffer.allocElement();
  6775. }
  6776. this.dataElements = res;
  6777. };
  6778. InstanceDataBase.prototype.freeElements = function () {
  6779. if (!this.dataElements) {
  6780. return;
  6781. }
  6782. for (var _i = 0, _a = this.dataElements; _i < _a.length; _i++) {
  6783. var ei = _a[_i];
  6784. this.dataBuffer.freeElement(ei);
  6785. }
  6786. this.dataElements = null;
  6787. };
  6788. Object.defineProperty(InstanceDataBase.prototype, "dataElementCount", {
  6789. get: function () {
  6790. return this._dataElementCount;
  6791. },
  6792. set: function (value) {
  6793. if (value === this._dataElementCount) {
  6794. return;
  6795. }
  6796. this.arrayLengthChanged = true;
  6797. this.freeElements();
  6798. this._dataElementCount = value;
  6799. this.allocElements();
  6800. },
  6801. enumerable: true,
  6802. configurable: true
  6803. });
  6804. return InstanceDataBase;
  6805. }());
  6806. __decorate([
  6807. instanceData()
  6808. ], InstanceDataBase.prototype, "zBias", null);
  6809. __decorate([
  6810. instanceData()
  6811. ], InstanceDataBase.prototype, "transformX", null);
  6812. __decorate([
  6813. instanceData()
  6814. ], InstanceDataBase.prototype, "transformY", null);
  6815. __decorate([
  6816. instanceData()
  6817. ], InstanceDataBase.prototype, "opacity", null);
  6818. BABYLON.InstanceDataBase = InstanceDataBase;
  6819. var RenderablePrim2D = RenderablePrim2D_1 = (function (_super) {
  6820. __extends(RenderablePrim2D, _super);
  6821. function RenderablePrim2D(settings) {
  6822. var _this = _super.call(this, settings) || this;
  6823. _this._transparentPrimitiveInfo = null;
  6824. return _this;
  6825. }
  6826. Object.defineProperty(RenderablePrim2D.prototype, "isAlphaTest", {
  6827. get: function () {
  6828. return this._useTextureAlpha() || this._isPrimAlphaTest();
  6829. },
  6830. enumerable: true,
  6831. configurable: true
  6832. });
  6833. Object.defineProperty(RenderablePrim2D.prototype, "isTransparent", {
  6834. get: function () {
  6835. return (this.actualOpacity < 1) || this._shouldUseAlphaFromTexture() || this._isPrimTransparent();
  6836. },
  6837. enumerable: true,
  6838. configurable: true
  6839. });
  6840. Object.defineProperty(RenderablePrim2D.prototype, "renderMode", {
  6841. get: function () {
  6842. return this._renderMode;
  6843. },
  6844. enumerable: true,
  6845. configurable: true
  6846. });
  6847. /**
  6848. * Dispose the primitive and its resources, remove it from its parent
  6849. */
  6850. RenderablePrim2D.prototype.dispose = function () {
  6851. if (!_super.prototype.dispose.call(this)) {
  6852. return false;
  6853. }
  6854. if (this.renderGroup) {
  6855. this.renderGroup._setCacheGroupDirty();
  6856. }
  6857. if (this._transparentPrimitiveInfo) {
  6858. this.renderGroup._renderableData.removeTransparentPrimitiveInfo(this._transparentPrimitiveInfo);
  6859. this._transparentPrimitiveInfo = null;
  6860. }
  6861. if (this._instanceDataParts) {
  6862. this._cleanupInstanceDataParts();
  6863. }
  6864. if (this._modelRenderCache) {
  6865. this._modelRenderCache.dispose();
  6866. this._modelRenderCache = null;
  6867. }
  6868. if (this._instanceDataParts) {
  6869. this._instanceDataParts.forEach(function (p) {
  6870. p.freeElements();
  6871. });
  6872. this._instanceDataParts = null;
  6873. }
  6874. return true;
  6875. };
  6876. RenderablePrim2D.prototype._cleanupInstanceDataParts = function () {
  6877. var gii = null;
  6878. for (var _i = 0, _a = this._instanceDataParts; _i < _a.length; _i++) {
  6879. var part = _a[_i];
  6880. part.freeElements();
  6881. gii = part.groupInstanceInfo;
  6882. }
  6883. if (gii) {
  6884. var usedCount = 0;
  6885. if (gii.hasOpaqueData) {
  6886. var od = gii.opaqueData[0];
  6887. usedCount += od._partData.usedElementCount;
  6888. gii.opaqueDirty = true;
  6889. }
  6890. if (gii.hasAlphaTestData) {
  6891. var atd = gii.alphaTestData[0];
  6892. usedCount += atd._partData.usedElementCount;
  6893. gii.alphaTestDirty = true;
  6894. }
  6895. if (gii.hasTransparentData) {
  6896. var td = gii.transparentData[0];
  6897. usedCount += td._partData.usedElementCount;
  6898. gii.transparentDirty = true;
  6899. }
  6900. if (usedCount === 0 && gii.modelRenderCache != null) {
  6901. this.renderGroup._renderableData._renderGroupInstancesInfo.remove(gii.modelRenderCache.modelKey);
  6902. gii.dispose();
  6903. }
  6904. if (this._modelRenderCache) {
  6905. this._modelRenderCache.dispose();
  6906. this._modelRenderCache = null;
  6907. }
  6908. }
  6909. this._instanceDataParts = null;
  6910. };
  6911. RenderablePrim2D.prototype._prepareRenderPre = function (context) {
  6912. _super.prototype._prepareRenderPre.call(this, context);
  6913. // If the model changed and we have already an instance, we must remove this instance from the obsolete model
  6914. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagModelDirty) && this._instanceDataParts) {
  6915. this._cleanupInstanceDataParts();
  6916. }
  6917. // Need to create the model?
  6918. var setupModelRenderCache = false;
  6919. if (!this._modelRenderCache || this._isFlagSet(BABYLON.SmartPropertyPrim.flagModelDirty)) {
  6920. setupModelRenderCache = this._createModelRenderCache();
  6921. }
  6922. var gii = null;
  6923. var newInstance = false;
  6924. // Need to create the instance data parts?
  6925. if (!this._instanceDataParts) {
  6926. // Yes, flag it for later, more processing will have to be done
  6927. newInstance = true;
  6928. gii = this._createModelDataParts();
  6929. }
  6930. // If the ModelRenderCache is brand new, now is the time to call the implementation's specific setup method to create the rendering resources
  6931. if (setupModelRenderCache) {
  6932. this.setupModelRenderCache(this._modelRenderCache);
  6933. }
  6934. // 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.
  6935. // 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.
  6936. if (this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagVisibilityChanged | BABYLON.SmartPropertyPrim.flagNeedRefresh) || context.forceRefreshPrimitive || newInstance || (this._instanceDirtyFlags !== 0) || (this._globalTransformProcessStep !== this._globalTransformStep) || this._mustUpdateInstance()) {
  6937. this._updateInstanceDataParts(gii);
  6938. }
  6939. };
  6940. RenderablePrim2D.prototype._createModelRenderCache = function () {
  6941. var _this = this;
  6942. var setupModelRenderCache = false;
  6943. if (this._modelRenderCache) {
  6944. this._modelRenderCache.dispose();
  6945. }
  6946. this._modelRenderCache = this.owner._engineData.GetOrAddModelCache(this.modelKey, function (key) {
  6947. var mrc = _this.createModelRenderCache(key);
  6948. setupModelRenderCache = true;
  6949. return mrc;
  6950. });
  6951. this._clearFlags(BABYLON.SmartPropertyPrim.flagModelDirty);
  6952. // if this is still false it means the MRC already exists, so we add a reference to it
  6953. if (!setupModelRenderCache) {
  6954. this._modelRenderCache.addRef();
  6955. }
  6956. return setupModelRenderCache;
  6957. };
  6958. RenderablePrim2D.prototype._createModelDataParts = function () {
  6959. var _this = this;
  6960. // Create the instance data parts of the primitive and store them
  6961. var parts = this.createInstanceDataParts();
  6962. this._instanceDataParts = parts;
  6963. // Check if the ModelRenderCache for this particular instance is also brand new, initialize it if it's the case
  6964. if (!this._modelRenderCache._partData) {
  6965. this._setupModelRenderCache(parts);
  6966. }
  6967. // The Rendering resources (Effect, VB, IB, Textures) are stored in the ModelRenderCache
  6968. // But it's the RenderGroup that will store all the Instanced related data to render all the primitive it owns.
  6969. // So for a given ModelKey we getOrAdd a GroupInstanceInfo that will store all these data
  6970. var gii = this.renderGroup._renderableData._renderGroupInstancesInfo.getOrAddWithFactory(this.modelKey, function (k) {
  6971. var res = new BABYLON.GroupInstanceInfo(_this.renderGroup, _this._modelRenderCache, _this._modelRenderCache._partData.length);
  6972. for (var j = 0; j < _this._modelRenderCache._partData.length; j++) {
  6973. var part = _this._instanceDataParts[j];
  6974. res.partIndexFromId.add(part.id.toString(), j);
  6975. res.usedShaderCategories[j] = ";" + _this.getUsedShaderCategories(part).join(";") + ";";
  6976. res.strides[j] = _this._modelRenderCache._partData[j]._partDataStride;
  6977. }
  6978. return res;
  6979. });
  6980. // Get the GroupInfoDataPart corresponding to the render category of the part
  6981. var rm = 0;
  6982. var gipd = null;
  6983. if (this.isTransparent) {
  6984. gipd = gii.transparentData;
  6985. rm = BABYLON.Render2DContext.RenderModeTransparent;
  6986. }
  6987. else if (this.isAlphaTest) {
  6988. gipd = gii.alphaTestData;
  6989. rm = BABYLON.Render2DContext.RenderModeAlphaTest;
  6990. }
  6991. else {
  6992. gipd = gii.opaqueData;
  6993. rm = BABYLON.Render2DContext.RenderModeOpaque;
  6994. }
  6995. // For each instance data part of the primitive, allocate the instanced element it needs for render
  6996. for (var i = 0; i < parts.length; i++) {
  6997. var part = parts[i];
  6998. part.dataBuffer = gipd[i]._partData;
  6999. part.allocElements();
  7000. part.renderMode = rm;
  7001. part.groupInstanceInfo = gii;
  7002. }
  7003. return gii;
  7004. };
  7005. RenderablePrim2D.prototype._setupModelRenderCache = function (parts) {
  7006. var ctiArray = new Array();
  7007. this._modelRenderCache._partData = new Array();
  7008. for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
  7009. var dataPart = parts_1[_i];
  7010. var pd = new BABYLON.ModelRenderCachePartData();
  7011. this._modelRenderCache._partData.push(pd);
  7012. var cat = this.getUsedShaderCategories(dataPart);
  7013. var cti = dataPart.getClassTreeInfo();
  7014. // Make sure the instance is visible other the properties won't be set and their size/offset wont be computed
  7015. var curVisible = this.isVisible;
  7016. this.isVisible = true;
  7017. // 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.
  7018. //console.log("Build Prop Layout for " + Tools.getClassName(this._instanceDataParts[0]));
  7019. var joinCat = ";" + cat.join(";") + ";";
  7020. pd._partJoinedUsedCategories = joinCat;
  7021. InstanceClassInfo._CurCategories = joinCat;
  7022. var obj = this.beforeRefreshForLayoutConstruction(dataPart);
  7023. if (!this.refreshInstanceDataPart(dataPart)) {
  7024. console.log("Layout construction for " + BABYLON.Tools.getClassName(this._instanceDataParts[0]) + " failed because refresh returned false");
  7025. }
  7026. this.afterRefreshForLayoutConstruction(dataPart, obj);
  7027. this.isVisible = curVisible;
  7028. var size = 0;
  7029. cti.fullContent.forEach(function (k, v) {
  7030. if (!v.category || cat.indexOf(v.category) !== -1) {
  7031. if (v.attributeName === "zBias") {
  7032. pd._zBiasOffset = v.instanceOffset.get(joinCat);
  7033. }
  7034. if (!v.size) {
  7035. console.log("ERROR: Couldn't detect the size of the Property " + v.attributeName + " from type " + BABYLON.Tools.getClassName(cti.type) + ". Property is ignored.");
  7036. }
  7037. else {
  7038. size += v.size;
  7039. }
  7040. }
  7041. });
  7042. pd._partDataStride = size;
  7043. pd._partUsedCategories = cat;
  7044. pd._partId = dataPart.id;
  7045. ctiArray.push(cti);
  7046. }
  7047. this._modelRenderCache._partsClassInfo = ctiArray;
  7048. };
  7049. RenderablePrim2D.prototype.onZOrderChanged = function () {
  7050. if (this.isTransparent && this._transparentPrimitiveInfo) {
  7051. this.renderGroup._renderableData.transparentPrimitiveZChanged(this._transparentPrimitiveInfo);
  7052. var gii = this.renderGroup._renderableData._renderGroupInstancesInfo.get(this.modelKey);
  7053. // Flag the transparentData dirty has will have to sort it again
  7054. gii.transparentOrderDirty = true;
  7055. }
  7056. };
  7057. RenderablePrim2D.prototype._mustUpdateInstance = function () {
  7058. return false;
  7059. };
  7060. RenderablePrim2D.prototype._useTextureAlpha = function () {
  7061. return false;
  7062. };
  7063. RenderablePrim2D.prototype._shouldUseAlphaFromTexture = function () {
  7064. return false;
  7065. };
  7066. RenderablePrim2D.prototype._isPrimAlphaTest = function () {
  7067. return false;
  7068. };
  7069. RenderablePrim2D.prototype._isPrimTransparent = function () {
  7070. return false;
  7071. };
  7072. RenderablePrim2D.prototype._updateInstanceDataParts = function (gii) {
  7073. // Fetch the GroupInstanceInfo if we don't already have it
  7074. var rd = this.renderGroup._renderableData;
  7075. if (!gii) {
  7076. gii = rd._renderGroupInstancesInfo.get(this.modelKey);
  7077. }
  7078. var isTransparent = this.isTransparent;
  7079. var isAlphaTest = this.isAlphaTest;
  7080. var wereTransparent = false;
  7081. // Check a render mode change
  7082. var rmChanged = false;
  7083. if (this._instanceDataParts.length > 0) {
  7084. var firstPart = this._instanceDataParts[0];
  7085. var partRM = firstPart.renderMode;
  7086. var curRM = this.renderMode;
  7087. if (partRM !== curRM) {
  7088. wereTransparent = partRM === BABYLON.Render2DContext.RenderModeTransparent;
  7089. rmChanged = true;
  7090. var gipd = void 0;
  7091. switch (curRM) {
  7092. case BABYLON.Render2DContext.RenderModeTransparent:
  7093. gipd = gii.transparentData;
  7094. break;
  7095. case BABYLON.Render2DContext.RenderModeAlphaTest:
  7096. gipd = gii.alphaTestData;
  7097. break;
  7098. default:
  7099. gipd = gii.opaqueData;
  7100. }
  7101. for (var i = 0; i < this._instanceDataParts.length; i++) {
  7102. var part = this._instanceDataParts[i];
  7103. part.freeElements();
  7104. part.dataBuffer = gipd[i]._partData;
  7105. part.renderMode = curRM;
  7106. }
  7107. }
  7108. }
  7109. // Handle changes related to ZOffset
  7110. var visChanged = this._isFlagSet(BABYLON.SmartPropertyPrim.flagVisibilityChanged);
  7111. if (isTransparent || wereTransparent) {
  7112. // Handle visibility change, which is also triggered when the primitive just got created
  7113. if (visChanged || rmChanged) {
  7114. if (this.isVisible && !wereTransparent) {
  7115. if (!this._transparentPrimitiveInfo) {
  7116. // Add the primitive to the list of transparent ones in the group that render is
  7117. this._transparentPrimitiveInfo = rd.addNewTransparentPrimitiveInfo(this, gii);
  7118. }
  7119. }
  7120. else {
  7121. if (this._transparentPrimitiveInfo) {
  7122. rd.removeTransparentPrimitiveInfo(this._transparentPrimitiveInfo);
  7123. this._transparentPrimitiveInfo = null;
  7124. }
  7125. }
  7126. gii.transparentOrderDirty = true;
  7127. }
  7128. }
  7129. var rebuildTrans = false;
  7130. // For each Instance Data part, refresh it to update the data in the DynamicFloatArray
  7131. for (var _i = 0, _a = this._instanceDataParts; _i < _a.length; _i++) {
  7132. var part = _a[_i];
  7133. var justAllocated = false;
  7134. // Check if we need to allocate data elements (hidden prim which becomes visible again)
  7135. if (!part.dataElements && (visChanged || rmChanged || this.isVisible)) {
  7136. part.allocElements();
  7137. justAllocated = true;
  7138. }
  7139. InstanceClassInfo._CurCategories = gii.usedShaderCategories[gii.partIndexFromId.get(part.id.toString())];
  7140. // Will return false if the instance should not be rendered (not visible or other any reasons)
  7141. part.arrayLengthChanged = false;
  7142. if (!this.refreshInstanceDataPart(part)) {
  7143. // Free the data element
  7144. if (part.dataElements) {
  7145. part.freeElements();
  7146. }
  7147. // The refresh couldn't succeed, push the primitive to be dirty again for the next render
  7148. if (this.isVisible) {
  7149. rd._primNewDirtyList.push(this);
  7150. }
  7151. }
  7152. rebuildTrans = rebuildTrans || part.arrayLengthChanged || justAllocated;
  7153. }
  7154. this._instanceDirtyFlags = 0;
  7155. // Make the appropriate data dirty
  7156. if (isTransparent) {
  7157. gii.transparentDirty = true;
  7158. if (rebuildTrans) {
  7159. rd._transparentListChanged = true;
  7160. }
  7161. }
  7162. else if (isAlphaTest) {
  7163. gii.alphaTestDirty = true;
  7164. }
  7165. else {
  7166. gii.opaqueDirty = true;
  7167. }
  7168. this._clearFlags(BABYLON.SmartPropertyPrim.flagVisibilityChanged); // Reset the flag as we've handled the case
  7169. };
  7170. RenderablePrim2D.prototype._updateTransparentSegmentIndices = function (ts) {
  7171. var minOff = BABYLON.Prim2DBase._bigInt;
  7172. var maxOff = 0;
  7173. for (var _i = 0, _a = this._instanceDataParts; _i < _a.length; _i++) {
  7174. var part = _a[_i];
  7175. if (part && part.dataElements) {
  7176. part.dataBuffer.pack();
  7177. for (var _b = 0, _c = part.dataElements; _b < _c.length; _b++) {
  7178. var el = _c[_b];
  7179. minOff = Math.min(minOff, el.offset);
  7180. maxOff = Math.max(maxOff, el.offset);
  7181. }
  7182. ts.startDataIndex = Math.min(ts.startDataIndex, minOff / part.dataBuffer.stride);
  7183. ts.endDataIndex = Math.max(ts.endDataIndex, (maxOff / part.dataBuffer.stride) + 1); // +1 for exclusive
  7184. }
  7185. }
  7186. };
  7187. // This internal method is mainly used for transparency processing
  7188. RenderablePrim2D.prototype._getNextPrimZOrder = function () {
  7189. var length = this._instanceDataParts.length;
  7190. for (var i = 0; i < length; i++) {
  7191. var part = this._instanceDataParts[i];
  7192. if (part) {
  7193. var stride = part.dataBuffer.stride;
  7194. var lastElementOffset = part.dataElements[part.dataElements.length - 1].offset;
  7195. // check if it's the last in the DFA
  7196. if (part.dataBuffer.totalElementCount * stride <= lastElementOffset) {
  7197. return null;
  7198. }
  7199. // Return the Z of the next primitive that lies in the DFA
  7200. return part.dataBuffer[lastElementOffset + stride + this.modelRenderCache._partData[i]._zBiasOffset];
  7201. }
  7202. }
  7203. return null;
  7204. };
  7205. // This internal method is mainly used for transparency processing
  7206. RenderablePrim2D.prototype._getPrevPrimZOrder = function () {
  7207. var length = this._instanceDataParts.length;
  7208. for (var i = 0; i < length; i++) {
  7209. var part = this._instanceDataParts[i];
  7210. if (part) {
  7211. var stride = part.dataBuffer.stride;
  7212. var firstElementOffset = part.dataElements[0].offset;
  7213. // check if it's the first in the DFA
  7214. if (firstElementOffset === 0) {
  7215. return null;
  7216. }
  7217. // Return the Z of the previous primitive that lies in the DFA
  7218. return part.dataBuffer[firstElementOffset - stride + this.modelRenderCache._partData[i]._zBiasOffset];
  7219. }
  7220. }
  7221. return null;
  7222. };
  7223. /**
  7224. * Transform a given point using the Primitive's origin setting.
  7225. * This method requires the Primitive's actualSize to be accurate
  7226. * @param p the point to transform
  7227. * @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.
  7228. * @param res an allocated Vector2 that will receive the transformed content
  7229. */
  7230. RenderablePrim2D.prototype.transformPointWithOriginByRef = function (p, originOffset, res) {
  7231. var actualSize = this.actualSize;
  7232. res.x = p.x - ((this.origin.x + (originOffset ? originOffset.x : 0)) * actualSize.width);
  7233. res.y = p.y - ((this.origin.y + (originOffset ? originOffset.y : 0)) * actualSize.height);
  7234. };
  7235. RenderablePrim2D.prototype.transformPointWithOriginToRef = function (p, originOffset, res) {
  7236. this.transformPointWithOriginByRef(p, originOffset, res);
  7237. return res;
  7238. };
  7239. /**
  7240. * Get the info for a given effect based on the dataPart metadata
  7241. * @param dataPartId partId in part list to get the info
  7242. * @param vertexBufferAttributes vertex buffer attributes to manually add
  7243. * @param uniforms uniforms to manually add
  7244. * @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
  7245. */
  7246. RenderablePrim2D.prototype.getDataPartEffectInfo = function (dataPartId, vertexBufferAttributes, uniforms, useInstanced) {
  7247. if (uniforms === void 0) { uniforms = null; }
  7248. if (useInstanced === void 0) { useInstanced = null; }
  7249. var dataPart = BABYLON.Tools.first(this._instanceDataParts, function (i) { return i.id === dataPartId; });
  7250. if (!dataPart) {
  7251. return null;
  7252. }
  7253. var instancedArray = this.owner.supportInstancedArray;
  7254. if (useInstanced != null) {
  7255. // Check if the caller ask for Instanced Array and the engine does not support it, return null if it's the case
  7256. if (useInstanced && instancedArray === false) {
  7257. return null;
  7258. }
  7259. // Use the caller's setting
  7260. instancedArray = useInstanced;
  7261. }
  7262. var cti = dataPart.getClassTreeInfo();
  7263. var categories = this.getUsedShaderCategories(dataPart);
  7264. var att = cti.classContent.getShaderAttributes(categories);
  7265. var defines = "";
  7266. categories.forEach(function (c) { defines += "#define " + c + "\n"; });
  7267. if (instancedArray) {
  7268. defines += "#define Instanced\n";
  7269. }
  7270. return {
  7271. attributes: instancedArray ? vertexBufferAttributes.concat(att) : vertexBufferAttributes,
  7272. uniforms: instancedArray ? (uniforms != null ? uniforms : []) : ((uniforms != null) ? att.concat(uniforms) : (att != null ? att : [])),
  7273. defines: defines
  7274. };
  7275. };
  7276. Object.defineProperty(RenderablePrim2D.prototype, "modelRenderCache", {
  7277. get: function () {
  7278. return this._modelRenderCache;
  7279. },
  7280. enumerable: true,
  7281. configurable: true
  7282. });
  7283. RenderablePrim2D.prototype.createModelRenderCache = function (modelKey) {
  7284. return null;
  7285. };
  7286. RenderablePrim2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  7287. };
  7288. RenderablePrim2D.prototype.createInstanceDataParts = function () {
  7289. return null;
  7290. };
  7291. RenderablePrim2D.prototype.getUsedShaderCategories = function (dataPart) {
  7292. return [];
  7293. };
  7294. RenderablePrim2D.prototype.beforeRefreshForLayoutConstruction = function (part) {
  7295. };
  7296. RenderablePrim2D.prototype.afterRefreshForLayoutConstruction = function (part, obj) {
  7297. };
  7298. RenderablePrim2D.prototype.applyActualScaleOnTransform = function () {
  7299. return true;
  7300. };
  7301. RenderablePrim2D.prototype.refreshInstanceDataPart = function (part) {
  7302. if (!this.isVisible) {
  7303. return false;
  7304. }
  7305. part.isVisible = this.isVisible;
  7306. // 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)
  7307. if (part.dataElementCount === 1) {
  7308. part.curElement = 0;
  7309. this.updateInstanceDataPart(part);
  7310. }
  7311. return true;
  7312. };
  7313. /**
  7314. * Update the instanceDataBase level properties of a part
  7315. * @param part the part to update
  7316. * @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).
  7317. */
  7318. RenderablePrim2D.prototype.updateInstanceDataPart = function (part, positionOffset) {
  7319. if (positionOffset === void 0) { positionOffset = null; }
  7320. var t = this._globalTransform.multiply(this.renderGroup.invGlobalTransform); // Compute the transformation into the renderGroup's space
  7321. 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.
  7322. var size = this.renderGroup.viewportSize;
  7323. var zBias = this.actualZOffset;
  7324. var offX = 0;
  7325. var offY = 0;
  7326. // If there's an offset, apply the global transformation matrix on it to get a global offset
  7327. if (positionOffset) {
  7328. offX = positionOffset.x * t.m[0] + positionOffset.y * t.m[4];
  7329. offY = positionOffset.x * t.m[1] + positionOffset.y * t.m[5];
  7330. }
  7331. // 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
  7332. // Current coordinates are expressed in renderGroup coordinates ([0, renderGroup.actualSize.width|height]) with 0,0 being at the left/top corner
  7333. // So for X:
  7334. // - tx.x = value * 2 / width: is to switch from [0, renderGroup.width] to [0, 2]
  7335. // - 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].
  7336. // At last we don't forget to apply the actualScale of the Render Group to tx[0] and ty[1] to propagate scaling correctly
  7337. var w = size.width;
  7338. var h = size.height;
  7339. var invZBias = 1 / zBias;
  7340. var tx = new BABYLON.Vector4(t.m[0] * rgScale.x * 2 / w, t.m[4] * 2 / w, 0 /*t.m[8]*/, ((t.m[12] + offX) * rgScale.x * 2 / w) - 1);
  7341. var ty = new BABYLON.Vector4(t.m[1] * 2 / h, t.m[5] * rgScale.y * 2 / h, 0 /*t.m[9]*/, ((t.m[13] + offY) * rgScale.y * 2 / h) - 1);
  7342. if (!this.applyActualScaleOnTransform()) {
  7343. t.m[0] = tx.x, t.m[4] = tx.y, t.m[12] = tx.w;
  7344. t.m[1] = ty.x, t.m[5] = ty.y, t.m[13] = ty.w;
  7345. var las = this.actualScale;
  7346. t.decompose(RenderablePrim2D_1._s, RenderablePrim2D_1._r, RenderablePrim2D_1._t);
  7347. var scale = new BABYLON.Vector3(RenderablePrim2D_1._s.x / las.x, RenderablePrim2D_1._s.y / las.y, 1);
  7348. t = BABYLON.Matrix.Compose(scale, RenderablePrim2D_1._r, RenderablePrim2D_1._t);
  7349. tx = new BABYLON.Vector4(t.m[0], t.m[4], 0, t.m[12]);
  7350. ty = new BABYLON.Vector4(t.m[1], t.m[5], 0, t.m[13]);
  7351. }
  7352. part.transformX = tx;
  7353. part.transformY = ty;
  7354. part.opacity = this.actualOpacity;
  7355. // 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)
  7356. part.zBias = new BABYLON.Vector2(zBias, invZBias);
  7357. };
  7358. RenderablePrim2D.prototype._updateRenderMode = function () {
  7359. if (this.isTransparent) {
  7360. this._renderMode = BABYLON.Render2DContext.RenderModeTransparent;
  7361. }
  7362. else if (this.isAlphaTest) {
  7363. this._renderMode = BABYLON.Render2DContext.RenderModeAlphaTest;
  7364. }
  7365. else {
  7366. this._renderMode = BABYLON.Render2DContext.RenderModeOpaque;
  7367. }
  7368. };
  7369. return RenderablePrim2D;
  7370. }(BABYLON.Prim2DBase));
  7371. RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT = BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 5;
  7372. RenderablePrim2D._uV = new BABYLON.Vector2(1, 1);
  7373. RenderablePrim2D._s = BABYLON.Vector3.Zero();
  7374. RenderablePrim2D._r = BABYLON.Quaternion.Identity();
  7375. RenderablePrim2D._t = BABYLON.Vector3.Zero();
  7376. RenderablePrim2D._uV3 = new BABYLON.Vector3(1, 1, 1);
  7377. __decorate([
  7378. BABYLON.dynamicLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 0, function (pi) { return RenderablePrim2D_1.isAlphaTestProperty = pi; })
  7379. ], RenderablePrim2D.prototype, "isAlphaTest", null);
  7380. __decorate([
  7381. BABYLON.dynamicLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 1, function (pi) { return RenderablePrim2D_1.isTransparentProperty = pi; })
  7382. ], RenderablePrim2D.prototype, "isTransparent", null);
  7383. RenderablePrim2D = RenderablePrim2D_1 = __decorate([
  7384. BABYLON.className("RenderablePrim2D", "BABYLON")
  7385. ], RenderablePrim2D);
  7386. BABYLON.RenderablePrim2D = RenderablePrim2D;
  7387. var RenderablePrim2D_1;
  7388. })(BABYLON || (BABYLON = {}));
  7389. //# sourceMappingURL=babylon.renderablePrim2d.js.map
  7390. var __extends = (this && this.__extends) || function (d, b) {
  7391. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  7392. function __() { this.constructor = d; }
  7393. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7394. };
  7395. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  7396. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  7397. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  7398. 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;
  7399. return c > 3 && r && Object.defineProperty(target, key, r), r;
  7400. };
  7401. var BABYLON;
  7402. (function (BABYLON) {
  7403. var Shape2D = Shape2D_1 = (function (_super) {
  7404. __extends(Shape2D, _super);
  7405. function Shape2D(settings) {
  7406. var _this = _super.call(this, settings) || this;
  7407. if (!settings) {
  7408. settings = {};
  7409. }
  7410. var borderBrush = null;
  7411. if (settings.border) {
  7412. if (typeof (settings.border) === "string") {
  7413. borderBrush = BABYLON.Canvas2D.GetBrushFromString(settings.border);
  7414. }
  7415. else {
  7416. borderBrush = settings.border;
  7417. }
  7418. }
  7419. var fillBrush = null;
  7420. if (settings.fill) {
  7421. if (typeof (settings.fill) === "string") {
  7422. fillBrush = BABYLON.Canvas2D.GetBrushFromString(settings.fill);
  7423. }
  7424. else {
  7425. fillBrush = settings.fill;
  7426. }
  7427. }
  7428. _this._isTransparent = false;
  7429. _this._oldTransparent = false;
  7430. _this.border = borderBrush;
  7431. _this.fill = fillBrush;
  7432. _this._updateTransparencyStatus();
  7433. _this.borderThickness = settings.borderThickness;
  7434. return _this;
  7435. }
  7436. Object.defineProperty(Shape2D.prototype, "border", {
  7437. get: function () {
  7438. return this._border;
  7439. },
  7440. set: function (value) {
  7441. this._border = value;
  7442. this._updateTransparencyStatus();
  7443. },
  7444. enumerable: true,
  7445. configurable: true
  7446. });
  7447. Object.defineProperty(Shape2D.prototype, "fill", {
  7448. /**
  7449. * Get/set the brush to render the Fill part of the Primitive
  7450. */
  7451. get: function () {
  7452. return this._fill;
  7453. },
  7454. set: function (value) {
  7455. this._fill = value;
  7456. this._updateTransparencyStatus();
  7457. },
  7458. enumerable: true,
  7459. configurable: true
  7460. });
  7461. Object.defineProperty(Shape2D.prototype, "borderThickness", {
  7462. get: function () {
  7463. return this._borderThickness;
  7464. },
  7465. set: function (value) {
  7466. this._borderThickness = value;
  7467. },
  7468. enumerable: true,
  7469. configurable: true
  7470. });
  7471. Shape2D.prototype.getUsedShaderCategories = function (dataPart) {
  7472. var cat = _super.prototype.getUsedShaderCategories.call(this, dataPart);
  7473. // Fill Part
  7474. if (dataPart.id === Shape2D_1.SHAPE2D_FILLPARTID) {
  7475. var fill = this.fill;
  7476. if (fill instanceof BABYLON.SolidColorBrush2D) {
  7477. cat.push(Shape2D_1.SHAPE2D_CATEGORY_FILLSOLID);
  7478. }
  7479. if (fill instanceof BABYLON.GradientColorBrush2D) {
  7480. cat.push(Shape2D_1.SHAPE2D_CATEGORY_FILLGRADIENT);
  7481. }
  7482. }
  7483. // Border Part
  7484. if (dataPart.id === Shape2D_1.SHAPE2D_BORDERPARTID) {
  7485. cat.push(Shape2D_1.SHAPE2D_CATEGORY_BORDER);
  7486. var border = this.border;
  7487. if (border instanceof BABYLON.SolidColorBrush2D) {
  7488. cat.push(Shape2D_1.SHAPE2D_CATEGORY_BORDERSOLID);
  7489. }
  7490. if (border instanceof BABYLON.GradientColorBrush2D) {
  7491. cat.push(Shape2D_1.SHAPE2D_CATEGORY_BORDERGRADIENT);
  7492. }
  7493. }
  7494. return cat;
  7495. };
  7496. Shape2D.prototype.applyActualScaleOnTransform = function () {
  7497. return false;
  7498. };
  7499. Shape2D.prototype.refreshInstanceDataPart = function (part) {
  7500. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  7501. return false;
  7502. }
  7503. // Fill Part
  7504. if (part.id === Shape2D_1.SHAPE2D_FILLPARTID) {
  7505. var d = part;
  7506. if (this.fill) {
  7507. var fill = this.fill;
  7508. if (fill instanceof BABYLON.SolidColorBrush2D) {
  7509. d.fillSolidColor = fill.color;
  7510. }
  7511. else if (fill instanceof BABYLON.GradientColorBrush2D) {
  7512. d.fillGradientColor1 = fill.color1;
  7513. d.fillGradientColor2 = fill.color2;
  7514. 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));
  7515. var ty = new BABYLON.Vector4(t.m[1], t.m[5], t.m[9], t.m[13]);
  7516. d.fillGradientTY = ty;
  7517. }
  7518. }
  7519. }
  7520. else if (part.id === Shape2D_1.SHAPE2D_BORDERPARTID) {
  7521. var d = part;
  7522. if (this.border) {
  7523. d.borderThickness = this.borderThickness;
  7524. var border = this.border;
  7525. if (border instanceof BABYLON.SolidColorBrush2D) {
  7526. d.borderSolidColor = border.color;
  7527. }
  7528. else if (border instanceof BABYLON.GradientColorBrush2D) {
  7529. d.borderGradientColor1 = border.color1;
  7530. d.borderGradientColor2 = border.color2;
  7531. 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));
  7532. var ty = new BABYLON.Vector4(t.m[1], t.m[5], t.m[9], t.m[13]);
  7533. d.borderGradientTY = ty;
  7534. }
  7535. }
  7536. }
  7537. return true;
  7538. };
  7539. Shape2D.prototype._updateTransparencyStatus = function () {
  7540. this._isTransparent = (this._border && this._border.isTransparent()) || (this._fill && this._fill.isTransparent()) || (this.actualOpacity < 1);
  7541. if (this._isTransparent !== this._oldTransparent) {
  7542. this._oldTransparent = this._isTransparent;
  7543. this._updateRenderMode();
  7544. }
  7545. };
  7546. Shape2D.prototype._mustUpdateInstance = function () {
  7547. var res = this._oldTransparent !== this._isTransparent;
  7548. if (res) {
  7549. this._updateRenderMode();
  7550. this._oldTransparent = this._isTransparent;
  7551. }
  7552. return res;
  7553. };
  7554. Shape2D.prototype._isPrimTransparent = function () {
  7555. return this._isTransparent;
  7556. };
  7557. return Shape2D;
  7558. }(BABYLON.RenderablePrim2D));
  7559. Shape2D.SHAPE2D_BORDERPARTID = 1;
  7560. Shape2D.SHAPE2D_FILLPARTID = 2;
  7561. Shape2D.SHAPE2D_CATEGORY_BORDER = "Border";
  7562. Shape2D.SHAPE2D_CATEGORY_BORDERSOLID = "BorderSolid";
  7563. Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT = "BorderGradient";
  7564. Shape2D.SHAPE2D_CATEGORY_FILLSOLID = "FillSolid";
  7565. Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT = "FillGradient";
  7566. Shape2D.SHAPE2D_PROPCOUNT = BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 5;
  7567. __decorate([
  7568. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 1, function (pi) { return Shape2D_1.borderProperty = pi; }, true)
  7569. ], Shape2D.prototype, "border", null);
  7570. __decorate([
  7571. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 2, function (pi) { return Shape2D_1.fillProperty = pi; }, true)
  7572. ], Shape2D.prototype, "fill", null);
  7573. __decorate([
  7574. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 3, function (pi) { return Shape2D_1.borderThicknessProperty = pi; })
  7575. ], Shape2D.prototype, "borderThickness", null);
  7576. Shape2D = Shape2D_1 = __decorate([
  7577. BABYLON.className("Shape2D", "BABYLON")
  7578. ], Shape2D);
  7579. BABYLON.Shape2D = Shape2D;
  7580. var Shape2DInstanceData = (function (_super) {
  7581. __extends(Shape2DInstanceData, _super);
  7582. function Shape2DInstanceData() {
  7583. return _super.apply(this, arguments) || this;
  7584. }
  7585. Object.defineProperty(Shape2DInstanceData.prototype, "fillSolidColor", {
  7586. // FILL ATTRIBUTES
  7587. get: function () {
  7588. return null;
  7589. },
  7590. set: function (value) {
  7591. },
  7592. enumerable: true,
  7593. configurable: true
  7594. });
  7595. Object.defineProperty(Shape2DInstanceData.prototype, "fillGradientColor1", {
  7596. get: function () {
  7597. return null;
  7598. },
  7599. set: function (value) {
  7600. },
  7601. enumerable: true,
  7602. configurable: true
  7603. });
  7604. Object.defineProperty(Shape2DInstanceData.prototype, "fillGradientColor2", {
  7605. get: function () {
  7606. return null;
  7607. },
  7608. set: function (value) {
  7609. },
  7610. enumerable: true,
  7611. configurable: true
  7612. });
  7613. Object.defineProperty(Shape2DInstanceData.prototype, "fillGradientTY", {
  7614. get: function () {
  7615. return null;
  7616. },
  7617. set: function (value) {
  7618. },
  7619. enumerable: true,
  7620. configurable: true
  7621. });
  7622. Object.defineProperty(Shape2DInstanceData.prototype, "borderThickness", {
  7623. // BORDER ATTRIBUTES
  7624. get: function () {
  7625. return null;
  7626. },
  7627. set: function (value) {
  7628. },
  7629. enumerable: true,
  7630. configurable: true
  7631. });
  7632. Object.defineProperty(Shape2DInstanceData.prototype, "borderSolidColor", {
  7633. get: function () {
  7634. return null;
  7635. },
  7636. set: function (value) {
  7637. },
  7638. enumerable: true,
  7639. configurable: true
  7640. });
  7641. Object.defineProperty(Shape2DInstanceData.prototype, "borderGradientColor1", {
  7642. get: function () {
  7643. return null;
  7644. },
  7645. set: function (value) {
  7646. },
  7647. enumerable: true,
  7648. configurable: true
  7649. });
  7650. Object.defineProperty(Shape2DInstanceData.prototype, "borderGradientColor2", {
  7651. get: function () {
  7652. return null;
  7653. },
  7654. set: function (value) {
  7655. },
  7656. enumerable: true,
  7657. configurable: true
  7658. });
  7659. Object.defineProperty(Shape2DInstanceData.prototype, "borderGradientTY", {
  7660. get: function () {
  7661. return null;
  7662. },
  7663. set: function (value) {
  7664. },
  7665. enumerable: true,
  7666. configurable: true
  7667. });
  7668. return Shape2DInstanceData;
  7669. }(BABYLON.InstanceDataBase));
  7670. __decorate([
  7671. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLSOLID)
  7672. ], Shape2DInstanceData.prototype, "fillSolidColor", null);
  7673. __decorate([
  7674. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  7675. ], Shape2DInstanceData.prototype, "fillGradientColor1", null);
  7676. __decorate([
  7677. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  7678. ], Shape2DInstanceData.prototype, "fillGradientColor2", null);
  7679. __decorate([
  7680. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  7681. ], Shape2DInstanceData.prototype, "fillGradientTY", null);
  7682. __decorate([
  7683. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDER)
  7684. ], Shape2DInstanceData.prototype, "borderThickness", null);
  7685. __decorate([
  7686. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERSOLID)
  7687. ], Shape2DInstanceData.prototype, "borderSolidColor", null);
  7688. __decorate([
  7689. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT)
  7690. ], Shape2DInstanceData.prototype, "borderGradientColor1", null);
  7691. __decorate([
  7692. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT)
  7693. ], Shape2DInstanceData.prototype, "borderGradientColor2", null);
  7694. __decorate([
  7695. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT)
  7696. ], Shape2DInstanceData.prototype, "borderGradientTY", null);
  7697. BABYLON.Shape2DInstanceData = Shape2DInstanceData;
  7698. var Shape2D_1;
  7699. })(BABYLON || (BABYLON = {}));
  7700. //# sourceMappingURL=babylon.shape2d.js.map
  7701. var __extends = (this && this.__extends) || function (d, b) {
  7702. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  7703. function __() { this.constructor = d; }
  7704. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7705. };
  7706. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  7707. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  7708. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  7709. 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;
  7710. return c > 3 && r && Object.defineProperty(target, key, r), r;
  7711. };
  7712. var BABYLON;
  7713. (function (BABYLON) {
  7714. var Group2D = Group2D_1 = (function (_super) {
  7715. __extends(Group2D, _super);
  7716. /**
  7717. * Create an Logical or Renderable Group.
  7718. * @param settings a combination of settings, possible ones are
  7719. * - 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)
  7720. * - children: an array of direct children
  7721. * - id a text identifier, for information purpose
  7722. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  7723. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  7724. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  7725. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  7726. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  7727. * - zOrder: override the zOrder with the specified value
  7728. * - origin: define the normalized origin point location, default [0.5;0.5]
  7729. * - 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.
  7730. * - cacheBehavior: Define how the group should behave regarding the Canvas's cache strategy, default is Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY
  7731. * - 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).
  7732. * - isVisible: true if the group must be visible, false for hidden. Default is true.
  7733. * - 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.
  7734. * - 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.
  7735. * - 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!
  7736. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7737. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7738. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7739. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7740. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  7741. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  7742. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  7743. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  7744. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7745. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7746. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7747. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7748. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  7749. */
  7750. function Group2D(settings) {
  7751. var _this;
  7752. if (settings == null) {
  7753. settings = {};
  7754. }
  7755. if (settings.origin == null) {
  7756. settings.origin = new BABYLON.Vector2(0, 0);
  7757. }
  7758. _this = _super.call(this, settings) || this;
  7759. var size = (!settings.size && !settings.width && !settings.height) ? null : (settings.size || (new BABYLON.Size(settings.width || 0, settings.height || 0)));
  7760. _this._trackedNode = (settings.trackNode == null) ? null : settings.trackNode;
  7761. if (_this._trackedNode && _this.owner) {
  7762. _this.owner._registerTrackedNode(_this);
  7763. }
  7764. _this._cacheBehavior = (settings.cacheBehavior == null) ? Group2D_1.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY : settings.cacheBehavior;
  7765. var rd = _this._renderableData;
  7766. if (rd) {
  7767. rd._noResizeOnScale = (_this.cacheBehavior & Group2D_1.GROUPCACHEBEHAVIOR_NORESIZEONSCALE) !== 0;
  7768. }
  7769. _this.size = size;
  7770. _this._viewportPosition = BABYLON.Vector2.Zero();
  7771. _this._viewportSize = BABYLON.Size.Zero();
  7772. return _this;
  7773. }
  7774. Group2D._createCachedCanvasGroup = function (owner) {
  7775. 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 });
  7776. return g;
  7777. };
  7778. Group2D.prototype.applyCachedTexture = function (vertexData, material) {
  7779. this._bindCacheTarget();
  7780. if (vertexData) {
  7781. var uv = vertexData.uvs;
  7782. var nodeuv = this._renderableData._cacheNodeUVs;
  7783. for (var i = 0; i < 4; i++) {
  7784. uv[i * 2 + 0] = nodeuv[i].x;
  7785. uv[i * 2 + 1] = nodeuv[i].y;
  7786. }
  7787. }
  7788. if (material) {
  7789. material.diffuseTexture = this._renderableData._cacheTexture;
  7790. material.emissiveColor = new BABYLON.Color3(1, 1, 1);
  7791. }
  7792. this._renderableData._cacheTexture.hasAlpha = true;
  7793. this._unbindCacheTarget();
  7794. };
  7795. Object.defineProperty(Group2D.prototype, "cachedRect", {
  7796. /**
  7797. * Allow you to access the information regarding the cached rectangle of the Group2D into the MapTexture.
  7798. * 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.
  7799. */
  7800. get: function () {
  7801. if (!this._renderableData) {
  7802. return null;
  7803. }
  7804. return this._renderableData._cacheNode;
  7805. },
  7806. enumerable: true,
  7807. configurable: true
  7808. });
  7809. Object.defineProperty(Group2D.prototype, "cachedUVs", {
  7810. /**
  7811. * The UVs into the MapTexture that map the cached group
  7812. */
  7813. get: function () {
  7814. if (!this._renderableData) {
  7815. return null;
  7816. }
  7817. return this._renderableData._cacheNodeUVs;
  7818. },
  7819. enumerable: true,
  7820. configurable: true
  7821. });
  7822. Object.defineProperty(Group2D.prototype, "cachedUVsChanged", {
  7823. get: function () {
  7824. if (!this._renderableData) {
  7825. return null;
  7826. }
  7827. if (!this._renderableData._cacheNodeUVsChangedObservable) {
  7828. this._renderableData._cacheNodeUVsChangedObservable = new BABYLON.Observable();
  7829. }
  7830. return this._renderableData._cacheNodeUVsChangedObservable;
  7831. },
  7832. enumerable: true,
  7833. configurable: true
  7834. });
  7835. Object.defineProperty(Group2D.prototype, "cacheTexture", {
  7836. /**
  7837. * Access the texture that maintains a cached version of the Group2D.
  7838. * This is useful only if you're not using a WorldSpaceNode for your WorldSpace Canvas and therefore need to perform the rendering yourself.
  7839. */
  7840. get: function () {
  7841. if (!this._renderableData) {
  7842. return null;
  7843. }
  7844. return this._renderableData._cacheTexture;
  7845. },
  7846. enumerable: true,
  7847. configurable: true
  7848. });
  7849. /**
  7850. * Call this method to remove this Group and its children from the Canvas
  7851. */
  7852. Group2D.prototype.dispose = function () {
  7853. if (!_super.prototype.dispose.call(this)) {
  7854. return false;
  7855. }
  7856. if (this._trackedNode != null) {
  7857. this.owner._unregisterTrackedNode(this);
  7858. this._trackedNode = null;
  7859. }
  7860. if (this._renderableData) {
  7861. this._renderableData.dispose(this.owner);
  7862. this._renderableData = null;
  7863. }
  7864. return true;
  7865. };
  7866. Object.defineProperty(Group2D.prototype, "isRenderableGroup", {
  7867. /**
  7868. * @returns Returns true if the Group render content, false if it's a logical group only
  7869. */
  7870. get: function () {
  7871. return this._isRenderableGroup;
  7872. },
  7873. enumerable: true,
  7874. configurable: true
  7875. });
  7876. Object.defineProperty(Group2D.prototype, "isCachedGroup", {
  7877. /**
  7878. * @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
  7879. */
  7880. get: function () {
  7881. return this._isCachedGroup;
  7882. },
  7883. enumerable: true,
  7884. configurable: true
  7885. });
  7886. Object.defineProperty(Group2D.prototype, "size", {
  7887. get: function () {
  7888. return this._size;
  7889. },
  7890. /**
  7891. * Get/Set the size of the group. If null the size of the group will be determine from its content.
  7892. * 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.
  7893. */
  7894. set: function (val) {
  7895. this._size = val;
  7896. },
  7897. enumerable: true,
  7898. configurable: true
  7899. });
  7900. Object.defineProperty(Group2D.prototype, "viewportSize", {
  7901. get: function () {
  7902. return this._viewportSize;
  7903. },
  7904. enumerable: true,
  7905. configurable: true
  7906. });
  7907. Object.defineProperty(Group2D.prototype, "actualSize", {
  7908. get: function () {
  7909. // The computed size will be floor on both width and height
  7910. var actualSize;
  7911. // Return the actualSize if set
  7912. if (this._actualSize) {
  7913. return this._actualSize;
  7914. }
  7915. // Return the size if set by the user
  7916. if (this._size) {
  7917. actualSize = new BABYLON.Size(Math.ceil(this._size.width), Math.ceil(this._size.height));
  7918. }
  7919. else {
  7920. var m = this.layoutBoundingInfo.max();
  7921. actualSize = new BABYLON.Size(Math.ceil(m.x), Math.ceil(m.y));
  7922. }
  7923. // 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)
  7924. if (!actualSize.equals(this._actualSize)) {
  7925. this.onPrimitivePropertyDirty(Group2D_1.actualSizeProperty.flagId);
  7926. this._actualSize = actualSize;
  7927. this.handleGroupChanged(Group2D_1.actualSizeProperty);
  7928. }
  7929. return actualSize;
  7930. },
  7931. set: function (value) {
  7932. this._actualSize = value;
  7933. },
  7934. enumerable: true,
  7935. configurable: true
  7936. });
  7937. Object.defineProperty(Group2D.prototype, "cacheBehavior", {
  7938. /**
  7939. * 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.
  7940. * GROUPCACHEBEHAVIOR_NORESIZEONSCALE can also be set if you set it at creation time.
  7941. * 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.
  7942. */
  7943. get: function () {
  7944. return this._cacheBehavior;
  7945. },
  7946. enumerable: true,
  7947. configurable: true
  7948. });
  7949. Group2D.prototype._addPrimToDirtyList = function (prim) {
  7950. this._renderableData._primDirtyList.push(prim);
  7951. };
  7952. Group2D.prototype._renderCachedCanvas = function () {
  7953. this.owner._addGroupRenderCount(1);
  7954. this.updateCachedStates(true);
  7955. var context = new BABYLON.PrepareRender2DContext();
  7956. this._prepareGroupRender(context);
  7957. this._groupRender();
  7958. };
  7959. Object.defineProperty(Group2D.prototype, "trackedNode", {
  7960. /**
  7961. * Get/set the Scene's Node that should be tracked, the group's position will follow the projected position of the Node.
  7962. */
  7963. get: function () {
  7964. return this._trackedNode;
  7965. },
  7966. set: function (val) {
  7967. if (val != null) {
  7968. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  7969. this.owner._registerTrackedNode(this);
  7970. }
  7971. this._trackedNode = val;
  7972. }
  7973. else {
  7974. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  7975. this.owner._unregisterTrackedNode(this);
  7976. }
  7977. this._trackedNode = null;
  7978. }
  7979. },
  7980. enumerable: true,
  7981. configurable: true
  7982. });
  7983. Group2D.prototype.levelIntersect = function (intersectInfo) {
  7984. // 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
  7985. return true;
  7986. };
  7987. Group2D.prototype.updateLevelBoundingInfo = function () {
  7988. var size;
  7989. // If the size is set by the user, the boundingInfo is computed from this value
  7990. if (this.size) {
  7991. size = this.size;
  7992. }
  7993. else {
  7994. size = new BABYLON.Size(0, 0);
  7995. }
  7996. BABYLON.BoundingInfo2D.CreateFromSizeToRef(size, this._levelBoundingInfo);
  7997. };
  7998. // Method called only on renderable groups to prepare the rendering
  7999. Group2D.prototype._prepareGroupRender = function (context) {
  8000. var sortedDirtyList = null;
  8001. // Update the Global Transformation and visibility status of the changed primitives
  8002. var rd = this._renderableData;
  8003. if ((rd._primDirtyList.length > 0) || context.forceRefreshPrimitive) {
  8004. sortedDirtyList = rd._primDirtyList.sort(function (a, b) { return a.hierarchyDepth - b.hierarchyDepth; });
  8005. this.updateCachedStatesOf(sortedDirtyList, true);
  8006. }
  8007. var s = this.actualSize;
  8008. var a = this.actualScale;
  8009. var sw = Math.ceil(s.width * a.x);
  8010. var sh = Math.ceil(s.height * a.y);
  8011. // 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.
  8012. // So we set the width/height to the rendering's one because that's what we want for the viewport!
  8013. if ((this instanceof BABYLON.Canvas2D || this.id === "__cachedCanvasGroup__") && this.owner.designSize != null) {
  8014. sw = this.owner.engine.getRenderWidth();
  8015. sh = this.owner.engine.getRenderHeight();
  8016. }
  8017. // Setup the size of the rendering viewport
  8018. // 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
  8019. if (!this._isCachedGroup) {
  8020. // Compute the WebGL viewport's location/size
  8021. var t = this._globalTransform.getTranslation();
  8022. var rs = this.owner._renderingSize;
  8023. sh = Math.min(sh, rs.height - t.y);
  8024. sw = Math.min(sw, rs.width - t.x);
  8025. var x = t.x;
  8026. var y = t.y;
  8027. // 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
  8028. this._viewportPosition.x = x;
  8029. this._viewportPosition.y = y;
  8030. }
  8031. // 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.
  8032. if (this._viewportSize.width !== sw || this._viewportSize.height !== sh) {
  8033. context.forceRefreshPrimitive = true;
  8034. this._viewportSize.width = sw;
  8035. this._viewportSize.height = sh;
  8036. }
  8037. if ((rd._primDirtyList.length > 0) || context.forceRefreshPrimitive) {
  8038. // If the group is cached, set the dirty flag to true because of the incoming changes
  8039. this._cacheGroupDirty = this._isCachedGroup;
  8040. rd._primNewDirtyList.splice(0);
  8041. // If it's a force refresh, prepare all the children
  8042. if (context.forceRefreshPrimitive) {
  8043. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  8044. var p = _a[_i];
  8045. p._prepareRender(context);
  8046. }
  8047. }
  8048. else {
  8049. // Each primitive that changed at least once was added into the primDirtyList, we have to sort this level using
  8050. // the hierarchyDepth in order to prepare primitives from top to bottom
  8051. if (!sortedDirtyList) {
  8052. sortedDirtyList = rd._primDirtyList.sort(function (a, b) { return a.hierarchyDepth - b.hierarchyDepth; });
  8053. }
  8054. sortedDirtyList.forEach(function (p) {
  8055. // 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.
  8056. // 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.
  8057. if (!p.isDisposed && p._needPrepare()) {
  8058. p._prepareRender(context);
  8059. }
  8060. });
  8061. }
  8062. // Everything is updated, clear the dirty list
  8063. rd._primDirtyList.forEach(function (p) {
  8064. if (rd._primNewDirtyList.indexOf(p) === -1) {
  8065. p._resetPropertiesDirty();
  8066. }
  8067. else {
  8068. p._setFlags(BABYLON.SmartPropertyPrim.flagNeedRefresh);
  8069. }
  8070. });
  8071. rd._primDirtyList.splice(0);
  8072. rd._primDirtyList = rd._primDirtyList.concat(rd._primNewDirtyList);
  8073. }
  8074. // A renderable group has a list of direct children that are also renderable groups, we recurse on them to also prepare them
  8075. rd._childrenRenderableGroups.forEach(function (g) {
  8076. g._prepareGroupRender(context);
  8077. });
  8078. };
  8079. Group2D.prototype._groupRender = function () {
  8080. var _this = this;
  8081. var engine = this.owner.engine;
  8082. var failedCount = 0;
  8083. // First recurse to children render group to render them (in their cache or on screen)
  8084. for (var _i = 0, _a = this._renderableData._childrenRenderableGroups; _i < _a.length; _i++) {
  8085. var childGroup = _a[_i];
  8086. childGroup._groupRender();
  8087. }
  8088. // Render the primitives if needed: either if we don't cache the content or if the content is cached but has changed
  8089. if (!this.isCachedGroup || this._cacheGroupDirty) {
  8090. this.owner._addGroupRenderCount(1);
  8091. if (this.isCachedGroup) {
  8092. this._bindCacheTarget();
  8093. }
  8094. else {
  8095. var curVP = engine.setDirectViewport(this._viewportPosition.x, this._viewportPosition.y, this._viewportSize.width, this._viewportSize.height);
  8096. }
  8097. var curAlphaTest = engine.getAlphaTesting() === true;
  8098. var curDepthWrite = engine.getDepthWrite() === true;
  8099. // ===================================================================
  8100. // First pass, update the InstancedArray and render Opaque primitives
  8101. // Disable Alpha Testing, Enable Depth Write
  8102. engine.setAlphaTesting(false);
  8103. engine.setDepthWrite(true);
  8104. // For each different model of primitive to render
  8105. var context_1 = new BABYLON.Render2DContext(BABYLON.Render2DContext.RenderModeOpaque);
  8106. this._renderableData._renderGroupInstancesInfo.forEach(function (k, v) {
  8107. // Prepare the context object, update the WebGL Instanced Array buffer if needed
  8108. var renderCount = _this._prepareContext(engine, context_1, v);
  8109. // If null is returned, there's no opaque data to render
  8110. if (renderCount === null) {
  8111. return;
  8112. }
  8113. // Submit render only if we have something to render (everything may be hidden and the floatarray empty)
  8114. if (!_this.owner.supportInstancedArray || renderCount > 0) {
  8115. // render all the instances of this model, if the render method returns true then our instances are no longer dirty
  8116. var renderFailed = !v.modelRenderCache.render(v, context_1);
  8117. // Update dirty flag/related
  8118. v.opaqueDirty = renderFailed;
  8119. failedCount += renderFailed ? 1 : 0;
  8120. }
  8121. });
  8122. // =======================================================================
  8123. // Second pass, update the InstancedArray and render AlphaTest primitives
  8124. // Enable Alpha Testing, Enable Depth Write
  8125. engine.setAlphaTesting(true);
  8126. engine.setDepthWrite(true);
  8127. // For each different model of primitive to render
  8128. context_1 = new BABYLON.Render2DContext(BABYLON.Render2DContext.RenderModeAlphaTest);
  8129. this._renderableData._renderGroupInstancesInfo.forEach(function (k, v) {
  8130. // Prepare the context object, update the WebGL Instanced Array buffer if needed
  8131. var renderCount = _this._prepareContext(engine, context_1, v);
  8132. // If null is returned, there's no opaque data to render
  8133. if (renderCount === null) {
  8134. return;
  8135. }
  8136. // Submit render only if we have something to render (everything may be hidden and the floatarray empty)
  8137. if (!_this.owner.supportInstancedArray || renderCount > 0) {
  8138. // render all the instances of this model, if the render method returns true then our instances are no longer dirty
  8139. var renderFailed = !v.modelRenderCache.render(v, context_1);
  8140. // Update dirty flag/related
  8141. v.opaqueDirty = renderFailed;
  8142. failedCount += renderFailed ? 1 : 0;
  8143. }
  8144. });
  8145. // =======================================================================
  8146. // Third pass, transparent primitive rendering
  8147. // Enable Alpha Testing, Disable Depth Write
  8148. engine.setAlphaTesting(true);
  8149. engine.setDepthWrite(false);
  8150. // First Check if the transparent List change so we can update the TransparentSegment and PartData (sort if needed)
  8151. if (this._renderableData._transparentListChanged) {
  8152. this._updateTransparentData();
  8153. }
  8154. // From this point on we have up to date data to render, so let's go
  8155. failedCount += this._renderTransparentData();
  8156. // =======================================================================
  8157. // Unbind target/restore viewport setting, clear dirty flag, and quit
  8158. // The group's content is no longer dirty
  8159. this._cacheGroupDirty = failedCount !== 0;
  8160. if (this.isCachedGroup) {
  8161. this._unbindCacheTarget();
  8162. }
  8163. else {
  8164. if (curVP) {
  8165. engine.setViewport(curVP);
  8166. }
  8167. }
  8168. // Restore saved states
  8169. engine.setAlphaTesting(curAlphaTest);
  8170. engine.setDepthWrite(curDepthWrite);
  8171. }
  8172. };
  8173. Group2D.prototype._setCacheGroupDirty = function () {
  8174. this._cacheGroupDirty = true;
  8175. };
  8176. Group2D.prototype._updateTransparentData = function () {
  8177. this.owner._addUpdateTransparentDataCount(1);
  8178. var rd = this._renderableData;
  8179. // Sort all the primitive from their depth, max (bottom) to min (top)
  8180. rd._transparentPrimitives.sort(function (a, b) { return b._primitive.actualZOffset - a._primitive.actualZOffset; });
  8181. var checkAndAddPrimInSegment = function (seg, tpiI) {
  8182. var tpi = rd._transparentPrimitives[tpiI];
  8183. // Fast rejection: if gii are different
  8184. if (seg.groupInsanceInfo !== tpi._groupInstanceInfo) {
  8185. return false;
  8186. }
  8187. //let tpiZ = tpi._primitive.actualZOffset;
  8188. // We've made it so far, the tpi can be part of the segment, add it
  8189. tpi._transparentSegment = seg;
  8190. tpi._primitive._updateTransparentSegmentIndices(seg);
  8191. return true;
  8192. };
  8193. // Free the existing TransparentSegments
  8194. for (var _i = 0, _a = rd._transparentSegments; _i < _a.length; _i++) {
  8195. var ts = _a[_i];
  8196. ts.dispose(this.owner.engine);
  8197. }
  8198. rd._transparentSegments.splice(0);
  8199. var prevSeg = null;
  8200. for (var tpiI = 0; tpiI < rd._transparentPrimitives.length; tpiI++) {
  8201. var tpi = rd._transparentPrimitives[tpiI];
  8202. // Check if the Data in which the primitive is stored is not sorted properly
  8203. if (tpi._groupInstanceInfo.transparentOrderDirty) {
  8204. tpi._groupInstanceInfo.sortTransparentData();
  8205. }
  8206. // Reset the segment, we have to create/rebuild it
  8207. tpi._transparentSegment = null;
  8208. // If there's a previous valid segment, check if this prim can be part of it
  8209. if (prevSeg) {
  8210. checkAndAddPrimInSegment(prevSeg, tpiI);
  8211. }
  8212. // If we couldn't insert in the adjacent segments, he have to create one
  8213. if (!tpi._transparentSegment) {
  8214. var ts = new BABYLON.TransparentSegment();
  8215. ts.groupInsanceInfo = tpi._groupInstanceInfo;
  8216. var prim = tpi._primitive;
  8217. ts.startZ = prim.actualZOffset;
  8218. prim._updateTransparentSegmentIndices(ts);
  8219. ts.endZ = ts.startZ;
  8220. tpi._transparentSegment = ts;
  8221. rd._transparentSegments.push(ts);
  8222. }
  8223. // Update prevSeg
  8224. prevSeg = tpi._transparentSegment;
  8225. }
  8226. //rd._firstChangedPrim = null;
  8227. rd._transparentListChanged = false;
  8228. };
  8229. Group2D.prototype._renderTransparentData = function () {
  8230. var failedCount = 0;
  8231. var context = new BABYLON.Render2DContext(BABYLON.Render2DContext.RenderModeTransparent);
  8232. var rd = this._renderableData;
  8233. var useInstanced = this.owner.supportInstancedArray;
  8234. var length = rd._transparentSegments.length;
  8235. for (var i = 0; i < length; i++) {
  8236. context.instancedBuffers = null;
  8237. var ts = rd._transparentSegments[i];
  8238. var gii = ts.groupInsanceInfo;
  8239. var mrc = gii.modelRenderCache;
  8240. var engine = this.owner.engine;
  8241. var count = ts.endDataIndex - ts.startDataIndex;
  8242. // Use Instanced Array if it's supported and if there's at least minPartCountToUseInstancedArray prims to draw.
  8243. // We don't want to create an Instanced Buffer for less that minPartCountToUseInstancedArray prims
  8244. if (useInstanced && count >= this.owner.minPartCountToUseInstancedArray) {
  8245. if (!ts.partBuffers) {
  8246. var buffers = new Array();
  8247. for (var j = 0; j < gii.transparentData.length; j++) {
  8248. var gitd = gii.transparentData[j];
  8249. var dfa = gitd._partData;
  8250. var data = dfa.pack();
  8251. var stride = dfa.stride;
  8252. var neededSize = count * stride * 4;
  8253. var buffer = engine.createInstancesBuffer(neededSize); // Create + bind
  8254. var segData = data.subarray(ts.startDataIndex * stride, ts.endDataIndex * stride);
  8255. engine.updateArrayBuffer(segData);
  8256. buffers.push(buffer);
  8257. }
  8258. ts.partBuffers = buffers;
  8259. }
  8260. else if (gii.transparentDirty) {
  8261. for (var j = 0; j < gii.transparentData.length; j++) {
  8262. var gitd = gii.transparentData[j];
  8263. var dfa = gitd._partData;
  8264. var data = dfa.pack();
  8265. var stride = dfa.stride;
  8266. var buffer = ts.partBuffers[j];
  8267. var segData = data.subarray(ts.startDataIndex * stride, ts.endDataIndex * stride);
  8268. engine.bindArrayBuffer(buffer);
  8269. engine.updateArrayBuffer(segData);
  8270. }
  8271. }
  8272. context.useInstancing = true;
  8273. context.instancesCount = count;
  8274. context.instancedBuffers = ts.partBuffers;
  8275. context.groupInfoPartData = gii.transparentData;
  8276. var renderFailed = !mrc.render(gii, context);
  8277. failedCount += renderFailed ? 1 : 0;
  8278. }
  8279. else {
  8280. context.useInstancing = false;
  8281. context.partDataStartIndex = ts.startDataIndex;
  8282. context.partDataEndIndex = ts.endDataIndex;
  8283. context.groupInfoPartData = gii.transparentData;
  8284. var renderFailed = !mrc.render(gii, context);
  8285. failedCount += renderFailed ? 1 : 0;
  8286. }
  8287. }
  8288. return failedCount;
  8289. };
  8290. Group2D.prototype._prepareContext = function (engine, context, gii) {
  8291. var gipd = null;
  8292. var setDirty;
  8293. var getDirty;
  8294. // Render Mode specifics
  8295. switch (context.renderMode) {
  8296. case BABYLON.Render2DContext.RenderModeOpaque:
  8297. {
  8298. if (!gii.hasOpaqueData) {
  8299. return null;
  8300. }
  8301. setDirty = function (dirty) { gii.opaqueDirty = dirty; };
  8302. getDirty = function () { return gii.opaqueDirty; };
  8303. context.groupInfoPartData = gii.opaqueData;
  8304. gipd = gii.opaqueData;
  8305. break;
  8306. }
  8307. case BABYLON.Render2DContext.RenderModeAlphaTest:
  8308. {
  8309. if (!gii.hasAlphaTestData) {
  8310. return null;
  8311. }
  8312. setDirty = function (dirty) { gii.alphaTestDirty = dirty; };
  8313. getDirty = function () { return gii.alphaTestDirty; };
  8314. context.groupInfoPartData = gii.alphaTestData;
  8315. gipd = gii.alphaTestData;
  8316. break;
  8317. }
  8318. default:
  8319. throw new Error("_prepareContext is only for opaque or alphaTest");
  8320. }
  8321. var renderCount = 0;
  8322. // This part will pack the dynamicfloatarray and update the instanced array WebGLBufffer
  8323. // Skip it if instanced arrays are not supported
  8324. if (this.owner.supportInstancedArray) {
  8325. // Flag for instancing
  8326. context.useInstancing = true;
  8327. // Make sure all the WebGLBuffers of the Instanced Array are created/up to date for the parts to render.
  8328. for (var i = 0; i < gipd.length; i++) {
  8329. var pid = gipd[i];
  8330. // If the instances of the model was changed, pack the data
  8331. var array = pid._partData;
  8332. var instanceData_1 = array.pack();
  8333. renderCount += array.usedElementCount;
  8334. // Compute the size the instance buffer should have
  8335. var neededSize = array.usedElementCount * array.stride * 4;
  8336. // Check if we have to (re)create the instancesBuffer because there's none or the size is too small
  8337. if (!pid._partBuffer || (pid._partBufferSize < neededSize)) {
  8338. if (pid._partBuffer) {
  8339. engine.deleteInstancesBuffer(pid._partBuffer);
  8340. }
  8341. pid._partBuffer = engine.createInstancesBuffer(neededSize); // Create + bind
  8342. pid._partBufferSize = neededSize;
  8343. setDirty(false);
  8344. // Update the WebGL buffer to match the new content of the instances data
  8345. engine.updateArrayBuffer(instanceData_1);
  8346. }
  8347. else if (getDirty()) {
  8348. // Update the WebGL buffer to match the new content of the instances data
  8349. engine.bindArrayBuffer(pid._partBuffer);
  8350. engine.updateArrayBuffer(instanceData_1);
  8351. }
  8352. }
  8353. setDirty(false);
  8354. }
  8355. else {
  8356. context.partDataStartIndex = 0;
  8357. // Find the first valid object to get the count
  8358. if (context.groupInfoPartData.length > 0) {
  8359. var i = 0;
  8360. while (!context.groupInfoPartData[i]) {
  8361. i++;
  8362. }
  8363. context.partDataEndIndex = context.groupInfoPartData[i]._partData.usedElementCount;
  8364. }
  8365. }
  8366. return renderCount;
  8367. };
  8368. Group2D.prototype._setRenderingScale = function (scale) {
  8369. if (this._renderableData._renderingScale === scale) {
  8370. return;
  8371. }
  8372. this._renderableData._renderingScale = scale;
  8373. };
  8374. Group2D.prototype._bindCacheTarget = function () {
  8375. var curWidth;
  8376. var curHeight;
  8377. var rd = this._renderableData;
  8378. var rs = rd._renderingScale;
  8379. var noResizeScale = rd._noResizeOnScale;
  8380. var isCanvas = this.parent == null;
  8381. var scale;
  8382. if (noResizeScale) {
  8383. scale = isCanvas ? Group2D_1._uV : this.parent.actualScale;
  8384. }
  8385. else {
  8386. scale = this.actualScale;
  8387. }
  8388. if (isCanvas && this.owner.cachingStrategy === BABYLON.Canvas2D.CACHESTRATEGY_CANVAS && this.owner.isScreenSpace) {
  8389. if (this.owner.designSize || this.owner.fitRenderingDevice) {
  8390. Group2D_1._s.width = this.owner.engine.getRenderWidth();
  8391. Group2D_1._s.height = this.owner.engine.getRenderHeight();
  8392. }
  8393. else {
  8394. Group2D_1._s.copyFrom(this.owner.size);
  8395. }
  8396. }
  8397. else {
  8398. Group2D_1._s.width = Math.ceil(this.actualSize.width * scale.x * rs);
  8399. Group2D_1._s.height = Math.ceil(this.actualSize.height * scale.y * rs);
  8400. }
  8401. var sizeChanged = !Group2D_1._s.equals(rd._cacheSize);
  8402. if (rd._cacheNode) {
  8403. var size = rd._cacheNode.contentSize;
  8404. // Check if we have to deallocate because the size is too small
  8405. if ((size.width < Group2D_1._s.width) || (size.height < Group2D_1._s.height)) {
  8406. // For Screen space: over-provisioning of 7% more to avoid frequent resizing for few pixels...
  8407. // For World space: no over-provisioning
  8408. var overprovisioning = this.owner.isScreenSpace ? 1.07 : 1;
  8409. curWidth = Math.floor(Group2D_1._s.width * overprovisioning);
  8410. curHeight = Math.floor(Group2D_1._s.height * overprovisioning);
  8411. //console.log(`[${this._globalTransformProcessStep}] Resize group ${this.id}, width: ${curWidth}, height: ${curHeight}`);
  8412. rd._cacheTexture.freeRect(rd._cacheNode);
  8413. rd._cacheNode = null;
  8414. }
  8415. }
  8416. if (!rd._cacheNode) {
  8417. // Check if we have to allocate a rendering zone in the global cache texture
  8418. var res = this.owner._allocateGroupCache(this, this.parent && this.parent.renderGroup, curWidth ? new BABYLON.Size(curWidth, curHeight) : null, rd._useMipMap, rd._anisotropicLevel);
  8419. rd._cacheNode = res.node;
  8420. rd._cacheTexture = res.texture;
  8421. if (rd._cacheRenderSprite) {
  8422. rd._cacheRenderSprite.dispose();
  8423. }
  8424. rd._cacheRenderSprite = res.sprite;
  8425. sizeChanged = true;
  8426. }
  8427. if (sizeChanged) {
  8428. rd._cacheSize.copyFrom(Group2D_1._s);
  8429. rd._cacheNodeUVs = rd._cacheNode.getUVsForCustomSize(rd._cacheSize);
  8430. if (rd._cacheNodeUVsChangedObservable && rd._cacheNodeUVsChangedObservable.hasObservers()) {
  8431. rd._cacheNodeUVsChangedObservable.notifyObservers(rd._cacheNodeUVs);
  8432. }
  8433. this._setFlags(BABYLON.SmartPropertyPrim.flagWorldCacheChanged);
  8434. }
  8435. var n = rd._cacheNode;
  8436. rd._cacheTexture.bindTextureForPosSize(n.pos, Group2D_1._s, true);
  8437. };
  8438. Group2D.prototype._unbindCacheTarget = function () {
  8439. if (this._renderableData._cacheTexture) {
  8440. this._renderableData._cacheTexture.unbindTexture();
  8441. }
  8442. };
  8443. Group2D.prototype._spreadActualScaleDirty = function () {
  8444. if (this._renderableData && this._renderableData._cacheRenderSprite) {
  8445. this.handleGroupChanged(BABYLON.Prim2DBase.actualScaleProperty);
  8446. }
  8447. _super.prototype._spreadActualScaleDirty.call(this);
  8448. };
  8449. Group2D.prototype.handleGroupChanged = function (prop) {
  8450. // This method is only for cachedGroup
  8451. var rd = this._renderableData;
  8452. if (!rd) {
  8453. return;
  8454. }
  8455. var cachedSprite = rd._cacheRenderSprite;
  8456. if (!this.isCachedGroup || !cachedSprite) {
  8457. return;
  8458. }
  8459. // For now we only support these property changes
  8460. // TODO: add more! :)
  8461. switch (prop.id) {
  8462. case BABYLON.Prim2DBase.actualPositionProperty.id:
  8463. cachedSprite.actualPosition = this.actualPosition.clone();
  8464. if (cachedSprite.position != null) {
  8465. cachedSprite.position = cachedSprite.actualPosition.clone();
  8466. }
  8467. break;
  8468. case BABYLON.Prim2DBase.rotationProperty.id:
  8469. cachedSprite.rotation = this.rotation;
  8470. break;
  8471. case BABYLON.Prim2DBase.scaleProperty.id:
  8472. cachedSprite.scale = this.scale;
  8473. break;
  8474. case BABYLON.Prim2DBase.originProperty.id:
  8475. cachedSprite.origin = this.origin.clone();
  8476. break;
  8477. case Group2D_1.actualSizeProperty.id:
  8478. cachedSprite.size = this.actualSize.clone();
  8479. break;
  8480. }
  8481. };
  8482. Group2D.prototype.detectGroupStates = function () {
  8483. var isCanvas = this instanceof BABYLON.Canvas2D;
  8484. var canvasStrat = this.owner.cachingStrategy;
  8485. // In Don't Cache mode, only the canvas is renderable, all the other groups are logical. There are not a single cached group.
  8486. if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_DONTCACHE) {
  8487. this._isRenderableGroup = isCanvas;
  8488. this._isCachedGroup = false;
  8489. }
  8490. else if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_CANVAS) {
  8491. if (isCanvas) {
  8492. this._isRenderableGroup = true;
  8493. this._isCachedGroup = true;
  8494. }
  8495. else {
  8496. this._isRenderableGroup = this.id === "__cachedCanvasGroup__";
  8497. this._isCachedGroup = false;
  8498. }
  8499. }
  8500. else if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_TOPLEVELGROUPS) {
  8501. if (isCanvas) {
  8502. this._isRenderableGroup = true;
  8503. this._isCachedGroup = false;
  8504. }
  8505. else {
  8506. if (this.hierarchyDepth === 1) {
  8507. this._isRenderableGroup = true;
  8508. this._isCachedGroup = true;
  8509. }
  8510. else {
  8511. this._isRenderableGroup = false;
  8512. this._isCachedGroup = false;
  8513. }
  8514. }
  8515. }
  8516. else if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_ALLGROUPS) {
  8517. if (isCanvas) {
  8518. this._isRenderableGroup = true;
  8519. this._isCachedGroup = false;
  8520. }
  8521. else {
  8522. var gcb = this.cacheBehavior & Group2D_1.GROUPCACHEBEHAVIOR_OPTIONMASK;
  8523. if ((gcb === Group2D_1.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE) || (gcb === Group2D_1.GROUPCACHEBEHAVIOR_CACHEINPARENTGROUP)) {
  8524. this._isRenderableGroup = gcb === Group2D_1.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE;
  8525. this._isCachedGroup = false;
  8526. }
  8527. if (gcb === Group2D_1.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY) {
  8528. this._isRenderableGroup = true;
  8529. this._isCachedGroup = true;
  8530. }
  8531. }
  8532. }
  8533. if (this._isRenderableGroup) {
  8534. // Yes, we do need that check, trust me, unfortunately we can call _detectGroupStates many time on the same object...
  8535. if (!this._renderableData) {
  8536. this._renderableData = new RenderableGroupData();
  8537. }
  8538. }
  8539. // If the group is tagged as renderable we add it to the renderable tree
  8540. if (this._isCachedGroup) {
  8541. this._renderableData._noResizeOnScale = (this.cacheBehavior & Group2D_1.GROUPCACHEBEHAVIOR_NORESIZEONSCALE) !== 0;
  8542. var cur = this.parent;
  8543. while (cur) {
  8544. if (cur instanceof Group2D_1 && cur._isRenderableGroup) {
  8545. if (cur._renderableData._childrenRenderableGroups.indexOf(this) === -1) {
  8546. cur._renderableData._childrenRenderableGroups.push(this);
  8547. }
  8548. break;
  8549. }
  8550. cur = cur.parent;
  8551. }
  8552. }
  8553. };
  8554. return Group2D;
  8555. }(BABYLON.Prim2DBase));
  8556. Group2D.GROUP2D_PROPCOUNT = BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 5;
  8557. /**
  8558. * Default behavior, the group will use the caching strategy defined at the Canvas Level
  8559. */
  8560. Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY = 0;
  8561. /**
  8562. * When used, this group's content won't be cached, no matter which strategy used.
  8563. * If the group is part of a WorldSpace Canvas, its content will be drawn in the Canvas cache bitmap.
  8564. */
  8565. Group2D.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE = 1;
  8566. /**
  8567. * When used, the group's content will be cached in the nearest cached parent group/canvas
  8568. */
  8569. Group2D.GROUPCACHEBEHAVIOR_CACHEINPARENTGROUP = 2;
  8570. /**
  8571. * 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
  8572. */
  8573. Group2D.GROUPCACHEBEHAVIOR_NORESIZEONSCALE = 0x100;
  8574. Group2D.GROUPCACHEBEHAVIOR_OPTIONMASK = 0xFF;
  8575. Group2D._uV = new BABYLON.Vector2(1, 1);
  8576. Group2D._s = BABYLON.Size.Zero();
  8577. Group2D._unS = new BABYLON.Vector2(1, 1);
  8578. __decorate([
  8579. BABYLON.instanceLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 1, function (pi) { return Group2D_1.sizeProperty = pi; }, false, true)
  8580. ], Group2D.prototype, "size", null);
  8581. __decorate([
  8582. BABYLON.instanceLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 2, function (pi) { return Group2D_1.actualSizeProperty = pi; })
  8583. ], Group2D.prototype, "actualSize", null);
  8584. Group2D = Group2D_1 = __decorate([
  8585. BABYLON.className("Group2D", "BABYLON")
  8586. ], Group2D);
  8587. BABYLON.Group2D = Group2D;
  8588. var RenderableGroupData = (function () {
  8589. function RenderableGroupData() {
  8590. this._primDirtyList = new Array();
  8591. this._primNewDirtyList = new Array();
  8592. this._childrenRenderableGroups = new Array();
  8593. this._renderGroupInstancesInfo = new BABYLON.StringDictionary();
  8594. this._transparentPrimitives = new Array();
  8595. this._transparentSegments = new Array();
  8596. this._transparentListChanged = false;
  8597. this._cacheNode = null;
  8598. this._cacheTexture = null;
  8599. this._cacheRenderSprite = null;
  8600. this._renderingScale = 1;
  8601. this._cacheNodeUVs = null;
  8602. this._cacheNodeUVsChangedObservable = null;
  8603. this._cacheSize = BABYLON.Size.Zero();
  8604. this._useMipMap = false;
  8605. this._anisotropicLevel = 1;
  8606. this._noResizeOnScale = false;
  8607. }
  8608. RenderableGroupData.prototype.dispose = function (owner) {
  8609. var engine = owner.engine;
  8610. if (this._cacheRenderSprite) {
  8611. this._cacheRenderSprite.dispose();
  8612. this._cacheRenderSprite = null;
  8613. }
  8614. if (this._cacheTexture && this._cacheNode) {
  8615. this._cacheTexture.freeRect(this._cacheNode);
  8616. this._cacheTexture = null;
  8617. this._cacheNode = null;
  8618. }
  8619. if (this._primDirtyList) {
  8620. this._primDirtyList.splice(0);
  8621. this._primDirtyList = null;
  8622. }
  8623. if (this._renderGroupInstancesInfo) {
  8624. this._renderGroupInstancesInfo.forEach(function (k, v) {
  8625. v.dispose();
  8626. });
  8627. this._renderGroupInstancesInfo = null;
  8628. }
  8629. if (this._cacheNodeUVsChangedObservable) {
  8630. this._cacheNodeUVsChangedObservable.clear();
  8631. this._cacheNodeUVsChangedObservable = null;
  8632. }
  8633. if (this._transparentSegments) {
  8634. for (var _i = 0, _a = this._transparentSegments; _i < _a.length; _i++) {
  8635. var ts = _a[_i];
  8636. ts.dispose(engine);
  8637. }
  8638. this._transparentSegments.splice(0);
  8639. this._transparentSegments = null;
  8640. }
  8641. };
  8642. RenderableGroupData.prototype.addNewTransparentPrimitiveInfo = function (prim, gii) {
  8643. var tpi = new TransparentPrimitiveInfo();
  8644. tpi._primitive = prim;
  8645. tpi._groupInstanceInfo = gii;
  8646. tpi._transparentSegment = null;
  8647. this._transparentPrimitives.push(tpi);
  8648. this._transparentListChanged = true;
  8649. return tpi;
  8650. };
  8651. RenderableGroupData.prototype.removeTransparentPrimitiveInfo = function (tpi) {
  8652. var index = this._transparentPrimitives.indexOf(tpi);
  8653. if (index !== -1) {
  8654. this._transparentPrimitives.splice(index, 1);
  8655. this._transparentListChanged = true;
  8656. }
  8657. };
  8658. RenderableGroupData.prototype.transparentPrimitiveZChanged = function (tpi) {
  8659. this._transparentListChanged = true;
  8660. //this.updateSmallestZChangedPrim(tpi);
  8661. };
  8662. return RenderableGroupData;
  8663. }());
  8664. BABYLON.RenderableGroupData = RenderableGroupData;
  8665. var TransparentPrimitiveInfo = (function () {
  8666. function TransparentPrimitiveInfo() {
  8667. }
  8668. return TransparentPrimitiveInfo;
  8669. }());
  8670. BABYLON.TransparentPrimitiveInfo = TransparentPrimitiveInfo;
  8671. var Group2D_1;
  8672. })(BABYLON || (BABYLON = {}));
  8673. //# sourceMappingURL=babylon.group2d.js.map
  8674. var __extends = (this && this.__extends) || function (d, b) {
  8675. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  8676. function __() { this.constructor = d; }
  8677. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8678. };
  8679. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  8680. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  8681. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  8682. 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;
  8683. return c > 3 && r && Object.defineProperty(target, key, r), r;
  8684. };
  8685. var BABYLON;
  8686. (function (BABYLON) {
  8687. var Rectangle2DRenderCache = (function (_super) {
  8688. __extends(Rectangle2DRenderCache, _super);
  8689. function Rectangle2DRenderCache(engine, modelKey) {
  8690. var _this = _super.call(this, engine, modelKey) || this;
  8691. _this.effectsReady = false;
  8692. _this.fillVB = null;
  8693. _this.fillIB = null;
  8694. _this.fillIndicesCount = 0;
  8695. _this.instancingFillAttributes = null;
  8696. _this.effectFill = null;
  8697. _this.effectFillInstanced = null;
  8698. _this.borderVB = null;
  8699. _this.borderIB = null;
  8700. _this.borderIndicesCount = 0;
  8701. _this.instancingBorderAttributes = null;
  8702. _this.effectBorder = null;
  8703. _this.effectBorderInstanced = null;
  8704. return _this;
  8705. }
  8706. Rectangle2DRenderCache.prototype.render = function (instanceInfo, context) {
  8707. // Do nothing if the shader is still loading/preparing
  8708. if (!this.effectsReady) {
  8709. if ((this.effectFill && (!this.effectFill.isReady() || (this.effectFillInstanced && !this.effectFillInstanced.isReady()))) ||
  8710. (this.effectBorder && (!this.effectBorder.isReady() || (this.effectBorderInstanced && !this.effectBorderInstanced.isReady())))) {
  8711. return false;
  8712. }
  8713. this.effectsReady = true;
  8714. }
  8715. var canvas = instanceInfo.owner.owner;
  8716. var engine = canvas.engine;
  8717. var depthFunction = 0;
  8718. if (this.effectFill && this.effectBorder) {
  8719. depthFunction = engine.getDepthFunction();
  8720. engine.setDepthFunctionToLessOrEqual();
  8721. }
  8722. var curAlphaMode = engine.getAlphaMode();
  8723. if (this.effectFill) {
  8724. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_FILLPARTID.toString());
  8725. var pid = context.groupInfoPartData[partIndex];
  8726. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  8727. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  8728. }
  8729. var effect = context.useInstancing ? this.effectFillInstanced : this.effectFill;
  8730. engine.enableEffect(effect);
  8731. engine.bindBuffersDirectly(this.fillVB, this.fillIB, [1], 4, effect);
  8732. if (context.useInstancing) {
  8733. if (!this.instancingFillAttributes) {
  8734. this.instancingFillAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_FILLPARTID, effect);
  8735. }
  8736. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  8737. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  8738. canvas._addDrawCallCount(1, context.renderMode);
  8739. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingFillAttributes);
  8740. engine.draw(true, 0, this.fillIndicesCount, count);
  8741. engine.unbindInstanceAttributes();
  8742. }
  8743. else {
  8744. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  8745. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  8746. this.setupUniforms(effect, partIndex, pid._partData, i);
  8747. engine.draw(true, 0, this.fillIndicesCount);
  8748. }
  8749. }
  8750. }
  8751. if (this.effectBorder) {
  8752. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_BORDERPARTID.toString());
  8753. var pid = context.groupInfoPartData[partIndex];
  8754. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  8755. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  8756. }
  8757. var effect = context.useInstancing ? this.effectBorderInstanced : this.effectBorder;
  8758. engine.enableEffect(effect);
  8759. engine.bindBuffersDirectly(this.borderVB, this.borderIB, [1], 4, effect);
  8760. if (context.useInstancing) {
  8761. if (!this.instancingBorderAttributes) {
  8762. this.instancingBorderAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, effect);
  8763. }
  8764. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  8765. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  8766. canvas._addDrawCallCount(1, context.renderMode);
  8767. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingBorderAttributes);
  8768. engine.draw(true, 0, this.borderIndicesCount, count);
  8769. engine.unbindInstanceAttributes();
  8770. }
  8771. else {
  8772. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  8773. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  8774. this.setupUniforms(effect, partIndex, pid._partData, i);
  8775. engine.draw(true, 0, this.borderIndicesCount);
  8776. }
  8777. }
  8778. }
  8779. engine.setAlphaMode(curAlphaMode, true);
  8780. if (this.effectFill && this.effectBorder) {
  8781. engine.setDepthFunction(depthFunction);
  8782. }
  8783. return true;
  8784. };
  8785. Rectangle2DRenderCache.prototype.dispose = function () {
  8786. if (!_super.prototype.dispose.call(this)) {
  8787. return false;
  8788. }
  8789. if (this.fillVB) {
  8790. this._engine._releaseBuffer(this.fillVB);
  8791. this.fillVB = null;
  8792. }
  8793. if (this.fillIB) {
  8794. this._engine._releaseBuffer(this.fillIB);
  8795. this.fillIB = null;
  8796. }
  8797. this.effectFill = null;
  8798. this.effectFillInstanced = null;
  8799. this.effectBorder = null;
  8800. this.effectBorderInstanced = null;
  8801. if (this.borderVB) {
  8802. this._engine._releaseBuffer(this.borderVB);
  8803. this.borderVB = null;
  8804. }
  8805. if (this.borderIB) {
  8806. this._engine._releaseBuffer(this.borderIB);
  8807. this.borderIB = null;
  8808. }
  8809. return true;
  8810. };
  8811. return Rectangle2DRenderCache;
  8812. }(BABYLON.ModelRenderCache));
  8813. BABYLON.Rectangle2DRenderCache = Rectangle2DRenderCache;
  8814. var Rectangle2DInstanceData = (function (_super) {
  8815. __extends(Rectangle2DInstanceData, _super);
  8816. function Rectangle2DInstanceData(partId) {
  8817. return _super.call(this, partId, 1) || this;
  8818. }
  8819. Object.defineProperty(Rectangle2DInstanceData.prototype, "properties", {
  8820. get: function () {
  8821. return null;
  8822. },
  8823. set: function (value) {
  8824. },
  8825. enumerable: true,
  8826. configurable: true
  8827. });
  8828. return Rectangle2DInstanceData;
  8829. }(BABYLON.Shape2DInstanceData));
  8830. __decorate([
  8831. BABYLON.instanceData()
  8832. ], Rectangle2DInstanceData.prototype, "properties", null);
  8833. BABYLON.Rectangle2DInstanceData = Rectangle2DInstanceData;
  8834. var Rectangle2D = Rectangle2D_1 = (function (_super) {
  8835. __extends(Rectangle2D, _super);
  8836. /**
  8837. * Create an Rectangle 2D Shape primitive. May be a sharp rectangle (with sharp corners), or a rounded one.
  8838. * @param settings a combination of settings, possible ones are
  8839. * - 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)
  8840. * - children: an array of direct children
  8841. * - id a text identifier, for information purpose
  8842. * - position: the X & Y positions relative to its parent. Alternatively the x and y settings can be set. Default is [0;0]
  8843. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  8844. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  8845. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  8846. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  8847. * - zOrder: override the zOrder with the specified value
  8848. * - origin: define the normalized origin point location, default [0.5;0.5]
  8849. * - size: the size of the group. Alternatively the width and height settings can be set. Default will be [10;10].
  8850. * - roundRadius: if the rectangle has rounded corner, set their radius, default is 0 (to get a sharp edges rectangle).
  8851. * - 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)
  8852. * - 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)
  8853. * - borderThickness: the thickness of the drawn border, default is 1.
  8854. * - isVisible: true if the primitive must be visible, false for hidden. Default is true.
  8855. * - 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.
  8856. * - 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.
  8857. * - 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!
  8858. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8859. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8860. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8861. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8862. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  8863. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  8864. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  8865. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  8866. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8867. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8868. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8869. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8870. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  8871. */
  8872. function Rectangle2D(settings) {
  8873. var _this;
  8874. // Avoid checking every time if the object exists
  8875. if (settings == null) {
  8876. settings = {};
  8877. }
  8878. _this = _super.call(this, settings) || this;
  8879. if (settings.size != null) {
  8880. _this.size = settings.size;
  8881. }
  8882. else if (settings.width || settings.height) {
  8883. var size = new BABYLON.Size(settings.width, settings.height);
  8884. _this.size = size;
  8885. }
  8886. //let size = settings.size || (new Size((settings.width === null) ? null : (settings.width || 10), (settings.height === null) ? null : (settings.height || 10)));
  8887. var roundRadius = (settings.roundRadius == null) ? 0 : settings.roundRadius;
  8888. var borderThickness = (settings.borderThickness == null) ? 1 : settings.borderThickness;
  8889. //this.size = size;
  8890. _this.roundRadius = roundRadius;
  8891. _this.borderThickness = borderThickness;
  8892. return _this;
  8893. }
  8894. Object.defineProperty(Rectangle2D.prototype, "actualSize", {
  8895. get: function () {
  8896. if (this._actualSize) {
  8897. return this._actualSize;
  8898. }
  8899. return this.size;
  8900. },
  8901. set: function (value) {
  8902. this._actualSize = value;
  8903. },
  8904. enumerable: true,
  8905. configurable: true
  8906. });
  8907. Object.defineProperty(Rectangle2D.prototype, "notRounded", {
  8908. get: function () {
  8909. return this._notRounded;
  8910. },
  8911. set: function (value) {
  8912. this._notRounded = value;
  8913. },
  8914. enumerable: true,
  8915. configurable: true
  8916. });
  8917. Object.defineProperty(Rectangle2D.prototype, "roundRadius", {
  8918. get: function () {
  8919. return this._roundRadius;
  8920. },
  8921. set: function (value) {
  8922. this._roundRadius = value;
  8923. this.notRounded = value === 0;
  8924. this._positioningDirty();
  8925. },
  8926. enumerable: true,
  8927. configurable: true
  8928. });
  8929. Rectangle2D.prototype.levelIntersect = function (intersectInfo) {
  8930. // If we got there it mean the boundingInfo intersection succeed, if the rectangle has not roundRadius, it means it succeed!
  8931. if (this.notRounded) {
  8932. return true;
  8933. }
  8934. // 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.
  8935. // 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)
  8936. // 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.
  8937. // First let remove the origin out the equation, to have the rectangle with an origin at bottom/left
  8938. var size = this.size;
  8939. Rectangle2D_1._i0.x = intersectInfo._localPickPosition.x;
  8940. Rectangle2D_1._i0.y = intersectInfo._localPickPosition.y;
  8941. var rr = this.roundRadius;
  8942. var rrs = rr * rr;
  8943. // Check if the point is in the bottom/left quarter area
  8944. Rectangle2D_1._i1.x = rr;
  8945. Rectangle2D_1._i1.y = rr;
  8946. if (Rectangle2D_1._i0.x <= Rectangle2D_1._i1.x && Rectangle2D_1._i0.y <= Rectangle2D_1._i1.y) {
  8947. // Compute the intersection point in the quarter local space
  8948. Rectangle2D_1._i2.x = Rectangle2D_1._i0.x - Rectangle2D_1._i1.x;
  8949. Rectangle2D_1._i2.y = Rectangle2D_1._i0.y - Rectangle2D_1._i1.y;
  8950. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  8951. return Rectangle2D_1._i2.lengthSquared() <= rrs;
  8952. }
  8953. // Check if the point is in the top/left quarter area
  8954. Rectangle2D_1._i1.x = rr;
  8955. Rectangle2D_1._i1.y = size.height - rr;
  8956. if (Rectangle2D_1._i0.x <= Rectangle2D_1._i1.x && Rectangle2D_1._i0.y >= Rectangle2D_1._i1.y) {
  8957. // Compute the intersection point in the quarter local space
  8958. Rectangle2D_1._i2.x = Rectangle2D_1._i0.x - Rectangle2D_1._i1.x;
  8959. Rectangle2D_1._i2.y = Rectangle2D_1._i0.y - Rectangle2D_1._i1.y;
  8960. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  8961. return Rectangle2D_1._i2.lengthSquared() <= rrs;
  8962. }
  8963. // Check if the point is in the top/right quarter area
  8964. Rectangle2D_1._i1.x = size.width - rr;
  8965. Rectangle2D_1._i1.y = size.height - rr;
  8966. if (Rectangle2D_1._i0.x >= Rectangle2D_1._i1.x && Rectangle2D_1._i0.y >= Rectangle2D_1._i1.y) {
  8967. // Compute the intersection point in the quarter local space
  8968. Rectangle2D_1._i2.x = Rectangle2D_1._i0.x - Rectangle2D_1._i1.x;
  8969. Rectangle2D_1._i2.y = Rectangle2D_1._i0.y - Rectangle2D_1._i1.y;
  8970. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  8971. return Rectangle2D_1._i2.lengthSquared() <= rrs;
  8972. }
  8973. // Check if the point is in the bottom/right quarter area
  8974. Rectangle2D_1._i1.x = size.width - rr;
  8975. Rectangle2D_1._i1.y = rr;
  8976. if (Rectangle2D_1._i0.x >= Rectangle2D_1._i1.x && Rectangle2D_1._i0.y <= Rectangle2D_1._i1.y) {
  8977. // Compute the intersection point in the quarter local space
  8978. Rectangle2D_1._i2.x = Rectangle2D_1._i0.x - Rectangle2D_1._i1.x;
  8979. Rectangle2D_1._i2.y = Rectangle2D_1._i0.y - Rectangle2D_1._i1.y;
  8980. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  8981. return Rectangle2D_1._i2.lengthSquared() <= rrs;
  8982. }
  8983. // At any other locations the point is guarantied to be inside
  8984. return true;
  8985. };
  8986. Rectangle2D.prototype.updateLevelBoundingInfo = function () {
  8987. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.actualSize, this._levelBoundingInfo);
  8988. };
  8989. Rectangle2D.prototype.createModelRenderCache = function (modelKey) {
  8990. var renderCache = new Rectangle2DRenderCache(this.owner.engine, modelKey);
  8991. return renderCache;
  8992. };
  8993. Rectangle2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  8994. var renderCache = modelRenderCache;
  8995. var engine = this.owner.engine;
  8996. // Need to create WebGL resources for fill part?
  8997. if (this.fill) {
  8998. var vbSize = ((this.notRounded ? 1 : Rectangle2D_1.roundSubdivisions) * 4) + 1;
  8999. var vb = new Float32Array(vbSize);
  9000. for (var i = 0; i < vbSize; i++) {
  9001. vb[i] = i;
  9002. }
  9003. renderCache.fillVB = engine.createVertexBuffer(vb);
  9004. var triCount = vbSize - 1;
  9005. var ib = new Float32Array(triCount * 3);
  9006. for (var i = 0; i < triCount; i++) {
  9007. ib[i * 3 + 0] = 0;
  9008. ib[i * 3 + 2] = i + 1;
  9009. ib[i * 3 + 1] = i + 2;
  9010. }
  9011. ib[triCount * 3 - 2] = 1;
  9012. renderCache.fillIB = engine.createIndexBuffer(ib);
  9013. renderCache.fillIndicesCount = triCount * 3;
  9014. // 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
  9015. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, true);
  9016. if (ei) {
  9017. renderCache.effectFillInstanced = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9018. }
  9019. // Get the non instanced version
  9020. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, false);
  9021. renderCache.effectFill = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9022. }
  9023. // Need to create WebGL resource for border part?
  9024. if (this.border) {
  9025. var vbSize = (this.notRounded ? 1 : Rectangle2D_1.roundSubdivisions) * 4 * 2;
  9026. var vb = new Float32Array(vbSize);
  9027. for (var i = 0; i < vbSize; i++) {
  9028. vb[i] = i;
  9029. }
  9030. renderCache.borderVB = engine.createVertexBuffer(vb);
  9031. var triCount = vbSize;
  9032. var rs = triCount / 2;
  9033. var ib = new Float32Array(triCount * 3);
  9034. for (var i = 0; i < rs; i++) {
  9035. var r0 = i;
  9036. var r1 = (i + 1) % rs;
  9037. ib[i * 6 + 0] = rs + r1;
  9038. ib[i * 6 + 1] = rs + r0;
  9039. ib[i * 6 + 2] = r0;
  9040. ib[i * 6 + 3] = r1;
  9041. ib[i * 6 + 4] = rs + r1;
  9042. ib[i * 6 + 5] = r0;
  9043. }
  9044. renderCache.borderIB = engine.createIndexBuffer(ib);
  9045. renderCache.borderIndicesCount = triCount * 3;
  9046. // 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
  9047. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, true);
  9048. if (ei) {
  9049. renderCache.effectBorderInstanced = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9050. }
  9051. // Get the non instanced version
  9052. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, false);
  9053. renderCache.effectBorder = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9054. }
  9055. return renderCache;
  9056. };
  9057. // 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
  9058. Rectangle2D.prototype._getInitialContentAreaToRef = function (primSize, initialContentPosition, initialContentArea) {
  9059. // Fall back to default implementation if there's no round Radius
  9060. if (this._notRounded) {
  9061. _super.prototype._getInitialContentAreaToRef.call(this, primSize, initialContentPosition, initialContentArea);
  9062. }
  9063. else {
  9064. var rr = Math.round((this.roundRadius - (this.roundRadius / Math.sqrt(2))) * 1.3);
  9065. initialContentPosition.x = initialContentPosition.y = rr;
  9066. initialContentArea.width = Math.max(0, primSize.width - (rr * 2));
  9067. initialContentArea.height = Math.max(0, primSize.height - (rr * 2));
  9068. initialContentPosition.z = primSize.width - (initialContentPosition.x + initialContentArea.width);
  9069. initialContentPosition.w = primSize.height - (initialContentPosition.y + initialContentArea.height);
  9070. }
  9071. };
  9072. Rectangle2D.prototype._getActualSizeFromContentToRef = function (primSize, newPrimSize) {
  9073. // Fall back to default implementation if there's no round Radius
  9074. if (this._notRounded) {
  9075. _super.prototype._getActualSizeFromContentToRef.call(this, primSize, newPrimSize);
  9076. }
  9077. else {
  9078. var rr = Math.round((this.roundRadius - (this.roundRadius / Math.sqrt(2))) * 1.3);
  9079. newPrimSize.copyFrom(primSize);
  9080. newPrimSize.width += rr * 2;
  9081. newPrimSize.height += rr * 2;
  9082. }
  9083. };
  9084. Rectangle2D.prototype.createInstanceDataParts = function () {
  9085. var res = new Array();
  9086. if (this.border) {
  9087. res.push(new Rectangle2DInstanceData(BABYLON.Shape2D.SHAPE2D_BORDERPARTID));
  9088. }
  9089. if (this.fill) {
  9090. res.push(new Rectangle2DInstanceData(BABYLON.Shape2D.SHAPE2D_FILLPARTID));
  9091. }
  9092. return res;
  9093. };
  9094. Rectangle2D.prototype.refreshInstanceDataPart = function (part) {
  9095. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  9096. return false;
  9097. }
  9098. if (part.id === BABYLON.Shape2D.SHAPE2D_BORDERPARTID) {
  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. else if (part.id === BABYLON.Shape2D.SHAPE2D_FILLPARTID) {
  9105. var d = part;
  9106. var size = this.actualSize;
  9107. var s = this.actualScale;
  9108. d.properties = new BABYLON.Vector3(size.width * s.x, size.height * s.y, this.roundRadius || 0);
  9109. }
  9110. return true;
  9111. };
  9112. return Rectangle2D;
  9113. }(BABYLON.Shape2D));
  9114. Rectangle2D._i0 = BABYLON.Vector2.Zero();
  9115. Rectangle2D._i1 = BABYLON.Vector2.Zero();
  9116. Rectangle2D._i2 = BABYLON.Vector2.Zero();
  9117. Rectangle2D.roundSubdivisions = 16;
  9118. __decorate([
  9119. BABYLON.instanceLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 1, function (pi) { return Rectangle2D_1.actualSizeProperty = pi; }, false, true)
  9120. ], Rectangle2D.prototype, "actualSize", null);
  9121. __decorate([
  9122. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 2, function (pi) { return Rectangle2D_1.notRoundedProperty = pi; })
  9123. ], Rectangle2D.prototype, "notRounded", null);
  9124. __decorate([
  9125. BABYLON.instanceLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 3, function (pi) { return Rectangle2D_1.roundRadiusProperty = pi; })
  9126. ], Rectangle2D.prototype, "roundRadius", null);
  9127. Rectangle2D = Rectangle2D_1 = __decorate([
  9128. BABYLON.className("Rectangle2D", "BABYLON")
  9129. ], Rectangle2D);
  9130. BABYLON.Rectangle2D = Rectangle2D;
  9131. var Rectangle2D_1;
  9132. })(BABYLON || (BABYLON = {}));
  9133. //# sourceMappingURL=babylon.rectangle2d.js.map
  9134. var __extends = (this && this.__extends) || function (d, b) {
  9135. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  9136. function __() { this.constructor = d; }
  9137. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9138. };
  9139. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  9140. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  9141. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  9142. 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;
  9143. return c > 3 && r && Object.defineProperty(target, key, r), r;
  9144. };
  9145. var BABYLON;
  9146. (function (BABYLON) {
  9147. var Ellipse2DRenderCache = (function (_super) {
  9148. __extends(Ellipse2DRenderCache, _super);
  9149. function Ellipse2DRenderCache(engine, modelKey) {
  9150. var _this = _super.call(this, engine, modelKey) || this;
  9151. _this.effectsReady = false;
  9152. _this.fillVB = null;
  9153. _this.fillIB = null;
  9154. _this.fillIndicesCount = 0;
  9155. _this.instancingFillAttributes = null;
  9156. _this.effectFillInstanced = null;
  9157. _this.effectFill = null;
  9158. _this.borderVB = null;
  9159. _this.borderIB = null;
  9160. _this.borderIndicesCount = 0;
  9161. _this.instancingBorderAttributes = null;
  9162. _this.effectBorderInstanced = null;
  9163. _this.effectBorder = null;
  9164. return _this;
  9165. }
  9166. Ellipse2DRenderCache.prototype.render = function (instanceInfo, context) {
  9167. // Do nothing if the shader is still loading/preparing
  9168. if (!this.effectsReady) {
  9169. if ((this.effectFill && (!this.effectFill.isReady() || (this.effectFillInstanced && !this.effectFillInstanced.isReady()))) ||
  9170. (this.effectBorder && (!this.effectBorder.isReady() || (this.effectBorderInstanced && !this.effectBorderInstanced.isReady())))) {
  9171. return false;
  9172. }
  9173. this.effectsReady = true;
  9174. }
  9175. var canvas = instanceInfo.owner.owner;
  9176. var engine = canvas.engine;
  9177. var depthFunction = 0;
  9178. if (this.effectFill && this.effectBorder) {
  9179. depthFunction = engine.getDepthFunction();
  9180. engine.setDepthFunctionToLessOrEqual();
  9181. }
  9182. var curAlphaMode = engine.getAlphaMode();
  9183. if (this.effectFill) {
  9184. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_FILLPARTID.toString());
  9185. var pid = context.groupInfoPartData[partIndex];
  9186. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  9187. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  9188. }
  9189. var effect = context.useInstancing ? this.effectFillInstanced : this.effectFill;
  9190. engine.enableEffect(effect);
  9191. engine.bindBuffersDirectly(this.fillVB, this.fillIB, [1], 4, effect);
  9192. if (context.useInstancing) {
  9193. if (!this.instancingFillAttributes) {
  9194. this.instancingFillAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_FILLPARTID, effect);
  9195. }
  9196. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  9197. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  9198. canvas._addDrawCallCount(1, context.renderMode);
  9199. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingFillAttributes);
  9200. engine.draw(true, 0, this.fillIndicesCount, count);
  9201. engine.unbindInstanceAttributes();
  9202. }
  9203. else {
  9204. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  9205. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  9206. this.setupUniforms(effect, partIndex, pid._partData, i);
  9207. engine.draw(true, 0, this.fillIndicesCount);
  9208. }
  9209. }
  9210. }
  9211. if (this.effectBorder) {
  9212. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_BORDERPARTID.toString());
  9213. var pid = context.groupInfoPartData[partIndex];
  9214. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  9215. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  9216. }
  9217. var effect = context.useInstancing ? this.effectBorderInstanced : this.effectBorder;
  9218. engine.enableEffect(effect);
  9219. engine.bindBuffersDirectly(this.borderVB, this.borderIB, [1], 4, effect);
  9220. if (context.useInstancing) {
  9221. if (!this.instancingBorderAttributes) {
  9222. this.instancingBorderAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, effect);
  9223. }
  9224. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  9225. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  9226. canvas._addDrawCallCount(1, context.renderMode);
  9227. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingBorderAttributes);
  9228. engine.draw(true, 0, this.borderIndicesCount, count);
  9229. engine.unbindInstanceAttributes();
  9230. }
  9231. else {
  9232. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  9233. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  9234. this.setupUniforms(effect, partIndex, pid._partData, i);
  9235. engine.draw(true, 0, this.borderIndicesCount);
  9236. }
  9237. }
  9238. }
  9239. engine.setAlphaMode(curAlphaMode, true);
  9240. if (this.effectFill && this.effectBorder) {
  9241. engine.setDepthFunction(depthFunction);
  9242. }
  9243. return true;
  9244. };
  9245. Ellipse2DRenderCache.prototype.dispose = function () {
  9246. if (!_super.prototype.dispose.call(this)) {
  9247. return false;
  9248. }
  9249. if (this.fillVB) {
  9250. this._engine._releaseBuffer(this.fillVB);
  9251. this.fillVB = null;
  9252. }
  9253. if (this.fillIB) {
  9254. this._engine._releaseBuffer(this.fillIB);
  9255. this.fillIB = null;
  9256. }
  9257. this.effectFill = null;
  9258. this.effectFillInstanced = null;
  9259. this.effectBorder = null;
  9260. this.effectBorderInstanced = null;
  9261. if (this.borderVB) {
  9262. this._engine._releaseBuffer(this.borderVB);
  9263. this.borderVB = null;
  9264. }
  9265. if (this.borderIB) {
  9266. this._engine._releaseBuffer(this.borderIB);
  9267. this.borderIB = null;
  9268. }
  9269. return true;
  9270. };
  9271. return Ellipse2DRenderCache;
  9272. }(BABYLON.ModelRenderCache));
  9273. BABYLON.Ellipse2DRenderCache = Ellipse2DRenderCache;
  9274. var Ellipse2DInstanceData = (function (_super) {
  9275. __extends(Ellipse2DInstanceData, _super);
  9276. function Ellipse2DInstanceData(partId) {
  9277. return _super.call(this, partId, 1) || this;
  9278. }
  9279. Object.defineProperty(Ellipse2DInstanceData.prototype, "properties", {
  9280. get: function () {
  9281. return null;
  9282. },
  9283. set: function (value) {
  9284. },
  9285. enumerable: true,
  9286. configurable: true
  9287. });
  9288. return Ellipse2DInstanceData;
  9289. }(BABYLON.Shape2DInstanceData));
  9290. __decorate([
  9291. BABYLON.instanceData()
  9292. ], Ellipse2DInstanceData.prototype, "properties", null);
  9293. BABYLON.Ellipse2DInstanceData = Ellipse2DInstanceData;
  9294. var Ellipse2D = Ellipse2D_1 = (function (_super) {
  9295. __extends(Ellipse2D, _super);
  9296. /**
  9297. * Create an Ellipse 2D Shape primitive
  9298. * @param settings a combination of settings, possible ones are
  9299. * - 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)
  9300. * - children: an array of direct children
  9301. * - id: a text identifier, for information purpose
  9302. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  9303. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  9304. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  9305. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  9306. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  9307. * - zOrder: override the zOrder with the specified value
  9308. * - origin: define the normalized origin point location, default [0.5;0.5]
  9309. * - size: the size of the group. Alternatively the width and height properties can be set. Default will be [10;10].
  9310. * - subdivision: the number of subdivision to create the ellipse perimeter, default is 64.
  9311. * - 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)
  9312. * - 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)
  9313. * - borderThickness: the thickness of the drawn border, default is 1.
  9314. * - isVisible: true if the group must be visible, false for hidden. Default is true.
  9315. * - 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.
  9316. * - 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.
  9317. * - 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!
  9318. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9319. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9320. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9321. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9322. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  9323. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  9324. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  9325. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  9326. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9327. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9328. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9329. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9330. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  9331. */
  9332. function Ellipse2D(settings) {
  9333. var _this;
  9334. // Avoid checking every time if the object exists
  9335. if (settings == null) {
  9336. settings = {};
  9337. }
  9338. _this = _super.call(this, settings) || this;
  9339. if (settings.size != null) {
  9340. _this.size = settings.size;
  9341. }
  9342. else if (settings.width || settings.height) {
  9343. var size = new BABYLON.Size(settings.width, settings.height);
  9344. _this.size = size;
  9345. }
  9346. var sub = (settings.subdivisions == null) ? 64 : settings.subdivisions;
  9347. _this.subdivisions = sub;
  9348. return _this;
  9349. }
  9350. Object.defineProperty(Ellipse2D.prototype, "actualSize", {
  9351. get: function () {
  9352. if (this._actualSize) {
  9353. return this._actualSize;
  9354. }
  9355. return this.size;
  9356. },
  9357. set: function (value) {
  9358. this._actualSize = value;
  9359. },
  9360. enumerable: true,
  9361. configurable: true
  9362. });
  9363. Object.defineProperty(Ellipse2D.prototype, "subdivisions", {
  9364. get: function () {
  9365. return this._subdivisions;
  9366. },
  9367. set: function (value) {
  9368. this._subdivisions = value;
  9369. },
  9370. enumerable: true,
  9371. configurable: true
  9372. });
  9373. Ellipse2D.prototype.levelIntersect = function (intersectInfo) {
  9374. var w = this.size.width / 2;
  9375. var h = this.size.height / 2;
  9376. var x = intersectInfo._localPickPosition.x - w;
  9377. var y = intersectInfo._localPickPosition.y - h;
  9378. return ((x * x) / (w * w) + (y * y) / (h * h)) <= 1;
  9379. };
  9380. Ellipse2D.prototype.updateLevelBoundingInfo = function () {
  9381. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.actualSize, this._levelBoundingInfo);
  9382. };
  9383. Ellipse2D.prototype.createModelRenderCache = function (modelKey) {
  9384. var renderCache = new Ellipse2DRenderCache(this.owner.engine, modelKey);
  9385. return renderCache;
  9386. };
  9387. Ellipse2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  9388. var renderCache = modelRenderCache;
  9389. var engine = this.owner.engine;
  9390. // Need to create WebGL resources for fill part?
  9391. if (this.fill) {
  9392. var vbSize = this.subdivisions + 1;
  9393. var vb = new Float32Array(vbSize);
  9394. for (var i = 0; i < vbSize; i++) {
  9395. vb[i] = i;
  9396. }
  9397. renderCache.fillVB = engine.createVertexBuffer(vb);
  9398. var triCount = vbSize - 1;
  9399. var ib = new Float32Array(triCount * 3);
  9400. for (var i = 0; i < triCount; i++) {
  9401. ib[i * 3 + 0] = 0;
  9402. ib[i * 3 + 2] = i + 1;
  9403. ib[i * 3 + 1] = i + 2;
  9404. }
  9405. ib[triCount * 3 - 2] = 1;
  9406. renderCache.fillIB = engine.createIndexBuffer(ib);
  9407. renderCache.fillIndicesCount = triCount * 3;
  9408. // 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
  9409. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, true);
  9410. if (ei) {
  9411. renderCache.effectFillInstanced = engine.createEffect({ vertex: "ellipse2d", fragment: "ellipse2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  9412. }
  9413. // Get the non instanced version
  9414. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, false);
  9415. renderCache.effectFill = engine.createEffect({ vertex: "ellipse2d", fragment: "ellipse2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  9416. }
  9417. // Need to create WebGL resource for border part?
  9418. if (this.border) {
  9419. var vbSize = this.subdivisions * 2;
  9420. var vb = new Float32Array(vbSize);
  9421. for (var i = 0; i < vbSize; i++) {
  9422. vb[i] = i;
  9423. }
  9424. renderCache.borderVB = engine.createVertexBuffer(vb);
  9425. var triCount = vbSize;
  9426. var rs = triCount / 2;
  9427. var ib = new Float32Array(triCount * 3);
  9428. for (var i = 0; i < rs; i++) {
  9429. var r0 = i;
  9430. var r1 = (i + 1) % rs;
  9431. ib[i * 6 + 0] = rs + r1;
  9432. ib[i * 6 + 1] = rs + r0;
  9433. ib[i * 6 + 2] = r0;
  9434. ib[i * 6 + 3] = r1;
  9435. ib[i * 6 + 4] = rs + r1;
  9436. ib[i * 6 + 5] = r0;
  9437. }
  9438. renderCache.borderIB = engine.createIndexBuffer(ib);
  9439. renderCache.borderIndicesCount = (triCount * 3);
  9440. // 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
  9441. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, true);
  9442. if (ei) {
  9443. renderCache.effectBorderInstanced = engine.createEffect("ellipse2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9444. }
  9445. // Get the non instanced version
  9446. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, false);
  9447. renderCache.effectBorder = engine.createEffect("ellipse2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9448. }
  9449. return renderCache;
  9450. };
  9451. Ellipse2D.prototype.createInstanceDataParts = function () {
  9452. var res = new Array();
  9453. if (this.border) {
  9454. res.push(new Ellipse2DInstanceData(BABYLON.Shape2D.SHAPE2D_BORDERPARTID));
  9455. }
  9456. if (this.fill) {
  9457. res.push(new Ellipse2DInstanceData(BABYLON.Shape2D.SHAPE2D_FILLPARTID));
  9458. }
  9459. return res;
  9460. };
  9461. Ellipse2D.prototype.refreshInstanceDataPart = function (part) {
  9462. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  9463. return false;
  9464. }
  9465. if (part.id === BABYLON.Shape2D.SHAPE2D_BORDERPARTID) {
  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. else if (part.id === BABYLON.Shape2D.SHAPE2D_FILLPARTID) {
  9472. var d = part;
  9473. var size = this.actualSize;
  9474. var s = this.actualScale;
  9475. d.properties = new BABYLON.Vector3(size.width * s.x, size.height * s.y, this.subdivisions);
  9476. }
  9477. return true;
  9478. };
  9479. return Ellipse2D;
  9480. }(BABYLON.Shape2D));
  9481. __decorate([
  9482. BABYLON.instanceLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 1, function (pi) { return Ellipse2D_1.acutalSizeProperty = pi; }, false, true)
  9483. ], Ellipse2D.prototype, "actualSize", null);
  9484. __decorate([
  9485. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 2, function (pi) { return Ellipse2D_1.subdivisionsProperty = pi; })
  9486. ], Ellipse2D.prototype, "subdivisions", null);
  9487. Ellipse2D = Ellipse2D_1 = __decorate([
  9488. BABYLON.className("Ellipse2D", "BABYLON")
  9489. ], Ellipse2D);
  9490. BABYLON.Ellipse2D = Ellipse2D;
  9491. var Ellipse2D_1;
  9492. })(BABYLON || (BABYLON = {}));
  9493. //# sourceMappingURL=babylon.ellipse2d.js.map
  9494. var __extends = (this && this.__extends) || function (d, b) {
  9495. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  9496. function __() { this.constructor = d; }
  9497. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9498. };
  9499. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  9500. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  9501. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  9502. 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;
  9503. return c > 3 && r && Object.defineProperty(target, key, r), r;
  9504. };
  9505. var BABYLON;
  9506. (function (BABYLON) {
  9507. var Sprite2DRenderCache = (function (_super) {
  9508. __extends(Sprite2DRenderCache, _super);
  9509. function Sprite2DRenderCache() {
  9510. var _this = _super.apply(this, arguments) || this;
  9511. _this.effectsReady = false;
  9512. _this.vb = null;
  9513. _this.ib = null;
  9514. _this.instancingAttributes = null;
  9515. _this.texture = null;
  9516. _this.effect = null;
  9517. _this.effectInstanced = null;
  9518. return _this;
  9519. }
  9520. Sprite2DRenderCache.prototype.render = function (instanceInfo, context) {
  9521. // Do nothing if the shader is still loading/preparing
  9522. if (!this.effectsReady) {
  9523. if ((this.effect && (!this.effect.isReady() || (this.effectInstanced && !this.effectInstanced.isReady())))) {
  9524. return false;
  9525. }
  9526. this.effectsReady = true;
  9527. }
  9528. // Compute the offset locations of the attributes in the vertex shader that will be mapped to the instance buffer data
  9529. var canvas = instanceInfo.owner.owner;
  9530. var engine = canvas.engine;
  9531. var cur = engine.getAlphaMode();
  9532. var effect = context.useInstancing ? this.effectInstanced : this.effect;
  9533. engine.enableEffect(effect);
  9534. effect.setTexture("diffuseSampler", this.texture);
  9535. engine.bindBuffersDirectly(this.vb, this.ib, [1], 4, effect);
  9536. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  9537. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  9538. }
  9539. effect.setBool("alphaTest", context.renderMode === BABYLON.Render2DContext.RenderModeAlphaTest);
  9540. var pid = context.groupInfoPartData[0];
  9541. if (context.useInstancing) {
  9542. if (!this.instancingAttributes) {
  9543. this.instancingAttributes = this.loadInstancingAttributes(Sprite2D.SPRITE2D_MAINPARTID, effect);
  9544. }
  9545. var glBuffer = context.instancedBuffers ? context.instancedBuffers[0] : pid._partBuffer;
  9546. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  9547. canvas._addDrawCallCount(1, context.renderMode);
  9548. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingAttributes);
  9549. engine.draw(true, 0, 6, count);
  9550. engine.unbindInstanceAttributes();
  9551. }
  9552. else {
  9553. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  9554. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  9555. this.setupUniforms(effect, 0, pid._partData, i);
  9556. engine.draw(true, 0, 6);
  9557. }
  9558. }
  9559. engine.setAlphaMode(cur, true);
  9560. return true;
  9561. };
  9562. Sprite2DRenderCache.prototype.dispose = function () {
  9563. if (!_super.prototype.dispose.call(this)) {
  9564. return false;
  9565. }
  9566. if (this.vb) {
  9567. this._engine._releaseBuffer(this.vb);
  9568. this.vb = null;
  9569. }
  9570. if (this.ib) {
  9571. this._engine._releaseBuffer(this.ib);
  9572. this.ib = null;
  9573. }
  9574. //if (this.texture) {
  9575. // this.texture.dispose();
  9576. // this.texture = null;
  9577. //}
  9578. this.effect = null;
  9579. this.effectInstanced = null;
  9580. return true;
  9581. };
  9582. return Sprite2DRenderCache;
  9583. }(BABYLON.ModelRenderCache));
  9584. BABYLON.Sprite2DRenderCache = Sprite2DRenderCache;
  9585. var Sprite2DInstanceData = (function (_super) {
  9586. __extends(Sprite2DInstanceData, _super);
  9587. function Sprite2DInstanceData(partId) {
  9588. return _super.call(this, partId, 1) || this;
  9589. }
  9590. Object.defineProperty(Sprite2DInstanceData.prototype, "topLeftUV", {
  9591. get: function () {
  9592. return null;
  9593. },
  9594. set: function (value) {
  9595. },
  9596. enumerable: true,
  9597. configurable: true
  9598. });
  9599. Object.defineProperty(Sprite2DInstanceData.prototype, "sizeUV", {
  9600. get: function () {
  9601. return null;
  9602. },
  9603. set: function (value) {
  9604. },
  9605. enumerable: true,
  9606. configurable: true
  9607. });
  9608. Object.defineProperty(Sprite2DInstanceData.prototype, "scaleFactor", {
  9609. get: function () {
  9610. return null;
  9611. },
  9612. set: function (value) {
  9613. },
  9614. enumerable: true,
  9615. configurable: true
  9616. });
  9617. Object.defineProperty(Sprite2DInstanceData.prototype, "textureSize", {
  9618. get: function () {
  9619. return null;
  9620. },
  9621. set: function (value) {
  9622. },
  9623. enumerable: true,
  9624. configurable: true
  9625. });
  9626. Object.defineProperty(Sprite2DInstanceData.prototype, "properties", {
  9627. // 3 floats being:
  9628. // - x: frame number to display
  9629. // - y: invertY setting
  9630. // - z: alignToPixel setting
  9631. get: function () {
  9632. return null;
  9633. },
  9634. set: function (value) {
  9635. },
  9636. enumerable: true,
  9637. configurable: true
  9638. });
  9639. return Sprite2DInstanceData;
  9640. }(BABYLON.InstanceDataBase));
  9641. __decorate([
  9642. BABYLON.instanceData()
  9643. ], Sprite2DInstanceData.prototype, "topLeftUV", null);
  9644. __decorate([
  9645. BABYLON.instanceData()
  9646. ], Sprite2DInstanceData.prototype, "sizeUV", null);
  9647. __decorate([
  9648. BABYLON.instanceData()
  9649. ], Sprite2DInstanceData.prototype, "scaleFactor", null);
  9650. __decorate([
  9651. BABYLON.instanceData()
  9652. ], Sprite2DInstanceData.prototype, "textureSize", null);
  9653. __decorate([
  9654. BABYLON.instanceData()
  9655. ], Sprite2DInstanceData.prototype, "properties", null);
  9656. BABYLON.Sprite2DInstanceData = Sprite2DInstanceData;
  9657. var Sprite2D = Sprite2D_1 = (function (_super) {
  9658. __extends(Sprite2D, _super);
  9659. /**
  9660. * Create an 2D Sprite primitive
  9661. * @param texture the texture that stores the sprite to render
  9662. * @param settings a combination of settings, possible ones are
  9663. * - 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)
  9664. * - children: an array of direct children
  9665. * - id a text identifier, for information purpose
  9666. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  9667. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  9668. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  9669. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  9670. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  9671. * - zOrder: override the zOrder with the specified value
  9672. * - origin: define the normalized origin point location, default [0.5;0.5]
  9673. * - spriteSize: the size of the sprite (in pixels), if null the size of the given texture will be used, default is null.
  9674. * - spriteLocation: the location (in pixels) in the texture of the top/left corner of the Sprite to display, default is null (0,0)
  9675. * - 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.
  9676. * - invertY: if true the texture Y will be inverted, default is false.
  9677. * - 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.
  9678. * - isVisible: true if the sprite must be visible, false for hidden. Default is true.
  9679. * - 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.
  9680. * - 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.
  9681. * - 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!
  9682. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9683. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9684. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9685. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9686. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  9687. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  9688. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  9689. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  9690. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9691. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9692. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9693. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9694. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  9695. */
  9696. function Sprite2D(texture, settings) {
  9697. var _this;
  9698. if (!settings) {
  9699. settings = {};
  9700. }
  9701. _this = _super.call(this, settings) || this;
  9702. _this.texture = texture;
  9703. _this.texture.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
  9704. _this.texture.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
  9705. _this.size = (settings.spriteSize != null) ? settings.spriteSize.clone() : null;
  9706. _this.spriteLocation = (settings.spriteLocation != null) ? settings.spriteLocation.clone() : new BABYLON.Vector2(0, 0);
  9707. _this.spriteScaleFactor = (settings.spriteScaleFactor != null) ? settings.spriteScaleFactor : new BABYLON.Vector2(1, 1);
  9708. _this.spriteFrame = 0;
  9709. _this.invertY = (settings.invertY == null) ? false : settings.invertY;
  9710. _this.alignToPixel = (settings.alignToPixel == null) ? true : settings.alignToPixel;
  9711. _this.useAlphaFromTexture = true;
  9712. // 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.
  9713. // The fucking delayed texture sprite bug is fixed!
  9714. if (settings.spriteSize == null) {
  9715. _this.size = new BABYLON.Size(10, 10);
  9716. }
  9717. if (settings.spriteSize == null || !texture.isReady()) {
  9718. if (texture.isReady()) {
  9719. var s = texture.getBaseSize();
  9720. _this.size = new BABYLON.Size(s.width, s.height);
  9721. }
  9722. else {
  9723. texture.onLoadObservable.add(function () {
  9724. if (settings.spriteSize == null) {
  9725. var s = texture.getBaseSize();
  9726. _this.size = new BABYLON.Size(s.width, s.height);
  9727. }
  9728. _this._positioningDirty();
  9729. _this._setLayoutDirty();
  9730. _this._instanceDirtyFlags |= BABYLON.Prim2DBase.originProperty.flagId | Sprite2D_1.textureProperty.flagId; // To make sure the sprite is issued again for render
  9731. });
  9732. }
  9733. }
  9734. return _this;
  9735. }
  9736. Object.defineProperty(Sprite2D.prototype, "texture", {
  9737. get: function () {
  9738. return this._texture;
  9739. },
  9740. set: function (value) {
  9741. this._texture = value;
  9742. this._oldTextureHasAlpha = this._texture && this.texture.hasAlpha;
  9743. },
  9744. enumerable: true,
  9745. configurable: true
  9746. });
  9747. Object.defineProperty(Sprite2D.prototype, "useAlphaFromTexture", {
  9748. get: function () {
  9749. return this._useAlphaFromTexture;
  9750. },
  9751. set: function (value) {
  9752. if (this._useAlphaFromTexture === value) {
  9753. return;
  9754. }
  9755. this._useAlphaFromTexture = value;
  9756. this._updateRenderMode();
  9757. },
  9758. enumerable: true,
  9759. configurable: true
  9760. });
  9761. Object.defineProperty(Sprite2D.prototype, "actualSize", {
  9762. get: function () {
  9763. if (this._actualSize) {
  9764. return this._actualSize;
  9765. }
  9766. return this.size;
  9767. },
  9768. set: function (value) {
  9769. this._actualSize = value;
  9770. },
  9771. enumerable: true,
  9772. configurable: true
  9773. });
  9774. Object.defineProperty(Sprite2D.prototype, "spriteLocation", {
  9775. get: function () {
  9776. return this._location;
  9777. },
  9778. set: function (value) {
  9779. this._location = value;
  9780. },
  9781. enumerable: true,
  9782. configurable: true
  9783. });
  9784. Object.defineProperty(Sprite2D.prototype, "spriteFrame", {
  9785. get: function () {
  9786. return this._spriteFrame;
  9787. },
  9788. set: function (value) {
  9789. this._spriteFrame = value;
  9790. },
  9791. enumerable: true,
  9792. configurable: true
  9793. });
  9794. Object.defineProperty(Sprite2D.prototype, "invertY", {
  9795. get: function () {
  9796. return this._invertY;
  9797. },
  9798. set: function (value) {
  9799. this._invertY = value;
  9800. },
  9801. enumerable: true,
  9802. configurable: true
  9803. });
  9804. Object.defineProperty(Sprite2D.prototype, "spriteScaleFactor", {
  9805. get: function () {
  9806. return this._spriteScaleFactor;
  9807. },
  9808. set: function (value) {
  9809. this._spriteScaleFactor = value;
  9810. },
  9811. enumerable: true,
  9812. configurable: true
  9813. });
  9814. /**
  9815. * Sets the scale of the sprite using a BABYLON.Size(w,h).
  9816. * Keeps proportion by taking the maximum of the two scale for x and y.
  9817. * @param {Size} size Size(width,height)
  9818. */
  9819. Sprite2D.prototype.scaleToSize = function (size) {
  9820. var baseSize = this.size;
  9821. if (baseSize == null || !this.texture.isReady()) {
  9822. // we're probably at initiation of the scene, size is not set
  9823. if (this.texture.isReady()) {
  9824. baseSize = this.texture.getBaseSize();
  9825. }
  9826. else {
  9827. // the texture is not ready, wait for it to load before calling scaleToSize again
  9828. var thisObject = this;
  9829. this.texture.onLoadObservable.add(function () {
  9830. thisObject.scaleToSize(size);
  9831. });
  9832. return;
  9833. }
  9834. }
  9835. this.scale = Math.max(size.height / baseSize.height, size.width / baseSize.width);
  9836. };
  9837. Object.defineProperty(Sprite2D.prototype, "alignToPixel", {
  9838. /**
  9839. * Get/set if the sprite rendering should be aligned to the target rendering device pixel or not
  9840. */
  9841. get: function () {
  9842. return this._alignToPixel;
  9843. },
  9844. set: function (value) {
  9845. this._alignToPixel = value;
  9846. },
  9847. enumerable: true,
  9848. configurable: true
  9849. });
  9850. Sprite2D.prototype.updateLevelBoundingInfo = function () {
  9851. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.size, this._levelBoundingInfo);
  9852. };
  9853. /**
  9854. * Get the animatable array (see http://doc.babylonjs.com/tutorials/Animations)
  9855. */
  9856. Sprite2D.prototype.getAnimatables = function () {
  9857. var res = new Array();
  9858. if (this.texture && this.texture.animations && this.texture.animations.length > 0) {
  9859. res.push(this.texture);
  9860. }
  9861. return res;
  9862. };
  9863. Sprite2D.prototype.levelIntersect = function (intersectInfo) {
  9864. // 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
  9865. return true;
  9866. };
  9867. Sprite2D.prototype.createModelRenderCache = function (modelKey) {
  9868. var renderCache = new Sprite2DRenderCache(this.owner.engine, modelKey);
  9869. return renderCache;
  9870. };
  9871. Sprite2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  9872. var renderCache = modelRenderCache;
  9873. var engine = this.owner.engine;
  9874. var vb = new Float32Array(4);
  9875. for (var i = 0; i < 4; i++) {
  9876. vb[i] = i;
  9877. }
  9878. renderCache.vb = engine.createVertexBuffer(vb);
  9879. var ib = new Float32Array(6);
  9880. ib[0] = 0;
  9881. ib[1] = 2;
  9882. ib[2] = 1;
  9883. ib[3] = 0;
  9884. ib[4] = 3;
  9885. ib[5] = 2;
  9886. renderCache.ib = engine.createIndexBuffer(ib);
  9887. renderCache.texture = this.texture;
  9888. // 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
  9889. var ei = this.getDataPartEffectInfo(Sprite2D_1.SPRITE2D_MAINPARTID, ["index"], ["alphaTest"], true);
  9890. if (ei) {
  9891. renderCache.effectInstanced = engine.createEffect("sprite2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  9892. }
  9893. ei = this.getDataPartEffectInfo(Sprite2D_1.SPRITE2D_MAINPARTID, ["index"], ["alphaTest"], false);
  9894. renderCache.effect = engine.createEffect("sprite2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  9895. return renderCache;
  9896. };
  9897. Sprite2D.prototype.createInstanceDataParts = function () {
  9898. return [new Sprite2DInstanceData(Sprite2D_1.SPRITE2D_MAINPARTID)];
  9899. };
  9900. Sprite2D.prototype.beforeRefreshForLayoutConstruction = function (part) {
  9901. Sprite2D_1.layoutConstructMode = true;
  9902. };
  9903. // if obj contains something, we restore the _text property
  9904. Sprite2D.prototype.afterRefreshForLayoutConstruction = function (part, obj) {
  9905. Sprite2D_1.layoutConstructMode = false;
  9906. };
  9907. Sprite2D.prototype.refreshInstanceDataPart = function (part) {
  9908. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  9909. return false;
  9910. }
  9911. if (!this.texture.isReady() && !Sprite2D_1.layoutConstructMode) {
  9912. return false;
  9913. }
  9914. if (part.id === Sprite2D_1.SPRITE2D_MAINPARTID) {
  9915. var d = this._instanceDataParts[0];
  9916. if (Sprite2D_1.layoutConstructMode) {
  9917. d.topLeftUV = BABYLON.Vector2.Zero();
  9918. d.sizeUV = BABYLON.Vector2.Zero();
  9919. d.properties = BABYLON.Vector3.Zero();
  9920. d.textureSize = BABYLON.Vector2.Zero();
  9921. d.scaleFactor = BABYLON.Vector2.Zero();
  9922. }
  9923. else {
  9924. var ts = this.texture.getBaseSize();
  9925. var sl = this.spriteLocation;
  9926. var ss = this.actualSize;
  9927. var ssf = this.spriteScaleFactor;
  9928. d.topLeftUV = new BABYLON.Vector2(sl.x / ts.width, sl.y / ts.height);
  9929. var suv = new BABYLON.Vector2(ss.width / ts.width, ss.height / ts.height);
  9930. d.sizeUV = suv;
  9931. d.scaleFactor = ssf;
  9932. Sprite2D_1._prop.x = this.spriteFrame;
  9933. Sprite2D_1._prop.y = this.invertY ? 1 : 0;
  9934. Sprite2D_1._prop.z = this.alignToPixel ? 1 : 0;
  9935. d.properties = Sprite2D_1._prop;
  9936. d.textureSize = new BABYLON.Vector2(ts.width, ts.height);
  9937. }
  9938. }
  9939. return true;
  9940. };
  9941. Sprite2D.prototype._mustUpdateInstance = function () {
  9942. var res = this._oldTextureHasAlpha !== (this.texture != null && this.texture.hasAlpha);
  9943. this._oldTextureHasAlpha = this.texture != null && this.texture.hasAlpha;
  9944. if (res) {
  9945. this._updateRenderMode();
  9946. }
  9947. return res;
  9948. };
  9949. Sprite2D.prototype._useTextureAlpha = function () {
  9950. return this.texture != null && this.texture.hasAlpha;
  9951. };
  9952. Sprite2D.prototype._shouldUseAlphaFromTexture = function () {
  9953. return this.texture != null && this.texture.hasAlpha && this.useAlphaFromTexture;
  9954. };
  9955. return Sprite2D;
  9956. }(BABYLON.RenderablePrim2D));
  9957. Sprite2D.SPRITE2D_MAINPARTID = 1;
  9958. Sprite2D._prop = BABYLON.Vector3.Zero();
  9959. Sprite2D.layoutConstructMode = false;
  9960. __decorate([
  9961. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 1, function (pi) { return Sprite2D_1.textureProperty = pi; })
  9962. ], Sprite2D.prototype, "texture", null);
  9963. __decorate([
  9964. BABYLON.dynamicLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 2, function (pi) { return Sprite2D_1.useAlphaFromTextureProperty = pi; })
  9965. ], Sprite2D.prototype, "useAlphaFromTexture", null);
  9966. __decorate([
  9967. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 3, function (pi) { return Sprite2D_1.actualSizeProperty = pi; }, false, true)
  9968. ], Sprite2D.prototype, "actualSize", null);
  9969. __decorate([
  9970. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 4, function (pi) { return Sprite2D_1.spriteLocationProperty = pi; })
  9971. ], Sprite2D.prototype, "spriteLocation", null);
  9972. __decorate([
  9973. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 5, function (pi) { return Sprite2D_1.spriteFrameProperty = pi; })
  9974. ], Sprite2D.prototype, "spriteFrame", null);
  9975. __decorate([
  9976. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 6, function (pi) { return Sprite2D_1.invertYProperty = pi; })
  9977. ], Sprite2D.prototype, "invertY", null);
  9978. __decorate([
  9979. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 7, function (pi) { return Sprite2D_1.spriteScaleFactorProperty = pi; })
  9980. ], Sprite2D.prototype, "spriteScaleFactor", null);
  9981. Sprite2D = Sprite2D_1 = __decorate([
  9982. BABYLON.className("Sprite2D", "BABYLON")
  9983. ], Sprite2D);
  9984. BABYLON.Sprite2D = Sprite2D;
  9985. var Sprite2D_1;
  9986. })(BABYLON || (BABYLON = {}));
  9987. //# sourceMappingURL=babylon.sprite2d.js.map
  9988. var __extends = (this && this.__extends) || function (d, b) {
  9989. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  9990. function __() { this.constructor = d; }
  9991. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9992. };
  9993. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  9994. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  9995. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  9996. 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;
  9997. return c > 3 && r && Object.defineProperty(target, key, r), r;
  9998. };
  9999. var BABYLON;
  10000. (function (BABYLON) {
  10001. var Text2DRenderCache = (function (_super) {
  10002. __extends(Text2DRenderCache, _super);
  10003. function Text2DRenderCache() {
  10004. var _this = _super.apply(this, arguments) || this;
  10005. _this.effectsReady = false;
  10006. _this.vb = null;
  10007. _this.ib = null;
  10008. _this.instancingAttributes = null;
  10009. _this.fontTexture = null;
  10010. _this.effect = null;
  10011. _this.effectInstanced = null;
  10012. return _this;
  10013. }
  10014. Text2DRenderCache.prototype.render = function (instanceInfo, context) {
  10015. // Do nothing if the shader is still loading/preparing
  10016. if (!this.effectsReady) {
  10017. if ((this.effect && (!this.effect.isReady() || (this.effectInstanced && !this.effectInstanced.isReady())))) {
  10018. return false;
  10019. }
  10020. this.effectsReady = true;
  10021. }
  10022. var canvas = instanceInfo.owner.owner;
  10023. var engine = canvas.engine;
  10024. this.fontTexture.update();
  10025. var effect = context.useInstancing ? this.effectInstanced : this.effect;
  10026. engine.enableEffect(effect);
  10027. effect.setTexture("diffuseSampler", this.fontTexture);
  10028. engine.bindBuffersDirectly(this.vb, this.ib, [1], 4, effect);
  10029. var sdf = this.fontTexture.isSignedDistanceField;
  10030. // Enable alpha mode only if the texture is not using SDF, SDF is rendered in AlphaTest mode, which mean no alpha blend
  10031. var curAlphaMode;
  10032. if (!sdf) {
  10033. curAlphaMode = engine.getAlphaMode();
  10034. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  10035. }
  10036. var pid = context.groupInfoPartData[0];
  10037. if (context.useInstancing) {
  10038. if (!this.instancingAttributes) {
  10039. this.instancingAttributes = this.loadInstancingAttributes(Text2D.TEXT2D_MAINPARTID, effect);
  10040. }
  10041. var glBuffer = context.instancedBuffers ? context.instancedBuffers[0] : pid._partBuffer;
  10042. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  10043. canvas._addDrawCallCount(1, context.renderMode);
  10044. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingAttributes);
  10045. engine.draw(true, 0, 6, count);
  10046. engine.unbindInstanceAttributes();
  10047. }
  10048. else {
  10049. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  10050. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  10051. this.setupUniforms(effect, 0, pid._partData, i);
  10052. engine.draw(true, 0, 6);
  10053. }
  10054. }
  10055. if (!sdf) {
  10056. engine.setAlphaMode(curAlphaMode, true);
  10057. }
  10058. return true;
  10059. };
  10060. Text2DRenderCache.prototype.dispose = function () {
  10061. if (!_super.prototype.dispose.call(this)) {
  10062. return false;
  10063. }
  10064. if (this.vb) {
  10065. this._engine._releaseBuffer(this.vb);
  10066. this.vb = null;
  10067. }
  10068. if (this.ib) {
  10069. this._engine._releaseBuffer(this.ib);
  10070. this.ib = null;
  10071. }
  10072. if (this.fontTexture) {
  10073. this.fontTexture.decCachedFontTextureCounter();
  10074. this.fontTexture = null;
  10075. }
  10076. this.effect = null;
  10077. this.effectInstanced = null;
  10078. return true;
  10079. };
  10080. return Text2DRenderCache;
  10081. }(BABYLON.ModelRenderCache));
  10082. BABYLON.Text2DRenderCache = Text2DRenderCache;
  10083. var Text2DInstanceData = (function (_super) {
  10084. __extends(Text2DInstanceData, _super);
  10085. function Text2DInstanceData(partId, dataElementCount) {
  10086. return _super.call(this, partId, dataElementCount) || this;
  10087. }
  10088. Object.defineProperty(Text2DInstanceData.prototype, "topLeftUV", {
  10089. get: function () {
  10090. return null;
  10091. },
  10092. set: function (value) {
  10093. },
  10094. enumerable: true,
  10095. configurable: true
  10096. });
  10097. Object.defineProperty(Text2DInstanceData.prototype, "sizeUV", {
  10098. get: function () {
  10099. return null;
  10100. },
  10101. set: function (value) {
  10102. },
  10103. enumerable: true,
  10104. configurable: true
  10105. });
  10106. Object.defineProperty(Text2DInstanceData.prototype, "textureSize", {
  10107. get: function () {
  10108. return null;
  10109. },
  10110. set: function (value) {
  10111. },
  10112. enumerable: true,
  10113. configurable: true
  10114. });
  10115. Object.defineProperty(Text2DInstanceData.prototype, "color", {
  10116. get: function () {
  10117. return null;
  10118. },
  10119. set: function (value) {
  10120. },
  10121. enumerable: true,
  10122. configurable: true
  10123. });
  10124. Object.defineProperty(Text2DInstanceData.prototype, "superSampleFactor", {
  10125. get: function () {
  10126. return null;
  10127. },
  10128. set: function (value) {
  10129. },
  10130. enumerable: true,
  10131. configurable: true
  10132. });
  10133. return Text2DInstanceData;
  10134. }(BABYLON.InstanceDataBase));
  10135. __decorate([
  10136. BABYLON.instanceData()
  10137. ], Text2DInstanceData.prototype, "topLeftUV", null);
  10138. __decorate([
  10139. BABYLON.instanceData()
  10140. ], Text2DInstanceData.prototype, "sizeUV", null);
  10141. __decorate([
  10142. BABYLON.instanceData()
  10143. ], Text2DInstanceData.prototype, "textureSize", null);
  10144. __decorate([
  10145. BABYLON.instanceData()
  10146. ], Text2DInstanceData.prototype, "color", null);
  10147. __decorate([
  10148. BABYLON.instanceData()
  10149. ], Text2DInstanceData.prototype, "superSampleFactor", null);
  10150. BABYLON.Text2DInstanceData = Text2DInstanceData;
  10151. var Text2D = Text2D_1 = (function (_super) {
  10152. __extends(Text2D, _super);
  10153. /**
  10154. * Create a Text primitive
  10155. * @param text the text to display
  10156. * @param settings a combination of settings, possible ones are
  10157. * - 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)
  10158. * - children: an array of direct children
  10159. * - id a text identifier, for information purpose
  10160. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  10161. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  10162. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  10163. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  10164. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  10165. * - zOrder: override the zOrder with the specified value
  10166. * - origin: define the normalized origin point location, default [0.5;0.5]
  10167. * - fontName: the name/size/style of the font to use, following the CSS notation. Default is "12pt Arial".
  10168. * - 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.
  10169. * - 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.
  10170. * - defaultFontColor: the color by default to apply on each letter of the text to display, default is plain white.
  10171. * - areaSize: the size of the area in which to display the text, default is auto-fit from text content.
  10172. * - tabulationSize: number of space character to insert when a tabulation is encountered, default is 4
  10173. * - isVisible: true if the text must be visible, false for hidden. Default is true.
  10174. * - 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.
  10175. * - 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.
  10176. * - 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!
  10177. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10178. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10179. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10180. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10181. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  10182. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  10183. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  10184. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  10185. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10186. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10187. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10188. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10189. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  10190. */
  10191. function Text2D(text, settings) {
  10192. var _this;
  10193. if (!settings) {
  10194. settings = {};
  10195. }
  10196. _this = _super.call(this, settings) || this;
  10197. _this.fontName = (settings.fontName == null) ? "12pt Arial" : settings.fontName;
  10198. _this._fontSuperSample = (settings.fontSuperSample != null && settings.fontSuperSample);
  10199. _this._fontSDF = (settings.fontSignedDistanceField != null && settings.fontSignedDistanceField);
  10200. _this.defaultFontColor = (settings.defaultFontColor == null) ? new BABYLON.Color4(1, 1, 1, 1) : settings.defaultFontColor;
  10201. _this._tabulationSize = (settings.tabulationSize == null) ? 4 : settings.tabulationSize;
  10202. _this._textSize = null;
  10203. _this.text = text;
  10204. _this.size = (settings.size == null) ? null : settings.size;
  10205. _this._updateRenderMode();
  10206. return _this;
  10207. }
  10208. Object.defineProperty(Text2D.prototype, "fontName", {
  10209. get: function () {
  10210. return this._fontName;
  10211. },
  10212. set: function (value) {
  10213. if (this._fontName) {
  10214. throw new Error("Font Name change is not supported right now.");
  10215. }
  10216. this._fontName = value;
  10217. },
  10218. enumerable: true,
  10219. configurable: true
  10220. });
  10221. Object.defineProperty(Text2D.prototype, "defaultFontColor", {
  10222. get: function () {
  10223. return this._defaultFontColor;
  10224. },
  10225. set: function (value) {
  10226. this._defaultFontColor = value;
  10227. },
  10228. enumerable: true,
  10229. configurable: true
  10230. });
  10231. Object.defineProperty(Text2D.prototype, "text", {
  10232. get: function () {
  10233. return this._text;
  10234. },
  10235. set: function (value) {
  10236. if (!value) {
  10237. value = "";
  10238. }
  10239. this._text = value;
  10240. this._textSize = null; // A change of text will reset the TextSize which will be recomputed next time it's used
  10241. this._size = null;
  10242. this._updateCharCount();
  10243. // Trigger a textSize to for a sizeChange if necessary, which is needed for layout to recompute
  10244. var s = this.textSize;
  10245. },
  10246. enumerable: true,
  10247. configurable: true
  10248. });
  10249. Object.defineProperty(Text2D.prototype, "size", {
  10250. get: function () {
  10251. if (this._size != null) {
  10252. return this._size;
  10253. }
  10254. return this.textSize;
  10255. },
  10256. set: function (value) {
  10257. this._size = value;
  10258. },
  10259. enumerable: true,
  10260. configurable: true
  10261. });
  10262. Object.defineProperty(Text2D.prototype, "fontSuperSample", {
  10263. get: function () {
  10264. return this._fontTexture && this._fontTexture.isSuperSampled;
  10265. },
  10266. enumerable: true,
  10267. configurable: true
  10268. });
  10269. Object.defineProperty(Text2D.prototype, "fontSignedDistanceField", {
  10270. get: function () {
  10271. return this._fontTexture && this._fontTexture.isSignedDistanceField;
  10272. },
  10273. enumerable: true,
  10274. configurable: true
  10275. });
  10276. Object.defineProperty(Text2D.prototype, "isSizeAuto", {
  10277. get: function () {
  10278. return false;
  10279. },
  10280. enumerable: true,
  10281. configurable: true
  10282. });
  10283. Object.defineProperty(Text2D.prototype, "actualSize", {
  10284. /**
  10285. * Get the actual size of the Text2D primitive
  10286. */
  10287. get: function () {
  10288. if (this._actualSize) {
  10289. return this._actualSize;
  10290. }
  10291. return this.size;
  10292. },
  10293. enumerable: true,
  10294. configurable: true
  10295. });
  10296. Object.defineProperty(Text2D.prototype, "textSize", {
  10297. /**
  10298. * Get the area that bounds the text associated to the primitive
  10299. */
  10300. get: function () {
  10301. if (!this._textSize) {
  10302. if (this.owner && this._text) {
  10303. var newSize = this.fontTexture.measureText(this._text, this._tabulationSize);
  10304. if (!newSize.equals(this._textSize)) {
  10305. this.onPrimitivePropertyDirty(BABYLON.Prim2DBase.sizeProperty.flagId);
  10306. this._positioningDirty();
  10307. }
  10308. this._textSize = newSize;
  10309. }
  10310. else {
  10311. return Text2D_1.nullSize;
  10312. }
  10313. }
  10314. return this._textSize;
  10315. },
  10316. enumerable: true,
  10317. configurable: true
  10318. });
  10319. Object.defineProperty(Text2D.prototype, "fontTexture", {
  10320. get: function () {
  10321. if (this._fontTexture) {
  10322. return this._fontTexture;
  10323. }
  10324. if (this.fontName == null || this.owner == null || this.owner.scene == null) {
  10325. return null;
  10326. }
  10327. this._fontTexture = BABYLON.FontTexture.GetCachedFontTexture(this.owner.scene, this.fontName, this._fontSuperSample, this._fontSDF);
  10328. return this._fontTexture;
  10329. },
  10330. enumerable: true,
  10331. configurable: true
  10332. });
  10333. /**
  10334. * Dispose the primitive, remove it from its parent
  10335. */
  10336. Text2D.prototype.dispose = function () {
  10337. if (!_super.prototype.dispose.call(this)) {
  10338. return false;
  10339. }
  10340. if (this._fontTexture) {
  10341. BABYLON.FontTexture.ReleaseCachedFontTexture(this.owner.scene, this.fontName, this._fontSuperSample, this._fontSDF);
  10342. this._fontTexture = null;
  10343. }
  10344. return true;
  10345. };
  10346. Text2D.prototype.updateLevelBoundingInfo = function () {
  10347. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.actualSize, this._levelBoundingInfo);
  10348. };
  10349. Text2D.prototype.levelIntersect = function (intersectInfo) {
  10350. // 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...
  10351. return true;
  10352. };
  10353. Text2D.prototype.createModelRenderCache = function (modelKey) {
  10354. var renderCache = new Text2DRenderCache(this.owner.engine, modelKey);
  10355. return renderCache;
  10356. };
  10357. Text2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  10358. var renderCache = modelRenderCache;
  10359. var engine = this.owner.engine;
  10360. renderCache.fontTexture = this.fontTexture;
  10361. renderCache.fontTexture.incCachedFontTextureCounter();
  10362. var vb = new Float32Array(4);
  10363. for (var i = 0; i < 4; i++) {
  10364. vb[i] = i;
  10365. }
  10366. renderCache.vb = engine.createVertexBuffer(vb);
  10367. var ib = new Float32Array(6);
  10368. ib[0] = 0;
  10369. ib[1] = 2;
  10370. ib[2] = 1;
  10371. ib[3] = 0;
  10372. ib[4] = 3;
  10373. ib[5] = 2;
  10374. renderCache.ib = engine.createIndexBuffer(ib);
  10375. // 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
  10376. var ei = this.getDataPartEffectInfo(Text2D_1.TEXT2D_MAINPARTID, ["index"], null, true);
  10377. if (ei) {
  10378. renderCache.effectInstanced = engine.createEffect("text2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  10379. }
  10380. ei = this.getDataPartEffectInfo(Text2D_1.TEXT2D_MAINPARTID, ["index"], null, false);
  10381. renderCache.effect = engine.createEffect("text2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  10382. return renderCache;
  10383. };
  10384. Text2D.prototype.createInstanceDataParts = function () {
  10385. return [new Text2DInstanceData(Text2D_1.TEXT2D_MAINPARTID, this._charCount)];
  10386. };
  10387. // Looks like a hack!? Yes! Because that's what it is!
  10388. // 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
  10389. // 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)
  10390. Text2D.prototype.beforeRefreshForLayoutConstruction = function (part) {
  10391. if (!this._charCount) {
  10392. var curText = this._text;
  10393. this.text = "A";
  10394. return curText;
  10395. }
  10396. };
  10397. // if obj contains something, we restore the _text property
  10398. Text2D.prototype.afterRefreshForLayoutConstruction = function (part, obj) {
  10399. if (obj !== undefined) {
  10400. this.text = obj;
  10401. }
  10402. };
  10403. Text2D.prototype.getUsedShaderCategories = function (dataPart) {
  10404. var cat = _super.prototype.getUsedShaderCategories.call(this, dataPart);
  10405. if (this._fontSDF) {
  10406. cat.push(Text2D_1.TEXT2D_CATEGORY_SDF);
  10407. }
  10408. return cat;
  10409. };
  10410. Text2D.prototype.refreshInstanceDataPart = function (part) {
  10411. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  10412. return false;
  10413. }
  10414. if (part.id === Text2D_1.TEXT2D_MAINPARTID) {
  10415. var d = part;
  10416. var texture = this.fontTexture;
  10417. var superSampleFactor = texture.isSuperSampled ? 0.5 : 1;
  10418. var ts = texture.getSize();
  10419. var offset = BABYLON.Vector2.Zero();
  10420. var lh = this.fontTexture.lineHeight;
  10421. 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
  10422. var charxpos = 0;
  10423. d.dataElementCount = this._charCount;
  10424. d.curElement = 0;
  10425. for (var _i = 0, _a = this.text; _i < _a.length; _i++) {
  10426. var char = _a[_i];
  10427. // Line feed
  10428. if (char === "\n") {
  10429. offset.x = 0;
  10430. offset.y -= texture.lineHeight;
  10431. }
  10432. // Tabulation ?
  10433. if (char === "\t") {
  10434. var nextPos = charxpos + this._tabulationSize;
  10435. nextPos = nextPos - (nextPos % this._tabulationSize);
  10436. offset.x += (nextPos - charxpos) * texture.spaceWidth;
  10437. charxpos = nextPos;
  10438. continue;
  10439. }
  10440. if (char < " ") {
  10441. continue;
  10442. }
  10443. this.updateInstanceDataPart(d, offset);
  10444. var ci = texture.getChar(char);
  10445. offset.x += ci.charWidth;
  10446. d.topLeftUV = ci.topLeftUV;
  10447. var suv = ci.bottomRightUV.subtract(ci.topLeftUV);
  10448. d.sizeUV = suv;
  10449. d.textureSize = new BABYLON.Vector2(ts.width, ts.height);
  10450. d.color = this.defaultFontColor;
  10451. d.superSampleFactor = superSampleFactor;
  10452. ++d.curElement;
  10453. }
  10454. }
  10455. return true;
  10456. };
  10457. Text2D.prototype._updateCharCount = function () {
  10458. var count = 0;
  10459. for (var _i = 0, _a = this._text; _i < _a.length; _i++) {
  10460. var char = _a[_i];
  10461. if (char === "\r" || char === "\n" || char === "\t" || char < " ") {
  10462. continue;
  10463. }
  10464. ++count;
  10465. }
  10466. this._charCount = count;
  10467. };
  10468. Text2D.prototype._useTextureAlpha = function () {
  10469. return this._fontSDF;
  10470. };
  10471. Text2D.prototype._shouldUseAlphaFromTexture = function () {
  10472. return !this._fontSDF;
  10473. };
  10474. return Text2D;
  10475. }(BABYLON.RenderablePrim2D));
  10476. Text2D.TEXT2D_MAINPARTID = 1;
  10477. Text2D.TEXT2D_CATEGORY_SDF = "SignedDistanceField";
  10478. __decorate([
  10479. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 1, function (pi) { return Text2D_1.fontProperty = pi; }, false, true)
  10480. ], Text2D.prototype, "fontName", null);
  10481. __decorate([
  10482. BABYLON.dynamicLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 2, function (pi) { return Text2D_1.defaultFontColorProperty = pi; })
  10483. ], Text2D.prototype, "defaultFontColor", null);
  10484. __decorate([
  10485. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 3, function (pi) { return Text2D_1.textProperty = pi; }, false, true)
  10486. ], Text2D.prototype, "text", null);
  10487. __decorate([
  10488. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 4, function (pi) { return Text2D_1.sizeProperty = pi; })
  10489. ], Text2D.prototype, "size", null);
  10490. __decorate([
  10491. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 5, function (pi) { return Text2D_1.fontSuperSampleProperty = pi; }, false, false)
  10492. ], Text2D.prototype, "fontSuperSample", null);
  10493. __decorate([
  10494. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 6, function (pi) { return Text2D_1.fontSuperSampleProperty = pi; }, false, false)
  10495. ], Text2D.prototype, "fontSignedDistanceField", null);
  10496. Text2D = Text2D_1 = __decorate([
  10497. BABYLON.className("Text2D", "BABYLON")
  10498. ], Text2D);
  10499. BABYLON.Text2D = Text2D;
  10500. var Text2D_1;
  10501. })(BABYLON || (BABYLON = {}));
  10502. //# sourceMappingURL=babylon.text2d.js.map
  10503. var __extends = (this && this.__extends) || function (d, b) {
  10504. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  10505. function __() { this.constructor = d; }
  10506. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10507. };
  10508. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  10509. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  10510. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  10511. 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;
  10512. return c > 3 && r && Object.defineProperty(target, key, r), r;
  10513. };
  10514. var BABYLON;
  10515. (function (BABYLON) {
  10516. var Lines2DRenderCache = (function (_super) {
  10517. __extends(Lines2DRenderCache, _super);
  10518. function Lines2DRenderCache(engine, modelKey) {
  10519. var _this = _super.call(this, engine, modelKey) || this;
  10520. _this.effectsReady = false;
  10521. _this.fillVB = null;
  10522. _this.fillIB = null;
  10523. _this.fillIndicesCount = 0;
  10524. _this.instancingFillAttributes = null;
  10525. _this.effectFill = null;
  10526. _this.effectFillInstanced = null;
  10527. _this.borderVB = null;
  10528. _this.borderIB = null;
  10529. _this.borderIndicesCount = 0;
  10530. _this.instancingBorderAttributes = null;
  10531. _this.effectBorder = null;
  10532. _this.effectBorderInstanced = null;
  10533. return _this;
  10534. }
  10535. Lines2DRenderCache.prototype.render = function (instanceInfo, context) {
  10536. // Do nothing if the shader is still loading/preparing
  10537. if (!this.effectsReady) {
  10538. if ((this.effectFill && (!this.effectFill.isReady() || (this.effectFillInstanced && !this.effectFillInstanced.isReady()))) ||
  10539. (this.effectBorder && (!this.effectBorder.isReady() || (this.effectBorderInstanced && !this.effectBorderInstanced.isReady())))) {
  10540. return false;
  10541. }
  10542. this.effectsReady = true;
  10543. }
  10544. var canvas = instanceInfo.owner.owner;
  10545. var engine = canvas.engine;
  10546. var depthFunction = 0;
  10547. if (this.effectFill && this.effectBorder) {
  10548. depthFunction = engine.getDepthFunction();
  10549. engine.setDepthFunctionToLessOrEqual();
  10550. }
  10551. var curAlphaMode = engine.getAlphaMode();
  10552. if (this.effectFill) {
  10553. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_FILLPARTID.toString());
  10554. var pid = context.groupInfoPartData[partIndex];
  10555. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  10556. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  10557. }
  10558. var effect = context.useInstancing ? this.effectFillInstanced : this.effectFill;
  10559. engine.enableEffect(effect);
  10560. engine.bindBuffersDirectly(this.fillVB, this.fillIB, [2], 2 * 4, effect);
  10561. if (context.useInstancing) {
  10562. if (!this.instancingFillAttributes) {
  10563. this.instancingFillAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_FILLPARTID, effect);
  10564. }
  10565. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  10566. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  10567. canvas._addDrawCallCount(1, context.renderMode);
  10568. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingFillAttributes);
  10569. engine.draw(true, 0, this.fillIndicesCount, count);
  10570. engine.unbindInstanceAttributes();
  10571. }
  10572. else {
  10573. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  10574. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  10575. this.setupUniforms(effect, partIndex, pid._partData, i);
  10576. engine.draw(true, 0, this.fillIndicesCount);
  10577. }
  10578. }
  10579. }
  10580. if (this.effectBorder) {
  10581. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_BORDERPARTID.toString());
  10582. var pid = context.groupInfoPartData[partIndex];
  10583. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  10584. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  10585. }
  10586. var effect = context.useInstancing ? this.effectBorderInstanced : this.effectBorder;
  10587. engine.enableEffect(effect);
  10588. engine.bindBuffersDirectly(this.borderVB, this.borderIB, [2], 2 * 4, effect);
  10589. if (context.useInstancing) {
  10590. if (!this.instancingBorderAttributes) {
  10591. this.instancingBorderAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, effect);
  10592. }
  10593. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  10594. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  10595. canvas._addDrawCallCount(1, context.renderMode);
  10596. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingBorderAttributes);
  10597. engine.draw(true, 0, this.borderIndicesCount, count);
  10598. engine.unbindInstanceAttributes();
  10599. }
  10600. else {
  10601. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  10602. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  10603. this.setupUniforms(effect, partIndex, pid._partData, i);
  10604. engine.draw(true, 0, this.borderIndicesCount);
  10605. }
  10606. }
  10607. }
  10608. engine.setAlphaMode(curAlphaMode, true);
  10609. if (this.effectFill && this.effectBorder) {
  10610. engine.setDepthFunction(depthFunction);
  10611. }
  10612. return true;
  10613. };
  10614. Lines2DRenderCache.prototype.dispose = function () {
  10615. if (!_super.prototype.dispose.call(this)) {
  10616. return false;
  10617. }
  10618. if (this.fillVB) {
  10619. this._engine._releaseBuffer(this.fillVB);
  10620. this.fillVB = null;
  10621. }
  10622. if (this.fillIB) {
  10623. this._engine._releaseBuffer(this.fillIB);
  10624. this.fillIB = null;
  10625. }
  10626. this.effectFill = null;
  10627. this.effectFillInstanced = null;
  10628. this.effectBorder = null;
  10629. this.effectBorderInstanced = null;
  10630. if (this.borderVB) {
  10631. this._engine._releaseBuffer(this.borderVB);
  10632. this.borderVB = null;
  10633. }
  10634. if (this.borderIB) {
  10635. this._engine._releaseBuffer(this.borderIB);
  10636. this.borderIB = null;
  10637. }
  10638. return true;
  10639. };
  10640. return Lines2DRenderCache;
  10641. }(BABYLON.ModelRenderCache));
  10642. BABYLON.Lines2DRenderCache = Lines2DRenderCache;
  10643. var Lines2DInstanceData = (function (_super) {
  10644. __extends(Lines2DInstanceData, _super);
  10645. function Lines2DInstanceData(partId) {
  10646. return _super.call(this, partId, 1) || this;
  10647. }
  10648. Object.defineProperty(Lines2DInstanceData.prototype, "boundingMin", {
  10649. get: function () {
  10650. return null;
  10651. },
  10652. set: function (value) {
  10653. },
  10654. enumerable: true,
  10655. configurable: true
  10656. });
  10657. Object.defineProperty(Lines2DInstanceData.prototype, "boundingMax", {
  10658. get: function () {
  10659. return null;
  10660. },
  10661. set: function (value) {
  10662. },
  10663. enumerable: true,
  10664. configurable: true
  10665. });
  10666. return Lines2DInstanceData;
  10667. }(BABYLON.Shape2DInstanceData));
  10668. __decorate([
  10669. BABYLON.instanceData(BABYLON.Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  10670. ], Lines2DInstanceData.prototype, "boundingMin", null);
  10671. __decorate([
  10672. BABYLON.instanceData(BABYLON.Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  10673. ], Lines2DInstanceData.prototype, "boundingMax", null);
  10674. BABYLON.Lines2DInstanceData = Lines2DInstanceData;
  10675. var Lines2D = Lines2D_1 = (function (_super) {
  10676. __extends(Lines2D, _super);
  10677. /**
  10678. * Create an 2D Lines Shape primitive. The defined lines may be opened or closed (see below)
  10679. * @param points an array that describe the points to use to draw the line, must contain at least two entries.
  10680. * @param settings a combination of settings, possible ones are
  10681. * - 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)
  10682. * - children: an array of direct children
  10683. * - id a text identifier, for information purpose
  10684. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  10685. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  10686. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  10687. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  10688. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  10689. * - zOrder: override the zOrder with the specified value
  10690. * - origin: define the normalized origin point location, default [0.5;0.5]
  10691. * - 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.
  10692. * - 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.
  10693. * - 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.
  10694. * - 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.
  10695. * - 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)
  10696. * - 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)
  10697. * - borderThickness: the thickness of the drawn border, default is 1.
  10698. * - isVisible: true if the primitive must be visible, false for hidden. Default is true.
  10699. * - 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.
  10700. * - 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.
  10701. * - 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!
  10702. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10703. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10704. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10705. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10706. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  10707. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  10708. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  10709. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  10710. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10711. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10712. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10713. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10714. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  10715. */
  10716. function Lines2D(points, settings) {
  10717. var _this;
  10718. if (!settings) {
  10719. settings = {};
  10720. }
  10721. _this = _super.call(this, settings) || this;
  10722. _this._fillVB = null;
  10723. _this._fillIB = null;
  10724. _this._borderVB = null;
  10725. _this._borderIB = null;
  10726. _this._size = BABYLON.Size.Zero();
  10727. _this._boundingMin = null;
  10728. _this._boundingMax = null;
  10729. var fillThickness = (settings.fillThickness == null) ? 1 : settings.fillThickness;
  10730. var startCap = (settings.startCap == null) ? 0 : settings.startCap;
  10731. var endCap = (settings.endCap == null) ? 0 : settings.endCap;
  10732. var closed = (settings.closed == null) ? false : settings.closed;
  10733. _this.points = points;
  10734. _this.fillThickness = fillThickness;
  10735. _this.startCap = startCap;
  10736. _this.endCap = endCap;
  10737. _this.closed = closed;
  10738. return _this;
  10739. }
  10740. Object.defineProperty(Lines2D, "NoCap", {
  10741. /**
  10742. * No Cap to apply on the extremity
  10743. */
  10744. get: function () { return Lines2D_1._noCap; },
  10745. enumerable: true,
  10746. configurable: true
  10747. });
  10748. Object.defineProperty(Lines2D, "RoundCap", {
  10749. /**
  10750. * A round cap, will use the line thickness as diameter
  10751. */
  10752. get: function () { return Lines2D_1._roundCap; },
  10753. enumerable: true,
  10754. configurable: true
  10755. });
  10756. Object.defineProperty(Lines2D, "TriangleCap", {
  10757. /**
  10758. * Creates a triangle at the extremity.
  10759. */
  10760. get: function () { return Lines2D_1._triangleCap; },
  10761. enumerable: true,
  10762. configurable: true
  10763. });
  10764. Object.defineProperty(Lines2D, "SquareAnchorCap", {
  10765. /**
  10766. * Creates a Square anchor at the extremity, the square size is twice the thickness of the line
  10767. */
  10768. get: function () { return Lines2D_1._squareAnchorCap; },
  10769. enumerable: true,
  10770. configurable: true
  10771. });
  10772. Object.defineProperty(Lines2D, "RoundAnchorCap", {
  10773. /**
  10774. * Creates a round anchor at the extremity, the diameter is twice the thickness of the line
  10775. */
  10776. get: function () { return Lines2D_1._roundAnchorCap; },
  10777. enumerable: true,
  10778. configurable: true
  10779. });
  10780. Object.defineProperty(Lines2D, "DiamondAnchorCap", {
  10781. /**
  10782. * Creates a diamond anchor at the extremity.
  10783. */
  10784. get: function () { return Lines2D_1._diamondAnchorCap; },
  10785. enumerable: true,
  10786. configurable: true
  10787. });
  10788. Object.defineProperty(Lines2D, "ArrowCap", {
  10789. /**
  10790. * Creates an arrow anchor at the extremity. the arrow base size is twice the thickness of the line
  10791. */
  10792. get: function () { return Lines2D_1._arrowCap; },
  10793. enumerable: true,
  10794. configurable: true
  10795. });
  10796. Object.defineProperty(Lines2D.prototype, "points", {
  10797. get: function () {
  10798. return this._points;
  10799. },
  10800. set: function (value) {
  10801. this._points = value;
  10802. this._contour = null;
  10803. this._boundingBoxDirty();
  10804. },
  10805. enumerable: true,
  10806. configurable: true
  10807. });
  10808. Object.defineProperty(Lines2D.prototype, "fillThickness", {
  10809. get: function () {
  10810. return this._fillThickness;
  10811. },
  10812. set: function (value) {
  10813. this._fillThickness = value;
  10814. },
  10815. enumerable: true,
  10816. configurable: true
  10817. });
  10818. Object.defineProperty(Lines2D.prototype, "closed", {
  10819. get: function () {
  10820. return this._closed;
  10821. },
  10822. set: function (value) {
  10823. this._closed = value;
  10824. },
  10825. enumerable: true,
  10826. configurable: true
  10827. });
  10828. Object.defineProperty(Lines2D.prototype, "startCap", {
  10829. get: function () {
  10830. return this._startCap;
  10831. },
  10832. set: function (value) {
  10833. this._startCap = value;
  10834. },
  10835. enumerable: true,
  10836. configurable: true
  10837. });
  10838. Object.defineProperty(Lines2D.prototype, "endCap", {
  10839. get: function () {
  10840. return this._endCap;
  10841. },
  10842. set: function (value) {
  10843. this._endCap = value;
  10844. },
  10845. enumerable: true,
  10846. configurable: true
  10847. });
  10848. Lines2D.prototype.levelIntersect = function (intersectInfo) {
  10849. var _this = this;
  10850. if (this._contour == null) {
  10851. this._computeLines2D();
  10852. }
  10853. var pl = this.points.length;
  10854. var l = this.closed ? pl + 1 : pl;
  10855. var p = intersectInfo._localPickPosition;
  10856. this.transformPointWithOriginToRef(this._contour[0], null, Lines2D_1._prevA);
  10857. this.transformPointWithOriginToRef(this._contour[1], null, Lines2D_1._prevB);
  10858. for (var i = 1; i < l; i++) {
  10859. this.transformPointWithOriginToRef(this._contour[(i % pl) * 2 + 0], null, Lines2D_1._curA);
  10860. this.transformPointWithOriginToRef(this._contour[(i % pl) * 2 + 1], null, Lines2D_1._curB);
  10861. if (BABYLON.Vector2.PointInTriangle(p, Lines2D_1._prevA, Lines2D_1._prevB, Lines2D_1._curA)) {
  10862. return true;
  10863. }
  10864. if (BABYLON.Vector2.PointInTriangle(p, Lines2D_1._curA, Lines2D_1._prevB, Lines2D_1._curB)) {
  10865. return true;
  10866. }
  10867. Lines2D_1._prevA.x = Lines2D_1._curA.x;
  10868. Lines2D_1._prevA.y = Lines2D_1._curA.y;
  10869. Lines2D_1._prevB.x = Lines2D_1._curB.x;
  10870. Lines2D_1._prevB.y = Lines2D_1._curB.y;
  10871. }
  10872. var capIntersect = function (tri, points) {
  10873. var l = tri.length;
  10874. for (var i = 0; i < l; i += 3) {
  10875. Lines2D_1._curA.x = points[tri[i + 0] * 2 + 0];
  10876. Lines2D_1._curA.y = points[tri[i + 0] * 2 + 1];
  10877. _this.transformPointWithOriginToRef(Lines2D_1._curA, null, Lines2D_1._curB);
  10878. Lines2D_1._curA.x = points[tri[i + 1] * 2 + 0];
  10879. Lines2D_1._curA.y = points[tri[i + 1] * 2 + 1];
  10880. _this.transformPointWithOriginToRef(Lines2D_1._curA, null, Lines2D_1._prevA);
  10881. Lines2D_1._curA.x = points[tri[i + 2] * 2 + 0];
  10882. Lines2D_1._curA.y = points[tri[i + 2] * 2 + 1];
  10883. _this.transformPointWithOriginToRef(Lines2D_1._curA, null, Lines2D_1._prevB);
  10884. if (BABYLON.Vector2.PointInTriangle(p, Lines2D_1._prevA, Lines2D_1._prevB, Lines2D_1._curB)) {
  10885. return true;
  10886. }
  10887. }
  10888. return false;
  10889. };
  10890. if (this._startCapTriIndices) {
  10891. if (this._startCapTriIndices && capIntersect(this._startCapTriIndices, this._startCapContour)) {
  10892. return true;
  10893. }
  10894. if (this._endCapTriIndices && capIntersect(this._endCapTriIndices, this._endCapContour)) {
  10895. return true;
  10896. }
  10897. }
  10898. return false;
  10899. };
  10900. Object.defineProperty(Lines2D.prototype, "boundingMin", {
  10901. get: function () {
  10902. if (!this._boundingMin) {
  10903. this._computeLines2D();
  10904. }
  10905. return this._boundingMin;
  10906. },
  10907. enumerable: true,
  10908. configurable: true
  10909. });
  10910. Object.defineProperty(Lines2D.prototype, "boundingMax", {
  10911. get: function () {
  10912. if (!this._boundingMax) {
  10913. this._computeLines2D();
  10914. }
  10915. return this._boundingMax;
  10916. },
  10917. enumerable: true,
  10918. configurable: true
  10919. });
  10920. Lines2D.prototype.getUsedShaderCategories = function (dataPart) {
  10921. var res = _super.prototype.getUsedShaderCategories.call(this, dataPart);
  10922. // Remove the BORDER category, we don't use it in the VertexShader
  10923. var i = res.indexOf(BABYLON.Shape2D.SHAPE2D_CATEGORY_BORDER);
  10924. if (i !== -1) {
  10925. res.splice(i, 1);
  10926. }
  10927. return res;
  10928. };
  10929. Lines2D.prototype.updateLevelBoundingInfo = function () {
  10930. if (!this._boundingMin) {
  10931. this._computeLines2D();
  10932. }
  10933. BABYLON.BoundingInfo2D.CreateFromMinMaxToRef(this._boundingMin.x, this._boundingMax.x, this._boundingMin.y, this._boundingMax.y, this._levelBoundingInfo);
  10934. };
  10935. Lines2D.prototype.createModelRenderCache = function (modelKey) {
  10936. var renderCache = new Lines2DRenderCache(this.owner.engine, modelKey);
  10937. return renderCache;
  10938. };
  10939. ///////////////////////////////////////////////////////////////////////////////////
  10940. // Methods for Lines building
  10941. Lines2D.prototype._perp = function (v, res) {
  10942. res.x = v.y;
  10943. res.y = -v.x;
  10944. };
  10945. ;
  10946. Lines2D.prototype._direction = function (a, b, res) {
  10947. a.subtractToRef(b, res);
  10948. res.normalize();
  10949. };
  10950. Lines2D.prototype._computeMiter = function (tangent, miter, a, b) {
  10951. a.addToRef(b, tangent);
  10952. tangent.normalize();
  10953. miter.x = -tangent.y;
  10954. miter.y = tangent.x;
  10955. Lines2D_1._miterTps.x = -a.y;
  10956. Lines2D_1._miterTps.y = a.x;
  10957. return 1 / BABYLON.Vector2.Dot(miter, Lines2D_1._miterTps);
  10958. };
  10959. Lines2D.prototype._intersect = function (x1, y1, x2, y2, x3, y3, x4, y4) {
  10960. var d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
  10961. if (d === 0)
  10962. return false;
  10963. var xi = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d; // Intersection point is xi/yi, just in case...
  10964. //let yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d; // That's why I left it commented
  10965. if (xi < Math.min(x1, x2) || xi > Math.max(x1, x2))
  10966. return false;
  10967. if (xi < Math.min(x3, x4) || xi > Math.max(x3, x4))
  10968. return false;
  10969. return true;
  10970. };
  10971. Lines2D.prototype._updateMinMax = function (array, offset) {
  10972. if (offset >= array.length) {
  10973. return;
  10974. }
  10975. this._boundingMin.x = Math.min(this._boundingMin.x, array[offset]);
  10976. this._boundingMax.x = Math.max(this._boundingMax.x, array[offset]);
  10977. this._boundingMin.y = Math.min(this._boundingMin.y, array[offset + 1]);
  10978. this._boundingMax.y = Math.max(this._boundingMax.y, array[offset + 1]);
  10979. };
  10980. Lines2D.prototype._store = function (array, contour, index, max, p, n, halfThickness, borderThickness, detectFlip) {
  10981. var borderMode = borderThickness != null && !isNaN(borderThickness);
  10982. var off = index * (borderMode ? 8 : 4);
  10983. // 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)
  10984. if (off >= array.length) {
  10985. return;
  10986. }
  10987. // Store start/end normal, we need it for the cap construction
  10988. if (index === 0) {
  10989. this._perp(n, Lines2D_1._startDir);
  10990. }
  10991. else if (index === max - 1) {
  10992. this._perp(n, Lines2D_1._endDir);
  10993. Lines2D_1._endDir.x *= -1;
  10994. Lines2D_1._endDir.y *= -1;
  10995. }
  10996. var swap = false;
  10997. array[off + 0] = p.x + n.x * halfThickness;
  10998. array[off + 1] = p.y + n.y * halfThickness;
  10999. array[off + 2] = p.x + n.x * -halfThickness;
  11000. array[off + 3] = p.y + n.y * -halfThickness;
  11001. this._updateMinMax(array, off);
  11002. this._updateMinMax(array, off + 2);
  11003. // If an index is given we check if the two segments formed between [index+0;detectFlip+0] and [index+2;detectFlip+2] intersect themselves.
  11004. // 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
  11005. if (detectFlip != 0) {
  11006. // Flip if intersect
  11007. var flipOff = detectFlip * (borderMode ? 8 : 4);
  11008. 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])) {
  11009. swap = true;
  11010. var tps = array[off + 0];
  11011. array[off + 0] = array[off + 2];
  11012. array[off + 2] = tps;
  11013. tps = array[off + 1];
  11014. array[off + 1] = array[off + 3];
  11015. array[off + 3] = tps;
  11016. }
  11017. }
  11018. if (borderMode) {
  11019. var t = halfThickness + borderThickness;
  11020. array[off + 4] = p.x + n.x * (swap ? -t : t);
  11021. array[off + 5] = p.y + n.y * (swap ? -t : t);
  11022. array[off + 6] = p.x + n.x * (swap ? t : -t);
  11023. array[off + 7] = p.y + n.y * (swap ? t : -t);
  11024. this._updateMinMax(array, off + 4);
  11025. this._updateMinMax(array, off + 6);
  11026. }
  11027. if (contour) {
  11028. off += borderMode ? 4 : 0;
  11029. contour.push(new BABYLON.Vector2(array[off + 0], array[off + 1]));
  11030. contour.push(new BABYLON.Vector2(array[off + 2], array[off + 3]));
  11031. }
  11032. };
  11033. Lines2D.prototype._getCapSize = function (type, border) {
  11034. if (border === void 0) { border = false; }
  11035. var sd = Lines2D_1._roundCapSubDiv;
  11036. // If no array given, we call this to get the size
  11037. var vbsize = 0, ibsize = 0;
  11038. switch (type) {
  11039. case Lines2D_1.NoCap:
  11040. {
  11041. // If the line is not close and we're computing border, we add the size to generate the edge border
  11042. if (!this.closed && border) {
  11043. vbsize = 4;
  11044. ibsize = 6;
  11045. }
  11046. else {
  11047. vbsize = ibsize = 0;
  11048. }
  11049. break;
  11050. }
  11051. case Lines2D_1.RoundCap:
  11052. {
  11053. if (border) {
  11054. vbsize = sd;
  11055. ibsize = (sd - 2) * 3;
  11056. }
  11057. else {
  11058. vbsize = (sd / 2) + 1;
  11059. ibsize = (sd / 2) * 3;
  11060. }
  11061. break;
  11062. }
  11063. case Lines2D_1.ArrowCap:
  11064. {
  11065. if (border) {
  11066. vbsize = 12;
  11067. ibsize = 24;
  11068. }
  11069. else {
  11070. vbsize = 3;
  11071. ibsize = 3;
  11072. }
  11073. break;
  11074. }
  11075. case Lines2D_1.TriangleCap:
  11076. {
  11077. if (border) {
  11078. vbsize = 6;
  11079. ibsize = 12;
  11080. }
  11081. else {
  11082. vbsize = 3;
  11083. ibsize = 3;
  11084. }
  11085. break;
  11086. }
  11087. case Lines2D_1.DiamondAnchorCap:
  11088. {
  11089. if (border) {
  11090. vbsize = 10;
  11091. ibsize = 24;
  11092. }
  11093. else {
  11094. vbsize = 5;
  11095. ibsize = 9;
  11096. }
  11097. break;
  11098. }
  11099. case Lines2D_1.SquareAnchorCap:
  11100. {
  11101. if (border) {
  11102. vbsize = 12;
  11103. ibsize = 30;
  11104. }
  11105. else {
  11106. vbsize = 4;
  11107. ibsize = 6;
  11108. }
  11109. break;
  11110. }
  11111. case Lines2D_1.RoundAnchorCap:
  11112. {
  11113. if (border) {
  11114. vbsize = sd * 2;
  11115. ibsize = (sd - 1) * 6;
  11116. }
  11117. else {
  11118. vbsize = sd + 1;
  11119. ibsize = (sd + 1) * 3;
  11120. }
  11121. break;
  11122. }
  11123. }
  11124. return { vbsize: vbsize * 2, ibsize: ibsize };
  11125. };
  11126. Lines2D.prototype._storeVertex = function (vb, baseOffset, index, basePos, rotation, vertex, contour) {
  11127. var c = Math.cos(rotation);
  11128. var s = Math.sin(rotation);
  11129. Lines2D_1._tpsV.x = (c * vertex.x) + (-s * vertex.y) + basePos.x;
  11130. Lines2D_1._tpsV.y = (s * vertex.x) + (c * vertex.y) + basePos.y;
  11131. var offset = baseOffset + (index * 2);
  11132. vb[offset + 0] = Lines2D_1._tpsV.x;
  11133. vb[offset + 1] = Lines2D_1._tpsV.y;
  11134. if (contour) {
  11135. contour.push(Lines2D_1._tpsV.x);
  11136. contour.push(Lines2D_1._tpsV.y);
  11137. }
  11138. this._updateMinMax(vb, offset);
  11139. return (baseOffset + index * 2) / 2;
  11140. };
  11141. Lines2D.prototype._storeIndex = function (ib, baseOffset, index, vertexIndex) {
  11142. ib[baseOffset + index] = vertexIndex;
  11143. };
  11144. Lines2D.prototype._buildCap = function (vb, vbi, ib, ibi, pos, thickness, borderThickness, type, capDir, contour) {
  11145. // 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
  11146. var sd = Lines2D_1._roundCapSubDiv;
  11147. var dir = new BABYLON.Vector2(1, 0);
  11148. var angle = Math.atan2(capDir.y, capDir.x) - Math.atan2(dir.y, dir.x);
  11149. var ht = thickness / 2;
  11150. var t = thickness;
  11151. var borderMode = borderThickness != null;
  11152. var bt = borderThickness;
  11153. switch (type) {
  11154. case Lines2D_1.NoCap:
  11155. if (borderMode && !this.closed) {
  11156. var vi = 0;
  11157. var ii = 0;
  11158. var v1 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, ht + bt), contour);
  11159. var v2 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(bt, ht + bt), contour);
  11160. var v3 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(bt, -(ht + bt)), contour);
  11161. var v4 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -(ht + bt)), contour);
  11162. this._storeIndex(ib, ibi, ii++, v1);
  11163. this._storeIndex(ib, ibi, ii++, v2);
  11164. this._storeIndex(ib, ibi, ii++, v3);
  11165. this._storeIndex(ib, ibi, ii++, v1);
  11166. this._storeIndex(ib, ibi, ii++, v3);
  11167. this._storeIndex(ib, ibi, ii++, v4);
  11168. }
  11169. break;
  11170. case Lines2D_1.ArrowCap:
  11171. ht *= 2;
  11172. case Lines2D_1.TriangleCap:
  11173. {
  11174. if (borderMode) {
  11175. var f = type === Lines2D_1.TriangleCap ? bt : Math.sqrt(bt * bt * 2);
  11176. var v1 = this._storeVertex(vb, vbi, 0, pos, angle, new BABYLON.Vector2(0, ht), null);
  11177. var v2 = this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(ht, 0), null);
  11178. var v3 = this._storeVertex(vb, vbi, 2, pos, angle, new BABYLON.Vector2(0, -ht), null);
  11179. var v4 = this._storeVertex(vb, vbi, 3, pos, angle, new BABYLON.Vector2(0, ht + f), contour);
  11180. var v5 = this._storeVertex(vb, vbi, 4, pos, angle, new BABYLON.Vector2(ht + f, 0), contour);
  11181. var v6 = this._storeVertex(vb, vbi, 5, pos, angle, new BABYLON.Vector2(0, -(ht + f)), contour);
  11182. var ii = 0;
  11183. this._storeIndex(ib, ibi, ii++, v1);
  11184. this._storeIndex(ib, ibi, ii++, v4);
  11185. this._storeIndex(ib, ibi, ii++, v5);
  11186. this._storeIndex(ib, ibi, ii++, v1);
  11187. this._storeIndex(ib, ibi, ii++, v5);
  11188. this._storeIndex(ib, ibi, ii++, v2);
  11189. this._storeIndex(ib, ibi, ii++, v6);
  11190. this._storeIndex(ib, ibi, ii++, v3);
  11191. this._storeIndex(ib, ibi, ii++, v2);
  11192. this._storeIndex(ib, ibi, ii++, v6);
  11193. this._storeIndex(ib, ibi, ii++, v2);
  11194. this._storeIndex(ib, ibi, ii++, v5);
  11195. if (type === Lines2D_1.ArrowCap) {
  11196. var rht = thickness / 2;
  11197. var v10 = this._storeVertex(vb, vbi, 9, pos, angle, new BABYLON.Vector2(0, -(rht + bt)), null);
  11198. var v12 = this._storeVertex(vb, vbi, 11, pos, angle, new BABYLON.Vector2(-bt, -(ht + f)), contour);
  11199. var v11 = this._storeVertex(vb, vbi, 10, pos, angle, new BABYLON.Vector2(-bt, -(rht + bt)), contour);
  11200. var v7 = this._storeVertex(vb, vbi, 6, pos, angle, new BABYLON.Vector2(0, rht + bt), null);
  11201. var v8 = this._storeVertex(vb, vbi, 7, pos, angle, new BABYLON.Vector2(-bt, rht + bt), contour);
  11202. var v9 = this._storeVertex(vb, vbi, 8, pos, angle, new BABYLON.Vector2(-bt, ht + f), contour);
  11203. this._storeIndex(ib, ibi, ii++, v7);
  11204. this._storeIndex(ib, ibi, ii++, v8);
  11205. this._storeIndex(ib, ibi, ii++, v9);
  11206. this._storeIndex(ib, ibi, ii++, v7);
  11207. this._storeIndex(ib, ibi, ii++, v9);
  11208. this._storeIndex(ib, ibi, ii++, v4);
  11209. this._storeIndex(ib, ibi, ii++, v10);
  11210. this._storeIndex(ib, ibi, ii++, v12);
  11211. this._storeIndex(ib, ibi, ii++, v11);
  11212. this._storeIndex(ib, ibi, ii++, v10);
  11213. this._storeIndex(ib, ibi, ii++, v6);
  11214. this._storeIndex(ib, ibi, ii++, v12);
  11215. }
  11216. }
  11217. else {
  11218. var v1 = this._storeVertex(vb, vbi, 0, pos, angle, new BABYLON.Vector2(0, ht), contour);
  11219. var v2 = this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(ht, 0), contour);
  11220. var v3 = this._storeVertex(vb, vbi, 2, pos, angle, new BABYLON.Vector2(0, -ht), contour);
  11221. this._storeIndex(ib, ibi, 0, v1);
  11222. this._storeIndex(ib, ibi, 1, v2);
  11223. this._storeIndex(ib, ibi, 2, v3);
  11224. }
  11225. break;
  11226. }
  11227. case Lines2D_1.RoundCap:
  11228. {
  11229. if (borderMode) {
  11230. var curA = -Math.PI / 2;
  11231. var incA = Math.PI / (sd / 2 - 1);
  11232. var ii = 0;
  11233. for (var i = 0; i < (sd / 2); i++) {
  11234. var v1 = this._storeVertex(vb, vbi, i * 2 + 0, pos, angle, new BABYLON.Vector2(Math.cos(curA) * ht, Math.sin(curA) * ht), null);
  11235. 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);
  11236. if (i > 0) {
  11237. this._storeIndex(ib, ibi, ii++, v1 - 2);
  11238. this._storeIndex(ib, ibi, ii++, v2 - 2);
  11239. this._storeIndex(ib, ibi, ii++, v2);
  11240. this._storeIndex(ib, ibi, ii++, v1 - 2);
  11241. this._storeIndex(ib, ibi, ii++, v2);
  11242. this._storeIndex(ib, ibi, ii++, v1);
  11243. }
  11244. curA += incA;
  11245. }
  11246. }
  11247. else {
  11248. var c = this._storeVertex(vb, vbi, 0, pos, angle, new BABYLON.Vector2(0, 0), null);
  11249. var curA = -Math.PI / 2;
  11250. var incA = Math.PI / (sd / 2 - 1);
  11251. this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(Math.cos(curA) * ht, Math.sin(curA) * ht), null);
  11252. curA += incA;
  11253. for (var i = 1; i < (sd / 2); i++) {
  11254. var v2 = this._storeVertex(vb, vbi, i + 1, pos, angle, new BABYLON.Vector2(Math.cos(curA) * ht, Math.sin(curA) * ht), contour);
  11255. this._storeIndex(ib, ibi, i * 3 + 0, c);
  11256. this._storeIndex(ib, ibi, i * 3 + 1, v2 - 1);
  11257. this._storeIndex(ib, ibi, i * 3 + 2, v2);
  11258. curA += incA;
  11259. }
  11260. }
  11261. break;
  11262. }
  11263. case Lines2D_1.SquareAnchorCap:
  11264. {
  11265. var vi = 0;
  11266. var c = borderMode ? null : contour;
  11267. var v1 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, t), c);
  11268. var v2 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2, t), c);
  11269. var v3 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2, -t), c);
  11270. var v4 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -t), c);
  11271. if (borderMode) {
  11272. var v5 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, ht + bt), null);
  11273. var v6 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, ht + bt), contour);
  11274. var v7 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, t + bt), contour);
  11275. var v8 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2 + bt, t + bt), contour);
  11276. var v9 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2 + bt, -(t + bt)), contour);
  11277. var v10 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, -(t + bt)), contour);
  11278. var v11 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, -(ht + bt)), contour);
  11279. var v12 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -(ht + bt)), null);
  11280. var ii = 0;
  11281. this._storeIndex(ib, ibi, ii++, v6);
  11282. this._storeIndex(ib, ibi, ii++, v1);
  11283. this._storeIndex(ib, ibi, ii++, v5);
  11284. this._storeIndex(ib, ibi, ii++, v6);
  11285. this._storeIndex(ib, ibi, ii++, v7);
  11286. this._storeIndex(ib, ibi, ii++, v1);
  11287. this._storeIndex(ib, ibi, ii++, v1);
  11288. this._storeIndex(ib, ibi, ii++, v7);
  11289. this._storeIndex(ib, ibi, ii++, v8);
  11290. this._storeIndex(ib, ibi, ii++, v1);
  11291. this._storeIndex(ib, ibi, ii++, v8);
  11292. this._storeIndex(ib, ibi, ii++, v2);
  11293. this._storeIndex(ib, ibi, ii++, v2);
  11294. this._storeIndex(ib, ibi, ii++, v8);
  11295. this._storeIndex(ib, ibi, ii++, v9);
  11296. this._storeIndex(ib, ibi, ii++, v2);
  11297. this._storeIndex(ib, ibi, ii++, v9);
  11298. this._storeIndex(ib, ibi, ii++, v3);
  11299. this._storeIndex(ib, ibi, ii++, v3);
  11300. this._storeIndex(ib, ibi, ii++, v9);
  11301. this._storeIndex(ib, ibi, ii++, v10);
  11302. this._storeIndex(ib, ibi, ii++, v3);
  11303. this._storeIndex(ib, ibi, ii++, v10);
  11304. this._storeIndex(ib, ibi, ii++, v4);
  11305. this._storeIndex(ib, ibi, ii++, v10);
  11306. this._storeIndex(ib, ibi, ii++, v11);
  11307. this._storeIndex(ib, ibi, ii++, v4);
  11308. this._storeIndex(ib, ibi, ii++, v11);
  11309. this._storeIndex(ib, ibi, ii++, v12);
  11310. this._storeIndex(ib, ibi, ii++, v4);
  11311. }
  11312. else {
  11313. this._storeIndex(ib, ibi, 0, v1);
  11314. this._storeIndex(ib, ibi, 1, v2);
  11315. this._storeIndex(ib, ibi, 2, v3);
  11316. this._storeIndex(ib, ibi, 3, v1);
  11317. this._storeIndex(ib, ibi, 4, v3);
  11318. this._storeIndex(ib, ibi, 5, v4);
  11319. }
  11320. break;
  11321. }
  11322. case Lines2D_1.RoundAnchorCap:
  11323. {
  11324. var cpos = Math.sqrt(t * t - ht * ht);
  11325. var center = new BABYLON.Vector2(cpos, 0);
  11326. var curA = BABYLON.Tools.ToRadians(-150);
  11327. var incA = BABYLON.Tools.ToRadians(300) / (sd - 1);
  11328. if (borderMode) {
  11329. var ii = 0;
  11330. for (var i = 0; i < sd; i++) {
  11331. var v1 = this._storeVertex(vb, vbi, i * 2 + 0, pos, angle, new BABYLON.Vector2(cpos + Math.cos(curA) * t, Math.sin(curA) * t), null);
  11332. 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);
  11333. if (i > 0) {
  11334. this._storeIndex(ib, ibi, ii++, v1 - 2);
  11335. this._storeIndex(ib, ibi, ii++, v2 - 2);
  11336. this._storeIndex(ib, ibi, ii++, v2);
  11337. this._storeIndex(ib, ibi, ii++, v1 - 2);
  11338. this._storeIndex(ib, ibi, ii++, v2);
  11339. this._storeIndex(ib, ibi, ii++, v1);
  11340. }
  11341. curA += incA;
  11342. }
  11343. }
  11344. else {
  11345. var c = this._storeVertex(vb, vbi, 0, pos, angle, center, null);
  11346. this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(cpos + Math.cos(curA) * t, Math.sin(curA) * t), null);
  11347. curA += incA;
  11348. for (var i = 1; i < sd; i++) {
  11349. var v2 = this._storeVertex(vb, vbi, i + 1, pos, angle, new BABYLON.Vector2(cpos + Math.cos(curA) * t, Math.sin(curA) * t), contour);
  11350. this._storeIndex(ib, ibi, i * 3 + 0, c);
  11351. this._storeIndex(ib, ibi, i * 3 + 1, v2 - 1);
  11352. this._storeIndex(ib, ibi, i * 3 + 2, v2);
  11353. curA += incA;
  11354. }
  11355. this._storeIndex(ib, ibi, sd * 3 + 0, c);
  11356. this._storeIndex(ib, ibi, sd * 3 + 1, c + 1);
  11357. this._storeIndex(ib, ibi, sd * 3 + 2, c + sd);
  11358. }
  11359. break;
  11360. }
  11361. case Lines2D_1.DiamondAnchorCap:
  11362. {
  11363. var vi = 0;
  11364. var c = borderMode ? null : contour;
  11365. var v1 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, ht), c);
  11366. var v2 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, t), c);
  11367. var v3 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht * 3, 0), c);
  11368. var v4 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, -t), c);
  11369. var v5 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -ht), c);
  11370. if (borderMode) {
  11371. var f = Math.sqrt(bt * bt * 2);
  11372. var v6 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-f, ht), contour);
  11373. var v7 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, t + f), contour);
  11374. var v8 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht * 3 + f, 0), contour);
  11375. var v9 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, -(t + f)), contour);
  11376. var v10 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-f, -ht), contour);
  11377. var ii = 0;
  11378. this._storeIndex(ib, ibi, ii++, v6);
  11379. this._storeIndex(ib, ibi, ii++, v7);
  11380. this._storeIndex(ib, ibi, ii++, v1);
  11381. this._storeIndex(ib, ibi, ii++, v1);
  11382. this._storeIndex(ib, ibi, ii++, v7);
  11383. this._storeIndex(ib, ibi, ii++, v2);
  11384. this._storeIndex(ib, ibi, ii++, v2);
  11385. this._storeIndex(ib, ibi, ii++, v7);
  11386. this._storeIndex(ib, ibi, ii++, v8);
  11387. this._storeIndex(ib, ibi, ii++, v2);
  11388. this._storeIndex(ib, ibi, ii++, v8);
  11389. this._storeIndex(ib, ibi, ii++, v3);
  11390. this._storeIndex(ib, ibi, ii++, v3);
  11391. this._storeIndex(ib, ibi, ii++, v8);
  11392. this._storeIndex(ib, ibi, ii++, v9);
  11393. this._storeIndex(ib, ibi, ii++, v3);
  11394. this._storeIndex(ib, ibi, ii++, v9);
  11395. this._storeIndex(ib, ibi, ii++, v4);
  11396. this._storeIndex(ib, ibi, ii++, v4);
  11397. this._storeIndex(ib, ibi, ii++, v9);
  11398. this._storeIndex(ib, ibi, ii++, v10);
  11399. this._storeIndex(ib, ibi, ii++, v4);
  11400. this._storeIndex(ib, ibi, ii++, v10);
  11401. this._storeIndex(ib, ibi, ii++, v5);
  11402. }
  11403. else {
  11404. this._storeIndex(ib, ibi, 0, v1);
  11405. this._storeIndex(ib, ibi, 1, v2);
  11406. this._storeIndex(ib, ibi, 2, v3);
  11407. this._storeIndex(ib, ibi, 3, v1);
  11408. this._storeIndex(ib, ibi, 4, v3);
  11409. this._storeIndex(ib, ibi, 5, v5);
  11410. this._storeIndex(ib, ibi, 6, v5);
  11411. this._storeIndex(ib, ibi, 7, v3);
  11412. this._storeIndex(ib, ibi, 8, v4);
  11413. }
  11414. break;
  11415. }
  11416. }
  11417. return null;
  11418. };
  11419. Lines2D.prototype._buildLine = function (vb, contour, ht, bt) {
  11420. var lineA = BABYLON.Vector2.Zero();
  11421. var lineB = BABYLON.Vector2.Zero();
  11422. var tangent = BABYLON.Vector2.Zero();
  11423. var miter = BABYLON.Vector2.Zero();
  11424. var curNormal = null;
  11425. if (this.closed) {
  11426. this.points.push(this.points[0]);
  11427. }
  11428. var total = this.points.length;
  11429. for (var i = 1; i < total; i++) {
  11430. var last = this.points[i - 1];
  11431. var cur = this.points[i];
  11432. var next = (i < (this.points.length - 1)) ? this.points[i + 1] : null;
  11433. this._direction(cur, last, lineA);
  11434. if (!curNormal) {
  11435. curNormal = BABYLON.Vector2.Zero();
  11436. this._perp(lineA, curNormal);
  11437. }
  11438. if (i === 1) {
  11439. this._store(vb, contour, 0, total, this.points[0], curNormal, ht, bt);
  11440. }
  11441. if (!next) {
  11442. this._perp(lineA, curNormal);
  11443. this._store(vb, contour, i, total, this.points[i], curNormal, ht, bt, i - 1);
  11444. }
  11445. else {
  11446. this._direction(next, cur, lineB);
  11447. var miterLen = this._computeMiter(tangent, miter, lineA, lineB);
  11448. this._store(vb, contour, i, total, this.points[i], miter, miterLen * ht, miterLen * bt, i - 1);
  11449. }
  11450. }
  11451. if (this.points.length > 2 && this.closed) {
  11452. var last2 = this.points[total - 2];
  11453. var cur2 = this.points[0];
  11454. var next2 = this.points[1];
  11455. this._direction(cur2, last2, lineA);
  11456. this._direction(next2, cur2, lineB);
  11457. this._perp(lineA, curNormal);
  11458. var miterLen2 = this._computeMiter(tangent, miter, lineA, lineB);
  11459. this._store(vb, null, 0, total, this.points[0], miter, miterLen2 * ht, miterLen2 * bt, 1);
  11460. // Patch contour
  11461. if (contour) {
  11462. var off = (bt == null) ? 0 : 4;
  11463. contour[0].x = vb[off + 0];
  11464. contour[0].y = vb[off + 1];
  11465. contour[1].x = vb[off + 2];
  11466. contour[1].y = vb[off + 3];
  11467. }
  11468. }
  11469. // Remove the point we added at the beginning
  11470. if (this.closed) {
  11471. this.points.splice(total - 1);
  11472. }
  11473. };
  11474. // Methods for Lines building
  11475. ///////////////////////////////////////////////////////////////////////////////////
  11476. Lines2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  11477. var renderCache = modelRenderCache;
  11478. var engine = this.owner.engine;
  11479. if (this._fillVB === null) {
  11480. this._computeLines2D();
  11481. }
  11482. // Need to create WebGL resources for fill part?
  11483. if (this.fill) {
  11484. renderCache.fillVB = engine.createVertexBuffer(this._fillVB);
  11485. renderCache.fillIB = engine.createIndexBuffer(this._fillIB);
  11486. renderCache.fillIndicesCount = this._fillIB.length;
  11487. // 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
  11488. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["position"], null, true);
  11489. if (ei) {
  11490. renderCache.effectFillInstanced = engine.createEffect("lines2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  11491. }
  11492. // Get the non instanced version
  11493. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["position"], null, false);
  11494. renderCache.effectFill = engine.createEffect("lines2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  11495. }
  11496. // Need to create WebGL resources for border part?
  11497. if (this.border) {
  11498. renderCache.borderVB = engine.createVertexBuffer(this._borderVB);
  11499. renderCache.borderIB = engine.createIndexBuffer(this._borderIB);
  11500. renderCache.borderIndicesCount = this._borderIB.length;
  11501. // 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
  11502. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["position"], null, true);
  11503. if (ei) {
  11504. renderCache.effectBorderInstanced = engine.createEffect({ vertex: "lines2d", fragment: "lines2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  11505. }
  11506. // Get the non instanced version
  11507. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["position"], null, false);
  11508. renderCache.effectBorder = engine.createEffect({ vertex: "lines2d", fragment: "lines2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  11509. }
  11510. this._fillVB = null;
  11511. this._fillIB = null;
  11512. this._borderVB = null;
  11513. this._borderIB = null;
  11514. return renderCache;
  11515. };
  11516. Lines2D.prototype._computeLines2D = function () {
  11517. // Init min/max because their being computed here
  11518. this._boundingMin = new BABYLON.Vector2(Number.MAX_VALUE, Number.MAX_VALUE);
  11519. this._boundingMax = new BABYLON.Vector2(Number.MIN_VALUE, Number.MIN_VALUE);
  11520. var contour = new Array();
  11521. var startCapContour = new Array();
  11522. var endCapContour = new Array();
  11523. // Need to create WebGL resources for fill part?
  11524. if (this.fill) {
  11525. var startCapInfo = this._getCapSize(this.startCap);
  11526. var endCapInfo = this._getCapSize(this.endCap);
  11527. var count = this.points.length;
  11528. var vbSize = (count * 2 * 2) + startCapInfo.vbsize + endCapInfo.vbsize;
  11529. this._fillVB = new Float32Array(vbSize);
  11530. var vb = this._fillVB;
  11531. var ht = this.fillThickness / 2;
  11532. var total = this.points.length;
  11533. this._buildLine(vb, this.border ? null : contour, ht);
  11534. var max = total * 2;
  11535. var triCount = (count - (this.closed ? 0 : 1)) * 2;
  11536. this._fillIB = new Float32Array(triCount * 3 + startCapInfo.ibsize + endCapInfo.ibsize);
  11537. var ib = this._fillIB;
  11538. for (var i = 0; i < triCount; i += 2) {
  11539. ib[i * 3 + 0] = i + 0;
  11540. ib[i * 3 + 1] = i + 1;
  11541. ib[i * 3 + 2] = (i + 2) % max;
  11542. ib[i * 3 + 3] = i + 1;
  11543. ib[i * 3 + 4] = (i + 3) % max;
  11544. ib[i * 3 + 5] = (i + 2) % max;
  11545. }
  11546. this._buildCap(vb, count * 2 * 2, ib, triCount * 3, this.points[0], this.fillThickness, null, this.startCap, Lines2D_1._startDir, this.border ? null : startCapContour);
  11547. 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);
  11548. }
  11549. // Need to create WebGL resources for border part?
  11550. if (this.border) {
  11551. var startCapInfo = this._getCapSize(this.startCap, true);
  11552. var endCapInfo = this._getCapSize(this.endCap, true);
  11553. var count = this.points.length;
  11554. var vbSize = (count * 2 * 2 * 2) + startCapInfo.vbsize + endCapInfo.vbsize;
  11555. this._borderVB = new Float32Array(vbSize);
  11556. var vb = this._borderVB;
  11557. var ht = this.fillThickness / 2;
  11558. var bt = this.borderThickness;
  11559. var total = this.points.length;
  11560. this._buildLine(vb, contour, ht, bt);
  11561. var max = total * 2 * 2;
  11562. var triCount = (count - (this.closed ? 0 : 1)) * 2 * 2;
  11563. this._borderIB = new Float32Array(triCount * 3 + startCapInfo.ibsize + endCapInfo.ibsize);
  11564. var ib = this._borderIB;
  11565. for (var i = 0; i < triCount; i += 4) {
  11566. ib[i * 3 + 0] = i + 0;
  11567. ib[i * 3 + 1] = i + 2;
  11568. ib[i * 3 + 2] = (i + 6) % max;
  11569. ib[i * 3 + 3] = i + 0;
  11570. ib[i * 3 + 4] = (i + 6) % max;
  11571. ib[i * 3 + 5] = (i + 4) % max;
  11572. ib[i * 3 + 6] = i + 3;
  11573. ib[i * 3 + 7] = i + 1;
  11574. ib[i * 3 + 8] = (i + 5) % max;
  11575. ib[i * 3 + 9] = i + 3;
  11576. ib[i * 3 + 10] = (i + 5) % max;
  11577. ib[i * 3 + 11] = (i + 7) % max;
  11578. }
  11579. this._buildCap(vb, count * 2 * 2 * 2, ib, triCount * 3, this.points[0], this.fillThickness, this.borderThickness, this.startCap, Lines2D_1._startDir, startCapContour);
  11580. 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);
  11581. }
  11582. this._contour = contour;
  11583. if (startCapContour.length > 0) {
  11584. var startCapTri = Earcut.earcut(startCapContour, null, 2);
  11585. this._startCapTriIndices = startCapTri;
  11586. this._startCapContour = startCapContour;
  11587. }
  11588. else {
  11589. this._startCapTriIndices = null;
  11590. this._startCapContour = null;
  11591. }
  11592. if (endCapContour.length > 0) {
  11593. var endCapTri = Earcut.earcut(endCapContour, null, 2);
  11594. this._endCapContour = endCapContour;
  11595. this._endCapTriIndices = endCapTri;
  11596. }
  11597. else {
  11598. this._endCapContour = null;
  11599. this._endCapTriIndices = null;
  11600. }
  11601. var bs = this._boundingMax.subtract(this._boundingMin);
  11602. this._size.width = bs.x;
  11603. this._size.height = bs.y;
  11604. };
  11605. Object.defineProperty(Lines2D.prototype, "size", {
  11606. get: function () {
  11607. if (this._size == null) {
  11608. this._computeLines2D();
  11609. }
  11610. return this._size;
  11611. },
  11612. enumerable: true,
  11613. configurable: true
  11614. });
  11615. Lines2D.prototype.createInstanceDataParts = function () {
  11616. var res = new Array();
  11617. if (this.border) {
  11618. res.push(new Lines2DInstanceData(BABYLON.Shape2D.SHAPE2D_BORDERPARTID));
  11619. }
  11620. if (this.fill) {
  11621. res.push(new Lines2DInstanceData(BABYLON.Shape2D.SHAPE2D_FILLPARTID));
  11622. }
  11623. return res;
  11624. };
  11625. Lines2D.prototype.applyActualScaleOnTransform = function () {
  11626. return true;
  11627. };
  11628. Lines2D.prototype.refreshInstanceDataPart = function (part) {
  11629. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  11630. return false;
  11631. }
  11632. if (part.id === BABYLON.Shape2D.SHAPE2D_BORDERPARTID) {
  11633. var d = part;
  11634. if (this.border instanceof BABYLON.GradientColorBrush2D) {
  11635. d.boundingMin = this.boundingMin;
  11636. d.boundingMax = this.boundingMax;
  11637. }
  11638. }
  11639. else if (part.id === BABYLON.Shape2D.SHAPE2D_FILLPARTID) {
  11640. var d = part;
  11641. if (this.fill instanceof BABYLON.GradientColorBrush2D) {
  11642. d.boundingMin = this.boundingMin;
  11643. d.boundingMax = this.boundingMax;
  11644. }
  11645. }
  11646. return true;
  11647. };
  11648. return Lines2D;
  11649. }(BABYLON.Shape2D));
  11650. Lines2D._prevA = BABYLON.Vector2.Zero();
  11651. Lines2D._prevB = BABYLON.Vector2.Zero();
  11652. Lines2D._curA = BABYLON.Vector2.Zero();
  11653. Lines2D._curB = BABYLON.Vector2.Zero();
  11654. Lines2D._miterTps = BABYLON.Vector2.Zero();
  11655. Lines2D._startDir = BABYLON.Vector2.Zero();
  11656. Lines2D._endDir = BABYLON.Vector2.Zero();
  11657. Lines2D._tpsV = BABYLON.Vector2.Zero();
  11658. Lines2D._noCap = 0;
  11659. Lines2D._roundCap = 1;
  11660. Lines2D._triangleCap = 2;
  11661. Lines2D._squareAnchorCap = 3;
  11662. Lines2D._roundAnchorCap = 4;
  11663. Lines2D._diamondAnchorCap = 5;
  11664. Lines2D._arrowCap = 6;
  11665. Lines2D._roundCapSubDiv = 36;
  11666. __decorate([
  11667. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 1, function (pi) { return Lines2D_1.pointsProperty = pi; })
  11668. ], Lines2D.prototype, "points", null);
  11669. __decorate([
  11670. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 2, function (pi) { return Lines2D_1.fillThicknessProperty = pi; })
  11671. ], Lines2D.prototype, "fillThickness", null);
  11672. __decorate([
  11673. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 3, function (pi) { return Lines2D_1.closedProperty = pi; })
  11674. ], Lines2D.prototype, "closed", null);
  11675. __decorate([
  11676. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 4, function (pi) { return Lines2D_1.startCapProperty = pi; })
  11677. ], Lines2D.prototype, "startCap", null);
  11678. __decorate([
  11679. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 5, function (pi) { return Lines2D_1.endCapProperty = pi; })
  11680. ], Lines2D.prototype, "endCap", null);
  11681. Lines2D = Lines2D_1 = __decorate([
  11682. BABYLON.className("Lines2D", "BABYLON")
  11683. ], Lines2D);
  11684. BABYLON.Lines2D = Lines2D;
  11685. var Lines2D_1;
  11686. })(BABYLON || (BABYLON = {}));
  11687. var __extends = (this && this.__extends) || function (d, b) {
  11688. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  11689. function __() { this.constructor = d; }
  11690. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  11691. };
  11692. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  11693. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  11694. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  11695. 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;
  11696. return c > 3 && r && Object.defineProperty(target, key, r), r;
  11697. };
  11698. var BABYLON;
  11699. (function (BABYLON) {
  11700. // This class contains data that lifetime is bounding to the Babylon Engine object
  11701. var Canvas2DEngineBoundData = (function () {
  11702. function Canvas2DEngineBoundData() {
  11703. this._modelCache = new BABYLON.StringDictionary();
  11704. }
  11705. Canvas2DEngineBoundData.prototype.GetOrAddModelCache = function (key, factory) {
  11706. return this._modelCache.getOrAddWithFactory(key, factory);
  11707. };
  11708. Canvas2DEngineBoundData.prototype.DisposeModelRenderCache = function (modelRenderCache) {
  11709. if (!modelRenderCache.isDisposed) {
  11710. return false;
  11711. }
  11712. this._modelCache.remove(modelRenderCache.modelKey);
  11713. return true;
  11714. };
  11715. return Canvas2DEngineBoundData;
  11716. }());
  11717. BABYLON.Canvas2DEngineBoundData = Canvas2DEngineBoundData;
  11718. var Canvas2D = Canvas2D_1 = (function (_super) {
  11719. __extends(Canvas2D, _super);
  11720. function Canvas2D(scene, settings) {
  11721. var _this = _super.call(this, settings) || this;
  11722. /**
  11723. * 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.
  11724. * Beware that you have to take under consideration the origin in your calculations! Good luck!
  11725. */
  11726. _this.worldSpaceToNodeLocal = function (worldPos) {
  11727. var node = _this._worldSpaceNode;
  11728. if (!node) {
  11729. return;
  11730. }
  11731. var mtx = node.getWorldMatrix().clone();
  11732. mtx.invert();
  11733. var v = BABYLON.Vector3.TransformCoordinates(worldPos, mtx);
  11734. var res = new BABYLON.Vector2(v.x, v.y);
  11735. var size = _this.actualSize;
  11736. res.x += size.width * 0.5; // res is centered, make it relative to bottom/left
  11737. res.y += size.height * 0.5;
  11738. return res;
  11739. };
  11740. /**
  11741. * 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
  11742. */
  11743. _this.worldSpaceCacheChanged = function () {
  11744. var plane = _this.worldSpaceCanvasNode;
  11745. var vd = BABYLON.VertexData.ExtractFromMesh(plane); //new VertexData();
  11746. vd.uvs = new Float32Array(8);
  11747. var material = plane.material;
  11748. var tex = _this._renderableData._cacheTexture;
  11749. if (material.diffuseTexture !== tex) {
  11750. material.diffuseTexture = tex;
  11751. tex.hasAlpha = true;
  11752. }
  11753. var nodeuv = _this._renderableData._cacheNodeUVs;
  11754. for (var i = 0; i < 4; i++) {
  11755. vd.uvs[i * 2 + 0] = nodeuv[i].x;
  11756. vd.uvs[i * 2 + 1] = nodeuv[i].y;
  11757. }
  11758. vd.applyToMesh(plane);
  11759. };
  11760. _this._notifDebugMode = false;
  11761. /**
  11762. * Instanced Array will be create if there's at least this number of parts/prim that can fit into it
  11763. */
  11764. _this.minPartCountToUseInstancedArray = 5;
  11765. _this._mapCounter = 0;
  11766. _this._drawCallsOpaqueCounter = new BABYLON.PerfCounter();
  11767. _this._drawCallsAlphaTestCounter = new BABYLON.PerfCounter();
  11768. _this._drawCallsTransparentCounter = new BABYLON.PerfCounter();
  11769. _this._groupRenderCounter = new BABYLON.PerfCounter();
  11770. _this._updateTransparentDataCounter = new BABYLON.PerfCounter();
  11771. _this._cachedGroupRenderCounter = new BABYLON.PerfCounter();
  11772. _this._updateCachedStateCounter = new BABYLON.PerfCounter();
  11773. _this._updateLayoutCounter = new BABYLON.PerfCounter();
  11774. _this._updatePositioningCounter = new BABYLON.PerfCounter();
  11775. _this._updateLocalTransformCounter = new BABYLON.PerfCounter();
  11776. _this._updateGlobalTransformCounter = new BABYLON.PerfCounter();
  11777. _this._boundingInfoRecomputeCounter = new BABYLON.PerfCounter();
  11778. _this._uid = null;
  11779. _this._cachedCanvasGroup = null;
  11780. _this._renderingGroupObserver = null;
  11781. _this._beforeRenderObserver = null;
  11782. _this._afterRenderObserver = null;
  11783. _this._profileInfoText = null;
  11784. BABYLON.Prim2DBase._isCanvasInit = false;
  11785. if (!settings) {
  11786. settings = {};
  11787. }
  11788. if (_this._cachingStrategy !== Canvas2D_1.CACHESTRATEGY_TOPLEVELGROUPS) {
  11789. _this._background = new BABYLON.Rectangle2D({ parent: _this, id: "###CANVAS BACKGROUND###", size: settings.size }); //TODO CHECK when size is null
  11790. _this._background.zOrder = 1.0;
  11791. _this._background.isPickable = false;
  11792. _this._background.origin = BABYLON.Vector2.Zero();
  11793. _this._background.levelVisible = false;
  11794. if (settings.backgroundRoundRadius != null) {
  11795. _this.backgroundRoundRadius = settings.backgroundRoundRadius;
  11796. }
  11797. if (settings.backgroundBorder != null) {
  11798. if (typeof (settings.backgroundBorder) === "string") {
  11799. _this.backgroundBorder = Canvas2D_1.GetBrushFromString(settings.backgroundBorder);
  11800. }
  11801. else {
  11802. _this.backgroundBorder = settings.backgroundBorder;
  11803. }
  11804. }
  11805. if (settings.backgroundBorderThickNess != null) {
  11806. _this.backgroundBorderThickness = settings.backgroundBorderThickNess;
  11807. }
  11808. if (settings.backgroundFill != null) {
  11809. if (typeof (settings.backgroundFill) === "string") {
  11810. _this.backgroundFill = Canvas2D_1.GetBrushFromString(settings.backgroundFill);
  11811. }
  11812. else {
  11813. _this.backgroundFill = settings.backgroundFill;
  11814. }
  11815. }
  11816. // Put a handler to resize the background whenever the canvas is resizing
  11817. _this.propertyChanged.add(function (e, s) {
  11818. if (e.propertyName === "size") {
  11819. _this._background.size = _this.size;
  11820. }
  11821. }, BABYLON.Group2D.sizeProperty.flagId);
  11822. _this._background._patchHierarchy(_this);
  11823. }
  11824. var engine = scene.getEngine();
  11825. _this.__engineData = engine.getOrAddExternalDataWithFactory("__BJSCANVAS2D__", function (k) { return new Canvas2DEngineBoundData(); });
  11826. _this._primPointerInfo = new BABYLON.PrimitivePointerInfo();
  11827. _this._capturedPointers = new BABYLON.StringDictionary();
  11828. _this._pickStartingPosition = BABYLON.Vector2.Zero();
  11829. _this._hierarchyLevelMaxSiblingCount = 50;
  11830. _this._hierarchyDepth = 0;
  11831. _this._zOrder = 0;
  11832. _this._zMax = 1;
  11833. _this._scene = scene;
  11834. _this._engine = engine;
  11835. _this._renderingSize = new BABYLON.Size(0, 0);
  11836. _this._designSize = settings.designSize || null;
  11837. _this._designUseHorizAxis = settings.designUseHorizAxis === true;
  11838. _this._trackedGroups = new Array();
  11839. _this._maxAdaptiveWorldSpaceCanvasSize = null;
  11840. _this._groupCacheMaps = new BABYLON.StringDictionary();
  11841. _this._patchHierarchy(_this);
  11842. var enableInteraction = (settings.enableInteraction == null) ? true : settings.enableInteraction;
  11843. _this._fitRenderingDevice = !settings.size;
  11844. if (!settings.size) {
  11845. settings.size = new BABYLON.Size(engine.getRenderWidth(), engine.getRenderHeight());
  11846. }
  11847. // Register scene dispose to also dispose the canvas when it'll happens
  11848. scene.onDisposeObservable.add(function (d, s) {
  11849. _this.dispose();
  11850. });
  11851. if (_this._isScreenSpace) {
  11852. if (settings.renderingPhase) {
  11853. if (!settings.renderingPhase.camera || settings.renderingPhase.renderingGroupID == null) {
  11854. throw Error("You have to specify a valid camera and renderingGroup");
  11855. }
  11856. _this._renderingGroupObserver = _this._scene.onRenderingGroupObservable.add(function (e, s) {
  11857. if ((_this._scene.activeCamera === settings.renderingPhase.camera) && (e.renderStage === BABYLON.RenderingGroupInfo.STAGE_POSTTRANSPARENT)) {
  11858. _this._engine.clear(null, false, true, true);
  11859. _this._render();
  11860. }
  11861. }, Math.pow(2, settings.renderingPhase.renderingGroupID));
  11862. }
  11863. else {
  11864. _this._afterRenderObserver = _this._scene.onAfterRenderObservable.add(function (d, s) {
  11865. _this._engine.clear(null, false, true, true);
  11866. _this._render();
  11867. });
  11868. }
  11869. }
  11870. else {
  11871. _this._beforeRenderObserver = _this._scene.onBeforeRenderObservable.add(function (d, s) {
  11872. _this._render();
  11873. });
  11874. }
  11875. _this._supprtInstancedArray = _this._engine.getCaps().instancedArrays !== null;
  11876. //this._supprtInstancedArray = false; // TODO REMOVE!!!
  11877. _this._setupInteraction(enableInteraction);
  11878. // Register this instance
  11879. Canvas2D_1._INSTANCES.push(_this);
  11880. return _this;
  11881. }
  11882. Object.defineProperty(Canvas2D.prototype, "drawCallsOpaqueCounter", {
  11883. get: function () {
  11884. return this._drawCallsOpaqueCounter;
  11885. },
  11886. enumerable: true,
  11887. configurable: true
  11888. });
  11889. Object.defineProperty(Canvas2D.prototype, "drawCallsAlphaTestCounter", {
  11890. get: function () {
  11891. return this._drawCallsAlphaTestCounter;
  11892. },
  11893. enumerable: true,
  11894. configurable: true
  11895. });
  11896. Object.defineProperty(Canvas2D.prototype, "drawCallsTransparentCounter", {
  11897. get: function () {
  11898. return this._drawCallsTransparentCounter;
  11899. },
  11900. enumerable: true,
  11901. configurable: true
  11902. });
  11903. Object.defineProperty(Canvas2D.prototype, "groupRenderCounter", {
  11904. get: function () {
  11905. return this._groupRenderCounter;
  11906. },
  11907. enumerable: true,
  11908. configurable: true
  11909. });
  11910. Object.defineProperty(Canvas2D.prototype, "updateTransparentDataCounter", {
  11911. get: function () {
  11912. return this._updateTransparentDataCounter;
  11913. },
  11914. enumerable: true,
  11915. configurable: true
  11916. });
  11917. Object.defineProperty(Canvas2D.prototype, "cachedGroupRenderCounter", {
  11918. get: function () {
  11919. return this._cachedGroupRenderCounter;
  11920. },
  11921. enumerable: true,
  11922. configurable: true
  11923. });
  11924. Object.defineProperty(Canvas2D.prototype, "updateCachedStateCounter", {
  11925. get: function () {
  11926. return this._updateCachedStateCounter;
  11927. },
  11928. enumerable: true,
  11929. configurable: true
  11930. });
  11931. Object.defineProperty(Canvas2D.prototype, "updateLayoutCounter", {
  11932. get: function () {
  11933. return this._updateLayoutCounter;
  11934. },
  11935. enumerable: true,
  11936. configurable: true
  11937. });
  11938. Object.defineProperty(Canvas2D.prototype, "updatePositioningCounter", {
  11939. get: function () {
  11940. return this._updatePositioningCounter;
  11941. },
  11942. enumerable: true,
  11943. configurable: true
  11944. });
  11945. Object.defineProperty(Canvas2D.prototype, "updateLocalTransformCounter", {
  11946. get: function () {
  11947. return this._updateLocalTransformCounter;
  11948. },
  11949. enumerable: true,
  11950. configurable: true
  11951. });
  11952. Object.defineProperty(Canvas2D.prototype, "updateGlobalTransformCounter", {
  11953. get: function () {
  11954. return this._updateGlobalTransformCounter;
  11955. },
  11956. enumerable: true,
  11957. configurable: true
  11958. });
  11959. Object.defineProperty(Canvas2D.prototype, "boundingInfoRecomputeCounter", {
  11960. get: function () {
  11961. return this._boundingInfoRecomputeCounter;
  11962. },
  11963. enumerable: true,
  11964. configurable: true
  11965. });
  11966. Object.defineProperty(Canvas2D, "instances", {
  11967. get: function () {
  11968. return Canvas2D_1._INSTANCES;
  11969. },
  11970. enumerable: true,
  11971. configurable: true
  11972. });
  11973. Canvas2D.prototype._canvasPreInit = function (settings) {
  11974. var cachingStrategy = (settings.cachingStrategy == null) ? Canvas2D_1.CACHESTRATEGY_DONTCACHE : settings.cachingStrategy;
  11975. this._cachingStrategy = cachingStrategy;
  11976. this._isScreenSpace = (settings.isScreenSpace == null) ? true : settings.isScreenSpace;
  11977. };
  11978. Canvas2D.prototype._setupInteraction = function (enable) {
  11979. var _this = this;
  11980. // No change detection
  11981. if (enable === this._interactionEnabled) {
  11982. return;
  11983. }
  11984. // Set the new state
  11985. this._interactionEnabled = enable;
  11986. // ScreenSpace mode
  11987. if (this._isScreenSpace) {
  11988. // Disable interaction
  11989. if (!enable) {
  11990. if (this._scenePrePointerObserver) {
  11991. this.scene.onPrePointerObservable.remove(this._scenePrePointerObserver);
  11992. this._scenePrePointerObserver = null;
  11993. }
  11994. return;
  11995. }
  11996. // Enable Interaction
  11997. // Register the observable
  11998. this._scenePrePointerObserver = this.scene.onPrePointerObservable.add(function (e, s) {
  11999. if (_this.isVisible === false) {
  12000. return;
  12001. }
  12002. var hs = 1 / _this.engine.getHardwareScalingLevel();
  12003. var localPos = e.localPosition.multiplyByFloats(hs, hs);
  12004. _this._handlePointerEventForInteraction(e, localPos, s);
  12005. });
  12006. }
  12007. else {
  12008. var scene = this.scene;
  12009. if (enable) {
  12010. scene.constantlyUpdateMeshUnderPointer = true;
  12011. this._scenePointerObserver = scene.onPointerObservable.add(function (e, s) {
  12012. if (_this.isVisible === false) {
  12013. return;
  12014. }
  12015. if (e.pickInfo.hit && e.pickInfo.pickedMesh === _this._worldSpaceNode && _this.worldSpaceToNodeLocal) {
  12016. var localPos = _this.worldSpaceToNodeLocal(e.pickInfo.pickedPoint);
  12017. _this._handlePointerEventForInteraction(e, localPos, s);
  12018. }
  12019. });
  12020. }
  12021. else {
  12022. if (this._scenePointerObserver) {
  12023. this.scene.onPointerObservable.remove(this._scenePointerObserver);
  12024. this._scenePointerObserver = null;
  12025. }
  12026. }
  12027. }
  12028. };
  12029. /**
  12030. * Internal method, you should use the Prim2DBase version instead
  12031. */
  12032. Canvas2D.prototype._setPointerCapture = function (pointerId, primitive) {
  12033. if (this.isPointerCaptured(pointerId)) {
  12034. return false;
  12035. }
  12036. // Try to capture the pointer on the HTML side
  12037. try {
  12038. this.engine.getRenderingCanvas().setPointerCapture(pointerId);
  12039. }
  12040. catch (e) {
  12041. }
  12042. this._primPointerInfo.updateRelatedTarget(primitive, BABYLON.Vector2.Zero());
  12043. this._bubbleNotifyPrimPointerObserver(primitive, BABYLON.PrimitivePointerInfo.PointerGotCapture, null);
  12044. this._capturedPointers.add(pointerId.toString(), primitive);
  12045. return true;
  12046. };
  12047. /**
  12048. * Internal method, you should use the Prim2DBase version instead
  12049. */
  12050. Canvas2D.prototype._releasePointerCapture = function (pointerId, primitive) {
  12051. if (this._capturedPointers.get(pointerId.toString()) !== primitive) {
  12052. return false;
  12053. }
  12054. // Try to release the pointer on the HTML side
  12055. try {
  12056. this.engine.getRenderingCanvas().releasePointerCapture(pointerId);
  12057. }
  12058. catch (e) {
  12059. }
  12060. this._primPointerInfo.updateRelatedTarget(primitive, BABYLON.Vector2.Zero());
  12061. this._bubbleNotifyPrimPointerObserver(primitive, BABYLON.PrimitivePointerInfo.PointerLostCapture, null);
  12062. this._capturedPointers.remove(pointerId.toString());
  12063. return true;
  12064. };
  12065. /**
  12066. * Determine if the given pointer is captured or not
  12067. * @param pointerId the Id of the pointer
  12068. * @return true if it's captured, false otherwise
  12069. */
  12070. Canvas2D.prototype.isPointerCaptured = function (pointerId) {
  12071. return this._capturedPointers.contains(pointerId.toString());
  12072. };
  12073. Canvas2D.prototype.getCapturedPrimitive = function (pointerId) {
  12074. // Avoid unnecessary lookup
  12075. if (this._capturedPointers.count === 0) {
  12076. return null;
  12077. }
  12078. return this._capturedPointers.get(pointerId.toString());
  12079. };
  12080. Canvas2D.prototype._handlePointerEventForInteraction = function (eventData, localPosition, eventState) {
  12081. // Dispose check
  12082. if (this.isDisposed) {
  12083. return;
  12084. }
  12085. // Update the this._primPointerInfo structure we'll send to observers using the PointerEvent data
  12086. if (!this._updatePointerInfo(eventData, localPosition)) {
  12087. return;
  12088. }
  12089. var capturedPrim = this.getCapturedPrimitive(this._primPointerInfo.pointerId);
  12090. // 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.
  12091. // 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.
  12092. this._updateIntersectionList(this._primPointerInfo.canvasPointerPos, capturedPrim !== null, true);
  12093. // 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
  12094. this._updateOverStatus(true);
  12095. // Check if we have nothing to raise
  12096. if (!this._actualOverPrimitive && !capturedPrim) {
  12097. return;
  12098. }
  12099. // Update the relatedTarget info with the over primitive or the captured one (if any)
  12100. var targetPrim = capturedPrim || this._actualOverPrimitive.prim;
  12101. var targetPointerPos = capturedPrim ? this._primPointerInfo.canvasPointerPos.subtract(new BABYLON.Vector2(targetPrim.globalTransform.m[12], targetPrim.globalTransform.m[13])) : this._actualOverPrimitive.intersectionLocation;
  12102. this._primPointerInfo.updateRelatedTarget(targetPrim, targetPointerPos);
  12103. // Analyze the pointer event type and fire proper events on the primitive
  12104. var skip = false;
  12105. if (eventData.type === BABYLON.PointerEventTypes.POINTERWHEEL) {
  12106. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerMouseWheel, eventData);
  12107. }
  12108. else if (eventData.type === BABYLON.PointerEventTypes.POINTERMOVE) {
  12109. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerMove, eventData);
  12110. }
  12111. else if (eventData.type === BABYLON.PointerEventTypes.POINTERDOWN) {
  12112. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerDown, eventData);
  12113. }
  12114. else if (eventData.type === BABYLON.PointerEventTypes.POINTERUP) {
  12115. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerUp, eventData);
  12116. }
  12117. eventState.skipNextObservers = skip;
  12118. };
  12119. Canvas2D.prototype._updatePointerInfo = function (eventData, localPosition) {
  12120. var s = this.scale;
  12121. var pii = this._primPointerInfo;
  12122. pii.cancelBubble = false;
  12123. if (!pii.canvasPointerPos) {
  12124. pii.canvasPointerPos = BABYLON.Vector2.Zero();
  12125. }
  12126. var camera = this._scene.cameraToUseForPointers || this._scene.activeCamera;
  12127. if (!camera || !camera.viewport) {
  12128. return false;
  12129. }
  12130. var engine = this._scene.getEngine();
  12131. if (this._isScreenSpace) {
  12132. var cameraViewport = camera.viewport;
  12133. var viewport = cameraViewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight());
  12134. // Moving coordinates to local viewport world
  12135. var x = localPosition.x - viewport.x;
  12136. var y = localPosition.y - viewport.y;
  12137. pii.canvasPointerPos.x = (x - this.actualPosition.x) / s;
  12138. pii.canvasPointerPos.y = (engine.getRenderHeight() - y - this.actualPosition.y) / s;
  12139. }
  12140. else {
  12141. pii.canvasPointerPos.x = localPosition.x / s;
  12142. pii.canvasPointerPos.y = localPosition.y / s;
  12143. }
  12144. //console.log(`UpdatePointerInfo for ${this.id}, X:${pii.canvasPointerPos.x}, Y:${pii.canvasPointerPos.y}`);
  12145. pii.mouseWheelDelta = 0;
  12146. if (eventData.type === BABYLON.PointerEventTypes.POINTERWHEEL) {
  12147. var event = eventData.event;
  12148. if (event.wheelDelta) {
  12149. pii.mouseWheelDelta = event.wheelDelta / (BABYLON.PrimitivePointerInfo.MouseWheelPrecision * 40);
  12150. }
  12151. else if (event.detail) {
  12152. pii.mouseWheelDelta = -event.detail / BABYLON.PrimitivePointerInfo.MouseWheelPrecision;
  12153. }
  12154. }
  12155. else {
  12156. var pe = eventData.event;
  12157. pii.ctrlKey = pe.ctrlKey;
  12158. pii.altKey = pe.altKey;
  12159. pii.shiftKey = pe.shiftKey;
  12160. pii.metaKey = pe.metaKey;
  12161. pii.button = pe.button;
  12162. pii.buttons = pe.buttons;
  12163. pii.pointerId = pe.pointerId;
  12164. pii.width = pe.width;
  12165. pii.height = pe.height;
  12166. pii.presssure = pe.pressure;
  12167. pii.tilt.x = pe.tiltX;
  12168. pii.tilt.y = pe.tiltY;
  12169. pii.isCaptured = this.getCapturedPrimitive(pe.pointerId) !== null;
  12170. }
  12171. return true;
  12172. };
  12173. Canvas2D.prototype._updateIntersectionList = function (mouseLocalPos, isCapture, force) {
  12174. if (!force && (this.scene.getRenderId() === this._intersectionRenderId)) {
  12175. return;
  12176. }
  12177. // 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
  12178. if (!this._globalTransform) {
  12179. this.updateCachedStates(true);
  12180. }
  12181. var ii = Canvas2D_1._interInfo;
  12182. ii.pickPosition.x = mouseLocalPos.x;
  12183. ii.pickPosition.y = mouseLocalPos.y;
  12184. ii.findFirstOnly = false;
  12185. // Fast rejection: test if the mouse pointer is outside the canvas's bounding Info
  12186. if (!isCapture && !this.levelBoundingInfo.doesIntersect(ii.pickPosition)) {
  12187. // Reset intersection info as we don't hit anything
  12188. ii.intersectedPrimitives = new Array();
  12189. ii.topMostIntersectedPrimitive = null;
  12190. }
  12191. else {
  12192. // The pointer is inside the Canvas, do an intersection test
  12193. this.intersect(ii);
  12194. }
  12195. {
  12196. // Update prev/actual intersection info, fire "overPrim" property change if needed
  12197. this._previousIntersectionList = this._actualIntersectionList;
  12198. this._actualIntersectionList = ii.intersectedPrimitives;
  12199. this._previousOverPrimitive = this._actualOverPrimitive;
  12200. this._actualOverPrimitive = ii.topMostIntersectedPrimitive;
  12201. var prev = (this._previousOverPrimitive != null) ? this._previousOverPrimitive.prim : null;
  12202. var actual = (this._actualOverPrimitive != null) ? this._actualOverPrimitive.prim : null;
  12203. if (prev !== actual) {
  12204. this.onPropertyChanged("overPrim", this._previousOverPrimitive ? this._previousOverPrimitive.prim : null, this._actualOverPrimitive ? this._actualOverPrimitive.prim : null);
  12205. }
  12206. }
  12207. this._intersectionRenderId = this.scene.getRenderId();
  12208. };
  12209. // Based on the previousIntersectionList and the actualInstersectionList we can determined which primitives are being hover state or loosing it
  12210. Canvas2D.prototype._updateOverStatus = function (force) {
  12211. if ((!force && (this.scene.getRenderId() === this._hoverStatusRenderId)) || !this._previousIntersectionList || !this._actualIntersectionList) {
  12212. return;
  12213. }
  12214. // Detect a change of over
  12215. var prevPrim = this._previousOverPrimitive ? this._previousOverPrimitive.prim : null;
  12216. var actualPrim = this._actualOverPrimitive ? this._actualOverPrimitive.prim : null;
  12217. if (prevPrim !== actualPrim) {
  12218. // Detect if the current pointer is captured, only fire event if they belong to the capture primitive
  12219. var capturedPrim = this.getCapturedPrimitive(this._primPointerInfo.pointerId);
  12220. // Notify the previous "over" prim that the pointer is no longer over it
  12221. if ((capturedPrim && capturedPrim === prevPrim) || (!capturedPrim && prevPrim && !prevPrim.isDisposed)) {
  12222. this._primPointerInfo.updateRelatedTarget(prevPrim, this._previousOverPrimitive.intersectionLocation);
  12223. this._bubbleNotifyPrimPointerObserver(prevPrim, BABYLON.PrimitivePointerInfo.PointerOut, null);
  12224. }
  12225. // Notify the new "over" prim that the pointer is over it
  12226. if ((capturedPrim && capturedPrim === actualPrim) || (!capturedPrim && actualPrim)) {
  12227. this._primPointerInfo.updateRelatedTarget(actualPrim, this._actualOverPrimitive.intersectionLocation);
  12228. this._bubbleNotifyPrimPointerObserver(actualPrim, BABYLON.PrimitivePointerInfo.PointerOver, null);
  12229. }
  12230. }
  12231. this._hoverStatusRenderId = this.scene.getRenderId();
  12232. };
  12233. Canvas2D.prototype._updatePrimPointerPos = function (prim) {
  12234. if (this._primPointerInfo.isCaptured) {
  12235. this._primPointerInfo.primitivePointerPos = this._primPointerInfo.relatedTargetPointerPos;
  12236. }
  12237. else {
  12238. for (var _i = 0, _a = this._actualIntersectionList; _i < _a.length; _i++) {
  12239. var pii = _a[_i];
  12240. if (pii.prim === prim) {
  12241. this._primPointerInfo.primitivePointerPos = pii.intersectionLocation;
  12242. return;
  12243. }
  12244. }
  12245. }
  12246. };
  12247. Canvas2D.prototype._debugExecObserver = function (prim, mask) {
  12248. if (!this._notifDebugMode) {
  12249. return;
  12250. }
  12251. var debug = "";
  12252. for (var i = 0; i < prim.hierarchyDepth; i++) {
  12253. debug += " ";
  12254. }
  12255. var pii = this._primPointerInfo;
  12256. 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();
  12257. console.log(debug);
  12258. };
  12259. Canvas2D.prototype._bubbleNotifyPrimPointerObserver = function (prim, mask, eventData) {
  12260. var ppi = this._primPointerInfo;
  12261. var event = eventData ? eventData.event : null;
  12262. // In case of PointerOver/Out we will first notify the parent with PointerEnter/Leave
  12263. if ((mask & (BABYLON.PrimitivePointerInfo.PointerOver | BABYLON.PrimitivePointerInfo.PointerOut)) !== 0) {
  12264. this._notifParents(prim, mask);
  12265. }
  12266. var bubbleCancelled = false;
  12267. var cur = prim;
  12268. while (cur && !cur.isDisposed) {
  12269. // Only trigger the observers if the primitive is intersected (except for out)
  12270. if (!bubbleCancelled) {
  12271. this._updatePrimPointerPos(cur);
  12272. // Exec the observers
  12273. this._debugExecObserver(cur, mask);
  12274. if (!cur._pointerEventObservable.notifyObservers(ppi, mask) && eventData instanceof BABYLON.PointerInfoPre) {
  12275. eventData.skipOnPointerObservable = true;
  12276. return false;
  12277. }
  12278. this._triggerActionManager(cur, ppi, mask, event);
  12279. // Bubble canceled? If we're not executing PointerOver or PointerOut, quit immediately
  12280. // If it's PointerOver/Out we have to trigger PointerEnter/Leave no matter what
  12281. if (ppi.cancelBubble) {
  12282. if ((mask & (BABYLON.PrimitivePointerInfo.PointerOver | BABYLON.PrimitivePointerInfo.PointerOut)) === 0) {
  12283. return false;
  12284. }
  12285. // We're dealing with PointerOver/Out, let's keep looping to fire PointerEnter/Leave, but not Over/Out anymore
  12286. bubbleCancelled = true;
  12287. }
  12288. }
  12289. // If bubble is cancel we didn't update the Primitive Pointer Pos yet, let's do it
  12290. if (bubbleCancelled) {
  12291. this._updatePrimPointerPos(cur);
  12292. }
  12293. // 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
  12294. //// Trigger a PointerEnter corresponding to the PointerOver
  12295. //if (mask === PrimitivePointerInfo.PointerOver) {
  12296. // this._debugExecObserver(cur, PrimitivePointerInfo.PointerEnter);
  12297. // cur._pointerEventObservable.notifyObservers(ppi, PrimitivePointerInfo.PointerEnter);
  12298. //}
  12299. //// Trigger a PointerLeave corresponding to the PointerOut
  12300. //else if (mask === PrimitivePointerInfo.PointerOut) {
  12301. // this._debugExecObserver(cur, PrimitivePointerInfo.PointerLeave);
  12302. // cur._pointerEventObservable.notifyObservers(ppi, PrimitivePointerInfo.PointerLeave);
  12303. //}
  12304. // Loop to the parent
  12305. cur = cur.parent;
  12306. }
  12307. return true;
  12308. };
  12309. Canvas2D.prototype._triggerActionManager = function (prim, ppi, mask, eventData) {
  12310. var _this = this;
  12311. // 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
  12312. if (!this._globalTransform) {
  12313. this.updateCachedStates(true);
  12314. }
  12315. // Process Trigger related to PointerDown
  12316. if ((mask & BABYLON.PrimitivePointerInfo.PointerDown) !== 0) {
  12317. // On pointer down, record the current position and time to be able to trick PickTrigger and LongPressTrigger
  12318. this._pickStartingPosition = ppi.primitivePointerPos.clone();
  12319. this._pickStartingTime = new Date().getTime();
  12320. this._pickedDownPrim = null;
  12321. if (prim.actionManager) {
  12322. this._pickedDownPrim = prim;
  12323. if (prim.actionManager.hasPickTriggers) {
  12324. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  12325. switch (eventData.button) {
  12326. case 0:
  12327. prim.actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger, actionEvent);
  12328. break;
  12329. case 1:
  12330. prim.actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger, actionEvent);
  12331. break;
  12332. case 2:
  12333. prim.actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger, actionEvent);
  12334. break;
  12335. }
  12336. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPickDownTrigger, actionEvent);
  12337. }
  12338. if (prim.actionManager.hasSpecificTrigger(BABYLON.ActionManager.OnLongPressTrigger)) {
  12339. window.setTimeout(function () {
  12340. var ppi = _this._primPointerInfo;
  12341. var capturedPrim = _this.getCapturedPrimitive(ppi.pointerId);
  12342. _this._updateIntersectionList(ppi.canvasPointerPos, capturedPrim !== null, true);
  12343. _this._updateOverStatus(false);
  12344. var ii = new BABYLON.IntersectInfo2D();
  12345. ii.pickPosition = ppi.canvasPointerPos.clone();
  12346. ii.findFirstOnly = false;
  12347. _this.intersect(ii);
  12348. if (ii.isPrimIntersected(prim) !== null) {
  12349. if (prim.actionManager) {
  12350. 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)) {
  12351. _this._pickStartingTime = 0;
  12352. prim.actionManager.processTrigger(BABYLON.ActionManager.OnLongPressTrigger, BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData));
  12353. }
  12354. }
  12355. }
  12356. }, BABYLON.ActionManager.LongPressDelay);
  12357. }
  12358. }
  12359. }
  12360. else if ((mask & BABYLON.PrimitivePointerInfo.PointerUp) !== 0) {
  12361. this._pickStartingTime = 0;
  12362. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  12363. if (prim.actionManager) {
  12364. // OnPickUpTrigger
  12365. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPickUpTrigger, actionEvent);
  12366. // OnPickTrigger
  12367. if (Math.abs(this._pickStartingPosition.x - ppi.canvasPointerPos.x) < BABYLON.ActionManager.DragMovementThreshold && Math.abs(this._pickStartingPosition.y - ppi.canvasPointerPos.y) < BABYLON.ActionManager.DragMovementThreshold) {
  12368. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger, actionEvent);
  12369. }
  12370. }
  12371. // OnPickOutTrigger
  12372. if (this._pickedDownPrim && this._pickedDownPrim.actionManager && (this._pickedDownPrim !== prim)) {
  12373. this._pickedDownPrim.actionManager.processTrigger(BABYLON.ActionManager.OnPickOutTrigger, actionEvent);
  12374. }
  12375. }
  12376. else if ((mask & BABYLON.PrimitivePointerInfo.PointerOver) !== 0) {
  12377. if (prim.actionManager) {
  12378. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  12379. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOverTrigger, actionEvent);
  12380. }
  12381. }
  12382. else if ((mask & BABYLON.PrimitivePointerInfo.PointerOut) !== 0) {
  12383. if (prim.actionManager) {
  12384. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  12385. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOutTrigger, actionEvent);
  12386. }
  12387. }
  12388. };
  12389. Canvas2D.prototype._notifParents = function (prim, mask) {
  12390. var pii = this._primPointerInfo;
  12391. var curPrim = this;
  12392. while (curPrim) {
  12393. this._updatePrimPointerPos(curPrim);
  12394. // Fire the proper notification
  12395. if (mask === BABYLON.PrimitivePointerInfo.PointerOver) {
  12396. this._debugExecObserver(curPrim, BABYLON.PrimitivePointerInfo.PointerEnter);
  12397. curPrim._pointerEventObservable.notifyObservers(pii, BABYLON.PrimitivePointerInfo.PointerEnter);
  12398. }
  12399. else if (mask === BABYLON.PrimitivePointerInfo.PointerOut) {
  12400. this._debugExecObserver(curPrim, BABYLON.PrimitivePointerInfo.PointerLeave);
  12401. curPrim._pointerEventObservable.notifyObservers(pii, BABYLON.PrimitivePointerInfo.PointerLeave);
  12402. }
  12403. curPrim = curPrim.parent;
  12404. }
  12405. };
  12406. /**
  12407. * Don't forget to call the dispose method when you're done with the Canvas instance.
  12408. * But don't worry, if you dispose its scene, the canvas will be automatically disposed too.
  12409. */
  12410. Canvas2D.prototype.dispose = function () {
  12411. if (!_super.prototype.dispose.call(this)) {
  12412. return false;
  12413. }
  12414. if (this._profilingCanvas) {
  12415. this._profilingCanvas.dispose();
  12416. this._profilingCanvas = null;
  12417. }
  12418. if (this.interactionEnabled) {
  12419. this._setupInteraction(false);
  12420. }
  12421. if (this._renderingGroupObserver) {
  12422. this._scene.onRenderingGroupObservable.remove(this._renderingGroupObserver);
  12423. this._renderingGroupObserver = null;
  12424. }
  12425. if (this._beforeRenderObserver) {
  12426. this._scene.onBeforeRenderObservable.remove(this._beforeRenderObserver);
  12427. this._beforeRenderObserver = null;
  12428. }
  12429. if (this._afterRenderObserver) {
  12430. this._scene.onAfterRenderObservable.remove(this._afterRenderObserver);
  12431. this._afterRenderObserver = null;
  12432. }
  12433. if (this._groupCacheMaps) {
  12434. this._groupCacheMaps.forEach(function (k, m) { return m.forEach(function (e) { return e.dispose(); }); });
  12435. this._groupCacheMaps = null;
  12436. }
  12437. // Unregister this instance
  12438. var index = Canvas2D_1._INSTANCES.indexOf(this);
  12439. if (index > -1) {
  12440. Canvas2D_1._INSTANCES.splice(index, 1);
  12441. }
  12442. return true;
  12443. };
  12444. Object.defineProperty(Canvas2D.prototype, "scene", {
  12445. /**
  12446. * Accessor to the Scene that owns the Canvas
  12447. * @returns The instance of the Scene object
  12448. */
  12449. get: function () {
  12450. return this._scene;
  12451. },
  12452. enumerable: true,
  12453. configurable: true
  12454. });
  12455. Object.defineProperty(Canvas2D.prototype, "engine", {
  12456. /**
  12457. * Accessor to the Engine that drives the Scene used by this Canvas
  12458. * @returns The instance of the Engine object
  12459. */
  12460. get: function () {
  12461. return this._engine;
  12462. },
  12463. enumerable: true,
  12464. configurable: true
  12465. });
  12466. Object.defineProperty(Canvas2D.prototype, "uid", {
  12467. /**
  12468. * return a unique identifier for the Canvas2D
  12469. */
  12470. get: function () {
  12471. if (!this._uid) {
  12472. this._uid = BABYLON.Tools.RandomId();
  12473. }
  12474. return this._uid;
  12475. },
  12476. enumerable: true,
  12477. configurable: true
  12478. });
  12479. Object.defineProperty(Canvas2D.prototype, "renderObservable", {
  12480. /**
  12481. * And observable called during the Canvas rendering process.
  12482. * This observable is called twice per render, each time with a different mask:
  12483. * - 1: before render is executed
  12484. * - 2: after render is executed
  12485. */
  12486. get: function () {
  12487. if (!this._renderObservable) {
  12488. this._renderObservable = new BABYLON.Observable();
  12489. }
  12490. return this._renderObservable;
  12491. },
  12492. enumerable: true,
  12493. configurable: true
  12494. });
  12495. Object.defineProperty(Canvas2D.prototype, "cachingStrategy", {
  12496. /**
  12497. * Accessor of the Caching Strategy used by this Canvas.
  12498. * See Canvas2D.CACHESTRATEGY_xxxx static members for more information
  12499. * @returns the value corresponding to the used strategy.
  12500. */
  12501. get: function () {
  12502. return this._cachingStrategy;
  12503. },
  12504. enumerable: true,
  12505. configurable: true
  12506. });
  12507. Object.defineProperty(Canvas2D.prototype, "isScreenSpace", {
  12508. /**
  12509. * Return true if the Canvas is a Screen Space one, false if it's a World Space one.
  12510. * @returns {}
  12511. */
  12512. get: function () {
  12513. return this._isScreenSpace;
  12514. },
  12515. enumerable: true,
  12516. configurable: true
  12517. });
  12518. Object.defineProperty(Canvas2D.prototype, "worldSpaceCanvasNode", {
  12519. /**
  12520. * Only valid for World Space Canvas, returns the scene node that displays the canvas
  12521. */
  12522. get: function () {
  12523. return this._worldSpaceNode;
  12524. },
  12525. set: function (val) {
  12526. this._worldSpaceNode = val;
  12527. },
  12528. enumerable: true,
  12529. configurable: true
  12530. });
  12531. Object.defineProperty(Canvas2D.prototype, "supportInstancedArray", {
  12532. /**
  12533. * Check if the WebGL Instanced Array extension is supported or not
  12534. */
  12535. get: function () {
  12536. return this._supprtInstancedArray;
  12537. },
  12538. enumerable: true,
  12539. configurable: true
  12540. });
  12541. Object.defineProperty(Canvas2D.prototype, "backgroundFill", {
  12542. /**
  12543. * Property that defines the fill object used to draw the background of the Canvas.
  12544. * Note that Canvas with a Caching Strategy of
  12545. * @returns If the background is not set, null will be returned, otherwise a valid fill object is returned.
  12546. */
  12547. get: function () {
  12548. if (!this._background || !this._background.isVisible) {
  12549. return null;
  12550. }
  12551. return this._background.fill;
  12552. },
  12553. set: function (value) {
  12554. this.checkBackgroundAvailability();
  12555. if (value === this._background.fill) {
  12556. return;
  12557. }
  12558. this._background.fill = value;
  12559. this._background.levelVisible = true;
  12560. },
  12561. enumerable: true,
  12562. configurable: true
  12563. });
  12564. Object.defineProperty(Canvas2D.prototype, "backgroundBorder", {
  12565. /**
  12566. * Property that defines the border object used to draw the background of the Canvas.
  12567. * @returns If the background is not set, null will be returned, otherwise a valid border object is returned.
  12568. */
  12569. get: function () {
  12570. if (!this._background || !this._background.isVisible) {
  12571. return null;
  12572. }
  12573. return this._background.border;
  12574. },
  12575. set: function (value) {
  12576. this.checkBackgroundAvailability();
  12577. if (value === this._background.border) {
  12578. return;
  12579. }
  12580. this._background.border = value;
  12581. this._background.levelVisible = true;
  12582. },
  12583. enumerable: true,
  12584. configurable: true
  12585. });
  12586. Object.defineProperty(Canvas2D.prototype, "backgroundBorderThickness", {
  12587. /**
  12588. * Property that defines the thickness of the border object used to draw the background of the Canvas.
  12589. * @returns If the background is not set, null will be returned, otherwise a valid number matching the thickness is returned.
  12590. */
  12591. get: function () {
  12592. if (!this._background || !this._background.isVisible) {
  12593. return null;
  12594. }
  12595. return this._background.borderThickness;
  12596. },
  12597. set: function (value) {
  12598. this.checkBackgroundAvailability();
  12599. if (value === this._background.borderThickness) {
  12600. return;
  12601. }
  12602. this._background.borderThickness = value;
  12603. },
  12604. enumerable: true,
  12605. configurable: true
  12606. });
  12607. Object.defineProperty(Canvas2D.prototype, "backgroundRoundRadius", {
  12608. /**
  12609. * You can set the roundRadius of the background
  12610. * @returns The current roundRadius
  12611. */
  12612. get: function () {
  12613. if (!this._background || !this._background.isVisible) {
  12614. return null;
  12615. }
  12616. return this._background.roundRadius;
  12617. },
  12618. set: function (value) {
  12619. this.checkBackgroundAvailability();
  12620. if (value === this._background.roundRadius) {
  12621. return;
  12622. }
  12623. this._background.roundRadius = value;
  12624. this._background.levelVisible = true;
  12625. },
  12626. enumerable: true,
  12627. configurable: true
  12628. });
  12629. Object.defineProperty(Canvas2D.prototype, "interactionEnabled", {
  12630. /**
  12631. * Enable/Disable interaction for this Canvas
  12632. * When enabled the Prim2DBase.pointerEventObservable property will notified when appropriate events occur
  12633. */
  12634. get: function () {
  12635. return this._interactionEnabled;
  12636. },
  12637. set: function (enable) {
  12638. this._setupInteraction(enable);
  12639. },
  12640. enumerable: true,
  12641. configurable: true
  12642. });
  12643. Object.defineProperty(Canvas2D.prototype, "fitRenderingDevice", {
  12644. get: function () {
  12645. return this._fitRenderingDevice;
  12646. },
  12647. enumerable: true,
  12648. configurable: true
  12649. });
  12650. Object.defineProperty(Canvas2D.prototype, "designSize", {
  12651. get: function () {
  12652. return this._designSize;
  12653. },
  12654. enumerable: true,
  12655. configurable: true
  12656. });
  12657. Object.defineProperty(Canvas2D.prototype, "designSizeUseHorizAxis", {
  12658. get: function () {
  12659. return this._designUseHorizAxis;
  12660. },
  12661. enumerable: true,
  12662. configurable: true
  12663. });
  12664. Object.defineProperty(Canvas2D.prototype, "overPrim", {
  12665. /**
  12666. * Return
  12667. */
  12668. get: function () {
  12669. return this._actualOverPrimitive ? this._actualOverPrimitive.prim : null;
  12670. },
  12671. enumerable: true,
  12672. configurable: true
  12673. });
  12674. Object.defineProperty(Canvas2D.prototype, "_engineData", {
  12675. /**
  12676. * Access the babylon.js' engine bound data, do not invoke this method, it's for internal purpose only
  12677. * @returns {}
  12678. */
  12679. get: function () {
  12680. return this.__engineData;
  12681. },
  12682. enumerable: true,
  12683. configurable: true
  12684. });
  12685. Canvas2D.prototype.createCanvasProfileInfoCanvas = function () {
  12686. if (this._profilingCanvas) {
  12687. return this._profilingCanvas;
  12688. }
  12689. var canvas = new ScreenSpaceCanvas2D(this.scene, {
  12690. id: "ProfileInfoCanvas", cachingStrategy: Canvas2D_1.CACHESTRATEGY_DONTCACHE, children: [
  12691. new BABYLON.Rectangle2D({
  12692. id: "ProfileBorder", border: "#FFFFFFFF", borderThickness: 2, roundRadius: 5, fill: "#C04040C0", marginAlignment: "h: left, v: top", margin: "10", padding: "10", children: [
  12693. new BABYLON.Text2D("Stats", { id: "ProfileInfoText", marginAlignment: "h: left, v: top", fontName: "12pt Lucida Console", fontSignedDistanceField: true })
  12694. ]
  12695. })
  12696. ]
  12697. });
  12698. this._profileInfoText = canvas.findById("ProfileInfoText");
  12699. this._profilingCanvas = canvas;
  12700. return canvas;
  12701. };
  12702. Canvas2D.prototype.checkBackgroundAvailability = function () {
  12703. if (this._cachingStrategy === Canvas2D_1.CACHESTRATEGY_TOPLEVELGROUPS) {
  12704. throw Error("Can't use Canvas Background with the caching strategy TOPLEVELGROUPS");
  12705. }
  12706. };
  12707. Canvas2D.prototype._initPerfMetrics = function () {
  12708. this._drawCallsOpaqueCounter.fetchNewFrame();
  12709. this._drawCallsAlphaTestCounter.fetchNewFrame();
  12710. this._drawCallsTransparentCounter.fetchNewFrame();
  12711. this._groupRenderCounter.fetchNewFrame();
  12712. this._updateTransparentDataCounter.fetchNewFrame();
  12713. this._cachedGroupRenderCounter.fetchNewFrame();
  12714. this._updateCachedStateCounter.fetchNewFrame();
  12715. this._updateLayoutCounter.fetchNewFrame();
  12716. this._updatePositioningCounter.fetchNewFrame();
  12717. this._updateLocalTransformCounter.fetchNewFrame();
  12718. this._updateGlobalTransformCounter.fetchNewFrame();
  12719. this._boundingInfoRecomputeCounter.fetchNewFrame();
  12720. };
  12721. Canvas2D.prototype._fetchPerfMetrics = function () {
  12722. this._drawCallsOpaqueCounter.addCount(0, true);
  12723. this._drawCallsAlphaTestCounter.addCount(0, true);
  12724. this._drawCallsTransparentCounter.addCount(0, true);
  12725. this._groupRenderCounter.addCount(0, true);
  12726. this._updateTransparentDataCounter.addCount(0, true);
  12727. this._cachedGroupRenderCounter.addCount(0, true);
  12728. this._updateCachedStateCounter.addCount(0, true);
  12729. this._updateLayoutCounter.addCount(0, true);
  12730. this._updatePositioningCounter.addCount(0, true);
  12731. this._updateLocalTransformCounter.addCount(0, true);
  12732. this._updateGlobalTransformCounter.addCount(0, true);
  12733. this._boundingInfoRecomputeCounter.addCount(0, true);
  12734. };
  12735. Canvas2D.prototype._updateProfileCanvas = function () {
  12736. if (this._profileInfoText == null) {
  12737. return;
  12738. }
  12739. var format = function (v) { return (Math.round(v * 100) / 100).toString(); };
  12740. var p = "Draw Calls:\n" +
  12741. (" - Opaque: " + format(this.drawCallsOpaqueCounter.current) + ", (avg:" + format(this.drawCallsOpaqueCounter.lastSecAverage) + ", t:" + format(this.drawCallsOpaqueCounter.total) + ")\n") +
  12742. (" - AlphaTest: " + format(this.drawCallsAlphaTestCounter.current) + ", (avg:" + format(this.drawCallsAlphaTestCounter.lastSecAverage) + ", t:" + format(this.drawCallsAlphaTestCounter.total) + ")\n") +
  12743. (" - Transparent: " + format(this.drawCallsTransparentCounter.current) + ", (avg:" + format(this.drawCallsTransparentCounter.lastSecAverage) + ", t:" + format(this.drawCallsTransparentCounter.total) + ")\n") +
  12744. ("Group Render: " + this.groupRenderCounter.current + ", (avg:" + format(this.groupRenderCounter.lastSecAverage) + ", t:" + format(this.groupRenderCounter.total) + ")\n") +
  12745. ("Update Transparent Data: " + this.updateTransparentDataCounter.current + ", (avg:" + format(this.updateTransparentDataCounter.lastSecAverage) + ", t:" + format(this.updateTransparentDataCounter.total) + ")\n") +
  12746. ("Cached Group Render: " + this.cachedGroupRenderCounter.current + ", (avg:" + format(this.cachedGroupRenderCounter.lastSecAverage) + ", t:" + format(this.cachedGroupRenderCounter.total) + ")\n") +
  12747. ("Update Cached States: " + this.updateCachedStateCounter.current + ", (avg:" + format(this.updateCachedStateCounter.lastSecAverage) + ", t:" + format(this.updateCachedStateCounter.total) + ")\n") +
  12748. (" - Update Layout: " + this.updateLayoutCounter.current + ", (avg:" + format(this.updateLayoutCounter.lastSecAverage) + ", t:" + format(this.updateLayoutCounter.total) + ")\n") +
  12749. (" - Update Positioning: " + this.updatePositioningCounter.current + ", (avg:" + format(this.updatePositioningCounter.lastSecAverage) + ", t:" + format(this.updatePositioningCounter.total) + ")\n") +
  12750. (" - Update Local Trans: " + this.updateLocalTransformCounter.current + ", (avg:" + format(this.updateLocalTransformCounter.lastSecAverage) + ", t:" + format(this.updateLocalTransformCounter.total) + ")\n") +
  12751. (" - Update Global Trans: " + this.updateGlobalTransformCounter.current + ", (avg:" + format(this.updateGlobalTransformCounter.lastSecAverage) + ", t:" + format(this.updateGlobalTransformCounter.total) + ")\n") +
  12752. (" - BoundingInfo Recompute: " + this.boundingInfoRecomputeCounter.current + ", (avg:" + format(this.boundingInfoRecomputeCounter.lastSecAverage) + ", t:" + format(this.boundingInfoRecomputeCounter.total) + ")");
  12753. this._profileInfoText.text = p;
  12754. };
  12755. Canvas2D.prototype._addDrawCallCount = function (count, renderMode) {
  12756. switch (renderMode) {
  12757. case BABYLON.Render2DContext.RenderModeOpaque:
  12758. this._drawCallsOpaqueCounter.addCount(count, false);
  12759. return;
  12760. case BABYLON.Render2DContext.RenderModeAlphaTest:
  12761. this._drawCallsAlphaTestCounter.addCount(count, false);
  12762. return;
  12763. case BABYLON.Render2DContext.RenderModeTransparent:
  12764. this._drawCallsTransparentCounter.addCount(count, false);
  12765. return;
  12766. }
  12767. };
  12768. Canvas2D.prototype._addGroupRenderCount = function (count) {
  12769. this._groupRenderCounter.addCount(count, false);
  12770. };
  12771. Canvas2D.prototype._addUpdateTransparentDataCount = function (count) {
  12772. this._updateTransparentDataCounter.addCount(count, false);
  12773. };
  12774. Canvas2D.prototype.addCachedGroupRenderCounter = function (count) {
  12775. this._cachedGroupRenderCounter.addCount(count, false);
  12776. };
  12777. Canvas2D.prototype.addUpdateCachedStateCounter = function (count) {
  12778. this._updateCachedStateCounter.addCount(count, false);
  12779. };
  12780. Canvas2D.prototype.addUpdateLayoutCounter = function (count) {
  12781. this._updateLayoutCounter.addCount(count, false);
  12782. };
  12783. Canvas2D.prototype.addUpdatePositioningCounter = function (count) {
  12784. this._updatePositioningCounter.addCount(count, false);
  12785. };
  12786. Canvas2D.prototype.addupdateLocalTransformCounter = function (count) {
  12787. this._updateLocalTransformCounter.addCount(count, false);
  12788. };
  12789. Canvas2D.prototype.addUpdateGlobalTransformCounter = function (count) {
  12790. this._updateGlobalTransformCounter.addCount(count, false);
  12791. };
  12792. Canvas2D.prototype._updateTrackedNodes = function () {
  12793. var cam = this.scene.cameraToUseForPointers || this.scene.activeCamera;
  12794. cam.getViewMatrix().multiplyToRef(cam.getProjectionMatrix(), Canvas2D_1._m);
  12795. var rh = this.engine.getRenderHeight();
  12796. var v = cam.viewport.toGlobal(this.engine.getRenderWidth(), rh);
  12797. for (var _i = 0, _a = this._trackedGroups; _i < _a.length; _i++) {
  12798. var group = _a[_i];
  12799. if (group.isDisposed || !group.isVisible) {
  12800. continue;
  12801. }
  12802. var node = group.trackedNode;
  12803. var worldMtx = node.getWorldMatrix();
  12804. var proj = BABYLON.Vector3.Project(Canvas2D_1._v, worldMtx, Canvas2D_1._m, v);
  12805. // Set the visibility state accordingly, if the position is outside the frustum (well on the Z planes only...) set the group to hidden
  12806. group.levelVisible = proj.z >= 0 && proj.z < 1.0;
  12807. var s = this.scale;
  12808. group.x = Math.round(proj.x / s);
  12809. group.y = Math.round((rh - proj.y) / s);
  12810. }
  12811. };
  12812. /**
  12813. * Call this method change you want to have layout related data computed and up to date (layout area, primitive area, local/global transformation matrices)
  12814. */
  12815. Canvas2D.prototype.updateCanvasLayout = function (forceRecompute) {
  12816. this._updateCanvasState(forceRecompute);
  12817. };
  12818. Canvas2D.prototype._updateAdaptiveSizeWorldCanvas = function () {
  12819. if (this._globalTransformStep < 2) {
  12820. return;
  12821. }
  12822. var n = this.worldSpaceCanvasNode;
  12823. var bi = n.getBoundingInfo().boundingBox;
  12824. var v = bi.vectorsWorld;
  12825. var cam = this.scene.cameraToUseForPointers || this.scene.activeCamera;
  12826. cam.getViewMatrix().multiplyToRef(cam.getProjectionMatrix(), Canvas2D_1._m);
  12827. var vp = cam.viewport.toGlobal(this.engine.getRenderWidth(), this.engine.getRenderHeight());
  12828. var projPoints = new Array(4);
  12829. for (var i = 0; i < 4; i++) {
  12830. projPoints[i] = BABYLON.Vector3.Project(v[i], Canvas2D_1._mI, Canvas2D_1._m, vp);
  12831. }
  12832. var left = projPoints[3].subtract(projPoints[0]).length();
  12833. var top = projPoints[3].subtract(projPoints[1]).length();
  12834. var right = projPoints[1].subtract(projPoints[2]).length();
  12835. var bottom = projPoints[2].subtract(projPoints[0]).length();
  12836. var w = Math.round(Math.max(top, bottom));
  12837. var h = Math.round(Math.max(right, left));
  12838. var isW = w > h;
  12839. // Basically if it's under 256 we use 256, otherwise we take the biggest power of 2
  12840. var edge = Math.max(w, h);
  12841. if (edge < 256) {
  12842. edge = 256;
  12843. }
  12844. else {
  12845. edge = Math.pow(2, Math.ceil(Math.log(edge) / Math.log(2)));
  12846. }
  12847. // Clip values if needed
  12848. edge = Math.min(edge, this._maxAdaptiveWorldSpaceCanvasSize);
  12849. var newScale = edge / ((isW) ? this.size.width : this.size.height);
  12850. if (newScale !== this.scale) {
  12851. var scale = newScale;
  12852. // console.log(`New adaptive scale for Canvas ${this.id}, w: ${w}, h: ${h}, scale: ${scale}, edge: ${edge}, isW: ${isW}`);
  12853. this._setRenderingScale(scale);
  12854. }
  12855. };
  12856. Canvas2D.prototype._updateCanvasState = function (forceRecompute) {
  12857. // Check if the update has already been made for this render Frame
  12858. if (!forceRecompute && this.scene.getRenderId() === this._updateRenderId) {
  12859. return;
  12860. }
  12861. // Detect a change of rendering size
  12862. var renderingSizeChanged = false;
  12863. var newWidth = this.engine.getRenderWidth();
  12864. if (newWidth !== this._renderingSize.width) {
  12865. renderingSizeChanged = true;
  12866. }
  12867. this._renderingSize.width = newWidth;
  12868. var newHeight = this.engine.getRenderHeight();
  12869. if (newHeight !== this._renderingSize.height) {
  12870. renderingSizeChanged = true;
  12871. }
  12872. this._renderingSize.height = newHeight;
  12873. // If the canvas fit the rendering size and it changed, update
  12874. if (renderingSizeChanged && this._fitRenderingDevice) {
  12875. this._actualSize = this._renderingSize.clone();
  12876. this._size = this._renderingSize.clone();
  12877. if (this._background) {
  12878. this._background.size = this.size;
  12879. }
  12880. // Dirty the Layout at the Canvas level to recompute as the size changed
  12881. this._setLayoutDirty();
  12882. }
  12883. // If there's a design size, update the scale according to the renderingSize
  12884. if (this._designSize) {
  12885. var scale = void 0;
  12886. if (this._designUseHorizAxis) {
  12887. scale = this._renderingSize.width / this._designSize.width;
  12888. }
  12889. else {
  12890. scale = this._renderingSize.height / this._designSize.height;
  12891. }
  12892. this.size = this._designSize.clone();
  12893. this.actualSize = this._designSize.clone();
  12894. this.scale = scale;
  12895. }
  12896. var context = new BABYLON.PrepareRender2DContext();
  12897. ++this._globalTransformProcessStep;
  12898. this.updateCachedStates(false);
  12899. this._prepareGroupRender(context);
  12900. this._updateRenderId = this.scene.getRenderId();
  12901. };
  12902. /**
  12903. * Method that renders the Canvas, you should not invoke
  12904. */
  12905. Canvas2D.prototype._render = function () {
  12906. this._initPerfMetrics();
  12907. if (this._renderObservable && this._renderObservable.hasObservers()) {
  12908. this._renderObservable.notifyObservers(this, Canvas2D_1.RENDEROBSERVABLE_PRE);
  12909. }
  12910. this._updateCanvasState(false);
  12911. this._updateTrackedNodes();
  12912. // Nothing to do is the Canvas is not visible
  12913. if (this.isVisible === false) {
  12914. return;
  12915. }
  12916. if (!this._isScreenSpace) {
  12917. this._updateAdaptiveSizeWorldCanvas();
  12918. }
  12919. this._updateCanvasState(false);
  12920. if (this._primPointerInfo.canvasPointerPos) {
  12921. this._updateIntersectionList(this._primPointerInfo.canvasPointerPos, false, false);
  12922. this._updateOverStatus(false);
  12923. }
  12924. this.engine.setState(false);
  12925. this._groupRender();
  12926. if (!this._isScreenSpace) {
  12927. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagWorldCacheChanged)) {
  12928. this.worldSpaceCacheChanged();
  12929. this._clearFlags(BABYLON.SmartPropertyPrim.flagWorldCacheChanged);
  12930. }
  12931. }
  12932. // If the canvas is cached at canvas level, we must manually render the sprite that will display its content
  12933. if (this._cachingStrategy === Canvas2D_1.CACHESTRATEGY_CANVAS && this._cachedCanvasGroup) {
  12934. this._cachedCanvasGroup._renderCachedCanvas();
  12935. }
  12936. this._fetchPerfMetrics();
  12937. this._updateProfileCanvas();
  12938. if (this._renderObservable && this._renderObservable.hasObservers()) {
  12939. this._renderObservable.notifyObservers(this, Canvas2D_1.RENDEROBSERVABLE_POST);
  12940. }
  12941. };
  12942. /**
  12943. * Internal method that allocate a cache for the given group.
  12944. * Caching is made using a collection of MapTexture where many groups have their bitmap cache stored inside.
  12945. * @param group The group to allocate the cache of.
  12946. * @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.
  12947. */
  12948. Canvas2D.prototype._allocateGroupCache = function (group, parent, minSize, useMipMap, anisotropicLevel) {
  12949. if (useMipMap === void 0) { useMipMap = false; }
  12950. if (anisotropicLevel === void 0) { anisotropicLevel = 1; }
  12951. var key = (useMipMap ? "MipMap" : "NoMipMap") + "_" + anisotropicLevel;
  12952. var rd = group._renderableData;
  12953. var noResizeScale = rd._noResizeOnScale;
  12954. var isCanvas = parent == null;
  12955. var scale;
  12956. if (noResizeScale) {
  12957. scale = isCanvas ? Canvas2D_1._unS : group.parent.actualScale;
  12958. }
  12959. else {
  12960. scale = group.actualScale;
  12961. }
  12962. // Determine size
  12963. var size = group.actualSize;
  12964. size = new BABYLON.Size(Math.ceil(size.width * scale.x), Math.ceil(size.height * scale.y));
  12965. var originalSize = size.clone();
  12966. if (minSize) {
  12967. size.width = Math.max(minSize.width, size.width);
  12968. size.height = Math.max(minSize.height, size.height);
  12969. }
  12970. var mapArray = this._groupCacheMaps.getOrAddWithFactory(key, function () { return new Array(); });
  12971. // Try to find a spot in one of the cached texture
  12972. var res = null;
  12973. var map;
  12974. for (var _i = 0, mapArray_1 = mapArray; _i < mapArray_1.length; _i++) {
  12975. var _map = mapArray_1[_i];
  12976. map = _map;
  12977. var node = map.allocateRect(size);
  12978. if (node) {
  12979. res = { node: node, texture: map };
  12980. break;
  12981. }
  12982. }
  12983. // Couldn't find a map that could fit the rect, create a new map for it
  12984. if (!res) {
  12985. var mapSize = new BABYLON.Size(Canvas2D_1._groupTextureCacheSize, Canvas2D_1._groupTextureCacheSize);
  12986. // Check if the predefined size would fit, other create a custom size using the nearest bigger power of 2
  12987. if (size.width > mapSize.width || size.height > mapSize.height) {
  12988. mapSize.width = Math.pow(2, Math.ceil(Math.log(size.width) / Math.log(2)));
  12989. mapSize.height = Math.pow(2, Math.ceil(Math.log(size.height) / Math.log(2)));
  12990. }
  12991. var id = "groupsMapChache" + this._mapCounter++ + "forCanvas" + this.id;
  12992. map = new BABYLON.MapTexture(id, this._scene, mapSize, useMipMap ? BABYLON.Texture.TRILINEAR_SAMPLINGMODE : BABYLON.Texture.BILINEAR_SAMPLINGMODE, useMipMap);
  12993. map.hasAlpha = true;
  12994. map.anisotropicFilteringLevel = 4;
  12995. mapArray.splice(0, 0, map);
  12996. var node = map.allocateRect(size);
  12997. res = { node: node, texture: map };
  12998. }
  12999. // Check if we have to create a Sprite that will display the content of the Canvas which is cached.
  13000. // Don't do it in case of the group being a worldspace canvas (because its texture is bound to a WorldSpaceCanvas node)
  13001. if (group !== this || this._isScreenSpace) {
  13002. var node = res.node;
  13003. // 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
  13004. var sprite = void 0;
  13005. if (this._cachingStrategy === Canvas2D_1.CACHESTRATEGY_CANVAS) {
  13006. if (this._cachedCanvasGroup) {
  13007. this._cachedCanvasGroup.dispose();
  13008. }
  13009. this._cachedCanvasGroup = BABYLON.Group2D._createCachedCanvasGroup(this);
  13010. sprite = new BABYLON.Sprite2D(map, { parent: this._cachedCanvasGroup, id: "__cachedCanvasSprite__", spriteSize: originalSize, spriteLocation: node.pos });
  13011. sprite.zOrder = 1;
  13012. sprite.origin = BABYLON.Vector2.Zero();
  13013. }
  13014. else {
  13015. 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 });
  13016. sprite.origin = group.origin.clone();
  13017. sprite.addExternalData("__cachedGroup__", group);
  13018. sprite.pointerEventObservable.add(function (e, s) {
  13019. if (group.pointerEventObservable !== null) {
  13020. group.pointerEventObservable.notifyObservers(e, s.mask);
  13021. }
  13022. });
  13023. res.sprite = sprite;
  13024. }
  13025. if (sprite && noResizeScale) {
  13026. var relScale = isCanvas ? group.actualScale : group.actualScale.divide(group.parent.actualScale);
  13027. sprite.scaleX = relScale.x;
  13028. sprite.scaleY = relScale.y;
  13029. }
  13030. }
  13031. return res;
  13032. };
  13033. /**
  13034. * Internal method used to register a Scene Node to track position for the given group
  13035. * Do not invoke this method, for internal purpose only.
  13036. * @param group the group to track its associated Scene Node
  13037. */
  13038. Canvas2D.prototype._registerTrackedNode = function (group) {
  13039. if (group._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  13040. return;
  13041. }
  13042. this._trackedGroups.push(group);
  13043. group._setFlags(BABYLON.SmartPropertyPrim.flagTrackedGroup);
  13044. };
  13045. /**
  13046. * Internal method used to unregister a tracked Scene Node
  13047. * Do not invoke this method, it's for internal purpose only.
  13048. * @param group the group to unregister its tracked Scene Node from.
  13049. */
  13050. Canvas2D.prototype._unregisterTrackedNode = function (group) {
  13051. if (!group._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  13052. return;
  13053. }
  13054. var i = this._trackedGroups.indexOf(group);
  13055. if (i !== -1) {
  13056. this._trackedGroups.splice(i, 1);
  13057. }
  13058. group._clearFlags(BABYLON.SmartPropertyPrim.flagTrackedGroup);
  13059. };
  13060. /**
  13061. * Get a Solid Color Brush instance matching the given color.
  13062. * @param color The color to retrieve
  13063. * @return A shared instance of the SolidColorBrush2D class that use the given color
  13064. */
  13065. Canvas2D.GetSolidColorBrush = function (color) {
  13066. return Canvas2D_1._solidColorBrushes.getOrAddWithFactory(color.toHexString(), function () { return new BABYLON.SolidColorBrush2D(color.clone(), true); });
  13067. };
  13068. /**
  13069. * Get a Solid Color Brush instance matching the given color expressed as a CSS formatted hexadecimal value.
  13070. * @param color The color to retrieve
  13071. * @return A shared instance of the SolidColorBrush2D class that uses the given color
  13072. */
  13073. Canvas2D.GetSolidColorBrushFromHex = function (hexValue) {
  13074. return Canvas2D_1._solidColorBrushes.getOrAddWithFactory(hexValue, function () { return new BABYLON.SolidColorBrush2D(BABYLON.Color4.FromHexString(hexValue), true); });
  13075. };
  13076. /**
  13077. * Get a Gradient Color Brush
  13078. * @param color1 starting color
  13079. * @param color2 engine color
  13080. * @param translation translation vector to apply. default is [0;0]
  13081. * @param rotation rotation in radian to apply to the brush, initial direction is top to bottom. rotation is counter clockwise. default is 0.
  13082. * @param scale scaling factor to apply. default is 1.
  13083. */
  13084. Canvas2D.GetGradientColorBrush = function (color1, color2, translation, rotation, scale) {
  13085. if (translation === void 0) { translation = BABYLON.Vector2.Zero(); }
  13086. if (rotation === void 0) { rotation = 0; }
  13087. if (scale === void 0) { scale = 1; }
  13088. return Canvas2D_1._gradientColorBrushes.getOrAddWithFactory(BABYLON.GradientColorBrush2D.BuildKey(color1, color2, translation, rotation, scale), function () { return new BABYLON.GradientColorBrush2D(color1, color2, translation, rotation, scale, true); });
  13089. };
  13090. /**
  13091. * Create a solid or gradient brush from a string value.
  13092. * @param brushString should be either
  13093. * - "solid: #RRGGBBAA" or "#RRGGBBAA"
  13094. * - "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.
  13095. */
  13096. Canvas2D.GetBrushFromString = function (brushString) {
  13097. // Note: yes, I hate/don't know RegEx.. Feel free to add your contribution to the cause!
  13098. brushString = brushString.trim();
  13099. var split = brushString.split(",");
  13100. // Solid, formatted as: "[solid:]#FF808080"
  13101. if (split.length === 1) {
  13102. var value = null;
  13103. if (brushString.indexOf("solid:") === 0) {
  13104. value = brushString.substr(6).trim();
  13105. }
  13106. else if (brushString.indexOf("#") === 0) {
  13107. value = brushString;
  13108. }
  13109. else {
  13110. return null;
  13111. }
  13112. return Canvas2D_1.GetSolidColorBrushFromHex(value);
  13113. }
  13114. else {
  13115. if (split[0].indexOf("gradient:") === 0) {
  13116. split[0] = split[0].substr(9).trim();
  13117. }
  13118. try {
  13119. var start = BABYLON.Color4.FromHexString(split[0].trim());
  13120. var end = BABYLON.Color4.FromHexString(split[1].trim());
  13121. var t = BABYLON.Vector2.Zero();
  13122. if (split.length > 2) {
  13123. var v = split[2].trim();
  13124. if (v.charAt(0) !== "[" || v.charAt(v.length - 1) !== "]") {
  13125. return null;
  13126. }
  13127. var sep = v.indexOf(":");
  13128. var x = parseFloat(v.substr(1, sep));
  13129. var y = parseFloat(v.substr(sep + 1, v.length - (sep + 1)));
  13130. t = new BABYLON.Vector2(x, y);
  13131. }
  13132. var r = 0;
  13133. if (split.length > 3) {
  13134. r = BABYLON.Tools.ToRadians(parseFloat(split[3].trim()));
  13135. }
  13136. var s = 1;
  13137. if (split.length > 4) {
  13138. s = parseFloat(split[4].trim());
  13139. }
  13140. return Canvas2D_1.GetGradientColorBrush(start, end, t, r, s);
  13141. }
  13142. catch (e) {
  13143. return null;
  13144. }
  13145. }
  13146. };
  13147. return Canvas2D;
  13148. }(BABYLON.Group2D));
  13149. /**
  13150. * 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.
  13151. * This strategy doesn't allow primitives added directly as children of the Canvas.
  13152. * 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.
  13153. */
  13154. Canvas2D.CACHESTRATEGY_TOPLEVELGROUPS = 1;
  13155. /**
  13156. * In this strategy each group will have its own cache bitmap (except if a given group explicitly defines the DONTCACHEOVERRIDE or CACHEINPARENTGROUP behaviors).
  13157. * 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.
  13158. * When using this strategy, group instances can rely on the DONTCACHEOVERRIDE or CACHEINPARENTGROUP behaviors to minimize the amount of cached bitmaps.
  13159. * 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.
  13160. */
  13161. Canvas2D.CACHESTRATEGY_ALLGROUPS = 2;
  13162. /**
  13163. * 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).
  13164. */
  13165. Canvas2D.CACHESTRATEGY_CANVAS = 3;
  13166. /**
  13167. * This strategy is used to recompose/redraw the canvas entirely at each viewport render.
  13168. * 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).
  13169. * Note that you can't use this strategy for WorldSpace Canvas, they need at least a top level group caching.
  13170. */
  13171. Canvas2D.CACHESTRATEGY_DONTCACHE = 4;
  13172. /**
  13173. * Observable Mask to be notified before rendering is made
  13174. */
  13175. Canvas2D.RENDEROBSERVABLE_PRE = 1;
  13176. /**
  13177. * Observable Mask to be notified after rendering is made
  13178. */
  13179. Canvas2D.RENDEROBSERVABLE_POST = 2;
  13180. Canvas2D._INSTANCES = [];
  13181. Canvas2D._zMinDelta = 1 / (Math.pow(2, 24) - 1);
  13182. Canvas2D._interInfo = new BABYLON.IntersectInfo2D();
  13183. Canvas2D._v = BABYLON.Vector3.Zero(); // Must stay zero
  13184. Canvas2D._m = BABYLON.Matrix.Identity();
  13185. Canvas2D._mI = BABYLON.Matrix.Identity(); // Must stay identity
  13186. /**
  13187. * Define the default size used for both the width and height of a MapTexture to allocate.
  13188. * Note that some MapTexture might be bigger than this size if the first node to allocate is bigger in width or height
  13189. */
  13190. Canvas2D._groupTextureCacheSize = 1024;
  13191. Canvas2D._solidColorBrushes = new BABYLON.StringDictionary();
  13192. Canvas2D._gradientColorBrushes = new BABYLON.StringDictionary();
  13193. Canvas2D = Canvas2D_1 = __decorate([
  13194. BABYLON.className("Canvas2D", "BABYLON")
  13195. ], Canvas2D);
  13196. BABYLON.Canvas2D = Canvas2D;
  13197. var WorldSpaceCanvas2D = (function (_super) {
  13198. __extends(WorldSpaceCanvas2D, _super);
  13199. /**
  13200. * 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.
  13201. * 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.
  13202. * @param scene the Scene that owns the Canvas
  13203. * @param size the dimension of the Canvas in World Space
  13204. * @param settings a combination of settings, possible ones are
  13205. * - children: an array of direct children primitives
  13206. * - id: a text identifier, for information purpose only, default is null.
  13207. * - worldPosition the position of the Canvas in World Space, default is [0,0,0]
  13208. * - worldRotation the rotation of the Canvas in World Space, default is Quaternion.Identity()
  13209. * - sideOrientation: Unexpected behavior occur if the value is different from Mesh.DEFAULTSIDE right now, so please use this one, which is the default.
  13210. * - cachingStrategy Must be CACHESTRATEGY_CANVAS for now, which is the default.
  13211. * - 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).
  13212. * - isVisible: true if the canvas must be visible, false for hidden. Default is true.
  13213. * - backgroundRoundRadius: the round radius of the background, either backgroundFill or backgroundBorder must be specified.
  13214. * - 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.
  13215. * - 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.
  13216. * - backgroundBorderThickness: if a backgroundBorder is specified, its thickness can be set using this property
  13217. * - 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.
  13218. * - 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.
  13219. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  13220. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  13221. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  13222. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  13223. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  13224. */
  13225. function WorldSpaceCanvas2D(scene, size, settings) {
  13226. var _this;
  13227. BABYLON.Prim2DBase._isCanvasInit = true;
  13228. var s = settings;
  13229. s.isScreenSpace = false;
  13230. s.size = size.clone();
  13231. settings.cachingStrategy = (settings.cachingStrategy == null) ? Canvas2D.CACHESTRATEGY_CANVAS : settings.cachingStrategy;
  13232. if (settings.cachingStrategy !== Canvas2D.CACHESTRATEGY_CANVAS) {
  13233. throw new Error("Right now only the CACHESTRATEGY_CANVAS cache Strategy is supported for WorldSpace Canvas. More will come soon!");
  13234. }
  13235. _this = _super.call(this, scene, settings) || this;
  13236. BABYLON.Prim2DBase._isCanvasInit = false;
  13237. _this._renderableData._useMipMap = true;
  13238. _this._renderableData._anisotropicLevel = 8;
  13239. //if (cachingStrategy === Canvas2D.CACHESTRATEGY_DONTCACHE) {
  13240. // throw new Error("CACHESTRATEGY_DONTCACHE cache Strategy can't be used for WorldSpace Canvas");
  13241. //}
  13242. var createWorldSpaceNode = !settings || (settings.customWorldSpaceNode == null);
  13243. _this._customWorldSpaceNode = !createWorldSpaceNode;
  13244. var id = settings ? settings.id || null : null;
  13245. // Set the max size of texture allowed for the adaptive render of the world space canvas cached bitmap
  13246. var capMaxTextSize = _this.engine.getCaps().maxRenderTextureSize;
  13247. var defaultTextSize = (Math.min(capMaxTextSize, 1024)); // Default is 4K if allowed otherwise the max allowed
  13248. if (settings.maxAdaptiveCanvasSize == null) {
  13249. _this._maxAdaptiveWorldSpaceCanvasSize = defaultTextSize;
  13250. }
  13251. else {
  13252. // We still clip the given value with the max allowed, the user may not be aware of these limitations
  13253. _this._maxAdaptiveWorldSpaceCanvasSize = Math.min(settings.maxAdaptiveCanvasSize, capMaxTextSize);
  13254. }
  13255. if (createWorldSpaceNode) {
  13256. var plane = new BABYLON.WorldSpaceCanvas2DNode(id, scene, _this);
  13257. var vertexData = BABYLON.VertexData.CreatePlane({
  13258. width: size.width,
  13259. height: size.height,
  13260. sideOrientation: settings && settings.sideOrientation || BABYLON.Mesh.DEFAULTSIDE
  13261. });
  13262. var mtl = new BABYLON.StandardMaterial(id + "_Material", scene);
  13263. _this.applyCachedTexture(vertexData, mtl);
  13264. vertexData.applyToMesh(plane, true);
  13265. mtl.specularColor = new BABYLON.Color3(0, 0, 0);
  13266. mtl.disableLighting = true;
  13267. mtl.useAlphaFromDiffuseTexture = true;
  13268. plane.position = settings && settings.worldPosition || BABYLON.Vector3.Zero();
  13269. plane.rotationQuaternion = settings && settings.worldRotation || BABYLON.Quaternion.Identity();
  13270. plane.material = mtl;
  13271. _this._worldSpaceNode = plane;
  13272. }
  13273. else {
  13274. _this._worldSpaceNode = settings.customWorldSpaceNode;
  13275. _this.applyCachedTexture(null, null);
  13276. }
  13277. _this.propertyChanged.add(function (e, st) {
  13278. var mesh = _this._worldSpaceNode;
  13279. if (mesh) {
  13280. mesh.isVisible = e.newValue;
  13281. }
  13282. }, BABYLON.Prim2DBase.isVisibleProperty.flagId);
  13283. return _this;
  13284. }
  13285. WorldSpaceCanvas2D.prototype.dispose = function () {
  13286. if (!_super.prototype.dispose.call(this)) {
  13287. return false;
  13288. }
  13289. if (!this._customWorldSpaceNode && this._worldSpaceNode) {
  13290. this._worldSpaceNode.dispose();
  13291. this._worldSpaceNode = null;
  13292. }
  13293. };
  13294. return WorldSpaceCanvas2D;
  13295. }(Canvas2D));
  13296. WorldSpaceCanvas2D = __decorate([
  13297. BABYLON.className("WorldSpaceCanvas2D", "BABYLON")
  13298. ], WorldSpaceCanvas2D);
  13299. BABYLON.WorldSpaceCanvas2D = WorldSpaceCanvas2D;
  13300. var ScreenSpaceCanvas2D = (function (_super) {
  13301. __extends(ScreenSpaceCanvas2D, _super);
  13302. /**
  13303. * 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.
  13304. * 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.
  13305. * All caching strategies will be available.
  13306. * 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]
  13307. * @param scene the Scene that owns the Canvas
  13308. * @param settings a combination of settings, possible ones are
  13309. * - children: an array of direct children primitives
  13310. * - id: a text identifier, for information purpose only
  13311. * - x: the position along the x axis (horizontal), relative to the left edge of the viewport. you can alternatively use the position setting.
  13312. * - y: the position along the y axis (vertically), relative to the bottom edge of the viewport. you can alternatively use the position setting.
  13313. * - 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]
  13314. * - width: the width of the Canvas. you can alternatively use the size setting.
  13315. * - height: the height of the Canvas. you can alternatively use the size setting.
  13316. * - 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
  13317. * - 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.
  13318. * - 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.
  13319. * - 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.
  13320. * - cachingStrategy: either CACHESTRATEGY_TOPLEVELGROUPS, CACHESTRATEGY_ALLGROUPS, CACHESTRATEGY_CANVAS, CACHESTRATEGY_DONTCACHE. Please refer to their respective documentation for more information. Default is Canvas2D.CACHESTRATEGY_DONTCACHE
  13321. * - 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.
  13322. * - isVisible: true if the canvas must be visible, false for hidden. Default is true.
  13323. * - backgroundRoundRadius: the round radius of the background, either backgroundFill or backgroundBorder must be specified.
  13324. * - 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.
  13325. * - 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.
  13326. * - backgroundBorderThickness: if a backgroundBorder is specified, its thickness can be set using this property
  13327. * - 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.
  13328. * - paddingTop: top padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  13329. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  13330. * - paddingRight: right padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  13331. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  13332. * - padding: top, left, right and bottom padding formatted as a single string (see BABYLON.PrimitiveThickness.fromString)
  13333. */
  13334. function ScreenSpaceCanvas2D(scene, settings) {
  13335. var _this;
  13336. BABYLON.Prim2DBase._isCanvasInit = true;
  13337. _this = _super.call(this, scene, settings) || this;
  13338. return _this;
  13339. }
  13340. return ScreenSpaceCanvas2D;
  13341. }(Canvas2D));
  13342. ScreenSpaceCanvas2D = __decorate([
  13343. BABYLON.className("ScreenSpaceCanvas2D", "BABYLON")
  13344. ], ScreenSpaceCanvas2D);
  13345. BABYLON.ScreenSpaceCanvas2D = ScreenSpaceCanvas2D;
  13346. var Canvas2D_1;
  13347. })(BABYLON || (BABYLON = {}));
  13348. var __extends = (this && this.__extends) || function (d, b) {
  13349. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  13350. function __() { this.constructor = d; }
  13351. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13352. };
  13353. var BABYLON;
  13354. (function (BABYLON) {
  13355. /**
  13356. * This is the class that is used to display a World Space Canvas into a 3D scene
  13357. */
  13358. var WorldSpaceCanvas2DNode = (function (_super) {
  13359. __extends(WorldSpaceCanvas2DNode, _super);
  13360. function WorldSpaceCanvas2DNode(name, scene, canvas) {
  13361. var _this = _super.call(this, name, scene) || this;
  13362. _this._canvas = canvas;
  13363. return _this;
  13364. }
  13365. WorldSpaceCanvas2DNode.prototype.dispose = function () {
  13366. _super.prototype.dispose.call(this);
  13367. if (this._canvas) {
  13368. this._canvas.dispose();
  13369. this._canvas = null;
  13370. }
  13371. };
  13372. return WorldSpaceCanvas2DNode;
  13373. }(BABYLON.Mesh));
  13374. BABYLON.WorldSpaceCanvas2DNode = WorldSpaceCanvas2DNode;
  13375. })(BABYLON || (BABYLON = {}));
  13376. var __extends = (this && this.__extends) || function (d, b) {
  13377. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  13378. function __() { this.constructor = d; }
  13379. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13380. };
  13381. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  13382. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  13383. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  13384. 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;
  13385. return c > 3 && r && Object.defineProperty(target, key, r), r;
  13386. };
  13387. var BABYLON;
  13388. (function (BABYLON) {
  13389. var Command = (function () {
  13390. function Command(execute, canExecute) {
  13391. if (!execute) {
  13392. throw Error("At least an execute lambda must be given at Command creation time");
  13393. }
  13394. this._canExecuteChanged = null;
  13395. this._lastCanExecuteResult = null;
  13396. this.execute = execute;
  13397. this.canExecute = canExecute;
  13398. }
  13399. Command.prototype.canExecute = function (parameter) {
  13400. var res = true;
  13401. if (this._canExecute) {
  13402. res = this._canExecute(parameter);
  13403. }
  13404. if (res !== this._lastCanExecuteResult) {
  13405. if (this._canExecuteChanged && this._canExecuteChanged.hasObservers()) {
  13406. this._canExecuteChanged.notifyObservers(null);
  13407. }
  13408. this._lastCanExecuteResult = res;
  13409. }
  13410. return res;
  13411. };
  13412. Command.prototype.execute = function (parameter) {
  13413. this._execute(parameter);
  13414. };
  13415. Object.defineProperty(Command.prototype, "canExecuteChanged", {
  13416. get: function () {
  13417. if (!this._canExecuteChanged) {
  13418. this._canExecuteChanged = new BABYLON.Observable();
  13419. }
  13420. return this._canExecuteChanged;
  13421. },
  13422. enumerable: true,
  13423. configurable: true
  13424. });
  13425. return Command;
  13426. }());
  13427. BABYLON.Command = Command;
  13428. var UIElement = (function (_super) {
  13429. __extends(UIElement, _super);
  13430. function UIElement(settings) {
  13431. var _this = _super.call(this) || this;
  13432. if (!settings) {
  13433. throw Error("A settings object must be passed with at least either a parent or owner parameter");
  13434. }
  13435. var type = BABYLON.Tools.getFullClassName(_this);
  13436. _this._ownerWindow = null;
  13437. _this._parent = null;
  13438. _this._visualPlaceholder = null;
  13439. _this._visualTemplateRoot = null;
  13440. _this._visualChildrenPlaceholder = null;
  13441. _this._hierarchyDepth = 0;
  13442. _this._renderingTemplateName = (settings.templateName != null) ? settings.templateName : GUIManager.DefaultTemplateName;
  13443. _this._style = (settings.styleName != null) ? GUIManager.getStyle(type, settings.styleName) : null;
  13444. _this._flags = 0;
  13445. _this._id = (settings.id != null) ? settings.id : null;
  13446. _this._uid = null;
  13447. _this._width = (settings.width != null) ? settings.width : null;
  13448. _this._height = (settings.height != null) ? settings.height : null;
  13449. _this._minWidth = (settings.minWidth != null) ? settings.minWidth : 0;
  13450. _this._minHeight = (settings.minHeight != null) ? settings.minHeight : 0;
  13451. _this._maxWidth = (settings.maxWidth != null) ? settings.maxWidth : Number.MAX_VALUE;
  13452. _this._maxHeight = (settings.maxHeight != null) ? settings.maxHeight : Number.MAX_VALUE;
  13453. _this._margin = null;
  13454. _this._padding = null;
  13455. _this._marginAlignment = null;
  13456. _this._setFlags(UIElement.flagIsVisible | UIElement.flagIsEnabled);
  13457. // Default Margin Alignment for UIElement is stretch for horizontal/vertical and not left/bottom (which is the default for Canvas2D Primitives)
  13458. //this.marginAlignment.horizontal = PrimitiveAlignment.AlignStretch;
  13459. //this.marginAlignment.vertical = PrimitiveAlignment.AlignStretch;
  13460. // Set the layout/margin stuffs
  13461. if (settings.marginTop) {
  13462. _this.margin.setTop(settings.marginTop);
  13463. }
  13464. if (settings.marginLeft) {
  13465. _this.margin.setLeft(settings.marginLeft);
  13466. }
  13467. if (settings.marginRight) {
  13468. _this.margin.setRight(settings.marginRight);
  13469. }
  13470. if (settings.marginBottom) {
  13471. _this.margin.setBottom(settings.marginBottom);
  13472. }
  13473. if (settings.margin) {
  13474. if (typeof settings.margin === "string") {
  13475. _this.margin.fromString(settings.margin);
  13476. }
  13477. else {
  13478. _this.margin.fromUniformPixels(settings.margin);
  13479. }
  13480. }
  13481. if (settings.marginHAlignment) {
  13482. _this.marginAlignment.horizontal = settings.marginHAlignment;
  13483. }
  13484. if (settings.marginVAlignment) {
  13485. _this.marginAlignment.vertical = settings.marginVAlignment;
  13486. }
  13487. if (settings.marginAlignment) {
  13488. _this.marginAlignment.fromString(settings.marginAlignment);
  13489. }
  13490. if (settings.paddingTop) {
  13491. _this.padding.setTop(settings.paddingTop);
  13492. }
  13493. if (settings.paddingLeft) {
  13494. _this.padding.setLeft(settings.paddingLeft);
  13495. }
  13496. if (settings.paddingRight) {
  13497. _this.padding.setRight(settings.paddingRight);
  13498. }
  13499. if (settings.paddingBottom) {
  13500. _this.padding.setBottom(settings.paddingBottom);
  13501. }
  13502. if (settings.padding) {
  13503. _this.padding.fromString(settings.padding);
  13504. }
  13505. if (settings.paddingHAlignment) {
  13506. _this.paddingAlignment.horizontal = settings.paddingHAlignment;
  13507. }
  13508. if (settings.paddingVAlignment) {
  13509. _this.paddingAlignment.vertical = settings.paddingVAlignment;
  13510. }
  13511. if (settings.paddingAlignment) {
  13512. _this.paddingAlignment.fromString(settings.paddingAlignment);
  13513. }
  13514. if (settings.parent != null) {
  13515. _this._parent = settings.parent;
  13516. _this._hierarchyDepth = _this._parent._hierarchyDepth + 1;
  13517. }
  13518. return _this;
  13519. }
  13520. Object.defineProperty(UIElement, "enabledState", {
  13521. get: function () {
  13522. return UIElement._enableState;
  13523. },
  13524. enumerable: true,
  13525. configurable: true
  13526. });
  13527. Object.defineProperty(UIElement, "disabledState", {
  13528. get: function () {
  13529. return UIElement._disabledState;
  13530. },
  13531. enumerable: true,
  13532. configurable: true
  13533. });
  13534. Object.defineProperty(UIElement, "mouseOverState", {
  13535. get: function () {
  13536. return UIElement._mouseOverState;
  13537. },
  13538. enumerable: true,
  13539. configurable: true
  13540. });
  13541. UIElement.prototype.dispose = function () {
  13542. if (this.isDisposed) {
  13543. return false;
  13544. }
  13545. if (this._renderingTemplate) {
  13546. this._renderingTemplate.detach();
  13547. this._renderingTemplate = null;
  13548. }
  13549. _super.prototype.dispose.call(this);
  13550. // Don't set to null, it may upset somebody...
  13551. this.animations.splice(0);
  13552. return true;
  13553. };
  13554. /**
  13555. * Returns as a new array populated with the Animatable used by the primitive. Must be overloaded by derived primitives.
  13556. * Look at Sprite2D for more information
  13557. */
  13558. UIElement.prototype.getAnimatables = function () {
  13559. return new Array();
  13560. };
  13561. // TODO
  13562. // PROPERTIES
  13563. // Style
  13564. // Id
  13565. // Parent/Children
  13566. // ActualWidth/Height, MinWidth/Height, MaxWidth/Height,
  13567. // Alignment/Margin
  13568. // Visibility, IsVisible
  13569. // IsEnabled (is false, control is disabled, no interaction and a specific render state)
  13570. // CacheMode of Visual Elements
  13571. // Focusable/IsFocused
  13572. // IsPointerCaptured, CapturePointer, IsPointerDirectlyOver, IsPointerOver. De-correlate mouse, stylus, touch?
  13573. // ContextMenu
  13574. // Cursor
  13575. // DesiredSize
  13576. // IsInputEnable ?
  13577. // Opacity, OpacityMask ?
  13578. // SnapToDevicePixels
  13579. // Tag
  13580. // ToolTip
  13581. // METHODS
  13582. // BringIntoView (for scrollable content, to move the scroll to bring the given element visible in the parent's area)
  13583. // Capture/ReleaseCapture (mouse, touch, stylus)
  13584. // Focus
  13585. // PointFrom/ToScreen to translate coordinates
  13586. // EVENTS
  13587. // ContextMenuOpening/Closing/Changed
  13588. // DragEnter/LeaveOver, Drop
  13589. // Got/LostFocus
  13590. // IsEnabledChanged
  13591. // IsPointerOver/DirectlyOverChanged
  13592. // IsVisibleChanged
  13593. // KeyDown/Up
  13594. // LayoutUpdated ?
  13595. // Pointer related events
  13596. // SizeChanged
  13597. // ToolTipOpening/Closing
  13598. UIElement.prototype.findById = function (id) {
  13599. if (this._id === id) {
  13600. return this;
  13601. }
  13602. var children = this._getChildren();
  13603. for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
  13604. var child = children_1[_i];
  13605. var r = child.findById(id);
  13606. if (r != null) {
  13607. return r;
  13608. }
  13609. }
  13610. };
  13611. Object.defineProperty(UIElement.prototype, "ownerWindow", {
  13612. get: function () {
  13613. return this._ownerWindow;
  13614. },
  13615. enumerable: true,
  13616. configurable: true
  13617. });
  13618. Object.defineProperty(UIElement.prototype, "style", {
  13619. get: function () {
  13620. if (!this.style) {
  13621. return GUIManager.DefaultStyleName;
  13622. }
  13623. return this._style.name;
  13624. },
  13625. set: function (value) {
  13626. if (this._style && (this._style.name === value)) {
  13627. return;
  13628. }
  13629. var newStyle = null;
  13630. if (value) {
  13631. newStyle = GUIManager.getStyle(BABYLON.Tools.getFullClassName(this), value);
  13632. if (!newStyle) {
  13633. throw Error("Couldn't find Style " + value + " for UIElement " + BABYLON.Tools.getFullClassName(this));
  13634. }
  13635. }
  13636. if (this._style) {
  13637. this._style.removeStyle(this);
  13638. }
  13639. if (newStyle) {
  13640. newStyle.applyStyle(this);
  13641. }
  13642. this._style = newStyle;
  13643. },
  13644. enumerable: true,
  13645. configurable: true
  13646. });
  13647. Object.defineProperty(UIElement.prototype, "id", {
  13648. /**
  13649. * A string that identifies the UIElement.
  13650. * The id is optional and there's possible collision with other UIElement's id as the uniqueness is not supported.
  13651. */
  13652. get: function () {
  13653. return this._id;
  13654. },
  13655. set: function (value) {
  13656. if (this._id === value) {
  13657. return;
  13658. }
  13659. this._id = value;
  13660. },
  13661. enumerable: true,
  13662. configurable: true
  13663. });
  13664. Object.defineProperty(UIElement.prototype, "uid", {
  13665. /**
  13666. * Return a unique id automatically generated.
  13667. * This property is mainly used for serialization to ensure a perfect way of identifying a UIElement
  13668. */
  13669. get: function () {
  13670. if (!this._uid) {
  13671. this._uid = BABYLON.Tools.RandomId();
  13672. }
  13673. return this._uid;
  13674. },
  13675. enumerable: true,
  13676. configurable: true
  13677. });
  13678. Object.defineProperty(UIElement.prototype, "hierarchyDepth", {
  13679. get: function () {
  13680. return this._hierarchyDepth;
  13681. },
  13682. enumerable: true,
  13683. configurable: true
  13684. });
  13685. Object.defineProperty(UIElement.prototype, "parent", {
  13686. get: function () {
  13687. return this._parent;
  13688. },
  13689. set: function (value) {
  13690. this._parent = value;
  13691. },
  13692. enumerable: true,
  13693. configurable: true
  13694. });
  13695. Object.defineProperty(UIElement.prototype, "width", {
  13696. get: function () {
  13697. return this._width;
  13698. },
  13699. set: function (value) {
  13700. this._width = value;
  13701. },
  13702. enumerable: true,
  13703. configurable: true
  13704. });
  13705. Object.defineProperty(UIElement.prototype, "height", {
  13706. get: function () {
  13707. return this._height;
  13708. },
  13709. set: function (value) {
  13710. this._height = value;
  13711. },
  13712. enumerable: true,
  13713. configurable: true
  13714. });
  13715. Object.defineProperty(UIElement.prototype, "minWidth", {
  13716. get: function () {
  13717. return this._minWidth;
  13718. },
  13719. set: function (value) {
  13720. this._minWidth = value;
  13721. },
  13722. enumerable: true,
  13723. configurable: true
  13724. });
  13725. Object.defineProperty(UIElement.prototype, "minHheight", {
  13726. get: function () {
  13727. return this._minHeight;
  13728. },
  13729. enumerable: true,
  13730. configurable: true
  13731. });
  13732. Object.defineProperty(UIElement.prototype, "minHeight", {
  13733. set: function (value) {
  13734. this._minHeight = value;
  13735. },
  13736. enumerable: true,
  13737. configurable: true
  13738. });
  13739. Object.defineProperty(UIElement.prototype, "maxWidth", {
  13740. get: function () {
  13741. return this._maxWidth;
  13742. },
  13743. set: function (value) {
  13744. this._maxWidth = value;
  13745. },
  13746. enumerable: true,
  13747. configurable: true
  13748. });
  13749. Object.defineProperty(UIElement.prototype, "maxHeight", {
  13750. get: function () {
  13751. return this._maxHeight;
  13752. },
  13753. set: function (value) {
  13754. this._maxHeight = value;
  13755. },
  13756. enumerable: true,
  13757. configurable: true
  13758. });
  13759. Object.defineProperty(UIElement.prototype, "actualWidth", {
  13760. get: function () {
  13761. return this._actualWidth;
  13762. },
  13763. set: function (value) {
  13764. this._actualWidth = value;
  13765. },
  13766. enumerable: true,
  13767. configurable: true
  13768. });
  13769. Object.defineProperty(UIElement.prototype, "actualHeight", {
  13770. get: function () {
  13771. return this._actualHeight;
  13772. },
  13773. set: function (value) {
  13774. this._actualHeight = value;
  13775. },
  13776. enumerable: true,
  13777. configurable: true
  13778. });
  13779. Object.defineProperty(UIElement.prototype, "margin", {
  13780. get: function () {
  13781. var _this = this;
  13782. if (!this._margin) {
  13783. this._margin = new BABYLON.PrimitiveThickness(function () {
  13784. if (!_this.parent) {
  13785. return null;
  13786. }
  13787. return _this.parent.margin;
  13788. });
  13789. }
  13790. return this._margin;
  13791. },
  13792. set: function (value) {
  13793. this.margin.copyFrom(value);
  13794. },
  13795. enumerable: true,
  13796. configurable: true
  13797. });
  13798. Object.defineProperty(UIElement.prototype, "_hasMargin", {
  13799. get: function () {
  13800. return (this._margin !== null && !this._margin.isDefault) || (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  13801. },
  13802. enumerable: true,
  13803. configurable: true
  13804. });
  13805. Object.defineProperty(UIElement.prototype, "padding", {
  13806. get: function () {
  13807. var _this = this;
  13808. if (!this._padding) {
  13809. this._padding = new BABYLON.PrimitiveThickness(function () {
  13810. if (!_this.parent) {
  13811. return null;
  13812. }
  13813. return _this.parent.padding;
  13814. });
  13815. }
  13816. return this._padding;
  13817. },
  13818. set: function (value) {
  13819. this.padding.copyFrom(value);
  13820. },
  13821. enumerable: true,
  13822. configurable: true
  13823. });
  13824. Object.defineProperty(UIElement.prototype, "_hasPadding", {
  13825. get: function () {
  13826. return this._padding !== null && !this._padding.isDefault;
  13827. },
  13828. enumerable: true,
  13829. configurable: true
  13830. });
  13831. Object.defineProperty(UIElement.prototype, "marginAlignment", {
  13832. get: function () {
  13833. if (!this._marginAlignment) {
  13834. this._marginAlignment = new BABYLON.PrimitiveAlignment();
  13835. }
  13836. return this._marginAlignment;
  13837. },
  13838. set: function (value) {
  13839. this.marginAlignment.copyFrom(value);
  13840. },
  13841. enumerable: true,
  13842. configurable: true
  13843. });
  13844. Object.defineProperty(UIElement.prototype, "_hasMarginAlignment", {
  13845. /**
  13846. * Check if there a marginAlignment specified (non null and not default)
  13847. */
  13848. get: function () {
  13849. return (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  13850. },
  13851. enumerable: true,
  13852. configurable: true
  13853. });
  13854. Object.defineProperty(UIElement.prototype, "paddingAlignment", {
  13855. get: function () {
  13856. if (!this._paddingAlignment) {
  13857. this._paddingAlignment = new BABYLON.PrimitiveAlignment();
  13858. }
  13859. return this._paddingAlignment;
  13860. },
  13861. set: function (value) {
  13862. this.paddingAlignment.copyFrom(value);
  13863. },
  13864. enumerable: true,
  13865. configurable: true
  13866. });
  13867. Object.defineProperty(UIElement.prototype, "_hasPaddingAlignment", {
  13868. /**
  13869. * Check if there a marginAlignment specified (non null and not default)
  13870. */
  13871. get: function () {
  13872. return (this._paddingAlignment !== null && !this._paddingAlignment.isDefault);
  13873. },
  13874. enumerable: true,
  13875. configurable: true
  13876. });
  13877. Object.defineProperty(UIElement.prototype, "isVisible", {
  13878. get: function () {
  13879. return this._isFlagSet(UIElement.flagIsVisible);
  13880. },
  13881. set: function (value) {
  13882. if (this.isVisible === value) {
  13883. return;
  13884. }
  13885. this._visualPlaceholder.levelVisible = value;
  13886. this._changeFlags(UIElement.flagIsVisible, value);
  13887. },
  13888. enumerable: true,
  13889. configurable: true
  13890. });
  13891. Object.defineProperty(UIElement.prototype, "isEnabled", {
  13892. get: function () {
  13893. return this._isFlagSet(UIElement.flagIsEnabled);
  13894. },
  13895. set: function (value) {
  13896. this._changeFlags(UIElement.flagIsEnabled, value);
  13897. },
  13898. enumerable: true,
  13899. configurable: true
  13900. });
  13901. Object.defineProperty(UIElement.prototype, "isFocused", {
  13902. get: function () {
  13903. return this._isFlagSet(UIElement.flagIsFocus);
  13904. },
  13905. set: function (value) {
  13906. // If the UIElement doesn't accept focus, set it on its parent
  13907. if (!this.isFocusable) {
  13908. var p = this.parent;
  13909. if (!p) {
  13910. return;
  13911. }
  13912. p.isFocused = value;
  13913. }
  13914. // If the focus is being set, notify the Focus Manager
  13915. if (value) {
  13916. this.ownerWindow.focusManager.setFocusOn(this, this.getFocusScope());
  13917. }
  13918. this._changeFlags(UIElement.flagIsFocus, value);
  13919. },
  13920. enumerable: true,
  13921. configurable: true
  13922. });
  13923. Object.defineProperty(UIElement.prototype, "isMouseOver", {
  13924. get: function () {
  13925. return this._isFlagSet(UIElement.flagIsMouseOver);
  13926. },
  13927. set: function (value) {
  13928. this._changeFlags(UIElement.flagIsMouseOver, value);
  13929. },
  13930. enumerable: true,
  13931. configurable: true
  13932. });
  13933. Object.defineProperty(UIElement.prototype, "isFocusScope", {
  13934. get: function () {
  13935. return this._isFlagSet(UIElement.flagIsFocusScope);
  13936. },
  13937. set: function (value) {
  13938. this._changeFlags(UIElement.flagIsFocusScope, value);
  13939. },
  13940. enumerable: true,
  13941. configurable: true
  13942. });
  13943. Object.defineProperty(UIElement.prototype, "isFocusable", {
  13944. get: function () {
  13945. return this._isFlagSet(UIElement.flagIsFocusable);
  13946. },
  13947. set: function (value) {
  13948. this._changeFlags(UIElement.flagIsFocusable, value);
  13949. },
  13950. enumerable: true,
  13951. configurable: true
  13952. });
  13953. // 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)
  13954. UIElement.prototype.getFocusScope = function () {
  13955. if (this.isFocusScope) {
  13956. return this;
  13957. }
  13958. var p = this.parent;
  13959. if (!p) {
  13960. return null;
  13961. }
  13962. return p.getFocusScope();
  13963. };
  13964. /**
  13965. * Check if a given flag is set
  13966. * @param flag the flag value
  13967. * @return true if set, false otherwise
  13968. */
  13969. UIElement.prototype._isFlagSet = function (flag) {
  13970. return (this._flags & flag) !== 0;
  13971. };
  13972. /**
  13973. * Check if all given flags are set
  13974. * @param flags the flags ORed
  13975. * @return true if all the flags are set, false otherwise
  13976. */
  13977. UIElement.prototype._areAllFlagsSet = function (flags) {
  13978. return (this._flags & flags) === flags;
  13979. };
  13980. /**
  13981. * Check if at least one flag of the given flags is set
  13982. * @param flags the flags ORed
  13983. * @return true if at least one flag is set, false otherwise
  13984. */
  13985. UIElement.prototype._areSomeFlagsSet = function (flags) {
  13986. return (this._flags & flags) !== 0;
  13987. };
  13988. /**
  13989. * Clear the given flags
  13990. * @param flags the flags to clear
  13991. */
  13992. UIElement.prototype._clearFlags = function (flags) {
  13993. this._flags &= ~flags;
  13994. };
  13995. /**
  13996. * Set the given flags to true state
  13997. * @param flags the flags ORed to set
  13998. * @return the flags state before this call
  13999. */
  14000. UIElement.prototype._setFlags = function (flags) {
  14001. var cur = this._flags;
  14002. this._flags |= flags;
  14003. return cur;
  14004. };
  14005. /**
  14006. * Change the state of the given flags
  14007. * @param flags the flags ORed to change
  14008. * @param state true to set them, false to clear them
  14009. */
  14010. UIElement.prototype._changeFlags = function (flags, state) {
  14011. if (state) {
  14012. this._flags |= flags;
  14013. }
  14014. else {
  14015. this._flags &= ~flags;
  14016. }
  14017. };
  14018. UIElement.prototype._assignTemplate = function (templateName) {
  14019. if (!templateName) {
  14020. templateName = GUIManager.DefaultTemplateName;
  14021. }
  14022. var className = BABYLON.Tools.getFullClassName(this);
  14023. if (!className) {
  14024. throw Error("Couldn't access class name of this UIElement, you have to decorate the type with the className decorator");
  14025. }
  14026. var factory = GUIManager.getRenderingTemplate(className, templateName);
  14027. if (!factory) {
  14028. throw Error("Couldn't get the renderingTemplate " + templateName + " of class " + className);
  14029. }
  14030. this._renderingTemplateName = templateName;
  14031. this._renderingTemplate = factory();
  14032. this._renderingTemplate.attach(this);
  14033. };
  14034. UIElement.prototype._createVisualTree = function () {
  14035. var parentPrim = this.ownerWindow.canvas;
  14036. if (this.parent) {
  14037. parentPrim = this.parent.visualChildrenPlaceholder;
  14038. }
  14039. if (!this._renderingTemplate) {
  14040. this._assignTemplate(this._renderingTemplateName);
  14041. }
  14042. this._visualPlaceholder = new BABYLON.Group2D({ parent: parentPrim, id: "GUI " + BABYLON.Tools.getClassName(this) + " RootGroup of " + this.id });
  14043. var p = this._visualPlaceholder;
  14044. p.addExternalData("_GUIOwnerElement_", this);
  14045. p.dataSource = this;
  14046. p.createSimpleDataBinding(BABYLON.Prim2DBase.widthProperty, "width", BABYLON.DataBinding.MODE_ONEWAY);
  14047. p.createSimpleDataBinding(BABYLON.Prim2DBase.heightProperty, "height", BABYLON.DataBinding.MODE_ONEWAY);
  14048. p.createSimpleDataBinding(BABYLON.Prim2DBase.actualWidthProperty, "actualWidth", BABYLON.DataBinding.MODE_ONEWAYTOSOURCE);
  14049. p.createSimpleDataBinding(BABYLON.Prim2DBase.actualHeightProperty, "actualHeight", BABYLON.DataBinding.MODE_ONEWAYTOSOURCE);
  14050. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginProperty, "margin", BABYLON.DataBinding.MODE_ONEWAY);
  14051. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginAlignmentProperty, "marginAlignment", BABYLON.DataBinding.MODE_ONEWAY);
  14052. this.createVisualTree();
  14053. };
  14054. UIElement.prototype._patchUIElement = function (ownerWindow, parent) {
  14055. if (ownerWindow) {
  14056. if (!this._ownerWindow) {
  14057. ownerWindow._registerVisualToBuild(this);
  14058. }
  14059. this._ownerWindow = ownerWindow;
  14060. }
  14061. this._parent = parent;
  14062. if (parent) {
  14063. this._hierarchyDepth = parent.hierarchyDepth + 1;
  14064. }
  14065. var children = this._getChildren();
  14066. if (children) {
  14067. for (var _i = 0, children_2 = children; _i < children_2.length; _i++) {
  14068. var curChild = children_2[_i];
  14069. curChild._patchUIElement(ownerWindow, this);
  14070. }
  14071. }
  14072. };
  14073. // 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.
  14074. UIElement.prototype._getDataSource = function () {
  14075. var levelDS = _super.prototype._getDataSource.call(this);
  14076. if (levelDS != null) {
  14077. return levelDS;
  14078. }
  14079. var p = this.parent;
  14080. if (p != null) {
  14081. return p.dataSource;
  14082. }
  14083. return null;
  14084. };
  14085. UIElement.prototype.createVisualTree = function () {
  14086. var res = this._renderingTemplate.createVisualTree(this, this._visualPlaceholder);
  14087. this._visualTemplateRoot = res.root;
  14088. this._visualChildrenPlaceholder = res.contentPlaceholder;
  14089. };
  14090. Object.defineProperty(UIElement.prototype, "visualPlaceholder", {
  14091. get: function () {
  14092. return this._visualPlaceholder;
  14093. },
  14094. enumerable: true,
  14095. configurable: true
  14096. });
  14097. Object.defineProperty(UIElement.prototype, "visualTemplateRoot", {
  14098. get: function () {
  14099. return this._visualTemplateRoot;
  14100. },
  14101. enumerable: true,
  14102. configurable: true
  14103. });
  14104. Object.defineProperty(UIElement.prototype, "visualChildrenPlaceholder", {
  14105. get: function () {
  14106. return this._visualChildrenPlaceholder;
  14107. },
  14108. enumerable: true,
  14109. configurable: true
  14110. });
  14111. Object.defineProperty(UIElement.prototype, "_position", {
  14112. get: function () { return null; } // TODO use abstract keyword when TS 2.0 will be approved
  14113. ,
  14114. enumerable: true,
  14115. configurable: true
  14116. });
  14117. return UIElement;
  14118. }(BABYLON.SmartPropertyBase));
  14119. UIElement.UIELEMENT_PROPCOUNT = 16;
  14120. UIElement.flagVisualToBuild = 0x0000001;
  14121. UIElement.flagIsVisible = 0x0000002;
  14122. UIElement.flagIsFocus = 0x0000004;
  14123. UIElement.flagIsFocusScope = 0x0000008;
  14124. UIElement.flagIsFocusable = 0x0000010;
  14125. UIElement.flagIsEnabled = 0x0000020;
  14126. UIElement.flagIsMouseOver = 0x0000040;
  14127. UIElement._enableState = "Enabled";
  14128. UIElement._disabledState = "Disabled";
  14129. UIElement._mouseOverState = "MouseOver";
  14130. __decorate([
  14131. BABYLON.dependencyProperty(0, function (pi) { return UIElement.parentProperty = pi; })
  14132. ], UIElement.prototype, "parent", null);
  14133. __decorate([
  14134. BABYLON.dependencyProperty(1, function (pi) { return UIElement.widthProperty = pi; })
  14135. ], UIElement.prototype, "width", null);
  14136. __decorate([
  14137. BABYLON.dependencyProperty(2, function (pi) { return UIElement.heightProperty = pi; })
  14138. ], UIElement.prototype, "height", null);
  14139. __decorate([
  14140. BABYLON.dependencyProperty(3, function (pi) { return UIElement.minWidthProperty = pi; })
  14141. ], UIElement.prototype, "minWidth", null);
  14142. __decorate([
  14143. BABYLON.dependencyProperty(4, function (pi) { return UIElement.minHeightProperty = pi; })
  14144. ], UIElement.prototype, "minHheight", null);
  14145. __decorate([
  14146. BABYLON.dependencyProperty(5, function (pi) { return UIElement.maxWidthProperty = pi; })
  14147. ], UIElement.prototype, "maxWidth", null);
  14148. __decorate([
  14149. BABYLON.dependencyProperty(6, function (pi) { return UIElement.maxHeightProperty = pi; })
  14150. ], UIElement.prototype, "maxHeight", null);
  14151. __decorate([
  14152. BABYLON.dependencyProperty(7, function (pi) { return UIElement.actualWidthProperty = pi; })
  14153. ], UIElement.prototype, "actualWidth", null);
  14154. __decorate([
  14155. BABYLON.dependencyProperty(8, function (pi) { return UIElement.actualHeightProperty = pi; })
  14156. ], UIElement.prototype, "actualHeight", null);
  14157. __decorate([
  14158. BABYLON.dynamicLevelProperty(9, function (pi) { return UIElement.marginProperty = pi; })
  14159. ], UIElement.prototype, "margin", null);
  14160. __decorate([
  14161. BABYLON.dynamicLevelProperty(10, function (pi) { return UIElement.paddingProperty = pi; })
  14162. ], UIElement.prototype, "padding", null);
  14163. __decorate([
  14164. BABYLON.dynamicLevelProperty(11, function (pi) { return UIElement.marginAlignmentProperty = pi; })
  14165. ], UIElement.prototype, "marginAlignment", null);
  14166. __decorate([
  14167. BABYLON.dynamicLevelProperty(12, function (pi) { return UIElement.paddingAlignmentProperty = pi; })
  14168. ], UIElement.prototype, "paddingAlignment", null);
  14169. __decorate([
  14170. BABYLON.dynamicLevelProperty(13, function (pi) { return UIElement.isEnabledProperty = pi; })
  14171. ], UIElement.prototype, "isEnabled", null);
  14172. __decorate([
  14173. BABYLON.dynamicLevelProperty(14, function (pi) { return UIElement.isFocusedProperty = pi; })
  14174. ], UIElement.prototype, "isFocused", null);
  14175. __decorate([
  14176. BABYLON.dynamicLevelProperty(15, function (pi) { return UIElement.isMouseOverProperty = pi; })
  14177. ], UIElement.prototype, "isMouseOver", null);
  14178. BABYLON.UIElement = UIElement;
  14179. var UIElementStyle = (function () {
  14180. function UIElementStyle() {
  14181. }
  14182. Object.defineProperty(UIElementStyle.prototype, "name", {
  14183. get: function () { return null; } // TODO use abstract keyword when TS 2.0 will be approved
  14184. ,
  14185. enumerable: true,
  14186. configurable: true
  14187. });
  14188. return UIElementStyle;
  14189. }());
  14190. BABYLON.UIElementStyle = UIElementStyle;
  14191. var GUIManager = (function () {
  14192. function GUIManager() {
  14193. }
  14194. /////////////////////////////////////////////////////////////////////////////////////////////////////
  14195. // DATA TEMPLATE MANAGER
  14196. GUIManager.registerDataTemplate = function (className, factory) {
  14197. };
  14198. // DATA TEMPLATE MANAGER
  14199. /////////////////////////////////////////////////////////////////////////////////////////////////////
  14200. /////////////////////////////////////////////////////////////////////////////////////////////////////
  14201. // STYLE MANAGER
  14202. GUIManager.getStyle = function (uiElType, styleName) {
  14203. var styles = GUIManager.stylesByUIElement.get(uiElType);
  14204. if (!styles) {
  14205. throw Error("The type " + uiElType + " is unknown, no style were registered for it.");
  14206. }
  14207. var style = styles.get(styleName);
  14208. if (!style) {
  14209. throw Error("Couldn't find Template " + styleName + " of UIElement type " + uiElType);
  14210. }
  14211. return style;
  14212. };
  14213. GUIManager.registerStyle = function (uiElType, templateName, style) {
  14214. var templates = GUIManager.stylesByUIElement.getOrAddWithFactory(uiElType, function () { return new BABYLON.StringDictionary(); });
  14215. if (templates.contains(templateName)) {
  14216. templates[templateName] = style;
  14217. }
  14218. else {
  14219. templates.add(templateName, style);
  14220. }
  14221. };
  14222. Object.defineProperty(GUIManager, "DefaultStyleName", {
  14223. get: function () {
  14224. return GUIManager._defaultStyleName;
  14225. },
  14226. set: function (value) {
  14227. GUIManager._defaultStyleName = value;
  14228. },
  14229. enumerable: true,
  14230. configurable: true
  14231. });
  14232. // STYLE MANAGER
  14233. /////////////////////////////////////////////////////////////////////////////////////////////////////
  14234. /////////////////////////////////////////////////////////////////////////////////////////////////////
  14235. // RENDERING TEMPLATE MANAGER
  14236. GUIManager.getRenderingTemplate = function (uiElType, templateName) {
  14237. var templates = GUIManager.renderingTemplatesByUIElement.get(uiElType);
  14238. if (!templates) {
  14239. throw Error("The type " + uiElType + " is unknown, no Rendering Template were registered for it.");
  14240. }
  14241. var templateFactory = templates.get(templateName);
  14242. if (!templateFactory) {
  14243. throw Error("Couldn't find Template " + templateName + " of UI Element type " + uiElType);
  14244. }
  14245. return templateFactory;
  14246. };
  14247. GUIManager.registerRenderingTemplate = function (uiElType, templateName, factory) {
  14248. var templates = GUIManager.renderingTemplatesByUIElement.getOrAddWithFactory(uiElType, function () { return new BABYLON.StringDictionary(); });
  14249. if (templates.contains(templateName)) {
  14250. templates[templateName] = factory;
  14251. }
  14252. else {
  14253. templates.add(templateName, factory);
  14254. }
  14255. };
  14256. Object.defineProperty(GUIManager, "DefaultTemplateName", {
  14257. get: function () {
  14258. return GUIManager._defaultTemplateName;
  14259. },
  14260. set: function (value) {
  14261. GUIManager._defaultTemplateName = value;
  14262. },
  14263. enumerable: true,
  14264. configurable: true
  14265. });
  14266. return GUIManager;
  14267. }());
  14268. GUIManager.stylesByUIElement = new BABYLON.StringDictionary();
  14269. GUIManager.renderingTemplatesByUIElement = new BABYLON.StringDictionary();
  14270. // RENDERING TEMPLATE MANAGER
  14271. /////////////////////////////////////////////////////////////////////////////////////////////////////
  14272. GUIManager._defaultTemplateName = "Default";
  14273. GUIManager._defaultStyleName = "Default";
  14274. BABYLON.GUIManager = GUIManager;
  14275. var UIElementRenderingTemplateBase = (function () {
  14276. function UIElementRenderingTemplateBase() {
  14277. }
  14278. UIElementRenderingTemplateBase.prototype.attach = function (owner) {
  14279. this._owner = owner;
  14280. };
  14281. UIElementRenderingTemplateBase.prototype.detach = function () {
  14282. };
  14283. Object.defineProperty(UIElementRenderingTemplateBase.prototype, "owner", {
  14284. get: function () {
  14285. return this._owner;
  14286. },
  14287. enumerable: true,
  14288. configurable: true
  14289. });
  14290. return UIElementRenderingTemplateBase;
  14291. }());
  14292. BABYLON.UIElementRenderingTemplateBase = UIElementRenderingTemplateBase;
  14293. function registerWindowRenderingTemplate(uiElType, templateName, factory) {
  14294. return function () {
  14295. GUIManager.registerRenderingTemplate(uiElType, templateName, factory);
  14296. };
  14297. }
  14298. BABYLON.registerWindowRenderingTemplate = registerWindowRenderingTemplate;
  14299. })(BABYLON || (BABYLON = {}));
  14300. var __extends = (this && this.__extends) || function (d, b) {
  14301. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14302. function __() { this.constructor = d; }
  14303. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14304. };
  14305. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14306. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14307. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14308. 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;
  14309. return c > 3 && r && Object.defineProperty(target, key, r), r;
  14310. };
  14311. var BABYLON;
  14312. (function (BABYLON) {
  14313. var StackPanel = StackPanel_1 = (function (_super) {
  14314. __extends(StackPanel, _super);
  14315. function StackPanel(settings) {
  14316. var _this;
  14317. if (!settings) {
  14318. settings = {};
  14319. }
  14320. _this = _super.call(this, settings) || this;
  14321. _this.isOrientationHorizontal = (settings.isOrientationHorizontal == null) ? true : settings.isOrientationHorizontal;
  14322. _this._children = new Array();
  14323. if (settings.children != null) {
  14324. for (var _i = 0, _a = settings.children; _i < _a.length; _i++) {
  14325. var child = _a[_i];
  14326. _this._children.push(child);
  14327. }
  14328. }
  14329. return _this;
  14330. }
  14331. Object.defineProperty(StackPanel.prototype, "isOrientationHorizontal", {
  14332. get: function () {
  14333. return this._isOrientationHorizontal;
  14334. },
  14335. set: function (value) {
  14336. this._isOrientationHorizontal = value;
  14337. },
  14338. enumerable: true,
  14339. configurable: true
  14340. });
  14341. StackPanel.prototype.createVisualTree = function () {
  14342. _super.prototype.createVisualTree.call(this);
  14343. // A StackPanel Control has a Group2D, child of the visualPlaceHolder, which is the Children placeholder.
  14344. // The Children UIElement Tree will be create inside this placeholder.
  14345. this._childrenPlaceholder = new BABYLON.Group2D({ parent: this._visualPlaceholder, id: "StackPanel Children Placeholder of " + this.id });
  14346. var p = this._childrenPlaceholder;
  14347. p.layoutEngine = this.isOrientationHorizontal ? BABYLON.StackPanelLayoutEngine.Horizontal : BABYLON.StackPanelLayoutEngine.Vertical;
  14348. // 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.
  14349. p.dataSource = this;
  14350. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginProperty, "padding", BABYLON.DataBinding.MODE_ONEWAY);
  14351. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginAlignmentProperty, "paddingAlignment", BABYLON.DataBinding.MODE_ONEWAY);
  14352. // The UIElement set the childrenPlaceholder with the visual returned by the renderingTemplate.
  14353. // But it's not the case for a StackPanel, the placeholder of UIElement Children (the content)
  14354. this._visualChildrenPlaceholder = this._childrenPlaceholder;
  14355. };
  14356. Object.defineProperty(StackPanel.prototype, "children", {
  14357. get: function () {
  14358. return this._children;
  14359. },
  14360. enumerable: true,
  14361. configurable: true
  14362. });
  14363. StackPanel.prototype._getChildren = function () {
  14364. return this.children;
  14365. };
  14366. return StackPanel;
  14367. }(BABYLON.UIElement));
  14368. StackPanel.STACKPANEL_PROPCOUNT = BABYLON.UIElement.UIELEMENT_PROPCOUNT + 3;
  14369. __decorate([
  14370. BABYLON.dependencyProperty(StackPanel_1.STACKPANEL_PROPCOUNT + 0, function (pi) { return StackPanel_1.orientationHorizontalProperty = pi; })
  14371. ], StackPanel.prototype, "isOrientationHorizontal", null);
  14372. StackPanel = StackPanel_1 = __decorate([
  14373. BABYLON.className("StackPanel", "BABYLON")
  14374. ], StackPanel);
  14375. BABYLON.StackPanel = StackPanel;
  14376. var DefaultStackPanelRenderingTemplate = DefaultStackPanelRenderingTemplate_1 = (function (_super) {
  14377. __extends(DefaultStackPanelRenderingTemplate, _super);
  14378. function DefaultStackPanelRenderingTemplate() {
  14379. return _super.apply(this, arguments) || this;
  14380. }
  14381. DefaultStackPanelRenderingTemplate.prototype.createVisualTree = function (owner, visualPlaceholder) {
  14382. return { root: visualPlaceholder, contentPlaceholder: visualPlaceholder };
  14383. };
  14384. DefaultStackPanelRenderingTemplate.prototype.attach = function (owner) {
  14385. _super.prototype.attach.call(this, owner);
  14386. };
  14387. return DefaultStackPanelRenderingTemplate;
  14388. }(BABYLON.UIElementRenderingTemplateBase));
  14389. DefaultStackPanelRenderingTemplate = DefaultStackPanelRenderingTemplate_1 = __decorate([
  14390. BABYLON.registerWindowRenderingTemplate("BABYLON.StackPanel", "Default", function () { return new DefaultStackPanelRenderingTemplate_1(); })
  14391. ], DefaultStackPanelRenderingTemplate);
  14392. BABYLON.DefaultStackPanelRenderingTemplate = DefaultStackPanelRenderingTemplate;
  14393. var StackPanel_1, DefaultStackPanelRenderingTemplate_1;
  14394. })(BABYLON || (BABYLON = {}));
  14395. var __extends = (this && this.__extends) || function (d, b) {
  14396. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14397. function __() { this.constructor = d; }
  14398. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14399. };
  14400. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14401. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14402. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14403. 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;
  14404. return c > 3 && r && Object.defineProperty(target, key, r), r;
  14405. };
  14406. var BABYLON;
  14407. (function (BABYLON) {
  14408. var Control = Control_1 = (function (_super) {
  14409. __extends(Control, _super);
  14410. function Control(settings) {
  14411. return _super.call(this, settings) || this;
  14412. }
  14413. Object.defineProperty(Control.prototype, "background", {
  14414. get: function () {
  14415. if (!this._background) {
  14416. this._background = new BABYLON.ObservableStringDictionary(false);
  14417. }
  14418. return this._background;
  14419. },
  14420. set: function (value) {
  14421. this.background.copyFrom(value);
  14422. },
  14423. enumerable: true,
  14424. configurable: true
  14425. });
  14426. Object.defineProperty(Control.prototype, "border", {
  14427. get: function () {
  14428. return this._border;
  14429. },
  14430. set: function (value) {
  14431. this._border = value;
  14432. },
  14433. enumerable: true,
  14434. configurable: true
  14435. });
  14436. Object.defineProperty(Control.prototype, "borderThickness", {
  14437. get: function () {
  14438. return this._borderThickness;
  14439. },
  14440. set: function (value) {
  14441. this._borderThickness = value;
  14442. },
  14443. enumerable: true,
  14444. configurable: true
  14445. });
  14446. Object.defineProperty(Control.prototype, "fontName", {
  14447. get: function () {
  14448. return this._fontName;
  14449. },
  14450. set: function (value) {
  14451. this._fontName = value;
  14452. },
  14453. enumerable: true,
  14454. configurable: true
  14455. });
  14456. Object.defineProperty(Control.prototype, "foreground", {
  14457. get: function () {
  14458. return this._foreground;
  14459. },
  14460. set: function (value) {
  14461. this._foreground = value;
  14462. },
  14463. enumerable: true,
  14464. configurable: true
  14465. });
  14466. return Control;
  14467. }(BABYLON.UIElement));
  14468. Control.CONTROL_PROPCOUNT = BABYLON.UIElement.UIELEMENT_PROPCOUNT + 5;
  14469. __decorate([
  14470. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 0, function (pi) { return Control_1.backgroundProperty = pi; })
  14471. ], Control.prototype, "background", null);
  14472. __decorate([
  14473. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 1, function (pi) { return Control_1.borderProperty = pi; })
  14474. ], Control.prototype, "border", null);
  14475. __decorate([
  14476. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 2, function (pi) { return Control_1.borderThicknessProperty = pi; })
  14477. ], Control.prototype, "borderThickness", null);
  14478. __decorate([
  14479. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 3, function (pi) { return Control_1.fontNameProperty = pi; })
  14480. ], Control.prototype, "fontName", null);
  14481. __decorate([
  14482. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 4, function (pi) { return Control_1.foregroundProperty = pi; })
  14483. ], Control.prototype, "foreground", null);
  14484. Control = Control_1 = __decorate([
  14485. BABYLON.className("Control", "BABYLON")
  14486. ], Control);
  14487. BABYLON.Control = Control;
  14488. var Control_1;
  14489. })(BABYLON || (BABYLON = {}));
  14490. var __extends = (this && this.__extends) || function (d, b) {
  14491. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14492. function __() { this.constructor = d; }
  14493. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14494. };
  14495. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14496. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14497. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14498. 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;
  14499. return c > 3 && r && Object.defineProperty(target, key, r), r;
  14500. };
  14501. var BABYLON;
  14502. (function (BABYLON) {
  14503. var ContentControl = ContentControl_1 = (function (_super) {
  14504. __extends(ContentControl, _super);
  14505. function ContentControl(settings) {
  14506. var _this;
  14507. if (!settings) {
  14508. settings = {};
  14509. }
  14510. _this = _super.call(this, settings) || this;
  14511. if (settings.content != null) {
  14512. _this._content = settings.content;
  14513. }
  14514. return _this;
  14515. }
  14516. ContentControl.prototype.dispose = function () {
  14517. if (this.isDisposed) {
  14518. return false;
  14519. }
  14520. if (this.content && this.content.dispose) {
  14521. this.content.dispose();
  14522. this.content = null;
  14523. }
  14524. if (this.__contentUIElement) {
  14525. this.__contentUIElement.dispose();
  14526. this.__contentUIElement = null;
  14527. }
  14528. _super.prototype.dispose.call(this);
  14529. return true;
  14530. };
  14531. Object.defineProperty(ContentControl.prototype, "content", {
  14532. get: function () {
  14533. return this._content;
  14534. },
  14535. set: function (value) {
  14536. this._content = value;
  14537. },
  14538. enumerable: true,
  14539. configurable: true
  14540. });
  14541. Object.defineProperty(ContentControl.prototype, "_contentUIElement", {
  14542. get: function () {
  14543. if (!this.__contentUIElement) {
  14544. this._buildContentUIElement();
  14545. }
  14546. return this.__contentUIElement;
  14547. },
  14548. enumerable: true,
  14549. configurable: true
  14550. });
  14551. ContentControl.prototype._createVisualTree = function () {
  14552. // Base implementation will create the Group2D for the Visual Placeholder and its Visual Tree
  14553. _super.prototype._createVisualTree.call(this);
  14554. // A Content Control has a Group2D, child of the visualPlaceHolder, which is the Content placeholder.
  14555. // The Content UIElement Tree will be create inside this placeholder.
  14556. this._contentPlaceholder = new BABYLON.Group2D({ parent: this._visualPlaceholder, id: "ContentControl Content Placeholder of " + this.id });
  14557. var p = this._contentPlaceholder;
  14558. // 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.
  14559. p.dataSource = this;
  14560. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginProperty, "padding", BABYLON.DataBinding.MODE_ONEWAY);
  14561. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginAlignmentProperty, "paddingAlignment", BABYLON.DataBinding.MODE_ONEWAY);
  14562. // The UIElement set the childrenPlaceholder with the visual returned by the renderingTemplate.
  14563. // But it's not the case for a ContentControl, the placeholder of UIElement Children (the content)
  14564. this._visualChildrenPlaceholder = this._contentPlaceholder;
  14565. };
  14566. ContentControl.prototype._buildContentUIElement = function () {
  14567. var c = this._content;
  14568. this.__contentUIElement = null;
  14569. // Already a UIElement
  14570. if (c instanceof BABYLON.UIElement) {
  14571. this.__contentUIElement = c;
  14572. }
  14573. else if ((typeof c === "string") || (typeof c === "boolean") || (typeof c === "number")) {
  14574. var l = new BABYLON.Label({ parent: this, id: "Content of " + this.id });
  14575. var binding = new BABYLON.DataBinding();
  14576. binding.propertyPathName = "content";
  14577. binding.stringFormat = function (v) { return "" + v; };
  14578. binding.dataSource = this;
  14579. l.createDataBinding(BABYLON.Label.textProperty, binding);
  14580. this.__contentUIElement = l;
  14581. }
  14582. else {
  14583. }
  14584. if (this.__contentUIElement) {
  14585. this.__contentUIElement._patchUIElement(this.ownerWindow, this);
  14586. }
  14587. };
  14588. ContentControl.prototype._getChildren = function () {
  14589. var children = new Array();
  14590. if (this.content) {
  14591. children.push(this._contentUIElement);
  14592. }
  14593. return children;
  14594. };
  14595. return ContentControl;
  14596. }(BABYLON.Control));
  14597. ContentControl.CONTENTCONTROL_PROPCOUNT = BABYLON.Control.CONTROL_PROPCOUNT + 2;
  14598. __decorate([
  14599. BABYLON.dependencyProperty(BABYLON.Control.CONTROL_PROPCOUNT + 0, function (pi) { return ContentControl_1.contentProperty = pi; })
  14600. ], ContentControl.prototype, "content", null);
  14601. ContentControl = ContentControl_1 = __decorate([
  14602. BABYLON.className("ContentControl", "BABYLON")
  14603. ], ContentControl);
  14604. BABYLON.ContentControl = ContentControl;
  14605. var ContentControl_1;
  14606. })(BABYLON || (BABYLON = {}));
  14607. var __extends = (this && this.__extends) || function (d, b) {
  14608. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14609. function __() { this.constructor = d; }
  14610. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14611. };
  14612. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14613. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14614. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14615. 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;
  14616. return c > 3 && r && Object.defineProperty(target, key, r), r;
  14617. };
  14618. var BABYLON;
  14619. (function (BABYLON) {
  14620. var FocusScopeData = (function () {
  14621. function FocusScopeData(focusScope) {
  14622. this.focusScope = focusScope;
  14623. this.focusedElement = null;
  14624. }
  14625. return FocusScopeData;
  14626. }());
  14627. var FocusManager = (function () {
  14628. function FocusManager() {
  14629. this._focusScopes = new BABYLON.StringDictionary();
  14630. this._rootScope = new FocusScopeData(null);
  14631. this._activeScope = null;
  14632. }
  14633. FocusManager.prototype.setFocusOn = function (el, focusScope) {
  14634. var fsd = (focusScope != null) ? this._focusScopes.getOrAddWithFactory(focusScope.uid, function (k) { return new FocusScopeData(focusScope); }) : this._rootScope;
  14635. if (fsd.focusedElement !== el) {
  14636. // Remove focus from current
  14637. if (fsd.focusedElement) {
  14638. fsd.focusedElement.isFocused = false;
  14639. }
  14640. fsd.focusedElement = el;
  14641. }
  14642. if (this._activeScope !== fsd) {
  14643. this._activeScope = fsd;
  14644. }
  14645. };
  14646. return FocusManager;
  14647. }());
  14648. BABYLON.FocusManager = FocusManager;
  14649. var GUISceneData = (function () {
  14650. function GUISceneData(scene) {
  14651. this.scene = scene;
  14652. this.screenSpaceCanvas = new BABYLON.ScreenSpaceCanvas2D(scene, { id: "GUI Canvas", cachingStrategy: BABYLON.Canvas2D.CACHESTRATEGY_DONTCACHE });
  14653. this.focusManager = new FocusManager();
  14654. }
  14655. return GUISceneData;
  14656. }());
  14657. var Window = Window_1 = (function (_super) {
  14658. __extends(Window, _super);
  14659. function Window(scene, settings) {
  14660. var _this;
  14661. if (!settings) {
  14662. settings = {};
  14663. }
  14664. _this = _super.call(this, settings) || this;
  14665. // Per default a Window is focus scope
  14666. _this.isFocusScope = true;
  14667. _this.isActive = false;
  14668. if (!_this._UIElementVisualToBuildList) {
  14669. _this._UIElementVisualToBuildList = new Array();
  14670. }
  14671. // Patch the owner and also the parent property through the whole tree
  14672. _this._patchUIElement(_this, null);
  14673. // Screen Space UI
  14674. if (!settings.worldPosition && !settings.worldRotation) {
  14675. _this._sceneData = Window_1.getSceneData(scene);
  14676. _this._canvas = _this._sceneData.screenSpaceCanvas;
  14677. _this._isWorldSpaceCanvas = false;
  14678. _this._left = (settings.left != null) ? settings.left : 0;
  14679. _this._bottom = (settings.bottom != null) ? settings.bottom : 0;
  14680. }
  14681. else {
  14682. var w = (settings.width == null) ? 100 : settings.width;
  14683. var h = (settings.height == null) ? 100 : settings.height;
  14684. var wpos = (settings.worldPosition == null) ? BABYLON.Vector3.Zero() : settings.worldPosition;
  14685. var wrot = (settings.worldRotation == null) ? BABYLON.Quaternion.Identity() : settings.worldRotation;
  14686. _this._canvas = new BABYLON.WorldSpaceCanvas2D(scene, new BABYLON.Size(w, h), { id: "GUI Canvas", cachingStrategy: BABYLON.Canvas2D.CACHESTRATEGY_DONTCACHE, worldPosition: wpos, worldRotation: wrot });
  14687. _this._isWorldSpaceCanvas = true;
  14688. }
  14689. _this._renderObserver = _this._canvas.renderObservable.add(function (e, s) { return _this._canvasPreRender(); }, BABYLON.Canvas2D.RENDEROBSERVABLE_PRE);
  14690. _this._disposeObserver = _this._canvas.disposeObservable.add(function (e, s) { return _this._canvasDisposed(); });
  14691. _this._canvas.propertyChanged.add(function (e, s) {
  14692. if (e.propertyName === "overPrim") {
  14693. _this._overPrimChanged(e.oldValue, e.newValue);
  14694. }
  14695. });
  14696. _this._mouseOverUIElement = null;
  14697. return _this;
  14698. }
  14699. Object.defineProperty(Window.prototype, "canvas", {
  14700. get: function () {
  14701. return this._canvas;
  14702. },
  14703. enumerable: true,
  14704. configurable: true
  14705. });
  14706. Object.defineProperty(Window.prototype, "left", {
  14707. get: function () {
  14708. return this._left;
  14709. },
  14710. set: function (value) {
  14711. var old = new BABYLON.Vector2(this._left, this._bottom);
  14712. this._left = value;
  14713. this.onPropertyChanged("_position", old, this._position);
  14714. },
  14715. enumerable: true,
  14716. configurable: true
  14717. });
  14718. Object.defineProperty(Window.prototype, "bottom", {
  14719. get: function () {
  14720. return this._bottom;
  14721. },
  14722. set: function (value) {
  14723. var old = new BABYLON.Vector2(this._left, this._bottom);
  14724. this._bottom = value;
  14725. this.onPropertyChanged("_position", old, this._position);
  14726. },
  14727. enumerable: true,
  14728. configurable: true
  14729. });
  14730. Object.defineProperty(Window.prototype, "position", {
  14731. get: function () {
  14732. return this._position;
  14733. },
  14734. set: function (value) {
  14735. this._left = value.x;
  14736. this._bottom = value.y;
  14737. },
  14738. enumerable: true,
  14739. configurable: true
  14740. });
  14741. Object.defineProperty(Window.prototype, "isActive", {
  14742. get: function () {
  14743. return this._isActive;
  14744. },
  14745. set: function (value) {
  14746. this._isActive = value;
  14747. },
  14748. enumerable: true,
  14749. configurable: true
  14750. });
  14751. Object.defineProperty(Window.prototype, "focusManager", {
  14752. get: function () {
  14753. return this._sceneData.focusManager;
  14754. },
  14755. enumerable: true,
  14756. configurable: true
  14757. });
  14758. Object.defineProperty(Window.prototype, "_position", {
  14759. get: function () {
  14760. return new BABYLON.Vector2(this.left, this.bottom);
  14761. },
  14762. enumerable: true,
  14763. configurable: true
  14764. });
  14765. Window.prototype.createVisualTree = function () {
  14766. _super.prototype.createVisualTree.call(this);
  14767. var p = this._visualPlaceholder;
  14768. p.createSimpleDataBinding(BABYLON.Group2D.positionProperty, "position");
  14769. };
  14770. Window.prototype._registerVisualToBuild = function (uiel) {
  14771. if (uiel._isFlagSet(BABYLON.UIElement.flagVisualToBuild)) {
  14772. return;
  14773. }
  14774. if (!this._UIElementVisualToBuildList) {
  14775. this._UIElementVisualToBuildList = new Array();
  14776. }
  14777. this._UIElementVisualToBuildList.push(uiel);
  14778. uiel._setFlags(BABYLON.UIElement.flagVisualToBuild);
  14779. };
  14780. Window.prototype._overPrimChanged = function (oldPrim, newPrim) {
  14781. var curOverEl = this._mouseOverUIElement;
  14782. var newOverEl = null;
  14783. var curGroup = newPrim ? newPrim.traverseUp(function (p) { return p instanceof BABYLON.Group2D; }) : null;
  14784. while (curGroup) {
  14785. var uiel = curGroup.getExternalData("_GUIOwnerElement_");
  14786. if (uiel) {
  14787. newOverEl = uiel;
  14788. break;
  14789. }
  14790. curGroup = curGroup.parent ? curGroup.parent.traverseUp(function (p) { return p instanceof BABYLON.Group2D; }) : null;
  14791. }
  14792. if (curOverEl === newOverEl) {
  14793. return;
  14794. }
  14795. if (curOverEl) {
  14796. curOverEl.isMouseOver = false;
  14797. }
  14798. if (newOverEl) {
  14799. newOverEl.isMouseOver = true;
  14800. }
  14801. this._mouseOverUIElement = newOverEl;
  14802. };
  14803. Window.prototype._canvasPreRender = function () {
  14804. // Check if we have visual to create
  14805. if (this._UIElementVisualToBuildList.length > 0) {
  14806. // Sort the UI Element to get the highest (so lowest hierarchy depth) in the hierarchy tree first
  14807. var sortedElementList = this._UIElementVisualToBuildList.sort(function (a, b) { return a.hierarchyDepth - b.hierarchyDepth; });
  14808. for (var _i = 0, sortedElementList_1 = sortedElementList; _i < sortedElementList_1.length; _i++) {
  14809. var el = sortedElementList_1[_i];
  14810. el._createVisualTree();
  14811. }
  14812. this._UIElementVisualToBuildList.splice(0);
  14813. }
  14814. };
  14815. Window.prototype._canvasDisposed = function () {
  14816. this._canvas.disposeObservable.remove(this._disposeObserver);
  14817. this._canvas.renderObservable.remove(this._renderObserver);
  14818. };
  14819. Window.getSceneData = function (scene) {
  14820. return Window_1._sceneData.getOrAddWithFactory(scene.uid, function (k) { return new GUISceneData(scene); });
  14821. };
  14822. return Window;
  14823. }(BABYLON.ContentControl));
  14824. Window.WINDOW_PROPCOUNT = BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 4;
  14825. Window._sceneData = new BABYLON.StringDictionary();
  14826. __decorate([
  14827. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 0, function (pi) { return Window_1.leftProperty = pi; })
  14828. ], Window.prototype, "left", null);
  14829. __decorate([
  14830. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 1, function (pi) { return Window_1.bottomProperty = pi; })
  14831. ], Window.prototype, "bottom", null);
  14832. __decorate([
  14833. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 2, function (pi) { return Window_1.positionProperty = pi; })
  14834. ], Window.prototype, "position", null);
  14835. __decorate([
  14836. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 3, function (pi) { return Window_1.isActiveProperty = pi; })
  14837. ], Window.prototype, "isActive", null);
  14838. Window = Window_1 = __decorate([
  14839. BABYLON.className("Window", "BABYLON")
  14840. ], Window);
  14841. BABYLON.Window = Window;
  14842. var DefaultWindowRenderingTemplate = DefaultWindowRenderingTemplate_1 = (function (_super) {
  14843. __extends(DefaultWindowRenderingTemplate, _super);
  14844. function DefaultWindowRenderingTemplate() {
  14845. return _super.apply(this, arguments) || this;
  14846. }
  14847. DefaultWindowRenderingTemplate.prototype.createVisualTree = function (owner, visualPlaceholder) {
  14848. var r = new BABYLON.Rectangle2D({ parent: visualPlaceholder, fill: "#808080FF" });
  14849. return { root: r, contentPlaceholder: r };
  14850. };
  14851. return DefaultWindowRenderingTemplate;
  14852. }(BABYLON.UIElementRenderingTemplateBase));
  14853. DefaultWindowRenderingTemplate = DefaultWindowRenderingTemplate_1 = __decorate([
  14854. BABYLON.registerWindowRenderingTemplate("BABYLON.Window", "Default", function () { return new DefaultWindowRenderingTemplate_1(); })
  14855. ], DefaultWindowRenderingTemplate);
  14856. BABYLON.DefaultWindowRenderingTemplate = DefaultWindowRenderingTemplate;
  14857. var Window_1, DefaultWindowRenderingTemplate_1;
  14858. })(BABYLON || (BABYLON = {}));
  14859. var __extends = (this && this.__extends) || function (d, b) {
  14860. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14861. function __() { this.constructor = d; }
  14862. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14863. };
  14864. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14865. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14866. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14867. 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;
  14868. return c > 3 && r && Object.defineProperty(target, key, r), r;
  14869. };
  14870. var BABYLON;
  14871. (function (BABYLON) {
  14872. var Label = Label_1 = (function (_super) {
  14873. __extends(Label, _super);
  14874. function Label(settings) {
  14875. var _this;
  14876. if (!settings) {
  14877. settings = {};
  14878. }
  14879. _this = _super.call(this, settings) || this;
  14880. if (settings.text != null) {
  14881. _this.text = settings.text;
  14882. }
  14883. return _this;
  14884. }
  14885. Object.defineProperty(Label.prototype, "_position", {
  14886. get: function () {
  14887. return BABYLON.Vector2.Zero();
  14888. },
  14889. enumerable: true,
  14890. configurable: true
  14891. });
  14892. Label.prototype._getChildren = function () {
  14893. return Label_1._emptyArray;
  14894. };
  14895. Label.prototype.createVisualTree = function () {
  14896. _super.prototype.createVisualTree.call(this);
  14897. var p = this._visualChildrenPlaceholder;
  14898. };
  14899. Object.defineProperty(Label.prototype, "text", {
  14900. get: function () {
  14901. return this._text;
  14902. },
  14903. set: function (value) {
  14904. this._text = value;
  14905. },
  14906. enumerable: true,
  14907. configurable: true
  14908. });
  14909. return Label;
  14910. }(BABYLON.Control));
  14911. Label._emptyArray = new Array();
  14912. __decorate([
  14913. BABYLON.dependencyProperty(BABYLON.Control.CONTROL_PROPCOUNT + 0, function (pi) { return Label_1.textProperty = pi; })
  14914. ], Label.prototype, "text", null);
  14915. Label = Label_1 = __decorate([
  14916. BABYLON.className("Label", "BABYLON")
  14917. ], Label);
  14918. BABYLON.Label = Label;
  14919. var DefaultLabelRenderingTemplate = DefaultLabelRenderingTemplate_1 = (function (_super) {
  14920. __extends(DefaultLabelRenderingTemplate, _super);
  14921. function DefaultLabelRenderingTemplate() {
  14922. return _super.apply(this, arguments) || this;
  14923. }
  14924. DefaultLabelRenderingTemplate.prototype.createVisualTree = function (owner, visualPlaceholder) {
  14925. var r = new BABYLON.Text2D("", { parent: visualPlaceholder });
  14926. r.createSimpleDataBinding(BABYLON.Text2D.textProperty, "text");
  14927. r.dataSource = owner;
  14928. return { root: r, contentPlaceholder: r };
  14929. };
  14930. return DefaultLabelRenderingTemplate;
  14931. }(BABYLON.UIElementRenderingTemplateBase));
  14932. DefaultLabelRenderingTemplate = DefaultLabelRenderingTemplate_1 = __decorate([
  14933. BABYLON.registerWindowRenderingTemplate("BABYLON.Label", "Default", function () { return new DefaultLabelRenderingTemplate_1(); })
  14934. ], DefaultLabelRenderingTemplate);
  14935. BABYLON.DefaultLabelRenderingTemplate = DefaultLabelRenderingTemplate;
  14936. var Label_1, DefaultLabelRenderingTemplate_1;
  14937. })(BABYLON || (BABYLON = {}));
  14938. var __extends = (this && this.__extends) || function (d, b) {
  14939. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14940. function __() { this.constructor = d; }
  14941. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14942. };
  14943. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14944. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14945. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14946. 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;
  14947. return c > 3 && r && Object.defineProperty(target, key, r), r;
  14948. };
  14949. var BABYLON;
  14950. (function (BABYLON) {
  14951. var Button = Button_1 = (function (_super) {
  14952. __extends(Button, _super);
  14953. function Button(settings) {
  14954. var _this;
  14955. if (!settings) {
  14956. settings = {};
  14957. }
  14958. _this = _super.call(this, settings) || this;
  14959. if (settings.paddingAlignment == null) {
  14960. _this.paddingAlignment.horizontal = BABYLON.PrimitiveAlignment.AlignCenter;
  14961. _this.paddingAlignment.vertical = BABYLON.PrimitiveAlignment.AlignCenter;
  14962. }
  14963. _this._normalStateBackground = new BABYLON.ObservableStringDictionary(false);
  14964. _this._normalStateBorder = new BABYLON.ObservableStringDictionary(false);
  14965. _this._defaultStateBackground = new BABYLON.ObservableStringDictionary(false);
  14966. _this._defaultStateBorder = new BABYLON.ObservableStringDictionary(false);
  14967. _this._normalStateBackground.add(BABYLON.UIElement.enabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#337AB7FF"));
  14968. _this._normalStateBackground.add(BABYLON.UIElement.disabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#7BA9D0FF"));
  14969. _this._normalStateBackground.add(BABYLON.UIElement.mouseOverState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#286090FF"));
  14970. _this._normalStateBackground.add(Button_1.pushedState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#1E496EFF"));
  14971. _this._normalStateBorder.add(BABYLON.UIElement.enabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#2E6DA4FF"));
  14972. _this._normalStateBorder.add(BABYLON.UIElement.disabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#77A0C4FF"));
  14973. _this._normalStateBorder.add(BABYLON.UIElement.mouseOverState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#204D74FF"));
  14974. _this._normalStateBorder.add(Button_1.pushedState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#2E5D9EFF"));
  14975. _this._defaultStateBackground.add(BABYLON.UIElement.enabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#FFFFFFFF"));
  14976. _this._defaultStateBackground.add(BABYLON.UIElement.disabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#FFFFFFFF"));
  14977. _this._defaultStateBackground.add(BABYLON.UIElement.mouseOverState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#E6E6E6FF"));
  14978. _this._defaultStateBackground.add(Button_1.pushedState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#D4D4D4FF"));
  14979. _this._defaultStateBorder.add(BABYLON.UIElement.enabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#CCCCCCFF"));
  14980. _this._defaultStateBorder.add(BABYLON.UIElement.disabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#DEDEDEFF"));
  14981. _this._defaultStateBorder.add(BABYLON.UIElement.mouseOverState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#ADADADFF"));
  14982. _this._defaultStateBorder.add(Button_1.pushedState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#6C8EC5FF"));
  14983. return _this;
  14984. }
  14985. Object.defineProperty(Button, "pushedState", {
  14986. get: function () {
  14987. return Button_1._pushedState;
  14988. },
  14989. enumerable: true,
  14990. configurable: true
  14991. });
  14992. Object.defineProperty(Button.prototype, "isPushed", {
  14993. get: function () {
  14994. return this._isPushed;
  14995. },
  14996. set: function (value) {
  14997. this._isPushed = value;
  14998. },
  14999. enumerable: true,
  15000. configurable: true
  15001. });
  15002. Object.defineProperty(Button.prototype, "isDefault", {
  15003. get: function () {
  15004. return this._isDefault;
  15005. },
  15006. set: function (value) {
  15007. this._isDefault = value;
  15008. },
  15009. enumerable: true,
  15010. configurable: true
  15011. });
  15012. Object.defineProperty(Button.prototype, "isOutline", {
  15013. get: function () {
  15014. return this._isOutline;
  15015. },
  15016. set: function (value) {
  15017. this._isOutline = value;
  15018. },
  15019. enumerable: true,
  15020. configurable: true
  15021. });
  15022. Object.defineProperty(Button.prototype, "clickObservable", {
  15023. get: function () {
  15024. if (!this._clickObservable) {
  15025. this._clickObservable = new BABYLON.Observable();
  15026. }
  15027. return this._clickObservable;
  15028. },
  15029. enumerable: true,
  15030. configurable: true
  15031. });
  15032. Button.prototype._raiseClick = function () {
  15033. if (this._clickObservable && this._clickObservable.hasObservers()) {
  15034. this._clickObservable.notifyObservers(this);
  15035. }
  15036. };
  15037. Button.prototype.createVisualTree = function () {
  15038. var _this = this;
  15039. _super.prototype.createVisualTree.call(this);
  15040. var p = this._visualPlaceholder;
  15041. p.pointerEventObservable.add(function (e, s) {
  15042. // check if input must be discarded
  15043. if (!_this.isVisible || !_this.isEnabled) {
  15044. return;
  15045. }
  15046. // We reject an event coming from the placeholder because it means it's on an empty spot, so it's not valid.
  15047. if (e.relatedTarget === _this._visualPlaceholder) {
  15048. return;
  15049. }
  15050. if (s.mask === BABYLON.PrimitivePointerInfo.PointerUp) {
  15051. _this._raiseClick();
  15052. _this.isPushed = false;
  15053. }
  15054. else if (s.mask === BABYLON.PrimitivePointerInfo.PointerDown) {
  15055. _this.isPushed = true;
  15056. _this.isFocused = true;
  15057. }
  15058. }, BABYLON.PrimitivePointerInfo.PointerUp | BABYLON.PrimitivePointerInfo.PointerDown);
  15059. };
  15060. Object.defineProperty(Button.prototype, "normalStateBackground", {
  15061. get: function () {
  15062. return this._normalStateBackground;
  15063. },
  15064. enumerable: true,
  15065. configurable: true
  15066. });
  15067. Object.defineProperty(Button.prototype, "defaultStateBackground", {
  15068. get: function () {
  15069. return this._defaultStateBackground;
  15070. },
  15071. enumerable: true,
  15072. configurable: true
  15073. });
  15074. Object.defineProperty(Button.prototype, "normalStateBorder", {
  15075. get: function () {
  15076. return this._normalStateBorder;
  15077. },
  15078. enumerable: true,
  15079. configurable: true
  15080. });
  15081. Object.defineProperty(Button.prototype, "defaultStateBorder", {
  15082. get: function () {
  15083. return this._defaultStateBorder;
  15084. },
  15085. enumerable: true,
  15086. configurable: true
  15087. });
  15088. return Button;
  15089. }(BABYLON.ContentControl));
  15090. Button.BUTTON_PROPCOUNT = BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 3;
  15091. Button._pushedState = "Pushed";
  15092. __decorate([
  15093. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTROL_PROPCOUNT + 0, function (pi) { return Button_1.isPushedProperty = pi; })
  15094. ], Button.prototype, "isPushed", null);
  15095. __decorate([
  15096. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTROL_PROPCOUNT + 1, function (pi) { return Button_1.isDefaultProperty = pi; })
  15097. ], Button.prototype, "isDefault", null);
  15098. __decorate([
  15099. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTROL_PROPCOUNT + 2, function (pi) { return Button_1.isOutlineProperty = pi; })
  15100. ], Button.prototype, "isOutline", null);
  15101. Button = Button_1 = __decorate([
  15102. BABYLON.className("Button", "BABYLON")
  15103. ], Button);
  15104. BABYLON.Button = Button;
  15105. var DefaultButtonRenderingTemplate = DefaultButtonRenderingTemplate_1 = (function (_super) {
  15106. __extends(DefaultButtonRenderingTemplate, _super);
  15107. function DefaultButtonRenderingTemplate() {
  15108. return _super.apply(this, arguments) || this;
  15109. }
  15110. DefaultButtonRenderingTemplate.prototype.createVisualTree = function (owner, visualPlaceholder) {
  15111. this._rect = new BABYLON.Rectangle2D({ parent: visualPlaceholder, fill: "#FF8080FF", border: "#FF8080FF", roundRadius: 10, borderThickness: 2 });
  15112. this.stateChange();
  15113. return { root: this._rect, contentPlaceholder: this._rect };
  15114. };
  15115. DefaultButtonRenderingTemplate.prototype.attach = function (owner) {
  15116. var _this = this;
  15117. _super.prototype.attach.call(this, owner);
  15118. this.owner.propertyChanged.add(function (e, s) { return _this.stateChange(); }, BABYLON.UIElement.isEnabledProperty.flagId |
  15119. BABYLON.UIElement.isFocusedProperty.flagId |
  15120. BABYLON.UIElement.isMouseOverProperty.flagId |
  15121. Button.isDefaultProperty.flagId |
  15122. Button.isOutlineProperty.flagId |
  15123. Button.isPushedProperty.flagId);
  15124. // Register for brush change and update the Visual
  15125. var button = owner;
  15126. button.normalStateBackground.dictionaryChanged.add(function (e, c) { return _this.stateChange(); });
  15127. button.normalStateBorder.dictionaryChanged.add(function (e, c) { return _this.stateChange(); });
  15128. button.defaultStateBackground.dictionaryChanged.add(function (e, c) { return _this.stateChange(); });
  15129. button.defaultStateBorder.dictionaryChanged.add(function (e, c) { return _this.stateChange(); });
  15130. };
  15131. DefaultButtonRenderingTemplate.prototype.stateChange = function () {
  15132. //console.log("state changed");
  15133. var b = this.owner;
  15134. var state = BABYLON.UIElement.enabledState;
  15135. var bg = b.isDefault ? b.defaultStateBackground.get(state) : b.normalStateBackground.get(state);
  15136. var bd = b.isDefault ? b.defaultStateBorder.get(state) : b.normalStateBorder.get(state);
  15137. if (b.isPushed) {
  15138. state = Button.pushedState;
  15139. if (b.isDefault) {
  15140. bg = b.defaultStateBackground.get(state);
  15141. bd = b.defaultStateBorder.get(state);
  15142. }
  15143. else {
  15144. bg = b.normalStateBackground.get(state);
  15145. bd = b.normalStateBorder.get(state);
  15146. }
  15147. }
  15148. else if (b.isMouseOver) {
  15149. state = BABYLON.UIElement.mouseOverState;
  15150. if (b.isDefault) {
  15151. bg = b.defaultStateBackground.get(state);
  15152. bd = b.defaultStateBorder.get(state);
  15153. }
  15154. else {
  15155. bg = b.normalStateBackground.get(state);
  15156. bd = b.normalStateBorder.get(state);
  15157. }
  15158. }
  15159. else if (!b.isEnabled) {
  15160. state = BABYLON.UIElement.disabledState;
  15161. if (b.isDefault) {
  15162. bg = b.defaultStateBackground.get(state);
  15163. bd = b.defaultStateBorder.get(state);
  15164. }
  15165. else {
  15166. bg = b.normalStateBackground.get(state);
  15167. bd = b.normalStateBorder.get(state);
  15168. }
  15169. }
  15170. this._rect.fill = bg;
  15171. this._rect.border = bd;
  15172. };
  15173. return DefaultButtonRenderingTemplate;
  15174. }(BABYLON.UIElementRenderingTemplateBase));
  15175. DefaultButtonRenderingTemplate = DefaultButtonRenderingTemplate_1 = __decorate([
  15176. BABYLON.registerWindowRenderingTemplate("BABYLON.Button", "Default", function () { return new DefaultButtonRenderingTemplate_1(); })
  15177. ], DefaultButtonRenderingTemplate);
  15178. BABYLON.DefaultButtonRenderingTemplate = DefaultButtonRenderingTemplate;
  15179. var Button_1, DefaultButtonRenderingTemplate_1;
  15180. })(BABYLON || (BABYLON = {}));