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

178 lines
4.1 KiB
JavaScript
Raw Normal View History

2016-12-19 17:44:15 +01:00
/**
* This component renders a scene
* @param id String
* @param name String
* @param autoClear bool
* @param localClipping
* @param width
* @param height
* @param domElement
2017-06-07 11:32:52 +02:00
* @param clearColor
2017-08-24 22:20:40 +02:00
* @param camera
* @param scenes
* @param viewports
2017-01-02 17:05:40 +01:00
* @param parentEntity
2017-01-09 15:20:48 +01:00
* @param preserveDrawingBuffer
2017-09-20 15:24:15 +02:00
* @param clippingPlanes
* @param bufferScene
* @param bufferCamera
* @param renderTarget
2017-12-04 13:23:15 +01:00
* @param sortObjects
2017-10-27 09:32:28 +02:00
* @param defaultScene
2016-12-19 17:44:15 +01:00
* @constructor
*/
GameLib.D3.API.Renderer = function (
id,
name,
autoClear,
localClipping,
width,
2017-01-02 17:05:40 +01:00
height,
2017-01-31 15:23:38 +01:00
preserveDrawingBuffer,
domElement,
2017-06-07 11:32:52 +02:00
clearColor,
2017-08-24 22:20:40 +02:00
camera,
scenes,
viewports,
2017-09-20 15:24:15 +02:00
clippingPlanes,
bufferScene,
bufferCamera,
renderTarget,
2017-10-27 09:32:28 +02:00
defaultScene,
2017-11-03 11:55:20 +01:00
sortObjects,
2017-01-31 15:23:38 +01:00
parentEntity
2016-12-19 17:44:15 +01:00
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
2017-01-09 15:20:48 +01:00
name = "Renderer (" + this.id + ")";
2016-12-19 17:44:15 +01:00
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(autoClear)) {
2017-01-31 15:23:38 +01:00
autoClear = true;
2016-12-19 17:44:15 +01:00
}
this.autoClear = autoClear;
if (GameLib.Utils.UndefinedOrNull(localClipping)) {
localClipping = false;
2017-09-20 15:24:15 +02:00
if (clippingPlanes && clippingPlanes.length > 0) {
localClipping = true;
}
2016-12-19 17:44:15 +01:00
}
this.localClipping = localClipping;
if (GameLib.Utils.UndefinedOrNull(width)) {
width = 800;
}
this.width = width;
if (GameLib.Utils.UndefinedOrNull(height)) {
height = 600;
}
this.height = height;
2017-01-09 15:20:48 +01:00
if (GameLib.Utils.UndefinedOrNull(preserveDrawingBuffer)) {
2017-01-31 15:23:38 +01:00
preserveDrawingBuffer = false;
2017-01-09 15:20:48 +01:00
}
this.preserveDrawingBuffer = preserveDrawingBuffer;
if (GameLib.Utils.UndefinedOrNull(domElement)) {
domElement = null;
}
this.domElement = domElement;
2017-06-07 11:32:52 +02:00
if (GameLib.Utils.UndefinedOrNull(clearColor)) {
clearColor = new GameLib.API.Color(0.11, 0.11, 0.11);
2017-06-07 11:32:52 +02:00
}
this.clearColor = clearColor;
2017-06-16 15:49:53 +02:00
2017-08-24 22:20:40 +02:00
if (GameLib.Utils.UndefinedOrNull(camera)) {
camera = null;
}
this.camera = camera;
if (GameLib.Utils.UndefinedOrNull(scenes)) {
scenes = [];
}
this.scenes = scenes;
if (GameLib.Utils.UndefinedOrNull(viewports)) {
viewports = [];
}
this.viewports = viewports;
2017-09-20 15:24:15 +02:00
if (GameLib.Utils.UndefinedOrNull(clippingPlanes)) {
clippingPlanes = [];
}
this.clippingPlanes = clippingPlanes;
if (GameLib.Utils.UndefinedOrNull(bufferScene)) {
bufferScene = null;
}
this.bufferScene = bufferScene;
if (GameLib.Utils.UndefinedOrNull(bufferCamera)) {
bufferCamera = camera;
}
this.bufferCamera = bufferCamera;
if (GameLib.Utils.UndefinedOrNull(renderTarget)) {
renderTarget = null;
}
this.renderTarget = renderTarget;
2017-10-27 09:32:28 +02:00
if (GameLib.Utils.UndefinedOrNull(defaultScene)) {
defaultScene = null;
}
this.defaultScene = defaultScene;
2017-11-03 11:55:20 +01:00
if (GameLib.Utils.UndefinedOrNull(sortObjects)) {
sortObjects = true;
}
this.sortObjects = sortObjects;
2017-12-04 13:23:15 +01:00
GameLib.API.Component.call(
this,
GameLib.Component.RENDERER,
parentEntity
);
2017-06-16 15:49:53 +02:00
2016-12-19 17:44:15 +01:00
};
GameLib.D3.API.Renderer.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.Renderer.prototype.constructor = GameLib.D3.API.Renderer;
2017-01-06 16:53:53 +01:00
/**
* Object to GameLib.D3.API.Renderer
* @param objectComponent
* @constructor
*/
2017-06-14 14:21:57 +02:00
GameLib.D3.API.Renderer.FromObject = function(objectComponent) {
2017-01-06 16:53:53 +01:00
return new GameLib.D3.API.Renderer(
objectComponent.id,
objectComponent.name,
objectComponent.autoClear,
objectComponent.localClipping,
objectComponent.width,
objectComponent.height,
2017-01-31 15:23:38 +01:00
objectComponent.preserveDrawingBuffer,
objectComponent.domElement,
2017-06-07 11:32:52 +02:00
objectComponent.clearColor,
2017-08-24 22:20:40 +02:00
objectComponent.camera,
objectComponent.scenes,
objectComponent.viewports,
2017-09-20 15:24:15 +02:00
objectComponent.clippingPlanes,
objectComponent.bufferScene,
objectComponent.bufferCamera,
objectComponent.renderTarget,
2017-10-27 09:32:28 +02:00
objectComponent.defaultScene,
2017-11-03 11:55:20 +01:00
objectComponent.sortObjects,
2017-01-31 15:23:38 +01:00
objectComponent.parentEntity
2017-01-06 16:53:53 +01:00
);
};