JSFiddle - React, Tailwind, and code Playground
by kalverk
HTML
<script src="http://threejs.org/build/three.min.js"></script>
CSS
body {
background-color: #000;
margin: 0px;
overflow: hidden;
}
JavaScript
// three.js animataed line using BufferGeometry and drawcalls
var renderer, scene, camera;
var line,lines;
var MAX_POINTS = 500;
var drawCount;
var mousePosition = new THREE.Vector3(0, 0, 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 animataed line using BufferGeometry and drawcalls";
document.body.appendChild( info );
// renderer
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
// scene
scene = new THREE.Scene();
// camera
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.set( 0, 0, 1000 );
// geometry
var geometry = new THREE.BufferGeometry();
// attributes
var positions = new Float32Array( MAX_POINTS * 3 ); // 3 vertices per point
geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
// drawcalls
drawCount = 2; // draw the first 2 points, only
geometry.addDrawCall( 0, drawCount, 0 );
// material
var material = new THREE.LineBasicMaterial( { color: 0xff0000, linewidth: 2 } );
material.originalColor = material.color;
// line
lines = new THREE.Object3D();
line = new THREE.Line( geometry, material );
lines.add(line);
scene.add(lines);
document.onmousemove = function(event){
mousePosition.x = 2 * (event.clientX / window.innerWidth) - 1;
mousePosition.y = 1 - 2 * ( event.clientY / window.innerHeight);
mousePosition.unproject(camera);
var raycaster = new...