Unable to view through transparent merged geometry in three.js

Could someone assist me in understanding why, when merging the geometries of these boxes, I am encountering visibility issues from certain angles?

Blue boxes represent normal individual boxes, while Orange boxes are the result of merged geometries. I am using MeshLambertMaterial with an opacity of 0.5.

Thank you in advance for any help or insights.

code: https://codesandbox.io/s/three-alpha-issue-bfdhk?file=/src/index.ts

screenshot: https://i.sstatic.net/NWD8D.png

code fragment:

// create boxes and add them to the scene (right, blue)
const boxGeo = new BoxGeometry(0.1, 0.1, 0.1);
const mat = new MeshLambertMaterial({
  transparent: true,
  opacity: 0.5,
  color: "#4469BE"
});
const boxes = [
  [   0,    0,  0.1], [   0,    0, -0.1], [   0, 0.15,  0.1], [   0, 0.15, -0.1],
  [0.15,    0,  0.1], [0.15,    0, -0.1], [0.15, 0.15,  0.1], [0.15, 0.15, -0.1]
].map((v) => {
  const box = new Mesh(boxGeo, mat);
  box.position.fromArray(v);
  box.updateMatrix();
  return box;
});
const group = new Group();
group.position.x = 0.1;
group.add(...boxes);
scene.add(group);

// merge boxes and add them to the scene (left, orange)
// issue: you can't see through some merged boxes from some angles
const geos = boxes.map((m) => m.geometry.clone().applyMatrix4(m.matrix));
const geo = BufferGeometryUtils.mergeBufferGeometries(geos);
const mergeMat = mat.clone();
mergeMat.color = new Color("#fa6900");
const merge = new Mesh(geo, mergeMat);
merge.position.x -= 0.25;
scene.add(merge);

Answer №1

To resolve the issue, you have the option to specify either depthWrite: false or depthTest: false for the material.

const mat = new MeshLambertMaterial({
  transparent: true,
  opacity: 0.5,
  color: "#4469BE",
  depthWrite: false,
});

I found this solution while looking into a problem related to material transparency overlapping with itself, as discussed in a similar question.

For a more in-depth explanation of the distinction between the two options, you can visit .

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

Exploring a JavaScript function that triggers another function to create a new object - Utilizing Sinon and Mocha for testing purposes

I am currently working on a nodejs application where I need to write a test for a function that invokes another function to create a new object, and then calls a method of that object. Below is the code in service.js that I am trying to test; // servic ...

Automated tool for generating random JSON objects

Looking for a tool that can generate random JSON objects? I'm in need of one to test my HTTP POST requests and incorporate the random JSON object into them. Any recommendations? ...

Encountered an issue while installing npm dependencies for webtorrent: "Error: Unable to locate 'fs' - Fountain-Js (Yeoman)"

Having trouble installing an NPM dependency in my code. Successfully installed the module using this command: npm install --save webtorrent This is the content of my package.json file: ./package.json { "dependencies": { "angular": "^1.5.0" ...

Using jQuery's slideToggle feature to hide content when clicked again or when a different button is

I have a challenge with creating toggle buttons that require specific functions: 1) Display content on the first click (this is working) 2) Conceal content when another button is clicked (this is also working) 3) Hide content on the second click (this i ...

Tips for Keeping Sub Menu Visible Without Having to Click

I am working on an HTML navigation menu that opens submenus on click like this... $("#nav_evnavmenu > li > a").click(function () { // bind onclick if ($(this).parent().hasClass('selected')) { $("#nav_evnavmenu .selected div div ...

Why won't NextJS Image elements render on iOS 16 when they are not in the viewport initially?

I opted to implement NextJS for enhanced routing capabilities and image optimization. However, I encountered an issue with certain images failing to load properly on iOS devices. The problem arises within a scrollable horizontal container featuring Product ...

Unable to properly cancel a post request using abort functionality

In the process of building a Next.js app, I encountered an issue with calling a post request. I included a cancel button to halt the post request, and attempted to use abortController in conjunction with Axios (v1.4.0) to achieve this. Even though the &ap ...

The class type "selectLabel" passed to the classes property in index.js:1 for Material-UI is not recognized in the ForwardRef(TablePagination) component

Just started using react and encountering a repetitive error in the console after adding this new component. Here is the full error message: Material-UI: The key selectLabel provided to the classes prop is not implemented in ForwardRef(TablePagination). ...

What is the reason behind localStorage.getItem consistently returning a string value?

Something strange is happening. In the lib.dom.d.ts file, the type for localstorage.getItem shows as 'string | null', but in my app it always returns a string. Why is this discrepancy occurring? ...

Complete AJAX event: matching URL using regular expressions

After a specific ajax request is completed, I am attempting to execute a function. To target the desired request among multiple requests on the site, I am using settings.url as outlined in the official documentation: $( document ).ajaxComplete(function( e ...

Utilizing Selenium with Python to choose a specific option from a dropdown selection

I am currently experimenting with using Selenium in Python to choose the option "Custom date" from the dropdown menu displayed in the image below: https://i.sstatic.net/ASHU2.png The hierarchy of divs is structured as shown here: https://i.sstatic.net/xtA ...

Adding pixels to the top position with jQuery in Angular 2

I am trying to adjust the position of my markers when the zoom level is at 18 or higher by adding 10px upwards. However, my current approach doesn't seem to be working as expected. Can someone please assist me with this issue? You can view the code sn ...

I'm trying to set an object value for this select element, and while I have managed to do so, I am struggling to display the title of the selected object. Can anyone help me

I am struggling to display the title of the selected object in this select element. Can anyone help me understand why my code is not showing the title? Here is the code snippet: const [selectedCategory, setSelectedCategory] = useState(""); const categor ...

collecting user input in React.js

After doing some research on React.js from this website, I stumbled upon a piece of code that left me puzzled. As far as I can tell, the checkbox for isGoing will be pre-filled as true (checked) and the numberOfGuests will be set to 2. However, I found m ...

Use CSS and JavaScript to create a visually appealing and interactive tree structure. Give the tree a dynamic design

I have been experimenting with CSS and JavaScript to create a dynamic graph based on a data table. You can view the graph that I need to replicate using CSS and JavaScript in this PDF. The example provided below showcases what I am attempting to achieve, a ...

Navigating from a view to a controller in MVC to reach a different view: a step-by-step guide

I implement the MVC model using PHP, JS, HTML, and CSS. Additionally, I utilize CodeIgniter as my framework. I am looking to understand how to redirect to another controller. While on the Home page of my project, when clicking on "details" (div = prod_det ...

Continuously refresh the if/else statement

I'm currently facing an issue with my jQuery code regarding a responsive navigation bar. I am trying to add a class called 'mobile' to the navigation bar when it reaches close to the logo. Below is the snippet of my code: function respon ...

React Native: Javascript library with typings not recognized as a module

I am currently facing a challenge of integrating the Microsoft Playfab Javascript Library into my React Native app following the recommendations provided here. The library comes with typings and is structured as illustrated here. In my file playfabWrapper. ...

Establish the directive upon receiving the broadcast

Is there a way to trigger a directive when a specific event occurs on the backend and sets a value to false?... This is where the event is being captured .factory('AuthInterceptor', function($q, $injector, $rootScope) { return { ...

Using Vue3 to create a dynamic reference in a computed status, allowing for the repetition of a player multiple times in a table along with a play/pause

On the Vue3 page below, I have successfully integrated a player that displays a "play" icon when the player is stopped and a "pause" icon when it's playing. Now, my goal is to allow the player to repeat n times by placing it in a table. The challeng ...