-
Notifications
You must be signed in to change notification settings - Fork 678
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add <FlyControls /> * Added Flycontrols to index * Removed useEffect. Using delta from useFrame. * Updated README. * Added fly controls story. Co-authored-by: lucathebest <luca_marangon@inapl.com>
- Loading branch information
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react' | ||
import { withKnobs, number, boolean } from '@storybook/addon-knobs' | ||
|
||
import { Setup } from '../Setup' | ||
|
||
import { FlyControls } from '../../src/FlyControls' | ||
import { Box } from '../../src/shapes' | ||
|
||
export function FlyControlsStory() { | ||
return ( | ||
<> | ||
<FlyControls | ||
autoForward={boolean('AutoForward', false)} | ||
dragToLook={boolean('DragToLook', false)} | ||
movementSpeed={number('MovementSpeed', 1.0)} | ||
rollSpeed={number('RollSpeed', 0.005)} | ||
/> | ||
<Box> | ||
<meshBasicMaterial attach="material" wireframe /> | ||
</Box> | ||
</> | ||
) | ||
} | ||
|
||
FlyControlsStory.storyName = 'Default' | ||
|
||
export default { | ||
title: 'Controls/FlyControls', | ||
component: FlyControls, | ||
decorators: [withKnobs, (storyFn) => <Setup controls={false}>{storyFn()}</Setup>], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, { forwardRef, useRef } from 'react' | ||
import { ReactThreeFiber, extend, useThree, useFrame, Overwrite } from 'react-three-fiber' | ||
import { FlyControls as FlyControlsImpl } from 'three/examples/jsm/controls/FlyControls' | ||
// @ts-ignore | ||
import mergeRefs from 'react-merge-refs' | ||
|
||
extend({ FlyControlsImpl }) | ||
|
||
export type FlyControls = Overwrite< | ||
ReactThreeFiber.Object3DNode<FlyControlsImpl, typeof FlyControlsImpl>, | ||
{ target?: ReactThreeFiber.Vector3 } | ||
> | ||
|
||
declare global { | ||
namespace JSX { | ||
// eslint-disable-next-line @typescript-eslint/interface-name-prefix | ||
interface IntrinsicElements { | ||
flyControlsImpl: FlyControls | ||
} | ||
} | ||
} | ||
|
||
export const FlyControls = forwardRef((props: FlyControls, ref) => { | ||
const controls = useRef<FlyControlsImpl>() | ||
const { camera, gl } = useThree() | ||
useFrame((state, delta) => controls.current?.update(delta)) | ||
return <flyControlsImpl ref={mergeRefs([controls, ref])} args={[camera, gl.domElement]} {...props} /> | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters