Modifying the vertices of geometry to create a low poly terrain is causing unexpected black glitches to appear

I'm currently working on a project that requires creating random low-poly style terrain. To achieve this, I have come up with the following approach:

  1. Start by creating a BoxGeometry object to serve as the floor, adjusting the widthSegments and heightSegments beyond the default value of 100
  2. Access each vertex using the .vertices array
  3. Iterate through each vertex using a forEach loop on geomFloor.vertices
  4. In each iteration, generate a random number within specified limits (minimum and maximum y position for the vertex)
  5. Assign the generated random number to the current vertex's .y property
  6. Update the vertices accordingly

Here's the code snippet for this process:

function createFloorSecondScene(){ 
    var geomFloor = new THREE.BoxGeometry(20000, 1, 20000, 100, 1, 100); 

    geomFloor.mergeVertices();

    var randomFloorVertexPos;

    geomFloor.vertices.forEach(function(floorVertex){
        randomFloorVertexPos = Math.floor(Math.random() * ((0) - 
        (-90)) + (-90));

        floorVertex.y = randomFloorVertexPos;
        geomFloor.verticesNeedUpdate = true;
    });

    var matFloor = new THREE.MeshPhongMaterial({color: 
    Colors.grassGreen});
    matFloor.flatShading = true;

    var Floor = new THREE.Mesh(geomFloor, matFloor);

    Floor.position.y = -72.5;
    Floor.receiveShadow = true;
    Floor.castShadow = true;
    Floor.name = "floor";
    scene.add(Floor);
}

The Issue at Hand

While the floor appears as intended from certain angles and sections, there are strange black shapes in larger areas which disappear upon changing the camera angle using OrbitControls.

A visual representation of the issue can be seen here: https://i.sstatic.net/7eHdM.png

This problem may stem from the simplistic method used to manipulate the geometry's vertices, resulting in some overlapping vertices causing rendering anomalies.

Resolution Required

  • Main: Resolve the appearance of black shapes on the floor
  • If possible, provide insight into why this occurs only in specific spots and viewing angles
  • If my vertex manipulation is flawed or if there is a more effective way to generate random low-poly terrain, I would appreciate guidance on the correct coding approach

Answer №1

Transitioning to using the PlaneGeometry option can simplify the process of creating your terrain.

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

A guide on customizing column names in MUI Datatables through object keys

I'm currently facing an issue where I need to set the name of a column in MUI Datatables using an object key. Specifically, I want to set one of the column names with the first element of children.childName so that it displays a list of child names, b ...

Tips for effectively utilizing node modules that have yet to be installed without encountering any errors

I am looking to create a setup script for my NodeJS application. The script will: Establish system roles for users Create a root category for posts Finally, create a system admin user for the initial login These details will be saved in a database. Ad ...

Undefined value is returned for Vue 3 object property

Is there a way to extract additional attributes from the Keycloak object ? Currently, If I try, console.log(keycloak) it will display the entire keycloak object. Even after reloading, it remains in the console. However, when I do, console.log(keycloak.t ...

The Next.js middleware, specifically NextRequest.nextUrl.locale, will return an empty string once it is deployed

Encountering a bug in the next-js middleware The middleware function is returning a NextRequest param According to the documentation from Next.js: The NextRequest object is an extension of the native Request interface, with the following added metho ...

Determine the number of rows in an Excel spreadsheet using JavaScript

Currently, I am working on a codeigniter project where I need to upload an Excel file. However, before uploading the file, I want to display the number of records it contains. To achieve this, I decided to create a function within my script and then call t ...

Input a new function

Trying to properly type this incoming function prop in a React Hook Component. Currently, I have just used any which is not ideal as I am still learning TypeScript: const FeaturedCompanies = (findFeaturedCompanies: any) => { ... } This is the plain fun ...

Adding strings to an array according to the numerical value entered in an input field using JavaScript

Can we dynamically add a string to an array based on the quantity entered by the user in a field? For example, if a user adds an item to their shopping basket, the function() will add the SKU string to the array. However, if the user then updates the quan ...

It seems like I'm having trouble sharing a collection of objects

Hey there, here's where I currently stand. I've got some code that sends an array of items to a .NET WebAPI (c#). var stuff = []; $('#items').find('input').each(function(){ var text = $(this).val(); stuff.push({ ID: ...

React Hooks findByID method is throwing an error stating that it cannot read the property 'params' because it is undefined

As I dive into learning React hooks, I'm realizing that it's crucial to stay up-to-date with the latest trends in web development. Despite hours of research and tinkering around, I can't seem to wrap my head around some key concepts. The fac ...

Guide to inserting an index on Vue list templates in HTML

Can you review this code snippet below? It's embedded directly in an html page, no isolated components here. This code is designed for a Vue.js application. <div v-for="(screw, index) in form.screws " class="screw-module"> <input type ...

When a card is clicked in the parent component, data is sent to the child component in Angular. The card contains an image, name, ID,

How can I pass data from a parent component (nfts) to a child component (main) when a card is clicked? The card contains images, ids, names, and more information. I've attempted using @Input() but haven't been able to receive the value in the ch ...

A guide on retrieving the upload status of a file using an AJAX post request

Is there a way to retrieve the status of uploaded files when the user cancels the process while uploading multiple files using an ajax call? This is how I am currently making the ajax request to upload files: var request = $.ajax({ url: 'file ...

Retrieving the selected date from JqueryUI Datepicker after form submission

I am currently using an inline datepicker that fills in an input textbox. $("#left-calendar").datepicker({ altField: "#left-date-text" }); The left-date-text is located within a form, and upon submission with a submit button, it sends the data to a p ...

Checking the validity of a date range

Date 1: 23/05/2013 Date 2: 29/05/2013 Currently, I have two dateTimePickers named dtDateStart and dtDateFinish, along with a submit button. My goal is to implement validation on the Submit button click event so that it does not accept dates falling betwe ...

Can the input type of an input element inside a table cell be altered by referencing the table cell's id using javascript?

Need help with changing the type of an input element from password to text using JavaScript? The input element is located inside a <td> with the id "pass". Also looking to add a checkbox that toggles displaying or hiding the password value. I'm ...

Exploring the World of Infinite Scrolling with React.js and Material_ui

I am currently working on a project using react.js As part of this project, I need to implement a board with infinite scroll similar to Facebook I have a specific question regarding this implementation. When scrolling the board and loading more posts li ...

What is the best way to select the child of the second-to-last child?

In the structure of my HTML code, I have an unordered list with a class "menu" containing several list items and corresponding anchor tags like this <ul class="menu"> <li> <a href="#1"></a> </li> <div&g ...

Textbox value disappears after being updated

When I click on the edit link (name), the value from the database is displayed as a textbox. However, when I update another normal textbox (age), the value in the edit link textbox disappears. Strangely, if I input a new value into the edit link textbox, i ...

Using the ng-if condition in navigation is causing issues with functionality

Hey there, I'm having an issue with my navigation when using ng-if condition in ul. Can someone please assist me with resolving this problem? <nav id="menu" class="nav-main" role="navigation"> <ul class="nav nav-main ...

Navigating the world of cryptocurrency can be daunting, but with the right tools

Hello fellow developers, I've encountered some difficulties with cryptocurrency in my Nativescript project. I am attempting to incorporate the NPM package ripple-lib into my code, but I have been unsuccessful using nativescript-nodeify. How can I suc ...