Have you ever noticed that in Three.js / WebGL, when you have two planes and one or both are transparent, the plane behind can be hidden by the transparent plane on top? Why does this happen?
Have you ever noticed that in Three.js / WebGL, when you have two planes and one or both are transparent, the plane behind can be hidden by the transparent plane on top? Why does this happen?
My problem was resolved by setting the depthWrite
attribute to false
.
Creating a new THREE.MeshBasicMaterial with the following properties:
opacity: 0.25,
transparent: true,
side: THREE.DoubleSide,
depthWrite: false
Imagine you have a partially transparent image in *.png format. In this case, you can make use of the following code snippet:
const material = new THREE.MeshBasicMaterial({
depthWrite: false,
depthTest: false,
side: THREE.DoubleSide,
map: texture
});
One potential solution could be to include alphaTest: 0.5
in the material settings.
The behavior you are experiencing is not a bug, but rather a result of how OpenGL (and consequently WebGL) functions. Transparent surfaces do not interact well with the z-buffer, requiring manual sorting and rendering in a back-to-front sequence. While Three JS tries to handle this automatically (which explains why the issue disappears with X value > 0), it struggles to manage intersecting geometries like the ones in your case.
For a more detailed explanation, you can refer to a related discussion on a different SO thread.
Just a heads up, if you have numerous parallel planes (unfortunately, I can't view your sample as Google is unable to resolve your domain), it is simple to maintain their order along the perpendicular axis. When dealing with a series of planes [A B C D], they will either be drawn in the order [A B C D] or [D C B A], and no other sequence! This means there is no need to worry about any performance issues from sorting. Just ensure they remain in the correct order as you progress.
Using Mesh renderOrder
to resolve the issue at hand, the following snippet shows my implementation. Feel free to adjust the value of node.renderOrder
:
loader.load(model_url, (gltf)=>{
let scene = gltf.scene
scene.traverse((node)=>{
if(node.isMesh){
node.material.transparent = true
if(node.name === 'car_windows'){
node.material.opacity = 0.4
node.material.side = 0
node.renderOrder = 110
}
if(node.name === 'car_body'){
node.material.opacity = 0.4
node.renderOrder = 100
}
if(node.name === 'car_seats'){
node.material.opacity = .5
node.renderOrder = 90
}
mesh_arr.push(node)
mesh_objs[node.name] = node
}
})
})
I found success with this method; instead of using the value true for transparency, I recommend using the number 1.
object3d.material.transparent = 1;
Looking for help with a PHP script to calculate the sum of checked checkboxes with corresponding numeric values. For example, if checkbox 1 = 80; checkbox 2 = 21; and checkbox 3 = 15, and the user checks checkboxes 2 and 3, the PHP should output 36. I hav ...
Utilizing Firebase in my chat application, I am adding a timestamp to the chat object using the Firebase.ServerValue.TIMESTAMP method. I want to display the time when the message was received in the chat application using this timestamp. If it is the cur ...
I am encountering an issue with a JavaScript object in my application that contains an array object, which is a collection of objects with two properties (Name, Value) on the server-side. Despite my efforts, when the code reaches the C# web service, the C ...
Currently working on a JavaScript project to create a captcha display on a canvas. The issue I'm facing is that the background image does not load when the page initially opens. However, upon hitting the refresh button, it functions as intended. Here& ...
I am currently using sha1 encryption coding in PHP <?php echo hash('sha1', 'testing'.'abcdb'); ?> However, I need this encryption to work on a page named xyz.html, causing the current block of code to not function prop ...
I am looking to search for a specific value within an array and retrieve its index. Sample HTML: <div class="container"> <div class="col-md-6"> <div id="task0">Task0</div> </div> <div class="col-md-6"> &l ...
When working with JSON data from an API, I am creating a dynamic select element. The goal is to change some content (text and image src) based on the option selected from this select element. I have successfully populated the select options with names usi ...
I have 2 featured posts in 1 div id, one with a big class and the other with a small class. I want the big featured div to display posts based on categories. The code for the big featured post is shown below: <div class="main_feat"> ...
I'm not very familiar with regex, so I'm curious about the process of replacing a section in a string based on a regex pattern where the index is part of the identified section. Let's consider this example string: let exampleStr = "How do ...
Something seems off about the context in this code. I've left comments to describe my issue below: const cat = { //arrow function meow: () => { console.log(this); }, makeMeow(){ // Why does 'this' refer ...
Looking to implement a "lightweight offline database" that stores data in .csv files. The module I am using can be found in the documentation: https://www.npmjs.com/package/csv-db Unfortunately, I've been encountering issues with this module and have ...
Using the .each method, I constructed an options string and sent it via .post to an external script. clicked.closest("form").find("input,textarea").each(function(){ var input=$(this); if(index==1){ options = ...
Encountering a unique edge case, I found a solution. When creating a form with Vue, I noticed that empty strings were being sent to the server. Upon investigation, it became apparent that the issue lies within the @submit directive. Interestingly, when uti ...
When attempting to run npm start on the trip example in deck.gl, I encountered an issue. Although other examples open without any problems, the trip example is giving me this npm error: Module not found: Error: Can't resolve '@deck.gl/experim ...
My website uses jQuery to load the app page into a div on the index page. The app page consists of two DIVs: a search form and a results div. When the user searches, jQuery loads the results into the results div. Each result includes call-to-action butto ...
Currently, I am managing 3 arrays and wish to toggle between them using ng-repeat: $scope.fooDataObj = { array1:[{name:'john', id:'1'},{name:'jerry', id:'2'}], array2[{name:'bill', id:'1'},{name: ...
Having an issue with storing JSONP data into variables and using it as input for a Google Pie Chart. Consider the following: Data in test.json: { "name": "ProjA", sp": 10, "current": 20 } The goal is to retrieve the SP value. Attempted solution usin ...
Keep in mind that the parent variable is a firebase reference that has already been defined. Using it like this works fine: v-if="parent['key'] == foo" However, when trying to access a child element like this: v-if="parent['key'].ch ...
Currently, I am facing an issue while plotting a temperature chart as I have two arrays: a, which consists of registered temperature values throughout the day. For example: a=[22.1, 23.4, 21.7,...]; and b, containing the corresponding timestamps for eac ...
My nodejs server has a JSON schema like this: var UserSchema = new Schema({ nick: String, deviceId: String, visivel: Boolean, checks: [{date: {type:String},log: {type:Number},lng: {type:Number}}] }); In the Post code ...