rescaling and replicating a pattern in three.js

I have a large plane with a set displacement map and scale that I want to remain unchanged. I just need the loaded texture to be applied to the mesh without scaling up too much.

Right now, a floor texture doesn't look natural because it has been enlarged to fit the large plane size. How can I reduce the texture scale and distribute it across the plane to resemble actual terrain?

const tilesNormalMap = textureLoader.load(
  "./textures/Stylized_Stone_Floor_005_normal.jpg"
);
function createGround() {
  let disMap = new THREE.TextureLoader().load("./models/Heightmap.png");

  disMap.wrapS = disMap.wrapT = THREE.RepeatWrapping;
  disMap.repeat.set(4, 2);

  const groundMat = new THREE.MeshStandardMaterial({
    map: tilesBaseColor,
    normalMap: tilesNormalMap,
    displacementMap: disMap,
    displacementScale: 2
  });

  const groundGeo = new THREE.PlaneGeometry(300, 300, 800, 800);
  let groundMesh = new THREE.Mesh(groundGeo, groundMat);
  scene.add(groundMesh);
  groundMesh.rotation.x = -Math.PI / 2;
  groundMesh.position.y -= 1.5;

I attempted to use the .repeat method as shown below but couldn't quite figure out how to implement it

 tilesBaseColor.repeat.set(0.9, 0.9);
 tilesBaseColor.offset.set(0.001, 0.001);

here is a picture of the current ground texture enter image description here

Answer №1

At the moment, achieving your desired outcome with three.js is not feasible because there can only be a single uv transform for all textures, except for light and ao map. In your case, the map takes precedence, so having different repeat settings for the displacement map is not possible. For more information, refer to the related GitHub issue: https://github.com/mrdoob/three.js/issues/3456

The current floor texture appears distorted when upscaled to fit the large plane. How can I scale down the texture and distribute it evenly across the plane to resemble natural terrain?

To address this issue, utilize repeat values greater than 1 to prevent zooming into the texture. Follow the example below:

const camera, scene, renderer;

initialize().then(start);

async function initialize() {

  camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.01, 10);
  camera.position.z = 1;

  scene = new THREE.Scene();

  const loader = new THREE.TextureLoader();
  const terrainTexture = await loader.loadAsync('https://mytextures.com/example.jpg');
  
  // set repeat parameters
  
  terrainTexture.wrapS = THREE.RepeatWrapping;
  terrainTexture.wrapT = THREE.RepeatWrapping;
  terrainTexture.repeat.set(2, 2);

  const geometry = new THREE.PlaneGeometry();
  const material = new THREE.MeshBasicMaterial({map: terrainTexture});

  const mesh = new THREE.Mesh(geometry, material);
  scene.add(mesh);

  renderer = new THREE.WebGLRenderer({antialias: true});
  renderer.setPixelRatio(window.devicePixelRatio);
  renderer.setSize(window.innerWidth, window.innerHeight);
  document.body.appendChild(renderer.domElement);

}

function start() {

  renderer.render(scene, camera);

}
body {
      margin: 0;
}
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5232350f060313393724212d30373b227c363039">[email protected]</a>/build/three.min.js"></script>

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

The innerHTML feature in Javascript seems to be malfunctioning

Having a simple javascript issue here. I am attempting to retrieve a date from a textbox and display it in a label for another purpose. However, I encountered some problems along the way. I can successfully alert the date retrieved from the textbox, but wh ...

Hiding the div element with 'display: none' causes the disappearance

Whenever I execute this piece of code; document.getElementById("loading").style.display = "none" It unexpectedly hides the div named "myDiv" as well. By setting MyDiv to block, the text appears correctly. However, when loading is set to none, it strange ...

Using jQuery to modify the caret class when clicked

