123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- var BABYLON = BABYLON || {};
- (function () {
- BABYLON.OctreeBlock = function (minPoint, maxPoint, capacity) {
- this.subMeshes = [];
- this.meshes = [];
- this._capacity = capacity;
- this._minPoint = minPoint;
- this._maxPoint = maxPoint;
-
- this._boundingVectors = [];
- this._boundingVectors.push(minPoint.clone());
- this._boundingVectors.push(maxPoint.clone());
- this._boundingVectors.push(minPoint.clone());
- this._boundingVectors[2].x = maxPoint.x;
- this._boundingVectors.push(minPoint.clone());
- this._boundingVectors[3].y = maxPoint.y;
- this._boundingVectors.push(minPoint.clone());
- this._boundingVectors[4].z = maxPoint.z;
- this._boundingVectors.push(maxPoint.clone());
- this._boundingVectors[5].z = minPoint.z;
- this._boundingVectors.push(maxPoint.clone());
- this._boundingVectors[6].x = minPoint.x;
- this._boundingVectors.push(maxPoint.clone());
- this._boundingVectors[7].y = minPoint.y;
- };
- // Methods
- BABYLON.OctreeBlock.prototype.addEntries = function (meshes) {
- for (var index = 0; index < meshes.length; index++) {
- var mesh = meshes[index];
- if (mesh.getBoundingInfo().boundingBox.intersectsMinMax(this._minPoint, this._maxPoint)) {
- var localMeshIndex = this.meshes.length;
- this.meshes.push(mesh);
- this.subMeshes[localMeshIndex] = [];
- for (var subIndex = 0; subIndex < mesh.subMeshes.length; subIndex++) {
- var subMesh = mesh.subMeshes[subIndex];
- if (mesh.subMeshes.length === 1 || subMesh.getBoundingInfo().boundingBox.intersectsMinMax(this._minPoint, this._maxPoint)) {
- this.subMeshes[localMeshIndex].push(subMesh);
- }
- }
- }
- }
-
- if (this.subMeshes.length > this._capacity) {
- BABYLON.Octree._CreateBlocks(this._minPoint, this._maxPoint, this.meshes, this._capacity, this);
- }
- };
- BABYLON.OctreeBlock.prototype.select = function (frustumPlanes, selection) {
- if (this.blocks) {
- for (var index = 0; index < this.blocks.length; index++) {
- var block = this.blocks[index];
- block.select(frustumPlanes, selection);
- }
- return;
- }
- if (BABYLON.BoundingBox.IsInFrustrum(this._boundingVectors, frustumPlanes)) {
- selection.push(this);
- }
- };
- })();
|