Преглед на файлове

Add AssetTask for EquiRectangularCubeTextures

Dennis Dervisis преди 6 години
родител
ревизия
cf85998f1e
променени са 1 файла, в които са добавени 90 реда и са изтрити 0 реда
  1. 90 0
      src/Misc/assetsManager.ts

+ 90 - 0
src/Misc/assetsManager.ts

@@ -11,6 +11,7 @@ import { CubeTexture } from "../Materials/Textures/cubeTexture";
 import { HDRCubeTexture } from "../Materials/Textures/hdrCubeTexture";
 import { Logger } from "../Misc/logger";
 import { AnimationGroup } from '../Animations/animationGroup';
+import { EquiRectangularCubeTexture } from 'Materials/Textures/equiRectangularCubeTexture';
 
 /**
  * Defines the list of states available for a task inside a AssetsManager
@@ -686,6 +687,77 @@ export class HDRCubeTextureAssetTask extends AbstractAssetTask implements ITextu
     }
 }
 
+class EquiRectangularCubeTextureAssetTask extends AbstractAssetTask implements ITextureAssetTask<EquiRectangularCubeTexture> {
+    /**
+     * Gets the loaded texture
+     */
+    public texture: EquiRectangularCubeTexture;
+
+    /**
+     * Callback called when the task is successful
+     */
+    public onSuccess: (task: EquiRectangularCubeTextureAssetTask) => void;
+    /**
+     * Callback called when the task is successful
+     */
+    public onError: (task: EquiRectangularCubeTextureAssetTask, message?: string, exception?: any) => void;
+
+    /**
+     * Creates a new EquiRectangularCubeTextureAssetTask object
+     * @param name defines the name of the task
+     * @param url defines the location of the file to load
+     * @param size defines the desired size (the more it increases the longer the generation will be)
+     * If the size is omitted this implies you are using a preprocessed cubemap.
+     * @param noMipmap defines if mipmaps should not be generated (default is false)
+     * @param gammaSpace specifies if the texture will be used in gamma or linear space
+     * (the PBR material requires those texture in linear space, but the standard material would require them in Gamma space)
+     * (default is false)
+     */
+    constructor(
+        /**
+         * Defines the name of the task
+         */
+        public name: string,
+        /**
+         * Defines the location of the file to load
+         */
+        public url: string,
+        /**
+         * Defines the desired size (the more it increases the longer the generation will be)
+         */
+        public size: number,
+        /**
+         * Defines if mipmaps should not be generated (default is false)
+         */
+        public noMipmap: boolean = false,
+        /**
+         * Specifies if the texture will be use in gamma or linear space (the PBR material requires those texture in linear space,
+         * but the standard material would require them in Gamma space) (default is false)
+         */
+        public gammaSpace: boolean = false) {
+        super(name);
+    }
+
+    /**
+     * Execute the current task
+     * @param scene defines the scene where you want your assets to be loaded
+     * @param onSuccess is a callback called when the task is successfully executed
+     * @param onError is a callback called if an error occurs
+     */
+    public run(scene: Scene, onSuccess: () => void, onError: (message?: string, exception?: any) => void): void {
+
+        const onload = () => {
+            onSuccess();
+        };
+
+        const onerror = (message?: string, exception?: any) => {
+            onError(message, exception);
+        };
+
+        this.texture = new EquiRectangularCubeTexture(this.url, scene, this.size, this.noMipmap, this.gammaSpace, onload, onerror);
+    }
+}
+
 /**
  * This class can be used to easily import assets into a scene
  * @see http://doc.babylonjs.com/how_to/how_to_use_assetsmanager
@@ -858,6 +930,24 @@ export class AssetsManager {
     }
 
     /**
+     *
+     * Add a EquiRectangularCubeTextureAssetTask to the list of active tasks
+     * @param taskName defines the name of the new task
+     * @param url defines the url of the file to load
+     * @param size defines the size you want for the cubemap (can be null)
+     * @param noMipmap defines if the texture must not receive mipmaps (false by default)
+     * @param gammaSpace Specifies if the texture will be used in gamma or linear space
+     * (the PBR material requires those textures in linear space, but the standard material would require them in Gamma space)
+     * @returns a new EquiRectangularCubeTextureAssetTask object
+     */
+    public addEquiRectangularCubeTextureAssetTask(taskName: string, url: string, size: number, noMipmap = false, gammaSpace = true): EquiRectangularCubeTextureAssetTask {
+        const task = new EquiRectangularCubeTextureAssetTask(taskName, url, size, noMipmap, gammaSpace);
+        this._tasks.push(task);
+
+        return task;
+    }
+
+    /**
      * Remove a task from the assets manager.
      * @param task the task to remove
      */