|
@@ -57,6 +57,29 @@ interface IRegisteredExtension {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * Type of data held by a texture
|
|
|
|
+ * @hidden
|
|
|
|
+ */
|
|
|
|
+export enum TextureDataType {
|
|
|
|
+ /** color data (albedo, emissive, ...) */
|
|
|
|
+ Color,
|
|
|
|
+ /** roughness data */
|
|
|
|
+ Roughness,
|
|
|
|
+ /** normal map */
|
|
|
|
+ Normal,
|
|
|
|
+ /** glossiness data */
|
|
|
|
+ Glossiness,
|
|
|
|
+ /** specular map */
|
|
|
|
+ Specular,
|
|
|
|
+ /** transmission map (thickness) */
|
|
|
|
+ Transmission,
|
|
|
|
+ /** metallic/roughness data */
|
|
|
|
+ MetallicRoughness,
|
|
|
|
+ /** occlusion data */
|
|
|
|
+ Occlusion
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
* Helper class for working with arrays when loading the glTF asset
|
|
* Helper class for working with arrays when loading the glTF asset
|
|
*/
|
|
*/
|
|
export class ArrayItem {
|
|
export class ArrayItem {
|
|
@@ -1713,7 +1736,7 @@ export class GLTFLoader implements IGLTFLoader {
|
|
promises.push(this.loadTextureInfoAsync(`${context}/metallicRoughnessTexture`, properties.metallicRoughnessTexture, (texture) => {
|
|
promises.push(this.loadTextureInfoAsync(`${context}/metallicRoughnessTexture`, properties.metallicRoughnessTexture, (texture) => {
|
|
texture.name = `${babylonMaterial.name} (Metallic Roughness)`;
|
|
texture.name = `${babylonMaterial.name} (Metallic Roughness)`;
|
|
babylonMaterial.metallicTexture = texture;
|
|
babylonMaterial.metallicTexture = texture;
|
|
- }));
|
|
|
|
|
|
+ }, TextureDataType.MetallicRoughness));
|
|
|
|
|
|
babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
|
|
babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
|
|
babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
|
|
babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
|
|
@@ -1854,7 +1877,7 @@ export class GLTFLoader implements IGLTFLoader {
|
|
promises.push(this.loadTextureInfoAsync(`${context}/normalTexture`, material.normalTexture, (texture) => {
|
|
promises.push(this.loadTextureInfoAsync(`${context}/normalTexture`, material.normalTexture, (texture) => {
|
|
texture.name = `${babylonMaterial.name} (Normal)`;
|
|
texture.name = `${babylonMaterial.name} (Normal)`;
|
|
babylonMaterial.bumpTexture = texture;
|
|
babylonMaterial.bumpTexture = texture;
|
|
- }));
|
|
|
|
|
|
+ }, TextureDataType.Normal));
|
|
|
|
|
|
babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
|
|
babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
|
|
babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
|
|
babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
|
|
@@ -1869,7 +1892,7 @@ export class GLTFLoader implements IGLTFLoader {
|
|
promises.push(this.loadTextureInfoAsync(`${context}/occlusionTexture`, material.occlusionTexture, (texture) => {
|
|
promises.push(this.loadTextureInfoAsync(`${context}/occlusionTexture`, material.occlusionTexture, (texture) => {
|
|
texture.name = `${babylonMaterial.name} (Occlusion)`;
|
|
texture.name = `${babylonMaterial.name} (Occlusion)`;
|
|
babylonMaterial.ambientTexture = texture;
|
|
babylonMaterial.ambientTexture = texture;
|
|
- }));
|
|
|
|
|
|
+ }, TextureDataType.Occlusion));
|
|
|
|
|
|
babylonMaterial.useAmbientInGrayScale = true;
|
|
babylonMaterial.useAmbientInGrayScale = true;
|
|
if (material.occlusionTexture.strength != undefined) {
|
|
if (material.occlusionTexture.strength != undefined) {
|
|
@@ -1932,10 +1955,11 @@ export class GLTFLoader implements IGLTFLoader {
|
|
* @param context The context when loading the asset
|
|
* @param context The context when loading the asset
|
|
* @param textureInfo The glTF texture info property
|
|
* @param textureInfo The glTF texture info property
|
|
* @param assign A function called synchronously after parsing the glTF properties
|
|
* @param assign A function called synchronously after parsing the glTF properties
|
|
|
|
+ * @param textureDataType type of data held by the texture
|
|
* @returns A promise that resolves with the loaded Babylon texture when the load is complete
|
|
* @returns A promise that resolves with the loaded Babylon texture when the load is complete
|
|
*/
|
|
*/
|
|
- public loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void = () => { }): Promise<BaseTexture> {
|
|
|
|
- const extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
|
|
|
|
|
|
+ public loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void = () => { }, textureDataType: TextureDataType = TextureDataType.Color): Promise<BaseTexture> {
|
|
|
|
+ const extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign, textureDataType);
|
|
if (extensionPromise) {
|
|
if (extensionPromise) {
|
|
return extensionPromise;
|
|
return extensionPromise;
|
|
}
|
|
}
|
|
@@ -1952,7 +1976,7 @@ export class GLTFLoader implements IGLTFLoader {
|
|
GLTFLoader.AddPointerMetadata(babylonTexture, context);
|
|
GLTFLoader.AddPointerMetadata(babylonTexture, context);
|
|
this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
|
|
this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
|
|
assign(babylonTexture);
|
|
assign(babylonTexture);
|
|
- });
|
|
|
|
|
|
+ }, textureDataType);
|
|
|
|
|
|
this.logClose();
|
|
this.logClose();
|
|
|
|
|
|
@@ -1960,8 +1984,8 @@ export class GLTFLoader implements IGLTFLoader {
|
|
}
|
|
}
|
|
|
|
|
|
/** @hidden */
|
|
/** @hidden */
|
|
- public _loadTextureAsync(context: string, texture: ITexture, assign: (babylonTexture: BaseTexture) => void = () => { }): Promise<BaseTexture> {
|
|
|
|
- const extensionPromise = this._extensionsLoadTextureAsync(context, texture, assign);
|
|
|
|
|
|
+ public _loadTextureAsync(context: string, texture: ITexture, assign: (babylonTexture: BaseTexture) => void = () => { }, textureDataType: TextureDataType = TextureDataType.Color): Promise<BaseTexture> {
|
|
|
|
+ const extensionPromise = this._extensionsLoadTextureAsync(context, texture, assign, textureDataType);
|
|
if (extensionPromise) {
|
|
if (extensionPromise) {
|
|
return extensionPromise;
|
|
return extensionPromise;
|
|
}
|
|
}
|
|
@@ -1978,7 +2002,7 @@ export class GLTFLoader implements IGLTFLoader {
|
|
}
|
|
}
|
|
|
|
|
|
/** @hidden */
|
|
/** @hidden */
|
|
- public _createTextureAsync(context: string, sampler: ISampler, image: IImage, assign: (babylonTexture: BaseTexture) => void = () => { }): Promise<BaseTexture> {
|
|
|
|
|
|
+ public _createTextureAsync(context: string, sampler: ISampler, image: IImage, assign: (babylonTexture: BaseTexture) => void = () => { }, textureLoaderOptions?: any): Promise<BaseTexture> {
|
|
const samplerData = this._loadSampler(`/samplers/${sampler.index}`, sampler);
|
|
const samplerData = this._loadSampler(`/samplers/${sampler.index}`, sampler);
|
|
|
|
|
|
const promises = new Array<Promise<any>>();
|
|
const promises = new Array<Promise<any>>();
|
|
@@ -1993,7 +2017,7 @@ export class GLTFLoader implements IGLTFLoader {
|
|
if (!this._disposed) {
|
|
if (!this._disposed) {
|
|
deferred.reject(new Error(`${context}: ${(exception && exception.message) ? exception.message : message || "Failed to load texture"}`));
|
|
deferred.reject(new Error(`${context}: ${(exception && exception.message) ? exception.message : message || "Failed to load texture"}`));
|
|
}
|
|
}
|
|
- }, undefined, undefined, undefined, image.mimeType);
|
|
|
|
|
|
+ }, undefined, undefined, undefined, image.mimeType, textureLoaderOptions);
|
|
this._babylonScene._blockEntityCollection = false;
|
|
this._babylonScene._blockEntityCollection = false;
|
|
promises.push(deferred.promise);
|
|
promises.push(deferred.promise);
|
|
|
|
|
|
@@ -2338,12 +2362,12 @@ export class GLTFLoader implements IGLTFLoader {
|
|
return this._applyExtensions(material, "loadMaterialProperties", (extension) => extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial));
|
|
return this._applyExtensions(material, "loadMaterialProperties", (extension) => extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial));
|
|
}
|
|
}
|
|
|
|
|
|
- private _extensionsLoadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>> {
|
|
|
|
- return this._applyExtensions(textureInfo, "loadTextureInfo", (extension) => extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign));
|
|
|
|
|
|
+ private _extensionsLoadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void, textureDataType: TextureDataType): Nullable<Promise<BaseTexture>> {
|
|
|
|
+ return this._applyExtensions(textureInfo, "loadTextureInfo", (extension) => extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign, textureDataType));
|
|
}
|
|
}
|
|
|
|
|
|
- private _extensionsLoadTextureAsync(context: string, texture: ITexture, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>> {
|
|
|
|
- return this._applyExtensions(texture, "loadTexture", (extension) => extension._loadTextureAsync && extension._loadTextureAsync(context, texture, assign));
|
|
|
|
|
|
+ private _extensionsLoadTextureAsync(context: string, texture: ITexture, assign: (babylonTexture: BaseTexture) => void, textureDataType: TextureDataType): Nullable<Promise<BaseTexture>> {
|
|
|
|
+ return this._applyExtensions(texture, "loadTexture", (extension) => extension._loadTextureAsync && extension._loadTextureAsync(context, texture, assign, textureDataType));
|
|
}
|
|
}
|
|
|
|
|
|
private _extensionsLoadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>> {
|
|
private _extensionsLoadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>> {
|