I got an exciting PR from @dennemark for react-babylonjs
, which is a port of the Html component from drei
.
Allows you to tie HTML content to any object of your scene. It will be projected to the objects whereabouts automatically.
So that this:
import { Html } from 'react-babylonjs'
...
<transformNode name="transform-node" position={position} rotation={rotation}>
<sphere name='sphere1' diameter={2} segments={16} position={new Vector3(0, 1, 0)}>
<Html name="html" center occlude={false} >
{<div style={{backgroundColor: 'white', borderRadius: '5px', border: '2px solid #000000', padding: '8px'}}>Lorus<br/>Ipsum</div>}
</Html>
</sphere>
</transformNode>
… ends up looking like this where I have declaratively attached DOM to be projected in the 3d scene:
You can see a live demo here:
GUI - Html Text ⋅ Storybook (brianzinn.github.io)
Source code of Html is here:
react-babylonjs/Html.tsx at master · brianzinn/react-babylonjs (github.com)