Using Popmelt with Three.js and react-three-fiber
Target scene objects through Core's React Three Fiber integration and discuss changes in context.
Core can target objects in Three.js scenes through its React Three Fiber integration. The adapter registers the scene, camera, and renderer with Core, so scene objects use the familiar hover, annotation, and thread workflow. It does not depend on See or object segmentation.
This guide covers React Three Fiber, not automatic integration with an arbitrary Three.js canvas. For images and paused video, see Creating annotations with the Chat tool.
React Three Fiber
Install the scene peers alongside Core:
npm install @popmelt.com/core @react-three/fiber three
Keep the provider outside the canvas and the adapter inside it:
import { PopmeltProvider } from '@popmelt.com/core';
import { PopmeltThreeAdapter } from '@popmelt.com/core/react-three-fiber';
import { Canvas } from '@react-three/fiber';
export function ProductPreview() {
return (
<PopmeltProvider>
<Canvas>
<PopmeltThreeAdapter />
<ProductScene />
</Canvas>
</PopmeltProvider>
);
}
ProductScene is your scene component. Named scene objects receive readable labels. Add stable application identity when names or ordering may change:
<mesh
name="Bottle"
userData={{ popmeltId: 'hero-bottle', popmeltLabel: 'Hero bottle' }}
>
{/* Your geometry and material */}
</mesh>
Leave scene feedback
Choose Chat (C) and point to an object in the scene. Check the outline, click the object, and describe the change you want. Press Command/Control+Enter to send it and continue in the thread.
Adapt the scene's semantics
Use distinct adapter IDs for multiple canvases. Pass root to restrict targeting to a scene subtree or captureFrame={false} to omit renderer screenshots. The select, key, label, and describe options let you map scene objects to the application's own semantics.
When a component needs the registered adapter instance, import usePopmeltThreeAdapter from @popmelt.com/core/react-three-fiber. Call const adapter = usePopmeltThreeAdapter({ id: 'product-preview' }) inside a canvas child. The hook manages registration and cleanup and takes the place of the PopmeltThreeAdapter component for that scene.
Annotate a Gaussian splat scene
A splat scene can expose its parts through the same adapter. In the signal tuner, the app registers a separate selection target for each part. The dial carries the stable ID tuner-dial and follows the dial as it moves.
In Chat, hover over the dial and check its name and bounds. Click it, type your feedback, and press Enter to finish the note. Rotate the tuner to see how the note follows the dial.
Didn't find the answer? Have an idea?
Ask a question