I have seen a lot of comments and tutorials on how to work with CSS3DRenderer and WebGLRenderer. I could implement the CSS3DRenderer, although it seems that I can’t find the right way to make orbitControls work.
My project idea is to make a HTML page and insert it on a plane to “simulate” a screen on my scene.
Right now the div seems to be overlaping the WebGL Canvas.

If I insert a zIndez of -1 for the css3drenderer, everything works fine again, although it doesn’t show the content from css3dRenderer.
The code for the renderer:
import * as THREE from 'three';
import Experience from "./Experience";
import { CSS3DRenderer } from 'three/examples/jsm/renderers/CSS3DRenderer.js';
export default class Renderer {
constructor() {
// Instancializing a singletong
this.experience = new Experience();
// Setup
this.canvas = this.experience.canvas;
this.sizes = this.experience.sizes;
this.scene = this.experience.scene;
this.sceneCSS3D = this.experience.sceneCSS3D;
this.camera = this.experience.camera;
// Methods
this.setInstance();
}
setInstance() {
this.instance = new THREE.WebGLRenderer({
canvas: this.canvas,
antialias: true,
alpha: true
});
this.instance.physicallyCorrectLights = true;
this.instance.outputEncoding = THREE.sRGBEncoding;
this.instance.toneMapping = THREE.CineonToneMapping;
this.instance.toneMappingExposure = 1.75;
this.instance.shadowMap.enabled = true;
this.instance.shadowMap.type = THREE.PCFSoftShadowMap;
this.instance.setClearColor(0xFF00FF, 1);
this.instance.setSize(this.sizes.width, this.sizes.height);
this.instance.setPixelRatio(Math.min(window.devicePixelRatio, 2));
document.body.appendChild(this.instance.domElement);
// CSS3d
this.css3drenderer = new CSS3DRenderer();
this.css3drenderer.setSize(this.sizes.width, this.sizes.height);
this.css3drenderer.domElement.style.position = 'absolute';
this.css3drenderer.domElement.style.top = 0;
document.body.appendChild(this.css3drenderer.domElement);
}
resize() {
this.instance.setSize(this.sizes.width, this.sizes.height);
this.instance.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
update() {
this.instance.render(this.scene, this.camera.instance);
this.css3drenderer.render(this.sceneCSS3D, this.camera.instance);
}
}
How I tried setting up the object:
import * as THREE from 'three';
import Experience from "../Experience";
import { CSS3DObject } from 'three/examples/jsm/renderers/CSS3DRenderer.js';
export default class Object {
constructor() {
this.experience = new Experience();
this.scene = this.experience.scene;
this.sceneCSS3D = this.experience.sceneCSS3D;
this.resources = this.experience.resources;
this.time = this.experience.time;
this.debug = this.experience.debug;
// Setup
this.resources = this.resources.items;
// Methods
this.setModel();
}
setModel() {
this.model = {};
// CSS3D
this.model.element = document.createElement('div');
this.model.element.innerHTML = `Tutorix is the best e-learning platform Tutorix is the best e-learning platform Tutorix is the best e-learning platform`;
this.model.element.style.width = '5px';
this.model.element.style.height = '5px';
this.model.element.style.overflowY = 'auto';
this.model.element.style.backgroud = new THREE.Color(0xFFFFFF).getStyle();
this.model.meshCss3d = new CSS3DObject(this.model.element);
this.model.meshCss3d.scale.x = 1;
this.model.meshCss3d.scale.y = 1;
this.sceneCSS3D.add(this.model.meshCss3d);
// Plane
this.model.material = new THREE.MeshBasicMaterial({
color: 0x000000,
wireframe: true,
wireframeLinewidth: 1,
side: THREE.DoubleSide
});
this.model.mesh = new THREE.Mesh(new THREE.PlaneGeometry(10, 10), this.model.material);
this.scene.add(this.model.mesh);
}
update() {
}
}
My HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nilton SF</title>
<link rel="stylesheet" href="../tailwind/tailwind.css">
</head>
<body>
<canvas class="webgl"></canvas>
</body>
</html>

