renderer update
parent
9ee7b26c1e
commit
5fa8e6583d
|
@ -97,7 +97,7 @@ GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED = 0x4f;
|
||||||
GameLib.Event.CAST_SOURCE_CHANGED = 0x50;
|
GameLib.Event.CAST_SOURCE_CHANGED = 0x50;
|
||||||
GameLib.Event.ANIMATION_MESH_ADDED = 0x51;
|
GameLib.Event.ANIMATION_MESH_ADDED = 0x51;
|
||||||
GameLib.Event.ANIMATION_MESH_REMOVED = 0x52;
|
GameLib.Event.ANIMATION_MESH_REMOVED = 0x52;
|
||||||
GameLib.Event.GET_SCENE = 0x53;
|
// GameLib.Event.GET_SCENE = 0x53;
|
||||||
GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE = 0x54;
|
GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE = 0x54;
|
||||||
GameLib.Event.LOAD_FONT = 0x55;
|
GameLib.Event.LOAD_FONT = 0x55;
|
||||||
GameLib.Event.FONT_NOT_FOUND = 0x56;
|
GameLib.Event.FONT_NOT_FOUND = 0x56;
|
||||||
|
@ -215,7 +215,7 @@ GameLib.Event.GetEventName = function(number) {
|
||||||
case 0x50 : return 'cast_source_changed';
|
case 0x50 : return 'cast_source_changed';
|
||||||
case 0x51 : return 'animation_mesh_added';
|
case 0x51 : return 'animation_mesh_added';
|
||||||
case 0x52 : return 'animation_mesh_removed';
|
case 0x52 : return 'animation_mesh_removed';
|
||||||
case 0x53 : return 'get_scene';
|
case 0x53 : return 'unused';//return 'get_scene';
|
||||||
case 0x54 : return 'custom_code_window_resize';
|
case 0x54 : return 'custom_code_window_resize';
|
||||||
case 0x55 : return 'load_font';
|
case 0x55 : return 'load_font';
|
||||||
case 0x56 : return 'font_not_found';
|
case 0x56 : return 'font_not_found';
|
||||||
|
|
|
@ -213,7 +213,7 @@ GameLib.Component.SOCKET = 0x6;
|
||||||
GameLib.Component.MESH = 0x7;
|
GameLib.Component.MESH = 0x7;
|
||||||
GameLib.Component.SPLINE = 0x8;
|
GameLib.Component.SPLINE = 0x8;
|
||||||
GameLib.Component.LIGHT = 0x9;
|
GameLib.Component.LIGHT = 0x9;
|
||||||
//GameLib.Component.INPUT_DRIVE = 0xa;
|
GameLib.Component.PLANE = 0xa;
|
||||||
GameLib.Component.COMPOSER = 0xb;
|
GameLib.Component.COMPOSER = 0xb;
|
||||||
GameLib.Component.RENDER_TARGET = 0xc;
|
GameLib.Component.RENDER_TARGET = 0xc;
|
||||||
GameLib.Component.PASS = 0xd;
|
GameLib.Component.PASS = 0xd;
|
||||||
|
@ -364,7 +364,12 @@ GameLib.Component.GetComponentInfo = function(number) {
|
||||||
constructor : GameLib.D3.Light,
|
constructor : GameLib.D3.Light,
|
||||||
apiConstructor : GameLib.D3.API.Light
|
apiConstructor : GameLib.D3.API.Light
|
||||||
};
|
};
|
||||||
case 0xa : return null;
|
case 0xa : return {
|
||||||
|
name : 'GameLib.Plane',
|
||||||
|
runtime : GameLib.Component.GRAPHICS_RUNTIME,
|
||||||
|
constructor : GameLib.Plane,
|
||||||
|
apiConstructor : GameLib.API.Plane
|
||||||
|
};
|
||||||
case 0xb : return {
|
case 0xb : return {
|
||||||
name : 'GameLib.D3.Composer',
|
name : 'GameLib.D3.Composer',
|
||||||
runtime : GameLib.Component.GRAPHICS_RUNTIME,
|
runtime : GameLib.Component.GRAPHICS_RUNTIME,
|
||||||
|
|
|
@ -4,16 +4,12 @@
|
||||||
* @param id
|
* @param id
|
||||||
* @param name
|
* @param name
|
||||||
* @param entities GameLib.API.Entity[]
|
* @param entities GameLib.API.Entity[]
|
||||||
* @param defaultEntity
|
|
||||||
* @param defaultRenderer
|
|
||||||
* @param parentEntity
|
* @param parentEntity
|
||||||
*/
|
*/
|
||||||
GameLib.API.EntityManager = function(
|
GameLib.API.EntityManager = function(
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
entities,
|
entities,
|
||||||
defaultEntity,
|
|
||||||
defaultRenderer,
|
|
||||||
parentEntity
|
parentEntity
|
||||||
) {
|
) {
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
@ -31,16 +27,6 @@ GameLib.API.EntityManager = function(
|
||||||
}
|
}
|
||||||
this.entities = entities;
|
this.entities = entities;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(defaultEntity)) {
|
|
||||||
defaultEntity = null;
|
|
||||||
}
|
|
||||||
this.defaultEntity = defaultEntity;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(defaultRenderer)) {
|
|
||||||
defaultRenderer = null;
|
|
||||||
}
|
|
||||||
this.defaultRenderer = defaultRenderer;
|
|
||||||
|
|
||||||
GameLib.API.Component.call(
|
GameLib.API.Component.call(
|
||||||
this,
|
this,
|
||||||
GameLib.Component.ENTITY_MANAGER,
|
GameLib.Component.ENTITY_MANAGER,
|
||||||
|
@ -68,8 +54,6 @@ GameLib.API.EntityManager.FromObject = function(objectEntityManager) {
|
||||||
objectEntityManager.id,
|
objectEntityManager.id,
|
||||||
objectEntityManager.name,
|
objectEntityManager.name,
|
||||||
apiEntities,
|
apiEntities,
|
||||||
objectEntityManager.defaultEntity,
|
|
||||||
objectEntityManager.defaultRenderer,
|
|
||||||
objectEntityManager.parentEntity
|
objectEntityManager.parentEntity
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
* @param id
|
* @param id
|
||||||
* @param name
|
* @param name
|
||||||
* @param components GameLib.Component[]
|
* @param components GameLib.Component[]
|
||||||
* @param renderer
|
|
||||||
* @param parentEntity GameLib.Entity
|
* @param parentEntity GameLib.Entity
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
|
@ -11,7 +10,6 @@ GameLib.API.Entity = function(
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
components,
|
components,
|
||||||
renderer,
|
|
||||||
parentEntity
|
parentEntity
|
||||||
) {
|
) {
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
@ -29,11 +27,6 @@ GameLib.API.Entity = function(
|
||||||
}
|
}
|
||||||
this.components = components;
|
this.components = components;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(renderer)) {
|
|
||||||
renderer = null;
|
|
||||||
}
|
|
||||||
this.renderer = renderer;
|
|
||||||
|
|
||||||
GameLib.API.Component.call(
|
GameLib.API.Component.call(
|
||||||
this,
|
this,
|
||||||
GameLib.Component.ENTITY,
|
GameLib.Component.ENTITY,
|
||||||
|
@ -54,7 +47,6 @@ GameLib.API.Entity.FromObject = function(objectEntity) {
|
||||||
objectEntity.id,
|
objectEntity.id,
|
||||||
objectEntity.name,
|
objectEntity.name,
|
||||||
objectEntity.components,
|
objectEntity.components,
|
||||||
objectEntity.renderer,
|
|
||||||
objectEntity.parentEntity
|
objectEntity.parentEntity
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
GameLib.API.Plane = function (
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
normal,
|
||||||
|
constant,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = 'Plane (' + this.id + ')';
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(normal)) {
|
||||||
|
normal = new GameLib.API.Vector3(1,0,0);
|
||||||
|
}
|
||||||
|
this.normal = normal;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(constant)) {
|
||||||
|
constant = 0;
|
||||||
|
}
|
||||||
|
this.constant = constant;
|
||||||
|
|
||||||
|
GameLib.API.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.PLANE,
|
||||||
|
parentEntity
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
GameLib.API.Plane.prototype = Object.create(GameLib.API.Component.prototype);
|
||||||
|
GameLib.API.Plane.prototype.constructor = GameLib.API.Plane;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an API vector from an Object vector
|
||||||
|
* @param objectPlane
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.API.Plane.FromObject = function (objectPlane) {
|
||||||
|
return new GameLib.API.Plane(
|
||||||
|
objectPlane.id,
|
||||||
|
objectPlane.name,
|
||||||
|
GameLib.API.Vector3.FromObject(objectPlane.normal),
|
||||||
|
objectPlane.constant,
|
||||||
|
objectPlane.parentEntity
|
||||||
|
);
|
||||||
|
};
|
|
@ -1,45 +1,91 @@
|
||||||
/**
|
/**
|
||||||
* This component renders a scene
|
* Renderer Data
|
||||||
* @param id String
|
* @param id
|
||||||
* @param name String
|
* @param name
|
||||||
* @param autoClear bool
|
|
||||||
* @param localClipping
|
|
||||||
* @param width
|
* @param width
|
||||||
* @param height
|
* @param height
|
||||||
* @param domElement
|
* @param renderMode
|
||||||
|
* @param autoClear
|
||||||
|
* @param autoClearColor
|
||||||
|
* @param autoClearDepth
|
||||||
|
* @param autoClearStencil
|
||||||
|
* @param gammaFactor
|
||||||
|
* @param gammaInput
|
||||||
|
* @param gammaOutput
|
||||||
|
* @param maxMorphTargets
|
||||||
|
* @param maxMorphNormals
|
||||||
|
* @param physicallyCorrectLights
|
||||||
|
* @param shadowMapEnabled
|
||||||
|
* @param shadowMapAutoUpdate
|
||||||
|
* @param shadowMapNeedsUpdate
|
||||||
|
* @param shadowMapType
|
||||||
|
* @param shadowMapRenderReverseSided
|
||||||
|
* @param shadowMapRenderSingleSided
|
||||||
|
* @param sortObjects
|
||||||
|
* @param toneMapping
|
||||||
|
* @param toneMappingExposure
|
||||||
|
* @param toneMappingWhitePoint
|
||||||
|
* @param premultipliedAlpha
|
||||||
|
* @param antialias
|
||||||
|
* @param stencil
|
||||||
|
* @param preserveDrawingBuffer
|
||||||
|
* @param depth
|
||||||
|
* @param logarithmicDepthBuffer
|
||||||
|
* @param fullscreen
|
||||||
|
* @param canvas
|
||||||
|
* @param renderTarget
|
||||||
|
* @param localClippingEnabled
|
||||||
|
* @param clippingPlanes
|
||||||
* @param clearColor
|
* @param clearColor
|
||||||
* @param camera
|
* @param camera
|
||||||
* @param scenes
|
* @param scenes
|
||||||
|
* @param defaultScene
|
||||||
* @param viewports
|
* @param viewports
|
||||||
* @param parentEntity
|
* @param parentEntity
|
||||||
* @param preserveDrawingBuffer
|
|
||||||
* @param clippingPlanes
|
|
||||||
* @param bufferScene
|
|
||||||
* @param bufferCamera
|
|
||||||
* @param renderTarget
|
|
||||||
* @param sortObjects
|
|
||||||
* @param defaultScene
|
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.API.Renderer = function (
|
GameLib.D3.API.Renderer = function (
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
autoClear,
|
|
||||||
localClipping,
|
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
|
renderMode,
|
||||||
|
autoClear,
|
||||||
|
autoClearColor,
|
||||||
|
autoClearDepth,
|
||||||
|
autoClearStencil,
|
||||||
|
gammaFactor,
|
||||||
|
gammaInput,
|
||||||
|
gammaOutput,
|
||||||
|
maxMorphTargets,
|
||||||
|
maxMorphNormals,
|
||||||
|
physicallyCorrectLights,
|
||||||
|
shadowMapEnabled,
|
||||||
|
shadowMapAutoUpdate,
|
||||||
|
shadowMapNeedsUpdate,
|
||||||
|
shadowMapType,
|
||||||
|
shadowMapRenderReverseSided,
|
||||||
|
shadowMapRenderSingleSided,
|
||||||
|
sortObjects,
|
||||||
|
toneMapping,
|
||||||
|
toneMappingExposure,
|
||||||
|
toneMappingWhitePoint,
|
||||||
|
premultipliedAlpha,
|
||||||
|
antialias,
|
||||||
|
stencil,
|
||||||
preserveDrawingBuffer,
|
preserveDrawingBuffer,
|
||||||
domElement,
|
depth,
|
||||||
|
logarithmicDepthBuffer,
|
||||||
|
localClippingEnabled,
|
||||||
|
fullscreen,
|
||||||
|
canvas,
|
||||||
|
renderTarget,
|
||||||
|
clippingPlanes,
|
||||||
clearColor,
|
clearColor,
|
||||||
camera,
|
camera,
|
||||||
scenes,
|
scenes,
|
||||||
viewports,
|
|
||||||
clippingPlanes,
|
|
||||||
bufferScene,
|
|
||||||
bufferCamera,
|
|
||||||
renderTarget,
|
|
||||||
defaultScene,
|
defaultScene,
|
||||||
sortObjects,
|
viewports,
|
||||||
parentEntity
|
parentEntity
|
||||||
) {
|
) {
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
@ -52,39 +98,180 @@ GameLib.D3.API.Renderer = function (
|
||||||
}
|
}
|
||||||
this.name = name;
|
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(renderMode)) {
|
||||||
|
renderMode = GameLib.D3.API.Renderer.MODE_CANVAS;
|
||||||
|
}
|
||||||
|
this.renderMode = renderMode;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(autoClear)) {
|
if (GameLib.Utils.UndefinedOrNull(autoClear)) {
|
||||||
autoClear = true;
|
autoClear = true;
|
||||||
}
|
}
|
||||||
this.autoClear = autoClear;
|
this.autoClear = autoClear;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(localClipping)) {
|
if (GameLib.Utils.UndefinedOrNull(autoClearColor)) {
|
||||||
localClipping = false;
|
autoClearColor = true;
|
||||||
|
}
|
||||||
|
this.autoClearColor = autoClearColor;
|
||||||
|
|
||||||
if (clippingPlanes && clippingPlanes.length > 0) {
|
if (GameLib.Utils.UndefinedOrNull(autoClearDepth)) {
|
||||||
localClipping = true;
|
autoClearDepth = true;
|
||||||
}
|
}
|
||||||
}
|
this.autoClearDepth = autoClearDepth;
|
||||||
this.localClipping = localClipping;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(width)) {
|
if (GameLib.Utils.UndefinedOrNull(autoClearStencil)) {
|
||||||
width = 800;
|
autoClearStencil = true;
|
||||||
}
|
}
|
||||||
this.width = width;
|
this.autoClearStencil = autoClearStencil;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(height)) {
|
if (GameLib.Utils.UndefinedOrNull(gammaFactor)) {
|
||||||
height = 600;
|
gammaFactor = 2;
|
||||||
}
|
}
|
||||||
this.height = height;
|
this.gammaFactor = gammaFactor;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(gammaInput)) {
|
||||||
|
gammaInput = false;
|
||||||
|
}
|
||||||
|
this.gammaInput = gammaInput;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(gammaOutput)) {
|
||||||
|
gammaOutput = false;
|
||||||
|
}
|
||||||
|
this.gammaOutput = gammaOutput;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(maxMorphTargets)) {
|
||||||
|
maxMorphTargets = 8;
|
||||||
|
}
|
||||||
|
this.maxMorphTargets = maxMorphTargets;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(maxMorphNormals)) {
|
||||||
|
maxMorphNormals = 4;
|
||||||
|
}
|
||||||
|
this.maxMorphNormals = maxMorphNormals;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(physicallyCorrectLights)) {
|
||||||
|
physicallyCorrectLights = false;
|
||||||
|
}
|
||||||
|
this.physicallyCorrectLights = physicallyCorrectLights;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(shadowMapEnabled)) {
|
||||||
|
shadowMapEnabled = false;
|
||||||
|
}
|
||||||
|
this.shadowMapEnabled = shadowMapEnabled;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(shadowMapAutoUpdate)) {
|
||||||
|
shadowMapAutoUpdate = true;
|
||||||
|
}
|
||||||
|
this.shadowMapAutoUpdate = shadowMapAutoUpdate;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(shadowMapNeedsUpdate)) {
|
||||||
|
shadowMapNeedsUpdate = false;
|
||||||
|
}
|
||||||
|
this.shadowMapNeedsUpdate = shadowMapNeedsUpdate;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(shadowMapType)) {
|
||||||
|
shadowMapType = GameLib.D3.API.Renderer.SHADOW_MAP_TYPE_BASIC;
|
||||||
|
}
|
||||||
|
this.shadowMapType = shadowMapType;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(shadowMapRenderReverseSided)) {
|
||||||
|
shadowMapRenderReverseSided = true;
|
||||||
|
}
|
||||||
|
this.shadowMapRenderReverseSided = shadowMapRenderReverseSided;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(shadowMapRenderSingleSided)) {
|
||||||
|
shadowMapRenderSingleSided = true;
|
||||||
|
}
|
||||||
|
this.shadowMapRenderSingleSided = shadowMapRenderSingleSided;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(sortObjects)) {
|
||||||
|
sortObjects = true;
|
||||||
|
}
|
||||||
|
this.sortObjects = sortObjects;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(toneMapping)) {
|
||||||
|
toneMapping = GameLib.D3.API.Renderer.TONE_MAPPING_LINEAR;
|
||||||
|
}
|
||||||
|
this.toneMapping = toneMapping;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(toneMappingExposure)) {
|
||||||
|
toneMappingExposure = 1;
|
||||||
|
}
|
||||||
|
this.toneMappingExposure = toneMappingExposure;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(toneMappingWhitePoint)) {
|
||||||
|
toneMappingWhitePoint = 1;
|
||||||
|
}
|
||||||
|
this.toneMappingWhitePoint = toneMappingWhitePoint;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(premultipliedAlpha)) {
|
||||||
|
premultipliedAlpha = true;
|
||||||
|
}
|
||||||
|
this.premultipliedAlpha = premultipliedAlpha;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(antialias)) {
|
||||||
|
antialias = false;
|
||||||
|
}
|
||||||
|
this.antialias = antialias;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(stencil)) {
|
||||||
|
stencil = true;
|
||||||
|
}
|
||||||
|
this.stencil = stencil;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(preserveDrawingBuffer)) {
|
if (GameLib.Utils.UndefinedOrNull(preserveDrawingBuffer)) {
|
||||||
preserveDrawingBuffer = false;
|
preserveDrawingBuffer = false;
|
||||||
}
|
}
|
||||||
this.preserveDrawingBuffer = preserveDrawingBuffer;
|
this.preserveDrawingBuffer = preserveDrawingBuffer;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(domElement)) {
|
if (GameLib.Utils.UndefinedOrNull(depth)) {
|
||||||
domElement = null;
|
depth = true;
|
||||||
}
|
}
|
||||||
this.domElement = domElement;
|
this.depth = depth;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(logarithmicDepthBuffer)) {
|
||||||
|
logarithmicDepthBuffer = false;
|
||||||
|
}
|
||||||
|
this.logarithmicDepthBuffer = logarithmicDepthBuffer;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(localClippingEnabled)) {
|
||||||
|
localClippingEnabled = false;
|
||||||
|
}
|
||||||
|
this.localClippingEnabled = localClippingEnabled;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(fullscreen)) {
|
||||||
|
fullscreen = true;
|
||||||
|
}
|
||||||
|
this.fullscreen = fullscreen;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(canvas)) {
|
||||||
|
canvas = new GameLib.API.Canvas(
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
this.width,
|
||||||
|
this.height
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.canvas = canvas;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(renderTarget)) {
|
||||||
|
renderTarget = null;
|
||||||
|
}
|
||||||
|
this.renderTarget = renderTarget;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(clippingPlanes)) {
|
||||||
|
clippingPlanes = [];
|
||||||
|
}
|
||||||
|
this.clippingPlanes = clippingPlanes;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(clearColor)) {
|
if (GameLib.Utils.UndefinedOrNull(clearColor)) {
|
||||||
clearColor = new GameLib.API.Color(0.11, 0.11, 0.11);
|
clearColor = new GameLib.API.Color(0.11, 0.11, 0.11);
|
||||||
|
@ -92,49 +279,37 @@ GameLib.D3.API.Renderer = function (
|
||||||
this.clearColor = clearColor;
|
this.clearColor = clearColor;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
||||||
camera = null;
|
camera = new GameLib.D3.API.Camera(
|
||||||
|
null,
|
||||||
|
GameLib.D3.API.Camera.PERSPECTIVE_CAMERA,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
this.width / this.height
|
||||||
|
);
|
||||||
}
|
}
|
||||||
this.camera = camera;
|
this.camera = camera;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(scenes)) {
|
if (GameLib.Utils.UndefinedOrNull(scenes)) {
|
||||||
scenes = [];
|
scenes = [new GameLib.D3.API.Scene()];
|
||||||
}
|
}
|
||||||
this.scenes = scenes;
|
this.scenes = scenes;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(viewports)) {
|
|
||||||
viewports = [];
|
|
||||||
}
|
|
||||||
this.viewports = viewports;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(clippingPlanes)) {
|
|
||||||
clippingPlanes = [];
|
|
||||||
}
|
|
||||||
this.clippingPlanes = clippingPlanes;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(bufferScene)) {
|
|
||||||
bufferScene = null;
|
|
||||||
}
|
|
||||||
this.bufferScene = bufferScene;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(bufferCamera)) {
|
|
||||||
bufferCamera = camera;
|
|
||||||
}
|
|
||||||
this.bufferCamera = bufferCamera;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(renderTarget)) {
|
|
||||||
renderTarget = null;
|
|
||||||
}
|
|
||||||
this.renderTarget = renderTarget;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(defaultScene)) {
|
if (GameLib.Utils.UndefinedOrNull(defaultScene)) {
|
||||||
defaultScene = null;
|
defaultScene = this.scenes[0];
|
||||||
}
|
}
|
||||||
this.defaultScene = defaultScene;
|
this.defaultScene = defaultScene;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(sortObjects)) {
|
if (GameLib.Utils.UndefinedOrNull(viewports)) {
|
||||||
sortObjects = true;
|
viewports = [new GameLib.D3.API.Viewport(
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
)];
|
||||||
}
|
}
|
||||||
this.sortObjects = sortObjects;
|
this.viewports = viewports;
|
||||||
|
|
||||||
GameLib.API.Component.call(
|
GameLib.API.Component.call(
|
||||||
this,
|
this,
|
||||||
|
@ -147,31 +322,68 @@ GameLib.D3.API.Renderer = function (
|
||||||
GameLib.D3.API.Renderer.prototype = Object.create(GameLib.API.Component.prototype);
|
GameLib.D3.API.Renderer.prototype = Object.create(GameLib.API.Component.prototype);
|
||||||
GameLib.D3.API.Renderer.prototype.constructor = GameLib.D3.API.Renderer;
|
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.SHADOW_MAP_TYPE_BASIC = 0;
|
||||||
|
GameLib.D3.API.Renderer.SHADOW_MAP_TYPE_PCF = 1;
|
||||||
|
GameLib.D3.API.Renderer.SHADOW_MAP_TYPE_PCF_SOFT = 2;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object to GameLib.D3.API.Renderer
|
* Object to GameLib.D3.API.Renderer
|
||||||
* @param objectComponent
|
* @param objectRenderer
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.API.Renderer.FromObject = function(objectComponent) {
|
GameLib.D3.API.Renderer.FromObject = function(objectRenderer) {
|
||||||
return new GameLib.D3.API.Renderer(
|
return new GameLib.D3.API.Renderer(
|
||||||
objectComponent.id,
|
objectRenderer.id,
|
||||||
objectComponent.name,
|
objectRenderer.name,
|
||||||
objectComponent.autoClear,
|
objectRenderer.width,
|
||||||
objectComponent.localClipping,
|
objectRenderer.height,
|
||||||
objectComponent.width,
|
objectRenderer.renderMode,
|
||||||
objectComponent.height,
|
objectRenderer.autoClear,
|
||||||
objectComponent.preserveDrawingBuffer,
|
objectRenderer.autoClearColor,
|
||||||
objectComponent.domElement,
|
objectRenderer.autoClearDepth,
|
||||||
objectComponent.clearColor,
|
objectRenderer.autoClearStencil,
|
||||||
objectComponent.camera,
|
objectRenderer.gammaFactor,
|
||||||
objectComponent.scenes,
|
objectRenderer.gammaInput,
|
||||||
objectComponent.viewports,
|
objectRenderer.gammaOutput,
|
||||||
objectComponent.clippingPlanes,
|
objectRenderer.maxMorphTargets,
|
||||||
objectComponent.bufferScene,
|
objectRenderer.maxMorphNormals,
|
||||||
objectComponent.bufferCamera,
|
objectRenderer.physicallyCorrectLights,
|
||||||
objectComponent.renderTarget,
|
objectRenderer.shadowMapEnabled,
|
||||||
objectComponent.defaultScene,
|
objectRenderer.shadowMapAutoUpdate,
|
||||||
objectComponent.sortObjects,
|
objectRenderer.shadowMapNeedsUpdate,
|
||||||
objectComponent.parentEntity
|
objectRenderer.shadowMapType,
|
||||||
|
objectRenderer.shadowMapRenderReverseSided,
|
||||||
|
objectRenderer.shadowMapRenderSingleSided,
|
||||||
|
objectRenderer.sortObjects,
|
||||||
|
objectRenderer.toneMapping,
|
||||||
|
objectRenderer.toneMappingExposure,
|
||||||
|
objectRenderer.toneMappingWhitePoint,
|
||||||
|
objectRenderer.premultipliedAlpha,
|
||||||
|
objectRenderer.antialias,
|
||||||
|
objectRenderer.stencil,
|
||||||
|
objectRenderer.preserveDrawingBuffer,
|
||||||
|
objectRenderer.depth,
|
||||||
|
objectRenderer.logarithmicDepthBuffer,
|
||||||
|
objectRenderer.localClippingEnabled,
|
||||||
|
objectRenderer.fullscreen,
|
||||||
|
objectRenderer.canvas,
|
||||||
|
objectRenderer.renderTarget,
|
||||||
|
objectRenderer.clippingPlanes,
|
||||||
|
GameLib.API.Color.FromObject(objectRenderer.clearColor),
|
||||||
|
objectRenderer.camera,
|
||||||
|
objectRenderer.scenes,
|
||||||
|
objectRenderer.defaultScene,
|
||||||
|
objectRenderer.viewports,
|
||||||
|
objectRenderer.parentEntity
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -49,7 +49,7 @@ GameLib.D3.API.Scene = function(
|
||||||
this.meshes = meshes;
|
this.meshes = meshes;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(lights)) {
|
if (GameLib.Utils.UndefinedOrNull(lights)) {
|
||||||
lights = [];
|
lights = [new GameLib.D3.API.Light()];
|
||||||
}
|
}
|
||||||
this.lights = lights;
|
this.lights = lights;
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,12 @@ GameLib.D3.API.Viewport = function(
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(width)) {
|
if (GameLib.Utils.UndefinedOrNull(width)) {
|
||||||
width = 800;
|
width = 1;
|
||||||
}
|
}
|
||||||
this.width = width;
|
this.width = width;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(height)) {
|
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||||
height = 600;
|
height = 1;
|
||||||
}
|
}
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
|
||||||
|
|
|
@ -20,44 +20,78 @@ GameLib.D3.Renderer = function (
|
||||||
this,
|
this,
|
||||||
apiRenderer.id,
|
apiRenderer.id,
|
||||||
apiRenderer.name,
|
apiRenderer.name,
|
||||||
apiRenderer.autoClear,
|
|
||||||
apiRenderer.localClipping,
|
|
||||||
apiRenderer.width,
|
apiRenderer.width,
|
||||||
apiRenderer.height,
|
apiRenderer.height,
|
||||||
|
apiRenderer.renderMode,
|
||||||
|
apiRenderer.autoClear,
|
||||||
|
apiRenderer.autoClearColor,
|
||||||
|
apiRenderer.autoClearDepth,
|
||||||
|
apiRenderer.autoClearStencil,
|
||||||
|
apiRenderer.gammaFactor,
|
||||||
|
apiRenderer.gammaInput,
|
||||||
|
apiRenderer.gammaOutput,
|
||||||
|
apiRenderer.maxMorphTargets,
|
||||||
|
apiRenderer.maxMorphNormals,
|
||||||
|
apiRenderer.physicallyCorrectLights,
|
||||||
|
apiRenderer.shadowMapEnabled,
|
||||||
|
apiRenderer.shadowMapAutoUpdate,
|
||||||
|
apiRenderer.shadowMapNeedsUpdate,
|
||||||
|
apiRenderer.shadowMapType,
|
||||||
|
apiRenderer.shadowMapRenderReverseSided,
|
||||||
|
apiRenderer.shadowMapRenderSingleSided,
|
||||||
|
apiRenderer.sortObjects,
|
||||||
|
apiRenderer.toneMapping,
|
||||||
|
apiRenderer.toneMappingExposure,
|
||||||
|
apiRenderer.toneMappingWhitePoint,
|
||||||
|
apiRenderer.premultipliedAlpha,
|
||||||
|
apiRenderer.antialias,
|
||||||
|
apiRenderer.stencil,
|
||||||
apiRenderer.preserveDrawingBuffer,
|
apiRenderer.preserveDrawingBuffer,
|
||||||
|
apiRenderer.depth,
|
||||||
|
apiRenderer.logarithmicDepthBuffer,
|
||||||
|
apiRenderer.localClippingEnabled,
|
||||||
|
apiRenderer.fullscreen,
|
||||||
apiRenderer.canvas,
|
apiRenderer.canvas,
|
||||||
|
apiRenderer.renderTarget,
|
||||||
|
apiRenderer.clippingPlanes,
|
||||||
apiRenderer.clearColor,
|
apiRenderer.clearColor,
|
||||||
apiRenderer.camera,
|
apiRenderer.camera,
|
||||||
apiRenderer.scenes,
|
apiRenderer.scenes,
|
||||||
apiRenderer.viewports,
|
|
||||||
apiRenderer.clippingPlanes,
|
|
||||||
apiRenderer.bufferScene,
|
|
||||||
apiRenderer.bufferCamera,
|
|
||||||
apiRenderer.renderTarget,
|
|
||||||
apiRenderer.defaultScene,
|
apiRenderer.defaultScene,
|
||||||
apiRenderer.sortObjects,
|
apiRenderer.viewports,
|
||||||
apiRenderer.parentEntity
|
apiRenderer.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (this.canvas instanceof GameLib.API.Canvas) {
|
||||||
|
this.canvas = new GameLib.Canvas(
|
||||||
|
this.canvas
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.renderTarget instanceof GameLib.D3.API.RenderTarget) {
|
||||||
|
this.renderTarget = new GameLib.D3.RenderTarget(
|
||||||
|
this.graphics,
|
||||||
|
this.renderTarget
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.clippingPlanes = this.clippingPlanes.map(function(clippingPlane){
|
||||||
|
if (clippingPlane instanceof GameLib.API.Plane) {
|
||||||
|
return new GameLib.Plane(
|
||||||
|
this.graphics,
|
||||||
|
clippingPlane
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return clippingPlane;
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
this.clearColor = new GameLib.Color(
|
this.clearColor = new GameLib.Color(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this.clearColor,
|
this.clearColor,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this.canvas) {
|
|
||||||
this.width = this.canvas.width;
|
|
||||||
this.height = this.canvas.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (this.canvas instanceof GameLib.API.Canvas) {
|
|
||||||
this.canvas = new GameLib.Canvas(
|
|
||||||
this.canvas
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (this.camera instanceof GameLib.D3.API.Camera) {
|
if (this.camera instanceof GameLib.D3.API.Camera) {
|
||||||
this.camera = new GameLib.D3.Camera(
|
this.camera = new GameLib.D3.Camera(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
|
@ -67,10 +101,17 @@ if (this.canvas instanceof GameLib.API.Canvas) {
|
||||||
|
|
||||||
this.scenes = this.scenes.map(function(scene){
|
this.scenes = this.scenes.map(function(scene){
|
||||||
if (scene instanceof GameLib.D3.API.Scene) {
|
if (scene instanceof GameLib.D3.API.Scene) {
|
||||||
return new GameLib.D3.Scene(
|
|
||||||
|
var runtimeScene = new GameLib.D3.Scene(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
scene
|
scene
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (scene === this.defaultScene) {
|
||||||
|
this.defaultScene = runtimeScene;
|
||||||
|
}
|
||||||
|
|
||||||
|
return runtimeScene;
|
||||||
} else {
|
} else {
|
||||||
return scene;
|
return scene;
|
||||||
}
|
}
|
||||||
|
@ -87,58 +128,16 @@ if (this.canvas instanceof GameLib.API.Canvas) {
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.clippingPlanes = this.clippingPlanes.map(function(clippingPlane){
|
|
||||||
if (clippingPlane instanceof GameLib.D3.API.Mesh) {
|
|
||||||
return new GameLib.D3.Mesh.Plane(
|
|
||||||
this.graphics,
|
|
||||||
clippingPlane,
|
|
||||||
clippingPlane.width,
|
|
||||||
clippingPlane.height,
|
|
||||||
clippingPlane.widthSegments,
|
|
||||||
clippingPlane.heightSegments,
|
|
||||||
clippingPlane.heightMapScale,
|
|
||||||
clippingPlane.isHeightMap,
|
|
||||||
clippingPlane.isClippingPlane,
|
|
||||||
clippingPlane.distanceFromOrigin
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return clippingPlane;
|
|
||||||
}
|
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
if (this.bufferScene instanceof GameLib.D3.API.Scene) {
|
|
||||||
this.bufferScene = new GameLib.D3.Scene(
|
|
||||||
this.graphics,
|
|
||||||
this.bufferScene
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.bufferCamera instanceof GameLib.D3.API.Camera) {
|
|
||||||
this.bufferCamera = new GameLib.D3.Camera(
|
|
||||||
this.graphics,
|
|
||||||
this.bufferCamera
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.renderTarget instanceof GameLib.D3.API.RenderTarget) {
|
|
||||||
this.renderTarget = new GameLib.D3.RenderTarget(
|
|
||||||
this.graphics,
|
|
||||||
this.renderTarget
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
this,
|
this,
|
||||||
{
|
{
|
||||||
'canvas' : GameLib.Canvas,
|
'canvas' : GameLib.Canvas,
|
||||||
|
'renderTarget' : GameLib.D3.RenderTarget,
|
||||||
|
'clippingPlanes': [GameLib.Plane],
|
||||||
'camera' : GameLib.D3.Camera,
|
'camera' : GameLib.D3.Camera,
|
||||||
'scenes' : [GameLib.D3.Scene],
|
'scenes' : [GameLib.D3.Scene],
|
||||||
'viewports' : [GameLib.D3.Viewport],
|
'defaultScene' : GameLib.D3.Scene,
|
||||||
'clippingPlanes': [GameLib.D3.Mesh.Plane],
|
'viewports' : [GameLib.D3.Viewport]
|
||||||
'bufferScene' : GameLib.D3.Scene,
|
|
||||||
'bufferCamera' : GameLib.D3.Camera,
|
|
||||||
'renderTarget' : GameLib.D3.RenderTarget,
|
|
||||||
'defaultScene' : GameLib.D3.Scene
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -163,30 +162,65 @@ GameLib.D3.Renderer.prototype.createInstance = function() {
|
||||||
|
|
||||||
this.instance = new THREE.WebGLRenderer(
|
this.instance = new THREE.WebGLRenderer(
|
||||||
{
|
{
|
||||||
canvas : this.canvas.instance
|
canvas : this.canvas.instance,
|
||||||
|
alpha : this.alpha,
|
||||||
|
premultipliedAlpha : this.premultipliedAlpha,
|
||||||
|
antialias : this.antialias,
|
||||||
|
stencil : this.stencil,
|
||||||
|
preserveDrawingBuffer : this.preserveDrawingBuffer,
|
||||||
|
depth : this.depth,
|
||||||
|
logarithmicDepthBuffer : this.logarithmicDepthBuffer
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this.clippingPlanes.length > 0) {
|
|
||||||
this.instance.clippingPlanes = this.clippingPlanes.map(
|
|
||||||
function(clippingPlane) {
|
|
||||||
|
|
||||||
if (!clippingPlane.isClippingPlane || !clippingPlane.instance || !clippingPlane.instance.clipping) {
|
|
||||||
throw new Error('is not a clipping plane or no clipping plane instance');
|
|
||||||
}
|
|
||||||
|
|
||||||
return clippingPlane.instance.clipping;
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.instance.localClippingEnabled = this.localClipping;
|
|
||||||
|
|
||||||
this.instance.setSize(
|
this.instance.setSize(
|
||||||
this.width,
|
this.width,
|
||||||
this.height
|
this.height
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.instance.autoClear = this.autoClear;
|
||||||
|
this.instance.autoClearColor = this.autoClearColor;
|
||||||
|
this.instance.autoClearDepth = this.autoClearDepth;
|
||||||
|
this.instance.autoClearStencil = this.autoClearStencil;
|
||||||
|
|
||||||
|
this.instance.gammaFactor = this.gammaFactor;
|
||||||
|
this.instance.gammaInput = this.gammaInput;
|
||||||
|
this.instance.gammaOutput = this.gammaOutput;
|
||||||
|
|
||||||
|
this.instance.maxMorphTargets = this.maxMorphTargets;
|
||||||
|
this.instance.maxMorphNormals = this.maxMorphNormals;
|
||||||
|
|
||||||
|
this.instance.physicallyCorrectLights = this.physicallyCorrectLights;
|
||||||
|
|
||||||
|
this.instance.shadowMap.enabled = this.shadowMapEnabled;
|
||||||
|
this.instance.shadowMap.autoUpdate = this.shadowMapAutoUpdate;
|
||||||
|
this.instance.shadowMap.needsUpdate = this.shadowMapNeedsUpdate;
|
||||||
|
this.instance.shadowMap.type = this.shadowMapType;
|
||||||
|
this.instance.shadowMap.renderReverseSided = this.shadowMapRenderReverseSided;
|
||||||
|
this.instance.shadowMap.renderSingleSided = this.shadowMapRenderSingleSided;
|
||||||
|
|
||||||
|
this.instance.sortObjects = this.sortObjects;
|
||||||
|
|
||||||
|
this.instance.toneMapping = this.toneMapping;
|
||||||
|
this.instance.toneMappingExposure = this.toneMappingExposure;
|
||||||
|
this.instance.toneMappingWhitePoint = this.toneMappingWhitePoint;
|
||||||
|
|
||||||
|
this.instance.premultipliedAlpha = this.premultipliedAlpha;
|
||||||
|
|
||||||
|
this.instance.localClippingEnabled = this.localClippingEnabled;
|
||||||
|
|
||||||
|
if (this.renderTarget) {
|
||||||
|
this.instance.setRenderTarget(this.renderTarget.instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.clippingPlanes.length > 0) {
|
||||||
|
this.instance.clippingPlanes = this.clippingPlanes.map(
|
||||||
|
function(clippingPlane) {
|
||||||
|
return clippingPlane.instance;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
this.instance.setClearColor(
|
this.instance.setClearColor(
|
||||||
new THREE.Color(
|
new THREE.Color(
|
||||||
this.clearColor.r,
|
this.clearColor.r,
|
||||||
|
@ -196,53 +230,187 @@ GameLib.D3.Renderer.prototype.createInstance = function() {
|
||||||
1 - this.clearColor.a
|
1 - this.clearColor.a
|
||||||
);
|
);
|
||||||
|
|
||||||
this.instance.domElement.width = this.width;
|
|
||||||
this.instance.domElement.height = this.height;
|
|
||||||
|
|
||||||
this.instance.autoClear = this.autoClear;
|
|
||||||
this.instance.preserveDrawingBuffer = this.preserveDrawingBuffer;
|
|
||||||
|
|
||||||
this.instance.sortObjects = this.sortObjects;
|
|
||||||
|
|
||||||
GameLib.Component.prototype.createInstance.call(this);
|
GameLib.Component.prototype.createInstance.call(this);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Update Renderer Instance
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Renderer.prototype.updateInstance = function(property) {
|
GameLib.D3.Renderer.prototype.updateInstance = function(property) {
|
||||||
|
|
||||||
if (!this.instance) {
|
|
||||||
try {
|
|
||||||
this.createInstance();
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error.message);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!property) {
|
if (!property) {
|
||||||
console.error('no property for renderer');
|
throw new Error('no renderer property');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'localClipping') {
|
if (!this.instance) {
|
||||||
this.instance.localClippingEnabled = this.localClipping;
|
throw new Error('no renderer instance');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'canvas') {
|
if (property === 'width') {
|
||||||
this.instance.dispose();
|
|
||||||
this.createInstance();
|
this.width = Math.round(this.width);
|
||||||
|
|
||||||
|
this.canvas.width = this.width;
|
||||||
|
|
||||||
|
this.canvas.updateInstance('width');
|
||||||
|
|
||||||
|
this.instance.setSize(this.width, this.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'width' || 'height') {
|
if (property === 'height') {
|
||||||
|
|
||||||
|
this.height = Math.round(this.height);
|
||||||
|
|
||||||
|
this.canvas.height = this.height;
|
||||||
|
|
||||||
|
this.canvas.updateInstance('height');
|
||||||
|
|
||||||
|
this.instance.setSize(this.width, this.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'widthheight') {
|
||||||
|
|
||||||
this.width = Math.round(this.width);
|
this.width = Math.round(this.width);
|
||||||
this.height = Math.round(this.height);
|
this.height = Math.round(this.height);
|
||||||
|
|
||||||
this.setSize(this.width, this.height);
|
this.canvas.width = this.width;
|
||||||
|
this.canvas.height = this.height;
|
||||||
|
|
||||||
|
this.canvas.updateInstance('width');
|
||||||
|
this.canvas.updateInstance('height');
|
||||||
|
|
||||||
|
this.instance.setSize(this.width, this.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (property === 'renderMode') {
|
||||||
|
console.log('todo: render mode update');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'autoClear') {
|
||||||
|
this.instance.autoClear = this.autoClear;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'autoClearColor') {
|
||||||
|
this.instance.autoClearColor = this.autoClearColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'autoClearDepth') {
|
||||||
|
this.instance.autoClearDepth = this.autoClearDepth;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'autoClearStencil') {
|
||||||
|
this.instance.autoClearStencil = this.autoClearStencil;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'gammaFactor') {
|
||||||
|
this.instance.gammaFactor = this.gammaFactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'gammaInput') {
|
||||||
|
this.instance.gammaInput = this.gammaInput;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'gammaOutput') {
|
||||||
|
this.instance.gammaOutput = this.gammaOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'maxMorphTargets') {
|
||||||
|
this.instance.maxMorphTargets = this.maxMorphTargets;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'maxMorphNormals') {
|
||||||
|
this.instance.maxMorphNormals = this.maxMorphNormals;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'physicallyCorrectLights') {
|
||||||
|
this.instance.physicallyCorrectLights = this.physicallyCorrectLights;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'shadowMapEnabled') {
|
||||||
|
this.instance.shadowMap.enabled = this.shadowMapEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'shadowMapAutoUpdate') {
|
||||||
|
this.instance.shadowMap.autoUpdate = this.shadowMapAutoUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'shadowMapNeedsUpdate') {
|
||||||
|
this.instance.shadowMap.needsUpdate = this.shadowMapNeedsUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'shadowMapType') {
|
||||||
|
this.instance.shadowMap.type = this.shadowMapType;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'shadowMapRenderReverseSided') {
|
||||||
|
this.instance.shadowMap.renderReverseSided = this.shadowMapRenderReverseSided;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'shadowMapRenderSingleSided') {
|
||||||
|
this.instance.shadowMap.renderSingleSided = this.shadowMapRenderSingleSided;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'sortObjects') {
|
||||||
|
this.instance.sortObjects = this.sortObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'toneMapping') {
|
||||||
|
this.instance.toneMapping = this.toneMapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'toneMappingExposure') {
|
||||||
|
this.instance.toneMappingExposure = this.toneMappingExposure;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'toneMappingWhitePoint') {
|
||||||
|
this.instance.toneMappingWhitePoint = this.toneMappingWhitePoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'premultipliedAlpha') {
|
||||||
|
this.instance.premultipliedAlpha = this.premultipliedAlpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'premultipliedAlpha') {
|
||||||
|
this.instance.premultipliedAlpha = this.premultipliedAlpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'antialias') {
|
||||||
|
this.instance.antialias = this.antialias;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'stencil') {
|
||||||
|
this.instance.stencil = this.stencil;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'preserveDrawingBuffer') {
|
||||||
|
this.instance.preserveDrawingBuffer = this.preserveDrawingBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'depth') {
|
||||||
|
this.instance.depth = this.depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'logarithmicDepthBuffer') {
|
||||||
|
this.instance.logarithmicDepthBuffer = this.logarithmicDepthBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'localClippingEnabled') {
|
||||||
|
this.instance.localClippingEnabled = this.localClippingEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'canvas') {
|
||||||
|
console.warn('experimental canvas change for renderer');
|
||||||
|
this.instance.dispose();
|
||||||
|
this.createInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'renderTarget') {
|
||||||
|
console.warn('todo: render target change');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'clippingPlanes') {
|
||||||
|
console.warn('todo: clipping planes change');
|
||||||
|
}
|
||||||
|
|
||||||
if (property === 'clearColor') {
|
if (property === 'clearColor') {
|
||||||
this.instance.setClearColor(
|
this.instance.setClearColor(
|
||||||
|
@ -255,32 +423,24 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (property === 'camera') {
|
||||||
if (property === 'autoClear') {
|
console.warn('todo: camera change');
|
||||||
this.instance.autoClear = this.autoClear;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'preserveDrawingBuffer') {
|
if (property === 'scenes') {
|
||||||
this.instance.preserveDrawingBuffer = this.preserveDrawingBuffer;
|
console.warn('todo: scenes change');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.clippingPlanes.length > 0) {
|
if (property === 'defaultScene') {
|
||||||
this.instance.clippingPlanes = this.clippingPlanes.map(
|
console.warn('todo: defaultScene change');
|
||||||
function(clippingPlane) {
|
|
||||||
|
|
||||||
if (!clippingPlane.isClippingPlane || !clippingPlane.instance || !clippingPlane.instance.clipping) {
|
|
||||||
throw new Error('is not a clipping plane or no clipping plane instance');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return clippingPlane.instance.clipping;
|
if (property === 'viewports') {
|
||||||
}
|
console.warn('todo: viewports change');
|
||||||
)
|
|
||||||
} else {
|
|
||||||
this.instance.clippingPlanes = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'sortObjects') {
|
if (property === 'parentEntity') {
|
||||||
this.instance.sortObjects = this.sortObjects;
|
console.warn('todo: parentEntity change');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -293,30 +453,56 @@ GameLib.D3.Renderer.prototype.toApiObject = function() {
|
||||||
var apiRenderer = new GameLib.D3.API.Renderer(
|
var apiRenderer = new GameLib.D3.API.Renderer(
|
||||||
this.id,
|
this.id,
|
||||||
this.name,
|
this.name,
|
||||||
this.autoClear,
|
|
||||||
this.localClipping,
|
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
|
this.renderMode,
|
||||||
|
this.autoClear,
|
||||||
|
this.autoClearColor,
|
||||||
|
this.autoClearDepth,
|
||||||
|
this.autoClearStencil,
|
||||||
|
this.gammaFactor,
|
||||||
|
this.gammaInput,
|
||||||
|
this.gammaOutput,
|
||||||
|
this.maxMorphTargets,
|
||||||
|
this.maxMorphNormals,
|
||||||
|
this.physicallyCorrectLights,
|
||||||
|
this.shadowMapEnabled,
|
||||||
|
this.shadowMapAutoUpdate,
|
||||||
|
this.shadowMapNeedsUpdate,
|
||||||
|
this.shadowMapType,
|
||||||
|
this.shadowMapRenderReverseSided,
|
||||||
|
this.shadowMapRenderSingleSided,
|
||||||
|
this.sortObjects,
|
||||||
|
this.toneMapping,
|
||||||
|
this.toneMappingExposure,
|
||||||
|
this.toneMappingWhitePoint,
|
||||||
|
this.premultipliedAlpha,
|
||||||
|
this.antialias,
|
||||||
|
this.stencil,
|
||||||
this.preserveDrawingBuffer,
|
this.preserveDrawingBuffer,
|
||||||
|
this.depth,
|
||||||
|
this.logarithmicDepthBuffer,
|
||||||
|
this.localClippingEnabled,
|
||||||
GameLib.Utils.IdOrNull(this.canvas),
|
GameLib.Utils.IdOrNull(this.canvas),
|
||||||
this.clearColor.toApiObject(),
|
GameLib.Utils.IdOrNull(this.renderTarget),
|
||||||
GameLib.Utils.IdOrNull(this.camera),
|
|
||||||
this.scenes.map(function(scene){
|
|
||||||
return GameLib.Utils.IdOrNull(scene);
|
|
||||||
}),
|
|
||||||
this.viewports.map(function(viewport){
|
|
||||||
return GameLib.Utils.IdOrNull(viewport);
|
|
||||||
}),
|
|
||||||
this.clippingPlanes.map(
|
this.clippingPlanes.map(
|
||||||
function(clippingPlane) {
|
function(clippingPlane){
|
||||||
return GameLib.Utils.IdOrNull(clippingPlane);
|
return GameLib.Utils.IdOrNull(clippingPlane);
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
GameLib.Utils.IdOrNull(this.bufferScene),
|
this.clearColor.toApiObject(),
|
||||||
GameLib.Utils.IdOrNull(this.bufferCamera),
|
GameLib.Utils.IdOrNull(this.camera),
|
||||||
GameLib.Utils.IdOrNull(this.renderTarget),
|
this.scenes.map(
|
||||||
|
function(scene){
|
||||||
|
return GameLib.Utils.IdOrNull(scene);
|
||||||
|
}
|
||||||
|
),
|
||||||
GameLib.Utils.IdOrNull(this.defaultScene),
|
GameLib.Utils.IdOrNull(this.defaultScene),
|
||||||
this.sortObjects,
|
this.viewports.map(
|
||||||
|
function(viewport){
|
||||||
|
return GameLib.Utils.IdOrNull(viewport);
|
||||||
|
}
|
||||||
|
),
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -340,115 +526,3 @@ GameLib.D3.Renderer.FromObject = function(graphics, objectComponent) {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience render function
|
|
||||||
*/
|
|
||||||
GameLib.D3.Renderer.prototype.render = function(delta, scenes) {
|
|
||||||
|
|
||||||
if (!this.instance) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(scenes)) {
|
|
||||||
scenes = this.scenes;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.viewports.length > 1) {
|
|
||||||
this.instance.autoClear = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scenes.length > 1) {
|
|
||||||
this.instance.autoClear = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.instance.clear();
|
|
||||||
|
|
||||||
if (
|
|
||||||
this.bufferScene &&
|
|
||||||
this.bufferScene.instance &&
|
|
||||||
this.bufferCamera &&
|
|
||||||
this.bufferCamera.instance &&
|
|
||||||
this.renderTarget &&
|
|
||||||
this.renderTarget.instance
|
|
||||||
) {
|
|
||||||
/**
|
|
||||||
* We have a buffer that should render to an offscreen render target
|
|
||||||
*/
|
|
||||||
this.instance.render(
|
|
||||||
this.bufferScene.instance,
|
|
||||||
this.bufferCamera.instance,
|
|
||||||
this.renderTarget.instance
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.viewports.map(
|
|
||||||
|
|
||||||
function(viewport) {
|
|
||||||
|
|
||||||
this.instance.setViewport(
|
|
||||||
viewport.x * this.width,
|
|
||||||
viewport.y * this.height,
|
|
||||||
viewport.width * this.width,
|
|
||||||
viewport.height * this.height
|
|
||||||
);
|
|
||||||
|
|
||||||
scenes.map(function(scene) {
|
|
||||||
|
|
||||||
if (!scene.instance) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.camera.instance && !(scene.renderCamera || scene.renderCamera.instance)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (scene.renderCamera && scene.renderCamera.instance) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A scene's renderCamera instance overrides the default renderer camera
|
|
||||||
*/
|
|
||||||
this.instance.render(
|
|
||||||
scene.instance,
|
|
||||||
scene.renderCamera.instance
|
|
||||||
)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ok just do a normal render
|
|
||||||
*/
|
|
||||||
this.instance.render(
|
|
||||||
scene.instance,
|
|
||||||
this.camera.instance
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
}.bind(this)
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.Renderer.prototype.setSize = function(width, height) {
|
|
||||||
|
|
||||||
this.width = Math.round(width);
|
|
||||||
this.height = Math.round(height);
|
|
||||||
|
|
||||||
this.canvas.width = this.width;
|
|
||||||
this.canvas.height = this.height;
|
|
||||||
|
|
||||||
this.canvas.updateInstance('width');
|
|
||||||
|
|
||||||
if (this.instance) {
|
|
||||||
this.instance.setSize(
|
|
||||||
this.width,
|
|
||||||
this.height
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
console.log('renderer not ready to set size');
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
|
@ -464,6 +464,10 @@ GameLib.D3.Scene.prototype.addObject = function(object) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.parentEntity) {
|
||||||
|
this.parentEntity.addComponent(object);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Scene.prototype.addClone = function(component) {
|
GameLib.D3.Scene.prototype.addClone = function(component) {
|
||||||
|
@ -528,6 +532,9 @@ GameLib.D3.Scene.prototype.removeObject = function(object) {
|
||||||
object.parentScene = null;
|
object.parentScene = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.parentEntity) {
|
||||||
|
this.parentEntity.removeComponent(object);
|
||||||
|
}
|
||||||
// this.buildIdToObject();
|
// this.buildIdToObject();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,6 @@ GameLib.EntityManager = function(apiEntityManager) {
|
||||||
apiEntityManager.id,
|
apiEntityManager.id,
|
||||||
apiEntityManager.name,
|
apiEntityManager.name,
|
||||||
apiEntityManager.entities,
|
apiEntityManager.entities,
|
||||||
apiEntityManager.defaultEntity,
|
|
||||||
apiEntityManager.defaultRenderer,
|
|
||||||
apiEntityManager.parentEntity
|
apiEntityManager.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -45,9 +43,7 @@ GameLib.EntityManager = function(apiEntityManager) {
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
this,
|
this,
|
||||||
{
|
{
|
||||||
'entities' : [GameLib.Entity],
|
'entities' : [GameLib.Entity]
|
||||||
'defaultEntity' : GameLib.Entity,
|
|
||||||
'defaultRenderer' : GameLib.D3.Renderer
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -384,8 +380,6 @@ GameLib.EntityManager.prototype.toApiObject = function() {
|
||||||
this.id,
|
this.id,
|
||||||
this.name,
|
this.name,
|
||||||
apiEntities,
|
apiEntities,
|
||||||
GameLib.Utils.IdOrNull(this.defaultEntity),
|
|
||||||
GameLib.Utils.IdOrNull(this.defaultRenderer),
|
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -15,15 +15,13 @@ GameLib.Entity = function (
|
||||||
apiEntity.id,
|
apiEntity.id,
|
||||||
apiEntity.name,
|
apiEntity.name,
|
||||||
apiEntity.components,
|
apiEntity.components,
|
||||||
apiEntity.renderer,
|
|
||||||
apiEntity.parentEntity
|
apiEntity.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
this,
|
this,
|
||||||
{
|
{
|
||||||
'components' : [GameLib.Component],
|
'components' : [GameLib.Component]
|
||||||
'renderer' : GameLib.D3.Renderer
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -191,7 +189,6 @@ GameLib.Entity.prototype.toApiObject = function() {
|
||||||
this.id,
|
this.id,
|
||||||
this.name,
|
this.name,
|
||||||
apiComponents,
|
apiComponents,
|
||||||
GameLib.Utils.IdOrNull(this.renderer),
|
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
/**
|
||||||
|
* Creates a Plane object
|
||||||
|
* @param graphics GameLib.GraphicsRuntime
|
||||||
|
* @param apiPlane GameLib.API.Plane
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.Plane = function(
|
||||||
|
graphics,
|
||||||
|
apiPlane
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiPlane)) {
|
||||||
|
apiPlane = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.API.Plane.call(
|
||||||
|
this,
|
||||||
|
apiPlane.id,
|
||||||
|
apiPlane.name,
|
||||||
|
apiPlane.normal,
|
||||||
|
apiPlane.constant,
|
||||||
|
apiPlane.parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
this.normal = new GameLib.Vector3(
|
||||||
|
this.graphics,
|
||||||
|
this.normal,
|
||||||
|
this
|
||||||
|
);
|
||||||
|
|
||||||
|
GameLib.Component.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.Plane.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.Plane.prototype.constructor = GameLib.Plane;
|
||||||
|
|
||||||
|
GameLib.Plane.prototype.createInstance = function() {
|
||||||
|
|
||||||
|
this.instance = new THREE.Plane(
|
||||||
|
this.normal.instance,
|
||||||
|
this.constant
|
||||||
|
);
|
||||||
|
|
||||||
|
GameLib.Component.prototype.createInstance.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.Plane.prototype.updateInstance = function(property) {
|
||||||
|
|
||||||
|
if (property === 'normal') {
|
||||||
|
|
||||||
|
this.normal.normalize();
|
||||||
|
|
||||||
|
this.instance.normal.x = this.normal.x;
|
||||||
|
this.instance.normal.y = this.normal.y;
|
||||||
|
this.instance.normal.z = this.normal.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'constant') {
|
||||||
|
this.instance.constant = this.constant;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.Plane to a new GameLib.API.Plane
|
||||||
|
* @returns {GameLib.API.Plane}
|
||||||
|
*/
|
||||||
|
GameLib.Plane.prototype.toApiObject = function() {
|
||||||
|
|
||||||
|
return new GameLib.API.Plane(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
this.normal.toApiObject(),
|
||||||
|
this.constant,
|
||||||
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts from an Object Plane to a GameLib.Plane
|
||||||
|
* @param graphics GameLib.GraphicsRuntime
|
||||||
|
* @param objectPlane Object
|
||||||
|
* @returns {GameLib.Plane}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.Plane.FromObject = function(graphics, objectPlane) {
|
||||||
|
var apiPlane = GameLib.API.Plane.FromObject(objectPlane);
|
||||||
|
return new GameLib.Plane(
|
||||||
|
graphics,
|
||||||
|
apiPlane
|
||||||
|
);
|
||||||
|
};
|
|
@ -872,6 +872,43 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
} else if (property === 'renderMode') {
|
||||||
|
controllers.push(
|
||||||
|
folder.add(
|
||||||
|
object,
|
||||||
|
property,
|
||||||
|
{
|
||||||
|
'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
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else if (property === 'shadowMapType') {
|
||||||
|
controllers.push(
|
||||||
|
folder.add(
|
||||||
|
object,
|
||||||
|
property,
|
||||||
|
{
|
||||||
|
'basic': GameLib.D3.API.Renderer.SHADOW_MAP_TYPE_BASIC,
|
||||||
|
'pcf': GameLib.D3.API.Renderer.SHADOW_MAP_TYPE_PCF,
|
||||||
|
'pcf soft': GameLib.D3.API.Renderer.SHADOW_MAP_TYPE_PCF_SOFT
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else if (property === 'toneMapping') {
|
||||||
|
controllers.push(
|
||||||
|
folder.add(
|
||||||
|
object,
|
||||||
|
property,
|
||||||
|
{
|
||||||
|
'linear': GameLib.D3.API.Renderer.TONE_MAPPING_LINEAR,
|
||||||
|
'reinhard': GameLib.D3.API.Renderer.TONE_MAPPING_REINHARD,
|
||||||
|
'uncharted 2': GameLib.D3.API.Renderer.TONE_MAPPING_UNCHARTED_2,
|
||||||
|
'cineon': GameLib.D3.API.Renderer.TONE_MAPPING_CINEON
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
} else if (property === 'opacityType') {
|
} else if (property === 'opacityType') {
|
||||||
controllers.push(
|
controllers.push(
|
||||||
folder.add(
|
folder.add(
|
||||||
|
|
|
@ -115,14 +115,14 @@ GameLib.System.Render.prototype.windowResize = function(data) {
|
||||||
renderers.map(
|
renderers.map(
|
||||||
function(renderer) {
|
function(renderer) {
|
||||||
|
|
||||||
renderer.setSize(
|
if (renderer.fullscreen) {
|
||||||
renderer.canvas.width,
|
renderer.width = data.width;
|
||||||
renderer.canvas.height
|
renderer.height = data.height;
|
||||||
);
|
/**
|
||||||
|
* widthheight simply saves a function call
|
||||||
renderer.camera.aspect = renderer.canvas.width / renderer.canvas.height;
|
*/
|
||||||
|
renderer.updateInstance('widthheight');
|
||||||
renderer.camera.updateInstance('aspect');
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -145,13 +145,6 @@ GameLib.System.Render.prototype.instanceCreated = function(data) {
|
||||||
|
|
||||||
if (data.component instanceof GameLib.D3.Renderer) {
|
if (data.component instanceof GameLib.D3.Renderer) {
|
||||||
this.renderers.push(data.component);
|
this.renderers.push(data.component);
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.WINDOW_RESIZE,
|
|
||||||
{
|
|
||||||
width : window.innerWidth,
|
|
||||||
height : window.innerHeight
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.component instanceof GameLib.Stats) {
|
if (data.component instanceof GameLib.Stats) {
|
||||||
|
@ -215,48 +208,88 @@ GameLib.System.Render.prototype.render = function(data) {
|
||||||
data
|
data
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this.renderers.length < 1) {
|
this.renderers.map(
|
||||||
/**
|
|
||||||
* Do nothing
|
|
||||||
*/
|
|
||||||
} else if (this.renderers.length === 1) {
|
|
||||||
/**
|
|
||||||
* Quite simple - we have a renderer - it wants to render its stuff
|
|
||||||
*/
|
|
||||||
this.renderers[0].render(data.delta);
|
|
||||||
|
|
||||||
} else {
|
function(renderer){
|
||||||
|
|
||||||
|
if (renderer.viewports.length > 1) {
|
||||||
|
renderer.instance.autoClear = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (renderer.scenes.length > 1) {
|
||||||
|
renderer.instance.autoClear = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.instance.clear();
|
||||||
|
|
||||||
|
renderer.viewports.map(
|
||||||
|
|
||||||
|
function(viewport) {
|
||||||
|
|
||||||
|
var trueWidth = viewport.width * renderer.width;
|
||||||
|
var trueHeight = viewport.height * renderer.height;
|
||||||
|
|
||||||
|
renderer.instance.setViewport(
|
||||||
|
viewport.x * renderer.width,
|
||||||
|
viewport.y * renderer.height,
|
||||||
|
viewport.width * renderer.width,
|
||||||
|
viewport.height * renderer.height
|
||||||
|
);
|
||||||
|
|
||||||
|
var aspect = trueWidth / trueHeight;
|
||||||
|
|
||||||
/**
|
|
||||||
* If we have multiple renderers, we have a problem - they don't share the same webGL context -
|
|
||||||
* So, we need to get their scenes and render them individually instead of trying to have both renderers render
|
|
||||||
* to the same canvas (sharing the same webgl context does not work)
|
|
||||||
*/
|
|
||||||
var scenes = this.renderers.reduce(
|
|
||||||
function(result, renderer) {
|
|
||||||
renderer.scenes.map(
|
renderer.scenes.map(
|
||||||
function(scene){
|
function (scene) {
|
||||||
result.push(scene);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
var renderer = GameLib.EntityManager.Instance.defaultRenderer;
|
var camera = renderer.camera;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(renderer)) {
|
|
||||||
/**
|
/**
|
||||||
* No default renderer, using first one
|
* A scene's renderCamera overrides the renderer camera
|
||||||
*/
|
*/
|
||||||
renderer = this.renderers[0];
|
if (scene.renderCamera && scene.renderCamera.instance) {
|
||||||
|
camera = scene.renderCamera;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.render(data.delta, scenes);
|
/**
|
||||||
|
* 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 {
|
||||||
|
console.warn('unknown render mode:' + renderer.renderMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.AFTER_RENDER,
|
GameLib.Event.AFTER_RENDER,
|
||||||
data
|
data
|
||||||
|
|
Loading…
Reference in New Issue