r3-legacy/src/game-lib-d3-renderer.js

106 lines
2.6 KiB
JavaScript
Raw Normal View History

2016-12-19 17:44:15 +01:00
/**
* Renders a scene with a camera
* @param graphics GameLib.D3.Graphics
* @param parentObject
* @param apiRenderer GameLib.D3.API.Renderer
* @constructor
*/
GameLib.D3.Renderer = function RuntimeRenderer(
graphics,
parentObject,
apiRenderer
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
parentObject = null;
}
this.parentObject = parentObject;
GameLib.D3.API.Renderer.call(
this,
apiRenderer.id,
apiRenderer.name,
apiRenderer.scene,
apiRenderer.camera,
apiRenderer.autoClear,
apiRenderer.localClipping,
apiRenderer.width,
apiRenderer.height
);
this.instance = this.createInstance();
};
GameLib.D3.Renderer.prototype = Object.create(GameLib.D3.API.Renderer.prototype);
GameLib.D3.Renderer.prototype.constructor = GameLib.D3.Renderer;
GameLib.D3.Renderer.prototype.createInstance = function(update) {
var instance = null;
if (update) {
instance = this.instance;
} else {
instance = new THREE.WebGLRenderer();
}
instance.localClippingEnabled = this.localClipping;
instance.setSize(this.width, this.height);
instance.autoClear = this.autoClear;
if (this.camera && this.camera.instance) {
this.camera.instance.aspect = this.width / this.height;
this.camera.instance.updateProjectionMatrix();
}
2016-12-19 17:44:15 +01:00
this.instance = instance;
return instance;
};
GameLib.D3.Renderer.prototype.updateInstance = function() {
this.instance = this.createInstance(true);
};
GameLib.D3.Renderer.prototype.toApiComponent = function() {
var apiRenderer = new GameLib.D3.API.Renderer(
this.id,
this.name,
GameLib.Utils.IdOrNull(this.scene),
GameLib.Utils.IdOrNull(this.camera),
this.autoClear,
this.localClipping,
this.width,
this.height
2016-12-19 17:44:15 +01:00
);
return apiRenderer;
};
GameLib.D3.Renderer.FromObjectComponent = function(graphics, objectComponent) {
var apiRenderer = new GameLib.D3.API.Renderer(
objectComponent.id,
objectComponent.name,
objectComponent.scene,
objectComponent.camera,
objectComponent.autoClear,
objectComponent.localClipping,
objectComponent.width,
objectComponent.height
2016-12-19 17:44:15 +01:00
);
return new GameLib.D3.Renderer(
graphics,
this,
apiRenderer
);
};
GameLib.D3.Renderer.prototype.render = function(deltaTime) {
this.instance.render(this.scene.instance, this.camera.instance);
};