|
@@ -5,9 +5,14 @@ module BABYLON.GLTF2 {
|
|
|
* Abstract class that can be implemented to extend existing glTF loader behavior.
|
|
|
*/
|
|
|
export abstract class GLTFLoaderExtension implements IGLTFLoaderExtension, IDisposable {
|
|
|
- /** Gets or sets a boolean indicating if the extension is enabled */
|
|
|
+ /**
|
|
|
+ * Gets or sets a boolean indicating if the extension is enabled
|
|
|
+ */
|
|
|
public enabled = true;
|
|
|
- /** Gets or sets extension name */
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Gets or sets extension name
|
|
|
+ */
|
|
|
public abstract readonly name: string;
|
|
|
|
|
|
protected _loader: GLTFLoader;
|
|
@@ -20,15 +25,17 @@ module BABYLON.GLTF2 {
|
|
|
this._loader = loader;
|
|
|
}
|
|
|
|
|
|
- /** Release all resources */
|
|
|
+ /**
|
|
|
+ * Release all resources
|
|
|
+ */
|
|
|
public dispose(): void {
|
|
|
delete this._loader;
|
|
|
}
|
|
|
|
|
|
// #region Overridable Methods
|
|
|
|
|
|
- /**
|
|
|
- * Override this method to modify the default behavior for loading scenes.
|
|
|
+ /**
|
|
|
+ * Override this method to modify the default behavior for loading scenes.
|
|
|
* @hidden
|
|
|
*/
|
|
|
protected _loadSceneAsync(context: string, node: _ILoaderScene): Nullable<Promise<void>> { return null; }
|
|
@@ -39,18 +46,22 @@ module BABYLON.GLTF2 {
|
|
|
*/
|
|
|
protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>> { return null; }
|
|
|
|
|
|
- /** Override this method to modify the default behavior for loading mesh primitive vertex data. */
|
|
|
+ /**
|
|
|
+ * Override this method to modify the default behavior for loading mesh primitive vertex data.
|
|
|
+ * @hidden
|
|
|
+ */
|
|
|
protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>> { return null; }
|
|
|
|
|
|
- /** Override this method to modify the default behavior for loading materials.
|
|
|
+ /**
|
|
|
+ * Override this method to modify the default behavior for loading materials.
|
|
|
* @hidden
|
|
|
*/
|
|
|
- protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>> { return null; }
|
|
|
+ protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>> { return null; }
|
|
|
|
|
|
/**
|
|
|
* Override this method to modify the default behavior for loading textures.
|
|
|
* @hidden
|
|
|
- */
|
|
|
+ */
|
|
|
protected _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>> { return null; }
|
|
|
|
|
|
/**
|
|
@@ -65,7 +76,7 @@ module BABYLON.GLTF2 {
|
|
|
* Helper method called by a loader extension to load an glTF extension.
|
|
|
* @hidden
|
|
|
*/
|
|
|
- protected _loadExtensionAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, extension: TProperty) => Promise<TResult>): Nullable<Promise<TResult>> {
|
|
|
+ protected _loadExtensionAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, extension: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>> {
|
|
|
if (!property.extensions) {
|
|
|
return null;
|
|
|
}
|
|
@@ -77,7 +88,7 @@ module BABYLON.GLTF2 {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- // Clear out the extension before executing the action to avoid recursing into the same property.
|
|
|
+ // Clear out the extension before executing the action to avoid infinite recursion.
|
|
|
delete extensions[this.name];
|
|
|
|
|
|
try {
|
|
@@ -89,6 +100,34 @@ module BABYLON.GLTF2 {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Helper method called by the loader to allow extensions to override loading scenes.
|
|
|
+ * @hidden
|
|
|
+ */
|
|
|
+ protected _loadExtrasValueAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, value: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>> {
|
|
|
+ if (!property.extras) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ const extras = property.extras;
|
|
|
+
|
|
|
+ const value = extras[this.name] as TProperty;
|
|
|
+ if (value === undefined) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Clear out the extras value before executing the action to avoid infinite recursion.
|
|
|
+ delete extras[this.name];
|
|
|
+
|
|
|
+ try {
|
|
|
+ return actionAsync(`${context}/extras/${this.name}`, value);
|
|
|
+ }
|
|
|
+ finally {
|
|
|
+ // Restore the extras value after executing the action.
|
|
|
+ extras[this.name] = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Helper method called by the loader to allow extensions to override loading scenes.
|
|
|
* @hidden
|
|
@@ -117,8 +156,8 @@ module BABYLON.GLTF2 {
|
|
|
* Helper method called by the loader to allow extensions to override loading materials.
|
|
|
* @hidden
|
|
|
*/
|
|
|
- public static _LoadMaterialAsync(loader: GLTFLoader, context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>> {
|
|
|
- return loader._applyExtensions(extension => extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign));
|
|
|
+ public static _LoadMaterialAsync(loader: GLTFLoader, context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>> {
|
|
|
+ return loader._applyExtensions(extension => extension._loadMaterialAsync(context, material, mesh, babylonMesh, babylonDrawMode, assign));
|
|
|
}
|
|
|
|
|
|
/**
|