|
@@ -1,19 +1,33 @@
|
|
|
export class space_scene {
|
|
export class space_scene {
|
|
|
|
|
+ #manager;
|
|
|
#renderer;
|
|
#renderer;
|
|
|
- #canvas;
|
|
|
|
|
#camera;
|
|
#camera;
|
|
|
#scene;
|
|
#scene;
|
|
|
#working;
|
|
#working;
|
|
|
#framerate;
|
|
#framerate;
|
|
|
|
|
|
|
|
- constructor(canvas, context) {
|
|
|
|
|
- this.#framerate = 30;
|
|
|
|
|
- this.#canvas = canvas;
|
|
|
|
|
|
|
+ constructor(manager) {
|
|
|
|
|
+ this.#manager = manager;
|
|
|
|
|
+
|
|
|
|
|
+ const canvas = manager.canvas;
|
|
|
|
|
+ const context = manager.context;
|
|
|
|
|
+
|
|
|
|
|
+ this.#framerate = 60;
|
|
|
this.#renderer = new THREE.WebGLRenderer({canvas, context: context});
|
|
this.#renderer = new THREE.WebGLRenderer({canvas, context: context});
|
|
|
this.#camera = new THREE.PerspectiveCamera(75, 1);
|
|
this.#camera = new THREE.PerspectiveCamera(75, 1);
|
|
|
this.#scene = new THREE.Scene();
|
|
this.#scene = new THREE.Scene();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ this.set_room();
|
|
|
this.update_size();
|
|
this.update_size();
|
|
|
|
|
+ this.manager.mouse.add_listener((move) => this.#camera_rotate(move));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ get manager() {
|
|
|
|
|
+ return this.#manager;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ get #canvas() {
|
|
|
|
|
+ return this.manager.canvas;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
update_size(width, height) {
|
|
update_size(width, height) {
|
|
@@ -39,9 +53,46 @@ export class space_scene {
|
|
|
this.#working = false;
|
|
this.#working = false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ set_room() {
|
|
|
|
|
+ const url = this.manager.loader.texture("example_room.jpg");
|
|
|
|
|
+
|
|
|
|
|
+ const texture = new THREE.TextureLoader().load(url, () => {
|
|
|
|
|
+ texture.mapping = THREE.EquirectangularReflectionMapping;
|
|
|
|
|
+ texture.colorSpace = THREE.SRGBColorSpace;
|
|
|
|
|
+ this.scene.background = texture;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ get camera() {
|
|
|
|
|
+ return this.#camera;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #animate() {
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ get maximum_rotation() {
|
|
|
|
|
+ return Math.PI / 3;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #camera_rotate(move) {
|
|
|
|
|
+ this.camera.rotation.reorder("YXZ");
|
|
|
|
|
+
|
|
|
|
|
+ this.camera.rotation.x -= move.y / 100;
|
|
|
|
|
+ this.camera.rotation.y -= move.x / 100;
|
|
|
|
|
+
|
|
|
|
|
+ if (this.camera.rotation.x > this.maximum_rotation) {
|
|
|
|
|
+ this.camera.rotation.x = this.maximum_rotation;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (this.camera.rotation.x < -this.maximum_rotation) {
|
|
|
|
|
+ this.camera.rotation.x = -this.maximum_rotation;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
#rendering() {
|
|
#rendering() {
|
|
|
const before = performance.now();
|
|
const before = performance.now();
|
|
|
|
|
|
|
|
|
|
+ this.#animate();
|
|
|
this.#renderer.render(this.#scene, this.#camera);
|
|
this.#renderer.render(this.#scene, this.#camera);
|
|
|
|
|
|
|
|
if (!this.#working) {
|
|
if (!this.#working) {
|
|
@@ -50,7 +101,7 @@ export class space_scene {
|
|
|
|
|
|
|
|
const after = performance.now();
|
|
const after = performance.now();
|
|
|
const delta = after - before;
|
|
const delta = after - before;
|
|
|
- const next = 1000 / 30 - ((delta >= 0) ? delta : 0);
|
|
|
|
|
|
|
+ const next = 1000 / this.#framerate - ((delta >= 0) ? delta : 0);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
requestAnimationFrame(() => { this.#rendering(); });
|
|
requestAnimationFrame(() => { this.#rendering(); });
|