How can I make the cssRenderer layer element transparent so that the webglRenderer layer is visible beneath it in Three.js?

A test is being conducted on a cssRenderer that is running a scene directly in front of a webglRender. This setup allows both to run together, creating the illusion of including html dom elements (div and text) in webgl.

The goal is to make the textbox background, rendered in the cssScene, transparent so that the floor, rendered in the glscene, is visible behind it.

The cssObject is linked to the planeMesh, with the planeMesh having zero opacity and

material.blending = THREE.NoBlending;
. Despite this setup, changes in blending modes do not have any effect, even with full opacity. Moreover, applying blending modes to the cssObject does not produce any results either.

An intriguing observation is that when spinning the scene around and looking through the back of the text box, the text may appear backwards but the textbox is transparent. This raises the question of why this occurs and how to achieve transparency in the text box while keeping the text oriented correctly.

Explore the plunker here

Below is the relevant js code:

function drawMesh(){
// create the plane mesh
//var material = new THREE.MeshBasicMaterial({ wireframe: false, color: 0xFF00FF });

var material   = new THREE.MeshBasicMaterial();
material.color.set('black');
material.opacity   = 0;
// material = THREE.DoubleSide;
material.blending = THREE.NoBlending;

var geometry = new THREE.PlaneGeometry(1.70,0.49);
  planeMesh = new THREE.Mesh( geometry, material );
  planeMesh.position.x = 2.5;
  planeMesh.position.y = 1.8;
  planeMesh.position.z = -2;
  planeMesh.rotation.y = Math.PI / 1;


// add it to the WebGL scene
glscene.add(planeMesh);

var number = document.createElement( 'div' );
number.className = 'number';
number.textContent = "This is an html textbox and that is a cube. blah blah blah";
// create the object3d for this element
cssObject = new THREE.CSS3DObject( number );
// we reference the same position and rotation 
cssObject.position = planeMesh.position;
cssObject.rotation = planeMesh.rotation;


cssObject.scale.set(0.0075,0.0075,0.0075);
cssObject.rotation.y = Math.PI / 1;
cssObject.position.x = 2.5;
cssObject.position.y = 1.8;
cssObject.position.z = -2;

cssObject.blending = THREE.AdditiveBlending;
console.log(cssObject.position.x);
// add it to the css scene
cssScene.add(cssObject);
}

Answer №1

MeshBasicMaterial does not include an opacity parameter.

To work around this, you can either define the material as material = new THREE.Material();
or, you can remove the planeMesh from the scene and simply apply a background-color to your cssObject in the css file.

Check out the updated plunker

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

Using Vue Formulate to effortlessly upload multiple images

One of my projects involves using a Vue Formulate component for uploading multiple images to an Express.js backend. Here is the code snippet for the Vue Formulate component: <FormulateInput type="image" name="property_ ...

Customize bullet list icons to adjust in size based on content using css

In my CMS project, the CMS team has a special requirement regarding unordered and ordered lists. They want the size of the bullet list icon to adjust according to the text content within the list. The image below shows the default design of a list item: ...

Having difficulty ensuring DayJs is accessible for all Cypress tests

Currently embarking on a new Cypress project, I find myself dealing with an application heavily focused on calendars, requiring frequent manipulations of dates. I'm facing an issue where I need to make DayJs globally available throughout the entire p ...

Store user input as cookies and showcase it to the user upon their return visit

I'm looking for some assistance in saving user input to cookies and displaying it to the user. The goal is to have the text entered in the input field change into a div and be displayed to the user every time they revisit the page. Currently, I only ...

What causes Express Async Errors to produce unexpected outcomes?

I stumbled upon a fantastic npm package called Express Async Errors that is highly recommended in the documentation. However, when I try to implement it, my server crashes. Here is my Route handler code: Controller const { Genre } = require("../models"); ...

Tips for avoiding accidental double mouse clicks occurring simultaneously

