Integrating a sphere mesh into a sphere of CSS3DObject
s presents a challenge due to the independent rendering and sorting of WebGL and HTML/CSS elements. This results in element labels remaining visible even when the sphere mesh is positioned in front of them. An example showcasing this issue, an advanced version of the official demo, can be viewed here.
The suggested approach involves creating two renderers and stacking their domElement
properties on top of each other as follows:
// WebGL
rendererWebGL = new THREE.WebGLRenderer( { antialias: true } );
rendererWebGL.setPixelRatio( window.devicePixelRatio );
rendererWebGL.setSize( window.innerWidth, window.innerHeight );
container.appendChild( rendererWebGL.domElement );
// CSS
renderer = new CSS3DRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.domElement.style.position = 'absolute';
renderer.domElement.style.top = 0;
document.getElementById( 'container' ).appendChild( renderer.domElement );
Nevertheless, this setup does not entirely eliminate the visual inconsistency mentioned earlier.
For a smoother display, it is advised to construct the periodic system using simple plane meshes instead of HTML/CSS elements, relying solely on WebGLRenderer
.