viewports, editor updates
parent
3adc03f200
commit
24897794af
|
@ -43,6 +43,7 @@ GameLib.Component.COMPONENT_SCENE = 0xf;
|
|||
GameLib.Component.COMPONENT_GAME = 0x10;
|
||||
GameLib.Component.COMPONENT_INPUT_EDITOR = 0x11;
|
||||
GameLib.Component.COMPONENT_EDITOR = 0x12;
|
||||
GameLib.Component.COMPONENT_VIEWPORT = 0x13;
|
||||
|
||||
/**
|
||||
* Components are linked at runtime - for storing, we just store the ID
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
* @param name
|
||||
* @param games [GameLib.API.D3.Game]
|
||||
* @param allSelected
|
||||
* @param selectedObjects
|
||||
* @param viewports
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
|
@ -12,6 +14,8 @@ GameLib.D3.API.Editor = function(
|
|||
name,
|
||||
games,
|
||||
allSelected,
|
||||
selectedObjects,
|
||||
viewports,
|
||||
parentEntity
|
||||
) {
|
||||
GameLib.Component.call(
|
||||
|
@ -41,6 +45,12 @@ GameLib.D3.API.Editor = function(
|
|||
allSelected = false;
|
||||
}
|
||||
this.allSelected = allSelected;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(selectedObjects)) {
|
||||
selectedObjects = [];
|
||||
}
|
||||
this.selectedObjects = selectedObjects;
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.API.Editor.prototype = Object.create(GameLib.Component.prototype);
|
||||
|
@ -57,6 +67,7 @@ GameLib.D3.API.Editor.FromObjectEditor = function(objectEditor) {
|
|||
objectEditor.name,
|
||||
objectEditor.games,
|
||||
objectEditor.allSelected,
|
||||
objectEditor.selectedObjects,
|
||||
objectEditor.parentEntity
|
||||
);
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||
* @param id String
|
||||
* @param name String
|
||||
* @param domElementId
|
||||
* @param editor GameLib.D3.API.Editor
|
||||
* @param camera
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
|
@ -10,7 +10,7 @@
|
|||
GameLib.D3.API.Input.Editor = function (
|
||||
id,
|
||||
name,
|
||||
domElementId,
|
||||
editor,
|
||||
camera,
|
||||
parentEntity
|
||||
) {
|
||||
|
@ -18,12 +18,18 @@ GameLib.D3.API.Input.Editor = function (
|
|||
this,
|
||||
GameLib.Component.COMPONENT_INPUT_EDITOR,
|
||||
{
|
||||
'camera' : GameLib.D3.Camera
|
||||
'camera' : GameLib.D3.Camera,
|
||||
'editor' : GameLib.D3.Editor
|
||||
},
|
||||
null,
|
||||
parentEntity
|
||||
);
|
||||
|
||||
this.meshMoveMode = false;
|
||||
this.meshMoveXMode = false;
|
||||
this.meshMoveYMode = false;
|
||||
this.meshMoveZMode = false;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
* @param height
|
||||
* @param parentEntity
|
||||
* @param preserveDrawingBuffer
|
||||
* @param composer GameLib.D3.API.Composer
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Renderer = function (
|
||||
|
@ -21,16 +20,13 @@ GameLib.D3.API.Renderer = function (
|
|||
width,
|
||||
height,
|
||||
parentEntity,
|
||||
preserveDrawingBuffer,
|
||||
composer
|
||||
preserveDrawingBuffer
|
||||
) {
|
||||
|
||||
GameLib.Component.call(
|
||||
this,
|
||||
GameLib.Component.COMPONENT_RENDERER,
|
||||
{
|
||||
'composer' : GameLib.D3.Composer
|
||||
},
|
||||
null,
|
||||
null,
|
||||
parentEntity
|
||||
);
|
||||
|
@ -90,11 +86,6 @@ GameLib.D3.API.Renderer = function (
|
|||
}
|
||||
}
|
||||
this.preserveDrawingBuffer = preserveDrawingBuffer;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(composer)) {
|
||||
composer = null;
|
||||
}
|
||||
this.composer = composer;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Renderer.prototype = Object.create(GameLib.Component.prototype);
|
||||
|
@ -115,7 +106,6 @@ GameLib.D3.API.Renderer.FromObjectComponent = function(objectComponent) {
|
|||
objectComponent.width,
|
||||
objectComponent.height,
|
||||
objectComponent.parentEntity,
|
||||
objectComponent.preserveDrawingBuffer,
|
||||
objectComponent.composer
|
||||
objectComponent.preserveDrawingBuffer
|
||||
);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
/**
|
||||
* Raw Viewport API object - should always correspond with the Viewport Schema
|
||||
* @param id
|
||||
* @param name
|
||||
* @param width
|
||||
* @param height
|
||||
* @param x
|
||||
* @param y
|
||||
* @param composer GameLib.D3.API.Composer
|
||||
* @param renderer GameLib.D3.API.Renderer
|
||||
* @param scene GameLib.D3.API.Scene
|
||||
* @param camera GameLib.D3.API.Camera
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Viewport = function(
|
||||
id,
|
||||
name,
|
||||
width,
|
||||
height,
|
||||
x,
|
||||
y,
|
||||
composer,
|
||||
renderer,
|
||||
scene,
|
||||
camera,
|
||||
parentEntity
|
||||
) {
|
||||
GameLib.Component.call(
|
||||
this,
|
||||
GameLib.Component.COMPONENT_VIEWPORT,
|
||||
{
|
||||
'composer' : GameLib.D3.Composer,
|
||||
'renderer' : GameLib.D3.Renderer,
|
||||
'scene' : GameLib.D3.Scene,
|
||||
'camera' : GameLib.D3.Camera
|
||||
},
|
||||
null,
|
||||
parentEntity
|
||||
);
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Viewport (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(width)) {
|
||||
width = 800;
|
||||
}
|
||||
this.width = width;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||
height = 600;
|
||||
}
|
||||
this.height = height;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(x)) {
|
||||
x = 0;
|
||||
}
|
||||
this.x = x;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(y)) {
|
||||
y = 0;
|
||||
}
|
||||
this.y = y;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(composer)) {
|
||||
composer = null;
|
||||
}
|
||||
this.composer = composer;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(renderer)) {
|
||||
renderer = null;
|
||||
}
|
||||
this.renderer = renderer;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(scene)) {
|
||||
scene = null;
|
||||
}
|
||||
this.scene = scene;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
||||
camera = null;
|
||||
}
|
||||
this.camera = camera;
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.API.Viewport.prototype = Object.create(GameLib.Component.prototype);
|
||||
GameLib.D3.API.Viewport.prototype.constructor = GameLib.D3.API.Viewport;
|
||||
|
||||
/**
|
||||
* Creates an API Viewport from an Object Viewport
|
||||
* @param objectViewport
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Viewport.FromObjectViewport = function(objectViewport) {
|
||||
return new GameLib.D3.API.Viewport(
|
||||
objectViewport.id,
|
||||
objectViewport.name,
|
||||
objectViewport.width,
|
||||
objectViewport.height,
|
||||
objectViewport.x,
|
||||
objectViewport.y,
|
||||
objectViewport.composer,
|
||||
objectViewport.renderer,
|
||||
objectViewport.scene,
|
||||
objectViewport.camera,
|
||||
objectViewport.parentEntity
|
||||
);
|
||||
};
|
||||
|
|
@ -19,7 +19,8 @@ GameLib.D3.Input.Editor = function (
|
|||
apiInputEditor.camera,
|
||||
apiInputEditor.parentEntity
|
||||
);
|
||||
|
||||
|
||||
|
||||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
|
|
|
@ -22,8 +22,7 @@ GameLib.D3.Renderer = function (
|
|||
apiRenderer.width,
|
||||
apiRenderer.height,
|
||||
apiRenderer.parentEntity,
|
||||
apiRenderer.preserveDrawingBuffer,
|
||||
apiRenderer.composer
|
||||
apiRenderer.preserveDrawingBuffer
|
||||
);
|
||||
|
||||
this.instance = this.createInstance();
|
||||
|
@ -51,7 +50,12 @@ GameLib.D3.Renderer.prototype.createInstance = function(update) {
|
|||
}
|
||||
|
||||
instance.localClippingEnabled = this.localClipping;
|
||||
instance.setSize(this.width, this.height);
|
||||
|
||||
instance.setSize(
|
||||
this.width,
|
||||
this.height
|
||||
);
|
||||
|
||||
instance.autoClear = this.autoClear;
|
||||
instance.preserveDrawingBuffer = this.preserveDrawingBuffer;
|
||||
|
||||
|
@ -73,8 +77,7 @@ GameLib.D3.Renderer.prototype.toApiComponent = function() {
|
|||
this.width,
|
||||
this.height,
|
||||
GameLib.Utils.IdOrNull(this.parentEntity),
|
||||
preserveDrawingBuffer,
|
||||
GameLib.Utils.IdOrNull(this.composer)
|
||||
preserveDrawingBuffer
|
||||
);
|
||||
|
||||
return apiRenderer;
|
||||
|
|
|
@ -0,0 +1,163 @@
|
|||
/**
|
||||
* Viewport Runtime
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param apiViewport GameLib.D3.API.Viewport
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Viewport = function (
|
||||
graphics,
|
||||
apiViewport
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
GameLib.D3.API.Viewport.call(
|
||||
this,
|
||||
apiViewport.id,
|
||||
apiViewport.name,
|
||||
apiViewport.width,
|
||||
apiViewport.height,
|
||||
apiViewport.x,
|
||||
apiViewport.y,
|
||||
apiViewport.composer,
|
||||
apiViewport.scene,
|
||||
apiViewport.camera,
|
||||
apiViewport.parentEntity
|
||||
);
|
||||
|
||||
if (this.composer instanceof GameLib.D3.API.Composer) {
|
||||
this.composer = new GameLib.D3.Composer(
|
||||
this.graphics,
|
||||
this.composer
|
||||
)
|
||||
}
|
||||
|
||||
if (this.renderer instanceof GameLib.D3.API.Renderer) {
|
||||
this.renderer = new GameLib.D3.Renderer(
|
||||
this.graphics,
|
||||
this.renderer
|
||||
)
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
}
|
||||
|
||||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
GameLib.D3.Viewport.prototype = Object.create(GameLib.D3.API.Viewport.prototype);
|
||||
GameLib.D3.Viewport.prototype.constructor = GameLib.D3.Viewport;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param update
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.Viewport.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (update) {
|
||||
instance = this.instance;
|
||||
}
|
||||
|
||||
if (this.renderer) {
|
||||
this.renderer.width = this.width;
|
||||
this.renderer.height = this.height;
|
||||
this.renderer.updateInstance();
|
||||
|
||||
this.renderer.instance.setViewport(
|
||||
this.x,
|
||||
this.y,
|
||||
this.width,
|
||||
this.height
|
||||
);
|
||||
} else if (this.composer) {
|
||||
this.composer.renderer.width = this.width;
|
||||
this.composer.renderer.height = this.height;
|
||||
this.composer.renderer.updateInstance();
|
||||
|
||||
this.composer.renderer.instance.setViewport(
|
||||
this.x,
|
||||
this.y,
|
||||
this.width,
|
||||
this.height
|
||||
)
|
||||
}
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
GameLib.D3.Viewport.prototype.updateInstance = function() {
|
||||
this.instance = this.createInstance(true);
|
||||
};
|
||||
|
||||
/**
|
||||
* GameLib.D3.Viewport to GameLib.D3.API.Viewport
|
||||
* @returns {GameLib.D3.API.Viewport}
|
||||
*/
|
||||
GameLib.D3.Viewport.prototype.toApiComponent = function() {
|
||||
|
||||
var apiViewport = new GameLib.D3.API.Viewport(
|
||||
this.id,
|
||||
this.name,
|
||||
this.width,
|
||||
this.height,
|
||||
this.x,
|
||||
this.y,
|
||||
GameLib.Utils.IdOrNull(this.composer),
|
||||
GameLib.Utils.IdOrNull(this.scene),
|
||||
GameLib.Utils.IdOrNull(this.camera),
|
||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
|
||||
return apiViewport;
|
||||
};
|
||||
|
||||
/**
|
||||
* GameLib.D3.Viewport from Object Viewport
|
||||
* @param graphics
|
||||
* @param objectComponent
|
||||
* @returns {GameLib.D3.Viewport}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Viewport.FromObjectComponent = function(graphics, objectComponent) {
|
||||
|
||||
var apiViewport = GameLib.D3.API.Viewport.FromObjectComponent(objectComponent);
|
||||
|
||||
return new GameLib.D3.Viewport(
|
||||
graphics,
|
||||
apiViewport
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Component update override
|
||||
*/
|
||||
GameLib.D3.Viewport.prototype.update = function() {
|
||||
|
||||
if (this.renderer && this.scene && this.camera) {
|
||||
this.renderer.instance.render(
|
||||
this.scene.instance,
|
||||
this.camera.instance
|
||||
)
|
||||
} else if (this.composer) {
|
||||
this.composer.instance.render();
|
||||
}
|
||||
|
||||
};
|
|
@ -23,7 +23,7 @@ GameLib.System.Render = function(
|
|||
this.stats = stats;
|
||||
|
||||
this.renderers = [];
|
||||
|
||||
this.viewports = [];
|
||||
};
|
||||
|
||||
GameLib.System.Render.prototype = Object.create(GameLib.System.prototype);
|
||||
|
@ -40,63 +40,27 @@ GameLib.System.Render.prototype.start = function() {
|
|||
this.renderers = this.entityManager.query([GameLib.D3.Renderer]);
|
||||
this.renderers.forEach(
|
||||
function (renderer) {
|
||||
|
||||
if (!renderer.instance) {
|
||||
renderer.createInstance();
|
||||
} else {
|
||||
renderer.updateInstance();
|
||||
}
|
||||
|
||||
this.domElement.appendChild(renderer.instance.domElement);
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.viewports = this.entityManager.query([GameLib.D3.Viewport]);
|
||||
};
|
||||
|
||||
/**
|
||||
* @override
|
||||
*
|
||||
* @param deltaTime
|
||||
*/
|
||||
GameLib.System.Render.prototype.update = function(deltaTime) {
|
||||
|
||||
// var renderers = this.entityManager.query([GameLib.D3.Renderer]);
|
||||
|
||||
this.renderers.forEach(
|
||||
function (renderer) {
|
||||
renderer.render(deltaTime);
|
||||
this.viewports.forEach(
|
||||
function (viewport) {
|
||||
viewport.update(deltaTime);
|
||||
}
|
||||
);
|
||||
|
||||
var renderer = this.renderers[this.activeRendererIndex];
|
||||
|
||||
var camera = this.cameras[this.activeCameraIndex];
|
||||
|
||||
if (renderer.rendererType == GameLib.D3.Renderer.RENDER_TYPE_NORMAL) {
|
||||
renderer.instance.render(
|
||||
this.instance,
|
||||
camera.instance
|
||||
);
|
||||
}
|
||||
|
||||
if (renderer.rendererType = GameLib.D3.Renderer.RENDER_TYPE_STEREO) {
|
||||
|
||||
renderer.composer.passes[0].instance.scene = this;
|
||||
|
||||
renderer.instance.setViewport(0, 0, this.width / 2, this.height);
|
||||
renderer.composer.passes[0].instance.camera = camera.instance.left;
|
||||
renderer.composer.instance.render();
|
||||
|
||||
renderer.instance.setViewport(this.width / 2, 0, this.width / 2, this.height);
|
||||
renderer.composer.passes[0].instance.camera = camera.instance.right;
|
||||
renderer.composer.instance.render();
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
GameLib.System.Render.prototype.stop = function() {
|
||||
|
||||
this.domElement.innerHTML = '';
|
||||
|
||||
this.renderers = [];
|
||||
this.viewports = [];
|
||||
};
|
Loading…
Reference in New Issue