|
@@ -4,15 +4,6 @@ import { SubMesh } from "../../Meshes/subMesh";
|
|
|
import { AbstractMesh } from "../../Meshes/abstractMesh";
|
|
|
import { Ray } from "../../Culling/ray";
|
|
|
import { OctreeBlock } from "./octreeBlock";
|
|
|
- /**
|
|
|
- * Contains an array of blocks representing the octree
|
|
|
- */
|
|
|
- export interface IOctreeContainer<T> {
|
|
|
- /**
|
|
|
- * Blocks within the octree
|
|
|
- */
|
|
|
- blocks: Array<OctreeBlock<T>>;
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* Octrees are a really powerful data structure that can quickly select entities based on space coordinates.
|
|
@@ -59,7 +50,7 @@ import { OctreeBlock } from "./octreeBlock";
|
|
|
* @param entries meshes to be added to the octree blocks
|
|
|
*/
|
|
|
public update(worldMin: Vector3, worldMax: Vector3, entries: T[]): void {
|
|
|
- Octree._CreateBlocks(worldMin, worldMax, entries, this._maxBlockCapacity, 0, this.maxDepth, this, this._creationFunc);
|
|
|
+ OctreeBlock._CreateBlocks(worldMin, worldMax, entries, this._maxBlockCapacity, 0, this.maxDepth, this, this._creationFunc);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -150,28 +141,6 @@ import { OctreeBlock } from "./octreeBlock";
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @hidden
|
|
|
- */
|
|
|
- public static _CreateBlocks<T>(worldMin: Vector3, worldMax: Vector3, entries: T[], maxBlockCapacity: number, currentDepth: number, maxDepth: number, target: IOctreeContainer<T>, creationFunc: (entry: T, block: OctreeBlock<T>) => void): void {
|
|
|
- target.blocks = new Array<OctreeBlock<T>>();
|
|
|
- var blockSize = new Vector3((worldMax.x - worldMin.x) / 2, (worldMax.y - worldMin.y) / 2, (worldMax.z - worldMin.z) / 2);
|
|
|
-
|
|
|
- // Segmenting space
|
|
|
- for (var x = 0; x < 2; x++) {
|
|
|
- for (var y = 0; y < 2; y++) {
|
|
|
- for (var z = 0; z < 2; z++) {
|
|
|
- var localMin = worldMin.add(blockSize.multiplyByFloats(x, y, z));
|
|
|
- var localMax = worldMin.add(blockSize.multiplyByFloats(x + 1, y + 1, z + 1));
|
|
|
-
|
|
|
- var block = new OctreeBlock<T>(localMin, localMax, maxBlockCapacity, currentDepth + 1, maxDepth, creationFunc);
|
|
|
- block.addEntries(entries);
|
|
|
- target.blocks.push(block);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* Adds a mesh into the octree block if it intersects the block
|
|
|
*/
|
|
|
public static CreationFuncForMeshes = (entry: AbstractMesh, block: OctreeBlock<AbstractMesh>): void => {
|