271 lines
6.8 KiB
JavaScript
271 lines
6.8 KiB
JavaScript
/**
|
|
* R3.RenderConfiguration
|
|
* @param graphics
|
|
* @param apiRenderConfiguration R3.API.RenderConfiguration
|
|
* @constructor
|
|
*/
|
|
R3.RenderConfiguration = function (
|
|
graphics,
|
|
apiRenderConfiguration
|
|
) {
|
|
|
|
this.graphics = graphics;
|
|
this.graphics.isNotThreeThrow();
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiRenderConfiguration)) {
|
|
apiRenderConfiguration = {};
|
|
}
|
|
|
|
R3.API.RenderConfiguration.call(
|
|
this,
|
|
apiRenderConfiguration.id,
|
|
apiRenderConfiguration.name,
|
|
apiRenderConfiguration.parentEntity,
|
|
apiRenderConfiguration.logicalSize,
|
|
apiRenderConfiguration.aspectRatio,
|
|
apiRenderConfiguration.scaleMode,
|
|
apiRenderConfiguration.activeCamera,
|
|
apiRenderConfiguration.activeScene,
|
|
apiRenderConfiguration.activeScenes,
|
|
apiRenderConfiguration.activeRenderer,
|
|
apiRenderConfiguration.activeComposer,
|
|
apiRenderConfiguration.activeEffect,
|
|
apiRenderConfiguration.enableComposer,
|
|
apiRenderConfiguration.enableEffect,
|
|
apiRenderConfiguration.defaultMode
|
|
);
|
|
|
|
this.logicalSize = new R3.Vector2(
|
|
this.graphics,
|
|
this.logicalSize,
|
|
this
|
|
);
|
|
|
|
R3.Component.call(
|
|
this,
|
|
{
|
|
'activeCamera' : R3.D3.Camera,
|
|
'activeScene' : R3.D3.Scene,
|
|
'activeScenes' : [R3.D3.Scene],
|
|
'activeRenderer' : R3.Renderer,
|
|
'activeComposer' : R3.D3.Composer,
|
|
'activeEffect' : R3.D3.Effect
|
|
}
|
|
);
|
|
|
|
};
|
|
|
|
R3.RenderConfiguration.prototype = Object.create(R3.Component.prototype);
|
|
R3.RenderConfiguration.prototype.constructor = R3.RenderConfiguration;
|
|
|
|
/**
|
|
* Create RenderConfiguration Instance
|
|
* @returns {*}
|
|
*/
|
|
R3.RenderConfiguration.prototype.createInstance = function() {
|
|
|
|
this.instance = {};
|
|
|
|
R3.Component.prototype.createInstance.call(this);
|
|
};
|
|
|
|
/**
|
|
* Update RenderConfiguration Instance
|
|
*/
|
|
R3.RenderConfiguration.prototype.updateInstance = function(property) {
|
|
|
|
if (
|
|
property === 'logicalSize' ||
|
|
property === 'aspectRatio' ||
|
|
property === 'scaleMode'
|
|
) {
|
|
|
|
console.log('todo: implement fixed aspect ratios for different scale modes');
|
|
|
|
if (
|
|
R3.Utils.Defined(this.activeCamera) &&
|
|
R3.Utils.Defined(this.activeCamera.instance)
|
|
) {
|
|
|
|
/**
|
|
* For now - just use normal aspect ratio
|
|
*/
|
|
R3.Event.Emit(
|
|
R3.Event.GET_WINDOW_SIZE,
|
|
{},
|
|
function(data) {
|
|
|
|
if (data.width === data.height) {
|
|
console.log('square');
|
|
}
|
|
|
|
if (data.width > data.height) {
|
|
console.log('landscape');
|
|
}
|
|
|
|
if (data.width < data.height) {
|
|
console.log('portrait');
|
|
}
|
|
|
|
this.activeCamera.aspect = data.width / data.height;
|
|
this.activeCamera.updateInstance('aspect');
|
|
|
|
}.bind(this)
|
|
)
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (property === 'activeCamera') {
|
|
|
|
if (
|
|
R3.Utils.Defined(this.activeCamera) &&
|
|
R3.Utils.Defined(this.activeCamera.instance)
|
|
) {
|
|
/**
|
|
* Update the aspect ratio for the active camera
|
|
*/
|
|
this.updateInstance('aspectRatio');
|
|
|
|
R3.EntityManager.Instance.queryComponents(R3.Component.PASS_RENDER).map(
|
|
function(renderPass) {
|
|
renderPass.camera = this.activeCamera;
|
|
renderPass.updateInstance('camera');
|
|
}.bind(this)
|
|
)
|
|
}
|
|
}
|
|
|
|
if (
|
|
property === 'activeScene' ||
|
|
property === 'activeScenes' ||
|
|
property === 'activeRenderer'
|
|
) {
|
|
console.log('todo: active component update');
|
|
return;
|
|
}
|
|
|
|
if (
|
|
property === 'activeComposer'
|
|
) {
|
|
|
|
if (this.activeComposer === null) {
|
|
if (this.enableComposer) {
|
|
console.warn('no composer active - nothing will render');
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (
|
|
this.activeComposer.passes.length === 0
|
|
) {
|
|
console.warn('this composer has no passes - nothing will render when this composer is enabled');
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (
|
|
property === 'activeEffect'
|
|
) {
|
|
|
|
if (this.activeEffect === null) {
|
|
if (this.enableEffect) {
|
|
console.warn('no effects active - nothing will render');
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (
|
|
property === 'enableComposer'
|
|
) {
|
|
|
|
if (this.enableComposer) {
|
|
if (this.enableEffect) {
|
|
this.enableComposer = false;
|
|
console.warn('Only one of effect or composer can be enabled, not both at the same time');
|
|
return;
|
|
}
|
|
|
|
if (
|
|
this.activeComposer === null
|
|
) {
|
|
console.warn('no composer active - nothing will render');
|
|
return;
|
|
}
|
|
|
|
if (
|
|
this.activeComposer.passes.length === 0
|
|
) {
|
|
console.warn('this composer has no passes - nothing will render');
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (
|
|
property === 'enableEffect'
|
|
) {
|
|
|
|
if (this.enableEffect) {
|
|
if (this.enableComposer) {
|
|
this.enableEffect = false;
|
|
console.warn('Only one of effect or composer can be enabled, not both at the same time');
|
|
return;
|
|
}
|
|
|
|
if (this.activeEffect === null) {
|
|
console.warn('no effect active - nothing will render');
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (
|
|
property === 'defaultMode'
|
|
) {
|
|
console.log('todo: defaultMode change');
|
|
return;
|
|
}
|
|
|
|
R3.Component.prototype.updateInstance.call(this, property);
|
|
|
|
};
|
|
|
|
/**
|
|
*
|
|
* @returns {R3.API.RenderConfiguration}
|
|
*/
|
|
R3.RenderConfiguration.prototype.toApiObject = function() {
|
|
|
|
var apiRenderConfiguration = new R3.API.RenderConfiguration(
|
|
this.id,
|
|
this.name,
|
|
R3.Utils.IdOrNull(this.parentEntity),
|
|
this.logicalSize.toApiObject(),
|
|
this.aspectRatio,
|
|
this.scaleMode,
|
|
R3.Utils.IdOrNull(this.activeCamera),
|
|
R3.Utils.IdOrNull(this.activeScene),
|
|
this.activeScenes.map(
|
|
function(activeScene) {
|
|
return R3.Utils.IdOrNull(activeScene);
|
|
}
|
|
),
|
|
R3.Utils.IdOrNull(this.activeRenderer),
|
|
R3.Utils.IdOrNull(this.activeComposer),
|
|
R3.Utils.IdOrNull(this.activeEffect),
|
|
this.enableComposer,
|
|
this.enableEffect,
|
|
this.defaultMode
|
|
);
|
|
|
|
return apiRenderConfiguration;
|
|
};
|