The CSS3D object stands out among 3D objects, maintaining its visibility even as the scene is rotated

I'm utilizing the CSS3DRenderer to render HTML on FBX 3D objects. Everything seems to be working well, except that when I rotate my scene, the HTML becomes visible through the 3D objects as if they were transparent. I am relatively new to Three.js and would greatly appreciate any advice or guidance you could offer. For reference, I have created a video which you can view here.

Here is a snippet of the code:

   this.scene = new THREE.Scene();
   this.scene2 = new THREE.Scene();
   this.addRoulettable();
   this.renderThings();

   addRoulettable() {
       let t = this;
       return new Promise((resolve, reject) => {
         t.loader.load('../../assets/models/fbx/roulettetable.fbx',                      function (object) {
           object.traverse(function (child) {

             if (child['isMesh']) {

               child.castShadow = true;
               child.receiveShadow = false;

             }

             if (child instanceof THREE.Mesh) {

               var texture = t.textureLoader.load('../../assets/images/leather.jpg', function (texture) {

          texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
          texture.offset.set(0, 0);
          texture.repeat.set(50, 50);

        });

        var dashboard = t.textureLoader.load('../../assets/images/greencloth.png');

        child.material = [
          new THREE.MeshStandardMaterial({
            map: dashboard,
            blending: THREE.NoBlending,
            roughness: 2,
            side: THREE.DoubleSide,
          }),
          new THREE.MeshPhysicalMaterial({
            map: texture
          }),
          new THREE.MeshPhysicalMaterial({
            map: THREE.ImageUtils.loadTexture('../../assets/images/Gradient Diagonal (Color).jpg'),
            // blending: THREE.NoBlending,
            side: THREE.DoubleSide
          }),
          new THREE.MeshStandardMaterial({
            // map: THREE.ImageUtils.loadTexture('../../assets/images/Gradient Vertical (Color).jpg'),
            // blending: THREE.NoBlending,
            color: 'orange',
            side: THREE.DoubleSide,
            roughness: 0.4,
            metalness: 0.6,
            envMapIntensity: t.settings.envMapIntensity,
            envMap: t.reflectionCube
          }),
          new THREE.MeshStandardMaterial({
            color: 0xffffff,
            roughness: t.settings.roughness,
            metalness: t.settings.metalness,
            envMapIntensity: t.settings.envMapIntensity,
            envMap: t.reflectionCube,
            transparent: true,
            opacity: 0.6
          }),
          new THREE.MeshStandardMaterial({
            color: 0xffffff,
            roughness: 0,
            metalness: 0.7,
            envMapIntensity: t.settings.envMapIntensity,
            envMap: t.reflectionCube
          }),
          new THREE.MeshPhysicalMaterial({
            color: 0x474645
          })
        ];
      }
    });

    object.position.set(0, 400, 37);

    var object3D = new THREE.Object3D;

    object3D.add(object);

    var positionVector = new THREE.Vector3();
    var box = new THREE.Box3().setFromObject(object);
    console.log(box.min, box.max, box.getSize(positionVector));
    var material = new THREE.MeshBasicMaterial({ wireframe: true });
    material.color.set('black')
    material.transparent = true;
    material.opacity = 0;
    material.blending = THREE.NoBlending;

    var geometry = new THREE.PlaneGeometry(positionVector.x * 0.85, positionVector.z * 0.53);
    var planeMesh = new THREE.Mesh(geometry, material);

    planeMesh.position.y = 680;
    planeMesh.position.z = 850;
    planeMesh.rotation.copy(object.rotation);
    planeMesh.rotation.x = -90 * degree;
    planeMesh.scale.copy(object.scale);

    object3D.add(planeMesh);

    t.htmlPlane = planeMesh;
    t.rouletTable = object3D;

    t.scene.add(object3D);
    var dom = document.getElementById('battingUI');
    dom.style.height = positionVector.z * 0.53 + 'px';
    dom.style.width = positionVector.x * 0.85 + 'px';

    t.html = new CSS3DObject(dom);
    t.html.position.copy(planeMesh.position);
    t.html.rotation.copy(planeMesh.rotation);
    t.html.scale.copy(planeMesh.scale);

    t.html.buffersNeedUpdate = true;
    t.html.uvsNeedUpdate = true;

    t.scene2.add(t.html);

    resolve(true);

  }, undefined, (err) => {
    console.error(err);
    reject(err);
  });
});
}

renderThings() {
       let gameContainer = document.getElementById('container');
       this.renderer2 = new CSS3DRenderer();
       this.renderer2.setSize(this.width, this.height);
       this.renderer2.domElement.style.position = 'absolute';
       this.renderer2.domElement.style.top = '0';

       gameContainer.appendChild(this.renderer2.domElement);

       this.renderer = new THREE.WebGLRenderer({ antialias: true });
       this.renderer.setPixelRatio(window.devicePixelRatio);
       this.renderer.setClearColor(0x000000, 0);
       this.renderer.setSize(this.width, this.height);
       this.renderer.domElement.style.zIndex = 1;
       this.renderer.shadowMap.enabled = true;
       this.renderer.shadowMap.type = THREE.PCFSoftShadowMap;

       gameContainer.appendChild(this.renderer.domElement);
}

Answer №1

CSS3DRenderer doesn't have any knowledge of the depth buffer used by WebGLRenderer, so it's expected that you're experiencing this issue.

