2017-01-10 17:04:30 +01:00
|
|
|
/**
|
|
|
|
* Renders a scene with a camera
|
|
|
|
* @param graphics GameLib.D3.Graphics
|
|
|
|
* @param apiPass GameLib.D3.API.Pass
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.D3.Pass = function (
|
|
|
|
graphics,
|
|
|
|
apiPass
|
|
|
|
) {
|
|
|
|
|
|
|
|
this.graphics = graphics;
|
|
|
|
this.graphics.isNotThreeThrow();
|
|
|
|
|
2017-01-17 13:24:45 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(apiPass)) {
|
|
|
|
apiPass = {};
|
|
|
|
}
|
|
|
|
|
2017-05-11 04:48:02 +02:00
|
|
|
if (apiPass instanceof GameLib.D3.Pass) {
|
|
|
|
return apiPass;
|
|
|
|
}
|
|
|
|
|
2017-01-10 17:04:30 +01:00
|
|
|
GameLib.D3.API.Pass.call(
|
|
|
|
this,
|
|
|
|
apiPass.id,
|
|
|
|
apiPass.name,
|
|
|
|
apiPass.passType,
|
|
|
|
apiPass.camera,
|
|
|
|
apiPass.scene,
|
|
|
|
apiPass.renderToScreen,
|
|
|
|
apiPass.parentEntity
|
|
|
|
);
|
|
|
|
|
2017-01-19 17:50:11 +01:00
|
|
|
this.buildIdToObject();
|
|
|
|
|
2017-01-10 17:04:30 +01:00
|
|
|
this.instance = this.createInstance();
|
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.D3.Pass.prototype = Object.create(GameLib.D3.API.Pass.prototype);
|
|
|
|
GameLib.D3.Pass.prototype.constructor = GameLib.D3.Pass;
|
|
|
|
|
|
|
|
GameLib.D3.Pass.PASS_TYPE_RENDER = 0x1;
|
|
|
|
GameLib.D3.Pass.PASS_TYPE_COPY_SHADER = 0x2;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create Pass instance
|
|
|
|
* @param update
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
|
|
|
GameLib.D3.Pass.prototype.createInstance = function(update) {
|
|
|
|
|
|
|
|
var instance = null;
|
|
|
|
|
|
|
|
if (update) {
|
|
|
|
instance = this.instance;
|
2017-01-19 17:50:11 +01:00
|
|
|
}
|
2017-01-10 17:04:30 +01:00
|
|
|
|
2017-01-19 17:50:11 +01:00
|
|
|
if (this.passType == GameLib.D3.Pass.PASS_TYPE_RENDER) {
|
2017-01-10 17:04:30 +01:00
|
|
|
|
2017-01-19 17:50:11 +01:00
|
|
|
if (this.scene && this.camera) {
|
2017-01-10 17:04:30 +01:00
|
|
|
if (!THREE.RenderPass) {
|
|
|
|
console.warn('No THREE.RenderPass');
|
|
|
|
throw new Error('No THREE.RenderPass');
|
|
|
|
}
|
|
|
|
|
|
|
|
instance = new THREE.RenderPass(
|
|
|
|
this.scene.instance,
|
|
|
|
this.camera.instance
|
|
|
|
);
|
2017-01-19 17:50:11 +01:00
|
|
|
}
|
2017-01-10 17:04:30 +01:00
|
|
|
|
2017-01-19 17:50:11 +01:00
|
|
|
} else if (this.passType == GameLib.D3.Pass.PASS_TYPE_COPY_SHADER) {
|
|
|
|
|
|
|
|
if (!THREE.CopyShader) {
|
|
|
|
console.warn('No THREE.CopyShader');
|
|
|
|
throw new Error('No THREE.CopyShader');
|
2017-01-10 17:04:30 +01:00
|
|
|
}
|
2017-01-19 17:50:11 +01:00
|
|
|
|
|
|
|
instance = THREE.CopyShader;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
console.warn('Render pass not supported yet: ' + this.passType);
|
|
|
|
throw new Error('Render pass not supported yet: ' + this.passType);
|
2017-01-10 17:04:30 +01:00
|
|
|
}
|
|
|
|
|
2017-01-19 17:50:11 +01:00
|
|
|
if (instance) {
|
|
|
|
instance.renderToScreen = this.renderToScreen;
|
|
|
|
}
|
2017-01-10 17:04:30 +01:00
|
|
|
|
|
|
|
return instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update Pass instance
|
|
|
|
*/
|
|
|
|
GameLib.D3.Pass.prototype.updateInstance = function() {
|
|
|
|
this.instance = this.createInstance(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GameLib.D3.Pass to GameLib.D3.API.Pass
|
|
|
|
* @returns {GameLib.D3.API.Pass}
|
|
|
|
*/
|
|
|
|
GameLib.D3.Pass.prototype.toApiComponent = function() {
|
|
|
|
|
|
|
|
var apiPass = new GameLib.D3.API.Pass(
|
|
|
|
this.id,
|
|
|
|
this.name,
|
|
|
|
this.passType,
|
|
|
|
GameLib.Utils.IdOrNull(this.camera),
|
|
|
|
GameLib.Utils.IdOrNull(this.scene),
|
|
|
|
this.renderToScreen,
|
|
|
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
|
|
|
);
|
|
|
|
|
|
|
|
return apiPass;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GameLib.D3.Pass from Object
|
|
|
|
* @param graphics
|
|
|
|
* @param objectComponent
|
|
|
|
* @returns {GameLib.D3.Pass}
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.D3.Pass.FromObjectComponent = function(graphics, objectComponent) {
|
|
|
|
|
|
|
|
var apiPass = GameLib.D3.API.Pass.FromObjectComponent(objectComponent);
|
|
|
|
|
|
|
|
return new GameLib.D3.Pass(
|
|
|
|
graphics,
|
|
|
|
apiPass
|
|
|
|
);
|
|
|
|
};
|