babylon.octreeBlock.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. var BABYLON = BABYLON || {};
  2. (function () {
  3. BABYLON.OctreeBlock = function (minPoint, maxPoint, capacity) {
  4. this.subMeshes = [];
  5. this.meshes = [];
  6. this._capacity = capacity;
  7. this._minPoint = minPoint;
  8. this._maxPoint = maxPoint;
  9. this._boundingVectors = [];
  10. this._boundingVectors.push(minPoint.clone());
  11. this._boundingVectors.push(maxPoint.clone());
  12. this._boundingVectors.push(minPoint.clone());
  13. this._boundingVectors[2].x = maxPoint.x;
  14. this._boundingVectors.push(minPoint.clone());
  15. this._boundingVectors[3].y = maxPoint.y;
  16. this._boundingVectors.push(minPoint.clone());
  17. this._boundingVectors[4].z = maxPoint.z;
  18. this._boundingVectors.push(maxPoint.clone());
  19. this._boundingVectors[5].z = minPoint.z;
  20. this._boundingVectors.push(maxPoint.clone());
  21. this._boundingVectors[6].x = minPoint.x;
  22. this._boundingVectors.push(maxPoint.clone());
  23. this._boundingVectors[7].y = minPoint.y;
  24. };
  25. // Methods
  26. BABYLON.OctreeBlock.prototype.addEntries = function (meshes) {
  27. for (var index = 0; index < meshes.length; index++) {
  28. var mesh = meshes[index];
  29. if (mesh.getBoundingInfo().boundingBox.intersectsMinMax(this._minPoint, this._maxPoint)) {
  30. var localMeshIndex = this.meshes.length;
  31. this.meshes.push(mesh);
  32. this.subMeshes[localMeshIndex] = [];
  33. for (var subIndex = 0; subIndex < mesh.subMeshes.length; subIndex++) {
  34. var subMesh = mesh.subMeshes[subIndex];
  35. if (mesh.subMeshes.length === 1 || subMesh.getBoundingInfo().boundingBox.intersectsMinMax(this._minPoint, this._maxPoint)) {
  36. this.subMeshes[localMeshIndex].push(subMesh);
  37. }
  38. }
  39. }
  40. }
  41. if (this.subMeshes.length > this._capacity) {
  42. BABYLON.Octree._CreateBlocks(this._minPoint, this._maxPoint, this.meshes, this._capacity, this);
  43. }
  44. };
  45. BABYLON.OctreeBlock.prototype.select = function (frustumPlanes, selection) {
  46. if (this.blocks) {
  47. for (var index = 0; index < this.blocks.length; index++) {
  48. var block = this.blocks[index];
  49. block.select(frustumPlanes, selection);
  50. }
  51. return;
  52. }
  53. if (BABYLON.BoundingBox.IsInFrustrum(this._boundingVectors, frustumPlanes)) {
  54. selection.push(this);
  55. }
  56. };
  57. })();