babylon.InstancedMesh.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. this.sourceMesh._preActivate();
  91. };
  92. InstancedMesh.prototype._activate = function (renderId) {
  93. this.sourceMesh._registerInstanceForRenderId(this, renderId);
  94. };
  95. InstancedMesh.prototype._syncSubMeshes = function () {
  96. this.releaseSubMeshes();
  97. for (var index = 0; index < this._sourceMesh.subMeshes.length; index++) {
  98. this._sourceMesh.subMeshes[index].clone(this, this._sourceMesh);
  99. }
  100. };
  101. InstancedMesh.prototype._generatePointsArray = function () {
  102. return this._sourceMesh._generatePointsArray();
  103. };
  104. // Clone
  105. InstancedMesh.prototype.clone = function (name, newParent, doNotCloneChildren) {
  106. var result = this._sourceMesh.createInstance(name);
  107. // Deep copy
  108. BABYLON.Tools.DeepCopy(this, result, ["name"], []);
  109. // Bounding info
  110. this.refreshBoundingInfo();
  111. // Parent
  112. if (newParent) {
  113. result.parent = newParent;
  114. }
  115. if (!doNotCloneChildren) {
  116. for (var index = 0; index < this.getScene().meshes.length; index++) {
  117. var mesh = this.getScene().meshes[index];
  118. if (mesh.parent == this) {
  119. mesh.clone(mesh.name, result);
  120. }
  121. }
  122. }
  123. result.computeWorldMatrix(true);
  124. return result;
  125. };
  126. // Dispoe
  127. InstancedMesh.prototype.dispose = function (doNotRecurse) {
  128. // Remove from mesh
  129. var index = this._sourceMesh.instances.indexOf(this);
  130. this._sourceMesh.instances.splice(index, 1);
  131. _super.prototype.dispose.call(this, doNotRecurse);
  132. };
  133. return InstancedMesh;
  134. })(BABYLON.AbstractMesh);
  135. BABYLON.InstancedMesh = InstancedMesh;
  136. })(BABYLON || (BABYLON = {}));
  137. //# sourceMappingURL=babylon.instancedMesh.js.map