How can I place a THREE.ArrowHelper on a specific layer in Three.js?

Exploring the world of Three.js, I'm striving to understand how to organize elements onto separate layers.

One of the challenges I'm facing involves an ArrowHelper that I've set up and added to the scene in the following manner:

    var arrowLeft = new THREE.ArrowHelper(direction, center, length, 0x884400);
    arrowLeft.layers.set(1);
    scene.add(arrowLeft);

Additionally, I have a Mesh that is assigned a font and a THREE.MeshPhongMaterial:

    var loader = new THREE.FontLoader();
    loader.load( 'fonts/helvetiker_bold.typeface.json', function ( font ) {

        var textGeo = new THREE.TextGeometry( "My Text", {
            font: font,
            size: 1 * globalScale,
            height: 0.01,
            curveSegments: 12
        });

        var textMaterial = new THREE.MeshPhongMaterial( { color: 0xff0000 } );
        var mesh = new THREE.Mesh( textGeo, textMaterial );

        mesh.layers.set(1);
        mesh.position.set( 2, 0, zPos);

        scene.add(mesh);
    } );

Reviewing my render function reveals the following structure:

    function render() 
    {
        camera.layers.set(1);
        renderer.render(scene, camera);
        controls.update();
    }

Despite setting the layers correctly, only the mesh is visible in the output, not the arrow. Upon inspecting the arrow object with console.log, it confirms that it is on layer 1 and visible.

Altering the render function to:

    function render() 
    {
        camera.layers.set(0);
        renderer.render(scene, camera);
        controls.update();
    }

... results in only the arrow being displayed. This discrepancy is confusing as I'm using three.js revision 85.

Answer №1

When using the ArrowHelper to instantiate an object with children, it is crucial to set the layers for each object in the hierarchy. Keep in mind that the layers property is not automatically inherited.

Follow this pattern to ensure proper layer assignment:

light.layers.set( 0 );
light.layers.enable( 1 );

mesh.layers.set( 1 );

arrowHelper.traverse( function( node ) { node.layers.set( 1 ); } );

camera.layers.set( 1 );

Version: three.js r.85

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

Exploring ways to display a JavaScript object on click from a .json file

As I delve into the world of javascript and json, I find myself facing a challenge. I am looking to extract information (using the Get Information function) from a json file within a javascript function triggered by an event. The catch is, I want to accom ...

Cannot display data in template

After successfully retrieving JSON data, I am facing trouble displaying the value in my template. It seems that something went wrong with the way I am trying to output it compared to others. My function looks like this, getUserInfo() { var service ...

The server has denied access to the resource due to a HTTP 403 Forbidden error in the AJAX request

I have exhausted all resources online in an attempt to resolve an error I am encountering with my AJAX request. Even after trying XMLHttpRequest() request, the problem remains unsolved. Below is the code for my Ajax Request: $.ajax({ type: "POST", url: " ...

Tips on formatting dates in a Material UI text field

<TextField name="BalDueDate" format="MM/dd/yyyy" value={basicDetails.BalDueDate.slice(0,10)} onChange={event => { ...

The implementation of local JSON instead of external JSONP in Angular

I am exploring the option of storing a json-file on the same server as my Angular app. I am wondering about how I can modify this code to read from a locally stored json file: ergastAPI.getDrivers = function() { return $http({ method: 'GET&apos ...

What is the best way to display a resolved promise object in string format on a button, as an example?

I've searched through many similar questions, but none of them seem to address my specific issue in a simple way. Currently, the behavior of my promise is shown in the image below: https://i.sstatic.net/9GETz.png When looking at lines 62 and 63 in ...

Attempting to transfer a string variable into a JavaScript scope within an HTML document using handlebars-express

Struggling to pass a variable from server-side to client-side using handlebars-express... After searching through the content here for some time, I realize I might need some help. I've confirmed that the object passed is indeed of string type, but h ...

Promise.all doesn't pause for Firestore queries to iterate

The code I am converting from the Realtime Database to Firestore involves looping through each User (doc) in Firestore and then through each document of 2 nested Subcollections inside each User in order to create some jobs to be handled later. Although I ...

Error message: "Issue with Jointjs library on Node.js server - Uncaught ReferenceError: Joint is not recognized"

I am attempting to create a sample diagram using the code below on a file hosted on a Node server: <!DOCTYPE html> <html> <head> <title>newpageshere</title> <link rel="stylesheet" href="joint.css" /> <script src="j ...

What is causing the .responseToString function to be recognized as not a function?

Consider the following scenario with Typescript: interface IResponse { responseToString(): string; } export default IResponse; We have two classes that implement this interface, namely RestResponse and HTMLResponse: import IResponse from "./IRespo ...

What could be causing my Ionic/Firebase subscription to be triggered three times?

I'm having an issue with my code where it seems to be executed 3 times and I can't figure out why. advertenciaMantto() { this.afs.doc('Core/Programador').valueChanges().subscribe(async (data) => { await this.afs.firestore.doc(` ...

Transform and command the data acquired through an AJAX request using jQuery

My code includes an AJAX call using jQuery: $('.add a').click(function() { $.ajax({ type: 'POST', url: '/api/fos', context: this, datatype: 'html', success: function(data) ...

struggling to send variables to jade templates with coffeescript and express.js

As a newcomer to node and express, I am currently building the front end of an application that utilizes jade as its templating engine. Despite extensive searching online and within this community, I have not been able to find a solution to a particular is ...

What is the most efficient way to apply a single click handler instead of using multiple click handlers for the same

Check out the project I'm currently working on by following this link: The link provided above contains a list of clickable colors available on the right side. When a user clicks on a color, the images on the left side change accordingly. Below is t ...

Problem encountered when attempting to pass data from parent to child component

While using Vuu.js, I encountered an issue with passing a value from parent to child component. Initially, I had it working perfectly with a provided example. However, as soon as I tried changing the name, the functionality broke. I'm struggling to un ...

Replace the image source with a list of images

I am looking to create a dynamic image list using either an array or an HTML list. When I hover over an image, it should change one by one with a fade or slide effect, and revert back to the default images when I hover out. Question 1: What type of list s ...

An error occured: Unable to access undefined properties (specifically 'hasOwnProperty')

I encountered an issue and managed to solve it. I am currently working on creating an update profile page for my Express app using Mongoose, but I keep getting the error "TypeError: Cannot read properties of undefined (reading 'hasOwnProperty')". ...

If the condition is true, apply a class with ng-class when ng-click is triggered

I am facing a situation similar to toggling where I am adding the class col-xs-6 to divide the page into two views. Initially, when I click, I set a variable value as true and in ng-class, I check for a condition to append the col-xs-6 class. Below is the ...

Adding the <br> tag in a Bootstrap modal: a simple guide

Hi everyone! I am currently working with a bootstrap modal to create a login functionality within the modal itself. There is a data validation function in place. However, when an error occurs, the word 'br' displays directly in the HTML instead ...

Modify Bootstrap TouchSpin's initial value

Struggling to update the initial value displayed in TouchSpin, it seems like there is no direct way to do it. While it's possible to change other values like the maximum value, attempts to set the initval directly have failed. $("input[name=&apos ...