Dan Glodeanu
Dan Glodeanu

Reputation: 25

Exporting scene in GLTF format from react-three-fiber

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.

Upvotes: 1

Views: 3199

Answers (1)

Epiczzor
Epiczzor

Reputation: 427

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>
 )
}

Upvotes: 3

Related Questions