What is the method for determining the global/world position of a child object?

Is there a way to retrieve the global position of an Object3D nested inside another Object3D?

scenario:

var parent = new THREE.Object3D();
parent.position.set(100, 100, 100);

var child = new THREE.Object3D();
child.position.set(100, 100, 100);
parent.add(child);

scene.add(parent);

remarks:

I initially attempted to achieve this using:

console.log(child.localToWorld(parent.position));

...however, the result was (100, 100, 100) instead of the expected (200, 200, 200).

Answer №1

To extract the global position, follow these steps:

let destination = new THREE.Vector3(); // Initialize it once and reuse

child.getWorldPosition( destination );

The extracted result will be stored in destination.

NOTE: This method has been updated to work with three.js version r.120.

Answer №2

With threejs version r89, you have the ability to easily retrieve the world position using Object3D.getWorldPosition. The exact date of when this functionality was added is unknown to me.

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

Load images and audio files using jQuery AJAX prior to the page being rendered

Recently, I embarked on a new project - a web app that incorporates numerous images and mp3 sounds. However, I encountered an issue where new images and sounds would load over time as users explored different parts of the app. To address this problem, I de ...

Steps for sending a DELETE HTTP request using Vanilla JavaScript (without jQuery)

I'm currently grappling with how to execute a DELETE request solely using JavaScript. I have a Java Spring service where the controller for the specific URL employs method = RequestMethod.DELETE. The URL in question is something along the lines of htt ...

Results for Angular application

Why is the output for the second div tag displaying normally? Why isn't AngularJS binding with it? Could you please provide an explanation? <!DOCTYPE html> <html> <head> <title>Angular JS Demo</title> <script ...

Switching between light and dark themes in a Next.js application with Ant Design v5 theme toggle

In my Next.js application using Ant Design v5, I am working on implementing a dynamic theme toggle to switch between light and dark modes. The issue I'm facing is that the initial theme settings work correctly, but subsequent changes to the isDarkMode ...

The image placeholder is missing

This is my custom Results component: This is my custom Thumbnail component: `import React from "react"; const Thumbnail = ({ result }) => { return ( <div> <h1>Thumbnail</h1> </div> ); }; export default Thumb ...

The jQuery ajax function seems to be malfunctioning when attempting to send a post request

Having trouble with AJAX? Let me show you my approach to making a POST request to my RESTful service using AJAX: var lat = marker.getPosition().lat(); var lng = marker.getPosition().lng(); //xmlhttp.open("GET","http://192.168.1.100:8080/MapDemo/serv ...

Utilizing ReactJS and Gatsby Js: How to pass the value of a child component to the parent component to create a button

In my current project, I am facing an issue with a simple component that is supposed to pass back the link value from the child component to a function in the parent component. However, it seems to only call back the full function instead of its actual v ...

What is the best way to identify which JavaScript code is triggering or managing an event?

In the development of an HTML5 application framework designed for businesses to use on their intranet and extranet sites, a SAP JEE application server is utilized. The framework incorporates the grid system known as "Semantic UI" along with various JavaScr ...

The Angular Sortable Containment feature ensures that items cannot be dropped outside of

I am experiencing an issue with a horizontal sortable Angular list where the containment option is not functioning properly, causing the dragged item to not be dropped. Take a look at the sortable list below without a containment option - you may notice t ...

Attempting to embed a secondary window within the primary window using three.js

I am currently working on incorporating a zoomed view of a sphere into a main window that represents the sphere. At this point, I have succeeded in displaying a subwindow at the bottom right corner that contains three axes of the main scene. These axes ro ...

Can we create a dynamic Context Menu?

I visited the following link: https://codepen.io/templarian/pen/VLKZLB After clicking on More Options, I need to display dynamically populated names like var Obj = [{name:"1st Item",taste:"sweet"},{name:"2nd item",taste:"spicy"}]; Instead of "Alert ...

Unhook, add at the beginning, and set requirements jQuery

There are two clickable div elements that can switch classes when clicked. If the first one contains "1", it will be given a class of "active". If the second one contains "2", it will have the class "active" while removing the class from the first one. &l ...

"Is it possible to make a JSON API call in Node.js before exiting with a SIGINT

In my attempt to configure certain variables and make an API call using the request module before exiting the program, I encountered issues where the function was not being properly executed due to the presence of both SIGINT and exit signals: const reque ...

The useAutocomplete function in Material-UI fails to consider the disabled

Currently, I am working on developing my own Autocomplete component by utilizing the useAutocomplete hook from the mui/base package. Most parts of the implementation are functioning correctly, except for the disabled option. My expectation is that the com ...

Using TypeScript to Trigger Events in Three.js

After recently diving into Typescript, I encountered an issue when using EventEmitter from the ThreeJS library. Whenever I attempt to trigger an event: const event: THREE.EventDispatcher = new THREE.EventDispatcher(); event.addEventListener('test&apo ...

Rendering text in three.js on or near an object

Is there a way in three.js to display text next to or in front of an object, or even on its surface? For example, if I create an object like a box, I'd like to have a visible name displayed for that object at all times (similar to a tooltip, but alwa ...

I encountered an issue with loading an array from session storage in Java Script

I am struggling to restore and reuse a created array in HTML. I attempted using JSON, but it was not successful for me. In the code below, I am attempting to reload items that were previously stored in an array on another page. However, when I try to loa ...

Incorporating Node.JS variables within an HTML document

After building a simple site using Express, I discovered that Node.js variables can also be used with Jade. exports.index = function(req, res){ res.render('index', { title: 'Express' }); }; This is the code for the index file: ext ...

What is the goal of JSON.parse(JSON.stringify(x))?

During my recent project work, I stumbled upon the following code snippet: let newParams = JSON.parse(JSON.stringify(initialParams)); I'm curious - what exactly does this code achieve? ...

Verify for redundant entries in the database when the button is clicked

I have a specific requirement that involves verifying whether the user is repeatedly inputting the same Project and Survey No. An alert should be triggered if the same combination is entered twice upon button click. Below is the HTML code snippet: <t ...