crazy render mode

beta.r3js.org
-=yb4f310 2018-01-29 12:42:46 +01:00
parent cb8abfb5ec
commit 7916ec376c
50 changed files with 2173 additions and 666 deletions

View File

@ -207,6 +207,50 @@ GameLib.Utils.UndefinedOrNull = function (
return typeof variable === 'undefined' || variable === null;
};
/**
* The variable is not undefined and not null
* @param variable
* @returns {boolean}
* @constructor
*/
GameLib.Utils.Defined = function (
variable
) {
return typeof variable !== 'undefined' && variable !== null;
};
/**
* Gets function parameters
* @param fn
* @constructor
*/
GameLib.Utils.GetParameters = function(fn) {
var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
var FN_ARG_SPLIT = /,/;
var FN_ARG = /^\s*(_?)(.+?)\1\s*$/;
var STRIP_COMMENTS = /(\/\/.*$)|(\/\*[\s\S]*?\*\/)|(\s*=[^,\)]*(('(?:\\'|[^'\r\n])*')|("(?:\\"|[^"\r\n])*"))|(\s*=[^,\)]*))/mg;
var parameters,
fnText,
argDecl;
if (typeof fn !== 'function') {
parameters = [];
fnText = fn.toString().replace(STRIP_COMMENTS, '');
argDecl = fnText.match(FN_ARGS);
argDecl[1].split(FN_ARG_SPLIT).forEach(function(arg) {
arg.replace(FN_ARG, function(all, underscore, name) {
parameters.push(name);
});
});
} else {
throw Error("not a function")
}
return parameters;
};
/**
* Returns either an ID of the object or Null
* @param object

View File

@ -208,11 +208,11 @@ GameLib.Component.SOCKET_RECEIVE = 0x1;
GameLib.Component.MATERIAL = 0x2;
GameLib.Component.RENDERER = 0x3;
GameLib.Component.SERVER = 0x4;
GameLib.Component.CAMERA = 0x5;
GameLib.Component.CAMERA_PERSPECTIVE = 0x5;
GameLib.Component.SOCKET = 0x6;
GameLib.Component.MESH = 0x7;
GameLib.Component.SPLINE = 0x8;
//GameLib.Component.LIGHT = 0x9;
GameLib.Component.SHADOW_DIRECTIONAL = 0x9;
GameLib.Component.PLANE = 0xa;
GameLib.Component.COMPOSER = 0xb;
GameLib.Component.RENDER_TARGET = 0xc;
@ -231,7 +231,7 @@ GameLib.Component.SKELETON = 0x18;
GameLib.Component.TEXTURE = 0x19;
GameLib.Component.ENTITY_MANAGER = 0x1a;
GameLib.Component.DOM_ELEMENT = 0x1b;
//GameLib.Component.IMAGE_FACTORY = 0x1c;
GameLib.Component.SHADOW_SPOT = 0x1c;
GameLib.Component.STATS = 0x1d;
GameLib.Component.GUI = 0x1e;
GameLib.Component.IMAGE = 0x1f;
@ -291,7 +291,11 @@ GameLib.Component.PARTICLE = 0x54;
GameLib.Component.AUDIO = 0x55;
GameLib.Component.SYSTEM_AUDIO = 0x56;
GameLib.Component.SOCKET_CAST = 0x57;
GameLib.Component.MAX_COMPONENTS = 0x58;
GameLib.Component.CAMERA_ORTHOGRAPHIC = 0x58;
GameLib.Component.CAMERA_STEREO = 0x59;
GameLib.Component.CAMERA_CUBE = 0x5a;
GameLib.Component.SHADOW = 0x5b;
GameLib.Component.MAX_COMPONENTS = 0x5c;
GameLib.Component.GRAPHICS_RUNTIME = 0x1;
GameLib.Component.PHYSICS_RUNTIME = 0x2;
@ -341,10 +345,10 @@ GameLib.Component.GetComponentInfo = function(number) {
apiConstructor : GameLib.API.Server
};
case 0x5 : return {
name : 'GameLib.D3.Camera',
name : 'GameLib.D3.Camera.Perspective',
runtime : GameLib.Component.GRAPHICS_RUNTIME,
constructor : GameLib.D3.Camera,
apiConstructor : GameLib.D3.API.Camera
constructor : GameLib.D3.Camera.Perspective,
apiConstructor : GameLib.D3.API.Camera.Perspective
};
case 0x6 : return {
name : 'GameLib.Socket',
@ -365,10 +369,10 @@ GameLib.Component.GetComponentInfo = function(number) {
apiConstructor : GameLib.D3.API.Spline
};
case 0x9 : return {
name : 'GameLib.D3.Light',
name : 'GameLib.D3.Shadow.Directional',
runtime : GameLib.Component.GRAPHICS_RUNTIME,
constructor : GameLib.D3.Light,
apiConstructor : GameLib.D3.API.Light
constructor : GameLib.D3.Shadow.Directional,
apiConstructor : GameLib.D3.API.Shadow.Directional
};
case 0xa : return {
name : 'GameLib.Plane',
@ -475,7 +479,12 @@ GameLib.Component.GetComponentInfo = function(number) {
constructor : GameLib.DomElement,
apiConstructor : GameLib.API.DomElement
};
case 0x1c : return null;
case 0x1c : return {
name : 'GameLib.D3.Shadow.Spot',
runtime : GameLib.Component.SHADOW_SPOT,
constructor : GameLib.D3.Shadow.Spot,
apiConstructor : GameLib.D3.API.Shadow.Spot
};
case 0x1d : return {
name : 'GameLib.Stats',
runtime : GameLib.Component.STATISTICS_RUNTIME,
@ -829,6 +838,30 @@ GameLib.Component.GetComponentInfo = function(number) {
constructor : GameLib.Socket.Cast,
apiConstructor : GameLib.API.Socket.Cast
};
case 0x58 : return {
name : 'GameLib.D3.Camera.Orthographic',
runtime : GameLib.Component.CAMERA_ORTHOGRAPHIC,
constructor : GameLib.D3.Camera.Orthographic,
apiConstructor : GameLib.D3.API.Camera.Orthographic
};
case 0x59 : return {
name : 'GameLib.D3.Camera.Stereo',
runtime : GameLib.Component.CAMERA_STEREO,
constructor : GameLib.D3.Camera.Stereo,
apiConstructor : GameLib.D3.API.Camera.Stereo
};
case 0x5a : return {
name : 'GameLib.D3.Camera.Cube',
runtime : GameLib.Component.CAMERA_CUBE,
constructor : GameLib.D3.Camera.Cube,
apiConstructor : GameLib.D3.API.Camera.Cube
};
case 0x5b : return {
name : 'GameLib.D3.Shadow',
runtime : GameLib.Component.SHADOW,
constructor : GameLib.D3.Shadow,
apiConstructor : GameLib.D3.API.Shadow
};
break;
}
@ -918,7 +951,20 @@ GameLib.Component.GetComponentConstructor = function(componentType) {
* @returns {*}
*/
GameLib.Component.prototype.toApiObject = function() {
return this.id;
var info = GameLib.Component.GetComponentInfo(this.componentType);
var apiConstructor = info.apiConstructor;
console.warn('implement generic component toApiObject');
var parameters = GameLib.Utils.GetParameters(apiConstructor);
throw new Error(parameters);
return this.id;
// return new info.apiConstructor()
};
GameLib.Component.prototype.processComponent = function(object) {

View File

@ -16,13 +16,17 @@ GameLib.API.Controls.D3.Editor = function(
};
}
if (GameLib.Utils.UndefinedOrNull(apiControls.controlsType)) {
apiControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_EDITOR;
}
if (GameLib.Utils.UndefinedOrNull(raycaster)) {
raycaster = new GameLib.D3.API.Raycaster();
}
this.raycaster = raycaster;
if (GameLib.Utils.UndefinedOrNull(camera)) {
camera = new GameLib.D3.API.Camera();
camera = null;
}
this.camera = camera;

View File

@ -12,6 +12,10 @@ GameLib.API.Controls.Keyboard = function(
};
}
if (GameLib.Utils.UndefinedOrNull(apiControls.controlsType)) {
apiControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD;
}
GameLib.API.Controls.call(
this,
apiControls.id,

View File

@ -12,6 +12,10 @@ GameLib.API.Controls.Mouse = function(
};
}
if (GameLib.Utils.UndefinedOrNull(apiControls.controlsType)) {
apiControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_MOUSE;
}
GameLib.API.Controls.call(
this,
apiControls.id,

View File

@ -14,6 +14,10 @@ GameLib.API.Controls.Touch = function(
};
}
if (GameLib.Utils.UndefinedOrNull(apiControls.controlsType)) {
apiControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_TOUCH;
}
if (GameLib.Utils.UndefinedOrNull(sensitivity)) {
sensitivity = 5;
}

View File

@ -0,0 +1,34 @@
/**
* GameLib.API.Number
* @constructor
* @param value
* @param grain
* @param min
* @param max
*/
GameLib.API.Number = function (
value,
grain,
min,
max
) {
if (GameLib.Utils.UndefinedOrNull(value)) {
value = 0;
}
this.value = value;
if (GameLib.Utils.UndefinedOrNull(grain)) {
grain = 0.1;
}
this.grain = grain;
if (GameLib.Utils.UndefinedOrNull(min)) {
min = 0;
}
this.min = min;
if (GameLib.Utils.UndefinedOrNull(max)) {
max = 100;
}
this.max = max;
};

View File

