Lights updated
parent
e22904841a
commit
cb8abfb5ec
|
@ -212,7 +212,7 @@ GameLib.Component.CAMERA = 0x5;
|
||||||
GameLib.Component.SOCKET = 0x6;
|
GameLib.Component.SOCKET = 0x6;
|
||||||
GameLib.Component.MESH = 0x7;
|
GameLib.Component.MESH = 0x7;
|
||||||
GameLib.Component.SPLINE = 0x8;
|
GameLib.Component.SPLINE = 0x8;
|
||||||
GameLib.Component.LIGHT = 0x9;
|
//GameLib.Component.LIGHT = 0x9;
|
||||||
GameLib.Component.PLANE = 0xa;
|
GameLib.Component.PLANE = 0xa;
|
||||||
GameLib.Component.COMPOSER = 0xb;
|
GameLib.Component.COMPOSER = 0xb;
|
||||||
GameLib.Component.RENDER_TARGET = 0xc;
|
GameLib.Component.RENDER_TARGET = 0xc;
|
||||||
|
@ -277,6 +277,12 @@ GameLib.Component.SYSTEM_PHYSICS = 0x46;
|
||||||
GameLib.Component.SYSTEM_RENDER = 0x47;
|
GameLib.Component.SYSTEM_RENDER = 0x47;
|
||||||
GameLib.Component.SYSTEM_STORAGE = 0x48;
|
GameLib.Component.SYSTEM_STORAGE = 0x48;
|
||||||
GameLib.Component.SYSTEM_VISUALIZATION = 0x49;
|
GameLib.Component.SYSTEM_VISUALIZATION = 0x49;
|
||||||
|
GameLib.Component.LIGHT_AMBIENT = 0x4a;
|
||||||
|
GameLib.Component.LIGHT_DIRECTIONAL = 0x4b;
|
||||||
|
GameLib.Component.LIGHT_HEMISPHERE = 0x4c;
|
||||||
|
GameLib.Component.LIGHT_POINT = 0x4d;
|
||||||
|
GameLib.Component.LIGHT_RECT_AREA = 0x4e;
|
||||||
|
GameLib.Component.LIGHT_SPOT = 0x4f;
|
||||||
GameLib.Component.FOG = 0x50;
|
GameLib.Component.FOG = 0x50;
|
||||||
GameLib.Component.MESH_LINE = 0x51;
|
GameLib.Component.MESH_LINE = 0x51;
|
||||||
GameLib.Component.PARTICLE_ENGINE = 0x52;
|
GameLib.Component.PARTICLE_ENGINE = 0x52;
|
||||||
|
@ -739,6 +745,42 @@ GameLib.Component.GetComponentInfo = function(number) {
|
||||||
constructor : GameLib.System.Visualization,
|
constructor : GameLib.System.Visualization,
|
||||||
apiConstructor : GameLib.API.System
|
apiConstructor : GameLib.API.System
|
||||||
};
|
};
|
||||||
|
case 0x4a : return {
|
||||||
|
name : 'GameLib.D3.Light.Ambient',
|
||||||
|
runtime : GameLib.Component.GRAPHICS_RUNTIME,
|
||||||
|
constructor : GameLib.D3.Light.Ambient,
|
||||||
|
apiConstructor : GameLib.D3.API.Light.Ambient
|
||||||
|
};
|
||||||
|
case 0x4b : return {
|
||||||
|
name : 'GameLib.D3.Light.Directional',
|
||||||
|
runtime : GameLib.Component.GRAPHICS_RUNTIME,
|
||||||
|
constructor : GameLib.D3.Light.Directional,
|
||||||
|
apiConstructor : GameLib.D3.API.Light.Directional
|
||||||
|
};
|
||||||
|
case 0x4c : return {
|
||||||
|
name : 'GameLib.D3.Light.Hemisphere',
|
||||||
|
runtime : GameLib.Component.GRAPHICS_RUNTIME,
|
||||||
|
constructor : GameLib.D3.Light.Hemisphere,
|
||||||
|
apiConstructor : GameLib.D3.API.Light.Hemisphere
|
||||||
|
};
|
||||||
|
case 0x4d : return {
|
||||||
|
name : 'GameLib.D3.Light.Point',
|
||||||
|
runtime : GameLib.Component.GRAPHICS_RUNTIME,
|
||||||
|
constructor : GameLib.D3.Light.Point,
|
||||||
|
apiConstructor : GameLib.D3.API.Light.Point
|
||||||
|
};
|
||||||
|
case 0x4e : return {
|
||||||
|
name : 'GameLib.D3.Light.RectArea',
|
||||||
|
runtime : GameLib.Component.GRAPHICS_RUNTIME,
|
||||||
|
constructor : GameLib.D3.Light.RectArea,
|
||||||
|
apiConstructor : GameLib.D3.API.Light.RectArea
|
||||||
|
};
|
||||||
|
case 0x4f : return {
|
||||||
|
name : 'GameLib.D3.Light.Spot',
|
||||||
|
runtime : GameLib.Component.GRAPHICS_RUNTIME,
|
||||||
|
constructor : GameLib.D3.Light.Spot,
|
||||||
|
apiConstructor : GameLib.D3.API.Light.Spot
|
||||||
|
};
|
||||||
case 0x50 : return {
|
case 0x50 : return {
|
||||||
name : 'GameLib.D3.Fog',
|
name : 'GameLib.D3.Fog',
|
||||||
runtime : GameLib.Component.GRAPHICS_RUNTIME,
|
runtime : GameLib.Component.GRAPHICS_RUNTIME,
|
||||||
|
|
|
@ -16,15 +16,6 @@ GameLib.API.Controls.D3.Editor = function(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLib.API.Controls.call(
|
|
||||||
this,
|
|
||||||
apiControls.id,
|
|
||||||
apiControls.name,
|
|
||||||
apiControls.controlsType,
|
|
||||||
apiControls.canvas,
|
|
||||||
apiControls.parentEntity
|
|
||||||
);
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(raycaster)) {
|
if (GameLib.Utils.UndefinedOrNull(raycaster)) {
|
||||||
raycaster = new GameLib.D3.API.Raycaster();
|
raycaster = new GameLib.D3.API.Raycaster();
|
||||||
}
|
}
|
||||||
|
@ -35,9 +26,13 @@ GameLib.API.Controls.D3.Editor = function(
|
||||||
}
|
}
|
||||||
this.camera = camera;
|
this.camera = camera;
|
||||||
|
|
||||||
GameLib.API.Component.call(
|
GameLib.API.Controls.call(
|
||||||
this,
|
this,
|
||||||
GameLib.Component.CONTROLS_EDITOR
|
apiControls.id,
|
||||||
|
apiControls.name,
|
||||||
|
apiControls.controlsType,
|
||||||
|
apiControls.canvas,
|
||||||
|
apiControls.parentEntity
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,6 @@ GameLib.API.Controls.Keyboard = function(
|
||||||
apiControls.canvas,
|
apiControls.canvas,
|
||||||
apiControls.parentEntity
|
apiControls.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
GameLib.API.Component.call(
|
|
||||||
this,
|
|
||||||
GameLib.Component.CONTROLS_KEYBOARD
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.API.Controls.Keyboard.prototype = Object.create(GameLib.API.Controls.prototype);
|
GameLib.API.Controls.Keyboard.prototype = Object.create(GameLib.API.Controls.prototype);
|
||||||
|
|
|
@ -20,11 +20,6 @@ GameLib.API.Controls.Mouse = function(
|
||||||
apiControls.canvas,
|
apiControls.canvas,
|
||||||
apiControls.parentEntity
|
apiControls.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
GameLib.API.Component.call(
|
|
||||||
this,
|
|
||||||
GameLib.Component.CONTROLS_MOUSE
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.API.Controls.Mouse.prototype = Object.create(GameLib.API.Controls.prototype);
|
GameLib.API.Controls.Mouse.prototype = Object.create(GameLib.API.Controls.prototype);
|
||||||
|
|
|
@ -14,6 +14,11 @@ GameLib.API.Controls.Touch = function(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(sensitivity)) {
|
||||||
|
sensitivity = 5;
|
||||||
|
}
|
||||||
|
this.sensitivity = sensitivity;
|
||||||
|
|
||||||
GameLib.API.Controls.call(
|
GameLib.API.Controls.call(
|
||||||
this,
|
this,
|
||||||
apiControls.id,
|
apiControls.id,
|
||||||
|
@ -22,16 +27,6 @@ GameLib.API.Controls.Touch = function(
|
||||||
apiControls.canvas,
|
apiControls.canvas,
|
||||||
apiControls.parentEntity
|
apiControls.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(sensitivity)) {
|
|
||||||
sensitivity = 5;
|
|
||||||
}
|
|
||||||
this.sensitivity = sensitivity;
|
|
||||||
|
|
||||||
GameLib.API.Component.call(
|
|
||||||
this,
|
|
||||||
GameLib.Component.CONTROLS_TOUCH
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.API.Controls.Touch.prototype = Object.create(GameLib.API.Controls.prototype);
|
GameLib.API.Controls.Touch.prototype = Object.create(GameLib.API.Controls.prototype);
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
/**
|
||||||
|
* Raw Light API object - should always correspond with the Light Schema
|
||||||
|
* @param id
|
||||||
|
* @param lightType
|
||||||
|
* @param name
|
||||||
|
* @param color
|
||||||
|
* @param intensity
|
||||||
|
* @param parentScene
|
||||||
|
* @param parentEntity
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Light = function(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
lightType,
|
||||||
|
color,
|
||||||
|
intensity,
|
||||||
|
parentScene,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = 'Light (' + id + ')';
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(lightType)) {
|
||||||
|
lightType = GameLib.D3.API.Light.LIGHT_TYPE_AMBIENT;
|
||||||
|
}
|
||||||
|
this.lightType = lightType;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(color)) {
|
||||||
|
color = new GameLib.API.Color(1,1,1);
|
||||||
|
}
|
||||||
|
this.color = color;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(intensity)) {
|
||||||
|
intensity = 1;
|
||||||
|
}
|
||||||
|
this.intensity = intensity;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(parentScene)) {
|
||||||
|
parentScene = null;
|
||||||
|
}
|
||||||
|
this.parentScene = parentScene;
|
||||||
|
|
||||||
|
var componentType = null;
|
||||||
|
|
||||||
|
switch (this.lightType) {
|
||||||
|
case GameLib.D3.API.Light.LIGHT_TYPE_AMBIENT :
|
||||||
|
componentType = GameLib.Component.LIGHT_AMBIENT;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.Light.LIGHT_TYPE_DIRECTIONAL :
|
||||||
|
componentType = GameLib.Component.LIGHT_DIRECTIONAL;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.Light.LIGHT_TYPE_POINT :
|
||||||
|
componentType = GameLib.Component.LIGHT_POINT;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.Light.LIGHT_TYPE_SPOT :
|
||||||
|
componentType = GameLib.Component.LIGHT_SPOT;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.Light.LIGHT_TYPE_HEMISPHERE :
|
||||||
|
componentType = GameLib.Component.LIGHT_HEMISPHERE;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.Light.LIGHT_TYPE_RECT_AREA :
|
||||||
|
componentType = GameLib.Component.LIGHT_RECT_AREA;
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
console.error('could not determine light component type');
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.API.Component.call(
|
||||||
|
this,
|
||||||
|
componentType,
|
||||||
|
parentEntity
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Light.prototype = Object.create(GameLib.API.Component.prototype);
|
||||||
|
GameLib.D3.API.Light.prototype.constructor = GameLib.D3.API.Light;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Light Types
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Light.LIGHT_TYPE_AMBIENT = 0x1;
|
||||||
|
GameLib.D3.API.Light.LIGHT_TYPE_DIRECTIONAL = 0x2;
|
||||||
|
GameLib.D3.API.Light.LIGHT_TYPE_POINT = 0x3;
|
||||||
|
GameLib.D3.API.Light.LIGHT_TYPE_SPOT = 0x4;
|
||||||
|
GameLib.D3.API.Light.LIGHT_TYPE_HEMISPHERE = 0x5;
|
||||||
|
GameLib.D3.API.Light.LIGHT_TYPE_RECT_AREA = 0x6;
|
|
@ -0,0 +1,29 @@
|
||||||
|
/**
|
||||||
|
* Raw Light API object - should always correspond with the Light Schema
|
||||||
|
* @constructor
|
||||||
|
* @param apiLight
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Light.Ambient = function(
|
||||||
|
apiLight
|
||||||
|
) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiLight)) {
|
||||||
|
apiLight = {
|
||||||
|
lightType : GameLib.D3.API.Light.LIGHT_TYPE_AMBIENT
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.API.Light.call(
|
||||||
|
this,
|
||||||
|
apiLight.id,
|
||||||
|
apiLight.name,
|
||||||
|
apiLight.lightType,
|
||||||
|
apiLight.color,
|
||||||
|
apiLight.intensity,
|
||||||
|
apiLight.parentScene,
|
||||||
|
apiLight.parentEntity
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Light.Ambient.prototype = Object.create(GameLib.D3.API.Light.prototype);
|
||||||
|
GameLib.D3.API.Light.Ambient.prototype.constructor = GameLib.D3.API.Light.Ambient;
|
|
@ -0,0 +1,60 @@
|
||||||
|
/**
|
||||||
|
* Raw Light API object - should always correspond with the Light Schema
|
||||||
|
* @constructor
|
||||||
|
* @param apiLight
|
||||||
|
* @param castShadow
|
||||||
|
* @param position
|
||||||
|
* @param shadow
|
||||||
|
* @param target
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Light.Directional = function(
|
||||||
|
apiLight,
|
||||||
|
castShadow,
|
||||||
|
position,
|
||||||
|
shadow,
|
||||||
|
target
|
||||||
|
) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiLight)) {
|
||||||
|
apiLight = {
|
||||||
|
lightType : GameLib.D3.API.Light.LIGHT_TYPE_DIRECTIONAL
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(castShadow)) {
|
||||||
|
castShadow = false;
|
||||||
|
}
|
||||||
|
this.castShadow = castShadow;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Light shines from the top
|
||||||
|
*/
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(position)) {
|
||||||
|
position = new GameLib.API.Vector3(0,1,0);
|
||||||
|
}
|
||||||
|
this.position = position;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(shadow)) {
|
||||||
|
shadow = null;
|
||||||
|
}
|
||||||
|
this.shadow = shadow;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(target)) {
|
||||||
|
target = null;
|
||||||
|
}
|
||||||
|
this.target = target;
|
||||||
|
|
||||||
|
GameLib.D3.API.Light.call(
|
||||||
|
this,
|
||||||
|
apiLight.id,
|
||||||
|
apiLight.name,
|
||||||
|
apiLight.lightType,
|
||||||
|
apiLight.color,
|
||||||
|
apiLight.intensity,
|
||||||
|
apiLight.parentScene,
|
||||||
|
apiLight.parentEntity
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Light.Directional.prototype = Object.create(GameLib.D3.API.Light.prototype);
|
||||||
|
GameLib.D3.API.Light.Directional.prototype.constructor = GameLib.D3.API.Light.Directional;
|
|
@ -0,0 +1,53 @@
|
||||||
|
/**
|
||||||
|
* Raw Light API object - should always correspond with the Light Schema
|
||||||
|
* @constructor
|
||||||
|
* @param apiLight
|
||||||
|
* @param castShadow
|
||||||
|
* @param position
|
||||||
|
* @param groundColor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Light.Hemisphere = function(
|
||||||
|
apiLight,
|
||||||
|
castShadow,
|
||||||
|
position,
|
||||||
|
groundColor
|
||||||
|
) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiLight)) {
|
||||||
|
apiLight = {
|
||||||
|
lightType : GameLib.D3.API.Light.LIGHT_TYPE_HEMISPHERE
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(castShadow)) {
|
||||||
|
castShadow = false;
|
||||||
|
}
|
||||||
|
this.castShadow = castShadow;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Light shines from the top
|
||||||
|
*/
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(position)) {
|
||||||
|
position = new GameLib.API.Vector3(0,1,0);
|
||||||
|
}
|
||||||
|
this.position = position;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(groundColor)) {
|
||||||
|
groundColor = new GameLib.API.Color(1,1,1);
|
||||||
|
}
|
||||||
|
this.groundColor = groundColor;
|
||||||
|
|
||||||
|
GameLib.D3.API.Light.call(
|
||||||
|
this,
|
||||||
|
apiLight.id,
|
||||||
|
apiLight.name,
|
||||||
|
apiLight.lightType,
|
||||||
|
apiLight.color,
|
||||||
|
apiLight.intensity,
|
||||||
|
apiLight.parentScene,
|
||||||
|
apiLight.parentEntity
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Light.Hemisphere.prototype = Object.create(GameLib.D3.API.Light.prototype);
|
||||||
|
GameLib.D3.API.Light.Hemisphere.prototype.constructor = GameLib.D3.API.Light.Hemisphere;
|
|
@ -0,0 +1,73 @@
|
||||||
|
/**
|
||||||
|
* Raw Light API object - should always correspond with the Light Schema
|
||||||
|
* @constructor
|
||||||
|
* @param apiLight
|
||||||
|
* @param position
|
||||||
|
* @param decay
|
||||||
|
* @param distance
|
||||||
|
* @param power
|
||||||
|
* @param shadow
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Light.Point = function(
|
||||||
|
apiLight,
|
||||||
|
position,
|
||||||
|
decay,
|
||||||
|
distance,
|
||||||
|
power,
|
||||||
|
shadow
|
||||||
|
) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiLight)) {
|
||||||
|
apiLight = {
|
||||||
|
lightType : GameLib.D3.API.Light.LIGHT_TYPE_POINT
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Light shines from the top
|
||||||
|
*/
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(position)) {
|
||||||
|
position = new GameLib.API.Vector3(0,0,0);
|
||||||
|
}
|
||||||
|
this.position = position;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In physically correct mode, decay is 2
|
||||||
|
*/
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(decay)) {
|
||||||
|
decay = 1;
|
||||||
|
}
|
||||||
|
this.decay = decay;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In physically correct mode, decay is 2
|
||||||
|
*/
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(distance)) {
|
||||||
|
distance = 0;
|
||||||
|
}
|
||||||
|
this.distance = distance;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(power)) {
|
||||||
|
power = 4 * Math.PI;
|
||||||
|
}
|
||||||
|
this.power = power;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(shadow)) {
|
||||||
|
shadow = null;
|
||||||
|
}
|
||||||
|
this.shadow = shadow;
|
||||||
|
|
||||||
|
GameLib.D3.API.Light.call(
|
||||||
|
this,
|
||||||
|
apiLight.id,
|
||||||
|
apiLight.name,
|
||||||
|
apiLight.lightType,
|
||||||
|
apiLight.color,
|
||||||
|
apiLight.intensity,
|
||||||
|
apiLight.parentScene,
|
||||||
|
apiLight.parentEntity
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Light.Point.prototype = Object.create(GameLib.D3.API.Light.prototype);
|
||||||
|
GameLib.D3.API.Light.Point.prototype.constructor = GameLib.D3.API.Light.Point;
|
|
@ -0,0 +1,87 @@
|
||||||
|
/**
|
||||||
|
* Raw Light API object - should always correspond with the Light Schema
|
||||||
|
* @constructor
|
||||||
|
* @param apiLight
|
||||||
|
* @param position
|
||||||
|
* @param castShadow
|
||||||
|
* @param decay
|
||||||
|
* @param distance
|
||||||
|
* @param width
|
||||||
|
* @param height
|
||||||
|
* @param target
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Light.RectArea = function(
|
||||||
|
apiLight,
|
||||||
|
position,
|
||||||
|
castShadow,
|
||||||
|
decay,
|
||||||
|
distance,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
target
|
||||||
|
) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiLight)) {
|
||||||
|
apiLight = {
|
||||||
|
lightType : GameLib.D3.API.Light.LIGHT_TYPE_RECT_AREA
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Light shines from the top
|
||||||
|
*/
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(position)) {
|
||||||
|
position = new GameLib.API.Vector3(0,1,0);
|
||||||
|
}
|
||||||
|
this.position = position;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(castShadow)) {
|
||||||
|
castShadow = false;
|
||||||
|
}
|
||||||
|
this.castShadow = castShadow;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In physically correct mode, decay is 2
|
||||||
|
*/
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(decay)) {
|
||||||
|
decay = 1;
|
||||||
|
}
|
||||||
|
this.decay = decay;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In physically correct mode, decay is 2
|
||||||
|
*/
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(distance)) {
|
||||||
|
distance = 0;
|
||||||
|
}
|
||||||
|
this.distance = distance;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(width)) {
|
||||||
|
width = 10;
|
||||||
|
}
|
||||||
|
this.width = width;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||||
|
height = 10;
|
||||||
|
}
|
||||||
|
this.height = height;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(target)) {
|
||||||
|
target = null;
|
||||||
|
}
|
||||||
|
this.target = target;
|
||||||
|
|
||||||
|
GameLib.D3.API.Light.call(
|
||||||
|
this,
|
||||||
|
apiLight.id,
|
||||||
|
apiLight.name,
|
||||||
|
apiLight.lightType,
|
||||||
|
apiLight.color,
|
||||||
|
apiLight.intensity,
|
||||||
|
apiLight.parentScene,
|
||||||
|
apiLight.parentEntity
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Light.RectArea.prototype = Object.create(GameLib.D3.API.Light.prototype);
|
||||||
|
GameLib.D3.API.Light.RectArea.prototype.constructor = GameLib.D3.API.Light.RectArea;
|
|
@ -0,0 +1,101 @@
|
||||||
|
/**
|
||||||
|
* Raw Light API object - should always correspond with the Light Schema
|
||||||
|
* @constructor
|
||||||
|
* @param apiLight
|
||||||
|
* @param position
|
||||||
|
* @param angle
|
||||||
|
* @param castShadow
|
||||||
|
* @param decay
|
||||||
|
* @param distance
|
||||||
|
* @param penumbra
|
||||||
|
* @param power
|
||||||
|
* @param shadow
|
||||||
|
* @param target
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Light.Spot = function(
|
||||||
|
apiLight,
|
||||||
|
position,
|
||||||
|
angle,
|
||||||
|
castShadow,
|
||||||
|
decay,
|
||||||
|
distance,
|
||||||
|
penumbra,
|
||||||
|
power,
|
||||||
|
shadow,
|
||||||
|
target
|
||||||
|
) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiLight)) {
|
||||||
|
apiLight = {
|
||||||
|
lightType : GameLib.D3.API.Light.LIGHT_TYPE_SPOT
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Light shines from the top
|
||||||
|
*/
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(position)) {
|
||||||
|
position = new GameLib.API.Vector3(0,1,0);
|
||||||
|
}
|
||||||
|
this.position = position;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* angle should be no more than Math.PI / 2
|
||||||
|
*/
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(angle)) {
|
||||||
|
angle = Math.PI / 3;
|
||||||
|
}
|
||||||
|
this.angle = angle;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(castShadow)) {
|
||||||
|
castShadow = false;
|
||||||
|
}
|
||||||
|
this.castShadow = castShadow;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In physically correct mode, decay is 2
|
||||||
|
*/
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(decay)) {
|
||||||
|
decay = 1;
|
||||||
|
}
|
||||||
|
this.decay = decay;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(distance)) {
|
||||||
|
distance = 0;
|
||||||
|
}
|
||||||
|
this.distance = distance;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(penumbra)) {
|
||||||
|
penumbra = 0;
|
||||||
|
}
|
||||||
|
this.penumbra = penumbra;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(power)) {
|
||||||
|
power = Math.PI * 4;
|
||||||
|
}
|
||||||
|
this.power = power;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(shadow)) {
|
||||||
|
shadow = null;
|
||||||
|
}
|
||||||
|
this.shadow = shadow;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(target)) {
|
||||||
|
target = null;
|
||||||
|
}
|
||||||
|
this.target = target;
|
||||||
|
|
||||||
|
GameLib.D3.API.Light.call(
|
||||||
|
this,
|
||||||
|
apiLight.id,
|
||||||
|
apiLight.name,
|
||||||
|
apiLight.lightType,
|
||||||
|
apiLight.color,
|
||||||
|
apiLight.intensity,
|
||||||
|
apiLight.parentScene,
|
||||||
|
apiLight.parentEntity
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Light.Spot.prototype = Object.create(GameLib.D3.API.Light.prototype);
|
||||||
|
GameLib.D3.API.Light.Spot.prototype.constructor = GameLib.D3.API.Light.Spot;
|
|
@ -1,173 +0,0 @@
|
||||||
/**
|
|
||||||
* Raw Light API object - should always correspond with the Light Schema
|
|
||||||
* @param id
|
|
||||||
* @param lightType
|
|
||||||
* @param name
|
|
||||||
* @param color
|
|
||||||
* @param intensity
|
|
||||||
* @param position
|
|
||||||
* @param targetPosition
|
|
||||||
* @param quaternion
|
|
||||||
* @param rotation
|
|
||||||
* @param scale
|
|
||||||
* @param distance
|
|
||||||
* @param decay
|
|
||||||
* @param power
|
|
||||||
* @param angle
|
|
||||||
* @param penumbra
|
|
||||||
* @param parentScene
|
|
||||||
* @param parentEntity
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.D3.API.Light = function(
|
|
||||||
id,
|
|
||||||
lightType,
|
|
||||||
name,
|
|
||||||
color,
|
|
||||||
intensity,
|
|
||||||
position,
|
|
||||||
targetPosition,
|
|
||||||
quaternion,
|
|
||||||
rotation,
|
|
||||||
scale,
|
|
||||||
distance,
|
|
||||||
decay,
|
|
||||||
power,
|
|
||||||
angle,
|
|
||||||
penumbra,
|
|
||||||
parentScene,
|
|
||||||
parentEntity
|
|
||||||
) {
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
||||||
id = GameLib.Utils.RandomId();
|
|
||||||
}
|
|
||||||
this.id = id;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(lightType)) {
|
|
||||||
lightType = GameLib.D3.Light.LIGHT_TYPE_AMBIENT;
|
|
||||||
}
|
|
||||||
this.lightType = lightType;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
||||||
|
|
||||||
if (this.lightType === GameLib.D3.Light.LIGHT_TYPE_AMBIENT) {
|
|
||||||
name = 'Ambient ';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.lightType === GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL) {
|
|
||||||
name = 'Directional ';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.lightType === GameLib.D3.Light.LIGHT_TYPE_POINT) {
|
|
||||||
name = 'Point ';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.lightType === GameLib.D3.Light.LIGHT_TYPE_SPOT) {
|
|
||||||
name = 'Spot ';
|
|
||||||
}
|
|
||||||
|
|
||||||
name += 'Light (' + id + ')';
|
|
||||||
}
|
|
||||||
this.name = name;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(color)) {
|
|
||||||
color = new GameLib.API.Color(1,1,1,1);
|
|
||||||
}
|
|
||||||
this.color = color;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(intensity)) {
|
|
||||||
intensity = 1;
|
|
||||||
}
|
|
||||||
this.intensity = intensity;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(position)) {
|
|
||||||
position = new GameLib.API.Vector3(10,10,10);
|
|
||||||
}
|
|
||||||
this.position = position;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(targetPosition)) {
|
|
||||||
targetPosition = new GameLib.API.Vector3(0,0,0);
|
|
||||||
}
|
|
||||||
this.targetPosition = targetPosition;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(quaternion)){
|
|
||||||
quaternion = new GameLib.API.Quaternion();
|
|
||||||
}
|
|
||||||
this.quaternion = quaternion;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(rotation)){
|
|
||||||
rotation = new GameLib.API.Vector3(0,0,0);
|
|
||||||
}
|
|
||||||
this.rotation = rotation;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(scale)){
|
|
||||||
scale = new GameLib.API.Vector3(1,1,1);
|
|
||||||
}
|
|
||||||
this.scale = scale;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(distance)){
|
|
||||||
distance = 0;
|
|
||||||
}
|
|
||||||
this.distance = distance;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(decay)){
|
|
||||||
decay = 1;
|
|
||||||
}
|
|
||||||
this.decay = decay;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(power)){
|
|
||||||
power = 4 * Math.PI;
|
|
||||||
}
|
|
||||||
this.power = power;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(angle)){
|
|
||||||
angle = Math.PI / 3;
|
|
||||||
}
|
|
||||||
this.angle = angle;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(penumbra)){
|
|
||||||
penumbra = 0;
|
|
||||||
}
|
|
||||||
this.penumbra = penumbra;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(parentScene)){
|
|
||||||
parentScene = null;
|
|
||||||
}
|
|
||||||
this.parentScene = parentScene;
|
|
||||||
|
|
||||||
GameLib.API.Component.call(
|
|
||||||
this,
|
|
||||||
GameLib.Component.LIGHT,
|
|
||||||
parentEntity
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.API.Light.prototype = Object.create(GameLib.API.Component.prototype);
|
|
||||||
GameLib.D3.API.Light.prototype.constructor = GameLib.D3.API.Light;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an API light from an Object light
|
|
||||||
* @param objectLight
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.D3.API.Light.FromObject = function(objectLight) {
|
|
||||||
return new GameLib.D3.API.Light(
|
|
||||||
objectLight.id,
|
|
||||||
objectLight.lightType,
|
|
||||||
objectLight.name,
|
|
||||||
GameLib.API.Color.FromObject(objectLight.color),
|
|
||||||
objectLight.intensity,
|
|
||||||
GameLib.API.Vector3.FromObject(objectLight.position),
|
|
||||||
GameLib.API.Vector3.FromObject(objectLight.targetPosition),
|
|
||||||
GameLib.API.Quaternion.FromObject(objectLight.quaternion),
|
|
||||||
GameLib.API.Vector3.FromObject(objectLight.rotation),
|
|
||||||
GameLib.API.Vector3.FromObject(objectLight.scale),
|
|
||||||
objectLight.distance,
|
|
||||||
objectLight.decay,
|
|
||||||
objectLight.power,
|
|
||||||
objectLight.angle,
|
|
||||||
objectLight.penumbra,
|
|
||||||
objectLight.parentScene,
|
|
||||||
objectLight.parentEntity
|
|
||||||
);
|
|
||||||
};
|
|
|
@ -47,15 +47,15 @@ GameLib.D3.Helper = function(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (object instanceof GameLib.D3.Light) {
|
if (object instanceof GameLib.D3.Light) {
|
||||||
if (object.lightType === GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL) {
|
if (object.lightType === GameLib.D3.API.Light.LIGHT_TYPE_DIRECTIONAL) {
|
||||||
helperType = GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT;
|
helperType = GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (object.lightType === GameLib.D3.Light.LIGHT_TYPE_POINT) {
|
if (object.lightType === GameLib.D3.API.Light.LIGHT_TYPE_POINT) {
|
||||||
helperType = GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT;
|
helperType = GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (object.lightType === GameLib.D3.Light.LIGHT_TYPE_SPOT) {
|
if (object.lightType === GameLib.D3.API.Light.LIGHT_TYPE_SPOT) {
|
||||||
helperType = GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT;
|
helperType = GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,118 @@
|
||||||
|
/**
|
||||||
|
* Light Superset - The apiLight properties get moved into the Light object itself, and then the instance is created
|
||||||
|
* @param graphics GameLib.GraphicsRuntime
|
||||||
|
* @param apiLight GameLib.D3.API.Light
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light = function(
|
||||||
|
graphics,
|
||||||
|
apiLight
|
||||||
|
) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiLight)) {
|
||||||
|
apiLight = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.API.Controls.call(
|
||||||
|
this,
|
||||||
|
apiLight.id,
|
||||||
|
apiLight.name,
|
||||||
|
apiLight.lightType,
|
||||||
|
apiLight.color,
|
||||||
|
apiLight.intensity,
|
||||||
|
apiLight.parentScene,
|
||||||
|
apiLight.parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
var linkedObjects = {
|
||||||
|
'parentScene' : GameLib.D3.Scene
|
||||||
|
};
|
||||||
|
|
||||||
|
switch (this.componentType) {
|
||||||
|
|
||||||
|
case GameLib.Component.LIGHT_DIRECTIONAL :
|
||||||
|
case GameLib.Component.LIGHT_SPOT :
|
||||||
|
linkedObjects.shadow = GameLib.D3.Shadow;
|
||||||
|
linkedObjects.target = GameLib.Component;
|
||||||
|
break;
|
||||||
|
case GameLib.Component.LIGHT_POINT :
|
||||||
|
linkedObjects.shadow = GameLib.D3.Shadow;
|
||||||
|
break;
|
||||||
|
case GameLib.Component.LIGHT_RECT_AREA :
|
||||||
|
linkedObjects.target = GameLib.Component;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.Component.call(
|
||||||
|
this,
|
||||||
|
linkedObjects,
|
||||||
|
delayed
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Light.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.D3.Light.prototype.constructor = GameLib.D3.Light;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a light instance
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.prototype.createInstance = function() {
|
||||||
|
|
||||||
|
if (!this.instance) {
|
||||||
|
console.warn('call the specific light createInstance first before calling its parent');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.instance.color.set(this.color.toHex());
|
||||||
|
|
||||||
|
this.instance.intensity = this.intensity;
|
||||||
|
|
||||||
|
GameLib.Component.prototype.createInstance.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.prototype.updateInstance = function(property) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(property)) {
|
||||||
|
console.warn('no property for light: ' + this.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'color') {
|
||||||
|
this.instance.color.set(this.color.toHex());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'intensity') {
|
||||||
|
this.instance.intensity = this.intensity;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'parentScene') {
|
||||||
|
console.warn('todo: implement parentScene change for light')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'parentEntity') {
|
||||||
|
console.warn('todo: implement parentEntity change for light')
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.D3.Light to a GameLib.D3.API.Light
|
||||||
|
* @returns {GameLib.D3.API.Light}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.prototype.toApiObject = function() {
|
||||||
|
return new GameLib.D3.API.Light(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
this.lightType,
|
||||||
|
this.color.toApiObject(),
|
||||||
|
this.intensity,
|
||||||
|
GameLib.Utils.IdOrNull(this.parentScene),
|
||||||
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,64 @@
|
||||||
|
/**
|
||||||
|
* Light Superset - The apiLight properties get moved into the Light object itself, and then the instance is created
|
||||||
|
* @param graphics GameLib.GraphicsRuntime
|
||||||
|
* @param apiAmbientLight
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Ambient = function(
|
||||||
|
graphics,
|
||||||
|
apiAmbientLight
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiAmbientLight)) {
|
||||||
|
apiAmbientLight = {
|
||||||
|
lightType : GameLib.D3.API.Light.LIGHT_TYPE_AMBIENT
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.API.Light.Ambient.call(
|
||||||
|
this,
|
||||||
|
apiAmbientLight
|
||||||
|
);
|
||||||
|
|
||||||
|
GameLib.D3.Light.call(
|
||||||
|
this,
|
||||||
|
this.graphics,
|
||||||
|
apiAmbientLight
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Light.Ambient.prototype = Object.create(GameLib.D3.Light.prototype);
|
||||||
|
GameLib.D3.Light.Ambient.prototype.constructor = GameLib.D3.Light.Ambient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a light instance
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Ambient.prototype.createInstance = function() {
|
||||||
|
|
||||||
|
this.instance = new THREE.AmbientLight();
|
||||||
|
|
||||||
|
GameLib.D3.Light.prototype.createInstance.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Ambient.prototype.updateInstance = function(property) {
|
||||||
|
GameLib.D3.Light.prototype.updateInstance.call(this, property);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.D3.Light to a GameLib.D3.API.Light
|
||||||
|
* @returns {GameLib.D3.API.Light}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Ambient.prototype.toApiObject = function() {
|
||||||
|
|
||||||
|
var apiLight = GameLib.D3.Light.prototype.toApiObject.call(this);
|
||||||
|
|
||||||
|
return apiLight;
|
||||||
|
};
|
|
@ -0,0 +1,142 @@
|
||||||
|
/**
|
||||||
|
* Light Superset - The apiLight properties get moved into the Light object itself, and then the instance is created
|
||||||
|
* @param graphics GameLib.GraphicsRuntime
|
||||||
|
* @param apiDirectionalLight
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Directional = function(
|
||||||
|
graphics,
|
||||||
|
apiDirectionalLight
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiDirectionalLight)) {
|
||||||
|
apiDirectionalLight = {
|
||||||
|
lightType : GameLib.D3.API.Light.LIGHT_TYPE_DIRECTIONAL
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.API.Light.Directional.call(
|
||||||
|
this,
|
||||||
|
apiDirectionalLight,
|
||||||
|
apiDirectionalLight.castShadow,
|
||||||
|
apiDirectionalLight.position,
|
||||||
|
apiDirectionalLight.shadow,
|
||||||
|
apiDirectionalLight.target
|
||||||
|
);
|
||||||
|
|
||||||
|
this.position = new GameLib.Vector3(
|
||||||
|
this.graphics,
|
||||||
|
this.position,
|
||||||
|
this
|
||||||
|
);
|
||||||
|
|
||||||
|
if (this.shadow instanceof GameLib.D3.API.Shadow) {
|
||||||
|
this.shadow = new GameLib.D3.Shadow(
|
||||||
|
this.graphics,
|
||||||
|
this.shadow
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.target instanceof GameLib.API.Component) {
|
||||||
|
console.warn('todo: implement generic api component to runtime component here');
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.Light.call(
|
||||||
|
this,
|
||||||
|
this.graphics,
|
||||||
|
apiDirectionalLight
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Light.Directional.prototype = Object.create(GameLib.D3.Light.prototype);
|
||||||
|
GameLib.D3.Light.Directional.prototype.constructor = GameLib.D3.Light.Directional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a light instance
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Directional.prototype.createInstance = function() {
|
||||||
|
|
||||||
|
this.instance = new THREE.DirectionalLight();
|
||||||
|
|
||||||
|
this.instance.castShadow = this.castShadow;
|
||||||
|
|
||||||
|
this.instance.position.x = this.position.x;
|
||||||
|
this.instance.position.y = this.position.y;
|
||||||
|
this.instance.position.z = this.position.z;
|
||||||
|
|
||||||
|
if (this.shadow && this.shadow.instance) {
|
||||||
|
this.instance.shadow = this.shadow.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.target && this.target.instance) {
|
||||||
|
this.instance.target = this.target.instance;
|
||||||
|
|
||||||
|
if (this.parentScene && this.parentScene.instance) {
|
||||||
|
this.parentScene.addObject(this.target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.Light.prototype.createInstance.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Directional.prototype.updateInstance = function(property, oldTarget) {
|
||||||
|
|
||||||
|
if (property === 'castShadow') {
|
||||||
|
this.instance.castShadow = this.castShadow;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'position') {
|
||||||
|
this.instance.position.x = this.position.x;
|
||||||
|
this.instance.position.y = this.position.y;
|
||||||
|
this.instance.position.z = this.position.z;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'shadow') {
|
||||||
|
this.instance.shadow = this.shadow.instance;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'target') {
|
||||||
|
|
||||||
|
if (typeof oldTarget === 'undefined') {
|
||||||
|
console.warn('oldTarget undefined');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldTarget) {
|
||||||
|
if (this.parentScene) {
|
||||||
|
this.parentScene.removeObject(oldTarget);
|
||||||
|
this.parentScene.addObject(this.target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.Light.prototype.updateInstance.call(this, property);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.D3.Light to a GameLib.D3.API.Light
|
||||||
|
* @returns {GameLib.D3.API.Light}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Directional.prototype.toApiObject = function() {
|
||||||
|
|
||||||
|
var apiDirectionalLight = GameLib.D3.Light.prototype.toApiObject.call(this);
|
||||||
|
|
||||||
|
apiDirectionalLight.castShadow = this.castShadow;
|
||||||
|
apiDirectionalLight.position = this.position.toApiObject();
|
||||||
|
apiDirectionalLight.shadow = GameLib.Utils.IdOrNull(this.shadow);
|
||||||
|
apiDirectionalLight.target = GameLib.Utils.IdOrNull(this.target);
|
||||||
|
|
||||||
|
return apiDirectionalLight;
|
||||||
|
};
|
|
@ -0,0 +1,119 @@
|
||||||
|
/**
|
||||||
|
* Light Superset - The apiLight properties get moved into the Light object itself, and then the instance is created
|
||||||
|
* @param graphics GameLib.GraphicsRuntime
|
||||||
|
* @param apiHemisphereLight
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Hemisphere = function(
|
||||||
|
graphics,
|
||||||
|
apiHemisphereLight
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiHemisphereLight)) {
|
||||||
|
apiHemisphereLight = {
|
||||||
|
lightType : GameLib.D3.API.Light.LIGHT_TYPE_HEMISPHERE
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.API.Light.Hemisphere.call(
|
||||||
|
this,
|
||||||
|
apiHemisphereLight,
|
||||||
|
apiHemisphereLight.castShadow,
|
||||||
|
apiHemisphereLight.position,
|
||||||
|
apiHemisphereLight.groundColor
|
||||||
|
);
|
||||||
|
|
||||||
|
this.position = new GameLib.Vector3(
|
||||||
|
this.graphics,
|
||||||
|
this.position,
|
||||||
|
this
|
||||||
|
);
|
||||||
|
|
||||||
|
this.groundColor = new GameLib.Color(
|
||||||
|
this.graphics,
|
||||||
|
this.groundColor,
|
||||||
|
this
|
||||||
|
);
|
||||||
|
|
||||||
|
GameLib.D3.Light.call(
|
||||||
|
this,
|
||||||
|
this.graphics,
|
||||||
|
apiHemisphereLight
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Light.Hemisphere.prototype = Object.create(GameLib.D3.Light.prototype);
|
||||||
|
GameLib.D3.Light.Hemisphere.prototype.constructor = GameLib.D3.Light.Hemisphere;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a light instance
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Hemisphere.prototype.createInstance = function() {
|
||||||
|
|
||||||
|
this.instance = new THREE.HemisphereLight();
|
||||||
|
|
||||||
|
this.instance.castShadow = this.castShadow;
|
||||||
|
|
||||||
|
this.instance.position.x = this.position.x;
|
||||||
|
this.instance.position.y = this.position.y;
|
||||||
|
this.instance.position.z = this.position.z;
|
||||||
|
|
||||||
|
if (this.shadow && this.shadow.instance) {
|
||||||
|
this.instance.shadow = this.shadow.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.target && this.target.instance) {
|
||||||
|
this.instance.target = this.target.instance;
|
||||||
|
|
||||||
|
if (this.parentScene && this.parentScene.instance) {
|
||||||
|
this.parentScene.addObject(this.target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.Light.prototype.createInstance.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Hemisphere.prototype.updateInstance = function(property, oldTarget) {
|
||||||
|
|
||||||
|
if (property === 'castShadow') {
|
||||||
|
this.instance.castShadow = this.castShadow;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'position') {
|
||||||
|
this.instance.position.x = this.position.x;
|
||||||
|
this.instance.position.y = this.position.y;
|
||||||
|
this.instance.position.z = this.position.z;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'groundColor') {
|
||||||
|
this.instance.groundColor.set(this.color.toHex());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.Light.prototype.updateInstance.call(this, property);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.D3.Light to a GameLib.D3.API.Light
|
||||||
|
* @returns {GameLib.D3.API.Light}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Hemisphere.prototype.toApiObject = function() {
|
||||||
|
|
||||||
|
var apiHemisphereLight = GameLib.D3.Light.prototype.toApiObject.call(this);
|
||||||
|
|
||||||
|
apiHemisphereLight.castShadow = this.castShadow;
|
||||||
|
apiHemisphereLight.position = this.position.toApiObject();
|
||||||
|
apiHemisphereLight.groundColor = this.groundColor.toApiObject();
|
||||||
|
|
||||||
|
return apiHemisphereLight;
|
||||||
|
};
|
|
@ -0,0 +1,130 @@
|
||||||
|
/**
|
||||||
|
* Light Superset - The apiLight properties get moved into the Light object itself, and then the instance is created
|
||||||
|
* @param graphics GameLib.GraphicsRuntime
|
||||||
|
* @param apiPointLight
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Point = function(
|
||||||
|
graphics,
|
||||||
|
apiPointLight
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiPointLight)) {
|
||||||
|
apiPointLight = {
|
||||||
|
lightType : GameLib.D3.API.Light.LIGHT_TYPE_POINT
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.API.Light.Point.call(
|
||||||
|
this,
|
||||||
|
apiPointLight,
|
||||||
|
apiPointLight.position,
|
||||||
|
apiPointLight.decay,
|
||||||
|
apiPointLight.distance,
|
||||||
|
apiPointLight.power,
|
||||||
|
apiPointLight.shadow
|
||||||
|
);
|
||||||
|
|
||||||
|
this.position = new GameLib.Vector3(
|
||||||
|
this.graphics,
|
||||||
|
this.position,
|
||||||
|
this
|
||||||
|
);
|
||||||
|
|
||||||
|
if (this.shadow instanceof GameLib.D3.API.Shadow) {
|
||||||
|
this.shadow = new GameLib.D3.Shadow(
|
||||||
|
this.graphics,
|
||||||
|
this.shadow
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.Light.call(
|
||||||
|
this,
|
||||||
|
this.graphics,
|
||||||
|
apiPointLight
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Light.Point.prototype = Object.create(GameLib.D3.Light.prototype);
|
||||||
|
GameLib.D3.Light.Point.prototype.constructor = GameLib.D3.Light.Point;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a light instance
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Point.prototype.createInstance = function() {
|
||||||
|
|
||||||
|
this.instance = new THREE.PointLight();
|
||||||
|
|
||||||
|
this.instance.position.x = this.position.x;
|
||||||
|
this.instance.position.y = this.position.y;
|
||||||
|
this.instance.position.z = this.position.z;
|
||||||
|
|
||||||
|
this.instance.decay = this.decay;
|
||||||
|
this.instance.distance = this.distance;
|
||||||
|
this.instance.power = this.power;
|
||||||
|
|
||||||
|
if (this.shadow && this.shadow.instance) {
|
||||||
|
this.instance.shadow = this.shadow.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.Light.prototype.createInstance.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Point.prototype.updateInstance = function(property) {
|
||||||
|
|
||||||
|
if (property === 'position') {
|
||||||
|
this.instance.position.x = this.position.x;
|
||||||
|
this.instance.position.y = this.position.y;
|
||||||
|
this.instance.position.z = this.position.z;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'decay') {
|
||||||
|
this.instance.decay = this.decay;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'distance') {
|
||||||
|
this.instance.distance = this.distance;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'power') {
|
||||||
|
this.instance.power = this.power;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'shadow') {
|
||||||
|
if (this.shadow && this.shadow.instance) {
|
||||||
|
this.instance.shadow = this.shadow.instance;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.Light.prototype.updateInstance.call(this, property);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.D3.Light to a GameLib.D3.API.Light
|
||||||
|
* @returns {GameLib.D3.API.Light}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Point.prototype.toApiObject = function() {
|
||||||
|
|
||||||
|
var apiPointLight = GameLib.D3.Light.prototype.toApiObject.call(this);
|
||||||
|
|
||||||
|
apiPointLight.position = this.position.toApiObject();
|
||||||
|
apiPointLight.decay = this.decay;
|
||||||
|
apiPointLight.distance = this.distance;
|
||||||
|
apiPointLight.power = this.power;
|
||||||
|
apiPointLight.shadow = GameLib.Utils.IdOrNull(this.shadow);
|
||||||
|
|
||||||
|
return apiPointLight;
|
||||||
|
};
|
|
@ -0,0 +1,157 @@
|
||||||
|
/**
|
||||||
|
* Light Superset - The apiLight properties get moved into the Light object itself, and then the instance is created
|
||||||
|
* @param graphics GameLib.GraphicsRuntime
|
||||||
|
* @param apiRectAreaLight
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.RectArea = function(
|
||||||
|
graphics,
|
||||||
|
apiRectAreaLight
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiRectAreaLight)) {
|
||||||
|
apiRectAreaLight = {
|
||||||
|
lightType : GameLib.D3.API.Light.LIGHT_TYPE_RECT_AREA
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.API.Light.RectArea.call(
|
||||||
|
this,
|
||||||
|
apiRectAreaLight,
|
||||||
|
apiRectAreaLight.position,
|
||||||
|
apiRectAreaLight.castShadow,
|
||||||
|
apiRectAreaLight.decay,
|
||||||
|
apiRectAreaLight.distance,
|
||||||
|
apiRectAreaLight.width,
|
||||||
|
apiRectAreaLight.height,
|
||||||
|
apiRectAreaLight.target
|
||||||
|
);
|
||||||
|
|
||||||
|
this.position = new GameLib.Vector3(
|
||||||
|
this.graphics,
|
||||||
|
this.position,
|
||||||
|
this
|
||||||
|
);
|
||||||
|
|
||||||
|
if (this.target instanceof GameLib.API.Component) {
|
||||||
|
console.warn('todo: implement generic api component to runtime component here');
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.Light.call(
|
||||||
|
this,
|
||||||
|
this.graphics,
|
||||||
|
apiRectAreaLight
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Light.RectArea.prototype = Object.create(GameLib.D3.Light.prototype);
|
||||||
|
GameLib.D3.Light.RectArea.prototype.constructor = GameLib.D3.Light.RectArea;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a light instance
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.RectArea.prototype.createInstance = function() {
|
||||||
|
|
||||||
|
this.instance = new THREE.RectAreaLight();
|
||||||
|
|
||||||
|
this.instance.position.x = this.position.x;
|
||||||
|
this.instance.position.y = this.position.y;
|
||||||
|
this.instance.position.z = this.position.z;
|
||||||
|
|
||||||
|
this.instance.castShadow = this.castShadow;
|
||||||
|
|
||||||
|
this.instance.decay = this.decay;
|
||||||
|
this.instance.distance = this.distance;
|
||||||
|
|
||||||
|
this.instance.width = this.width;
|
||||||
|
this.instance.height = this.height;
|
||||||
|
|
||||||
|
if (this.target && this.target.instance) {
|
||||||
|
this.instance.target = this.target.instance;
|
||||||
|
|
||||||
|
if (this.parentScene && this.parentScene.instance) {
|
||||||
|
this.parentScene.addObject(this.target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GameLib.D3.Light.prototype.createInstance.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.RectArea.prototype.updateInstance = function(property, oldTarget) {
|
||||||
|
|
||||||
|
if (property === 'castShadow') {
|
||||||
|
this.instance.castShadow = this.castShadow;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'position') {
|
||||||
|
this.instance.position.x = this.position.x;
|
||||||
|
this.instance.position.y = this.position.y;
|
||||||
|
this.instance.position.z = this.position.z;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'decay') {
|
||||||
|
this.instance.decay = this.decay;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'distance') {
|
||||||
|
this.instance.distance = this.distance;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'width') {
|
||||||
|
this.instance.width = this.width;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'height') {
|
||||||
|
this.instance.height = this.height;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'target') {
|
||||||
|
|
||||||
|
if (typeof oldTarget === 'undefined') {
|
||||||
|
console.warn('oldTarget undefined');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldTarget) {
|
||||||
|
if (this.parentScene) {
|
||||||
|
this.parentScene.removeObject(oldTarget);
|
||||||
|
this.parentScene.addObject(this.target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.Light.prototype.updateInstance.call(this, property);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.D3.Light to a GameLib.D3.API.Light
|
||||||
|
* @returns {GameLib.D3.API.Light}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.RectArea.prototype.toApiObject = function() {
|
||||||
|
|
||||||
|
var apiRectAreaLight = GameLib.D3.Light.prototype.toApiObject.call(this);
|
||||||
|
|
||||||
|
apiRectAreaLight.position = this.position.toApiObject();
|
||||||
|
apiRectAreaLight.castShadow = this.castShadow;
|
||||||
|
apiRectAreaLight.decay = this.decay;
|
||||||
|
apiRectAreaLight.distance = this.distance;
|
||||||
|
apiRectAreaLight.width = this.width;
|
||||||
|
apiRectAreaLight.height = this.height;
|
||||||
|
apiRectAreaLight.target = GameLib.Utils.IdOrNull(this.target);
|
||||||
|
|
||||||
|
return apiRectAreaLight;
|
||||||
|
};
|
|
@ -0,0 +1,184 @@
|
||||||
|
/**
|
||||||
|
* Light Superset - The apiLight properties get moved into the Light object itself, and then the instance is created
|
||||||
|
* @param graphics GameLib.GraphicsRuntime
|
||||||
|
* @param apiSpotLight
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Spot = function(
|
||||||
|
graphics,
|
||||||
|
apiSpotLight
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiSpotLight)) {
|
||||||
|
apiSpotLight = {
|
||||||
|
lightType : GameLib.D3.API.Light.LIGHT_TYPE_SPOT
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.API.Light.Spot.call(
|
||||||
|
this,
|
||||||
|
apiSpotLight,
|
||||||
|
apiSpotLight.position,
|
||||||
|
apiSpotLight.angle,
|
||||||
|
apiSpotLight.castShadow,
|
||||||
|
apiSpotLight.decay,
|
||||||
|
apiSpotLight.distance,
|
||||||
|
apiSpotLight.penumbra,
|
||||||
|
apiSpotLight.power,
|
||||||
|
apiSpotLight.shadow,
|
||||||
|
apiSpotLight.target
|
||||||
|
);
|
||||||
|
|
||||||
|
this.position = new GameLib.Vector3(
|
||||||
|
this.graphics,
|
||||||
|
this.position,
|
||||||
|
this
|
||||||
|
);
|
||||||
|
|
||||||
|
if (this.shadow instanceof GameLib.D3.API.Shadow) {
|
||||||
|
this.shadow = new GameLib.D3.Shadow(
|
||||||
|
this.graphics,
|
||||||
|
this.shadow
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.target instanceof GameLib.API.Component) {
|
||||||
|
console.warn('todo: implement generic api component to runtime component here');
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.Light.call(
|
||||||
|
this,
|
||||||
|
this.graphics,
|
||||||
|
apiSpotLight
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Light.Spot.prototype = Object.create(GameLib.D3.Light.prototype);
|
||||||
|
GameLib.D3.Light.Spot.prototype.constructor = GameLib.D3.Light.Spot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a light instance
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Spot.prototype.createInstance = function() {
|
||||||
|
|
||||||
|
this.instance = new THREE.SpotLight();
|
||||||
|
|
||||||
|
this.instance.position.x = this.position.x;
|
||||||
|
this.instance.position.y = this.position.y;
|
||||||
|
this.instance.position.z = this.position.z;
|
||||||
|
|
||||||
|
this.instance.angle = this.angle;
|
||||||
|
this.instance.castShadow = this.castShadow;
|
||||||
|
this.instance.decay = this.decay;
|
||||||
|
this.instance.distance = this.distance;
|
||||||
|
this.instance.penumbra = this.penumbra;
|
||||||
|
this.instance.power = this.power;
|
||||||
|
|
||||||
|
if (this.shadow && this.shadow.instance) {
|
||||||
|
this.instance.shadow = this.shadow.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.target && this.target.instance) {
|
||||||
|
this.instance.target = this.target.instance;
|
||||||
|
|
||||||
|
if (this.parentScene && this.parentScene.instance) {
|
||||||
|
this.parentScene.addObject(this.target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.Light.prototype.createInstance.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Spot.prototype.updateInstance = function(property, oldTarget) {
|
||||||
|
|
||||||
|
if (property === 'position') {
|
||||||
|
this.instance.position.x = this.position.x;
|
||||||
|
this.instance.position.y = this.position.y;
|
||||||
|
this.instance.position.z = this.position.z;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'angle') {
|
||||||
|
this.instance.angle = this.angle;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'castShadow') {
|
||||||
|
this.instance.castShadow = this.castShadow;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'decay') {
|
||||||
|
this.instance.decay = this.decay;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'distance') {
|
||||||
|
this.instance.distance = this.distance;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'penumbra') {
|
||||||
|
this.instance.penumbra = this.penumbra;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'power') {
|
||||||
|
this.instance.power = this.power;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'shadow') {
|
||||||
|
if (this.shadow && this.shadow.instance) {
|
||||||
|
this.instance.shadow = this.shadow.instance;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'target') {
|
||||||
|
|
||||||
|
if (typeof oldTarget === 'undefined') {
|
||||||
|
console.warn('oldTarget undefined');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldTarget) {
|
||||||
|
if (this.parentScene) {
|
||||||
|
this.parentScene.removeObject(oldTarget);
|
||||||
|
this.parentScene.addObject(this.target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.Light.prototype.updateInstance.call(this, property);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.D3.Light to a GameLib.D3.API.Light
|
||||||
|
* @returns {GameLib.D3.API.Light}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.Spot.prototype.toApiObject = function() {
|
||||||
|
|
||||||
|
var apiSpotLight = GameLib.D3.Light.prototype.toApiObject.call(this);
|
||||||
|
|
||||||
|
apiSpotLight.position = this.position.toApiObject();
|
||||||
|
apiSpotLight.angle = this.angle;
|
||||||
|
apiSpotLight.castShadow = this.castShadow;
|
||||||
|
apiSpotLight.decay = this.decay;
|
||||||
|
apiSpotLight.distance = this.distance;
|
||||||
|
apiSpotLight.penumbra = this.penumbra;
|
||||||
|
apiSpotLight.power = this.power;
|
||||||
|
apiSpotLight.shadow = GameLib.Utils.IdOrNull(this.shadow);
|
||||||
|
apiSpotLight.target = GameLib.Utils.IdOrNull(this.target);
|
||||||
|
|
||||||
|
return apiSpotLight;
|
||||||
|
};
|
|
@ -1,270 +0,0 @@
|
||||||
/**
|
|
||||||
* Light Superset - The apiLight properties get moved into the Light object itself, and then the instance is created
|
|
||||||
* @param graphics GameLib.GraphicsRuntime
|
|
||||||
* @param apiLight GameLib.D3.API.Light
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.D3.Light = function(
|
|
||||||
graphics,
|
|
||||||
apiLight
|
|
||||||
) {
|
|
||||||
this.graphics = graphics;
|
|
||||||
this.graphics.isNotThreeThrow();
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(apiLight)) {
|
|
||||||
apiLight = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
GameLib.D3.API.Light.call(
|
|
||||||
this,
|
|
||||||
apiLight.id,
|
|
||||||
apiLight.lightType,
|
|
||||||
apiLight.name,
|
|
||||||
apiLight.color,
|
|
||||||
apiLight.intensity,
|
|
||||||
apiLight.position,
|
|
||||||
apiLight.targetPosition,
|
|
||||||
apiLight.quaternion,
|
|
||||||
apiLight.rotation,
|
|
||||||
apiLight.scale,
|
|
||||||
apiLight.distance,
|
|
||||||
apiLight.decay,
|
|
||||||
apiLight.power,
|
|
||||||
apiLight.angle,
|
|
||||||
apiLight.penumbra,
|
|
||||||
apiLight.parentScene,
|
|
||||||
apiLight.parentEntity
|
|
||||||
);
|
|
||||||
|
|
||||||
this.color = new GameLib.Color(
|
|
||||||
graphics,
|
|
||||||
this.color,
|
|
||||||
this
|
|
||||||
);
|
|
||||||
|
|
||||||
this.position = new GameLib.Vector3(
|
|
||||||
graphics,
|
|
||||||
this.position,
|
|
||||||
this
|
|
||||||
);
|
|
||||||
|
|
||||||
this.targetPosition = new GameLib.Vector3(
|
|
||||||
graphics,
|
|
||||||
this.targetPosition,
|
|
||||||
this
|
|
||||||
);
|
|
||||||
|
|
||||||
this.scale = new GameLib.Vector3(
|
|
||||||
graphics,
|
|
||||||
this.scale,
|
|
||||||
this
|
|
||||||
);
|
|
||||||
|
|
||||||
this.quaternion = new GameLib.Quaternion(
|
|
||||||
graphics,
|
|
||||||
this.quaternion,
|
|
||||||
this
|
|
||||||
);
|
|
||||||
|
|
||||||
this.rotation = new GameLib.Vector3(
|
|
||||||
graphics,
|
|
||||||
this.rotation,
|
|
||||||
this
|
|
||||||
);
|
|
||||||
|
|
||||||
GameLib.Component.call(
|
|
||||||
this,
|
|
||||||
{
|
|
||||||
'parentScene' : GameLib.D3.Scene
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.Light.prototype = Object.create(GameLib.Component.prototype);
|
|
||||||
GameLib.D3.Light.prototype.constructor = GameLib.D3.Light;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Light Types
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
GameLib.D3.Light.LIGHT_TYPE_AMBIENT = 0x1;
|
|
||||||
GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL = 0x2;
|
|
||||||
GameLib.D3.Light.LIGHT_TYPE_POINT = 0x3;
|
|
||||||
GameLib.D3.Light.LIGHT_TYPE_SPOT = 0x4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a light instance
|
|
||||||
* @returns {*}
|
|
||||||
*/
|
|
||||||
GameLib.D3.Light.prototype.createInstance = function() {
|
|
||||||
|
|
||||||
if (
|
|
||||||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_AMBIENT ||
|
|
||||||
this.lightType === 'AmbientLight'
|
|
||||||
) {
|
|
||||||
this.instance = new THREE.AmbientLight(
|
|
||||||
this.color.instance,
|
|
||||||
this.intensity
|
|
||||||
);
|
|
||||||
} else if (
|
|
||||||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL ||
|
|
||||||
this.lightType === 'DirectionalLight'
|
|
||||||
) {
|
|
||||||
this.instance = new THREE.DirectionalLight(
|
|
||||||
this.color.instance,
|
|
||||||
this.intensity
|
|
||||||
);
|
|
||||||
} else if (
|
|
||||||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_POINT ||
|
|
||||||
this.lightType === 'PointLight'
|
|
||||||
) {
|
|
||||||
this.instance = new THREE.PointLight(
|
|
||||||
this.color.instance,
|
|
||||||
this.intensity
|
|
||||||
);
|
|
||||||
this.instance.distance = this.distance;
|
|
||||||
this.instance.decay = this.decay;
|
|
||||||
} else if (
|
|
||||||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_SPOT ||
|
|
||||||
this.lightType === 'SpotLight'
|
|
||||||
) {
|
|
||||||
this.instance = new THREE.SpotLight(
|
|
||||||
this.color.instance,
|
|
||||||
this.intensity
|
|
||||||
);
|
|
||||||
this.instance.distance = this.distance;
|
|
||||||
this.instance.angle = this.angle;
|
|
||||||
this.instance.penumbra = this.penumbra;
|
|
||||||
this.instance.decay = this.decay;
|
|
||||||
} else {
|
|
||||||
console.warn('unsupported light type: ' + this.lightType);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.instance.name = this.name;
|
|
||||||
|
|
||||||
this.instance.position.x = this.position.x;
|
|
||||||
this.instance.position.y = this.position.y;
|
|
||||||
this.instance.position.z = this.position.z;
|
|
||||||
|
|
||||||
this.instance.scale.x = this.scale.x;
|
|
||||||
this.instance.scale.y = this.scale.y;
|
|
||||||
this.instance.scale.z = this.scale.z;
|
|
||||||
|
|
||||||
if (this.instance.target) {
|
|
||||||
this.instance.target.position.x = this.targetPosition.x;
|
|
||||||
this.instance.target.position.y = this.targetPosition.y;
|
|
||||||
this.instance.target.position.z = this.targetPosition.z;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.instance.quaternion.x = this.quaternion.x;
|
|
||||||
this.instance.quaternion.y = this.quaternion.y;
|
|
||||||
this.instance.quaternion.z = this.quaternion.z;
|
|
||||||
this.instance.quaternion.w = this.quaternion.w;
|
|
||||||
|
|
||||||
this.instance.intensity = this.intensity;
|
|
||||||
|
|
||||||
this.instance.color.set(this.color.toHex());
|
|
||||||
|
|
||||||
GameLib.Component.prototype.createInstance.call(this);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the instance with the current state
|
|
||||||
*/
|
|
||||||
GameLib.D3.Light.prototype.updateInstance = function(property) {
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(property)) {
|
|
||||||
console.warn('no property for light: ' + this.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (property === 'lightType') {
|
|
||||||
this.parentScene.instance.remove(this.instance);
|
|
||||||
this.createInstance();
|
|
||||||
this.parentScene.instance.add(this.instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (property === 'name') {
|
|
||||||
this.instance.name = this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (property === 'position') {
|
|
||||||
this.instance.position.x = this.position.x;
|
|
||||||
this.instance.position.y = this.position.y;
|
|
||||||
this.instance.position.z = this.position.z;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (property === 'scale') {
|
|
||||||
this.instance.scale.x = this.scale.x;
|
|
||||||
this.instance.scale.y = this.scale.y;
|
|
||||||
this.instance.scale.z = this.scale.z;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (property === 'target') {
|
|
||||||
if (this.instance.target) {
|
|
||||||
this.instance.target.position.x = this.targetPosition.x;
|
|
||||||
this.instance.target.position.y = this.targetPosition.y;
|
|
||||||
this.instance.target.position.z = this.targetPosition.z;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (property === 'quaternion') {
|
|
||||||
this.instance.quaternion.x = this.quaternion.x;
|
|
||||||
this.instance.quaternion.y = this.quaternion.y;
|
|
||||||
this.instance.quaternion.z = this.quaternion.z;
|
|
||||||
this.instance.quaternion.w = this.quaternion.w;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (property === 'intensity') {
|
|
||||||
this.instance.intensity = this.intensity;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (property === 'color') {
|
|
||||||
this.instance.color.set(this.color.toHex());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 'parentScene' is handled by LinkingSystem
|
|
||||||
*/
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a GameLib.D3.Light to a GameLib.D3.API.Light
|
|
||||||
* @returns {GameLib.D3.API.Light}
|
|
||||||
*/
|
|
||||||
GameLib.D3.Light.prototype.toApiObject = function() {
|
|
||||||
return new GameLib.D3.API.Light(
|
|
||||||
this.id,
|
|
||||||
this.lightType,
|
|
||||||
this.name,
|
|
||||||
this.color.toApiObject(),
|
|
||||||
this.intensity,
|
|
||||||
this.position.toApiObject(),
|
|
||||||
this.targetPosition.toApiObject(),
|
|
||||||
this.quaternion.toApiObject(),
|
|
||||||
this.rotation.toApiObject(),
|
|
||||||
this.scale.toApiObject(),
|
|
||||||
this.distance,
|
|
||||||
this.decay,
|
|
||||||
this.power,
|
|
||||||
this.angle,
|
|
||||||
this.penumbra,
|
|
||||||
GameLib.Utils.IdOrNull(this.parentScene),
|
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a new GameLib.D3.Light from a GameLib.D3.API.Light
|
|
||||||
* @param graphics GameLib.GraphicsRuntime
|
|
||||||
* @param objectLight GameLib.D3.API.Light
|
|
||||||
* @returns {GameLib.D3.Light}
|
|
||||||
*/
|
|
||||||
GameLib.D3.Light.FromObject = function(graphics, objectLight) {
|
|
||||||
|
|
||||||
return new GameLib.D3.Light(
|
|
||||||
graphics,
|
|
||||||
GameLib.D3.API.Light.FromObject(objectLight)
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
|
|
@ -1392,10 +1392,12 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
||||||
object,
|
object,
|
||||||
property,
|
property,
|
||||||
{
|
{
|
||||||
'ambient': GameLib.D3.Light.LIGHT_TYPE_AMBIENT,
|
'ambient': GameLib.D3.API.Light.LIGHT_TYPE_AMBIENT,
|
||||||
'directional': GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL,
|
'directional': GameLib.D3.API.Light.LIGHT_TYPE_DIRECTIONAL,
|
||||||
'spot': GameLib.D3.Light.LIGHT_TYPE_SPOT,
|
'spot': GameLib.D3.API.Light.LIGHT_TYPE_SPOT,
|
||||||
'point': GameLib.D3.Light.LIGHT_TYPE_POINT
|
'point': GameLib.D3.API.Light.LIGHT_TYPE_POINT,
|
||||||
|
'hemisphere': GameLib.D3.API.Light.LIGHT_TYPE_HEMISPHERE,
|
||||||
|
'rect area': GameLib.D3.API.Light.LIGHT_TYPE_RECT_AREA
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,13 +4,17 @@
|
||||||
* @param apiVector3 GameLib.API.Vector3
|
* @param apiVector3 GameLib.API.Vector3
|
||||||
* @param parentObject GameLib.*
|
* @param parentObject GameLib.*
|
||||||
* @param grain Number
|
* @param grain Number
|
||||||
|
* @param min
|
||||||
|
* @param max
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.Vector3 = function (
|
GameLib.Vector3 = function (
|
||||||
implementation,
|
implementation,
|
||||||
apiVector3,
|
apiVector3,
|
||||||
parentObject,
|
parentObject,
|
||||||
grain
|
grain,
|
||||||
|
min,
|
||||||
|
max
|
||||||
) {
|
) {
|
||||||
|
|
||||||
this.implementation = implementation;
|
this.implementation = implementation;
|
||||||
|
@ -48,6 +52,17 @@ GameLib.Vector3 = function (
|
||||||
}
|
}
|
||||||
this.grain = grain;
|
this.grain = grain;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(min)) {
|
||||||
|
min = 0;
|
||||||
|
}
|
||||||
|
this.min = min;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(max)) {
|
||||||
|
max = 1;
|
||||||
|
}
|
||||||
|
this.max = max;
|
||||||
|
|
||||||
|
|
||||||
this.createInstance();
|
this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue