babylon.InstancedMesh.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. var __extends = this.__extends || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. __.prototype = b.prototype;
  5. d.prototype = new __();
  6. };
  7. var BABYLON;
  8. (function (BABYLON) {
  9. var InstancedMesh = (function (_super) {
  10. __extends(InstancedMesh, _super);
  11. function InstancedMesh(name, source) {
  12. _super.call(this, name, source.getScene());
  13. source.instances.push(this);
  14. this._sourceMesh = source;
  15. this.position.copyFrom(source.position);
  16. this.rotation.copyFrom(source.rotation);
  17. this.scaling.copyFrom(source.scaling);
  18. if (source.rotationQuaternion) {
  19. this.rotationQuaternion = source.rotationQuaternion.clone();
  20. }
  21. this.infiniteDistance = source.infiniteDistance;
  22. this.setPivotMatrix(source.getPivotMatrix());
  23. this.refreshBoundingInfo();
  24. this._syncSubMeshes();
  25. }
  26. Object.defineProperty(InstancedMesh.prototype, "receiveShadows", {
  27. // Methods
  28. get: function () {
  29. return this._sourceMesh.receiveShadows;
  30. },
  31. enumerable: true,
  32. configurable: true
  33. });
  34. Object.defineProperty(InstancedMesh.prototype, "material", {
  35. get: function () {
  36. return this._sourceMesh.material;
  37. },
  38. enumerable: true,
  39. configurable: true
  40. });
  41. Object.defineProperty(InstancedMesh.prototype, "visibility", {
  42. get: function () {
  43. return this._sourceMesh.visibility;
  44. },
  45. enumerable: true,
  46. configurable: true
  47. });
  48. Object.defineProperty(InstancedMesh.prototype, "skeleton", {
  49. get: function () {
  50. return this._sourceMesh.skeleton;
  51. },
  52. enumerable: true,
  53. configurable: true
  54. });
  55. InstancedMesh.prototype.getTotalVertices = function () {
  56. return this._sourceMesh.getTotalVertices();
  57. };
  58. Object.defineProperty(InstancedMesh.prototype, "sourceMesh", {
  59. get: function () {
  60. return this._sourceMesh;
  61. },
  62. enumerable: true,
  63. configurable: true
  64. });
  65. InstancedMesh.prototype.getVerticesData = function (kind) {
  66. return this._sourceMesh.getVerticesData(kind);
  67. };
  68. InstancedMesh.prototype.isVerticesDataPresent = function (kind) {
  69. return this._sourceMesh.isVerticesDataPresent(kind);
  70. };
  71. InstancedMesh.prototype.getIndices = function () {
  72. return this._sourceMesh.getIndices();
  73. };
  74. Object.defineProperty(InstancedMesh.prototype, "_positions", {
  75. get: function () {
  76. return this._sourceMesh._positions;
  77. },
  78. enumerable: true,
  79. configurable: true
  80. });
  81. InstancedMesh.prototype.refreshBoundingInfo = function () {
  82. var data = this._sourceMesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  83. if (data) {
  84. var extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this._sourceMesh.getTotalVertices());
  85. this._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
  86. }
  87. this._updateBoundingInfo();
  88. };
  89. InstancedMesh.prototype._preActivate = function () {
  90. if (this._currentLOD) {
  91. this._currentLOD._preActivate();
  92. }
  93. };
  94. InstancedMesh.prototype._activate = function (renderId) {
  95. if (this._currentLOD) {
  96. this._currentLOD._registerInstanceForRenderId(this, renderId);
  97. }
  98. };
  99. InstancedMesh.prototype.getLOD = function (camera) {
  100. this._currentLOD = this.sourceMesh.getLOD(this.getScene().activeCamera, this.getBoundingInfo().boundingSphere);
  101. return this._currentLOD;
  102. };
  103. InstancedMesh.prototype._syncSubMeshes = function () {
  104. this.releaseSubMeshes();
  105. for (var index = 0; index < this._sourceMesh.subMeshes.length; index++) {
  106. this._sourceMesh.subMeshes[index].clone(this, this._sourceMesh);
  107. }
  108. };
  109. InstancedMesh.prototype._generatePointsArray = function () {
  110. return this._sourceMesh._generatePointsArray();
  111. };
  112. // Clone
  113. InstancedMesh.prototype.clone = function (name, newParent, doNotCloneChildren) {
  114. var result = this._sourceMesh.createInstance(name);
  115. // Deep copy
  116. BABYLON.Tools.DeepCopy(this, result, ["name"], []);
  117. // Bounding info
  118. this.refreshBoundingInfo();
  119. // Parent
  120. if (newParent) {
  121. result.parent = newParent;
  122. }
  123. if (!doNotCloneChildren) {
  124. for (var index = 0; index < this.getScene().meshes.length; index++) {
  125. var mesh = this.getScene().meshes[index];
  126. if (mesh.parent == this) {
  127. mesh.clone(mesh.name, result);
  128. }
  129. }
  130. }
  131. result.computeWorldMatrix(true);
  132. return result;
  133. };
  134. // Dispoe
  135. InstancedMesh.prototype.dispose = function (doNotRecurse) {
  136. // Remove from mesh
  137. var index = this._sourceMesh.instances.indexOf(this);
  138. this._sourceMesh.instances.splice(index, 1);
  139. _super.prototype.dispose.call(this, doNotRecurse);
  140. };
  141. return InstancedMesh;
  142. })(BABYLON.AbstractMesh);
  143. BABYLON.InstancedMesh = InstancedMesh;
  144. })(BABYLON || (BABYLON = {}));
  145. //# sourceMappingURL=babylon.instancedMesh.js.map