Adding pointlights to the camera in three.js is a great way to

I have written some code to add two lights on the camera that move along with the orbitcontrols. However, the lights and spheres are not visible for some reason. Can someone help me identify the issue in my code?

var sphere1 = new THREE.Mesh( new THREE.SphereGeometry( 2000, 16, 16), new THREE.MeshBasicMaterial({color:0xff0000}) );
var cameraLight1 = new THREE.PointLight( this.options.lights.lightColor, this.options.lights.lightIntensity * 1.2, this.options.lights.lightRadious );

    sphere1.add( cameraLight1 );
    sphere1.position.set( -5000, -5000, -5000 );

this.camera.add( sphere1 );

var sphere2 = new THREE.Mesh( new THREE.SphereGeometry( 2000, 16, 16), new THREE.MeshBasicMaterial({color:0xff0000}) );
var cameraLight2 = new THREE.PointLight( this.options.lights.lightColor, this.options.lights.lightIntensity * 1.2, this.options.lights.lightRadious );

    sphere2.add( cameraLight2 );    
    sphere2.position.set( -5000, -5000, -5000 );

this.camera.add( sphere2 );

When I add the spheres/lights to the scene directly, they appear fine. I am unsure why this method is not working.

PS:

Camera initial position:

{x: 0, y: 5.510910596163089e-12, z: 90000}

Update:

Even this alternative approach does not work:

var cameraLight1 = new THREE.PointLight( this.options.lights.lightColor, this.options.lights.lightIntensity * 1.2, this.options.lights.lightRadious );

this.camera.add( cameraLight1 );
    cameraLight1.position.set( 0,0,-5000 );

var cameraLight2 = new THREE.PointLight( this.options.lights.lightColor, this.options.lights.lightIntensity * 1.2, this.options.lights.lightRadious );

this.camera.add( cameraLight2 );
    cameraLight2.position.set( 0,0,-5000 );

Answer №1

When adding child objects to the camera in three.js, it is important to remember to also add the camera to the scene. Failure to do so will result in the child objects not being included in the scene graph.

scene.add( camera ); // Don't forget this step...
camera.add( light ); // ... to ensure proper functionality

Version r.69 of three.js

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

Can WebDriver (HtmlUnit, Ruby bindings) be configured to bypass JavaScript exceptions?

When attempting to load the page, HtmlUnit throws an exception and crashes my test. caps = Selenium::WebDriver::Remote::Capabilities.htmlunit(:javascript_enabled => true) driver = Selenium::WebDriver.for(:remote, :desired_capabilities => caps) drive ...

Enhance user interaction in Angular 13 by animating a selected element using just one animation block

I am currently working on a one-page website project to enhance my Angular skills, and I'm facing a challenge with animating multiple DOM elements using a single animation. Defining the animation for each element individually seems like a cumbersome a ...

Eliminating choices from a dropdown list using jQuery

I am currently working on a page that contains 5 dropdown menus, all of which have been assigned the class name 'ct'. During an onclick event, I want to remove the option with the value 'X' from each dropdown menu. My current code snipp ...

Retrieve a data value from a JSON object by checking if the ID exists within a nested object

I am facing the challenge of navigating through a JSON object where child objects contain IDs that need to be matched with parent properties. The JSON structure looks like this: { id: 1, map: "test", parameter_definitions: [{ID: 1, pa ...

React JS makes it simple to create user-friendly cards that are optimized

I have a collection of objects that include a name and description. The name is short and consists of only a few characters, while the description can vary in length. I am looking to showcase this data within Cards in my React project, and have tried using ...

The unexpected behavior in React's reconciliation process: What is causing the state to remain unchanged?

While exploring the React documentation, I came across an interesting example of resetting state: here To better understand it, I created different sandboxes to experiment with. However, I am struggling to reconcile what I observe in each of them. Each s ...

Guide on sending a JSONP POST request using jQuery and setting the contentType

I'm struggling to figure out how to make a jsonp POST request with the correct content type of 'application/json'. Initially, I was able to send the POST request to the server using the jQuery.ajax method: jQuery.ajax({ type: ...

Step-by-step guide on triggering a button using another button

I have a unique question that sets it apart from others because I am looking to activate the button, not just fire it. Here is my syntax: $("#second_btn").click(function(){ $('#first_btn').addClass('active'); }) #first_btn ...

What is the best way to implement a conditional check before a directive is executed in Angular, aside from using ng-if

I am facing an issue where the directive is being executed before the ng-if directive. Is there a way to ensure that the ng-if directive is executed before the custom directive? Could I be making a mistake somewhere? Should I consider using a different ...

Leveraging PHP JSON responses for decision-making in jQuery/JavaScript

Recently, a friend shared the following code snippet with me: json : { result: true } success function(data){ if(data.result) { //do something here } else { //do something here } } I'm curious how I can integrate that ...

Modify the `<link>` tag using the `onclick` function in JavaScript

I want to switch up the site's style with just a click on an icon <head> <meta charset="utf-8"> <link rel="stylesheet" href="styled.css" id="styles"> </head> Everytime I try to tackle th ...

The HTML table seems to be inexplicably replicating defaultValue values

I'm encountering an issue where, when I use JavaScript to add a new table data cell (td), it ends up copying the defaultValue and innerText of the previous td in the new cell. This is confusing to me because I am simply adding a new HTML element that ...

Effortless Ways to Automatically Accept SSL Certificates in Chrome

It has been quite some time that I have been attempting to find a way to automatically accept SSL certificates. Unfortunately, I haven't had any success yet. The scenario is this: I am working on selenium tests and every time I run the test on Chrome, ...

Retrieving PHP data with jQuery

Isn't it interesting that I couldn't find anything on Google, but I believe you can assist me. I have a Table containing different accounts. Upon clicking on a specific row, I want another table related to that account to slide in. This secondary ...

Introduce an additional parameter to the Prestashop Cart entity

After setting up a radiobox "stock_action" in the Cart, I need to send its value to the Cart object for additional order costs. In the Cart Override, the $stock_action variable has been added: public $stock_action; /** * @see ObjectModel::$defi ...

Display content exclusively within a modal specifically designed for mobile devices

I want to implement a feature where a button triggers a modal displaying content, but only on mobile devices. On desktop, the same content should be displayed in a div without the need for a button or modal. For instance: <div class="container&quo ...

The most efficient way to invoke a jws void method in the fewest steps possible

When calling a void method of a SOAP JWS web-service using JavaScript without expecting a result back, what is the most efficient and concise approach? ...

Using SignalR for lengthy processes: transmitting progress updates

Utilizing SignalR to initiate lengthy computations on the server and notify the client when the results are ready. The input bindings consist of an HTTP request. Desire to send multiple messages to update the client on various stages of the process (e.g., ...

Setting a timeout from the frontend in the AWS apigClient can be accomplished by adjusting the

I am currently integrating the Amazon API Client Gateway into my project and I have successfully set up all the necessary requests and responses. Now, I am trying to implement a timeout feature by adding the following code snippet: apigClient.me ...

Browsing through a collection of pictures, I find myself wanting to linger on the final image rather than swiftly exiting the window

The functionality currently implemented is as follows: $("#btnNextImage").click(function (e) { var win = window.opener.parent; win.postMessage('next', '*'); window.close(); //close ...