Selaa lähdekoodia

Updating octree with maxdepth

David Catuhe 11 vuotta sitten
vanhempi
commit
b17c135583

+ 3 - 2
Babylon/Culling/Octrees/babylon.octree.js

@@ -1,8 +1,9 @@
 var BABYLON;
 (function (BABYLON) {
     var Octree = (function () {
-        function Octree(creationFunc, maxBlockCapacity) {
-            this.maxDepth = 2;
+        function Octree(creationFunc, maxBlockCapacity, maxDepth) {
+            if (typeof maxDepth === "undefined") { maxDepth = 2; }
+            this.maxDepth = maxDepth;
             this.dynamicContent = new Array();
             this._maxBlockCapacity = maxBlockCapacity || 64;
             this._selectionContent = new BABYLON.SmartArray(1024);

+ 1 - 2
Babylon/Culling/Octrees/babylon.octree.ts

@@ -5,14 +5,13 @@
 
     export class Octree<T> {
         public blocks: Array<OctreeBlock<T>>;
-        public maxDepth = 2;
         public dynamicContent = new Array<T>();
 
         private _maxBlockCapacity: number;
         private _selectionContent: SmartArray<T>;       
         private _creationFunc: (entry: T, block: OctreeBlock<T>) => void;
 
-        constructor(creationFunc: (entry: T, block: OctreeBlock<T>) => void, maxBlockCapacity?: number) {
+        constructor(creationFunc: (entry: T, block: OctreeBlock<T>) => void, maxBlockCapacity?: number, public maxDepth = 2) {
             this._maxBlockCapacity = maxBlockCapacity || 64;
             this._selectionContent = new BABYLON.SmartArray<T>(1024);
             this._creationFunc = creationFunc;

+ 1 - 0
Babylon/Materials/textures/babylon.renderTargetTexture.js

@@ -9,6 +9,7 @@ var BABYLON;
     var RenderTargetTexture = (function (_super) {
         __extends(RenderTargetTexture, _super);
         function RenderTargetTexture(name, size, scene, generateMipMaps, doNotChangeAspectRatio) {
+            if (typeof doNotChangeAspectRatio === "undefined") { doNotChangeAspectRatio = true; }
             _super.call(this, null, scene, !generateMipMaps);
             this.renderList = new Array();
             this.renderParticles = true;

+ 1 - 1
Babylon/Materials/textures/babylon.renderTargetTexture.ts

@@ -16,7 +16,7 @@
         private _currentRefreshId = -1;
         private _refreshRate = 1;
 
-        constructor(name: string, size: any, scene: Scene, generateMipMaps?: boolean, doNotChangeAspectRatio?: boolean) {
+        constructor(name: string, size: any, scene: Scene, generateMipMaps?: boolean, doNotChangeAspectRatio: boolean = true) {
             super(null, scene, !generateMipMaps);
 
             this.name = name;

+ 4 - 2
Babylon/Mesh/babylon.abstractMesh.js

@@ -527,9 +527,11 @@ var BABYLON;
         * This function will create an octree to help select the right submeshes for rendering, picking and collisions
         * Please note that you must have a decent number of submeshes to get performance improvements when using octree
         */
-        AbstractMesh.prototype.createOrUpdateSubmeshesOctree = function (capacity) {
+        AbstractMesh.prototype.createOrUpdateSubmeshesOctree = function (maxCapacity, maxDepth) {
+            if (typeof maxCapacity === "undefined") { maxCapacity = 64; }
+            if (typeof maxDepth === "undefined") { maxDepth = 2; }
             if (!this._submeshesOctree) {
-                this._submeshesOctree = new BABYLON.Octree(BABYLON.Octree.CreationFuncForSubMeshes, capacity);
+                this._submeshesOctree = new BABYLON.Octree(BABYLON.Octree.CreationFuncForSubMeshes, maxCapacity, maxDepth);
             }
 
             this.computeWorldMatrix(true);

+ 2 - 2
Babylon/Mesh/babylon.abstractMesh.ts

@@ -523,9 +523,9 @@
         * This function will create an octree to help select the right submeshes for rendering, picking and collisions
         * Please note that you must have a decent number of submeshes to get performance improvements when using octree
         */
-        public createOrUpdateSubmeshesOctree(capacity?: number): Octree<SubMesh> {
+        public createOrUpdateSubmeshesOctree(maxCapacity = 64, maxDepth = 2): Octree<SubMesh> {
             if (!this._submeshesOctree) {
-                this._submeshesOctree = new BABYLON.Octree<SubMesh>(Octree.CreationFuncForSubMeshes, capacity);
+                this._submeshesOctree = new BABYLON.Octree<SubMesh>(Octree.CreationFuncForSubMeshes, maxCapacity, maxDepth);
             }
 
             this.computeWorldMatrix(true);            

+ 8 - 7
Babylon/Mesh/babylon.groundMesh.js

@@ -10,7 +10,6 @@ var BABYLON;
         __extends(GroundMesh, _super);
         function GroundMesh(name, scene) {
             _super.call(this, name, scene);
-            this.chunkSize = 128;
             this._worldInverse = new BABYLON.Matrix();
         }
         Object.defineProperty(GroundMesh.prototype, "subdivisions", {
@@ -21,14 +20,16 @@ var BABYLON;
             configurable: true
         });
 
-        GroundMesh.prototype.optimize = function (subdivisions) {
-            if (this.getTotalVertices() < 2000) {
-                BABYLON.Tools.Warn("Optimizing GroundMesh requires at least 2000 vertices.");
-            }
+        GroundMesh.prototype._setReady = function (state) {
+            if (state) {
+                if (this._subdivisions > 10) {
+                    this.subdivide(this._subdivisions);
 
-            this.subdivide(subdivisions || this._subdivisions);
+                    this.createOrUpdateSubmeshesOctree(32);
+                }
+            }
 
-            this.createOrUpdateSubmeshesOctree();
+            _super.prototype._setReady.call(this, state);
         };
 
         GroundMesh.prototype.getHeightAtCoordinates = function (x, z) {

+ 8 - 7
Babylon/Mesh/babylon.groundMesh.ts

@@ -1,6 +1,5 @@
 module BABYLON {
     export class GroundMesh extends Mesh {
-        public chunkSize = 128; // Aiming to get around 128 indices per submesh
         private _worldInverse = new BABYLON.Matrix();
 
         public _subdivisions: number;
@@ -13,14 +12,16 @@
             return this._subdivisions;
         }
 
-        public optimize(subdivisions?: number): void {
-            if (this.getTotalVertices() < 2000) {
-                Tools.Warn("Optimizing GroundMesh requires at least 2000 vertices.");
-            }
+        public _setReady(state: boolean): void {
+            if (state) {
+                if (this._subdivisions > 10) {
+                    this.subdivide(this._subdivisions);
 
-            this.subdivide(subdivisions || this._subdivisions);
+                    this.createOrUpdateSubmeshesOctree(32);
+                }
+            }
 
-            this.createOrUpdateSubmeshesOctree();
+            super._setReady(state);
         }
 
         public getHeightAtCoordinates(x: number, z: number): number {

+ 1 - 1
Babylon/Tools/babylon.tools.js

@@ -428,7 +428,7 @@ var BABYLON;
             }
 
             //At this point size can be a number, or an object (according to engine.prototype.createRenderTargetTexture method)
-            var texture = new BABYLON.RenderTargetTexture("screenShot", size, engine.scenes[0]);
+            var texture = new BABYLON.RenderTargetTexture("screenShot", size, engine.scenes[0], false, false);
             texture.renderList = engine.scenes[0].meshes;
 
             texture.onAfterRender = function () {

+ 1 - 1
Babylon/Tools/babylon.tools.ts

@@ -462,7 +462,7 @@ module BABYLON {
             }
 
             //At this point size can be a number, or an object (according to engine.prototype.createRenderTargetTexture method)
-            var texture = new RenderTargetTexture("screenShot", size, engine.scenes[0]);
+            var texture = new RenderTargetTexture("screenShot", size, engine.scenes[0], false, false);
             texture.renderList = engine.scenes[0].meshes;
 
             texture.onAfterRender = () => {

+ 4 - 2
Babylon/babylon.scene.js

@@ -1046,9 +1046,11 @@
         };
 
         // Octrees
-        Scene.prototype.createOrUpdateSelectionOctree = function () {
+        Scene.prototype.createOrUpdateSelectionOctree = function (maxCapacity, maxDepth) {
+            if (typeof maxCapacity === "undefined") { maxCapacity = 64; }
+            if (typeof maxDepth === "undefined") { maxDepth = 2; }
             if (!this._selectionOctree) {
-                this._selectionOctree = new BABYLON.Octree(BABYLON.Octree.CreationFuncForMeshes);
+                this._selectionOctree = new BABYLON.Octree(BABYLON.Octree.CreationFuncForMeshes, maxCapacity, maxDepth);
             }
 
             var min = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);

+ 2 - 2
Babylon/babylon.scene.ts

@@ -1122,9 +1122,9 @@
         }
 
         // Octrees
-        public createOrUpdateSelectionOctree(): Octree<AbstractMesh> {
+        public createOrUpdateSelectionOctree(maxCapacity = 64, maxDepth = 2): Octree<AbstractMesh> {
             if (!this._selectionOctree) {
-                this._selectionOctree = new BABYLON.Octree<AbstractMesh>(Octree.CreationFuncForMeshes);
+                this._selectionOctree = new BABYLON.Octree<AbstractMesh>(Octree.CreationFuncForMeshes, maxCapacity, maxDepth);
             }
 
             var min = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 6 - 6
babylon.1.12-beta.js