body {
background-color: #000;
margin: 0px;
overflow: hidden;
}
JavaScript
// three.js info box follows shape
var renderer, scene, camera;
var angle = 0;
var position = 0;
// direction vector for movement
var direction = new THREE.Vector3(1, 0, 0);
var up = new THREE.Vector3(0, 0, 1);
var axis = new THREE.Vector3();
// scalar to simulate speed
var speed = 0.5;
init();
animate();
function init() {
// info
var info = document.createElement('div');
info.style.position = 'absolute';
info.style.top = '30px';
info.style.width = '100%';
info.style.textAlign = 'center';
info.style.color = '#fff';
info.style.fontWeight = 'bold';
info.style.backgroundColor = 'transparent';
info.style.zIndex = '1';
info.style.fontFamily = 'Monospace';
info.innerHTML = "three.js - move objects on and relative to a path ";
document.body.appendChild(info);
// renderer
renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// scene
scene = new THREE.Scene();
// ambient light
var ambient = new THREE.AmbientLight(0x404040);
scene.add(ambient);
// directional light
var directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
directionalLight.position.set(-1, -1, 1);
scene.add(directionalLight);
// camera
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.set(-100, -100, 20);
camera.up.set(0, 0, 1);
// controls
controls = new THREE.OrbitControls(camera);
controls.target = new THREE.Vector3(25, -25, 0);
controls.update();
// material
var material = new THREE.MeshPhongMaterial({
color: 0xff0000,
shading: THREE.FlatShading
});
// geometry
var geometry = new THREE.BoxGeometry(10, 10, 10);
// mesh
mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
mesh2 = mesh.clone();
scene.add( mesh2 );
// set a initial rotation
mesh2.rotation.z...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.