Malfunctioning lines intersecting at the meeting point of two surfaces in THREE.JS

I've been dedicating my time to crafting a voxel game in JavaScript similar to Minecraft as a way to enhance my JS/TS abilities. However, I've hit a snag.

When rendering the voxels by creating multiple faces of blocks in a BufferGeometry, there appears to be a glitched line between two faces like shown in this image.
https://i.sstatic.net/UNggT.png

Here are some snippets of my code that might shed light on where the issue is originating:

The material used:

const texture = loader.load(this.instance.ressourceMapUrl);
texture.magFilter = THREE.NearestFilter;
texture.minFilter = THREE.NearestFilter;
const material = this.blockMaterial = new THREE.MeshLambertMaterial({
    map: texture,
    alphaTest: 0.1,
    transparent: true,
    vertexColors: THREE.VertexColors
});

The BufferGeometry setup:

const geometry = new THREE.BufferGeometry();
const positionNumComponents = 3;
geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(positions), positionNumComponents));
const normalNumComponents = 3;
geometry.setAttribute('normal', new THREE.BufferAttribute(new Float32Array(normals), normalNumComponents));
const uvNumComponents = 2;
geometry.setAttribute('uv', new THREE.BufferAttribute(new Float32Array(uvs), uvNumComponents));
geometry.setIndex(indices);
        
geometry.colors = new Float32Array(colors);
geometry.setAttribute( 'color', new THREE.BufferAttribute( geometry.colors, 3, true) );

geometry.computeBoundingSphere();

A snippet illustrating the vertexes of a typical chunk:

[0, 12, 0, 0, 12, 1, 1, 12, 0, 1, 12, 1, 1, 12, 0, 1, 12, 1, 2, 12, 0, 2, 12, 1, 2, 12, 0, 2, 12, 1, 3, 12, 0, 3, 12, 1, 3, 12, 0, 3, 12, 1, 4, 12, 0, 4, 12, 1, 4, 12, 0, 4, 12, 1, 5, 12, 0, 5, 12...]

The order in which vertexes are utilized:

let ndx = positions.length/3;
indices.push(
    ndx, ndx + 1, ndx + 2,
    ndx + 2, ndx + 1, ndx + 3,
);

The values for my far and near variables:

const near = 0.101;
const far = 240

Thank you for taking the time to go through this. While it might seem like a simple question, I've been grappling with this for a week now without finding a solution online.

Wishing you a wonderful day!

Answer №1

After much exploration, I identified the issue and its solution: The root cause was traced back to my textures. Due to the lack of precision with floats, it resulted in these erroneous lines.

To rectify this issue, I made a slight adjustment by shifting the corners used for my texture towards the center by 0.0001 units.

The arrangement of my textures within the texture map is structured as follows: [x1, y1 x2, y2]. To address this concern, I implemented the following steps:

let uv: [number, number, number, number] = ...;
let correction = uv[0] > uv[2] ? 0.0001 : -0.0001;
uv[0] -= correction;
uv[2] += correction;
correction = uv[1] > uv[3] ? 0.0001 : -0.0001;
uv[1] -= correction;
uv[3] += correction;

A heartfelt appreciation to all those who attempted to assist me, and I trust that this process will be beneficial to others facing a similar challenge!

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

Error: Unable to access the 'login' property of an undefined object

An error occurred: Uncaught TypeError: Cannot read property 'login' of undefined........... import Login from '../components/Login.jsx'; import { useDeps, composeWithTracker, composeAll } from 'mantra-core'; export const com ...

Creating a unique triangle in three.js

I am currently working on creating a custom triangle in Three.js. The current code is rendering the wireframe of the triangle, but nothing else. When I turn off the wireframe, it becomes invisible. How can I modify this to render a colored triangle? v ...

Toggle the ASP validation control using JavaScript

I am looking to control the validation of my form using JavaScript. When a user clicks on a radio button in a list (yes or no), 2-3 rows are displayed. If the user selects "Yes," they must enter input into a textbox in one of those rows. To enforce this, ...

What is the best way to display the text of a button once it has been clicked?

