@fps-games/editor 0.1.7 → 0.1.8-beta.2
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/build-info.json +16 -16
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/local-editor-harness.d.ts +4 -0
- package/dist/local-editor-harness.d.ts.map +1 -1
- package/dist/local-editor-harness.js +113 -51
- package/dist/local-editor-harness.js.map +1 -1
- package/dist/local-editor-performance-stats.d.ts.map +1 -1
- package/dist/local-editor-performance-stats.js +7 -0
- package/dist/local-editor-performance-stats.js.map +1 -1
- package/dist/playable-babylon-facade.d.ts +2 -2
- package/dist/playable-babylon-facade.d.ts.map +1 -1
- package/dist/playable-babylon-facade.js +1 -1
- package/dist/playable-babylon-facade.js.map +1 -1
- package/dist/playable-local-editor-host.d.ts +5 -1
- package/dist/playable-local-editor-host.d.ts.map +1 -1
- package/dist/playable-local-editor-host.js +75 -1
- package/dist/playable-local-editor-host.js.map +1 -1
- package/dist/playable-sdk.d.ts +2 -2
- package/dist/playable-sdk.d.ts.map +1 -1
- package/dist/playable-sdk.js +1 -1
- package/dist/playable-sdk.js.map +1 -1
- package/node_modules/@fps-games/babylon-renderer/dist/index.d.ts +1 -0
- package/node_modules/@fps-games/babylon-renderer/dist/index.d.ts.map +1 -1
- package/node_modules/@fps-games/babylon-renderer/dist/index.js +1 -0
- package/node_modules/@fps-games/babylon-renderer/dist/index.js.map +1 -1
- package/node_modules/@fps-games/babylon-renderer/dist/shadows/dynamic-shadow-system.d.ts +83 -0
- package/node_modules/@fps-games/babylon-renderer/dist/shadows/dynamic-shadow-system.d.ts.map +1 -0
- package/node_modules/@fps-games/babylon-renderer/dist/shadows/dynamic-shadow-system.js +561 -0
- package/node_modules/@fps-games/babylon-renderer/dist/shadows/dynamic-shadow-system.js.map +1 -0
- package/node_modules/@fps-games/babylon-renderer/package.json +1 -1
- package/node_modules/@fps-games/editor-babylon/dist/inspector-host.d.ts +2 -0
- package/node_modules/@fps-games/editor-babylon/dist/inspector-host.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-babylon/dist/inspector-host.js +1 -0
- package/node_modules/@fps-games/editor-babylon/dist/inspector-host.js.map +1 -1
- package/node_modules/@fps-games/editor-babylon/dist/material-property-adapter.d.ts +6 -2
- package/node_modules/@fps-games/editor-babylon/dist/material-property-adapter.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-babylon/dist/material-property-adapter.js +94 -24
- package/node_modules/@fps-games/editor-babylon/dist/material-property-adapter.js.map +1 -1
- package/node_modules/@fps-games/editor-babylon/dist/material-slot-source-resolver.d.ts +6 -2
- package/node_modules/@fps-games/editor-babylon/dist/material-slot-source-resolver.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-babylon/dist/material-slot-source-resolver.js +7 -0
- package/node_modules/@fps-games/editor-babylon/dist/material-slot-source-resolver.js.map +1 -1
- package/node_modules/@fps-games/editor-babylon/dist/monitor.d.ts +2 -0
- package/node_modules/@fps-games/editor-babylon/dist/monitor.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-babylon/dist/monitor.js +2 -0
- package/node_modules/@fps-games/editor-babylon/dist/monitor.js.map +1 -1
- package/node_modules/@fps-games/editor-babylon/dist/performance-monitor.d.ts +14 -0
- package/node_modules/@fps-games/editor-babylon/dist/performance-monitor.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-babylon/dist/performance-monitor.js +121 -2
- package/node_modules/@fps-games/editor-babylon/dist/performance-monitor.js.map +1 -1
- package/node_modules/@fps-games/editor-babylon/dist/projection-asset-container-importer.js +1 -5
- package/node_modules/@fps-games/editor-babylon/dist/projection-asset-container-importer.js.map +1 -1
- package/node_modules/@fps-games/editor-babylon/dist/projection.d.ts +18 -0
- package/node_modules/@fps-games/editor-babylon/dist/projection.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-babylon/dist/projection.js +367 -52
- package/node_modules/@fps-games/editor-babylon/dist/projection.js.map +1 -1
- package/node_modules/@fps-games/editor-babylon/dist/shadow-preview-controller.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-babylon/dist/shadow-preview-controller.js +96 -35
- package/node_modules/@fps-games/editor-babylon/dist/shadow-preview-controller.js.map +1 -1
- package/node_modules/@fps-games/editor-babylon/package.json +5 -5
- package/node_modules/@fps-games/editor-browser/dist/index.d.ts +3 -1
- package/node_modules/@fps-games/editor-browser/dist/index.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-browser/dist/index.js +1 -0
- package/node_modules/@fps-games/editor-browser/dist/index.js.map +1 -1
- package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-modal-dialog.d.ts +26 -0
- package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-modal-dialog.d.ts.map +1 -0
- package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-modal-dialog.js +187 -0
- package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-modal-dialog.js.map +1 -0
- package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-types.d.ts +17 -0
- package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-types.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-browser/dist/local-editor-ui.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-browser/dist/local-editor-ui.js +84 -0
- package/node_modules/@fps-games/editor-browser/dist/local-editor-ui.js.map +1 -1
- package/node_modules/@fps-games/editor-browser/package.json +3 -3
- package/node_modules/@fps-games/editor-core/package.json +2 -2
- package/node_modules/@fps-games/editor-forge-play/package.json +2 -2
- package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/forge-play-types.d.ts +4 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/forge-play-types.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/forge-play.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/forge-play.js +96 -12
- package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/forge-play.js.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/host-controller.d.ts +4 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/host-controller.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/host-controller.js +60 -5
- package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/host-controller.js.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/index.d.ts +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/index.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/index.js.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/lifecycle.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/lifecycle.js +62 -2
- package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/lifecycle.js.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/types.d.ts +27 -0
- package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/types.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/scene-source/driver.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/scene-source/driver.js +57 -3
- package/node_modules/@fps-games/editor-playable-sdk/dist/scene-source/driver.js.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/scene-source/types.d.ts +30 -0
- package/node_modules/@fps-games/editor-playable-sdk/dist/scene-source/types.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/session/hierarchy.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/session/hierarchy.js +18 -2
- package/node_modules/@fps-games/editor-playable-sdk/dist/session/hierarchy.js.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/session/patches.d.ts +1 -0
- package/node_modules/@fps-games/editor-playable-sdk/dist/session/patches.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/session/patches.js +1 -0
- package/node_modules/@fps-games/editor-playable-sdk/dist/session/patches.js.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/shadow-system/index.d.ts +1 -0
- package/node_modules/@fps-games/editor-playable-sdk/dist/shadow-system/index.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/shadow-system/index.js +1 -0
- package/node_modules/@fps-games/editor-playable-sdk/dist/shadow-system/index.js.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/shadow-system/runtime.d.ts +62 -0
- package/node_modules/@fps-games/editor-playable-sdk/dist/shadow-system/runtime.d.ts.map +1 -0
- package/node_modules/@fps-games/editor-playable-sdk/dist/shadow-system/runtime.js +410 -0
- package/node_modules/@fps-games/editor-playable-sdk/dist/shadow-system/runtime.js.map +1 -0
- package/node_modules/@fps-games/editor-playable-sdk/dist/shadow-system/types.d.ts +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/dist/shadow-system/types.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-playable-sdk/package.json +3 -3
- package/node_modules/@fps-games/editor-protocol/dist/index.d.ts +1 -1
- package/node_modules/@fps-games/editor-protocol/dist/index.d.ts.map +1 -1
- package/node_modules/@fps-games/editor-protocol/dist/index.js.map +1 -1
- package/node_modules/@fps-games/editor-protocol/package.json +1 -1
- package/package.json +8 -8
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Camera } from '@babylonjs/core/Cameras/camera';
|
|
2
|
+
import type { DirectionalLight } from '@babylonjs/core/Lights/directionalLight';
|
|
3
|
+
import { ShadowGenerator } from '@babylonjs/core/Lights/Shadows/shadowGenerator';
|
|
4
|
+
import type { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';
|
|
5
|
+
import type { Scene } from '@babylonjs/core/scene';
|
|
6
|
+
import '@babylonjs/core/Lights/Shadows/shadowGeneratorSceneComponent.js';
|
|
7
|
+
export interface DynamicShadowParams {
|
|
8
|
+
opacity: number;
|
|
9
|
+
softness: number;
|
|
10
|
+
bias: number;
|
|
11
|
+
normalBias: number;
|
|
12
|
+
maxDistance: number;
|
|
13
|
+
resolution: 512 | 1024 | 2048 | 4096;
|
|
14
|
+
cascadeCount: 1 | 2 | 4;
|
|
15
|
+
blurKernel: number;
|
|
16
|
+
}
|
|
17
|
+
export interface DynamicShadowOptions {
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
camera?: Camera | null;
|
|
20
|
+
params: DynamicShadowParams;
|
|
21
|
+
useCsm?: boolean;
|
|
22
|
+
boundsPadding?: number;
|
|
23
|
+
stableSnapping?: boolean;
|
|
24
|
+
debug?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface DynamicShadowLightOrthoBounds {
|
|
27
|
+
left: number;
|
|
28
|
+
right: number;
|
|
29
|
+
top: number;
|
|
30
|
+
bottom: number;
|
|
31
|
+
minZ: number;
|
|
32
|
+
maxZ: number;
|
|
33
|
+
}
|
|
34
|
+
export interface DynamicShadowWorldBounds {
|
|
35
|
+
min: {
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
z: number;
|
|
39
|
+
};
|
|
40
|
+
max: {
|
|
41
|
+
x: number;
|
|
42
|
+
y: number;
|
|
43
|
+
z: number;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export interface DynamicShadowDiagnostics {
|
|
47
|
+
enabled: boolean;
|
|
48
|
+
casterCount: number;
|
|
49
|
+
receiverCount: number;
|
|
50
|
+
generator: {
|
|
51
|
+
className: string | null;
|
|
52
|
+
mapSize: unknown;
|
|
53
|
+
darkness: number | null;
|
|
54
|
+
bias: number | null;
|
|
55
|
+
normalBias: number | null;
|
|
56
|
+
blurKernel: number | null;
|
|
57
|
+
renderListCount: number;
|
|
58
|
+
useCsm: boolean;
|
|
59
|
+
} | null;
|
|
60
|
+
params: DynamicShadowParams;
|
|
61
|
+
bounds: {
|
|
62
|
+
world: DynamicShadowWorldBounds;
|
|
63
|
+
lightOrtho: DynamicShadowLightOrthoBounds;
|
|
64
|
+
texelSize: number;
|
|
65
|
+
cameraProjection: 'orthographic' | 'perspective' | 'none';
|
|
66
|
+
} | null;
|
|
67
|
+
fallbackReasons: string[];
|
|
68
|
+
}
|
|
69
|
+
export interface DynamicShadowSystem {
|
|
70
|
+
initialize(): void;
|
|
71
|
+
addCaster(mesh: AbstractMesh): boolean;
|
|
72
|
+
removeCaster(mesh: AbstractMesh): void;
|
|
73
|
+
addReceiver(mesh: AbstractMesh): void;
|
|
74
|
+
removeReceiver(mesh: AbstractMesh): void;
|
|
75
|
+
setCamera(camera: Camera | null): void;
|
|
76
|
+
setOptions(options: Partial<DynamicShadowOptions>): void;
|
|
77
|
+
refresh(): void;
|
|
78
|
+
getShadowGenerator(): ShadowGenerator | null;
|
|
79
|
+
getDiagnostics(): DynamicShadowDiagnostics;
|
|
80
|
+
dispose(): void;
|
|
81
|
+
}
|
|
82
|
+
export declare function createDynamicShadowSystem(scene: Scene, directionalLight: DirectionalLight, options?: Partial<DynamicShadowOptions>): DynamicShadowSystem;
|
|
83
|
+
//# sourceMappingURL=dynamic-shadow-system.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-shadow-system.d.ts","sourceRoot":"","sources":["../../src/shadows/dynamic-shadow-system.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
import { Camera } from '@babylonjs/core/Cameras/camera.js';
|
|
2
|
+
import { CascadedShadowGenerator } from '@babylonjs/core/Lights/Shadows/cascadedShadowGenerator.js';
|
|
3
|
+
import { ShadowGenerator } from '@babylonjs/core/Lights/Shadows/shadowGenerator.js';
|
|
4
|
+
import { Matrix, Vector3 } from '@babylonjs/core/Maths/math.vector.js';
|
|
5
|
+
import '@babylonjs/core/Lights/Shadows/shadowGeneratorSceneComponent.js';
|
|
6
|
+
const DEFAULT_DYNAMIC_SHADOW_PARAMS = {
|
|
7
|
+
opacity: 0.42,
|
|
8
|
+
softness: 0.4,
|
|
9
|
+
bias: 0.001,
|
|
10
|
+
normalBias: 0.01,
|
|
11
|
+
maxDistance: 48,
|
|
12
|
+
resolution: 1024,
|
|
13
|
+
cascadeCount: 2,
|
|
14
|
+
blurKernel: 4,
|
|
15
|
+
};
|
|
16
|
+
export function createDynamicShadowSystem(scene, directionalLight, options = {}) {
|
|
17
|
+
return new BabylonDynamicShadowSystem(scene, directionalLight, options);
|
|
18
|
+
}
|
|
19
|
+
class BabylonDynamicShadowSystem {
|
|
20
|
+
constructor(scene, directionalLight, options) {
|
|
21
|
+
this.scene = scene;
|
|
22
|
+
this.directionalLight = directionalLight;
|
|
23
|
+
this.shadowGenerator = null;
|
|
24
|
+
this.casters = new Set();
|
|
25
|
+
this.receivers = new Map();
|
|
26
|
+
this.receiverStates = new Map();
|
|
27
|
+
this.renderObserver = null;
|
|
28
|
+
this.initialized = false;
|
|
29
|
+
this.previousSceneShadowsEnabled = null;
|
|
30
|
+
this.previousLightShadowEnabled = null;
|
|
31
|
+
this.previousLightAutoUpdateExtends = null;
|
|
32
|
+
this.previousLightFrustum = null;
|
|
33
|
+
this.useCsmExplicit = false;
|
|
34
|
+
this.useCsmExplicit = hasExplicitUseCsm(options);
|
|
35
|
+
this.options = resolveDynamicShadowOptions(options);
|
|
36
|
+
this.diagnostics = this.createDiagnostics(null, []);
|
|
37
|
+
}
|
|
38
|
+
initialize() {
|
|
39
|
+
if (this.initialized || !this.options.enabled)
|
|
40
|
+
return;
|
|
41
|
+
this.previousSceneShadowsEnabled = this.scene.shadowsEnabled;
|
|
42
|
+
this.previousLightShadowEnabled = this.directionalLight.shadowEnabled;
|
|
43
|
+
this.previousLightAutoUpdateExtends = this.directionalLight.autoUpdateExtends;
|
|
44
|
+
this.previousLightFrustum = {
|
|
45
|
+
left: this.directionalLight.orthoLeft,
|
|
46
|
+
right: this.directionalLight.orthoRight,
|
|
47
|
+
top: this.directionalLight.orthoTop,
|
|
48
|
+
bottom: this.directionalLight.orthoBottom,
|
|
49
|
+
minZ: this.directionalLight.shadowMinZ,
|
|
50
|
+
maxZ: this.directionalLight.shadowMaxZ,
|
|
51
|
+
};
|
|
52
|
+
this.scene.shadowsEnabled = true;
|
|
53
|
+
this.directionalLight.shadowEnabled = true;
|
|
54
|
+
this.directionalLight.autoUpdateExtends = false;
|
|
55
|
+
this.ensureShadowGenerator();
|
|
56
|
+
this.renderObserver = this.scene.onBeforeRenderObservable.add(() => this.refresh());
|
|
57
|
+
this.initialized = true;
|
|
58
|
+
this.refresh();
|
|
59
|
+
}
|
|
60
|
+
addCaster(mesh) {
|
|
61
|
+
if (isDisposed(mesh))
|
|
62
|
+
return false;
|
|
63
|
+
this.casters.add(mesh);
|
|
64
|
+
if (!this.options.enabled || !this.initialized)
|
|
65
|
+
return true;
|
|
66
|
+
this.shadowGenerator?.addShadowCaster(mesh, true);
|
|
67
|
+
this.refresh();
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
removeCaster(mesh) {
|
|
71
|
+
this.casters.delete(mesh);
|
|
72
|
+
this.shadowGenerator?.removeShadowCaster(mesh, true);
|
|
73
|
+
this.refresh();
|
|
74
|
+
}
|
|
75
|
+
addReceiver(mesh) {
|
|
76
|
+
if (isDisposed(mesh))
|
|
77
|
+
return;
|
|
78
|
+
if (!this.receivers.has(mesh)) {
|
|
79
|
+
this.receivers.set(mesh, createReceiverInfo(mesh, this.receiverStates));
|
|
80
|
+
}
|
|
81
|
+
if (!this.options.enabled || !this.initialized)
|
|
82
|
+
return;
|
|
83
|
+
activateReceiverInfo(this.receivers.get(mesh));
|
|
84
|
+
this.refresh();
|
|
85
|
+
}
|
|
86
|
+
removeReceiver(mesh) {
|
|
87
|
+
const info = this.receivers.get(mesh);
|
|
88
|
+
if (info)
|
|
89
|
+
releaseReceiverInfo(info, this.receiverStates);
|
|
90
|
+
this.receivers.delete(mesh);
|
|
91
|
+
this.refresh();
|
|
92
|
+
}
|
|
93
|
+
setCamera(camera) {
|
|
94
|
+
this.options = {
|
|
95
|
+
...this.options,
|
|
96
|
+
camera,
|
|
97
|
+
};
|
|
98
|
+
if (this.shadowGenerator)
|
|
99
|
+
this.shadowGenerator.camera = camera;
|
|
100
|
+
this.refresh();
|
|
101
|
+
}
|
|
102
|
+
setOptions(options) {
|
|
103
|
+
const previous = this.options;
|
|
104
|
+
if (hasExplicitUseCsm(options))
|
|
105
|
+
this.useCsmExplicit = true;
|
|
106
|
+
this.options = resolveDynamicShadowOptions(options, this.options, this.useCsmExplicit);
|
|
107
|
+
if (previous.enabled && !this.options.enabled) {
|
|
108
|
+
this.dispose();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const generatorNeedsRecreate = previous.params.resolution !== this.options.params.resolution
|
|
112
|
+
|| previous.params.cascadeCount !== this.options.params.cascadeCount
|
|
113
|
+
|| previous.useCsm !== this.options.useCsm;
|
|
114
|
+
if (generatorNeedsRecreate && this.initialized)
|
|
115
|
+
this.recreateShadowGenerator();
|
|
116
|
+
else if (this.shadowGenerator)
|
|
117
|
+
this.shadowGenerator.camera = this.options.camera ?? null;
|
|
118
|
+
if (!previous.enabled && this.options.enabled)
|
|
119
|
+
this.initialize();
|
|
120
|
+
else
|
|
121
|
+
this.refresh();
|
|
122
|
+
}
|
|
123
|
+
refresh() {
|
|
124
|
+
if (!this.options.enabled || !this.initialized)
|
|
125
|
+
return;
|
|
126
|
+
this.pruneDisposedEntries();
|
|
127
|
+
const generator = this.ensureShadowGenerator();
|
|
128
|
+
if (!generator) {
|
|
129
|
+
this.diagnostics = this.createDiagnostics(null, ['shadow generator unavailable']);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
this.applyGeneratorParams(this.options.params);
|
|
133
|
+
this.syncShadowMapRenderList();
|
|
134
|
+
for (const receiver of this.receivers.values())
|
|
135
|
+
activateReceiverInfo(receiver);
|
|
136
|
+
const fit = this.fitDirectionalLightBounds();
|
|
137
|
+
this.diagnostics = this.createDiagnostics(fit, []);
|
|
138
|
+
}
|
|
139
|
+
getShadowGenerator() {
|
|
140
|
+
return this.shadowGenerator;
|
|
141
|
+
}
|
|
142
|
+
getDiagnostics() {
|
|
143
|
+
return cloneDynamicShadowDiagnostics(this.diagnostics);
|
|
144
|
+
}
|
|
145
|
+
dispose() {
|
|
146
|
+
if (this.renderObserver) {
|
|
147
|
+
this.scene.onBeforeRenderObservable.remove(this.renderObserver);
|
|
148
|
+
this.renderObserver = null;
|
|
149
|
+
}
|
|
150
|
+
for (const receiver of this.receivers.values())
|
|
151
|
+
releaseReceiverInfo(receiver, this.receiverStates);
|
|
152
|
+
this.receiverStates.clear();
|
|
153
|
+
this.receivers.clear();
|
|
154
|
+
this.casters.clear();
|
|
155
|
+
this.shadowGenerator?.dispose();
|
|
156
|
+
this.shadowGenerator = null;
|
|
157
|
+
if (this.previousSceneShadowsEnabled !== null) {
|
|
158
|
+
this.scene.shadowsEnabled = this.previousSceneShadowsEnabled;
|
|
159
|
+
this.previousSceneShadowsEnabled = null;
|
|
160
|
+
}
|
|
161
|
+
if (this.previousLightShadowEnabled !== null) {
|
|
162
|
+
this.directionalLight.shadowEnabled = this.previousLightShadowEnabled;
|
|
163
|
+
this.previousLightShadowEnabled = null;
|
|
164
|
+
}
|
|
165
|
+
if (this.previousLightAutoUpdateExtends !== null) {
|
|
166
|
+
this.directionalLight.autoUpdateExtends = this.previousLightAutoUpdateExtends;
|
|
167
|
+
this.previousLightAutoUpdateExtends = null;
|
|
168
|
+
}
|
|
169
|
+
if (this.previousLightFrustum) {
|
|
170
|
+
this.directionalLight.orthoLeft = this.previousLightFrustum.left;
|
|
171
|
+
this.directionalLight.orthoRight = this.previousLightFrustum.right;
|
|
172
|
+
this.directionalLight.orthoTop = this.previousLightFrustum.top;
|
|
173
|
+
this.directionalLight.orthoBottom = this.previousLightFrustum.bottom;
|
|
174
|
+
this.directionalLight.shadowMinZ = this.previousLightFrustum.minZ;
|
|
175
|
+
this.directionalLight.shadowMaxZ = this.previousLightFrustum.maxZ;
|
|
176
|
+
this.previousLightFrustum = null;
|
|
177
|
+
}
|
|
178
|
+
this.initialized = false;
|
|
179
|
+
this.diagnostics = this.createDiagnostics(null, []);
|
|
180
|
+
}
|
|
181
|
+
ensureShadowGenerator() {
|
|
182
|
+
if (this.shadowGenerator)
|
|
183
|
+
return this.shadowGenerator;
|
|
184
|
+
const params = this.options.params;
|
|
185
|
+
if (this.options.useCsm && params.cascadeCount > 1 && CascadedShadowGenerator.IsSupported) {
|
|
186
|
+
const generator = new CascadedShadowGenerator(params.resolution, this.directionalLight, undefined, this.options.camera ?? undefined);
|
|
187
|
+
generator.numCascades = params.cascadeCount;
|
|
188
|
+
generator.stabilizeCascades = true;
|
|
189
|
+
this.shadowGenerator = generator;
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
this.shadowGenerator = new ShadowGenerator(params.resolution, this.directionalLight, undefined, this.options.camera ?? undefined);
|
|
193
|
+
}
|
|
194
|
+
this.applyGeneratorParams(params);
|
|
195
|
+
return this.shadowGenerator;
|
|
196
|
+
}
|
|
197
|
+
recreateShadowGenerator() {
|
|
198
|
+
const existingCasters = [...this.casters];
|
|
199
|
+
this.shadowGenerator?.dispose();
|
|
200
|
+
this.shadowGenerator = null;
|
|
201
|
+
const generator = this.ensureShadowGenerator();
|
|
202
|
+
for (const caster of existingCasters) {
|
|
203
|
+
generator?.addShadowCaster(caster, true);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
applyGeneratorParams(params) {
|
|
207
|
+
const generator = this.shadowGenerator;
|
|
208
|
+
if (!generator)
|
|
209
|
+
return;
|
|
210
|
+
generator.useBlurExponentialShadowMap = false;
|
|
211
|
+
generator.useKernelBlur = false;
|
|
212
|
+
generator.usePercentageCloserFiltering = true;
|
|
213
|
+
generator.filteringQuality = ShadowGenerator.QUALITY_HIGH;
|
|
214
|
+
generator.setDarkness(clamp01(1 - params.opacity));
|
|
215
|
+
generator.bias = params.bias;
|
|
216
|
+
generator.normalBias = params.normalBias;
|
|
217
|
+
if (generator instanceof CascadedShadowGenerator) {
|
|
218
|
+
generator.numCascades = params.cascadeCount;
|
|
219
|
+
generator.shadowMaxZ = params.maxDistance;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
syncShadowMapRenderList() {
|
|
223
|
+
const renderList = this.shadowGenerator?.getShadowMap?.()?.renderList;
|
|
224
|
+
if (!renderList)
|
|
225
|
+
return;
|
|
226
|
+
renderList.length = 0;
|
|
227
|
+
for (const caster of this.casters) {
|
|
228
|
+
if (!isDisposed(caster)) {
|
|
229
|
+
this.shadowGenerator?.addShadowCaster(caster, true);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
fitDirectionalLightBounds() {
|
|
234
|
+
const params = this.options.params;
|
|
235
|
+
const points = this.collectCoveragePoints(params);
|
|
236
|
+
if (points.length === 0)
|
|
237
|
+
return null;
|
|
238
|
+
const worldBounds = boundsFromPoints(points);
|
|
239
|
+
const viewMatrix = createShadowViewMatrix(this.directionalLight);
|
|
240
|
+
const lightPoints = points.map(point => Vector3.TransformCoordinates(point, viewMatrix));
|
|
241
|
+
const lightBounds = boundsFromPoints(lightPoints);
|
|
242
|
+
const padding = readPositiveNumber(this.options.boundsPadding, Math.max(0.5, params.maxDistance * 0.025));
|
|
243
|
+
const rawLeft = lightBounds.min.x - padding;
|
|
244
|
+
const rawRight = lightBounds.max.x + padding;
|
|
245
|
+
const rawBottom = lightBounds.min.y - padding;
|
|
246
|
+
const rawTop = lightBounds.max.y + padding;
|
|
247
|
+
const width = Math.max(1e-4, rawRight - rawLeft);
|
|
248
|
+
const height = Math.max(1e-4, rawTop - rawBottom);
|
|
249
|
+
const texelSize = Math.max(width, height) / params.resolution;
|
|
250
|
+
const bounds = this.options.stableSnapping === false || texelSize <= 0
|
|
251
|
+
? {
|
|
252
|
+
left: rawLeft,
|
|
253
|
+
right: rawRight,
|
|
254
|
+
bottom: rawBottom,
|
|
255
|
+
top: rawTop,
|
|
256
|
+
minZ: lightBounds.min.z - padding,
|
|
257
|
+
maxZ: lightBounds.max.z + padding,
|
|
258
|
+
}
|
|
259
|
+
: {
|
|
260
|
+
left: Math.floor(rawLeft / texelSize) * texelSize,
|
|
261
|
+
right: Math.ceil(rawRight / texelSize) * texelSize,
|
|
262
|
+
bottom: Math.floor(rawBottom / texelSize) * texelSize,
|
|
263
|
+
top: Math.ceil(rawTop / texelSize) * texelSize,
|
|
264
|
+
minZ: Math.floor((lightBounds.min.z - padding) / texelSize) * texelSize,
|
|
265
|
+
maxZ: Math.ceil((lightBounds.max.z + padding) / texelSize) * texelSize,
|
|
266
|
+
};
|
|
267
|
+
this.directionalLight.orthoLeft = bounds.left;
|
|
268
|
+
this.directionalLight.orthoRight = bounds.right;
|
|
269
|
+
this.directionalLight.orthoBottom = bounds.bottom;
|
|
270
|
+
this.directionalLight.orthoTop = bounds.top;
|
|
271
|
+
this.directionalLight.shadowMinZ = bounds.minZ;
|
|
272
|
+
this.directionalLight.shadowMaxZ = Math.max(this.directionalLight.shadowMinZ + 1, bounds.maxZ);
|
|
273
|
+
return {
|
|
274
|
+
world: {
|
|
275
|
+
min: serializeVec3(worldBounds.min),
|
|
276
|
+
max: serializeVec3(worldBounds.max),
|
|
277
|
+
},
|
|
278
|
+
lightOrtho: {
|
|
279
|
+
left: bounds.left,
|
|
280
|
+
right: bounds.right,
|
|
281
|
+
bottom: bounds.bottom,
|
|
282
|
+
top: bounds.top,
|
|
283
|
+
minZ: this.directionalLight.shadowMinZ,
|
|
284
|
+
maxZ: this.directionalLight.shadowMaxZ,
|
|
285
|
+
},
|
|
286
|
+
texelSize,
|
|
287
|
+
cameraProjection: readCameraProjection(this.options.camera),
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
collectCoveragePoints(params) {
|
|
291
|
+
const points = [];
|
|
292
|
+
const lightDirection = readLightDirection(this.directionalLight.getShadowDirection(0));
|
|
293
|
+
const shadowOffset = lightDirection.scale(params.maxDistance);
|
|
294
|
+
for (const caster of this.casters) {
|
|
295
|
+
points.push(...readMeshBoundsCorners(caster));
|
|
296
|
+
for (const corner of readMeshBoundsCorners(caster))
|
|
297
|
+
points.push(corner.add(shadowOffset));
|
|
298
|
+
}
|
|
299
|
+
for (const receiver of this.receivers.keys())
|
|
300
|
+
points.push(...readMeshBoundsCorners(receiver));
|
|
301
|
+
points.push(...readCameraCoveragePoints(this.options.camera, this.scene, params.maxDistance));
|
|
302
|
+
return points.filter(point => Number.isFinite(point.x) && Number.isFinite(point.y) && Number.isFinite(point.z));
|
|
303
|
+
}
|
|
304
|
+
pruneDisposedEntries() {
|
|
305
|
+
for (const caster of [...this.casters]) {
|
|
306
|
+
if (isDisposed(caster))
|
|
307
|
+
this.casters.delete(caster);
|
|
308
|
+
}
|
|
309
|
+
for (const [receiver, info] of [...this.receivers]) {
|
|
310
|
+
if (isDisposed(receiver)) {
|
|
311
|
+
releaseReceiverInfo(info, this.receiverStates);
|
|
312
|
+
this.receivers.delete(receiver);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
createDiagnostics(bounds, fallbackReasons) {
|
|
317
|
+
const generator = this.shadowGenerator;
|
|
318
|
+
const renderList = generator?.getShadowMap?.()?.renderList ?? [];
|
|
319
|
+
return {
|
|
320
|
+
enabled: this.options.enabled,
|
|
321
|
+
casterCount: this.casters.size,
|
|
322
|
+
receiverCount: this.receivers.size,
|
|
323
|
+
generator: generator
|
|
324
|
+
? {
|
|
325
|
+
className: generator.getClassName?.() ?? null,
|
|
326
|
+
mapSize: generator.getShadowMap?.()?.getSize?.() ?? null,
|
|
327
|
+
darkness: generator.getDarkness?.() ?? null,
|
|
328
|
+
bias: generator.bias ?? null,
|
|
329
|
+
normalBias: generator.normalBias ?? null,
|
|
330
|
+
blurKernel: generator.blurKernel ?? null,
|
|
331
|
+
renderListCount: renderList.length,
|
|
332
|
+
useCsm: generator instanceof CascadedShadowGenerator,
|
|
333
|
+
}
|
|
334
|
+
: null,
|
|
335
|
+
params: { ...this.options.params },
|
|
336
|
+
bounds,
|
|
337
|
+
fallbackReasons,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
function resolveDynamicShadowOptions(options, fallback, preserveFallbackUseCsm = false) {
|
|
342
|
+
const params = resolveDynamicShadowParams(options.params, fallback?.params);
|
|
343
|
+
return {
|
|
344
|
+
enabled: options.enabled ?? fallback?.enabled ?? true,
|
|
345
|
+
camera: options.camera ?? fallback?.camera ?? null,
|
|
346
|
+
params,
|
|
347
|
+
useCsm: options.useCsm ?? (preserveFallbackUseCsm ? fallback?.useCsm : undefined) ?? params.cascadeCount > 1,
|
|
348
|
+
boundsPadding: readPositiveNumber(options.boundsPadding, fallback?.boundsPadding ?? Math.max(0.5, params.maxDistance * 0.025)),
|
|
349
|
+
stableSnapping: options.stableSnapping ?? fallback?.stableSnapping ?? true,
|
|
350
|
+
debug: options.debug ?? fallback?.debug ?? false,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function hasExplicitUseCsm(options) {
|
|
354
|
+
return Object.prototype.hasOwnProperty.call(options, 'useCsm') && typeof options.useCsm === 'boolean';
|
|
355
|
+
}
|
|
356
|
+
function resolveDynamicShadowParams(params, fallback = DEFAULT_DYNAMIC_SHADOW_PARAMS) {
|
|
357
|
+
return {
|
|
358
|
+
opacity: clamp01(readFiniteNumber(params?.opacity, fallback.opacity)),
|
|
359
|
+
softness: clamp01(readFiniteNumber(params?.softness, fallback.softness)),
|
|
360
|
+
bias: readFiniteNumber(params?.bias, fallback.bias),
|
|
361
|
+
normalBias: readFiniteNumber(params?.normalBias, fallback.normalBias),
|
|
362
|
+
maxDistance: readPositiveNumber(params?.maxDistance, fallback.maxDistance),
|
|
363
|
+
resolution: readShadowResolution(params?.resolution, fallback.resolution),
|
|
364
|
+
cascadeCount: readCascadeCount(params?.cascadeCount, fallback.cascadeCount),
|
|
365
|
+
blurKernel: Math.max(0, Math.round(readFiniteNumber(params?.blurKernel, fallback.blurKernel))),
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
function createReceiverInfo(mesh, receiverStates) {
|
|
369
|
+
const trackedMeshes = [mesh];
|
|
370
|
+
const sourceMesh = mesh.sourceMesh;
|
|
371
|
+
if (sourceMesh && sourceMesh !== mesh)
|
|
372
|
+
trackedMeshes.push(sourceMesh);
|
|
373
|
+
for (const trackedMesh of trackedMeshes)
|
|
374
|
+
acquireReceiverState(trackedMesh, receiverStates);
|
|
375
|
+
return { mesh, trackedMeshes };
|
|
376
|
+
}
|
|
377
|
+
function activateReceiverInfo(info) {
|
|
378
|
+
if (!info)
|
|
379
|
+
return;
|
|
380
|
+
for (const mesh of info.trackedMeshes)
|
|
381
|
+
mesh.receiveShadows = true;
|
|
382
|
+
}
|
|
383
|
+
function acquireReceiverState(mesh, receiverStates) {
|
|
384
|
+
const existing = receiverStates.get(mesh);
|
|
385
|
+
if (existing) {
|
|
386
|
+
existing.refCount += 1;
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
receiverStates.set(mesh, {
|
|
390
|
+
mesh,
|
|
391
|
+
previousReceiveShadows: mesh.receiveShadows,
|
|
392
|
+
refCount: 1,
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
function releaseReceiverInfo(info, receiverStates) {
|
|
396
|
+
for (const mesh of info.trackedMeshes)
|
|
397
|
+
releaseReceiverState(mesh, receiverStates);
|
|
398
|
+
}
|
|
399
|
+
function releaseReceiverState(mesh, receiverStates) {
|
|
400
|
+
const state = receiverStates.get(mesh);
|
|
401
|
+
if (!state)
|
|
402
|
+
return;
|
|
403
|
+
state.refCount -= 1;
|
|
404
|
+
if (state.refCount > 0)
|
|
405
|
+
return;
|
|
406
|
+
state.mesh.receiveShadows = state.previousReceiveShadows;
|
|
407
|
+
receiverStates.delete(mesh);
|
|
408
|
+
}
|
|
409
|
+
function readMeshBoundsCorners(mesh) {
|
|
410
|
+
if (isDisposed(mesh))
|
|
411
|
+
return [];
|
|
412
|
+
mesh.computeWorldMatrix(true);
|
|
413
|
+
const bounds = mesh.getHierarchyBoundingVectors(true);
|
|
414
|
+
return createBoundsCorners(bounds.min, bounds.max);
|
|
415
|
+
}
|
|
416
|
+
function readCameraCoveragePoints(camera, scene, maxDistance) {
|
|
417
|
+
if (!camera)
|
|
418
|
+
return [];
|
|
419
|
+
const position = camera.globalPosition ?? camera.position;
|
|
420
|
+
if (!position)
|
|
421
|
+
return [];
|
|
422
|
+
const forward = safeCameraDirection(camera, Vector3.Forward(), new Vector3(0, 0, 1));
|
|
423
|
+
const right = safeCameraDirection(camera, Vector3.Right(), new Vector3(1, 0, 0));
|
|
424
|
+
const up = safeCameraDirection(camera, Vector3.Up(), new Vector3(0, 1, 0));
|
|
425
|
+
const farDistance = Math.max(1, Math.min(maxDistance, readPositiveNumber(camera.maxZ, maxDistance)));
|
|
426
|
+
const nearDistance = Math.max(0.1, Math.min(farDistance, readPositiveNumber(camera.minZ, 0.1)));
|
|
427
|
+
const aspect = readSceneAspect(scene);
|
|
428
|
+
if (camera.mode === Camera.ORTHOGRAPHIC_CAMERA) {
|
|
429
|
+
const halfHeight = Math.max(0.5, Math.abs(readFiniteNumber(camera.orthoTop, 1) - readFiniteNumber(camera.orthoBottom, -1)) * 0.5);
|
|
430
|
+
const halfWidth = Math.max(0.5, Math.abs(readFiniteNumber(camera.orthoRight, aspect) - readFiniteNumber(camera.orthoLeft, -aspect)) * 0.5);
|
|
431
|
+
return [
|
|
432
|
+
...createCameraPlaneCorners(position.add(forward.scale(nearDistance)), right, up, halfWidth, halfHeight),
|
|
433
|
+
...createCameraPlaneCorners(position.add(forward.scale(farDistance)), right, up, halfWidth, halfHeight),
|
|
434
|
+
];
|
|
435
|
+
}
|
|
436
|
+
const fov = readPositiveNumber(camera.fov, 0.8);
|
|
437
|
+
const farHalfHeight = Math.tan(fov * 0.5) * farDistance;
|
|
438
|
+
const farHalfWidth = farHalfHeight * aspect;
|
|
439
|
+
const nearHalfHeight = Math.tan(fov * 0.5) * nearDistance;
|
|
440
|
+
const nearHalfWidth = nearHalfHeight * aspect;
|
|
441
|
+
return [
|
|
442
|
+
...createCameraPlaneCorners(position.add(forward.scale(nearDistance)), right, up, nearHalfWidth, nearHalfHeight),
|
|
443
|
+
...createCameraPlaneCorners(position.add(forward.scale(farDistance)), right, up, farHalfWidth, farHalfHeight),
|
|
444
|
+
];
|
|
445
|
+
}
|
|
446
|
+
function createCameraPlaneCorners(center, right, up, halfWidth, halfHeight) {
|
|
447
|
+
return [
|
|
448
|
+
center.add(right.scale(-halfWidth)).add(up.scale(-halfHeight)),
|
|
449
|
+
center.add(right.scale(halfWidth)).add(up.scale(-halfHeight)),
|
|
450
|
+
center.add(right.scale(halfWidth)).add(up.scale(halfHeight)),
|
|
451
|
+
center.add(right.scale(-halfWidth)).add(up.scale(halfHeight)),
|
|
452
|
+
];
|
|
453
|
+
}
|
|
454
|
+
function createShadowViewMatrix(light) {
|
|
455
|
+
let lightPosition = light.position;
|
|
456
|
+
if (light.computeTransformedInformation()) {
|
|
457
|
+
lightPosition = light.transformedPosition;
|
|
458
|
+
}
|
|
459
|
+
const lightDirection = readLightDirection(light.getShadowDirection(0));
|
|
460
|
+
if (Math.abs(Vector3.Dot(lightDirection, Vector3.Up())) === 1) {
|
|
461
|
+
lightDirection.z = 1e-13;
|
|
462
|
+
}
|
|
463
|
+
return Matrix.LookAtLH(lightPosition, lightPosition.add(lightDirection), Vector3.Up());
|
|
464
|
+
}
|
|
465
|
+
function boundsFromPoints(points) {
|
|
466
|
+
const min = new Vector3(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY);
|
|
467
|
+
const max = new Vector3(Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY);
|
|
468
|
+
for (const point of points) {
|
|
469
|
+
min.minimizeInPlace(point);
|
|
470
|
+
max.maximizeInPlace(point);
|
|
471
|
+
}
|
|
472
|
+
return { min, max };
|
|
473
|
+
}
|
|
474
|
+
function createBoundsCorners(min, max) {
|
|
475
|
+
return [
|
|
476
|
+
new Vector3(min.x, min.y, min.z),
|
|
477
|
+
new Vector3(max.x, min.y, min.z),
|
|
478
|
+
new Vector3(max.x, max.y, min.z),
|
|
479
|
+
new Vector3(min.x, max.y, min.z),
|
|
480
|
+
new Vector3(min.x, min.y, max.z),
|
|
481
|
+
new Vector3(max.x, min.y, max.z),
|
|
482
|
+
new Vector3(max.x, max.y, max.z),
|
|
483
|
+
new Vector3(min.x, max.y, max.z),
|
|
484
|
+
];
|
|
485
|
+
}
|
|
486
|
+
function safeCameraDirection(camera, localAxis, fallback) {
|
|
487
|
+
try {
|
|
488
|
+
const direction = camera.getDirection(localAxis);
|
|
489
|
+
if (isFiniteVector(direction) && direction.lengthSquared() > 1e-8)
|
|
490
|
+
return direction.normalize();
|
|
491
|
+
}
|
|
492
|
+
catch {
|
|
493
|
+
// Camera direction is best-effort diagnostics input; use a stable fallback.
|
|
494
|
+
}
|
|
495
|
+
return fallback.clone();
|
|
496
|
+
}
|
|
497
|
+
function readLightDirection(direction) {
|
|
498
|
+
return isFiniteVector(direction) && direction.lengthSquared() > 1e-8
|
|
499
|
+
? direction.clone().normalize()
|
|
500
|
+
: new Vector3(-0.3, -1, -0.2).normalize();
|
|
501
|
+
}
|
|
502
|
+
function readCameraProjection(camera) {
|
|
503
|
+
if (!camera)
|
|
504
|
+
return 'none';
|
|
505
|
+
return camera.mode === Camera.ORTHOGRAPHIC_CAMERA ? 'orthographic' : 'perspective';
|
|
506
|
+
}
|
|
507
|
+
function readSceneAspect(scene) {
|
|
508
|
+
const engine = scene.getEngine();
|
|
509
|
+
const width = Math.max(1, engine.getRenderWidth());
|
|
510
|
+
const height = Math.max(1, engine.getRenderHeight());
|
|
511
|
+
return width / height;
|
|
512
|
+
}
|
|
513
|
+
function cloneDynamicShadowDiagnostics(diagnostics) {
|
|
514
|
+
return {
|
|
515
|
+
...diagnostics,
|
|
516
|
+
generator: diagnostics.generator ? { ...diagnostics.generator } : null,
|
|
517
|
+
params: { ...diagnostics.params },
|
|
518
|
+
bounds: diagnostics.bounds
|
|
519
|
+
? {
|
|
520
|
+
world: {
|
|
521
|
+
min: { ...diagnostics.bounds.world.min },
|
|
522
|
+
max: { ...diagnostics.bounds.world.max },
|
|
523
|
+
},
|
|
524
|
+
lightOrtho: { ...diagnostics.bounds.lightOrtho },
|
|
525
|
+
texelSize: diagnostics.bounds.texelSize,
|
|
526
|
+
cameraProjection: diagnostics.bounds.cameraProjection,
|
|
527
|
+
}
|
|
528
|
+
: null,
|
|
529
|
+
fallbackReasons: [...diagnostics.fallbackReasons],
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
function serializeVec3(value) {
|
|
533
|
+
return { x: value.x, y: value.y, z: value.z };
|
|
534
|
+
}
|
|
535
|
+
function isFiniteVector(value) {
|
|
536
|
+
return Number.isFinite(value.x) && Number.isFinite(value.y) && Number.isFinite(value.z);
|
|
537
|
+
}
|
|
538
|
+
function isDisposed(mesh) {
|
|
539
|
+
return typeof mesh.isDisposed === 'function' && mesh.isDisposed();
|
|
540
|
+
}
|
|
541
|
+
function readFiniteNumber(value, fallback) {
|
|
542
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : fallback;
|
|
543
|
+
}
|
|
544
|
+
function readPositiveNumber(value, fallback) {
|
|
545
|
+
const number = readFiniteNumber(value, fallback);
|
|
546
|
+
return number > 0 ? number : fallback;
|
|
547
|
+
}
|
|
548
|
+
function clamp01(value) {
|
|
549
|
+
if (!Number.isFinite(value))
|
|
550
|
+
return 0;
|
|
551
|
+
return Math.min(1, Math.max(0, value));
|
|
552
|
+
}
|
|
553
|
+
function readShadowResolution(value, fallback) {
|
|
554
|
+
return value === 512 || value === 1024 || value === 2048 || value === 4096
|
|
555
|
+
? value
|
|
556
|
+
: fallback;
|
|
557
|
+
}
|
|
558
|
+
function readCascadeCount(value, fallback) {
|
|
559
|
+
return value === 1 || value === 2 || value === 4 ? value : fallback;
|
|
560
|
+
}
|
|
561
|
+
//# sourceMappingURL=dynamic-shadow-system.js.map
|