babylon.octreeBlock.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var OctreeBlock = (function () {
  4. function OctreeBlock(minPoint, maxPoint, capacity, depth, maxDepth, creationFunc) {
  5. this.entries = new Array();
  6. this._boundingVectors = new Array();
  7. this._capacity = capacity;
  8. this._depth = depth;
  9. this._maxDepth = maxDepth;
  10. this._creationFunc = creationFunc;
  11. this._minPoint = minPoint;
  12. this._maxPoint = maxPoint;
  13. this._boundingVectors.push(minPoint.clone());
  14. this._boundingVectors.push(maxPoint.clone());
  15. this._boundingVectors.push(minPoint.clone());
  16. this._boundingVectors[2].x = maxPoint.x;
  17. this._boundingVectors.push(minPoint.clone());
  18. this._boundingVectors[3].y = maxPoint.y;
  19. this._boundingVectors.push(minPoint.clone());
  20. this._boundingVectors[4].z = maxPoint.z;
  21. this._boundingVectors.push(maxPoint.clone());
  22. this._boundingVectors[5].z = minPoint.z;
  23. this._boundingVectors.push(maxPoint.clone());
  24. this._boundingVectors[6].x = minPoint.x;
  25. this._boundingVectors.push(maxPoint.clone());
  26. this._boundingVectors[7].y = minPoint.y;
  27. }
  28. Object.defineProperty(OctreeBlock.prototype, "capacity", {
  29. // Property
  30. get: function () {
  31. return this._capacity;
  32. },
  33. enumerable: true,
  34. configurable: true
  35. });
  36. Object.defineProperty(OctreeBlock.prototype, "minPoint", {
  37. get: function () {
  38. return this._minPoint;
  39. },
  40. enumerable: true,
  41. configurable: true
  42. });
  43. Object.defineProperty(OctreeBlock.prototype, "maxPoint", {
  44. get: function () {
  45. return this._maxPoint;
  46. },
  47. enumerable: true,
  48. configurable: true
  49. });
  50. // Methods
  51. OctreeBlock.prototype.addEntry = function (entry) {
  52. if (this.blocks) {
  53. for (var index = 0; index < this.blocks.length; index++) {
  54. var block = this.blocks[index];
  55. block.addEntry(entry);
  56. }
  57. return;
  58. }
  59. this._creationFunc(entry, this);
  60. if (this.entries.length > this.capacity && this._depth < this._maxDepth) {
  61. this.createInnerBlocks();
  62. }
  63. };
  64. OctreeBlock.prototype.addEntries = function (entries) {
  65. for (var index = 0; index < entries.length; index++) {
  66. var mesh = entries[index];
  67. this.addEntry(mesh);
  68. }
  69. };
  70. OctreeBlock.prototype.select = function (frustumPlanes, selection, allowDuplicate) {
  71. if (BABYLON.BoundingBox.IsInFrustum(this._boundingVectors, frustumPlanes)) {
  72. if (this.blocks) {
  73. for (var index = 0; index < this.blocks.length; index++) {
  74. var block = this.blocks[index];
  75. block.select(frustumPlanes, selection, allowDuplicate);
  76. }
  77. return;
  78. }
  79. if (allowDuplicate) {
  80. selection.concat(this.entries);
  81. } else {
  82. selection.concatWithNoDuplicate(this.entries);
  83. }
  84. }
  85. };
  86. OctreeBlock.prototype.intersects = function (sphereCenter, sphereRadius, selection, allowDuplicate) {
  87. if (BABYLON.BoundingBox.IntersectsSphere(this._minPoint, this._maxPoint, sphereCenter, sphereRadius)) {
  88. if (this.blocks) {
  89. for (var index = 0; index < this.blocks.length; index++) {
  90. var block = this.blocks[index];
  91. block.intersects(sphereCenter, sphereRadius, selection, allowDuplicate);
  92. }
  93. return;
  94. }
  95. if (allowDuplicate) {
  96. selection.concat(this.entries);
  97. } else {
  98. selection.concatWithNoDuplicate(this.entries);
  99. }
  100. }
  101. };
  102. OctreeBlock.prototype.intersectsRay = function (ray, selection) {
  103. if (ray.intersectsBoxMinMax(this._minPoint, this._maxPoint)) {
  104. if (this.blocks) {
  105. for (var index = 0; index < this.blocks.length; index++) {
  106. var block = this.blocks[index];
  107. block.intersectsRay(ray, selection);
  108. }
  109. return;
  110. }
  111. selection.concatWithNoDuplicate(this.entries);
  112. }
  113. };
  114. OctreeBlock.prototype.createInnerBlocks = function () {
  115. BABYLON.Octree._CreateBlocks(this._minPoint, this._maxPoint, this.entries, this._capacity, this._depth, this._maxDepth, this, this._creationFunc);
  116. };
  117. return OctreeBlock;
  118. })();
  119. BABYLON.OctreeBlock = OctreeBlock;
  120. })(BABYLON || (BABYLON = {}));
  121. //# sourceMappingURL=babylon.octreeBlock.js.map