Discovering the diagonal measurement of a Box3 in Three.js and Threebox: a comprehensive guide

I'm currently utilizing Threebox (a Mapbox plugin for Three.js) to display 3D models of buildings on a map, with the capability of interacting with the buildings by rotating and moving them. The rotation feature is accessible through a floating ring that allows users to rotate the model when clicked.

For instance:

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

However, since my models vary in size, I am facing difficulty in determining the appropriate measurements for the ring. Ideally, it should look like the following:

https://i.sstatic.net/7gqQD.png

To create the ring, I use a TorusGeometry from Three.js as shown below:

let geom = new THREE.TorusGeometry(ringSize, 0.01, 30, 25);
let material = new THREE.MeshStandardMaterial({ color: 0xffc000, side: THREE.DoubleSide });
let mesh = new THREE.Mesh(geom, material);

My challenge lies in calculating the required ring size beforehand. For example, the radius for the house model mentioned earlier is approximately 0.7, but I am unable to accurately derive this value from any properties of the models. I suspect this discrepancy may be due to Threebox using meters as units while Three.js has its own map units.

The object provides some properties which I can access:

unitsPerMeter: 0.0600151
modelSize: { x: 13.9649, y: 11.4863, z: 9.1121 }
boundingBox.box: {
    "min": {
        "x": -6.982465131993985,
        "y": -5.743162421920143,
        "z": 0
    },
    "max": {
        "x": 6.982465131993986,
        "y": 5.743162421920143,
        "z": 9.112114852394226
    }
}
center: {
    "x": -1.4794275894722282,
    "y": 0.5752914186997362,
    "z": -0.0858976981176804
}

I have attempted the following methods to determine the size:

let box = new THREE.Box3().setFromObject(object);
let size = new THREE.Vector3();
box.getSize(size);
console.log(size)

However, the output does not provide much assistance as the dimensions are significantly larger than the desired length of 0.7.

Answer №1

To find the length of a diagonal in a square, use the formula side * sqrt(2), where side represents the length of one side of the square.

Answer №2

Are you in need of information regarding this specific section from the documentation?

As per this section, you have the ability to:

tb.projectToWorld(lnglat)

in order to

determine the corresponding THREE.Vector3 for a provided lnglat coordinate

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

Is it necessary for the error event of xmlhttprequest to include an error message?

Currently, I am in the process of developing an AJAX request within a Firefox extension. The following code snippet illustrates my approach: function GetMenu(){ var oReq = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(); ...

How to populate a database with Facebook data by utilizing AJAX post and PHP

I've been developing a Facebook Canvas game and had it running smoothly on my localhost along with a local database via phpMyAdmin. However, after moving it online, I've encountered an issue with the database. Previously, the game would grab pla ...

Implementing automatic activation of a tab upon page load using Angular

I am currently working with a set of Bootstrap nav pills in my navigation bar. The 'ng-init' code in my Angular script sets the 'dateState' to 'past' on page load. However, I have noticed that the 'Past Events' nav p ...

PHP: Link to logo in different folder by including 'nav.php'

I am facing an issue with my nav.php file: <div> <!-- there's a lot of code here so I want to write it once and include it in all pages within the main folder as well as subfolders <img src="logo.png"> </div> The structur ...

The craft of masonry is known for its creation of intentional gaps

I've gone through all the posts related to this issue, but none of the suggested solutions seem to work for me. Here is a visual representation of my grid: https://i.sstatic.net/ybufk.png If you want to see the code and play around with it, check o ...

Steps for allowing the cells in a Data-Table column to be edited

Is it possible to have editable cells in a column of a Data Table with the support of the plugin? ...

Generating exportable dynamic code in Javascript

Any assistance or links to similar inquiries would be greatly welcomed as I have conducted some research but am uncertain about the best approach to take in this situation. I find it difficult to articulate exactly what I need, so I have created a visual ...

What is the best way to retrieve data from PHP and format it into JSON for use in my jQuery script?

I need help formatting the data returned to jQuery from a query. The specific format I want is: var externalDataRetrievedFromServer = [ { name: 'Bartek', age: 34 }, { name: 'John', age: 27 }, { name: 'Elizabeth', ...

The Heroku app seems to be malfunctioning (Issue with deployment?)

After deploying my application that utilizes JavaScript, Express, and Node.js on Heroku, I encountered an issue where the functionality of the app is not working at all when accessed through Heroku. Interestingly, everything works perfectly fine when teste ...

Guide to retrieving the width measurement of a troika-three-text element

Is there a way to retrieve the dimensions (width and height) of a Text object from troika-three-text library? import { Text } from 'troika-three-text' // Instantiate Text object: const myText = new Text() myScene.add(myText) // Customize proper ...

Increase the date by one day excluding weekends (Saturday and Sunday)

My current code is designed to add +1 day to the current date. var date = '30 Apr 2010'; var actual_date = new Date(date); var final_date = new Date(actual_date.getFullYear(), actual_date.getMonth(), actual_date.getDate()+1); Now, I am looking ...

Utilizing an EllipseCurve for Extrusion Paths in Three.js - How is it Done?

The issue: I'm struggling to convert an EllipseCurve into a path that can be extruded along in Three.js. When I try to use the EllipseCurve as the extrude path, nothing shows on the screen even though there are no errors. However, if I switch it to a ...

Exploring the organization of files: comparing the /bin and /dist directories

I often find myself confused when it comes to structuring my project directories in a way that is considered "professional." This confusion arises from the differentiation between the purpose of the 'bin', 'src', and 'build' d ...

Having trouble with my jQuery .hover() code not running as expected

Whenever I hover over my divs, I want them to change color. However, the code doesn't seem to be working as expected when I try to do so. I suspect that the issue might be related to the z-index property used in the class that I am trying to hover ove ...

What is the reason behind having the default router preloaded?

Creating 3 unique pages and a navigation menu. When a menu option is clicked, the page reloads. Template: <a (click)="toLogin()">Login</a> | <a (click)="toHome()">Home</a> | <a (click)="toCatalog()">Catalog</a> ...

Utilizing commonjs pattern to share functions among different couchdb views for increased reusability

I am seeking a way to utilize a variety of functions across different couchdb view map functions. My attempt involves using the commonjs require pattern. Within the given design doc, I am puzzled as to why the require statement in test1 successfully funct ...

Refreshing browser data with JQuery ajax when the browser is refreshed

Is there a way in JavaScript or jQuery to stop the page from refreshing (F5) and only update certain parts of the page using Ajax? I attempted the following code, but it did not work: $(window).bind('beforeunload', function(event) { ...

Looking to display a JSON-based menu using AngularJS?

Having trouble displaying a dropdown menu when trying to print a menu from a JSON file. https://i.sstatic.net/fNLxw.png JSON Data [{ "Option": "Request", "Name": "<a href=\"#/request\"><i class=\"material-icons left\ ...

Error message: Attempting to access the property '_layerAdd' of an undefined object in the context of vue and leaflet integration

Encountering an issue while attempting to include a feature group on my map: TypeError: Cannot read property '_layerAdd' of undefined The section of code causing the error: <l-map id="mapid" :zoom="zoom" :center="center" /> var ...

Tips for updating the data value of a specific block using Vue.js

I am looking to develop a basic Vue.js application. Within this app, I have multiple counter blocks that are rendered using the v-for directive. In my data object, I initialize a 'counter: 0' instance. My goal is to increment and decrement only o ...