Purpose :
- To simulate a reflective floor ( like this ) in three js.
Idea :
- Make the floor translucent by setting the opacity to 0.5.
- Place a Mirror under it to reflect the nets above it.
Expected Result :
- To see the reflection of the house through the floor mirror.
The resulting conclusion :
- Does not reflect the nets that are part of the house.
- Instead, it displays only the skybox, and it is also only at a certain angle.
Screenshots:
:
.......
.......
function getReflectiveFloorMesh(floorMesh) {
var WIDTH = window.innerWidth;
var HEIGHT = window.innerHeight;
floorMirror = new THREE.Mirror( renderer, firstPerson.camera,
{ clipBias: 0.003,
textureWidth: WIDTH,
textureHeight: HEIGHT,
color: 0x889999 } );
var mirrorMesh = floorMesh.clone();
mirrorMesh.position.y -= 10;
mirrorMesh.material = floorMirror.material;
mirrorMesh.material.side = THREE.BackSide;
mirrorMesh.material.needsUpdate = true;
mirrorMesh.add(floorMirror);
return mirrorMesh;
}
function getSkybox() {
var urlPrefix = "/img/skybox/sunset/";
var urls = [urlPrefix + "px.png", urlPrefix + "nx.png",
urlPrefix + "py.png", urlPrefix + "ny.png",
urlPrefix + "pz.png", urlPrefix + "nz.png"];
var textureCube = THREE.ImageUtils.loadTextureCube(urls);
var shader = THREE.ShaderLib["cube"];
shader.uniforms["tCube"].value = textureCube;
var material = new THREE.ShaderMaterial({
fragmentShader: shader.fragmentShader,
vertexShader: shader.vertexShader,
uniforms: shader.uniforms,
side: THREE.BackSide
});
var skyboxMesh = new THREE.Mesh(new THREE.CubeGeometry(10000, 10000, 10000, 1, 1, 1, null, true), material);
return skyboxMesh;
}
function setupScene(model, floor) {
scene.add(model);
scene.add(getSkybox());
scene.add(getReflectiveFloorMesh(floor));
scope.animate();
}
....
....
this.animate = function () {
if(floorMirror)
floorMirror.render();
renderer.render(scene, firstPerson.camera);
};