|
@@ -8915,25 +8915,48 @@ var BABYLON;
|
|
url = url.replace(/#/mg, "%23");
|
|
url = url.replace(/#/mg, "%23");
|
|
return url;
|
|
return url;
|
|
};
|
|
};
|
|
- Tools.LoadImage = function (url, onLoad, onError, database) {
|
|
|
|
- if (url instanceof ArrayBuffer) {
|
|
|
|
- url = Tools.EncodeArrayBufferTobase64(url);
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 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 database database for caching
|
|
|
|
+ * @returns the HTMLImageElement of the loaded image
|
|
|
|
+ */
|
|
|
|
+ Tools.LoadImage = function (input, onLoad, onError, database) {
|
|
|
|
+ var url;
|
|
|
|
+ var usingObjectURL = false;
|
|
|
|
+ if (input instanceof ArrayBuffer) {
|
|
|
|
+ url = URL.createObjectURL(new Blob([input]));
|
|
|
|
+ usingObjectURL = true;
|
|
|
|
+ }
|
|
|
|
+ else if (input instanceof Blob) {
|
|
|
|
+ url = URL.createObjectURL(input);
|
|
|
|
+ usingObjectURL = true;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ url = Tools.CleanUrl(input);
|
|
|
|
+ url = Tools.PreprocessUrl(input);
|
|
}
|
|
}
|
|
- url = Tools.CleanUrl(url);
|
|
|
|
- url = Tools.PreprocessUrl(url);
|
|
|
|
var img = new Image();
|
|
var img = new Image();
|
|
Tools.SetCorsBehavior(url, img);
|
|
Tools.SetCorsBehavior(url, img);
|
|
var loadHandler = function () {
|
|
var loadHandler = function () {
|
|
|
|
+ if (usingObjectURL && img.src) {
|
|
|
|
+ URL.revokeObjectURL(img.src);
|
|
|
|
+ }
|
|
img.removeEventListener("load", loadHandler);
|
|
img.removeEventListener("load", loadHandler);
|
|
img.removeEventListener("error", errorHandler);
|
|
img.removeEventListener("error", errorHandler);
|
|
onLoad(img);
|
|
onLoad(img);
|
|
};
|
|
};
|
|
var errorHandler = function (err) {
|
|
var errorHandler = function (err) {
|
|
|
|
+ if (usingObjectURL && img.src) {
|
|
|
|
+ URL.revokeObjectURL(img.src);
|
|
|
|
+ }
|
|
img.removeEventListener("load", loadHandler);
|
|
img.removeEventListener("load", loadHandler);
|
|
img.removeEventListener("error", errorHandler);
|
|
img.removeEventListener("error", errorHandler);
|
|
- Tools.Error("Error while trying to load image: " + url);
|
|
|
|
|
|
+ Tools.Error("Error while trying to load image: " + input);
|
|
if (onError) {
|
|
if (onError) {
|
|
- onError("Error while trying to load image: " + url, err);
|
|
|
|
|
|
+ onError("Error while trying to load image: " + input, err);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
img.addEventListener("load", loadHandler);
|
|
img.addEventListener("load", loadHandler);
|
|
@@ -8964,6 +8987,7 @@ var BABYLON;
|
|
blobURL = URL.createObjectURL(BABYLON.FilesInput.FilesToLoad[textureName]);
|
|
blobURL = URL.createObjectURL(BABYLON.FilesInput.FilesToLoad[textureName]);
|
|
}
|
|
}
|
|
img.src = blobURL;
|
|
img.src = blobURL;
|
|
|
|
+ usingObjectURL = true;
|
|
}
|
|
}
|
|
catch (e) {
|
|
catch (e) {
|
|
img.src = "";
|
|
img.src = "";
|
|
@@ -14544,7 +14568,7 @@ var BABYLON;
|
|
* @param samplingMode mode with should be used sample / access the texture (Default: BABYLON.Texture.TRILINEAR_SAMPLINGMODE)
|
|
* @param samplingMode mode with should be used sample / access the texture (Default: BABYLON.Texture.TRILINEAR_SAMPLINGMODE)
|
|
* @param onLoad optional callback to be called upon successful completion
|
|
* @param onLoad optional callback to be called upon successful completion
|
|
* @param onError optional callback to be called upon failure
|
|
* @param onError optional callback to be called upon failure
|
|
- * @param buffer a source of a file previously fetched as either an ArrayBuffer (compressed or image format) or HTMLImageElement (image format)
|
|
|
|
|
|
+ * @param buffer a source of a file previously fetched as either a base64 string, an ArrayBuffer (compressed or image format), HTMLImageElement (image format), or a Blob
|
|
* @param fallback an internal argument in case the function must be called again, due to etc1 not having alpha capabilities
|
|
* @param fallback an internal argument in case the function must be called again, due to etc1 not having alpha capabilities
|
|
* @param format internal format. Default: RGB when extension is '.jpg' else RGBA. Ignored for compressed textures
|
|
* @param format internal format. Default: RGB when extension is '.jpg' else RGBA. Ignored for compressed textures
|
|
* @returns a InternalTexture for assignment back into BABYLON.Texture
|
|
* @returns a InternalTexture for assignment back into BABYLON.Texture
|
|
@@ -14687,17 +14711,20 @@ var BABYLON;
|
|
return true;
|
|
return true;
|
|
}, samplingMode);
|
|
}, samplingMode);
|
|
};
|
|
};
|
|
- if (!fromData || isBase64)
|
|
|
|
|
|
+ if (!fromData || isBase64) {
|
|
if (buffer instanceof HTMLImageElement) {
|
|
if (buffer instanceof HTMLImageElement) {
|
|
onload(buffer);
|
|
onload(buffer);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
BABYLON.Tools.LoadImage(url, onload, onerror, scene ? scene.database : null);
|
|
BABYLON.Tools.LoadImage(url, onload, onerror, scene ? scene.database : null);
|
|
}
|
|
}
|
|
- else if (buffer instanceof Array || typeof buffer === "string" || buffer instanceof ArrayBuffer)
|
|
|
|
|
|
+ }
|
|
|
|
+ else if (typeof buffer === "string" || buffer instanceof ArrayBuffer || buffer instanceof Blob) {
|
|
BABYLON.Tools.LoadImage(buffer, onload, onerror, scene ? scene.database : null);
|
|
BABYLON.Tools.LoadImage(buffer, onload, onerror, scene ? scene.database : null);
|
|
- else
|
|
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
onload(buffer);
|
|
onload(buffer);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return texture;
|
|
return texture;
|
|
};
|
|
};
|
|
@@ -30718,8 +30745,18 @@ var BABYLON;
|
|
enumerable: true,
|
|
enumerable: true,
|
|
configurable: true
|
|
configurable: true
|
|
});
|
|
});
|
|
- Texture.prototype.updateURL = function (url) {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Update the url (and optional buffer) of this texture if url was null during construction.
|
|
|
|
+ * @param url the url of the texture
|
|
|
|
+ * @param buffer the buffer of the texture (defaults to null)
|
|
|
|
+ */
|
|
|
|
+ Texture.prototype.updateURL = function (url, buffer) {
|
|
|
|
+ if (buffer === void 0) { buffer = null; }
|
|
|
|
+ if (this.url) {
|
|
|
|
+ throw new Error("URL is already set");
|
|
|
|
+ }
|
|
this.url = url;
|
|
this.url = url;
|
|
|
|
+ this._buffer = buffer;
|
|
this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
|
|
this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
|
|
this.delayLoad();
|
|
this.delayLoad();
|
|
};
|
|
};
|
|
@@ -96130,6 +96167,7 @@ var BABYLON;
|
|
if (onLoad) {
|
|
if (onLoad) {
|
|
onLoad();
|
|
onLoad();
|
|
}
|
|
}
|
|
|
|
+ this._internalTexturesCache.push(texture);
|
|
return texture;
|
|
return texture;
|
|
};
|
|
};
|
|
NullEngine.prototype.createRenderTargetTexture = function (size, options) {
|
|
NullEngine.prototype.createRenderTargetTexture = function (size, options) {
|
|
@@ -96164,6 +96202,7 @@ var BABYLON;
|
|
texture.type = fullOptions.type;
|
|
texture.type = fullOptions.type;
|
|
texture._generateDepthBuffer = fullOptions.generateDepthBuffer;
|
|
texture._generateDepthBuffer = fullOptions.generateDepthBuffer;
|
|
texture._generateStencilBuffer = fullOptions.generateStencilBuffer ? true : false;
|
|
texture._generateStencilBuffer = fullOptions.generateStencilBuffer ? true : false;
|
|
|
|
+ this._internalTexturesCache.push(texture);
|
|
return texture;
|
|
return texture;
|
|
};
|
|
};
|
|
NullEngine.prototype.updateTextureSamplingMode = function (samplingMode, texture) {
|
|
NullEngine.prototype.updateTextureSamplingMode = function (samplingMode, texture) {
|