131 lines
3.0 KiB
JavaScript
131 lines
3.0 KiB
JavaScript
/**
|
|
* GameLib.D3.Pass.Render
|
|
* @param graphics GameLib.GraphicsRuntime
|
|
* @param apiPassRender GameLib.D3.API.Pass.Render
|
|
* @constructor
|
|
*/
|
|
GameLib.D3.Pass.Render = function (
|
|
graphics,
|
|
apiPassRender
|
|
) {
|
|
|
|
this.graphics = graphics;
|
|
this.graphics.isNotThreeThrow();
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(apiPassRender)) {
|
|
apiPassRender = {
|
|
passType : GameLib.D3.API.Pass.PASS_TYPE_RENDER
|
|
};
|
|
}
|
|
|
|
GameLib.D3.API.Pass.Render.call(
|
|
this,
|
|
apiPassRender,
|
|
apiPassRender.scene,
|
|
apiPassRender.camera
|
|
);
|
|
|
|
if (this.scene instanceof GameLib.D3.API.Scene) {
|
|
this.scene = new GameLib.D3.Scene(
|
|
this.graphics,
|
|
this.scene
|
|
)
|
|
}
|
|
|
|
if (this.camera instanceof GameLib.D3.API.Camera) {
|
|
this.camera = new GameLib.D3.Camera(
|
|
this.graphics,
|
|
this.camera
|
|
)
|
|
}
|
|
|
|
GameLib.D3.Pass.call(
|
|
this,
|
|
this.graphics,
|
|
this
|
|
);
|
|
};
|
|
|
|
GameLib.D3.Pass.Render.prototype = Object.create(GameLib.D3.Pass.prototype);
|
|
GameLib.D3.Pass.Render.prototype.constructor = GameLib.D3.Pass.Render;
|
|
|
|
/**
|
|
* Create Pass.Render instance
|
|
* @returns {*}
|
|
*/
|
|
GameLib.D3.Pass.Render.prototype.createInstance = function() {
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(this.scene) ||
|
|
GameLib.Utils.UndefinedOrNull(this.scene.instance)
|
|
) {
|
|
console.warn('scene not ready');
|
|
return;
|
|
}
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(this.camera) ||
|
|
GameLib.Utils.UndefinedOrNull(this.camera.instance)
|
|
) {
|
|
console.warn('camera not ready');
|
|
return;
|
|
}
|
|
|
|
this.instance = new THREE.RenderPass(
|
|
this.scene.instance,
|
|
this.camera.instance
|
|
);
|
|
|
|
console.log('Constructed a render pass instance');
|
|
|
|
GameLib.D3.Pass.prototype.createInstance.call(this);
|
|
};
|
|
|
|
/**
|
|
* Update Pass.Render instance
|
|
*/
|
|
GameLib.D3.Pass.Render.prototype.updateInstance = function(property) {
|
|
|
|
if (property === 'scene') {
|
|
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
|
|
this.createInstance();
|
|
}
|
|
|
|
if (this.instance && this.scene.instance) {
|
|
this.instance.scene = this.scene.instance;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (property === 'camera') {
|
|
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
|
|
this.createInstance();
|
|
}
|
|
|
|
if (this.instance && this.camera.instance) {
|
|
this.instance.camera = this.camera.instance;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
GameLib.D3.Pass.prototype.updateInstance.call(this, property);
|
|
|
|
};
|
|
|
|
/**
|
|
* GameLib.D3.Pass.Render to GameLib.D3.API.Pass.Render
|
|
* @returns {GameLib.D3.API.Pass.Render}
|
|
*/
|
|
GameLib.D3.Pass.Render.prototype.toApiObject = function() {
|
|
|
|
var apiPass = GameLib.D3.Pass.prototype.toApiObject.call(this);
|
|
|
|
var apiRenderPass = new GameLib.D3.API.Pass.Render(
|
|
apiPass,
|
|
GameLib.Utils.IdOrNull(this.scene),
|
|
GameLib.Utils.IdOrNull(this.camera)
|
|
);
|
|
|
|
return apiRenderPass;
|
|
};
|