babylon.node.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var Node = (function () {
  4. function Node(name, scene) {
  5. this.animations = new Array();
  6. this._childrenFlag = -1;
  7. this._isEnabled = true;
  8. this._isReady = true;
  9. this._currentRenderId = -1;
  10. this.name = name;
  11. this.id = name;
  12. this._scene = scene;
  13. this._initCache();
  14. }
  15. Node.prototype.getScene = function () {
  16. return this._scene;
  17. };
  18. Node.prototype.getEngine = function () {
  19. return this._scene.getEngine();
  20. };
  21. // override it in derived class
  22. Node.prototype.getWorldMatrix = function () {
  23. return BABYLON.Matrix.Identity();
  24. };
  25. // override it in derived class if you add new variables to the cache
  26. // and call the parent class method
  27. Node.prototype._initCache = function () {
  28. this._cache = {};
  29. this._cache.parent = undefined;
  30. };
  31. Node.prototype.updateCache = function (force) {
  32. if (!force && this.isSynchronized())
  33. return;
  34. this._cache.parent = this.parent;
  35. this._updateCache();
  36. };
  37. // override it in derived class if you add new variables to the cache
  38. // and call the parent class method if !ignoreParentClass
  39. Node.prototype._updateCache = function (ignoreParentClass) {
  40. };
  41. // override it in derived class if you add new variables to the cache
  42. Node.prototype._isSynchronized = function () {
  43. return true;
  44. };
  45. Node.prototype.isSynchronizedWithParent = function () {
  46. return this.parent ? this.parent._currentRenderId <= this._currentRenderId : true;
  47. };
  48. Node.prototype.isSynchronized = function (updateCache) {
  49. var check = this.hasNewParent();
  50. check = check || !this.isSynchronizedWithParent();
  51. check = check || !this._isSynchronized();
  52. if (updateCache)
  53. this.updateCache(true);
  54. return !check;
  55. };
  56. Node.prototype.hasNewParent = function (update) {
  57. if (this._cache.parent === this.parent)
  58. return false;
  59. if (update)
  60. this._cache.parent = this.parent;
  61. return true;
  62. };
  63. Node.prototype.isReady = function () {
  64. return this._isReady;
  65. };
  66. Node.prototype.isEnabled = function () {
  67. if (!this._isEnabled) {
  68. return false;
  69. }
  70. if (this.parent) {
  71. return this.parent.isEnabled();
  72. }
  73. return true;
  74. };
  75. Node.prototype.setEnabled = function (value) {
  76. this._isEnabled = value;
  77. };
  78. Node.prototype.isDescendantOf = function (ancestor) {
  79. if (this.parent) {
  80. if (this.parent === ancestor) {
  81. return true;
  82. }
  83. return this.parent.isDescendantOf(ancestor);
  84. }
  85. return false;
  86. };
  87. Node.prototype._getDescendants = function (list, results) {
  88. for (var index = 0; index < list.length; index++) {
  89. var item = list[index];
  90. if (item.isDescendantOf(this)) {
  91. results.push(item);
  92. }
  93. }
  94. };
  95. Node.prototype.getDescendants = function () {
  96. var results = [];
  97. this._getDescendants(this._scene.meshes, results);
  98. this._getDescendants(this._scene.lights, results);
  99. this._getDescendants(this._scene.cameras, results);
  100. return results;
  101. };
  102. Node.prototype._setReady = function (state) {
  103. if (state == this._isReady) {
  104. return;
  105. }
  106. if (!state) {
  107. this._isReady = false;
  108. return;
  109. }
  110. this._isReady = true;
  111. if (this.onReady) {
  112. this.onReady(this);
  113. }
  114. };
  115. return Node;
  116. })();
  117. BABYLON.Node = Node;
  118. })(BABYLON || (BABYLON = {}));
  119. //# sourceMappingURL=babylon.node.js.map