@egen-civitas/esm-styleguide 2.3.1 → 3.0.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/CHANGELOG.md +40 -0
- package/dist/_all.scss +0 -1
- package/dist/_vars.scss +4 -4
- package/dist/assistant/index.d.ts +7 -0
- package/dist/assistant/index.d.ts.map +1 -1
- package/dist/assistant/index.js +5 -0
- package/dist/assistant/robot/README.md +47 -0
- package/dist/assistant/robot/Robot.d.ts +16 -0
- package/dist/assistant/robot/Robot.d.ts.map +1 -0
- package/dist/assistant/robot/Robot.js +159 -0
- package/dist/assistant/robot/RobotStage.d.ts +31 -0
- package/dist/assistant/robot/RobotStage.d.ts.map +1 -0
- package/dist/assistant/robot/RobotStage.js +250 -0
- package/dist/assistant/robot/clips.d.ts +62 -0
- package/dist/assistant/robot/clips.d.ts.map +1 -0
- package/dist/assistant/robot/clips.js +179 -0
- package/dist/assistant/robot/controller.d.ts +133 -0
- package/dist/assistant/robot/controller.d.ts.map +1 -0
- package/dist/assistant/robot/controller.js +522 -0
- package/dist/assistant/robot/gestures.d.ts +23 -0
- package/dist/assistant/robot/gestures.d.ts.map +1 -0
- package/dist/assistant/robot/gestures.js +1301 -0
- package/dist/assistant/robot/hands.d.ts +55 -0
- package/dist/assistant/robot/hands.d.ts.map +1 -0
- package/dist/assistant/robot/hands.js +121 -0
- package/dist/assistant/robot/ik.d.ts +34 -0
- package/dist/assistant/robot/ik.d.ts.map +1 -0
- package/dist/assistant/robot/ik.js +57 -0
- package/dist/assistant/robot/index.d.ts +18 -0
- package/dist/assistant/robot/index.d.ts.map +1 -0
- package/dist/assistant/robot/index.js +9 -0
- package/dist/assistant/robot/lazy.d.ts +8 -0
- package/dist/assistant/robot/lazy.d.ts.map +1 -0
- package/dist/assistant/robot/lazy.js +33 -0
- package/dist/assistant/robot/materials.d.ts +46 -0
- package/dist/assistant/robot/materials.d.ts.map +1 -0
- package/dist/assistant/robot/materials.js +101 -0
- package/dist/assistant/robot/parts/Body.d.ts +28 -0
- package/dist/assistant/robot/parts/Body.d.ts.map +1 -0
- package/dist/assistant/robot/parts/Body.js +368 -0
- package/dist/assistant/robot/parts/Head.d.ts +11 -0
- package/dist/assistant/robot/parts/Head.d.ts.map +1 -0
- package/dist/assistant/robot/parts/Head.js +210 -0
- package/dist/assistant/robot/parts/primitives.d.ts +36 -0
- package/dist/assistant/robot/parts/primitives.d.ts.map +1 -0
- package/dist/assistant/robot/parts/primitives.js +127 -0
- package/dist/assistant/robot/skeleton.d.ts +66 -0
- package/dist/assistant/robot/skeleton.d.ts.map +1 -0
- package/dist/assistant/robot/skeleton.js +266 -0
- package/dist/cards/card-header.component.d.ts +1 -1
- package/dist/cards/card-header.component.js +1 -1
- package/dist/cards/card-header.stories.js +1 -1
- package/dist/components/_general.scss +3 -3
- package/dist/config-schema.d.ts +0 -17
- package/dist/config-schema.d.ts.map +1 -1
- package/dist/config-schema.js +0 -25
- package/dist/datepicker/datepicker.stories.js +1 -1
- package/dist/empty-card/empty-card.stories.js +2 -2
- package/dist/error-state/error-state.stories.js +2 -2
- package/dist/icons/icon-registration.d.ts.map +1 -1
- package/dist/icons/icon-registration.js +0 -30
- package/dist/icons/icons.d.ts +4 -32
- package/dist/icons/icons.d.ts.map +1 -1
- package/dist/icons/icons.js +18 -148
- package/dist/index.js +0 -2
- package/dist/internal.d.ts +0 -3
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +0 -3
- package/dist/notifications/actionable-notification.stories.js +5 -5
- package/dist/notifications/notification.stories.js +5 -5
- package/dist/page-header/page-header.component.d.ts +1 -1
- package/dist/page-header/page-header.component.js +1 -1
- package/dist/pagination/pagination.stories.js +2 -2
- package/dist/pictograms/pictogram-registration.d.ts.map +1 -1
- package/dist/pictograms/pictogram-registration.js +2 -36
- package/dist/pictograms/pictograms.d.ts +2 -20
- package/dist/pictograms/pictograms.d.ts.map +1 -1
- package/dist/pictograms/pictograms.js +2 -139
- package/dist/public.d.ts +0 -3
- package/dist/public.d.ts.map +1 -1
- package/dist/public.js +0 -3
- package/dist/responsive-wrapper/responsive-wrapper.stories.js +1 -1
- package/dist/snackbars/snackbar.stories.js +1 -1
- package/dist/toasts/toast.stories.js +1 -1
- package/dist/workbench/splitter.component.d.ts +14 -0
- package/dist/workbench/splitter.component.d.ts.map +1 -1
- package/dist/workbench/splitter.component.js +52 -0
- package/dist/workbench/tool-window-rail.component.d.ts.map +1 -1
- package/dist/workbench/tool-window-rail.component.js +9 -1
- package/dist/workbench/tool-window-zone.component.d.ts.map +1 -1
- package/dist/workbench/tool-window-zone.component.js +9 -1
- package/dist/workbench/workbench.module.scss +64 -1
- package/dist/workbench/workbench.store.d.ts +2 -0
- package/dist/workbench/workbench.store.d.ts.map +1 -1
- package/dist/workbench/workbench.store.js +9 -0
- package/dist/workspaces/container/workspace-container.component.d.ts +8 -8
- package/dist/workspaces/container/workspace-container.component.js +9 -9
- package/dist/workspaces2/workspace2.d.ts +3 -3
- package/dist/workspaces2/workspace2.js +3 -3
- package/mock-jest.tsx +0 -41
- package/mock.tsx +0 -41
- package/package.json +26 -23
- package/src/_vars.scss +4 -4
- package/dist/entity-banner/actions-menu/entity-banner-actions-menu.component.d.ts +0 -19
- package/dist/entity-banner/actions-menu/entity-banner-actions-menu.component.d.ts.map +0 -1
- package/dist/entity-banner/actions-menu/entity-banner-actions-menu.component.js +0 -137
- package/dist/entity-banner/actions-menu/entity-banner-actions-menu.module.scss +0 -23
- package/dist/entity-banner/contact-details/entity-banner-contact-details.component.d.ts +0 -9
- package/dist/entity-banner/contact-details/entity-banner-contact-details.component.d.ts.map +0 -1
- package/dist/entity-banner/contact-details/entity-banner-contact-details.component.js +0 -207
- package/dist/entity-banner/contact-details/entity-banner-contact-details.module.scss +0 -47
- package/dist/entity-banner/contact-details/entity-banner-toggle-contact-details-button.component.d.ts +0 -12
- package/dist/entity-banner/contact-details/entity-banner-toggle-contact-details-button.component.d.ts.map +0 -1
- package/dist/entity-banner/contact-details/entity-banner-toggle-contact-details-button.component.js +0 -15
- package/dist/entity-banner/contact-details/types.d.ts +0 -48
- package/dist/entity-banner/contact-details/types.d.ts.map +0 -1
- package/dist/entity-banner/contact-details/types.js +0 -1
- package/dist/entity-banner/contact-details/useEntityAttributes.d.ts +0 -14
- package/dist/entity-banner/contact-details/useEntityAttributes.d.ts.map +0 -1
- package/dist/entity-banner/contact-details/useEntityAttributes.js +0 -12
- package/dist/entity-banner/contact-details/useEntityGroupsForEntity.d.ts +0 -11
- package/dist/entity-banner/contact-details/useEntityGroupsForEntity.d.ts.map +0 -1
- package/dist/entity-banner/contact-details/useEntityGroupsForEntity.js +0 -9
- package/dist/entity-banner/contact-details/useRelationships.d.ts +0 -35
- package/dist/entity-banner/contact-details/useRelationships.d.ts.map +0 -1
- package/dist/entity-banner/contact-details/useRelationships.js +0 -37
- package/dist/entity-banner/entity-info/entity-banner-entity-identifiers.component.d.ts +0 -9
- package/dist/entity-banner/entity-info/entity-banner-entity-identifiers.component.d.ts.map +0 -1
- package/dist/entity-banner/entity-info/entity-banner-entity-identifiers.component.js +0 -77
- package/dist/entity-banner/entity-info/entity-banner-entity-info.component.d.ts +0 -9
- package/dist/entity-banner/entity-info/entity-banner-entity-info.component.d.ts.map +0 -1
- package/dist/entity-banner/entity-info/entity-banner-entity-info.component.js +0 -72
- package/dist/entity-banner/entity-info/entity-banner-entity-info.module.scss +0 -165
- package/dist/entity-banner/index.d.ts +0 -5
- package/dist/entity-banner/index.d.ts.map +0 -1
- package/dist/entity-banner/index.js +0 -4
- package/dist/entity-photo/entity-photo.component.d.ts +0 -21
- package/dist/entity-photo/entity-photo.component.d.ts.map +0 -1
- package/dist/entity-photo/entity-photo.component.js +0 -111
- package/dist/entity-photo/entity-photo.module.scss +0 -21
- package/dist/entity-photo/index.d.ts +0 -3
- package/dist/entity-photo/index.d.ts.map +0 -1
- package/dist/entity-photo/index.js +0 -2
- package/dist/entity-photo/placeholder-icon.component.d.ts +0 -9
- package/dist/entity-photo/placeholder-icon.component.d.ts.map +0 -1
- package/dist/entity-photo/placeholder-icon.component.js +0 -26
- package/dist/entity-photo/useEntityPhoto.d.ts +0 -29
- package/dist/entity-photo/useEntityPhoto.d.ts.map +0 -1
- package/dist/entity-photo/useEntityPhoto.js +0 -37
- package/dist/icons/svgs/baby.svg +0 -1
- package/dist/icons/svgs/chemistry.svg +0 -1
- package/dist/icons/svgs/drug-order.svg +0 -1
- package/dist/icons/svgs/generic-order-type.svg +0 -1
- package/dist/icons/svgs/hospital-bed.svg +0 -1
- package/dist/icons/svgs/image-medical.svg +0 -1
- package/dist/icons/svgs/lab-order.svg +0 -1
- package/dist/icons/svgs/material-order.svg +0 -1
- package/dist/icons/svgs/medication.svg +0 -1
- package/dist/icons/svgs/microscope.svg +0 -1
- package/dist/icons/svgs/mother.svg +0 -1
- package/dist/icons/svgs/procedure-order.svg +0 -1
- package/dist/icons/svgs/referral-order.svg +0 -1
- package/dist/icons/svgs/syringe.svg +0 -1
- package/dist/logo/_logo.scss +0 -34
- package/dist/logo/egen-logo-full.svg +0 -1
- package/dist/logo/egen-logo-icon.svg +0 -1
- package/dist/logo/egen-logo-partial.svg +0 -1
- package/dist/logo/egen-logo-white.svg +0 -1
- package/dist/logo/index.d.ts +0 -8
- package/dist/logo/index.d.ts.map +0 -1
- package/dist/logo/index.js +0 -22
- package/dist/numeric-datapoint/index.d.ts +0 -4
- package/dist/numeric-datapoint/index.d.ts.map +0 -1
- package/dist/numeric-datapoint/index.js +0 -3
- package/dist/numeric-datapoint/interpretation-utils.d.ts +0 -27
- package/dist/numeric-datapoint/interpretation-utils.d.ts.map +0 -1
- package/dist/numeric-datapoint/interpretation-utils.js +0 -66
- package/dist/numeric-datapoint/numeric-datapoint.component.d.ts +0 -44
- package/dist/numeric-datapoint/numeric-datapoint.component.d.ts.map +0 -1
- package/dist/numeric-datapoint/numeric-datapoint.component.js +0 -110
- package/dist/numeric-datapoint/numeric-datapoint.module.scss +0 -141
- package/dist/numeric-datapoint/use-concept-reference-range.d.ts +0 -13
- package/dist/numeric-datapoint/use-concept-reference-range.d.ts.map +0 -1
- package/dist/numeric-datapoint/use-concept-reference-range.js +0 -31
- package/dist/pictograms/svgs/blood-bank.svg +0 -1
- package/dist/pictograms/svgs/cardiology.svg +0 -1
- package/dist/pictograms/svgs/ct-scan.svg +0 -1
- package/dist/pictograms/svgs/dentistry.svg +0 -1
- package/dist/pictograms/svgs/emergency-department.svg +0 -1
- package/dist/pictograms/svgs/geriatrics.svg +0 -1
- package/dist/pictograms/svgs/gynaecology.svg +0 -1
- package/dist/pictograms/svgs/in-patient.svg +0 -1
- package/dist/pictograms/svgs/labs-2.svg +0 -1
- package/dist/pictograms/svgs/labs.svg +0 -1
- package/dist/pictograms/svgs/obstetrics.svg +0 -1
- package/dist/pictograms/svgs/patient-search.svg +0 -1
- package/dist/pictograms/svgs/patients.svg +0 -1
- package/dist/pictograms/svgs/pharmacy-1.svg +0 -1
- package/dist/pictograms/svgs/pharmacy-2.svg +0 -1
- package/dist/pictograms/svgs/triage.svg +0 -1
- package/dist/pictograms/svgs/x-ray.svg +0 -1
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
import { clipWeight, compileClip, sampleClip } from "./clips.js";
|
|
15
|
+
import { GESTURE_LIBRARY, TALK_GESTURES, resolveGesture } from "./gestures.js";
|
|
16
|
+
import { HAND_SHAPES, handPose, resolveShape } from "./hands.js";
|
|
17
|
+
import { JOINT_NAMES, REST_POSE, clampToLimits, createRestPose } from "./skeleton.js";
|
|
18
|
+
const MAX_SPEED = 0.9;
|
|
19
|
+
const STRIDE = 0.9;
|
|
20
|
+
const TURN_RATE = 3.2;
|
|
21
|
+
function mulberry32(seed) {
|
|
22
|
+
let a = seed >>> 0;
|
|
23
|
+
return ()=>{
|
|
24
|
+
a = a + 0x6d2b79f5 >>> 0;
|
|
25
|
+
let t = a;
|
|
26
|
+
t = Math.imul(t ^ t >>> 15, t | 1);
|
|
27
|
+
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
|
28
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const damp = (cur, goal, lambda, dt)=>cur + (goal - cur) * (1 - Math.exp(-lambda * dt));
|
|
32
|
+
const wrapAngle = (a)=>Math.atan2(Math.sin(a), Math.cos(a));
|
|
33
|
+
const smoothstep = (u)=>{
|
|
34
|
+
const x = Math.min(1, Math.max(0, u));
|
|
35
|
+
return x * x * (3 - 2 * x);
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Cerveau du robot : décide, à chaque image, de l'angle de chaque articulation.
|
|
39
|
+
*
|
|
40
|
+
* Il ne dépend NI de React NI de WebGL : il lit des commandes (jouer un geste, marcher,
|
|
41
|
+
* regarder, changer d'état) et écrit un résultat dans `pose` (angles lissés) et `root`
|
|
42
|
+
* (position et cap du robot). Le rendu (`Robot.tsx`) n'a qu'à recopier ces valeurs.
|
|
43
|
+
*
|
|
44
|
+
* Ordre de calcul à chaque image (le dernier gagne sur les mêmes articulations) :
|
|
45
|
+
* 1. pose de repos
|
|
46
|
+
* 2. attitude de l'état (écoute : léger penché, etc.)
|
|
47
|
+
* 3. démarche, si le robot marche
|
|
48
|
+
* 4. clips de gestes en cours (avec fondu d'entrée / sortie)
|
|
49
|
+
* 5. couches additives : respiration, balancement, regard
|
|
50
|
+
* 6. butées de chaque articulation, puis lissage exponentiel
|
|
51
|
+
* 7. doigts (forme de main lissée)
|
|
52
|
+
*/ export class RobotController {
|
|
53
|
+
// ---------------------------------------------------------------- commandes
|
|
54
|
+
/** Joue un geste de la bibliothèque. La promesse se résout quand il est terminé (ou interrompu). */ play(name, options = {}) {
|
|
55
|
+
const def = resolveGesture(name, options.side ?? 'L');
|
|
56
|
+
return this.start(def, GESTURE_LIBRARY[name] ? 1 : 1, options);
|
|
57
|
+
}
|
|
58
|
+
/** Joue un clip personnalisé (voir `ClipDef`). */ playClip(def, options = {}) {
|
|
59
|
+
return this.start(def, 1, options);
|
|
60
|
+
}
|
|
61
|
+
/** Arrête les gestes en cours (tous, ou seulement `name`) avec un fondu. */ stopGesture(name) {
|
|
62
|
+
for (const p of this.players){
|
|
63
|
+
if (!name || p.clip.name === name) this.beginStop(p);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
get isGesturing() {
|
|
67
|
+
return this.players.some((p)=>!p.stopping && p.priority > 0);
|
|
68
|
+
}
|
|
69
|
+
setState(state) {
|
|
70
|
+
if (state === this.state) return;
|
|
71
|
+
this.state = state;
|
|
72
|
+
if (state === 'thinking' && this.autoBehaviors) this.play('think', {
|
|
73
|
+
side: this.rand() > 0.5 ? 'L' : 'R'
|
|
74
|
+
});
|
|
75
|
+
if (state !== 'speaking') this.speechLevel = 0;
|
|
76
|
+
}
|
|
77
|
+
getState() {
|
|
78
|
+
return this.state;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Oriente le regard (radians, relatif au corps) : `yaw` > 0 vers la gauche du robot (+x),
|
|
82
|
+
* `pitch` > 0 vers le haut. `null` rend la main aux regards spontanés.
|
|
83
|
+
*/ setGaze(gaze) {
|
|
84
|
+
this.gazeManual = gaze ? {
|
|
85
|
+
yaw: gaze.yaw,
|
|
86
|
+
pitch: gaze.pitch
|
|
87
|
+
} : null;
|
|
88
|
+
}
|
|
89
|
+
/** Marche jusqu'à (x, z) en mètres. Résolu à l'arrivée ; une nouvelle commande interrompt la précédente. */ walkTo(x, z, options = {}) {
|
|
90
|
+
this.walkTarget?.resolve();
|
|
91
|
+
return new Promise((resolve)=>{
|
|
92
|
+
this.walkTarget = {
|
|
93
|
+
x,
|
|
94
|
+
z,
|
|
95
|
+
arriveYaw: options.arriveYaw ?? null,
|
|
96
|
+
resolve
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
stopWalking() {
|
|
101
|
+
this.walkTarget?.resolve();
|
|
102
|
+
this.walkTarget = null;
|
|
103
|
+
}
|
|
104
|
+
get isWalking() {
|
|
105
|
+
return this.walkTarget !== null || this.walkBlend > 0.05;
|
|
106
|
+
}
|
|
107
|
+
/** Tourne sur place vers le cap `yaw` (rad). */ async turnTo(yaw) {
|
|
108
|
+
await this.walkTo(this.root.x, this.root.z, {
|
|
109
|
+
arriveYaw: yaw
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/** Tend la main `side` vers un point (repère du robot, m), `null` pour relâcher. */ reachAt(side, target) {
|
|
113
|
+
const r = this.reach[side];
|
|
114
|
+
r.active = target !== null;
|
|
115
|
+
if (target) r.target = [
|
|
116
|
+
...target
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
/** Convertit un point de la scène (x, y, z) en repère du robot (origine aux pieds, +z devant lui). */ toRobotFrame(x, y, z) {
|
|
120
|
+
const dx = x - this.root.x;
|
|
121
|
+
const dz = z - this.root.z;
|
|
122
|
+
const c = Math.cos(this.root.yaw);
|
|
123
|
+
const s = Math.sin(this.root.yaw);
|
|
124
|
+
return [
|
|
125
|
+
dx * c - dz * s,
|
|
126
|
+
y - this.root.lift,
|
|
127
|
+
dx * s + dz * c
|
|
128
|
+
];
|
|
129
|
+
}
|
|
130
|
+
/** Tend le bras `side` vers un point (repère du robot) et pointe l'index ; `null` relâche. */ pointAt(side, target) {
|
|
131
|
+
this.reachAt(side, target);
|
|
132
|
+
this.setHand(side, target ? 'point' : null);
|
|
133
|
+
}
|
|
134
|
+
/** Force la forme d'une main ; `null` rend la main aux gestes. */ setHand(side, shape) {
|
|
135
|
+
this.handManual[side] = shape ? resolveShape(shape) : null;
|
|
136
|
+
}
|
|
137
|
+
// ------------------------------------------------------------ mise à jour
|
|
138
|
+
update(rawDt) {
|
|
139
|
+
const dt = Math.min(0.05, Math.max(0, rawDt));
|
|
140
|
+
if (dt === 0) return;
|
|
141
|
+
this.time += dt;
|
|
142
|
+
this.runAutoBehaviors();
|
|
143
|
+
this.advancePlayers(dt);
|
|
144
|
+
const t = this.target;
|
|
145
|
+
for (const n of JOINT_NAMES){
|
|
146
|
+
const r = REST_POSE[n];
|
|
147
|
+
t[n][0] = r[0];
|
|
148
|
+
t[n][1] = r[1];
|
|
149
|
+
t[n][2] = r[2];
|
|
150
|
+
}
|
|
151
|
+
this.applyStateStance(t);
|
|
152
|
+
this.updateLocomotion(dt);
|
|
153
|
+
this.applyGait(t);
|
|
154
|
+
let lift = 0;
|
|
155
|
+
const handVotes = {};
|
|
156
|
+
for (const p of this.players){
|
|
157
|
+
const w = clipWeight(p.clip, p.time, p.stopping, p.stopTime);
|
|
158
|
+
if (w <= 0) continue;
|
|
159
|
+
const s = sampleClip(p.clip, p.time);
|
|
160
|
+
for (const [n, v] of Object.entries(s.pose)){
|
|
161
|
+
const c = t[n];
|
|
162
|
+
c[0] += (v[0] - c[0]) * w;
|
|
163
|
+
c[1] += (v[1] - c[1]) * w;
|
|
164
|
+
c[2] += (v[2] - c[2]) * w;
|
|
165
|
+
}
|
|
166
|
+
lift += s.lift * w;
|
|
167
|
+
if (w > 0.3) Object.assign(handVotes, s.hands);
|
|
168
|
+
}
|
|
169
|
+
this.applyAdditive(t, dt);
|
|
170
|
+
for (const n of JOINT_NAMES){
|
|
171
|
+
const goal = clampToLimits(n, t[n]);
|
|
172
|
+
const cur = this.pose[n];
|
|
173
|
+
const lambda = n.startsWith('hips') ? 20 : 16;
|
|
174
|
+
cur[0] = damp(cur[0], goal[0], lambda, dt);
|
|
175
|
+
cur[1] = damp(cur[1], goal[1], lambda, dt);
|
|
176
|
+
cur[2] = damp(cur[2], goal[2], lambda, dt);
|
|
177
|
+
}
|
|
178
|
+
this.updateHands(dt, handVotes);
|
|
179
|
+
this.root.lift = damp(this.root.lift, lift + this.walkBob(), 24, dt);
|
|
180
|
+
for (const side of [
|
|
181
|
+
'L',
|
|
182
|
+
'R'
|
|
183
|
+
]){
|
|
184
|
+
const r = this.reach[side];
|
|
185
|
+
r.weight = damp(r.weight, r.active ? 1 : 0, 7, dt);
|
|
186
|
+
if (!r.active && r.weight < 0.005) {
|
|
187
|
+
r.weight = 0;
|
|
188
|
+
r.target = null;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
this.updateBlink();
|
|
192
|
+
}
|
|
193
|
+
// ------------------------------------------------------------ internes
|
|
194
|
+
start(def, priority, options) {
|
|
195
|
+
for (const p of this.players)if (p.priority <= priority) this.beginStop(p);
|
|
196
|
+
const clip = compileClip(options.loop ? {
|
|
197
|
+
...def,
|
|
198
|
+
loop: true
|
|
199
|
+
} : def);
|
|
200
|
+
return new Promise((resolve)=>{
|
|
201
|
+
this.players.push({
|
|
202
|
+
id: this.nextId++,
|
|
203
|
+
clip,
|
|
204
|
+
time: 0,
|
|
205
|
+
speed: options.speed ?? 1,
|
|
206
|
+
stopping: false,
|
|
207
|
+
stopTime: 0,
|
|
208
|
+
priority,
|
|
209
|
+
resolve,
|
|
210
|
+
loopOverride: !!options.loop
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
beginStop(p) {
|
|
215
|
+
if (p.stopping) return;
|
|
216
|
+
p.stopping = true;
|
|
217
|
+
p.stopTime = p.time;
|
|
218
|
+
if (p.clip.fadeOut <= 0) p.clip.fadeOut = 0.15;
|
|
219
|
+
}
|
|
220
|
+
advancePlayers(dt) {
|
|
221
|
+
for (const p of this.players){
|
|
222
|
+
p.time += dt * p.speed;
|
|
223
|
+
const ended = p.stopping ? p.time - p.stopTime >= p.clip.fadeOut : !p.clip.loop && p.time >= p.clip.duration;
|
|
224
|
+
if (ended) p.resolve();
|
|
225
|
+
}
|
|
226
|
+
this.players = this.players.filter((p)=>{
|
|
227
|
+
const ended = p.stopping ? p.time - p.stopTime >= p.clip.fadeOut : !p.clip.loop && p.time >= p.clip.duration;
|
|
228
|
+
return !ended;
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
runAutoBehaviors() {
|
|
232
|
+
if (!this.autoBehaviors) return;
|
|
233
|
+
const now = this.time;
|
|
234
|
+
if (this.state === 'speaking' && !this.isGesturing && now >= this.nextTalkAt) {
|
|
235
|
+
const name = TALK_GESTURES[Math.floor(this.rand() * TALK_GESTURES.length)];
|
|
236
|
+
const side = this.rand() > 0.5 ? 'L' : 'R';
|
|
237
|
+
const def = resolveGesture(name, side);
|
|
238
|
+
void this.start(def, 0, {
|
|
239
|
+
speed: 0.9 + this.rand() * 0.3
|
|
240
|
+
});
|
|
241
|
+
this.nextTalkAt = now + def.duration + 0.2 + this.rand() * 1.1;
|
|
242
|
+
}
|
|
243
|
+
if (this.state === 'thinking' && !this.players.some((p)=>!p.stopping && p.clip.name === 'think') && this.rand() < 0.02) {
|
|
244
|
+
this.play('think', {
|
|
245
|
+
side: this.rand() > 0.5 ? 'L' : 'R'
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
if (this.state === 'listening' && !this.isGesturing && now >= this.nextNodAt) {
|
|
249
|
+
void this.start(resolveGesture('nod'), 0, {
|
|
250
|
+
speed: 0.85
|
|
251
|
+
});
|
|
252
|
+
this.nextNodAt = now + 2.8 + this.rand() * 3;
|
|
253
|
+
}
|
|
254
|
+
if (!this.gazeManual && now >= this.nextGlanceAt) {
|
|
255
|
+
const calm = this.state === 'speaking' || this.state === 'listening';
|
|
256
|
+
this.gazeGoal = {
|
|
257
|
+
yaw: (this.rand() - 0.5) * (calm ? 0.25 : 0.7),
|
|
258
|
+
pitch: (this.rand() - 0.5) * 0.25
|
|
259
|
+
};
|
|
260
|
+
this.nextGlanceAt = now + 1.6 + this.rand() * 3;
|
|
261
|
+
}
|
|
262
|
+
if (now >= this.nextBlinkAt) {
|
|
263
|
+
this.blinkStart = now;
|
|
264
|
+
this.nextBlinkAt = now + 2.2 + this.rand() * 3.8;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
updateBlink() {
|
|
268
|
+
const bt = this.time - this.blinkStart;
|
|
269
|
+
let b = 0;
|
|
270
|
+
if (bt >= 0 && bt < 0.055) b = bt / 0.055;
|
|
271
|
+
else if (bt < 0.1) b = 1;
|
|
272
|
+
else if (bt < 0.18) b = 1 - (bt - 0.1) / 0.08;
|
|
273
|
+
this.blink = b;
|
|
274
|
+
}
|
|
275
|
+
applyStateStance(t) {
|
|
276
|
+
if (this.state === 'listening') {
|
|
277
|
+
t.head[2] += 0.1;
|
|
278
|
+
t.neck[0] += 0.03;
|
|
279
|
+
t.spine[0] += 0.06;
|
|
280
|
+
} else if (this.state === 'thinking') {
|
|
281
|
+
t.head[0] += -0.05;
|
|
282
|
+
t.head[1] += 0.12;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
updateLocomotion(dt) {
|
|
286
|
+
const w = this.walkTarget;
|
|
287
|
+
const yawBefore = this.root.yaw;
|
|
288
|
+
let moving = false;
|
|
289
|
+
if (w) {
|
|
290
|
+
const dx = w.x - this.root.x;
|
|
291
|
+
const dz = w.z - this.root.z;
|
|
292
|
+
const dist = Math.hypot(dx, dz);
|
|
293
|
+
if (dist > 0.04) {
|
|
294
|
+
const want = Math.atan2(dx, dz);
|
|
295
|
+
const err = wrapAngle(want - this.root.yaw);
|
|
296
|
+
this.root.yaw += Math.max(-TURN_RATE * dt, Math.min(TURN_RATE * dt, err));
|
|
297
|
+
const facing = smoothstep(1 - Math.abs(wrapAngle(want - this.root.yaw)) / 0.9);
|
|
298
|
+
const v = Math.min(MAX_SPEED, 0.25 + dist * 1.6) * facing;
|
|
299
|
+
this.speed = damp(this.speed, v, 8, dt);
|
|
300
|
+
const step = Math.min(this.speed * dt, dist);
|
|
301
|
+
this.root.x += Math.sin(this.root.yaw) * step;
|
|
302
|
+
this.root.z += Math.cos(this.root.yaw) * step;
|
|
303
|
+
moving = this.speed > 0.05;
|
|
304
|
+
} else if (w.arriveYaw !== null) {
|
|
305
|
+
const err = wrapAngle(w.arriveYaw - this.root.yaw);
|
|
306
|
+
if (Math.abs(err) > 0.03) {
|
|
307
|
+
this.root.yaw += Math.max(-TURN_RATE * dt, Math.min(TURN_RATE * dt, err));
|
|
308
|
+
} else {
|
|
309
|
+
this.finishWalk();
|
|
310
|
+
}
|
|
311
|
+
this.speed = damp(this.speed, 0, 8, dt);
|
|
312
|
+
} else {
|
|
313
|
+
this.finishWalk();
|
|
314
|
+
this.speed = damp(this.speed, 0, 8, dt);
|
|
315
|
+
}
|
|
316
|
+
} else {
|
|
317
|
+
this.speed = damp(this.speed, 0, 8, dt);
|
|
318
|
+
}
|
|
319
|
+
// Tourner sur place fait faire de petits pas : la vitesse de rotation compte comme un déplacement.
|
|
320
|
+
this.yawRate = wrapAngle(this.root.yaw - yawBefore) / dt;
|
|
321
|
+
const turning = Math.abs(this.yawRate) > 0.5;
|
|
322
|
+
this.walkBlend = damp(this.walkBlend, moving || turning ? 1 : 0, 6, dt);
|
|
323
|
+
if (this.walkBlend > 0.01) {
|
|
324
|
+
const travelled = this.speed * dt + (turning ? Math.abs(this.yawRate) * dt * 0.1 : 0);
|
|
325
|
+
this.walkPhase += travelled / STRIDE * Math.PI * 2;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
finishWalk() {
|
|
329
|
+
const w = this.walkTarget;
|
|
330
|
+
this.walkTarget = null;
|
|
331
|
+
w?.resolve();
|
|
332
|
+
}
|
|
333
|
+
walkBob() {
|
|
334
|
+
return this.walkBlend * 0.018 * Math.abs(Math.sin(this.walkPhase));
|
|
335
|
+
}
|
|
336
|
+
applyGait(t) {
|
|
337
|
+
const b = this.walkBlend;
|
|
338
|
+
if (b < 0.01) return;
|
|
339
|
+
const ph = this.walkPhase;
|
|
340
|
+
const s = Math.sin(ph);
|
|
341
|
+
const c = Math.cos(ph);
|
|
342
|
+
const effective = this.speed + Math.abs(this.yawRate) * 0.1;
|
|
343
|
+
const amp = 0.5 * Math.min(1, 0.4 + effective / MAX_SPEED);
|
|
344
|
+
const mix = (j, v)=>{
|
|
345
|
+
const a = t[j];
|
|
346
|
+
a[0] += (v[0] - a[0]) * b;
|
|
347
|
+
a[1] += (v[1] - a[1]) * b;
|
|
348
|
+
a[2] += (v[2] - a[2]) * b;
|
|
349
|
+
};
|
|
350
|
+
for (const side of [
|
|
351
|
+
'L',
|
|
352
|
+
'R'
|
|
353
|
+
]){
|
|
354
|
+
const sg = side === 'L' ? 1 : -1;
|
|
355
|
+
const m = side === 'L' ? 1 : -1;
|
|
356
|
+
const phase = sg * s;
|
|
357
|
+
const swing = sg * c;
|
|
358
|
+
const hipX = -amp * phase;
|
|
359
|
+
const kneeX = 0.12 + 0.85 * Math.max(0, swing) * (amp / 0.5);
|
|
360
|
+
mix(`hip${side}`, [
|
|
361
|
+
hipX,
|
|
362
|
+
0,
|
|
363
|
+
m * 0.03
|
|
364
|
+
]);
|
|
365
|
+
mix(`knee${side}`, [
|
|
366
|
+
kneeX,
|
|
367
|
+
0,
|
|
368
|
+
0
|
|
369
|
+
]);
|
|
370
|
+
mix(`ankle${side}`, [
|
|
371
|
+
-(hipX + kneeX) * 0.8,
|
|
372
|
+
0,
|
|
373
|
+
0
|
|
374
|
+
]);
|
|
375
|
+
mix(`shoulder${side}`, [
|
|
376
|
+
amp * 0.8 * phase,
|
|
377
|
+
0,
|
|
378
|
+
m * 0.1
|
|
379
|
+
]);
|
|
380
|
+
mix(`elbow${side}`, [
|
|
381
|
+
-0.28 - 0.3 * Math.max(0, -phase),
|
|
382
|
+
0,
|
|
383
|
+
0
|
|
384
|
+
]);
|
|
385
|
+
}
|
|
386
|
+
mix('spine', [
|
|
387
|
+
0.05,
|
|
388
|
+
-0.1 * s,
|
|
389
|
+
0
|
|
390
|
+
]);
|
|
391
|
+
mix('chest', [
|
|
392
|
+
0,
|
|
393
|
+
0.14 * s,
|
|
394
|
+
0
|
|
395
|
+
]);
|
|
396
|
+
mix('hips', [
|
|
397
|
+
0,
|
|
398
|
+
0.1 * s,
|
|
399
|
+
0.03 * c
|
|
400
|
+
]);
|
|
401
|
+
}
|
|
402
|
+
applyAdditive(t, dt) {
|
|
403
|
+
const time = this.time;
|
|
404
|
+
// Respiration et petit balancement : le corps ne reste jamais figé.
|
|
405
|
+
const breath = Math.sin(time * 1.55);
|
|
406
|
+
t.chest[0] += breath * 0.014;
|
|
407
|
+
t.spine[0] += breath * 0.008;
|
|
408
|
+
t.shoulderL[2] += breath * 0.012;
|
|
409
|
+
t.shoulderR[2] -= breath * 0.012;
|
|
410
|
+
t.hips[1] += Math.sin(time * 0.43) * 0.025 * (1 - this.walkBlend);
|
|
411
|
+
t.hips[2] += Math.sin(time * 0.31 + 0.7) * 0.012 * (1 - this.walkBlend); // transfert de poids d'un pied sur l'autre
|
|
412
|
+
t.head[2] += Math.sin(time * 0.71 + 1.1) * 0.014;
|
|
413
|
+
// Voix : la tête accompagne le volume.
|
|
414
|
+
if (this.state === 'speaking') {
|
|
415
|
+
const k = 0.02 + this.speechLevel * 0.1;
|
|
416
|
+
t.head[0] += Math.sin(time * 7.3) * k * 0.6 + Math.sin(time * 3.1) * k;
|
|
417
|
+
t.head[1] += Math.sin(time * 2.3) * k * 1.5;
|
|
418
|
+
}
|
|
419
|
+
// Regard : le goal est soit imposé, soit spontané.
|
|
420
|
+
const goal = this.gazeManual ?? this.gazeGoal;
|
|
421
|
+
this.gaze.yaw = damp(this.gaze.yaw, goal.yaw, 9, dt);
|
|
422
|
+
this.gaze.pitch = damp(this.gaze.pitch, goal.pitch, 9, dt);
|
|
423
|
+
const { yaw, pitch } = this.gaze;
|
|
424
|
+
t.head[1] += yaw * 0.55;
|
|
425
|
+
t.neck[1] += yaw * 0.3;
|
|
426
|
+
t.chest[1] += yaw * 0.12;
|
|
427
|
+
t.head[0] += -pitch * 0.6;
|
|
428
|
+
t.neck[0] += -pitch * 0.3;
|
|
429
|
+
}
|
|
430
|
+
updateHands(dt, votes) {
|
|
431
|
+
for (const side of [
|
|
432
|
+
'L',
|
|
433
|
+
'R'
|
|
434
|
+
]){
|
|
435
|
+
const goal = this.handManual[side] ?? (votes[side] ? HAND_SHAPES[votes[side]] : HAND_SHAPES.relaxed);
|
|
436
|
+
this.handGoal[side] = goal;
|
|
437
|
+
const h = this.hand[side];
|
|
438
|
+
for(let i = 0; i < 5; i++)h.curl[i] = damp(h.curl[i], goal.curl[i], 18, dt);
|
|
439
|
+
h.thumbOut = damp(h.thumbOut, goal.thumbOut, 18, dt);
|
|
440
|
+
const p = handPose(side, h.curl, h.thumbOut);
|
|
441
|
+
for (const [n, v] of Object.entries(p)){
|
|
442
|
+
this.pose[n][0] = v[0];
|
|
443
|
+
this.pose[n][1] = v[1];
|
|
444
|
+
this.pose[n][2] = v[2];
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
constructor(options = {}){
|
|
449
|
+
/** Angles lissés de toutes les articulations, prêts à être appliqués au rendu. */ _define_property(this, "pose", createRestPose());
|
|
450
|
+
/** Position (m) et cap (rad) du robot sur le sol ; `lift` = hauteur de saut (m). */ _define_property(this, "root", {
|
|
451
|
+
x: 0,
|
|
452
|
+
z: 0,
|
|
453
|
+
yaw: 0,
|
|
454
|
+
lift: 0
|
|
455
|
+
});
|
|
456
|
+
/** Fermeture des paupières, 0 (ouvert) à 1 (fermé). */ _define_property(this, "blink", 0);
|
|
457
|
+
/** Niveau sonore de la voix, 0..1 : amplifie les mouvements de tête quand l'assistant parle. */ _define_property(this, "speechLevel", 0);
|
|
458
|
+
/** Cibles d'atteinte des mains (repère du robot, mètres). Résolues par IK dans le rendu. */ _define_property(this, "reach", {
|
|
459
|
+
L: {
|
|
460
|
+
target: null,
|
|
461
|
+
weight: 0,
|
|
462
|
+
active: false
|
|
463
|
+
},
|
|
464
|
+
R: {
|
|
465
|
+
target: null,
|
|
466
|
+
weight: 0,
|
|
467
|
+
active: false
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
_define_property(this, "state", 'idle');
|
|
471
|
+
_define_property(this, "time", 0);
|
|
472
|
+
_define_property(this, "rand", void 0);
|
|
473
|
+
_define_property(this, "autoBehaviors", void 0);
|
|
474
|
+
_define_property(this, "players", []);
|
|
475
|
+
_define_property(this, "nextId", 1);
|
|
476
|
+
_define_property(this, "target", createRestPose());
|
|
477
|
+
_define_property(this, "gazeManual", null);
|
|
478
|
+
_define_property(this, "gazeGoal", {
|
|
479
|
+
yaw: 0,
|
|
480
|
+
pitch: 0
|
|
481
|
+
});
|
|
482
|
+
_define_property(this, "gaze", {
|
|
483
|
+
yaw: 0,
|
|
484
|
+
pitch: 0
|
|
485
|
+
});
|
|
486
|
+
_define_property(this, "nextGlanceAt", 1.5);
|
|
487
|
+
_define_property(this, "nextBlinkAt", 2);
|
|
488
|
+
_define_property(this, "blinkStart", -10);
|
|
489
|
+
_define_property(this, "nextTalkAt", 0);
|
|
490
|
+
_define_property(this, "nextNodAt", 3);
|
|
491
|
+
_define_property(this, "walkTarget", null);
|
|
492
|
+
_define_property(this, "walkBlend", 0);
|
|
493
|
+
_define_property(this, "walkPhase", 0);
|
|
494
|
+
_define_property(this, "speed", 0);
|
|
495
|
+
_define_property(this, "yawRate", 0);
|
|
496
|
+
_define_property(this, "handManual", {
|
|
497
|
+
L: null,
|
|
498
|
+
R: null
|
|
499
|
+
});
|
|
500
|
+
_define_property(this, "handGoal", {
|
|
501
|
+
L: HAND_SHAPES.relaxed,
|
|
502
|
+
R: HAND_SHAPES.relaxed
|
|
503
|
+
});
|
|
504
|
+
_define_property(this, "hand", {
|
|
505
|
+
L: {
|
|
506
|
+
curl: [
|
|
507
|
+
...HAND_SHAPES.relaxed.curl
|
|
508
|
+
],
|
|
509
|
+
thumbOut: HAND_SHAPES.relaxed.thumbOut
|
|
510
|
+
},
|
|
511
|
+
R: {
|
|
512
|
+
curl: [
|
|
513
|
+
...HAND_SHAPES.relaxed.curl
|
|
514
|
+
],
|
|
515
|
+
thumbOut: HAND_SHAPES.relaxed.thumbOut
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
this.rand = mulberry32(options.seed ?? 1);
|
|
519
|
+
this.autoBehaviors = options.autoBehaviors ?? true;
|
|
520
|
+
this.nextBlinkAt = 1.5 + this.rand() * 2;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ClipDef } from './clips.js';
|
|
2
|
+
import type { Side } from './skeleton.js';
|
|
3
|
+
/**
|
|
4
|
+
* Bibliothèque de gestes.
|
|
5
|
+
*
|
|
6
|
+
* Chaque geste est écrit pour le bras GAUCHE (côté +x). `play('wave', { side: 'R' })`
|
|
7
|
+
* le rejoue avec le bras droit grâce à `mirrorClip`. Les gestes à deux bras (`sided: false`)
|
|
8
|
+
* contiennent déjà les deux côtés.
|
|
9
|
+
*
|
|
10
|
+
* Pour ajouter un geste : décrire quelques poses clés (angles en radians, voir skeleton.ts)
|
|
11
|
+
* et l'enregistrer dans `GESTURE_LIBRARY` — rien d'autre à modifier.
|
|
12
|
+
*/
|
|
13
|
+
export type GestureName = 'wave' | 'greet' | 'nod' | 'shakeHead' | 'tiltHead' | 'point' | 'thumbsUp' | 'openArms' | 'shrug' | 'think' | 'clap' | 'bow' | 'celebrate' | 'present' | 'talkA' | 'talkB' | 'talkC';
|
|
14
|
+
export interface GestureEntry {
|
|
15
|
+
def: ClipDef;
|
|
16
|
+
/** `true` : écrit pour un seul bras, peut être joué à gauche ou à droite. */
|
|
17
|
+
sided: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare const GESTURE_LIBRARY: Record<GestureName, GestureEntry>;
|
|
20
|
+
export declare const GESTURE_NAMES: GestureName[];
|
|
21
|
+
export declare const TALK_GESTURES: GestureName[];
|
|
22
|
+
export declare function resolveGesture(name: GestureName, side?: Side): ClipDef;
|
|
23
|
+
//# sourceMappingURL=gestures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gestures.d.ts","sourceRoot":"","sources":["../../../src/assistant/robot/gestures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,OAAO,EAAgB,MAAM,YAAY,CAAC;AACpE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C;;;;;;;;;GASG;AAEH,MAAM,MAAM,WAAW,GACnB,MAAM,GACN,OAAO,GACP,KAAK,GACL,WAAW,GACX,UAAU,GACV,OAAO,GACP,UAAU,GACV,UAAU,GACV,OAAO,GACP,OAAO,GACP,MAAM,GACN,KAAK,GACL,WAAW,GACX,SAAS,GACT,OAAO,GACP,OAAO,GACP,OAAO,CAAC;AAEZ,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,OAAO,CAAC;IACb,6EAA6E;IAC7E,KAAK,EAAE,OAAO,CAAC;CAChB;AAoYD,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,WAAW,EAAE,YAAY,CAkB7D,CAAC;AAEF,eAAO,MAAM,aAAa,EAAmC,WAAW,EAAE,CAAC;AAC3E,eAAO,MAAM,aAAa,EAAE,WAAW,EAAgC,CAAC;AAExE,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,GAAE,IAAU,GAAG,OAAO,CAG3E"}
|