-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewport.js
More file actions
43 lines (30 loc) · 941 Bytes
/
Viewport.js
File metadata and controls
43 lines (30 loc) · 941 Bytes
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
import * as THREE from 'three'
export default class Viewport {
constructor (canvas, scene) {
this.width = null
this.height = null
this.aspectRatio = null
this.canvas = canvas
this.renderer = new THREE.WebGLRenderer({ canvas })
this.renderer.setPixelRatio(window.devicePixelRatio);
this.scene = scene
this.camera = new THREE.PerspectiveCamera(50, 1, 1, 2000);
this.camera.position.set(4, 8, 10);
this.resize()
}
resize () {
this.canvas.style.width = ''
this.canvas.style.height = ''
this.width = this.canvas.offsetWidth
this.height = this.canvas.offsetHeight
this.renderer.setSize(this.width, this.height)
this.aspectRatio = this.width / this.height
this.camera.aspect = this.aspectRatio
this.camera.updateProjectionMatrix()
this.render()
}
render () {
this.renderer.render(this.scene, this.camera)
return this.renderer.info;
}
}