render passes, effects, stereo cameras, light updates, materials revamp, render configruation

beta.r3js.org
-=yb4f310 2018-02-05 22:35:58 +01:00
parent da67665771
commit 584b5e2a7b
63 changed files with 6020 additions and 3522 deletions

View File

@ -0,0 +1,81 @@
/**
* GameLib.D3.API.Camera.Stereo.Anaglyph
* @constructor
* @param apiStereoCamera
* @param colorMatrixLeft
* @param colorMatrixRight
* @param orthographicCamera
* @param orthographicScene
*/
GameLib.D3.API.Camera.Stereo.Anaglyph = function(
apiStereoCamera,
colorMatrixLeft,
colorMatrixRight,
orthographicCamera,
orthographicScene,
renderTargetL,
renderTargetR,
shaderMaterial,
meshPlane
) {
if (GameLib.Utils.UndefinedOrNull(apiStereoCamera)) {
apiStereoCamera = {
stereoType : GameLib.D3.API.Camera.Stereo.STEREO_MODE_ANAGLYPH
};
}
if (GameLib.Utils.UndefinedOrNull(apiStereoCamera.stereoType)) {
apiStereoCamera.stereoType = GameLib.D3.API.Camera.Stereo.STEREO_MODE_ANAGLYPH;
}
if (GameLib.Utils.UndefinedOrNull(colorMatrixLeft)) {
colorMatrixLeft = [
1.0671679973602295, -0.0016435992438346148, 0.0001777536963345483, // r out
-0.028107794001698494, -0.00019593400065787137, -0.0002875397040043026, // g out
-0.04279090091586113, 0.000015809757314855233, -0.00024287120322696865 // b out
]
}
this.colorMatrixLeft = colorMatrixLeft;
if (GameLib.Utils.UndefinedOrNull(colorMatrixRight)) {
colorMatrixRight = [
-0.0355340838432312, -0.06440307199954987, 0.018319187685847282, // r out
-0.10269022732973099, 0.8079727292060852, -0.04835830628871918, // g out
0.0001224992738571018, -0.009558862075209618, 0.567823588848114 // b out
]
}
this.colorMatrixRight = colorMatrixRight;
if (GameLib.Utils.UndefinedOrNull(orthographicCamera)) {
orthographicCamera = new GameLib.D3.API.Camera.Orthographic(null, null, 0, 1, -1, 1, 1, -1);
}
this.orthographicCamera = orthographicCamera;
if (GameLib.Utils.UndefinedOrNull(orthographicScene)) {
orthographicScene = new GameLib.D3.API.Scene(null, 'Orthographic Stereo Anaglyph Scene');
}
this.orthographicScene = orthographicScene;
//
// if (GameLib.Utils.UndefinedOrNull(renderTargetL)) {
// renderTargetL = new GameLib.D3.API.RenderTarget(null, null, null, )
// }
//
// renderTargetL,
// renderTargetR,
// shaderMaterial,
// meshPlane
GameLib.D3.API.Camera.Stereo.call(
this,
apiStereoCamera,
apiStereoCamera.stereoType,
apiStereoCamera.eyeSep,
apiStereoCamera.main,
apiStereoCamera.cameraL,
apiStereoCamera.cameraR
);
};
GameLib.D3.API.Camera.Stereo.Anaglyph.prototype = Object.create(GameLib.D3.API.Camera.Stereo.prototype);
GameLib.D3.API.Camera.Stereo.Anaglyph.prototype.constructor = GameLib.D3.API.Camera.Stereo.Anaglyph;

View File

@ -0,0 +1,32 @@
/**
* GameLib.D3.API.Camera.Stereo.Normal
* @constructor
* @param apiStereoCamera
*/
GameLib.D3.API.Camera.Stereo.Normal = function(
apiStereoCamera
) {
if (GameLib.Utils.UndefinedOrNull(apiStereoCamera)) {
apiStereoCamera = {
stereoType : GameLib.D3.API.Camera.Stereo.STEREO_TYPE_NORMAL
};
}
if (GameLib.Utils.UndefinedOrNull(apiStereoCamera.stereoType)) {
apiStereoCamera.stereoType = GameLib.D3.API.Camera.Stereo.STEREO_TYPE_NORMAL;
}
GameLib.D3.API.Camera.Stereo.call(
this,
apiStereoCamera,
apiStereoCamera.stereoType,
apiStereoCamera.eyeSep,
apiStereoCamera.main,
apiStereoCamera.cameraL,
apiStereoCamera.cameraR
);
};
GameLib.D3.API.Camera.Stereo.Normal.prototype = Object.create(GameLib.D3.API.Camera.Stereo.prototype);
GameLib.D3.API.Camera.Stereo.Normal.prototype.constructor = GameLib.D3.API.Camera.Stereo.Normal;

View File

@ -98,7 +98,7 @@ GameLib.Event.CAST_SOURCE_CHANGED = 0x50;
GameLib.Event.ANIMATION_MESH_ADDED = 0x51;
GameLib.Event.ANIMATION_MESH_REMOVED = 0x52;
GameLib.Event.CANVAS_CHANGE = 0x53;
GameLib.Event.AFTER_WINDOW_RESIZE = 0x54;
GameLib.Event.AFTER_WINDOW_RESIZE = 0x54;
GameLib.Event.LOAD_FONT = 0x55;
GameLib.Event.FONT_NOT_FOUND = 0x56;
GameLib.Event.STOP_ALL_AUDIO = 0x57;
@ -127,6 +127,7 @@ GameLib.Event.SELECTION_MODE_CHANGE = 0x6d;
GameLib.Event.MESH_FACE_SELECTED = 0x6e;
GameLib.Event.MESH_FACE_DESELECTED = 0x6f;
GameLib.Event.BEFORE_WINDOW_RESIZE = 0x70;
GameLib.Event.GET_WINDOW_SIZE = 0x71;
/**
* Returns string name of event ID

View File

@ -205,7 +205,7 @@ GameLib.Component.prototype.toString = function() {
};
GameLib.Component.SOCKET_RECEIVE = 0x1;
GameLib.Component.MATERIAL = 0x2;
GameLib.Component.MATERIAL_STANDARD = 0x2;
GameLib.Component.RENDERER = 0x3;
GameLib.Component.SERVER = 0x4;
GameLib.Component.CAMERA_PERSPECTIVE = 0x5;
@ -216,7 +216,7 @@ GameLib.Component.SHADOW_DIRECTIONAL = 0x9;
GameLib.Component.PLANE = 0xa;
GameLib.Component.COMPOSER = 0xb;
GameLib.Component.RENDER_TARGET = 0xc;
GameLib.Component.PASS = 0xd;
GameLib.Component.PASS_RENDER = 0xd;
GameLib.Component.SCENE = 0xe;
GameLib.Component.RAYCASTER = 0xf;
GameLib.Component.TEXT = 0x10;
@ -228,7 +228,7 @@ GameLib.Component.HELPER = 0x15;
GameLib.Component.CUSTOM_CODE = 0x16;
GameLib.Component.MOUSE = 0x17;
GameLib.Component.SKELETON = 0x18;
GameLib.Component.TEXTURE = 0x19;
GameLib.Component.TEXTURE_IMAGE = 0x19;
GameLib.Component.ENTITY_MANAGER = 0x1a;
GameLib.Component.DOM_ELEMENT = 0x1b;
GameLib.Component.SHADOW_SPOT = 0x1c;
@ -295,7 +295,17 @@ 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.RENDER_TARGET_CUBE = 0x5c;
GameLib.Component.TEXTURE_CUBE = 0x5d;
GameLib.Component.TEXTURE_CANVAS = 0x5e;
GameLib.Component.EFFECT_STEREO = 0x5f;
GameLib.Component.EFFECT_ANAGLYPH = 0x60;
GameLib.Component.EFFECT_PARALLAX = 0x61;
GameLib.Component.PASS_SSAO = 0x62;
GameLib.Component.PASS_BLOOM = 0x63;
GameLib.Component.PASS_FXAA = 0x64;
GameLib.Component.RENDER_CONFIGURATION = 0x65;
GameLib.Component.MAX_COMPONENTS = 0x66;
GameLib.Component.GRAPHICS_RUNTIME = 0x1;
GameLib.Component.PHYSICS_RUNTIME = 0x2;
@ -327,10 +337,10 @@ GameLib.Component.GetComponentInfo = function(number) {
apiConstructor : GameLib.API.Socket.Receive
};
case 0x2 : return {
name : 'GameLib.D3.Material',
name : 'GameLib.D3.Material.Standard',
runtime : GameLib.Component.GRAPHICS_RUNTIME,
constructor : GameLib.D3.Material,
apiConstructor : GameLib.D3.API.Material
constructor : GameLib.D3.Material.Standard,
apiConstructor : GameLib.D3.API.Material.Standard
};
case 0x3 : return {
name : 'GameLib.D3.Renderer',
@ -393,10 +403,10 @@ GameLib.Component.GetComponentInfo = function(number) {
apiConstructor : GameLib.D3.API.RenderTarget
};
case 0xd : return {
name : 'GameLib.D3.Pass',
name : 'GameLib.D3.Pass.Render',
runtime : GameLib.Component.GRAPHICS_RUNTIME,
constructor : GameLib.D3.Pass,
apiConstructor : GameLib.D3.API.Pass
constructor : GameLib.D3.Pass.Render,
apiConstructor : GameLib.D3.API.Pass.Render
};
case 0xe : return {
name : 'GameLib.D3.Scene',
@ -462,10 +472,10 @@ GameLib.Component.GetComponentInfo = function(number) {
apiConstructor : GameLib.D3.API.Skeleton
};
case 0x19 : return {
name : 'GameLib.D3.Texture',
name : 'GameLib.D3.Texture.Image',
runtime : GameLib.Component.GRAPHICS_RUNTIME,
constructor : GameLib.D3.Texture,
apiConstructor : GameLib.D3.API.Texture
constructor : GameLib.D3.Texture.Image,
apiConstructor : GameLib.D3.API.Texture.Image
};
case 0x1a : return {
name : 'GameLib.EntityManager',
@ -858,10 +868,70 @@ GameLib.Component.GetComponentInfo = function(number) {
};
case 0x5b : return {
name : 'GameLib.D3.Shadow',
runtime : GameLib.Component.SHADOW,
runtime : GameLib.Component.GRAPHICS_RUNTIME,
constructor : GameLib.D3.Shadow,
apiConstructor : GameLib.D3.API.Shadow
};
case 0x5c : return {
name : 'GameLib.D3.RenderTarget.Cube',
runtime : GameLib.Component.GRAPHICS_RUNTIME,
constructor : GameLib.D3.RenderTarget.Cube,
apiConstructor : GameLib.D3.API.RenderTarget.Cube
};
case 0x5d : return {
name : 'GameLib.D3.Texture.Cube',
runtime : GameLib.Component.GRAPHICS_RUNTIME,
constructor : GameLib.D3.Texture.Cube,
apiConstructor : GameLib.D3.API.Texture.Cube
};
case 0x5e : return {
name : 'GameLib.D3.Texture.Canvas',
runtime : GameLib.Component.GRAPHICS_RUNTIME,
constructor : GameLib.D3.Texture.Canvas,
apiConstructor : GameLib.D3.API.Texture.Canvas
};
case 0x5f : return {
name : 'GameLib.D3.Effect.Stereo',
runtime : GameLib.Component.GRAPHICS_RUNTIME,
constructor : GameLib.D3.Effect.Stereo,
apiConstructor : GameLib.D3.API.Effect.Stereo
};
case 0x60 : return {
name : 'GameLib.D3.Effect.Anaglyph',
runtime : GameLib.Component.GRAPHICS_RUNTIME,
constructor : GameLib.D3.Effect.Anaglyph,
apiConstructor : GameLib.D3.API.Effect.Anaglyph
};
case 0x61 : return {
name : 'GameLib.D3.Effect.Parallax',
runtime : GameLib.Component.GRAPHICS_RUNTIME,
constructor : GameLib.D3.Effect.Parallax,
apiConstructor : GameLib.D3.API.Effect.Parallax
};
case 0x62 : return {
name : 'GameLib.D3.Pass.SSAO',
runtime : GameLib.Component.GRAPHICS_RUNTIME,
constructor : GameLib.D3.Pass.SSAO,
apiConstructor : GameLib.D3.API.Pass.SSAO
};
case 0x63 : return {
name : 'GameLib.D3.Pass.Bloom',
runtime : GameLib.Component.GRAPHICS_RUNTIME,
constructor : GameLib.D3.Pass.Bloom,
apiConstructor : GameLib.D3.API.Pass.Bloom
};
case 0x64 : return {
name : 'GameLib.D3.Pass.FXAA',
runtime : GameLib.Component.GRAPHICS_RUNTIME,
constructor : GameLib.D3.Pass.FXAA,
apiConstructor : GameLib.D3.API.Pass.FXAA
};
case 0x65 : return {
name : 'GameLib.RenderConfiguration',
runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.RenderConfiguration,
apiConstructor : GameLib.API.RenderConfiguration
};
break;
}

View File

@ -13,12 +13,13 @@
GameLib.API.Image = function(
id,
name,
parentEntity,
parentTexture,
fileName,
extension,
path,
contentType,
size,
parentEntity
size
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
@ -30,6 +31,11 @@ GameLib.API.Image = function(
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(parentTexture)) {
parentTexture = null;
}
this.parentTexture = parentTexture;
if (GameLib.Utils.UndefinedOrNull(fileName)) {
fileName = GameLib.Utils.LowerUnderscore(name);
}
@ -77,22 +83,3 @@ GameLib.API.Image = function(
GameLib.API.Image.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.API.Image.prototype.constructor = GameLib.API.Image;
/**
* Returns an API light from an Object light
* @constructor
* @param objectImage
*/
GameLib.API.Image.FromObject = function(objectImage) {
return new GameLib.API.Image(
objectImage.id,
objectImage.name,
objectImage.fileName,
objectImage.extension,
objectImage.path,
objectImage.contentType,
objectImage.size,
objectImage.parentEntity
);
};

View File

@ -0,0 +1,117 @@
/**
* GameLib.API.RenderConfiguration
* @param id
* @param name
* @param parentEntity
* @param logicalSize
* @param aspectRatio
* @param scaleMode
* @param activeCamera
* @param activeScenes
* @param activeComposer
* @param activeEffect
* @param activeRenderer
* @param enableComposer
* @param enableEffect
* @constructor
*/
GameLib.API.RenderConfiguration = function (
id,
name,
parentEntity,
logicalSize,
aspectRatio,
scaleMode,
activeCamera,
activeScenes,
activeRenderer,
activeComposer,
activeEffect,
enableComposer,
enableEffect
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = "RenderConfiguration (" + this.id + ")";
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(logicalSize)) {
logicalSize = new GameLib.API.Vector2(
480,
320
);
}
this.logicalSize = logicalSize;
if (GameLib.Utils.UndefinedOrNull(aspectRatio)) {
aspectRatio = GameLib.D3.API.Renderer.ASPECT_RATIO_3_2;
}
this.aspectRatio = aspectRatio;
if (GameLib.Utils.UndefinedOrNull(scaleMode)) {
scaleMode = GameLib.D3.API.Renderer.SCALE_MODE_LETTERBOX;
}
this.scaleMode = scaleMode;
if (GameLib.Utils.UndefinedOrNull(activeCamera)) {
activeCamera = null;
}
this.activeCamera = activeCamera;
if (GameLib.Utils.UndefinedOrNull(activeScenes)) {
activeScenes = [];
}
this.activeScene = activeScenes;
if (GameLib.Utils.UndefinedOrNull(activeRenderer)) {
activeRenderer = null;
}
this.activeRenderer = activeRenderer;
if (GameLib.Utils.UndefinedOrNull(activeComposer)) {
activeComposer = null;
}
this.activeComposer = activeComposer;
if (GameLib.Utils.UndefinedOrNull(activeEffect)) {
activeEffect = null;
}
this.activeEffect = activeEffect;
if (GameLib.Utils.UndefinedOrNull(enableComposer)) {
enableComposer = false;
}
this.enableComposer = enableComposer;
if (GameLib.Utils.UndefinedOrNull(enableEffect)) {
enableEffect = false;
}
this.enableEffect = enableEffect;
GameLib.API.Component.call(
this,
GameLib.Component.RENDER_CONFIGURATION,
parentEntity
);
};
GameLib.API.RenderConfiguration.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.API.RenderConfiguration.prototype.constructor = GameLib.API.RenderConfiguration;
GameLib.API.RenderConfiguration.ASPECT_RATIO_NONE = 0x1;
GameLib.API.RenderConfiguration.ASPECT_RATIO_4_3 = 0x2;
GameLib.API.RenderConfiguration.ASPECT_RATIO_3_2 = 0x3;
GameLib.API.RenderConfiguration.ASPECT_RATIO_16_10 = 0x4;
GameLib.API.RenderConfiguration.ASPECT_RATIO_17_10 = 0x5;
GameLib.API.RenderConfiguration.ASPECT_RATIO_16_9 = 0x6;
GameLib.API.RenderConfiguration.SCALE_MODE_NONE = 0x1;
GameLib.API.RenderConfiguration.SCALE_MODE_LETTERBOX = 0x2;
GameLib.API.RenderConfiguration.SCALE_MODE_ZOOM_TO_BIGGER = 0x3;
GameLib.API.RenderConfiguration.SCALE_MODE_NON_UNIFORM = 0x4;

View File

