# Questions on: https://threejs.org/examples/css2d\_label.html

**URL:** <https://discourse.threejs.org/t/questions-on-https-threejs-org-examples-css2d-label-html/56577>\
**Category:** Questions\
**Tags:** css-renderer\
**Created:** [October 2, 2023, 10:03am UTC](https://discourse.threejs.org/t/questions-on-https-threejs-org-examples-css2d-label-html/56577 "2023-10-02T10:03:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![oldman](https://avatars.discourse-cdn.com/v4/letter/o/b2d939/32.png) [@oldman](https://discourse.threejs.org/u/oldman)\
**Post date:** [October 2, 2023, 10:03am UTC](https://discourse.threejs.org/t/questions-on-https-threejs-org-examples-css2d-label-html/56577/1 "2023-10-02T10:03:49Z")

</div>

(1) There are two renderers. One for the 3D objects (renderer) and one for the 2D objects (labelRenderer). When rendering a scene it is necessary to call them both, one after the other

However, the following line

```javascript
   const controls = new OrbitControls( camera, labelRenderer.domElement );

```

assigns controls to ONLY to labelRenderer.

Why not renderer instead?  
Why not renderer also?

(2) Assigning the position of a label takes these calls:

```javascript
moonLabel.position.set( 1.5 * MOON_RADIUS, 0, 0 );
moonLabel.center.set( 0, 1 );

```

In the second call, what is the center and what does (0,1) mean?

OLDMAN

---

<div class="post-metadata">

**Author:** ![Lawrence3DPK](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lawrence3dpk/32/29184_2.png) [@Lawrence3DPK](https://discourse.threejs.org/u/Lawrence3DPK)\
**Post date:** [October 2, 2023, 11:32am UTC](https://discourse.threejs.org/t/questions-on-https-threejs-org-examples-css2d-label-html/56577/2 "2023-10-02T11:32:43Z")

</div>

> [@oldman](#):
>
> assigns controls to ONLY to labelRenderer.
> 
> Why not renderer instead?  
> Why not renderer also?

`CSS2DRenderer` is an extra 2D div that overlays the main 3D canvas, it’s simply a container to place created `CSS2DObject`s in, if you look at the “elements” panel of dev tools you will see this overlay, as this is on top of the 3D canvas, using the CSS2D “layer” makes sense as it’s just referring to the overlaid div element, there’s no need for both to be referenced and trying to use the usual `renderer.domElement` would have it’s pointer events “blocked” by the 2D div in front of it…

> [@oldman](#):
>
> In the second call, what is the center and what does (0,1) mean?

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/6/8/68cf33312ed5ffd20eb206199e9a2070f0136274.png)  
it’s just a `vector2` that allows you to specify where the 2DObject is centered, I guess this is normalized so no matter the dims of the 2DObjects div element content (0.5,0.5) will displace the content by half it’s width and height as to be central to it’s point of origin ( the Object3D “pivot point” that the class extends…)

---

<div class="post-metadata">

**Author:** ![oldman](https://avatars.discourse-cdn.com/v4/letter/o/b2d939/32.png) [@oldman](https://discourse.threejs.org/u/oldman)\
**Post date:** [October 3, 2023, 5:16am UTC](https://discourse.threejs.org/t/questions-on-https-threejs-org-examples-css2d-label-html/56577/3 "2023-10-03T05:16:40Z")

</div>

In the following code snippet taken from the same example,

```javascript
				const earthLabel = new CSS2DObject( earthDiv );
				earthLabel.position.set( 1.5 * EARTH_RADIUS, 0, 0 );
				earthLabel.center.set( 0, 1 );
				earth.add( earthLabel );

```

is the position of (1.5\*EARTH\_RADIUS, 0, 0) being defined RELATIVE to the center of the “earth” object?   
Or is it an ABSOLUTE position relative to the global origin?

If relative, in this case since the “earth” object is a sphere, the center is obvious. But what if it a general mesh? What would be the center?

OLDMAN

---

<div class="post-metadata">

**Author:** ![trusktr](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/trusktr/32/13726_2.png) [@trusktr](https://discourse.threejs.org/u/trusktr)\
**Post date:** [October 3, 2023, 6:10am UTC](https://discourse.threejs.org/t/questions-on-https-threejs-org-examples-css2d-label-html/56577/4 "2023-10-03T06:10:21Z")

</div>

Chrome/Edge devtools has a 3D view in which you can see DOM layers. If you take a look, you’ll see that the red layer on top covers all the rest. For this reason the example uses the layer that is on top for catching pointer events because that’s layer that is receiving the pointer interaction (the layers behind are blocked). Imagine your pointer casts a ray onto these layers, and it stops at the first surface that it hits (this is in the browser’s CSS space).

[https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/5/5/55de193234e44520b98c89cd486e7f3e4f9563e6.mov](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/5/5/55de193234e44520b98c89cd486e7f3e4f9563e6.mov)

[https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/8/a/8a6845863e9fe68956cf57e6978b47054c78e981.mov](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/8/a/8a6845863e9fe68956cf57e6978b47054c78e981.mov)

The browser does its own raycasting on CSS 3D surfaces too, but those are not pictured in the devtools 3D view, the 3D view only shows the CSS render layers. You might think of these layers roughly as quads with a texture onto which the CSS engine renders to. One of those quads includes the content of the `renderer`’s `<canvas>`, and the other quad’s texture includes all of the CSS 2D content from `labelRenderer`.

Did that make any sense? 😃

---

<div class="post-metadata">

**Author:** ![Lawrence3DPK](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lawrence3dpk/32/29184_2.png) [@Lawrence3DPK](https://discourse.threejs.org/u/Lawrence3DPK)\
**Post date:** [October 3, 2023, 3:46pm UTC](https://discourse.threejs.org/t/questions-on-https-threejs-org-examples-css2d-label-html/56577/5 "2023-10-03T15:46:35Z")

</div>

> [@oldman](#):
>
> is the position of (1.5\*EARTH\_RADIUS, 0, 0) being defined RELATIVE to the center of the “earth” object?  
> Or is it an ABSOLUTE position relative to the global origin?

You can see and treat the CSS2DObject as any other `Object3D` (it is an extension of the `Object3D` class) if for instance in the case you used…

```javascript
earth.add(earthLabel) 

```

Yes the label position would be and stay relative to the earth object, in the case of example in question though, both the earth object and label are being added to the scene so will be relative to the global origin, eg. If the earth object is moved the label will stay relative to it’s own global origin, to update it’s position in the scene (relative to the earth object) you would set it’s position from the earth objects `localToWorld` position and then add `1.5*EARTH_RADIUS` to it’s `position.x`

---

<div class="post-metadata">

**Author:** ![trusktr](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/trusktr/32/13726_2.png) [@trusktr](https://discourse.threejs.org/u/trusktr)\
**Post date:** [October 3, 2023, 9:24pm UTC](https://discourse.threejs.org/t/questions-on-https-threejs-org-examples-css2d-label-html/56577/6 "2023-10-03T21:24:24Z")

</div>

^ True. Just remember: objects are always positioned relative to their parent’s origin (0,0,0).

> [@oldman](#):
>
> If relative, in this case since the “earth” object is a sphere, the center is obvious. But what if it a general mesh? What would be the center?

The center of a mesh doesn’t come into play in this case, and the center of a mesh is not necessarily the origin. A mesh has an origin (0,0,0), and any geometry vertices are just points that are relative to the object’s (0,0,0). So it is very possibly you can have a mesh where all of its vertices are more than 100 in every axis, which means the origin of the mesh object will always be outside of the actual geometry (or in other words, the geometry will always be away from the object’s origin).

With the above in mind, when _any_ child of a Mesh is positioned, the child is always positioned relative to the mesh’s origin (0,0,0) and has nothing to do with the geometry.

Think of it kinda like this:

- a Mesh object has `.children`, and those children are position relative to the Mesh’s origin (0,0,0)
- a Mesh also has geometry, which are a bag of vertices, and similar to children, those vertices are also positioned relative to the Mesh’s origin (0,0,0), and this has no effect on positioning of `.children`.
- If you modify the Mesh’s geometry vertices, this does nothing to the positioning of `.children`
- it is _as if_ `.geometry` is a separate special child that is not inside of `.children`.
