Try to simulate the “holographic pyramid”.
I only build one trapezoidal plane (by feeding the required vertices of the geometry).
The floor is a BIG plane geometry with checkerboard texture.
[Please check the gif: https://i.imgur.com/DHMDeGE.gif]
The reflections look OK in some angles, but for some viewing angles, the result is clearly wrong (as shown below, since the floor is quite large, compared to the mirror.)
The code as
`
import * as THREE from ‘https://raw.githack.com/mrdoob/three.js/dev/build/three.module.js’;
import { OrbitControls } from 'https://raw.githack.com/mrdoob/three.js/dev/examples/jsm/controls/OrbitControls.js';
import { Reflector } from 'https://raw.githack.com/mrdoob/three.js/dev/examples/jsm/objects/Reflector.js';
var scene, renderer, camera;
var WIDTH, HEIGHT;
init();
animate();
function makeTrapezoid(l) {
var geometry = new THREE.Geometry();
geometry.vertices.push(
new THREE.Vector3(0, 0, .5),
new THREE.Vector3(l, 0, 3),
new THREE.Vector3(l, 0, -3),
new THREE.Vector3(0, 0, -.5)
);
var face;
//face = new THREE.Face3(0, 1, 3);
face = new THREE.Face3(0, 3, 1);
face.materialIndex = 0;
geometry.faces.push(face);
//face = new THREE.Face3(1, 2, 3);
face = new THREE.Face3(1, 3, 2);
face.materialIndex = 0;
geometry.faces.push(face);
var verticalMirror = new Reflector( geometry,
{
clipBias: 0.003,
textureWidth: WIDTH * window.devicePixelRatio,
textureHeight: HEIGHT * window.devicePixelRatio,
color: 0x999999,
recursion: 1
} );
return verticalMirror;
}
function init() {
scene = new THREE.Scene();
renderer = new THREE.WebGLRenderer();
WIDTH = window.innerWidth;
HEIGHT = window.innerHeight;
renderer.setSize(WIDTH, HEIGHT);
renderer.setClearColor(0x888888);
document.body.appendChild(renderer.domElement);
camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 3000);
camera.position.z = 50;
let controls = new OrbitControls(camera, renderer.domElement);
window.addEventListener('resize', onWindowResize, false);
scene.add (new THREE.AxesHelper(10));
var l = Math.sqrt (4.5 *4.5 - 2.5* 2.5);
var theta = Math.acos (2.5/l);
var trape;
trape = makeTrapezoid (l)
scene.add( trape);
trape.position.set (.5,0,0)
trape.rotation.z = theta;
let loader = new THREE.TextureLoader();
let tex = loader.load ("https://i.imgur.com/p8CRm9W.jpg");
tex.repeat.set (10,10);
tex.wrapS = tex.wrapT = THREE.RepeatWrapping;
let floor = new THREE.Mesh (new THREE.PlaneGeometry (100,100),
new THREE.MeshBasicMaterial({map: tex}));
floor.rotation.x = -Math.PI/2;
scene.add (floor);
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
`
Three.js version
- [x ] Dev
- r106
- …
Browser
- All of them
- Chrome
- Firefox
- Internet Explorer
OS
- All of them
- Windows
- [ x] macOS
- Linux
- Android
- iOS