delayed image creation for storage system
parent
cfe46575a1
commit
e361382580
|
@ -377,7 +377,7 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc
|
||||||
|
|
||||||
if (clientErrorCallback) {
|
if (clientErrorCallback) {
|
||||||
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;
|
var progress = 0;
|
||||||
|
|
||||||
if (progressEvent.total !== 0) {
|
if (progressEvent.total !== 0) {
|
||||||
progress = Number(progressEvent.loaded / progressEvent.total);
|
progress = Math.round(Number(progressEvent.loaded / progressEvent.total) * 100);
|
||||||
progress *= 100;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onComponentProgress) {
|
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
|
* Process all images - we have to load them in addition to creating their runtime components
|
||||||
*/
|
*/
|
||||||
data.images.map(function(imageData){
|
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.Emit(
|
||||||
GameLib.Event.COMPONENT_CREATED,
|
GameLib.Event.COMPONENT_CREATED,
|
||||||
{
|
{
|
||||||
|
@ -855,9 +852,7 @@ GameLib.System.Storage.prototype.processBlenderData = function(data) {
|
||||||
* Process all textures
|
* Process all textures
|
||||||
*/
|
*/
|
||||||
data.textures.map(function(textureData){
|
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.Emit(
|
||||||
GameLib.Event.COMPONENT_CREATED,
|
GameLib.Event.COMPONENT_CREATED,
|
||||||
{
|
{
|
||||||
|
@ -885,9 +880,7 @@ GameLib.System.Storage.prototype.processBlenderData = function(data) {
|
||||||
* Now process all meshes
|
* Now process all meshes
|
||||||
*/
|
*/
|
||||||
data.meshes.map(function(meshData){
|
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.Emit(
|
||||||
GameLib.Event.COMPONENT_CREATED,
|
GameLib.Event.COMPONENT_CREATED,
|
||||||
{
|
{
|
||||||
|
@ -992,52 +985,34 @@ GameLib.System.Storage.prototype.loadImage = function(data) {
|
||||||
|
|
||||||
xhr.onload = function() {
|
xhr.onload = function() {
|
||||||
|
|
||||||
|
var objectUrl = false;
|
||||||
|
|
||||||
|
var url = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QoWEQMQBXD4hQAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAABRSURBVGje7c8xDQAwCAAwmA3koA/PU8FB0jpo1nRc9uI4AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBgX0fjEoBa8xN1z4AAAAASUVORK5CYII=';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (this.response.type !== 'application/json') {
|
if (this.response.type !== 'application/json') {
|
||||||
var url = window.URL.createObjectURL(this.response);
|
url = window.URL.createObjectURL(this.response);
|
||||||
} else {
|
objectUrl = true;
|
||||||
if (onError) {
|
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.IMAGE_NOT_FOUND,
|
|
||||||
{
|
|
||||||
image : image
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
onError(image, {message:'Image not found'});
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (onError) {
|
/**
|
||||||
|
* Do Nothing
|
||||||
GameLib.Event.Emit(
|
*/
|
||||||
GameLib.Event.IMAGE_NOT_FOUND,
|
|
||||||
{
|
|
||||||
image : image
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
onError(image, {message:'Image not found'});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var img = document.createElement('img');
|
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.instance = img;
|
||||||
|
|
||||||
image.publish(
|
image.delayed = false;
|
||||||
GameLib.Event.IMAGE_INSTANCE_CREATED,
|
|
||||||
{
|
image.createInstance();
|
||||||
image: image
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (onLoaded) {
|
if (onLoaded) {
|
||||||
onLoaded(image, data.createTexture);
|
onLoaded(image, data.createTexture);
|
||||||
|
@ -1052,8 +1027,7 @@ GameLib.System.Storage.prototype.loadImage = function(data) {
|
||||||
var progress = 0;
|
var progress = 0;
|
||||||
|
|
||||||
if (progressEvent.total !== 0) {
|
if (progressEvent.total !== 0) {
|
||||||
progress = Number(progressEvent.loaded / progressEvent.total);
|
progress = Math.round(Number(progressEvent.loaded / progressEvent.total) * 100);
|
||||||
progress *= 100;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onProgress) {
|
if (onProgress) {
|
||||||
|
|
Loading…
Reference in New Issue