@expofp/renderer 3.45.15 → 3.46.0
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/index.d.ts +1 -1
- package/dist/objects/lighting/Lighting.d.ts +57 -27
- package/dist/objects/lighting/Lighting.js +267 -48
- package/dist/objects/lighting/index.d.ts +1 -1
- package/dist/objects/lighting/index.js +1 -1
- package/dist/objects/lighting/lighting-gui.js +61 -39
- package/dist/objects/lighting/studio-environment.d.ts +70 -0
- package/dist/objects/lighting/studio-environment.js +167 -0
- package/dist/objects/lighting/sun-shadow-map.d.ts +61 -0
- package/dist/objects/lighting/sun-shadow-map.js +324 -0
- package/dist/objects/materials/ColorMaterial.js +2 -0
- package/dist/objects/materials/ModelMaterial.js +10 -2
- package/dist/objects/materials/effects/ao/index.js +3 -1
- package/dist/objects/materials/effects/contact-shadow.d.ts +13 -1
- package/dist/objects/materials/effects/contact-shadow.js +9 -0
- package/dist/objects/materials/effects/sun-shadow.d.ts +32 -0
- package/dist/objects/materials/effects/sun-shadow.js +108 -0
- package/dist/objects/models/Models.js +25 -11
- package/dist/objects/models/gltf-cache.d.ts +4 -1
- package/dist/objects/models/gltf-cache.js +41 -12
- package/dist/objects/models/ktx2.d.ts +21 -0
- package/dist/objects/models/ktx2.js +28 -0
- package/dist/objects/models/model-container.d.ts +10 -0
- package/dist/objects/models/model-container.js +5 -3
- package/dist/objects/models/model-opacity.d.ts +27 -0
- package/dist/objects/models/model-opacity.js +48 -0
- package/dist/objects/shapes/Shapes.js +3 -1
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useThree } from '@react-three/fiber';
|
|
3
3
|
import { Fragment, useEffect, useState } from 'react';
|
|
4
|
+
import { MeshDepthMaterial } from 'three';
|
|
4
5
|
import { InstancedMesh } from '../../core/instanced/InstancedMesh';
|
|
5
6
|
import { sameSequence } from '../../utils/arrays';
|
|
6
7
|
import { createLogger } from '../../utils/logging';
|
|
@@ -9,6 +10,7 @@ import { useOccluder } from '../lighting/occluder';
|
|
|
9
10
|
import { ModelMaterial } from '../materials/ModelMaterial';
|
|
10
11
|
import { loadModel } from './gltf-cache';
|
|
11
12
|
import { MODEL_KINDS, ModelContainer, modelKindOf, OPACITY_UNIFORM, } from './model-container';
|
|
13
|
+
import { useDefaultModelOpacity } from './model-opacity';
|
|
12
14
|
import { ModelInstance } from './ModelInstance';
|
|
13
15
|
const logger = createLogger('models');
|
|
14
16
|
/**
|
|
@@ -29,6 +31,8 @@ const logger = createLogger('models');
|
|
|
29
31
|
*/
|
|
30
32
|
export function Models(props) {
|
|
31
33
|
const { defs } = props;
|
|
34
|
+
// A def without its own `opacity` takes the default, which can move a def between batches.
|
|
35
|
+
const defaultOpacity = useDefaultModelOpacity();
|
|
32
36
|
// Handed to each part's mesh as a prefix of *its* members, the way `Shapes` hands one to each of
|
|
33
37
|
// its batches: a model layer is small and its meshes are few, and the scheduler sizes the next
|
|
34
38
|
// slice from what this one actually cost.
|
|
@@ -42,12 +46,13 @@ export function Models(props) {
|
|
|
42
46
|
// an ordinary slot write that never re-renders this component, so one crossing 1 would otherwise
|
|
43
47
|
// leave the def in a batch whose material describes the wrong render list. `repartition` is what
|
|
44
48
|
// the containers call when they notice.
|
|
45
|
-
const [partition, setPartition] = useState(() => partitionModels(defs, undefined));
|
|
46
|
-
if (partition.defs !== defs)
|
|
47
|
-
setPartition((current) => partitionModels(defs, current.batches));
|
|
49
|
+
const [partition, setPartition] = useState(() => partitionModels(defs, defaultOpacity, undefined));
|
|
50
|
+
if (partition.defs !== defs || partition.defaultOpacity !== defaultOpacity) {
|
|
51
|
+
setPartition((current) => partitionModels(defs, defaultOpacity, current.batches));
|
|
52
|
+
}
|
|
48
53
|
/** Re-splits the current membership, for a batch that found a member of the wrong kind. */
|
|
49
54
|
function repartition() {
|
|
50
|
-
setPartition((current) => partitionModels(defs, current.batches));
|
|
55
|
+
setPartition((current) => partitionModels(defs, defaultOpacity, current.batches));
|
|
51
56
|
}
|
|
52
57
|
// The distinct urls the layer draws, held in state so the load effect depends on a value that
|
|
53
58
|
// changes exactly when the *set* does: the snapshot from `useStagedChildren` is rebuilt on every
|
|
@@ -63,9 +68,10 @@ export function Models(props) {
|
|
|
63
68
|
setUrls(wanted);
|
|
64
69
|
const [assets, setAssets] = useState([]);
|
|
65
70
|
const invalidate = useThree((state) => state.invalidate);
|
|
71
|
+
const gl = useThree((state) => state.gl);
|
|
66
72
|
useEffect(() => {
|
|
67
73
|
let live = true;
|
|
68
|
-
void Promise.all(urls.map(loadOrWarn)).then((loaded) => {
|
|
74
|
+
void Promise.all(urls.map((url) => loadOrWarn(url, gl))).then((loaded) => {
|
|
69
75
|
if (!live)
|
|
70
76
|
return;
|
|
71
77
|
// `filter(Boolean)` does not narrow a union, so the guard is spelled out.
|
|
@@ -75,7 +81,7 @@ export function Models(props) {
|
|
|
75
81
|
return () => {
|
|
76
82
|
live = false;
|
|
77
83
|
};
|
|
78
|
-
}, [urls, invalidate]);
|
|
84
|
+
}, [urls, invalidate, gl]);
|
|
79
85
|
// Nested rather than flattened because React scopes keys to their parent, so each level only has
|
|
80
86
|
// to be unique among its siblings — and `ModelPart.id` is, where `material.uuid` is not.
|
|
81
87
|
//
|
|
@@ -95,10 +101,11 @@ export function Models(props) {
|
|
|
95
101
|
/**
|
|
96
102
|
* Splits a layer's models by kind and url, keeping every batch that is already mounted.
|
|
97
103
|
* @param defs - The layer's models, in paint order.
|
|
104
|
+
* @param defaultOpacity - The opacity of a def that sets none.
|
|
98
105
|
* @param mounted - The batches already on screen, whose keys are carried forward emptied.
|
|
99
106
|
* @returns The split.
|
|
100
107
|
*/
|
|
101
|
-
function partitionModels(defs, mounted) {
|
|
108
|
+
function partitionModels(defs, defaultOpacity, mounted) {
|
|
102
109
|
const batches = {
|
|
103
110
|
opaque: emptied(mounted?.opaque),
|
|
104
111
|
translucent: emptied(mounted?.translucent),
|
|
@@ -111,7 +118,7 @@ function partitionModels(defs, mounted) {
|
|
|
111
118
|
else
|
|
112
119
|
byUrl.set(def.url, [def]);
|
|
113
120
|
}
|
|
114
|
-
return { defs, batches };
|
|
121
|
+
return { defs, defaultOpacity, batches };
|
|
115
122
|
}
|
|
116
123
|
/**
|
|
117
124
|
* The same urls, each with an empty membership — how a mounted batch survives losing its last
|
|
@@ -159,17 +166,24 @@ function ModelPartMesh(props) {
|
|
|
159
166
|
return (_jsxs(_Fragment, { children: [_jsxs(InstancedMesh, { args: container.args, ref: (mesh) => {
|
|
160
167
|
container.bind(mesh);
|
|
161
168
|
occluder(kind === 'opaque' ? mesh : null);
|
|
162
|
-
|
|
169
|
+
// three draws every shadow caster with one shared depth material, and the
|
|
170
|
+
// instancing patch binds the first mesh's textures into it. Each mesh needs its own.
|
|
171
|
+
if (mesh && !mesh.customDepthMaterial)
|
|
172
|
+
mesh.customDepthMaterial = new MeshDepthMaterial();
|
|
173
|
+
}, matrixAutoUpdate: false, matrix: container.meshMatrix,
|
|
174
|
+
// Models cast the sun's shadow and receive it.
|
|
175
|
+
castShadow: true, receiveShadow: true, sortObjects: true, renderOrder: renderOrder, children: [_jsx("primitive", { object: part.geometry, attach: "geometry", dispose: null }), _jsx(ModelMaterial, { source: part.material, opacityUniform: OPACITY_UNIFORM, translucent: kind === 'translucent' })] }), defs.slice(0, mounted).map((def) => (_jsx(ModelInstance, { def: def, container: container }, defKey(def))))] }));
|
|
163
176
|
}
|
|
164
177
|
/**
|
|
165
178
|
* Loads one model, reporting a failure rather than rejecting — one missing model should not cost a
|
|
166
179
|
* layer the rest of them.
|
|
167
180
|
* @param url - The model to load.
|
|
181
|
+
* @param renderer - The renderer its textures upload into.
|
|
168
182
|
* @returns The asset, or `undefined` if it could not be loaded.
|
|
169
183
|
*/
|
|
170
|
-
async function loadOrWarn(url) {
|
|
184
|
+
async function loadOrWarn(url, renderer) {
|
|
171
185
|
try {
|
|
172
|
-
return await loadModel(url);
|
|
186
|
+
return await loadModel(url, renderer);
|
|
173
187
|
}
|
|
174
188
|
catch (error) {
|
|
175
189
|
logger.warn('failed to load model %s: %O', url, error);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type WebGLRenderer } from 'three';
|
|
1
2
|
import { type ModelAsset } from './model-asset';
|
|
2
3
|
/**
|
|
3
4
|
* Loads and parses a GLB, or returns the in-flight promise for one already being loaded.
|
|
@@ -11,7 +12,9 @@ import { type ModelAsset } from './model-asset';
|
|
|
11
12
|
* reports to the mount scheduler, so the scene's admission queue would stall on the first model
|
|
12
13
|
* layer (see `Models`). A hook could not be called per url in a loop either.
|
|
13
14
|
* @param url - The model's URL.
|
|
15
|
+
* @param renderer - The renderer its textures upload into, which picks the GPU format a KTX2
|
|
16
|
+
* texture is transcoded to.
|
|
14
17
|
* @returns The parsed asset.
|
|
15
18
|
*/
|
|
16
|
-
export declare function loadModel(url: string): Promise<ModelAsset>;
|
|
19
|
+
export declare function loadModel(url: string, renderer: WebGLRenderer): Promise<ModelAsset>;
|
|
17
20
|
//# sourceMappingURL=gltf-cache.d.ts.map
|
|
@@ -13,13 +13,15 @@ import { bakeGltf } from './model-asset';
|
|
|
13
13
|
* reports to the mount scheduler, so the scene's admission queue would stall on the first model
|
|
14
14
|
* layer (see `Models`). A hook could not be called per url in a loop either.
|
|
15
15
|
* @param url - The model's URL.
|
|
16
|
+
* @param renderer - The renderer its textures upload into, which picks the GPU format a KTX2
|
|
17
|
+
* texture is transcoded to.
|
|
16
18
|
* @returns The parsed asset.
|
|
17
19
|
*/
|
|
18
|
-
export function loadModel(url) {
|
|
20
|
+
export function loadModel(url, renderer) {
|
|
19
21
|
const pending = cache.get(url);
|
|
20
22
|
if (pending)
|
|
21
23
|
return pending;
|
|
22
|
-
const promise = parse(url).catch((error) => {
|
|
24
|
+
const promise = parse(url, renderer).catch((error) => {
|
|
23
25
|
cache.delete(url);
|
|
24
26
|
throw error;
|
|
25
27
|
});
|
|
@@ -29,22 +31,49 @@ export function loadModel(url) {
|
|
|
29
31
|
/**
|
|
30
32
|
* Fetches and bakes a GLB.
|
|
31
33
|
* @param url - The model's URL.
|
|
34
|
+
* @param renderer - The renderer its textures upload into.
|
|
32
35
|
* @returns The parsed asset.
|
|
33
36
|
*/
|
|
34
|
-
async function parse(url) {
|
|
35
|
-
const gltf = await
|
|
37
|
+
async function parse(url, renderer) {
|
|
38
|
+
const gltf = await loaderFor(renderer).loadAsync(url);
|
|
36
39
|
return bakeGltf(gltf.scene, url);
|
|
37
40
|
}
|
|
38
41
|
/**
|
|
39
|
-
* The loader
|
|
40
|
-
* costs nothing at rest
|
|
41
|
-
*
|
|
42
|
-
*
|
|
42
|
+
* The loader for one renderer. Meshopt is wired in because its decoder ships inside three's addons
|
|
43
|
+
* and costs nothing at rest. Draco stays out: its decoder comes from a CDN at runtime, and an
|
|
44
|
+
* offline plan copy works from its own files only.
|
|
45
|
+
*
|
|
46
|
+
* The KTX2 loader is a stand-in that imports the real one on its first texture. `GLTFLoader` calls
|
|
47
|
+
* it only for a texture that uses `KHR_texture_basisu`, and only through `load`, so the KTX2 chunk
|
|
48
|
+
* and its transcoder download with the first KTX2 texture.
|
|
49
|
+
* @param renderer - The renderer the textures upload into, which picks the GPU format a KTX2 texture
|
|
50
|
+
* is transcoded to.
|
|
51
|
+
* @returns The loader.
|
|
52
|
+
*/
|
|
53
|
+
function loaderFor(renderer) {
|
|
54
|
+
let loader = loaders.get(renderer);
|
|
55
|
+
if (!loader) {
|
|
56
|
+
loader = new GLTFLoader()
|
|
57
|
+
.setMeshoptDecoder(MeshoptDecoder)
|
|
58
|
+
.setKTX2Loader(lazyKtx2Loader(renderer));
|
|
59
|
+
loaders.set(renderer, loader);
|
|
60
|
+
}
|
|
61
|
+
return loader;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A stand-in for `KTX2Loader` that imports it on the first `load`.
|
|
65
|
+
* @param renderer - The renderer the textures upload into.
|
|
66
|
+
* @returns The stand-in, typed as the loader `GLTFLoader` expects.
|
|
43
67
|
*/
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
68
|
+
function lazyKtx2Loader(renderer) {
|
|
69
|
+
const stand = {
|
|
70
|
+
load(url, onLoad, onProgress, onError) {
|
|
71
|
+
import('./ktx2').then(({ ktx2Loader }) => ktx2Loader(renderer).load(url, onLoad, onProgress, onError), onError);
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
return stand;
|
|
47
75
|
}
|
|
48
76
|
/** In-flight and settled loads, keyed by URL. */
|
|
49
77
|
const cache = new Map();
|
|
50
|
-
|
|
78
|
+
/** One loader per renderer; see {@link loaderFor}. */
|
|
79
|
+
const loaders = new WeakMap();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type WebGLRenderer } from 'three';
|
|
2
|
+
import { KTX2Loader } from 'three/examples/jsm/loaders/KTX2Loader.js';
|
|
3
|
+
/**
|
|
4
|
+
* The KTX2 loader for models whose textures are Basis Universal compressed (`KHR_texture_basisu`).
|
|
5
|
+
*
|
|
6
|
+
* A module of its own so `gltf-cache` can import it on demand: the Basis transcoder is about 570 KB,
|
|
7
|
+
* and only a plan whose models carry a KTX2 texture downloads it.
|
|
8
|
+
*
|
|
9
|
+
* The transcoder ships with the bundle. three's `KTX2Loader` names its own copy with
|
|
10
|
+
* `new URL('../libs/basis/basis_transcoder.*', import.meta.url)` by default, and
|
|
11
|
+
* Vite resolves that expression at build time: the application build emits both files beside the
|
|
12
|
+
* chunk, and a library build inlines them into it. Either way an offline copy carries the transcoder,
|
|
13
|
+
* because it copies every file the build emitted. Every byte comes from the plan's own files.
|
|
14
|
+
*
|
|
15
|
+
* One loader per renderer, because `detectSupport` reads which GPU formats that context can sample
|
|
16
|
+
* (ASTC, ETC2, BC7, …) and the transcoder targets the best one.
|
|
17
|
+
* @param renderer - The renderer the textures upload into.
|
|
18
|
+
* @returns The loader, its transcoder worker started lazily on first use.
|
|
19
|
+
*/
|
|
20
|
+
export declare function ktx2Loader(renderer: WebGLRenderer): KTX2Loader;
|
|
21
|
+
//# sourceMappingURL=ktx2.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { KTX2Loader } from 'three/examples/jsm/loaders/KTX2Loader.js';
|
|
2
|
+
/**
|
|
3
|
+
* The KTX2 loader for models whose textures are Basis Universal compressed (`KHR_texture_basisu`).
|
|
4
|
+
*
|
|
5
|
+
* A module of its own so `gltf-cache` can import it on demand: the Basis transcoder is about 570 KB,
|
|
6
|
+
* and only a plan whose models carry a KTX2 texture downloads it.
|
|
7
|
+
*
|
|
8
|
+
* The transcoder ships with the bundle. three's `KTX2Loader` names its own copy with
|
|
9
|
+
* `new URL('../libs/basis/basis_transcoder.*', import.meta.url)` by default, and
|
|
10
|
+
* Vite resolves that expression at build time: the application build emits both files beside the
|
|
11
|
+
* chunk, and a library build inlines them into it. Either way an offline copy carries the transcoder,
|
|
12
|
+
* because it copies every file the build emitted. Every byte comes from the plan's own files.
|
|
13
|
+
*
|
|
14
|
+
* One loader per renderer, because `detectSupport` reads which GPU formats that context can sample
|
|
15
|
+
* (ASTC, ETC2, BC7, …) and the transcoder targets the best one.
|
|
16
|
+
* @param renderer - The renderer the textures upload into.
|
|
17
|
+
* @returns The loader, its transcoder worker started lazily on first use.
|
|
18
|
+
*/
|
|
19
|
+
export function ktx2Loader(renderer) {
|
|
20
|
+
let loader = loaders.get(renderer);
|
|
21
|
+
if (!loader) {
|
|
22
|
+
loader = new KTX2Loader().detectSupport(renderer);
|
|
23
|
+
loaders.set(renderer, loader);
|
|
24
|
+
}
|
|
25
|
+
return loader;
|
|
26
|
+
}
|
|
27
|
+
/** One loader per renderer; see {@link ktx2Loader}. */
|
|
28
|
+
const loaders = new WeakMap();
|
|
@@ -120,4 +120,14 @@ export declare class ModelContainer extends SlotContainer<null, InstancedMeshImp
|
|
|
120
120
|
* @returns The shared scratch matrix, composed. Valid until the next call.
|
|
121
121
|
*/
|
|
122
122
|
export declare function fitToBounds(extents: Box3, bounds: Rect): Matrix4;
|
|
123
|
+
/**
|
|
124
|
+
* Plan → glTF, the way back.
|
|
125
|
+
*
|
|
126
|
+
* It happens to equal {@link PLAN_FROM_GLTF} — swapping two axes twice returns you to where you
|
|
127
|
+
* started — so the inverse could be spelled with the same constant and cost nothing. It is not,
|
|
128
|
+
* because {@link ModelContainer.place} is a conjugation and should look like one: written with a
|
|
129
|
+
* single constant on both sides, it reads as an error, and it would quietly *become* one the day the
|
|
130
|
+
* mapping stops being its own inverse.
|
|
131
|
+
*/
|
|
132
|
+
export declare const GLTF_FROM_PLAN: Matrix4;
|
|
123
133
|
//# sourceMappingURL=model-container.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Matrix4, Quaternion, Vector3 } from 'three';
|
|
2
2
|
import { SlotContainer } from '../containers';
|
|
3
3
|
import { DIM_SCHEMA } from '../materials/effects/color-dim';
|
|
4
|
+
import { getDefaultModelOpacity, USE_DEFAULT_OPACITY } from './model-opacity';
|
|
4
5
|
/**
|
|
5
6
|
* The per-instance uniform a model mesh reads its opacity from. The container owns the name: it
|
|
6
7
|
* declares the schema on bind and writes each slot's value, and hands the name to `ModelMaterial`,
|
|
@@ -23,7 +24,7 @@ export const MODEL_KINDS = ['opaque', 'translucent'];
|
|
|
23
24
|
* @returns The kind of batch it draws from.
|
|
24
25
|
*/
|
|
25
26
|
export function modelKindOf(def) {
|
|
26
|
-
return (def.opacity ??
|
|
27
|
+
return (def.opacity ?? getDefaultModelOpacity()) < 1 ? 'translucent' : 'opaque';
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
30
|
* One model part's slot bookkeeping: every def in the layer drawing that part gets an instance, so
|
|
@@ -110,7 +111,8 @@ export class ModelContainer extends SlotContainer {
|
|
|
110
111
|
* @param def - The def supplying the opacity.
|
|
111
112
|
*/
|
|
112
113
|
setOpacity(slot, def) {
|
|
113
|
-
|
|
114
|
+
// A def without its own opacity defers to the shared default in the shader.
|
|
115
|
+
const opacity = this.kind === 'translucent' ? (def.opacity ?? USE_DEFAULT_OPACITY) : 1;
|
|
114
116
|
this.mesh.setUniformAt(slot, OPACITY_UNIFORM, opacity);
|
|
115
117
|
}
|
|
116
118
|
addInstance() {
|
|
@@ -185,7 +187,7 @@ const PLAN_FROM_GLTF = new Matrix4()
|
|
|
185
187
|
* single constant on both sides, it reads as an error, and it would quietly *become* one the day the
|
|
186
188
|
* mapping stops being its own inverse.
|
|
187
189
|
*/
|
|
188
|
-
const GLTF_FROM_PLAN = PLAN_FROM_GLTF.clone().invert();
|
|
190
|
+
export const GLTF_FROM_PLAN = PLAN_FROM_GLTF.clone().invert();
|
|
189
191
|
/**
|
|
190
192
|
* The schema the mesh declares so it can hold an {@link OPACITY_UNIFORM} and a dim per slot.
|
|
191
193
|
*
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type IUniform } from 'three';
|
|
2
|
+
/**
|
|
3
|
+
* The opacity a model draws at when its def sets none, moved by the Lighting folder's slider.
|
|
4
|
+
*
|
|
5
|
+
* A shared uniform: a model without its own `opacity` stores {@link USE_DEFAULT_OPACITY} in its
|
|
6
|
+
* slot, and the shader reads this instead. Moving the default changes this one value, and the
|
|
7
|
+
* opaque/translucent split follows it as `Models` re-renders on {@link useDefaultModelOpacity}.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEFAULT_MODEL_OPACITY: IUniform<number>;
|
|
10
|
+
/** The per-instance opacity that means "use {@link DEFAULT_MODEL_OPACITY}". */
|
|
11
|
+
export declare const USE_DEFAULT_OPACITY = -1;
|
|
12
|
+
/**
|
|
13
|
+
* Reads the default model opacity, re-rendering when it moves.
|
|
14
|
+
* @returns The opacity a model without its own `opacity` draws at.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useDefaultModelOpacity(): number;
|
|
17
|
+
/**
|
|
18
|
+
* The default model opacity.
|
|
19
|
+
* @returns The opacity a model without its own `opacity` draws at.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getDefaultModelOpacity(): number;
|
|
22
|
+
/**
|
|
23
|
+
* Moves the default model opacity.
|
|
24
|
+
* @param opacity - From `0` to `1`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function setDefaultModelOpacity(opacity: number): void;
|
|
27
|
+
//# sourceMappingURL=model-opacity.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useSyncExternalStore } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* The opacity a model draws at when its def sets none, moved by the Lighting folder's slider.
|
|
4
|
+
*
|
|
5
|
+
* A shared uniform: a model without its own `opacity` stores {@link USE_DEFAULT_OPACITY} in its
|
|
6
|
+
* slot, and the shader reads this instead. Moving the default changes this one value, and the
|
|
7
|
+
* opaque/translucent split follows it as `Models` re-renders on {@link useDefaultModelOpacity}.
|
|
8
|
+
*/
|
|
9
|
+
export const DEFAULT_MODEL_OPACITY = { value: 1 };
|
|
10
|
+
/** The per-instance opacity that means "use {@link DEFAULT_MODEL_OPACITY}". */
|
|
11
|
+
export const USE_DEFAULT_OPACITY = -1;
|
|
12
|
+
/**
|
|
13
|
+
* Reads the default model opacity, re-rendering when it moves.
|
|
14
|
+
* @returns The opacity a model without its own `opacity` draws at.
|
|
15
|
+
*/
|
|
16
|
+
export function useDefaultModelOpacity() {
|
|
17
|
+
return useSyncExternalStore(subscribe, getDefaultModelOpacity);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The default model opacity.
|
|
21
|
+
* @returns The opacity a model without its own `opacity` draws at.
|
|
22
|
+
*/
|
|
23
|
+
export function getDefaultModelOpacity() {
|
|
24
|
+
return DEFAULT_MODEL_OPACITY.value;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Moves the default model opacity.
|
|
28
|
+
* @param opacity - From `0` to `1`.
|
|
29
|
+
*/
|
|
30
|
+
export function setDefaultModelOpacity(opacity) {
|
|
31
|
+
if (opacity === DEFAULT_MODEL_OPACITY.value)
|
|
32
|
+
return;
|
|
33
|
+
DEFAULT_MODEL_OPACITY.value = opacity;
|
|
34
|
+
for (const listener of listeners)
|
|
35
|
+
listener();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Subscribes to the default model opacity.
|
|
39
|
+
* @param listener - Called after it moves.
|
|
40
|
+
* @returns Unsubscribes.
|
|
41
|
+
*/
|
|
42
|
+
function subscribe(listener) {
|
|
43
|
+
listeners.add(listener);
|
|
44
|
+
return () => {
|
|
45
|
+
listeners.delete(listener);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const listeners = new Set();
|
|
@@ -127,5 +127,7 @@ function ShapeBatch(props) {
|
|
|
127
127
|
return (_jsxs(_Fragment, { children: [_jsx(BatchedMesh, { args: container.capacity, ref: (mesh) => {
|
|
128
128
|
container.bind(mesh);
|
|
129
129
|
occluder(kind === 'solid' ? mesh : null);
|
|
130
|
-
}, customSort: container.customSort,
|
|
130
|
+
}, customSort: container.customSort,
|
|
131
|
+
// Solid shapes catch the models' sun shadows.
|
|
132
|
+
receiveShadow: kind !== 'planar', renderOrder: renderOrder, children: _jsx(ColorMaterial, { solid: kind !== 'planar', translucent: kind === 'translucent' }) }), defs.slice(0, mounted).map((def) => (_jsx(ShapeInstance, { def: def, container: container }, defKey(def))))] }));
|
|
131
133
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expofp/renderer",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.46.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/expofp/efp-app.git",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"troika-three-text": "^0.52.5",
|
|
43
43
|
"tslib": "^2.3.0",
|
|
44
44
|
"webgl-memory": "^1.1.3",
|
|
45
|
-
"@expofp/geometry": "3.
|
|
45
|
+
"@expofp/geometry": "3.46.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@react-three/test-renderer": "^9.1.0",
|