Creating translucent mesh in Three.js with intersecting triangles

I am trying to create a unique transparent shape made up of multiple overlapping triangles. Below is the code I am currently using:

geometry = new THREE.Geometry();
material = new THREE.MeshBasicMaterial({
    color: 0x00ff00,
    side: THREE.DoubleSide,
    transparent: true,
    opacity: 0.2
});


mesh = new THREE.Mesh( geometry, material );
geometry.vertices.push(new THREE.Vector3(100, 0, 1));
geometry.vertices.push(new THREE.Vector3(0, -200, 1));
geometry.vertices.push(new THREE.Vector3(200, -200, 1));

geometry.vertices.push(new THREE.Vector3(0, 0, 1));
geometry.vertices.push(new THREE.Vector3(200, 0, 1));
geometry.vertices.push(new THREE.Vector3(100, -200, 1));
geometry.faces.push(new THREE.Face3(0,1,2));
geometry.faces.push(new THREE.Face3(3,4,5));

To see the issue I am facing with this code, please visit this jsfiddle http://jsfiddle.net/7wk0cfcj/

The current code produces a shape with a darker area in the middle caused by the overlap of triangles. I want the mesh to appear as a single transparent object with consistent color throughout. Is there a solution to achieve this without modifying the triangles to prevent them from overlapping?

Answer №1

By modifying the z test function on the material, it is possible to prevent redundant drawing in the same location for your selection since the Z value remains constant.

This functionality has not been officially rolled out in three.js; it currently exists in the development branch.

http://jsfiddle.net/fgaudet/7wk0cfcj/5/ contains an external reference to the development branch...

material = new THREE.MeshBasicMaterial({
    color: 0x00ff00,
    side: THREE.DoubleSide,
    transparent: true,
    opacity: 0.2,
    depthFunc: THREE.LessDepth
});

Answer №2

Enhance your Material:

blending: THREE.NoBlending

The trade-off is that you lose the ability to see through objects, making anything behind the triangles invisible.

Check out this demo for reference!

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

Looking for a way to extract a dynamic URL from a website's div element?

Is there a way for my app to load dynamically by extracting and reading the changing URL from a webpage? //webpage <div style="display:none" id="urladdress"> //dynamic url **https://freeuk30.listen2myradio.co ...

SystemJS is loading classes that are extending others

In my Angular2 application, I have two classes where one extends the other. The first class is defined in the file course.ts (loaded as js) export class Course { id:string; } The second class is in schoolCourse.ts (also loaded as js) import {Cours ...

Getting the execution time of a JavaScript function with Puppeteer - a simple guide

In my project, I'm working on logging the time it takes to execute functions. Right now, I'm using the tracing.start method to obtain the trace data. However, I'm struggling to understand how Chrome DevTools calculates the time taken by each ...

Incorporate %20 instead of " " in a fetch call

Although the question of how to replace spaces with %20 has been asked on SO, I am specifically looking for guidance on where to implement this in my setup. My frontend is built using React Native and my backend uses NodeJS (ExpressJS) connected to a Postg ...

The React JSON Unhandled Rejection problem requires immediate attention

While working on a form in React 16, I reached out to a tutor for some guidance. However, when trying to mock the componentDidMount, I encountered an error that has left me puzzled. The app still runs fine, but I am curious as to why this error is occurrin ...

Searching for Bluetooth devices using React Native

In my project, I am working on scanning HM-10 BLE with a react-native app. To achieve this, I referred to the example provided in Scanning for Bluetooth devices with React Native. So far, the library seems to be successfully installed without any errors du ...

Tips for bringing in and adding an excel spreadsheet to a kendo grid with the help of JQuery

I am facing a challenge with my kendo grid as I am trying to incorporate an excel file into it. Specifically, I would like to import and add an excel file to my kendo grid. If, for instance, my kendo grid initially has 3 rows, after importing an excel file ...

Having trouble integrating the circular progress bar into the movie card and getting it to align properly

Struggling to position my react circular bar for movie rating in the bottom corner of the movie card. The classes are not working as expected, even though I tried to replicate it from another website using React and SCSS while I'm utilizing Material-U ...

What steps can be taken to prolong the duration of a service?

As a newcomer to angularjs, I am struggling to find documentation or examples on how to extend a basic service in order to utilize its methods from other services. For example, consider the following basic service: angular.module('myServices', [ ...

Having trouble accessing a CSV file with JQuery and FileContentResult?

How can I make an ajax call without using ActionLink in my controller? Here is a snippet of my controller code: public IActionResult ExportUsers(List<string> listOfEmails) { /*some data processing*/ return File(result, "text/csv", ...

I possess an array with a specific structure that I wish to substitute the keys as demonstrated below

The data array is currently structured in this way. I have attempted various methods but have not been able to find a suitable solution. I need to send the JSON below via an AJAX request, however, I do not want the keys 0 and 1 in both child arrays. [sch ...

When a specific string is found in a textbox, trigger a function in JavaScript

Is there a way to search for a specific string within a large text box that contains 200 words? I would like to create a function that can color the string. For example, if the sentence "my dog is happy" is in the textbox and I want the word "dog" to be ...

Error: Functionality cannot be achieved

Looking for assistance in resolving this issue. Currently, I am attempting to register a new user and need to verify if the username already exists or not. Below is the factory code used for this purpose: .factory('accountService', function($res ...

Navigating the complexities of custom directive attributes within Angular can be a daunting task

I'm feeling a bit lost as to why this isn't functioning properly... Here's the directive I am working with: app.directive('dateDropDowns', function () { function link($scope, elem, attr) { console.log($scope.startYear); }; ...

Having trouble with Vue 3 Composition API's Provide/Inject feature in Single File Components?

I am currently developing a VueJS 3 library using the Composition API. I have implemented Provide/Inject as outlined in the documentation. However, I am encountering an issue where the property in the child component remains undefined, leading to the follo ...

Tips for automatically minimizing the size of PDF documents using Node.js and Javascript

After exploring solutions for PDF size reduction in other programming languages like Object C, Swift, and Java, I am curious if there is a well-established method or package available for reducing the size of PDF files using Node. Currently, my backend u ...

Creating a Chrome extension that opens multiple tabs using JavaScript

Currently, I am working on a chrome extension that includes several buttons to open different tabs. However, there seems to be an issue where clicking the Seqta button opens the tab three times and clicking the maths book button opens the tab twice. Below, ...

What methods can I use to evaluate the efficiency of my website?

Is there a way to assess and improve website performance in terms of load time, render time, and overall efficiency? I've heard of YSLOW for firebug, but am curious if there are any other tools or websites available for this purpose. ...

Effortless side-to-side and up-and-down scrolling

I recently launched a new website and I am looking to implement smooth horizontal and vertical scrolling. I want to have a menu on the right side that allows users to easily navigate to different sections. While I have found helpful codes and guides for ...

Steps for retrieving JSON data successfully following an asynchronous AJAX request in JavaScript

When submitting a form using AJAX, I need to pass successful data back to the submission page. The transaction is being sent over the TRON network, and the response is an array containing the transaction ID that needs to be returned to the submission page. ...