@react-three/fiber 10.0.0-alpha.4 → 10.0.0-alpha.6
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.BSXtODQl.cjs +14 -0
- package/dist/shared/fiber.Bll9fqKA.d.mts +90 -0
- package/dist/shared/fiber.BuWl08aJ.mjs +16564 -0
- package/dist/shared/fiber.C-3TIsF8.mjs +500 -0
- package/dist/shared/fiber.CjMAAsJy.d.ts +2494 -0
- package/dist/shared/fiber.DEWBFQJe.mjs +9 -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/shared/fiber.TRm3lZ7I.cjs +16662 -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 +11 -2
|
@@ -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.cjs';
|
|
4
|
+
import { R as RenderTargetOptions, aU as CanvasProps } from './fiber.34TOMPo3.cjs';
|
|
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 };
|
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const React = require('react');
|
|
4
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
const itsFine = require('its-fine');
|
|
6
|
+
const scheduler = require('@pmndrs/scheduler');
|
|
7
|
+
|
|
8
|
+
function _interopNamespaceCompat(e) {
|
|
9
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
10
|
+
const n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
for (const k in e) {
|
|
13
|
+
n[k] = e[k];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
n.default = e;
|
|
17
|
+
return n;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const React__namespace = /*#__PURE__*/_interopNamespaceCompat(React);
|
|
21
|
+
|
|
22
|
+
var __defProp = Object.defineProperty;
|
|
23
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
24
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
25
|
+
const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
26
|
+
function useMutableCallback(fn) {
|
|
27
|
+
const ref = React__namespace.useRef(fn);
|
|
28
|
+
useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
|
|
29
|
+
return ref;
|
|
30
|
+
}
|
|
31
|
+
const useActivityBridge = React__namespace["Activity"] ? itsFine.useActivityBridge : () => React__namespace.Fragment;
|
|
32
|
+
function useBridge() {
|
|
33
|
+
const fiber = itsFine.useFiber();
|
|
34
|
+
const ContextBridge = itsFine.useContextBridge();
|
|
35
|
+
const ActivityBridge = useActivityBridge();
|
|
36
|
+
return React__namespace.useMemo(
|
|
37
|
+
() => ({ children }) => {
|
|
38
|
+
const strict = !!itsFine.traverseFiber(fiber, true, (node) => node.type === React__namespace.StrictMode);
|
|
39
|
+
const Root = strict ? React__namespace.StrictMode : React__namespace.Fragment;
|
|
40
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Root, { children: /* @__PURE__ */ jsxRuntime.jsx(ActivityBridge, { children: /* @__PURE__ */ jsxRuntime.jsx(ContextBridge, { children }) }) });
|
|
41
|
+
},
|
|
42
|
+
[fiber, ContextBridge, ActivityBridge]
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
function Block({ set }) {
|
|
46
|
+
useIsomorphicLayoutEffect(() => {
|
|
47
|
+
set(new Promise(() => null));
|
|
48
|
+
return () => set(false);
|
|
49
|
+
}, [set]);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
53
|
+
var _a;
|
|
54
|
+
return _a = class extends React__namespace.Component {
|
|
55
|
+
constructor() {
|
|
56
|
+
super(...arguments);
|
|
57
|
+
__publicField(this, "state", { error: false });
|
|
58
|
+
}
|
|
59
|
+
componentDidCatch(err) {
|
|
60
|
+
this.props.set(err);
|
|
61
|
+
}
|
|
62
|
+
render() {
|
|
63
|
+
return this.state.error ? null : this.props.children;
|
|
64
|
+
}
|
|
65
|
+
}, __publicField(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
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
|
+
}
|
|
84
|
+
|
|
85
|
+
const shownNotices = /* @__PURE__ */ new Set();
|
|
86
|
+
function notifyDepreciated({ heading, body, link }) {
|
|
87
|
+
if (typeof process !== "undefined" && (process.env.NODE_ENV === "test" || process.env.JEST_WORKER_ID !== void 0) && process.env.R3F_SHOW_DEPRECATION_WARNINGS !== "true") {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (shownNotices.has(heading)) return;
|
|
91
|
+
shownNotices.add(heading);
|
|
92
|
+
const caller = getCallerFrame();
|
|
93
|
+
if (caller) {
|
|
94
|
+
console.log();
|
|
95
|
+
}
|
|
96
|
+
const boxStyle = "background: #ff9800; color: #1a1a1a; padding: 8px 12px; border-radius: 4px; font-weight: 500;";
|
|
97
|
+
if (caller) {
|
|
98
|
+
console.log(`%c\u26A0\uFE0F ${heading}`, boxStyle);
|
|
99
|
+
}
|
|
100
|
+
if (body || link) {
|
|
101
|
+
let message = "";
|
|
102
|
+
if (body) message += body;
|
|
103
|
+
if (link) message += (body ? "\n\n" : "") + `More info: ${link}`;
|
|
104
|
+
console.warn(`%c${message}`, "font-weight: bold;");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function getCallerFrame(depth = 3) {
|
|
108
|
+
const stack = new Error().stack;
|
|
109
|
+
if (!stack) return null;
|
|
110
|
+
const lines = stack.split("\n");
|
|
111
|
+
const frame = lines[depth];
|
|
112
|
+
if (!frame) return null;
|
|
113
|
+
let match = frame.match(/^\s*at (?:(.+?) )?\(?(.+?):(\d+):(\d+)\)?$/);
|
|
114
|
+
if (!match) {
|
|
115
|
+
match = frame.match(/^(?:(.+?)@)?(.+?):(\d+):(\d+)$/);
|
|
116
|
+
}
|
|
117
|
+
if (!match) return null;
|
|
118
|
+
const [, fn, url, line] = match;
|
|
119
|
+
return {
|
|
120
|
+
functionName: fn ?? "<anonymous>",
|
|
121
|
+
location: formatLocation(url, Number(line))
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function formatLocation(url, line) {
|
|
125
|
+
const clean = url.split("?")[0];
|
|
126
|
+
const file = clean.split("/").pop() ?? clean;
|
|
127
|
+
return `${file}:${line}`;
|
|
128
|
+
}
|
|
129
|
+
function notifyAlpha({ message, link }) {
|
|
130
|
+
if (typeof process !== "undefined" && (process.env.NODE_ENV === "test" || process.env.JEST_WORKER_ID !== void 0) && process.env.R3F_SHOW_ALPHA_WARNINGS !== "true") {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (shownNotices.has(message)) return;
|
|
134
|
+
shownNotices.add(message);
|
|
135
|
+
const boxStyle = "background: #6366f1; color: #ffffff; padding: 6px 10px; border-radius: 4px; font-weight: 500;";
|
|
136
|
+
console.log(`%c\u{1F52C} ${message}`, boxStyle);
|
|
137
|
+
{
|
|
138
|
+
console.log(`%cMore info: ${link}`, "color: #6366f1; font-weight: normal;");
|
|
139
|
+
}
|
|
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
|
+
const schedulerViews = /* @__PURE__ */ new WeakMap();
|
|
208
|
+
function stateForScheduler(state) {
|
|
209
|
+
let view = schedulerViews.get(state);
|
|
210
|
+
if (!view) {
|
|
211
|
+
view = cloneState(state);
|
|
212
|
+
Object.defineProperty(view, "gl", {
|
|
213
|
+
get() {
|
|
214
|
+
return this.internal?.actualRenderer;
|
|
215
|
+
},
|
|
216
|
+
set(value) {
|
|
217
|
+
this.internal.actualRenderer = value;
|
|
218
|
+
},
|
|
219
|
+
enumerable: true,
|
|
220
|
+
configurable: true
|
|
221
|
+
});
|
|
222
|
+
schedulerViews.set(state, view);
|
|
223
|
+
}
|
|
224
|
+
return view;
|
|
225
|
+
}
|
|
226
|
+
function defineRendererAccessors(state) {
|
|
227
|
+
Object.defineProperty(state, "gl", {
|
|
228
|
+
get() {
|
|
229
|
+
const renderer = this.internal?.actualRenderer;
|
|
230
|
+
if (!glNoticeShown && renderer && !this.isLegacy) {
|
|
231
|
+
const stack = new Error().stack || "";
|
|
232
|
+
if (!isInternalRendererAccess(stack)) {
|
|
233
|
+
glNoticeShown = true;
|
|
234
|
+
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
235
|
+
notifyDepreciated({
|
|
236
|
+
heading: "Accessing state.gl in WebGPU mode",
|
|
237
|
+
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
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return renderer;
|
|
242
|
+
},
|
|
243
|
+
set(value) {
|
|
244
|
+
this.internal.actualRenderer = value;
|
|
245
|
+
},
|
|
246
|
+
enumerable: true,
|
|
247
|
+
configurable: true
|
|
248
|
+
});
|
|
249
|
+
Object.defineProperty(state, "renderer", {
|
|
250
|
+
get() {
|
|
251
|
+
return this.internal?.actualRenderer;
|
|
252
|
+
},
|
|
253
|
+
set(value) {
|
|
254
|
+
this.internal.actualRenderer = value;
|
|
255
|
+
},
|
|
256
|
+
enumerable: true,
|
|
257
|
+
configurable: true
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
|
|
262
|
+
const context = globalThis[R3F_CONTEXT] ?? (globalThis[R3F_CONTEXT] = React__namespace.createContext(null));
|
|
263
|
+
|
|
264
|
+
const R3F_EXTENSIONS = Symbol.for("@react-three/fiber.extensions");
|
|
265
|
+
function getRegistry() {
|
|
266
|
+
return globalThis[R3F_EXTENSIONS] ?? (globalThis[R3F_EXTENSIONS] = {
|
|
267
|
+
extensions: /* @__PURE__ */ new Map(),
|
|
268
|
+
roots: /* @__PURE__ */ new Set(),
|
|
269
|
+
applied: /* @__PURE__ */ new WeakMap()
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
function setupRoot(registry, store, extension) {
|
|
273
|
+
let applied = registry.applied.get(store);
|
|
274
|
+
if (!applied) registry.applied.set(store, applied = /* @__PURE__ */ new Map());
|
|
275
|
+
if (applied.has(extension.name)) return;
|
|
276
|
+
applied.set(extension.name, extension);
|
|
277
|
+
const patch = extension.setup?.(store);
|
|
278
|
+
if (patch) store.setState(patch);
|
|
279
|
+
}
|
|
280
|
+
function registerRootExtension(extension) {
|
|
281
|
+
const registry = getRegistry();
|
|
282
|
+
registry.extensions.set(extension.name, extension);
|
|
283
|
+
for (const store of registry.roots) setupRoot(registry, store, extension);
|
|
284
|
+
return () => {
|
|
285
|
+
if (registry.extensions.get(extension.name) === extension) registry.extensions.delete(extension.name);
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
function setRenderOverride(store, render) {
|
|
289
|
+
store.getState().internal.renderOverride = render;
|
|
290
|
+
}
|
|
291
|
+
function attachRootExtensions(store) {
|
|
292
|
+
const registry = getRegistry();
|
|
293
|
+
registry.roots.add(store);
|
|
294
|
+
for (const extension of registry.extensions.values()) setupRoot(registry, store, extension);
|
|
295
|
+
}
|
|
296
|
+
function current(registry, setUpBy) {
|
|
297
|
+
return registry.extensions.get(setUpBy.name) ?? setUpBy;
|
|
298
|
+
}
|
|
299
|
+
function detachRootExtensions(store) {
|
|
300
|
+
const registry = getRegistry();
|
|
301
|
+
if (!registry.roots.delete(store)) return;
|
|
302
|
+
const applied = registry.applied.get(store);
|
|
303
|
+
registry.applied.delete(store);
|
|
304
|
+
if (!applied) return;
|
|
305
|
+
for (const setUpBy of applied.values()) current(registry, setUpBy).dispose?.(store);
|
|
306
|
+
}
|
|
307
|
+
function notifyRootExtensionsHmr(store) {
|
|
308
|
+
const registry = getRegistry();
|
|
309
|
+
const applied = registry.applied.get(store);
|
|
310
|
+
if (!applied) return;
|
|
311
|
+
for (const setUpBy of applied.values()) current(registry, setUpBy).hmr?.(store);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function useStore() {
|
|
315
|
+
const store = React.useContext(context);
|
|
316
|
+
if (!store) throw new Error("R3F: Hooks can only be used within the Canvas component!");
|
|
317
|
+
return store;
|
|
318
|
+
}
|
|
319
|
+
function useThree(selector = (state) => state, equalityFn) {
|
|
320
|
+
return useStore()(selector, equalityFn);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function useFrame(callback, priorityOrOptions) {
|
|
324
|
+
const store = React__namespace.useContext(context);
|
|
325
|
+
const isInsideCanvas = store !== null;
|
|
326
|
+
const scheduler$1 = scheduler.getScheduler();
|
|
327
|
+
const optionsKey = typeof priorityOrOptions === "number" ? `p:${priorityOrOptions}` : priorityOrOptions ? JSON.stringify({
|
|
328
|
+
id: priorityOrOptions.id,
|
|
329
|
+
phase: priorityOrOptions.phase,
|
|
330
|
+
priority: priorityOrOptions.priority,
|
|
331
|
+
fps: priorityOrOptions.fps,
|
|
332
|
+
drop: priorityOrOptions.drop,
|
|
333
|
+
enabled: priorityOrOptions.enabled,
|
|
334
|
+
before: priorityOrOptions.before,
|
|
335
|
+
after: priorityOrOptions.after
|
|
336
|
+
}) : "";
|
|
337
|
+
const options = React__namespace.useMemo(() => {
|
|
338
|
+
return typeof priorityOrOptions === "number" ? { priority: priorityOrOptions } : priorityOrOptions ?? {};
|
|
339
|
+
}, [optionsKey]);
|
|
340
|
+
const [generatedId] = React__namespace.useState(() => scheduler$1.generateJobId());
|
|
341
|
+
const id = options.id ?? generatedId;
|
|
342
|
+
const callbackRef = useMutableCallback(callback);
|
|
343
|
+
const isLegacyPriority = typeof priorityOrOptions === "number" && priorityOrOptions > 0;
|
|
344
|
+
const isLegacyOrdering = typeof priorityOrOptions === "number" && priorityOrOptions < 0;
|
|
345
|
+
useIsomorphicLayoutEffect(() => {
|
|
346
|
+
if (!callback) return;
|
|
347
|
+
if (isLegacyOrdering) {
|
|
348
|
+
notifyDepreciated({
|
|
349
|
+
heading: "useFrame numeric priority order is reversed in v10",
|
|
350
|
+
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).",
|
|
351
|
+
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
if (isInsideCanvas) {
|
|
355
|
+
const state = store.getState();
|
|
356
|
+
const rootId = state.internal.rootId;
|
|
357
|
+
if (isLegacyPriority) {
|
|
358
|
+
state.internal.priority++;
|
|
359
|
+
let parentRoot = state.previousRoot;
|
|
360
|
+
while (parentRoot) {
|
|
361
|
+
const parentState = parentRoot.getState();
|
|
362
|
+
if (parentState?.internal) parentState.internal.priority++;
|
|
363
|
+
parentRoot = parentState?.previousRoot;
|
|
364
|
+
}
|
|
365
|
+
notifyDepreciated({
|
|
366
|
+
heading: "useFrame with numeric priority is deprecated",
|
|
367
|
+
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',
|
|
368
|
+
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
const wrappedCallback = (frameState, delta) => {
|
|
372
|
+
const mergedState = cloneState(store.getState());
|
|
373
|
+
mergedState.time = frameState.time;
|
|
374
|
+
mergedState.delta = frameState.delta;
|
|
375
|
+
mergedState.elapsed = frameState.elapsed;
|
|
376
|
+
mergedState.frame = frameState.frame;
|
|
377
|
+
mergedState.overstep = frameState.overstep;
|
|
378
|
+
callbackRef.current?.(mergedState, delta);
|
|
379
|
+
};
|
|
380
|
+
const unregister = scheduler$1.register(wrappedCallback, {
|
|
381
|
+
id,
|
|
382
|
+
rootId,
|
|
383
|
+
...options
|
|
384
|
+
});
|
|
385
|
+
return () => {
|
|
386
|
+
unregister();
|
|
387
|
+
if (isLegacyPriority) {
|
|
388
|
+
const currentState = store.getState();
|
|
389
|
+
if (currentState.internal) {
|
|
390
|
+
currentState.internal.priority--;
|
|
391
|
+
let parentRoot = currentState.previousRoot;
|
|
392
|
+
while (parentRoot) {
|
|
393
|
+
const parentState = parentRoot.getState();
|
|
394
|
+
if (parentState?.internal) parentState.internal.priority--;
|
|
395
|
+
parentRoot = parentState?.previousRoot;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
} else {
|
|
401
|
+
return scheduler$1.register(
|
|
402
|
+
(state, delta) => {
|
|
403
|
+
const frameState = state;
|
|
404
|
+
if (!frameState.renderer) return;
|
|
405
|
+
callbackRef.current?.(frameState, delta);
|
|
406
|
+
},
|
|
407
|
+
{ id, ...options }
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
}, [store, scheduler$1, id, optionsKey, isLegacyPriority, isLegacyOrdering, isInsideCanvas]);
|
|
411
|
+
const isPaused = React__namespace.useSyncExternalStore(
|
|
412
|
+
// Subscribe function
|
|
413
|
+
React__namespace.useCallback(
|
|
414
|
+
(onStoreChange) => {
|
|
415
|
+
return scheduler.getScheduler().subscribeJobState(id, onStoreChange);
|
|
416
|
+
},
|
|
417
|
+
[id]
|
|
418
|
+
),
|
|
419
|
+
// getSnapshot function
|
|
420
|
+
React__namespace.useCallback(() => scheduler.getScheduler().isJobPaused(id), [id]),
|
|
421
|
+
// getServerSnapshot function (SSR)
|
|
422
|
+
React__namespace.useCallback(() => false, [])
|
|
423
|
+
);
|
|
424
|
+
const controls = React__namespace.useMemo(() => {
|
|
425
|
+
const scheduler2 = scheduler.getScheduler();
|
|
426
|
+
return {
|
|
427
|
+
/** The job's unique ID */
|
|
428
|
+
id,
|
|
429
|
+
/**
|
|
430
|
+
* Access to the global scheduler for frame loop control.
|
|
431
|
+
* Use for controlling the entire frame loop, adding phases, etc.
|
|
432
|
+
*/
|
|
433
|
+
scheduler: scheduler2,
|
|
434
|
+
/**
|
|
435
|
+
* The root that currently owns this job. Resolve on access because ambient
|
|
436
|
+
* jobs can be adopted by a Canvas after the controls object is created.
|
|
437
|
+
*/
|
|
438
|
+
get rootId() {
|
|
439
|
+
return scheduler.getScheduler().getJobRootId(id);
|
|
440
|
+
},
|
|
441
|
+
/**
|
|
442
|
+
* Manually step this job only.
|
|
443
|
+
* Bypasses FPS limiting - always runs.
|
|
444
|
+
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
445
|
+
*/
|
|
446
|
+
step: (timestamp) => {
|
|
447
|
+
scheduler.getScheduler().stepJob(id, timestamp);
|
|
448
|
+
},
|
|
449
|
+
/**
|
|
450
|
+
* Manually step ALL jobs in the scheduler.
|
|
451
|
+
* Useful for frameloop='never' mode.
|
|
452
|
+
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
453
|
+
*/
|
|
454
|
+
stepAll: (timestamp) => {
|
|
455
|
+
scheduler.getScheduler().step(timestamp);
|
|
456
|
+
},
|
|
457
|
+
/**
|
|
458
|
+
* Request frames for this job's owning root without waking sibling roots.
|
|
459
|
+
*/
|
|
460
|
+
invalidate: (frames, stackFrames) => {
|
|
461
|
+
const scheduler3 = scheduler.getScheduler();
|
|
462
|
+
const rootId = scheduler3.getJobRootId(id);
|
|
463
|
+
if (rootId) scheduler3.invalidateRoot(rootId, frames, stackFrames);
|
|
464
|
+
},
|
|
465
|
+
/**
|
|
466
|
+
* Pause this job (set enabled=false).
|
|
467
|
+
* Job remains registered but won't run.
|
|
468
|
+
*/
|
|
469
|
+
pause: () => {
|
|
470
|
+
scheduler.getScheduler().pauseJob(id);
|
|
471
|
+
},
|
|
472
|
+
/**
|
|
473
|
+
* Resume this job (set enabled=true).
|
|
474
|
+
*/
|
|
475
|
+
resume: () => {
|
|
476
|
+
scheduler.getScheduler().resumeJob(id);
|
|
477
|
+
},
|
|
478
|
+
/**
|
|
479
|
+
* Reactive paused state - automatically updates when pause/resume is called.
|
|
480
|
+
* No need for forceUpdate() in your components.
|
|
481
|
+
*/
|
|
482
|
+
isPaused
|
|
483
|
+
};
|
|
484
|
+
}, [id, isPaused]);
|
|
485
|
+
return controls;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const R3F_STAGED_TEXTURES = Symbol.for("@react-three/fiber.stagedTextures");
|
|
489
|
+
const globalStaging = globalThis;
|
|
490
|
+
const staging = globalStaging[R3F_STAGED_TEXTURES] ?? (globalStaging[R3F_STAGED_TEXTURES] = /* @__PURE__ */ new WeakMap());
|
|
491
|
+
function stageTextures(store, entries) {
|
|
492
|
+
const registered = store.getState().textures;
|
|
493
|
+
let staged = staging.get(store);
|
|
494
|
+
for (const [url, texture] of entries) {
|
|
495
|
+
if (registered.has(url)) continue;
|
|
496
|
+
if (!staged) staging.set(store, staged = /* @__PURE__ */ new Map());
|
|
497
|
+
staged.set(url, texture);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
function unstageTextures(store, urls) {
|
|
501
|
+
const staged = staging.get(store);
|
|
502
|
+
if (!staged) return;
|
|
503
|
+
for (const url of urls) staged.delete(url);
|
|
504
|
+
if (staged.size === 0) staging.delete(store);
|
|
505
|
+
}
|
|
506
|
+
function getTextureView(store) {
|
|
507
|
+
const registered = store.getState().textures;
|
|
508
|
+
const staged = staging.get(store);
|
|
509
|
+
if (!staged) return registered;
|
|
510
|
+
const view = new Map(registered);
|
|
511
|
+
for (const [url, texture] of staged) if (!view.has(url)) view.set(url, texture);
|
|
512
|
+
return view;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
exports.Block = Block;
|
|
516
|
+
exports.ErrorBoundary = ErrorBoundary;
|
|
517
|
+
exports.attachRootExtensions = attachRootExtensions;
|
|
518
|
+
exports.cloneState = cloneState;
|
|
519
|
+
exports.context = context;
|
|
520
|
+
exports.defineRendererAccessors = defineRendererAccessors;
|
|
521
|
+
exports.detachRootExtensions = detachRootExtensions;
|
|
522
|
+
exports.getTextureView = getTextureView;
|
|
523
|
+
exports.isAccessor = isAccessor;
|
|
524
|
+
exports.isDevelopment = isDevelopment;
|
|
525
|
+
exports.keepAccessors = keepAccessors;
|
|
526
|
+
exports.notifyAlpha = notifyAlpha;
|
|
527
|
+
exports.notifyDepreciated = notifyDepreciated;
|
|
528
|
+
exports.notifyRootExtensionsHmr = notifyRootExtensionsHmr;
|
|
529
|
+
exports.preserveAccessors = preserveAccessors;
|
|
530
|
+
exports.registerRootExtension = registerRootExtension;
|
|
531
|
+
exports.setRenderOverride = setRenderOverride;
|
|
532
|
+
exports.stageTextures = stageTextures;
|
|
533
|
+
exports.stateForScheduler = stateForScheduler;
|
|
534
|
+
exports.unstageTextures = unstageTextures;
|
|
535
|
+
exports.useBridge = useBridge;
|
|
536
|
+
exports.useFrame = useFrame;
|
|
537
|
+
exports.useGate = useGate;
|
|
538
|
+
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
|
|
539
|
+
exports.useMutableCallback = useMutableCallback;
|
|
540
|
+
exports.useStore = useStore;
|
|
541
|
+
exports.useThree = useThree;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Canvas = require('./fiber.TRm3lZ7I.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;
|