Guide on integrating a HemisphereLight into a basic Three.js environment

I've been experimenting with adding light to a simple scene in threejs, but no matter what intensity or color I set for the light, there is no visible change. Strangely, even when I exclude the light code altogether, nothing happens either. Why is HemisphereLight not functioning as expected in this scenario?

  var scene = new THREE.Scene();
  var camera = new THREE.PerspectiveCamera( 200, window.innerWidth/window.innerHeight, 0.1, 1000 );

  var renderer = new THREE.WebGLRenderer();
  renderer.setSize( window.innerWidth, window.innerHeight );
  document.body.appendChild( renderer.domElement );

  var planeGeometry = new THREE.PlaneGeometry(25, 60, 20, 20);

  var planeMaterial = new THREE.MeshBasicMaterial({color:"green"})

  var plane = new THREE.Mesh( planeGeometry, planeMaterial );
  var light = new THREE.HemisphereLight(0xffffff, 0x000000, 2);

  scene.add(light);
  scene.add(plane);

  plane.rotateZ(Math.PI/2)
  camera.position.z = 10;

  scene.background = new THREE.Color(0xffffff);

  var render = function (time) {
              requestAnimationFrame( render );   
       
            renderer.render(scene, camera);
        };

        render();

Answer №1

What version of Three.JS are you currently using?

I put together a JSFiddle incorporating your code, utilizing only Javascript and Three.js version 105, and everything functioned properly. However, when I switched to Three.JS version r54, the code stopped working as expected.

I apologize for presenting my question in this format, as I am unable to leave comments at the moment. Please let me know if it is an issue, and I will promptly remove it.

You can determine the version you are using by executing the following line of code:

console.log(THREE.REVISION)

<script src="https://threejs.org/build/three.js"></script> 
<script type="module">
console.log(THREE.REVISION)

var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 200, window.innerWidth/window.innerHeight, 0.1, 1000 );

var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

var planeGeometry = new THREE.PlaneGeometry(25, 60, 20, 20);

var planeMaterial = new THREE.MeshBasicMaterial({color:"green"})

var plane = new THREE.Mesh( planeGeometry, planeMaterial );
var light = new THREE.HemisphereLight(0xffffff, 0x000000, 2);

scene.add(light);
scene.add(plane);

plane.rotateZ(Math.PI/2)
camera.position.z = 10;

scene.background = new THREE.Color(0xffff00);

var render = function (time) {
    requestAnimationFrame( render );   
    renderer.render(scene, camera);
};
render();
</script>

All of the code above belongs within one HTML file.

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

Saving a pointer to "this" for usage in a named function callback through the prototype pattern in JavaScript

Having encountered difficulties obtaining a reference to a JavaScript object structured with the prototype pattern within a callback, specifically coming from a 3rd party component integrated into my object. The said 3rd party object connects to a message ...

The output varies with each reload even though the function remains constant

Essentially, my webpage functions as an online store where the content is dynamically generated using PHP shortcodes. Here is an example of how it is structured: <?php get_header(); ?> <div id="main-content"> <div id="page-content"> ...

Employing switch statements to match regular expressions in JavaScript

Could someone help me with converting my if statements to a switch statement for evaluating regex? I have been struggling to figure it out and would appreciate any guidance. Below is the code I have attempted: var username = $('input.username'), ...

Prevent any pop-up windows from appearing when a specific link is clicked

On my website, I have implemented popup advertising where ads open when clicked inside the body. However, I am looking to disable popups when a link with the class donot is clicked. Currently, when the donot link is clicked, a popup opens and the link doe ...

Struggling with integrating HTML Canvas within Vue.js

Currently, I am attempting to upload an image by utilizing HTML canvas. My decision to use canvas stems from the fact that I will be superimposing additional images based on the data received from the API, and this process seems more straightforward when u ...

Unable to run the method in the parent component from the child component