The order in which things are displayed on top is determined by this section of your code:

   this.renderer2 = new CSS3DRenderer();
   this.renderer2.domElement.style.position = 'absolute';
   this.renderer2.domElement.style.top = '0';
   gameContainer.appendChild( this.renderer2.domElement );

   this.renderer = new THREE.WebGLRenderer({ antialias: true });
   gameContainer.appendChild( this.renderer.domElement );

Using three.js version r.108

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

Rearranging lists in JHipster: What is the best way to do it?

Seeking advice and guidance on implementing a drag-and-drop reorderable list in JHipster 6.7.1. To illustrate, picture creating a custom ordered list of objects where users can add, remove, and rearrange items. For instance, wanting to move [Epsilon] betw ...

"Exploring the process of accessing the request headers section within the network tab of your browser

How can I extract the access date from the request headers section in the network tab of my browser when receiving a response from the API? Can someone help me with this problem? ...

Angular: The Ultimate Guide to Reloading a Specific Section of HTML (Form/Div/Table)

On my create operation page, I have a form with two fields. When I reload the page using window.reload in code, I can see updates in the form. However, I want to trigger a refresh on the form by clicking a button. I need help writing a function that can r ...

When the page is refreshed, reorienting axes in three.js encounters difficulties

I am currently working on a project that involves using the three.js editor source code available for download on the three.js website. As part of this project, I am required to adjust the orientation of the axes to align with standard airplane coordinate ...

How to extract IDs from a URL in Angular

I'm facing an issue with retrieving the first id from an image URL. Instead of getting the desired id, I am receiving the one after the semicolon ("id" = 1). I have tried various methods but haven't been successful in resolving this issue. Any su ...

Encountering a Problem Configuring Jest in Angular 9 Using angular-jest-preset

Currently in the process of setting up Jest for Angular 9 using jest-preset-angular version 9. The code is running, but encountering the error: Error: Cannot read property 'ngModule' of null Uncertain on how to troubleshoot this issue. https:/ ...

The in-memory-web-api is failing to respond to queries when using Chrome

I've been experiencing an issue with my in-memory database setup. Even though I have registered everything correctly, I am not receiving any data back. There are no errors or 404 responses; it seems like the app is intercepting the request and returni ...

Using ThreeJS to Apply Dual Materials to a Mesh Entity

With ThreeJS, it's possible to incorporate more than one material into an Object3D/Mesh as stated in the documentation. You can either utilize a single Material or an array of Material: Class declaration and constructor for Mesh TypeScript file (exce ...

What causes a delay in HTTP calls in Chrome when it is in the "Stalled" or "Initial Connection" state? Is it possible for these states to generate multiple threads for the same request?

My application uses Angular on the client side and Java (Spring Boot) on the backend. Occasionally, during some network calls, the waterfall chart gets stuck in either the "Stalled" or "Initial Connection" state. When this happens, I have noticed in my log ...

Angular Update Component on Input ChangeEnsuring that the component is automatically

<div class=" card-body"> <div class="row"> <div class=" font-icon-list col-lg-2 col-md-3 col-sm-4 col-xs-6 col-xs-6" routerLinkActive="active" *ngFor="let subject of subjects"> <div class=" fon ...

Binding data to custom components in Angular allows for a more flexible

In my current scenario, I am looking to pass a portion of a complex object to an Angular component. <app-component [set]="data.set"></app-component> I want the 'data.set' object in the parent class to always mirror the 'set&apo ...

Tips for utilizing functions in an inline HTML translation pipe

My objective is to streamline the code by using the Angular translate pipe. Currently, I find myself using 8 curly brackets and repeating the word "translate" twice... there must be a more efficient approach. Here is my current code setup: <s ...

The vertical scrolling feature seems to be malfunctioning within my angular 10 application

I'm having an issue with the scrollbar not working on this Angular 10 template, even after adding the CSS style overflow: auto; to the main container. Although I've included the overflow property in the main container "cont" as shown in the HTML ...

Challenges encountered when setting a value to a custom directive via property binding

I'm working on a question.component.html template where I render different options for a specific question. The goal is to change the background color of an option to yellow if the user selects the correct answer, and to red if they choose incorrectly ...

Guidelines for redirecting to a complete URL

I am currently developing a web application using Angular 7. One of the features I need to implement is redirecting to a full URL that is retrieved from a database. The challenge here is to perform the redirect within the app without causing a full page re ...

Dealing with a multi-part Response body in Angular

When working with Angular, I encountered an issue where the application was not handling multipart response bodies correctly. It seems that the HttpClient in Angular is unable to parse multipart response bodies accurately, as discussed in this GitHub issue ...

Encountering a 403 error upon refreshing the page of my Angular 6 project

I am currently working on an Angular 6 project with JWT authorization deployed on AWS Elastic Beanstalk and utilizing CloudFront. I am using the @auth0/angular-jwt library to manage everything efficiently. The setup is functioning smoothly, and I have a li ...

Getting around relative paths in an Angular application hosted by NGINX

I am using NGINX to host my Angular application. The frontend is accessible at http://localhost/, and the backend can be accessed at http://localhost/api/. While most of my configuration works correctly, I am encountering an issue with a relative path in a ...

Modifying the date format of the ag-Grid date filter

On my Angular 5.2.11 application, I utilize ag-grid to showcase a table. The date column is configured with the default date filter agDateColumnFilter as per the documentation. After enabling browserDatePicker: true, the Datepicker displays dates in the ...

Issues with Angular Structural Directives arising from NPM installation concerns are causing problems

I have developed an npm package called sezam-shareds To integrate the package into a new project, you need to follow these steps: Add the following component from the package: <sezam-overflow [show]="true"></sezam-overflow> to a compo ...