delayed image creation for storage system

beta.r3js.org
-=yb4f310 2017-10-27 10:19:00 +02:00
parent cfe46575a1
commit e361382580
1 changed files with 23 additions and 49 deletions

View File

@ -377,7 +377,7 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc
if (clientErrorCallback) {
clientErrorCallback({
message : error.messsage || 'JSON parse error'
message : error.message || 'JSON parse error'
})
}
@ -618,8 +618,7 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc
var progress = 0;
if (progressEvent.total !== 0) {
progress = Number(progressEvent.loaded / progressEvent.total);
progress *= 100;
progress = Math.round(Number(progressEvent.loaded / progressEvent.total) * 100);
}
if (onComponentProgress) {
@ -839,9 +838,7 @@ GameLib.System.Storage.prototype.processBlenderData = function(data) {
* Process all images - we have to load them in addition to creating their runtime components
*/
data.images.map(function(imageData){
var image = GameLib.D3.Image.FromObject(this.graphics, imageData);
var image = GameLib.D3.Image.FromObject(this.graphics, imageData);
GameLib.Event.Emit(
GameLib.Event.COMPONENT_CREATED,
{
@ -855,9 +852,7 @@ GameLib.System.Storage.prototype.processBlenderData = function(data) {
* Process all textures
*/
data.textures.map(function(textureData){
var texture = GameLib.D3.Texture.FromObject(this.graphics, textureData);
var texture = GameLib.D3.Texture.FromObject(this.graphics, textureData);
GameLib.Event.Emit(
GameLib.Event.COMPONENT_CREATED,
{
@ -885,9 +880,7 @@ GameLib.System.Storage.prototype.processBlenderData = function(data) {
* Now process all meshes
*/
data.meshes.map(function(meshData){
var mesh = GameLib.D3.Mesh.FromObject(this.graphics, meshData);
var mesh = GameLib.D3.Mesh.FromObject(this.graphics, meshData);
GameLib.Event.Emit(
GameLib.Event.COMPONENT_CREATED,
{
@ -992,52 +985,34 @@ GameLib.System.Storage.prototype.loadImage = function(data) {
xhr.onload = function() {
var objectUrl = false;
var url = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QoWEQMQBXD4hQAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAABRSURBVGje7c8xDQAwCAAwmA3koA/PU8FB0jpo1nRc9uI4AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBgX0fjEoBa8xN1z4AAAAASUVORK5CYII=';
try {
if (this.response.type !== 'application/json') {
var url = window.URL.createObjectURL(this.response);
} else {
if (onError) {
GameLib.Event.Emit(
GameLib.Event.IMAGE_NOT_FOUND,
{
image : image
}
);
onError(image, {message:'Image not found'});
return;
}
url = window.URL.createObjectURL(this.response);
objectUrl = true;
}
} catch (error) {
if (onError) {
GameLib.Event.Emit(
GameLib.Event.IMAGE_NOT_FOUND,
{
image : image
}
);
onError(image, {message:'Image not found'});
return;
}
/**
* Do Nothing
*/
}
var img = document.createElement('img');
img.onload = function() {
img.onload = function () {
window.URL.revokeObjectURL(url);
if (objectUrl) {
window.URL.revokeObjectURL(url);
}
image.instance = img;
image.publish(
GameLib.Event.IMAGE_INSTANCE_CREATED,
{
image: image
}
);
image.delayed = false;
image.createInstance();
if (onLoaded) {
onLoaded(image, data.createTexture);
@ -1052,8 +1027,7 @@ GameLib.System.Storage.prototype.loadImage = function(data) {
var progress = 0;
if (progressEvent.total !== 0) {
progress = Number(progressEvent.loaded / progressEvent.total);
progress *= 100;
progress = Math.round(Number(progressEvent.loaded / progressEvent.total) * 100);
}
if (onProgress) {