I am attempting to trigger a method to run on a parent component when a button within one of its child components is clicked. I am utilizing single file components with Webpack. Below is the code for the child component: <template> <button v-on ...

Error: Attempting to modify a constant value for property 'amount' within object '#<Object>'

After fetching data from an API, I stored an array in a state. Upon trying to update a specific field within an object inside the array using user input, I encountered the error message: 'Uncaught TypeError: Cannot assign to read only property 'a ...

Tips for sending an array of "FormData" through ajax and retrieving it in a Laravel controller

# Could you please provide guidance on sending this array to the controller via Ajax request? var dataPanier=[]; function addarray(objser) { dataPanier.push(objser); } $('.target').click(function() { var btn_name=$(this).attr("name"); ...

The functionality of JQuery's `.on("click"... is sporadically functioning

I have a code block that dynamically generates elements and includes event handling. However, the event handling sometimes works and other times it doesn't. I'm not sure how to debug this issue. Can someone help me figure out what might be causin ...

What is the method to retrieve results using 'return' from NeDB in vue.js?

Seeking assistance on retrieving data from NeDB within a method in a .vue file using electron-vue. Currently, I am aware that the data can be stored in a variable, but my preference is to fetch it using 'return' as I intend to utilize the result ...

I require the use of Nodejs with the gm module to process images, but it is essential that it

There are two methods to consider, but I am struggling to make it synchronous. Despite attempting to use Promise.all to synchronize the process, I am faced with the challenge of images processing asynchronously and inability to reject or resolve in a loop. ...

Retrieving JSON information and refreshing the display

Currently, I am utilizing OnsenUI in conjunction with AngularJS to create a searching application. On page1, the user inputs the data they wish to search for. Upon clicking the search button, page1 is added to the stack and a background GET request is trig ...

Accessing Private Files with Signed URLs from AWS S3

Issue: The challenge is to securely allow users to upload a file and retrieve it later. The files are stored in private Buckets and objects using S3 pre-signed URLs for uploading. However, fetching the file poses a problem as the signed URLs expire after ...

Importing a form input as a constant in an API endpoint script

Recently stepping into the realm of React, I'm encountering difficulties in my Next.js app related to imports and exports. My goal is to export a const from a form component to an API endpoint for use within a function. While I can see the form compo ...

How to effectively implement addEventListener() / attachEvent()?

Can anyone provide guidance on how to correctly use addEventListener and attachEvent? window.onload = function (myFunc1) { /* do something */ } function myFunc2() { /* do something */ } if (window.addEventListener) { window.addEventListener('load ...

What is the best way to display or conceal buttons when the textarea is in focus or out of focus, while still allowing them

Seeking help to include two buttons beneath the input box. One button is for saving the input in the textarea, while the other is for aborting. The buttons should only be visible when the input field is focused. An issue I am facing is that clicking on ...

I am encountering an issue with the dropdown navigation menu in bootstrap

After creating a dropdown list using the code below, I encountered an issue where the sub-item "game" was not visible during implementation. Does this require any additional CDN? View the screenshot of the implementation. <head> <title>...& ...

The response from the node is not accurate

In the index.js file, I have the following code snippet: function Answer(value) { this._val = value; } Answer.prototype.get = function get() { return this._value; } var lifeAnswer = new Answer(42); console.log(lifeAnswer.get()); var piAnswer = new ...

Disable menu bar | customize menu bar in electronJS

I am developing an Angular application with Electron.js. Due to the specific design requirements of my app, which is browser-based, I do not require or want the default Electron.js menu or menu bar to be displayed. Is there a way to remove it from my app ...

What is the most effective way to retrieve 'this' within an object method that is being used as a callback function?

I am currently working on a word game project to enhance my understanding of JavaScript, especially since I am new to it. To facilitate user interaction, I am utilizing the NPM package prompt (https://www.npmjs.com/package/prompt). Coming from an OOP back ...