babylon.canvas2d.d.ts 209 KB

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