$(document).ready(function() { $(".voteMe").one('click', function (event) { event.preventDefault(); //my customization $(this).prop('disabled', true); }); }); the provided code enabl ...

What can you do to prevent a div from taking up the entire page if its height is not specified?

Currently, I am experiencing an issue with my layout. I have a hidden div with a fixed position that becomes visible when a button on the page is clicked. Inside this div, there is a table of buttons for the user to choose from. The problem arises when I ...

Approach to Preloading STL Files for Efficient Loading

Within my scene, I have two Mesh properties. One of them is created programmatically, while the other is loaded from an STL file. Upon initial page load, only the dynamically created mesh is visible, while the mesh from the STL file remains invisible. Rec ...

Is there a way to trim the current shapes in three.js?

I have created a shape similar to this using Box Geometry at the following link: https://jsfiddle.net/cdu96z3c/. I am looking to achieve a design like the image below by properly utilizing v.x and v.z, while maintaining the current corrugation and properti ...

Dynamic stacking of buttons in response to user navigation choices

Is it possible to create a navigation bar with 5 buttons using CSS and JS? Here is what I am looking to achieve: Display 5 nav/button options When a user clicks on a button, the other buttons should transition or hide, leaving only the selected button vi ...

Steps for transitioning a VUE JS project to TypeScript

Is it possible to transition a VUE JS project from JavaScript to TypeScript without rewriting everything? I heard from a friend that it can be done through the VUE CLI, but I haven't been able to find any documentation or articles on this method. Has ...

Checking for an existing alert in JavaScript

In my development of a Blackberry Webworks (HTML5) app, I am running multiple methods simultaneously in the background. If any of these methods happen to fail, an alert is triggered using the alert() method in JavaScript. However, if both methods fail, two ...

Is it possible to retrieve JSON data from an external URL using JavaScript or jQuery?

My goal is to retrieve JSON data from the following URL: I have a button that triggers the function called "jsonplz()", which should display an alert message with the fetched JSON data. This is what my JavaScript code looks like: <script src="htt ...

Exporting modules in Node.js allows you to use functions

Can you explain why this code snippet is successful: exports.foo = 'foo'; var bar = require('./foo'); console.log(bar); // {foo: 'foo'} While this one fails to produce the desired output: var data = { foo: 'foo' ...

Retrieve information using AJAX via POST method

I find myself in a bit of a pickle at the moment. I've been researching for hours, and I still can't seem to figure out this seemingly basic issue. It would be greatly appreciated if someone could offer me some quick advice. So here's my dil ...

Issues encountered when attempting to utilize removeEventListener() with multiple elements within a for loop in Javascript

After experimenting, I have been exploring ways to avoid encountering repeated event listeners The script provided below iterates through all buttons with a specific attribute. However, the issue is that it only functions effectively for a single button ...

AngularJS display element within viewport

My div is extremely wide and contains many elements. I need a way to bring specific elements into view when a button is clicked. Is there an alternative to $anchorscroll that can achieve this? Looking for a solution for horizontally scrolling to a particu ...

Developing a fresh feature in Angular.js for transmitting my localstorage model information to a bus?

As a beginner in Angular Js, I have mastered the basics and am now working on storing user input values to localstorage using a form. Although this part is working fine, I need assistance in creating a new service to communicate with my colleague's . ...

Code in Javascript is functioning properly when executed directly in the console, however, it fails to run as

I need help troubleshooting my JavaScript code that is meant to run on my homepage when it loads: $(".mm-page").css({"position":"inherit"}); I included this code at the bottom of my home.html.erb file: <% content_for(:after_js) do %> <scrip ...

Alpha tearing in Three.js refers to the visual artifact that

Currently experimenting with ThreeJs in Canvas mode and encountering an alpha issue. Attempting to create a solid sphere rotating counterclockwise around Y, with a slightly larger semi-transparent sphere rotating clockwise around it. When stationary and t ...