r3-legacy/bak/r3-d3-sky-box.js

70 lines
2.3 KiB
JavaScript

R3.D3.SkyBox = function (
graphics
) {
this.id = null;
this.graphics = graphics;
this.graphics.isNotThreeThrow();
this.texturesFolder = null;
};
R3.D3.SkyBox.prototype.load = function (
texturesFolder
) {
this.texturesFolder = texturesFolder;
this.textures = [];
this.materials = [];
this.mesh = {};
this.scene = new this.graphics.instance.Scene();
this.textureCube = null;
var textureLoader = new this.graphics.instance.TextureLoader();
// this textures are used to display the skybox
this.textures.push(textureLoader.load(this.texturesFolder + "px.png"));
this.textures.push(textureLoader.load(this.texturesFolder + "nx.png"));
this.textures.push(textureLoader.load(this.texturesFolder + "py.png"));
this.textures.push(textureLoader.load(this.texturesFolder + "ny.png"));
this.textures.push(textureLoader.load(this.texturesFolder + "pz.png"));
this.textures.push(textureLoader.load(this.texturesFolder + "nz.png"));
// assign textures to each cube face
for (var i = 0; i < 6; i ++) {
this.materials.push(new this.graphics.instance.MeshBasicMaterial({ map: this.textures[i] }));
}
// create cube geometry
this.mesh = new this.graphics.instance.Mesh(new this.graphics.instance.CubeGeometry(1, 1, 1), new this.graphics.instance.MeshFaceMaterial(this.materials));
this.mesh.applyMatrix(new this.graphics.instance.Matrix4().makeScale(1, 1, -1));
this.scene.add(this.mesh);
// Load env textureCube
// this is used for reflections on meshes
// mesh.material.envMap = this.textureCube;
this.textureCube = new this.graphics.instance.CubeTextureLoader().load([
this.texturesFolder + "px.png", this.texturesFolder + "nx.png",
this.texturesFolder + "py.png", this.texturesFolder + "ny.png",
this.texturesFolder + "pz.png", this.texturesFolder + "nz.png"
]);
};
R3.D3.SkyBox.prototype.render = function (
threeRenderer,
threeCamera
) {
var cameraPosition = new this.graphics.instance.Vector3(threeCamera.position.x, threeCamera.position.y, threeCamera.position.z);
threeCamera.position.set(0, 0, 0);
var gl = threeRenderer.context;
gl.disable(gl.DEPTH_TEST);
threeRenderer.render(this.scene, threeCamera);
gl.enable(gl.DEPTH_TEST);
threeCamera.position.copy(cameraPosition);
};