English
Appearance
English
Appearance
Related references:
It is possible to place 3D content "onto the screen", but more precisely, this is not a dedicated API. The usual method is to attach the object under the camera.
The core idea looks like this:
const camera = await api.getDefaultCamera();
await api.addChild(camera, obj);That makes the object move and rotate together with the camera, which visually feels much closer to "fixed in front of the screen".
If your goal is a typical HUD or fixed UI, it is still better to:
This is a better fit for:
The reasons are straightforward:
This works better for content that:
const camera = await api.getDefaultCamera();
const obj = await api.getObject('screen-object');If the object is created at runtime, you can also use the returned handle directly:
const obj = await api.createImage('/assets/tag.png');await api.addChild(camera, obj);await api.setPosition(obj, 0, 0, -2);
await api.setScale(obj, 0.5, 0.5, 0.5);The most important value here is z:
z is usually negative, meaning the object is placed in front of the lens0 make it appear closer to the screenx and y determine the horizontal and vertical position on screen.
For example:
// Centered but lower
await api.setPosition(obj, 0, -0.6, -2);
// Near the upper-left corner
await api.setPosition(obj, -1.2, 0.8, -2);// Keep the object on top and disable depth testing / depth-buffer writes.
const recursive = true; // Apply the same settings to all child nodes as well. Default is false.
await api.setGLState(obj, "depthTest", false, recursive);
await api.setGLState(obj, "depthWrite", false, recursive);iframe.addEventListener('ready', async (event) => {
const { api } = event.detail;
const camera = await api.getDefaultCamera();
const image = await api.createImage('/assets/floating-badge.png');
await api.addChild(camera, image);
await api.setPosition(image, 1.1, -0.8, -2);
await api.setScale(image, 0.35, 0.35, 0.35);
const recursive = true;
await api.setGLState(image, "depthTest", false, recursive);
await api.setGLState(image, "depthWrite", false, recursive);
});If you no longer want the object attached to the camera, remove that parent-child relationship and attach it elsewhere:
await api.removeChild(camera, obj);If you only want to hide it:
await api.setObjectVisible(obj, false);Although this technique can create a "screen-fixed" effect, it still uses 3D coordinates rather than CSS pixels. So:
A safer approach is:
In those cases, HTML / CSS is usually a better fit than a 3D solution.