From 4a99e7c844d8cf49eeea50f5c9e8730387db517b Mon Sep 17 00:00:00 2001 From: Cody Bennett Date: Sat, 21 Oct 2023 06:32:17 -0500 Subject: [PATCH] fix: ignore deprecated types, use correct XRFrame definition (#3052) --- packages/fiber/package.json | 1 + packages/fiber/src/core/index.tsx | 3 ++- packages/fiber/src/core/loop.ts | 11 +++-------- packages/fiber/src/core/store.ts | 7 +++---- packages/fiber/src/core/utils.ts | 6 ++++++ packages/fiber/src/three-types.ts | 33 ++++++++++++++++++++++++++++++- yarn.lock | 5 +++++ 7 files changed, 52 insertions(+), 14 deletions(-) diff --git a/packages/fiber/package.json b/packages/fiber/package.json index 9d1a75aa9a..a4afa18843 100644 --- a/packages/fiber/package.json +++ b/packages/fiber/package.json @@ -44,6 +44,7 @@ "dependencies": { "@babel/runtime": "^7.17.8", "@types/react-reconciler": "^0.26.7", + "@types/webxr": "*", "base64-js": "^1.5.1", "buffer": "^6.0.3", "its-fine": "^1.0.6", diff --git a/packages/fiber/src/core/index.tsx b/packages/fiber/src/core/index.tsx index 3b754de465..c23fd7e4d8 100644 --- a/packages/fiber/src/core/index.tsx +++ b/packages/fiber/src/core/index.tsx @@ -30,6 +30,7 @@ import { updateCamera, getColorManagement, buildGraph, + _XRFrame, } from './utils' import { useStore } from './hooks' import type { Properties } from '../three-types' @@ -245,7 +246,7 @@ function createRoot(canvas: TCanvas): ReconcilerRoot { + const handleXRFrame = (timestamp: number, frame?: _XRFrame) => { const state = store.getState() if (state.frameloop === 'never') return advance(timestamp, true, state, frame) diff --git a/packages/fiber/src/core/loop.ts b/packages/fiber/src/core/loop.ts index 4c15b897cb..065b35d223 100644 --- a/packages/fiber/src/core/loop.ts +++ b/packages/fiber/src/core/loop.ts @@ -1,6 +1,6 @@ -import * as THREE from 'three' import { Root } from './renderer' import { RootState, Subscription } from './store' +import { _XRFrame } from './utils' export type GlobalRenderCallback = (timeStamp: number) => void type SubItem = { callback: GlobalRenderCallback } @@ -56,7 +56,7 @@ export function flushGlobalEffects(type: GlobalEffectType, timestamp: number): v let subscribers: Subscription[] let subscription: Subscription -function render(timestamp: number, state: RootState, frame?: THREE.XRFrame) { +function render(timestamp: number, state: RootState, frame?: _XRFrame) { // Run local effects let delta = state.clock.getDelta() // In frameloop='never' mode, clock times are updated using the provided timestamp @@ -131,12 +131,7 @@ export function createLoop(roots: Map) { } } - function advance( - timestamp: number, - runGlobalEffects: boolean = true, - state?: RootState, - frame?: THREE.XRFrame, - ): void { + function advance(timestamp: number, runGlobalEffects: boolean = true, state?: RootState, frame?: _XRFrame): void { if (runGlobalEffects) flushGlobalEffects('before', timestamp) if (!state) for (const root of roots.values()) render(timestamp, root.store.getState()) else render(timestamp, state, frame) diff --git a/packages/fiber/src/core/store.ts b/packages/fiber/src/core/store.ts index c392ad952f..920c8b43a5 100644 --- a/packages/fiber/src/core/store.ts +++ b/packages/fiber/src/core/store.ts @@ -1,9 +1,8 @@ import * as THREE from 'three' import * as React from 'react' import create, { GetState, SetState, StoreApi, UseBoundStore } from 'zustand' -import { prepare } from './renderer' import { DomEvent, EventManager, PointerCaptureTarget, ThreeEvent } from './events' -import { calculateDpr, Camera, isOrthographicCamera, updateCamera } from './utils' +import { _XRFrame, calculateDpr, Camera, isOrthographicCamera, updateCamera } from './utils' // Keys that shouldn't be copied between R3F stores export const privateKeys = [ @@ -53,7 +52,7 @@ export type Viewport = Size & { aspect: number } -export type RenderCallback = (state: RootState, delta: number, frame?: THREE.XRFrame) => void +export type RenderCallback = (state: RootState, delta: number, frame?: _XRFrame) => void export type Performance = { /** Current performance normal, between min and max */ @@ -167,7 +166,7 @@ const context = React.createContext>(null!) const createStore = ( invalidate: (state?: RootState, frames?: number) => void, - advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState, frame?: THREE.XRFrame) => void, + advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState, frame?: _XRFrame) => void, ): UseBoundStore => { const rootState = create((set, get) => { const position = new THREE.Vector3() diff --git a/packages/fiber/src/core/utils.ts b/packages/fiber/src/core/utils.ts index 3810d4159a..ffaaa0d56d 100644 --- a/packages/fiber/src/core/utils.ts +++ b/packages/fiber/src/core/utils.ts @@ -1,3 +1,4 @@ +/// import * as THREE from 'three' import * as React from 'react' import { UseBoundStore } from 'zustand' @@ -5,6 +6,11 @@ import { EventHandlers } from './events' import { AttachType, catalogue, Instance, InstanceProps, LocalState } from './renderer' import { Dpr, Renderer, RootState, Size } from './store' +// < r141 shipped vendored types https://github.com/pmndrs/react-three-fiber/issues/2501 +// @ts-ignore +type _DeprecatedXRFrame = THREE.XRFrame +export type _XRFrame = THREE.WebGLRenderTargetOptions extends { samples?: number } ? XRFrame : _DeprecatedXRFrame + /** * Returns `true` with correct TS type inference if an object has a configurable color space (since r152). */ diff --git a/packages/fiber/src/three-types.ts b/packages/fiber/src/three-types.ts index da83071fb9..163de7b6f3 100644 --- a/packages/fiber/src/three-types.ts +++ b/packages/fiber/src/three-types.ts @@ -98,53 +98,81 @@ export type InstancedBufferGeometryProps = BufferGeometryNode< typeof THREE.InstancedBufferGeometry > export type BufferGeometryProps = BufferGeometryNode +// @ts-ignore export type BoxBufferGeometryProps = BufferGeometryNode export type CircleBufferGeometryProps = BufferGeometryNode< + // @ts-ignore THREE.CircleBufferGeometry, + // @ts-ignore typeof THREE.CircleBufferGeometry > +// @ts-ignore export type ConeBufferGeometryProps = BufferGeometryNode export type CylinderBufferGeometryProps = BufferGeometryNode< + // @ts-ignore THREE.CylinderBufferGeometry, + // @ts-ignore typeof THREE.CylinderBufferGeometry > export type DodecahedronBufferGeometryProps = BufferGeometryNode< + // @ts-ignore THREE.DodecahedronBufferGeometry, + // @ts-ignore typeof THREE.DodecahedronBufferGeometry > export type ExtrudeBufferGeometryProps = BufferGeometryNode< + // @ts-ignore THREE.ExtrudeBufferGeometry, + // @ts-ignore typeof THREE.ExtrudeBufferGeometry > export type IcosahedronBufferGeometryProps = BufferGeometryNode< + // @ts-ignore THREE.IcosahedronBufferGeometry, + // @ts-ignore typeof THREE.IcosahedronBufferGeometry > +// @ts-ignore export type LatheBufferGeometryProps = BufferGeometryNode export type OctahedronBufferGeometryProps = BufferGeometryNode< + // @ts-ignore THREE.OctahedronBufferGeometry, + // @ts-ignore typeof THREE.OctahedronBufferGeometry > +// @ts-ignore export type PlaneBufferGeometryProps = BufferGeometryNode export type PolyhedronBufferGeometryProps = BufferGeometryNode< + // @ts-ignore THREE.PolyhedronBufferGeometry, + // @ts-ignore typeof THREE.PolyhedronBufferGeometry > +// @ts-ignore export type RingBufferGeometryProps = BufferGeometryNode +// @ts-ignore export type ShapeBufferGeometryProps = BufferGeometryNode export type SphereBufferGeometryProps = BufferGeometryNode< + // @ts-ignore THREE.SphereBufferGeometry, + // @ts-ignore typeof THREE.SphereBufferGeometry > export type TetrahedronBufferGeometryProps = BufferGeometryNode< + // @ts-ignore THREE.TetrahedronBufferGeometry, + // @ts-ignore typeof THREE.TetrahedronBufferGeometry > +// @ts-ignore export type TorusBufferGeometryProps = BufferGeometryNode export type TorusKnotBufferGeometryProps = BufferGeometryNode< + // @ts-ignore THREE.TorusKnotBufferGeometry, + // @ts-ignore typeof THREE.TorusKnotBufferGeometry > +// @ts-ignore export type TubeBufferGeometryProps = BufferGeometryNode export type WireframeGeometryProps = BufferGeometryNode export type TetrahedronGeometryProps = BufferGeometryNode @@ -169,7 +197,7 @@ export type ConeGeometryProps = BufferGeometryNode export type CircleGeometryProps = BufferGeometryNode export type BoxGeometryProps = BufferGeometryNode -export type CapsuleGeometryProps = BufferGeometryNode +export type CapsuleGeometryProps = BufferGeometryNode export type MaterialProps = MaterialNode export type ShadowMaterialProps = MaterialNode @@ -202,7 +230,9 @@ export type DirectionalLightShadowProps = Node export type AmbientLightProps = LightNode export type LightShadowProps = Node +// @ts-ignore export type AmbientLightProbeProps = LightNode +// @ts-ignore export type HemisphereLightProbeProps = LightNode export type LightProbeProps = LightNode @@ -226,6 +256,7 @@ export type AxesHelperProps = Object3DNode export type VideoTextureProps = Node export type DataTextureProps = Node +// @ts-ignore export type DataTexture3DProps = Node export type CompressedTextureProps = Node export type CubeTextureProps = Node diff --git a/yarn.lock b/yarn.lock index d90433eb09..d7600e7500 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2730,6 +2730,11 @@ resolved "https://registry.yarnpkg.com/@types/three/-/three-0.139.0.tgz#69af1f0c52f8eea390f513e05478af1dd7f49e6f" integrity sha512-4V/jZhyq7Mv05coUzxL3bz8AuBOSi/1F0RY7ujisHTV0Amy/fnYJ+s7TSJ1/hXjZukSkpuFRgV+wvWUEMbsMbQ== +"@types/webxr@*": + version "0.5.6" + resolved "https://registry.yarnpkg.com/@types/webxr/-/webxr-0.5.6.tgz#835c7ac9983a732e2e849d0d302bc735aa455126" + integrity sha512-/uWg82/WT+Pl18b2kkG6nlbiiaNIb8RN2mvvcGexGvwLvUrEhDhGBzYHiwa5nQPtin0hISyrXkKOKVScTK+kKg== + "@types/webxr@^0.5.2": version "0.5.2" resolved "https://registry.yarnpkg.com/@types/webxr/-/webxr-0.5.2.tgz#5d9627b0ffe223aa3b166de7112ac8a9460dc54f"