Utilize absolute positioning within Three.js to ensure that all objects are anchored at the 0,0,0 coordinate point

I am facing an issue where the solutions provided do not seem to work for me as I am new to Three.js.

In my scene, I have several objects such as a map with each region represented by a separate object positioned on a plane. Here is an image of my setup: . Now, I would like to bring all these objects to a single coordinate, for example at 0,0,0, and have them grouped together. However, when I try setting municipios[i].position.set(0,0,0), they all end up in the same position. How can I ensure that they remain in their actual positions on the Cartesian plane?

Below is a snippet of the code I am currently working with:

                            for(i in $scope.datosMunicipio){

                            Geometria[i]=new THREE.Geometry();
                            array_extrude[i]=new Array();
                              for (var a  in  vector_lat[i]){

                                 if(a!=0){
                                    if(vector_lat[i][a]==vector_lat[i][a-1]) {
                                        continue;
                                    }
                                 }
                                    Vector[i]=new THREE.Vector3((vector_long[i][a]+75.5)*10,((vector_lat[i][a])-5.5)*10,0);
                                    Geometria[i].vertices.push(Vector[i]);  
                                    array_extrude[i].push(Vector[i]);

                                }

                            forma_figura[i]=new THREE.Shape(array_extrude[i]);

                            extrude_geometria[i]=new THREE.ExtrudeGeometry(forma_figura[i],datos_extrusion); // lento
                            materialFront[i] = new THREE.MeshBasicMaterial( { color: "#FF0000",name:$scope.datosMunicipio[i].nombre} );

                            municipios[i] = new THREE.Mesh( extrude_geometria[i], materialFront[i] );

The data loaded from the database assigns each municipios[i] object to a specific region in its own position. The coordinates correspond to Google Maps data, longitude and latitude respectively, falling within the range of 5.5 to -75. Each region has its individual 0,0,0 position. How can I group them all to share one common 0,0,0 position?

Answer №1

It appears that all of your geometries are already in the same coordinate system, starting at 0,0,0. Therefore, moving them there simply returns them to their original position.

If you utilize the

extrude_geometria[i].computeBoundingBox()
method, it will establish the range values for the geometry. To align all the geometries to coincide at a specific location, ensure each one is set to the center of the bounding box. This operation is akin to using the .center() method for the geometry.

municipios[i].geometry.computeBoundingBox();
var offset = municipios[i].geometry.boundingBox.center().negate();
municipios[i].position.copy(offset);

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

Issue with undefined object values in Internet Explorer

Within the workflow of an enterprise application, the following process takes place: Each service page features a "search box" where users can type something, triggering a call to a Struts 2 action through jQuery autocompleter. Upon the action call, Hibe ...

Choose the offspring of an element using jQuery

Currently, I have a function set up to open a modal dialog and populate it with information from the 'dblclicked' node: $(function(){ $(".delete").live('dblclick', function () { var id = $(this).attr('id'); ...

The function form.parse() in node.js is always overlooked

I'm having an issue where form.parse() is never called. When I delete bodyparser, my session variable throws an error. How can I resolve this and make it work? logcat The write(string, encoding, offset, length) method is deprecated. Use write(st ...

This function appears to have an excessive number of statements, totaling 41 in total

Currently, I am using this controller: .controller('ctrl', function($scope, $rootScope, $timeout, $alert, $location, $tooltip, $popover, BetSlipFactory, AccordionsFactory, AuthFac ...

Loading an HTML template dynamically into a pre-loaded div element

I need to dynamically load an HTML template into my index.html file. Now, I am looking to load another HTML template into the previously loaded template content. To clarify further: The index is loaded with a dashboard template, and the dashboard contains ...

Inability to successfully upload batch data within specified criteria using a keyword and conditional statement

My goal is to batch the data, using "Repair" as a separator for the data. Splitting criteria = Repair Copper limit = 2.5 [ {"engineSN":"20","timeRun":"30","Cu":"2"}, {"engineSN": ...

Three.js isn't displaying colors for OBJ files

I've tried uploading the .obj file and adjusting its color settings, but it's only showing up in black. const loader = new OBJLoader(); loader.load( src, function ( obj ) { obj.traverse( function ( child ) { child.material.color.setHex(0xFF ...

Is it possible to turn off the tooltips for components within an iframe that comes from a different domain?

Is there a way to disable annoying tool tip texts on buttons in an iframe that is loaded from a different domain? I am looking for a solution using jquery, js, or css to remove the tool tip text from the iframe or the entire page. Note: The page within th ...

Issues with jQuery .on() hover functionality in HTML5 select element not being resolved

I'm currently working on capturing the event triggered when the mouse hovers over a select box, regardless of whether it's collapsed or expanded. My approach involves using .on() in the following manner: $(document).on('hover', "select ...

The StreamingTextResponse feature is malfunctioning in the live environment

When I share my code, it's an API route in Next.js. In development mode, everything works as expected. However, in production, the response appears to be static instead of dynamic. It seems like only one part of the data is being sent. I'm puzzl ...

Does the size of a JavaScript heap, when it's big but not enough to cause a crash, have the potential to slow down a website, aside from just having an

Utilizing angular material dialog, I have incorporated a mat stepper with three tables (one per step), where one or two of them may contain an extensive amount of records. I have already integrated virtual scrolling to improve performance. However, when ...

Firefox MediaSourceExtension now has enhanced mp3 support

Currently exploring the integration of adaptive and progressive audio streaming in the browser without the need for plugins. MSE is the HTML5 API that I've been anticipating, now available in FF 42. However, I'm encountering issues with audio fo ...

Guide on setting up ShareThis on a Vue.js project

I attempted to include this code in the public index.html file: <script type='text/javascript' src='https://platform-api.sharethis.com/js/sharethis.js#property=5f4e15b2e56e550012ae1e77&product=inline-share-buttons' async='a ...

What is the process for updating selenium-webdriver if it is not globally installed on my system?

After installing selenium-webdriver with the command npm install selenium-webdriver (without the -g option), I found that the usual instruction of running webdriver-manager update did not work since it was installed locally. What is the correct way to upd ...

Eliminating fillers dashes from a text

Imagine having a string filled with soft hyphens like the one below: T-h-i-s- -i-s- -a- -t-e-s-t-.- The goal is to eliminate these soft hyphens and get back the clean string: This is a test. Attempting this task in JavaScript, here's how far I&apo ...

Checking the validity of date inputs - microservice for timestamps

I'm encountering an issue while attempting to validate my date input. I've tried using moment js, but it seems there's a problem. The error message "date invalid" keeps popping up! Here is the code snippet: app.get("/api/timestamp/:date_s ...

Leveraging async/await in tandem with a for loop and mongodb

My goal is to send an order confirmation email using nodemailer to customers once they have completed their purchase. I also want to include some data from the purchased products in this email. I have tried various combinations of async/await but have not ...

I'm looking to customize my d3.js Bar Graph by changing the color of each bar individually and adding a Scale for them. How can I

I am currently working on constructing a graph that illustrates the data for the Amount of Resources utilized Per Project by creating a bar graph. I am aiming to customize the colors of the bars so that each one has its own unique color. Currently, the col ...

The message sent from the server via SocketIO seems to be malfunctioning

Currently, I am in the process of developing an application that utilizes websockets for facilitating server-client communication. The main idea behind this concept is to enable the client to request messages from the server, while also allowing the server ...

Headers cannot be sent to the client after they have already been set in Axios within Next.js

For additional discussion on this issue, please refer to the GitHub thread at - https://github.com/axios/axios/issues/2743 In my Next.js project, I am using Axios and occasionally encounter an error related to interceptors when returning a Promise.reject. ...