Getting bounding box data from a 3D entity in A-Frame: A simple guide

Currently I'm immersed in a new aframe venture that requires me to import 3D objects of various sizes into my scene. I'm thinking ahead and would like to adjust the object to a specific size (such as a fixed height) before integrating it into the scene. However, I'm unsure of how to obtain details like width, height, and depth from the object's bounding box. Can anyone assist with this?

Answer №1

To achieve this, it is essential to utilize A-Frame's underlying three.js APIs. While a similar solution has been provided for three.js previously, below is an A-Frame specific approach:

// Accessing three.js object from an aframe entity
var element = document.querySelector('#my-element');
var object = element.getObject3D('mesh');

// Evaluating the bounding box
var boundingBox = new THREE.Box3().setFromObject(object);
console.log(boundingBox.min, boundingBox.max)

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

Save information on users' Google accounts

Utilizing this resource, I successfully implemented a login feature on my website. The implementation includes functions such as onSignIn, signOut, and auth2.isSignedIn.get() to manage user authentication. Now, I am looking for a way to extract specific d ...

Show or hide item by clicking outside the div

Looking for a way to use jQuery's slidetoggle to hide the showup class when clicking anywhere outside of the DIV. Any advice is appreciated! Check out this online SAMPLE: http://jsfiddle.net/evGd6/ <div class="click">click me</div> <d ...

Handling dynamic routes with React Router 4 and the 404 path

I have been working with the latest version of React Router (4) and have implemented a dynamic route configuration as described in the tutorial. The routes are functioning correctly, except for when I tried to add a 404 path following the tutorial's i ...

Guide on incorporating a JS file in a React application

I recently obtained a template for my website that includes the following JS file which is being called from my React component. !(function($) { "use strict"; // Hero typed if ($('.typed').length) { var typed_strings = $(&quo ...

Displaying the chosen array in a Material UI Table within a React application does not show the desired checkboxes

After days of hard work and research, I finally figured out how to achieve what I needed. In my React App, I have a Material UI table that I want to load with pre-rendered checks in the DOM based on entries in a selected array. The selected array contains ...

Improving JavaScript event management efficiency through handling numerous asynchronous HTTP requests

Summary: In a SPA CMS project, multiple dynamic data sources are causing performance issues due to a large number of asynchronous HTTP calls required to display a table with extensive data. The challenge is to maintain good performance while handling the ...

What is the method for importing the merge function from "lodash/merge" in TypeScript?

When using ES6, it's possible to import only a single function from a library in order to reduce the overall bundle size. For example: import merge from "lodash/merge" But in TypeScript, the statement above can trigger a compile error: Cannot find m ...

jQuery code tailored specifically for desktop use

Hello, I could use some assistance with a jquery script. I have been able to accomplish what I need using a jquery script, but I would like it to only work on desktops and be disabled on tablets and mobile devices. The script I am currently using is as fo ...

How to assign values to an object within an array in React?

In React, I am currently working on creating a swipeable card that consists of 4 slides. The data displayed within the card is entirely dependent on user input. To start off, I define a sample object like so: const initialState = { id: '', title ...

Trouble Arising in Showing the "X" Symbol upon Initial Click in Tic-Tac-Toe Match

Description: I'm currently developing a tic-tac-toe game, and I've run into an interesting issue. When I click on any box for the first time, the "X" symbol doesn't show up. However, it works fine after the initial click. Problem Details: ...

Saving functions in the localStorage API of HTML5: A step-by-step guide

I have encountered an issue while trying to store an array in local storage using JSON.stringify. The array contains functions (referred to as promises) within an object, but it seems that when I convert the array to a string, the functions are removed. Su ...

When I adjust the page size, the navbar stays hidden after clicking

Trying to implement a toggle button for the navigation bar. The objective is to hide the navbar on screens smaller than 667px and display a toggle button instead. Clicking the button should toggle the visibility of the navbar items. The toggle button work ...

How about incorporating a unique twist while utilizing a for loop to attach click listeners?

I've been exploring, but I'm unable to find a solution to this particular issue. I am working with a linked list that needs to be accessed when specific items on my webpage are clicked. To do this, I created a get(id) method that iterates throug ...

Leverage information retrieved from API in a separate React component

Is there a way to fetch data from an API in one component and then access it in another component without having to re-fetch the data? For example, if I fetch some data and create a table in Tables.js, how can I use that same data in TableDetails.js withou ...

Giant Slide - navigate directly to a particular slide using a link

Hey there, I am currently working on incorporating the Superslide slider for fullscreen images in my website. My goal is to have a mostly text-free site where users can navigate through the images using the main menu or jump to a specific image within the ...

Attempting to navigate the world of AJAX and PHP

My experience with AJAX is limited, but I am currently working on a project that requires a form to submit data without refreshing the page. The goal is to display the result in a modal window instead. To achieve this functionality, I understand that imple ...

Fixing an erroneous value that has been dragged into the drop function with Jquery

I am encountering an issue with my codes and need some assistance in identifying the problem. The data is being dynamically loaded from the database, and I am using a foreach loop to display all items in a draggable div. The issue arises when I drag an it ...

Incorporate a "Back" button following the removal of the navigation bar in a Meteor-Ionic

When working on a Meteor-Angular-ionic app, I encountered a situation where I needed to hide the nav-bar in a template to create a full-screen view using the following code: <ion-view hide-nav-bar="true"> However, I then faced the challenge of addi ...

What is the best way to transform a string into React components that can be displayed on the screen?

Stored in my database are strings that contain partial HTML content, as shown below: “Intro<br /><br />Paragraph 1<br /><br />Paragraph 2” If I want to display this string within a new <p> element, what is a straightforwa ...

Why does my window scroll change when making a $.ajax call?

Encountering a peculiar bug... Whenever my JS code enters the success function after a jQuery $.ajax call, the scroll position on my window suddenly jumps to the bottom of the page. This is problematic for me as I'm developing a mobile page and want t ...