123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <!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">
- <link type="text/css" rel="stylesheet" href="main.css">
- </head>
- <body>
- <div id="info"><a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - dashed lines example</div>
- <div id="container"></div>
- <script type="module">
- import * as THREE from '../build/three.module.js';
- import Stats from './jsm/libs/stats.module.js';
- import { GeometryUtils } from './jsm/utils/GeometryUtils.js';
- 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 = GeometryUtils.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.setAttribute( '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>
|