"Exploring the concept of object occlusion with transparent elements in

Is it possible to create an object in a three.js scene that is invisible but still acts as if it's blocking other objects? For example, say we have objects a, b, and c in the scene along with a camera. I want object c to be unseen by the camera, yet still block object b. How can this effect be achieved in three.js?

Scenario 1: In this scenario, object c should be hidden from the camera, but still occlude object b.

Scenario 2: Here, object c needs to remain invisible to the camera while obstructing object b.

If anyone knows of a technique or method to accomplish this in three.js, please share your insights. Thank you!

Answer №1

A possibility in three.js is to create an object that remains invisible while still obscuring other objects as if it were visible.

To achieve this effect, two key features within three.js need to be utilized: Object3D.renderOrder and Material.colorWrite.

It is crucial to ensure that the imperceptible object is rendered before the object(s) it is intended to obscure.

The rendering sequence can be manipulated through the renderOrder attribute.

By adjusting the material's colorWrite property to false, the obstructing object can be made unseen.

// material
var material = new THREE.MeshPhongMaterial();

// mesh a
var geometry = new THREE.PlaneGeometry( 10, 10, 4, 4 );
mesh = new THREE.Mesh( geometry, material.clone() );
mesh.material.color.set( 0xff0000 );
mesh.renderOrder = 0; // <===================
mesh.position.z = - 10;
scene.add( mesh );

// mesh b
var geometry = new THREE.BoxGeometry( 2, 2, 2 );
mesh = new THREE.Mesh( geometry, material.clone() );
mesh.material.color.set( 0x606060 );
mesh.renderOrder = 3;
mesh.position.z = 0;
scene.add( mesh );

// mesh c
var geometry = new THREE.BoxGeometry( 3, 3, 3 );
mesh = new THREE.Mesh( geometry, material.clone() );
mesh.material.color.set( 0x0000ff );
mesh.material.colorWrite = false; // <=================
mesh.renderOrder = 2;
mesh.position.z = 10;
scene.add( mesh );

three.js r.143

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

Discovering a CSS value using jQueryUncovering the CSS value with jQuery

Currently, I have a script that allows me to change the color of an event in a calendar to red when clicked. eventClick: function(calEvent, jsEvent, view) { $(this).css('border-color', 'red'); } Now, I want to enhance this featur ...

Control the options of the Select menu using ajax

Consider having two dropdown menus <select id=first> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</opti ...

The RadImageEditor onSaving Event does not permit the sending of response scripts

I am using a custom RadImageEditor control with a version of 2013.1.220.40. The control is placed on a page and displayed in a RadWindow. My goal is to either pass a URL or not pass it (for Update and Add scenarios, respectively). After cropping the image ...

Items appear elongated or warped exclusively along the borders of the display

Could this distortion of spherical objects into egg/oval shapes at the edges of the screen be due to a field of view (FOV) issue with my perspective camera? I'm curious to know why this effect occurs in my scene. Any insights on this phenomenon? ...

Troubleshooting a Problem with the Horizontal Scrollbar in Dynamic jqGrid

Currently, I am working on an ASP.net MVC project where I have implemented both dynamic and static jq grids. However, I am encountering an issue with the horizontal scroll bar in my application. To address this problem, I attempted to modify the overflow ...

What steps can be taken to turn off specific warning rules for CSS mode in ACE editor?

Utilizing the Ace Editor (through Brace and React-Ace) is a key aspect of my project. In our implementation, we specify the editor's mode as "css" and integrate it into our webpage. While this setup functions correctly, we have observed that some of ...

Steps to Resolve the Issue: "SyntaxError: Identifier 'getScrollParents' has already been declared; Bootstrap tooltips depend on Tether;"

After trying to resolve the issue by installing tether.js and utils.js, I found that fixing one error only led to two more popping up. Although I came across a similar post, my current issue is slightly different as it stemmed from a previous problem. Sh ...

Unable to retrieve the textContent of an HTML element, however, it is possible to log it

Currently, I'm attempting to make changes to a table on the following website. I've inserted the script below into the console of both Chrome and Firefox: let skins = [ "button" //simplified ]; skins.forEach((skin)=>{ document.que ...

Retrieving information from a JavaScript array outputs 'undefined'

I am currently attempting to retrieve the attribute labeled "MediaURL" from my Javascript array object. To provide a clearer understanding, the image below illustrates an expanded view of the array: https://i.sstatic.net/BWNym.png Encountering the follow ...

Why isn't the show/hide feature in Jquery functioning properly?

I have a div that needs to be displayed after hovering over another element. These elements are not within the same div. The popup info should appear when an icon with the class .option_36_124 is hovered over. $(".option_36_124").hover(function(){ $(& ...

What could be causing the issue of images not loading in Chrome while they are loading perfectly in Mozilla when using CSS3?

Recently, I dove into a project utilizing react with webpack, and everything was smooth sailing until I encountered the CSS hurdle. Despite successfully configuring webpack, trouble brewed when it came to styling. Specifically, setting the background image ...

Preventing the Vue compiler from managing static assets: A step-by-step guide

In my Vue 3 application, I have a variety of static assets that are organized in their own file structure separate from the app's source directory. Fortunately, my web server is configured to serve files from both the Vue build directory and the stati ...

What is the best method for deleting automatically added connection proxies in XCC?

Is there a way to make an ajax request from IBM Connections XCC without it being proxied? let api = 'https://my-server2/api.xml' var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = () => { if (xmlhttp.readyState == XMLHttpRe ...

Unveiling Insights from a JSON File: Data Extraction

I have a JSON file named pio2.json that contains the following data: { "controles":[{ "chart":[{ "type":"columns", "title":"Pollitos" }], "datos":[{"key":"Math","value":98}, {"key":"Physics" ...

Is it possible to execute custom JavaScript code in an R Jupyter notebook?

Within my Jupyter Notebook, I am working with the R programming language and would like to integrate javascript functions into it. I'm aware that there are libraries in javascript that can be called from R, but I haven't been able to find any ex ...

Is the existence of the file also verified by JavaScript's realpathSync() function?

I want to utilize node.js FileSystem realpathSync() to find the actual path of a file. Does realpathSync() also verify if the file exists? Would this code be sufficient: try { res = fs.realpathSync(path); } catch (err) { ...

Difficulty obtaining elements in Internet Explorer, however works fine in Chrome and Firefox

My <textarea> is set up like this: <textarea class="form-control notetext" id="{{this._id}}-notetext" name="notetext">{{this.text}}</textarea> I am using ajax to send data and load a partial webpage. After loading the content, I attemp ...

Reload a jquery pop up upon closing a pop up window

I have a modal pop up that appears after clicking an ASP button : <div class="form-group"> <asp:Button ID="btnBrand" runat="server" Text="Add brand" CssClass="btn btn-info" OnClick="btnAdd_Click" /> </div> Code Behind : protected ...

Utilize JavaScript/jQuery to check for upcoming deadlines in a SharePoint 2013 list

I need to check if an item is due based on its date. When a user creates an item with a date in the format MM/DD (e.g., 06/15), I want to determine if that date falls within the next 30 days, turning it red, within the next 60 days, turning it orange, or g ...

Enhance your Three.js experience: Effortlessly Panning Panoramas with Smooth E

I am currently working on a 6 cube panorama project and using this demo as a reference: The dragging functionality in this demo is controlled by mouse events. I am looking to implement easing so that the panorama cube follows the mouse smoothly. I underst ...