r3-legacy/src/game-lib-d3-composer.js

113 lines
2.5 KiB
JavaScript
Raw Normal View History

2017-01-10 17:04:30 +01:00
/**
* Renders a scene with a camera
* @param graphics GameLib.D3.Graphics
* @param apiComposer GameLib.D3.API.Composer
* @constructor
*/
GameLib.D3.Composer = function (
graphics,
apiComposer
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
2017-01-12 17:40:17 +01:00
if (GameLib.Utils.UndefinedOrNull(apiComposer)) {
apiComposer = {};
}
2017-01-10 17:04:30 +01:00
GameLib.D3.API.Composer.call(
this,
apiComposer.id,
apiComposer.name,
apiComposer.renderer,
apiComposer.renderTarget,
apiComposer.passes,
apiComposer.parentEntity
);
this.instance = this.createInstance();
};
GameLib.D3.Composer.prototype = Object.create(GameLib.D3.API.Composer.prototype);
GameLib.D3.Composer.prototype.constructor = GameLib.D3.Composer;
/**
* Creates a Composer instance
* @param update
* @returns {*}
*/
GameLib.D3.Composer.prototype.createInstance = function(update) {
var instance = null;
if (update) {
instance = this.instance;
} else {
if (!THREE.EffectComposer) {
console.warn('No THREE.EffectComposer');
throw new Error('No THREE.EffectComposer');
}
instance = new THREE.EffectComposer(
this.renderer.instance,
this.renderTarget.instance
);
this.passes.map(
function(pass) {
this.instance.addPass(pass.instance);
}.bind(this)
);
}
return instance;
};
/**
* Updates Composer instance
*/
GameLib.D3.Composer.prototype.updateInstance = function() {
this.instance = this.createInstance(true);
};
/**
* GameLib.D3.Composer to GameLib.D3.API.Composer
* @returns {GameLib.D3.API.Composer}
*/
GameLib.D3.Composer.prototype.toApiComponent = function() {
var apiComposer = new GameLib.D3.API.Composer(
this.id,
this.name,
GameLib.Utils.IdOrNull(this.renderer),
GameLib.Utils.IdOrNull(this.renderTarget),
this.passes.map(
function(pass) {
return GameLib.Utils.IdOrNull(pass);
}
),
GameLib.Utils.IdOrNull(this.parentEntity)
);
return apiComposer;
};
/**
*
* @param graphics
* @param objectComponent
* @returns {GameLib.D3.Composer}
* @constructor
*/
GameLib.D3.Composer.FromObjectComponent = function(graphics, objectComponent) {
var apiComposer = GameLib.D3.API.Composer.FromObjectComponent(objectComponent);
return new GameLib.D3.Composer(
graphics,
apiComposer
);
};