@react-three/fiber 10.0.0-canary.39882dd → 10.0.0-canary.42caa10
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/chunks/webgpu.cjs +37 -0
- package/dist/chunks/webgpu.mjs +21 -0
- package/dist/extension.cjs +13 -0
- package/dist/extension.d.cts +63 -0
- package/dist/extension.d.mts +63 -0
- package/dist/extension.d.ts +63 -0
- package/dist/extension.mjs +1 -0
- package/dist/index.cjs +98 -15370
- package/dist/index.d.cts +101 -3774
- package/dist/index.d.mts +101 -3774
- package/dist/index.d.ts +101 -3774
- package/dist/index.mjs +12 -15271
- package/dist/legacy.cjs +105 -15307
- package/dist/legacy.d.cts +115 -3763
- package/dist/legacy.d.mts +115 -3763
- package/dist/legacy.d.ts +115 -3763
- package/dist/legacy.mjs +21 -15224
- package/dist/shared/fiber.34TOMPo3.d.cts +2494 -0
- package/dist/shared/fiber.BFuGd7gN.d.cts +90 -0
- package/dist/shared/fiber.BO8-26r8.cjs +541 -0
- package/dist/shared/fiber.Bll9fqKA.d.mts +90 -0
- package/dist/shared/fiber.BwymjkeO.mjs +16564 -0
- package/dist/shared/fiber.BzEJI6VE.cjs +14 -0
- package/dist/shared/fiber.C-3TIsF8.mjs +500 -0
- package/dist/shared/fiber.C2WmwvFB.cjs +16662 -0
- package/dist/shared/fiber.C4Q4G0wZ.mjs +9 -0
- package/dist/shared/fiber.CjMAAsJy.d.ts +2494 -0
- package/dist/shared/fiber.DQTSZ24m.d.cts +1240 -0
- package/dist/shared/fiber.DQTSZ24m.d.mts +1240 -0
- package/dist/shared/fiber.DQTSZ24m.d.ts +1240 -0
- package/dist/shared/fiber.DuA4F8L5.d.ts +90 -0
- package/dist/shared/fiber.Dy7Uz273.d.mts +2494 -0
- package/dist/webgpu/index.cjs +101 -16210
- package/dist/webgpu/index.d.cts +106 -4139
- package/dist/webgpu/index.d.mts +106 -4139
- package/dist/webgpu/index.d.ts +106 -4139
- package/dist/webgpu/index.mjs +15 -16093
- package/package.json +13 -10
- package/readme.md +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Canvas = require('./fiber.C2WmwvFB.cjs');
|
|
4
|
+
const textureStaging = require('./fiber.BO8-26r8.cjs');
|
|
5
|
+
|
|
6
|
+
const useThree = textureStaging.useThree;
|
|
7
|
+
const useFrame = textureStaging.useFrame;
|
|
8
|
+
const useRenderTarget = Canvas.useRenderTarget;
|
|
9
|
+
const asWebGPUCanvas = (Canvas) => Canvas;
|
|
10
|
+
|
|
11
|
+
exports.asWebGPUCanvas = asWebGPUCanvas;
|
|
12
|
+
exports.useFrame = useFrame;
|
|
13
|
+
exports.useRenderTarget = useRenderTarget;
|
|
14
|
+
exports.useThree = useThree;
|
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useContext } from 'react';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { useFiber, useContextBridge, useActivityBridge as useActivityBridge$1, traverseFiber } from 'its-fine';
|
|
5
|
+
import { getScheduler } from '@pmndrs/scheduler';
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
10
|
+
const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React.useLayoutEffect : React.useEffect;
|
|
11
|
+
function useMutableCallback(fn) {
|
|
12
|
+
const ref = React.useRef(fn);
|
|
13
|
+
useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
|
|
14
|
+
return ref;
|
|
15
|
+
}
|
|
16
|
+
const useActivityBridge = React["Activity"] ? useActivityBridge$1 : () => React.Fragment;
|
|
17
|
+
function useBridge() {
|
|
18
|
+
const fiber = useFiber();
|
|
19
|
+
const ContextBridge = useContextBridge();
|
|
20
|
+
const ActivityBridge = useActivityBridge();
|
|
21
|
+
return React.useMemo(
|
|
22
|
+
() => ({ children }) => {
|
|
23
|
+
const strict = !!traverseFiber(fiber, true, (node) => node.type === React.StrictMode);
|
|
24
|
+
const Root = strict ? React.StrictMode : React.Fragment;
|
|
25
|
+
return /* @__PURE__ */ jsx(Root, { children: /* @__PURE__ */ jsx(ActivityBridge, { children: /* @__PURE__ */ jsx(ContextBridge, { children }) }) });
|
|
26
|
+
},
|
|
27
|
+
[fiber, ContextBridge, ActivityBridge]
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
function Block({ set }) {
|
|
31
|
+
useIsomorphicLayoutEffect(() => {
|
|
32
|
+
set(new Promise(() => null));
|
|
33
|
+
return () => set(false);
|
|
34
|
+
}, [set]);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
38
|
+
var _a;
|
|
39
|
+
return _a = class extends React.Component {
|
|
40
|
+
constructor() {
|
|
41
|
+
super(...arguments);
|
|
42
|
+
__publicField(this, "state", { error: false });
|
|
43
|
+
}
|
|
44
|
+
componentDidCatch(err) {
|
|
45
|
+
this.props.set(err);
|
|
46
|
+
}
|
|
47
|
+
render() {
|
|
48
|
+
return this.state.error ? null : this.props.children;
|
|
49
|
+
}
|
|
50
|
+
}, __publicField(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
51
|
+
})();
|
|
52
|
+
const noop = () => {
|
|
53
|
+
};
|
|
54
|
+
function Gate({ promise, onSettled }) {
|
|
55
|
+
React.use(promise);
|
|
56
|
+
useIsomorphicLayoutEffect(onSettled, [onSettled]);
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
function useGate() {
|
|
60
|
+
const [promise, setPromise] = React.useState(null);
|
|
61
|
+
const onSettled = React.useCallback(() => setPromise(null), []);
|
|
62
|
+
const waitFor = React.useCallback(
|
|
63
|
+
(next) => setPromise((current) => current ?? Promise.resolve(next).then(noop, noop)),
|
|
64
|
+
[]
|
|
65
|
+
);
|
|
66
|
+
const gate = promise ? /* @__PURE__ */ jsx(React.Suspense, { fallback: null, children: /* @__PURE__ */ jsx(Gate, { promise, onSettled }) }) : null;
|
|
67
|
+
return [gate, waitFor];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const shownNotices = /* @__PURE__ */ new Set();
|
|
71
|
+
function notifyDepreciated({ heading, body, link }) {
|
|
72
|
+
if (typeof process !== "undefined" && (process.env.NODE_ENV === "test" || process.env.JEST_WORKER_ID !== void 0) && process.env.R3F_SHOW_DEPRECATION_WARNINGS !== "true") {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (shownNotices.has(heading)) return;
|
|
76
|
+
shownNotices.add(heading);
|
|
77
|
+
const caller = getCallerFrame();
|
|
78
|
+
if (caller) {
|
|
79
|
+
console.log();
|
|
80
|
+
}
|
|
81
|
+
const boxStyle = "background: #ff9800; color: #1a1a1a; padding: 8px 12px; border-radius: 4px; font-weight: 500;";
|
|
82
|
+
if (caller) {
|
|
83
|
+
console.log(`%c\u26A0\uFE0F ${heading}`, boxStyle);
|
|
84
|
+
}
|
|
85
|
+
if (body || link) {
|
|
86
|
+
let message = "";
|
|
87
|
+
if (body) message += body;
|
|
88
|
+
if (link) message += (body ? "\n\n" : "") + `More info: ${link}`;
|
|
89
|
+
console.warn(`%c${message}`, "font-weight: bold;");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function getCallerFrame(depth = 3) {
|
|
93
|
+
const stack = new Error().stack;
|
|
94
|
+
if (!stack) return null;
|
|
95
|
+
const lines = stack.split("\n");
|
|
96
|
+
const frame = lines[depth];
|
|
97
|
+
if (!frame) return null;
|
|
98
|
+
let match = frame.match(/^\s*at (?:(.+?) )?\(?(.+?):(\d+):(\d+)\)?$/);
|
|
99
|
+
if (!match) {
|
|
100
|
+
match = frame.match(/^(?:(.+?)@)?(.+?):(\d+):(\d+)$/);
|
|
101
|
+
}
|
|
102
|
+
if (!match) return null;
|
|
103
|
+
const [, fn, url, line] = match;
|
|
104
|
+
return {
|
|
105
|
+
functionName: fn ?? "<anonymous>",
|
|
106
|
+
location: formatLocation(url, Number(line))
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function formatLocation(url, line) {
|
|
110
|
+
const clean = url.split("?")[0];
|
|
111
|
+
const file = clean.split("/").pop() ?? clean;
|
|
112
|
+
return `${file}:${line}`;
|
|
113
|
+
}
|
|
114
|
+
function notifyAlpha({ message, link }) {
|
|
115
|
+
if (typeof process !== "undefined" && (process.env.NODE_ENV === "test" || process.env.JEST_WORKER_ID !== void 0) && process.env.R3F_SHOW_ALPHA_WARNINGS !== "true") {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (shownNotices.has(message)) return;
|
|
119
|
+
shownNotices.add(message);
|
|
120
|
+
const boxStyle = "background: #6366f1; color: #ffffff; padding: 6px 10px; border-radius: 4px; font-weight: 500;";
|
|
121
|
+
console.log(`%c\u{1F52C} ${message}`, boxStyle);
|
|
122
|
+
{
|
|
123
|
+
console.log(`%cMore info: ${link}`, "color: #6366f1; font-weight: normal;");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function isDevelopment() {
|
|
127
|
+
try {
|
|
128
|
+
return process.env.NODE_ENV !== "production";
|
|
129
|
+
} catch {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const INTERNAL_LIB_MARKERS = [
|
|
135
|
+
"zustand",
|
|
136
|
+
"setState",
|
|
137
|
+
"Object.assign",
|
|
138
|
+
"@pmndrs/scheduler",
|
|
139
|
+
"Scheduler.tickRoot",
|
|
140
|
+
"Scheduler.stepJob"
|
|
141
|
+
];
|
|
142
|
+
function isInternalRendererAccess(stack, callerDepth = 2) {
|
|
143
|
+
if (!stack) return false;
|
|
144
|
+
const caller = stack.split("\n")[callerDepth] ?? "";
|
|
145
|
+
return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const isAccessorDescriptor = (descriptor) => !!descriptor && (descriptor.get !== void 0 || descriptor.set !== void 0);
|
|
149
|
+
const isAccessor = (object, key) => isAccessorDescriptor(Object.getOwnPropertyDescriptor(object, key));
|
|
150
|
+
function cloneState(...sources) {
|
|
151
|
+
const target = {};
|
|
152
|
+
for (const source of sources) {
|
|
153
|
+
if (source) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
154
|
+
}
|
|
155
|
+
return target;
|
|
156
|
+
}
|
|
157
|
+
function preserveAccessors(rawSet, get) {
|
|
158
|
+
return ((partial, replace) => {
|
|
159
|
+
const previous = get();
|
|
160
|
+
const patch = typeof partial === "function" ? partial(previous) : partial;
|
|
161
|
+
if (replace || !previous || patch == null || Object.is(patch, previous)) {
|
|
162
|
+
return rawSet(patch, replace);
|
|
163
|
+
}
|
|
164
|
+
const next = cloneState(previous);
|
|
165
|
+
const viaSetter = [];
|
|
166
|
+
for (const key of Reflect.ownKeys(patch)) {
|
|
167
|
+
const descriptor = Object.getOwnPropertyDescriptor(patch, key);
|
|
168
|
+
if (!descriptor.enumerable) continue;
|
|
169
|
+
if (isAccessorDescriptor(descriptor)) {
|
|
170
|
+
Object.defineProperty(next, key, descriptor);
|
|
171
|
+
} else if (isAccessor(next, key)) {
|
|
172
|
+
viaSetter.push(key);
|
|
173
|
+
} else {
|
|
174
|
+
Object.defineProperty(next, key, {
|
|
175
|
+
value: descriptor.value,
|
|
176
|
+
writable: true,
|
|
177
|
+
enumerable: true,
|
|
178
|
+
configurable: true
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
for (const key of viaSetter) next[key] = patch[key];
|
|
183
|
+
rawSet(next, true);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
const keepAccessors = (initializer) => (rawSet, get, api) => {
|
|
187
|
+
const set = preserveAccessors(rawSet, get);
|
|
188
|
+
api.setState = set;
|
|
189
|
+
return initializer(set, get, api);
|
|
190
|
+
};
|
|
191
|
+
let glNoticeShown = false;
|
|
192
|
+
const schedulerViews = /* @__PURE__ */ new WeakMap();
|
|
193
|
+
function stateForScheduler(state) {
|
|
194
|
+
let view = schedulerViews.get(state);
|
|
195
|
+
if (!view) {
|
|
196
|
+
view = cloneState(state);
|
|
197
|
+
Object.defineProperty(view, "gl", {
|
|
198
|
+
get() {
|
|
199
|
+
return this.internal?.actualRenderer;
|
|
200
|
+
},
|
|
201
|
+
set(value) {
|
|
202
|
+
this.internal.actualRenderer = value;
|
|
203
|
+
},
|
|
204
|
+
enumerable: true,
|
|
205
|
+
configurable: true
|
|
206
|
+
});
|
|
207
|
+
schedulerViews.set(state, view);
|
|
208
|
+
}
|
|
209
|
+
return view;
|
|
210
|
+
}
|
|
211
|
+
function defineRendererAccessors(state) {
|
|
212
|
+
Object.defineProperty(state, "gl", {
|
|
213
|
+
get() {
|
|
214
|
+
const renderer = this.internal?.actualRenderer;
|
|
215
|
+
if (!glNoticeShown && renderer && !this.isLegacy) {
|
|
216
|
+
const stack = new Error().stack || "";
|
|
217
|
+
if (!isInternalRendererAccess(stack)) {
|
|
218
|
+
glNoticeShown = true;
|
|
219
|
+
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
220
|
+
notifyDepreciated({
|
|
221
|
+
heading: "Accessing state.gl in WebGPU mode",
|
|
222
|
+
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
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return renderer;
|
|
227
|
+
},
|
|
228
|
+
set(value) {
|
|
229
|
+
this.internal.actualRenderer = value;
|
|
230
|
+
},
|
|
231
|
+
enumerable: true,
|
|
232
|
+
configurable: true
|
|
233
|
+
});
|
|
234
|
+
Object.defineProperty(state, "renderer", {
|
|
235
|
+
get() {
|
|
236
|
+
return this.internal?.actualRenderer;
|
|
237
|
+
},
|
|
238
|
+
set(value) {
|
|
239
|
+
this.internal.actualRenderer = value;
|
|
240
|
+
},
|
|
241
|
+
enumerable: true,
|
|
242
|
+
configurable: true
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
|
|
247
|
+
const context = globalThis[R3F_CONTEXT] ?? (globalThis[R3F_CONTEXT] = React.createContext(null));
|
|
248
|
+
|
|
249
|
+
const R3F_EXTENSIONS = Symbol.for("@react-three/fiber.extensions");
|
|
250
|
+
function getRegistry() {
|
|
251
|
+
return globalThis[R3F_EXTENSIONS] ?? (globalThis[R3F_EXTENSIONS] = {
|
|
252
|
+
extensions: /* @__PURE__ */ new Map(),
|
|
253
|
+
roots: /* @__PURE__ */ new Set(),
|
|
254
|
+
applied: /* @__PURE__ */ new WeakMap()
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function setupRoot(registry, store, extension) {
|
|
258
|
+
let applied = registry.applied.get(store);
|
|
259
|
+
if (!applied) registry.applied.set(store, applied = /* @__PURE__ */ new Map());
|
|
260
|
+
if (applied.has(extension.name)) return;
|
|
261
|
+
applied.set(extension.name, extension);
|
|
262
|
+
const patch = extension.setup?.(store);
|
|
263
|
+
if (patch) store.setState(patch);
|
|
264
|
+
}
|
|
265
|
+
function registerRootExtension(extension) {
|
|
266
|
+
const registry = getRegistry();
|
|
267
|
+
registry.extensions.set(extension.name, extension);
|
|
268
|
+
for (const store of registry.roots) setupRoot(registry, store, extension);
|
|
269
|
+
return () => {
|
|
270
|
+
if (registry.extensions.get(extension.name) === extension) registry.extensions.delete(extension.name);
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function setRenderOverride(store, render) {
|
|
274
|
+
store.getState().internal.renderOverride = render;
|
|
275
|
+
}
|
|
276
|
+
function attachRootExtensions(store) {
|
|
277
|
+
const registry = getRegistry();
|
|
278
|
+
registry.roots.add(store);
|
|
279
|
+
for (const extension of registry.extensions.values()) setupRoot(registry, store, extension);
|
|
280
|
+
}
|
|
281
|
+
function current(registry, setUpBy) {
|
|
282
|
+
return registry.extensions.get(setUpBy.name) ?? setUpBy;
|
|
283
|
+
}
|
|
284
|
+
function detachRootExtensions(store) {
|
|
285
|
+
const registry = getRegistry();
|
|
286
|
+
if (!registry.roots.delete(store)) return;
|
|
287
|
+
const applied = registry.applied.get(store);
|
|
288
|
+
registry.applied.delete(store);
|
|
289
|
+
if (!applied) return;
|
|
290
|
+
for (const setUpBy of applied.values()) current(registry, setUpBy).dispose?.(store);
|
|
291
|
+
}
|
|
292
|
+
function notifyRootExtensionsHmr(store) {
|
|
293
|
+
const registry = getRegistry();
|
|
294
|
+
const applied = registry.applied.get(store);
|
|
295
|
+
if (!applied) return;
|
|
296
|
+
for (const setUpBy of applied.values()) current(registry, setUpBy).hmr?.(store);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function useStore() {
|
|
300
|
+
const store = useContext(context);
|
|
301
|
+
if (!store) throw new Error("R3F: Hooks can only be used within the Canvas component!");
|
|
302
|
+
return store;
|
|
303
|
+
}
|
|
304
|
+
function useThree(selector = (state) => state, equalityFn) {
|
|
305
|
+
return useStore()(selector, equalityFn);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function useFrame(callback, priorityOrOptions) {
|
|
309
|
+
const store = React.useContext(context);
|
|
310
|
+
const isInsideCanvas = store !== null;
|
|
311
|
+
const scheduler = getScheduler();
|
|
312
|
+
const optionsKey = typeof priorityOrOptions === "number" ? `p:${priorityOrOptions}` : priorityOrOptions ? JSON.stringify({
|
|
313
|
+
id: priorityOrOptions.id,
|
|
314
|
+
phase: priorityOrOptions.phase,
|
|
315
|
+
priority: priorityOrOptions.priority,
|
|
316
|
+
fps: priorityOrOptions.fps,
|
|
317
|
+
drop: priorityOrOptions.drop,
|
|
318
|
+
enabled: priorityOrOptions.enabled,
|
|
319
|
+
before: priorityOrOptions.before,
|
|
320
|
+
after: priorityOrOptions.after
|
|
321
|
+
}) : "";
|
|
322
|
+
const options = React.useMemo(() => {
|
|
323
|
+
return typeof priorityOrOptions === "number" ? { priority: priorityOrOptions } : priorityOrOptions ?? {};
|
|
324
|
+
}, [optionsKey]);
|
|
325
|
+
const [generatedId] = React.useState(() => scheduler.generateJobId());
|
|
326
|
+
const id = options.id ?? generatedId;
|
|
327
|
+
const callbackRef = useMutableCallback(callback);
|
|
328
|
+
const isLegacyPriority = typeof priorityOrOptions === "number" && priorityOrOptions > 0;
|
|
329
|
+
const isLegacyOrdering = typeof priorityOrOptions === "number" && priorityOrOptions < 0;
|
|
330
|
+
useIsomorphicLayoutEffect(() => {
|
|
331
|
+
if (!callback) return;
|
|
332
|
+
if (isLegacyOrdering) {
|
|
333
|
+
notifyDepreciated({
|
|
334
|
+
heading: "useFrame numeric priority order is reversed in v10",
|
|
335
|
+
body: "useFrame(callback, number) is deprecated and its ordering direction is reversed from v9: v9 ran lower numbers first, v10 maps the number to { priority } and runs higher numbers first, so a negative priority now runs after default-priority jobs.\n\nUse { before, after } to name the dependency, or { priority } with the v10 direction (higher = earlier).",
|
|
336
|
+
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
if (isInsideCanvas) {
|
|
340
|
+
const state = store.getState();
|
|
341
|
+
const rootId = state.internal.rootId;
|
|
342
|
+
if (isLegacyPriority) {
|
|
343
|
+
state.internal.priority++;
|
|
344
|
+
let parentRoot = state.previousRoot;
|
|
345
|
+
while (parentRoot) {
|
|
346
|
+
const parentState = parentRoot.getState();
|
|
347
|
+
if (parentState?.internal) parentState.internal.priority++;
|
|
348
|
+
parentRoot = parentState?.previousRoot;
|
|
349
|
+
}
|
|
350
|
+
notifyDepreciated({
|
|
351
|
+
heading: "useFrame with numeric priority is deprecated",
|
|
352
|
+
body: 'Using useFrame(callback, number) to control render order is deprecated.\n\nFor custom rendering, use: useFrame(callback, { phase: "render" })\nFor execution order within a phase, use: useFrame(callback, { priority: number }) \u2014 higher runs first, the reverse of v9',
|
|
353
|
+
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
const wrappedCallback = (frameState, delta) => {
|
|
357
|
+
const mergedState = cloneState(store.getState());
|
|
358
|
+
mergedState.time = frameState.time;
|
|
359
|
+
mergedState.delta = frameState.delta;
|
|
360
|
+
mergedState.elapsed = frameState.elapsed;
|
|
361
|
+
mergedState.frame = frameState.frame;
|
|
362
|
+
mergedState.overstep = frameState.overstep;
|
|
363
|
+
callbackRef.current?.(mergedState, delta);
|
|
364
|
+
};
|
|
365
|
+
const unregister = scheduler.register(wrappedCallback, {
|
|
366
|
+
id,
|
|
367
|
+
rootId,
|
|
368
|
+
...options
|
|
369
|
+
});
|
|
370
|
+
return () => {
|
|
371
|
+
unregister();
|
|
372
|
+
if (isLegacyPriority) {
|
|
373
|
+
const currentState = store.getState();
|
|
374
|
+
if (currentState.internal) {
|
|
375
|
+
currentState.internal.priority--;
|
|
376
|
+
let parentRoot = currentState.previousRoot;
|
|
377
|
+
while (parentRoot) {
|
|
378
|
+
const parentState = parentRoot.getState();
|
|
379
|
+
if (parentState?.internal) parentState.internal.priority--;
|
|
380
|
+
parentRoot = parentState?.previousRoot;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
} else {
|
|
386
|
+
return scheduler.register(
|
|
387
|
+
(state, delta) => {
|
|
388
|
+
const frameState = state;
|
|
389
|
+
if (!frameState.renderer) return;
|
|
390
|
+
callbackRef.current?.(frameState, delta);
|
|
391
|
+
},
|
|
392
|
+
{ id, ...options }
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
}, [store, scheduler, id, optionsKey, isLegacyPriority, isLegacyOrdering, isInsideCanvas]);
|
|
396
|
+
const isPaused = React.useSyncExternalStore(
|
|
397
|
+
// Subscribe function
|
|
398
|
+
React.useCallback(
|
|
399
|
+
(onStoreChange) => {
|
|
400
|
+
return getScheduler().subscribeJobState(id, onStoreChange);
|
|
401
|
+
},
|
|
402
|
+
[id]
|
|
403
|
+
),
|
|
404
|
+
// getSnapshot function
|
|
405
|
+
React.useCallback(() => getScheduler().isJobPaused(id), [id]),
|
|
406
|
+
// getServerSnapshot function (SSR)
|
|
407
|
+
React.useCallback(() => false, [])
|
|
408
|
+
);
|
|
409
|
+
const controls = React.useMemo(() => {
|
|
410
|
+
const scheduler2 = getScheduler();
|
|
411
|
+
return {
|
|
412
|
+
/** The job's unique ID */
|
|
413
|
+
id,
|
|
414
|
+
/**
|
|
415
|
+
* Access to the global scheduler for frame loop control.
|
|
416
|
+
* Use for controlling the entire frame loop, adding phases, etc.
|
|
417
|
+
*/
|
|
418
|
+
scheduler: scheduler2,
|
|
419
|
+
/**
|
|
420
|
+
* The root that currently owns this job. Resolve on access because ambient
|
|
421
|
+
* jobs can be adopted by a Canvas after the controls object is created.
|
|
422
|
+
*/
|
|
423
|
+
get rootId() {
|
|
424
|
+
return getScheduler().getJobRootId(id);
|
|
425
|
+
},
|
|
426
|
+
/**
|
|
427
|
+
* Manually step this job only.
|
|
428
|
+
* Bypasses FPS limiting - always runs.
|
|
429
|
+
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
430
|
+
*/
|
|
431
|
+
step: (timestamp) => {
|
|
432
|
+
getScheduler().stepJob(id, timestamp);
|
|
433
|
+
},
|
|
434
|
+
/**
|
|
435
|
+
* Manually step ALL jobs in the scheduler.
|
|
436
|
+
* Useful for frameloop='never' mode.
|
|
437
|
+
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
438
|
+
*/
|
|
439
|
+
stepAll: (timestamp) => {
|
|
440
|
+
getScheduler().step(timestamp);
|
|
441
|
+
},
|
|
442
|
+
/**
|
|
443
|
+
* Request frames for this job's owning root without waking sibling roots.
|
|
444
|
+
*/
|
|
445
|
+
invalidate: (frames, stackFrames) => {
|
|
446
|
+
const scheduler3 = getScheduler();
|
|
447
|
+
const rootId = scheduler3.getJobRootId(id);
|
|
448
|
+
if (rootId) scheduler3.invalidateRoot(rootId, frames, stackFrames);
|
|
449
|
+
},
|
|
450
|
+
/**
|
|
451
|
+
* Pause this job (set enabled=false).
|
|
452
|
+
* Job remains registered but won't run.
|
|
453
|
+
*/
|
|
454
|
+
pause: () => {
|
|
455
|
+
getScheduler().pauseJob(id);
|
|
456
|
+
},
|
|
457
|
+
/**
|
|
458
|
+
* Resume this job (set enabled=true).
|
|
459
|
+
*/
|
|
460
|
+
resume: () => {
|
|
461
|
+
getScheduler().resumeJob(id);
|
|
462
|
+
},
|
|
463
|
+
/**
|
|
464
|
+
* Reactive paused state - automatically updates when pause/resume is called.
|
|
465
|
+
* No need for forceUpdate() in your components.
|
|
466
|
+
*/
|
|
467
|
+
isPaused
|
|
468
|
+
};
|
|
469
|
+
}, [id, isPaused]);
|
|
470
|
+
return controls;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const R3F_STAGED_TEXTURES = Symbol.for("@react-three/fiber.stagedTextures");
|
|
474
|
+
const globalStaging = globalThis;
|
|
475
|
+
const staging = globalStaging[R3F_STAGED_TEXTURES] ?? (globalStaging[R3F_STAGED_TEXTURES] = /* @__PURE__ */ new WeakMap());
|
|
476
|
+
function stageTextures(store, entries) {
|
|
477
|
+
const registered = store.getState().textures;
|
|
478
|
+
let staged = staging.get(store);
|
|
479
|
+
for (const [url, texture] of entries) {
|
|
480
|
+
if (registered.has(url)) continue;
|
|
481
|
+
if (!staged) staging.set(store, staged = /* @__PURE__ */ new Map());
|
|
482
|
+
staged.set(url, texture);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
function unstageTextures(store, urls) {
|
|
486
|
+
const staged = staging.get(store);
|
|
487
|
+
if (!staged) return;
|
|
488
|
+
for (const url of urls) staged.delete(url);
|
|
489
|
+
if (staged.size === 0) staging.delete(store);
|
|
490
|
+
}
|
|
491
|
+
function getTextureView(store) {
|
|
492
|
+
const registered = store.getState().textures;
|
|
493
|
+
const staged = staging.get(store);
|
|
494
|
+
if (!staged) return registered;
|
|
495
|
+
const view = new Map(registered);
|
|
496
|
+
for (const [url, texture] of staged) if (!view.has(url)) view.set(url, texture);
|
|
497
|
+
return view;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
export { Block as B, ErrorBoundary as E, useThree as a, useFrame as b, context as c, useIsomorphicLayoutEffect as d, useMutableCallback as e, useBridge as f, getTextureView as g, defineRendererAccessors as h, isDevelopment as i, stateForScheduler as j, detachRootExtensions as k, attachRootExtensions as l, unstageTextures as m, notifyDepreciated as n, stageTextures as o, preserveAccessors as p, isAccessor as q, registerRootExtension as r, setRenderOverride as s, cloneState as t, useStore as u, keepAccessors as v, useGate as w, notifyAlpha as x, notifyRootExtensionsHmr as y };
|