@ -26,7 +26,7 @@ GameLib.Controls = function (
var delayed = false;
if (this.controlsType === GameLib.API.Controls.CONTROLS_TYPE_EDITOR) {
if (apiControls.controlsType === GameLib.API.Controls.CONTROLS_TYPE_EDITOR) {
linkedObjects.raycaster = GameLib.D3.Raycaster;
linkedObjects.camera = GameLib.D3.Camera;

View File

@ -32,13 +32,6 @@ GameLib.Controls.D3.Editor = function (
);
}
if (this.camera instanceof GameLib.D3.API.Camera) {
this.camera = new GameLib.D3.Camera(
this.graphics,
this.camera
)
}
GameLib.Controls.call(
this,
apiEditorControls

View File

@ -0,0 +1,93 @@
/**
* GameLib.D3.API.Camera
* @param id
* @param name
* @param cameraType GameLib.D3.API.Camera.CAMERA_TYPE_*
* @param aspect
* @param position GameLib.API.Vector3
* @param lookAt GameLib.API.Vector3
* @param parentEntity
* @constructor
*/
GameLib.D3.API.Camera = function(
id,
name,
cameraType,
aspect,
position,
lookAt,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Camera (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(cameraType)) {
throw new Error('No camera type specified - do not call this constructor directly');
}
this.cameraType = cameraType;
if (GameLib.Utils.UndefinedOrNull(aspect)) {
//aspect = new GameLib.API.Number(1, 0.001, 0, 5);
aspect = 1;
}
this.aspect = aspect;
if (GameLib.Utils.UndefinedOrNull(position)) {
position = new GameLib.API.Vector3(
15,
15,
15
);
}
this.position = position;
if (GameLib.Utils.UndefinedOrNull(lookAt)) {
lookAt = new GameLib.API.Vector3(
0,
0,
0
);
}
this.lookAt = lookAt;
var componentType = null;
switch (this.cameraType) {
case GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE :
componentType = GameLib.Component.CAMERA_PERSPECTIVE;
break;
case GameLib.D3.API.Camera.CAMERA_TYPE_ORTHOGRAPHIC :
componentType = GameLib.Component.CAMERA_ORTHOGRAPHIC;
break;
case GameLib.D3.API.Camera.CAMERA_TYPE_STEREO :
componentType = GameLib.Component.CAMERA_STEREO;
break;
case GameLib.D3.API.Camera.CAMERA_TYPE_CUBE :
componentType = GameLib.Component.CAMERA_CUBE;
break;
default:
throw new Error('unsupported camera type: ' + this.cameraType);
}
GameLib.API.Component.call(
this,
componentType,
parentEntity
);
};
GameLib.D3.API.Camera.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.D3.API.Camera.prototype.constructor = GameLib.D3.API.Camera;
GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE = 0x1;
GameLib.D3.API.Camera.CAMERA_TYPE_ORTHOGRAPHIC = 0x2;
GameLib.D3.API.Camera.CAMERA_TYPE_STEREO = 0x3;
GameLib.D3.API.Camera.CAMERA_TYPE_CUBE = 0x4;

View File

@ -0,0 +1,67 @@
/**
* GameLib.D3.API.Camera.Cube
* @constructor
* @param apiCamera
* @param near
* @param far
* @param cubeResolution
* @param renderTarget
*/
GameLib.D3.API.Camera.Cube = function(
apiCamera,
near,
far,
cubeResolution,
renderTarget
) {
if (GameLib.Utils.UndefinedOrNull(apiCamera)) {
apiCamera = {
cameraType : GameLib.D3.API.Camera.CAMERA_TYPE_CUBE
};
}
if (GameLib.Utils.UndefinedOrNull(apiCamera.cameraType)) {
apiCamera.cameraType = GameLib.D3.API.Camera.CAMERA_TYPE_CUBE;
}
if (GameLib.Utils.UndefinedOrNull(near)) {
//near = new GameLib.API.Number(0.1, 0.001, 0.001, 2000);
near = 0.1;
}
this.near = near;
if (GameLib.Utils.UndefinedOrNull(far)) {
//far = new GameLib.API.Number(2000, 1, 1, 4000);
far = 2000;
}
this.far = far;
if (GameLib.Utils.UndefinedOrNull(cubeResolution)) {
//cubeResolution = new GameLib.API.Number(512, 64, 64, 8192);
cubeResolution = 512;
}
this.cubeResolution = cubeResolution;
if (GameLib.Utils.UndefinedOrNull(renderTarget)) {
renderTarget = null;
}
this.renderTarget = renderTarget;
/**
* CubeCamera's have hardcoded fov=90 and aspect=1
*/
GameLib.D3.API.Camera.call(
this,
apiCamera.id,
apiCamera.name,
apiCamera.cameraType,
1,
apiCamera.position,
apiCamera.lookAt,
apiCamera.parentEntity
);
};
GameLib.D3.API.Camera.Cube.prototype = Object.create(GameLib.D3.API.Camera.prototype);
GameLib.D3.API.Camera.Cube.prototype.constructor = GameLib.D3.API.Camera.Cube;

View File

@ -0,0 +1,120 @@
/**
* GameLib.D3.API.Camera.Orthographic
*
* OK - since the introduction of fixed aspect ratio's for our canvases, we only need to know
* the aspect ratio and width - then we calculate the left, right, up and down coords -
*
* for the Z space - we simply use the values in near and far - you should know what you are doing when you
* create an orthographic camera
*
* There are two ways to update the camera - one is by affecting the aspect ratio - the other is modifying the left,
* right, top and bottom values - this also affects the aspect ratio.
*
* In both modes - the camera is assumed to be at position 0,0,10 and facing direction 0,0,-1 (in the positive Z facing
* the negative Z direction seeing what happens around the origin)
*
* Also - the offset is always respected
*
* @constructor
* @param apiCamera
* @param width
* @param near
* @param far
* @param left
* @param right
* @param top
* @param bottom
* @param zoom
*/
GameLib.D3.API.Camera.Orthographic = function(
apiCamera,
width,
near,
far,
left,
right,
top,
bottom,
zoom
) {
if (GameLib.Utils.UndefinedOrNull(apiCamera)) {
apiCamera = {
cameraType : GameLib.D3.API.Camera.CAMERA_TYPE_ORTHOGRAPHIC
};
}
if (GameLib.Utils.UndefinedOrNull(apiCamera.cameraType)) {
apiCamera.cameraType = GameLib.D3.API.Camera.CAMERA_TYPE_ORTHOGRAPHIC;
}
if (GameLib.Utils.UndefinedOrNull(apiCamera.position)) {
apiCamera.position = new GameLib.API.Vector3(0,0,10);
}
if (GameLib.Utils.UndefinedOrNull(apiCamera.lookAt)) {
apiCamera.lookAt = new GameLib.API.Vector3(0,0,-1);
}
if (GameLib.Utils.UndefinedOrNull(width)) {
//width = GameLib.API.Number(10, 1, 1, 2000);
width = 10;
}
this.width = width;
if (GameLib.Utils.UndefinedOrNull(near)) {
//near = GameLib.API.Number(0.1, 0, 0.1, 2000);
near = 0.1;
}
this.near = near;
if (GameLib.Utils.UndefinedOrNull(far)) {
// far = GameLib.API.Number(2000, 0, 0.1, 4000);
far = 2000;
}
this.far = far;
if (GameLib.Utils.UndefinedOrNull(left)) {
// left = GameLib.API.Number(-5, 1, -2000, 0);
left = -5;
}
this.left = left;
if (GameLib.Utils.UndefinedOrNull(right)) {
//right = GameLib.API.Number(5, 1, 0, 2000);
right = 5;
}
this.right = right;
if (GameLib.Utils.UndefinedOrNull(top)) {
//top = GameLib.API.Number(5, 1, 0, 2000);
top = 5;
}
this.top = top;
if (GameLib.Utils.UndefinedOrNull(bottom)) {
// bottom = GameLib.API.Number(-5, 1, -2000, 0);
bottom = -5;
}
this.bottom = bottom;
if (GameLib.Utils.UndefinedOrNull(zoom)) {
// zoom = new GameLib.API.Number(1, 0.01, 0, 10);
zoom = 1;
}
this.zoom = zoom;
GameLib.D3.API.Camera.call(
this,
apiCamera.id,
apiCamera.name,
apiCamera.cameraType,
apiCamera.aspect,
apiCamera.position,
apiCamera.lookAt,
apiCamera.parentEntity
);
};
GameLib.D3.API.Camera.Orthographic.prototype = Object.create(GameLib.D3.API.Camera.prototype);
GameLib.D3.API.Camera.Orthographic.prototype.constructor = GameLib.D3.API.Camera.Orthographic;

View File

@ -0,0 +1,89 @@
/**
* GameLib.D3.API.Camera.Perspective
* @constructor
* @param apiCamera
* @param fov
* @param near
* @param far
* @param filmGauge
* @param filmOffset
* @param focus
* @param zoom
*/
GameLib.D3.API.Camera.Perspective = function(
apiCamera,
near,
far,
fov,
filmGauge,
filmOffset,
focus,
zoom
) {
if (GameLib.Utils.UndefinedOrNull(apiCamera)) {
apiCamera = {
cameraType : GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE
};
}
if (GameLib.Utils.UndefinedOrNull(apiCamera.cameraType)) {
apiCamera.cameraType = GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE;
}
if (GameLib.Utils.UndefinedOrNull(near)) {
// near = new GameLib.API.Number(0.1, 0.001, 0.001, 2000);
near = 0.1;
}
this.near = near;
if (GameLib.Utils.UndefinedOrNull(far)) {
// far = new GameLib.API.Number(2000, 1, 1, 4000);
far = 2000;
}
this.far = far;
if (GameLib.Utils.UndefinedOrNull(fov)) {
// fov = new GameLib.API.Number(50, 1, 0, 180);
fov = 50;
}
this.fov = fov;
if (GameLib.Utils.UndefinedOrNull(filmGauge)) {
// filmGauge = new GameLib.API.Number(35, 1, 0, 200);
filmGauge = 35;
}
this.filmGauge = filmGauge;
if (GameLib.Utils.UndefinedOrNull(filmOffset)) {
// filmOffset = new GameLib.API.Number(0, 1, 0, 200);
filmOffset = 0;
}
this.filmOffset = filmOffset;
if (GameLib.Utils.UndefinedOrNull(focus)) {
// focus = new GameLib.API.Number(10, 0.1, 0, 200);
focus = 10;
}
this.focus = focus;
if (GameLib.Utils.UndefinedOrNull(zoom)) {
// zoom = new GameLib.API.Number(1, 0.01, 0, 10);
zoom = 1;
}
this.zoom = zoom;
GameLib.D3.API.Camera.call(
this,
apiCamera.id,
apiCamera.name,
apiCamera.cameraType,
apiCamera.aspect,
apiCamera.position,
apiCamera.lookAt,
apiCamera.parentEntity
);
};
GameLib.D3.API.Camera.Perspective.prototype = Object.create(GameLib.D3.API.Camera.prototype);
GameLib.D3.API.Camera.Perspective.prototype.constructor = GameLib.D3.API.Camera.Perspective;

View File

@ -0,0 +1,55 @@
/**
* GameLib.D3.API.Camera.Stereo
* @constructor
* @param apiCamera
* @param eyeSep
* @param cameraL
* @param cameraR
*/
GameLib.D3.API.Camera.Stereo = function(
apiCamera,
eyeSep,
cameraL,
cameraR
) {
if (GameLib.Utils.UndefinedOrNull(apiCamera)) {
apiCamera = {
cameraType : GameLib.D3.API.Camera.CAMERA_TYPE_STEREO
};
}
if (GameLib.Utils.UndefinedOrNull(apiCamera.cameraType)) {
apiCamera.cameraType = GameLib.D3.API.Camera.CAMERA_TYPE_STEREO;
}
if (GameLib.Utils.UndefinedOrNull(eyeSep)) {
// eyeSep = new GameLib.API.Number(0.064, 0.0001, 0, 2);
eyeSep = 0.064;
}
this.eyeSep = eyeSep;
if (GameLib.Utils.UndefinedOrNull(cameraL)) {
cameraL = new GameLib.D3.API.Camera.Perspective();
}
this.cameraL = cameraL;
if (GameLib.Utils.UndefinedOrNull(cameraR)) {
cameraR = new GameLib.D3.API.Camera.Perspective();
}
this.cameraR = cameraR;
GameLib.D3.API.Camera.call(
this,
apiCamera.id,
apiCamera.name,
apiCamera.cameraType,
apiCamera.position,
apiCamera.aspect,
apiCamera.lookAt,
apiCamera.parentEntity
);
};
GameLib.D3.API.Camera.Stereo.prototype = Object.create(GameLib.D3.API.Camera.prototype);
GameLib.D3.API.Camera.Stereo.prototype.constructor = GameLib.D3.API.Camera.Stereo;

View File

@ -1,199 +0,0 @@
/**
* Raw Camera API object - should always correspond with the Camera Schema
* @param id
* @param name
* @param cameraType GameLib.D3.Camera.CAMERA_TYPE_*
* @param fov
* @param aspect
* @param near
* @param far
* @param position GameLib.API.Vector3
* @param lookAt GameLib.API.Vector3
* @param minX
* @param maxX
* @param minY
* @param maxY
* @param minZ
* @param maxZ
* @param offsetX
* @param offsetY
* @param quaternion GameLib.Quaternion
* @param eyeSeparation
* @param focalLength
* @param parentEntity
* @constructor
*/
GameLib.D3.API.Camera = function(
id,
cameraType,
name,
fov,
aspect,
near,
far,
position,
lookAt,
minX,
maxX,
minY,
maxY,
minZ,
maxZ,
offsetX,
offsetY,
quaternion,
eyeSeparation,
focalLength,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(cameraType)) {
cameraType = GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE;
}
this.cameraType = cameraType;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Camera (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(fov)) {
fov = 75;
}
this.fov = fov;
if (GameLib.Utils.UndefinedOrNull(aspect)) {
aspect = window.screen.availWidth / window.screen.availHeight;
}
this.aspect = aspect;
if (GameLib.Utils.UndefinedOrNull(near)) {
near = 0.01;
}
this.near = near;
if (GameLib.Utils.UndefinedOrNull(far)) {
far = 1000;
}
this.far = far;
if (GameLib.Utils.UndefinedOrNull(position)) {
position = new GameLib.API.Vector3(
15,
15,
15
);
}
this.position = position;
if (GameLib.Utils.UndefinedOrNull(quaternion)) {
quaternion = new GameLib.API.Quaternion();
}
this.quaternion = quaternion;
if (GameLib.Utils.UndefinedOrNull(lookAt)) {
lookAt = new GameLib.API.Vector3(
0,
0,
0
);
}
this.lookAt = lookAt;
if (GameLib.Utils.UndefinedOrNull(minX)) {
minX = -100;
}
this.minX = minX;
if (GameLib.Utils.UndefinedOrNull(maxX)) {
maxX = 100;
}
this.maxX = maxX;
if (GameLib.Utils.UndefinedOrNull(minY)) {
minY = -100;
}
this.minY = minY;
if (GameLib.Utils.UndefinedOrNull(maxY)) {
maxY = 100;
}
this.maxY = maxY;
if (GameLib.Utils.UndefinedOrNull(minZ)) {
minZ = -100;
}
this.minZ = minZ;
if (GameLib.Utils.UndefinedOrNull(maxZ)) {
maxZ = 100;
}
this.maxZ = maxZ;
if (GameLib.Utils.UndefinedOrNull(offsetX)) {
offsetX = 0;
}
this.offsetX = offsetX;
if (GameLib.Utils.UndefinedOrNull(offsetY)) {
offsetY = 0;
}
this.offsetY = offsetY;
if (GameLib.Utils.UndefinedOrNull(eyeSeparation)) {
eyeSeparation = 30;
}
this.eyeSeparation = eyeSeparation;
if (GameLib.Utils.UndefinedOrNull(focalLength)) {
focalLength = 150;
}
this.focalLength = focalLength;
GameLib.API.Component.call(
this,
GameLib.Component.CAMERA,
parentEntity
);
};
GameLib.D3.API.Camera.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.D3.API.Camera.prototype.constructor = GameLib.D3.API.Camera;
/**
* Creates an API camera from an Object camera
* @param objectCamera
* @constructor
*/
GameLib.D3.API.Camera.FromObject = function(objectCamera) {
return new GameLib.D3.API.Camera(
objectCamera.id,
objectCamera.cameraType,
objectCamera.name,
objectCamera.fov,
objectCamera.aspect,
objectCamera.near,
objectCamera.far,
GameLib.API.Vector3.FromObject(objectCamera.position),
GameLib.API.Vector3.FromObject(objectCamera.lookAt),
objectCamera.minX,
objectCamera.maxX,
objectCamera.minY,
objectCamera.maxY,
objectCamera.minZ,
objectCamera.maxZ,
objectCamera.offsetX,
objectCamera.offsetY,
GameLib.API.Quaternion.FromObject(objectCamera.quaternion),
objectCamera.eyeSeparation,
objectCamera.focalLength,
objectCamera.parentEntity
);
};

View File

@ -13,6 +13,10 @@ GameLib.D3.API.Light.Ambient = function(
};
}
if (GameLib.Utils.UndefinedOrNull(apiLight.lightType)) {
apiLight.lightType = GameLib.D3.API.Light.LIGHT_TYPE_AMBIENT;
}
GameLib.D3.API.Light.call(
this,
apiLight.id,

View File

@ -21,6 +21,10 @@ GameLib.D3.API.Light.Directional = function(
};
}
if (GameLib.Utils.UndefinedOrNull(apiLight.lightType)) {
apiLight.lightType = GameLib.D3.API.Light.LIGHT_TYPE_DIRECTIONAL;
}
if (GameLib.Utils.UndefinedOrNull(castShadow)) {
castShadow = false;
}
@ -34,6 +38,10 @@ GameLib.D3.API.Light.Directional = function(
}
this.position = position;
/**
* ThreeJS creates the shadow instance - we just create the gamelib object for it and update it later from the instance
* It's important not to create a shadow component, so we know it loaded from the API
*/
if (GameLib.Utils.UndefinedOrNull(shadow)) {
shadow = null;
}

View File

@ -2,13 +2,11 @@
* 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
) {
@ -19,10 +17,9 @@ GameLib.D3.API.Light.Hemisphere = function(
};
}
if (GameLib.Utils.UndefinedOrNull(castShadow)) {
castShadow = false;
if (GameLib.Utils.UndefinedOrNull(apiLight.lightType)) {
apiLight.lightType = GameLib.D3.API.Light.LIGHT_TYPE_HEMISPHERE;
}
this.castShadow = castShadow;
/**
* Light shines from the top

View File

@ -23,6 +23,10 @@ GameLib.D3.API.Light.Point = function(
};
}
if (GameLib.Utils.UndefinedOrNull(apiLight.lightType)) {
apiLight.lightType = GameLib.D3.API.Light.LIGHT_TYPE_POINT;
}
/**
* Light shines from the top
*/
@ -52,6 +56,9 @@ GameLib.D3.API.Light.Point = function(
}
this.power = power;
/**
* It's important not to create the shadow so our runtime component can know whether we loaded from API or not
*/
if (GameLib.Utils.UndefinedOrNull(shadow)) {
shadow = null;
}

View File

@ -27,6 +27,10 @@ GameLib.D3.API.Light.RectArea = function(
};
}
if (GameLib.Utils.UndefinedOrNull(apiLight.lightType)) {
apiLight.lightType = GameLib.D3.API.Light.LIGHT_TYPE_RECT_AREA;
}
/**
* Light shines from the top
*/

