|
@@ -1,25 +1,67 @@
|
|
module BABYLON {
|
|
module BABYLON {
|
|
|
|
+ /**
|
|
|
|
+ * Class used to represent data loading progression
|
|
|
|
+ */
|
|
export class SceneLoaderProgressEvent {
|
|
export class SceneLoaderProgressEvent {
|
|
- constructor(public readonly lengthComputable: boolean, public readonly loaded: number, public readonly total: number) {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Create a new progress event
|
|
|
|
+ * @param lengthComputable defines if data length to load can be evaluated
|
|
|
|
+ * @param loaded defines the loaded data length
|
|
|
|
+ * @param total defines the data length to load
|
|
|
|
+ */
|
|
|
|
+ constructor(
|
|
|
|
+ /** defines if data length to load can be evaluated */
|
|
|
|
+ public readonly lengthComputable: boolean,
|
|
|
|
+ /** defines the loaded data length */
|
|
|
|
+ public readonly loaded: number,
|
|
|
|
+ /** defines the data length to load */
|
|
|
|
+ public readonly total: number) {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Creates a new SceneLoaderProgressEvent from a ProgressEvent
|
|
|
|
+ * @param event defines the source event
|
|
|
|
+ * @returns a new SceneLoaderProgressEvent
|
|
|
|
+ */
|
|
public static FromProgressEvent(event: ProgressEvent): SceneLoaderProgressEvent {
|
|
public static FromProgressEvent(event: ProgressEvent): SceneLoaderProgressEvent {
|
|
return new SceneLoaderProgressEvent(event.lengthComputable, event.loaded, event.total);
|
|
return new SceneLoaderProgressEvent(event.lengthComputable, event.loaded, event.total);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Interface used by SceneLoader plugins to define supported file extensions
|
|
|
|
+ */
|
|
export interface ISceneLoaderPluginExtensions {
|
|
export interface ISceneLoaderPluginExtensions {
|
|
|
|
+ /**
|
|
|
|
+ * Defines the list of supported extensions
|
|
|
|
+ */
|
|
[extension: string]: {
|
|
[extension: string]: {
|
|
isBinary: boolean;
|
|
isBinary: boolean;
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Interface used by SceneLoader plugin factory
|
|
|
|
+ */
|
|
export interface ISceneLoaderPluginFactory {
|
|
export interface ISceneLoaderPluginFactory {
|
|
|
|
+ /**
|
|
|
|
+ * Defines the name of the factory
|
|
|
|
+ */
|
|
name: string;
|
|
name: string;
|
|
|
|
+ /**
|
|
|
|
+ * Function called to create a new plugin
|
|
|
|
+ * @return the new plugin
|
|
|
|
+ */
|
|
createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
|
|
createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
|
|
|
|
+ /**
|
|
|
|
+ * Boolean indicating if the plugin can direct load specific data
|
|
|
|
+ */
|
|
canDirectLoad?: (data: string) => boolean;
|
|
canDirectLoad?: (data: string) => boolean;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Interface used to define a SceneLoader plugin
|
|
|
|
+ */
|
|
export interface ISceneLoaderPlugin {
|
|
export interface ISceneLoaderPlugin {
|
|
/**
|
|
/**
|
|
* The friendly name of this plugin.
|
|
* The friendly name of this plugin.
|
|
@@ -76,6 +118,9 @@
|
|
loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
|
|
loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Interface used to define an async SceneLoader plugin
|
|
|
|
+ */
|
|
export interface ISceneLoaderPluginAsync {
|
|
export interface ISceneLoaderPluginAsync {
|
|
/**
|
|
/**
|
|
* The friendly name of this plugin.
|
|
* The friendly name of this plugin.
|
|
@@ -132,41 +177,73 @@
|
|
loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
|
|
loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Defines a plugin registered by the SceneLoader
|
|
|
|
+ */
|
|
interface IRegisteredPlugin {
|
|
interface IRegisteredPlugin {
|
|
|
|
+ /**
|
|
|
|
+ * Defines the plugin to use
|
|
|
|
+ */
|
|
plugin: ISceneLoaderPlugin | ISceneLoaderPluginAsync | ISceneLoaderPluginFactory;
|
|
plugin: ISceneLoaderPlugin | ISceneLoaderPluginAsync | ISceneLoaderPluginFactory;
|
|
|
|
+ /**
|
|
|
|
+ * Defines if the plugin supports binary data
|
|
|
|
+ */
|
|
isBinary: boolean;
|
|
isBinary: boolean;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Defines file information
|
|
|
|
+ */
|
|
interface IFileInfo {
|
|
interface IFileInfo {
|
|
|
|
+ /**
|
|
|
|
+ * Gets the file url
|
|
|
|
+ */
|
|
url: string;
|
|
url: string;
|
|
|
|
+ /**
|
|
|
|
+ * Gets the root url
|
|
|
|
+ */
|
|
rootUrl: string;
|
|
rootUrl: string;
|
|
|
|
+ /**
|
|
|
|
+ * Gets filename
|
|
|
|
+ */
|
|
name: string;
|
|
name: string;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Class used to load scene from various file formats using registered plugins
|
|
|
|
+ * @see http://doc.babylonjs.com/how_to/load_from_any_file_type
|
|
|
|
+ */
|
|
export class SceneLoader {
|
|
export class SceneLoader {
|
|
// Flags
|
|
// Flags
|
|
private static _ForceFullSceneLoadingForIncremental = false;
|
|
private static _ForceFullSceneLoadingForIncremental = false;
|
|
private static _ShowLoadingScreen = true;
|
|
private static _ShowLoadingScreen = true;
|
|
private static _CleanBoneMatrixWeights = false;
|
|
private static _CleanBoneMatrixWeights = false;
|
|
|
|
|
|
- public static get NO_LOGGING(): number {
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
|
+ * No logging while loading
|
|
|
|
+ */
|
|
|
|
+ public static readonly NO_LOGGING = 0;
|
|
|
|
|
|
- public static get MINIMAL_LOGGING(): number {
|
|
|
|
- return 1;
|
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Minimal logging while loading
|
|
|
|
+ */
|
|
|
|
+ public static readonly MINIMAL_LOGGING = 1;
|
|
|
|
|
|
- public static get SUMMARY_LOGGING(): number {
|
|
|
|
- return 2;
|
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Summary logging while loading
|
|
|
|
+ */
|
|
|
|
+ public static readonly SUMMARY_LOGGING = 2;
|
|
|
|
|
|
- public static get DETAILED_LOGGING(): number {
|
|
|
|
- return 3;
|
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Detailled logging while loading
|
|
|
|
+ */
|
|
|
|
+ public static readonly DETAILED_LOGGING = 3;
|
|
|
|
|
|
private static _loggingLevel = SceneLoader.NO_LOGGING;
|
|
private static _loggingLevel = SceneLoader.NO_LOGGING;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Gets or sets a boolean indicating if entire scene must be loaded even if scene contains incremental data
|
|
|
|
+ */
|
|
public static get ForceFullSceneLoadingForIncremental() {
|
|
public static get ForceFullSceneLoadingForIncremental() {
|
|
return SceneLoader._ForceFullSceneLoadingForIncremental;
|
|
return SceneLoader._ForceFullSceneLoadingForIncremental;
|
|
}
|
|
}
|
|
@@ -175,6 +252,9 @@
|
|
SceneLoader._ForceFullSceneLoadingForIncremental = value;
|
|
SceneLoader._ForceFullSceneLoadingForIncremental = value;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Gets or sets a boolean indicating if loading screen must be displayed while loading a scene
|
|
|
|
+ */
|
|
public static get ShowLoadingScreen(): boolean {
|
|
public static get ShowLoadingScreen(): boolean {
|
|
return SceneLoader._ShowLoadingScreen;
|
|
return SceneLoader._ShowLoadingScreen;
|
|
}
|
|
}
|
|
@@ -183,6 +263,10 @@
|
|
SceneLoader._ShowLoadingScreen = value;
|
|
SceneLoader._ShowLoadingScreen = value;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Defines the current logging level (while loading the scene)
|
|
|
|
+ * @ignorenaming
|
|
|
|
+ */
|
|
public static get loggingLevel(): number {
|
|
public static get loggingLevel(): number {
|
|
return SceneLoader._loggingLevel;
|
|
return SceneLoader._loggingLevel;
|
|
}
|
|
}
|
|
@@ -191,6 +275,9 @@
|
|
SceneLoader._loggingLevel = value;
|
|
SceneLoader._loggingLevel = value;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Gets or set a boolean indicating if matrix weights must be cleaned upon loading
|
|
|
|
+ */
|
|
public static get CleanBoneMatrixWeights(): boolean {
|
|
public static get CleanBoneMatrixWeights(): boolean {
|
|
return SceneLoader._CleanBoneMatrixWeights;
|
|
return SceneLoader._CleanBoneMatrixWeights;
|
|
}
|
|
}
|
|
@@ -200,6 +287,10 @@
|
|
}
|
|
}
|
|
|
|
|
|
// Members
|
|
// Members
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Event raised when a plugin is used to load a scene
|
|
|
|
+ */
|
|
public static OnPluginActivatedObservable = new Observable<ISceneLoaderPlugin | ISceneLoaderPluginAsync>();
|
|
public static OnPluginActivatedObservable = new Observable<ISceneLoaderPlugin | ISceneLoaderPluginAsync>();
|
|
|
|
|
|
private static _registeredPlugins: { [extension: string]: IRegisteredPlugin } = {};
|
|
private static _registeredPlugins: { [extension: string]: IRegisteredPlugin } = {};
|
|
@@ -375,14 +466,29 @@
|
|
}
|
|
}
|
|
|
|
|
|
// Public functions
|
|
// Public functions
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets a plugin that can load the given extension
|
|
|
|
+ * @param extension defines the extension to load
|
|
|
|
+ * @returns a plugin or null if none works
|
|
|
|
+ */
|
|
public static GetPluginForExtension(extension: string): ISceneLoaderPlugin | ISceneLoaderPluginAsync | ISceneLoaderPluginFactory {
|
|
public static GetPluginForExtension(extension: string): ISceneLoaderPlugin | ISceneLoaderPluginAsync | ISceneLoaderPluginFactory {
|
|
return SceneLoader._getPluginForExtension(extension).plugin;
|
|
return SceneLoader._getPluginForExtension(extension).plugin;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Gets a boolean indicating that the given extension can be loaded
|
|
|
|
+ * @param extension defines the extension to load
|
|
|
|
+ * @returns true if the extension is supported
|
|
|
|
+ */
|
|
public static IsPluginForExtensionAvailable(extension: string): boolean {
|
|
public static IsPluginForExtensionAvailable(extension: string): boolean {
|
|
return !!SceneLoader._registeredPlugins[extension];
|
|
return !!SceneLoader._registeredPlugins[extension];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Adds a new plugin to the list of registered plugins
|
|
|
|
+ * @param plugin defines the plugin to add
|
|
|
|
+ */
|
|
public static RegisterPlugin(plugin: ISceneLoaderPlugin | ISceneLoaderPluginAsync): void {
|
|
public static RegisterPlugin(plugin: ISceneLoaderPlugin | ISceneLoaderPluginAsync): void {
|
|
if (typeof plugin.extensions === "string") {
|
|
if (typeof plugin.extensions === "string") {
|
|
var extension = <string>plugin.extensions;
|
|
var extension = <string>plugin.extensions;
|