@ -39,12 +39,12 @@ GameLib.D3.API.Camera.Cube = function(
if (GameLib.Utils.UndefinedOrNull(cubeResolution)) {
//cubeResolution = new GameLib.API.Number(512, 64, 64, 8192);
cubeResolution = 512;
cubeResolution = 128;
}
this.cubeResolution = cubeResolution;
if (GameLib.Utils.UndefinedOrNull(renderTarget)) {
renderTarget = null;
renderTarget = new GameLib.D3.API.RenderTarget.Cube();
}
this.renderTarget = renderTarget;

View File

@ -2,19 +2,11 @@
* GameLib.D3.API.Camera.Stereo
* @constructor
* @param apiCamera
* @param eyeSep
* @param stereoMode
* @param main
* @param cameraL
* @param cameraR
*/
GameLib.D3.API.Camera.Stereo = function(
apiCamera,
eyeSep,
stereoMode,
main,
cameraL,
cameraR
stereoMode
) {
if (GameLib.Utils.UndefinedOrNull(apiCamera)) {
@ -27,32 +19,11 @@ GameLib.D3.API.Camera.Stereo = function(
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(stereoMode)) {
stereoMode = GameLib.D3.API.Camera.Stereo.STEREO_MODE_STEREO;
}
this.stereoMode = stereoMode;
if (GameLib.Utils.UndefinedOrNull(main)) {
main = new GameLib.D3.API.Camera.Perspective();
}
this.main = main;
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,
@ -70,4 +41,4 @@ GameLib.D3.API.Camera.Stereo.prototype.constructor = GameLib.D3.API.Camera.Stere
GameLib.D3.API.Camera.Stereo.STEREO_MODE_STEREO = 0x1;
GameLib.D3.API.Camera.Stereo.STEREO_MODE_ANAGLYPH = 0x2;
GameLib.D3.API.Camera.Stereo.STEREO_MODE_PARALLAX = 0x3;
GameLib.D3.API.Camera.Stereo.STEREO_MODE_PARALLAX = 0x3;

View File

@ -1,20 +1,24 @@
/**
* This component renders a scene
* @param id String
* @param name String
* @param renderer GameLib.D3.Renderer
* @param renderTarget GameLib.D3.API.RenderTarget
* @param passes GameLib.D3.API.Pass[]
* GameLib.D3.API.Composer
* @param id
* @param name
* @param parentEntity
* @param width
* @param height
* @param renderer
* @param renderTarget
* @param passes
* @constructor
*/
GameLib.D3.API.Composer = function (
id,
name,
parentEntity,
width,
height,
renderer,
renderTarget,
passes,
parentEntity
passes
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
@ -26,6 +30,16 @@ GameLib.D3.API.Composer = function (
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(width)) {
width = 512;
}
this.width = width;
if (GameLib.Utils.UndefinedOrNull(height)) {
height = 512;
}
this.height = height;
if (GameLib.Utils.UndefinedOrNull(renderer)) {
renderer = null;
}
@ -50,19 +64,3 @@ GameLib.D3.API.Composer = function (
GameLib.D3.API.Composer.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.D3.API.Composer.prototype.constructor = GameLib.D3.API.Composer;
/**
* Object to GameLib.D3.API.Composer
* @param objectComponent
* @constructor
*/
GameLib.D3.API.Composer.FromObject = function(objectComponent) {
return new GameLib.D3.API.Composer(
objectComponent.id,
objectComponent.name,
objectComponent.renderer,
objectComponent.renderTarget,
objectComponent.passes,
objectComponent.parentEntity
);
};

View File

@ -0,0 +1,84 @@
/**
* GameLib.D3.API.Effect
* @param id
* @param name
* @param effectType
* @param parentEntity
* @param renderer
* @param width
* @param height
*
* @property effectType
*
* @constructor
*/
GameLib.D3.API.Effect = function(
id,
name,
effectType,
parentEntity,
renderer,
width,
height
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Effect (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(effectType)) {
effectType = GameLib.D3.API.Effect.EFFECT_TYPE_NONE;
}
this.effectType = effectType;
if (GameLib.Utils.UndefinedOrNull(renderer)) {
renderer = null;
}
this.renderer = renderer;
if (GameLib.Utils.UndefinedOrNull(width)) {
width = 512;
}
this.width = width;
if (GameLib.Utils.UndefinedOrNull(height)) {
height = 512;
}
this.height = height;
var componentType = null;
switch (this.effectType) {
case GameLib.D3.API.Effect.EFFECT_TYPE_STEREO :
componentType = GameLib.Component.EFFECT_STEREO;
break;
case GameLib.D3.API.Effect.EFFECT_TYPE_ANAGLYPH :
componentType = GameLib.Component.EFFECT_ANAGLYPH;
break;
case GameLib.D3.API.Effect.EFFECT_TYPE_PARALLAX :
componentType = GameLib.Component.EFFECT_PARALLAX;
break;
default:
throw new Error('unsupported effect type: ' + this.effectType);
}
GameLib.API.Component.call(
this,
componentType,
parentEntity
);
};
GameLib.D3.API.Effect.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.D3.API.Effect.prototype.constructor = GameLib.D3.API.Effect;
GameLib.D3.API.Effect.EFFECT_TYPE_NONE = 0x0;
GameLib.D3.API.Effect.EFFECT_TYPE_STEREO = 0x1;
GameLib.D3.API.Effect.EFFECT_TYPE_ANAGLYPH = 0x2;
GameLib.D3.API.Effect.EFFECT_TYPE_PARALLAX = 0x3;

View File

@ -0,0 +1,34 @@
/**
* GameLib.D3.API.Effect.Anaglyph
* @constructor
* @param apiEffect
*/
GameLib.D3.API.Effect.Anaglyph = function(
apiEffect
) {
if (GameLib.Utils.UndefinedOrNull(apiEffect)) {
apiEffect = {
effectType : GameLib.D3.API.Effect.EFFECT_TYPE_ANAGLYPH
};
}
if (GameLib.Utils.UndefinedOrNull(apiEffect.cameraType)) {
apiEffect.effectType = GameLib.D3.API.Effect.EFFECT_TYPE_ANAGLYPH;
}
GameLib.D3.API.Effect.call(
this,
apiEffect.id,
apiEffect.name,
apiEffect.effectType,
apiEffect.parentEntity,
apiEffect.renderer,
apiEffect.width,
apiEffect.height
);
};
GameLib.D3.API.Effect.Anaglyph.prototype = Object.create(GameLib.D3.API.Effect.prototype);
GameLib.D3.API.Effect.Anaglyph.prototype.constructor = GameLib.D3.API.Effect.Anaglyph;

View File

@ -0,0 +1,34 @@
/**
* GameLib.D3.API.Effect.Parallax
* @constructor
* @param apiEffect
*/
GameLib.D3.API.Effect.Parallax = function(
apiEffect
) {
if (GameLib.Utils.UndefinedOrNull(apiEffect)) {
apiEffect = {
effectType : GameLib.D3.API.Effect.EFFECT_TYPE_PARALLAX
};
}
if (GameLib.Utils.UndefinedOrNull(apiEffect.cameraType)) {
apiEffect.effectType = GameLib.D3.API.Effect.EFFECT_TYPE_PARALLAX;
}
GameLib.D3.API.Effect.call(
this,
apiEffect.id,
apiEffect.name,
apiEffect.effectType,
apiEffect.parentEntity,
apiEffect.renderer,
apiEffect.width,
apiEffect.height
);
};
GameLib.D3.API.Effect.Parallax.prototype = Object.create(GameLib.D3.API.Effect.prototype);
GameLib.D3.API.Effect.Parallax.prototype.constructor = GameLib.D3.API.Effect.Parallax;

View File

@ -0,0 +1,41 @@
/**
* GameLib.D3.API.Effect.Stereo
* @constructor
* @param apiEffect
* @param eyeSeperation
*/
GameLib.D3.API.Effect.Stereo = function(
apiEffect,
eyeSeperation
) {
if (GameLib.Utils.UndefinedOrNull(apiEffect)) {
apiEffect = {
effectType : GameLib.D3.API.Effect.EFFECT_TYPE_STEREO
};
}
if (GameLib.Utils.UndefinedOrNull(apiEffect.cameraType)) {
apiEffect.effectType = GameLib.D3.API.Effect.EFFECT_TYPE_STEREO;
}
if (GameLib.Utils.UndefinedOrNull(eyeSeperation)) {
eyeSeperation = 0.064;
}
this.eyeSeperation = eyeSeperation;
GameLib.D3.API.Effect.call(
this,
apiEffect.id,
apiEffect.name,
apiEffect.effectType,
apiEffect.parentEntity,
apiEffect.renderer,
apiEffect.width,
apiEffect.height
);
};
GameLib.D3.API.Effect.Stereo.prototype = Object.create(GameLib.D3.API.Effect.prototype);
GameLib.D3.API.Effect.Stereo.prototype.constructor = GameLib.D3.API.Effect.Stereo;

View File

@ -0,0 +1,397 @@
/**
* GameLib.D3.API.Material
* @param id
* @param name
* @param materialType
* @param parentEntity
* @param parentMeshes
* @param alphaTest
* @param blendDst
* @param blendDstAlpha
* @param blendEquation
* @param blendEquationAlpha
* @param blending
* @param blendSrc
* @param blendSrcAlpha
* @param clipIntersection
* @param clippingPlanes
* @param clipShadows
* @param colorWrite
* @param customDepthMaterial
* @param customDistanceMaterial
* @param defines
* @param depthFunc
* @param depthTest
* @param depthWrite
* @param fog
* @param lights
* @param opacity
* @param overdraw
* @param polygonOffset
* @param polygonOffsetFactor
* @param polygonOffsetUnits
* @param precision
* @param premultipliedAlpha
* @param dithering
* @param flatShading
* @param side
* @param transparent
* @param vertexColors
* @param visible
* @constructor
*/
GameLib.D3.API.Material = function(
id,
name,
materialType,
parentEntity,
parentMeshes,
alphaTest,
blendDst,
blendDstAlpha,
blendEquation,
blendEquationAlpha,
blending,
blendSrc,
blendSrcAlpha,
clipIntersection,
clippingPlanes,
clipShadows,
colorWrite,
customDepthMaterial,
customDistanceMaterial,
defines,
depthFunc,
depthTest,
depthWrite,
fog,
lights,
opacity,
overdraw,
polygonOffset,
polygonOffsetFactor,
polygonOffsetUnits,
precision,
premultipliedAlpha,
dithering,
flatShading,
side,
transparent,
vertexColors,
visible
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Material (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(materialType)) {
materialType = GameLib.D3.API.Material.MATERIAL_TYPE_NONE;
}
this.materialType = materialType;
if (GameLib.Utils.UndefinedOrNull(parentMeshes)) {
parentMeshes = [];
}
this.parentMeshes = parentMeshes;
if (GameLib.Utils.UndefinedOrNull(alphaTest)) {
alphaTest = 0;
}
this.alphaTest = alphaTest;
if (GameLib.Utils.UndefinedOrNull(blendDst)) {
blendDst = GameLib.D3.API.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR;
}
this.blendDst = blendDst;
if (GameLib.Utils.UndefinedOrNull(blendDstAlpha)) {
blendDstAlpha = null;
}
this.blendDstAlpha = blendDstAlpha;
if (GameLib.Utils.UndefinedOrNull(blendEquation)) {
blendEquation = GameLib.D3.API.Material.TYPE_ADD_EQUATION;
}
this.blendEquation = blendEquation;
if (GameLib.Utils.UndefinedOrNull(blendEquationAlpha)) {
blendEquationAlpha = null;
}
this.blendEquationAlpha = blendEquationAlpha;
if (GameLib.Utils.UndefinedOrNull(blending)) {
blending = GameLib.D3.API.Material.TYPE_NORMAL_BLENDING;
}
this.blending = blending;
if (GameLib.Utils.UndefinedOrNull(blendSrc)) {
blendSrc = GameLib.D3.API.Material.TYPE_SRC_ALPHA_FACTOR;
}
this.blendSrc = blendSrc;
if (GameLib.Utils.UndefinedOrNull(blendSrcAlpha)) {
blendSrcAlpha = null;
}
this.blendSrcAlpha = blendSrcAlpha;
if (GameLib.Utils.UndefinedOrNull(clipIntersection)) {
clipIntersection = false;
}
this.clipIntersection = clipIntersection;
if (GameLib.Utils.UndefinedOrNull(clippingPlanes)) {
clippingPlanes = [];
}
this.clippingPlanes = clippingPlanes;
if (GameLib.Utils.UndefinedOrNull(clipShadows)) {
clipShadows = false;
}
this.clipShadows = clipShadows;
if (GameLib.Utils.UndefinedOrNull(colorWrite)) {
colorWrite = true;
}
this.colorWrite = colorWrite;
if (GameLib.Utils.UndefinedOrNull(customDepthMaterial)) {
customDepthMaterial = null;
}
this.customDepthMaterial = customDepthMaterial;
if (GameLib.Utils.UndefinedOrNull(customDistanceMaterial)) {
customDistanceMaterial = null;
}
this.customDistanceMaterial = customDistanceMaterial;
if (GameLib.Utils.UndefinedOrNull(defines)) {
defines = null;
}
this.defines = defines;
if (GameLib.Utils.UndefinedOrNull(depthFunc)) {
depthFunc = GameLib.D3.API.Material.TYPE_LESS_EQUAL_DEPTH;
}
this.depthFunc = depthFunc;
if (GameLib.Utils.UndefinedOrNull(depthTest)) {
depthTest = true;
}
this.depthTest = depthTest;
if (GameLib.Utils.UndefinedOrNull(depthWrite)) {
depthWrite = true;
}
this.depthWrite = depthWrite;
if (GameLib.Utils.UndefinedOrNull(fog)) {
fog = true;
}
this.fog = fog;
if (GameLib.Utils.UndefinedOrNull(lights)) {
lights = true;
}
this.lights = lights;
if (GameLib.Utils.UndefinedOrNull(opacity)) {
opacity = 1.0;
}
this.opacity = opacity;
if (GameLib.Utils.UndefinedOrNull(overdraw)) {
overdraw = 0;
}
this.overdraw = overdraw;
if (GameLib.Utils.UndefinedOrNull(polygonOffset)) {
polygonOffset = false;
}
this.polygonOffset = polygonOffset;
if (GameLib.Utils.UndefinedOrNull(polygonOffsetFactor)) {
polygonOffsetFactor = 0;
}
this.polygonOffsetFactor = polygonOffsetFactor;
if (GameLib.Utils.UndefinedOrNull(polygonOffsetUnits)) {
polygonOffsetUnits = 0;
}
this.polygonOffsetUnits = polygonOffsetUnits;
if (GameLib.Utils.UndefinedOrNull(precision)) {
precision = null;
}
this.precision = precision;
if (GameLib.Utils.UndefinedOrNull(premultipliedAlpha)) {
premultipliedAlpha = false;
}
this.premultipliedAlpha = premultipliedAlpha;
if (GameLib.Utils.UndefinedOrNull(dithering)) {
dithering = false;
}
this.dithering = dithering;
if (GameLib.Utils.UndefinedOrNull(flatShading)) {
flatShading = false;
}
this.flatShading = flatShading;
if (GameLib.Utils.UndefinedOrNull(side)) {
side = GameLib.D3.API.Material.TYPE_FRONT_SIDE;
}
this.side = side;
if (GameLib.Utils.UndefinedOrNull(transparent)) {
transparent = false;
}
this.transparent = transparent;
if (GameLib.Utils.UndefinedOrNull(vertexColors)) {
vertexColors = GameLib.D3.API.Material.TYPE_NO_COLORS;
}
this.vertexColors = vertexColors;
if (GameLib.Utils.UndefinedOrNull(visible)) {
visible = true;
}
this.visible = visible;
var componentType = null;
switch (this.materialType) {
case GameLib.D3.API.Material.MATERIAL_TYPE_STANDARD :
componentType = GameLib.Component.MATERIAL_STANDARD;
break;
default :
throw new Error('unhandled material type: ' + this.materialType);
}
this.needsUpdate = false;
GameLib.API.Component.call(
this,
componentType,
parentEntity
);
};
GameLib.D3.API.Material.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.D3.API.Material.prototype.constructor = GameLib.D3.API.Material;
/**
* Combine Method
* @type {number}
*/
GameLib.D3.API.Material.TYPE_MULTIPLY_OPERATION = 0;
GameLib.D3.API.Material.TYPE_MIX_OPERATION = 1;
GameLib.D3.API.Material.TYPE_ADD_OPERATION = 2;
/**
* Vertex Color Mode
* @type {number}
*/
GameLib.D3.API.Material.TYPE_NO_COLORS = 0;
GameLib.D3.API.Material.TYPE_FACE_COLORS = 1;
GameLib.D3.API.Material.TYPE_VERTEX_COLORS = 2;
/**
* Blending Mode
* @type {number}
*/
GameLib.D3.API.Material.TYPE_NO_BLENDING = 0;
GameLib.D3.API.Material.TYPE_NORMAL_BLENDING = 1;
GameLib.D3.API.Material.TYPE_ADDITIVE_BLENDING = 2;
GameLib.D3.API.Material.TYPE_SUBTRACTIVE_BLENDING = 3;
GameLib.D3.API.Material.TYPE_MULTIPLY_BLENDING = 4;
GameLib.D3.API.Material.TYPE_CUSTOM_BLENDING = 5;
/**
* Blend Source and Destination
* @type {number}
*/
GameLib.D3.API.Material.TYPE_ZERO_FACTOR = 200;
GameLib.D3.API.Material.TYPE_ONE_FACTOR = 201;
GameLib.D3.API.Material.TYPE_SRC_COLOR_FACTOR = 202;
GameLib.D3.API.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR = 203;
GameLib.D3.API.Material.TYPE_SRC_ALPHA_FACTOR = 204;
GameLib.D3.API.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR = 205;
GameLib.D3.API.Material.TYPE_DST_ALPHA_FACTOR = 206;
GameLib.D3.API.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR = 207;
GameLib.D3.API.Material.TYPE_DST_COLOR_FACTOR = 208;
GameLib.D3.API.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR = 209;
GameLib.D3.API.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR = 210;
/**
* Blend Operation
* @type {number}
*/
GameLib.D3.API.Material.TYPE_ADD_EQUATION = 100;
GameLib.D3.API.Material.TYPE_SUBTRACT_EQUATION = 101;
GameLib.D3.API.Material.TYPE_REVERSE_SUBTRACT_EQUATION = 102;
GameLib.D3.API.Material.TYPE_MIN_EQUATION = 103;
GameLib.D3.API.Material.TYPE_MAX_EQUATION = 104;
/**
* Depth Function
* @type {number}
*/
GameLib.D3.API.Material.TYPE_NEVER_DEPTH = 0;
GameLib.D3.API.Material.TYPE_ALWAYS_DEPTH = 1;
GameLib.D3.API.Material.TYPE_LESS_DEPTH = 2;
GameLib.D3.API.Material.TYPE_LESS_EQUAL_DEPTH = 3;
GameLib.D3.API.Material.TYPE_EQUAL_DEPTH = 4;
GameLib.D3.API.Material.TYPE_GREATER_EQUAL_DEPTH = 5;
GameLib.D3.API.Material.TYPE_GREATER_DEPTH = 6;
GameLib.D3.API.Material.TYPE_NOT_EQUAL_DEPTH = 7;
/**
* Culling Mode
* @type {number}
*/
GameLib.D3.API.Material.TYPE_FRONT_SIDE = 0;
GameLib.D3.API.Material.TYPE_BACK_SIDE = 1;
GameLib.D3.API.Material.TYPE_DOUBLE_SIDE = 2;
/**
* Shading Type
* @type {number}
*/
GameLib.D3.API.Material.TYPE_FLAT_SHADING = 1;
GameLib.D3.API.Material.TYPE_SMOOTH_SHADING = 2;
/**
* Material Type
* @type {string}
*/
GameLib.D3.API.Material.MATERIAL_TYPE_NONE = 0x0;
GameLib.D3.API.Material.MATERIAL_TYPE_LINE_BASIC = 0x1;
GameLib.D3.API.Material.MATERIAL_TYPE_LINE_DASHED = 0x2;
GameLib.D3.API.Material.MATERIAL_TYPE_BASIC = 0x3;
GameLib.D3.API.Material.MATERIAL_TYPE_DEPTH = 0x4;
GameLib.D3.API.Material.MATERIAL_TYPE_LAMBERT = 0x5;
GameLib.D3.API.Material.MATERIAL_TYPE_NORMAL = 0x6;
GameLib.D3.API.Material.MATERIAL_TYPE_PHONG = 0x7;
GameLib.D3.API.Material.MATERIAL_TYPE_STANDARD = 0x8;
GameLib.D3.API.Material.MATERIAL_TYPE_POINTS = 0x9;
GameLib.D3.API.Material.MATERIAL_TYPE_SPRITE = 0xa;
GameLib.D3.API.Material.MATERIAL_TYPE_TOON = 0xb;
GameLib.D3.API.Material.MATERIAL_TYPE_SHADER = 0xc;
GameLib.D3.API.Material.LINE_CAP_BUTT = 0x1;//'butt';
GameLib.D3.API.Material.LINE_CAP_ROUND = 0x2;//'round';
GameLib.D3.API.Material.LINE_CAP_SQUARE = 0x3;//'square';
GameLib.D3.API.Material.LINE_JOIN_ROUND = 0x1;//'round';
GameLib.D3.API.Material.LINE_JOIN_BEVEL = 0x2;//'bevel';
GameLib.D3.API.Material.LINE_JOIN_MITER = 0x3;//'miter';

View File

@ -0,0 +1,281 @@
/**
* GameLib.D3.API.Material.Standard
* @param apiMaterial
* @param alphaMap
* @param aoMap
* @param aoMapIntensity
* @param bumpMap
* @param bumpScale
* @param color
* @param displacementMap
* @param displacementScale
* @param displacementBias
* @param emissive
* @param emissiveMap
* @param emissiveIntensity
* @param envMap
* @param envMapIntensity
* @param lightMap
* @param lightMapIntensity
* @param diffuseMap
* @param metalness
* @param metalnessMap
* @param morphNormals
* @param morphTargets
* @param normalMap
* @param normalScale
* @param refractionRatio
* @param roughness
* @param roughnessMap
* @param skinning
* @param wireframe
* @param wireframeLinecap
* @param wireframeLinejoin
* @param wireframeLinewidth
* @constructor
*/
GameLib.D3.API.Material.Standard = function(
apiMaterial,
alphaMap,
aoMap,
aoMapIntensity,
bumpMap,
bumpScale,
color,
displacementMap,
displacementScale,
displacementBias,
emissive,
emissiveMap,
emissiveIntensity,
envMap,
envMapIntensity,
lightMap,
lightMapIntensity,
diffuseMap,
metalness,
metalnessMap,
morphNormals,
morphTargets,
normalMap,
normalScale,
refractionRatio,
roughness,
roughnessMap,
skinning,
wireframe,
wireframeLinecap,
wireframeLinejoin,
wireframeLinewidth
) {
if (GameLib.Utils.UndefinedOrNull(apiMaterial)) {
apiMaterial = {
materialType: GameLib.D3.API.Material.MATERIAL_TYPE_STANDARD
};
}
if (GameLib.Utils.UndefinedOrNull(apiMaterial.materialType)) {
apiMaterial.materialType = GameLib.D3.API.Material.MATERIAL_TYPE_STANDARD;
}
if (GameLib.Utils.UndefinedOrNull(alphaMap)) {
alphaMap = null;
}
this.alphaMap = alphaMap;
if (GameLib.Utils.UndefinedOrNull(aoMap)) {
aoMap = null;
}
this.aoMap = aoMap;
if (GameLib.Utils.UndefinedOrNull(aoMapIntensity)) {
aoMapIntensity = 1;
}
this.aoMapIntensity = aoMapIntensity;
if (GameLib.Utils.UndefinedOrNull(bumpMap)) {
bumpMap = null;
}
this.bumpMap = bumpMap;
if (GameLib.Utils.UndefinedOrNull(bumpScale)) {
bumpScale = 1;
}
this.bumpScale = bumpScale;
if (GameLib.Utils.UndefinedOrNull(color)) {
color = new GameLib.API.Color(1, 1, 1, 1)
}
this.color = color;
if (GameLib.Utils.UndefinedOrNull(displacementMap)) {
displacementMap = null;
}
this.displacementMap = displacementMap;
if (GameLib.Utils.UndefinedOrNull(displacementBias)) {
displacementBias = 0;
}
this.displacementBias = displacementBias;
if (GameLib.Utils.UndefinedOrNull(displacementScale)) {
displacementScale = 1;
}
this.displacementScale = displacementScale;
if (GameLib.Utils.UndefinedOrNull(emissive)) {
emissive = new GameLib.API.Color(0, 0, 0, 0);
}
this.emissive = emissive;
if (GameLib.Utils.UndefinedOrNull(emissiveMap)) {
emissiveMap = null;
}
this.emissiveMap = emissiveMap;
if (GameLib.Utils.UndefinedOrNull(emissiveIntensity)) {
emissiveIntensity = 1;
}
this.emissiveIntensity = emissiveIntensity;
if (GameLib.Utils.UndefinedOrNull(envMap)) {
envMap = null;
}
this.envMap = envMap;
if (GameLib.Utils.UndefinedOrNull(envMapIntensity)) {
envMapIntensity = 1;
}
this.envMapIntensity = envMapIntensity;
if (GameLib.Utils.UndefinedOrNull(lightMap)) {
lightMap = null;
}
this.lightMap = lightMap;
if (GameLib.Utils.UndefinedOrNull(lightMapIntensity)) {
lightMapIntensity = 1;
}
this.lightMapIntensity = lightMapIntensity;
if (GameLib.Utils.UndefinedOrNull(diffuseMap)) {
diffuseMap = null;
}
this.diffuseMap = diffuseMap;
if (GameLib.Utils.UndefinedOrNull(metalness)) {
metalness = 0.5;
}
this.metalness = metalness;
if (GameLib.Utils.UndefinedOrNull(metalnessMap)) {
metalnessMap = null;
}
this.metalnessMap = metalnessMap;
if (GameLib.Utils.UndefinedOrNull(morphNormals)) {
morphNormals = false;
}
this.morphNormals = morphNormals;
if (GameLib.Utils.UndefinedOrNull(morphTargets)) {
morphTargets = false;
}
this.morphTargets = morphTargets;
if (GameLib.Utils.UndefinedOrNull(normalMap)) {
normalMap = null;
}
this.normalMap = normalMap;
if (GameLib.Utils.UndefinedOrNull(normalScale)) {
normalScale = 1;
}
this.normalScale = normalScale;
if (GameLib.Utils.UndefinedOrNull(refractionRatio)) {
refractionRatio = 0.98;
}
this.refractionRatio = refractionRatio;
if (GameLib.Utils.UndefinedOrNull(roughness)) {
roughness = 0.5;
}
this.roughness = roughness;
if (GameLib.Utils.UndefinedOrNull(roughnessMap)) {
roughnessMap = null;
}
this.roughnessMap = roughnessMap;
if (GameLib.Utils.UndefinedOrNull(skinning)) {
skinning = false;
}
this.skinning = skinning;
if (GameLib.Utils.UndefinedOrNull(wireframe)) {
wireframe = false;
}
this.wireframe = wireframe;
if (GameLib.Utils.UndefinedOrNull(wireframeLinecap)) {
wireframeLinecap = 'round';
}
this.wireframeLinecap = wireframeLinecap;
if (GameLib.Utils.UndefinedOrNull(wireframeLinejoin)) {
wireframeLinejoin = 'round';
}
this.wireframeLinejoin = wireframeLinejoin;
if (GameLib.Utils.UndefinedOrNull(wireframeLinewidth)) {
wireframeLinewidth = 1;
}
this.wireframeLinewidth = wireframeLinewidth;
GameLib.D3.API.Material.call(
this,
apiMaterial.id,
apiMaterial.name,
apiMaterial.materialType,
apiMaterial.parentEntity,
apiMaterial.parentMeshes,
apiMaterial.alphaTest,
apiMaterial.blendDst,
apiMaterial.blendDstAlpha,
apiMaterial.blendEquation,
apiMaterial.blendEquationAlpha,
apiMaterial.blending,
apiMaterial.blendSrc,
apiMaterial.blendSrcAlpha,
apiMaterial.clipIntersection,
apiMaterial.clippingPlanes,
apiMaterial.clipShadows,
apiMaterial.colorWrite,
apiMaterial.customDepthMaterial,
apiMaterial.customDistanceMaterial,
apiMaterial.defines,
apiMaterial.depthFunc,
apiMaterial.depthTest,
apiMaterial.depthWrite,
apiMaterial.fog,
apiMaterial.lights,
apiMaterial.opacity,
apiMaterial.overdraw,
apiMaterial.polygonOffset,
apiMaterial.polygonOffsetFactor,
apiMaterial.polygonOffsetUnits,
apiMaterial.precision,
apiMaterial.premultipliedAlpha,
apiMaterial.dithering,
apiMaterial.flatShading,
apiMaterial.side,
apiMaterial.transparent,
apiMaterial.vertexColors,
apiMaterial.visible
);
};
GameLib.D3.API.Material.Standard.prototype = Object.create(GameLib.D3.API.Material.prototype);
GameLib.D3.API.Material.Standard.prototype.constructor = GameLib.D3.API.Material.Standard;

View File

@ -1,637 +0,0 @@
/**
* Raw material API object - should always correspond with the Material Schema
* @param id
* @param materialType
* @param name
* @param opacity
* @param side
* @param transparent
* @param specular
* @param lightMapIntensity
* @param aoMapIntensity
* @param color
* @param emissive
* @param emissiveIntensity
* @param combine
* @param shininess
* @param reflectivity
* @param refractionRatio
* @param fog
* @param wireframe
* @param wireframeLineWidth
* @param wireframeLineCap
* @param wireframeLineJoin
* @param vertexColors
* @param skinning
* @param morphTargets
* @param morphNormals
* @param lineWidth
* @param lineCap
* @param lineJoin
* @param dashSize
* @param gapWidth
* @param blending
* @param blendSrc
* @param blendDst
* @param blendEquation
* @param depthTest
* @param depthFunc
* @param depthWrite
* @param polygonOffset
* @param polygonOffsetFactor
* @param polygonOffsetUnits
* @param alphaTest
* @param clippingPlanes
* @param clipShadows
* @param visible
* @param overdraw
* @param flatShading
* @param bumpScale
* @param normalScale
* @param displacementScale
* @param displacementBias
* @param roughness
* @param metalness
* @param pointSize
* @param pointSizeAttenuation
* @param spriteRotation
* @param envMapIntensity
* @param alphaMap
* @param aoMap
* @param bumpMap
* @param diffuseMap
* @param displacementMap
* @param emissiveMap
* @param environmentMap
* @param lightMap
* @param metalnessMap
* @param normalMap
* @param roughnessMap
* @param specularMap
* @param parentEntity
* @constructor
*/
GameLib.D3.API.Material = function(
id,
materialType,
name,
opacity,
side,
transparent,
specular,
lightMapIntensity,
aoMapIntensity,
color,
emissive,
emissiveIntensity,
combine,
shininess,
reflectivity,
refractionRatio,
fog,
wireframe,
wireframeLineWidth,
wireframeLineCap,
wireframeLineJoin,
vertexColors,
skinning,
morphTargets,
morphNormals,
lineWidth,
lineCap,
lineJoin,
dashSize,
gapWidth,
blending,
blendSrc,
blendDst,
blendEquation,
depthTest,
depthFunc,
depthWrite,
polygonOffset,
polygonOffsetFactor,
polygonOffsetUnits,
alphaTest,
clippingPlanes,
clipShadows,
visible,
overdraw,
flatShading,
bumpScale,
normalScale,
displacementScale,
displacementBias,
roughness,
metalness,
pointSize,
pointSizeAttenuation,
spriteRotation,
envMapIntensity,
alphaMap,
aoMap,
bumpMap,
diffuseMap,
displacementMap,
emissiveMap,
environmentMap,
lightMap,
metalnessMap,
normalMap,
roughnessMap,
specularMap,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(materialType)) {
materialType = GameLib.D3.Material.MATERIAL_TYPE_STANDARD;
}
this.materialType = materialType;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Material (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(opacity)) {
opacity = 1.0;
}
this.opacity = opacity;
if (GameLib.Utils.UndefinedOrNull(side)) {
side = GameLib.D3.Material.TYPE_FRONT_SIDE;
}
this.side = side;
if (GameLib.Utils.UndefinedOrNull(transparent)) {
transparent = false;
}
this.transparent = transparent;
if (GameLib.Utils.UndefinedOrNull(specular)) {
specular = new GameLib.API.Color(0.06, 0.06, 0.06, 0.06);
}
this.specular = specular;
if (GameLib.Utils.UndefinedOrNull(lightMapIntensity)) {
lightMapIntensity = 1;
}
this.lightMapIntensity = lightMapIntensity;
if (GameLib.Utils.UndefinedOrNull(aoMapIntensity)) {
aoMapIntensity = 1;
}
this.aoMapIntensity = aoMapIntensity;
if (GameLib.Utils.UndefinedOrNull(color)) {
color = new GameLib.API.Color(1, 1, 1, 1)
}
this.color = color;
if (GameLib.Utils.UndefinedOrNull(emissive)) {
emissive = new GameLib.API.Color(0, 0, 0, 0);
}
this.emissive = emissive;
if (GameLib.Utils.UndefinedOrNull(emissiveIntensity)) {
emissiveIntensity = 1;
}
this.emissiveIntensity = emissiveIntensity;
if (GameLib.Utils.UndefinedOrNull(combine)) {
combine = GameLib.D3.Material.TYPE_MULTIPLY_OPERATION;
}
this.combine = combine;
if (GameLib.Utils.UndefinedOrNull(shininess)) {
shininess = 30;
}
this.shininess = shininess;
if (GameLib.Utils.UndefinedOrNull(reflectivity)) {
reflectivity = 1;
}
this.reflectivity = reflectivity;
if (GameLib.Utils.UndefinedOrNull(refractionRatio)) {
refractionRatio = 0.98;
}
this.refractionRatio = refractionRatio;
if (GameLib.Utils.UndefinedOrNull(fog)) {
fog = true;
}
this.fog = fog;
if (GameLib.Utils.UndefinedOrNull(wireframe)) {
wireframe = false;
}
this.wireframe = wireframe;
if (GameLib.Utils.UndefinedOrNull(wireframeLineWidth)) {
wireframeLineWidth = 1;
}
this.wireframeLineWidth = wireframeLineWidth;
if (GameLib.Utils.UndefinedOrNull(wireframeLineCap)) {
wireframeLineCap = 'round';
}
this.wireframeLineCap = wireframeLineCap;
if (GameLib.Utils.UndefinedOrNull(wireframeLineJoin)) {
wireframeLineJoin = 'round';
}
this.wireframeLineJoin = wireframeLineJoin;
if (GameLib.Utils.UndefinedOrNull(vertexColors)) {
vertexColors = GameLib.D3.Material.TYPE_FACE_COLORS;
}
this.vertexColors = vertexColors;
if (GameLib.Utils.UndefinedOrNull(skinning)) {
skinning = false;
}
this.skinning = skinning;
if (GameLib.Utils.UndefinedOrNull(morphTargets)) {
morphTargets = false;
}
this.morphTargets = morphTargets;
if (GameLib.Utils.UndefinedOrNull(morphNormals)) {
morphNormals = false;
}
this.morphNormals = morphNormals;
if (GameLib.Utils.UndefinedOrNull(overdraw)) {
overdraw = 0;
}
this.overdraw = overdraw;
if (GameLib.Utils.UndefinedOrNull(lineWidth)) {
lineWidth = 1;
}
this.lineWidth = lineWidth;
if (GameLib.Utils.UndefinedOrNull(lineCap)) {
lineCap = 'round';
}
this.lineCap = lineCap;
if (GameLib.Utils.UndefinedOrNull(lineJoin)) {
lineJoin = 'round';
}
this.lineJoin = lineJoin;
if (GameLib.Utils.UndefinedOrNull(dashSize)) {
dashSize = 3;
}
this.dashSize = dashSize;
if (GameLib.Utils.UndefinedOrNull(gapWidth)) {
gapWidth = 1;
}
this.gapWidth = gapWidth;
if (GameLib.Utils.UndefinedOrNull(blending)) {
blending = GameLib.D3.Material.TYPE_NORMAL_BLENDING;
}
this.blending = blending;
if (GameLib.Utils.UndefinedOrNull(blendSrc)) {
blendSrc = GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR;
}
this.blendSrc = blendSrc;
if (GameLib.Utils.UndefinedOrNull(blendDst)) {
blendDst = GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR;
}
this.blendDst = blendDst;
if (GameLib.Utils.UndefinedOrNull(blendEquation)) {
blendEquation = GameLib.D3.Material.TYPE_ADD_EQUATION;
}
this.blendEquation = blendEquation;
if (GameLib.Utils.UndefinedOrNull(depthTest)) {
depthTest = true;
}
this.depthTest = depthTest;
if (GameLib.Utils.UndefinedOrNull(depthFunc)) {
depthFunc = GameLib.D3.Material.TYPE_LESS_EQUAL_DEPTH;
}
this.depthFunc = depthFunc;
if (GameLib.Utils.UndefinedOrNull(depthWrite)) {
depthWrite = true;
}
this.depthWrite = depthWrite;
if (GameLib.Utils.UndefinedOrNull(polygonOffset)) {
polygonOffset = false;
}
this.polygonOffset = polygonOffset;
if (GameLib.Utils.UndefinedOrNull(polygonOffsetFactor)) {
polygonOffsetFactor = 1;
}
this.polygonOffsetFactor = polygonOffsetFactor;
if (GameLib.Utils.UndefinedOrNull(polygonOffsetUnits)) {
polygonOffsetUnits = 1;
}
this.polygonOffsetUnits = polygonOffsetUnits;
if (GameLib.Utils.UndefinedOrNull(alphaTest)) {
alphaTest = 0;
}
this.alphaTest = alphaTest;
if (GameLib.Utils.UndefinedOrNull(clippingPlanes)) {
clippingPlanes = [];
}
this.clippingPlanes = clippingPlanes;
if (GameLib.Utils.UndefinedOrNull(clipShadows)) {
clipShadows = false;
}
this.clipShadows = clipShadows;
if (GameLib.Utils.UndefinedOrNull(visible)) {
visible = true;
}
this.visible = visible;
if (GameLib.Utils.UndefinedOrNull(flatShading)) {
flatShading = false;
}
this.flatShading = flatShading;
if (GameLib.Utils.UndefinedOrNull(bumpScale)) {
bumpScale = 1;
}
this.bumpScale = bumpScale;
if (GameLib.Utils.UndefinedOrNull(normalScale)) {
normalScale = 1;
}
this.normalScale = normalScale;
if (GameLib.Utils.UndefinedOrNull(displacementScale)) {
displacementScale = 1;
}
this.displacementScale = displacementScale;
if (GameLib.Utils.UndefinedOrNull(displacementBias)) {
displacementBias = 0;
}
this.displacementBias = displacementBias;
if (GameLib.Utils.UndefinedOrNull(roughness)) {
roughness = 0.5;
}
this.roughness = roughness;
if (GameLib.Utils.UndefinedOrNull(metalness)) {
metalness = 0.5;
}
this.metalness = metalness;
if (GameLib.Utils.UndefinedOrNull(pointSize)) {
pointSize = 1;
}
this.pointSize = pointSize;
if (GameLib.Utils.UndefinedOrNull(pointSizeAttenuation)) {
pointSizeAttenuation = true;
}
this.pointSizeAttenuation = pointSizeAttenuation;
if (GameLib.Utils.UndefinedOrNull(spriteRotation)) {
spriteRotation = 0;
}
this.spriteRotation = spriteRotation;
if (GameLib.Utils.UndefinedOrNull(envMapIntensity)) {
envMapIntensity = 1.0;
}
this.envMapIntensity = envMapIntensity;
if (GameLib.Utils.UndefinedOrNull(alphaMap)) {
alphaMap = null;
}
this.alphaMap = alphaMap;
if (GameLib.Utils.UndefinedOrNull(aoMap)) {
aoMap = null;
}
this.aoMap = aoMap;
if (GameLib.Utils.UndefinedOrNull(bumpMap)) {
bumpMap = null;
}
this.bumpMap = bumpMap;
if (GameLib.Utils.UndefinedOrNull(diffuseMap)) {
diffuseMap = null;
}
this.diffuseMap = diffuseMap;
if (GameLib.Utils.UndefinedOrNull(displacementMap)) {
displacementMap = null;
}
this.displacementMap = displacementMap;
if (GameLib.Utils.UndefinedOrNull(emissiveMap)) {
emissiveMap = null;
}
this.emissiveMap = emissiveMap;
if (GameLib.Utils.UndefinedOrNull(environmentMap)) {
environmentMap = null;
}
this.environmentMap = environmentMap;
if (GameLib.Utils.UndefinedOrNull(lightMap)) {
lightMap = null;
}
this.lightMap = lightMap;
if (GameLib.Utils.UndefinedOrNull(metalnessMap)) {
metalnessMap = null;
}
this.metalnessMap = metalnessMap;
if (GameLib.Utils.UndefinedOrNull(normalMap)) {
normalMap = null;
}
this.normalMap = normalMap;
if (GameLib.Utils.UndefinedOrNull(roughnessMap)) {
roughnessMap = null;
}
this.roughnessMap = roughnessMap;
if (GameLib.Utils.UndefinedOrNull(specularMap)) {
specularMap = null;
}
this.specularMap = specularMap;
GameLib.API.Component.call(
this,
GameLib.Component.MATERIAL,
parentEntity
);
this.needsUpdate = false;
};
GameLib.D3.API.Material.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.D3.API.Material.prototype.constructor = GameLib.D3.API.Material;
/**
* Returns an API Material from an Object material
* @param objectMaterial
* @constructor
*/
GameLib.D3.API.Material.FromObject = function(objectMaterial) {
var apiAlphaMap = null;
var apiAoMap = null;
var apiBumpMap = null;
var apiDiffuseMap = null;
var apiDisplacementMap = null;
var apiEmissiveMap = null;
var apiEnvironmentMap = null;
var apiLightMap = null;
var apiMetalnessMap = null;
var apiNormalMap = null;
var apiRoughnessMap = null;
var apiSpecularMap = null;
if (objectMaterial.alphaMap) {
apiAlphaMap = objectMaterial.alphaMap;
}
if (objectMaterial.aoMap) {
apiAoMap = objectMaterial.aoMap;
}
if (objectMaterial.bumpMap) {
apiBumpMap = objectMaterial.bumpMap;
}
if (objectMaterial.diffuseMap) {
apiDiffuseMap = objectMaterial.diffuseMap;
}
if (objectMaterial.displacementMap) {
apiDisplacementMap = objectMaterial.displacementMap;
}
if (objectMaterial.emissiveMap) {
apiEmissiveMap = objectMaterial.emissiveMap;
}
if (objectMaterial.environmentMap) {
apiEnvironmentMap = objectMaterial.environmentMap;
}
if (objectMaterial.lightMap) {
apiLightMap = objectMaterial.lightMap;
}
if (objectMaterial.metalnessMap) {
apiMetalnessMap = objectMaterial.metalnessMap;
}
if (objectMaterial.normalMap) {
apiNormalMap = objectMaterial.normalMap;
}
if (objectMaterial.roughnessMap) {
apiRoughnessMap = objectMaterial.roughnessMap;
}
if (objectMaterial.specularMap) {
apiSpecularMap = objectMaterial.specularMap;
}
return new GameLib.D3.API.Material(
objectMaterial.id,
objectMaterial.materialType,
objectMaterial.name,
objectMaterial.opacity,
objectMaterial.side,
objectMaterial.transparent,
GameLib.API.Color.FromObject(objectMaterial.specular),
objectMaterial.lightMapIntensity,
objectMaterial.aoMapIntensity,
GameLib.API.Color.FromObject(objectMaterial.color),
GameLib.API.Color.FromObject(objectMaterial.emissive),
objectMaterial.emissiveIntensity,
objectMaterial.combine,
objectMaterial.shininess,
objectMaterial.reflectivity,
objectMaterial.refractionRatio,
objectMaterial.fog,
objectMaterial.wireframe,
objectMaterial.wireframeLineWidth,
objectMaterial.wireframeLineCap,
objectMaterial.wireframeLineJoin,
objectMaterial.vertexColors,
objectMaterial.skinning,
objectMaterial.morphTargets,
objectMaterial.morphNormals,
objectMaterial.lineWidth,
objectMaterial.lineCap,
objectMaterial.lineJoin,
objectMaterial.dashSize,
objectMaterial.gapWidth,
objectMaterial.blending,
objectMaterial.blendSrc,
objectMaterial.blendDst,
objectMaterial.blendEquation,
objectMaterial.depthTest,
objectMaterial.depthFunc,
objectMaterial.depthWrite,
objectMaterial.polygonOffset,
objectMaterial.polygonOffsetFactor,
objectMaterial.polygonOffsetUnits,
objectMaterial.alphaTest,
objectMaterial.clippingPlanes,
objectMaterial.clipShadows,
objectMaterial.visible,
objectMaterial.overdraw,
objectMaterial.flatShading,
objectMaterial.bumpScale,
objectMaterial.normalScale,
objectMaterial.displacementScale,
objectMaterial.displacementBias,
objectMaterial.roughness,
objectMaterial.metalness,
objectMaterial.pointSize,
objectMaterial.pointSizeAttenuation,
objectMaterial.spriteRotation,
objectMaterial.envMapIntensity,
apiAlphaMap,
apiAoMap,
apiBumpMap,
apiDiffuseMap,
apiDisplacementMap,
apiEmissiveMap,
apiEnvironmentMap,
apiLightMap,
apiMetalnessMap,
apiNormalMap,
apiRoughnessMap,
apiSpecularMap,
objectMaterial.parentEntity
)
};

View File

@ -104,7 +104,11 @@ GameLib.D3.API.Mesh = function(
this.skinWeights = skinWeights;
if (GameLib.Utils.UndefinedOrNull(materials) || (materials instanceof Array && materials.length === 0)) {
materials = [new GameLib.D3.API.Material(null, GameLib.D3.Material.MATERIAL_TYPE_STANDARD, 'Material (' + this.name + ')')];
materials = [
new GameLib.D3.API.Material.Standard({
name : 'Material ' + this.id
})
];
}
this.materials = materials;

View File

@ -0,0 +1,70 @@
/**
* GameLib.D3.API.Pass
* @param id
* @param name
* @param passType
* @param parentEntity
* @param renderToScreen
* @constructor
*/
GameLib.D3.API.Pass = function (
id,
name,
passType,
parentEntity,
renderToScreen
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Pass (' + id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(passType)) {
passType = GameLib.D3.API.Pass.PASS_TYPE_RENDER;
}
this.passType = passType;
if (GameLib.Utils.UndefinedOrNull(renderToScreen)) {
renderToScreen = false;
}
this.renderToScreen = renderToScreen;
var componentType = null;
switch (this.passType) {
case GameLib.D3.API.Pass.PASS_TYPE_RENDER:
componentType = GameLib.Component.PASS_RENDER;
break;
case GameLib.D3.API.Pass.PASS_TYPE_SSAO:
componentType = GameLib.Component.PASS_SSAO;
break;
case GameLib.D3.API.Pass.PASS_TYPE_BLOOM:
componentType = GameLib.Component.PASS_BLOOM;
break;
case GameLib.D3.API.Pass.PASS_TYPE_FXAA:
componentType = GameLib.Component.PASS_FXAA;
break;
default :
throw new Error('unsupported pass type: ' + this.passType);
}
GameLib.API.Component.call(
this,
componentType,
parentEntity
);
};
GameLib.D3.API.Pass.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.D3.API.Pass.prototype.constructor = GameLib.D3.API.Pass;
GameLib.D3.API.Pass.PASS_TYPE_NONE = 0x0;
GameLib.D3.API.Pass.PASS_TYPE_RENDER = 0x1;
GameLib.D3.API.Pass.PASS_TYPE_SSAO = 0x2;
GameLib.D3.API.Pass.PASS_TYPE_BLOOM = 0x3;
GameLib.D3.API.Pass.PASS_TYPE_FXAA = 0x4;

View File

@ -0,0 +1,65 @@
/**
* GameLib.D3.API.Pass.Bloom
* @param apiPass
* @param width
* @param height
* @param strength
* @param radius
* @param threshold
* @constructor
*/
GameLib.D3.API.Pass.Bloom = function (
apiPass,
width,
height,
strength,
radius,
threshold
) {
if (GameLib.Utils.UndefinedOrNull(apiPass)) {
apiPass = {
passType: GameLib.D3.API.Pass.PASS_TYPE_BLOOM
};
}
if (GameLib.Utils.UndefinedOrNull(apiPass.passType)) {
apiPass.passType = GameLib.D3.API.Pass.PASS_TYPE_BLOOM;
}
if (GameLib.Utils.UndefinedOrNull(width)) {
width = 512;
}
this.width = width;
if (GameLib.Utils.UndefinedOrNull(height)) {
height = 512;
}
this.height = height;
if (GameLib.Utils.UndefinedOrNull(strength)) {
strength = 1.5;
}
this.strength = strength;
if (GameLib.Utils.UndefinedOrNull(radius)) {
radius = 0.4;
}
this.radius = radius;
if (GameLib.Utils.UndefinedOrNull(threshold)) {
threshold = 0.85;
}
this.threshold = threshold;
GameLib.D3.API.Pass.call(
this,
apiPass.id,
apiPass.name,
apiPass.passType,
apiPass.parentEntity,
apiPass.renderToScreen
)
};
GameLib.D3.API.Pass.Bloom.prototype = Object.create(GameLib.D3.API.Pass.prototype);
GameLib.D3.API.Pass.Bloom.prototype.constructor = GameLib.D3.API.Pass.Bloom;

View File

@ -0,0 +1,44 @@
/**
* GameLib.D3.API.Pass.FXAA
* @param apiPass
* @param width
* @param height
* @constructor
*/
GameLib.D3.API.Pass.FXAA = function (
apiPass,
width,
height
) {
if (GameLib.Utils.UndefinedOrNull(apiPass)) {
apiPass = {
passType: GameLib.D3.API.Pass.PASS_TYPE_FXAA
};
}
if (GameLib.Utils.UndefinedOrNull(apiPass.passType)) {
apiPass.passType = GameLib.D3.API.Pass.PASS_TYPE_FXAA;
}
if (GameLib.Utils.UndefinedOrNull(width)) {
width = 512;
}
this.width = width;
if (GameLib.Utils.UndefinedOrNull(height)) {
height = 512;
}
this.height = height;
GameLib.D3.API.Pass.call(
this,
apiPass.id,
apiPass.name,
apiPass.passType,
apiPass.parentEntity,
apiPass.renderToScreen
)
};
GameLib.D3.API.Pass.FXAA.prototype = Object.create(GameLib.D3.API.Pass.prototype);
GameLib.D3.API.Pass.FXAA.prototype.constructor = GameLib.D3.API.Pass.FXAA;

View File

@ -0,0 +1,44 @@
/**
* GameLib.D3.API.Pass.Render
* @param apiPass
* @param camera
* @param scene
* @constructor
*/
GameLib.D3.API.Pass.Render = function (
apiPass,
scene,
camera
) {
if (GameLib.Utils.UndefinedOrNull(apiPass)) {
apiPass = {
passType: GameLib.D3.API.Pass.PASS_TYPE_RENDER
};
}
if (GameLib.Utils.UndefinedOrNull(apiPass.passType)) {
apiPass.passType = GameLib.D3.API.Pass.PASS_TYPE_RENDER;
}
if (GameLib.Utils.UndefinedOrNull(scene)) {
scene = null;
}
this.scene = scene;
if (GameLib.Utils.UndefinedOrNull(camera)) {
camera = null;
}
this.camera = camera;
GameLib.D3.API.Pass.call(
this,
apiPass.id,
apiPass.name,
apiPass.passType,
apiPass.parentEntity,
apiPass.renderToScreen
)
};
GameLib.D3.API.Pass.Render.prototype = Object.create(GameLib.D3.API.Pass.prototype);
GameLib.D3.API.Pass.Render.prototype.constructor = GameLib.D3.API.Pass.Render;

View File

@ -0,0 +1,44 @@
/**
* GameLib.D3.API.Pass.SSAO
* @param apiPass
* @param camera
* @param scene
* @constructor
*/
GameLib.D3.API.Pass.SSAO = function (
apiPass,
scene,
camera
) {
if (GameLib.Utils.UndefinedOrNull(apiPass)) {
apiPass = {
passType: GameLib.D3.API.Pass.PASS_TYPE_SSAO
};
}
if (GameLib.Utils.UndefinedOrNull(apiPass.passType)) {
apiPass.passType = GameLib.D3.API.Pass.PASS_TYPE_SSAO;
}
if (GameLib.Utils.UndefinedOrNull(scene)) {
scene = null;
}
this.scene = scene;
if (GameLib.Utils.UndefinedOrNull(camera)) {
camera = null;
}
this.camera = camera;
GameLib.D3.API.Pass.call(
this,
apiPass.id,
apiPass.name,
apiPass.passType,
apiPass.parentEntity,
apiPass.renderToScreen
)
};
GameLib.D3.API.Pass.SSAO.prototype = Object.create(GameLib.D3.API.Pass.prototype);
GameLib.D3.API.Pass.SSAO.prototype.constructor = GameLib.D3.API.Pass.SSAO;

View File

@ -1,85 +0,0 @@
/**
* This component renders a scene
* @param id String
* @param name String
* @param passType
* @param camera
* @param scene
* @param renderToScreen
* @param parentEntity
* @constructor
*/
GameLib.D3.API.Pass = function (
id,
name,
passType,
camera,
scene,
renderToScreen,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Pass (' + id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(passType)) {
passType = GameLib.D3.Pass.PASS_TYPE_RENDER;
}
this.passType = passType;
if (GameLib.Utils.UndefinedOrNull(camera)) {
camera = null;
}
this.camera = camera;
if (GameLib.Utils.UndefinedOrNull(scene)) {
scene = null;
}
this.scene = scene;
if (GameLib.Utils.UndefinedOrNull(renderToScreen)) {
if (this.passType === GameLib.D3.Pass.PASS_TYPE_RENDER) {
renderToScreen = false;
} else if (GameLib.D3.Pass.PASS_TYPE_COPY_SHADER) {
renderToScreen = true;
} else {
console.warn('Unsupported Render Pass Type : ' + this.passType);
throw new Error('Unsupported Render Pass Type : ' + this.passType);
}
}
this.renderToScreen = renderToScreen;
GameLib.API.Component.call(
this,
GameLib.Component.PASS,
parentEntity
);
};
GameLib.D3.API.Pass.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.D3.API.Pass.prototype.constructor = GameLib.D3.API.Pass;
/**
* Object to GameLib.D3.API.Pass
* @param objectComponent
* @constructor
*/
GameLib.D3.API.Pass.FromObject = function(objectComponent) {
return new GameLib.D3.API.Pass(
objectComponent.id,
objectComponent.name,
objectComponent.passType,
objectComponent.camera,
objectComponent.scene,
objectComponent.renderToScreen,
objectComponent.parentEntity
);
};

View File

@ -0,0 +1,112 @@
/**
* GameLib.D3.API.RenderTarget
* @param id
* @param name
* @param renderTargetType
* @param width
* @param height
* @param stencilBuffer
* @param textureParameters
* @param texture
* @param parentEntity
* @constructor
*/
GameLib.D3.API.RenderTarget = function (
id,
name,
renderTargetType,
width,
height,
stencilBuffer,
textureParameters,
texture,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Render Target (' + id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(renderTargetType)) {
renderTargetType = GameLib.D3.API.RenderTarget.TARGET_TYPE_NORMAL;
}
this.renderTargetType = renderTargetType;
if (GameLib.Utils.UndefinedOrNull(width)) {
width = 512;
}
this.width = width;
if (GameLib.Utils.UndefinedOrNull(height)) {
height = 512;
}
this.height = height;
if (GameLib.Utils.UndefinedOrNull(stencilBuffer)) {
stencilBuffer = false;
}
this.stencilBuffer = stencilBuffer;
if (GameLib.Utils.UndefinedOrNull(textureParameters)) {
textureParameters = null;
}
this.textureParameters = textureParameters;
if (GameLib.Utils.UndefinedOrNull(texture)) {
switch (this.renderTargetType) {
case GameLib.D3.API.RenderTarget.TARGET_TYPE_NORMAL :
texture = new GameLib.D3.API.Texture(
null,
'Texture (Render Target ' + this.id + ')',
GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE
);
break;
case GameLib.D3.API.RenderTarget.TARGET_TYPE_CUBE :
texture = new GameLib.D3.API.Texture(
null,
'Cube Texture (Render Target ' + this.id + ')',
GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE
);
break;
default :
throw new Error('Unknown render target type: ' + this.renderTargetType);
}
}
this.texture = texture;
var componentType = null;
switch (this.renderTargetType) {
case GameLib.D3.API.RenderTarget.TARGET_TYPE_NORMAL :
componentType = GameLib.Component.RENDER_TARGET;
break;
case GameLib.D3.API.RenderTarget.TARGET_TYPE_CUBE :
componentType = GameLib.Component.RENDER_TARGET_CUBE;
break;
default :
throw new Error('Unknown render target type: ' + this.renderTargetType);
}
GameLib.API.Component.call(
this,
componentType,
parentEntity
);
};
GameLib.D3.API.RenderTarget.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.D3.API.RenderTarget.prototype.constructor = GameLib.D3.API.RenderTarget;
GameLib.D3.API.RenderTarget.TARGET_TYPE_NORMAL = 0x1;
GameLib.D3.API.RenderTarget.TARGET_TYPE_CUBE = 0x2;

View File

@ -0,0 +1,36 @@
/**
* GameLib.D3.API.RenderTarget.Cube
* @constructor
* @param apiRenderTarget
*/
GameLib.D3.API.RenderTarget.Cube = function (
apiRenderTarget
) {
if (GameLib.Utils.UndefinedOrNull(apiRenderTarget)) {
apiRenderTarget = {
renderTargetType : GameLib.D3.API.RenderTarget.TARGET_TYPE_CUBE
};
}
if (GameLib.Utils.UndefinedOrNull(apiRenderTarget.renderTargetType)) {
apiRenderTarget.renderTargetType = GameLib.D3.API.RenderTarget.TARGET_TYPE_CUBE;
}
GameLib.D3.API.RenderTarget.call(
this,
apiRenderTarget.id,
apiRenderTarget.name,
apiRenderTarget.renderTargetType,
apiRenderTarget.width,
apiRenderTarget.height,
apiRenderTarget.stencilBuffer,
apiRenderTarget.textureParameters,
apiRenderTarget.texture,
apiRenderTarget.parentEntity
);
};
GameLib.D3.API.RenderTarget.Cube.prototype = Object.create(GameLib.D3.API.RenderTarget.prototype);
GameLib.D3.API.RenderTarget.Cube.prototype.constructor = GameLib.D3.API.RenderTarget.Cube;

View File

@ -1,82 +0,0 @@
/**
* RenderTarget is used to render a scene to a target
* @param id
* @param name
* @param width
* @param height
* @param stencilBuffer
* @param texture
* @param parentEntity
* @constructor
*/
GameLib.D3.API.RenderTarget = function (
id,
name,
width,
height,
stencilBuffer,
texture,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Render Target (' + id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(width)) {
width = 512;
}
this.width = width;
if (GameLib.Utils.UndefinedOrNull(height)) {
height = 512;
}
this.height = height;
if (GameLib.Utils.UndefinedOrNull(stencilBuffer)) {
stencilBuffer = false;
}
this.stencilBuffer = stencilBuffer;
if (GameLib.Utils.UndefinedOrNull(texture)) {
texture = new GameLib.D3.API.Texture(
null,
null,
null,
new GameLib.API.Image()
);
}
this.texture = texture;
GameLib.API.Component.call(
this,
GameLib.Component.RENDER_TARGET,
parentEntity
);
};
GameLib.D3.API.RenderTarget.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.D3.API.RenderTarget.prototype.constructor = GameLib.D3.API.RenderTarget;
/**
* Object to GameLib.D3.API.RenderTarget
* @param objectComponent
* @constructor
*/
GameLib.D3.API.RenderTarget.FromObject = function(objectComponent) {
return new GameLib.D3.API.RenderTarget(
objectComponent.id,
objectComponent.name,
objectComponent.width,
objectComponent.height,
objectComponent.stencilBuffer,
objectComponent.texture,
objectComponent.parentEntity
);
};

View File

@ -1,11 +1,10 @@
/**
* Renderer Data
* GameLib.D3.API.Renderer
* @param id
* @param name
* @param width
* @param height
* @param renderMode
* @param lastRenderMode
* @param autoClear
* @param autoClearColor
* @param autoClearDepth
@ -32,20 +31,12 @@
* @param preserveDrawingBuffer
* @param depth
* @param logarithmicDepthBuffer
* @param windowSize
* @param aspectRatio
* @param scaleMode
* @param logicalSize
* @param offset
* @param canvas
* @param renderTarget
* @param localClippingEnabled
* @param clippingPlanes
* @param clearColor
* @param camera
* @param editCamera
* @param scenes
* @param defaultScene
* @param viewports
* @param parentEntity
* @constructor
@ -56,7 +47,6 @@ GameLib.D3.API.Renderer = function (
width,
height,
renderMode,
lastRenderMode,
autoClear,
autoClearColor,
autoClearDepth,
@ -84,19 +74,11 @@ GameLib.D3.API.Renderer = function (
depth,
logarithmicDepthBuffer,
localClippingEnabled,
aspectRatio,
scaleMode,
windowSize,
logicalSize,
offset,
canvas,
renderTarget,
clippingPlanes,
clearColor,
camera,
editCamera,
scenes,
defaultScene,
viewports,
parentEntity
) {
@ -125,11 +107,6 @@ GameLib.D3.API.Renderer = function (
}
this.renderMode = renderMode;
if (GameLib.Utils.UndefinedOrNull(lastRenderMode)) {
lastRenderMode = GameLib.D3.API.Renderer.MODE_CANVAS;
}
this.lastRenderMode = lastRenderMode;
if (GameLib.Utils.UndefinedOrNull(autoClear)) {
autoClear = true;
}
@ -265,32 +242,6 @@ GameLib.D3.API.Renderer = function (
}
this.localClippingEnabled = localClippingEnabled;
if (GameLib.Utils.UndefinedOrNull(aspectRatio)) {
aspectRatio = GameLib.D3.API.Renderer.ASPECT_RATIO_3_2;
}
this.aspectRatio = aspectRatio;
if (GameLib.Utils.UndefinedOrNull(scaleMode)) {
scaleMode = GameLib.D3.API.Renderer.SCALE_MODE_LETTERBOX;
}
this.scaleMode = scaleMode;
if (GameLib.Utils.UndefinedOrNull(windowSize)) {
windowSize = new GameLib.API.Vector2(
512,
512
);
}
this.windowSize = windowSize;
if (GameLib.Utils.UndefinedOrNull(logicalSize)) {
logicalSize = new GameLib.API.Vector2(
480,
320
);
}
this.logicalSize = logicalSize;
if (GameLib.Utils.UndefinedOrNull(offset)) {
offset = new GameLib.API.Vector2(0,0);
}
@ -300,8 +251,8 @@ GameLib.D3.API.Renderer = function (
canvas = new GameLib.API.Canvas(
null,
null,
this.windowSize.x,
this.windowSize.y
512,
512
);
}
this.canvas = canvas;
@ -321,36 +272,6 @@ GameLib.D3.API.Renderer = function (
}
this.clearColor = clearColor;
if (GameLib.Utils.UndefinedOrNull(camera)) {
camera = new GameLib.D3.API.Camera.Stereo(
{
name : 'Render Camera',
aspect : 3 / 2
}
);
}
this.camera = camera;
if (GameLib.Utils.UndefinedOrNull(editCamera)) {
editCamera = new GameLib.D3.API.Camera.Stereo(
{
name : 'Edit Camera',
aspect : 3 / 2
}
);
}
this.editCamera = editCamera;
if (GameLib.Utils.UndefinedOrNull(scenes)) {
scenes = [new GameLib.D3.API.Scene()];
}
this.scenes = scenes;
if (GameLib.Utils.UndefinedOrNull(defaultScene)) {
defaultScene = this.scenes[0];
}
this.defaultScene = defaultScene;
if (GameLib.Utils.UndefinedOrNull(viewports)) {
viewports = [new GameLib.D3.API.Viewport(
null,
@ -377,7 +298,6 @@ GameLib.D3.API.Renderer.prototype.constructor = GameLib.D3.API.Renderer;
GameLib.D3.API.Renderer.MODE_CANVAS = 0x1;
GameLib.D3.API.Renderer.MODE_TARGET = 0x2;
GameLib.D3.API.Renderer.MODE_CANVAS_AND_TARGET = 0x3;
GameLib.D3.API.Renderer.MODE_EDIT = 0x4;
GameLib.D3.API.Renderer.SHADOW_MAP_TYPE_BASIC = 0;
GameLib.D3.API.Renderer.SHADOW_MAP_TYPE_PCF = 1;
@ -387,15 +307,3 @@ GameLib.D3.API.Renderer.TONE_MAPPING_LINEAR = 1;
GameLib.D3.API.Renderer.TONE_MAPPING_REINHARD = 2;
GameLib.D3.API.Renderer.TONE_MAPPING_UNCHARTED_2 = 3;
GameLib.D3.API.Renderer.TONE_MAPPING_CINEON = 4;
GameLib.D3.API.Renderer.ASPECT_RATIO_NONE = 0x1;
GameLib.D3.API.Renderer.ASPECT_RATIO_4_3 = 0x2;
GameLib.D3.API.Renderer.ASPECT_RATIO_3_2 = 0x3;
GameLib.D3.API.Renderer.ASPECT_RATIO_16_10 = 0x4;
GameLib.D3.API.Renderer.ASPECT_RATIO_17_10 = 0x5;
GameLib.D3.API.Renderer.ASPECT_RATIO_16_9 = 0x6;
GameLib.D3.API.Renderer.SCALE_MODE_NONE = 0x1;
GameLib.D3.API.Renderer.SCALE_MODE_LETTERBOX = 0x2;
GameLib.D3.API.Renderer.SCALE_MODE_ZOOM_TO_BIGGER = 0x3;
GameLib.D3.API.Renderer.SCALE_MODE_NON_UNIFORM = 0x4;

View File

@ -1,63 +1,64 @@
/**
* Raw Texture API object - should always correspond with the Texture Schema
* GameLib.D3.API.Texture
* @param id
* @param textureType
* @param name
* @param image
* @param images
* @param textureType
* @param parentEntity
* @param parentMaterials
* @param mipmaps
* @param mapping
* @param wrapS
* @param wrapT
* @param repeat
* @param data
* @param format
* @param mapping
* @param magFilter
* @param minFilter
* @param storageType
* @param textureType
* @param anisotropy
* @param format
* @param storageType
* @param offset
* @param generateMipmaps
* @param flipY
* @param mipmaps
* @param unpackAlignment
* @param repeat
* @param rotation
* @param center
* @param matrixAutoUpdate
* @param generateMipMaps
* @param premultiplyAlpha
* @param flipY
* @param unpackAlignment
* @param encoding
* @param canvas
* @param version
* @param animated
* @param reverseAnimation
* @param forward
* @param parentEntity
* @constructor
*/
GameLib.D3.API.Texture = function(
id,
textureType,
name,
image,
images,
textureType,
parentEntity,
parentMaterials,
mipmaps,
mapping,
wrapS,
wrapT,
repeat,
data,
format,
mapping,
magFilter,
minFilter,
storageType,
anisotropy,
format,
storageType,
offset,
generateMipmaps,
flipY,
mipmaps,
unpackAlignment,
repeat,
rotation,
center,
matrixAutoUpdate,
generateMipMaps,
premultiplyAlpha,
flipY,
unpackAlignment,
encoding,
canvas,
version,
animated,
reverseAnimation,
forward,
parentEntity
forward
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
@ -65,25 +66,30 @@ GameLib.D3.API.Texture = function(
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(textureType)) {
textureType = GameLib.D3.API.Texture.TEXTURE_TYPE_NORMAL;
}
this.textureType = textureType;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Texture (' + id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(image)) {
image = null;
if (GameLib.Utils.UndefinedOrNull(textureType)) {
textureType = GameLib.D3.API.Texture.TEXTURE_TYPE_NONE;
}
this.image = image;
this.textureType = textureType;
if (GameLib.Utils.UndefinedOrNull(images)) {
images = [];
if (GameLib.Utils.UndefinedOrNull(parentMaterials)) {
parentMaterials = [];
}
this.images = images;
this.parentMaterials = parentMaterials;
if (GameLib.Utils.UndefinedOrNull(mipmaps)) {
mipmaps = [];
}
this.mipmaps = mipmaps;
if (GameLib.Utils.UndefinedOrNull(mapping)) {
mapping = GameLib.D3.API.Texture.TYPE_UV_MAPPING;
}
this.mapping = mapping;
if (GameLib.Utils.UndefinedOrNull(wrapS)) {
wrapS = GameLib.D3.API.Texture.TYPE_REPEAT_WRAPPING;
@ -95,26 +101,6 @@ GameLib.D3.API.Texture = function(
}
this.wrapT = wrapT;
if (GameLib.Utils.UndefinedOrNull(repeat)) {
repeat = new GameLib.API.Vector2(1, 1);
}
this.repeat = repeat;
if (GameLib.Utils.UndefinedOrNull(data)) {
data = null;
}
this.data = data;
if (GameLib.Utils.UndefinedOrNull(format)) {
format = GameLib.D3.API.Texture.TYPE_RGBA_FORMAT;
}
this.format = format;
if (GameLib.Utils.UndefinedOrNull(mapping)) {
mapping = GameLib.D3.API.Texture.TYPE_UV_MAPPING;
}
this.mapping = mapping;
if (GameLib.Utils.UndefinedOrNull(magFilter)) {
magFilter = GameLib.D3.API.Texture.TYPE_LINEAR_FILTER;
}
@ -125,55 +111,75 @@ GameLib.D3.API.Texture = function(
}
this.minFilter = minFilter;
if (GameLib.Utils.UndefinedOrNull(storageType)) {
storageType = GameLib.D3.API.Texture.TYPE_UNSIGNED_BYTE;
}
this.storageType = storageType;
if (GameLib.Utils.UndefinedOrNull(anisotropy)) {
anisotropy = 1;
}
this.anisotropy = anisotropy;
if (GameLib.Utils.UndefinedOrNull(format)) {
format = GameLib.D3.API.Texture.TYPE_RGBA_FORMAT;
}
this.format = format;
if (GameLib.Utils.UndefinedOrNull(storageType)) {
storageType = GameLib.D3.API.Texture.TYPE_UNSIGNED_BYTE;
}
this.storageType = storageType;
if (GameLib.Utils.UndefinedOrNull(offset)) {
offset = new GameLib.API.Vector2(0, 0);
}
this.offset = offset;
if (GameLib.Utils.UndefinedOrNull(generateMipmaps)) {
generateMipmaps = true;
if (GameLib.Utils.UndefinedOrNull(repeat)) {
repeat = new GameLib.API.Vector2(1, 1);
}
this.generateMipmaps = generateMipmaps;
this.repeat = repeat;
if (GameLib.Utils.UndefinedOrNull(flipY)) {
flipY = true;
if (GameLib.Utils.UndefinedOrNull(rotation)) {
rotation = 0;
}
this.flipY = flipY;
this.rotation = rotation;
if (GameLib.Utils.UndefinedOrNull(mipmaps)) {
mipmaps = [];
if (GameLib.Utils.UndefinedOrNull(center)) {
center = new GameLib.API.Vector2(0.5, 0.5);
}
this.mipmaps = mipmaps;
this.center = center;
if (GameLib.Utils.UndefinedOrNull(unpackAlignment)) {
unpackAlignment = 4;
if (GameLib.Utils.UndefinedOrNull(matrixAutoUpdate)) {
matrixAutoUpdate = true;
}
this.unpackAlignment = unpackAlignment;
this.matrixAutoUpdate = matrixAutoUpdate;
if (GameLib.Utils.UndefinedOrNull(generateMipMaps)) {
generateMipMaps = true;
}
this.generateMipMaps = generateMipMaps;
if (GameLib.Utils.UndefinedOrNull(premultiplyAlpha)) {
premultiplyAlpha = false;
}
this.premultiplyAlpha = premultiplyAlpha;
if (GameLib.Utils.UndefinedOrNull(flipY)) {
flipY = true;
}
this.flipY = flipY;
if (GameLib.Utils.UndefinedOrNull(unpackAlignment)) {
unpackAlignment = 4;
}
this.unpackAlignment = unpackAlignment;
if (GameLib.Utils.UndefinedOrNull(encoding)) {
encoding = GameLib.D3.API.Texture.TYPE_LINEAR_ENCODING;
}
this.encoding = encoding;
if (GameLib.Utils.UndefinedOrNull(canvas)) {
canvas = null;
if (GameLib.Utils.UndefinedOrNull(version)) {
version = 0
}
this.canvas = canvas;
this.version = version;
if (GameLib.Utils.UndefinedOrNull(animated)) {
animated = false;
@ -190,11 +196,27 @@ GameLib.D3.API.Texture = function(
}
this.forward = forward;
var componentType = null;
switch (this.textureType) {
case GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE :
componentType = GameLib.Component.TEXTURE_IMAGE;
break;
case GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE :
componentType = GameLib.Component.TEXTURE_CUBE;
break;
case GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS :
componentType = GameLib.Component.TEXTURE_CANVAS;
break;
default :
throw new Error('Wrong texture type: ' + this.textureType);
}
this.needsUpdate = false;
GameLib.API.Component.call(
this,
GameLib.Component.TEXTURE,
componentType,
parentEntity
);
};
@ -271,44 +293,11 @@ GameLib.D3.API.Texture.TYPE_RGBM7_ENCODING = 3004;
GameLib.D3.API.Texture.TYPE_RGBM16_ENCODING = 3005;
GameLib.D3.API.Texture.TYPE_RGBD_ENCODING = 3006; // MAXRANGE IS 256.
GameLib.D3.API.Texture.TEXTURE_TYPE_NORMAL = 0x1;
/**
* Texture Component Types
* @type {number}
*/
GameLib.D3.API.Texture.TEXTURE_TYPE_NONE = 0x0;
GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE = 0x1;
GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE = 0x2;
GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS = 0x3;
/**
* Creates an API texture from Object data
* @param objectTexture
* @constructor
*/
GameLib.D3.API.Texture.FromObject = function(objectTexture) {
return new GameLib.D3.API.Texture(
objectTexture.id,
objectTexture.typeId || objectTexture.textureType,
objectTexture.name,
objectTexture.image,
objectTexture.images,
objectTexture.wrapS,
objectTexture.wrapT,
GameLib.API.Vector2.FromObject(objectTexture.repeat),
objectTexture.data,
objectTexture.format,
objectTexture.mapping,
objectTexture.magFilter,
objectTexture.minFilter,
objectTexture.storageType,
objectTexture.anisotropy,
GameLib.API.Vector2.FromObject(objectTexture.offset),
objectTexture.generateMipmaps,
objectTexture.flipY,
objectTexture.mipmaps,
objectTexture.unpackAlignment,
objectTexture.premultiplyAlpha,
objectTexture.encoding,
objectTexture.canvas,
objectTexture.animated,
objectTexture.reverseAnimation,
objectTexture.forward,
objectTexture.parentEntity
)
};

View File

@ -0,0 +1,61 @@
/**
* GameLib.D3.API.Texture.Canvas
* @constructor
* @param apiTexture
* @param canvas
*/
GameLib.D3.API.Texture.Canvas = function(
apiTexture,
canvas
) {
if (GameLib.Utils.UndefinedOrNull(apiTexture)) {
apiTexture = {
textureType: GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS
};
}
if (GameLib.Utils.UndefinedOrNull(apiTexture.textureType)) {
apiTexture.textureType = GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS;
}
if (GameLib.Utils.UndefinedOrNull(canvas)) {
canvas = new GameLib.API.Canvas();
}
this.canvas = canvas;
GameLib.D3.API.Texture.call(
this,
apiTexture.id,
apiTexture.name,
apiTexture.textureType,
apiTexture.parentEntity,
apiTexture.parentMaterials,
apiTexture.mipmaps,
apiTexture.mapping,
apiTexture.wrapS,
apiTexture.wrapT,
apiTexture.magFilter,
apiTexture.minFilter,
apiTexture.anisotropy,
apiTexture.format,
apiTexture.storageType,
apiTexture.offset,
apiTexture.repeat,
apiTexture.rotation,
apiTexture.center,
apiTexture.matrixAutoUpdate,
apiTexture.generateMipMaps,
apiTexture.premultiplyAlpha,
apiTexture.flipY,
apiTexture.unpackAlignment,
apiTexture.encoding,
apiTexture.version,
apiTexture.animated,
apiTexture.reverseAnimation,
apiTexture.forward
);
};
GameLib.D3.API.Texture.Canvas.prototype = Object.create(GameLib.D3.API.Texture.prototype);
GameLib.D3.API.Texture.Canvas.prototype.constructor = GameLib.D3.API.Texture.Canvas;

View File

@ -0,0 +1,68 @@
/**
* GameLib.D3.API.Texture.Cube
* @constructor
* @param apiTexture
* @param images
*/
GameLib.D3.API.Texture.Cube = function(
apiTexture,
images
) {
if (GameLib.Utils.UndefinedOrNull(apiTexture)) {
apiTexture = {
textureType: GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE
};
}
if (GameLib.Utils.UndefinedOrNull(apiTexture.textureType)) {
apiTexture.textureType = GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE;
}
if (GameLib.Utils.UndefinedOrNull(images)) {
images = [
new GameLib.API.Image(),
new GameLib.API.Image(),
new GameLib.API.Image(),
new GameLib.API.Image(),
new GameLib.API.Image(),
new GameLib.API.Image()
];
}
this.images = images;
GameLib.D3.API.Texture.call(
this,
apiTexture.id,
apiTexture.name,
apiTexture.textureType,
apiTexture.parentEntity,
apiTexture.parentMaterials,
apiTexture.mipmaps,
apiTexture.mapping,
apiTexture.wrapS,
apiTexture.wrapT,
apiTexture.magFilter,
apiTexture.minFilter,
apiTexture.anisotropy,
apiTexture.format,
apiTexture.storageType,
apiTexture.offset,
apiTexture.repeat,
apiTexture.rotation,
apiTexture.center,
apiTexture.matrixAutoUpdate,
apiTexture.generateMipMaps,
apiTexture.premultiplyAlpha,
apiTexture.flipY,
apiTexture.unpackAlignment,
apiTexture.encoding,
apiTexture.version,
apiTexture.animated,
apiTexture.reverseAnimation,
apiTexture.forward
);
};
GameLib.D3.API.Texture.Cube.prototype = Object.create(GameLib.D3.API.Texture.prototype);
GameLib.D3.API.Texture.Cube.prototype.constructor = GameLib.D3.API.Texture.Cube;

View File

@ -0,0 +1,61 @@
/**
* GameLib.D3.API.Texture.Image
* @constructor
* @param apiTexture
* @param image
*/
GameLib.D3.API.Texture.Image = function(
apiTexture,
image
) {
if (GameLib.Utils.UndefinedOrNull(apiTexture)) {
apiTexture = {
textureType: GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE
};
}
if (GameLib.Utils.UndefinedOrNull(apiTexture.textureType)) {
apiTexture.textureType = GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE;
}
if (GameLib.Utils.UndefinedOrNull(image)) {
image = new GameLib.API.Image();
}
this.image = image;
GameLib.D3.API.Texture.call(
this,
apiTexture.id,
apiTexture.name,
apiTexture.textureType,
apiTexture.parentEntity,
apiTexture.parentMaterials,
apiTexture.mipmaps,
apiTexture.mapping,
apiTexture.wrapS,
apiTexture.wrapT,
apiTexture.magFilter,
apiTexture.minFilter,
apiTexture.anisotropy,
apiTexture.format,
apiTexture.storageType,
apiTexture.offset,
apiTexture.repeat,
apiTexture.rotation,
apiTexture.center,
apiTexture.matrixAutoUpdate,
apiTexture.generateMipMaps,
apiTexture.premultiplyAlpha,
apiTexture.flipY,
apiTexture.unpackAlignment,
apiTexture.encoding,
apiTexture.version,
apiTexture.animated,
apiTexture.reverseAnimation,
apiTexture.forward
);
};
GameLib.D3.API.Texture.Image.prototype = Object.create(GameLib.D3.API.Texture.prototype);
GameLib.D3.API.Texture.Image.prototype.constructor = GameLib.D3.API.Texture.Image;

View File

@ -46,9 +46,7 @@ GameLib.D3.Camera = function(
linkedObjects.renderTarget = GameLib.D3.RenderTarget;
break;
case GameLib.D3.API.Camera.CAMERA_TYPE_STEREO :
linkedObjects.main = GameLib.D3.Camera.Perspective;
linkedObjects.cameraL = GameLib.D3.Camera.Perspective;
linkedObjects.cameraR = GameLib.D3.Camera.Perspective;
linkedObjects.effect = GameLib.D3.Effect;
break;
default :
break;
@ -72,11 +70,11 @@ GameLib.D3.Camera.prototype.createInstance = function() {
/**
* Not all implementations of camera has a position (Stereo camera gets its position on update)
*/
// if (GameLib.Utils.Defined(this.instance.position)) {
if (GameLib.Utils.Defined(this.instance.position)) {
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
@ -85,10 +83,13 @@ GameLib.D3.Camera.prototype.createInstance = function() {
this.instance.aspect = this.aspect;
}
//if (GameLib.Utils.Defined(this.instance.lookAt)) {
if (GameLib.Utils.Defined(this.instance.lookAt)) {
this.instance.lookAt(this.lookAt.instance);
}
if (GameLib.Utils.Defined(this.instance.updateProjectionMatrix)) {
this.instance.updateProjectionMatrix();
//}
}
GameLib.Component.prototype.createInstance.call(this);
};
@ -133,7 +134,9 @@ GameLib.D3.Camera.prototype.updateInstance = function(property) {
if (property === 'aspect') {
if (GameLib.Utils.Defined(this.instance.aspect)) {
this.instance.aspect = this.aspect;
this.instance.updateProjectionMatrix();
if (GameLib.Utils.Defined(this.instance.updateProjectionMatrix)) {
this.instance.updateProjectionMatrix();
}
} else {
console.warn('updating the aspect ratio of this type of camera has no effect.');
}
@ -141,19 +144,32 @@ GameLib.D3.Camera.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;
this.instance.updateProjectionMatrix();
if (GameLib.Utils.Defined(this.instance.updateProjectionMatrix)) {
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();
if (GameLib.Utils.Defined(this.instance.lookAt)) {
this.instance.lookAt(this.lookAt.instance);
}
if (GameLib.Utils.Defined(this.instance.updateProjectionMatrix)) {
this.instance.updateProjectionMatrix();
}
return;
}

View File

@ -27,6 +27,13 @@ GameLib.D3.Camera.Cube = function(
apiCubeCamera.renderTarget
);
if (this.renderTarget instanceof GameLib.D3.API.RenderTarget) {
this.renderTarget = new GameLib.D3.RenderTarget(
this.graphics,
this.renderTarget
)
}
GameLib.D3.Camera.call(
this,
this.graphics,
@ -50,9 +57,16 @@ GameLib.D3.Camera.Cube.prototype.createInstance = function() {
this.cubeResolution
);
/**
if (this.renderTarget && this.renderTarget.instance) {
this.instance.renderTarget = this.renderTarget.instance;
}
}*/
this.renderTarget.instance = this.instance.renderTarget;
this.renderTarget.instance.texture = this.instance.renderTarget.texture;
this.renderTarget.texture.instance = this.instance.renderTarget.texture;
GameLib.D3.Camera.prototype.createInstance.call(this);
};
@ -90,6 +104,18 @@ GameLib.D3.Camera.Cube.prototype.updateInstance = function(property) {
GameLib.D3.Camera.prototype.updateInstance.call(this, property);
};
/**
* Updates the render target with renderer and scene information
* @param renderer
* @param scene
*/
GameLib.D3.Camera.Cube.prototype.update = function(renderer, scene) {
this.instance.update(
renderer.instance,
scene.instance
)
};
/**
* Converts a GameLib.D3.Camera to a GameLib.D3.API.Camera
* @returns {GameLib.D3.API.Camera}

View File

@ -21,34 +21,9 @@ GameLib.D3.Camera.Stereo = function(
GameLib.D3.API.Camera.Stereo.call(
this,
apiStereoCamera,
apiStereoCamera.eyeSep,
apiStereoCamera.stereoMode,
apiStereoCamera.main,
apiStereoCamera.cameraL,
apiStereoCamera.cameraR
apiStereoCamera.stereoMode
);
if (this.main instanceof GameLib.D3.API.Camera.Perspective) {
this.main = new GameLib.D3.Camera.Perspective(
this.graphics,
this.main
);
}
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
);
}
GameLib.D3.Camera.call(
this,
this.graphics,
@ -66,24 +41,18 @@ GameLib.D3.Camera.Stereo.prototype.constructor = GameLib.D3.Camera.Stereo;
*/
GameLib.D3.Camera.Stereo.prototype.createInstance = function() {
this.instance = this.main.instance;
this.instance = new THREE.PerspectiveCamera();
var instance = new THREE.StereoCamera();
for (var property in instance) {
this.instance[property] = instance[property];
if (
instance.hasOwnProperty(property) ||
typeof instance[property] === 'function'
) {
this.instance[property] = instance[property];
}
}
//
//
// Object.keys(instance).map(
// function(property) {
// this.instance[property] = instance[property];
// }.bind(this)
// );
this.instance.aspect = this.aspect;
this.instance.eyeSep = this.eyeSep;
GameLib.D3.Camera.prototype.createInstance.call(this);
};
@ -93,31 +62,11 @@ GameLib.D3.Camera.Stereo.prototype.createInstance = function() {
*/
GameLib.D3.Camera.Stereo.prototype.updateInstance = function(property) {
if (property === 'eyeSep') {
this.instance.eyeSep = this.eyeSep;
return;
}
if (property === 'stereoMode') {
console.warn('experimental update stereo mode');
console.warn('todo: update stereo mode');
return;
}
if (property === 'main') {
console.warn('experimental update stereo camera main instance');
return;
}
if (property === 'cameraL') {
console.warn('experimental update stereo camera cameraL instance');
return;
}
if (property === 'cameraR') {
console.warn('experimental update stereo camera cameraR instance');
return;
}
GameLib.D3.Camera.prototype.updateInstance.call(this, property);
};
@ -131,24 +80,8 @@ GameLib.D3.Camera.Stereo.prototype.toApiObject = function() {
var apiStereoCamera = new GameLib.D3.API.Camera.Stereo(
apiCamera,
this.eyeSep,
this.stereoMode,
GameLib.Utils.IdOrNull(this.main),
GameLib.Utils.IdOrNull(this.cameraL),
GameLib.Utils.IdOrNull(this.cameraR)
this.stereoMode
);
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

@ -20,10 +20,12 @@ GameLib.D3.Composer = function (
this,
apiComposer.id,
apiComposer.name,
apiComposer.parentEntity,
apiComposer.width,
apiComposer.height,
apiComposer.renderer,
apiComposer.renderTarget,
apiComposer.passes,
apiComposer.parentEntity
apiComposer.passes
);
GameLib.Component.call(
@ -45,45 +47,127 @@ GameLib.D3.Composer.prototype.constructor = GameLib.D3.Composer;
*/
GameLib.D3.Composer.prototype.createInstance = function() {
//TODO : Fix this too - make it nice (no circular references)
// var instance = null;
//
// if (update) {
// instance = this.instance;
// }
if (
GameLib.Utils.UndefinedOrNull(this.renderer) ||
GameLib.Utils.UndefinedOrNull(this.renderer.instance)
) {
console.warn('renderer not ready');
return;
}
//TODO : Fix this still (renderer and renderTarget should be objects)
// if (this.renderer &&
// this.renderTarget) {
//
// if (!THREE.EffectComposer) {
// console.warn('No THREE.EffectComposer');
// throw new Error('No THREE.EffectComposer');
// }
//
// instance = new THREE.EffectComposer(
// this.renderer.instance,
// this.renderTarget.instance
// );
//
// this.passes.map(
// function(pass) {
// this.instance.addPass(pass.instance);
// }.bind(this)
// );
// }
console.log('GameLib.D3.Composer.prototype.createInstance() - fix me');
var renderTargetInstance = undefined;
if (
GameLib.Utils.Defined(this.renderTarget) &&
GameLib.Utils.Defined(this.renderTarget.instance)
) {
renderTargetInstance = this.renderTarget.instance;
}
this.instance = new THREE.EffectComposer(
this.renderer.instance,
renderTargetInstance
);
this.passes.map(
function(pass) {
if (GameLib.Utils.UndefinedOrNull(pass.instance)) {
console.warn('pass not ready');
return;
}
this.instance.addPass(pass.instance);
}.bind(this)
);
this.instance.setSize(
this.width,
this.height
);
console.log('Constructed a composer instance');
GameLib.Component.prototype.createInstance.call(this);
//return instance;
};
/**
* Updates Composer instance
*/
GameLib.D3.Composer.prototype.updateInstance = function() {
console.log('GameLib.D3.Composer.prototype.updateInstance() - fix me');
GameLib.D3.Composer.prototype.updateInstance = function(property) {
if (property === 'renderer') {
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
this.createInstance();
}
return;
}
if (property === 'renderTarget') {
if (
GameLib.Utils.Defined(this.instance) &&
GameLib.Utils.Defined(this.renderTarget) &&
GameLib.Utils.Defined(this.renderTarget.instance)
) {
this.instance.reset(this.renderTarget.instance);
}
return;
}
if (
property === 'width' ||
property === 'height'
) {
this.instance.setSize(
this.width,
this.height
);
return;
}
if (property === 'passes') {
this.instance.passes = [];
this.passes.map(
function(pass) {
if (GameLib.Utils.UndefinedOrNull(pass.instance)) {
console.warn('pass not ready');
return;
}
this.instance.addPass(pass.instance);
console.log('adding pass : ' + pass.name);
}.bind(this)
)
}
};
/**
* Convenience function to set size
* @param width
* @param height
*/
GameLib.D3.Composer.prototype.setSize = function(width, height) {
this.width = width;
this.height = height;
this.updateInstance('width');
};
/**
* Convenience function to render
*/
GameLib.D3.Composer.prototype.render = function() {
this.instance.render();
};
/**
@ -95,32 +179,17 @@ GameLib.D3.Composer.prototype.toApiObject = function() {
var apiComposer = new GameLib.D3.API.Composer(
this.id,
this.name,
GameLib.Utils.IdOrNull(this.parentEntity),
this.width,
this.height,
GameLib.Utils.IdOrNull(this.renderer),
GameLib.Utils.IdOrNull(this.renderTarget),
this.passes.map(
function(pass) {
return GameLib.Utils.IdOrNull(pass);
}
),
GameLib.Utils.IdOrNull(this.parentEntity)
)
);
return apiComposer;
};
/**
*
* @param graphics
* @param objectComponent
* @returns {GameLib.D3.Composer}
* @constructor
*/
GameLib.D3.Composer.FromObject = function(graphics, objectComponent) {
var apiComposer = GameLib.D3.API.Composer.FromObject(objectComponent);
return new GameLib.D3.Composer(
graphics,
apiComposer
);
};

153
src/game-lib-d3-effect-a.js Normal file
View File

@ -0,0 +1,153 @@
/**
* GameLib.D3.Effect
* @param graphics GameLib.GraphicsRuntime
* @param apiEffect GameLib.D3.API.Effect
* @constructor
*/
GameLib.D3.Effect = function(
graphics,
apiEffect
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiEffect)) {
apiEffect = {};
}
GameLib.D3.API.Effect.call(
this,
apiEffect.id,
apiEffect.name,
apiEffect.effectType,
apiEffect.parentEntity,
apiEffect.renderer,
apiEffect.width,
apiEffect.height
);
var linkedObjects = {
renderer : GameLib.D3.Renderer
};
GameLib.Component.call(
this,
linkedObjects
);
};
GameLib.D3.Effect.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.Effect.prototype.constructor = GameLib.D3.Effect;
GameLib.D3.Effect.prototype.createInstance = function() {
if (!this.instance) {
console.warn('call this child create instance first');
return;
}
var width = this.width;
var height = this.height;
if (this.renderer && this.renderer.instance) {
var size = this.renderer.getSize();
width = size.width;
height = size.height;
}
this.setSize(
width,
height
);
GameLib.Component.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Effect.prototype.updateInstance = function(property) {
if (GameLib.Utils.UndefinedOrNull(property)) {
console.warn('no camera property specified for : ' + this.name);
}
if (property === 'effectType') {
console.warn('todo: update effect type');
return;
}
if (
property === 'width' ||
property === 'height'
) {
this.setSize(
this.width,
this.height
)
}
if (property === 'renderer') {
if (property === 'renderer') {
if (
GameLib.Utils.Defined(this.renderer) &&
GameLib.Utils.Defined(this.renderer.instance)
) {
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
this.createInstance();
} else {
this.instance.dispose();
this.createInstance();
}
}
}
return;
}
};
/**
* Convenience function to set effect size
* @param width
* @param height
*/
GameLib.D3.Effect.prototype.setSize = function(width, height) {
this.instance.setSize(
width,
height
);
};
/**
* Convenience function to render a scene / camera with this effect
* @param scene
* @param camera
*/
GameLib.D3.Effect.prototype.render = function(scene, camera) {
this.instance.render(
scene.instance,
camera.instance
);
};
/**
* Converts a GameLib.D3.Effect to a new GameLib.D3.API.Effect
* @returns {GameLib.D3.API.Effect}
*/
GameLib.D3.Effect.prototype.toApiObject = function() {
return new GameLib.D3.API.Effect(
this.id,
this.name,
this.effectType,
GameLib.Utils.IdOrNull(this.parentEntity),
GameLib.Utils.IdOrNull(this.renderer),
this.width,
this.height
);
};

View File

@ -0,0 +1,80 @@
/**
* GameLib.D3.Effect.Anaglyph
* @param graphics GameLib.GraphicsRuntime
* @param apiAnaglyphEffect
* @constructor
*/
GameLib.D3.Effect.Anaglyph = function(
graphics,
apiAnaglyphEffect
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiAnaglyphEffect)) {
apiAnaglyphEffect = {
effectType : GameLib.D3.API.Effect.EFFECT_TYPE_ANAGLYPH
};
}
GameLib.D3.API.Effect.Anaglyph.call(
this,
apiAnaglyphEffect
);
GameLib.D3.Effect.call(
this,
this.graphics,
this
);
};
GameLib.D3.Effect.Anaglyph.prototype = Object.create(GameLib.D3.Effect.prototype);
GameLib.D3.Effect.Anaglyph.prototype.constructor = GameLib.D3.Effect.Anaglyph;
/**
* Creates a camera instance
* @returns {*}
*/
GameLib.D3.Effect.Anaglyph.prototype.createInstance = function() {
if (
GameLib.Utils.UndefinedOrNull(this.renderer) ||
GameLib.Utils.UndefinedOrNull(this.renderer.instance)
) {
console.warn('anaglyph not ready for instance - needs a renderer');
return;
}
this.instance = new THREE.AnaglyphEffect(
this.renderer.instance
);
console.log('anaglyph effect instance created');
GameLib.D3.Effect.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Effect.Anaglyph.prototype.updateInstance = function(property) {
GameLib.D3.Effect.prototype.updateInstance.call(this, property);
};
/**
* Converts a GameLib.D3.Effect to a GameLib.D3.API.Effect
* @returns {GameLib.D3.API.Effect}
*/
GameLib.D3.Effect.Anaglyph.prototype.toApiObject = function() {
var apiEffect = GameLib.D3.Effect.prototype.toApiObject.call(this);
var apiAnaglyphEffect = new GameLib.D3.API.Effect.Anaglyph(
apiEffect
);
return apiAnaglyphEffect;
};

View File

@ -0,0 +1,80 @@
/**
* GameLib.D3.Effect.Parallax
* @param graphics GameLib.GraphicsRuntime
* @param apiParallaxEffect
* @constructor
*/
GameLib.D3.Effect.Parallax = function(
graphics,
apiParallaxEffect
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiParallaxEffect)) {
apiParallaxEffect = {
effectType : GameLib.D3.API.Effect.EFFECT_TYPE_PARALLAX
};
}
GameLib.D3.API.Effect.Parallax.call(
this,
apiParallaxEffect
);
GameLib.D3.Effect.call(
this,
this.graphics,
this
);
};
GameLib.D3.Effect.Parallax.prototype = Object.create(GameLib.D3.Effect.prototype);
GameLib.D3.Effect.Parallax.prototype.constructor = GameLib.D3.Effect.Parallax;
/**
* Creates a camera instance
* @returns {*}
*/
GameLib.D3.Effect.Parallax.prototype.createInstance = function() {
if (
GameLib.Utils.UndefinedOrNull(this.renderer) ||
GameLib.Utils.UndefinedOrNull(this.renderer.instance)
) {
console.warn('parallax not ready for instance - needs a renderer');
return;
}
this.instance = new THREE.ParallaxBarrierEffect(
this.renderer.instance
);
console.log('parallax effect instance created');
GameLib.D3.Effect.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Effect.Parallax.prototype.updateInstance = function(property) {
GameLib.D3.Effect.prototype.updateInstance.call(this, property);
};
/**
* Converts a GameLib.D3.Effect to a GameLib.D3.API.Effect
* @returns {GameLib.D3.API.Effect}
*/
GameLib.D3.Effect.Parallax.prototype.toApiObject = function() {
var apiEffect = GameLib.D3.Effect.prototype.toApiObject.call(this);
var apiParallaxEffect = new GameLib.D3.API.Effect.Parallax(
apiEffect
);
return apiParallaxEffect;
};

View File

@ -0,0 +1,90 @@
/**
* GameLib.D3.Effect.Stereo
* @param graphics GameLib.GraphicsRuntime
* @param apiStereoEffect
* @constructor
*/
GameLib.D3.Effect.Stereo = function(
graphics,
apiStereoEffect
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiStereoEffect)) {
apiStereoEffect = {
effectType : GameLib.D3.API.Effect.EFFECT_TYPE_STEREO
};
}
GameLib.D3.API.Effect.Stereo.call(
this,
apiStereoEffect,
apiStereoEffect.eyeSeperation
);
GameLib.D3.Effect.call(
this,
this.graphics,
this
);
};
GameLib.D3.Effect.Stereo.prototype = Object.create(GameLib.D3.Effect.prototype);
GameLib.D3.Effect.Stereo.prototype.constructor = GameLib.D3.Effect.Stereo;
/**
* Creates a camera instance
* @returns {*}
*/
GameLib.D3.Effect.Stereo.prototype.createInstance = function() {
if (
GameLib.Utils.UndefinedOrNull(this.renderer) ||
GameLib.Utils.UndefinedOrNull(this.renderer.instance)
) {
console.warn('stereo effect not ready for instance - needs a renderer');
return;
}
this.instance = new THREE.StereoEffect(
this.renderer.instance
);
this.instance.setEyeSeparation(this.eyeSeperation);
console.log('stereo effect instance created');
GameLib.D3.Effect.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Effect.Stereo.prototype.updateInstance = function(property) {
if (property === 'eyeSeperation') {
this.instance.setEyeSeparation(this.eyeSeperation);
return;
}
GameLib.D3.Effect.prototype.updateInstance.call(this, property);
};
/**
* Converts a GameLib.D3.Effect to a GameLib.D3.API.Effect
* @returns {GameLib.D3.API.Effect}
*/
GameLib.D3.Effect.Stereo.prototype.toApiObject = function() {
var apiEffect = GameLib.D3.Effect.prototype.toApiObject.call(this);
var apiStereoEffect = new GameLib.D3.API.Effect.Stereo(
apiEffect,
this.eyeSeperation
);
return apiStereoEffect;
};

View File

@ -251,7 +251,7 @@ GameLib.D3.Face.prototype.createHelper = function(mesh) {
// mesh.materials[this.materialIndex].emissive.b = 0.5;
// mesh.materials[this.materialIndex].updateInstance('emissive');
mesh.materials[this.materialIndex].vertexColors = GameLib.D3.Material.TYPE_VERTEX_COLORS;
mesh.materials[this.materialIndex].vertexColors = GameLib.D3.API.Material.TYPE_VERTEX_COLORS;
mesh.materials[this.materialIndex].updateInstance('vertexColors');
mesh.instance.geometry.elementsNeedUpdate = true;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,409 @@
/**
* GameLib.D3.Material.Standard
* @param graphics
* @param apiMaterialStandard
* @constructor
*/
GameLib.D3.Material.Standard = function(
graphics,
apiMaterialStandard
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiMaterialStandard)) {
apiMaterialStandard = {
materialType : GameLib.D3.API.Material.MATERIAL_TYPE_STANDARD
};
}
GameLib.D3.API.Material.Standard.call(
this,
apiMaterialStandard,
apiMaterialStandard.alphaMap,
apiMaterialStandard.aoMap,
apiMaterialStandard.aoMapIntensity,
apiMaterialStandard.bumpMap,
apiMaterialStandard.bumpScale,
apiMaterialStandard.color,
apiMaterialStandard.displacementMap,
apiMaterialStandard.displacementScale,
apiMaterialStandard.displacementBias,
apiMaterialStandard.emissive,
apiMaterialStandard.emissiveMap,
apiMaterialStandard.emissiveIntensity,
apiMaterialStandard.envMap,
apiMaterialStandard.envMapIntensity,
apiMaterialStandard.lightMap,
apiMaterialStandard.lightMapIntensity,
apiMaterialStandard.diffuseMap,
apiMaterialStandard.metalness,
apiMaterialStandard.metalnessMap,
apiMaterialStandard.morphNormals,
apiMaterialStandard.morphTargets,
apiMaterialStandard.normalMap,
apiMaterialStandard.normalScale,
apiMaterialStandard.refractionRatio,
apiMaterialStandard.roughness,
apiMaterialStandard.roughnessMap,
apiMaterialStandard.skinning,
apiMaterialStandard.wireframe,
apiMaterialStandard.wireframeLinecap,
apiMaterialStandard.wireframeLinejoin,
apiMaterialStandard.wireframeLinewidth
);
if (this.alphaMap instanceof GameLib.D3.API.Texture) {
this.alphaMap = new GameLib.D3.Texture(
this.graphics,
this.alphaMap
);
}
if (this.aoMap instanceof GameLib.D3.API.Texture) {
this.aoMap = new GameLib.D3.Texture(
this.graphics,
this.aoMap
);
}
if (this.bumpMap instanceof GameLib.D3.API.Texture) {
this.bumpMap = new GameLib.D3.Texture(
this.graphics,
this.bumpMap
);
}
this.color = new GameLib.Color(
this.graphics,
this.color,
this
);
if (this.displacementMap instanceof GameLib.D3.API.Texture) {
this.displacementMap = new GameLib.D3.Texture(
this.graphics,
this.displacementMap
);
}
this.emissive = new GameLib.Color(
this.graphics,
this.emissive,
this
);
if (this.emissiveMap instanceof GameLib.D3.API.Texture) {
this.emissiveMap = new GameLib.D3.Texture(
this.graphics,
this.emissiveMap
);
}
if (this.envMap instanceof GameLib.D3.API.Texture) {
this.envMap = new GameLib.D3.Texture(
this.graphics,
this.envMap
);
}
if (this.lightMap instanceof GameLib.D3.API.Texture) {
this.lightMap = new GameLib.D3.Texture(
this.graphics,
this.lightMap
);
}
if (this.diffuseMap instanceof GameLib.D3.API.Texture) {
this.diffuseMap = new GameLib.D3.Texture(
this.graphics,
this.diffuseMap
);
}
if (this.metalnessMap instanceof GameLib.D3.API.Texture) {
this.metalnessMap = new GameLib.D3.Texture(
this.graphics,
this.metalnessMap
);
}
if (this.normalMap instanceof GameLib.D3.API.Texture) {
this.normalMap = new GameLib.D3.Texture(
this.graphics,
this.normalMap
);
}
if (this.roughnessMap instanceof GameLib.D3.API.Texture) {
this.roughnessMap = new GameLib.D3.Texture(
this.graphics,
this.roughnessMap
);
}
GameLib.D3.Material.call(
this,
this.graphics,
this
);
};
GameLib.D3.Material.Standard.prototype = Object.create(GameLib.D3.Material.prototype);
GameLib.D3.Material.Standard.prototype.constructor = GameLib.D3.Material.Standard;
/**
* Creates an instance of our texture object
* @returns {*}
*/
GameLib.D3.Material.Standard.prototype.createInstance = function() {
this.instance = new THREE.MeshStandardMaterial(
{
alphaMap : this.alphaMap ? this.alphaMap.instance : null,
aoMap : this.aoMap ? this.aoMap.instance : null,
aoMapIntensity : this.aoMapIntensity,
bumpMap : this.bumpMap ? this.bumpMap.instance : null,
bumpScale : this.bumpScale,
color : this.color.instance,
displacementMap : this.displacementMap ? this.displacementMap.instance : null,
displacementScale : this.displacementScale,
displacementBias : this.displacementBias,
emissive : this.emissive.instance,
emissiveMap : this.emissiveMap ? this.emissiveMap.instance : null,
emissiveIntensity : this.emissiveIntensity,
envMap : this.envMap ? this.envMap.instance : null,
envMapIntensity : this.envMapIntensity,
lightMap : this.lightMap ? this.lightMap.instance : null,
lightMapIntensity : this.lightMapIntensity,
map : this.diffuseMap ? this.diffuseMap.instance : null,
metalness : this.metalness,
metalnessMap : this.metalnessMap ? this.metalnessMap.instance : null,
morphNormals : this.morphNormals,
morphTargets : this.morphTargets,
normalMap : this.normalMap ? this.normalMap.instance : null,
normalScale : this.normalScale,
refractionRatio : this.refractionRatio,
roughness : this.roughness,
roughnessMap : this.roughnessMap ? this.roughnessMap.instance : null,
skinning : this.skinning,
wireframe : this.wireframe,
wireframeLinecap : this.wireframeLinecap,
wireframeLinejoin : this.wireframeLinejoin,
wireframeLinewidth : this.wireframeLinewidth
}
);
GameLib.D3.Material.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Material.Standard.prototype.updateInstance = function(property) {
if (property === 'alphaMap') {
this.assignTexture('alphaMap', property);
return;
}
if (property === 'aoMap') {
this.assignTexture('aoMap', property);
return;
}
if (property === 'aoMapIntensity') {
this.instance.aoMapIntensity = this.aoMapIntensity;
return;
}
if (property === 'bumpMap') {
this.assignTexture('bumpMap', property);
return;
}
if (property === 'bumpScale') {
this.instance.bumpScale = this.bumpScale;
return;
}
if (property === 'color') {
this.instance.color = this.color.instance;
return;
}
if (property === 'displacementMap') {
this.assignTexture('displacementMap', property);
return;
}
if (property === 'displacementScale') {
this.instance.displacementScale = this.displacementScale;
return;
}
if (property === 'displacementBias') {
this.instance.displacementBias = this.displacementBias;
return;
}
if (property === 'emissive') {
this.instance.emissive = this.emissive.instance;
return;
}
if (property === 'emissiveMap') {
this.assignTexture('emissiveMap', property);
return;
}
if (property === 'emissiveIntensity') {
this.instance.emissiveIntensity = this.emissiveIntensity;
return;
}
if (property === 'envMap') {
this.assignTexture('envMap', property);
return;
}
if (property === 'envMapIntensity') {
this.instance.envMapIntensity = this.envMapIntensity;
return;
}
if (property === 'lightMap') {
this.assignTexture('lightMap', property);
return;
}
if (property === 'lightMapIntensity') {
this.instance.lightMapIntensity = this.lightMapIntensity;
return;
}
if (property === 'diffuseMap') {
this.assignTexture('map', property);
return;
}
if (property === 'metalness') {
this.instance.metalness = this.metalness;
return;
}
if (property === 'metalnessMap') {
this.assignTexture('metalnessMap', property);
return;
}
if (property === 'morphNormals') {
this.instance.morphNormals = this.morphNormals;
return;
}
if (property === 'morphTargets') {
this.instance.morphTargets = this.morphTargets;
return;
}
if (property === 'normalMap') {
this.assignTexture('normalMap', property);
return;
}
if (property === 'normalScale') {
this.instance.normalScale = this.normalScale;
return;
}
if (property === 'refractionRatio') {
this.instance.refractionRatio = this.refractionRatio;
return;
}
if (property === 'roughness') {
this.instance.roughness = this.roughness;
return;
}
if (property === 'roughnessMap') {
this.assignTexture('roughnessMap', property);
return;
}
if (property === 'skinning') {
this.instance.skinning = this.skinning;
return;
}
if (property === 'wireframe') {
this.instance.wireframe = this.wireframe;
return;
}
if (property === 'wireframeLinecap') {
this.instance.wireframeLinecap = this.wireframeLinecap;
return;
}
if (property === 'wireframeLinejoin') {
this.instance.wireframeLinejoin = this.wireframeLinejoin;
return;
}
if (property === 'wireframeLinewidth') {
this.instance.wireframeLinewidth = this.wireframeLinewidth;
return;
}
GameLib.D3.Material.prototype.updateInstance.call(this, property);
};
/**
* Converts a GameLib.D3.Material.Standard to a GameLib.D3.API.Material.Standard
* @returns {GameLib.D3.API.Material.Standard}
*/
GameLib.D3.Material.Standard.prototype.toApiObject = function() {
var apiMaterial = GameLib.D3.Material.prototype.toApiObject.call(this);
var apiMaterialStandard = new GameLib.D3.API.Material.Standard(
apiMaterial,
GameLib.Utils.IdOrNull(this.alphaMap),
GameLib.Utils.IdOrNull(this.aoMap),
this.aoMapIntensity,
GameLib.Utils.IdOrNull(this.bumpMap),
this.bumpScale,
this.color.toApiObject(),
GameLib.Utils.IdOrNull(this.displacementMap),
this.displacementScale,
this.displacementBias,
this.emissive.toApiObject(),
GameLib.Utils.IdOrNull(this.emissiveMap),
this.emissiveIntensity,
GameLib.Utils.IdOrNull(this.envMap),
this.envMapIntensity,
GameLib.Utils.IdOrNull(this.lightMap),
this.lightMapIntensity,
GameLib.Utils.IdOrNull(this.diffuseMap),
this.metalness,
GameLib.Utils.IdOrNull(this.metalnessMap),
this.morphNormals,
this.morphTargets,
GameLib.Utils.IdOrNull(this.normalMap),
this.normalScale,
this.refractionRatio,
this.roughness,
GameLib.Utils.IdOrNull(this.roughnessMap),
this.skinning,
this.wireframe,
this.wireframeLinecap,
this.wireframeLinejoin,
this.wireframeLinewidth
);
return apiMaterialStandard;
};

File diff suppressed because it is too large Load Diff

View File

@ -61,10 +61,12 @@ GameLib.D3.Mesh = function (
return material;
}
return new GameLib.D3.Material(
this.graphics,
material
);
var info = GameLib.Component.GetComponentInfo(material.componentType);
if (material instanceof info.apiConstructor) {
return new info.constructor(this.graphics, material);
} else {
console.warn('unhandled component type');
}
}.bind(this)
);

103
src/game-lib-d3-pass-0.js Normal file
View File

@ -0,0 +1,103 @@
/**
* GameLib.D3.Pass
* @param graphics GameLib.GraphicsRuntime
* @param apiPass GameLib.D3.API.Pass
* @property passType
* @constructor
*/
GameLib.D3.Pass = function (
graphics,
apiPass
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiPass)) {
apiPass = {
passType : GameLib.D3.API.Pass.PASS_TYPE_NONE
}
}
GameLib.D3.API.Pass.call(
this,
apiPass.id,
apiPass.name,
apiPass.passType,
apiPass.parentEntity,
apiPass.renderToScreen
);
var linkedObjects = {};
switch (this.passType) {
case GameLib.D3.API.Pass.PASS_TYPE_RENDER:
case GameLib.D3.API.Pass.PASS_TYPE_SSAO:
linkedObjects.scene = GameLib.D3.Scene;
linkedObjects.camera = GameLib.D3.Camera;
break;
default :
break;
}
GameLib.Component.call(
this,
linkedObjects
);
};
GameLib.D3.Pass.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.Pass.prototype.constructor = GameLib.D3.Pass;
/**
* Create Pass instance
* @returns {*}
*/
GameLib.D3.Pass.prototype.createInstance = function() {
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
console.warn('no instance - call the child createInstance() first');
return;
}
this.instance.renderToScreen = this.renderToScreen;
GameLib.Component.prototype.createInstance.call(this);
};
/**
* Update Pass instance
*/
GameLib.D3.Pass.prototype.updateInstance = function(property) {
if (property === 'renderToScreen') {
this.instance.renderToScreen = this.renderToScreen;
}
};
/**
* Not all passes have setSize, but this is just a safety function in case someone calls setSize on a pass component
* @param property
*/
GameLib.D3.Pass.prototype.setSize = function(property) {
};
/**
* GameLib.D3.Pass to GameLib.D3.API.Pass
* @returns {GameLib.D3.API.Pass}
*/
GameLib.D3.Pass.prototype.toApiObject = function() {
var apiPass = new GameLib.D3.API.Pass(
this.id,
this.name,
this.passType,
GameLib.Utils.IdOrNull(this.parentEntity),
this.renderToScreen
);
return apiPass;
};

View File

@ -0,0 +1,126 @@
/**
* GameLib.D3.Pass.Bloom
* @param graphics GameLib.GraphicsRuntime
* @param apiPassBloom GameLib.D3.API.Pass.Bloom
* @constructor
*/
GameLib.D3.Pass.Bloom = function (
graphics,
apiPassBloom
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiPassBloom)) {
apiPassBloom = {
passType : GameLib.D3.API.Pass.PASS_TYPE_BLOOM
};
}
GameLib.D3.API.Pass.Bloom.call(
this,
apiPassBloom,
apiPassBloom.width,
apiPassBloom.height,
apiPassBloom.strength,
apiPassBloom.radius,
apiPassBloom.threshold
);
GameLib.D3.Pass.call(
this,
this.graphics,
this
);
};
GameLib.D3.Pass.Bloom.prototype = Object.create(GameLib.D3.Pass.prototype);
GameLib.D3.Pass.Bloom.prototype.constructor = GameLib.D3.Pass.Bloom;
/**
* Create Pass.Bloom instance
* @returns {*}
*/
GameLib.D3.Pass.Bloom.prototype.createInstance = function() {
this.instance = new THREE.UnrealBloomPass(
new THREE.Vector2(
this.width,
this.height
),
this.strength,
this.radius,
this.threshold
);
console.log('Constructed a bloom pass instance');
GameLib.D3.Pass.prototype.createInstance.call(this);
};
/**
* Update Pass.Bloom instance
*/
GameLib.D3.Pass.Bloom.prototype.updateInstance = function(property) {
if (
property === 'width' ||
property === 'height'
) {
this.instance.setSize(
this.width,
this.height
);
return;
}
if (property === 'strength') {
this.instance.strength = this.strength;
return;
}
if (property === 'radius') {
this.instance.radius = this.radius;
return;
}
if (property === 'threshold') {
this.instance.threshold = this.threshold;
return;
}
GameLib.D3.Pass.prototype.updateInstance.call(this, property);
};
/**
* Convenience function to set size
* @param width
* @param height
*/
GameLib.D3.Pass.Bloom.prototype.setSize = function(width, height) {
this.width = width;
this.height = height;
this.updateInstance('width');
};
/**
* GameLib.D3.Pass.Bloom to GameLib.D3.API.Pass.Bloom
* @returns {GameLib.D3.API.Pass.Bloom}
*/
GameLib.D3.Pass.Bloom.prototype.toApiObject = function() {
var apiPass = GameLib.D3.Pass.prototype.toApiObject.call(this);
var apiBloomPass = new GameLib.D3.API.Pass.Bloom(
apiPass,
this.width,
this.height,
this.strength,
this.radius,
this.threshold
);
return apiBloomPass;
};

View File

@ -0,0 +1,100 @@
/**
* GameLib.D3.Pass.FXAA
* @param graphics GameLib.GraphicsRuntime
* @param apiPassFXAA GameLib.D3.API.Pass.FXAA
* @constructor
*/
GameLib.D3.Pass.FXAA = function (
graphics,
apiPassFXAA
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiPassFXAA)) {
apiPassFXAA = {
passType : GameLib.D3.API.Pass.PASS_TYPE_FXAA
};
}
GameLib.D3.API.Pass.FXAA.call(
this,
apiPassFXAA,
apiPassFXAA.width,
apiPassFXAA.height
);
GameLib.D3.Pass.call(
this,
this.graphics,
this
);
};
GameLib.D3.Pass.FXAA.prototype = Object.create(GameLib.D3.Pass.prototype);
GameLib.D3.Pass.FXAA.prototype.constructor = GameLib.D3.Pass.FXAA;
/**
* Create Pass.FXAA instance
* @returns {*}
*/
GameLib.D3.Pass.FXAA.prototype.createInstance = function() {
this.instance = new THREE.ShaderPass(THREE.FXAAShader);
this.instance.uniforms['resolution'].value.set(
1 / this.width,
1 / this.height
);
console.log('Constructed an FXAA pass instance');
};
/**
* Update Pass.FXAA instance
*/
GameLib.D3.Pass.FXAA.prototype.updateInstance = function(property) {
if (
property === 'width' ||
property === 'height'
) {
this.instance.uniforms['resolution'].value.set(
1 / this.width,
1 / this.height
);
return;
}
GameLib.D3.Pass.prototype.updateInstance.call(this, property);
};
/**
* Convenience function to set size
* @param width
* @param height
*/
GameLib.D3.Pass.FXAA.prototype.setSize = function(width, height) {
this.width = width;
this.height = height;
this.updateInstance('width');
};
/**
* GameLib.D3.Pass.FXAA to GameLib.D3.API.Pass.FXAA
* @returns {GameLib.D3.API.Pass.FXAA}
*/
GameLib.D3.Pass.FXAA.prototype.toApiObject = function() {
var apiPass = GameLib.D3.Pass.prototype.toApiObject.call(this);
var apiFXAAPass = new GameLib.D3.API.Pass.FXAA(
apiPass,
this.width,
this.height
);
return apiFXAAPass;
};

View File

@ -0,0 +1,120 @@
/**
* GameLib.D3.Pass.Render
* @param graphics GameLib.GraphicsRuntime
* @param apiPassRender GameLib.D3.API.Pass.Render
* @constructor
*/
GameLib.D3.Pass.Render = function (
graphics,
apiPassRender
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiPassRender)) {
apiPassRender = {
passType : GameLib.D3.API.Pass.PASS_TYPE_RENDER
};
}
GameLib.D3.API.Pass.Render.call(
this,
apiPassRender,
apiPassRender.scene,
apiPassRender.camera
);
if (this.scene instanceof GameLib.D3.API.Scene) {
this.scene = new GameLib.D3.Scene(
this.graphics,
this.scene
)
}
if (this.camera instanceof GameLib.D3.API.Camera) {
this.camera = new GameLib.D3.Camera(
this.graphics,
this.camera
)
}
GameLib.D3.Pass.call(
this,
this.graphics,
this
);
};
GameLib.D3.Pass.Render.prototype = Object.create(GameLib.D3.Pass.prototype);
GameLib.D3.Pass.Render.prototype.constructor = GameLib.D3.Pass.Render;
/**
* Create Pass.Render instance
* @returns {*}
*/
GameLib.D3.Pass.Render.prototype.createInstance = function() {
if (GameLib.Utils.UndefinedOrNull(this.scene) ||
GameLib.Utils.UndefinedOrNull(this.scene.instance)
) {
console.warn('scene not ready');
return;
}
if (GameLib.Utils.UndefinedOrNull(this.camera) ||
GameLib.Utils.UndefinedOrNull(this.camera.instance)
) {
console.warn('camera not ready');
return;
}
this.instance = new THREE.RenderPass(
this.scene.instance,
this.camera.instance
);
console.log('Constructed a render pass instance');
GameLib.D3.Pass.prototype.createInstance.call(this);
};
/**
* Update Pass.Render instance
*/
GameLib.D3.Pass.Render.prototype.updateInstance = function(property) {
if (property === 'scene') {
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
this.createInstance();
}
return;
}
if (property === 'camera') {
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
this.createInstance();
}
return;
}
GameLib.D3.Pass.prototype.updateInstance.call(this, property);
};
/**
* GameLib.D3.Pass.Render to GameLib.D3.API.Pass.Render
* @returns {GameLib.D3.API.Pass.Render}
*/
GameLib.D3.Pass.Render.prototype.toApiObject = function() {
var apiPass = GameLib.D3.Pass.prototype.toApiObject.call(this);
var apiRenderPass = new GameLib.D3.API.Pass.Render(
apiPass,
GameLib.Utils.IdOrNull(this.scene),
GameLib.Utils.IdOrNull(this.camera)
);
return apiRenderPass;
};

View File

@ -0,0 +1,120 @@
/**
* GameLib.D3.Pass.SSAO
* @param graphics GameLib.GraphicsRuntime
* @param apiPassSSAO GameLib.D3.API.Pass.SSAO
* @constructor
*/
GameLib.D3.Pass.SSAO = function (
graphics,
apiPassSSAO
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiPassSSAO)) {
apiPassSSAO = {
passType : GameLib.D3.API.Pass.PASS_TYPE_SSAO
};
}
GameLib.D3.API.Pass.SSAO.call(
this,
apiPassSSAO,
apiPassSSAO.scene,
apiPassSSAO.camera
);
if (this.scene instanceof GameLib.D3.API.Scene) {
this.scene = new GameLib.D3.Scene(
this.graphics,
this.scene
)
}
if (this.camera instanceof GameLib.D3.API.Camera) {
this.camera = new GameLib.D3.Camera(
this.graphics,
this.camera
)
}
GameLib.D3.Pass.call(
this,
this.graphics,
this
);
};
GameLib.D3.Pass.SSAO.prototype = Object.create(GameLib.D3.Pass.prototype);
GameLib.D3.Pass.SSAO.prototype.constructor = GameLib.D3.Pass.SSAO;
/**
* Create Pass.SSAO instance
* @returns {*}
*/
GameLib.D3.Pass.SSAO.prototype.createInstance = function() {
if (GameLib.Utils.UndefinedOrNull(this.scene) ||
GameLib.Utils.UndefinedOrNull(this.scene.instance)
) {
console.warn('scene not ready');
return;
}
if (GameLib.Utils.UndefinedOrNull(this.camera) ||
GameLib.Utils.UndefinedOrNull(this.camera.instance)
) {
console.warn('camera not ready');
return;
}
this.instance = new THREE.SSAOPass(
this.scene.instance,
this.camera.instance
);
console.log('Constructed an SSAO pass instance');
GameLib.D3.Pass.prototype.createInstance.call(this);
};
/**
* Update Pass.SSAO instance
*/
GameLib.D3.Pass.SSAO.prototype.updateInstance = function(property) {
if (property === 'scene') {
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
this.createInstance();
}
return;
}
if (property === 'camera') {
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
this.createInstance();
}
return;
}
GameLib.D3.Pass.prototype.updateInstance.call(this, property);
};
/**
* GameLib.D3.Pass.SSAO to GameLib.D3.API.Pass.SSAO
* @returns {GameLib.D3.API.Pass.SSAO}
*/
GameLib.D3.Pass.SSAO.prototype.toApiObject = function() {
var apiPass = GameLib.D3.Pass.prototype.toApiObject.call(this);
var apiSSAOPass = new GameLib.D3.API.Pass.SSAO(
apiPass,
GameLib.Utils.IdOrNull(this.scene),
GameLib.Utils.IdOrNull(this.camera)
);
return apiSSAOPass;
};

