@react-three/fiber 10.0.0-canary.d458ee7 → 10.0.0-canary.d46ab63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extension.cjs +8 -8
- package/dist/extension.d.cts +50 -6
- package/dist/extension.d.mts +50 -6
- package/dist/extension.d.ts +50 -6
- package/dist/extension.mjs +1 -1
- package/dist/index.cjs +17 -19
- package/dist/index.d.cts +15 -47
- package/dist/index.d.mts +15 -47
- package/dist/index.d.ts +15 -47
- package/dist/index.mjs +7 -8
- package/dist/legacy.cjs +37 -15
- package/dist/legacy.d.cts +10 -7
- package/dist/legacy.d.mts +10 -7
- package/dist/legacy.d.ts +10 -7
- package/dist/legacy.mjs +13 -5
- package/dist/shared/{fiber.DNehrxK5.d.ts → fiber.34TOMPo3.d.cts} +157 -463
- package/dist/shared/fiber.BFuGd7gN.d.cts +90 -0
- package/dist/shared/{fiber.BgxhptM_.mjs → fiber.BSYBnw8x.mjs} +2066 -1497
- package/dist/shared/{fiber.B0oukOFO.mjs → fiber.Biz9olEe.mjs} +181 -64
- package/dist/shared/fiber.Bll9fqKA.d.mts +90 -0
- package/dist/shared/{fiber.TWXdbcWP.d.mts → fiber.CjMAAsJy.d.ts} +157 -463
- package/dist/shared/{fiber.I5Q4dVvl.d.cts → fiber.DQTSZ24m.d.cts} +488 -26
- package/dist/shared/{fiber.I5Q4dVvl.d.mts → fiber.DQTSZ24m.d.mts} +488 -26
- package/dist/shared/{fiber.I5Q4dVvl.d.ts → fiber.DQTSZ24m.d.ts} +488 -26
- package/dist/shared/fiber.DUgKvaq-.mjs +9 -0
- package/dist/shared/{fiber.khFlPHPf.cjs → fiber.DfiCufha.cjs} +186 -62
- package/dist/shared/fiber.DuA4F8L5.d.ts +90 -0
- package/dist/shared/{fiber.11sXr8Eb.d.cts → fiber.Dy7Uz273.d.mts} +157 -463
- package/dist/shared/fiber.X4yI0DId.cjs +14 -0
- package/dist/shared/{fiber.EDf0d92E.cjs → fiber.nDnBf1np.cjs} +2092 -1523
- package/dist/webgpu/index.cjs +16 -18
- package/dist/webgpu/index.d.cts +17 -78
- package/dist/webgpu/index.d.mts +17 -78
- package/dist/webgpu/index.d.ts +17 -78
- package/dist/webgpu/index.mjs +7 -9
- package/package.json +3 -3
- package/dist/chunks/webgl.cjs +0 -27
- package/dist/chunks/webgl.mjs +0 -11
- package/dist/shared/fiber.BU0vBHc9.d.mts +0 -48
- package/dist/shared/fiber.Cx-UAmMb.d.ts +0 -48
- package/dist/shared/fiber.DAl4H27x.d.cts +0 -48
|
@@ -28,16 +28,18 @@ function useMutableCallback(fn) {
|
|
|
28
28
|
useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
|
|
29
29
|
return ref;
|
|
30
30
|
}
|
|
31
|
+
const useActivityBridge = React__namespace["Activity"] ? itsFine.useActivityBridge : () => React__namespace.Fragment;
|
|
31
32
|
function useBridge() {
|
|
32
33
|
const fiber = itsFine.useFiber();
|
|
33
34
|
const ContextBridge = itsFine.useContextBridge();
|
|
35
|
+
const ActivityBridge = useActivityBridge();
|
|
34
36
|
return React__namespace.useMemo(
|
|
35
37
|
() => ({ children }) => {
|
|
36
38
|
const strict = !!itsFine.traverseFiber(fiber, true, (node) => node.type === React__namespace.StrictMode);
|
|
37
39
|
const Root = strict ? React__namespace.StrictMode : React__namespace.Fragment;
|
|
38
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Root, { children: /* @__PURE__ */ jsxRuntime.jsx(ContextBridge, { children }) });
|
|
40
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Root, { children: /* @__PURE__ */ jsxRuntime.jsx(ActivityBridge, { children: /* @__PURE__ */ jsxRuntime.jsx(ContextBridge, { children }) }) });
|
|
39
41
|
},
|
|
40
|
-
[fiber, ContextBridge]
|
|
42
|
+
[fiber, ContextBridge, ActivityBridge]
|
|
41
43
|
);
|
|
42
44
|
}
|
|
43
45
|
function Block({ set }) {
|
|
@@ -62,6 +64,23 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
62
64
|
}
|
|
63
65
|
}, __publicField(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
64
66
|
})();
|
|
67
|
+
const noop = () => {
|
|
68
|
+
};
|
|
69
|
+
function Gate({ promise, onSettled }) {
|
|
70
|
+
React__namespace.use(promise);
|
|
71
|
+
useIsomorphicLayoutEffect(onSettled, [onSettled]);
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
function useGate() {
|
|
75
|
+
const [promise, setPromise] = React__namespace.useState(null);
|
|
76
|
+
const onSettled = React__namespace.useCallback(() => setPromise(null), []);
|
|
77
|
+
const waitFor = React__namespace.useCallback(
|
|
78
|
+
(next) => setPromise((current) => current ?? Promise.resolve(next).then(noop, noop)),
|
|
79
|
+
[]
|
|
80
|
+
);
|
|
81
|
+
const gate = promise ? /* @__PURE__ */ jsxRuntime.jsx(React__namespace.Suspense, { fallback: null, children: /* @__PURE__ */ jsxRuntime.jsx(Gate, { promise, onSettled }) }) : null;
|
|
82
|
+
return [gate, waitFor];
|
|
83
|
+
}
|
|
65
84
|
|
|
66
85
|
const shownNotices = /* @__PURE__ */ new Set();
|
|
67
86
|
function notifyDepreciated({ heading, body, link }) {
|
|
@@ -119,10 +138,160 @@ function notifyAlpha({ message, link }) {
|
|
|
119
138
|
console.log(`%cMore info: ${link}`, "color: #6366f1; font-weight: normal;");
|
|
120
139
|
}
|
|
121
140
|
}
|
|
141
|
+
function isDevelopment() {
|
|
142
|
+
try {
|
|
143
|
+
return process.env.NODE_ENV !== "production";
|
|
144
|
+
} catch {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const INTERNAL_LIB_MARKERS = [
|
|
150
|
+
"zustand",
|
|
151
|
+
"setState",
|
|
152
|
+
"Object.assign",
|
|
153
|
+
"@pmndrs/scheduler",
|
|
154
|
+
"Scheduler.tickRoot",
|
|
155
|
+
"Scheduler.stepJob"
|
|
156
|
+
];
|
|
157
|
+
function isInternalRendererAccess(stack, callerDepth = 2) {
|
|
158
|
+
if (!stack) return false;
|
|
159
|
+
const caller = stack.split("\n")[callerDepth] ?? "";
|
|
160
|
+
return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const isAccessorDescriptor = (descriptor) => !!descriptor && (descriptor.get !== void 0 || descriptor.set !== void 0);
|
|
164
|
+
const isAccessor = (object, key) => isAccessorDescriptor(Object.getOwnPropertyDescriptor(object, key));
|
|
165
|
+
function cloneState(...sources) {
|
|
166
|
+
const target = {};
|
|
167
|
+
for (const source of sources) {
|
|
168
|
+
if (source) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
169
|
+
}
|
|
170
|
+
return target;
|
|
171
|
+
}
|
|
172
|
+
function preserveAccessors(rawSet, get) {
|
|
173
|
+
return ((partial, replace) => {
|
|
174
|
+
const previous = get();
|
|
175
|
+
const patch = typeof partial === "function" ? partial(previous) : partial;
|
|
176
|
+
if (replace || !previous || patch == null || Object.is(patch, previous)) {
|
|
177
|
+
return rawSet(patch, replace);
|
|
178
|
+
}
|
|
179
|
+
const next = cloneState(previous);
|
|
180
|
+
const viaSetter = [];
|
|
181
|
+
for (const key of Reflect.ownKeys(patch)) {
|
|
182
|
+
const descriptor = Object.getOwnPropertyDescriptor(patch, key);
|
|
183
|
+
if (!descriptor.enumerable) continue;
|
|
184
|
+
if (isAccessorDescriptor(descriptor)) {
|
|
185
|
+
Object.defineProperty(next, key, descriptor);
|
|
186
|
+
} else if (isAccessor(next, key)) {
|
|
187
|
+
viaSetter.push(key);
|
|
188
|
+
} else {
|
|
189
|
+
Object.defineProperty(next, key, {
|
|
190
|
+
value: descriptor.value,
|
|
191
|
+
writable: true,
|
|
192
|
+
enumerable: true,
|
|
193
|
+
configurable: true
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
for (const key of viaSetter) next[key] = patch[key];
|
|
198
|
+
rawSet(next, true);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
const keepAccessors = (initializer) => (rawSet, get, api) => {
|
|
202
|
+
const set = preserveAccessors(rawSet, get);
|
|
203
|
+
api.setState = set;
|
|
204
|
+
return initializer(set, get, api);
|
|
205
|
+
};
|
|
206
|
+
let glNoticeShown = false;
|
|
207
|
+
function defineRendererAccessors(state) {
|
|
208
|
+
Object.defineProperty(state, "gl", {
|
|
209
|
+
get() {
|
|
210
|
+
const renderer = this.internal?.actualRenderer;
|
|
211
|
+
if (!glNoticeShown && renderer && !this.isLegacy) {
|
|
212
|
+
const stack = new Error().stack || "";
|
|
213
|
+
if (!isInternalRendererAccess(stack)) {
|
|
214
|
+
glNoticeShown = true;
|
|
215
|
+
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
216
|
+
notifyDepreciated({
|
|
217
|
+
heading: "Accessing state.gl in WebGPU mode",
|
|
218
|
+
body: "Please use state.renderer instead. state.gl is deprecated and will be removed in future versions.\n\nFor backwards compatibility, state.gl currently maps to state.renderer, but this may cause issues with libraries expecting WebGLRenderer.\n\nAccessed from:\n" + cleanedStack
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return renderer;
|
|
223
|
+
},
|
|
224
|
+
set(value) {
|
|
225
|
+
this.internal.actualRenderer = value;
|
|
226
|
+
},
|
|
227
|
+
enumerable: true,
|
|
228
|
+
configurable: true
|
|
229
|
+
});
|
|
230
|
+
Object.defineProperty(state, "renderer", {
|
|
231
|
+
get() {
|
|
232
|
+
return this.internal?.actualRenderer;
|
|
233
|
+
},
|
|
234
|
+
set(value) {
|
|
235
|
+
this.internal.actualRenderer = value;
|
|
236
|
+
},
|
|
237
|
+
enumerable: true,
|
|
238
|
+
configurable: true
|
|
239
|
+
});
|
|
240
|
+
}
|
|
122
241
|
|
|
123
242
|
const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
|
|
124
243
|
const context = globalThis[R3F_CONTEXT] ?? (globalThis[R3F_CONTEXT] = React__namespace.createContext(null));
|
|
125
244
|
|
|
245
|
+
const R3F_EXTENSIONS = Symbol.for("@react-three/fiber.extensions");
|
|
246
|
+
function getRegistry() {
|
|
247
|
+
return globalThis[R3F_EXTENSIONS] ?? (globalThis[R3F_EXTENSIONS] = {
|
|
248
|
+
extensions: /* @__PURE__ */ new Map(),
|
|
249
|
+
roots: /* @__PURE__ */ new Set(),
|
|
250
|
+
applied: /* @__PURE__ */ new WeakMap()
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
function setupRoot(registry, store, extension) {
|
|
254
|
+
let applied = registry.applied.get(store);
|
|
255
|
+
if (!applied) registry.applied.set(store, applied = /* @__PURE__ */ new Map());
|
|
256
|
+
if (applied.has(extension.name)) return;
|
|
257
|
+
applied.set(extension.name, extension);
|
|
258
|
+
const patch = extension.setup?.(store);
|
|
259
|
+
if (patch) store.setState(patch);
|
|
260
|
+
}
|
|
261
|
+
function registerRootExtension(extension) {
|
|
262
|
+
const registry = getRegistry();
|
|
263
|
+
registry.extensions.set(extension.name, extension);
|
|
264
|
+
for (const store of registry.roots) setupRoot(registry, store, extension);
|
|
265
|
+
return () => {
|
|
266
|
+
if (registry.extensions.get(extension.name) === extension) registry.extensions.delete(extension.name);
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
function setRenderOverride(store, render) {
|
|
270
|
+
store.getState().internal.renderOverride = render;
|
|
271
|
+
}
|
|
272
|
+
function attachRootExtensions(store) {
|
|
273
|
+
const registry = getRegistry();
|
|
274
|
+
registry.roots.add(store);
|
|
275
|
+
for (const extension of registry.extensions.values()) setupRoot(registry, store, extension);
|
|
276
|
+
}
|
|
277
|
+
function current(registry, setUpBy) {
|
|
278
|
+
return registry.extensions.get(setUpBy.name) ?? setUpBy;
|
|
279
|
+
}
|
|
280
|
+
function detachRootExtensions(store) {
|
|
281
|
+
const registry = getRegistry();
|
|
282
|
+
if (!registry.roots.delete(store)) return;
|
|
283
|
+
const applied = registry.applied.get(store);
|
|
284
|
+
registry.applied.delete(store);
|
|
285
|
+
if (!applied) return;
|
|
286
|
+
for (const setUpBy of applied.values()) current(registry, setUpBy).dispose?.(store);
|
|
287
|
+
}
|
|
288
|
+
function notifyRootExtensionsHmr(store) {
|
|
289
|
+
const registry = getRegistry();
|
|
290
|
+
const applied = registry.applied.get(store);
|
|
291
|
+
if (!applied) return;
|
|
292
|
+
for (const setUpBy of applied.values()) current(registry, setUpBy).hmr?.(store);
|
|
293
|
+
}
|
|
294
|
+
|
|
126
295
|
function useStore() {
|
|
127
296
|
const store = React.useContext(context);
|
|
128
297
|
if (!store) throw new Error("R3F: Hooks can only be used within the Canvas component!");
|
|
@@ -149,8 +318,8 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
149
318
|
const options = React__namespace.useMemo(() => {
|
|
150
319
|
return typeof priorityOrOptions === "number" ? { priority: priorityOrOptions } : priorityOrOptions ?? {};
|
|
151
320
|
}, [optionsKey]);
|
|
152
|
-
const
|
|
153
|
-
const id = options.id ??
|
|
321
|
+
const [generatedId] = React__namespace.useState(() => scheduler$1.generateJobId());
|
|
322
|
+
const id = options.id ?? generatedId;
|
|
154
323
|
const callbackRef = useMutableCallback(callback);
|
|
155
324
|
const isLegacyPriority = typeof priorityOrOptions === "number" && priorityOrOptions > 0;
|
|
156
325
|
const isLegacyOrdering = typeof priorityOrOptions === "number" && priorityOrOptions < 0;
|
|
@@ -181,14 +350,12 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
181
350
|
});
|
|
182
351
|
}
|
|
183
352
|
const wrappedCallback = (frameState, delta) => {
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
frame: frameState.frame
|
|
191
|
-
};
|
|
353
|
+
const mergedState = cloneState(store.getState());
|
|
354
|
+
mergedState.time = frameState.time;
|
|
355
|
+
mergedState.delta = frameState.delta;
|
|
356
|
+
mergedState.elapsed = frameState.elapsed;
|
|
357
|
+
mergedState.frame = frameState.frame;
|
|
358
|
+
mergedState.overstep = frameState.overstep;
|
|
192
359
|
callbackRef.current?.(mergedState, delta);
|
|
193
360
|
};
|
|
194
361
|
const unregister = scheduler$1.register(wrappedCallback, {
|
|
@@ -326,71 +493,28 @@ function getTextureView(store) {
|
|
|
326
493
|
return view;
|
|
327
494
|
}
|
|
328
495
|
|
|
329
|
-
const R3F_EXTENSIONS = Symbol.for("@react-three/fiber.extensions");
|
|
330
|
-
function getRegistry() {
|
|
331
|
-
return globalThis[R3F_EXTENSIONS] ?? (globalThis[R3F_EXTENSIONS] = {
|
|
332
|
-
extensions: /* @__PURE__ */ new Map(),
|
|
333
|
-
roots: /* @__PURE__ */ new Set(),
|
|
334
|
-
applied: /* @__PURE__ */ new WeakMap()
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
function setupRoot(registry, store, extension) {
|
|
338
|
-
let applied = registry.applied.get(store);
|
|
339
|
-
if (!applied) registry.applied.set(store, applied = /* @__PURE__ */ new Map());
|
|
340
|
-
if (applied.has(extension.name)) return;
|
|
341
|
-
applied.set(extension.name, extension);
|
|
342
|
-
const patch = extension.setup?.(store);
|
|
343
|
-
if (patch) store.setState(patch);
|
|
344
|
-
}
|
|
345
|
-
function registerRootExtension(extension) {
|
|
346
|
-
const registry = getRegistry();
|
|
347
|
-
registry.extensions.set(extension.name, extension);
|
|
348
|
-
for (const store of registry.roots) setupRoot(registry, store, extension);
|
|
349
|
-
return () => {
|
|
350
|
-
if (registry.extensions.get(extension.name) === extension) registry.extensions.delete(extension.name);
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
function setRenderOverride(store, render) {
|
|
354
|
-
store.getState().internal.renderOverride = render;
|
|
355
|
-
}
|
|
356
|
-
function attachRootExtensions(store) {
|
|
357
|
-
const registry = getRegistry();
|
|
358
|
-
registry.roots.add(store);
|
|
359
|
-
for (const extension of registry.extensions.values()) setupRoot(registry, store, extension);
|
|
360
|
-
}
|
|
361
|
-
function current(registry, setUpBy) {
|
|
362
|
-
return registry.extensions.get(setUpBy.name) ?? setUpBy;
|
|
363
|
-
}
|
|
364
|
-
function detachRootExtensions(store) {
|
|
365
|
-
const registry = getRegistry();
|
|
366
|
-
if (!registry.roots.delete(store)) return;
|
|
367
|
-
const applied = registry.applied.get(store);
|
|
368
|
-
registry.applied.delete(store);
|
|
369
|
-
if (!applied) return;
|
|
370
|
-
for (const setUpBy of applied.values()) current(registry, setUpBy).dispose?.(store);
|
|
371
|
-
}
|
|
372
|
-
function notifyRootExtensionsHmr(store) {
|
|
373
|
-
const registry = getRegistry();
|
|
374
|
-
const applied = registry.applied.get(store);
|
|
375
|
-
if (!applied) return;
|
|
376
|
-
for (const setUpBy of applied.values()) current(registry, setUpBy).hmr?.(store);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
496
|
exports.Block = Block;
|
|
380
497
|
exports.ErrorBoundary = ErrorBoundary;
|
|
381
498
|
exports.attachRootExtensions = attachRootExtensions;
|
|
499
|
+
exports.cloneState = cloneState;
|
|
382
500
|
exports.context = context;
|
|
501
|
+
exports.defineRendererAccessors = defineRendererAccessors;
|
|
383
502
|
exports.detachRootExtensions = detachRootExtensions;
|
|
384
503
|
exports.getTextureView = getTextureView;
|
|
504
|
+
exports.isAccessor = isAccessor;
|
|
505
|
+
exports.isDevelopment = isDevelopment;
|
|
506
|
+
exports.keepAccessors = keepAccessors;
|
|
385
507
|
exports.notifyAlpha = notifyAlpha;
|
|
386
508
|
exports.notifyDepreciated = notifyDepreciated;
|
|
387
509
|
exports.notifyRootExtensionsHmr = notifyRootExtensionsHmr;
|
|
510
|
+
exports.preserveAccessors = preserveAccessors;
|
|
388
511
|
exports.registerRootExtension = registerRootExtension;
|
|
389
512
|
exports.setRenderOverride = setRenderOverride;
|
|
390
513
|
exports.stageTextures = stageTextures;
|
|
391
514
|
exports.unstageTextures = unstageTextures;
|
|
392
515
|
exports.useBridge = useBridge;
|
|
393
516
|
exports.useFrame = useFrame;
|
|
517
|
+
exports.useGate = useGate;
|
|
394
518
|
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
|
|
395
519
|
exports.useMutableCallback = useMutableCallback;
|
|
396
520
|
exports.useStore = useStore;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { FrameCallback, UseFrameNextOptions, FrameNextControls } from '@pmndrs/scheduler';
|
|
2
|
+
import { WebGPURenderer, WebGPURendererParameters, RenderTarget } from 'three/webgpu';
|
|
3
|
+
import { H as RootState, I as InternalState, a8 as RendererFactory, a7 as BaseRendererProps, az as Properties } from './fiber.DQTSZ24m.js';
|
|
4
|
+
import { R as RenderTargetOptions, aU as CanvasProps } from './fiber.CjMAAsJy.js';
|
|
5
|
+
|
|
6
|
+
//* Renderer Props ========================================
|
|
7
|
+
|
|
8
|
+
type WebGPUDefaultProps = Omit<WebGPURendererParameters, 'canvas'> & BaseRendererProps
|
|
9
|
+
|
|
10
|
+
type WebGPUProps =
|
|
11
|
+
| RendererFactory<WebGPURenderer, WebGPUDefaultProps>
|
|
12
|
+
| Partial<Properties<WebGPURenderer> | WebGPURendererParameters>
|
|
13
|
+
|
|
14
|
+
// WebGPU doesn't have shadow maps in the same way
|
|
15
|
+
interface WebGPUShadowConfig {
|
|
16
|
+
shadows?: boolean // Simplified for WebGPU
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//* WebGPU-specific Types ========================================
|
|
20
|
+
|
|
21
|
+
/** WebGPU renderer type - re-exported as R3FRenderer from @react-three/fiber/webgpu */
|
|
22
|
+
type WebGPUR3FRenderer = WebGPURenderer
|
|
23
|
+
|
|
24
|
+
/** WebGPU internal state with narrowed renderer type */
|
|
25
|
+
interface WebGPUInternalState extends Omit<InternalState, 'actualRenderer'> {
|
|
26
|
+
actualRenderer: WebGPURenderer
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* WebGPU-specific RootState with narrowed renderer type.
|
|
31
|
+
* Automatically used when importing from `@react-three/fiber/webgpu`.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* import { useThree } from '@react-three/fiber/webgpu'
|
|
36
|
+
*
|
|
37
|
+
* function MyComponent() {
|
|
38
|
+
* const { renderer } = useThree()
|
|
39
|
+
* // renderer is typed as WebGPURenderer
|
|
40
|
+
* renderer.compute(computePass)
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
// `gl` is not narrowed: it keeps the base type (WebGLRenderer, for code written against it), so a
|
|
45
|
+
// WebGPURootState stays assignable to RootState and `useFrame((state: RootState) => ...)` still
|
|
46
|
+
// compiles where the hooks are WebGPU-typed. At runtime it aliases `renderer`; use that instead.
|
|
47
|
+
interface WebGPURootState extends Omit<RootState, 'renderer' | 'internal'> {
|
|
48
|
+
/** The WebGPU renderer instance */
|
|
49
|
+
renderer: WebGPURenderer
|
|
50
|
+
/** Internals with WebGPU renderer */
|
|
51
|
+
internal: WebGPUInternalState
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @fileoverview WebGPU-narrowed hook and Canvas types, shared by the entries that render with WebGPU
|
|
56
|
+
*
|
|
57
|
+
* `@react-three/fiber` and `@react-three/fiber/webgpu` both render with WebGPURenderer. The core
|
|
58
|
+
* hooks are declared against the base RootState, whose `renderer` is the R3FRenderer union
|
|
59
|
+
* (WebGLRenderer included) so that libraries typed against it also compile for `/legacy` apps. On
|
|
60
|
+
* these entries that union is already resolved, so leaving it in place forced a cast for anything
|
|
61
|
+
* WebGPU-only:
|
|
62
|
+
*
|
|
63
|
+
* const renderer = useThree((s) => s.renderer)
|
|
64
|
+
* renderer.compute(node) // Property 'compute' does not exist on type 'R3FRenderer'
|
|
65
|
+
*
|
|
66
|
+
* The entries re-export the hooks below instead. Types only: the values are the core
|
|
67
|
+
* implementations untouched, so there is no runtime cost and no second code path to keep in sync.
|
|
68
|
+
* See https://github.com/pmndrs/react-three-fiber/issues/3851
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
/** `useThree` narrowed to WebGPU state — `state.renderer` is a `WebGPURenderer`. */
|
|
72
|
+
type UseThreeWebGPU = <T = WebGPURootState>(selector?: (state: WebGPURootState) => T, equalityFn?: <U>(state: U, newState: U) => boolean) => T;
|
|
73
|
+
/** `useFrame` narrowed to WebGPU state — the callback's `state.renderer` is a `WebGPURenderer`. */
|
|
74
|
+
type UseFrameWebGPU = (callback?: FrameCallback<WebGPURootState>, priorityOrOptions?: number | UseFrameNextOptions) => FrameNextControls;
|
|
75
|
+
declare const useThree: UseThreeWebGPU;
|
|
76
|
+
declare const useFrame: UseFrameWebGPU;
|
|
77
|
+
/** `useRenderTarget` narrowed to the target a WebGPU renderer produces. */
|
|
78
|
+
declare const useRenderTarget: {
|
|
79
|
+
(options?: RenderTargetOptions): RenderTarget;
|
|
80
|
+
(size: number, options?: RenderTargetOptions): RenderTarget;
|
|
81
|
+
(width: number, height: number, options?: RenderTargetOptions): RenderTarget;
|
|
82
|
+
};
|
|
83
|
+
/** Canvas props on a WebGPU entry: `onCreated` receives `WebGPURootState`. */
|
|
84
|
+
type WebGPUCanvasProps = Omit<CanvasProps, 'onCreated'> & {
|
|
85
|
+
/** Callback after the canvas has rendered (but not yet committed); `state.renderer` is a `WebGPURenderer` */
|
|
86
|
+
onCreated?: (state: WebGPURootState) => void;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export { useFrame as a, useRenderTarget as b, useThree as u };
|
|
90
|
+
export type { UseThreeWebGPU as U, WebGPUCanvasProps as W, UseFrameWebGPU as c, WebGPURootState as d, WebGPUInternalState as e, WebGPUR3FRenderer as f, WebGPUProps as g, WebGPUDefaultProps as h, WebGPUShadowConfig as i };
|