I'm looking to create a toggle effect for the caret icon in my HTML code. The initial class is fa fa-caret-down, and I want it to switch to fa fa-caret-up when clicked, and vice versa. I've attempted to achieve this with the following jQuery: $( ...

How to change class names dynamically in Vue.js?

I am looking for a way to dynamically change the background color based on a review rating using Vue.js. Ideally, I would like to achieve this with the following code: <div class="review" :style="reviewColor(hotel.average)"> In my methods section, ...

Issue in Three.js: Implementing an image texture leads to the disappearance of other elements

Trying to create a space time cube and ran into an issue with a strange bug when adding a texture to the bottom of the cube (which is a plane in my design). The objects just above the plane are sometimes not visible and the image becomes distorted. It&apos ...

The selection will remain hidden and attempting to make a choice will be ineffective

Received an HTML sample from another company () and now I am attempting to create a web form based on it (). Using the same scripts, the basic structure mirrors the sample closely. After meticulously comparing the code, I can't find any discrepancies. ...

I'm experiencing trouble with Shopify as it appears to be failing to execute

I have been attempting to incorporate a tracking pixel into my project. Thus far, I have tested the code in various environments, both with and without wrapping it in a function and deploying it using window.onload. If you would like to see the implementa ...

The issue arises when attempting to use a JavaScript marker within an array, as it

At the moment, I am in the process of building a website that includes a Google map showcasing my custom markers. Each marker is linked to a specific URL, and the connection is straightforward (as shown with one of my markers below) - var image = 'p ...

The choice between using inline style objects with React or utilizing traditional CSS classes presents distinct advantages and

Is there a discernible difference between utilizing an inline style object for react components and using a normal CSS class through the className attribute? Even when wanting to modify styles based on a specific event, simply changing the className should ...

The process of saving report filters and making them accessible for both running and scheduling tasks

I am facing a use case where I need to add query parameters to API calls and save them for future use. Essentially, I have a report that requires multiple filters to be saved - some predefined and others customizable. These saved filters can then be execut ...

Perform calculations using the provided input values or null values in Javascript/Jquery

I'm a beginner in Javascript and JQuery. Take a look at my code that calculates an average (A) value based on three input values. https://i.sstatic.net/teGkc.png Check out the JQuery snippet below: $(".q-value, .e-value, .t-value").click(f ...

Tips for keeping a div element at the top of the page

I am looking to have a div stick to the top of the page when someone scrolls down When the page is scrolled, the green div with class stickdiv should automatically stick to the top var left = document.getElementsByClassName("stickdiv"); for( var i = 0; ...

The tabbing feature in bxslider disrupts the alignment of slides, making it

After encountering accessibility issues, I upgraded the bxslider library to version 4.2.3 for better support. Check out this example of bxslider where you can easily tab through the controls: http://jsfiddle.net/qax7w8vt/2/embedded/result/ The problem a ...

Generating symbols that combine both images and text seamlessly

I am working with a circle image that I need to resize based on its placement. This image is intended to be a background for a character or two of text. Specifically, whenever the number 1 or 2 appears in a certain element, I want the circle to appear beh ...

Breaking down a statement into individual elements within an array, incorporating keys alongside the elements within the array

let condition = "[AccNum]==true&&[AccNum]==[ARID]&&[AccNum]==aaaa || [ARID]!=true&&[DOB]&gt;[ARID] || [DOB]&gt;bbb&&[DOS]&gt;=[ARID]&&[DOS]&lt;[Gender]&&[66642]&lt;=cccc&&[66642] I ...

Challenge yourself with the act of dragging and dropping multiple times using only Javascript

I'm currently working on implementing a drag and drop functionality from one column to another. The goal is to allow multiple copies of an element from the left list to be placed in the right list. Each copy will have a unique ID assigned before being ...

Challenges with Hangman in JavaScript

As a beginner in JavaScript, I recently developed a simple hangman-like game. However, I encountered some challenges that I need help with. One issue is related to my lettersGuessed array. Currently, the array displays every time a key is pressed and repea ...

Dynamic scrolling text for overflowing text display

Here's a scenario I'm facing: Let's say I have three div tags, each 100 pixels wide: <--- DIV WIDTH ---> Text in div 1 Text in div two, it overflows Text in div three <--- DIV WIDTH ---> Currently, I've set the following C ...

Using jQuery to create clickable URLs within a rollover div

I am looking to have the div appear on a mouse over effect in the following code. Is there a way for me to input a url based on the data that is passed to it? Anchorage: ["Anchorage", "(555)555-5555"], (This represents the data being posted) AtlanticCit ...

Looping through properties of objects with the help of angularJS ng-repeat is known as using objects['propertyname&#

What is the best way to iterate over an object with property names like this? $scope.myobjects = [ { 'property1': { id: 0, name: 'someone' } }, { 'property2': { id: 1, name: ' ...