View File

@ -1,142 +0,0 @@
/**
* Renders a scene with a camera
* @param graphics GameLib.GraphicsRuntime
* @param apiPass GameLib.D3.API.Pass
* @constructor
*/
GameLib.D3.Pass = function (
graphics,
apiPass
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiPass)) {
apiPass = {};
}
GameLib.D3.API.Pass.call(
this,
apiPass.id,
apiPass.name,
apiPass.passType,
apiPass.camera,
apiPass.scene,
apiPass.renderToScreen,
apiPass.parentEntity
);
GameLib.Component.call(
this,
{
'camera' : GameLib.D3.Camera,
'scene' : GameLib.D3.Scene
}
);
};
GameLib.D3.Pass.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.Pass.prototype.constructor = GameLib.D3.Pass;
GameLib.D3.Pass.PASS_TYPE_RENDER = 0x1;
GameLib.D3.Pass.PASS_TYPE_COPY_SHADER = 0x2;
/**
* Create Pass instance
* @returns {*}
*/
GameLib.D3.Pass.prototype.createInstance = function() {
if (this.passType === GameLib.D3.Pass.PASS_TYPE_RENDER) {
if (GameLib.Utils.UndefinedOrNull(this.scene)) {
throw new Error('no scene object');
}
if (GameLib.Utils.UndefinedOrNull(this.camera)) {
throw new Error('no camera object');
}
if (GameLib.Utils.UndefinedOrNull(THREE.RenderPass)) {
throw new Error('no render pass library')
}
this.instance = new THREE.RenderPass(
this.scene.instance,
this.camera.instance
);
} else if (this.passType === GameLib.D3.Pass.PASS_TYPE_COPY_SHADER) {
if (GameLib.Utils.UndefinedOrNull(THREE.CopyShader)) {
throw new Error('no copyshader library')
}
this.instance = THREE.CopyShader;
} else {
console.warn('Render pass not supported yet: ' + this.passType);
throw new Error('Render pass not supported yet: ' + this.passType);
}
this.instance.renderToScreen = this.renderToScreen;
GameLib.Component.prototype.createInstance.call(this);
};
/**
* Update Pass instance
*/
GameLib.D3.Pass.prototype.updateInstance = function() {
if (
this.passType === GameLib.D3.Pass.PASS_TYPE_RENDER && !(this.instance instanceof THREE.RenderPass)){
this.createInstance();
}
if (
this.passType === GameLib.D3.Pass.PASS_TYPE_COPY_SHADER && !(this.instance instanceof THREE.CopyShader)){
this.createInstance();
}
this.instance.renderToScreen = this.renderToScreen;
};
/**
* GameLib.D3.Pass to GameLib.D3.API.Pass
* @returns {GameLib.D3.API.Pass}
*/
GameLib.D3.Pass.prototype.toApiObject = function() {
var apiPass = new GameLib.D3.API.Pass(
this.id,
this.name,
this.passType,
GameLib.Utils.IdOrNull(this.camera),
GameLib.Utils.IdOrNull(this.scene),
this.renderToScreen,
GameLib.Utils.IdOrNull(this.parentEntity)
);
return apiPass;
};
/**
* GameLib.D3.Pass from Object
* @param graphics
* @param objectComponent
* @returns {GameLib.D3.Pass}
* @constructor
*/
GameLib.D3.Pass.FromObject = function(graphics, objectComponent) {
var apiPass = GameLib.D3.API.Pass.FromObject(objectComponent);
return new GameLib.D3.Pass(
graphics,
apiPass
);
};

