I thought that I have to access the faces of the cube mesh and then add a CSS2DObject to them, but it doesnt work.
Here is my code:
const cssRenderer = new CSS2DRenderer();
document.body.appendChild(cssRenderer.domElement);
const indices = smallCubeGeometry.index.array;
const vertices = smallCubeGeometry.attributes.position.array;
const faces = [];
for (let i = 0; i < indices.length; i += 3) {
const a = indices[i];
const b = indices[i + 1];
const c = indices[i + 2];
const face = {
a: new THREE.Vector3().fromArray(vertices, a * 3),
b: new THREE.Vector3().fromArray(vertices, b * 3),
c: new THREE.Vector3().fromArray(vertices, c * 3),
};
faces.push(face);
}
const div = document.createElement('div');
div.textContent = 'Hello Worlds';
const label = new CSS2DObject(div);