소스 검색

Integrating queue in scene

Queue is now created per scene and execute next is running on every
frame (checking if needed and executing task)
Raanan Weber 10 년 전
부모
커밋
c0b723b814

+ 9 - 45
Babylon/Mesh/babylon.mesh.js

@@ -871,52 +871,16 @@ var BABYLON;
          * @param type the type of simplification to run.
          * successCallback optional success callback to be called after the simplification finished processing all settings.
          */
-        Mesh.prototype.simplify = function (settings, parallelProcessing, type, successCallback) {
-            var _this = this;
+        Mesh.prototype.simplify = function (settings, parallelProcessing, simplificationType, successCallback) {
             if (parallelProcessing === void 0) { parallelProcessing = true; }
-            if (type === void 0) { type = 0 /* QUADRATIC */; }
-            var getSimplifier = function () {
-                switch (type) {
-                    case 0 /* QUADRATIC */:
-                    default:
-                        return new BABYLON.QuadraticErrorSimplification(_this);
-                }
-            };
-            if (parallelProcessing) {
-                //parallel simplifier
-                settings.forEach(function (setting) {
-                    var simplifier = getSimplifier();
-                    simplifier.simplify(setting, function (newMesh) {
-                        _this.addLODLevel(setting.distance, newMesh);
-                        //check if it is the last
-                        if (setting.quality === settings[settings.length - 1].quality && successCallback) {
-                            //all done, run the success callback.
-                            successCallback();
-                        }
-                    });
-                });
-            }
-            else {
-                //single simplifier.
-                var simplifier = getSimplifier();
-                var runDecimation = function (setting, callback) {
-                    simplifier.simplify(setting, function (newMesh) {
-                        _this.addLODLevel(setting.distance, newMesh);
-                        //run the next quality level
-                        callback();
-                    });
-                };
-                BABYLON.AsyncLoop.Run(settings.length, function (loop) {
-                    runDecimation(settings[loop.index], function () {
-                        loop.executeNext();
-                    });
-                }, function () {
-                    //execution ended, run the success callback.
-                    if (successCallback) {
-                        successCallback();
-                    }
-                });
-            }
+            if (simplificationType === void 0) { simplificationType = BABYLON.SimplificationType.QUADRATIC; }
+            this.getScene().simplificationQueue.addTask({
+                settings: settings,
+                parallelProcessing: parallelProcessing,
+                mesh: this,
+                simplificationType: simplificationType,
+                successCallback: successCallback
+            });
         };
         // Statics
         Mesh.CreateRibbon = function (name, pathArray, closeArray, closePath, offset, scene, updatable, sideOrientation) {

+ 8 - 46
Babylon/Mesh/babylon.mesh.ts

@@ -1069,52 +1069,14 @@
          * @param type the type of simplification to run.
          * successCallback optional success callback to be called after the simplification finished processing all settings.
          */
-        public simplify(settings: Array<ISimplificationSettings>, parallelProcessing: boolean = true, type: SimplificationType = SimplificationType.QUADRATIC, successCallback?: () => void) {
-
-            var getSimplifier = (): ISimplifier => {
-                switch (type) {
-                    case SimplificationType.QUADRATIC:
-                    default:
-                        return new QuadraticErrorSimplification(this);
-                }
-            }
-
-            if (parallelProcessing) {
-                //parallel simplifier
-                settings.forEach((setting) => {
-                    var simplifier = getSimplifier();
-                    simplifier.simplify(setting, (newMesh) => {
-                        this.addLODLevel(setting.distance, newMesh);
-                        //check if it is the last
-                        if (setting.quality === settings[settings.length - 1].quality && successCallback) {
-                            //all done, run the success callback.
-                            successCallback();
-                        }
-                    });
-                });
-            } else {
-                //single simplifier.
-                var simplifier = getSimplifier();
-
-                var runDecimation = (setting: ISimplificationSettings, callback: () => void) => {
-                    simplifier.simplify(setting, (newMesh) => {
-                        this.addLODLevel(setting.distance, newMesh);
-                        //run the next quality level
-                        callback();
-                    });
-                }
-
-                AsyncLoop.Run(settings.length, (loop: AsyncLoop) => {
-                    runDecimation(settings[loop.index], () => {
-                        loop.executeNext();
-                    });
-                }, () => {
-                        //execution ended, run the success callback.
-                        if (successCallback) {
-                            successCallback();
-                        }
-                    });
-            }
+        public simplify(settings: Array<ISimplificationSettings>, parallelProcessing: boolean = true, simplificationType: SimplificationType = SimplificationType.QUADRATIC, successCallback?: () => void) {
+            this.getScene().simplificationQueue.addTask({
+                settings: settings,
+                parallelProcessing: parallelProcessing,
+                mesh: this,
+                simplificationType: simplificationType,
+                successCallback: successCallback
+            });            
         }
 
         // Statics

+ 3 - 0
Babylon/Mesh/babylon.meshSimplification.js

@@ -13,6 +13,9 @@ var BABYLON;
             this.running = false;
             this._simplificationArray = [];
         }
+        SimplificationQueue.prototype.addTask = function (task) {
+            this._simplificationArray.push(task);
+        };
         SimplificationQueue.prototype.executeNext = function () {
             var task = this._simplificationArray.pop();
             if (task) {

+ 4 - 0
Babylon/Mesh/babylon.meshSimplification.ts

@@ -47,6 +47,10 @@
             this._simplificationArray = [];
         }
 
+        public addTask(task: ISimplificationTask) {
+            this._simplificationArray.push(task);
+        }
+
         public executeNext() {
             var task = this._simplificationArray.pop();
             if (task) {

+ 6 - 0
Babylon/babylon.scene.js

@@ -137,6 +137,8 @@ var BABYLON;
             this.attachControl();
             this._debugLayer = new BABYLON.DebugLayer(this);
             this.mainSoundTrack = new BABYLON.SoundTrack(this, { mainTrack: true });
+            //simplification queue
+            this.simplificationQueue = new BABYLON.SimplificationQueue();
         }
         Object.defineProperty(Scene, "FOGMODE_NONE", {
             get: function () {
@@ -1042,6 +1044,10 @@ var BABYLON;
             if (this.actionManager) {
                 this.actionManager.processTrigger(BABYLON.ActionManager.OnEveryFrameTrigger, null);
             }
+            //Simplification Queue
+            if (!this.simplificationQueue.running) {
+                this.simplificationQueue.executeNext();
+            }
             // Before render
             if (this.beforeRender) {
                 this.beforeRender();

+ 11 - 0
Babylon/babylon.scene.ts

@@ -190,6 +190,9 @@
         public mainSoundTrack: SoundTrack;
         public soundTracks = new Array<SoundTrack>();
 
+        //Simplification Queue
+        public simplificationQueue: SimplificationQueue;
+
         // Private
         private _engine: Engine;
         private _totalVertices = 0;
@@ -271,6 +274,9 @@
 
             this._debugLayer = new DebugLayer(this);
             this.mainSoundTrack = new SoundTrack(this, { mainTrack: true });
+
+            //simplification queue
+            this.simplificationQueue = new SimplificationQueue();
         }
 
         // Properties 
@@ -1338,6 +1344,11 @@
                 this.actionManager.processTrigger(ActionManager.OnEveryFrameTrigger, null);
             }
 
+            //Simplification Queue
+            if (!this.simplificationQueue.running) {
+                this.simplificationQueue.executeNext();
+            }
+
             // Before render
             if (this.beforeRender) {
                 this.beforeRender();