babylon.node.js 3.9 KB

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