r3-legacy/src/r3-api-project-d3-0.js

143 lines
3.9 KiB
JavaScript

/**
* R3.API.Project
* @param apiComponent
*
* @property renderers
* @property renderTargets
* @property cameras
* @property controls
* @property audios
*
* @constructor
*/
R3.API.Project.D3 = function(
apiComponent
) {
/**
* Override everything not coming from DB
*/
__API_COMPONENT__;
/**
* This means we need to construct the cameras first if they are not coming from the database
*/
if (R3.Utils.UndefinedOrNull(apiComponent.cameras)) {
var editCamera = new R3.D3.API.Camera.Perspective(
{
parent : this,
name : this.name + ' - Edit Camera'
}
);
var runCamera = new R3.D3.API.Camera.Perspective(
{
parent : this,
name : this.name + ' - Run Camera'
}
);
apiComponent.cameras = [editCamera, runCamera];
}
this.cameras = apiComponent.cameras;
if (R3.Utils.UndefinedOrNull(apiComponent.mouse)) {
apiComponent.mouse = new R3.API.Mouse(
{
parent: this,
name: this.name + ' - Mouse'
}
);
}
this.mouse = apiComponent.mouse;
if (R3.Utils.UndefinedOrNull(apiComponent.raycaster)) {
apiComponent.raycaster = new R3.D3.API.Raycaster(
{
parent: this,
name: this.name + ' - Raycaster'
}
);
}
this.raycaster = apiComponent.raycaster;
if (R3.Utils.UndefinedOrNull(apiComponent.clock)) {
apiComponent.clock = new R3.API.Clock(
{
parent: this,
name: this.name + ' - Clock'
}
);
}
this.clock = apiComponent.clock;
/**
* And we should also override here the renderers if they are not coming from the API
*/
if (R3.Utils.UndefinedOrNull(apiComponent.renderers)) {
apiComponent.renderers = [
new R3.API.Renderer.D3.Canvas(
{
parent : this,
name : this.name + ' - 3D Canvas Renderer'
}
)
];
}
this.renderers = apiComponent.renderers;
/**
* Now override the controls before initializing the other API properties
*/
if (R3.Utils.UndefinedOrNull(apiComponent.controls)) {
apiComponent.controls = [
new R3.API.Controls.Mouse(
{
parent : this,
name : this.name + ' - Mouse Controls',
canvas : this.renderers[0].canvas
}
),
new R3.API.Controls.Keyboard(
{
parent : this,
name : this.name + ' - Keyboard Controls',
canvas : this.renderers[0].canvas
}
),
new R3.API.Controls.Touch(
{
parent : this,
name : this.name + ' - Touch Controls',
canvas : this.renderers[0].canvas
}
),
new R3.API.Controls.D3.Orbit(
{
parent : this,
name : this.name + ' - Orbit Controls',
camera : this.cameras[0],
canvas : this.renderers[0].canvas
}
)
];
}
if (R3.Utils.UndefinedOrNull(apiComponent.renderTargets)) {
apiComponent.renderTargets = [];
}
this.renderTargets = apiComponent.renderTargets;
if (R3.Utils.UndefinedOrNull(apiComponent.audios)) {
apiComponent.audios = [];
}
this.audios = apiComponent.audios;
R3.API.Project.call(
this,
apiComponent
);
};
R3.API.Project.D3.prototype = Object.create(R3.API.Project.prototype);
R3.API.Project.D3.prototype.constructor = R3.API.Project.D3;