@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.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as webgpu from 'three/webgpu';
|
|
2
|
-
import { CubeRenderTarget, RenderTarget, Frustum, Matrix4, Group, BoxGeometry, MeshBasicNodeMaterial, Mesh, Node, NodeUpdateType, Layers, ShaderMaterial, Uniform, SRGBColorSpace, RGBAFormat, UnsignedByteType, TextureLoader, Texture as Texture$1, CubeReflectionMapping, EquirectangularReflectionMapping, CubeTextureLoader, Vector3, Vector2, CanvasTarget, Raycaster, OrthographicCamera, PerspectiveCamera, Scene, PCFShadowMap, VSMShadowMap, BasicShadowMap, ACESFilmicToneMapping, WebGPURenderer, HalfFloatType, Color
|
|
2
|
+
import { CubeRenderTarget, RenderTarget, Frustum, Matrix4, Group, BoxGeometry, MeshBasicNodeMaterial, Mesh, Node, NodeUpdateType, Layers, ShaderMaterial, Uniform, SRGBColorSpace, RGBAFormat, UnsignedByteType, TextureLoader, Texture as Texture$1, CubeReflectionMapping, EquirectangularReflectionMapping, CubeTextureLoader, Vector3, Vector2, CanvasTarget, Raycaster, OrthographicCamera, PerspectiveCamera, Scene, PCFShadowMap, VSMShadowMap, BasicShadowMap, ACESFilmicToneMapping, WebGPURenderer, HalfFloatType, Color } from 'three/webgpu';
|
|
3
3
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import React__default, { useContext, useRef, useMemo, useLayoutEffect, useEffect, useImperativeHandle, useCallback, useState } from 'react';
|
|
@@ -16,9 +16,6 @@ import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js';
|
|
|
16
16
|
import { UltraHDRLoader } from 'three/examples/jsm/loaders/UltraHDRLoader.js';
|
|
17
17
|
import { GainMapLoader } from '@monogrid/gainmap-js';
|
|
18
18
|
import { suspend, preload, clear } from 'suspend-react';
|
|
19
|
-
import { dequal } from 'dequal/lite';
|
|
20
|
-
import 'zustand/shallow';
|
|
21
|
-
import { uniform, pass } from 'three/tsl';
|
|
22
19
|
|
|
23
20
|
function _mergeNamespaces(n, m) {
|
|
24
21
|
for (var i = 0; i < m.length; i++) {
|
|
@@ -118,9 +115,9 @@ function getPrimaryIds() {
|
|
|
118
115
|
return Array.from(primaryRegistry.keys());
|
|
119
116
|
}
|
|
120
117
|
|
|
121
|
-
var __defProp
|
|
122
|
-
var __defNormalProp
|
|
123
|
-
var __publicField
|
|
118
|
+
var __defProp = Object.defineProperty;
|
|
119
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
120
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
124
121
|
const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React.useLayoutEffect : React.useEffect;
|
|
125
122
|
function useMutableCallback(fn) {
|
|
126
123
|
const ref = React.useRef(fn);
|
|
@@ -151,7 +148,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
151
148
|
return _a = class extends React.Component {
|
|
152
149
|
constructor() {
|
|
153
150
|
super(...arguments);
|
|
154
|
-
__publicField
|
|
151
|
+
__publicField(this, "state", { error: false });
|
|
155
152
|
}
|
|
156
153
|
componentDidCatch(err) {
|
|
157
154
|
this.props.set(err);
|
|
@@ -159,7 +156,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
159
156
|
render() {
|
|
160
157
|
return this.state.error ? null : this.props.children;
|
|
161
158
|
}
|
|
162
|
-
}, __publicField
|
|
159
|
+
}, __publicField(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
163
160
|
})();
|
|
164
161
|
|
|
165
162
|
const is = {
|
|
@@ -1444,9 +1441,9 @@ const packageData = {
|
|
|
1444
1441
|
function Xb(Tt) {
|
|
1445
1442
|
return Tt && Tt.__esModule && Object.prototype.hasOwnProperty.call(Tt, "default") ? Tt.default : Tt;
|
|
1446
1443
|
}
|
|
1447
|
-
var Rm = { exports: {} }, Og = { exports: {} }, _b
|
|
1444
|
+
var Rm = { exports: {} }, Og = { exports: {} }, _b;
|
|
1448
1445
|
function Kb() {
|
|
1449
|
-
return _b
|
|
1446
|
+
return _b || (_b = 1, (function(Tt) {
|
|
1450
1447
|
Tt.exports = function(m) {
|
|
1451
1448
|
function Yn(t, r, a, l) {
|
|
1452
1449
|
return new uc(t, r, a, l);
|
|
@@ -13961,16 +13958,10 @@ const createStore = (invalidate, advance) => {
|
|
|
13961
13958
|
},
|
|
13962
13959
|
setError: (error) => set(() => ({ error })),
|
|
13963
13960
|
error: null,
|
|
13964
|
-
//*
|
|
13965
|
-
uniforms
|
|
13966
|
-
nodes: {},
|
|
13967
|
-
buffers: {},
|
|
13968
|
-
gpuStorage: {},
|
|
13961
|
+
//* Texture registry (useTextures) ==============================
|
|
13962
|
+
// TSL fields (uniforms, nodes, ..., renderPipeline) are added by @react-three/tsl's root extension.
|
|
13969
13963
|
textures: /* @__PURE__ */ new Map(),
|
|
13970
13964
|
_textureRefs: /* @__PURE__ */ new Map(),
|
|
13971
|
-
renderPipeline: null,
|
|
13972
|
-
passes: {},
|
|
13973
|
-
_hmrVersion: 0,
|
|
13974
13965
|
_sizeImperative: false,
|
|
13975
13966
|
_sizeProps: null,
|
|
13976
13967
|
previousRoot: void 0,
|
|
@@ -15306,788 +15297,6 @@ function Canvas$1(props) {
|
|
|
15306
15297
|
return /* @__PURE__ */ jsx(FiberProvider, { children: /* @__PURE__ */ jsx(CanvasImpl, { ...props }) });
|
|
15307
15298
|
}
|
|
15308
15299
|
|
|
15309
|
-
const RESOURCE_KINDS = ["nodes", "uniforms", "buffers", "gpuStorage"];
|
|
15310
|
-
const ROOT_SCOPE = "";
|
|
15311
|
-
const registries = /* @__PURE__ */ new WeakMap();
|
|
15312
|
-
function getKindRegistry(store, kind) {
|
|
15313
|
-
let registry = registries.get(store);
|
|
15314
|
-
if (!registry) {
|
|
15315
|
-
registry = {
|
|
15316
|
-
nodes: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
15317
|
-
uniforms: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
15318
|
-
buffers: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
15319
|
-
gpuStorage: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() }
|
|
15320
|
-
};
|
|
15321
|
-
registries.set(store, registry);
|
|
15322
|
-
}
|
|
15323
|
-
return registry[kind];
|
|
15324
|
-
}
|
|
15325
|
-
function resolvePrimary$1(store) {
|
|
15326
|
-
return store.getState().primaryStore ?? store;
|
|
15327
|
-
}
|
|
15328
|
-
function isScopeValid(store, kind, scopeKey) {
|
|
15329
|
-
return getKindRegistry(store, kind).valid.has(scopeKey);
|
|
15330
|
-
}
|
|
15331
|
-
function peekStaged(store, kind, scopeKey) {
|
|
15332
|
-
return getKindRegistry(store, kind).staged.get(scopeKey);
|
|
15333
|
-
}
|
|
15334
|
-
function stageEntries(store, kind, scopeKey, entries) {
|
|
15335
|
-
const { staged } = getKindRegistry(store, kind);
|
|
15336
|
-
const current = staged.get(scopeKey);
|
|
15337
|
-
if (current) Object.assign(current, entries);
|
|
15338
|
-
else staged.set(scopeKey, { ...entries });
|
|
15339
|
-
}
|
|
15340
|
-
function readCommittedScope(map, scopeKey, isLeaf) {
|
|
15341
|
-
if (scopeKey === ROOT_SCOPE) {
|
|
15342
|
-
const leaves = {};
|
|
15343
|
-
for (const [key, value] of Object.entries(map)) if (isLeaf(value)) leaves[key] = value;
|
|
15344
|
-
return leaves;
|
|
15345
|
-
}
|
|
15346
|
-
const scopeData = map[scopeKey];
|
|
15347
|
-
if (scopeData && typeof scopeData === "object" && !isLeaf(scopeData)) return scopeData;
|
|
15348
|
-
return {};
|
|
15349
|
-
}
|
|
15350
|
-
function withStagedOverlay(store, kind, committed) {
|
|
15351
|
-
const { staged } = getKindRegistry(store, kind);
|
|
15352
|
-
if (staged.size === 0) return committed;
|
|
15353
|
-
const view = { ...committed };
|
|
15354
|
-
for (const [scopeKey, entries] of staged) {
|
|
15355
|
-
if (scopeKey === ROOT_SCOPE) Object.assign(view, entries);
|
|
15356
|
-
else view[scopeKey] = { ...view[scopeKey], ...entries };
|
|
15357
|
-
}
|
|
15358
|
-
return view;
|
|
15359
|
-
}
|
|
15360
|
-
function flushStagedScope(store, kind, scopeKey, isLeaf) {
|
|
15361
|
-
const registry = getKindRegistry(store, kind);
|
|
15362
|
-
const staged = registry.staged.get(scopeKey);
|
|
15363
|
-
if (!staged) return;
|
|
15364
|
-
registry.staged.delete(scopeKey);
|
|
15365
|
-
const replace = !registry.valid.has(scopeKey);
|
|
15366
|
-
store.setState((state) => {
|
|
15367
|
-
const map = state[kind];
|
|
15368
|
-
if (scopeKey === ROOT_SCOPE) {
|
|
15369
|
-
if (!replace) return { [kind]: { ...map, ...staged } };
|
|
15370
|
-
const next = {};
|
|
15371
|
-
for (const [key, value] of Object.entries(map)) if (!isLeaf(value)) next[key] = value;
|
|
15372
|
-
return { [kind]: { ...next, ...staged } };
|
|
15373
|
-
}
|
|
15374
|
-
const current = replace ? {} : map[scopeKey] ?? {};
|
|
15375
|
-
return { [kind]: { ...map, [scopeKey]: { ...current, ...staged } } };
|
|
15376
|
-
});
|
|
15377
|
-
registry.valid.add(scopeKey);
|
|
15378
|
-
}
|
|
15379
|
-
function invalidateResource(store, kind, scopeKey) {
|
|
15380
|
-
const registry = getKindRegistry(store, kind);
|
|
15381
|
-
if (scopeKey === void 0) {
|
|
15382
|
-
registry.valid.clear();
|
|
15383
|
-
registry.staged.clear();
|
|
15384
|
-
} else {
|
|
15385
|
-
registry.valid.delete(scopeKey);
|
|
15386
|
-
registry.staged.delete(scopeKey);
|
|
15387
|
-
}
|
|
15388
|
-
}
|
|
15389
|
-
function rebuildResource(store, kind, userScope) {
|
|
15390
|
-
const primary = resolvePrimary$1(store);
|
|
15391
|
-
invalidateResource(primary, kind, userScope === "root" ? ROOT_SCOPE : userScope);
|
|
15392
|
-
primary.setState((state) => ({ _hmrVersion: state._hmrVersion + 1 }));
|
|
15393
|
-
}
|
|
15394
|
-
function invalidateAllResources(store) {
|
|
15395
|
-
for (const kind of RESOURCE_KINDS) invalidateResource(store, kind);
|
|
15396
|
-
}
|
|
15397
|
-
function removeResourceEntries(store, kind, names, scope, isLeaf) {
|
|
15398
|
-
const staged = peekStaged(store, kind, scope ?? ROOT_SCOPE);
|
|
15399
|
-
if (staged) for (const name of names) delete staged[name];
|
|
15400
|
-
store.setState((state) => {
|
|
15401
|
-
const map = state[kind];
|
|
15402
|
-
if (scope) {
|
|
15403
|
-
const currentScope = { ...map[scope] };
|
|
15404
|
-
for (const name of names) delete currentScope[name];
|
|
15405
|
-
return { [kind]: { ...map, [scope]: currentScope } };
|
|
15406
|
-
}
|
|
15407
|
-
const next = { ...map };
|
|
15408
|
-
for (const name of names) if (isLeaf(next[name])) delete next[name];
|
|
15409
|
-
return { [kind]: next };
|
|
15410
|
-
});
|
|
15411
|
-
}
|
|
15412
|
-
function clearResourceEntries(store, kind, scope, isLeaf) {
|
|
15413
|
-
const registry = getKindRegistry(store, kind);
|
|
15414
|
-
if (scope && scope !== "root") registry.staged.delete(scope);
|
|
15415
|
-
else if (scope === "root") registry.staged.delete(ROOT_SCOPE);
|
|
15416
|
-
else registry.staged.clear();
|
|
15417
|
-
store.setState((state) => {
|
|
15418
|
-
const map = state[kind];
|
|
15419
|
-
if (scope && scope !== "root") {
|
|
15420
|
-
const { [scope]: _, ...rest } = map;
|
|
15421
|
-
return { [kind]: rest };
|
|
15422
|
-
}
|
|
15423
|
-
if (scope === "root") {
|
|
15424
|
-
const next = {};
|
|
15425
|
-
for (const [key, value] of Object.entries(map)) if (!isLeaf(value)) next[key] = value;
|
|
15426
|
-
return { [kind]: next };
|
|
15427
|
-
}
|
|
15428
|
-
return { [kind]: {} };
|
|
15429
|
-
});
|
|
15430
|
-
}
|
|
15431
|
-
|
|
15432
|
-
const isObjectLike = (value) => value !== null && (typeof value === "object" || typeof value === "function");
|
|
15433
|
-
const hasValidLegacyNodeMarkers = (value) => {
|
|
15434
|
-
const hasUuid = "uuid" in value;
|
|
15435
|
-
const hasNodeType = "nodeType" in value;
|
|
15436
|
-
const uuid = Reflect.get(value, "uuid");
|
|
15437
|
-
const nodeType = Reflect.get(value, "nodeType");
|
|
15438
|
-
return (hasUuid || hasNodeType) && (!hasUuid || uuid === void 0 || typeof uuid === "string") && (!hasNodeType || nodeType === void 0 || nodeType === null || typeof nodeType === "string");
|
|
15439
|
-
};
|
|
15440
|
-
const isUniformNode = (value) => isObjectLike(value) && "isUniformNode" in value && value.isUniformNode === true;
|
|
15441
|
-
const isTSLNode = (value) => isObjectLike(value) && (Reflect.get(value, "isNode") === true || Reflect.get(value, "shaderNode") !== void 0 && typeof Reflect.get(value, "id") === "number" || hasValidLegacyNodeMarkers(value));
|
|
15442
|
-
const isBufferLike = (value) => ArrayBuffer.isView(value) && !(value instanceof DataView) || isObjectLike(value) && ("isBufferAttribute" in value || "isInterleavedBufferAttribute" in value || isTSLNode(value));
|
|
15443
|
-
const isStorageLike = (value) => isObjectLike(value) && ("isTexture" in value || "isData3DTexture" in value || isTSLNode(value));
|
|
15444
|
-
|
|
15445
|
-
var __defProp = Object.defineProperty;
|
|
15446
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
15447
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
15448
|
-
var _a, _b;
|
|
15449
|
-
const INTERNAL_DATA = Symbol("ScopedStore.data");
|
|
15450
|
-
const INTERNAL_IS_LEAF = Symbol("ScopedStore.isLeaf");
|
|
15451
|
-
_b = INTERNAL_DATA, _a = INTERNAL_IS_LEAF;
|
|
15452
|
-
const _ScopedStore = class _ScopedStore {
|
|
15453
|
-
constructor(data, isLeaf) {
|
|
15454
|
-
__publicField(this, _b);
|
|
15455
|
-
__publicField(this, _a);
|
|
15456
|
-
this[INTERNAL_DATA] = data;
|
|
15457
|
-
this[INTERNAL_IS_LEAF] = isLeaf;
|
|
15458
|
-
return new Proxy(this, {
|
|
15459
|
-
get(target, prop, receiver) {
|
|
15460
|
-
if (typeof prop === "string") {
|
|
15461
|
-
if (prop === "scope" || prop === "has" || prop === "keys") {
|
|
15462
|
-
return Reflect.get(target, prop, receiver);
|
|
15463
|
-
}
|
|
15464
|
-
return target[INTERNAL_DATA][prop];
|
|
15465
|
-
}
|
|
15466
|
-
return Reflect.get(target, prop, receiver);
|
|
15467
|
-
},
|
|
15468
|
-
has(target, prop) {
|
|
15469
|
-
return typeof prop === "string" ? prop in target[INTERNAL_DATA] : Reflect.has(target, prop);
|
|
15470
|
-
},
|
|
15471
|
-
ownKeys(target) {
|
|
15472
|
-
return Reflect.ownKeys(target[INTERNAL_DATA]);
|
|
15473
|
-
},
|
|
15474
|
-
getOwnPropertyDescriptor(target, prop) {
|
|
15475
|
-
if (typeof prop === "string" && prop in target[INTERNAL_DATA]) {
|
|
15476
|
-
return {
|
|
15477
|
-
configurable: true,
|
|
15478
|
-
enumerable: true,
|
|
15479
|
-
value: target[INTERNAL_DATA][prop]
|
|
15480
|
-
};
|
|
15481
|
-
}
|
|
15482
|
-
return void 0;
|
|
15483
|
-
}
|
|
15484
|
-
});
|
|
15485
|
-
}
|
|
15486
|
-
/**
|
|
15487
|
-
* Access a nested scope by key.
|
|
15488
|
-
* If the key doesn't exist or isn't a scope object, returns an empty ScopedStore.
|
|
15489
|
-
*/
|
|
15490
|
-
scope(key) {
|
|
15491
|
-
const value = this[INTERNAL_DATA][key];
|
|
15492
|
-
const isLeaf = this[INTERNAL_IS_LEAF];
|
|
15493
|
-
const scope = value && typeof value === "object" && !isLeaf(value) ? value : {};
|
|
15494
|
-
return new _ScopedStore(scope, isLeaf);
|
|
15495
|
-
}
|
|
15496
|
-
/**
|
|
15497
|
-
* Check if a key exists in the store.
|
|
15498
|
-
*/
|
|
15499
|
-
has(key) {
|
|
15500
|
-
return key in this[INTERNAL_DATA];
|
|
15501
|
-
}
|
|
15502
|
-
/**
|
|
15503
|
-
* Get all keys in the store.
|
|
15504
|
-
*/
|
|
15505
|
-
keys() {
|
|
15506
|
-
return Object.keys(this[INTERNAL_DATA]);
|
|
15507
|
-
}
|
|
15508
|
-
};
|
|
15509
|
-
let ScopedStore = _ScopedStore;
|
|
15510
|
-
function createScopedStore(data, isLeaf) {
|
|
15511
|
-
return new ScopedStore(data, isLeaf);
|
|
15512
|
-
}
|
|
15513
|
-
function createLazyCreatorState(state, store) {
|
|
15514
|
-
let _uniforms = null;
|
|
15515
|
-
let _nodes = null;
|
|
15516
|
-
let _buffers = null;
|
|
15517
|
-
let _gpuStorage = null;
|
|
15518
|
-
const view = (kind) => store ? withStagedOverlay(store, kind, state[kind]) : state[kind];
|
|
15519
|
-
return Object.create(state, {
|
|
15520
|
-
uniforms: {
|
|
15521
|
-
get() {
|
|
15522
|
-
return _uniforms ?? (_uniforms = createScopedStore(view("uniforms"), isUniformNode));
|
|
15523
|
-
}
|
|
15524
|
-
},
|
|
15525
|
-
nodes: {
|
|
15526
|
-
get() {
|
|
15527
|
-
return _nodes ?? (_nodes = createScopedStore(view("nodes"), isTSLNode));
|
|
15528
|
-
}
|
|
15529
|
-
},
|
|
15530
|
-
buffers: {
|
|
15531
|
-
get() {
|
|
15532
|
-
return _buffers ?? (_buffers = createScopedStore(view("buffers"), isBufferLike));
|
|
15533
|
-
}
|
|
15534
|
-
},
|
|
15535
|
-
gpuStorage: {
|
|
15536
|
-
get() {
|
|
15537
|
-
return _gpuStorage ?? (_gpuStorage = createScopedStore(view("gpuStorage"), isStorageLike));
|
|
15538
|
-
}
|
|
15539
|
-
}
|
|
15540
|
-
});
|
|
15541
|
-
}
|
|
15542
|
-
|
|
15543
|
-
function resolvePrimary(local) {
|
|
15544
|
-
return local.getState().primaryStore ?? local;
|
|
15545
|
-
}
|
|
15546
|
-
function usePrimaryStore() {
|
|
15547
|
-
const local = useStore();
|
|
15548
|
-
const primary = local.getState().primaryStore;
|
|
15549
|
-
return useMemo(() => primary ?? local, [primary, local]);
|
|
15550
|
-
}
|
|
15551
|
-
function usePrimaryThree(selector = (state) => state, equalityFn) {
|
|
15552
|
-
const local = useStore();
|
|
15553
|
-
const primary = resolvePrimary(local);
|
|
15554
|
-
return primary(selector, equalityFn);
|
|
15555
|
-
}
|
|
15556
|
-
|
|
15557
|
-
function scopedNodeName(scope, name) {
|
|
15558
|
-
const raw = scope ? `${scope}_${name}` : name;
|
|
15559
|
-
const safe = raw.replace(/[^A-Za-z0-9_]/g, "_");
|
|
15560
|
-
return /^[A-Za-z_]/.test(safe) ? safe : `_${safe}`;
|
|
15561
|
-
}
|
|
15562
|
-
function extractTSLValue(value) {
|
|
15563
|
-
if (value === null || value === void 0) return value;
|
|
15564
|
-
if (typeof value !== "object") return value;
|
|
15565
|
-
const node = value;
|
|
15566
|
-
if (!node.isNode) return value;
|
|
15567
|
-
if (node.isConstNode) {
|
|
15568
|
-
return node.value;
|
|
15569
|
-
}
|
|
15570
|
-
if ("value" in node) {
|
|
15571
|
-
let extractedValue = node.value;
|
|
15572
|
-
if (typeof node.traverse === "function") {
|
|
15573
|
-
node.traverse((n) => {
|
|
15574
|
-
if (n.isConstNode) {
|
|
15575
|
-
extractedValue = n.value;
|
|
15576
|
-
}
|
|
15577
|
-
});
|
|
15578
|
-
}
|
|
15579
|
-
return extractedValue;
|
|
15580
|
-
}
|
|
15581
|
-
return value;
|
|
15582
|
-
}
|
|
15583
|
-
function vectorize(inObject) {
|
|
15584
|
-
if (inObject === null || inObject === void 0) return inObject;
|
|
15585
|
-
if (typeof inObject === "string") {
|
|
15586
|
-
const isHexColor = /^(#|0x)[0-9a-f]{3,8}$/i.test(inObject);
|
|
15587
|
-
const isNamedColor = /^[a-z]+$/i.test(inObject);
|
|
15588
|
-
if (isHexColor || isNamedColor) {
|
|
15589
|
-
return new Color(inObject);
|
|
15590
|
-
}
|
|
15591
|
-
return inObject;
|
|
15592
|
-
}
|
|
15593
|
-
if (typeof inObject !== "object") return inObject;
|
|
15594
|
-
const obj = inObject;
|
|
15595
|
-
if (obj.isNode) {
|
|
15596
|
-
return extractTSLValue(inObject);
|
|
15597
|
-
}
|
|
15598
|
-
if (obj.isVector2 || obj.isVector3 || obj.isVector4) return inObject;
|
|
15599
|
-
if (obj.isMatrix2 || obj.isMatrix3 || obj.isMatrix4) return inObject;
|
|
15600
|
-
if (obj.isColor || obj.isEuler || obj.isQuaternion || obj.isSpherical) return inObject;
|
|
15601
|
-
if ("r" in obj && "g" in obj && "b" in obj && typeof obj.r === "number" && typeof obj.g === "number" && typeof obj.b === "number") {
|
|
15602
|
-
const scale = obj.r > 1 || obj.g > 1 || obj.b > 1 ? 1 / 255 : 1;
|
|
15603
|
-
return new Color(obj.r * scale, obj.g * scale, obj.b * scale);
|
|
15604
|
-
}
|
|
15605
|
-
if ("x" in obj && "y" in obj && typeof obj.x === "number" && typeof obj.y === "number") {
|
|
15606
|
-
if ("w" in obj && typeof obj.w === "number" && "z" in obj && typeof obj.z === "number") {
|
|
15607
|
-
return new Vector4(obj.x, obj.y, obj.z, obj.w);
|
|
15608
|
-
}
|
|
15609
|
-
if ("z" in obj && typeof obj.z === "number") {
|
|
15610
|
-
return new Vector3(obj.x, obj.y, obj.z);
|
|
15611
|
-
}
|
|
15612
|
-
return new Vector2(obj.x, obj.y);
|
|
15613
|
-
}
|
|
15614
|
-
return inObject;
|
|
15615
|
-
}
|
|
15616
|
-
|
|
15617
|
-
function useCompareMemoize(value, deep) {
|
|
15618
|
-
const ref = useRef(value);
|
|
15619
|
-
const compare = dequal ;
|
|
15620
|
-
if (!compare(value, ref.current)) {
|
|
15621
|
-
ref.current = value;
|
|
15622
|
-
}
|
|
15623
|
-
return ref.current;
|
|
15624
|
-
}
|
|
15625
|
-
|
|
15626
|
-
function clearHmrCaches(store) {
|
|
15627
|
-
const primary = store.getState().primaryStore ?? store;
|
|
15628
|
-
invalidateAllResources(primary);
|
|
15629
|
-
primary.setState((state) => ({ _hmrVersion: state._hmrVersion + 1 }));
|
|
15630
|
-
}
|
|
15631
|
-
|
|
15632
|
-
const SHARED_KEYS = ["uniforms", "nodes", "buffers", "gpuStorage", "_hmrVersion"];
|
|
15633
|
-
const following = /* @__PURE__ */ new WeakMap();
|
|
15634
|
-
function followPrimary(store) {
|
|
15635
|
-
const primary = store.getState().primaryStore;
|
|
15636
|
-
if (!primary || primary === store) return;
|
|
15637
|
-
const sync = () => {
|
|
15638
|
-
const source = primary.getState();
|
|
15639
|
-
const target = store.getState();
|
|
15640
|
-
let patch = null;
|
|
15641
|
-
for (const key of SHARED_KEYS) {
|
|
15642
|
-
if (target[key] !== source[key]) (patch ?? (patch = {}))[key] = source[key];
|
|
15643
|
-
}
|
|
15644
|
-
if (patch) store.setState(patch);
|
|
15645
|
-
};
|
|
15646
|
-
sync();
|
|
15647
|
-
following.set(store, primary.subscribe(sync));
|
|
15648
|
-
}
|
|
15649
|
-
function stopFollowing(store) {
|
|
15650
|
-
following.get(store)?.();
|
|
15651
|
-
following.delete(store);
|
|
15652
|
-
}
|
|
15653
|
-
let registered = false;
|
|
15654
|
-
function ensureTSLExtension() {
|
|
15655
|
-
if (registered) return;
|
|
15656
|
-
registered = true;
|
|
15657
|
-
registerRootExtension({
|
|
15658
|
-
name: "@react-three/tsl",
|
|
15659
|
-
setup: followPrimary,
|
|
15660
|
-
dispose: stopFollowing,
|
|
15661
|
-
// Resolves primaryStore itself, so every canvas sharing a renderer refreshes the same resources.
|
|
15662
|
-
hmr: clearHmrCaches
|
|
15663
|
-
});
|
|
15664
|
-
}
|
|
15665
|
-
|
|
15666
|
-
ensureTSLExtension();
|
|
15667
|
-
function useScopedResource(options) {
|
|
15668
|
-
const { store, kind, scope, isLeaf, create, prepare, reconcile, input } = options;
|
|
15669
|
-
const scopeKey = scope ?? ROOT_SCOPE;
|
|
15670
|
-
const version = store((s) => s._hmrVersion);
|
|
15671
|
-
const entries = useMemo(() => {
|
|
15672
|
-
const staged = peekStaged(store, kind, scopeKey);
|
|
15673
|
-
const reusable = isScopeValid(store, kind, scopeKey);
|
|
15674
|
-
const map = store.getState()[kind];
|
|
15675
|
-
const committed = reusable ? readCommittedScope(map, scopeKey, isLeaf) : void 0;
|
|
15676
|
-
const result = {};
|
|
15677
|
-
let fresh = null;
|
|
15678
|
-
for (const [name, candidate] of Object.entries(create())) {
|
|
15679
|
-
const existing = staged?.[name] ?? committed?.[name];
|
|
15680
|
-
if (existing !== void 0) {
|
|
15681
|
-
result[name] = existing;
|
|
15682
|
-
reconcile?.(existing, candidate);
|
|
15683
|
-
} else {
|
|
15684
|
-
const value = prepare ? prepare(name, candidate) : candidate;
|
|
15685
|
-
result[name] = value;
|
|
15686
|
-
(fresh ?? (fresh = {}))[name] = value;
|
|
15687
|
-
}
|
|
15688
|
-
}
|
|
15689
|
-
if (fresh) stageEntries(store, kind, scopeKey, fresh);
|
|
15690
|
-
return result;
|
|
15691
|
-
}, [store, kind, scopeKey, version, input]);
|
|
15692
|
-
useIsomorphicLayoutEffect(() => {
|
|
15693
|
-
flushStagedScope(store, kind, scopeKey, isLeaf);
|
|
15694
|
-
});
|
|
15695
|
-
return entries;
|
|
15696
|
-
}
|
|
15697
|
-
|
|
15698
|
-
function useUniforms(creatorOrScope, scope) {
|
|
15699
|
-
const store = usePrimaryStore();
|
|
15700
|
-
const removeUniforms2 = useCallback(
|
|
15701
|
-
(names, targetScope) => removeResourceEntries(store, "uniforms", Array.isArray(names) ? names : [names], targetScope, isUniformNode),
|
|
15702
|
-
[store]
|
|
15703
|
-
);
|
|
15704
|
-
const clearUniforms = useCallback(
|
|
15705
|
-
(targetScope) => clearResourceEntries(store, "uniforms", targetScope, isUniformNode),
|
|
15706
|
-
[store]
|
|
15707
|
-
);
|
|
15708
|
-
const rebuildUniforms = useCallback(
|
|
15709
|
-
(targetScope) => rebuildResource(store, "uniforms", targetScope),
|
|
15710
|
-
[store]
|
|
15711
|
-
);
|
|
15712
|
-
const processedInput = useMemo(() => {
|
|
15713
|
-
let raw = creatorOrScope;
|
|
15714
|
-
if (is.fun(creatorOrScope)) {
|
|
15715
|
-
const wrappedState = createLazyCreatorState(store.getState(), store);
|
|
15716
|
-
raw = creatorOrScope(wrappedState);
|
|
15717
|
-
}
|
|
15718
|
-
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
15719
|
-
const normalized = {};
|
|
15720
|
-
for (const [key, value] of Object.entries(raw)) {
|
|
15721
|
-
normalized[key] = vectorize(value);
|
|
15722
|
-
}
|
|
15723
|
-
return { candidates: raw, normalized };
|
|
15724
|
-
}
|
|
15725
|
-
return { candidates: raw, normalized: raw };
|
|
15726
|
-
}, [creatorOrScope, store]);
|
|
15727
|
-
const memoizedInput = useCompareMemoize(processedInput.normalized);
|
|
15728
|
-
const isReader = memoizedInput === void 0 || typeof memoizedInput === "string";
|
|
15729
|
-
const storeUniforms = usePrimaryThree((s) => s.uniforms);
|
|
15730
|
-
const created = useScopedResource({
|
|
15731
|
-
store,
|
|
15732
|
-
kind: "uniforms",
|
|
15733
|
-
scope: isReader ? void 0 : scope,
|
|
15734
|
-
isLeaf: isUniformNode,
|
|
15735
|
-
input: memoizedInput,
|
|
15736
|
-
create: () => {
|
|
15737
|
-
if (isReader) return {};
|
|
15738
|
-
if (typeof processedInput.candidates !== "object" || processedInput.candidates === null)
|
|
15739
|
-
throw new Error("Invalid uniform input");
|
|
15740
|
-
return processedInput.candidates;
|
|
15741
|
-
},
|
|
15742
|
-
prepare: (name, candidate) => createUniform(name, candidate, scope),
|
|
15743
|
-
reconcile: (existing, candidate) => {
|
|
15744
|
-
const existingVal = existing.value;
|
|
15745
|
-
const newVal = vectorize(candidate);
|
|
15746
|
-
let equals = newVal === existingVal;
|
|
15747
|
-
if (!equals && hasEqualsMethod(existingVal) && hasEqualsMethod(newVal)) {
|
|
15748
|
-
if (isThreeVector(existingVal) && isThreeVector(newVal)) {
|
|
15749
|
-
equals = vectorEquals(existingVal, newVal);
|
|
15750
|
-
} else if (isSameThreeType(existingVal, newVal)) {
|
|
15751
|
-
equals = existingVal.equals(newVal);
|
|
15752
|
-
}
|
|
15753
|
-
}
|
|
15754
|
-
if (!equals) existing.value = newVal;
|
|
15755
|
-
}
|
|
15756
|
-
});
|
|
15757
|
-
let uniforms = created;
|
|
15758
|
-
if (memoizedInput === void 0) {
|
|
15759
|
-
uniforms = storeUniforms;
|
|
15760
|
-
} else if (typeof memoizedInput === "string") {
|
|
15761
|
-
const scopeData = storeUniforms[memoizedInput];
|
|
15762
|
-
uniforms = scopeData && !isUniformNode(scopeData) ? scopeData : {};
|
|
15763
|
-
}
|
|
15764
|
-
return { ...uniforms, removeUniforms: removeUniforms2, clearUniforms, rebuildUniforms };
|
|
15765
|
-
}
|
|
15766
|
-
function rebuildAllUniforms(store, scope) {
|
|
15767
|
-
rebuildResource(store, "uniforms", scope);
|
|
15768
|
-
}
|
|
15769
|
-
function removeUniforms(set, names, scope) {
|
|
15770
|
-
set((state) => {
|
|
15771
|
-
if (scope) {
|
|
15772
|
-
const currentScope = { ...state.uniforms[scope] };
|
|
15773
|
-
for (const name of names) delete currentScope[name];
|
|
15774
|
-
return { uniforms: { ...state.uniforms, [scope]: currentScope } };
|
|
15775
|
-
}
|
|
15776
|
-
const uniforms = { ...state.uniforms };
|
|
15777
|
-
for (const name of names) if (isUniformNode(uniforms[name])) delete uniforms[name];
|
|
15778
|
-
return { uniforms };
|
|
15779
|
-
});
|
|
15780
|
-
}
|
|
15781
|
-
function clearScope(set, scope) {
|
|
15782
|
-
set((state) => {
|
|
15783
|
-
const { [scope]: _, ...rest } = state.uniforms;
|
|
15784
|
-
return { uniforms: rest };
|
|
15785
|
-
});
|
|
15786
|
-
}
|
|
15787
|
-
function clearRootUniforms(set) {
|
|
15788
|
-
set((state) => {
|
|
15789
|
-
const uniforms = {};
|
|
15790
|
-
for (const [key, value] of Object.entries(state.uniforms)) {
|
|
15791
|
-
if (!isUniformNode(value)) uniforms[key] = value;
|
|
15792
|
-
}
|
|
15793
|
-
return { uniforms };
|
|
15794
|
-
});
|
|
15795
|
-
}
|
|
15796
|
-
function createUniform(inName, node, scope) {
|
|
15797
|
-
if (node.type === "UniformNode") return node;
|
|
15798
|
-
const inValue = vectorize(node);
|
|
15799
|
-
const newUniform = uniform(inValue);
|
|
15800
|
-
if (typeof newUniform.setName === "function") {
|
|
15801
|
-
newUniform.setName(scopedNodeName(scope, inName));
|
|
15802
|
-
}
|
|
15803
|
-
return newUniform;
|
|
15804
|
-
}
|
|
15805
|
-
function isThreeVector(inVector) {
|
|
15806
|
-
if (!inVector) return false;
|
|
15807
|
-
return inVector.isVector2 || inVector.isVector3 || inVector.isVector4;
|
|
15808
|
-
}
|
|
15809
|
-
function vectorEquals(a, b) {
|
|
15810
|
-
if (a.isVector2 && b.isVector2) {
|
|
15811
|
-
return a.equals(b);
|
|
15812
|
-
}
|
|
15813
|
-
if (a.isVector3 && b.isVector3) {
|
|
15814
|
-
return a.equals(b);
|
|
15815
|
-
}
|
|
15816
|
-
if (a.isVector4 && b.isVector4) {
|
|
15817
|
-
return a.equals(b);
|
|
15818
|
-
}
|
|
15819
|
-
return false;
|
|
15820
|
-
}
|
|
15821
|
-
function hasEqualsMethod(value) {
|
|
15822
|
-
return value !== null && typeof value === "object" && "equals" in value && typeof value.equals === "function";
|
|
15823
|
-
}
|
|
15824
|
-
function isSameThreeType(a, b) {
|
|
15825
|
-
const obj_a = a;
|
|
15826
|
-
const obj_b = b;
|
|
15827
|
-
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;
|
|
15828
|
-
}
|
|
15829
|
-
|
|
15830
|
-
const uniformOf = uniform;
|
|
15831
|
-
function useUniform(name, value) {
|
|
15832
|
-
const store = usePrimaryStore();
|
|
15833
|
-
const registered = useScopedResource({
|
|
15834
|
-
store,
|
|
15835
|
-
kind: "uniforms",
|
|
15836
|
-
scope: void 0,
|
|
15837
|
-
isLeaf: isUniformNode,
|
|
15838
|
-
input: name,
|
|
15839
|
-
create: () => value === void 0 ? {} : { [name]: value },
|
|
15840
|
-
prepare: createNamedUniform,
|
|
15841
|
-
reconcile: (existing2) => {
|
|
15842
|
-
if (value !== void 0 && !isTSLNode(value) && !isUniformNode(value)) {
|
|
15843
|
-
existing2.value = typeof value === "string" ? new Color(value) : value;
|
|
15844
|
-
}
|
|
15845
|
-
}
|
|
15846
|
-
});
|
|
15847
|
-
if (registered[name]) return registered[name];
|
|
15848
|
-
const existing = peekStaged(store, "uniforms", ROOT_SCOPE)?.[name] ?? store.getState().uniforms[name];
|
|
15849
|
-
if (existing && isUniformNode(existing)) return existing;
|
|
15850
|
-
throw new Error(
|
|
15851
|
-
`[useUniform] Uniform "${name}" not found. Create it first with: useUniform('${name}', initialValue)`
|
|
15852
|
-
);
|
|
15853
|
-
}
|
|
15854
|
-
function createNamedUniform(name, value) {
|
|
15855
|
-
let node;
|
|
15856
|
-
if (isUniformNode(value)) {
|
|
15857
|
-
node = value;
|
|
15858
|
-
} else if (isTSLNode(value)) {
|
|
15859
|
-
node = uniformOf(value);
|
|
15860
|
-
} else if (typeof value === "string") {
|
|
15861
|
-
node = uniform(new Color(value));
|
|
15862
|
-
} else {
|
|
15863
|
-
node = uniformOf(value);
|
|
15864
|
-
}
|
|
15865
|
-
if (typeof node.setName === "function") {
|
|
15866
|
-
node.setName(name);
|
|
15867
|
-
}
|
|
15868
|
-
return node;
|
|
15869
|
-
}
|
|
15870
|
-
|
|
15871
|
-
function useNodes(creatorOrScope, scope) {
|
|
15872
|
-
const store = usePrimaryStore();
|
|
15873
|
-
const removeNodes2 = useCallback(
|
|
15874
|
-
(names, targetScope) => removeResourceEntries(store, "nodes", Array.isArray(names) ? names : [names], targetScope, isTSLNode),
|
|
15875
|
-
[store]
|
|
15876
|
-
);
|
|
15877
|
-
const clearNodes = useCallback(
|
|
15878
|
-
(targetScope) => clearResourceEntries(store, "nodes", targetScope, isTSLNode),
|
|
15879
|
-
[store]
|
|
15880
|
-
);
|
|
15881
|
-
const rebuildNodes = useCallback(
|
|
15882
|
-
(targetScope) => rebuildResource(store, "nodes", targetScope),
|
|
15883
|
-
[store]
|
|
15884
|
-
);
|
|
15885
|
-
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
15886
|
-
const storeNodes = usePrimaryThree((s) => s.nodes);
|
|
15887
|
-
const created = useScopedResource({
|
|
15888
|
-
store,
|
|
15889
|
-
kind: "nodes",
|
|
15890
|
-
scope: isReader ? void 0 : scope,
|
|
15891
|
-
isLeaf: isTSLNode,
|
|
15892
|
-
create: () => {
|
|
15893
|
-
if (isReader) return {};
|
|
15894
|
-
return creatorOrScope(createLazyCreatorState(store.getState(), store));
|
|
15895
|
-
},
|
|
15896
|
-
prepare: (name, node) => {
|
|
15897
|
-
const setName = Reflect.get(node, "setName");
|
|
15898
|
-
if (typeof setName === "function") setName.call(node, scopedNodeName(scope, name));
|
|
15899
|
-
return node;
|
|
15900
|
-
}
|
|
15901
|
-
});
|
|
15902
|
-
let nodes = created;
|
|
15903
|
-
if (creatorOrScope === void 0) {
|
|
15904
|
-
nodes = storeNodes;
|
|
15905
|
-
} else if (typeof creatorOrScope === "string") {
|
|
15906
|
-
const scopeData = storeNodes[creatorOrScope];
|
|
15907
|
-
nodes = scopeData && !isTSLNode(scopeData) ? scopeData : {};
|
|
15908
|
-
}
|
|
15909
|
-
return { ...nodes, removeNodes: removeNodes2, clearNodes, rebuildNodes };
|
|
15910
|
-
}
|
|
15911
|
-
function rebuildAllNodes(store, scope) {
|
|
15912
|
-
rebuildResource(store, "nodes", scope);
|
|
15913
|
-
}
|
|
15914
|
-
function removeNodes(set, names, scope) {
|
|
15915
|
-
set((state) => {
|
|
15916
|
-
if (scope) {
|
|
15917
|
-
const currentScope = { ...state.nodes[scope] };
|
|
15918
|
-
for (const name of names) delete currentScope[name];
|
|
15919
|
-
return { nodes: { ...state.nodes, [scope]: currentScope } };
|
|
15920
|
-
}
|
|
15921
|
-
const nodes = { ...state.nodes };
|
|
15922
|
-
for (const name of names) if (isTSLNode(nodes[name])) delete nodes[name];
|
|
15923
|
-
return { nodes };
|
|
15924
|
-
});
|
|
15925
|
-
}
|
|
15926
|
-
function clearNodeScope(set, scope) {
|
|
15927
|
-
set((state) => {
|
|
15928
|
-
const { [scope]: _, ...rest } = state.nodes;
|
|
15929
|
-
return { nodes: rest };
|
|
15930
|
-
});
|
|
15931
|
-
}
|
|
15932
|
-
function clearRootNodes(set) {
|
|
15933
|
-
set((state) => {
|
|
15934
|
-
const nodes = {};
|
|
15935
|
-
for (const [key, value] of Object.entries(state.nodes)) {
|
|
15936
|
-
if (!isTSLNode(value)) nodes[key] = value;
|
|
15937
|
-
}
|
|
15938
|
-
return { nodes };
|
|
15939
|
-
});
|
|
15940
|
-
}
|
|
15941
|
-
function useLocalNodes(creator) {
|
|
15942
|
-
const store = usePrimaryStore();
|
|
15943
|
-
const uniforms = usePrimaryThree((s) => s.uniforms);
|
|
15944
|
-
const nodes = usePrimaryThree((s) => s.nodes);
|
|
15945
|
-
const textures = usePrimaryThree((s) => s.textures);
|
|
15946
|
-
const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
|
|
15947
|
-
return useMemo(() => {
|
|
15948
|
-
const wrappedState = createLazyCreatorState(store.getState(), store);
|
|
15949
|
-
return creator(wrappedState);
|
|
15950
|
-
}, [store, creator, uniforms, nodes, textures, hmrVersion]);
|
|
15951
|
-
}
|
|
15952
|
-
|
|
15953
|
-
const disposeBuffer = (buffer) => {
|
|
15954
|
-
if (buffer === null || typeof buffer !== "object") return;
|
|
15955
|
-
if ("dispose" in buffer && typeof buffer.dispose === "function") {
|
|
15956
|
-
buffer.dispose();
|
|
15957
|
-
}
|
|
15958
|
-
};
|
|
15959
|
-
function useBuffers(creatorOrScope, scope) {
|
|
15960
|
-
const store = usePrimaryStore();
|
|
15961
|
-
const removeBuffers = useCallback(
|
|
15962
|
-
(names, targetScope) => removeResourceEntries(store, "buffers", Array.isArray(names) ? names : [names], targetScope, isBufferLike),
|
|
15963
|
-
[store]
|
|
15964
|
-
);
|
|
15965
|
-
const clearBuffers = useCallback(
|
|
15966
|
-
(targetScope) => clearResourceEntries(store, "buffers", targetScope, isBufferLike),
|
|
15967
|
-
[store]
|
|
15968
|
-
);
|
|
15969
|
-
const rebuildBuffers = useCallback(
|
|
15970
|
-
(targetScope) => rebuildResource(store, "buffers", targetScope),
|
|
15971
|
-
[store]
|
|
15972
|
-
);
|
|
15973
|
-
const disposeBuffers = useCallback(
|
|
15974
|
-
(names, targetScope) => {
|
|
15975
|
-
const nameArray = Array.isArray(names) ? names : [names];
|
|
15976
|
-
const state = store.getState();
|
|
15977
|
-
for (const name of nameArray) {
|
|
15978
|
-
const buffer = targetScope ? state.buffers[targetScope]?.[name] : state.buffers[name];
|
|
15979
|
-
if (buffer && isBufferLike(buffer)) {
|
|
15980
|
-
disposeBuffer(buffer);
|
|
15981
|
-
}
|
|
15982
|
-
}
|
|
15983
|
-
removeBuffers(names, targetScope);
|
|
15984
|
-
},
|
|
15985
|
-
[store, removeBuffers]
|
|
15986
|
-
);
|
|
15987
|
-
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
15988
|
-
const storeBuffers = usePrimaryThree((s) => s.buffers);
|
|
15989
|
-
const created = useScopedResource({
|
|
15990
|
-
store,
|
|
15991
|
-
kind: "buffers",
|
|
15992
|
-
scope: isReader ? void 0 : scope,
|
|
15993
|
-
isLeaf: isBufferLike,
|
|
15994
|
-
create: () => {
|
|
15995
|
-
if (isReader) return {};
|
|
15996
|
-
return creatorOrScope(createLazyCreatorState(store.getState(), store));
|
|
15997
|
-
},
|
|
15998
|
-
prepare: (name, buffer) => {
|
|
15999
|
-
const setName = Reflect.get(buffer, "setName");
|
|
16000
|
-
if (typeof setName === "function") setName.call(buffer, scopedNodeName(scope, name));
|
|
16001
|
-
return buffer;
|
|
16002
|
-
}
|
|
16003
|
-
});
|
|
16004
|
-
let buffers = created;
|
|
16005
|
-
if (creatorOrScope === void 0) {
|
|
16006
|
-
buffers = storeBuffers;
|
|
16007
|
-
} else if (typeof creatorOrScope === "string") {
|
|
16008
|
-
const scopeData = storeBuffers[creatorOrScope];
|
|
16009
|
-
buffers = scopeData && !isBufferLike(scopeData) ? scopeData : {};
|
|
16010
|
-
}
|
|
16011
|
-
return { ...buffers, removeBuffers, clearBuffers, rebuildBuffers, disposeBuffers };
|
|
16012
|
-
}
|
|
16013
|
-
function rebuildAllBuffers(store, scope) {
|
|
16014
|
-
rebuildResource(store, "buffers", scope);
|
|
16015
|
-
}
|
|
16016
|
-
|
|
16017
|
-
const disposeStorage = (storage) => {
|
|
16018
|
-
if (storage === null || typeof storage !== "object") return;
|
|
16019
|
-
if ("dispose" in storage && typeof storage.dispose === "function") {
|
|
16020
|
-
storage.dispose();
|
|
16021
|
-
}
|
|
16022
|
-
};
|
|
16023
|
-
function useGPUStorage(creatorOrScope, scope) {
|
|
16024
|
-
const store = usePrimaryStore();
|
|
16025
|
-
const removeStorage = useCallback(
|
|
16026
|
-
(names, targetScope) => removeResourceEntries(store, "gpuStorage", Array.isArray(names) ? names : [names], targetScope, isStorageLike),
|
|
16027
|
-
[store]
|
|
16028
|
-
);
|
|
16029
|
-
const clearStorage = useCallback(
|
|
16030
|
-
(targetScope) => clearResourceEntries(store, "gpuStorage", targetScope, isStorageLike),
|
|
16031
|
-
[store]
|
|
16032
|
-
);
|
|
16033
|
-
const rebuildStorage = useCallback(
|
|
16034
|
-
(targetScope) => rebuildResource(store, "gpuStorage", targetScope),
|
|
16035
|
-
[store]
|
|
16036
|
-
);
|
|
16037
|
-
const disposeStorageFn = useCallback(
|
|
16038
|
-
(names, targetScope) => {
|
|
16039
|
-
const nameArray = Array.isArray(names) ? names : [names];
|
|
16040
|
-
const state = store.getState();
|
|
16041
|
-
for (const name of nameArray) {
|
|
16042
|
-
const storage = targetScope ? state.gpuStorage[targetScope]?.[name] : state.gpuStorage[name];
|
|
16043
|
-
if (storage && isStorageLike(storage)) {
|
|
16044
|
-
disposeStorage(storage);
|
|
16045
|
-
}
|
|
16046
|
-
}
|
|
16047
|
-
removeStorage(names, targetScope);
|
|
16048
|
-
},
|
|
16049
|
-
[store, removeStorage]
|
|
16050
|
-
);
|
|
16051
|
-
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
16052
|
-
const storeStorage = usePrimaryThree((s) => s.gpuStorage);
|
|
16053
|
-
const created = useScopedResource({
|
|
16054
|
-
store,
|
|
16055
|
-
kind: "gpuStorage",
|
|
16056
|
-
scope: isReader ? void 0 : scope,
|
|
16057
|
-
isLeaf: isStorageLike,
|
|
16058
|
-
create: () => {
|
|
16059
|
-
if (isReader) return {};
|
|
16060
|
-
return creatorOrScope(createLazyCreatorState(store.getState(), store));
|
|
16061
|
-
},
|
|
16062
|
-
prepare: (name, storage) => {
|
|
16063
|
-
const label = scopedNodeName(scope, name);
|
|
16064
|
-
const setName = Reflect.get(storage, "setName");
|
|
16065
|
-
if (typeof setName === "function") setName.call(storage, label);
|
|
16066
|
-
if ("name" in storage && typeof storage.name === "string") {
|
|
16067
|
-
storage.name = label;
|
|
16068
|
-
}
|
|
16069
|
-
return storage;
|
|
16070
|
-
}
|
|
16071
|
-
});
|
|
16072
|
-
let gpuStorage = created;
|
|
16073
|
-
if (creatorOrScope === void 0) {
|
|
16074
|
-
gpuStorage = storeStorage;
|
|
16075
|
-
} else if (typeof creatorOrScope === "string") {
|
|
16076
|
-
const scopeData = storeStorage[creatorOrScope];
|
|
16077
|
-
gpuStorage = scopeData && !isStorageLike(scopeData) ? scopeData : {};
|
|
16078
|
-
}
|
|
16079
|
-
return {
|
|
16080
|
-
...gpuStorage,
|
|
16081
|
-
removeStorage,
|
|
16082
|
-
clearStorage,
|
|
16083
|
-
rebuildStorage,
|
|
16084
|
-
disposeStorage: disposeStorageFn
|
|
16085
|
-
};
|
|
16086
|
-
}
|
|
16087
|
-
function rebuildAllStorage(store, scope) {
|
|
16088
|
-
rebuildResource(store, "gpuStorage", scope);
|
|
16089
|
-
}
|
|
16090
|
-
|
|
16091
15300
|
function addTexture(set, key, value) {
|
|
16092
15301
|
set((state) => {
|
|
16093
15302
|
const newMap = new Map(state.textures);
|
|
@@ -16128,130 +15337,9 @@ function createTextureOperations(set) {
|
|
|
16128
15337
|
};
|
|
16129
15338
|
}
|
|
16130
15339
|
|
|
16131
|
-
function renderThroughPipeline(store) {
|
|
16132
|
-
return () => {
|
|
16133
|
-
const pipeline = store.getState().renderPipeline;
|
|
16134
|
-
if (pipeline?.render) pipeline.render();
|
|
16135
|
-
};
|
|
16136
|
-
}
|
|
16137
|
-
function useRenderPipeline(mainCB, setupCB) {
|
|
16138
|
-
const store = useStore();
|
|
16139
|
-
const { scene, camera, renderer, isLegacy } = useThree$1();
|
|
16140
|
-
const callbacksRanRef = useRef(false);
|
|
16141
|
-
const scenePassCacheRef = useRef(null);
|
|
16142
|
-
const forceScenePassRebuildRef = useRef(false);
|
|
16143
|
-
const mainCBRef = useRef(mainCB);
|
|
16144
|
-
const setupCBRef = useRef(setupCB);
|
|
16145
|
-
mainCBRef.current = mainCB;
|
|
16146
|
-
setupCBRef.current = setupCB;
|
|
16147
|
-
const [rebuildVersion, setRebuildVersion] = useState(0);
|
|
16148
|
-
useEffect(() => {
|
|
16149
|
-
callbacksRanRef.current = false;
|
|
16150
|
-
forceScenePassRebuildRef.current = true;
|
|
16151
|
-
}, []);
|
|
16152
|
-
const clearPasses = useCallback(() => {
|
|
16153
|
-
store.setState({ passes: {} });
|
|
16154
|
-
}, [store]);
|
|
16155
|
-
const reset = useCallback(() => {
|
|
16156
|
-
store.setState({
|
|
16157
|
-
renderPipeline: null,
|
|
16158
|
-
passes: {}
|
|
16159
|
-
});
|
|
16160
|
-
setRenderOverride(store, null);
|
|
16161
|
-
scenePassCacheRef.current?.scenePass.dispose();
|
|
16162
|
-
callbacksRanRef.current = false;
|
|
16163
|
-
scenePassCacheRef.current = null;
|
|
16164
|
-
forceScenePassRebuildRef.current = false;
|
|
16165
|
-
}, [store]);
|
|
16166
|
-
const rebuild = useCallback(() => {
|
|
16167
|
-
callbacksRanRef.current = false;
|
|
16168
|
-
forceScenePassRebuildRef.current = true;
|
|
16169
|
-
setRebuildVersion((v) => v + 1);
|
|
16170
|
-
}, []);
|
|
16171
|
-
useLayoutEffect(() => {
|
|
16172
|
-
if (isLegacy) {
|
|
16173
|
-
throw new Error("useRenderPipeline is only available with WebGPU renderer. Set renderer prop on Canvas.");
|
|
16174
|
-
}
|
|
16175
|
-
if (!renderer || !scene || !camera) return;
|
|
16176
|
-
if (!("isWebGPURenderer" in renderer)) {
|
|
16177
|
-
throw new Error("useRenderPipeline: renderer is not a WebGPURenderer but isLegacy is false.");
|
|
16178
|
-
}
|
|
16179
|
-
const state = store.getState();
|
|
16180
|
-
const set = store.setState;
|
|
16181
|
-
try {
|
|
16182
|
-
let pipeline = state.renderPipeline;
|
|
16183
|
-
let currentPasses = { ...state.passes };
|
|
16184
|
-
let justCreatedPipeline = false;
|
|
16185
|
-
if (!pipeline) {
|
|
16186
|
-
pipeline = new RenderPipeline(renderer);
|
|
16187
|
-
justCreatedPipeline = true;
|
|
16188
|
-
}
|
|
16189
|
-
const cacheValid = !forceScenePassRebuildRef.current && scenePassCacheRef.current && scenePassCacheRef.current.sceneUuid === scene.uuid && scenePassCacheRef.current.cameraUuid === camera.uuid;
|
|
16190
|
-
let outgoingScenePass = null;
|
|
16191
|
-
let scenePass;
|
|
16192
|
-
if (cacheValid) {
|
|
16193
|
-
scenePass = scenePassCacheRef.current.scenePass;
|
|
16194
|
-
} else {
|
|
16195
|
-
outgoingScenePass = scenePassCacheRef.current?.scenePass ?? null;
|
|
16196
|
-
scenePass = pass(scene, camera);
|
|
16197
|
-
scenePassCacheRef.current = { sceneUuid: scene.uuid, cameraUuid: camera.uuid, scenePass };
|
|
16198
|
-
forceScenePassRebuildRef.current = false;
|
|
16199
|
-
}
|
|
16200
|
-
currentPasses.scenePass = scenePass;
|
|
16201
|
-
let outputNodeChanged = false;
|
|
16202
|
-
if (!pipeline.outputNode || justCreatedPipeline || pipeline.outputNode === outgoingScenePass) {
|
|
16203
|
-
pipeline.outputNode = scenePass;
|
|
16204
|
-
outputNodeChanged = true;
|
|
16205
|
-
}
|
|
16206
|
-
set({ renderPipeline: pipeline, passes: currentPasses });
|
|
16207
|
-
setRenderOverride(store, renderThroughPipeline(store));
|
|
16208
|
-
const shouldRunCallbacks = justCreatedPipeline || !callbacksRanRef.current || !cacheValid;
|
|
16209
|
-
if (shouldRunCallbacks) {
|
|
16210
|
-
if (setupCBRef.current) {
|
|
16211
|
-
const freshState = Object.assign({}, store.getState(), {
|
|
16212
|
-
renderPipeline: pipeline,
|
|
16213
|
-
passes: { ...currentPasses, scenePass },
|
|
16214
|
-
renderer,
|
|
16215
|
-
isLegacy: false
|
|
16216
|
-
});
|
|
16217
|
-
const setupResult = setupCBRef.current(freshState);
|
|
16218
|
-
if (setupResult && typeof setupResult === "object") {
|
|
16219
|
-
currentPasses = { ...currentPasses, ...setupResult };
|
|
16220
|
-
set({ passes: currentPasses });
|
|
16221
|
-
}
|
|
16222
|
-
}
|
|
16223
|
-
if (mainCBRef.current) {
|
|
16224
|
-
const freshState = Object.assign({}, store.getState(), {
|
|
16225
|
-
renderPipeline: pipeline,
|
|
16226
|
-
passes: { ...currentPasses, scenePass },
|
|
16227
|
-
renderer,
|
|
16228
|
-
isLegacy: false
|
|
16229
|
-
});
|
|
16230
|
-
const mainResult = mainCBRef.current(freshState);
|
|
16231
|
-
if (mainResult && typeof mainResult === "object") {
|
|
16232
|
-
currentPasses = { ...currentPasses, ...mainResult };
|
|
16233
|
-
set({ passes: currentPasses });
|
|
16234
|
-
}
|
|
16235
|
-
}
|
|
16236
|
-
outputNodeChanged = true;
|
|
16237
|
-
callbacksRanRef.current = true;
|
|
16238
|
-
}
|
|
16239
|
-
if (outputNodeChanged) pipeline.needsUpdate = true;
|
|
16240
|
-
if (outgoingScenePass && outgoingScenePass !== scenePass) outgoingScenePass.dispose();
|
|
16241
|
-
} catch (error) {
|
|
16242
|
-
console.warn("[useRenderPipeline] Setup failed; the render pipeline was not configured:", error);
|
|
16243
|
-
}
|
|
16244
|
-
}, [store, renderer, scene, camera, isLegacy, rebuildVersion]);
|
|
16245
|
-
const passes = useThree$1((s) => s.passes);
|
|
16246
|
-
const renderPipeline = useThree$1((s) => s.renderPipeline);
|
|
16247
|
-
const actions = { passes, clearPasses, reset, rebuild };
|
|
16248
|
-
if (renderPipeline) return { ...actions, isReady: true, renderPipeline };
|
|
16249
|
-
return { ...actions, isReady: false, renderPipeline: null };
|
|
16250
|
-
}
|
|
16251
|
-
|
|
16252
15340
|
extend(THREE);
|
|
16253
15341
|
const useThree = useThree$1;
|
|
16254
15342
|
const useFrame = useFrame$1;
|
|
16255
15343
|
const Canvas = Canvas$1;
|
|
16256
15344
|
|
|
16257
|
-
export { Block, Canvas, Environment, EnvironmentCube, EnvironmentMap, EnvironmentPortal, ErrorBoundary, FROM_REF, IsObject, ONCE, Portal, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS, Texture, _roots, addAfterEffect, addEffect, addTail, advance, applyProps, attach, buildGraph, calculateDpr,
|
|
15345
|
+
export { Block, Canvas, Environment, EnvironmentCube, EnvironmentMap, EnvironmentPortal, ErrorBoundary, FROM_REF, IsObject, ONCE, Portal, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS, Texture, _roots, addAfterEffect, addEffect, addTail, advance, applyProps, attach, buildGraph, calculateDpr, context, createEvents, createPointerEvents, createPortal, createRoot, createStore, createTextureOperations, detach, diffProps, dispose, createPointerEvents as events, extend, findInitialRoot, flushSync, fromRef, getInstanceProps, getPrimary, getPrimaryIds, getRootState, getUuidPrefix, hasConstructor, hasPrimary, invalidate, invalidateInstance, is, isColorRepresentation, isCopyable, isFromRef, isObject3D, isOnce, isOrthographicCamera, isRef$1 as isRef, isRenderer, isTexture, isVectorLike, once, prepare, presetsObj, reconciler, registerPrimary, registerRootExtension, removeInteractivity, resolve, setRenderOverride, swapInteractivity, unmountComponentAtNode, unregisterPrimary, updateCamera, updateFrustum, useBridge, useEnvironment, useFrame, useGraph, useInstanceHandle, useIsomorphicLayoutEffect, useLoader, useMutableCallback, useRenderTarget, useStore, useTexture, useTextures, useThree, waitForPrimary };
|