var camera, scene, light, renderer, geometry, material, mesh1, mesh2, gl;
var directionalLight;
var WIDTH = window.innerWidth - 20;
var HEIGHT = window.innerHeight - 20;
var controls;
var impostorMaterialCyl;
var impostorMaterialSphere;
createImpostorMaterial();
init();
animate();
function init() {
scene = new THREE.Scene();
var axisHelper = new THREE.AxisHelper( 1 );
scene.add( axisHelper );
camera = new THREE.PerspectiveCamera(50, WIDTH / HEIGHT, 5, 100);
camera.position.z = 10;
camera.position.y = 0;
var ambient = new THREE.AmbientLight( 0x404040 );
scene.add(ambient);
directionalLight = new THREE.DirectionalLight( 0xffffff, 1.0 );
directionalLight.position.set( 0, 15, 15 );
scene.add( directionalLight );
scene.add(camera);
// controls
controls = new THREE.OrbitControls( camera );
var geometry = createBufferGeometry();
geometry.addGroup(0, 2, 0);
geometry.addGroup(2, 2, 1);
var materials = new THREE.MultiMaterial([impostorMaterialCyl, impostorMaterialSphere]);
mesh1 = new THREE.Points(geometry, materials);
scene.add(mesh1);
renderer = new THREE.WebGLRenderer({ antialias: true, preserveDrawingBuffer: true});
renderer.setSize(WIDTH, HEIGHT);
renderer.setPixelRatio(window.devicePixelRatio);
renderer.autoClear = false;
renderer.sortObjects = true;
document.body.appendChild(renderer.domElement);
}
var previousTime;
function animate() {
requestAnimationFrame(animate);
var now = Date.now();
if (isNaN(previousTime)) {
previousTime = Date.now();
}
var time = (now - previousTime) * 0.0005;
previousTime = now;
var x = directionalLight.position.x;
var z = directionalLight.position.z;
directionalLight.position.x = x * Math.cos(time) - z * Math.sin(time);
directionalLight.position.z = z * Math.cos(time) + x * Math.sin(time);
render();
}
function render() {
// Clear...
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.