178 lines
4.1 KiB
JavaScript
178 lines
4.1 KiB
JavaScript
/**
|
|
* This component renders a scene
|
|
* @param id String
|
|
* @param name String
|
|
* @param autoClear bool
|
|
* @param localClipping
|
|
* @param width
|
|
* @param height
|
|
* @param domElement
|
|
* @param clearColor
|
|
* @param camera
|
|
* @param scenes
|
|
* @param viewports
|
|
* @param parentEntity
|
|
* @param preserveDrawingBuffer
|
|
* @param clippingPlanes
|
|
* @param bufferScene
|
|
* @param bufferCamera
|
|
* @param renderTarget
|
|
* @param sortObjects
|
|
* @param defaultScene
|
|
* @constructor
|
|
*/
|
|
GameLib.D3.API.Renderer = function (
|
|
id,
|
|
name,
|
|
autoClear,
|
|
localClipping,
|
|
width,
|
|
height,
|
|
preserveDrawingBuffer,
|
|
domElement,
|
|
clearColor,
|
|
camera,
|
|
scenes,
|
|
viewports,
|
|
clippingPlanes,
|
|
bufferScene,
|
|
bufferCamera,
|
|
renderTarget,
|
|
defaultScene,
|
|
sortObjects,
|
|
parentEntity
|
|
) {
|
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
id = GameLib.Utils.RandomId();
|
|
}
|
|
this.id = id;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
name = "Renderer (" + this.id + ")";
|
|
}
|
|
this.name = name;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(autoClear)) {
|
|
autoClear = true;
|
|
}
|
|
this.autoClear = autoClear;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(localClipping)) {
|
|
localClipping = false;
|
|
|
|
if (clippingPlanes && clippingPlanes.length > 0) {
|
|
localClipping = true;
|
|
}
|
|
}
|
|
this.localClipping = localClipping;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(width)) {
|
|
width = 800;
|
|
}
|
|
this.width = width;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(height)) {
|
|
height = 600;
|
|
}
|
|
this.height = height;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(preserveDrawingBuffer)) {
|
|
preserveDrawingBuffer = false;
|
|
}
|
|
this.preserveDrawingBuffer = preserveDrawingBuffer;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(domElement)) {
|
|
domElement = null;
|
|
}
|
|
this.domElement = domElement;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(clearColor)) {
|
|
clearColor = new GameLib.API.Color(0.11, 0.11, 0.11);
|
|
}
|
|
this.clearColor = clearColor;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(defaultScene)) {
|
|
defaultScene = null;
|
|
}
|
|
this.defaultScene = defaultScene;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(sortObjects)) {
|
|
sortObjects = true;
|
|
}
|
|
this.sortObjects = sortObjects;
|
|
|
|
GameLib.API.Component.call(
|
|
this,
|
|
GameLib.Component.RENDERER,
|
|
parentEntity
|
|
);
|
|
|
|
};
|
|
|
|
GameLib.D3.API.Renderer.prototype = Object.create(GameLib.Component.prototype);
|
|
GameLib.D3.API.Renderer.prototype.constructor = GameLib.D3.API.Renderer;
|
|
|
|
/**
|
|
* Object to GameLib.D3.API.Renderer
|
|
* @param objectComponent
|
|
* @constructor
|
|
*/
|
|
GameLib.D3.API.Renderer.FromObject = function(objectComponent) {
|
|
return new GameLib.D3.API.Renderer(
|
|
objectComponent.id,
|
|
objectComponent.name,
|
|
objectComponent.autoClear,
|
|
objectComponent.localClipping,
|
|
objectComponent.width,
|
|
objectComponent.height,
|
|
objectComponent.preserveDrawingBuffer,
|
|
objectComponent.domElement,
|
|
objectComponent.clearColor,
|
|
objectComponent.camera,
|
|
objectComponent.scenes,
|
|
objectComponent.viewports,
|
|
objectComponent.clippingPlanes,
|
|
objectComponent.bufferScene,
|
|
objectComponent.bufferCamera,
|
|
objectComponent.renderTarget,
|
|
objectComponent.defaultScene,
|
|
objectComponent.sortObjects,
|
|
objectComponent.parentEntity
|
|
);
|
|
};
|