forked from dav-leon/bimsc21-datamgmt-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
47 lines (32 loc) · 1.28 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// load three.js
import * as THREE from 'https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js'
// uncomment to load controls
import { OrbitControls } from 'https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/controls/OrbitControls.js'
// create a scene and a camera
const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 )
camera.position.z = 35
// create the renderer and add it to the html
const renderer = new THREE.WebGLRenderer()
renderer.setSize( window.innerWidth, window.innerHeight )
document.body.appendChild( renderer.domElement )
// Uncomment next line to add controls
const controls = new OrbitControls( camera, renderer.domElement );
// Create an object and add it to the scene:
// 1. Create the geometry:
const geometry = new THREE.TorusKnotBufferGeometry( 10, 3, 100, 16 )
// 2. Create the material:
const material = new THREE.MeshNormalMaterial()
// 3. Create the object
const torus = new THREE.Mesh( geometry, material )
// 4. Add it to the scene
scene.add( torus )
// Render
function animate() {
requestAnimationFrame( animate )
// rotate torus a little bit each frame
torus.rotation.x += 0.01
torus.rotation.y += 0.01
renderer.render( scene, camera )
}
animate()