babylon.InstancedMesh.js 5.3 KB

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