فهرست منبع

FileTools optionnal

sebavan 5 سال پیش
والد
کامیت
e98e6012c5
4فایلهای تغییر یافته به همراه42 افزوده شده و 6 حذف شده
  1. 18 2
      src/Engines/Processors/shaderProcessor.ts
  2. 16 3
      src/Engines/thinEngine.ts
  3. 2 0
      src/Materials/Textures/baseTexture.ts
  4. 6 1
      src/Misc/fileTools.ts

+ 18 - 2
src/Engines/Processors/shaderProcessor.ts

@@ -8,7 +8,8 @@ import { ShaderDefineAndOperator } from './Expressions/Operators/shaderDefineAnd
 import { ShaderDefineExpression } from './Expressions/shaderDefineExpression';
 import { ShaderDefineArithmeticOperator } from './Expressions/Operators/shaderDefineArithmeticOperator';
 import { ProcessingOptions } from './shaderProcessingOptions';
-import { FileTools } from '../../Misc/fileTools';
+import { _DevTools } from '../../Misc/devTools';
+import { IOfflineProvider, WebRequest, LoadFileError, IFileRequest } from '../..';
 
 /** @hidden */
 export class ShaderProcessor {
@@ -331,7 +332,7 @@ export class ShaderProcessor {
             } else {
                 var includeShaderUrl = options.shadersRepository + "ShadersInclude/" + includeFile + ".fx";
 
-                FileTools.LoadFile(includeShaderUrl, (fileContent) => {
+                ShaderProcessor._FileToolsLoadFile(includeShaderUrl, (fileContent) => {
                     options.includesShadersStore[includeFile] = fileContent as string;
                     this._ProcessIncludes(<string>returnValue, options, callback);
                 });
@@ -343,4 +344,19 @@ export class ShaderProcessor {
 
         callback(returnValue);
     }
+
+    /**
+     * Loads a file from a url
+     * @param url url to load
+     * @param onSuccess callback called when the file successfully loads
+     * @param onProgress callback called while file is loading (if the server supports this mode)
+     * @param offlineProvider defines the offline provider for caching
+     * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer
+     * @param onError callback called when the file fails to load
+     * @returns a file request object
+     * @hidden
+     */
+    public static _FileToolsLoadFile(url: string, onSuccess: (data: string | ArrayBuffer, responseURL?: string) => void, onProgress?: (ev: ProgressEvent) => void, offlineProvider?: IOfflineProvider, useArrayBuffer?: boolean, onError?: (request?: WebRequest, exception?: LoadFileError) => void): IFileRequest {
+        throw  _DevTools.WarnImport("FileTools");
+    }
 }

+ 16 - 3
src/Engines/thinEngine.ts

@@ -23,7 +23,6 @@ import { IPipelineContext } from './IPipelineContext';
 import { WebGLPipelineContext } from './WebGL/webGLPipelineContext';
 import { VertexBuffer } from '../Meshes/buffer';
 import { InstancingAttributeInfo } from './instancingAttributeInfo';
-import { FileTools } from '../Misc/fileTools';
 import { BaseTexture } from '../Materials/Textures/baseTexture';
 import { IOfflineProvider } from '../Offline/IOfflineProvider';
 import { IEffectFallbacks } from '../Materials/iEffectFallbacks';
@@ -2952,11 +2951,11 @@ export class ThinEngine {
                 if (buffer && ((<HTMLImageElement>buffer).decoding || (<ImageBitmap>buffer).close)) {
                     onload(<HTMLImageElement>buffer);
                 } else {
-                    FileTools.LoadImage(url, onload, onInternalError, scene ? scene.offlineProvider : null, mimeType);
+                    ThinEngine._FileToolsLoadImage(url, onload, onInternalError, scene ? scene.offlineProvider : null, mimeType);
                 }
             }
             else if (typeof buffer === "string" || buffer instanceof ArrayBuffer || ArrayBuffer.isView(buffer) || buffer instanceof Blob) {
-                FileTools.LoadImage(buffer, onload, onInternalError, scene ? scene.offlineProvider : null, mimeType);
+                ThinEngine._FileToolsLoadImage(buffer, onload, onInternalError, scene ? scene.offlineProvider : null, mimeType);
             }
             else if (buffer) {
                 onload(<HTMLImageElement>buffer);
@@ -2967,6 +2966,20 @@ export class ThinEngine {
     }
 
     /**
+     * Loads an image as an HTMLImageElement.
+     * @param input url string, ArrayBuffer, or Blob to load
+     * @param onLoad callback called when the image successfully loads
+     * @param onError callback called when the image fails to load
+     * @param offlineProvider offline provider for caching
+     * @param mimeType optional mime type
+     * @returns the HTMLImageElement of the loaded image
+     * @hidden
+     */
+    public static _FileToolsLoadImage(input: string | ArrayBuffer | ArrayBufferView | Blob, onLoad: (img: HTMLImageElement | ImageBitmap) => void, onError: (message?: string, exception?: any) => void, offlineProvider: Nullable<IOfflineProvider>, mimeType?: string): Nullable<HTMLImageElement> {
+        throw _DevTools.WarnImport("FileTools");
+    }
+
+    /**
      * @hidden
      */
     public _rescaleTexture(source: InternalTexture, destination: InternalTexture, scene: Nullable<any>, internalFormat: number, onComplete: () => void): void {

+ 2 - 0
src/Materials/Textures/baseTexture.ts

@@ -11,6 +11,8 @@ import { IAnimatable } from '../../Animations/animatable.interface';
 import { GUID } from '../../Misc/guid';
 import { ISize, Size } from '../../Maths/math.size';
 
+import "../../Misc/fileTools";
+
 declare type Animation = import("../../Animations/animation").Animation;
 
 /**

+ 6 - 1
src/Misc/fileTools.ts

@@ -8,6 +8,8 @@ import { FilesInputStore } from './filesInputStore';
 import { RetryStrategy } from './retryStrategy';
 import { BaseError } from './baseError';
 import { StringTools } from './stringTools';
+import { ThinEngine } from '../Engines';
+import { ShaderProcessor } from '../Engines/Processors';
 
 /** @ignore */
 export class LoadFileError extends BaseError {
@@ -468,4 +470,7 @@ export class FileTools {
     public static IsFileURL(): boolean {
         return location.protocol === "file:";
     }
-}
+}
+
+ThinEngine._FileToolsLoadImage = FileTools.LoadImage;
+ShaderProcessor._FileToolsLoadFile = FileTools.LoadFile;