babylon.smartPropertyPrim.ts 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. module BABYLON {
  2. export class Prim2DClassInfo {
  3. }
  4. export class Prim2DPropInfo {
  5. static PROPKIND_MODEL: number = 1;
  6. static PROPKIND_INSTANCE: number = 2;
  7. static PROPKIND_DYNAMIC: number = 3;
  8. id: number;
  9. flagId: number;
  10. kind: number;
  11. name: string;
  12. dirtyBoundingInfo: boolean;
  13. dirtyParentBoundingInfo: boolean;
  14. typeLevelCompare: boolean;
  15. }
  16. /**
  17. * Custom type of the propertyChanged observable
  18. */
  19. export class PropertyChangedInfo {
  20. /**
  21. * Previous value of the property
  22. */
  23. oldValue: any;
  24. /**
  25. * New value of the property
  26. */
  27. newValue: any;
  28. /**
  29. * Name of the property that changed its value
  30. */
  31. propertyName: string;
  32. }
  33. /**
  34. * Property Changed interface
  35. */
  36. export interface IPropertyChanged {
  37. /**
  38. * PropertyChanged observable
  39. */
  40. propertyChanged: Observable<PropertyChangedInfo>;
  41. }
  42. export class ClassTreeInfo<TClass, TProp>{
  43. constructor(baseClass: ClassTreeInfo<TClass, TProp>, type: Object, classContentFactory: (base: TClass) => TClass) {
  44. this._baseClass = baseClass;
  45. this._type = type;
  46. this._subClasses = new Array<{ type: Object, node: ClassTreeInfo<TClass, TProp> }>();
  47. this._levelContent = new StringDictionary<TProp>();
  48. this._classContentFactory = classContentFactory;
  49. }
  50. get classContent(): TClass {
  51. if (!this._classContent) {
  52. this._classContent = this._classContentFactory(this._baseClass ? this._baseClass.classContent : null);
  53. }
  54. return this._classContent;
  55. }
  56. get type(): Object {
  57. return this._type;
  58. }
  59. get levelContent(): StringDictionary<TProp> {
  60. return this._levelContent;
  61. }
  62. get fullContent(): StringDictionary<TProp> {
  63. if (!this._fullContent) {
  64. let dic = new StringDictionary<TProp>();
  65. let curLevel: ClassTreeInfo<TClass, TProp> = this;
  66. while (curLevel) {
  67. curLevel.levelContent.forEach((k, v) => dic.add(k, v));
  68. curLevel = curLevel._baseClass;
  69. }
  70. this._fullContent = dic;
  71. }
  72. return this._fullContent;
  73. }
  74. getLevelOf(type: Object): ClassTreeInfo<TClass, TProp> {
  75. // Are we already there?
  76. if (type === this._type) {
  77. return this;
  78. }
  79. let baseProto = Object.getPrototypeOf(type);
  80. let curProtoContent = this.getOrAddType(Object.getPrototypeOf(baseProto), baseProto);
  81. if (!curProtoContent) {
  82. this.getLevelOf(baseProto);
  83. }
  84. return this.getOrAddType(baseProto, type);
  85. }
  86. getOrAddType(baseType: Object, type: Object): ClassTreeInfo<TClass, TProp> {
  87. // Are we at the level corresponding to the baseType?
  88. // If so, get or add the level we're looking for
  89. if (baseType === this._type) {
  90. for (let subType of this._subClasses) {
  91. if (subType.type === type) {
  92. return subType.node;
  93. }
  94. }
  95. let node = new ClassTreeInfo<TClass, TProp>(this, type, this._classContentFactory);
  96. let info = { type: type, node: node };
  97. this._subClasses.push(info);
  98. return info.node;
  99. }
  100. // Recurse down to keep looking for the node corresponding to the baseTypeName
  101. for (let subType of this._subClasses) {
  102. let info = subType.node.getOrAddType(baseType, type);
  103. if (info) {
  104. return info;
  105. }
  106. }
  107. return null;
  108. }
  109. static get<TClass, TProp>(type: Object): ClassTreeInfo<TClass, TProp> {
  110. let dic = <ClassTreeInfo<TClass, TProp>>type["__classTreeInfo"];
  111. if (!dic) {
  112. return null;
  113. }
  114. return dic.getLevelOf(type);
  115. }
  116. static getOrRegister<TClass, TProp>(type: Object, classContentFactory: (base: TClass) => TClass): ClassTreeInfo<TClass, TProp> {
  117. let dic = <ClassTreeInfo<TClass, TProp>>type["__classTreeInfo"];
  118. if (!dic) {
  119. dic = new ClassTreeInfo<TClass, TProp>(null, type, classContentFactory);
  120. type["__classTreeInfo"] = dic;
  121. }
  122. return dic;
  123. }
  124. private _type: Object;
  125. private _classContent: TClass;
  126. private _baseClass: ClassTreeInfo<TClass, TProp>;
  127. private _subClasses: Array<{ type: Object, node: ClassTreeInfo<TClass, TProp> }>;
  128. private _levelContent: StringDictionary<TProp>;
  129. private _fullContent: StringDictionary<TProp>;
  130. private _classContentFactory: (base: TClass) => TClass;
  131. }
  132. @className("SmartPropertyPrim")
  133. /**
  134. * Base class of the primitives, implementing core crosscutting features
  135. */
  136. export abstract class SmartPropertyPrim implements IPropertyChanged {
  137. constructor() {
  138. this._flags = 0;
  139. this._modelKey = null;
  140. this._instanceDirtyFlags = 0;
  141. this._levelBoundingInfo = new BoundingInfo2D();
  142. this.animations = new Array<Animation>();
  143. }
  144. /**
  145. * An observable that is triggered when a property (using of the XXXXLevelProperty decorator) has its value changing.
  146. * 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)
  147. */
  148. public propertyChanged: Observable<PropertyChangedInfo>;
  149. /**
  150. * Check if the object is disposed or not.
  151. * @returns true if the object is dispose, false otherwise.
  152. */
  153. public get isDisposed(): boolean {
  154. return this._isFlagSet(SmartPropertyPrim.flagIsDisposed);
  155. }
  156. /**
  157. * Disposable pattern, this method must be overloaded by derived types in order to clean up hardware related resources.
  158. * @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.
  159. */
  160. public dispose(): boolean {
  161. if (this.isDisposed) {
  162. return false;
  163. }
  164. // Don't set to null, it may upset somebody...
  165. this.animations.splice(0);
  166. this._setFlags(SmartPropertyPrim.flagIsDisposed);
  167. return true;
  168. }
  169. /**
  170. * Animation array, more info: http://doc.babylonjs.com/tutorials/Animations
  171. */
  172. public animations: Animation[];
  173. /**
  174. * Returns as a new array populated with the Animatable used by the primitive. Must be overloaded by derived primitives.
  175. * Look at Sprite2D for more information
  176. */
  177. public getAnimatables(): IAnimatable[] {
  178. return new Array<IAnimatable>();
  179. }
  180. /**
  181. * Property giving the Model Key associated to the property.
  182. * This value is constructed from the type of the primitive and all the name/value of its properties declared with the modelLevelProperty decorator
  183. * @returns the model key string.
  184. */
  185. public get modelKey(): string {
  186. // No need to compute it?
  187. if (!this._isFlagSet(SmartPropertyPrim.flagModelDirty) && this._modelKey) {
  188. return this._modelKey;
  189. }
  190. let modelKey = `Class:${Tools.getClassName(this)};`;
  191. let propDic = this.propDic;
  192. propDic.forEach((k, v) => {
  193. if (v.kind === Prim2DPropInfo.PROPKIND_MODEL) {
  194. let propVal = this[v.name];
  195. // Special case, array, this WON'T WORK IN ALL CASES, all entries have to be of the same type and it must be a BJS well known one
  196. if (propVal && propVal.constructor === Array) {
  197. let firstVal = propVal[0];
  198. if (!firstVal) {
  199. propVal = 0;
  200. } else {
  201. propVal = Tools.hashCodeFromStream(Tools.arrayOrStringFeeder(propVal));
  202. }
  203. }
  204. modelKey += v.name + ":" + ((propVal != null) ? ((v.typeLevelCompare) ? Tools.getClassName(propVal) : propVal.toString()) : "[null]") + ";";
  205. }
  206. });
  207. this._clearFlags(SmartPropertyPrim.flagModelDirty);
  208. this._modelKey = modelKey;
  209. return modelKey;
  210. }
  211. /**
  212. * States if the Primitive is dirty and should be rendered again next time.
  213. * @returns true is dirty, false otherwise
  214. */
  215. public get isDirty(): boolean {
  216. return (this._instanceDirtyFlags !== 0) || this._areSomeFlagsSet(SmartPropertyPrim.flagModelDirty | SmartPropertyPrim.flagPositioningDirty | SmartPropertyPrim.flagLayoutDirty);
  217. }
  218. /**
  219. * Access the dictionary of properties metadata. Only properties decorated with XXXXLevelProperty are concerned
  220. * @returns the dictionary, the key is the property name as declared in Javascript, the value is the metadata object
  221. */
  222. private get propDic(): StringDictionary<Prim2DPropInfo> {
  223. if (!this._propInfo) {
  224. let cti = ClassTreeInfo.get<Prim2DClassInfo, Prim2DPropInfo>(Object.getPrototypeOf(this));
  225. if (!cti) {
  226. throw new Error("Can't access the propDic member in class definition, is this class SmartPropertyPrim based?");
  227. }
  228. this._propInfo = cti.fullContent;
  229. }
  230. return this._propInfo;
  231. }
  232. private static _createPropInfo(target: Object, propName: string, propId: number, dirtyBoundingInfo: boolean, dirtyParentBoundingBox: boolean, typeLevelCompare: boolean, kind: number): Prim2DPropInfo {
  233. let dic = ClassTreeInfo.getOrRegister<Prim2DClassInfo, Prim2DPropInfo>(target, () => new Prim2DClassInfo());
  234. var node = dic.getLevelOf(target);
  235. let propInfo = node.levelContent.get(propId.toString());
  236. if (propInfo) {
  237. throw new Error(`The ID ${propId} is already taken by another property declaration named: ${propInfo.name}`);
  238. }
  239. // Create, setup and add the PropInfo object to our prop dictionary
  240. propInfo = new Prim2DPropInfo();
  241. propInfo.id = propId;
  242. propInfo.flagId = Math.pow(2, propId);
  243. propInfo.kind = kind;
  244. propInfo.name = propName;
  245. propInfo.dirtyBoundingInfo = dirtyBoundingInfo;
  246. propInfo.dirtyParentBoundingInfo = dirtyParentBoundingBox;
  247. propInfo.typeLevelCompare = typeLevelCompare;
  248. node.levelContent.add(propName, propInfo);
  249. return propInfo;
  250. }
  251. private static _checkUnchanged(curValue, newValue): boolean {
  252. // Nothing to nothing: nothing to do!
  253. if ((curValue === null && newValue === null) || (curValue === undefined && newValue === undefined)) {
  254. return true;
  255. }
  256. // Check value unchanged
  257. if ((curValue != null) && (newValue != null)) {
  258. if (typeof (curValue.equals) == "function") {
  259. if (curValue.equals(newValue)) {
  260. return true;
  261. }
  262. } else {
  263. if (curValue === newValue) {
  264. return true;
  265. }
  266. }
  267. }
  268. return false;
  269. }
  270. private static propChangedInfo = new PropertyChangedInfo();
  271. public markAsDirty(propertyName: string) {
  272. if (this.isDisposed) {
  273. return;
  274. }
  275. let i = propertyName.indexOf(".");
  276. if (i !== -1) {
  277. propertyName = propertyName.substr(0, i);
  278. }
  279. var propInfo = this.propDic.get(propertyName);
  280. if (!propInfo) {
  281. return;
  282. }
  283. var newValue = this[propertyName];
  284. this._handlePropChanged(undefined, newValue, propertyName, propInfo, propInfo.typeLevelCompare);
  285. }
  286. protected _boundingBoxDirty() {
  287. this._setFlags(SmartPropertyPrim.flagLevelBoundingInfoDirty);
  288. // Escalate the dirty flag in the instance hierarchy, stop when a renderable group is found or at the end
  289. if (this instanceof Prim2DBase) {
  290. let curprim: Prim2DBase = (<any>this);
  291. while (curprim) {
  292. curprim._setFlags(SmartPropertyPrim.flagBoundingInfoDirty);
  293. if (curprim.isSizeAuto) {
  294. curprim.onPrimitivePropertyDirty(Prim2DBase.sizeProperty.flagId);
  295. curprim._setFlags(SmartPropertyPrim.flagPositioningDirty);
  296. }
  297. if (curprim instanceof Group2D) {
  298. if (curprim.isRenderableGroup) {
  299. break;
  300. }
  301. }
  302. curprim = curprim.parent;
  303. }
  304. }
  305. }
  306. private _handlePropChanged<T>(curValue: T, newValue: T, propName: string, propInfo: Prim2DPropInfo, typeLevelCompare: boolean) {
  307. // If the property change also dirty the boundingInfo, update the boundingInfo dirty flags
  308. if (propInfo.dirtyBoundingInfo) {
  309. this._boundingBoxDirty();
  310. } else if (propInfo.dirtyParentBoundingInfo) {
  311. let p: SmartPropertyPrim = (<any>this)._parent;
  312. if (p != null) {
  313. p._boundingBoxDirty();
  314. }
  315. }
  316. // Trigger property changed
  317. let info = SmartPropertyPrim.propChangedInfo;
  318. info.oldValue = curValue;
  319. info.newValue = newValue;
  320. info.propertyName = propName;
  321. let propMask = propInfo.flagId;
  322. this.propertyChanged.notifyObservers(info, propMask);
  323. // If the property belong to a group, check if it's a cached one, and dirty its render sprite accordingly
  324. if (this instanceof Group2D) {
  325. this.handleGroupChanged(propInfo);
  326. }
  327. // Check for parent layout dirty
  328. if (this instanceof Prim2DBase) {
  329. let p = (<any>this)._parent;
  330. if (p != null && p.layoutEngine && (p.layoutEngine.layoutDirtyOnPropertyChangedMask & propInfo.flagId) !== 0) {
  331. p._setLayoutDirty();
  332. }
  333. }
  334. // For type level compare, if there's a change of type it's a change of model, otherwise we issue an instance change
  335. var instanceDirty = false;
  336. if (typeLevelCompare && curValue != null && newValue != null) {
  337. var cvProto = (<any>curValue).__proto__;
  338. var nvProto = (<any>newValue).__proto__;
  339. instanceDirty = (cvProto === nvProto);
  340. }
  341. // Set the dirty flags
  342. if (!instanceDirty && (propInfo.kind === Prim2DPropInfo.PROPKIND_MODEL)) {
  343. if (!this.isDirty) {
  344. this._setFlags(SmartPropertyPrim.flagModelDirty);
  345. }
  346. } else if (instanceDirty || (propInfo.kind === Prim2DPropInfo.PROPKIND_INSTANCE) || (propInfo.kind === Prim2DPropInfo.PROPKIND_DYNAMIC)) {
  347. this.onPrimitivePropertyDirty(propMask);
  348. }
  349. }
  350. protected onPrimitivePropertyDirty(propFlagId: number) {
  351. this.onPrimBecomesDirty();
  352. this._instanceDirtyFlags |= propFlagId;
  353. }
  354. protected handleGroupChanged(prop: Prim2DPropInfo) {
  355. }
  356. /**
  357. * Check if a given set of properties are dirty or not.
  358. * @param flags a ORed combination of Prim2DPropInfo.flagId values
  359. * @return true if at least one property is dirty, false if none of them are.
  360. */
  361. public checkPropertiesDirty(flags: number): boolean {
  362. return (this._instanceDirtyFlags & flags) !== 0;
  363. }
  364. /**
  365. * Clear a given set of properties.
  366. * @param flags a ORed combination of Prim2DPropInfo.flagId values
  367. * @return the new set of property still marked as dirty
  368. */
  369. protected clearPropertiesDirty(flags: number): number {
  370. this._instanceDirtyFlags &= ~flags;
  371. return this._instanceDirtyFlags;
  372. }
  373. public _resetPropertiesDirty() {
  374. this._instanceDirtyFlags = 0;
  375. this._clearFlags(SmartPropertyPrim.flagPrimInDirtyList | SmartPropertyPrim.flagNeedRefresh);
  376. }
  377. /**
  378. * Retrieve the boundingInfo for this Primitive, computed based on the primitive itself and NOT its children
  379. */
  380. public get levelBoundingInfo(): BoundingInfo2D {
  381. if (this._isFlagSet(SmartPropertyPrim.flagLevelBoundingInfoDirty)) {
  382. this.updateLevelBoundingInfo();
  383. this._clearFlags(SmartPropertyPrim.flagLevelBoundingInfoDirty);
  384. }
  385. return this._levelBoundingInfo;
  386. }
  387. /**
  388. * This method must be overridden by a given Primitive implementation to compute its boundingInfo
  389. */
  390. protected updateLevelBoundingInfo() {
  391. }
  392. /**
  393. * Property method called when the Primitive becomes dirty
  394. */
  395. protected onPrimBecomesDirty() {
  396. }
  397. static _hookProperty<T>(propId: number, piStore: (pi: Prim2DPropInfo) => void, typeLevelCompare: boolean, dirtyBoundingInfo: boolean, dirtyParentBoundingBox: boolean, kind: number): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void {
  398. return (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => {
  399. var propInfo = SmartPropertyPrim._createPropInfo(target, <string>propName, propId, dirtyBoundingInfo, dirtyParentBoundingBox, typeLevelCompare, kind);
  400. if (piStore) {
  401. piStore(propInfo);
  402. }
  403. let getter = descriptor.get, setter = descriptor.set;
  404. // Overload the property setter implementation to add our own logic
  405. descriptor.set = function (val) {
  406. // check for disposed first, do nothing
  407. if (this.isDisposed) {
  408. return;
  409. }
  410. let curVal = getter.call(this);
  411. if (SmartPropertyPrim._checkUnchanged(curVal, val)) {
  412. return;
  413. }
  414. // Cast the object we're working one
  415. let prim = <SmartPropertyPrim>this;
  416. // Change the value
  417. setter.call(this, val);
  418. // Notify change, dirty flags update
  419. prim._handlePropChanged(curVal, val, <string>propName, propInfo, typeLevelCompare);
  420. }
  421. }
  422. }
  423. /**
  424. * Add an externally attached data from its key.
  425. * This method call will fail and return false, if such key already exists.
  426. * If you don't care and just want to get the data no matter what, use the more convenient getOrAddExternalDataWithFactory() method.
  427. * @param key the unique key that identifies the data
  428. * @param data the data object to associate to the key for this Engine instance
  429. * @return true if no such key were already present and the data was added successfully, false otherwise
  430. */
  431. public addExternalData<T>(key: string, data: T): boolean {
  432. if (!this._externalData) {
  433. this._externalData = new StringDictionary<Object>();
  434. }
  435. return this._externalData.add(key, data);
  436. }
  437. /**
  438. * Get an externally attached data from its key
  439. * @param key the unique key that identifies the data
  440. * @return the associated data, if present (can be null), or undefined if not present
  441. */
  442. public getExternalData<T>(key: string): T {
  443. if (!this._externalData) {
  444. return null;
  445. }
  446. return <T>this._externalData.get(key);
  447. }
  448. /**
  449. * Get an externally attached data from its key, create it using a factory if it's not already present
  450. * @param key the unique key that identifies the data
  451. * @param factory the factory that will be called to create the instance if and only if it doesn't exists
  452. * @return the associated data, can be null if the factory returned null.
  453. */
  454. public getOrAddExternalDataWithFactory<T>(key: string, factory: (k: string) => T): T {
  455. if (!this._externalData) {
  456. this._externalData = new StringDictionary<Object>();
  457. }
  458. return <T>this._externalData.getOrAddWithFactory(key, factory);
  459. }
  460. /**
  461. * Remove an externally attached data from the Engine instance
  462. * @param key the unique key that identifies the data
  463. * @return true if the data was successfully removed, false if it doesn't exist
  464. */
  465. public removeExternalData(key): boolean {
  466. if (!this._externalData) {
  467. return false;
  468. }
  469. return this._externalData.remove(key);
  470. }
  471. /**
  472. * Check if a given flag is set
  473. * @param flag the flag value
  474. * @return true if set, false otherwise
  475. */
  476. public _isFlagSet(flag: number): boolean {
  477. return (this._flags & flag) !== 0;
  478. }
  479. /**
  480. * Check if all given flags are set
  481. * @param flags the flags ORed
  482. * @return true if all the flags are set, false otherwise
  483. */
  484. public _areAllFlagsSet(flags: number): boolean {
  485. return (this._flags & flags) === flags;
  486. }
  487. /**
  488. * Check if at least one flag of the given flags is set
  489. * @param flags the flags ORed
  490. * @return true if at least one flag is set, false otherwise
  491. */
  492. public _areSomeFlagsSet(flags: number): boolean {
  493. return (this._flags & flags) !== 0;
  494. }
  495. /**
  496. * Clear the given flags
  497. * @param flags the flags to clear
  498. */
  499. public _clearFlags(flags: number) {
  500. this._flags &= ~flags;
  501. }
  502. /**
  503. * Set the given flags to true state
  504. * @param flags the flags ORed to set
  505. * @return the flags state before this call
  506. */
  507. public _setFlags(flags: number): number {
  508. let cur = this._flags;
  509. this._flags |= flags;
  510. return cur;
  511. }
  512. /**
  513. * Change the state of the given flags
  514. * @param flags the flags ORed to change
  515. * @param state true to set them, false to clear them
  516. */
  517. public _changeFlags(flags: number, state: boolean) {
  518. if (state) {
  519. this._flags |= flags;
  520. } else {
  521. this._flags &= ~flags;
  522. }
  523. }
  524. public static flagIsDisposed = 0x0000001; // set if the object is already disposed
  525. public static flagLevelBoundingInfoDirty = 0x0000002; // set if the primitive's level bounding box (not including children) is dirty
  526. public static flagModelDirty = 0x0000004; // set if the model must be changed
  527. public static flagLayoutDirty = 0x0000008; // set if the layout must be computed
  528. public static flagLevelVisible = 0x0000010; // set if the primitive is set as visible for its level only
  529. public static flagBoundingInfoDirty = 0x0000020; // set if the primitive's overall bounding box (including children) is dirty
  530. public static flagIsPickable = 0x0000040; // set if the primitive can be picked during interaction
  531. public static flagIsVisible = 0x0000080; // set if the primitive is concretely visible (use the levelVisible of parents)
  532. public static flagVisibilityChanged = 0x0000100; // set if there was a transition between visible/hidden status
  533. public static flagPositioningDirty = 0x0000200; // set if the primitive positioning must be computed
  534. public static flagTrackedGroup = 0x0000400; // set if the group2D is tracking a scene node
  535. public static flagWorldCacheChanged = 0x0000800; // set if the cached bitmap of a world space canvas changed
  536. public static flagChildrenFlatZOrder = 0x0001000; // set if all the children (direct and indirect) will share the same Z-Order
  537. public static flagZOrderDirty = 0x0002000; // set if the Z-Order for this prim and its children must be recomputed
  538. public static flagActualOpacityDirty = 0x0004000; // set if the actualOpactity should be recomputed
  539. public static flagPrimInDirtyList = 0x0008000; // set if the primitive is in the primDirtyList
  540. public static flagIsContainer = 0x0010000; // set if the primitive is a container
  541. public static flagNeedRefresh = 0x0020000; // set if the primitive wasn't successful at refresh
  542. public static flagActualScaleDirty = 0x0040000; // set if the actualScale property needs to be recomputed
  543. public static flagDontInheritParentScale = 0x0080000; // set if the actualScale must not use its parent's scale to be computed
  544. public static flagGlobalTransformDirty = 0x0100000; // set if the global transform must be recomputed due to a local transform change
  545. private _flags : number;
  546. private _externalData : StringDictionary<Object>;
  547. private _modelKey : string;
  548. private _propInfo : StringDictionary<Prim2DPropInfo>;
  549. protected _levelBoundingInfo : BoundingInfo2D;
  550. protected _boundingInfo : BoundingInfo2D;
  551. protected _instanceDirtyFlags: number;
  552. }
  553. export function modelLevelProperty<T>(propId: number, piStore: (pi: Prim2DPropInfo) => void, typeLevelCompare = false, dirtyBoundingInfo = false, dirtyParentBoundingBox = false): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void {
  554. return SmartPropertyPrim._hookProperty(propId, piStore, typeLevelCompare, dirtyBoundingInfo, dirtyParentBoundingBox, Prim2DPropInfo.PROPKIND_MODEL);
  555. }
  556. export function instanceLevelProperty<T>(propId: number, piStore: (pi: Prim2DPropInfo) => void, typeLevelCompare = false, dirtyBoundingInfo = false, dirtyParentBoundingBox = false): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void {
  557. return SmartPropertyPrim._hookProperty(propId, piStore, typeLevelCompare, dirtyBoundingInfo, dirtyParentBoundingBox, Prim2DPropInfo.PROPKIND_INSTANCE);
  558. }
  559. export function dynamicLevelProperty<T>(propId: number, piStore: (pi: Prim2DPropInfo) => void, typeLevelCompare = false, dirtyBoundingInfo = false, dirtyParentBoundingBox = false): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void {
  560. return SmartPropertyPrim._hookProperty(propId, piStore, typeLevelCompare, dirtyBoundingInfo, dirtyParentBoundingBox, Prim2DPropInfo.PROPKIND_DYNAMIC);
  561. }
  562. }