View File

@ -31,6 +31,10 @@ GameLib.D3.API.Light.Spot = function(
};
}
if (GameLib.Utils.UndefinedOrNull(apiLight.lightType)) {
apiLight.lightType = GameLib.D3.API.Light.LIGHT_TYPE_SPOT;
}
/**
* Light shines from the top
*/

View File

@ -305,23 +305,21 @@ GameLib.D3.API.Renderer = function (
this.clearColor = clearColor;
if (GameLib.Utils.UndefinedOrNull(camera)) {
camera = new GameLib.D3.API.Camera(
null,
GameLib.D3.API.Camera.PERSPECTIVE_CAMERA,
'Render Camera',
null,
this.width / this.height
camera = new GameLib.D3.API.Camera.Perspective(
{
name : 'Render Camera',
aspect : this.width / this.height
}
);
}
this.camera = camera;
if (GameLib.Utils.UndefinedOrNull(editCamera)) {
editCamera = new GameLib.D3.API.Camera(
null,
GameLib.D3.API.Camera.PERSPECTIVE_CAMERA,
'Edit Camera',
null,
this.width / this.height
editCamera = new GameLib.D3.API.Camera.Perspective(
{
name : 'Edit Camera',
aspect : this.width / this.height
}
);
}
this.editCamera = editCamera;

View File

@ -49,7 +49,7 @@ GameLib.D3.API.Scene = function(
this.meshes = meshes;
if (GameLib.Utils.UndefinedOrNull(lights)) {
lights = [new GameLib.D3.API.Light()];
lights = [];
}
this.lights = lights;

View File

@ -0,0 +1,98 @@
/**
* GameLib.D3.API.Shadow
* @param id
* @param name
* @param shadowType
* @param camera
* @param bias
* @param mapSize
* @param radius
* @param parentEntity
* @constructor
*/
GameLib.D3.API.Shadow = function(
id,
name,
shadowType,
camera,
bias,
mapSize,
radius,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
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(camera)) {
camera = new GameLib.D3.API.Camera.Perspective(
{
aspect : 1
},
0.5,
500,
90
);
}
this.camera = camera;
if (GameLib.Utils.UndefinedOrNull(bias)) {
bias = 0;//new GameLib.API.Number(0, 0.0001, -0.1, 0.1);
}
this.bias = bias;
if (GameLib.Utils.UndefinedOrNull(mapSize)) {
mapSize = new GameLib.API.Vector2(512, 512);
}
this.mapSize = mapSize;
if (GameLib.Utils.UndefinedOrNull(radius)) {
radius = 1;//new GameLib.API.Number(1, 0.01, 0, 5);
}
this.radius = radius;
var componentType = null;
switch (this.shadowType) {
case GameLib.D3.API.Shadow.SHADOW_TYPE_NORMAL :
componentType = GameLib.Component.SHADOW;
break;
case GameLib.D3.API.Shadow.SHADOW_TYPE_DIRECTIONAL :
componentType = GameLib.Component.SHADOW_DIRECTIONAL;
break;
case GameLib.D3.API.Shadow.SHADOW_TYPE_SPOT :
componentType = GameLib.Component.SHADOW_SPOT;
break;
default :
console.error('could not determine shadow component type');
}
GameLib.API.Component.call(
this,
componentType,
parentEntity
);
};
GameLib.D3.API.Shadow.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.D3.API.Shadow.prototype.constructor = GameLib.D3.API.Shadow;
/**
* Shadow Types
* @type {number}
*/
GameLib.D3.API.Shadow.SHADOW_TYPE_NORMAL = 0x1;
GameLib.D3.API.Shadow.SHADOW_TYPE_DIRECTIONAL = 0x2;
GameLib.D3.API.Shadow.SHADOW_TYPE_SPOT = 0x3;

View File

@ -0,0 +1,47 @@
/**
* GameLib.D3.API.Shadow
* @constructor
* @param apiDirectionalShadow
*/
GameLib.D3.API.Shadow.Directional = function(
apiDirectionalShadow
) {
if (GameLib.Utils.UndefinedOrNull(apiDirectionalShadow)) {
apiDirectionalShadow = {
shadowType : GameLib.D3.API.Shadow.SHADOW_TYPE_DIRECTIONAL
};
}
if (GameLib.Utils.UndefinedOrNull(apiDirectionalShadow.shadowType)) {
apiDirectionalShadow.shadowType = GameLib.D3.API.Shadow.SHADOW_TYPE_DIRECTIONAL;
}
if (GameLib.Utils.UndefinedOrNull(apiDirectionalShadow.camera)) {
apiDirectionalShadow.camera = new GameLib.D3.API.Camera.Orthographic(
null,
10,
0.5,
500,
-5,
5,
5,
-5
)
}
GameLib.API.Shadow.call(
this,
apiDirectionalShadow.id,
apiDirectionalShadow.name,
apiDirectionalShadow.shadowType,
apiDirectionalShadow.camera,
apiDirectionalShadow.bias,
apiDirectionalShadow.mapSize,
apiDirectionalShadow.radius,
apiDirectionalShadow.parentEntity
);
};
GameLib.D3.API.Shadow.Directional.prototype = Object.create(GameLib.D3.API.Shadow.prototype);
GameLib.D3.API.Shadow.Directional.prototype.constructor = GameLib.D3.API.Shadow.Directional;

View File

@ -0,0 +1,47 @@
/**
* GameLib.D3.API.Shadow
* @constructor
* @param apiSpotShadow
*/
GameLib.D3.API.Shadow.Spot = function(
apiSpotShadow
) {
if (GameLib.Utils.UndefinedOrNull(apiSpotShadow)) {
apiSpotShadow = {
shadowType : GameLib.D3.API.Shadow.SHADOW_TYPE_SPOT
};
}
if (GameLib.Utils.UndefinedOrNull(apiSpotShadow.shadowType)) {
apiSpotShadow.shadowType = GameLib.D3.API.Shadow.SHADOW_TYPE_SPOT;
}
/**
* Most of these properties will be updated depending on the parent light (mapSize = aspect, angle = fov and distance = far)
*/
if (GameLib.Utils.UndefinedOrNull(apiSpotShadow.camera)) {
apiSpotShadow.camera = new GameLib.D3.API.Camera.Perspective(
{
name : 'Spot Shadow Camera'
},
0.5,
500
)
}
GameLib.API.Shadow.call(
this,
apiSpotShadow.id,
apiSpotShadow.name,
apiSpotShadow.shadowType,
apiSpotShadow.camera,
apiSpotShadow.bias,
apiSpotShadow.mapSize,
apiSpotShadow.radius,
apiSpotShadow.parentEntity
);
};
GameLib.D3.API.Shadow.Spot.prototype = Object.create(GameLib.D3.API.Shadow.prototype);
GameLib.D3.API.Shadow.Spot.prototype.constructor = GameLib.D3.API.Shadow.Spot;

View File

@ -29,13 +29,6 @@ GameLib.D3.Audio = function(
apiAudio.parentEntity
);
if (this.camera instanceof GameLib.D3.API.Camera) {
this.camera = new GameLib.D3.Camera(
this.graphics,
this.camera
)
}
GameLib.Component.call(
this,
{

202
src/game-lib-d3-camera-a.js Normal file
View File

@ -0,0 +1,202 @@
/**
* GameLib.D3.Camera
* @param graphics GameLib.GraphicsRuntime
* @param apiCamera GameLib.D3.API.Camera
* @constructor
*/
GameLib.D3.Camera = function(
graphics,
apiCamera
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiCamera)) {
apiCamera = {};
}
GameLib.D3.API.Camera.call(
this,
apiCamera.id,
apiCamera.name,
apiCamera.cameraType,
apiCamera.aspect,
apiCamera.position,
apiCamera.lookAt,
apiCamera.parentEntity
);
this.position = new GameLib.Vector3(
graphics,
this.position,
this
);
this.lookAt = new GameLib.Vector3(
graphics,
this.lookAt,
this
);
//
// this.aspect = new GameLib.Number(
// this.aspect,
// this
// );
var linkedObjects = {};
switch (apiCamera.cameraType) {
case GameLib.D3.API.Camera.CAMERA_TYPE_CUBE :
linkedObjects.renderTarget = GameLib.D3.RenderTarget;
break;
case GameLib.D3.API.Camera.CAMERA_TYPE_STEREO :
linkedObjects.cameraL = GameLib.D3.Camera.Perspective;
linkedObjects.cameraR = GameLib.D3.Camera.Perspective;
break;
default :
break;
}
GameLib.Component.call(
this,
linkedObjects
);
};
GameLib.D3.Camera.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.Camera.prototype.constructor = GameLib.D3.Camera;
/**
* Creates a camera instance of 'graphics' type (only THREE for now)
* @returns {THREE.Camera}
*/
GameLib.D3.Camera.prototype.createInstance = function() {
this.instance.position.x = this.position.x;
this.instance.position.y = this.position.y;
this.instance.position.z = this.position.z;
/**
* Not all implementations of camera has aspect ratio, we, however do have an aspect ratio for all our cameras
*/
if (GameLib.Utils.Defined(this.instance.aspect)) {
this.instance.aspect = this.aspect;
}
this.instance.lookAt(this.lookAt.instance);
this.instance.updateProjectionMatrix();
GameLib.Component.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Camera.prototype.updateInstance = function(property) {
if (GameLib.Utils.UndefinedOrNull(property)) {
console.warn('no camera property specified for : ' + this.name);
}
if (property === 'cameraType') {
this.remove();
var args = [this.graphics, {
id : this.id,
name : this.name
}];
if (this.cameraType === GameLib.D3.API.Camera.CAMERA_TYPE_STEREO) {
GameLib.D3.Camera.Stereo.apply(this, args);
}
if (this.cameraType === GameLib.D3.API.Camera.CAMERA_TYPE_CUBE) {
GameLib.D3.Camera.Cube.apply(this, args);
}
if (this.cameraType === GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE) {
GameLib.D3.Camera.Perspective.apply(this, args);
}
if (this.cameraType === GameLib.D3.API.Camera.CAMERA_TYPE_ORTHOGRAPHIC) {
GameLib.D3.Camera.Orthographic.apply(this, args);
}
return;
}
if (property === 'aspect') {
if (GameLib.Utils.Defined(this.instance.aspect)) {
this.instance.aspect = this.aspect;
} else {
console.warn('updating the aspect ratio of this type of camera has no effect.');
}
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;
this.instance.updateProjectionMatrix();
return;
}
if (property === 'lookAt') {
this.lookAt.instance.x = this.lookAt.x;
this.lookAt.instance.y = this.lookAt.y;
this.lookAt.instance.z = this.lookAt.z;
this.instance.lookAt(this.lookAt.instance);
this.instance.updateProjectionMatrix();
return;
}
};
/**
* Resize default
* @param width
* @param height
*/
// GameLib.D3.Camera.prototype.resize = function(width, height) {
// camera.aspect = width / height;
// camera.updateInstance();
// };
/**
* Converts a GameLib.D3.Camera to a new GameLib.D3.API.Camera
* @returns {GameLib.D3.API.Camera}
*/
GameLib.D3.Camera.prototype.toApiObject = function() {
return new GameLib.D3.API.Camera(
this.id,
this.name,
this.cameraType,
this.aspect.toApiObject(),
this.position.toApiObject(),
this.lookAt.toApiObject(),
GameLib.Utils.IdOrNull(this.parentEntity)
);
};
GameLib.D3.Camera.prototype.updateFromInstance = function() {
this.aspect = this.instance.aspect;
this.position.x = this.instance.position.x;
this.position.y = this.instance.position.y;
this.position.z = this.instance.position.z;
if (this.instance.target) {
this.lookAt.x = this.instance.target.position.x;
this.lookAt.y = this.instance.target.position.y;
this.lookAt.z = this.instance.target.position.z;
} else {
console.warn('todo: update lookAt somehow...');
}
};

View File

@ -0,0 +1,140 @@
/**
* GameLib.D3.Camera.Cube
* @param graphics GameLib.GraphicsRuntime
* @param apiCubeCamera
* @constructor
*/
GameLib.D3.Camera.Cube = function(
graphics,
apiCubeCamera
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiCubeCamera)) {
apiCubeCamera = {
cameraType : GameLib.D3.API.Camera.CAMERA_TYPE_CUBE
};
}
GameLib.D3.API.Camera.Cube.call(
this,
apiCubeCamera,
apiCubeCamera.near,
apiCubeCamera.far,
apiCubeCamera.cubeResolution,
apiCubeCamera.renderTarget
);
// this.near = new GameLib.Number(
// this.near,
// this
// );
//
// this.far = new GameLib.Number(
// this.far,
// this
// );
//
// this.cubeResolution = new GameLib.Number(
// this.cubeResolution,
// this
// );
GameLib.D3.Camera.call(
this,
this.graphics,
apiCubeCamera
);
};
GameLib.D3.Camera.Cube.prototype = Object.create(GameLib.D3.Camera.prototype);
GameLib.D3.Camera.Cube.prototype.constructor = GameLib.D3.Camera.Cube;
/**
* Creates a camera instance
* @returns {*}
*/
GameLib.D3.Camera.Cube.prototype.createInstance = function() {
this.instance = new THREE.CubeCamera(
this.near,
this.far,
this.cubeResolution
);
if (this.renderTarget && this.renderTarget.instance) {
this.instance.renderTarget = this.renderTarget.instance;
}
GameLib.D3.Camera.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Camera.Cube.prototype.updateInstance = function(property) {
if (property === 'aspect') {
console.warn('changing the aspect ratio of a cube camera has no effect - its always 1');
return;
}
if (property === 'fov') {
console.warn('changing the fov of a cube camera has no effect - its always 90');
return;
}
if (property === 'near') {
this.instance.near = this.near;
return;
}
if (property === 'far') {
this.instance.far = this.far;
return;
}
if (property === 'cubeResolution') {
this.instance.cubeResolution = this.cubeResolution;
return;
}
if (property === 'renderTarget') {
this.instance.renderTarget = this.renderTarget.instance;
return;
}
GameLib.D3.Camera.prototype.updateInstance.call(this, property);
};
/**
* Converts a GameLib.D3.Camera to a GameLib.D3.API.Camera
* @returns {GameLib.D3.API.Camera}
*/
GameLib.D3.Camera.Cube.prototype.toApiObject = function() {
var apiCamera = GameLib.D3.Camera.prototype.toApiObject.call(this);
var apiCubeCamera = new GameLib.D3.API.Camera.Cube(
apiCamera,
this.near,
this.far,
this.cubeResolution,
GameLib.Utils.IdOrNull(this.renderTarget)
);
return apiCubeCamera;
};
GameLib.D3.Camera.Cube.prototype.updateFromInstance = function() {
this.near = this.instance.near;
this.far = this.instance.far;
this.cubeResolution = this.instance.cubeResolution;
console.warn('todo: implement renderTarget updateFromInstance');
GameLib.D3.Camera.prototype.updateFromInstance.call(this);
};

View File

@ -0,0 +1,192 @@
/**
* GameLib.D3.Camera.Orthographic
* @param graphics GameLib.GraphicsRuntime
* @param apiOrthographicCamera
* @constructor
*/
GameLib.D3.Camera.Orthographic = function(
graphics,
apiOrthographicCamera
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiOrthographicCamera)) {
apiOrthographicCamera = {
cameraType : GameLib.D3.API.Camera.CAMERA_TYPE_ORTHOGRAPHIC,
position : GameLib.API.Vector3(0,0,10),
lookAt: GameLib.API.Vector3(0,0,-1)
};
}
GameLib.D3.API.Camera.Orthographic.call(
this,
apiOrthographicCamera,
apiOrthographicCamera.width,
apiOrthographicCamera.near,
apiOrthographicCamera.far,
apiOrthographicCamera.left,
apiOrthographicCamera.right,
apiOrthographicCamera.top,
apiOrthographicCamera.bottom,
apiOrthographicCamera.zoom
);
//
// this.width = new GameLib.Number(
// this.width,
// this
// );
//
// this.near = new GameLib.Number(
// this.near,
// this
// );
//
// this.far = new GameLib.Number(
// this.far,
// this
// );
//
// this.left = new GameLib.Number(
// this.left,
// this
// );
//
// this.right = new GameLib.Number(
// this.right,
// this
// );
//
// this.top = new GameLib.Number(
// this.top,
// this
// );
//
// this.bottom = new GameLib.Number(
// this.bottom,
// this
// );
//
// this.zoom = new GameLib.Number(
// this.zoom,
// this
// );
GameLib.D3.Camera.call(
this,
this.graphics,
apiOrthographicCamera
);
};
GameLib.D3.Camera.Orthographic.prototype = Object.create(GameLib.D3.Camera.prototype);
GameLib.D3.Camera.Orthographic.prototype.constructor = GameLib.D3.Camera.Orthographic;
/**
* Creates a camera instance
* @returns {*}
*/
GameLib.D3.Camera.Orthographic.prototype.createInstance = function() {
this.instance = new THREE.OrthographicCamera(
this.left,
this.right,
this.top,
this.bottom,
this.near,
this.far
);
GameLib.D3.Camera.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Camera.Orthographic.prototype.updateInstance = function(property) {
var width, height;
if (
property === 'width' ||
property === 'aspect'
) {
if (!this.fixedAspectRatio) {
console.warn('changing the aspect ratio when this camera is not in fixedAspectRatio mode has no effect');
return;
}
height = this.width / this.aspect;
this.left = this.width / -2;
this.right = this.width / 2;
this.top = height / 2;
this.bottom = height / -2;
this.instance.left = this.left;
this.instance.right = this.right;
this.instance.top = this.top;
this.instance.bottom = this.bottom;
return;
}
if (
property === 'left' ||
property === 'right' ||
property === 'top' ||
property === 'bottom'
) {
this.instance.left = this.left;
this.instance.right = this.right;
this.instance.top = this.top;
this.instance.bottom = this.bottom;
width = this.right - this.left;
height = this.top - this.bottom;
this.aspect = width / height;
return;
}
GameLib.D3.Camera.prototype.updateInstance.call(this, property);
};
/**
* Converts a GameLib.D3.Camera to a GameLib.D3.API.Camera
* @returns {GameLib.D3.API.Camera}
*/
GameLib.D3.Camera.Orthographic.prototype.toApiObject = function() {
var apiCamera = GameLib.D3.Camera.prototype.toApiObject.call(this);
var apiOrthographicCamera = new GameLib.D3.API.Camera.Orthographic(
apiCamera,
this.width,
this.near,
this.far,
this.left,
this.right,
this.top,
this.bottom,
this.zoom
);
return apiOrthographicCamera;
};
GameLib.D3.Camera.Orthographic.prototype.updateFromInstance = function() {
this.width = this.instance.right - this.instance.left;
this.near = this.instance.near;
this.far = this.instance.far;
this.left = this.instance.left;
this.right = this.instance.right;
this.top = this.instance.top;
this.bottom = this.instance.bottom;
this.zoom = this.instance.zoom;
GameLib.D3.Camera.prototype.updateFromInstance.call(this);
};

View File

@ -0,0 +1,179 @@
/**
* GameLib.D3.Camera.Perspective
* @param graphics GameLib.GraphicsRuntime
* @param apiPerspectiveCamera
* @constructor
*/
GameLib.D3.Camera.Perspective = function(
graphics,
apiPerspectiveCamera
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiPerspectiveCamera)) {
apiPerspectiveCamera = {
cameraType : GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE
};
}
GameLib.D3.API.Camera.Perspective.call(
this,
apiPerspectiveCamera,
apiPerspectiveCamera.near,
apiPerspectiveCamera.far,
apiPerspectiveCamera.fov,
apiPerspectiveCamera.filmGauge,
apiPerspectiveCamera.filmOffset,
apiPerspectiveCamera.focus,
apiPerspectiveCamera.zoom
);
// this.near = new GameLib.Number(
// this.near,
// this
// );
//
// this.far = new GameLib.Number(
// this.far,
// this
// );
//
// this.fov = new GameLib.Number(
// this.fov,
// this
// );
//
// this.filmGauge = new GameLib.Number(
// this.filmGauge,
// this
// );
//
// this.filmOffset = new GameLib.Number(
// this.filmOffset,
// this
// );
//
// this.focus = new GameLib.Number(
// this.focus,
// this
// );
//
// this.zoom = new GameLib.Number(
// this.zoom,
// this
// );
GameLib.D3.Camera.call(
this,
this.graphics,
apiPerspectiveCamera
);
};
GameLib.D3.Camera.Perspective.prototype = Object.create(GameLib.D3.Camera.prototype);
GameLib.D3.Camera.Perspective.prototype.constructor = GameLib.D3.Camera.Perspective;
/**
* Creates a camera instance
* @returns {*}
*/
GameLib.D3.Camera.Perspective.prototype.createInstance = function() {
this.instance = new THREE.PerspectiveCamera(
this.fov,
this.aspect,
this.near,
this.far
);
this.instance.filmGauge = this.filmGauge;
this.instance.filmOffset = this.filmOffset;
this.instance.focus = this.focus;
this.instance.zoom = this.zoom;
GameLib.D3.Camera.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Camera.Perspective.prototype.updateInstance = function(property) {
if (property === 'aspect') {
this.instance.aspect = this.aspect;
return;
}
if (property === 'near') {
this.instance.near = this.near;
return;
}
if (property === 'far') {
this.instance.far = this.far;
return;
}
if (property === 'fov') {
this.instance.fov = this.fov;
return;
}
if (property === 'filmGauge') {
this.instance.filmGauge = this.filmGauge;
return;
}
if (property === 'filmOffset') {
this.instance.filmOffset = this.filmOffset;
return;
}
if (property === 'focus') {
this.instance.focus = this.focus;
return;
}
if (property === 'zoom') {
this.instance.zoom = this.zoom;
return;
}
GameLib.D3.Camera.prototype.updateInstance.call(this, property);
};
/**
* Converts a GameLib.D3.Camera to a GameLib.D3.API.Camera
* @returns {GameLib.D3.API.Camera}
*/
GameLib.D3.Camera.Perspective.prototype.toApiObject = function() {
var apiCamera = GameLib.D3.Camera.prototype.toApiObject.call(this);
var apiPerspectiveCamera = new GameLib.D3.API.Camera.Perspective(
apiCamera,
this.near,
this.far,
this.fov,
this.filmGauge,
this.filmOffset,
this.focus,
this.zoom
);
return apiPerspectiveCamera;
};
GameLib.D3.Camera.Perspective.prototype.updateFromInstance = function() {
this.near = this.instance.near;
this.far = this.instance.far;
this.fov = this.instance.fov;
this.filmGauge = this.instance.filmGauge;
this.filmOffset = this.instance.filmOffset;
this.focus = this.instance.focus;
this.zoom = this.instance.zoom;
GameLib.D3.Camera.prototype.updateFromInstance.call(this);
};

View File

@ -0,0 +1,130 @@
/**
* GameLib.D3.Camera.Stereo
* @param graphics GameLib.GraphicsRuntime
* @param apiStereoCamera
* @constructor
*/
GameLib.D3.Camera.Stereo = function(
graphics,
apiStereoCamera
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiStereoCamera)) {
apiStereoCamera = {
cameraType : GameLib.D3.API.Camera.CAMERA_TYPE_STEREO
};
}
GameLib.D3.API.Camera.Stereo.call(
this,
apiStereoCamera,
apiStereoCamera.eyeSep,
apiStereoCamera.cameraL,
apiStereoCamera.cameraR
);
if (this.cameraL instanceof GameLib.D3.API.Camera.Perspective) {
this.cameraL = new GameLib.D3.Camera.Perspective(
this.graphics,
this.cameraL
);
}
if (this.cameraR instanceof GameLib.D3.API.Camera.Perspective) {
this.cameraR = new GameLib.D3.Camera.Perspective(
this.graphics,
this.cameraR
);
}
//
// this.eyeSep = new GameLib.Number(
// this.eyeSep,
// this
// );
GameLib.D3.Camera.call(
this,
this.graphics,
apiStereoCamera
);
};
GameLib.D3.Camera.Stereo.prototype = Object.create(GameLib.D3.Camera.prototype);
GameLib.D3.Camera.Stereo.prototype.constructor = GameLib.D3.Camera.Stereo;
/**
* Creates a camera instance
* @returns {*}
*/
GameLib.D3.Camera.Stereo.prototype.createInstance = function() {
this.instance = new THREE.StereoCamera();
this.instance.aspect = this.aspect;
this.instance.eyeSep = this.eyeSep;
GameLib.D3.Camera.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Camera.Stereo.prototype.updateInstance = function(property) {
if (property === 'eyeSep') {
this.instance.eyeSep = this.eyeSep;
return;
}
if (property === 'aspect') {
this.instance.aspect = this.aspect;
return;
}
if (property === 'cameraL') {
console.warn('update stereo camera cameraL instance');
return;
}
if (property === 'cameraR') {
console.warn('update stereo camera cameraR instance');
return;
}
GameLib.D3.Camera.prototype.updateInstance.call(this, property);
};
/**
* Converts a GameLib.D3.Camera to a GameLib.D3.API.Camera
* @returns {GameLib.D3.API.Camera}
*/
GameLib.D3.Camera.Stereo.prototype.toApiObject = function() {
var apiCamera = GameLib.D3.Camera.prototype.toApiObject.call(this);
var apiStereoCamera = new GameLib.D3.API.Camera.Stereo(
apiCamera,
this.eyeSep,
GameLib.Utils.IdOrNull(this.cameraL),
GameLib.Utils.IdOrNull(this.cameraR)
);
return apiStereoCamera;
};
GameLib.D3.Camera.Stereo.prototype.updateFromInstance = function() {
this.eyeSep = this.instance.eyeSep;
this.cameraL.instance = this.instance.cameraL;
this.cameraL.updateFromInstance();
this.cameraR.instance = this.instance.cameraR;
this.cameraR.updateFromInstance();
GameLib.D3.Camera.prototype.updateFromInstance.call(this);
};

View File

@ -1,275 +0,0 @@
/**
* Creates a Camera object
* @param graphics GameLib.GraphicsRuntime
* @param apiCamera GameLib.D3.API.Camera
* @constructor
*/
GameLib.D3.Camera = function(
graphics,
apiCamera
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiCamera)) {
apiCamera = {};
}
GameLib.D3.API.Camera.call(
this,
apiCamera.id,
apiCamera.cameraType,
apiCamera.name,
apiCamera.fov,
apiCamera.aspect,
apiCamera.near,
apiCamera.far,
apiCamera.position,
apiCamera.lookAt,
apiCamera.minX,
apiCamera.maxX,
apiCamera.minY,
apiCamera.maxY,
apiCamera.minZ,
apiCamera.maxZ,
apiCamera.offsetX,
apiCamera.offsetY,
apiCamera.quaternion,
apiCamera.eyeSeparation,
apiCamera.focalLength,
apiCamera.parentEntity
);
this.position = new GameLib.Vector3(
graphics,
this.position,
this
);
this.quaternion = new GameLib.Quaternion(
graphics,
this.quaternion,
this
);
this.lookAt = new GameLib.Vector3(
graphics,
this.lookAt,
this
);
GameLib.Component.call(
this,
GameLib.Component.CAMERA
);
} ;
GameLib.D3.Camera.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.Camera.prototype.constructor = GameLib.D3.Camera;
GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE = 0x1;
GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL = 0x2;
GameLib.D3.Camera.CAMERA_TYPE_STEREO = 0x3;
/**
* Creates a camera instance of 'graphics' type (only THREE for now)
* @returns {THREE.Camera}
*/
GameLib.D3.Camera.prototype.createInstance = function() {
if (this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE ) {
this.instance = new THREE.PerspectiveCamera(
this.fov,
this.aspect,
this.near,
this.far
);
} else if (this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL) {
this.instance = new THREE.OrthographicCamera(
this.minX + this.offsetX,
this.maxX + this.offsetX,
this.maxY,
this.minY,
this.minZ,
this.maxZ
);
} else if (this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_STEREO) {
this.instance = new THREE.StereoCamera();
} else {
throw new Error('unsupported camera type : ' + this.cameraType);
}
this.instance.position.x = this.position.x;
this.instance.position.y = this.position.y;
this.instance.position.z = this.position.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.lookAt(this.lookAt.instance);
this.instance.updateProjectionMatrix();
GameLib.Component.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Camera.prototype.updateInstance = function(property) {
if (GameLib.Utils.UndefinedOrNull(property)) {
console.warn('no camera property specified for : ' + this.name);
}
if (property === 'cameraType') {
if (
this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL &&
!(this.instance instanceof THREE.OrthographicCamera)
) {
this.createInstance();
}
if (
this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE &&
!(this.instance instanceof THREE.PerspectiveCamera)
) {
this.createInstance();
}
}
if (
property === 'aspect' ||
property === 'minX' ||
property === 'maxX' ||
property === 'minY' ||
property === 'maxY' ||
property === 'minZ' ||
property === 'maxZ' ||
property === 'offsetX' ||
property === 'offsetY' ||
property === 'fov' ||
property === 'near' ||
property === 'far' ||
property === 'eyeSeparation' ||
property === 'focalLength'
) {
if (this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL) {
this.minX = this.aspect * this.minY;
this.maxX = this.aspect * this.maxY;
this.instance.left = this.minX + this.offsetX;
this.instance.right = this.maxX + this.offsetX;
this.instance.bottom = this.minY + this.offsetY;
this.instance.top = this.maxY + this.offsetY;
this.instance.near = this.minZ;
this.instance.far = this.maxZ;
}
if (
this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE ||
this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_STEREO
) {
this.instance.fov = this.fov;
this.instance.aspect = this.aspect;
this.instance.near = this.near;
this.instance.far = this.far;
}
if (this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_STEREO) {
this.instance.eyeSeparation = this.eyeSeparation;
this.instance.focalLength = this.focalLength;
this.instance.update(this.instance);
}
}
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 === '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 === 'lookAt') {
this.lookAt.instance.x = this.lookAt.x;
this.lookAt.instance.y = this.lookAt.y;
this.lookAt.instance.z = this.lookAt.z;
this.instance.lookAt(this.lookAt.instance);
}
this.instance.updateProjectionMatrix();
};
/**
* Resize default
* @param width
* @param height
*/
GameLib.D3.Camera.prototype.resize = function(width, height) {
camera.aspect = width / height;
camera.updateInstance();
};
/**
* Converts a GameLib.D3.Camera to a new GameLib.D3.API.Camera
* @returns {GameLib.D3.API.Camera}
*/
GameLib.D3.Camera.prototype.toApiObject = function() {
return new GameLib.D3.API.Camera(
this.id,
this.cameraType,
this.name,
this.fov,
this.aspect,
this.near,
this.far,
this.position.toApiObject(),
this.lookAt.toApiObject(),
this.minX,
this.maxX,
this.minY,
this.maxY,
this.minZ,
this.maxZ,
this.offsetX,
this.offsetY,
this.quaternion.toApiObject(),
this.eyeSeparation,
this.focalLength,
GameLib.Utils.IdOrNull(this.parentEntity)
);
};
/**
* Converts from an Object Camera to a GameLib.D3.Camera
* @param graphics GameLib.GraphicsRuntime
* @param objectCamera Object
* @returns {GameLib.D3.Camera}
* @constructor
*/
GameLib.D3.Camera.FromObject = function(graphics, objectCamera) {
var apiCamera = GameLib.D3.API.Camera.FromObject(objectCamera);
return new GameLib.D3.Camera(
graphics,
apiCamera
);
};

