babylon.octreeBlock.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 (!mesh.subMeshes) {
  29. return;
  30. }
  31. if (this.blocks) {
  32. for (var index = 0; index < this.blocks.length; index++) {
  33. var block = this.blocks[index];
  34. block.addMesh(mesh);
  35. }
  36. return;
  37. }
  38. if (mesh.getBoundingInfo().boundingBox.intersectsMinMax(this._minPoint, this._maxPoint)) {
  39. var localMeshIndex = this.meshes.length;
  40. this.meshes.push(mesh);
  41. this.subMeshes[localMeshIndex] = [];
  42. for (var subIndex = 0; subIndex < mesh.subMeshes.length; subIndex++) {
  43. var subMesh = mesh.subMeshes[subIndex];
  44. if (mesh.subMeshes.length === 1 || subMesh.getBoundingInfo().boundingBox.intersectsMinMax(this._minPoint, this._maxPoint)) {
  45. this.subMeshes[localMeshIndex].push(subMesh);
  46. }
  47. }
  48. }
  49. if (this.subMeshes.length > this._capacity) {
  50. BABYLON.Octree._CreateBlocks(this._minPoint, this._maxPoint, this.meshes, this._capacity, this);
  51. }
  52. };
  53. OctreeBlock.prototype.addEntries = function (meshes) {
  54. for (var index = 0; index < meshes.length; index++) {
  55. var mesh = meshes[index];
  56. this.addMesh(mesh);
  57. }
  58. };
  59. OctreeBlock.prototype.select = function (frustumPlanes, selection) {
  60. if (this.blocks) {
  61. for (var index = 0; index < this.blocks.length; index++) {
  62. var block = this.blocks[index];
  63. block.select(frustumPlanes, selection);
  64. }
  65. return;
  66. }
  67. if (BABYLON.BoundingBox.IsInFrustum(this._boundingVectors, frustumPlanes)) {
  68. selection.push(this);
  69. }
  70. };
  71. return OctreeBlock;
  72. })();
  73. BABYLON.OctreeBlock = OctreeBlock;
  74. })(BABYLON || (BABYLON = {}));
  75. //# sourceMappingURL=babylon.octreeBlock.js.map