I am trying to save my scene in a GLTF fromat. I saw examples with exports from Three.js by using exportGLTF but I can't figure out how I can do the same thing in react with react-three-fiber meshes. The example I found is: https://github.com/mrdoob/three.js/blob/master/examples/misc_exporter_gltf.html.
Asked
Active
Viewed 2,263 times
0
-
1there is no difference, you use it in the exact same way. you get the default scene via const { scene } = useThree() – hpalu Feb 19 '21 at 22:43
-
1I don't use vanila THREE.js and I don't have const { scene } = useThree(), instead I have
inside – Dan Glodeanu Mar 01 '21 at 10:12
1 Answers
2
You will have to get a ref from the component and use it in some react state callback like useEffect something like this
export default function something(props){
const meshRef = useRef();
const exporter = new GLTFExporter();
useEffect(() =>{
exporter.parse( meshRef.current, function ( gltf ) {
downloadJSON( gltf );
}, options ); // you will have to provide the options here
})
return(
<mesh ref={meshRef}>
...
</mesh>
)
}

Epiczzor
- 377
- 2
- 13