@agent-os-lab/agent-game-sdk 0.1.15 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
package/USAGE.md
CHANGED
|
@@ -188,6 +188,7 @@ import { mountAgentAvatar3D } from "@agent-os-lab/agent-game-sdk/avatar";
|
|
|
188
188
|
|
|
189
189
|
const view = mountAgentAvatar3D(container, {
|
|
190
190
|
agentId: "agent-1",
|
|
191
|
+
backgroundColor: "#f8fafc",
|
|
191
192
|
sceneState: "working",
|
|
192
193
|
framing: "upperBody",
|
|
193
194
|
viewAngle: "front",
|
|
@@ -209,6 +210,7 @@ view.destroy();
|
|
|
209
210
|
```
|
|
210
211
|
|
|
211
212
|
`framing` supports `fullBody` and `upperBody`. `viewAngle` supports `front` and `threeQuarter`.
|
|
213
|
+
The default 3D avatar background is transparent. Pass `backgroundColor` when the canvas or thumbnail should render with a solid color.
|
|
212
214
|
Use `camera` to fine-tune the portrait crop with `fov`, `positionY`, `positionZ`, and `lookAtY`.
|
|
213
215
|
Passing the same `agentId` used in the office game gives the standalone 3D view the same appearance as the office game scene. Use `renderIndex` only when you need to override that AgentID-derived appearance.
|
|
214
216
|
|
package/package.json
CHANGED
|
@@ -28,6 +28,7 @@ export type ResolvedAgentAvatar3DCameraOptions = Required<AgentAvatar3DCameraOpt
|
|
|
28
28
|
|
|
29
29
|
export type AgentAvatar3DSceneOptions = {
|
|
30
30
|
agent?: Partial<AgentGameOfficeAgent>;
|
|
31
|
+
backgroundColor?: THREE.ColorRepresentation | null;
|
|
31
32
|
camera?: AgentAvatar3DCameraOptions;
|
|
32
33
|
agentId?: string;
|
|
33
34
|
framing?: AgentAvatar3DFraming;
|
|
@@ -52,6 +53,7 @@ export type AgentAvatar3DScene = {
|
|
|
52
53
|
bodyLayer: AgentBodyInstancedLayer;
|
|
53
54
|
effectLayer: AgentEffectInstancedLayer;
|
|
54
55
|
state: ResolvedAgentAvatar3DState;
|
|
56
|
+
setBackground(backgroundColor?: THREE.ColorRepresentation | null): void;
|
|
55
57
|
setState(options: AgentAvatar3DSceneOptions, preservedRenderIndex?: number): ResolvedAgentAvatar3DState;
|
|
56
58
|
render(renderer: { render(scene: THREE.Scene, camera: THREE.Camera): void }, nowMs: number): void;
|
|
57
59
|
dispose(): void;
|
|
@@ -59,7 +61,7 @@ export type AgentAvatar3DScene = {
|
|
|
59
61
|
|
|
60
62
|
export function createAgentAvatar3DScene(options: AgentAvatar3DSceneOptions): AgentAvatar3DScene {
|
|
61
63
|
const scene = new THREE.Scene();
|
|
62
|
-
scene
|
|
64
|
+
applyAvatar3DBackground(scene, options.backgroundColor);
|
|
63
65
|
const camera = new THREE.PerspectiveCamera(38, options.width / options.height, 0.1, 100);
|
|
64
66
|
scene.add(new THREE.HemisphereLight(0xffffff, 0xd9e2ef, 1.8));
|
|
65
67
|
const keyLight = new THREE.DirectionalLight(0xffffff, 1.4);
|
|
@@ -84,8 +86,14 @@ export function createAgentAvatar3DScene(options: AgentAvatar3DSceneOptions): Ag
|
|
|
84
86
|
get state() {
|
|
85
87
|
return state;
|
|
86
88
|
},
|
|
89
|
+
setBackground(backgroundColor) {
|
|
90
|
+
applyAvatar3DBackground(scene, backgroundColor);
|
|
91
|
+
},
|
|
87
92
|
setState(nextOptions, preservedRenderIndex) {
|
|
88
93
|
state = resolveAgentAvatar3DState(nextOptions, preservedRenderIndex);
|
|
94
|
+
if ("backgroundColor" in nextOptions) {
|
|
95
|
+
applyAvatar3DBackground(scene, nextOptions.backgroundColor);
|
|
96
|
+
}
|
|
89
97
|
applyAvatar3DViewAngle(mesh.group, state.viewAngle);
|
|
90
98
|
applyAvatar3DCamera(camera, state.camera);
|
|
91
99
|
return state;
|
|
@@ -125,6 +133,12 @@ export function resolveAgentAvatar3DState(
|
|
|
125
133
|
};
|
|
126
134
|
}
|
|
127
135
|
|
|
136
|
+
function applyAvatar3DBackground(scene: THREE.Scene, backgroundColor?: THREE.ColorRepresentation | null): void {
|
|
137
|
+
scene.background = backgroundColor === undefined || backgroundColor === null
|
|
138
|
+
? null
|
|
139
|
+
: new THREE.Color(backgroundColor);
|
|
140
|
+
}
|
|
141
|
+
|
|
128
142
|
function resolveAgentAvatar3DCamera(
|
|
129
143
|
framing: AgentAvatar3DFraming,
|
|
130
144
|
camera?: AgentAvatar3DCameraOptions,
|
package/src/avatar/three-view.ts
CHANGED
|
@@ -21,6 +21,7 @@ export type AgentAvatar3DViewAngle = "front" | "threeQuarter";
|
|
|
21
21
|
|
|
22
22
|
export type AgentAvatar3DOptions = {
|
|
23
23
|
agent?: Partial<AgentGameOfficeAgent>;
|
|
24
|
+
backgroundColor?: THREE.ColorRepresentation | null;
|
|
24
25
|
camera?: AgentAvatar3DCameraOptions;
|
|
25
26
|
agentId?: string;
|
|
26
27
|
framing?: AgentAvatar3DFraming;
|
|
@@ -38,7 +39,7 @@ export type AgentAvatar3DOptions = {
|
|
|
38
39
|
|
|
39
40
|
export type AgentAvatar3DUpdateOptions = Partial<Pick<
|
|
40
41
|
AgentAvatar3DOptions,
|
|
41
|
-
"agent" | "agentId" | "camera" | "framing" | "sceneState" | "renderIndex" | "viewAngle"
|
|
42
|
+
"agent" | "agentId" | "backgroundColor" | "camera" | "framing" | "sceneState" | "renderIndex" | "viewAngle"
|
|
42
43
|
>>;
|
|
43
44
|
|
|
44
45
|
export type AgentAvatar3DController = {
|
|
@@ -91,6 +92,7 @@ export function mountAgentAvatar3D(
|
|
|
91
92
|
avatarScene.setState({
|
|
92
93
|
agent: { ...avatarScene.state, ...nextOptions.agent },
|
|
93
94
|
agentId: nextOptions.agentId,
|
|
95
|
+
backgroundColor: nextOptions.backgroundColor,
|
|
94
96
|
camera: nextOptions.camera ?? (framingChanged ? undefined : avatarScene.state.camera),
|
|
95
97
|
framing: nextOptions.framing ?? avatarScene.state.framing,
|
|
96
98
|
sceneState: nextOptions.sceneState ?? avatarScene.state.sceneState,
|
|
@@ -115,6 +115,7 @@ export function applyAgentPose(
|
|
|
115
115
|
function resetPose(mesh: AgentMeshParts): void {
|
|
116
116
|
mesh.visualRoot.position.y = 0;
|
|
117
117
|
mesh.body.rotation.set(0, 0, 0);
|
|
118
|
+
mesh.headRoot.rotation.set(0, 0, 0);
|
|
118
119
|
mesh.head.rotation.set(0, 0, 0);
|
|
119
120
|
mesh.leftArm.rotation.set(0, 0, 0);
|
|
120
121
|
mesh.rightArm.rotation.set(0, 0, 0);
|
|
@@ -150,7 +151,7 @@ function applyPoseMode(
|
|
|
150
151
|
applySeatedLowerBody(mesh);
|
|
151
152
|
mesh.visualRoot.position.y = CHAIR_SEATED_VISUAL_Y;
|
|
152
153
|
mesh.body.rotation.x = -0.1;
|
|
153
|
-
mesh.
|
|
154
|
+
mesh.headRoot.rotation.x = -0.06;
|
|
154
155
|
mesh.leftArm.rotation.x = 0.58 + Math.sin(phase) * 0.18;
|
|
155
156
|
mesh.rightArm.rotation.x = 0.58 - Math.sin(phase) * 0.18;
|
|
156
157
|
mesh.leftArm.rotation.z = -0.08;
|
|
@@ -158,21 +159,21 @@ function applyPoseMode(
|
|
|
158
159
|
return;
|
|
159
160
|
}
|
|
160
161
|
case "thinking":
|
|
161
|
-
mesh.
|
|
162
|
-
mesh.
|
|
162
|
+
mesh.headRoot.rotation.y = Math.sin(elapsedSeconds * 1.2) * 0.35;
|
|
163
|
+
mesh.headRoot.rotation.x = Math.sin(elapsedSeconds * 0.9) * 0.08;
|
|
163
164
|
mesh.body.rotation.z = Math.sin(elapsedSeconds * 1.6) * 0.07;
|
|
164
165
|
return;
|
|
165
166
|
case "meeting":
|
|
166
167
|
applySeatedLowerBody(mesh);
|
|
167
168
|
mesh.visualRoot.position.y = CHAIR_SEATED_VISUAL_Y;
|
|
168
|
-
mesh.
|
|
169
|
+
mesh.headRoot.rotation.x = Math.sin(elapsedSeconds * 2) * 0.08;
|
|
169
170
|
mesh.leftArm.rotation.x = 0.08;
|
|
170
171
|
mesh.rightArm.rotation.x = -0.08;
|
|
171
172
|
return;
|
|
172
173
|
case "waiting":
|
|
173
174
|
applySeatedLowerBody(mesh);
|
|
174
175
|
mesh.visualRoot.position.y = CHAIR_SEATED_VISUAL_Y;
|
|
175
|
-
mesh.
|
|
176
|
+
mesh.headRoot.rotation.y = Math.sin(elapsedSeconds * 0.9) * 0.12;
|
|
176
177
|
return;
|
|
177
178
|
case "resting": {
|
|
178
179
|
const breath = 1 + Math.sin(elapsedSeconds * 1.2) * 0.025;
|
|
@@ -180,7 +181,7 @@ function applyPoseMode(
|
|
|
180
181
|
mesh.visualRoot.position.y = SOFA_SEATED_VISUAL_Y;
|
|
181
182
|
mesh.body.scale.set(1, breath, 1);
|
|
182
183
|
mesh.body.rotation.x = 0.08;
|
|
183
|
-
mesh.
|
|
184
|
+
mesh.headRoot.rotation.z = Math.sin(elapsedSeconds * 0.8) * 0.05;
|
|
184
185
|
return;
|
|
185
186
|
}
|
|
186
187
|
case "idle": {
|
|
@@ -10,6 +10,7 @@ export type AgentMeshParts = {
|
|
|
10
10
|
group: THREE.Group;
|
|
11
11
|
visualRoot: THREE.Group;
|
|
12
12
|
body: THREE.Object3D;
|
|
13
|
+
headRoot: THREE.Object3D;
|
|
13
14
|
head: THREE.Object3D;
|
|
14
15
|
leftEye: THREE.Object3D;
|
|
15
16
|
rightEye: THREE.Object3D;
|
|
@@ -61,6 +62,15 @@ export type AgentBodyPartRenderSpec = {
|
|
|
61
62
|
z: number;
|
|
62
63
|
};
|
|
63
64
|
|
|
65
|
+
const HEAD_ROOT_PART_KEYS = new Set<AgentBodyPartKey>([
|
|
66
|
+
"head",
|
|
67
|
+
"leftEye",
|
|
68
|
+
"rightEye",
|
|
69
|
+
"mouth",
|
|
70
|
+
"hairTop",
|
|
71
|
+
"hairBack",
|
|
72
|
+
]);
|
|
73
|
+
|
|
64
74
|
export function resolveAgentBodyPartRenderSpecs(index: number): AgentBodyPartRenderSpec[] {
|
|
65
75
|
const shirt = agentColors[index % agentColors.length] ?? agentColors[0];
|
|
66
76
|
const skin = skinColors[index % skinColors.length] ?? skinColors[0];
|
|
@@ -90,11 +100,25 @@ export function createAgentMesh(agent: AgentGameOfficeAgent, index: number): Age
|
|
|
90
100
|
group.scale.setScalar(AGENT_MESH_SCALE);
|
|
91
101
|
const visualRoot = new THREE.Group();
|
|
92
102
|
group.add(visualRoot);
|
|
103
|
+
const specs = resolveAgentBodyPartRenderSpecs(index);
|
|
104
|
+
const headSpec = specs.find((part) => part.key === "head");
|
|
105
|
+
if (!headSpec) {
|
|
106
|
+
throw new Error("Agent mesh head part is required");
|
|
107
|
+
}
|
|
108
|
+
const headRoot = new THREE.Group();
|
|
109
|
+
headRoot.position.set(headSpec.x, headSpec.y, headSpec.z);
|
|
110
|
+
visualRoot.add(headRoot);
|
|
93
111
|
const parts = Object.fromEntries(
|
|
94
|
-
|
|
95
|
-
part.key
|
|
96
|
-
|
|
97
|
-
|
|
112
|
+
specs.map((part) => {
|
|
113
|
+
const parent = HEAD_ROOT_PART_KEYS.has(part.key) ? headRoot : visualRoot;
|
|
114
|
+
const x = HEAD_ROOT_PART_KEYS.has(part.key) ? part.x - headSpec.x : part.x;
|
|
115
|
+
const y = HEAD_ROOT_PART_KEYS.has(part.key) ? part.y - headSpec.y : part.y;
|
|
116
|
+
const z = HEAD_ROOT_PART_KEYS.has(part.key) ? part.z - headSpec.z : part.z;
|
|
117
|
+
return [
|
|
118
|
+
part.key,
|
|
119
|
+
addPart(parent, x, y, z),
|
|
120
|
+
];
|
|
121
|
+
}),
|
|
98
122
|
) as Record<AgentBodyPartKey, THREE.Object3D>;
|
|
99
123
|
const activityGlow = createActivityGlow();
|
|
100
124
|
const activityEffects = createAgentActivityEffects();
|
|
@@ -106,6 +130,7 @@ export function createAgentMesh(agent: AgentGameOfficeAgent, index: number): Age
|
|
|
106
130
|
group,
|
|
107
131
|
visualRoot,
|
|
108
132
|
body: parts.body,
|
|
133
|
+
headRoot,
|
|
109
134
|
head: parts.head,
|
|
110
135
|
leftEye: parts.leftEye,
|
|
111
136
|
rightEye: parts.rightEye,
|