Skip to content

Commit

Permalink
Create SettledObjects.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson authored Jan 30, 2025
1 parent 24d10ee commit 8907a52
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions src/r3f/components/SettledObjects.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

const QueryManagerContext = createContext( null );

Check warning on line 2 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'createContext' is not defined

Check warning on line 2 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'createContext' is not defined

export const SettledObject = forwardRef( function SettledObject( props, ref ) {

Check warning on line 4 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'forwardRef' is not defined

Check warning on line 4 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'forwardRef' is not defined

const {
component = group,

Check failure on line 7 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'component' is assigned a value but never used

Check warning on line 7 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'group' is not defined

Check failure on line 7 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'component' is assigned a value but never used

Check warning on line 7 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'group' is not defined
duration = 0,

Check failure on line 8 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'duration' is assigned a value but never used

Check failure on line 8 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'duration' is assigned a value but never used
easeFunction = x => x,

Check failure on line 9 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'easeFunction' is assigned a value but never used

Check failure on line 9 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'easeFunction' is assigned a value but never used
lat = null,
lon = null,
rayorigin = null,
raydirection = null,
...rest
} = props;

const objectRef = useRef( null );

Check warning on line 17 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'useRef' is not defined

Check warning on line 17 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'useRef' is not defined
const queries = useContext( QueryManagerContext );

Check warning on line 18 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'useContext' is not defined

Check warning on line 18 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'useContext' is not defined
useEffect( () => {

Check warning on line 19 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'useEffect' is not defined

Check warning on line 19 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'useEffect' is not defined

if ( lat !== null && lon !== null ) {

const index = queries.registerLatLonQuery( lat, lon, () => {

} );

return () => queries.unregisterQuery( index );

} else if ( rayorigin !== null && raydirection !== null ) {

const ray = new Ray();

Check warning on line 31 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'Ray' is not defined

Check warning on line 31 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'Ray' is not defined
ray.origin.copy( rayorigin );
ray.direction.copy( raydirection );
const index = queries.registerLatLonQuery( lat, lon, () => {

} );

return () => queries.unregisterQuery( index );

}

}, [ lat, lon, rayorigin, raydirection ] );

Check warning on line 42 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

React Hook useEffect has a missing dependency: 'queries'. Either include it or remove the dependency array

Check warning on line 42 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (20.x)

React Hook useEffect has a missing dependency: 'queries'. Either include it or remove the dependency array

return <component { ...rest } ref={ useMultipleRefs( objectRef, ref ) } />;

} );

export const SettledObjects = forwardRef( function SettledObjects( props, ref ) {

const {
scene,
children,
...rest
} = props;

const tiles = useContext( TilesRendererContext );
const queries = useMemo( () => new QueryManager() );

useDeepOptions( queries, rest );

useEffect( () => {

queries.setScene( ...scene );

}, [ queries, scene ] );

useEffect( () => {

if ( tiles ) {

// TODO: we need to react to matrix update
queries.ellipsoid.copy( tiles.ellipsoid );
queries.frame.copy( tiles.group.matrixWorld );

}

}, [ queries, tiles ] );

useEffect( () => {

useMultipleRefs( ref )( queries );

Check failure on line 81 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

React Hook "useMultipleRefs" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function

Check failure on line 81 in src/r3f/components/SettledObjects.jsx

View workflow job for this annotation

GitHub Actions / build (20.x)

React Hook "useMultipleRefs" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function

}, [ queries, ref ] );

return (
<QueryManagerContext.Provider value={ queries }>
{ children }
</QueryManagerContext.Provider>
);

} );

0 comments on commit 8907a52

Please sign in to comment.