Distortion of Textures on a Cylinder in ThreeJS

When I try to apply a texture to a cylinder geometry in THREE JS, I encounter some strange distortion issues with the texture. The problem can be clearly seen in this image:

https://i.sstatic.net/A80KH.png

The cylinder shape is generated using the following code:

var cylinderGeo = new THREE.CylinderGeometry(0.1, 1, 1, 4, 1, false, Math.PI / 4);
cylinderGeo.computeFlatVertexNormals();
var mesh = new THREE.Mesh(cylinderGeo);
mesh.position.x = 10;
mesh.scale.set(10, 5, 10);
mesh.material = new THREE.MeshLambertMaterial();

// LOAD TEXTURE:
textureLoader.load("/textures/" + src + ".png", function (texture) {
    texture.wrapS = THREE.RepeatWrapping;
    texture.wrapT = THREE.RepeatWrapping;
    texture.repeat.set(2,2);
    texture.needsUpdate = true;
    mesh.material.map = texture;
    mesh.material.needsUpdate = true;
});

It appears that the texture is being applied per polygon rather than per face. How can I ensure that the texture wraps around the cylinder correctly without any distortions?

EDIT: The dimensions of the texture are 256x256 pixels.

Answer №1

When constructing a pyramid, it is important to note that each side consists of two triangles. This structural aspect can be clearly observed in the demonstration provided on the CylinderGeometry documentation page.

The UV mapping for each triangle is set assuming both will retain the same scale, as demonstrated in the example. However, modifying one end of the cylinder alters the scaling but not the UV mapping.

To address this discrepancy, you have the option to adjust the UV mapping to compensate for the change or, as recommended, generate a new geometry with accurately defined UVs.

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's the best approach to trigger a Wordpress Audio Player refresh with SmoothState on page transitions?

I have integrated a Wordpress Audio Player using shortcode in the "header.php" file. In addition, I am also utilizing SmoothState for page transitions (). Which function should I use in the "callback" to reload the player on new pages? I have included j ...

When buttons contain an image instead of text, event.target.value will be undefined

I'm facing an issue with two buttons that are almost identical, except one includes an image while the other has text content. I have added onClick event handlers to both of them. Oddly, the event.target.value for the image button is coming up as und ...

Node.js Friendship NetworkIncorporating Friendships in Node

Currently, I have successfully set up a real-time chat application using node.js and socket.io. My next goal is to allow users to create accounts, search for other users by username, and send friend requests to start chatting. I have tried searching onlin ...

When transitioning between views in Angular App, it freezes due to the large data response from an HTTP request

I am encountering an issue with my Angular 9.1.11 application where it freezes after navigating from one page to another (which belongs to a different module with lazy loading). Here is the scenario: There is an action button called View Report that re ...

Creating unique image control buttons for each image within a div using a combination of CSS and JavaScript

How can I create image control buttons, such as close, resize, and rotate, for each individual image when hovering over it? Each image is contained within a draggable div. I want to display an image control button next to each image. This button should on ...

The state remains constant upon clicking

Below is the code snippet of my component: import React from "react"; import { useState } from "react"; import { Text, SvgContainer, Svg, Flex } from "../lib/styles"; import Modal from "./Modal"; const Credits = () ...

Creating an object in javascript with two arrays: a step-by-step guide

Looking for help with merging two different object arrays: array1 = [Object, Object, Object] array2 = [Object, Object, Object] Each Object in array1 has the structure: {property1 : "somevalue"} While each Object in array2 follows this structure: {prop ...

Creating and initializing arrays in JavaScript

Is it possible to declare and assign a variable within the same line, but not with an array? Why is that? var variable1 = 5; // Works var array1[0] = 5; // Doesn't work var array2 = []; // Works array2[0] = 5; ...

Connection between the view and the router's backbone

In my opinion, it is important to maintain isolation between the router and view in data-driven programming paradigm. They should only communicate with each other through model changes that they both subscribe to. However, I have noticed that different on ...

Exploring the capabilities of Three.js and OrbitControls in TypeScript

I am struggling to implement this example using TypeScript. I have included <script src="lib/three.min.js"></script> and <script src="lib/OrbitControls.js"></script> in the <head> of my html file, and the TypeScript file in t ...

Tips on creating vertical stacked content utilizing CSS

Has anyone come across this game before? https://i.sstatic.net/hFX9o.png I am trying to stack each card in a column, here is my fiddle jsfiddle. In my scenario, I have cards wrapped in div elements with a maximum height. If a card exceeds this height, i ...

The system was unable to locate node.js with socket.io

I'm having trouble locating the file. According to the documentation I reviewed, socket.io is supposed to be automatically exposed. Encountered Error: polling-xhr.js?bd56:264 GET http://localhost:8081/socket.io/?EIO=3&transport=polling&t=LyY ...

Issue with long text in a resizable table using jQuery tablesorter 2.31.1

My issue is that when I try to resize the columns in tablesorter, they snap back into place. The column width set with resizable_widths does not apply correctly until a column is manually resized. Despite setting the width of all cells to 120px, any cells ...

Center-align the table element

I've been struggling to center align this table element, specifically the one containing the square, but nothing seems to be working. Can anyone lend a hand in fixing this issue? <table> <tbody> <tr> <td>TURKEY - SU ...

Issue with loading Bootstrap modal correctly

I am currently developing a website using ASP.NET (Framework 4.0). The Master page includes all the necessary Bootstrap and jQuery files, as shown below. <link href="../assets/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> ...

Get the value of the button that has been clicked

I have a query regarding building a website that can be started via PowerShell. The PowerShell HTML code I am using is: $proxys = "" foreach ($email in $ADObj.proxyAddresses){ $proxys += "<button id='$email' name='alias&apo ...

What could be causing jest to throw an ERR_UNKNOWN_FILE_EXTENSION error when attempting to utilize a ts file as a custom testEnvironment?

I'm currently in the process of migrating my TypeScript project to a (pnpm) monorepo setup and encountering difficulties with running tests successfully. The issue seems to be related to jest, as I have a jest.config.js file that specifies a custom te ...

Creating an If statement tailored for a particular image source: a step-by-step guide

In the program I am running in Dreamweaver, there is a specific line of code that looks like this: function go() { if((document.test.test1.src == document.test.test2.src && document.test.test2.src == document.test.test3.src )) ...... ...... ..... ...

I keep encountering errors with TypeGuard

Looking for some guidance with typescript. Even after implementing a type guard (and including the '?' symbol), I'm still encountering errors in the code snippet below. Is the syntax correct or should I make changes to the tsconfig file? int ...

Calculate the total rows within a specified date range

Within my database, there is a column named IsStaff, which returns a value as a bit. This signifies whether a staff member in a company has an illness (1) or not (0). How can I construct an SQL query to count the occurrences of both 1's and 0's w ...