babylon.octreeBlock.js 2.1 KB

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