@automovie/human 0.1.0 → 0.2.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/README.md +18 -3
- package/lib/generation/AutoMovieHumanDigitJoints.d.ts +8 -26
- package/lib/generation/AutoMovieHumanDigitJoints.js +9 -37
- package/lib/generation/AutoMovieHumanDigitJoints.js.map +1 -1
- package/lib/generation/conic/AutoMovieHumanConicLoft.d.ts +154 -0
- package/lib/generation/conic/AutoMovieHumanConicLoft.js +430 -0
- package/lib/generation/conic/AutoMovieHumanConicLoft.js.map +1 -0
- package/lib/generation/conic/AutoMovieHumanConicPose.d.ts +92 -0
- package/lib/generation/conic/AutoMovieHumanConicPose.js +202 -0
- package/lib/generation/conic/AutoMovieHumanConicPose.js.map +1 -0
- package/lib/generation/conic/AutoMovieHumanConicRelief.d.ts +52 -0
- package/lib/generation/conic/AutoMovieHumanConicRelief.js +88 -0
- package/lib/generation/conic/AutoMovieHumanConicRelief.js.map +1 -0
- package/lib/generation/conic/AutoMovieHumanConicSection.d.ts +252 -0
- package/lib/generation/conic/AutoMovieHumanConicSection.js +567 -0
- package/lib/generation/conic/AutoMovieHumanConicSection.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1.d.ts +265 -0
- package/lib/generation/f1/AutoMovieHumanF1.js +1254 -0
- package/lib/generation/f1/AutoMovieHumanF1.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Antihelix.d.ts +23 -0
- package/lib/generation/f1/AutoMovieHumanF1Antihelix.js +65 -0
- package/lib/generation/f1/AutoMovieHumanF1Antihelix.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Arm.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Arm.js +82 -0
- package/lib/generation/f1/AutoMovieHumanF1Arm.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Axilla.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Axilla.js +91 -0
- package/lib/generation/f1/AutoMovieHumanF1Axilla.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Breast.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Breast.js +75 -0
- package/lib/generation/f1/AutoMovieHumanF1Breast.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Concha.d.ts +40 -0
- package/lib/generation/f1/AutoMovieHumanF1Concha.js +81 -0
- package/lib/generation/f1/AutoMovieHumanF1Concha.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerIndex.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerIndex.js +59 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerIndex.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerMiddle.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerMiddle.js +59 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerMiddle.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerPinky.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerPinky.js +75 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerPinky.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerRing.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerRing.js +75 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerRing.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerThumb.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerThumb.js +59 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerThumb.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Frames.d.ts +97 -0
- package/lib/generation/f1/AutoMovieHumanF1Frames.js +160 -0
- package/lib/generation/f1/AutoMovieHumanF1Frames.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Hand.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Hand.js +81 -0
- package/lib/generation/f1/AutoMovieHumanF1Hand.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Helix.d.ts +20 -0
- package/lib/generation/f1/AutoMovieHumanF1Helix.js +64 -0
- package/lib/generation/f1/AutoMovieHumanF1Helix.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Joints.d.ts +231 -0
- package/lib/generation/f1/AutoMovieHumanF1Joints.js +249 -0
- package/lib/generation/f1/AutoMovieHumanF1Joints.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Landmarks.d.ts +86 -0
- package/lib/generation/f1/AutoMovieHumanF1Landmarks.js +89 -0
- package/lib/generation/f1/AutoMovieHumanF1Landmarks.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Leg.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Leg.js +82 -0
- package/lib/generation/f1/AutoMovieHumanF1Leg.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Nose.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Nose.js +82 -0
- package/lib/generation/f1/AutoMovieHumanF1Nose.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Nostril.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Nostril.js +59 -0
- package/lib/generation/f1/AutoMovieHumanF1Nostril.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Placement.d.ts +75 -0
- package/lib/generation/f1/AutoMovieHumanF1Placement.js +151 -0
- package/lib/generation/f1/AutoMovieHumanF1Placement.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Placing.d.ts +45 -0
- package/lib/generation/f1/AutoMovieHumanF1Placing.js +301 -0
- package/lib/generation/f1/AutoMovieHumanF1Placing.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Plate.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Plate.js +59 -0
- package/lib/generation/f1/AutoMovieHumanF1Plate.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeBig.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeBig.js +59 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeBig.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeIndex.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeIndex.js +59 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeIndex.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeLittle.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeLittle.js +75 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeLittle.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeMiddle.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeMiddle.js +75 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeMiddle.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeRing.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeRing.js +75 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeRing.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Trunk.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Trunk.js +79 -0
- package/lib/generation/f1/AutoMovieHumanF1Trunk.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Vault.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Vault.js +75 -0
- package/lib/generation/f1/AutoMovieHumanF1Vault.js.map +1 -0
- package/lib/generation/frame/AutoMovieHumanSegmentFrame.d.ts +149 -0
- package/lib/generation/frame/AutoMovieHumanSegmentFrame.js +290 -0
- package/lib/generation/frame/AutoMovieHumanSegmentFrame.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -1
- package/lib/skeleton/AutoMovieHumanCanonicalBody.d.ts +7 -3
- package/lib/skeleton/AutoMovieHumanCanonicalBody.js +31 -3
- package/lib/skeleton/AutoMovieHumanCanonicalBody.js.map +1 -1
- package/lib/skeleton/AutoMovieHumanCanonicalProfile.d.ts +22 -31
- package/lib/skeleton/AutoMovieHumanCanonicalProfile.js +112 -172
- package/lib/skeleton/AutoMovieHumanCanonicalProfile.js.map +1 -1
- package/lib/skeleton/AutoMovieHumanCanonicalSolids.d.ts +65 -0
- package/lib/skeleton/AutoMovieHumanCanonicalSolids.js +105 -0
- package/lib/skeleton/AutoMovieHumanCanonicalSolids.js.map +1 -0
- package/lib/skeleton/index.d.ts +1 -0
- package/lib/skeleton/index.js +1 -0
- package/lib/skeleton/index.js.map +1 -1
- package/package.json +21 -13
- package/src/generation/AutoMovieHumanDigitJoints.ts +12 -47
- package/src/generation/conic/AutoMovieHumanConicLoft.ts +566 -0
- package/src/generation/conic/AutoMovieHumanConicPose.ts +213 -0
- package/src/generation/conic/AutoMovieHumanConicRelief.ts +94 -0
- package/src/generation/conic/AutoMovieHumanConicSection.ts +609 -0
- package/src/generation/f1/AutoMovieHumanF1.ts +1448 -0
- package/src/generation/f1/AutoMovieHumanF1Antihelix.ts +64 -0
- package/src/generation/f1/AutoMovieHumanF1Arm.ts +82 -0
- package/src/generation/f1/AutoMovieHumanF1Axilla.ts +90 -0
- package/src/generation/f1/AutoMovieHumanF1Breast.ts +74 -0
- package/src/generation/f1/AutoMovieHumanF1Concha.ts +80 -0
- package/src/generation/f1/AutoMovieHumanF1FingerIndex.ts +58 -0
- package/src/generation/f1/AutoMovieHumanF1FingerMiddle.ts +58 -0
- package/src/generation/f1/AutoMovieHumanF1FingerPinky.ts +74 -0
- package/src/generation/f1/AutoMovieHumanF1FingerRing.ts +74 -0
- package/src/generation/f1/AutoMovieHumanF1FingerThumb.ts +58 -0
- package/src/generation/f1/AutoMovieHumanF1Frames.ts +191 -0
- package/src/generation/f1/AutoMovieHumanF1Hand.ts +81 -0
- package/src/generation/f1/AutoMovieHumanF1Helix.ts +63 -0
- package/src/generation/f1/AutoMovieHumanF1Joints.ts +319 -0
- package/src/generation/f1/AutoMovieHumanF1Landmarks.ts +101 -0
- package/src/generation/f1/AutoMovieHumanF1Leg.ts +82 -0
- package/src/generation/f1/AutoMovieHumanF1Nose.ts +82 -0
- package/src/generation/f1/AutoMovieHumanF1Nostril.ts +58 -0
- package/src/generation/f1/AutoMovieHumanF1Placement.ts +148 -0
- package/src/generation/f1/AutoMovieHumanF1Placing.ts +313 -0
- package/src/generation/f1/AutoMovieHumanF1Plate.ts +59 -0
- package/src/generation/f1/AutoMovieHumanF1ToeBig.ts +58 -0
- package/src/generation/f1/AutoMovieHumanF1ToeIndex.ts +58 -0
- package/src/generation/f1/AutoMovieHumanF1ToeLittle.ts +74 -0
- package/src/generation/f1/AutoMovieHumanF1ToeMiddle.ts +74 -0
- package/src/generation/f1/AutoMovieHumanF1ToeRing.ts +74 -0
- package/src/generation/f1/AutoMovieHumanF1Trunk.ts +79 -0
- package/src/generation/f1/AutoMovieHumanF1Vault.ts +74 -0
- package/src/generation/frame/AutoMovieHumanSegmentFrame.ts +309 -0
- package/src/index.ts +11 -0
- package/src/skeleton/AutoMovieHumanCanonicalBody.ts +53 -3
- package/src/skeleton/AutoMovieHumanCanonicalProfile.ts +153 -358
- package/src/skeleton/AutoMovieHumanCanonicalSolids.ts +175 -0
- package/src/skeleton/index.ts +1 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { AutoMovieViewJointedCourse } from "@automovie/engine";
|
|
2
|
+
|
|
3
|
+
import { AutoMovieHumanConicLoft } from "./AutoMovieHumanConicLoft";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A conic family carried to a pose: what a change of its course's joint angles asks of the family besides moving its centres.
|
|
7
|
+
*
|
|
8
|
+
* A jointed course (`AutoMovieViewAxis.jointed`) rounds each interior centre by a turn of arclength `2 half`, which leaves both
|
|
9
|
+
* neighbouring segments at the set-back `d` from the centre; between two turns the course is the segment's own line, a straight run.
|
|
10
|
+
* The straight runs are bone and the turn is the joint, so a pose must keep each run on its bone:
|
|
11
|
+
*
|
|
12
|
+
* 1. **Set-back.** `d = half g(angle)` with `g` a function of the turn's angle alone (`share`, read from the engine's own preparation).
|
|
13
|
+
* At another angle the same `half` gives another set-back, and every station past the turn slides along its bone. A posed turn
|
|
14
|
+
* therefore takes `half' = half g(angle) / g(angle')`, which keeps `d`, and the turn's arclength changes by `2 (half' - half)`.
|
|
15
|
+
* 2. **Stations.** Every station of the family (`knots`, `tips`, relief windows, roll knots) is carried by a piecewise-linear map from
|
|
16
|
+
* the reference course to the posed one (`map`). A run's skin rides one segment, the bone that ends at the run's far centre, so
|
|
17
|
+
* every station of a run keeps its distance from that centre; the first run keeps its distances from the first centre. A turn's span
|
|
18
|
+
* is mapped linearly onto what lies between its neighbours' runs: its own changed arclength and, where a run's near centre stands on
|
|
19
|
+
* another segment than its bone (a built corner fixed in the parent), whatever length the line between the two centres gained or
|
|
20
|
+
* lost. That length is absorbed at the joint the turn stands for, not along the bone.
|
|
21
|
+
* 3. **Twist.** The chart is carried from `up` through each turn by that turn's own rotation, so a joint's rotation about its bone's
|
|
22
|
+
* axis moves no centre and leaves the chart where it was, while everything on the segments past it turns. The posed family takes a
|
|
23
|
+
* `roll` (`AutoMovieHumanConicLoft.IRoll`) that brings the chart on each run to where that run's segment carries the reference chart;
|
|
24
|
+
* along a run the roll goes linearly from the angle of the run before it, at its proximal joint, to its own at its distal joint, as a
|
|
25
|
+
* twist chain spreads a forearm's pronation along its length, and it holds its value across a turn.
|
|
26
|
+
*
|
|
27
|
+
* At the reference pose all three are exact no-ops: the halves, the stations and the arrays that hold them are the family's own.
|
|
28
|
+
*/
|
|
29
|
+
export namespace AutoMovieHumanConicPose {
|
|
30
|
+
type V3 = AutoMovieHumanConicLoft.V3;
|
|
31
|
+
|
|
32
|
+
/** A jointed course's runs and turns in arclength, as `AutoMovieViewJointedCourse.prepare` dates them. */
|
|
33
|
+
export interface ICourse {
|
|
34
|
+
/** Segment lengths between neighbouring centres, mm. */
|
|
35
|
+
lengths: number[];
|
|
36
|
+
|
|
37
|
+
/** Each interior centre's turn angle, radians. */
|
|
38
|
+
angles: number[];
|
|
39
|
+
|
|
40
|
+
/** Each turn's half arclength, mm. */
|
|
41
|
+
halves: number[];
|
|
42
|
+
|
|
43
|
+
/** Each turn's set-back on both its segments, mm. */
|
|
44
|
+
setbacks: number[];
|
|
45
|
+
|
|
46
|
+
/** The station each turn starts at, mm. */
|
|
47
|
+
starts: number[];
|
|
48
|
+
|
|
49
|
+
/** The course's arclength from its first centre to its last, mm. */
|
|
50
|
+
total: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Twists under this many radians are none: far above the rounding of an angle between unit vectors (1e-16), far below any joint's motion. */
|
|
54
|
+
const NO_TWIST: number = 1e-12;
|
|
55
|
+
|
|
56
|
+
/** Knots of the roll along one run besides its ends: the natural cubic through five points of a line departs from it only near the run's ends. */
|
|
57
|
+
const ROLL_KNOTS: number = 3;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A turn's set-back as a share of its half arclength, by its angle: the engine's own preparation of a made corner of that angle with a
|
|
61
|
+
* half of 1 mm between two segments of 1 km (the set-back is linear in the half and does not read the lengths). A straight joint has
|
|
62
|
+
* no turn; its share is the limit 1 of a vanishing angle, where the turn lies along both segments.
|
|
63
|
+
*/
|
|
64
|
+
export function share(angle: number): number {
|
|
65
|
+
if (angle === 0) return 1;
|
|
66
|
+
const made: AutoMovieViewJointedCourse.ICourse | string = AutoMovieViewJointedCourse.prepare([[-1e6, 0, 0], [0, 0, 0], [1e6 * Math.cos(angle), 1e6 * Math.sin(angle), 0]], [1]);
|
|
67
|
+
if (typeof made === "string") throw new Error("pose: no turn of " + angle + " rad: " + made);
|
|
68
|
+
return made.turns[0]!.setback;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The turn angle at each interior centre, radians, as the engine reads it: `atan2(|a x b|, a . b)` of the neighbouring unit directions. */
|
|
72
|
+
export function angles(centres: readonly V3[]): number[] {
|
|
73
|
+
const directions: V3[] = centres.slice(1).map((p: V3, i: number): V3 => {
|
|
74
|
+
const d: V3 = [p[0] - centres[i]![0], p[1] - centres[i]![1], p[2] - centres[i]![2]];
|
|
75
|
+
const l: number = Math.hypot(d[0], d[1], d[2]);
|
|
76
|
+
return [d[0] / l, d[1] / l, d[2] / l];
|
|
77
|
+
});
|
|
78
|
+
return directions.slice(1).map((b: V3, i: number): number => {
|
|
79
|
+
const a: V3 = directions[i]!;
|
|
80
|
+
const n: V3 = [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
81
|
+
return Math.atan2(Math.hypot(n[0], n[1], n[2]), a[0] * b[0] + a[1] * b[1] + a[2] * b[2]);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The halves that keep every turn's set-back when a course's centres move: `half' = half g(angle) / g(angle')`. At unchanged angles
|
|
87
|
+
* the given array itself is returned.
|
|
88
|
+
*/
|
|
89
|
+
export function halves(reference: readonly V3[], given: number[], posed: readonly V3[]): number[] {
|
|
90
|
+
const [from, to]: number[][] = [angles(reference), angles(posed)];
|
|
91
|
+
const out: number[] = given.map((half: number, i: number): number => (from![i] === to![i] ? half : (half * share(from![i]!)) / share(to![i]!)));
|
|
92
|
+
return out.every((half: number, i: number): boolean => half === given[i]) ? given : out;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** A course's runs and turns in arclength. A straight joint keeps its half as the stretch its set-backs span, which the engine walks as plain line. */
|
|
96
|
+
export function course(centres: readonly V3[], given: readonly number[]): ICourse {
|
|
97
|
+
const lengths: number[] = centres.slice(1).map((p: V3, i: number): number => Math.hypot(p[0] - centres[i]![0], p[1] - centres[i]![1], p[2] - centres[i]![2]));
|
|
98
|
+
const turned: number[] = angles(centres);
|
|
99
|
+
const setbacks: number[] = turned.map((angle: number, i: number): number => given[i]! * share(angle));
|
|
100
|
+
const starts: number[] = [];
|
|
101
|
+
let s: number = 0;
|
|
102
|
+
for (let i: number = 0; i < turned.length; ++i) {
|
|
103
|
+
s += lengths[i]! - (i >= 1 ? setbacks[i - 1]! : 0) - setbacks[i]!;
|
|
104
|
+
starts.push(s);
|
|
105
|
+
s += 2 * given[i]!;
|
|
106
|
+
}
|
|
107
|
+
return { lengths, angles: turned, halves: [...given], setbacks, starts, total: s + lengths.at(-1)! - (setbacks.at(-1) ?? 0) };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The stations where a course's law changes: its start, each turn's start and end, and its end. */
|
|
111
|
+
function breaks(c: ICourse): number[] {
|
|
112
|
+
return [0, ...c.starts.flatMap((start: number, i: number): number[] => [start, start + 2 * c.halves[i]!]), c.total];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The map of stations from a reference course to its posed course, of slope 1 on every run and before the first centre and past the
|
|
117
|
+
* last, and linear across each turn's span. A run after a turn ends where the posed course's run ends, at its far centre's set-back,
|
|
118
|
+
* and keeps its reference length back from there; the first run starts at the first centre. Each turn's span lies between its
|
|
119
|
+
* neighbours' runs, so it takes the turn's own change of arclength and any change of the following segment's length. Null when the
|
|
120
|
+
* two courses' breakpoints are the same numbers, where the map is the identity; a span left without length is refused.
|
|
121
|
+
*/
|
|
122
|
+
export function map(reference: ICourse, posed: ICourse): ((station: number) => number) | null {
|
|
123
|
+
const x: number[] = breaks(reference);
|
|
124
|
+
const to: number[] = breaks(posed);
|
|
125
|
+
// The posed breakpoints: each turn's start as the engine dates it, and each turn's span ending where the next run, of its reference
|
|
126
|
+
// length, starts.
|
|
127
|
+
const y: number[] = to.map((station: number, i: number): number => (i >= 2 && i % 2 === 0 && i + 1 < to.length ? to[i + 1]! - (x[i + 1]! - x[i]!) : station));
|
|
128
|
+
if (y.some((station: number, i: number): boolean => i >= 1 && !(station > y[i - 1]!) && x[i]! > x[i - 1]!)) throw new Error("pose: a turn's span is left without length");
|
|
129
|
+
if (x.every((s: number, i: number): boolean => s === y[i])) return null;
|
|
130
|
+
return (station: number): number => {
|
|
131
|
+
if (station <= x[0]!) return y[0]! + (station - x[0]!);
|
|
132
|
+
for (let i: number = 1; i < x.length; ++i) if (station <= x[i]!) return x[i] === x[i - 1] ? y[i]! : y[i - 1]! + ((y[i]! - y[i - 1]!) * (station - x[i - 1]!)) / (x[i]! - x[i - 1]!);
|
|
133
|
+
return y.at(-1)! + (station - x.at(-1)!);
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The roll that brings a posed family's chart on each run to where the run's segment carries the reference chart.
|
|
139
|
+
*
|
|
140
|
+
* On run `k` the angle is read at the run's middle: from the posed course's own chart `u`, carried from `up` by the turns alone, toward
|
|
141
|
+
* `v`, to the reference course's own `u` there, carried likewise, as `carried` maps it into the pose. Each angle is taken on the branch nearest the run
|
|
142
|
+
* before it. The roll's knots stand at each run's ends and `ROLL_KNOTS` points between, on the line from the angle of the run before
|
|
143
|
+
* (the first run: its own) to the run's own, so it holds across every turn. Absent when no run's angle reaches `NO_TWIST`.
|
|
144
|
+
*
|
|
145
|
+
* @param reference The family as stored, in the reference pose.
|
|
146
|
+
* @param posed Its centres, halves and `up` at the pose, without a roll.
|
|
147
|
+
* @param carried A direction of the reference pose on run `k`, as that run's segment carries it to the pose.
|
|
148
|
+
*/
|
|
149
|
+
export function twist(reference: AutoMovieHumanConicLoft.IFamily, posed: Pick<AutoMovieHumanConicLoft.IFamily, "centres" | "halves" | "up">, carried: (run: number, direction: V3) => V3): AutoMovieHumanConicLoft.IRoll | undefined {
|
|
150
|
+
// A posed course the engine does not admit has no chart to read; the family is refused with the engine's own rule when it is lofted.
|
|
151
|
+
if (typeof AutoMovieViewJointedCourse.prepare(posed.centres, posed.halves) === "string") return undefined;
|
|
152
|
+
const [from, to]: ICourse[] = [course(reference.centres, reference.halves), course(posed.centres, posed.halves)];
|
|
153
|
+
const ends = (c: ICourse): [number, number][] => c.lengths.map((_: number, k: number): [number, number] => [k === 0 ? 0 : c.starts[k - 1]! + 2 * c.halves[k - 1]!, k < c.starts.length ? c.starts[k]! : c.total]);
|
|
154
|
+
const [runs, placed]: [number, number][][] = [ends(from!), ends(to!)];
|
|
155
|
+
// Both charts are read as the turns alone carry them: a family's own roll rides on top of either and is no twist of a joint.
|
|
156
|
+
const [stored, moved] = [AutoMovieHumanConicLoft.axis({ centres: reference.centres, halves: reference.halves, up: reference.up }), AutoMovieHumanConicLoft.axis({ centres: posed.centres, halves: posed.halves, up: posed.up })];
|
|
157
|
+
const turned: number[] = [];
|
|
158
|
+
for (let k: number = 0; k < runs!.length; ++k) {
|
|
159
|
+
const target: V3 = carried(k, stored.at((runs![k]![0] + runs![k]![1]) / 2).u);
|
|
160
|
+
const frame = moved.at((placed![k]![0] + placed![k]![1]) / 2);
|
|
161
|
+
const angle: number = Math.atan2(target[0] * frame.v[0] + target[1] * frame.v[1] + target[2] * frame.v[2], target[0] * frame.u[0] + target[1] * frame.u[1] + target[2] * frame.u[2]);
|
|
162
|
+
const before: number = turned.at(-1) ?? 0;
|
|
163
|
+
turned.push(angle + 2 * Math.PI * Math.round((before - angle) / (2 * Math.PI)));
|
|
164
|
+
}
|
|
165
|
+
if (turned.every((angle: number): boolean => Math.abs(angle) < NO_TWIST)) return undefined;
|
|
166
|
+
const knots: number[] = [];
|
|
167
|
+
const values: number[] = [];
|
|
168
|
+
placed!.forEach(([start, end]: [number, number], k: number): void => {
|
|
169
|
+
const [a, b]: number[] = [turned[Math.max(0, k - 1)]!, turned[k]!];
|
|
170
|
+
for (let i: number = 0; i <= ROLL_KNOTS + 1; ++i) {
|
|
171
|
+
const t: number = i / (ROLL_KNOTS + 1);
|
|
172
|
+
const station: number = start + (end - start) * t;
|
|
173
|
+
if (knots.length > 0 && !(station > knots.at(-1)!)) continue;
|
|
174
|
+
knots.push(station);
|
|
175
|
+
values.push(a! + (b! - a!) * t);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
return { knots, values };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* A family carried to a pose: its centres and `up` as given, its halves keeping every set-back, its stations mapped, and the roll its
|
|
183
|
+
* joints' twists ask for. Its section values, layout and relief nets are the family's own arrays; where no station moves, so are its
|
|
184
|
+
* `knots`, `tips` and reliefs. `station` maps a station of the reference family to the posed one.
|
|
185
|
+
*
|
|
186
|
+
* A family that already rolls its chart (`roll`) keeps that roll on mapped knots; such a family whose joints also twist is refused,
|
|
187
|
+
* since one roll would have to carry both.
|
|
188
|
+
*/
|
|
189
|
+
export function repose(family: AutoMovieHumanConicLoft.IFamily, centres: V3[], up: V3, carried: (run: number, direction: V3) => V3): { family: AutoMovieHumanConicLoft.IFamily; station: ((station: number) => number) | null } {
|
|
190
|
+
const posed: number[] = halves(family.centres, family.halves, centres);
|
|
191
|
+
const station: ((station: number) => number) | null = centres.length < 3 ? null : map(course(family.centres, family.halves), course(centres, posed));
|
|
192
|
+
const twisted: AutoMovieHumanConicLoft.IRoll | undefined = centres.length < 3 ? undefined : twist(family, { centres, halves: posed, up }, carried);
|
|
193
|
+
if (twisted !== undefined && family.roll !== undefined) throw new Error("pose: " + family.name + " rolls its chart and its joints twist");
|
|
194
|
+
const tip = (end: AutoMovieHumanConicLoft.ITip | null): AutoMovieHumanConicLoft.ITip | null => (end === null || station === null ? end : { ...end, from: station(end.from), tip: station(end.tip) });
|
|
195
|
+
return {
|
|
196
|
+
station,
|
|
197
|
+
family: {
|
|
198
|
+
...family,
|
|
199
|
+
centres,
|
|
200
|
+
halves: posed,
|
|
201
|
+
up,
|
|
202
|
+
...(twisted !== undefined ? { roll: twisted } : family.roll === undefined || station === null ? {} : { roll: { knots: family.roll.knots.map(station), values: family.roll.values } }),
|
|
203
|
+
...(station === null
|
|
204
|
+
? {}
|
|
205
|
+
: {
|
|
206
|
+
knots: family.knots.map(station),
|
|
207
|
+
...(family.tips === undefined ? {} : { tips: [tip(family.tips[0]), tip(family.tips[1])] as [AutoMovieHumanConicLoft.ITip | null, AutoMovieHumanConicLoft.ITip | null] }),
|
|
208
|
+
...(family.reliefs === undefined ? {} : { reliefs: family.reliefs.map((relief: NonNullable<AutoMovieHumanConicLoft.IFamily["reliefs"]>[number]): NonNullable<AutoMovieHumanConicLoft.IFamily["reliefs"]>[number] => ({ ...relief, stations: [station(relief.stations[0]), station(relief.stations[1])] })) }),
|
|
209
|
+
}),
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { IAutoMovieLoftRelief } from "@automovie/engine";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The compact forms a family's relief nets are stored in, and their expansion to the nets the engine reads.
|
|
5
|
+
*
|
|
6
|
+
* A net repeats numbers in two ways the body's symmetry gives. A net of a median part whose window stands about the median plane is its
|
|
7
|
+
* own mirror image: its column `b` equals its column `columns - 1 - b`, the map the engine's uniform cubic gives a window reflected
|
|
8
|
+
* about its middle (`AutoMovieLoftRelief.height`: control `i` of `n` stands at parameter `i - 1` of `[0, n - 3]`, and the reflection
|
|
9
|
+
* `x -> n - 3 - x` sends it to `n - 1 - i`). And a net fitted on one side of such a part has a twin on the other, the same heights with
|
|
10
|
+
* their columns in the other order. A module stores the half and names the twin; `list` returns the full nets.
|
|
11
|
+
*
|
|
12
|
+
* Every expansion copies stored doubles and computes nothing, so a figure built from the expanded nets is built from the same numbers
|
|
13
|
+
* as one whose module wrote them all out.
|
|
14
|
+
*/
|
|
15
|
+
export namespace AutoMovieHumanConicRelief {
|
|
16
|
+
/** A net stored as the reflection of an earlier one of its family's list. */
|
|
17
|
+
export interface ITwin {
|
|
18
|
+
/** The twin's own name. */
|
|
19
|
+
name: string;
|
|
20
|
+
|
|
21
|
+
/** The name of the net it reflects, which stands before it in the list. */
|
|
22
|
+
twin: string;
|
|
23
|
+
|
|
24
|
+
/** The twin's own phase window, radians. */
|
|
25
|
+
phases: [number, number];
|
|
26
|
+
|
|
27
|
+
/** The twin's own unit direction of height. */
|
|
28
|
+
axis: [number, number, number];
|
|
29
|
+
|
|
30
|
+
/** The twin's own turning direction; present exactly when the original has one. */
|
|
31
|
+
turn?: [number, number, number];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** How many heights each expanded net's module stores, by the expanded `heights` array itself. */
|
|
35
|
+
const STORED: WeakMap<readonly number[], number> = new WeakMap();
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The full heights of a net that is its own mirror image, from its stored half.
|
|
39
|
+
*
|
|
40
|
+
* @param rows The net's rows.
|
|
41
|
+
* @param columns The net's columns, odd: the middle column is its own image and is stored once.
|
|
42
|
+
* @param half Columns 0 to `(columns - 1) / 2` of every row, row by row.
|
|
43
|
+
* @returns `rows * columns` heights, row by row: each row's stored columns, then the columns before the middle in reverse.
|
|
44
|
+
*/
|
|
45
|
+
export function mirrored(rows: number, columns: number, half: readonly number[]): number[] {
|
|
46
|
+
if (!Number.isInteger(rows) || !Number.isInteger(columns) || columns % 2 !== 1) throw new Error("mirrored: a net of " + rows + " by " + columns + " has no middle column to reflect about");
|
|
47
|
+
const kept: number = (columns + 1) / 2;
|
|
48
|
+
if (half.length !== rows * kept) throw new Error("mirrored: " + half.length + " heights given for " + rows + " rows of " + kept + " stored columns");
|
|
49
|
+
const out: number[] = new Array<number>(rows * columns);
|
|
50
|
+
for (let a: number = 0; a < rows; ++a) for (let b: number = 0; b < columns; ++b) out[a * columns + b] = half[a * kept + Math.min(b, columns - 1 - b)]!;
|
|
51
|
+
STORED.set(out, half.length);
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A net's twin across the median plane: the original's stations, rows, columns and heights with every row's columns in the other
|
|
57
|
+
* order, under the twin's own name, window and directions.
|
|
58
|
+
*
|
|
59
|
+
* @param original The net fitted on one side.
|
|
60
|
+
* @param own The twin's name, phase window and directions.
|
|
61
|
+
*/
|
|
62
|
+
export function twin(original: IAutoMovieLoftRelief, own: Omit<ITwin, "twin">): IAutoMovieLoftRelief {
|
|
63
|
+
if ((original.turn === undefined) !== (own.turn === undefined)) throw new Error("twin: " + own.name + " and " + original.name + " do not both turn their cast");
|
|
64
|
+
if (original.shift !== undefined) throw new Error("twin: " + original.name + " carries a station map, which no twin reflects");
|
|
65
|
+
const { rows, columns }: IAutoMovieLoftRelief = original;
|
|
66
|
+
const heights: number[] = new Array<number>(rows * columns);
|
|
67
|
+
for (let a: number = 0; a < rows; ++a) for (let b: number = 0; b < columns; ++b) heights[a * columns + b] = original.heights[a * columns + (columns - 1 - b)]!;
|
|
68
|
+
STORED.set(heights, 0);
|
|
69
|
+
return { name: own.name, stations: original.stations, phases: own.phases, axis: own.axis, ...(own.turn === undefined ? {} : { turn: own.turn }), rows, columns, heights };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* A family's nets from their stored list, in its order: a net written whole or through `mirrored` stands as it is, and a twin is the
|
|
74
|
+
* reflection of the net it names, which must stand before it.
|
|
75
|
+
*/
|
|
76
|
+
export function list(entries: readonly (IAutoMovieLoftRelief | ITwin)[]): IAutoMovieLoftRelief[] {
|
|
77
|
+
const out: IAutoMovieLoftRelief[] = [];
|
|
78
|
+
for (const entry of entries) {
|
|
79
|
+
if (!("twin" in entry)) {
|
|
80
|
+
out.push(entry);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const original: IAutoMovieLoftRelief | undefined = out.find((relief: IAutoMovieLoftRelief): boolean => relief.name === entry.twin);
|
|
84
|
+
if (original === undefined) throw new Error("list: " + entry.name + " reflects " + entry.twin + ", which does not stand before it");
|
|
85
|
+
out.push(twin(original, { name: entry.name, phases: entry.phases, axis: entry.axis, ...(entry.turn === undefined ? {} : { turn: entry.turn }) }));
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** How many heights a net's module stores: its half's for a mirrored net, none for a twin, and all of them for a net written whole. */
|
|
91
|
+
export function stored(relief: IAutoMovieLoftRelief): number {
|
|
92
|
+
return STORED.get(relief.heights) ?? relief.heights.length;
|
|
93
|
+
}
|
|
94
|
+
}
|