@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.
Files changed (86) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +94 -88
  3. package/build/deformation-runtime.js.map +1 -1
  4. package/build/impostor-runtime-needle-engine.js.map +1 -1
  5. package/build/impostor-runtime.js.map +1 -1
  6. package/build/internal/deformation/cloth-surface.js.map +1 -1
  7. package/build/internal/deformation/fur-surface.js.map +1 -1
  8. package/build/internal/deformation/ik-constraints.js.map +1 -1
  9. package/build/internal/deformation/joints-json.js.map +1 -1
  10. package/build/internal/deformation/limits.js.map +1 -1
  11. package/build/internal/deformation/motion-settings.js.map +1 -1
  12. package/build/internal/deformation/pin-cloth.js.map +1 -1
  13. package/build/internal/deformation/pin-ik.js.map +1 -1
  14. package/build/internal/deformation/pin-types.js.map +1 -1
  15. package/build/internal/deformation/pin-wiggle.js.map +1 -1
  16. package/build/internal/deformation/pose-slots.js.map +1 -1
  17. package/build/internal/deformation/pose-timeline.js.map +1 -1
  18. package/build/internal/deformation/rig-drivers.js.map +1 -1
  19. package/build/internal/deformation/rig-extension.js.map +1 -1
  20. package/build/internal/deformation/rig-runtime.js.map +1 -1
  21. package/build/internal/deformation/wind.js.map +1 -1
  22. package/build/internal/impostor/impostor-metadata.js.map +1 -1
  23. package/build/internal/impostor/impostor-node-material.js.map +1 -1
  24. package/build/internal/impostor/impostor-runtime-support.js.map +1 -1
  25. package/build/internal/impostor/octahedral.js.map +1 -1
  26. package/build/internal/pixel-impostor/pixel-impostor-display.js.map +1 -1
  27. package/build/internal/pixel-impostor/pixel-impostor-metadata.js.map +1 -1
  28. package/build/internal/pixel-impostor/pixel-impostor-runtime.js.map +1 -1
  29. package/build/internal/rendering/skin-projection.js +52 -52
  30. package/build/internal/rendering/skin-projection.js.map +2 -2
  31. package/build/internal/rendering/surface-query.js +52 -52
  32. package/build/internal/rendering/surface-query.js.map +2 -2
  33. package/build/internal/rendering/wireframe.js.map +1 -1
  34. package/build/internal/rendering/wrap-preview-settings.js.map +1 -1
  35. package/build/internal/rendering/wrap-preview.js +52 -52
  36. package/build/internal/rendering/wrap-preview.js.map +2 -2
  37. package/build/internal/rendering/wrap-skin.js +52 -52
  38. package/build/internal/rendering/wrap-skin.js.map +2 -2
  39. package/build/pixel-impostor-runtime.js.map +1 -1
  40. package/build/wrap-effects.js +52 -52
  41. package/build/wrap-effects.js.map +2 -2
  42. package/package.json +107 -94
  43. package/src/deformation/cloth-surface.ts +223 -223
  44. package/src/deformation/fur-surface.ts +129 -129
  45. package/src/deformation/ik-constraints.ts +37 -37
  46. package/src/deformation/joints-json.ts +94 -94
  47. package/src/deformation/limits.ts +25 -25
  48. package/src/deformation/motion-settings.ts +9 -9
  49. package/src/deformation/pin-cloth.ts +149 -149
  50. package/src/deformation/pin-ik.ts +582 -582
  51. package/src/deformation/pin-types.ts +22 -22
  52. package/src/deformation/pin-wiggle.ts +119 -119
  53. package/src/deformation/pose-slots.ts +106 -106
  54. package/src/deformation/pose-timeline.ts +242 -242
  55. package/src/deformation/rig-drivers.ts +32 -32
  56. package/src/deformation/rig-extension.ts +87 -87
  57. package/src/deformation/rig-runtime.ts +416 -416
  58. package/src/deformation/wind.ts +36 -36
  59. package/src/impostor/impostor-metadata.js +137 -137
  60. package/src/impostor/impostor-node-material.js +1581 -1581
  61. package/src/impostor/impostor-runtime-support.js +139 -139
  62. package/src/impostor/octahedral.js +280 -280
  63. package/src/pixel-impostor/pixel-impostor-display.js +794 -794
  64. package/src/pixel-impostor/pixel-impostor-metadata.js +74 -74
  65. package/src/pixel-impostor/pixel-impostor-runtime.js +78 -78
  66. package/src/public/deformation-runtime.ts +3 -3
  67. package/src/public/impostor-runtime-needle-engine.js +56 -56
  68. package/src/public/impostor-runtime.js +21 -21
  69. package/src/public/pixel-impostor-runtime.js +5 -5
  70. package/src/public/wrap-effects.js +21 -21
  71. package/src/rendering/skin-projection.js +113 -113
  72. package/src/rendering/surface-query.js +88 -88
  73. package/src/rendering/wireframe.js +115 -115
  74. package/src/rendering/wrap-preview-settings.js +123 -123
  75. package/src/rendering/wrap-preview.js +645 -645
  76. package/src/rendering/wrap-skin.js +109 -109
  77. package/build/internal/public/deformation-runtime.js +0 -2143
  78. package/build/internal/public/deformation-runtime.js.map +0 -7
  79. package/build/internal/public/impostor-runtime-needle-engine.js +0 -42
  80. package/build/internal/public/impostor-runtime-needle-engine.js.map +0 -7
  81. package/build/internal/public/impostor-runtime.js +0 -1333
  82. package/build/internal/public/impostor-runtime.js.map +0 -7
  83. package/build/internal/public/pixel-impostor-runtime.js +0 -876
  84. package/build/internal/public/pixel-impostor-runtime.js.map +0 -7
  85. package/build/internal/public/wrap-effects.js +0 -5640
  86. package/build/internal/public/wrap-effects.js.map +0 -7
