You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
198 lines
3.9 KiB
198 lines
3.9 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>three.js webgl - dashed lines</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 {
|
|
color: #ffffff;
|
|
font-family:Monospace;
|
|
font-size:13px;
|
|
text-align:center;
|
|
font-weight: bold;
|
|
|
|
background-color: #000000;
|
|
margin: 0px;
|
|
overflow: hidden;
|
|
}
|
|
#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" rel="noopener">three.js</a> - dashed lines example</div>
|
|
<div id="container"></div>
|
|
|
|
<script src="../build/three.js"></script>
|
|
|
|
<script src="js/geometries/hilbert3D.js"></script>
|
|
|
|
<script src="js/WebGL.js"></script>
|
|
<script src="js/libs/stats.min.js"></script>
|
|
|
|
<script>
|
|
|
|
if ( WEBGL.isWebGLAvailable() === false ) {
|
|
|
|
document.body.appendChild( WEBGL.getWebGLErrorMessage() );
|
|
|
|
}
|
|
|
|
var renderer, scene, camera, stats;
|
|
var objects = [];
|
|
|
|
var WIDTH = window.innerWidth, HEIGHT = window.innerHeight;
|
|
|
|
init();
|
|
animate();
|
|
|
|
function init() {
|
|
|
|
camera = new THREE.PerspectiveCamera( 60, WIDTH / HEIGHT, 1, 200 );
|
|
camera.position.z = 150;
|
|
|
|
scene = new THREE.Scene();
|
|
scene.background = new THREE.Color( 0x111111 );
|
|
scene.fog = new THREE.Fog( 0x111111, 150, 200 );
|
|
|
|
var subdivisions = 6;
|
|
var recursion = 1;
|
|
|
|
var points = hilbert3D( new THREE.Vector3( 0, 0, 0 ), 25.0, recursion, 0, 1, 2, 3, 4, 5, 6, 7 );
|
|
var spline = new THREE.CatmullRomCurve3( points );
|
|
|
|
var samples = spline.getPoints( points.length * subdivisions );
|
|
var geometrySpline = new THREE.BufferGeometry().setFromPoints( samples );
|
|
|
|
var line = new THREE.Line( geometrySpline, new THREE.LineDashedMaterial( { color: 0xffffff, dashSize: 1, gapSize: 0.5 } ) );
|
|
line.computeLineDistances();
|
|
|
|
objects.push( line );
|
|
scene.add( line );
|
|
|
|
var geometryCube = cube( 50 );
|
|
|
|
var lineSegments = new THREE.LineSegments( geometryCube, new THREE.LineDashedMaterial( { color: 0xffaa00, dashSize: 3, gapSize: 1 } ) );
|
|
lineSegments.computeLineDistances();
|
|
|
|
objects.push( lineSegments );
|
|
scene.add( lineSegments );
|
|
|
|
renderer = new THREE.WebGLRenderer( { antialias: true } );
|
|
renderer.setPixelRatio( window.devicePixelRatio );
|
|
renderer.setSize( WIDTH, HEIGHT );
|
|
|
|
var container = document.getElementById( 'container' );
|
|
container.appendChild( renderer.domElement );
|
|
|
|
stats = new Stats();
|
|
container.appendChild( stats.dom );
|
|
|
|
//
|
|
|
|
window.addEventListener( 'resize', onWindowResize, false );
|
|
|
|
}
|
|
|
|
function cube( size ) {
|
|
|
|
var h = size * 0.5;
|
|
|
|
var geometry = new THREE.BufferGeometry();
|
|
var position = [];
|
|
|
|
position.push(
|
|
- h, - h, - h,
|
|
- h, h, - h,
|
|
|
|
- h, h, - h,
|
|
h, h, - h,
|
|
|
|
h, h, - h,
|
|
h, - h, - h,
|
|
|
|
h, - h, - h,
|
|
- h, - h, - h,
|
|
|
|
- h, - h, h,
|
|
- h, h, h,
|
|
|
|
- h, h, h,
|
|
h, h, h,
|
|
|
|
h, h, h,
|
|
h, - h, h,
|
|
|
|
h, - h, h,
|
|
- h, - h, h,
|
|
|
|
- h, - h, - h,
|
|
- h, - h, h,
|
|
|
|
- h, h, - h,
|
|
- h, h, h,
|
|
|
|
h, h, - h,
|
|
h, h, h,
|
|
|
|
h, - h, - h,
|
|
h, - h, h
|
|
);
|
|
|
|
geometry.addAttribute( 'position', new THREE.Float32BufferAttribute( position, 3 ) );
|
|
|
|
return geometry;
|
|
|
|
}
|
|
|
|
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.001;
|
|
|
|
scene.traverse( function ( object ) {
|
|
|
|
if ( object.isLine ) {
|
|
|
|
object.rotation.x = 0.25 * time;
|
|
object.rotation.y = 0.25 * time;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
renderer.render( scene, camera );
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|