babylon.octreeBlock.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var OctreeBlock = (function () {
  4. function OctreeBlock(minPoint, maxPoint, capacity) {
  5. this.meshes = new Array();
  6. this.subMeshes = new Array();
  7. this._boundingVectors = new Array();
  8. this._capacity = capacity;
  9. this._minPoint = minPoint;
  10. this._maxPoint = maxPoint;
  11. this._boundingVectors.push(minPoint.clone());
  12. this._boundingVectors.push(maxPoint.clone());
  13. this._boundingVectors.push(minPoint.clone());
  14. this._boundingVectors[2].x = maxPoint.x;
  15. this._boundingVectors.push(minPoint.clone());
  16. this._boundingVectors[3].y = maxPoint.y;
  17. this._boundingVectors.push(minPoint.clone());
  18. this._boundingVectors[4].z = maxPoint.z;
  19. this._boundingVectors.push(maxPoint.clone());
  20. this._boundingVectors[5].z = minPoint.z;
  21. this._boundingVectors.push(maxPoint.clone());
  22. this._boundingVectors[6].x = minPoint.x;
  23. this._boundingVectors.push(maxPoint.clone());
  24. this._boundingVectors[7].y = minPoint.y;
  25. }
  26. // Methods
  27. OctreeBlock.prototype.addMesh = function (mesh) {
  28. if (this.blocks) {
  29. for (var index = 0; index < this.blocks.length; index++) {
  30. var block = this.blocks[index];
  31. block.addMesh(mesh);
  32. }
  33. return;
  34. }
  35. if (mesh.getBoundingInfo().boundingBox.intersectsMinMax(this._minPoint, this._maxPoint)) {
  36. var localMeshIndex = this.meshes.length;
  37. this.meshes.push(mesh);
  38. this.subMeshes[localMeshIndex] = [];
  39. if (mesh.subMeshes) {
  40. for (var subIndex = 0; subIndex < mesh.subMeshes.length; subIndex++) {
  41. var subMesh = mesh.subMeshes[subIndex];
  42. if (mesh.subMeshes.length === 1 || subMesh.getBoundingInfo().boundingBox.intersectsMinMax(this._minPoint, this._maxPoint)) {
  43. this.subMeshes[localMeshIndex].push(subMesh);
  44. }
  45. }
  46. }
  47. }
  48. if (this.subMeshes.length > this._capacity) {
  49. BABYLON.Octree._CreateBlocks(this._minPoint, this._maxPoint, this.meshes, this._capacity, this);
  50. }
  51. };
  52. OctreeBlock.prototype.addEntries = function (meshes) {
  53. for (var index = 0; index < meshes.length; index++) {
  54. var mesh = meshes[index];
  55. this.addMesh(mesh);
  56. }
  57. };
  58. OctreeBlock.prototype.select = function (frustumPlanes, selection) {
  59. if (this.blocks) {
  60. for (var index = 0; index < this.blocks.length; index++) {
  61. var block = this.blocks[index];
  62. block.select(frustumPlanes, selection);
  63. }
  64. return;
  65. }
  66. if (BABYLON.BoundingBox.IsInFrustum(this._boundingVectors, frustumPlanes)) {
  67. selection.push(this);
  68. }
  69. };
  70. return OctreeBlock;
  71. })();
  72. BABYLON.OctreeBlock = OctreeBlock;
  73. })(BABYLON || (BABYLON = {}));
  74. //# sourceMappingURL=babylon.octreeBlock.js.map