View File

@ -13,19 +13,30 @@ GameLib.D3.RenderTarget = function (
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiRenderTarget)) {
apiRenderTarget = {};
apiRenderTarget = {
renderTargetType : GameLib.D3.API.RenderTarget.TARGET_TYPE_NORMAL
};
}
GameLib.D3.API.RenderTarget.call(
this,
apiRenderTarget.id,
apiRenderTarget.name,
apiRenderTarget.renderTargetType,
apiRenderTarget.width,
apiRenderTarget.height,
apiRenderTarget.stencilBuffer,
apiRenderTarget.textureParameters,
apiRenderTarget.texture
);
if (this.texture instanceof GameLib.D3.API.Texture) {
this.texture = new GameLib.D3.Texture(
this.graphics,
this.texture
)
}
GameLib.Component.call(
this,
{
@ -54,11 +65,16 @@ GameLib.D3.RenderTarget.prototype.createInstance = function() {
this.instance = new THREE.WebGLRenderTarget(
this.width,
this.height,
{
stencilBuffer : this.stencilBuffer
}
this.textureParameters
);
/**
* The instance texture is automatically generated - we assign it to our texture and update from instance
* TODO: do this later if it starts failing
*/
//this.texture.instance = this.instance.texture;
//this.texture.updateFromInstance();
this.instance.texture = this.texture.instance;
GameLib.Component.prototype.createInstance.call(this);
@ -67,24 +83,23 @@ GameLib.D3.RenderTarget.prototype.createInstance = function() {
/**
* updates instance
*/
GameLib.D3.RenderTarget.prototype.updateInstance = function() {
GameLib.D3.RenderTarget.prototype.updateInstance = function(property) {
if (this.instance) {
if (
property === 'width' ||
property === 'height'
) {
this.instance.setSize(this.width, this.height);
this.instance.stencilBuffer = this.stencilBuffer;
if (this.texture && this.texture.instance) {
this.instance.texture = this.texture.instance;
this.instance.texture.needsUpdate = true;
} else {
this.instance.texture = null;
}
} else {
try {
this.createInstance();
} catch (error) {
console.error(error);
}
}
if (property === 'stencilBuffer') {
this.instance.stencilBuffer = this.stencilBuffer;
}
if (property === 'texture') {
this.instance.texture = this.texture.instance;
}
};
/**
@ -96,29 +111,14 @@ GameLib.D3.RenderTarget.prototype.toApiObject = function() {
var apiRenderTarget = new GameLib.D3.API.RenderTarget(
this.id,
this.name,
this.renderTargetType,
this.width,
this.height,
this.stencilBuffer,
this.textureParameters,
GameLib.Utils.IdOrNull(this.texture),
GameLib.Utils.IdOrNull(this.parentEntity)
);
return apiRenderTarget;
};
/**
*
* @param graphics
* @param objectComponent
* @returns {GameLib.D3.RenderTarget}
* @constructor
*/
GameLib.D3.RenderTarget.FromObject = function(graphics, objectComponent) {
var apiRenderTarget = GameLib.D3.API.RenderTarget.FromObject(objectComponent);
return new GameLib.D3.RenderTarget(
graphics,
apiRenderTarget
);
};

View File

@ -0,0 +1,107 @@
/**
* Renders a scene with a camera
* @param graphics GameLib.GraphicsRuntime
* @param apiRenderTargetCube GameLib.D3.API.RenderTarget.Cube
* @constructor
*/
GameLib.D3.RenderTarget.Cube = function (
graphics,
apiRenderTargetCube
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiRenderTargetCube)) {
apiRenderTargetCube = {
renderTargetType : GameLib.D3.API.RenderTarget.TARGET_TYPE_CUBE
};
}
GameLib.D3.API.RenderTarget.Cube.call(
this,
apiRenderTargetCube
);
GameLib.D3.RenderTarget.call(
this,
this.graphics,
this
);
};
GameLib.D3.RenderTarget.Cube.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.RenderTarget.Cube.prototype.constructor = GameLib.D3.RenderTarget.Cube;
/**
* Creates a Render Target instance
* @returns {*}
*/
GameLib.D3.RenderTarget.Cube.prototype.createInstance = function() {
if (GameLib.Utils.UndefinedOrNull(this.texture)) {
throw new Error('no texture');
}
if (GameLib.Utils.UndefinedOrNull(this.texture.instance)) {
throw new Error('no texture instance');
}
this.instance = new THREE.WebGLRenderTargetCube(
this.width,
this.height,
this.textureParameters
);
this.instance.texture.minFilter = THREE.LinearMipMapLinearFilter;
/**
* The instance texture is automatically generated - we assign it to our texture and update from instance
*/
//this.texture.instance = this.instance.texture;
//this.texture.updateFromInstance();
//this.instance.texture = this.texture.instance;
GameLib.Component.prototype.createInstance.call(this);
};
/**
* updates instance
*/
GameLib.D3.RenderTarget.Cube.prototype.updateInstance = function(property) {
if (
property === 'width' ||
property === 'height'
) {
this.instance.setSize(this.width, this.height);
}
if (property === 'stencilBuffer') {
this.instance.stencilBuffer = this.stencilBuffer;
}
if (property === 'texture') {
this.instance.texture = this.texture.instance;
}
};
/**
* Render Target to API Render Target
* @returns {GameLib.D3.API.RenderTarget.Cube}
*/
GameLib.D3.RenderTarget.Cube.prototype.toApiObject = function() {
var apiRenderTarget = GameLib.D3.RenderTarget.prototype.toApiObject.call(
this
);
var apiRenderTargetCube = new GameLib.D3.API.RenderTarget.Cube(
apiRenderTarget
);
return apiRenderTargetCube;
};

View File

@ -1,5 +1,5 @@
/**
* Renders a scene with a camera
* GameLib.D3.Renderer
* @param graphics GameLib.GraphicsRuntime
* @param apiRenderer GameLib.D3.API.Renderer
* @constructor
@ -23,7 +23,6 @@ GameLib.D3.Renderer = function (
apiRenderer.width,
apiRenderer.height,
apiRenderer.renderMode,
apiRenderer.lastRenderMode,
apiRenderer.autoClear,
apiRenderer.autoClearColor,
apiRenderer.autoClearDepth,
@ -51,35 +50,15 @@ GameLib.D3.Renderer = function (
apiRenderer.depth,
apiRenderer.logarithmicDepthBuffer,
apiRenderer.localClippingEnabled,
apiRenderer.aspectRatio,
apiRenderer.scaleMode,
apiRenderer.windowSize,
apiRenderer.logicalSize,
apiRenderer.offset,
apiRenderer.canvas,
apiRenderer.renderTarget,
apiRenderer.clippingPlanes,
apiRenderer.clearColor,
apiRenderer.camera,
apiRenderer.editCamera,
apiRenderer.scenes,
apiRenderer.defaultScene,
apiRenderer.viewports,
apiRenderer.parentEntity
);
this.windowSize = new GameLib.Vector2(
this.graphics,
this.windowSize,
this
);
this.logicalSize = new GameLib.Vector2(
this.graphics,
this.logicalSize,
this
);
this.offset = new GameLib.Vector2(
this.graphics,
this.offset,
@ -115,38 +94,6 @@ GameLib.D3.Renderer = function (
this.clearColor,
this
);
if (this.camera instanceof GameLib.D3.API.Camera.Stereo) {
this.camera = new GameLib.D3.Camera.Stereo(
this.graphics,
this.camera
)
}
if (this.editCamera instanceof GameLib.D3.API.Camera.Stereo) {
this.editCamera = new GameLib.D3.Camera.Stereo(
this.graphics,
this.editCamera
)
}
this.scenes = this.scenes.map(function(scene){
if (scene instanceof GameLib.D3.API.Scene) {
var runtimeScene = new GameLib.D3.Scene(
this.graphics,
scene
);
if (scene === this.defaultScene) {
this.defaultScene = runtimeScene;
}
return runtimeScene;
} else {
return scene;
}
}.bind(this));
this.viewports = this.viewports.map(function(viewport){
if (viewport instanceof GameLib.D3.API.Viewport) {
@ -165,10 +112,6 @@ GameLib.D3.Renderer = function (
'canvas' : GameLib.Canvas,
'renderTarget' : GameLib.D3.RenderTarget,
'clippingPlanes': [GameLib.Plane],
'camera' : GameLib.D3.Camera,
'editCamera' : GameLib.D3.Camera,
'scenes' : [GameLib.D3.Scene],
'defaultScene' : GameLib.D3.Scene,
'viewports' : [GameLib.D3.Viewport]
}
);
@ -184,12 +127,12 @@ GameLib.D3.Renderer.prototype.constructor = GameLib.D3.Renderer;
*/
GameLib.D3.Renderer.prototype.createInstance = function() {
if (GameLib.Utils.UndefinedOrNull(this.canvas)) {
throw new Error('no canvas');
}
if (GameLib.Utils.UndefinedOrNull(this.canvas.instance)) {
throw new Error('no canvas instance');
if (
GameLib.Utils.UndefinedOrNull(this.canvas) ||
GameLib.Utils.UndefinedOrNull(this.canvas.instance)
) {
console.warn('no canvas instance');
return;
}
this.instance = new THREE.WebGLRenderer(
@ -205,14 +148,15 @@ GameLib.D3.Renderer.prototype.createInstance = function() {
}
);
this.instance.setSize(
this.width * this.windowSize.x,
this.height * this.windowSize.y,
false
);
this.instance.setPixelRatio(window.devicePixelRatio);
this.canvas.instance.style.left = (this.offset.x * this.windowSize.x) + 'px';
this.canvas.instance.style.top = (this.offset.y * this.windowSize.y) + 'px';
GameLib.Event.Emit(
GameLib.Event.GET_WINDOW_SIZE,
{},
function(data) {
this.setSize(data.width, data.height);
}.bind(this)
);
this.instance.autoClear = this.autoClear;
this.instance.autoClearColor = this.autoClearColor;
@ -282,23 +226,27 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) {
throw new Error('no renderer instance');
}
var trueWidth;
var trueHeight;
if (
property === 'width' ||
property === 'height' ||
property === 'offset'
) {
if (property === 'width') {
this.updateInstance('windowSize');
return;
}
GameLib.Event.Emit(
GameLib.Event.GET_WINDOW_SIZE,
{},
function(data) {
this.setSize(data.width, data.height);
}.bind(this)
);
if (property === 'height') {
this.updateInstance('windowSize');
return;
}
if (property === 'renderMode') {
if (this.renderMode !== GameLib.D3.API.Renderer.MODE_EDIT) {
this.lastRenderMode = this.renderMode;
}
console.log('render mode change');
return;
}
@ -442,101 +390,30 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) {
return;
}
if (property === 'aspectRatio') {
if (property === 'canvas') {
if (this.scaleMode === GameLib.D3.API.Renderer.SCALE_MODE_LETTERBOX) {
if (this.windowSize.x === this.windowSize.y) {
/**
* Square
*/
// this.camera.aspect = 1;
// this.editCamera.aspect = 1;
console.log('square');
}
if (this.windowSize.x > this.windowSize.y) {
/**
* Landscape Mode
*/
// this.camera.aspect = this.windowSize.x / this.windowSize.y;
// this.editCamera.aspect = this.windowSize.x / this.windowSize.y;
console.log('landscape');
}
if (this.windowSize.x < this.windowSize.y) {
/**
* Portrait Mode
*/
// this.camera.aspect = this.windowSize.y / this.windowSize.x;
// this.editCamera.aspect = this.windowSize.y / this.windowSize.x;
console.log('portrait');
}
this.camera.aspect = this.windowSize.x / this.windowSize.y;
this.editCamera.aspect = this.windowSize.x / this.windowSize.y;
this.camera.updateInstance('aspect');
this.editCamera.updateInstance('aspect');
return;
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
this.createInstance();
} else {
console.warn('experimental canvas change for renderer');
this.instance.dispose();
this.createInstance();
}
console.warn('todo : update aspect ratio for scale mode : ' + this.scaleMode);
return;
}
if (property === 'scaleMode') {
this.updateInstance('aspectRatio');
return;
}
if (property === 'windowSize') {
trueWidth = this.width * this.windowSize.x;
trueHeight = this.height * this.windowSize.y;
this.canvas.width = trueWidth;
this.canvas.height = trueHeight;
this.canvas.updateInstance('width');
this.canvas.updateInstance('height');
this.instance.setSize(
trueWidth,
trueHeight,
false
);
this.canvas.instance.style.left = (this.offset.x * this.windowSize.x) + 'px';
this.canvas.instance.style.top = (this.offset.y * this.windowSize.y) + 'px';
this.updateInstance('aspectRatio');
return;
}
if (property === 'logicalSize') {
this.updateInstance('aspectRatio');
return;
}
if (property === 'offset') {
this.canvas.instance.style.left = (this.offset.x * this.windowSize.x) + 'px';
this.canvas.instance.style.top = (this.offset.y * this.windowSize.y) + 'px';
return;
}
if (property === 'canvas') {
console.warn('experimental canvas change for renderer');
this.instance.dispose();
this.createInstance();
return;
}
if (property === 'renderTarget') {
console.warn('todo: render target change');
if (
GameLib.Utils.Defined(this.instance) &&
GameLib.Utils.Defined(this.renderTarget) &&
GameLib.Utils.Defined(this.renderTarget.instance)
) {
this.instance.setRenderTarget(this.renderTarget.instance);
console.log('updated render target on render instance');
}
return;
}
@ -557,22 +434,6 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) {
return;
}
if (property === 'camera') {
console.warn('todo: camera change');
}
if (property === 'editCamera') {
console.warn('todo: edit camera change');
}
if (property === 'scenes') {
console.warn('todo: scenes change');
}
if (property === 'defaultScene') {
console.warn('todo: defaultScene change');
}
if (property === 'viewports') {
console.warn('todo: viewports change');
}
@ -582,23 +443,92 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) {
}
};
/**
* Convenience function to set size
* @param width
* @param height
*/
GameLib.D3.Renderer.prototype.setSize = function(width, height) {
this.instance.setSize(
this.width * width,
this.height * height,
false
);
this.canvas.instance.style.left = (this.offset.x * width) + 'px';
this.canvas.instance.style.top = (this.offset.y * height) + 'px';
};
/**
* Convenience function to get size
* @returns {{width, height}}
*/
GameLib.D3.Renderer.prototype.getSize = function() {
return this.instance.getSize();
};
/**
* Convenience function to set viewport
* @param x
* @param y
* @param width
* @param height
*/
GameLib.D3.Renderer.prototype.setViewport = function(
x,
y,
width,
height
) {
this.instance.setViewport(
x,
y,
width,
height
);
};
/**
* Renders to this.renderTarget
* @param scene
* @param camera
*/
GameLib.D3.Renderer.prototype.renderToTarget = function(scene, camera) {
this.instance.render(
scene.instance,
camera.instance,
this.renderTarget.instance
);
};
/**
* Renders normally
* @param scene
* @param camera
*/
GameLib.D3.Renderer.prototype.render = function(scene, camera) {
this.instance.render(
scene.instance,
camera.instance
)
};
/**
*
* @returns {GameLib.D3.API.Renderer}
*/
GameLib.D3.Renderer.prototype.toApiObject = function() {
if (this.renderMode !== GameLib.D3.API.Renderer.MODE_EDIT) {
this.lastRenderMode = this.renderMode;
}
var apiRenderer = new GameLib.D3.API.Renderer(
this.id,
this.name,
this.width,
this.height,
this.renderMode,
this.lastRenderMode,
this.autoClear,
this.autoClearColor,
this.autoClearDepth,
@ -626,10 +556,6 @@ GameLib.D3.Renderer.prototype.toApiObject = function() {
this.depth,
this.logarithmicDepthBuffer,
this.localClippingEnabled,
this.aspectRatio,
this.scaleMode,
this.windowSize.toApiObject(),
this.logicalSize.toApiObject(),
this.offset.toApiObject(),
GameLib.Utils.IdOrNull(this.canvas),
GameLib.Utils.IdOrNull(this.renderTarget),
@ -639,14 +565,6 @@ GameLib.D3.Renderer.prototype.toApiObject = function() {
}
),
this.clearColor.toApiObject(),
GameLib.Utils.IdOrNull(this.camera),
GameLib.Utils.IdOrNull(this.editCamera),
this.scenes.map(
function(scene){
return GameLib.Utils.IdOrNull(scene);
}
),
GameLib.Utils.IdOrNull(this.defaultScene),
this.viewports.map(
function(viewport){
return GameLib.Utils.IdOrNull(viewport);

View File

@ -0,0 +1,357 @@
/**
* Texture Superset - The apiTexture properties get moved into the Texture object itself, and then the instance is
* created
* @param apiTexture
* @param graphics GameLib.GraphicsRuntime
* @constructor
*/
GameLib.D3.Texture = function(
graphics,
apiTexture
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiTexture)) {
apiTexture = {
textureType : GameLib.D3.API.Texture.TEXTURE_TYPE_NONE
};
}
GameLib.D3.API.Texture.call(
this,
apiTexture.id,
apiTexture.name,
apiTexture.textureType,
apiTexture.parentEntity,
apiTexture.parentMaterials,
apiTexture.mipmaps,
apiTexture.mapping,
apiTexture.wrapS,
apiTexture.wrapT,
apiTexture.magFilter,
apiTexture.minFilter,
apiTexture.anisotropy,
apiTexture.format,
apiTexture.storageType,
apiTexture.offset,
apiTexture.repeat,
apiTexture.rotation,
apiTexture.center,
apiTexture.matrixAutoUpdate,
apiTexture.generateMipMaps,
apiTexture.premultiplyAlpha,
apiTexture.flipY,
apiTexture.unpackAlignment,
apiTexture.encoding,
apiTexture.version,
apiTexture.animated,
apiTexture.reverseAnimation,
apiTexture.forward
);
if (this.offset instanceof GameLib.API.Vector2) {
this.offset = new GameLib.Vector2(
this.graphics,
this.offset,
this
)
}
if (this.repeat instanceof GameLib.API.Vector2) {
this.repeat = new GameLib.Vector2(
this.graphics,
this.repeat,
this
)
}
if (this.center instanceof GameLib.API.Vector2) {
this.center = new GameLib.Vector2(
this.graphics,
this.center,
this
)
}
var linkedObjects = {};
switch (apiTexture.textureType) {
case GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE :
linkedObjects.image = GameLib.Image;
break;
case GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE :
linkedObjects.images = [GameLib.Image];
break;
case GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS :
linkedObjects.canvas = GameLib.Canvas;
break;
default :
throw new Error('Unhandled texture type : ' + this.textureType);
}
GameLib.Component.call(
this,
linkedObjects
);
};
GameLib.D3.Texture.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.Texture.prototype.constructor = GameLib.D3.Texture;
/**
* Creates an instance of our texture object
* @returns {*}
*/
GameLib.D3.Texture.prototype.createInstance = function() {
console.log('creating texture instance');
/**
* Some settings we copy from the instance
*/
this.mipmaps = this.instance.mipmaps;
this.mapping = this.instance.mapping;
this.encoding = this.instance.encoding;
this.format = this.instance.format;
this.storageType = this.instance.type;
this.unpackAlignment = this.instance.unpackAlignment;
this.version = this.instance.version;
/**
* Others we apply to the instance
*/
this.instance.name = this.name;
this.instance.wrapS = this.wrapS;
this.instance.wrapT = this.wrapT;
this.instance.magFilter = this.magFilter;
this.instance.minFilter = this.minFilter;
this.instance.anisotropy = this.anisotropy;
this.instance.offset.x = this.offset.x;
this.instance.offset.y = this.offset.y;
this.instance.repeat.x = this.repeat.x;
this.instance.repeat.y = this.repeat.y;
this.instance.rotation = this.rotation;
this.instance.center.x = this.center.x;
this.instance.center.y = this.center.y;
this.instance.matrixAutoUpdate = this.matrixAutoUpdate;
this.instance.generateMipMaps = this.generateMipMaps;
this.instance.premultiplyAlpha = this.premultiplyAlpha;
this.instance.flipY = this.flipY;
this.instance.needsUpdate = true;
GameLib.Component.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Texture.prototype.updateInstance = function(property) {
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
console.warn('no texture instance');
this.instance.needsUpdate = true;
return;
}
if (GameLib.Utils.UndefinedOrNull(property)) {
console.warn('no texture property');
return;
}
if (property === 'name') {
this.instance.name = this.name;
return;
}
if (property === 'textureType') {
console.warn('todo: texture type change here');
return;
}
if (property === 'mipmaps') {
console.warn('todo: mipmaps change here');
return;
}
if (property === 'mapping') {
this.instance.mapping = this.mapping;
}
if (property === 'wrapS') {
this.instance.wrapS = this.wrapS;
}
if (property === 'wrapT') {
this.instance.wrapT = this.wrapT;
}
if (property === 'magFilter') {
this.instance.magFilter = this.magFilter;
}
if (property === 'minFilter') {
this.instance.minFilter = this.minFilter;
}
if (property === 'anisotropy') {
this.instance.anisotropy = this.anisotropy;
}
if (property === 'format') {
this.instance.format = this.format;
}
if (property === 'storageType') {
this.instance.type = this.storageType;
}
if (property === 'offset') {
this.instance.offset.x = this.offset.x;
this.instance.offset.y = this.offset.y;
return;
}
if (property === 'repeat') {
this.instance.repeat.x = this.repeat.x;
this.instance.repeat.y = this.repeat.y;
return;
}
if (property === 'rotation') {
this.instance.rotation = this.rotation;
return;
}
if (property === 'center') {
this.instance.center.x = this.center.x;
this.instance.center.y = this.center.y;
return;
}
if (property === 'matrixAutoUpdate') {
this.instance.matrixAutoUpdate = this.matrixAutoUpdate;
return;
}
if (property === 'generateMipMaps') {
this.instance.generateMipMaps = this.generateMipMaps;
return;
}
if (property === 'premultiplyAlpha') {
this.instance.premultiplyAlpha = this.premultiplyAlpha;
return;
}
if (property === 'flipY') {
this.instance.flipY = this.flipY;
}
if (property === 'unpackAlignment') {
this.instance.unpackAlignment = this.unpackAlignment;
}
if (property === 'encoding') {
this.instance.encoding = this.encoding;
}
if (property === 'version') {
console.warn('version is read-only');
}
if (property === 'animated') {
GameLib.Event.Emit(
GameLib.Event.TEXTURE_ANIMATED_CHANGE,
{
texture: this
}
)
}
if (property === 'needsUpdate') {
this.needsUpdate = false;
}
/**
* So if you don't return earlier - the instance will re-compile its shader
* @type {boolean}
*/
this.instance.needsUpdate = true;
this.version = this.instance.version;
};
/**
* Converts a GameLib.D3.Texture to a GameLib.D3.API.Texture
* @returns {GameLib.D3.API.Texture}
*/
GameLib.D3.Texture.prototype.toApiObject = function() {
var apiTexture = new GameLib.D3.API.Texture(
this.id,
this.name,
this.textureType,
GameLib.Utils.IdOrNull(this.parentEntity),
this.parentMaterials.map(
function(parentMaterial) {
return GameLib.Utils.IdOrNull(parentMaterial);
}
),
this.mipmaps,
this.mapping,
this.wrapS,
this.wrapT,
this.magFilter,
this.minFilter,
this.anisotropy,
this.format,
this.storageType,
this.offset.toApiObject(),
this.repeat.toApiObject(),
this.rotation,
this.center.toApiObject(),
this.matrixAutoUpdate,
this.generateMipMaps,
this.premultiplyAlpha,
this.flipY,
this.unpackAlignment,
this.encoding,
this.version,
this.animated,
this.reverseAnimation,
this.forward
);
return apiTexture;
};
GameLib.D3.Texture.prototype.updateFromInstance = function() {
this.name = this.instance.name;
this.mipmaps = this.instance.mipmaps;
this.mapping = this.instance.mapping;
this.wrapS = this.instance.wrapS;
this.wrapT = this.instance.wrapT;
this.magFilter = this.instance.magFilter;
this.minFilter = this.instance.minFilter;
this.anisotropy = this.instance.anisotropy;
this.format = this.instance.format;
this.storageType = this.instance.storageType;
this.offset.x = this.instance.offset.x;
this.offset.y = this.instance.offset.y;
this.repeat.x = this.instance.repeat.x;
this.repeat.y = this.instance.repeat.y;
this.rotation = this.instance.rotation;
this.center.x = this.instance.center.x;
this.center.y = this.instance.center.y;
this.matrixAutoUpdate = this.instance.matrixAutoUpdate;
this.generateMipMaps = this.instance.generateMipMaps;
this.premultiplyAlpha = this.instance.premultiplyAlpha;
this.flipY = this.instance.flipY;
this.unpackAlignment = this.instance.unpackAlignment;
this.encoding = this.instance.encoding;
this.version = this.instance.version;
this.animated = this.instance.animated;
this.reverseAnimation = this.instance.reverseAnimation;
this.forward = this.instance.forward;
};

View File

@ -0,0 +1,95 @@
/**
* GameLib.D3.Texture.Canvas
* @param graphics
* @param apiTextureCanvas
* @constructor
*/
GameLib.D3.Texture.Canvas = function(
graphics,
apiTextureCanvas
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiTextureCanvas)) {
apiTextureCanvas = {
textureType : GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS
};
}
GameLib.D3.API.Texture.Canvas.call(
this,
apiTextureCanvas,
apiTextureCanvas.canvas
);
if (this.canvas instanceof GameLib.API.Canvas) {
this.canvas = new GameLib.Canvas(
this.canvas
);
}
GameLib.D3.Texture.call(
this,
this.graphics,
this
);
};
GameLib.D3.Texture.Canvas.prototype = Object.create(GameLib.D3.Texture.prototype);
GameLib.D3.Texture.Canvas.prototype.constructor = GameLib.D3.Texture.Canvas;
/**
* Creates an instance of our texture object
* @returns {*}
*/
GameLib.D3.Texture.Canvas.prototype.createInstance = function() {
if (
GameLib.Utils.UndefinedOrNull(this.canvas) ||
GameLib.Utils.UndefinedOrNull(this.canvas.instance)
) {
console.warn('canvas not ready at time of texture create instance');
return;
}
this.canvas.parentTexture = this;
this.instance = new THREE.Texture(
this.canvas.instance
);
GameLib.D3.Texture.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Texture.Canvas.prototype.updateInstance = function(property) {
if (property === 'canvas') {
this.createInstance();
return;
}
GameLib.D3.Texture.prototype.updateInstance.call(this, property);
};
/**
* Converts a GameLib.D3.Texture.Canvas to a GameLib.D3.API.Texture.Canvas
* @returns {GameLib.D3.API.Texture.Canvas}
*/
GameLib.D3.Texture.Canvas.prototype.toApiObject = function() {
var apiTexture = GameLib.D3.Texture.prototype.toApiObject.call(this);
var apiTextureCanvas = new GameLib.D3.API.Texture.Canvas(
apiTexture,
GameLib.Utils.IdOrNull(this.canvas)
);
return apiTextureCanvas;
};

View File

@ -0,0 +1,140 @@
/**
* GameLib.D3.Texture.Cube
* @param graphics
* @param apiTextureCube
* @constructor
*/
GameLib.D3.Texture.Cube = function(
graphics,
apiTextureCube
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiTextureCube)) {
apiTextureCube = {
textureType : GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE
};
}
GameLib.D3.API.Texture.Cube.call(
this,
apiTextureCube,
apiTextureCube.images
);
this.images = this.images.map(
function(image) {
if (image instanceof GameLib.API.Image) {
return new GameLib.Image(image);
} else {
return image;
}
}
);
GameLib.D3.Texture.call(
this,
this.graphics,
this
);
};
GameLib.D3.Texture.Cube.prototype = Object.create(GameLib.D3.Texture.prototype);
GameLib.D3.Texture.Cube.prototype.constructor = GameLib.D3.Texture.Cube;
/**
* Returns all image instances, or null if one of the images are not loaded
*/
GameLib.D3.Texture.Cube.prototype.getImageInstances = function() {
return this.images.reduce(
function(result, image) {
/**
* If we have a null result return early
*/
if (result === null) {
return result;
}
if (GameLib.Utils.UndefinedOrNull(image.instance)) {
result = null;
} else {
result.push(image.instance);
}
return result;
},
[]
);
};
/**
* Creates an instance of our texture object
* @returns {*}
*/
GameLib.D3.Texture.Cube.prototype.createInstance = function() {
var imageInstances = this.getImageInstances();
if (!imageInstances) {
console.warn('cube texture not ready');
return;
}
this.instance = new THREE.CubeTexture(imageInstances);
GameLib.D3.Texture.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Texture.Cube.prototype.updateInstance = function(property) {
if (property === 'images') {
var imageInstances = this.getImageInstances();
if (imageInstances) {
console.log('updating cube texture image instances');
this.image = imageInstances;
}
this.publish(
GameLib.Event.IMAGE_CHANGED,
{
texture : this
}
);
return;
}
GameLib.D3.Texture.prototype.updateInstance.call(this, property);
};
/**
* Converts a GameLib.D3.Texture.Cube to a GameLib.D3.API.Texture.Cube
* @returns {GameLib.D3.API.Texture.Cube}
*/
GameLib.D3.Texture.Cube.prototype.toApiObject = function() {
var apiTexture = GameLib.D3.Texture.prototype.toApiObject.call(this);
var apiTextureCube = new GameLib.D3.API.Texture.Cube(
apiTexture,
this.images.map(
function(image) {
return GameLib.Utils.IdOrNull(image);
}
)
);
return apiTextureCube;
};

View File

@ -0,0 +1,100 @@
/**
* GameLib.D3.Texture.Image
* @param graphics
* @param apiTextureImage
* @constructor
*/
GameLib.D3.Texture.Image = function(
graphics,
apiTextureImage
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiTextureImage)) {
apiTextureImage = {
textureType : GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE
};
}
GameLib.D3.API.Texture.Image.call(
this,
apiTextureImage,
apiTextureImage.image
);
if (this.image instanceof GameLib.API.Image) {
this.image = new GameLib.Image(
this.image
);
}
GameLib.D3.Texture.call(
this,
this.graphics,
this
);
};
GameLib.D3.Texture.Image.prototype = Object.create(GameLib.D3.Texture.prototype);
GameLib.D3.Texture.Image.prototype.constructor = GameLib.D3.Texture.Image;
/**
* Creates an instance of our texture object
* @returns {*}
*/
GameLib.D3.Texture.Image.prototype.createInstance = function() {
if (
GameLib.Utils.UndefinedOrNull(this.image) ||
GameLib.Utils.UndefinedOrNull(this.image.instance)
) {
console.warn('image not ready at time of texture create instance');
return;
}
this.instance = new THREE.Texture(
this.image.instance
);
GameLib.D3.Texture.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Texture.Image.prototype.updateInstance = function(property) {
if (property === 'image') {
this.publish(
GameLib.Event.IMAGE_CHANGED,
{
texture : this
}
);
this.instance.needsUpdate = true;
return;
}
GameLib.D3.Texture.prototype.updateInstance.call(this, property);
};
/**
* Converts a GameLib.D3.Texture.Image to a GameLib.D3.API.Texture.Image
* @returns {GameLib.D3.API.Texture.Image}
*/
GameLib.D3.Texture.Image.prototype.toApiObject = function() {
var apiTexture = GameLib.D3.Texture.prototype.toApiObject.call(this);
var apiTextureImage = new GameLib.D3.API.Texture.Image(
apiTexture,
GameLib.Utils.IdOrNull(this.image)
);
return apiTextureImage;
};

View File

@ -1,394 +0,0 @@
/**
* Texture Superset - The apiTexture properties get moved into the Texture object itself, and then the instance is
* created
* @param apiTexture
* @param graphics GameLib.GraphicsRuntime
* @constructor
*/
GameLib.D3.Texture = function(
graphics,
apiTexture
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiTexture)) {
apiTexture = {};
}
GameLib.D3.API.Texture.call(
this,
apiTexture.id,
apiTexture.textureType,
apiTexture.name,
apiTexture.image,
apiTexture.images,
apiTexture.wrapS,
apiTexture.wrapT,
apiTexture.repeat,
apiTexture.data,
apiTexture.format,
apiTexture.mapping,
apiTexture.magFilter,
apiTexture.minFilter,
apiTexture.storageType,
apiTexture.anisotropy,
apiTexture.offset,
apiTexture.generateMipmaps,
apiTexture.flipY,
apiTexture.mipmaps,
apiTexture.unpackAlignment,
apiTexture.premultiplyAlpha,
apiTexture.encoding,
apiTexture.canvas,
apiTexture.animated,
apiTexture.reverseAnimation,
apiTexture.forward,
apiTexture.parentEntity
);
this.offset = new GameLib.Vector2(
this.graphics,
this.offset,
this
);
this.repeat = new GameLib.Vector2(
this.graphics,
this.repeat,
this
);
if (this.image instanceof GameLib.API.Image) {
this.image = new GameLib.Image(
this.graphics,
this.image
);
}
this.images = this.images.map(
function(image) {
if (image instanceof GameLib.API.Image) {
return new GameLib.Image(
this.graphics,
image
);
} else {
return image;
}
}.bind(this)
);
if (this.canvas instanceof GameLib.API.Canvas) {
this.canvas = new GameLib.Canvas(
this.graphics,
this.canvas
);
}
GameLib.Component.call(
this,
{
'image' : GameLib.Image,
'images' : [GameLib.Image],
'canvas' : GameLib.Canvas
}
);
};
GameLib.D3.Texture.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.Texture.prototype.constructor = GameLib.D3.Texture;
/**
* Creates an instance of our texture object
* @returns {*}
*/
GameLib.D3.Texture.prototype.createInstance = function() {
if (this.textureType === GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE) {
if (this.images.length !== 6) {
throw new Error('not enough images for cube texture');
}
var imageInstances = this.images.map(
function(image) {
if (GameLib.Utils.UndefinedOrNull(image)) {
throw new Error('no image');
}
if (GameLib.Utils.UndefinedOrNull(image.instance)) {
throw new Error('no image instance');
}
return image.instance
}
);
this.instance = new THREE.CubeTexture(imageInstances);
} else if (this.textureType === GameLib.D3.API.Texture.TEXTURE_TYPE_NORMAL) {
if (
GameLib.Utils.UndefinedOrNull(this.image) ||
GameLib.Utils.UndefinedOrNull(this.image.instance)
) {
this.instance = new THREE.Texture();
} else {
//if (GameLib.Utils.UndefinedOrNull(this.image.instance)) {
// throw new Error('no image instance');
//}
this.instance = new THREE.Texture(
this.image.instance
);
}
} else if (this.textureType === GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS) {
if (GameLib.Utils.UndefinedOrNull(this.canvas)) {
this.instance = new THREE.Texture();
} else {
if (GameLib.Utils.UndefinedOrNull(this.canvas.instance)) {
throw new Error('no canvas instance');
}
this.canvas.parentTexture = this;
this.instance = new THREE.Texture(
this.canvas.instance
);
}
}
/**
* Some settings we copy from the instance
*/
this.mapping = this.instance.mapping;
this.encoding = this.instance.encoding;
this.format = this.instance.format;
/**
* Others we apply to the instance
*/
this.instance.name = this.name;
this.instance.flipY = this.flipY;
this.instance.offset.x = this.offset.x;
this.instance.offset.y = this.offset.y;
this.instance.repeat.x = this.repeat.x;
this.instance.repeat.y = this.repeat.y;
this.instance.wrapS = this.wrapS;
this.instance.wrapT = this.wrapT;
this.instance.needsUpdate = true;
GameLib.Component.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Texture.prototype.updateInstance = function(property) {
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
try {
this.createInstance();
return;
} catch (error) {
console.error(error);
}
}
if (GameLib.Utils.UndefinedOrNull(property)) {
throw new Error('need to specify a property');
}
if (
property === 'textureType' ||
property === 'canvas' ||
property === 'image'
) {
this.createInstance();
// }
//
// if (property === 'image') {
// if (this.textureType === GameLib.D3.API.Texture.TEXTURE_TYPE_NORMAL) {
//
// if (
// GameLib.Utils.UndefinedOrNull(this.image) &&
// this.instance.image
// ) {
// try {
// this.createInstance();
// } catch (error) {
// console.error(error);
// }
// }
//
// if (this.image && this.image.instance && this.instance.image !== this.image.instance) {
// try {
// this.createInstance();
// } catch (error) {
// console.error(error);
// }
// }
//
// } else if (this.textureType === GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS) {
//
// if (
// GameLib.Utils.UndefinedOrNull(this.canvas) &&
// this.instance.canvas
// ) {
// try {
// this.createInstance();
// } catch (error) {
// console.error(error);
// }
// }
//
// if (this.canvas && this.canvas.instance && this.instance.image !== this.canvas.instance) {
// try {
// this.createInstance();
// } catch (error) {
// console.error(error);
// }
// }
//
// } else if (this.textureType === GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE) {
//
// console.log('todo : cube images change check here');
// }
this.publish(
GameLib.Event.IMAGE_CHANGED,
{
texture : this
}
);
this.instance.needsUpdate = true;
}
if (property === 'name') {
this.instance.name = this.name;
}
if (property === 'flipY') {
this.instance.flipY = this.flipY;
this.instance.needsUpdate = true;
}
if (property === 'encoding') {
this.instance.encoding = this.encoding;
}
if (property === 'offset') {
this.instance.offset.x = this.offset.x;
this.instance.offset.y = this.offset.y;
}
if (property === 'repeat') {
this.instance.repeat.x = this.repeat.x;
this.instance.repeat.y = this.repeat.y;
}
if (property === 'mapping') {
this.instance.mapping = this.mapping;
}
if (property === 'format') {
this.instance.format = this.format;
}
if (property === 'wrapS') {
this.instance.wrapS = this.wrapS;
this.instance.needsUpdate = true;
}
if (property === 'wrapT') {
this.instance.wrapT = this.wrapT;
this.instance.needsUpdate = true;
}
if (property === 'animated') {
GameLib.Event.Emit(
GameLib.Event.TEXTURE_ANIMATED_CHANGE,
{
texture : this
}
)
}
};
/**
* Converts a GameLib.D3.Texture to a GameLib.D3.API.Texture
* @returns {GameLib.D3.API.Texture}
*/
GameLib.D3.Texture.prototype.toApiObject = function() {
var apiTexture = new GameLib.D3.API.Texture(
this.id,
this.textureType,
this.name,
GameLib.Utils.IdOrNull(this.image),
this.images.map(
function(image) {
return GameLib.Utils.IdOrNull(image)
}
),
this.wrapS,
this.wrapT,
this.repeat.toApiObject(),
this.data,
this.format,
this.mapping,
this.magFilter,
this.minFilter,
this.storageType,
this.anisotropy,
this.offset.toApiObject(),
this.generateMipmaps,
this.flipY,
this.mipmaps,
this.unpackAlignment,
this.premultiplyAlpha,
this.encoding,
GameLib.Utils.IdOrNull(this.canvas),
this.animated,
this.reverseAnimation,
this.forward,
GameLib.Utils.IdOrNull(this.parentEntity)
);
return apiTexture;
};
/**
* Converts from an Object texture to a GameLib.D3.Texture
* @param graphics GameLib.GraphicsRuntime
* @param objectTexture Object
* @constructor
*/
GameLib.D3.Texture.FromObject = function(
graphics,
objectTexture
) {
var apiTexture = GameLib.D3.API.Texture.FromObject(objectTexture);
return new GameLib.D3.Texture(
graphics,
apiTexture
);
};