View File

@ -1,5 +1,5 @@
/**
* Light Superset - The apiLight properties get moved into the Light object itself, and then the instance is created
* GameLib.D3.Light
* @param graphics GameLib.GraphicsRuntime
* @param apiLight GameLib.D3.API.Light
* @constructor
@ -13,7 +13,7 @@ GameLib.D3.Light = function(
apiLight = {};
}
GameLib.API.Controls.call(
GameLib.D3.API.Light.call(
this,
apiLight.id,
apiLight.name,
@ -28,17 +28,17 @@ GameLib.D3.Light = function(
'parentScene' : GameLib.D3.Scene
};
switch (this.componentType) {
switch (apiLight.lightType) {
case GameLib.Component.LIGHT_DIRECTIONAL :
case GameLib.Component.LIGHT_SPOT :
case GameLib.D3.API.Light.LIGHT_TYPE_DIRECTIONAL :
case GameLib.D3.API.Light.LIGHT_TYPE_SPOT :
linkedObjects.shadow = GameLib.D3.Shadow;
linkedObjects.target = GameLib.Component;
break;
case GameLib.Component.LIGHT_POINT :
case GameLib.D3.API.Light.LIGHT_TYPE_POINT :
linkedObjects.shadow = GameLib.D3.Shadow;
break;
case GameLib.Component.LIGHT_RECT_AREA :
case GameLib.D3.API.Light.LIGHT_TYPE_RECT_AREA :
linkedObjects.target = GameLib.Component;
break;
default:
@ -47,8 +47,7 @@ GameLib.D3.Light = function(
GameLib.Component.call(
this,
linkedObjects,
delayed
linkedObjects
);
};

View File

@ -1,5 +1,5 @@
/**
* Light Superset - The apiLight properties get moved into the Light object itself, and then the instance is created
* GameLib.D3.Light.Ambient
* @param graphics GameLib.GraphicsRuntime
* @param apiAmbientLight
* @constructor

View File

@ -1,5 +1,5 @@
/**
* Light Superset - The apiLight properties get moved into the Light object itself, and then the instance is created
* GameLib.D3.Light.Directional
* @param graphics GameLib.GraphicsRuntime
* @param apiDirectionalLight
* @constructor
@ -33,17 +33,13 @@ GameLib.D3.Light.Directional = function(
this
);
if (this.shadow instanceof GameLib.D3.API.Shadow) {
this.shadow = new GameLib.D3.Shadow(
if (this.shadow instanceof GameLib.D3.API.Shadow.Directional) {
this.shadow = new GameLib.D3.Shadow.Directional(
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,
@ -69,10 +65,43 @@ GameLib.D3.Light.Directional.prototype.createInstance = function() {
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;
/**
* Shadows work a little different - they are created internally by
* threejs - so we do it the other way around - we create our shadow object,
* and assign its properties from the one provided by threejs.
*
* If we already have a shadow object - it was loaded from the API, so we assign
* to our new shadow object the values from it.
*
* If we don't, we create a new one, and update it with the defaults from threejs
*/
if (this.shadow === null) {
/**
* This component is created during runtime
*/
this.shadow = new GameLib.D3.Shadow.Directional(this.graphics);
this.shadow.instance = this.instance.shadow;
this.shadow.updateFromInstance();
} else {
/**
* This component loaded from the API - update the instance with our settings
*/
this.shadow.instance = this.instance.shadow;
this.shadow.updateInstance('camera');
this.shadow.updateInstance('bias');
this.shadow.updateInstance('mapSize');
this.shadow.updateInstance('radius');
}
/**
* 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;
@ -102,12 +131,17 @@ GameLib.D3.Light.Directional.prototype.updateInstance = function(property, oldTa
}
if (property === 'shadow') {
this.instance.shadow = this.shadow.instance;
console.warn('experimental shadow change');
if (this.shadow && this.shadow.instance) {
this.instance.shadow = this.shadow.instance;
}
return;
}
if (property === 'target') {
console.warn('experimental target change');
if (typeof oldTarget === 'undefined') {
console.warn('oldTarget undefined');
}

View File

@ -1,5 +1,5 @@
/**
* Light Superset - The apiLight properties get moved into the Light object itself, and then the instance is created
* GameLib.D3.Light.Directional
* @param graphics GameLib.GraphicsRuntime
* @param apiHemisphereLight
* @constructor
@ -21,7 +21,6 @@ GameLib.D3.Light.Hemisphere = function(
GameLib.D3.API.Light.Hemisphere.call(
this,
apiHemisphereLight,
apiHemisphereLight.castShadow,
apiHemisphereLight.position,
apiHemisphereLight.groundColor
);
@ -63,18 +62,6 @@ GameLib.D3.Light.Hemisphere.prototype.createInstance = function() {
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);
};
@ -83,11 +70,6 @@ GameLib.D3.Light.Hemisphere.prototype.createInstance = function() {
*/
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;
@ -111,9 +93,8 @@ 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();
apiHemisphereLight.position = this.position.toApiObject();
apiHemisphereLight.groundColor = this.groundColor.toApiObject();
return apiHemisphereLight;
};

