babylon.canvas2d.js 748 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167
  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. PropertyChangedBase.pci = new PropertyChangedInfo();
  65. PropertyChangedBase.calling = false;
  66. return PropertyChangedBase;
  67. }());
  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. ArrayChanged._clearAction = 0x1;
  159. ArrayChanged._newItemsAction = 0x2;
  160. ArrayChanged._removedItemsAction = 0x4;
  161. ArrayChanged._replacedArrayAction = 0x8;
  162. ArrayChanged._lengthChangedAction = 0x10;
  163. ArrayChanged._changedItemAction = 0x20;
  164. return ArrayChanged;
  165. }());
  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. _super.call(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. }
  197. Object.defineProperty(ObservableArray.prototype, "length", {
  198. /**
  199. * Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.
  200. */
  201. get: function () {
  202. return this._array.length;
  203. },
  204. set: function (value) {
  205. if (value === this._array.length) {
  206. return;
  207. }
  208. var oldLength = this._array.length;
  209. this._array.length = value;
  210. this.onPropertyChanged("length", oldLength, this._array.length);
  211. },
  212. enumerable: true,
  213. configurable: true
  214. });
  215. ObservableArray.prototype.getAt = function (index) {
  216. return this._array[index];
  217. };
  218. ObservableArray.prototype.setAt = function (index, value) {
  219. if (index < 0) {
  220. return false;
  221. }
  222. var insertion = (index >= this._array.length) || this._array[index] === undefined;
  223. var oldLength = 0;
  224. if (insertion) {
  225. oldLength = this._array.length;
  226. }
  227. else if (this._watchObjectsPropertyChange) {
  228. this._removeWatchedElement(this._array[index]);
  229. }
  230. this._array[index] = value;
  231. if (this._watchObjectsPropertyChange) {
  232. this._addWatchedElement(value);
  233. }
  234. if (insertion) {
  235. this.onPropertyChanged("length", oldLength, this._array.length);
  236. }
  237. var ac = this.getArrayChangedObject();
  238. if (ac) {
  239. ac.action = insertion ? ArrayChanged.newItemsAction : ArrayChanged.changedItemAction;
  240. if (insertion) {
  241. ac.newItems.splice(0, ac.newItems.length, { index: index, value: value });
  242. ac.newStartingIndex = index;
  243. ac.changedItems.splice(0);
  244. }
  245. else {
  246. ac.newItems.splice(0);
  247. ac.changedStartingIndex = index;
  248. ac.changedItems.splice(0, ac.changedItems.length, { index: index, value: value });
  249. }
  250. ac.removedItems.splice(0);
  251. ac.removedStartingIndex = -1;
  252. this.callArrayChanged(ac);
  253. }
  254. };
  255. /**
  256. * Returns a string representation of an array.
  257. */
  258. ObservableArray.prototype.toString = function () {
  259. return this._array.toString();
  260. };
  261. ObservableArray.prototype.toLocaleString = function () {
  262. return this._array.toLocaleString();
  263. };
  264. /**
  265. * Appends new elements to an array, and returns the new length of the array.
  266. * @param items New elements of the Array.
  267. */
  268. ObservableArray.prototype.push = function () {
  269. var items = [];
  270. for (var _i = 0; _i < arguments.length; _i++) {
  271. items[_i - 0] = arguments[_i];
  272. }
  273. var oldLength = this._array.length;
  274. var n = (_a = this._array).push.apply(_a, items);
  275. if (this._watchObjectsPropertyChange) {
  276. this._addWatchedElement.apply(this, items);
  277. }
  278. this.onPropertyChanged("length", oldLength, this._array.length);
  279. var ac = this.getArrayChangedObject();
  280. if (ac) {
  281. ac.action = ArrayChanged.newItemsAction;
  282. ac.newStartingIndex = oldLength;
  283. this.feedNotifArray.apply(this, [ac.newItems, oldLength].concat(items));
  284. this.callArrayChanged(ac);
  285. }
  286. return n;
  287. var _a;
  288. };
  289. /**
  290. * Removes the last element from an array and returns it.
  291. */
  292. ObservableArray.prototype.pop = function () {
  293. var firstRemove = this._array.length - 1;
  294. var res = this._array.pop();
  295. if (res && this._watchObjectsPropertyChange) {
  296. this._removeWatchedElement(res);
  297. }
  298. if (firstRemove !== -1) {
  299. this.onPropertyChanged("length", this._array.length + 1, this._array.length);
  300. var ac = this.getArrayChangedObject();
  301. if (ac) {
  302. ac.action = ArrayChanged.removedItemsAction;
  303. ac.removedStartingIndex = firstRemove;
  304. this.feedNotifArray(ac.removedItems, firstRemove, res);
  305. }
  306. }
  307. return res;
  308. };
  309. /**
  310. * Combines two or more arrays.
  311. * @param items Additional items to add to the end of array1.
  312. */
  313. ObservableArray.prototype.concat = function () {
  314. var items = [];
  315. for (var _i = 0; _i < arguments.length; _i++) {
  316. items[_i - 0] = arguments[_i];
  317. }
  318. return new ObservableArray(this._watchObjectsPropertyChange, (_a = this._array).concat.apply(_a, items));
  319. var _a;
  320. };
  321. /**
  322. * Adds all the elements of an array separated by the specified separator string.
  323. * @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.
  324. */
  325. ObservableArray.prototype.join = function (separator) {
  326. return this._array.join(separator);
  327. };
  328. /**
  329. * Reverses the elements in an Array.
  330. * The arrayChanged action is
  331. */
  332. ObservableArray.prototype.reverse = function () {
  333. var res = this._array.reverse();
  334. var ac = this.getArrayChangedObject();
  335. ac.action = ArrayChanged.replacedArrayAction;
  336. return res;
  337. };
  338. /**
  339. * Removes the first element from an array and returns it, shift all subsequents element one element before.
  340. * The ArrayChange action is replacedArrayAction, the whole array changes and must be reevaluate as such, the removed element is in removedItems.
  341. *
  342. */
  343. ObservableArray.prototype.shift = function () {
  344. var oldLength = this._array.length;
  345. var res = this._array.shift();
  346. if (this._watchedObjectChanged && res != null) {
  347. this._removeWatchedElement(res);
  348. }
  349. if (oldLength !== 0) {
  350. this.onPropertyChanged("length", oldLength, this._array.length);
  351. var ac = this.getArrayChangedObject();
  352. if (ac) {
  353. ac.action = ArrayChanged.replacedArrayAction;
  354. ac.removedItems.splice(0, ac.removedItems.length, { index: 0, value: res });
  355. ac.newItems.splice(0);
  356. ac.changedItems.splice(0);
  357. ac.removedStartingIndex = 0;
  358. this.callArrayChanged(ac);
  359. }
  360. }
  361. return res;
  362. };
  363. /**
  364. * Returns a section of an array.
  365. * @param start The beginning of the specified portion of the array.
  366. * @param end The end of the specified portion of the array.
  367. */
  368. ObservableArray.prototype.slice = function (start, end) {
  369. return new ObservableArray(this._watchObjectsPropertyChange, this._array.slice(start, end));
  370. };
  371. /**
  372. * Sorts an array.
  373. * @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.
  374. * On the contrary of the Javascript Array's implementation, this method returns nothing
  375. */
  376. ObservableArray.prototype.sort = function (compareFn) {
  377. var oldLength = this._array.length;
  378. this._array.sort(compareFn);
  379. if (oldLength !== 0) {
  380. var ac = this.getArrayChangedObject();
  381. if (ac) {
  382. ac.clear();
  383. ac.action = ArrayChanged.replacedArrayAction;
  384. this.callArrayChanged(ac);
  385. }
  386. }
  387. };
  388. /**
  389. * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
  390. * @param start The zero-based location in the array from which to start removing elements.
  391. * @param deleteCount The number of elements to remove.
  392. * @param items Elements to insert into the array in place of the deleted elements.
  393. */
  394. ObservableArray.prototype.splice = function (start, deleteCount) {
  395. var items = [];
  396. for (var _i = 2; _i < arguments.length; _i++) {
  397. items[_i - 2] = arguments[_i];
  398. }
  399. var oldLength = this._array.length;
  400. if (this._watchObjectsPropertyChange) {
  401. for (var i = start; i < start + deleteCount; i++) {
  402. var val = this._array[i];
  403. if (this._watchObjectsPropertyChange && val != null) {
  404. this._removeWatchedElement(val);
  405. }
  406. }
  407. }
  408. var res = (_a = this._array).splice.apply(_a, [start, deleteCount].concat(items));
  409. if (this._watchObjectsPropertyChange) {
  410. this._addWatchedElement.apply(this, items);
  411. }
  412. if (oldLength !== this._array.length) {
  413. this.onPropertyChanged("length", oldLength, this._array.length);
  414. }
  415. var ac = this.getArrayChangedObject();
  416. if (ac) {
  417. ac.clear();
  418. ac.action = ArrayChanged.replacedArrayAction;
  419. this.callArrayChanged(ac);
  420. }
  421. return res;
  422. var _a;
  423. };
  424. /**
  425. * Inserts new elements at the start of an array.
  426. * @param items Elements to insert at the start of the Array.
  427. * The ChangedArray action is replacedArrayAction, newItems contains the list of the added items
  428. */
  429. ObservableArray.prototype.unshift = function () {
  430. var items = [];
  431. for (var _i = 0; _i < arguments.length; _i++) {
  432. items[_i - 0] = arguments[_i];
  433. }
  434. var oldLength = this._array.length;
  435. var res = (_a = this._array).unshift.apply(_a, items);
  436. if (this._watchObjectsPropertyChange) {
  437. this._addWatchedElement.apply(this, items);
  438. }
  439. this.onPropertyChanged("length", oldLength, this._array.length);
  440. var ac = this.getArrayChangedObject();
  441. if (ac) {
  442. ac.clear();
  443. ac.action = ArrayChanged.replacedArrayAction;
  444. ac.newStartingIndex = 0,
  445. 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 - 0] = 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 - 0] = 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. DictionaryChanged._clearAction = 0x1;
  695. DictionaryChanged._newItemAction = 0x2;
  696. DictionaryChanged._removedItemAction = 0x4;
  697. DictionaryChanged._itemValueChangedAction = 0x8;
  698. DictionaryChanged._replacedAction = 0x10;
  699. return DictionaryChanged;
  700. }());
  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. _super.call(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. }
  722. /**
  723. * This will clear this dictionary and copy the content from the 'source' one.
  724. * If the T value is a custom object, it won't be copied/cloned, the same object will be used
  725. * @param source the dictionary to take the content from and copy to this dictionary
  726. */
  727. ObservableStringDictionary.prototype.copyFrom = function (source) {
  728. var _this = this;
  729. var oldCount = this.count;
  730. // Don't rely on this class' implementation for clear/add otherwise tons of notification will be thrown
  731. _super.prototype.clear.call(this);
  732. source.forEach(function (t, v) { return _this._add(t, v, false, _this._watchObjectsPropertyChange); });
  733. this.onDictionaryChanged(DictionaryChanged.replacedAction, null, null, null);
  734. this.onPropertyChanged("count", oldCount, this.count);
  735. };
  736. /**
  737. * Get a value from its key or add it if it doesn't exist.
  738. * This method will ensure you that a given key/data will be present in the dictionary.
  739. * @param key the given key to get the matching value from
  740. * @param factory the factory that will create the value if the key is not present in the dictionary.
  741. * The factory will only be invoked if there's no data for the given key.
  742. * @return the value corresponding to the key.
  743. */
  744. ObservableStringDictionary.prototype.getOrAddWithFactory = function (key, factory) {
  745. var _this = this;
  746. var val = _super.prototype.getOrAddWithFactory.call(this, key, function (k) {
  747. var v = factory(key);
  748. _this._add(key, v, true, _this._watchObjectsPropertyChange);
  749. return v;
  750. });
  751. return val;
  752. };
  753. /**
  754. * Add a new key and its corresponding value
  755. * @param key the key to add
  756. * @param value the value corresponding to the key
  757. * @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
  758. */
  759. ObservableStringDictionary.prototype.add = function (key, value) {
  760. return this._add(key, value, true, true);
  761. };
  762. ObservableStringDictionary.prototype.getAndRemove = function (key) {
  763. var val = _super.prototype.get.call(this, key);
  764. this._remove(key, true, val);
  765. return val;
  766. };
  767. ObservableStringDictionary.prototype._add = function (key, value, fireNotif, registerWatcher) {
  768. if (_super.prototype.add.call(this, key, value)) {
  769. if (fireNotif) {
  770. this.onDictionaryChanged(DictionaryChanged.newItemAction, { key: key, value: value }, null, null);
  771. this.onPropertyChanged("count", this.count - 1, this.count);
  772. }
  773. if (registerWatcher) {
  774. this._addWatchedElement(key, value);
  775. }
  776. return true;
  777. }
  778. return false;
  779. };
  780. ObservableStringDictionary.prototype._addWatchedElement = function (key, el) {
  781. var _this = this;
  782. if (el["propertyChanged"]) {
  783. this._watchedObjectList.add(key, el.propertyChanged.add(function (e, d) {
  784. _this.onWatchedObjectChanged(key, el, e);
  785. }));
  786. }
  787. };
  788. ObservableStringDictionary.prototype._removeWatchedElement = function (key, el) {
  789. var observer = this._watchedObjectList.getAndRemove(key);
  790. if (el["propertyChanged"]) {
  791. el.propertyChanged.remove(observer);
  792. }
  793. };
  794. ObservableStringDictionary.prototype.set = function (key, value) {
  795. var oldValue = this.get(key);
  796. if (this._watchObjectsPropertyChange) {
  797. this._removeWatchedElement(key, oldValue);
  798. }
  799. if (_super.prototype.set.call(this, key, value)) {
  800. this.onDictionaryChanged(DictionaryChanged.itemValueChangedAction, null, null, { key: key, oldValue: oldValue, newValue: value });
  801. this._addWatchedElement(key, value);
  802. return true;
  803. }
  804. return false;
  805. };
  806. /**
  807. * Remove a key/value from the dictionary.
  808. * @param key the key to remove
  809. * @return true if the item was successfully deleted, false if no item with such key exist in the dictionary
  810. */
  811. ObservableStringDictionary.prototype.remove = function (key) {
  812. return this._remove(key, true);
  813. };
  814. ObservableStringDictionary.prototype._remove = function (key, fireNotif, element) {
  815. if (!element) {
  816. element = this.get(key);
  817. }
  818. if (!element) {
  819. return false;
  820. }
  821. if (_super.prototype.remove.call(this, key) === undefined) {
  822. return false;
  823. }
  824. this.onDictionaryChanged(DictionaryChanged.removedItemAction, null, key, null);
  825. this.onPropertyChanged("count", this.count + 1, this.count);
  826. if (this._watchObjectsPropertyChange) {
  827. this._removeWatchedElement(key, element);
  828. }
  829. return true;
  830. };
  831. /**
  832. * Clear the whole content of the dictionary
  833. */
  834. ObservableStringDictionary.prototype.clear = function () {
  835. var _this = this;
  836. this._watchedObjectList.forEach(function (k, v) {
  837. var el = _this.get(k);
  838. _this._removeWatchedElement(k, el);
  839. });
  840. this._watchedObjectList.clear();
  841. var oldCount = this.count;
  842. _super.prototype.clear.call(this);
  843. this.onDictionaryChanged(DictionaryChanged.clearAction, null, null, null);
  844. this.onPropertyChanged("count", oldCount, 0);
  845. };
  846. Object.defineProperty(ObservableStringDictionary.prototype, "propertyChanged", {
  847. get: function () {
  848. if (!this._propertyChanged) {
  849. this._propertyChanged = new BABYLON.Observable();
  850. }
  851. return this._propertyChanged;
  852. },
  853. enumerable: true,
  854. configurable: true
  855. });
  856. ObservableStringDictionary.prototype.onPropertyChanged = function (propName, oldValue, newValue, mask) {
  857. if (this._propertyChanged && this._propertyChanged.hasObservers()) {
  858. var pci = ObservableStringDictionary.callingPropChanged ? new BABYLON.PropertyChangedInfo() : ObservableStringDictionary.pci;
  859. pci.oldValue = oldValue;
  860. pci.newValue = newValue;
  861. pci.propertyName = propName;
  862. try {
  863. ObservableStringDictionary.callingPropChanged = true;
  864. this.propertyChanged.notifyObservers(pci, mask);
  865. }
  866. finally {
  867. ObservableStringDictionary.callingPropChanged = false;
  868. }
  869. }
  870. };
  871. Object.defineProperty(ObservableStringDictionary.prototype, "dictionaryChanged", {
  872. get: function () {
  873. if (!this._dictionaryChanged) {
  874. this._dictionaryChanged = new BABYLON.Observable();
  875. }
  876. return this._dictionaryChanged;
  877. },
  878. enumerable: true,
  879. configurable: true
  880. });
  881. ObservableStringDictionary.prototype.onDictionaryChanged = function (action, newItem, removedKey, changedItem) {
  882. if (this._dictionaryChanged && this._dictionaryChanged.hasObservers()) {
  883. var dci = this._callingDicChanged ? new DictionaryChanged() : this.dci;
  884. dci.action = action;
  885. dci.newItem = newItem;
  886. dci.removedKey = removedKey;
  887. dci.changedItem = changedItem;
  888. try {
  889. this._callingDicChanged = true;
  890. this.dictionaryChanged.notifyObservers(dci, action);
  891. }
  892. finally {
  893. this._callingDicChanged = false;
  894. }
  895. }
  896. };
  897. Object.defineProperty(ObservableStringDictionary.prototype, "watchedObjectChanged", {
  898. get: function () {
  899. if (!this._watchedObjectChanged) {
  900. this._watchedObjectChanged = new BABYLON.Observable();
  901. }
  902. return this._watchedObjectChanged;
  903. },
  904. enumerable: true,
  905. configurable: true
  906. });
  907. ObservableStringDictionary.prototype.onWatchedObjectChanged = function (key, object, propChanged) {
  908. if (this._watchedObjectChanged && this._watchedObjectChanged.hasObservers()) {
  909. var woci = this._callingWatchedObjectChanged ? new OSDWatchedObjectChangedInfo() : this._woci;
  910. woci.key = key;
  911. woci.object = object;
  912. woci.propertyChanged = propChanged;
  913. try {
  914. this._callingWatchedObjectChanged = true;
  915. this.watchedObjectChanged.notifyObservers(woci);
  916. }
  917. finally {
  918. this._callingWatchedObjectChanged = false;
  919. }
  920. }
  921. };
  922. ObservableStringDictionary.pci = new BABYLON.PropertyChangedInfo();
  923. ObservableStringDictionary.callingPropChanged = false;
  924. return ObservableStringDictionary;
  925. }(BABYLON.StringDictionary));
  926. BABYLON.ObservableStringDictionary = ObservableStringDictionary;
  927. })(BABYLON || (BABYLON = {}));
  928. //# sourceMappingURL=babylon.observableStringDictionary.js.map
  929. var BABYLON;
  930. (function (BABYLON) {
  931. /**
  932. * Stores 2D Bounding Information.
  933. * This class handles a circle area and a bounding rectangle one.
  934. */
  935. var BoundingInfo2D = (function () {
  936. function BoundingInfo2D() {
  937. this.radius = 0;
  938. this.center = BABYLON.Vector2.Zero();
  939. this.extent = BABYLON.Vector2.Zero();
  940. }
  941. /**
  942. * Create a BoundingInfo2D object from a given size
  943. * @param size the size that will be used to set the extend, radius will be computed from it.
  944. */
  945. BoundingInfo2D.CreateFromSize = function (size) {
  946. var r = new BoundingInfo2D();
  947. BoundingInfo2D.CreateFromSizeToRef(size, r);
  948. return r;
  949. };
  950. /**
  951. * Create a BoundingInfo2D object from a given radius
  952. * @param radius the radius to use, the extent will be computed from it.
  953. */
  954. BoundingInfo2D.CreateFromRadius = function (radius) {
  955. var r = new BoundingInfo2D();
  956. BoundingInfo2D.CreateFromRadiusToRef(radius, r);
  957. return r;
  958. };
  959. /**
  960. * Create a BoundingInfo2D object from a list of points.
  961. * The resulted object will be the smallest bounding area that includes all the given points.
  962. * @param points an array of points to compute the bounding object from.
  963. */
  964. BoundingInfo2D.CreateFromPoints = function (points) {
  965. var r = new BoundingInfo2D();
  966. BoundingInfo2D.CreateFromPointsToRef(points, r);
  967. return r;
  968. };
  969. /**
  970. * Update a BoundingInfo2D object using the given Size as input
  971. * @param size the bounding data will be computed from this size.
  972. * @param b must be a valid/allocated object, it will contain the result of the operation
  973. */
  974. BoundingInfo2D.CreateFromSizeToRef = function (size, b) {
  975. if (!size) {
  976. size = BABYLON.Size.Zero();
  977. }
  978. b.center.x = +size.width / 2;
  979. b.center.y = +size.height / 2;
  980. b.extent.x = b.center.x;
  981. b.extent.y = b.center.y;
  982. b.radius = b.extent.length();
  983. };
  984. /**
  985. * Update a BoundingInfo2D object using the given radius as input
  986. * @param radius the bounding data will be computed from this radius
  987. * @param b must be a valid/allocated object, it will contain the result of the operation
  988. */
  989. BoundingInfo2D.CreateFromRadiusToRef = function (radius, b) {
  990. b.center.x = b.center.y = 0;
  991. var r = +radius;
  992. b.extent.x = r;
  993. b.extent.y = r;
  994. b.radius = r;
  995. };
  996. /**
  997. * Update a BoundingInfo2D object using the given points array as input
  998. * @param points the point array to use to update the bounding data
  999. * @param b must be a valid/allocated object, it will contain the result of the operation
  1000. */
  1001. BoundingInfo2D.CreateFromPointsToRef = function (points, b) {
  1002. var xmin = Number.MAX_VALUE, ymin = Number.MAX_VALUE, xmax = Number.MIN_VALUE, ymax = Number.MIN_VALUE;
  1003. for (var _i = 0, points_1 = points; _i < points_1.length; _i++) {
  1004. var p = points_1[_i];
  1005. xmin = Math.min(p.x, xmin);
  1006. xmax = Math.max(p.x, xmax);
  1007. ymin = Math.min(p.y, ymin);
  1008. ymax = Math.max(p.y, ymax);
  1009. }
  1010. BoundingInfo2D.CreateFromMinMaxToRef(xmin, xmax, ymin, ymax, b);
  1011. };
  1012. /**
  1013. * Update a BoundingInfo2D object using the given min/max values as input
  1014. * @param xmin the smallest x coordinate
  1015. * @param xmax the biggest x coordinate
  1016. * @param ymin the smallest y coordinate
  1017. * @param ymax the buggest y coordinate
  1018. * @param b must be a valid/allocated object, it will contain the result of the operation
  1019. */
  1020. BoundingInfo2D.CreateFromMinMaxToRef = function (xmin, xmax, ymin, ymax, b) {
  1021. var w = xmax - xmin;
  1022. var h = ymax - ymin;
  1023. b.center = new BABYLON.Vector2(xmin + w / 2, ymin + h / 2);
  1024. b.extent = new BABYLON.Vector2(xmax - b.center.x, ymax - b.center.y);
  1025. b.radius = b.extent.length();
  1026. };
  1027. /**
  1028. * Duplicate this instance and return a new one
  1029. * @return the duplicated instance
  1030. */
  1031. BoundingInfo2D.prototype.clone = function () {
  1032. var r = new BoundingInfo2D();
  1033. r.center = this.center.clone();
  1034. r.radius = this.radius;
  1035. r.extent = this.extent.clone();
  1036. return r;
  1037. };
  1038. BoundingInfo2D.prototype.clear = function () {
  1039. this.center.copyFromFloats(0, 0);
  1040. this.radius = 0;
  1041. this.extent.copyFromFloats(0, 0);
  1042. };
  1043. BoundingInfo2D.prototype.copyFrom = function (src) {
  1044. this.center.copyFrom(src.center);
  1045. this.radius = src.radius;
  1046. this.extent.copyFrom(src.extent);
  1047. };
  1048. /**
  1049. * return the max extend of the bounding info
  1050. */
  1051. BoundingInfo2D.prototype.max = function () {
  1052. var r = BABYLON.Vector2.Zero();
  1053. this.maxToRef(r);
  1054. return r;
  1055. };
  1056. /**
  1057. * Update a vector2 with the max extend of the bounding info
  1058. * @param result must be a valid/allocated vector2 that will contain the result of the operation
  1059. */
  1060. BoundingInfo2D.prototype.maxToRef = function (result) {
  1061. result.x = this.center.x + this.extent.x;
  1062. result.y = this.center.y + this.extent.y;
  1063. };
  1064. /**
  1065. * Apply a transformation matrix to this BoundingInfo2D and return a new instance containing the result
  1066. * @param matrix the transformation matrix to apply
  1067. * @return the new instance containing the result of the transformation applied on this BoundingInfo2D
  1068. */
  1069. BoundingInfo2D.prototype.transform = function (matrix) {
  1070. var r = new BoundingInfo2D();
  1071. this.transformToRef(matrix, r);
  1072. return r;
  1073. };
  1074. /**
  1075. * Compute the union of this BoundingInfo2D with a given one, returns a new BoundingInfo2D as a result
  1076. * @param other the second BoundingInfo2D to compute the union with this one
  1077. * @return a new instance containing the result of the union
  1078. */
  1079. BoundingInfo2D.prototype.union = function (other) {
  1080. var r = new BoundingInfo2D();
  1081. this.unionToRef(other, r);
  1082. return r;
  1083. };
  1084. /**
  1085. * Transform this BoundingInfo2D with a given matrix and store the result in an existing BoundingInfo2D instance.
  1086. * 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.
  1087. * @param matrix The matrix to use to compute the transformation
  1088. * @param result A VALID (i.e. allocated) BoundingInfo2D object where the result will be stored
  1089. */
  1090. BoundingInfo2D.prototype.transformToRef = function (matrix, result) {
  1091. // Construct a bounding box based on the extent values
  1092. var p = BoundingInfo2D._transform;
  1093. p[0].x = this.center.x + this.extent.x;
  1094. p[0].y = this.center.y + this.extent.y;
  1095. p[1].x = this.center.x + this.extent.x;
  1096. p[1].y = this.center.y - this.extent.y;
  1097. p[2].x = this.center.x - this.extent.x;
  1098. p[2].y = this.center.y - this.extent.y;
  1099. p[3].x = this.center.x - this.extent.x;
  1100. p[3].y = this.center.y + this.extent.y;
  1101. // Transform the four points of the bounding box with the matrix
  1102. for (var i = 0; i < 4; i++) {
  1103. BABYLON.Vector2.TransformToRef(p[i], matrix, p[i]);
  1104. }
  1105. BoundingInfo2D.CreateFromPointsToRef(p, result);
  1106. };
  1107. /**
  1108. * Compute the union of this BoundingInfo2D with another one and store the result in a third valid BoundingInfo2D object
  1109. * 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.
  1110. * @param other the second object used to compute the union
  1111. * @param result a VALID BoundingInfo2D instance (i.e. allocated) where the result will be stored
  1112. */
  1113. BoundingInfo2D.prototype.unionToRef = function (other, result) {
  1114. var xmax = Math.max(this.center.x + this.extent.x, other.center.x + other.extent.x);
  1115. var ymax = Math.max(this.center.y + this.extent.y, other.center.y + other.extent.y);
  1116. var xmin = Math.min(this.center.x - this.extent.x, other.center.x - other.extent.x);
  1117. var ymin = Math.min(this.center.y - this.extent.y, other.center.y - other.extent.y);
  1118. BoundingInfo2D.CreateFromMinMaxToRef(xmin, xmax, ymin, ymax, result);
  1119. };
  1120. /**
  1121. * Check if the given point is inside the BoundingInfo.
  1122. * The test is first made on the radius, then inside the rectangle described by the extent
  1123. * @param pickPosition the position to test
  1124. * @return true if the point is inside, false otherwise
  1125. */
  1126. BoundingInfo2D.prototype.doesIntersect = function (pickPosition) {
  1127. // is it inside the radius?
  1128. var pickLocal = pickPosition.subtract(this.center);
  1129. if (pickLocal.lengthSquared() <= (this.radius * this.radius)) {
  1130. // is it inside the rectangle?
  1131. return ((Math.abs(pickLocal.x) <= this.extent.x) && (Math.abs(pickLocal.y) <= this.extent.y));
  1132. }
  1133. return false;
  1134. };
  1135. BoundingInfo2D._transform = new Array(BABYLON.Vector2.Zero(), BABYLON.Vector2.Zero(), BABYLON.Vector2.Zero(), BABYLON.Vector2.Zero());
  1136. return BoundingInfo2D;
  1137. }());
  1138. BABYLON.BoundingInfo2D = BoundingInfo2D;
  1139. })(BABYLON || (BABYLON = {}));
  1140. //# sourceMappingURL=babylon.bounding2d.js.map
  1141. var __extends = (this && this.__extends) || function (d, b) {
  1142. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  1143. function __() { this.constructor = d; }
  1144. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1145. };
  1146. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  1147. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  1148. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  1149. 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;
  1150. return c > 3 && r && Object.defineProperty(target, key, r), r;
  1151. };
  1152. var BABYLON;
  1153. (function (BABYLON) {
  1154. var LayoutEngineBase = (function () {
  1155. function LayoutEngineBase() {
  1156. this.layoutDirtyOnPropertyChangedMask = 0;
  1157. }
  1158. LayoutEngineBase.prototype.updateLayout = function (prim) {
  1159. };
  1160. Object.defineProperty(LayoutEngineBase.prototype, "isChildPositionAllowed", {
  1161. get: function () {
  1162. return false;
  1163. },
  1164. enumerable: true,
  1165. configurable: true
  1166. });
  1167. LayoutEngineBase.prototype.isLocked = function () {
  1168. return this._isLocked;
  1169. };
  1170. LayoutEngineBase.prototype.lock = function () {
  1171. if (this._isLocked) {
  1172. return false;
  1173. }
  1174. this._isLocked = true;
  1175. return true;
  1176. };
  1177. LayoutEngineBase = __decorate([
  1178. BABYLON.className("LayoutEngineBase", "BABYLON")
  1179. ], LayoutEngineBase);
  1180. return LayoutEngineBase;
  1181. }());
  1182. BABYLON.LayoutEngineBase = LayoutEngineBase;
  1183. var CanvasLayoutEngine = (function (_super) {
  1184. __extends(CanvasLayoutEngine, _super);
  1185. function CanvasLayoutEngine() {
  1186. _super.apply(this, arguments);
  1187. }
  1188. // A very simple (no) layout computing...
  1189. // The Canvas and its direct children gets the Canvas' size as Layout Area
  1190. // Indirect children have their Layout Area to the actualSize (margin area) of their parent
  1191. CanvasLayoutEngine.prototype.updateLayout = function (prim) {
  1192. // If this prim is layoutDiry we update its layoutArea and also the one of its direct children
  1193. if (prim._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty)) {
  1194. for (var _i = 0, _a = prim.children; _i < _a.length; _i++) {
  1195. var child = _a[_i];
  1196. this._doUpdate(child);
  1197. }
  1198. prim._clearFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  1199. }
  1200. };
  1201. CanvasLayoutEngine.prototype._doUpdate = function (prim) {
  1202. // Canvas ?
  1203. if (prim instanceof BABYLON.Canvas2D) {
  1204. prim.layoutArea = prim.actualSize; //.multiplyByFloats(prim.scaleX, prim.scaleY);
  1205. }
  1206. else if (prim.parent instanceof BABYLON.Canvas2D) {
  1207. prim.layoutArea = prim.owner.actualSize; //.multiplyByFloats(prim.owner.scaleX, prim.owner.scaleY);
  1208. }
  1209. else {
  1210. prim.layoutArea = prim.parent.contentArea;
  1211. }
  1212. };
  1213. Object.defineProperty(CanvasLayoutEngine.prototype, "isChildPositionAllowed", {
  1214. get: function () {
  1215. return true;
  1216. },
  1217. enumerable: true,
  1218. configurable: true
  1219. });
  1220. CanvasLayoutEngine.Singleton = new CanvasLayoutEngine();
  1221. CanvasLayoutEngine = __decorate([
  1222. BABYLON.className("CanvasLayoutEngine", "BABYLON")
  1223. ], CanvasLayoutEngine);
  1224. return CanvasLayoutEngine;
  1225. }(LayoutEngineBase));
  1226. BABYLON.CanvasLayoutEngine = CanvasLayoutEngine;
  1227. var StackPanelLayoutEngine = (function (_super) {
  1228. __extends(StackPanelLayoutEngine, _super);
  1229. function StackPanelLayoutEngine() {
  1230. _super.call(this);
  1231. this._isHorizontal = true;
  1232. this.layoutDirtyOnPropertyChangedMask = BABYLON.Prim2DBase.sizeProperty.flagId;
  1233. }
  1234. Object.defineProperty(StackPanelLayoutEngine, "Horizontal", {
  1235. get: function () {
  1236. if (!StackPanelLayoutEngine._horizontal) {
  1237. StackPanelLayoutEngine._horizontal = new StackPanelLayoutEngine();
  1238. StackPanelLayoutEngine._horizontal.isHorizontal = true;
  1239. StackPanelLayoutEngine._horizontal.lock();
  1240. }
  1241. return StackPanelLayoutEngine._horizontal;
  1242. },
  1243. enumerable: true,
  1244. configurable: true
  1245. });
  1246. Object.defineProperty(StackPanelLayoutEngine, "Vertical", {
  1247. get: function () {
  1248. if (!StackPanelLayoutEngine._vertical) {
  1249. StackPanelLayoutEngine._vertical = new StackPanelLayoutEngine();
  1250. StackPanelLayoutEngine._vertical.isHorizontal = false;
  1251. StackPanelLayoutEngine._vertical.lock();
  1252. }
  1253. return StackPanelLayoutEngine._vertical;
  1254. },
  1255. enumerable: true,
  1256. configurable: true
  1257. });
  1258. Object.defineProperty(StackPanelLayoutEngine.prototype, "isHorizontal", {
  1259. get: function () {
  1260. return this._isHorizontal;
  1261. },
  1262. set: function (val) {
  1263. if (this.isLocked()) {
  1264. return;
  1265. }
  1266. this._isHorizontal = val;
  1267. },
  1268. enumerable: true,
  1269. configurable: true
  1270. });
  1271. StackPanelLayoutEngine.prototype.updateLayout = function (prim) {
  1272. if (prim._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty)) {
  1273. var x = 0;
  1274. var y = 0;
  1275. var h = this.isHorizontal;
  1276. var max = 0;
  1277. for (var _i = 0, _a = prim.children; _i < _a.length; _i++) {
  1278. var child = _a[_i];
  1279. if (child._isFlagSet(BABYLON.SmartPropertyPrim.flagNoPartOfLayout)) {
  1280. continue;
  1281. }
  1282. var layoutArea = void 0;
  1283. if (child._hasMargin) {
  1284. child.margin.computeWithAlignment(prim.layoutArea, child.actualSize, child.marginAlignment, StackPanelLayoutEngine.dstOffset, StackPanelLayoutEngine.dstArea, true);
  1285. layoutArea = StackPanelLayoutEngine.dstArea.clone();
  1286. child.layoutArea = layoutArea;
  1287. }
  1288. else {
  1289. layoutArea = child.layoutArea;
  1290. child.margin.computeArea(child.actualSize, layoutArea);
  1291. }
  1292. max = Math.max(max, h ? layoutArea.height : layoutArea.width);
  1293. }
  1294. for (var _b = 0, _c = prim.children; _b < _c.length; _b++) {
  1295. var child = _c[_b];
  1296. if (child._isFlagSet(BABYLON.SmartPropertyPrim.flagNoPartOfLayout)) {
  1297. continue;
  1298. }
  1299. child.layoutAreaPos = new BABYLON.Vector2(x, y);
  1300. var layoutArea = child.layoutArea;
  1301. if (h) {
  1302. x += layoutArea.width;
  1303. child.layoutArea = new BABYLON.Size(layoutArea.width, max);
  1304. }
  1305. else {
  1306. y += layoutArea.height;
  1307. child.layoutArea = new BABYLON.Size(max, layoutArea.height);
  1308. }
  1309. }
  1310. prim._clearFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  1311. }
  1312. };
  1313. Object.defineProperty(StackPanelLayoutEngine.prototype, "isChildPositionAllowed", {
  1314. get: function () {
  1315. return false;
  1316. },
  1317. enumerable: true,
  1318. configurable: true
  1319. });
  1320. StackPanelLayoutEngine._horizontal = null;
  1321. StackPanelLayoutEngine._vertical = null;
  1322. StackPanelLayoutEngine.dstOffset = BABYLON.Vector4.Zero();
  1323. StackPanelLayoutEngine.dstArea = BABYLON.Size.Zero();
  1324. StackPanelLayoutEngine = __decorate([
  1325. BABYLON.className("StackPanelLayoutEngine", "BABYLON")
  1326. ], StackPanelLayoutEngine);
  1327. return StackPanelLayoutEngine;
  1328. }(LayoutEngineBase));
  1329. BABYLON.StackPanelLayoutEngine = StackPanelLayoutEngine;
  1330. })(BABYLON || (BABYLON = {}));
  1331. //# sourceMappingURL=babylon.canvas2dLayoutEngine.js.map
  1332. var __extends = (this && this.__extends) || function (d, b) {
  1333. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  1334. function __() { this.constructor = d; }
  1335. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1336. };
  1337. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  1338. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  1339. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  1340. 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;
  1341. return c > 3 && r && Object.defineProperty(target, key, r), r;
  1342. };
  1343. var BABYLON;
  1344. (function (BABYLON) {
  1345. /**
  1346. * Base class implementing the ILocable interface.
  1347. * The particularity of this class is to call the protected onLock() method when the instance is about to be locked for good.
  1348. */
  1349. var LockableBase = (function () {
  1350. function LockableBase() {
  1351. }
  1352. LockableBase.prototype.isLocked = function () {
  1353. return this._isLocked;
  1354. };
  1355. LockableBase.prototype.lock = function () {
  1356. if (this._isLocked) {
  1357. return true;
  1358. }
  1359. this.onLock();
  1360. this._isLocked = true;
  1361. return false;
  1362. };
  1363. /**
  1364. * Protected handler that will be called when the instance is about to be locked.
  1365. */
  1366. LockableBase.prototype.onLock = function () {
  1367. };
  1368. return LockableBase;
  1369. }());
  1370. BABYLON.LockableBase = LockableBase;
  1371. var SolidColorBrush2D = (function (_super) {
  1372. __extends(SolidColorBrush2D, _super);
  1373. function SolidColorBrush2D(color, lock) {
  1374. if (lock === void 0) { lock = false; }
  1375. _super.call(this);
  1376. this._color = color;
  1377. if (lock) {
  1378. {
  1379. this.lock();
  1380. }
  1381. }
  1382. }
  1383. /**
  1384. * Return true if the brush is transparent, false if it's totally opaque
  1385. */
  1386. SolidColorBrush2D.prototype.isTransparent = function () {
  1387. return this._color && this._color.a < 1.0;
  1388. };
  1389. Object.defineProperty(SolidColorBrush2D.prototype, "color", {
  1390. /**
  1391. * The color used by this instance to render
  1392. * @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.
  1393. */
  1394. get: function () {
  1395. return this._color;
  1396. },
  1397. set: function (value) {
  1398. if (this.isLocked()) {
  1399. return;
  1400. }
  1401. this._color = value;
  1402. },
  1403. enumerable: true,
  1404. configurable: true
  1405. });
  1406. /**
  1407. * Return a unique identifier of the instance, which is simply the hexadecimal representation (CSS Style) of the solid color.
  1408. */
  1409. SolidColorBrush2D.prototype.toString = function () {
  1410. return this._color.toHexString();
  1411. };
  1412. SolidColorBrush2D = __decorate([
  1413. BABYLON.className("SolidColorBrush2D", "BABYLON")
  1414. ], SolidColorBrush2D);
  1415. return SolidColorBrush2D;
  1416. }(LockableBase));
  1417. BABYLON.SolidColorBrush2D = SolidColorBrush2D;
  1418. var GradientColorBrush2D = (function (_super) {
  1419. __extends(GradientColorBrush2D, _super);
  1420. function GradientColorBrush2D(color1, color2, translation, rotation, scale, lock) {
  1421. if (translation === void 0) { translation = BABYLON.Vector2.Zero(); }
  1422. if (rotation === void 0) { rotation = 0; }
  1423. if (scale === void 0) { scale = 1; }
  1424. if (lock === void 0) { lock = false; }
  1425. _super.call(this);
  1426. this._color1 = color1;
  1427. this._color2 = color2;
  1428. this._translation = translation;
  1429. this._rotation = rotation;
  1430. this._scale = scale;
  1431. if (lock) {
  1432. this.lock();
  1433. }
  1434. }
  1435. /**
  1436. * Return true if the brush is transparent, false if it's totally opaque
  1437. */
  1438. GradientColorBrush2D.prototype.isTransparent = function () {
  1439. return (this._color1 && this._color1.a < 1.0) || (this._color2 && this._color2.a < 1.0);
  1440. };
  1441. Object.defineProperty(GradientColorBrush2D.prototype, "color1", {
  1442. /**
  1443. * First color, the blend will start from this color
  1444. */
  1445. get: function () {
  1446. return this._color1;
  1447. },
  1448. set: function (value) {
  1449. if (this.isLocked()) {
  1450. return;
  1451. }
  1452. this._color1 = value;
  1453. },
  1454. enumerable: true,
  1455. configurable: true
  1456. });
  1457. Object.defineProperty(GradientColorBrush2D.prototype, "color2", {
  1458. /**
  1459. * Second color, the blend will end to this color
  1460. */
  1461. get: function () {
  1462. return this._color2;
  1463. },
  1464. set: function (value) {
  1465. if (this.isLocked()) {
  1466. return;
  1467. }
  1468. this._color2 = value;
  1469. },
  1470. enumerable: true,
  1471. configurable: true
  1472. });
  1473. Object.defineProperty(GradientColorBrush2D.prototype, "translation", {
  1474. /**
  1475. * Translation vector to apply on the blend
  1476. * Default is [0;0]
  1477. */
  1478. get: function () {
  1479. return this._translation;
  1480. },
  1481. set: function (value) {
  1482. if (this.isLocked()) {
  1483. return;
  1484. }
  1485. this._translation = value;
  1486. },
  1487. enumerable: true,
  1488. configurable: true
  1489. });
  1490. Object.defineProperty(GradientColorBrush2D.prototype, "rotation", {
  1491. /**
  1492. * Rotation in radian to apply to the brush
  1493. * Default direction of the brush is vertical, you can change this using this property.
  1494. * Default is 0.
  1495. */
  1496. get: function () {
  1497. return this._rotation;
  1498. },
  1499. set: function (value) {
  1500. if (this.isLocked()) {
  1501. return;
  1502. }
  1503. this._rotation = value;
  1504. },
  1505. enumerable: true,
  1506. configurable: true
  1507. });
  1508. Object.defineProperty(GradientColorBrush2D.prototype, "scale", {
  1509. /**
  1510. * Scale factor to apply to the gradient.
  1511. * Default is 1: no scale.
  1512. */
  1513. get: function () {
  1514. return this._scale;
  1515. },
  1516. set: function (value) {
  1517. if (this.isLocked()) {
  1518. return;
  1519. }
  1520. this._scale = value;
  1521. },
  1522. enumerable: true,
  1523. configurable: true
  1524. });
  1525. /**
  1526. * Return a string describing the brush
  1527. */
  1528. GradientColorBrush2D.prototype.toString = function () {
  1529. return "C1:" + this._color1 + ";C2:" + this._color2 + ";T:" + this._translation.toString() + ";R:" + this._rotation + ";S:" + this._scale + ";";
  1530. };
  1531. /**
  1532. * Build a unique key string for the given parameters
  1533. */
  1534. GradientColorBrush2D.BuildKey = function (color1, color2, translation, rotation, scale) {
  1535. return "C1:" + color1 + ";C2:" + color2 + ";T:" + translation.toString() + ";R:" + rotation + ";S:" + scale + ";";
  1536. };
  1537. GradientColorBrush2D = __decorate([
  1538. BABYLON.className("GradientColorBrush2D", "BABYLON")
  1539. ], GradientColorBrush2D);
  1540. return GradientColorBrush2D;
  1541. }(LockableBase));
  1542. BABYLON.GradientColorBrush2D = GradientColorBrush2D;
  1543. })(BABYLON || (BABYLON = {}));
  1544. //# sourceMappingURL=babylon.brushes2d.js.map
  1545. var __extends = (this && this.__extends) || function (d, b) {
  1546. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  1547. function __() { this.constructor = d; }
  1548. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1549. };
  1550. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  1551. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  1552. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  1553. 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;
  1554. return c > 3 && r && Object.defineProperty(target, key, r), r;
  1555. };
  1556. var BABYLON;
  1557. (function (BABYLON) {
  1558. var Prim2DClassInfo = (function () {
  1559. function Prim2DClassInfo() {
  1560. }
  1561. return Prim2DClassInfo;
  1562. }());
  1563. BABYLON.Prim2DClassInfo = Prim2DClassInfo;
  1564. var Prim2DPropInfo = (function () {
  1565. function Prim2DPropInfo() {
  1566. }
  1567. Prim2DPropInfo.PROPKIND_MODEL = 1;
  1568. Prim2DPropInfo.PROPKIND_INSTANCE = 2;
  1569. Prim2DPropInfo.PROPKIND_DYNAMIC = 3;
  1570. return Prim2DPropInfo;
  1571. }());
  1572. BABYLON.Prim2DPropInfo = Prim2DPropInfo;
  1573. var ClassTreeInfo = (function () {
  1574. function ClassTreeInfo(baseClass, type, classContentFactory) {
  1575. this._baseClass = baseClass;
  1576. this._type = type;
  1577. this._subClasses = new Array();
  1578. this._levelContent = new BABYLON.StringDictionary();
  1579. this._classContentFactory = classContentFactory;
  1580. }
  1581. Object.defineProperty(ClassTreeInfo.prototype, "classContent", {
  1582. get: function () {
  1583. if (!this._classContent) {
  1584. this._classContent = this._classContentFactory(this._baseClass ? this._baseClass.classContent : null);
  1585. }
  1586. return this._classContent;
  1587. },
  1588. enumerable: true,
  1589. configurable: true
  1590. });
  1591. Object.defineProperty(ClassTreeInfo.prototype, "type", {
  1592. get: function () {
  1593. return this._type;
  1594. },
  1595. enumerable: true,
  1596. configurable: true
  1597. });
  1598. Object.defineProperty(ClassTreeInfo.prototype, "levelContent", {
  1599. get: function () {
  1600. return this._levelContent;
  1601. },
  1602. enumerable: true,
  1603. configurable: true
  1604. });
  1605. Object.defineProperty(ClassTreeInfo.prototype, "fullContent", {
  1606. get: function () {
  1607. if (!this._fullContent) {
  1608. var dic_1 = new BABYLON.StringDictionary();
  1609. var curLevel = this;
  1610. while (curLevel) {
  1611. curLevel.levelContent.forEach(function (k, v) { return dic_1.add(k, v); });
  1612. curLevel = curLevel._baseClass;
  1613. }
  1614. this._fullContent = dic_1;
  1615. }
  1616. return this._fullContent;
  1617. },
  1618. enumerable: true,
  1619. configurable: true
  1620. });
  1621. ClassTreeInfo.prototype.getLevelOf = function (type) {
  1622. // Are we already there?
  1623. if (type === this._type) {
  1624. return this;
  1625. }
  1626. var baseProto = Object.getPrototypeOf(type);
  1627. var curProtoContent = this.getOrAddType(Object.getPrototypeOf(baseProto), baseProto);
  1628. if (!curProtoContent) {
  1629. this.getLevelOf(baseProto);
  1630. }
  1631. return this.getOrAddType(baseProto, type);
  1632. };
  1633. ClassTreeInfo.prototype.getOrAddType = function (baseType, type) {
  1634. // Are we at the level corresponding to the baseType?
  1635. // If so, get or add the level we're looking for
  1636. if (baseType === this._type) {
  1637. for (var _i = 0, _a = this._subClasses; _i < _a.length; _i++) {
  1638. var subType = _a[_i];
  1639. if (subType.type === type) {
  1640. return subType.node;
  1641. }
  1642. }
  1643. var node = new ClassTreeInfo(this, type, this._classContentFactory);
  1644. var info = { type: type, node: node };
  1645. this._subClasses.push(info);
  1646. return info.node;
  1647. }
  1648. // Recurse down to keep looking for the node corresponding to the baseTypeName
  1649. for (var _b = 0, _c = this._subClasses; _b < _c.length; _b++) {
  1650. var subType = _c[_b];
  1651. var info = subType.node.getOrAddType(baseType, type);
  1652. if (info) {
  1653. return info;
  1654. }
  1655. }
  1656. return null;
  1657. };
  1658. ClassTreeInfo.get = function (type) {
  1659. var dic = type["__classTreeInfo"];
  1660. if (!dic) {
  1661. return null;
  1662. }
  1663. return dic.getLevelOf(type);
  1664. };
  1665. ClassTreeInfo.getOrRegister = function (type, classContentFactory) {
  1666. var dic = type["__classTreeInfo"];
  1667. if (!dic) {
  1668. dic = new ClassTreeInfo(null, type, classContentFactory);
  1669. type["__classTreeInfo"] = dic;
  1670. }
  1671. return dic;
  1672. };
  1673. return ClassTreeInfo;
  1674. }());
  1675. BABYLON.ClassTreeInfo = ClassTreeInfo;
  1676. var DataBinding = (function () {
  1677. function DataBinding() {
  1678. this._converter = null;
  1679. this._mode = DataBinding.MODE_DEFAULT;
  1680. this._uiElementId = null;
  1681. this._dataSource = null;
  1682. this._currentDataSource = null;
  1683. this._propertyPathName = null;
  1684. this._stringFormat = null;
  1685. this._updateSourceTrigger = DataBinding.UPDATESOURCETRIGGER_PROPERTYCHANGED;
  1686. this._boundTo = null;
  1687. this._owner = null;
  1688. this._updateCounter = 0;
  1689. }
  1690. Object.defineProperty(DataBinding.prototype, "converter", {
  1691. /**
  1692. * Provide a callback that will convert the value obtained by the Data Binding to the type of the SmartProperty it's bound to.
  1693. * If no value are set, then it's assumed that the sourceValue is of the same type as the SmartProperty's one.
  1694. * 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.
  1695. * @param sourceValue the source object retrieve by the Data Binding mechanism
  1696. * @returns the object of a compatible type with the SmartProperty it's bound to
  1697. */
  1698. get: function () {
  1699. return this._converter;
  1700. },
  1701. set: function (value) {
  1702. if (this._converter === value) {
  1703. return;
  1704. }
  1705. this._converter = value;
  1706. },
  1707. enumerable: true,
  1708. configurable: true
  1709. });
  1710. Object.defineProperty(DataBinding.prototype, "mode", {
  1711. /**
  1712. * 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
  1713. */
  1714. get: function () {
  1715. if (this._mode === DataBinding.MODE_DEFAULT) {
  1716. return this._boundTo.bindingMode;
  1717. }
  1718. return this._mode;
  1719. },
  1720. set: function (value) {
  1721. if (this._mode === value) {
  1722. return;
  1723. }
  1724. this._mode = value;
  1725. },
  1726. enumerable: true,
  1727. configurable: true
  1728. });
  1729. Object.defineProperty(DataBinding.prototype, "uiElementId", {
  1730. /**
  1731. * You can override the Data Source object with this member which is the Id of a uiElement existing in the UI Logical tree.
  1732. * If not set and source no set too, then the dataSource property will be used.
  1733. */
  1734. get: function () {
  1735. return this._uiElementId;
  1736. },
  1737. set: function (value) {
  1738. if (this._uiElementId === value) {
  1739. return;
  1740. }
  1741. this._uiElementId = value;
  1742. },
  1743. enumerable: true,
  1744. configurable: true
  1745. });
  1746. Object.defineProperty(DataBinding.prototype, "dataSource", {
  1747. /**
  1748. * You can override the Data Source object with this member which is the source object to use directly.
  1749. * If not set and uiElement no set too, then the dataSource property of the SmartPropertyBase object will be used.
  1750. */
  1751. get: function () {
  1752. return this._dataSource;
  1753. },
  1754. set: function (value) {
  1755. if (this._dataSource === value) {
  1756. return;
  1757. }
  1758. this._dataSource = value;
  1759. },
  1760. enumerable: true,
  1761. configurable: true
  1762. });
  1763. Object.defineProperty(DataBinding.prototype, "propertyPathName", {
  1764. /**
  1765. * The path & name of the property to get from the source object.
  1766. * 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.
  1767. * If nothing is set then the source object will be used.
  1768. * 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.
  1769. * 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.
  1770. */
  1771. get: function () {
  1772. return this._propertyPathName;
  1773. },
  1774. set: function (value) {
  1775. if (this._propertyPathName === value) {
  1776. return;
  1777. }
  1778. if (this._owner) {
  1779. }
  1780. this._propertyPathName = value;
  1781. if (this._owner) {
  1782. }
  1783. },
  1784. enumerable: true,
  1785. configurable: true
  1786. });
  1787. Object.defineProperty(DataBinding.prototype, "stringFormat", {
  1788. /**
  1789. * 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}`
  1790. */
  1791. get: function () {
  1792. return this._stringFormat;
  1793. },
  1794. set: function (value) {
  1795. if (this._stringFormat === value) {
  1796. return;
  1797. }
  1798. this._stringFormat = value;
  1799. },
  1800. enumerable: true,
  1801. configurable: true
  1802. });
  1803. Object.defineProperty(DataBinding.prototype, "updateSourceTrigger", {
  1804. /**
  1805. * 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.
  1806. */
  1807. get: function () {
  1808. return this._updateSourceTrigger;
  1809. },
  1810. set: function (value) {
  1811. if (this._updateSourceTrigger === value) {
  1812. return;
  1813. }
  1814. this._updateSourceTrigger = value;
  1815. },
  1816. enumerable: true,
  1817. configurable: true
  1818. });
  1819. DataBinding.prototype.canUpdateTarget = function (resetUpdateCounter) {
  1820. if (resetUpdateCounter) {
  1821. this._updateCounter = 0;
  1822. }
  1823. var mode = this.mode;
  1824. if (mode === DataBinding.MODE_ONETIME) {
  1825. return this._updateCounter === 0;
  1826. }
  1827. if (mode === DataBinding.MODE_ONEWAYTOSOURCE) {
  1828. return false;
  1829. }
  1830. return true;
  1831. };
  1832. DataBinding.prototype.updateTarget = function () {
  1833. var value = this._getActualDataSource();
  1834. var properties = this.propertyPathName.split(".");
  1835. for (var _i = 0, properties_1 = properties; _i < properties_1.length; _i++) {
  1836. var propertyName = properties_1[_i];
  1837. value = value[propertyName];
  1838. }
  1839. this._storeBoundValue(this._owner, value);
  1840. };
  1841. DataBinding.prototype._storeBoundValue = function (watcher, value) {
  1842. if ((++this._updateCounter > 1) && (this.mode === DataBinding.MODE_ONETIME)) {
  1843. return;
  1844. }
  1845. var newValue = value;
  1846. if (this._converter) {
  1847. newValue = this._converter(value);
  1848. }
  1849. if (this._stringFormat) {
  1850. newValue = this._stringFormat(newValue);
  1851. }
  1852. watcher[this._boundTo.name] = newValue;
  1853. };
  1854. DataBinding.prototype._getActualDataSource = function () {
  1855. if (this.dataSource) {
  1856. return this.dataSource;
  1857. }
  1858. if (this.uiElementId) {
  1859. // TODO Find UIElement
  1860. return null;
  1861. }
  1862. return this._owner.dataSource;
  1863. };
  1864. DataBinding.prototype._registerDataSource = function (updateTarget) {
  1865. var ds = this._getActualDataSource();
  1866. if (ds === this._currentDataSource) {
  1867. return;
  1868. }
  1869. if (this._currentDataSource) {
  1870. BindingHelper.unregisterDataSource(this._currentDataSource, this, 0);
  1871. }
  1872. if (ds) {
  1873. BindingHelper.registerDataSource(ds, this);
  1874. if (updateTarget && this.canUpdateTarget(true)) {
  1875. this.updateTarget();
  1876. }
  1877. }
  1878. this._currentDataSource = ds;
  1879. };
  1880. DataBinding.prototype._unregisterDataSource = function () {
  1881. var ds = this._getActualDataSource();
  1882. if (ds) {
  1883. BindingHelper.unregisterDataSource(ds, this, 0);
  1884. }
  1885. };
  1886. /**
  1887. * Use the mode specified in the SmartProperty declaration
  1888. */
  1889. DataBinding.MODE_DEFAULT = 1;
  1890. /**
  1891. * Update the binding target only once when the Smart Property's value is first accessed
  1892. */
  1893. DataBinding.MODE_ONETIME = 2;
  1894. /**
  1895. * Update the smart property when the source changes.
  1896. * The source won't be updated if the smart property value is set.
  1897. */
  1898. DataBinding.MODE_ONEWAY = 3;
  1899. /**
  1900. * Only update the source when the target's data is changing.
  1901. */
  1902. DataBinding.MODE_ONEWAYTOSOURCE = 4;
  1903. /**
  1904. * Update the bind target when the source changes and update the source when the Smart Property value is set.
  1905. */
  1906. DataBinding.MODE_TWOWAY = 5;
  1907. /**
  1908. * Use the Update Source Trigger defined in the SmartProperty declaration
  1909. */
  1910. DataBinding.UPDATESOURCETRIGGER_DEFAULT = 1;
  1911. /**
  1912. * Update the source as soon as the Smart Property has a value change
  1913. */
  1914. DataBinding.UPDATESOURCETRIGGER_PROPERTYCHANGED = 2;
  1915. /**
  1916. * Update the source when the binding target loses focus
  1917. */
  1918. DataBinding.UPDATESOURCETRIGGER_LOSTFOCUS = 3;
  1919. /**
  1920. * Update the source will be made by explicitly calling the UpdateFromDataSource method
  1921. */
  1922. DataBinding.UPDATESOURCETRIGGER_EXPLICIT = 4;
  1923. DataBinding = __decorate([
  1924. BABYLON.className("DataBinding", "BABYLON")
  1925. ], DataBinding);
  1926. return DataBinding;
  1927. }());
  1928. BABYLON.DataBinding = DataBinding;
  1929. var SmartPropertyBase = (function (_super) {
  1930. __extends(SmartPropertyBase, _super);
  1931. function SmartPropertyBase() {
  1932. _super.call(this);
  1933. this._dataSource = null;
  1934. this._dataSourceObserver = null;
  1935. this._instanceDirtyFlags = 0;
  1936. this._isDisposed = false;
  1937. this._bindings = null;
  1938. this._hasBinding = 0;
  1939. this._bindingSourceChanged = 0;
  1940. this._disposeObservable = null;
  1941. }
  1942. Object.defineProperty(SmartPropertyBase.prototype, "disposeObservable", {
  1943. get: function () {
  1944. if (!this._disposeObservable) {
  1945. this._disposeObservable = new BABYLON.Observable();
  1946. }
  1947. return this._disposeObservable;
  1948. },
  1949. enumerable: true,
  1950. configurable: true
  1951. });
  1952. Object.defineProperty(SmartPropertyBase.prototype, "isDisposed", {
  1953. /**
  1954. * Check if the object is disposed or not.
  1955. * @returns true if the object is dispose, false otherwise.
  1956. */
  1957. get: function () {
  1958. return this._isDisposed;
  1959. },
  1960. enumerable: true,
  1961. configurable: true
  1962. });
  1963. /**
  1964. * Disposable pattern, this method must be overloaded by derived types in order to clean up hardware related resources.
  1965. * @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.
  1966. */
  1967. SmartPropertyBase.prototype.dispose = function () {
  1968. if (this.isDisposed) {
  1969. return false;
  1970. }
  1971. if (this._disposeObservable && this._disposeObservable.hasObservers()) {
  1972. this._disposeObservable.notifyObservers(this);
  1973. }
  1974. this._isDisposed = true;
  1975. return true;
  1976. };
  1977. /**
  1978. * Check if a given set of properties are dirty or not.
  1979. * @param flags a ORed combination of Prim2DPropInfo.flagId values
  1980. * @return true if at least one property is dirty, false if none of them are.
  1981. */
  1982. SmartPropertyBase.prototype.checkPropertiesDirty = function (flags) {
  1983. return (this._instanceDirtyFlags & flags) !== 0;
  1984. };
  1985. /**
  1986. * Clear a given set of properties.
  1987. * @param flags a ORed combination of Prim2DPropInfo.flagId values
  1988. * @return the new set of property still marked as dirty
  1989. */
  1990. SmartPropertyBase.prototype.clearPropertiesDirty = function (flags) {
  1991. this._instanceDirtyFlags &= ~flags;
  1992. return this._instanceDirtyFlags;
  1993. };
  1994. SmartPropertyBase.prototype._resetPropertiesDirty = function () {
  1995. this._instanceDirtyFlags = 0;
  1996. };
  1997. /**
  1998. * Add an externally attached data from its key.
  1999. * This method call will fail and return false, if such key already exists.
  2000. * If you don't care and just want to get the data no matter what, use the more convenient getOrAddExternalDataWithFactory() method.
  2001. * @param key the unique key that identifies the data
  2002. * @param data the data object to associate to the key for this Engine instance
  2003. * @return true if no such key were already present and the data was added successfully, false otherwise
  2004. */
  2005. SmartPropertyBase.prototype.addExternalData = function (key, data) {
  2006. if (!this._externalData) {
  2007. this._externalData = new BABYLON.StringDictionary();
  2008. }
  2009. return this._externalData.add(key, data);
  2010. };
  2011. /**
  2012. * Get an externally attached data from its key
  2013. * @param key the unique key that identifies the data
  2014. * @return the associated data, if present (can be null), or undefined if not present
  2015. */
  2016. SmartPropertyBase.prototype.getExternalData = function (key) {
  2017. if (!this._externalData) {
  2018. return null;
  2019. }
  2020. return this._externalData.get(key);
  2021. };
  2022. /**
  2023. * Get an externally attached data from its key, create it using a factory if it's not already present
  2024. * @param key the unique key that identifies the data
  2025. * @param factory the factory that will be called to create the instance if and only if it doesn't exists
  2026. * @return the associated data, can be null if the factory returned null.
  2027. */
  2028. SmartPropertyBase.prototype.getOrAddExternalDataWithFactory = function (key, factory) {
  2029. if (!this._externalData) {
  2030. this._externalData = new BABYLON.StringDictionary();
  2031. }
  2032. return this._externalData.getOrAddWithFactory(key, factory);
  2033. };
  2034. /**
  2035. * Remove an externally attached data from the Engine instance
  2036. * @param key the unique key that identifies the data
  2037. * @return true if the data was successfully removed, false if it doesn't exist
  2038. */
  2039. SmartPropertyBase.prototype.removeExternalData = function (key) {
  2040. if (!this._externalData) {
  2041. return false;
  2042. }
  2043. return this._externalData.remove(key);
  2044. };
  2045. SmartPropertyBase._hookProperty = function (propId, piStore, kind, settings) {
  2046. return function (target, propName, descriptor) {
  2047. if (!settings) {
  2048. settings = {};
  2049. }
  2050. var propInfo = SmartPropertyBase._createPropInfo(target, propName, propId, kind, settings);
  2051. if (piStore) {
  2052. piStore(propInfo);
  2053. }
  2054. var getter = descriptor.get, setter = descriptor.set;
  2055. var typeLevelCompare = (settings.typeLevelCompare !== undefined) ? settings.typeLevelCompare : false;
  2056. // Overload the property setter implementation to add our own logic
  2057. descriptor.set = function (val) {
  2058. if (!setter) {
  2059. throw Error("Property '" + propInfo.name + "' of type '" + BABYLON.Tools.getFullClassName(this) + "' has no setter defined but was invoked as if it had one.");
  2060. }
  2061. // check for disposed first, do nothing
  2062. if (this.isDisposed) {
  2063. return;
  2064. }
  2065. var curVal = getter.call(this);
  2066. if (SmartPropertyBase._checkUnchanged(curVal, val)) {
  2067. return;
  2068. }
  2069. // Cast the object we're working one
  2070. var prim = this;
  2071. // Change the value
  2072. setter.call(this, val);
  2073. // Notify change, dirty flags update
  2074. prim._handlePropChanged(curVal, val, propName, propInfo, typeLevelCompare);
  2075. };
  2076. };
  2077. };
  2078. SmartPropertyBase._createPropInfo = function (target, propName, propId, kind, settings) {
  2079. var dic = ClassTreeInfo.getOrRegister(target, function () { return new Prim2DClassInfo(); });
  2080. var node = dic.getLevelOf(target);
  2081. var propInfo = node.levelContent.get(propId.toString());
  2082. if (propInfo) {
  2083. throw new Error("The ID " + propId + " is already taken by another property declaration named: " + propInfo.name);
  2084. }
  2085. // Create, setup and add the PropInfo object to our prop dictionary
  2086. propInfo = new Prim2DPropInfo();
  2087. propInfo.id = propId;
  2088. propInfo.flagId = Math.pow(2, propId);
  2089. propInfo.kind = kind;
  2090. propInfo.name = propName;
  2091. propInfo.bindingMode = (settings.bindingMode !== undefined) ? settings.bindingMode : DataBinding.MODE_TWOWAY;
  2092. propInfo.bindingUpdateSourceTrigger = (settings.bindingUpdateSourceTrigger !== undefined) ? settings.bindingUpdateSourceTrigger : DataBinding.UPDATESOURCETRIGGER_PROPERTYCHANGED;
  2093. propInfo.dirtyBoundingInfo = (settings.dirtyBoundingInfo !== undefined) ? settings.dirtyBoundingInfo : false;
  2094. propInfo.dirtyParentBoundingInfo = (settings.dirtyParentBoundingBox !== undefined) ? settings.dirtyParentBoundingBox : false;
  2095. propInfo.typeLevelCompare = (settings.typeLevelCompare !== undefined) ? settings.typeLevelCompare : false;
  2096. node.levelContent.add(propName, propInfo);
  2097. return propInfo;
  2098. };
  2099. Object.defineProperty(SmartPropertyBase.prototype, "propDic", {
  2100. /**
  2101. * Access the dictionary of properties metadata. Only properties decorated with XXXXLevelProperty are concerned
  2102. * @returns the dictionary, the key is the property name as declared in Javascript, the value is the metadata object
  2103. */
  2104. get: function () {
  2105. if (!this._propInfo) {
  2106. var cti = ClassTreeInfo.get(Object.getPrototypeOf(this));
  2107. if (!cti) {
  2108. throw new Error("Can't access the propDic member in class definition, is this class SmartPropertyPrim based?");
  2109. }
  2110. this._propInfo = cti.fullContent;
  2111. }
  2112. return this._propInfo;
  2113. },
  2114. enumerable: true,
  2115. configurable: true
  2116. });
  2117. SmartPropertyBase._checkUnchanged = function (curValue, newValue) {
  2118. // Nothing to nothing: nothing to do!
  2119. if ((curValue === null && newValue === null) || (curValue === undefined && newValue === undefined)) {
  2120. return true;
  2121. }
  2122. // Check value unchanged
  2123. if ((curValue != null) && (newValue != null)) {
  2124. if (typeof (curValue.equals) == "function") {
  2125. if (curValue.equals(newValue)) {
  2126. return true;
  2127. }
  2128. }
  2129. else {
  2130. if (curValue === newValue) {
  2131. return true;
  2132. }
  2133. }
  2134. }
  2135. return false;
  2136. };
  2137. SmartPropertyBase.prototype._handlePropChanged = function (curValue, newValue, propName, propInfo, typeLevelCompare) {
  2138. // Trigger property changed
  2139. var info = SmartPropertyBase.propChangeGuarding ? new BABYLON.PropertyChangedInfo() : SmartPropertyPrim.propChangedInfo;
  2140. info.oldValue = curValue;
  2141. info.newValue = newValue;
  2142. info.propertyName = propName;
  2143. var propMask = propInfo ? propInfo.flagId : -1;
  2144. try {
  2145. SmartPropertyBase.propChangeGuarding = true;
  2146. this.propertyChanged.notifyObservers(info, propMask);
  2147. }
  2148. finally {
  2149. SmartPropertyBase.propChangeGuarding = false;
  2150. }
  2151. };
  2152. SmartPropertyBase.prototype._triggerPropertyChanged = function (propInfo, newValue) {
  2153. if (this.isDisposed) {
  2154. return;
  2155. }
  2156. if (!propInfo) {
  2157. return;
  2158. }
  2159. this._handlePropChanged(undefined, newValue, propInfo.name, propInfo, propInfo.typeLevelCompare);
  2160. };
  2161. Object.defineProperty(SmartPropertyBase.prototype, "dataSource", {
  2162. /**
  2163. * Set the object from which Smart Properties using Binding will take/update their data from/to.
  2164. * 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.
  2165. */
  2166. get: function () {
  2167. // Don't access to _dataSource directly but via a call to the _getDataSource method which can be overloaded in inherited classes
  2168. return this._getDataSource();
  2169. },
  2170. set: function (value) {
  2171. if (this._dataSource === value) {
  2172. return;
  2173. }
  2174. var oldValue = this._dataSource;
  2175. this._dataSource = value;
  2176. if (this._bindings && value != null) {
  2177. // Register the bindings
  2178. for (var _i = 0, _a = this._bindings; _i < _a.length; _i++) {
  2179. var binding = _a[_i];
  2180. if (binding != null) {
  2181. binding._registerDataSource(true);
  2182. }
  2183. }
  2184. }
  2185. this.onPropertyChanged("dataSource", oldValue, value);
  2186. },
  2187. enumerable: true,
  2188. configurable: true
  2189. });
  2190. // Inheriting classes can overload this method to provides additional logic for dataSource access
  2191. SmartPropertyBase.prototype._getDataSource = function () {
  2192. return this._dataSource;
  2193. };
  2194. SmartPropertyBase.prototype.createSimpleDataBinding = function (propInfo, propertyPathName, mode) {
  2195. if (mode === void 0) { mode = DataBinding.MODE_DEFAULT; }
  2196. var binding = new DataBinding();
  2197. binding.propertyPathName = propertyPathName;
  2198. binding.mode = mode;
  2199. return this.createDataBinding(propInfo, binding);
  2200. };
  2201. SmartPropertyBase.prototype.createDataBinding = function (propInfo, binding) {
  2202. if (!this._bindings) {
  2203. this._bindings = new Array();
  2204. }
  2205. if (!binding || binding._owner != null) {
  2206. throw Error("A valid/unused Binding must be passed.");
  2207. }
  2208. // Unregister a potentially existing binding for this property
  2209. this.removeDataBinding(propInfo);
  2210. // register the binding
  2211. binding._owner = this;
  2212. binding._boundTo = propInfo;
  2213. this._bindings[propInfo.id] = binding;
  2214. this._hasBinding |= propInfo.flagId;
  2215. binding._registerDataSource(true);
  2216. return binding;
  2217. };
  2218. SmartPropertyBase.prototype.removeDataBinding = function (propInfo) {
  2219. if ((this._hasBinding & propInfo.flagId) === 0) {
  2220. return false;
  2221. }
  2222. var curBinding = this._bindings[propInfo.id];
  2223. curBinding._unregisterDataSource();
  2224. this._bindings[propInfo.id] = null;
  2225. this._hasBinding &= ~propInfo.flagId;
  2226. return true;
  2227. };
  2228. SmartPropertyBase.prototype.updateFromDataSource = function () {
  2229. for (var _i = 0, _a = this._bindings; _i < _a.length; _i++) {
  2230. var binding = _a[_i];
  2231. if (binding) {
  2232. }
  2233. }
  2234. };
  2235. SmartPropertyBase.propChangedInfo = new BABYLON.PropertyChangedInfo();
  2236. SmartPropertyBase.propChangeGuarding = false;
  2237. SmartPropertyBase = __decorate([
  2238. BABYLON.className("SmartPropertyBase", "BABYLON")
  2239. ], SmartPropertyBase);
  2240. return SmartPropertyBase;
  2241. }(BABYLON.PropertyChangedBase));
  2242. BABYLON.SmartPropertyBase = SmartPropertyBase;
  2243. var BindingInfo = (function () {
  2244. function BindingInfo(binding, level, isLast) {
  2245. this.binding = binding;
  2246. this.level = level;
  2247. this.isLast = isLast;
  2248. }
  2249. return BindingInfo;
  2250. }());
  2251. var MonitoredObjectData = (function () {
  2252. function MonitoredObjectData(monitoredObject) {
  2253. var _this = this;
  2254. this.monitoredObject = monitoredObject;
  2255. this.monitoredIntermediateProperties = new BABYLON.StringDictionary();
  2256. this.observer = this.monitoredObject.propertyChanged.add(function (e, s) { _this.propertyChangedHandler(e.propertyName, e.oldValue, e.newValue); });
  2257. this.boundProperties = new BABYLON.StringDictionary();
  2258. this.monitoredIntermediateMask = 0;
  2259. this.boundPropertiesMask = 0;
  2260. }
  2261. MonitoredObjectData.prototype.propertyChangedHandler = function (propName, oldValue, newValue) {
  2262. var propId = BindingHelper._getPropertyID(this.monitoredObject, propName);
  2263. var propIdStr = propId.toString();
  2264. // Loop through all the registered bindings for this property that had a value change
  2265. if ((this.boundPropertiesMask & propId) !== 0) {
  2266. var bindingInfos = this.boundProperties.get(propIdStr);
  2267. for (var _i = 0, bindingInfos_1 = bindingInfos; _i < bindingInfos_1.length; _i++) {
  2268. var bi = bindingInfos_1[_i];
  2269. if (!bi.isLast) {
  2270. BindingHelper.unregisterDataSource(this.monitoredObject, bi.binding, bi.level);
  2271. BindingHelper.registerDataSource(bi.binding._currentDataSource, bi.binding);
  2272. }
  2273. if (bi.binding.canUpdateTarget(false)) {
  2274. bi.binding.updateTarget();
  2275. }
  2276. }
  2277. }
  2278. };
  2279. return MonitoredObjectData;
  2280. }());
  2281. var BindingHelper = (function () {
  2282. function BindingHelper() {
  2283. }
  2284. BindingHelper.registerDataSource = function (dataSource, binding) {
  2285. var properties = binding.propertyPathName.split(".");
  2286. var ownerMod = null;
  2287. var ownerInterPropId = 0;
  2288. var propertyOwner = dataSource;
  2289. var _loop_1 = function(i) {
  2290. var propName = properties[i];
  2291. var propId = BindingHelper._getPropertyID(propertyOwner, propName);
  2292. var propIdStr = propId.toString();
  2293. var mod = void 0;
  2294. if (ownerMod) {
  2295. var o_1 = ownerMod;
  2296. var po_1 = propertyOwner;
  2297. var oii_1 = ownerInterPropId;
  2298. mod = ownerMod.monitoredIntermediateProperties.getOrAddWithFactory(oii_1.toString(), function (k) {
  2299. o_1.monitoredIntermediateMask |= oii_1;
  2300. return BindingHelper._getMonitoredObjectData(po_1);
  2301. });
  2302. }
  2303. else {
  2304. mod = BindingHelper._getMonitoredObjectData(propertyOwner);
  2305. }
  2306. var m = mod;
  2307. var bindingInfos = mod.boundProperties.getOrAddWithFactory(propIdStr, function (k) {
  2308. m.boundPropertiesMask |= propId;
  2309. return new Array();
  2310. });
  2311. var bi = BABYLON.Tools.first(bindingInfos, function (cbi) { return cbi.binding === binding; });
  2312. if (!bi) {
  2313. bindingInfos.push(new BindingInfo(binding, i, (i + 1) === properties.length));
  2314. }
  2315. ownerMod = mod;
  2316. ownerInterPropId = propId;
  2317. propertyOwner = propertyOwner[propName];
  2318. };
  2319. for (var i = 0; i < properties.length; i++) {
  2320. _loop_1(i);
  2321. }
  2322. };
  2323. BindingHelper.unregisterDataSource = function (dataSource, binding, level) {
  2324. var properties = binding.propertyPathName.split(".");
  2325. var propertyOwner = dataSource;
  2326. var mod = BindingHelper._getMonitoredObjectData(propertyOwner);
  2327. for (var i = 0; i < properties.length; i++) {
  2328. var propName = properties[i];
  2329. var propId = BindingHelper._getPropertyID(propertyOwner, propName);
  2330. var propIdStr = propId.toString();
  2331. if (i >= level) {
  2332. mod = BindingHelper._unregisterBinding(mod, propId, binding);
  2333. }
  2334. else {
  2335. mod = mod.monitoredIntermediateProperties.get(propIdStr);
  2336. }
  2337. propertyOwner = propertyOwner[propName];
  2338. }
  2339. };
  2340. BindingHelper._unregisterBinding = function (mod, propertyID, binding) {
  2341. var propertyIDStr = propertyID.toString();
  2342. var res = null;
  2343. // Check if the property is registered as an intermediate and remove it
  2344. if ((mod.monitoredIntermediateMask & propertyID) !== 0) {
  2345. res = mod.monitoredIntermediateProperties.get(propertyIDStr);
  2346. mod.monitoredIntermediateProperties.remove(propertyIDStr);
  2347. // Update the mask
  2348. mod.monitoredIntermediateMask &= ~propertyID;
  2349. }
  2350. // Check if the property is registered as a final property and remove it
  2351. if ((mod.boundPropertiesMask & propertyID) !== 0) {
  2352. var bindingInfos = mod.boundProperties.get(propertyIDStr);
  2353. // Find the binding and remove it
  2354. var bi = BABYLON.Tools.first(bindingInfos, function (cbi) { return cbi.binding === binding; });
  2355. if (bi) {
  2356. var bii = bindingInfos.indexOf(bi);
  2357. bindingInfos.splice(bii, 1);
  2358. }
  2359. // If the array is empty, update the mask
  2360. if (bindingInfos.length === 0) {
  2361. mod.boundPropertiesMask &= ~propertyID;
  2362. }
  2363. }
  2364. // Check if the MOD is empty and unregister the observer and remove it from the list of MODs
  2365. if (mod.boundPropertiesMask === 0 && mod.monitoredIntermediateMask === 0) {
  2366. // Unregister the observer on Property Change
  2367. mod.monitoredObject.propertyChanged.remove(mod.observer);
  2368. // Remove the MOD from the dic
  2369. var objectId = BindingHelper._getObjectId(mod.monitoredObject);
  2370. BindingHelper._monitoredObjects.remove(objectId);
  2371. }
  2372. return res;
  2373. };
  2374. BindingHelper._getMonitoredObjectData = function (object) {
  2375. var objectId = BindingHelper._getObjectId(object);
  2376. var mod = BindingHelper._monitoredObjects.getOrAddWithFactory(objectId, function (k) { return new MonitoredObjectData(object); });
  2377. return mod;
  2378. };
  2379. BindingHelper._getObjectId = function (obj) {
  2380. var id = obj["__bindingHelperObjectId__"];
  2381. if (id == null) {
  2382. id = BABYLON.Tools.RandomId();
  2383. obj["__bindingHelperObjectId__"] = id;
  2384. return id;
  2385. }
  2386. return id;
  2387. };
  2388. BindingHelper._getObjectTypePropertyIDs = function (obj) {
  2389. var fullName = BABYLON.Tools.getFullClassName(obj);
  2390. if (!fullName) {
  2391. throw Error("Types involved in Data Binding must be decorated with the @className decorator");
  2392. }
  2393. var d = BindingHelper._propertiesID.getOrAddWithFactory(fullName, function () { return new BABYLON.StringDictionary(); });
  2394. return d;
  2395. };
  2396. BindingHelper._getPropertyID = function (object, propName) {
  2397. var otd = BindingHelper._getObjectTypePropertyIDs(object);
  2398. // Make sure we have a WatchedPropertyData for this property of this object type. This will contains the flagIg of the watched property.
  2399. // We use this flagId to flag for each watched instance which properties are watched, as final or intermediate and which directions are used
  2400. var propData = otd.getOrAddWithFactory(propName, function (k) { return 1 << otd.count; });
  2401. return propData;
  2402. };
  2403. BindingHelper._propertiesID = new BABYLON.StringDictionary();
  2404. BindingHelper._monitoredObjects = new BABYLON.StringDictionary();
  2405. return BindingHelper;
  2406. }());
  2407. var SmartPropertyPrim = (function (_super) {
  2408. __extends(SmartPropertyPrim, _super);
  2409. function SmartPropertyPrim() {
  2410. _super.call(this);
  2411. this._flags = 0;
  2412. this._modelKey = null;
  2413. this._levelBoundingInfo = new BABYLON.BoundingInfo2D();
  2414. this._boundingInfo = new BABYLON.BoundingInfo2D();
  2415. this.animations = new Array();
  2416. }
  2417. /**
  2418. * Disposable pattern, this method must be overloaded by derived types in order to clean up hardware related resources.
  2419. * @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.
  2420. */
  2421. SmartPropertyPrim.prototype.dispose = function () {
  2422. if (this.isDisposed) {
  2423. return false;
  2424. }
  2425. _super.prototype.dispose.call(this);
  2426. // Don't set to null, it may upset somebody...
  2427. this.animations.splice(0);
  2428. return true;
  2429. };
  2430. /**
  2431. * Returns as a new array populated with the Animatable used by the primitive. Must be overloaded by derived primitives.
  2432. * Look at Sprite2D for more information
  2433. */
  2434. SmartPropertyPrim.prototype.getAnimatables = function () {
  2435. return new Array();
  2436. };
  2437. Object.defineProperty(SmartPropertyPrim.prototype, "modelKey", {
  2438. /**
  2439. * Property giving the Model Key associated to the property.
  2440. * This value is constructed from the type of the primitive and all the name/value of its properties declared with the modelLevelProperty decorator
  2441. * @returns the model key string.
  2442. */
  2443. get: function () {
  2444. var _this = this;
  2445. // No need to compute it?
  2446. if (!this._isFlagSet(SmartPropertyPrim.flagModelDirty) && this._modelKey) {
  2447. return this._modelKey;
  2448. }
  2449. var modelKey = "Class:" + BABYLON.Tools.getClassName(this) + ";";
  2450. var propDic = this.propDic;
  2451. propDic.forEach(function (k, v) {
  2452. if (v.kind === Prim2DPropInfo.PROPKIND_MODEL) {
  2453. var propVal = _this[v.name];
  2454. // 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
  2455. if (propVal && propVal.constructor === Array) {
  2456. var firstVal = propVal[0];
  2457. if (!firstVal) {
  2458. propVal = 0;
  2459. }
  2460. else {
  2461. propVal = BABYLON.Tools.hashCodeFromStream(BABYLON.Tools.arrayOrStringFeeder(propVal));
  2462. }
  2463. }
  2464. var value = "[null]";
  2465. if (propVal != null) {
  2466. if (v.typeLevelCompare) {
  2467. value = BABYLON.Tools.getClassName(propVal);
  2468. }
  2469. else {
  2470. if (propVal instanceof BABYLON.BaseTexture) {
  2471. value = propVal.uid;
  2472. }
  2473. else {
  2474. value = propVal.toString();
  2475. }
  2476. }
  2477. }
  2478. modelKey += v.name + ":" + value + ";";
  2479. }
  2480. });
  2481. this._clearFlags(SmartPropertyPrim.flagModelDirty);
  2482. this._modelKey = modelKey;
  2483. return modelKey;
  2484. },
  2485. enumerable: true,
  2486. configurable: true
  2487. });
  2488. Object.defineProperty(SmartPropertyPrim.prototype, "isDirty", {
  2489. /**
  2490. * States if the Primitive is dirty and should be rendered again next time.
  2491. * @returns true is dirty, false otherwise
  2492. */
  2493. get: function () {
  2494. return (this._instanceDirtyFlags !== 0) || this._areSomeFlagsSet(SmartPropertyPrim.flagModelDirty | SmartPropertyPrim.flagPositioningDirty | SmartPropertyPrim.flagLayoutDirty);
  2495. },
  2496. enumerable: true,
  2497. configurable: true
  2498. });
  2499. SmartPropertyPrim.prototype._boundingBoxDirty = function () {
  2500. this._setFlags(SmartPropertyPrim.flagLevelBoundingInfoDirty);
  2501. // Escalate the dirty flag in the instance hierarchy, stop when a renderable group is found or at the end
  2502. if (this instanceof BABYLON.Prim2DBase) {
  2503. var curprim = this;
  2504. while (curprim) {
  2505. curprim._setFlags(SmartPropertyPrim.flagBoundingInfoDirty);
  2506. if (curprim.isSizeAuto) {
  2507. curprim.onPrimitivePropertyDirty(BABYLON.Prim2DBase.sizeProperty.flagId);
  2508. curprim._setFlags(SmartPropertyPrim.flagPositioningDirty);
  2509. }
  2510. if (curprim instanceof BABYLON.Group2D) {
  2511. if (curprim.isRenderableGroup) {
  2512. break;
  2513. }
  2514. }
  2515. curprim = curprim.parent;
  2516. }
  2517. }
  2518. };
  2519. SmartPropertyPrim.prototype._handlePropChanged = function (curValue, newValue, propName, propInfo, typeLevelCompare) {
  2520. _super.prototype._handlePropChanged.call(this, curValue, newValue, propName, propInfo, typeLevelCompare);
  2521. // If the property change also dirty the boundingInfo, update the boundingInfo dirty flags
  2522. if (propInfo.dirtyBoundingInfo) {
  2523. this._boundingBoxDirty();
  2524. }
  2525. else if (propInfo.dirtyParentBoundingInfo) {
  2526. var p = this._parent;
  2527. if (p != null) {
  2528. p._boundingBoxDirty();
  2529. }
  2530. }
  2531. // If the property belong to a group, check if it's a cached one, and dirty its render sprite accordingly
  2532. if (this instanceof BABYLON.Group2D && this._renderableData) {
  2533. this.handleGroupChanged(propInfo);
  2534. }
  2535. // Check for parent layout dirty
  2536. if (this instanceof BABYLON.Prim2DBase) {
  2537. var p = this._parent;
  2538. if (p != null && p.layoutEngine && (p.layoutEngine.layoutDirtyOnPropertyChangedMask & propInfo.flagId) !== 0) {
  2539. p._setLayoutDirty();
  2540. }
  2541. }
  2542. // For type level compare, if there's a change of type it's a change of model, otherwise we issue an instance change
  2543. var instanceDirty = false;
  2544. if (typeLevelCompare && curValue != null && newValue != null) {
  2545. var cvProto = curValue.__proto__;
  2546. var nvProto = newValue.__proto__;
  2547. instanceDirty = (cvProto === nvProto);
  2548. }
  2549. // Set the dirty flags
  2550. if (!instanceDirty && (propInfo.kind === Prim2DPropInfo.PROPKIND_MODEL)) {
  2551. if (!this.isDirty) {
  2552. this._setFlags(SmartPropertyPrim.flagModelDirty);
  2553. }
  2554. }
  2555. else if (instanceDirty || (propInfo.kind === Prim2DPropInfo.PROPKIND_INSTANCE) || (propInfo.kind === Prim2DPropInfo.PROPKIND_DYNAMIC)) {
  2556. var propMask = propInfo.flagId;
  2557. this.onPrimitivePropertyDirty(propMask);
  2558. }
  2559. };
  2560. SmartPropertyPrim.prototype.onPrimitivePropertyDirty = function (propFlagId) {
  2561. this.onPrimBecomesDirty();
  2562. this._instanceDirtyFlags |= propFlagId;
  2563. };
  2564. SmartPropertyPrim.prototype.handleGroupChanged = function (prop) {
  2565. };
  2566. SmartPropertyPrim.prototype._resetPropertiesDirty = function () {
  2567. _super.prototype._resetPropertiesDirty.call(this);
  2568. this._clearFlags(SmartPropertyPrim.flagPrimInDirtyList | SmartPropertyPrim.flagNeedRefresh);
  2569. };
  2570. Object.defineProperty(SmartPropertyPrim.prototype, "levelBoundingInfo", {
  2571. /**
  2572. * Retrieve the boundingInfo for this Primitive, computed based on the primitive itself and NOT its children
  2573. */
  2574. get: function () {
  2575. if (this._isFlagSet(SmartPropertyPrim.flagLevelBoundingInfoDirty)) {
  2576. this.updateLevelBoundingInfo();
  2577. this._clearFlags(SmartPropertyPrim.flagLevelBoundingInfoDirty);
  2578. }
  2579. return this._levelBoundingInfo;
  2580. },
  2581. enumerable: true,
  2582. configurable: true
  2583. });
  2584. /**
  2585. * This method must be overridden by a given Primitive implementation to compute its boundingInfo
  2586. */
  2587. SmartPropertyPrim.prototype.updateLevelBoundingInfo = function () {
  2588. };
  2589. /**
  2590. * Property method called when the Primitive becomes dirty
  2591. */
  2592. SmartPropertyPrim.prototype.onPrimBecomesDirty = function () {
  2593. };
  2594. /**
  2595. * Check if a given flag is set
  2596. * @param flag the flag value
  2597. * @return true if set, false otherwise
  2598. */
  2599. SmartPropertyPrim.prototype._isFlagSet = function (flag) {
  2600. return (this._flags & flag) !== 0;
  2601. };
  2602. /**
  2603. * Check if all given flags are set
  2604. * @param flags the flags ORed
  2605. * @return true if all the flags are set, false otherwise
  2606. */
  2607. SmartPropertyPrim.prototype._areAllFlagsSet = function (flags) {
  2608. return (this._flags & flags) === flags;
  2609. };
  2610. /**
  2611. * Check if at least one flag of the given flags is set
  2612. * @param flags the flags ORed
  2613. * @return true if at least one flag is set, false otherwise
  2614. */
  2615. SmartPropertyPrim.prototype._areSomeFlagsSet = function (flags) {
  2616. return (this._flags & flags) !== 0;
  2617. };
  2618. /**
  2619. * Clear the given flags
  2620. * @param flags the flags to clear
  2621. */
  2622. SmartPropertyPrim.prototype._clearFlags = function (flags) {
  2623. this._flags &= ~flags;
  2624. };
  2625. /**
  2626. * Set the given flags to true state
  2627. * @param flags the flags ORed to set
  2628. * @return the flags state before this call
  2629. */
  2630. SmartPropertyPrim.prototype._setFlags = function (flags) {
  2631. var cur = this._flags;
  2632. this._flags |= flags;
  2633. return cur;
  2634. };
  2635. /**
  2636. * Change the state of the given flags
  2637. * @param flags the flags ORed to change
  2638. * @param state true to set them, false to clear them
  2639. */
  2640. SmartPropertyPrim.prototype._changeFlags = function (flags, state) {
  2641. if (state) {
  2642. this._flags |= flags;
  2643. }
  2644. else {
  2645. this._flags &= ~flags;
  2646. }
  2647. };
  2648. SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT = 0;
  2649. SmartPropertyPrim.flagNoPartOfLayout = 0x0000001; // set if the primitive's position/size must not be computed by Layout Engine
  2650. SmartPropertyPrim.flagLevelBoundingInfoDirty = 0x0000002; // set if the primitive's level bounding box (not including children) is dirty
  2651. SmartPropertyPrim.flagModelDirty = 0x0000004; // set if the model must be changed
  2652. SmartPropertyPrim.flagLayoutDirty = 0x0000008; // set if the layout must be computed
  2653. SmartPropertyPrim.flagLevelVisible = 0x0000010; // set if the primitive is set as visible for its level only
  2654. SmartPropertyPrim.flagBoundingInfoDirty = 0x0000020; // set if the primitive's overall bounding box (including children) is dirty
  2655. SmartPropertyPrim.flagIsPickable = 0x0000040; // set if the primitive can be picked during interaction
  2656. SmartPropertyPrim.flagIsVisible = 0x0000080; // set if the primitive is concretely visible (use the levelVisible of parents)
  2657. SmartPropertyPrim.flagVisibilityChanged = 0x0000100; // set if there was a transition between visible/hidden status
  2658. SmartPropertyPrim.flagPositioningDirty = 0x0000200; // set if the primitive positioning must be computed
  2659. SmartPropertyPrim.flagTrackedGroup = 0x0000400; // set if the group2D is tracking a scene node
  2660. SmartPropertyPrim.flagWorldCacheChanged = 0x0000800; // set if the cached bitmap of a world space canvas changed
  2661. SmartPropertyPrim.flagChildrenFlatZOrder = 0x0001000; // set if all the children (direct and indirect) will share the same Z-Order
  2662. SmartPropertyPrim.flagZOrderDirty = 0x0002000; // set if the Z-Order for this prim and its children must be recomputed
  2663. SmartPropertyPrim.flagActualOpacityDirty = 0x0004000; // set if the actualOpactity should be recomputed
  2664. SmartPropertyPrim.flagPrimInDirtyList = 0x0008000; // set if the primitive is in the primDirtyList
  2665. SmartPropertyPrim.flagIsContainer = 0x0010000; // set if the primitive is a container
  2666. SmartPropertyPrim.flagNeedRefresh = 0x0020000; // set if the primitive wasn't successful at refresh
  2667. SmartPropertyPrim.flagActualScaleDirty = 0x0040000; // set if the actualScale property needs to be recomputed
  2668. SmartPropertyPrim.flagDontInheritParentScale = 0x0080000; // set if the actualScale must not use its parent's scale to be computed
  2669. SmartPropertyPrim.flagGlobalTransformDirty = 0x0100000; // set if the global transform must be recomputed due to a local transform change
  2670. SmartPropertyPrim.flagLayoutBoundingInfoDirty = 0x0200000; // set if the layout bounding info is dirty
  2671. SmartPropertyPrim = __decorate([
  2672. BABYLON.className("SmartPropertyPrim", "BABYLON")
  2673. ], SmartPropertyPrim);
  2674. return SmartPropertyPrim;
  2675. }(SmartPropertyBase));
  2676. BABYLON.SmartPropertyPrim = SmartPropertyPrim;
  2677. function dependencyProperty(propId, piStore, mode, updateSourceTrigger) {
  2678. if (mode === void 0) { mode = DataBinding.MODE_TWOWAY; }
  2679. if (updateSourceTrigger === void 0) { updateSourceTrigger = DataBinding.UPDATESOURCETRIGGER_PROPERTYCHANGED; }
  2680. return SmartPropertyBase._hookProperty(propId, piStore, Prim2DPropInfo.PROPKIND_DYNAMIC, { bindingMode: mode, bindingUpdateSourceTrigger: updateSourceTrigger });
  2681. }
  2682. BABYLON.dependencyProperty = dependencyProperty;
  2683. function modelLevelProperty(propId, piStore, typeLevelCompare, dirtyBoundingInfo, dirtyParentBoundingBox) {
  2684. if (typeLevelCompare === void 0) { typeLevelCompare = false; }
  2685. if (dirtyBoundingInfo === void 0) { dirtyBoundingInfo = false; }
  2686. if (dirtyParentBoundingBox === void 0) { dirtyParentBoundingBox = false; }
  2687. return SmartPropertyBase._hookProperty(propId, piStore, Prim2DPropInfo.PROPKIND_MODEL, { typeLevelCompare: typeLevelCompare, dirtyBoundingInfo: dirtyBoundingInfo, dirtyParentBoundingBox: dirtyParentBoundingBox });
  2688. }
  2689. BABYLON.modelLevelProperty = modelLevelProperty;
  2690. function instanceLevelProperty(propId, piStore, typeLevelCompare, dirtyBoundingInfo, dirtyParentBoundingBox) {
  2691. if (typeLevelCompare === void 0) { typeLevelCompare = false; }
  2692. if (dirtyBoundingInfo === void 0) { dirtyBoundingInfo = false; }
  2693. if (dirtyParentBoundingBox === void 0) { dirtyParentBoundingBox = false; }
  2694. return SmartPropertyBase._hookProperty(propId, piStore, Prim2DPropInfo.PROPKIND_INSTANCE, { typeLevelCompare: typeLevelCompare, dirtyBoundingInfo: dirtyBoundingInfo, dirtyParentBoundingBox: dirtyParentBoundingBox });
  2695. }
  2696. BABYLON.instanceLevelProperty = instanceLevelProperty;
  2697. function dynamicLevelProperty(propId, piStore, typeLevelCompare, dirtyBoundingInfo, dirtyParentBoundingBox) {
  2698. if (typeLevelCompare === void 0) { typeLevelCompare = false; }
  2699. if (dirtyBoundingInfo === void 0) { dirtyBoundingInfo = false; }
  2700. if (dirtyParentBoundingBox === void 0) { dirtyParentBoundingBox = false; }
  2701. return SmartPropertyBase._hookProperty(propId, piStore, Prim2DPropInfo.PROPKIND_DYNAMIC, { typeLevelCompare: typeLevelCompare, dirtyBoundingInfo: dirtyBoundingInfo, dirtyParentBoundingBox: dirtyParentBoundingBox });
  2702. }
  2703. BABYLON.dynamicLevelProperty = dynamicLevelProperty;
  2704. })(BABYLON || (BABYLON = {}));
  2705. //# sourceMappingURL=babylon.smartPropertyPrim.js.map
  2706. var __extends = (this && this.__extends) || function (d, b) {
  2707. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  2708. function __() { this.constructor = d; }
  2709. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2710. };
  2711. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2712. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  2713. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  2714. 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;
  2715. return c > 3 && r && Object.defineProperty(target, key, r), r;
  2716. };
  2717. var BABYLON;
  2718. (function (BABYLON) {
  2719. var PrepareRender2DContext = (function () {
  2720. function PrepareRender2DContext() {
  2721. this.forceRefreshPrimitive = false;
  2722. }
  2723. return PrepareRender2DContext;
  2724. }());
  2725. BABYLON.PrepareRender2DContext = PrepareRender2DContext;
  2726. var Render2DContext = (function () {
  2727. function Render2DContext(renderMode) {
  2728. this._renderMode = renderMode;
  2729. this.useInstancing = false;
  2730. this.groupInfoPartData = null;
  2731. this.partDataStartIndex = this.partDataEndIndex = null;
  2732. this.instancedBuffers = null;
  2733. }
  2734. Object.defineProperty(Render2DContext.prototype, "renderMode", {
  2735. /**
  2736. * Define which render Mode should be used to render the primitive: one of Render2DContext.RenderModeXxxx property
  2737. */
  2738. get: function () {
  2739. return this._renderMode;
  2740. },
  2741. enumerable: true,
  2742. configurable: true
  2743. });
  2744. Object.defineProperty(Render2DContext, "RenderModeOpaque", {
  2745. /**
  2746. * The set of primitives to render is opaque.
  2747. * This is the first rendering pass. All Opaque primitives are rendered. Depth Compare and Write are both enabled.
  2748. */
  2749. get: function () {
  2750. return Render2DContext._renderModeOpaque;
  2751. },
  2752. enumerable: true,
  2753. configurable: true
  2754. });
  2755. Object.defineProperty(Render2DContext, "RenderModeAlphaTest", {
  2756. /**
  2757. * The set of primitives to render is using Alpha Test (aka masking).
  2758. * 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.
  2759. */
  2760. get: function () {
  2761. return Render2DContext._renderModeAlphaTest;
  2762. },
  2763. enumerable: true,
  2764. configurable: true
  2765. });
  2766. Object.defineProperty(Render2DContext, "RenderModeTransparent", {
  2767. /**
  2768. * The set of primitives to render is transparent.
  2769. * 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.
  2770. */
  2771. get: function () {
  2772. return Render2DContext._renderModeTransparent;
  2773. },
  2774. enumerable: true,
  2775. configurable: true
  2776. });
  2777. Render2DContext._renderModeOpaque = 1;
  2778. Render2DContext._renderModeAlphaTest = 2;
  2779. Render2DContext._renderModeTransparent = 3;
  2780. return Render2DContext;
  2781. }());
  2782. BABYLON.Render2DContext = Render2DContext;
  2783. /**
  2784. * This class store information for the pointerEventObservable Observable.
  2785. * 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.
  2786. */
  2787. var PrimitivePointerInfo = (function () {
  2788. function PrimitivePointerInfo() {
  2789. this.primitivePointerPos = BABYLON.Vector2.Zero();
  2790. this.tilt = BABYLON.Vector2.Zero();
  2791. this.cancelBubble = false;
  2792. }
  2793. Object.defineProperty(PrimitivePointerInfo, "PointerOver", {
  2794. // 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.
  2795. /**
  2796. * This event type is raised when a pointing device is moved into the hit test boundaries of a primitive.
  2797. * Bubbles: yes
  2798. */
  2799. get: function () {
  2800. return PrimitivePointerInfo._pointerOver;
  2801. },
  2802. enumerable: true,
  2803. configurable: true
  2804. });
  2805. Object.defineProperty(PrimitivePointerInfo, "PointerEnter", {
  2806. /**
  2807. * This event type is raised when a pointing device is moved into the hit test boundaries of a primitive or one of its descendants.
  2808. * Bubbles: no
  2809. */
  2810. get: function () {
  2811. return PrimitivePointerInfo._pointerEnter;
  2812. },
  2813. enumerable: true,
  2814. configurable: true
  2815. });
  2816. Object.defineProperty(PrimitivePointerInfo, "PointerDown", {
  2817. /**
  2818. * 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.
  2819. * Bubbles: yes
  2820. */
  2821. get: function () {
  2822. return PrimitivePointerInfo._pointerDown;
  2823. },
  2824. enumerable: true,
  2825. configurable: true
  2826. });
  2827. Object.defineProperty(PrimitivePointerInfo, "PointerMouseWheel", {
  2828. /**
  2829. * This event type is raised when the pointer is a mouse and it's wheel is rolling
  2830. * Bubbles: yes
  2831. */
  2832. get: function () {
  2833. return PrimitivePointerInfo._pointerMouseWheel;
  2834. },
  2835. enumerable: true,
  2836. configurable: true
  2837. });
  2838. Object.defineProperty(PrimitivePointerInfo, "PointerMove", {
  2839. /**
  2840. * 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.
  2841. * Bubbles: yes
  2842. */
  2843. get: function () {
  2844. return PrimitivePointerInfo._pointerMove;
  2845. },
  2846. enumerable: true,
  2847. configurable: true
  2848. });
  2849. Object.defineProperty(PrimitivePointerInfo, "PointerUp", {
  2850. /**
  2851. * 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.
  2852. * Bubbles: yes
  2853. */
  2854. get: function () {
  2855. return PrimitivePointerInfo._pointerUp;
  2856. },
  2857. enumerable: true,
  2858. configurable: true
  2859. });
  2860. Object.defineProperty(PrimitivePointerInfo, "PointerOut", {
  2861. /**
  2862. * This event type is raised when a pointing device is moved out of the hit test the boundaries of a primitive.
  2863. * Bubbles: yes
  2864. */
  2865. get: function () {
  2866. return PrimitivePointerInfo._pointerOut;
  2867. },
  2868. enumerable: true,
  2869. configurable: true
  2870. });
  2871. Object.defineProperty(PrimitivePointerInfo, "PointerLeave", {
  2872. /**
  2873. * This event type is raised when a pointing device is moved out of the hit test boundaries of a primitive and all its descendants.
  2874. * Bubbles: no
  2875. */
  2876. get: function () {
  2877. return PrimitivePointerInfo._pointerLeave;
  2878. },
  2879. enumerable: true,
  2880. configurable: true
  2881. });
  2882. Object.defineProperty(PrimitivePointerInfo, "PointerGotCapture", {
  2883. /**
  2884. * 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.
  2885. * Bubbles: yes
  2886. */
  2887. get: function () {
  2888. return PrimitivePointerInfo._pointerGotCapture;
  2889. },
  2890. enumerable: true,
  2891. configurable: true
  2892. });
  2893. Object.defineProperty(PrimitivePointerInfo, "PointerLostCapture", {
  2894. /**
  2895. * This event type is raised after pointer capture is released for a pointer.
  2896. * Bubbles: yes
  2897. */
  2898. get: function () {
  2899. return PrimitivePointerInfo._pointerLostCapture;
  2900. },
  2901. enumerable: true,
  2902. configurable: true
  2903. });
  2904. Object.defineProperty(PrimitivePointerInfo, "MouseWheelPrecision", {
  2905. get: function () {
  2906. return PrimitivePointerInfo._mouseWheelPrecision;
  2907. },
  2908. enumerable: true,
  2909. configurable: true
  2910. });
  2911. PrimitivePointerInfo.prototype.updateRelatedTarget = function (prim, primPointerPos) {
  2912. this.relatedTarget = prim;
  2913. this.relatedTargetPointerPos = primPointerPos;
  2914. };
  2915. PrimitivePointerInfo.getEventTypeName = function (mask) {
  2916. switch (mask) {
  2917. case PrimitivePointerInfo.PointerOver: return "PointerOver";
  2918. case PrimitivePointerInfo.PointerEnter: return "PointerEnter";
  2919. case PrimitivePointerInfo.PointerDown: return "PointerDown";
  2920. case PrimitivePointerInfo.PointerMouseWheel: return "PointerMouseWheel";
  2921. case PrimitivePointerInfo.PointerMove: return "PointerMove";
  2922. case PrimitivePointerInfo.PointerUp: return "PointerUp";
  2923. case PrimitivePointerInfo.PointerOut: return "PointerOut";
  2924. case PrimitivePointerInfo.PointerLeave: return "PointerLeave";
  2925. case PrimitivePointerInfo.PointerGotCapture: return "PointerGotCapture";
  2926. case PrimitivePointerInfo.PointerLostCapture: return "PointerLostCapture";
  2927. }
  2928. };
  2929. PrimitivePointerInfo._pointerOver = 0x0001;
  2930. PrimitivePointerInfo._pointerEnter = 0x0002;
  2931. PrimitivePointerInfo._pointerDown = 0x0004;
  2932. PrimitivePointerInfo._pointerMouseWheel = 0x0008;
  2933. PrimitivePointerInfo._pointerMove = 0x0010;
  2934. PrimitivePointerInfo._pointerUp = 0x0020;
  2935. PrimitivePointerInfo._pointerOut = 0x0040;
  2936. PrimitivePointerInfo._pointerLeave = 0x0080;
  2937. PrimitivePointerInfo._pointerGotCapture = 0x0100;
  2938. PrimitivePointerInfo._pointerLostCapture = 0x0200;
  2939. PrimitivePointerInfo._mouseWheelPrecision = 3.0;
  2940. return PrimitivePointerInfo;
  2941. }());
  2942. BABYLON.PrimitivePointerInfo = PrimitivePointerInfo;
  2943. /**
  2944. * Defines the horizontal and vertical alignment information for a Primitive.
  2945. */
  2946. var PrimitiveAlignment = (function () {
  2947. function PrimitiveAlignment(changeCallback) {
  2948. this._changedCallback = changeCallback;
  2949. this._horizontal = PrimitiveAlignment.AlignLeft;
  2950. this._vertical = PrimitiveAlignment.AlignBottom;
  2951. }
  2952. Object.defineProperty(PrimitiveAlignment, "AlignLeft", {
  2953. /**
  2954. * Alignment is made relative to the left edge of the Primitive. Valid for horizontal alignment only.
  2955. */
  2956. get: function () { return PrimitiveAlignment._AlignLeft; },
  2957. enumerable: true,
  2958. configurable: true
  2959. });
  2960. Object.defineProperty(PrimitiveAlignment, "AlignTop", {
  2961. /**
  2962. * Alignment is made relative to the top edge of the Primitive. Valid for vertical alignment only.
  2963. */
  2964. get: function () { return PrimitiveAlignment._AlignTop; },
  2965. enumerable: true,
  2966. configurable: true
  2967. });
  2968. Object.defineProperty(PrimitiveAlignment, "AlignRight", {
  2969. /**
  2970. * Alignment is made relative to the right edge of the Primitive. Valid for horizontal alignment only.
  2971. */
  2972. get: function () { return PrimitiveAlignment._AlignRight; },
  2973. enumerable: true,
  2974. configurable: true
  2975. });
  2976. Object.defineProperty(PrimitiveAlignment, "AlignBottom", {
  2977. /**
  2978. * Alignment is made relative to the bottom edge of the Primitive. Valid for vertical alignment only.
  2979. */
  2980. get: function () { return PrimitiveAlignment._AlignBottom; },
  2981. enumerable: true,
  2982. configurable: true
  2983. });
  2984. Object.defineProperty(PrimitiveAlignment, "AlignCenter", {
  2985. /**
  2986. * Alignment is made to center the content from equal distance to the opposite edges of the Primitive
  2987. */
  2988. get: function () { return PrimitiveAlignment._AlignCenter; },
  2989. enumerable: true,
  2990. configurable: true
  2991. });
  2992. Object.defineProperty(PrimitiveAlignment, "AlignStretch", {
  2993. /**
  2994. * The content is stretched toward the opposite edges of the Primitive
  2995. */
  2996. get: function () { return PrimitiveAlignment._AlignStretch; },
  2997. enumerable: true,
  2998. configurable: true
  2999. });
  3000. Object.defineProperty(PrimitiveAlignment.prototype, "horizontal", {
  3001. /**
  3002. * Get/set the horizontal alignment. Use one of the AlignXXX static properties of this class
  3003. */
  3004. get: function () {
  3005. return this._horizontal;
  3006. },
  3007. set: function (value) {
  3008. if (this._horizontal === value) {
  3009. return;
  3010. }
  3011. this._horizontal = value;
  3012. this.onChangeCallback();
  3013. },
  3014. enumerable: true,
  3015. configurable: true
  3016. });
  3017. Object.defineProperty(PrimitiveAlignment.prototype, "vertical", {
  3018. /**
  3019. * Get/set the vertical alignment. Use one of the AlignXXX static properties of this class
  3020. */
  3021. get: function () {
  3022. return this._vertical;
  3023. },
  3024. set: function (value) {
  3025. if (this._vertical === value) {
  3026. return;
  3027. }
  3028. this._vertical = value;
  3029. this.onChangeCallback();
  3030. },
  3031. enumerable: true,
  3032. configurable: true
  3033. });
  3034. PrimitiveAlignment.prototype.onChangeCallback = function () {
  3035. if (this._changedCallback) {
  3036. this._changedCallback();
  3037. }
  3038. };
  3039. /**
  3040. * Set the horizontal alignment from a string value.
  3041. * @param text can be either: 'left','right','center','stretch'
  3042. */
  3043. PrimitiveAlignment.prototype.setHorizontal = function (text) {
  3044. var v = text.trim().toLocaleLowerCase();
  3045. switch (v) {
  3046. case "left":
  3047. this.horizontal = PrimitiveAlignment.AlignLeft;
  3048. return;
  3049. case "right":
  3050. this.horizontal = PrimitiveAlignment.AlignRight;
  3051. return;
  3052. case "center":
  3053. this.horizontal = PrimitiveAlignment.AlignCenter;
  3054. return;
  3055. case "stretch":
  3056. this.horizontal = PrimitiveAlignment.AlignStretch;
  3057. return;
  3058. }
  3059. };
  3060. /**
  3061. * Set the vertical alignment from a string value.
  3062. * @param text can be either: 'top','bottom','center','stretch'
  3063. */
  3064. PrimitiveAlignment.prototype.setVertical = function (text) {
  3065. var v = text.trim().toLocaleLowerCase();
  3066. switch (v) {
  3067. case "top":
  3068. this.vertical = PrimitiveAlignment.AlignTop;
  3069. return;
  3070. case "bottom":
  3071. this.vertical = PrimitiveAlignment.AlignBottom;
  3072. return;
  3073. case "center":
  3074. this.vertical = PrimitiveAlignment.AlignCenter;
  3075. return;
  3076. case "stretch":
  3077. this.vertical = PrimitiveAlignment.AlignStretch;
  3078. return;
  3079. }
  3080. };
  3081. /**
  3082. * Set the horizontal and or vertical alignments from a string value.
  3083. * @param text can be: [<h:|horizontal:><left|right|center|stretch>], [<v:|vertical:><top|bottom|center|stretch>]
  3084. */
  3085. PrimitiveAlignment.prototype.fromString = function (value) {
  3086. var m = value.trim().split(",");
  3087. if (m.length === 1) {
  3088. this.setHorizontal(m[0]);
  3089. this.setVertical(m[0]);
  3090. }
  3091. else {
  3092. for (var _i = 0, m_1 = m; _i < m_1.length; _i++) {
  3093. var v = m_1[_i];
  3094. v = v.toLocaleLowerCase().trim();
  3095. // Horizontal
  3096. var i = v.indexOf("h:");
  3097. if (i === -1) {
  3098. i = v.indexOf("horizontal:");
  3099. }
  3100. if (i !== -1) {
  3101. v = v.substr(v.indexOf(":") + 1);
  3102. this.setHorizontal(v);
  3103. continue;
  3104. }
  3105. // Vertical
  3106. i = v.indexOf("v:");
  3107. if (i === -1) {
  3108. i = v.indexOf("vertical:");
  3109. }
  3110. if (i !== -1) {
  3111. v = v.substr(v.indexOf(":") + 1);
  3112. this.setVertical(v);
  3113. continue;
  3114. }
  3115. }
  3116. }
  3117. };
  3118. PrimitiveAlignment.prototype.copyFrom = function (pa) {
  3119. this._horizontal = pa._horizontal;
  3120. this._vertical = pa._vertical;
  3121. this.onChangeCallback();
  3122. };
  3123. Object.defineProperty(PrimitiveAlignment.prototype, "isDefault", {
  3124. get: function () {
  3125. return this.horizontal === PrimitiveAlignment.AlignLeft && this.vertical === PrimitiveAlignment.AlignBottom;
  3126. },
  3127. enumerable: true,
  3128. configurable: true
  3129. });
  3130. PrimitiveAlignment._AlignLeft = 1;
  3131. PrimitiveAlignment._AlignTop = 1; // Same as left
  3132. PrimitiveAlignment._AlignRight = 2;
  3133. PrimitiveAlignment._AlignBottom = 2; // Same as right
  3134. PrimitiveAlignment._AlignCenter = 3;
  3135. PrimitiveAlignment._AlignStretch = 4;
  3136. PrimitiveAlignment = __decorate([
  3137. BABYLON.className("PrimitiveAlignment", "BABYLON")
  3138. ], PrimitiveAlignment);
  3139. return PrimitiveAlignment;
  3140. }());
  3141. BABYLON.PrimitiveAlignment = PrimitiveAlignment;
  3142. /**
  3143. * Stores information about a Primitive that was intersected
  3144. */
  3145. var PrimitiveIntersectedInfo = (function () {
  3146. function PrimitiveIntersectedInfo(prim, intersectionLocation) {
  3147. this.prim = prim;
  3148. this.intersectionLocation = intersectionLocation;
  3149. }
  3150. return PrimitiveIntersectedInfo;
  3151. }());
  3152. BABYLON.PrimitiveIntersectedInfo = PrimitiveIntersectedInfo;
  3153. /**
  3154. * Define a thickness toward every edges of a Primitive to allow margin and padding.
  3155. * The thickness can be expressed as pixels, percentages, inherit the value of the parent primitive or be auto.
  3156. */
  3157. var PrimitiveThickness = (function () {
  3158. function PrimitiveThickness(parentAccess, changedCallback) {
  3159. this._parentAccess = parentAccess;
  3160. this._changedCallback = changedCallback;
  3161. this._pixels = new Array(4);
  3162. this._percentages = new Array(4);
  3163. this._setType(0, PrimitiveThickness.Auto);
  3164. this._setType(1, PrimitiveThickness.Auto);
  3165. this._setType(2, PrimitiveThickness.Auto);
  3166. this._setType(3, PrimitiveThickness.Auto);
  3167. this._pixels[0] = 0;
  3168. this._pixels[1] = 0;
  3169. this._pixels[2] = 0;
  3170. this._pixels[3] = 0;
  3171. }
  3172. /**
  3173. * Set the thickness from a string value
  3174. * @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.
  3175. * Values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  3176. */
  3177. PrimitiveThickness.prototype.fromString = function (thickness) {
  3178. this._clear();
  3179. var m = thickness.trim().split(",");
  3180. // Special case, one value to apply to all edges
  3181. if (m.length === 1 && thickness.indexOf(":") === -1) {
  3182. this._setStringValue(m[0], 0, false);
  3183. this._setStringValue(m[0], 1, false);
  3184. this._setStringValue(m[0], 2, false);
  3185. this._setStringValue(m[0], 3, false);
  3186. this.onChangeCallback();
  3187. return;
  3188. }
  3189. var res = false;
  3190. for (var _i = 0, m_2 = m; _i < m_2.length; _i++) {
  3191. var cm = m_2[_i];
  3192. res = this._extractString(cm, false) || res;
  3193. }
  3194. if (!res) {
  3195. throw new Error("Can't parse the string to create a PrimitiveMargin object, format must be: 'top: <value>, left:<value>, right:<value>, bottom:<value>");
  3196. }
  3197. // Check the margin that weren't set and set them in auto
  3198. if ((this._flags & 0x000F) === 0)
  3199. this._flags |= PrimitiveThickness.Pixel << 0;
  3200. if ((this._flags & 0x00F0) === 0)
  3201. this._flags |= PrimitiveThickness.Pixel << 4;
  3202. if ((this._flags & 0x0F00) === 0)
  3203. this._flags |= PrimitiveThickness.Pixel << 8;
  3204. if ((this._flags & 0xF000) === 0)
  3205. this._flags |= PrimitiveThickness.Pixel << 12;
  3206. this.onChangeCallback();
  3207. };
  3208. /**
  3209. * Set the thickness from multiple string
  3210. * Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  3211. * @param top the top thickness to set
  3212. * @param left the left thickness to set
  3213. * @param right the right thickness to set
  3214. * @param bottom the bottom thickness to set
  3215. */
  3216. PrimitiveThickness.prototype.fromStrings = function (top, left, right, bottom) {
  3217. this._clear();
  3218. this._setStringValue(top, 0, false);
  3219. this._setStringValue(left, 1, false);
  3220. this._setStringValue(right, 2, false);
  3221. this._setStringValue(bottom, 3, false);
  3222. this.onChangeCallback();
  3223. return this;
  3224. };
  3225. /**
  3226. * Set the thickness from pixel values
  3227. * @param top the top thickness in pixels to set
  3228. * @param left the left thickness in pixels to set
  3229. * @param right the right thickness in pixels to set
  3230. * @param bottom the bottom thickness in pixels to set
  3231. */
  3232. PrimitiveThickness.prototype.fromPixels = function (top, left, right, bottom) {
  3233. this._clear();
  3234. this._pixels[0] = top;
  3235. this._pixels[1] = left;
  3236. this._pixels[2] = right;
  3237. this._pixels[3] = bottom;
  3238. this.onChangeCallback();
  3239. return this;
  3240. };
  3241. /**
  3242. * Apply the same pixel value to all edges
  3243. * @param margin the value to set, in pixels.
  3244. */
  3245. PrimitiveThickness.prototype.fromUniformPixels = function (margin) {
  3246. this._clear();
  3247. this._pixels[0] = margin;
  3248. this._pixels[1] = margin;
  3249. this._pixels[2] = margin;
  3250. this._pixels[3] = margin;
  3251. this.onChangeCallback();
  3252. return this;
  3253. };
  3254. PrimitiveThickness.prototype.copyFrom = function (pt) {
  3255. this._clear();
  3256. for (var i = 0; i < 4; i++) {
  3257. this._pixels[i] = pt._pixels[i];
  3258. this._percentages[i] = pt._percentages[i];
  3259. }
  3260. this._flags = pt._flags;
  3261. this.onChangeCallback();
  3262. };
  3263. /**
  3264. * Set all edges in auto
  3265. */
  3266. PrimitiveThickness.prototype.auto = function () {
  3267. this._clear();
  3268. this._flags = (PrimitiveThickness.Auto << 0) | (PrimitiveThickness.Auto << 4) | (PrimitiveThickness.Auto << 8) | (PrimitiveThickness.Auto << 12);
  3269. this._pixels[0] = 0;
  3270. this._pixels[1] = 0;
  3271. this._pixels[2] = 0;
  3272. this._pixels[3] = 0;
  3273. this.onChangeCallback();
  3274. return this;
  3275. };
  3276. PrimitiveThickness.prototype._clear = function () {
  3277. this._flags = 0;
  3278. this._pixels[0] = 0;
  3279. this._pixels[1] = 0;
  3280. this._pixels[2] = 0;
  3281. this._pixels[3] = 0;
  3282. this._percentages[0] = null;
  3283. this._percentages[1] = null;
  3284. this._percentages[2] = null;
  3285. this._percentages[3] = null;
  3286. };
  3287. PrimitiveThickness.prototype._extractString = function (value, emitChanged) {
  3288. var v = value.trim().toLocaleLowerCase();
  3289. if (v.indexOf("top:") === 0) {
  3290. v = v.substr(4).trim();
  3291. return this._setStringValue(v, 0, emitChanged);
  3292. }
  3293. if (v.indexOf("left:") === 0) {
  3294. v = v.substr(5).trim();
  3295. return this._setStringValue(v, 1, emitChanged);
  3296. }
  3297. if (v.indexOf("right:") === 0) {
  3298. v = v.substr(6).trim();
  3299. return this._setStringValue(v, 2, emitChanged);
  3300. }
  3301. if (v.indexOf("bottom:") === 0) {
  3302. v = v.substr(7).trim();
  3303. return this._setStringValue(v, 3, emitChanged);
  3304. }
  3305. return false;
  3306. };
  3307. PrimitiveThickness.prototype._setStringValue = function (value, index, emitChanged) {
  3308. // Check for auto
  3309. var v = value.trim().toLocaleLowerCase();
  3310. if (v === "auto") {
  3311. if (this._isType(index, PrimitiveThickness.Auto)) {
  3312. return true;
  3313. }
  3314. this._setType(index, PrimitiveThickness.Auto);
  3315. this._pixels[index] = 0;
  3316. if (emitChanged) {
  3317. this.onChangeCallback();
  3318. }
  3319. }
  3320. else if (v === "inherit") {
  3321. if (this._isType(index, PrimitiveThickness.Inherit)) {
  3322. return true;
  3323. }
  3324. this._setType(index, PrimitiveThickness.Inherit);
  3325. this._pixels[index] = null;
  3326. if (emitChanged) {
  3327. this.onChangeCallback();
  3328. }
  3329. }
  3330. else {
  3331. var pI = v.indexOf("%");
  3332. // Check for percentage
  3333. if (pI !== -1) {
  3334. var n_1 = v.substr(0, pI);
  3335. var number_1 = Math.round(Number(n_1)) / 100; // Normalize the percentage to [0;1] with a 0.01 precision
  3336. if (this._isType(index, PrimitiveThickness.Percentage) && (this._percentages[index] === number_1)) {
  3337. return true;
  3338. }
  3339. this._setType(index, PrimitiveThickness.Percentage);
  3340. if (isNaN(number_1)) {
  3341. return false;
  3342. }
  3343. this._percentages[index] = number_1;
  3344. if (emitChanged) {
  3345. this.onChangeCallback();
  3346. }
  3347. return true;
  3348. }
  3349. // Check for pixel
  3350. var n = void 0;
  3351. pI = v.indexOf("px");
  3352. if (pI !== -1) {
  3353. n = v.substr(0, pI).trim();
  3354. }
  3355. else {
  3356. n = v;
  3357. }
  3358. var number = Number(n);
  3359. if (this._isType(index, PrimitiveThickness.Pixel) && (this._pixels[index] === number)) {
  3360. return true;
  3361. }
  3362. if (isNaN(number)) {
  3363. return false;
  3364. }
  3365. this._pixels[index] = number;
  3366. this._setType(index, PrimitiveThickness.Pixel);
  3367. if (emitChanged) {
  3368. this.onChangeCallback();
  3369. }
  3370. return true;
  3371. }
  3372. };
  3373. PrimitiveThickness.prototype._setPixels = function (value, index, emitChanged) {
  3374. // 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
  3375. value = Math.round(value);
  3376. if (this._isType(index, PrimitiveThickness.Pixel) && this._pixels[index] === value) {
  3377. return;
  3378. }
  3379. this._setType(index, PrimitiveThickness.Pixel);
  3380. this._pixels[index] = value;
  3381. if (emitChanged) {
  3382. this.onChangeCallback();
  3383. }
  3384. };
  3385. PrimitiveThickness.prototype._setPercentage = function (value, index, emitChanged) {
  3386. // Clip Value to bounds
  3387. value = Math.min(1, value);
  3388. value = Math.max(0, value);
  3389. value = Math.round(value * 100) / 100; // 0.01 precision
  3390. if (this._isType(index, PrimitiveThickness.Percentage) && this._percentages[index] === value) {
  3391. return;
  3392. }
  3393. this._setType(index, PrimitiveThickness.Percentage);
  3394. this._percentages[index] = value;
  3395. if (emitChanged) {
  3396. this.onChangeCallback();
  3397. }
  3398. };
  3399. PrimitiveThickness.prototype._getStringValue = function (index) {
  3400. var f = (this._flags >> (index * 4)) & 0xF;
  3401. switch (f) {
  3402. case PrimitiveThickness.Auto:
  3403. return "auto";
  3404. case PrimitiveThickness.Pixel:
  3405. return this._pixels[index] + "px";
  3406. case PrimitiveThickness.Percentage:
  3407. return this._percentages[index] * 100 + "%";
  3408. case PrimitiveThickness.Inherit:
  3409. return "inherit";
  3410. }
  3411. return "";
  3412. };
  3413. PrimitiveThickness.prototype._isType = function (index, type) {
  3414. var f = (this._flags >> (index * 4)) & 0xF;
  3415. return f === type;
  3416. };
  3417. PrimitiveThickness.prototype._getType = function (index, processInherit) {
  3418. var t = (this._flags >> (index * 4)) & 0xF;
  3419. if (processInherit && (t === PrimitiveThickness.Inherit)) {
  3420. var p = this._parentAccess();
  3421. if (p) {
  3422. return p._getType(index, true);
  3423. }
  3424. return PrimitiveThickness.Auto;
  3425. }
  3426. return t;
  3427. };
  3428. PrimitiveThickness.prototype._setType = function (index, type) {
  3429. this._flags &= ~(0xF << (index * 4));
  3430. this._flags |= type << (index * 4);
  3431. };
  3432. PrimitiveThickness.prototype.setTop = function (value) {
  3433. if (typeof value === "string") {
  3434. this._setStringValue(value, 0, true);
  3435. }
  3436. else {
  3437. this.topPixels = value;
  3438. }
  3439. };
  3440. PrimitiveThickness.prototype.setLeft = function (value) {
  3441. if (typeof value === "string") {
  3442. this._setStringValue(value, 1, true);
  3443. }
  3444. else {
  3445. this.leftPixels = value;
  3446. }
  3447. };
  3448. PrimitiveThickness.prototype.setRight = function (value) {
  3449. if (typeof value === "string") {
  3450. this._setStringValue(value, 2, true);
  3451. }
  3452. else {
  3453. this.rightPixels = value;
  3454. }
  3455. };
  3456. PrimitiveThickness.prototype.setBottom = function (value) {
  3457. if (typeof value === "string") {
  3458. this._setStringValue(value, 3, true);
  3459. }
  3460. else {
  3461. this.bottomPixels = value;
  3462. }
  3463. };
  3464. Object.defineProperty(PrimitiveThickness.prototype, "top", {
  3465. /**
  3466. * Get/set the top thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  3467. */
  3468. get: function () {
  3469. return this._getStringValue(0);
  3470. },
  3471. set: function (value) {
  3472. this._setStringValue(value, 0, true);
  3473. },
  3474. enumerable: true,
  3475. configurable: true
  3476. });
  3477. Object.defineProperty(PrimitiveThickness.prototype, "left", {
  3478. /**
  3479. * Get/set the left thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  3480. */
  3481. get: function () {
  3482. return this._getStringValue(1);
  3483. },
  3484. set: function (value) {
  3485. this._setStringValue(value, 1, true);
  3486. },
  3487. enumerable: true,
  3488. configurable: true
  3489. });
  3490. Object.defineProperty(PrimitiveThickness.prototype, "right", {
  3491. /**
  3492. * Get/set the right thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  3493. */
  3494. get: function () {
  3495. return this._getStringValue(2);
  3496. },
  3497. set: function (value) {
  3498. this._setStringValue(value, 2, true);
  3499. },
  3500. enumerable: true,
  3501. configurable: true
  3502. });
  3503. Object.defineProperty(PrimitiveThickness.prototype, "bottom", {
  3504. /**
  3505. * Get/set the bottom thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  3506. */
  3507. get: function () {
  3508. return this._getStringValue(3);
  3509. },
  3510. set: function (value) {
  3511. this._setStringValue(value, 3, true);
  3512. },
  3513. enumerable: true,
  3514. configurable: true
  3515. });
  3516. Object.defineProperty(PrimitiveThickness.prototype, "topPixels", {
  3517. /**
  3518. * Get/set the top thickness in pixel.
  3519. */
  3520. get: function () {
  3521. return this._pixels[0];
  3522. },
  3523. set: function (value) {
  3524. this._setPixels(value, 0, true);
  3525. },
  3526. enumerable: true,
  3527. configurable: true
  3528. });
  3529. Object.defineProperty(PrimitiveThickness.prototype, "leftPixels", {
  3530. /**
  3531. * Get/set the left thickness in pixel.
  3532. */
  3533. get: function () {
  3534. return this._pixels[1];
  3535. },
  3536. set: function (value) {
  3537. this._setPixels(value, 1, true);
  3538. },
  3539. enumerable: true,
  3540. configurable: true
  3541. });
  3542. Object.defineProperty(PrimitiveThickness.prototype, "rightPixels", {
  3543. /**
  3544. * Get/set the right thickness in pixel.
  3545. */
  3546. get: function () {
  3547. return this._pixels[2];
  3548. },
  3549. set: function (value) {
  3550. this._setPixels(value, 2, true);
  3551. },
  3552. enumerable: true,
  3553. configurable: true
  3554. });
  3555. Object.defineProperty(PrimitiveThickness.prototype, "bottomPixels", {
  3556. /**
  3557. * Get/set the bottom thickness in pixel.
  3558. */
  3559. get: function () {
  3560. return this._pixels[3];
  3561. },
  3562. set: function (value) {
  3563. this._setPixels(value, 3, true);
  3564. },
  3565. enumerable: true,
  3566. configurable: true
  3567. });
  3568. Object.defineProperty(PrimitiveThickness.prototype, "topPercentage", {
  3569. /**
  3570. * Get/set the top thickness in percentage.
  3571. * The get will return a valid value only if the edge type is percentage.
  3572. * The Set will change the edge mode if needed
  3573. */
  3574. get: function () {
  3575. return this._percentages[0];
  3576. },
  3577. set: function (value) {
  3578. this._setPercentage(value, 0, true);
  3579. },
  3580. enumerable: true,
  3581. configurable: true
  3582. });
  3583. Object.defineProperty(PrimitiveThickness.prototype, "leftPercentage", {
  3584. /**
  3585. * Get/set the left thickness in percentage.
  3586. * The get will return a valid value only if the edge mode is percentage.
  3587. * The Set will change the edge mode if needed
  3588. */
  3589. get: function () {
  3590. return this._percentages[1];
  3591. },
  3592. set: function (value) {
  3593. this._setPercentage(value, 1, true);
  3594. },
  3595. enumerable: true,
  3596. configurable: true
  3597. });
  3598. Object.defineProperty(PrimitiveThickness.prototype, "rightPercentage", {
  3599. /**
  3600. * Get/set the right thickness in percentage.
  3601. * The get will return a valid value only if the edge mode is percentage.
  3602. * The Set will change the edge mode if needed
  3603. */
  3604. get: function () {
  3605. return this._percentages[2];
  3606. },
  3607. set: function (value) {
  3608. this._setPercentage(value, 2, true);
  3609. },
  3610. enumerable: true,
  3611. configurable: true
  3612. });
  3613. Object.defineProperty(PrimitiveThickness.prototype, "bottomPercentage", {
  3614. /**
  3615. * Get/set the bottom thickness in percentage.
  3616. * The get will return a valid value only if the edge mode is percentage.
  3617. * The Set will change the edge mode if needed
  3618. */
  3619. get: function () {
  3620. return this._percentages[3];
  3621. },
  3622. set: function (value) {
  3623. this._setPercentage(value, 3, true);
  3624. },
  3625. enumerable: true,
  3626. configurable: true
  3627. });
  3628. Object.defineProperty(PrimitiveThickness.prototype, "topMode", {
  3629. /**
  3630. * Get/set the top mode. The setter shouldn't be used, other setters with value should be preferred
  3631. */
  3632. get: function () {
  3633. return this._getType(0, false);
  3634. },
  3635. set: function (mode) {
  3636. this._setType(0, mode);
  3637. },
  3638. enumerable: true,
  3639. configurable: true
  3640. });
  3641. Object.defineProperty(PrimitiveThickness.prototype, "leftMode", {
  3642. /**
  3643. * Get/set the left mode. The setter shouldn't be used, other setters with value should be preferred
  3644. */
  3645. get: function () {
  3646. return this._getType(1, false);
  3647. },
  3648. set: function (mode) {
  3649. this._setType(1, mode);
  3650. },
  3651. enumerable: true,
  3652. configurable: true
  3653. });
  3654. Object.defineProperty(PrimitiveThickness.prototype, "rightMode", {
  3655. /**
  3656. * Get/set the right mode. The setter shouldn't be used, other setters with value should be preferred
  3657. */
  3658. get: function () {
  3659. return this._getType(2, false);
  3660. },
  3661. set: function (mode) {
  3662. this._setType(2, mode);
  3663. },
  3664. enumerable: true,
  3665. configurable: true
  3666. });
  3667. Object.defineProperty(PrimitiveThickness.prototype, "bottomMode", {
  3668. /**
  3669. * Get/set the bottom mode. The setter shouldn't be used, other setters with value should be preferred
  3670. */
  3671. get: function () {
  3672. return this._getType(3, false);
  3673. },
  3674. set: function (mode) {
  3675. this._setType(3, mode);
  3676. },
  3677. enumerable: true,
  3678. configurable: true
  3679. });
  3680. Object.defineProperty(PrimitiveThickness.prototype, "isDefault", {
  3681. get: function () {
  3682. return this._flags === 0x1111;
  3683. },
  3684. enumerable: true,
  3685. configurable: true
  3686. });
  3687. PrimitiveThickness.prototype._computePixels = function (index, sourceArea, emitChanged) {
  3688. var type = this._getType(index, false);
  3689. if (type === PrimitiveThickness.Inherit) {
  3690. this._parentAccess()._computePixels(index, sourceArea, emitChanged);
  3691. return;
  3692. }
  3693. if (type !== PrimitiveThickness.Percentage) {
  3694. return;
  3695. }
  3696. var pixels = ((index === 0 || index === 3) ? sourceArea.height : sourceArea.width) * this._percentages[index];
  3697. this._pixels[index] = pixels;
  3698. if (emitChanged) {
  3699. this.onChangeCallback();
  3700. }
  3701. };
  3702. PrimitiveThickness.prototype.onChangeCallback = function () {
  3703. if (this._changedCallback) {
  3704. this._changedCallback();
  3705. }
  3706. };
  3707. /**
  3708. * Compute the positioning/size of an area considering the thickness of this object and a given alignment
  3709. * @param sourceArea the source area where the content must be sized/positioned
  3710. * @param contentSize the content size to position/resize
  3711. * @param alignment the alignment setting
  3712. * @param dstOffset the position of the content, x, y, z, w are left, bottom, right, top
  3713. * @param dstArea the new size of the content
  3714. */
  3715. PrimitiveThickness.prototype.computeWithAlignment = function (sourceArea, contentSize, alignment, dstOffset, dstArea, computeLayoutArea) {
  3716. if (computeLayoutArea === void 0) { computeLayoutArea = false; }
  3717. // Fetch some data
  3718. var topType = this._getType(0, true);
  3719. var leftType = this._getType(1, true);
  3720. var rightType = this._getType(2, true);
  3721. var bottomType = this._getType(3, true);
  3722. var hasWidth = contentSize && (contentSize.width != null);
  3723. var hasHeight = contentSize && (contentSize.height != null);
  3724. var width = hasWidth ? contentSize.width : 0;
  3725. var height = hasHeight ? contentSize.height : 0;
  3726. var isTopAuto = topType === PrimitiveThickness.Auto;
  3727. var isLeftAuto = leftType === PrimitiveThickness.Auto;
  3728. var isRightAuto = rightType === PrimitiveThickness.Auto;
  3729. var isBottomAuto = bottomType === PrimitiveThickness.Auto;
  3730. switch (alignment.horizontal) {
  3731. case PrimitiveAlignment.AlignLeft:
  3732. {
  3733. if (isLeftAuto) {
  3734. dstOffset.x = 0;
  3735. }
  3736. else {
  3737. this._computePixels(1, sourceArea, true);
  3738. dstOffset.x = this.leftPixels;
  3739. }
  3740. dstArea.width = width;
  3741. if (computeLayoutArea) {
  3742. dstArea.width += this.leftPixels;
  3743. }
  3744. dstOffset.z = sourceArea.width - (dstOffset.x + width);
  3745. break;
  3746. }
  3747. case PrimitiveAlignment.AlignRight:
  3748. {
  3749. if (isRightAuto) {
  3750. dstOffset.x = Math.round(sourceArea.width - width);
  3751. }
  3752. else {
  3753. this._computePixels(2, sourceArea, true);
  3754. dstOffset.x = Math.round(sourceArea.width - (width + this.rightPixels));
  3755. }
  3756. dstArea.width = width;
  3757. if (computeLayoutArea) {
  3758. dstArea.width += this.rightPixels;
  3759. }
  3760. dstOffset.z = this.rightPixels;
  3761. break;
  3762. }
  3763. case PrimitiveAlignment.AlignStretch:
  3764. {
  3765. if (isLeftAuto) {
  3766. dstOffset.x = 0;
  3767. }
  3768. else {
  3769. this._computePixels(1, sourceArea, true);
  3770. dstOffset.x = this.leftPixels;
  3771. }
  3772. var right = 0;
  3773. if (!isRightAuto) {
  3774. this._computePixels(2, sourceArea, true);
  3775. right = this.rightPixels;
  3776. }
  3777. dstArea.width = sourceArea.width - (dstOffset.x + right);
  3778. dstOffset.z = this.rightPixels;
  3779. break;
  3780. }
  3781. case PrimitiveAlignment.AlignCenter:
  3782. {
  3783. if (!isLeftAuto) {
  3784. this._computePixels(1, sourceArea, true);
  3785. }
  3786. if (!isRightAuto) {
  3787. this._computePixels(2, sourceArea, true);
  3788. }
  3789. var offset = (isLeftAuto ? 0 : this.leftPixels) - (isRightAuto ? 0 : this.rightPixels);
  3790. dstOffset.x = Math.round(((sourceArea.width - width) / 2) + offset);
  3791. dstArea.width = width;
  3792. dstOffset.z = sourceArea.width - (dstOffset.x + width);
  3793. break;
  3794. }
  3795. }
  3796. switch (alignment.vertical) {
  3797. case PrimitiveAlignment.AlignTop:
  3798. {
  3799. if (isTopAuto) {
  3800. dstOffset.y = sourceArea.height - height;
  3801. }
  3802. else {
  3803. this._computePixels(0, sourceArea, true);
  3804. dstOffset.y = Math.round(sourceArea.height - (height + this.topPixels));
  3805. }
  3806. dstArea.height = height;
  3807. if (computeLayoutArea) {
  3808. dstArea.height += this.topPixels;
  3809. }
  3810. dstOffset.w = this.topPixels;
  3811. break;
  3812. }
  3813. case PrimitiveAlignment.AlignBottom:
  3814. {
  3815. if (isBottomAuto) {
  3816. dstOffset.y = 0;
  3817. }
  3818. else {
  3819. this._computePixels(3, sourceArea, true);
  3820. dstOffset.y = this.bottomPixels;
  3821. }
  3822. dstArea.height = height;
  3823. if (computeLayoutArea) {
  3824. dstArea.height += this.bottomPixels;
  3825. }
  3826. dstOffset.w = sourceArea.height - (dstOffset.y + height);
  3827. break;
  3828. }
  3829. case PrimitiveAlignment.AlignStretch:
  3830. {
  3831. if (isBottomAuto) {
  3832. dstOffset.y = 0;
  3833. }
  3834. else {
  3835. this._computePixels(3, sourceArea, true);
  3836. dstOffset.y = this.bottomPixels;
  3837. }
  3838. var top_1 = 0;
  3839. if (!isTopAuto) {
  3840. this._computePixels(0, sourceArea, true);
  3841. top_1 = this.topPixels;
  3842. }
  3843. dstArea.height = sourceArea.height - (dstOffset.y + top_1);
  3844. dstOffset.w = this.topPixels;
  3845. break;
  3846. }
  3847. case PrimitiveAlignment.AlignCenter:
  3848. {
  3849. if (!isTopAuto) {
  3850. this._computePixels(0, sourceArea, true);
  3851. }
  3852. if (!isBottomAuto) {
  3853. this._computePixels(3, sourceArea, true);
  3854. }
  3855. var offset = (isBottomAuto ? 0 : this.bottomPixels) - (isTopAuto ? 0 : this.topPixels);
  3856. dstOffset.y = Math.round(((sourceArea.height - height) / 2) + offset);
  3857. dstArea.height = height;
  3858. dstOffset.w = sourceArea.height - (dstOffset.y + height);
  3859. break;
  3860. }
  3861. }
  3862. };
  3863. /**
  3864. * Compute an area and its position considering this thickness properties based on a given source area
  3865. * @param sourceArea the source area
  3866. * @param dstOffset the position of the resulting area
  3867. * @param dstArea the size of the resulting area
  3868. */
  3869. PrimitiveThickness.prototype.compute = function (sourceArea, dstOffset, dstArea) {
  3870. this._computePixels(0, sourceArea, true);
  3871. this._computePixels(1, sourceArea, true);
  3872. this._computePixels(2, sourceArea, true);
  3873. this._computePixels(3, sourceArea, true);
  3874. dstOffset.x = this.leftPixels;
  3875. dstArea.width = sourceArea.width - (dstOffset.x + this.rightPixels);
  3876. dstOffset.y = this.bottomPixels;
  3877. dstArea.height = sourceArea.height - (dstOffset.y + this.topPixels);
  3878. dstOffset.z = this.rightPixels;
  3879. dstOffset.w = this.topPixels;
  3880. };
  3881. /**
  3882. * Compute an area considering this thickness properties based on a given source area
  3883. * @param sourceArea the source area
  3884. * @param result the resulting area
  3885. */
  3886. PrimitiveThickness.prototype.computeArea = function (sourceArea, result) {
  3887. this._computePixels(0, sourceArea, true);
  3888. this._computePixels(1, sourceArea, true);
  3889. this._computePixels(2, sourceArea, true);
  3890. this._computePixels(3, sourceArea, true);
  3891. result.width = this.leftPixels + sourceArea.width + this.rightPixels;
  3892. result.height = this.bottomPixels + sourceArea.height + this.topPixels;
  3893. };
  3894. PrimitiveThickness.prototype.enlarge = function (sourceArea, dstOffset, enlargedArea) {
  3895. this._computePixels(0, sourceArea, true);
  3896. this._computePixels(1, sourceArea, true);
  3897. this._computePixels(2, sourceArea, true);
  3898. this._computePixels(3, sourceArea, true);
  3899. dstOffset.x = this.leftPixels;
  3900. enlargedArea.width = sourceArea.width + (dstOffset.x + this.rightPixels);
  3901. dstOffset.y = this.bottomPixels;
  3902. enlargedArea.height = sourceArea.height + (dstOffset.y + this.topPixels);
  3903. dstOffset.z = this.rightPixels;
  3904. dstOffset.w = this.topPixels;
  3905. };
  3906. PrimitiveThickness.Auto = 0x1;
  3907. PrimitiveThickness.Inherit = 0x2;
  3908. PrimitiveThickness.Percentage = 0x4;
  3909. PrimitiveThickness.Pixel = 0x8;
  3910. PrimitiveThickness = __decorate([
  3911. BABYLON.className("PrimitiveThickness", "BABYLON")
  3912. ], PrimitiveThickness);
  3913. return PrimitiveThickness;
  3914. }());
  3915. BABYLON.PrimitiveThickness = PrimitiveThickness;
  3916. /**
  3917. * Main class used for the Primitive Intersection API
  3918. */
  3919. var IntersectInfo2D = (function () {
  3920. function IntersectInfo2D() {
  3921. this.findFirstOnly = false;
  3922. this.intersectHidden = false;
  3923. this.pickPosition = BABYLON.Vector2.Zero();
  3924. }
  3925. Object.defineProperty(IntersectInfo2D.prototype, "isIntersected", {
  3926. /**
  3927. * true if at least one primitive intersected during the test
  3928. */
  3929. get: function () {
  3930. return this.intersectedPrimitives && this.intersectedPrimitives.length > 0;
  3931. },
  3932. enumerable: true,
  3933. configurable: true
  3934. });
  3935. IntersectInfo2D.prototype.isPrimIntersected = function (prim) {
  3936. for (var _i = 0, _a = this.intersectedPrimitives; _i < _a.length; _i++) {
  3937. var cur = _a[_i];
  3938. if (cur.prim === prim) {
  3939. return cur.intersectionLocation;
  3940. }
  3941. }
  3942. return null;
  3943. };
  3944. // Internals, don't use
  3945. IntersectInfo2D.prototype._exit = function (firstLevel) {
  3946. if (firstLevel) {
  3947. this._globalPickPosition = null;
  3948. }
  3949. };
  3950. return IntersectInfo2D;
  3951. }());
  3952. BABYLON.IntersectInfo2D = IntersectInfo2D;
  3953. var Prim2DBase = (function (_super) {
  3954. __extends(Prim2DBase, _super);
  3955. function Prim2DBase(settings) {
  3956. // Avoid checking every time if the object exists
  3957. if (settings == null) {
  3958. settings = {};
  3959. }
  3960. // BASE CLASS CALL
  3961. _super.call(this);
  3962. // Fetch the owner, parent. There're many ways to do it and we can end up with nothing for both
  3963. var owner;
  3964. var parent;
  3965. if (Prim2DBase._isCanvasInit) {
  3966. owner = this;
  3967. parent = null;
  3968. this._canvasPreInit(settings);
  3969. }
  3970. else {
  3971. if (settings.parent != null) {
  3972. parent = settings.parent;
  3973. owner = settings.parent.owner;
  3974. if (!owner) {
  3975. throw new Error("Parent " + parent.id + " of " + settings.id + " doesn't have a valid owner!");
  3976. }
  3977. 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)) {
  3978. 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");
  3979. }
  3980. }
  3981. }
  3982. // Fields initialization
  3983. this._layoutEngine = BABYLON.CanvasLayoutEngine.Singleton;
  3984. this._size = null; //Size.Zero();
  3985. this._scale = new BABYLON.Vector2(1, 1);
  3986. this._actualSize = null;
  3987. this._boundingSize = BABYLON.Size.Zero();
  3988. this._layoutArea = BABYLON.Size.Zero();
  3989. this._layoutAreaPos = null;
  3990. this._layoutBoundingInfo = null;
  3991. this._marginOffset = BABYLON.Vector4.Zero();
  3992. this._paddingOffset = BABYLON.Vector4.Zero();
  3993. this._parentPaddingOffset = BABYLON.Vector2.Zero();
  3994. this._parentContentArea = BABYLON.Size.Zero();
  3995. this._lastAutoSizeArea = BABYLON.Size.Zero();
  3996. this._contentArea = new BABYLON.Size(null, null);
  3997. this._pointerEventObservable = new BABYLON.Observable();
  3998. this._boundingInfo = new BABYLON.BoundingInfo2D();
  3999. this._owner = owner;
  4000. this._parent = null;
  4001. this._margin = null;
  4002. this._padding = null;
  4003. this._marginAlignment = null;
  4004. this._id = settings.id;
  4005. this._children = new Array();
  4006. this._localTransform = new BABYLON.Matrix();
  4007. this._globalTransform = null;
  4008. this._invGlobalTransform = null;
  4009. this._globalTransformProcessStep = 0;
  4010. this._globalTransformStep = 0;
  4011. this._renderGroup = null;
  4012. this._primLinearPosition = 0;
  4013. this._manualZOrder = null;
  4014. this._zOrder = 0;
  4015. this._zMax = 0;
  4016. this._firstZDirtyIndex = Prim2DBase._bigInt;
  4017. this._actualOpacity = 0;
  4018. this._actualScale = BABYLON.Vector2.Zero();
  4019. this._displayDebugAreas = false;
  4020. this._debugAreaGroup = null;
  4021. var isPickable = true;
  4022. var isContainer = true;
  4023. if (settings.isPickable !== undefined) {
  4024. isPickable = settings.isPickable;
  4025. }
  4026. if (settings.isContainer !== undefined) {
  4027. isContainer = settings.isContainer;
  4028. }
  4029. if (settings.dontInheritParentScale) {
  4030. this._setFlags(BABYLON.SmartPropertyPrim.flagDontInheritParentScale);
  4031. }
  4032. this._setFlags((isPickable ? BABYLON.SmartPropertyPrim.flagIsPickable : 0) | BABYLON.SmartPropertyPrim.flagBoundingInfoDirty | BABYLON.SmartPropertyPrim.flagActualOpacityDirty | (isContainer ? BABYLON.SmartPropertyPrim.flagIsContainer : 0) | BABYLON.SmartPropertyPrim.flagActualScaleDirty | BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty);
  4033. if (settings.opacity != null) {
  4034. this._opacity = settings.opacity;
  4035. }
  4036. else {
  4037. this._opacity = 1;
  4038. }
  4039. this._updateRenderMode();
  4040. if (settings.childrenFlatZOrder) {
  4041. this._setFlags(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  4042. }
  4043. // If the parent is given, initialize the hierarchy/owner related data
  4044. if (parent != null) {
  4045. parent.addChild(this);
  4046. this._hierarchyDepth = parent._hierarchyDepth + 1;
  4047. this._patchHierarchy(parent.owner);
  4048. }
  4049. // If it's a group, detect its own states
  4050. if (this.owner && this instanceof BABYLON.Group2D) {
  4051. var group = this;
  4052. group.detectGroupStates();
  4053. }
  4054. // Time to insert children if some are specified
  4055. if (settings.children != null) {
  4056. for (var _i = 0, _a = settings.children; _i < _a.length; _i++) {
  4057. var child = _a[_i];
  4058. this.addChild(child);
  4059. // Good time to patch the hierarchy, it won't go very far if there's no need to
  4060. if (this.owner != null) {
  4061. child._patchHierarchy(this.owner);
  4062. }
  4063. }
  4064. }
  4065. if (settings.zOrder != null) {
  4066. this.zOrder = settings.zOrder;
  4067. }
  4068. // Set the model related properties
  4069. if (settings.position != null) {
  4070. this.position = settings.position;
  4071. }
  4072. else if (settings.x != null || settings.y != null) {
  4073. this.position = new BABYLON.Vector2(settings.x || 0, settings.y || 0);
  4074. }
  4075. else {
  4076. this._position = null;
  4077. }
  4078. this.rotation = (settings.rotation == null) ? 0 : settings.rotation;
  4079. if (settings.scale != null) {
  4080. this.scale = settings.scale;
  4081. }
  4082. else {
  4083. if (settings.scaleX != null) {
  4084. this.scaleX = settings.scaleX;
  4085. }
  4086. if (settings.scaleY != null) {
  4087. this.scaleY = settings.scaleY;
  4088. }
  4089. }
  4090. this.levelVisible = (settings.isVisible == null) ? true : settings.isVisible;
  4091. this.origin = settings.origin || new BABYLON.Vector2(0.5, 0.5);
  4092. // Layout Engine
  4093. if (settings.layoutEngine != null) {
  4094. if (typeof settings.layoutEngine === "string") {
  4095. var name_1 = settings.layoutEngine.toLocaleLowerCase().trim();
  4096. if (name_1 === "canvas" || name_1 === "canvaslayoutengine") {
  4097. this.layoutEngine = BABYLON.CanvasLayoutEngine.Singleton;
  4098. }
  4099. else if (name_1.indexOf("stackpanel") === 0 || name_1.indexOf("horizontalstackpanel") === 0) {
  4100. this.layoutEngine = BABYLON.StackPanelLayoutEngine.Horizontal;
  4101. }
  4102. else if (name_1.indexOf("verticalstackpanel") === 0) {
  4103. this.layoutEngine = BABYLON.StackPanelLayoutEngine.Vertical;
  4104. }
  4105. }
  4106. else if (settings.layoutEngine instanceof BABYLON.LayoutEngineBase) {
  4107. this.layoutEngine = settings.layoutEngine;
  4108. }
  4109. }
  4110. // Set the layout/margin stuffs
  4111. if (settings.marginTop) {
  4112. this.margin.setTop(settings.marginTop);
  4113. }
  4114. if (settings.marginLeft) {
  4115. this.margin.setLeft(settings.marginLeft);
  4116. }
  4117. if (settings.marginRight) {
  4118. this.margin.setRight(settings.marginRight);
  4119. }
  4120. if (settings.marginBottom) {
  4121. this.margin.setBottom(settings.marginBottom);
  4122. }
  4123. if (settings.margin) {
  4124. if (typeof settings.margin === "string") {
  4125. this.margin.fromString(settings.margin);
  4126. }
  4127. else {
  4128. this.margin.fromUniformPixels(settings.margin);
  4129. }
  4130. }
  4131. if (settings.marginHAlignment) {
  4132. this.marginAlignment.horizontal = settings.marginHAlignment;
  4133. }
  4134. if (settings.marginVAlignment) {
  4135. this.marginAlignment.vertical = settings.marginVAlignment;
  4136. }
  4137. if (settings.marginAlignment) {
  4138. this.marginAlignment.fromString(settings.marginAlignment);
  4139. }
  4140. if (settings.paddingTop) {
  4141. this.padding.setTop(settings.paddingTop);
  4142. }
  4143. if (settings.paddingLeft) {
  4144. this.padding.setLeft(settings.paddingLeft);
  4145. }
  4146. if (settings.paddingRight) {
  4147. this.padding.setRight(settings.paddingRight);
  4148. }
  4149. if (settings.paddingBottom) {
  4150. this.padding.setBottom(settings.paddingBottom);
  4151. }
  4152. if (settings.padding) {
  4153. this.padding.fromString(settings.padding);
  4154. }
  4155. // Dirty layout and positioning
  4156. this._parentLayoutDirty();
  4157. this._positioningDirty();
  4158. }
  4159. Object.defineProperty(Prim2DBase.prototype, "actionManager", {
  4160. get: function () {
  4161. if (!this._actionManager) {
  4162. this._actionManager = new BABYLON.ActionManager(this.owner.scene);
  4163. }
  4164. return this._actionManager;
  4165. },
  4166. enumerable: true,
  4167. configurable: true
  4168. });
  4169. /**
  4170. * From 'this' primitive, traverse up (from parent to parent) until the given predicate is true
  4171. * @param predicate the predicate to test on each parent
  4172. * @return the first primitive where the predicate was successful
  4173. */
  4174. Prim2DBase.prototype.traverseUp = function (predicate) {
  4175. var p = this;
  4176. while (p != null) {
  4177. if (predicate(p)) {
  4178. return p;
  4179. }
  4180. p = p._parent;
  4181. }
  4182. return null;
  4183. };
  4184. Object.defineProperty(Prim2DBase.prototype, "owner", {
  4185. /**
  4186. * Retrieve the owner Canvas2D
  4187. */
  4188. get: function () {
  4189. return this._owner;
  4190. },
  4191. enumerable: true,
  4192. configurable: true
  4193. });
  4194. Object.defineProperty(Prim2DBase.prototype, "parent", {
  4195. /**
  4196. * Get the parent primitive (can be the Canvas, only the Canvas has no parent)
  4197. */
  4198. get: function () {
  4199. return this._parent;
  4200. },
  4201. enumerable: true,
  4202. configurable: true
  4203. });
  4204. Object.defineProperty(Prim2DBase.prototype, "children", {
  4205. /**
  4206. * The array of direct children primitives
  4207. */
  4208. get: function () {
  4209. return this._children;
  4210. },
  4211. enumerable: true,
  4212. configurable: true
  4213. });
  4214. Object.defineProperty(Prim2DBase.prototype, "id", {
  4215. /**
  4216. * The identifier of this primitive, may not be unique, it's for information purpose only
  4217. */
  4218. get: function () {
  4219. return this._id;
  4220. },
  4221. set: function (value) {
  4222. if (this._id === value) {
  4223. return;
  4224. }
  4225. var oldValue = this._id;
  4226. this.onPropertyChanged("id", oldValue, this._id);
  4227. },
  4228. enumerable: true,
  4229. configurable: true
  4230. });
  4231. Object.defineProperty(Prim2DBase.prototype, "actualPosition", {
  4232. get: function () {
  4233. if (this._actualPosition != null) {
  4234. return this._actualPosition;
  4235. }
  4236. if (this._position != null) {
  4237. return this._position;
  4238. }
  4239. // At least return 0,0, we can't return null on actualPosition
  4240. return Prim2DBase._nullPosition;
  4241. },
  4242. /**
  4243. * DO NOT INVOKE for internal purpose only
  4244. */
  4245. set: function (val) {
  4246. this._actualPosition = val;
  4247. },
  4248. enumerable: true,
  4249. configurable: true
  4250. });
  4251. Object.defineProperty(Prim2DBase.prototype, "actualX", {
  4252. /**
  4253. * Shortcut to actualPosition.x
  4254. */
  4255. get: function () {
  4256. return this.actualPosition.x;
  4257. },
  4258. set: function (val) {
  4259. this._actualPosition.x = val;
  4260. this._triggerPropertyChanged(Prim2DBase.actualPositionProperty, this._actualPosition);
  4261. },
  4262. enumerable: true,
  4263. configurable: true
  4264. });
  4265. Object.defineProperty(Prim2DBase.prototype, "actualY", {
  4266. /**
  4267. * Shortcut to actualPosition.y
  4268. */
  4269. get: function () {
  4270. return this.actualPosition.y;
  4271. },
  4272. set: function (val) {
  4273. this._actualPosition.y = val;
  4274. this._triggerPropertyChanged(Prim2DBase.actualPositionProperty, this._actualPosition);
  4275. },
  4276. enumerable: true,
  4277. configurable: true
  4278. });
  4279. Object.defineProperty(Prim2DBase.prototype, "position", {
  4280. /**
  4281. * Position of the primitive, relative to its parent.
  4282. * BEWARE: if you change only position.x or y it won't trigger a property change and you won't have the expected behavior.
  4283. * Use this property to set a new Vector2 object, otherwise to change only the x/y use Prim2DBase.x or y properties.
  4284. * Setting this property may have no effect is specific alignment are in effect.
  4285. */
  4286. get: function () {
  4287. if (!this._position) {
  4288. this._position = BABYLON.Vector2.Zero();
  4289. }
  4290. return this._position;
  4291. },
  4292. set: function (value) {
  4293. if (!this._checkPositionChange()) {
  4294. return;
  4295. }
  4296. this._position = value;
  4297. this._triggerPropertyChanged(Prim2DBase.actualPositionProperty, value);
  4298. },
  4299. enumerable: true,
  4300. configurable: true
  4301. });
  4302. Object.defineProperty(Prim2DBase.prototype, "x", {
  4303. /**
  4304. * Direct access to the position.x value of the primitive
  4305. * Use this property when you only want to change one component of the position property
  4306. */
  4307. get: function () {
  4308. if (!this._position) {
  4309. return null;
  4310. }
  4311. return this._position.x;
  4312. },
  4313. set: function (value) {
  4314. if (!this._checkPositionChange()) {
  4315. return;
  4316. }
  4317. if (!this._position) {
  4318. this._position = BABYLON.Vector2.Zero();
  4319. }
  4320. if (this._position.x === value) {
  4321. return;
  4322. }
  4323. this._position.x = value;
  4324. this._triggerPropertyChanged(Prim2DBase.positionProperty, value);
  4325. this._triggerPropertyChanged(Prim2DBase.actualPositionProperty, value);
  4326. },
  4327. enumerable: true,
  4328. configurable: true
  4329. });
  4330. Object.defineProperty(Prim2DBase.prototype, "y", {
  4331. /**
  4332. * Direct access to the position.y value of the primitive
  4333. * Use this property when you only want to change one component of the position property
  4334. */
  4335. get: function () {
  4336. if (!this._position) {
  4337. return null;
  4338. }
  4339. return this._position.y;
  4340. },
  4341. set: function (value) {
  4342. if (!this._checkPositionChange()) {
  4343. return;
  4344. }
  4345. if (!this._position) {
  4346. this._position = BABYLON.Vector2.Zero();
  4347. }
  4348. if (this._position.y === value) {
  4349. return;
  4350. }
  4351. this._position.y = value;
  4352. this._triggerPropertyChanged(Prim2DBase.positionProperty, value);
  4353. this._triggerPropertyChanged(Prim2DBase.actualPositionProperty, value);
  4354. },
  4355. enumerable: true,
  4356. configurable: true
  4357. });
  4358. Object.defineProperty(Prim2DBase.prototype, "size", {
  4359. /**
  4360. * Size of the primitive or its bounding area
  4361. * BEWARE: if you change only size.width or height it won't trigger a property change and you won't have the expected behavior.
  4362. * Use this property to set a new Size object, otherwise to change only the width/height use Prim2DBase.width or height properties.
  4363. */
  4364. get: function () {
  4365. if (!this._size || this._size.width == null || this._size.height == null) {
  4366. if (Prim2DBase.boundinbBoxReentrency) {
  4367. return Prim2DBase.nullSize;
  4368. }
  4369. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagBoundingInfoDirty)) {
  4370. return this._boundingSize;
  4371. }
  4372. Prim2DBase.boundinbBoxReentrency = true;
  4373. var b = this.boundingInfo;
  4374. Prim2DBase.boundinbBoxReentrency = false;
  4375. return this._boundingSize;
  4376. }
  4377. return this._size;
  4378. },
  4379. set: function (value) {
  4380. this._size = value;
  4381. },
  4382. enumerable: true,
  4383. configurable: true
  4384. });
  4385. Object.defineProperty(Prim2DBase.prototype, "width", {
  4386. /**
  4387. * Direct access to the size.width value of the primitive
  4388. * Use this property when you only want to change one component of the size property
  4389. */
  4390. get: function () {
  4391. if (!this.size) {
  4392. return null;
  4393. }
  4394. return this.size.width;
  4395. },
  4396. set: function (value) {
  4397. if (this.size && this.size.width === value) {
  4398. return;
  4399. }
  4400. if (!this.size) {
  4401. this.size = new BABYLON.Size(value, 0);
  4402. }
  4403. else {
  4404. this.size.width = value;
  4405. }
  4406. this._triggerPropertyChanged(Prim2DBase.sizeProperty, value);
  4407. this._positioningDirty();
  4408. },
  4409. enumerable: true,
  4410. configurable: true
  4411. });
  4412. Object.defineProperty(Prim2DBase.prototype, "height", {
  4413. /**
  4414. * Direct access to the size.height value of the primitive
  4415. * Use this property when you only want to change one component of the size property
  4416. */
  4417. get: function () {
  4418. if (!this.size) {
  4419. return null;
  4420. }
  4421. return this.size.height;
  4422. },
  4423. set: function (value) {
  4424. if (this.size && this.size.height === value) {
  4425. return;
  4426. }
  4427. if (!this.size) {
  4428. this.size = new BABYLON.Size(0, value);
  4429. }
  4430. else {
  4431. this.size.height = value;
  4432. }
  4433. this._triggerPropertyChanged(Prim2DBase.sizeProperty, value);
  4434. this._positioningDirty();
  4435. },
  4436. enumerable: true,
  4437. configurable: true
  4438. });
  4439. Object.defineProperty(Prim2DBase.prototype, "rotation", {
  4440. get: function () {
  4441. return this._rotation;
  4442. },
  4443. set: function (value) {
  4444. this._rotation = value;
  4445. },
  4446. enumerable: true,
  4447. configurable: true
  4448. });
  4449. Object.defineProperty(Prim2DBase.prototype, "scale", {
  4450. get: function () {
  4451. return this._scale.x;
  4452. },
  4453. set: function (value) {
  4454. this._scale.x = this._scale.y = value;
  4455. this._setFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  4456. this._spreadActualScaleDirty();
  4457. },
  4458. enumerable: true,
  4459. configurable: true
  4460. });
  4461. Object.defineProperty(Prim2DBase.prototype, "actualSize", {
  4462. /**
  4463. * Return the size of the primitive as it's being rendered into the target.
  4464. * 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.
  4465. * BEWARE: don't use the setter, it's for internal purpose only
  4466. * Note to implementers: you have to override this property and declare if necessary a @xxxxInstanceLevel decorator
  4467. */
  4468. get: function () {
  4469. if (this._actualSize) {
  4470. return this._actualSize;
  4471. }
  4472. return this._size;
  4473. },
  4474. set: function (value) {
  4475. if (this._actualSize.equals(value)) {
  4476. return;
  4477. }
  4478. this._actualSize = value;
  4479. },
  4480. enumerable: true,
  4481. configurable: true
  4482. });
  4483. Object.defineProperty(Prim2DBase.prototype, "actualWidth", {
  4484. /**
  4485. * Shortcut to actualSize.width
  4486. */
  4487. get: function () {
  4488. return this.actualSize.width;
  4489. },
  4490. set: function (val) {
  4491. this._actualSize.width = val;
  4492. this._triggerPropertyChanged(Prim2DBase.actualSizeProperty, this._actualSize);
  4493. },
  4494. enumerable: true,
  4495. configurable: true
  4496. });
  4497. Object.defineProperty(Prim2DBase.prototype, "actualHeight", {
  4498. /**
  4499. * Shortcut to actualPosition.height
  4500. */
  4501. get: function () {
  4502. return this.actualSize.height;
  4503. },
  4504. set: function (val) {
  4505. this._actualSize.height = val;
  4506. this._triggerPropertyChanged(Prim2DBase.actualPositionProperty, this._actualSize);
  4507. },
  4508. enumerable: true,
  4509. configurable: true
  4510. });
  4511. Object.defineProperty(Prim2DBase.prototype, "actualZOffset", {
  4512. get: function () {
  4513. if (this._manualZOrder != null) {
  4514. return this._manualZOrder;
  4515. }
  4516. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  4517. this._updateZOrder();
  4518. }
  4519. return (1 - this._zOrder);
  4520. },
  4521. enumerable: true,
  4522. configurable: true
  4523. });
  4524. Object.defineProperty(Prim2DBase.prototype, "minSize", {
  4525. /**
  4526. * Get or set the minimal size the Layout Engine should respect when computing the primitive's actualSize.
  4527. * The Primitive's size won't be less than specified.
  4528. * The default value depends of the Primitive type
  4529. */
  4530. get: function () {
  4531. return this._minSize;
  4532. },
  4533. set: function (value) {
  4534. if (this._minSize && value && this._minSize.equals(value)) {
  4535. return;
  4536. }
  4537. this._minSize = value;
  4538. this._parentLayoutDirty();
  4539. },
  4540. enumerable: true,
  4541. configurable: true
  4542. });
  4543. Object.defineProperty(Prim2DBase.prototype, "maxSize", {
  4544. /**
  4545. * Get or set the maximal size the Layout Engine should respect when computing the primitive's actualSize.
  4546. * The Primitive's size won't be more than specified.
  4547. * The default value depends of the Primitive type
  4548. */
  4549. get: function () {
  4550. return this._maxSize;
  4551. },
  4552. set: function (value) {
  4553. if (this._maxSize && value && this._maxSize.equals(value)) {
  4554. return;
  4555. }
  4556. this._maxSize = value;
  4557. this._parentLayoutDirty();
  4558. },
  4559. enumerable: true,
  4560. configurable: true
  4561. });
  4562. Object.defineProperty(Prim2DBase.prototype, "origin", {
  4563. /**
  4564. * The origin defines the normalized coordinate of the center of the primitive, from the bottom/left corner.
  4565. * The origin is used only to compute transformation of the primitive, it has no meaning in the primitive local frame of reference
  4566. * For instance:
  4567. * 0,0 means the center is bottom/left. Which is the default for Canvas2D instances
  4568. * 0.5,0.5 means the center is at the center of the primitive, which is default of all types of Primitives
  4569. * 0,1 means the center is top/left
  4570. * @returns The normalized center.
  4571. */
  4572. get: function () {
  4573. return this._origin;
  4574. },
  4575. set: function (value) {
  4576. this._origin = value;
  4577. },
  4578. enumerable: true,
  4579. configurable: true
  4580. });
  4581. Object.defineProperty(Prim2DBase.prototype, "levelVisible", {
  4582. get: function () {
  4583. return this._isFlagSet(BABYLON.SmartPropertyPrim.flagLevelVisible);
  4584. },
  4585. set: function (value) {
  4586. this._changeFlags(BABYLON.SmartPropertyPrim.flagLevelVisible, value);
  4587. },
  4588. enumerable: true,
  4589. configurable: true
  4590. });
  4591. Object.defineProperty(Prim2DBase.prototype, "isVisible", {
  4592. get: function () {
  4593. return this._isFlagSet(BABYLON.SmartPropertyPrim.flagIsVisible);
  4594. },
  4595. set: function (value) {
  4596. this._changeFlags(BABYLON.SmartPropertyPrim.flagIsVisible, value);
  4597. },
  4598. enumerable: true,
  4599. configurable: true
  4600. });
  4601. Object.defineProperty(Prim2DBase.prototype, "zOrder", {
  4602. get: function () {
  4603. return this._manualZOrder;
  4604. },
  4605. set: function (value) {
  4606. if (this._manualZOrder === value) {
  4607. return;
  4608. }
  4609. this._manualZOrder = value;
  4610. this.onZOrderChanged();
  4611. if (this._actualZOrderChangedObservable && this._actualZOrderChangedObservable.hasObservers()) {
  4612. this._actualZOrderChangedObservable.notifyObservers(value);
  4613. }
  4614. },
  4615. enumerable: true,
  4616. configurable: true
  4617. });
  4618. Object.defineProperty(Prim2DBase.prototype, "isManualZOrder", {
  4619. get: function () {
  4620. return this._manualZOrder != null;
  4621. },
  4622. enumerable: true,
  4623. configurable: true
  4624. });
  4625. Object.defineProperty(Prim2DBase.prototype, "margin", {
  4626. get: function () {
  4627. var _this = this;
  4628. if (!this._margin) {
  4629. this._margin = new PrimitiveThickness(function () {
  4630. if (!_this.parent) {
  4631. return null;
  4632. }
  4633. return _this.parent.margin;
  4634. }, function () { return _this._positioningDirty(); });
  4635. }
  4636. return this._margin;
  4637. },
  4638. set: function (value) {
  4639. this.margin.copyFrom(value);
  4640. },
  4641. enumerable: true,
  4642. configurable: true
  4643. });
  4644. Object.defineProperty(Prim2DBase.prototype, "_hasMargin", {
  4645. /**
  4646. * Check for both margin and marginAlignment, return true if at least one of them is specified with a non default value
  4647. */
  4648. get: function () {
  4649. return (this._margin !== null && !this._margin.isDefault) || (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  4650. },
  4651. enumerable: true,
  4652. configurable: true
  4653. });
  4654. Object.defineProperty(Prim2DBase.prototype, "padding", {
  4655. get: function () {
  4656. var _this = this;
  4657. if (!this._padding) {
  4658. this._padding = new PrimitiveThickness(function () {
  4659. if (!_this.parent) {
  4660. return null;
  4661. }
  4662. return _this.parent.padding;
  4663. }, function () { return _this._positioningDirty(); });
  4664. }
  4665. return this._padding;
  4666. },
  4667. set: function (value) {
  4668. this.padding.copyFrom(value);
  4669. },
  4670. enumerable: true,
  4671. configurable: true
  4672. });
  4673. Object.defineProperty(Prim2DBase.prototype, "_hasPadding", {
  4674. get: function () {
  4675. return this._padding !== null && !this._padding.isDefault;
  4676. },
  4677. enumerable: true,
  4678. configurable: true
  4679. });
  4680. Object.defineProperty(Prim2DBase.prototype, "marginAlignment", {
  4681. get: function () {
  4682. var _this = this;
  4683. if (!this._marginAlignment) {
  4684. this._marginAlignment = new PrimitiveAlignment(function () { return _this._positioningDirty(); });
  4685. }
  4686. return this._marginAlignment;
  4687. },
  4688. set: function (value) {
  4689. this.marginAlignment.copyFrom(value);
  4690. },
  4691. enumerable: true,
  4692. configurable: true
  4693. });
  4694. Object.defineProperty(Prim2DBase.prototype, "_hasMarginAlignment", {
  4695. /**
  4696. * Check if there a marginAlignment specified (non null and not default)
  4697. */
  4698. get: function () {
  4699. return (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  4700. },
  4701. enumerable: true,
  4702. configurable: true
  4703. });
  4704. Object.defineProperty(Prim2DBase.prototype, "opacity", {
  4705. get: function () {
  4706. return this._opacity;
  4707. },
  4708. set: function (value) {
  4709. if (value < 0) {
  4710. value = 0;
  4711. }
  4712. else if (value > 1) {
  4713. value = 1;
  4714. }
  4715. if (this._opacity === value) {
  4716. return;
  4717. }
  4718. this._opacity = value;
  4719. this._setFlags(BABYLON.SmartPropertyPrim.flagActualOpacityDirty);
  4720. this._spreadActualOpacityChanged();
  4721. this._updateRenderMode();
  4722. },
  4723. enumerable: true,
  4724. configurable: true
  4725. });
  4726. Object.defineProperty(Prim2DBase.prototype, "scaleX", {
  4727. get: function () {
  4728. return this._scale.x;
  4729. },
  4730. set: function (value) {
  4731. this._scale.x = value;
  4732. this._setFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  4733. this._spreadActualScaleDirty();
  4734. },
  4735. enumerable: true,
  4736. configurable: true
  4737. });
  4738. Object.defineProperty(Prim2DBase.prototype, "scaleY", {
  4739. get: function () {
  4740. return this._scale.y;
  4741. },
  4742. set: function (value) {
  4743. this._scale.y = value;
  4744. this._setFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  4745. this._spreadActualScaleDirty();
  4746. },
  4747. enumerable: true,
  4748. configurable: true
  4749. });
  4750. Prim2DBase.prototype._spreadActualScaleDirty = function () {
  4751. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  4752. var child = _a[_i];
  4753. child._setFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  4754. child._spreadActualScaleDirty();
  4755. }
  4756. };
  4757. Object.defineProperty(Prim2DBase.prototype, "actualScale", {
  4758. /**
  4759. * 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
  4760. */
  4761. get: function () {
  4762. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagActualScaleDirty)) {
  4763. var cur = this._isFlagSet(BABYLON.SmartPropertyPrim.flagDontInheritParentScale) ? null : this.parent;
  4764. var sx = this.scaleX;
  4765. var sy = this.scaleY;
  4766. while (cur) {
  4767. sx *= cur.scaleX;
  4768. sy *= cur.scaleY;
  4769. cur = cur._isFlagSet(BABYLON.SmartPropertyPrim.flagDontInheritParentScale) ? null : cur.parent;
  4770. }
  4771. this._actualScale.copyFromFloats(sx, sy);
  4772. this._clearFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  4773. }
  4774. return this._actualScale;
  4775. },
  4776. enumerable: true,
  4777. configurable: true
  4778. });
  4779. Object.defineProperty(Prim2DBase.prototype, "actualScaleX", {
  4780. /**
  4781. * Get the actual Scale of the X axis, shortcut for this.actualScale.x
  4782. */
  4783. get: function () {
  4784. return this.actualScale.x;
  4785. },
  4786. enumerable: true,
  4787. configurable: true
  4788. });
  4789. Object.defineProperty(Prim2DBase.prototype, "actualScaleY", {
  4790. /**
  4791. * Get the actual Scale of the Y axis, shortcut for this.actualScale.y
  4792. */
  4793. get: function () {
  4794. return this.actualScale.y;
  4795. },
  4796. enumerable: true,
  4797. configurable: true
  4798. });
  4799. Object.defineProperty(Prim2DBase.prototype, "actualOpacity", {
  4800. /**
  4801. * Get the actual opacity level, this property is computed from the opacity property, multiplied by the actualOpacity of its parent (if any)
  4802. */
  4803. get: function () {
  4804. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagActualOpacityDirty)) {
  4805. var cur = this.parent;
  4806. var op = this.opacity;
  4807. while (cur) {
  4808. op *= cur.opacity;
  4809. cur = cur.parent;
  4810. }
  4811. this._actualOpacity = op;
  4812. this._clearFlags(BABYLON.SmartPropertyPrim.flagActualOpacityDirty);
  4813. }
  4814. return this._actualOpacity;
  4815. },
  4816. enumerable: true,
  4817. configurable: true
  4818. });
  4819. Object.defineProperty(Prim2DBase.prototype, "layoutEngine", {
  4820. /**
  4821. * Get/set the layout engine to use for this primitive.
  4822. * The default layout engine is the CanvasLayoutEngine.
  4823. */
  4824. get: function () {
  4825. if (!this._layoutEngine) {
  4826. this._layoutEngine = BABYLON.CanvasLayoutEngine.Singleton;
  4827. }
  4828. return this._layoutEngine;
  4829. },
  4830. set: function (value) {
  4831. if (this._layoutEngine === value) {
  4832. return;
  4833. }
  4834. this._changeLayoutEngine(value);
  4835. },
  4836. enumerable: true,
  4837. configurable: true
  4838. });
  4839. Object.defineProperty(Prim2DBase.prototype, "layoutArea", {
  4840. /**
  4841. * Get/set the layout are of this primitive.
  4842. * The Layout area is the zone allocated by the Layout Engine for this particular primitive. Margins/Alignment will be computed based on this area.
  4843. * The setter should only be called by a Layout Engine class.
  4844. */
  4845. get: function () {
  4846. return this._layoutArea;
  4847. },
  4848. set: function (val) {
  4849. if (this._layoutArea.equals(val)) {
  4850. return;
  4851. }
  4852. this._positioningDirty();
  4853. if (this.parent) {
  4854. this.parent._setFlags(BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty | BABYLON.SmartPropertyPrim.flagGlobalTransformDirty);
  4855. }
  4856. this._layoutArea = val;
  4857. },
  4858. enumerable: true,
  4859. configurable: true
  4860. });
  4861. Object.defineProperty(Prim2DBase.prototype, "layoutAreaPos", {
  4862. /**
  4863. * Get/set the layout area position (relative to the parent primitive).
  4864. * The setter should only be called by a Layout Engine class.
  4865. */
  4866. get: function () {
  4867. if (!this._layoutAreaPos) {
  4868. this._layoutAreaPos = BABYLON.Vector2.Zero();
  4869. }
  4870. return this._layoutAreaPos;
  4871. },
  4872. set: function (val) {
  4873. if (this._layoutAreaPos && this._layoutAreaPos.equals(val)) {
  4874. return;
  4875. }
  4876. if (this.parent) {
  4877. this.parent._setFlags(BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty | BABYLON.SmartPropertyPrim.flagGlobalTransformDirty);
  4878. }
  4879. this._positioningDirty();
  4880. this._layoutAreaPos = val;
  4881. },
  4882. enumerable: true,
  4883. configurable: true
  4884. });
  4885. Object.defineProperty(Prim2DBase.prototype, "isPickable", {
  4886. /**
  4887. * Define if the Primitive can be subject to intersection test or not (default is true)
  4888. */
  4889. get: function () {
  4890. return this._isFlagSet(BABYLON.SmartPropertyPrim.flagIsPickable);
  4891. },
  4892. set: function (value) {
  4893. this._changeFlags(BABYLON.SmartPropertyPrim.flagIsPickable, value);
  4894. },
  4895. enumerable: true,
  4896. configurable: true
  4897. });
  4898. Object.defineProperty(Prim2DBase.prototype, "isContainer", {
  4899. /**
  4900. * Define if the Primitive acts as a container or not
  4901. * A container will encapsulate its children for interaction event.
  4902. * If it's not a container events will be process down to children if the primitive is not pickable.
  4903. * Default value is true
  4904. */
  4905. get: function () {
  4906. return this._isFlagSet(BABYLON.SmartPropertyPrim.flagIsContainer);
  4907. },
  4908. set: function (value) {
  4909. this._changeFlags(BABYLON.SmartPropertyPrim.flagIsContainer, value);
  4910. },
  4911. enumerable: true,
  4912. configurable: true
  4913. });
  4914. Object.defineProperty(Prim2DBase.prototype, "hierarchyDepth", {
  4915. /**
  4916. * Return the depth level of the Primitive into the Canvas' Graph. A Canvas will be 0, its direct children 1, and so on.
  4917. */
  4918. get: function () {
  4919. return this._hierarchyDepth;
  4920. },
  4921. enumerable: true,
  4922. configurable: true
  4923. });
  4924. Object.defineProperty(Prim2DBase.prototype, "renderGroup", {
  4925. /**
  4926. * Retrieve the Group that is responsible to render this primitive
  4927. */
  4928. get: function () {
  4929. return this._renderGroup;
  4930. },
  4931. enumerable: true,
  4932. configurable: true
  4933. });
  4934. Object.defineProperty(Prim2DBase.prototype, "globalTransform", {
  4935. /**
  4936. * Get the global transformation matrix of the primitive
  4937. */
  4938. get: function () {
  4939. this._updateLocalTransform();
  4940. return this._globalTransform;
  4941. },
  4942. enumerable: true,
  4943. configurable: true
  4944. });
  4945. /**
  4946. * return the global position of the primitive, relative to its canvas
  4947. */
  4948. Prim2DBase.prototype.getGlobalPosition = function () {
  4949. var v = new BABYLON.Vector2(0, 0);
  4950. this.getGlobalPositionByRef(v);
  4951. return v;
  4952. };
  4953. /**
  4954. * return the global position of the primitive, relative to its canvas
  4955. * @param v the valid Vector2 object where the global position will be stored
  4956. */
  4957. Prim2DBase.prototype.getGlobalPositionByRef = function (v) {
  4958. v.x = this.globalTransform.m[12];
  4959. v.y = this.globalTransform.m[13];
  4960. };
  4961. Object.defineProperty(Prim2DBase.prototype, "invGlobalTransform", {
  4962. /**
  4963. * Get invert of the global transformation matrix of the primitive
  4964. */
  4965. get: function () {
  4966. this._updateLocalTransform();
  4967. return this._invGlobalTransform;
  4968. },
  4969. enumerable: true,
  4970. configurable: true
  4971. });
  4972. Object.defineProperty(Prim2DBase.prototype, "localTransform", {
  4973. /**
  4974. * Get the local transformation of the primitive
  4975. */
  4976. get: function () {
  4977. this._updateLocalTransform();
  4978. return this._localTransform;
  4979. },
  4980. enumerable: true,
  4981. configurable: true
  4982. });
  4983. Object.defineProperty(Prim2DBase.prototype, "boundingInfo", {
  4984. /**
  4985. * Get the boundingInfo associated to the primitive and its children.
  4986. * The value is supposed to be always up to date
  4987. */
  4988. get: function () {
  4989. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagBoundingInfoDirty)) {
  4990. if (this.owner) {
  4991. this.owner.boundingInfoRecomputeCounter.addCount(1, false);
  4992. }
  4993. if (this.isSizedByContent) {
  4994. this._boundingInfo.clear();
  4995. }
  4996. else {
  4997. this._boundingInfo.copyFrom(this.levelBoundingInfo);
  4998. }
  4999. var bi = this._boundingInfo;
  5000. var tps = new BABYLON.BoundingInfo2D();
  5001. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5002. var curChild = _a[_i];
  5003. var bb = curChild.boundingInfo;
  5004. bb.transformToRef(curChild.localTransform, tps);
  5005. bi.unionToRef(tps, bi);
  5006. }
  5007. this._boundingInfo.maxToRef(Prim2DBase._bMax);
  5008. this._boundingSize.copyFromFloats((!this._size || this._size.width == null) ? Math.ceil(Prim2DBase._bMax.x) : this._size.width, (!this._size || this._size.height == null) ? Math.ceil(Prim2DBase._bMax.y) : this._size.height);
  5009. this._clearFlags(BABYLON.SmartPropertyPrim.flagBoundingInfoDirty);
  5010. }
  5011. return this._boundingInfo;
  5012. },
  5013. enumerable: true,
  5014. configurable: true
  5015. });
  5016. Object.defineProperty(Prim2DBase.prototype, "layoutBoundingInfo", {
  5017. /**
  5018. * Get the boundingInfo of the primitive's content arranged by a layout Engine
  5019. * If a particular child is not arranged by layout, it's boundingInfo is used instead to produce something as accurate as possible
  5020. */
  5021. get: function () {
  5022. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty)) {
  5023. if (!this._layoutBoundingInfo) {
  5024. this._layoutBoundingInfo = new BABYLON.BoundingInfo2D();
  5025. }
  5026. if (this.isSizedByContent) {
  5027. this._layoutBoundingInfo.clear();
  5028. }
  5029. else {
  5030. this._layoutBoundingInfo.copyFrom(this.levelBoundingInfo);
  5031. }
  5032. var bi = this._layoutBoundingInfo;
  5033. var tps = new BABYLON.BoundingInfo2D();
  5034. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5035. var curChild = _a[_i];
  5036. var bb = void 0;
  5037. if (curChild._layoutAreaPos) {
  5038. var s = curChild._layoutArea;
  5039. BABYLON.BoundingInfo2D.CreateFromMinMaxToRef(0, s.width, 0, s.height, Prim2DBase._tpsBB);
  5040. bb = Prim2DBase._tpsBB;
  5041. }
  5042. else {
  5043. bb = curChild.boundingInfo;
  5044. }
  5045. bb.transformToRef(curChild.localTransform, tps);
  5046. bi.unionToRef(tps, bi);
  5047. }
  5048. this._clearFlags(BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty);
  5049. }
  5050. return this._layoutBoundingInfo;
  5051. },
  5052. enumerable: true,
  5053. configurable: true
  5054. });
  5055. Object.defineProperty(Prim2DBase.prototype, "isSizeAuto", {
  5056. /**
  5057. * Determine if the size is automatically computed or fixed because manually specified.
  5058. * Use the actualSize property to get the final/real size of the primitive
  5059. * @returns true if the size is automatically computed, false if it were manually specified.
  5060. */
  5061. get: function () {
  5062. return this._size == null;
  5063. },
  5064. enumerable: true,
  5065. configurable: true
  5066. });
  5067. Object.defineProperty(Prim2DBase.prototype, "isSizedByContent", {
  5068. /**
  5069. * Return true if this prim has an auto size which is set by the children's global bounding box
  5070. */
  5071. get: function () {
  5072. return (this._size == null) && (this._children.length > 0);
  5073. },
  5074. enumerable: true,
  5075. configurable: true
  5076. });
  5077. Object.defineProperty(Prim2DBase.prototype, "isPositionAuto", {
  5078. /**
  5079. * Determine if the position is automatically computed or fixed because manually specified.
  5080. * Use the actualPosition property to get the final/real position of the primitive
  5081. * @returns true if the position is automatically computed, false if it were manually specified.
  5082. */
  5083. get: function () {
  5084. return this._position == null;
  5085. },
  5086. enumerable: true,
  5087. configurable: true
  5088. });
  5089. Object.defineProperty(Prim2DBase.prototype, "pointerEventObservable", {
  5090. /**
  5091. * Interaction with the primitive can be create using this Observable. See the PrimitivePointerInfo class for more information
  5092. */
  5093. get: function () {
  5094. return this._pointerEventObservable;
  5095. },
  5096. enumerable: true,
  5097. configurable: true
  5098. });
  5099. Object.defineProperty(Prim2DBase.prototype, "zActualOrderChangedObservable", {
  5100. get: function () {
  5101. if (!this._actualZOrderChangedObservable) {
  5102. this._actualZOrderChangedObservable = new BABYLON.Observable();
  5103. }
  5104. return this._actualZOrderChangedObservable;
  5105. },
  5106. enumerable: true,
  5107. configurable: true
  5108. });
  5109. Object.defineProperty(Prim2DBase.prototype, "displayDebugAreas", {
  5110. get: function () {
  5111. return this._displayDebugAreas;
  5112. },
  5113. set: function (value) {
  5114. if (this._displayDebugAreas === value) {
  5115. return;
  5116. }
  5117. if (value === false) {
  5118. this._debugAreaGroup.dispose();
  5119. this._debugAreaGroup = null;
  5120. }
  5121. else {
  5122. var layoutFill = "#F0808040"; // Red - Layout area
  5123. var layoutBorder = "#F08080FF";
  5124. var marginFill = "#F0F04040"; // Yellow - Margin area
  5125. var marginBorder = "#F0F040FF";
  5126. var paddingFill = "#F040F040"; // Magenta - Padding Area
  5127. var paddingBorder = "#F040F0FF";
  5128. var contentFill = "#40F0F040"; // Cyan - Content area
  5129. var contentBorder = "#40F0F0FF";
  5130. var s = new BABYLON.Size(10, 10);
  5131. var p = BABYLON.Vector2.Zero();
  5132. this._debugAreaGroup = new BABYLON.Group2D({ dontInheritParentScale: true,
  5133. parent: (this.parent != null) ? this.parent : this, id: "###DEBUG AREA GROUP###", children: [
  5134. new BABYLON.Group2D({
  5135. id: "###Layout Area###", position: p, size: s, children: [
  5136. new BABYLON.Rectangle2D({ id: "###Layout Frame###", position: BABYLON.Vector2.Zero(), size: s, fill: null, border: layoutBorder }),
  5137. new BABYLON.Rectangle2D({ id: "###Layout Top###", position: BABYLON.Vector2.Zero(), size: s, fill: layoutFill }),
  5138. new BABYLON.Rectangle2D({ id: "###Layout Left###", position: BABYLON.Vector2.Zero(), size: s, fill: layoutFill }),
  5139. new BABYLON.Rectangle2D({ id: "###Layout Right###", position: BABYLON.Vector2.Zero(), size: s, fill: layoutFill }),
  5140. new BABYLON.Rectangle2D({ id: "###Layout Bottom###", position: BABYLON.Vector2.Zero(), size: s, fill: layoutFill })
  5141. ]
  5142. }),
  5143. new BABYLON.Group2D({
  5144. id: "###Margin Area###", position: p, size: s, children: [
  5145. new BABYLON.Rectangle2D({ id: "###Margin Frame###", position: BABYLON.Vector2.Zero(), size: s, fill: null, border: marginBorder }),
  5146. new BABYLON.Rectangle2D({ id: "###Margin Top###", position: BABYLON.Vector2.Zero(), size: s, fill: marginFill }),
  5147. new BABYLON.Rectangle2D({ id: "###Margin Left###", position: BABYLON.Vector2.Zero(), size: s, fill: marginFill }),
  5148. new BABYLON.Rectangle2D({ id: "###Margin Right###", position: BABYLON.Vector2.Zero(), size: s, fill: marginFill }),
  5149. new BABYLON.Rectangle2D({ id: "###Margin Bottom###", position: BABYLON.Vector2.Zero(), size: s, fill: marginFill })
  5150. ]
  5151. }),
  5152. new BABYLON.Group2D({
  5153. id: "###Padding Area###", position: p, size: s, children: [
  5154. new BABYLON.Rectangle2D({ id: "###Padding Frame###", position: BABYLON.Vector2.Zero(), size: s, fill: null, border: paddingBorder }),
  5155. new BABYLON.Rectangle2D({ id: "###Padding Top###", position: BABYLON.Vector2.Zero(), size: s, fill: paddingFill }),
  5156. new BABYLON.Rectangle2D({ id: "###Padding Left###", position: BABYLON.Vector2.Zero(), size: s, fill: paddingFill }),
  5157. new BABYLON.Rectangle2D({ id: "###Padding Right###", position: BABYLON.Vector2.Zero(), size: s, fill: paddingFill }),
  5158. new BABYLON.Rectangle2D({ id: "###Padding Bottom###", position: BABYLON.Vector2.Zero(), size: s, fill: paddingFill })
  5159. ]
  5160. }),
  5161. new BABYLON.Group2D({
  5162. id: "###Content Area###", position: p, size: s, children: [
  5163. new BABYLON.Rectangle2D({ id: "###Content Frame###", position: BABYLON.Vector2.Zero(), size: s, fill: null, border: contentBorder }),
  5164. new BABYLON.Rectangle2D({ id: "###Content Top###", position: BABYLON.Vector2.Zero(), size: s, fill: contentFill }),
  5165. new BABYLON.Rectangle2D({ id: "###Content Left###", position: BABYLON.Vector2.Zero(), size: s, fill: contentFill }),
  5166. new BABYLON.Rectangle2D({ id: "###Content Right###", position: BABYLON.Vector2.Zero(), size: s, fill: contentFill }),
  5167. new BABYLON.Rectangle2D({ id: "###Content Bottom###", position: BABYLON.Vector2.Zero(), size: s, fill: contentFill })
  5168. ]
  5169. })
  5170. ]
  5171. });
  5172. this._debugAreaGroup._setFlags(BABYLON.SmartPropertyPrim.flagNoPartOfLayout);
  5173. this._updateDebugArea();
  5174. }
  5175. this._displayDebugAreas = value;
  5176. },
  5177. enumerable: true,
  5178. configurable: true
  5179. });
  5180. Prim2DBase.prototype._updateDebugArea = function () {
  5181. var areaNames = ["Layout", "Margin", "Padding", "Content"];
  5182. var areaZones = ["Area", "Frame", "Top", "Left", "Right", "Bottom"];
  5183. var prims = new Array(4);
  5184. // Get all the primitives used to display the areas
  5185. for (var i = 0; i < 4; i++) {
  5186. prims[i] = new Array(6);
  5187. for (var j = 0; j < 6; j++) {
  5188. prims[i][j] = this._debugAreaGroup.findById("###" + areaNames[i] + " " + areaZones[j] + "###");
  5189. if (j > 1) {
  5190. prims[i][j].levelVisible = false;
  5191. }
  5192. }
  5193. }
  5194. // Update the visibility status of layout/margin/padding
  5195. var hasLayout = this._layoutAreaPos != null;
  5196. var hasPos = (this.actualPosition.x !== 0) || (this.actualPosition.y !== 0);
  5197. var hasMargin = this._hasMargin;
  5198. var hasPadding = this._hasPadding;
  5199. prims[0][0].levelVisible = hasLayout;
  5200. prims[1][0].levelVisible = hasMargin;
  5201. prims[2][0].levelVisible = hasPadding;
  5202. prims[3][0].levelVisible = true;
  5203. // Current offset
  5204. var curOffset = BABYLON.Vector2.Zero();
  5205. // Store the area info of the layout area
  5206. var curAreaIndex = 0;
  5207. // Store data about each area
  5208. var areaInfo = new Array(4);
  5209. var storeAreaInfo = function (pos, size) {
  5210. var min = pos.clone();
  5211. var max = pos.clone();
  5212. if (size.width > 0) {
  5213. max.x += size.width;
  5214. }
  5215. if (size.height > 0) {
  5216. max.y += size.height;
  5217. }
  5218. areaInfo[curAreaIndex++] = { off: pos, size: size, min: min, max: max };
  5219. };
  5220. var isCanvas = this instanceof BABYLON.Canvas2D;
  5221. var marginH = this._marginOffset.x + this._marginOffset.z;
  5222. var marginV = this._marginOffset.y + this._marginOffset.w;
  5223. var actualSize = this.actualSize.multiplyByFloats(isCanvas ? 1 : this.scaleX, isCanvas ? 1 : this.scaleY);
  5224. var w = hasLayout ? (this.layoutAreaPos.x + this.layoutArea.width) : (marginH + actualSize.width);
  5225. var h = hasLayout ? (this.layoutAreaPos.y + this.layoutArea.height) : (marginV + actualSize.height);
  5226. var pos = (!hasLayout && !hasMargin && !hasPadding && hasPos) ? this.actualPosition : BABYLON.Vector2.Zero();
  5227. storeAreaInfo(pos, new BABYLON.Size(w, h));
  5228. // Compute the layout related data
  5229. if (hasLayout) {
  5230. var layoutOffset = this.layoutAreaPos.clone();
  5231. storeAreaInfo(layoutOffset, (hasMargin || hasPadding) ? this.layoutArea.clone() : actualSize.clone());
  5232. curOffset = layoutOffset.clone();
  5233. }
  5234. // Compute margin data
  5235. if (hasMargin) {
  5236. var marginOffset = curOffset.clone();
  5237. marginOffset.x += this._marginOffset.x;
  5238. marginOffset.y += this._marginOffset.y;
  5239. var marginArea = actualSize;
  5240. storeAreaInfo(marginOffset, marginArea);
  5241. curOffset = marginOffset.clone();
  5242. }
  5243. if (hasPadding) {
  5244. var contentOffset = curOffset.clone();
  5245. contentOffset.x += this._paddingOffset.x;
  5246. contentOffset.y += this._paddingOffset.y;
  5247. var contentArea = this.contentArea;
  5248. storeAreaInfo(contentOffset, contentArea);
  5249. curOffset = curOffset.add(contentOffset);
  5250. }
  5251. // Helper function that set the pos and size of a given prim
  5252. var setArea = function (i, j, pos, size) {
  5253. prims[i][j].position = pos;
  5254. prims[i][j].size = size;
  5255. };
  5256. var setFullRect = function (i, pos, size) {
  5257. var plist = prims[i];
  5258. plist[2].levelVisible = true;
  5259. plist[3].levelVisible = false;
  5260. plist[4].levelVisible = false;
  5261. plist[5].levelVisible = false;
  5262. setArea(i, 1, pos, size);
  5263. setArea(i, 2, pos, size);
  5264. };
  5265. var setQuadRect = function (i, areaIndex) {
  5266. var plist = prims[i];
  5267. plist[2].levelVisible = true;
  5268. plist[3].levelVisible = true;
  5269. plist[4].levelVisible = true;
  5270. plist[5].levelVisible = true;
  5271. var ca = areaInfo[areaIndex];
  5272. var na = areaInfo[areaIndex + 1];
  5273. var tp = new BABYLON.Vector2(ca.min.x, na.max.y);
  5274. var ts = new BABYLON.Size(ca.size.width, ca.max.y - tp.y);
  5275. var lp = new BABYLON.Vector2(ca.min.x, na.min.y);
  5276. var ls = new BABYLON.Size(na.min.x - ca.min.x, na.max.y - na.min.y);
  5277. var rp = new BABYLON.Vector2(na.max.x, na.min.y);
  5278. var rs = new BABYLON.Size(ca.max.x - na.max.x, na.max.y - na.min.y);
  5279. var bp = new BABYLON.Vector2(ca.min.x, ca.min.y);
  5280. var bs = new BABYLON.Size(ca.size.width, na.min.y - ca.min.y);
  5281. // Frame
  5282. plist[1].position = ca.off;
  5283. plist[1].size = ca.size;
  5284. // Top rect
  5285. plist[2].position = tp;
  5286. plist[2].size = ts;
  5287. // Left rect
  5288. plist[3].position = lp;
  5289. plist[3].size = ls;
  5290. // Right rect
  5291. plist[4].position = rp;
  5292. plist[4].size = rs;
  5293. // Bottom rect
  5294. plist[5].position = bp;
  5295. plist[5].size = bs;
  5296. };
  5297. var areaCount = curAreaIndex;
  5298. curAreaIndex = 0;
  5299. // Available zones
  5300. var availableZones = [false, hasLayout, hasMargin, hasPadding, true];
  5301. for (var k = 1; k < 5; k++) {
  5302. if (availableZones[k]) {
  5303. var ai = areaInfo[curAreaIndex];
  5304. setArea(k - 1, 0, BABYLON.Vector2.Zero(), ai.size);
  5305. // setArea(k-1, 1, Vector2.Zero(), ai.size);
  5306. if (k === 4) {
  5307. setFullRect(k - 1, ai.off, ai.size);
  5308. }
  5309. else {
  5310. setQuadRect(k - 1, curAreaIndex);
  5311. }
  5312. ++curAreaIndex;
  5313. }
  5314. }
  5315. };
  5316. Prim2DBase.prototype.findById = function (id) {
  5317. if (this._id === id) {
  5318. return this;
  5319. }
  5320. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5321. var child = _a[_i];
  5322. var r = child.findById(id);
  5323. if (r != null) {
  5324. return r;
  5325. }
  5326. }
  5327. };
  5328. Prim2DBase.prototype.onZOrderChanged = function () {
  5329. };
  5330. Prim2DBase.prototype.levelIntersect = function (intersectInfo) {
  5331. return false;
  5332. };
  5333. /**
  5334. * Capture all the Events of the given PointerId for this primitive.
  5335. * Don't forget to call releasePointerEventsCapture when done.
  5336. * @param pointerId the Id of the pointer to capture the events from.
  5337. */
  5338. Prim2DBase.prototype.setPointerEventCapture = function (pointerId) {
  5339. return this.owner._setPointerCapture(pointerId, this);
  5340. };
  5341. /**
  5342. * Release a captured pointer made with setPointerEventCapture.
  5343. * @param pointerId the Id of the pointer to release the capture from.
  5344. */
  5345. Prim2DBase.prototype.releasePointerEventsCapture = function (pointerId) {
  5346. return this.owner._releasePointerCapture(pointerId, this);
  5347. };
  5348. Prim2DBase.prototype.intersect = function (intersectInfo) {
  5349. if (!intersectInfo) {
  5350. return false;
  5351. }
  5352. // If this is null it means this method is call for the first level, initialize stuffs
  5353. var firstLevel = !intersectInfo._globalPickPosition;
  5354. if (firstLevel) {
  5355. // 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).
  5356. intersectInfo._globalPickPosition = BABYLON.Vector2.Zero();
  5357. BABYLON.Vector2.TransformToRef(intersectInfo.pickPosition, this.globalTransform, intersectInfo._globalPickPosition);
  5358. intersectInfo._localPickPosition = intersectInfo.pickPosition.clone();
  5359. intersectInfo.intersectedPrimitives = new Array();
  5360. intersectInfo.topMostIntersectedPrimitive = null;
  5361. }
  5362. if (!Prim2DBase._bypassGroup2DExclusion && this instanceof BABYLON.Group2D && this.isCachedGroup && !this.isRenderableGroup) {
  5363. // Important to call this before each return to allow a good recursion next time this intersectInfo is reused
  5364. intersectInfo._exit(firstLevel);
  5365. return false;
  5366. }
  5367. if (!intersectInfo.intersectHidden && !this.isVisible) {
  5368. // Important to call this before each return to allow a good recursion next time this intersectInfo is reused
  5369. intersectInfo._exit(firstLevel);
  5370. return false;
  5371. }
  5372. var id = this.id;
  5373. if (id != null && id.indexOf("__cachedSpriteOfGroup__") === 0) {
  5374. try {
  5375. Prim2DBase._bypassGroup2DExclusion = true;
  5376. var ownerGroup = this.getExternalData("__cachedGroup__");
  5377. return ownerGroup.intersect(intersectInfo);
  5378. }
  5379. finally {
  5380. Prim2DBase._bypassGroup2DExclusion = false;
  5381. }
  5382. }
  5383. // 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).
  5384. var isIntersectionTest = false;
  5385. if (this instanceof BABYLON.Group2D) {
  5386. var g = this;
  5387. isIntersectionTest = g.isCachedGroup;
  5388. }
  5389. if (isIntersectionTest && !this.levelBoundingInfo.doesIntersect(intersectInfo._localPickPosition)) {
  5390. // Important to call this before each return to allow a good recursion next time this intersectInfo is reused
  5391. intersectInfo._exit(firstLevel);
  5392. return false;
  5393. }
  5394. // Fast rejection test with boundingInfo
  5395. if (this.isPickable && !this.boundingInfo.doesIntersect(intersectInfo._localPickPosition)) {
  5396. // Important to call this before each return to allow a good recursion next time this intersectInfo is reused
  5397. intersectInfo._exit(firstLevel);
  5398. return false;
  5399. }
  5400. // We hit the boundingInfo that bounds this primitive and its children, now we have to test on the primitive of this level
  5401. var levelIntersectRes = false;
  5402. if (this.isPickable) {
  5403. levelIntersectRes = this.levelIntersect(intersectInfo);
  5404. if (levelIntersectRes) {
  5405. var pii = new PrimitiveIntersectedInfo(this, intersectInfo._localPickPosition.clone());
  5406. intersectInfo.intersectedPrimitives.push(pii);
  5407. if (!intersectInfo.topMostIntersectedPrimitive || (intersectInfo.topMostIntersectedPrimitive.prim.actualZOffset > pii.prim.actualZOffset)) {
  5408. intersectInfo.topMostIntersectedPrimitive = pii;
  5409. }
  5410. // If we must stop at the first intersection, we're done, quit!
  5411. if (intersectInfo.findFirstOnly) {
  5412. intersectInfo._exit(firstLevel);
  5413. return true;
  5414. }
  5415. }
  5416. }
  5417. // Recurse to children if needed
  5418. if (!levelIntersectRes || !intersectInfo.findFirstOnly) {
  5419. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5420. var curChild = _a[_i];
  5421. // Don't test primitive not pick able or if it's hidden and we don't test hidden ones
  5422. if ((!curChild.isPickable && curChild.isContainer) || (!intersectInfo.intersectHidden && !curChild.isVisible)) {
  5423. continue;
  5424. }
  5425. // Must compute the localPickLocation for the children level
  5426. BABYLON.Vector2.TransformToRef(intersectInfo._globalPickPosition, curChild.invGlobalTransform, intersectInfo._localPickPosition);
  5427. // If we got an intersection with the child and we only need to find the first one, quit!
  5428. if (curChild.intersect(intersectInfo) && intersectInfo.findFirstOnly) {
  5429. intersectInfo._exit(firstLevel);
  5430. return true;
  5431. }
  5432. }
  5433. }
  5434. intersectInfo._exit(firstLevel);
  5435. return intersectInfo.isIntersected;
  5436. };
  5437. /**
  5438. * Move a child object into a new position regarding its siblings to change its rendering order.
  5439. * You can also use the shortcut methods to move top/bottom: moveChildToTop, moveChildToBottom, moveToTop, moveToBottom.
  5440. * @param child the object to move
  5441. * @param previous the object which will be before "child", if child has to be the first among sibling, set "previous" to null.
  5442. */
  5443. Prim2DBase.prototype.moveChild = function (child, previous) {
  5444. if (child.parent !== this) {
  5445. return false;
  5446. }
  5447. var childIndex = this._children.indexOf(child);
  5448. var prevIndex = previous ? this._children.indexOf(previous) : -1;
  5449. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder)) {
  5450. this._setFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  5451. this._firstZDirtyIndex = Math.min(this._firstZDirtyIndex, prevIndex + 1);
  5452. }
  5453. this._children.splice(prevIndex + 1, 0, this._children.splice(childIndex, 1)[0]);
  5454. return true;
  5455. };
  5456. /**
  5457. * Move the given child so it's displayed on the top of all its siblings
  5458. * @param child the primitive to move to the top
  5459. */
  5460. Prim2DBase.prototype.moveChildToTop = function (child) {
  5461. return this.moveChild(child, this._children[this._children.length - 1]);
  5462. };
  5463. /**
  5464. * Move the given child so it's displayed on the bottom of all its siblings
  5465. * @param child the primitive to move to the top
  5466. */
  5467. Prim2DBase.prototype.moveChildToBottom = function (child) {
  5468. return this.moveChild(child, null);
  5469. };
  5470. /**
  5471. * Move this primitive to be at the top among all its sibling
  5472. */
  5473. Prim2DBase.prototype.moveToTop = function () {
  5474. if (this.parent == null) {
  5475. return false;
  5476. }
  5477. return this.parent.moveChildToTop(this);
  5478. };
  5479. /**
  5480. * Move this primitive to be at the bottom among all its sibling
  5481. */
  5482. Prim2DBase.prototype.moveToBottom = function () {
  5483. if (this.parent == null) {
  5484. return false;
  5485. }
  5486. return this.parent.moveChildToBottom(this);
  5487. };
  5488. Prim2DBase.prototype.addChild = function (child) {
  5489. child._parent = this;
  5490. this._boundingBoxDirty();
  5491. var flat = this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  5492. if (flat) {
  5493. child._setFlags(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  5494. child._setZOrder(this._zOrder, true);
  5495. child._zMax = this._zOrder;
  5496. }
  5497. else {
  5498. this._setFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  5499. }
  5500. var length = this._children.push(child);
  5501. this._firstZDirtyIndex = Math.min(this._firstZDirtyIndex, length - 1);
  5502. };
  5503. /**
  5504. * Dispose the primitive, remove it from its parent.
  5505. */
  5506. Prim2DBase.prototype.dispose = function () {
  5507. if (!_super.prototype.dispose.call(this)) {
  5508. return false;
  5509. }
  5510. if (this._pointerEventObservable) {
  5511. this._pointerEventObservable.clear();
  5512. this._pointerEventObservable = null;
  5513. }
  5514. if (this._actionManager) {
  5515. this._actionManager.dispose();
  5516. this._actionManager = null;
  5517. }
  5518. // If there's a parent, remove this object from its parent list
  5519. if (this._parent) {
  5520. if (this instanceof BABYLON.Group2D) {
  5521. var g = this;
  5522. if (g.isRenderableGroup) {
  5523. var parentRenderable = this.parent.traverseUp(function (p) { return (p instanceof BABYLON.Group2D && p.isRenderableGroup); });
  5524. if (parentRenderable != null) {
  5525. var l = parentRenderable._renderableData._childrenRenderableGroups;
  5526. var i_1 = l.indexOf(g);
  5527. if (i_1 !== -1) {
  5528. l.splice(i_1, 1);
  5529. }
  5530. }
  5531. }
  5532. }
  5533. var i = this._parent._children.indexOf(this);
  5534. if (i !== undefined) {
  5535. this._parent._children.splice(i, 1);
  5536. }
  5537. this._parent = null;
  5538. }
  5539. // Recurse dispose to children
  5540. if (this._children) {
  5541. while (this._children.length > 0) {
  5542. this._children[this._children.length - 1].dispose();
  5543. }
  5544. }
  5545. return true;
  5546. };
  5547. Prim2DBase.prototype.onPrimBecomesDirty = function () {
  5548. if (this._renderGroup && !this._isFlagSet(BABYLON.SmartPropertyPrim.flagPrimInDirtyList)) {
  5549. this._renderGroup._addPrimToDirtyList(this);
  5550. this._setFlags(BABYLON.SmartPropertyPrim.flagPrimInDirtyList);
  5551. }
  5552. };
  5553. Prim2DBase.prototype._needPrepare = function () {
  5554. return this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagVisibilityChanged | BABYLON.SmartPropertyPrim.flagModelDirty | BABYLON.SmartPropertyPrim.flagNeedRefresh) || (this._instanceDirtyFlags !== 0) || (this._globalTransformProcessStep !== this._globalTransformStep);
  5555. };
  5556. Prim2DBase.prototype._prepareRender = function (context) {
  5557. this._prepareRenderPre(context);
  5558. this._prepareRenderPost(context);
  5559. };
  5560. Prim2DBase.prototype._prepareRenderPre = function (context) {
  5561. };
  5562. Prim2DBase.prototype._prepareRenderPost = function (context) {
  5563. // Don't recurse if it's a renderable group, the content will be processed by the group itself
  5564. if (this instanceof BABYLON.Group2D) {
  5565. var self = this;
  5566. if (self.isRenderableGroup) {
  5567. return;
  5568. }
  5569. }
  5570. // Check if we need to recurse the prepare to children primitives
  5571. // - must have children
  5572. // - the global transform of this level have changed, or
  5573. // - the visible state of primitive has changed
  5574. if (this._children.length > 0 && ((this._globalTransformProcessStep !== this._globalTransformStep) ||
  5575. this.checkPropertiesDirty(Prim2DBase.isVisibleProperty.flagId))) {
  5576. this._children.forEach(function (c) {
  5577. // As usual stop the recursion if we meet a renderable group
  5578. if (!(c instanceof BABYLON.Group2D && c.isRenderableGroup)) {
  5579. c._prepareRender(context);
  5580. }
  5581. });
  5582. }
  5583. // Finally reset the dirty flags as we've processed everything
  5584. this._clearFlags(BABYLON.SmartPropertyPrim.flagModelDirty);
  5585. this._instanceDirtyFlags = 0;
  5586. };
  5587. Prim2DBase.prototype._canvasPreInit = function (settings) {
  5588. };
  5589. Prim2DBase.CheckParent = function (parent) {
  5590. //if (!Prim2DBase._isCanvasInit && !parent) {
  5591. // 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)");
  5592. //}
  5593. };
  5594. Prim2DBase.prototype.updateCachedStatesOf = function (list, recurse) {
  5595. for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
  5596. var cur = list_1[_i];
  5597. cur.updateCachedStates(recurse);
  5598. }
  5599. };
  5600. Prim2DBase.prototype._parentLayoutDirty = function () {
  5601. if (!this._parent || this._parent.isDisposed) {
  5602. return;
  5603. }
  5604. this._parent._setLayoutDirty();
  5605. };
  5606. Prim2DBase.prototype._setLayoutDirty = function () {
  5607. this.onPrimBecomesDirty();
  5608. this._setFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  5609. };
  5610. Prim2DBase.prototype._checkPositionChange = function () {
  5611. if (this.parent && this.parent.layoutEngine.isChildPositionAllowed === false) {
  5612. console.log("Can't manually set the position of " + this.id + ", the Layout Engine of its parent doesn't allow it");
  5613. return false;
  5614. }
  5615. return true;
  5616. };
  5617. Prim2DBase.prototype._positioningDirty = function () {
  5618. this.onPrimBecomesDirty();
  5619. this._setFlags(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5620. };
  5621. Prim2DBase.prototype._spreadActualOpacityChanged = function () {
  5622. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5623. var child = _a[_i];
  5624. child._setFlags(BABYLON.SmartPropertyPrim.flagActualOpacityDirty);
  5625. child._updateRenderMode();
  5626. child.onPrimBecomesDirty();
  5627. child._spreadActualOpacityChanged();
  5628. }
  5629. };
  5630. Prim2DBase.prototype._changeLayoutEngine = function (engine) {
  5631. this._layoutEngine = engine;
  5632. };
  5633. Prim2DBase.prototype._updateLocalTransform = function () {
  5634. var tflags = Prim2DBase.actualPositionProperty.flagId | Prim2DBase.rotationProperty.flagId | Prim2DBase.scaleProperty.flagId | Prim2DBase.scaleXProperty.flagId | Prim2DBase.scaleYProperty.flagId | Prim2DBase.originProperty.flagId;
  5635. if (this.checkPropertiesDirty(tflags)) {
  5636. if (this.owner) {
  5637. this.owner.addupdateLocalTransformCounter(1);
  5638. }
  5639. var rot = BABYLON.Quaternion.RotationAxis(new BABYLON.Vector3(0, 0, 1), this._rotation);
  5640. var local;
  5641. var pos = this._position ? this.position : this.layoutAreaPos;
  5642. if (this._origin.x === 0 && this._origin.y === 0) {
  5643. 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));
  5644. this._localTransform = local;
  5645. }
  5646. else {
  5647. // -Origin offset
  5648. var as = this.actualSize;
  5649. BABYLON.Matrix.TranslationToRef((-as.width * this._origin.x), (-as.height * this._origin.y), 0, Prim2DBase._t0);
  5650. // -Origin * rotation
  5651. rot.toRotationMatrix(Prim2DBase._t1);
  5652. Prim2DBase._t0.multiplyToRef(Prim2DBase._t1, Prim2DBase._t2);
  5653. // -Origin * rotation * scale
  5654. BABYLON.Matrix.ScalingToRef(this._scale.x, this._scale.y, 1, Prim2DBase._t0);
  5655. Prim2DBase._t2.multiplyToRef(Prim2DBase._t0, Prim2DBase._t1);
  5656. // -Origin * rotation * scale * (Origin + Position)
  5657. 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._t2);
  5658. Prim2DBase._t1.multiplyToRef(Prim2DBase._t2, this._localTransform);
  5659. }
  5660. this.clearPropertiesDirty(tflags);
  5661. this._setFlags(BABYLON.SmartPropertyPrim.flagGlobalTransformDirty);
  5662. return true;
  5663. }
  5664. return false;
  5665. };
  5666. Prim2DBase.prototype.updateCachedStates = function (recurse) {
  5667. if (this.isDisposed) {
  5668. return;
  5669. }
  5670. this.owner.addCachedGroupRenderCounter(1);
  5671. // Check if the parent is synced
  5672. if (this._parent && ((this._parent._globalTransformProcessStep !== this.owner._globalTransformProcessStep) || this._parent._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagLayoutDirty | BABYLON.SmartPropertyPrim.flagPositioningDirty | BABYLON.SmartPropertyPrim.flagZOrderDirty))) {
  5673. this._parent.updateCachedStates(false);
  5674. }
  5675. // Update Z-Order if needed
  5676. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  5677. this._updateZOrder();
  5678. }
  5679. // Update actualSize only if there' not positioning to recompute and the size changed
  5680. // Otherwise positioning will take care of it.
  5681. var sizeDirty = this.checkPropertiesDirty(Prim2DBase.sizeProperty.flagId);
  5682. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty) && !this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty) && sizeDirty) {
  5683. var size = this.size;
  5684. if (size) {
  5685. if (this.size.width != null) {
  5686. this.actualSize.width = this.size.width;
  5687. }
  5688. if (this.size.height != null) {
  5689. this.actualSize.height = this.size.height;
  5690. }
  5691. this.clearPropertiesDirty(Prim2DBase.sizeProperty.flagId);
  5692. }
  5693. }
  5694. var positioningDirty = this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5695. var positioningComputed = positioningDirty && !this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5696. // Check for layout update
  5697. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty)) {
  5698. this.owner.addUpdateLayoutCounter(1);
  5699. this._layoutEngine.updateLayout(this);
  5700. this._clearFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  5701. }
  5702. var autoContentChanged = false;
  5703. if (this.isSizeAuto) {
  5704. if (!this._lastAutoSizeArea) {
  5705. autoContentChanged = this.actualSize !== null;
  5706. }
  5707. else {
  5708. autoContentChanged = (!this._lastAutoSizeArea.equals(this.actualSize));
  5709. }
  5710. }
  5711. // Check for positioning update
  5712. if (!positioningComputed && (autoContentChanged || sizeDirty || this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty) || (this._parent && !this._parent.contentArea.equals(this._parentContentArea)))) {
  5713. this._updatePositioning();
  5714. this._clearFlags(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5715. if (sizeDirty) {
  5716. this.clearPropertiesDirty(Prim2DBase.sizeProperty.flagId);
  5717. }
  5718. positioningComputed = true;
  5719. }
  5720. if (positioningComputed && this._parent) {
  5721. this._parentContentArea.copyFrom(this._parent.contentArea);
  5722. }
  5723. // Check if we must update this prim
  5724. if (this === this.owner || this._globalTransformProcessStep !== this.owner._globalTransformProcessStep) {
  5725. this.owner.addUpdateGlobalTransformCounter(1);
  5726. var curVisibleState = this.isVisible;
  5727. this.isVisible = (!this._parent || this._parent.isVisible) && this.levelVisible;
  5728. // Detect a change of visibility
  5729. this._changeFlags(BABYLON.SmartPropertyPrim.flagVisibilityChanged, curVisibleState !== this.isVisible);
  5730. // Get/compute the localTransform
  5731. var localDirty = this._updateLocalTransform();
  5732. var parentPaddingChanged = false;
  5733. var parentPaddingOffset = Prim2DBase._v0;
  5734. if (this._parent) {
  5735. parentPaddingOffset = new BABYLON.Vector2(this._parent._paddingOffset.x, this._parent._paddingOffset.y);
  5736. parentPaddingChanged = !parentPaddingOffset.equals(this._parentPaddingOffset);
  5737. }
  5738. // Check if there are changes in the parent that will force us to update the global matrix
  5739. var parentDirty = (this._parent != null) ? (this._parent._globalTransformStep !== this._parentTransformStep) : false;
  5740. // Check if we have to update the globalTransform
  5741. if (!this._globalTransform || localDirty || parentDirty || parentPaddingChanged || this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagGlobalTransformDirty)) {
  5742. var globalTransform = this._parent ? this._parent._globalTransform : null;
  5743. var localTransform = void 0;
  5744. Prim2DBase._transMtx.copyFrom(this._localTransform);
  5745. Prim2DBase._transMtx.m[12] += parentPaddingOffset.x;
  5746. Prim2DBase._transMtx.m[13] += parentPaddingOffset.y;
  5747. localTransform = Prim2DBase._transMtx;
  5748. this._globalTransform = this._parent ? localTransform.multiply(globalTransform) : localTransform.clone();
  5749. this._invGlobalTransform = BABYLON.Matrix.Invert(this._globalTransform);
  5750. this._globalTransformStep = this.owner._globalTransformProcessStep + 1;
  5751. this._parentTransformStep = this._parent ? this._parent._globalTransformStep : 0;
  5752. this._clearFlags(BABYLON.SmartPropertyPrim.flagGlobalTransformDirty);
  5753. }
  5754. this._globalTransformProcessStep = this.owner._globalTransformProcessStep;
  5755. }
  5756. if (recurse) {
  5757. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5758. var child = _a[_i];
  5759. // Stop the recursion if we meet a renderable group
  5760. child.updateCachedStates(!(child instanceof BABYLON.Group2D && child.isRenderableGroup));
  5761. }
  5762. }
  5763. };
  5764. Prim2DBase.prototype._updatePositioning = function () {
  5765. if (this.owner) {
  5766. this.owner.addUpdatePositioningCounter(1);
  5767. }
  5768. // From this point we assume that the primitive layoutArea is computed and up to date.
  5769. // We know have to :
  5770. // 1. Determine the PaddingArea and the ActualPosition based on the margin/marginAlignment properties, which will also set the size property of the primitive
  5771. // 2. Determine the contentArea based on the padding property.
  5772. var isSizeAuto = this.isSizeAuto;
  5773. // 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
  5774. if (!this._hasMarginAlignment && (isSizeAuto || (this.actualSize.width == null || this.actualSize.height == null))) {
  5775. if (isSizeAuto || this.actualSize.width == null) {
  5776. this.marginAlignment.horizontal = PrimitiveAlignment.AlignStretch;
  5777. }
  5778. if (isSizeAuto || this.actualSize.height == null) {
  5779. this.marginAlignment.vertical = PrimitiveAlignment.AlignStretch;
  5780. }
  5781. }
  5782. // Apply margin
  5783. if (this._hasMargin) {
  5784. this.margin.computeWithAlignment(this.layoutArea, this.size || this.actualSize, this.marginAlignment, this._marginOffset, Prim2DBase._size);
  5785. this.actualSize = Prim2DBase._size.clone();
  5786. }
  5787. if (this._hasPadding) {
  5788. // Two cases from here: the size of the Primitive is Auto, its content can't be shrink, so we resize the primitive itself
  5789. if (isSizeAuto) {
  5790. var content = this.size.clone();
  5791. this._getActualSizeFromContentToRef(content, Prim2DBase._icArea);
  5792. this.padding.enlarge(Prim2DBase._icArea, this._paddingOffset, Prim2DBase._size);
  5793. this._contentArea.copyFrom(content);
  5794. this.actualSize = Prim2DBase._size.clone();
  5795. // Changing the padding has resize the prim, which forces us to recompute margin again
  5796. if (this._hasMargin) {
  5797. this.margin.computeWithAlignment(this.layoutArea, Prim2DBase._size, this.marginAlignment, this._marginOffset, Prim2DBase._size);
  5798. }
  5799. }
  5800. else {
  5801. this._getInitialContentAreaToRef(this.actualSize, Prim2DBase._icZone, Prim2DBase._icArea);
  5802. Prim2DBase._icArea.width = Math.max(0, Prim2DBase._icArea.width);
  5803. Prim2DBase._icArea.height = Math.max(0, Prim2DBase._icArea.height);
  5804. this.padding.compute(Prim2DBase._icArea, this._paddingOffset, Prim2DBase._size);
  5805. this._paddingOffset.x += Prim2DBase._icZone.x;
  5806. this._paddingOffset.y += Prim2DBase._icZone.y;
  5807. this._paddingOffset.z -= Prim2DBase._icZone.z;
  5808. this._paddingOffset.w -= Prim2DBase._icZone.w;
  5809. this._contentArea.copyFrom(Prim2DBase._size);
  5810. }
  5811. }
  5812. else {
  5813. this._getInitialContentAreaToRef(this.actualSize, Prim2DBase._icZone, Prim2DBase._icArea);
  5814. Prim2DBase._icArea.width = Math.max(0, Prim2DBase._icArea.width);
  5815. Prim2DBase._icArea.height = Math.max(0, Prim2DBase._icArea.height);
  5816. this._paddingOffset.x = Prim2DBase._icZone.x;
  5817. this._paddingOffset.y = Prim2DBase._icZone.y;
  5818. this._paddingOffset.z = Prim2DBase._icZone.z;
  5819. this._paddingOffset.w = Prim2DBase._icZone.w;
  5820. this._contentArea.copyFrom(Prim2DBase._icArea);
  5821. }
  5822. if (!this._position) {
  5823. var aPos = new BABYLON.Vector2(this.layoutAreaPos.x + this._marginOffset.x, this.layoutAreaPos.y + this._marginOffset.y);
  5824. this.actualPosition = aPos;
  5825. }
  5826. if (isSizeAuto) {
  5827. this._lastAutoSizeArea = this.actualSize;
  5828. }
  5829. if (this.displayDebugAreas) {
  5830. this._updateDebugArea();
  5831. }
  5832. };
  5833. Object.defineProperty(Prim2DBase.prototype, "contentArea", {
  5834. /**
  5835. * Get the content are of this primitive, this area is computed using the padding property and also possibly the primitive type itself.
  5836. * Children of this primitive will be positioned relative to the bottom/left corner of this area.
  5837. */
  5838. get: function () {
  5839. // Check for positioning update
  5840. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty)) {
  5841. this._updatePositioning();
  5842. this._clearFlags(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5843. }
  5844. return this._contentArea;
  5845. },
  5846. enumerable: true,
  5847. configurable: true
  5848. });
  5849. Prim2DBase.prototype._patchHierarchy = function (owner) {
  5850. this._owner = owner;
  5851. // The only place we initialize the _renderGroup is this method, if it's set, we already been there, no need to execute more
  5852. if (this._renderGroup != null) {
  5853. return;
  5854. }
  5855. if (this instanceof BABYLON.Group2D) {
  5856. var group = this;
  5857. group.detectGroupStates();
  5858. if (group._trackedNode && !group._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  5859. group.owner._registerTrackedNode(this);
  5860. }
  5861. }
  5862. this._renderGroup = this.traverseUp(function (p) { return p instanceof BABYLON.Group2D && p.isRenderableGroup; });
  5863. if (this._parent) {
  5864. this._parentLayoutDirty();
  5865. }
  5866. // Make sure the prim is in the dirtyList if it should be
  5867. if (this._renderGroup && this.isDirty) {
  5868. var list = this._renderGroup._renderableData._primDirtyList;
  5869. var i = list.indexOf(this);
  5870. if (i === -1) {
  5871. list.push(this);
  5872. }
  5873. }
  5874. // Recurse
  5875. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5876. var child = _a[_i];
  5877. child._hierarchyDepth = this._hierarchyDepth + 1;
  5878. child._patchHierarchy(owner);
  5879. }
  5880. };
  5881. Prim2DBase.prototype._updateZOrder = function () {
  5882. var prevLinPos = this._primLinearPosition;
  5883. var startI = 0;
  5884. var startZ = this._zOrder;
  5885. // 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
  5886. var childrenCount = this._children.length;
  5887. if (this._firstZDirtyIndex > 0) {
  5888. if ((this._firstZDirtyIndex - 1) < childrenCount) {
  5889. var prevPrim = this._children[this._firstZDirtyIndex - 1];
  5890. prevLinPos = prevPrim._primLinearPosition;
  5891. startI = this._firstZDirtyIndex - 1;
  5892. startZ = prevPrim._zOrder;
  5893. }
  5894. }
  5895. var startPos = prevLinPos;
  5896. // Update the linear position of the primitive from the first one to the last inside this primitive, compute the total number of prim traversed
  5897. Prim2DBase._totalCount = 0;
  5898. for (var i = startI; i < childrenCount; i++) {
  5899. var child = this._children[i];
  5900. prevLinPos = child._updatePrimitiveLinearPosition(prevLinPos);
  5901. }
  5902. // Compute the new Z-Order for all the primitives
  5903. // Add 20% to the current total count to reserve space for future insertions, except if we're rebuilding due to a zMinDelta reached
  5904. var zDelta = (this._zMax - startZ) / (Prim2DBase._totalCount * (Prim2DBase._zRebuildReentrency ? 1 : 1.2));
  5905. // 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.
  5906. if (zDelta < BABYLON.Canvas2D._zMinDelta) {
  5907. // 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...
  5908. if (Prim2DBase._zRebuildReentrency) {
  5909. var p = this._parent;
  5910. if (p == null) {
  5911. // 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...)
  5912. console.log("Can't compute Z-Order for " + this.id + "'s children, zDelta is too small, Z-Order is now in an unstable state");
  5913. Prim2DBase._zRebuildReentrency = false;
  5914. return;
  5915. }
  5916. p._firstZDirtyIndex = 0;
  5917. return p._updateZOrder();
  5918. }
  5919. Prim2DBase._zRebuildReentrency = true;
  5920. this._firstZDirtyIndex = 0;
  5921. this._updateZOrder();
  5922. Prim2DBase._zRebuildReentrency = false;
  5923. }
  5924. for (var i = startI; i < childrenCount; i++) {
  5925. var child = this._children[i];
  5926. child._updatePrimitiveZOrder(startPos, startZ, zDelta);
  5927. }
  5928. // Notify the Observers that we found during the Z change (we do it after to avoid any kind of re-entrance)
  5929. for (var _i = 0, _a = Prim2DBase._zOrderChangedNotifList; _i < _a.length; _i++) {
  5930. var p = _a[_i];
  5931. p._actualZOrderChangedObservable.notifyObservers(p.actualZOffset);
  5932. }
  5933. Prim2DBase._zOrderChangedNotifList.splice(0);
  5934. this._firstZDirtyIndex = Prim2DBase._bigInt;
  5935. this._clearFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  5936. };
  5937. Prim2DBase.prototype._updatePrimitiveLinearPosition = function (prevLinPos) {
  5938. if (this.isManualZOrder) {
  5939. return prevLinPos;
  5940. }
  5941. this._primLinearPosition = ++prevLinPos;
  5942. Prim2DBase._totalCount++;
  5943. // Check for the FlatZOrder, which means the children won't have a dedicated Z-Order but will all share the same (unique) one.
  5944. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder)) {
  5945. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5946. var child = _a[_i];
  5947. prevLinPos = child._updatePrimitiveLinearPosition(prevLinPos);
  5948. }
  5949. }
  5950. return prevLinPos;
  5951. };
  5952. Prim2DBase.prototype._updatePrimitiveZOrder = function (startPos, startZ, deltaZ) {
  5953. if (this.isManualZOrder) {
  5954. return null;
  5955. }
  5956. var newZ = startZ + ((this._primLinearPosition - startPos) * deltaZ);
  5957. var isFlat = this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  5958. this._setZOrder(newZ, false);
  5959. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  5960. this._firstZDirtyIndex = Prim2DBase._bigInt;
  5961. this._clearFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  5962. }
  5963. var curZ = newZ;
  5964. // Check for the FlatZOrder, which means the children won't have a dedicated Z-Order but will all share the same (unique) one.
  5965. if (isFlat) {
  5966. if (this._children.length > 0) {
  5967. //let childrenZOrder = startZ + ((this._children[0]._primLinearPosition - startPos) * deltaZ);
  5968. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5969. var child = _a[_i];
  5970. child._updatePrimitiveFlatZOrder(this._zOrder);
  5971. }
  5972. }
  5973. }
  5974. else {
  5975. for (var _b = 0, _c = this._children; _b < _c.length; _b++) {
  5976. var child = _c[_b];
  5977. var r = child._updatePrimitiveZOrder(startPos, startZ, deltaZ);
  5978. if (r != null) {
  5979. curZ = r;
  5980. }
  5981. }
  5982. }
  5983. this._zMax = isFlat ? newZ : (curZ + deltaZ);
  5984. return curZ;
  5985. };
  5986. Prim2DBase.prototype._updatePrimitiveFlatZOrder = function (newZ) {
  5987. if (this.isManualZOrder) {
  5988. return;
  5989. }
  5990. this._setZOrder(newZ, false);
  5991. this._zMax = newZ;
  5992. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  5993. this._firstZDirtyIndex = Prim2DBase._bigInt;
  5994. this._clearFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  5995. }
  5996. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5997. var child = _a[_i];
  5998. child._updatePrimitiveFlatZOrder(newZ);
  5999. }
  6000. };
  6001. Prim2DBase.prototype._setZOrder = function (newZ, directEmit) {
  6002. if (newZ !== this._zOrder) {
  6003. this._zOrder = newZ;
  6004. this.onPrimBecomesDirty();
  6005. this.onZOrderChanged();
  6006. if (this._actualZOrderChangedObservable && this._actualZOrderChangedObservable.hasObservers()) {
  6007. if (directEmit) {
  6008. this._actualZOrderChangedObservable.notifyObservers(newZ);
  6009. }
  6010. else {
  6011. Prim2DBase._zOrderChangedNotifList.push(this);
  6012. }
  6013. }
  6014. }
  6015. };
  6016. Prim2DBase.prototype._updateRenderMode = function () {
  6017. };
  6018. /**
  6019. * This method is used to alter the contentArea of the Primitive before margin is applied.
  6020. * 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.
  6021. * @param primSize the current size of the primitive
  6022. * @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
  6023. * @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!
  6024. */
  6025. Prim2DBase.prototype._getInitialContentAreaToRef = function (primSize, initialContentPosition, initialContentArea) {
  6026. initialContentArea.copyFrom(primSize);
  6027. initialContentPosition.x = initialContentPosition.y = initialContentPosition.z = initialContentPosition.w = 0;
  6028. };
  6029. /**
  6030. * This method is used to calculate the new size of the primitive based on the content which must stay the same
  6031. * Check the Rectangle2D implementation for a concrete application.
  6032. * @param primSize the current size of the primitive
  6033. * @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!
  6034. */
  6035. Prim2DBase.prototype._getActualSizeFromContentToRef = function (primSize, newPrimSize) {
  6036. newPrimSize.copyFrom(primSize);
  6037. };
  6038. Prim2DBase.PRIM2DBASE_PROPCOUNT = 25;
  6039. Prim2DBase._bigInt = Math.pow(2, 30);
  6040. Prim2DBase._nullPosition = BABYLON.Vector2.Zero();
  6041. Prim2DBase.boundinbBoxReentrency = false;
  6042. Prim2DBase.nullSize = BABYLON.Size.Zero();
  6043. Prim2DBase._bMax = BABYLON.Vector2.Zero();
  6044. Prim2DBase._tpsBB = new BABYLON.BoundingInfo2D();
  6045. /**
  6046. * Make an intersection test with the primitive, all inputs/outputs are stored in the IntersectInfo2D class, see its documentation for more information.
  6047. * @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.
  6048. */
  6049. Prim2DBase._bypassGroup2DExclusion = false;
  6050. Prim2DBase._isCanvasInit = false;
  6051. Prim2DBase._t0 = new BABYLON.Matrix();
  6052. Prim2DBase._t1 = new BABYLON.Matrix();
  6053. Prim2DBase._t2 = new BABYLON.Matrix();
  6054. Prim2DBase._v0 = BABYLON.Vector2.Zero(); // Must stay with the value 0,0
  6055. Prim2DBase._transMtx = BABYLON.Matrix.Zero();
  6056. Prim2DBase._icPos = BABYLON.Vector2.Zero();
  6057. Prim2DBase._icZone = BABYLON.Vector4.Zero();
  6058. Prim2DBase._icArea = BABYLON.Size.Zero();
  6059. Prim2DBase._size = BABYLON.Size.Zero();
  6060. Prim2DBase._zOrderChangedNotifList = new Array();
  6061. Prim2DBase._zRebuildReentrency = false;
  6062. Prim2DBase._totalCount = 0;
  6063. __decorate([
  6064. BABYLON.instanceLevelProperty(1, function (pi) { return Prim2DBase.actualPositionProperty = pi; }, false, false, true)
  6065. ], Prim2DBase.prototype, "actualPosition", null);
  6066. __decorate([
  6067. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 1, function (pi) { return Prim2DBase.actualXProperty = pi; }, false, false, true)
  6068. ], Prim2DBase.prototype, "actualX", null);
  6069. __decorate([
  6070. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 2, function (pi) { return Prim2DBase.actualYProperty = pi; }, false, false, true)
  6071. ], Prim2DBase.prototype, "actualY", null);
  6072. __decorate([
  6073. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 3, function (pi) { return Prim2DBase.positionProperty = pi; }, false, false, true)
  6074. ], Prim2DBase.prototype, "position", null);
  6075. __decorate([
  6076. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 4, function (pi) { return Prim2DBase.xProperty = pi; }, false, false, true)
  6077. ], Prim2DBase.prototype, "x", null);
  6078. __decorate([
  6079. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 5, function (pi) { return Prim2DBase.yProperty = pi; }, false, false, true)
  6080. ], Prim2DBase.prototype, "y", null);
  6081. __decorate([
  6082. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 6, function (pi) { return Prim2DBase.sizeProperty = pi; }, false, true)
  6083. ], Prim2DBase.prototype, "size", null);
  6084. __decorate([
  6085. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 7, function (pi) { return Prim2DBase.widthProperty = pi; }, false, true)
  6086. ], Prim2DBase.prototype, "width", null);
  6087. __decorate([
  6088. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 8, function (pi) { return Prim2DBase.heightProperty = pi; }, false, true)
  6089. ], Prim2DBase.prototype, "height", null);
  6090. __decorate([
  6091. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 9, function (pi) { return Prim2DBase.rotationProperty = pi; }, false, true)
  6092. ], Prim2DBase.prototype, "rotation", null);
  6093. __decorate([
  6094. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 10, function (pi) { return Prim2DBase.scaleProperty = pi; }, false, true)
  6095. ], Prim2DBase.prototype, "scale", null);
  6096. __decorate([
  6097. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 11, function (pi) { return Prim2DBase.actualSizeProperty = pi; }, false, true)
  6098. ], Prim2DBase.prototype, "actualSize", null);
  6099. __decorate([
  6100. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 12, function (pi) { return Prim2DBase.actualWidthProperty = pi; }, false, true)
  6101. ], Prim2DBase.prototype, "actualWidth", null);
  6102. __decorate([
  6103. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 13, function (pi) { return Prim2DBase.actualHeightProperty = pi; }, false, true)
  6104. ], Prim2DBase.prototype, "actualHeight", null);
  6105. __decorate([
  6106. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 14, function (pi) { return Prim2DBase.originProperty = pi; }, false, true)
  6107. ], Prim2DBase.prototype, "origin", null);
  6108. __decorate([
  6109. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 15, function (pi) { return Prim2DBase.levelVisibleProperty = pi; })
  6110. ], Prim2DBase.prototype, "levelVisible", null);
  6111. __decorate([
  6112. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 16, function (pi) { return Prim2DBase.isVisibleProperty = pi; })
  6113. ], Prim2DBase.prototype, "isVisible", null);
  6114. __decorate([
  6115. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 17, function (pi) { return Prim2DBase.zOrderProperty = pi; })
  6116. ], Prim2DBase.prototype, "zOrder", null);
  6117. __decorate([
  6118. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 18, function (pi) { return Prim2DBase.marginProperty = pi; })
  6119. ], Prim2DBase.prototype, "margin", null);
  6120. __decorate([
  6121. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 19, function (pi) { return Prim2DBase.paddingProperty = pi; })
  6122. ], Prim2DBase.prototype, "padding", null);
  6123. __decorate([
  6124. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 20, function (pi) { return Prim2DBase.marginAlignmentProperty = pi; })
  6125. ], Prim2DBase.prototype, "marginAlignment", null);
  6126. __decorate([
  6127. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 21, function (pi) { return Prim2DBase.opacityProperty = pi; })
  6128. ], Prim2DBase.prototype, "opacity", null);
  6129. __decorate([
  6130. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 22, function (pi) { return Prim2DBase.scaleXProperty = pi; }, false, true)
  6131. ], Prim2DBase.prototype, "scaleX", null);
  6132. __decorate([
  6133. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 23, function (pi) { return Prim2DBase.scaleYProperty = pi; }, false, true)
  6134. ], Prim2DBase.prototype, "scaleY", null);
  6135. __decorate([
  6136. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 24, function (pi) { return Prim2DBase.actualScaleProperty = pi; }, false, true)
  6137. ], Prim2DBase.prototype, "actualScale", null);
  6138. Prim2DBase = __decorate([
  6139. BABYLON.className("Prim2DBase", "BABYLON")
  6140. ], Prim2DBase);
  6141. return Prim2DBase;
  6142. }(BABYLON.SmartPropertyPrim));
  6143. BABYLON.Prim2DBase = Prim2DBase;
  6144. })(BABYLON || (BABYLON = {}));
  6145. //# sourceMappingURL=babylon.prim2dBase.js.map
  6146. var __extends = (this && this.__extends) || function (d, b) {
  6147. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  6148. function __() { this.constructor = d; }
  6149. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6150. };
  6151. var BABYLON;
  6152. (function (BABYLON) {
  6153. var GroupInstanceInfo = (function () {
  6154. function GroupInstanceInfo(owner, mrc, partCount) {
  6155. this._partCount = partCount;
  6156. this.owner = owner;
  6157. this.modelRenderCache = mrc;
  6158. this.modelRenderCache.addRef();
  6159. this.partIndexFromId = new BABYLON.StringDictionary();
  6160. this._usedShaderCategories = new Array(partCount);
  6161. this._strides = new Array(partCount);
  6162. this._opaqueData = null;
  6163. this._alphaTestData = null;
  6164. this._transparentData = null;
  6165. this.opaqueDirty = this.alphaTestDirty = this.transparentDirty = this.transparentOrderDirty = false;
  6166. }
  6167. GroupInstanceInfo.prototype.dispose = function () {
  6168. if (this._isDisposed) {
  6169. return false;
  6170. }
  6171. if (this.modelRenderCache) {
  6172. this.modelRenderCache.dispose();
  6173. this.modelRenderCache = null;
  6174. }
  6175. var engine = this.owner.owner.engine;
  6176. if (this._opaqueData) {
  6177. this._opaqueData.forEach(function (d) { return d.dispose(engine); });
  6178. this._opaqueData = null;
  6179. }
  6180. if (this._alphaTestData) {
  6181. this._alphaTestData.forEach(function (d) { return d.dispose(engine); });
  6182. this._alphaTestData = null;
  6183. }
  6184. if (this._transparentData) {
  6185. this._transparentData.forEach(function (d) { return d.dispose(engine); });
  6186. this._transparentData = null;
  6187. }
  6188. this.partIndexFromId = null;
  6189. this._isDisposed = true;
  6190. return true;
  6191. };
  6192. Object.defineProperty(GroupInstanceInfo.prototype, "hasOpaqueData", {
  6193. get: function () {
  6194. return this._opaqueData != null;
  6195. },
  6196. enumerable: true,
  6197. configurable: true
  6198. });
  6199. Object.defineProperty(GroupInstanceInfo.prototype, "hasAlphaTestData", {
  6200. get: function () {
  6201. return this._alphaTestData != null;
  6202. },
  6203. enumerable: true,
  6204. configurable: true
  6205. });
  6206. Object.defineProperty(GroupInstanceInfo.prototype, "hasTransparentData", {
  6207. get: function () {
  6208. return this._transparentData != null;
  6209. },
  6210. enumerable: true,
  6211. configurable: true
  6212. });
  6213. Object.defineProperty(GroupInstanceInfo.prototype, "opaqueData", {
  6214. get: function () {
  6215. if (!this._opaqueData) {
  6216. this._opaqueData = new Array(this._partCount);
  6217. for (var i = 0; i < this._partCount; i++) {
  6218. this._opaqueData[i] = new GroupInfoPartData(this._strides[i]);
  6219. }
  6220. }
  6221. return this._opaqueData;
  6222. },
  6223. enumerable: true,
  6224. configurable: true
  6225. });
  6226. Object.defineProperty(GroupInstanceInfo.prototype, "alphaTestData", {
  6227. get: function () {
  6228. if (!this._alphaTestData) {
  6229. this._alphaTestData = new Array(this._partCount);
  6230. for (var i = 0; i < this._partCount; i++) {
  6231. this._alphaTestData[i] = new GroupInfoPartData(this._strides[i]);
  6232. }
  6233. }
  6234. return this._alphaTestData;
  6235. },
  6236. enumerable: true,
  6237. configurable: true
  6238. });
  6239. Object.defineProperty(GroupInstanceInfo.prototype, "transparentData", {
  6240. get: function () {
  6241. if (!this._transparentData) {
  6242. this._transparentData = new Array(this._partCount);
  6243. for (var i = 0; i < this._partCount; i++) {
  6244. var zoff = this.modelRenderCache._partData[i]._zBiasOffset;
  6245. this._transparentData[i] = new TransparentGroupInfoPartData(this._strides[i], zoff);
  6246. }
  6247. }
  6248. return this._transparentData;
  6249. },
  6250. enumerable: true,
  6251. configurable: true
  6252. });
  6253. GroupInstanceInfo.prototype.sortTransparentData = function () {
  6254. if (!this.transparentOrderDirty) {
  6255. return;
  6256. }
  6257. for (var i = 0; i < this._transparentData.length; i++) {
  6258. var td = this._transparentData[i];
  6259. td._partData.sort();
  6260. }
  6261. this.transparentOrderDirty = false;
  6262. };
  6263. Object.defineProperty(GroupInstanceInfo.prototype, "usedShaderCategories", {
  6264. get: function () {
  6265. return this._usedShaderCategories;
  6266. },
  6267. enumerable: true,
  6268. configurable: true
  6269. });
  6270. Object.defineProperty(GroupInstanceInfo.prototype, "strides", {
  6271. get: function () {
  6272. return this._strides;
  6273. },
  6274. enumerable: true,
  6275. configurable: true
  6276. });
  6277. return GroupInstanceInfo;
  6278. }());
  6279. BABYLON.GroupInstanceInfo = GroupInstanceInfo;
  6280. var TransparentSegment = (function () {
  6281. function TransparentSegment() {
  6282. this.groupInsanceInfo = null;
  6283. this.startZ = 0;
  6284. this.endZ = 0;
  6285. this.startDataIndex = BABYLON.Prim2DBase._bigInt;
  6286. this.endDataIndex = 0;
  6287. this.partBuffers = null;
  6288. }
  6289. TransparentSegment.prototype.dispose = function (engine) {
  6290. if (this.partBuffers) {
  6291. this.partBuffers.forEach(function (b) { return engine._releaseBuffer(b); });
  6292. this.partBuffers.splice(0);
  6293. this.partBuffers = null;
  6294. }
  6295. };
  6296. return TransparentSegment;
  6297. }());
  6298. BABYLON.TransparentSegment = TransparentSegment;
  6299. var GroupInfoPartData = (function () {
  6300. function GroupInfoPartData(stride) {
  6301. this._partData = null;
  6302. this._partBuffer = null;
  6303. this._partBufferSize = 0;
  6304. this._partData = new BABYLON.DynamicFloatArray(stride / 4, 50);
  6305. this._isDisposed = false;
  6306. }
  6307. GroupInfoPartData.prototype.dispose = function (engine) {
  6308. if (this._isDisposed) {
  6309. return false;
  6310. }
  6311. if (this._partBuffer) {
  6312. engine._releaseBuffer(this._partBuffer);
  6313. this._partBuffer = null;
  6314. }
  6315. this._partData = null;
  6316. this._isDisposed = true;
  6317. };
  6318. return GroupInfoPartData;
  6319. }());
  6320. BABYLON.GroupInfoPartData = GroupInfoPartData;
  6321. var TransparentGroupInfoPartData = (function (_super) {
  6322. __extends(TransparentGroupInfoPartData, _super);
  6323. function TransparentGroupInfoPartData(stride, zoff) {
  6324. _super.call(this, stride);
  6325. this._partData.compareValueOffset = zoff;
  6326. this._partData.sortingAscending = false;
  6327. }
  6328. return TransparentGroupInfoPartData;
  6329. }(GroupInfoPartData));
  6330. BABYLON.TransparentGroupInfoPartData = TransparentGroupInfoPartData;
  6331. var ModelRenderCache = (function () {
  6332. function ModelRenderCache(engine, modelKey) {
  6333. this._engine = engine;
  6334. this._modelKey = modelKey;
  6335. this._nextKey = 1;
  6336. this._refCounter = 1;
  6337. this._partData = null;
  6338. }
  6339. ModelRenderCache.prototype.dispose = function () {
  6340. if (--this._refCounter !== 0) {
  6341. return false;
  6342. }
  6343. // Remove the Model Render Cache from the global dictionary
  6344. var edata = this._engine.getExternalData("__BJSCANVAS2D__");
  6345. if (edata) {
  6346. edata.DisposeModelRenderCache(this);
  6347. }
  6348. return true;
  6349. };
  6350. Object.defineProperty(ModelRenderCache.prototype, "isDisposed", {
  6351. get: function () {
  6352. return this._refCounter <= 0;
  6353. },
  6354. enumerable: true,
  6355. configurable: true
  6356. });
  6357. ModelRenderCache.prototype.addRef = function () {
  6358. return ++this._refCounter;
  6359. };
  6360. Object.defineProperty(ModelRenderCache.prototype, "modelKey", {
  6361. get: function () {
  6362. return this._modelKey;
  6363. },
  6364. enumerable: true,
  6365. configurable: true
  6366. });
  6367. /**
  6368. * Render the model instances
  6369. * @param instanceInfo
  6370. * @param context
  6371. * @return must return true is the rendering succeed, false if the rendering couldn't be done (asset's not yet ready, like Effect)
  6372. */
  6373. ModelRenderCache.prototype.render = function (instanceInfo, context) {
  6374. return true;
  6375. };
  6376. ModelRenderCache.prototype.getPartIndexFromId = function (partId) {
  6377. for (var i = 0; i < this._partData.length; i++) {
  6378. if (this._partData[i]._partId === partId) {
  6379. return i;
  6380. }
  6381. }
  6382. return null;
  6383. };
  6384. ModelRenderCache.prototype.loadInstancingAttributes = function (partId, effect) {
  6385. var i = this.getPartIndexFromId(partId);
  6386. if (i === null) {
  6387. return null;
  6388. }
  6389. var ci = this._partsClassInfo[i];
  6390. var categories = this._partData[i]._partUsedCategories;
  6391. var res = ci.classContent.getInstancingAttributeInfos(effect, categories);
  6392. return res;
  6393. };
  6394. ModelRenderCache.prototype.setupUniforms = function (effect, partIndex, data, elementCount) {
  6395. var pd = this._partData[partIndex];
  6396. var offset = (pd._partDataStride / 4) * elementCount;
  6397. var pci = this._partsClassInfo[partIndex];
  6398. var self = this;
  6399. pci.fullContent.forEach(function (k, v) {
  6400. if (!v.category || pd._partUsedCategories.indexOf(v.category) !== -1) {
  6401. switch (v.dataType) {
  6402. case 4 /* float */:
  6403. {
  6404. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  6405. effect.setFloat(v.attributeName, data.buffer[offset + attribOffset]);
  6406. break;
  6407. }
  6408. case 0 /* Vector2 */:
  6409. {
  6410. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  6411. ModelRenderCache.v2.x = data.buffer[offset + attribOffset + 0];
  6412. ModelRenderCache.v2.y = data.buffer[offset + attribOffset + 1];
  6413. effect.setVector2(v.attributeName, ModelRenderCache.v2);
  6414. break;
  6415. }
  6416. case 5 /* Color3 */:
  6417. case 1 /* Vector3 */:
  6418. {
  6419. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  6420. ModelRenderCache.v3.x = data.buffer[offset + attribOffset + 0];
  6421. ModelRenderCache.v3.y = data.buffer[offset + attribOffset + 1];
  6422. ModelRenderCache.v3.z = data.buffer[offset + attribOffset + 2];
  6423. effect.setVector3(v.attributeName, ModelRenderCache.v3);
  6424. break;
  6425. }
  6426. case 6 /* Color4 */:
  6427. case 2 /* Vector4 */:
  6428. {
  6429. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  6430. ModelRenderCache.v4.x = data.buffer[offset + attribOffset + 0];
  6431. ModelRenderCache.v4.y = data.buffer[offset + attribOffset + 1];
  6432. ModelRenderCache.v4.z = data.buffer[offset + attribOffset + 2];
  6433. ModelRenderCache.v4.w = data.buffer[offset + attribOffset + 3];
  6434. effect.setVector4(v.attributeName, ModelRenderCache.v4);
  6435. break;
  6436. }
  6437. default:
  6438. }
  6439. }
  6440. });
  6441. };
  6442. //setupUniformsLocation(effect: Effect, uniforms: string[], partId: number) {
  6443. // let i = this.getPartIndexFromId(partId);
  6444. // if (i === null) {
  6445. // return null;
  6446. // }
  6447. // let pci = this._partsClassInfo[i];
  6448. // pci.fullContent.forEach((k, v) => {
  6449. // if (uniforms.indexOf(v.attributeName) !== -1) {
  6450. // v.uniformLocation = effect.getUniform(v.attributeName);
  6451. // }
  6452. // });
  6453. //}
  6454. ModelRenderCache.v2 = BABYLON.Vector2.Zero();
  6455. ModelRenderCache.v3 = BABYLON.Vector3.Zero();
  6456. ModelRenderCache.v4 = BABYLON.Vector4.Zero();
  6457. return ModelRenderCache;
  6458. }());
  6459. BABYLON.ModelRenderCache = ModelRenderCache;
  6460. var ModelRenderCachePartData = (function () {
  6461. function ModelRenderCachePartData() {
  6462. }
  6463. return ModelRenderCachePartData;
  6464. }());
  6465. BABYLON.ModelRenderCachePartData = ModelRenderCachePartData;
  6466. })(BABYLON || (BABYLON = {}));
  6467. //# sourceMappingURL=babylon.modelRenderCache.js.map
  6468. var __extends = (this && this.__extends) || function (d, b) {
  6469. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  6470. function __() { this.constructor = d; }
  6471. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6472. };
  6473. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  6474. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  6475. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  6476. 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;
  6477. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6478. };
  6479. var BABYLON;
  6480. (function (BABYLON) {
  6481. var InstanceClassInfo = (function () {
  6482. function InstanceClassInfo(base) {
  6483. this._baseInfo = base;
  6484. this._nextOffset = new BABYLON.StringDictionary();
  6485. this._attributes = new Array();
  6486. }
  6487. InstanceClassInfo.prototype.mapProperty = function (propInfo, push) {
  6488. var curOff = this._nextOffset.getOrAdd(InstanceClassInfo._CurCategories, 0);
  6489. propInfo.instanceOffset.add(InstanceClassInfo._CurCategories, this._getBaseOffset(InstanceClassInfo._CurCategories) + curOff);
  6490. //console.log(`[${InstanceClassInfo._CurCategories}] New PropInfo. Category: ${propInfo.category}, Name: ${propInfo.attributeName}, Offset: ${propInfo.instanceOffset.get(InstanceClassInfo._CurCategories)}, Size: ${propInfo.size / 4}`);
  6491. this._nextOffset.set(InstanceClassInfo._CurCategories, curOff + (propInfo.size / 4));
  6492. if (push) {
  6493. this._attributes.push(propInfo);
  6494. }
  6495. };
  6496. InstanceClassInfo.prototype.getInstancingAttributeInfos = function (effect, categories) {
  6497. var catInline = ";" + categories.join(";") + ";";
  6498. var res = new Array();
  6499. var curInfo = this;
  6500. while (curInfo) {
  6501. for (var _i = 0, _a = curInfo._attributes; _i < _a.length; _i++) {
  6502. var attrib = _a[_i];
  6503. // 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
  6504. if (!attrib.category || categories.indexOf(attrib.category) !== -1) {
  6505. var index = effect.getAttributeLocationByName(attrib.attributeName);
  6506. var iai = new BABYLON.InstancingAttributeInfo();
  6507. iai.index = index;
  6508. 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)
  6509. iai.offset = attrib.instanceOffset.get(catInline) * 4; // attrib.instanceOffset is in float, iai.offset must be in bytes
  6510. iai.attributeName = attrib.attributeName;
  6511. res.push(iai);
  6512. }
  6513. }
  6514. curInfo = curInfo._baseInfo;
  6515. }
  6516. return res;
  6517. };
  6518. InstanceClassInfo.prototype.getShaderAttributes = function (categories) {
  6519. var res = new Array();
  6520. var curInfo = this;
  6521. while (curInfo) {
  6522. for (var _i = 0, _a = curInfo._attributes; _i < _a.length; _i++) {
  6523. var attrib = _a[_i];
  6524. // 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
  6525. if (!attrib.category || categories.indexOf(attrib.category) !== -1) {
  6526. res.push(attrib.attributeName);
  6527. }
  6528. }
  6529. curInfo = curInfo._baseInfo;
  6530. }
  6531. return res;
  6532. };
  6533. InstanceClassInfo.prototype._getBaseOffset = function (categories) {
  6534. var curOffset = 0;
  6535. var curBase = this._baseInfo;
  6536. while (curBase) {
  6537. curOffset += curBase._nextOffset.getOrAdd(categories, 0);
  6538. curBase = curBase._baseInfo;
  6539. }
  6540. return curOffset;
  6541. };
  6542. return InstanceClassInfo;
  6543. }());
  6544. BABYLON.InstanceClassInfo = InstanceClassInfo;
  6545. var InstancePropInfo = (function () {
  6546. function InstancePropInfo() {
  6547. this.instanceOffset = new BABYLON.StringDictionary();
  6548. }
  6549. InstancePropInfo.prototype.setSize = function (val) {
  6550. if (val instanceof BABYLON.Vector2) {
  6551. this.size = 8;
  6552. this.dataType = 0 /* Vector2 */;
  6553. return;
  6554. }
  6555. if (val instanceof BABYLON.Vector3) {
  6556. this.size = 12;
  6557. this.dataType = 1 /* Vector3 */;
  6558. return;
  6559. }
  6560. if (val instanceof BABYLON.Vector4) {
  6561. this.size = 16;
  6562. this.dataType = 2 /* Vector4 */;
  6563. return;
  6564. }
  6565. if (val instanceof BABYLON.Matrix) {
  6566. throw new Error("Matrix type is not supported by WebGL Instance Buffer, you have to use four Vector4 properties instead");
  6567. }
  6568. if (typeof (val) === "number") {
  6569. this.size = 4;
  6570. this.dataType = 4 /* float */;
  6571. return;
  6572. }
  6573. if (val instanceof BABYLON.Color3) {
  6574. this.size = 12;
  6575. this.dataType = 5 /* Color3 */;
  6576. return;
  6577. }
  6578. if (val instanceof BABYLON.Color4) {
  6579. this.size = 16;
  6580. this.dataType = 6 /* Color4 */;
  6581. return;
  6582. }
  6583. if (val instanceof BABYLON.Size) {
  6584. this.size = 8;
  6585. this.dataType = 7 /* Size */;
  6586. return;
  6587. }
  6588. return;
  6589. };
  6590. InstancePropInfo.prototype.writeData = function (array, offset, val) {
  6591. switch (this.dataType) {
  6592. case 0 /* Vector2 */:
  6593. {
  6594. var v = val;
  6595. array[offset + 0] = v.x;
  6596. array[offset + 1] = v.y;
  6597. break;
  6598. }
  6599. case 1 /* Vector3 */:
  6600. {
  6601. var v = val;
  6602. array[offset + 0] = v.x;
  6603. array[offset + 1] = v.y;
  6604. array[offset + 2] = v.z;
  6605. break;
  6606. }
  6607. case 2 /* Vector4 */:
  6608. {
  6609. var v = val;
  6610. array[offset + 0] = v.x;
  6611. array[offset + 1] = v.y;
  6612. array[offset + 2] = v.z;
  6613. array[offset + 3] = v.w;
  6614. break;
  6615. }
  6616. case 5 /* Color3 */:
  6617. {
  6618. var v = val;
  6619. array[offset + 0] = v.r;
  6620. array[offset + 1] = v.g;
  6621. array[offset + 2] = v.b;
  6622. break;
  6623. }
  6624. case 6 /* Color4 */:
  6625. {
  6626. var v = val;
  6627. array[offset + 0] = v.r;
  6628. array[offset + 1] = v.g;
  6629. array[offset + 2] = v.b;
  6630. array[offset + 3] = v.a;
  6631. break;
  6632. }
  6633. case 4 /* float */:
  6634. {
  6635. var v = val;
  6636. array[offset] = v;
  6637. break;
  6638. }
  6639. case 3 /* Matrix */:
  6640. {
  6641. var v = val;
  6642. for (var i = 0; i < 16; i++) {
  6643. array[offset + i] = v.m[i];
  6644. }
  6645. break;
  6646. }
  6647. case 7 /* Size */:
  6648. {
  6649. var s = val;
  6650. array[offset + 0] = s.width;
  6651. array[offset + 1] = s.height;
  6652. break;
  6653. }
  6654. }
  6655. };
  6656. return InstancePropInfo;
  6657. }());
  6658. BABYLON.InstancePropInfo = InstancePropInfo;
  6659. function instanceData(category, shaderAttributeName) {
  6660. return function (target, propName, descriptor) {
  6661. var dic = BABYLON.ClassTreeInfo.getOrRegister(target, function (base) { return new InstanceClassInfo(base); });
  6662. var node = dic.getLevelOf(target);
  6663. var instanceDataName = propName;
  6664. shaderAttributeName = shaderAttributeName || instanceDataName;
  6665. var info = node.levelContent.get(instanceDataName);
  6666. if (info) {
  6667. throw new Error("The ID " + instanceDataName + " is already taken by another instance data");
  6668. }
  6669. info = new InstancePropInfo();
  6670. info.attributeName = shaderAttributeName;
  6671. info.category = category || null;
  6672. if (info.category) {
  6673. info.delimitedCategory = ";" + info.category + ";";
  6674. }
  6675. node.levelContent.add(instanceDataName, info);
  6676. descriptor.get = function () {
  6677. return null;
  6678. };
  6679. descriptor.set = function (val) {
  6680. // Check that we're not trying to set a property that belongs to a category that is not allowed (current)
  6681. // Quit if it's the case, otherwise we could overwrite data somewhere...
  6682. if (info.category && InstanceClassInfo._CurCategories.indexOf(info.delimitedCategory) === -1) {
  6683. return;
  6684. }
  6685. if (!info.size) {
  6686. info.setSize(val);
  6687. node.classContent.mapProperty(info, true);
  6688. }
  6689. else if (!info.instanceOffset.contains(InstanceClassInfo._CurCategories)) {
  6690. node.classContent.mapProperty(info, false);
  6691. }
  6692. var obj = this;
  6693. if (obj.dataBuffer && obj.dataElements) {
  6694. var offset = obj.dataElements[obj.curElement].offset + info.instanceOffset.get(InstanceClassInfo._CurCategories);
  6695. info.writeData(obj.dataBuffer.buffer, offset, val);
  6696. }
  6697. };
  6698. };
  6699. }
  6700. BABYLON.instanceData = instanceData;
  6701. var InstanceDataBase = (function () {
  6702. function InstanceDataBase(partId, dataElementCount) {
  6703. this.id = partId;
  6704. this.curElement = 0;
  6705. this._dataElementCount = dataElementCount;
  6706. this.renderMode = 0;
  6707. this.arrayLengthChanged = false;
  6708. }
  6709. Object.defineProperty(InstanceDataBase.prototype, "zBias", {
  6710. get: function () {
  6711. return null;
  6712. },
  6713. set: function (value) {
  6714. },
  6715. enumerable: true,
  6716. configurable: true
  6717. });
  6718. Object.defineProperty(InstanceDataBase.prototype, "transformX", {
  6719. get: function () {
  6720. return null;
  6721. },
  6722. set: function (value) {
  6723. },
  6724. enumerable: true,
  6725. configurable: true
  6726. });
  6727. Object.defineProperty(InstanceDataBase.prototype, "transformY", {
  6728. get: function () {
  6729. return null;
  6730. },
  6731. set: function (value) {
  6732. },
  6733. enumerable: true,
  6734. configurable: true
  6735. });
  6736. Object.defineProperty(InstanceDataBase.prototype, "opacity", {
  6737. get: function () {
  6738. return null;
  6739. },
  6740. set: function (value) {
  6741. },
  6742. enumerable: true,
  6743. configurable: true
  6744. });
  6745. InstanceDataBase.prototype.getClassTreeInfo = function () {
  6746. if (!this.typeInfo) {
  6747. this.typeInfo = BABYLON.ClassTreeInfo.get(Object.getPrototypeOf(this));
  6748. }
  6749. return this.typeInfo;
  6750. };
  6751. InstanceDataBase.prototype.allocElements = function () {
  6752. if (!this.dataBuffer || this.dataElements) {
  6753. return;
  6754. }
  6755. var res = new Array(this.dataElementCount);
  6756. for (var i = 0; i < this.dataElementCount; i++) {
  6757. res[i] = this.dataBuffer.allocElement();
  6758. }
  6759. this.dataElements = res;
  6760. };
  6761. InstanceDataBase.prototype.freeElements = function () {
  6762. if (!this.dataElements) {
  6763. return;
  6764. }
  6765. for (var _i = 0, _a = this.dataElements; _i < _a.length; _i++) {
  6766. var ei = _a[_i];
  6767. this.dataBuffer.freeElement(ei);
  6768. }
  6769. this.dataElements = null;
  6770. };
  6771. Object.defineProperty(InstanceDataBase.prototype, "dataElementCount", {
  6772. get: function () {
  6773. return this._dataElementCount;
  6774. },
  6775. set: function (value) {
  6776. if (value === this._dataElementCount) {
  6777. return;
  6778. }
  6779. this.arrayLengthChanged = true;
  6780. this.freeElements();
  6781. this._dataElementCount = value;
  6782. this.allocElements();
  6783. },
  6784. enumerable: true,
  6785. configurable: true
  6786. });
  6787. __decorate([
  6788. instanceData()
  6789. ], InstanceDataBase.prototype, "zBias", null);
  6790. __decorate([
  6791. instanceData()
  6792. ], InstanceDataBase.prototype, "transformX", null);
  6793. __decorate([
  6794. instanceData()
  6795. ], InstanceDataBase.prototype, "transformY", null);
  6796. __decorate([
  6797. instanceData()
  6798. ], InstanceDataBase.prototype, "opacity", null);
  6799. return InstanceDataBase;
  6800. }());
  6801. BABYLON.InstanceDataBase = InstanceDataBase;
  6802. var RenderablePrim2D = (function (_super) {
  6803. __extends(RenderablePrim2D, _super);
  6804. function RenderablePrim2D(settings) {
  6805. _super.call(this, settings);
  6806. this._transparentPrimitiveInfo = null;
  6807. }
  6808. Object.defineProperty(RenderablePrim2D.prototype, "isAlphaTest", {
  6809. get: function () {
  6810. return this._useTextureAlpha() || this._isPrimAlphaTest();
  6811. },
  6812. enumerable: true,
  6813. configurable: true
  6814. });
  6815. Object.defineProperty(RenderablePrim2D.prototype, "isTransparent", {
  6816. get: function () {
  6817. return (this.actualOpacity < 1) || this._shouldUseAlphaFromTexture() || this._isPrimTransparent();
  6818. },
  6819. enumerable: true,
  6820. configurable: true
  6821. });
  6822. Object.defineProperty(RenderablePrim2D.prototype, "renderMode", {
  6823. get: function () {
  6824. return this._renderMode;
  6825. },
  6826. enumerable: true,
  6827. configurable: true
  6828. });
  6829. /**
  6830. * Dispose the primitive and its resources, remove it from its parent
  6831. */
  6832. RenderablePrim2D.prototype.dispose = function () {
  6833. if (!_super.prototype.dispose.call(this)) {
  6834. return false;
  6835. }
  6836. if (this.renderGroup) {
  6837. this.renderGroup._setCacheGroupDirty();
  6838. }
  6839. if (this._transparentPrimitiveInfo) {
  6840. this.renderGroup._renderableData.removeTransparentPrimitiveInfo(this._transparentPrimitiveInfo);
  6841. this._transparentPrimitiveInfo = null;
  6842. }
  6843. if (this._instanceDataParts) {
  6844. this._cleanupInstanceDataParts();
  6845. }
  6846. if (this._modelRenderCache) {
  6847. this._modelRenderCache.dispose();
  6848. this._modelRenderCache = null;
  6849. }
  6850. if (this._instanceDataParts) {
  6851. this._instanceDataParts.forEach(function (p) {
  6852. p.freeElements();
  6853. });
  6854. this._instanceDataParts = null;
  6855. }
  6856. return true;
  6857. };
  6858. RenderablePrim2D.prototype._cleanupInstanceDataParts = function () {
  6859. var gii = null;
  6860. for (var _i = 0, _a = this._instanceDataParts; _i < _a.length; _i++) {
  6861. var part = _a[_i];
  6862. part.freeElements();
  6863. gii = part.groupInstanceInfo;
  6864. }
  6865. if (gii) {
  6866. var usedCount = 0;
  6867. if (gii.hasOpaqueData) {
  6868. var od = gii.opaqueData[0];
  6869. usedCount += od._partData.usedElementCount;
  6870. gii.opaqueDirty = true;
  6871. }
  6872. if (gii.hasAlphaTestData) {
  6873. var atd = gii.alphaTestData[0];
  6874. usedCount += atd._partData.usedElementCount;
  6875. gii.alphaTestDirty = true;
  6876. }
  6877. if (gii.hasTransparentData) {
  6878. var td = gii.transparentData[0];
  6879. usedCount += td._partData.usedElementCount;
  6880. gii.transparentDirty = true;
  6881. }
  6882. if (usedCount === 0 && gii.modelRenderCache != null) {
  6883. this.renderGroup._renderableData._renderGroupInstancesInfo.remove(gii.modelRenderCache.modelKey);
  6884. gii.dispose();
  6885. }
  6886. if (this._modelRenderCache) {
  6887. this._modelRenderCache.dispose();
  6888. this._modelRenderCache = null;
  6889. }
  6890. }
  6891. this._instanceDataParts = null;
  6892. };
  6893. RenderablePrim2D.prototype._prepareRenderPre = function (context) {
  6894. _super.prototype._prepareRenderPre.call(this, context);
  6895. // If the model changed and we have already an instance, we must remove this instance from the obsolete model
  6896. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagModelDirty) && this._instanceDataParts) {
  6897. this._cleanupInstanceDataParts();
  6898. }
  6899. // Need to create the model?
  6900. var setupModelRenderCache = false;
  6901. if (!this._modelRenderCache || this._isFlagSet(BABYLON.SmartPropertyPrim.flagModelDirty)) {
  6902. setupModelRenderCache = this._createModelRenderCache();
  6903. }
  6904. var gii = null;
  6905. var newInstance = false;
  6906. // Need to create the instance data parts?
  6907. if (!this._instanceDataParts) {
  6908. // Yes, flag it for later, more processing will have to be done
  6909. newInstance = true;
  6910. gii = this._createModelDataParts();
  6911. }
  6912. // If the ModelRenderCache is brand new, now is the time to call the implementation's specific setup method to create the rendering resources
  6913. if (setupModelRenderCache) {
  6914. this.setupModelRenderCache(this._modelRenderCache);
  6915. }
  6916. // 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.
  6917. // 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.
  6918. if (this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagVisibilityChanged | BABYLON.SmartPropertyPrim.flagNeedRefresh) || context.forceRefreshPrimitive || newInstance || (this._instanceDirtyFlags !== 0) || (this._globalTransformProcessStep !== this._globalTransformStep) || this._mustUpdateInstance()) {
  6919. this._updateInstanceDataParts(gii);
  6920. }
  6921. };
  6922. RenderablePrim2D.prototype._createModelRenderCache = function () {
  6923. var _this = this;
  6924. var setupModelRenderCache = false;
  6925. if (this._modelRenderCache) {
  6926. this._modelRenderCache.dispose();
  6927. }
  6928. this._modelRenderCache = this.owner._engineData.GetOrAddModelCache(this.modelKey, function (key) {
  6929. var mrc = _this.createModelRenderCache(key);
  6930. setupModelRenderCache = true;
  6931. return mrc;
  6932. });
  6933. this._clearFlags(BABYLON.SmartPropertyPrim.flagModelDirty);
  6934. // if this is still false it means the MRC already exists, so we add a reference to it
  6935. if (!setupModelRenderCache) {
  6936. this._modelRenderCache.addRef();
  6937. }
  6938. return setupModelRenderCache;
  6939. };
  6940. RenderablePrim2D.prototype._createModelDataParts = function () {
  6941. var _this = this;
  6942. // Create the instance data parts of the primitive and store them
  6943. var parts = this.createInstanceDataParts();
  6944. this._instanceDataParts = parts;
  6945. // Check if the ModelRenderCache for this particular instance is also brand new, initialize it if it's the case
  6946. if (!this._modelRenderCache._partData) {
  6947. this._setupModelRenderCache(parts);
  6948. }
  6949. // The Rendering resources (Effect, VB, IB, Textures) are stored in the ModelRenderCache
  6950. // But it's the RenderGroup that will store all the Instanced related data to render all the primitive it owns.
  6951. // So for a given ModelKey we getOrAdd a GroupInstanceInfo that will store all these data
  6952. var gii = this.renderGroup._renderableData._renderGroupInstancesInfo.getOrAddWithFactory(this.modelKey, function (k) {
  6953. var res = new BABYLON.GroupInstanceInfo(_this.renderGroup, _this._modelRenderCache, _this._modelRenderCache._partData.length);
  6954. for (var j = 0; j < _this._modelRenderCache._partData.length; j++) {
  6955. var part = _this._instanceDataParts[j];
  6956. res.partIndexFromId.add(part.id.toString(), j);
  6957. res.usedShaderCategories[j] = ";" + _this.getUsedShaderCategories(part).join(";") + ";";
  6958. res.strides[j] = _this._modelRenderCache._partData[j]._partDataStride;
  6959. }
  6960. return res;
  6961. });
  6962. // Get the GroupInfoDataPart corresponding to the render category of the part
  6963. var rm = 0;
  6964. var gipd = null;
  6965. if (this.isTransparent) {
  6966. gipd = gii.transparentData;
  6967. rm = BABYLON.Render2DContext.RenderModeTransparent;
  6968. }
  6969. else if (this.isAlphaTest) {
  6970. gipd = gii.alphaTestData;
  6971. rm = BABYLON.Render2DContext.RenderModeAlphaTest;
  6972. }
  6973. else {
  6974. gipd = gii.opaqueData;
  6975. rm = BABYLON.Render2DContext.RenderModeOpaque;
  6976. }
  6977. // For each instance data part of the primitive, allocate the instanced element it needs for render
  6978. for (var i = 0; i < parts.length; i++) {
  6979. var part = parts[i];
  6980. part.dataBuffer = gipd[i]._partData;
  6981. part.allocElements();
  6982. part.renderMode = rm;
  6983. part.groupInstanceInfo = gii;
  6984. }
  6985. return gii;
  6986. };
  6987. RenderablePrim2D.prototype._setupModelRenderCache = function (parts) {
  6988. var ctiArray = new Array();
  6989. this._modelRenderCache._partData = new Array();
  6990. for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
  6991. var dataPart = parts_1[_i];
  6992. var pd = new BABYLON.ModelRenderCachePartData();
  6993. this._modelRenderCache._partData.push(pd);
  6994. var cat = this.getUsedShaderCategories(dataPart);
  6995. var cti = dataPart.getClassTreeInfo();
  6996. // Make sure the instance is visible other the properties won't be set and their size/offset wont be computed
  6997. var curVisible = this.isVisible;
  6998. this.isVisible = true;
  6999. // 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.
  7000. //console.log("Build Prop Layout for " + Tools.getClassName(this._instanceDataParts[0]));
  7001. var joinCat = ";" + cat.join(";") + ";";
  7002. pd._partJoinedUsedCategories = joinCat;
  7003. InstanceClassInfo._CurCategories = joinCat;
  7004. var obj = this.beforeRefreshForLayoutConstruction(dataPart);
  7005. if (!this.refreshInstanceDataPart(dataPart)) {
  7006. console.log("Layout construction for " + BABYLON.Tools.getClassName(this._instanceDataParts[0]) + " failed because refresh returned false");
  7007. }
  7008. this.afterRefreshForLayoutConstruction(dataPart, obj);
  7009. this.isVisible = curVisible;
  7010. var size = 0;
  7011. cti.fullContent.forEach(function (k, v) {
  7012. if (!v.category || cat.indexOf(v.category) !== -1) {
  7013. if (v.attributeName === "zBias") {
  7014. pd._zBiasOffset = v.instanceOffset.get(joinCat);
  7015. }
  7016. if (!v.size) {
  7017. console.log("ERROR: Couldn't detect the size of the Property " + v.attributeName + " from type " + BABYLON.Tools.getClassName(cti.type) + ". Property is ignored.");
  7018. }
  7019. else {
  7020. size += v.size;
  7021. }
  7022. }
  7023. });
  7024. pd._partDataStride = size;
  7025. pd._partUsedCategories = cat;
  7026. pd._partId = dataPart.id;
  7027. ctiArray.push(cti);
  7028. }
  7029. this._modelRenderCache._partsClassInfo = ctiArray;
  7030. };
  7031. RenderablePrim2D.prototype.onZOrderChanged = function () {
  7032. if (this.isTransparent && this._transparentPrimitiveInfo) {
  7033. this.renderGroup._renderableData.transparentPrimitiveZChanged(this._transparentPrimitiveInfo);
  7034. var gii = this.renderGroup._renderableData._renderGroupInstancesInfo.get(this.modelKey);
  7035. // Flag the transparentData dirty has will have to sort it again
  7036. gii.transparentOrderDirty = true;
  7037. }
  7038. };
  7039. RenderablePrim2D.prototype._mustUpdateInstance = function () {
  7040. return false;
  7041. };
  7042. RenderablePrim2D.prototype._useTextureAlpha = function () {
  7043. return false;
  7044. };
  7045. RenderablePrim2D.prototype._shouldUseAlphaFromTexture = function () {
  7046. return false;
  7047. };
  7048. RenderablePrim2D.prototype._isPrimAlphaTest = function () {
  7049. return false;
  7050. };
  7051. RenderablePrim2D.prototype._isPrimTransparent = function () {
  7052. return false;
  7053. };
  7054. RenderablePrim2D.prototype._updateInstanceDataParts = function (gii) {
  7055. // Fetch the GroupInstanceInfo if we don't already have it
  7056. var rd = this.renderGroup._renderableData;
  7057. if (!gii) {
  7058. gii = rd._renderGroupInstancesInfo.get(this.modelKey);
  7059. }
  7060. var isTransparent = this.isTransparent;
  7061. var isAlphaTest = this.isAlphaTest;
  7062. var wereTransparent = false;
  7063. // Check a render mode change
  7064. var rmChanged = false;
  7065. if (this._instanceDataParts.length > 0) {
  7066. var firstPart = this._instanceDataParts[0];
  7067. var partRM = firstPart.renderMode;
  7068. var curRM = this.renderMode;
  7069. if (partRM !== curRM) {
  7070. wereTransparent = partRM === BABYLON.Render2DContext.RenderModeTransparent;
  7071. rmChanged = true;
  7072. var gipd = void 0;
  7073. switch (curRM) {
  7074. case BABYLON.Render2DContext.RenderModeTransparent:
  7075. gipd = gii.transparentData;
  7076. break;
  7077. case BABYLON.Render2DContext.RenderModeAlphaTest:
  7078. gipd = gii.alphaTestData;
  7079. break;
  7080. default:
  7081. gipd = gii.opaqueData;
  7082. }
  7083. for (var i = 0; i < this._instanceDataParts.length; i++) {
  7084. var part = this._instanceDataParts[i];
  7085. part.freeElements();
  7086. part.dataBuffer = gipd[i]._partData;
  7087. part.renderMode = curRM;
  7088. }
  7089. }
  7090. }
  7091. // Handle changes related to ZOffset
  7092. var visChanged = this._isFlagSet(BABYLON.SmartPropertyPrim.flagVisibilityChanged);
  7093. if (isTransparent || wereTransparent) {
  7094. // Handle visibility change, which is also triggered when the primitive just got created
  7095. if (visChanged || rmChanged) {
  7096. if (this.isVisible && !wereTransparent) {
  7097. if (!this._transparentPrimitiveInfo) {
  7098. // Add the primitive to the list of transparent ones in the group that render is
  7099. this._transparentPrimitiveInfo = rd.addNewTransparentPrimitiveInfo(this, gii);
  7100. }
  7101. }
  7102. else {
  7103. if (this._transparentPrimitiveInfo) {
  7104. rd.removeTransparentPrimitiveInfo(this._transparentPrimitiveInfo);
  7105. this._transparentPrimitiveInfo = null;
  7106. }
  7107. }
  7108. gii.transparentOrderDirty = true;
  7109. }
  7110. }
  7111. var rebuildTrans = false;
  7112. // For each Instance Data part, refresh it to update the data in the DynamicFloatArray
  7113. for (var _i = 0, _a = this._instanceDataParts; _i < _a.length; _i++) {
  7114. var part = _a[_i];
  7115. var justAllocated = false;
  7116. // Check if we need to allocate data elements (hidden prim which becomes visible again)
  7117. if (!part.dataElements && (visChanged || rmChanged || this.isVisible)) {
  7118. part.allocElements();
  7119. justAllocated = true;
  7120. }
  7121. InstanceClassInfo._CurCategories = gii.usedShaderCategories[gii.partIndexFromId.get(part.id.toString())];
  7122. // Will return false if the instance should not be rendered (not visible or other any reasons)
  7123. part.arrayLengthChanged = false;
  7124. if (!this.refreshInstanceDataPart(part)) {
  7125. // Free the data element
  7126. if (part.dataElements) {
  7127. part.freeElements();
  7128. }
  7129. // The refresh couldn't succeed, push the primitive to be dirty again for the next render
  7130. if (this.isVisible) {
  7131. rd._primNewDirtyList.push(this);
  7132. }
  7133. }
  7134. rebuildTrans = rebuildTrans || part.arrayLengthChanged || justAllocated;
  7135. }
  7136. this._instanceDirtyFlags = 0;
  7137. // Make the appropriate data dirty
  7138. if (isTransparent) {
  7139. gii.transparentDirty = true;
  7140. if (rebuildTrans) {
  7141. rd._transparentListChanged = true;
  7142. }
  7143. }
  7144. else if (isAlphaTest) {
  7145. gii.alphaTestDirty = true;
  7146. }
  7147. else {
  7148. gii.opaqueDirty = true;
  7149. }
  7150. this._clearFlags(BABYLON.SmartPropertyPrim.flagVisibilityChanged); // Reset the flag as we've handled the case
  7151. };
  7152. RenderablePrim2D.prototype._updateTransparentSegmentIndices = function (ts) {
  7153. var minOff = BABYLON.Prim2DBase._bigInt;
  7154. var maxOff = 0;
  7155. for (var _i = 0, _a = this._instanceDataParts; _i < _a.length; _i++) {
  7156. var part = _a[_i];
  7157. if (part && part.dataElements) {
  7158. part.dataBuffer.pack();
  7159. for (var _b = 0, _c = part.dataElements; _b < _c.length; _b++) {
  7160. var el = _c[_b];
  7161. minOff = Math.min(minOff, el.offset);
  7162. maxOff = Math.max(maxOff, el.offset);
  7163. }
  7164. ts.startDataIndex = Math.min(ts.startDataIndex, minOff / part.dataBuffer.stride);
  7165. ts.endDataIndex = Math.max(ts.endDataIndex, (maxOff / part.dataBuffer.stride) + 1); // +1 for exclusive
  7166. }
  7167. }
  7168. };
  7169. // This internal method is mainly used for transparency processing
  7170. RenderablePrim2D.prototype._getNextPrimZOrder = function () {
  7171. var length = this._instanceDataParts.length;
  7172. for (var i = 0; i < length; i++) {
  7173. var part = this._instanceDataParts[i];
  7174. if (part) {
  7175. var stride = part.dataBuffer.stride;
  7176. var lastElementOffset = part.dataElements[part.dataElements.length - 1].offset;
  7177. // check if it's the last in the DFA
  7178. if (part.dataBuffer.totalElementCount * stride <= lastElementOffset) {
  7179. return null;
  7180. }
  7181. // Return the Z of the next primitive that lies in the DFA
  7182. return part.dataBuffer[lastElementOffset + stride + this.modelRenderCache._partData[i]._zBiasOffset];
  7183. }
  7184. }
  7185. return null;
  7186. };
  7187. // This internal method is mainly used for transparency processing
  7188. RenderablePrim2D.prototype._getPrevPrimZOrder = 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 firstElementOffset = part.dataElements[0].offset;
  7195. // check if it's the first in the DFA
  7196. if (firstElementOffset === 0) {
  7197. return null;
  7198. }
  7199. // Return the Z of the previous primitive that lies in the DFA
  7200. return part.dataBuffer[firstElementOffset - stride + this.modelRenderCache._partData[i]._zBiasOffset];
  7201. }
  7202. }
  7203. return null;
  7204. };
  7205. /**
  7206. * Transform a given point using the Primitive's origin setting.
  7207. * This method requires the Primitive's actualSize to be accurate
  7208. * @param p the point to transform
  7209. * @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.
  7210. * @param res an allocated Vector2 that will receive the transformed content
  7211. */
  7212. RenderablePrim2D.prototype.transformPointWithOriginByRef = function (p, originOffset, res) {
  7213. var actualSize = this.actualSize;
  7214. res.x = p.x - ((this.origin.x + (originOffset ? originOffset.x : 0)) * actualSize.width);
  7215. res.y = p.y - ((this.origin.y + (originOffset ? originOffset.y : 0)) * actualSize.height);
  7216. };
  7217. RenderablePrim2D.prototype.transformPointWithOriginToRef = function (p, originOffset, res) {
  7218. this.transformPointWithOriginByRef(p, originOffset, res);
  7219. return res;
  7220. };
  7221. /**
  7222. * Get the info for a given effect based on the dataPart metadata
  7223. * @param dataPartId partId in part list to get the info
  7224. * @param vertexBufferAttributes vertex buffer attributes to manually add
  7225. * @param uniforms uniforms to manually add
  7226. * @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
  7227. */
  7228. RenderablePrim2D.prototype.getDataPartEffectInfo = function (dataPartId, vertexBufferAttributes, uniforms, useInstanced) {
  7229. if (uniforms === void 0) { uniforms = null; }
  7230. if (useInstanced === void 0) { useInstanced = null; }
  7231. var dataPart = BABYLON.Tools.first(this._instanceDataParts, function (i) { return i.id === dataPartId; });
  7232. if (!dataPart) {
  7233. return null;
  7234. }
  7235. var instancedArray = this.owner.supportInstancedArray;
  7236. if (useInstanced != null) {
  7237. // Check if the caller ask for Instanced Array and the engine does not support it, return null if it's the case
  7238. if (useInstanced && instancedArray === false) {
  7239. return null;
  7240. }
  7241. // Use the caller's setting
  7242. instancedArray = useInstanced;
  7243. }
  7244. var cti = dataPart.getClassTreeInfo();
  7245. var categories = this.getUsedShaderCategories(dataPart);
  7246. var att = cti.classContent.getShaderAttributes(categories);
  7247. var defines = "";
  7248. categories.forEach(function (c) { defines += "#define " + c + "\n"; });
  7249. if (instancedArray) {
  7250. defines += "#define Instanced\n";
  7251. }
  7252. return {
  7253. attributes: instancedArray ? vertexBufferAttributes.concat(att) : vertexBufferAttributes,
  7254. uniforms: instancedArray ? (uniforms != null ? uniforms : []) : ((uniforms != null) ? att.concat(uniforms) : (att != null ? att : [])),
  7255. defines: defines
  7256. };
  7257. };
  7258. Object.defineProperty(RenderablePrim2D.prototype, "modelRenderCache", {
  7259. get: function () {
  7260. return this._modelRenderCache;
  7261. },
  7262. enumerable: true,
  7263. configurable: true
  7264. });
  7265. RenderablePrim2D.prototype.createModelRenderCache = function (modelKey) {
  7266. return null;
  7267. };
  7268. RenderablePrim2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  7269. };
  7270. RenderablePrim2D.prototype.createInstanceDataParts = function () {
  7271. return null;
  7272. };
  7273. RenderablePrim2D.prototype.getUsedShaderCategories = function (dataPart) {
  7274. return [];
  7275. };
  7276. RenderablePrim2D.prototype.beforeRefreshForLayoutConstruction = function (part) {
  7277. };
  7278. RenderablePrim2D.prototype.afterRefreshForLayoutConstruction = function (part, obj) {
  7279. };
  7280. RenderablePrim2D.prototype.applyActualScaleOnTransform = function () {
  7281. return true;
  7282. };
  7283. RenderablePrim2D.prototype.refreshInstanceDataPart = function (part) {
  7284. if (!this.isVisible) {
  7285. return false;
  7286. }
  7287. part.isVisible = this.isVisible;
  7288. // 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)
  7289. if (part.dataElementCount === 1) {
  7290. part.curElement = 0;
  7291. this.updateInstanceDataPart(part);
  7292. }
  7293. return true;
  7294. };
  7295. /**
  7296. * Update the instanceDataBase level properties of a part
  7297. * @param part the part to update
  7298. * @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).
  7299. */
  7300. RenderablePrim2D.prototype.updateInstanceDataPart = function (part, positionOffset) {
  7301. if (positionOffset === void 0) { positionOffset = null; }
  7302. var t = this._globalTransform.multiply(this.renderGroup.invGlobalTransform); // Compute the transformation into the renderGroup's space
  7303. var rgScale = this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagDontInheritParentScale) ? RenderablePrim2D._uV : this.renderGroup.actualScale; // We still need to apply the scale of the renderGroup to our rendering, so get it.
  7304. var size = this.renderGroup.viewportSize;
  7305. var zBias = this.actualZOffset;
  7306. var offX = 0;
  7307. var offY = 0;
  7308. // If there's an offset, apply the global transformation matrix on it to get a global offset
  7309. if (positionOffset) {
  7310. offX = positionOffset.x * t.m[0] + positionOffset.y * t.m[4];
  7311. offY = positionOffset.x * t.m[1] + positionOffset.y * t.m[5];
  7312. }
  7313. // 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
  7314. // Current coordinates are expressed in renderGroup coordinates ([0, renderGroup.actualSize.width|height]) with 0,0 being at the left/top corner
  7315. // So for X:
  7316. // - tx.x = value * 2 / width: is to switch from [0, renderGroup.width] to [0, 2]
  7317. // - 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].
  7318. // At last we don't forget to apply the actualScale of the Render Group to tx[0] and ty[1] to propagate scaling correctly
  7319. var w = size.width;
  7320. var h = size.height;
  7321. var invZBias = 1 / zBias;
  7322. 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);
  7323. 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);
  7324. if (!this.applyActualScaleOnTransform()) {
  7325. var las = this.actualScale;
  7326. tx.x /= las.x;
  7327. ty.y /= las.y;
  7328. }
  7329. part.transformX = tx;
  7330. part.transformY = ty;
  7331. part.opacity = this.actualOpacity;
  7332. // 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)
  7333. part.zBias = new BABYLON.Vector2(zBias, invZBias);
  7334. };
  7335. RenderablePrim2D.prototype._updateRenderMode = function () {
  7336. if (this.isTransparent) {
  7337. this._renderMode = BABYLON.Render2DContext.RenderModeTransparent;
  7338. }
  7339. else if (this.isAlphaTest) {
  7340. this._renderMode = BABYLON.Render2DContext.RenderModeAlphaTest;
  7341. }
  7342. else {
  7343. this._renderMode = BABYLON.Render2DContext.RenderModeOpaque;
  7344. }
  7345. };
  7346. RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT = BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 5;
  7347. RenderablePrim2D._uV = new BABYLON.Vector2(1, 1);
  7348. __decorate([
  7349. BABYLON.dynamicLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 0, function (pi) { return RenderablePrim2D.isAlphaTestProperty = pi; })
  7350. ], RenderablePrim2D.prototype, "isAlphaTest", null);
  7351. __decorate([
  7352. BABYLON.dynamicLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 1, function (pi) { return RenderablePrim2D.isTransparentProperty = pi; })
  7353. ], RenderablePrim2D.prototype, "isTransparent", null);
  7354. RenderablePrim2D = __decorate([
  7355. BABYLON.className("RenderablePrim2D", "BABYLON")
  7356. ], RenderablePrim2D);
  7357. return RenderablePrim2D;
  7358. }(BABYLON.Prim2DBase));
  7359. BABYLON.RenderablePrim2D = RenderablePrim2D;
  7360. })(BABYLON || (BABYLON = {}));
  7361. //# sourceMappingURL=babylon.renderablePrim2d.js.map
  7362. var __extends = (this && this.__extends) || function (d, b) {
  7363. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  7364. function __() { this.constructor = d; }
  7365. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7366. };
  7367. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  7368. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  7369. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  7370. 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;
  7371. return c > 3 && r && Object.defineProperty(target, key, r), r;
  7372. };
  7373. var BABYLON;
  7374. (function (BABYLON) {
  7375. var Shape2D = (function (_super) {
  7376. __extends(Shape2D, _super);
  7377. function Shape2D(settings) {
  7378. _super.call(this, settings);
  7379. if (!settings) {
  7380. settings = {};
  7381. }
  7382. var borderBrush = null;
  7383. if (settings.border) {
  7384. if (typeof (settings.border) === "string") {
  7385. borderBrush = BABYLON.Canvas2D.GetBrushFromString(settings.border);
  7386. }
  7387. else {
  7388. borderBrush = settings.border;
  7389. }
  7390. }
  7391. var fillBrush = null;
  7392. if (settings.fill) {
  7393. if (typeof (settings.fill) === "string") {
  7394. fillBrush = BABYLON.Canvas2D.GetBrushFromString(settings.fill);
  7395. }
  7396. else {
  7397. fillBrush = settings.fill;
  7398. }
  7399. }
  7400. this._isTransparent = false;
  7401. this._oldTransparent = false;
  7402. this.border = borderBrush;
  7403. this.fill = fillBrush;
  7404. this._updateTransparencyStatus();
  7405. this.borderThickness = settings.borderThickness;
  7406. }
  7407. Object.defineProperty(Shape2D.prototype, "border", {
  7408. get: function () {
  7409. return this._border;
  7410. },
  7411. set: function (value) {
  7412. this._border = value;
  7413. this._updateTransparencyStatus();
  7414. },
  7415. enumerable: true,
  7416. configurable: true
  7417. });
  7418. Object.defineProperty(Shape2D.prototype, "fill", {
  7419. /**
  7420. * Get/set the brush to render the Fill part of the Primitive
  7421. */
  7422. get: function () {
  7423. return this._fill;
  7424. },
  7425. set: function (value) {
  7426. this._fill = value;
  7427. this._updateTransparencyStatus();
  7428. },
  7429. enumerable: true,
  7430. configurable: true
  7431. });
  7432. Object.defineProperty(Shape2D.prototype, "borderThickness", {
  7433. get: function () {
  7434. return this._borderThickness;
  7435. },
  7436. set: function (value) {
  7437. this._borderThickness = value;
  7438. },
  7439. enumerable: true,
  7440. configurable: true
  7441. });
  7442. Shape2D.prototype.getUsedShaderCategories = function (dataPart) {
  7443. var cat = _super.prototype.getUsedShaderCategories.call(this, dataPart);
  7444. // Fill Part
  7445. if (dataPart.id === Shape2D.SHAPE2D_FILLPARTID) {
  7446. var fill = this.fill;
  7447. if (fill instanceof BABYLON.SolidColorBrush2D) {
  7448. cat.push(Shape2D.SHAPE2D_CATEGORY_FILLSOLID);
  7449. }
  7450. if (fill instanceof BABYLON.GradientColorBrush2D) {
  7451. cat.push(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT);
  7452. }
  7453. }
  7454. // Border Part
  7455. if (dataPart.id === Shape2D.SHAPE2D_BORDERPARTID) {
  7456. cat.push(Shape2D.SHAPE2D_CATEGORY_BORDER);
  7457. var border = this.border;
  7458. if (border instanceof BABYLON.SolidColorBrush2D) {
  7459. cat.push(Shape2D.SHAPE2D_CATEGORY_BORDERSOLID);
  7460. }
  7461. if (border instanceof BABYLON.GradientColorBrush2D) {
  7462. cat.push(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT);
  7463. }
  7464. }
  7465. return cat;
  7466. };
  7467. Shape2D.prototype.applyActualScaleOnTransform = function () {
  7468. return false;
  7469. };
  7470. Shape2D.prototype.refreshInstanceDataPart = function (part) {
  7471. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  7472. return false;
  7473. }
  7474. // Fill Part
  7475. if (part.id === Shape2D.SHAPE2D_FILLPARTID) {
  7476. var d = part;
  7477. if (this.fill) {
  7478. var fill = this.fill;
  7479. if (fill instanceof BABYLON.SolidColorBrush2D) {
  7480. d.fillSolidColor = fill.color;
  7481. }
  7482. else if (fill instanceof BABYLON.GradientColorBrush2D) {
  7483. d.fillGradientColor1 = fill.color1;
  7484. d.fillGradientColor2 = fill.color2;
  7485. 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));
  7486. var ty = new BABYLON.Vector4(t.m[1], t.m[5], t.m[9], t.m[13]);
  7487. d.fillGradientTY = ty;
  7488. }
  7489. }
  7490. }
  7491. else if (part.id === Shape2D.SHAPE2D_BORDERPARTID) {
  7492. var d = part;
  7493. if (this.border) {
  7494. d.borderThickness = this.borderThickness;
  7495. var border = this.border;
  7496. if (border instanceof BABYLON.SolidColorBrush2D) {
  7497. d.borderSolidColor = border.color;
  7498. }
  7499. else if (border instanceof BABYLON.GradientColorBrush2D) {
  7500. d.borderGradientColor1 = border.color1;
  7501. d.borderGradientColor2 = border.color2;
  7502. 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));
  7503. var ty = new BABYLON.Vector4(t.m[1], t.m[5], t.m[9], t.m[13]);
  7504. d.borderGradientTY = ty;
  7505. }
  7506. }
  7507. }
  7508. return true;
  7509. };
  7510. Shape2D.prototype._updateTransparencyStatus = function () {
  7511. this._isTransparent = (this._border && this._border.isTransparent()) || (this._fill && this._fill.isTransparent()) || (this.actualOpacity < 1);
  7512. if (this._isTransparent !== this._oldTransparent) {
  7513. this._oldTransparent = this._isTransparent;
  7514. this._updateRenderMode();
  7515. }
  7516. };
  7517. Shape2D.prototype._mustUpdateInstance = function () {
  7518. var res = this._oldTransparent !== this._isTransparent;
  7519. if (res) {
  7520. this._updateRenderMode();
  7521. this._oldTransparent = this._isTransparent;
  7522. }
  7523. return res;
  7524. };
  7525. Shape2D.prototype._isPrimTransparent = function () {
  7526. return this._isTransparent;
  7527. };
  7528. Shape2D.SHAPE2D_BORDERPARTID = 1;
  7529. Shape2D.SHAPE2D_FILLPARTID = 2;
  7530. Shape2D.SHAPE2D_CATEGORY_BORDER = "Border";
  7531. Shape2D.SHAPE2D_CATEGORY_BORDERSOLID = "BorderSolid";
  7532. Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT = "BorderGradient";
  7533. Shape2D.SHAPE2D_CATEGORY_FILLSOLID = "FillSolid";
  7534. Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT = "FillGradient";
  7535. Shape2D.SHAPE2D_PROPCOUNT = BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 5;
  7536. __decorate([
  7537. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 1, function (pi) { return Shape2D.borderProperty = pi; }, true)
  7538. ], Shape2D.prototype, "border", null);
  7539. __decorate([
  7540. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 2, function (pi) { return Shape2D.fillProperty = pi; }, true)
  7541. ], Shape2D.prototype, "fill", null);
  7542. __decorate([
  7543. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 3, function (pi) { return Shape2D.borderThicknessProperty = pi; })
  7544. ], Shape2D.prototype, "borderThickness", null);
  7545. Shape2D = __decorate([
  7546. BABYLON.className("Shape2D", "BABYLON")
  7547. ], Shape2D);
  7548. return Shape2D;
  7549. }(BABYLON.RenderablePrim2D));
  7550. BABYLON.Shape2D = Shape2D;
  7551. var Shape2DInstanceData = (function (_super) {
  7552. __extends(Shape2DInstanceData, _super);
  7553. function Shape2DInstanceData() {
  7554. _super.apply(this, arguments);
  7555. }
  7556. Object.defineProperty(Shape2DInstanceData.prototype, "fillSolidColor", {
  7557. // FILL ATTRIBUTES
  7558. get: function () {
  7559. return null;
  7560. },
  7561. set: function (value) {
  7562. },
  7563. enumerable: true,
  7564. configurable: true
  7565. });
  7566. Object.defineProperty(Shape2DInstanceData.prototype, "fillGradientColor1", {
  7567. get: function () {
  7568. return null;
  7569. },
  7570. set: function (value) {
  7571. },
  7572. enumerable: true,
  7573. configurable: true
  7574. });
  7575. Object.defineProperty(Shape2DInstanceData.prototype, "fillGradientColor2", {
  7576. get: function () {
  7577. return null;
  7578. },
  7579. set: function (value) {
  7580. },
  7581. enumerable: true,
  7582. configurable: true
  7583. });
  7584. Object.defineProperty(Shape2DInstanceData.prototype, "fillGradientTY", {
  7585. get: function () {
  7586. return null;
  7587. },
  7588. set: function (value) {
  7589. },
  7590. enumerable: true,
  7591. configurable: true
  7592. });
  7593. Object.defineProperty(Shape2DInstanceData.prototype, "borderThickness", {
  7594. // BORDER ATTRIBUTES
  7595. get: function () {
  7596. return null;
  7597. },
  7598. set: function (value) {
  7599. },
  7600. enumerable: true,
  7601. configurable: true
  7602. });
  7603. Object.defineProperty(Shape2DInstanceData.prototype, "borderSolidColor", {
  7604. get: function () {
  7605. return null;
  7606. },
  7607. set: function (value) {
  7608. },
  7609. enumerable: true,
  7610. configurable: true
  7611. });
  7612. Object.defineProperty(Shape2DInstanceData.prototype, "borderGradientColor1", {
  7613. get: function () {
  7614. return null;
  7615. },
  7616. set: function (value) {
  7617. },
  7618. enumerable: true,
  7619. configurable: true
  7620. });
  7621. Object.defineProperty(Shape2DInstanceData.prototype, "borderGradientColor2", {
  7622. get: function () {
  7623. return null;
  7624. },
  7625. set: function (value) {
  7626. },
  7627. enumerable: true,
  7628. configurable: true
  7629. });
  7630. Object.defineProperty(Shape2DInstanceData.prototype, "borderGradientTY", {
  7631. get: function () {
  7632. return null;
  7633. },
  7634. set: function (value) {
  7635. },
  7636. enumerable: true,
  7637. configurable: true
  7638. });
  7639. __decorate([
  7640. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLSOLID)
  7641. ], Shape2DInstanceData.prototype, "fillSolidColor", null);
  7642. __decorate([
  7643. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  7644. ], Shape2DInstanceData.prototype, "fillGradientColor1", null);
  7645. __decorate([
  7646. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  7647. ], Shape2DInstanceData.prototype, "fillGradientColor2", null);
  7648. __decorate([
  7649. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  7650. ], Shape2DInstanceData.prototype, "fillGradientTY", null);
  7651. __decorate([
  7652. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDER)
  7653. ], Shape2DInstanceData.prototype, "borderThickness", null);
  7654. __decorate([
  7655. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERSOLID)
  7656. ], Shape2DInstanceData.prototype, "borderSolidColor", null);
  7657. __decorate([
  7658. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT)
  7659. ], Shape2DInstanceData.prototype, "borderGradientColor1", null);
  7660. __decorate([
  7661. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT)
  7662. ], Shape2DInstanceData.prototype, "borderGradientColor2", null);
  7663. __decorate([
  7664. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT)
  7665. ], Shape2DInstanceData.prototype, "borderGradientTY", null);
  7666. return Shape2DInstanceData;
  7667. }(BABYLON.InstanceDataBase));
  7668. BABYLON.Shape2DInstanceData = Shape2DInstanceData;
  7669. })(BABYLON || (BABYLON = {}));
  7670. //# sourceMappingURL=babylon.shape2d.js.map
  7671. var __extends = (this && this.__extends) || function (d, b) {
  7672. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  7673. function __() { this.constructor = d; }
  7674. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7675. };
  7676. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  7677. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  7678. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  7679. 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;
  7680. return c > 3 && r && Object.defineProperty(target, key, r), r;
  7681. };
  7682. var BABYLON;
  7683. (function (BABYLON) {
  7684. var Group2D = (function (_super) {
  7685. __extends(Group2D, _super);
  7686. /**
  7687. * Create an Logical or Renderable Group.
  7688. * @param settings a combination of settings, possible ones are
  7689. * - 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)
  7690. * - children: an array of direct children
  7691. * - id a text identifier, for information purpose
  7692. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  7693. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  7694. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  7695. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  7696. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  7697. * - zOrder: override the zOrder with the specified value
  7698. * - origin: define the normalized origin point location, default [0.5;0.5]
  7699. * - 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.
  7700. * - cacheBehavior: Define how the group should behave regarding the Canvas's cache strategy, default is Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY
  7701. * - 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).
  7702. * - isVisible: true if the group must be visible, false for hidden. Default is true.
  7703. * - 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.
  7704. * - 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.
  7705. * - 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!
  7706. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7707. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7708. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7709. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7710. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  7711. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  7712. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  7713. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  7714. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7715. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7716. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7717. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7718. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  7719. */
  7720. function Group2D(settings) {
  7721. if (settings == null) {
  7722. settings = {};
  7723. }
  7724. if (settings.origin == null) {
  7725. settings.origin = new BABYLON.Vector2(0, 0);
  7726. }
  7727. _super.call(this, settings);
  7728. var size = (!settings.size && !settings.width && !settings.height) ? null : (settings.size || (new BABYLON.Size(settings.width || 0, settings.height || 0)));
  7729. this._trackedNode = (settings.trackNode == null) ? null : settings.trackNode;
  7730. if (this._trackedNode && this.owner) {
  7731. this.owner._registerTrackedNode(this);
  7732. }
  7733. this._cacheBehavior = (settings.cacheBehavior == null) ? Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY : settings.cacheBehavior;
  7734. var rd = this._renderableData;
  7735. if (rd) {
  7736. rd._noResizeOnScale = (this.cacheBehavior & Group2D.GROUPCACHEBEHAVIOR_NORESIZEONSCALE) !== 0;
  7737. }
  7738. this.size = size;
  7739. this._viewportPosition = BABYLON.Vector2.Zero();
  7740. this._viewportSize = BABYLON.Size.Zero();
  7741. }
  7742. Group2D._createCachedCanvasGroup = function (owner) {
  7743. var g = new Group2D({ parent: owner, id: "__cachedCanvasGroup__", position: BABYLON.Vector2.Zero(), origin: BABYLON.Vector2.Zero(), size: null, isVisible: true, isPickable: false, dontInheritParentScale: true });
  7744. return g;
  7745. };
  7746. Group2D.prototype.applyCachedTexture = function (vertexData, material) {
  7747. this._bindCacheTarget();
  7748. if (vertexData) {
  7749. var uv = vertexData.uvs;
  7750. var nodeuv = this._renderableData._cacheNodeUVs;
  7751. for (var i = 0; i < 4; i++) {
  7752. uv[i * 2 + 0] = nodeuv[i].x;
  7753. uv[i * 2 + 1] = nodeuv[i].y;
  7754. }
  7755. }
  7756. if (material) {
  7757. material.diffuseTexture = this._renderableData._cacheTexture;
  7758. material.emissiveColor = new BABYLON.Color3(1, 1, 1);
  7759. }
  7760. this._renderableData._cacheTexture.hasAlpha = true;
  7761. this._unbindCacheTarget();
  7762. };
  7763. Object.defineProperty(Group2D.prototype, "cachedRect", {
  7764. /**
  7765. * Allow you to access the information regarding the cached rectangle of the Group2D into the MapTexture.
  7766. * 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.
  7767. */
  7768. get: function () {
  7769. if (!this._renderableData) {
  7770. return null;
  7771. }
  7772. return this._renderableData._cacheNode;
  7773. },
  7774. enumerable: true,
  7775. configurable: true
  7776. });
  7777. Object.defineProperty(Group2D.prototype, "cachedUVs", {
  7778. /**
  7779. * The UVs into the MapTexture that map the cached group
  7780. */
  7781. get: function () {
  7782. if (!this._renderableData) {
  7783. return null;
  7784. }
  7785. return this._renderableData._cacheNodeUVs;
  7786. },
  7787. enumerable: true,
  7788. configurable: true
  7789. });
  7790. Object.defineProperty(Group2D.prototype, "cachedUVsChanged", {
  7791. get: function () {
  7792. if (!this._renderableData) {
  7793. return null;
  7794. }
  7795. if (!this._renderableData._cacheNodeUVsChangedObservable) {
  7796. this._renderableData._cacheNodeUVsChangedObservable = new BABYLON.Observable();
  7797. }
  7798. return this._renderableData._cacheNodeUVsChangedObservable;
  7799. },
  7800. enumerable: true,
  7801. configurable: true
  7802. });
  7803. Object.defineProperty(Group2D.prototype, "cacheTexture", {
  7804. /**
  7805. * Access the texture that maintains a cached version of the Group2D.
  7806. * This is useful only if you're not using a WorldSpaceNode for your WorldSpace Canvas and therefore need to perform the rendering yourself.
  7807. */
  7808. get: function () {
  7809. if (!this._renderableData) {
  7810. return null;
  7811. }
  7812. return this._renderableData._cacheTexture;
  7813. },
  7814. enumerable: true,
  7815. configurable: true
  7816. });
  7817. /**
  7818. * Call this method to remove this Group and its children from the Canvas
  7819. */
  7820. Group2D.prototype.dispose = function () {
  7821. if (!_super.prototype.dispose.call(this)) {
  7822. return false;
  7823. }
  7824. if (this._trackedNode != null) {
  7825. this.owner._unregisterTrackedNode(this);
  7826. this._trackedNode = null;
  7827. }
  7828. if (this._renderableData) {
  7829. this._renderableData.dispose(this.owner);
  7830. this._renderableData = null;
  7831. }
  7832. return true;
  7833. };
  7834. Object.defineProperty(Group2D.prototype, "isRenderableGroup", {
  7835. /**
  7836. * @returns Returns true if the Group render content, false if it's a logical group only
  7837. */
  7838. get: function () {
  7839. return this._isRenderableGroup;
  7840. },
  7841. enumerable: true,
  7842. configurable: true
  7843. });
  7844. Object.defineProperty(Group2D.prototype, "isCachedGroup", {
  7845. /**
  7846. * @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
  7847. */
  7848. get: function () {
  7849. return this._isCachedGroup;
  7850. },
  7851. enumerable: true,
  7852. configurable: true
  7853. });
  7854. Object.defineProperty(Group2D.prototype, "size", {
  7855. get: function () {
  7856. return this._size;
  7857. },
  7858. /**
  7859. * Get/Set the size of the group. If null the size of the group will be determine from its content.
  7860. * 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.
  7861. */
  7862. set: function (val) {
  7863. this._size = val;
  7864. },
  7865. enumerable: true,
  7866. configurable: true
  7867. });
  7868. Object.defineProperty(Group2D.prototype, "viewportSize", {
  7869. get: function () {
  7870. return this._viewportSize;
  7871. },
  7872. enumerable: true,
  7873. configurable: true
  7874. });
  7875. Object.defineProperty(Group2D.prototype, "actualSize", {
  7876. get: function () {
  7877. // The computed size will be floor on both width and height
  7878. var actualSize;
  7879. // Return the actualSize if set
  7880. if (this._actualSize) {
  7881. return this._actualSize;
  7882. }
  7883. // Return the size if set by the user
  7884. if (this._size) {
  7885. actualSize = new BABYLON.Size(Math.ceil(this._size.width), Math.ceil(this._size.height));
  7886. }
  7887. else {
  7888. var m = this.layoutBoundingInfo.max();
  7889. actualSize = new BABYLON.Size(Math.ceil(m.x), Math.ceil(m.y));
  7890. }
  7891. // 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)
  7892. if (!actualSize.equals(this._actualSize)) {
  7893. this.onPrimitivePropertyDirty(Group2D.actualSizeProperty.flagId);
  7894. this._actualSize = actualSize;
  7895. this.handleGroupChanged(Group2D.actualSizeProperty);
  7896. }
  7897. return actualSize;
  7898. },
  7899. set: function (value) {
  7900. this._actualSize = value;
  7901. },
  7902. enumerable: true,
  7903. configurable: true
  7904. });
  7905. Object.defineProperty(Group2D.prototype, "cacheBehavior", {
  7906. /**
  7907. * 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.
  7908. * GROUPCACHEBEHAVIOR_NORESIZEONSCALE can also be set if you set it at creation time.
  7909. * 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.
  7910. */
  7911. get: function () {
  7912. return this._cacheBehavior;
  7913. },
  7914. enumerable: true,
  7915. configurable: true
  7916. });
  7917. Group2D.prototype._addPrimToDirtyList = function (prim) {
  7918. this._renderableData._primDirtyList.push(prim);
  7919. };
  7920. Group2D.prototype._renderCachedCanvas = function () {
  7921. this.owner._addGroupRenderCount(1);
  7922. this.updateCachedStates(true);
  7923. var context = new BABYLON.PrepareRender2DContext();
  7924. this._prepareGroupRender(context);
  7925. this._groupRender();
  7926. };
  7927. Object.defineProperty(Group2D.prototype, "trackedNode", {
  7928. /**
  7929. * Get/set the Scene's Node that should be tracked, the group's position will follow the projected position of the Node.
  7930. */
  7931. get: function () {
  7932. return this._trackedNode;
  7933. },
  7934. set: function (val) {
  7935. if (val != null) {
  7936. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  7937. this.owner._registerTrackedNode(this);
  7938. }
  7939. this._trackedNode = val;
  7940. }
  7941. else {
  7942. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  7943. this.owner._unregisterTrackedNode(this);
  7944. }
  7945. this._trackedNode = null;
  7946. }
  7947. },
  7948. enumerable: true,
  7949. configurable: true
  7950. });
  7951. Group2D.prototype.levelIntersect = function (intersectInfo) {
  7952. // 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
  7953. return true;
  7954. };
  7955. Group2D.prototype.updateLevelBoundingInfo = function () {
  7956. var size;
  7957. // If the size is set by the user, the boundingInfo is computed from this value
  7958. if (this.size) {
  7959. size = this.size;
  7960. }
  7961. else {
  7962. size = new BABYLON.Size(0, 0);
  7963. }
  7964. BABYLON.BoundingInfo2D.CreateFromSizeToRef(size, this._levelBoundingInfo);
  7965. };
  7966. // Method called only on renderable groups to prepare the rendering
  7967. Group2D.prototype._prepareGroupRender = function (context) {
  7968. var sortedDirtyList = null;
  7969. // Update the Global Transformation and visibility status of the changed primitives
  7970. var rd = this._renderableData;
  7971. if ((rd._primDirtyList.length > 0) || context.forceRefreshPrimitive) {
  7972. sortedDirtyList = rd._primDirtyList.sort(function (a, b) { return a.hierarchyDepth - b.hierarchyDepth; });
  7973. this.updateCachedStatesOf(sortedDirtyList, true);
  7974. }
  7975. var s = this.actualSize;
  7976. var a = this.actualScale;
  7977. var sw = Math.ceil(s.width * a.x);
  7978. var sh = Math.ceil(s.height * a.y);
  7979. // 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.
  7980. // So we set the width/height to the rendering's one because that's what we want for the viewport!
  7981. if ((this instanceof BABYLON.Canvas2D || this.id === "__cachedCanvasGroup__") && this.owner.designSize != null) {
  7982. sw = this.owner.engine.getRenderWidth();
  7983. sh = this.owner.engine.getRenderHeight();
  7984. }
  7985. // Setup the size of the rendering viewport
  7986. // 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
  7987. if (!this._isCachedGroup) {
  7988. // Compute the WebGL viewport's location/size
  7989. var t = this._globalTransform.getTranslation();
  7990. var rs = this.owner._renderingSize;
  7991. sh = Math.min(sh, rs.height - t.y);
  7992. sw = Math.min(sw, rs.width - t.x);
  7993. var x = t.x;
  7994. var y = t.y;
  7995. // 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
  7996. this._viewportPosition.x = x;
  7997. this._viewportPosition.y = y;
  7998. }
  7999. // 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.
  8000. if (this._viewportSize.width !== sw || this._viewportSize.height !== sh) {
  8001. context.forceRefreshPrimitive = true;
  8002. this._viewportSize.width = sw;
  8003. this._viewportSize.height = sh;
  8004. }
  8005. if ((rd._primDirtyList.length > 0) || context.forceRefreshPrimitive) {
  8006. // If the group is cached, set the dirty flag to true because of the incoming changes
  8007. this._cacheGroupDirty = this._isCachedGroup;
  8008. rd._primNewDirtyList.splice(0);
  8009. // If it's a force refresh, prepare all the children
  8010. if (context.forceRefreshPrimitive) {
  8011. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  8012. var p = _a[_i];
  8013. p._prepareRender(context);
  8014. }
  8015. }
  8016. else {
  8017. // Each primitive that changed at least once was added into the primDirtyList, we have to sort this level using
  8018. // the hierarchyDepth in order to prepare primitives from top to bottom
  8019. if (!sortedDirtyList) {
  8020. sortedDirtyList = rd._primDirtyList.sort(function (a, b) { return a.hierarchyDepth - b.hierarchyDepth; });
  8021. }
  8022. sortedDirtyList.forEach(function (p) {
  8023. // 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.
  8024. // 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.
  8025. if (!p.isDisposed && p._needPrepare()) {
  8026. p._prepareRender(context);
  8027. }
  8028. });
  8029. }
  8030. // Everything is updated, clear the dirty list
  8031. rd._primDirtyList.forEach(function (p) {
  8032. if (rd._primNewDirtyList.indexOf(p) === -1) {
  8033. p._resetPropertiesDirty();
  8034. }
  8035. else {
  8036. p._setFlags(BABYLON.SmartPropertyPrim.flagNeedRefresh);
  8037. }
  8038. });
  8039. rd._primDirtyList.splice(0);
  8040. rd._primDirtyList = rd._primDirtyList.concat(rd._primNewDirtyList);
  8041. }
  8042. // A renderable group has a list of direct children that are also renderable groups, we recurse on them to also prepare them
  8043. rd._childrenRenderableGroups.forEach(function (g) {
  8044. g._prepareGroupRender(context);
  8045. });
  8046. };
  8047. Group2D.prototype._groupRender = function () {
  8048. var _this = this;
  8049. var engine = this.owner.engine;
  8050. var failedCount = 0;
  8051. // First recurse to children render group to render them (in their cache or on screen)
  8052. for (var _i = 0, _a = this._renderableData._childrenRenderableGroups; _i < _a.length; _i++) {
  8053. var childGroup = _a[_i];
  8054. childGroup._groupRender();
  8055. }
  8056. // Render the primitives if needed: either if we don't cache the content or if the content is cached but has changed
  8057. if (!this.isCachedGroup || this._cacheGroupDirty) {
  8058. this.owner._addGroupRenderCount(1);
  8059. if (this.isCachedGroup) {
  8060. this._bindCacheTarget();
  8061. }
  8062. else {
  8063. var curVP = engine.setDirectViewport(this._viewportPosition.x, this._viewportPosition.y, this._viewportSize.width, this._viewportSize.height);
  8064. }
  8065. var curAlphaTest = engine.getAlphaTesting() === true;
  8066. var curDepthWrite = engine.getDepthWrite() === true;
  8067. // ===================================================================
  8068. // First pass, update the InstancedArray and render Opaque primitives
  8069. // Disable Alpha Testing, Enable Depth Write
  8070. engine.setAlphaTesting(false);
  8071. engine.setDepthWrite(true);
  8072. // For each different model of primitive to render
  8073. var context_1 = new BABYLON.Render2DContext(BABYLON.Render2DContext.RenderModeOpaque);
  8074. this._renderableData._renderGroupInstancesInfo.forEach(function (k, v) {
  8075. // Prepare the context object, update the WebGL Instanced Array buffer if needed
  8076. var renderCount = _this._prepareContext(engine, context_1, v);
  8077. // If null is returned, there's no opaque data to render
  8078. if (renderCount === null) {
  8079. return;
  8080. }
  8081. // Submit render only if we have something to render (everything may be hidden and the floatarray empty)
  8082. if (!_this.owner.supportInstancedArray || renderCount > 0) {
  8083. // render all the instances of this model, if the render method returns true then our instances are no longer dirty
  8084. var renderFailed = !v.modelRenderCache.render(v, context_1);
  8085. // Update dirty flag/related
  8086. v.opaqueDirty = renderFailed;
  8087. failedCount += renderFailed ? 1 : 0;
  8088. }
  8089. });
  8090. // =======================================================================
  8091. // Second pass, update the InstancedArray and render AlphaTest primitives
  8092. // Enable Alpha Testing, Enable Depth Write
  8093. engine.setAlphaTesting(true);
  8094. engine.setDepthWrite(true);
  8095. // For each different model of primitive to render
  8096. context_1 = new BABYLON.Render2DContext(BABYLON.Render2DContext.RenderModeAlphaTest);
  8097. this._renderableData._renderGroupInstancesInfo.forEach(function (k, v) {
  8098. // Prepare the context object, update the WebGL Instanced Array buffer if needed
  8099. var renderCount = _this._prepareContext(engine, context_1, v);
  8100. // If null is returned, there's no opaque data to render
  8101. if (renderCount === null) {
  8102. return;
  8103. }
  8104. // Submit render only if we have something to render (everything may be hidden and the floatarray empty)
  8105. if (!_this.owner.supportInstancedArray || renderCount > 0) {
  8106. // render all the instances of this model, if the render method returns true then our instances are no longer dirty
  8107. var renderFailed = !v.modelRenderCache.render(v, context_1);
  8108. // Update dirty flag/related
  8109. v.opaqueDirty = renderFailed;
  8110. failedCount += renderFailed ? 1 : 0;
  8111. }
  8112. });
  8113. // =======================================================================
  8114. // Third pass, transparent primitive rendering
  8115. // Enable Alpha Testing, Disable Depth Write
  8116. engine.setAlphaTesting(true);
  8117. engine.setDepthWrite(false);
  8118. // First Check if the transparent List change so we can update the TransparentSegment and PartData (sort if needed)
  8119. if (this._renderableData._transparentListChanged) {
  8120. this._updateTransparentData();
  8121. }
  8122. // From this point on we have up to date data to render, so let's go
  8123. failedCount += this._renderTransparentData();
  8124. // =======================================================================
  8125. // Unbind target/restore viewport setting, clear dirty flag, and quit
  8126. // The group's content is no longer dirty
  8127. this._cacheGroupDirty = failedCount !== 0;
  8128. if (this.isCachedGroup) {
  8129. this._unbindCacheTarget();
  8130. }
  8131. else {
  8132. if (curVP) {
  8133. engine.setViewport(curVP);
  8134. }
  8135. }
  8136. // Restore saved states
  8137. engine.setAlphaTesting(curAlphaTest);
  8138. engine.setDepthWrite(curDepthWrite);
  8139. }
  8140. };
  8141. Group2D.prototype._setCacheGroupDirty = function () {
  8142. this._cacheGroupDirty = true;
  8143. };
  8144. Group2D.prototype._updateTransparentData = function () {
  8145. this.owner._addUpdateTransparentDataCount(1);
  8146. var rd = this._renderableData;
  8147. // Sort all the primitive from their depth, max (bottom) to min (top)
  8148. rd._transparentPrimitives.sort(function (a, b) { return b._primitive.actualZOffset - a._primitive.actualZOffset; });
  8149. var checkAndAddPrimInSegment = function (seg, tpiI) {
  8150. var tpi = rd._transparentPrimitives[tpiI];
  8151. // Fast rejection: if gii are different
  8152. if (seg.groupInsanceInfo !== tpi._groupInstanceInfo) {
  8153. return false;
  8154. }
  8155. //let tpiZ = tpi._primitive.actualZOffset;
  8156. // We've made it so far, the tpi can be part of the segment, add it
  8157. tpi._transparentSegment = seg;
  8158. tpi._primitive._updateTransparentSegmentIndices(seg);
  8159. return true;
  8160. };
  8161. // Free the existing TransparentSegments
  8162. for (var _i = 0, _a = rd._transparentSegments; _i < _a.length; _i++) {
  8163. var ts = _a[_i];
  8164. ts.dispose(this.owner.engine);
  8165. }
  8166. rd._transparentSegments.splice(0);
  8167. var prevSeg = null;
  8168. for (var tpiI = 0; tpiI < rd._transparentPrimitives.length; tpiI++) {
  8169. var tpi = rd._transparentPrimitives[tpiI];
  8170. // Check if the Data in which the primitive is stored is not sorted properly
  8171. if (tpi._groupInstanceInfo.transparentOrderDirty) {
  8172. tpi._groupInstanceInfo.sortTransparentData();
  8173. }
  8174. // Reset the segment, we have to create/rebuild it
  8175. tpi._transparentSegment = null;
  8176. // If there's a previous valid segment, check if this prim can be part of it
  8177. if (prevSeg) {
  8178. checkAndAddPrimInSegment(prevSeg, tpiI);
  8179. }
  8180. // If we couldn't insert in the adjacent segments, he have to create one
  8181. if (!tpi._transparentSegment) {
  8182. var ts = new BABYLON.TransparentSegment();
  8183. ts.groupInsanceInfo = tpi._groupInstanceInfo;
  8184. var prim = tpi._primitive;
  8185. ts.startZ = prim.actualZOffset;
  8186. prim._updateTransparentSegmentIndices(ts);
  8187. ts.endZ = ts.startZ;
  8188. tpi._transparentSegment = ts;
  8189. rd._transparentSegments.push(ts);
  8190. }
  8191. // Update prevSeg
  8192. prevSeg = tpi._transparentSegment;
  8193. }
  8194. //rd._firstChangedPrim = null;
  8195. rd._transparentListChanged = false;
  8196. };
  8197. Group2D.prototype._renderTransparentData = function () {
  8198. var failedCount = 0;
  8199. var context = new BABYLON.Render2DContext(BABYLON.Render2DContext.RenderModeTransparent);
  8200. var rd = this._renderableData;
  8201. var useInstanced = this.owner.supportInstancedArray;
  8202. var length = rd._transparentSegments.length;
  8203. for (var i = 0; i < length; i++) {
  8204. context.instancedBuffers = null;
  8205. var ts = rd._transparentSegments[i];
  8206. var gii = ts.groupInsanceInfo;
  8207. var mrc = gii.modelRenderCache;
  8208. var engine = this.owner.engine;
  8209. var count = ts.endDataIndex - ts.startDataIndex;
  8210. // Use Instanced Array if it's supported and if there's at least minPartCountToUseInstancedArray prims to draw.
  8211. // We don't want to create an Instanced Buffer for less that minPartCountToUseInstancedArray prims
  8212. if (useInstanced && count >= this.owner.minPartCountToUseInstancedArray) {
  8213. if (!ts.partBuffers) {
  8214. var buffers = new Array();
  8215. for (var j = 0; j < gii.transparentData.length; j++) {
  8216. var gitd = gii.transparentData[j];
  8217. var dfa = gitd._partData;
  8218. var data = dfa.pack();
  8219. var stride = dfa.stride;
  8220. var neededSize = count * stride * 4;
  8221. var buffer = engine.createInstancesBuffer(neededSize); // Create + bind
  8222. var segData = data.subarray(ts.startDataIndex * stride, ts.endDataIndex * stride);
  8223. engine.updateArrayBuffer(segData);
  8224. buffers.push(buffer);
  8225. }
  8226. ts.partBuffers = buffers;
  8227. }
  8228. else if (gii.transparentDirty) {
  8229. for (var j = 0; j < gii.transparentData.length; j++) {
  8230. var gitd = gii.transparentData[j];
  8231. var dfa = gitd._partData;
  8232. var data = dfa.pack();
  8233. var stride = dfa.stride;
  8234. var buffer = ts.partBuffers[j];
  8235. var segData = data.subarray(ts.startDataIndex * stride, ts.endDataIndex * stride);
  8236. engine.bindArrayBuffer(buffer);
  8237. engine.updateArrayBuffer(segData);
  8238. }
  8239. }
  8240. context.useInstancing = true;
  8241. context.instancesCount = count;
  8242. context.instancedBuffers = ts.partBuffers;
  8243. context.groupInfoPartData = gii.transparentData;
  8244. var renderFailed = !mrc.render(gii, context);
  8245. failedCount += renderFailed ? 1 : 0;
  8246. }
  8247. else {
  8248. context.useInstancing = false;
  8249. context.partDataStartIndex = ts.startDataIndex;
  8250. context.partDataEndIndex = ts.endDataIndex;
  8251. context.groupInfoPartData = gii.transparentData;
  8252. var renderFailed = !mrc.render(gii, context);
  8253. failedCount += renderFailed ? 1 : 0;
  8254. }
  8255. }
  8256. return failedCount;
  8257. };
  8258. Group2D.prototype._prepareContext = function (engine, context, gii) {
  8259. var gipd = null;
  8260. var setDirty;
  8261. var getDirty;
  8262. // Render Mode specifics
  8263. switch (context.renderMode) {
  8264. case BABYLON.Render2DContext.RenderModeOpaque:
  8265. {
  8266. if (!gii.hasOpaqueData) {
  8267. return null;
  8268. }
  8269. setDirty = function (dirty) { gii.opaqueDirty = dirty; };
  8270. getDirty = function () { return gii.opaqueDirty; };
  8271. context.groupInfoPartData = gii.opaqueData;
  8272. gipd = gii.opaqueData;
  8273. break;
  8274. }
  8275. case BABYLON.Render2DContext.RenderModeAlphaTest:
  8276. {
  8277. if (!gii.hasAlphaTestData) {
  8278. return null;
  8279. }
  8280. setDirty = function (dirty) { gii.alphaTestDirty = dirty; };
  8281. getDirty = function () { return gii.alphaTestDirty; };
  8282. context.groupInfoPartData = gii.alphaTestData;
  8283. gipd = gii.alphaTestData;
  8284. break;
  8285. }
  8286. default:
  8287. throw new Error("_prepareContext is only for opaque or alphaTest");
  8288. }
  8289. var renderCount = 0;
  8290. // This part will pack the dynamicfloatarray and update the instanced array WebGLBufffer
  8291. // Skip it if instanced arrays are not supported
  8292. if (this.owner.supportInstancedArray) {
  8293. // Flag for instancing
  8294. context.useInstancing = true;
  8295. // Make sure all the WebGLBuffers of the Instanced Array are created/up to date for the parts to render.
  8296. for (var i = 0; i < gipd.length; i++) {
  8297. var pid = gipd[i];
  8298. // If the instances of the model was changed, pack the data
  8299. var array = pid._partData;
  8300. var instanceData_1 = array.pack();
  8301. renderCount += array.usedElementCount;
  8302. // Compute the size the instance buffer should have
  8303. var neededSize = array.usedElementCount * array.stride * 4;
  8304. // Check if we have to (re)create the instancesBuffer because there's none or the size is too small
  8305. if (!pid._partBuffer || (pid._partBufferSize < neededSize)) {
  8306. if (pid._partBuffer) {
  8307. engine.deleteInstancesBuffer(pid._partBuffer);
  8308. }
  8309. pid._partBuffer = engine.createInstancesBuffer(neededSize); // Create + bind
  8310. pid._partBufferSize = neededSize;
  8311. setDirty(false);
  8312. // Update the WebGL buffer to match the new content of the instances data
  8313. engine.updateArrayBuffer(instanceData_1);
  8314. }
  8315. else if (getDirty()) {
  8316. // Update the WebGL buffer to match the new content of the instances data
  8317. engine.bindArrayBuffer(pid._partBuffer);
  8318. engine.updateArrayBuffer(instanceData_1);
  8319. }
  8320. }
  8321. setDirty(false);
  8322. }
  8323. else {
  8324. context.partDataStartIndex = 0;
  8325. // Find the first valid object to get the count
  8326. if (context.groupInfoPartData.length > 0) {
  8327. var i = 0;
  8328. while (!context.groupInfoPartData[i]) {
  8329. i++;
  8330. }
  8331. context.partDataEndIndex = context.groupInfoPartData[i]._partData.usedElementCount;
  8332. }
  8333. }
  8334. return renderCount;
  8335. };
  8336. Group2D.prototype._setRenderingScale = function (scale) {
  8337. if (this._renderableData._renderingScale === scale) {
  8338. return;
  8339. }
  8340. this._renderableData._renderingScale = scale;
  8341. };
  8342. Group2D.prototype._bindCacheTarget = function () {
  8343. var curWidth;
  8344. var curHeight;
  8345. var rd = this._renderableData;
  8346. var rs = rd._renderingScale;
  8347. var noResizeScale = rd._noResizeOnScale;
  8348. var isCanvas = this.parent == null;
  8349. var scale;
  8350. if (noResizeScale) {
  8351. scale = isCanvas ? Group2D._uV : this.parent.actualScale;
  8352. }
  8353. else {
  8354. scale = this.actualScale;
  8355. }
  8356. if (isCanvas && this.owner.cachingStrategy === BABYLON.Canvas2D.CACHESTRATEGY_CANVAS && this.owner.isScreenSpace) {
  8357. if (this.owner.designSize || this.owner.fitRenderingDevice) {
  8358. Group2D._s.width = this.owner.engine.getRenderWidth();
  8359. Group2D._s.height = this.owner.engine.getRenderHeight();
  8360. }
  8361. else {
  8362. Group2D._s.copyFrom(this.owner.size);
  8363. }
  8364. }
  8365. else {
  8366. Group2D._s.width = Math.ceil(this.actualSize.width * scale.x * rs);
  8367. Group2D._s.height = Math.ceil(this.actualSize.height * scale.y * rs);
  8368. }
  8369. var sizeChanged = !Group2D._s.equals(rd._cacheSize);
  8370. if (rd._cacheNode) {
  8371. var size = rd._cacheNode.contentSize;
  8372. // Check if we have to deallocate because the size is too small
  8373. if ((size.width < Group2D._s.width) || (size.height < Group2D._s.height)) {
  8374. // For Screen space: over-provisioning of 7% more to avoid frequent resizing for few pixels...
  8375. // For World space: no over-provisioning
  8376. var overprovisioning = this.owner.isScreenSpace ? 1.07 : 1;
  8377. curWidth = Math.floor(Group2D._s.width * overprovisioning);
  8378. curHeight = Math.floor(Group2D._s.height * overprovisioning);
  8379. //console.log(`[${this._globalTransformProcessStep}] Resize group ${this.id}, width: ${curWidth}, height: ${curHeight}`);
  8380. rd._cacheTexture.freeRect(rd._cacheNode);
  8381. rd._cacheNode = null;
  8382. }
  8383. }
  8384. if (!rd._cacheNode) {
  8385. // Check if we have to allocate a rendering zone in the global cache texture
  8386. var res = this.owner._allocateGroupCache(this, this.parent && this.parent.renderGroup, curWidth ? new BABYLON.Size(curWidth, curHeight) : null, rd._useMipMap, rd._anisotropicLevel);
  8387. rd._cacheNode = res.node;
  8388. rd._cacheTexture = res.texture;
  8389. if (rd._cacheRenderSprite) {
  8390. rd._cacheRenderSprite.dispose();
  8391. }
  8392. rd._cacheRenderSprite = res.sprite;
  8393. sizeChanged = true;
  8394. }
  8395. if (sizeChanged) {
  8396. rd._cacheSize.copyFrom(Group2D._s);
  8397. rd._cacheNodeUVs = rd._cacheNode.getUVsForCustomSize(rd._cacheSize);
  8398. if (rd._cacheNodeUVsChangedObservable && rd._cacheNodeUVsChangedObservable.hasObservers()) {
  8399. rd._cacheNodeUVsChangedObservable.notifyObservers(rd._cacheNodeUVs);
  8400. }
  8401. this._setFlags(BABYLON.SmartPropertyPrim.flagWorldCacheChanged);
  8402. }
  8403. var n = rd._cacheNode;
  8404. rd._cacheTexture.bindTextureForPosSize(n.pos, Group2D._s, true);
  8405. };
  8406. Group2D.prototype._unbindCacheTarget = function () {
  8407. if (this._renderableData._cacheTexture) {
  8408. this._renderableData._cacheTexture.unbindTexture();
  8409. }
  8410. };
  8411. Group2D.prototype._spreadActualScaleDirty = function () {
  8412. if (this._renderableData && this._renderableData._cacheRenderSprite) {
  8413. this.handleGroupChanged(BABYLON.Prim2DBase.actualScaleProperty);
  8414. }
  8415. _super.prototype._spreadActualScaleDirty.call(this);
  8416. };
  8417. Group2D.prototype.handleGroupChanged = function (prop) {
  8418. // This method is only for cachedGroup
  8419. var rd = this._renderableData;
  8420. if (!rd) {
  8421. return;
  8422. }
  8423. var cachedSprite = rd._cacheRenderSprite;
  8424. if (!this.isCachedGroup || !cachedSprite) {
  8425. return;
  8426. }
  8427. // For now we only support these property changes
  8428. // TODO: add more! :)
  8429. switch (prop.id) {
  8430. case BABYLON.Prim2DBase.actualPositionProperty.id:
  8431. cachedSprite.actualPosition = this.actualPosition.clone();
  8432. if (cachedSprite.position != null) {
  8433. cachedSprite.position = cachedSprite.actualPosition.clone();
  8434. }
  8435. break;
  8436. case BABYLON.Prim2DBase.rotationProperty.id:
  8437. cachedSprite.rotation = this.rotation;
  8438. break;
  8439. case BABYLON.Prim2DBase.scaleProperty.id:
  8440. cachedSprite.scale = this.scale;
  8441. break;
  8442. case BABYLON.Prim2DBase.originProperty.id:
  8443. cachedSprite.origin = this.origin.clone();
  8444. break;
  8445. case Group2D.actualSizeProperty.id:
  8446. cachedSprite.size = this.actualSize.clone();
  8447. break;
  8448. }
  8449. };
  8450. Group2D.prototype.detectGroupStates = function () {
  8451. var isCanvas = this instanceof BABYLON.Canvas2D;
  8452. var canvasStrat = this.owner.cachingStrategy;
  8453. // In Don't Cache mode, only the canvas is renderable, all the other groups are logical. There are not a single cached group.
  8454. if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_DONTCACHE) {
  8455. this._isRenderableGroup = isCanvas;
  8456. this._isCachedGroup = false;
  8457. }
  8458. else if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_CANVAS) {
  8459. if (isCanvas) {
  8460. this._isRenderableGroup = true;
  8461. this._isCachedGroup = true;
  8462. }
  8463. else {
  8464. this._isRenderableGroup = this.id === "__cachedCanvasGroup__";
  8465. this._isCachedGroup = false;
  8466. }
  8467. }
  8468. else if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_TOPLEVELGROUPS) {
  8469. if (isCanvas) {
  8470. this._isRenderableGroup = true;
  8471. this._isCachedGroup = false;
  8472. }
  8473. else {
  8474. if (this.hierarchyDepth === 1) {
  8475. this._isRenderableGroup = true;
  8476. this._isCachedGroup = true;
  8477. }
  8478. else {
  8479. this._isRenderableGroup = false;
  8480. this._isCachedGroup = false;
  8481. }
  8482. }
  8483. }
  8484. else if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_ALLGROUPS) {
  8485. if (isCanvas) {
  8486. this._isRenderableGroup = true;
  8487. this._isCachedGroup = false;
  8488. }
  8489. else {
  8490. var gcb = this.cacheBehavior & Group2D.GROUPCACHEBEHAVIOR_OPTIONMASK;
  8491. if ((gcb === Group2D.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE) || (gcb === Group2D.GROUPCACHEBEHAVIOR_CACHEINPARENTGROUP)) {
  8492. this._isRenderableGroup = gcb === Group2D.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE;
  8493. this._isCachedGroup = false;
  8494. }
  8495. if (gcb === Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY) {
  8496. this._isRenderableGroup = true;
  8497. this._isCachedGroup = true;
  8498. }
  8499. }
  8500. }
  8501. if (this._isRenderableGroup) {
  8502. // Yes, we do need that check, trust me, unfortunately we can call _detectGroupStates many time on the same object...
  8503. if (!this._renderableData) {
  8504. this._renderableData = new RenderableGroupData();
  8505. }
  8506. }
  8507. // If the group is tagged as renderable we add it to the renderable tree
  8508. if (this._isCachedGroup) {
  8509. this._renderableData._noResizeOnScale = (this.cacheBehavior & Group2D.GROUPCACHEBEHAVIOR_NORESIZEONSCALE) !== 0;
  8510. var cur = this.parent;
  8511. while (cur) {
  8512. if (cur instanceof Group2D && cur._isRenderableGroup) {
  8513. if (cur._renderableData._childrenRenderableGroups.indexOf(this) === -1) {
  8514. cur._renderableData._childrenRenderableGroups.push(this);
  8515. }
  8516. break;
  8517. }
  8518. cur = cur.parent;
  8519. }
  8520. }
  8521. };
  8522. Group2D.GROUP2D_PROPCOUNT = BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 5;
  8523. /**
  8524. * Default behavior, the group will use the caching strategy defined at the Canvas Level
  8525. */
  8526. Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY = 0;
  8527. /**
  8528. * When used, this group's content won't be cached, no matter which strategy used.
  8529. * If the group is part of a WorldSpace Canvas, its content will be drawn in the Canvas cache bitmap.
  8530. */
  8531. Group2D.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE = 1;
  8532. /**
  8533. * When used, the group's content will be cached in the nearest cached parent group/canvas
  8534. */
  8535. Group2D.GROUPCACHEBEHAVIOR_CACHEINPARENTGROUP = 2;
  8536. /**
  8537. * 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
  8538. */
  8539. Group2D.GROUPCACHEBEHAVIOR_NORESIZEONSCALE = 0x100;
  8540. Group2D.GROUPCACHEBEHAVIOR_OPTIONMASK = 0xFF;
  8541. Group2D._uV = new BABYLON.Vector2(1, 1);
  8542. Group2D._s = BABYLON.Size.Zero();
  8543. Group2D._unS = new BABYLON.Vector2(1, 1);
  8544. __decorate([
  8545. BABYLON.instanceLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 1, function (pi) { return Group2D.sizeProperty = pi; }, false, true)
  8546. ], Group2D.prototype, "size", null);
  8547. __decorate([
  8548. BABYLON.instanceLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 2, function (pi) { return Group2D.actualSizeProperty = pi; })
  8549. ], Group2D.prototype, "actualSize", null);
  8550. Group2D = __decorate([
  8551. BABYLON.className("Group2D", "BABYLON")
  8552. ], Group2D);
  8553. return Group2D;
  8554. }(BABYLON.Prim2DBase));
  8555. BABYLON.Group2D = Group2D;
  8556. var RenderableGroupData = (function () {
  8557. function RenderableGroupData() {
  8558. this._primDirtyList = new Array();
  8559. this._primNewDirtyList = new Array();
  8560. this._childrenRenderableGroups = new Array();
  8561. this._renderGroupInstancesInfo = new BABYLON.StringDictionary();
  8562. this._transparentPrimitives = new Array();
  8563. this._transparentSegments = new Array();
  8564. this._transparentListChanged = false;
  8565. this._cacheNode = null;
  8566. this._cacheTexture = null;
  8567. this._cacheRenderSprite = null;
  8568. this._renderingScale = 1;
  8569. this._cacheNodeUVs = null;
  8570. this._cacheNodeUVsChangedObservable = null;
  8571. this._cacheSize = BABYLON.Size.Zero();
  8572. this._useMipMap = false;
  8573. this._anisotropicLevel = 1;
  8574. this._noResizeOnScale = false;
  8575. }
  8576. RenderableGroupData.prototype.dispose = function (owner) {
  8577. var engine = owner.engine;
  8578. if (this._cacheRenderSprite) {
  8579. this._cacheRenderSprite.dispose();
  8580. this._cacheRenderSprite = null;
  8581. }
  8582. if (this._cacheTexture && this._cacheNode) {
  8583. this._cacheTexture.freeRect(this._cacheNode);
  8584. this._cacheTexture = null;
  8585. this._cacheNode = null;
  8586. }
  8587. if (this._primDirtyList) {
  8588. this._primDirtyList.splice(0);
  8589. this._primDirtyList = null;
  8590. }
  8591. if (this._renderGroupInstancesInfo) {
  8592. this._renderGroupInstancesInfo.forEach(function (k, v) {
  8593. v.dispose();
  8594. });
  8595. this._renderGroupInstancesInfo = null;
  8596. }
  8597. if (this._cacheNodeUVsChangedObservable) {
  8598. this._cacheNodeUVsChangedObservable.clear();
  8599. this._cacheNodeUVsChangedObservable = null;
  8600. }
  8601. if (this._transparentSegments) {
  8602. for (var _i = 0, _a = this._transparentSegments; _i < _a.length; _i++) {
  8603. var ts = _a[_i];
  8604. ts.dispose(engine);
  8605. }
  8606. this._transparentSegments.splice(0);
  8607. this._transparentSegments = null;
  8608. }
  8609. };
  8610. RenderableGroupData.prototype.addNewTransparentPrimitiveInfo = function (prim, gii) {
  8611. var tpi = new TransparentPrimitiveInfo();
  8612. tpi._primitive = prim;
  8613. tpi._groupInstanceInfo = gii;
  8614. tpi._transparentSegment = null;
  8615. this._transparentPrimitives.push(tpi);
  8616. this._transparentListChanged = true;
  8617. return tpi;
  8618. };
  8619. RenderableGroupData.prototype.removeTransparentPrimitiveInfo = function (tpi) {
  8620. var index = this._transparentPrimitives.indexOf(tpi);
  8621. if (index !== -1) {
  8622. this._transparentPrimitives.splice(index, 1);
  8623. this._transparentListChanged = true;
  8624. }
  8625. };
  8626. RenderableGroupData.prototype.transparentPrimitiveZChanged = function (tpi) {
  8627. this._transparentListChanged = true;
  8628. //this.updateSmallestZChangedPrim(tpi);
  8629. };
  8630. return RenderableGroupData;
  8631. }());
  8632. BABYLON.RenderableGroupData = RenderableGroupData;
  8633. var TransparentPrimitiveInfo = (function () {
  8634. function TransparentPrimitiveInfo() {
  8635. }
  8636. return TransparentPrimitiveInfo;
  8637. }());
  8638. BABYLON.TransparentPrimitiveInfo = TransparentPrimitiveInfo;
  8639. })(BABYLON || (BABYLON = {}));
  8640. //# sourceMappingURL=babylon.group2d.js.map
  8641. var __extends = (this && this.__extends) || function (d, b) {
  8642. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  8643. function __() { this.constructor = d; }
  8644. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8645. };
  8646. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  8647. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  8648. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  8649. 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;
  8650. return c > 3 && r && Object.defineProperty(target, key, r), r;
  8651. };
  8652. var BABYLON;
  8653. (function (BABYLON) {
  8654. var Rectangle2DRenderCache = (function (_super) {
  8655. __extends(Rectangle2DRenderCache, _super);
  8656. function Rectangle2DRenderCache(engine, modelKey) {
  8657. _super.call(this, engine, modelKey);
  8658. this.effectsReady = false;
  8659. this.fillVB = null;
  8660. this.fillIB = null;
  8661. this.fillIndicesCount = 0;
  8662. this.instancingFillAttributes = null;
  8663. this.effectFill = null;
  8664. this.effectFillInstanced = null;
  8665. this.borderVB = null;
  8666. this.borderIB = null;
  8667. this.borderIndicesCount = 0;
  8668. this.instancingBorderAttributes = null;
  8669. this.effectBorder = null;
  8670. this.effectBorderInstanced = null;
  8671. }
  8672. Rectangle2DRenderCache.prototype.render = function (instanceInfo, context) {
  8673. // Do nothing if the shader is still loading/preparing
  8674. if (!this.effectsReady) {
  8675. if ((this.effectFill && (!this.effectFill.isReady() || (this.effectFillInstanced && !this.effectFillInstanced.isReady()))) ||
  8676. (this.effectBorder && (!this.effectBorder.isReady() || (this.effectBorderInstanced && !this.effectBorderInstanced.isReady())))) {
  8677. return false;
  8678. }
  8679. this.effectsReady = true;
  8680. }
  8681. var canvas = instanceInfo.owner.owner;
  8682. var engine = canvas.engine;
  8683. var depthFunction = 0;
  8684. if (this.effectFill && this.effectBorder) {
  8685. depthFunction = engine.getDepthFunction();
  8686. engine.setDepthFunctionToLessOrEqual();
  8687. }
  8688. var curAlphaMode = engine.getAlphaMode();
  8689. if (this.effectFill) {
  8690. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_FILLPARTID.toString());
  8691. var pid = context.groupInfoPartData[partIndex];
  8692. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  8693. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  8694. }
  8695. var effect = context.useInstancing ? this.effectFillInstanced : this.effectFill;
  8696. engine.enableEffect(effect);
  8697. engine.bindBuffersDirectly(this.fillVB, this.fillIB, [1], 4, effect);
  8698. if (context.useInstancing) {
  8699. if (!this.instancingFillAttributes) {
  8700. this.instancingFillAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_FILLPARTID, effect);
  8701. }
  8702. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  8703. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  8704. canvas._addDrawCallCount(1, context.renderMode);
  8705. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingFillAttributes);
  8706. engine.draw(true, 0, this.fillIndicesCount, count);
  8707. engine.unbindInstanceAttributes();
  8708. }
  8709. else {
  8710. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  8711. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  8712. this.setupUniforms(effect, partIndex, pid._partData, i);
  8713. engine.draw(true, 0, this.fillIndicesCount);
  8714. }
  8715. }
  8716. }
  8717. if (this.effectBorder) {
  8718. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_BORDERPARTID.toString());
  8719. var pid = context.groupInfoPartData[partIndex];
  8720. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  8721. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  8722. }
  8723. var effect = context.useInstancing ? this.effectBorderInstanced : this.effectBorder;
  8724. engine.enableEffect(effect);
  8725. engine.bindBuffersDirectly(this.borderVB, this.borderIB, [1], 4, effect);
  8726. if (context.useInstancing) {
  8727. if (!this.instancingBorderAttributes) {
  8728. this.instancingBorderAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, effect);
  8729. }
  8730. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  8731. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  8732. canvas._addDrawCallCount(1, context.renderMode);
  8733. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingBorderAttributes);
  8734. engine.draw(true, 0, this.borderIndicesCount, count);
  8735. engine.unbindInstanceAttributes();
  8736. }
  8737. else {
  8738. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  8739. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  8740. this.setupUniforms(effect, partIndex, pid._partData, i);
  8741. engine.draw(true, 0, this.borderIndicesCount);
  8742. }
  8743. }
  8744. }
  8745. engine.setAlphaMode(curAlphaMode, true);
  8746. if (this.effectFill && this.effectBorder) {
  8747. engine.setDepthFunction(depthFunction);
  8748. }
  8749. return true;
  8750. };
  8751. Rectangle2DRenderCache.prototype.dispose = function () {
  8752. if (!_super.prototype.dispose.call(this)) {
  8753. return false;
  8754. }
  8755. if (this.fillVB) {
  8756. this._engine._releaseBuffer(this.fillVB);
  8757. this.fillVB = null;
  8758. }
  8759. if (this.fillIB) {
  8760. this._engine._releaseBuffer(this.fillIB);
  8761. this.fillIB = null;
  8762. }
  8763. this.effectFill = null;
  8764. this.effectFillInstanced = null;
  8765. this.effectBorder = null;
  8766. this.effectBorderInstanced = null;
  8767. if (this.borderVB) {
  8768. this._engine._releaseBuffer(this.borderVB);
  8769. this.borderVB = null;
  8770. }
  8771. if (this.borderIB) {
  8772. this._engine._releaseBuffer(this.borderIB);
  8773. this.borderIB = null;
  8774. }
  8775. return true;
  8776. };
  8777. return Rectangle2DRenderCache;
  8778. }(BABYLON.ModelRenderCache));
  8779. BABYLON.Rectangle2DRenderCache = Rectangle2DRenderCache;
  8780. var Rectangle2DInstanceData = (function (_super) {
  8781. __extends(Rectangle2DInstanceData, _super);
  8782. function Rectangle2DInstanceData(partId) {
  8783. _super.call(this, partId, 1);
  8784. }
  8785. Object.defineProperty(Rectangle2DInstanceData.prototype, "properties", {
  8786. get: function () {
  8787. return null;
  8788. },
  8789. set: function (value) {
  8790. },
  8791. enumerable: true,
  8792. configurable: true
  8793. });
  8794. __decorate([
  8795. BABYLON.instanceData()
  8796. ], Rectangle2DInstanceData.prototype, "properties", null);
  8797. return Rectangle2DInstanceData;
  8798. }(BABYLON.Shape2DInstanceData));
  8799. BABYLON.Rectangle2DInstanceData = Rectangle2DInstanceData;
  8800. var Rectangle2D = (function (_super) {
  8801. __extends(Rectangle2D, _super);
  8802. /**
  8803. * Create an Rectangle 2D Shape primitive. May be a sharp rectangle (with sharp corners), or a rounded one.
  8804. * @param settings a combination of settings, possible ones are
  8805. * - 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)
  8806. * - children: an array of direct children
  8807. * - id a text identifier, for information purpose
  8808. * - position: the X & Y positions relative to its parent. Alternatively the x and y settings can be set. Default is [0;0]
  8809. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  8810. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  8811. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  8812. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  8813. * - zOrder: override the zOrder with the specified value
  8814. * - origin: define the normalized origin point location, default [0.5;0.5]
  8815. * - size: the size of the group. Alternatively the width and height settings can be set. Default will be [10;10].
  8816. * - roundRadius: if the rectangle has rounded corner, set their radius, default is 0 (to get a sharp edges rectangle).
  8817. * - 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)
  8818. * - 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)
  8819. * - borderThickness: the thickness of the drawn border, default is 1.
  8820. * - isVisible: true if the primitive must be visible, false for hidden. Default is true.
  8821. * - 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.
  8822. * - 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.
  8823. * - 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!
  8824. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8825. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8826. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8827. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8828. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  8829. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  8830. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  8831. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  8832. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8833. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8834. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8835. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8836. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  8837. */
  8838. function Rectangle2D(settings) {
  8839. // Avoid checking every time if the object exists
  8840. if (settings == null) {
  8841. settings = {};
  8842. }
  8843. _super.call(this, settings);
  8844. if (settings.size != null) {
  8845. this.size = settings.size;
  8846. }
  8847. else if (settings.width || settings.height) {
  8848. var size = new BABYLON.Size(settings.width, settings.height);
  8849. this.size = size;
  8850. }
  8851. //let size = settings.size || (new Size((settings.width === null) ? null : (settings.width || 10), (settings.height === null) ? null : (settings.height || 10)));
  8852. var roundRadius = (settings.roundRadius == null) ? 0 : settings.roundRadius;
  8853. var borderThickness = (settings.borderThickness == null) ? 1 : settings.borderThickness;
  8854. //this.size = size;
  8855. this.roundRadius = roundRadius;
  8856. this.borderThickness = borderThickness;
  8857. }
  8858. Object.defineProperty(Rectangle2D.prototype, "actualSize", {
  8859. get: function () {
  8860. if (this._actualSize) {
  8861. return this._actualSize;
  8862. }
  8863. return this.size;
  8864. },
  8865. set: function (value) {
  8866. this._actualSize = value;
  8867. },
  8868. enumerable: true,
  8869. configurable: true
  8870. });
  8871. Object.defineProperty(Rectangle2D.prototype, "notRounded", {
  8872. get: function () {
  8873. return this._notRounded;
  8874. },
  8875. set: function (value) {
  8876. this._notRounded = value;
  8877. },
  8878. enumerable: true,
  8879. configurable: true
  8880. });
  8881. Object.defineProperty(Rectangle2D.prototype, "roundRadius", {
  8882. get: function () {
  8883. return this._roundRadius;
  8884. },
  8885. set: function (value) {
  8886. this._roundRadius = value;
  8887. this.notRounded = value === 0;
  8888. this._positioningDirty();
  8889. },
  8890. enumerable: true,
  8891. configurable: true
  8892. });
  8893. Rectangle2D.prototype.levelIntersect = function (intersectInfo) {
  8894. // If we got there it mean the boundingInfo intersection succeed, if the rectangle has not roundRadius, it means it succeed!
  8895. if (this.notRounded) {
  8896. return true;
  8897. }
  8898. // 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.
  8899. // 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)
  8900. // 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.
  8901. // First let remove the origin out the equation, to have the rectangle with an origin at bottom/left
  8902. var size = this.size;
  8903. Rectangle2D._i0.x = intersectInfo._localPickPosition.x;
  8904. Rectangle2D._i0.y = intersectInfo._localPickPosition.y;
  8905. var rr = this.roundRadius;
  8906. var rrs = rr * rr;
  8907. // Check if the point is in the bottom/left quarter area
  8908. Rectangle2D._i1.x = rr;
  8909. Rectangle2D._i1.y = rr;
  8910. if (Rectangle2D._i0.x <= Rectangle2D._i1.x && Rectangle2D._i0.y <= Rectangle2D._i1.y) {
  8911. // Compute the intersection point in the quarter local space
  8912. Rectangle2D._i2.x = Rectangle2D._i0.x - Rectangle2D._i1.x;
  8913. Rectangle2D._i2.y = Rectangle2D._i0.y - Rectangle2D._i1.y;
  8914. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  8915. return Rectangle2D._i2.lengthSquared() <= rrs;
  8916. }
  8917. // Check if the point is in the top/left quarter area
  8918. Rectangle2D._i1.x = rr;
  8919. Rectangle2D._i1.y = size.height - rr;
  8920. if (Rectangle2D._i0.x <= Rectangle2D._i1.x && Rectangle2D._i0.y >= Rectangle2D._i1.y) {
  8921. // Compute the intersection point in the quarter local space
  8922. Rectangle2D._i2.x = Rectangle2D._i0.x - Rectangle2D._i1.x;
  8923. Rectangle2D._i2.y = Rectangle2D._i0.y - Rectangle2D._i1.y;
  8924. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  8925. return Rectangle2D._i2.lengthSquared() <= rrs;
  8926. }
  8927. // Check if the point is in the top/right quarter area
  8928. Rectangle2D._i1.x = size.width - rr;
  8929. Rectangle2D._i1.y = size.height - rr;
  8930. if (Rectangle2D._i0.x >= Rectangle2D._i1.x && Rectangle2D._i0.y >= Rectangle2D._i1.y) {
  8931. // Compute the intersection point in the quarter local space
  8932. Rectangle2D._i2.x = Rectangle2D._i0.x - Rectangle2D._i1.x;
  8933. Rectangle2D._i2.y = Rectangle2D._i0.y - Rectangle2D._i1.y;
  8934. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  8935. return Rectangle2D._i2.lengthSquared() <= rrs;
  8936. }
  8937. // Check if the point is in the bottom/right quarter area
  8938. Rectangle2D._i1.x = size.width - rr;
  8939. Rectangle2D._i1.y = rr;
  8940. if (Rectangle2D._i0.x >= Rectangle2D._i1.x && Rectangle2D._i0.y <= Rectangle2D._i1.y) {
  8941. // Compute the intersection point in the quarter local space
  8942. Rectangle2D._i2.x = Rectangle2D._i0.x - Rectangle2D._i1.x;
  8943. Rectangle2D._i2.y = Rectangle2D._i0.y - Rectangle2D._i1.y;
  8944. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  8945. return Rectangle2D._i2.lengthSquared() <= rrs;
  8946. }
  8947. // At any other locations the point is guarantied to be inside
  8948. return true;
  8949. };
  8950. Rectangle2D.prototype.updateLevelBoundingInfo = function () {
  8951. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.actualSize, this._levelBoundingInfo);
  8952. };
  8953. Rectangle2D.prototype.createModelRenderCache = function (modelKey) {
  8954. var renderCache = new Rectangle2DRenderCache(this.owner.engine, modelKey);
  8955. return renderCache;
  8956. };
  8957. Rectangle2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  8958. var renderCache = modelRenderCache;
  8959. var engine = this.owner.engine;
  8960. // Need to create WebGL resources for fill part?
  8961. if (this.fill) {
  8962. var vbSize = ((this.notRounded ? 1 : Rectangle2D.roundSubdivisions) * 4) + 1;
  8963. var vb = new Float32Array(vbSize);
  8964. for (var i = 0; i < vbSize; i++) {
  8965. vb[i] = i;
  8966. }
  8967. renderCache.fillVB = engine.createVertexBuffer(vb);
  8968. var triCount = vbSize - 1;
  8969. var ib = new Float32Array(triCount * 3);
  8970. for (var i = 0; i < triCount; i++) {
  8971. ib[i * 3 + 0] = 0;
  8972. ib[i * 3 + 2] = i + 1;
  8973. ib[i * 3 + 1] = i + 2;
  8974. }
  8975. ib[triCount * 3 - 2] = 1;
  8976. renderCache.fillIB = engine.createIndexBuffer(ib);
  8977. renderCache.fillIndicesCount = triCount * 3;
  8978. // 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
  8979. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, true);
  8980. if (ei) {
  8981. renderCache.effectFillInstanced = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  8982. }
  8983. // Get the non instanced version
  8984. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, false);
  8985. renderCache.effectFill = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  8986. }
  8987. // Need to create WebGL resource for border part?
  8988. if (this.border) {
  8989. var vbSize = (this.notRounded ? 1 : Rectangle2D.roundSubdivisions) * 4 * 2;
  8990. var vb = new Float32Array(vbSize);
  8991. for (var i = 0; i < vbSize; i++) {
  8992. vb[i] = i;
  8993. }
  8994. renderCache.borderVB = engine.createVertexBuffer(vb);
  8995. var triCount = vbSize;
  8996. var rs = triCount / 2;
  8997. var ib = new Float32Array(triCount * 3);
  8998. for (var i = 0; i < rs; i++) {
  8999. var r0 = i;
  9000. var r1 = (i + 1) % rs;
  9001. ib[i * 6 + 0] = rs + r1;
  9002. ib[i * 6 + 1] = rs + r0;
  9003. ib[i * 6 + 2] = r0;
  9004. ib[i * 6 + 3] = r1;
  9005. ib[i * 6 + 4] = rs + r1;
  9006. ib[i * 6 + 5] = r0;
  9007. }
  9008. renderCache.borderIB = engine.createIndexBuffer(ib);
  9009. renderCache.borderIndicesCount = triCount * 3;
  9010. // 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
  9011. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, true);
  9012. if (ei) {
  9013. renderCache.effectBorderInstanced = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9014. }
  9015. // Get the non instanced version
  9016. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, false);
  9017. renderCache.effectBorder = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9018. }
  9019. return renderCache;
  9020. };
  9021. // 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
  9022. Rectangle2D.prototype._getInitialContentAreaToRef = function (primSize, initialContentPosition, initialContentArea) {
  9023. // Fall back to default implementation if there's no round Radius
  9024. if (this._notRounded) {
  9025. _super.prototype._getInitialContentAreaToRef.call(this, primSize, initialContentPosition, initialContentArea);
  9026. }
  9027. else {
  9028. var rr = Math.round((this.roundRadius - (this.roundRadius / Math.sqrt(2))) * 1.3);
  9029. initialContentPosition.x = initialContentPosition.y = rr;
  9030. initialContentArea.width = Math.max(0, primSize.width - (rr * 2));
  9031. initialContentArea.height = Math.max(0, primSize.height - (rr * 2));
  9032. initialContentPosition.z = primSize.width - (initialContentPosition.x + initialContentArea.width);
  9033. initialContentPosition.w = primSize.height - (initialContentPosition.y + initialContentArea.height);
  9034. }
  9035. };
  9036. Rectangle2D.prototype._getActualSizeFromContentToRef = function (primSize, newPrimSize) {
  9037. // Fall back to default implementation if there's no round Radius
  9038. if (this._notRounded) {
  9039. _super.prototype._getActualSizeFromContentToRef.call(this, primSize, newPrimSize);
  9040. }
  9041. else {
  9042. var rr = Math.round((this.roundRadius - (this.roundRadius / Math.sqrt(2))) * 1.3);
  9043. newPrimSize.copyFrom(primSize);
  9044. newPrimSize.width += rr * 2;
  9045. newPrimSize.height += rr * 2;
  9046. }
  9047. };
  9048. Rectangle2D.prototype.createInstanceDataParts = function () {
  9049. var res = new Array();
  9050. if (this.border) {
  9051. res.push(new Rectangle2DInstanceData(BABYLON.Shape2D.SHAPE2D_BORDERPARTID));
  9052. }
  9053. if (this.fill) {
  9054. res.push(new Rectangle2DInstanceData(BABYLON.Shape2D.SHAPE2D_FILLPARTID));
  9055. }
  9056. return res;
  9057. };
  9058. Rectangle2D.prototype.refreshInstanceDataPart = function (part) {
  9059. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  9060. return false;
  9061. }
  9062. if (part.id === BABYLON.Shape2D.SHAPE2D_BORDERPARTID) {
  9063. var d = part;
  9064. var size = this.actualSize;
  9065. var s = this.actualScale;
  9066. d.properties = new BABYLON.Vector3(size.width * s.x, size.height * s.y, this.roundRadius || 0);
  9067. }
  9068. else if (part.id === BABYLON.Shape2D.SHAPE2D_FILLPARTID) {
  9069. var d = part;
  9070. var size = this.actualSize;
  9071. var s = this.actualScale;
  9072. d.properties = new BABYLON.Vector3(size.width * s.x, size.height * s.y, this.roundRadius || 0);
  9073. }
  9074. return true;
  9075. };
  9076. Rectangle2D._i0 = BABYLON.Vector2.Zero();
  9077. Rectangle2D._i1 = BABYLON.Vector2.Zero();
  9078. Rectangle2D._i2 = BABYLON.Vector2.Zero();
  9079. Rectangle2D.roundSubdivisions = 16;
  9080. __decorate([
  9081. BABYLON.instanceLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 1, function (pi) { return Rectangle2D.actualSizeProperty = pi; }, false, true)
  9082. ], Rectangle2D.prototype, "actualSize", null);
  9083. __decorate([
  9084. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 2, function (pi) { return Rectangle2D.notRoundedProperty = pi; })
  9085. ], Rectangle2D.prototype, "notRounded", null);
  9086. __decorate([
  9087. BABYLON.instanceLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 3, function (pi) { return Rectangle2D.roundRadiusProperty = pi; })
  9088. ], Rectangle2D.prototype, "roundRadius", null);
  9089. Rectangle2D = __decorate([
  9090. BABYLON.className("Rectangle2D", "BABYLON")
  9091. ], Rectangle2D);
  9092. return Rectangle2D;
  9093. }(BABYLON.Shape2D));
  9094. BABYLON.Rectangle2D = Rectangle2D;
  9095. })(BABYLON || (BABYLON = {}));
  9096. //# sourceMappingURL=babylon.rectangle2d.js.map
  9097. var __extends = (this && this.__extends) || function (d, b) {
  9098. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  9099. function __() { this.constructor = d; }
  9100. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9101. };
  9102. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  9103. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  9104. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  9105. 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;
  9106. return c > 3 && r && Object.defineProperty(target, key, r), r;
  9107. };
  9108. var BABYLON;
  9109. (function (BABYLON) {
  9110. var Ellipse2DRenderCache = (function (_super) {
  9111. __extends(Ellipse2DRenderCache, _super);
  9112. function Ellipse2DRenderCache(engine, modelKey) {
  9113. _super.call(this, engine, modelKey);
  9114. this.effectsReady = false;
  9115. this.fillVB = null;
  9116. this.fillIB = null;
  9117. this.fillIndicesCount = 0;
  9118. this.instancingFillAttributes = null;
  9119. this.effectFillInstanced = null;
  9120. this.effectFill = null;
  9121. this.borderVB = null;
  9122. this.borderIB = null;
  9123. this.borderIndicesCount = 0;
  9124. this.instancingBorderAttributes = null;
  9125. this.effectBorderInstanced = null;
  9126. this.effectBorder = null;
  9127. }
  9128. Ellipse2DRenderCache.prototype.render = function (instanceInfo, context) {
  9129. // Do nothing if the shader is still loading/preparing
  9130. if (!this.effectsReady) {
  9131. if ((this.effectFill && (!this.effectFill.isReady() || (this.effectFillInstanced && !this.effectFillInstanced.isReady()))) ||
  9132. (this.effectBorder && (!this.effectBorder.isReady() || (this.effectBorderInstanced && !this.effectBorderInstanced.isReady())))) {
  9133. return false;
  9134. }
  9135. this.effectsReady = true;
  9136. }
  9137. var canvas = instanceInfo.owner.owner;
  9138. var engine = canvas.engine;
  9139. var depthFunction = 0;
  9140. if (this.effectFill && this.effectBorder) {
  9141. depthFunction = engine.getDepthFunction();
  9142. engine.setDepthFunctionToLessOrEqual();
  9143. }
  9144. var curAlphaMode = engine.getAlphaMode();
  9145. if (this.effectFill) {
  9146. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_FILLPARTID.toString());
  9147. var pid = context.groupInfoPartData[partIndex];
  9148. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  9149. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  9150. }
  9151. var effect = context.useInstancing ? this.effectFillInstanced : this.effectFill;
  9152. engine.enableEffect(effect);
  9153. engine.bindBuffersDirectly(this.fillVB, this.fillIB, [1], 4, effect);
  9154. if (context.useInstancing) {
  9155. if (!this.instancingFillAttributes) {
  9156. this.instancingFillAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_FILLPARTID, effect);
  9157. }
  9158. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  9159. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  9160. canvas._addDrawCallCount(1, context.renderMode);
  9161. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingFillAttributes);
  9162. engine.draw(true, 0, this.fillIndicesCount, count);
  9163. engine.unbindInstanceAttributes();
  9164. }
  9165. else {
  9166. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  9167. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  9168. this.setupUniforms(effect, partIndex, pid._partData, i);
  9169. engine.draw(true, 0, this.fillIndicesCount);
  9170. }
  9171. }
  9172. }
  9173. if (this.effectBorder) {
  9174. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_BORDERPARTID.toString());
  9175. var pid = context.groupInfoPartData[partIndex];
  9176. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  9177. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  9178. }
  9179. var effect = context.useInstancing ? this.effectBorderInstanced : this.effectBorder;
  9180. engine.enableEffect(effect);
  9181. engine.bindBuffersDirectly(this.borderVB, this.borderIB, [1], 4, effect);
  9182. if (context.useInstancing) {
  9183. if (!this.instancingBorderAttributes) {
  9184. this.instancingBorderAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, effect);
  9185. }
  9186. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  9187. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  9188. canvas._addDrawCallCount(1, context.renderMode);
  9189. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingBorderAttributes);
  9190. engine.draw(true, 0, this.borderIndicesCount, count);
  9191. engine.unbindInstanceAttributes();
  9192. }
  9193. else {
  9194. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  9195. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  9196. this.setupUniforms(effect, partIndex, pid._partData, i);
  9197. engine.draw(true, 0, this.borderIndicesCount);
  9198. }
  9199. }
  9200. }
  9201. engine.setAlphaMode(curAlphaMode, true);
  9202. if (this.effectFill && this.effectBorder) {
  9203. engine.setDepthFunction(depthFunction);
  9204. }
  9205. return true;
  9206. };
  9207. Ellipse2DRenderCache.prototype.dispose = function () {
  9208. if (!_super.prototype.dispose.call(this)) {
  9209. return false;
  9210. }
  9211. if (this.fillVB) {
  9212. this._engine._releaseBuffer(this.fillVB);
  9213. this.fillVB = null;
  9214. }
  9215. if (this.fillIB) {
  9216. this._engine._releaseBuffer(this.fillIB);
  9217. this.fillIB = null;
  9218. }
  9219. this.effectFill = null;
  9220. this.effectFillInstanced = null;
  9221. this.effectBorder = null;
  9222. this.effectBorderInstanced = null;
  9223. if (this.borderVB) {
  9224. this._engine._releaseBuffer(this.borderVB);
  9225. this.borderVB = null;
  9226. }
  9227. if (this.borderIB) {
  9228. this._engine._releaseBuffer(this.borderIB);
  9229. this.borderIB = null;
  9230. }
  9231. return true;
  9232. };
  9233. return Ellipse2DRenderCache;
  9234. }(BABYLON.ModelRenderCache));
  9235. BABYLON.Ellipse2DRenderCache = Ellipse2DRenderCache;
  9236. var Ellipse2DInstanceData = (function (_super) {
  9237. __extends(Ellipse2DInstanceData, _super);
  9238. function Ellipse2DInstanceData(partId) {
  9239. _super.call(this, partId, 1);
  9240. }
  9241. Object.defineProperty(Ellipse2DInstanceData.prototype, "properties", {
  9242. get: function () {
  9243. return null;
  9244. },
  9245. set: function (value) {
  9246. },
  9247. enumerable: true,
  9248. configurable: true
  9249. });
  9250. __decorate([
  9251. BABYLON.instanceData()
  9252. ], Ellipse2DInstanceData.prototype, "properties", null);
  9253. return Ellipse2DInstanceData;
  9254. }(BABYLON.Shape2DInstanceData));
  9255. BABYLON.Ellipse2DInstanceData = Ellipse2DInstanceData;
  9256. var Ellipse2D = (function (_super) {
  9257. __extends(Ellipse2D, _super);
  9258. /**
  9259. * Create an Ellipse 2D Shape primitive
  9260. * @param settings a combination of settings, possible ones are
  9261. * - 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)
  9262. * - children: an array of direct children
  9263. * - id: a text identifier, for information purpose
  9264. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  9265. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  9266. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  9267. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  9268. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  9269. * - zOrder: override the zOrder with the specified value
  9270. * - origin: define the normalized origin point location, default [0.5;0.5]
  9271. * - size: the size of the group. Alternatively the width and height properties can be set. Default will be [10;10].
  9272. * - subdivision: the number of subdivision to create the ellipse perimeter, default is 64.
  9273. * - 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)
  9274. * - 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)
  9275. * - borderThickness: the thickness of the drawn border, default is 1.
  9276. * - isVisible: true if the group must be visible, false for hidden. Default is true.
  9277. * - 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.
  9278. * - 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.
  9279. * - 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!
  9280. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9281. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9282. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9283. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9284. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  9285. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  9286. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  9287. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  9288. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9289. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9290. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9291. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9292. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  9293. */
  9294. function Ellipse2D(settings) {
  9295. // Avoid checking every time if the object exists
  9296. if (settings == null) {
  9297. settings = {};
  9298. }
  9299. _super.call(this, settings);
  9300. if (settings.size != null) {
  9301. this.size = settings.size;
  9302. }
  9303. else if (settings.width || settings.height) {
  9304. var size = new BABYLON.Size(settings.width, settings.height);
  9305. this.size = size;
  9306. }
  9307. var sub = (settings.subdivisions == null) ? 64 : settings.subdivisions;
  9308. this.subdivisions = sub;
  9309. }
  9310. Object.defineProperty(Ellipse2D.prototype, "actualSize", {
  9311. get: function () {
  9312. if (this._actualSize) {
  9313. return this._actualSize;
  9314. }
  9315. return this.size;
  9316. },
  9317. set: function (value) {
  9318. this._actualSize = value;
  9319. },
  9320. enumerable: true,
  9321. configurable: true
  9322. });
  9323. Object.defineProperty(Ellipse2D.prototype, "subdivisions", {
  9324. get: function () {
  9325. return this._subdivisions;
  9326. },
  9327. set: function (value) {
  9328. this._subdivisions = value;
  9329. },
  9330. enumerable: true,
  9331. configurable: true
  9332. });
  9333. Ellipse2D.prototype.levelIntersect = function (intersectInfo) {
  9334. var w = this.size.width / 2;
  9335. var h = this.size.height / 2;
  9336. var x = intersectInfo._localPickPosition.x - w;
  9337. var y = intersectInfo._localPickPosition.y - h;
  9338. return ((x * x) / (w * w) + (y * y) / (h * h)) <= 1;
  9339. };
  9340. Ellipse2D.prototype.updateLevelBoundingInfo = function () {
  9341. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.actualSize, this._levelBoundingInfo);
  9342. };
  9343. Ellipse2D.prototype.createModelRenderCache = function (modelKey) {
  9344. var renderCache = new Ellipse2DRenderCache(this.owner.engine, modelKey);
  9345. return renderCache;
  9346. };
  9347. Ellipse2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  9348. var renderCache = modelRenderCache;
  9349. var engine = this.owner.engine;
  9350. // Need to create WebGL resources for fill part?
  9351. if (this.fill) {
  9352. var vbSize = this.subdivisions + 1;
  9353. var vb = new Float32Array(vbSize);
  9354. for (var i = 0; i < vbSize; i++) {
  9355. vb[i] = i;
  9356. }
  9357. renderCache.fillVB = engine.createVertexBuffer(vb);
  9358. var triCount = vbSize - 1;
  9359. var ib = new Float32Array(triCount * 3);
  9360. for (var i = 0; i < triCount; i++) {
  9361. ib[i * 3 + 0] = 0;
  9362. ib[i * 3 + 2] = i + 1;
  9363. ib[i * 3 + 1] = i + 2;
  9364. }
  9365. ib[triCount * 3 - 2] = 1;
  9366. renderCache.fillIB = engine.createIndexBuffer(ib);
  9367. renderCache.fillIndicesCount = triCount * 3;
  9368. // 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
  9369. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, true);
  9370. if (ei) {
  9371. renderCache.effectFillInstanced = engine.createEffect({ vertex: "ellipse2d", fragment: "ellipse2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  9372. }
  9373. // Get the non instanced version
  9374. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, false);
  9375. renderCache.effectFill = engine.createEffect({ vertex: "ellipse2d", fragment: "ellipse2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  9376. }
  9377. // Need to create WebGL resource for border part?
  9378. if (this.border) {
  9379. var vbSize = this.subdivisions * 2;
  9380. var vb = new Float32Array(vbSize);
  9381. for (var i = 0; i < vbSize; i++) {
  9382. vb[i] = i;
  9383. }
  9384. renderCache.borderVB = engine.createVertexBuffer(vb);
  9385. var triCount = vbSize;
  9386. var rs = triCount / 2;
  9387. var ib = new Float32Array(triCount * 3);
  9388. for (var i = 0; i < rs; i++) {
  9389. var r0 = i;
  9390. var r1 = (i + 1) % rs;
  9391. ib[i * 6 + 0] = rs + r1;
  9392. ib[i * 6 + 1] = rs + r0;
  9393. ib[i * 6 + 2] = r0;
  9394. ib[i * 6 + 3] = r1;
  9395. ib[i * 6 + 4] = rs + r1;
  9396. ib[i * 6 + 5] = r0;
  9397. }
  9398. renderCache.borderIB = engine.createIndexBuffer(ib);
  9399. renderCache.borderIndicesCount = (triCount * 3);
  9400. // 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
  9401. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, true);
  9402. if (ei) {
  9403. renderCache.effectBorderInstanced = engine.createEffect("ellipse2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9404. }
  9405. // Get the non instanced version
  9406. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, false);
  9407. renderCache.effectBorder = engine.createEffect("ellipse2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  9408. }
  9409. return renderCache;
  9410. };
  9411. Ellipse2D.prototype.createInstanceDataParts = function () {
  9412. var res = new Array();
  9413. if (this.border) {
  9414. res.push(new Ellipse2DInstanceData(BABYLON.Shape2D.SHAPE2D_BORDERPARTID));
  9415. }
  9416. if (this.fill) {
  9417. res.push(new Ellipse2DInstanceData(BABYLON.Shape2D.SHAPE2D_FILLPARTID));
  9418. }
  9419. return res;
  9420. };
  9421. Ellipse2D.prototype.refreshInstanceDataPart = function (part) {
  9422. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  9423. return false;
  9424. }
  9425. if (part.id === BABYLON.Shape2D.SHAPE2D_BORDERPARTID) {
  9426. var d = part;
  9427. var size = this.actualSize;
  9428. var s = this.actualScale;
  9429. d.properties = new BABYLON.Vector3(size.width * s.x, size.height * s.y, this.subdivisions);
  9430. }
  9431. else if (part.id === BABYLON.Shape2D.SHAPE2D_FILLPARTID) {
  9432. var d = part;
  9433. var size = this.actualSize;
  9434. var s = this.actualScale;
  9435. d.properties = new BABYLON.Vector3(size.width * s.x, size.height * s.y, this.subdivisions);
  9436. }
  9437. return true;
  9438. };
  9439. __decorate([
  9440. BABYLON.instanceLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 1, function (pi) { return Ellipse2D.acutalSizeProperty = pi; }, false, true)
  9441. ], Ellipse2D.prototype, "actualSize", null);
  9442. __decorate([
  9443. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 2, function (pi) { return Ellipse2D.subdivisionsProperty = pi; })
  9444. ], Ellipse2D.prototype, "subdivisions", null);
  9445. Ellipse2D = __decorate([
  9446. BABYLON.className("Ellipse2D", "BABYLON")
  9447. ], Ellipse2D);
  9448. return Ellipse2D;
  9449. }(BABYLON.Shape2D));
  9450. BABYLON.Ellipse2D = Ellipse2D;
  9451. })(BABYLON || (BABYLON = {}));
  9452. //# sourceMappingURL=babylon.ellipse2d.js.map
  9453. var __extends = (this && this.__extends) || function (d, b) {
  9454. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  9455. function __() { this.constructor = d; }
  9456. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9457. };
  9458. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  9459. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  9460. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  9461. 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;
  9462. return c > 3 && r && Object.defineProperty(target, key, r), r;
  9463. };
  9464. var BABYLON;
  9465. (function (BABYLON) {
  9466. var Sprite2DRenderCache = (function (_super) {
  9467. __extends(Sprite2DRenderCache, _super);
  9468. function Sprite2DRenderCache() {
  9469. _super.apply(this, arguments);
  9470. this.effectsReady = false;
  9471. this.vb = null;
  9472. this.ib = null;
  9473. this.instancingAttributes = null;
  9474. this.texture = null;
  9475. this.effect = null;
  9476. this.effectInstanced = null;
  9477. }
  9478. Sprite2DRenderCache.prototype.render = function (instanceInfo, context) {
  9479. // Do nothing if the shader is still loading/preparing
  9480. if (!this.effectsReady) {
  9481. if ((this.effect && (!this.effect.isReady() || (this.effectInstanced && !this.effectInstanced.isReady())))) {
  9482. return false;
  9483. }
  9484. this.effectsReady = true;
  9485. }
  9486. // Compute the offset locations of the attributes in the vertex shader that will be mapped to the instance buffer data
  9487. var canvas = instanceInfo.owner.owner;
  9488. var engine = canvas.engine;
  9489. var cur = engine.getAlphaMode();
  9490. var effect = context.useInstancing ? this.effectInstanced : this.effect;
  9491. engine.enableEffect(effect);
  9492. effect.setTexture("diffuseSampler", this.texture);
  9493. engine.bindBuffersDirectly(this.vb, this.ib, [1], 4, effect);
  9494. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  9495. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  9496. }
  9497. effect.setBool("alphaTest", context.renderMode === BABYLON.Render2DContext.RenderModeAlphaTest);
  9498. var pid = context.groupInfoPartData[0];
  9499. if (context.useInstancing) {
  9500. if (!this.instancingAttributes) {
  9501. this.instancingAttributes = this.loadInstancingAttributes(Sprite2D.SPRITE2D_MAINPARTID, effect);
  9502. }
  9503. var glBuffer = context.instancedBuffers ? context.instancedBuffers[0] : pid._partBuffer;
  9504. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  9505. canvas._addDrawCallCount(1, context.renderMode);
  9506. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingAttributes);
  9507. engine.draw(true, 0, 6, count);
  9508. engine.unbindInstanceAttributes();
  9509. }
  9510. else {
  9511. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  9512. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  9513. this.setupUniforms(effect, 0, pid._partData, i);
  9514. engine.draw(true, 0, 6);
  9515. }
  9516. }
  9517. engine.setAlphaMode(cur, true);
  9518. return true;
  9519. };
  9520. Sprite2DRenderCache.prototype.dispose = function () {
  9521. if (!_super.prototype.dispose.call(this)) {
  9522. return false;
  9523. }
  9524. if (this.vb) {
  9525. this._engine._releaseBuffer(this.vb);
  9526. this.vb = null;
  9527. }
  9528. if (this.ib) {
  9529. this._engine._releaseBuffer(this.ib);
  9530. this.ib = null;
  9531. }
  9532. //if (this.texture) {
  9533. // this.texture.dispose();
  9534. // this.texture = null;
  9535. //}
  9536. this.effect = null;
  9537. this.effectInstanced = null;
  9538. return true;
  9539. };
  9540. return Sprite2DRenderCache;
  9541. }(BABYLON.ModelRenderCache));
  9542. BABYLON.Sprite2DRenderCache = Sprite2DRenderCache;
  9543. var Sprite2DInstanceData = (function (_super) {
  9544. __extends(Sprite2DInstanceData, _super);
  9545. function Sprite2DInstanceData(partId) {
  9546. _super.call(this, partId, 1);
  9547. }
  9548. Object.defineProperty(Sprite2DInstanceData.prototype, "topLeftUV", {
  9549. get: function () {
  9550. return null;
  9551. },
  9552. set: function (value) {
  9553. },
  9554. enumerable: true,
  9555. configurable: true
  9556. });
  9557. Object.defineProperty(Sprite2DInstanceData.prototype, "sizeUV", {
  9558. get: function () {
  9559. return null;
  9560. },
  9561. set: function (value) {
  9562. },
  9563. enumerable: true,
  9564. configurable: true
  9565. });
  9566. Object.defineProperty(Sprite2DInstanceData.prototype, "scaleFactor", {
  9567. get: function () {
  9568. return null;
  9569. },
  9570. set: function (value) {
  9571. },
  9572. enumerable: true,
  9573. configurable: true
  9574. });
  9575. Object.defineProperty(Sprite2DInstanceData.prototype, "textureSize", {
  9576. get: function () {
  9577. return null;
  9578. },
  9579. set: function (value) {
  9580. },
  9581. enumerable: true,
  9582. configurable: true
  9583. });
  9584. Object.defineProperty(Sprite2DInstanceData.prototype, "properties", {
  9585. // 3 floats being:
  9586. // - x: frame number to display
  9587. // - y: invertY setting
  9588. // - z: alignToPixel setting
  9589. get: function () {
  9590. return null;
  9591. },
  9592. set: function (value) {
  9593. },
  9594. enumerable: true,
  9595. configurable: true
  9596. });
  9597. __decorate([
  9598. BABYLON.instanceData()
  9599. ], Sprite2DInstanceData.prototype, "topLeftUV", null);
  9600. __decorate([
  9601. BABYLON.instanceData()
  9602. ], Sprite2DInstanceData.prototype, "sizeUV", null);
  9603. __decorate([
  9604. BABYLON.instanceData()
  9605. ], Sprite2DInstanceData.prototype, "scaleFactor", null);
  9606. __decorate([
  9607. BABYLON.instanceData()
  9608. ], Sprite2DInstanceData.prototype, "textureSize", null);
  9609. __decorate([
  9610. BABYLON.instanceData()
  9611. ], Sprite2DInstanceData.prototype, "properties", null);
  9612. return Sprite2DInstanceData;
  9613. }(BABYLON.InstanceDataBase));
  9614. BABYLON.Sprite2DInstanceData = Sprite2DInstanceData;
  9615. var Sprite2D = (function (_super) {
  9616. __extends(Sprite2D, _super);
  9617. /**
  9618. * Create an 2D Sprite primitive
  9619. * @param texture the texture that stores the sprite to render
  9620. * @param settings a combination of settings, possible ones are
  9621. * - 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)
  9622. * - children: an array of direct children
  9623. * - id a text identifier, for information purpose
  9624. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  9625. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  9626. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  9627. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  9628. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  9629. * - zOrder: override the zOrder with the specified value
  9630. * - origin: define the normalized origin point location, default [0.5;0.5]
  9631. * - spriteSize: the size of the sprite (in pixels), if null the size of the given texture will be used, default is null.
  9632. * - spriteLocation: the location (in pixels) in the texture of the top/left corner of the Sprite to display, default is null (0,0)
  9633. * - 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.
  9634. * - invertY: if true the texture Y will be inverted, default is false.
  9635. * - 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.
  9636. * - isVisible: true if the sprite must be visible, false for hidden. Default is true.
  9637. * - 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.
  9638. * - 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.
  9639. * - 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!
  9640. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9641. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9642. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9643. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9644. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  9645. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  9646. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  9647. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  9648. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9649. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9650. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9651. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9652. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  9653. */
  9654. function Sprite2D(texture, settings) {
  9655. var _this = this;
  9656. if (!settings) {
  9657. settings = {};
  9658. }
  9659. _super.call(this, settings);
  9660. this.texture = texture;
  9661. this.texture.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
  9662. this.texture.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
  9663. this.size = (settings.spriteSize != null) ? settings.spriteSize.clone() : null;
  9664. this.spriteLocation = (settings.spriteLocation != null) ? settings.spriteLocation.clone() : new BABYLON.Vector2(0, 0);
  9665. this.spriteScaleFactor = (settings.spriteScaleFactor != null) ? settings.spriteScaleFactor : new BABYLON.Vector2(1, 1);
  9666. this.spriteFrame = 0;
  9667. this.invertY = (settings.invertY == null) ? false : settings.invertY;
  9668. this.alignToPixel = (settings.alignToPixel == null) ? true : settings.alignToPixel;
  9669. this.useAlphaFromTexture = true;
  9670. // 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.
  9671. // The fucking delayed texture sprite bug is fixed!
  9672. if (settings.spriteSize == null) {
  9673. this.size = new BABYLON.Size(10, 10);
  9674. }
  9675. if (settings.spriteSize == null || !texture.isReady()) {
  9676. if (texture.isReady()) {
  9677. var s = texture.getBaseSize();
  9678. this.size = new BABYLON.Size(s.width, s.height);
  9679. }
  9680. else {
  9681. texture.onLoadObservable.add(function () {
  9682. if (settings.spriteSize == null) {
  9683. var s = texture.getBaseSize();
  9684. _this.size = new BABYLON.Size(s.width, s.height);
  9685. }
  9686. _this._positioningDirty();
  9687. _this._setLayoutDirty();
  9688. _this._instanceDirtyFlags |= BABYLON.Prim2DBase.originProperty.flagId | Sprite2D.textureProperty.flagId; // To make sure the sprite is issued again for render
  9689. });
  9690. }
  9691. }
  9692. }
  9693. Object.defineProperty(Sprite2D.prototype, "texture", {
  9694. get: function () {
  9695. return this._texture;
  9696. },
  9697. set: function (value) {
  9698. this._texture = value;
  9699. this._oldTextureHasAlpha = this._texture && this.texture.hasAlpha;
  9700. },
  9701. enumerable: true,
  9702. configurable: true
  9703. });
  9704. Object.defineProperty(Sprite2D.prototype, "useAlphaFromTexture", {
  9705. get: function () {
  9706. return this._useAlphaFromTexture;
  9707. },
  9708. set: function (value) {
  9709. if (this._useAlphaFromTexture === value) {
  9710. return;
  9711. }
  9712. this._useAlphaFromTexture = value;
  9713. this._updateRenderMode();
  9714. },
  9715. enumerable: true,
  9716. configurable: true
  9717. });
  9718. Object.defineProperty(Sprite2D.prototype, "actualSize", {
  9719. get: function () {
  9720. if (this._actualSize) {
  9721. return this._actualSize;
  9722. }
  9723. return this.size;
  9724. },
  9725. set: function (value) {
  9726. this._actualSize = value;
  9727. },
  9728. enumerable: true,
  9729. configurable: true
  9730. });
  9731. Object.defineProperty(Sprite2D.prototype, "spriteLocation", {
  9732. get: function () {
  9733. return this._location;
  9734. },
  9735. set: function (value) {
  9736. this._location = value;
  9737. },
  9738. enumerable: true,
  9739. configurable: true
  9740. });
  9741. Object.defineProperty(Sprite2D.prototype, "spriteFrame", {
  9742. get: function () {
  9743. return this._spriteFrame;
  9744. },
  9745. set: function (value) {
  9746. this._spriteFrame = value;
  9747. },
  9748. enumerable: true,
  9749. configurable: true
  9750. });
  9751. Object.defineProperty(Sprite2D.prototype, "invertY", {
  9752. get: function () {
  9753. return this._invertY;
  9754. },
  9755. set: function (value) {
  9756. this._invertY = value;
  9757. },
  9758. enumerable: true,
  9759. configurable: true
  9760. });
  9761. Object.defineProperty(Sprite2D.prototype, "spriteScaleFactor", {
  9762. get: function () {
  9763. return this._spriteScaleFactor;
  9764. },
  9765. set: function (value) {
  9766. this._spriteScaleFactor = value;
  9767. },
  9768. enumerable: true,
  9769. configurable: true
  9770. });
  9771. /**
  9772. * Sets the scale of the sprite using a BABYLON.Size(w,h).
  9773. * Keeps proportion by taking the maximum of the two scale for x and y.
  9774. * @param {Size} size Size(width,height)
  9775. */
  9776. Sprite2D.prototype.scaleToSize = function (size) {
  9777. var baseSize = this.size;
  9778. if (baseSize == null || !this.texture.isReady()) {
  9779. // we're probably at initiation of the scene, size is not set
  9780. if (this.texture.isReady()) {
  9781. baseSize = this.texture.getBaseSize();
  9782. }
  9783. else {
  9784. // the texture is not ready, wait for it to load before calling scaleToSize again
  9785. var thisObject = this;
  9786. this.texture.onLoadObservable.add(function () {
  9787. thisObject.scaleToSize(size);
  9788. });
  9789. return;
  9790. }
  9791. }
  9792. this.scale = Math.max(size.height / baseSize.height, size.width / baseSize.width);
  9793. };
  9794. Object.defineProperty(Sprite2D.prototype, "alignToPixel", {
  9795. /**
  9796. * Get/set if the sprite rendering should be aligned to the target rendering device pixel or not
  9797. */
  9798. get: function () {
  9799. return this._alignToPixel;
  9800. },
  9801. set: function (value) {
  9802. this._alignToPixel = value;
  9803. },
  9804. enumerable: true,
  9805. configurable: true
  9806. });
  9807. Sprite2D.prototype.updateLevelBoundingInfo = function () {
  9808. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.size, this._levelBoundingInfo);
  9809. };
  9810. /**
  9811. * Get the animatable array (see http://doc.babylonjs.com/tutorials/Animations)
  9812. */
  9813. Sprite2D.prototype.getAnimatables = function () {
  9814. var res = new Array();
  9815. if (this.texture && this.texture.animations && this.texture.animations.length > 0) {
  9816. res.push(this.texture);
  9817. }
  9818. return res;
  9819. };
  9820. Sprite2D.prototype.levelIntersect = function (intersectInfo) {
  9821. // 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
  9822. return true;
  9823. };
  9824. Sprite2D.prototype.createModelRenderCache = function (modelKey) {
  9825. var renderCache = new Sprite2DRenderCache(this.owner.engine, modelKey);
  9826. return renderCache;
  9827. };
  9828. Sprite2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  9829. var renderCache = modelRenderCache;
  9830. var engine = this.owner.engine;
  9831. var vb = new Float32Array(4);
  9832. for (var i = 0; i < 4; i++) {
  9833. vb[i] = i;
  9834. }
  9835. renderCache.vb = engine.createVertexBuffer(vb);
  9836. var ib = new Float32Array(6);
  9837. ib[0] = 0;
  9838. ib[1] = 2;
  9839. ib[2] = 1;
  9840. ib[3] = 0;
  9841. ib[4] = 3;
  9842. ib[5] = 2;
  9843. renderCache.ib = engine.createIndexBuffer(ib);
  9844. renderCache.texture = this.texture;
  9845. // 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
  9846. var ei = this.getDataPartEffectInfo(Sprite2D.SPRITE2D_MAINPARTID, ["index"], ["alphaTest"], true);
  9847. if (ei) {
  9848. renderCache.effectInstanced = engine.createEffect("sprite2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  9849. }
  9850. ei = this.getDataPartEffectInfo(Sprite2D.SPRITE2D_MAINPARTID, ["index"], ["alphaTest"], false);
  9851. renderCache.effect = engine.createEffect("sprite2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  9852. return renderCache;
  9853. };
  9854. Sprite2D.prototype.createInstanceDataParts = function () {
  9855. return [new Sprite2DInstanceData(Sprite2D.SPRITE2D_MAINPARTID)];
  9856. };
  9857. Sprite2D.prototype.beforeRefreshForLayoutConstruction = function (part) {
  9858. Sprite2D.layoutConstructMode = true;
  9859. };
  9860. // if obj contains something, we restore the _text property
  9861. Sprite2D.prototype.afterRefreshForLayoutConstruction = function (part, obj) {
  9862. Sprite2D.layoutConstructMode = false;
  9863. };
  9864. Sprite2D.prototype.refreshInstanceDataPart = function (part) {
  9865. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  9866. return false;
  9867. }
  9868. if (!this.texture.isReady() && !Sprite2D.layoutConstructMode) {
  9869. return false;
  9870. }
  9871. if (part.id === Sprite2D.SPRITE2D_MAINPARTID) {
  9872. var d = this._instanceDataParts[0];
  9873. if (Sprite2D.layoutConstructMode) {
  9874. d.topLeftUV = BABYLON.Vector2.Zero();
  9875. d.sizeUV = BABYLON.Vector2.Zero();
  9876. d.properties = BABYLON.Vector3.Zero();
  9877. d.textureSize = BABYLON.Vector2.Zero();
  9878. d.scaleFactor = BABYLON.Vector2.Zero();
  9879. }
  9880. else {
  9881. var ts = this.texture.getBaseSize();
  9882. var sl = this.spriteLocation;
  9883. var ss = this.actualSize;
  9884. var ssf = this.spriteScaleFactor;
  9885. d.topLeftUV = new BABYLON.Vector2(sl.x / ts.width, sl.y / ts.height);
  9886. var suv = new BABYLON.Vector2(ss.width / ts.width, ss.height / ts.height);
  9887. d.sizeUV = suv;
  9888. d.scaleFactor = ssf;
  9889. Sprite2D._prop.x = this.spriteFrame;
  9890. Sprite2D._prop.y = this.invertY ? 1 : 0;
  9891. Sprite2D._prop.z = this.alignToPixel ? 1 : 0;
  9892. d.properties = Sprite2D._prop;
  9893. d.textureSize = new BABYLON.Vector2(ts.width, ts.height);
  9894. }
  9895. }
  9896. return true;
  9897. };
  9898. Sprite2D.prototype._mustUpdateInstance = function () {
  9899. var res = this._oldTextureHasAlpha !== (this.texture != null && this.texture.hasAlpha);
  9900. this._oldTextureHasAlpha = this.texture != null && this.texture.hasAlpha;
  9901. if (res) {
  9902. this._updateRenderMode();
  9903. }
  9904. return res;
  9905. };
  9906. Sprite2D.prototype._useTextureAlpha = function () {
  9907. return this.texture != null && this.texture.hasAlpha;
  9908. };
  9909. Sprite2D.prototype._shouldUseAlphaFromTexture = function () {
  9910. return this.texture != null && this.texture.hasAlpha && this.useAlphaFromTexture;
  9911. };
  9912. Sprite2D.SPRITE2D_MAINPARTID = 1;
  9913. Sprite2D._prop = BABYLON.Vector3.Zero();
  9914. Sprite2D.layoutConstructMode = false;
  9915. __decorate([
  9916. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 1, function (pi) { return Sprite2D.textureProperty = pi; })
  9917. ], Sprite2D.prototype, "texture", null);
  9918. __decorate([
  9919. BABYLON.dynamicLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 2, function (pi) { return Sprite2D.useAlphaFromTextureProperty = pi; })
  9920. ], Sprite2D.prototype, "useAlphaFromTexture", null);
  9921. __decorate([
  9922. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 3, function (pi) { return Sprite2D.actualSizeProperty = pi; }, false, true)
  9923. ], Sprite2D.prototype, "actualSize", null);
  9924. __decorate([
  9925. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 4, function (pi) { return Sprite2D.spriteLocationProperty = pi; })
  9926. ], Sprite2D.prototype, "spriteLocation", null);
  9927. __decorate([
  9928. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 5, function (pi) { return Sprite2D.spriteFrameProperty = pi; })
  9929. ], Sprite2D.prototype, "spriteFrame", null);
  9930. __decorate([
  9931. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 6, function (pi) { return Sprite2D.invertYProperty = pi; })
  9932. ], Sprite2D.prototype, "invertY", null);
  9933. __decorate([
  9934. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 7, function (pi) { return Sprite2D.spriteScaleFactorProperty = pi; })
  9935. ], Sprite2D.prototype, "spriteScaleFactor", null);
  9936. Sprite2D = __decorate([
  9937. BABYLON.className("Sprite2D", "BABYLON")
  9938. ], Sprite2D);
  9939. return Sprite2D;
  9940. }(BABYLON.RenderablePrim2D));
  9941. BABYLON.Sprite2D = Sprite2D;
  9942. })(BABYLON || (BABYLON = {}));
  9943. //# sourceMappingURL=babylon.sprite2d.js.map
  9944. var __extends = (this && this.__extends) || function (d, b) {
  9945. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  9946. function __() { this.constructor = d; }
  9947. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9948. };
  9949. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  9950. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  9951. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  9952. 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;
  9953. return c > 3 && r && Object.defineProperty(target, key, r), r;
  9954. };
  9955. var BABYLON;
  9956. (function (BABYLON) {
  9957. var Text2DRenderCache = (function (_super) {
  9958. __extends(Text2DRenderCache, _super);
  9959. function Text2DRenderCache() {
  9960. _super.apply(this, arguments);
  9961. this.effectsReady = false;
  9962. this.vb = null;
  9963. this.ib = null;
  9964. this.instancingAttributes = null;
  9965. this.fontTexture = null;
  9966. this.effect = null;
  9967. this.effectInstanced = null;
  9968. }
  9969. Text2DRenderCache.prototype.render = function (instanceInfo, context) {
  9970. // Do nothing if the shader is still loading/preparing
  9971. if (!this.effectsReady) {
  9972. if ((this.effect && (!this.effect.isReady() || (this.effectInstanced && !this.effectInstanced.isReady())))) {
  9973. return false;
  9974. }
  9975. this.effectsReady = true;
  9976. }
  9977. var canvas = instanceInfo.owner.owner;
  9978. var engine = canvas.engine;
  9979. this.fontTexture.update();
  9980. var effect = context.useInstancing ? this.effectInstanced : this.effect;
  9981. engine.enableEffect(effect);
  9982. effect.setTexture("diffuseSampler", this.fontTexture);
  9983. engine.bindBuffersDirectly(this.vb, this.ib, [1], 4, effect);
  9984. var sdf = this.fontTexture.isSignedDistanceField;
  9985. // Enable alpha mode only if the texture is not using SDF, SDF is rendered in AlphaTest mode, which mean no alpha blend
  9986. var curAlphaMode;
  9987. if (!sdf) {
  9988. curAlphaMode = engine.getAlphaMode();
  9989. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  9990. }
  9991. var pid = context.groupInfoPartData[0];
  9992. if (context.useInstancing) {
  9993. if (!this.instancingAttributes) {
  9994. this.instancingAttributes = this.loadInstancingAttributes(Text2D.TEXT2D_MAINPARTID, effect);
  9995. }
  9996. var glBuffer = context.instancedBuffers ? context.instancedBuffers[0] : pid._partBuffer;
  9997. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  9998. canvas._addDrawCallCount(1, context.renderMode);
  9999. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingAttributes);
  10000. engine.draw(true, 0, 6, count);
  10001. engine.unbindInstanceAttributes();
  10002. }
  10003. else {
  10004. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  10005. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  10006. this.setupUniforms(effect, 0, pid._partData, i);
  10007. engine.draw(true, 0, 6);
  10008. }
  10009. }
  10010. if (!sdf) {
  10011. engine.setAlphaMode(curAlphaMode, true);
  10012. }
  10013. return true;
  10014. };
  10015. Text2DRenderCache.prototype.dispose = function () {
  10016. if (!_super.prototype.dispose.call(this)) {
  10017. return false;
  10018. }
  10019. if (this.vb) {
  10020. this._engine._releaseBuffer(this.vb);
  10021. this.vb = null;
  10022. }
  10023. if (this.ib) {
  10024. this._engine._releaseBuffer(this.ib);
  10025. this.ib = null;
  10026. }
  10027. if (this.fontTexture) {
  10028. this.fontTexture.decCachedFontTextureCounter();
  10029. this.fontTexture = null;
  10030. }
  10031. this.effect = null;
  10032. this.effectInstanced = null;
  10033. return true;
  10034. };
  10035. return Text2DRenderCache;
  10036. }(BABYLON.ModelRenderCache));
  10037. BABYLON.Text2DRenderCache = Text2DRenderCache;
  10038. var Text2DInstanceData = (function (_super) {
  10039. __extends(Text2DInstanceData, _super);
  10040. function Text2DInstanceData(partId, dataElementCount) {
  10041. _super.call(this, partId, dataElementCount);
  10042. }
  10043. Object.defineProperty(Text2DInstanceData.prototype, "topLeftUV", {
  10044. get: function () {
  10045. return null;
  10046. },
  10047. set: function (value) {
  10048. },
  10049. enumerable: true,
  10050. configurable: true
  10051. });
  10052. Object.defineProperty(Text2DInstanceData.prototype, "sizeUV", {
  10053. get: function () {
  10054. return null;
  10055. },
  10056. set: function (value) {
  10057. },
  10058. enumerable: true,
  10059. configurable: true
  10060. });
  10061. Object.defineProperty(Text2DInstanceData.prototype, "textureSize", {
  10062. get: function () {
  10063. return null;
  10064. },
  10065. set: function (value) {
  10066. },
  10067. enumerable: true,
  10068. configurable: true
  10069. });
  10070. Object.defineProperty(Text2DInstanceData.prototype, "color", {
  10071. get: function () {
  10072. return null;
  10073. },
  10074. set: function (value) {
  10075. },
  10076. enumerable: true,
  10077. configurable: true
  10078. });
  10079. Object.defineProperty(Text2DInstanceData.prototype, "superSampleFactor", {
  10080. get: function () {
  10081. return null;
  10082. },
  10083. set: function (value) {
  10084. },
  10085. enumerable: true,
  10086. configurable: true
  10087. });
  10088. __decorate([
  10089. BABYLON.instanceData()
  10090. ], Text2DInstanceData.prototype, "topLeftUV", null);
  10091. __decorate([
  10092. BABYLON.instanceData()
  10093. ], Text2DInstanceData.prototype, "sizeUV", null);
  10094. __decorate([
  10095. BABYLON.instanceData()
  10096. ], Text2DInstanceData.prototype, "textureSize", null);
  10097. __decorate([
  10098. BABYLON.instanceData()
  10099. ], Text2DInstanceData.prototype, "color", null);
  10100. __decorate([
  10101. BABYLON.instanceData()
  10102. ], Text2DInstanceData.prototype, "superSampleFactor", null);
  10103. return Text2DInstanceData;
  10104. }(BABYLON.InstanceDataBase));
  10105. BABYLON.Text2DInstanceData = Text2DInstanceData;
  10106. var Text2D = (function (_super) {
  10107. __extends(Text2D, _super);
  10108. /**
  10109. * Create a Text primitive
  10110. * @param text the text to display
  10111. * @param settings a combination of settings, possible ones are
  10112. * - 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)
  10113. * - children: an array of direct children
  10114. * - id a text identifier, for information purpose
  10115. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  10116. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  10117. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  10118. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  10119. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  10120. * - zOrder: override the zOrder with the specified value
  10121. * - origin: define the normalized origin point location, default [0.5;0.5]
  10122. * - fontName: the name/size/style of the font to use, following the CSS notation. Default is "12pt Arial".
  10123. * - 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.
  10124. * - 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.
  10125. * - defaultFontColor: the color by default to apply on each letter of the text to display, default is plain white.
  10126. * - areaSize: the size of the area in which to display the text, default is auto-fit from text content.
  10127. * - tabulationSize: number of space character to insert when a tabulation is encountered, default is 4
  10128. * - isVisible: true if the text must be visible, false for hidden. Default is true.
  10129. * - 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.
  10130. * - 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.
  10131. * - 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!
  10132. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10133. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10134. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10135. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10136. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  10137. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  10138. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  10139. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  10140. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10141. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10142. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10143. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10144. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  10145. */
  10146. function Text2D(text, settings) {
  10147. if (!settings) {
  10148. settings = {};
  10149. }
  10150. _super.call(this, settings);
  10151. this.fontName = (settings.fontName == null) ? "12pt Arial" : settings.fontName;
  10152. this._fontSuperSample = (settings.fontSuperSample != null && settings.fontSuperSample);
  10153. this._fontSDF = (settings.fontSignedDistanceField != null && settings.fontSignedDistanceField);
  10154. this.defaultFontColor = (settings.defaultFontColor == null) ? new BABYLON.Color4(1, 1, 1, 1) : settings.defaultFontColor;
  10155. this._tabulationSize = (settings.tabulationSize == null) ? 4 : settings.tabulationSize;
  10156. this._textSize = null;
  10157. this.text = text;
  10158. this.size = (settings.size == null) ? null : settings.size;
  10159. this._updateRenderMode();
  10160. }
  10161. Object.defineProperty(Text2D.prototype, "fontName", {
  10162. get: function () {
  10163. return this._fontName;
  10164. },
  10165. set: function (value) {
  10166. if (this._fontName) {
  10167. throw new Error("Font Name change is not supported right now.");
  10168. }
  10169. this._fontName = value;
  10170. },
  10171. enumerable: true,
  10172. configurable: true
  10173. });
  10174. Object.defineProperty(Text2D.prototype, "defaultFontColor", {
  10175. get: function () {
  10176. return this._defaultFontColor;
  10177. },
  10178. set: function (value) {
  10179. this._defaultFontColor = value;
  10180. },
  10181. enumerable: true,
  10182. configurable: true
  10183. });
  10184. Object.defineProperty(Text2D.prototype, "text", {
  10185. get: function () {
  10186. return this._text;
  10187. },
  10188. set: function (value) {
  10189. if (!value) {
  10190. value = "";
  10191. }
  10192. this._text = value;
  10193. this._textSize = null; // A change of text will reset the TextSize which will be recomputed next time it's used
  10194. this._size = null;
  10195. this._updateCharCount();
  10196. // Trigger a textSize to for a sizeChange if necessary, which is needed for layout to recompute
  10197. var s = this.textSize;
  10198. },
  10199. enumerable: true,
  10200. configurable: true
  10201. });
  10202. Object.defineProperty(Text2D.prototype, "size", {
  10203. get: function () {
  10204. if (this._size != null) {
  10205. return this._size;
  10206. }
  10207. return this.textSize;
  10208. },
  10209. set: function (value) {
  10210. this._size = value;
  10211. },
  10212. enumerable: true,
  10213. configurable: true
  10214. });
  10215. Object.defineProperty(Text2D.prototype, "fontSuperSample", {
  10216. get: function () {
  10217. return this._fontTexture && this._fontTexture.isSuperSampled;
  10218. },
  10219. enumerable: true,
  10220. configurable: true
  10221. });
  10222. Object.defineProperty(Text2D.prototype, "fontSignedDistanceField", {
  10223. get: function () {
  10224. return this._fontTexture && this._fontTexture.isSignedDistanceField;
  10225. },
  10226. enumerable: true,
  10227. configurable: true
  10228. });
  10229. Object.defineProperty(Text2D.prototype, "isSizeAuto", {
  10230. get: function () {
  10231. return false;
  10232. },
  10233. enumerable: true,
  10234. configurable: true
  10235. });
  10236. Object.defineProperty(Text2D.prototype, "actualSize", {
  10237. /**
  10238. * Get the actual size of the Text2D primitive
  10239. */
  10240. get: function () {
  10241. if (this._actualSize) {
  10242. return this._actualSize;
  10243. }
  10244. return this.size;
  10245. },
  10246. enumerable: true,
  10247. configurable: true
  10248. });
  10249. Object.defineProperty(Text2D.prototype, "textSize", {
  10250. /**
  10251. * Get the area that bounds the text associated to the primitive
  10252. */
  10253. get: function () {
  10254. if (!this._textSize) {
  10255. if (this.owner && this._text) {
  10256. var newSize = this.fontTexture.measureText(this._text, this._tabulationSize);
  10257. if (!newSize.equals(this._textSize)) {
  10258. this.onPrimitivePropertyDirty(BABYLON.Prim2DBase.sizeProperty.flagId);
  10259. this._positioningDirty();
  10260. }
  10261. this._textSize = newSize;
  10262. }
  10263. else {
  10264. return Text2D.nullSize;
  10265. }
  10266. }
  10267. return this._textSize;
  10268. },
  10269. enumerable: true,
  10270. configurable: true
  10271. });
  10272. Object.defineProperty(Text2D.prototype, "fontTexture", {
  10273. get: function () {
  10274. if (this._fontTexture) {
  10275. return this._fontTexture;
  10276. }
  10277. if (this.fontName == null || this.owner == null || this.owner.scene == null) {
  10278. return null;
  10279. }
  10280. this._fontTexture = BABYLON.FontTexture.GetCachedFontTexture(this.owner.scene, this.fontName, this._fontSuperSample, this._fontSDF);
  10281. return this._fontTexture;
  10282. },
  10283. enumerable: true,
  10284. configurable: true
  10285. });
  10286. /**
  10287. * Dispose the primitive, remove it from its parent
  10288. */
  10289. Text2D.prototype.dispose = function () {
  10290. if (!_super.prototype.dispose.call(this)) {
  10291. return false;
  10292. }
  10293. if (this._fontTexture) {
  10294. BABYLON.FontTexture.ReleaseCachedFontTexture(this.owner.scene, this.fontName, this._fontSuperSample, this._fontSDF);
  10295. this._fontTexture = null;
  10296. }
  10297. return true;
  10298. };
  10299. Text2D.prototype.updateLevelBoundingInfo = function () {
  10300. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.actualSize, this._levelBoundingInfo);
  10301. };
  10302. Text2D.prototype.levelIntersect = function (intersectInfo) {
  10303. // 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...
  10304. return true;
  10305. };
  10306. Text2D.prototype.createModelRenderCache = function (modelKey) {
  10307. var renderCache = new Text2DRenderCache(this.owner.engine, modelKey);
  10308. return renderCache;
  10309. };
  10310. Text2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  10311. var renderCache = modelRenderCache;
  10312. var engine = this.owner.engine;
  10313. renderCache.fontTexture = this.fontTexture;
  10314. renderCache.fontTexture.incCachedFontTextureCounter();
  10315. var vb = new Float32Array(4);
  10316. for (var i = 0; i < 4; i++) {
  10317. vb[i] = i;
  10318. }
  10319. renderCache.vb = engine.createVertexBuffer(vb);
  10320. var ib = new Float32Array(6);
  10321. ib[0] = 0;
  10322. ib[1] = 2;
  10323. ib[2] = 1;
  10324. ib[3] = 0;
  10325. ib[4] = 3;
  10326. ib[5] = 2;
  10327. renderCache.ib = engine.createIndexBuffer(ib);
  10328. // 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
  10329. var ei = this.getDataPartEffectInfo(Text2D.TEXT2D_MAINPARTID, ["index"], null, true);
  10330. if (ei) {
  10331. renderCache.effectInstanced = engine.createEffect("text2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  10332. }
  10333. ei = this.getDataPartEffectInfo(Text2D.TEXT2D_MAINPARTID, ["index"], null, false);
  10334. renderCache.effect = engine.createEffect("text2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  10335. return renderCache;
  10336. };
  10337. Text2D.prototype.createInstanceDataParts = function () {
  10338. return [new Text2DInstanceData(Text2D.TEXT2D_MAINPARTID, this._charCount)];
  10339. };
  10340. // Looks like a hack!? Yes! Because that's what it is!
  10341. // 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
  10342. // 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)
  10343. Text2D.prototype.beforeRefreshForLayoutConstruction = function (part) {
  10344. if (!this._charCount) {
  10345. var curText = this._text;
  10346. this.text = "A";
  10347. return curText;
  10348. }
  10349. };
  10350. // if obj contains something, we restore the _text property
  10351. Text2D.prototype.afterRefreshForLayoutConstruction = function (part, obj) {
  10352. if (obj !== undefined) {
  10353. this.text = obj;
  10354. }
  10355. };
  10356. Text2D.prototype.getUsedShaderCategories = function (dataPart) {
  10357. var cat = _super.prototype.getUsedShaderCategories.call(this, dataPart);
  10358. if (this._fontSDF) {
  10359. cat.push(Text2D.TEXT2D_CATEGORY_SDF);
  10360. }
  10361. return cat;
  10362. };
  10363. Text2D.prototype.refreshInstanceDataPart = function (part) {
  10364. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  10365. return false;
  10366. }
  10367. if (part.id === Text2D.TEXT2D_MAINPARTID) {
  10368. var d = part;
  10369. var texture = this.fontTexture;
  10370. var superSampleFactor = texture.isSuperSampled ? 0.5 : 1;
  10371. var ts = texture.getSize();
  10372. var offset = BABYLON.Vector2.Zero();
  10373. var lh = this.fontTexture.lineHeight;
  10374. 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
  10375. var charxpos = 0;
  10376. d.dataElementCount = this._charCount;
  10377. d.curElement = 0;
  10378. for (var _i = 0, _a = this.text; _i < _a.length; _i++) {
  10379. var char = _a[_i];
  10380. // Line feed
  10381. if (char === "\n") {
  10382. offset.x = 0;
  10383. offset.y -= texture.lineHeight;
  10384. }
  10385. // Tabulation ?
  10386. if (char === "\t") {
  10387. var nextPos = charxpos + this._tabulationSize;
  10388. nextPos = nextPos - (nextPos % this._tabulationSize);
  10389. offset.x += (nextPos - charxpos) * texture.spaceWidth;
  10390. charxpos = nextPos;
  10391. continue;
  10392. }
  10393. if (char < " ") {
  10394. continue;
  10395. }
  10396. this.updateInstanceDataPart(d, offset);
  10397. var ci = texture.getChar(char);
  10398. offset.x += ci.charWidth;
  10399. d.topLeftUV = ci.topLeftUV;
  10400. var suv = ci.bottomRightUV.subtract(ci.topLeftUV);
  10401. d.sizeUV = suv;
  10402. d.textureSize = new BABYLON.Vector2(ts.width, ts.height);
  10403. d.color = this.defaultFontColor;
  10404. d.superSampleFactor = superSampleFactor;
  10405. ++d.curElement;
  10406. }
  10407. }
  10408. return true;
  10409. };
  10410. Text2D.prototype._updateCharCount = function () {
  10411. var count = 0;
  10412. for (var _i = 0, _a = this._text; _i < _a.length; _i++) {
  10413. var char = _a[_i];
  10414. if (char === "\r" || char === "\n" || char === "\t" || char < " ") {
  10415. continue;
  10416. }
  10417. ++count;
  10418. }
  10419. this._charCount = count;
  10420. };
  10421. Text2D.prototype._useTextureAlpha = function () {
  10422. return this._fontSDF;
  10423. };
  10424. Text2D.prototype._shouldUseAlphaFromTexture = function () {
  10425. return !this._fontSDF;
  10426. };
  10427. Text2D.TEXT2D_MAINPARTID = 1;
  10428. Text2D.TEXT2D_CATEGORY_SDF = "SignedDistanceField";
  10429. __decorate([
  10430. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 1, function (pi) { return Text2D.fontProperty = pi; }, false, true)
  10431. ], Text2D.prototype, "fontName", null);
  10432. __decorate([
  10433. BABYLON.dynamicLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 2, function (pi) { return Text2D.defaultFontColorProperty = pi; })
  10434. ], Text2D.prototype, "defaultFontColor", null);
  10435. __decorate([
  10436. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 3, function (pi) { return Text2D.textProperty = pi; }, false, true)
  10437. ], Text2D.prototype, "text", null);
  10438. __decorate([
  10439. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 4, function (pi) { return Text2D.sizeProperty = pi; })
  10440. ], Text2D.prototype, "size", null);
  10441. __decorate([
  10442. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 5, function (pi) { return Text2D.fontSuperSampleProperty = pi; }, false, false)
  10443. ], Text2D.prototype, "fontSuperSample", null);
  10444. __decorate([
  10445. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 6, function (pi) { return Text2D.fontSuperSampleProperty = pi; }, false, false)
  10446. ], Text2D.prototype, "fontSignedDistanceField", null);
  10447. Text2D = __decorate([
  10448. BABYLON.className("Text2D", "BABYLON")
  10449. ], Text2D);
  10450. return Text2D;
  10451. }(BABYLON.RenderablePrim2D));
  10452. BABYLON.Text2D = Text2D;
  10453. })(BABYLON || (BABYLON = {}));
  10454. //# sourceMappingURL=babylon.text2d.js.map
  10455. var __extends = (this && this.__extends) || function (d, b) {
  10456. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  10457. function __() { this.constructor = d; }
  10458. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10459. };
  10460. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  10461. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  10462. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  10463. 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;
  10464. return c > 3 && r && Object.defineProperty(target, key, r), r;
  10465. };
  10466. var BABYLON;
  10467. (function (BABYLON) {
  10468. var Lines2DRenderCache = (function (_super) {
  10469. __extends(Lines2DRenderCache, _super);
  10470. function Lines2DRenderCache(engine, modelKey) {
  10471. _super.call(this, engine, modelKey);
  10472. this.effectsReady = false;
  10473. this.fillVB = null;
  10474. this.fillIB = null;
  10475. this.fillIndicesCount = 0;
  10476. this.instancingFillAttributes = null;
  10477. this.effectFill = null;
  10478. this.effectFillInstanced = null;
  10479. this.borderVB = null;
  10480. this.borderIB = null;
  10481. this.borderIndicesCount = 0;
  10482. this.instancingBorderAttributes = null;
  10483. this.effectBorder = null;
  10484. this.effectBorderInstanced = null;
  10485. }
  10486. Lines2DRenderCache.prototype.render = function (instanceInfo, context) {
  10487. // Do nothing if the shader is still loading/preparing
  10488. if (!this.effectsReady) {
  10489. if ((this.effectFill && (!this.effectFill.isReady() || (this.effectFillInstanced && !this.effectFillInstanced.isReady()))) ||
  10490. (this.effectBorder && (!this.effectBorder.isReady() || (this.effectBorderInstanced && !this.effectBorderInstanced.isReady())))) {
  10491. return false;
  10492. }
  10493. this.effectsReady = true;
  10494. }
  10495. var canvas = instanceInfo.owner.owner;
  10496. var engine = canvas.engine;
  10497. var depthFunction = 0;
  10498. if (this.effectFill && this.effectBorder) {
  10499. depthFunction = engine.getDepthFunction();
  10500. engine.setDepthFunctionToLessOrEqual();
  10501. }
  10502. var curAlphaMode = engine.getAlphaMode();
  10503. if (this.effectFill) {
  10504. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_FILLPARTID.toString());
  10505. var pid = context.groupInfoPartData[partIndex];
  10506. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  10507. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  10508. }
  10509. var effect = context.useInstancing ? this.effectFillInstanced : this.effectFill;
  10510. engine.enableEffect(effect);
  10511. engine.bindBuffersDirectly(this.fillVB, this.fillIB, [2], 2 * 4, effect);
  10512. if (context.useInstancing) {
  10513. if (!this.instancingFillAttributes) {
  10514. this.instancingFillAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_FILLPARTID, effect);
  10515. }
  10516. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  10517. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  10518. canvas._addDrawCallCount(1, context.renderMode);
  10519. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingFillAttributes);
  10520. engine.draw(true, 0, this.fillIndicesCount, count);
  10521. engine.unbindInstanceAttributes();
  10522. }
  10523. else {
  10524. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  10525. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  10526. this.setupUniforms(effect, partIndex, pid._partData, i);
  10527. engine.draw(true, 0, this.fillIndicesCount);
  10528. }
  10529. }
  10530. }
  10531. if (this.effectBorder) {
  10532. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_BORDERPARTID.toString());
  10533. var pid = context.groupInfoPartData[partIndex];
  10534. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  10535. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  10536. }
  10537. var effect = context.useInstancing ? this.effectBorderInstanced : this.effectBorder;
  10538. engine.enableEffect(effect);
  10539. engine.bindBuffersDirectly(this.borderVB, this.borderIB, [2], 2 * 4, effect);
  10540. if (context.useInstancing) {
  10541. if (!this.instancingBorderAttributes) {
  10542. this.instancingBorderAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, effect);
  10543. }
  10544. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  10545. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  10546. canvas._addDrawCallCount(1, context.renderMode);
  10547. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingBorderAttributes);
  10548. engine.draw(true, 0, this.borderIndicesCount, count);
  10549. engine.unbindInstanceAttributes();
  10550. }
  10551. else {
  10552. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  10553. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  10554. this.setupUniforms(effect, partIndex, pid._partData, i);
  10555. engine.draw(true, 0, this.borderIndicesCount);
  10556. }
  10557. }
  10558. }
  10559. engine.setAlphaMode(curAlphaMode, true);
  10560. if (this.effectFill && this.effectBorder) {
  10561. engine.setDepthFunction(depthFunction);
  10562. }
  10563. return true;
  10564. };
  10565. Lines2DRenderCache.prototype.dispose = function () {
  10566. if (!_super.prototype.dispose.call(this)) {
  10567. return false;
  10568. }
  10569. if (this.fillVB) {
  10570. this._engine._releaseBuffer(this.fillVB);
  10571. this.fillVB = null;
  10572. }
  10573. if (this.fillIB) {
  10574. this._engine._releaseBuffer(this.fillIB);
  10575. this.fillIB = null;
  10576. }
  10577. this.effectFill = null;
  10578. this.effectFillInstanced = null;
  10579. this.effectBorder = null;
  10580. this.effectBorderInstanced = null;
  10581. if (this.borderVB) {
  10582. this._engine._releaseBuffer(this.borderVB);
  10583. this.borderVB = null;
  10584. }
  10585. if (this.borderIB) {
  10586. this._engine._releaseBuffer(this.borderIB);
  10587. this.borderIB = null;
  10588. }
  10589. return true;
  10590. };
  10591. return Lines2DRenderCache;
  10592. }(BABYLON.ModelRenderCache));
  10593. BABYLON.Lines2DRenderCache = Lines2DRenderCache;
  10594. var Lines2DInstanceData = (function (_super) {
  10595. __extends(Lines2DInstanceData, _super);
  10596. function Lines2DInstanceData(partId) {
  10597. _super.call(this, partId, 1);
  10598. }
  10599. Object.defineProperty(Lines2DInstanceData.prototype, "boundingMin", {
  10600. get: function () {
  10601. return null;
  10602. },
  10603. set: function (value) {
  10604. },
  10605. enumerable: true,
  10606. configurable: true
  10607. });
  10608. Object.defineProperty(Lines2DInstanceData.prototype, "boundingMax", {
  10609. get: function () {
  10610. return null;
  10611. },
  10612. set: function (value) {
  10613. },
  10614. enumerable: true,
  10615. configurable: true
  10616. });
  10617. __decorate([
  10618. BABYLON.instanceData(BABYLON.Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  10619. ], Lines2DInstanceData.prototype, "boundingMin", null);
  10620. __decorate([
  10621. BABYLON.instanceData(BABYLON.Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  10622. ], Lines2DInstanceData.prototype, "boundingMax", null);
  10623. return Lines2DInstanceData;
  10624. }(BABYLON.Shape2DInstanceData));
  10625. BABYLON.Lines2DInstanceData = Lines2DInstanceData;
  10626. var Lines2D = (function (_super) {
  10627. __extends(Lines2D, _super);
  10628. /**
  10629. * Create an 2D Lines Shape primitive. The defined lines may be opened or closed (see below)
  10630. * @param points an array that describe the points to use to draw the line, must contain at least two entries.
  10631. * @param settings a combination of settings, possible ones are
  10632. * - 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)
  10633. * - children: an array of direct children
  10634. * - id a text identifier, for information purpose
  10635. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  10636. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  10637. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  10638. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  10639. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  10640. * - zOrder: override the zOrder with the specified value
  10641. * - origin: define the normalized origin point location, default [0.5;0.5]
  10642. * - 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.
  10643. * - 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.
  10644. * - 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.
  10645. * - 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.
  10646. * - 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)
  10647. * - 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)
  10648. * - borderThickness: the thickness of the drawn border, default is 1.
  10649. * - isVisible: true if the primitive must be visible, false for hidden. Default is true.
  10650. * - 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.
  10651. * - 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.
  10652. * - 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!
  10653. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10654. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10655. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10656. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10657. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  10658. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  10659. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  10660. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  10661. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10662. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10663. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10664. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10665. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  10666. */
  10667. function Lines2D(points, settings) {
  10668. if (!settings) {
  10669. settings = {};
  10670. }
  10671. _super.call(this, settings);
  10672. this._fillVB = null;
  10673. this._fillIB = null;
  10674. this._borderVB = null;
  10675. this._borderIB = null;
  10676. this._size = BABYLON.Size.Zero();
  10677. this._boundingMin = null;
  10678. this._boundingMax = null;
  10679. var fillThickness = (settings.fillThickness == null) ? 1 : settings.fillThickness;
  10680. var startCap = (settings.startCap == null) ? 0 : settings.startCap;
  10681. var endCap = (settings.endCap == null) ? 0 : settings.endCap;
  10682. var closed = (settings.closed == null) ? false : settings.closed;
  10683. this.points = points;
  10684. this.fillThickness = fillThickness;
  10685. this.startCap = startCap;
  10686. this.endCap = endCap;
  10687. this.closed = closed;
  10688. }
  10689. Object.defineProperty(Lines2D, "NoCap", {
  10690. /**
  10691. * No Cap to apply on the extremity
  10692. */
  10693. get: function () { return Lines2D._noCap; },
  10694. enumerable: true,
  10695. configurable: true
  10696. });
  10697. Object.defineProperty(Lines2D, "RoundCap", {
  10698. /**
  10699. * A round cap, will use the line thickness as diameter
  10700. */
  10701. get: function () { return Lines2D._roundCap; },
  10702. enumerable: true,
  10703. configurable: true
  10704. });
  10705. Object.defineProperty(Lines2D, "TriangleCap", {
  10706. /**
  10707. * Creates a triangle at the extremity.
  10708. */
  10709. get: function () { return Lines2D._triangleCap; },
  10710. enumerable: true,
  10711. configurable: true
  10712. });
  10713. Object.defineProperty(Lines2D, "SquareAnchorCap", {
  10714. /**
  10715. * Creates a Square anchor at the extremity, the square size is twice the thickness of the line
  10716. */
  10717. get: function () { return Lines2D._squareAnchorCap; },
  10718. enumerable: true,
  10719. configurable: true
  10720. });
  10721. Object.defineProperty(Lines2D, "RoundAnchorCap", {
  10722. /**
  10723. * Creates a round anchor at the extremity, the diameter is twice the thickness of the line
  10724. */
  10725. get: function () { return Lines2D._roundAnchorCap; },
  10726. enumerable: true,
  10727. configurable: true
  10728. });
  10729. Object.defineProperty(Lines2D, "DiamondAnchorCap", {
  10730. /**
  10731. * Creates a diamond anchor at the extremity.
  10732. */
  10733. get: function () { return Lines2D._diamondAnchorCap; },
  10734. enumerable: true,
  10735. configurable: true
  10736. });
  10737. Object.defineProperty(Lines2D, "ArrowCap", {
  10738. /**
  10739. * Creates an arrow anchor at the extremity. the arrow base size is twice the thickness of the line
  10740. */
  10741. get: function () { return Lines2D._arrowCap; },
  10742. enumerable: true,
  10743. configurable: true
  10744. });
  10745. Object.defineProperty(Lines2D.prototype, "points", {
  10746. get: function () {
  10747. return this._points;
  10748. },
  10749. set: function (value) {
  10750. this._points = value;
  10751. this._contour = null;
  10752. this._boundingBoxDirty();
  10753. },
  10754. enumerable: true,
  10755. configurable: true
  10756. });
  10757. Object.defineProperty(Lines2D.prototype, "fillThickness", {
  10758. get: function () {
  10759. return this._fillThickness;
  10760. },
  10761. set: function (value) {
  10762. this._fillThickness = value;
  10763. },
  10764. enumerable: true,
  10765. configurable: true
  10766. });
  10767. Object.defineProperty(Lines2D.prototype, "closed", {
  10768. get: function () {
  10769. return this._closed;
  10770. },
  10771. set: function (value) {
  10772. this._closed = value;
  10773. },
  10774. enumerable: true,
  10775. configurable: true
  10776. });
  10777. Object.defineProperty(Lines2D.prototype, "startCap", {
  10778. get: function () {
  10779. return this._startCap;
  10780. },
  10781. set: function (value) {
  10782. this._startCap = value;
  10783. },
  10784. enumerable: true,
  10785. configurable: true
  10786. });
  10787. Object.defineProperty(Lines2D.prototype, "endCap", {
  10788. get: function () {
  10789. return this._endCap;
  10790. },
  10791. set: function (value) {
  10792. this._endCap = value;
  10793. },
  10794. enumerable: true,
  10795. configurable: true
  10796. });
  10797. Lines2D.prototype.levelIntersect = function (intersectInfo) {
  10798. var _this = this;
  10799. if (this._contour == null) {
  10800. this._computeLines2D();
  10801. }
  10802. var pl = this.points.length;
  10803. var l = this.closed ? pl + 1 : pl;
  10804. var p = intersectInfo._localPickPosition;
  10805. this.transformPointWithOriginToRef(this._contour[0], null, Lines2D._prevA);
  10806. this.transformPointWithOriginToRef(this._contour[1], null, Lines2D._prevB);
  10807. for (var i = 1; i < l; i++) {
  10808. this.transformPointWithOriginToRef(this._contour[(i % pl) * 2 + 0], null, Lines2D._curA);
  10809. this.transformPointWithOriginToRef(this._contour[(i % pl) * 2 + 1], null, Lines2D._curB);
  10810. if (BABYLON.Vector2.PointInTriangle(p, Lines2D._prevA, Lines2D._prevB, Lines2D._curA)) {
  10811. return true;
  10812. }
  10813. if (BABYLON.Vector2.PointInTriangle(p, Lines2D._curA, Lines2D._prevB, Lines2D._curB)) {
  10814. return true;
  10815. }
  10816. Lines2D._prevA.x = Lines2D._curA.x;
  10817. Lines2D._prevA.y = Lines2D._curA.y;
  10818. Lines2D._prevB.x = Lines2D._curB.x;
  10819. Lines2D._prevB.y = Lines2D._curB.y;
  10820. }
  10821. var capIntersect = function (tri, points) {
  10822. var l = tri.length;
  10823. for (var i = 0; i < l; i += 3) {
  10824. Lines2D._curA.x = points[tri[i + 0] * 2 + 0];
  10825. Lines2D._curA.y = points[tri[i + 0] * 2 + 1];
  10826. _this.transformPointWithOriginToRef(Lines2D._curA, null, Lines2D._curB);
  10827. Lines2D._curA.x = points[tri[i + 1] * 2 + 0];
  10828. Lines2D._curA.y = points[tri[i + 1] * 2 + 1];
  10829. _this.transformPointWithOriginToRef(Lines2D._curA, null, Lines2D._prevA);
  10830. Lines2D._curA.x = points[tri[i + 2] * 2 + 0];
  10831. Lines2D._curA.y = points[tri[i + 2] * 2 + 1];
  10832. _this.transformPointWithOriginToRef(Lines2D._curA, null, Lines2D._prevB);
  10833. if (BABYLON.Vector2.PointInTriangle(p, Lines2D._prevA, Lines2D._prevB, Lines2D._curB)) {
  10834. return true;
  10835. }
  10836. }
  10837. return false;
  10838. };
  10839. if (this._startCapTriIndices) {
  10840. if (this._startCapTriIndices && capIntersect(this._startCapTriIndices, this._startCapContour)) {
  10841. return true;
  10842. }
  10843. if (this._endCapTriIndices && capIntersect(this._endCapTriIndices, this._endCapContour)) {
  10844. return true;
  10845. }
  10846. }
  10847. return false;
  10848. };
  10849. Object.defineProperty(Lines2D.prototype, "boundingMin", {
  10850. get: function () {
  10851. if (!this._boundingMin) {
  10852. this._computeLines2D();
  10853. }
  10854. return this._boundingMin;
  10855. },
  10856. enumerable: true,
  10857. configurable: true
  10858. });
  10859. Object.defineProperty(Lines2D.prototype, "boundingMax", {
  10860. get: function () {
  10861. if (!this._boundingMax) {
  10862. this._computeLines2D();
  10863. }
  10864. return this._boundingMax;
  10865. },
  10866. enumerable: true,
  10867. configurable: true
  10868. });
  10869. Lines2D.prototype.getUsedShaderCategories = function (dataPart) {
  10870. var res = _super.prototype.getUsedShaderCategories.call(this, dataPart);
  10871. // Remove the BORDER category, we don't use it in the VertexShader
  10872. var i = res.indexOf(BABYLON.Shape2D.SHAPE2D_CATEGORY_BORDER);
  10873. if (i !== -1) {
  10874. res.splice(i, 1);
  10875. }
  10876. return res;
  10877. };
  10878. Lines2D.prototype.updateLevelBoundingInfo = function () {
  10879. if (!this._boundingMin) {
  10880. this._computeLines2D();
  10881. }
  10882. BABYLON.BoundingInfo2D.CreateFromMinMaxToRef(this._boundingMin.x, this._boundingMax.x, this._boundingMin.y, this._boundingMax.y, this._levelBoundingInfo);
  10883. };
  10884. Lines2D.prototype.createModelRenderCache = function (modelKey) {
  10885. var renderCache = new Lines2DRenderCache(this.owner.engine, modelKey);
  10886. return renderCache;
  10887. };
  10888. ///////////////////////////////////////////////////////////////////////////////////
  10889. // Methods for Lines building
  10890. Lines2D.prototype._perp = function (v, res) {
  10891. res.x = v.y;
  10892. res.y = -v.x;
  10893. };
  10894. ;
  10895. Lines2D.prototype._direction = function (a, b, res) {
  10896. a.subtractToRef(b, res);
  10897. res.normalize();
  10898. };
  10899. Lines2D.prototype._computeMiter = function (tangent, miter, a, b) {
  10900. a.addToRef(b, tangent);
  10901. tangent.normalize();
  10902. miter.x = -tangent.y;
  10903. miter.y = tangent.x;
  10904. Lines2D._miterTps.x = -a.y;
  10905. Lines2D._miterTps.y = a.x;
  10906. return 1 / BABYLON.Vector2.Dot(miter, Lines2D._miterTps);
  10907. };
  10908. Lines2D.prototype._intersect = function (x1, y1, x2, y2, x3, y3, x4, y4) {
  10909. var d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
  10910. if (d === 0)
  10911. return false;
  10912. var xi = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d; // Intersection point is xi/yi, just in case...
  10913. //let yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d; // That's why I left it commented
  10914. if (xi < Math.min(x1, x2) || xi > Math.max(x1, x2))
  10915. return false;
  10916. if (xi < Math.min(x3, x4) || xi > Math.max(x3, x4))
  10917. return false;
  10918. return true;
  10919. };
  10920. Lines2D.prototype._updateMinMax = function (array, offset) {
  10921. if (offset >= array.length) {
  10922. return;
  10923. }
  10924. this._boundingMin.x = Math.min(this._boundingMin.x, array[offset]);
  10925. this._boundingMax.x = Math.max(this._boundingMax.x, array[offset]);
  10926. this._boundingMin.y = Math.min(this._boundingMin.y, array[offset + 1]);
  10927. this._boundingMax.y = Math.max(this._boundingMax.y, array[offset + 1]);
  10928. };
  10929. Lines2D.prototype._store = function (array, contour, index, max, p, n, halfThickness, borderThickness, detectFlip) {
  10930. var borderMode = borderThickness != null && !isNaN(borderThickness);
  10931. var off = index * (borderMode ? 8 : 4);
  10932. // 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)
  10933. if (off >= array.length) {
  10934. return;
  10935. }
  10936. // Store start/end normal, we need it for the cap construction
  10937. if (index === 0) {
  10938. this._perp(n, Lines2D._startDir);
  10939. }
  10940. else if (index === max - 1) {
  10941. this._perp(n, Lines2D._endDir);
  10942. Lines2D._endDir.x *= -1;
  10943. Lines2D._endDir.y *= -1;
  10944. }
  10945. var swap = false;
  10946. array[off + 0] = p.x + n.x * halfThickness;
  10947. array[off + 1] = p.y + n.y * halfThickness;
  10948. array[off + 2] = p.x + n.x * -halfThickness;
  10949. array[off + 3] = p.y + n.y * -halfThickness;
  10950. this._updateMinMax(array, off);
  10951. this._updateMinMax(array, off + 2);
  10952. // If an index is given we check if the two segments formed between [index+0;detectFlip+0] and [index+2;detectFlip+2] intersect themselves.
  10953. // 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
  10954. if (detectFlip != 0) {
  10955. // Flip if intersect
  10956. var flipOff = detectFlip * (borderMode ? 8 : 4);
  10957. 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])) {
  10958. swap = true;
  10959. var tps = array[off + 0];
  10960. array[off + 0] = array[off + 2];
  10961. array[off + 2] = tps;
  10962. tps = array[off + 1];
  10963. array[off + 1] = array[off + 3];
  10964. array[off + 3] = tps;
  10965. }
  10966. }
  10967. if (borderMode) {
  10968. var t = halfThickness + borderThickness;
  10969. array[off + 4] = p.x + n.x * (swap ? -t : t);
  10970. array[off + 5] = p.y + n.y * (swap ? -t : t);
  10971. array[off + 6] = p.x + n.x * (swap ? t : -t);
  10972. array[off + 7] = p.y + n.y * (swap ? t : -t);
  10973. this._updateMinMax(array, off + 4);
  10974. this._updateMinMax(array, off + 6);
  10975. }
  10976. if (contour) {
  10977. off += borderMode ? 4 : 0;
  10978. contour.push(new BABYLON.Vector2(array[off + 0], array[off + 1]));
  10979. contour.push(new BABYLON.Vector2(array[off + 2], array[off + 3]));
  10980. }
  10981. };
  10982. Lines2D.prototype._getCapSize = function (type, border) {
  10983. if (border === void 0) { border = false; }
  10984. var sd = Lines2D._roundCapSubDiv;
  10985. // If no array given, we call this to get the size
  10986. var vbsize = 0, ibsize = 0;
  10987. switch (type) {
  10988. case Lines2D.NoCap:
  10989. {
  10990. // If the line is not close and we're computing border, we add the size to generate the edge border
  10991. if (!this.closed && border) {
  10992. vbsize = 4;
  10993. ibsize = 6;
  10994. }
  10995. else {
  10996. vbsize = ibsize = 0;
  10997. }
  10998. break;
  10999. }
  11000. case Lines2D.RoundCap:
  11001. {
  11002. if (border) {
  11003. vbsize = sd;
  11004. ibsize = (sd - 2) * 3;
  11005. }
  11006. else {
  11007. vbsize = (sd / 2) + 1;
  11008. ibsize = (sd / 2) * 3;
  11009. }
  11010. break;
  11011. }
  11012. case Lines2D.ArrowCap:
  11013. {
  11014. if (border) {
  11015. vbsize = 12;
  11016. ibsize = 24;
  11017. }
  11018. else {
  11019. vbsize = 3;
  11020. ibsize = 3;
  11021. }
  11022. break;
  11023. }
  11024. case Lines2D.TriangleCap:
  11025. {
  11026. if (border) {
  11027. vbsize = 6;
  11028. ibsize = 12;
  11029. }
  11030. else {
  11031. vbsize = 3;
  11032. ibsize = 3;
  11033. }
  11034. break;
  11035. }
  11036. case Lines2D.DiamondAnchorCap:
  11037. {
  11038. if (border) {
  11039. vbsize = 10;
  11040. ibsize = 24;
  11041. }
  11042. else {
  11043. vbsize = 5;
  11044. ibsize = 9;
  11045. }
  11046. break;
  11047. }
  11048. case Lines2D.SquareAnchorCap:
  11049. {
  11050. if (border) {
  11051. vbsize = 12;
  11052. ibsize = 30;
  11053. }
  11054. else {
  11055. vbsize = 4;
  11056. ibsize = 6;
  11057. }
  11058. break;
  11059. }
  11060. case Lines2D.RoundAnchorCap:
  11061. {
  11062. if (border) {
  11063. vbsize = sd * 2;
  11064. ibsize = (sd - 1) * 6;
  11065. }
  11066. else {
  11067. vbsize = sd + 1;
  11068. ibsize = (sd + 1) * 3;
  11069. }
  11070. break;
  11071. }
  11072. }
  11073. return { vbsize: vbsize * 2, ibsize: ibsize };
  11074. };
  11075. Lines2D.prototype._storeVertex = function (vb, baseOffset, index, basePos, rotation, vertex, contour) {
  11076. var c = Math.cos(rotation);
  11077. var s = Math.sin(rotation);
  11078. Lines2D._tpsV.x = (c * vertex.x) + (-s * vertex.y) + basePos.x;
  11079. Lines2D._tpsV.y = (s * vertex.x) + (c * vertex.y) + basePos.y;
  11080. var offset = baseOffset + (index * 2);
  11081. vb[offset + 0] = Lines2D._tpsV.x;
  11082. vb[offset + 1] = Lines2D._tpsV.y;
  11083. if (contour) {
  11084. contour.push(Lines2D._tpsV.x);
  11085. contour.push(Lines2D._tpsV.y);
  11086. }
  11087. this._updateMinMax(vb, offset);
  11088. return (baseOffset + index * 2) / 2;
  11089. };
  11090. Lines2D.prototype._storeIndex = function (ib, baseOffset, index, vertexIndex) {
  11091. ib[baseOffset + index] = vertexIndex;
  11092. };
  11093. Lines2D.prototype._buildCap = function (vb, vbi, ib, ibi, pos, thickness, borderThickness, type, capDir, contour) {
  11094. // 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
  11095. var sd = Lines2D._roundCapSubDiv;
  11096. var dir = new BABYLON.Vector2(1, 0);
  11097. var angle = Math.atan2(capDir.y, capDir.x) - Math.atan2(dir.y, dir.x);
  11098. var ht = thickness / 2;
  11099. var t = thickness;
  11100. var borderMode = borderThickness != null;
  11101. var bt = borderThickness;
  11102. switch (type) {
  11103. case Lines2D.NoCap:
  11104. if (borderMode && !this.closed) {
  11105. var vi = 0;
  11106. var ii = 0;
  11107. var v1 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, ht + bt), contour);
  11108. var v2 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(bt, ht + bt), contour);
  11109. var v3 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(bt, -(ht + bt)), contour);
  11110. var v4 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -(ht + bt)), contour);
  11111. this._storeIndex(ib, ibi, ii++, v1);
  11112. this._storeIndex(ib, ibi, ii++, v2);
  11113. this._storeIndex(ib, ibi, ii++, v3);
  11114. this._storeIndex(ib, ibi, ii++, v1);
  11115. this._storeIndex(ib, ibi, ii++, v3);
  11116. this._storeIndex(ib, ibi, ii++, v4);
  11117. }
  11118. break;
  11119. case Lines2D.ArrowCap:
  11120. ht *= 2;
  11121. case Lines2D.TriangleCap:
  11122. {
  11123. if (borderMode) {
  11124. var f = type === Lines2D.TriangleCap ? bt : Math.sqrt(bt * bt * 2);
  11125. var v1 = this._storeVertex(vb, vbi, 0, pos, angle, new BABYLON.Vector2(0, ht), null);
  11126. var v2 = this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(ht, 0), null);
  11127. var v3 = this._storeVertex(vb, vbi, 2, pos, angle, new BABYLON.Vector2(0, -ht), null);
  11128. var v4 = this._storeVertex(vb, vbi, 3, pos, angle, new BABYLON.Vector2(0, ht + f), contour);
  11129. var v5 = this._storeVertex(vb, vbi, 4, pos, angle, new BABYLON.Vector2(ht + f, 0), contour);
  11130. var v6 = this._storeVertex(vb, vbi, 5, pos, angle, new BABYLON.Vector2(0, -(ht + f)), contour);
  11131. var ii = 0;
  11132. this._storeIndex(ib, ibi, ii++, v1);
  11133. this._storeIndex(ib, ibi, ii++, v4);
  11134. this._storeIndex(ib, ibi, ii++, v5);
  11135. this._storeIndex(ib, ibi, ii++, v1);
  11136. this._storeIndex(ib, ibi, ii++, v5);
  11137. this._storeIndex(ib, ibi, ii++, v2);
  11138. this._storeIndex(ib, ibi, ii++, v6);
  11139. this._storeIndex(ib, ibi, ii++, v3);
  11140. this._storeIndex(ib, ibi, ii++, v2);
  11141. this._storeIndex(ib, ibi, ii++, v6);
  11142. this._storeIndex(ib, ibi, ii++, v2);
  11143. this._storeIndex(ib, ibi, ii++, v5);
  11144. if (type === Lines2D.ArrowCap) {
  11145. var rht = thickness / 2;
  11146. var v10 = this._storeVertex(vb, vbi, 9, pos, angle, new BABYLON.Vector2(0, -(rht + bt)), null);
  11147. var v12 = this._storeVertex(vb, vbi, 11, pos, angle, new BABYLON.Vector2(-bt, -(ht + f)), contour);
  11148. var v11 = this._storeVertex(vb, vbi, 10, pos, angle, new BABYLON.Vector2(-bt, -(rht + bt)), contour);
  11149. var v7 = this._storeVertex(vb, vbi, 6, pos, angle, new BABYLON.Vector2(0, rht + bt), null);
  11150. var v8 = this._storeVertex(vb, vbi, 7, pos, angle, new BABYLON.Vector2(-bt, rht + bt), contour);
  11151. var v9 = this._storeVertex(vb, vbi, 8, pos, angle, new BABYLON.Vector2(-bt, ht + f), contour);
  11152. this._storeIndex(ib, ibi, ii++, v7);
  11153. this._storeIndex(ib, ibi, ii++, v8);
  11154. this._storeIndex(ib, ibi, ii++, v9);
  11155. this._storeIndex(ib, ibi, ii++, v7);
  11156. this._storeIndex(ib, ibi, ii++, v9);
  11157. this._storeIndex(ib, ibi, ii++, v4);
  11158. this._storeIndex(ib, ibi, ii++, v10);
  11159. this._storeIndex(ib, ibi, ii++, v12);
  11160. this._storeIndex(ib, ibi, ii++, v11);
  11161. this._storeIndex(ib, ibi, ii++, v10);
  11162. this._storeIndex(ib, ibi, ii++, v6);
  11163. this._storeIndex(ib, ibi, ii++, v12);
  11164. }
  11165. }
  11166. else {
  11167. var v1 = this._storeVertex(vb, vbi, 0, pos, angle, new BABYLON.Vector2(0, ht), contour);
  11168. var v2 = this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(ht, 0), contour);
  11169. var v3 = this._storeVertex(vb, vbi, 2, pos, angle, new BABYLON.Vector2(0, -ht), contour);
  11170. this._storeIndex(ib, ibi, 0, v1);
  11171. this._storeIndex(ib, ibi, 1, v2);
  11172. this._storeIndex(ib, ibi, 2, v3);
  11173. }
  11174. break;
  11175. }
  11176. case Lines2D.RoundCap:
  11177. {
  11178. if (borderMode) {
  11179. var curA = -Math.PI / 2;
  11180. var incA = Math.PI / (sd / 2 - 1);
  11181. var ii = 0;
  11182. for (var i = 0; i < (sd / 2); i++) {
  11183. var v1 = this._storeVertex(vb, vbi, i * 2 + 0, pos, angle, new BABYLON.Vector2(Math.cos(curA) * ht, Math.sin(curA) * ht), null);
  11184. 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);
  11185. if (i > 0) {
  11186. this._storeIndex(ib, ibi, ii++, v1 - 2);
  11187. this._storeIndex(ib, ibi, ii++, v2 - 2);
  11188. this._storeIndex(ib, ibi, ii++, v2);
  11189. this._storeIndex(ib, ibi, ii++, v1 - 2);
  11190. this._storeIndex(ib, ibi, ii++, v2);
  11191. this._storeIndex(ib, ibi, ii++, v1);
  11192. }
  11193. curA += incA;
  11194. }
  11195. }
  11196. else {
  11197. var c = this._storeVertex(vb, vbi, 0, pos, angle, new BABYLON.Vector2(0, 0), null);
  11198. var curA = -Math.PI / 2;
  11199. var incA = Math.PI / (sd / 2 - 1);
  11200. this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(Math.cos(curA) * ht, Math.sin(curA) * ht), null);
  11201. curA += incA;
  11202. for (var i = 1; i < (sd / 2); i++) {
  11203. var v2 = this._storeVertex(vb, vbi, i + 1, pos, angle, new BABYLON.Vector2(Math.cos(curA) * ht, Math.sin(curA) * ht), contour);
  11204. this._storeIndex(ib, ibi, i * 3 + 0, c);
  11205. this._storeIndex(ib, ibi, i * 3 + 1, v2 - 1);
  11206. this._storeIndex(ib, ibi, i * 3 + 2, v2);
  11207. curA += incA;
  11208. }
  11209. }
  11210. break;
  11211. }
  11212. case Lines2D.SquareAnchorCap:
  11213. {
  11214. var vi = 0;
  11215. var c = borderMode ? null : contour;
  11216. var v1 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, t), c);
  11217. var v2 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2, t), c);
  11218. var v3 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2, -t), c);
  11219. var v4 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -t), c);
  11220. if (borderMode) {
  11221. var v5 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, ht + bt), null);
  11222. var v6 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, ht + bt), contour);
  11223. var v7 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, t + bt), contour);
  11224. var v8 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2 + bt, t + bt), contour);
  11225. var v9 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2 + bt, -(t + bt)), contour);
  11226. var v10 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, -(t + bt)), contour);
  11227. var v11 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, -(ht + bt)), contour);
  11228. var v12 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -(ht + bt)), null);
  11229. var ii = 0;
  11230. this._storeIndex(ib, ibi, ii++, v6);
  11231. this._storeIndex(ib, ibi, ii++, v1);
  11232. this._storeIndex(ib, ibi, ii++, v5);
  11233. this._storeIndex(ib, ibi, ii++, v6);
  11234. this._storeIndex(ib, ibi, ii++, v7);
  11235. this._storeIndex(ib, ibi, ii++, v1);
  11236. this._storeIndex(ib, ibi, ii++, v1);
  11237. this._storeIndex(ib, ibi, ii++, v7);
  11238. this._storeIndex(ib, ibi, ii++, v8);
  11239. this._storeIndex(ib, ibi, ii++, v1);
  11240. this._storeIndex(ib, ibi, ii++, v8);
  11241. this._storeIndex(ib, ibi, ii++, v2);
  11242. this._storeIndex(ib, ibi, ii++, v2);
  11243. this._storeIndex(ib, ibi, ii++, v8);
  11244. this._storeIndex(ib, ibi, ii++, v9);
  11245. this._storeIndex(ib, ibi, ii++, v2);
  11246. this._storeIndex(ib, ibi, ii++, v9);
  11247. this._storeIndex(ib, ibi, ii++, v3);
  11248. this._storeIndex(ib, ibi, ii++, v3);
  11249. this._storeIndex(ib, ibi, ii++, v9);
  11250. this._storeIndex(ib, ibi, ii++, v10);
  11251. this._storeIndex(ib, ibi, ii++, v3);
  11252. this._storeIndex(ib, ibi, ii++, v10);
  11253. this._storeIndex(ib, ibi, ii++, v4);
  11254. this._storeIndex(ib, ibi, ii++, v10);
  11255. this._storeIndex(ib, ibi, ii++, v11);
  11256. this._storeIndex(ib, ibi, ii++, v4);
  11257. this._storeIndex(ib, ibi, ii++, v11);
  11258. this._storeIndex(ib, ibi, ii++, v12);
  11259. this._storeIndex(ib, ibi, ii++, v4);
  11260. }
  11261. else {
  11262. this._storeIndex(ib, ibi, 0, v1);
  11263. this._storeIndex(ib, ibi, 1, v2);
  11264. this._storeIndex(ib, ibi, 2, v3);
  11265. this._storeIndex(ib, ibi, 3, v1);
  11266. this._storeIndex(ib, ibi, 4, v3);
  11267. this._storeIndex(ib, ibi, 5, v4);
  11268. }
  11269. break;
  11270. }
  11271. case Lines2D.RoundAnchorCap:
  11272. {
  11273. var cpos = Math.sqrt(t * t - ht * ht);
  11274. var center = new BABYLON.Vector2(cpos, 0);
  11275. var curA = BABYLON.Tools.ToRadians(-150);
  11276. var incA = BABYLON.Tools.ToRadians(300) / (sd - 1);
  11277. if (borderMode) {
  11278. var ii = 0;
  11279. for (var i = 0; i < sd; i++) {
  11280. var v1 = this._storeVertex(vb, vbi, i * 2 + 0, pos, angle, new BABYLON.Vector2(cpos + Math.cos(curA) * t, Math.sin(curA) * t), null);
  11281. 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);
  11282. if (i > 0) {
  11283. this._storeIndex(ib, ibi, ii++, v1 - 2);
  11284. this._storeIndex(ib, ibi, ii++, v2 - 2);
  11285. this._storeIndex(ib, ibi, ii++, v2);
  11286. this._storeIndex(ib, ibi, ii++, v1 - 2);
  11287. this._storeIndex(ib, ibi, ii++, v2);
  11288. this._storeIndex(ib, ibi, ii++, v1);
  11289. }
  11290. curA += incA;
  11291. }
  11292. }
  11293. else {
  11294. var c = this._storeVertex(vb, vbi, 0, pos, angle, center, null);
  11295. this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(cpos + Math.cos(curA) * t, Math.sin(curA) * t), null);
  11296. curA += incA;
  11297. for (var i = 1; i < sd; i++) {
  11298. var v2 = this._storeVertex(vb, vbi, i + 1, pos, angle, new BABYLON.Vector2(cpos + Math.cos(curA) * t, Math.sin(curA) * t), contour);
  11299. this._storeIndex(ib, ibi, i * 3 + 0, c);
  11300. this._storeIndex(ib, ibi, i * 3 + 1, v2 - 1);
  11301. this._storeIndex(ib, ibi, i * 3 + 2, v2);
  11302. curA += incA;
  11303. }
  11304. this._storeIndex(ib, ibi, sd * 3 + 0, c);
  11305. this._storeIndex(ib, ibi, sd * 3 + 1, c + 1);
  11306. this._storeIndex(ib, ibi, sd * 3 + 2, c + sd);
  11307. }
  11308. break;
  11309. }
  11310. case Lines2D.DiamondAnchorCap:
  11311. {
  11312. var vi = 0;
  11313. var c = borderMode ? null : contour;
  11314. var v1 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, ht), c);
  11315. var v2 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, t), c);
  11316. var v3 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht * 3, 0), c);
  11317. var v4 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, -t), c);
  11318. var v5 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -ht), c);
  11319. if (borderMode) {
  11320. var f = Math.sqrt(bt * bt * 2);
  11321. var v6 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-f, ht), contour);
  11322. var v7 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, t + f), contour);
  11323. var v8 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht * 3 + f, 0), contour);
  11324. var v9 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, -(t + f)), contour);
  11325. var v10 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-f, -ht), contour);
  11326. var ii = 0;
  11327. this._storeIndex(ib, ibi, ii++, v6);
  11328. this._storeIndex(ib, ibi, ii++, v7);
  11329. this._storeIndex(ib, ibi, ii++, v1);
  11330. this._storeIndex(ib, ibi, ii++, v1);
  11331. this._storeIndex(ib, ibi, ii++, v7);
  11332. this._storeIndex(ib, ibi, ii++, v2);
  11333. this._storeIndex(ib, ibi, ii++, v2);
  11334. this._storeIndex(ib, ibi, ii++, v7);
  11335. this._storeIndex(ib, ibi, ii++, v8);
  11336. this._storeIndex(ib, ibi, ii++, v2);
  11337. this._storeIndex(ib, ibi, ii++, v8);
  11338. this._storeIndex(ib, ibi, ii++, v3);
  11339. this._storeIndex(ib, ibi, ii++, v3);
  11340. this._storeIndex(ib, ibi, ii++, v8);
  11341. this._storeIndex(ib, ibi, ii++, v9);
  11342. this._storeIndex(ib, ibi, ii++, v3);
  11343. this._storeIndex(ib, ibi, ii++, v9);
  11344. this._storeIndex(ib, ibi, ii++, v4);
  11345. this._storeIndex(ib, ibi, ii++, v4);
  11346. this._storeIndex(ib, ibi, ii++, v9);
  11347. this._storeIndex(ib, ibi, ii++, v10);
  11348. this._storeIndex(ib, ibi, ii++, v4);
  11349. this._storeIndex(ib, ibi, ii++, v10);
  11350. this._storeIndex(ib, ibi, ii++, v5);
  11351. }
  11352. else {
  11353. this._storeIndex(ib, ibi, 0, v1);
  11354. this._storeIndex(ib, ibi, 1, v2);
  11355. this._storeIndex(ib, ibi, 2, v3);
  11356. this._storeIndex(ib, ibi, 3, v1);
  11357. this._storeIndex(ib, ibi, 4, v3);
  11358. this._storeIndex(ib, ibi, 5, v5);
  11359. this._storeIndex(ib, ibi, 6, v5);
  11360. this._storeIndex(ib, ibi, 7, v3);
  11361. this._storeIndex(ib, ibi, 8, v4);
  11362. }
  11363. break;
  11364. }
  11365. }
  11366. return null;
  11367. };
  11368. Lines2D.prototype._buildLine = function (vb, contour, ht, bt) {
  11369. var lineA = BABYLON.Vector2.Zero();
  11370. var lineB = BABYLON.Vector2.Zero();
  11371. var tangent = BABYLON.Vector2.Zero();
  11372. var miter = BABYLON.Vector2.Zero();
  11373. var curNormal = null;
  11374. if (this.closed) {
  11375. this.points.push(this.points[0]);
  11376. }
  11377. var total = this.points.length;
  11378. for (var i = 1; i < total; i++) {
  11379. var last = this.points[i - 1];
  11380. var cur = this.points[i];
  11381. var next = (i < (this.points.length - 1)) ? this.points[i + 1] : null;
  11382. this._direction(cur, last, lineA);
  11383. if (!curNormal) {
  11384. curNormal = BABYLON.Vector2.Zero();
  11385. this._perp(lineA, curNormal);
  11386. }
  11387. if (i === 1) {
  11388. this._store(vb, contour, 0, total, this.points[0], curNormal, ht, bt);
  11389. }
  11390. if (!next) {
  11391. this._perp(lineA, curNormal);
  11392. this._store(vb, contour, i, total, this.points[i], curNormal, ht, bt, i - 1);
  11393. }
  11394. else {
  11395. this._direction(next, cur, lineB);
  11396. var miterLen = this._computeMiter(tangent, miter, lineA, lineB);
  11397. this._store(vb, contour, i, total, this.points[i], miter, miterLen * ht, miterLen * bt, i - 1);
  11398. }
  11399. }
  11400. if (this.points.length > 2 && this.closed) {
  11401. var last2 = this.points[total - 2];
  11402. var cur2 = this.points[0];
  11403. var next2 = this.points[1];
  11404. this._direction(cur2, last2, lineA);
  11405. this._direction(next2, cur2, lineB);
  11406. this._perp(lineA, curNormal);
  11407. var miterLen2 = this._computeMiter(tangent, miter, lineA, lineB);
  11408. this._store(vb, null, 0, total, this.points[0], miter, miterLen2 * ht, miterLen2 * bt, 1);
  11409. // Patch contour
  11410. if (contour) {
  11411. var off = (bt == null) ? 0 : 4;
  11412. contour[0].x = vb[off + 0];
  11413. contour[0].y = vb[off + 1];
  11414. contour[1].x = vb[off + 2];
  11415. contour[1].y = vb[off + 3];
  11416. }
  11417. }
  11418. // Remove the point we added at the beginning
  11419. if (this.closed) {
  11420. this.points.splice(total - 1);
  11421. }
  11422. };
  11423. // Methods for Lines building
  11424. ///////////////////////////////////////////////////////////////////////////////////
  11425. Lines2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  11426. var renderCache = modelRenderCache;
  11427. var engine = this.owner.engine;
  11428. if (this._fillVB === null) {
  11429. this._computeLines2D();
  11430. }
  11431. // Need to create WebGL resources for fill part?
  11432. if (this.fill) {
  11433. renderCache.fillVB = engine.createVertexBuffer(this._fillVB);
  11434. renderCache.fillIB = engine.createIndexBuffer(this._fillIB);
  11435. renderCache.fillIndicesCount = this._fillIB.length;
  11436. // 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
  11437. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["position"], null, true);
  11438. if (ei) {
  11439. renderCache.effectFillInstanced = engine.createEffect("lines2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  11440. }
  11441. // Get the non instanced version
  11442. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["position"], null, false);
  11443. renderCache.effectFill = engine.createEffect("lines2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  11444. }
  11445. // Need to create WebGL resources for border part?
  11446. if (this.border) {
  11447. renderCache.borderVB = engine.createVertexBuffer(this._borderVB);
  11448. renderCache.borderIB = engine.createIndexBuffer(this._borderIB);
  11449. renderCache.borderIndicesCount = this._borderIB.length;
  11450. // 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
  11451. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["position"], null, true);
  11452. if (ei) {
  11453. renderCache.effectBorderInstanced = engine.createEffect({ vertex: "lines2d", fragment: "lines2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  11454. }
  11455. // Get the non instanced version
  11456. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["position"], null, false);
  11457. renderCache.effectBorder = engine.createEffect({ vertex: "lines2d", fragment: "lines2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  11458. }
  11459. this._fillVB = null;
  11460. this._fillIB = null;
  11461. this._borderVB = null;
  11462. this._borderIB = null;
  11463. return renderCache;
  11464. };
  11465. Lines2D.prototype._computeLines2D = function () {
  11466. // Init min/max because their being computed here
  11467. this._boundingMin = new BABYLON.Vector2(Number.MAX_VALUE, Number.MAX_VALUE);
  11468. this._boundingMax = new BABYLON.Vector2(Number.MIN_VALUE, Number.MIN_VALUE);
  11469. var contour = new Array();
  11470. var startCapContour = new Array();
  11471. var endCapContour = new Array();
  11472. // Need to create WebGL resources for fill part?
  11473. if (this.fill) {
  11474. var startCapInfo = this._getCapSize(this.startCap);
  11475. var endCapInfo = this._getCapSize(this.endCap);
  11476. var count = this.points.length;
  11477. var vbSize = (count * 2 * 2) + startCapInfo.vbsize + endCapInfo.vbsize;
  11478. this._fillVB = new Float32Array(vbSize);
  11479. var vb = this._fillVB;
  11480. var ht = this.fillThickness / 2;
  11481. var total = this.points.length;
  11482. this._buildLine(vb, this.border ? null : contour, ht);
  11483. var max = total * 2;
  11484. var triCount = (count - (this.closed ? 0 : 1)) * 2;
  11485. this._fillIB = new Float32Array(triCount * 3 + startCapInfo.ibsize + endCapInfo.ibsize);
  11486. var ib = this._fillIB;
  11487. for (var i = 0; i < triCount; i += 2) {
  11488. ib[i * 3 + 0] = i + 0;
  11489. ib[i * 3 + 1] = i + 1;
  11490. ib[i * 3 + 2] = (i + 2) % max;
  11491. ib[i * 3 + 3] = i + 1;
  11492. ib[i * 3 + 4] = (i + 3) % max;
  11493. ib[i * 3 + 5] = (i + 2) % max;
  11494. }
  11495. this._buildCap(vb, count * 2 * 2, ib, triCount * 3, this.points[0], this.fillThickness, null, this.startCap, Lines2D._startDir, this.border ? null : startCapContour);
  11496. this._buildCap(vb, (count * 2 * 2) + startCapInfo.vbsize, ib, (triCount * 3) + startCapInfo.ibsize, this.points[total - 1], this.fillThickness, null, this.endCap, Lines2D._endDir, this.border ? null : startCapContour);
  11497. }
  11498. // Need to create WebGL resources for border part?
  11499. if (this.border) {
  11500. var startCapInfo = this._getCapSize(this.startCap, true);
  11501. var endCapInfo = this._getCapSize(this.endCap, true);
  11502. var count = this.points.length;
  11503. var vbSize = (count * 2 * 2 * 2) + startCapInfo.vbsize + endCapInfo.vbsize;
  11504. this._borderVB = new Float32Array(vbSize);
  11505. var vb = this._borderVB;
  11506. var ht = this.fillThickness / 2;
  11507. var bt = this.borderThickness;
  11508. var total = this.points.length;
  11509. this._buildLine(vb, contour, ht, bt);
  11510. var max = total * 2 * 2;
  11511. var triCount = (count - (this.closed ? 0 : 1)) * 2 * 2;
  11512. this._borderIB = new Float32Array(triCount * 3 + startCapInfo.ibsize + endCapInfo.ibsize);
  11513. var ib = this._borderIB;
  11514. for (var i = 0; i < triCount; i += 4) {
  11515. ib[i * 3 + 0] = i + 0;
  11516. ib[i * 3 + 1] = i + 2;
  11517. ib[i * 3 + 2] = (i + 6) % max;
  11518. ib[i * 3 + 3] = i + 0;
  11519. ib[i * 3 + 4] = (i + 6) % max;
  11520. ib[i * 3 + 5] = (i + 4) % max;
  11521. ib[i * 3 + 6] = i + 3;
  11522. ib[i * 3 + 7] = i + 1;
  11523. ib[i * 3 + 8] = (i + 5) % max;
  11524. ib[i * 3 + 9] = i + 3;
  11525. ib[i * 3 + 10] = (i + 5) % max;
  11526. ib[i * 3 + 11] = (i + 7) % max;
  11527. }
  11528. this._buildCap(vb, count * 2 * 2 * 2, ib, triCount * 3, this.points[0], this.fillThickness, this.borderThickness, this.startCap, Lines2D._startDir, startCapContour);
  11529. 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._endDir, endCapContour);
  11530. }
  11531. this._contour = contour;
  11532. if (startCapContour.length > 0) {
  11533. var startCapTri = Earcut.earcut(startCapContour, null, 2);
  11534. this._startCapTriIndices = startCapTri;
  11535. this._startCapContour = startCapContour;
  11536. }
  11537. else {
  11538. this._startCapTriIndices = null;
  11539. this._startCapContour = null;
  11540. }
  11541. if (endCapContour.length > 0) {
  11542. var endCapTri = Earcut.earcut(endCapContour, null, 2);
  11543. this._endCapContour = endCapContour;
  11544. this._endCapTriIndices = endCapTri;
  11545. }
  11546. else {
  11547. this._endCapContour = null;
  11548. this._endCapTriIndices = null;
  11549. }
  11550. var bs = this._boundingMax.subtract(this._boundingMin);
  11551. this._size.width = bs.x;
  11552. this._size.height = bs.y;
  11553. };
  11554. Object.defineProperty(Lines2D.prototype, "size", {
  11555. get: function () {
  11556. if (this._size == null) {
  11557. this._computeLines2D();
  11558. }
  11559. return this._size;
  11560. },
  11561. enumerable: true,
  11562. configurable: true
  11563. });
  11564. Lines2D.prototype.createInstanceDataParts = function () {
  11565. var res = new Array();
  11566. if (this.border) {
  11567. res.push(new Lines2DInstanceData(BABYLON.Shape2D.SHAPE2D_BORDERPARTID));
  11568. }
  11569. if (this.fill) {
  11570. res.push(new Lines2DInstanceData(BABYLON.Shape2D.SHAPE2D_FILLPARTID));
  11571. }
  11572. return res;
  11573. };
  11574. Lines2D.prototype.applyActualScaleOnTransform = function () {
  11575. return true;
  11576. };
  11577. Lines2D.prototype.refreshInstanceDataPart = function (part) {
  11578. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  11579. return false;
  11580. }
  11581. if (part.id === BABYLON.Shape2D.SHAPE2D_BORDERPARTID) {
  11582. var d = part;
  11583. if (this.border instanceof BABYLON.GradientColorBrush2D) {
  11584. d.boundingMin = this.boundingMin;
  11585. d.boundingMax = this.boundingMax;
  11586. }
  11587. }
  11588. else if (part.id === BABYLON.Shape2D.SHAPE2D_FILLPARTID) {
  11589. var d = part;
  11590. if (this.fill instanceof BABYLON.GradientColorBrush2D) {
  11591. d.boundingMin = this.boundingMin;
  11592. d.boundingMax = this.boundingMax;
  11593. }
  11594. }
  11595. return true;
  11596. };
  11597. Lines2D._prevA = BABYLON.Vector2.Zero();
  11598. Lines2D._prevB = BABYLON.Vector2.Zero();
  11599. Lines2D._curA = BABYLON.Vector2.Zero();
  11600. Lines2D._curB = BABYLON.Vector2.Zero();
  11601. Lines2D._miterTps = BABYLON.Vector2.Zero();
  11602. Lines2D._startDir = BABYLON.Vector2.Zero();
  11603. Lines2D._endDir = BABYLON.Vector2.Zero();
  11604. Lines2D._tpsV = BABYLON.Vector2.Zero();
  11605. Lines2D._noCap = 0;
  11606. Lines2D._roundCap = 1;
  11607. Lines2D._triangleCap = 2;
  11608. Lines2D._squareAnchorCap = 3;
  11609. Lines2D._roundAnchorCap = 4;
  11610. Lines2D._diamondAnchorCap = 5;
  11611. Lines2D._arrowCap = 6;
  11612. Lines2D._roundCapSubDiv = 36;
  11613. __decorate([
  11614. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 1, function (pi) { return Lines2D.pointsProperty = pi; })
  11615. ], Lines2D.prototype, "points", null);
  11616. __decorate([
  11617. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 2, function (pi) { return Lines2D.fillThicknessProperty = pi; })
  11618. ], Lines2D.prototype, "fillThickness", null);
  11619. __decorate([
  11620. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 3, function (pi) { return Lines2D.closedProperty = pi; })
  11621. ], Lines2D.prototype, "closed", null);
  11622. __decorate([
  11623. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 4, function (pi) { return Lines2D.startCapProperty = pi; })
  11624. ], Lines2D.prototype, "startCap", null);
  11625. __decorate([
  11626. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 5, function (pi) { return Lines2D.endCapProperty = pi; })
  11627. ], Lines2D.prototype, "endCap", null);
  11628. Lines2D = __decorate([
  11629. BABYLON.className("Lines2D", "BABYLON")
  11630. ], Lines2D);
  11631. return Lines2D;
  11632. }(BABYLON.Shape2D));
  11633. BABYLON.Lines2D = Lines2D;
  11634. })(BABYLON || (BABYLON = {}));
  11635. //# sourceMappingURL=babylon.lines2d.js.map
  11636. var __extends = (this && this.__extends) || function (d, b) {
  11637. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  11638. function __() { this.constructor = d; }
  11639. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  11640. };
  11641. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  11642. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  11643. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  11644. 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;
  11645. return c > 3 && r && Object.defineProperty(target, key, r), r;
  11646. };
  11647. var BABYLON;
  11648. (function (BABYLON) {
  11649. // This class contains data that lifetime is bounding to the Babylon Engine object
  11650. var Canvas2DEngineBoundData = (function () {
  11651. function Canvas2DEngineBoundData() {
  11652. this._modelCache = new BABYLON.StringDictionary();
  11653. }
  11654. Canvas2DEngineBoundData.prototype.GetOrAddModelCache = function (key, factory) {
  11655. return this._modelCache.getOrAddWithFactory(key, factory);
  11656. };
  11657. Canvas2DEngineBoundData.prototype.DisposeModelRenderCache = function (modelRenderCache) {
  11658. if (!modelRenderCache.isDisposed) {
  11659. return false;
  11660. }
  11661. this._modelCache.remove(modelRenderCache.modelKey);
  11662. return true;
  11663. };
  11664. return Canvas2DEngineBoundData;
  11665. }());
  11666. BABYLON.Canvas2DEngineBoundData = Canvas2DEngineBoundData;
  11667. var Canvas2D = (function (_super) {
  11668. __extends(Canvas2D, _super);
  11669. function Canvas2D(scene, settings) {
  11670. var _this = this;
  11671. _super.call(this, settings);
  11672. /**
  11673. * 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.
  11674. * Beware that you have to take under consideration the origin in your calculations! Good luck!
  11675. */
  11676. this.worldSpaceToNodeLocal = function (worldPos) {
  11677. var node = _this._worldSpaceNode;
  11678. if (!node) {
  11679. return;
  11680. }
  11681. var mtx = node.getWorldMatrix().clone();
  11682. mtx.invert();
  11683. var v = BABYLON.Vector3.TransformCoordinates(worldPos, mtx);
  11684. var res = new BABYLON.Vector2(v.x, v.y);
  11685. var size = _this.actualSize;
  11686. res.x += size.width * 0.5; // res is centered, make it relative to bottom/left
  11687. res.y += size.height * 0.5;
  11688. return res;
  11689. };
  11690. /**
  11691. * 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
  11692. */
  11693. this.worldSpaceCacheChanged = function () {
  11694. var plane = _this.worldSpaceCanvasNode;
  11695. var vd = BABYLON.VertexData.ExtractFromMesh(plane); //new VertexData();
  11696. vd.uvs = new Float32Array(8);
  11697. var material = plane.material;
  11698. var tex = _this._renderableData._cacheTexture;
  11699. if (material.diffuseTexture !== tex) {
  11700. material.diffuseTexture = tex;
  11701. tex.hasAlpha = true;
  11702. }
  11703. var nodeuv = _this._renderableData._cacheNodeUVs;
  11704. for (var i = 0; i < 4; i++) {
  11705. vd.uvs[i * 2 + 0] = nodeuv[i].x;
  11706. vd.uvs[i * 2 + 1] = nodeuv[i].y;
  11707. }
  11708. vd.applyToMesh(plane);
  11709. };
  11710. this._notifDebugMode = false;
  11711. /**
  11712. * Instanced Array will be create if there's at least this number of parts/prim that can fit into it
  11713. */
  11714. this.minPartCountToUseInstancedArray = 5;
  11715. this._mapCounter = 0;
  11716. this._drawCallsOpaqueCounter = new BABYLON.PerfCounter();
  11717. this._drawCallsAlphaTestCounter = new BABYLON.PerfCounter();
  11718. this._drawCallsTransparentCounter = new BABYLON.PerfCounter();
  11719. this._groupRenderCounter = new BABYLON.PerfCounter();
  11720. this._updateTransparentDataCounter = new BABYLON.PerfCounter();
  11721. this._cachedGroupRenderCounter = new BABYLON.PerfCounter();
  11722. this._updateCachedStateCounter = new BABYLON.PerfCounter();
  11723. this._updateLayoutCounter = new BABYLON.PerfCounter();
  11724. this._updatePositioningCounter = new BABYLON.PerfCounter();
  11725. this._updateLocalTransformCounter = new BABYLON.PerfCounter();
  11726. this._updateGlobalTransformCounter = new BABYLON.PerfCounter();
  11727. this._boundingInfoRecomputeCounter = new BABYLON.PerfCounter();
  11728. this._uid = null;
  11729. this._cachedCanvasGroup = null;
  11730. this._renderingGroupObserver = null;
  11731. this._beforeRenderObserver = null;
  11732. this._afterRenderObserver = null;
  11733. this._profileInfoText = null;
  11734. BABYLON.Prim2DBase._isCanvasInit = false;
  11735. if (!settings) {
  11736. settings = {};
  11737. }
  11738. if (this._cachingStrategy !== Canvas2D.CACHESTRATEGY_TOPLEVELGROUPS) {
  11739. this._background = new BABYLON.Rectangle2D({ parent: this, id: "###CANVAS BACKGROUND###", size: settings.size }); //TODO CHECK when size is null
  11740. this._background.zOrder = 1.0;
  11741. this._background.isPickable = false;
  11742. this._background.origin = BABYLON.Vector2.Zero();
  11743. this._background.levelVisible = false;
  11744. if (settings.backgroundRoundRadius != null) {
  11745. this.backgroundRoundRadius = settings.backgroundRoundRadius;
  11746. }
  11747. if (settings.backgroundBorder != null) {
  11748. if (typeof (settings.backgroundBorder) === "string") {
  11749. this.backgroundBorder = Canvas2D.GetBrushFromString(settings.backgroundBorder);
  11750. }
  11751. else {
  11752. this.backgroundBorder = settings.backgroundBorder;
  11753. }
  11754. }
  11755. if (settings.backgroundBorderThickNess != null) {
  11756. this.backgroundBorderThickness = settings.backgroundBorderThickNess;
  11757. }
  11758. if (settings.backgroundFill != null) {
  11759. if (typeof (settings.backgroundFill) === "string") {
  11760. this.backgroundFill = Canvas2D.GetBrushFromString(settings.backgroundFill);
  11761. }
  11762. else {
  11763. this.backgroundFill = settings.backgroundFill;
  11764. }
  11765. }
  11766. // Put a handler to resize the background whenever the canvas is resizing
  11767. this.propertyChanged.add(function (e, s) {
  11768. if (e.propertyName === "size") {
  11769. _this._background.size = _this.size;
  11770. }
  11771. }, BABYLON.Group2D.sizeProperty.flagId);
  11772. this._background._patchHierarchy(this);
  11773. }
  11774. var engine = scene.getEngine();
  11775. this.__engineData = engine.getOrAddExternalDataWithFactory("__BJSCANVAS2D__", function (k) { return new Canvas2DEngineBoundData(); });
  11776. this._primPointerInfo = new BABYLON.PrimitivePointerInfo();
  11777. this._capturedPointers = new BABYLON.StringDictionary();
  11778. this._pickStartingPosition = BABYLON.Vector2.Zero();
  11779. this._hierarchyLevelMaxSiblingCount = 50;
  11780. this._hierarchyDepth = 0;
  11781. this._zOrder = 0;
  11782. this._zMax = 1;
  11783. this._scene = scene;
  11784. this._engine = engine;
  11785. this._renderingSize = new BABYLON.Size(0, 0);
  11786. this._designSize = settings.designSize || null;
  11787. this._designUseHorizAxis = settings.designUseHorizAxis === true;
  11788. this._trackedGroups = new Array();
  11789. this._maxAdaptiveWorldSpaceCanvasSize = null;
  11790. this._groupCacheMaps = new BABYLON.StringDictionary();
  11791. this._patchHierarchy(this);
  11792. var enableInteraction = (settings.enableInteraction == null) ? true : settings.enableInteraction;
  11793. this._fitRenderingDevice = !settings.size;
  11794. if (!settings.size) {
  11795. settings.size = new BABYLON.Size(engine.getRenderWidth(), engine.getRenderHeight());
  11796. }
  11797. // Register scene dispose to also dispose the canvas when it'll happens
  11798. scene.onDisposeObservable.add(function (d, s) {
  11799. _this.dispose();
  11800. });
  11801. if (this._isScreenSpace) {
  11802. if (settings.renderingPhase) {
  11803. if (!settings.renderingPhase.camera || settings.renderingPhase.renderingGroupID == null) {
  11804. throw Error("You have to specify a valid camera and renderingGroup");
  11805. }
  11806. this._renderingGroupObserver = this._scene.onRenderingGroupObservable.add(function (e, s) {
  11807. if ((_this._scene.activeCamera === settings.renderingPhase.camera) && (e.renderStage === BABYLON.RenderingGroupInfo.STAGE_POSTTRANSPARENT)) {
  11808. _this._engine.clear(null, false, true, true);
  11809. _this._render();
  11810. }
  11811. }, Math.pow(2, settings.renderingPhase.renderingGroupID));
  11812. }
  11813. else {
  11814. this._afterRenderObserver = this._scene.onAfterRenderObservable.add(function (d, s) {
  11815. _this._engine.clear(null, false, true, true);
  11816. _this._render();
  11817. });
  11818. }
  11819. }
  11820. else {
  11821. this._beforeRenderObserver = this._scene.onBeforeRenderObservable.add(function (d, s) {
  11822. _this._render();
  11823. });
  11824. }
  11825. this._supprtInstancedArray = this._engine.getCaps().instancedArrays !== null;
  11826. //this._supprtInstancedArray = false; // TODO REMOVE!!!
  11827. this._setupInteraction(enableInteraction);
  11828. // Register this instance
  11829. Canvas2D._INSTANCES.push(this);
  11830. }
  11831. Object.defineProperty(Canvas2D.prototype, "drawCallsOpaqueCounter", {
  11832. get: function () {
  11833. return this._drawCallsOpaqueCounter;
  11834. },
  11835. enumerable: true,
  11836. configurable: true
  11837. });
  11838. Object.defineProperty(Canvas2D.prototype, "drawCallsAlphaTestCounter", {
  11839. get: function () {
  11840. return this._drawCallsAlphaTestCounter;
  11841. },
  11842. enumerable: true,
  11843. configurable: true
  11844. });
  11845. Object.defineProperty(Canvas2D.prototype, "drawCallsTransparentCounter", {
  11846. get: function () {
  11847. return this._drawCallsTransparentCounter;
  11848. },
  11849. enumerable: true,
  11850. configurable: true
  11851. });
  11852. Object.defineProperty(Canvas2D.prototype, "groupRenderCounter", {
  11853. get: function () {
  11854. return this._groupRenderCounter;
  11855. },
  11856. enumerable: true,
  11857. configurable: true
  11858. });
  11859. Object.defineProperty(Canvas2D.prototype, "updateTransparentDataCounter", {
  11860. get: function () {
  11861. return this._updateTransparentDataCounter;
  11862. },
  11863. enumerable: true,
  11864. configurable: true
  11865. });
  11866. Object.defineProperty(Canvas2D.prototype, "cachedGroupRenderCounter", {
  11867. get: function () {
  11868. return this._cachedGroupRenderCounter;
  11869. },
  11870. enumerable: true,
  11871. configurable: true
  11872. });
  11873. Object.defineProperty(Canvas2D.prototype, "updateCachedStateCounter", {
  11874. get: function () {
  11875. return this._updateCachedStateCounter;
  11876. },
  11877. enumerable: true,
  11878. configurable: true
  11879. });
  11880. Object.defineProperty(Canvas2D.prototype, "updateLayoutCounter", {
  11881. get: function () {
  11882. return this._updateLayoutCounter;
  11883. },
  11884. enumerable: true,
  11885. configurable: true
  11886. });
  11887. Object.defineProperty(Canvas2D.prototype, "updatePositioningCounter", {
  11888. get: function () {
  11889. return this._updatePositioningCounter;
  11890. },
  11891. enumerable: true,
  11892. configurable: true
  11893. });
  11894. Object.defineProperty(Canvas2D.prototype, "updateLocalTransformCounter", {
  11895. get: function () {
  11896. return this._updateLocalTransformCounter;
  11897. },
  11898. enumerable: true,
  11899. configurable: true
  11900. });
  11901. Object.defineProperty(Canvas2D.prototype, "updateGlobalTransformCounter", {
  11902. get: function () {
  11903. return this._updateGlobalTransformCounter;
  11904. },
  11905. enumerable: true,
  11906. configurable: true
  11907. });
  11908. Object.defineProperty(Canvas2D.prototype, "boundingInfoRecomputeCounter", {
  11909. get: function () {
  11910. return this._boundingInfoRecomputeCounter;
  11911. },
  11912. enumerable: true,
  11913. configurable: true
  11914. });
  11915. Object.defineProperty(Canvas2D, "instances", {
  11916. get: function () {
  11917. return Canvas2D._INSTANCES;
  11918. },
  11919. enumerable: true,
  11920. configurable: true
  11921. });
  11922. Canvas2D.prototype._canvasPreInit = function (settings) {
  11923. var cachingStrategy = (settings.cachingStrategy == null) ? Canvas2D.CACHESTRATEGY_DONTCACHE : settings.cachingStrategy;
  11924. this._cachingStrategy = cachingStrategy;
  11925. this._isScreenSpace = (settings.isScreenSpace == null) ? true : settings.isScreenSpace;
  11926. };
  11927. Canvas2D.prototype._setupInteraction = function (enable) {
  11928. var _this = this;
  11929. // No change detection
  11930. if (enable === this._interactionEnabled) {
  11931. return;
  11932. }
  11933. // Set the new state
  11934. this._interactionEnabled = enable;
  11935. // ScreenSpace mode
  11936. if (this._isScreenSpace) {
  11937. // Disable interaction
  11938. if (!enable) {
  11939. if (this._scenePrePointerObserver) {
  11940. this.scene.onPrePointerObservable.remove(this._scenePrePointerObserver);
  11941. this._scenePrePointerObserver = null;
  11942. }
  11943. return;
  11944. }
  11945. // Enable Interaction
  11946. // Register the observable
  11947. this._scenePrePointerObserver = this.scene.onPrePointerObservable.add(function (e, s) {
  11948. if (_this.isVisible === false) {
  11949. return;
  11950. }
  11951. var hs = 1 / _this.engine.getHardwareScalingLevel();
  11952. var localPos = e.localPosition.multiplyByFloats(hs, hs);
  11953. _this._handlePointerEventForInteraction(e, localPos, s);
  11954. });
  11955. }
  11956. else {
  11957. var scene = this.scene;
  11958. if (enable) {
  11959. scene.constantlyUpdateMeshUnderPointer = true;
  11960. this._scenePointerObserver = scene.onPointerObservable.add(function (e, s) {
  11961. if (_this.isVisible === false) {
  11962. return;
  11963. }
  11964. if (e.pickInfo.hit && e.pickInfo.pickedMesh === _this._worldSpaceNode && _this.worldSpaceToNodeLocal) {
  11965. var localPos = _this.worldSpaceToNodeLocal(e.pickInfo.pickedPoint);
  11966. _this._handlePointerEventForInteraction(e, localPos, s);
  11967. }
  11968. });
  11969. }
  11970. else {
  11971. if (this._scenePointerObserver) {
  11972. this.scene.onPointerObservable.remove(this._scenePointerObserver);
  11973. this._scenePointerObserver = null;
  11974. }
  11975. }
  11976. }
  11977. };
  11978. /**
  11979. * Internal method, you should use the Prim2DBase version instead
  11980. */
  11981. Canvas2D.prototype._setPointerCapture = function (pointerId, primitive) {
  11982. if (this.isPointerCaptured(pointerId)) {
  11983. return false;
  11984. }
  11985. // Try to capture the pointer on the HTML side
  11986. try {
  11987. this.engine.getRenderingCanvas().setPointerCapture(pointerId);
  11988. }
  11989. catch (e) {
  11990. }
  11991. this._primPointerInfo.updateRelatedTarget(primitive, BABYLON.Vector2.Zero());
  11992. this._bubbleNotifyPrimPointerObserver(primitive, BABYLON.PrimitivePointerInfo.PointerGotCapture, null);
  11993. this._capturedPointers.add(pointerId.toString(), primitive);
  11994. return true;
  11995. };
  11996. /**
  11997. * Internal method, you should use the Prim2DBase version instead
  11998. */
  11999. Canvas2D.prototype._releasePointerCapture = function (pointerId, primitive) {
  12000. if (this._capturedPointers.get(pointerId.toString()) !== primitive) {
  12001. return false;
  12002. }
  12003. // Try to release the pointer on the HTML side
  12004. try {
  12005. this.engine.getRenderingCanvas().releasePointerCapture(pointerId);
  12006. }
  12007. catch (e) {
  12008. }
  12009. this._primPointerInfo.updateRelatedTarget(primitive, BABYLON.Vector2.Zero());
  12010. this._bubbleNotifyPrimPointerObserver(primitive, BABYLON.PrimitivePointerInfo.PointerLostCapture, null);
  12011. this._capturedPointers.remove(pointerId.toString());
  12012. return true;
  12013. };
  12014. /**
  12015. * Determine if the given pointer is captured or not
  12016. * @param pointerId the Id of the pointer
  12017. * @return true if it's captured, false otherwise
  12018. */
  12019. Canvas2D.prototype.isPointerCaptured = function (pointerId) {
  12020. return this._capturedPointers.contains(pointerId.toString());
  12021. };
  12022. Canvas2D.prototype.getCapturedPrimitive = function (pointerId) {
  12023. // Avoid unnecessary lookup
  12024. if (this._capturedPointers.count === 0) {
  12025. return null;
  12026. }
  12027. return this._capturedPointers.get(pointerId.toString());
  12028. };
  12029. Canvas2D.prototype._handlePointerEventForInteraction = function (eventData, localPosition, eventState) {
  12030. // Dispose check
  12031. if (this.isDisposed) {
  12032. return;
  12033. }
  12034. // Update the this._primPointerInfo structure we'll send to observers using the PointerEvent data
  12035. if (!this._updatePointerInfo(eventData, localPosition)) {
  12036. return;
  12037. }
  12038. var capturedPrim = this.getCapturedPrimitive(this._primPointerInfo.pointerId);
  12039. // 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.
  12040. // 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.
  12041. this._updateIntersectionList(this._primPointerInfo.canvasPointerPos, capturedPrim !== null, true);
  12042. // 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
  12043. this._updateOverStatus(true);
  12044. // Check if we have nothing to raise
  12045. if (!this._actualOverPrimitive && !capturedPrim) {
  12046. return;
  12047. }
  12048. // Update the relatedTarget info with the over primitive or the captured one (if any)
  12049. var targetPrim = capturedPrim || this._actualOverPrimitive.prim;
  12050. var targetPointerPos = capturedPrim ? this._primPointerInfo.canvasPointerPos.subtract(new BABYLON.Vector2(targetPrim.globalTransform.m[12], targetPrim.globalTransform.m[13])) : this._actualOverPrimitive.intersectionLocation;
  12051. this._primPointerInfo.updateRelatedTarget(targetPrim, targetPointerPos);
  12052. // Analyze the pointer event type and fire proper events on the primitive
  12053. var skip = false;
  12054. if (eventData.type === BABYLON.PointerEventTypes.POINTERWHEEL) {
  12055. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerMouseWheel, eventData);
  12056. }
  12057. else if (eventData.type === BABYLON.PointerEventTypes.POINTERMOVE) {
  12058. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerMove, eventData);
  12059. }
  12060. else if (eventData.type === BABYLON.PointerEventTypes.POINTERDOWN) {
  12061. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerDown, eventData);
  12062. }
  12063. else if (eventData.type === BABYLON.PointerEventTypes.POINTERUP) {
  12064. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerUp, eventData);
  12065. }
  12066. eventState.skipNextObservers = skip;
  12067. };
  12068. Canvas2D.prototype._updatePointerInfo = function (eventData, localPosition) {
  12069. var s = this.scale;
  12070. var pii = this._primPointerInfo;
  12071. pii.cancelBubble = false;
  12072. if (!pii.canvasPointerPos) {
  12073. pii.canvasPointerPos = BABYLON.Vector2.Zero();
  12074. }
  12075. var camera = this._scene.cameraToUseForPointers || this._scene.activeCamera;
  12076. if (!camera || !camera.viewport) {
  12077. return false;
  12078. }
  12079. var engine = this._scene.getEngine();
  12080. if (this._isScreenSpace) {
  12081. var cameraViewport = camera.viewport;
  12082. var viewport = cameraViewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight());
  12083. // Moving coordinates to local viewport world
  12084. var x = localPosition.x - viewport.x;
  12085. var y = localPosition.y - viewport.y;
  12086. pii.canvasPointerPos.x = (x - this.actualPosition.x) / s;
  12087. pii.canvasPointerPos.y = (engine.getRenderHeight() - y - this.actualPosition.y) / s;
  12088. }
  12089. else {
  12090. pii.canvasPointerPos.x = localPosition.x / s;
  12091. pii.canvasPointerPos.y = localPosition.y / s;
  12092. }
  12093. //console.log(`UpdatePointerInfo for ${this.id}, X:${pii.canvasPointerPos.x}, Y:${pii.canvasPointerPos.y}`);
  12094. pii.mouseWheelDelta = 0;
  12095. if (eventData.type === BABYLON.PointerEventTypes.POINTERWHEEL) {
  12096. var event = eventData.event;
  12097. if (event.wheelDelta) {
  12098. pii.mouseWheelDelta = event.wheelDelta / (BABYLON.PrimitivePointerInfo.MouseWheelPrecision * 40);
  12099. }
  12100. else if (event.detail) {
  12101. pii.mouseWheelDelta = -event.detail / BABYLON.PrimitivePointerInfo.MouseWheelPrecision;
  12102. }
  12103. }
  12104. else {
  12105. var pe = eventData.event;
  12106. pii.ctrlKey = pe.ctrlKey;
  12107. pii.altKey = pe.altKey;
  12108. pii.shiftKey = pe.shiftKey;
  12109. pii.metaKey = pe.metaKey;
  12110. pii.button = pe.button;
  12111. pii.buttons = pe.buttons;
  12112. pii.pointerId = pe.pointerId;
  12113. pii.width = pe.width;
  12114. pii.height = pe.height;
  12115. pii.presssure = pe.pressure;
  12116. pii.tilt.x = pe.tiltX;
  12117. pii.tilt.y = pe.tiltY;
  12118. pii.isCaptured = this.getCapturedPrimitive(pe.pointerId) !== null;
  12119. }
  12120. return true;
  12121. };
  12122. Canvas2D.prototype._updateIntersectionList = function (mouseLocalPos, isCapture, force) {
  12123. if (!force && (this.scene.getRenderId() === this._intersectionRenderId)) {
  12124. return;
  12125. }
  12126. // 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
  12127. if (!this._globalTransform) {
  12128. this.updateCachedStates(true);
  12129. }
  12130. var ii = Canvas2D._interInfo;
  12131. ii.pickPosition.x = mouseLocalPos.x;
  12132. ii.pickPosition.y = mouseLocalPos.y;
  12133. ii.findFirstOnly = false;
  12134. // Fast rejection: test if the mouse pointer is outside the canvas's bounding Info
  12135. if (!isCapture && !this.levelBoundingInfo.doesIntersect(ii.pickPosition)) {
  12136. // Reset intersection info as we don't hit anything
  12137. ii.intersectedPrimitives = new Array();
  12138. ii.topMostIntersectedPrimitive = null;
  12139. }
  12140. else {
  12141. // The pointer is inside the Canvas, do an intersection test
  12142. this.intersect(ii);
  12143. }
  12144. {
  12145. // Update prev/actual intersection info, fire "overPrim" property change if needed
  12146. this._previousIntersectionList = this._actualIntersectionList;
  12147. this._actualIntersectionList = ii.intersectedPrimitives;
  12148. this._previousOverPrimitive = this._actualOverPrimitive;
  12149. this._actualOverPrimitive = ii.topMostIntersectedPrimitive;
  12150. var prev = (this._previousOverPrimitive != null) ? this._previousOverPrimitive.prim : null;
  12151. var actual = (this._actualOverPrimitive != null) ? this._actualOverPrimitive.prim : null;
  12152. if (prev !== actual) {
  12153. this.onPropertyChanged("overPrim", this._previousOverPrimitive ? this._previousOverPrimitive.prim : null, this._actualOverPrimitive ? this._actualOverPrimitive.prim : null);
  12154. }
  12155. }
  12156. this._intersectionRenderId = this.scene.getRenderId();
  12157. };
  12158. // Based on the previousIntersectionList and the actualInstersectionList we can determined which primitives are being hover state or loosing it
  12159. Canvas2D.prototype._updateOverStatus = function (force) {
  12160. if ((!force && (this.scene.getRenderId() === this._hoverStatusRenderId)) || !this._previousIntersectionList || !this._actualIntersectionList) {
  12161. return;
  12162. }
  12163. // Detect a change of over
  12164. var prevPrim = this._previousOverPrimitive ? this._previousOverPrimitive.prim : null;
  12165. var actualPrim = this._actualOverPrimitive ? this._actualOverPrimitive.prim : null;
  12166. if (prevPrim !== actualPrim) {
  12167. // Detect if the current pointer is captured, only fire event if they belong to the capture primitive
  12168. var capturedPrim = this.getCapturedPrimitive(this._primPointerInfo.pointerId);
  12169. // Notify the previous "over" prim that the pointer is no longer over it
  12170. if ((capturedPrim && capturedPrim === prevPrim) || (!capturedPrim && prevPrim && !prevPrim.isDisposed)) {
  12171. this._primPointerInfo.updateRelatedTarget(prevPrim, this._previousOverPrimitive.intersectionLocation);
  12172. this._bubbleNotifyPrimPointerObserver(prevPrim, BABYLON.PrimitivePointerInfo.PointerOut, null);
  12173. }
  12174. // Notify the new "over" prim that the pointer is over it
  12175. if ((capturedPrim && capturedPrim === actualPrim) || (!capturedPrim && actualPrim)) {
  12176. this._primPointerInfo.updateRelatedTarget(actualPrim, this._actualOverPrimitive.intersectionLocation);
  12177. this._bubbleNotifyPrimPointerObserver(actualPrim, BABYLON.PrimitivePointerInfo.PointerOver, null);
  12178. }
  12179. }
  12180. this._hoverStatusRenderId = this.scene.getRenderId();
  12181. };
  12182. Canvas2D.prototype._updatePrimPointerPos = function (prim) {
  12183. if (this._primPointerInfo.isCaptured) {
  12184. this._primPointerInfo.primitivePointerPos = this._primPointerInfo.relatedTargetPointerPos;
  12185. }
  12186. else {
  12187. for (var _i = 0, _a = this._actualIntersectionList; _i < _a.length; _i++) {
  12188. var pii = _a[_i];
  12189. if (pii.prim === prim) {
  12190. this._primPointerInfo.primitivePointerPos = pii.intersectionLocation;
  12191. return;
  12192. }
  12193. }
  12194. }
  12195. };
  12196. Canvas2D.prototype._debugExecObserver = function (prim, mask) {
  12197. if (!this._notifDebugMode) {
  12198. return;
  12199. }
  12200. var debug = "";
  12201. for (var i = 0; i < prim.hierarchyDepth; i++) {
  12202. debug += " ";
  12203. }
  12204. var pii = this._primPointerInfo;
  12205. 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();
  12206. console.log(debug);
  12207. };
  12208. Canvas2D.prototype._bubbleNotifyPrimPointerObserver = function (prim, mask, eventData) {
  12209. var ppi = this._primPointerInfo;
  12210. var event = eventData ? eventData.event : null;
  12211. // In case of PointerOver/Out we will first notify the parent with PointerEnter/Leave
  12212. if ((mask & (BABYLON.PrimitivePointerInfo.PointerOver | BABYLON.PrimitivePointerInfo.PointerOut)) !== 0) {
  12213. this._notifParents(prim, mask);
  12214. }
  12215. var bubbleCancelled = false;
  12216. var cur = prim;
  12217. while (cur && !cur.isDisposed) {
  12218. // Only trigger the observers if the primitive is intersected (except for out)
  12219. if (!bubbleCancelled) {
  12220. this._updatePrimPointerPos(cur);
  12221. // Exec the observers
  12222. this._debugExecObserver(cur, mask);
  12223. if (!cur._pointerEventObservable.notifyObservers(ppi, mask) && eventData instanceof BABYLON.PointerInfoPre) {
  12224. eventData.skipOnPointerObservable = true;
  12225. return false;
  12226. }
  12227. this._triggerActionManager(cur, ppi, mask, event);
  12228. // Bubble canceled? If we're not executing PointerOver or PointerOut, quit immediately
  12229. // If it's PointerOver/Out we have to trigger PointerEnter/Leave no matter what
  12230. if (ppi.cancelBubble) {
  12231. if ((mask & (BABYLON.PrimitivePointerInfo.PointerOver | BABYLON.PrimitivePointerInfo.PointerOut)) === 0) {
  12232. return false;
  12233. }
  12234. // We're dealing with PointerOver/Out, let's keep looping to fire PointerEnter/Leave, but not Over/Out anymore
  12235. bubbleCancelled = true;
  12236. }
  12237. }
  12238. // If bubble is cancel we didn't update the Primitive Pointer Pos yet, let's do it
  12239. if (bubbleCancelled) {
  12240. this._updatePrimPointerPos(cur);
  12241. }
  12242. // 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
  12243. //// Trigger a PointerEnter corresponding to the PointerOver
  12244. //if (mask === PrimitivePointerInfo.PointerOver) {
  12245. // this._debugExecObserver(cur, PrimitivePointerInfo.PointerEnter);
  12246. // cur._pointerEventObservable.notifyObservers(ppi, PrimitivePointerInfo.PointerEnter);
  12247. //}
  12248. //// Trigger a PointerLeave corresponding to the PointerOut
  12249. //else if (mask === PrimitivePointerInfo.PointerOut) {
  12250. // this._debugExecObserver(cur, PrimitivePointerInfo.PointerLeave);
  12251. // cur._pointerEventObservable.notifyObservers(ppi, PrimitivePointerInfo.PointerLeave);
  12252. //}
  12253. // Loop to the parent
  12254. cur = cur.parent;
  12255. }
  12256. return true;
  12257. };
  12258. Canvas2D.prototype._triggerActionManager = function (prim, ppi, mask, eventData) {
  12259. var _this = this;
  12260. // 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
  12261. if (!this._globalTransform) {
  12262. this.updateCachedStates(true);
  12263. }
  12264. // Process Trigger related to PointerDown
  12265. if ((mask & BABYLON.PrimitivePointerInfo.PointerDown) !== 0) {
  12266. // On pointer down, record the current position and time to be able to trick PickTrigger and LongPressTrigger
  12267. this._pickStartingPosition = ppi.primitivePointerPos.clone();
  12268. this._pickStartingTime = new Date().getTime();
  12269. this._pickedDownPrim = null;
  12270. if (prim.actionManager) {
  12271. this._pickedDownPrim = prim;
  12272. if (prim.actionManager.hasPickTriggers) {
  12273. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  12274. switch (eventData.button) {
  12275. case 0:
  12276. prim.actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger, actionEvent);
  12277. break;
  12278. case 1:
  12279. prim.actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger, actionEvent);
  12280. break;
  12281. case 2:
  12282. prim.actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger, actionEvent);
  12283. break;
  12284. }
  12285. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPickDownTrigger, actionEvent);
  12286. }
  12287. if (prim.actionManager.hasSpecificTrigger(BABYLON.ActionManager.OnLongPressTrigger)) {
  12288. window.setTimeout(function () {
  12289. var ppi = _this._primPointerInfo;
  12290. var capturedPrim = _this.getCapturedPrimitive(ppi.pointerId);
  12291. _this._updateIntersectionList(ppi.canvasPointerPos, capturedPrim !== null, true);
  12292. _this._updateOverStatus(false);
  12293. var ii = new BABYLON.IntersectInfo2D();
  12294. ii.pickPosition = ppi.canvasPointerPos.clone();
  12295. ii.findFirstOnly = false;
  12296. _this.intersect(ii);
  12297. if (ii.isPrimIntersected(prim) !== null) {
  12298. if (prim.actionManager) {
  12299. 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)) {
  12300. _this._pickStartingTime = 0;
  12301. prim.actionManager.processTrigger(BABYLON.ActionManager.OnLongPressTrigger, BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData));
  12302. }
  12303. }
  12304. }
  12305. }, BABYLON.ActionManager.LongPressDelay);
  12306. }
  12307. }
  12308. }
  12309. else if ((mask & BABYLON.PrimitivePointerInfo.PointerUp) !== 0) {
  12310. this._pickStartingTime = 0;
  12311. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  12312. if (prim.actionManager) {
  12313. // OnPickUpTrigger
  12314. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPickUpTrigger, actionEvent);
  12315. // OnPickTrigger
  12316. if (Math.abs(this._pickStartingPosition.x - ppi.canvasPointerPos.x) < BABYLON.ActionManager.DragMovementThreshold && Math.abs(this._pickStartingPosition.y - ppi.canvasPointerPos.y) < BABYLON.ActionManager.DragMovementThreshold) {
  12317. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger, actionEvent);
  12318. }
  12319. }
  12320. // OnPickOutTrigger
  12321. if (this._pickedDownPrim && this._pickedDownPrim.actionManager && (this._pickedDownPrim !== prim)) {
  12322. this._pickedDownPrim.actionManager.processTrigger(BABYLON.ActionManager.OnPickOutTrigger, actionEvent);
  12323. }
  12324. }
  12325. else if ((mask & BABYLON.PrimitivePointerInfo.PointerOver) !== 0) {
  12326. if (prim.actionManager) {
  12327. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  12328. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOverTrigger, actionEvent);
  12329. }
  12330. }
  12331. else if ((mask & BABYLON.PrimitivePointerInfo.PointerOut) !== 0) {
  12332. if (prim.actionManager) {
  12333. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  12334. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOutTrigger, actionEvent);
  12335. }
  12336. }
  12337. };
  12338. Canvas2D.prototype._notifParents = function (prim, mask) {
  12339. var pii = this._primPointerInfo;
  12340. var curPrim = this;
  12341. while (curPrim) {
  12342. this._updatePrimPointerPos(curPrim);
  12343. // Fire the proper notification
  12344. if (mask === BABYLON.PrimitivePointerInfo.PointerOver) {
  12345. this._debugExecObserver(curPrim, BABYLON.PrimitivePointerInfo.PointerEnter);
  12346. curPrim._pointerEventObservable.notifyObservers(pii, BABYLON.PrimitivePointerInfo.PointerEnter);
  12347. }
  12348. else if (mask === BABYLON.PrimitivePointerInfo.PointerOut) {
  12349. this._debugExecObserver(curPrim, BABYLON.PrimitivePointerInfo.PointerLeave);
  12350. curPrim._pointerEventObservable.notifyObservers(pii, BABYLON.PrimitivePointerInfo.PointerLeave);
  12351. }
  12352. curPrim = curPrim.parent;
  12353. }
  12354. };
  12355. /**
  12356. * Don't forget to call the dispose method when you're done with the Canvas instance.
  12357. * But don't worry, if you dispose its scene, the canvas will be automatically disposed too.
  12358. */
  12359. Canvas2D.prototype.dispose = function () {
  12360. if (!_super.prototype.dispose.call(this)) {
  12361. return false;
  12362. }
  12363. if (this._profilingCanvas) {
  12364. this._profilingCanvas.dispose();
  12365. this._profilingCanvas = null;
  12366. }
  12367. if (this.interactionEnabled) {
  12368. this._setupInteraction(false);
  12369. }
  12370. if (this._renderingGroupObserver) {
  12371. this._scene.onRenderingGroupObservable.remove(this._renderingGroupObserver);
  12372. this._renderingGroupObserver = null;
  12373. }
  12374. if (this._beforeRenderObserver) {
  12375. this._scene.onBeforeRenderObservable.remove(this._beforeRenderObserver);
  12376. this._beforeRenderObserver = null;
  12377. }
  12378. if (this._afterRenderObserver) {
  12379. this._scene.onAfterRenderObservable.remove(this._afterRenderObserver);
  12380. this._afterRenderObserver = null;
  12381. }
  12382. if (this._groupCacheMaps) {
  12383. this._groupCacheMaps.forEach(function (k, m) { return m.forEach(function (e) { return e.dispose(); }); });
  12384. this._groupCacheMaps = null;
  12385. }
  12386. // Unregister this instance
  12387. var index = Canvas2D._INSTANCES.indexOf(this);
  12388. if (index > -1) {
  12389. Canvas2D._INSTANCES.splice(index, 1);
  12390. }
  12391. return true;
  12392. };
  12393. Object.defineProperty(Canvas2D.prototype, "scene", {
  12394. /**
  12395. * Accessor to the Scene that owns the Canvas
  12396. * @returns The instance of the Scene object
  12397. */
  12398. get: function () {
  12399. return this._scene;
  12400. },
  12401. enumerable: true,
  12402. configurable: true
  12403. });
  12404. Object.defineProperty(Canvas2D.prototype, "engine", {
  12405. /**
  12406. * Accessor to the Engine that drives the Scene used by this Canvas
  12407. * @returns The instance of the Engine object
  12408. */
  12409. get: function () {
  12410. return this._engine;
  12411. },
  12412. enumerable: true,
  12413. configurable: true
  12414. });
  12415. Object.defineProperty(Canvas2D.prototype, "uid", {
  12416. /**
  12417. * return a unique identifier for the Canvas2D
  12418. */
  12419. get: function () {
  12420. if (!this._uid) {
  12421. this._uid = BABYLON.Tools.RandomId();
  12422. }
  12423. return this._uid;
  12424. },
  12425. enumerable: true,
  12426. configurable: true
  12427. });
  12428. Object.defineProperty(Canvas2D.prototype, "renderObservable", {
  12429. /**
  12430. * And observable called during the Canvas rendering process.
  12431. * This observable is called twice per render, each time with a different mask:
  12432. * - 1: before render is executed
  12433. * - 2: after render is executed
  12434. */
  12435. get: function () {
  12436. if (!this._renderObservable) {
  12437. this._renderObservable = new BABYLON.Observable();
  12438. }
  12439. return this._renderObservable;
  12440. },
  12441. enumerable: true,
  12442. configurable: true
  12443. });
  12444. Object.defineProperty(Canvas2D.prototype, "cachingStrategy", {
  12445. /**
  12446. * Accessor of the Caching Strategy used by this Canvas.
  12447. * See Canvas2D.CACHESTRATEGY_xxxx static members for more information
  12448. * @returns the value corresponding to the used strategy.
  12449. */
  12450. get: function () {
  12451. return this._cachingStrategy;
  12452. },
  12453. enumerable: true,
  12454. configurable: true
  12455. });
  12456. Object.defineProperty(Canvas2D.prototype, "isScreenSpace", {
  12457. /**
  12458. * Return true if the Canvas is a Screen Space one, false if it's a World Space one.
  12459. * @returns {}
  12460. */
  12461. get: function () {
  12462. return this._isScreenSpace;
  12463. },
  12464. enumerable: true,
  12465. configurable: true
  12466. });
  12467. Object.defineProperty(Canvas2D.prototype, "worldSpaceCanvasNode", {
  12468. /**
  12469. * Only valid for World Space Canvas, returns the scene node that displays the canvas
  12470. */
  12471. get: function () {
  12472. return this._worldSpaceNode;
  12473. },
  12474. set: function (val) {
  12475. this._worldSpaceNode = val;
  12476. },
  12477. enumerable: true,
  12478. configurable: true
  12479. });
  12480. Object.defineProperty(Canvas2D.prototype, "supportInstancedArray", {
  12481. /**
  12482. * Check if the WebGL Instanced Array extension is supported or not
  12483. */
  12484. get: function () {
  12485. return this._supprtInstancedArray;
  12486. },
  12487. enumerable: true,
  12488. configurable: true
  12489. });
  12490. Object.defineProperty(Canvas2D.prototype, "backgroundFill", {
  12491. /**
  12492. * Property that defines the fill object used to draw the background of the Canvas.
  12493. * Note that Canvas with a Caching Strategy of
  12494. * @returns If the background is not set, null will be returned, otherwise a valid fill object is returned.
  12495. */
  12496. get: function () {
  12497. if (!this._background || !this._background.isVisible) {
  12498. return null;
  12499. }
  12500. return this._background.fill;
  12501. },
  12502. set: function (value) {
  12503. this.checkBackgroundAvailability();
  12504. if (value === this._background.fill) {
  12505. return;
  12506. }
  12507. this._background.fill = value;
  12508. this._background.levelVisible = true;
  12509. },
  12510. enumerable: true,
  12511. configurable: true
  12512. });
  12513. Object.defineProperty(Canvas2D.prototype, "backgroundBorder", {
  12514. /**
  12515. * Property that defines the border object used to draw the background of the Canvas.
  12516. * @returns If the background is not set, null will be returned, otherwise a valid border object is returned.
  12517. */
  12518. get: function () {
  12519. if (!this._background || !this._background.isVisible) {
  12520. return null;
  12521. }
  12522. return this._background.border;
  12523. },
  12524. set: function (value) {
  12525. this.checkBackgroundAvailability();
  12526. if (value === this._background.border) {
  12527. return;
  12528. }
  12529. this._background.border = value;
  12530. this._background.levelVisible = true;
  12531. },
  12532. enumerable: true,
  12533. configurable: true
  12534. });
  12535. Object.defineProperty(Canvas2D.prototype, "backgroundBorderThickness", {
  12536. /**
  12537. * Property that defines the thickness of the border object used to draw the background of the Canvas.
  12538. * @returns If the background is not set, null will be returned, otherwise a valid number matching the thickness is returned.
  12539. */
  12540. get: function () {
  12541. if (!this._background || !this._background.isVisible) {
  12542. return null;
  12543. }
  12544. return this._background.borderThickness;
  12545. },
  12546. set: function (value) {
  12547. this.checkBackgroundAvailability();
  12548. if (value === this._background.borderThickness) {
  12549. return;
  12550. }
  12551. this._background.borderThickness = value;
  12552. },
  12553. enumerable: true,
  12554. configurable: true
  12555. });
  12556. Object.defineProperty(Canvas2D.prototype, "backgroundRoundRadius", {
  12557. /**
  12558. * You can set the roundRadius of the background
  12559. * @returns The current roundRadius
  12560. */
  12561. get: function () {
  12562. if (!this._background || !this._background.isVisible) {
  12563. return null;
  12564. }
  12565. return this._background.roundRadius;
  12566. },
  12567. set: function (value) {
  12568. this.checkBackgroundAvailability();
  12569. if (value === this._background.roundRadius) {
  12570. return;
  12571. }
  12572. this._background.roundRadius = value;
  12573. this._background.levelVisible = true;
  12574. },
  12575. enumerable: true,
  12576. configurable: true
  12577. });
  12578. Object.defineProperty(Canvas2D.prototype, "interactionEnabled", {
  12579. /**
  12580. * Enable/Disable interaction for this Canvas
  12581. * When enabled the Prim2DBase.pointerEventObservable property will notified when appropriate events occur
  12582. */
  12583. get: function () {
  12584. return this._interactionEnabled;
  12585. },
  12586. set: function (enable) {
  12587. this._setupInteraction(enable);
  12588. },
  12589. enumerable: true,
  12590. configurable: true
  12591. });
  12592. Object.defineProperty(Canvas2D.prototype, "fitRenderingDevice", {
  12593. get: function () {
  12594. return this._fitRenderingDevice;
  12595. },
  12596. enumerable: true,
  12597. configurable: true
  12598. });
  12599. Object.defineProperty(Canvas2D.prototype, "designSize", {
  12600. get: function () {
  12601. return this._designSize;
  12602. },
  12603. enumerable: true,
  12604. configurable: true
  12605. });
  12606. Object.defineProperty(Canvas2D.prototype, "designSizeUseHorizAxis", {
  12607. get: function () {
  12608. return this._designUseHorizAxis;
  12609. },
  12610. enumerable: true,
  12611. configurable: true
  12612. });
  12613. Object.defineProperty(Canvas2D.prototype, "overPrim", {
  12614. /**
  12615. * Return
  12616. */
  12617. get: function () {
  12618. return this._actualOverPrimitive ? this._actualOverPrimitive.prim : null;
  12619. },
  12620. enumerable: true,
  12621. configurable: true
  12622. });
  12623. Object.defineProperty(Canvas2D.prototype, "_engineData", {
  12624. /**
  12625. * Access the babylon.js' engine bound data, do not invoke this method, it's for internal purpose only
  12626. * @returns {}
  12627. */
  12628. get: function () {
  12629. return this.__engineData;
  12630. },
  12631. enumerable: true,
  12632. configurable: true
  12633. });
  12634. Canvas2D.prototype.createCanvasProfileInfoCanvas = function () {
  12635. if (this._profilingCanvas) {
  12636. return this._profilingCanvas;
  12637. }
  12638. var canvas = new ScreenSpaceCanvas2D(this.scene, {
  12639. id: "ProfileInfoCanvas", cachingStrategy: Canvas2D.CACHESTRATEGY_DONTCACHE, children: [
  12640. new BABYLON.Rectangle2D({
  12641. id: "ProfileBorder", border: "#FFFFFFFF", borderThickness: 2, roundRadius: 5, fill: "#C04040C0", marginAlignment: "h: left, v: top", margin: "10", padding: "10", children: [
  12642. new BABYLON.Text2D("Stats", { id: "ProfileInfoText", marginAlignment: "h: left, v: top", fontName: "12pt Lucida Console", fontSignedDistanceField: true })
  12643. ]
  12644. })
  12645. ]
  12646. });
  12647. this._profileInfoText = canvas.findById("ProfileInfoText");
  12648. this._profilingCanvas = canvas;
  12649. return canvas;
  12650. };
  12651. Canvas2D.prototype.checkBackgroundAvailability = function () {
  12652. if (this._cachingStrategy === Canvas2D.CACHESTRATEGY_TOPLEVELGROUPS) {
  12653. throw Error("Can't use Canvas Background with the caching strategy TOPLEVELGROUPS");
  12654. }
  12655. };
  12656. Canvas2D.prototype._initPerfMetrics = function () {
  12657. this._drawCallsOpaqueCounter.fetchNewFrame();
  12658. this._drawCallsAlphaTestCounter.fetchNewFrame();
  12659. this._drawCallsTransparentCounter.fetchNewFrame();
  12660. this._groupRenderCounter.fetchNewFrame();
  12661. this._updateTransparentDataCounter.fetchNewFrame();
  12662. this._cachedGroupRenderCounter.fetchNewFrame();
  12663. this._updateCachedStateCounter.fetchNewFrame();
  12664. this._updateLayoutCounter.fetchNewFrame();
  12665. this._updatePositioningCounter.fetchNewFrame();
  12666. this._updateLocalTransformCounter.fetchNewFrame();
  12667. this._updateGlobalTransformCounter.fetchNewFrame();
  12668. this._boundingInfoRecomputeCounter.fetchNewFrame();
  12669. };
  12670. Canvas2D.prototype._fetchPerfMetrics = function () {
  12671. this._drawCallsOpaqueCounter.addCount(0, true);
  12672. this._drawCallsAlphaTestCounter.addCount(0, true);
  12673. this._drawCallsTransparentCounter.addCount(0, true);
  12674. this._groupRenderCounter.addCount(0, true);
  12675. this._updateTransparentDataCounter.addCount(0, true);
  12676. this._cachedGroupRenderCounter.addCount(0, true);
  12677. this._updateCachedStateCounter.addCount(0, true);
  12678. this._updateLayoutCounter.addCount(0, true);
  12679. this._updatePositioningCounter.addCount(0, true);
  12680. this._updateLocalTransformCounter.addCount(0, true);
  12681. this._updateGlobalTransformCounter.addCount(0, true);
  12682. this._boundingInfoRecomputeCounter.addCount(0, true);
  12683. };
  12684. Canvas2D.prototype._updateProfileCanvas = function () {
  12685. if (this._profileInfoText == null) {
  12686. return;
  12687. }
  12688. var format = function (v) { return (Math.round(v * 100) / 100).toString(); };
  12689. var p = "Draw Calls:\n" +
  12690. (" - Opaque: " + format(this.drawCallsOpaqueCounter.current) + ", (avg:" + format(this.drawCallsOpaqueCounter.lastSecAverage) + ", t:" + format(this.drawCallsOpaqueCounter.total) + ")\n") +
  12691. (" - AlphaTest: " + format(this.drawCallsAlphaTestCounter.current) + ", (avg:" + format(this.drawCallsAlphaTestCounter.lastSecAverage) + ", t:" + format(this.drawCallsAlphaTestCounter.total) + ")\n") +
  12692. (" - Transparent: " + format(this.drawCallsTransparentCounter.current) + ", (avg:" + format(this.drawCallsTransparentCounter.lastSecAverage) + ", t:" + format(this.drawCallsTransparentCounter.total) + ")\n") +
  12693. ("Group Render: " + this.groupRenderCounter.current + ", (avg:" + format(this.groupRenderCounter.lastSecAverage) + ", t:" + format(this.groupRenderCounter.total) + ")\n") +
  12694. ("Update Transparent Data: " + this.updateTransparentDataCounter.current + ", (avg:" + format(this.updateTransparentDataCounter.lastSecAverage) + ", t:" + format(this.updateTransparentDataCounter.total) + ")\n") +
  12695. ("Cached Group Render: " + this.cachedGroupRenderCounter.current + ", (avg:" + format(this.cachedGroupRenderCounter.lastSecAverage) + ", t:" + format(this.cachedGroupRenderCounter.total) + ")\n") +
  12696. ("Update Cached States: " + this.updateCachedStateCounter.current + ", (avg:" + format(this.updateCachedStateCounter.lastSecAverage) + ", t:" + format(this.updateCachedStateCounter.total) + ")\n") +
  12697. (" - Update Layout: " + this.updateLayoutCounter.current + ", (avg:" + format(this.updateLayoutCounter.lastSecAverage) + ", t:" + format(this.updateLayoutCounter.total) + ")\n") +
  12698. (" - Update Positioning: " + this.updatePositioningCounter.current + ", (avg:" + format(this.updatePositioningCounter.lastSecAverage) + ", t:" + format(this.updatePositioningCounter.total) + ")\n") +
  12699. (" - Update Local Trans: " + this.updateLocalTransformCounter.current + ", (avg:" + format(this.updateLocalTransformCounter.lastSecAverage) + ", t:" + format(this.updateLocalTransformCounter.total) + ")\n") +
  12700. (" - Update Global Trans: " + this.updateGlobalTransformCounter.current + ", (avg:" + format(this.updateGlobalTransformCounter.lastSecAverage) + ", t:" + format(this.updateGlobalTransformCounter.total) + ")\n") +
  12701. (" - BoundingInfo Recompute: " + this.boundingInfoRecomputeCounter.current + ", (avg:" + format(this.boundingInfoRecomputeCounter.lastSecAverage) + ", t:" + format(this.boundingInfoRecomputeCounter.total) + ")");
  12702. this._profileInfoText.text = p;
  12703. };
  12704. Canvas2D.prototype._addDrawCallCount = function (count, renderMode) {
  12705. switch (renderMode) {
  12706. case BABYLON.Render2DContext.RenderModeOpaque:
  12707. this._drawCallsOpaqueCounter.addCount(count, false);
  12708. return;
  12709. case BABYLON.Render2DContext.RenderModeAlphaTest:
  12710. this._drawCallsAlphaTestCounter.addCount(count, false);
  12711. return;
  12712. case BABYLON.Render2DContext.RenderModeTransparent:
  12713. this._drawCallsTransparentCounter.addCount(count, false);
  12714. return;
  12715. }
  12716. };
  12717. Canvas2D.prototype._addGroupRenderCount = function (count) {
  12718. this._groupRenderCounter.addCount(count, false);
  12719. };
  12720. Canvas2D.prototype._addUpdateTransparentDataCount = function (count) {
  12721. this._updateTransparentDataCounter.addCount(count, false);
  12722. };
  12723. Canvas2D.prototype.addCachedGroupRenderCounter = function (count) {
  12724. this._cachedGroupRenderCounter.addCount(count, false);
  12725. };
  12726. Canvas2D.prototype.addUpdateCachedStateCounter = function (count) {
  12727. this._updateCachedStateCounter.addCount(count, false);
  12728. };
  12729. Canvas2D.prototype.addUpdateLayoutCounter = function (count) {
  12730. this._updateLayoutCounter.addCount(count, false);
  12731. };
  12732. Canvas2D.prototype.addUpdatePositioningCounter = function (count) {
  12733. this._updatePositioningCounter.addCount(count, false);
  12734. };
  12735. Canvas2D.prototype.addupdateLocalTransformCounter = function (count) {
  12736. this._updateLocalTransformCounter.addCount(count, false);
  12737. };
  12738. Canvas2D.prototype.addUpdateGlobalTransformCounter = function (count) {
  12739. this._updateGlobalTransformCounter.addCount(count, false);
  12740. };
  12741. Canvas2D.prototype._updateTrackedNodes = function () {
  12742. var cam = this.scene.cameraToUseForPointers || this.scene.activeCamera;
  12743. cam.getViewMatrix().multiplyToRef(cam.getProjectionMatrix(), Canvas2D._m);
  12744. var rh = this.engine.getRenderHeight();
  12745. var v = cam.viewport.toGlobal(this.engine.getRenderWidth(), rh);
  12746. for (var _i = 0, _a = this._trackedGroups; _i < _a.length; _i++) {
  12747. var group = _a[_i];
  12748. if (group.isDisposed || !group.isVisible) {
  12749. continue;
  12750. }
  12751. var node = group.trackedNode;
  12752. var worldMtx = node.getWorldMatrix();
  12753. var proj = BABYLON.Vector3.Project(Canvas2D._v, worldMtx, Canvas2D._m, v);
  12754. var s = this.scale;
  12755. group.x = Math.round(proj.x / s);
  12756. group.y = Math.round((rh - proj.y) / s);
  12757. }
  12758. };
  12759. /**
  12760. * Call this method change you want to have layout related data computed and up to date (layout area, primitive area, local/global transformation matrices)
  12761. */
  12762. Canvas2D.prototype.updateCanvasLayout = function (forceRecompute) {
  12763. this._updateCanvasState(forceRecompute);
  12764. };
  12765. Canvas2D.prototype._updateAdaptiveSizeWorldCanvas = function () {
  12766. if (this._globalTransformStep < 2) {
  12767. return;
  12768. }
  12769. var n = this.worldSpaceCanvasNode;
  12770. var bi = n.getBoundingInfo().boundingBox;
  12771. var v = bi.vectorsWorld;
  12772. var cam = this.scene.cameraToUseForPointers || this.scene.activeCamera;
  12773. cam.getViewMatrix().multiplyToRef(cam.getProjectionMatrix(), Canvas2D._m);
  12774. var vp = cam.viewport.toGlobal(this.engine.getRenderWidth(), this.engine.getRenderHeight());
  12775. var projPoints = new Array(4);
  12776. for (var i = 0; i < 4; i++) {
  12777. projPoints[i] = BABYLON.Vector3.Project(v[i], Canvas2D._mI, Canvas2D._m, vp);
  12778. }
  12779. var left = projPoints[3].subtract(projPoints[0]).length();
  12780. var top = projPoints[3].subtract(projPoints[1]).length();
  12781. var right = projPoints[1].subtract(projPoints[2]).length();
  12782. var bottom = projPoints[2].subtract(projPoints[0]).length();
  12783. var w = Math.round(Math.max(top, bottom));
  12784. var h = Math.round(Math.max(right, left));
  12785. var isW = w > h;
  12786. // Basically if it's under 256 we use 256, otherwise we take the biggest power of 2
  12787. var edge = Math.max(w, h);
  12788. if (edge < 256) {
  12789. edge = 256;
  12790. }
  12791. else {
  12792. edge = Math.pow(2, Math.ceil(Math.log(edge) / Math.log(2)));
  12793. }
  12794. // Clip values if needed
  12795. edge = Math.min(edge, this._maxAdaptiveWorldSpaceCanvasSize);
  12796. var newScale = edge / ((isW) ? this.size.width : this.size.height);
  12797. if (newScale !== this.scale) {
  12798. var scale = newScale;
  12799. // console.log(`New adaptive scale for Canvas ${this.id}, w: ${w}, h: ${h}, scale: ${scale}, edge: ${edge}, isW: ${isW}`);
  12800. this._setRenderingScale(scale);
  12801. }
  12802. };
  12803. Canvas2D.prototype._updateCanvasState = function (forceRecompute) {
  12804. // Check if the update has already been made for this render Frame
  12805. if (!forceRecompute && this.scene.getRenderId() === this._updateRenderId) {
  12806. return;
  12807. }
  12808. // Detect a change of rendering size
  12809. var renderingSizeChanged = false;
  12810. var newWidth = this.engine.getRenderWidth();
  12811. if (newWidth !== this._renderingSize.width) {
  12812. renderingSizeChanged = true;
  12813. }
  12814. this._renderingSize.width = newWidth;
  12815. var newHeight = this.engine.getRenderHeight();
  12816. if (newHeight !== this._renderingSize.height) {
  12817. renderingSizeChanged = true;
  12818. }
  12819. this._renderingSize.height = newHeight;
  12820. // If the canvas fit the rendering size and it changed, update
  12821. if (renderingSizeChanged && this._fitRenderingDevice) {
  12822. this._actualSize = this._renderingSize.clone();
  12823. this._size = this._renderingSize.clone();
  12824. if (this._background) {
  12825. this._background.size = this.size;
  12826. }
  12827. // Dirty the Layout at the Canvas level to recompute as the size changed
  12828. this._setLayoutDirty();
  12829. }
  12830. // If there's a design size, update the scale according to the renderingSize
  12831. if (this._designSize) {
  12832. var scale = void 0;
  12833. if (this._designUseHorizAxis) {
  12834. scale = this._renderingSize.width / this._designSize.width;
  12835. }
  12836. else {
  12837. scale = this._renderingSize.height / this._designSize.height;
  12838. }
  12839. this.size = this._designSize.clone();
  12840. this.actualSize = this._designSize.clone();
  12841. this.scale = scale;
  12842. }
  12843. var context = new BABYLON.PrepareRender2DContext();
  12844. ++this._globalTransformProcessStep;
  12845. this.updateCachedStates(false);
  12846. this._prepareGroupRender(context);
  12847. this._updateRenderId = this.scene.getRenderId();
  12848. };
  12849. /**
  12850. * Method that renders the Canvas, you should not invoke
  12851. */
  12852. Canvas2D.prototype._render = function () {
  12853. this._initPerfMetrics();
  12854. if (this._renderObservable && this._renderObservable.hasObservers()) {
  12855. this._renderObservable.notifyObservers(this, Canvas2D.RENDEROBSERVABLE_PRE);
  12856. }
  12857. this._updateCanvasState(false);
  12858. this._updateTrackedNodes();
  12859. // Nothing to do is the Canvas is not visible
  12860. if (this.isVisible === false) {
  12861. return;
  12862. }
  12863. if (!this._isScreenSpace) {
  12864. this._updateAdaptiveSizeWorldCanvas();
  12865. }
  12866. this._updateCanvasState(false);
  12867. if (this._primPointerInfo.canvasPointerPos) {
  12868. this._updateIntersectionList(this._primPointerInfo.canvasPointerPos, false, false);
  12869. this._updateOverStatus(false);
  12870. }
  12871. this.engine.setState(false);
  12872. this._groupRender();
  12873. if (!this._isScreenSpace) {
  12874. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagWorldCacheChanged)) {
  12875. this.worldSpaceCacheChanged();
  12876. this._clearFlags(BABYLON.SmartPropertyPrim.flagWorldCacheChanged);
  12877. }
  12878. }
  12879. // If the canvas is cached at canvas level, we must manually render the sprite that will display its content
  12880. if (this._cachingStrategy === Canvas2D.CACHESTRATEGY_CANVAS && this._cachedCanvasGroup) {
  12881. this._cachedCanvasGroup._renderCachedCanvas();
  12882. }
  12883. this._fetchPerfMetrics();
  12884. this._updateProfileCanvas();
  12885. if (this._renderObservable && this._renderObservable.hasObservers()) {
  12886. this._renderObservable.notifyObservers(this, Canvas2D.RENDEROBSERVABLE_POST);
  12887. }
  12888. };
  12889. /**
  12890. * Internal method that allocate a cache for the given group.
  12891. * Caching is made using a collection of MapTexture where many groups have their bitmap cache stored inside.
  12892. * @param group The group to allocate the cache of.
  12893. * @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.
  12894. */
  12895. Canvas2D.prototype._allocateGroupCache = function (group, parent, minSize, useMipMap, anisotropicLevel) {
  12896. if (useMipMap === void 0) { useMipMap = false; }
  12897. if (anisotropicLevel === void 0) { anisotropicLevel = 1; }
  12898. var key = (useMipMap ? "MipMap" : "NoMipMap") + "_" + anisotropicLevel;
  12899. var rd = group._renderableData;
  12900. var noResizeScale = rd._noResizeOnScale;
  12901. var isCanvas = parent == null;
  12902. var scale;
  12903. if (noResizeScale) {
  12904. scale = isCanvas ? Canvas2D._unS : group.parent.actualScale;
  12905. }
  12906. else {
  12907. scale = group.actualScale;
  12908. }
  12909. // Determine size
  12910. var size = group.actualSize;
  12911. size = new BABYLON.Size(Math.ceil(size.width * scale.x), Math.ceil(size.height * scale.y));
  12912. var originalSize = size.clone();
  12913. if (minSize) {
  12914. size.width = Math.max(minSize.width, size.width);
  12915. size.height = Math.max(minSize.height, size.height);
  12916. }
  12917. var mapArray = this._groupCacheMaps.getOrAddWithFactory(key, function () { return new Array(); });
  12918. // Try to find a spot in one of the cached texture
  12919. var res = null;
  12920. var map;
  12921. for (var _i = 0, mapArray_1 = mapArray; _i < mapArray_1.length; _i++) {
  12922. var _map = mapArray_1[_i];
  12923. map = _map;
  12924. var node = map.allocateRect(size);
  12925. if (node) {
  12926. res = { node: node, texture: map };
  12927. break;
  12928. }
  12929. }
  12930. // Couldn't find a map that could fit the rect, create a new map for it
  12931. if (!res) {
  12932. var mapSize = new BABYLON.Size(Canvas2D._groupTextureCacheSize, Canvas2D._groupTextureCacheSize);
  12933. // Check if the predefined size would fit, other create a custom size using the nearest bigger power of 2
  12934. if (size.width > mapSize.width || size.height > mapSize.height) {
  12935. mapSize.width = Math.pow(2, Math.ceil(Math.log(size.width) / Math.log(2)));
  12936. mapSize.height = Math.pow(2, Math.ceil(Math.log(size.height) / Math.log(2)));
  12937. }
  12938. var id = "groupsMapChache" + this._mapCounter++ + "forCanvas" + this.id;
  12939. map = new BABYLON.MapTexture(id, this._scene, mapSize, useMipMap ? BABYLON.Texture.TRILINEAR_SAMPLINGMODE : BABYLON.Texture.BILINEAR_SAMPLINGMODE, useMipMap);
  12940. map.hasAlpha = true;
  12941. map.anisotropicFilteringLevel = 4;
  12942. mapArray.splice(0, 0, map);
  12943. var node = map.allocateRect(size);
  12944. res = { node: node, texture: map };
  12945. }
  12946. // Check if we have to create a Sprite that will display the content of the Canvas which is cached.
  12947. // Don't do it in case of the group being a worldspace canvas (because its texture is bound to a WorldSpaceCanvas node)
  12948. if (group !== this || this._isScreenSpace) {
  12949. var node = res.node;
  12950. // 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
  12951. var sprite = void 0;
  12952. if (this._cachingStrategy === Canvas2D.CACHESTRATEGY_CANVAS) {
  12953. if (this._cachedCanvasGroup) {
  12954. this._cachedCanvasGroup.dispose();
  12955. }
  12956. this._cachedCanvasGroup = BABYLON.Group2D._createCachedCanvasGroup(this);
  12957. sprite = new BABYLON.Sprite2D(map, { parent: this._cachedCanvasGroup, id: "__cachedCanvasSprite__", spriteSize: originalSize, spriteLocation: node.pos });
  12958. sprite.zOrder = 1;
  12959. sprite.origin = BABYLON.Vector2.Zero();
  12960. }
  12961. else {
  12962. 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 });
  12963. sprite.origin = group.origin.clone();
  12964. sprite.addExternalData("__cachedGroup__", group);
  12965. sprite.pointerEventObservable.add(function (e, s) {
  12966. if (group.pointerEventObservable !== null) {
  12967. group.pointerEventObservable.notifyObservers(e, s.mask);
  12968. }
  12969. });
  12970. res.sprite = sprite;
  12971. }
  12972. if (sprite && noResizeScale) {
  12973. var relScale = isCanvas ? group.actualScale : group.actualScale.divide(group.parent.actualScale);
  12974. sprite.scaleX = relScale.x;
  12975. sprite.scaleY = relScale.y;
  12976. }
  12977. }
  12978. return res;
  12979. };
  12980. /**
  12981. * Internal method used to register a Scene Node to track position for the given group
  12982. * Do not invoke this method, for internal purpose only.
  12983. * @param group the group to track its associated Scene Node
  12984. */
  12985. Canvas2D.prototype._registerTrackedNode = function (group) {
  12986. if (group._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  12987. return;
  12988. }
  12989. this._trackedGroups.push(group);
  12990. group._setFlags(BABYLON.SmartPropertyPrim.flagTrackedGroup);
  12991. };
  12992. /**
  12993. * Internal method used to unregister a tracked Scene Node
  12994. * Do not invoke this method, it's for internal purpose only.
  12995. * @param group the group to unregister its tracked Scene Node from.
  12996. */
  12997. Canvas2D.prototype._unregisterTrackedNode = function (group) {
  12998. if (!group._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  12999. return;
  13000. }
  13001. var i = this._trackedGroups.indexOf(group);
  13002. if (i !== -1) {
  13003. this._trackedGroups.splice(i, 1);
  13004. }
  13005. group._clearFlags(BABYLON.SmartPropertyPrim.flagTrackedGroup);
  13006. };
  13007. /**
  13008. * Get a Solid Color Brush instance matching the given color.
  13009. * @param color The color to retrieve
  13010. * @return A shared instance of the SolidColorBrush2D class that use the given color
  13011. */
  13012. Canvas2D.GetSolidColorBrush = function (color) {
  13013. return Canvas2D._solidColorBrushes.getOrAddWithFactory(color.toHexString(), function () { return new BABYLON.SolidColorBrush2D(color.clone(), true); });
  13014. };
  13015. /**
  13016. * Get a Solid Color Brush instance matching the given color expressed as a CSS formatted hexadecimal value.
  13017. * @param color The color to retrieve
  13018. * @return A shared instance of the SolidColorBrush2D class that uses the given color
  13019. */
  13020. Canvas2D.GetSolidColorBrushFromHex = function (hexValue) {
  13021. return Canvas2D._solidColorBrushes.getOrAddWithFactory(hexValue, function () { return new BABYLON.SolidColorBrush2D(BABYLON.Color4.FromHexString(hexValue), true); });
  13022. };
  13023. /**
  13024. * Get a Gradient Color Brush
  13025. * @param color1 starting color
  13026. * @param color2 engine color
  13027. * @param translation translation vector to apply. default is [0;0]
  13028. * @param rotation rotation in radian to apply to the brush, initial direction is top to bottom. rotation is counter clockwise. default is 0.
  13029. * @param scale scaling factor to apply. default is 1.
  13030. */
  13031. Canvas2D.GetGradientColorBrush = function (color1, color2, translation, rotation, scale) {
  13032. if (translation === void 0) { translation = BABYLON.Vector2.Zero(); }
  13033. if (rotation === void 0) { rotation = 0; }
  13034. if (scale === void 0) { scale = 1; }
  13035. return Canvas2D._gradientColorBrushes.getOrAddWithFactory(BABYLON.GradientColorBrush2D.BuildKey(color1, color2, translation, rotation, scale), function () { return new BABYLON.GradientColorBrush2D(color1, color2, translation, rotation, scale, true); });
  13036. };
  13037. /**
  13038. * Create a solid or gradient brush from a string value.
  13039. * @param brushString should be either
  13040. * - "solid: #RRGGBBAA" or "#RRGGBBAA"
  13041. * - "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.
  13042. */
  13043. Canvas2D.GetBrushFromString = function (brushString) {
  13044. // Note: yes, I hate/don't know RegEx.. Feel free to add your contribution to the cause!
  13045. brushString = brushString.trim();
  13046. var split = brushString.split(",");
  13047. // Solid, formatted as: "[solid:]#FF808080"
  13048. if (split.length === 1) {
  13049. var value = null;
  13050. if (brushString.indexOf("solid:") === 0) {
  13051. value = brushString.substr(6).trim();
  13052. }
  13053. else if (brushString.indexOf("#") === 0) {
  13054. value = brushString;
  13055. }
  13056. else {
  13057. return null;
  13058. }
  13059. return Canvas2D.GetSolidColorBrushFromHex(value);
  13060. }
  13061. else {
  13062. if (split[0].indexOf("gradient:") === 0) {
  13063. split[0] = split[0].substr(9).trim();
  13064. }
  13065. try {
  13066. var start = BABYLON.Color4.FromHexString(split[0].trim());
  13067. var end = BABYLON.Color4.FromHexString(split[1].trim());
  13068. var t = BABYLON.Vector2.Zero();
  13069. if (split.length > 2) {
  13070. var v = split[2].trim();
  13071. if (v.charAt(0) !== "[" || v.charAt(v.length - 1) !== "]") {
  13072. return null;
  13073. }
  13074. var sep = v.indexOf(":");
  13075. var x = parseFloat(v.substr(1, sep));
  13076. var y = parseFloat(v.substr(sep + 1, v.length - (sep + 1)));
  13077. t = new BABYLON.Vector2(x, y);
  13078. }
  13079. var r = 0;
  13080. if (split.length > 3) {
  13081. r = BABYLON.Tools.ToRadians(parseFloat(split[3].trim()));
  13082. }
  13083. var s = 1;
  13084. if (split.length > 4) {
  13085. s = parseFloat(split[4].trim());
  13086. }
  13087. return Canvas2D.GetGradientColorBrush(start, end, t, r, s);
  13088. }
  13089. catch (e) {
  13090. return null;
  13091. }
  13092. }
  13093. };
  13094. /**
  13095. * 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.
  13096. * This strategy doesn't allow primitives added directly as children of the Canvas.
  13097. * 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.
  13098. */
  13099. Canvas2D.CACHESTRATEGY_TOPLEVELGROUPS = 1;
  13100. /**
  13101. * In this strategy each group will have its own cache bitmap (except if a given group explicitly defines the DONTCACHEOVERRIDE or CACHEINPARENTGROUP behaviors).
  13102. * 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.
  13103. * When using this strategy, group instances can rely on the DONTCACHEOVERRIDE or CACHEINPARENTGROUP behaviors to minimize the amount of cached bitmaps.
  13104. * 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.
  13105. */
  13106. Canvas2D.CACHESTRATEGY_ALLGROUPS = 2;
  13107. /**
  13108. * 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).
  13109. */
  13110. Canvas2D.CACHESTRATEGY_CANVAS = 3;
  13111. /**
  13112. * This strategy is used to recompose/redraw the canvas entirely at each viewport render.
  13113. * 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).
  13114. * Note that you can't use this strategy for WorldSpace Canvas, they need at least a top level group caching.
  13115. */
  13116. Canvas2D.CACHESTRATEGY_DONTCACHE = 4;
  13117. /**
  13118. * Observable Mask to be notified before rendering is made
  13119. */
  13120. Canvas2D.RENDEROBSERVABLE_PRE = 1;
  13121. /**
  13122. * Observable Mask to be notified after rendering is made
  13123. */
  13124. Canvas2D.RENDEROBSERVABLE_POST = 2;
  13125. Canvas2D._INSTANCES = [];
  13126. Canvas2D._zMinDelta = 1 / (Math.pow(2, 24) - 1);
  13127. Canvas2D._interInfo = new BABYLON.IntersectInfo2D();
  13128. Canvas2D._v = BABYLON.Vector3.Zero(); // Must stay zero
  13129. Canvas2D._m = BABYLON.Matrix.Identity();
  13130. Canvas2D._mI = BABYLON.Matrix.Identity(); // Must stay identity
  13131. /**
  13132. * Define the default size used for both the width and height of a MapTexture to allocate.
  13133. * Note that some MapTexture might be bigger than this size if the first node to allocate is bigger in width or height
  13134. */
  13135. Canvas2D._groupTextureCacheSize = 1024;
  13136. Canvas2D._solidColorBrushes = new BABYLON.StringDictionary();
  13137. Canvas2D._gradientColorBrushes = new BABYLON.StringDictionary();
  13138. Canvas2D = __decorate([
  13139. BABYLON.className("Canvas2D", "BABYLON")
  13140. ], Canvas2D);
  13141. return Canvas2D;
  13142. }(BABYLON.Group2D));
  13143. BABYLON.Canvas2D = Canvas2D;
  13144. var WorldSpaceCanvas2D = (function (_super) {
  13145. __extends(WorldSpaceCanvas2D, _super);
  13146. /**
  13147. * 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.
  13148. * 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.
  13149. * @param scene the Scene that owns the Canvas
  13150. * @param size the dimension of the Canvas in World Space
  13151. * @param settings a combination of settings, possible ones are
  13152. * - children: an array of direct children primitives
  13153. * - id: a text identifier, for information purpose only, default is null.
  13154. * - worldPosition the position of the Canvas in World Space, default is [0,0,0]
  13155. * - worldRotation the rotation of the Canvas in World Space, default is Quaternion.Identity()
  13156. * - sideOrientation: Unexpected behavior occur if the value is different from Mesh.DEFAULTSIDE right now, so please use this one, which is the default.
  13157. * - cachingStrategy Must be CACHESTRATEGY_CANVAS for now, which is the default.
  13158. * - 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).
  13159. * - isVisible: true if the canvas must be visible, false for hidden. Default is true.
  13160. * - backgroundRoundRadius: the round radius of the background, either backgroundFill or backgroundBorder must be specified.
  13161. * - 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.
  13162. * - 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.
  13163. * - backgroundBorderThickness: if a backgroundBorder is specified, its thickness can be set using this property
  13164. * - 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.
  13165. * - 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.
  13166. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  13167. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  13168. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  13169. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  13170. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  13171. */
  13172. function WorldSpaceCanvas2D(scene, size, settings) {
  13173. var _this = this;
  13174. BABYLON.Prim2DBase._isCanvasInit = true;
  13175. var s = settings;
  13176. s.isScreenSpace = false;
  13177. s.size = size.clone();
  13178. settings.cachingStrategy = (settings.cachingStrategy == null) ? Canvas2D.CACHESTRATEGY_CANVAS : settings.cachingStrategy;
  13179. if (settings.cachingStrategy !== Canvas2D.CACHESTRATEGY_CANVAS) {
  13180. throw new Error("Right now only the CACHESTRATEGY_CANVAS cache Strategy is supported for WorldSpace Canvas. More will come soon!");
  13181. }
  13182. _super.call(this, scene, settings);
  13183. BABYLON.Prim2DBase._isCanvasInit = false;
  13184. this._renderableData._useMipMap = true;
  13185. this._renderableData._anisotropicLevel = 8;
  13186. //if (cachingStrategy === Canvas2D.CACHESTRATEGY_DONTCACHE) {
  13187. // throw new Error("CACHESTRATEGY_DONTCACHE cache Strategy can't be used for WorldSpace Canvas");
  13188. //}
  13189. var createWorldSpaceNode = !settings || (settings.customWorldSpaceNode == null);
  13190. this._customWorldSpaceNode = !createWorldSpaceNode;
  13191. var id = settings ? settings.id || null : null;
  13192. // Set the max size of texture allowed for the adaptive render of the world space canvas cached bitmap
  13193. var capMaxTextSize = this.engine.getCaps().maxRenderTextureSize;
  13194. var defaultTextSize = (Math.min(capMaxTextSize, 1024)); // Default is 4K if allowed otherwise the max allowed
  13195. if (settings.maxAdaptiveCanvasSize == null) {
  13196. this._maxAdaptiveWorldSpaceCanvasSize = defaultTextSize;
  13197. }
  13198. else {
  13199. // We still clip the given value with the max allowed, the user may not be aware of these limitations
  13200. this._maxAdaptiveWorldSpaceCanvasSize = Math.min(settings.maxAdaptiveCanvasSize, capMaxTextSize);
  13201. }
  13202. if (createWorldSpaceNode) {
  13203. var plane = new BABYLON.WorldSpaceCanvas2DNode(id, scene, this);
  13204. var vertexData = BABYLON.VertexData.CreatePlane({
  13205. width: size.width,
  13206. height: size.height,
  13207. sideOrientation: settings && settings.sideOrientation || BABYLON.Mesh.DEFAULTSIDE
  13208. });
  13209. var mtl = new BABYLON.StandardMaterial(id + "_Material", scene);
  13210. this.applyCachedTexture(vertexData, mtl);
  13211. vertexData.applyToMesh(plane, true);
  13212. mtl.specularColor = new BABYLON.Color3(0, 0, 0);
  13213. mtl.disableLighting = true;
  13214. mtl.useAlphaFromDiffuseTexture = true;
  13215. plane.position = settings && settings.worldPosition || BABYLON.Vector3.Zero();
  13216. plane.rotationQuaternion = settings && settings.worldRotation || BABYLON.Quaternion.Identity();
  13217. plane.material = mtl;
  13218. this._worldSpaceNode = plane;
  13219. }
  13220. else {
  13221. this._worldSpaceNode = settings.customWorldSpaceNode;
  13222. this.applyCachedTexture(null, null);
  13223. }
  13224. this.propertyChanged.add(function (e, st) {
  13225. var mesh = _this._worldSpaceNode;
  13226. if (mesh) {
  13227. mesh.isVisible = e.newValue;
  13228. }
  13229. }, BABYLON.Prim2DBase.isVisibleProperty.flagId);
  13230. }
  13231. WorldSpaceCanvas2D.prototype.dispose = function () {
  13232. if (!_super.prototype.dispose.call(this)) {
  13233. return false;
  13234. }
  13235. if (!this._customWorldSpaceNode && this._worldSpaceNode) {
  13236. this._worldSpaceNode.dispose();
  13237. this._worldSpaceNode = null;
  13238. }
  13239. };
  13240. WorldSpaceCanvas2D = __decorate([
  13241. BABYLON.className("WorldSpaceCanvas2D", "BABYLON")
  13242. ], WorldSpaceCanvas2D);
  13243. return WorldSpaceCanvas2D;
  13244. }(Canvas2D));
  13245. BABYLON.WorldSpaceCanvas2D = WorldSpaceCanvas2D;
  13246. var ScreenSpaceCanvas2D = (function (_super) {
  13247. __extends(ScreenSpaceCanvas2D, _super);
  13248. /**
  13249. * 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.
  13250. * 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.
  13251. * All caching strategies will be available.
  13252. * 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]
  13253. * @param scene the Scene that owns the Canvas
  13254. * @param settings a combination of settings, possible ones are
  13255. * - children: an array of direct children primitives
  13256. * - id: a text identifier, for information purpose only
  13257. * - x: the position along the x axis (horizontal), relative to the left edge of the viewport. you can alternatively use the position setting.
  13258. * - y: the position along the y axis (vertically), relative to the bottom edge of the viewport. you can alternatively use the position setting.
  13259. * - 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]
  13260. * - width: the width of the Canvas. you can alternatively use the size setting.
  13261. * - height: the height of the Canvas. you can alternatively use the size setting.
  13262. * - 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
  13263. * - 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.
  13264. * - 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.
  13265. * - 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.
  13266. * - cachingStrategy: either CACHESTRATEGY_TOPLEVELGROUPS, CACHESTRATEGY_ALLGROUPS, CACHESTRATEGY_CANVAS, CACHESTRATEGY_DONTCACHE. Please refer to their respective documentation for more information. Default is Canvas2D.CACHESTRATEGY_DONTCACHE
  13267. * - 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.
  13268. * - isVisible: true if the canvas must be visible, false for hidden. Default is true.
  13269. * - backgroundRoundRadius: the round radius of the background, either backgroundFill or backgroundBorder must be specified.
  13270. * - 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.
  13271. * - 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.
  13272. * - backgroundBorderThickness: if a backgroundBorder is specified, its thickness can be set using this property
  13273. * - 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.
  13274. * - paddingTop: top padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  13275. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  13276. * - paddingRight: right padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  13277. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  13278. * - padding: top, left, right and bottom padding formatted as a single string (see BABYLON.PrimitiveThickness.fromString)
  13279. */
  13280. function ScreenSpaceCanvas2D(scene, settings) {
  13281. BABYLON.Prim2DBase._isCanvasInit = true;
  13282. _super.call(this, scene, settings);
  13283. }
  13284. ScreenSpaceCanvas2D = __decorate([
  13285. BABYLON.className("ScreenSpaceCanvas2D", "BABYLON")
  13286. ], ScreenSpaceCanvas2D);
  13287. return ScreenSpaceCanvas2D;
  13288. }(Canvas2D));
  13289. BABYLON.ScreenSpaceCanvas2D = ScreenSpaceCanvas2D;
  13290. })(BABYLON || (BABYLON = {}));
  13291. //# sourceMappingURL=babylon.canvas2d.js.map
  13292. var __extends = (this && this.__extends) || function (d, b) {
  13293. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  13294. function __() { this.constructor = d; }
  13295. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13296. };
  13297. var BABYLON;
  13298. (function (BABYLON) {
  13299. /**
  13300. * This is the class that is used to display a World Space Canvas into a 3D scene
  13301. */
  13302. var WorldSpaceCanvas2DNode = (function (_super) {
  13303. __extends(WorldSpaceCanvas2DNode, _super);
  13304. function WorldSpaceCanvas2DNode(name, scene, canvas) {
  13305. _super.call(this, name, scene);
  13306. this._canvas = canvas;
  13307. }
  13308. WorldSpaceCanvas2DNode.prototype.dispose = function () {
  13309. _super.prototype.dispose.call(this);
  13310. if (this._canvas) {
  13311. this._canvas.dispose();
  13312. this._canvas = null;
  13313. }
  13314. };
  13315. return WorldSpaceCanvas2DNode;
  13316. }(BABYLON.Mesh));
  13317. BABYLON.WorldSpaceCanvas2DNode = WorldSpaceCanvas2DNode;
  13318. })(BABYLON || (BABYLON = {}));
  13319. //# sourceMappingURL=babylon.worldSpaceCanvas2dNode.js.map
  13320. var __extends = (this && this.__extends) || function (d, b) {
  13321. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  13322. function __() { this.constructor = d; }
  13323. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13324. };
  13325. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  13326. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  13327. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  13328. 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;
  13329. return c > 3 && r && Object.defineProperty(target, key, r), r;
  13330. };
  13331. var BABYLON;
  13332. (function (BABYLON) {
  13333. var Command = (function () {
  13334. function Command(execute, canExecute) {
  13335. if (!execute) {
  13336. throw Error("At least an execute lambda must be given at Command creation time");
  13337. }
  13338. this._canExecuteChanged = null;
  13339. this._lastCanExecuteResult = null;
  13340. this.execute = execute;
  13341. this.canExecute = canExecute;
  13342. }
  13343. Command.prototype.canExecute = function (parameter) {
  13344. var res = true;
  13345. if (this._canExecute) {
  13346. res = this._canExecute(parameter);
  13347. }
  13348. if (res !== this._lastCanExecuteResult) {
  13349. if (this._canExecuteChanged && this._canExecuteChanged.hasObservers()) {
  13350. this._canExecuteChanged.notifyObservers(null);
  13351. }
  13352. this._lastCanExecuteResult = res;
  13353. }
  13354. return res;
  13355. };
  13356. Command.prototype.execute = function (parameter) {
  13357. this._execute(parameter);
  13358. };
  13359. Object.defineProperty(Command.prototype, "canExecuteChanged", {
  13360. get: function () {
  13361. if (!this._canExecuteChanged) {
  13362. this._canExecuteChanged = new BABYLON.Observable();
  13363. }
  13364. return this._canExecuteChanged;
  13365. },
  13366. enumerable: true,
  13367. configurable: true
  13368. });
  13369. return Command;
  13370. }());
  13371. BABYLON.Command = Command;
  13372. var UIElement = (function (_super) {
  13373. __extends(UIElement, _super);
  13374. function UIElement(settings) {
  13375. _super.call(this);
  13376. if (!settings) {
  13377. throw Error("A settings object must be passed with at least either a parent or owner parameter");
  13378. }
  13379. var type = BABYLON.Tools.getFullClassName(this);
  13380. this._ownerWindow = null;
  13381. this._parent = null;
  13382. this._visualPlaceholder = null;
  13383. this._visualTemplateRoot = null;
  13384. this._visualChildrenPlaceholder = null;
  13385. this._hierarchyDepth = 0;
  13386. this._renderingTemplateName = (settings.templateName != null) ? settings.templateName : GUIManager.DefaultTemplateName;
  13387. this._style = (settings.styleName != null) ? GUIManager.getStyle(type, settings.styleName) : null;
  13388. this._flags = 0;
  13389. this._id = (settings.id != null) ? settings.id : null;
  13390. this._uid = null;
  13391. this._width = (settings.width != null) ? settings.width : null;
  13392. this._height = (settings.height != null) ? settings.height : null;
  13393. this._minWidth = (settings.minWidth != null) ? settings.minWidth : 0;
  13394. this._minHeight = (settings.minHeight != null) ? settings.minHeight : 0;
  13395. this._maxWidth = (settings.maxWidth != null) ? settings.maxWidth : Number.MAX_VALUE;
  13396. this._maxHeight = (settings.maxHeight != null) ? settings.maxHeight : Number.MAX_VALUE;
  13397. this._margin = null;
  13398. this._padding = null;
  13399. this._marginAlignment = null;
  13400. this._setFlags(UIElement.flagIsVisible | UIElement.flagIsEnabled);
  13401. // Default Margin Alignment for UIElement is stretch for horizontal/vertical and not left/bottom (which is the default for Canvas2D Primitives)
  13402. //this.marginAlignment.horizontal = PrimitiveAlignment.AlignStretch;
  13403. //this.marginAlignment.vertical = PrimitiveAlignment.AlignStretch;
  13404. // Set the layout/margin stuffs
  13405. if (settings.marginTop) {
  13406. this.margin.setTop(settings.marginTop);
  13407. }
  13408. if (settings.marginLeft) {
  13409. this.margin.setLeft(settings.marginLeft);
  13410. }
  13411. if (settings.marginRight) {
  13412. this.margin.setRight(settings.marginRight);
  13413. }
  13414. if (settings.marginBottom) {
  13415. this.margin.setBottom(settings.marginBottom);
  13416. }
  13417. if (settings.margin) {
  13418. if (typeof settings.margin === "string") {
  13419. this.margin.fromString(settings.margin);
  13420. }
  13421. else {
  13422. this.margin.fromUniformPixels(settings.margin);
  13423. }
  13424. }
  13425. if (settings.marginHAlignment) {
  13426. this.marginAlignment.horizontal = settings.marginHAlignment;
  13427. }
  13428. if (settings.marginVAlignment) {
  13429. this.marginAlignment.vertical = settings.marginVAlignment;
  13430. }
  13431. if (settings.marginAlignment) {
  13432. this.marginAlignment.fromString(settings.marginAlignment);
  13433. }
  13434. if (settings.paddingTop) {
  13435. this.padding.setTop(settings.paddingTop);
  13436. }
  13437. if (settings.paddingLeft) {
  13438. this.padding.setLeft(settings.paddingLeft);
  13439. }
  13440. if (settings.paddingRight) {
  13441. this.padding.setRight(settings.paddingRight);
  13442. }
  13443. if (settings.paddingBottom) {
  13444. this.padding.setBottom(settings.paddingBottom);
  13445. }
  13446. if (settings.padding) {
  13447. this.padding.fromString(settings.padding);
  13448. }
  13449. if (settings.paddingHAlignment) {
  13450. this.paddingAlignment.horizontal = settings.paddingHAlignment;
  13451. }
  13452. if (settings.paddingVAlignment) {
  13453. this.paddingAlignment.vertical = settings.paddingVAlignment;
  13454. }
  13455. if (settings.paddingAlignment) {
  13456. this.paddingAlignment.fromString(settings.paddingAlignment);
  13457. }
  13458. if (settings.parent != null) {
  13459. this._parent = settings.parent;
  13460. this._hierarchyDepth = this._parent._hierarchyDepth + 1;
  13461. }
  13462. }
  13463. Object.defineProperty(UIElement, "enabledState", {
  13464. get: function () {
  13465. return UIElement._enableState;
  13466. },
  13467. enumerable: true,
  13468. configurable: true
  13469. });
  13470. Object.defineProperty(UIElement, "disabledState", {
  13471. get: function () {
  13472. return UIElement._disabledState;
  13473. },
  13474. enumerable: true,
  13475. configurable: true
  13476. });
  13477. Object.defineProperty(UIElement, "mouseOverState", {
  13478. get: function () {
  13479. return UIElement._mouseOverState;
  13480. },
  13481. enumerable: true,
  13482. configurable: true
  13483. });
  13484. UIElement.prototype.dispose = function () {
  13485. if (this.isDisposed) {
  13486. return false;
  13487. }
  13488. if (this._renderingTemplate) {
  13489. this._renderingTemplate.detach();
  13490. this._renderingTemplate = null;
  13491. }
  13492. _super.prototype.dispose.call(this);
  13493. // Don't set to null, it may upset somebody...
  13494. this.animations.splice(0);
  13495. return true;
  13496. };
  13497. /**
  13498. * Returns as a new array populated with the Animatable used by the primitive. Must be overloaded by derived primitives.
  13499. * Look at Sprite2D for more information
  13500. */
  13501. UIElement.prototype.getAnimatables = function () {
  13502. return new Array();
  13503. };
  13504. // TODO
  13505. // PROPERTIES
  13506. // Style
  13507. // Id
  13508. // Parent/Children
  13509. // ActualWidth/Height, MinWidth/Height, MaxWidth/Height,
  13510. // Alignment/Margin
  13511. // Visibility, IsVisible
  13512. // IsEnabled (is false, control is disabled, no interaction and a specific render state)
  13513. // CacheMode of Visual Elements
  13514. // Focusable/IsFocused
  13515. // IsPointerCaptured, CapturePointer, IsPointerDirectlyOver, IsPointerOver. De-correlate mouse, stylus, touch?
  13516. // ContextMenu
  13517. // Cursor
  13518. // DesiredSize
  13519. // IsInputEnable ?
  13520. // Opacity, OpacityMask ?
  13521. // SnapToDevicePixels
  13522. // Tag
  13523. // ToolTip
  13524. // METHODS
  13525. // BringIntoView (for scrollable content, to move the scroll to bring the given element visible in the parent's area)
  13526. // Capture/ReleaseCapture (mouse, touch, stylus)
  13527. // Focus
  13528. // PointFrom/ToScreen to translate coordinates
  13529. // EVENTS
  13530. // ContextMenuOpening/Closing/Changed
  13531. // DragEnter/LeaveOver, Drop
  13532. // Got/LostFocus
  13533. // IsEnabledChanged
  13534. // IsPointerOver/DirectlyOverChanged
  13535. // IsVisibleChanged
  13536. // KeyDown/Up
  13537. // LayoutUpdated ?
  13538. // Pointer related events
  13539. // SizeChanged
  13540. // ToolTipOpening/Closing
  13541. UIElement.prototype.findById = function (id) {
  13542. if (this._id === id) {
  13543. return this;
  13544. }
  13545. var children = this._getChildren();
  13546. for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
  13547. var child = children_1[_i];
  13548. var r = child.findById(id);
  13549. if (r != null) {
  13550. return r;
  13551. }
  13552. }
  13553. };
  13554. Object.defineProperty(UIElement.prototype, "ownerWindow", {
  13555. get: function () {
  13556. return this._ownerWindow;
  13557. },
  13558. enumerable: true,
  13559. configurable: true
  13560. });
  13561. Object.defineProperty(UIElement.prototype, "style", {
  13562. get: function () {
  13563. if (!this.style) {
  13564. return GUIManager.DefaultStyleName;
  13565. }
  13566. return this._style.name;
  13567. },
  13568. set: function (value) {
  13569. if (this._style && (this._style.name === value)) {
  13570. return;
  13571. }
  13572. var newStyle = null;
  13573. if (value) {
  13574. newStyle = GUIManager.getStyle(BABYLON.Tools.getFullClassName(this), value);
  13575. if (!newStyle) {
  13576. throw Error("Couldn't find Style " + value + " for UIElement " + BABYLON.Tools.getFullClassName(this));
  13577. }
  13578. }
  13579. if (this._style) {
  13580. this._style.removeStyle(this);
  13581. }
  13582. if (newStyle) {
  13583. newStyle.applyStyle(this);
  13584. }
  13585. this._style = newStyle;
  13586. },
  13587. enumerable: true,
  13588. configurable: true
  13589. });
  13590. Object.defineProperty(UIElement.prototype, "id", {
  13591. /**
  13592. * A string that identifies the UIElement.
  13593. * The id is optional and there's possible collision with other UIElement's id as the uniqueness is not supported.
  13594. */
  13595. get: function () {
  13596. return this._id;
  13597. },
  13598. set: function (value) {
  13599. if (this._id === value) {
  13600. return;
  13601. }
  13602. this._id = value;
  13603. },
  13604. enumerable: true,
  13605. configurable: true
  13606. });
  13607. Object.defineProperty(UIElement.prototype, "uid", {
  13608. /**
  13609. * Return a unique id automatically generated.
  13610. * This property is mainly used for serialization to ensure a perfect way of identifying a UIElement
  13611. */
  13612. get: function () {
  13613. if (!this._uid) {
  13614. this._uid = BABYLON.Tools.RandomId();
  13615. }
  13616. return this._uid;
  13617. },
  13618. enumerable: true,
  13619. configurable: true
  13620. });
  13621. Object.defineProperty(UIElement.prototype, "hierarchyDepth", {
  13622. get: function () {
  13623. return this._hierarchyDepth;
  13624. },
  13625. enumerable: true,
  13626. configurable: true
  13627. });
  13628. Object.defineProperty(UIElement.prototype, "parent", {
  13629. get: function () {
  13630. return this._parent;
  13631. },
  13632. set: function (value) {
  13633. this._parent = value;
  13634. },
  13635. enumerable: true,
  13636. configurable: true
  13637. });
  13638. Object.defineProperty(UIElement.prototype, "width", {
  13639. get: function () {
  13640. return this._width;
  13641. },
  13642. set: function (value) {
  13643. this._width = value;
  13644. },
  13645. enumerable: true,
  13646. configurable: true
  13647. });
  13648. Object.defineProperty(UIElement.prototype, "height", {
  13649. get: function () {
  13650. return this._height;
  13651. },
  13652. set: function (value) {
  13653. this._height = value;
  13654. },
  13655. enumerable: true,
  13656. configurable: true
  13657. });
  13658. Object.defineProperty(UIElement.prototype, "minWidth", {
  13659. get: function () {
  13660. return this._minWidth;
  13661. },
  13662. set: function (value) {
  13663. this._minWidth = value;
  13664. },
  13665. enumerable: true,
  13666. configurable: true
  13667. });
  13668. Object.defineProperty(UIElement.prototype, "minHheight", {
  13669. get: function () {
  13670. return this._minHeight;
  13671. },
  13672. enumerable: true,
  13673. configurable: true
  13674. });
  13675. Object.defineProperty(UIElement.prototype, "minHeight", {
  13676. set: function (value) {
  13677. this._minHeight = value;
  13678. },
  13679. enumerable: true,
  13680. configurable: true
  13681. });
  13682. Object.defineProperty(UIElement.prototype, "maxWidth", {
  13683. get: function () {
  13684. return this._maxWidth;
  13685. },
  13686. set: function (value) {
  13687. this._maxWidth = value;
  13688. },
  13689. enumerable: true,
  13690. configurable: true
  13691. });
  13692. Object.defineProperty(UIElement.prototype, "maxHeight", {
  13693. get: function () {
  13694. return this._maxHeight;
  13695. },
  13696. set: function (value) {
  13697. this._maxHeight = value;
  13698. },
  13699. enumerable: true,
  13700. configurable: true
  13701. });
  13702. Object.defineProperty(UIElement.prototype, "actualWidth", {
  13703. get: function () {
  13704. return this._actualWidth;
  13705. },
  13706. set: function (value) {
  13707. this._actualWidth = value;
  13708. },
  13709. enumerable: true,
  13710. configurable: true
  13711. });
  13712. Object.defineProperty(UIElement.prototype, "actualHeight", {
  13713. get: function () {
  13714. return this._actualHeight;
  13715. },
  13716. set: function (value) {
  13717. this._actualHeight = value;
  13718. },
  13719. enumerable: true,
  13720. configurable: true
  13721. });
  13722. Object.defineProperty(UIElement.prototype, "margin", {
  13723. get: function () {
  13724. var _this = this;
  13725. if (!this._margin) {
  13726. this._margin = new BABYLON.PrimitiveThickness(function () {
  13727. if (!_this.parent) {
  13728. return null;
  13729. }
  13730. return _this.parent.margin;
  13731. });
  13732. }
  13733. return this._margin;
  13734. },
  13735. set: function (value) {
  13736. this.margin.copyFrom(value);
  13737. },
  13738. enumerable: true,
  13739. configurable: true
  13740. });
  13741. Object.defineProperty(UIElement.prototype, "_hasMargin", {
  13742. get: function () {
  13743. return (this._margin !== null && !this._margin.isDefault) || (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  13744. },
  13745. enumerable: true,
  13746. configurable: true
  13747. });
  13748. Object.defineProperty(UIElement.prototype, "padding", {
  13749. get: function () {
  13750. var _this = this;
  13751. if (!this._padding) {
  13752. this._padding = new BABYLON.PrimitiveThickness(function () {
  13753. if (!_this.parent) {
  13754. return null;
  13755. }
  13756. return _this.parent.padding;
  13757. });
  13758. }
  13759. return this._padding;
  13760. },
  13761. set: function (value) {
  13762. this.padding.copyFrom(value);
  13763. },
  13764. enumerable: true,
  13765. configurable: true
  13766. });
  13767. Object.defineProperty(UIElement.prototype, "_hasPadding", {
  13768. get: function () {
  13769. return this._padding !== null && !this._padding.isDefault;
  13770. },
  13771. enumerable: true,
  13772. configurable: true
  13773. });
  13774. Object.defineProperty(UIElement.prototype, "marginAlignment", {
  13775. get: function () {
  13776. if (!this._marginAlignment) {
  13777. this._marginAlignment = new BABYLON.PrimitiveAlignment();
  13778. }
  13779. return this._marginAlignment;
  13780. },
  13781. set: function (value) {
  13782. this.marginAlignment.copyFrom(value);
  13783. },
  13784. enumerable: true,
  13785. configurable: true
  13786. });
  13787. Object.defineProperty(UIElement.prototype, "_hasMarginAlignment", {
  13788. /**
  13789. * Check if there a marginAlignment specified (non null and not default)
  13790. */
  13791. get: function () {
  13792. return (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  13793. },
  13794. enumerable: true,
  13795. configurable: true
  13796. });
  13797. Object.defineProperty(UIElement.prototype, "paddingAlignment", {
  13798. get: function () {
  13799. if (!this._paddingAlignment) {
  13800. this._paddingAlignment = new BABYLON.PrimitiveAlignment();
  13801. }
  13802. return this._paddingAlignment;
  13803. },
  13804. set: function (value) {
  13805. this.paddingAlignment.copyFrom(value);
  13806. },
  13807. enumerable: true,
  13808. configurable: true
  13809. });
  13810. Object.defineProperty(UIElement.prototype, "_hasPaddingAlignment", {
  13811. /**
  13812. * Check if there a marginAlignment specified (non null and not default)
  13813. */
  13814. get: function () {
  13815. return (this._paddingAlignment !== null && !this._paddingAlignment.isDefault);
  13816. },
  13817. enumerable: true,
  13818. configurable: true
  13819. });
  13820. Object.defineProperty(UIElement.prototype, "isVisible", {
  13821. get: function () {
  13822. return this._isFlagSet(UIElement.flagIsVisible);
  13823. },
  13824. set: function (value) {
  13825. if (this.isVisible === value) {
  13826. return;
  13827. }
  13828. this._visualPlaceholder.levelVisible = value;
  13829. this._changeFlags(UIElement.flagIsVisible, value);
  13830. },
  13831. enumerable: true,
  13832. configurable: true
  13833. });
  13834. Object.defineProperty(UIElement.prototype, "isEnabled", {
  13835. get: function () {
  13836. return this._isFlagSet(UIElement.flagIsEnabled);
  13837. },
  13838. set: function (value) {
  13839. this._changeFlags(UIElement.flagIsEnabled, value);
  13840. },
  13841. enumerable: true,
  13842. configurable: true
  13843. });
  13844. Object.defineProperty(UIElement.prototype, "isFocused", {
  13845. get: function () {
  13846. return this._isFlagSet(UIElement.flagIsFocus);
  13847. },
  13848. set: function (value) {
  13849. // If the UIElement doesn't accept focus, set it on its parent
  13850. if (!this.isFocusable) {
  13851. var p = this.parent;
  13852. if (!p) {
  13853. return;
  13854. }
  13855. p.isFocused = value;
  13856. }
  13857. // If the focus is being set, notify the Focus Manager
  13858. if (value) {
  13859. this.ownerWindow.focusManager.setFocusOn(this, this.getFocusScope());
  13860. }
  13861. this._changeFlags(UIElement.flagIsFocus, value);
  13862. },
  13863. enumerable: true,
  13864. configurable: true
  13865. });
  13866. Object.defineProperty(UIElement.prototype, "isMouseOver", {
  13867. get: function () {
  13868. return this._isFlagSet(UIElement.flagIsMouseOver);
  13869. },
  13870. set: function (value) {
  13871. this._changeFlags(UIElement.flagIsMouseOver, value);
  13872. },
  13873. enumerable: true,
  13874. configurable: true
  13875. });
  13876. Object.defineProperty(UIElement.prototype, "isFocusScope", {
  13877. get: function () {
  13878. return this._isFlagSet(UIElement.flagIsFocusScope);
  13879. },
  13880. set: function (value) {
  13881. this._changeFlags(UIElement.flagIsFocusScope, value);
  13882. },
  13883. enumerable: true,
  13884. configurable: true
  13885. });
  13886. Object.defineProperty(UIElement.prototype, "isFocusable", {
  13887. get: function () {
  13888. return this._isFlagSet(UIElement.flagIsFocusable);
  13889. },
  13890. set: function (value) {
  13891. this._changeFlags(UIElement.flagIsFocusable, value);
  13892. },
  13893. enumerable: true,
  13894. configurable: true
  13895. });
  13896. // 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)
  13897. UIElement.prototype.getFocusScope = function () {
  13898. if (this.isFocusScope) {
  13899. return this;
  13900. }
  13901. var p = this.parent;
  13902. if (!p) {
  13903. return null;
  13904. }
  13905. return p.getFocusScope();
  13906. };
  13907. /**
  13908. * Check if a given flag is set
  13909. * @param flag the flag value
  13910. * @return true if set, false otherwise
  13911. */
  13912. UIElement.prototype._isFlagSet = function (flag) {
  13913. return (this._flags & flag) !== 0;
  13914. };
  13915. /**
  13916. * Check if all given flags are set
  13917. * @param flags the flags ORed
  13918. * @return true if all the flags are set, false otherwise
  13919. */
  13920. UIElement.prototype._areAllFlagsSet = function (flags) {
  13921. return (this._flags & flags) === flags;
  13922. };
  13923. /**
  13924. * Check if at least one flag of the given flags is set
  13925. * @param flags the flags ORed
  13926. * @return true if at least one flag is set, false otherwise
  13927. */
  13928. UIElement.prototype._areSomeFlagsSet = function (flags) {
  13929. return (this._flags & flags) !== 0;
  13930. };
  13931. /**
  13932. * Clear the given flags
  13933. * @param flags the flags to clear
  13934. */
  13935. UIElement.prototype._clearFlags = function (flags) {
  13936. this._flags &= ~flags;
  13937. };
  13938. /**
  13939. * Set the given flags to true state
  13940. * @param flags the flags ORed to set
  13941. * @return the flags state before this call
  13942. */
  13943. UIElement.prototype._setFlags = function (flags) {
  13944. var cur = this._flags;
  13945. this._flags |= flags;
  13946. return cur;
  13947. };
  13948. /**
  13949. * Change the state of the given flags
  13950. * @param flags the flags ORed to change
  13951. * @param state true to set them, false to clear them
  13952. */
  13953. UIElement.prototype._changeFlags = function (flags, state) {
  13954. if (state) {
  13955. this._flags |= flags;
  13956. }
  13957. else {
  13958. this._flags &= ~flags;
  13959. }
  13960. };
  13961. UIElement.prototype._assignTemplate = function (templateName) {
  13962. if (!templateName) {
  13963. templateName = GUIManager.DefaultTemplateName;
  13964. }
  13965. var className = BABYLON.Tools.getFullClassName(this);
  13966. if (!className) {
  13967. throw Error("Couldn't access class name of this UIElement, you have to decorate the type with the className decorator");
  13968. }
  13969. var factory = GUIManager.getRenderingTemplate(className, templateName);
  13970. if (!factory) {
  13971. throw Error("Couldn't get the renderingTemplate " + templateName + " of class " + className);
  13972. }
  13973. this._renderingTemplateName = templateName;
  13974. this._renderingTemplate = factory();
  13975. this._renderingTemplate.attach(this);
  13976. };
  13977. UIElement.prototype._createVisualTree = function () {
  13978. var parentPrim = this.ownerWindow.canvas;
  13979. if (this.parent) {
  13980. parentPrim = this.parent.visualChildrenPlaceholder;
  13981. }
  13982. if (!this._renderingTemplate) {
  13983. this._assignTemplate(this._renderingTemplateName);
  13984. }
  13985. this._visualPlaceholder = new BABYLON.Group2D({ parent: parentPrim, id: "GUI " + BABYLON.Tools.getClassName(this) + " RootGroup of " + this.id });
  13986. var p = this._visualPlaceholder;
  13987. p.addExternalData("_GUIOwnerElement_", this);
  13988. p.dataSource = this;
  13989. p.createSimpleDataBinding(BABYLON.Prim2DBase.widthProperty, "width", BABYLON.DataBinding.MODE_ONEWAY);
  13990. p.createSimpleDataBinding(BABYLON.Prim2DBase.heightProperty, "height", BABYLON.DataBinding.MODE_ONEWAY);
  13991. p.createSimpleDataBinding(BABYLON.Prim2DBase.actualWidthProperty, "actualWidth", BABYLON.DataBinding.MODE_ONEWAYTOSOURCE);
  13992. p.createSimpleDataBinding(BABYLON.Prim2DBase.actualHeightProperty, "actualHeight", BABYLON.DataBinding.MODE_ONEWAYTOSOURCE);
  13993. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginProperty, "margin", BABYLON.DataBinding.MODE_ONEWAY);
  13994. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginAlignmentProperty, "marginAlignment", BABYLON.DataBinding.MODE_ONEWAY);
  13995. this.createVisualTree();
  13996. };
  13997. UIElement.prototype._patchUIElement = function (ownerWindow, parent) {
  13998. if (ownerWindow) {
  13999. if (!this._ownerWindow) {
  14000. ownerWindow._registerVisualToBuild(this);
  14001. }
  14002. this._ownerWindow = ownerWindow;
  14003. }
  14004. this._parent = parent;
  14005. if (parent) {
  14006. this._hierarchyDepth = parent.hierarchyDepth + 1;
  14007. }
  14008. var children = this._getChildren();
  14009. if (children) {
  14010. for (var _i = 0, children_2 = children; _i < children_2.length; _i++) {
  14011. var curChild = children_2[_i];
  14012. curChild._patchUIElement(ownerWindow, this);
  14013. }
  14014. }
  14015. };
  14016. // 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.
  14017. UIElement.prototype._getDataSource = function () {
  14018. var levelDS = _super.prototype._getDataSource.call(this);
  14019. if (levelDS != null) {
  14020. return levelDS;
  14021. }
  14022. var p = this.parent;
  14023. if (p != null) {
  14024. return p.dataSource;
  14025. }
  14026. return null;
  14027. };
  14028. UIElement.prototype.createVisualTree = function () {
  14029. var res = this._renderingTemplate.createVisualTree(this, this._visualPlaceholder);
  14030. this._visualTemplateRoot = res.root;
  14031. this._visualChildrenPlaceholder = res.contentPlaceholder;
  14032. };
  14033. Object.defineProperty(UIElement.prototype, "visualPlaceholder", {
  14034. get: function () {
  14035. return this._visualPlaceholder;
  14036. },
  14037. enumerable: true,
  14038. configurable: true
  14039. });
  14040. Object.defineProperty(UIElement.prototype, "visualTemplateRoot", {
  14041. get: function () {
  14042. return this._visualTemplateRoot;
  14043. },
  14044. enumerable: true,
  14045. configurable: true
  14046. });
  14047. Object.defineProperty(UIElement.prototype, "visualChildrenPlaceholder", {
  14048. get: function () {
  14049. return this._visualChildrenPlaceholder;
  14050. },
  14051. enumerable: true,
  14052. configurable: true
  14053. });
  14054. Object.defineProperty(UIElement.prototype, "_position", {
  14055. get: function () { return null; } // TODO use abstract keyword when TS 2.0 will be approved
  14056. ,
  14057. enumerable: true,
  14058. configurable: true
  14059. });
  14060. UIElement.UIELEMENT_PROPCOUNT = 16;
  14061. UIElement.flagVisualToBuild = 0x0000001;
  14062. UIElement.flagIsVisible = 0x0000002;
  14063. UIElement.flagIsFocus = 0x0000004;
  14064. UIElement.flagIsFocusScope = 0x0000008;
  14065. UIElement.flagIsFocusable = 0x0000010;
  14066. UIElement.flagIsEnabled = 0x0000020;
  14067. UIElement.flagIsMouseOver = 0x0000040;
  14068. UIElement._enableState = "Enabled";
  14069. UIElement._disabledState = "Disabled";
  14070. UIElement._mouseOverState = "MouseOver";
  14071. __decorate([
  14072. BABYLON.dependencyProperty(0, function (pi) { return UIElement.parentProperty = pi; })
  14073. ], UIElement.prototype, "parent", null);
  14074. __decorate([
  14075. BABYLON.dependencyProperty(1, function (pi) { return UIElement.widthProperty = pi; })
  14076. ], UIElement.prototype, "width", null);
  14077. __decorate([
  14078. BABYLON.dependencyProperty(2, function (pi) { return UIElement.heightProperty = pi; })
  14079. ], UIElement.prototype, "height", null);
  14080. __decorate([
  14081. BABYLON.dependencyProperty(3, function (pi) { return UIElement.minWidthProperty = pi; })
  14082. ], UIElement.prototype, "minWidth", null);
  14083. __decorate([
  14084. BABYLON.dependencyProperty(4, function (pi) { return UIElement.minHeightProperty = pi; })
  14085. ], UIElement.prototype, "minHheight", null);
  14086. __decorate([
  14087. BABYLON.dependencyProperty(5, function (pi) { return UIElement.maxWidthProperty = pi; })
  14088. ], UIElement.prototype, "maxWidth", null);
  14089. __decorate([
  14090. BABYLON.dependencyProperty(6, function (pi) { return UIElement.maxHeightProperty = pi; })
  14091. ], UIElement.prototype, "maxHeight", null);
  14092. __decorate([
  14093. BABYLON.dependencyProperty(7, function (pi) { return UIElement.actualWidthProperty = pi; })
  14094. ], UIElement.prototype, "actualWidth", null);
  14095. __decorate([
  14096. BABYLON.dependencyProperty(8, function (pi) { return UIElement.actualHeightProperty = pi; })
  14097. ], UIElement.prototype, "actualHeight", null);
  14098. __decorate([
  14099. BABYLON.dynamicLevelProperty(9, function (pi) { return UIElement.marginProperty = pi; })
  14100. ], UIElement.prototype, "margin", null);
  14101. __decorate([
  14102. BABYLON.dynamicLevelProperty(10, function (pi) { return UIElement.paddingProperty = pi; })
  14103. ], UIElement.prototype, "padding", null);
  14104. __decorate([
  14105. BABYLON.dynamicLevelProperty(11, function (pi) { return UIElement.marginAlignmentProperty = pi; })
  14106. ], UIElement.prototype, "marginAlignment", null);
  14107. __decorate([
  14108. BABYLON.dynamicLevelProperty(12, function (pi) { return UIElement.paddingAlignmentProperty = pi; })
  14109. ], UIElement.prototype, "paddingAlignment", null);
  14110. __decorate([
  14111. BABYLON.dynamicLevelProperty(13, function (pi) { return UIElement.isEnabledProperty = pi; })
  14112. ], UIElement.prototype, "isEnabled", null);
  14113. __decorate([
  14114. BABYLON.dynamicLevelProperty(14, function (pi) { return UIElement.isFocusedProperty = pi; })
  14115. ], UIElement.prototype, "isFocused", null);
  14116. __decorate([
  14117. BABYLON.dynamicLevelProperty(15, function (pi) { return UIElement.isMouseOverProperty = pi; })
  14118. ], UIElement.prototype, "isMouseOver", null);
  14119. return UIElement;
  14120. }(BABYLON.SmartPropertyBase));
  14121. BABYLON.UIElement = UIElement;
  14122. var UIElementStyle = (function () {
  14123. function UIElementStyle() {
  14124. }
  14125. Object.defineProperty(UIElementStyle.prototype, "name", {
  14126. get: function () { return null; } // TODO use abstract keyword when TS 2.0 will be approved
  14127. ,
  14128. enumerable: true,
  14129. configurable: true
  14130. });
  14131. return UIElementStyle;
  14132. }());
  14133. BABYLON.UIElementStyle = UIElementStyle;
  14134. var GUIManager = (function () {
  14135. function GUIManager() {
  14136. }
  14137. /////////////////////////////////////////////////////////////////////////////////////////////////////
  14138. // DATA TEMPLATE MANAGER
  14139. GUIManager.registerDataTemplate = function (className, factory) {
  14140. };
  14141. // DATA TEMPLATE MANAGER
  14142. /////////////////////////////////////////////////////////////////////////////////////////////////////
  14143. /////////////////////////////////////////////////////////////////////////////////////////////////////
  14144. // STYLE MANAGER
  14145. GUIManager.getStyle = function (uiElType, styleName) {
  14146. var styles = GUIManager.stylesByUIElement.get(uiElType);
  14147. if (!styles) {
  14148. throw Error("The type " + uiElType + " is unknown, no style were registered for it.");
  14149. }
  14150. var style = styles.get(styleName);
  14151. if (!style) {
  14152. throw Error("Couldn't find Template " + styleName + " of UIElement type " + uiElType);
  14153. }
  14154. return style;
  14155. };
  14156. GUIManager.registerStyle = function (uiElType, templateName, style) {
  14157. var templates = GUIManager.stylesByUIElement.getOrAddWithFactory(uiElType, function () { return new BABYLON.StringDictionary(); });
  14158. if (templates.contains(templateName)) {
  14159. templates[templateName] = style;
  14160. }
  14161. else {
  14162. templates.add(templateName, style);
  14163. }
  14164. };
  14165. Object.defineProperty(GUIManager, "DefaultStyleName", {
  14166. get: function () {
  14167. return GUIManager._defaultStyleName;
  14168. },
  14169. set: function (value) {
  14170. GUIManager._defaultStyleName = value;
  14171. },
  14172. enumerable: true,
  14173. configurable: true
  14174. });
  14175. // STYLE MANAGER
  14176. /////////////////////////////////////////////////////////////////////////////////////////////////////
  14177. /////////////////////////////////////////////////////////////////////////////////////////////////////
  14178. // RENDERING TEMPLATE MANAGER
  14179. GUIManager.getRenderingTemplate = function (uiElType, templateName) {
  14180. var templates = GUIManager.renderingTemplatesByUIElement.get(uiElType);
  14181. if (!templates) {
  14182. throw Error("The type " + uiElType + " is unknown, no Rendering Template were registered for it.");
  14183. }
  14184. var templateFactory = templates.get(templateName);
  14185. if (!templateFactory) {
  14186. throw Error("Couldn't find Template " + templateName + " of UI Element type " + uiElType);
  14187. }
  14188. return templateFactory;
  14189. };
  14190. GUIManager.registerRenderingTemplate = function (uiElType, templateName, factory) {
  14191. var templates = GUIManager.renderingTemplatesByUIElement.getOrAddWithFactory(uiElType, function () { return new BABYLON.StringDictionary(); });
  14192. if (templates.contains(templateName)) {
  14193. templates[templateName] = factory;
  14194. }
  14195. else {
  14196. templates.add(templateName, factory);
  14197. }
  14198. };
  14199. Object.defineProperty(GUIManager, "DefaultTemplateName", {
  14200. get: function () {
  14201. return GUIManager._defaultTemplateName;
  14202. },
  14203. set: function (value) {
  14204. GUIManager._defaultTemplateName = value;
  14205. },
  14206. enumerable: true,
  14207. configurable: true
  14208. });
  14209. GUIManager.stylesByUIElement = new BABYLON.StringDictionary();
  14210. GUIManager.renderingTemplatesByUIElement = new BABYLON.StringDictionary();
  14211. // RENDERING TEMPLATE MANAGER
  14212. /////////////////////////////////////////////////////////////////////////////////////////////////////
  14213. GUIManager._defaultTemplateName = "Default";
  14214. GUIManager._defaultStyleName = "Default";
  14215. return GUIManager;
  14216. }());
  14217. BABYLON.GUIManager = GUIManager;
  14218. var UIElementRenderingTemplateBase = (function () {
  14219. function UIElementRenderingTemplateBase() {
  14220. }
  14221. UIElementRenderingTemplateBase.prototype.attach = function (owner) {
  14222. this._owner = owner;
  14223. };
  14224. UIElementRenderingTemplateBase.prototype.detach = function () {
  14225. };
  14226. Object.defineProperty(UIElementRenderingTemplateBase.prototype, "owner", {
  14227. get: function () {
  14228. return this._owner;
  14229. },
  14230. enumerable: true,
  14231. configurable: true
  14232. });
  14233. return UIElementRenderingTemplateBase;
  14234. }());
  14235. BABYLON.UIElementRenderingTemplateBase = UIElementRenderingTemplateBase;
  14236. function registerWindowRenderingTemplate(uiElType, templateName, factory) {
  14237. return function () {
  14238. GUIManager.registerRenderingTemplate(uiElType, templateName, factory);
  14239. };
  14240. }
  14241. BABYLON.registerWindowRenderingTemplate = registerWindowRenderingTemplate;
  14242. })(BABYLON || (BABYLON = {}));
  14243. //# sourceMappingURL=babylon.gui.UIElement.js.map
  14244. var __extends = (this && this.__extends) || function (d, b) {
  14245. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14246. function __() { this.constructor = d; }
  14247. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14248. };
  14249. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14250. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14251. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14252. 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;
  14253. return c > 3 && r && Object.defineProperty(target, key, r), r;
  14254. };
  14255. var BABYLON;
  14256. (function (BABYLON) {
  14257. var StackPanel = (function (_super) {
  14258. __extends(StackPanel, _super);
  14259. function StackPanel(settings) {
  14260. if (!settings) {
  14261. settings = {};
  14262. }
  14263. _super.call(this, settings);
  14264. this.isOrientationHorizontal = (settings.isOrientationHorizontal == null) ? true : settings.isOrientationHorizontal;
  14265. this._children = new Array();
  14266. if (settings.children != null) {
  14267. for (var _i = 0, _a = settings.children; _i < _a.length; _i++) {
  14268. var child = _a[_i];
  14269. this._children.push(child);
  14270. }
  14271. }
  14272. }
  14273. Object.defineProperty(StackPanel.prototype, "isOrientationHorizontal", {
  14274. get: function () {
  14275. return this._isOrientationHorizontal;
  14276. },
  14277. set: function (value) {
  14278. this._isOrientationHorizontal = value;
  14279. },
  14280. enumerable: true,
  14281. configurable: true
  14282. });
  14283. StackPanel.prototype.createVisualTree = function () {
  14284. _super.prototype.createVisualTree.call(this);
  14285. // A StackPanel Control has a Group2D, child of the visualPlaceHolder, which is the Children placeholder.
  14286. // The Children UIElement Tree will be create inside this placeholder.
  14287. this._childrenPlaceholder = new BABYLON.Group2D({ parent: this._visualPlaceholder, id: "StackPanel Children Placeholder of " + this.id });
  14288. var p = this._childrenPlaceholder;
  14289. p.layoutEngine = this.isOrientationHorizontal ? BABYLON.StackPanelLayoutEngine.Horizontal : BABYLON.StackPanelLayoutEngine.Vertical;
  14290. // 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.
  14291. p.dataSource = this;
  14292. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginProperty, "padding", BABYLON.DataBinding.MODE_ONEWAY);
  14293. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginAlignmentProperty, "paddingAlignment", BABYLON.DataBinding.MODE_ONEWAY);
  14294. // The UIElement set the childrenPlaceholder with the visual returned by the renderingTemplate.
  14295. // But it's not the case for a StackPanel, the placeholder of UIElement Children (the content)
  14296. this._visualChildrenPlaceholder = this._childrenPlaceholder;
  14297. };
  14298. Object.defineProperty(StackPanel.prototype, "children", {
  14299. get: function () {
  14300. return this._children;
  14301. },
  14302. enumerable: true,
  14303. configurable: true
  14304. });
  14305. StackPanel.prototype._getChildren = function () {
  14306. return this.children;
  14307. };
  14308. StackPanel.STACKPANEL_PROPCOUNT = BABYLON.UIElement.UIELEMENT_PROPCOUNT + 3;
  14309. __decorate([
  14310. BABYLON.dependencyProperty(StackPanel.STACKPANEL_PROPCOUNT + 0, function (pi) { return StackPanel.orientationHorizontalProperty = pi; })
  14311. ], StackPanel.prototype, "isOrientationHorizontal", null);
  14312. StackPanel = __decorate([
  14313. BABYLON.className("StackPanel", "BABYLON")
  14314. ], StackPanel);
  14315. return StackPanel;
  14316. }(BABYLON.UIElement));
  14317. BABYLON.StackPanel = StackPanel;
  14318. var DefaultStackPanelRenderingTemplate = (function (_super) {
  14319. __extends(DefaultStackPanelRenderingTemplate, _super);
  14320. function DefaultStackPanelRenderingTemplate() {
  14321. _super.apply(this, arguments);
  14322. }
  14323. DefaultStackPanelRenderingTemplate.prototype.createVisualTree = function (owner, visualPlaceholder) {
  14324. return { root: visualPlaceholder, contentPlaceholder: visualPlaceholder };
  14325. };
  14326. DefaultStackPanelRenderingTemplate.prototype.attach = function (owner) {
  14327. _super.prototype.attach.call(this, owner);
  14328. };
  14329. DefaultStackPanelRenderingTemplate = __decorate([
  14330. BABYLON.registerWindowRenderingTemplate("BABYLON.StackPanel", "Default", function () { return new DefaultStackPanelRenderingTemplate(); })
  14331. ], DefaultStackPanelRenderingTemplate);
  14332. return DefaultStackPanelRenderingTemplate;
  14333. }(BABYLON.UIElementRenderingTemplateBase));
  14334. BABYLON.DefaultStackPanelRenderingTemplate = DefaultStackPanelRenderingTemplate;
  14335. })(BABYLON || (BABYLON = {}));
  14336. //# sourceMappingURL=babylon.gui.stackPanel.js.map
  14337. var __extends = (this && this.__extends) || function (d, b) {
  14338. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14339. function __() { this.constructor = d; }
  14340. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14341. };
  14342. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14343. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14344. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14345. 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;
  14346. return c > 3 && r && Object.defineProperty(target, key, r), r;
  14347. };
  14348. var BABYLON;
  14349. (function (BABYLON) {
  14350. var Control = (function (_super) {
  14351. __extends(Control, _super);
  14352. function Control(settings) {
  14353. _super.call(this, settings);
  14354. }
  14355. Object.defineProperty(Control.prototype, "background", {
  14356. get: function () {
  14357. if (!this._background) {
  14358. this._background = new BABYLON.ObservableStringDictionary(false);
  14359. }
  14360. return this._background;
  14361. },
  14362. set: function (value) {
  14363. this.background.copyFrom(value);
  14364. },
  14365. enumerable: true,
  14366. configurable: true
  14367. });
  14368. Object.defineProperty(Control.prototype, "border", {
  14369. get: function () {
  14370. return this._border;
  14371. },
  14372. set: function (value) {
  14373. this._border = value;
  14374. },
  14375. enumerable: true,
  14376. configurable: true
  14377. });
  14378. Object.defineProperty(Control.prototype, "borderThickness", {
  14379. get: function () {
  14380. return this._borderThickness;
  14381. },
  14382. set: function (value) {
  14383. this._borderThickness = value;
  14384. },
  14385. enumerable: true,
  14386. configurable: true
  14387. });
  14388. Object.defineProperty(Control.prototype, "fontName", {
  14389. get: function () {
  14390. return this._fontName;
  14391. },
  14392. set: function (value) {
  14393. this._fontName = value;
  14394. },
  14395. enumerable: true,
  14396. configurable: true
  14397. });
  14398. Object.defineProperty(Control.prototype, "foreground", {
  14399. get: function () {
  14400. return this._foreground;
  14401. },
  14402. set: function (value) {
  14403. this._foreground = value;
  14404. },
  14405. enumerable: true,
  14406. configurable: true
  14407. });
  14408. Control.CONTROL_PROPCOUNT = BABYLON.UIElement.UIELEMENT_PROPCOUNT + 5;
  14409. __decorate([
  14410. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 0, function (pi) { return Control.backgroundProperty = pi; })
  14411. ], Control.prototype, "background", null);
  14412. __decorate([
  14413. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 1, function (pi) { return Control.borderProperty = pi; })
  14414. ], Control.prototype, "border", null);
  14415. __decorate([
  14416. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 2, function (pi) { return Control.borderThicknessProperty = pi; })
  14417. ], Control.prototype, "borderThickness", null);
  14418. __decorate([
  14419. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 3, function (pi) { return Control.fontNameProperty = pi; })
  14420. ], Control.prototype, "fontName", null);
  14421. __decorate([
  14422. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 4, function (pi) { return Control.foregroundProperty = pi; })
  14423. ], Control.prototype, "foreground", null);
  14424. Control = __decorate([
  14425. BABYLON.className("Control", "BABYLON")
  14426. ], Control);
  14427. return Control;
  14428. }(BABYLON.UIElement));
  14429. BABYLON.Control = Control;
  14430. })(BABYLON || (BABYLON = {}));
  14431. //# sourceMappingURL=babylon.gui.control.js.map
  14432. var __extends = (this && this.__extends) || function (d, b) {
  14433. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14434. function __() { this.constructor = d; }
  14435. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14436. };
  14437. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14438. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14439. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14440. 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;
  14441. return c > 3 && r && Object.defineProperty(target, key, r), r;
  14442. };
  14443. var BABYLON;
  14444. (function (BABYLON) {
  14445. var ContentControl = (function (_super) {
  14446. __extends(ContentControl, _super);
  14447. function ContentControl(settings) {
  14448. if (!settings) {
  14449. settings = {};
  14450. }
  14451. _super.call(this, settings);
  14452. if (settings.content != null) {
  14453. this._content = settings.content;
  14454. }
  14455. }
  14456. ContentControl.prototype.dispose = function () {
  14457. if (this.isDisposed) {
  14458. return false;
  14459. }
  14460. if (this.content && this.content.dispose) {
  14461. this.content.dispose();
  14462. this.content = null;
  14463. }
  14464. if (this.__contentUIElement) {
  14465. this.__contentUIElement.dispose();
  14466. this.__contentUIElement = null;
  14467. }
  14468. _super.prototype.dispose.call(this);
  14469. return true;
  14470. };
  14471. Object.defineProperty(ContentControl.prototype, "content", {
  14472. get: function () {
  14473. return this._content;
  14474. },
  14475. set: function (value) {
  14476. this._content = value;
  14477. },
  14478. enumerable: true,
  14479. configurable: true
  14480. });
  14481. Object.defineProperty(ContentControl.prototype, "_contentUIElement", {
  14482. get: function () {
  14483. if (!this.__contentUIElement) {
  14484. this._buildContentUIElement();
  14485. }
  14486. return this.__contentUIElement;
  14487. },
  14488. enumerable: true,
  14489. configurable: true
  14490. });
  14491. ContentControl.prototype._createVisualTree = function () {
  14492. // Base implementation will create the Group2D for the Visual Placeholder and its Visual Tree
  14493. _super.prototype._createVisualTree.call(this);
  14494. // A Content Control has a Group2D, child of the visualPlaceHolder, which is the Content placeholder.
  14495. // The Content UIElement Tree will be create inside this placeholder.
  14496. this._contentPlaceholder = new BABYLON.Group2D({ parent: this._visualPlaceholder, id: "ContentControl Content Placeholder of " + this.id });
  14497. var p = this._contentPlaceholder;
  14498. // 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.
  14499. p.dataSource = this;
  14500. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginProperty, "padding", BABYLON.DataBinding.MODE_ONEWAY);
  14501. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginAlignmentProperty, "paddingAlignment", BABYLON.DataBinding.MODE_ONEWAY);
  14502. // The UIElement set the childrenPlaceholder with the visual returned by the renderingTemplate.
  14503. // But it's not the case for a ContentControl, the placeholder of UIElement Children (the content)
  14504. this._visualChildrenPlaceholder = this._contentPlaceholder;
  14505. };
  14506. ContentControl.prototype._buildContentUIElement = function () {
  14507. var c = this._content;
  14508. this.__contentUIElement = null;
  14509. // Already a UIElement
  14510. if (c instanceof BABYLON.UIElement) {
  14511. this.__contentUIElement = c;
  14512. }
  14513. else if ((typeof c === "string") || (typeof c === "boolean") || (typeof c === "number")) {
  14514. var l = new BABYLON.Label({ parent: this, id: "Content of " + this.id });
  14515. var binding = new BABYLON.DataBinding();
  14516. binding.propertyPathName = "content";
  14517. binding.stringFormat = function (v) { return ("" + v); };
  14518. binding.dataSource = this;
  14519. l.createDataBinding(BABYLON.Label.textProperty, binding);
  14520. this.__contentUIElement = l;
  14521. }
  14522. else {
  14523. }
  14524. if (this.__contentUIElement) {
  14525. this.__contentUIElement._patchUIElement(this.ownerWindow, this);
  14526. }
  14527. };
  14528. ContentControl.prototype._getChildren = function () {
  14529. var children = new Array();
  14530. if (this.content) {
  14531. children.push(this._contentUIElement);
  14532. }
  14533. return children;
  14534. };
  14535. ContentControl.CONTENTCONTROL_PROPCOUNT = BABYLON.Control.CONTROL_PROPCOUNT + 2;
  14536. __decorate([
  14537. BABYLON.dependencyProperty(BABYLON.Control.CONTROL_PROPCOUNT + 0, function (pi) { return ContentControl.contentProperty = pi; })
  14538. ], ContentControl.prototype, "content", null);
  14539. ContentControl = __decorate([
  14540. BABYLON.className("ContentControl", "BABYLON")
  14541. ], ContentControl);
  14542. return ContentControl;
  14543. }(BABYLON.Control));
  14544. BABYLON.ContentControl = ContentControl;
  14545. })(BABYLON || (BABYLON = {}));
  14546. //# sourceMappingURL=babylon.gui.contentControl.js.map
  14547. var __extends = (this && this.__extends) || function (d, b) {
  14548. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14549. function __() { this.constructor = d; }
  14550. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14551. };
  14552. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14553. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14554. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14555. 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;
  14556. return c > 3 && r && Object.defineProperty(target, key, r), r;
  14557. };
  14558. var BABYLON;
  14559. (function (BABYLON) {
  14560. var FocusScopeData = (function () {
  14561. function FocusScopeData(focusScope) {
  14562. this.focusScope = focusScope;
  14563. this.focusedElement = null;
  14564. }
  14565. return FocusScopeData;
  14566. }());
  14567. var FocusManager = (function () {
  14568. function FocusManager() {
  14569. this._focusScopes = new BABYLON.StringDictionary();
  14570. this._rootScope = new FocusScopeData(null);
  14571. this._activeScope = null;
  14572. }
  14573. FocusManager.prototype.setFocusOn = function (el, focusScope) {
  14574. var fsd = (focusScope != null) ? this._focusScopes.getOrAddWithFactory(focusScope.uid, function (k) { return new FocusScopeData(focusScope); }) : this._rootScope;
  14575. if (fsd.focusedElement !== el) {
  14576. // Remove focus from current
  14577. if (fsd.focusedElement) {
  14578. fsd.focusedElement.isFocused = false;
  14579. }
  14580. fsd.focusedElement = el;
  14581. }
  14582. if (this._activeScope !== fsd) {
  14583. this._activeScope = fsd;
  14584. }
  14585. };
  14586. return FocusManager;
  14587. }());
  14588. BABYLON.FocusManager = FocusManager;
  14589. var GUISceneData = (function () {
  14590. function GUISceneData(scene) {
  14591. this.scene = scene;
  14592. this.screenSpaceCanvas = new BABYLON.ScreenSpaceCanvas2D(scene, { id: "GUI Canvas", cachingStrategy: BABYLON.Canvas2D.CACHESTRATEGY_DONTCACHE });
  14593. this.focusManager = new FocusManager();
  14594. }
  14595. return GUISceneData;
  14596. }());
  14597. var Window = (function (_super) {
  14598. __extends(Window, _super);
  14599. function Window(scene, settings) {
  14600. var _this = this;
  14601. if (!settings) {
  14602. settings = {};
  14603. }
  14604. _super.call(this, settings);
  14605. // Per default a Window is focus scope
  14606. this.isFocusScope = true;
  14607. this.isActive = false;
  14608. if (!this._UIElementVisualToBuildList) {
  14609. this._UIElementVisualToBuildList = new Array();
  14610. }
  14611. // Patch the owner and also the parent property through the whole tree
  14612. this._patchUIElement(this, null);
  14613. // Screen Space UI
  14614. if (!settings.worldPosition && !settings.worldRotation) {
  14615. this._sceneData = Window.getSceneData(scene);
  14616. this._canvas = this._sceneData.screenSpaceCanvas;
  14617. this._isWorldSpaceCanvas = false;
  14618. this._left = (settings.left != null) ? settings.left : 0;
  14619. this._bottom = (settings.bottom != null) ? settings.bottom : 0;
  14620. }
  14621. else {
  14622. var w = (settings.width == null) ? 100 : settings.width;
  14623. var h = (settings.height == null) ? 100 : settings.height;
  14624. var wpos = (settings.worldPosition == null) ? BABYLON.Vector3.Zero() : settings.worldPosition;
  14625. var wrot = (settings.worldRotation == null) ? BABYLON.Quaternion.Identity() : settings.worldRotation;
  14626. this._canvas = new BABYLON.WorldSpaceCanvas2D(scene, new BABYLON.Size(w, h), { id: "GUI Canvas", cachingStrategy: BABYLON.Canvas2D.CACHESTRATEGY_DONTCACHE, worldPosition: wpos, worldRotation: wrot });
  14627. this._isWorldSpaceCanvas = true;
  14628. }
  14629. this._renderObserver = this._canvas.renderObservable.add(function (e, s) { return _this._canvasPreRender(); }, BABYLON.Canvas2D.RENDEROBSERVABLE_PRE);
  14630. this._disposeObserver = this._canvas.disposeObservable.add(function (e, s) { return _this._canvasDisposed(); });
  14631. this._canvas.propertyChanged.add(function (e, s) {
  14632. if (e.propertyName === "overPrim") {
  14633. _this._overPrimChanged(e.oldValue, e.newValue);
  14634. }
  14635. });
  14636. this._mouseOverUIElement = null;
  14637. }
  14638. Object.defineProperty(Window.prototype, "canvas", {
  14639. get: function () {
  14640. return this._canvas;
  14641. },
  14642. enumerable: true,
  14643. configurable: true
  14644. });
  14645. Object.defineProperty(Window.prototype, "left", {
  14646. get: function () {
  14647. return this._left;
  14648. },
  14649. set: function (value) {
  14650. var old = new BABYLON.Vector2(this._left, this._bottom);
  14651. this._left = value;
  14652. this.onPropertyChanged("_position", old, this._position);
  14653. },
  14654. enumerable: true,
  14655. configurable: true
  14656. });
  14657. Object.defineProperty(Window.prototype, "bottom", {
  14658. get: function () {
  14659. return this._bottom;
  14660. },
  14661. set: function (value) {
  14662. var old = new BABYLON.Vector2(this._left, this._bottom);
  14663. this._bottom = value;
  14664. this.onPropertyChanged("_position", old, this._position);
  14665. },
  14666. enumerable: true,
  14667. configurable: true
  14668. });
  14669. Object.defineProperty(Window.prototype, "position", {
  14670. get: function () {
  14671. return this._position;
  14672. },
  14673. set: function (value) {
  14674. this._left = value.x;
  14675. this._bottom = value.y;
  14676. },
  14677. enumerable: true,
  14678. configurable: true
  14679. });
  14680. Object.defineProperty(Window.prototype, "isActive", {
  14681. get: function () {
  14682. return this._isActive;
  14683. },
  14684. set: function (value) {
  14685. this._isActive = value;
  14686. },
  14687. enumerable: true,
  14688. configurable: true
  14689. });
  14690. Object.defineProperty(Window.prototype, "focusManager", {
  14691. get: function () {
  14692. return this._sceneData.focusManager;
  14693. },
  14694. enumerable: true,
  14695. configurable: true
  14696. });
  14697. Object.defineProperty(Window.prototype, "_position", {
  14698. get: function () {
  14699. return new BABYLON.Vector2(this.left, this.bottom);
  14700. },
  14701. enumerable: true,
  14702. configurable: true
  14703. });
  14704. Window.prototype.createVisualTree = function () {
  14705. _super.prototype.createVisualTree.call(this);
  14706. var p = this._visualPlaceholder;
  14707. p.createSimpleDataBinding(BABYLON.Group2D.positionProperty, "position");
  14708. };
  14709. Window.prototype._registerVisualToBuild = function (uiel) {
  14710. if (uiel._isFlagSet(BABYLON.UIElement.flagVisualToBuild)) {
  14711. return;
  14712. }
  14713. if (!this._UIElementVisualToBuildList) {
  14714. this._UIElementVisualToBuildList = new Array();
  14715. }
  14716. this._UIElementVisualToBuildList.push(uiel);
  14717. uiel._setFlags(BABYLON.UIElement.flagVisualToBuild);
  14718. };
  14719. Window.prototype._overPrimChanged = function (oldPrim, newPrim) {
  14720. var curOverEl = this._mouseOverUIElement;
  14721. var newOverEl = null;
  14722. var curGroup = newPrim ? newPrim.traverseUp(function (p) { return p instanceof BABYLON.Group2D; }) : null;
  14723. while (curGroup) {
  14724. var uiel = curGroup.getExternalData("_GUIOwnerElement_");
  14725. if (uiel) {
  14726. newOverEl = uiel;
  14727. break;
  14728. }
  14729. curGroup = curGroup.parent ? curGroup.parent.traverseUp(function (p) { return p instanceof BABYLON.Group2D; }) : null;
  14730. }
  14731. if (curOverEl === newOverEl) {
  14732. return;
  14733. }
  14734. if (curOverEl) {
  14735. curOverEl.isMouseOver = false;
  14736. }
  14737. if (newOverEl) {
  14738. newOverEl.isMouseOver = true;
  14739. }
  14740. this._mouseOverUIElement = newOverEl;
  14741. };
  14742. Window.prototype._canvasPreRender = function () {
  14743. // Check if we have visual to create
  14744. if (this._UIElementVisualToBuildList.length > 0) {
  14745. // Sort the UI Element to get the highest (so lowest hierarchy depth) in the hierarchy tree first
  14746. var sortedElementList = this._UIElementVisualToBuildList.sort(function (a, b) { return a.hierarchyDepth - b.hierarchyDepth; });
  14747. for (var _i = 0, sortedElementList_1 = sortedElementList; _i < sortedElementList_1.length; _i++) {
  14748. var el = sortedElementList_1[_i];
  14749. el._createVisualTree();
  14750. }
  14751. this._UIElementVisualToBuildList.splice(0);
  14752. }
  14753. };
  14754. Window.prototype._canvasDisposed = function () {
  14755. this._canvas.disposeObservable.remove(this._disposeObserver);
  14756. this._canvas.renderObservable.remove(this._renderObserver);
  14757. };
  14758. Window.getSceneData = function (scene) {
  14759. return Window._sceneData.getOrAddWithFactory(scene.uid, function (k) { return new GUISceneData(scene); });
  14760. };
  14761. Window.WINDOW_PROPCOUNT = BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 4;
  14762. Window._sceneData = new BABYLON.StringDictionary();
  14763. __decorate([
  14764. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 0, function (pi) { return Window.leftProperty = pi; })
  14765. ], Window.prototype, "left", null);
  14766. __decorate([
  14767. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 1, function (pi) { return Window.bottomProperty = pi; })
  14768. ], Window.prototype, "bottom", null);
  14769. __decorate([
  14770. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 2, function (pi) { return Window.positionProperty = pi; })
  14771. ], Window.prototype, "position", null);
  14772. __decorate([
  14773. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 3, function (pi) { return Window.isActiveProperty = pi; })
  14774. ], Window.prototype, "isActive", null);
  14775. Window = __decorate([
  14776. BABYLON.className("Window", "BABYLON")
  14777. ], Window);
  14778. return Window;
  14779. }(BABYLON.ContentControl));
  14780. BABYLON.Window = Window;
  14781. var DefaultWindowRenderingTemplate = (function (_super) {
  14782. __extends(DefaultWindowRenderingTemplate, _super);
  14783. function DefaultWindowRenderingTemplate() {
  14784. _super.apply(this, arguments);
  14785. }
  14786. DefaultWindowRenderingTemplate.prototype.createVisualTree = function (owner, visualPlaceholder) {
  14787. var r = new BABYLON.Rectangle2D({ parent: visualPlaceholder, fill: "#808080FF" });
  14788. return { root: r, contentPlaceholder: r };
  14789. };
  14790. DefaultWindowRenderingTemplate = __decorate([
  14791. BABYLON.registerWindowRenderingTemplate("BABYLON.Window", "Default", function () { return new DefaultWindowRenderingTemplate(); })
  14792. ], DefaultWindowRenderingTemplate);
  14793. return DefaultWindowRenderingTemplate;
  14794. }(BABYLON.UIElementRenderingTemplateBase));
  14795. BABYLON.DefaultWindowRenderingTemplate = DefaultWindowRenderingTemplate;
  14796. })(BABYLON || (BABYLON = {}));
  14797. //# sourceMappingURL=babylon.gui.window.js.map
  14798. var __extends = (this && this.__extends) || function (d, b) {
  14799. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14800. function __() { this.constructor = d; }
  14801. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14802. };
  14803. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14804. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14805. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14806. 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;
  14807. return c > 3 && r && Object.defineProperty(target, key, r), r;
  14808. };
  14809. var BABYLON;
  14810. (function (BABYLON) {
  14811. var Label = (function (_super) {
  14812. __extends(Label, _super);
  14813. function Label(settings) {
  14814. if (!settings) {
  14815. settings = {};
  14816. }
  14817. _super.call(this, settings);
  14818. if (settings.text != null) {
  14819. this.text = settings.text;
  14820. }
  14821. }
  14822. Object.defineProperty(Label.prototype, "_position", {
  14823. get: function () {
  14824. return BABYLON.Vector2.Zero();
  14825. },
  14826. enumerable: true,
  14827. configurable: true
  14828. });
  14829. Label.prototype._getChildren = function () {
  14830. return Label._emptyArray;
  14831. };
  14832. Label.prototype.createVisualTree = function () {
  14833. _super.prototype.createVisualTree.call(this);
  14834. var p = this._visualChildrenPlaceholder;
  14835. };
  14836. Object.defineProperty(Label.prototype, "text", {
  14837. get: function () {
  14838. return this._text;
  14839. },
  14840. set: function (value) {
  14841. this._text = value;
  14842. },
  14843. enumerable: true,
  14844. configurable: true
  14845. });
  14846. Label._emptyArray = new Array();
  14847. __decorate([
  14848. BABYLON.dependencyProperty(BABYLON.Control.CONTROL_PROPCOUNT + 0, function (pi) { return Label.textProperty = pi; })
  14849. ], Label.prototype, "text", null);
  14850. Label = __decorate([
  14851. BABYLON.className("Label", "BABYLON")
  14852. ], Label);
  14853. return Label;
  14854. }(BABYLON.Control));
  14855. BABYLON.Label = Label;
  14856. var DefaultLabelRenderingTemplate = (function (_super) {
  14857. __extends(DefaultLabelRenderingTemplate, _super);
  14858. function DefaultLabelRenderingTemplate() {
  14859. _super.apply(this, arguments);
  14860. }
  14861. DefaultLabelRenderingTemplate.prototype.createVisualTree = function (owner, visualPlaceholder) {
  14862. var r = new BABYLON.Text2D("", { parent: visualPlaceholder });
  14863. r.createSimpleDataBinding(BABYLON.Text2D.textProperty, "text");
  14864. r.dataSource = owner;
  14865. return { root: r, contentPlaceholder: r };
  14866. };
  14867. DefaultLabelRenderingTemplate = __decorate([
  14868. BABYLON.registerWindowRenderingTemplate("BABYLON.Label", "Default", function () { return new DefaultLabelRenderingTemplate(); })
  14869. ], DefaultLabelRenderingTemplate);
  14870. return DefaultLabelRenderingTemplate;
  14871. }(BABYLON.UIElementRenderingTemplateBase));
  14872. BABYLON.DefaultLabelRenderingTemplate = DefaultLabelRenderingTemplate;
  14873. })(BABYLON || (BABYLON = {}));
  14874. //# sourceMappingURL=babylon.gui.label.js.map
  14875. var __extends = (this && this.__extends) || function (d, b) {
  14876. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  14877. function __() { this.constructor = d; }
  14878. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14879. };
  14880. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  14881. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14882. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14883. 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;
  14884. return c > 3 && r && Object.defineProperty(target, key, r), r;
  14885. };
  14886. var BABYLON;
  14887. (function (BABYLON) {
  14888. var Button = (function (_super) {
  14889. __extends(Button, _super);
  14890. function Button(settings) {
  14891. if (!settings) {
  14892. settings = {};
  14893. }
  14894. _super.call(this, settings);
  14895. if (settings.paddingAlignment == null) {
  14896. this.paddingAlignment.horizontal = BABYLON.PrimitiveAlignment.AlignCenter;
  14897. this.paddingAlignment.vertical = BABYLON.PrimitiveAlignment.AlignCenter;
  14898. }
  14899. this._normalStateBackground = new BABYLON.ObservableStringDictionary(false);
  14900. this._normalStateBorder = new BABYLON.ObservableStringDictionary(false);
  14901. this._defaultStateBackground = new BABYLON.ObservableStringDictionary(false);
  14902. this._defaultStateBorder = new BABYLON.ObservableStringDictionary(false);
  14903. this._normalStateBackground.add(BABYLON.UIElement.enabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#337AB7FF"));
  14904. this._normalStateBackground.add(BABYLON.UIElement.disabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#7BA9D0FF"));
  14905. this._normalStateBackground.add(BABYLON.UIElement.mouseOverState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#286090FF"));
  14906. this._normalStateBackground.add(Button.pushedState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#1E496EFF"));
  14907. this._normalStateBorder.add(BABYLON.UIElement.enabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#2E6DA4FF"));
  14908. this._normalStateBorder.add(BABYLON.UIElement.disabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#77A0C4FF"));
  14909. this._normalStateBorder.add(BABYLON.UIElement.mouseOverState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#204D74FF"));
  14910. this._normalStateBorder.add(Button.pushedState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#2E5D9EFF"));
  14911. this._defaultStateBackground.add(BABYLON.UIElement.enabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#FFFFFFFF"));
  14912. this._defaultStateBackground.add(BABYLON.UIElement.disabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#FFFFFFFF"));
  14913. this._defaultStateBackground.add(BABYLON.UIElement.mouseOverState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#E6E6E6FF"));
  14914. this._defaultStateBackground.add(Button.pushedState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#D4D4D4FF"));
  14915. this._defaultStateBorder.add(BABYLON.UIElement.enabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#CCCCCCFF"));
  14916. this._defaultStateBorder.add(BABYLON.UIElement.disabledState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#DEDEDEFF"));
  14917. this._defaultStateBorder.add(BABYLON.UIElement.mouseOverState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#ADADADFF"));
  14918. this._defaultStateBorder.add(Button.pushedState, BABYLON.Canvas2D.GetSolidColorBrushFromHex("#6C8EC5FF"));
  14919. }
  14920. Object.defineProperty(Button, "pushedState", {
  14921. get: function () {
  14922. return Button._pushedState;
  14923. },
  14924. enumerable: true,
  14925. configurable: true
  14926. });
  14927. Object.defineProperty(Button.prototype, "isPushed", {
  14928. get: function () {
  14929. return this._isPushed;
  14930. },
  14931. set: function (value) {
  14932. this._isPushed = value;
  14933. },
  14934. enumerable: true,
  14935. configurable: true
  14936. });
  14937. Object.defineProperty(Button.prototype, "isDefault", {
  14938. get: function () {
  14939. return this._isDefault;
  14940. },
  14941. set: function (value) {
  14942. this._isDefault = value;
  14943. },
  14944. enumerable: true,
  14945. configurable: true
  14946. });
  14947. Object.defineProperty(Button.prototype, "isOutline", {
  14948. get: function () {
  14949. return this._isOutline;
  14950. },
  14951. set: function (value) {
  14952. this._isOutline = value;
  14953. },
  14954. enumerable: true,
  14955. configurable: true
  14956. });
  14957. Object.defineProperty(Button.prototype, "clickObservable", {
  14958. get: function () {
  14959. if (!this._clickObservable) {
  14960. this._clickObservable = new BABYLON.Observable();
  14961. }
  14962. return this._clickObservable;
  14963. },
  14964. enumerable: true,
  14965. configurable: true
  14966. });
  14967. Button.prototype._raiseClick = function () {
  14968. if (this._clickObservable && this._clickObservable.hasObservers()) {
  14969. this._clickObservable.notifyObservers(this);
  14970. }
  14971. };
  14972. Button.prototype.createVisualTree = function () {
  14973. var _this = this;
  14974. _super.prototype.createVisualTree.call(this);
  14975. var p = this._visualPlaceholder;
  14976. p.pointerEventObservable.add(function (e, s) {
  14977. // check if input must be discarded
  14978. if (!_this.isVisible || !_this.isEnabled) {
  14979. return;
  14980. }
  14981. // We reject an event coming from the placeholder because it means it's on an empty spot, so it's not valid.
  14982. if (e.relatedTarget === _this._visualPlaceholder) {
  14983. return;
  14984. }
  14985. if (s.mask === BABYLON.PrimitivePointerInfo.PointerUp) {
  14986. _this._raiseClick();
  14987. _this.isPushed = false;
  14988. }
  14989. else if (s.mask === BABYLON.PrimitivePointerInfo.PointerDown) {
  14990. _this.isPushed = true;
  14991. _this.isFocused = true;
  14992. }
  14993. }, BABYLON.PrimitivePointerInfo.PointerUp | BABYLON.PrimitivePointerInfo.PointerDown);
  14994. };
  14995. Object.defineProperty(Button.prototype, "normalStateBackground", {
  14996. get: function () {
  14997. return this._normalStateBackground;
  14998. },
  14999. enumerable: true,
  15000. configurable: true
  15001. });
  15002. Object.defineProperty(Button.prototype, "defaultStateBackground", {
  15003. get: function () {
  15004. return this._defaultStateBackground;
  15005. },
  15006. enumerable: true,
  15007. configurable: true
  15008. });
  15009. Object.defineProperty(Button.prototype, "normalStateBorder", {
  15010. get: function () {
  15011. return this._normalStateBorder;
  15012. },
  15013. enumerable: true,
  15014. configurable: true
  15015. });
  15016. Object.defineProperty(Button.prototype, "defaultStateBorder", {
  15017. get: function () {
  15018. return this._defaultStateBorder;
  15019. },
  15020. enumerable: true,
  15021. configurable: true
  15022. });
  15023. Button.BUTTON_PROPCOUNT = BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 3;
  15024. Button._pushedState = "Pushed";
  15025. __decorate([
  15026. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTROL_PROPCOUNT + 0, function (pi) { return Button.isPushedProperty = pi; })
  15027. ], Button.prototype, "isPushed", null);
  15028. __decorate([
  15029. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTROL_PROPCOUNT + 1, function (pi) { return Button.isDefaultProperty = pi; })
  15030. ], Button.prototype, "isDefault", null);
  15031. __decorate([
  15032. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTROL_PROPCOUNT + 2, function (pi) { return Button.isOutlineProperty = pi; })
  15033. ], Button.prototype, "isOutline", null);
  15034. Button = __decorate([
  15035. BABYLON.className("Button", "BABYLON")
  15036. ], Button);
  15037. return Button;
  15038. }(BABYLON.ContentControl));
  15039. BABYLON.Button = Button;
  15040. var DefaultButtonRenderingTemplate = (function (_super) {
  15041. __extends(DefaultButtonRenderingTemplate, _super);
  15042. function DefaultButtonRenderingTemplate() {
  15043. _super.apply(this, arguments);
  15044. }
  15045. DefaultButtonRenderingTemplate.prototype.createVisualTree = function (owner, visualPlaceholder) {
  15046. this._rect = new BABYLON.Rectangle2D({ parent: visualPlaceholder, fill: "#FF8080FF", border: "#FF8080FF", roundRadius: 10, borderThickness: 2 });
  15047. this.stateChange();
  15048. return { root: this._rect, contentPlaceholder: this._rect };
  15049. };
  15050. DefaultButtonRenderingTemplate.prototype.attach = function (owner) {
  15051. var _this = this;
  15052. _super.prototype.attach.call(this, owner);
  15053. this.owner.propertyChanged.add(function (e, s) { return _this.stateChange(); }, BABYLON.UIElement.isEnabledProperty.flagId |
  15054. BABYLON.UIElement.isFocusedProperty.flagId |
  15055. BABYLON.UIElement.isMouseOverProperty.flagId |
  15056. Button.isDefaultProperty.flagId |
  15057. Button.isOutlineProperty.flagId |
  15058. Button.isPushedProperty.flagId);
  15059. // Register for brush change and update the Visual
  15060. var button = owner;
  15061. button.normalStateBackground.dictionaryChanged.add(function (e, c) { return _this.stateChange(); });
  15062. button.normalStateBorder.dictionaryChanged.add(function (e, c) { return _this.stateChange(); });
  15063. button.defaultStateBackground.dictionaryChanged.add(function (e, c) { return _this.stateChange(); });
  15064. button.defaultStateBorder.dictionaryChanged.add(function (e, c) { return _this.stateChange(); });
  15065. };
  15066. DefaultButtonRenderingTemplate.prototype.stateChange = function () {
  15067. //console.log("state changed");
  15068. var b = this.owner;
  15069. var state = BABYLON.UIElement.enabledState;
  15070. var bg = b.isDefault ? b.defaultStateBackground.get(state) : b.normalStateBackground.get(state);
  15071. var bd = b.isDefault ? b.defaultStateBorder.get(state) : b.normalStateBorder.get(state);
  15072. if (b.isPushed) {
  15073. state = Button.pushedState;
  15074. if (b.isDefault) {
  15075. bg = b.defaultStateBackground.get(state);
  15076. bd = b.defaultStateBorder.get(state);
  15077. }
  15078. else {
  15079. bg = b.normalStateBackground.get(state);
  15080. bd = b.normalStateBorder.get(state);
  15081. }
  15082. }
  15083. else if (b.isMouseOver) {
  15084. state = BABYLON.UIElement.mouseOverState;
  15085. if (b.isDefault) {
  15086. bg = b.defaultStateBackground.get(state);
  15087. bd = b.defaultStateBorder.get(state);
  15088. }
  15089. else {
  15090. bg = b.normalStateBackground.get(state);
  15091. bd = b.normalStateBorder.get(state);
  15092. }
  15093. }
  15094. else if (!b.isEnabled) {
  15095. state = BABYLON.UIElement.disabledState;
  15096. if (b.isDefault) {
  15097. bg = b.defaultStateBackground.get(state);
  15098. bd = b.defaultStateBorder.get(state);
  15099. }
  15100. else {
  15101. bg = b.normalStateBackground.get(state);
  15102. bd = b.normalStateBorder.get(state);
  15103. }
  15104. }
  15105. this._rect.fill = bg;
  15106. this._rect.border = bd;
  15107. };
  15108. DefaultButtonRenderingTemplate = __decorate([
  15109. BABYLON.registerWindowRenderingTemplate("BABYLON.Button", "Default", function () { return new DefaultButtonRenderingTemplate(); })
  15110. ], DefaultButtonRenderingTemplate);
  15111. return DefaultButtonRenderingTemplate;
  15112. }(BABYLON.UIElementRenderingTemplateBase));
  15113. BABYLON.DefaultButtonRenderingTemplate = DefaultButtonRenderingTemplate;
  15114. })(BABYLON || (BABYLON = {}));
  15115. //# sourceMappingURL=babylon.gui.button.js.map