View File

@ -15,15 +15,21 @@ GameLib.Image = function(
this,
apiImage.id,
apiImage.name,
apiImage.parentEntity,
apiImage.parentTexture,
apiImage.fileName,
apiImage.extension,
apiImage.path,
apiImage.contentType,
apiImage.size,
apiImage.parentEntity
apiImage.size
);
GameLib.Component.call(this);
GameLib.Component.call(
this,
{
parentTexture : GameLib.D3.Texture
}
);
};
GameLib.Image.prototype = Object.create(GameLib.Component.prototype);
@ -90,24 +96,14 @@ GameLib.Image.prototype.toApiObject = function() {
var apiImage = new GameLib.API.Image(
this.id,
this.name,
GameLib.Utils.IdOrNull(this.parentEntity),
GameLib.Utils.IdOrNull(this.parentTexture),
this.fileName,
this.extension,
this.path,
this.contentType,
this.size,
GameLib.Utils.IdOrNull(this.parentEntity)
this.size
);
return apiImage;
};
/**
* @param objectImage
* @returns {GameLib.Image}
* @constructor
*/
GameLib.Image.FromObject = function(objectImage) {
return new GameLib.Image(
GameLib.API.Image.FromObject(objectImage)
);
};

View File

@ -0,0 +1,188 @@
/**
* GameLib.RenderConfiguration
* @param apiRenderConfiguration GameLib.API.RenderConfiguration
* @constructor
*/
GameLib.RenderConfiguration = function (
apiRenderConfiguration
) {
if (GameLib.Utils.UndefinedOrNull(apiRenderConfiguration)) {
apiRenderConfiguration = {};
}
GameLib.API.RenderConfiguration.call(
this,
apiRenderConfiguration.id,
apiRenderConfiguration.name,
apiRenderConfiguration.parentEntity,
apiRenderConfiguration.logicalSize,
apiRenderConfiguration.aspectRatio,
apiRenderConfiguration.scaleMode,
apiRenderConfiguration.activeCamera,
apiRenderConfiguration.activeScenes,
apiRenderConfiguration.activeRenderer,
apiRenderConfiguration.activeComposer,
apiRenderConfiguration.activeEffect,
apiRenderConfiguration.enableComposer,
apiRenderConfiguration.enableEffect
);
GameLib.Component.call(
this,
{
'activeCamera' : GameLib.D3.Camera,
'activeScenes' : [GameLib.D3.Scene],
'activeRenderer' : GameLib.D3.Renderer,
'activeComposer' : GameLib.D3.Composer,
'activeEffect' : GameLib.D3.Effect
}
);
};
GameLib.RenderConfiguration.prototype = Object.create(GameLib.Component.prototype);
GameLib.RenderConfiguration.prototype.constructor = GameLib.RenderConfiguration;
/**
* Create RenderConfiguration Instance
* @returns {*}
*/
GameLib.RenderConfiguration.prototype.createInstance = function() {
this.instance = {};
GameLib.Component.prototype.createInstance.call(this);
};
/**
* Update RenderConfiguration Instance
*/
GameLib.RenderConfiguration.prototype.updateInstance = function(property) {
if (
property === 'logicalSize' ||
property === 'aspectRatio' ||
property === 'scaleMode'
) {
console.log('todo: implement fixed aspect ratios for different scale modes');
if (
GameLib.Utils.Defined(this.activeCamera) &&
GameLib.Utils.Defined(this.activeCamera.instance)
) {
/**
* For now - just use normal aspect ratio
*/
GameLib.Event.Emit(
GameLib.Event.GET_WINDOW_SIZE,
{},
function(data) {
if (data.width === data.height) {
console.log('square');
}
if (data.width > data.height) {
console.log('landscape');
}
if (data.width < data.height) {
console.log('portrait');
}
this.activeCamera.aspect = data.width / data.height;
this.activeCamera.updateInstance('aspect');
}.bind(this)
)
}
return;
}
if (property === 'activeCamera') {
if (
GameLib.Utils.Defined(this.activeCamera) &&
GameLib.Utils.Defined(this.activeCamera.instance)
) {
/**
* Update the aspect ratio for the active camera
*/
this.updateInstance('aspectRatio');
}
}
if (
property === 'activeScenes' ||
property === 'activeRenderer' ||
property === 'activeComposer' ||
property === 'activeEffect'
) {
console.log('todo: active component update');
return;
}
if (
property === 'enableComposer'
) {
if (this.enableComposer) {
if (this.enableEffect) {
this.enableComposer = false;
console.warn('Only one of effect or composer can be enabled, not both at the same time');
return;
}
}
return;
}
if (
property === 'enableEffect'
) {
if (this.enableEffect) {
if (this.enableComposer) {
this.enableEffect = false;
console.warn('Only one of effect or composer can be enabled, not both at the same time');
return;
}
}
return;
}
};
/**
*
* @returns {GameLib.API.RenderConfiguration}
*/
GameLib.RenderConfiguration.prototype.toApiObject = function() {
var apiRenderConfiguration = new GameLib.API.RenderConfiguration(
this.id,
this.name,
GameLib.Utils.IdOrNull(this.parentEntity),
this.logicalSize.toApiObject(),
this.aspectRatio,
this.scaleMode,
GameLib.Utils.IdOrNull(this.activeCamera),
this.activeScenes.map(
function(activeScene) {
return GameLib.Utils.IdOrNull(activeScene);
}
),
GameLib.Utils.IdOrNull(this.activeRenderer),
GameLib.Utils.IdOrNull(this.activeComposer),
GameLib.Utils.IdOrNull(this.activeEffect),
this.enableComposer,
this.enableEffect
);
return apiRenderConfiguration;
};

