1use enum2schema::Schema;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, Schema)]
10pub struct EntityRef {
11 pub id: u32,
12 pub generation: u32,
13}
14
15pub type CorrelationId = u64;
18
19pub type SubscriptionId = u64;
22
23pub type Version = u64;
25
26#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
28pub enum WritePolicyInfo {
29 Free,
31 Owned { command: String },
34 Derived,
37}
38
39#[derive(Clone, Debug, Serialize, Deserialize)]
42pub struct ComponentInfo {
43 pub name: String,
44 pub write_policy: WritePolicyInfo,
45 pub schema: Value,
47 pub example: Value,
50}
51
52#[derive(Clone, Debug, Serialize, Deserialize)]
56pub enum AgentCommand {
57 Reparent {
58 child: EntityRef,
59 new_parent: Option<EntityRef>,
60 },
61 DeleteEntity {
62 entity: EntityRef,
63 },
64 LoadGltf {
65 uri: String,
66 },
67 SelectNode {
68 entity: EntityRef,
69 },
70 SetActiveCamera {
72 entity: EntityRef,
73 },
74 LoadPolyhavenModel {
76 slug: String,
77 resolution: u32,
78 },
79 AddPrimitive {
82 kind: super::ShapeKind,
83 components: Vec<(String, Value)>,
84 },
85 AddLight {
87 kind: super::LightKind,
88 components: Vec<(String, Value)>,
89 },
90 ClearScene,
94 SpawnEntity {
95 components: Vec<(String, Value)>,
96 },
97 SetComponents {
98 entity: EntityRef,
99 components: Vec<(String, Value)>,
100 },
101 RemoveComponents {
102 entity: EntityRef,
103 component_types: Vec<String>,
104 },
105}
106
107#[derive(Clone, Debug, Serialize, Deserialize, Schema)]
109pub struct SubscriptionFilter {
110 pub component_types: Vec<String>,
111 pub entities: Option<Vec<EntityRef>>,
112}
113
114#[derive(Clone, Debug, Default, Serialize, Deserialize, Schema)]
118pub struct MaterialSpec {
119 pub name: String,
120 pub base_color: Option<[f32; 4]>,
122 pub metallic: Option<f32>,
123 pub roughness: Option<f32>,
124 pub emissive_factor: Option<[f32; 3]>,
125 pub emissive_strength: Option<f32>,
126 pub unlit: Option<bool>,
127 pub double_sided: Option<bool>,
128 pub base_texture: Option<String>,
133 pub tiling: Option<f32>,
138 pub normal_texture: Option<String>,
140 pub normal_scale: Option<f32>,
142 pub metallic_roughness_texture: Option<String>,
144 pub emissive_texture: Option<String>,
146 pub occlusion_texture: Option<String>,
148 pub occlusion_strength: Option<f32>,
150 pub alpha_mode: Option<String>,
152 pub alpha_cutoff: Option<f32>,
154}
155
156#[derive(Clone, Debug, Default, Serialize, Deserialize, Schema)]
161pub struct RenderSettingsPatch {
162 pub ambient_light: Option<[f32; 4]>,
163 pub bloom_enabled: Option<bool>,
164 pub bloom_intensity: Option<f32>,
165 pub bloom_threshold: Option<f32>,
166 pub bloom_knee: Option<f32>,
167 pub bloom_filter_radius: Option<f32>,
168 pub ssao_enabled: Option<bool>,
169 pub ssao_radius: Option<f32>,
170 pub ssao_intensity: Option<f32>,
171 pub ssao_bias: Option<f32>,
172 pub ssao_sample_count: Option<u32>,
173 pub ssgi_enabled: Option<bool>,
174 pub ssgi_radius: Option<f32>,
175 pub ssgi_intensity: Option<f32>,
176 pub ssgi_max_steps: Option<u32>,
177 pub ssr_enabled: Option<bool>,
178 pub ssr_max_steps: Option<u32>,
179 pub ssr_thickness: Option<f32>,
180 pub ssr_max_distance: Option<f32>,
181 pub ssr_stride: Option<f32>,
182 pub ssr_fade_start: Option<f32>,
183 pub ssr_fade_end: Option<f32>,
184 pub ssr_intensity: Option<f32>,
185 pub fog_enabled: Option<bool>,
186 pub fog_color: Option<[f32; 3]>,
187 pub fog_start: Option<f32>,
188 pub fog_end: Option<f32>,
189 pub dof_enabled: Option<bool>,
190 pub dof_focus_distance: Option<f32>,
191 pub dof_focus_range: Option<f32>,
192 pub dof_max_blur_radius: Option<f32>,
193 pub dof_quality: Option<u32>,
195 pub taa_enabled: Option<bool>,
196 pub render_scale: Option<f32>,
197 pub ibl_blend_factor: Option<f32>,
198 pub unlit_mode: Option<bool>,
199 pub selection_outline_enabled: Option<bool>,
200 pub selection_outline_color: Option<[f32; 4]>,
201 pub exposure: Option<f32>,
202 pub saturation: Option<f32>,
203 pub contrast: Option<f32>,
204 pub brightness: Option<f32>,
205 pub gamma: Option<f32>,
206 pub show_grid: Option<bool>,
207 pub show_normals: Option<bool>,
208 pub ssao_visualization: Option<bool>,
209 pub navmesh_debug: Option<bool>,
210 pub pbr_debug_index: Option<u32>,
212}
213
214#[derive(Clone, Debug, Default, Serialize, Deserialize, Schema)]
217pub struct Environment {
218 pub atmosphere: Option<String>,
220 pub show_sky: Option<bool>,
221 pub clear_color: Option<[f32; 4]>,
223 pub hour: Option<f32>,
225 pub exposure: Option<f32>,
226 pub hdri_uri: Option<String>,
228}
229
230#[derive(Clone, Debug, Serialize, Deserialize)]
233pub enum AgentRequest {
234 ListComponentTypes {
235 correlation_id: CorrelationId,
236 },
237 Query {
238 correlation_id: CorrelationId,
239 component_types: Vec<String>,
240 },
241 GetComponents {
242 correlation_id: CorrelationId,
243 entity: EntityRef,
244 component_types: Vec<String>,
245 },
246 Command {
247 correlation_id: CorrelationId,
248 command: AgentCommand,
249 },
250 Subscribe {
251 correlation_id: CorrelationId,
252 filter: SubscriptionFilter,
253 },
254 Unsubscribe {
255 correlation_id: CorrelationId,
256 subscription_id: SubscriptionId,
257 },
258 ControlAnimation {
260 correlation_id: CorrelationId,
261 entity: EntityRef,
262 command: super::AnimationCommand,
263 },
264 SetRenderSettings {
266 correlation_id: CorrelationId,
267 settings: RenderSettingsPatch,
268 },
269 SceneTree {
271 correlation_id: CorrelationId,
272 },
273 EditorAction {
276 correlation_id: CorrelationId,
277 action: Box<super::EditorAction>,
278 },
279 GetEditorState {
283 correlation_id: CorrelationId,
284 },
285 SetEnvironment {
287 correlation_id: CorrelationId,
288 environment: Environment,
289 },
290 SetMaterial {
292 correlation_id: CorrelationId,
293 material: MaterialSpec,
294 },
295 ListMaterials {
297 correlation_id: CorrelationId,
298 },
299 ListAssets {
304 correlation_id: CorrelationId,
305 search: Option<String>,
306 },
307 Screenshot {
312 correlation_id: CorrelationId,
313 camera: Option<EntityRef>,
314 max_dimension: Option<u32>,
315 },
316}
317
318#[derive(Clone, Debug, Serialize, Deserialize)]
321pub enum GetResult {
322 Live {
323 entity: EntityRef,
324 components: Vec<(String, Value)>,
325 },
326 NotLive {
327 entity: EntityRef,
328 },
329}
330
331#[derive(Clone, Debug, Serialize, Deserialize)]
333pub struct SnapshotEntity {
334 pub entity: EntityRef,
335 pub components: Vec<(String, Value)>,
336}
337
338#[derive(Clone, Debug, Serialize, Deserialize)]
341pub struct Snapshot {
342 pub version: Version,
343 pub entities: Vec<SnapshotEntity>,
344}
345
346#[derive(Clone, Debug, Serialize, Deserialize)]
349pub struct Checksum {
350 pub version: Version,
351 pub digest: u64,
352}
353
354#[derive(Clone, Debug, Serialize, Deserialize)]
358pub enum Delta {
359 Changed {
360 entity: EntityRef,
361 component: String,
362 value: Value,
363 origin: Option<CorrelationId>,
364 },
365 Added {
366 entity: EntityRef,
367 component: String,
368 value: Value,
369 origin: Option<CorrelationId>,
370 },
371 Removed {
372 entity: EntityRef,
373 component: String,
374 origin: Option<CorrelationId>,
375 },
376 Spawned {
377 entity: EntityRef,
378 components: Vec<(String, Value)>,
379 origin: Option<CorrelationId>,
380 },
381 Despawned {
382 entity: EntityRef,
383 origin: Option<CorrelationId>,
384 },
385}
386
387#[derive(Clone, Debug, Serialize, Deserialize)]
391pub struct DeltaBatch {
392 pub base_version: Version,
393 pub target_version: Version,
394 pub deltas: Vec<Delta>,
395 pub checksum: Option<Checksum>,
396}
397
398#[derive(Clone, Debug, Serialize, Deserialize)]
400pub enum AgentResponse {
401 ComponentTypes {
402 correlation_id: CorrelationId,
403 components: Vec<ComponentInfo>,
404 },
405 QueryResult {
406 correlation_id: CorrelationId,
407 entities: Vec<EntityRef>,
408 },
409 GetResult {
410 correlation_id: CorrelationId,
411 result: GetResult,
412 },
413 CommandApplied {
416 correlation_id: CorrelationId,
417 version: Version,
418 },
419 Loaded {
422 correlation_id: CorrelationId,
423 version: Version,
424 roots: Vec<EntityRef>,
425 },
426 CommandFailed {
427 correlation_id: CorrelationId,
428 error: String,
429 },
430 CommandProgress {
431 correlation_id: CorrelationId,
432 stage: String,
433 },
434 Subscribed {
435 correlation_id: CorrelationId,
436 subscription_id: SubscriptionId,
437 snapshot: Snapshot,
438 },
439 Unsubscribed {
440 correlation_id: CorrelationId,
441 subscription_id: SubscriptionId,
442 },
443 EditorState {
445 correlation_id: CorrelationId,
446 state: Value,
447 },
448 Materials {
450 correlation_id: CorrelationId,
451 materials: Value,
452 },
453 Assets {
455 correlation_id: CorrelationId,
456 assets: Value,
457 },
458 Screenshot {
460 correlation_id: CorrelationId,
461 width: u32,
462 height: u32,
463 png_base64: String,
464 },
465 Batch { batch: DeltaBatch },
467 SceneTree {
469 correlation_id: CorrelationId,
470 rows: Value,
471 },
472 Log { entries: Value },
476}