before image path trouble

beta.r3js.org
Theunis J. Botha 2017-06-20 16:46:59 +02:00
parent c913ea0822
commit 58796b1e11
7 changed files with 162 additions and 17 deletions

View File

@ -33,7 +33,8 @@ GameLib.Event.LOAD_COMPONENT_ERROR = 0x11;
GameLib.Event.COMPONENT_LOADED = 0x12;
GameLib.Event.LOGGED_IN = 0x13;
GameLib.Event.COMPONENT_CREATED = 0x14;
GameLib.Event.SCENE_INSTANCE_CREATED = 0x15;
GameLib.Event.SCENE_OBJECT_INSTANCE_CREATED = 0x16;
/**
* Subscribe to some events
* @param eventName

View File

@ -370,6 +370,7 @@ GameLib.Component.prototype.save = function() {
this.idToObject.hasOwnProperty(property) &&
this.idToObject[property] instanceof GameLib.Component
) {
var apiObject = this.idToObject[property].toApiObject();
apiObject.componentType = this.idToObject[property].componentType;

View File

@ -103,8 +103,8 @@ GameLib.D3.Image.prototype.createInstance = function(update) {
console.log( (xhr.loaded / xhr.total * 100) + '% loaded of ' + this.name);
this.size = xhr.total;
}.bind(this),
function() {
console.log('An image load error happened');
function(error) {
console.log('An image load error happened: ' + error);
}
);

View File

@ -161,10 +161,16 @@ GameLib.D3.Raycaster.prototype.setPosition = function(
*/
GameLib.D3.Raycaster.prototype.getIntersectedObjects = function(meshes) {
var meshInstances = meshes.map(
function (mesh) {
return mesh.instance;
}
var meshInstances = meshes.reduce(
function (result, mesh) {
if (mesh.instance) {
result.push(mesh.instance);
}
return result;
},
[]
);
var intersects = this.instance.intersectObjects(meshInstances);

View File

@ -173,6 +173,9 @@ GameLib.D3.Scene = function (
//
// this.linkObjects(this.idToObject);
this.sceneInstanceSubscriptions = [];
this.objectInstanceSubscriptions = [];
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_SCENE,
@ -344,16 +347,89 @@ GameLib.D3.Scene.prototype.addObject = function(object) {
object.parentScene = this;
if (this.instance) {
this.instance.add(object.instance);
} else {
console.warn('no scene instance');
if (!this.instance) {
console.warn('No Scene Instance');
var index = this.sceneInstanceSubscriptions.length;
this.sceneInstanceSubscriptions.push(
this.subscribe(
GameLib.Event.SCENE_INSTANCE_CREATED,
function(__index, __object, __scene) {
return function(data) {
if (data.scene.id === __scene.id) {
if (!data.scene.instance) {
console.warn('Invalid Scene ' + data.scene);
throw new Error('Invalid Scene' + data.scene);
}
if (__object.instance) {
data.scene.instance.add(__object.instance);
} else {
/**
* We should alread have a subscription for a non-loaded object instance below,
* it will fire soon
*/
}
/**
* Now remove the subscription to this event
*/
__scene.sceneInstanceSubscriptions[__index].remove();
}
}
}(index, object, this)
)
);
}
if (!object.instance) {
// this.instance.add(object.instance);
//
// this.buildIdToObject();
console.warn('No Object Instance');
var o = this.objectInstanceSubscriptions.length;
this.objectInstanceSubscriptions.push(
this.subscribe(
GameLib.Event.SCENE_OBJECT_INSTANCE_CREATED,
function(__index, __scene) {
return function (data) {
if (!data.object.instance) {
console.warn('Invalid Object or wrong Event Emitted');
throw new Error('Invalid Object or wrong Event Emitted');
}
if (!__scene.instance) {
/**
* This is ok, we will have the opportunity to add a new object once the scene is created
*/
} else {
/**
* Add the object to the scene
*/
__scene.instance.add(data.object.instance);
}
/**
* Remove the listener for this event
*/
__scene.objectInstanceSubscriptions[__index].remove();
}
}(o, this)
)
);
}
if (
this.instance &&
object.instance
) {
this.instance.add(object.instance);
}
};
/**

View File

@ -534,6 +534,7 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
*/
if (data.component.dependencies.length === 0) {
data.component.loaded = true;
delete data.component.dependencies;
}
/**
@ -551,9 +552,45 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
* All components loaded
*/
if (loaded) {
this.loading.map(function(component){
component.instance = component.createInstance();
});
this.loading.map(function(component) {
component.instance = component.createInstance();
if (
component instanceof GameLib.D3.Mesh ||
component instanceof GameLib.D3.Light
) {
GameLib.Event.Emit(
GameLib.Event.SCENE_OBJECT_INSTANCE_CREATED,
{
object: component
}
)
}
if (
component instanceof GameLib.D3.Scene
) {
GameLib.Event.Emit(
GameLib.Event.SCENE_INSTANCE_CREATED,
{
scene: component
}
);
}
if (
component instanceof GameLib.D3.Material
) {
GameLib.Event.Emit(
GameLib.Event.MATERIAL_LOADED,
{
material: component
}
);
}
});
this.loading = [];
}

View File

@ -284,6 +284,30 @@ GameLib.GUI.prototype.buildControl = function(folder, object, property, entityMa
}
).name(property).listen()
);
} else if (object instanceof GameLib.D3.Image && property === 'imageType') {
handles.push(
folder.add(
object,
property,
{
'sphere' : GameLib.D3.Image.IMAGE_TYPE_SPHERE,
'cube' : GameLib.D3.Image.IMAGE_TYPE_CUBE,
'normal' : GameLib.D3.Image.IMAGE_TYPE_NORMAL
}
).name(property).listen()
);
} else if (object instanceof GameLib.D3.Mesh && property === 'meshType') {
handles.push(
folder.add(
object,
property,
{
'normal' : GameLib.D3.Mesh.TYPE_NORMAL,
'curve' : GameLib.D3.Mesh.TYPE_CURVE,
'skinned' : GameLib.D3.Mesh.TYPE_SKINNED
}
).name(property).listen()
);
} else if (object instanceof GameLib.D3.Material && property === 'materialType') {
handles.push(
folder.add(