Unable to obtain the vertices of the extremities due to the absence of labels on AxisHelper

My goal is to add labels on AxisHelper in Three.js that rotate along with it. I came across a helpful code snippet from this source:

// Axes
axes2 = new THREE.AxisHelper(70);

// Axes labels
addLabelAxes();

// Add axes to zoomScene
zoomScene.add(axes2);


function addLabelAxes() {

  // Axes label
  var loader = new THREE.FontLoader();
  loader.load('js/helvetiker_regular.typeface.js', function (font) {

    textGeo = new THREE.TextGeometry('Example label', {
      font: font,
      size: 15,
      height: 5,
      curveSegments: 10,
    });

    var color = new THREE.Color();
    color.setRGB(255, 0, 0);
    textMaterial = new THREE.MeshBasicMaterial({ color: color });
    meshText = new THREE.Mesh(textGeo, textMaterial);

    // Position of first axis
    meshText.position.x = axes2.geometry.vertices[1].x;
    meshText.position.y = axes2.geometry.vertices[1].y;
    meshText.position.z = axes2.geometry.vertices[1].z;

    meshText.rotation = zoomCamera.rotation;
    zoomScene.add(meshText);

  });

}

However, when attempting to implement this code, I encountered the following error in the console log:

TypeError: axes2.geometry.vertices is undefined
addLabelAxes/<()
sphere_dev.js:230
THREE.FontLoader.prototype.load/<()
three.min.js:382
THREE.XHRLoader.prototype.load/<()

What could be causing this issue?

Answer №1

The AxisHelper in question has a geometry classified as BufferGeometry, not the conventional Geometry.

To retrieve the positional values of the AxisHelper's geometry, you can use the following method:

var axes = new THREE.AxisHelper( 20 );

var position = axes.geometry.attributes.position;

The variable position is a type of BufferAttribute. By examining its contents closely, you will notice the underlying structure.

Subsequently, you can access individual elements of the attribute using a similar approach like this:

var x = position.getX( index ); // or getY, getZ

Version used: three.js r.76

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

Trouble with Add To Cart feature in React app due to issues with Context API

I have been following a tutorial located here. I followed the steps exactly and even checked the code on the related github repository, which matches. However, when I try to add a product to the cart by clicking the button, the state does not update. In Re ...

Node.js: Error - Module 'html' not found

Currently, I am utilizing Node.js and attempting to exclusively serve HTML files without any Jade or EJS engines. Below is the code for my entry point (index.js): var express = require('express'); var bodyParser = require('body-parser&apo ...

Endless Scroll Feature in Javascript

A brief tale: I am in search of a way to extract data from a website that features infinite scroll without actually implementing the infinite scroll feature myself. My plan is to create a script that will auto-scroll the page from the browser console, wai ...

Having difficulty accurately interpreting the input value

As someone new to JavaScript, I set out to create a basic calculator using JavaScript and HTML. My goal is to have two input fields, named Fld1 and Fld2, that would add up the values entered into them when submitting. However, despite parsing the input val ...

Determine the total quantity of colored cells within a row of an HTML table and display the count in its own

I need assistance with a table that has 32 columns. From columns 1 to 31, I am able to fill in colors by clicking on the cells. However, I now want to calculate and display the number of cells that are not colored in the last column. This task must be co ...

Send data to a webpage and instantly navigate to it

When using the JavaScript code below, I am able to successfully send data to a page named "book.php" via the POST method (as indicated by the alert), but when I try to display the received data on book.php, nothing shows up. <script type="text/javascri ...

Modify JSON date format to a shorter version using the first 2 letters of the month and the year

Looking to convert date values in a JSON array from "December 2016" format to "D16". Hoping to accomplish this using Regex, any assistance would be greatly appreciated. [["November 2016","December 2016","January 2017","February 2017","March 2017"],["tot ...

The WebView.HitTestResult method is currently only receiving <img src> elements and not <a href> elements

I am attempting to open a new window in the Android browser using "_blank". I have set up an event listener for this purpose. mWebView.getSettings().setSupportMultipleWindows(true); mWebView.setWebChromeClient(new WebChromeClient() { ...

What is the best way to loop through arrays of objects within other arrays and delete specific attributes?

I have an array of JavaScript objects with potential children who share the same type as their parent. These children can also have their own set of children. My goal is to loop through all nodes and modify certain values. [ { "text": "Auto", ...

Using a variable in Ajax URL with Action razor syntax

I have a function that calls a method in the controller through an Action URL. However, I need to use a parameter as the name of the method, but unfortunately, this is not possible in the current implementation. function changeDropDownList(id, dropNameToC ...

Having trouble toggling journal entries in an HTML journal? The Jquery function might not be working properly

I have been tasked with creating a civil war journal for my 8th grade Social Studies class and I decided to present it as an HTML file featuring the title and date of each journal entry. The goal is to allow users to click on each entry to open it while au ...

timer-based user session expiration

Currently, the app I'm developing has a system where a session is created with a 15-minute expiration time once a user interacts with a form. This session is managed server-side. If the user remains idle for 15 minutes, the server returns a 404 erro ...

The Three.JS AudioAnalyser() function is experiencing issues when working with an audio source in Stream type format on Safari

Currently, I am in the process of creating a unique streaming radio experience in 3D utilizing the power of Three.JS. I have implemented a system where music is sent to clients via a PeerConnection, with a THREE.AudioAnalyser() attached to visually represe ...

JavaScript code encounters a math calculator script error

Am I overlooking something in my script? Everything seems to work fine when I click the minus (-) button, but when I press the plus (+) button, the calculator malfunctions. It displays 1, 11, 21, and so on, all ending with 1... Here is my code: functi ...

Restore to the prior iteration of jQuery

Encountered an issue after installing two libraries, one updating to jQuery 1.9.1 and the other installing 1.9.2. Found both versions of jQuery in my Scripts folder, so attempted an upgrade-package in nuGet to version 2.0.1. My project still requires com ...

JavaScript for Altering Viewport/Screen Width

Lately, I've been experimenting with creating a responsive button for our new website. The goal is to adjust the body width to 460px, simulating how our site would appear on mobile devices. While researching, I came across a technique that utilizes if ...

Automatically change a text based on its location

Currently leveraging the amazing flexible-nav to showcase the current subtopic within my post. I am also considering the possibility of extracting this current-string and showcasing it at the top of the page in my main navigation bar. This way, the text w ...

Is it possible to incorporate additional sections by utilizing map and props in the given code snippet?

I have a component named CardItems.jsx which specifically defines the appearance of a card. Then, I also have Gotocart.jsx where there is a welcome section (similar to welcoming someone to their cart) and an order section at the end (for initiating an orde ...

Arrays data being retrieved and set by Chrome Extension are visible in the console but not appearing in the HTML

Having trouble displaying my arrays in HTML. I'm attempting to do this within a Chrome Extension. While I can view the array perfectly in console.log, I'm encountering issues when trying to add it to the HTML DOM: /* Generating the array f ...

Utilize the composite primary key of an Entity within Typeorm for efficient data retrieval

I am working with the following database entities: @Entity() class Team { @PrimaryGeneratedColumn() id: string @PrimaryColumn() teamName: string @OneToMany(() => Player, player => player.team) players: Player[] } @Entity() class Player ...