@react-three/fiber 10.0.0-canary.dc0ec15 → 10.0.0-canary.de17310
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.d.cts +49 -1095
- package/dist/extension.d.mts +49 -1095
- package/dist/extension.d.ts +49 -1067
- package/dist/index.cjs +2 -8
- package/dist/index.d.cts +8 -342
- package/dist/index.d.mts +8 -342
- package/dist/index.d.ts +7 -341
- package/dist/index.mjs +2 -8
- package/dist/legacy.cjs +2 -8
- package/dist/legacy.d.cts +6 -341
- package/dist/legacy.d.mts +6 -341
- package/dist/legacy.d.ts +6 -341
- package/dist/legacy.mjs +2 -8
- package/dist/webgpu/index.cjs +9 -939
- package/dist/webgpu/index.d.cts +12 -685
- package/dist/webgpu/index.d.mts +12 -685
- package/dist/webgpu/index.d.ts +11 -684
- package/dist/webgpu/index.mjs +11 -923
- package/package.json +1 -1
package/dist/webgpu/index.cjs
CHANGED
|
@@ -15,9 +15,6 @@ const EXRLoader_js = require('three/examples/jsm/loaders/EXRLoader.js');
|
|
|
15
15
|
const UltraHDRLoader_js = require('three/examples/jsm/loaders/UltraHDRLoader.js');
|
|
16
16
|
const gainmapJs = require('@monogrid/gainmap-js');
|
|
17
17
|
const suspendReact = require('suspend-react');
|
|
18
|
-
const lite = require('dequal/lite');
|
|
19
|
-
require('zustand/shallow');
|
|
20
|
-
const tsl = require('three/tsl');
|
|
21
18
|
|
|
22
19
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
23
20
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
@@ -138,9 +135,9 @@ function getPrimaryIds() {
|
|
|
138
135
|
return Array.from(primaryRegistry.keys());
|
|
139
136
|
}
|
|
140
137
|
|
|
141
|
-
var __defProp
|
|
142
|
-
var __defNormalProp
|
|
143
|
-
var __publicField
|
|
138
|
+
var __defProp = Object.defineProperty;
|
|
139
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
140
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
144
141
|
const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
145
142
|
function useMutableCallback(fn) {
|
|
146
143
|
const ref = React__namespace.useRef(fn);
|
|
@@ -171,7 +168,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
171
168
|
return _a = class extends React__namespace.Component {
|
|
172
169
|
constructor() {
|
|
173
170
|
super(...arguments);
|
|
174
|
-
__publicField
|
|
171
|
+
__publicField(this, "state", { error: false });
|
|
175
172
|
}
|
|
176
173
|
componentDidCatch(err) {
|
|
177
174
|
this.props.set(err);
|
|
@@ -179,7 +176,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
179
176
|
render() {
|
|
180
177
|
return this.state.error ? null : this.props.children;
|
|
181
178
|
}
|
|
182
|
-
}, __publicField
|
|
179
|
+
}, __publicField(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
183
180
|
})();
|
|
184
181
|
|
|
185
182
|
const is = {
|
|
@@ -1464,9 +1461,9 @@ const packageData = {
|
|
|
1464
1461
|
function Xb(Tt) {
|
|
1465
1462
|
return Tt && Tt.__esModule && Object.prototype.hasOwnProperty.call(Tt, "default") ? Tt.default : Tt;
|
|
1466
1463
|
}
|
|
1467
|
-
var Rm = { exports: {} }, Og = { exports: {} }, _b
|
|
1464
|
+
var Rm = { exports: {} }, Og = { exports: {} }, _b;
|
|
1468
1465
|
function Kb() {
|
|
1469
|
-
return _b
|
|
1466
|
+
return _b || (_b = 1, (function(Tt) {
|
|
1470
1467
|
Tt.exports = function(m) {
|
|
1471
1468
|
function Yn(t, r, a, l) {
|
|
1472
1469
|
return new uc(t, r, a, l);
|
|
@@ -13981,16 +13978,10 @@ const createStore = (invalidate, advance) => {
|
|
|
13981
13978
|
},
|
|
13982
13979
|
setError: (error) => set(() => ({ error })),
|
|
13983
13980
|
error: null,
|
|
13984
|
-
//*
|
|
13985
|
-
uniforms
|
|
13986
|
-
nodes: {},
|
|
13987
|
-
buffers: {},
|
|
13988
|
-
gpuStorage: {},
|
|
13981
|
+
//* Texture registry (useTextures) ==============================
|
|
13982
|
+
// TSL fields (uniforms, nodes, ..., renderPipeline) are added by @react-three/tsl's root extension.
|
|
13989
13983
|
textures: /* @__PURE__ */ new Map(),
|
|
13990
13984
|
_textureRefs: /* @__PURE__ */ new Map(),
|
|
13991
|
-
renderPipeline: null,
|
|
13992
|
-
passes: {},
|
|
13993
|
-
_hmrVersion: 0,
|
|
13994
13985
|
_sizeImperative: false,
|
|
13995
13986
|
_sizeProps: null,
|
|
13996
13987
|
previousRoot: void 0,
|
|
@@ -15326,788 +15317,6 @@ function Canvas$1(props) {
|
|
|
15326
15317
|
return /* @__PURE__ */ jsxRuntime.jsx(itsFine.FiberProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(CanvasImpl, { ...props }) });
|
|
15327
15318
|
}
|
|
15328
15319
|
|
|
15329
|
-
const RESOURCE_KINDS = ["nodes", "uniforms", "buffers", "gpuStorage"];
|
|
15330
|
-
const ROOT_SCOPE = "";
|
|
15331
|
-
const registries = /* @__PURE__ */ new WeakMap();
|
|
15332
|
-
function getKindRegistry(store, kind) {
|
|
15333
|
-
let registry = registries.get(store);
|
|
15334
|
-
if (!registry) {
|
|
15335
|
-
registry = {
|
|
15336
|
-
nodes: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
15337
|
-
uniforms: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
15338
|
-
buffers: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
15339
|
-
gpuStorage: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() }
|
|
15340
|
-
};
|
|
15341
|
-
registries.set(store, registry);
|
|
15342
|
-
}
|
|
15343
|
-
return registry[kind];
|
|
15344
|
-
}
|
|
15345
|
-
function resolvePrimary$1(store) {
|
|
15346
|
-
return store.getState().primaryStore ?? store;
|
|
15347
|
-
}
|
|
15348
|
-
function isScopeValid(store, kind, scopeKey) {
|
|
15349
|
-
return getKindRegistry(store, kind).valid.has(scopeKey);
|
|
15350
|
-
}
|
|
15351
|
-
function peekStaged(store, kind, scopeKey) {
|
|
15352
|
-
return getKindRegistry(store, kind).staged.get(scopeKey);
|
|
15353
|
-
}
|
|
15354
|
-
function stageEntries(store, kind, scopeKey, entries) {
|
|
15355
|
-
const { staged } = getKindRegistry(store, kind);
|
|
15356
|
-
const current = staged.get(scopeKey);
|
|
15357
|
-
if (current) Object.assign(current, entries);
|
|
15358
|
-
else staged.set(scopeKey, { ...entries });
|
|
15359
|
-
}
|
|
15360
|
-
function readCommittedScope(map, scopeKey, isLeaf) {
|
|
15361
|
-
if (scopeKey === ROOT_SCOPE) {
|
|
15362
|
-
const leaves = {};
|
|
15363
|
-
for (const [key, value] of Object.entries(map)) if (isLeaf(value)) leaves[key] = value;
|
|
15364
|
-
return leaves;
|
|
15365
|
-
}
|
|
15366
|
-
const scopeData = map[scopeKey];
|
|
15367
|
-
if (scopeData && typeof scopeData === "object" && !isLeaf(scopeData)) return scopeData;
|
|
15368
|
-
return {};
|
|
15369
|
-
}
|
|
15370
|
-
function withStagedOverlay(store, kind, committed) {
|
|
15371
|
-
const { staged } = getKindRegistry(store, kind);
|
|
15372
|
-
if (staged.size === 0) return committed;
|
|
15373
|
-
const view = { ...committed };
|
|
15374
|
-
for (const [scopeKey, entries] of staged) {
|
|
15375
|
-
if (scopeKey === ROOT_SCOPE) Object.assign(view, entries);
|
|
15376
|
-
else view[scopeKey] = { ...view[scopeKey], ...entries };
|
|
15377
|
-
}
|
|
15378
|
-
return view;
|
|
15379
|
-
}
|
|
15380
|
-
function flushStagedScope(store, kind, scopeKey, isLeaf) {
|
|
15381
|
-
const registry = getKindRegistry(store, kind);
|
|
15382
|
-
const staged = registry.staged.get(scopeKey);
|
|
15383
|
-
if (!staged) return;
|
|
15384
|
-
registry.staged.delete(scopeKey);
|
|
15385
|
-
const replace = !registry.valid.has(scopeKey);
|
|
15386
|
-
store.setState((state) => {
|
|
15387
|
-
const map = state[kind];
|
|
15388
|
-
if (scopeKey === ROOT_SCOPE) {
|
|
15389
|
-
if (!replace) return { [kind]: { ...map, ...staged } };
|
|
15390
|
-
const next = {};
|
|
15391
|
-
for (const [key, value] of Object.entries(map)) if (!isLeaf(value)) next[key] = value;
|
|
15392
|
-
return { [kind]: { ...next, ...staged } };
|
|
15393
|
-
}
|
|
15394
|
-
const current = replace ? {} : map[scopeKey] ?? {};
|
|
15395
|
-
return { [kind]: { ...map, [scopeKey]: { ...current, ...staged } } };
|
|
15396
|
-
});
|
|
15397
|
-
registry.valid.add(scopeKey);
|
|
15398
|
-
}
|
|
15399
|
-
function invalidateResource(store, kind, scopeKey) {
|
|
15400
|
-
const registry = getKindRegistry(store, kind);
|
|
15401
|
-
if (scopeKey === void 0) {
|
|
15402
|
-
registry.valid.clear();
|
|
15403
|
-
registry.staged.clear();
|
|
15404
|
-
} else {
|
|
15405
|
-
registry.valid.delete(scopeKey);
|
|
15406
|
-
registry.staged.delete(scopeKey);
|
|
15407
|
-
}
|
|
15408
|
-
}
|
|
15409
|
-
function rebuildResource(store, kind, userScope) {
|
|
15410
|
-
const primary = resolvePrimary$1(store);
|
|
15411
|
-
invalidateResource(primary, kind, userScope === "root" ? ROOT_SCOPE : userScope);
|
|
15412
|
-
primary.setState((state) => ({ _hmrVersion: state._hmrVersion + 1 }));
|
|
15413
|
-
}
|
|
15414
|
-
function invalidateAllResources(store) {
|
|
15415
|
-
for (const kind of RESOURCE_KINDS) invalidateResource(store, kind);
|
|
15416
|
-
}
|
|
15417
|
-
function removeResourceEntries(store, kind, names, scope, isLeaf) {
|
|
15418
|
-
const staged = peekStaged(store, kind, scope ?? ROOT_SCOPE);
|
|
15419
|
-
if (staged) for (const name of names) delete staged[name];
|
|
15420
|
-
store.setState((state) => {
|
|
15421
|
-
const map = state[kind];
|
|
15422
|
-
if (scope) {
|
|
15423
|
-
const currentScope = { ...map[scope] };
|
|
15424
|
-
for (const name of names) delete currentScope[name];
|
|
15425
|
-
return { [kind]: { ...map, [scope]: currentScope } };
|
|
15426
|
-
}
|
|
15427
|
-
const next = { ...map };
|
|
15428
|
-
for (const name of names) if (isLeaf(next[name])) delete next[name];
|
|
15429
|
-
return { [kind]: next };
|
|
15430
|
-
});
|
|
15431
|
-
}
|
|
15432
|
-
function clearResourceEntries(store, kind, scope, isLeaf) {
|
|
15433
|
-
const registry = getKindRegistry(store, kind);
|
|
15434
|
-
if (scope && scope !== "root") registry.staged.delete(scope);
|
|
15435
|
-
else if (scope === "root") registry.staged.delete(ROOT_SCOPE);
|
|
15436
|
-
else registry.staged.clear();
|
|
15437
|
-
store.setState((state) => {
|
|
15438
|
-
const map = state[kind];
|
|
15439
|
-
if (scope && scope !== "root") {
|
|
15440
|
-
const { [scope]: _, ...rest } = map;
|
|
15441
|
-
return { [kind]: rest };
|
|
15442
|
-
}
|
|
15443
|
-
if (scope === "root") {
|
|
15444
|
-
const next = {};
|
|
15445
|
-
for (const [key, value] of Object.entries(map)) if (!isLeaf(value)) next[key] = value;
|
|
15446
|
-
return { [kind]: next };
|
|
15447
|
-
}
|
|
15448
|
-
return { [kind]: {} };
|
|
15449
|
-
});
|
|
15450
|
-
}
|
|
15451
|
-
|
|
15452
|
-
const isObjectLike = (value) => value !== null && (typeof value === "object" || typeof value === "function");
|
|
15453
|
-
const hasValidLegacyNodeMarkers = (value) => {
|
|
15454
|
-
const hasUuid = "uuid" in value;
|
|
15455
|
-
const hasNodeType = "nodeType" in value;
|
|
15456
|
-
const uuid = Reflect.get(value, "uuid");
|
|
15457
|
-
const nodeType = Reflect.get(value, "nodeType");
|
|
15458
|
-
return (hasUuid || hasNodeType) && (!hasUuid || uuid === void 0 || typeof uuid === "string") && (!hasNodeType || nodeType === void 0 || nodeType === null || typeof nodeType === "string");
|
|
15459
|
-
};
|
|
15460
|
-
const isUniformNode = (value) => isObjectLike(value) && "isUniformNode" in value && value.isUniformNode === true;
|
|
15461
|
-
const isTSLNode = (value) => isObjectLike(value) && (Reflect.get(value, "isNode") === true || Reflect.get(value, "shaderNode") !== void 0 && typeof Reflect.get(value, "id") === "number" || hasValidLegacyNodeMarkers(value));
|
|
15462
|
-
const isBufferLike = (value) => ArrayBuffer.isView(value) && !(value instanceof DataView) || isObjectLike(value) && ("isBufferAttribute" in value || "isInterleavedBufferAttribute" in value || isTSLNode(value));
|
|
15463
|
-
const isStorageLike = (value) => isObjectLike(value) && ("isTexture" in value || "isData3DTexture" in value || isTSLNode(value));
|
|
15464
|
-
|
|
15465
|
-
var __defProp = Object.defineProperty;
|
|
15466
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
15467
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
15468
|
-
var _a, _b;
|
|
15469
|
-
const INTERNAL_DATA = Symbol("ScopedStore.data");
|
|
15470
|
-
const INTERNAL_IS_LEAF = Symbol("ScopedStore.isLeaf");
|
|
15471
|
-
_b = INTERNAL_DATA, _a = INTERNAL_IS_LEAF;
|
|
15472
|
-
const _ScopedStore = class _ScopedStore {
|
|
15473
|
-
constructor(data, isLeaf) {
|
|
15474
|
-
__publicField(this, _b);
|
|
15475
|
-
__publicField(this, _a);
|
|
15476
|
-
this[INTERNAL_DATA] = data;
|
|
15477
|
-
this[INTERNAL_IS_LEAF] = isLeaf;
|
|
15478
|
-
return new Proxy(this, {
|
|
15479
|
-
get(target, prop, receiver) {
|
|
15480
|
-
if (typeof prop === "string") {
|
|
15481
|
-
if (prop === "scope" || prop === "has" || prop === "keys") {
|
|
15482
|
-
return Reflect.get(target, prop, receiver);
|
|
15483
|
-
}
|
|
15484
|
-
return target[INTERNAL_DATA][prop];
|
|
15485
|
-
}
|
|
15486
|
-
return Reflect.get(target, prop, receiver);
|
|
15487
|
-
},
|
|
15488
|
-
has(target, prop) {
|
|
15489
|
-
return typeof prop === "string" ? prop in target[INTERNAL_DATA] : Reflect.has(target, prop);
|
|
15490
|
-
},
|
|
15491
|
-
ownKeys(target) {
|
|
15492
|
-
return Reflect.ownKeys(target[INTERNAL_DATA]);
|
|
15493
|
-
},
|
|
15494
|
-
getOwnPropertyDescriptor(target, prop) {
|
|
15495
|
-
if (typeof prop === "string" && prop in target[INTERNAL_DATA]) {
|
|
15496
|
-
return {
|
|
15497
|
-
configurable: true,
|
|
15498
|
-
enumerable: true,
|
|
15499
|
-
value: target[INTERNAL_DATA][prop]
|
|
15500
|
-
};
|
|
15501
|
-
}
|
|
15502
|
-
return void 0;
|
|
15503
|
-
}
|
|
15504
|
-
});
|
|
15505
|
-
}
|
|
15506
|
-
/**
|
|
15507
|
-
* Access a nested scope by key.
|
|
15508
|
-
* If the key doesn't exist or isn't a scope object, returns an empty ScopedStore.
|
|
15509
|
-
*/
|
|
15510
|
-
scope(key) {
|
|
15511
|
-
const value = this[INTERNAL_DATA][key];
|
|
15512
|
-
const isLeaf = this[INTERNAL_IS_LEAF];
|
|
15513
|
-
const scope = value && typeof value === "object" && !isLeaf(value) ? value : {};
|
|
15514
|
-
return new _ScopedStore(scope, isLeaf);
|
|
15515
|
-
}
|
|
15516
|
-
/**
|
|
15517
|
-
* Check if a key exists in the store.
|
|
15518
|
-
*/
|
|
15519
|
-
has(key) {
|
|
15520
|
-
return key in this[INTERNAL_DATA];
|
|
15521
|
-
}
|
|
15522
|
-
/**
|
|
15523
|
-
* Get all keys in the store.
|
|
15524
|
-
*/
|
|
15525
|
-
keys() {
|
|
15526
|
-
return Object.keys(this[INTERNAL_DATA]);
|
|
15527
|
-
}
|
|
15528
|
-
};
|
|
15529
|
-
let ScopedStore = _ScopedStore;
|
|
15530
|
-
function createScopedStore(data, isLeaf) {
|
|
15531
|
-
return new ScopedStore(data, isLeaf);
|
|
15532
|
-
}
|
|
15533
|
-
function createLazyCreatorState(state, store) {
|
|
15534
|
-
let _uniforms = null;
|
|
15535
|
-
let _nodes = null;
|
|
15536
|
-
let _buffers = null;
|
|
15537
|
-
let _gpuStorage = null;
|
|
15538
|
-
const view = (kind) => store ? withStagedOverlay(store, kind, state[kind]) : state[kind];
|
|
15539
|
-
return Object.create(state, {
|
|
15540
|
-
uniforms: {
|
|
15541
|
-
get() {
|
|
15542
|
-
return _uniforms ?? (_uniforms = createScopedStore(view("uniforms"), isUniformNode));
|
|
15543
|
-
}
|
|
15544
|
-
},
|
|
15545
|
-
nodes: {
|
|
15546
|
-
get() {
|
|
15547
|
-
return _nodes ?? (_nodes = createScopedStore(view("nodes"), isTSLNode));
|
|
15548
|
-
}
|
|
15549
|
-
},
|
|
15550
|
-
buffers: {
|
|
15551
|
-
get() {
|
|
15552
|
-
return _buffers ?? (_buffers = createScopedStore(view("buffers"), isBufferLike));
|
|
15553
|
-
}
|
|
15554
|
-
},
|
|
15555
|
-
gpuStorage: {
|
|
15556
|
-
get() {
|
|
15557
|
-
return _gpuStorage ?? (_gpuStorage = createScopedStore(view("gpuStorage"), isStorageLike));
|
|
15558
|
-
}
|
|
15559
|
-
}
|
|
15560
|
-
});
|
|
15561
|
-
}
|
|
15562
|
-
|
|
15563
|
-
function resolvePrimary(local) {
|
|
15564
|
-
return local.getState().primaryStore ?? local;
|
|
15565
|
-
}
|
|
15566
|
-
function usePrimaryStore() {
|
|
15567
|
-
const local = useStore();
|
|
15568
|
-
const primary = local.getState().primaryStore;
|
|
15569
|
-
return React.useMemo(() => primary ?? local, [primary, local]);
|
|
15570
|
-
}
|
|
15571
|
-
function usePrimaryThree(selector = (state) => state, equalityFn) {
|
|
15572
|
-
const local = useStore();
|
|
15573
|
-
const primary = resolvePrimary(local);
|
|
15574
|
-
return primary(selector, equalityFn);
|
|
15575
|
-
}
|
|
15576
|
-
|
|
15577
|
-
function scopedNodeName(scope, name) {
|
|
15578
|
-
const raw = scope ? `${scope}_${name}` : name;
|
|
15579
|
-
const safe = raw.replace(/[^A-Za-z0-9_]/g, "_");
|
|
15580
|
-
return /^[A-Za-z_]/.test(safe) ? safe : `_${safe}`;
|
|
15581
|
-
}
|
|
15582
|
-
function extractTSLValue(value) {
|
|
15583
|
-
if (value === null || value === void 0) return value;
|
|
15584
|
-
if (typeof value !== "object") return value;
|
|
15585
|
-
const node = value;
|
|
15586
|
-
if (!node.isNode) return value;
|
|
15587
|
-
if (node.isConstNode) {
|
|
15588
|
-
return node.value;
|
|
15589
|
-
}
|
|
15590
|
-
if ("value" in node) {
|
|
15591
|
-
let extractedValue = node.value;
|
|
15592
|
-
if (typeof node.traverse === "function") {
|
|
15593
|
-
node.traverse((n) => {
|
|
15594
|
-
if (n.isConstNode) {
|
|
15595
|
-
extractedValue = n.value;
|
|
15596
|
-
}
|
|
15597
|
-
});
|
|
15598
|
-
}
|
|
15599
|
-
return extractedValue;
|
|
15600
|
-
}
|
|
15601
|
-
return value;
|
|
15602
|
-
}
|
|
15603
|
-
function vectorize(inObject) {
|
|
15604
|
-
if (inObject === null || inObject === void 0) return inObject;
|
|
15605
|
-
if (typeof inObject === "string") {
|
|
15606
|
-
const isHexColor = /^(#|0x)[0-9a-f]{3,8}$/i.test(inObject);
|
|
15607
|
-
const isNamedColor = /^[a-z]+$/i.test(inObject);
|
|
15608
|
-
if (isHexColor || isNamedColor) {
|
|
15609
|
-
return new webgpu.Color(inObject);
|
|
15610
|
-
}
|
|
15611
|
-
return inObject;
|
|
15612
|
-
}
|
|
15613
|
-
if (typeof inObject !== "object") return inObject;
|
|
15614
|
-
const obj = inObject;
|
|
15615
|
-
if (obj.isNode) {
|
|
15616
|
-
return extractTSLValue(inObject);
|
|
15617
|
-
}
|
|
15618
|
-
if (obj.isVector2 || obj.isVector3 || obj.isVector4) return inObject;
|
|
15619
|
-
if (obj.isMatrix2 || obj.isMatrix3 || obj.isMatrix4) return inObject;
|
|
15620
|
-
if (obj.isColor || obj.isEuler || obj.isQuaternion || obj.isSpherical) return inObject;
|
|
15621
|
-
if ("r" in obj && "g" in obj && "b" in obj && typeof obj.r === "number" && typeof obj.g === "number" && typeof obj.b === "number") {
|
|
15622
|
-
const scale = obj.r > 1 || obj.g > 1 || obj.b > 1 ? 1 / 255 : 1;
|
|
15623
|
-
return new webgpu.Color(obj.r * scale, obj.g * scale, obj.b * scale);
|
|
15624
|
-
}
|
|
15625
|
-
if ("x" in obj && "y" in obj && typeof obj.x === "number" && typeof obj.y === "number") {
|
|
15626
|
-
if ("w" in obj && typeof obj.w === "number" && "z" in obj && typeof obj.z === "number") {
|
|
15627
|
-
return new webgpu.Vector4(obj.x, obj.y, obj.z, obj.w);
|
|
15628
|
-
}
|
|
15629
|
-
if ("z" in obj && typeof obj.z === "number") {
|
|
15630
|
-
return new webgpu.Vector3(obj.x, obj.y, obj.z);
|
|
15631
|
-
}
|
|
15632
|
-
return new webgpu.Vector2(obj.x, obj.y);
|
|
15633
|
-
}
|
|
15634
|
-
return inObject;
|
|
15635
|
-
}
|
|
15636
|
-
|
|
15637
|
-
function useCompareMemoize(value, deep) {
|
|
15638
|
-
const ref = React.useRef(value);
|
|
15639
|
-
const compare = lite.dequal ;
|
|
15640
|
-
if (!compare(value, ref.current)) {
|
|
15641
|
-
ref.current = value;
|
|
15642
|
-
}
|
|
15643
|
-
return ref.current;
|
|
15644
|
-
}
|
|
15645
|
-
|
|
15646
|
-
function clearHmrCaches(store) {
|
|
15647
|
-
const primary = store.getState().primaryStore ?? store;
|
|
15648
|
-
invalidateAllResources(primary);
|
|
15649
|
-
primary.setState((state) => ({ _hmrVersion: state._hmrVersion + 1 }));
|
|
15650
|
-
}
|
|
15651
|
-
|
|
15652
|
-
const SHARED_KEYS = ["uniforms", "nodes", "buffers", "gpuStorage", "_hmrVersion"];
|
|
15653
|
-
const following = /* @__PURE__ */ new WeakMap();
|
|
15654
|
-
function followPrimary(store) {
|
|
15655
|
-
const primary = store.getState().primaryStore;
|
|
15656
|
-
if (!primary || primary === store) return;
|
|
15657
|
-
const sync = () => {
|
|
15658
|
-
const source = primary.getState();
|
|
15659
|
-
const target = store.getState();
|
|
15660
|
-
let patch = null;
|
|
15661
|
-
for (const key of SHARED_KEYS) {
|
|
15662
|
-
if (target[key] !== source[key]) (patch ?? (patch = {}))[key] = source[key];
|
|
15663
|
-
}
|
|
15664
|
-
if (patch) store.setState(patch);
|
|
15665
|
-
};
|
|
15666
|
-
sync();
|
|
15667
|
-
following.set(store, primary.subscribe(sync));
|
|
15668
|
-
}
|
|
15669
|
-
function stopFollowing(store) {
|
|
15670
|
-
following.get(store)?.();
|
|
15671
|
-
following.delete(store);
|
|
15672
|
-
}
|
|
15673
|
-
let registered = false;
|
|
15674
|
-
function ensureTSLExtension() {
|
|
15675
|
-
if (registered) return;
|
|
15676
|
-
registered = true;
|
|
15677
|
-
registerRootExtension({
|
|
15678
|
-
name: "@react-three/tsl",
|
|
15679
|
-
setup: followPrimary,
|
|
15680
|
-
dispose: stopFollowing,
|
|
15681
|
-
// Resolves primaryStore itself, so every canvas sharing a renderer refreshes the same resources.
|
|
15682
|
-
hmr: clearHmrCaches
|
|
15683
|
-
});
|
|
15684
|
-
}
|
|
15685
|
-
|
|
15686
|
-
ensureTSLExtension();
|
|
15687
|
-
function useScopedResource(options) {
|
|
15688
|
-
const { store, kind, scope, isLeaf, create, prepare, reconcile, input } = options;
|
|
15689
|
-
const scopeKey = scope ?? ROOT_SCOPE;
|
|
15690
|
-
const version = store((s) => s._hmrVersion);
|
|
15691
|
-
const entries = React.useMemo(() => {
|
|
15692
|
-
const staged = peekStaged(store, kind, scopeKey);
|
|
15693
|
-
const reusable = isScopeValid(store, kind, scopeKey);
|
|
15694
|
-
const map = store.getState()[kind];
|
|
15695
|
-
const committed = reusable ? readCommittedScope(map, scopeKey, isLeaf) : void 0;
|
|
15696
|
-
const result = {};
|
|
15697
|
-
let fresh = null;
|
|
15698
|
-
for (const [name, candidate] of Object.entries(create())) {
|
|
15699
|
-
const existing = staged?.[name] ?? committed?.[name];
|
|
15700
|
-
if (existing !== void 0) {
|
|
15701
|
-
result[name] = existing;
|
|
15702
|
-
reconcile?.(existing, candidate);
|
|
15703
|
-
} else {
|
|
15704
|
-
const value = prepare ? prepare(name, candidate) : candidate;
|
|
15705
|
-
result[name] = value;
|
|
15706
|
-
(fresh ?? (fresh = {}))[name] = value;
|
|
15707
|
-
}
|
|
15708
|
-
}
|
|
15709
|
-
if (fresh) stageEntries(store, kind, scopeKey, fresh);
|
|
15710
|
-
return result;
|
|
15711
|
-
}, [store, kind, scopeKey, version, input]);
|
|
15712
|
-
useIsomorphicLayoutEffect(() => {
|
|
15713
|
-
flushStagedScope(store, kind, scopeKey, isLeaf);
|
|
15714
|
-
});
|
|
15715
|
-
return entries;
|
|
15716
|
-
}
|
|
15717
|
-
|
|
15718
|
-
function useUniforms(creatorOrScope, scope) {
|
|
15719
|
-
const store = usePrimaryStore();
|
|
15720
|
-
const removeUniforms2 = React.useCallback(
|
|
15721
|
-
(names, targetScope) => removeResourceEntries(store, "uniforms", Array.isArray(names) ? names : [names], targetScope, isUniformNode),
|
|
15722
|
-
[store]
|
|
15723
|
-
);
|
|
15724
|
-
const clearUniforms = React.useCallback(
|
|
15725
|
-
(targetScope) => clearResourceEntries(store, "uniforms", targetScope, isUniformNode),
|
|
15726
|
-
[store]
|
|
15727
|
-
);
|
|
15728
|
-
const rebuildUniforms = React.useCallback(
|
|
15729
|
-
(targetScope) => rebuildResource(store, "uniforms", targetScope),
|
|
15730
|
-
[store]
|
|
15731
|
-
);
|
|
15732
|
-
const processedInput = React.useMemo(() => {
|
|
15733
|
-
let raw = creatorOrScope;
|
|
15734
|
-
if (is.fun(creatorOrScope)) {
|
|
15735
|
-
const wrappedState = createLazyCreatorState(store.getState(), store);
|
|
15736
|
-
raw = creatorOrScope(wrappedState);
|
|
15737
|
-
}
|
|
15738
|
-
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
15739
|
-
const normalized = {};
|
|
15740
|
-
for (const [key, value] of Object.entries(raw)) {
|
|
15741
|
-
normalized[key] = vectorize(value);
|
|
15742
|
-
}
|
|
15743
|
-
return { candidates: raw, normalized };
|
|
15744
|
-
}
|
|
15745
|
-
return { candidates: raw, normalized: raw };
|
|
15746
|
-
}, [creatorOrScope, store]);
|
|
15747
|
-
const memoizedInput = useCompareMemoize(processedInput.normalized);
|
|
15748
|
-
const isReader = memoizedInput === void 0 || typeof memoizedInput === "string";
|
|
15749
|
-
const storeUniforms = usePrimaryThree((s) => s.uniforms);
|
|
15750
|
-
const created = useScopedResource({
|
|
15751
|
-
store,
|
|
15752
|
-
kind: "uniforms",
|
|
15753
|
-
scope: isReader ? void 0 : scope,
|
|
15754
|
-
isLeaf: isUniformNode,
|
|
15755
|
-
input: memoizedInput,
|
|
15756
|
-
create: () => {
|
|
15757
|
-
if (isReader) return {};
|
|
15758
|
-
if (typeof processedInput.candidates !== "object" || processedInput.candidates === null)
|
|
15759
|
-
throw new Error("Invalid uniform input");
|
|
15760
|
-
return processedInput.candidates;
|
|
15761
|
-
},
|
|
15762
|
-
prepare: (name, candidate) => createUniform(name, candidate, scope),
|
|
15763
|
-
reconcile: (existing, candidate) => {
|
|
15764
|
-
const existingVal = existing.value;
|
|
15765
|
-
const newVal = vectorize(candidate);
|
|
15766
|
-
let equals = newVal === existingVal;
|
|
15767
|
-
if (!equals && hasEqualsMethod(existingVal) && hasEqualsMethod(newVal)) {
|
|
15768
|
-
if (isThreeVector(existingVal) && isThreeVector(newVal)) {
|
|
15769
|
-
equals = vectorEquals(existingVal, newVal);
|
|
15770
|
-
} else if (isSameThreeType(existingVal, newVal)) {
|
|
15771
|
-
equals = existingVal.equals(newVal);
|
|
15772
|
-
}
|
|
15773
|
-
}
|
|
15774
|
-
if (!equals) existing.value = newVal;
|
|
15775
|
-
}
|
|
15776
|
-
});
|
|
15777
|
-
let uniforms = created;
|
|
15778
|
-
if (memoizedInput === void 0) {
|
|
15779
|
-
uniforms = storeUniforms;
|
|
15780
|
-
} else if (typeof memoizedInput === "string") {
|
|
15781
|
-
const scopeData = storeUniforms[memoizedInput];
|
|
15782
|
-
uniforms = scopeData && !isUniformNode(scopeData) ? scopeData : {};
|
|
15783
|
-
}
|
|
15784
|
-
return { ...uniforms, removeUniforms: removeUniforms2, clearUniforms, rebuildUniforms };
|
|
15785
|
-
}
|
|
15786
|
-
function rebuildAllUniforms(store, scope) {
|
|
15787
|
-
rebuildResource(store, "uniforms", scope);
|
|
15788
|
-
}
|
|
15789
|
-
function removeUniforms(set, names, scope) {
|
|
15790
|
-
set((state) => {
|
|
15791
|
-
if (scope) {
|
|
15792
|
-
const currentScope = { ...state.uniforms[scope] };
|
|
15793
|
-
for (const name of names) delete currentScope[name];
|
|
15794
|
-
return { uniforms: { ...state.uniforms, [scope]: currentScope } };
|
|
15795
|
-
}
|
|
15796
|
-
const uniforms = { ...state.uniforms };
|
|
15797
|
-
for (const name of names) if (isUniformNode(uniforms[name])) delete uniforms[name];
|
|
15798
|
-
return { uniforms };
|
|
15799
|
-
});
|
|
15800
|
-
}
|
|
15801
|
-
function clearScope(set, scope) {
|
|
15802
|
-
set((state) => {
|
|
15803
|
-
const { [scope]: _, ...rest } = state.uniforms;
|
|
15804
|
-
return { uniforms: rest };
|
|
15805
|
-
});
|
|
15806
|
-
}
|
|
15807
|
-
function clearRootUniforms(set) {
|
|
15808
|
-
set((state) => {
|
|
15809
|
-
const uniforms = {};
|
|
15810
|
-
for (const [key, value] of Object.entries(state.uniforms)) {
|
|
15811
|
-
if (!isUniformNode(value)) uniforms[key] = value;
|
|
15812
|
-
}
|
|
15813
|
-
return { uniforms };
|
|
15814
|
-
});
|
|
15815
|
-
}
|
|
15816
|
-
function createUniform(inName, node, scope) {
|
|
15817
|
-
if (node.type === "UniformNode") return node;
|
|
15818
|
-
const inValue = vectorize(node);
|
|
15819
|
-
const newUniform = tsl.uniform(inValue);
|
|
15820
|
-
if (typeof newUniform.setName === "function") {
|
|
15821
|
-
newUniform.setName(scopedNodeName(scope, inName));
|
|
15822
|
-
}
|
|
15823
|
-
return newUniform;
|
|
15824
|
-
}
|
|
15825
|
-
function isThreeVector(inVector) {
|
|
15826
|
-
if (!inVector) return false;
|
|
15827
|
-
return inVector.isVector2 || inVector.isVector3 || inVector.isVector4;
|
|
15828
|
-
}
|
|
15829
|
-
function vectorEquals(a, b) {
|
|
15830
|
-
if (a.isVector2 && b.isVector2) {
|
|
15831
|
-
return a.equals(b);
|
|
15832
|
-
}
|
|
15833
|
-
if (a.isVector3 && b.isVector3) {
|
|
15834
|
-
return a.equals(b);
|
|
15835
|
-
}
|
|
15836
|
-
if (a.isVector4 && b.isVector4) {
|
|
15837
|
-
return a.equals(b);
|
|
15838
|
-
}
|
|
15839
|
-
return false;
|
|
15840
|
-
}
|
|
15841
|
-
function hasEqualsMethod(value) {
|
|
15842
|
-
return value !== null && typeof value === "object" && "equals" in value && typeof value.equals === "function";
|
|
15843
|
-
}
|
|
15844
|
-
function isSameThreeType(a, b) {
|
|
15845
|
-
const obj_a = a;
|
|
15846
|
-
const obj_b = b;
|
|
15847
|
-
return obj_a.isColor && obj_b.isColor || obj_a.isMatrix2 && obj_b.isMatrix2 || obj_a.isMatrix3 && obj_b.isMatrix3 || obj_a.isMatrix4 && obj_b.isMatrix4 || obj_a.isEuler && obj_b.isEuler || obj_a.isQuaternion && obj_b.isQuaternion;
|
|
15848
|
-
}
|
|
15849
|
-
|
|
15850
|
-
const uniformOf = tsl.uniform;
|
|
15851
|
-
function useUniform(name, value) {
|
|
15852
|
-
const store = usePrimaryStore();
|
|
15853
|
-
const registered = useScopedResource({
|
|
15854
|
-
store,
|
|
15855
|
-
kind: "uniforms",
|
|
15856
|
-
scope: void 0,
|
|
15857
|
-
isLeaf: isUniformNode,
|
|
15858
|
-
input: name,
|
|
15859
|
-
create: () => value === void 0 ? {} : { [name]: value },
|
|
15860
|
-
prepare: createNamedUniform,
|
|
15861
|
-
reconcile: (existing2) => {
|
|
15862
|
-
if (value !== void 0 && !isTSLNode(value) && !isUniformNode(value)) {
|
|
15863
|
-
existing2.value = typeof value === "string" ? new webgpu.Color(value) : value;
|
|
15864
|
-
}
|
|
15865
|
-
}
|
|
15866
|
-
});
|
|
15867
|
-
if (registered[name]) return registered[name];
|
|
15868
|
-
const existing = peekStaged(store, "uniforms", ROOT_SCOPE)?.[name] ?? store.getState().uniforms[name];
|
|
15869
|
-
if (existing && isUniformNode(existing)) return existing;
|
|
15870
|
-
throw new Error(
|
|
15871
|
-
`[useUniform] Uniform "${name}" not found. Create it first with: useUniform('${name}', initialValue)`
|
|
15872
|
-
);
|
|
15873
|
-
}
|
|
15874
|
-
function createNamedUniform(name, value) {
|
|
15875
|
-
let node;
|
|
15876
|
-
if (isUniformNode(value)) {
|
|
15877
|
-
node = value;
|
|
15878
|
-
} else if (isTSLNode(value)) {
|
|
15879
|
-
node = uniformOf(value);
|
|
15880
|
-
} else if (typeof value === "string") {
|
|
15881
|
-
node = tsl.uniform(new webgpu.Color(value));
|
|
15882
|
-
} else {
|
|
15883
|
-
node = uniformOf(value);
|
|
15884
|
-
}
|
|
15885
|
-
if (typeof node.setName === "function") {
|
|
15886
|
-
node.setName(name);
|
|
15887
|
-
}
|
|
15888
|
-
return node;
|
|
15889
|
-
}
|
|
15890
|
-
|
|
15891
|
-
function useNodes(creatorOrScope, scope) {
|
|
15892
|
-
const store = usePrimaryStore();
|
|
15893
|
-
const removeNodes2 = React.useCallback(
|
|
15894
|
-
(names, targetScope) => removeResourceEntries(store, "nodes", Array.isArray(names) ? names : [names], targetScope, isTSLNode),
|
|
15895
|
-
[store]
|
|
15896
|
-
);
|
|
15897
|
-
const clearNodes = React.useCallback(
|
|
15898
|
-
(targetScope) => clearResourceEntries(store, "nodes", targetScope, isTSLNode),
|
|
15899
|
-
[store]
|
|
15900
|
-
);
|
|
15901
|
-
const rebuildNodes = React.useCallback(
|
|
15902
|
-
(targetScope) => rebuildResource(store, "nodes", targetScope),
|
|
15903
|
-
[store]
|
|
15904
|
-
);
|
|
15905
|
-
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
15906
|
-
const storeNodes = usePrimaryThree((s) => s.nodes);
|
|
15907
|
-
const created = useScopedResource({
|
|
15908
|
-
store,
|
|
15909
|
-
kind: "nodes",
|
|
15910
|
-
scope: isReader ? void 0 : scope,
|
|
15911
|
-
isLeaf: isTSLNode,
|
|
15912
|
-
create: () => {
|
|
15913
|
-
if (isReader) return {};
|
|
15914
|
-
return creatorOrScope(createLazyCreatorState(store.getState(), store));
|
|
15915
|
-
},
|
|
15916
|
-
prepare: (name, node) => {
|
|
15917
|
-
const setName = Reflect.get(node, "setName");
|
|
15918
|
-
if (typeof setName === "function") setName.call(node, scopedNodeName(scope, name));
|
|
15919
|
-
return node;
|
|
15920
|
-
}
|
|
15921
|
-
});
|
|
15922
|
-
let nodes = created;
|
|
15923
|
-
if (creatorOrScope === void 0) {
|
|
15924
|
-
nodes = storeNodes;
|
|
15925
|
-
} else if (typeof creatorOrScope === "string") {
|
|
15926
|
-
const scopeData = storeNodes[creatorOrScope];
|
|
15927
|
-
nodes = scopeData && !isTSLNode(scopeData) ? scopeData : {};
|
|
15928
|
-
}
|
|
15929
|
-
return { ...nodes, removeNodes: removeNodes2, clearNodes, rebuildNodes };
|
|
15930
|
-
}
|
|
15931
|
-
function rebuildAllNodes(store, scope) {
|
|
15932
|
-
rebuildResource(store, "nodes", scope);
|
|
15933
|
-
}
|
|
15934
|
-
function removeNodes(set, names, scope) {
|
|
15935
|
-
set((state) => {
|
|
15936
|
-
if (scope) {
|
|
15937
|
-
const currentScope = { ...state.nodes[scope] };
|
|
15938
|
-
for (const name of names) delete currentScope[name];
|
|
15939
|
-
return { nodes: { ...state.nodes, [scope]: currentScope } };
|
|
15940
|
-
}
|
|
15941
|
-
const nodes = { ...state.nodes };
|
|
15942
|
-
for (const name of names) if (isTSLNode(nodes[name])) delete nodes[name];
|
|
15943
|
-
return { nodes };
|
|
15944
|
-
});
|
|
15945
|
-
}
|
|
15946
|
-
function clearNodeScope(set, scope) {
|
|
15947
|
-
set((state) => {
|
|
15948
|
-
const { [scope]: _, ...rest } = state.nodes;
|
|
15949
|
-
return { nodes: rest };
|
|
15950
|
-
});
|
|
15951
|
-
}
|
|
15952
|
-
function clearRootNodes(set) {
|
|
15953
|
-
set((state) => {
|
|
15954
|
-
const nodes = {};
|
|
15955
|
-
for (const [key, value] of Object.entries(state.nodes)) {
|
|
15956
|
-
if (!isTSLNode(value)) nodes[key] = value;
|
|
15957
|
-
}
|
|
15958
|
-
return { nodes };
|
|
15959
|
-
});
|
|
15960
|
-
}
|
|
15961
|
-
function useLocalNodes(creator) {
|
|
15962
|
-
const store = usePrimaryStore();
|
|
15963
|
-
const uniforms = usePrimaryThree((s) => s.uniforms);
|
|
15964
|
-
const nodes = usePrimaryThree((s) => s.nodes);
|
|
15965
|
-
const textures = usePrimaryThree((s) => s.textures);
|
|
15966
|
-
const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
|
|
15967
|
-
return React.useMemo(() => {
|
|
15968
|
-
const wrappedState = createLazyCreatorState(store.getState(), store);
|
|
15969
|
-
return creator(wrappedState);
|
|
15970
|
-
}, [store, creator, uniforms, nodes, textures, hmrVersion]);
|
|
15971
|
-
}
|
|
15972
|
-
|
|
15973
|
-
const disposeBuffer = (buffer) => {
|
|
15974
|
-
if (buffer === null || typeof buffer !== "object") return;
|
|
15975
|
-
if ("dispose" in buffer && typeof buffer.dispose === "function") {
|
|
15976
|
-
buffer.dispose();
|
|
15977
|
-
}
|
|
15978
|
-
};
|
|
15979
|
-
function useBuffers(creatorOrScope, scope) {
|
|
15980
|
-
const store = usePrimaryStore();
|
|
15981
|
-
const removeBuffers = React.useCallback(
|
|
15982
|
-
(names, targetScope) => removeResourceEntries(store, "buffers", Array.isArray(names) ? names : [names], targetScope, isBufferLike),
|
|
15983
|
-
[store]
|
|
15984
|
-
);
|
|
15985
|
-
const clearBuffers = React.useCallback(
|
|
15986
|
-
(targetScope) => clearResourceEntries(store, "buffers", targetScope, isBufferLike),
|
|
15987
|
-
[store]
|
|
15988
|
-
);
|
|
15989
|
-
const rebuildBuffers = React.useCallback(
|
|
15990
|
-
(targetScope) => rebuildResource(store, "buffers", targetScope),
|
|
15991
|
-
[store]
|
|
15992
|
-
);
|
|
15993
|
-
const disposeBuffers = React.useCallback(
|
|
15994
|
-
(names, targetScope) => {
|
|
15995
|
-
const nameArray = Array.isArray(names) ? names : [names];
|
|
15996
|
-
const state = store.getState();
|
|
15997
|
-
for (const name of nameArray) {
|
|
15998
|
-
const buffer = targetScope ? state.buffers[targetScope]?.[name] : state.buffers[name];
|
|
15999
|
-
if (buffer && isBufferLike(buffer)) {
|
|
16000
|
-
disposeBuffer(buffer);
|
|
16001
|
-
}
|
|
16002
|
-
}
|
|
16003
|
-
removeBuffers(names, targetScope);
|
|
16004
|
-
},
|
|
16005
|
-
[store, removeBuffers]
|
|
16006
|
-
);
|
|
16007
|
-
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
16008
|
-
const storeBuffers = usePrimaryThree((s) => s.buffers);
|
|
16009
|
-
const created = useScopedResource({
|
|
16010
|
-
store,
|
|
16011
|
-
kind: "buffers",
|
|
16012
|
-
scope: isReader ? void 0 : scope,
|
|
16013
|
-
isLeaf: isBufferLike,
|
|
16014
|
-
create: () => {
|
|
16015
|
-
if (isReader) return {};
|
|
16016
|
-
return creatorOrScope(createLazyCreatorState(store.getState(), store));
|
|
16017
|
-
},
|
|
16018
|
-
prepare: (name, buffer) => {
|
|
16019
|
-
const setName = Reflect.get(buffer, "setName");
|
|
16020
|
-
if (typeof setName === "function") setName.call(buffer, scopedNodeName(scope, name));
|
|
16021
|
-
return buffer;
|
|
16022
|
-
}
|
|
16023
|
-
});
|
|
16024
|
-
let buffers = created;
|
|
16025
|
-
if (creatorOrScope === void 0) {
|
|
16026
|
-
buffers = storeBuffers;
|
|
16027
|
-
} else if (typeof creatorOrScope === "string") {
|
|
16028
|
-
const scopeData = storeBuffers[creatorOrScope];
|
|
16029
|
-
buffers = scopeData && !isBufferLike(scopeData) ? scopeData : {};
|
|
16030
|
-
}
|
|
16031
|
-
return { ...buffers, removeBuffers, clearBuffers, rebuildBuffers, disposeBuffers };
|
|
16032
|
-
}
|
|
16033
|
-
function rebuildAllBuffers(store, scope) {
|
|
16034
|
-
rebuildResource(store, "buffers", scope);
|
|
16035
|
-
}
|
|
16036
|
-
|
|
16037
|
-
const disposeStorage = (storage) => {
|
|
16038
|
-
if (storage === null || typeof storage !== "object") return;
|
|
16039
|
-
if ("dispose" in storage && typeof storage.dispose === "function") {
|
|
16040
|
-
storage.dispose();
|
|
16041
|
-
}
|
|
16042
|
-
};
|
|
16043
|
-
function useGPUStorage(creatorOrScope, scope) {
|
|
16044
|
-
const store = usePrimaryStore();
|
|
16045
|
-
const removeStorage = React.useCallback(
|
|
16046
|
-
(names, targetScope) => removeResourceEntries(store, "gpuStorage", Array.isArray(names) ? names : [names], targetScope, isStorageLike),
|
|
16047
|
-
[store]
|
|
16048
|
-
);
|
|
16049
|
-
const clearStorage = React.useCallback(
|
|
16050
|
-
(targetScope) => clearResourceEntries(store, "gpuStorage", targetScope, isStorageLike),
|
|
16051
|
-
[store]
|
|
16052
|
-
);
|
|
16053
|
-
const rebuildStorage = React.useCallback(
|
|
16054
|
-
(targetScope) => rebuildResource(store, "gpuStorage", targetScope),
|
|
16055
|
-
[store]
|
|
16056
|
-
);
|
|
16057
|
-
const disposeStorageFn = React.useCallback(
|
|
16058
|
-
(names, targetScope) => {
|
|
16059
|
-
const nameArray = Array.isArray(names) ? names : [names];
|
|
16060
|
-
const state = store.getState();
|
|
16061
|
-
for (const name of nameArray) {
|
|
16062
|
-
const storage = targetScope ? state.gpuStorage[targetScope]?.[name] : state.gpuStorage[name];
|
|
16063
|
-
if (storage && isStorageLike(storage)) {
|
|
16064
|
-
disposeStorage(storage);
|
|
16065
|
-
}
|
|
16066
|
-
}
|
|
16067
|
-
removeStorage(names, targetScope);
|
|
16068
|
-
},
|
|
16069
|
-
[store, removeStorage]
|
|
16070
|
-
);
|
|
16071
|
-
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
16072
|
-
const storeStorage = usePrimaryThree((s) => s.gpuStorage);
|
|
16073
|
-
const created = useScopedResource({
|
|
16074
|
-
store,
|
|
16075
|
-
kind: "gpuStorage",
|
|
16076
|
-
scope: isReader ? void 0 : scope,
|
|
16077
|
-
isLeaf: isStorageLike,
|
|
16078
|
-
create: () => {
|
|
16079
|
-
if (isReader) return {};
|
|
16080
|
-
return creatorOrScope(createLazyCreatorState(store.getState(), store));
|
|
16081
|
-
},
|
|
16082
|
-
prepare: (name, storage) => {
|
|
16083
|
-
const label = scopedNodeName(scope, name);
|
|
16084
|
-
const setName = Reflect.get(storage, "setName");
|
|
16085
|
-
if (typeof setName === "function") setName.call(storage, label);
|
|
16086
|
-
if ("name" in storage && typeof storage.name === "string") {
|
|
16087
|
-
storage.name = label;
|
|
16088
|
-
}
|
|
16089
|
-
return storage;
|
|
16090
|
-
}
|
|
16091
|
-
});
|
|
16092
|
-
let gpuStorage = created;
|
|
16093
|
-
if (creatorOrScope === void 0) {
|
|
16094
|
-
gpuStorage = storeStorage;
|
|
16095
|
-
} else if (typeof creatorOrScope === "string") {
|
|
16096
|
-
const scopeData = storeStorage[creatorOrScope];
|
|
16097
|
-
gpuStorage = scopeData && !isStorageLike(scopeData) ? scopeData : {};
|
|
16098
|
-
}
|
|
16099
|
-
return {
|
|
16100
|
-
...gpuStorage,
|
|
16101
|
-
removeStorage,
|
|
16102
|
-
clearStorage,
|
|
16103
|
-
rebuildStorage,
|
|
16104
|
-
disposeStorage: disposeStorageFn
|
|
16105
|
-
};
|
|
16106
|
-
}
|
|
16107
|
-
function rebuildAllStorage(store, scope) {
|
|
16108
|
-
rebuildResource(store, "gpuStorage", scope);
|
|
16109
|
-
}
|
|
16110
|
-
|
|
16111
15320
|
function addTexture(set, key, value) {
|
|
16112
15321
|
set((state) => {
|
|
16113
15322
|
const newMap = new Map(state.textures);
|
|
@@ -16148,127 +15357,6 @@ function createTextureOperations(set) {
|
|
|
16148
15357
|
};
|
|
16149
15358
|
}
|
|
16150
15359
|
|
|
16151
|
-
function renderThroughPipeline(store) {
|
|
16152
|
-
return () => {
|
|
16153
|
-
const pipeline = store.getState().renderPipeline;
|
|
16154
|
-
if (pipeline?.render) pipeline.render();
|
|
16155
|
-
};
|
|
16156
|
-
}
|
|
16157
|
-
function useRenderPipeline(mainCB, setupCB) {
|
|
16158
|
-
const store = useStore();
|
|
16159
|
-
const { scene, camera, renderer, isLegacy } = useThree$1();
|
|
16160
|
-
const callbacksRanRef = React.useRef(false);
|
|
16161
|
-
const scenePassCacheRef = React.useRef(null);
|
|
16162
|
-
const forceScenePassRebuildRef = React.useRef(false);
|
|
16163
|
-
const mainCBRef = React.useRef(mainCB);
|
|
16164
|
-
const setupCBRef = React.useRef(setupCB);
|
|
16165
|
-
mainCBRef.current = mainCB;
|
|
16166
|
-
setupCBRef.current = setupCB;
|
|
16167
|
-
const [rebuildVersion, setRebuildVersion] = React.useState(0);
|
|
16168
|
-
React.useEffect(() => {
|
|
16169
|
-
callbacksRanRef.current = false;
|
|
16170
|
-
forceScenePassRebuildRef.current = true;
|
|
16171
|
-
}, []);
|
|
16172
|
-
const clearPasses = React.useCallback(() => {
|
|
16173
|
-
store.setState({ passes: {} });
|
|
16174
|
-
}, [store]);
|
|
16175
|
-
const reset = React.useCallback(() => {
|
|
16176
|
-
store.setState({
|
|
16177
|
-
renderPipeline: null,
|
|
16178
|
-
passes: {}
|
|
16179
|
-
});
|
|
16180
|
-
setRenderOverride(store, null);
|
|
16181
|
-
scenePassCacheRef.current?.scenePass.dispose();
|
|
16182
|
-
callbacksRanRef.current = false;
|
|
16183
|
-
scenePassCacheRef.current = null;
|
|
16184
|
-
forceScenePassRebuildRef.current = false;
|
|
16185
|
-
}, [store]);
|
|
16186
|
-
const rebuild = React.useCallback(() => {
|
|
16187
|
-
callbacksRanRef.current = false;
|
|
16188
|
-
forceScenePassRebuildRef.current = true;
|
|
16189
|
-
setRebuildVersion((v) => v + 1);
|
|
16190
|
-
}, []);
|
|
16191
|
-
React.useLayoutEffect(() => {
|
|
16192
|
-
if (isLegacy) {
|
|
16193
|
-
throw new Error("useRenderPipeline is only available with WebGPU renderer. Set renderer prop on Canvas.");
|
|
16194
|
-
}
|
|
16195
|
-
if (!renderer || !scene || !camera) return;
|
|
16196
|
-
if (!("isWebGPURenderer" in renderer)) {
|
|
16197
|
-
throw new Error("useRenderPipeline: renderer is not a WebGPURenderer but isLegacy is false.");
|
|
16198
|
-
}
|
|
16199
|
-
const state = store.getState();
|
|
16200
|
-
const set = store.setState;
|
|
16201
|
-
try {
|
|
16202
|
-
let pipeline = state.renderPipeline;
|
|
16203
|
-
let currentPasses = { ...state.passes };
|
|
16204
|
-
let justCreatedPipeline = false;
|
|
16205
|
-
if (!pipeline) {
|
|
16206
|
-
pipeline = new webgpu.RenderPipeline(renderer);
|
|
16207
|
-
justCreatedPipeline = true;
|
|
16208
|
-
}
|
|
16209
|
-
const cacheValid = !forceScenePassRebuildRef.current && scenePassCacheRef.current && scenePassCacheRef.current.sceneUuid === scene.uuid && scenePassCacheRef.current.cameraUuid === camera.uuid;
|
|
16210
|
-
let outgoingScenePass = null;
|
|
16211
|
-
let scenePass;
|
|
16212
|
-
if (cacheValid) {
|
|
16213
|
-
scenePass = scenePassCacheRef.current.scenePass;
|
|
16214
|
-
} else {
|
|
16215
|
-
outgoingScenePass = scenePassCacheRef.current?.scenePass ?? null;
|
|
16216
|
-
scenePass = tsl.pass(scene, camera);
|
|
16217
|
-
scenePassCacheRef.current = { sceneUuid: scene.uuid, cameraUuid: camera.uuid, scenePass };
|
|
16218
|
-
forceScenePassRebuildRef.current = false;
|
|
16219
|
-
}
|
|
16220
|
-
currentPasses.scenePass = scenePass;
|
|
16221
|
-
let outputNodeChanged = false;
|
|
16222
|
-
if (!pipeline.outputNode || justCreatedPipeline || pipeline.outputNode === outgoingScenePass) {
|
|
16223
|
-
pipeline.outputNode = scenePass;
|
|
16224
|
-
outputNodeChanged = true;
|
|
16225
|
-
}
|
|
16226
|
-
set({ renderPipeline: pipeline, passes: currentPasses });
|
|
16227
|
-
setRenderOverride(store, renderThroughPipeline(store));
|
|
16228
|
-
const shouldRunCallbacks = justCreatedPipeline || !callbacksRanRef.current || !cacheValid;
|
|
16229
|
-
if (shouldRunCallbacks) {
|
|
16230
|
-
if (setupCBRef.current) {
|
|
16231
|
-
const freshState = Object.assign({}, store.getState(), {
|
|
16232
|
-
renderPipeline: pipeline,
|
|
16233
|
-
passes: { ...currentPasses, scenePass },
|
|
16234
|
-
renderer,
|
|
16235
|
-
isLegacy: false
|
|
16236
|
-
});
|
|
16237
|
-
const setupResult = setupCBRef.current(freshState);
|
|
16238
|
-
if (setupResult && typeof setupResult === "object") {
|
|
16239
|
-
currentPasses = { ...currentPasses, ...setupResult };
|
|
16240
|
-
set({ passes: currentPasses });
|
|
16241
|
-
}
|
|
16242
|
-
}
|
|
16243
|
-
if (mainCBRef.current) {
|
|
16244
|
-
const freshState = Object.assign({}, store.getState(), {
|
|
16245
|
-
renderPipeline: pipeline,
|
|
16246
|
-
passes: { ...currentPasses, scenePass },
|
|
16247
|
-
renderer,
|
|
16248
|
-
isLegacy: false
|
|
16249
|
-
});
|
|
16250
|
-
const mainResult = mainCBRef.current(freshState);
|
|
16251
|
-
if (mainResult && typeof mainResult === "object") {
|
|
16252
|
-
currentPasses = { ...currentPasses, ...mainResult };
|
|
16253
|
-
set({ passes: currentPasses });
|
|
16254
|
-
}
|
|
16255
|
-
}
|
|
16256
|
-
outputNodeChanged = true;
|
|
16257
|
-
callbacksRanRef.current = true;
|
|
16258
|
-
}
|
|
16259
|
-
if (outputNodeChanged) pipeline.needsUpdate = true;
|
|
16260
|
-
if (outgoingScenePass && outgoingScenePass !== scenePass) outgoingScenePass.dispose();
|
|
16261
|
-
} catch (error) {
|
|
16262
|
-
console.warn("[useRenderPipeline] Setup failed; the render pipeline was not configured:", error);
|
|
16263
|
-
}
|
|
16264
|
-
}, [store, renderer, scene, camera, isLegacy, rebuildVersion]);
|
|
16265
|
-
const passes = useThree$1((s) => s.passes);
|
|
16266
|
-
const renderPipeline = useThree$1((s) => s.renderPipeline);
|
|
16267
|
-
const actions = { passes, clearPasses, reset, rebuild };
|
|
16268
|
-
if (renderPipeline) return { ...actions, isReady: true, renderPipeline };
|
|
16269
|
-
return { ...actions, isReady: false, renderPipeline: null };
|
|
16270
|
-
}
|
|
16271
|
-
|
|
16272
15360
|
extend(THREE);
|
|
16273
15361
|
const useThree = useThree$1;
|
|
16274
15362
|
const useFrame = useFrame$1;
|
|
@@ -16301,16 +15389,11 @@ exports.applyProps = applyProps;
|
|
|
16301
15389
|
exports.attach = attach;
|
|
16302
15390
|
exports.buildGraph = buildGraph;
|
|
16303
15391
|
exports.calculateDpr = calculateDpr;
|
|
16304
|
-
exports.clearNodeScope = clearNodeScope;
|
|
16305
|
-
exports.clearRootNodes = clearRootNodes;
|
|
16306
|
-
exports.clearRootUniforms = clearRootUniforms;
|
|
16307
|
-
exports.clearScope = clearScope;
|
|
16308
15392
|
exports.context = context;
|
|
16309
15393
|
exports.createEvents = createEvents;
|
|
16310
15394
|
exports.createPointerEvents = createPointerEvents;
|
|
16311
15395
|
exports.createPortal = createPortal;
|
|
16312
15396
|
exports.createRoot = createRoot;
|
|
16313
|
-
exports.createScopedStore = createScopedStore;
|
|
16314
15397
|
exports.createStore = createStore;
|
|
16315
15398
|
exports.createTextureOperations = createTextureOperations;
|
|
16316
15399
|
exports.detach = detach;
|
|
@@ -16344,16 +15427,10 @@ exports.isVectorLike = isVectorLike;
|
|
|
16344
15427
|
exports.once = once;
|
|
16345
15428
|
exports.prepare = prepare;
|
|
16346
15429
|
exports.presetsObj = presetsObj;
|
|
16347
|
-
exports.rebuildAllBuffers = rebuildAllBuffers;
|
|
16348
|
-
exports.rebuildAllNodes = rebuildAllNodes;
|
|
16349
|
-
exports.rebuildAllStorage = rebuildAllStorage;
|
|
16350
|
-
exports.rebuildAllUniforms = rebuildAllUniforms;
|
|
16351
15430
|
exports.reconciler = reconciler;
|
|
16352
15431
|
exports.registerPrimary = registerPrimary;
|
|
16353
15432
|
exports.registerRootExtension = registerRootExtension;
|
|
16354
15433
|
exports.removeInteractivity = removeInteractivity;
|
|
16355
|
-
exports.removeNodes = removeNodes;
|
|
16356
|
-
exports.removeUniforms = removeUniforms;
|
|
16357
15434
|
exports.resolve = resolve;
|
|
16358
15435
|
exports.setRenderOverride = setRenderOverride;
|
|
16359
15436
|
exports.swapInteractivity = swapInteractivity;
|
|
@@ -16362,23 +15439,16 @@ exports.unregisterPrimary = unregisterPrimary;
|
|
|
16362
15439
|
exports.updateCamera = updateCamera;
|
|
16363
15440
|
exports.updateFrustum = updateFrustum;
|
|
16364
15441
|
exports.useBridge = useBridge;
|
|
16365
|
-
exports.useBuffers = useBuffers;
|
|
16366
15442
|
exports.useEnvironment = useEnvironment;
|
|
16367
15443
|
exports.useFrame = useFrame;
|
|
16368
|
-
exports.useGPUStorage = useGPUStorage;
|
|
16369
15444
|
exports.useGraph = useGraph;
|
|
16370
15445
|
exports.useInstanceHandle = useInstanceHandle;
|
|
16371
15446
|
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
|
|
16372
15447
|
exports.useLoader = useLoader;
|
|
16373
|
-
exports.useLocalNodes = useLocalNodes;
|
|
16374
15448
|
exports.useMutableCallback = useMutableCallback;
|
|
16375
|
-
exports.useNodes = useNodes;
|
|
16376
|
-
exports.useRenderPipeline = useRenderPipeline;
|
|
16377
15449
|
exports.useRenderTarget = useRenderTarget;
|
|
16378
15450
|
exports.useStore = useStore;
|
|
16379
15451
|
exports.useTexture = useTexture;
|
|
16380
15452
|
exports.useTextures = useTextures;
|
|
16381
15453
|
exports.useThree = useThree;
|
|
16382
|
-
exports.useUniform = useUniform;
|
|
16383
|
-
exports.useUniforms = useUniforms;
|
|
16384
15454
|
exports.waitForPrimary = waitForPrimary;
|