@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.
Files changed (162) hide show
  1. package/README.md +18 -3
  2. package/lib/generation/AutoMovieHumanDigitJoints.d.ts +8 -26
  3. package/lib/generation/AutoMovieHumanDigitJoints.js +9 -37
  4. package/lib/generation/AutoMovieHumanDigitJoints.js.map +1 -1
  5. package/lib/generation/conic/AutoMovieHumanConicLoft.d.ts +154 -0
  6. package/lib/generation/conic/AutoMovieHumanConicLoft.js +430 -0
  7. package/lib/generation/conic/AutoMovieHumanConicLoft.js.map +1 -0
  8. package/lib/generation/conic/AutoMovieHumanConicPose.d.ts +92 -0
  9. package/lib/generation/conic/AutoMovieHumanConicPose.js +202 -0
  10. package/lib/generation/conic/AutoMovieHumanConicPose.js.map +1 -0
  11. package/lib/generation/conic/AutoMovieHumanConicRelief.d.ts +52 -0
  12. package/lib/generation/conic/AutoMovieHumanConicRelief.js +88 -0
  13. package/lib/generation/conic/AutoMovieHumanConicRelief.js.map +1 -0
  14. package/lib/generation/conic/AutoMovieHumanConicSection.d.ts +252 -0
  15. package/lib/generation/conic/AutoMovieHumanConicSection.js +567 -0
  16. package/lib/generation/conic/AutoMovieHumanConicSection.js.map +1 -0
  17. package/lib/generation/f1/AutoMovieHumanF1.d.ts +265 -0
  18. package/lib/generation/f1/AutoMovieHumanF1.js +1254 -0
  19. package/lib/generation/f1/AutoMovieHumanF1.js.map +1 -0
  20. package/lib/generation/f1/AutoMovieHumanF1Antihelix.d.ts +23 -0
  21. package/lib/generation/f1/AutoMovieHumanF1Antihelix.js +65 -0
  22. package/lib/generation/f1/AutoMovieHumanF1Antihelix.js.map +1 -0
  23. package/lib/generation/f1/AutoMovieHumanF1Arm.d.ts +18 -0
  24. package/lib/generation/f1/AutoMovieHumanF1Arm.js +82 -0
  25. package/lib/generation/f1/AutoMovieHumanF1Arm.js.map +1 -0
  26. package/lib/generation/f1/AutoMovieHumanF1Axilla.d.ts +18 -0
  27. package/lib/generation/f1/AutoMovieHumanF1Axilla.js +91 -0
  28. package/lib/generation/f1/AutoMovieHumanF1Axilla.js.map +1 -0
  29. package/lib/generation/f1/AutoMovieHumanF1Breast.d.ts +18 -0
  30. package/lib/generation/f1/AutoMovieHumanF1Breast.js +75 -0
  31. package/lib/generation/f1/AutoMovieHumanF1Breast.js.map +1 -0
  32. package/lib/generation/f1/AutoMovieHumanF1Concha.d.ts +40 -0
  33. package/lib/generation/f1/AutoMovieHumanF1Concha.js +81 -0
  34. package/lib/generation/f1/AutoMovieHumanF1Concha.js.map +1 -0
  35. package/lib/generation/f1/AutoMovieHumanF1FingerIndex.d.ts +18 -0
  36. package/lib/generation/f1/AutoMovieHumanF1FingerIndex.js +59 -0
  37. package/lib/generation/f1/AutoMovieHumanF1FingerIndex.js.map +1 -0
  38. package/lib/generation/f1/AutoMovieHumanF1FingerMiddle.d.ts +18 -0
  39. package/lib/generation/f1/AutoMovieHumanF1FingerMiddle.js +59 -0
  40. package/lib/generation/f1/AutoMovieHumanF1FingerMiddle.js.map +1 -0
  41. package/lib/generation/f1/AutoMovieHumanF1FingerPinky.d.ts +18 -0
  42. package/lib/generation/f1/AutoMovieHumanF1FingerPinky.js +75 -0
  43. package/lib/generation/f1/AutoMovieHumanF1FingerPinky.js.map +1 -0
  44. package/lib/generation/f1/AutoMovieHumanF1FingerRing.d.ts +18 -0
  45. package/lib/generation/f1/AutoMovieHumanF1FingerRing.js +75 -0
  46. package/lib/generation/f1/AutoMovieHumanF1FingerRing.js.map +1 -0
  47. package/lib/generation/f1/AutoMovieHumanF1FingerThumb.d.ts +18 -0
  48. package/lib/generation/f1/AutoMovieHumanF1FingerThumb.js +59 -0
  49. package/lib/generation/f1/AutoMovieHumanF1FingerThumb.js.map +1 -0
  50. package/lib/generation/f1/AutoMovieHumanF1Frames.d.ts +97 -0
  51. package/lib/generation/f1/AutoMovieHumanF1Frames.js +160 -0
  52. package/lib/generation/f1/AutoMovieHumanF1Frames.js.map +1 -0
  53. package/lib/generation/f1/AutoMovieHumanF1Hand.d.ts +18 -0
  54. package/lib/generation/f1/AutoMovieHumanF1Hand.js +81 -0
  55. package/lib/generation/f1/AutoMovieHumanF1Hand.js.map +1 -0
  56. package/lib/generation/f1/AutoMovieHumanF1Helix.d.ts +20 -0
  57. package/lib/generation/f1/AutoMovieHumanF1Helix.js +64 -0
  58. package/lib/generation/f1/AutoMovieHumanF1Helix.js.map +1 -0
  59. package/lib/generation/f1/AutoMovieHumanF1Joints.d.ts +231 -0
  60. package/lib/generation/f1/AutoMovieHumanF1Joints.js +249 -0
  61. package/lib/generation/f1/AutoMovieHumanF1Joints.js.map +1 -0
  62. package/lib/generation/f1/AutoMovieHumanF1Landmarks.d.ts +86 -0
  63. package/lib/generation/f1/AutoMovieHumanF1Landmarks.js +89 -0
  64. package/lib/generation/f1/AutoMovieHumanF1Landmarks.js.map +1 -0
  65. package/lib/generation/f1/AutoMovieHumanF1Leg.d.ts +18 -0
  66. package/lib/generation/f1/AutoMovieHumanF1Leg.js +82 -0
  67. package/lib/generation/f1/AutoMovieHumanF1Leg.js.map +1 -0
  68. package/lib/generation/f1/AutoMovieHumanF1Nose.d.ts +18 -0
  69. package/lib/generation/f1/AutoMovieHumanF1Nose.js +82 -0
  70. package/lib/generation/f1/AutoMovieHumanF1Nose.js.map +1 -0
  71. package/lib/generation/f1/AutoMovieHumanF1Nostril.d.ts +18 -0
  72. package/lib/generation/f1/AutoMovieHumanF1Nostril.js +59 -0
  73. package/lib/generation/f1/AutoMovieHumanF1Nostril.js.map +1 -0
  74. package/lib/generation/f1/AutoMovieHumanF1Placement.d.ts +75 -0
  75. package/lib/generation/f1/AutoMovieHumanF1Placement.js +151 -0
  76. package/lib/generation/f1/AutoMovieHumanF1Placement.js.map +1 -0
  77. package/lib/generation/f1/AutoMovieHumanF1Placing.d.ts +45 -0
  78. package/lib/generation/f1/AutoMovieHumanF1Placing.js +301 -0
  79. package/lib/generation/f1/AutoMovieHumanF1Placing.js.map +1 -0
  80. package/lib/generation/f1/AutoMovieHumanF1Plate.d.ts +18 -0
  81. package/lib/generation/f1/AutoMovieHumanF1Plate.js +59 -0
  82. package/lib/generation/f1/AutoMovieHumanF1Plate.js.map +1 -0
  83. package/lib/generation/f1/AutoMovieHumanF1ToeBig.d.ts +18 -0
  84. package/lib/generation/f1/AutoMovieHumanF1ToeBig.js +59 -0
  85. package/lib/generation/f1/AutoMovieHumanF1ToeBig.js.map +1 -0
  86. package/lib/generation/f1/AutoMovieHumanF1ToeIndex.d.ts +18 -0
  87. package/lib/generation/f1/AutoMovieHumanF1ToeIndex.js +59 -0
  88. package/lib/generation/f1/AutoMovieHumanF1ToeIndex.js.map +1 -0
  89. package/lib/generation/f1/AutoMovieHumanF1ToeLittle.d.ts +18 -0
  90. package/lib/generation/f1/AutoMovieHumanF1ToeLittle.js +75 -0
  91. package/lib/generation/f1/AutoMovieHumanF1ToeLittle.js.map +1 -0
  92. package/lib/generation/f1/AutoMovieHumanF1ToeMiddle.d.ts +18 -0
  93. package/lib/generation/f1/AutoMovieHumanF1ToeMiddle.js +75 -0
  94. package/lib/generation/f1/AutoMovieHumanF1ToeMiddle.js.map +1 -0
  95. package/lib/generation/f1/AutoMovieHumanF1ToeRing.d.ts +18 -0
  96. package/lib/generation/f1/AutoMovieHumanF1ToeRing.js +75 -0
  97. package/lib/generation/f1/AutoMovieHumanF1ToeRing.js.map +1 -0
  98. package/lib/generation/f1/AutoMovieHumanF1Trunk.d.ts +18 -0
  99. package/lib/generation/f1/AutoMovieHumanF1Trunk.js +79 -0
  100. package/lib/generation/f1/AutoMovieHumanF1Trunk.js.map +1 -0
  101. package/lib/generation/f1/AutoMovieHumanF1Vault.d.ts +18 -0
  102. package/lib/generation/f1/AutoMovieHumanF1Vault.js +75 -0
  103. package/lib/generation/f1/AutoMovieHumanF1Vault.js.map +1 -0
  104. package/lib/generation/frame/AutoMovieHumanSegmentFrame.d.ts +149 -0
  105. package/lib/generation/frame/AutoMovieHumanSegmentFrame.js +290 -0
  106. package/lib/generation/frame/AutoMovieHumanSegmentFrame.js.map +1 -0
  107. package/lib/index.d.ts +11 -0
  108. package/lib/index.js +11 -0
  109. package/lib/index.js.map +1 -1
  110. package/lib/skeleton/AutoMovieHumanCanonicalBody.d.ts +7 -3
  111. package/lib/skeleton/AutoMovieHumanCanonicalBody.js +31 -3
  112. package/lib/skeleton/AutoMovieHumanCanonicalBody.js.map +1 -1
  113. package/lib/skeleton/AutoMovieHumanCanonicalProfile.d.ts +22 -31
  114. package/lib/skeleton/AutoMovieHumanCanonicalProfile.js +112 -172
  115. package/lib/skeleton/AutoMovieHumanCanonicalProfile.js.map +1 -1
  116. package/lib/skeleton/AutoMovieHumanCanonicalSolids.d.ts +65 -0
  117. package/lib/skeleton/AutoMovieHumanCanonicalSolids.js +105 -0
  118. package/lib/skeleton/AutoMovieHumanCanonicalSolids.js.map +1 -0
  119. package/lib/skeleton/index.d.ts +1 -0
  120. package/lib/skeleton/index.js +1 -0
  121. package/lib/skeleton/index.js.map +1 -1
  122. package/package.json +21 -13
  123. package/src/generation/AutoMovieHumanDigitJoints.ts +12 -47
  124. package/src/generation/conic/AutoMovieHumanConicLoft.ts +566 -0
  125. package/src/generation/conic/AutoMovieHumanConicPose.ts +213 -0
  126. package/src/generation/conic/AutoMovieHumanConicRelief.ts +94 -0
  127. package/src/generation/conic/AutoMovieHumanConicSection.ts +609 -0
  128. package/src/generation/f1/AutoMovieHumanF1.ts +1448 -0
  129. package/src/generation/f1/AutoMovieHumanF1Antihelix.ts +64 -0
  130. package/src/generation/f1/AutoMovieHumanF1Arm.ts +82 -0
  131. package/src/generation/f1/AutoMovieHumanF1Axilla.ts +90 -0
  132. package/src/generation/f1/AutoMovieHumanF1Breast.ts +74 -0
  133. package/src/generation/f1/AutoMovieHumanF1Concha.ts +80 -0
  134. package/src/generation/f1/AutoMovieHumanF1FingerIndex.ts +58 -0
  135. package/src/generation/f1/AutoMovieHumanF1FingerMiddle.ts +58 -0
  136. package/src/generation/f1/AutoMovieHumanF1FingerPinky.ts +74 -0
  137. package/src/generation/f1/AutoMovieHumanF1FingerRing.ts +74 -0
  138. package/src/generation/f1/AutoMovieHumanF1FingerThumb.ts +58 -0
  139. package/src/generation/f1/AutoMovieHumanF1Frames.ts +191 -0
  140. package/src/generation/f1/AutoMovieHumanF1Hand.ts +81 -0
  141. package/src/generation/f1/AutoMovieHumanF1Helix.ts +63 -0
  142. package/src/generation/f1/AutoMovieHumanF1Joints.ts +319 -0
  143. package/src/generation/f1/AutoMovieHumanF1Landmarks.ts +101 -0
  144. package/src/generation/f1/AutoMovieHumanF1Leg.ts +82 -0
  145. package/src/generation/f1/AutoMovieHumanF1Nose.ts +82 -0
  146. package/src/generation/f1/AutoMovieHumanF1Nostril.ts +58 -0
  147. package/src/generation/f1/AutoMovieHumanF1Placement.ts +148 -0
  148. package/src/generation/f1/AutoMovieHumanF1Placing.ts +313 -0
  149. package/src/generation/f1/AutoMovieHumanF1Plate.ts +59 -0
  150. package/src/generation/f1/AutoMovieHumanF1ToeBig.ts +58 -0
  151. package/src/generation/f1/AutoMovieHumanF1ToeIndex.ts +58 -0
  152. package/src/generation/f1/AutoMovieHumanF1ToeLittle.ts +74 -0
  153. package/src/generation/f1/AutoMovieHumanF1ToeMiddle.ts +74 -0
  154. package/src/generation/f1/AutoMovieHumanF1ToeRing.ts +74 -0
  155. package/src/generation/f1/AutoMovieHumanF1Trunk.ts +79 -0
  156. package/src/generation/f1/AutoMovieHumanF1Vault.ts +74 -0
  157. package/src/generation/frame/AutoMovieHumanSegmentFrame.ts +309 -0
  158. package/src/index.ts +11 -0
  159. package/src/skeleton/AutoMovieHumanCanonicalBody.ts +53 -3
  160. package/src/skeleton/AutoMovieHumanCanonicalProfile.ts +153 -358
  161. package/src/skeleton/AutoMovieHumanCanonicalSolids.ts +175 -0
  162. package/src/skeleton/index.ts +1 -0
