@memori.ai/memori-react 7.16.0 → 7.16.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.
- package/CHANGELOG.md +25 -0
- package/README.md +0 -1
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/MorhTargetController.d.ts +17 -0
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/MorhTargetController.js +73 -0
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/MorhTargetController.js.map +1 -0
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.d.ts +17 -0
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.js +25 -0
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.js.map +1 -0
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.d.ts +26 -0
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.js +166 -0
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.js.map +1 -0
- package/dist/components/MemoriWidget/MemoriWidget.js +49 -16
- package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +17 -12
- package/dist/index.js.map +1 -1
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/MorhTargetController.d.ts +17 -0
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/MorhTargetController.js +69 -0
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/MorhTargetController.js.map +1 -0
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.d.ts +17 -0
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.js +22 -0
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.js.map +1 -0
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.d.ts +26 -0
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.js +163 -0
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.js.map +1 -0
- package/esm/components/MemoriWidget/MemoriWidget.js +49 -16
- package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/esm/index.d.ts +0 -1
- package/esm/index.js +17 -12
- package/esm/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/MemoriWidget/MemoriWidget.tsx +78 -24
- package/src/index.tsx +15 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## [7.16.2](https://github.com/memori-ai/memori-react/compare/v7.16.1...v7.16.2) (2025-02-10)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* improve speech key fetching and audio enabling logic ([f6ea5e2](https://github.com/memori-ai/memori-react/commit/f6ea5e2f23e0316b70702661670a487572cda07c))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Changes
|
|
12
|
+
|
|
13
|
+
* send initial question with previous session with empty history ([1a6ff68](https://github.com/memori-ai/memori-react/commit/1a6ff6838c19a2099da4bfe224150718d794fd6f))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Maintenance
|
|
17
|
+
|
|
18
|
+
* remove AZURE_COGNITIVE_SERVICES_TTS_KEY as prop ([06ee821](https://github.com/memori-ai/memori-react/commit/06ee821d309532941121c949badeb6f9d3a6d297))
|
|
19
|
+
* update api client ([a97c44e](https://github.com/memori-ai/memori-react/commit/a97c44e4ac052135b2e515aa36c76424bdf729b5))
|
|
20
|
+
|
|
21
|
+
## [7.16.1](https://github.com/memori-ai/memori-react/compare/v7.16.0...v7.16.1) (2025-01-31)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* opening session current tag check + history ([adc90f9](https://github.com/memori-ai/memori-react/commit/adc90f9a0c1e7414ec24a55a19d6504a0aec65a8))
|
|
27
|
+
|
|
3
28
|
## [7.16.0](https://github.com/memori-ai/memori-react/compare/v7.15.2...v7.16.0) (2025-01-31)
|
|
4
29
|
|
|
5
30
|
|
package/README.md
CHANGED
|
@@ -90,7 +90,6 @@ const App = () => (
|
|
|
90
90
|
| `defaultSpeakerActive` | | `boolean` | `true` | Default value for the speaker activation |
|
|
91
91
|
| `disableTextEnteredEvents` | | `boolean` | `false` | Disable MemoriTextEntered events listeners for `typeMessage` functions, useful to avoid issues with multiple widgets in page. |
|
|
92
92
|
| `useMathFormatting` | | `boolean` | `false` | Apply math formatting to the messages, defaults to false if otherwise indicated by props or integration config. |
|
|
93
|
-
| `AZURE_COGNITIVE_SERVICES_TTS_KEY` | | `string` | | Azure Cognitive Services TTS key, used to generate the audio of the Memori and for STT recognition |
|
|
94
93
|
| `layout` | | `string` | | Layout of the Memori, can be "FULLPAGE" (default), "CHAT", "WEBSITE_ASSISTANT", "TOTEM", "HIDDEN_CHAT" or "ZOOMED_FULL_BODY". see [below](#layouts) |
|
|
95
94
|
| `customLayout` | | `React.FC<LayoutProps>` | | Custom layout component, see [below](#custom-layout) |
|
|
96
95
|
| `customMediaRenderer` | | `(mimeType: string) => JSX.Element \| null` | | Custom media renderer, see [below](#custom-media-renderer) |
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SkinnedMesh } from 'three';
|
|
2
|
+
export declare class MorphTargetController {
|
|
3
|
+
private headMesh;
|
|
4
|
+
private currentEmotionValues;
|
|
5
|
+
private previousEmotionKeys;
|
|
6
|
+
constructor(headMesh: SkinnedMesh);
|
|
7
|
+
updateMorphTargets(currentTime: number, emotionMorphTargets: Record<string, number>, currentViseme: {
|
|
8
|
+
name: string;
|
|
9
|
+
weight: number;
|
|
10
|
+
} | null, eyeBlink: boolean, blinkState: {
|
|
11
|
+
isBlinking: boolean;
|
|
12
|
+
lastBlinkTime: number;
|
|
13
|
+
nextBlinkTime: number;
|
|
14
|
+
blinkStartTime: number;
|
|
15
|
+
}): void;
|
|
16
|
+
private calculateBlinkValue;
|
|
17
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MorphTargetController = void 0;
|
|
4
|
+
const three_1 = require("three");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
class MorphTargetController {
|
|
7
|
+
constructor(headMesh) {
|
|
8
|
+
this.currentEmotionValues = {};
|
|
9
|
+
this.previousEmotionKeys = new Set();
|
|
10
|
+
this.headMesh = headMesh;
|
|
11
|
+
}
|
|
12
|
+
updateMorphTargets(currentTime, emotionMorphTargets, currentViseme, eyeBlink, blinkState) {
|
|
13
|
+
if (!this.headMesh.morphTargetDictionary ||
|
|
14
|
+
!this.headMesh.morphTargetInfluences) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const blinkValue = this.calculateBlinkValue(currentTime, blinkState, eyeBlink);
|
|
18
|
+
const currentEmotionKeys = new Set(Object.keys(emotionMorphTargets));
|
|
19
|
+
Object.entries(this.headMesh.morphTargetDictionary).forEach(([key, index]) => {
|
|
20
|
+
if (typeof index !== 'number')
|
|
21
|
+
return;
|
|
22
|
+
let targetValue = 0;
|
|
23
|
+
if (currentEmotionKeys.has(key)) {
|
|
24
|
+
const targetEmotionValue = emotionMorphTargets[key];
|
|
25
|
+
const currentEmotionValue = this.currentEmotionValues[key] || 0;
|
|
26
|
+
const newEmotionValue = three_1.MathUtils.lerp(currentEmotionValue, targetEmotionValue * 2.5, constants_1.EMOTION_SMOOTHING);
|
|
27
|
+
this.currentEmotionValues[key] = newEmotionValue;
|
|
28
|
+
targetValue += newEmotionValue;
|
|
29
|
+
}
|
|
30
|
+
if (currentViseme && key === currentViseme.name) {
|
|
31
|
+
targetValue += currentViseme.weight;
|
|
32
|
+
}
|
|
33
|
+
if (key === 'eyesClosed' && eyeBlink) {
|
|
34
|
+
targetValue += blinkValue;
|
|
35
|
+
}
|
|
36
|
+
targetValue = three_1.MathUtils.clamp(targetValue, 0, 1);
|
|
37
|
+
if (this.headMesh.morphTargetInfluences) {
|
|
38
|
+
this.headMesh.morphTargetInfluences[index] = three_1.MathUtils.lerp(this.headMesh.morphTargetInfluences[index] || 0, targetValue, constants_1.VISEME_SMOOTHING);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
this.previousEmotionKeys = currentEmotionKeys;
|
|
42
|
+
}
|
|
43
|
+
calculateBlinkValue(currentTime, blinkState, eyeBlink) {
|
|
44
|
+
if (!eyeBlink)
|
|
45
|
+
return 0;
|
|
46
|
+
let blinkValue = 0;
|
|
47
|
+
if (currentTime >= blinkState.nextBlinkTime && !blinkState.isBlinking) {
|
|
48
|
+
blinkState.isBlinking = true;
|
|
49
|
+
blinkState.blinkStartTime = currentTime;
|
|
50
|
+
blinkState.lastBlinkTime = currentTime;
|
|
51
|
+
blinkState.nextBlinkTime =
|
|
52
|
+
currentTime +
|
|
53
|
+
Math.random() * (constants_1.BLINK_CONFIG.maxInterval - constants_1.BLINK_CONFIG.minInterval) +
|
|
54
|
+
constants_1.BLINK_CONFIG.minInterval;
|
|
55
|
+
}
|
|
56
|
+
if (blinkState.isBlinking) {
|
|
57
|
+
const blinkProgress = (currentTime - blinkState.blinkStartTime) / constants_1.BLINK_CONFIG.blinkDuration;
|
|
58
|
+
if (blinkProgress <= 0.5) {
|
|
59
|
+
blinkValue = blinkProgress * 2;
|
|
60
|
+
}
|
|
61
|
+
else if (blinkProgress <= 1) {
|
|
62
|
+
blinkValue = 2 - blinkProgress * 2;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
blinkState.isBlinking = false;
|
|
66
|
+
blinkValue = 0;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return blinkValue;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.MorphTargetController = MorphTargetController;
|
|
73
|
+
//# sourceMappingURL=MorhTargetController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MorhTargetController.js","sourceRoot":"","sources":["../../../../../../../src/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/MorhTargetController.ts"],"names":[],"mappings":";;;AACA,iCAAkC;AAClC,2CAAgF;AAEhF,MAAa,qBAAqB;IAKhC,YAAY,QAAqB;QAHzB,yBAAoB,GAA2B,EAAE,CAAC;QAClD,wBAAmB,GAAgB,IAAI,GAAG,EAAE,CAAC;QAGnD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,kBAAkB,CAChB,WAAmB,EACnB,mBAA2C,EAC3C,aAAsD,EACtD,QAAiB,EACjB,UAKC;QAED,IACE,CAAC,IAAI,CAAC,QAAQ,CAAC,qBAAqB;YACpC,CAAC,IAAI,CAAC,QAAQ,CAAC,qBAAqB,EACpC;YACA,OAAO;SACR;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,mBAAmB,CACzC,WAAW,EACX,UAAU,EACV,QAAQ,CACT,CAAC;QACF,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC;QAErE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC,OAAO,CACzD,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YACf,IAAI,OAAO,KAAK,KAAK,QAAQ;gBAAE,OAAO;YAEtC,IAAI,WAAW,GAAG,CAAC,CAAC;YAGpB,IAAI,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;gBAC/B,MAAM,kBAAkB,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;gBACpD,MAAM,mBAAmB,GAAG,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,IAAI,CAAC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,MAAM,EAAE,GAAG,CAAC,wBAAY,CAAC,WAAW,GAAG,wBAAY,CAAC,WAAW,CAAC;oBACrE,wBAAY,CAAC,WAAW,CAAC;SAC5B;QAED,IAAI,UAAU,CAAC,UAAU,EAAE;YACzB,MAAM,aAAa,GACjB,CAAC,WAAW,GAAG,UAAU,CAAC,cAAc,CAAC,GAAG,wBAAY,CAAC,aAAa,CAAC;YACzE,IAAI,aAAa,IAAI,GAAG,EAAE;gBACxB,UAAU,GAAG,aAAa,GAAG,CAAC,CAAC;aAChC;iBAAM,IAAI,aAAa,IAAI,CAAC,EAAE;gBAC7B,UAAU,GAAG,CAAC,GAAG,aAAa,GAAG,CAAC,CAAC;aACpC;iBAAM;gBACL,UAAU,CAAC,UAAU,GAAG,KAAK,CAAC;gBAC9B,UAAU,GAAG,CAAC,CAAC;aAChB;SACF;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;CACF;AAtHD,sDAsHC"}
|
package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Vector3, Euler } from 'three';
|
|
2
|
+
import { AnimationConfig } from './types';
|
|
3
|
+
export declare const AVATAR_POSITION: Vector3;
|
|
4
|
+
export declare const AVATAR_ROTATION: Euler;
|
|
5
|
+
export declare const AVATAR_POSITION_ZOOMED: Vector3;
|
|
6
|
+
export declare const ANIMATION_URLS: {
|
|
7
|
+
MALE: string;
|
|
8
|
+
FEMALE: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const BLINK_CONFIG: {
|
|
11
|
+
minInterval: number;
|
|
12
|
+
maxInterval: number;
|
|
13
|
+
blinkDuration: number;
|
|
14
|
+
};
|
|
15
|
+
export declare const DEFAULT_CONFIG: AnimationConfig;
|
|
16
|
+
export declare const EMOTION_SMOOTHING = 0.3;
|
|
17
|
+
export declare const VISEME_SMOOTHING = 0.5;
|
package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VISEME_SMOOTHING = exports.EMOTION_SMOOTHING = exports.DEFAULT_CONFIG = exports.BLINK_CONFIG = exports.ANIMATION_URLS = exports.AVATAR_POSITION_ZOOMED = exports.AVATAR_ROTATION = exports.AVATAR_POSITION = void 0;
|
|
4
|
+
const three_1 = require("three");
|
|
5
|
+
exports.AVATAR_POSITION = new three_1.Vector3(0, -1, 0);
|
|
6
|
+
exports.AVATAR_ROTATION = new three_1.Euler(0.175, 0, 0);
|
|
7
|
+
exports.AVATAR_POSITION_ZOOMED = new three_1.Vector3(0, -1.45, 0);
|
|
8
|
+
exports.ANIMATION_URLS = {
|
|
9
|
+
MALE: 'https://assets.memori.ai/api/v2/asset/2c5e88a4-cf62-408b-9ef0-518b099dfcb2.glb',
|
|
10
|
+
FEMALE: 'https://assets.memori.ai/api/v2/asset/2adc934b-24b2-45bd-94ad-ffec58d3cb32.glb',
|
|
11
|
+
};
|
|
12
|
+
exports.BLINK_CONFIG = {
|
|
13
|
+
minInterval: 1000,
|
|
14
|
+
maxInterval: 5000,
|
|
15
|
+
blinkDuration: 150,
|
|
16
|
+
};
|
|
17
|
+
exports.DEFAULT_CONFIG = {
|
|
18
|
+
fadeInDuration: 0.8,
|
|
19
|
+
fadeOutDuration: 0.8,
|
|
20
|
+
idleCount: 5,
|
|
21
|
+
timeScale: 1.0,
|
|
22
|
+
};
|
|
23
|
+
exports.EMOTION_SMOOTHING = 0.3;
|
|
24
|
+
exports.VISEME_SMOOTHING = 0.5;
|
|
25
|
+
//# sourceMappingURL=constants.js.map
|
package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../../src/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.ts"],"names":[],"mappings":";;;AAAA,iCAAuC;AAG1B,QAAA,eAAe,GAAG,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACxC,QAAA,eAAe,GAAG,IAAI,aAAK,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACzC,QAAA,sBAAsB,GAAG,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAElD,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gFAAgF;IACtF,MAAM,EACJ,gFAAgF;CACnF,CAAC;AAEW,QAAA,YAAY,GAAG;IAC1B,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE,GAAG;CACnB,CAAC;AAEW,QAAA,cAAc,GAAoB;IAC7C,cAAc,EAAE,GAAG;IACnB,eAAe,EAAE,GAAG;IACpB,SAAS,EAAE,CAAC;IACZ,SAAS,EAAE,GAAG;CACf,CAAC;AAEW,QAAA,iBAAiB,GAAG,GAAG,CAAC;AACxB,QAAA,gBAAgB,GAAG,GAAG,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
interface FullbodyAvatarProps {
|
|
2
|
+
url: string;
|
|
3
|
+
sex: 'MALE' | 'FEMALE';
|
|
4
|
+
onLoaded?: () => void;
|
|
5
|
+
currentBaseAction: {
|
|
6
|
+
action: string;
|
|
7
|
+
weight: number;
|
|
8
|
+
};
|
|
9
|
+
timeScale: number;
|
|
10
|
+
isZoomed?: boolean;
|
|
11
|
+
eyeBlink?: boolean;
|
|
12
|
+
stopProcessing: () => void;
|
|
13
|
+
resetVisemeQueue: () => void;
|
|
14
|
+
updateCurrentViseme: (currentTime: number) => {
|
|
15
|
+
name: string;
|
|
16
|
+
weight: number;
|
|
17
|
+
} | null;
|
|
18
|
+
smoothMorphTarget?: boolean;
|
|
19
|
+
morphTargetSmoothing?: number;
|
|
20
|
+
morphTargetInfluences: Record<string, number>;
|
|
21
|
+
setMorphTargetDictionary: (morphTargetDictionary: Record<string, number>) => void;
|
|
22
|
+
setMorphTargetInfluences: (morphTargetInfluences: Record<string, number>) => void;
|
|
23
|
+
emotionMorphTargets: Record<string, number>;
|
|
24
|
+
}
|
|
25
|
+
export default function FullbodyAvatar({ url, sex, currentBaseAction, timeScale, isZoomed, eyeBlink, updateCurrentViseme, setMorphTargetDictionary, setMorphTargetInfluences, emotionMorphTargets, }: FullbodyAvatarProps): JSX.Element;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const three_1 = require("three");
|
|
6
|
+
const drei_1 = require("@react-three/drei");
|
|
7
|
+
const fiber_1 = require("@react-three/fiber");
|
|
8
|
+
const AVATAR_POSITION = new three_1.Vector3(0, -1, 0);
|
|
9
|
+
const AVATAR_ROTATION = new three_1.Euler(0.175, 0, 0);
|
|
10
|
+
const AVATAR_POSITION_ZOOMED = new three_1.Vector3(0, -1.45, 0);
|
|
11
|
+
const ANIMATION_URLS = {
|
|
12
|
+
MALE: 'https://assets.memori.ai/api/v2/asset/2c5e88a4-cf62-408b-9ef0-518b099dfcb2.glb',
|
|
13
|
+
FEMALE: 'https://assets.memori.ai/api/v2/asset/8d1a5853-f05a-4a34-9f99-6eff64986081.glb',
|
|
14
|
+
};
|
|
15
|
+
const BLINK_CONFIG = {
|
|
16
|
+
minInterval: 1000,
|
|
17
|
+
maxInterval: 5000,
|
|
18
|
+
blinkDuration: 150,
|
|
19
|
+
};
|
|
20
|
+
const EMOTION_SMOOTHING = 0.3;
|
|
21
|
+
const VISME_SMOOTHING = 0.5;
|
|
22
|
+
function FullbodyAvatar({ url, sex, currentBaseAction, timeScale, isZoomed, eyeBlink, updateCurrentViseme, setMorphTargetDictionary, setMorphTargetInfluences, emotionMorphTargets, }) {
|
|
23
|
+
const { scene } = (0, drei_1.useGLTF)(url);
|
|
24
|
+
const { animations } = (0, drei_1.useGLTF)(ANIMATION_URLS[sex]);
|
|
25
|
+
const { actions } = (0, drei_1.useAnimations)(animations, scene);
|
|
26
|
+
const mixerRef = (0, react_1.useRef)();
|
|
27
|
+
const headMeshRef = (0, react_1.useRef)();
|
|
28
|
+
const currentActionRef = (0, react_1.useRef)(null);
|
|
29
|
+
const isTransitioningToIdleRef = (0, react_1.useRef)(false);
|
|
30
|
+
const lastBlinkTimeRef = (0, react_1.useRef)(0);
|
|
31
|
+
const nextBlinkTimeRef = (0, react_1.useRef)(0);
|
|
32
|
+
const isBlinkingRef = (0, react_1.useRef)(false);
|
|
33
|
+
const blinkStartTimeRef = (0, react_1.useRef)(0);
|
|
34
|
+
const currentEmotionRef = (0, react_1.useRef)({});
|
|
35
|
+
const previousEmotionKeysRef = (0, react_1.useRef)(new Set());
|
|
36
|
+
const headMesh = (0, react_1.useMemo)(() => {
|
|
37
|
+
let foundMesh;
|
|
38
|
+
scene.traverse((object) => {
|
|
39
|
+
if (object instanceof three_1.SkinnedMesh &&
|
|
40
|
+
(object.name === 'GBNL__Head' || object.name === 'Wolf3D_Avatar')) {
|
|
41
|
+
foundMesh = object;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return foundMesh;
|
|
45
|
+
}, [scene]);
|
|
46
|
+
(0, react_1.useEffect)(() => {
|
|
47
|
+
if (headMesh) {
|
|
48
|
+
headMeshRef.current = headMesh;
|
|
49
|
+
if (headMesh.morphTargetDictionary && headMesh.morphTargetInfluences) {
|
|
50
|
+
setMorphTargetDictionary(headMesh.morphTargetDictionary);
|
|
51
|
+
const initialInfluences = Object.keys(headMesh.morphTargetDictionary).reduce((acc, key) => ({ ...acc, [key]: 0 }), {});
|
|
52
|
+
setMorphTargetInfluences(initialInfluences);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
mixerRef.current = new three_1.AnimationMixer(scene);
|
|
56
|
+
}, [headMesh, scene, setMorphTargetDictionary, setMorphTargetInfluences]);
|
|
57
|
+
const handleAnimationChange = (0, react_1.useCallback)(() => {
|
|
58
|
+
if (!actions || !currentBaseAction.action)
|
|
59
|
+
return;
|
|
60
|
+
const newAction = actions[currentBaseAction.action];
|
|
61
|
+
if (!newAction) {
|
|
62
|
+
console.warn(`Animation "${currentBaseAction.action}" not found in actions.`);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const fadeOutDuration = 0.8;
|
|
66
|
+
const fadeInDuration = 0.8;
|
|
67
|
+
if (currentActionRef.current) {
|
|
68
|
+
currentActionRef.current.fadeOut(fadeOutDuration);
|
|
69
|
+
}
|
|
70
|
+
newAction.reset().fadeIn(fadeInDuration).play();
|
|
71
|
+
currentActionRef.current = newAction;
|
|
72
|
+
newAction.timeScale = timeScale;
|
|
73
|
+
if (currentBaseAction.action.startsWith('Gioia') ||
|
|
74
|
+
currentBaseAction.action.startsWith('Rabbia') ||
|
|
75
|
+
currentBaseAction.action.startsWith('Sorpresa') ||
|
|
76
|
+
currentBaseAction.action.startsWith('Timore') ||
|
|
77
|
+
currentBaseAction.action.startsWith('Tristezza')) {
|
|
78
|
+
newAction.setLoop(three_1.LoopOnce, 1);
|
|
79
|
+
newAction.clampWhenFinished = true;
|
|
80
|
+
isTransitioningToIdleRef.current = true;
|
|
81
|
+
}
|
|
82
|
+
}, [actions, currentBaseAction, timeScale]);
|
|
83
|
+
(0, react_1.useEffect)(() => {
|
|
84
|
+
handleAnimationChange();
|
|
85
|
+
}, [handleAnimationChange]);
|
|
86
|
+
const updateFrame = (0, react_1.useCallback)((currentTime) => {
|
|
87
|
+
var _a;
|
|
88
|
+
if (!headMeshRef.current ||
|
|
89
|
+
!headMeshRef.current.morphTargetDictionary ||
|
|
90
|
+
!headMeshRef.current.morphTargetInfluences)
|
|
91
|
+
return;
|
|
92
|
+
let blinkValue = 0;
|
|
93
|
+
if (eyeBlink) {
|
|
94
|
+
if (currentTime >= nextBlinkTimeRef.current && !isBlinkingRef.current) {
|
|
95
|
+
isBlinkingRef.current = true;
|
|
96
|
+
blinkStartTimeRef.current = currentTime;
|
|
97
|
+
lastBlinkTimeRef.current = currentTime;
|
|
98
|
+
nextBlinkTimeRef.current =
|
|
99
|
+
currentTime +
|
|
100
|
+
Math.random() *
|
|
101
|
+
(BLINK_CONFIG.maxInterval - BLINK_CONFIG.minInterval) +
|
|
102
|
+
BLINK_CONFIG.minInterval;
|
|
103
|
+
}
|
|
104
|
+
if (isBlinkingRef.current) {
|
|
105
|
+
const blinkProgress = (currentTime - blinkStartTimeRef.current) /
|
|
106
|
+
BLINK_CONFIG.blinkDuration;
|
|
107
|
+
if (blinkProgress <= 0.5) {
|
|
108
|
+
blinkValue = blinkProgress * 2;
|
|
109
|
+
}
|
|
110
|
+
else if (blinkProgress <= 1) {
|
|
111
|
+
blinkValue = 2 - blinkProgress * 2;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
isBlinkingRef.current = false;
|
|
115
|
+
blinkValue = 0;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const currentViseme = updateCurrentViseme(currentTime / 1000);
|
|
120
|
+
const currentEmotionKeys = new Set(Object.keys(emotionMorphTargets));
|
|
121
|
+
Object.entries(headMeshRef.current.morphTargetDictionary).forEach(([key, index]) => {
|
|
122
|
+
if (typeof index === 'number') {
|
|
123
|
+
let targetValue = 0;
|
|
124
|
+
if (currentEmotionKeys.has(key)) {
|
|
125
|
+
const targetEmotionValue = emotionMorphTargets[key];
|
|
126
|
+
const currentEmotionValue = currentEmotionRef.current[key] || 0;
|
|
127
|
+
const newEmotionValue = three_1.MathUtils.lerp(currentEmotionValue, targetEmotionValue * 2.5, EMOTION_SMOOTHING);
|
|
128
|
+
currentEmotionRef.current[key] = newEmotionValue;
|
|
129
|
+
targetValue += newEmotionValue;
|
|
130
|
+
}
|
|
131
|
+
if (currentViseme && key === currentViseme.name) {
|
|
132
|
+
targetValue += currentViseme.weight;
|
|
133
|
+
}
|
|
134
|
+
if (key === 'eyesClosed' && eyeBlink) {
|
|
135
|
+
targetValue += blinkValue;
|
|
136
|
+
}
|
|
137
|
+
targetValue = three_1.MathUtils.clamp(targetValue, 0, 1);
|
|
138
|
+
if (headMeshRef.current &&
|
|
139
|
+
headMeshRef.current.morphTargetInfluences) {
|
|
140
|
+
headMeshRef.current.morphTargetInfluences[index] = three_1.MathUtils.lerp(headMeshRef.current.morphTargetInfluences[index], targetValue, VISME_SMOOTHING);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
previousEmotionKeysRef.current = currentEmotionKeys;
|
|
145
|
+
if (isTransitioningToIdleRef.current && currentActionRef.current) {
|
|
146
|
+
if (currentActionRef.current.time >=
|
|
147
|
+
currentActionRef.current.getClip().duration) {
|
|
148
|
+
const idleNumber = Math.floor(Math.random() * 5) + 1;
|
|
149
|
+
const idleAction = actions[`Idle${idleNumber === 3 ? 4 : idleNumber}`];
|
|
150
|
+
if (idleAction) {
|
|
151
|
+
currentActionRef.current.fadeOut(0.5);
|
|
152
|
+
idleAction.reset().fadeIn(0.5).play();
|
|
153
|
+
currentActionRef.current = idleAction;
|
|
154
|
+
isTransitioningToIdleRef.current = false;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
(_a = mixerRef.current) === null || _a === void 0 ? void 0 : _a.update(0.01);
|
|
159
|
+
}, [actions, emotionMorphTargets, eyeBlink, updateCurrentViseme]);
|
|
160
|
+
(0, fiber_1.useFrame)(state => {
|
|
161
|
+
updateFrame(state.clock.elapsedTime * 1000);
|
|
162
|
+
});
|
|
163
|
+
return ((0, jsx_runtime_1.jsx)("group", { position: isZoomed ? AVATAR_POSITION_ZOOMED : AVATAR_POSITION, rotation: AVATAR_ROTATION, children: (0, jsx_runtime_1.jsx)("primitive", { object: scene }) }));
|
|
164
|
+
}
|
|
165
|
+
exports.default = FullbodyAvatar;
|
|
166
|
+
//# sourceMappingURL=fullbodyAvatar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fullbodyAvatar.js","sourceRoot":"","sources":["../../../../../../src/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.tsx"],"names":[],"mappings":";;;AAAA,iCAAuE;AACvE,iCASe;AACf,4CAA2D;AAC3D,8CAAwD;AA8BxD,MAAM,eAAe,GAAG,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC9C,MAAM,eAAe,GAAG,IAAI,aAAK,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC/C,MAAM,sBAAsB,GAAG,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAExD,MAAM,cAAc,GAAG;IACrB,IAAI,EAAE,gFAAgF;IACtF,MAAM,EACJ,gFAAgF;CACnF,CAAC;AAEF,MAAM,YAAY,GAAG;IACnB,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE,GAAG;CACnB,CAAC;AAEF,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,SAAwB,cAAc,CAAC,EACrC,GAAG,EACH,GAAG,EACH,iBAAiB,EACjB,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,wBAAwB,EACxB,wBAAwB,EACxB,mBAAmB,GACC;IACpB,MAAM,EAAE,KAAK,EAAE,GAAG,IAAA,cAAO,EAAC,GAAG,CAAC,CAAC;IAC/B,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,cAAO,EAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;IACpD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,oBAAa,EAAC,UAAU,EAAE,KAAK,CAAC,CAAC;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AAO,GAAG,KAAK,CAAC;iBAC1C;aACF;SACF;QAED,MAAA,QAAQ,CAAC,OAAO,0CAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC,EACD,CAAC,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,mBAAmB,CAAC,CAC9D,CAAC;IAEF,IAAA,gBAAQ,EAAC,KAAK,CAAC,EAAE;QACf,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,OAAO,CACL,kCACE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,eAAe,EAC7D,QAAQ,EAAE,eAAe,YAEzB,sCAAW,MAAM,EAAE,KAAK,GAAI,GACtB,CACT,CAAC;AACJ,CAAC;AA3ND,iCA2NC"}
|
|
@@ -1656,7 +1656,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1656
1656
|
};
|
|
1657
1657
|
}, [sessionId, userLang, disableTextEnteredEvents]);
|
|
1658
1658
|
const onClickStart = (0, react_1.useCallback)(async (session, initialSessionExpired = false) => {
|
|
1659
|
-
var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
1659
|
+
var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _t;
|
|
1660
1660
|
const sessionID = (session === null || session === void 0 ? void 0 : session.sessionID) || sessionId;
|
|
1661
1661
|
const dialogState = (session === null || session === void 0 ? void 0 : session.dialogState) || currentDialogState;
|
|
1662
1662
|
setClickedStart(true);
|
|
@@ -1666,6 +1666,9 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1666
1666
|
!window.navigator.userAgent.includes('Chrome');
|
|
1667
1667
|
if (memoriAudioElement && isSafari) {
|
|
1668
1668
|
memoriAudioElement.muted = false;
|
|
1669
|
+
memoriAudioElement.play().catch((e) => {
|
|
1670
|
+
console.warn('error playing intro audio', e);
|
|
1671
|
+
});
|
|
1669
1672
|
}
|
|
1670
1673
|
let storageBirthDate = (0, configuration_1.getLocalConfig)('birthDate', undefined);
|
|
1671
1674
|
let birth = birthDate || storageBirthDate || undefined;
|
|
@@ -1724,8 +1727,10 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1724
1727
|
return;
|
|
1725
1728
|
}
|
|
1726
1729
|
else if (initialSessionID) {
|
|
1730
|
+
console.debug('[CLICK_START] Handling initial session');
|
|
1727
1731
|
const { currentState, ...response } = await getSession(sessionID);
|
|
1728
1732
|
if (response.resultCode !== 0 || !currentState) {
|
|
1733
|
+
console.debug('[CLICK_START] Session expired, opening new session');
|
|
1729
1734
|
setGotErrorInOpening(true);
|
|
1730
1735
|
setSessionId(undefined);
|
|
1731
1736
|
setClickedStart(false);
|
|
@@ -1738,8 +1743,9 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1738
1743
|
if (memori.needsDateTime)
|
|
1739
1744
|
sendDateChangedEvent({ sessionID: sessionID, state: currentState });
|
|
1740
1745
|
if (personification &&
|
|
1741
|
-
|
|
1746
|
+
currentState.currentTag !== personification.tag) {
|
|
1742
1747
|
try {
|
|
1748
|
+
console.debug('[CLICK_START] Changing tag for personification', personification, currentState);
|
|
1743
1749
|
await changeTag(memori.engineMemoriID, sessionID, '-');
|
|
1744
1750
|
const session = await changeTag(memori.engineMemoriID, sessionID, personification.tag, personification.pin);
|
|
1745
1751
|
if (session && session.resultCode === 0) {
|
|
@@ -1772,10 +1778,11 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1772
1778
|
}
|
|
1773
1779
|
}
|
|
1774
1780
|
else if (!personification &&
|
|
1775
|
-
(
|
|
1776
|
-
(
|
|
1777
|
-
(
|
|
1781
|
+
(currentState === null || currentState === void 0 ? void 0 : currentState.currentTag) &&
|
|
1782
|
+
(currentState === null || currentState === void 0 ? void 0 : currentState.currentTag) !== constants_1.anonTag &&
|
|
1783
|
+
(currentState === null || currentState === void 0 ? void 0 : currentState.currentTag) !== '-') {
|
|
1778
1784
|
try {
|
|
1785
|
+
console.debug('[CLICK_START] Changing to anonymous tag');
|
|
1779
1786
|
await changeTag(memori.engineMemoriID, sessionID, '-');
|
|
1780
1787
|
const session = await changeTag(memori.engineMemoriID, sessionID, constants_1.anonTag);
|
|
1781
1788
|
if (session && session.resultCode === 0) {
|
|
@@ -1809,6 +1816,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1809
1816
|
}
|
|
1810
1817
|
else {
|
|
1811
1818
|
try {
|
|
1819
|
+
console.debug('[CLICK_START] Getting chat history');
|
|
1812
1820
|
const { chatLogs, ...resp } = await getSessionChatLogs(sessionID, sessionID);
|
|
1813
1821
|
const messages = (_r = chatLogs === null || chatLogs === void 0 ? void 0 : chatLogs[0]) === null || _r === void 0 ? void 0 : _r.lines.map((l, i) => {
|
|
1814
1822
|
var _a, _b;
|
|
@@ -1824,10 +1832,11 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1824
1832
|
initial: i === 0,
|
|
1825
1833
|
});
|
|
1826
1834
|
});
|
|
1827
|
-
translatedMessages = messages;
|
|
1835
|
+
translatedMessages = messages !== null && messages !== void 0 ? messages : [];
|
|
1828
1836
|
if (language.toUpperCase() !== userLang.toUpperCase() &&
|
|
1829
1837
|
isMultilanguageEnabled) {
|
|
1830
1838
|
try {
|
|
1839
|
+
console.debug('[CLICK_START] Translating messages');
|
|
1831
1840
|
translatedMessages = await Promise.all(messages.map(async (m) => ({
|
|
1832
1841
|
...m,
|
|
1833
1842
|
originalText: m.text,
|
|
@@ -1838,19 +1847,42 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1838
1847
|
}
|
|
1839
1848
|
}
|
|
1840
1849
|
setHistory(translatedMessages);
|
|
1850
|
+
console.debug('[CLICK_START] props currentState:', currentState, 'userLang:', userLang, 'translatedMessages:', translatedMessages, 'history:', history);
|
|
1841
1851
|
}
|
|
1842
1852
|
catch (e) {
|
|
1853
|
+
console.log('[CLICK_START] Error retrieving chat logs:', e);
|
|
1854
|
+
}
|
|
1855
|
+
if ((!!(translatedMessages === null || translatedMessages === void 0 ? void 0 : translatedMessages.length) && translatedMessages.length > 1) ||
|
|
1856
|
+
!initialQuestion) {
|
|
1857
|
+
translateDialogState(currentState, userLang, undefined, !!(translatedMessages === null || translatedMessages === void 0 ? void 0 : translatedMessages.length))
|
|
1858
|
+
.then(ts => {
|
|
1859
|
+
let text = ts.translatedEmission || ts.emission;
|
|
1860
|
+
if (text) {
|
|
1861
|
+
speak(text);
|
|
1862
|
+
}
|
|
1863
|
+
})
|
|
1864
|
+
.finally(() => {
|
|
1865
|
+
setHasUserActivatedSpeak(true);
|
|
1866
|
+
});
|
|
1867
|
+
}
|
|
1868
|
+
else {
|
|
1869
|
+
translatedMessages = [];
|
|
1870
|
+
setHistory([]);
|
|
1871
|
+
const response = await postTextEnteredEvent({
|
|
1872
|
+
sessionId: sessionID,
|
|
1873
|
+
text: initialQuestion,
|
|
1874
|
+
});
|
|
1875
|
+
translateDialogState((_t = response.currentState) !== null && _t !== void 0 ? _t : currentState, userLang, undefined, false)
|
|
1876
|
+
.then(ts => {
|
|
1877
|
+
let text = ts.translatedEmission || ts.emission;
|
|
1878
|
+
if (text) {
|
|
1879
|
+
speak(text);
|
|
1880
|
+
}
|
|
1881
|
+
})
|
|
1882
|
+
.finally(() => {
|
|
1883
|
+
setHasUserActivatedSpeak(true);
|
|
1884
|
+
});
|
|
1843
1885
|
}
|
|
1844
|
-
translateDialogState(currentState, userLang, undefined, true)
|
|
1845
|
-
.then(ts => {
|
|
1846
|
-
let text = ts.translatedEmission || ts.emission;
|
|
1847
|
-
if (text) {
|
|
1848
|
-
speak(text);
|
|
1849
|
-
}
|
|
1850
|
-
})
|
|
1851
|
-
.finally(() => {
|
|
1852
|
-
setHasUserActivatedSpeak(true);
|
|
1853
|
-
});
|
|
1854
1886
|
}
|
|
1855
1887
|
if (position)
|
|
1856
1888
|
applyPosition(position, sessionID);
|
|
@@ -1858,6 +1890,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1858
1890
|
sendDateChangedEvent({ sessionID: sessionID, state: currentState });
|
|
1859
1891
|
}
|
|
1860
1892
|
else {
|
|
1893
|
+
console.debug('[CLICK_START] Using existing session');
|
|
1861
1894
|
setHistory([]);
|
|
1862
1895
|
translateDialogState(dialogState, userLang)
|
|
1863
1896
|
.then(ts => {
|