custom geometry

by jmcjc5u

HTML

<div id="info">
  custom geometry
</div>

CSS

body {
	  background-color: #fff;
	  color: #111;
	  margin: 0px;
	  overflow: hidden;
	  font-family: Monospace;
	  font-size: 20px;
	  position: absolute;
	}

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

JavaScript

import * as THREE from "https://threejs.org/build/three.module.js";
import { OrbitControls } from "https://threejs.org/examples/jsm/controls/OrbitControls.js";

var scene, renderer, camera;

init();
animate();

function init() {
  var width = window.innerWidth;
  var height = window.innerHeight;

  renderer = new THREE.WebGLRenderer({
    antialias: true
  });
  renderer.setSize(width, height);
  renderer.setClearColor(0x888888);

  document.body.appendChild(renderer.domElement);

  scene = new THREE.Scene();

  camera = new THREE.PerspectiveCamera(45, width / height, 1, 10000);
  camera.position.y = 160;
  camera.position.z = 400;
  camera.lookAt(new THREE.Vector3(0, 0, 0));

  let controls = new OrbitControls(camera, renderer.domElement);

  var gridXZ = new THREE.GridHelper(200, 20, 'red', 'white');
  scene.add(gridXZ);

  var pointLight = new THREE.PointLight(0xffffff);
  pointLight.position.set(0, 300, 200);
  scene.add(pointLight);

  var ambientLight = new THREE.AmbientLight(0x111111);
  scene.add(ambientLight);

  window.addEventListener('resize', onWindowResize, false);

  //////////////////////////////////////////////////////////
  let points = []
  points.push(
    new THREE.Vector3(-5, 0, 3),
    new THREE.Vector3(5, 0, 3),
    new THREE.Vector3(5, 0, -3),
    new THREE.Vector3(-5, 0, -3),
    new THREE.Vector3(5, 10, 0),
    new THREE.Vector3(-5, 10, 0)
  );

  var geometry = new THREE.BufferGeometry().setFromPoints(points);

	var face;
  face = new THREE.Face3(0, 1, 5); face.materialIndex = 0;
  geometry.faces.push(face);
  face = new THREE.Face3(1, 4, 5); face.materialIndex = 0;
  geometry.faces.push(face);
  face = new THREE.Face3(3, 5, 4); face.materialIndex = 1;
  geometry.faces.push(face);
  face = new THREE.Face3(2, 3, 4); face.materialIndex = 1;
  geometry.faces.push(face);

  face = new THREE.Face3(0, 3, 1); face.materialIndex = 3;
  geometry.faces.push(face);
  face = new THREE.Face3(1, 3, 2); face.materialIndex = 3;
 ...