@@ -0,0 +1,309 @@
1
+ /**
2
+ * The segment-frame law: a body segment's frame built from its landmarks by a written definition, and the chain that hangs the segments
3
+ * on their parents by one rotation per joint.
4
+ *
5
+ * A frame is an origin and three unit axes X, Y, Z, all in the figure's frame (millimetres), right-handed: Z = X x Y. The ISB
6
+ * recommendations write every segment so (Wu et al. 2002, J Biomech 35:543-548; Wu et al. 2005, J Biomech 38:981-992): X anterior, Y
7
+ * along the segment toward its proximal end (cranial for the trunk), Z to the right. The figure keeps one side, the stored side (+Z), and
8
+ * its twin is the reflection in z = 0 ({@link mirror}); ISB's right-side definitions read on the stored side.
9
+ *
10
+ * A joint's zero is the child's axes parallel to its parent's, the zero of ISB's joint coordinate systems (the anatomical position).
11
+ * With the axes as the columns of a matrix A, a joint's rotation is `R = A_parent^T A_child`, the child's axes written in its parent's
12
+ * frame, and a pose is one rotation per joint: {@link world} composes `A_child = A_parent R` down the tree, so the reference rotations
13
+ * return the reference frames and identity rotations the neutral body. A segment's origin is the joint centre it pivots about; its place
14
+ * in its parent's frame, `A_parent^T (o_child - o_parent)`, is a constant of the body.
15
+ */
16
+ export namespace AutoMovieHumanSegmentFrame {
17
+ /** A point or a direction, mm. */
18
+ export type V3 = [number, number, number];
19
+
20
+ /** A 3 x 3 matrix by rows. */
21
+ export type M3 = [V3, V3, V3];
22
+
23
+ /** A segment frame: its origin and unit axes X, Y, Z in the figure's frame. */
24
+ export interface IFrame {
25
+ /** Origin, mm. */
26
+ origin: V3;
27
+
28
+ /** Unit axes X, Y, Z, right-handed. */
29
+ axes: [V3, V3, V3];
30
+ }
31
+
32
+ /** One segment of a chain: its parent, its origin in the parent's frame and its reference rotation. */
33
+ export interface IJoint {
34
+ /** The segment's name. */
35
+ name: string;
36
+
37
+ /** The parent segment's name; null for the root. */
38
+ parent: string | null;
39
+
40
+ /** The origin in the parent's frame, mm (the root: in the figure's frame). */
41
+ offset: V3;
42
+
43
+ /** The reference rotation `A_parent^T A_child` (the root: its axes as columns). */
44
+ rotation: M3;
45
+ }
46
+
47
+ /** A frame from an exact Y and a hint for Z: Z is the hint made square to Y, X = Y x Z. */
48
+ export function fromYZ(origin: V3, y: V3, z: V3): IFrame {
49
+ const Y: V3 = unit(y);
50
+ const Z: V3 = perpendicular(z, Y);
51
+ return { origin, axes: [cross(Y, Z), Y, Z] };
52
+ }
53
+
54
+ /** A frame from an exact Y and a hint for X: X is the hint made square to Y, Z = X x Y. */
55
+ export function fromYX(origin: V3, y: V3, x: V3): IFrame {
56
+ const Y: V3 = unit(y);
57
+ const X: V3 = perpendicular(x, Y);
58
+ return { origin, axes: [X, Y, cross(X, Y)] };
59
+ }
60
+
61
+ /** A frame from an exact X and a hint for Y: Y is the hint made square to X, Z = X x Y. */
62
+ export function fromXY(origin: V3, x: V3, y: V3): IFrame {
63
+ const X: V3 = unit(x);
64
+ const Y: V3 = perpendicular(y, X);
65
+ return { origin, axes: [X, Y, cross(X, Y)] };
66
+ }
67
+
68
+ /** A frame at `origin` with the axes of `parent`: a segment rigid to and parallel with its parent. */
69
+ export function parallel(origin: V3, parent: IFrame): IFrame {
70
+ return { origin, axes: [[...parent.axes[0]], [...parent.axes[1]], [...parent.axes[2]]] };
71
+ }
72
+
73
+ /**
74
+ * The humerus, Wu et al. 2005 2.3.4 option 1, on the stored side: Y from the epicondyles' midpoint to the glenohumeral centre, X the
75
+ * normal of the plane through GH, EL and EM, forward, Z = X x Y. With EL lateral (+Z) and EM medial, `(EL - GH) x (EM - GH)` points
76
+ * forward, so no hint is needed. ISB's origin is GH, which is also the joint the segment pivots about.
77
+ */
78
+ export function humerus(gh: V3, el: V3, em: V3): IFrame {
79
+ const Y: V3 = unit(sub(gh, mid(el, em)));
80
+ const X: V3 = perpendicular(cross(sub(el, gh), sub(em, gh)), Y);
81
+ return { origin: gh, axes: [X, Y, cross(X, Y)] };
82
+ }
83
+
84
+ /**
85
+ * The forearm, Wu et al. 2005 2.3.6, on the stored side: Y from the ulnar styloid US to the epicondyles' midpoint, X the normal of the
86
+ * plane through US, RS and that midpoint, forward, Z = X x Y. With RS lateral of US in the anatomical position, `(E - US) x (RS - US)`
87
+ * points forward. The origin is the elbow centre the segment pivots about; ISB's origin US is a constant translation inside the segment
88
+ * that changes no axis and no joint angle.
89
+ */
90
+ export function forearm(elbow: V3, us: V3, rs: V3, el: V3, em: V3): IFrame {
91
+ const e: V3 = mid(el, em);
92
+ const Y: V3 = unit(sub(e, us));
93
+ const X: V3 = perpendicular(cross(sub(e, us), sub(rs, us)), Y);
94
+ return { origin: elbow, axes: [X, Y, cross(X, Y)] };
95
+ }
96
+
97
+ /**
98
+ * The femur, Wu et al. 2002 4.4, on the stored side: Y from the femoral epicondyles' midpoint to the hip centre, Z the lateral
99
+ * epicondyle's direction from the medial one made square to Y (in the plane of the hip centre and both epicondyles, to the right on the
100
+ * stored side), X = Y x Z. ISB's origin is the hip centre, the joint the segment pivots about.
101
+ */
102
+ export function femur(hip: V3, lateral: V3, medial: V3): IFrame {
103
+ return fromYZ(hip, sub(hip, mid(lateral, medial)), sub(lateral, medial));
104
+ }
105
+
106
+ /** The axes as the columns of a matrix. */
107
+ export function matrix(frame: IFrame): M3 {
108
+ const [x, y, z]: [V3, V3, V3] = frame.axes;
109
+ return [
110
+ [x[0], y[0], z[0]],
111
+ [x[1], y[1], z[1]],
112
+ [x[2], y[2], z[2]],
113
+ ];
114
+ }
115
+
116
+ /** The frame whose axes are the columns of `m`. */
117
+ export function columns(origin: V3, m: M3): IFrame {
118
+ return {
119
+ origin,
120
+ axes: [
121
+ [m[0][0], m[1][0], m[2][0]],
122
+ [m[0][1], m[1][1], m[2][1]],
123
+ [m[0][2], m[1][2], m[2][2]],
124
+ ],
125
+ };
126
+ }
127
+
128
+ /** A point of the figure's frame in the segment's frame: `A^T (p - o)`. */
129
+ export function toLocal(frame: IFrame, p: V3): V3 {
130
+ return toLocalDirection(frame, sub(p, frame.origin));
131
+ }
132
+
133
+ /** A direction of the figure's frame in the segment's frame: `A^T d`. */
134
+ export function toLocalDirection(frame: IFrame, d: V3): V3 {
135
+ return [dot(frame.axes[0], d), dot(frame.axes[1], d), dot(frame.axes[2], d)];
136
+ }
137
+
138
+ /** A point of the segment's frame in the figure's frame: `o + A q`. */
139
+ export function toWorld(frame: IFrame, q: V3): V3 {
140
+ return add(frame.origin, toWorldDirection(frame, q));
141
+ }
142
+
143
+ /** A direction of the segment's frame in the figure's frame: `A q`. */
144
+ export function toWorldDirection(frame: IFrame, q: V3): V3 {
145
+ const [x, y, z]: [V3, V3, V3] = frame.axes;
146
+ return [x[0] * q[0] + y[0] * q[1] + z[0] * q[2], x[1] * q[0] + y[1] * q[1] + z[1] * q[2], x[2] * q[0] + y[2] * q[1] + z[2] * q[2]];
147
+ }
148
+
149
+ /** `child`, written in `parent`'s frame, placed in the figure's frame: the rigid transform `parent o child`. */
150
+ export function compose(parent: IFrame, child: IFrame): IFrame {
151
+ return { origin: toWorld(parent, child.origin), axes: [toWorldDirection(parent, child.axes[0]), toWorldDirection(parent, child.axes[1]), toWorldDirection(parent, child.axes[2])] };
152
+ }
153
+
154
+ /** The inverse rigid transform: the figure's frame written in the segment's frame, so `compose(frame, inverse(frame))` is the identity. */
155
+ export function inverse(frame: IFrame): IFrame {
156
+ const m: M3 = transpose(matrix(frame));
157
+ return columns(scale(multiplyVector(m, frame.origin), -1), m);
158
+ }
159
+
160
+ /** `child` written in `parent`'s frame: its origin `A_p^T (o_c - o_p)` and its rotation `A_p^T A_c`. */
161
+ export function relative(parent: IFrame, child: IFrame): { offset: V3; rotation: M3 } {
162
+ return { offset: toLocal(parent, child.origin), rotation: multiply(transpose(matrix(parent)), matrix(child)) };
163
+ }
164
+
165
+ /**
166
+ * The twin's frame: the reflection `S = diag(1, 1, -1)` in z = 0 of the origin, X and Y, with Z = X' x Y' = -S Z so the twin stays
167
+ * right-handed. Its joint rotations are `D R D` with `D = diag(1, 1, -1)`, since `S A D` replaces `A` on both sides.
168
+ */
169
+ export function mirror(frame: IFrame): IFrame {
170
+ const s = (v: V3): V3 => [v[0], v[1], -v[2]];
171
+ const [x, y, z]: [V3, V3, V3] = frame.axes;
172
+ return { origin: s(frame.origin), axes: [s(x), s(y), scale(s(z), -1)] };
173
+ }
174
+
175
+ /**
176
+ * The chain of a tree of segments given parent-first: each segment's origin in its parent's frame and its reference rotation. The
177
+ * root's offset is its origin and its rotation its axes, both in the figure's frame.
178
+ */
179
+ export function chain(segments: readonly { name: string; parent: string | null; frame: IFrame }[]): IJoint[] {
180
+ const placed: Map<string, IFrame> = new Map();
181
+ return segments.map((segment: { name: string; parent: string | null; frame: IFrame }): IJoint => {
182
+ placed.set(segment.name, segment.frame);
183
+ if (segment.parent === null) return { name: segment.name, parent: null, offset: [...segment.frame.origin], rotation: matrix(segment.frame) };
184
+ const parent: IFrame | undefined = placed.get(segment.parent);
185
+ if (parent === undefined) throw new Error("Segment " + segment.name + " precedes its parent " + segment.parent);
186
+ return { name: segment.name, parent: segment.parent, ...relative(parent, segment.frame) };
187
+ });
188
+ }
189
+
190
+ /**
191
+ * The frames of a posed chain: `A_child = A_parent R` and `o_child = o_parent + A_parent offset`, parent first. `pose` gives a joint's
192
+ * rotation by name; a joint it leaves undefined keeps its reference rotation, so `world(joints, () => undefined)` returns the reference
193
+ * frames and identity rotations the neutral body.
194
+ */
195
+ export function world(joints: readonly IJoint[], pose: (name: string) => M3 | undefined): Map<string, IFrame> {
196
+ const out: Map<string, IFrame> = new Map();
197
+ for (const joint of joints) {
198
+ const rotation: M3 = pose(joint.name) ?? joint.rotation;
199
+ if (joint.parent === null) {
200
+ out.set(joint.name, columns([...joint.offset], rotation));
201
+ continue;
202
+ }
203
+ const parent: IFrame | undefined = out.get(joint.parent);
204
+ if (parent === undefined) throw new Error("Joint " + joint.name + " precedes its parent " + joint.parent);
205
+ out.set(joint.name, columns(toWorld(parent, joint.offset), multiply(matrix(parent), rotation)));
206
+ }
207
+ return out;
208
+ }
209
+
210
+ /** The rotation by `angle` radians about the unit axis `axis` (0 X, 1 Y, 2 Z) of the frame it acts in. */
211
+ export function about(axis: 0 | 1 | 2, angle: number): M3 {
212
+ const c: number = Math.cos(angle);
213
+ const s: number = Math.sin(angle);
214
+ if (axis === 0) return [[1, 0, 0], [0, c, -s], [0, s, c]];
215
+ if (axis === 1) return [[c, 0, s], [0, 1, 0], [-s, 0, c]];
216
+ return [[c, -s, 0], [s, c, 0], [0, 0, 1]];
217
+ }
218
+
219
+ /**
220
+ * The ISB joint-coordinate angles of a Z-X-Y Cardan sequence (Grood and Suntay 1983, as ISB writes the hip, knee and ankle in Wu et al.
221
+ * 2002 and the elbow and wrist in Wu et al. 2005): `R = Rz(a) Rx(b) Ry(c)` with a about the parent's Z (flexion), b about the floating
222
+ * axis (adduction or deviation) and c about the child's Y (axial rotation), radians. From the product,
223
+ * `R[2][1] = sin b`, `R[0][1] = -sin a cos b`, `R[1][1] = cos a cos b`, `R[2][0] = -cos b sin c`, `R[2][2] = cos b cos c`.
224
+ */
225
+ export function cardanZXY(r: M3): [number, number, number] {
226
+ return [Math.atan2(-r[0][1], r[1][1]), Math.asin(Math.max(-1, Math.min(1, r[2][1]))), Math.atan2(-r[2][0], r[2][2])];
227
+ }
228
+
229
+ /**
230
+ * The ISB shoulder angles, a Y-X-Y Euler sequence (Wu et al. 2005 2.4.7, the humerus relative to the thorax): `R = Ry(a) Rx(b) Ry(c)`
231
+ * with a the plane of elevation (0 abduction, 90 degrees forward flexion), b the elevation and c the axial rotation (internal
232
+ * positive), radians. The text writes "elevation (negative)", and its footnote 5 that the second rotation is by definition in the
233
+ * negative direction as a consequence of the chosen axes, so the branch with b in [-pi, 0] is returned: an arm raised sideways reads
234
+ * a plane of elevation near 0 and a negative elevation. From the product, `R[1][1] = cos b`, `R[0][1] = sin a sin b`, `R[2][1] = cos a sin b`,
235
+ * `R[1][0] = sin b sin c`, `R[1][2] = -sin b cos c`, so with `sin b <= 0`: `a = atan2(-R[0][1], -R[2][1])`, `c = atan2(-R[1][0], R[1][2])`.
236
+ */
237
+ export function eulerYXY(r: M3): [number, number, number] {
238
+ return [Math.atan2(-r[0][1], -r[2][1]), -Math.acos(Math.max(-1, Math.min(1, r[1][1]))), Math.atan2(-r[1][0], r[1][2])];
239
+ }
240
+
241
+ /** Matrix product. */
242
+ export function multiply(a: M3, b: M3): M3 {
243
+ const row = (i: number): V3 => [0, 1, 2].map((j: number): number => a[i]![0] * b[0][j]! + a[i]![1] * b[1][j]! + a[i]![2] * b[2][j]!) as V3;
244
+ return [row(0), row(1), row(2)];
245
+ }
246
+
247
+ /** Matrix times a vector. */
248
+ export function multiplyVector(m: M3, v: V3): V3 {
249
+ return [dot(m[0], v), dot(m[1], v), dot(m[2], v)];
250
+ }
251
+
252
+ /** Transpose. */
253
+ export function transpose(m: M3): M3 {
254
+ return [
255
+ [m[0][0], m[1][0], m[2][0]],
256
+ [m[0][1], m[1][1], m[2][1]],
257
+ [m[0][2], m[1][2], m[2][2]],
258
+ ];
259
+ }
260
+
261
+ /** The identity rotation. */
262
+ export const IDENTITY: M3 = [
263
+ [1, 0, 0],
264
+ [0, 1, 0],
265
+ [0, 0, 1],
266
+ ];
267
+
268
+ /** Midpoint. */
269
+ export function mid(a: V3, b: V3): V3 {
270
+ return [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2];
271
+ }
272
+
273
+ /** Difference. */
274
+ export function sub(a: V3, b: V3): V3 {
275
+ return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
276
+ }
277
+
278
+ /** Sum. */
279
+ export function add(a: V3, b: V3): V3 {
280
+ return [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
281
+ }
282
+
283
+ /** Multiple. */
284
+ export function scale(a: V3, s: number): V3 {
285
+ return [a[0] * s, a[1] * s, a[2] * s];
286
+ }
287
+
288
+ /** Scalar product. */
289
+ export function dot(a: V3, b: V3): number {
290
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
291
+ }
292
+
293
+ /** Right-handed vector product. */
294
+ export function cross(a: V3, b: V3): V3 {
295
+ return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
296
+ }
297
+
298
+ /** Unit vector; a zero vector has no direction and is refused. */
299
+ export function unit(a: V3): V3 {
300
+ const l: number = Math.hypot(a[0], a[1], a[2]);
301
+ if (!(l > 0)) throw new Error("A segment axis has no direction");
302
+ return [a[0] / l, a[1] / l, a[2] / l];
303
+ }
304
+
305
+ /** `a` made square to the unit `n`, unit; `a` along `n` has no square part and is refused. */
306
+ export function perpendicular(a: V3, n: V3): V3 {
307
+ return unit(sub(a, scale(n, dot(a, n))));
308
+ }
309
+ }
package/src/index.ts CHANGED
@@ -3,3 +3,14 @@ export * from "./lofting";
3
3
  export * from "./skeleton";
4
4
  export * from "./structures";
5
5
  export * from "./typings";
6
+ export * from "./generation/conic/AutoMovieHumanConicLoft";
7
+ export * from "./generation/conic/AutoMovieHumanConicPose";
8
+ export * from "./generation/conic/AutoMovieHumanConicRelief";
9
+ export * from "./generation/conic/AutoMovieHumanConicSection";
10
+ export * from "./generation/f1/AutoMovieHumanF1";
11
+ export * from "./generation/f1/AutoMovieHumanF1Joints";
12
+ export * from "./generation/f1/AutoMovieHumanF1Landmarks";
13
+ export * from "./generation/f1/AutoMovieHumanF1Frames";
14
+ export * from "./generation/f1/AutoMovieHumanF1Placing";
15
+ export * from "./generation/f1/AutoMovieHumanF1Placement";
16
+ export * from "./generation/frame/AutoMovieHumanSegmentFrame";
@@ -108,13 +108,17 @@ export namespace AutoMovieHumanCanonicalBody {
108
108
  * The joints then move onto the canonical rig: reflected from Human's
109
109
  * registered frame, each arm straightened along ±X by shortest arcs about
110
110
  * the shoulder, the elbow and the wrist and pronated until the palm faces
111
- * -Y, each thigh and shank straightened along -Y with the foot keeping its
111
+ * -Y, each finger straightened in the palm's plane along its own knuckle
112
+ * line and the thumb's two hinges along its metacarpal (the bind holds a
113
+ * relaxed hand, and a finger angle of zero is the extended finger, as in
114
+ * the VRM T-pose and the Neutral-0 position), each thigh and shank straightened along -Y with the foot keeping its
112
115
  * bind orientation, and the whole body raised or lowered so its lowest foot
113
116
  * joint sphere touches the floor. Every humanoid-named joint becomes a rig
114
117
  * bone with an identity rest rotation, the toes bone at the hallux's
115
118
  * metatarsophalangeal joint, and every other joint rides its nearest
116
119
  * humanoid ancestor. The contact profile is built from the same joints and
117
- * radii (`AutoMovieHumanCanonicalProfile`), so contacts meet what is drawn.
120
+ * radii (`AutoMovieHumanCanonicalProfile`), its colliders the convex hulls
121
+ * of the drawn ring points, so contacts meet what is drawn.
118
122
  *
119
123
  * @param params The Human's parameters.
120
124
  * @param options Body mass in kilograms and the skeleton id.
@@ -229,7 +233,7 @@ export namespace AutoMovieHumanCanonicalBody {
229
233
  * `(x, y, z) -> (z, y, x)`. The drawing's parent must carry that same
230
234
  * reflection (`REFLECTION`, a column-major 4x4) so the figure shows in the
231
235
  * canonical world; a reflected world matrix keeps faces outward because
232
- * three.js and the CPU rasterizer reverse winding for it.
236
+ * three.js reverses winding for it.
233
237
  *
234
238
  * @param body The canonical body.
235
239
  * @param pose A canonical pose; omitted, the T-pose rest.
@@ -349,6 +353,22 @@ function canonical(
349
353
  pivot,
350
354
  );
351
355
  };
356
+ const straighten = (
357
+ chain: readonly string[],
358
+ direction: IAutoMovieVector3,
359
+ ): void => {
360
+ chain.forEach((bone: string, i: number): void => {
361
+ const pivot: IAutoMovieVector3 = position.get(bone)!;
362
+ const end: IAutoMovieVector3 | null =
363
+ i + 1 < chain.length ? position.get(chain[i + 1]!)! : tip.get(bone)!;
364
+ if (end === null) return;
365
+ turn(
366
+ descendants(bone),
367
+ rotationBetween(Vector3.subtract(end, pivot), direction),
368
+ pivot,
369
+ );
370
+ });
371
+ };
352
372
  const down: IAutoMovieVector3 = Vector3.create(0, -1, 0);
353
373
  for (const [side, sign] of [
354
374
  ["left", 1],
@@ -385,6 +405,34 @@ function canonical(
385
405
  position.get(`${side}LowerArm`)!,
386
406
  );
387
407
 
408
+ // Straight digits: the bind holds a relaxed hand, and a clinical zero is
409
+ // the extended one (Neutral-0), so each finger lies in the palm's plane
410
+ // along its own knuckle line and the thumb's two hinges continue its
411
+ // metacarpal.
412
+ for (const finger of ["Index", "Middle", "Ring", "Little"] as const) {
413
+ const line: IAutoMovieVector3 = Vector3.subtract(
414
+ position.get(`${side}${finger}Intermediate`)!,
415
+ position.get(`${side}${finger}Proximal`)!,
416
+ );
417
+ straighten(
418
+ [
419
+ `${side}${finger}Proximal`,
420
+ `${side}${finger}Intermediate`,
421
+ `${side}${finger}Distal`,
422
+ ],
423
+ Vector3.normalize(Vector3.create(line.x, 0, line.z)),
424
+ );
425
+ }
426
+ straighten(
427
+ [`${side}ThumbProximal`, `${side}ThumbDistal`],
428
+ Vector3.normalize(
429
+ Vector3.subtract(
430
+ position.get(`${side}ThumbProximal`)!,
431
+ position.get(`${side}ThumbMetacarpal`)!,
432
+ ),
433
+ ),
434
+ );
435
+
388
436
  // Straight legs; each foot turns back to its bind orientation.
389
437
  align(side, "UpperLeg", "LowerLeg", down);
390
438
  align(side, "LowerLeg", "Foot", down);
@@ -468,6 +516,8 @@ function canonical(
468
516
  bind.map((bone: IBind): [string, Profile.IJoint] => [
469
517
  bone.bone,
470
518
  {
519
+ parent: bone.parent,
520
+ carrier: carrier.get(bone.bone)!,
471
521
  position: position.get(bone.bone)!,
472
522
  tip: tip.get(bone.bone)!,
473
523
  radius: bone.radius,