Custom Geometry

by jmcjc5u

HTML

<div id="info">Holographic Pyramid</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/107/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js">
</script>

CSS

#info {
  position: absolute;
  top: 3%;
  width: 100%;
  padding: 10px;
  text-align: center;
  color: #ffff00
}

body {
  overflow: hidden;
}

JavaScript

var camera, scene, renderer;
var l;

init();
animate();

function makeTrapezoid() {

  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.materialIndex = 0;
  geometry.faces.push(face);
  face = new THREE.Face3(1, 2, 3);
  face.materialIndex = 0;
  geometry.faces.push(face);

  geometry.computeBoundingSphere();
  geometry.computeFaceNormals();
  geometry.computeVertexNormals();

  return new THREE.Mesh(geometry, new THREE.MeshNormalMaterial({side:THREE.DoubleSide}) );
}

function init() {
  scene = new THREE.Scene();

  camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 1000);
  camera.position.z = 20;
  scene.add(camera);

	scene.add (new THREE.AxesHelper (10))
  renderer = new THREE.WebGLRenderer();
  renderer.setSize(window.innerWidth, window.innerHeight);
  renderer.setClearColor(0x888888);

  controls = new THREE.OrbitControls(camera, renderer.domElement);
  document.body.appendChild(renderer.domElement);
  window.addEventListener('resize', onWindowResize, false);

  //////////////////////////////////////////////////////////////
	l = Math.sqrt (4.5*4.5 - 2.5*2.5);
  theta = Math.acos (2.5/l);
  trape = makeTrapezoid ()
	scene.add( trape);
  trape.position.set (.5,0,0)
  trape.rotation.z = theta;
  
  trape = makeTrapezoid ()
	scene.add( trape);
  trape.position.set (-.5,0,0)
  trape.rotation.z = Math.PI-theta;
  
  trape = makeTrapezoid ()
	scene.add( trape);
  trape.position.set (0,0,-.5)
  trape.rotation.y = Math.PI/2; 
  trape.rotation.z = theta;

  trape = makeTrapezoid ()
	scene.add( trape);
  trape.position.set (0,0,.5)
  trape.rotation.y = -Math.PI/2; 
  trape.rotation.z = theta;
}

function onWindowResize() {
  camera.aspect = window.innerWidth / window.innerHeight;
  camera.updateProjectionMatrix();
 ...