babylon.octree.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var Octree = (function () {
  4. function Octree(maxBlockCapacity) {
  5. this._maxBlockCapacity = maxBlockCapacity || 64;
  6. this._selection = new BABYLON.SmartArray(256);
  7. }
  8. // Methods
  9. Octree.prototype.update = function (worldMin, worldMax, meshes) {
  10. Octree._CreateBlocks(worldMin, worldMax, meshes, this._maxBlockCapacity, this);
  11. };
  12. Octree.prototype.addMesh = function (mesh) {
  13. for (var index = 0; index < this.blocks.length; index++) {
  14. var block = this.blocks[index];
  15. block.addMesh(mesh);
  16. }
  17. };
  18. Octree.prototype.select = function (frustumPlanes) {
  19. this._selection.reset();
  20. for (var index = 0; index < this.blocks.length; index++) {
  21. var block = this.blocks[index];
  22. block.select(frustumPlanes, this._selection);
  23. }
  24. return this._selection;
  25. };
  26. // Statics
  27. Octree._CreateBlocks = function (worldMin, worldMax, meshes, maxBlockCapacity, target) {
  28. target.blocks = [];
  29. var blockSize = new BABYLON.Vector3((worldMax.x - worldMin.x) / 2, (worldMax.y - worldMin.y) / 2, (worldMax.z - worldMin.z) / 2);
  30. for (var x = 0; x < 2; x++) {
  31. for (var y = 0; y < 2; y++) {
  32. for (var z = 0; z < 2; z++) {
  33. var localMin = worldMin.add(blockSize.multiplyByFloats(x, y, z));
  34. var localMax = worldMin.add(blockSize.multiplyByFloats(x + 1, y + 1, z + 1));
  35. var block = new BABYLON.OctreeBlock(localMin, localMax, maxBlockCapacity);
  36. block.addEntries(meshes);
  37. target.blocks.push(block);
  38. }
  39. }
  40. }
  41. };
  42. return Octree;
  43. })();
  44. BABYLON.Octree = Octree;
  45. })(BABYLON || (BABYLON = {}));
  46. //# sourceMappingURL=babylon.octree.js.map