Problem involving semi-transparent textures with two sides

I'm having trouble creating a cage-like object on a canvas using three.js. It seems like there's a problem with the short sides of the cage. Despite my efforts, I can't seem to get them to behave correctly. You can view the jsFiddle I created here.
The front and back of the cage look fine (although when viewing from behind, it appears that the back texture is erasing the front one as you orbit around). Interestingly, the floor of the cage is still visible between the bars. However, the short sides are only visible if you position the camera in front of them while orbiting. The code for all sides of the cage is the same (except for the solid gray floor and transparent ceiling), which is shown below:

var cageTexture = THREE.ImageUtils.loadTexture(/*omitted, see fiddle*/);
cageTexture.wrapS = THREE.RepeatWrapping;
cageTexture.wrapT = THREE.RepeatWrapping;
cageTexture.repeat.set(10, 1);
var cageFaces = [
    new THREE.MeshBasicMaterial({transparent: true, map: cageTexture, side: THREE.DoubleSide}),
    new THREE.MeshBasicMaterial({transparent: true, map: cageTexture, side: THREE.DoubleSide}),
    new THREE.MeshBasicMaterial({transparent: true, opacity: 0, side: THREE.DoubleSide}),
    new THREE.MeshBasicMaterial({color: "gray", side: THREE.DoubleSide}),
    new THREE.MeshBasicMaterial({transparent: true, map: cageTexture, side: THREE.DoubleSide}),
    new THREE.MeshBasicMaterial({transparent: true, map: cageTexture, side: THREE.DoubleSide})
];
var cage = new THREE.Mesh(
    new THREE.BoxGeometry(2, 1.5, 1),
    new THREE.MeshFaceMaterial(cageFaces)
);

I need help figuring out what I'm doing wrong. Orbit around the scene by clicking and dragging to experience the issue firsthand. Please feel free to make edits to the fiddle. Thank you in advance.

Answer №1

To achieve your desired result, consider disabling the depthTest as transparent objects are sorted automatically. Sorting plays a crucial role in ensuring the smooth rendering of objects with varying degrees of transparency. (referenced from the WebGLRenderer documentation on sortObjects)

You can find a demo showcasing this concept in action at this JSFiddle link.

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

Developing a similar platform to Sketchfab

We are looking to develop a similar analogue of Sketchfab on our website, allowing users to view virtual object models. Can anyone provide information on the technologies used by Sketchfab and what is needed to bring this project to life? ...

Tips for sorting through various elements or items

How can I improve my filtering function to select multiple items simultaneously, such as fruits and animals, or even 3+ items? Currently, it only allows selecting one item at a time. I attempted using , but it had bugs that displayed the text incorrectly. ...

Stop objects from shifting while easily applying a border

I have a code that adds a red border around elements when you mouseover them and removes it when you mouseout. However, the elements jump around when the border is added because it changes their dimensions. Is there a way to stop this jumping behavior? ...

Guide on making a JavaScript button with both "light and dark" modes

Currently, I am attempting to change the color scheme of the page by adjusting the :root variables using a function called changeBackgrondColor(). This function is then assigned to the fontAwesome moon "button". However, when I click on the moon, the pag ...

Select2 - Issue with AJAX causing search results to not display in dropdown

Currently using Select2 version 4.0.1. Implemented ajax to display results based on user input, but facing an issue where Select2 does not list any results despite receiving the proper response from ajax. Additionally, the input box loses focus after the ...

Tips for sharing data between two components

In my project, I have a customized Shared Component which consists of an input search bar with a "continue" button. This Shared Component is being utilized within two other components - the buy component and sell component. The challenge I am encountering ...

Calculate the total length of the nested arrays within an object

Check out this object: const obj = { name: "abc", arr: [{ key1: "value1", arr1: [1, 2, 3] }, { key1: "value2", arr1: [4, 5, 6] }] } I'm looking to find a way to quickly calculate the sum of lengths of arrays arr1 and arr2. ...

Highlighting PHP files as JavaScript files in Sublime Text for improved readability

I'm working with a group of .php files in Sublime Text that primarily consist of JavaScript code with some PHP constants mixed in. Is there a way to configure Sublime Text to consistently highlight these files as JavaScript instead of PHP without havi ...

Using Express to request data from Mongo database and only receiving the path

I've been troubleshooting a websocket function that interacts with MongoDB to fetch some data stored in the system using 'get'. const User = require('mongoose'); const express = require('express'); const cal = require(&a ...

Countdown alert using JavaScript

Currently in my frontend code, I am utilizing angularjs as the javascript framework. In a specific section of my code, I need to display an error message followed by a warning message in this format: If a user inputs an incorrect month, then the following ...

The error thrown states: "TypeError: Unable to access the property 'getFieldDecorator' of undefined in a React component."

Encountering this error: > TypeError: Cannot read property 'getFieldDecorator' of undefined > _class.render src/containers/RegisterTenant/register.js:81 78 | this.setState({ 'selectedFiles': files }); 79 | } 80 | > ...

Execute a click event on a single button within a specified CSS class

When a button with the class of "my-button-class" is clicked on a page, I have JavaScript code set up to execute the logic defined in doSomething(). However, the issue I am facing is that the doSomething() function is triggered for every button with that c ...

What is preventing me from using javascript setInterval with a function in a separate external file?

Everything is running smoothly with this code snippet...an alert pops up every 10 seconds <script type='text/javascript'> function letsTest(){ alert("it works"); } var uptimeId = window.setInterval(letsTest, 10000); < ...

What causes CSS to fail to load in React but work normally in Next.js?

We are currently experiencing an issue with a component located in a Git Submodule that is being used by both Next.js and React. While everything is functioning correctly in Next.js, React is unable to accept the way the CSS is being loaded: import styles ...

Change the icon switch from fas fa-lock-open to fas fa-lock by adding an event listener for a click action

let lockIcon = document.createElement("i"); lockIcon.setAttribute("class", "fas fa-lock-open"); lockIcon.setAttribute("id", color + "lock"); Is there a way to toggle between the icons fas fa-lock-open and fas fa-lock when clicking using a ...

The Material-UI Button isn't able to trigger when the Popover is closed

Currently, I am working with Material-UI 4.11 and have implemented a Popover component along with a Button: Popover and Button <Popover id={id} open={open} anchorEl={anchorEl} onClose={handleClose} anchorOrigin={{ vertical: ...

Interacting with Zend forms using AJAX and JavaScript's onchange event

I'm currently working on a code that utilizes the onchange event in my application. Here's the code snippet I have so far: .Phtml <script type="text/javascript"> function submit() { $id = intval($_GET['id']) ...

Encountering difficulty in creating a Nuxt website using @googlemaps/js-api-loader

While using the @googlemaps/js-api-loader in my Nuxt 3 website, I encountered an issue. Everything worked perfectly during local development. However, when I attempted to build the project with nuxt generate (whether locally or on Vercel), I received the f ...

I am unable to display the content even after setting `display: block` using the `.show()`

Hello there, I have attached my javascript and html code. While in debug mode, I can see that the CSS property 'display: none' changes to 'display: block', but for some reason, the popupEventForm does not open up. Any suggestions on why ...

Issue with Vue-Multiselect: Unselecting a group of pre-loaded values is not functioning as expected

My code: https://jsfiddle.net/bgarrison25/tndsmkq1/4/ Html: <div id="app"> <label class="typo__label">Groups</label> <multiselect v-model="value" :options="options" :multiple="true" group-values="libs" g ...