render stuff legacy

beta.r3js.org
-=yb4f310 2018-01-07 12:22:29 +01:00
parent d4ed87868f
commit b4f673adb8
6 changed files with 110 additions and 44 deletions

View File

@ -38,6 +38,11 @@ GameLib.Canvas.prototype.createInstance = function() {
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.height = this.height;
@ -53,14 +58,19 @@ GameLib.Canvas.prototype.updateInstance = function(property) {
console.warn('unknown property update for Canvas: ' + property);
}
if (property === 'id') {
this.instance.setAttribute('id', this.id);
}
if (property === 'width') {
this.width = Math.round(this.width);
this.instance.width = this.width;
}
if (property === 'height') {
this.height = Math.round(this.height);
this.instance.height = this.height;
}
};
/**

View File

@ -29,12 +29,12 @@ GameLib.D3.API.RenderTarget = function (
this.name = name;
if (GameLib.Utils.UndefinedOrNull(width)) {
width = 800;
width = 512;
}
this.width = width;
if (GameLib.Utils.UndefinedOrNull(height)) {
height = 600;
height = 512;
}
this.height = height;
@ -44,7 +44,12 @@ GameLib.D3.API.RenderTarget = function (
this.stencilBuffer = stencilBuffer;
if (GameLib.Utils.UndefinedOrNull(texture)) {
texture = null;
texture = new GameLib.D3.API.Texture(
null,
null,
null,
new GameLib.API.Image()
);
}
this.texture = texture;

View File

@ -29,7 +29,7 @@ GameLib.D3.Renderer = function (
apiRenderer.width,
apiRenderer.height,
apiRenderer.preserveDrawingBuffer,
apiRenderer.domElement,
apiRenderer.canvas,
apiRenderer.clearColor,
apiRenderer.camera,
apiRenderer.scenes,
@ -49,12 +49,19 @@ GameLib.D3.Renderer = function (
this
);
if (this.domElement instanceof GameLib.API.DomElement) {
this.domElement = new GameLib.DomElement(
this.domElement
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) {
this.camera = new GameLib.D3.Camera(
this.graphics,
@ -127,7 +134,7 @@ GameLib.D3.Renderer = function (
GameLib.Component.call(
this,
{
'domElement' : GameLib.DomElement,
'canvas' : GameLib.Canvas,
'camera' : GameLib.D3.Camera,
'scenes' : [GameLib.D3.Scene],
'viewports' : [GameLib.D3.Viewport],
@ -150,17 +157,17 @@ GameLib.D3.Renderer.prototype.constructor = GameLib.D3.Renderer;
*/
GameLib.D3.Renderer.prototype.createInstance = function() {
if (GameLib.Utils.UndefinedOrNull(this.domElement)) {
throw new Error('no dom element');
if (GameLib.Utils.UndefinedOrNull(this.canvas)) {
throw new Error('no canvas');
}
if (GameLib.Utils.UndefinedOrNull(this.domElement.instance)) {
throw new Error('no dom element instance');
if (GameLib.Utils.UndefinedOrNull(this.canvas.instance)) {
throw new Error('no canvas instance');
}
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;
}
if (property === 'width' || 'height') {
this.instance.setSize(
this.width,
this.height
);
if (property === 'canvas') {
this.instance.dispose();
this.createInstance();
}
this.instance.domElement.width = this.width;
this.instance.domElement.height = this.height;
if (property === 'width' || '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.height,
this.preserveDrawingBuffer,
GameLib.Utils.IdOrNull(this.domElement),
GameLib.Utils.IdOrNull(this.canvas),
this.clearColor.toApiObject(),
GameLib.Utils.IdOrNull(this.camera),
this.scenes.map(function(scene){
@ -396,15 +406,22 @@ GameLib.D3.Renderer.prototype.render = function(delta, scenes) {
return;
}
/**
* A scene's renderCamera instance overrides the default renderer camera
*/
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.renderCamera.instance
)
} else {
/**
* Ok just do a normal render
*/
this.instance.render(
scene.instance,
this.camera.instance
@ -419,8 +436,14 @@ GameLib.D3.Renderer.prototype.render = function(delta, scenes) {
};
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) {
this.instance.setSize(

View File

@ -41,8 +41,10 @@ GameLib.DomElement.prototype.createInstance = function() {
/**
* Updates instance domElement
*/
GameLib.DomElement.prototype.updateInstance = function() {
this.instance = document.getElementById(this.domElementId);
GameLib.DomElement.prototype.updateInstance = function(property) {
if (property === 'domElementId') {
this.createInstance()
}
};
/**

View File

@ -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 componentTemplate
* @param property

View File

@ -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) {
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);
renderers.map(
function(renderer) {
renderer.setSize(
data.width,
data.height
renderer.canvas.width,
renderer.canvas.height
);
renderer.camera.aspect = renderer.canvas.width / renderer.canvas.height;
renderer.camera.updateInstance('aspect');
}
);
GameLib.Event.Emit(
GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE,
{
aspect : aspect,
width : data.width,
height : data.height
}
@ -142,6 +145,13 @@ GameLib.System.Render.prototype.instanceCreated = function(data) {
if (data.component instanceof GameLib.D3.Renderer) {
this.renderers.push(data.component);
GameLib.Event.Emit(
GameLib.Event.WINDOW_RESIZE,
{
width : window.innerWidth,
height : window.innerHeight
}
);
}
if (data.component instanceof GameLib.Stats) {
@ -155,9 +165,11 @@ GameLib.System.Render.prototype.instanceCreated = function(data) {
*/
GameLib.System.Render.prototype.removeComponent = function(data) {
var index;
if (data.component instanceof GameLib.D3.Renderer) {
var index = this.renderers.indexOf(data.component);
index = this.renderers.indexOf(data.component);
if (index !== -1) {
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);
}
}
};
/**