I'm experiencing some issues with my scene in ThreeJS - the HDR background isn't displaying, and my cube

<style>
  body {
    margin: 0;
  }
</style>

<script
  async
  src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="afcadc82c2c0cbdac3ca82dcc7c6c2dcef9e8199819c">[email protected]</a>/dist/es-module-shims.js"
></script>

<script type="importmap">
  {
    "imports": {
      "three": "https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="77031f0512123747594642475946">[email protected]</a>/build/three.module.js",
      "three/addons/": "https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="13677b61767653233d2226233d22">[email protected]</a>/examples/jsm/"
    }
  }
</script>

<script type="module">
  import * as THREE from 'three'
  import { OrbitControls } from 'three/addons/controls/OrbitControls.js'
  import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';

  const scene = new THREE.Scene()
  const camera = new THREE.PerspectiveCamera(
    75,
    window.innerWidth / window.innerHeight,
    0.1,
    1000
  )
  
  const renderer = new THREE.WebGLRenderer({antialias: true})
  renderer.setSize(window.innerWidth, window.innerHeight)
  renderer.setPixelRatio( window.devicePixelRatio );
  document.body.appendChild(renderer.domElement)
  const skyboxTexture = new URL('./textures/skybox.hdr', import.meta.url)
 const loader = new RGBELoader()
loader.load(skyboxTexture, function ( texture ) {

                        texture.mapping = THREE.EquirectangularReflectionMapping;

                        scene.background = texture;
                        scene.environment = texture;

                    } );
            const   cubeRenderTarget = new THREE.WebGLCubeRenderTarget( 256 );
                cubeRenderTarget.texture.type = THREE.HalfFloatType;
  

  const controls = new OrbitControls(camera, renderer.domElement)
  const cubeCamera = new THREE.CubeCamera( 1, 1000, cubeRenderTarget );

  const geometry = new THREE.BoxGeometry(1, 1, 1)
  const material = new THREE.MeshStandardMaterial({ color: 0x00ff00, roughness: 0, metalness: 1, envMap: cubeRenderTarget.texture})
  const cube = new THREE.Mesh(geometry, material)
  cube.castShadow = true
  scene.add(cube)

  const light = new THREE.AmbientLight(0xffffff, 10)
  light.castShadow = true
//  scene.add(light)
   light.position.z = 2
   light.position.y = 3
  camera.position.z = 5

  
  const gg = new THREE.BoxGeometry(5, 0.5, 10)
  const gm = new THREE.MeshStandardMaterial({ color: 0x0000ff })
  const ground = new THREE.Mesh(gg, gm)
  ground.receiveShadow = true
  ground.position.y = -3
  scene.add(ground)
  renderer.shadowMap.enabled = true

  function animate() {
    requestAnimationFrame(animate)
    renderer.render(scene, camera)
    cube.rotation.x += 0.01
    cube.rotation.y += 0.01
    cubeCamera.update( renderer, scene );
  }
  animate()
</script>

https://i.sstatic.net/cx3Pt.jpg

My scene doesn't show my HDR background. I also made my cube roughness to 0 and metallic to 1. It's is dark but sometimes show blue color of the ground. Everything is dark. I want to show my HDR background. No errors saying!

I used everything from a YouTube video but not working. Everything is error.

The tutorial I used

Answer №1

When setting the HDR environment map to Scene.environment, make sure not to also assign the render target of a CubeCamera to the materials envMap property simultaneously.

According to the documentation for Scene.environment, environment maps assigned to the envMap material property take precedence. It is recommended to temporarily remove the cube camera and reevaluate the results.

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

Manipulate MySQL data in Node.js by storing it in a variable

Struggling to grasp the concepts of nodeJS/typescript and how to effectively save database query results into variables for return. Seeking assistance to solve the problem faced: Here is a method snippet that needs help: public getAllProducts(): ProductA ...

Could anyone clarify the reason behind the success of one function while the failure of the other?

