From 7da550512446b9f898718dce78bc96e31d5d2139 Mon Sep 17 00:00:00 2001 From: Daan Vanden Bosch Date: Wed, 3 Jul 2019 10:53:22 +0200 Subject: [PATCH] Fix light in place so that it doesn't rotate with the camera in model viewer. --- src/rendering/ModelRenderer.ts | 1 + src/rendering/Renderer.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/rendering/ModelRenderer.ts b/src/rendering/ModelRenderer.ts index 75f00d73..50856ea3 100644 --- a/src/rendering/ModelRenderer.ts +++ b/src/rendering/ModelRenderer.ts @@ -69,6 +69,7 @@ export class ModelRenderer extends Renderer { model_viewer_store.update_animation_frame(); } + this.light_holder.quaternion.copy(this.camera.quaternion); super.render(); if (model_viewer_store.animation && !model_viewer_store.animation.action.paused) { diff --git a/src/rendering/Renderer.ts b/src/rendering/Renderer.ts index fa336f11..4a21b11f 100644 --- a/src/rendering/Renderer.ts +++ b/src/rendering/Renderer.ts @@ -8,6 +8,7 @@ import { Vector3, WebGLRenderer, Vector2, + Group, } from "three"; import OrbitControlsCreator from "three-orbit-controls"; @@ -17,11 +18,15 @@ export class Renderer { protected camera: PerspectiveCamera; protected controls: any; protected scene = new Scene(); + protected light_holder = new Group(); private renderer = new WebGLRenderer({ antialias: true }); private render_scheduled = false; + private light = new HemisphereLight(0xffffff, 0x505050, 1); constructor() { + this.renderer.setPixelRatio(window.devicePixelRatio); + this.camera = new PerspectiveCamera(75, 1, 0.1, 5000); this.controls = new OrbitControls(this.camera, this.renderer.domElement); @@ -30,7 +35,9 @@ export class Renderer { this.controls.addEventListener("change", this.schedule_render); this.scene.background = new Color(0x151c21); - this.scene.add(new HemisphereLight(0xffffff, 0x505050, 1)); + + this.light_holder.add(this.light); + this.scene.add(this.light_holder); } get dom_element(): HTMLElement {