Using CanvasTexture to apply as a texture map on a 3D .obj model that has been

I recently imported a .obj file into my project using the following code:

OBJLoader.load('/models/model.obj', m => {
                    let model = m.children[0];
                    model.material = new THREE.MeshBasicMaterial();
                    scene.add(model);
                });

To modify the map separately, I decided to replace the default material with a THREE.MeshBasicMaterial.

Afterwards, I obtained a CanvasTexture and assigned it as the map:

let texture = new CanvasTexture(canvas);
model.material.map = texture;
model.material.needsUpdate = true;

Although this method seemed to work, I encountered an issue where the texture appeared 'zoomed in' on the object within the scene, displaying only the overall color of the texture without any fine details. Despite adjusting texture.repeat, I struggled to achieve my desired outcome:

I aim for the texture to cover the entire object completely and scale appropriately across all faces without any repetitions. The object was created in Blender and consists of multiple faces, hence my goal is to have the texture fill every face seamlessly.

Any suggestions on how I can accomplish this?

Edit: You can find the model I'm working with here https://drive.google.com/drive/folders/1y6NmxNpamCtWsiBPlDhndnvQbxYPVgB7?usp=sharing

Answer №1

Unfortunately, your OBJ file lacks the necessary texture coordinates to apply a texture as desired.

Thankfully, working with Blender should make it relatively easy to create the required texture coordinates. Additionally, I suggest exporting your model to the more up-to-date glTF format instead of sticking with OBJ. glTF is the preferred 3D format for three.js.

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

"Enhance your website with a unique Bootstrap 5 carousel featuring multiple

As a beginner in Bootstrap, I am currently working on an ecommerce template to learn about Bootstrap 5. I am interested in creating a carousel that displays multiple slides at once, like a products slider with left and right arrows. Is this possible in Bo ...

Sending non-textual data within a JQuery ajax POST request

I have encountered an issue related to sending data from a JavaScript application to a Node.js server for database query purposes. Despite trying to find a solution from various sources, I have been unable to resolve it. Here is the code snippet used to s ...

Tips for preventing Chrome from masking the background image and color on an autofill input

Google Chrome Browser has caused the background-color and background-image effects to be removed from the Username and Password input fields. Before autocomplete https://i.stack.imgur.com/Ww7Hg.png After autocomplete https://i.stack.imgur.com/hbG2C.png ...

Refreshing the page causes Material UI Button to revert to default styling

My question regarding the Material UI Button losing styling after a page refresh (link: Material UI Button loses Styling after page refresh) went unanswered, so I am reposting with a CodeSandbox included for reference: https://codesandbox.io/s/bold-resonan ...

Steps to manage the time delay between mousewheel events triggering

Currently, I am working on a website for a movie production company that showcases their various films in full-screen mode. Each video is listed and there is a function that automatically takes the user to the next video when a mousewheel event occurs. How ...

The voting system will increase or decrease by 1 to 5 during each round

Recently, I added a voting system to my website inspired by this source. It's functioning well, but there is an issue where each vote can sometimes count for more than one. You can view the source code on the original website and test it out live here ...

Update the ngModel value once input validation has been successfully validated

My input is defined as shown below <input id="xInputControl" name="xInputControl" type="text" xInput class="form-control" [(ngModel)]="x" #validated="ng ...

Activate a modal component in ReactJS when a click event occurs

I'm having trouble integrating ReactStrap Modal into my NavBar and I haven't found a solution yet. I created a handler function to be triggered on a click event, but I can't figure out how to call my login component from this handler functio ...

Using ES6 imports, create a wrapper function for a React higher order component that does not require a variable name

With the commonjs require method, I am able to achieve this: let wrapper = require('./wrapper') let Nephi = wrapper(require('./Nephi')) However, when using es6 import syntax, it appears that I need to do the following: import wrapper ...

When attempting to add objects to an indexedDB object store, an InvalidStateError is encountered

I have defined IndexedDB and IDBTransaction dbVersion = 1; var db; var dbreq; var customerData = { ssn: "444", name: "Bill", age: 35, email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d2b0bbbebe92b1bdbfa2b3bcabfcb1bdbf"& ...

Customized Bootstrap Dropdown with the ability to add text dynamically

I am working on a Bootstrap dropdown menu that allows users to generate expressions by clicking on the menu items. For example, when the "Action" item is clicked, it should insert {{Action}} into the textbox. The user can then type something like "Hello" a ...

Retrieving information from an external API in response to an express GET request

After reviewing the sample code in the gtfs-realtime-bindings library's documentation, I attempted to implement a similar logic within my router. However, I encountered issues with extracting the result from the request() route.get('/', (req ...

Unable to substitute a value using the useState hook in React

Whenever I click a key, I attempt to update the value of a variable but it appears not to be working as intended. ↓ The current implementation is not effective and needs improvement import React, { useState, useEffect } from 'react'; const Li ...

Utilize Bootstrap DataTable Sparkline to extract information from a comma-delimited string rather than an array

I have successfully implemented a Bootstrap DataTable component in my Asp.net Core MVC App to display data from my database. However, I am facing a challenge when trying to add a sparkline to a column. The sparkline component requires an array of values, b ...

Inline display malfunctioning

I am facing an issue while integrating ngTimepicker into my Angular project. It is functioning properly, but I am unable to inline the ngTimepicker inputs with the form input. Check out the plunker here I would like this section of HTML to be displayed in ...

Tips for declaring a non-reactive instance property in Vue.js with TypeScript

I am currently in the process of transitioning my Vue.js components to TypeScript. In accordance with the recommendations provided in the documentation, I attempted to utilize Vue.extend() for my component implementation. The code snippet for my component ...

Achieving intellisense functionality in TypeScript without the use of classes

Just dipped my toes into TypeScript, attempting to convert this basic JavaScript code to TypeScript. Here is the JavaScript code snippet: Item = {} Item.buy = function (id) {} Item.sell = function (id) {} I prefer not to use classes and would like to ut ...

Sending a JS function to a PHP script

I've been incorporating the Soundcloud API into my project and successfully implemented their record button on my website. Once the upload is completed, the code generates the URL of the newly created soundcloud file. My goal now is to pass that URL ...

Placing elements in Chrome compared to IE

I'm currently attempting to position elements in two rows using mathematical calculations. One of the elements, thumb_container, is a div that is absolutely positioned. Within this container, I am dynamically loading and appending image thumbnails usi ...

Having trouble customizing the HTML range input?

I am looking to customize the appearance of a range input slider. Specifically, I want the slider to be green for the lower portion (where the thumb has moved) and grey for the remaining section. I have successfully changed the default styles from blue and ...