@needle-tools/three-mesh-effects 0.0.0-stage → 0.1.0-alpha
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 -0
- package/README.md +88 -3
- package/build/deformation-runtime.js +2143 -0
- package/build/deformation-runtime.js.map +7 -0
- package/build/impostor-runtime-needle-engine.js +42 -0
- package/build/impostor-runtime-needle-engine.js.map +7 -0
- package/build/impostor-runtime.js +1333 -0
- package/build/impostor-runtime.js.map +7 -0
- package/build/internal/deformation/cloth-surface.js +288 -0
- package/build/internal/deformation/cloth-surface.js.map +7 -0
- package/build/internal/deformation/fur-surface.js +130 -0
- package/build/internal/deformation/fur-surface.js.map +7 -0
- package/build/internal/deformation/ik-constraints.js +44 -0
- package/build/internal/deformation/ik-constraints.js.map +7 -0
- package/build/internal/deformation/joints-json.js +197 -0
- package/build/internal/deformation/joints-json.js.map +7 -0
- package/build/internal/deformation/limits.js +16 -0
- package/build/internal/deformation/limits.js.map +7 -0
- package/build/internal/deformation/motion-settings.js +12 -0
- package/build/internal/deformation/motion-settings.js.map +7 -0
- package/build/internal/deformation/pin-cloth.js +196 -0
- package/build/internal/deformation/pin-cloth.js.map +7 -0
- package/build/internal/deformation/pin-ik.js +650 -0
- package/build/internal/deformation/pin-ik.js.map +7 -0
- package/build/internal/deformation/pin-types.js +12 -0
- package/build/internal/deformation/pin-types.js.map +7 -0
- package/build/internal/deformation/pin-wiggle.js +249 -0
- package/build/internal/deformation/pin-wiggle.js.map +7 -0
- package/build/internal/deformation/pose-slots.js +84 -0
- package/build/internal/deformation/pose-slots.js.map +7 -0
- package/build/internal/deformation/pose-timeline.js +210 -0
- package/build/internal/deformation/pose-timeline.js.map +7 -0
- package/build/internal/deformation/rig-drivers.js +48 -0
- package/build/internal/deformation/rig-drivers.js.map +7 -0
- package/build/internal/deformation/rig-extension.js +334 -0
- package/build/internal/deformation/rig-extension.js.map +7 -0
- package/build/internal/deformation/rig-runtime.js +2141 -0
- package/build/internal/deformation/rig-runtime.js.map +7 -0
- package/build/internal/deformation/wind.js +34 -0
- package/build/internal/deformation/wind.js.map +7 -0
- package/build/internal/impostor/impostor-metadata.js +77 -0
- package/build/internal/impostor/impostor-metadata.js.map +7 -0
- package/build/internal/impostor/impostor-node-material.js +1331 -0
- package/build/internal/impostor/impostor-node-material.js.map +7 -0
- package/build/internal/impostor/impostor-runtime-support.js +162 -0
- package/build/internal/impostor/impostor-runtime-support.js.map +7 -0
- package/build/internal/impostor/octahedral.js +232 -0
- package/build/internal/impostor/octahedral.js.map +7 -0
- package/build/internal/pixel-impostor/pixel-impostor-display.js +728 -0
- package/build/internal/pixel-impostor/pixel-impostor-display.js.map +7 -0
- package/build/internal/pixel-impostor/pixel-impostor-metadata.js +71 -0
- package/build/internal/pixel-impostor/pixel-impostor-metadata.js.map +7 -0
- package/build/internal/pixel-impostor/pixel-impostor-runtime.js +150 -0
- package/build/internal/pixel-impostor/pixel-impostor-runtime.js.map +7 -0
- package/build/internal/public/deformation-runtime.js +2143 -0
- package/build/internal/public/deformation-runtime.js.map +7 -0
- package/build/internal/public/impostor-runtime-needle-engine.js +42 -0
- package/build/internal/public/impostor-runtime-needle-engine.js.map +7 -0
- package/build/internal/public/impostor-runtime.js +1333 -0
- package/build/internal/public/impostor-runtime.js.map +7 -0
- package/build/internal/public/pixel-impostor-runtime.js +876 -0
- package/build/internal/public/pixel-impostor-runtime.js.map +7 -0
- package/build/internal/public/wrap-effects.js +5640 -0
- package/build/internal/public/wrap-effects.js.map +7 -0
- package/build/internal/rendering/skin-projection.js +4630 -0
- package/build/internal/rendering/skin-projection.js.map +7 -0
- package/build/internal/rendering/surface-query.js +4519 -0
- package/build/internal/rendering/surface-query.js.map +7 -0
- package/build/internal/rendering/wireframe.js +112 -0
- package/build/internal/rendering/wireframe.js.map +7 -0
- package/build/internal/rendering/wrap-preview-settings.js +126 -0
- package/build/internal/rendering/wrap-preview-settings.js.map +7 -0
- package/build/internal/rendering/wrap-preview.js +5610 -0
- package/build/internal/rendering/wrap-preview.js.map +7 -0
- package/build/internal/rendering/wrap-skin.js +4746 -0
- package/build/internal/rendering/wrap-skin.js.map +7 -0
- package/build/pixel-impostor-runtime.js +876 -0
- package/build/pixel-impostor-runtime.js.map +7 -0
- package/build/types/deformation/cloth-surface.d.ts +39 -0
- package/build/types/deformation/cloth-surface.js +1 -0
- package/build/types/deformation/fur-surface.d.ts +27 -0
- package/build/types/deformation/fur-surface.js +1 -0
- package/build/types/deformation/ik-constraints.d.ts +18 -0
- package/build/types/deformation/ik-constraints.js +1 -0
- package/build/types/deformation/joints-json.d.ts +17 -0
- package/build/types/deformation/joints-json.js +1 -0
- package/build/types/deformation/limits.d.ts +23 -0
- package/build/types/deformation/limits.js +1 -0
- package/build/types/deformation/motion-settings.d.ts +9 -0
- package/build/types/deformation/motion-settings.js +1 -0
- package/build/types/deformation/pin-cloth.d.ts +28 -0
- package/build/types/deformation/pin-cloth.js +1 -0
- package/build/types/deformation/pin-ik.d.ts +37 -0
- package/build/types/deformation/pin-ik.js +1 -0
- package/build/types/deformation/pin-types.d.ts +53 -0
- package/build/types/deformation/pin-types.js +1 -0
- package/build/types/deformation/pin-wiggle.d.ts +16 -0
- package/build/types/deformation/pin-wiggle.js +1 -0
- package/build/types/deformation/pose-slots.d.ts +41 -0
- package/build/types/deformation/pose-slots.js +1 -0
- package/build/types/deformation/pose-timeline.d.ts +65 -0
- package/build/types/deformation/pose-timeline.js +1 -0
- package/build/types/deformation/rig-drivers.d.ts +19 -0
- package/build/types/deformation/rig-drivers.js +1 -0
- package/build/types/deformation/rig-extension.d.ts +33 -0
- package/build/types/deformation/rig-extension.js +1 -0
- package/build/types/deformation/rig-runtime.d.ts +95 -0
- package/build/types/deformation/rig-runtime.js +1 -0
- package/build/types/deformation/wind.d.ts +16 -0
- package/build/types/deformation/wind.js +1 -0
- package/build/types/impostor/impostor-metadata.d.ts +61 -0
- package/build/types/impostor/impostor-metadata.js +1 -0
- package/build/types/impostor/impostor-node-material.d.ts +140 -0
- package/build/types/impostor/impostor-node-material.js +1 -0
- package/build/types/impostor/impostor-runtime-support.d.ts +52 -0
- package/build/types/impostor/impostor-runtime-support.js +1 -0
- package/build/types/impostor/octahedral.d.ts +84 -0
- package/build/types/impostor/octahedral.js +1 -0
- package/build/types/pixel-impostor/pixel-impostor-display.d.ts +48 -0
- package/build/types/pixel-impostor/pixel-impostor-display.js +1 -0
- package/build/types/pixel-impostor/pixel-impostor-metadata.d.ts +34 -0
- package/build/types/pixel-impostor/pixel-impostor-metadata.js +1 -0
- package/build/types/pixel-impostor/pixel-impostor-runtime.d.ts +18 -0
- package/build/types/pixel-impostor/pixel-impostor-runtime.js +1 -0
- package/build/types/public/deformation-runtime.d.ts +3 -0
- package/build/types/public/deformation-runtime.js +1 -0
- package/build/types/public/impostor-runtime-needle-engine.d.ts +31 -0
- package/build/types/public/impostor-runtime-needle-engine.js +1 -0
- package/build/types/public/impostor-runtime.d.ts +6 -0
- package/build/types/public/impostor-runtime.js +1 -0
- package/build/types/public/pixel-impostor-runtime.d.ts +3 -0
- package/build/types/public/pixel-impostor-runtime.js +1 -0
- package/build/types/public/wrap-effects.d.ts +4 -0
- package/build/types/public/wrap-effects.js +1 -0
- package/build/types/rendering/skin-projection.d.ts +44 -0
- package/build/types/rendering/skin-projection.js +1 -0
- package/build/types/rendering/surface-query.d.ts +66 -0
- package/build/types/rendering/surface-query.js +1 -0
- package/build/types/rendering/wireframe.d.ts +25 -0
- package/build/types/rendering/wireframe.js +1 -0
- package/build/types/rendering/wrap-preview-settings.d.ts +22 -0
- package/build/types/rendering/wrap-preview-settings.js +1 -0
- package/build/types/rendering/wrap-preview.d.ts +39 -0
- package/build/types/rendering/wrap-preview.js +1 -0
- package/build/types/rendering/wrap-skin.d.ts +14 -0
- package/build/types/rendering/wrap-skin.js +1 -0
- package/build/wrap-effects.js +5640 -0
- package/build/wrap-effects.js.map +7 -0
- package/package.json +94 -6
- package/src/deformation/cloth-surface.ts +223 -0
- package/src/deformation/fur-surface.ts +129 -0
- package/src/deformation/ik-constraints.ts +37 -0
- package/src/deformation/joints-json.ts +94 -0
- package/src/deformation/limits.ts +25 -0
- package/src/deformation/motion-settings.ts +9 -0
- package/src/deformation/pin-cloth.ts +149 -0
- package/src/deformation/pin-ik.ts +582 -0
- package/src/deformation/pin-types.ts +22 -0
- package/src/deformation/pin-wiggle.ts +119 -0
- package/src/deformation/pose-slots.ts +106 -0
- package/src/deformation/pose-timeline.ts +242 -0
- package/src/deformation/rig-drivers.ts +32 -0
- package/src/deformation/rig-extension.ts +87 -0
- package/src/deformation/rig-runtime.ts +416 -0
- package/src/deformation/wind.ts +36 -0
- package/src/impostor/impostor-metadata.js +137 -0
- package/src/impostor/impostor-node-material.js +1581 -0
- package/src/impostor/impostor-runtime-support.js +139 -0
- package/src/impostor/octahedral.js +280 -0
- package/src/pixel-impostor/pixel-impostor-display.js +794 -0
- package/src/pixel-impostor/pixel-impostor-metadata.js +74 -0
- package/src/pixel-impostor/pixel-impostor-runtime.js +78 -0
- package/src/public/deformation-runtime.ts +3 -0
- package/src/public/impostor-runtime-needle-engine.js +56 -0
- package/src/public/impostor-runtime.js +21 -0
- package/src/public/pixel-impostor-runtime.js +5 -0
- package/src/public/wrap-effects.js +21 -0
- package/src/rendering/skin-projection.js +113 -0
- package/src/rendering/surface-query.js +88 -0
- package/src/rendering/wireframe.js +115 -0
- package/src/rendering/wrap-preview-settings.js +123 -0
- package/src/rendering/wrap-preview.js +645 -0
- package/src/rendering/wrap-skin.js +109 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
|
|
3
|
+
// src/deformation/wind.ts
|
|
4
|
+
import { Vector3 } from "three";
|
|
5
|
+
var MAX_WIND_STRENGTH = 4;
|
|
6
|
+
function windProfile(strength) {
|
|
7
|
+
const level = Math.max(0, Math.min(MAX_WIND_STRENGTH, strength));
|
|
8
|
+
const label = level === 0 ? "Off" : level < 0.75 ? "Breeze" : level < 1.5 ? "Windy" : level < 2.5 ? "Strong wind" : level < 3.3 ? "Gale" : "Storm";
|
|
9
|
+
return {
|
|
10
|
+
label,
|
|
11
|
+
load: 30 * level * level / (0.8 + level * level),
|
|
12
|
+
surfaceLoad: 4 * level * level,
|
|
13
|
+
gust: 0.14 + 0.12 * level,
|
|
14
|
+
crosswind: 0.05 + 0.07 * level,
|
|
15
|
+
gustRate: 0.42 + 0.12 * level
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function windAcceleration(seconds, strength, scale, position) {
|
|
19
|
+
if (strength <= 0) return new Vector3();
|
|
20
|
+
const size = Math.max(1e-4, scale);
|
|
21
|
+
const profile = windProfile(strength);
|
|
22
|
+
const along = position[0] / size, lateral = (position[1] * 0.67 + position[2] * 0.33) / size;
|
|
23
|
+
const slow = seconds * profile.gustRate - along * 0.55;
|
|
24
|
+
const fast = seconds * (profile.gustRate * 2.7) - along * 1.4 + lateral * 0.4;
|
|
25
|
+
const gust = Math.max(0.2, 1 + profile.gust * (0.7 * Math.sin(slow) + 0.3 * Math.sin(fast + 1.3)));
|
|
26
|
+
const cross = profile.crosswind * (0.65 * Math.sin(fast + lateral) + 0.35 * Math.sin(slow * 0.73 - lateral * 0.6));
|
|
27
|
+
return new Vector3(1, cross * 0.35, cross).normalize().multiplyScalar(profile.load * size * gust);
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
MAX_WIND_STRENGTH,
|
|
31
|
+
windAcceleration,
|
|
32
|
+
windProfile
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=wind.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/deformation/wind.ts"],
|
|
4
|
+
"sourcesContent": ["import { Vector3 } from 'three';\r\n\r\nexport const MAX_WIND_STRENGTH = 4;\r\n\r\n/** A single weather control drives pin motion and surface pressure. Sparse pin\r\n * loads stay bounded; fabric pressure has room to grow through a storm. */\r\nexport function windProfile(strength: number) {\r\n const level = Math.max(0, Math.min(MAX_WIND_STRENGTH, strength));\r\n const label = level === 0 ? 'Off' : level < .75 ? 'Breeze' : level < 1.5 ? 'Windy' : level < 2.5 ? 'Strong wind' : level < 3.3 ? 'Gale' : 'Storm';\r\n return {\r\n label,\r\n load: 30 * level * level / (.8 + level * level),\r\n surfaceLoad: 4 * level * level,\r\n gust: .14 + .12 * level,\r\n crosswind: .05 + .07 * level,\r\n gustRate: .42 + .12 * level,\r\n };\r\n}\r\n\r\n/** Deterministic scene-local prevailing wind with slow gusts and spatially\r\n * varying eddies. Force is an acceleration scaled to the model's size, so a\r\n * tiny prop and a large character respond comparably at the same setting. */\r\nexport function windAcceleration(seconds: number, strength: number, scale: number, position: readonly number[]) {\r\n if (strength <= 0) return new Vector3();\r\n const size = Math.max(1e-4, scale);\r\n const profile = windProfile(strength);\r\n // Advect the gust bands along +X. Nearby controls see related wind, while\r\n // their phase delay keeps a large sheet or branch hierarchy from moving as\r\n // one perfectly synchronized rigid object.\r\n const along = position[0] / size, lateral = (position[1] * .67 + position[2] * .33) / size;\r\n const slow = seconds * profile.gustRate - along * .55;\r\n const fast = seconds * (profile.gustRate * 2.7) - along * 1.4 + lateral * .4;\r\n const gust = Math.max(.2, 1 + profile.gust * (.7 * Math.sin(slow) + .3 * Math.sin(fast + 1.3)));\r\n const cross = profile.crosswind * (.65 * Math.sin(fast + lateral) + .35 * Math.sin(slow * .73 - lateral * .6));\r\n return new Vector3(1, cross * .35, cross).normalize().multiplyScalar(profile.load * size * gust);\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;;AAAA,SAAS,eAAe;AAEjB,IAAM,oBAAoB;AAI1B,SAAS,YAAY,UAAkB;AAC5C,QAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,mBAAmB,QAAQ,CAAC;AAC/D,QAAM,QAAQ,UAAU,IAAI,QAAQ,QAAQ,OAAM,WAAW,QAAQ,MAAM,UAAU,QAAQ,MAAM,gBAAgB,QAAQ,MAAM,SAAS;AAC1I,SAAO;AAAA,IACL;AAAA,IACA,MAAM,KAAK,QAAQ,SAAS,MAAK,QAAQ;AAAA,IACzC,aAAa,IAAI,QAAQ;AAAA,IACzB,MAAM,OAAM,OAAM;AAAA,IAClB,WAAW,OAAM,OAAM;AAAA,IACvB,UAAU,OAAM,OAAM;AAAA,EACxB;AACF;AAKO,SAAS,iBAAiB,SAAiB,UAAkB,OAAe,UAA6B;AAC9G,MAAI,YAAY,EAAG,QAAO,IAAI,QAAQ;AACtC,QAAM,OAAO,KAAK,IAAI,MAAM,KAAK;AACjC,QAAM,UAAU,YAAY,QAAQ;AAIpC,QAAM,QAAQ,SAAS,CAAC,IAAI,MAAM,WAAW,SAAS,CAAC,IAAI,OAAM,SAAS,CAAC,IAAI,QAAO;AACtF,QAAM,OAAO,UAAU,QAAQ,WAAW,QAAQ;AAClD,QAAM,OAAO,WAAW,QAAQ,WAAW,OAAO,QAAQ,MAAM,UAAU;AAC1E,QAAM,OAAO,KAAK,IAAI,KAAI,IAAI,QAAQ,QAAQ,MAAK,KAAK,IAAI,IAAI,IAAI,MAAK,KAAK,IAAI,OAAO,GAAG,EAAE;AAC9F,QAAM,QAAQ,QAAQ,aAAa,OAAM,KAAK,IAAI,OAAO,OAAO,IAAI,OAAM,KAAK,IAAI,OAAO,OAAM,UAAU,GAAE;AAC5G,SAAO,IAAI,QAAQ,GAAG,QAAQ,MAAK,KAAK,EAAE,UAAU,EAAE,eAAe,QAAQ,OAAO,OAAO,IAAI;AACjG;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
|
|
3
|
+
// src/impostor/impostor-metadata.js
|
|
4
|
+
var NEEDLE_MESH_IMPOSTOR = "NEEDLE_mesh_impostor";
|
|
5
|
+
function parseImpostorDescriptor(value) {
|
|
6
|
+
if (!value || typeof value !== "object") return null;
|
|
7
|
+
const descriptor = (
|
|
8
|
+
/** @type {Partial<ImpostorDescriptor>} */
|
|
9
|
+
value
|
|
10
|
+
);
|
|
11
|
+
if (descriptor.version !== 1 || descriptor.mapping !== "hemisphere" && descriptor.mapping !== "full" && descriptor.mapping !== "single" || !isPositiveInteger(descriptor.frames) || (descriptor.mapping === "single" ? descriptor.frames !== 1 || !isUnitVec3(descriptor.captureDirection) : false) || !isPositiveInteger(descriptor.frameResolution) || !isNonNegativeInteger(descriptor.padding) || !isPositiveFinite(descriptor.radius) || descriptor.compression !== void 0 && (descriptor.compression.version !== 4 || descriptor.compression.layout !== "compact-atlas-v4" || descriptor.compression.depthEncoding !== "lossless-geometry10-rgba" || !isPositiveInteger(descriptor.compression.materialFrameResolution) || typeof descriptor.compression.emissive !== "boolean") || !isFiniteVec3(descriptor.boundsMin) || !isFiniteVec3(descriptor.boundsMax) || !isFiniteVec3(descriptor.center) || !Array.isArray(descriptor.viewBounds) || descriptor.viewBounds.length !== (descriptor.frames ?? 0) * (descriptor.frames ?? 0) * 4 || !descriptor.viewBounds.every(Number.isFinite) || descriptor.coverageEncoding !== "captured-alpha+sdf-material" && descriptor.coverageEncoding !== "sdf-base-alpha" || !isUnitInterval(descriptor.captureAlphaCutoff) || !isUnitInterval(descriptor.alphaCutoff) || !isBlendZone(descriptor.blendZone) || !isNonNegativeInteger(descriptor.parallaxSteps) || typeof descriptor.depthDerivedWeights !== "boolean" || typeof descriptor.castShadow !== "boolean" || typeof descriptor.receiveShadow !== "boolean" || !descriptor.material || !isUnitInterval(descriptor.material.occlusion) || !isUnitInterval(descriptor.material.roughness) || !isUnitInterval(descriptor.material.metalness)) return null;
|
|
12
|
+
const valid = (
|
|
13
|
+
/** @type {ImpostorDescriptor} */
|
|
14
|
+
descriptor
|
|
15
|
+
);
|
|
16
|
+
return {
|
|
17
|
+
version: 1,
|
|
18
|
+
mapping: valid.mapping,
|
|
19
|
+
frames: valid.frames,
|
|
20
|
+
...valid.mapping === "single" ? { captureDirection: valid.captureDirection } : {},
|
|
21
|
+
frameResolution: valid.frameResolution,
|
|
22
|
+
padding: valid.padding,
|
|
23
|
+
radius: valid.radius,
|
|
24
|
+
boundsMin: valid.boundsMin,
|
|
25
|
+
boundsMax: valid.boundsMax,
|
|
26
|
+
center: valid.center,
|
|
27
|
+
viewBounds: valid.viewBounds,
|
|
28
|
+
coverageEncoding: valid.coverageEncoding,
|
|
29
|
+
captureAlphaCutoff: valid.captureAlphaCutoff,
|
|
30
|
+
alphaCutoff: valid.alphaCutoff,
|
|
31
|
+
blendZone: valid.blendZone,
|
|
32
|
+
parallaxSteps: valid.parallaxSteps,
|
|
33
|
+
depthDerivedWeights: valid.depthDerivedWeights,
|
|
34
|
+
castShadow: valid.castShadow,
|
|
35
|
+
receiveShadow: valid.receiveShadow,
|
|
36
|
+
material: valid.material,
|
|
37
|
+
...valid.compression ? { compression: valid.compression } : {}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function isFiniteVec3(value) {
|
|
41
|
+
return Array.isArray(value) && value.length === 3 && value.every(Number.isFinite);
|
|
42
|
+
}
|
|
43
|
+
function isUnitVec3(value) {
|
|
44
|
+
if (!isFiniteVec3(value)) return false;
|
|
45
|
+
const vector = (
|
|
46
|
+
/** @type {number[]} */
|
|
47
|
+
value
|
|
48
|
+
);
|
|
49
|
+
return Math.abs(Math.hypot(vector[0], vector[1], vector[2]) - 1) < 1e-4;
|
|
50
|
+
}
|
|
51
|
+
function isPositiveInteger(value) {
|
|
52
|
+
return Number.isInteger(value) && /** @type {number} */
|
|
53
|
+
value > 0;
|
|
54
|
+
}
|
|
55
|
+
function isNonNegativeInteger(value) {
|
|
56
|
+
return Number.isInteger(value) && /** @type {number} */
|
|
57
|
+
value >= 0;
|
|
58
|
+
}
|
|
59
|
+
function isPositiveFinite(value) {
|
|
60
|
+
return Number.isFinite(value) && /** @type {number} */
|
|
61
|
+
value > 0;
|
|
62
|
+
}
|
|
63
|
+
function isUnitInterval(value) {
|
|
64
|
+
return Number.isFinite(value) && /** @type {number} */
|
|
65
|
+
value >= 0 && /** @type {number} */
|
|
66
|
+
value <= 1;
|
|
67
|
+
}
|
|
68
|
+
function isBlendZone(value) {
|
|
69
|
+
return Number.isFinite(value) && /** @type {number} */
|
|
70
|
+
value >= 0.35 && /** @type {number} */
|
|
71
|
+
value <= 1;
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
NEEDLE_MESH_IMPOSTOR,
|
|
75
|
+
parseImpostorDescriptor
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=impostor-metadata.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/impostor/impostor-metadata.js"],
|
|
4
|
+
"sourcesContent": ["// @ts-check\r\n\r\n/** Primitive extension declaring an explicitly-bound Needle mesh impostor. */\r\nexport const NEEDLE_MESH_IMPOSTOR = 'NEEDLE_mesh_impostor';\r\n\r\n/**\r\n * @typedef {object} ImpostorDescriptor\r\n * @property {1} version\r\n * @property {'hemisphere' | 'full' | 'single'} mapping\r\n * @property {number} frames\r\n * @property {readonly [number, number, number]=} captureDirection\r\n * @property {number} frameResolution\r\n * @property {number} padding\r\n * @property {number} radius\r\n * @property {readonly [number, number, number]} boundsMin\r\n * @property {readonly [number, number, number]} boundsMax\r\n * @property {readonly [number, number, number]} center\r\n * @property {readonly number[]} viewBounds\r\n * @property {'captured-alpha+sdf-material' | 'sdf-base-alpha'} coverageEncoding\r\n * @property {number} captureAlphaCutoff\r\n * @property {number} alphaCutoff\r\n * @property {number} blendZone\r\n * @property {number} parallaxSteps\r\n * @property {boolean} depthDerivedWeights\r\n * @property {boolean} castShadow\r\n * @property {boolean} receiveShadow\r\n * @property {{occlusion: number, roughness: number, metalness: number}} material\r\n * @property {{version: 4, layout: 'compact-atlas-v4', depthEncoding: 'lossless-geometry10-rgba', materialFrameResolution: number, emissive: boolean}=} compression\r\n */\r\n\r\n/** @param {unknown} value @returns {ImpostorDescriptor | null} */\r\nexport function parseImpostorDescriptor(value) {\r\n if (!value || typeof value !== 'object') return null;\r\n const descriptor = /** @type {Partial<ImpostorDescriptor>} */ (value);\r\n if (\r\n descriptor.version !== 1\r\n || (descriptor.mapping !== 'hemisphere' && descriptor.mapping !== 'full' && descriptor.mapping !== 'single')\r\n || !isPositiveInteger(descriptor.frames)\r\n || (descriptor.mapping === 'single'\r\n ? (descriptor.frames !== 1 || !isUnitVec3(descriptor.captureDirection))\r\n : false)\r\n || !isPositiveInteger(descriptor.frameResolution)\r\n || !isNonNegativeInteger(descriptor.padding)\r\n || !isPositiveFinite(descriptor.radius)\r\n || (descriptor.compression !== undefined && (\r\n descriptor.compression.version !== 4\r\n || descriptor.compression.layout !== 'compact-atlas-v4'\r\n || descriptor.compression.depthEncoding !== 'lossless-geometry10-rgba'\r\n || !isPositiveInteger(descriptor.compression.materialFrameResolution)\r\n || typeof descriptor.compression.emissive !== 'boolean'\r\n ))\r\n || !isFiniteVec3(descriptor.boundsMin)\r\n || !isFiniteVec3(descriptor.boundsMax)\r\n || !isFiniteVec3(descriptor.center)\r\n || !Array.isArray(descriptor.viewBounds)\r\n || descriptor.viewBounds.length !== (descriptor.frames ?? 0) * (descriptor.frames ?? 0) * 4\r\n || !descriptor.viewBounds.every(Number.isFinite)\r\n || (descriptor.coverageEncoding !== 'captured-alpha+sdf-material'\r\n && descriptor.coverageEncoding !== 'sdf-base-alpha')\r\n || !isUnitInterval(descriptor.captureAlphaCutoff)\r\n || !isUnitInterval(descriptor.alphaCutoff)\r\n || !isBlendZone(descriptor.blendZone)\r\n || !isNonNegativeInteger(descriptor.parallaxSteps)\r\n || typeof descriptor.depthDerivedWeights !== 'boolean'\r\n || typeof descriptor.castShadow !== 'boolean'\r\n || typeof descriptor.receiveShadow !== 'boolean'\r\n || !descriptor.material\r\n || !isUnitInterval(descriptor.material.occlusion)\r\n || !isUnitInterval(descriptor.material.roughness)\r\n || !isUnitInterval(descriptor.material.metalness)\r\n ) return null;\r\n const valid = /** @type {ImpostorDescriptor} */ (descriptor);\r\n return {\r\n version: 1,\r\n mapping: valid.mapping,\r\n frames: valid.frames,\r\n ...(valid.mapping === 'single' ? { captureDirection: valid.captureDirection } : {}),\r\n frameResolution: valid.frameResolution,\r\n padding: valid.padding,\r\n radius: valid.radius,\r\n boundsMin: valid.boundsMin,\r\n boundsMax: valid.boundsMax,\r\n center: valid.center,\r\n viewBounds: valid.viewBounds,\r\n coverageEncoding: valid.coverageEncoding,\r\n captureAlphaCutoff: valid.captureAlphaCutoff,\r\n alphaCutoff: valid.alphaCutoff,\r\n blendZone: valid.blendZone,\r\n parallaxSteps: valid.parallaxSteps,\r\n depthDerivedWeights: valid.depthDerivedWeights,\r\n castShadow: valid.castShadow,\r\n receiveShadow: valid.receiveShadow,\r\n material: valid.material,\r\n ...(valid.compression ? { compression: valid.compression } : {}),\r\n };\r\n}\r\n\r\n/** @param {unknown} value */\r\nfunction isFiniteVec3(value) {\r\n return Array.isArray(value) && value.length === 3 && value.every(Number.isFinite);\r\n}\r\n\r\n/** @param {unknown} value */\r\nfunction isUnitVec3(value) {\r\n if (!isFiniteVec3(value)) return false;\r\n const vector = /** @type {number[]} */ (value);\r\n return Math.abs(Math.hypot(vector[0], vector[1], vector[2]) - 1) < 1e-4;\r\n}\r\n\r\n/** @param {unknown} value */\r\nfunction isPositiveInteger(value) {\r\n return Number.isInteger(value) && /** @type {number} */ (value) > 0;\r\n}\r\n\r\n/** @param {unknown} value */\r\nfunction isNonNegativeInteger(value) {\r\n return Number.isInteger(value) && /** @type {number} */ (value) >= 0;\r\n}\r\n\r\n/** @param {unknown} value */\r\nfunction isPositiveFinite(value) {\r\n return Number.isFinite(value) && /** @type {number} */ (value) > 0;\r\n}\r\n\r\n/** @param {unknown} value */\r\nfunction isUnitInterval(value) {\r\n return Number.isFinite(value)\r\n && /** @type {number} */ (value) >= 0\r\n && /** @type {number} */ (value) <= 1;\r\n}\r\n\r\n/** @param {unknown} value */\r\nfunction isBlendZone(value) {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