View File

@ -429,7 +429,7 @@ GameLib.System.GUI.prototype.buildQuaternionControl = function(folder, component
GameLib.System.GUI.prototype.buildVectorControl = function(folder, componentTemplate, property) {
var step = 0.00001;
var step = 0.001;
var object = componentTemplate.template;
@ -593,6 +593,7 @@ GameLib.System.GUI.prototype.buildArrayManagerControl = function(
'remove' : function() {
componentTemplate.affected.map(function(component){
component[property].splice(index, 1);
component.updateInstance(property);
folder.remove(controller);
});
}
@ -871,10 +872,6 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
grain = object.grain;
}
if (property === 'bias') {
grain = 0.0001;
}
if (property === 'componentType') {
var readOnly = {
@ -965,7 +962,7 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
}
)
);
} else if (property === 'renderMode' || property === 'lastRenderMode') {
} else if (property === 'renderMode') {
controllers.push(
folder.add(
object,
@ -973,8 +970,7 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
{
'canvas': GameLib.D3.API.Renderer.MODE_CANVAS,
'target': GameLib.D3.API.Renderer.MODE_TARGET,
'canvas and target': GameLib.D3.API.Renderer.MODE_CANVAS_AND_TARGET,
'edit': GameLib.D3.API.Renderer.MODE_EDIT
'canvas and target': GameLib.D3.API.Renderer.MODE_CANVAS_AND_TARGET
}
)
);
@ -1154,12 +1150,12 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
object,
property,
{
'standard': GameLib.D3.Material.MATERIAL_TYPE_STANDARD,
'basic': GameLib.D3.Material.MATERIAL_TYPE_BASIC,
'phong': GameLib.D3.Material.MATERIAL_TYPE_PHONG,
'points': GameLib.D3.Material.MATERIAL_TYPE_POINTS,
'toon': GameLib.D3.Material.MATERIAL_TYPE_TOON,
'line basic' : GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC
'standard': GameLib.D3.API.Material.MATERIAL_TYPE_STANDARD,
'basic': GameLib.D3.API.Material.MATERIAL_TYPE_BASIC,
'phong': GameLib.D3.API.Material.MATERIAL_TYPE_PHONG,
'points': GameLib.D3.API.Material.MATERIAL_TYPE_POINTS,
'toon': GameLib.D3.API.Material.MATERIAL_TYPE_TOON,
'line basic' : GameLib.D3.API.Material.MATERIAL_TYPE_LINE_BASIC
}
)
);
@ -1169,9 +1165,9 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
object,
property,
{
'double': GameLib.D3.Material.TYPE_DOUBLE_SIDE,
'front': GameLib.D3.Material.TYPE_FRONT_SIDE,
'back': GameLib.D3.Material.TYPE_BACK_SIDE
'double': GameLib.D3.API.Material.TYPE_DOUBLE_SIDE,
'front': GameLib.D3.API.Material.TYPE_FRONT_SIDE,
'back': GameLib.D3.API.Material.TYPE_BACK_SIDE
}
)
);
@ -1181,9 +1177,9 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
object,
property,
{
'multiply': GameLib.D3.Material.TYPE_MULTIPLY_OPERATION,
'mix': GameLib.D3.Material.TYPE_MIX_OPERATION,
'add': GameLib.D3.Material.TYPE_ADD_OPERATION
'multiply': GameLib.D3.API.Material.TYPE_MULTIPLY_OPERATION,
'mix': GameLib.D3.API.Material.TYPE_MIX_OPERATION,
'add': GameLib.D3.API.Material.TYPE_ADD_OPERATION
}
)
);
@ -1193,9 +1189,9 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
object,
property,
{
'none': GameLib.D3.Material.TYPE_NO_COLORS,
'face': GameLib.D3.Material.TYPE_FACE_COLORS,
'vertex': GameLib.D3.Material.TYPE_VERTEX_COLORS
'none': GameLib.D3.API.Material.TYPE_NO_COLORS,
'face': GameLib.D3.API.Material.TYPE_FACE_COLORS,
'vertex': GameLib.D3.API.Material.TYPE_VERTEX_COLORS
}
)
);
@ -1205,12 +1201,12 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
object,
property,
{
'none': GameLib.D3.Material.TYPE_NO_BLENDING,
'normal': GameLib.D3.Material.TYPE_NORMAL_BLENDING,
'additive': GameLib.D3.Material.TYPE_ADDITIVE_BLENDING,
'subtractive': GameLib.D3.Material.TYPE_SUBTRACTIVE_BLENDING,
'multiply': GameLib.D3.Material.TYPE_MULTIPLY_BLENDING,
'custom': GameLib.D3.Material.TYPE_CUSTOM_BLENDING
'none': GameLib.D3.API.Material.TYPE_NO_BLENDING,
'normal': GameLib.D3.API.Material.TYPE_NORMAL_BLENDING,
'additive': GameLib.D3.API.Material.TYPE_ADDITIVE_BLENDING,
'subtractive': GameLib.D3.API.Material.TYPE_SUBTRACTIVE_BLENDING,
'multiply': GameLib.D3.API.Material.TYPE_MULTIPLY_BLENDING,
'custom': GameLib.D3.API.Material.TYPE_CUSTOM_BLENDING
}
)
);
@ -1220,17 +1216,17 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
object,
property,
{
'zero': GameLib.D3.Material.TYPE_ZERO_FACTOR,
'one': GameLib.D3.Material.TYPE_ONE_FACTOR,
'source color': GameLib.D3.Material.TYPE_SRC_COLOR_FACTOR,
'one minus source color': GameLib.D3.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR,
'source alpha': GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR,
'one minus source alpha': GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR,
'destination alpha': GameLib.D3.Material.TYPE_DST_ALPHA_FACTOR,
'one minus destination alpha': GameLib.D3.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR,
'destination color': GameLib.D3.Material.TYPE_DST_COLOR_FACTOR,
'one minus destination color': GameLib.D3.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR,
'source alpha saturate': GameLib.D3.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR
'zero': GameLib.D3.API.Material.TYPE_ZERO_FACTOR,
'one': GameLib.D3.API.Material.TYPE_ONE_FACTOR,
'source color': GameLib.D3.API.Material.TYPE_SRC_COLOR_FACTOR,
'one minus source color': GameLib.D3.API.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR,
'source alpha': GameLib.D3.API.Material.TYPE_SRC_ALPHA_FACTOR,
'one minus source alpha': GameLib.D3.API.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR,
'destination alpha': GameLib.D3.API.Material.TYPE_DST_ALPHA_FACTOR,
'one minus destination alpha': GameLib.D3.API.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR,
'destination color': GameLib.D3.API.Material.TYPE_DST_COLOR_FACTOR,
'one minus destination color': GameLib.D3.API.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR,
'source alpha saturate': GameLib.D3.API.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR
}
)
);
@ -1240,17 +1236,17 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
object,
property,
{
'zero': GameLib.D3.Material.TYPE_ZERO_FACTOR,
'one': GameLib.D3.Material.TYPE_ONE_FACTOR,
'source color': GameLib.D3.Material.TYPE_SRC_COLOR_FACTOR,
'one minus source color': GameLib.D3.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR,
'source alpha': GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR,
'one minus source alpha': GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR,
'destination alpha': GameLib.D3.Material.TYPE_DST_ALPHA_FACTOR,
'one minus destination alpha': GameLib.D3.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR,
'destination color': GameLib.D3.Material.TYPE_DST_COLOR_FACTOR,
'one minus destination color': GameLib.D3.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR,
'source alpha saturate': GameLib.D3.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR
'zero': GameLib.D3.API.Material.TYPE_ZERO_FACTOR,
'one': GameLib.D3.API.Material.TYPE_ONE_FACTOR,
'source color': GameLib.D3.API.Material.TYPE_SRC_COLOR_FACTOR,
'one minus source color': GameLib.D3.API.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR,
'source alpha': GameLib.D3.API.Material.TYPE_SRC_ALPHA_FACTOR,
'one minus source alpha': GameLib.D3.API.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR,
'destination alpha': GameLib.D3.API.Material.TYPE_DST_ALPHA_FACTOR,
'one minus destination alpha': GameLib.D3.API.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR,
'destination color': GameLib.D3.API.Material.TYPE_DST_COLOR_FACTOR,
'one minus destination color': GameLib.D3.API.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR,
'source alpha saturate': GameLib.D3.API.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR
}
)
);
@ -1260,11 +1256,11 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
object,
property,
{
'add': GameLib.D3.Material.TYPE_ADD_EQUATION,
'subtract': GameLib.D3.Material.TYPE_SUBTRACT_EQUATION,
'reverse subtract': GameLib.D3.Material.TYPE_REVERSE_SUBTRACT_EQUATION,
'min': GameLib.D3.Material.TYPE_MIN_EQUATION,
'max': GameLib.D3.Material.TYPE_MAX_EQUATION
'add': GameLib.D3.API.Material.TYPE_ADD_EQUATION,
'subtract': GameLib.D3.API.Material.TYPE_SUBTRACT_EQUATION,
'reverse subtract': GameLib.D3.API.Material.TYPE_REVERSE_SUBTRACT_EQUATION,
'min': GameLib.D3.API.Material.TYPE_MIN_EQUATION,
'max': GameLib.D3.API.Material.TYPE_MAX_EQUATION
}
)
);
@ -1274,14 +1270,14 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
object,
property,
{
'never': GameLib.D3.Material.TYPE_NEVER_DEPTH,
'always': GameLib.D3.Material.TYPE_ALWAYS_DEPTH,
'less depth': GameLib.D3.Material.TYPE_LESS_DEPTH,
'less equal depth': GameLib.D3.Material.TYPE_LESS_EQUAL_DEPTH,
'equal depth': GameLib.D3.Material.TYPE_EQUAL_DEPTH,
'greated equal depth': GameLib.D3.Material.TYPE_GREATER_EQUAL_DEPTH,
'greated depth': GameLib.D3.Material.TYPE_GREATER_DEPTH,
'not equal depth': GameLib.D3.Material.TYPE_NOT_EQUAL_DEPTH
'never': GameLib.D3.API.Material.TYPE_NEVER_DEPTH,
'always': GameLib.D3.API.Material.TYPE_ALWAYS_DEPTH,
'less depth': GameLib.D3.API.Material.TYPE_LESS_DEPTH,
'less equal depth': GameLib.D3.API.Material.TYPE_LESS_EQUAL_DEPTH,
'equal depth': GameLib.D3.API.Material.TYPE_EQUAL_DEPTH,
'greated equal depth': GameLib.D3.API.Material.TYPE_GREATER_EQUAL_DEPTH,
'greated depth': GameLib.D3.API.Material.TYPE_GREATER_DEPTH,
'not equal depth': GameLib.D3.API.Material.TYPE_NOT_EQUAL_DEPTH
}
)
);
@ -1371,19 +1367,19 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
}
)
);
} else if (componentType === GameLib.Component.TEXTURE && property === 'textureType') {
} else if (property === 'textureType') {
controllers.push(
folder.add(
object,
property,
{
'normal': GameLib.D3.API.Texture.TEXTURE_TYPE_NORMAL,
'normal': GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE,
'cube': GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE,
'canvas': GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS
}
)
);
} else if (property === 'textureType') {
} else if (property === 'storageType') {
controllers.push(
folder.add(
object,
@ -1493,7 +1489,7 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
);
} else {
/**
/**
* Try to guess a scale for this property
*/
if (
@ -1584,7 +1580,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
) {
controllers.push(folder.add(object, property, 1, 50, 1));
} else if (
property === 'density'
property === 'density' ||
property === 'bias'
) {
controllers.push(folder.add(object, property, 0, 1, 0.0001));
} else if (
@ -1596,10 +1593,17 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
property === 'port'
) {
controllers.push(folder.add(object, property, 1, 65536, 1));
} else if (
property === 'eyeSep'
) {
controllers.push(folder.add(object, property, -2, 2, 0.0001));
} else {
controllers.push(folder.add(object, property, -1000, 1000, 0.1));
}
}
}
}
controllers.map(
@ -2072,7 +2076,13 @@ GameLib.System.GUI.prototype.buildGUI = function(data) {
if (
templateProperty.indexOf('parent') === 0
) {
this.buildParentSelectionControl(folder, componentTemplate, templateProperty);
if (componentTemplate.template[templateProperty] instanceof Array) {
console.warn('read-only property :' + templateProperty);
} else {
this.buildParentSelectionControl(folder, componentTemplate, templateProperty);
}
continue;
}

View File

@ -574,11 +574,9 @@ GameLib.System.Linking.prototype.imageChanged = function(data) {
var textures = material.getTextures();
if (textures.indexOf(data.texture) !== -1) {
if (material.loaded) {
material.updateInstance('diffuseMap');
}
}
});
@ -622,19 +620,22 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) {
/**
* Find all textures which use this image
*/
GameLib.EntityManager.Instance.queryComponents(GameLib.Component.TEXTURE).map(
GameLib.EntityManager.Instance.queryComponents(GameLib.Component.TEXTURE_IMAGE).map(
function(texture) {
if (texture.image === data.component ||
texture.images.indexOf(data.component) !== -1
) {
/**
* Ok - this image is in use - this should notify materials when its image changes
*/
if (texture.image === data.component) {
texture.updateInstance('image');
}
}
);
GameLib.EntityManager.Instance.queryComponents(GameLib.Component.TEXTURE_CUBE).map(
function(texture) {
if (texture.images.indexOf(data.component) !== -1) {
texture.updateInstance('images');
}
}
);
}
/**

View File

@ -22,6 +22,15 @@ GameLib.System.Render = function(
this.animationFrameHook = null;
this.renderConfigurations = [];
this.renderers = [];
this.composers = [];
this.statistics = [];
this.cubeCameras = [];
};
GameLib.System.Render.prototype = Object.create(GameLib.System.prototype);
@ -34,10 +43,16 @@ GameLib.System.Render.prototype.start = function() {
GameLib.System.prototype.start.call(this);
this.renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RENDERER);
this.renderConfigurations = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RENDER_CONFIGURATION);
this.renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RENDERER);
this.composers = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.COMPOSER);
this.statistics = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.STATS);
this.cubeCameras = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CAMERA_CUBE);
this.instanceCreatedSubscription = GameLib.Event.Subscribe(
GameLib.Event.INSTANCE_CREATED,
this.instanceCreated.bind(this)
@ -58,6 +73,11 @@ GameLib.System.Render.prototype.start = function() {
this.windowResize
);
// this.delayedInstanceEncounteredSubscription = GameLib.Event.Subscribe(
// GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED,
// this.delayedInstanceEncountered.bind(this)
// );
// window.addEventListener(
// 'resize',
// this.nativeWindowResize,
@ -81,6 +101,11 @@ GameLib.System.Render.prototype.start = function() {
this.run();
};
//
// GameLib.System.Render.prototype.delayedInstanceEncountered = function() {
//
//
// };
GameLib.System.Render.prototype.run = function() {
@ -125,11 +150,34 @@ GameLib.System.Render.prototype.windowResize = function(data) {
renderers.map(
function(renderer) {
renderer.setSize(data.width, data.height);
}
);
renderer.windowSize.x = data.width;
renderer.windowSize.y = data.height;
var effects = GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Effect);
renderer.updateInstance('windowSize');
effects.map(
function(effect){
effect.setSize(data.width, data.height);
}
);
GameLib.EntityManager.Instance.queryComponents(GameLib.Component.COMPOSER).map(
function(composer){
composer.setSize(
data.width,
data.height
);
composer.passes.map(
function(pass) {
pass.setSize(
data.width,
data.height
)
}
)
}
);
@ -146,29 +194,64 @@ GameLib.System.Render.prototype.windowResize = function(data) {
*/
GameLib.System.Render.prototype.instanceCreated = function(data) {
if (data.component instanceof GameLib.RenderConfiguration) {
console.log('adding render configuration to render system');
this.renderConfigurations.push(data.component);
}
if (data.component instanceof GameLib.D3.Renderer) {
console.log('adding renderer to render system');
this.renderers.push(data.component);
}
if (data.component instanceof GameLib.D3.Composer) {
console.log('adding composer to render system');
this.composers.push(data.component);
}
if (data.component instanceof GameLib.Stats) {
this.statistics.push(data.component);
}
/**
* Link Parent Textures to Canvas Objects
*/
if (data.component instanceof GameLib.D3.Camera.Cube) {
this.cubeCameras.push(data.component);
}
if (data.component instanceof GameLib.D3.Texture) {
/**
* Link Parent Textures to Canvas Objects
*/
GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CANVAS).map(
function(canvas){
if (canvas.parentTexture === data.component.id) {
canvas.parentTexture = data.component;
}
}
);
/**
* Find all Render Targets and see if their textures need updating
*/
GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RENDER_TARGET).map(
function(renderTarget) {
if (renderTarget.texture === data.component) {
/**
* We found a render target which has this component as their texture - their instance
* has been updated
*/
if (renderTarget.texture.instance !== renderTarget.instance.texture) {
console.log('updating render target texture instance');
renderTarget.instance.texture = renderTarget.texture.instance;
}
}
}
)
}
if (data.component instanceof GameLib.Canvas) {
GameLib.EntityManager.Instance.queryComponents(GameLib.Component.TEXTURE).map(
GameLib.EntityManager.Instance.queryComponents(GameLib.Component.TEXTURE_CANVAS).map(
function(texture){
if (data.component.parentTexture === texture.id) {
data.component.parentTexture = texture;
@ -186,6 +269,20 @@ GameLib.System.Render.prototype.removeComponent = function(data) {
var index;
if (data.component instanceof GameLib.RenderConfiguration) {
index = this.renderConfigurations.indexOf(data.component);
if (index !== -1) {
console.log('removing renderer configuration from system');
this.renderConfigurations.splice(index, 1);
} else {
console.log('failed to find the render configuration in the system : ' + data.component.name);
}
}
if (data.component instanceof GameLib.D3.Renderer) {
index = this.renderers.indexOf(data.component);
@ -200,6 +297,20 @@ GameLib.System.Render.prototype.removeComponent = function(data) {
}
}
if (data.component instanceof GameLib.D3.Composer) {
index = this.composers.indexOf(data.component);
if (index !== -1) {
console.log('removing composer from system');
this.composers.splice(index, 1);
} else {
console.log('failed to find the composer in the system : ' + data.component.name);
}
}
if (data.component instanceof GameLib.Stats) {
index = this.statistics.indexOf(data.component);
@ -214,6 +325,19 @@ GameLib.System.Render.prototype.removeComponent = function(data) {
}
}
if (data.component instanceof GameLib.D3.Camera.Cube) {
index = this.cubeCameras.indexOf(data.component);
if (index !== -1) {
console.log('removing cube camera from system');
this.cubeCameras.splice(index, 1);
} else {
console.log('failed to find the cube camera in the system : ' + data.component.name);
}
}
};
/**
@ -234,142 +358,103 @@ GameLib.System.Render.prototype.render = function(data) {
data
);
this.renderers.map(
this.renderConfigurations.map(
function(configuration) {
function(renderer){
var renderer = configuration.activeRenderer;
if (renderer.viewports.length > 1) {
renderer.instance.autoClear = false;
var scenes = configuration.activeScenes;
var camera = configuration.activeCamera;
var effect = configuration.activeEffect;
var composer = configuration.activeComposer;
if (
configuration.enableEffect &&
(!effect || !effect.instance)
) {
console.warn('no effect');
return;
}
if (renderer.scenes.length > 1) {
renderer.instance.autoClear = false;
if (
configuration.enableComposer &&
(!composer || !composer.instance)
) {
console.warn('no composer');
return;
}
renderer.instance.clear();
if (
renderer.renderMode === GameLib.D3.API.Renderer.MODE_TARGET ||
renderer.renderMode === GameLib.D3.API.Renderer.MODE_CANVAS_AND_TARGET
) {
if (!renderer.target) {
console.warn('no render target');
if (!renderer.renderTarget) {
console.warn('no render renderTarget');
return;
}
}
var size = renderer.getSize();
renderer.viewports.map(
function(viewport) {
var trueOffsetX = viewport.x * renderer.width * renderer.windowSize.x;
var trueOffsetY = viewport.y * renderer.height * renderer.windowSize.y;
var trueWidth = viewport.width * renderer.width * renderer.windowSize.x;
var trueHeight = viewport.height * renderer.height * renderer.windowSize.y;
renderer.instance.setViewport(
trueOffsetX,
trueOffsetY,
trueWidth,
trueHeight
renderer.setViewport(
viewport.x * size.width,
viewport.y * size.height,
viewport.width * size.width,
viewport.height * size.height
);
//var aspect = trueWidth / trueHeight;
if (configuration.enableComposer) {
composer.render();
return;
}
scenes.map(
renderer.scenes.map(
function (scene) {
var camera = renderer.camera;
/**
* Update any cube camera's based on the scene
*/
this.cubeCameras.map(
function(cubeCamera) {
cubeCamera.update(renderer, scene);
}
);
if (renderer.renderMode === GameLib.D3.API.Renderer.MODE_TARGET ||
renderer.renderMode === GameLib.D3.API.Renderer.MODE_CANVAS_AND_TARGET) {
renderer.renderToTarget(
scene,
camera
)
if (scene.camera && scene.camera.instance) {
camera = scene.camera;
}
if (renderer.renderMode === GameLib.D3.API.Renderer.MODE_EDIT) {
if (renderer.renderMode === GameLib.D3.API.Renderer.MODE_CANVAS ||
renderer.renderMode === GameLib.D3.API.Renderer.MODE_CANVAS_AND_TARGET) {
if (!renderer.editCamera || !renderer.editCamera.instance) {
console.warn('edit camera not ready');
if (configuration.enableEffect) {
effect.render(scene, camera);
return;
}
camera = renderer.editCamera;
renderer.render(scene, camera);
}
/**
* Ensure the camera aspect ratio
*/
// if (camera.aspect !== aspect) {
// camera.aspect = aspect;
// camera.updateInstance('aspect');
// }
if (renderer.renderMode === GameLib.D3.API.Renderer.MODE_TARGET) {
renderer.instance.render(
scene.instance,
camera.instance,
renderer.target.instance
)
} else if (renderer.renderMode === GameLib.D3.API.Renderer.MODE_CANVAS) {
renderer.instance.render(
scene.instance,
camera.instance
)
} else if (renderer.renderMode === GameLib.D3.API.Renderer.MODE_CANVAS_AND_TARGET) {
renderer.instance.render(
scene.instance,
camera.instance,
renderer.target.instance
);
renderer.instance.render(
scene.instance,
camera.instance
);
} else if (renderer.renderMode === GameLib.D3.API.Renderer.MODE_EDIT) {
if (camera instanceof GameLib.D3.Camera.Stereo) {
var size = renderer.instance.getSize();
scene.instance.updateMatrixWorld();
camera.instance.updateMatrixWorld();
camera.instance.update(camera.main.instance);
renderer.instance.clear();
renderer.instance.setScissorTest(true);
renderer.instance.setScissor(0, 0, size.width / 2, size.height);
renderer.instance.setViewport(0, 0, size.width / 2, size.height);
renderer.instance.render(scene.instance, camera.instance.cameraL);
renderer.instance.setScissor(size.width / 2, 0, size.width / 2, size.height);
renderer.instance.setViewport(size.width / 2, 0, size.width / 2, size.height);
renderer.instance.render(scene.instance, camera.instance.cameraR);
renderer.instance.setScissorTest(false);
} else {
renderer.instance.render(
scene.instance,
camera.instance
)
}
} else {
console.warn('unknown render mode:' + renderer.renderMode);
}
}
}.bind(this)
);
}
}.bind(this)
)
}
}.bind(this)
);
GameLib.Event.Emit(
@ -401,6 +486,8 @@ GameLib.System.Render.prototype.stop = function() {
this.renderSubscription.remove();
// this.delayedInstanceEncounteredSubscription.remove();
// window.removeEventListener(
// 'resize',
// this.nativeWindowResize,
@ -424,7 +511,14 @@ GameLib.System.Render.prototype.stop = function() {
}
);
this.renderConfigurations = [];
this.renderers = [];
this.composers = [];
this.statistics = [];
this.cubeCameras = [];
};