2016-12-19 17:44:15 +01:00
|
|
|
/**
|
|
|
|
* Renders a scene with a camera
|
|
|
|
* @param graphics GameLib.D3.Graphics
|
|
|
|
* @param apiRenderer GameLib.D3.API.Renderer
|
|
|
|
* @constructor
|
|
|
|
*/
|
2017-01-06 16:53:53 +01:00
|
|
|
GameLib.D3.Renderer = function (
|
2016-12-19 17:44:15 +01:00
|
|
|
graphics,
|
|
|
|
apiRenderer
|
|
|
|
) {
|
|
|
|
|
|
|
|
this.graphics = graphics;
|
|
|
|
this.graphics.isNotThreeThrow();
|
|
|
|
|
|
|
|
GameLib.D3.API.Renderer.call(
|
|
|
|
this,
|
|
|
|
apiRenderer.id,
|
|
|
|
apiRenderer.name,
|
2017-01-09 15:20:48 +01:00
|
|
|
apiRenderer.rendererType,
|
2016-12-19 17:44:15 +01:00
|
|
|
apiRenderer.scene,
|
|
|
|
apiRenderer.camera,
|
|
|
|
apiRenderer.autoClear,
|
|
|
|
apiRenderer.localClipping,
|
|
|
|
apiRenderer.width,
|
2017-01-02 17:05:40 +01:00
|
|
|
apiRenderer.height,
|
2017-01-09 15:20:48 +01:00
|
|
|
apiRenderer.parentEntity,
|
|
|
|
apiRenderer.preserveDrawingBuffer
|
2016-12-19 17:44:15 +01:00
|
|
|
);
|
|
|
|
|
2017-01-09 15:20:48 +01:00
|
|
|
if (this.camera instanceof Object) {
|
|
|
|
if (this.camera.cameraType == GameLib.Component.COMPONENT_CAMERA) {
|
|
|
|
this.camera = new GameLib.D3.Camera(
|
|
|
|
this.graphics,
|
|
|
|
this.camera
|
|
|
|
);
|
|
|
|
} else if (this.camera.cameraType == GameLib.Component.COMPONENT_STEREO_CAMERA) {
|
|
|
|
this.camera = new GameLib.D3.StereoCamera(
|
|
|
|
this.graphics,
|
|
|
|
this.camera
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
console.warn('Camera type not supported : ' + this.camera.cameraType);
|
|
|
|
throw new Error('Camera type not supported : ' + this.camera.cameraType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-19 17:44:15 +01:00
|
|
|
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;
|
2017-01-09 15:20:48 +01:00
|
|
|
instance.preserveDrawingBuffer = this.preserveDrawingBuffer;
|
2016-12-19 17:44:15 +01:00
|
|
|
|
2017-01-09 15:20:48 +01:00
|
|
|
if (this.camera) {
|
|
|
|
this.camera.aspect = this.width / this.height;
|
|
|
|
this.camera.updateInstance();
|
2016-12-20 17:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-12-19 17:44:15 +01:00
|
|
|
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,
|
2017-01-09 15:20:48 +01:00
|
|
|
this.rendererType,
|
2016-12-19 17:44:15 +01:00
|
|
|
GameLib.Utils.IdOrNull(this.scene),
|
|
|
|
GameLib.Utils.IdOrNull(this.camera),
|
2016-12-20 17:27:36 +01:00
|
|
|
this.autoClear,
|
|
|
|
this.localClipping,
|
|
|
|
this.width,
|
2017-01-02 17:05:40 +01:00
|
|
|
this.height,
|
2017-01-09 15:20:48 +01:00
|
|
|
GameLib.Utils.IdOrNull(this.parentEntity),
|
|
|
|
this.preserveDrawingBuffer
|
2016-12-19 17:44:15 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return apiRenderer;
|
|
|
|
};
|
|
|
|
|
2017-01-09 15:20:48 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param graphics
|
|
|
|
* @param objectComponent
|
|
|
|
* @returns {GameLib.D3.Renderer}
|
|
|
|
* @constructor
|
|
|
|
*/
|
2016-12-19 17:44:15 +01:00
|
|
|
GameLib.D3.Renderer.FromObjectComponent = function(graphics, objectComponent) {
|
|
|
|
|
2017-01-06 16:53:53 +01:00
|
|
|
var apiRenderer = GameLib.D3.API.Renderer.FromObjectComponent(objectComponent);
|
2016-12-19 17:44:15 +01:00
|
|
|
|
|
|
|
return new GameLib.D3.Renderer(
|
|
|
|
graphics,
|
|
|
|
this,
|
|
|
|
apiRenderer
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2017-01-09 15:20:48 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2017-01-06 16:53:53 +01:00
|
|
|
GameLib.D3.Renderer.prototype.render = function() {
|
2017-01-09 15:20:48 +01:00
|
|
|
this.instance.render(
|
|
|
|
this.scene.instance,
|
|
|
|
this.camera.instance
|
|
|
|
);
|
|
|
|
};
|