babylon.canvas2d.d.ts 255 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250
  1. declare module BABYLON {
  2. /**
  3. * A class storing a Matrix2D for 2D transformations
  4. * The stored matrix is a 3*3 Matrix2D
  5. * I [0,1] [mX, mY] R [ CosZ, SinZ] T [ 0, 0] S [Sx, 0]
  6. * D = [2,3] = [nX, nY] O = [-SinZ, CosZ] R = [ 0, 0] C = [ 0, Sy]
  7. * X [4,5] [tX, tY] T [ 0 , 0 ] N [Tx, Ty] L [ 0, 0]
  8. *
  9. * IDX = index, zero based. ROT = Z axis Rotation. TRN = Translation. SCL = Scale.
  10. */
  11. class Matrix2D {
  12. static Zero(): Matrix2D;
  13. static FromValuesToRef(m0: number, m1: number, m2: number, m3: number, m4: number, m5: number, result: Matrix2D): void;
  14. static FromMatrix(source: Matrix): Matrix2D;
  15. static FromMatrixToRef(source: Matrix, result: Matrix2D): void;
  16. static Rotation(angle: number): Matrix2D;
  17. static RotationToRef(angle: number, result: Matrix2D): void;
  18. static Translation(x: number, y: number): Matrix2D;
  19. static TranslationToRef(x: number, y: number, result: Matrix2D): void;
  20. static Scaling(x: number, y: number): Matrix2D;
  21. static ScalingToRef(x: number, y: number, result: Matrix2D): void;
  22. m: Float32Array;
  23. static Identity(): Matrix2D;
  24. static IdentityToRef(res: Matrix2D): void;
  25. static FromQuaternion(quaternion: Quaternion): Matrix2D;
  26. static FromQuaternionToRef(quaternion: Quaternion, result: Matrix2D): void;
  27. static Compose(scale: Vector2, rotation: number, translation: Vector2): Matrix2D;
  28. static Invert(source: Matrix2D): Matrix2D;
  29. clone(): Matrix2D;
  30. copyFrom(other: Matrix2D): void;
  31. getTranslation(): Vector2;
  32. setTranslation(translation: Vector2): void;
  33. determinant(): number;
  34. invertToThis(): void;
  35. invert(): Matrix2D;
  36. invertToRef(res: Matrix2D): void;
  37. multiplyToThis(other: Matrix2D): void;
  38. multiply(other: Matrix2D): Matrix2D;
  39. multiplyToRef(other: Matrix2D, result: Matrix2D): void;
  40. transformFloats(x: number, y: number): Vector2;
  41. transformFloatsToRef(x: number, y: number, r: Vector2): void;
  42. transformPoint(p: Vector2): Vector2;
  43. transformPointToRef(p: Vector2, r: Vector2): void;
  44. private static _decomp;
  45. decompose(scale: Vector2, translation: Vector2): number;
  46. }
  47. /**
  48. * Stores information about a 2D Triangle.
  49. * This class stores the 3 vertices but also the center and radius of the triangle
  50. */
  51. class Tri2DInfo {
  52. /**
  53. * Construct an instance of Tri2DInfo, you can either pass null to a, b and c and the instance will be allocated "clear", or give actual triangle info and the center/radius will be computed
  54. */
  55. constructor(a: Vector2, b: Vector2, c: Vector2);
  56. a: Vector2;
  57. b: Vector2;
  58. c: Vector2;
  59. center: Vector2;
  60. radius: number;
  61. static Zero(): Tri2DInfo;
  62. set(a: Vector2, b: Vector2, c: Vector2): void;
  63. transformInPlace(transform: Matrix2D): void;
  64. doesContain(p: Vector2): boolean;
  65. private _updateCenterRadius();
  66. }
  67. /**
  68. * Stores an array of 2D Triangles.
  69. * Internally the data is stored as a Float32Array to minimize the memory footprint.
  70. * This can use the Tri2DInfo class as proxy for storing/retrieving data.
  71. * The array can't grow, it's fixed size.
  72. */
  73. class Tri2DArray {
  74. constructor(count: number);
  75. /**
  76. * Clear the content and allocate a new array to store the given count of triangles
  77. * @param count The new count of triangles to store
  78. */
  79. clear(count: number): void;
  80. /**
  81. * Store a given triangle at the given index
  82. * @param index the 0 based index to store the triangle in the array
  83. * @param a the A vertex of the triangle
  84. * @param b the B vertex of the triangle
  85. * @param c the C vertex of the triangle
  86. */
  87. storeTriangle(index: number, a: Vector2, b: Vector2, c: Vector2): void;
  88. /**
  89. * Store a triangle in a Tri2DInfo object
  90. * @param index the index of the triangle to store
  91. * @param tri2dInfo the instance that will contain the data, it must be already allocated with its inner object also allocated
  92. */
  93. storeToTri2DInfo(index: number, tri2dInfo: Tri2DInfo): void;
  94. /**
  95. * Transform the given triangle and store its result in the array
  96. * @param index The index to store the result to
  97. * @param tri2dInfo The triangle to transform
  98. * @param transform The transformation matrix
  99. */
  100. transformAndStoreToTri2DInfo(index: number, tri2dInfo: Tri2DInfo, transform: Matrix2D): void;
  101. /**
  102. * Get the element count that can be stored in this array
  103. * @returns {}
  104. */
  105. readonly count: number;
  106. /**
  107. * Check if a given point intersects with at least one of the triangles stored in the array.
  108. * If true is returned the point is intersecting with at least one triangle, false if it doesn't intersect with any of them
  109. * @param p The point to check
  110. */
  111. doesContain(p: Vector2): boolean;
  112. /**
  113. * Make a intersection test between two sets of triangles. The triangles of setB will be transformed to the frame of reference of the setA using the given bToATransform matrix.
  114. * If true is returned at least one triangle intersects with another of the other set, otherwise false is returned.
  115. * @param setA The first set of triangles
  116. * @param setB The second set of triangles
  117. * @param bToATransform The transformation matrix to transform the setB triangles into the frame of reference of the setA
  118. */
  119. static doesIntersect(setA: Tri2DArray, setB: Tri2DArray, bToATransform: Matrix2D): boolean;
  120. private static _checkInitStatics();
  121. private _count;
  122. private _array;
  123. private static tempV;
  124. private static tempT;
  125. }
  126. }
  127. declare module BABYLON {
  128. class PropertyChangedInfo {
  129. /**
  130. * Previous value of the property
  131. */
  132. oldValue: any;
  133. /**
  134. * New value of the property
  135. */
  136. newValue: any;
  137. /**
  138. * Name of the property that changed its value
  139. */
  140. propertyName: string;
  141. }
  142. /**
  143. * Custom type of the propertyChanged observable
  144. */
  145. /**
  146. * Property Changed interface
  147. */
  148. interface IPropertyChanged {
  149. /**
  150. * PropertyChanged observable
  151. */
  152. propertyChanged: Observable<PropertyChangedInfo>;
  153. }
  154. /**
  155. * The purpose of this class is to provide a base implementation of the IPropertyChanged interface for the user to avoid rewriting a code needlessly.
  156. * 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.
  157. * 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)
  158. */
  159. abstract class PropertyChangedBase implements IPropertyChanged {
  160. /**
  161. * Protected method to call when there's a change of value in a property set
  162. * @param propName the name of the concerned property
  163. * @param oldValue its old value
  164. * @param newValue its new value
  165. * @param mask an optional observable mask
  166. */
  167. protected onPropertyChanged<T>(propName: string, oldValue: T, newValue: T, mask?: number): void;
  168. /**
  169. * An observable that is triggered when a property (using of the XXXXLevelProperty decorator) has its value changing.
  170. * 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)
  171. */
  172. readonly propertyChanged: Observable<PropertyChangedInfo>;
  173. _propertyChanged: Observable<PropertyChangedInfo>;
  174. private static pci;
  175. private static calling;
  176. }
  177. }
  178. declare module BABYLON {
  179. class C2DLogging {
  180. static snooze: boolean;
  181. static logFrameRender(frameCount: number): void;
  182. static setPostMessage(message: () => string): void;
  183. static _startFrameRender(): void;
  184. static _endFrameRender(): void;
  185. private static _logFramesCount;
  186. }
  187. function logProp<T>(message?: string, alsoGet?: boolean, setNoProlog?: boolean, getNoProlog?: boolean): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void;
  188. function logMethod(message?: string, noProlog?: boolean): (target: any, key: any, descriptor: any) => any;
  189. }
  190. declare module BABYLON {
  191. /**
  192. * Class for the ObservableArray.onArrayChanged observable
  193. */
  194. class ArrayChanged<T> {
  195. constructor();
  196. /**
  197. * Contain the action that were made on the ObservableArray, it's one of the ArrayChanged.xxxAction members.
  198. * Note the action's value can be used in the "mask" field of the Observable to only be notified about given action(s)
  199. */
  200. action: number;
  201. /**
  202. * Only valid if the action is newItemsAction
  203. */
  204. newItems: {
  205. index: number;
  206. value: T;
  207. }[];
  208. /**
  209. * Only valid if the action is removedItemsAction
  210. */
  211. removedItems: {
  212. index: number;
  213. value: T;
  214. }[];
  215. /**
  216. * Only valid if the action is changedItemAction
  217. */
  218. changedItems: {
  219. index: number;
  220. value: T;
  221. }[];
  222. /**
  223. * Get the index of the first item inserted
  224. */
  225. newStartingIndex: number;
  226. /**
  227. * Get the index of the first item removed
  228. */
  229. removedStartingIndex: number;
  230. /**
  231. * Get the index of the first changed item
  232. */
  233. changedStartingIndex: number;
  234. /**
  235. * The content of the array was totally cleared
  236. */
  237. static readonly clearAction: number;
  238. /**
  239. * A new item was added, the newItems field contains the key/value pairs
  240. */
  241. static readonly newItemsAction: number;
  242. /**
  243. * An existing item was removed, the removedKey field contains its key
  244. */
  245. static readonly removedItemsAction: number;
  246. /**
  247. * One or many items in the array were changed, the
  248. */
  249. static readonly changedItemAction: number;
  250. /**
  251. * The array's content was totally changed
  252. * Depending on the method that used this mode the ChangedArray object may contains more information
  253. */
  254. static readonly replacedArrayAction: number;
  255. /**
  256. * The length of the array changed
  257. */
  258. static readonly lengthChangedAction: number;
  259. private static _clearAction;
  260. private static _newItemsAction;
  261. private static _removedItemsAction;
  262. private static _replacedArrayAction;
  263. private static _lengthChangedAction;
  264. private static _changedItemAction;
  265. clear(): void;
  266. }
  267. class OAWatchedObjectChangedInfo<T> {
  268. object: T;
  269. propertyChanged: PropertyChangedInfo;
  270. }
  271. /**
  272. * This class mimics the Javascript Array and TypeScript Array<T> classes, adding new features concerning the Observable pattern.
  273. *
  274. */
  275. class ObservableArray<T> extends PropertyChangedBase {
  276. /**
  277. * Create an Observable Array.
  278. * @param watchObjectsPropertyChange
  279. * @param array and optional array that will be encapsulated by this ObservableArray instance. That's right, it's NOT a copy!
  280. */
  281. constructor(watchObjectsPropertyChange: boolean, array?: Array<T>);
  282. /**
  283. * Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.
  284. */
  285. length: number;
  286. getAt(index: number): T;
  287. setAt(index: number, value: T): boolean;
  288. /**
  289. * Returns a string representation of an array.
  290. */
  291. toString(): string;
  292. toLocaleString(): string;
  293. /**
  294. * Appends new elements to an array, and returns the new length of the array.
  295. * @param items New elements of the Array.
  296. */
  297. push(...items: T[]): number;
  298. /**
  299. * Removes the last element from an array and returns it.
  300. */
  301. pop(): T;
  302. /**
  303. * Combines two or more arrays.
  304. * @param items Additional items to add to the end of array1.
  305. */
  306. concat(...items: T[]): ObservableArray<T>;
  307. /**
  308. * Adds all the elements of an array separated by the specified separator string.
  309. * @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.
  310. */
  311. join(separator?: string): string;
  312. /**
  313. * Reverses the elements in an Array.
  314. * The arrayChanged action is
  315. */
  316. reverse(): T[];
  317. /**
  318. * Removes the first element from an array and returns it, shift all subsequents element one element before.
  319. * The ArrayChange action is replacedArrayAction, the whole array changes and must be reevaluate as such, the removed element is in removedItems.
  320. *
  321. */
  322. shift(): T;
  323. /**
  324. * Returns a section of an array.
  325. * @param start The beginning of the specified portion of the array.
  326. * @param end The end of the specified portion of the array.
  327. */
  328. slice(start?: number, end?: number): ObservableArray<T>;
  329. /**
  330. * Sorts an array.
  331. * @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.
  332. * On the contrary of the Javascript Array's implementation, this method returns nothing
  333. */
  334. sort(compareFn?: (a: T, b: T) => number): void;
  335. /**
  336. * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
  337. * @param start The zero-based location in the array from which to start removing elements.
  338. * @param deleteCount The number of elements to remove.
  339. * @param items Elements to insert into the array in place of the deleted elements.
  340. */
  341. splice(start: number, deleteCount: number, ...items: T[]): T[];
  342. /**
  343. * Inserts new elements at the start of an array.
  344. * @param items Elements to insert at the start of the Array.
  345. * The ChangedArray action is replacedArrayAction, newItems contains the list of the added items
  346. */
  347. unshift(...items: T[]): number;
  348. /**
  349. * Returns the index of the first occurrence of a value in an array.
  350. * @param searchElement The value to locate in the array.
  351. * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
  352. */
  353. indexOf(searchElement: T, fromIndex?: number): number;
  354. /**
  355. * Returns the index of the last occurrence of a specified value in an array.
  356. * @param searchElement The value to locate in the array.
  357. * @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.
  358. */
  359. lastIndexOf(searchElement: T, fromIndex?: number): number;
  360. /**
  361. * Determines whether all the members of an array satisfy the specified test.
  362. * @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.
  363. * @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.
  364. */
  365. every(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean;
  366. /**
  367. * Determines whether the specified callback function returns true for any element of an array.
  368. * @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.
  369. * @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.
  370. */
  371. some(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean;
  372. /**
  373. * Performs the specified action for each element in an array.
  374. * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
  375. * @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.
  376. */
  377. forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void;
  378. /**
  379. * Calls a defined callback function on each element of an array, and returns an array that contains the results.
  380. * @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.
  381. * @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.
  382. */
  383. map<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[];
  384. /**
  385. * Returns the elements of an array that meet the condition specified in a callback function.
  386. * @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.
  387. * @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.
  388. */
  389. filter(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): T[];
  390. /**
  391. * 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.
  392. * @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.
  393. * @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.
  394. */
  395. reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T;
  396. /**
  397. * 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.
  398. * @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.
  399. * @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.
  400. */
  401. reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T;
  402. readonly arrayChanged: Observable<ArrayChanged<T>>;
  403. protected getArrayChangedObject(): ArrayChanged<T>;
  404. protected feedNotifArray(array: {
  405. index: number;
  406. value: T;
  407. }[], startindIndex: number, ...items: T[]): void;
  408. protected callArrayChanged(ac: ArrayChanged<T>): void;
  409. readonly watchedObjectChanged: Observable<OAWatchedObjectChangedInfo<T>>;
  410. private _addWatchedElement(...items);
  411. private _removeWatchedElement(...items);
  412. protected onWatchedObjectChanged(key: string, object: T, propChanged: PropertyChangedInfo): void;
  413. private _array;
  414. private _arrayChanged;
  415. private dci;
  416. private _callingArrayChanged;
  417. private _watchedObjectChanged;
  418. private _woci;
  419. private _callingWatchedObjectChanged;
  420. private _watchObjectsPropertyChange;
  421. private _watchedObjectList;
  422. }
  423. }
  424. declare module BABYLON {
  425. /**
  426. * Class for the ObservableStringDictionary.onDictionaryChanged observable
  427. */
  428. class DictionaryChanged<T> {
  429. /**
  430. * Contain the action that were made on the dictionary, it's one of the DictionaryChanged.xxxAction members.
  431. * Note the action's value can be used in the "mask" field of the Observable to only be notified about given action(s)
  432. */
  433. action: number;
  434. /**
  435. * Only valid if the action is newItemAction
  436. */
  437. newItem: {
  438. key: string;
  439. value: T;
  440. };
  441. /**
  442. * Only valid if the action is removedItemAction
  443. */
  444. removedKey: string;
  445. /**
  446. * Only valid if the action is itemValueChangedAction
  447. */
  448. changedItem: {
  449. key: string;
  450. oldValue: T;
  451. newValue: T;
  452. };
  453. /**
  454. * The content of the dictionary was totally cleared
  455. */
  456. static readonly clearAction: number;
  457. /**
  458. * A new item was added, the newItem field contains the key/value pair
  459. */
  460. static readonly newItemAction: number;
  461. /**
  462. * An existing item was removed, the removedKey field contains its key
  463. */
  464. static readonly removedItemAction: number;
  465. /**
  466. * An existing item had a value change, the changedItem field contains the key/value
  467. */
  468. static readonly itemValueChangedAction: number;
  469. /**
  470. * The dictionary's content was reset and replaced by the content of another dictionary.
  471. * DictionaryChanged<T> contains no further information about this action
  472. */
  473. static readonly replacedAction: number;
  474. private static _clearAction;
  475. private static _newItemAction;
  476. private static _removedItemAction;
  477. private static _itemValueChangedAction;
  478. private static _replacedAction;
  479. }
  480. class OSDWatchedObjectChangedInfo<T> {
  481. key: string;
  482. object: T;
  483. propertyChanged: PropertyChangedInfo;
  484. }
  485. class ObservableStringDictionary<T> extends StringDictionary<T> implements IPropertyChanged {
  486. constructor(watchObjectsPropertyChange: boolean);
  487. /**
  488. * This will clear this dictionary and copy the content from the 'source' one.
  489. * If the T value is a custom object, it won't be copied/cloned, the same object will be used
  490. * @param source the dictionary to take the content from and copy to this dictionary
  491. */
  492. copyFrom(source: StringDictionary<T>): void;
  493. /**
  494. * Get a value from its key or add it if it doesn't exist.
  495. * This method will ensure you that a given key/data will be present in the dictionary.
  496. * @param key the given key to get the matching value from
  497. * @param factory the factory that will create the value if the key is not present in the dictionary.
  498. * The factory will only be invoked if there's no data for the given key.
  499. * @return the value corresponding to the key.
  500. */
  501. getOrAddWithFactory(key: string, factory: (key: string) => T): T;
  502. /**
  503. * Add a new key and its corresponding value
  504. * @param key the key to add
  505. * @param value the value corresponding to the key
  506. * @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
  507. */
  508. add(key: string, value: T): boolean;
  509. getAndRemove(key: string): T;
  510. private _add(key, value, fireNotif, registerWatcher);
  511. private _addWatchedElement(key, el);
  512. private _removeWatchedElement(key, el);
  513. set(key: string, value: T): boolean;
  514. /**
  515. * Remove a key/value from the dictionary.
  516. * @param key the key to remove
  517. * @return true if the item was successfully deleted, false if no item with such key exist in the dictionary
  518. */
  519. remove(key: string): boolean;
  520. private _remove(key, fireNotif, element?);
  521. /**
  522. * Clear the whole content of the dictionary
  523. */
  524. clear(): void;
  525. readonly propertyChanged: Observable<PropertyChangedInfo>;
  526. protected onPropertyChanged<T>(propName: string, oldValue: T, newValue: T, mask?: number): void;
  527. readonly dictionaryChanged: Observable<DictionaryChanged<T>>;
  528. protected onDictionaryChanged(action: number, newItem: {
  529. key: string;
  530. value: T;
  531. }, removedKey: string, changedItem: {
  532. key: string;
  533. oldValue: T;
  534. newValue: T;
  535. }): void;
  536. readonly watchedObjectChanged: Observable<OSDWatchedObjectChangedInfo<T>>;
  537. protected onWatchedObjectChanged(key: string, object: T, propChanged: PropertyChangedInfo): void;
  538. private _propertyChanged;
  539. private static pci;
  540. private static callingPropChanged;
  541. private _dictionaryChanged;
  542. private dci;
  543. private _callingDicChanged;
  544. private _watchedObjectChanged;
  545. private _woci;
  546. private _callingWatchedObjectChanged;
  547. private _watchObjectsPropertyChange;
  548. private _watchedObjectList;
  549. }
  550. }
  551. declare module BABYLON {
  552. /**
  553. * This class given information about a given character.
  554. */
  555. class CharInfo {
  556. /**
  557. * The normalized ([0;1]) top/left position of the character in the texture
  558. */
  559. topLeftUV: Vector2;
  560. /**
  561. * The normalized ([0;1]) right/bottom position of the character in the texture
  562. */
  563. bottomRightUV: Vector2;
  564. xOffset: number;
  565. yOffset: number;
  566. xAdvance: number;
  567. charWidth: number;
  568. }
  569. /**
  570. * This is an abstract base class to hold a Texture that will contain a FontMap
  571. */
  572. abstract class BaseFontTexture extends Texture {
  573. constructor(url: string, scene: Scene, noMipmap?: boolean, invertY?: boolean, samplingMode?: number, premultipliedAlpha?: boolean);
  574. /**
  575. * Is the Font is using Super Sampling (each font texel is doubled).
  576. */
  577. readonly isSuperSampled: boolean;
  578. /**
  579. * Is the Font was rendered using the Signed Distance Field algorithm
  580. * @returns {}
  581. */
  582. readonly isSignedDistanceField: boolean;
  583. /**
  584. * True if the font was drawn using multiplied alpha
  585. */
  586. readonly isPremultipliedAlpha: boolean;
  587. /**
  588. * Get the Width (in pixel) of the Space character
  589. */
  590. readonly spaceWidth: number;
  591. /**
  592. * Get the Line height (in pixel)
  593. */
  594. readonly lineHeight: number;
  595. /**
  596. * When the FontTexture is retrieved through the FontCache, there's a reference counter that is incremented for each use.
  597. * You also have the possibility to extend the lifetime of the FontTexture when passing it to another object by calling this method
  598. * Don't forget to call the corresponding decCachedFontTextureCounter method when you no longer have use of the FontTexture.
  599. * Each call to incCachedFontTextureCounter must have a corresponding call to decCachedFontTextureCounter.
  600. */
  601. abstract incCachedFontTextureCounter(): any;
  602. /**
  603. * Decrement the reference counter, if it reaches 0 the FontTexture is disposed
  604. */
  605. abstract decCachedFontTextureCounter(): any;
  606. /**
  607. * Is the font dynamically updated, if true is returned then you have to call the update() before using the font in rendering if new character were adding using getChar()
  608. */
  609. readonly abstract isDynamicFontTexture: boolean;
  610. /**
  611. * Will fetch the new characters retrieved with getChar() to the texture.
  612. * If there were no new char, this call is harmless and quit in no time.
  613. * If there were new chars a texture lock/update is made, which is a costy operation.
  614. */
  615. abstract update(): void;
  616. /**
  617. * Measure the width/height that will take a given text
  618. * @param text the text to measure
  619. * @param tabulationSize the size (in space character) of the tabulation character, default value must be 4
  620. */
  621. measureText(text: string, tabulationSize?: number): Size;
  622. /**
  623. * Retrieve the CharInfo object for a given character
  624. * @param char the character to retrieve the CharInfo object from (e.g.: "A", "a", etc.)
  625. */
  626. abstract getChar(char: string): CharInfo;
  627. protected _charInfos: StringDictionary<CharInfo>;
  628. protected _lineHeight: number;
  629. protected _spaceWidth: any;
  630. protected _superSample: boolean;
  631. protected _signedDistanceField: boolean;
  632. protected _isPremultipliedAlpha: boolean;
  633. protected _cachedFontId: string;
  634. }
  635. class BitmapFontInfo {
  636. kerningDic: StringDictionary<number>;
  637. charDic: StringDictionary<CharInfo>;
  638. textureSize: Size;
  639. atlasName: string;
  640. padding: Vector4;
  641. lineHeight: number;
  642. baseLine: number;
  643. textureUrl: string;
  644. textureFile: string;
  645. }
  646. interface IBitmapFontLoader {
  647. loadFont(fontDataContent: any, scene: Scene, invertY: boolean): {
  648. bfi: BitmapFontInfo;
  649. errorMsg: string;
  650. errorCode: number;
  651. };
  652. }
  653. class BitmapFontTexture extends BaseFontTexture {
  654. constructor(scene: Scene, bmFontUrl: string, textureUrl?: string, noMipmap?: boolean, invertY?: boolean, samplingMode?: number, premultipliedAlpha?: boolean, onLoad?: () => void, onError?: (msg: string, code: number) => void);
  655. static GetCachedFontTexture(scene: Scene, fontTexture: BitmapFontTexture): BitmapFontTexture;
  656. static ReleaseCachedFontTexture(scene: Scene, fontTexture: BitmapFontTexture): void;
  657. /**
  658. * Is the font dynamically updated, if true is returned then you have to call the update() before using the font in rendering if new character were adding using getChar()
  659. */
  660. readonly isDynamicFontTexture: boolean;
  661. /**
  662. * This method does nothing for a BitmapFontTexture object as it's a static texture
  663. */
  664. update(): void;
  665. /**
  666. * Retrieve the CharInfo object for a given character
  667. * @param char the character to retrieve the CharInfo object from (e.g.: "A", "a", etc.)
  668. */
  669. getChar(char: string): CharInfo;
  670. /**
  671. * For FontTexture retrieved using GetCachedFontTexture, use this method when you transfer this object's lifetime to another party in order to share this resource.
  672. * When the other party is done with this object, decCachedFontTextureCounter must be called.
  673. */
  674. incCachedFontTextureCounter(): void;
  675. /**
  676. * Use this method only in conjunction with incCachedFontTextureCounter, call it when you no longer need to use this shared resource.
  677. */
  678. decCachedFontTextureCounter(): void;
  679. private _usedCounter;
  680. static addLoader(fileExtension: string, plugin: IBitmapFontLoader): void;
  681. static plugins: StringDictionary<IBitmapFontLoader[]>;
  682. }
  683. /**
  684. * This class is a special kind of texture which generates on the fly characters of a given css style "fontName".
  685. * The generated texture will be updated when new characters will be retrieved using the getChar() method, but you have
  686. * to call the update() method for the texture to fetch these changes, you can harmlessly call update any time you want, if no
  687. * change were made, nothing will happen.
  688. * The Font Texture can be rendered in three modes: normal size, super sampled size (x2) or using Signed Distance Field rendering.
  689. * Signed Distance Field should be prefered because the texture can be rendered using AlphaTest instead of Transparency, which is way more faster. More about SDF here (http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf).
  690. * The only flaw of SDF is that the rendering quality may not be the best or the edges too sharp is the font thickness is too thin.
  691. */
  692. class FontTexture extends BaseFontTexture {
  693. private _canvas;
  694. private _context;
  695. private _lineHeightSuper;
  696. private _xMargin;
  697. private _yMargin;
  698. private _offset;
  699. private _baseLine;
  700. private _currentFreePosition;
  701. private _curCharCount;
  702. private _lastUpdateCharCount;
  703. private _spaceWidthSuper;
  704. private _sdfCanvas;
  705. private _sdfContext;
  706. private _sdfScale;
  707. private _usedCounter;
  708. debugMode: boolean;
  709. readonly isDynamicFontTexture: boolean;
  710. static GetCachedFontTexture(scene: Scene, fontName: string, supersample?: boolean, signedDistanceField?: boolean, bilinearFiltering?: boolean): FontTexture;
  711. static ReleaseCachedFontTexture(scene: Scene, fontName: string, supersample?: boolean, signedDistanceField?: boolean, bilinearFiltering?: boolean): void;
  712. /**
  713. * Create a new instance of the FontTexture class
  714. * @param name the name of the texture
  715. * @param font the font to use, use the W3C CSS notation
  716. * @param scene the scene that owns the texture
  717. * @param maxCharCount the approximative maximum count of characters that could fit in the texture. This is an approximation because most of the fonts are proportional (each char has its own Width). The 'W' character's width is used to compute the size of the texture based on the given maxCharCount
  718. * @param samplingMode the texture sampling mode
  719. * @param superSample if true the FontTexture will be created with a font of a size twice bigger than the given one but all properties (lineHeight, charWidth, etc.) will be according to the original size. This is made to improve the text quality.
  720. */
  721. constructor(name: string, font: string, scene: Scene, maxCharCount?: number, samplingMode?: number, superSample?: boolean, signedDistanceField?: boolean);
  722. private _saveToImage(url);
  723. /**
  724. * Make sure the given char is present in the font map.
  725. * @param char the character to get or add
  726. * @return the CharInfo instance corresponding to the given character
  727. */
  728. getChar(char: string): CharInfo;
  729. private _computeSDFChar(source);
  730. private getSuperSampleFont(font);
  731. private getFontHeight(font, chars);
  732. readonly canRescale: boolean;
  733. getContext(): CanvasRenderingContext2D;
  734. /**
  735. * Call this method when you've call getChar() at least one time, this will update the texture if needed.
  736. * Don't be afraid to call it, if no new character was added, this method simply does nothing.
  737. */
  738. update(): void;
  739. clone(): FontTexture;
  740. /**
  741. * For FontTexture retrieved using GetCachedFontTexture, use this method when you transfer this object's lifetime to another party in order to share this resource.
  742. * When the other party is done with this object, decCachedFontTextureCounter must be called.
  743. */
  744. incCachedFontTextureCounter(): void;
  745. /**
  746. * Use this method only in conjunction with incCachedFontTextureCounter, call it when you no longer need to use this shared resource.
  747. */
  748. decCachedFontTextureCounter(): void;
  749. }
  750. function BitmapFontLoaderPlugin(fileExtension: string, plugin: IBitmapFontLoader): (target: Object) => void;
  751. }
  752. declare module BABYLON {
  753. /**
  754. * Stores 2D Bounding Information.
  755. * This class handles a circle area and a bounding rectangle one.
  756. */
  757. class BoundingInfo2D {
  758. /**
  759. * The coordinate of the center of the bounding info
  760. */
  761. center: Vector2;
  762. /**
  763. * The radius of the bounding circle, from the center of the bounded object
  764. */
  765. radius: number;
  766. /**
  767. * The extent of the bounding rectangle, from the center of the bounded object.
  768. * This is an absolute value in both X and Y of the vector which describe the right/top corner of the rectangle, you can easily reconstruct the whole rectangle by negating X &| Y.
  769. */
  770. extent: Vector2;
  771. constructor();
  772. /**
  773. * Create a BoundingInfo2D object from a given size
  774. * @param size the size that will be used to set the extend, radius will be computed from it.
  775. */
  776. static CreateFromSize(size: Size): BoundingInfo2D;
  777. /**
  778. * Create a BoundingInfo2D object from a given radius
  779. * @param radius the radius to use, the extent will be computed from it.
  780. */
  781. static CreateFromRadius(radius: number): BoundingInfo2D;
  782. /**
  783. * Create a BoundingInfo2D object from a list of points.
  784. * The resulted object will be the smallest bounding area that includes all the given points.
  785. * @param points an array of points to compute the bounding object from.
  786. */
  787. static CreateFromPoints(points: Vector2[]): BoundingInfo2D;
  788. /**
  789. * Update a BoundingInfo2D object using the given Size as input
  790. * @param size the bounding data will be computed from this size.
  791. * @param b must be a valid/allocated object, it will contain the result of the operation
  792. */
  793. static CreateFromSizeToRef(size: Size, b: BoundingInfo2D): void;
  794. /**
  795. * Update a BoundingInfo2D object using the given radius as input
  796. * @param radius the bounding data will be computed from this radius
  797. * @param b must be a valid/allocated object, it will contain the result of the operation
  798. */
  799. static CreateFromRadiusToRef(radius: number, b: BoundingInfo2D): void;
  800. /**
  801. * Update a BoundingInfo2D object using the given points array as input
  802. * @param points the point array to use to update the bounding data
  803. * @param b must be a valid/allocated object, it will contain the result of the operation
  804. */
  805. static CreateFromPointsToRef(points: Vector2[], b: BoundingInfo2D): void;
  806. /**
  807. * Update a BoundingInfo2D object using the given min/max values as input
  808. * @param xmin the smallest x coordinate
  809. * @param xmax the biggest x coordinate
  810. * @param ymin the smallest y coordinate
  811. * @param ymax the buggest y coordinate
  812. * @param b must be a valid/allocated object, it will contain the result of the operation
  813. */
  814. static CreateFromMinMaxToRef(xmin: number, xmax: number, ymin: number, ymax: number, b: BoundingInfo2D): void;
  815. toString(): string;
  816. /**
  817. * Duplicate this instance and return a new one
  818. * @return the duplicated instance
  819. */
  820. clone(): BoundingInfo2D;
  821. clear(): void;
  822. copyFrom(src: BoundingInfo2D): void;
  823. equals(other: BoundingInfo2D): boolean;
  824. /**
  825. * return the max extend of the bounding info
  826. */
  827. max(): Vector2;
  828. /**
  829. * return the min/max extend of the bounding info.
  830. * x, y, z, w are left, bottom, right and top
  831. */
  832. minMax(): Vector4;
  833. /**
  834. * Update a vector2 with the max extend of the bounding info
  835. * @param result must be a valid/allocated vector2 that will contain the result of the operation
  836. */
  837. maxToRef(result: Vector2): void;
  838. /**
  839. * Update a vector4 with the min/max extend of the bounding info
  840. * x, y, z, w are left, bottom, right and top
  841. * @param result must be a valid/allocated vector4 that will contain the result of the operation
  842. */
  843. minMaxToRef(result: Vector4): void;
  844. /**
  845. * Return the size of the boundingInfo rect surface
  846. */
  847. size(): Size;
  848. /**
  849. * Stores in the result object the size of the boundingInfo rect surface
  850. * @param result
  851. */
  852. sizeToRef(result: Size): void;
  853. /**
  854. * Inflate the boundingInfo with the given vector
  855. * @param offset the extent will be incremented with offset and the radius will be computed again
  856. */
  857. inflate(offset: Vector2): void;
  858. /**
  859. * Apply a transformation matrix to this BoundingInfo2D and return a new instance containing the result
  860. * @param matrix the transformation matrix to apply
  861. * @return the new instance containing the result of the transformation applied on this BoundingInfo2D
  862. */
  863. transform(matrix: Matrix2D): BoundingInfo2D;
  864. /**
  865. * Compute the union of this BoundingInfo2D with a given one, returns a new BoundingInfo2D as a result
  866. * @param other the second BoundingInfo2D to compute the union with this one
  867. * @return a new instance containing the result of the union
  868. */
  869. union(other: BoundingInfo2D): BoundingInfo2D;
  870. worldAABBIntersectionTest(other: BoundingInfo2D): boolean;
  871. private static _transform;
  872. /**
  873. * Transform this BoundingInfo2D with a given matrix and store the result in an existing BoundingInfo2D instance.
  874. * 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.
  875. * @param matrix The matrix to use to compute the transformation
  876. * @param result A VALID (i.e. allocated) BoundingInfo2D object where the result will be stored
  877. */
  878. transformToRef(matrix: Matrix2D, result: BoundingInfo2D): void;
  879. private _updateWorldAABB(worldMatrix);
  880. worldMatrixAccess: () => Matrix2D;
  881. readonly worldAABBDirtyObservable: Observable<BoundingInfo2D>;
  882. readonly isWorldAABBDirty: boolean;
  883. dirtyWorldAABB(): void;
  884. /**
  885. * Retrieve the world AABB, the Vector4's data is x=xmin, y=ymin, z=xmax, w=ymax
  886. */
  887. readonly worldAABB: Vector4;
  888. /**
  889. * Compute the union of this BoundingInfo2D with another one and store the result in a third valid BoundingInfo2D object
  890. * 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.
  891. * @param other the second object used to compute the union
  892. * @param result a VALID BoundingInfo2D instance (i.e. allocated) where the result will be stored
  893. */
  894. unionToRef(other: BoundingInfo2D, result: BoundingInfo2D): void;
  895. /**
  896. * Check if the given point is inside the BoundingInfo.
  897. * The test is first made on the radius, then inside the rectangle described by the extent
  898. * @param pickPosition the position to test
  899. * @return true if the point is inside, false otherwise
  900. */
  901. doesIntersect(pickPosition: Vector2): boolean;
  902. private _worldAABBDirtyObservable;
  903. private _worldAABBDirty;
  904. private _worldAABB;
  905. }
  906. }
  907. declare module BABYLON {
  908. /**
  909. * The base class for all implementation of a Primitive Collision Manager
  910. */
  911. abstract class PrimitiveCollisionManagerBase {
  912. constructor(owner: Canvas2D);
  913. abstract _addActor(actor: Prim2DBase, deep: boolean): ActorInfoBase;
  914. abstract _removeActor(actor: Prim2DBase): any;
  915. abstract _update(): any;
  916. /**
  917. * If collisionManagerUseBorders is true during the Canvas creation, this dictionary contains all the primitives intersecting with the left border
  918. */
  919. readonly abstract leftBorderIntersectedActors: ObservableStringDictionary<Prim2DBase>;
  920. /**
  921. * If collisionManagerUseBorders is true during the Canvas creation, this dictionary contains all the primitives intersecting with the bottom border
  922. */
  923. readonly abstract bottomBorderIntersectedActors: ObservableStringDictionary<Prim2DBase>;
  924. /**
  925. * If collisionManagerUseBorders is true during the Canvas creation, this dictionary contains all the primitives intersecting with the right border
  926. */
  927. readonly abstract rightBorderIntersectedActors: ObservableStringDictionary<Prim2DBase>;
  928. /**
  929. * If collisionManagerUseBorders is true during the Canvas creation, this dictionary contains all the primitives intersecting with the top border
  930. */
  931. readonly abstract topBorderIntersectedActors: ObservableStringDictionary<Prim2DBase>;
  932. /**
  933. * This dictionary contains all the couple of intersecting primitives
  934. */
  935. readonly abstract intersectedActors: ObservableStringDictionary<{
  936. a: Prim2DBase;
  937. b: Prim2DBase;
  938. }>;
  939. /**
  940. * Renders the World AABB of all Actors
  941. */
  942. abstract debugRenderAABB: boolean;
  943. /**
  944. * Renders the area of the Clusters
  945. */
  946. abstract debugRenderClusters: boolean;
  947. /**
  948. * Display stats about the PCM on screen
  949. */
  950. abstract debugStats: boolean;
  951. static allocBasicPCM(owner: Canvas2D, enableBorders: boolean): PrimitiveCollisionManagerBase;
  952. protected _owner: Canvas2D;
  953. }
  954. /**
  955. * Base class of an Actor
  956. */
  957. abstract class ActorInfoBase {
  958. /**
  959. * Access the World AABB of the Actor, the vector4 is x:left, y: bottom, z: right, w: top
  960. */
  961. readonly abstract worldAABB: Vector4;
  962. /**
  963. * Return true if the actor is enable, false otherwise
  964. */
  965. readonly abstract isEnabled: boolean;
  966. /**
  967. * Return true is the actor boundingInfo is use, false if its levelBoundingInfo is used.
  968. */
  969. readonly abstract isDeep: boolean;
  970. /**
  971. * Return the primitive of the actor
  972. */
  973. readonly abstract prim: Prim2DBase;
  974. /**
  975. * Return a dictionary containing all the actors intersecting with this one
  976. */
  977. readonly abstract intersectWith: ObservableStringDictionary<ActorInfoBase>;
  978. }
  979. }
  980. declare module BABYLON {
  981. interface ILayoutData {
  982. }
  983. class LayoutEngineBase implements ILockable {
  984. constructor();
  985. updateLayout(prim: Prim2DBase): void;
  986. readonly isChildPositionAllowed: boolean;
  987. isLocked(): boolean;
  988. lock(): boolean;
  989. layoutDirtyOnPropertyChangedMask: any;
  990. private _isLocked;
  991. }
  992. class CanvasLayoutEngine extends LayoutEngineBase {
  993. private static _singleton;
  994. static readonly Singleton: CanvasLayoutEngine;
  995. constructor();
  996. updateLayout(prim: Prim2DBase): void;
  997. private _doUpdate(prim);
  998. readonly isChildPositionAllowed: boolean;
  999. }
  1000. class StackPanelLayoutEngine extends LayoutEngineBase {
  1001. constructor();
  1002. static readonly Horizontal: StackPanelLayoutEngine;
  1003. static readonly Vertical: StackPanelLayoutEngine;
  1004. private static _horizontal;
  1005. private static _vertical;
  1006. isHorizontal: boolean;
  1007. private _isHorizontal;
  1008. private static stackPanelLayoutArea;
  1009. private static dstOffset;
  1010. private static dstArea;
  1011. private static computeCounter;
  1012. updateLayout(prim: Prim2DBase): void;
  1013. readonly isChildPositionAllowed: boolean;
  1014. }
  1015. /**
  1016. * GridData is used specify what row(s) and column(s) a primitive is placed in when its parent is using a Grid Panel Layout.
  1017. */
  1018. class GridData implements ILayoutData {
  1019. /**
  1020. * the row number of the grid
  1021. **/
  1022. row: number;
  1023. /**
  1024. * the column number of the grid
  1025. **/
  1026. column: number;
  1027. /**
  1028. * the number of rows a primitive will occupy
  1029. **/
  1030. rowSpan: number;
  1031. /**
  1032. * the number of columns a primitive will occupy
  1033. **/
  1034. columnSpan: number;
  1035. /**
  1036. * Create a Grid Data that describes where a primitive will be placed in a Grid Panel Layout.
  1037. * @param row the row number of the grid
  1038. * @param column the column number of the grid
  1039. * @param rowSpan the number of rows a primitive will occupy
  1040. * @param columnSpan the number of columns a primitive will occupy
  1041. **/
  1042. constructor(row: number, column: number, rowSpan?: number, columnSpan?: number);
  1043. }
  1044. class GridPanelLayoutEngine extends LayoutEngineBase {
  1045. constructor(settings: {
  1046. rows: [{
  1047. height: string;
  1048. }];
  1049. columns: [{
  1050. width: string;
  1051. }];
  1052. });
  1053. private _rows;
  1054. private _columns;
  1055. private _children;
  1056. private _rowBottoms;
  1057. private _columnLefts;
  1058. private _rowHeights;
  1059. private _columnWidths;
  1060. private static dstOffset;
  1061. private static dstArea;
  1062. private static dstAreaPos;
  1063. updateLayout(prim: Prim2DBase): void;
  1064. readonly isChildPositionAllowed: boolean;
  1065. private _getMaxChildHeightInRow(rowNum);
  1066. private _getMaxChildWidthInColumn(colNum);
  1067. private _updateGrid(prim);
  1068. }
  1069. }
  1070. declare module BABYLON {
  1071. /**
  1072. * This interface is used to implement a lockable instance pattern.
  1073. * Classes that implements it may be locked at any time, making their content immutable from now on.
  1074. * You also can query if a given instance is locked or not.
  1075. * This allow instances to be shared among several 'consumers'.
  1076. */
  1077. interface ILockable {
  1078. /**
  1079. * Query the lock state
  1080. * @returns returns true if the object is locked and immutable, false if it's not
  1081. */
  1082. isLocked(): boolean;
  1083. /**
  1084. * A call to this method will definitely lock the instance, making its content immutable
  1085. * @returns the previous lock state of the object. so if true is returned the object were already locked and this method does nothing, if false is returned it means the object wasn't locked and this call locked it for good.
  1086. */
  1087. lock(): boolean;
  1088. }
  1089. /**
  1090. * This interface defines the IBrush2D contract.
  1091. * Classes implementing a new type of Brush2D must implement this interface
  1092. */
  1093. interface IBrush2D extends ILockable {
  1094. /**
  1095. * Define if the brush will use transparency / alpha blending
  1096. * @returns true if the brush use transparency
  1097. */
  1098. isTransparent(): boolean;
  1099. /**
  1100. * It is critical for each instance of a given Brush2D type to return a unique string that identifies it because the Border instance will certainly be part of the computed ModelKey for a given Primitive
  1101. * @returns A string identifier that uniquely identify the instance
  1102. */
  1103. toString(): string;
  1104. }
  1105. /**
  1106. * Base class implementing the ILocable interface.
  1107. * The particularity of this class is to call the protected onLock() method when the instance is about to be locked for good.
  1108. */
  1109. class LockableBase implements ILockable {
  1110. isLocked(): boolean;
  1111. private _isLocked;
  1112. lock(): boolean;
  1113. /**
  1114. * Protected handler that will be called when the instance is about to be locked.
  1115. */
  1116. protected onLock(): void;
  1117. }
  1118. class SolidColorBrush2D extends LockableBase implements IBrush2D {
  1119. constructor(color: Color4, lock?: boolean);
  1120. /**
  1121. * Return true if the brush is transparent, false if it's totally opaque
  1122. */
  1123. isTransparent(): boolean;
  1124. /**
  1125. * The color used by this instance to render
  1126. * @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.
  1127. */
  1128. color: Color4;
  1129. /**
  1130. * Return a unique identifier of the instance, which is simply the hexadecimal representation (CSS Style) of the solid color.
  1131. */
  1132. toString(): string;
  1133. private _color;
  1134. }
  1135. class GradientColorBrush2D extends LockableBase implements IBrush2D {
  1136. constructor(color1: Color4, color2: Color4, translation?: Vector2, rotation?: number, scale?: number, lock?: boolean);
  1137. /**
  1138. * Return true if the brush is transparent, false if it's totally opaque
  1139. */
  1140. isTransparent(): boolean;
  1141. /**
  1142. * First color, the blend will start from this color
  1143. */
  1144. color1: Color4;
  1145. /**
  1146. * Second color, the blend will end to this color
  1147. */
  1148. color2: Color4;
  1149. /**
  1150. * Translation vector to apply on the blend
  1151. * Default is [0;0]
  1152. */
  1153. translation: Vector2;
  1154. /**
  1155. * Rotation in radian to apply to the brush
  1156. * Default direction of the brush is vertical, you can change this using this property.
  1157. * Default is 0.
  1158. */
  1159. rotation: number;
  1160. /**
  1161. * Scale factor to apply to the gradient.
  1162. * Default is 1: no scale.
  1163. */
  1164. scale: number;
  1165. /**
  1166. * Return a string describing the brush
  1167. */
  1168. toString(): string;
  1169. /**
  1170. * Build a unique key string for the given parameters
  1171. */
  1172. static BuildKey(color1: Color4, color2: Color4, translation: Vector2, rotation: number, scale: number): string;
  1173. private _color1;
  1174. private _color2;
  1175. private _translation;
  1176. private _rotation;
  1177. private _scale;
  1178. }
  1179. }
  1180. declare module BABYLON {
  1181. class Prim2DClassInfo {
  1182. }
  1183. class Prim2DPropInfo {
  1184. static PROPKIND_MODEL: number;
  1185. static PROPKIND_INSTANCE: number;
  1186. static PROPKIND_DYNAMIC: number;
  1187. id: number;
  1188. flagId: number;
  1189. kind: number;
  1190. name: string;
  1191. dirtyBoundingInfo: boolean;
  1192. dirtyParentBoundingInfo: boolean;
  1193. typeLevelCompare: boolean;
  1194. bindingMode: number;
  1195. bindingUpdateSourceTrigger: number;
  1196. }
  1197. class ClassTreeInfo<TClass, TProp> {
  1198. constructor(baseClass: ClassTreeInfo<TClass, TProp>, type: Object, classContentFactory: (base: TClass) => TClass);
  1199. readonly classContent: TClass;
  1200. readonly type: Object;
  1201. readonly levelContent: StringDictionary<TProp>;
  1202. readonly fullContent: StringDictionary<TProp>;
  1203. getLevelOf(type: Object): ClassTreeInfo<TClass, TProp>;
  1204. getOrAddType(baseType: Object, type: Object): ClassTreeInfo<TClass, TProp>;
  1205. static get<TClass, TProp>(type: Object): ClassTreeInfo<TClass, TProp>;
  1206. static getOrRegister<TClass, TProp>(type: Object, classContentFactory: (base: TClass) => TClass): ClassTreeInfo<TClass, TProp>;
  1207. private _type;
  1208. private _classContent;
  1209. private _baseClass;
  1210. private _subClasses;
  1211. private _levelContent;
  1212. private _fullContent;
  1213. private _classContentFactory;
  1214. }
  1215. class DataBinding {
  1216. /**
  1217. * Use the mode specified in the SmartProperty declaration
  1218. */
  1219. static MODE_DEFAULT: number;
  1220. /**
  1221. * Update the binding target only once when the Smart Property's value is first accessed
  1222. */
  1223. static MODE_ONETIME: number;
  1224. /**
  1225. * Update the smart property when the source changes.
  1226. * The source won't be updated if the smart property value is set.
  1227. */
  1228. static MODE_ONEWAY: number;
  1229. /**
  1230. * Only update the source when the target's data is changing.
  1231. */
  1232. static MODE_ONEWAYTOSOURCE: number;
  1233. /**
  1234. * Update the bind target when the source changes and update the source when the Smart Property value is set.
  1235. */
  1236. static MODE_TWOWAY: number;
  1237. /**
  1238. * Use the Update Source Trigger defined in the SmartProperty declaration
  1239. */
  1240. static UPDATESOURCETRIGGER_DEFAULT: number;
  1241. /**
  1242. * Update the source as soon as the Smart Property has a value change
  1243. */
  1244. static UPDATESOURCETRIGGER_PROPERTYCHANGED: number;
  1245. /**
  1246. * Update the source when the binding target loses focus
  1247. */
  1248. static UPDATESOURCETRIGGER_LOSTFOCUS: number;
  1249. /**
  1250. * Update the source will be made by explicitly calling the UpdateFromDataSource method
  1251. */
  1252. static UPDATESOURCETRIGGER_EXPLICIT: number;
  1253. constructor();
  1254. /**
  1255. * Provide a callback that will convert the value obtained by the Data Binding to the type of the SmartProperty it's bound to.
  1256. * If no value are set, then it's assumed that the sourceValue is of the same type as the SmartProperty's one.
  1257. * 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.
  1258. * @param sourceValue the source object retrieve by the Data Binding mechanism
  1259. * @returns the object of a compatible type with the SmartProperty it's bound to
  1260. */
  1261. converter: (sourceValue: any) => any;
  1262. /**
  1263. * 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
  1264. */
  1265. mode: number;
  1266. /**
  1267. * You can override the Data Source object with this member which is the Id of a uiElement existing in the UI Logical tree.
  1268. * If not set and source no set too, then the dataSource property will be used.
  1269. */
  1270. uiElementId: string;
  1271. /**
  1272. * You can override the Data Source object with this member which is the source object to use directly.
  1273. * If not set and uiElement no set too, then the dataSource property of the SmartPropertyBase object will be used.
  1274. */
  1275. dataSource: IPropertyChanged;
  1276. /**
  1277. * The path & name of the property to get from the source object.
  1278. * 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.
  1279. * If nothing is set then the source object will be used.
  1280. * 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.
  1281. * 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.
  1282. */
  1283. propertyPathName: string;
  1284. /**
  1285. * 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}`
  1286. */
  1287. stringFormat: (value: any) => string;
  1288. /**
  1289. * 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.
  1290. */
  1291. updateSourceTrigger: number;
  1292. canUpdateTarget(resetUpdateCounter: boolean): boolean;
  1293. updateTarget(): void;
  1294. _storeBoundValue(watcher: SmartPropertyBase, value: any): void;
  1295. private _getActualDataSource();
  1296. _registerDataSource(updateTarget: boolean): void;
  1297. _unregisterDataSource(): void;
  1298. /**
  1299. * The PropInfo of the property the binding is bound to
  1300. */
  1301. _boundTo: Prim2DPropInfo;
  1302. _owner: SmartPropertyBase;
  1303. private _converter;
  1304. private _mode;
  1305. private _uiElementId;
  1306. private _dataSource;
  1307. _currentDataSource: IPropertyChanged;
  1308. private _propertyPathName;
  1309. private _stringFormat;
  1310. private _updateSourceTrigger;
  1311. private _updateCounter;
  1312. }
  1313. abstract class SmartPropertyBase extends PropertyChangedBase {
  1314. constructor();
  1315. readonly disposeObservable: Observable<SmartPropertyBase>;
  1316. /**
  1317. * Check if the object is disposed or not.
  1318. * @returns true if the object is dispose, false otherwise.
  1319. */
  1320. readonly isDisposed: boolean;
  1321. /**
  1322. * Disposable pattern, this method must be overloaded by derived types in order to clean up hardware related resources.
  1323. * @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.
  1324. */
  1325. dispose(): boolean;
  1326. /**
  1327. * Check if a given set of properties are dirty or not.
  1328. * @param flags a ORed combination of Prim2DPropInfo.flagId values
  1329. * @return true if at least one property is dirty, false if none of them are.
  1330. */
  1331. checkPropertiesDirty(flags: number): boolean;
  1332. /**
  1333. * Clear a given set of properties.
  1334. * @param flags a ORed combination of Prim2DPropInfo.flagId values
  1335. * @return the new set of property still marked as dirty
  1336. */
  1337. protected clearPropertiesDirty(flags: number): number;
  1338. _resetPropertiesDirty(): void;
  1339. /**
  1340. * Add an externally attached data from its key.
  1341. * This method call will fail and return false, if such key already exists.
  1342. * If you don't care and just want to get the data no matter what, use the more convenient getOrAddExternalDataWithFactory() method.
  1343. * @param key the unique key that identifies the data
  1344. * @param data the data object to associate to the key for this Engine instance
  1345. * @return true if no such key were already present and the data was added successfully, false otherwise
  1346. */
  1347. addExternalData<T>(key: string, data: T): boolean;
  1348. /**
  1349. * Get an externally attached data from its key
  1350. * @param key the unique key that identifies the data
  1351. * @return the associated data, if present (can be null), or undefined if not present
  1352. */
  1353. getExternalData<T>(key: string): T;
  1354. /**
  1355. * Get an externally attached data from its key, create it using a factory if it's not already present
  1356. * @param key the unique key that identifies the data
  1357. * @param factory the factory that will be called to create the instance if and only if it doesn't exists
  1358. * @return the associated data, can be null if the factory returned null.
  1359. */
  1360. getOrAddExternalDataWithFactory<T>(key: string, factory: (k: string) => T): T;
  1361. /**
  1362. * Remove an externally attached data from the Engine instance
  1363. * @param key the unique key that identifies the data
  1364. * @return true if the data was successfully removed, false if it doesn't exist
  1365. */
  1366. removeExternalData(key: any): boolean;
  1367. static _hookProperty<T>(propId: number, piStore: (pi: Prim2DPropInfo) => void, kind: number, settings?: {
  1368. bindingMode?: number;
  1369. bindingUpdateSourceTrigger?: number;
  1370. typeLevelCompare?: boolean;
  1371. dirtyBoundingInfo?: boolean;
  1372. dirtyParentBoundingBox?: boolean;
  1373. }): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void;
  1374. private static _createPropInfo(target, propName, propId, kind, settings);
  1375. /**
  1376. * Access the dictionary of properties metadata. Only properties decorated with XXXXLevelProperty are concerned
  1377. * @returns the dictionary, the key is the property name as declared in Javascript, the value is the metadata object
  1378. */
  1379. protected readonly propDic: StringDictionary<Prim2DPropInfo>;
  1380. private static _checkUnchanged(curValue, newValue);
  1381. private static propChangedInfo;
  1382. private static propChangeGuarding;
  1383. protected _handlePropChanged<T>(curValue: T, newValue: T, propName: string, propInfo: Prim2DPropInfo, typeLevelCompare: boolean): void;
  1384. protected _triggerPropertyChanged(propInfo: Prim2DPropInfo, newValue: any): void;
  1385. /**
  1386. * Set the object from which Smart Properties using Binding will take/update their data from/to.
  1387. * 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.
  1388. */
  1389. dataSource: IPropertyChanged;
  1390. protected _getDataSource(): IPropertyChanged;
  1391. createSimpleDataBinding(propInfo: Prim2DPropInfo, propertyPathName: string, mode?: number): DataBinding;
  1392. createDataBinding(propInfo: Prim2DPropInfo, binding: DataBinding): DataBinding;
  1393. removeDataBinding(propInfo: Prim2DPropInfo): boolean;
  1394. updateFromDataSource(): void;
  1395. private _dataSource;
  1396. private _dataSourceObserver;
  1397. private _isDisposed;
  1398. private _externalData;
  1399. protected _instanceDirtyFlags: number;
  1400. private _propInfo;
  1401. _bindings: Array<DataBinding>;
  1402. private _hasBinding;
  1403. private _bindingSourceChanged;
  1404. private _disposeObservable;
  1405. }
  1406. abstract class SmartPropertyPrim extends SmartPropertyBase {
  1407. static SMARTPROPERTYPRIM_PROPCOUNT: number;
  1408. constructor();
  1409. /**
  1410. * Disposable pattern, this method must be overloaded by derived types in order to clean up hardware related resources.
  1411. * @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.
  1412. */
  1413. dispose(): boolean;
  1414. /**
  1415. * Animation array, more info: http://doc.babylonjs.com/tutorials/Animations
  1416. */
  1417. animations: Animation[];
  1418. /**
  1419. * return a unique identifier for the Canvas2D
  1420. */
  1421. readonly uid: string;
  1422. /**
  1423. * Returns as a new array populated with the Animatable used by the primitive. Must be overloaded by derived primitives.
  1424. * Look at Sprite2D for more information
  1425. */
  1426. getAnimatables(): IAnimatable[];
  1427. /**
  1428. * Property giving the Model Key associated to the property.
  1429. * This value is constructed from the type of the primitive and all the name/value of its properties declared with the modelLevelProperty decorator
  1430. * @returns the model key string.
  1431. */
  1432. readonly modelKey: string;
  1433. /**
  1434. * States if the Primitive is dirty and should be rendered again next time.
  1435. * @returns true is dirty, false otherwise
  1436. */
  1437. readonly isDirty: boolean;
  1438. protected _boundingBoxDirty(): void;
  1439. protected _handlePropChanged<T>(curValue: T, newValue: T, propName: string, propInfo: Prim2DPropInfo, typeLevelCompare: boolean): void;
  1440. protected onPrimitivePropertyDirty(propFlagId: number): void;
  1441. protected handleGroupChanged(prop: Prim2DPropInfo): void;
  1442. _resetPropertiesDirty(): void;
  1443. /**
  1444. * Retrieve the boundingInfo for this Primitive, computed based on the primitive itself and NOT its children
  1445. */
  1446. readonly levelBoundingInfo: BoundingInfo2D;
  1447. /**
  1448. * This method must be overridden by a given Primitive implementation to compute its boundingInfo
  1449. */
  1450. protected updateLevelBoundingInfo(): boolean;
  1451. /**
  1452. * Property method called when the Primitive becomes dirty
  1453. */
  1454. protected onPrimBecomesDirty(): void;
  1455. /**
  1456. * Check if a given flag is set
  1457. * @param flag the flag value
  1458. * @return true if set, false otherwise
  1459. */
  1460. _isFlagSet(flag: number): boolean;
  1461. /**
  1462. * Check if all given flags are set
  1463. * @param flags the flags ORed
  1464. * @return true if all the flags are set, false otherwise
  1465. */
  1466. _areAllFlagsSet(flags: number): boolean;
  1467. /**
  1468. * Check if at least one flag of the given flags is set
  1469. * @param flags the flags ORed
  1470. * @return true if at least one flag is set, false otherwise
  1471. */
  1472. _areSomeFlagsSet(flags: number): boolean;
  1473. /**
  1474. * Clear the given flags
  1475. * @param flags the flags to clear
  1476. */
  1477. _clearFlags(flags: number): void;
  1478. /**
  1479. * Set the given flags to true state
  1480. * @param flags the flags ORed to set
  1481. * @return the flags state before this call
  1482. */
  1483. _setFlags(flags: number): number;
  1484. /**
  1485. * Change the state of the given flags
  1486. * @param flags the flags ORed to change
  1487. * @param state true to set them, false to clear them
  1488. */
  1489. _changeFlags(flags: number, state: boolean): void;
  1490. _getFlagsDebug(flags: number): string;
  1491. static flagNoPartOfLayout: number;
  1492. static flagLevelBoundingInfoDirty: number;
  1493. static flagModelDirty: number;
  1494. static flagLayoutDirty: number;
  1495. static flagLevelVisible: number;
  1496. static flagBoundingInfoDirty: number;
  1497. static flagIsPickable: number;
  1498. static flagIsVisible: number;
  1499. static flagVisibilityChanged: number;
  1500. static flagPositioningDirty: number;
  1501. static flagTrackedGroup: number;
  1502. static flagWorldCacheChanged: number;
  1503. static flagChildrenFlatZOrder: number;
  1504. static flagZOrderDirty: number;
  1505. static flagActualOpacityDirty: number;
  1506. static flagPrimInDirtyList: number;
  1507. static flagIsContainer: number;
  1508. static flagNeedRefresh: number;
  1509. static flagActualScaleDirty: number;
  1510. static flagDontInheritParentScale: number;
  1511. static flagGlobalTransformDirty: number;
  1512. static flagLayoutBoundingInfoDirty: number;
  1513. static flagCollisionActor: number;
  1514. static flagModelUpdate: number;
  1515. static flagLocalTransformDirty: number;
  1516. static flagUsePositioning: number;
  1517. static flagComputingPositioning: number;
  1518. static flagAlignPrimitive: number;
  1519. private _uid;
  1520. private _flags;
  1521. private _modelKey;
  1522. protected _levelBoundingInfo: BoundingInfo2D;
  1523. protected _boundingInfo: BoundingInfo2D;
  1524. protected _layoutBoundingInfo: BoundingInfo2D;
  1525. }
  1526. function dependencyProperty<T>(propId: number, piStore: (pi: Prim2DPropInfo) => void, mode?: number, updateSourceTrigger?: number): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void;
  1527. function modelLevelProperty<T>(propId: number, piStore: (pi: Prim2DPropInfo) => void, typeLevelCompare?: boolean, dirtyBoundingInfo?: boolean, dirtyParentBoundingBox?: boolean): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void;
  1528. function instanceLevelProperty<T>(propId: number, piStore: (pi: Prim2DPropInfo) => void, typeLevelCompare?: boolean, dirtyBoundingInfo?: boolean, dirtyParentBoundingBox?: boolean): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void;
  1529. function dynamicLevelProperty<T>(propId: number, piStore: (pi: Prim2DPropInfo) => void, typeLevelCompare?: boolean, dirtyBoundingInfo?: boolean, dirtyParentBoundingBox?: boolean): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void;
  1530. }
  1531. declare module BABYLON {
  1532. class PrepareRender2DContext {
  1533. constructor();
  1534. /**
  1535. * True if the primitive must be refreshed no matter what
  1536. * This mode is needed because sometimes the primitive doesn't change by itself, but external changes make a refresh of its InstanceData necessary
  1537. */
  1538. forceRefreshPrimitive: boolean;
  1539. }
  1540. class Render2DContext {
  1541. constructor(renderMode: number);
  1542. /**
  1543. * Define which render Mode should be used to render the primitive: one of Render2DContext.RenderModeXxxx property
  1544. */
  1545. readonly renderMode: number;
  1546. /**
  1547. * If true hardware instancing is supported and must be used for the rendering. The groupInfoPartData._partBuffer must be used.
  1548. * If false rendering on a per primitive basis must be made. The following properties must be used
  1549. * - groupInfoPartData._partData: contains the primitive instances data to render
  1550. * - partDataStartIndex: the index into instanceArrayData of the first instance to render.
  1551. * - partDataCount: the number of primitive to render
  1552. */
  1553. useInstancing: boolean;
  1554. /**
  1555. * If specified, must take precedence from the groupInfoPartData. partIndex is the same as groupInfoPardData
  1556. */
  1557. instancedBuffers: WebGLBuffer[];
  1558. /**
  1559. * To use when instancedBuffers is specified, gives the count of instances to draw
  1560. */
  1561. instancesCount: number;
  1562. /**
  1563. * Contains the data related to the primitives instances to render
  1564. */
  1565. groupInfoPartData: GroupInfoPartData[];
  1566. /**
  1567. * The index into groupInfoPartData._partData of the first primitive to render. This is an index, not an offset: it represent the nth primitive which is the first to render.
  1568. */
  1569. partDataStartIndex: number;
  1570. /**
  1571. * The exclusive end index, you have to render the primitive instances until you reach this one, but don't render this one!
  1572. */
  1573. partDataEndIndex: number;
  1574. /**
  1575. * The set of primitives to render is opaque.
  1576. * This is the first rendering pass. All Opaque primitives are rendered. Depth Compare and Write are both enabled.
  1577. */
  1578. static readonly RenderModeOpaque: number;
  1579. /**
  1580. * The set of primitives to render is using Alpha Test (aka masking).
  1581. * 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.
  1582. */
  1583. static readonly RenderModeAlphaTest: number;
  1584. /**
  1585. * The set of primitives to render is transparent.
  1586. * 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.
  1587. */
  1588. static readonly RenderModeTransparent: number;
  1589. private static _renderModeOpaque;
  1590. private static _renderModeAlphaTest;
  1591. private static _renderModeTransparent;
  1592. private _renderMode;
  1593. }
  1594. /**
  1595. * This class store information for the pointerEventObservable Observable.
  1596. * 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.
  1597. */
  1598. class PrimitivePointerInfo {
  1599. private static _pointerOver;
  1600. private static _pointerEnter;
  1601. private static _pointerDown;
  1602. private static _pointerMouseWheel;
  1603. private static _pointerMove;
  1604. private static _pointerUp;
  1605. private static _pointerOut;
  1606. private static _pointerLeave;
  1607. private static _pointerGotCapture;
  1608. private static _pointerLostCapture;
  1609. private static _mouseWheelPrecision;
  1610. /**
  1611. * This event type is raised when a pointing device is moved into the hit test boundaries of a primitive.
  1612. * Bubbles: yes
  1613. */
  1614. static readonly PointerOver: number;
  1615. /**
  1616. * This event type is raised when a pointing device is moved into the hit test boundaries of a primitive or one of its descendants.
  1617. * Bubbles: no
  1618. */
  1619. static readonly PointerEnter: number;
  1620. /**
  1621. * 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.
  1622. * Bubbles: yes
  1623. */
  1624. static readonly PointerDown: number;
  1625. /**
  1626. * This event type is raised when the pointer is a mouse and it's wheel is rolling
  1627. * Bubbles: yes
  1628. */
  1629. static readonly PointerMouseWheel: number;
  1630. /**
  1631. * 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.
  1632. * Bubbles: yes
  1633. */
  1634. static readonly PointerMove: number;
  1635. /**
  1636. * 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.
  1637. * Bubbles: yes
  1638. */
  1639. static readonly PointerUp: number;
  1640. /**
  1641. * This event type is raised when a pointing device is moved out of the hit test the boundaries of a primitive.
  1642. * Bubbles: yes
  1643. */
  1644. static readonly PointerOut: number;
  1645. /**
  1646. * This event type is raised when a pointing device is moved out of the hit test boundaries of a primitive and all its descendants.
  1647. * Bubbles: no
  1648. */
  1649. static readonly PointerLeave: number;
  1650. /**
  1651. * 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.
  1652. * Bubbles: yes
  1653. */
  1654. static readonly PointerGotCapture: number;
  1655. /**
  1656. * This event type is raised after pointer capture is released for a pointer.
  1657. * Bubbles: yes
  1658. */
  1659. static readonly PointerLostCapture: number;
  1660. static readonly MouseWheelPrecision: number;
  1661. /**
  1662. * Event Type, one of the static PointerXXXX property defined above (PrimitivePointerInfo.PointerOver to PrimitivePointerInfo.PointerLostCapture)
  1663. */
  1664. eventType: number;
  1665. /**
  1666. * Position of the pointer relative to the bottom/left of the Canvas
  1667. */
  1668. canvasPointerPos: Vector2;
  1669. /**
  1670. * Position of the pointer relative to the bottom/left of the primitive that registered the Observer
  1671. */
  1672. primitivePointerPos: Vector2;
  1673. /**
  1674. * The primitive where the event was initiated first (in case of bubbling)
  1675. */
  1676. relatedTarget: Prim2DBase;
  1677. /**
  1678. * Position of the pointer relative to the bottom/left of the relatedTarget
  1679. */
  1680. relatedTargetPointerPos: Vector2;
  1681. /**
  1682. * An observable can set this property to true to stop bubbling on the upper levels
  1683. */
  1684. cancelBubble: boolean;
  1685. /**
  1686. * True if the Control keyboard key is down
  1687. */
  1688. ctrlKey: boolean;
  1689. /**
  1690. * true if the Shift keyboard key is down
  1691. */
  1692. shiftKey: boolean;
  1693. /**
  1694. * true if the Alt keyboard key is down
  1695. */
  1696. altKey: boolean;
  1697. /**
  1698. * true if the Meta keyboard key is down
  1699. */
  1700. metaKey: boolean;
  1701. /**
  1702. * For button, buttons, refer to https://www.w3.org/TR/pointerevents/#button-states
  1703. */
  1704. button: number;
  1705. /**
  1706. * For button, buttons, refer to https://www.w3.org/TR/pointerevents/#button-states
  1707. */
  1708. buttons: number;
  1709. /**
  1710. * The amount of mouse wheel rolled
  1711. */
  1712. mouseWheelDelta: number;
  1713. /**
  1714. * Id of the Pointer involved in the event
  1715. */
  1716. pointerId: number;
  1717. width: number;
  1718. height: number;
  1719. presssure: number;
  1720. tilt: Vector2;
  1721. /**
  1722. * true if the involved pointer is captured for a particular primitive, false otherwise.
  1723. */
  1724. isCaptured: boolean;
  1725. constructor();
  1726. updateRelatedTarget(prim: Prim2DBase, primPointerPos: Vector2): void;
  1727. static getEventTypeName(mask: number): string;
  1728. }
  1729. /**
  1730. * Defines the horizontal and vertical alignment information for a Primitive.
  1731. */
  1732. class PrimitiveAlignment {
  1733. constructor(changeCallback?: () => void);
  1734. /**
  1735. * Alignment is made relative to the left edge of the Primitive. Valid for horizontal alignment only.
  1736. */
  1737. static readonly AlignLeft: number;
  1738. /**
  1739. * Alignment is made relative to the top edge of the Primitive. Valid for vertical alignment only.
  1740. */
  1741. static readonly AlignTop: number;
  1742. /**
  1743. * Alignment is made relative to the right edge of the Primitive. Valid for horizontal alignment only.
  1744. */
  1745. static readonly AlignRight: number;
  1746. /**
  1747. * Alignment is made relative to the bottom edge of the Primitive. Valid for vertical alignment only.
  1748. */
  1749. static readonly AlignBottom: number;
  1750. /**
  1751. * Alignment is made to center the content from equal distance to the opposite edges of the Primitive
  1752. */
  1753. static readonly AlignCenter: number;
  1754. /**
  1755. * The content is stretched toward the opposite edges of the Primitive
  1756. */
  1757. static readonly AlignStretch: number;
  1758. private static _AlignLeft;
  1759. private static _AlignTop;
  1760. private static _AlignRight;
  1761. private static _AlignBottom;
  1762. private static _AlignCenter;
  1763. private static _AlignStretch;
  1764. /**
  1765. * Get/set the horizontal alignment. Use one of the AlignXXX static properties of this class
  1766. */
  1767. horizontal: number;
  1768. /**
  1769. * Get/set the vertical alignment. Use one of the AlignXXX static properties of this class
  1770. */
  1771. vertical: number;
  1772. private onChangeCallback();
  1773. private _changedCallback;
  1774. private _horizontal;
  1775. private _vertical;
  1776. /**
  1777. * Set the horizontal alignment from a string value.
  1778. * @param text can be either: 'left','right','center','stretch'
  1779. */
  1780. setHorizontal(text: string): void;
  1781. /**
  1782. * Set the vertical alignment from a string value.
  1783. * @param text can be either: 'top','bottom','center','stretch'
  1784. */
  1785. setVertical(text: string): void;
  1786. /**
  1787. * Set the horizontal and or vertical alignments from a string value.
  1788. * @param text can be: [<h:|horizontal:><left|right|center|stretch>], [<v:|vertical:><top|bottom|center|stretch>]
  1789. */
  1790. fromString(value: string): void;
  1791. copyFrom(pa: PrimitiveAlignment): void;
  1792. clone(): PrimitiveAlignment;
  1793. readonly isDefault: boolean;
  1794. }
  1795. /**
  1796. * Stores information about a Primitive that was intersected
  1797. */
  1798. class PrimitiveIntersectedInfo {
  1799. prim: Prim2DBase;
  1800. intersectionLocation: Vector2;
  1801. constructor(prim: Prim2DBase, intersectionLocation: Vector2);
  1802. }
  1803. /**
  1804. * Define a thickness toward every edges of a Primitive to allow margin and padding.
  1805. * The thickness can be expressed as pixels, percentages, inherit the value of the parent primitive or be auto.
  1806. */
  1807. class PrimitiveThickness {
  1808. constructor(parentAccess: () => PrimitiveThickness, changedCallback?: () => void);
  1809. /**
  1810. * Set the thickness from a string value
  1811. * @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.
  1812. * Values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  1813. */
  1814. fromString(thickness: string): void;
  1815. /**
  1816. * Set the thickness from multiple string
  1817. * Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  1818. * @param top the top thickness to set
  1819. * @param left the left thickness to set
  1820. * @param right the right thickness to set
  1821. * @param bottom the bottom thickness to set
  1822. */
  1823. fromStrings(top: string, left: string, right: string, bottom: string): PrimitiveThickness;
  1824. /**
  1825. * Set the thickness from pixel values
  1826. * @param top the top thickness in pixels to set
  1827. * @param left the left thickness in pixels to set
  1828. * @param right the right thickness in pixels to set
  1829. * @param bottom the bottom thickness in pixels to set
  1830. */
  1831. fromPixels(top: number, left: number, right: number, bottom: number): PrimitiveThickness;
  1832. /**
  1833. * Apply the same pixel value to all edges
  1834. * @param margin the value to set, in pixels.
  1835. */
  1836. fromUniformPixels(margin: number): PrimitiveThickness;
  1837. copyFrom(pt: PrimitiveThickness): void;
  1838. /**
  1839. * Set all edges in auto
  1840. */
  1841. auto(): PrimitiveThickness;
  1842. private _clear();
  1843. private _extractString(value, emitChanged);
  1844. private _setStringValue(value, index, emitChanged);
  1845. private _setPixels(value, index, emitChanged);
  1846. private _setPercentage(value, index, emitChanged);
  1847. private _getStringValue(index);
  1848. private _isType(index, type);
  1849. private _getType(index, processInherit);
  1850. private _setType(index, type);
  1851. setTop(value: number | string): void;
  1852. setLeft(value: number | string): void;
  1853. setRight(value: number | string): void;
  1854. setBottom(value: number | string): void;
  1855. /**
  1856. * Get/set the top thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  1857. */
  1858. top: string;
  1859. /**
  1860. * Get/set the left thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  1861. */
  1862. left: string;
  1863. /**
  1864. * Get/set the right thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  1865. */
  1866. right: string;
  1867. /**
  1868. * Get/set the bottom thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  1869. */
  1870. bottom: string;
  1871. /**
  1872. * Get/set the top thickness in pixel.
  1873. */
  1874. topPixels: number;
  1875. /**
  1876. * Get/set the left thickness in pixel.
  1877. */
  1878. leftPixels: number;
  1879. /**
  1880. * Get/set the right thickness in pixel.
  1881. */
  1882. rightPixels: number;
  1883. /**
  1884. * Get/set the bottom thickness in pixel.
  1885. */
  1886. bottomPixels: number;
  1887. /**
  1888. * Get/set the top thickness in percentage.
  1889. * The get will return a valid value only if the edge type is percentage.
  1890. * The Set will change the edge mode if needed
  1891. */
  1892. topPercentage: number;
  1893. /**
  1894. * Get/set the left thickness in percentage.
  1895. * The get will return a valid value only if the edge mode is percentage.
  1896. * The Set will change the edge mode if needed
  1897. */
  1898. leftPercentage: number;
  1899. /**
  1900. * Get/set the right thickness in percentage.
  1901. * The get will return a valid value only if the edge mode is percentage.
  1902. * The Set will change the edge mode if needed
  1903. */
  1904. rightPercentage: number;
  1905. /**
  1906. * Get/set the bottom thickness in percentage.
  1907. * The get will return a valid value only if the edge mode is percentage.
  1908. * The Set will change the edge mode if needed
  1909. */
  1910. bottomPercentage: number;
  1911. /**
  1912. * Get/set the top mode. The setter shouldn't be used, other setters with value should be preferred
  1913. */
  1914. topMode: number;
  1915. /**
  1916. * Get/set the left mode. The setter shouldn't be used, other setters with value should be preferred
  1917. */
  1918. leftMode: number;
  1919. /**
  1920. * Get/set the right mode. The setter shouldn't be used, other setters with value should be preferred
  1921. */
  1922. rightMode: number;
  1923. /**
  1924. * Get/set the bottom mode. The setter shouldn't be used, other setters with value should be preferred
  1925. */
  1926. bottomMode: number;
  1927. readonly isDefault: boolean;
  1928. private _parentAccess;
  1929. private _changedCallback;
  1930. private _pixels;
  1931. private _percentages;
  1932. private _flags;
  1933. static Auto: number;
  1934. static Inherit: number;
  1935. static Percentage: number;
  1936. static Pixel: number;
  1937. static ComputeH: number;
  1938. static ComputeV: number;
  1939. static ComputeAll: number;
  1940. private _computePixels(index, sourceArea, emitChanged);
  1941. private onChangeCallback();
  1942. /**
  1943. * Compute the positioning/size of an area considering the thickness of this object and a given alignment
  1944. * @param sourceArea the source area where the content must be sized/positioned
  1945. * @param contentSize the content size to position/resize
  1946. * @param alignment the alignment setting
  1947. * @param dstOffset the position of the content, x, y, z, w are left, bottom, right, top
  1948. * @param dstArea the new size of the content
  1949. */
  1950. computeWithAlignment(sourceArea: Size, contentSize: Size, alignment: PrimitiveAlignment, contentScale: Vector2, dstOffset: Vector4, dstArea: Size, computeLayoutArea?: boolean, computeAxis?: number): void;
  1951. /**
  1952. * Compute an area and its position considering this thickness properties based on a given source area
  1953. * @param sourceArea the source area
  1954. * @param dstOffset the position of the resulting area
  1955. * @param dstArea the size of the resulting area
  1956. */
  1957. compute(sourceArea: Size, dstOffset: Vector4, dstArea: Size, computeLayoutArea?: boolean): void;
  1958. /**
  1959. * Compute an area considering this thickness properties based on a given source area
  1960. * @param sourceArea the source area
  1961. * @param result the resulting area
  1962. */
  1963. computeArea(sourceArea: Size, sourceScale: Vector2, result: Size): void;
  1964. enlarge(sourceArea: Size, sourceScale: Vector2, dstOffset: Vector4, enlargedArea: Size): void;
  1965. }
  1966. /**
  1967. * Main class used for the Primitive Intersection API
  1968. */
  1969. class IntersectInfo2D {
  1970. constructor();
  1971. /**
  1972. * Set the pick position, relative to the primitive where the intersection test is made
  1973. */
  1974. pickPosition: Vector2;
  1975. /**
  1976. * If true the intersection will stop at the first hit, if false all primitives will be tested and the intersectedPrimitives array will be filled accordingly (false default)
  1977. */
  1978. findFirstOnly: boolean;
  1979. /**
  1980. * If true the intersection test will also be made on hidden primitive (false default)
  1981. */
  1982. intersectHidden: boolean;
  1983. _globalPickPosition: Vector2;
  1984. _localPickPosition: Vector2;
  1985. /**
  1986. * The topmost intersected primitive
  1987. */
  1988. topMostIntersectedPrimitive: PrimitiveIntersectedInfo;
  1989. /**
  1990. * The array containing all intersected primitive, in no particular order.
  1991. */
  1992. intersectedPrimitives: Array<PrimitiveIntersectedInfo>;
  1993. /**
  1994. * true if at least one primitive intersected during the test
  1995. */
  1996. readonly isIntersected: boolean;
  1997. isPrimIntersected(prim: Prim2DBase): Vector2;
  1998. _exit(firstLevel: boolean): void;
  1999. }
  2000. class Prim2DBase extends SmartPropertyPrim {
  2001. static PRIM2DBASE_PROPCOUNT: number;
  2002. static _bigInt: number;
  2003. constructor(settings: {
  2004. parent?: Prim2DBase;
  2005. id?: string;
  2006. children?: Array<Prim2DBase>;
  2007. position?: Vector2;
  2008. x?: number;
  2009. y?: number;
  2010. rotation?: number;
  2011. scale?: number;
  2012. scaleX?: number;
  2013. scaleY?: number;
  2014. dontInheritParentScale?: boolean;
  2015. alignToPixel?: boolean;
  2016. opacity?: number;
  2017. zOrder?: number;
  2018. origin?: Vector2;
  2019. layoutEngine?: LayoutEngineBase | string;
  2020. isVisible?: boolean;
  2021. isPickable?: boolean;
  2022. isContainer?: boolean;
  2023. childrenFlatZOrder?: boolean;
  2024. levelCollision?: boolean;
  2025. deepCollision?: boolean;
  2026. layoutData?: ILayoutData;
  2027. marginTop?: number | string;
  2028. marginLeft?: number | string;
  2029. marginRight?: number | string;
  2030. marginBottom?: number | string;
  2031. margin?: number | string;
  2032. marginHAlignment?: number;
  2033. marginVAlignment?: number;
  2034. marginAlignment?: string;
  2035. paddingTop?: number | string;
  2036. paddingLeft?: number | string;
  2037. paddingRight?: number | string;
  2038. paddingBottom?: number | string;
  2039. padding?: number | string;
  2040. });
  2041. /**
  2042. * Return the ChangedDictionary observable of the StringDictionary containing the primitives intersecting with this one
  2043. */
  2044. readonly intersectWithObservable: Observable<DictionaryChanged<ActorInfoBase>>;
  2045. /**
  2046. * Return the ObservableStringDictionary containing all the primitives intersecting with this one.
  2047. * The key is the primitive uid, the value is the ActorInfo object
  2048. * @returns {}
  2049. */
  2050. readonly intersectWith: ObservableStringDictionary<ActorInfoBase>;
  2051. readonly actionManager: ActionManager;
  2052. /**
  2053. * From 'this' primitive, traverse up (from parent to parent) until the given predicate is true
  2054. * @param predicate the predicate to test on each parent
  2055. * @return the first primitive where the predicate was successful
  2056. */
  2057. traverseUp(predicate: (p: Prim2DBase) => boolean): Prim2DBase;
  2058. /**
  2059. * Retrieve the owner Canvas2D
  2060. */
  2061. readonly owner: Canvas2D;
  2062. /**
  2063. * Get the parent primitive (can be the Canvas, only the Canvas has no parent)
  2064. */
  2065. readonly parent: Prim2DBase;
  2066. /**
  2067. * The array of direct children primitives
  2068. */
  2069. readonly children: Prim2DBase[];
  2070. /**
  2071. * The identifier of this primitive, may not be unique, it's for information purpose only
  2072. */
  2073. id: string;
  2074. /**
  2075. * Metadata of the position property
  2076. */
  2077. static positionProperty: Prim2DPropInfo;
  2078. /**
  2079. * Metadata of the left property
  2080. */
  2081. static xProperty: Prim2DPropInfo;
  2082. /**
  2083. * Metadata of the bottom property
  2084. */
  2085. static yProperty: Prim2DPropInfo;
  2086. /**
  2087. * Metadata of the actualPosition property
  2088. */
  2089. static actualPositionProperty: Prim2DPropInfo;
  2090. /**
  2091. * Metadata of the actualX (Left) property
  2092. */
  2093. static actualXProperty: Prim2DPropInfo;
  2094. /**
  2095. * Metadata of the actualY (Bottom) property
  2096. */
  2097. static actualYProperty: Prim2DPropInfo;
  2098. /**
  2099. * Metadata of the size property
  2100. */
  2101. static sizeProperty: Prim2DPropInfo;
  2102. /**
  2103. * Metadata of the width property
  2104. */
  2105. static widthProperty: Prim2DPropInfo;
  2106. /**
  2107. * Metadata of the height property
  2108. */
  2109. static heightProperty: Prim2DPropInfo;
  2110. /**
  2111. * Metadata of the rotation property
  2112. */
  2113. static rotationProperty: Prim2DPropInfo;
  2114. /**
  2115. * Metadata of the scale property
  2116. */
  2117. static scaleProperty: Prim2DPropInfo;
  2118. /**
  2119. * Metadata of the actualSize property
  2120. */
  2121. static actualSizeProperty: Prim2DPropInfo;
  2122. /**
  2123. * Metadata of the actualWidth property
  2124. */
  2125. static actualWidthProperty: Prim2DPropInfo;
  2126. /**
  2127. * Metadata of the actualHeight property
  2128. */
  2129. static actualHeightProperty: Prim2DPropInfo;
  2130. /**
  2131. * Metadata of the origin property
  2132. */
  2133. static originProperty: Prim2DPropInfo;
  2134. /**
  2135. * Metadata of the levelVisible property
  2136. */
  2137. static levelVisibleProperty: Prim2DPropInfo;
  2138. /**
  2139. * Metadata of the isVisible property
  2140. */
  2141. static isVisibleProperty: Prim2DPropInfo;
  2142. /**
  2143. * Metadata of the zOrder property
  2144. */
  2145. static zOrderProperty: Prim2DPropInfo;
  2146. /**
  2147. * Metadata of the margin property
  2148. */
  2149. static marginProperty: Prim2DPropInfo;
  2150. /**
  2151. * Metadata of the margin property
  2152. */
  2153. static paddingProperty: Prim2DPropInfo;
  2154. /**
  2155. * Metadata of the marginAlignment property
  2156. */
  2157. static marginAlignmentProperty: Prim2DPropInfo;
  2158. /**
  2159. * Metadata of the opacity property
  2160. */
  2161. static opacityProperty: Prim2DPropInfo;
  2162. /**
  2163. * Metadata of the scaleX property
  2164. */
  2165. static scaleXProperty: Prim2DPropInfo;
  2166. /**
  2167. * Metadata of the scaleY property
  2168. */
  2169. static scaleYProperty: Prim2DPropInfo;
  2170. /**
  2171. * Metadata of the actualScale property
  2172. */
  2173. static actualScaleProperty: Prim2DPropInfo;
  2174. /**
  2175. * DO NOT INVOKE for internal purpose only
  2176. */
  2177. actualPosition: Vector2;
  2178. private static _nullPosition;
  2179. private static _nullSize;
  2180. /**
  2181. * Shortcut to actualPosition.x
  2182. */
  2183. /**
  2184. * DO NOT INVOKE for internal purpose only
  2185. */
  2186. actualX: number;
  2187. /**
  2188. * Shortcut to actualPosition.y
  2189. */
  2190. /**
  2191. * DO NOT INVOKE for internal purpose only
  2192. */
  2193. actualY: number;
  2194. /**
  2195. * Position of the primitive, relative to its parent.
  2196. * BEWARE: if you change only position.x or y it won't trigger a property change and you won't have the expected behavior.
  2197. * Use this property to set a new Vector2 object, otherwise to change only the x/y use Prim2DBase.x or y properties.
  2198. * Setting this property may have no effect is specific alignment are in effect.
  2199. */
  2200. position: Vector2;
  2201. /**
  2202. * Direct access to the position.x value of the primitive
  2203. * Use this property when you only want to change one component of the position property
  2204. */
  2205. x: number;
  2206. /**
  2207. * Direct access to the position.y value of the primitive
  2208. * Use this property when you only want to change one component of the position property
  2209. */
  2210. y: number;
  2211. private static boundinbBoxReentrency;
  2212. protected static nullSize: Size;
  2213. size: Size;
  2214. protected internalGetSize(): Size;
  2215. protected internalSetSize(value: Size): void;
  2216. width: number;
  2217. height: number;
  2218. rotation: number;
  2219. scale: number;
  2220. actualSize: Size;
  2221. actualWidth: number;
  2222. actualHeight: number;
  2223. readonly actualZOffset: number;
  2224. /**
  2225. * Get or set the minimal size the Layout Engine should respect when computing the primitive's actualSize.
  2226. * The Primitive's size won't be less than specified.
  2227. * The default value depends of the Primitive type
  2228. */
  2229. minSize: Size;
  2230. /**
  2231. * Get or set the maximal size the Layout Engine should respect when computing the primitive's actualSize.
  2232. * The Primitive's size won't be more than specified.
  2233. * The default value depends of the Primitive type
  2234. */
  2235. maxSize: Size;
  2236. /**
  2237. * The origin defines the normalized coordinate of the center of the primitive, from the bottom/left corner.
  2238. * The origin is used only to compute transformation of the primitive, it has no meaning in the primitive local frame of reference
  2239. * For instance:
  2240. * 0,0 means the center is bottom/left. Which is the default for Canvas2D instances
  2241. * 0.5,0.5 means the center is at the center of the primitive, which is default of all types of Primitives
  2242. * 0,1 means the center is top/left
  2243. * @returns The normalized center.
  2244. */
  2245. origin: Vector2;
  2246. levelVisible: boolean;
  2247. isVisible: boolean;
  2248. zOrder: number;
  2249. readonly isManualZOrder: boolean;
  2250. margin: PrimitiveThickness;
  2251. /**
  2252. * Set the margin from a string value
  2253. * @param value 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.
  2254. * Values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  2255. */
  2256. setMargin(value: string): void;
  2257. /**
  2258. * Check for both margin and marginAlignment, return true if at least one of them is specified with a non default value
  2259. */
  2260. readonly _hasMargin: boolean;
  2261. padding: PrimitiveThickness;
  2262. /**
  2263. * Set the padding from a string value
  2264. * @param value 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.
  2265. * Values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels. */
  2266. setPadding(value: string): void;
  2267. private readonly _hasPadding;
  2268. marginAlignment: PrimitiveAlignment;
  2269. /**
  2270. * Set the margin's horizontal and or vertical alignments from a string value.
  2271. * @param value can be: [<h:|horizontal:><left|right|center|stretch>], [<v:|vertical:><top|bottom|center|stretch>]
  2272. */
  2273. setMarginalignment(value: string): void;
  2274. /**
  2275. * Check if there a marginAlignment specified (non null and not default)
  2276. */
  2277. readonly _hasMarginAlignment: boolean;
  2278. protected _updatePositioningState(): void;
  2279. opacity: number;
  2280. scaleX: number;
  2281. scaleY: number;
  2282. protected _spreadActualScaleDirty(): void;
  2283. /**
  2284. * 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
  2285. */
  2286. readonly actualScale: Vector2;
  2287. /**
  2288. * Get the actual Scale of the X axis, shortcut for this.actualScale.x
  2289. */
  2290. readonly actualScaleX: number;
  2291. /**
  2292. * This method stores the actual global scale (including DesignMode and DPR related scales) in the given Vector2
  2293. * @param res the object that will receive the actual global scale: this is actualScale * DPRScale * DesignModeScale
  2294. */
  2295. getActualGlobalScaleToRef(res: Vector2): void;
  2296. /**
  2297. * Get the actual Scale of the Y axis, shortcut for this.actualScale.y
  2298. */
  2299. readonly actualScaleY: number;
  2300. /**
  2301. * Get the actual opacity level, this property is computed from the opacity property, multiplied by the actualOpacity of its parent (if any)
  2302. */
  2303. readonly actualOpacity: number;
  2304. /**
  2305. * Get/set the layout engine to use for this primitive.
  2306. * The default layout engine is the CanvasLayoutEngine.
  2307. */
  2308. layoutEngine: LayoutEngineBase;
  2309. /**
  2310. * Get/set the layout are of this primitive.
  2311. * The Layout area is the zone allocated by the Layout Engine for this particular primitive. Margins/Alignment will be computed based on this area.
  2312. * The setter should only be called by a Layout Engine class.
  2313. */
  2314. layoutArea: Size;
  2315. /**
  2316. * Get/set the layout area position (relative to the parent primitive).
  2317. * The setter should only be called by a Layout Engine class.
  2318. */
  2319. layoutAreaPos: Vector2;
  2320. /**
  2321. * Define if the Primitive can be subject to intersection test or not (default is true)
  2322. */
  2323. isPickable: boolean;
  2324. /**
  2325. * Define if the Primitive acts as a container or not
  2326. * A container will encapsulate its children for interaction event.
  2327. * If it's not a container events will be process down to children if the primitive is not pickable.
  2328. * Default value is true
  2329. */
  2330. isContainer: boolean;
  2331. /**
  2332. * Return the depth level of the Primitive into the Canvas' Graph. A Canvas will be 0, its direct children 1, and so on.
  2333. */
  2334. readonly hierarchyDepth: number;
  2335. /**
  2336. * Retrieve the Group that is responsible to render this primitive
  2337. */
  2338. readonly renderGroup: Group2D;
  2339. /**
  2340. * Get the global transformation matrix of the primitive
  2341. */
  2342. readonly globalTransform: Matrix2D;
  2343. /**
  2344. * return the global position of the primitive, relative to its canvas
  2345. */
  2346. getGlobalPosition(): Vector2;
  2347. /**
  2348. * return the global position of the primitive, relative to its canvas
  2349. * @param v the valid Vector2 object where the global position will be stored
  2350. */
  2351. getGlobalPositionByRef(v: Vector2): void;
  2352. /**
  2353. * Get invert of the global transformation matrix of the primitive
  2354. */
  2355. readonly invGlobalTransform: Matrix2D;
  2356. /**
  2357. * Get the local transformation of the primitive
  2358. */
  2359. readonly localTransform: Matrix2D;
  2360. readonly localLayoutTransform: Matrix2D;
  2361. /**
  2362. * Get/set if the sprite rendering should be aligned to the target rendering device pixel or not
  2363. */
  2364. alignToPixel: boolean;
  2365. private static _bMinMax;
  2366. private static _bMax;
  2367. private static _bSize;
  2368. private static _tpsBB;
  2369. private static _tpsBB2;
  2370. /**
  2371. * Get the boundingInfo associated to the primitive and its children.
  2372. */
  2373. readonly boundingInfo: BoundingInfo2D;
  2374. /**
  2375. * Get the boundingInfo of the primitive's content arranged by a layout Engine
  2376. * If a particular child is not arranged by layout, it's boundingInfo is used instead to produce something as accurate as possible
  2377. */
  2378. readonly layoutBoundingInfo: BoundingInfo2D;
  2379. /**
  2380. * Determine if the size is automatically computed or fixed because manually specified.
  2381. * Use the actualSize property to get the final/real size of the primitive
  2382. * @returns true if the size is automatically computed, false if it were manually specified.
  2383. */
  2384. readonly isSizeAuto: boolean;
  2385. /**
  2386. * Determine if the horizontal size is automatically computed or fixed because manually specified.
  2387. * Use the actualSize property to get the final/real size of the primitive
  2388. * @returns true if the horizontal size is automatically computed, false if it were manually specified.
  2389. */
  2390. readonly isHorizontalSizeAuto: boolean;
  2391. /**
  2392. * Determine if the vertical size is automatically computed or fixed because manually specified.
  2393. * Use the actualSize property to get the final/real size of the primitive
  2394. * @returns true if the vertical size is automatically computed, false if it were manually specified.
  2395. */
  2396. readonly isVerticalSizeAuto: boolean;
  2397. /**
  2398. * Return true if this prim has an auto size which is set by the children's global bounding box
  2399. */
  2400. readonly isSizedByContent: boolean;
  2401. /**
  2402. * Determine if the position is automatically computed or fixed because manually specified.
  2403. * Use the actualPosition property to get the final/real position of the primitive
  2404. * @returns true if the position is automatically computed, false if it were manually specified.
  2405. */
  2406. readonly isPositionAuto: boolean;
  2407. /**
  2408. * Interaction with the primitive can be create using this Observable. See the PrimitivePointerInfo class for more information
  2409. */
  2410. readonly pointerEventObservable: Observable<PrimitivePointerInfo>;
  2411. readonly zActualOrderChangedObservable: Observable<number>;
  2412. displayDebugAreas: boolean;
  2413. private static _updatingDebugArea;
  2414. private _updateDebugArea();
  2415. findById(id: string): Prim2DBase;
  2416. protected onZOrderChanged(): void;
  2417. protected levelIntersect(intersectInfo: IntersectInfo2D): boolean;
  2418. /**
  2419. * Capture all the Events of the given PointerId for this primitive.
  2420. * Don't forget to call releasePointerEventsCapture when done.
  2421. * @param pointerId the Id of the pointer to capture the events from.
  2422. */
  2423. setPointerEventCapture(pointerId: number): boolean;
  2424. /**
  2425. * Release a captured pointer made with setPointerEventCapture.
  2426. * @param pointerId the Id of the pointer to release the capture from.
  2427. */
  2428. releasePointerEventsCapture(pointerId: number): boolean;
  2429. private static _bypassGroup2DExclusion;
  2430. /**
  2431. * Make an intersection test with the primitive, all inputs/outputs are stored in the IntersectInfo2D class, see its documentation for more information.
  2432. * @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.
  2433. */
  2434. intersect(intersectInfo: IntersectInfo2D): boolean;
  2435. intersectOtherPrim(other: Prim2DBase): boolean;
  2436. readonly triList: Tri2DArray;
  2437. protected updateTriArray(): void;
  2438. /**
  2439. * Move a child object into a new position regarding its siblings to change its rendering order.
  2440. * You can also use the shortcut methods to move top/bottom: moveChildToTop, moveChildToBottom, moveToTop, moveToBottom.
  2441. * @param child the object to move
  2442. * @param previous the object which will be before "child", if child has to be the first among sibling, set "previous" to null.
  2443. */
  2444. moveChild(child: Prim2DBase, previous: Prim2DBase): boolean;
  2445. /**
  2446. * Move the given child so it's displayed on the top of all its siblings
  2447. * @param child the primitive to move to the top
  2448. */
  2449. moveChildToTop(child: Prim2DBase): boolean;
  2450. /**
  2451. * Move the given child so it's displayed on the bottom of all its siblings
  2452. * @param child the primitive to move to the top
  2453. */
  2454. moveChildToBottom(child: Prim2DBase): boolean;
  2455. /**
  2456. * Move this primitive to be at the top among all its sibling
  2457. */
  2458. moveToTop(): boolean;
  2459. /**
  2460. * Move this primitive to be at the bottom among all its sibling
  2461. */
  2462. moveToBottom(): boolean;
  2463. private addChild(child);
  2464. /**
  2465. * Dispose the primitive, remove it from its parent.
  2466. */
  2467. dispose(): boolean;
  2468. protected onPrimBecomesDirty(): void;
  2469. _needPrepare(): boolean;
  2470. _prepareRender(context: PrepareRender2DContext): void;
  2471. _prepareRenderPre(context: PrepareRender2DContext): void;
  2472. _prepareRenderPost(context: PrepareRender2DContext): void;
  2473. protected _canvasPreInit(settings: any): void;
  2474. protected static _isCanvasInit: boolean;
  2475. protected static CheckParent(parent: Prim2DBase): void;
  2476. protected updateCachedStatesOf(list: Prim2DBase[], recurse: boolean): void;
  2477. private _parentLayoutDirty();
  2478. protected _setLayoutDirty(): void;
  2479. private _checkUseMargin();
  2480. protected _positioningDirty(): void;
  2481. protected _spreadActualOpacityChanged(): void;
  2482. private _changeLayoutEngine(engine);
  2483. private static _t0;
  2484. private static _t1;
  2485. private static _t2;
  2486. private static _v0;
  2487. private static _v30;
  2488. private static _iv2;
  2489. private static _ts0;
  2490. private _updateLocalTransform();
  2491. private static _transMtx;
  2492. protected updateCachedStates(recurse: boolean): void;
  2493. private static _icPos;
  2494. private static _icZone;
  2495. private static _icArea;
  2496. private static _size;
  2497. private static _size2;
  2498. private static _size3;
  2499. private static _size4;
  2500. private static _pv0;
  2501. private static _curContentArea;
  2502. private static _piv;
  2503. private static _tbi;
  2504. private static _pv1;
  2505. private static _pv2;
  2506. private _updatePositioning();
  2507. /**
  2508. * Get the content are of this primitive, this area is computed the primitive size and using the padding property.
  2509. * Children of this primitive will be positioned relative to the bottom/left corner of this area.
  2510. */
  2511. readonly contentArea: Size;
  2512. _patchHierarchy(owner: Canvas2D): void;
  2513. protected onSetOwner(): void;
  2514. private static _zOrderChangedNotifList;
  2515. private static _zRebuildReentrency;
  2516. private _updateZOrder();
  2517. private static _totalCount;
  2518. private _updatePrimitiveLinearPosition(prevLinPos);
  2519. private _updatePrimitiveZOrder(startPos, startZ, deltaZ);
  2520. private _updatePrimitiveFlatZOrder(newZ);
  2521. private _setZOrder(newZ, directEmit);
  2522. protected _updateRenderMode(): void;
  2523. /**
  2524. * This method is used to alter the contentArea of the Primitive before margin is applied.
  2525. * 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.
  2526. * @param primSize the current size of the primitive
  2527. * @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
  2528. * @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!
  2529. */
  2530. protected _getInitialContentAreaToRef(primSize: Size, initialContentPosition: Vector4, initialContentArea: Size): void;
  2531. /**
  2532. * This method is used to calculate the new size of the primitive based on the content which must stay the same
  2533. * Check the Rectangle2D implementation for a concrete application.
  2534. * @param primSize the current size of the primitive
  2535. * @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!
  2536. */
  2537. protected _getActualSizeFromContentToRef(primSize: Size, paddingOffset: Vector4, newPrimSize: Size): void;
  2538. /**
  2539. * Get/set the layout data to use for this primitive.
  2540. */
  2541. layoutData: ILayoutData;
  2542. private _owner;
  2543. private _parent;
  2544. private _actionManager;
  2545. protected _children: Array<Prim2DBase>;
  2546. private _renderGroup;
  2547. protected _hierarchyDepth: number;
  2548. protected _zOrder: number;
  2549. private _manualZOrder;
  2550. protected _zMax: number;
  2551. private _firstZDirtyIndex;
  2552. private _primLinearPosition;
  2553. private _margin;
  2554. private _padding;
  2555. private _marginAlignment;
  2556. _pointerEventObservable: Observable<PrimitivePointerInfo>;
  2557. private _actualZOrderChangedObservable;
  2558. private _id;
  2559. private _position;
  2560. private _actualPosition;
  2561. protected _size: Size;
  2562. protected _actualSize: Size;
  2563. private _internalSize;
  2564. protected _minSize: Size;
  2565. protected _maxSize: Size;
  2566. protected _desiredSize: Size;
  2567. private _layoutEngine;
  2568. private _marginOffset;
  2569. private _paddingOffset;
  2570. private _parentPaddingOffset;
  2571. private _parentContentArea;
  2572. private _lastAutoSizeArea;
  2573. private _layoutAreaPos;
  2574. private _layoutArea;
  2575. private _layoutData;
  2576. private _contentArea;
  2577. private _rotation;
  2578. private _scale;
  2579. protected _postScale: Vector2;
  2580. private _origin;
  2581. protected _opacity: number;
  2582. private _actualOpacity;
  2583. private _actualScale;
  2584. private _displayDebugAreas;
  2585. private _debugAreaGroup;
  2586. private _actorInfo;
  2587. protected _parentTransformStep: number;
  2588. protected _globalTransformStep: number;
  2589. protected _globalTransformProcessStep: number;
  2590. protected _prepareProcessStep: number;
  2591. protected _updateCachesProcessStep: number;
  2592. protected _localTransform: Matrix2D;
  2593. protected _localLayoutTransform: Matrix2D;
  2594. protected _globalTransform: Matrix2D;
  2595. protected _invGlobalTransform: Matrix2D;
  2596. protected _primTriArrayDirty: boolean;
  2597. protected _primTriArray: Tri2DArray;
  2598. }
  2599. }
  2600. declare module BABYLON {
  2601. const enum ShaderDataType {
  2602. Vector2 = 0,
  2603. Vector3 = 1,
  2604. Vector4 = 2,
  2605. float = 3,
  2606. Color3 = 4,
  2607. Color4 = 5,
  2608. Size = 6,
  2609. }
  2610. class GroupInstanceInfo {
  2611. constructor(owner: Group2D, mrc: ModelRenderCache, partCount: number);
  2612. incPrimCount(): void;
  2613. dispose(): boolean;
  2614. readonly isDisposed: boolean;
  2615. private _isDisposed;
  2616. owner: Group2D;
  2617. modelRenderCache: ModelRenderCache;
  2618. partIndexFromId: StringDictionary<number>;
  2619. readonly hasOpaqueData: boolean;
  2620. readonly hasAlphaTestData: boolean;
  2621. readonly hasTransparentData: boolean;
  2622. opaqueDirty: boolean;
  2623. readonly opaqueData: GroupInfoPartData[];
  2624. alphaTestDirty: boolean;
  2625. readonly alphaTestData: GroupInfoPartData[];
  2626. transparentOrderDirty: boolean;
  2627. transparentDirty: boolean;
  2628. readonly transparentData: TransparentGroupInfoPartData[];
  2629. sortTransparentData(): void;
  2630. readonly usedShaderCategories: string[];
  2631. readonly strides: number[];
  2632. private _partCount;
  2633. private _primCount;
  2634. private _strides;
  2635. private _usedShaderCategories;
  2636. private _opaqueData;
  2637. private _alphaTestData;
  2638. private _transparentData;
  2639. }
  2640. class TransparentSegment {
  2641. constructor();
  2642. dispose(engine: Engine): void;
  2643. groupInsanceInfo: GroupInstanceInfo;
  2644. startZ: number;
  2645. endZ: number;
  2646. startDataIndex: number;
  2647. endDataIndex: number;
  2648. partBuffers: WebGLBuffer[];
  2649. }
  2650. class GroupInfoPartData {
  2651. _partData: DynamicFloatArray;
  2652. _partBuffer: WebGLBuffer;
  2653. _partBufferSize: number;
  2654. constructor(stride: number);
  2655. dispose(engine: Engine): boolean;
  2656. private _isDisposed;
  2657. }
  2658. class TransparentGroupInfoPartData extends GroupInfoPartData {
  2659. constructor(stride: number, zoff: number);
  2660. }
  2661. class ModelRenderCache {
  2662. constructor(engine: Engine, modelKey: string);
  2663. dispose(): boolean;
  2664. readonly isDisposed: boolean;
  2665. addRef(): number;
  2666. readonly modelKey: string;
  2667. updateModelRenderCache(prim: Prim2DBase): boolean;
  2668. /**
  2669. * Render the model instances
  2670. * @param instanceInfo
  2671. * @param context
  2672. * @return must return true is the rendering succeed, false if the rendering couldn't be done (asset's not yet ready, like Effect)
  2673. */
  2674. render(instanceInfo: GroupInstanceInfo, context: Render2DContext): boolean;
  2675. protected getPartIndexFromId(partId: number): number;
  2676. protected loadInstancingAttributes(partId: number, effect: Effect): InstancingAttributeInfo[];
  2677. private static v2;
  2678. private static v3;
  2679. private static v4;
  2680. protected setupUniforms(effect: Effect, partIndex: number, data: DynamicFloatArray, elementCount: number): void;
  2681. protected _engine: Engine;
  2682. private _modelKey;
  2683. private _nextKey;
  2684. private _refCounter;
  2685. _partData: ModelRenderCachePartData[];
  2686. _partsClassInfo: ClassTreeInfo<InstanceClassInfo, InstancePropInfo>[];
  2687. }
  2688. class ModelRenderCachePartData {
  2689. _partId: number;
  2690. _zBiasOffset: number;
  2691. _partDataStride: number;
  2692. _partUsedCategories: string[];
  2693. _partJoinedUsedCategories: string;
  2694. }
  2695. }
  2696. declare module BABYLON {
  2697. class InstanceClassInfo {
  2698. constructor(base: InstanceClassInfo);
  2699. mapProperty(propInfo: InstancePropInfo, push: boolean): void;
  2700. getInstancingAttributeInfos(effect: Effect, categories: string[]): InstancingAttributeInfo[];
  2701. getShaderAttributes(categories: string[]): string[];
  2702. private _getBaseOffset(categories);
  2703. static _CurCategories: string;
  2704. private _baseInfo;
  2705. private _nextOffset;
  2706. private _attributes;
  2707. }
  2708. class InstancePropInfo {
  2709. attributeName: string;
  2710. category: string;
  2711. size: number;
  2712. instanceOffset: StringDictionary<number>;
  2713. dataType: ShaderDataType;
  2714. curCategory: string;
  2715. curCategoryOffset: number;
  2716. delimitedCategory: string;
  2717. constructor();
  2718. setSize(val: any): void;
  2719. writeData(array: Float32Array, offset: number, val: any): void;
  2720. }
  2721. function instanceData<T>(category?: string, shaderAttributeName?: string): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void;
  2722. class InstanceDataBase {
  2723. constructor(partId: number, dataElementCount: number);
  2724. id: number;
  2725. isVisible: boolean;
  2726. zBias: Vector2;
  2727. transformX: Vector4;
  2728. transformY: Vector4;
  2729. renderingInfo: Vector3;
  2730. opacity: number;
  2731. getClassTreeInfo(): ClassTreeInfo<InstanceClassInfo, InstancePropInfo>;
  2732. allocElements(): void;
  2733. freeElements(): void;
  2734. dataElementCount: number;
  2735. groupInstanceInfo: GroupInstanceInfo;
  2736. arrayLengthChanged: boolean;
  2737. curElement: number;
  2738. renderMode: number;
  2739. dataElements: DynamicFloatArrayElementInfo[];
  2740. dataBuffer: DynamicFloatArray;
  2741. typeInfo: ClassTreeInfo<InstanceClassInfo, InstancePropInfo>;
  2742. private _dataElementCount;
  2743. }
  2744. abstract class RenderablePrim2D extends Prim2DBase {
  2745. static RENDERABLEPRIM2D_PROPCOUNT: number;
  2746. static isAlphaTestProperty: Prim2DPropInfo;
  2747. static isTransparentProperty: Prim2DPropInfo;
  2748. readonly isAlphaTest: boolean;
  2749. readonly isTransparent: boolean;
  2750. readonly renderMode: number;
  2751. constructor(settings?: {
  2752. parent?: Prim2DBase;
  2753. id?: string;
  2754. origin?: Vector2;
  2755. isVisible?: boolean;
  2756. });
  2757. /**
  2758. * Dispose the primitive and its resources, remove it from its parent
  2759. */
  2760. dispose(): boolean;
  2761. private _cleanupInstanceDataParts();
  2762. _prepareRenderPre(context: PrepareRender2DContext): void;
  2763. private _createModelRenderCache();
  2764. private _createModelDataParts();
  2765. private _setupModelRenderCache(parts);
  2766. protected onZOrderChanged(): void;
  2767. protected _mustUpdateInstance(): boolean;
  2768. protected _useTextureAlpha(): boolean;
  2769. protected _shouldUseAlphaFromTexture(): boolean;
  2770. protected _isPrimAlphaTest(): boolean;
  2771. protected _isPrimTransparent(): boolean;
  2772. private _updateInstanceDataParts(gii);
  2773. _updateTransparentSegmentIndices(ts: TransparentSegment): void;
  2774. _getNextPrimZOrder(): number;
  2775. _getPrevPrimZOrder(): number;
  2776. private static _toz;
  2777. /**
  2778. * Get the info for a given effect based on the dataPart metadata
  2779. * @param dataPartId partId in part list to get the info
  2780. * @param vertexBufferAttributes vertex buffer attributes to manually add
  2781. * @param uniforms uniforms to manually add
  2782. * @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
  2783. */
  2784. protected getDataPartEffectInfo(dataPartId: number, vertexBufferAttributes: string[], uniforms?: string[], useInstanced?: boolean): {
  2785. attributes: string[];
  2786. uniforms: string[];
  2787. defines: string;
  2788. };
  2789. protected readonly modelRenderCache: ModelRenderCache;
  2790. protected createModelRenderCache(modelKey: string): ModelRenderCache;
  2791. protected setupModelRenderCache(modelRenderCache: ModelRenderCache): void;
  2792. protected createInstanceDataParts(): InstanceDataBase[];
  2793. protected getUsedShaderCategories(dataPart: InstanceDataBase): string[];
  2794. protected beforeRefreshForLayoutConstruction(part: InstanceDataBase): any;
  2795. protected afterRefreshForLayoutConstruction(part: InstanceDataBase, obj: any): void;
  2796. protected applyActualScaleOnTransform(): boolean;
  2797. protected refreshInstanceDataPart(part: InstanceDataBase): boolean;
  2798. private static _uV;
  2799. private static _s;
  2800. private static _r;
  2801. private static _t;
  2802. private static _iV2;
  2803. /**
  2804. * Update the instanceDataBase level properties of a part
  2805. * @param part the part to update
  2806. * @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).
  2807. */
  2808. protected updateInstanceDataPart(part: InstanceDataBase, positionOffset?: Vector2): void;
  2809. protected _updateRenderMode(): void;
  2810. private _modelRenderCache;
  2811. private _transparentPrimitiveInfo;
  2812. protected _instanceDataParts: InstanceDataBase[];
  2813. private _renderMode;
  2814. }
  2815. }
  2816. declare module BABYLON {
  2817. abstract class Shape2D extends RenderablePrim2D {
  2818. static SHAPE2D_BORDERPARTID: number;
  2819. static SHAPE2D_FILLPARTID: number;
  2820. static SHAPE2D_CATEGORY_BORDER: string;
  2821. static SHAPE2D_CATEGORY_BORDERSOLID: string;
  2822. static SHAPE2D_CATEGORY_BORDERGRADIENT: string;
  2823. static SHAPE2D_CATEGORY_FILLSOLID: string;
  2824. static SHAPE2D_CATEGORY_FILLGRADIENT: string;
  2825. static SHAPE2D_PROPCOUNT: number;
  2826. static borderProperty: Prim2DPropInfo;
  2827. static fillProperty: Prim2DPropInfo;
  2828. static borderThicknessProperty: Prim2DPropInfo;
  2829. border: IBrush2D;
  2830. /**
  2831. * Get/set the brush to render the Fill part of the Primitive
  2832. */
  2833. fill: IBrush2D;
  2834. borderThickness: number;
  2835. constructor(settings?: {
  2836. fill?: IBrush2D | string;
  2837. border?: IBrush2D | string;
  2838. borderThickness?: number;
  2839. });
  2840. protected getUsedShaderCategories(dataPart: InstanceDataBase): string[];
  2841. protected refreshInstanceDataPart(part: InstanceDataBase): boolean;
  2842. private _updateTransparencyStatus();
  2843. protected _mustUpdateInstance(): boolean;
  2844. protected _isPrimTransparent(): boolean;
  2845. private _oldTransparent;
  2846. private _isTransparent;
  2847. private _border;
  2848. private _borderThickness;
  2849. private _fill;
  2850. }
  2851. class Shape2DInstanceData extends InstanceDataBase {
  2852. fillSolidColor: Color4;
  2853. fillGradientColor1: Color4;
  2854. fillGradientColor2: Color4;
  2855. fillGradientTY: Vector4;
  2856. borderThickness: number;
  2857. borderSolidColor: Color4;
  2858. borderGradientColor1: Color4;
  2859. borderGradientColor2: Color4;
  2860. borderGradientTY: Vector4;
  2861. }
  2862. }
  2863. declare module BABYLON {
  2864. class Group2D extends Prim2DBase {
  2865. static GROUP2D_PROPCOUNT: number;
  2866. static sizeProperty: Prim2DPropInfo;
  2867. static actualSizeProperty: Prim2DPropInfo;
  2868. /**
  2869. * Default behavior, the group will use the caching strategy defined at the Canvas Level
  2870. */
  2871. static GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY: number;
  2872. /**
  2873. * When used, this group's content won't be cached, no matter which strategy used.
  2874. * If the group is part of a WorldSpace Canvas, its content will be drawn in the Canvas cache bitmap.
  2875. */
  2876. static GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE: number;
  2877. /**
  2878. * When used, the group's content will be cached in the nearest cached parent group/canvas
  2879. */
  2880. static GROUPCACHEBEHAVIOR_CACHEINPARENTGROUP: number;
  2881. /**
  2882. * 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
  2883. */
  2884. static GROUPCACHEBEHAVIOR_NORESIZEONSCALE: number;
  2885. private static GROUPCACHEBEHAVIOR_OPTIONMASK;
  2886. /**
  2887. * Create an Logical or Renderable Group.
  2888. * @param settings a combination of settings, possible ones are
  2889. * - 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)
  2890. * - children: an array of direct children
  2891. * - id a text identifier, for information purpose
  2892. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  2893. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  2894. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  2895. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  2896. * - trackNode: if you want the ScreenSpaceCanvas to track the position of a given Scene Node, use this setting to specify the Node to track
  2897. * - trackNodeOffset: if you use trackNode you may want to specify a 3D Offset to apply to shift the Canvas
  2898. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  2899. * - zOrder: override the zOrder with the specified value
  2900. * - origin: define the normalized origin point location, default [0.5;0.5]
  2901. * - 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.
  2902. * - cacheBehavior: Define how the group should behave regarding the Canvas's cache strategy, default is Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY
  2903. * - 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).
  2904. * - isVisible: true if the group must be visible, false for hidden. Default is true.
  2905. * - 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.
  2906. * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersect, 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.
  2907. * - 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!
  2908. * - levelCollision: this primitive is an actor of the Collision Manager and only this level will be used for collision (i.e. not the children). Use deepCollision if you want collision detection on the primitives and its children.
  2909. * - deepCollision: this primitive is an actor of the Collision Manager, this level AND ALSO its children will be used for collision (note: you don't need to set the children as level/deepCollision).
  2910. * - layoutData: a instance of a class implementing the ILayoutData interface that contain data to pass to the primitive parent's layout engine
  2911. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2912. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2913. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2914. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2915. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  2916. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  2917. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  2918. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  2919. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2920. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2921. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2922. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  2923. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  2924. */
  2925. constructor(settings?: {
  2926. parent?: Prim2DBase;
  2927. children?: Array<Prim2DBase>;
  2928. id?: string;
  2929. position?: Vector2;
  2930. x?: number;
  2931. y?: number;
  2932. scale?: number;
  2933. scaleX?: number;
  2934. scaleY?: number;
  2935. dontInheritParentScale?: boolean;
  2936. trackNode?: Node;
  2937. trackNodeOffset?: Vector3;
  2938. opacity?: number;
  2939. zOrder?: number;
  2940. origin?: Vector2;
  2941. size?: Size;
  2942. width?: number;
  2943. height?: number;
  2944. cacheBehavior?: number;
  2945. layoutEngine?: LayoutEngineBase | string;
  2946. isVisible?: boolean;
  2947. isPickable?: boolean;
  2948. isContainer?: boolean;
  2949. childrenFlatZOrder?: boolean;
  2950. levelCollision?: boolean;
  2951. deepCollision?: boolean;
  2952. layoutData?: ILayoutData;
  2953. marginTop?: number | string;
  2954. marginLeft?: number | string;
  2955. marginRight?: number | string;
  2956. marginBottom?: number | string;
  2957. margin?: number | string;
  2958. marginHAlignment?: number;
  2959. marginVAlignment?: number;
  2960. marginAlignment?: string;
  2961. paddingTop?: number | string;
  2962. paddingLeft?: number | string;
  2963. paddingRight?: number | string;
  2964. paddingBottom?: number | string;
  2965. padding?: number | string;
  2966. });
  2967. static _createCachedCanvasGroup(owner: Canvas2D): Group2D;
  2968. protected applyCachedTexture(vertexData: VertexData, material: StandardMaterial): void;
  2969. /**
  2970. * Allow you to access the information regarding the cached rectangle of the Group2D into the MapTexture.
  2971. * 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.
  2972. */
  2973. readonly cachedRect: PackedRect;
  2974. /**
  2975. * The UVs into the MapTexture that map the cached group
  2976. */
  2977. readonly cachedUVs: Vector2[];
  2978. readonly cachedUVsChanged: Observable<Vector2[]>;
  2979. /**
  2980. * Access the texture that maintains a cached version of the Group2D.
  2981. * This is useful only if you're not using a WorldSpaceNode for your WorldSpace Canvas and therefore need to perform the rendering yourself.
  2982. */
  2983. readonly cacheTexture: MapTexture;
  2984. /**
  2985. * Call this method to remove this Group and its children from the Canvas
  2986. */
  2987. dispose(): boolean;
  2988. /**
  2989. * @returns Returns true if the Group render content, false if it's a logical group only
  2990. */
  2991. readonly isRenderableGroup: boolean;
  2992. /**
  2993. * @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
  2994. */
  2995. readonly isCachedGroup: boolean;
  2996. /**
  2997. * Get/Set the size of the group. If null the size of the group will be determine from its content.
  2998. * 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.
  2999. */
  3000. size: Size;
  3001. readonly viewportSize: ISize;
  3002. /**
  3003. * 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.
  3004. * GROUPCACHEBEHAVIOR_NORESIZEONSCALE can also be set if you set it at creation time.
  3005. * 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.
  3006. */
  3007. readonly cacheBehavior: number;
  3008. _addPrimToDirtyList(prim: Prim2DBase): void;
  3009. _renderCachedCanvas(): void;
  3010. /**
  3011. * Get/set the Scene's Node that should be tracked, the group's position will follow the projected position of the Node.
  3012. */
  3013. trackedNode: Node;
  3014. /**
  3015. * Get/set the offset of the tracked node in the tracked node's local space.
  3016. */
  3017. trackedNodeOffset: Vector3;
  3018. protected levelIntersect(intersectInfo: IntersectInfo2D): boolean;
  3019. protected updateLevelBoundingInfo(): boolean;
  3020. protected _prepareGroupRender(context: PrepareRender2DContext): void;
  3021. protected _groupRender(): void;
  3022. _setCacheGroupDirty(): void;
  3023. private _updateTransparentData();
  3024. private _renderTransparentData();
  3025. private _prepareContext(engine, context, gii);
  3026. protected _setRenderingScale(scale: number): void;
  3027. private static _uV;
  3028. private static _s;
  3029. private static _v1;
  3030. private static _s2;
  3031. private _bindCacheTarget();
  3032. private _unbindCacheTarget();
  3033. protected _spreadActualScaleDirty(): void;
  3034. protected static _unS: Vector2;
  3035. protected handleGroupChanged(prop: Prim2DPropInfo): void;
  3036. private detectGroupStates();
  3037. readonly _cachedTexture: MapTexture;
  3038. private _trackedNode;
  3039. private _trackedNodeOffset;
  3040. protected _isRenderableGroup: boolean;
  3041. protected _isCachedGroup: boolean;
  3042. private _cacheGroupDirty;
  3043. private _cacheBehavior;
  3044. private _viewportPosition;
  3045. private _viewportSize;
  3046. _renderableData: RenderableGroupData;
  3047. }
  3048. class RenderableGroupData {
  3049. constructor();
  3050. dispose(owner: Canvas2D): void;
  3051. addNewTransparentPrimitiveInfo(prim: RenderablePrim2D, gii: GroupInstanceInfo): TransparentPrimitiveInfo;
  3052. removeTransparentPrimitiveInfo(tpi: TransparentPrimitiveInfo): void;
  3053. transparentPrimitiveZChanged(tpi: TransparentPrimitiveInfo): void;
  3054. resetPrimDirtyList(): void;
  3055. _primDirtyList: Array<Prim2DBase>;
  3056. _primNewDirtyList: Array<Prim2DBase>;
  3057. _childrenRenderableGroups: Array<Group2D>;
  3058. _renderGroupInstancesInfo: StringDictionary<GroupInstanceInfo>;
  3059. _cacheNode: PackedRect;
  3060. _cacheTexture: MapTexture;
  3061. _cacheRenderSprite: Sprite2D;
  3062. _cacheNodeUVs: Vector2[];
  3063. _cacheNodeUVsChangedObservable: Observable<Vector2[]>;
  3064. _cacheSize: Size;
  3065. _useMipMap: boolean;
  3066. _anisotropicLevel: number;
  3067. _noResizeOnScale: boolean;
  3068. _transparentListChanged: boolean;
  3069. _transparentPrimitives: Array<TransparentPrimitiveInfo>;
  3070. _transparentSegments: Array<TransparentSegment>;
  3071. _renderingScale: number;
  3072. }
  3073. class TransparentPrimitiveInfo {
  3074. _primitive: RenderablePrim2D;
  3075. _groupInstanceInfo: GroupInstanceInfo;
  3076. _transparentSegment: TransparentSegment;
  3077. }
  3078. }
  3079. declare module BABYLON {
  3080. class WireFrame2DRenderCache extends ModelRenderCache {
  3081. effectsReady: boolean;
  3082. vb: WebGLBuffer;
  3083. vtxCount: number;
  3084. instancingAttributes: InstancingAttributeInfo[];
  3085. effect: Effect;
  3086. effectInstanced: Effect;
  3087. render(instanceInfo: GroupInstanceInfo, context: Render2DContext): boolean;
  3088. updateModelRenderCache(prim: Prim2DBase): boolean;
  3089. dispose(): boolean;
  3090. }
  3091. class WireFrameVertex2D {
  3092. x: number;
  3093. y: number;
  3094. r: number;
  3095. g: number;
  3096. b: number;
  3097. a: number;
  3098. constructor(p: Vector2, c?: Color4);
  3099. fromVector2(p: Vector2): void;
  3100. fromColor3(c: Color3): void;
  3101. fromColor4(c: Color4): void;
  3102. }
  3103. class WireFrameGroup2D {
  3104. /**
  3105. * Construct a WireFrameGroup2D object
  3106. * @param id a unique ID among the Groups added to a given WireFrame2D primitive, if you don't specify an id, a random one will be generated. The id is immutable.
  3107. * @param defaultColor specify the default color that will be used when a vertex is pushed, white will be used if not specified.
  3108. */
  3109. constructor(id?: string, defaultColor?: Color4);
  3110. readonly uid: string;
  3111. /**
  3112. * Retrieve the ID of the group
  3113. */
  3114. readonly id: string;
  3115. /**
  3116. * Push a vertex in the array of vertices.
  3117. * If you're previously called startLineStrip, the vertex will be pushed twice in order to describe the end of a line and the start of a new one.
  3118. * @param p Position of the vertex
  3119. * @param c Color of the vertex, if null the default color of the group will be used
  3120. */
  3121. pushVertex(p: Vector2, c?: Color4): void;
  3122. /**
  3123. * Start to store a Line Strip. The given vertex will be pushed in the array. The you have to call pushVertex to add subsequent vertices describing the strip and don't forget to call endLineStrip to close the strip!!!
  3124. * @param p Position of the vertex
  3125. * @param c Color of the vertex, if null the default color of the group will be used
  3126. */
  3127. startLineStrip(p: Vector2, c?: Color4): void;
  3128. /**
  3129. * Close the Strip by storing a last vertex
  3130. * @param p Position of the vertex
  3131. * @param c Color of the vertex, if null the default color of the group will be used
  3132. */
  3133. endLineStrip(p: Vector2, c?: Color4): void;
  3134. /**
  3135. * Access to the array of Vertices, you can manipulate its content but BEWARE of what you're doing!
  3136. */
  3137. readonly vertices: Array<WireFrameVertex2D>;
  3138. private _uid;
  3139. private _id;
  3140. private _defaultColor;
  3141. private _vertices;
  3142. private _buildingStrip;
  3143. }
  3144. class WireFrame2D extends RenderablePrim2D {
  3145. static WIREFRAME2D_MAINPARTID: number;
  3146. static wireFrameGroupsProperty: Prim2DPropInfo;
  3147. readonly wireFrameGroups: StringDictionary<WireFrameGroup2D>;
  3148. /**
  3149. * If you change the content of the wireFrameGroups you MUST call this method for the changes to be reflected during rendering
  3150. */
  3151. wireFrameGroupsDirty(): void;
  3152. size: Size;
  3153. protected updateLevelBoundingInfo(): boolean;
  3154. protected levelIntersect(intersectInfo: IntersectInfo2D): boolean;
  3155. /**
  3156. * Create an WireFrame 2D primitive
  3157. * @param wireFrameGroups an array of WireFrameGroup.
  3158. * @param settings a combination of settings, possible ones are
  3159. * - 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)
  3160. * - children: an array of direct children
  3161. * - id a text identifier, for information purpose
  3162. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  3163. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  3164. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  3165. * - size: the size of the sprite displayed in the canvas, if not specified the spriteSize will be used
  3166. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  3167. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  3168. * - zOrder: override the zOrder with the specified value
  3169. * - origin: define the normalized origin point location, default [0.5;0.5]
  3170. * - alignToPixel: the rendered lines will be aligned to the rendering device' pixels
  3171. * - isVisible: true if the sprite must be visible, false for hidden. Default is true.
  3172. * - 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.
  3173. * - 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.
  3174. * - 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!
  3175. * - levelCollision: this primitive is an actor of the Collision Manager and only this level will be used for collision (i.e. not the children). Use deepCollision if you want collision detection on the primitives and its children.
  3176. * - deepCollision: this primitive is an actor of the Collision Manager, this level AND ALSO its children will be used for collision (note: you don't need to set the children as level/deepCollision).
  3177. * - layoutData: a instance of a class implementing the ILayoutData interface that contain data to pass to the primitive parent's layout engine
  3178. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3179. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3180. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3181. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3182. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  3183. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  3184. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  3185. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  3186. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3187. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3188. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3189. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3190. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  3191. */
  3192. constructor(wireFrameGroups: Array<WireFrameGroup2D>, settings?: {
  3193. parent?: Prim2DBase;
  3194. children?: Array<Prim2DBase>;
  3195. id?: string;
  3196. position?: Vector2;
  3197. x?: number;
  3198. y?: number;
  3199. rotation?: number;
  3200. size?: Size;
  3201. scale?: number;
  3202. scaleX?: number;
  3203. scaleY?: number;
  3204. dontInheritParentScale?: boolean;
  3205. opacity?: number;
  3206. zOrder?: number;
  3207. origin?: Vector2;
  3208. alignToPixel?: boolean;
  3209. isVisible?: boolean;
  3210. isPickable?: boolean;
  3211. isContainer?: boolean;
  3212. childrenFlatZOrder?: boolean;
  3213. levelCollision?: boolean;
  3214. deepCollision?: boolean;
  3215. layoutData?: ILayoutData;
  3216. marginTop?: number | string;
  3217. marginLeft?: number | string;
  3218. marginRight?: number | string;
  3219. marginBottom?: number | string;
  3220. margin?: number | string;
  3221. marginHAlignment?: number;
  3222. marginVAlignment?: number;
  3223. marginAlignment?: string;
  3224. paddingTop?: number | string;
  3225. paddingLeft?: number | string;
  3226. paddingRight?: number | string;
  3227. paddingBottom?: number | string;
  3228. padding?: number | string;
  3229. });
  3230. /**
  3231. * Get/set if the sprite rendering should be aligned to the target rendering device pixel or not
  3232. */
  3233. alignToPixel: boolean;
  3234. protected createModelRenderCache(modelKey: string): ModelRenderCache;
  3235. protected setupModelRenderCache(modelRenderCache: ModelRenderCache): WireFrame2DRenderCache;
  3236. _updateVertexBuffer(mrc: WireFrame2DRenderCache): void;
  3237. protected refreshInstanceDataPart(part: InstanceDataBase): boolean;
  3238. private _computeMinMaxTrans();
  3239. protected createInstanceDataParts(): InstanceDataBase[];
  3240. private _vtxTransparent;
  3241. private _wireFrameGroups;
  3242. private _alignToPixel;
  3243. }
  3244. class WireFrame2DInstanceData extends InstanceDataBase {
  3245. constructor(partId: number);
  3246. }
  3247. }
  3248. declare module BABYLON {
  3249. class Rectangle2DRenderCache extends ModelRenderCache {
  3250. effectsReady: boolean;
  3251. fillVB: WebGLBuffer;
  3252. fillIB: WebGLBuffer;
  3253. fillIndicesCount: number;
  3254. instancingFillAttributes: InstancingAttributeInfo[];
  3255. effectFill: Effect;
  3256. effectFillInstanced: Effect;
  3257. borderVB: WebGLBuffer;
  3258. borderIB: WebGLBuffer;
  3259. borderIndicesCount: number;
  3260. instancingBorderAttributes: InstancingAttributeInfo[];
  3261. effectBorder: Effect;
  3262. effectBorderInstanced: Effect;
  3263. constructor(engine: Engine, modelKey: string);
  3264. render(instanceInfo: GroupInstanceInfo, context: Render2DContext): boolean;
  3265. dispose(): boolean;
  3266. }
  3267. class Rectangle2DInstanceData extends Shape2DInstanceData {
  3268. constructor(partId: number);
  3269. properties: Vector3;
  3270. }
  3271. class Rectangle2D extends Shape2D {
  3272. static actualSizeProperty: Prim2DPropInfo;
  3273. static notRoundedProperty: Prim2DPropInfo;
  3274. static roundRadiusProperty: Prim2DPropInfo;
  3275. notRounded: boolean;
  3276. roundRadius: number;
  3277. private static _i0;
  3278. private static _i1;
  3279. private static _i2;
  3280. protected levelIntersect(intersectInfo: IntersectInfo2D): boolean;
  3281. protected updateLevelBoundingInfo(): boolean;
  3282. /**
  3283. * Create an Rectangle 2D Shape primitive. May be a sharp rectangle (with sharp corners), or a rounded one.
  3284. * @param settings a combination of settings, possible ones are
  3285. * - 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)
  3286. * - children: an array of direct children
  3287. * - id a text identifier, for information purpose
  3288. * - position: the X & Y positions relative to its parent. Alternatively the x and y settings can be set. Default is [0;0]
  3289. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  3290. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  3291. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  3292. * - alignToPixel: if true the primitive will be aligned to the target rendering device's pixel
  3293. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  3294. * - zOrder: override the zOrder with the specified value
  3295. * - origin: define the normalized origin point location, default [0.5;0.5]
  3296. * - size: the size of the group. Alternatively the width and height settings can be set. Default will be [10;10].
  3297. * - roundRadius: if the rectangle has rounded corner, set their radius, default is 0 (to get a sharp edges rectangle).
  3298. * - 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)
  3299. * - 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)
  3300. * - borderThickness: the thickness of the drawn border, default is 1.
  3301. * - isVisible: true if the primitive must be visible, false for hidden. Default is true.
  3302. * - 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.
  3303. * - 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.
  3304. * - 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!
  3305. * - levelCollision: this primitive is an actor of the Collision Manager and only this level will be used for collision (i.e. not the children). Use deepCollision if you want collision detection on the primitives and its children.
  3306. * - deepCollision: this primitive is an actor of the Collision Manager, this level AND ALSO its children will be used for collision (note: you don't need to set the children as level/deepCollision).
  3307. * - layoutData: a instance of a class implementing the ILayoutData interface that contain data to pass to the primitive parent's layout engine
  3308. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3309. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3310. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3311. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3312. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  3313. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  3314. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  3315. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  3316. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3317. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3318. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3319. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3320. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  3321. */
  3322. constructor(settings?: {
  3323. parent?: Prim2DBase;
  3324. children?: Array<Prim2DBase>;
  3325. id?: string;
  3326. position?: Vector2;
  3327. x?: number;
  3328. y?: number;
  3329. rotation?: number;
  3330. scale?: number;
  3331. scaleX?: number;
  3332. scaleY?: number;
  3333. dontInheritParentScale?: boolean;
  3334. alignToPixel?: boolean;
  3335. opacity?: number;
  3336. zOrder?: number;
  3337. origin?: Vector2;
  3338. size?: Size;
  3339. width?: number;
  3340. height?: number;
  3341. roundRadius?: number;
  3342. fill?: IBrush2D | string;
  3343. border?: IBrush2D | string;
  3344. borderThickness?: number;
  3345. isVisible?: boolean;
  3346. isPickable?: boolean;
  3347. isContainer?: boolean;
  3348. childrenFlatZOrder?: boolean;
  3349. levelCollision?: boolean;
  3350. deepCollision?: boolean;
  3351. layoutData?: ILayoutData;
  3352. marginTop?: number | string;
  3353. marginLeft?: number | string;
  3354. marginRight?: number | string;
  3355. marginBottom?: number | string;
  3356. margin?: number | string;
  3357. marginHAlignment?: number;
  3358. marginVAlignment?: number;
  3359. marginAlignment?: string;
  3360. paddingTop?: number | string;
  3361. paddingLeft?: number | string;
  3362. paddingRight?: number | string;
  3363. paddingBottom?: number | string;
  3364. padding?: number | string;
  3365. });
  3366. static roundSubdivisions: number;
  3367. protected createModelRenderCache(modelKey: string): ModelRenderCache;
  3368. protected updateTriArray(): void;
  3369. protected setupModelRenderCache(modelRenderCache: ModelRenderCache): Rectangle2DRenderCache;
  3370. protected _getInitialContentAreaToRef(primSize: Size, initialContentPosition: Vector4, initialContentArea: Size): void;
  3371. protected _getActualSizeFromContentToRef(primSize: Size, paddingOffset: Vector4, newPrimSize: Size): void;
  3372. protected createInstanceDataParts(): InstanceDataBase[];
  3373. private static _riv0;
  3374. protected refreshInstanceDataPart(part: InstanceDataBase): boolean;
  3375. private _notRounded;
  3376. private _roundRadius;
  3377. }
  3378. }
  3379. declare module BABYLON {
  3380. class Ellipse2DRenderCache extends ModelRenderCache {
  3381. effectsReady: boolean;
  3382. fillVB: WebGLBuffer;
  3383. fillIB: WebGLBuffer;
  3384. fillIndicesCount: number;
  3385. instancingFillAttributes: InstancingAttributeInfo[];
  3386. effectFillInstanced: Effect;
  3387. effectFill: Effect;
  3388. borderVB: WebGLBuffer;
  3389. borderIB: WebGLBuffer;
  3390. borderIndicesCount: number;
  3391. instancingBorderAttributes: InstancingAttributeInfo[];
  3392. effectBorderInstanced: Effect;
  3393. effectBorder: Effect;
  3394. constructor(engine: Engine, modelKey: string);
  3395. render(instanceInfo: GroupInstanceInfo, context: Render2DContext): boolean;
  3396. dispose(): boolean;
  3397. }
  3398. class Ellipse2DInstanceData extends Shape2DInstanceData {
  3399. constructor(partId: number);
  3400. properties: Vector3;
  3401. }
  3402. class Ellipse2D extends Shape2D {
  3403. static acutalSizeProperty: Prim2DPropInfo;
  3404. static subdivisionsProperty: Prim2DPropInfo;
  3405. subdivisions: number;
  3406. protected levelIntersect(intersectInfo: IntersectInfo2D): boolean;
  3407. protected updateLevelBoundingInfo(): boolean;
  3408. /**
  3409. * Create an Ellipse 2D Shape primitive
  3410. * @param settings a combination of settings, possible ones are
  3411. * - 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)
  3412. * - children: an array of direct children
  3413. * - id: a text identifier, for information purpose
  3414. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  3415. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  3416. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  3417. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  3418. * - alignToPixel: if true the primitive will be aligned to the target rendering device's pixel
  3419. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  3420. * - zOrder: override the zOrder with the specified value
  3421. * - origin: define the normalized origin point location, default [0.5;0.5]
  3422. * - size: the size of the group. Alternatively the width and height properties can be set. Default will be [10;10].
  3423. * - subdivision: the number of subdivision to create the ellipse perimeter, default is 64.
  3424. * - 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)
  3425. * - 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)
  3426. * - borderThickness: the thickness of the drawn border, default is 1.
  3427. * - isVisible: true if the group must be visible, false for hidden. Default is true.
  3428. * - 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.
  3429. * - 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.
  3430. * - 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!
  3431. * - levelCollision: this primitive is an actor of the Collision Manager and only this level will be used for collision (i.e. not the children). Use deepCollision if you want collision detection on the primitives and its children.
  3432. * - deepCollision: this primitive is an actor of the Collision Manager, this level AND ALSO its children will be used for collision (note: you don't need to set the children as level/deepCollision).
  3433. * - layoutData: a instance of a class implementing the ILayoutData interface that contain data to pass to the primitive parent's layout engine
  3434. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3435. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3436. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3437. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3438. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  3439. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  3440. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  3441. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  3442. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3443. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3444. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3445. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3446. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  3447. */
  3448. constructor(settings?: {
  3449. parent?: Prim2DBase;
  3450. children?: Array<Prim2DBase>;
  3451. id?: string;
  3452. position?: Vector2;
  3453. x?: number;
  3454. y?: number;
  3455. rotation?: number;
  3456. scale?: number;
  3457. scaleX?: number;
  3458. scaleY?: number;
  3459. dontInheritParentScale?: boolean;
  3460. alignToPixel?: boolean;
  3461. opacity?: number;
  3462. zOrder?: number;
  3463. origin?: Vector2;
  3464. size?: Size;
  3465. width?: number;
  3466. height?: number;
  3467. subdivisions?: number;
  3468. fill?: IBrush2D | string;
  3469. border?: IBrush2D | string;
  3470. borderThickness?: number;
  3471. isVisible?: boolean;
  3472. isPickable?: boolean;
  3473. isContainer?: boolean;
  3474. childrenFlatZOrder?: boolean;
  3475. levelCollision?: boolean;
  3476. deepCollision?: boolean;
  3477. layoutData?: ILayoutData;
  3478. marginTop?: number | string;
  3479. marginLeft?: number | string;
  3480. marginRight?: number | string;
  3481. marginBottom?: number | string;
  3482. margin?: number | string;
  3483. marginHAlignment?: number;
  3484. marginVAlignment?: number;
  3485. marginAlignment?: string;
  3486. paddingTop?: number | string;
  3487. paddingLeft?: number | string;
  3488. paddingRight?: number | string;
  3489. paddingBottom?: number | string;
  3490. padding?: number | string;
  3491. });
  3492. protected updateTriArray(): void;
  3493. protected createModelRenderCache(modelKey: string): ModelRenderCache;
  3494. protected setupModelRenderCache(modelRenderCache: ModelRenderCache): Ellipse2DRenderCache;
  3495. protected createInstanceDataParts(): InstanceDataBase[];
  3496. private static _riv0;
  3497. protected refreshInstanceDataPart(part: InstanceDataBase): boolean;
  3498. private _subdivisions;
  3499. }
  3500. }
  3501. declare module BABYLON {
  3502. class Sprite2DRenderCache extends ModelRenderCache {
  3503. effectsReady: boolean;
  3504. vb: WebGLBuffer;
  3505. ib: WebGLBuffer;
  3506. instancingAttributes: InstancingAttributeInfo[];
  3507. texture: Texture;
  3508. effect: Effect;
  3509. effectInstanced: Effect;
  3510. render(instanceInfo: GroupInstanceInfo, context: Render2DContext): boolean;
  3511. dispose(): boolean;
  3512. }
  3513. class Sprite2D extends RenderablePrim2D {
  3514. static SPRITE2D_MAINPARTID: number;
  3515. static SHAPE2D_CATEGORY_SCALE9: string;
  3516. static textureProperty: Prim2DPropInfo;
  3517. static useAlphaFromTextureProperty: Prim2DPropInfo;
  3518. static actualSizeProperty: Prim2DPropInfo;
  3519. static spriteSizeProperty: Prim2DPropInfo;
  3520. static spriteLocationProperty: Prim2DPropInfo;
  3521. static spriteFrameProperty: Prim2DPropInfo;
  3522. static invertYProperty: Prim2DPropInfo;
  3523. static spriteScale9Property: Prim2DPropInfo;
  3524. texture: Texture;
  3525. useAlphaFromTexture: boolean;
  3526. size: Size;
  3527. spriteSize: Size;
  3528. spriteLocation: Vector2;
  3529. spriteFrame: number;
  3530. invertY: boolean;
  3531. readonly isScale9: boolean;
  3532. protected updateLevelBoundingInfo(): boolean;
  3533. /**
  3534. * Get the animatable array (see http://doc.babylonjs.com/tutorials/Animations)
  3535. */
  3536. getAnimatables(): IAnimatable[];
  3537. protected levelIntersect(intersectInfo: IntersectInfo2D): boolean;
  3538. readonly isSizeAuto: boolean;
  3539. /**
  3540. * Create an 2D Sprite primitive
  3541. * @param texture the texture that stores the sprite to render
  3542. * @param settings a combination of settings, possible ones are
  3543. * - 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)
  3544. * - children: an array of direct children
  3545. * - id a text identifier, for information purpose
  3546. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  3547. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  3548. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  3549. * - size: the size of the sprite displayed in the canvas, if not specified the spriteSize will be used
  3550. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  3551. * - 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.
  3552. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  3553. * - zOrder: override the zOrder with the specified value
  3554. * - origin: define the normalized origin point location, default [0.5;0.5]
  3555. * - spriteSize: the size of the sprite (in pixels) as it is stored in the texture, if null the size of the given texture will be used, default is null.
  3556. * - spriteLocation: the location (in pixels) in the texture of the top/left corner of the Sprite to display, default is null (0,0)
  3557. * - scale9: draw the sprite as a Scale9 sprite, see http://yannickloriot.com/2013/03/9-patch-technique-in-cocos2d/ for more info. x, y, w, z are left, bottom, right, top coordinate of the resizable box
  3558. * - invertY: if true the texture Y will be inverted, default is false.
  3559. * - isVisible: true if the sprite must be visible, false for hidden. Default is true.
  3560. * - 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.
  3561. * - 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.
  3562. * - 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!
  3563. * - levelCollision: this primitive is an actor of the Collision Manager and only this level will be used for collision (i.e. not the children). Use deepCollision if you want collision detection on the primitives and its children.
  3564. * - deepCollision: this primitive is an actor of the Collision Manager, this level AND ALSO its children will be used for collision (note: you don't need to set the children as level/deepCollision).
  3565. * - layoutData: a instance of a class implementing the ILayoutData interface that contain data to pass to the primitive parent's layout engine
  3566. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3567. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3568. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3569. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3570. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  3571. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  3572. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  3573. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  3574. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3575. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3576. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3577. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3578. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  3579. */
  3580. constructor(texture: Texture, settings?: {
  3581. parent?: Prim2DBase;
  3582. children?: Array<Prim2DBase>;
  3583. id?: string;
  3584. position?: Vector2;
  3585. x?: number;
  3586. y?: number;
  3587. rotation?: number;
  3588. size?: Size;
  3589. scale?: number;
  3590. scaleX?: number;
  3591. scaleY?: number;
  3592. dontInheritParentScale?: boolean;
  3593. alignToPixel?: boolean;
  3594. opacity?: number;
  3595. zOrder?: number;
  3596. origin?: Vector2;
  3597. spriteSize?: Size;
  3598. spriteLocation?: Vector2;
  3599. spriteScaleFactor?: Vector2;
  3600. scale9?: Vector4;
  3601. invertY?: boolean;
  3602. isVisible?: boolean;
  3603. isPickable?: boolean;
  3604. isContainer?: boolean;
  3605. childrenFlatZOrder?: boolean;
  3606. levelCollision?: boolean;
  3607. deepCollision?: boolean;
  3608. layoutData?: ILayoutData;
  3609. marginTop?: number | string;
  3610. marginLeft?: number | string;
  3611. marginRight?: number | string;
  3612. marginBottom?: number | string;
  3613. margin?: number | string;
  3614. marginHAlignment?: number;
  3615. marginVAlignment?: number;
  3616. marginAlignment?: string;
  3617. paddingTop?: number | string;
  3618. paddingLeft?: number | string;
  3619. paddingRight?: number | string;
  3620. paddingBottom?: number | string;
  3621. padding?: number | string;
  3622. });
  3623. protected createModelRenderCache(modelKey: string): ModelRenderCache;
  3624. protected setupModelRenderCache(modelRenderCache: ModelRenderCache): Sprite2DRenderCache;
  3625. protected getUsedShaderCategories(dataPart: InstanceDataBase): string[];
  3626. protected createInstanceDataParts(): InstanceDataBase[];
  3627. private static _prop;
  3628. private static layoutConstructMode;
  3629. protected beforeRefreshForLayoutConstruction(part: InstanceDataBase): any;
  3630. protected afterRefreshForLayoutConstruction(part: InstanceDataBase, obj: any): void;
  3631. protected refreshInstanceDataPart(part: InstanceDataBase): boolean;
  3632. protected _mustUpdateInstance(): boolean;
  3633. protected _useTextureAlpha(): boolean;
  3634. protected _shouldUseAlphaFromTexture(): boolean;
  3635. private _updateSpriteScaleFactor();
  3636. private _texture;
  3637. private _oldTextureHasAlpha;
  3638. private _useAlphaFromTexture;
  3639. private _useSize;
  3640. private _spriteLocation;
  3641. private _spriteSize;
  3642. private _spriteFrame;
  3643. private _scale9;
  3644. private _invertY;
  3645. }
  3646. class Sprite2DInstanceData extends InstanceDataBase {
  3647. constructor(partId: number);
  3648. topLeftUV: Vector2;
  3649. sizeUV: Vector2;
  3650. scaleFactor: Vector2;
  3651. textureSize: Vector2;
  3652. properties: Vector3;
  3653. scale9: Vector4;
  3654. }
  3655. }
  3656. declare module BABYLON {
  3657. /**
  3658. * Interface to create your own Loader of Atlas Data file.
  3659. * Call the AtlasPictureInfoFactory.addLoader to addd your loader instance
  3660. */
  3661. interface IAtlasLoader {
  3662. loadFile(content: any): {
  3663. api: AtlasPictureInfo;
  3664. errorMsg: string;
  3665. errorCode: number;
  3666. };
  3667. }
  3668. /**
  3669. * This class will contains information about a sub picture present in an Atlas Picture.
  3670. */
  3671. class AtlasSubPictureInfo {
  3672. /**
  3673. * Name of the SubPicture, generally the filename of the initial picture file.
  3674. */
  3675. name: string;
  3676. /**
  3677. * Location of the bottom/left corner of the sub picture from the bottom/left corner the Atlas Picture
  3678. */
  3679. location: Vector2;
  3680. /**
  3681. * Size in pixel of the sub picture
  3682. */
  3683. size: Size;
  3684. }
  3685. /**
  3686. * This class represent an Atlas Picture, it contains the information of all the sub pictures and the Texture that stores the bitmap.
  3687. * You get an instance of this class using methods of the AtlasPictureInfoFactory
  3688. */
  3689. class AtlasPictureInfo {
  3690. /**
  3691. * Creates many sprite from the Atlas Picture
  3692. * @param filterCallback a predicate if true is returned then the corresponding sub picture will be used to create a sprite.
  3693. * The Predicate has many parameters:
  3694. * - index: just an index incremented at each sub picture submitted for Sprite creation
  3695. * - name: the sub picture's name
  3696. * - aspi: the AtlasSubPictureInfo corresponding to the submitted sub picture
  3697. * - settings: the Sprite2D creation settings, you can alter this JSON object but BEWARE, the alterations will be kept for subsequent Sprite2D creations!
  3698. * @param spriteSettings The Sprite2D settings to use for Sprite creation, this JSON object will be passed to the filterCallback for you to alter it, if needed.
  3699. */
  3700. createSprites(filterCallback: (index: number, name: string, aspi: AtlasSubPictureInfo, settings: any) => boolean, spriteSettings: {
  3701. parent?: Prim2DBase;
  3702. position?: Vector2;
  3703. x?: number;
  3704. y?: number;
  3705. rotation?: number;
  3706. size?: Size;
  3707. scale?: number;
  3708. scaleX?: number;
  3709. scaleY?: number;
  3710. dontInheritParentScale?: boolean;
  3711. opacity?: number;
  3712. zOrder?: number;
  3713. origin?: Vector2;
  3714. scale9?: Vector4;
  3715. invertY?: boolean;
  3716. alignToPixel?: boolean;
  3717. isVisible?: boolean;
  3718. isPickable?: boolean;
  3719. isContainer?: boolean;
  3720. childrenFlatZOrder?: boolean;
  3721. marginTop?: number | string;
  3722. marginLeft?: number | string;
  3723. marginRight?: number | string;
  3724. marginBottom?: number | string;
  3725. margin?: number | string;
  3726. marginHAlignment?: number;
  3727. marginVAlignment?: number;
  3728. marginAlignment?: string;
  3729. paddingTop?: number | string;
  3730. paddingLeft?: number | string;
  3731. paddingRight?: number | string;
  3732. paddingBottom?: number | string;
  3733. padding?: string;
  3734. }): Array<Sprite2D>;
  3735. /**
  3736. * Create one Sprite from a sub picture
  3737. * @param subPictureName the name of the sub picture to use
  3738. * @param spriteSettings the Sprite2D settings to use for the Sprite instance creation
  3739. */
  3740. createSprite(subPictureName: string, spriteSettings: {
  3741. parent?: Prim2DBase;
  3742. position?: Vector2;
  3743. x?: number;
  3744. y?: number;
  3745. rotation?: number;
  3746. size?: Size;
  3747. scale?: number;
  3748. scaleX?: number;
  3749. scaleY?: number;
  3750. dontInheritParentScale?: boolean;
  3751. opacity?: number;
  3752. zOrder?: number;
  3753. origin?: Vector2;
  3754. scale9?: Vector4;
  3755. invertY?: boolean;
  3756. alignToPixel?: boolean;
  3757. isVisible?: boolean;
  3758. isPickable?: boolean;
  3759. isContainer?: boolean;
  3760. childrenFlatZOrder?: boolean;
  3761. marginTop?: number | string;
  3762. marginLeft?: number | string;
  3763. marginRight?: number | string;
  3764. marginBottom?: number | string;
  3765. margin?: number | string;
  3766. marginHAlignment?: number;
  3767. marginVAlignment?: number;
  3768. marginAlignment?: string;
  3769. paddingTop?: number | string;
  3770. paddingLeft?: number | string;
  3771. paddingRight?: number | string;
  3772. paddingBottom?: number | string;
  3773. padding?: string;
  3774. }): Sprite2D;
  3775. /**
  3776. * Size of the Atlas Picture
  3777. */
  3778. atlasSize: Size;
  3779. /**
  3780. * String Dictionary of all the sub pictures, the key is the sub picture's name, the value is the info object
  3781. */
  3782. subPictures: StringDictionary<AtlasSubPictureInfo>;
  3783. /**
  3784. * The Texture associated to the Atlas Picture info
  3785. */
  3786. texture: Texture;
  3787. }
  3788. /**
  3789. * This if the Factory class containing static method to create Atlas Pictures Info objects or add new loaders
  3790. */
  3791. class AtlasPictureInfoFactory {
  3792. /**
  3793. * Add a custom loader
  3794. * @param fileExtension must be the file extension (without the dot) of the file that is loaded by this loader (e.g.: json)
  3795. * @param plugin the instance of the loader
  3796. */
  3797. static addLoader(fileExtension: string, plugin: IAtlasLoader): void;
  3798. /**
  3799. * Load an Atlas Picture Info object from a data file at a given url and with a given texture
  3800. * @param texture the texture containing the atlas bitmap
  3801. * @param url the URL of the Atlas Info data file
  3802. * @param onLoad a callback that will be called when the AtlasPictureInfo object will be loaded and ready
  3803. * @param onError a callback that will be called in case of error
  3804. */
  3805. static loadFromUrl(texture: Texture, url: string, onLoad: (api: AtlasPictureInfo) => void, onError?: (msg: string, code: number) => void): any;
  3806. private static plugins;
  3807. }
  3808. /**
  3809. * Use this decorator when you declare an Atlas Loader Class for the loader to register itself automatically.
  3810. * @param fileExtension the extension of the file that the plugin is loading (there can be many plugin for the same extension)
  3811. * @param plugin an instance of the plugin class to add to the AtlasPictureInfoFactory
  3812. */
  3813. function AtlasLoaderPlugin(fileExtension: string, plugin: IAtlasLoader): (target: Object) => void;
  3814. }
  3815. declare module BABYLON {
  3816. class Text2DRenderCache extends ModelRenderCache {
  3817. effectsReady: boolean;
  3818. vb: WebGLBuffer;
  3819. ib: WebGLBuffer;
  3820. instancingAttributes: InstancingAttributeInfo[];
  3821. fontTexture: BaseFontTexture;
  3822. effect: Effect;
  3823. effectInstanced: Effect;
  3824. fontPremulAlpha: boolean;
  3825. render(instanceInfo: GroupInstanceInfo, context: Render2DContext): boolean;
  3826. dispose(): boolean;
  3827. }
  3828. class Text2DInstanceData extends InstanceDataBase {
  3829. constructor(partId: number, dataElementCount: number);
  3830. topLeftUV: Vector2;
  3831. sizeUV: Vector2;
  3832. textureSize: Vector2;
  3833. color: Color4;
  3834. superSampleFactor: number;
  3835. }
  3836. class Text2D extends RenderablePrim2D {
  3837. static TEXT2D_MAINPARTID: number;
  3838. static TEXT2D_CATEGORY_SDF: string;
  3839. static TEXT2D_CATEGORY_FONTTEXTURE: string;
  3840. static fontProperty: Prim2DPropInfo;
  3841. static defaultFontColorProperty: Prim2DPropInfo;
  3842. static textProperty: Prim2DPropInfo;
  3843. static sizeProperty: Prim2DPropInfo;
  3844. static fontSuperSampleProperty: Prim2DPropInfo;
  3845. static fontSignedDistanceFieldProperty: Prim2DPropInfo;
  3846. static textureIsPremulAlphaProperty: Prim2DPropInfo;
  3847. static fontTextureProperty: Prim2DPropInfo;
  3848. /**
  3849. * Alignment is made relative to the left edge of the Content Area. Valid for horizontal alignment only.
  3850. */
  3851. static readonly AlignLeft: number;
  3852. /**
  3853. * Alignment is made relative to the top edge of the Content Area. Valid for vertical alignment only.
  3854. */
  3855. static readonly AlignTop: number;
  3856. /**
  3857. * Alignment is made relative to the right edge of the Content Area. Valid for horizontal alignment only.
  3858. */
  3859. static readonly AlignRight: number;
  3860. /**
  3861. * Alignment is made relative to the bottom edge of the Content Area. Valid for vertical alignment only.
  3862. */
  3863. static readonly AlignBottom: number;
  3864. /**
  3865. * Alignment is made to center the text from equal distance to the opposite edges of the Content Area
  3866. */
  3867. static readonly AlignCenter: number;
  3868. private static _AlignLeft;
  3869. private static _AlignTop;
  3870. private static _AlignRight;
  3871. private static _AlignBottom;
  3872. private static _AlignCenter;
  3873. fontName: string;
  3874. defaultFontColor: Color4;
  3875. text: string;
  3876. size: Size;
  3877. readonly fontSuperSample: boolean;
  3878. readonly fontSignedDistanceField: boolean;
  3879. textureIsPremulAlpha: boolean;
  3880. readonly isSizeAuto: boolean;
  3881. readonly isVerticalSizeAuto: boolean;
  3882. readonly isHorizontalSizeAuto: boolean;
  3883. /**
  3884. * Get the area that bounds the text associated to the primitive
  3885. */
  3886. readonly textSize: Size;
  3887. protected onSetOwner(): void;
  3888. readonly fontTexture: BaseFontTexture;
  3889. /**
  3890. * Dispose the primitive, remove it from its parent
  3891. */
  3892. dispose(): boolean;
  3893. protected updateLevelBoundingInfo(): boolean;
  3894. /**
  3895. * You can get/set the text alignment through this property
  3896. */
  3897. textAlignment: string;
  3898. /**
  3899. * Create a Text primitive
  3900. * @param text the text to display
  3901. * @param settings a combination of settings, possible ones are
  3902. * - 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)
  3903. * - children: an array of direct children
  3904. * - id a text identifier, for information purpose
  3905. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  3906. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  3907. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  3908. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  3909. * - alignToPixel: if true the primitive will be aligned to the target rendering device's pixel
  3910. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  3911. * - zOrder: override the zOrder with the specified value
  3912. * - origin: define the normalized origin point location, default [0.5;0.5]
  3913. * - fontName: the name/size/style of the font to use, following the CSS notation. Default is "12pt Arial".
  3914. * - 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.
  3915. * - 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.
  3916. * - bitmapFontTexture: set a BitmapFontTexture to use instead of a fontName.
  3917. * - defaultFontColor: the color by default to apply on each letter of the text to display, default is plain white.
  3918. * - useBilinearFiltering: if true a FontTexture using Bilinear filtering will be used, if false a FontTexture using Nearest filtering will be used. If not specified then bilinear will be chosen for Signed Distance Field mode or a Text2D inside a WorldSpaceCanvas2D, otherwise nearest will be chose.
  3919. * - areaSize: the size of the area in which to display the text, default is auto-fit from text content.
  3920. * - tabulationSize: number of space character to insert when a tabulation is encountered, default is 4
  3921. * - isVisible: true if the text must be visible, false for hidden. Default is true.
  3922. * - 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.
  3923. * - 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.
  3924. * - 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!
  3925. * - levelCollision: this primitive is an actor of the Collision Manager and only this level will be used for collision (i.e. not the children). Use deepCollision if you want collision detection on the primitives and its children.
  3926. * - deepCollision: this primitive is an actor of the Collision Manager, this level AND ALSO its children will be used for collision (note: you don't need to set the children as level/deepCollision).
  3927. * - layoutData: a instance of a class implementing the ILayoutData interface that contain data to pass to the primitive parent's layout engine
  3928. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3929. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3930. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3931. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3932. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  3933. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  3934. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  3935. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  3936. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3937. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3938. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3939. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  3940. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  3941. * - textAlignmentH: align text horizontally (Text2D.AlignLeft, Text2D.AlignCenter, Text2D.AlignRight)
  3942. * - textAlignmentV: align text vertically (Text2D.AlignTop, Text2D.AlignCenter, Text2D.AlignBottom)
  3943. * - textAlignment: a string defining the text alignment, text can be: [<h:|horizontal:><left|right|center>], [<v:|vertical:><top|bottom|center>]
  3944. * - wordWrap: if true the text will wrap inside content area
  3945. */
  3946. constructor(text: string, settings?: {
  3947. parent?: Prim2DBase;
  3948. children?: Array<Prim2DBase>;
  3949. id?: string;
  3950. position?: Vector2;
  3951. x?: number;
  3952. y?: number;
  3953. rotation?: number;
  3954. scale?: number;
  3955. scaleX?: number;
  3956. scaleY?: number;
  3957. dontInheritParentScale?: boolean;
  3958. alignToPixel?: boolean;
  3959. opacity?: number;
  3960. zOrder?: number;
  3961. origin?: Vector2;
  3962. fontName?: string;
  3963. fontSuperSample?: boolean;
  3964. fontSignedDistanceField?: boolean;
  3965. bitmapFontTexture?: BitmapFontTexture;
  3966. defaultFontColor?: Color4;
  3967. useBilinearFiltering?: boolean;
  3968. size?: Size;
  3969. tabulationSize?: number;
  3970. isVisible?: boolean;
  3971. isPickable?: boolean;
  3972. isContainer?: boolean;
  3973. childrenFlatZOrder?: boolean;
  3974. levelCollision?: boolean;
  3975. deepCollision?: boolean;
  3976. layoutData?: ILayoutData;
  3977. marginTop?: number | string;
  3978. marginLeft?: number | string;
  3979. marginRight?: number | string;
  3980. marginBottom?: number | string;
  3981. margin?: number | string;
  3982. marginHAlignment?: number;
  3983. marginVAlignment?: number;
  3984. marginAlignment?: string;
  3985. paddingTop?: number | string;
  3986. paddingLeft?: number | string;
  3987. paddingRight?: number | string;
  3988. paddingBottom?: number | string;
  3989. padding?: number | string;
  3990. textAlignmentH?: number;
  3991. textAlignmentV?: number;
  3992. textAlignment?: string;
  3993. wordWrap?: boolean;
  3994. });
  3995. protected levelIntersect(intersectInfo: IntersectInfo2D): boolean;
  3996. protected createModelRenderCache(modelKey: string): ModelRenderCache;
  3997. protected setupModelRenderCache(modelRenderCache: ModelRenderCache): Text2DRenderCache;
  3998. protected createInstanceDataParts(): InstanceDataBase[];
  3999. protected beforeRefreshForLayoutConstruction(part: InstanceDataBase): any;
  4000. protected afterRefreshForLayoutConstruction(part: InstanceDataBase, obj: any): void;
  4001. protected getUsedShaderCategories(dataPart: InstanceDataBase): string[];
  4002. protected refreshInstanceDataPart(part: InstanceDataBase): boolean;
  4003. private _isWhiteSpaceCharHoriz(char);
  4004. private _isWhiteSpaceCharVert(char);
  4005. private _updateCharCount();
  4006. private _setTextAlignmentfromString(value);
  4007. private _setTextAlignmentHorizontal(text);
  4008. private _setTextAlignmentVertical(text);
  4009. protected _useTextureAlpha(): boolean;
  4010. protected _shouldUseAlphaFromTexture(): boolean;
  4011. private _fontTexture;
  4012. private _tabulationSize;
  4013. private _charCount;
  4014. private _fontName;
  4015. private _fontSuperSample;
  4016. private _fontSDF;
  4017. private _defaultFontColor;
  4018. private _text;
  4019. private _textSize;
  4020. private _wordWrap;
  4021. private _textAlignment;
  4022. private _sizeSetByUser;
  4023. private _textureIsPremulAlpha;
  4024. private _useBilinearFiltering;
  4025. private _fontBilinearFiltering;
  4026. textAlignmentH: number;
  4027. textAlignmentV: number;
  4028. }
  4029. }
  4030. declare module BABYLON {
  4031. class Lines2DRenderCache extends ModelRenderCache {
  4032. effectsReady: boolean;
  4033. fillVB: WebGLBuffer;
  4034. fillIB: WebGLBuffer;
  4035. fillIndicesCount: number;
  4036. instancingFillAttributes: InstancingAttributeInfo[];
  4037. effectFill: Effect;
  4038. effectFillInstanced: Effect;
  4039. borderVB: WebGLBuffer;
  4040. borderIB: WebGLBuffer;
  4041. borderIndicesCount: number;
  4042. instancingBorderAttributes: InstancingAttributeInfo[];
  4043. effectBorder: Effect;
  4044. effectBorderInstanced: Effect;
  4045. constructor(engine: Engine, modelKey: string);
  4046. render(instanceInfo: GroupInstanceInfo, context: Render2DContext): boolean;
  4047. dispose(): boolean;
  4048. }
  4049. class Lines2DInstanceData extends Shape2DInstanceData {
  4050. constructor(partId: number);
  4051. boundingMin: Vector2;
  4052. boundingMax: Vector2;
  4053. }
  4054. class Lines2D extends Shape2D {
  4055. /**
  4056. * No Cap to apply on the extremity
  4057. */
  4058. static readonly NoCap: number;
  4059. /**
  4060. * A round cap, will use the line thickness as diameter
  4061. */
  4062. static readonly RoundCap: number;
  4063. /**
  4064. * Creates a triangle at the extremity.
  4065. */
  4066. static readonly TriangleCap: number;
  4067. /**
  4068. * Creates a Square anchor at the extremity, the square size is twice the thickness of the line
  4069. */
  4070. static readonly SquareAnchorCap: number;
  4071. /**
  4072. * Creates a round anchor at the extremity, the diameter is twice the thickness of the line
  4073. */
  4074. static readonly RoundAnchorCap: number;
  4075. /**
  4076. * Creates a diamond anchor at the extremity.
  4077. */
  4078. static readonly DiamondAnchorCap: number;
  4079. /**
  4080. * Creates an arrow anchor at the extremity. the arrow base size is twice the thickness of the line
  4081. */
  4082. static readonly ArrowCap: number;
  4083. static pointsProperty: Prim2DPropInfo;
  4084. static fillThicknessProperty: Prim2DPropInfo;
  4085. static closedProperty: Prim2DPropInfo;
  4086. static startCapProperty: Prim2DPropInfo;
  4087. static endCapProperty: Prim2DPropInfo;
  4088. points: Vector2[];
  4089. fillThickness: number;
  4090. closed: boolean;
  4091. startCap: number;
  4092. endCap: number;
  4093. private static _prevA;
  4094. private static _prevB;
  4095. private static _curA;
  4096. private static _curB;
  4097. protected levelIntersect(intersectInfo: IntersectInfo2D): boolean;
  4098. protected readonly boundingMin: Vector2;
  4099. protected readonly boundingMax: Vector2;
  4100. protected getUsedShaderCategories(dataPart: InstanceDataBase): string[];
  4101. protected updateLevelBoundingInfo(): boolean;
  4102. /**
  4103. * Create an 2D Lines Shape primitive. The defined lines may be opened or closed (see below)
  4104. * @param points an array that describe the points to use to draw the line, must contain at least two entries.
  4105. * @param settings a combination of settings, possible ones are
  4106. * - 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)
  4107. * - children: an array of direct children
  4108. * - id a text identifier, for information purpose
  4109. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  4110. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  4111. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  4112. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  4113. * - alignToPixel: if true the primitive will be aligned to the target rendering device's pixel
  4114. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  4115. * - zOrder: override the zOrder with the specified value
  4116. * - origin: define the normalized origin point location, default [0.5;0.5]
  4117. * - 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.
  4118. * - 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.
  4119. * - 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.
  4120. * - 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.
  4121. * - 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)
  4122. * - 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)
  4123. * - borderThickness: the thickness of the drawn border, default is 1.
  4124. * - isVisible: true if the primitive must be visible, false for hidden. Default is true.
  4125. * - 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.
  4126. * - 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.
  4127. * - 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!
  4128. * - levelCollision: this primitive is an actor of the Collision Manager and only this level will be used for collision (i.e. not the children). Use deepCollision if you want collision detection on the primitives and its children.
  4129. * - deepCollision: this primitive is an actor of the Collision Manager, this level AND ALSO its children will be used for collision (note: you don't need to set the children as level/deepCollision).
  4130. * - layoutData: a instance of a class implementing the ILayoutData interface that contain data to pass to the primitive parent's layout engine
  4131. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  4132. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  4133. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  4134. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  4135. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  4136. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  4137. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  4138. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  4139. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  4140. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  4141. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  4142. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  4143. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  4144. */
  4145. constructor(points: Vector2[], settings?: {
  4146. parent?: Prim2DBase;
  4147. children?: Array<Prim2DBase>;
  4148. id?: string;
  4149. position?: Vector2;
  4150. x?: number;
  4151. y?: number;
  4152. rotation?: number;
  4153. scale?: number;
  4154. scaleX?: number;
  4155. scaleY?: number;
  4156. dontInheritParentScale?: boolean;
  4157. alignToPixel?: boolean;
  4158. opacity?: number;
  4159. zOrder?: number;
  4160. origin?: Vector2;
  4161. fillThickness?: number;
  4162. closed?: boolean;
  4163. startCap?: number;
  4164. endCap?: number;
  4165. fill?: IBrush2D | string;
  4166. border?: IBrush2D | string;
  4167. borderThickness?: number;
  4168. isVisible?: boolean;
  4169. isPickable?: boolean;
  4170. isContainer?: boolean;
  4171. childrenFlatZOrder?: boolean;
  4172. levelCollision?: boolean;
  4173. deepCollision?: boolean;
  4174. layoutData?: ILayoutData;
  4175. marginTop?: number | string;
  4176. marginLeft?: number | string;
  4177. marginRight?: number | string;
  4178. marginBottom?: number | string;
  4179. margin?: number | string;
  4180. marginHAlignment?: number;
  4181. marginVAlignment?: number;
  4182. marginAlignment?: string;
  4183. paddingTop?: number | string;
  4184. paddingLeft?: number | string;
  4185. paddingRight?: number | string;
  4186. paddingBottom?: number | string;
  4187. padding?: number | string;
  4188. });
  4189. protected createModelRenderCache(modelKey: string): ModelRenderCache;
  4190. private _perp(v, res);
  4191. private _direction(a, b, res);
  4192. private static _miterTps;
  4193. private _computeMiter(tangent, miter, a, b);
  4194. private _intersect(x1, y1, x2, y2, x3, y3, x4, y4);
  4195. private _updateMinMax(array, offset);
  4196. private static _startDir;
  4197. private static _endDir;
  4198. private _store(array, contour, index, max, p, n, halfThickness, borderThickness, detectFlip?);
  4199. private _getCapSize(type, border?);
  4200. private static _tpsV;
  4201. private _storeVertex(vb, baseOffset, index, basePos, rotation, vertex, contour);
  4202. private _storeIndex(ib, baseOffset, index, vertexIndex);
  4203. private _buildCap(vb, vbi, ib, ibi, pos, thickness, borderThickness, type, capDir, contour);
  4204. private _buildLine(vb, contour, ht, bt?);
  4205. protected setupModelRenderCache(modelRenderCache: ModelRenderCache): Lines2DRenderCache;
  4206. protected updateTriArray(): void;
  4207. private _computeLines2D();
  4208. readonly size: Size;
  4209. protected createInstanceDataParts(): InstanceDataBase[];
  4210. protected applyActualScaleOnTransform(): boolean;
  4211. protected refreshInstanceDataPart(part: InstanceDataBase): boolean;
  4212. private static _noCap;
  4213. private static _roundCap;
  4214. private static _triangleCap;
  4215. private static _squareAnchorCap;
  4216. private static _roundAnchorCap;
  4217. private static _diamondAnchorCap;
  4218. private static _arrowCap;
  4219. private static _roundCapSubDiv;
  4220. private _fillVB;
  4221. private _fillIB;
  4222. private _borderVB;
  4223. private _borderIB;
  4224. private _boundingMin;
  4225. private _boundingMax;
  4226. private _closed;
  4227. private _startCap;
  4228. private _endCap;
  4229. private _fillThickness;
  4230. private _points;
  4231. }
  4232. }
  4233. declare module BABYLON {
  4234. class Canvas2DEngineBoundData {
  4235. GetOrAddModelCache<TInstData>(key: string, factory: (key: string) => ModelRenderCache): ModelRenderCache;
  4236. private _modelCache;
  4237. DisposeModelRenderCache(modelRenderCache: ModelRenderCache): boolean;
  4238. }
  4239. abstract class Canvas2D extends Group2D {
  4240. /**
  4241. * 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.
  4242. * This strategy doesn't allow primitives added directly as children of the Canvas.
  4243. * 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.
  4244. */
  4245. static CACHESTRATEGY_TOPLEVELGROUPS: number;
  4246. /**
  4247. * In this strategy each group will have its own cache bitmap (except if a given group explicitly defines the DONTCACHEOVERRIDE or CACHEINPARENTGROUP behaviors).
  4248. * 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.
  4249. * When using this strategy, group instances can rely on the DONTCACHEOVERRIDE or CACHEINPARENTGROUP behaviors to minimize the amount of cached bitmaps.
  4250. * 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.
  4251. */
  4252. static CACHESTRATEGY_ALLGROUPS: number;
  4253. /**
  4254. * 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).
  4255. */
  4256. static CACHESTRATEGY_CANVAS: number;
  4257. /**
  4258. * This strategy is used to recompose/redraw the canvas entirely at each viewport render.
  4259. * 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).
  4260. * Note that you can't use this strategy for WorldSpace Canvas, they need at least a top level group caching.
  4261. */
  4262. static CACHESTRATEGY_DONTCACHE: number;
  4263. /**
  4264. * Observable Mask to be notified before rendering is made
  4265. */
  4266. static RENDEROBSERVABLE_PRE: number;
  4267. /**
  4268. * Observable Mask to be notified after rendering is made
  4269. */
  4270. static RENDEROBSERVABLE_POST: number;
  4271. private static _INSTANCES;
  4272. constructor(scene: Scene, settings?: {
  4273. id?: string;
  4274. children?: Array<Prim2DBase>;
  4275. size?: Size;
  4276. renderingPhase?: {
  4277. camera: Camera;
  4278. renderingGroupID: number;
  4279. };
  4280. designSize?: Size;
  4281. designUseHorizAxis?: boolean;
  4282. isScreenSpace?: boolean;
  4283. cachingStrategy?: number;
  4284. enableInteraction?: boolean;
  4285. enableCollisionManager?: boolean;
  4286. customCollisionManager?: (owner: Canvas2D, enableBorders: boolean) => PrimitiveCollisionManagerBase;
  4287. collisionManagerUseBorders?: boolean;
  4288. origin?: Vector2;
  4289. isVisible?: boolean;
  4290. backgroundRoundRadius?: number;
  4291. backgroundFill?: IBrush2D | string;
  4292. backgroundBorder?: IBrush2D | string;
  4293. backgroundBorderThickNess?: number;
  4294. });
  4295. readonly drawCallsOpaqueCounter: PerfCounter;
  4296. readonly drawCallsAlphaTestCounter: PerfCounter;
  4297. readonly drawCallsTransparentCounter: PerfCounter;
  4298. readonly groupRenderCounter: PerfCounter;
  4299. readonly updateTransparentDataCounter: PerfCounter;
  4300. readonly updateCachedStateCounter: PerfCounter;
  4301. readonly updateLayoutCounter: PerfCounter;
  4302. readonly updatePositioningCounter: PerfCounter;
  4303. readonly updateLocalTransformCounter: PerfCounter;
  4304. readonly updateGlobalTransformCounter: PerfCounter;
  4305. readonly boundingInfoRecomputeCounter: PerfCounter;
  4306. readonly layoutBoundingInfoUpdateCounter: PerfCounter;
  4307. readonly canvasRenderTimeCounter: PerfCounter;
  4308. static readonly instances: Array<Canvas2D>;
  4309. readonly primitiveCollisionManager: PrimitiveCollisionManagerBase;
  4310. protected _canvasPreInit(settings: any): void;
  4311. static _zMinDelta: number;
  4312. private _setupInteraction(enable);
  4313. /**
  4314. * 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.
  4315. * Beware that you have to take under consideration the origin and unitScaleFactor in your calculations! Good luck!
  4316. */
  4317. worldSpaceToNodeLocal: (worldPos: Vector3) => Vector2;
  4318. /**
  4319. * 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
  4320. */
  4321. worldSpaceCacheChanged: () => void;
  4322. /**
  4323. * Internal method, you should use the Prim2DBase version instead
  4324. */
  4325. _setPointerCapture(pointerId: number, primitive: Prim2DBase): boolean;
  4326. /**
  4327. * Internal method, you should use the Prim2DBase version instead
  4328. */
  4329. _releasePointerCapture(pointerId: number, primitive: Prim2DBase): boolean;
  4330. /**
  4331. * Determine if the given pointer is captured or not
  4332. * @param pointerId the Id of the pointer
  4333. * @return true if it's captured, false otherwise
  4334. */
  4335. isPointerCaptured(pointerId: number): boolean;
  4336. private getCapturedPrimitive(pointerId);
  4337. private static _interInfo;
  4338. private _handlePointerEventForInteraction(eventData, localPosition, eventState);
  4339. private _updatePointerInfo(eventData, localPosition);
  4340. private _updateIntersectionList(mouseLocalPos, isCapture, force);
  4341. private _updateOverStatus(force);
  4342. private _updatePrimPointerPos(prim);
  4343. private _notifDebugMode;
  4344. private _debugExecObserver(prim, mask);
  4345. private _bubbleNotifyPrimPointerObserver(prim, mask, eventData);
  4346. private _triggerActionManager(prim, ppi, mask, eventData);
  4347. /**
  4348. * Don't forget to call the dispose method when you're done with the Canvas instance.
  4349. * But don't worry, if you dispose its scene, the canvas will be automatically disposed too.
  4350. */
  4351. dispose(): boolean;
  4352. /**
  4353. * Accessor to the Scene that owns the Canvas
  4354. * @returns The instance of the Scene object
  4355. */
  4356. readonly scene: Scene;
  4357. /**
  4358. * Accessor to the Engine that drives the Scene used by this Canvas
  4359. * @returns The instance of the Engine object
  4360. */
  4361. readonly engine: Engine;
  4362. /**
  4363. * And observable called during the Canvas rendering process.
  4364. * This observable is called twice per render, each time with a different mask:
  4365. * - 1: before render is executed
  4366. * - 2: after render is executed
  4367. */
  4368. readonly renderObservable: Observable<Canvas2D>;
  4369. /**
  4370. * Accessor of the Caching Strategy used by this Canvas.
  4371. * See Canvas2D.CACHESTRATEGY_xxxx static members for more information
  4372. * @returns the value corresponding to the used strategy.
  4373. */
  4374. readonly cachingStrategy: number;
  4375. /**
  4376. * Return true if the Canvas is a Screen Space one, false if it's a World Space one.
  4377. * @returns {}
  4378. */
  4379. readonly isScreenSpace: boolean;
  4380. /**
  4381. * Only valid for World Space Canvas, returns the scene node that displays the canvas
  4382. */
  4383. worldSpaceCanvasNode: Node;
  4384. /**
  4385. * Check if the WebGL Instanced Array extension is supported or not
  4386. */
  4387. readonly supportInstancedArray: boolean;
  4388. /**
  4389. * Property that defines the fill object used to draw the background of the Canvas.
  4390. * Note that Canvas with a Caching Strategy of
  4391. * @returns If the background is not set, null will be returned, otherwise a valid fill object is returned.
  4392. */
  4393. backgroundFill: IBrush2D;
  4394. /**
  4395. * Property that defines the border object used to draw the background of the Canvas.
  4396. * @returns If the background is not set, null will be returned, otherwise a valid border object is returned.
  4397. */
  4398. backgroundBorder: IBrush2D;
  4399. /**
  4400. * Property that defines the thickness of the border object used to draw the background of the Canvas.
  4401. * @returns If the background is not set, null will be returned, otherwise a valid number matching the thickness is returned.
  4402. */
  4403. backgroundBorderThickness: number;
  4404. /**
  4405. * You can set the roundRadius of the background
  4406. * @returns The current roundRadius
  4407. */
  4408. backgroundRoundRadius: number;
  4409. /**
  4410. * Enable/Disable interaction for this Canvas
  4411. * When enabled the Prim2DBase.pointerEventObservable property will notified when appropriate events occur
  4412. */
  4413. interactionEnabled: boolean;
  4414. readonly fitRenderingDevice: boolean;
  4415. readonly designSize: Size;
  4416. readonly designSizeUseHorizAxis: boolean;
  4417. designSizeUseHorizeAxis: boolean;
  4418. /**
  4419. * Return
  4420. */
  4421. readonly overPrim: Prim2DBase;
  4422. /**
  4423. * Access the babylon.js' engine bound data, do not invoke this method, it's for internal purpose only
  4424. * @returns {}
  4425. */
  4426. readonly _engineData: Canvas2DEngineBoundData;
  4427. readonly unitScaleFactor: number;
  4428. createCanvasProfileInfoCanvas(): Canvas2D;
  4429. /**
  4430. * Instanced Array will be create if there's at least this number of parts/prim that can fit into it
  4431. */
  4432. minPartCountToUseInstancedArray: number;
  4433. private checkBackgroundAvailability();
  4434. private _initPerfMetrics();
  4435. private _fetchPerfMetrics();
  4436. private _updateProfileCanvas();
  4437. _addDrawCallCount(count: number, renderMode: number): void;
  4438. _addGroupRenderCount(count: number): void;
  4439. _addUpdateTransparentDataCount(count: number): void;
  4440. addUpdateCachedStateCounter(count: number): void;
  4441. addUpdateLayoutCounter(count: number): void;
  4442. addUpdatePositioningCounter(count: number): void;
  4443. addupdateLocalTransformCounter(count: number): void;
  4444. addUpdateGlobalTransformCounter(count: number): void;
  4445. addLayoutBoundingInfoUpdateCounter(count: number): void;
  4446. private _renderObservable;
  4447. private __engineData;
  4448. private _interactionEnabled;
  4449. private _primPointerInfo;
  4450. private _updateRenderId;
  4451. private _intersectionRenderId;
  4452. private _hoverStatusRenderId;
  4453. private _pickStartingPosition;
  4454. private _pickedDownPrim;
  4455. private _pickStartingTime;
  4456. private _previousIntersectionList;
  4457. private _actualIntersectionList;
  4458. private _previousOverPrimitive;
  4459. private _actualOverPrimitive;
  4460. private _capturedPointers;
  4461. private _scenePrePointerObserver;
  4462. private _scenePointerObserver;
  4463. protected _worldSpaceNode: Node;
  4464. private _mapCounter;
  4465. private _background;
  4466. private _scene;
  4467. private _engine;
  4468. private _fitRenderingDevice;
  4469. private _isScreenSpace;
  4470. private _cachedCanvasGroup;
  4471. private _cachingStrategy;
  4472. private _hierarchyLevelMaxSiblingCount;
  4473. private _groupCacheMaps;
  4474. private _renderingGroupObserver;
  4475. private _beforeRenderObserver;
  4476. private _afterRenderObserver;
  4477. private _supprtInstancedArray;
  4478. protected _unitScaleFactor: number;
  4479. private _trackedGroups;
  4480. protected _trackNode: Node;
  4481. protected _trackNodeOffset: Vector3;
  4482. protected _trackNodeBillboard: boolean;
  4483. protected _maxAdaptiveWorldSpaceCanvasSize: number;
  4484. private _designSize;
  4485. private _designUseHorizAxis;
  4486. _primitiveCollisionManager: PrimitiveCollisionManagerBase;
  4487. _canvasLevelScale: Vector2;
  4488. _renderingSize: Size;
  4489. private _curHWScale;
  4490. private _drawCallsOpaqueCounter;
  4491. private _drawCallsAlphaTestCounter;
  4492. private _drawCallsTransparentCounter;
  4493. private _groupRenderCounter;
  4494. private _updateTransparentDataCounter;
  4495. private _updateCachedStateCounter;
  4496. private _updateLayoutCounter;
  4497. private _updatePositioningCounter;
  4498. private _updateGlobalTransformCounter;
  4499. private _updateLocalTransformCounter;
  4500. private _boundingInfoRecomputeCounter;
  4501. private _layoutBoundingInfoUpdateCounter;
  4502. private _canvasRenderTimeCounter;
  4503. private _profilingCanvas;
  4504. private _profileInfoText;
  4505. private static _v;
  4506. private static _cv1;
  4507. private static _m;
  4508. private static _mI;
  4509. private static tS;
  4510. private static tT;
  4511. private static tR;
  4512. private static _tmpMtx;
  4513. private static _tmpVec3;
  4514. private _updateTrackedNodes();
  4515. /**
  4516. * Call this method change you want to have layout related data computed and up to date (layout area, primitive area, local/global transformation matrices)
  4517. */
  4518. updateCanvasLayout(forceRecompute: boolean): void;
  4519. private _updateAdaptiveSizeWorldCanvas();
  4520. private static _pCLS;
  4521. private _updateCanvasState(forceRecompute);
  4522. /**
  4523. * Method that renders the Canvas, you should not invoke
  4524. */
  4525. private _render();
  4526. /**
  4527. * Internal method that allocate a cache for the given group.
  4528. * Caching is made using a collection of MapTexture where many groups have their bitmap cache stored inside.
  4529. * @param group The group to allocate the cache of.
  4530. * @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.
  4531. */
  4532. _allocateGroupCache(group: Group2D, parent: Group2D, minSize?: Size, useMipMap?: boolean, anisotropicLevel?: number): {
  4533. node: PackedRect;
  4534. texture: MapTexture;
  4535. sprite: Sprite2D;
  4536. };
  4537. /**
  4538. * Define the default size used for both the width and height of a MapTexture to allocate.
  4539. * Note that some MapTexture might be bigger than this size if the first node to allocate is bigger in width or height
  4540. */
  4541. private static _groupTextureCacheSize;
  4542. /**
  4543. * Internal method used to register a Scene Node to track position for the given group
  4544. * Do not invoke this method, for internal purpose only.
  4545. * @param group the group to track its associated Scene Node
  4546. */
  4547. _registerTrackedNode(group: Group2D): void;
  4548. /**
  4549. * Internal method used to unregister a tracked Scene Node
  4550. * Do not invoke this method, it's for internal purpose only.
  4551. * @param group the group to unregister its tracked Scene Node from.
  4552. */
  4553. _unregisterTrackedNode(group: Group2D): void;
  4554. /**
  4555. * Get a Solid Color Brush instance matching the given color.
  4556. * @param color The color to retrieve
  4557. * @return A shared instance of the SolidColorBrush2D class that use the given color
  4558. */
  4559. static GetSolidColorBrush(color: Color4): IBrush2D;
  4560. /**
  4561. * Get a Solid Color Brush instance matching the given color expressed as a CSS formatted hexadecimal value.
  4562. * @param color The color to retrieve
  4563. * @return A shared instance of the SolidColorBrush2D class that uses the given color
  4564. */
  4565. static GetSolidColorBrushFromHex(hexValue: string): IBrush2D;
  4566. /**
  4567. * Get a Gradient Color Brush
  4568. * @param color1 starting color
  4569. * @param color2 engine color
  4570. * @param translation translation vector to apply. default is [0;0]
  4571. * @param rotation rotation in radian to apply to the brush, initial direction is top to bottom. rotation is counter clockwise. default is 0.
  4572. * @param scale scaling factor to apply. default is 1.
  4573. */
  4574. static GetGradientColorBrush(color1: Color4, color2: Color4, translation?: Vector2, rotation?: number, scale?: number): IBrush2D;
  4575. /**
  4576. * Create a solid or gradient brush from a string value.
  4577. * @param brushString should be either
  4578. * - "solid: #RRGGBBAA" or "#RRGGBBAA"
  4579. * - "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.
  4580. */
  4581. static GetBrushFromString(brushString: string): IBrush2D;
  4582. private static _solidColorBrushes;
  4583. private static _gradientColorBrushes;
  4584. }
  4585. class WorldSpaceCanvas2D extends Canvas2D {
  4586. /**
  4587. * 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.
  4588. * 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.
  4589. * @param scene the Scene that owns the Canvas
  4590. * @param size the dimension of the Canvas in World Space
  4591. * @param settings a combination of settings, possible ones are
  4592. * - children: an array of direct children primitives
  4593. * - id: a text identifier, for information purpose only, default is null.
  4594. * - unitScaleFactor: if specified the created canvas will be with a width of size.width*unitScaleFactor and a height of size.height.unitScaleFactor. If not specified, the unit of 1 is used. You can use this setting when you're dealing with a 3D world with small coordinates and you need a Canvas having bigger coordinates (typically to display text with better quality).
  4595. * - worldPosition the position of the Canvas in World Space, default is [0,0,0]
  4596. * - worldRotation the rotation of the Canvas in World Space, default is Quaternion.Identity()
  4597. * - trackNode: if you want the WorldSpaceCanvas to track the position/rotation/scale of a given Scene Node, use this setting to specify the Node to track
  4598. * - trackNodeOffset: if you use trackNode you may want to specify a 3D Offset to apply to shift the Canvas
  4599. * - trackNodeBillboard: if true the WorldSpaceCanvas will always face the screen
  4600. * - sideOrientation: Unexpected behavior occur if the value is different from Mesh.DEFAULTSIDE right now, so please use this one, which is the default.
  4601. * - cachingStrategy Must be CACHESTRATEGY_CANVAS for now, which is the default.
  4602. * - 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).
  4603. * - isVisible: true if the canvas must be visible, false for hidden. Default is true.
  4604. * - backgroundRoundRadius: the round radius of the background, either backgroundFill or backgroundBorder must be specified.
  4605. * - 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.
  4606. * - 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.
  4607. * - backgroundBorderThickness: if a backgroundBorder is specified, its thickness can be set using this property
  4608. * - 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.
  4609. * - 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.
  4610. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  4611. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  4612. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  4613. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  4614. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  4615. */
  4616. constructor(scene: Scene, size: Size, settings?: {
  4617. children?: Array<Prim2DBase>;
  4618. id?: string;
  4619. unitScaleFactor?: number;
  4620. worldPosition?: Vector3;
  4621. worldRotation?: Quaternion;
  4622. trackNode?: Node;
  4623. trackNodeOffset?: Vector3;
  4624. trackNodeBillboard?: boolean;
  4625. sideOrientation?: number;
  4626. cachingStrategy?: number;
  4627. enableInteraction?: boolean;
  4628. isVisible?: boolean;
  4629. backgroundRoundRadius?: number;
  4630. backgroundFill?: IBrush2D | string;
  4631. backgroundBorder?: IBrush2D | string;
  4632. backgroundBorderThickNess?: number;
  4633. customWorldSpaceNode?: Node;
  4634. maxAdaptiveCanvasSize?: number;
  4635. paddingTop?: number | string;
  4636. paddingLeft?: number | string;
  4637. paddingRight?: number | string;
  4638. paddingBottom?: number | string;
  4639. padding?: string;
  4640. });
  4641. dispose(): boolean;
  4642. trackNode: Node;
  4643. trackNodeOffset: Vector3;
  4644. trackNodeBillboard: boolean;
  4645. private _customWorldSpaceNode;
  4646. }
  4647. class ScreenSpaceCanvas2D extends Canvas2D {
  4648. /**
  4649. * 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.
  4650. * 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.
  4651. * All caching strategies will be available.
  4652. * 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]
  4653. * @param scene the Scene that owns the Canvas
  4654. * @param settings a combination of settings, possible ones are
  4655. * - children: an array of direct children primitives
  4656. * - id: a text identifier, for information purpose only
  4657. * - x: the position along the x axis (horizontal), relative to the left edge of the viewport. you can alternatively use the position setting.
  4658. * - y: the position along the y axis (vertically), relative to the bottom edge of the viewport. you can alternatively use the position setting.
  4659. * - 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]
  4660. * - width: the width of the Canvas. you can alternatively use the size setting.
  4661. * - height: the height of the Canvas. you can alternatively use the size setting.
  4662. * - 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
  4663. * - 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.
  4664. * - 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.
  4665. * - 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.
  4666. * - cachingStrategy: either CACHESTRATEGY_TOPLEVELGROUPS, CACHESTRATEGY_ALLGROUPS, CACHESTRATEGY_CANVAS, CACHESTRATEGY_DONTCACHE. Please refer to their respective documentation for more information. Default is Canvas2D.CACHESTRATEGY_DONTCACHE
  4667. * - 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.
  4668. * - isVisible: true if the canvas must be visible, false for hidden. Default is true.
  4669. * - backgroundRoundRadius: the round radius of the background, either backgroundFill or backgroundBorder must be specified.
  4670. * - 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.
  4671. * - 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.
  4672. * - backgroundBorderThickness: if a backgroundBorder is specified, its thickness can be set using this property
  4673. * - 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.
  4674. * - paddingTop: top padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  4675. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  4676. * - paddingRight: right padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  4677. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  4678. * - padding: top, left, right and bottom padding formatted as a single string (see BABYLON.PrimitiveThickness.fromString)
  4679. */
  4680. constructor(scene: Scene, settings?: {
  4681. children?: Array<Prim2DBase>;
  4682. id?: string;
  4683. x?: number;
  4684. y?: number;
  4685. position?: Vector2;
  4686. origin?: Vector2;
  4687. width?: number;
  4688. height?: number;
  4689. size?: Size;
  4690. renderingPhase?: {
  4691. camera: Camera;
  4692. renderingGroupID: number;
  4693. };
  4694. designSize?: Size;
  4695. designUseHorizAxis?: boolean;
  4696. cachingStrategy?: number;
  4697. cacheBehavior?: number;
  4698. enableInteraction?: boolean;
  4699. enableCollisionManager?: boolean;
  4700. customCollisionManager?: (owner: Canvas2D, enableBorders: boolean) => PrimitiveCollisionManagerBase;
  4701. collisionManagerUseBorders?: boolean;
  4702. isVisible?: boolean;
  4703. backgroundRoundRadius?: number;
  4704. backgroundFill?: IBrush2D | string;
  4705. backgroundBorder?: IBrush2D | string;
  4706. backgroundBorderThickNess?: number;
  4707. paddingTop?: number | string;
  4708. paddingLeft?: number | string;
  4709. paddingRight?: number | string;
  4710. paddingBottom?: number | string;
  4711. padding?: string;
  4712. });
  4713. }
  4714. }
  4715. declare module BABYLON {
  4716. /**
  4717. * This is the class that is used to display a World Space Canvas into a 3D scene
  4718. */
  4719. class WorldSpaceCanvas2DNode extends Mesh {
  4720. constructor(name: string, scene: Scene, canvas: Canvas2D);
  4721. dispose(): void;
  4722. private _canvas;
  4723. }
  4724. }
  4725. declare module BABYLON {
  4726. interface ICommand {
  4727. canExecute(parameter: any): boolean;
  4728. execute(parameter: any): void;
  4729. canExecuteChanged: Observable<void>;
  4730. }
  4731. class Command implements ICommand {
  4732. constructor(execute: (p) => void, canExecute: (p) => boolean);
  4733. canExecute(parameter: any): boolean;
  4734. execute(parameter: any): void;
  4735. readonly canExecuteChanged: Observable<void>;
  4736. private _lastCanExecuteResult;
  4737. private _execute;
  4738. private _canExecute;
  4739. private _canExecuteChanged;
  4740. }
  4741. abstract class UIElement extends SmartPropertyBase {
  4742. static readonly enabledState: string;
  4743. static readonly disabledState: string;
  4744. static readonly mouseOverState: string;
  4745. static UIELEMENT_PROPCOUNT: number;
  4746. static parentProperty: Prim2DPropInfo;
  4747. static widthProperty: Prim2DPropInfo;
  4748. static heightProperty: Prim2DPropInfo;
  4749. static minWidthProperty: Prim2DPropInfo;
  4750. static minHeightProperty: Prim2DPropInfo;
  4751. static maxWidthProperty: Prim2DPropInfo;
  4752. static maxHeightProperty: Prim2DPropInfo;
  4753. static actualWidthProperty: Prim2DPropInfo;
  4754. static actualHeightProperty: Prim2DPropInfo;
  4755. static marginProperty: Prim2DPropInfo;
  4756. static paddingProperty: Prim2DPropInfo;
  4757. static marginAlignmentProperty: Prim2DPropInfo;
  4758. static paddingAlignmentProperty: Prim2DPropInfo;
  4759. static isEnabledProperty: Prim2DPropInfo;
  4760. static isFocusedProperty: Prim2DPropInfo;
  4761. static isMouseOverProperty: Prim2DPropInfo;
  4762. constructor(settings: {
  4763. id?: string;
  4764. parent?: UIElement;
  4765. templateName?: string;
  4766. styleName?: string;
  4767. minWidth?: number;
  4768. minHeight?: number;
  4769. maxWidth?: number;
  4770. maxHeight?: number;
  4771. width?: number;
  4772. height?: number;
  4773. marginTop?: number | string;
  4774. marginLeft?: number | string;
  4775. marginRight?: number | string;
  4776. marginBottom?: number | string;
  4777. margin?: number | string;
  4778. marginHAlignment?: number;
  4779. marginVAlignment?: number;
  4780. marginAlignment?: string;
  4781. paddingTop?: number | string;
  4782. paddingLeft?: number | string;
  4783. paddingRight?: number | string;
  4784. paddingBottom?: number | string;
  4785. padding?: string;
  4786. paddingHAlignment?: number;
  4787. paddingVAlignment?: number;
  4788. paddingAlignment?: string;
  4789. });
  4790. dispose(): boolean;
  4791. /**
  4792. * Animation array, more info: http://doc.babylonjs.com/tutorials/Animations
  4793. */
  4794. animations: Animation[];
  4795. /**
  4796. * Returns as a new array populated with the Animatable used by the primitive. Must be overloaded by derived primitives.
  4797. * Look at Sprite2D for more information
  4798. */
  4799. getAnimatables(): IAnimatable[];
  4800. findById(id: string): UIElement;
  4801. readonly ownerWindow: Window;
  4802. style: string;
  4803. /**
  4804. * A string that identifies the UIElement.
  4805. * The id is optional and there's possible collision with other UIElement's id as the uniqueness is not supported.
  4806. */
  4807. id: string;
  4808. /**
  4809. * Return a unique id automatically generated.
  4810. * This property is mainly used for serialization to ensure a perfect way of identifying a UIElement
  4811. */
  4812. readonly uid: string;
  4813. readonly hierarchyDepth: number;
  4814. parent: UIElement;
  4815. width: number;
  4816. height: number;
  4817. minWidth: number;
  4818. readonly minHheight: number;
  4819. minHeight: number;
  4820. maxWidth: number;
  4821. maxHeight: number;
  4822. actualWidth: number;
  4823. actualHeight: number;
  4824. margin: PrimitiveThickness;
  4825. readonly _hasMargin: boolean;
  4826. padding: PrimitiveThickness;
  4827. private readonly _hasPadding;
  4828. marginAlignment: PrimitiveAlignment;
  4829. /**
  4830. * Check if there a marginAlignment specified (non null and not default)
  4831. */
  4832. readonly _hasMarginAlignment: boolean;
  4833. paddingAlignment: PrimitiveAlignment;
  4834. /**
  4835. * Check if there a marginAlignment specified (non null and not default)
  4836. */
  4837. readonly _hasPaddingAlignment: boolean;
  4838. isVisible: boolean;
  4839. isEnabled: boolean;
  4840. isFocused: boolean;
  4841. isMouseOver: boolean;
  4842. isFocusScope: boolean;
  4843. isFocusable: boolean;
  4844. protected getFocusScope(): UIElement;
  4845. /**
  4846. * Check if a given flag is set
  4847. * @param flag the flag value
  4848. * @return true if set, false otherwise
  4849. */
  4850. _isFlagSet(flag: number): boolean;
  4851. /**
  4852. * Check if all given flags are set
  4853. * @param flags the flags ORed
  4854. * @return true if all the flags are set, false otherwise
  4855. */
  4856. _areAllFlagsSet(flags: number): boolean;
  4857. /**
  4858. * Check if at least one flag of the given flags is set
  4859. * @param flags the flags ORed
  4860. * @return true if at least one flag is set, false otherwise
  4861. */
  4862. _areSomeFlagsSet(flags: number): boolean;
  4863. /**
  4864. * Clear the given flags
  4865. * @param flags the flags to clear
  4866. */
  4867. _clearFlags(flags: number): void;
  4868. /**
  4869. * Set the given flags to true state
  4870. * @param flags the flags ORed to set
  4871. * @return the flags state before this call
  4872. */
  4873. _setFlags(flags: number): number;
  4874. /**
  4875. * Change the state of the given flags
  4876. * @param flags the flags ORed to change
  4877. * @param state true to set them, false to clear them
  4878. */
  4879. _changeFlags(flags: number, state: boolean): void;
  4880. private _assignTemplate(templateName);
  4881. _createVisualTree(): void;
  4882. _patchUIElement(ownerWindow: Window, parent: UIElement): void;
  4883. protected _getDataSource(): IPropertyChanged;
  4884. protected createVisualTree(): void;
  4885. protected readonly visualPlaceholder: Prim2DBase;
  4886. protected readonly visualTemplateRoot: Prim2DBase;
  4887. protected readonly visualChildrenPlaceholder: Prim2DBase;
  4888. protected readonly _position: Vector2;
  4889. protected abstract _getChildren(): Array<UIElement>;
  4890. static flagVisualToBuild: number;
  4891. static flagIsVisible: number;
  4892. static flagIsFocus: number;
  4893. static flagIsFocusScope: number;
  4894. static flagIsFocusable: number;
  4895. static flagIsEnabled: number;
  4896. static flagIsMouseOver: number;
  4897. protected _visualPlaceholder: Group2D;
  4898. protected _visualTemplateRoot: Prim2DBase;
  4899. protected _visualChildrenPlaceholder: Prim2DBase;
  4900. private _renderingTemplateName;
  4901. protected _renderingTemplate: UIElementRenderingTemplateBase;
  4902. private _parent;
  4903. private _hierarchyDepth;
  4904. private _flags;
  4905. private _style;
  4906. private _ownerWindow;
  4907. private _id;
  4908. private _uid;
  4909. private _actualWidth;
  4910. private _actualHeight;
  4911. private _minWidth;
  4912. private _minHeight;
  4913. private _maxWidth;
  4914. private _maxHeight;
  4915. private _width;
  4916. private _height;
  4917. private _margin;
  4918. private _padding;
  4919. private _marginAlignment;
  4920. private _paddingAlignment;
  4921. private static _enableState;
  4922. private static _disabledState;
  4923. private static _mouseOverState;
  4924. }
  4925. abstract class UIElementStyle {
  4926. abstract removeStyle(uiel: UIElement): any;
  4927. abstract applyStyle(uiel: UIElement): any;
  4928. readonly name: string;
  4929. }
  4930. class GUIManager {
  4931. static registerDataTemplate(className: string, factory: (parent: UIElement, dataObject: any) => UIElement): void;
  4932. static getStyle(uiElType: string, styleName: string): UIElementStyle;
  4933. static registerStyle(uiElType: string, templateName: string, style: UIElementStyle): void;
  4934. static stylesByUIElement: StringDictionary<StringDictionary<UIElementStyle>>;
  4935. static DefaultStyleName: string;
  4936. static getRenderingTemplate(uiElType: string, templateName: string): () => UIElementRenderingTemplateBase;
  4937. static registerRenderingTemplate(uiElType: string, templateName: string, factory: () => UIElementRenderingTemplateBase): void;
  4938. static renderingTemplatesByUIElement: StringDictionary<StringDictionary<() => UIElementRenderingTemplateBase>>;
  4939. static DefaultTemplateName: string;
  4940. private static _defaultTemplateName;
  4941. private static _defaultStyleName;
  4942. }
  4943. abstract class UIElementRenderingTemplateBase {
  4944. attach(owner: UIElement): void;
  4945. detach(): void;
  4946. readonly owner: UIElement;
  4947. abstract createVisualTree(owner: UIElement, visualPlaceholder: Group2D): {
  4948. root: Prim2DBase;
  4949. contentPlaceholder: Prim2DBase;
  4950. };
  4951. private _owner;
  4952. }
  4953. function registerWindowRenderingTemplate(uiElType: string, templateName: string, factory: () => UIElementRenderingTemplateBase): (target: Object) => void;
  4954. }
  4955. declare module BABYLON {
  4956. class StackPanel extends UIElement {
  4957. static STACKPANEL_PROPCOUNT: number;
  4958. static orientationHorizontalProperty: Prim2DPropInfo;
  4959. constructor(settings?: {
  4960. id?: string;
  4961. parent?: UIElement;
  4962. children?: Array<UIElement>;
  4963. templateName?: string;
  4964. styleName?: string;
  4965. isOrientationHorizontal?: any;
  4966. marginTop?: number | string;
  4967. marginLeft?: number | string;
  4968. marginRight?: number | string;
  4969. marginBottom?: number | string;
  4970. margin?: number | string;
  4971. marginHAlignment?: number;
  4972. marginVAlignment?: number;
  4973. marginAlignment?: string;
  4974. paddingTop?: number | string;
  4975. paddingLeft?: number | string;
  4976. paddingRight?: number | string;
  4977. paddingBottom?: number | string;
  4978. padding?: string;
  4979. paddingHAlignment?: number;
  4980. paddingVAlignment?: number;
  4981. paddingAlignment?: string;
  4982. });
  4983. isOrientationHorizontal: boolean;
  4984. protected createVisualTree(): void;
  4985. readonly children: Array<UIElement>;
  4986. protected _getChildren(): Array<UIElement>;
  4987. private _childrenPlaceholder;
  4988. private _children;
  4989. private _isOrientationHorizontal;
  4990. }
  4991. class DefaultStackPanelRenderingTemplate extends UIElementRenderingTemplateBase {
  4992. createVisualTree(owner: UIElement, visualPlaceholder: Group2D): {
  4993. root: Prim2DBase;
  4994. contentPlaceholder: Prim2DBase;
  4995. };
  4996. attach(owner: UIElement): void;
  4997. }
  4998. }
  4999. declare module BABYLON {
  5000. abstract class Control extends UIElement {
  5001. static CONTROL_PROPCOUNT: number;
  5002. static backgroundProperty: Prim2DPropInfo;
  5003. static borderProperty: Prim2DPropInfo;
  5004. static borderThicknessProperty: Prim2DPropInfo;
  5005. static fontNameProperty: Prim2DPropInfo;
  5006. static foregroundProperty: Prim2DPropInfo;
  5007. constructor(settings: {
  5008. id?: string;
  5009. templateName?: string;
  5010. styleName?: string;
  5011. });
  5012. background: StringDictionary<IBrush2D>;
  5013. border: IBrush2D;
  5014. borderThickness: number;
  5015. fontName: string;
  5016. foreground: IBrush2D;
  5017. private _background;
  5018. private _border;
  5019. private _borderThickness;
  5020. private _fontName;
  5021. private _foreground;
  5022. }
  5023. }
  5024. declare module BABYLON {
  5025. abstract class ContentControl extends Control {
  5026. static CONTENTCONTROL_PROPCOUNT: number;
  5027. static contentProperty: Prim2DPropInfo;
  5028. constructor(settings?: {
  5029. id?: string;
  5030. templateName?: string;
  5031. styleName?: string;
  5032. content?: any;
  5033. });
  5034. dispose(): boolean;
  5035. content: any;
  5036. protected readonly _contentUIElement: UIElement;
  5037. _createVisualTree(): void;
  5038. private _buildContentUIElement();
  5039. private _contentPlaceholder;
  5040. private _content;
  5041. private __contentUIElement;
  5042. protected _getChildren(): Array<UIElement>;
  5043. }
  5044. }
  5045. declare module BABYLON {
  5046. class FocusManager {
  5047. constructor();
  5048. setFocusOn(el: UIElement, focusScope: UIElement): void;
  5049. private _rootScope;
  5050. private _focusScopes;
  5051. private _activeScope;
  5052. }
  5053. class Window extends ContentControl {
  5054. static WINDOW_PROPCOUNT: number;
  5055. static leftProperty: Prim2DPropInfo;
  5056. static bottomProperty: Prim2DPropInfo;
  5057. static positionProperty: Prim2DPropInfo;
  5058. static isActiveProperty: Prim2DPropInfo;
  5059. constructor(scene: Scene, settings?: {
  5060. id?: string;
  5061. templateName?: string;
  5062. styleName?: string;
  5063. content?: any;
  5064. left?: number;
  5065. bottom?: number;
  5066. minWidth?: number;
  5067. minHeight?: number;
  5068. maxWidth?: number;
  5069. maxHeight?: number;
  5070. width?: number;
  5071. height?: number;
  5072. worldPosition?: Vector3;
  5073. worldRotation?: Quaternion;
  5074. marginTop?: number | string;
  5075. marginLeft?: number | string;
  5076. marginRight?: number | string;
  5077. marginBottom?: number | string;
  5078. margin?: number | string;
  5079. marginHAlignment?: number;
  5080. marginVAlignment?: number;
  5081. marginAlignment?: string;
  5082. paddingTop?: number | string;
  5083. paddingLeft?: number | string;
  5084. paddingRight?: number | string;
  5085. paddingBottom?: number | string;
  5086. padding?: string;
  5087. paddingHAlignment?: number;
  5088. paddingVAlignment?: number;
  5089. paddingAlignment?: string;
  5090. });
  5091. readonly canvas: Canvas2D;
  5092. left: number;
  5093. bottom: number;
  5094. position: Vector2;
  5095. isActive: boolean;
  5096. readonly focusManager: FocusManager;
  5097. protected readonly _position: Vector2;
  5098. protected createVisualTree(): void;
  5099. _registerVisualToBuild(uiel: UIElement): void;
  5100. private _overPrimChanged(oldPrim, newPrim);
  5101. private _canvasPreRender();
  5102. private _canvasDisposed();
  5103. private _sceneData;
  5104. private _canvas;
  5105. private _left;
  5106. private _bottom;
  5107. private _isActive;
  5108. private _isWorldSpaceCanvas;
  5109. private _renderObserver;
  5110. private _disposeObserver;
  5111. private _UIElementVisualToBuildList;
  5112. private _mouseOverUIElement;
  5113. private static getSceneData(scene);
  5114. private static _sceneData;
  5115. }
  5116. class DefaultWindowRenderingTemplate extends UIElementRenderingTemplateBase {
  5117. createVisualTree(owner: UIElement, visualPlaceholder: Group2D): {
  5118. root: Prim2DBase;
  5119. contentPlaceholder: Prim2DBase;
  5120. };
  5121. }
  5122. }
  5123. declare module BABYLON {
  5124. class Label extends Control {
  5125. static textProperty: Prim2DPropInfo;
  5126. constructor(settings?: {
  5127. id?: string;
  5128. parent?: UIElement;
  5129. templateName?: string;
  5130. styleName?: string;
  5131. text?: string;
  5132. marginTop?: number | string;
  5133. marginLeft?: number | string;
  5134. marginRight?: number | string;
  5135. marginBottom?: number | string;
  5136. margin?: number | string;
  5137. marginHAlignment?: number;
  5138. marginVAlignment?: number;
  5139. marginAlignment?: string;
  5140. paddingTop?: number | string;
  5141. paddingLeft?: number | string;
  5142. paddingRight?: number | string;
  5143. paddingBottom?: number | string;
  5144. padding?: string;
  5145. });
  5146. protected readonly _position: Vector2;
  5147. private static _emptyArray;
  5148. protected _getChildren(): UIElement[];
  5149. protected createVisualTree(): void;
  5150. text: string;
  5151. private _text;
  5152. }
  5153. class DefaultLabelRenderingTemplate extends UIElementRenderingTemplateBase {
  5154. createVisualTree(owner: UIElement, visualPlaceholder: Group2D): {
  5155. root: Prim2DBase;
  5156. contentPlaceholder: Prim2DBase;
  5157. };
  5158. }
  5159. }
  5160. declare module BABYLON {
  5161. class Button extends ContentControl {
  5162. static readonly pushedState: string;
  5163. static BUTTON_PROPCOUNT: number;
  5164. static isPushedProperty: Prim2DPropInfo;
  5165. static isDefaultProperty: Prim2DPropInfo;
  5166. static isOutlineProperty: Prim2DPropInfo;
  5167. constructor(settings?: {
  5168. id?: string;
  5169. parent?: UIElement;
  5170. templateName?: string;
  5171. styleName?: string;
  5172. content?: any;
  5173. marginTop?: number | string;
  5174. marginLeft?: number | string;
  5175. marginRight?: number | string;
  5176. marginBottom?: number | string;
  5177. margin?: number | string;
  5178. marginHAlignment?: number;
  5179. marginVAlignment?: number;
  5180. marginAlignment?: string;
  5181. paddingTop?: number | string;
  5182. paddingLeft?: number | string;
  5183. paddingRight?: number | string;
  5184. paddingBottom?: number | string;
  5185. padding?: string;
  5186. paddingHAlignment?: number;
  5187. paddingVAlignment?: number;
  5188. paddingAlignment?: string;
  5189. });
  5190. isPushed: boolean;
  5191. isDefault: boolean;
  5192. isOutline: boolean;
  5193. readonly clickObservable: Observable<Button>;
  5194. _raiseClick(): void;
  5195. protected createVisualTree(): void;
  5196. readonly normalStateBackground: ObservableStringDictionary<IBrush2D>;
  5197. readonly defaultStateBackground: ObservableStringDictionary<IBrush2D>;
  5198. readonly normalStateBorder: ObservableStringDictionary<IBrush2D>;
  5199. readonly defaultStateBorder: ObservableStringDictionary<IBrush2D>;
  5200. private _normalStateBackground;
  5201. private _normalStateBorder;
  5202. private _defaultStateBackground;
  5203. private _defaultStateBorder;
  5204. private _isPushed;
  5205. private _isDefault;
  5206. private _isOutline;
  5207. private _clickObservable;
  5208. private static _pushedState;
  5209. }
  5210. class DefaultButtonRenderingTemplate extends UIElementRenderingTemplateBase {
  5211. createVisualTree(owner: UIElement, visualPlaceholder: Group2D): {
  5212. root: Prim2DBase;
  5213. contentPlaceholder: Prim2DBase;
  5214. };
  5215. attach(owner: UIElement): void;
  5216. stateChange(): void;
  5217. private _rect;
  5218. }
  5219. }