more nice names, spotlight targets

beta.r3js.org
-=yb4f310 2018-02-07 18:48:54 +01:00
parent c76c34dcd6
commit fbcc5a8086
11 changed files with 145 additions and 68 deletions

View File

@ -17,7 +17,7 @@ GameLib.Event.OnceSubscriptions = {};
*/
GameLib.Event.WINDOW_RESIZE = 0x1;
GameLib.Event.PARENT_SCENE_CHANGE = 0x2;
GameLib.Event.PARENT_ENTITY_CHANGE = 0x3;
//GameLib.Event.PARENT_ENTITY_CHANGE = 0x3;
GameLib.Event.INSTANCE_CLONED = 0x4;
GameLib.Event.LOAD_IMAGE = 0x5;
GameLib.Event.NEW_ENTITY = 0x6;
@ -62,7 +62,7 @@ GameLib.Event.EVENT_LIST = 0x2c;
GameLib.Event.COMPILE_SUCCESS = 0x2d;
GameLib.Event.COMPILE_FAILED = 0x2e;
GameLib.Event.IMAGE_CHANGED = 0x2f;
GameLib.Event.PARENT_ENTITY_CHANGED = 0x30;
//GameLib.Event.PARENT_ENTITY_CHANGED = 0x30;
GameLib.Event.MATERIAL_TEXTURES_UPDATED = 0x31;
GameLib.Event.DELETE_COMPONENT_ERROR = 0x32;
GameLib.Event.COMPONENT_DELETED = 0x33;
@ -144,7 +144,7 @@ GameLib.Event.GetEventName = function(number) {
switch(number) {
case 0x1 : return 'window_resize';
case 0x2 : return 'parent_scene_change';
case 0x3 : return 'parent_entity_change';
case 0x3 : return 'unused';
case 0x4 : return 'instance_cloned';
case 0x5 : return 'load_image';
case 0x6 : return 'new_entity';
@ -189,7 +189,7 @@ GameLib.Event.GetEventName = function(number) {
case 0x2d : return 'compile_success';
case 0x2e : return 'compile_failed';
case 0x2f : return 'image_changed';
case 0x30 : return 'parent_entity_changed';
case 0x30 : return 'unused';
case 0x31 : return 'material_textures_updated';
case 0x32 : return 'delete_component_error';
case 0x33 : return 'component_deleted';

View File

@ -202,6 +202,30 @@ GameLib.Component.prototype.getDependencies = function() {
return dependencies;
};
GameLib.Component.prototype.updateInstance = function(property) {
if (property === 'parentEntity') {
if (this.parentEntity && this.parentEntity.loaded) {
this.parentEntity.addComponent(this);
this.buildIdToObject();
Object.keys(this.idToObject).map(
function(componentId) {
if (this.id !== componentId) {
this.parentEntity.addComponent(this.idToObject[componentId]);
}
}.bind(this)
)
}
}
};
GameLib.Component.prototype.toString = function() {
return this.id;
};
@ -1361,9 +1385,28 @@ GameLib.Component.prototype.save = function(remote) {
}.bind(this)
);
Object.keys(this.idToObject).map(
function(componentId) {
var apiObject = this.idToObject[componentId].toApiObject();
var component = this.idToObject[componentId];
if (this instanceof GameLib.Entity) {
/**
* We don't store children objects of entities which are not explicitly defined as children of this entity.
*/
if (this.components.indexOf(component) === -1) {
/**
* We don't want to store this component - but other components may depend on it
*/
console.warn(component.name + ' is being stored because a component depends on it - even though it was not explicitly added to this entity.');
}
}
var apiObject = component.toApiObject();
toSave.push(apiObject);

View File

@ -58,16 +58,47 @@ GameLib.D3.API.Mesh = function(
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Mesh (' + id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(meshType)) {
meshType = GameLib.D3.API.Mesh.MESH_TYPE_NORMAL;
}
this.meshType = meshType;
if (GameLib.Utils.UndefinedOrNull(name)) {
switch (this.meshType) {
case GameLib.D3.API.Mesh.MESH_TYPE_BOX :
name = 'Mesh Box';
break;
case GameLib.D3.API.Mesh.MESH_TYPE_TEXT :
name = 'Mesh Text';
break;
case GameLib.D3.API.Mesh.MESH_TYPE_CURVE :
name = 'Mesh Curve';
break;
case GameLib.D3.API.Mesh.MESH_TYPE_LINE :
name = 'Mesh Line';
break;
case GameLib.D3.API.Mesh.MESH_TYPE_SPHERE :
name = 'Mesh Sphere';
break;
case GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER :
name = 'Mesh Cylinder';
break;
case GameLib.D3.API.Mesh.MESH_TYPE_PLANE :
name = 'Mesh Plane';
break;
case GameLib.D3.API.Mesh.MESH_TYPE_SKINNED :
name = 'Mesh Skinned';
break;
default :
console.warn('no nice name for mesh');
name = 'Mesh';
}
name += ' (' + id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(vertices)) {
vertices = [];
}
@ -105,9 +136,7 @@ GameLib.D3.API.Mesh = function(
if (GameLib.Utils.UndefinedOrNull(materials) || (materials instanceof Array && materials.length === 0)) {
materials = [
new GameLib.D3.API.Material.Basic({
name : 'Material ' + this.id
})
new GameLib.D3.API.Material.Basic()
];
}
this.materials = materials;

View File

@ -25,16 +25,32 @@ GameLib.D3.API.Shadow = function(
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Shadow (' + id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(shadowType)) {
shadowType = GameLib.D3.API.Shadow.SHADOW_TYPE_NORMAL;
}
this.shadowType = shadowType;
if (GameLib.Utils.UndefinedOrNull(name)) {
switch (this.shadowType) {
case GameLib.D3.API.Shadow.SHADOW_TYPE_NORMAL :
name = 'Shadow Normal';
break;
case GameLib.D3.API.Shadow.SHADOW_TYPE_DIRECTIONAL :
name = 'Shadow Directional';
break;
case GameLib.D3.API.Shadow.SHADOW_TYPE_SPOT :
name = 'Shadow Spot';
break;
default :
console.warn('no nice name for shadow');
name = 'Shadow';
}
name += ' (' + id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(camera)) {
camera = new GameLib.D3.API.Camera.Perspective(
{

View File

@ -109,9 +109,7 @@ GameLib.D3.Light.prototype.updateInstance = function(property) {
console.warn('todo: implement parentScene change for light')
}
if (property === 'parentEntity') {
console.warn('todo: implement parentEntity change for light')
}
GameLib.Component.prototype.updateInstance.call(this, property);
};

View File

@ -81,7 +81,12 @@ GameLib.D3.Light.Directional.prototype.createInstance = function() {
/**
* This component is created during runtime
*/
this.shadow = new GameLib.D3.Shadow.Directional(this.graphics);
this.shadow = new GameLib.D3.Shadow.Directional(
this.graphics,
{
parentEntity : this.parentEntity
}
);
this.shadow.instance = this.instance.shadow;
@ -103,6 +108,7 @@ GameLib.D3.Light.Directional.prototype.createInstance = function() {
* The directional light points to target - target has to update its matrix world so needs to be added to the scene
*/
if (this.target && this.target.instance) {
this.instance.target = this.target.instance;
if (this.parentScene && this.parentScene.instance) {

View File

@ -168,10 +168,15 @@ GameLib.D3.Light.Spot.prototype.updateInstance = function(property, oldTarget) {
if (oldTarget) {
if (this.parentScene) {
this.parentScene.removeObject(oldTarget);
this.parentScene.addObject(this.target);
}
}
if (this.target.instance) {
this.instance.target = this.target.instance;
}
this.parentScene.addObject(this.target);
return;
}

View File

@ -583,10 +583,12 @@ GameLib.D3.Mesh.prototype.updateInstance = function(property) {
this.instance.up.x = this.up.x;
this.instance.up.y = this.up.y;
this.instance.up.z = this.up.z;
return;
}
if (property === 'name') {
this.instance.name = this.name;
return;
}
if (property === 'materials') {
@ -605,22 +607,27 @@ GameLib.D3.Mesh.prototype.updateInstance = function(property) {
this.instance.material = materialInstances;
}
return;
}
if (property === 'renderOrder') {
this.instance.renderOrder = this.renderOrder;
return;
}
if (property === 'visible') {
this.instance.visible = this.visible;
return;
}
if (property === 'castShadow') {
this.instance.castShadow = this.castShadow;
return;
}
if (property === 'receiveShadow') {
this.instance.receiveShadow = this.receiveShadow;
return;
}
if (this.helper) {
@ -631,7 +638,7 @@ GameLib.D3.Mesh.prototype.updateInstance = function(property) {
/**
* 'parentScene' is handled by LinkingSystem
*/
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -115,6 +115,8 @@ GameLib.Entity.prototype.addComponent = function(component) {
GameLib.Utils.PushUnique(this.idRegister[component.componentType], component);
component.buildIdToObject();
Object.keys(component.idToObject).map(
function(componentId) {

View File

@ -335,6 +335,14 @@ GameLib.System.GUI.prototype.controller = function(folder, object, property, sub
step = 0.01;
}
if (
property === 'mapSize'
) {
min = 16;
max = 4096;
step = 16;
}
var handle = folder.add(
object[property],
subProperty,
@ -508,17 +516,6 @@ GameLib.System.GUI.prototype.buildParentSelectionControl = function(folder, comp
component[property] = newComponent;
component.updateInstance(property);
if (property === 'parentEntity') {
GameLib.Event.Emit(
GameLib.Event.PARENT_ENTITY_CHANGE,
{
originalEntity : this.initialValue,
newEntity : newComponent,
object : component
}
);
}
if (property === 'parentPhysicsWorld') {
GameLib.Event.Emit(
GameLib.Event.PARENT_WORLD_CHANGE,
@ -1597,11 +1594,16 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
property === 'sensitivity'
) {
controllers.push(folder.add(object, property, 1, 50, 1));
} else if (
} else if (
property === 'density' ||
property === 'bias'
property === 'bias' ||
property === 'threshold'
) {
controllers.push(folder.add(object, property, 0, 1, 0.0001));
} else if (
property === 'strength'
) {
controllers.push(folder.add(object, property, 0, 50, 0.001));
} else if (
property === 'thetaLength' ||
property === 'angle'

View File

@ -37,7 +37,6 @@ GameLib.System.Linking = function(
*/
this.parentSceneChangeSubscription = null;
this.parentPhysicsWorldChangeSubscription = null;
this.parentEntityChangeSubscription = null;
/**
* Instances
@ -115,11 +114,6 @@ GameLib.System.Linking.prototype.start = function() {
this.onParentWorldChange
);
this.parentEntityChangeSubscription = this.subscribe(
GameLib.Event.PARENT_ENTITY_CHANGE,
this.onParentEntityChange
);
/**
* Instances
*/
@ -836,30 +830,6 @@ GameLib.System.Linking.prototype.onParentSceneChange = function(data) {
};
/**
* Change parent entity
* @param data
*/
GameLib.System.Linking.prototype.onParentEntityChange = function(data) {
if (data.originalEntity instanceof GameLib.Entity) {
data.originalEntity.removeComponent(data.object);
}
if (data.newEntity instanceof GameLib.Entity) {
data.newEntity.addComponent(data.object);
}
GameLib.Event.Emit(
GameLib.Event.PARENT_ENTITY_CHANGED,
{
originalEntity : data.originalEntity,
newEntity : data.newEntity,
component : data.object
}
)
};
/**
* When a mesh is deleted - build a list of all the mesh children objects - also - find out if any of these
* children objects are in use by another object - if it is - don't delete it, otherwise, do
@ -948,7 +918,6 @@ GameLib.System.Linking.prototype.stop = function() {
*/
this.parentSceneChangeSubscription.remove();
this.parentPhysicsWorldChangeSubscription.remove();
this.parentEntityChangeSubscription.remove();
/**
* Instances