Creating a 3D object in Three.js by mapping texture coordinates (x, y) to object coordinates (x, y

I have a collection of OBJ files along with their respective mipmap texture files. Currently, I am loading the mipmap textures and applying them to the 3D objects generated from these OBJ files. These individual 3D objects come together to create a larger 3D object.

However, I am now interested in utilizing a 2D image as a texture instead of a mipmap. My goal is to overlay this 2D image on top of each 3D object so that the color at each (x,y) coordinate of the object matches the color at the corresponding position in the texture (z-axis can be disregarded). It's acceptable if the texture appears stretched or warped in the process.

In essence, rather than mapping the texture to specific (x,y,z) vertices of the object, my requirement is for it to be mapped to any vertices that share the same (x,y) values. Is there a method within Three.js that allows me to achieve this without the need to extract image data via canvas?

Answer №1

Yes, all you have to do is adjust the UV coordinates for each vertex of your mesh like this:

uv.x = S * (vertex.x + T)
uv.y = S * (vertex.y + T)

Afterwards, apply the texture to your mesh and you should achieve the desired result.

Remember to properly scale and translate the UVs so they fall within the range [0, 1].

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

Manipulating HTML content with jQuery

Review the code snippet provided below <div id="post-1234"> <h3><a href="some link">text</a></h3> <div> <div> <div> <span class"Event-Date">Event Date 1</span> </div> < ...

What methods work best for retrieving non-API data in Next.js when deploying on Vercel?

Before rendering my application, I am working on fetching my data. Luckily, Next.js offers a method called getStaticProps() for this purpose. Currently, I am utilizing the fs module to retrieve data from a json file in my local directory. export async fun ...

Is there a way for me to create a wireframe using only squares?

I've been experimenting with three.js and I have a question. I added a plane, enabled wireframe mode, and now I'm trying to create a grid of squares on this plane without the diagonal lines that appear due to the triangles forming each square. An ...

Combining the powers of Nextjs and Vue

Currently utilizing Vue.js, I am now looking to leverage the Next.js framework for its SEO capabilities, server-side rendering features, and other advantages. While I do have some experience with React, my primary focus is on mastering Vue.js. Is it poss ...

There was an error due to a TypeError: The 'page' property cannot be read because it is undefined

Can anyone assist me with an Angular issue I'm facing? I've been working on integrating server-side pagination, but no matter how many times I revise my code, I keep encountering the same error message: ERROR TypeError: Cannot read properties o ...

Issue with npm package mail-listener2: Attachments not being saved for emails received from Outlook 2016

I am attempting to retrieve attachments from Outlook, saving them in a specific folder as outlined in the configuration: { username: "username@here", password: "password", host: "hostName", port: 993, connTimeou ...

Angular Universal Resolve

I am trying to ensure that an asynchronous call completes before any of my routes are resolved by modifying route.resolve as follows: var originalWhen = $routeProvider.when; $routeProvider.when = function(path, route) { route.resolve || (route.resolve ...

Selenium: The ultimate guide to inserting text within a div element located inside an iframe

Snippet of HTML code: <div class="listRte__editorFrame"> <iframe src="about:blank" style="height: 150px;"> #document <html> <head> <body> ...

Implement event listeners for multiple buttons using Handlebar.js templates, but only the final one will be active

For a homework assignment, I am developing a web app that utilizes websockets to receive server messages and then displays them on an HTML page using handlebars.js. One feature I am trying to implement is the ability to delete a message with the following ...

Error: The integer provided in the Stripe payment form is invalid in the

I'm encountering an error that I can't seem to figure out. I believe I'm following the documentation correctly, but Stripe is not able to recognize the value. Have I overlooked something important here? https://stripe.com/docs/api/payment_i ...

Store the data from the form into the database according to the radio button choice

I feel like a fish out of water here...freshly dipping my toes into the ASP.net world, but finding it quite fascinating so far. Let me begin at the starting line: Background: I am currently working on an ASP.net MVC5 application that involves user login ...

Struggling to delete a table row using jquery

Currently, I am encountering an issue with removing a specific "tr" element within a table using jQuery. Here's the situation: I have a table where rows are clickable. Upon clicking on a row, I can update the data associated with that particular obj ...

I am interested in learning how to retrieve the page URL in order to trigger the opening of a menu in my sidenav bar

This is my navigation bar. I am trying to use JavaScript or jQuery to retrieve the current page's URL and open the corresponding dropdown container. I want to display the relevant section of the side navigation based on the URL. I have tried writing t ...

Is there a method to verify the presence of a message event listener already?

Is there a method to determine if a message event listener is already in place? I am trying to accomplish something similar to this: if(noMessageEventListenerExists) { globalThis.addEventListener('message', async function (data) {}) } I have ...

Easily move elements using a jQuery click animation

Having trouble animating a div's top position by -130px to move it off screen? Can't figure out why it's not working? I'm fairly new to jQuery/Javascript. I have a button/hyperlink with the ID #NavShrink. When clicked, I want the div # ...

Retrieve active route information from another component

We are utilizing a component (ka-cockpit-panel) that is not linked to any route and manually inserted into another component like so: .. ... <section class="ka-cockpit-panel cockpit-1 pull-left"> <ka-cockpit-panel></ka- ...

Leveraging webpack for CSS bundling

I'm currently working on bundling some NPM modules using webpack instead of utilizing a CDN. While I've successfully managed to integrate the .js files, I'm facing challenges with including the .css files for these modules. One example is ...

Is it possible to create personalized BBCode?

I currently manage my own forum where users can edit, delete, and report posts and replies. However, I am now looking to add new features such as BBCode. Specifically, I want to implement a [QUOTE][/QUOTE] feature that allows users to easily quote other po ...

Turn on/off the button click functionality on a jQuery smart wizard control

I am currently utilizing this particular control, which happens to be version 3 of jQuery Smart Wizard. Here is the code snippet for the smart wizard: $('#wizard').smartWizard({transitionEffect:'slide'}); These are some helper functi ...

Is it possible to utilize an API response within a conditional statement in NextJS?

I am working on a change password feature that interacts with an API for verification. If the current password entered is incorrect, I want to display an error message. If you have any suggestions on how to proceed or if there are any flaws in my approach ...