How to Retrieve the Size Measurements of a 3D Model Using JavaScript

Currently, I am involved in an AR project that utilizes three.js and involves working with various 3D models. One issue I have encountered is the inconsistency in sizes among the models. I aim to have all the models of the same size, which requires setting uniform dimensions for each. My initial attempt to address this involved using bounding boxes and bounding spheres, but unfortunately, this approach was ineffective.

How can I accurately determine the sizes of the models and successfully set them to be uniform?

Answer №1

var dimensions = new THREE.Box3().setFromObject( targetObject ).getDimensions(new THREE.Vector3())

Answer №2

There is a need for something different, as the code of manthrax is intriguing but has its limitations. For example, consider the following code snippet:

andy.scale.set(0.011, 0.011, 0.011);
                                andy.rotation.set(0, 0, 0);
                                andy.position.set(0,0,0);
                                var size = new THREE.Box3().setFromObject(andy).getSize(new THREE.Vector3())
                                console.log(size);

                                function moy(vect){
                                    return ((vect.x+vect.y+vect.z)/3);;
                                }

                                console.log(moy(size));

                                andy.scale.set(0.030, 0.030, 0.030);
                                console.log(moy(size));

If there is a need to modify the value of "size," how can that be achieved?

PS: andy represents my 3D model

I managed to find a solution by creating my own Box3:

                        andy.scale.set(0.011, 0.011, 0.011);
                        andy.rotation.set(0, 0, 0);
                        andy.position.set(0,0,0);
                        var box3d = new THREE.Box3();
                        var size = box3d.setFromObject(andy).getSize(new THREE.Vector3())
                        console.log(size);

                        function moy(vect){
                            return ((vect.x+vect.y+vect.z)/3);;
                        }

                        console.log(moy(size));

                        andy.scale.set(0.030, 0.030, 0.030);
                        box3d.setFromObject(andy).getSize(size);
                        console.log(moy(size));

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

SystemJS could not locate the root directory for RxJS

There seems to be an issue with SystemJS loading rxjs modules on Windows, as it throws a 404 Not Found error on the rxjs directory. This problem does not occur on OSX, and all modules are up to date. GET http://localhost:8080/node_modules/rxjs/ 404 (Not F ...

Issue with fulfilling Ajax promises

How can I properly use a promise to compare the current logged-in user with a field from a list in SharePoint? function compareCurrentUserWithListObject() { var userProp = this._userProfileProperties; var userName = userProp.get_userProfilePropertie ...

"Steady layout of grid for the navigation bar and

Currently, I am in the process of developing a control panel with the use of HTML and CSS. To structure the page, I opted for a grid layout. However, I encountered an issue where the navbar and sidebar do not stay fixed on the screen despite trying various ...

Remove option from MUI Autocomplete after it has been selected

I am currently utilizing a Material-UI Autocomplete component. To avoid users selecting the same element twice, resulting in duplicate ID numbers, I want to remove the element from the dropdown entirely. For instance, if "Shawshank Redemption" is selected ...

Having trouble retrieving JSON with crossDomain jQuery AJAX

The process I followed was creating a rails 3.0 scaffold and exposing it using json, keeping it running. When accessing http://localhost:3001/objects.json I can view json data in the browser Next, I had a simple html file with code.jquery.com/jquery-1.7 ...

Invoking one service from another service in AngularJS

I'm trying to access a service from another service and use the returned object for some operations. However, I keep encountering a TypeError: getDefinitions is not a function error. Here is the code for my services and controller: definitions.servi ...

Uncertainty surrounding the distinction between global variables (var) and block variables (let, const) in Node.js

It's common knowledge that var is a global variable in node js and can be accessed from anywhere. However, I found myself perplexed by the following examples: In the first example, accessing global_1 poses no issues as it is a global variable. var g ...

The program is designed to only allow up to two images to be wrapped

I'm struggling with a short jQuery program that I need help with. The problem is, I can't seem to get it to wrap more than two images in the same row. My goal is to create a website that side-scrolls, and I thought this approach would be the simp ...

There was an uncaught error in AngularJS stating that the URL in the HTTP request configuration must be a string

I've been working on a web application and have encountered some challenges. One particular issue I'm struggling with is related to the following code snippet: this.bookSpace = function (date, spaceId) { swal({ title: "Are you sure?", t ...

Mapping textures from a single Face4 to two separate Face3 in Three.js

Currently, I am experimenting with Three.js on a project that relies on an older version of the library. As part of my work, I am in the process of upgrading to the newest version (r71) of Three.js. While most aspects of the update are progressing smoothly ...

Obtaining the initial variable from an array - a simple guide

Although it seems simple, I am having trouble getting it to work. I have an array with 2 variables inside that I retrieve from jQuery. var features = [long, lat ] I want to iterate through all the values in the loop and use: fetures[i] This should give ...

A helpful guide on incorporating and showcasing a 'svg' file within a React Native application

I am having an issue with importing an svg file in my code. The svg file has a complex structure with various paths: <svg xmlns="http://www.w3.org/2000/svg" width="260.346" height="65.709" viewBox="0 0 260.346 65.709&q ...

Leveraging the NextAuth hooks, employ the useSession() function within the getServerSideProps

I'm currently working on retrieving data from my server based on the user who is logged in. I am utilizing Next-Auth and usually, I can easily obtain the session by calling: const { data: session } = useSession(); In a functional component, this work ...

Creating a backup link for a video player component in NextJs

My aim is to make sure that two video player components in a NextJS application can still access and play videos even when the application is running locally using npm run dev without an internet connection. Currently, these two components.. <HoverVi ...

Instructions for generating multiple components in React when an array is not at your disposal

In the process of developing a Tic-Tac-Toe game, I am in need of creating 9 empty squares. Currently, I have a ul element and 9 li elements representing each square in the game. The issue is that there is no array available for looping through and generati ...

What could be the reason for v-model not functioning properly?

Embarking on my Vue.js coding journey, I am currently following a straightforward online tutorial. Utilizing the vue-cli, I kickstarted my application and crafted a basic component named Test.vue. Within this component lies a simplistic input control conne ...

In IE8, submitting an Ajax request almost always results in an error being

This piece of code seems to be causing some trouble, as it works fine in all browsers except for IE8 on an XP machine. No matter what I try, the error function keeps getting triggered specifically in IE8. I've experimented with different dataTypes lik ...

Open the link and input the text into the text box?

Suppose I have the following JavaScript code: <script language="javascript" type="text/javascript"> function addText() { var newText = document.myForm.inputText.value; document.myForm.description.value += newText; } </script> I want t ...

Passing data from a parent node to a child node using JavaScript and the D3.js library

Creating a legend (var legend) for my d3js chart involves binding data to the parent 'g' element, specifically a string (label) that is needed in the child 'text' element. Any ideas on how to assign the parent data from the 'g&apo ...

establish a compacted directory shortcut within alfresco

Although I'm not highly skilled in Javascript, I am in need of creating a webscript for Alfresco that can generate an alias [A] for a folder (space) [B]. If the structure of [B] appears as companyhome/site/special/my/fo/ld/de/r, [A] should be struct ...