"Disabling ThreeJS HDR feature seems to stay off permanently, without any option

I've been working on toggling a HDR map in three.js.

This is how I set it up:

//HDR LOADER
var envmaploader = new THREE.PMREMGenerator(renderer);
const loadhdri = new THREE.RGBELoader()
.load("myhdr.hdr", function (texture){
 texture.mapping = THREE.EquirectangularReflectionMapping;
scene.background = texture;
scene.environment = texture;

}

Everything seems fine at this point.

Next, I added it to the GUI:

var gui = new dat.gui.GUI();
  var params = {switch: true}
  const lightsFolder = gui.addFolder('Customize lights')
  lightsFolder.add(params, "switch").name('hdrenv').onChange(updateHdr)

Finally, when trying to implement the toggle logic, the console always shows 'false':

function updateHdr() {
if (params.switch == true)
   {
   scene.environment = texture
   console.log("true")}
    else
   {scene.environment = null
   console.log ("else switch false")
   }
}
        

The HDR loads and turns off correctly with the button click, but has issues turning back on.

Answer №1

Here is a suggested way to structure your updateHdr function:

function updateHdr( status ) {

    if ( status === true ) {
        scene.environment = texture;
        console.log( 'true' );
    } else {
        scene.environment = null;
        console.log( 'else condition triggered' );
    }

}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

State in React Native causing asynchronous problems

I am working on developing a straightforward application that allows users to enter the name of a movie in a search bar. The app will then display a list of movies related to that specific title, sourced from an external public API. However, I have run int ...

Nested looping in ReactJS using the map method of JavaScript

I'm experiencing an issue with nested mapping in my project, as I keep getting an undefined error. Currently, I am passing the profile props to the Link router in navbar.jsx like this: profile: this.state.profile. Then, I fetch the data in profilePag ...

Converting an HTML table into a multi-series chart

Is there a way to automatically convert an HTML table into a multi-series chart using JavaScript or jQuery? Here is a sample of my table: | Category | YYYY | YYYY | YYYY | | Asset | 1,500.00 | 3,590.00 | 5,000.00 | | Revenue | 2,560 ...

What methods can I use to design a splash screen using Vue.js?

I am interested in creating a splash screen that will be displayed for a minimum of X seconds or until the app finishes loading. My vision is to have the app logo prominently displayed in the center of the screen, fading in and out against a black, opaque ...

Is there any issue that you can spot with this js / jQuery code?

Presented below is a script that prompts the user to confirm clicking a button based on a system setting. The system setting is saved in a hidden field established from the code-behind. Markup: <asp:HiddenField ID="hfConfirmOnApproval" runat="server" ...

zingcharts with multiple lines on x axis representing time

I am facing a rather interesting challenge with plotting data. I want to create a chart where time is the x-axis scale and multiple lines are plotted, each with varying time intervals between data points. While zingcharts has provided documentation on gene ...

What is the significance of the "component" prop within MUI components?

I am a beginner in React and HTML. Currently, I am using MUI and React to create my own website. I am currently attempting to add an "Upload button" that will allow me to select an image file when clicked. Below is the official implementation: <Button ...

"What is the most efficient way to break up an array into its maximum length and iterate over

Using Firebase to send push notifications, but encountering the following error: { Error: tokens list must not contain more than 500 items at FirebaseMessagingError.FirebaseError [as constructor] (/srv/node_modules/firebase-admin/lib/utils/error.js:42: ...

Mapping object data within an object in React: A step-by-step guide

Within my React project, I am retrieving data from a JSON source like so: https://i.sstatic.net/fEZFL.jpg The simplified JSON data appears as: const listData = [ { "_id": "abscdf456", "bucket": { code: "videos" }, "contents": [{}, {} ...

Is it possible to reorganize the JavaScript modules created by the TypeScript compiler?

In my TypeScript project, the structure resembles that of a typical Maven Java project. Here is an overview of how the project is organized: *.js file for commonjs/webpack, system, and amd.</p> For commonjs/webpack, I utilize tsc with tsconfig.jso ...

Animating Chart.js 2 from right to left instead of from top to bottom

Here is the issue demonstrated in the jsfiddle below. Initially, the data inserts work well. However, when the data set reaches a cap of 10, an unwanted behavior occurs where the data points are animated top-down instead of moving leftward. This can be qu ...

What methods can be used to boost performance while loading models in three.js?

Currently, I am facing a challenge with loading .stl files into my viewer. My goal is to utilize the orbit controls provided by three.js to enable users to navigate around the file and view it from various perspectives. While the models do load successfull ...

Error: Uncaught TypeError - Unable to access the 'handleClick' property of undefined within a forEach loop

I came across the following code snippet articles_list.jsx import React from 'react'; import './articles_list.css'; export default class ArticlesList extends React.Component { constructor(props) { super(props); this.state ...

Solutions for retrieving the selected row in a bootstrap modal using knockout js

I'm currently working on developing a master-detail page using Knockout JS, as shown in the image below. I've encountered an issue with retrieving values from a Bootstrap modal in the details section. For instance, upon clicking the browse butto ...

Update the class of the element that is currently selected using jQuery and the `this` keyword

Is there a way to change the class on hover only for the current element using 'this'? The code I have changes classes for all elements, but I need it to work individually. Here is the code snippet I'm currently using: https://codepen.io/ky ...

Is there a way to execute .jsx Photoshop scripts on images using Java?

Currently, I am in the process of developing a Java program to apply edits to a sequence of images. However, I am searching for a simple and adaptable method to conduct these edits by utilizing Image Editors Scripts (such as Photoshop Scripts, Gimp Scripts ...

Ensure the modal content is loaded only when the modal is being displayed, not

I currently have a basic CSS-styled modal that appears when a button is clicked using JavaScript. Here is the JavaScript code: <script> var modal = document.getElementById('myModal'); var btn = document.getElementById("myBtn"); var span = ...

Issues with Semantic UI Calendar not displaying properly

I am currently experimenting with the Semantic UI Calendar, where there is a date input field and a calendar that pops up when selected as demonstrated in this initial example. Since I am not familiar with this process, I am uncertain if I have properly li ...

Convenient methods in Three.js for easily detaching and attaching character weapons within a scene

I'm currently facing challenges while developing a first-person shooter game using Three.js. I've encountered major glitches with THREE.SceneUtils.detach() and THREE.SceneUtils.attach(), and I'm uncertain if they are the appropriate methods ...

Prevent excessive clicking on a div element

I am facing a simple issue that I haven't been able to resolve yet. I want to prevent multiple clicks on a button before an AJAX call is complete. This is what I have tried so far: <button id="btn_pay"></button> $("#btn_pay").click( fun ...