Skip to content

Commit

Permalink
Code simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson committed Feb 4, 2025
1 parent 3b2b47a commit a0f192f
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions src/r3f/components/SettledObjects.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,47 +137,43 @@ export const SettledObject = forwardRef( function SettledObject( props, ref ) {

useEffect( () => {

if ( lat !== null && lon !== null ) {
const callback = hit => {

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

if ( onQueryUpdate ) {
onQueryUpdate( hit );

onQueryUpdate( hit );
} else if ( tiles && hit !== null && objectRef.current !== null ) {

} else if ( tiles && hit !== null && objectRef.current !== null ) {
if ( lat !== null && lon !== null ) {

objectRef.current.position.copy( hit.point );
queries.ellipsoid.getRotationMatrixFromAzElRoll( lat, lon, 0, 0, 0, _matrix, OBJECT_FRAME ).premultiply( tiles.group.matrixWorld );
objectRef.current.quaternion.setFromRotationMatrix( _matrix );
invalidate();

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

objectRef.current.position.copy( hit.point );
objectRef.current.quaternion.identity();
invalidate();

}

} );
}

};

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

const index = queries.registerLatLonQuery( lat, lon, callback );
return () => queries.unregisterQuery( index );

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

_ray.origin.copy( rayorigin );
_ray.direction.copy( raydirection );
const index = queries.registerRayQuery( _ray, hit => {

if ( onQueryUpdate ) {

onQueryUpdate( hit );

} else if ( hit !== null && objectRef.current !== null ) {

objectRef.current.position.copy( hit.point );
objectRef.current.quaternion.identity();
invalidate();

}

} );

const index = queries.registerRayQuery( _ray, callback );
return () => queries.unregisterQuery( index );

}
Expand Down

0 comments on commit a0f192f

Please sign in to comment.