View File

@ -1,5 +1,5 @@
/**
* Light Superset - The apiLight properties get moved into the Light object itself, and then the instance is created
* GameLib.D3.Light.Point
* @param graphics GameLib.GraphicsRuntime
* @param apiPointLight
* @constructor
@ -68,10 +68,30 @@ GameLib.D3.Light.Point.prototype.createInstance = function() {
this.instance.distance = this.distance;
this.instance.power = this.power;
if (this.shadow && this.shadow.instance) {
this.instance.shadow = this.shadow.instance;
if (this.shadow === null) {
/**
* This component is created during runtime
*/
this.shadow = new GameLib.D3.Shadow(this.graphics);
this.shadow.instance = this.instance.shadow;
this.shadow.updateFromInstance();
} else {
/**
* This component loaded from the API - update the instance with our settings
*/
this.shadow.instance = this.instance.shadow;
this.shadow.updateInstance('camera');
this.shadow.updateInstance('bias');
this.shadow.updateInstance('mapSize');
this.shadow.updateInstance('radius');
}
GameLib.D3.Light.prototype.createInstance.call(this);
};
@ -103,6 +123,7 @@ GameLib.D3.Light.Point.prototype.updateInstance = function(property) {
}
if (property === 'shadow') {
console.warn('experimental shadow change');
if (this.shadow && this.shadow.instance) {
this.instance.shadow = this.shadow.instance;
}

View File

@ -1,5 +1,5 @@
/**
* Light Superset - The apiLight properties get moved into the Light object itself, and then the instance is created
* GameLib.D3.Light.RectArea
* @param graphics GameLib.GraphicsRuntime
* @param apiRectAreaLight
* @constructor
@ -36,10 +36,6 @@ GameLib.D3.Light.RectArea = function(
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,
@ -63,10 +59,10 @@ GameLib.D3.Light.RectArea.prototype.createInstance = function() {
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;
//TODO: not yet implemented
//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;
@ -87,7 +83,8 @@ GameLib.D3.Light.RectArea.prototype.createInstance = function() {
GameLib.D3.Light.RectArea.prototype.updateInstance = function(property, oldTarget) {
if (property === 'castShadow') {
this.instance.castShadow = this.castShadow;
console.warn('not yet implemented : castShadow');
// this.instance.castShadow = this.castShadow;
return;
}
@ -99,12 +96,14 @@ GameLib.D3.Light.RectArea.prototype.updateInstance = function(property, oldTarge
}
if (property === 'decay') {
this.instance.decay = this.decay;
console.warn('not yet implemented : decay');
// this.instance.decay = this.decay;
return;
}
if (property === 'distance') {
this.instance.distance = this.distance;
console.warn('not yet implemented : distance');
// this.instance.distance = this.distance;
return;
}

View File

@ -1,5 +1,5 @@
/**
* Light Superset - The apiLight properties get moved into the Light object itself, and then the instance is created
* GameLib.D3.Light.Spot
* @param graphics GameLib.GraphicsRuntime
* @param apiSpotLight
* @constructor
@ -38,17 +38,13 @@ GameLib.D3.Light.Spot = function(
this
);
if (this.shadow instanceof GameLib.D3.API.Shadow) {
this.shadow = new GameLib.D3.Shadow(
if (this.shadow instanceof GameLib.D3.API.Shadow.Spot) {
this.shadow = new GameLib.D3.Shadow.Spot(
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,
@ -79,8 +75,27 @@ GameLib.D3.Light.Spot.prototype.createInstance = function() {
this.instance.penumbra = this.penumbra;
this.instance.power = this.power;
if (this.shadow && this.shadow.instance) {
this.instance.shadow = this.shadow.instance;
if (this.shadow === null) {
/**
* This component is created during runtime
*/
this.shadow = new GameLib.D3.Shadow.Spot(this.graphics);
this.shadow.instance = this.instance.shadow;
this.shadow.updateFromInstance();
} else {
/**
* This component loaded from the API - update the instance with our settings
*/
this.shadow.instance = this.instance.shadow;
this.shadow.updateInstance('camera');
this.shadow.updateInstance('bias');
this.shadow.updateInstance('mapSize');
this.shadow.updateInstance('radius');
}
if (this.target && this.target.instance) {
@ -137,6 +152,7 @@ GameLib.D3.Light.Spot.prototype.updateInstance = function(property, oldTarget) {
}
if (property === 'shadow') {
console.warn('experimental shadow change');
if (this.shadow && this.shadow.instance) {
this.instance.shadow = this.shadow.instance;
}

View File

@ -44,13 +44,6 @@ GameLib.D3.ParticleEngine = function(
this
);
if (this.camera instanceof GameLib.D3.API.Camera) {
this.camera = new GameLib.D3.Camera(
graphics,
this.camera
)
}
if (this.templateParticle instanceof GameLib.D3.API.Particle) {
this.templateParticle = new GameLib.D3.Particle(
graphics,

View File

@ -108,15 +108,15 @@ GameLib.D3.Renderer = function (
this
);
if (this.camera instanceof GameLib.D3.API.Camera) {
this.camera = new GameLib.D3.Camera(
if (this.camera instanceof GameLib.D3.API.Camera.Perspective) {
this.camera = new GameLib.D3.Camera.Perspective(
this.graphics,
this.camera
)
}
if (this.editCamera instanceof GameLib.D3.API.Camera) {
this.editCamera = new GameLib.D3.Camera(
if (this.editCamera instanceof GameLib.D3.API.Camera.Perspective) {
this.editCamera = new GameLib.D3.Camera.Perspective(
this.graphics,
this.editCamera
)

View File

@ -34,39 +34,6 @@ GameLib.D3.Scene = function (
apiScene.parentEntity
);
this.meshes = this.meshes.map(
function(apiMesh) {
if (typeof apiMesh === 'string') {
return apiMesh;
} else {
apiMesh.parentScene = this;
return new GameLib.D3.Mesh(
this.graphics,
apiMesh
);
}
}.bind(this)
);
this.lights = this.lights.map(
function(apiLight) {
if (typeof apiLight === 'string') {
return apiLight;
} else {
return new GameLib.D3.Light(
this.graphics,
apiLight
);
}
}.bind(this)
);
this.textures = this.textures.map(
function(apiTexture) {
@ -125,13 +92,6 @@ GameLib.D3.Scene = function (
this
);
if (this.camera instanceof GameLib.D3.API.Camera) {
this.camera = new GameLib.D3.Camera(
this.graphics,
this.camera
)
}
/**
* Runtime scenes have helpers (just used to store which helper belongs to which scene)
* @type {Array}

127
src/game-lib-d3-shadow-a.js Normal file
View File

@ -0,0 +1,127 @@
/**
* GameLib.D3.Shadow
* @param graphics GameLib.GraphicsRuntime
* @param apiShadow GameLib.D3.API.Shadow
* @constructor
*/
GameLib.D3.Shadow = function(
graphics,
apiShadow
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiShadow)) {
apiShadow = {
shadowType : GameLib.D3.API.Shadow.SHADOW_TYPE_NORMAL
};
}
GameLib.D3.API.Shadow.call(
this,
apiShadow.id,
apiShadow.name,
apiShadow.shadowType,
apiShadow.camera,
apiShadow.bias,
apiShadow.mapSize,
apiShadow.radius,
apiShadow.parentEntity
);
if (this.camera instanceof GameLib.D3.API.Camera.Perspective) {
this.camera = new GameLib.D3.Camera.Perspective(
this.graphics,
this.camera
)
}
GameLib.Component.call(this);
};
GameLib.D3.Shadow.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.Shadow.prototype.constructor = GameLib.D3.Shadow;
/**
* Creates a light instance
* @returns {*}
*/
GameLib.D3.Shadow.prototype.createInstance = function() {
/**
* Shadow objects are not responsible for creating their instances right now -
* They are implicitly created through threejs light instances. This means,
* they only update their instances.
* @type {Object}
*/
this.instance = {};
GameLib.Component.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Shadow.prototype.updateInstance = function(property) {
if (typeof this.instance !== 'object') {
console.warn('this shadow instance is not ready for an update: ' + this.name);
return;
}
if (GameLib.Utils.UndefinedOrNull(property)) {
console.warn('no property for light: ' + this.name);
}
if (property === 'shadowType') {
console.warn('changing shadowType has no effect');
}
if (property === 'camera') {
this.instance.camera = this.camera.instance;
}
if (property === 'bias') {
this.instance.bias = this.bias;
}
if (property === 'mapSize') {
this.instance.mapSize.x = this.mapSize.x;
this.instance.mapSize.y = this.mapSize.y;
}
if (property === 'radius') {
this.instance.radius = this.radius;
}
if (property === 'parentEntity') {
console.warn('todo: implement parentEntity change for light')
}
};
/**
* Converts a GameLib.D3.Shadow to a GameLib.D3.API.Shadow
* @returns {GameLib.D3.API.Shadow}
*/
GameLib.D3.Shadow.prototype.toApiObject = function() {
return new GameLib.D3.API.Shadow(
this.id,
this.name,
this.shadowType,
GameLib.Utils.IdOrNull(this.camera),
this.bias,
this.mapSize.toApiObject(),
this.radius,
GameLib.Utils.IdOrNull(this.parentEntity)
);
};
GameLib.D3.Shadow.prototype.updateFromInstance = function() {
this.bias = this.instance.bias;
this.mapSize = this.instance.mapSize;
this.radius = this.instance.radius;
this.camera.instance = this.instance.camera;
this.camera.updateFromInstance();
};

View File

@ -0,0 +1,90 @@
/**
* GameLib.D3.Shadow.Directional
* @param graphics GameLib.GraphicsRuntime
* @param apiDirectionalShadow
* @constructor
*/
GameLib.D3.Shadow.Directional = function(
graphics,
apiDirectionalShadow
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiDirectionalShadow)) {
apiDirectionalShadow = {
shadowType : GameLib.D3.API.Shadow.SHADOW_TYPE_DIRECTIONAL
};
}
GameLib.D3.API.Shadow.Directional.call(
this,
apiDirectionalShadow
);
if (this.camera instanceof GameLib.D3.API.Camera.Orthographic) {
this.camera = new GameLib.D3.Camera.Orthographic(
this.graphics,
this.camera
)
}
GameLib.D3.Shadow.call(
this,
this.graphics,
apiDirectionalShadow
);
};
GameLib.D3.Shadow.Directional.prototype = Object.create(GameLib.D3.Shadow.prototype);
GameLib.D3.Shadow.Directional.prototype.constructor = GameLib.D3.Shadow.Directional;
/**
* Creates a shadow instance
* @returns {*}
*/
GameLib.D3.Shadow.Directional.prototype.createInstance = function() {
this.instance = {};
GameLib.D3.Shadow.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Shadow.Directional.prototype.updateInstance = function(property) {
if (property === 'camera') {
console.warn('todo: updateInstance for directional shadow camera instance');
return;
}
GameLib.D3.Shadow.prototype.updateInstance.call(this, property);
};
/**
* Converts a GameLib.D3.Shadow to a GameLib.D3.API.Shadow
* @returns {GameLib.D3.API.Shadow}
*/
GameLib.D3.Shadow.Directional.prototype.toApiObject = function() {
var apiShadow = GameLib.D3.Shadow.prototype.toApiObject.call(this);
var apiDirectionalShadow = new GameLib.D3.API.Shadow.Directional(
apiShadow
);
return apiDirectionalShadow;
};
GameLib.D3.Shadow.Directional.prototype.updateFromInstance = function() {
GameLib.D3.Shadow.prototype.updateFromInstance.call(this);
};

View File

@ -0,0 +1,83 @@
/**
* GameLib.D3.Shadow.Spot
* @param graphics GameLib.GraphicsRuntime
* @param apiSpotShadow
* @constructor
*/
GameLib.D3.Shadow.Spot = function(
graphics,
apiSpotShadow
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiSpotShadow)) {
apiSpotShadow = {
shadowType : GameLib.D3.API.Shadow.SHADOW_TYPE_SPOT
};
}
GameLib.D3.API.Shadow.Spot.call(
this,
apiSpotShadow
);
if (this.camera instanceof GameLib.D3.API.Camera.Perspective) {
this.camera = new GameLib.D3.Camera.Perspective(
this.graphics,
this.camera
)
}
GameLib.D3.Shadow.call(
this,
this.graphics,
apiSpotShadow
);
};
GameLib.D3.Shadow.Spot.prototype = Object.create(GameLib.D3.Shadow.prototype);
GameLib.D3.Shadow.Spot.prototype.constructor = GameLib.D3.Shadow.Spot;
/**
* Creates a shadow instance
* @returns {*}
*/
GameLib.D3.Shadow.Spot.prototype.createInstance = function() {
this.instance = {};
GameLib.D3.Shadow.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Shadow.Spot.prototype.updateInstance = function(property) {
if (property === 'camera') {
console.warn('todo: updateInstance for directional shadow camera instance');
return;
}
GameLib.D3.Shadow.prototype.updateInstance.call(this, property);
};
/**
* Converts a GameLib.D3.Shadow to a GameLib.D3.API.Shadow
* @returns {GameLib.D3.API.Shadow}
*/
GameLib.D3.Shadow.Spot.prototype.toApiObject = function() {
var apiShadow = GameLib.D3.Shadow.prototype.toApiObject.call(this);
var apiSpotShadow = new GameLib.D3.API.Shadow.Spot(
apiShadow
);
return apiSpotShadow;
};

76
src/game-lib-number.js Normal file
View File

@ -0,0 +1,76 @@
/**
* Runtime vector2 for updating instance objects
* @param apiNumber GameLib.API.Number
* @param parentObject
* @constructor
*/
GameLib.Number = function (
apiNumber,
parentObject
) {
if (GameLib.Utils.UndefinedOrNull(apiNumber)) {
apiNumber = {};
}
GameLib.API.Number.call(
this,
apiNumber
);
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
parentObject = null;
}
this.parentObject = parentObject;
this.createInstance();
};
GameLib.Number.prototype = Object.create(GameLib.API.Number.prototype);
GameLib.Number.prototype.constructor = GameLib.Number;
/**
* Creates an instance vector2
* @returns {*}
*/
GameLib.Number.prototype.createInstance = function() {
this.instance = {};
};
/**
* Updates the instance vector, calls updateInstance on the parent object
*/
GameLib.Number.prototype.updateInstance = function(property, parentProperty) {
if (property === 'value') {
if (this.parentObject && this.parentObject.updateInstance) {
this.parentObject.updateInstance(parentProperty);
}
}
if (property === 'grain') {
console.warn('todo: update number instance grain');
}
if (property === 'min') {
console.warn('todo: update number instance min');
}
if (property === 'max') {
console.warn('todo: update number instance max');
}
};
/**
* Converts runtime vector to API Vector
* @returns {GameLib.API.Number}
*/
GameLib.Number.prototype.toApiObject = function() {
return new GameLib.API.Number(
this.value,
this.grain,
this.min,
this.max
);
};

View File

@ -869,6 +869,10 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
grain = object.grain;
}
if (property === 'bias') {
grain = 0.0001;
}
if (property === 'componentType') {
var readOnly = {
@ -960,6 +964,17 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
}
)
);
} else if (property === 'shadowType') {
controllers.push(
folder.add(
object,
property,
{
'directional': GameLib.D3.API.Shadow.SHADOW_TYPE_DIRECTIONAL,
'spot': GameLib.D3.API.Shadow.SHADOW_TYPE_SPOT
}
)
);
} else if (property === 'shadowMapType') {
controllers.push(
folder.add(
@ -1112,8 +1127,10 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
object,
property,
{
'perspective' : GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE,
'orthographic' : GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL
'perspective' : GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE,
'orthographic' : GameLib.D3.API.Camera.CAMERA_TYPE_ORTHOGRAPHIC,
'stereo' : GameLib.D3.API.Camera.CAMERA_TYPE_STEREO,
'cube' : GameLib.D3.API.Camera.CAMERA_TYPE_CUBE
}
)
);

View File

@ -1091,23 +1091,7 @@ GameLib.System.Input.prototype.onMouseMoveEdit = function(event) {
* @param event
*/
GameLib.System.Input.prototype.onMouseUpEdit = function(event) {
this.editorControls.map(
function(editorControl) {
editorControl.camera.position.x = editorControl.camera.instance.position.x;
editorControl.camera.position.y = editorControl.camera.instance.position.y;
editorControl.camera.position.z = editorControl.camera.instance.position.z;
editorControl.camera.quaternion.x = editorControl.camera.instance.quaternion.x;
editorControl.camera.quaternion.y = editorControl.camera.instance.quaternion.y;
editorControl.camera.quaternion.z = editorControl.camera.instance.quaternion.z;
editorControl.camera.quaternion.w = editorControl.camera.instance.quaternion.w;
editorControl.camera.lookAt.x = editorControl.instance.center.x;
editorControl.camera.lookAt.y = editorControl.instance.center.y;
editorControl.camera.lookAt.z = editorControl.instance.center.z;
editorControl.camera.lookAt.instance.copy(editorControl.instance.center);
}
);
};
/**
@ -1116,13 +1100,7 @@ GameLib.System.Input.prototype.onMouseUpEdit = function(event) {
* @param event
*/
GameLib.System.Input.prototype.onMouseWheelEdit = function(event) {
this.editorControls.map(
function(editorControl) {
editorControl.camera.position.x = editorControl.camera.instance.position.x;
editorControl.camera.position.y = editorControl.camera.instance.position.y;
editorControl.camera.position.z = editorControl.camera.instance.position.z;
}
);
};
GameLib.System.Input.prototype.selectFace = function(mesh, face) {

View File

@ -296,10 +296,10 @@ GameLib.System.Render.prototype.render = function(data) {
/**
* Ensure the camera aspect ratio
*/
if (camera.aspect !== aspect) {
camera.aspect = aspect;
camera.updateInstance('aspect');
}
// if (camera.aspect !== aspect) {
// camera.aspect = aspect;
// camera.updateInstance('aspect');
// }
if (renderer.renderMode === GameLib.D3.API.Renderer.MODE_TARGET) {