Currently delving into the world of React, I decided to follow along with the Road To React book. In this guide, the author presented this code const List = (props) => ( props.list.map(item => ( <div key={item.objectID}> & ...

Obtain the value of an element from the Ajax response

Just starting out with Jquery and Ajax calls - here's what I've got: $(document).ready(function () { $.ajax({ type: "GET", url: "some url", success: function(response){ console.log(response); } }) }); Here's the ...

Scroll positioning determines the height of an entity

Here's a code snippet I'm working with: HTML: <div id="wrap"> <div id="column"></div> </div> CSS: #wrap { display: block; height: 2000px; width: 400px } #column { display: block; height: 20px; ...

vuejs default properties initialized with vue-i18n

I am trying to establish a default property from a dictionary in this way: props: { title: { type: String, default: this.$t("basic.confirm"), }, description: { type: String, } }, ... The $t function is part of the vu ...

Ways to enhance the appearance of the parent element when the radio button is clicked

Hey there! So, I have a situation where I'm working with two radio buttons and I want to apply certain CSS styles to the parent box (<div>) when a radio button is selected (checked). Here's how I want it to look: box-shadow: 0 0 5px #5cd05 ...

The parameter of type 'never' cannot be assigned with the argument of type 'number | boolean | undefined'

In my project, I am creating a validation input using TypeScript in Next.js. interface InputRules { required?: boolean min?: number max?: number minLength?: number maxLength?: number } I have defined an object that contains methods to handle val ...

Is there a way to display a Threejs model on a Gatsby site?

Currently exploring the use of Gatsby to display a Threejs model. Considering that Gatsby is built on react, there is a high likelihood of achieving this task The model in question is a basic box for now: import React, { useRef, useState } from "rea ...

insert data into modal's interface

I'm encountering an issue with my code, where the modal is not displaying the values inside the brackets as if they were not bound correctly. Everything else in the ng-repeat seems to be working fine, but for some reason the values are not being displ ...

What is the process for including a file in a request?

I've been encountering an issue while trying to upload a CSV file and send a request to an API. Despite attempting to do so via XHR, Unirest, and Axios, none of these methods seem to be working properly. Could there be something amiss with the impleme ...

React - A guide on accessing the scroll position of a div using JavaScript

Within my side navigation bar, there is a title and other information. The title is fixed in place (sticky) and the sidebar has a height of 100vh. I am looking to add a box-shadow effect to the title div (sticky-title) only when the user scrolls down past ...

What steps should I take to prompt Postman to interact with a Web API?

I have recently installed the Postman plugin for Chrome and I am curious about how to use it to call my web API. Currently, I am making an AJAX call in JavaScript with the following code: alert("Getting security token"); // Do AJAX call to get security t ...

Tips for transforming an object into a JSON file for the three.js model loader

I am currently developing a browser game using the three.js library and I have an imported model from Maya 2013 in .obj format. My next step is to convert this model into a JS file that will be compatible with the three.js loader. This snippet shows my c ...

Managing an iframes website using buttons and links: Tips and tricks

I am trying to create a website that includes an iframe for navigating through external websites using previous and next buttons. I also want to display the links on a sidebar so that users can click on them to automatically load the site in the iframe. I ...

Incorporate zoom feature into the jQuery polaroid gallery

Currently, I am utilizing a jQuery and CSS3 photo gallery found on this website. My goal is to allow the images to enlarge when clicked, however, the method provided by the author isn't very clear to me, as I'm not an expert in jQuery. I attempt ...

The power of the V8 JavaScript engine: Understanding v8::Arguments and the versatility of function

I have created a Node.js addon that wraps a C++ standard library element std::map<T1,T2>. The goal is to expose this map as a module with two primary functions: Set for adding new key-value pairs and Get for retrieving values by key. I want to create ...

Upon attempting to utilize Socket.io with Next.JS custom server, the server repeatedly restarts due to the error message "address already in

Every time I attempt to execute the refreshStock() function within an API endpoint /api/seller/deactivate, I encounter the following error: Error: listen EADDRINUSE: address already in use :::3000 at Server.setupListenHandle [as _listen2] (net.js:1318: ...

Strategies for effectively managing numerous API requests

My current setup involves fetching about five API calls simultaneously. While it works at times, most of the time it results in a fetch error. Is there a way to prevent these errors from occurring when running the API calls? app.post("/movie/:movieN ...

How can I initiate a TextChange event in ASP.NET C# without losing focus?

I attempted to trigger the TextChange event using Ajax, but it doesn't seem to be working as I expected. I'm hoping someone here can lend a hand. <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> ...

Accessing values from a JSON object in AngularJS without using a loop based on another field

Is there a way to extract the "value" associated with the "name" in JSON using Angular JS without having to iterate through the array? For instance, if I have an array like the one below with name and value fields, how can I retrieve the value "ABC" based ...