@agent-os-lab/agent-game-sdk 0.1.15 → 0.1.16
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 +1 -0
- package/USAGE.md +2 -0
- package/package.json +1 -1
- package/src/avatar/three-scene.ts +15 -1
- package/src/avatar/three-view.ts +3 -1
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,
|