Tips for adding texture to a three.js Mesh constructed using ShapeGeometry

Currently, I am attempting to apply a bitmap texture material onto a Mesh that has been created from a three.js ShapeGeometry.

The geometry itself is quite simple, resembling an octagon (although my ultimate goal is to round the edges to make it more of a rectangle).

After successfully creating and displaying the Mesh, I noticed that the bitmap texture appears as four large squares, giving off the appearance of a super low-resolution version of the actual image being loaded.

Just to provide some context, the image I am loading is a 512x512 picture of the French flag.

My main question at this point is: how can I ensure that the texture utilizes the full resolution of the loaded image? (Interestingly, this texture functions perfectly when applied as a material to a Mesh generated from a THREE.PlaneGeometry.)

Below is the code snippet I am working with:


var shape = new THREE.Shape();
shape.moveTo(-width/2 + radius, height/2);
shape.lineTo(width/2 - radius, height/2);
shape.lineTo(width/2, height/2 - radius);
shape.lineTo(width/2, -height/2 + radius);
shape.lineTo(width/2 - radius, -height/2);
shape.lineTo(-width/2 + radius, -height/2);
shape.lineTo(-width/2, -height/2 + radius);
shape.lineTo(-width/2, height/2 - radius);
shape.lineTo(-width/2 + radius, height/2);
var myGeometry = new THREE.ShapeGeometry(shape);

var myMesh = new THREE.Mesh(myGeometry, myMaterial);

I appreciate any guidance or assistance that you can offer! Thank you!

Answer №1

THREE.ExtrudeGeometry.WorldUVGenerator
is the standard UV generator for THREE.ShapeGeometry.

This default UV generator assigns the UVs to match the vertex coordinates.

If you want to use a custom UV generator with THREE.ShapeGeometry, you'll need to provide one yourself. Check out the source code for guidance on how to do this.

An alternative approach is to increase the size of your model by a factor of 10, and then adjust the scale using mesh.scale.set( 0.1, 0.1, 1 ).

Another option is to modify your shape geometry so that its vertices span the [ 0, 1 ] range - after which you can apply mesh.scale if desired.

Works with three.js version r.61

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

What is the method for combining a number with a variable designation?

Hey there, I'm having some trouble changing the variable name in a loop. I attempted to use a for loop with "stop" + i, but it didn't quite work out as I had hoped. Any assistance would be greatly appreciated! ...

Is it possible for a jQuery selector to retain its object? What can be done to prevent it

One interesting scenario involves a dropdown element within a container. <div class='container' /> <script> var dropdown = "<select class='multi-dropdown'> ... </select>" </script> Every time the value ...

Unable to locate javascript frame using webdriver

Recently, I encountered an unfamiliar issue while working on a Java program that checks store availability on websites like Staples. The problem seems to be related to entering information into a textbox found in a pop-up JavaScript window that appears whe ...

Error: CORS Missing Allow Origin is preventing access to the response body in a Laravel and Vue Js application

I am currently working on developing a Laravel 10 + Vue Js 3 application with separate project files for both. In my api.php file, I have the following login route: Route::post('/login', [LoginController::class, 'submit']); In my Vue.j ...

The error message "trying to access markers property of undefined in the render function" occurred

I encountered this error while running my react-native component and need assistance. An error stating "undefined is not an object (evaluating 'this.state.markers.map')" occurred. This error appears in the following locations: c:\proje ...

What is the best way to retrieve the dimensions of a custom pop-up window from the user?

Currently, I am in the process of developing a website that allows users to input width and height parameters within an HTML file. The idea is to use JavaScript to take these user inputs and generate a pop-up window of a custom size based on the values pro ...

Filter search results using selected region from dropdown menu

I have been attempting to retrieve the value from a dropdown list and customize the search functionality specifically for the selected field. The client should only be able to search within the chosen zone in the dropdown. I have been searching for a solut ...

Error message occurred stating "error running npm start due to spawn C:WINDOWSSystem32WindowsPowerShellv1.0powershell ENOENT"

Whenever I attempt to run npm start, this is the issue that arises. It seems like there might be a problem with PowerShell rather than npm because npm successfully starts the development server. By the way, I created a basic React app using npx create-reac ...

Grid Column with Checkboxes in Kendo UI for Vue

Seeking help in adding a checkbox column to a Kendo UI Vue grid. The column should display the values of a boolean field from the grid's data source. While I am aware of how to add a checkbox column for selection as demonstrated here: https://www.tele ...

Utilize Three.js to dynamically rotate objects within a moving Object3D element, ensuring they constantly face the camera

As someone who is relatively new to Threejs, I am curious about how to ensure that a moving mesh always faces the camera in a scene. Within a container Object3D, there are 100 meshes, and I am rotating this container on the x and y axis. Is there a method ...

Slide your finger to adjust the location of a 3D model within the Three.js environment

Having trouble with a three.js example that allows me to rotate, zoom in, and zoom out a 3D object, but I can't figure out how to change its position by dragging. Any assistance would be greatly appreciated. Check out the example here. ...

Prevent the keyup event from being executed twice

I need help creating a table with two columns and an entry for modification. However, whenever the modify function runs after the first row, it executes twice and prevents me from editing the second column. Here's the code for the modifier: function ...

Validating forms in express.js

I need to validate a form that includes user details. In addition to the basic validation for checking if fields are not empty, I also want to verify if the username/email exists in the database. For the email field, I need to ensure it is not empty, follo ...

The text box isn't displaying the value, even though it was functioning properly just two days back

<html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> function insertParamIntoField(anchor, param, field) { ...

Setting a function key, such as F2, to quickly rename a tab is a convenient way to

Looking at the screenshot provided, it is clear that renaming a selected tab requires clicking on it, while deleting an unselected tab necessitates a mouse hover. Unfortunately, these actions are not accessible via keyboard shortcuts. To address this issue ...

How can nested components be rendered in Vue.js? Let's explore this concept with a straightforward example

I am completely lost. I am struggling to figure out how to properly register and render a component nested within another component. Can someone please run this example, click on the About link, and take a look at the console? There seems to be a warning a ...

How can I store multiple dropdown values as an object in a single database cell using Laravel?

Here is a dropdown menu with multiple selections: <select multiple size="4" name="darha[]"> @foreach($doors as $door) <option value="{ image: '{{ $door->image }}'; code: '{{ $door->code }}'}"{{ $door->code }}</opti ...

Button-operated lightbox image slider

I am currently developing a website on WAMP where users can store images and view them in a lightbox effect. I have successfully implemented the lightbox effect, but I am facing challenges with moving between images within the lightbox. <html> <? ...

Updating array of documents in MongoDB with a new array of documents

Is there a way to properly update an array of objects in a collection without having to remove and re-insert them? I am worried about losing data if the insert operation fails after removing the existing array. How can I efficiently update all documents in ...

Python, BeautifulZoup, and Selenium come together to create a powerful web scraping tool

I'm currently in the process of extracting property information from a website known as hotpads.com. As I input a URL containing numerous listings (for example, link), my goal is to delve into each property and retrieve additional details for downloa ...