r3-legacy/src/r3-d3-pass-0.js

115 lines
2.3 KiB
JavaScript

/**
* R3.D3.Pass
* @param graphics R3.GraphicsRuntime
* @param apiPass R3.D3.API.Pass
* @property passType
* @constructor
*/
R3.D3.Pass = function (
graphics,
apiPass
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiPass)) {
apiPass = {
passType : R3.D3.API.Pass.PASS_TYPE_NONE
}
}
R3.D3.API.Pass.call(
this,
apiPass.id,
apiPass.name,
apiPass.passType,
apiPass.parentEntity,
apiPass.renderToScreen
);
var linkedObjects = {};
switch (this.passType) {
case R3.D3.API.Pass.PASS_TYPE_RENDER:
case R3.D3.API.Pass.PASS_TYPE_SSAO:
linkedObjects.scene = R3.D3.Scene;
linkedObjects.camera = R3.D3.Camera;
break;
default :
break;
}
R3.Component.call(
this,
linkedObjects
);
};
R3.D3.Pass.prototype = Object.create(R3.Component.prototype);
R3.D3.Pass.prototype.constructor = R3.D3.Pass;
/**
* Create Pass instance
* @returns {*}
*/
R3.D3.Pass.prototype.createInstance = function() {
if (R3.Utils.UndefinedOrNull(this.instance)) {
console.warn('no instance - call the child createInstance() first');
return;
}
this.instance.renderToScreen = this.renderToScreen;
R3.Component.prototype.createInstance.call(this);
};
/**
* Update Pass instance
*/
R3.D3.Pass.prototype.updateInstance = function(property) {
if (property === 'passType') {
var componentType = R3.D3.API.Pass.GetComponentType(this.passType);
this.replace(componentType);
return;
}
if (property === 'renderToScreen') {
this.instance.renderToScreen = this.renderToScreen;
}
R3.Component.prototype.updateInstance.call(this, property);
};
/**
* Not all passes have setSize, but this is just a safety function in case someone calls setSize on a pass component
* @param property
*/
R3.D3.Pass.prototype.setSize = function(property) {
};
/**
* R3.D3.Pass to R3.D3.API.Pass
* @returns {R3.D3.API.Pass}
*/
R3.D3.Pass.prototype.toApiObject = function() {
var apiPass = new R3.D3.API.Pass(
this.id,
this.name,
this.passType,
R3.Utils.IdOrNull(this.parentEntity),
this.renderToScreen
);
return apiPass;
};