Skip to content

Commit 482db12

Browse files
author
Kevin
committed
Refactor robot model and update agent state handling
- Updated `robot-final.gltf` to include clearcoat and sheen material extensions, adjusted mesh translations, and modified material properties. - Deleted obsolete `robot-high.bin` and `robot-high.gltf` files. - Enhanced `Status` component to display agent state and improved status logic based on constraints and state. - Modified `useRun` to track agent state changes and structured cloning for state management. - Updated state management in `state.ts` to include agent state tracking. - Refined `Agent` and `Agents` components for better visual representation of agent states. - Adjusted `Domain` component to optimize texture filtering. - Improved lighting calculations in `Light` component for better performance. - Updated `Stage` component to enhance rendering settings and fog color. - Introduced a new `colors.tsx` file for centralized color management.
1 parent 1cd0029 commit 482db12

File tree

14 files changed

+175
-700
lines changed

14 files changed

+175
-700
lines changed

public/base.png

-184 Bytes
Loading

public/robot-final.bin

32 Bytes
Binary file not shown.

public/robot-final.gltf

Lines changed: 97 additions & 75 deletions
Large diffs are not rendered by default.

public/robot-high.bin

-11.9 MB
Binary file not shown.

public/robot-high.gltf

Lines changed: 0 additions & 584 deletions
This file was deleted.

src/Status.tsx

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import { useAgentInfo } from "client/state";
2+
import { colors } from "colors";
23
import { Components } from "leva/plugin";
34
import { chain, noop } from "lodash";
45
import { useCss } from "react-use";
56

