babylon.node.js 4.2 KB

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