loading, checkRegister and texture creation order
parent
5398cebcbe
commit
22e0e8828d
|
@ -172,7 +172,7 @@ GameLib.D3.API.Texture.prototype.constructor = GameLib.D3.API.Texture;
|
||||||
GameLib.D3.API.Texture.FromObject = function(objectTexture) {
|
GameLib.D3.API.Texture.FromObject = function(objectTexture) {
|
||||||
return new GameLib.D3.API.Texture(
|
return new GameLib.D3.API.Texture(
|
||||||
objectTexture.id,
|
objectTexture.id,
|
||||||
objectTexture.textureType,
|
objectTexture.typeId,
|
||||||
objectTexture.name,
|
objectTexture.name,
|
||||||
objectTexture.image,
|
objectTexture.image,
|
||||||
objectTexture.wrapS,
|
objectTexture.wrapS,
|
||||||
|
|
|
@ -78,23 +78,18 @@ GameLib.D3.Image.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
console.log('loading normal image');
|
console.log('loading normal image');
|
||||||
|
|
||||||
loader = new THREE.XHRLoader();
|
loader = new THREE.ImageLoader();
|
||||||
|
|
||||||
loader.crossOrigin = true;
|
loader.crossOrigin = true;
|
||||||
|
|
||||||
loader.path = data.baseUrl;
|
loader.path = data.baseUrl;
|
||||||
|
|
||||||
loader.responseType = 'blob';
|
|
||||||
|
|
||||||
loader.load(
|
loader.load(
|
||||||
this.path + '?ts=' + Date.now(),
|
this.path + '?ts=' + Date.now(),
|
||||||
function (blob) {
|
function (image) {
|
||||||
|
|
||||||
var image = document.createElement('img');
|
|
||||||
image.onload = function ( e ) { URL.revokeObjectURL( image.src ); };
|
|
||||||
image.src = URL.createObjectURL( blob );
|
|
||||||
|
|
||||||
this.instance = image;
|
this.instance = image;
|
||||||
|
|
||||||
this.publish(
|
this.publish(
|
||||||
GameLib.Event.IMAGE_LOADED,
|
GameLib.Event.IMAGE_LOADED,
|
||||||
{
|
{
|
||||||
|
@ -102,6 +97,7 @@ GameLib.D3.Image.prototype.createInstance = function(update) {
|
||||||
imageInstance: this.instance
|
imageInstance: this.instance
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
}.bind(this),
|
}.bind(this),
|
||||||
function(xhr) {
|
function(xhr) {
|
||||||
console.log( (xhr.loaded / xhr.total * 100) + '% loaded of ' + this.name);
|
console.log( (xhr.loaded / xhr.total * 100) + '% loaded of ' + this.name);
|
||||||
|
|
|
@ -458,7 +458,11 @@ GameLib.D3.Mesh.prototype.createInstance = function(update) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.materials[0] === data.material) {
|
if (this.materials[0] === data.material) {
|
||||||
this.instance.material = data.material.instance;
|
|
||||||
|
if (this.instance.material !== data.material.instance) {
|
||||||
|
this.instance.material = data.material.instance;
|
||||||
|
}
|
||||||
|
|
||||||
this.instance.geometry.uvsNeedUpdate = true;
|
this.instance.geometry.uvsNeedUpdate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,7 @@ GameLib.D3.Scene = function (
|
||||||
function(apiTexture) {
|
function(apiTexture) {
|
||||||
|
|
||||||
if (apiTexture instanceof GameLib.D3.API.Texture) {
|
if (apiTexture instanceof GameLib.D3.API.Texture) {
|
||||||
|
|
||||||
var texture = new GameLib.D3.Texture(
|
var texture = new GameLib.D3.Texture(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
apiTexture
|
apiTexture
|
||||||
|
|
|
@ -210,35 +210,38 @@ GameLib.D3.Texture.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (this.image instanceof GameLib.D3.Image) {
|
// if (this.image instanceof GameLib.D3.Image) {
|
||||||
|
//
|
||||||
if (this.image.instance) {
|
// if (this.image.instance) {
|
||||||
|
//
|
||||||
var instance = new THREE.Texture(
|
// var instance = new THREE.Texture(
|
||||||
this.image.instance
|
// this.image.instance
|
||||||
);
|
// );
|
||||||
instance.name = this.name;
|
// instance.name = this.name;
|
||||||
instance.flipY = this.flipY;
|
// instance.flipY = this.flipY;
|
||||||
instance.encoding = this.encoding;
|
// instance.encoding = this.encoding;
|
||||||
instance.offset.x = this.offset.x;
|
// instance.offset.x = this.offset.x;
|
||||||
instance.offset.y = this.offset.y;
|
// instance.offset.y = this.offset.y;
|
||||||
instance.repeat.x = this.repeat.x;
|
// instance.repeat.x = this.repeat.x;
|
||||||
instance.repeat.y = this.repeat.y;
|
// instance.repeat.y = this.repeat.y;
|
||||||
instance.mapping = this.mapping;
|
// instance.mapping = this.mapping;
|
||||||
instance.format = this.format;
|
// instance.format = this.format;
|
||||||
instance.wrapS = this.wrapS;
|
// instance.wrapS = this.wrapS;
|
||||||
instance.wrapT = this.wrapT;
|
// instance.wrapT = this.wrapT;
|
||||||
|
//
|
||||||
this.publish(
|
// this.instance = instance;
|
||||||
GameLib.Event.TEXTURE_LOADED,
|
//
|
||||||
{
|
// this.publish(
|
||||||
texture : this
|
// GameLib.Event.TEXTURE_LOADED,
|
||||||
}
|
// {
|
||||||
);
|
// texture : this
|
||||||
|
// }
|
||||||
return instance;
|
// );
|
||||||
}
|
//
|
||||||
}
|
// this.instance.needsUpdate = true;
|
||||||
|
// return instance;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
this.subscribe(
|
this.subscribe(
|
||||||
GameLib.Event.IMAGE_LOADED,
|
GameLib.Event.IMAGE_LOADED,
|
||||||
|
@ -315,19 +318,8 @@ GameLib.D3.Texture.prototype.createInstance = function(update) {
|
||||||
instance = new THREE.Texture();
|
instance = new THREE.Texture();
|
||||||
} else {
|
} else {
|
||||||
instance = new THREE.Texture(this.image.instance);
|
instance = new THREE.Texture(this.image.instance);
|
||||||
// instance.needsUpdate = true;
|
|
||||||
// instance.name = this.name;
|
|
||||||
// instance.flipY = this.flipY;
|
|
||||||
// instance.encoding = this.encoding;
|
|
||||||
// instance.offset.x = this.offset.x;
|
|
||||||
// instance.offset.y = this.offset.y;
|
|
||||||
// instance.repeat.x = this.repeat.x;
|
|
||||||
// instance.repeat.y = this.repeat.y;
|
|
||||||
// this.format = instance.format;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.instance = instance;
|
|
||||||
|
|
||||||
this.publish(
|
this.publish(
|
||||||
GameLib.Event.TEXTURE_LOADED,
|
GameLib.Event.TEXTURE_LOADED,
|
||||||
{
|
{
|
||||||
|
@ -335,6 +327,8 @@ GameLib.D3.Texture.prototype.createInstance = function(update) {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
instance.needsUpdate = true;
|
||||||
|
this.instance = instance;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,18 @@ GameLib.EntityManager = function() {
|
||||||
|
|
||||||
this.entities = [];
|
this.entities = [];
|
||||||
|
|
||||||
|
this.loading = [];
|
||||||
|
|
||||||
|
this.dependencies = {};
|
||||||
|
|
||||||
|
this.subscriptions = [];
|
||||||
|
|
||||||
|
this.register = {};
|
||||||
|
|
||||||
|
this.checkRegister = [];
|
||||||
|
|
||||||
|
this.registerCallbacks();
|
||||||
|
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
this,
|
this,
|
||||||
GameLib.Component.COMPONENT_ENTITY_MANAGER,
|
GameLib.Component.COMPONENT_ENTITY_MANAGER,
|
||||||
|
@ -18,16 +30,6 @@ GameLib.EntityManager = function() {
|
||||||
},
|
},
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
this.loaded = [];
|
|
||||||
|
|
||||||
this.dependencies = {};
|
|
||||||
|
|
||||||
this.subscriptions = [];
|
|
||||||
|
|
||||||
this.register = {};
|
|
||||||
|
|
||||||
this.registerCallbacks();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.EntityManager.prototype = Object.create(GameLib.Component.prototype);
|
GameLib.EntityManager.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
@ -203,24 +205,31 @@ GameLib.EntityManager.prototype.query = function(components) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all actual components of all entities that contain this component
|
* Returns all actual components of all entities that contain this component
|
||||||
* @param constructor
|
* @param constructors (array of constructor or just a single constructor)
|
||||||
*/
|
*/
|
||||||
GameLib.EntityManager.prototype.queryComponents = function(constructor) {
|
GameLib.EntityManager.prototype.queryComponents = function(constructors) {
|
||||||
|
|
||||||
var entities = this.query([constructor]);
|
return this.checkRegister.reduce(
|
||||||
|
function(result, object) {
|
||||||
|
|
||||||
|
if (constructors instanceof Array) {
|
||||||
|
constructors.map(
|
||||||
|
function(constructor) {
|
||||||
|
if (object instanceof constructor) {
|
||||||
|
result.push(object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
if (object instanceof constructors) {
|
||||||
|
result.push(object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var components = entities.reduce(
|
|
||||||
function(result, entity){
|
|
||||||
var ecs = entity.getComponents(constructor);
|
|
||||||
ecs.map(function(ec){
|
|
||||||
result.push(ec);
|
|
||||||
});
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
return components;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -405,7 +414,12 @@ GameLib.EntityManager.prototype.link = function(component, data) {
|
||||||
|
|
||||||
GameLib.EntityManager.prototype.componentCreated = function(data) {
|
GameLib.EntityManager.prototype.componentCreated = function(data) {
|
||||||
|
|
||||||
console.log('component created : ' + data.component.name);
|
//console.log('component created : ' + data.component.name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register this component immediately
|
||||||
|
*/
|
||||||
|
this.checkRegister.push(data.component);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If we notify ourselves - ignore it
|
* If we notify ourselves - ignore it
|
||||||
|
@ -417,7 +431,7 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
|
||||||
/**
|
/**
|
||||||
* Store this component into our 'loaded' list
|
* Store this component into our 'loaded' list
|
||||||
*/
|
*/
|
||||||
this.loaded.push(data.component);
|
this.loading.push(data.component);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store the dependencies too
|
* Store the dependencies too
|
||||||
|
@ -533,8 +547,8 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
|
||||||
* Now check if all components are loaded, i.e., no more dependencies - if so - create their instance objects
|
* Now check if all components are loaded, i.e., no more dependencies - if so - create their instance objects
|
||||||
*/
|
*/
|
||||||
var loaded = true;
|
var loaded = true;
|
||||||
for (var i = 0; i < this.loaded.length; i++) {
|
for (var i = 0; i < this.loading.length; i++) {
|
||||||
if (!this.loaded[i].loaded) {
|
if (!this.loading[i].loaded) {
|
||||||
loaded = false;
|
loaded = false;
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -544,10 +558,10 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
|
||||||
* All components loaded
|
* All components loaded
|
||||||
*/
|
*/
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
this.loaded.map(function(component){
|
this.loading.map(function(component){
|
||||||
component.instance = component.createInstance();
|
component.instance = component.createInstance();
|
||||||
});
|
});
|
||||||
this.loaded = [];
|
this.loading = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -878,7 +878,7 @@ GameLib.GUI.prototype.buildSelectControl = function(folder, object, property, en
|
||||||
/**
|
/**
|
||||||
* Properties changed - rebuild the object list in the parent
|
* Properties changed - rebuild the object list in the parent
|
||||||
*/
|
*/
|
||||||
parentObject.buildIdToObject();
|
console.log('parentObject.buildIdToObject();');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Properties changed - rebuild GUI
|
* Properties changed - rebuild GUI
|
||||||
|
|
Loading…
Reference in New Issue