Calculating the bounding box of an Object3D with BufferGeometry in Three.js using JavaScript

Having an Object3D with various levels of children (more Object3Ds or Meshes/Lines), I am trying to compute a bounding box of the object and all its descendants similar to the setFromObject() method in the Box3 class.

Unfortunately, I can't utilize the setFromObject() method of Box3 because the project I'm working on exclusively uses BufferGeometry instead of Geometry. Since BufferGeometry objects lack a .vertices property, the setFromObject() function is unable to compute the bounding box as intended.

var bbox = new THREE.Box3().setFromObject(object);
console.log(bbox.min); // x, y, and z are all Infinity.
console.log(bbox.max); // x, y, and z are all -Infinity.

While attempting to use the computeBoundingBox() method of BufferGeometry, I have found that the bounding box does not update when the geometry is manipulated. This issue may be linked to matrixAutoUpdate being set to false, despite trying to invoke updateMatrix() with no success.

Is there a method to calculate a bounding box for an Object3D and all its descendants using the BufferGeometry class? As a newcomer to Three.js, any guidance on this matter would be greatly appreciated!

My current Three.js version is r66.

Answer №1

With the latest update, <code>Box3.setFromObject( object )
is now compatible with BufferGeometry.

Check out the new features in three.js version r.69dev (development version).

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

Extending the declaration of JavaScript native methods is not possible when using TypeScript

When attempting to enhance the JS native String class by adding a new method, I encounter error TS2339. interface String { transl(): string; } String.prototype.transl = function() { // TS2339: Property 'transl' does not exist on type 'St ...

What is the best way to retrieve id elements from a hidden field in jquery?

I'm working with a form that contains hidden fields and I need to retrieve the id of each hidden field. My goal is to potentially remove hidden elements using their id using jQuery's Remove methods. Form: <form id="postform" method="post" ac ...

Unable to animate meshes by rotating them individually on update

Exploring the realms of Three.js for the first time has been quite intriguing. In my current experiment, I am trying to add 35 icosahedrons to the scene and have them rotate individually when calling requestAnimationFrame. I initially thought that by ite ...

What measurement does Three js objects utilize?

let camera = new THREE.PerspectiveCamera( 35, // Field of view 800 / 640, // Aspect ratio .1, // Near plane value in units 10000 // Far plane value in units ); let cube = new THREE.Mesh( new THREE.CubeGeometry(5, ...

Guide on utilizing JavaScript to modify the attribute of a chosen web element with Selenium WebDriver in Java

I am seeking a way to utilize Javascript in order to set attributes for the selected element on a webpage. After some research, I have discovered two methods for achieving this with Javascript: Method 1 WebDriver driver; // Assigned elsewhere Jav ...

Utilize AngularFire to generate a new User and invoke the factory function to showcase notifications

I recently started working with AngularJS and wanted to integrate it with AngularFire/Firebase for storing project data. I created a factory that manages notifications to be displayed in a centralized location. Here is the structure of my factory: myApp.f ...

Is React failing to insert a span element in the client-side code?

First off, I'm a beginner in the world of react and recently tackled this guide on creating a real-time Twitter stream To cut to the chase, I wanted to include a link next to each tweet that followed its text. To achieve this, I simply added props to ...

How can I dynamically populate my select field with JSON data using React.js?

My goal is to fetch data from an API and use the 'symbol' JSON field as options for a select dropdown. However, I'm encountering an issue: 'TypeError: Cannot read property 'length' of undefined.' Beneath my code, I' ...

issue encountered while adding a new element to an array using javascript

I am encountering an issue with adding comments from HTML form elements to an array in AngularJS. Whenever I try to use the Javascript push function, I receive an error stating "property of object doesn't exist". Can someone assist me in resolving thi ...

What is the best way to programmatically route or navigate to a specific route within a Next.js class component?

tag: In the process of creating my app with next.js, I primarily use functional components. The sole exception is a class component that I utilize to manage forms. Upon form submission, my goal is to redirect back to the home page. However, when I attemp ...

Having trouble with Angular router.navigate not functioning properly with route guard while already being on a component?

I am currently troubleshooting an issue with the router.navigate(['']) code that is not redirecting the user to the login component as expected. Instead of navigating to the login component, I find myself stuck on the home component. Upon adding ...

Execute a middleware prior to running the Nest Js ServeStaticModule command

Is there a way to execute middleware before Nest JS serves my React application through the ServeStatic Module? I've attempted using both a Nest middleware and Global middleware, but they only seem to work for static routes such as '/'. mai ...

Suggestions for placing a script under the scripts menu in Illustrator CS5.1

My script for Adobe Illustrator CS5.1 is not showing up in the scripts menu despite trying to place it in various directories such as: C:\Program Files\Adobe\Adobe Illustrator CS5.1\Presets\en_GB\Scripts\ C:\Progra ...

Creating a dynamic multi-select feature in AngularJS with ng-repeat

I'm relatively new to AngularJS and JavaScript, but I've managed to create a functional multi-select list. The ng-model linked to the dropdown is part of a "user" DTO object, specifically a property that stores an array of "groups" the user can j ...

Ways to conceal ng repeat using ng if

My autocomplete feature is set up using ng-repeat to display suggestions and ng-click to change the textbox value. However, I am facing an issue where the suggestion does not disappear when the textbox value is already the same as the suggestion. How can I ...

Troubleshooting lack of output in Console.log (NodeJs)

I am facing an issue where I can't see any output when trying to console log a JavaScript code using Node.js. const pokemon = require('pokemon'); pokemon.all(); var name = pokemon.random(); console.log(name); I am unable to even display a ...

Tips for allowing specific tags using Google's Caja HTML Sanitizer in a node.js environment

I'm currently utilizing the npm module Caja-HTML-Sanitizer with node.js. Although I am able to sanitize the HTML input using the sanitizer() function, I am unsure of how to implement a whitelist in order to restrict only certain tags (e.g. p br stron ...

What could be causing the Gruntfile to throw an error?

Getting an unexpected error while trying to run grunt $ grunt Loading "Gruntfile.js" tasks...ERROR >> SyntaxError: Unexpected token : Warning: Task "default" not found. Use --force to continue. Execution terminated due to warnings. Here is my ...

Are items placed into an array passed by reference or by value?

When working with custom Objects in an Angular context, I define two objects "a" and "b" using an interface. These are created as class attributes along with an empty array of these objects. public a: CustomObj; public b: CustomObj; public array: ...

Uncertainties surrounding the complexity of this multi-stage form

Exploring this multi-step form I have a couple of questions: 1) Is there a way to transfer the value from the first step to the second step of the form? 2) How can I ensure that the datepicker value is not empty (to prevent user progress in the firs ...