@@ -1,139 +1,139 @@
1
- // @ts-check
2
-
3
- import {
4
- DataTexture,
5
- FloatType,
6
- NearestFilter,
7
- RGBAFormat,
8
- } from 'three';
9
-
10
- import { parseImpostorDescriptor } from './impostor-metadata.js';
11
- /** @import { ImpostorDescriptor } from './impostor-metadata.js' */
12
-
13
- export { parseImpostorDescriptor } from './impostor-metadata.js';
14
-
15
- export const REPROJECTION_CONFIDENCE_INNER_TEXELS = 0.25;
16
- export const REPROJECTION_CONFIDENCE_OUTER_TEXELS = 16;
17
-
18
- /**
19
- * Restricts barycentric interpolation to a compact fraction of each angular
20
- * transition. A value of one preserves ordinary linear barycentrics. Smaller
21
- * values create an exact single-view region around each capture while the
22
- * active transition remains continuous and normalized.
23
- *
24
- * Along a triangle edge, `blendZone` is exactly the fraction of that edge over
25
- * which both endpoint captures contribute.
26
- *
27
- * @param {readonly [number, number, number]} inputWeights
28
- * @param {number} blendZone
29
- * @returns {[number, number, number]}
30
- */
31
- export function applyImpostorBlendZone(inputWeights, blendZone) {
32
- if (!isBlendZone(blendZone)) {
33
- throw new RangeError('Impostor blend zone must be from 0.35 to 1.');
34
- }
35
- if (inputWeights.some((weight) => !Number.isFinite(weight) || weight < 0)) {
36
- throw new RangeError('Impostor barycentric weights must be finite and non-negative.');
37
- }
38
- const cutoff = (1 - blendZone) * 0.5;
39
- const weights = /** @type {[number, number, number]} */ (
40
- inputWeights.map((weight) => Math.max(0, weight - cutoff))
41
- );
42
- const sum = weights[0] + weights[1] + weights[2];
43
- if (!(sum > 0)) return [1, 0, 0];
44
- return /** @type {[number, number, number]} */ (
45
- weights.map((weight) => weight / sum)
46
- );
47
- }
48
-
49
- /**
50
- * Keeps the angular onset of a previously occluded contour approximately
51
- * stable as the atlas grid gets denser. The returned value is the temperature
52
- * used by the normalized log-sum-exp union in the runtime shader.
53
- *
54
- * @param {number} frames
55
- */
56
- export function impostorContourUnionSharpness(frames) {
57
- if (!Number.isInteger(frames) || frames < 2) {
58
- throw new RangeError('Impostor contour union requires at least two frames per atlas axis.');
59
- }
60
- return Math.max(1, 16 / frames);
61
- }
62
-
63
- /**
64
- * CPU mirror of the runtime's continuous geometric confidence. A binary
65
- * half-texel cutoff made individual pixels (and sometimes entire thin
66
- * features) switch reconstruction paths at one camera angle. The fade keeps
67
- * the same bounded rejection while making angular motion continuous.
68
- *
69
- * @param {boolean} startedOutOfBounds
70
- * @param {number} rayError
71
- * @param {number} footprint
72
- * @param {boolean=} reprojectionActive
73
- */
74
- export function reprojectedSampleConfidence(
75
- startedOutOfBounds,
76
- rayError,
77
- footprint,
78
- reprojectionActive = true,
79
- ) {
80
- if (startedOutOfBounds) return 0;
81
- if (!reprojectionActive) return 1;
82
- if (!(footprint > 0)) return 0;
83
- const residual = rayError / footprint;
84
- const interval = REPROJECTION_CONFIDENCE_OUTER_TEXELS
85
- - REPROJECTION_CONFIDENCE_INNER_TEXELS;
86
- const t = Math.min(1, Math.max(
87
- 0,
88
- (residual - REPROJECTION_CONFIDENCE_INNER_TEXELS) / interval,
89
- ));
90
- const eased = t * t * (3 - 2 * t);
91
- return 1 - eased;
92
- }
93
-
94
- /**
95
- * Mirrors the runtime coverage contribution used after depth reprojection.
96
- * Validity can remove a frame from a pixel, but it must never renormalize the
97
- * remaining frame to full opacity. Preserving angular support prevents a
98
- * surface visible in only one capture from appearing as a second opaque layer.
99
- *
100
- * @param {readonly [number, number, number]} visibilityWeights
101
- * @param {readonly [number, number, number]} correctedValidity
102
- * @returns {[number, number, number]}
103
- */
104
- export function resolveImpostorCoverageWeights(
105
- visibilityWeights,
106
- correctedValidity,
107
- ) {
108
- const values = [...visibilityWeights, ...correctedValidity];
109
- if (values.some((value) => !Number.isFinite(value) || value < 0)) {
110
- throw new RangeError('Coverage weights and validity must be finite and non-negative.');
111
- }
112
- return /** @type {[number, number, number]} */ (
113
- visibilityWeights.map((weight, index) => weight * correctedValidity[index])
114
- );
115
- }
116
-
117
- /** @param {ImpostorDescriptor} descriptor */
118
- export function createImpostorViewBoundsTexture(descriptor) {
119
- const texture = new DataTexture(
120
- new Float32Array(descriptor.viewBounds),
121
- descriptor.frames,
122
- descriptor.frames,
123
- RGBAFormat,
124
- FloatType,
125
- );
126
- texture.name = 'impostor view bounds';
127
- texture.minFilter = NearestFilter;
128
- texture.magFilter = NearestFilter;
129
- texture.generateMipmaps = false;
130
- texture.needsUpdate = true;
131
- return texture;
132
- }
133
-
134
- /** @param {unknown} value */
135
- function isBlendZone(value) {
136
- return Number.isFinite(value)
137
- && /** @type {number} */ (value) >= 0.35
138
- && /** @type {number} */ (value) <= 1;
139
- }
1
+ // @ts-check
2
+
3
+ import {
4
+ DataTexture,
5
+ FloatType,
6
+ NearestFilter,
7
+ RGBAFormat,
8
+ } from 'three';
9
+
10
+ import { parseImpostorDescriptor } from './impostor-metadata.js';
11
+ /** @import { ImpostorDescriptor } from './impostor-metadata.js' */
12
+
13
+ export { parseImpostorDescriptor } from './impostor-metadata.js';
14
+
15
+ export const REPROJECTION_CONFIDENCE_INNER_TEXELS = 0.25;
16
+ export const REPROJECTION_CONFIDENCE_OUTER_TEXELS = 16;
17
+
18
+ /**
19
+ * Restricts barycentric interpolation to a compact fraction of each angular
20
+ * transition. A value of one preserves ordinary linear barycentrics. Smaller
21
+ * values create an exact single-view region around each capture while the
22
+ * active transition remains continuous and normalized.
23
+ *
24
+ * Along a triangle edge, `blendZone` is exactly the fraction of that edge over
25
+ * which both endpoint captures contribute.
26
+ *
27
+ * @param {readonly [number, number, number]} inputWeights
28
+ * @param {number} blendZone
29
+ * @returns {[number, number, number]}
30
+ */
31
+ export function applyImpostorBlendZone(inputWeights, blendZone) {
32
+ if (!isBlendZone(blendZone)) {
33
+ throw new RangeError('Impostor blend zone must be from 0.35 to 1.');
34
+ }
35
+ if (inputWeights.some((weight) => !Number.isFinite(weight) || weight < 0)) {
36
+ throw new RangeError('Impostor barycentric weights must be finite and non-negative.');
37
+ }
38
+ const cutoff = (1 - blendZone) * 0.5;
39
+ const weights = /** @type {[number, number, number]} */ (
40
+ inputWeights.map((weight) => Math.max(0, weight - cutoff))
41
+ );
42
+ const sum = weights[0] + weights[1] + weights[2];
43
+ if (!(sum > 0)) return [1, 0, 0];
44
+ return /** @type {[number, number, number]} */ (
45
+ weights.map((weight) => weight / sum)
46
+ );
47
+ }
48
+
49
+ /**
50
+ * Keeps the angular onset of a previously occluded contour approximately
51
+ * stable as the atlas grid gets denser. The returned value is the temperature
52
+ * used by the normalized log-sum-exp union in the runtime shader.
53
+ *
54
+ * @param {number} frames
55
+ */
56
+ export function impostorContourUnionSharpness(frames) {
57
+ if (!Number.isInteger(frames) || frames < 2) {
58
+ throw new RangeError('Impostor contour union requires at least two frames per atlas axis.');
59
+ }
60
+ return Math.max(1, 16 / frames);
61
+ }
62
+
63
+ /**
64
+ * CPU mirror of the runtime's continuous geometric confidence. A binary
65
+ * half-texel cutoff made individual pixels (and sometimes entire thin
66
+ * features) switch reconstruction paths at one camera angle. The fade keeps
67
+ * the same bounded rejection while making angular motion continuous.
68
+ *
69
+ * @param {boolean} startedOutOfBounds
70
+ * @param {number} rayError
71
+ * @param {number} footprint
72
+ * @param {boolean=} reprojectionActive
73
+ */
74
+ export function reprojectedSampleConfidence(
75
+ startedOutOfBounds,
76
+ rayError,
77
+ footprint,
78
+ reprojectionActive = true,
79
+ ) {
80
+ if (startedOutOfBounds) return 0;
81
+ if (!reprojectionActive) return 1;
82
+ if (!(footprint > 0)) return 0;
83
+ const residual = rayError / footprint;
84
+ const interval = REPROJECTION_CONFIDENCE_OUTER_TEXELS
85
+ - REPROJECTION_CONFIDENCE_INNER_TEXELS;
86
+ const t = Math.min(1, Math.max(
87
+ 0,
88
+ (residual - REPROJECTION_CONFIDENCE_INNER_TEXELS) / interval,
89
+ ));
90
+ const eased = t * t * (3 - 2 * t);
91
+ return 1 - eased;
92
+ }
93
+
94
+ /**
95
+ * Mirrors the runtime coverage contribution used after depth reprojection.
96
+ * Validity can remove a frame from a pixel, but it must never renormalize the
97
+ * remaining frame to full opacity. Preserving angular support prevents a
98
+ * surface visible in only one capture from appearing as a second opaque layer.
99
+ *
100
+ * @param {readonly [number, number, number]} visibilityWeights
101
+ * @param {readonly [number, number, number]} correctedValidity
102
+ * @returns {[number, number, number]}
103
+ */
104
+ export function resolveImpostorCoverageWeights(
105
+ visibilityWeights,
106
+ correctedValidity,
107
+ ) {
108
+ const values = [...visibilityWeights, ...correctedValidity];
109
+ if (values.some((value) => !Number.isFinite(value) || value < 0)) {
110
+ throw new RangeError('Coverage weights and validity must be finite and non-negative.');
111
+ }
112
+ return /** @type {[number, number, number]} */ (
113
+ visibilityWeights.map((weight, index) => weight * correctedValidity[index])
114
+ );
115
+ }
116
+
117
+ /** @param {ImpostorDescriptor} descriptor */
118
+ export function createImpostorViewBoundsTexture(descriptor) {
119
+ const texture = new DataTexture(
120
+ new Float32Array(descriptor.viewBounds),
121
+ descriptor.frames,
122
+ descriptor.frames,
123
+ RGBAFormat,
124
+ FloatType,
125
+ );
126
+ texture.name = 'impostor view bounds';
127
+ texture.minFilter = NearestFilter;
128
+ texture.magFilter = NearestFilter;
129
+ texture.generateMipmaps = false;
130
+ texture.needsUpdate = true;
131
+ return texture;
132
+ }
133
+
134
+ /** @param {unknown} value */
135
+ function isBlendZone(value) {
136
+ return Number.isFinite(value)
137
+ && /** @type {number} */ (value) >= 0.35
138
+ && /** @type {number} */ (value) <= 1;
139
+ }