Last active
May 15, 2020 15:26
-
-
Save talentlessguy/18704253b4ac7f258ef6f91af792edc5 to your computer and use it in GitHub Desktop.
Trying to reach that instance of effect inside React code
This file contains hidden or 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
import { OutlineEffect } from 'postprocessing' | |
import { forwardRef, useMemo, useImperativeHandle } from 'react' | |
import { useThree } from 'react-three-fiber' | |
const Outline = forwardRef((props: OutlineEffect, ref) => { | |
const { scene, camera } = useThree() | |
const effect = useMemo(() => new OutlineEffect(scene, camera, props), [props]) | |
useImperativeHandle(ref, () => effect, [effect]) | |
return null | |
}) | |
export default Outline |
This file contains hidden or 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
import React, { useState, Suspense, useEffect, useRef } from 'react' | |
import { Canvas, useFrame } from 'react-three-fiber' | |
import { EffectComposer, Outline } from '../../dist/esm' | |
const OutlineDemo = () => { | |
const [selection, select] = useState() | |
const ref = useRef() | |
useEffect(() => { | |
console.log(ref) | |
ref.current?.selection.set(selection) | |
}, [selection]) | |
return ( | |
<Canvas> | |
<mesh onClick={(e) => select(e)}> | |
<coneGeometry args={[1, 3]} attach="geometry" /> | |
<meshPhongMaterial color="blue" attach="material" /> | |
</mesh> | |
<Suspense fallback={null}> | |
<EffectComposer> | |
{ /* undefined */ } | |
<Outline ref={ref} /> | |
</EffectComposer> | |
</Suspense> | |
</Canvas> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment