Tips for translating mesh without using its center point, but instead using its vertices

In my current project, I am utilizing the ThreeJS library. One of the challenges I have encountered involves setting the position of a mesh using mesh.position.set(x,y,z). However, I am interested in moving the mesh to a specific point based on its vertices. Specifically, I would like to move vertex 5 of a cube to the coordinates 100,100,100 causing the entire cube to shift to that position based on the vertex. The goal is to move the mesh to the desired point without displacing it but rather by targeting a specific vertex. How can this particular task be achieved?

Answer №1

To properly position your geometry, you must first ensure that the desired vertex v is located at coordinate ( 0, 0, 0 ) by applying a translation.

geometry.applyMatrix( new THREE.Matrix4().makeTranslation( - v.x, - v.y, - v.z ) );

Once the geometry has been translated, you can then set the position of the mesh using:

mesh.position.set( x, y, z )

This will effectively translate the mesh so that the specified vertex is positioned at the point ( x, y, z ).

Using three.js version r.68

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

Using the useState hook will help avoid any crashes when running on IE11

I recently added a new repository to my GitHub account. The file dist/index.htm is causing Internet Explorer 11 to crash, displaying the error message: "unable to get property 'root' of undefined or null reference." This issue arises when I u ...

Verifying that the data has been successfully saved using JavaScript

When a user submits a small chunk of data via AJAX using a standard update action and a remote form, the information is sent to the action as javascript. The response is then rendered in javascript utilizing format.js. def update @message = Message.wher ...

Using async/await with recursion in NodeJS for handling express requests

My code contains a function named GetAllData() that triggers the GetPurchaseData function, which in turn calls itself recursively until all the data is loaded. async function GetAllData(){ console.log("starting loading purchase data"); await G ...

Access denied encountered while executing NPM module that modifies environment variables in Nodejs on Kubuntu 18.04

While utilizing the npm module env-cmd to set environment variables on process.env in nodejs, I encountered a persistent "permission denied" issue on my Kubuntu 18.04 system. Even with sudo, I was unable to bypass the permission denial. My node and npm v ...

When a radio button is chosen, multiple text fields must be completed in order to validate the form

I am working with a set of 3 radio buttons. If the last option, labeled "In Home," is chosen, then all 4 of the text fields must be filled in for the form to validate. While I have found information on how to achieve this with checkboxes or a single text f ...

JavaScript refuses to connect with HTML

Just starting out in the world of programming, I decided to dive into a Programming Foundations class on Lynda.com. However, after following along for fifteen minutes, I encountered an issue - I couldn't seem to connect my JavaScript file to my HTML f ...

Incorporating HTML elements into a Jade template

Can HTML elements be passed into a jade file? For example, I want to insert text into the p element and nest some content inside the code element within the p element. JSON with string data var news = { one : { title : "Using JSON", body : "Us ...

Discover the ways in which an AngularJS function is able to generate HTML code containing an AngularJS

There is an issue here helper.getDataForTriggeredUploadOfMFFile = function (isTriggeredUploadMF) { if (!isTriggeredUploadMF) { return 'None'; } else { return '<spa ng-click=\"previewDataOnSmartAnalytics()>Preview Data</span&g ...

Iterate through a generic array to populate a table using ng-repeat

In the scenario I'm currently facing, I am working on creating a common reusable table structure using a directive. The goal is to display different JSON data in both the table header and body. Below is the controller code: angular.module('plun ...

Adding a color picker to a Kendo Grid

I am working with a kendo grid that has inline editing feature. I am looking to add a kendo colorpicker to a specific column. Is there a way to display the selected color even when the row is not in the editing mode? Does anyone have an example of how to ...

I am interested in using AngularJS to redirect to a different page

I am looking to navigate to another page within the application, similar to how it is done in MVC or asp.net applications. Below is the Route.js file that I have defined. The route.js file is structured as follows: var MainApp=angular.module('Routin ...

Rendering a page for a missing resource

Within the App.js file, the routes component is currently only wrapping a portion of the website. However, I would like the NotFound component to be rendered for the entire page if an incorrect URL is entered. Can you please provide guidance on how this ...

Guiding motion of a parental container using a button

This seems like a fairly straightforward task, but I'm getting a bit frustrated with it. Is there a way to move an entire div by simply holding down the mouse button on a particular button? let container = document.getElementById('abo ...

Javascript challenges for beginners in coding world

After running the code snippet, I encountered the following error messages: at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Fun ...

The JavaScript array remains unaltered

I've got an express server set up with GET and POST routes. The initial state looks something like this: let orders = [ { sum: 0, purchases: [ { id: 1, contractId: ...

What is the best way to bypass TS1192 when incorporating @types/cleave.js into my Angular application?

Using cleave.js (^1.5.2) in my Angular 6 application, along with the @types/cleave.js package (^1.4.0), I encountered a strange issue. When I run ng build to compile the application, it fails and shows the following errors: ERROR in src/app/app.component. ...

Updating a database on ASP.NET without the need to refresh the page

We are developing a user-friendly application with ASP.NET MVC that focuses on uploading pictures and rating them. The app includes two voting buttons, "like" and "dislike". https://i.sstatic.net/Z3dp5.png Whenever the like button (green) is clicked, the ...

Personalized customizable elements in Draft.js (extension)

For instance, I am interested in enabling users to incorporate a dynamic slideshow of images into their page using Draft.js. This would allow them to select a predefined slideshow from my app and have it automatically update on their page if the images a ...

What steps can I take to minimize the excessive white space below the footer on my website?

I have been attempting to resolve this issue by using multiple methods, but none of them have successfully fixed it. overflow-x: hidden; min-height: 100%; margin: 0px; https://i.sstatic.net/2ctwo.jpg Code: body: background-color: White; margin: 0px; p ...

Calculate and retrieve the result from the event handling function

I need to capture a returned value and store it in a variable within an event handler function. Below is a sample code snippet demonstrating this: var xhr = new XMLHttpRequest(); function getData(e) { if (xhr.readyState === 4) { if (xhr.s ...