@margoengine/rigging 0.0.0-stage → 0.1.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 +201 -0
- package/NOTICE +4 -0
- package/README.md +969 -3
- package/dist/autorig.d.ts +50 -0
- package/dist/autorig.js +660 -0
- package/dist/bar-grip.d.ts +7 -0
- package/dist/checks.d.ts +50 -0
- package/dist/contact.d.ts +175 -0
- package/dist/contact.js +739 -0
- package/dist/correctives.d.ts +92 -0
- package/dist/correctives.js +162 -0
- package/dist/errors-D8rc8kzg.js +7 -0
- package/dist/face.d.ts +93 -0
- package/dist/face.js +144 -0
- package/dist/hands.d.ts +209 -0
- package/dist/hands.js +510 -0
- package/dist/heat.d.ts +38 -0
- package/dist/hinged-contact.d.ts +7 -0
- package/dist/hulls.d.ts +54 -0
- package/dist/hulls.js +134 -0
- package/dist/ik.d.ts +109 -0
- package/dist/ik.js +358 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +390 -0
- package/dist/joint-limits.d.ts +44 -0
- package/dist/joint-limits.js +74 -0
- package/dist/limb-collision.d.ts +99 -0
- package/dist/loading-CZaYr1N7.js +67 -0
- package/dist/mesh-CyvLHNp0.js +142 -0
- package/dist/mesh.d.ts +47 -0
- package/dist/mtoon-data.d.ts +118 -0
- package/dist/mtoon-legacy.d.ts +17 -0
- package/dist/mtoon-shader.d.ts +4 -0
- package/dist/mtoon.d.ts +84 -0
- package/dist/mtoon.js +990 -0
- package/dist/paint.d.ts +82 -0
- package/dist/pose-tracking.d.ts +117 -0
- package/dist/pose-tracking.js +488 -0
- package/dist/retarget.d.ts +71 -0
- package/dist/retarget.js +351 -0
- package/dist/rig-BawZ5OLb.js +127 -0
- package/dist/rig.d.ts +65 -0
- package/dist/shared/gltf.d.ts +257 -0
- package/dist/shared/layers.d.ts +16 -0
- package/dist/springs.d.ts +180 -0
- package/dist/springs.js +458 -0
- package/dist/strand-springs.d.ts +46 -0
- package/dist/strand-springs.js +168 -0
- package/dist/swim.d.ts +55 -0
- package/dist/swim.js +167 -0
- package/dist/transfer.d.ts +41 -0
- package/dist/transfer.js +136 -0
- package/dist/voxel-weights-48ok-Dax.js +255 -0
- package/dist/voxel-weights.d.ts +42 -0
- package/dist/voxel-weights.js +1 -0
- package/dist/voxels.d.ts +36 -0
- package/dist/vrm-constraints.d.ts +60 -0
- package/dist/vrm-constraints.js +261 -0
- package/dist/vrm-first-person.d.ts +115 -0
- package/dist/vrm-first-person.js +618 -0
- package/dist/vrm-presets-CU4V4yq6.js +47 -0
- package/dist/vrm-presets.d.ts +1 -0
- package/dist/vrm.d.ts +298 -0
- package/dist/vrm.js +574 -0
- package/dist/vrm0.d.ts +134 -0
- package/dist/vrm0.js +377 -0
- package/dist/vrma.d.ts +90 -0
- package/dist/vrma.js +315 -0
- package/dist/weight-map-D8cAONQQ.js +92 -0
- package/dist/weight-map.d.ts +58 -0
- package/package.json +175 -6
package/dist/swim.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { RigPose } from './rig.js';
|
|
2
|
+
/** The supplied swimming profiles, including a fin-driven ray. */
|
|
3
|
+
export type SwimSpecies = 'reef-fish' | 'reef-shark' | 'bottlenose-dolphin' | 'humpback-whale' | 'bluespotted-ray';
|
|
4
|
+
/** Scale and joint placement for a swimming skeleton. */
|
|
5
|
+
export interface SwimRigOptions {
|
|
6
|
+
/** Head to caudal-fin or fluke hinge in metres. */
|
|
7
|
+
readonly length: number;
|
|
8
|
+
/** Number of articulated spine segments. The tail hinge is one extra joint. Default 24. */
|
|
9
|
+
readonly segments?: number;
|
|
10
|
+
/** Optional nonuniform hinge positions as fractions of length, starting at 0 and ending at 1. */
|
|
11
|
+
readonly stations?: readonly number[];
|
|
12
|
+
/** Paired pectoral hinges, in head-relative metres. The closest spine station owns each hinge. */
|
|
13
|
+
readonly pectorals?: readonly [left: SwimFin, right: SwimFin];
|
|
14
|
+
}
|
|
15
|
+
/** Hinge locations and rotation range for a pectoral fin. */
|
|
16
|
+
export interface SwimFin {
|
|
17
|
+
/** Proximal hinge in head-relative metres. */
|
|
18
|
+
readonly position: readonly [number, number, number];
|
|
19
|
+
/** Available fin roll in radians. Default 0.22. */
|
|
20
|
+
readonly roll?: number;
|
|
21
|
+
/** Optional distal hinge in head-relative metres, for a travelling wave along a flexible fin. */
|
|
22
|
+
readonly distal?: readonly [number, number, number];
|
|
23
|
+
}
|
|
24
|
+
/** A sampled swimmer's topology and local bind pose. */
|
|
25
|
+
export interface SwimRig extends RigPose {
|
|
26
|
+
/** Profile used when sampling the chain. */
|
|
27
|
+
readonly species: SwimSpecies;
|
|
28
|
+
/** Head to caudal hinge, in metres. */
|
|
29
|
+
readonly length: number;
|
|
30
|
+
/** Fractional spine locations in head-to-tail order. */
|
|
31
|
+
readonly stations: readonly number[];
|
|
32
|
+
/** Optional calibrated paired fins. */
|
|
33
|
+
readonly pectorals?: readonly [left: SwimFin, right: SwimFin];
|
|
34
|
+
/** Local bind translations, quaternion rotations and scales, ten floats per joint. */
|
|
35
|
+
readonly rest: Float32Array;
|
|
36
|
+
}
|
|
37
|
+
/** Animated stroke controls at one sample of the swimmer's path. */
|
|
38
|
+
export interface SwimStroke {
|
|
39
|
+
/** Accumulated tail beats, including the fractional beat. Drive this continuously across speed changes. */
|
|
40
|
+
readonly phase: number;
|
|
41
|
+
/** Stroke amplitude. Fade to zero to coast. Default 1, range 0–1. */
|
|
42
|
+
readonly effort?: number;
|
|
43
|
+
/** Lateral body bend, left negative and right positive. Default 0, range −1 to 1. */
|
|
44
|
+
readonly turn?: number;
|
|
45
|
+
}
|
|
46
|
+
/** Create a Y-up, +Z-forward chain. The head is at the origin and the tail extends along −Z. */
|
|
47
|
+
export declare function createSwimRig(species: SwimSpecies, options: SwimRigOptions): SwimRig;
|
|
48
|
+
/** Estimate steady cruising cadence in beats/second using profile Strouhal number and peak-to-peak excursion. */
|
|
49
|
+
export declare function swimCadence(rig: SwimRig, speed: number, effort?: number): number;
|
|
50
|
+
/**
|
|
51
|
+
* Evaluate local translation/rotation/scale frames. The output may be reused and must have the
|
|
52
|
+
* same size as rig.rest. Each span follows an analytic body-wave tangent at its midpoint, keeping
|
|
53
|
+
* the underlying segment length constant. The last joint feathers the caudal fin or flukes.
|
|
54
|
+
*/
|
|
55
|
+
export declare function sampleSwimPose(rig: SwimRig, stroke: SwimStroke, out?: Float32Array<ArrayBuffer>): Float32Array;
|
package/dist/swim.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
//#region src/swim.ts
|
|
2
|
+
var e = {
|
|
3
|
+
"reef-fish": {
|
|
4
|
+
vertical: !1,
|
|
5
|
+
onset: .24,
|
|
6
|
+
envelope: 2,
|
|
7
|
+
wavelength: .94,
|
|
8
|
+
excursion: .095,
|
|
9
|
+
feather: .25,
|
|
10
|
+
strouhal: .29,
|
|
11
|
+
turn: .52
|
|
12
|
+
},
|
|
13
|
+
"reef-shark": {
|
|
14
|
+
vertical: !1,
|
|
15
|
+
onset: .16,
|
|
16
|
+
envelope: 1.6,
|
|
17
|
+
wavelength: 1.04,
|
|
18
|
+
excursion: .078,
|
|
19
|
+
feather: .16,
|
|
20
|
+
strouhal: .29,
|
|
21
|
+
turn: .48
|
|
22
|
+
},
|
|
23
|
+
"bottlenose-dolphin": {
|
|
24
|
+
vertical: !0,
|
|
25
|
+
onset: .46,
|
|
26
|
+
envelope: 2.1,
|
|
27
|
+
wavelength: 1.27,
|
|
28
|
+
excursion: .088,
|
|
29
|
+
feather: .33,
|
|
30
|
+
strouhal: .27,
|
|
31
|
+
turn: .49
|
|
32
|
+
},
|
|
33
|
+
"humpback-whale": {
|
|
34
|
+
vertical: !0,
|
|
35
|
+
onset: .48,
|
|
36
|
+
envelope: 2.45,
|
|
37
|
+
wavelength: 1.52,
|
|
38
|
+
excursion: .085,
|
|
39
|
+
feather: .4,
|
|
40
|
+
strouhal: .25,
|
|
41
|
+
turn: .38
|
|
42
|
+
},
|
|
43
|
+
"bluespotted-ray": {
|
|
44
|
+
vertical: !1,
|
|
45
|
+
onset: .78,
|
|
46
|
+
envelope: 2.6,
|
|
47
|
+
wavelength: 1.41,
|
|
48
|
+
excursion: .012,
|
|
49
|
+
feather: .04,
|
|
50
|
+
strouhal: .25,
|
|
51
|
+
turn: .16
|
|
52
|
+
}
|
|
53
|
+
}, t = 2 * Math.PI;
|
|
54
|
+
function n(t, n) {
|
|
55
|
+
if (!Object.hasOwn(e, t)) throw RangeError("Unknown swimming species profile; pass a supplied SwimSpecies");
|
|
56
|
+
let { length: i, segments: a = 24 } = n;
|
|
57
|
+
if (!Number.isFinite(i) || i < .001 || i > 1e3) throw RangeError("Swimmer length must be in the range 0.001–1000 metres");
|
|
58
|
+
if (!Number.isInteger(a) || a < 4 || a >= 65536) throw RangeError("A swimmer needs 4 to 65,535 spine segments");
|
|
59
|
+
let o = n.stations ? Array.from(n.stations) : Array.from({ length: a + 1 }, (e, t) => t / a);
|
|
60
|
+
if (o.length < 5 || o.length > 65536 || o[0] !== 0 || o.at(-1) !== 1 || o.some((e, t) => !Number.isFinite(e) || t > 0 && e - o[t - 1] < 1e-8)) throw RangeError("Swimmer stations need 5 to 65,536 increasing fractions from 0 to 1");
|
|
61
|
+
let s = (n.pectorals ?? (t === "bluespotted-ray" ? r(i) : void 0))?.map(({ position: e, roll: t = .22, distal: n }) => {
|
|
62
|
+
let r = (e) => e.length === 3 && e.every(Number.isFinite) && e[2] <= 0 && e[2] >= -i;
|
|
63
|
+
if (!r(e) || n && !r(n) || !Number.isFinite(t) || t < 0 || t > Math.PI / 2) throw RangeError("Pectoral hinge needs a finite XYZ position along the body and roll from 0 to π/2");
|
|
64
|
+
return {
|
|
65
|
+
position: [...e],
|
|
66
|
+
roll: t,
|
|
67
|
+
...n && { distal: [...n] }
|
|
68
|
+
};
|
|
69
|
+
}), c = s?.reduce((e, t) => e + (t.distal ? 2 : 1), 0) ?? 0;
|
|
70
|
+
if (s && s.length !== 2 || o.length + c > 65536) throw RangeError("Pectorals need a left/right pair with available joint indices");
|
|
71
|
+
let l = new Float32Array((o.length + c) * 10), u = o.length - 1;
|
|
72
|
+
for (let e = 0; e <= u; e++) {
|
|
73
|
+
let t = e > 0 ? (o[e] - o[e - 1]) * i : 0;
|
|
74
|
+
l.set([
|
|
75
|
+
0,
|
|
76
|
+
0,
|
|
77
|
+
-t,
|
|
78
|
+
0,
|
|
79
|
+
0,
|
|
80
|
+
0,
|
|
81
|
+
1,
|
|
82
|
+
1,
|
|
83
|
+
1,
|
|
84
|
+
1
|
|
85
|
+
], e * 10);
|
|
86
|
+
}
|
|
87
|
+
let d = o.map((e, t) => t === 0 ? "head" : t === u ? "caudal-fin" : `spine-${t}`), f = o.map((e, t) => t - 1);
|
|
88
|
+
return s?.forEach(({ position: e }, t) => {
|
|
89
|
+
let [n, r, a] = e, s = -a / i, c = o.reduce((e, t, n) => Math.abs(s - t) < Math.abs(s - o[e]) ? n : e, 0);
|
|
90
|
+
d.push(t === 0 ? "pectoral-L" : "pectoral-R"), f.push(c), l.set([
|
|
91
|
+
n,
|
|
92
|
+
r,
|
|
93
|
+
a + o[c] * i,
|
|
94
|
+
0,
|
|
95
|
+
0,
|
|
96
|
+
0,
|
|
97
|
+
1,
|
|
98
|
+
1,
|
|
99
|
+
1,
|
|
100
|
+
1
|
|
101
|
+
], (o.length + t) * 10);
|
|
102
|
+
}), s?.forEach(({ position: e, distal: t }, n) => {
|
|
103
|
+
if (!t) return;
|
|
104
|
+
let r = d.length * 10;
|
|
105
|
+
d.push(n === 0 ? "pectoral-tip-L" : "pectoral-tip-R"), f.push(o.length + n), l.set([
|
|
106
|
+
...t.map((t, n) => t - e[n]),
|
|
107
|
+
0,
|
|
108
|
+
0,
|
|
109
|
+
0,
|
|
110
|
+
1,
|
|
111
|
+
1,
|
|
112
|
+
1,
|
|
113
|
+
1
|
|
114
|
+
], r);
|
|
115
|
+
}), {
|
|
116
|
+
species: t,
|
|
117
|
+
length: i,
|
|
118
|
+
stations: o,
|
|
119
|
+
names: d,
|
|
120
|
+
parents: f,
|
|
121
|
+
rest: l,
|
|
122
|
+
...s && { pectorals: s }
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function r(e) {
|
|
126
|
+
let t = (t) => ({
|
|
127
|
+
position: [
|
|
128
|
+
t * e * .054,
|
|
129
|
+
e * .022,
|
|
130
|
+
-e * .05
|
|
131
|
+
],
|
|
132
|
+
distal: [
|
|
133
|
+
t * e * .285,
|
|
134
|
+
e * .015,
|
|
135
|
+
-e * .21
|
|
136
|
+
],
|
|
137
|
+
roll: .68
|
|
138
|
+
});
|
|
139
|
+
return [t(1), t(-1)];
|
|
140
|
+
}
|
|
141
|
+
function i(t, n, r = 1) {
|
|
142
|
+
if (!Number.isFinite(n) || n < 0 || !Number.isFinite(r) || r <= 0 || r > 1) throw RangeError("Cruising speed must be nonnegative and effort greater than 0, up to 1");
|
|
143
|
+
let i = e[t.species], a = t.species === "bluespotted-ray" ? .13 : i.excursion, o = i.strouhal * n / (2 * a * t.length * r);
|
|
144
|
+
if (!Number.isFinite(o)) throw RangeError("Cruising cadence exceeds the finite range; increase effort or lower speed");
|
|
145
|
+
return o;
|
|
146
|
+
}
|
|
147
|
+
function a(n, r, i = new Float32Array(n.rest.length)) {
|
|
148
|
+
let { phase: a, effort: o = 1, turn: s = 0 } = r;
|
|
149
|
+
if (!Number.isFinite(a) || !Number.isFinite(o) || o < 0 || o > 1 || !Number.isFinite(s) || Math.abs(s) > 1) throw RangeError("A swim stroke needs a finite phase, effort from 0 to 1 and turn from −1 to 1");
|
|
150
|
+
if (i.length !== n.rest.length || i.buffer === n.rest.buffer) throw RangeError("The swim output must be separate from the matching rest pose");
|
|
151
|
+
if (i.set(n.rest), o === 0 && s === 0) return i;
|
|
152
|
+
let { vertical: c, onset: l, envelope: u, wavelength: d, excursion: f, feather: p, turn: m } = e[n.species], h = t / d, g = a % 1 * t, _ = n.stations.length - 1, v = 0, y = 0, b = 0, x = 1;
|
|
153
|
+
for (let e = 0; e <= _; e++) {
|
|
154
|
+
let t = e === _ ? 1 : (n.stations[e] + n.stations[e + 1]) * .5, r = Math.max(0, (t - l) / (1 - l)), a = h * t - g, d = r ** u, S = u * r ** (u - 1) / (1 - l), C = o * f * (S * Math.sin(a) + h * d * Math.cos(a)), w = e === _ ? o * p * Math.cos(a - Math.PI / 4) : 0, T = s * m * t * t + (c ? 0 : -Math.atan(C) + w), E = c ? Math.atan(C) + w : 0, D = T * .5, O = E * .5, k = Math.cos(D) * Math.sin(O), A = Math.sin(D) * Math.cos(O), j = -Math.sin(D) * Math.sin(O), M = Math.cos(D) * Math.cos(O), N = e * 10 + 3;
|
|
155
|
+
i[N] = x * k - v * M - y * j + b * A, i[N + 1] = x * A + v * j - y * M - b * k, i[N + 2] = x * j - v * A + y * k - b * M, i[N + 3] = x * M + v * k + y * A + b * j, v = k, y = A, b = j, x = M;
|
|
156
|
+
}
|
|
157
|
+
let S = _ + 3;
|
|
158
|
+
return n.pectorals?.forEach(({ roll: e = .22, distal: t }, r) => {
|
|
159
|
+
let a = r === 0 ? 1 : -1, l = n.species === "bluespotted-ray", u = g + a * .16 - .67, d = (a * (o * (l ? .85 : c ? .41 : .19) * Math.sin(u)) + s * .52) * e * .5, f = (_ + 1 + r) * 10;
|
|
160
|
+
if (i[f + 5] = Math.sin(d), i[f + 6] = Math.cos(d), t) {
|
|
161
|
+
let t = (a * o * Math.sin(u - .78) + s * .18) * e * .5 - d;
|
|
162
|
+
i[S * 10 + 5] = Math.sin(t), i[S * 10 + 6] = Math.cos(t), S++;
|
|
163
|
+
}
|
|
164
|
+
}), i;
|
|
165
|
+
}
|
|
166
|
+
//#endregion
|
|
167
|
+
export { n as createSwimRig, a as sampleSwimPose, i as swimCadence };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type WeightMesh } from './mesh.js';
|
|
2
|
+
import { WeightMap, type VertexInfluences } from './weight-map.js';
|
|
3
|
+
/** A skinned mesh to copy from. */
|
|
4
|
+
export interface WeightSource extends WeightMesh {
|
|
5
|
+
/** One row per vertex: a {@link WeightMap}, or JOINTS_0 / WEIGHTS_0 style influences. */
|
|
6
|
+
readonly weights: WeightMap | VertexInfluences;
|
|
7
|
+
}
|
|
8
|
+
/** Options for {@link transferWeights}. */
|
|
9
|
+
export interface TransferOptions {
|
|
10
|
+
/** Bones in the result, for influences that do not use the last ones. Default the source's. */
|
|
11
|
+
boneCount?: number;
|
|
12
|
+
/** Farthest a match may be, as a fraction of the source's size (default 0.05). */
|
|
13
|
+
maxDistance?: number;
|
|
14
|
+
/** Largest angle between the two surfaces at a match, degrees, 0 to 90 (default 60); either facing counts. */
|
|
15
|
+
maxAngle?: number;
|
|
16
|
+
/** Most conjugate-gradient steps of the fill per bone (default 1,000); it stops once the residual is 1e-10 of the start. */
|
|
17
|
+
iterations?: number;
|
|
18
|
+
/** Weights below this are dropped before renormalising (default 1e-4). */
|
|
19
|
+
threshold?: number;
|
|
20
|
+
/** Welding tolerance of the target as a fraction of its size (default 1e-6: coincident vertices). */
|
|
21
|
+
weld?: number;
|
|
22
|
+
/** Cancels the transfer; the promise rejects with the signal's reason. */
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}
|
|
25
|
+
/** {@link transferWeights}'s result. */
|
|
26
|
+
export interface TransferResult {
|
|
27
|
+
/** Weights over the target's vertices. */
|
|
28
|
+
readonly weights: WeightMap;
|
|
29
|
+
/** Target points that matched the source. */
|
|
30
|
+
readonly matched: number;
|
|
31
|
+
/** Target points filled from their neighbours. */
|
|
32
|
+
readonly filled: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Copies skin weights from `source` to `target` by proximity. Both meshes share one space. Vertices at one position get
|
|
36
|
+
* the same weights. Resolves to a {@link WeightMap} over the target's vertices, with how many points matched and how
|
|
37
|
+
* many were filled in. A part of the target with no match at all, such as a hat far from the body, takes the closest
|
|
38
|
+
* weights as they are.
|
|
39
|
+
* @throws TypeError or RangeError for invalid input.
|
|
40
|
+
*/
|
|
41
|
+
export declare function transferWeights(source: WeightSource, target: WeightMesh, options?: TransferOptions): Promise<TransferResult>;
|
package/dist/transfer.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { t as e } from "./weight-map-D8cAONQQ.js";
|
|
2
|
+
import { i as t, r as n, t as r } from "./mesh-CyvLHNp0.js";
|
|
3
|
+
import { MargoError as i } from "@margoengine/math/errors";
|
|
4
|
+
//#region src/transfer.ts
|
|
5
|
+
var a = 30;
|
|
6
|
+
function o(e) {
|
|
7
|
+
let t = e.positions, n = e.triangles, r = new Float64Array(t.length);
|
|
8
|
+
for (let e = 0; e < n.length; e += 3) {
|
|
9
|
+
let i = n[e] * 3, a = n[e + 1] * 3, o = n[e + 2] * 3, s = t[a] - t[i], c = t[a + 1] - t[i + 1], l = t[a + 2] - t[i + 2], u = t[o] - t[i], d = t[o + 1] - t[i + 1], f = t[o + 2] - t[i + 2], p = c * f - l * d, m = l * u - s * f, h = s * d - c * u;
|
|
10
|
+
for (let e of [
|
|
11
|
+
i,
|
|
12
|
+
a,
|
|
13
|
+
o
|
|
14
|
+
]) r[e] += p, r[e + 1] += m, r[e + 2] += h;
|
|
15
|
+
}
|
|
16
|
+
for (let e = 0; e < r.length; e += 3) {
|
|
17
|
+
let t = Math.hypot(r[e], r[e + 1], r[e + 2]);
|
|
18
|
+
t > 0 && (r[e] /= t, r[e + 1] /= t, r[e + 2] /= t);
|
|
19
|
+
}
|
|
20
|
+
return r;
|
|
21
|
+
}
|
|
22
|
+
async function s(s, c, l = {}) {
|
|
23
|
+
let { maxDistance: u = .05, maxAngle: d = 60, iterations: f = 1e3, threshold: p = 1e-4, signal: m } = l;
|
|
24
|
+
if (!(u > 0 && u < Infinity)) throw RangeError("Transfer maxDistance must be above 0");
|
|
25
|
+
if (!(d >= 0 && d <= 90)) throw RangeError("Transfer maxAngle must be from 0 to 90 degrees");
|
|
26
|
+
if (!Number.isInteger(f) || f < 0) throw RangeError("Transfer iterations must be 0 or more");
|
|
27
|
+
if (!(p >= 0 && p < .5)) throw RangeError("Transfer threshold must be from 0 to below 0.5");
|
|
28
|
+
m?.throwIfAborted();
|
|
29
|
+
let h = s?.weights instanceof e ? s.weights : e.fromInfluences(s?.weights, l.boneCount), g = l.boneCount ?? h.boneCount, _ = s?.positions, v = _?.length / 3;
|
|
30
|
+
if (g < h.boneCount) throw RangeError(`Transfer boneCount ${g} is under the source's ${h.boneCount}; raise it`);
|
|
31
|
+
if (h.vertexCount !== v) throw RangeError(`Transfer source has ${v} vertices and ${h.vertexCount} rows; give one row each`);
|
|
32
|
+
let y = t({
|
|
33
|
+
positions: _,
|
|
34
|
+
indices: s.indices
|
|
35
|
+
}, 0), b = t(c, l.weld);
|
|
36
|
+
if (!y.triangles.length) throw RangeError("Transfer source needs triangles; pass a mesh with faces");
|
|
37
|
+
let x;
|
|
38
|
+
try {
|
|
39
|
+
x = await import("@margoengine/bvh");
|
|
40
|
+
} catch (e) {
|
|
41
|
+
throw new i("unsupported", `Weight transfer needs @margoengine/bvh (${String(e)}); install it`);
|
|
42
|
+
}
|
|
43
|
+
m?.throwIfAborted();
|
|
44
|
+
let S = new Int32Array(y.positions.length / 3).fill(-1);
|
|
45
|
+
for (let e = v - 1; e >= 0; e--) S[y.point[e]] = e;
|
|
46
|
+
let C = x.MeshBVH.build({
|
|
47
|
+
positions: y.positions,
|
|
48
|
+
indices: y.triangles
|
|
49
|
+
}), w = b.positions.length / 3, T = new Float32Array(w * g), E = new Uint8Array(w), D = o(b), O = u * y.size, k = Math.cos(d * Math.PI / 180) - 1e-9, A = y.positions, j = y.triangles, M = h.boneCount, N = h.values, P = [
|
|
50
|
+
0,
|
|
51
|
+
0,
|
|
52
|
+
0
|
|
53
|
+
], F = performance.now();
|
|
54
|
+
for (let e = 0; e < w; e++) {
|
|
55
|
+
P[0] = b.positions[e * 3], P[1] = b.positions[e * 3 + 1], P[2] = b.positions[e * 3 + 2];
|
|
56
|
+
let t = C.closestPointToPoint(P), n = j[t.faceIndex * 3], r = j[t.faceIndex * 3 + 1], i = j[t.faceIndex * 3 + 2], [o, s, c] = t.barycoord, l = S[n] * M, u = S[r] * M, d = S[i] * M;
|
|
57
|
+
for (let t = 0; t < M; t++) T[e * g + t] = N[l + t] * o + N[u + t] * s + N[d + t] * c;
|
|
58
|
+
let f = A[r * 3] - A[n * 3], p = A[r * 3 + 1] - A[n * 3 + 1], h = A[r * 3 + 2] - A[n * 3 + 2], _ = A[i * 3] - A[n * 3], v = A[i * 3 + 1] - A[n * 3 + 1], y = A[i * 3 + 2] - A[n * 3 + 2], x = p * y - h * v, w = h * _ - f * y, I = f * v - p * _, L = Math.hypot(x, w, I) || 1, R = Math.abs(x * D[e * 3] + w * D[e * 3 + 1] + I * D[e * 3 + 2]) / L, z = D[e * 3] || D[e * 3 + 1] || D[e * 3 + 2];
|
|
59
|
+
t.distance <= O && (!z || R >= k) && (E[e] = 1), performance.now() - F > a && (await new Promise((e) => setTimeout(e)), F = performance.now(), m?.throwIfAborted());
|
|
60
|
+
}
|
|
61
|
+
let I = r(b), L = /* @__PURE__ */ new Set();
|
|
62
|
+
for (let e = 0; e < w; e++) E[e] && L.add(I[e]);
|
|
63
|
+
for (let e = 0; e < w; e++) L.has(I[e]) || (E[e] = 1);
|
|
64
|
+
let { offsets: R, columns: z } = n(b), B = [];
|
|
65
|
+
for (let e = 0; e < w; e++) E[e] || B.push(e);
|
|
66
|
+
let V = new Float32Array(z.length), H = b.positions;
|
|
67
|
+
for (let e of B) for (let t = R[e]; t < R[e + 1]; t++) {
|
|
68
|
+
let n = z[t];
|
|
69
|
+
V[t] = 1 / Math.max(1e-12, Math.hypot(H[e * 3] - H[n * 3], H[e * 3 + 1] - H[n * 3 + 1], H[e * 3 + 2] - H[n * 3 + 2]));
|
|
70
|
+
}
|
|
71
|
+
let U = new Int32Array(w).fill(-1);
|
|
72
|
+
B.forEach((e, t) => U[e] = t);
|
|
73
|
+
let W = B.length, G = new Float64Array(W), K = new Float64Array(W), q = new Float64Array(W), J = new Float64Array(W), Y = new Float64Array(W), X = new Float64Array(W), Z = new Float64Array(W);
|
|
74
|
+
B.forEach((e, t) => {
|
|
75
|
+
for (let n = R[e]; n < R[e + 1]; n++) G[t] += V[n];
|
|
76
|
+
});
|
|
77
|
+
let Q = (e, t) => {
|
|
78
|
+
for (let n = 0; n < W; n++) {
|
|
79
|
+
let r = B[n], i = G[n] * e[n];
|
|
80
|
+
for (let t = R[r]; t < R[r + 1]; t++) {
|
|
81
|
+
let n = U[z[t]];
|
|
82
|
+
n >= 0 && (i -= V[t] * e[n]);
|
|
83
|
+
}
|
|
84
|
+
t[n] = i;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
for (let e = 0; e < g && W; e++) {
|
|
88
|
+
let t = 0;
|
|
89
|
+
for (let n = 0; n < W; n++) {
|
|
90
|
+
let r = B[n], i = 0;
|
|
91
|
+
for (let t = R[r]; t < R[r + 1]; t++) U[z[t]] < 0 && (i += V[t] * T[z[t] * g + e]);
|
|
92
|
+
Z[n] = i, t += i * i, K[n] = T[r * g + e];
|
|
93
|
+
}
|
|
94
|
+
if (!(t > 0)) {
|
|
95
|
+
for (let t of B) T[t * g + e] = 0;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
Q(K, X);
|
|
99
|
+
let n = 0;
|
|
100
|
+
for (let e = 0; e < W; e++) q[e] = Z[e] - X[e], J[e] = q[e] / G[e], Y[e] = J[e], n += q[e] * J[e];
|
|
101
|
+
let r = 1e-20 * t;
|
|
102
|
+
for (let e = 0; e < f; e++) {
|
|
103
|
+
let e = 0;
|
|
104
|
+
for (let t = 0; t < W; t++) e += q[t] * q[t];
|
|
105
|
+
if (e <= r) break;
|
|
106
|
+
Q(Y, X);
|
|
107
|
+
let t = 0;
|
|
108
|
+
for (let e = 0; e < W; e++) t += Y[e] * X[e];
|
|
109
|
+
if (!(t > 0)) break;
|
|
110
|
+
let i = n / t, o = 0;
|
|
111
|
+
for (let e = 0; e < W; e++) K[e] += i * Y[e], q[e] -= i * X[e], J[e] = q[e] / G[e], o += q[e] * J[e];
|
|
112
|
+
let s = o / n;
|
|
113
|
+
n = o;
|
|
114
|
+
for (let e = 0; e < W; e++) Y[e] = J[e] + s * Y[e];
|
|
115
|
+
performance.now() - F > a && (await new Promise((e) => setTimeout(e)), F = performance.now(), m?.throwIfAborted());
|
|
116
|
+
}
|
|
117
|
+
for (let t = 0; t < W; t++) T[B[t] * g + e] = Math.min(1, Math.max(0, K[t]));
|
|
118
|
+
}
|
|
119
|
+
let $ = new e(b.vertexCount, g);
|
|
120
|
+
for (let e = 0; e < w; e++) {
|
|
121
|
+
let t = 0;
|
|
122
|
+
for (let n = 0; n < g; n++) {
|
|
123
|
+
let r = e * g + n;
|
|
124
|
+
T[r] < p && (T[r] = 0), t += T[r];
|
|
125
|
+
}
|
|
126
|
+
if (t > 0) for (let n = 0; n < g; n++) T[e * g + n] /= t;
|
|
127
|
+
}
|
|
128
|
+
for (let e = 0; e < b.vertexCount; e++) $.values.set(T.subarray(b.point[e] * g, (b.point[e] + 1) * g), e * g);
|
|
129
|
+
return {
|
|
130
|
+
weights: $,
|
|
131
|
+
matched: w - B.length,
|
|
132
|
+
filled: B.length
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
export { s as transferWeights };
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { t as e } from "./weight-map-D8cAONQQ.js";
|
|
2
|
+
import { i as t, n, o as r, t as i } from "./rig-BawZ5OLb.js";
|
|
3
|
+
import { i as a } from "./mesh-CyvLHNp0.js";
|
|
4
|
+
function o(e, t, n) {
|
|
5
|
+
let r = e.positions, i = [
|
|
6
|
+
Infinity,
|
|
7
|
+
Infinity,
|
|
8
|
+
Infinity
|
|
9
|
+
], a = [
|
|
10
|
+
-Infinity,
|
|
11
|
+
-Infinity,
|
|
12
|
+
-Infinity
|
|
13
|
+
];
|
|
14
|
+
for (let e = 0; e < r.length; e++) {
|
|
15
|
+
let t = e % 3;
|
|
16
|
+
r[e] < i[t] && (i[t] = r[e]), r[e] > a[t] && (a[t] = r[e]);
|
|
17
|
+
}
|
|
18
|
+
for (let e of t) for (let t = 0; t < 3; t++) e.position[t] < i[t] && (i[t] = e.position[t]), e.position[t] > a[t] && (a[t] = e.position[t]);
|
|
19
|
+
let o = Math.max(a[0] - i[0], a[1] - i[1], a[2] - i[2]);
|
|
20
|
+
if (!(o > 0)) throw RangeError("Voxel weights need a mesh with some size; every point is the same");
|
|
21
|
+
let s = o / n, c = [
|
|
22
|
+
0,
|
|
23
|
+
1,
|
|
24
|
+
2
|
|
25
|
+
].map((e) => Math.ceil((a[e] - i[e]) / s) + 3);
|
|
26
|
+
return {
|
|
27
|
+
nx: c[0],
|
|
28
|
+
ny: c[1],
|
|
29
|
+
nz: c[2],
|
|
30
|
+
cell: s,
|
|
31
|
+
origin: [
|
|
32
|
+
0,
|
|
33
|
+
1,
|
|
34
|
+
2
|
|
35
|
+
].map((e) => (i[e] + a[e]) / 2 - c[e] * s / 2),
|
|
36
|
+
state: new Uint8Array(c[0] * c[1] * c[2])
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function s(e, t) {
|
|
40
|
+
let { nx: n, ny: r, cell: i, origin: a, state: o } = e, s = t.positions, c = t.triangles, l = (e, t, s) => {
|
|
41
|
+
o[Math.floor((e - a[0]) / i) + n * (Math.floor((t - a[1]) / i) + r * Math.floor((s - a[2]) / i))] = 1;
|
|
42
|
+
};
|
|
43
|
+
for (let e = 0; e < c.length; e += 3) {
|
|
44
|
+
let t = c[e] * 3, n = c[e + 1] * 3, r = c[e + 2] * 3, a = Math.max(Math.hypot(s[n] - s[t], s[n + 1] - s[t + 1], s[n + 2] - s[t + 2]), Math.hypot(s[r] - s[t], s[r + 1] - s[t + 1], s[r + 2] - s[t + 2]), Math.hypot(s[r] - s[n], s[r + 1] - s[n + 1], s[r + 2] - s[n + 2])), o = Math.max(1, Math.ceil(a / i * 2));
|
|
45
|
+
for (let e = 0; e <= o; e++) for (let i = 0; i <= o - e; i++) {
|
|
46
|
+
let a = e / o, c = i / o, u = 1 - a - c;
|
|
47
|
+
l(s[t] * u + s[n] * a + s[r] * c, s[t + 1] * u + s[n + 1] * a + s[r + 1] * c, s[t + 2] * u + s[n + 2] * a + s[r + 2] * c);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function c(e, t) {
|
|
52
|
+
let { nx: n, ny: r, nz: i, state: a } = e, o = a.length, s = a.slice(), c = (e, t, a, o) => {
|
|
53
|
+
for (let s = 1; s < i - 1; s++) for (let i = 1; i < r - 1; i++) for (let c = 1; c < n - 1; c++) {
|
|
54
|
+
let l = c + n * (i + r * s);
|
|
55
|
+
(e[l] === 0 || o(e[l])) && (o(e[l - 1]) || o(e[l + 1]) || o(e[l - n]) || o(e[l + n]) || o(e[l - n * r]) || o(e[l + n * r])) && (t[l] = a);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
for (let e = 0; e < t; e++) c(s.slice(), s, 1, (e) => e === 1);
|
|
59
|
+
let l = new Uint8Array(o), u = new Int32Array(o), d = 0;
|
|
60
|
+
for (u[d++] = 0, l[0] = 1; d;) {
|
|
61
|
+
let e = u[--d], t = e % n, a = (e / n | 0) % r, o = e / (n * r) | 0, c = (e) => {
|
|
62
|
+
!l[e] && s[e] === 0 && (l[e] = 1, u[d++] = e);
|
|
63
|
+
};
|
|
64
|
+
t > 0 && c(e - 1), t < n - 1 && c(e + 1), a > 0 && c(e - n), a < r - 1 && c(e + n), o > 0 && c(e - n * r), o < i - 1 && c(e + n * r);
|
|
65
|
+
}
|
|
66
|
+
for (let e = 0; e < t; e++) {
|
|
67
|
+
let e = l.slice();
|
|
68
|
+
for (let t = 1; t < i - 1; t++) for (let i = 1; i < r - 1; i++) for (let o = 1; o < n - 1; o++) {
|
|
69
|
+
let s = o + n * (i + r * t);
|
|
70
|
+
e[s] || a[s] === 1 || (e[s - 1] || e[s + 1] || e[s - n] || e[s + n] || e[s - n * r] || e[s + n * r]) && (l[s] = 1);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for (let e = 0; e < o; e++) !l[e] && a[e] !== 1 && (a[e] = 2);
|
|
74
|
+
}
|
|
75
|
+
function l(e) {
|
|
76
|
+
let { nx: t, ny: n, nz: r, state: i } = e, a = new Uint8Array(i.length), o = (e, t, n) => {
|
|
77
|
+
for (let r = !1, o = 0, s = e; o < n; o++, s += t) i[s] === 0 ? r && a[s]++ : r = !0;
|
|
78
|
+
for (let r = !1, o = 0, s = e + t * (n - 1); o < n; o++, s -= t) i[s] === 0 ? r && a[s]++ : r = !0;
|
|
79
|
+
};
|
|
80
|
+
for (let e = 0; e < r; e++) for (let r = 0; r < n; r++) o(t * (r + n * e), 1, t);
|
|
81
|
+
for (let e = 0; e < r; e++) for (let r = 0; r < t; r++) o(r + t * n * e, t, n);
|
|
82
|
+
for (let e = 0; e < n; e++) for (let i = 0; i < t; i++) o(i + t * e, t * n, r);
|
|
83
|
+
return a;
|
|
84
|
+
}
|
|
85
|
+
var u = class {
|
|
86
|
+
constructor() {
|
|
87
|
+
this.keys = /* @__PURE__ */ new Float64Array(1024), this.items = /* @__PURE__ */ new Int32Array(1024), this.size = 0, this.item = 0, this.key = 0;
|
|
88
|
+
}
|
|
89
|
+
push(e, t) {
|
|
90
|
+
if (this.size === this.keys.length) {
|
|
91
|
+
let e = new Float64Array(this.size * 2), t = new Int32Array(this.size * 2);
|
|
92
|
+
e.set(this.keys), t.set(this.items), this.keys = e, this.items = t;
|
|
93
|
+
}
|
|
94
|
+
let n = this.size++, { keys: r, items: i } = this;
|
|
95
|
+
for (; n > 0;) {
|
|
96
|
+
let t = n - 1 >> 1;
|
|
97
|
+
if (r[t] <= e) break;
|
|
98
|
+
r[n] = r[t], i[n] = i[t], n = t;
|
|
99
|
+
}
|
|
100
|
+
r[n] = e, i[n] = t;
|
|
101
|
+
}
|
|
102
|
+
pop() {
|
|
103
|
+
let { keys: e, items: t } = this;
|
|
104
|
+
this.item = t[0], this.key = e[0];
|
|
105
|
+
let n = --this.size, r = e[n], i = t[n], a = 0;
|
|
106
|
+
for (;;) {
|
|
107
|
+
let i = a * 2 + 1;
|
|
108
|
+
if (i >= n || (i + 1 < n && e[i + 1] < e[i] && i++, e[i] >= r)) break;
|
|
109
|
+
e[a] = e[i], t[a] = t[i], a = i;
|
|
110
|
+
}
|
|
111
|
+
e[a] = r, t[a] = i;
|
|
112
|
+
}
|
|
113
|
+
}, d = Array.from({ length: 27 }, (e, t) => {
|
|
114
|
+
let n = t % 3 - 1, r = (t / 3 | 0) % 3 - 1, i = (t / 9 | 0) - 1;
|
|
115
|
+
return [
|
|
116
|
+
n,
|
|
117
|
+
r,
|
|
118
|
+
i,
|
|
119
|
+
Math.hypot(n, r, i)
|
|
120
|
+
];
|
|
121
|
+
}).filter((e) => e[3] > 0), f = 30;
|
|
122
|
+
function p(e, t, n) {
|
|
123
|
+
let { nx: r, ny: i, nz: a, state: o } = e, s = t.slice();
|
|
124
|
+
for (; s.length;) {
|
|
125
|
+
let e = s.pop(), t = e % r, c = (e / r | 0) % i, l = e / (r * i) | 0, u = (e) => {
|
|
126
|
+
o[e] === 0 && n[e] >= 4 && (o[e] = 2, s.push(e));
|
|
127
|
+
};
|
|
128
|
+
t > 0 && u(e - 1), t < r - 1 && u(e + 1), c > 0 && u(e - r), c < i - 1 && u(e + r), l > 0 && u(e - r * i), l < a - 1 && u(e + r * i);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function m(e, t, n) {
|
|
132
|
+
let { nx: r, ny: i, nz: a, cell: o, origin: s, state: c } = e, l = Array.from({ length: n }, () => /* @__PURE__ */ new Set()), u = [], { points: d, owners: f } = t, p = (e, t) => Math.floor((e - s[t]) / o);
|
|
133
|
+
for (let e = 0; e < f.length; e++) {
|
|
134
|
+
let t = e * 6, n = Math.hypot(d[t + 3] - d[t], d[t + 4] - d[t + 1], d[t + 5] - d[t + 2]), s = Math.max(1, Math.ceil(n / o * 2));
|
|
135
|
+
for (let n = 0; n <= s; n++) {
|
|
136
|
+
let o = n / s, m = p(d[t] + (d[t + 3] - d[t]) * o, 0), h = p(d[t + 1] + (d[t + 4] - d[t + 1]) * o, 1), g = p(d[t + 2] + (d[t + 5] - d[t + 2]) * o, 2);
|
|
137
|
+
if (m < 0 || h < 0 || g < 0 || m >= r || h >= i || g >= a) continue;
|
|
138
|
+
let _ = m + r * (h + i * g);
|
|
139
|
+
c[_] === 0 && (c[_] = 2, u.push(_)), l[f[e]].add(_);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
seeds: l,
|
|
144
|
+
leaked: u
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function h(e, t, n, r) {
|
|
148
|
+
let { nx: i, ny: a, nz: o, cell: s, state: c } = e;
|
|
149
|
+
n.fill(Infinity), r.size = 0;
|
|
150
|
+
for (let e of t) n[e] = 0, r.push(0, e);
|
|
151
|
+
for (; r.size;) {
|
|
152
|
+
r.pop();
|
|
153
|
+
let e = r.item, t = r.key;
|
|
154
|
+
if (t > n[e]) continue;
|
|
155
|
+
let l = e % i, u = (e / i | 0) % a, f = e / (i * a) | 0;
|
|
156
|
+
for (let [e, p, m, h] of d) {
|
|
157
|
+
let d = l + e, g = u + p, _ = f + m;
|
|
158
|
+
if (d < 0 || g < 0 || _ < 0 || d >= i || g >= a || _ >= o) continue;
|
|
159
|
+
let v = d + i * (g + a * _);
|
|
160
|
+
if (c[v] === 0) continue;
|
|
161
|
+
let y = t + h * s;
|
|
162
|
+
y < n[v] && (n[v] = y, r.push(y, v));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async function g(d, g, _ = {}) {
|
|
167
|
+
n(g);
|
|
168
|
+
let { resolution: v = 96, skip: y = [], falloff: b = 4, curve: x = .75, influences: S = 4, closing: C = 0, signal: w } = _;
|
|
169
|
+
if (!Number.isInteger(v) || v < 8 || v > 512) throw RangeError("Voxel resolution must be an integer from 8 to 512");
|
|
170
|
+
if (!(b > 0 && b < Infinity)) throw RangeError("Voxel falloff must be finite and above 0");
|
|
171
|
+
if (!(x >= 0 && x <= 1)) throw RangeError("Voxel curve must be from 0 to 1");
|
|
172
|
+
if (!Number.isInteger(S) || S < 1) throw RangeError("Voxel influences must be 1 or more");
|
|
173
|
+
if (!Number.isInteger(C) || C < 0 || C > 8) throw RangeError("Voxel closing must be an integer from 0 to 8");
|
|
174
|
+
w?.throwIfAborted();
|
|
175
|
+
let T = new Set(t(g, y, "Voxel weights skip"));
|
|
176
|
+
if (T.size === g.length) throw RangeError("Voxel weights skip every joint; leave at least one to move");
|
|
177
|
+
let E = a(d, _.weld), D = o(E, g, v), { nx: O, ny: k, nz: A, cell: j, origin: M, state: N } = D;
|
|
178
|
+
s(D, E), c(D, C);
|
|
179
|
+
let ee = l(D), P = i(g, (e) => !T.has(e)), { seeds: F, leaked: te } = m(D, P, g.length);
|
|
180
|
+
p(D, te, ee);
|
|
181
|
+
let I = E.positions, L = I.length / 3, R = Math.min(S, g.length), z = new Float32Array(L * R).fill(Infinity), B = new Int32Array(L * R).fill(-1), V = new Float64Array(N.length), ne = new u(), H = (e, t, n) => {
|
|
182
|
+
let r = e * R, i = R;
|
|
183
|
+
for (; i > 0 && n < z[r + i - 1];) i--;
|
|
184
|
+
if (i !== R) {
|
|
185
|
+
for (let e = R - 1; e > i; e--) z[r + e] = z[r + e - 1], B[r + e] = B[r + e - 1];
|
|
186
|
+
z[r + i] = n, B[r + i] = t;
|
|
187
|
+
}
|
|
188
|
+
}, U = new Int32Array(L * 8), W = new Float32Array(L * 8);
|
|
189
|
+
for (let e = 0; e < L; e++) {
|
|
190
|
+
let t = (I[e * 3] - M[0]) / j - .5, n = (I[e * 3 + 1] - M[1]) / j - .5, r = (I[e * 3 + 2] - M[2]) / j - .5, i = Math.min(O - 2, Math.max(0, Math.floor(t))), a = Math.min(k - 2, Math.max(0, Math.floor(n))), o = Math.min(A - 2, Math.max(0, Math.floor(r))), s = t - i, c = n - a, l = r - o;
|
|
191
|
+
for (let t = 0; t < 8; t++) {
|
|
192
|
+
let n = t & 1, r = t >> 1 & 1, u = t >> 2;
|
|
193
|
+
U[e * 8 + t] = i + n + O * (a + r + k * (o + u)), W[e * 8 + t] = (n ? s : 1 - s) * (r ? c : 1 - c) * (u ? l : 1 - l);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
let G = performance.now();
|
|
197
|
+
for (let e = 0; e < g.length; e++) if (F[e].size) {
|
|
198
|
+
h(D, F[e], V, ne);
|
|
199
|
+
for (let t = 0; t < L; t++) {
|
|
200
|
+
let n = 0, r = 0;
|
|
201
|
+
for (let e = 0; e < 8; e++) {
|
|
202
|
+
let i = V[U[t * 8 + e]];
|
|
203
|
+
i !== Infinity && (n += i * W[t * 8 + e], r += W[t * 8 + e]);
|
|
204
|
+
}
|
|
205
|
+
r > 0 && H(t, e, n / r);
|
|
206
|
+
}
|
|
207
|
+
performance.now() - G > f && (await new Promise((e) => setTimeout(e)), G = performance.now(), w?.throwIfAborted());
|
|
208
|
+
}
|
|
209
|
+
let K = new Int32Array(L).fill(-1), q = new Int32Array(E.vertexCount);
|
|
210
|
+
for (let e = E.vertexCount - 1; e >= 0; e--) q[e] = K[E.point[e]], K[E.point[e]] = e;
|
|
211
|
+
let J = new e(E.vertexCount, g.length), Y = new Float32Array(g.length), X = new Float64Array(g.length), Z = new Float64Array(g.length), Q = 0;
|
|
212
|
+
for (let e = 0; e < L; e++) {
|
|
213
|
+
let t = e * R;
|
|
214
|
+
if (B[t] === -1) {
|
|
215
|
+
Q++, Z.fill(Infinity);
|
|
216
|
+
for (let t = 0; t < P.owners.length; t++) {
|
|
217
|
+
let n = P.owners[t], i = r(P.points, t, I[e * 3], I[e * 3 + 1], I[e * 3 + 2]);
|
|
218
|
+
i < Z[n] && (Z[n] = i);
|
|
219
|
+
}
|
|
220
|
+
for (let t = 0; t < g.length; t++) Z[t] < Infinity && H(e, t, Math.sqrt(Z[t]));
|
|
221
|
+
}
|
|
222
|
+
let n = 0, i = Infinity;
|
|
223
|
+
Y.fill(0);
|
|
224
|
+
for (let e = 0; e < R && B[t + e] !== -1; e++) {
|
|
225
|
+
let n = Math.max(z[t + e], j * .5) / j;
|
|
226
|
+
i = Math.min(i, Math.log((1 - x) * n + x * n * n));
|
|
227
|
+
}
|
|
228
|
+
for (let e = 0; e < R; e++) {
|
|
229
|
+
let r = B[t + e];
|
|
230
|
+
if (r === -1) break;
|
|
231
|
+
let a = Math.max(z[t + e], j * .5) / j, o = Math.exp(-b * (Math.log((1 - x) * a + x * a * a) - i));
|
|
232
|
+
X[r] = o, n += o;
|
|
233
|
+
}
|
|
234
|
+
for (let e = 0; e < R; e++) {
|
|
235
|
+
let r = B[t + e];
|
|
236
|
+
if (r === -1) break;
|
|
237
|
+
Y[r] = X[r] / n;
|
|
238
|
+
}
|
|
239
|
+
for (let t = K[e]; t !== -1; t = q[t]) J.values.set(Y, t * g.length);
|
|
240
|
+
}
|
|
241
|
+
let $ = 0;
|
|
242
|
+
for (let e = 0; e < N.length; e++) N[e] !== 0 && $++;
|
|
243
|
+
return {
|
|
244
|
+
weights: J,
|
|
245
|
+
grid: [
|
|
246
|
+
O,
|
|
247
|
+
k,
|
|
248
|
+
A
|
|
249
|
+
],
|
|
250
|
+
voxels: $,
|
|
251
|
+
unreached: Q
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
//#endregion
|
|
255
|
+
export { o as a, c as i, u as n, s as o, d as r, l as s, g as t };
|