-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcube.html
More file actions
61 lines (54 loc) · 1.56 KB
/
Copy pathcube.html
File metadata and controls
61 lines (54 loc) · 1.56 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>THREE.JS Cube</title>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three/build/three.module.js",
"three/addons/": "https://unpkg.com/three/examples/jsm/"
}
}
</script>
<style>
canvas {
width: 600px;
height: 450px;
background-color: black;
}
</style>
</head>
<body>
<canvas></canvas>
<script type="module">
import * as THREE from 'three'
const canvas = document.querySelector('canvas')
const renderer = new THREE.WebGLRenderer({
antialias: true,
canvas
})
const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera(75, 600 / 450, 0.1, 5)
camera.position.z = 4
camera.position.y = -1.5
const light = new THREE.DirectionalLight(0xffffff, 3)
light.position.set(3, 3, 3)
scene.add(light)
const ambient = new THREE.AmbientLight(0x404040)
scene.add(ambient)
const geometry = new THREE.BoxGeometry(1, 1, 1)
const material = new THREE.MeshPhongMaterial({ color: 0xff8080 })
const cube = new THREE.Mesh(geometry, material)
scene.add(cube)
function render(time) {
time /= 1000
cube.rotation.y = time
cube.rotation.x = time
renderer.render(scene, camera)
requestAnimationFrame(render)
}
render(0)
</script>
</body>
</html>