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

92 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-01-10 17:04:30 +01:00
/**
* 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
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_PASS,
{
'camera' : GameLib.D3.Camera,
'scene' : GameLib.D3.Scene
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
2017-01-12 17:40:17 +01:00
name = 'Pass (' + id + ')';
2017-01-10 17:04:30 +01:00
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(passType)) {
passType = GameLib.D3.Pass.PASS_TYPE_RENDER;
}
this.passType = passType;
2017-01-19 17:50:11 +01:00
if (GameLib.Utils.UndefinedOrNull(camera)) {
camera = null;
}
this.camera = camera;
2017-01-10 17:04:30 +01:00
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.D3.API.Pass.prototype = Object.create(GameLib.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.FromObjectComponent = function(objectComponent) {
return new GameLib.D3.API.Pass(
objectComponent.id,
objectComponent.name,
objectComponent.passType,
objectComponent.camera,
objectComponent.scene,
objectComponent.renderToScreen,
objectComponent.parentEntity
);
};