@davi-ai/retorik-framework 4.0.0 → 4.0.2

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.
@@ -0,0 +1,649 @@
1
+ import {jsxs as $313pz$jsxs, jsx as $313pz$jsx} from "react/jsx-runtime";
2
+ import $313pz$react, {useState as $313pz$useState, useMemo as $313pz$useMemo, useEffect as $313pz$useEffect, useRef as $313pz$useRef} from "react";
3
+ import {CreationTool as $313pz$CreationTool, Object3D as $313pz$Object3D, addViseme as $313pz$addViseme, setVisemes as $313pz$setVisemes, setCharacterState as $313pz$setCharacterState, CharacterState as $313pz$CharacterState, flushLipSyncData as $313pz$flushLipSyncData, Character as $313pz$Character, presets as $313pz$presets, getCameraPosition as $313pz$getCameraPosition, getCharacterHeight as $313pz$getCharacterHeight, setLookAtCamera as $313pz$setLookAtCamera, setShowFirstTarget as $313pz$setShowFirstTarget} from "@davi-ai/react-bodyengine-three";
4
+ import {useDispatch as $313pz$useDispatch, useSelector as $313pz$useSelector} from "react-redux";
5
+ import {FilesetResolver as $313pz$FilesetResolver, FaceDetector as $313pz$FaceDetector} from "@mediapipe/tasks-vision";
6
+
7
+
8
+ function $parcel$defineInteropFlag(a) {
9
+ Object.defineProperty(a, '__esModule', {value: true, configurable: true});
10
+ }
11
+
12
+ function $parcel$export(e, n, v, s) {
13
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
14
+ }
15
+
16
+ var $parcel$global = globalThis;
17
+ var parcelRequire = $parcel$global["parcelRequirea39d"];
18
+ var parcelRegister = parcelRequire.register;
19
+ parcelRegister("4UN3k", function(module, exports) {
20
+
21
+ $parcel$defineInteropFlag(module.exports);
22
+
23
+ $parcel$export(module.exports, "default", () => $22f0b0bb3c6ec1e7$export$2e2bcd8739ae039);
24
+
25
+
26
+
27
+
28
+
29
+ var $8ItUL = parcelRequire("8ItUL");
30
+
31
+ var $4ucVo = parcelRequire("4ucVo");
32
+
33
+ var $7MbNn = parcelRequire("7MbNn");
34
+
35
+ var $gFkoW = parcelRequire("gFkoW");
36
+ const $22f0b0bb3c6ec1e7$var$ThreeJsWrapper = ({ agentData: agentData, visible: visible, height: height, size: size, cameraPreset: cameraPreset, calibration: calibration, centered: centered })=>{
37
+ const dispatch = (0, $313pz$useDispatch)();
38
+ const gpuData = (0, $313pz$useSelector)((state)=>state.retorikReducer.gpuData);
39
+ const speaking = (0, $313pz$useSelector)((state)=>state.speechReducer.speaking);
40
+ const loaderClosed = (0, $313pz$useSelector)((state)=>state.retorikReducer.loaderClosed);
41
+ const recognitionState = (0, $313pz$useSelector)((state)=>state.speechReducer.activeRecognitionState);
42
+ const lastRecognitionInterim = (0, $313pz$useSelector)((state)=>state.speechReducer.lastRecognitionInterim);
43
+ const singleViseme = (0, $313pz$useSelector)((state)=>state.speechReducer.singleVisemeAdded);
44
+ const multiVisemes = (0, $313pz$useSelector)((state)=>state.speechReducer.multiVisemesAdded);
45
+ const streamingQueue = (0, $313pz$useSelector)((state)=>state.speechReducer.streamingQueue);
46
+ const characterLoaded = (0, $313pz$useSelector)((state)=>state.viewReducer.characterLoaded);
47
+ const isMobile = (0, $313pz$useSelector)((state)=>state.viewReducer.isMobile);
48
+ const [targets, setTargets] = (0, $313pz$useState)([]);
49
+ const [dynamicData, setDynamicData] = (0, $313pz$useState)(undefined);
50
+ const [openCalibration, setOpenCalibration] = (0, $313pz$useState)(false);
51
+ /**
52
+ * Use model's source to get the right loader. Default to avaturn loader
53
+ */ const type = (0, $313pz$useMemo)(()=>{
54
+ if (agentData.source) switch(agentData.source.toLowerCase()){
55
+ case (0, $4ucVo.Source3DEngine).avatarsdk:
56
+ case (0, $4ucVo.Source3DEngine).avatarsdkbis:
57
+ return (0, $313pz$CreationTool).avatarsdk;
58
+ case (0, $4ucVo.Source3DEngine).cc3:
59
+ case (0, $4ucVo.Source3DEngine).cc4:
60
+ return (0, $313pz$CreationTool).cc3;
61
+ case (0, $4ucVo.Source3DEngine).rpm:
62
+ case (0, $4ucVo.Source3DEngine).readyplayerme:
63
+ return (0, $313pz$CreationTool).rpm;
64
+ case (0, $4ucVo.Source3DEngine).avaturn:
65
+ default:
66
+ return (0, $313pz$CreationTool).avaturn;
67
+ }
68
+ return (0, $313pz$CreationTool).avaturn;
69
+ }, [
70
+ agentData
71
+ ]);
72
+ (0, $313pz$useEffect)(()=>{
73
+ if (!calibration?.static?.enabled && !calibration?.dynamic?.enabled || isMobile) dispatch((0, $8ItUL.storeActions).view.setCalibrationCompleted(true));
74
+ }, [
75
+ calibration,
76
+ isMobile
77
+ ]);
78
+ (0, $313pz$useEffect)(()=>{
79
+ // Check if we should open the calibration screen or not
80
+ if ((calibration?.static?.enabled || calibration?.dynamic?.enabled) && !isMobile) {
81
+ // If there are some static data in the props or the local storage, we can directly set the targets without opening the calibration screen
82
+ if (calibration?.static?.enabled && calibration.static.staticTarget) {
83
+ const o = new (0, $313pz$Object3D)();
84
+ o.position.set(calibration.static.staticTarget.x, calibration.static.staticTarget.y, calibration.static.staticTarget.z);
85
+ setTargets([
86
+ o
87
+ ]);
88
+ setOpenCalibration(false);
89
+ dispatch((0, $8ItUL.storeActions).view.setCalibrationCompleted(true));
90
+ } else if (calibration?.static?.enabled && calibration.static.loadStaticTargetFromLocalStorage && localStorage.getItem('Retorik.Framework.Static.Target')) {
91
+ const calibrationData = JSON.parse(localStorage.getItem('Retorik.Framework.Static.Target') || '{}');
92
+ const o = new (0, $313pz$Object3D)();
93
+ o.position.set(calibrationData.x, calibrationData.y, calibrationData.z);
94
+ setTargets([
95
+ o
96
+ ]);
97
+ setOpenCalibration(false);
98
+ dispatch((0, $8ItUL.storeActions).view.setCalibrationCompleted(true));
99
+ } else if (calibration.dynamic?.enabled && calibration.dynamic.dynamicData) {
100
+ // Check if all the mandatory dynamic data are in the props
101
+ if (calibration.dynamic.dynamicData.webcamHeight && calibration.dynamic.dynamicData.ratioPixelToCentimeter && calibration.dynamic.dynamicData.deltaAgentHeightAgentWorldHeightInCentimeters && calibration.dynamic.dynamicData.distanceFromAgentToCameraInCentimeters) setDynamicData({
102
+ ...calibration.dynamic.dynamicData,
103
+ cameraRotationInDegrees: calibration.dynamic.dynamicData.cameraRotationInDegrees || 0
104
+ });
105
+ setOpenCalibration(true);
106
+ } else if (calibration.dynamic?.enabled && calibration.dynamic.loadDynamicDataFromLocalStorage && localStorage.getItem('Retorik.Framework.Dynamic.Data')) {
107
+ // Check if the local storage data is complete
108
+ const calibrationData = JSON.parse(localStorage.getItem('Retorik.Framework.Dynamic.Data') || '{}');
109
+ if (calibrationData.webcamHeight && calibrationData.ratioPixelToCentimeter && calibrationData.deltaAgentHeightAgentWorldHeightInCentimeters && calibrationData.distanceFromAgentToCameraInCentimeters) setDynamicData({
110
+ ...calibrationData,
111
+ cameraRotationInDegrees: calibrationData.cameraRotationInDegrees || 0
112
+ });
113
+ setOpenCalibration(true);
114
+ } else setOpenCalibration(true);
115
+ } else {
116
+ setOpenCalibration(false);
117
+ dispatch((0, $8ItUL.storeActions).view.setCalibrationCompleted(true));
118
+ }
119
+ }, [
120
+ calibration,
121
+ isMobile
122
+ ]);
123
+ (0, $313pz$useEffect)(()=>{
124
+ singleViseme && (0, $313pz$addViseme)(singleViseme);
125
+ }, [
126
+ singleViseme
127
+ ]);
128
+ (0, $313pz$useEffect)(()=>{
129
+ multiVisemes.length && (0, $313pz$setVisemes)(multiVisemes);
130
+ }, [
131
+ multiVisemes
132
+ ]);
133
+ (0, $313pz$useEffect)(()=>{
134
+ if (speaking || streamingQueue.length) (0, $313pz$setCharacterState)((0, $313pz$CharacterState).speaking);
135
+ else if (recognitionState === (0, $4ucVo.RecognitionState).Closed) (0, $313pz$setCharacterState)((0, $313pz$CharacterState).idle);
136
+ else if (lastRecognitionInterim) (0, $313pz$setCharacterState)((0, $313pz$CharacterState).listening);
137
+ else (0, $313pz$setCharacterState)((0, $313pz$CharacterState).waiting);
138
+ }, [
139
+ speaking,
140
+ recognitionState,
141
+ lastRecognitionInterim,
142
+ streamingQueue
143
+ ]);
144
+ (0, $313pz$useEffect)(()=>{
145
+ !speaking && (0, $313pz$flushLipSyncData)();
146
+ }, [
147
+ speaking
148
+ ]);
149
+ return /*#__PURE__*/ (0, $313pz$jsxs)((0, $313pz$react).Fragment, {
150
+ children: [
151
+ /*#__PURE__*/ (0, $313pz$jsx)("div", {
152
+ style: {
153
+ height: size || '100%',
154
+ paddingTop: height || 0,
155
+ visibility: characterLoaded && visible ? 'visible' : 'hidden'
156
+ },
157
+ children: type && /*#__PURE__*/ (0, $313pz$jsx)((0, $313pz$Character), {
158
+ url: agentData.url,
159
+ type: type,
160
+ animationsUrl: agentData?.animationsUrl || 'https://cdn.retorik.ai/bodyengine-three/animations/cc4/female/standing/',
161
+ gender: agentData?.gender === 'male' ? 'male' : 'female',
162
+ onLoadingCompleted: ()=>dispatch((0, $8ItUL.storeActions).view.setCharacterLoaded(true)),
163
+ camera: (0, $313pz$presets)[cameraPreset || 'default'],
164
+ targets: targets,
165
+ autoLookAt: true,
166
+ detectGpuData: gpuData,
167
+ license: "fake-license"
168
+ })
169
+ }),
170
+ !characterLoaded && /*#__PURE__*/ (0, $313pz$jsx)("div", {
171
+ className: "rf-absolute rf-top-0 rf-left-0 rf-w-full rf-h-full rf-flex rf-justify-center rf-items-center",
172
+ children: /*#__PURE__*/ (0, $313pz$jsx)("div", {
173
+ className: "rf-w-1/4 rf-aspect-square",
174
+ children: /*#__PURE__*/ (0, $313pz$jsx)((0, $7MbNn.default), {})
175
+ })
176
+ }),
177
+ openCalibration && loaderClosed && /*#__PURE__*/ (0, $313pz$jsx)((0, $gFkoW.default), {
178
+ centered: centered,
179
+ staticCalibrationEnabled: !!calibration?.static?.enabled,
180
+ dynamicCalibrationEnabled: !!calibration?.dynamic?.enabled,
181
+ setTargets: (targets)=>setTargets(targets),
182
+ dynamicData: dynamicData
183
+ })
184
+ ]
185
+ });
186
+ };
187
+ var $22f0b0bb3c6ec1e7$export$2e2bcd8739ae039 = $22f0b0bb3c6ec1e7$var$ThreeJsWrapper;
188
+
189
+ });
190
+ parcelRegister("gFkoW", function(module, exports) {
191
+
192
+ $parcel$export(module.exports, "default", () => $c6350b57d46149f8$export$2e2bcd8739ae039);
193
+
194
+
195
+
196
+
197
+
198
+ var $8ItUL = parcelRequire("8ItUL");
199
+
200
+ var $dJb7j = parcelRequire("dJb7j");
201
+ var $c6350b57d46149f8$var$CalibrationMode = /*#__PURE__*/ function(CalibrationMode) {
202
+ CalibrationMode[CalibrationMode["none"] = 1] = "none";
203
+ CalibrationMode[CalibrationMode["static"] = 2] = "static";
204
+ CalibrationMode[CalibrationMode["dynamic"] = 3] = "dynamic";
205
+ return CalibrationMode;
206
+ }($c6350b57d46149f8$var$CalibrationMode || {});
207
+ const $c6350b57d46149f8$var$CalibrationScreen = ({ centered: centered, staticCalibrationEnabled: staticCalibrationEnabled, dynamicCalibrationEnabled: dynamicCalibrationEnabled, dynamicData: dynamicData, setTargets: setTargets })=>{
208
+ const dispatch = (0, $313pz$useDispatch)();
209
+ const cameraPosition = (0, $313pz$getCameraPosition)();
210
+ const characterHeight = (0, $313pz$getCharacterHeight)();
211
+ const characterLoaded = (0, $313pz$useSelector)((state)=>state.viewReducer.characterLoaded);
212
+ const calibrationCompleted = (0, $313pz$useSelector)((state)=>state.viewReducer.calibrationCompleted);
213
+ const [calibrationMode, setCalibrationMode] = (0, $313pz$useState)(dynamicData ? 3 : 1);
214
+ const [distanceFromDevice, setDistanceFromDevice] = (0, $313pz$useState)(dynamicData?.distanceFromAgentToCameraInCentimeters || 0);
215
+ const [webcamRotation, setWebcamRotation] = (0, $313pz$useState)(0);
216
+ const [agentEyesHeightOnScreen, setAgentEyesHeightOnScreen] = (0, $313pz$useState)(0);
217
+ const [worldDistancePerDegree, setWorldDistancePerDegree] = (0, $313pz$useState)(0);
218
+ const [currentAngleInDegrees, setCurrentAngleInDegrees] = (0, $313pz$useState)(0);
219
+ const [cameraX, setCameraX] = (0, $313pz$useState)(0);
220
+ const [cameraY, setCameraY] = (0, $313pz$useState)(0);
221
+ const [cameraZ, setCameraZ] = (0, $313pz$useState)(0);
222
+ const cameraXRef = (0, $313pz$useRef)(0);
223
+ const cameraYRef = (0, $313pz$useRef)(0);
224
+ const cameraZRef = (0, $313pz$useRef)(0);
225
+ const currentAngleInDegreesRef = (0, $313pz$useRef)(0);
226
+ const webcamHeightRef = (0, $313pz$useRef)(dynamicData?.webcamHeight || 0);
227
+ const userEyesHeightRef = (0, $313pz$useRef)(0);
228
+ const agentEyesHeightRef = (0, $313pz$useRef)(0);
229
+ const distanceFromDeviceRef = (0, $313pz$useRef)(0);
230
+ const webcamRotatedRef = (0, $313pz$useRef)(dynamicData?.cameraRotationInDegrees || 0);
231
+ const deltaAgentHeightAgentWorldHeightInCentimetersRef = (0, $313pz$useRef)(dynamicData?.deltaAgentHeightAgentWorldHeightInCentimeters || 0);
232
+ const ratioPixelToCentimeterRef = (0, $313pz$useRef)(dynamicData?.ratioPixelToCentimeter || 0);
233
+ const calibrationCompletedRef = (0, $313pz$useRef)(calibrationCompleted);
234
+ const counterRef = (0, $313pz$useRef)(0);
235
+ (0, $313pz$useEffect)(()=>{
236
+ // If dynamic data are given, let's validate immediately to set calibratoin as completed
237
+ dynamicData && handleValidate();
238
+ }, []);
239
+ (0, $313pz$useEffect)(()=>{
240
+ characterLoaded && !dynamicData && (0, $313pz$setLookAtCamera)(true);
241
+ return ()=>{
242
+ (0, $313pz$setLookAtCamera)(false);
243
+ };
244
+ }, [
245
+ characterLoaded
246
+ ]);
247
+ (0, $313pz$useEffect)(()=>{
248
+ if (worldDistancePerDegree && !dynamicData) {
249
+ const o = new (0, $313pz$Object3D)();
250
+ o.position.set(cameraX, cameraY + currentAngleInDegrees * worldDistancePerDegree, Math.max(cameraZ / 5, 0.3));
251
+ setTargets([
252
+ o
253
+ ]);
254
+ }
255
+ }, [
256
+ currentAngleInDegrees,
257
+ worldDistancePerDegree,
258
+ distanceFromDevice,
259
+ cameraX,
260
+ cameraY,
261
+ cameraZ
262
+ ]);
263
+ (0, $313pz$useEffect)(()=>{
264
+ if (cameraPosition && !(cameraPosition.x === 0 && cameraPosition.y === 0)) {
265
+ const zDistanceCameraPlusUser = cameraPosition.z + distanceFromDevice / 100;
266
+ setCameraX(cameraPosition.x);
267
+ setCameraY(cameraPosition.y);
268
+ setCameraZ(zDistanceCameraPlusUser);
269
+ cameraXRef.current = cameraPosition.x;
270
+ cameraYRef.current = cameraPosition.y;
271
+ cameraZRef.current = zDistanceCameraPlusUser;
272
+ // Get Y world distance for one degree using tangent. The z distance is divided by 5 with 0.3 at the lowest to show a visible height bar when calibrating
273
+ setWorldDistancePerDegree(Math.tan(Math.PI / 180) * Math.max(zDistanceCameraPlusUser / 5, 0.3));
274
+ }
275
+ }, [
276
+ cameraPosition,
277
+ distanceFromDevice
278
+ ]);
279
+ (0, $313pz$useEffect)(()=>{
280
+ if (!dynamicData) characterHeight && agentEyesHeightOnScreen && (deltaAgentHeightAgentWorldHeightInCentimetersRef.current = (characterHeight - characterHeight / 16) * 100 - agentEyesHeightOnScreen);
281
+ }, [
282
+ characterHeight,
283
+ agentEyesHeightOnScreen
284
+ ]);
285
+ (0, $313pz$useEffect)(()=>{
286
+ !dynamicData && (webcamRotatedRef.current = webcamRotation);
287
+ }, [
288
+ webcamRotation
289
+ ]);
290
+ (0, $313pz$useEffect)(()=>{
291
+ calibrationCompletedRef.current = calibrationCompleted;
292
+ }, [
293
+ calibrationCompleted
294
+ ]);
295
+ (0, $313pz$useEffect)(()=>{
296
+ if (!dynamicData && calibrationMode === 2) (0, $313pz$setShowFirstTarget)(!calibrationCompleted);
297
+ }, [
298
+ calibrationMode,
299
+ calibrationCompleted
300
+ ]);
301
+ const handleReset = ()=>{
302
+ setCurrentAngleInDegrees(0);
303
+ currentAngleInDegreesRef.current = 0;
304
+ };
305
+ const handleValidate = ()=>{
306
+ (0, $313pz$setLookAtCamera)(false);
307
+ if (calibrationMode === 2) // In static mode, store the target in local storage to be able to reuse it later and avoid asking the user to calibrate again if the data are valid
308
+ localStorage.setItem('Retorik.Framework.Static.Target', JSON.stringify({
309
+ x: cameraX,
310
+ y: cameraY + currentAngleInDegrees * worldDistancePerDegree,
311
+ z: cameraZ
312
+ }));
313
+ else if (calibrationMode === 3 && ratioPixelToCentimeterRef.current) {
314
+ localStorage.setItem('Retorik.Framework.Dynamic.Data', JSON.stringify({
315
+ webcamHeight: webcamHeightRef.current,
316
+ ratioPixelToCentimeter: ratioPixelToCentimeterRef.current,
317
+ deltaAgentHeightAgentWorldHeightInCentimeters: deltaAgentHeightAgentWorldHeightInCentimetersRef.current,
318
+ cameraRotationInDegrees: webcamRotatedRef.current,
319
+ distanceFromAgentToCameraInCentimeters: distanceFromDeviceRef.current
320
+ }));
321
+ setTargets([]);
322
+ }
323
+ dispatch((0, $8ItUL.storeActions).view.setCalibrationCompleted(true));
324
+ };
325
+ const handleFaceDetected = (detections, width, height)=>{
326
+ counterRef.current++;
327
+ if (detections?.length && width && height) {
328
+ // The detections are inverted in X and Y axis (the origin is the top right corner of the image)
329
+ const webcamPositionY = webcamRotatedRef.current === 0 ? height / 2 : width / 2;
330
+ const userPositionY = webcamRotatedRef.current === 0 ? height * (1 - detections[0].keypoints[0].y) : width * (1 - detections[0].keypoints[0].x);
331
+ if (calibrationCompletedRef.current) // Check if the mandatory data have been filled (webcam / agent / user heights + distance user <-> device)
332
+ {
333
+ if (webcamHeightRef.current && ratioPixelToCentimeterRef.current && deltaAgentHeightAgentWorldHeightInCentimetersRef.current !== 0) {
334
+ const deltaHeightInPixels = webcamPositionY - userPositionY;
335
+ const userEyesHeightInCentimeters = webcamHeightRef.current - deltaHeightInPixels * ratioPixelToCentimeterRef.current;
336
+ const targetYInWorldCoordinates = (userEyesHeightInCentimeters + deltaAgentHeightAgentWorldHeightInCentimetersRef.current) / 100;
337
+ const o = new (0, $313pz$Object3D)();
338
+ o.position.set(cameraXRef.current, targetYInWorldCoordinates, cameraZRef.current);
339
+ setTargets([
340
+ o
341
+ ]);
342
+ }
343
+ } else // The detections are inverted in X and Y axis (the origin is the top right corner of the image)
344
+ if (webcamHeightRef.current && userEyesHeightRef.current && distanceFromDeviceRef.current) {
345
+ // Get the difference in height between the webcam and the user's eyes in cm, then use the detection to get the same difference in pixels on the webcam's image
346
+ const deltaHeightInCentimeters = Math.abs(webcamHeightRef.current - userEyesHeightRef.current);
347
+ const deltaHeightInPixels = Math.abs(webcamPositionY - userPositionY);
348
+ deltaHeightInPixels && (ratioPixelToCentimeterRef.current = deltaHeightInCentimeters / deltaHeightInPixels);
349
+ }
350
+ }
351
+ };
352
+ return /*#__PURE__*/ (0, $313pz$jsxs)("div", {
353
+ id: "retorik-framework-animation-container-calibration",
354
+ className: `rf-absolute rf-top-0 rf-h-full rf-w-full rf-grid rf-grid-cols-1 rf-grid-rows-1 ${!centered && 'landscape-retorik:rf-translate-x-1/4'}`,
355
+ children: [
356
+ calibrationMode === 3 && /*#__PURE__*/ (0, $313pz$jsx)("div", {
357
+ className: "rf-relative rf-z-1 rf-h-full rf-w-full rf-col-start-1 rf-col-span-1 rf-row-start-1 rf-row-span-1 rf-flex rf-justify-start rf-items-start",
358
+ children: /*#__PURE__*/ (0, $313pz$jsx)((0, $dJb7j.default), {
359
+ detectionThreshold: 0.8,
360
+ onFaceDetected: handleFaceDetected,
361
+ showThumbnail: !calibrationCompleted,
362
+ rotation: webcamRotation
363
+ })
364
+ }),
365
+ !calibrationCompleted && /*#__PURE__*/ (0, $313pz$jsx)((0, $313pz$react).Fragment, {
366
+ children: calibrationMode === 1 ? /*#__PURE__*/ (0, $313pz$jsxs)("div", {
367
+ className: "rf-h-full rf-w-full rf-col-start-1 rf-col-span-1 rf-row-start-1 rf-row-span-1 rf-flex rf-flex-col rf-justify-center rf-items-center rf-gap-4 rf-bg-white rf-bg-opacity-50",
368
+ children: [
369
+ /*#__PURE__*/ (0, $313pz$jsx)("p", {
370
+ className: "rf-text-medium-size-auto",
371
+ children: "Choisissez un mode de calibrage :"
372
+ }),
373
+ /*#__PURE__*/ (0, $313pz$jsxs)("div", {
374
+ className: "rf-flex rf-flex-row rf-gap-4",
375
+ children: [
376
+ staticCalibrationEnabled && /*#__PURE__*/ (0, $313pz$jsx)("div", {
377
+ className: "rf-px-4 rf-py-2 rf-border rf-border-primary rf-rounded-lg rf-bg-primary rf-bg-opacity-50 rf-cursor-pointer",
378
+ onClick: ()=>setCalibrationMode(2),
379
+ children: "STATIQUE"
380
+ }),
381
+ dynamicCalibrationEnabled && /*#__PURE__*/ (0, $313pz$jsx)("div", {
382
+ className: "rf-px-4 rf-py-2 rf-border rf-border-primary rf-rounded-lg rf-bg-primary rf-bg-opacity-50 rf-cursor-pointer",
383
+ onClick: ()=>setCalibrationMode(3),
384
+ children: "DYNAMIQUE"
385
+ })
386
+ ]
387
+ })
388
+ ]
389
+ }) : /*#__PURE__*/ (0, $313pz$jsx)("div", {
390
+ className: "rf-relative rf-h-full rf-w-full rf-col-start-1 rf-col-span-1 rf-row-start-1 rf-row-span-1 rf-flex rf-flex-col rf-justify-center rf-gap-4",
391
+ children: calibrationMode === 3 ? /*#__PURE__*/ (0, $313pz$jsxs)("div", {
392
+ className: "rf-absolute rf-left-32 rf-flex rf-flex-col rf-justify-center rf-items-center rf-gap-4",
393
+ children: [
394
+ /*#__PURE__*/ (0, $313pz$jsxs)("div", {
395
+ className: "rf-grid rf-grid-cols-2 rf-grid-rows-3 rf-gap-4",
396
+ children: [
397
+ /*#__PURE__*/ (0, $313pz$jsx)("p", {
398
+ className: "rf-font-bold",
399
+ children: "Hauteur webcam (en cm)"
400
+ }),
401
+ /*#__PURE__*/ (0, $313pz$jsx)("input", {
402
+ type: "number",
403
+ min: 0,
404
+ max: 300,
405
+ onChange: (e)=>{
406
+ webcamHeightRef.current = parseInt(e.target.value);
407
+ }
408
+ }),
409
+ /*#__PURE__*/ (0, $313pz$jsx)("p", {
410
+ className: "rf-font-bold",
411
+ children: "Votre taille (en cm)"
412
+ }),
413
+ /*#__PURE__*/ (0, $313pz$jsx)("input", {
414
+ type: "number",
415
+ min: 50,
416
+ max: 300,
417
+ onChange: (e)=>{
418
+ // We estimate the height of the user's eyes is 12 cm less than their total height
419
+ userEyesHeightRef.current = parseInt(e.target.value) - 12;
420
+ }
421
+ }),
422
+ /*#__PURE__*/ (0, $313pz$jsx)("p", {
423
+ className: "rf-font-bold",
424
+ children: "Hauteur des yeux de l'agent (en cm)"
425
+ }),
426
+ /*#__PURE__*/ (0, $313pz$jsx)("input", {
427
+ type: "number",
428
+ min: 50,
429
+ max: 300,
430
+ onChange: (e)=>{
431
+ setAgentEyesHeightOnScreen(parseInt(e.target.value));
432
+ agentEyesHeightRef.current = parseInt(e.target.value);
433
+ }
434
+ }),
435
+ /*#__PURE__*/ (0, $313pz$jsx)("p", {
436
+ className: "rf-font-bold",
437
+ children: "Distance utilisateur - borne (en cm)"
438
+ }),
439
+ /*#__PURE__*/ (0, $313pz$jsx)("input", {
440
+ type: "number",
441
+ min: 20,
442
+ max: 100,
443
+ onChange: (e)=>{
444
+ setDistanceFromDevice(parseInt(e.target.value));
445
+ distanceFromDeviceRef.current = parseInt(e.target.value);
446
+ }
447
+ }),
448
+ /*#__PURE__*/ (0, $313pz$jsx)("p", {
449
+ className: "rf-font-bold",
450
+ children: "Rotation de la webcam (en degr\xe9s)"
451
+ }),
452
+ /*#__PURE__*/ (0, $313pz$jsxs)("div", {
453
+ className: "rf-flex rf-flex-row rf-gap-2",
454
+ children: [
455
+ /*#__PURE__*/ (0, $313pz$jsx)("button", {
456
+ className: `rf-px-2 rf-py-1 rf-border rf-border-primary rf-rounded-lg rf-bg-primary rf-bg-opacity-50 rf-cursor-pointer ${webcamRotation === 0 && 'rf-bg-opacity-100'}`,
457
+ onClick: ()=>setWebcamRotation(0),
458
+ children: "0"
459
+ }),
460
+ /*#__PURE__*/ (0, $313pz$jsx)("button", {
461
+ className: `rf-px-2 rf-py-1 rf-border rf-border-primary rf-rounded-lg rf-bg-primary rf-bg-opacity-50 rf-cursor-pointer ${webcamRotation === 90 && 'rf-bg-opacity-100'}`,
462
+ onClick: ()=>setWebcamRotation(90),
463
+ children: "90"
464
+ }),
465
+ /*#__PURE__*/ (0, $313pz$jsx)("button", {
466
+ className: `rf-px-2 rf-py-1 rf-border rf-border-primary rf-rounded-lg rf-bg-primary rf-bg-opacity-50 rf-cursor-pointer ${webcamRotation === -90 && 'rf-bg-opacity-100'}`,
467
+ onClick: ()=>setWebcamRotation(-90),
468
+ children: "-90"
469
+ })
470
+ ]
471
+ })
472
+ ]
473
+ }),
474
+ /*#__PURE__*/ (0, $313pz$jsx)("div", {
475
+ className: "rf-h-16 rf-w-16 rf-flex rf-justify-center rf-items-center rf-bg-white rf-border rf-border-black rf-rounded-lg hover: rf-cursor-pointer",
476
+ onClick: handleValidate,
477
+ children: "Done"
478
+ })
479
+ ]
480
+ }) : /*#__PURE__*/ (0, $313pz$jsxs)("div", {
481
+ className: "rf-ml-4 rf-flex rf-flex-col rf-gap-4",
482
+ children: [
483
+ /*#__PURE__*/ (0, $313pz$jsxs)("div", {
484
+ className: "rf-flex rf-flex-row rf-items-center rf-gap-4",
485
+ children: [
486
+ /*#__PURE__*/ (0, $313pz$jsx)("input", {
487
+ type: "range",
488
+ min: -25,
489
+ max: 25,
490
+ step: 1,
491
+ value: currentAngleInDegrees,
492
+ onChange: (e)=>{
493
+ const val = parseInt(e.target.value);
494
+ setCurrentAngleInDegrees(val);
495
+ currentAngleInDegreesRef.current = val;
496
+ },
497
+ className: "rf-range-vertical rf-w-8 rf-h-80 rf-appearance-none rf-border rf-border-black rf-rounded-lg rf-cursor-pointer",
498
+ style: {
499
+ writingMode: 'vertical-lr',
500
+ direction: 'rtl'
501
+ }
502
+ }),
503
+ /*#__PURE__*/ (0, $313pz$jsxs)("div", {
504
+ className: "rf-w-fit rf-p-4 rf-flex rf-flex-col rf-justify-center rf-gap-2 rf-bg-white rf-border rf-border-black rf-rounded-lg",
505
+ children: [
506
+ /*#__PURE__*/ (0, $313pz$jsx)("p", {
507
+ children: "Position actuelle de la cible : "
508
+ }),
509
+ /*#__PURE__*/ (0, $313pz$jsx)("p", {
510
+ children: `x: ${cameraX}`
511
+ }),
512
+ /*#__PURE__*/ (0, $313pz$jsx)("p", {
513
+ children: `y: ${cameraY + (currentAngleInDegrees ? currentAngleInDegrees * worldDistancePerDegree : 0)}`
514
+ }),
515
+ /*#__PURE__*/ (0, $313pz$jsx)("p", {
516
+ children: `z: ${Math.max(cameraZ / 5, 0.3)}`
517
+ }),
518
+ /*#__PURE__*/ (0, $313pz$jsx)("p", {
519
+ children: `angle: ${currentAngleInDegrees}\xb0`
520
+ })
521
+ ]
522
+ })
523
+ ]
524
+ }),
525
+ /*#__PURE__*/ (0, $313pz$jsxs)("div", {
526
+ className: "rf-flex rf-flex-row rf-gap-2",
527
+ children: [
528
+ /*#__PURE__*/ (0, $313pz$jsx)("div", {
529
+ className: "rf-h-10 rf-px-4 rf-flex rf-justify-center rf-items-center rf-bg-white rf-border rf-border-black rf-rounded-lg rf-cursor-pointer",
530
+ onClick: ()=>handleReset(),
531
+ children: "Reset"
532
+ }),
533
+ /*#__PURE__*/ (0, $313pz$jsx)("div", {
534
+ className: "rf-h-10 rf-px-4 rf-flex rf-justify-center rf-items-center rf-bg-white rf-border rf-border-black rf-rounded-lg rf-cursor-pointer",
535
+ onClick: handleValidate,
536
+ children: "Done"
537
+ })
538
+ ]
539
+ })
540
+ ]
541
+ })
542
+ })
543
+ })
544
+ ]
545
+ });
546
+ };
547
+ var $c6350b57d46149f8$export$2e2bcd8739ae039 = $c6350b57d46149f8$var$CalibrationScreen;
548
+
549
+ });
550
+ parcelRegister("dJb7j", function(module, exports) {
551
+
552
+ $parcel$export(module.exports, "default", () => $741aef3293d0db11$export$2e2bcd8739ae039);
553
+
554
+
555
+
556
+ const $741aef3293d0db11$var$runningMode = 'VIDEO';
557
+ let $741aef3293d0db11$var$lastVideoTime = -1;
558
+ const $741aef3293d0db11$var$defaultConstraints = {
559
+ video: {
560
+ facingMode: 'user'
561
+ }
562
+ };
563
+ const $741aef3293d0db11$var$FaceDetector = ({ detectionThreshold: detectionThreshold, onFaceDetected: onFaceDetected, showThumbnail: showThumbnail, rotation: rotation })=>{
564
+ const [webcamWidth, setWebcamWidth] = (0, $313pz$useState)(0);
565
+ const [webcamHeight, setWebcamHeight] = (0, $313pz$useState)(0);
566
+ const [faceDetector, setFaceDetector] = (0, $313pz$useState)();
567
+ const videoRef = (0, $313pz$useRef)(null);
568
+ const rotationRef = (0, $313pz$useRef)(rotation || 0);
569
+ (0, $313pz$useEffect)(()=>{
570
+ rotationRef.current = rotation || 0;
571
+ }, [
572
+ rotation
573
+ ]);
574
+ (0, $313pz$useEffect)(()=>{
575
+ const createfaceDetector = async ()=>{
576
+ const vision = await (0, $313pz$FilesetResolver).forVisionTasks('https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.0/wasm');
577
+ const newFaceDetector = await (0, $313pz$FaceDetector).createFromOptions(vision, {
578
+ baseOptions: {
579
+ modelAssetPath: `https://storage.googleapis.com/mediapipe-models/face_detector/blaze_face_short_range/float16/1/blaze_face_short_range.tflite`,
580
+ delegate: 'GPU'
581
+ },
582
+ runningMode: $741aef3293d0db11$var$runningMode
583
+ });
584
+ newFaceDetector && setFaceDetector(newFaceDetector);
585
+ };
586
+ const initializefaceDetector = async ()=>{
587
+ navigator.mediaDevices.getUserMedia($741aef3293d0db11$var$defaultConstraints).then((display)=>{
588
+ const settings = display.getVideoTracks()[0].getSettings();
589
+ setWebcamWidth(settings.width || 0);
590
+ setWebcamHeight(settings.height || 0);
591
+ createfaceDetector();
592
+ }).catch((error)=>console.warn('Retorik Framework > an error occured when trying to use the webcam : ', error));
593
+ };
594
+ initializefaceDetector();
595
+ }, []);
596
+ const predictWebcam = async ()=>{
597
+ if (faceDetector && videoRef.current) {
598
+ let startTimeMs = performance.now();
599
+ // Detect faces using detectForVideo
600
+ if (videoRef.current.currentTime !== $741aef3293d0db11$var$lastVideoTime) {
601
+ $741aef3293d0db11$var$lastVideoTime = videoRef.current.currentTime;
602
+ const detections = faceDetector.detectForVideo(videoRef.current, startTimeMs, {
603
+ rotationDegrees: rotationRef.current
604
+ }).detections;
605
+ if (detections.length) {
606
+ const score = detections[0].categories[0].score;
607
+ score > detectionThreshold && onFaceDetected(detections, videoRef.current.videoWidth, videoRef.current.videoHeight);
608
+ }
609
+ }
610
+ }
611
+ // Call this function again to keep predicting when the browser is ready
612
+ window.requestAnimationFrame(predictWebcam);
613
+ };
614
+ (0, $313pz$useEffect)(()=>{
615
+ if (faceDetector && videoRef.current) // Activate the webcam stream
616
+ navigator.mediaDevices.getUserMedia($741aef3293d0db11$var$defaultConstraints).then((stream)=>{
617
+ if (videoRef.current) {
618
+ videoRef.current.srcObject = stream;
619
+ videoRef.current.addEventListener('loadeddata', predictWebcam);
620
+ }
621
+ }).catch((err)=>{
622
+ console.error(err);
623
+ });
624
+ }, [
625
+ faceDetector
626
+ ]);
627
+ return /*#__PURE__*/ (0, $313pz$jsx)("div", {
628
+ id: "retorik-framework-face-detector",
629
+ className: `rf-absolute rf-top-0 rf-left-0 ${!showThumbnail && 'rf-invisible'}`,
630
+ children: /*#__PURE__*/ (0, $313pz$jsx)("video", {
631
+ ref: videoRef,
632
+ src: "",
633
+ autoPlay: true,
634
+ style: {
635
+ rotate: `${rotation}deg`,
636
+ width: showThumbnail ? webcamWidth / 2 : webcamWidth,
637
+ height: showThumbnail ? webcamHeight / 2 : webcamHeight
638
+ }
639
+ })
640
+ });
641
+ };
642
+ var $741aef3293d0db11$export$2e2bcd8739ae039 = $741aef3293d0db11$var$FaceDetector;
643
+
644
+ });
645
+
646
+
647
+
648
+
649
+ //# sourceMappingURL=ThreeJsWrapper.cb253b3a.js.map