mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-26 23:44:56 +01:00
234 lines
5.7 KiB
HTML
234 lines
5.7 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<title>three.js svg - sandbox</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: #ffffff;
|
||
|
margin: 0px;
|
||
|
overflow: hidden;
|
||
|
}
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
<script src="../build/three.min.js"></script>
|
||
|
|
||
|
<script src="js/renderers/Projector.js"></script>
|
||
|
<script src="js/renderers/SVGRenderer.js"></script>
|
||
|
<script src="js/libs/stats.min.js"></script>
|
||
|
|
||
|
<script src="obj/Qrcode.js"></script>
|
||
|
|
||
|
<script>
|
||
|
|
||
|
var AMOUNT = 100;
|
||
|
|
||
|
var stats;
|
||
|
|
||
|
var camera, scene;
|
||
|
var renderer;
|
||
|
|
||
|
var mesh, group;
|
||
|
|
||
|
init();
|
||
|
animate();
|
||
|
|
||
|
function init() {
|
||
|
|
||
|
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
|
||
|
camera.position.z = 500;
|
||
|
|
||
|
scene = new THREE.Scene();
|
||
|
|
||
|
// QRCODE
|
||
|
|
||
|
mesh = new THREE.Mesh( new Qrcode(), new THREE.MeshLambertMaterial( { /*emissive: 0xff0000,*/ vertexColors: THREE.FaceColors } ) );
|
||
|
mesh.scale.x = mesh.scale.y = mesh.scale.z = 2;
|
||
|
scene.add( mesh );
|
||
|
|
||
|
// CUBES
|
||
|
|
||
|
var cube = new THREE.BoxGeometry( 100, 100, 100 );
|
||
|
|
||
|
mesh = new THREE.Mesh( cube, new THREE.MeshBasicMaterial( { color: 0x0000ff, opacity: 0.5, transparent: true } ) );
|
||
|
mesh.position.x = 500;
|
||
|
mesh.rotation.x = Math.random();
|
||
|
mesh.rotation.y = Math.random();
|
||
|
mesh.scale.x = mesh.scale.y = mesh.scale.z = 2;
|
||
|
scene.add( mesh );
|
||
|
|
||
|
mesh = new THREE.Mesh( cube, new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } ) );
|
||
|
mesh.position.x = 500;
|
||
|
mesh.position.y = 500;
|
||
|
mesh.rotation.x = Math.random();
|
||
|
mesh.rotation.y = Math.random();
|
||
|
mesh.scale.x = mesh.scale.y = mesh.scale.z = 2;
|
||
|
scene.add( mesh );
|
||
|
|
||
|
// PLANE
|
||
|
|
||
|
mesh = new THREE.Mesh( new THREE.PlaneBufferGeometry( 100, 100 ), new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, side: THREE.DoubleSide } ) );
|
||
|
mesh.position.y = -500;
|
||
|
mesh.scale.x = mesh.scale.y = mesh.scale.z = 2;
|
||
|
scene.add( mesh );
|
||
|
|
||
|
// CYLINDER
|
||
|
|
||
|
mesh = new THREE.Mesh( new THREE.CylinderGeometry( 20, 100, 200, 10 ), new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } ) );
|
||
|
mesh.position.x = -500;
|
||
|
mesh.rotation.x = - Math.PI / 2;
|
||
|
mesh.scale.x = mesh.scale.y = mesh.scale.z = 2;
|
||
|
scene.add( mesh );
|
||
|
|
||
|
// POLYFIELD
|
||
|
|
||
|
var geometry = new THREE.Geometry();
|
||
|
var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, side: THREE.DoubleSide } );
|
||
|
|
||
|
for ( var i = 0; i < 100; i ++ ) {
|
||
|
|
||
|
var v = new THREE.Vector3(
|
||
|
Math.random() * 1000 - 500,
|
||
|
Math.random() * 1000 - 500,
|
||
|
Math.random() * 1000 - 500
|
||
|
);
|
||
|
|
||
|
var v0 = new THREE.Vector3(
|
||
|
Math.random() * 100 - 50,
|
||
|
Math.random() * 100 - 50,
|
||
|
Math.random() * 100 - 50
|
||
|
);
|
||
|
|
||
|
var v1 = new THREE.Vector3(
|
||
|
Math.random() * 100 - 50,
|
||
|
Math.random() * 100 - 50,
|
||
|
Math.random() * 100 - 50
|
||
|
);
|
||
|
|
||
|
var v2 = new THREE.Vector3(
|
||
|
Math.random() * 100 - 50,
|
||
|
Math.random() * 100 - 50,
|
||
|
Math.random() * 100 - 50
|
||
|
);
|
||
|
|
||
|
v0.add( v );
|
||
|
v1.add( v );
|
||
|
v2.add( v );
|
||
|
|
||
|
var face = new THREE.Face3(
|
||
|
geometry.vertices.push( v0 ) - 1,
|
||
|
geometry.vertices.push( v1 ) - 1,
|
||
|
geometry.vertices.push( v2 ) - 1,
|
||
|
null,
|
||
|
new THREE.Color( Math.random() * 0xffffff )
|
||
|
);
|
||
|
|
||
|
geometry.faces.push( face );
|
||
|
|
||
|
}
|
||
|
|
||
|
geometry.computeFaceNormals();
|
||
|
|
||
|
group = new THREE.Mesh( geometry, material );
|
||
|
group.scale.set( 2, 2, 2 );
|
||
|
scene.add( group );
|
||
|
|
||
|
// SPRITES
|
||
|
|
||
|
for ( var i = 0; i < 50; i ++ ) {
|
||
|
|
||
|
var material = new THREE.SpriteMaterial( { color: Math.random() * 0xffffff } );
|
||
|
var sprite = new THREE.Sprite( material );
|
||
|
sprite.position.x = Math.random() * 1000 - 500;
|
||
|
sprite.position.y = Math.random() * 1000 - 500;
|
||
|
sprite.position.z = Math.random() * 1000 - 500;
|
||
|
sprite.scale.set( 64, 64, 1 );
|
||
|
scene.add( sprite );
|
||
|
|
||
|
}
|
||
|
|
||
|
// CUSTOM
|
||
|
|
||
|
var node = document.createElementNS( 'http://www.w3.org/2000/svg', 'circle' );
|
||
|
node.setAttribute( 'stroke', 'black' );
|
||
|
node.setAttribute( 'fill', 'red' );
|
||
|
node.setAttribute( 'r', '40' );
|
||
|
|
||
|
for ( var i = 0; i < 50; i ++ ) {
|
||
|
|
||
|
var object = new THREE.SVGObject( node.cloneNode() );
|
||
|
object.position.x = Math.random() * 1000 - 500;
|
||
|
object.position.y = Math.random() * 1000 - 500;
|
||
|
object.position.z = Math.random() * 1000 - 500;
|
||
|
scene.add( object );
|
||
|
|
||
|
}
|
||
|
|
||
|
// LIGHTS
|
||
|
|
||
|
var ambient = new THREE.AmbientLight( 0x80ffff );
|
||
|
scene.add( ambient );
|
||
|
|
||
|
var directional = new THREE.DirectionalLight( 0xffff00 );
|
||
|
directional.position.set( - 1, 0.5, 0 );
|
||
|
scene.add( directional );
|
||
|
|
||
|
renderer = new THREE.SVGRenderer();
|
||
|
renderer.setClearColor( 0xf0f0f0 );
|
||
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
||
|
renderer.setQuality( 'low' );
|
||
|
document.body.appendChild( renderer.domElement );
|
||
|
|
||
|
stats = new Stats();
|
||
|
stats.domElement.style.position = 'absolute';
|
||
|
stats.domElement.style.top = '0px';
|
||
|
document.body.appendChild( stats.domElement );
|
||
|
|
||
|
//
|
||
|
|
||
|
window.addEventListener( 'resize', onWindowResize, false );
|
||
|
|
||
|
}
|
||
|
|
||
|
function onWindowResize() {
|
||
|
|
||
|
camera.aspect = window.innerWidth / window.innerHeight;
|
||
|
camera.updateProjectionMatrix();
|
||
|
|
||
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
||
|
|
||
|
}
|
||
|
|
||
|
//
|
||
|
|
||
|
function animate() {
|
||
|
|
||
|
requestAnimationFrame( animate );
|
||
|
|
||
|
render();
|
||
|
stats.update();
|
||
|
|
||
|
}
|
||
|
|
||
|
function render() {
|
||
|
|
||
|
var time = Date.now() * 0.0002;
|
||
|
|
||
|
camera.position.x = Math.sin( time ) * 500;
|
||
|
camera.position.z = Math.cos( time ) * 500;
|
||
|
camera.lookAt( scene.position );
|
||
|
|
||
|
group.rotation.x += 0.01;
|
||
|
|
||
|
renderer.render( scene, camera );
|
||
|
|
||
|
}
|
||
|
|
||
|
</script>
|
||
|
|
||
|
</body>
|
||
|
</html>
|