cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
71 lines (70 loc) • 2.4 kB
JavaScript
import Base from "../core/Base.mjs";
import Vector3 from "../math/Vector3.mjs";
import PerspectiveCamera from "../camera/Perspective.mjs";
import FrameBuffer from "../FrameBuffer.mjs";
var targets = ["px", "nx", "py", "ny", "pz", "nz"];
var EnvironmentMapPass = Base.extend(function() {
var ret = {
position: new Vector3(),
far: 1e3,
near: 0.1,
texture: null,
shadowMapPass: null
};
var cameras = ret._cameras = {
px: new PerspectiveCamera({ fov: 90 }),
nx: new PerspectiveCamera({ fov: 90 }),
py: new PerspectiveCamera({ fov: 90 }),
ny: new PerspectiveCamera({ fov: 90 }),
pz: new PerspectiveCamera({ fov: 90 }),
nz: new PerspectiveCamera({ fov: 90 })
};
cameras.px.lookAt(Vector3.POSITIVE_X, Vector3.NEGATIVE_Y);
cameras.nx.lookAt(Vector3.NEGATIVE_X, Vector3.NEGATIVE_Y);
cameras.py.lookAt(Vector3.POSITIVE_Y, Vector3.POSITIVE_Z);
cameras.ny.lookAt(Vector3.NEGATIVE_Y, Vector3.NEGATIVE_Z);
cameras.pz.lookAt(Vector3.POSITIVE_Z, Vector3.NEGATIVE_Y);
cameras.nz.lookAt(Vector3.NEGATIVE_Z, Vector3.NEGATIVE_Y);
ret._frameBuffer = new FrameBuffer();
return ret;
}, {
getCamera: function(target) {
return this._cameras[target];
},
render: function(renderer, scene, notUpdateScene) {
var _gl = renderer.gl;
if (!notUpdateScene) {
scene.update();
}
var n = this.texture.width;
var fov = 2 * Math.atan(n / (n - 0.5)) / Math.PI * 180;
for (var i = 0; i < 6; i++) {
var target = targets[i];
var camera = this._cameras[target];
Vector3.copy(camera.position, this.position);
camera.far = this.far;
camera.near = this.near;
camera.fov = fov;
if (this.shadowMapPass) {
camera.update();
var bbox = scene.getBoundingBox();
bbox.applyTransform(camera.viewMatrix);
scene.viewBoundingBoxLastFrame.copy(bbox);
this.shadowMapPass.render(renderer, scene, camera, true);
}
this._frameBuffer.attach(
this.texture,
_gl.COLOR_ATTACHMENT0,
_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i
);
this._frameBuffer.bind(renderer);
renderer.render(scene, camera, true);
this._frameBuffer.unbind(renderer);
}
},
dispose: function(renderer) {
this._frameBuffer.dispose(renderer);
}
});
var EnvironmentMapPass$1 = EnvironmentMapPass;
export { EnvironmentMapPass$1 as default };