36 lines
878 B
TypeScript
36 lines
878 B
TypeScript
import { PerspectiveCamera, Scene, Vector2, WebGLRenderer } from 'three';
|
|
|
|
export class Renderer {
|
|
public renderer = new WebGLRenderer();
|
|
public camera = new PerspectiveCamera(
|
|
75,
|
|
this.resolution.x / this.resolution.y,
|
|
0.1,
|
|
10000
|
|
);
|
|
public scene = new Scene();
|
|
|
|
constructor(
|
|
public viewport: HTMLElement,
|
|
public resolution = new Vector2(1080, 720)
|
|
) {
|
|
this.renderer.setSize(resolution.x, resolution.y);
|
|
viewport.appendChild(this.renderer.domElement);
|
|
}
|
|
|
|
setSize(width: number, height: number) {
|
|
this.resolution.set(width, height);
|
|
this.camera.aspect = this.resolution.x / this.resolution.y;
|
|
this.renderer.setSize(this.resolution.x, this.resolution.y);
|
|
this.camera.updateProjectionMatrix();
|
|
}
|
|
|
|
render() {
|
|
this.renderer.render(this.scene, this.camera);
|
|
}
|
|
|
|
cleanUp() {
|
|
this.renderer.dispose();
|
|
}
|
|
}
|