This repository has been archived on 2022-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
GeometryDash3D/js/Env.js

78 lines
1.7 KiB
JavaScript
Raw Normal View History

import { Element } from "./Element.js";
export class Quality {
static ultra = 1;
static medium = 2;
static low = 3;
}
export class Env {
constructor() {
this.scene = new THREE.Scene();
this.camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
1,
1000
);
this.camera.position.z = 5;
this.renderer = new THREE.WebGLRenderer();
this.renderer.setSize(window.innerWidth, window.innerHeight);
// Modification of the scene scale without modifying the size
this.quality = Quality.ultra;
this.renderer.setSize(
window.innerWidth / this.quality,
window.innerHeight / this.quality,
false
);
}
/**
* Get the Canvas element
* @returns domElement
*/
getDomElement = () => this.renderer.domElement;
/**
* Get current scene
* @returns Scene
*/
getScene = () => this.scene;
/**
* Get used camera
* @returns Camera
*/
getCamera = () => this.camera;
/**
* Get current renderer
* @returns Render
*/
getRenderer = () => this.renderer;
/**
* Change the quality of the render
* @param {Quality} quality
* @returns
*/
setQuality = (quality) => (this.quality = quality);
/**
* Add an element to the scene
* @param {Element} element Element
*/
addToScene = (element) => {
this.scene.add(element.data);
};
/**
* Render the current scene, using the camera
* @returns
*/
render = () => this.renderer.render(this.scene, this.camera);
}