render stuff legacy
parent
d4ed87868f
commit
b4f673adb8
|
@ -38,6 +38,11 @@ GameLib.Canvas.prototype.createInstance = function() {
|
||||||
|
|
||||||
this.instance = document.createElement('canvas');
|
this.instance = document.createElement('canvas');
|
||||||
|
|
||||||
|
this.instance.setAttribute('id', this.id);
|
||||||
|
|
||||||
|
this.width = Math.round(this.width);
|
||||||
|
this.height = Math.round(this.height);
|
||||||
|
|
||||||
this.instance.width = this.width;
|
this.instance.width = this.width;
|
||||||
this.instance.height = this.height;
|
this.instance.height = this.height;
|
||||||
|
|
||||||
|
@ -53,14 +58,19 @@ GameLib.Canvas.prototype.updateInstance = function(property) {
|
||||||
console.warn('unknown property update for Canvas: ' + property);
|
console.warn('unknown property update for Canvas: ' + property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (property === 'id') {
|
||||||
|
this.instance.setAttribute('id', this.id);
|
||||||
|
}
|
||||||
|
|
||||||
if (property === 'width') {
|
if (property === 'width') {
|
||||||
|
this.width = Math.round(this.width);
|
||||||
this.instance.width = this.width;
|
this.instance.width = this.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'height') {
|
if (property === 'height') {
|
||||||
|
this.height = Math.round(this.height);
|
||||||
this.instance.height = this.height;
|
this.instance.height = this.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -29,12 +29,12 @@ GameLib.D3.API.RenderTarget = function (
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(width)) {
|
if (GameLib.Utils.UndefinedOrNull(width)) {
|
||||||
width = 800;
|
width = 512;
|
||||||
}
|
}
|
||||||
this.width = width;
|
this.width = width;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(height)) {
|
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||||
height = 600;
|
height = 512;
|
||||||
}
|
}
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
|
||||||
|
@ -44,7 +44,12 @@ GameLib.D3.API.RenderTarget = function (
|
||||||
this.stencilBuffer = stencilBuffer;
|
this.stencilBuffer = stencilBuffer;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(texture)) {
|
if (GameLib.Utils.UndefinedOrNull(texture)) {
|
||||||
texture = null;
|
texture = new GameLib.D3.API.Texture(
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
new GameLib.API.Image()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
this.texture = texture;
|
this.texture = texture;
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ GameLib.D3.Renderer = function (
|
||||||
apiRenderer.width,
|
apiRenderer.width,
|
||||||
apiRenderer.height,
|
apiRenderer.height,
|
||||||
apiRenderer.preserveDrawingBuffer,
|
apiRenderer.preserveDrawingBuffer,
|
||||||
apiRenderer.domElement,
|
apiRenderer.canvas,
|
||||||
apiRenderer.clearColor,
|
apiRenderer.clearColor,
|
||||||
apiRenderer.camera,
|
apiRenderer.camera,
|
||||||
apiRenderer.scenes,
|
apiRenderer.scenes,
|
||||||
|
@ -49,12 +49,19 @@ GameLib.D3.Renderer = function (
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this.domElement instanceof GameLib.API.DomElement) {
|
if (this.canvas) {
|
||||||
this.domElement = new GameLib.DomElement(
|
this.width = this.canvas.width;
|
||||||
this.domElement
|
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,
|
||||||
|
@ -127,7 +134,7 @@ GameLib.D3.Renderer = function (
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
this,
|
this,
|
||||||
{
|
{
|
||||||
'domElement' : GameLib.DomElement,
|
'canvas' : GameLib.Canvas,
|
||||||
'camera' : GameLib.D3.Camera,
|
'camera' : GameLib.D3.Camera,
|
||||||
'scenes' : [GameLib.D3.Scene],
|
'scenes' : [GameLib.D3.Scene],
|
||||||
'viewports' : [GameLib.D3.Viewport],
|
'viewports' : [GameLib.D3.Viewport],
|
||||||
|
@ -150,17 +157,17 @@ GameLib.D3.Renderer.prototype.constructor = GameLib.D3.Renderer;
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Renderer.prototype.createInstance = function() {
|
GameLib.D3.Renderer.prototype.createInstance = function() {
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(this.domElement)) {
|
if (GameLib.Utils.UndefinedOrNull(this.canvas)) {
|
||||||
throw new Error('no dom element');
|
throw new Error('no canvas');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(this.domElement.instance)) {
|
if (GameLib.Utils.UndefinedOrNull(this.canvas.instance)) {
|
||||||
throw new Error('no dom element instance');
|
throw new Error('no canvas instance');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.instance = new THREE.WebGLRenderer(
|
this.instance = new THREE.WebGLRenderer(
|
||||||
{
|
{
|
||||||
canvas : this.domElement.instance
|
canvas : this.canvas.instance
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -227,14 +234,17 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) {
|
||||||
this.instance.localClippingEnabled = this.localClipping;
|
this.instance.localClippingEnabled = this.localClipping;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'width' || 'height') {
|
if (property === 'canvas') {
|
||||||
this.instance.setSize(
|
this.instance.dispose();
|
||||||
this.width,
|
this.createInstance();
|
||||||
this.height
|
}
|
||||||
);
|
|
||||||
|
|
||||||
this.instance.domElement.width = this.width;
|
if (property === 'width' || 'height') {
|
||||||
this.instance.domElement.height = this.height;
|
|
||||||
|
this.width = Math.round(this.width);
|
||||||
|
this.height = Math.round(this.height);
|
||||||
|
|
||||||
|
this.setSize(this.width, this.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -292,7 +302,7 @@ GameLib.D3.Renderer.prototype.toApiObject = function() {
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
this.preserveDrawingBuffer,
|
this.preserveDrawingBuffer,
|
||||||
GameLib.Utils.IdOrNull(this.domElement),
|
GameLib.Utils.IdOrNull(this.canvas),
|
||||||
this.clearColor.toApiObject(),
|
this.clearColor.toApiObject(),
|
||||||
GameLib.Utils.IdOrNull(this.camera),
|
GameLib.Utils.IdOrNull(this.camera),
|
||||||
this.scenes.map(function(scene){
|
this.scenes.map(function(scene){
|
||||||
|
@ -396,15 +406,22 @@ GameLib.D3.Renderer.prototype.render = function(delta, scenes) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A scene's renderCamera instance overrides the default renderer camera
|
|
||||||
*/
|
|
||||||
if (scene.renderCamera && scene.renderCamera.instance) {
|
if (scene.renderCamera && scene.renderCamera.instance) {
|
||||||
this.instance.render(
|
|
||||||
|
/**
|
||||||
|
* A scene's renderCamera instance overrides the default renderer camera
|
||||||
|
*/
|
||||||
|
this.instance.render(
|
||||||
scene.instance,
|
scene.instance,
|
||||||
scene.renderCamera.instance
|
scene.renderCamera.instance
|
||||||
)
|
)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ok just do a normal render
|
||||||
|
*/
|
||||||
this.instance.render(
|
this.instance.render(
|
||||||
scene.instance,
|
scene.instance,
|
||||||
this.camera.instance
|
this.camera.instance
|
||||||
|
@ -419,8 +436,14 @@ GameLib.D3.Renderer.prototype.render = function(delta, scenes) {
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Renderer.prototype.setSize = function(width, height) {
|
GameLib.D3.Renderer.prototype.setSize = function(width, height) {
|
||||||
this.width = width;
|
|
||||||
this.height = 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) {
|
if (this.instance) {
|
||||||
this.instance.setSize(
|
this.instance.setSize(
|
||||||
|
|
|
@ -41,8 +41,10 @@ GameLib.DomElement.prototype.createInstance = function() {
|
||||||
/**
|
/**
|
||||||
* Updates instance domElement
|
* Updates instance domElement
|
||||||
*/
|
*/
|
||||||
GameLib.DomElement.prototype.updateInstance = function() {
|
GameLib.DomElement.prototype.updateInstance = function(property) {
|
||||||
this.instance = document.getElementById(this.domElementId);
|
if (property === 'domElementId') {
|
||||||
|
this.createInstance()
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -447,7 +447,7 @@ GameLib.System.GUI.prototype.buildVectorControl = function(folder, componentTemp
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a Paren Selection control
|
* Builds a Parent Selection control
|
||||||
* @param folder
|
* @param folder
|
||||||
* @param componentTemplate
|
* @param componentTemplate
|
||||||
* @param property
|
* @param property
|
||||||
|
|
|
@ -101,32 +101,35 @@ GameLib.System.Render.prototype.nativeWindowResize = function() {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.System.Render.prototype.getOffset = function (el) {
|
||||||
|
var rect = el.getBoundingClientRect(),
|
||||||
|
scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,
|
||||||
|
scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
||||||
|
return { top: rect.top + scrollTop, left: rect.left + scrollLeft }
|
||||||
|
};
|
||||||
|
|
||||||
GameLib.System.Render.prototype.windowResize = function(data) {
|
GameLib.System.Render.prototype.windowResize = function(data) {
|
||||||
|
|
||||||
var aspect = (data.width / data.height);
|
|
||||||
|
|
||||||
var cameras = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CAMERA);
|
|
||||||
|
|
||||||
cameras.map(function(camera){
|
|
||||||
camera.aspect = aspect;
|
|
||||||
camera.updateInstance('aspect');
|
|
||||||
});
|
|
||||||
|
|
||||||
var renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RENDERER);
|
var renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RENDERER);
|
||||||
|
|
||||||
renderers.map(
|
renderers.map(
|
||||||
function(renderer) {
|
function(renderer) {
|
||||||
|
|
||||||
renderer.setSize(
|
renderer.setSize(
|
||||||
data.width,
|
renderer.canvas.width,
|
||||||
data.height
|
renderer.canvas.height
|
||||||
);
|
);
|
||||||
|
|
||||||
|
renderer.camera.aspect = renderer.canvas.width / renderer.canvas.height;
|
||||||
|
|
||||||
|
renderer.camera.updateInstance('aspect');
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE,
|
GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE,
|
||||||
{
|
{
|
||||||
aspect : aspect,
|
|
||||||
width : data.width,
|
width : data.width,
|
||||||
height : data.height
|
height : data.height
|
||||||
}
|
}
|
||||||
|
@ -142,6 +145,13 @@ 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) {
|
||||||
|
@ -155,9 +165,11 @@ GameLib.System.Render.prototype.instanceCreated = function(data) {
|
||||||
*/
|
*/
|
||||||
GameLib.System.Render.prototype.removeComponent = function(data) {
|
GameLib.System.Render.prototype.removeComponent = function(data) {
|
||||||
|
|
||||||
|
var index;
|
||||||
|
|
||||||
if (data.component instanceof GameLib.D3.Renderer) {
|
if (data.component instanceof GameLib.D3.Renderer) {
|
||||||
|
|
||||||
var index = this.renderers.indexOf(data.component);
|
index = this.renderers.indexOf(data.component);
|
||||||
|
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
console.log('removing renderer from system');
|
console.log('removing renderer from system');
|
||||||
|
@ -169,6 +181,20 @@ GameLib.System.Render.prototype.removeComponent = function(data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.component instanceof GameLib.Stats) {
|
||||||
|
|
||||||
|
index = this.statistics.indexOf(data.component);
|
||||||
|
|
||||||
|
if (index !== -1) {
|
||||||
|
console.log('removing statistics from system');
|
||||||
|
|
||||||
|
this.statistics.splice(index, 1);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
console.log('failed to find the statistics in the system : ' + data.component.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue