|
@@ -1714,39 +1714,30 @@ module BABYLON.GLTF2 {
|
|
const samplerData = this._loadSampler(`/samplers/${sampler.index}`, sampler);
|
|
const samplerData = this._loadSampler(`/samplers/${sampler.index}`, sampler);
|
|
|
|
|
|
const image = ArrayItem.Get(`${context}/source`, this.gltf.images, texture.source);
|
|
const image = ArrayItem.Get(`${context}/source`, this.gltf.images, texture.source);
|
|
- let babylonTexture: Texture;
|
|
|
|
- if (image.uri && this.babylonScene.getEngine().textureFormatInUse) {
|
|
|
|
|
|
+ let textureURL: Nullable<string> = null;
|
|
|
|
+ if (image.uri && !Tools.IsBase64(image.uri) && this.babylonScene.getEngine().textureFormatInUse) {
|
|
// If an image uri and a texture format is set like (eg. KTX) load from url instead of blob to support texture format and fallback
|
|
// If an image uri and a texture format is set like (eg. KTX) load from url instead of blob to support texture format and fallback
|
|
- const deferred = new Deferred<void>();
|
|
|
|
- babylonTexture = new Texture(`${this._uniqueRootUrl}` + image.uri, this.babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, () => {
|
|
|
|
- if (!this._disposed) {
|
|
|
|
- deferred.resolve();
|
|
|
|
- }
|
|
|
|
- }, (message, exception) => {
|
|
|
|
- if (!this._disposed) {
|
|
|
|
- deferred.reject(new Error(`${context}: ${(exception && exception.message) ? exception.message : message || "Failed to load texture"}`));
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- promises.push(deferred.promise);
|
|
|
|
- }else {
|
|
|
|
- const deferred = new Deferred<void>();
|
|
|
|
- babylonTexture = new Texture(null, this.babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, () => {
|
|
|
|
- if (!this._disposed) {
|
|
|
|
- deferred.resolve();
|
|
|
|
- }
|
|
|
|
- }, (message, exception) => {
|
|
|
|
- if (!this._disposed) {
|
|
|
|
- deferred.reject(new Error(`${context}: ${(exception && exception.message) ? exception.message : message || "Failed to load texture"}`));
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- promises.push(deferred.promise);
|
|
|
|
|
|
+ textureURL = this._uniqueRootUrl + image.uri;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ const deferred = new Deferred<void>();
|
|
|
|
+ let babylonTexture = new Texture(textureURL, this.babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, () => {
|
|
|
|
+ if (!this._disposed) {
|
|
|
|
+ deferred.resolve();
|
|
|
|
+ }
|
|
|
|
+ }, (message, exception) => {
|
|
|
|
+ if (!this._disposed) {
|
|
|
|
+ deferred.reject(new Error(`${context}: ${(exception && exception.message) ? exception.message : message || "Failed to load texture"}`));
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ promises.push(deferred.promise);
|
|
|
|
+
|
|
|
|
+ if (!textureURL) {
|
|
promises.push(this.loadImageAsync(`/images/${image.index}`, image).then((data) => {
|
|
promises.push(this.loadImageAsync(`/images/${image.index}`, image).then((data) => {
|
|
const name = image.uri || `${this._fileName}#image${image.index}`;
|
|
const name = image.uri || `${this._fileName}#image${image.index}`;
|
|
const dataUrl = `data:${this._uniqueRootUrl}${name}`;
|
|
const dataUrl = `data:${this._uniqueRootUrl}${name}`;
|
|
babylonTexture.updateURL(dataUrl, new Blob([data], { type: image.mimeType }));
|
|
babylonTexture.updateURL(dataUrl, new Blob([data], { type: image.mimeType }));
|
|
}));
|
|
}));
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
babylonTexture.wrapU = samplerData.wrapU;
|
|
babylonTexture.wrapU = samplerData.wrapU;
|