Trying to implement a fade-in effect on text when clicking a button. Any assistance would be greatly appreciated! $(".btnClick").click(function(event) { var x = $(this).text(); if (x == "PowerApps") { $(this).parent(".show-details").find('. ...

What is the best way to emphasize a link to the current page in vue.js?

I am working on a sidebar feature that displays several dynamically generated links (similar to creating notes and then linking to them): https://i.stack.imgur.com/1lxcy.png Users can add a new note by clicking the 'Add stage' button. The list ...

React's .map is not compatible with arrays of objects

I want to retrieve all products from my API. Here is the code snippet for fetching products from the API. The following code snippet is functioning properly: const heh = () => { products.map((p) => console.log(p.id)) } The issue ari ...

Is it accurate that JavascriptResult displays javascript on the page in a string format?

I am new to .NET MVC and have been experimenting with different return types in MVC. However, I am having trouble getting the JavaScriptResult to work. In my controller, I have the following code: public ActionResult DoSomething() { string s = ...

using single quotation marks for string keys in a JavaScript object

While working with nodejs, I encountered an issue when creating a list of objects with string keys and numbers as values. Upon logging the list using console.log(), I noticed that some keys had single quotes surrounding them while others did not. For exam ...

Expanding your JavaScript skills: Tackling nested object key and value replacements

I am looking to manipulate the values of a nested object using JavaScript. The structure of the object is outlined below. let jsonObj = { "service":[ { "name":"restservice", "device&quo ...

Using Javascript to dynamically add and remove elements on click

Whenever I click on a link, I am able to generate input, label, and text. However, I want to be able to delete these elements with the next click event on the same link: I've tried updating my code like this: var addAnswer = (function() { var la ...

Warning issued after numerous clicks

My goal is to implement an Alert System that notifies the user when they leave a field empty. Currently, if a field is left empty and the next button is clicked, an alert pops up. However, if the same field is left empty again and the button is pressed, mu ...

Using a loop to pass a template to a function and create a dynamic component

I am currently attempting to dynamically generate a component while looping through a list. However, I have encountered an issue where the template cannot be passed to the function for creating the component. The error message indicates that the viewCont ...

A guide on extracting and displaying animations using react-three-fiber

I recently came across a .gltf animated model that I was able to load successfully, but unfortunately, I couldn't play the embedded animation. Is there any way to fix this issue? By the way, I am working on this in react. Thank you in advance. If you ...

Is it advisable to utilize jQuery's parseJSON/getJSON functions?

Upon examining the jQuery parseJSON function, I discovered that it essentially performs a basic regex validation: parseJSON: function( data ) { if ( typeof data !== "string" || !data ) { return null; } // Remove leading/trailing white ...

Analyzing a CSV file and executing asynchronous operations on specific columns with the help of ajax requests

I possess a CSV file that contains placement links and target links formatted as follows: CSV Example [placement url],[target url] [placement url],[target url] [placement url],[target url] My objective is to parse the CSV file line by line using JavaScri ...

Angular UI failing to refresh despite Observable subscription activation

I'm facing an issue with my Angular page where the UI is not updating when the observable parameter from a service changes. I've experimented with storing the observable result in a flat value and toggling a boolean to update the UI, but none of ...

Update Button Colour upon clicking the Button

I have multiple buttons lined up in a row on my webpage. I want the button's color to change when I click on them. Below is a snippet of my code: $( "button.change" ).click(function() { $(this).toggleClass( "selected" ); }); .Button { font-fa ...

Change the background color of a table cell based on its value with the help of JavaScript

I am attempting to apply color to cells in an HTML table (generated automatically by Python and Django) based on the content of the cells. Below is my table. I want to specifically color the column "status". Whenever the word "Cloture" appears, I would li ...

Having trouble with test coverage in Mocha using Blanket?

I have a Node application that I want to test and generate a coverage report for. I followed the steps outlined in the Getting Started Guide, but unfortunately, it doesn't seem to be working correctly. In my source code file named src/two.js: var tw ...

One div on Chrome for Mac is experiencing an issue with applying the background image

I currently have a website hosted on GitHub pages at this link: When viewing the site on Windows Chrome, the bottom div containing the filtering buttons blends seamlessly with the dark grey background set in the wrapper div. However, when viewed on Mac Ch ...