three.js dev template - module
CSS
body {
background-color: #000;
margin: 0px;
overflow: hidden;
}
JavaScript
import * as THREE from "https://cdn.jsdelivr.net/npm/three@0.119.1/build/three.module.js";
import { OrbitControls } from "https://cdn.jsdelivr.net/npm/three@0.119.1/examples/jsm/controls/OrbitControls.js";
var mesh, mesh2, renderer, scene, camera, controls;
init();
animate();
var count = 0;
function init() {
// renderer
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setPixelRatio( window.devicePixelRatio );
document.body.appendChild( renderer.domElement );
// scene
scene = new THREE.Scene();
// camera
camera = new THREE.OrthographicCamera( -window.innerWidth, window.innerWidth, window.innerWidth, -window.innerWidth, 0.0001, 10000);
camera.zoom = 50;
camera.up.set(0,1,0);
camera.position.set( 5,0,1);
camera.updateProjectionMatrix();
// controls
controls = new OrbitControls( camera, renderer.domElement );
controls.touches.ONE = THREE.TOUCH.PAN;
controls.touches.TWO = THREE.TOUCH.DOLLY_ROTATE;
controls.target.set(5,0,0);
// ambient
scene.add( new THREE.AmbientLight( 0x222222 ) );
// light
var light = new THREE.DirectionalLight( 0xffffff, 1 );
light.position.set( 20,20, 0 );
scene.add( light );
// axes
scene.add( new THREE.AxesHelper( 20 ) );
// geometry
var geometry = new THREE.PlaneGeometry( 5, 5);
// material
var material = new THREE.MeshPhongMaterial( {
color: 0x00ffff,
side: THREE.DoubleSide,
flatShading: true,
transparent: true,
opacity: 0.7,
} );
// mesh
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
var geometry2 = new THREE.PlaneGeometry( 3, 3);
var material2 = new THREE.MeshPhongMaterial( {
color: 0x00ffff,
side: THREE.DoubleSide,
flatShading: true,
transparent: true,
opacity: 0.7,
} );
mesh2 = new...