Calculating the internal bounding box of an object using three.js

How can we calculate the interior dimensions of a model imported into a three.js scene? Using the example of a rectangular barn with walls of varying thickness, what would be the best approach to determine the inner bounding box?

I have attempted to use a Box3 and set its dimensions directly from the object using Box3's setFromObject method. While this works for a standard bounding box, I am struggling to find a method to calculate the inside bounding box of an object.

View actual bounding box of barn walls model here

See desired inner bounding box in top-down view

Answer №1

Utilize model slicing as a method to simplify the issue from 3D to 2D.

STEP 1 - segment the model using N horizontal planes → resulting in N shapes in 2D space, each with its own Z height.

STEP 2 - for each slice:

  1. Determine the inner extreme lines (highlighted in red and green).
  2. Intersect the extreme lines to construct the inner rectangle at the specified Z height.

https://i.sstatic.net/CiJed.png

STEP 3 - Once you have a collection of rectangles, merge them to form the inner volume:

The inner volume will take the shape of the smallest common rectangle. Analyze which rectangles contribute to determine the min(Z) and max(Z) of the given shape.

https://i.sstatic.net/0XMTs.png

OPTIMIZING to achieve maximum volume

The inner volume can be expanded by excluding certain slices or introducing new ones. For instance, if we have an inner diamond shape, calculating max(Z) and min(Z) could result in a narrow column that may not yield the optimal volume in this scenario.

Eliminating slices from the top and bottom can enhance the outcomes. Hopefully, you grasp the concept despite my limited artistic abilities!

https://i.sstatic.net/xrbP4.png

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

Utilizing JSX within this.state results in it being displayed as plain text when rendered

Currently, I am dynamically rendering a list of elements and I need to insert other elements in front of them based on key-value pairs. I want to utilize <sup></sup> tags for these elements, but they are appearing as plain text rather than sup ...

Invoking a JavaScript function to retrieve an array of integers from a C# method for organizing columns in datatables.net

I have to admit that my JavaScript skills are not very strong. Currently, I am working on creating a table using datatables.net. The table is being populated by calling a generic handler, which in turn fetches data from the database using C#. This functio ...

Proper method for retrieving and displaying information from a targeted JSON through an API

Utilizing a third-party API requires specifying the desired fields in the request. For instance: axios.get("APIURL", { params: { fields: ["username", "phone", ...etc] } }) The response is typically structured like this: { "data": [{ ...

Leveraging Flask to pass data to Google Charts with JavaScript

Trying to integrate Google Charts on my website using Flask as the backend. Need help with sending data from Flask to JavaScript. Here's a snippet of where I plan to retrieve data later: @app.route("/") def home(): data = {'Language': &a ...

Which specific HTML5 video event is triggered when the current playback time of the video is updated?

My goal is to give users the option to skip the preroll ad after a specified time (e.g. 5 seconds into the ad) and then transition to playing the regular video content. How can I make this happen? Below is an outline of my current approach: var adManager ...

Is there a specific event in Angular.js that triggers when the $scope digest cycle is completed or when the view is refreshed?

Currently, I am making an AJAX request to retrieve data that is needed in the view to generate a list. My goal is to determine when the $scope has been updated and when the view has finished rendering after receiving a successful response. This will allow ...

Favicon in browser blinks when hash changes

Whenever I adjust the hash location using either document.location.hash or window.location.hash, there seems to be a slight 'blinking' effect in most browsers. It's quite unattractive and I need to find a way to prevent it, especially since ...

Why are ccall and cwarp functions important in Emscripten?

I have been following the guidelines provided in the Emscripten documentation here, and I am interested in experimenting with basic examples. My ultimate objective is to develop a C++ library, compile it into a single wasm binary file, and then utilize the ...

route in mean stack isn't providing a response

I am having trouble creating a controller for /projects that should return all the data in the 'work' collection. The call is completing successfully with a status code of 200, but it is only returning an empty array or 'test:test' if u ...

Substitute any text string starting with a colon, such as the route path in Express

Below are some sample strings: const a = '/example/:someItemUuid/hello' const b = '/example/:someItemUuid/hello/:otherItemUuid' const params = { someItemUuid: '12345', otherItemUuid: '67890' } I am in search o ...

Having trouble with adding spaces in React Link?

Working on a React project with bootstrap : <div className='container'> <div className='row' style={{}}> Want to register? Click {' '} <Link to='/signup'> <span> {' &a ...

I kindly request your assistance in resolving the issues with the append() and empty

Here is some code I've been working on: <!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script> $(document).ready(function(){ ...

What is the process for extracting information from one table based on a column's data in another table?

Let's consider two tables: Table 1 id | email 1 | email1 2 | email2 Table 2 userid | username 2 | user1 3 | user2 Now, with the help of sails.js associations, here is what I aim to achieve: I have a username = user1. What I need to a ...

Encountering a problem with displaying error messages in an empty text field

I am facing an issue with displaying error messages when a text field is left blank. I would like a simple message, such as "can't be empty", to appear below the text field in red color when the user clicks the submit button and leaves multiple fields ...

Enhancing JavaScript smooth scroll functionality

Currently, I have a functioning code that allows for smooth scrolling to an anchor point on a web page. $('a[href^="#"]').click(function () { $('html, body').animate({ scrollTop: $('[name="' + $.attr(this, 'h ...

Pass data to three.js using an input form

I'm trying to figure out how to pass the value of an input form to a three.js workspace. Here's my code where I want to use a slider to change the radius of a sphere, without relying on the built-in controls of three.js since I'm new to HTML ...

Transferring information to PHP script using only JavaScript (Ajax)

I have a good understanding of jQuery: $.ajax({ method: 'POST', url: 'send-data-to.php', data: {data:"data"} }) However, I am unsure of how to send data that is accessible via $_POST using pure JavaScript. The reason for my inqu ...

Preserve selected value in dropdown menu post form submission

Is there a way to have the selected option displayed on a drop-down list after form submission instead of always showing the first option? <form id="myform" > <label for="selectoption">Departments</label> ...

The presence of a check mark in the checkbox is constant, even when the attribute is missing

I am encountering an issue with my code where, upon clicking on my checkbox, the state is set to false but the check mark still remains visible when it shouldn't be present. Here is my code: <template> <div id="demo"> <f ...

Upgrading may lead to errors if react-dom is imported without being used

After recently updating react-dom to version 16.5.2, my tests have started to fail with the error message: requirejs error occurred TypeError: Cannot read property 'unstable_cancelScheduledWork' of undefined. Despite checking the release notes a ...