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

86 lines
2.0 KiB
JavaScript

/**
* This component renders a scene
* @param id String
* @param name String
* @param passType
* @param camera
* @param scene
* @param renderToScreen
* @param parentEntity
* @constructor
*/
GameLib.D3.API.Pass = function (
id,
name,
passType,
camera,
scene,
renderToScreen,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Pass (' + id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(passType)) {
passType = GameLib.D3.Pass.PASS_TYPE_RENDER;
}
this.passType = passType;
if (GameLib.Utils.UndefinedOrNull(camera)) {
camera = null;
}
this.camera = camera;
if (GameLib.Utils.UndefinedOrNull(scene)) {
scene = null;
}
this.scene = scene;
if (GameLib.Utils.UndefinedOrNull(renderToScreen)) {
if (this.passType === GameLib.D3.Pass.PASS_TYPE_RENDER) {
renderToScreen = false;
} else if (GameLib.D3.Pass.PASS_TYPE_COPY_SHADER) {
renderToScreen = true;
} else {
console.warn('Unsupported Render Pass Type : ' + this.passType);
throw new Error('Unsupported Render Pass Type : ' + this.passType);
}
}
this.renderToScreen = renderToScreen;
GameLib.API.Component.call(
this,
GameLib.Component.PASS,
parentEntity
);
};
GameLib.D3.API.Pass.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.D3.API.Pass.prototype.constructor = GameLib.D3.API.Pass;
/**
* Object to GameLib.D3.API.Pass
* @param objectComponent
* @constructor
*/
GameLib.D3.API.Pass.FromObject = function(objectComponent) {
return new GameLib.D3.API.Pass(
objectComponent.id,
objectComponent.name,
objectComponent.passType,
objectComponent.camera,
objectComponent.scene,
objectComponent.renderToScreen,
objectComponent.parentEntity
);
};