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.
135 lines
2.9 KiB
135 lines
2.9 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>three.js svg - 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">
|
|
<style>
|
|
svg {
|
|
display: block;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div id="info">
|
|
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> svg - lines
|
|
</div>
|
|
|
|
<!-- Import maps polyfill -->
|
|
<!-- Remove this when import maps will be widely supported -->
|
|
<script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>
|
|
|
|
<script type="importmap">
|
|
{
|
|
"imports": {
|
|
"three": "../build/three.module.js",
|
|
"three/addons/": "./jsm/"
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<script type="module">
|
|
|
|
import * as THREE from 'three';
|
|
|
|
import { SVGRenderer } from 'three/addons/renderers/SVGRenderer.js';
|
|
|
|
let camera, scene, renderer;
|
|
|
|
init();
|
|
animate();
|
|
|
|
function init() {
|
|
|
|
camera = new THREE.PerspectiveCamera( 33, window.innerWidth / window.innerHeight, 0.1, 100 );
|
|
camera.position.z = 10;
|
|
|
|
scene = new THREE.Scene();
|
|
scene.background = new THREE.Color( 0, 0, 0 );
|
|
|
|
renderer = new SVGRenderer();
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
document.body.appendChild( renderer.domElement );
|
|
|
|
//
|
|
|
|
const vertices = [];
|
|
const divisions = 50;
|
|
|
|
for ( let i = 0; i <= divisions; i ++ ) {
|
|
|
|
const v = ( i / divisions ) * ( Math.PI * 2 );
|
|
|
|
const x = Math.sin( v );
|
|
const z = Math.cos( v );
|
|
|
|
vertices.push( x, 0, z );
|
|
|
|
}
|
|
|
|
const geometry = new THREE.BufferGeometry();
|
|
geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
|
|
|
|
//
|
|
|
|
for ( let i = 1; i <= 3; i ++ ) {
|
|
|
|
const material = new THREE.LineBasicMaterial( {
|
|
color: Math.random() * 0xffffff,
|
|
linewidth: 10
|
|
} );
|
|
const line = new THREE.Line( geometry, material );
|
|
line.scale.setScalar( i / 3 );
|
|
scene.add( line );
|
|
|
|
}
|
|
|
|
const material = new THREE.LineDashedMaterial( {
|
|
color: 'blue',
|
|
linewidth: 1,
|
|
dashSize: 10,
|
|
gapSize: 10
|
|
} );
|
|
const line = new THREE.Line( geometry, material );
|
|
line.scale.setScalar( 2 );
|
|
scene.add( line );
|
|
|
|
//
|
|
|
|
window.addEventListener( 'resize', onWindowResize );
|
|
|
|
}
|
|
|
|
function onWindowResize() {
|
|
|
|
camera.aspect = window.innerWidth / window.innerHeight;
|
|
camera.updateProjectionMatrix();
|
|
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
|
}
|
|
|
|
function animate() {
|
|
|
|
let count = 0;
|
|
const time = performance.now() / 1000;
|
|
|
|
scene.traverse( function ( child ) {
|
|
|
|
child.rotation.x = count + ( time / 3 );
|
|
child.rotation.z = count + ( time / 4 );
|
|
|
|
count ++;
|
|
|
|
} );
|
|
|
|
renderer.render( scene, camera );
|
|
requestAnimationFrame( animate );
|
|
|
|
}
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|
|
|