@needle-tools/three-mesh-effects 0.1.0-alpha → 0.1.0-alpha.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/LICENSE +21 -21
- package/README.md +94 -88
- package/build/deformation-runtime.js.map +1 -1
- package/build/impostor-runtime-needle-engine.js.map +1 -1
- package/build/impostor-runtime.js.map +1 -1
- package/build/internal/deformation/cloth-surface.js.map +1 -1
- package/build/internal/deformation/fur-surface.js.map +1 -1
- package/build/internal/deformation/ik-constraints.js.map +1 -1
- package/build/internal/deformation/joints-json.js.map +1 -1
- package/build/internal/deformation/limits.js.map +1 -1
- package/build/internal/deformation/motion-settings.js.map +1 -1
- package/build/internal/deformation/pin-cloth.js.map +1 -1
- package/build/internal/deformation/pin-ik.js.map +1 -1
- package/build/internal/deformation/pin-types.js.map +1 -1
- package/build/internal/deformation/pin-wiggle.js.map +1 -1
- package/build/internal/deformation/pose-slots.js.map +1 -1
- package/build/internal/deformation/pose-timeline.js.map +1 -1
- package/build/internal/deformation/rig-drivers.js.map +1 -1
- package/build/internal/deformation/rig-extension.js.map +1 -1
- package/build/internal/deformation/rig-runtime.js.map +1 -1
- package/build/internal/deformation/wind.js.map +1 -1
- package/build/internal/impostor/impostor-metadata.js.map +1 -1
- package/build/internal/impostor/impostor-node-material.js.map +1 -1
- package/build/internal/impostor/impostor-runtime-support.js.map +1 -1
- package/build/internal/impostor/octahedral.js.map +1 -1
- package/build/internal/pixel-impostor/pixel-impostor-display.js.map +1 -1
- package/build/internal/pixel-impostor/pixel-impostor-metadata.js.map +1 -1
- package/build/internal/pixel-impostor/pixel-impostor-runtime.js.map +1 -1
- package/build/internal/rendering/skin-projection.js +52 -52
- package/build/internal/rendering/skin-projection.js.map +2 -2
- package/build/internal/rendering/surface-query.js +52 -52
- package/build/internal/rendering/surface-query.js.map +2 -2
- package/build/internal/rendering/wireframe.js.map +1 -1
- package/build/internal/rendering/wrap-preview-settings.js.map +1 -1
- package/build/internal/rendering/wrap-preview.js +52 -52
- package/build/internal/rendering/wrap-preview.js.map +2 -2
- package/build/internal/rendering/wrap-skin.js +52 -52
- package/build/internal/rendering/wrap-skin.js.map +2 -2
- package/build/pixel-impostor-runtime.js.map +1 -1
- package/build/wrap-effects.js +52 -52
- package/build/wrap-effects.js.map +2 -2
- package/package.json +107 -94
- package/src/deformation/cloth-surface.ts +223 -223
- package/src/deformation/fur-surface.ts +129 -129
- package/src/deformation/ik-constraints.ts +37 -37
- package/src/deformation/joints-json.ts +94 -94
- package/src/deformation/limits.ts +25 -25
- package/src/deformation/motion-settings.ts +9 -9
- package/src/deformation/pin-cloth.ts +149 -149
- package/src/deformation/pin-ik.ts +582 -582
- package/src/deformation/pin-types.ts +22 -22
- package/src/deformation/pin-wiggle.ts +119 -119
- package/src/deformation/pose-slots.ts +106 -106
- package/src/deformation/pose-timeline.ts +242 -242
- package/src/deformation/rig-drivers.ts +32 -32
- package/src/deformation/rig-extension.ts +87 -87
- package/src/deformation/rig-runtime.ts +416 -416
- package/src/deformation/wind.ts +36 -36
- package/src/impostor/impostor-metadata.js +137 -137
- package/src/impostor/impostor-node-material.js +1581 -1581
- package/src/impostor/impostor-runtime-support.js +139 -139
- package/src/impostor/octahedral.js +280 -280
- package/src/pixel-impostor/pixel-impostor-display.js +794 -794
- package/src/pixel-impostor/pixel-impostor-metadata.js +74 -74
- package/src/pixel-impostor/pixel-impostor-runtime.js +78 -78
- package/src/public/deformation-runtime.ts +3 -3
- package/src/public/impostor-runtime-needle-engine.js +56 -56
- package/src/public/impostor-runtime.js +21 -21
- package/src/public/pixel-impostor-runtime.js +5 -5
- package/src/public/wrap-effects.js +21 -21
- package/src/rendering/skin-projection.js +113 -113
- package/src/rendering/surface-query.js +88 -88
- package/src/rendering/wireframe.js +115 -115
- package/src/rendering/wrap-preview-settings.js +123 -123
- package/src/rendering/wrap-preview.js +645 -645
- package/src/rendering/wrap-skin.js +109 -109
- package/build/internal/public/deformation-runtime.js +0 -2143
- package/build/internal/public/deformation-runtime.js.map +0 -7
- package/build/internal/public/impostor-runtime-needle-engine.js +0 -42
- package/build/internal/public/impostor-runtime-needle-engine.js.map +0 -7
- package/build/internal/public/impostor-runtime.js +0 -1333
- package/build/internal/public/impostor-runtime.js.map +0 -7
- package/build/internal/public/pixel-impostor-runtime.js +0 -876
- package/build/internal/public/pixel-impostor-runtime.js.map +0 -7
- package/build/internal/public/wrap-effects.js +0 -5640
- package/build/internal/public/wrap-effects.js.map +0 -7
package/src/deformation/wind.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { Vector3 } from 'three';
|
|
2
|
-
|
|
3
|
-
export const MAX_WIND_STRENGTH = 4;
|
|
4
|
-
|
|
5
|
-
/** A single weather control drives pin motion and surface pressure. Sparse pin
|
|
6
|
-
* loads stay bounded; fabric pressure has room to grow through a storm. */
|
|
7
|
-
export function windProfile(strength: number) {
|
|
8
|
-
const level = Math.max(0, Math.min(MAX_WIND_STRENGTH, strength));
|
|
9
|
-
const label = level === 0 ? 'Off' : level < .75 ? 'Breeze' : level < 1.5 ? 'Windy' : level < 2.5 ? 'Strong wind' : level < 3.3 ? 'Gale' : 'Storm';
|
|
10
|
-
return {
|
|
11
|
-
label,
|
|
12
|
-
load: 30 * level * level / (.8 + level * level),
|
|
13
|
-
surfaceLoad: 4 * level * level,
|
|
14
|
-
gust: .14 + .12 * level,
|
|
15
|
-
crosswind: .05 + .07 * level,
|
|
16
|
-
gustRate: .42 + .12 * level,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** Deterministic scene-local prevailing wind with slow gusts and spatially
|
|
21
|
-
* varying eddies. Force is an acceleration scaled to the model's size, so a
|
|
22
|
-
* tiny prop and a large character respond comparably at the same setting. */
|
|
23
|
-
export function windAcceleration(seconds: number, strength: number, scale: number, position: readonly number[]) {
|
|
24
|
-
if (strength <= 0) return new Vector3();
|
|
25
|
-
const size = Math.max(1e-4, scale);
|
|
26
|
-
const profile = windProfile(strength);
|
|
27
|
-
// Advect the gust bands along +X. Nearby controls see related wind, while
|
|
28
|
-
// their phase delay keeps a large sheet or branch hierarchy from moving as
|
|
29
|
-
// one perfectly synchronized rigid object.
|
|
30
|
-
const along = position[0] / size, lateral = (position[1] * .67 + position[2] * .33) / size;
|
|
31
|
-
const slow = seconds * profile.gustRate - along * .55;
|
|
32
|
-
const fast = seconds * (profile.gustRate * 2.7) - along * 1.4 + lateral * .4;
|
|
33
|
-
const gust = Math.max(.2, 1 + profile.gust * (.7 * Math.sin(slow) + .3 * Math.sin(fast + 1.3)));
|
|
34
|
-
const cross = profile.crosswind * (.65 * Math.sin(fast + lateral) + .35 * Math.sin(slow * .73 - lateral * .6));
|
|
35
|
-
return new Vector3(1, cross * .35, cross).normalize().multiplyScalar(profile.load * size * gust);
|
|
36
|
-
}
|
|
1
|
+
import { Vector3 } from 'three';
|
|
2
|
+
|
|
3
|
+
export const MAX_WIND_STRENGTH = 4;
|
|
4
|
+
|
|
5
|
+
/** A single weather control drives pin motion and surface pressure. Sparse pin
|
|
6
|
+
* loads stay bounded; fabric pressure has room to grow through a storm. */
|
|
7
|
+
export function windProfile(strength: number) {
|
|
8
|
+
const level = Math.max(0, Math.min(MAX_WIND_STRENGTH, strength));
|
|
9
|
+
const label = level === 0 ? 'Off' : level < .75 ? 'Breeze' : level < 1.5 ? 'Windy' : level < 2.5 ? 'Strong wind' : level < 3.3 ? 'Gale' : 'Storm';
|
|
10
|
+
return {
|
|
11
|
+
label,
|
|
12
|
+
load: 30 * level * level / (.8 + level * level),
|
|
13
|
+
surfaceLoad: 4 * level * level,
|
|
14
|
+
gust: .14 + .12 * level,
|
|
15
|
+
crosswind: .05 + .07 * level,
|
|
16
|
+
gustRate: .42 + .12 * level,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Deterministic scene-local prevailing wind with slow gusts and spatially
|
|
21
|
+
* varying eddies. Force is an acceleration scaled to the model's size, so a
|
|
22
|
+
* tiny prop and a large character respond comparably at the same setting. */
|
|
23
|
+
export function windAcceleration(seconds: number, strength: number, scale: number, position: readonly number[]) {
|
|
24
|
+
if (strength <= 0) return new Vector3();
|
|
25
|
+
const size = Math.max(1e-4, scale);
|
|
26
|
+
const profile = windProfile(strength);
|
|
27
|
+
// Advect the gust bands along +X. Nearby controls see related wind, while
|
|
28
|
+
// their phase delay keeps a large sheet or branch hierarchy from moving as
|
|
29
|
+
// one perfectly synchronized rigid object.
|
|
30
|
+
const along = position[0] / size, lateral = (position[1] * .67 + position[2] * .33) / size;
|
|
31
|
+
const slow = seconds * profile.gustRate - along * .55;
|
|
32
|
+
const fast = seconds * (profile.gustRate * 2.7) - along * 1.4 + lateral * .4;
|
|
33
|
+
const gust = Math.max(.2, 1 + profile.gust * (.7 * Math.sin(slow) + .3 * Math.sin(fast + 1.3)));
|
|
34
|
+
const cross = profile.crosswind * (.65 * Math.sin(fast + lateral) + .35 * Math.sin(slow * .73 - lateral * .6));
|
|
35
|
+
return new Vector3(1, cross * .35, cross).normalize().multiplyScalar(profile.load * size * gust);
|
|
36
|
+
}
|
|
@@ -1,137 +1,137 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
/** Primitive extension declaring an explicitly-bound Needle mesh impostor. */
|
|
4
|
-
export const NEEDLE_MESH_IMPOSTOR = 'NEEDLE_mesh_impostor';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @typedef {object} ImpostorDescriptor
|
|
8
|
-
* @property {1} version
|
|
9
|
-
* @property {'hemisphere' | 'full' | 'single'} mapping
|
|
10
|
-
* @property {number} frames
|
|
11
|
-
* @property {readonly [number, number, number]=} captureDirection
|
|
12
|
-
* @property {number} frameResolution
|
|
13
|
-
* @property {number} padding
|
|
14
|
-
* @property {number} radius
|
|
15
|
-
* @property {readonly [number, number, number]} boundsMin
|
|
16
|
-
* @property {readonly [number, number, number]} boundsMax
|
|
17
|
-
* @property {readonly [number, number, number]} center
|
|
18
|
-
* @property {readonly number[]} viewBounds
|
|
19
|
-
* @property {'captured-alpha+sdf-material' | 'sdf-base-alpha'} coverageEncoding
|
|
20
|
-
* @property {number} captureAlphaCutoff
|
|
21
|
-
* @property {number} alphaCutoff
|
|
22
|
-
* @property {number} blendZone
|
|
23
|
-
* @property {number} parallaxSteps
|
|
24
|
-
* @property {boolean} depthDerivedWeights
|
|
25
|
-
* @property {boolean} castShadow
|
|
26
|
-
* @property {boolean} receiveShadow
|
|
27
|
-
* @property {{occlusion: number, roughness: number, metalness: number}} material
|
|
28
|
-
* @property {{version: 4, layout: 'compact-atlas-v4', depthEncoding: 'lossless-geometry10-rgba', materialFrameResolution: number, emissive: boolean}=} compression
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
/** @param {unknown} value @returns {ImpostorDescriptor | null} */
|
|
32
|
-
export function parseImpostorDescriptor(value) {
|
|
33
|
-
if (!value || typeof value !== 'object') return null;
|
|
34
|
-
const descriptor = /** @type {Partial<ImpostorDescriptor>} */ (value);
|
|
35
|
-
if (
|
|
36
|
-
descriptor.version !== 1
|
|
37
|
-
|| (descriptor.mapping !== 'hemisphere' && descriptor.mapping !== 'full' && descriptor.mapping !== 'single')
|
|
38
|
-
|| !isPositiveInteger(descriptor.frames)
|
|
39
|
-
|| (descriptor.mapping === 'single'
|
|
40
|
-
? (descriptor.frames !== 1 || !isUnitVec3(descriptor.captureDirection))
|
|
41
|
-
: false)
|
|
42
|
-
|| !isPositiveInteger(descriptor.frameResolution)
|
|
43
|
-
|| !isNonNegativeInteger(descriptor.padding)
|
|
44
|
-
|| !isPositiveFinite(descriptor.radius)
|
|
45
|
-
|| (descriptor.compression !== undefined && (
|
|
46
|
-
descriptor.compression.version !== 4
|
|
47
|
-
|| descriptor.compression.layout !== 'compact-atlas-v4'
|
|
48
|
-
|| descriptor.compression.depthEncoding !== 'lossless-geometry10-rgba'
|
|
49
|
-
|| !isPositiveInteger(descriptor.compression.materialFrameResolution)
|
|
50
|
-
|| typeof descriptor.compression.emissive !== 'boolean'
|
|
51
|
-
))
|
|
52
|
-
|| !isFiniteVec3(descriptor.boundsMin)
|
|
53
|
-
|| !isFiniteVec3(descriptor.boundsMax)
|
|
54
|
-
|| !isFiniteVec3(descriptor.center)
|
|
55
|
-
|| !Array.isArray(descriptor.viewBounds)
|
|
56
|
-
|| descriptor.viewBounds.length !== (descriptor.frames ?? 0) * (descriptor.frames ?? 0) * 4
|
|
57
|
-
|| !descriptor.viewBounds.every(Number.isFinite)
|
|
58
|
-
|| (descriptor.coverageEncoding !== 'captured-alpha+sdf-material'
|
|
59
|
-
&& descriptor.coverageEncoding !== 'sdf-base-alpha')
|
|
60
|
-
|| !isUnitInterval(descriptor.captureAlphaCutoff)
|
|
61
|
-
|| !isUnitInterval(descriptor.alphaCutoff)
|
|
62
|
-
|| !isBlendZone(descriptor.blendZone)
|
|
63
|
-
|| !isNonNegativeInteger(descriptor.parallaxSteps)
|
|
64
|
-
|| typeof descriptor.depthDerivedWeights !== 'boolean'
|
|
65
|
-
|| typeof descriptor.castShadow !== 'boolean'
|
|
66
|
-
|| typeof descriptor.receiveShadow !== 'boolean'
|
|
67
|
-
|| !descriptor.material
|
|
68
|
-
|| !isUnitInterval(descriptor.material.occlusion)
|
|
69
|
-
|| !isUnitInterval(descriptor.material.roughness)
|
|
70
|
-
|| !isUnitInterval(descriptor.material.metalness)
|
|
71
|
-
) return null;
|
|
72
|
-
const valid = /** @type {ImpostorDescriptor} */ (descriptor);
|
|
73
|
-
return {
|
|
74
|
-
version: 1,
|
|
75
|
-
mapping: valid.mapping,
|
|
76
|
-
frames: valid.frames,
|
|
77
|
-
...(valid.mapping === 'single' ? { captureDirection: valid.captureDirection } : {}),
|
|
78
|
-
frameResolution: valid.frameResolution,
|
|
79
|
-
padding: valid.padding,
|
|
80
|
-
radius: valid.radius,
|
|
81
|
-
boundsMin: valid.boundsMin,
|
|
82
|
-
boundsMax: valid.boundsMax,
|
|
83
|
-
center: valid.center,
|
|
84
|
-
viewBounds: valid.viewBounds,
|
|
85
|
-
coverageEncoding: valid.coverageEncoding,
|
|
86
|
-
captureAlphaCutoff: valid.captureAlphaCutoff,
|
|
87
|
-
alphaCutoff: valid.alphaCutoff,
|
|
88
|
-
blendZone: valid.blendZone,
|
|
89
|
-
parallaxSteps: valid.parallaxSteps,
|
|
90
|
-
depthDerivedWeights: valid.depthDerivedWeights,
|
|
91
|
-
castShadow: valid.castShadow,
|
|
92
|
-
receiveShadow: valid.receiveShadow,
|
|
93
|
-
material: valid.material,
|
|
94
|
-
...(valid.compression ? { compression: valid.compression } : {}),
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** @param {unknown} value */
|
|
99
|
-
function isFiniteVec3(value) {
|
|
100
|
-
return Array.isArray(value) && value.length === 3 && value.every(Number.isFinite);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** @param {unknown} value */
|
|
104
|
-
function isUnitVec3(value) {
|
|
105
|
-
if (!isFiniteVec3(value)) return false;
|
|
106
|
-
const vector = /** @type {number[]} */ (value);
|
|
107
|
-
return Math.abs(Math.hypot(vector[0], vector[1], vector[2]) - 1) < 1e-4;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** @param {unknown} value */
|
|
111
|
-
function isPositiveInteger(value) {
|
|
112
|
-
return Number.isInteger(value) && /** @type {number} */ (value) > 0;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/** @param {unknown} value */
|
|
116
|
-
function isNonNegativeInteger(value) {
|
|
117
|
-
return Number.isInteger(value) && /** @type {number} */ (value) >= 0;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** @param {unknown} value */
|
|
121
|
-
function isPositiveFinite(value) {
|
|
122
|
-
return Number.isFinite(value) && /** @type {number} */ (value) > 0;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** @param {unknown} value */
|
|
126
|
-
function isUnitInterval(value) {
|
|
127
|
-
return Number.isFinite(value)
|
|
128
|
-
&& /** @type {number} */ (value) >= 0
|
|
129
|
-
&& /** @type {number} */ (value) <= 1;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/** @param {unknown} value */
|
|
133
|
-
function isBlendZone(value) {
|
|
134
|
-
return Number.isFinite(value)
|
|
135
|
-
&& /** @type {number} */ (value) >= 0.35
|
|
136
|
-
&& /** @type {number} */ (value) <= 1;
|
|
137
|
-
}
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/** Primitive extension declaring an explicitly-bound Needle mesh impostor. */
|
|
4
|
+
export const NEEDLE_MESH_IMPOSTOR = 'NEEDLE_mesh_impostor';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {object} ImpostorDescriptor
|
|
8
|
+
* @property {1} version
|
|
9
|
+
* @property {'hemisphere' | 'full' | 'single'} mapping
|
|
10
|
+
* @property {number} frames
|
|
11
|
+
* @property {readonly [number, number, number]=} captureDirection
|
|
12
|
+
* @property {number} frameResolution
|
|
13
|
+
* @property {number} padding
|
|
14
|
+
* @property {number} radius
|
|
15
|
+
* @property {readonly [number, number, number]} boundsMin
|
|
16
|
+
* @property {readonly [number, number, number]} boundsMax
|
|
17
|
+
* @property {readonly [number, number, number]} center
|
|
18
|
+
* @property {readonly number[]} viewBounds
|
|
19
|
+
* @property {'captured-alpha+sdf-material' | 'sdf-base-alpha'} coverageEncoding
|
|
20
|
+
* @property {number} captureAlphaCutoff
|
|
21
|
+
* @property {number} alphaCutoff
|
|
22
|
+
* @property {number} blendZone
|
|
23
|
+
* @property {number} parallaxSteps
|
|
24
|
+
* @property {boolean} depthDerivedWeights
|
|
25
|
+
* @property {boolean} castShadow
|
|
26
|
+
* @property {boolean} receiveShadow
|
|
27
|
+
* @property {{occlusion: number, roughness: number, metalness: number}} material
|
|
28
|
+
* @property {{version: 4, layout: 'compact-atlas-v4', depthEncoding: 'lossless-geometry10-rgba', materialFrameResolution: number, emissive: boolean}=} compression
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/** @param {unknown} value @returns {ImpostorDescriptor | null} */
|
|
32
|
+
export function parseImpostorDescriptor(value) {
|
|
33
|
+
if (!value || typeof value !== 'object') return null;
|
|
34
|
+
const descriptor = /** @type {Partial<ImpostorDescriptor>} */ (value);
|
|
35
|
+
if (
|
|
36
|
+
descriptor.version !== 1
|
|
37
|
+
|| (descriptor.mapping !== 'hemisphere' && descriptor.mapping !== 'full' && descriptor.mapping !== 'single')
|
|
38
|
+
|| !isPositiveInteger(descriptor.frames)
|
|
39
|
+
|| (descriptor.mapping === 'single'
|
|
40
|
+
? (descriptor.frames !== 1 || !isUnitVec3(descriptor.captureDirection))
|
|
41
|
+
: false)
|
|
42
|
+
|| !isPositiveInteger(descriptor.frameResolution)
|
|
43
|
+
|| !isNonNegativeInteger(descriptor.padding)
|
|
44
|
+
|| !isPositiveFinite(descriptor.radius)
|
|
45
|
+
|| (descriptor.compression !== undefined && (
|
|
46
|
+
descriptor.compression.version !== 4
|
|
47
|
+
|| descriptor.compression.layout !== 'compact-atlas-v4'
|
|
48
|
+
|| descriptor.compression.depthEncoding !== 'lossless-geometry10-rgba'
|
|
49
|
+
|| !isPositiveInteger(descriptor.compression.materialFrameResolution)
|
|
50
|
+
|| typeof descriptor.compression.emissive !== 'boolean'
|
|
51
|
+
))
|
|
52
|
+
|| !isFiniteVec3(descriptor.boundsMin)
|
|
53
|
+
|| !isFiniteVec3(descriptor.boundsMax)
|
|
54
|
+
|| !isFiniteVec3(descriptor.center)
|
|
55
|
+
|| !Array.isArray(descriptor.viewBounds)
|
|
56
|
+
|| descriptor.viewBounds.length !== (descriptor.frames ?? 0) * (descriptor.frames ?? 0) * 4
|
|
57
|
+
|| !descriptor.viewBounds.every(Number.isFinite)
|
|
58
|
+
|| (descriptor.coverageEncoding !== 'captured-alpha+sdf-material'
|
|
59
|
+
&& descriptor.coverageEncoding !== 'sdf-base-alpha')
|
|
60
|
+
|| !isUnitInterval(descriptor.captureAlphaCutoff)
|
|
61
|
+
|| !isUnitInterval(descriptor.alphaCutoff)
|
|
62
|
+
|| !isBlendZone(descriptor.blendZone)
|
|
63
|
+
|| !isNonNegativeInteger(descriptor.parallaxSteps)
|
|
64
|
+
|| typeof descriptor.depthDerivedWeights !== 'boolean'
|
|
65
|
+
|| typeof descriptor.castShadow !== 'boolean'
|
|
66
|
+
|| typeof descriptor.receiveShadow !== 'boolean'
|
|
67
|
+
|| !descriptor.material
|
|
68
|
+
|| !isUnitInterval(descriptor.material.occlusion)
|
|
69
|
+
|| !isUnitInterval(descriptor.material.roughness)
|
|
70
|
+
|| !isUnitInterval(descriptor.material.metalness)
|
|
71
|
+
) return null;
|
|
72
|
+
const valid = /** @type {ImpostorDescriptor} */ (descriptor);
|
|
73
|
+
return {
|
|
74
|
+
version: 1,
|
|
75
|
+
mapping: valid.mapping,
|
|
76
|
+
frames: valid.frames,
|
|
77
|
+
...(valid.mapping === 'single' ? { captureDirection: valid.captureDirection } : {}),
|
|
78
|
+
frameResolution: valid.frameResolution,
|
|
79
|
+
padding: valid.padding,
|
|
80
|
+
radius: valid.radius,
|
|
81
|
+
boundsMin: valid.boundsMin,
|
|
82
|
+
boundsMax: valid.boundsMax,
|
|
83
|
+
center: valid.center,
|
|
84
|
+
viewBounds: valid.viewBounds,
|
|
85
|
+
coverageEncoding: valid.coverageEncoding,
|
|
86
|
+
captureAlphaCutoff: valid.captureAlphaCutoff,
|
|
87
|
+
alphaCutoff: valid.alphaCutoff,
|
|
88
|
+
blendZone: valid.blendZone,
|
|
89
|
+
parallaxSteps: valid.parallaxSteps,
|
|
90
|
+
depthDerivedWeights: valid.depthDerivedWeights,
|
|
91
|
+
castShadow: valid.castShadow,
|
|
92
|
+
receiveShadow: valid.receiveShadow,
|
|
93
|
+
material: valid.material,
|
|
94
|
+
...(valid.compression ? { compression: valid.compression } : {}),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** @param {unknown} value */
|
|
99
|
+
function isFiniteVec3(value) {
|
|
100
|
+
return Array.isArray(value) && value.length === 3 && value.every(Number.isFinite);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** @param {unknown} value */
|
|
104
|
+
function isUnitVec3(value) {
|
|
105
|
+
if (!isFiniteVec3(value)) return false;
|
|
106
|
+
const vector = /** @type {number[]} */ (value);
|
|
107
|
+
return Math.abs(Math.hypot(vector[0], vector[1], vector[2]) - 1) < 1e-4;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** @param {unknown} value */
|
|
111
|
+
function isPositiveInteger(value) {
|
|
112
|
+
return Number.isInteger(value) && /** @type {number} */ (value) > 0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** @param {unknown} value */
|
|
116
|
+
function isNonNegativeInteger(value) {
|
|
117
|
+
return Number.isInteger(value) && /** @type {number} */ (value) >= 0;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** @param {unknown} value */
|
|
121
|
+
function isPositiveFinite(value) {
|
|
122
|
+
return Number.isFinite(value) && /** @type {number} */ (value) > 0;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** @param {unknown} value */
|
|
126
|
+
function isUnitInterval(value) {
|
|
127
|
+
return Number.isFinite(value)
|
|
128
|
+
&& /** @type {number} */ (value) >= 0
|
|
129
|
+
&& /** @type {number} */ (value) <= 1;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** @param {unknown} value */
|
|
133
|
+
function isBlendZone(value) {
|
|
134
|
+
return Number.isFinite(value)
|
|
135
|
+
&& /** @type {number} */ (value) >= 0.35
|
|
136
|
+
&& /** @type {number} */ (value) <= 1;
|
|
137
|
+
}
|