mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-16 11:07:57 +01:00
190 lines
4.2 KiB
HTML
190 lines
4.2 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<title>three.js webgl - particles - billboards</title>
|
||
|
<meta charset="utf-8">
|
||
|
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
||
|
<style>
|
||
|
body {
|
||
|
background-color: #000000;
|
||
|
margin: 0px;
|
||
|
overflow: hidden;
|
||
|
font-family:Monospace;
|
||
|
font-size:13px;
|
||
|
text-align:center;
|
||
|
font-weight: bold;
|
||
|
text-align:center;
|
||
|
}
|
||
|
|
||
|
a {
|
||
|
color:#0078ff;
|
||
|
}
|
||
|
|
||
|
#info {
|
||
|
color:#fff;
|
||
|
position: absolute;
|
||
|
top: 0px; width: 100%;
|
||
|
padding: 5px;
|
||
|
z-index:100;
|
||
|
}
|
||
|
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
<div id="info">
|
||
|
<a href="http://threejs.org" target="_blank">three.js</a> - webgl particle billboards example
|
||
|
</div>
|
||
|
|
||
|
<script src="../build/three.min.js"></script>
|
||
|
|
||
|
<script src="js/Detector.js"></script>
|
||
|
<script src="js/libs/stats.min.js"></script>
|
||
|
|
||
|
<script>
|
||
|
|
||
|
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
|
||
|
|
||
|
var container, stats;
|
||
|
var camera, scene, renderer, particles, geometry, material, i, h, color, sprite, size;
|
||
|
var mouseX = 0, mouseY = 0;
|
||
|
|
||
|
var windowHalfX = window.innerWidth / 2;
|
||
|
var windowHalfY = window.innerHeight / 2;
|
||
|
|
||
|
init();
|
||
|
animate();
|
||
|
|
||
|
function init() {
|
||
|
|
||
|
container = document.createElement( 'div' );
|
||
|
document.body.appendChild( container );
|
||
|
|
||
|
camera = new THREE.PerspectiveCamera( 55, window.innerWidth / window.innerHeight, 2, 2000 );
|
||
|
camera.position.z = 1000;
|
||
|
|
||
|
scene = new THREE.Scene();
|
||
|
scene.fog = new THREE.FogExp2( 0x000000, 0.001 );
|
||
|
|
||
|
geometry = new THREE.Geometry();
|
||
|
|
||
|
sprite = THREE.ImageUtils.loadTexture( "textures/sprites/disc.png" );
|
||
|
|
||
|
for ( i = 0; i < 10000; i ++ ) {
|
||
|
|
||
|
var vertex = new THREE.Vector3();
|
||
|
vertex.x = 2000 * Math.random() - 1000;
|
||
|
vertex.y = 2000 * Math.random() - 1000;
|
||
|
vertex.z = 2000 * Math.random() - 1000;
|
||
|
|
||
|
geometry.vertices.push( vertex );
|
||
|
|
||
|
}
|
||
|
|
||
|
material = new THREE.PointCloudMaterial( { size: 35, sizeAttenuation: false, map: sprite, alphaTest: 0.5, transparent: true } );
|
||
|
material.color.setHSL( 1.0, 0.3, 0.7 );
|
||
|
|
||
|
particles = new THREE.PointCloud( geometry, material );
|
||
|
scene.add( particles );
|
||
|
|
||
|
//
|
||
|
|
||
|
renderer = new THREE.WebGLRenderer();
|
||
|
renderer.setPixelRatio( window.devicePixelRatio );
|
||
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
||
|
container.appendChild( renderer.domElement );
|
||
|
|
||
|
//
|
||
|
|
||
|
stats = new Stats();
|
||
|
stats.domElement.style.position = 'absolute';
|
||
|
stats.domElement.style.top = '0px';
|
||
|
container.appendChild( stats.domElement );
|
||
|
|
||
|
//
|
||
|
|
||
|
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
|
||
|
document.addEventListener( 'touchstart', onDocumentTouchStart, false );
|
||
|
document.addEventListener( 'touchmove', onDocumentTouchMove, false );
|
||
|
|
||
|
//
|
||
|
|
||
|
window.addEventListener( 'resize', onWindowResize, false );
|
||
|
|
||
|
}
|
||
|
|
||
|
function onWindowResize() {
|
||
|
|
||
|
windowHalfX = window.innerWidth / 2;
|
||
|
windowHalfY = window.innerHeight / 2;
|
||
|
|
||
|
camera.aspect = window.innerWidth / window.innerHeight;
|
||
|
camera.updateProjectionMatrix();
|
||
|
|
||
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
||
|
|
||
|
}
|
||
|
|
||
|
function onDocumentMouseMove( event ) {
|
||
|
|
||
|
mouseX = event.clientX - windowHalfX;
|
||
|
mouseY = event.clientY - windowHalfY;
|
||
|
|
||
|
}
|
||
|
|
||
|
function onDocumentTouchStart( event ) {
|
||
|
|
||
|
if ( event.touches.length == 1 ) {
|
||
|
|
||
|
event.preventDefault();
|
||
|
|
||
|
mouseX = event.touches[ 0 ].pageX - windowHalfX;
|
||
|
mouseY = event.touches[ 0 ].pageY - windowHalfY;
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function onDocumentTouchMove( event ) {
|
||
|
|
||
|
if ( event.touches.length == 1 ) {
|
||
|
|
||
|
event.preventDefault();
|
||
|
|
||
|
mouseX = event.touches[ 0 ].pageX - windowHalfX;
|
||
|
mouseY = event.touches[ 0 ].pageY - windowHalfY;
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
//
|
||
|
|
||
|
function animate() {
|
||
|
|
||
|
requestAnimationFrame( animate );
|
||
|
|
||
|
render();
|
||
|
stats.update();
|
||
|
|
||
|
}
|
||
|
|
||
|
function render() {
|
||
|
|
||
|
var time = Date.now() * 0.00005;
|
||
|
|
||
|
camera.position.x += ( mouseX - camera.position.x ) * 0.05;
|
||
|
camera.position.y += ( - mouseY - camera.position.y ) * 0.05;
|
||
|
|
||
|
camera.lookAt( scene.position );
|
||
|
|
||
|
h = ( 360 * ( 1.0 + time ) % 360 ) / 360;
|
||
|
material.color.setHSL( h, 0.5, 0.5 );
|
||
|
|
||
|
renderer.render( scene, camera );
|
||
|
|
||
|
}
|
||
|
|
||
|
</script>
|
||
|
</body>
|
||
|
</html>
|