从react-three-fiber导出GLTF格式的场景



我试图将我的场景保存为GLTF格式。我看到了使用exportGLTF从Three.js导出的例子,但我不知道如何在react-three-fiber mesh中做同样的事情。我发现的例子是:https://github.com/mrdoob/three.js/blob/master/examples/misc_exporter_gltf.html.

你必须从组件中获得一个ref并在一些反应状态回调中使用它,比如useEffect

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

最新更新