Integrating three-globe with react-three-fiber #2719
-
👋 hi everyone, I was able to successfully add the globe to the ThreeJS scene using a useEffect hook:
However ideally I would be able to render the MyGlobe as a component instead so it can be controlled using react-three-fiber utilities such as useFrame as shown in the example:
What is the best way to do it? Thanks for your help |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Have you seen https://docs.pmnd.rs/react-three-fiber/api/objects#using-3rd-party-objects-declaratively ? You can import React, { useRef, useLayoutEffect } from 'react'
import { extend } from 'react-three-fiber'
import ThreeGlobe from 'three-globe'
extend({ ThreeGlobe })
const Globe = (props) => {
// This reference will give us direct access to the ThreeGlobe class
const globeRef = useRef()
// An effect that runs after three.js elements are created but before render
useLayoutEffect(() => {
// Configure the globe
globeRef.current.globeImageUrl('//unpkg.com/three-globe/example/img/earth-blue-marble.jpg')
globeRef.current.bumpImageUrl('//unpkg.com/three-globe/example/img/earth-topology.png')
}, [])
// This is a ThreeGlobe object but represented in JSX.
// Any valid properties of that class are valid props
return <threeGlobe {...props} ref={globeRef} />
} |
Beta Was this translation helpful? Give feedback.
-
Getting
I tried:
but it's not working. |
Beta Was this translation helpful? Give feedback.
Have you seen https://docs.pmnd.rs/react-three-fiber/api/objects#using-3rd-party-objects-declaratively ?
You can
extend
the globe and use it as a native element.