6-
const colors = {
7-
warning: "#ffc400",
8-
success: "#00e676",
9-
};
10-
117
const vectorProps = {
128
onUpdate: noop,
139
settings: {
@@ -62,18 +58,23 @@ export function Status({ id }: { id: number }) {
6258
},
6359
});
6460
if (!a) return null;
65-
const status = a.constraints?.length
66-
? {
67-
color: colors.warning,
68-
label: `Waiting for ${chain(a.constraints)
69-
.map((c) => c.id)
70-
.uniq()
71-
.thru(
72-
(ids) => `${ids.length > 1 ? "agents" : "agent"} ${ids.join(", ")}`
73-
)
74-
.value()}`,
75-
}
76-
: { color: colors.success, label: "Healthy" };
61+
console.log(a.state);
62+
const status =
63+
a.constraints?.length || a.state === "idle"
64+
? {
65+
color: a.state === "idle" ? colors.error : colors.warning,
66+
label: `${
67+
a.state === "idle" ? "Waiting for" : "Constrained by"
68+
} ${chain(a.constraints)
69+
.map((c) => c.id)
70+
.uniq()
71+
.thru(
72+
(ids) =>
73+
`${ids.length > 1 ? "agents" : "agent"} ${ids.join(", ")}`
74+
)
75+
.value()}`,
76+
}
77+
: { color: colors.success, label: "Healthy" };
7778
return (
7879
<div className={cls}>
7980
<h4>
@@ -82,6 +83,7 @@ export function Status({ id }: { id: number }) {
8283
<Dot color={status.color} /> {status.label}
8384
</span>
8485
</h4>
86+
<p>State: {a.state}</p>
8587
<Components.Row input>
8688
<Components.Label>Position</Components.Label>
8789
<Components.Vector

src/client/run.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@ import { useMutation, useQuery } from "@tanstack/react-query";
22
import { Mutex } from "async-mutex";
33
import { client } from "client/trpc";
44
import { atom, useAtom, useAtomValue, useSetAtom } from "jotai";
5-
import { identity, isArray, slice, throttle, trim } from "lodash";
5+
import {
6+
clone,
7+
cloneDeep,
8+
identity,
9+
isArray,
10+
isNumber,
11+
range,
12+
slice,
13+
throttle,
14+
trim,
15+
} from "lodash";
616
import { useRef } from "react";
717
import { AdgProgress, Output } from "smart";
818
import { id } from "utils";
@@ -92,6 +102,7 @@ export function useRun() {
92102
1500,
93103
{ trailing: true, leading: false }
94104
);
105+
const agentState: State["agentState"] = {};
95106
let adg: AdgProgress | undefined = undefined;
96107
return await new Promise<void>((res, rej) => {
97108
abort.current = () => {
@@ -109,6 +120,17 @@ export function useRun() {
109120
for (const d of data) {
110121
if ("type" in d) {
111122
switch (d.type) {
123+
case "state_change":
124+
if (isNumber(d.agent)) {
125+
console.log(d.agent, d.value);
126+
agentState[d.agent] = d.value;
127+
console.log(structuredClone(agentState));
128+
} else {
129+
range(contents.count).forEach((i) => {
130+
agentState[i] = d.value;
131+
});
132+
}
133+
break;
112134
case "message":
113135
setLog((t) => slice([...t, d.content], -100));
114136
break;
@@ -119,7 +141,11 @@ export function useRun() {
119141
adg = d;
120142
break;
121143
case "tick":
122-
actions.push({ state: d, adg });
144+
actions.push({
145+
state: d,
146+
adg,
147+
agentState: structuredClone(agentState),
148+
});
123149
f();
124150
break;
125151
case "error":

src/client/state.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import { store } from "store";
1717
import { useEffect, useMemo, useState } from "react";
1818
import { useEffectOnce } from "react-use";
19-
import { AdgProgress, Step } from "smart";
19+
import { AdgProgress, StateChange, Step } from "smart";
2020
import { lerp, lerpRadians } from "utils";
2121
import { useSpeed } from "./play";
2222
import { selectionAtom } from "./selection";
@@ -26,6 +26,7 @@ const CHUNK_SIZE = 256;
2626
export type State = {
2727
state: Step;
2828
adg?: AdgProgress;
29+
agentState?: Record<number, StateChange["value"]>;
2930
};
3031

3132
export const logAtom = atom<string[]>([]);
@@ -101,6 +102,7 @@ export const useAgentInfo = (i: number) => {
101102
const agent = a?.state?.agents?.[i];
102103
if (!agent) return;
103104
return {
105+
state: a.agentState?.[i],
104106
constraints: a.adg?.constraints?.[i]?.constraining_agent,
105107
position: [agent.x + 0.5, 0, -agent.y - 0.5] as [
106108
number,
@@ -133,6 +135,7 @@ export const useAgentPosition = (i: number) => {
133135
// Teleport if too far away
134136
if (dist(p.position, v0.position) > 0.5) return v0;
135137
return {
138+
state: v0.state,
136139
constraints: v0.constraints,
137140
position: zip(p.position, v0.position).map(([a, b]) =>
138141
lerp(a!, b!, alpha(speed))

src/colors.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const colors = {
2+
warning: "#ffc400",
3+
success: "#00e676",
4+
error: "#f50057",
5+
};

src/components/Agent.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ComponentProps, Suspense } from "react";
1616
import { useBoolean, useTween } from "react-use";
1717
import { DoubleSide } from "three";
1818
import { rectangleRounded } from "./rectangleRounded";
19+
import { colors } from "colors";
1920

2021
const font = `./fonts/geist-medium.ttf`;
2122

@@ -95,7 +96,6 @@ export function Path({
9596
const dest = last(path);
9697

9798
const { current: a } = useAgentPosition(id);
98-
9999
const constrained = !!a?.constraints?.length;
100100

101101
return (
@@ -131,19 +131,25 @@ export function Path({
131131
renderOrder={9998}
132132
dashScale={5}
133133
depthTest={false}
134-
lineWidth={s.scale.to((s) => s * 6)}
134+
lineWidth={s.scale.to((s) => s * 4)}
135135
color="#fff"
136136
points={path}
137137
dashed
138138
/>
139139
<AnimatedRing
140140
scale={s.scale}
141141
args={[0.6 / 2, 0.7 / 2, 32, 32]}
142-
position={[x, y - 0.09, z]}
142+
position={[x, y - 0.06, z]}
143143
rotation={[-Math.PI / 2, 0, 0]}
144144
>
145145
<meshBasicMaterial
146-
color={constrained ? "#ffc400" : "#00e676"}
146+
color={
147+
a?.state === "idle"
148+
? colors.error
149+
: constrained
150+
? colors.warning
151+
: colors.success
152+
}
147153
/>
148154
</AnimatedRing>
149155
<AnimatedRing
@@ -153,7 +159,7 @@ export function Path({
153159
position={dest}
154160
rotation={[-Math.PI / 2, 0, 0]}
155161
>
156-
<meshBasicMaterial color={"#f50057"} depthTest={false} />
162+
<meshBasicMaterial color={colors.error} depthTest={false} />
157163
</AnimatedRing>
158164
<AnimatedRing
159165
renderOrder={9999}
@@ -162,7 +168,7 @@ export function Path({
162168
position={src}
163169
rotation={[-Math.PI / 2, 0, 0]}
164170
>
165-
<meshBasicMaterial color={"#00e676"} depthTest={false} />
171+
<meshBasicMaterial color={colors.success} depthTest={false} />
166172
</AnimatedRing>
167173
{a?.constraints?.map?.(({ id: to }) => (
168174
<Constraint
@@ -200,7 +206,6 @@ export function Agent({ i, ...props }: { i: number } & InstanceProps) {
200206
if (!a) {
201207
return undefined;
202208
}
203-
204209
return (
205210
<>
206211
<Suspense fallback={null}>

0 commit comments

Comments
 (0)