From 95d4e1d31547d5f9df0709f53e528b6db5a7973e Mon Sep 17 00:00:00 2001 From: Andrew Prifer <2991360+AndrewPrifer@users.noreply.github.com> Date: Wed, 18 May 2022 17:04:07 +0200 Subject: [PATCH] Create reference window for r3f (#169) * Add reference window (and fix tooltips) * Replace image with data url so the build doesn't fail --- .../playground/src/shared/r3f-rocket/App.tsx | 8 +- .../ReferenceWindow/ReferenceWindow.tsx | 149 ++++++++++++++++++ .../ReferenceWindow/noise-transparent.png | Bin 0 -> 11126 bytes .../components/ReferenceWindow/noiseImage.ts | 4 + .../r3f/src/components/SnapshotEditor.tsx | 96 ++++++----- .../src/components/TooltipPortalProvider.tsx | 27 ++++ packages/r3f/src/components/editorStuff.ts | 3 + 7 files changed, 247 insertions(+), 40 deletions(-) create mode 100644 packages/r3f/src/components/ReferenceWindow/ReferenceWindow.tsx create mode 100644 packages/r3f/src/components/ReferenceWindow/noise-transparent.png create mode 100644 packages/r3f/src/components/ReferenceWindow/noiseImage.ts create mode 100644 packages/r3f/src/components/TooltipPortalProvider.tsx diff --git a/packages/playground/src/shared/r3f-rocket/App.tsx b/packages/playground/src/shared/r3f-rocket/App.tsx index 19feef1..eb9b650 100644 --- a/packages/playground/src/shared/r3f-rocket/App.tsx +++ b/packages/playground/src/shared/r3f-rocket/App.tsx @@ -53,7 +53,13 @@ function App() { height: '100vh', }} > - + diff --git a/packages/r3f/src/components/ReferenceWindow/ReferenceWindow.tsx b/packages/r3f/src/components/ReferenceWindow/ReferenceWindow.tsx new file mode 100644 index 0000000..fe11ebf --- /dev/null +++ b/packages/r3f/src/components/ReferenceWindow/ReferenceWindow.tsx @@ -0,0 +1,149 @@ +import type {VFC} from 'react' +import React, {useEffect, useLayoutEffect, useRef} from 'react' +import {useEditorStore} from '../../store' +import shallow from 'zustand/shallow' +import type {WebGLRenderer} from 'three' +import useMeasure from 'react-use-measure' +import styled, {keyframes} from 'styled-components' +import {TiWarningOutline} from 'react-icons/ti' +// This is ugly, but pure TS doesn't let you do bundler-stuff +import noiseImageUrl from './noiseImage' + +const Container = styled.div` + position: relative; + width: fit-content; + height: fit-content; + border-radius: 4px; + overflow: hidden; +` + +const Canvas = styled.canvas` + display: block; +` + +const staticAnimation = keyframes` + 0% { transform: translate(0,0) } + 10% { transform: translate(-5%,-5%) } + 20% { transform: translate(-10%,5%) } + 30% { transform: translate(5%,-10%) } + 40% { transform: translate(-5%,15%) } + 50% { transform: translate(-10%,5%) } + 60% { transform: translate(15%,0) } + 70% { transform: translate(0,10%) } + 80% { transform: translate(-15%,0) } + 90% { transform: translate(10%,5%) } + 100% { transform: translate(5%,0) } +` + +const Static = styled.div` + position: relative; + display: flex; + width: 200px; + height: 120px; + padding: 18px; + + ::before { + content: ''; + position: absolute; + z-index: -1; + top: -50%; + left: -50%; + right: -50%; + bottom: -50%; + background: #2f2f2f url(${noiseImageUrl}) repeat 0 0; + animation: ${staticAnimation} 0.2s infinite; + } +` + +const Warning = styled.div` + display: flex; + flex-direction: column; + gap: 12px; + align-items: center; + text-align: center; + opacity: 0.8; +` + +interface ReferenceWindowProps { + height: number +} + +const ReferenceWindow: VFC = ({height}) => { + const canvasRef = useRef(null) + + const [gl] = useEditorStore((state) => [state.gl], shallow) + const [ref, bounds] = useMeasure() + + const preserveDrawingBuffer = + ( + gl?.domElement.getContext('webgl') ?? gl?.domElement.getContext('webgl2') + )?.getContextAttributes()?.preserveDrawingBuffer ?? false + + useLayoutEffect(() => { + if (gl) { + ref(gl?.domElement) + } + }, [gl, ref]) + + useEffect(() => { + let animationHandle: number + const draw = (gl: WebGLRenderer) => () => { + animationHandle = requestAnimationFrame(draw(gl)) + + if (!gl.domElement || !preserveDrawingBuffer) { + cancelAnimationFrame(animationHandle) + return + } + + const width = (gl.domElement.width / gl.domElement.height) * height + + const ctx = canvasRef.current!.getContext('2d')! + + console.log(gl.domElement.getContext('webgl2')!.getContextAttributes()) + + // https://stackoverflow.com/questions/17861447/html5-canvas-drawimage-how-to-apply-antialiasing + ctx.imageSmoothingQuality = 'high' + + ctx.fillStyle = 'white' + ctx.fillRect(0, 0, width, height) + + ctx.drawImage(gl.domElement, 0, 0, width, height) + } + + if (gl) { + draw(gl)() + } + + return () => { + cancelAnimationFrame(animationHandle) + } + }, [gl, height, preserveDrawingBuffer]) + + return ( + + {gl?.domElement && preserveDrawingBuffer ? ( + + ) : ( + + + + + Please set
{`gl={{ preserveDrawingBuffer: true }}`}
on + the r3f Canvas for the reference window to work. +
+
+
+ )} +
+ ) +} + +export default ReferenceWindow diff --git a/packages/r3f/src/components/ReferenceWindow/noise-transparent.png b/packages/r3f/src/components/ReferenceWindow/noise-transparent.png new file mode 100644 index 0000000000000000000000000000000000000000..45902c91f000dd388949c6bb7f1b766c7b3276f6 GIT binary patch literal 11126 zcmV-+D~Z&JP)tb-t+rE7k8rDQ&iT(NP=gL@hf(P| z@j8Irfqsc3R)?p@$5G)jyL$4hP9z=*1vTGIWhQY+yfyT21-Cc>AXMevB|urQtDs(Q zJPCA4L6LmJrRlZkjl$)vbIL8}(tMa*8ZgT-b}yPd0Q1;$%jiSA;2xZoPIg_hEJ!Q! zO5YvEKu{6gJi$_Nt1Q>BL(Cv4&XS&Nv~o9V3>StJM-cygf7wVjBVQ^cuVXW>+MD8b5#h6K@c z2_5>Z3r?Y-x0hLo4HYn=X+lluvjrI~z{=Di9T^b9EsdVf{@f`0E7}I5pvZ<=P)~|f zgHsZbAZS(>s!r)OlMoD8vZ=V(*EqwT9x(Pk*z+V$u=r$>D!FubUr&-~+|z6qAONKc z*CMk_F%kN8+~W=i;OMq@lcFceq z$5o7IN_9B)oQJJ+prtY35C_hPm3t^2@IjkLracY?>Rsr7k`mN|Yp%4ep^vpymr#%y zJt!6+bBZq68aq^u~pc@Lr1wb6QDlR6>HVT+yjuI=`B^)L$_)3*bVhqlFHAlcD zOJ$M>D|0KF;5X-+)8q-c;VkkOE$>V5GTXh^^3!ix9zwj}?pe#vp0#{h>C3~o4Cwgm zk|~=$iIRMTaFDyCblX;Cl(I5*eeO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HJ>HcfGq5w;Kl#f6P>J~?n~57}PDn;2`qZj1KD9i9!7p+z2}mQPE|Aj6 z-w<@+nC189$;$7t+z8sI zu1-m3qrFUJ*NmL^H6!JK9I5z#3SAtaLLoxn=^ZL`g)tJKt#jkn-DHY9noN(Fg=HM7 z5DLIjR>ws|9cPBLY+Nt-+6vx|hld1U7+HMUDsm}wvZd4|Te_{H({S@rp5s$o1bHJ{ zsyW#bxu{x%zdxFbsv!J*vl8U(-ZmsA{>t = (props) => { const snapshotEditorSheet = getEditorSheet() const paneId = props.paneId const editorObject = getEditorSheetObject() + const showReferenceWindow = + useVal(editorObject?.props.viewport.showReferenceWindow) ?? true + const [sceneSnapshot, createSnapshot] = useEditorStore( (state) => [state.sceneSnapshot, state.createSnapshot], shallow, @@ -148,43 +160,49 @@ const SnapshotEditor: React.FC<{paneId: string}> = (props) => { <> - - - - - - - - - - {sceneSnapshot ? ( - <> - - { - gl.setClearColor('white') - }} - shadowMap - dpr={[1, 2]} - fog={'red'} - frameloop="demand" - onPointerMissed={onPointerMissed} + + + + + - - - - - ) : null} - - {/* */} + + + + {showReferenceWindow && ( + + + + )} + + + {sceneSnapshot ? ( + <> + + { + gl.setClearColor('white') + }} + shadowMap + dpr={[1, 2]} + fog={'red'} + frameloop="demand" + onPointerMissed={onPointerMissed} + > + + + + + ) : null} + + diff --git a/packages/r3f/src/components/TooltipPortalProvider.tsx b/packages/r3f/src/components/TooltipPortalProvider.tsx new file mode 100644 index 0000000..0955e50 --- /dev/null +++ b/packages/r3f/src/components/TooltipPortalProvider.tsx @@ -0,0 +1,27 @@ +import type {ReactNode} from 'react'; +import React, { useState} from 'react' +import {PortalContext} from 'reakit' +import styled from 'styled-components' + +const PortalHost = styled.div` + position: fixed; + inset: 0; + pointer-events: none; +` + +export interface PortalManagerProps { + children: ReactNode +} + +const TooltipPortalProvider: React.VFC = ({children}) => { + const [wrapper, setWrapper] = useState(null) + + return ( + + {children} + + + ) +} + +export default TooltipPortalProvider diff --git a/packages/r3f/src/components/editorStuff.ts b/packages/r3f/src/components/editorStuff.ts index a039679..9fb4155 100644 --- a/packages/r3f/src/components/editorStuff.ts +++ b/packages/r3f/src/components/editorStuff.ts @@ -22,6 +22,9 @@ const editorSheetObjectConfig = { }, {as: 'menu', label: 'Shading'}, ), + showReferenceWindow: types.boolean(true, { + label: 'Reference', + }), }, {label: 'Viewport Config'}, ),