Issue with Three JS where the BoundingBox does not update correctly following rotation operations

I am trying to determine the bounding box of a geometry after applying rotations to it.

I obtained the rotation code from the sample editor in Three JS:

object.rotation.x = xRadians;
object.rotation.y = yRdians;
object.rotation.z = zRadians

This rotation works as expected.

However, I am having trouble getting the updated bounding box:

Here is the code I am using to retrieve the bounding box:

var minX = parseFloat(object.boundingBox.min.x);
var minY = parseFloat(object.boundingBox.min.y);
var minZ = parseFloat(object.boundingBox.min.z);

Regardless of the rotation applied, I keep receiving the same values for minX-Z. How can I properly obtain the updated bounding box?

I am currently on version r-66.

In addition, I attempted the following approach:

var radians = x * Math.PI / 180;
var axisX = new THREE.Vector3(1, 0, 0);
var matrix = new THREE.Matrix4().makeRotationAxis(axisX, radians);
geometry.applyMatrix(matrix);

This method correctly updates the bounding box after performing relative rotation. However, I am looking to achieve the same result without relative rotation. The initial method I mentioned does not update the object's bounding box accordingly.

Any suggestions or ideas would be greatly appreciated. Thank you!

Answer №1

Box3.setFromObject( object ) calculates the overall world-aligned bounding box of an object and its descendants, taking into consideration the global transformations applied to both the object and its children.

var box = new THREE.Box3().setFromObject( object );

Version r.66 of three.js

Answer №2

const box = new THREE.Box3().setFromObject(object);

To get the world coordinates, you must deduct them:

const bbox = new THREE.Box3().setFromObject(object);
bbox.min.sub(object.position);
bbox.max.sub(object.position);

This calculation provides the accurate bounding box in relation to the object.

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

How can mongoose be used to modify user information in a database?

Hey there, I'm currently working on a personal project and came across an issue. I've successfully set up my (steam) user data to save in mongodb through mongoose. Right now, I have it set to only save a new user if they are not already in the da ...

Is it possible to retrieve calculated data from a child component and pass it to the parent component?

Is there a way to transfer computed data from a child component to a parent component? Currently, I am passing data from the parent to the child first and then I would like to utilize the computed property (data) in the parent component. This is crucial as ...

How can one go about incorporating the feature "updating list upon clicking a label" on a webpage?

On my website, I currently display a comprehensive list of publications. However, I am looking to organize these publications by various research topics using labels. Ideally, when clicking on a specific label, only the papers related to that topic will be ...

When utilizing the React API Fetch, there may be instances where not all data is returned. However

Having some trouble with my FetchData class. I am receiving a list of data, but it's in an array format. When I try to access specific values like countries: data.Countries[0], I can get individual values based on the index. However, what I really wan ...

Solving templateUrl resolution of directives in Angular with RequireJS

Currently, I am using AngularJS and RequireJS in my single-page application (SPA). To organize imports efficiently, I rely on RequireJS. With RequireJS, I can utilize features like baseUrl to resolve import paths seamlessly. Now, I wish to apply the same r ...

Tips on eliminating overlapping strokes

I'm having trouble with drawing an array of circles that are meant to intersect a series of lines. The issue I face is that if the circles overlap, a stroke appears underneath them which I want to remove. Does anyone have any suggestions on how to el ...

What is the method for obtaining the socket object for individual users who are connected in Node.js?

I am currently using socket.io to send notifications to users. I have set up a listener that is monitoring for a specific event. myEvent.watch ((res,err)=> { if (!err) { let id = res.userID; let msg = res.msg; //to imple ...

Working efficiently with query selectors in React using useRef

I have created a typewriting effect function and now I am trying to display the code associated with this effect within a specific div element (typingRef). Currently, I am using typingRef.current = letter, but I am wondering if this is equivalent to docu ...

What is the best way to add items to arrays with matching titles?

I am currently working on a form that allows for the creation of duplicate sections. After submitting the form, it generates one large object. To better organize the data and make it compatible with my API, I am developing a filter function to group the du ...

What is the best way to transform this code into a JavaScript string that can be evaluated at a later time?

I need a way to save this snippet of JavaScript code, make some modifications to it, and then evaluate it at a later time. Unfortunately, the online converter I tried using didn't produce the desired outcome. Original Code $Lightning.use("c: ...

What could be the reason for StaticComponent constantly re-rendering despite having a static state that does not change

I'm trying to grasp the core concepts of how React triggers component re-rendering upon state changes. In the scenario described below, the console.log('hi') statement within the StaticComponent is executed every time the onChange event han ...

Is there a way to automatically determine the text direction based on the language in the input text?

When posting in Google Plus (and other platforms), I noticed that when I type in Persian, which is a right-to-left language, the text direction changes automatically to rtl and text-alignment:right. However, when I switch to English, the direction switches ...

Encountering an error code of 500 when executing the createIndex function in Pouch

I'm currently working on setting up a basic index, and I have the following code snippet: currentDB.createIndex({ index: { fields: ['name'] } }).then((result) => { }).catch((error) => { }) However, when I try to r ...

How to show or hide a textbox in JavaScript?

Within my user control, there is a panel with two controls: ddlType, a drop-down list, and txtOthers, a text box. Initially, txtOthers is set to be invisible. The goal is for txtOthers to become visible when the user selects an option in ddlType that corr ...

Encountering an "Unsupported Media Type" error while attempting to generate an Hpalm defect through the rest api

I have been attempting to create a defect through the hpalm rest api, but I keep encountering a "415 Unsupported Media Type" error. Here's what I've done so far: var postOptions = { jar: cookies, accept: 'application/json', ...

Experiencing difficulty in choosing an array in Javascript

Currently learning Javascript and working on a project that involves retrieving data from a weather API. Encountered a simple issue that I need help with. Here is the data I managed to fetch so far: {coord: {…}, weather: Array(1), base: "stations", mai ...

Choosing elements in HTML using jQuery from an Ajax GET response

As a programming student, I am currently working on developing a basic website using HTML, JavaScript, and jQuery for the front-end, while utilizing node.js and Express frameworks for the back-end. In my project, I have used Ajax to retrieve data and then ...

Constructing a React component with a constructor

I am brand new to working with react native and I'm requesting assistance in fixing the code below. Currently, I have a view within a const and I am looking to include a constructor inside the const function. const { width } = Dimensions.get(' ...

Solving yarn conflicts when managing multiple versions of a package

My software application contains a vulnerability related to a package that has different versions available (1.x, 2.x, 3.x). Since many other packages rely on this particular one as a dependency, updating each one individually is not a viable solution at t ...

Looking to fill a text field with email addresses by selecting checkboxes for various towers

I have 4 towers and I need checkboxes for each of them. Upon checking any combination of them, the 'txtNotifTo' textbox should be populated with the respective group of email IDs for each tower selected. Could you please assist me in identifying ...