use enum2schema::Schema;
use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, Schema)]
pub struct EntityRef {
pub id: u32,
pub generation: u32,
}
pub type CorrelationId = u64;
pub type SubscriptionId = u64;
pub type Version = u64;
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum WritePolicyInfo {
Free,
Owned { command: String },
Derived,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ComponentInfo {
pub name: String,
pub write_policy: WritePolicyInfo,
pub schema: Value,
pub example: Value,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum AgentCommand {
Reparent {
child: EntityRef,
new_parent: Option<EntityRef>,
},
DeleteEntity {
entity: EntityRef,
},
LoadGltf {
uri: String,
},
SelectNode {
entity: EntityRef,
},
SetActiveCamera {
entity: EntityRef,
},
LoadPolyhavenModel {
slug: String,
resolution: u32,
},
AddPrimitive {
kind: super::ShapeKind,
components: Vec<(String, Value)>,
},
AddLight {
kind: super::LightKind,
components: Vec<(String, Value)>,
},
ClearScene,
SpawnEntity {
components: Vec<(String, Value)>,
},
SetComponents {
entity: EntityRef,
components: Vec<(String, Value)>,
},
RemoveComponents {
entity: EntityRef,
component_types: Vec<String>,
},
}
#[derive(Clone, Debug, Serialize, Deserialize, Schema)]
pub struct SubscriptionFilter {
pub component_types: Vec<String>,
pub entities: Option<Vec<EntityRef>>,
}
#[derive(Clone, Debug, Default, Serialize, Deserialize, Schema)]
pub struct MaterialSpec {
pub name: String,
pub base_color: Option<[f32; 4]>,
pub metallic: Option<f32>,
pub roughness: Option<f32>,
pub emissive_factor: Option<[f32; 3]>,
pub emissive_strength: Option<f32>,
pub unlit: Option<bool>,
pub double_sided: Option<bool>,
pub base_texture: Option<String>,
pub tiling: Option<f32>,
}
#[derive(Clone, Debug, Default, Serialize, Deserialize, Schema)]
pub struct Environment {
pub atmosphere: Option<String>,
pub show_sky: Option<bool>,
pub clear_color: Option<[f32; 4]>,
pub hour: Option<f32>,
pub exposure: Option<f32>,
pub hdri_uri: Option<String>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum AgentRequest {
ListComponentTypes {
correlation_id: CorrelationId,
},
Query {
correlation_id: CorrelationId,
component_types: Vec<String>,
},
GetComponents {
correlation_id: CorrelationId,
entity: EntityRef,
component_types: Vec<String>,
},
Command {
correlation_id: CorrelationId,
command: AgentCommand,
},
Subscribe {
correlation_id: CorrelationId,
filter: SubscriptionFilter,
},
Unsubscribe {
correlation_id: CorrelationId,
subscription_id: SubscriptionId,
},
Resync {
subscription_id: SubscriptionId,
known_version: Version,
},
EditorAction {
correlation_id: CorrelationId,
action: Box<super::EditorAction>,
},
GetEditorState {
correlation_id: CorrelationId,
},
SetEnvironment {
correlation_id: CorrelationId,
environment: Environment,
},
SetMaterial {
correlation_id: CorrelationId,
material: MaterialSpec,
},
ListMaterials {
correlation_id: CorrelationId,
},
ListAssets {
correlation_id: CorrelationId,
search: Option<String>,
},
Screenshot {
correlation_id: CorrelationId,
camera: Option<EntityRef>,
max_dimension: Option<u32>,
},
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum GetResult {
Live {
entity: EntityRef,
components: Vec<(String, Value)>,
},
NotLive {
entity: EntityRef,
},
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SnapshotEntity {
pub entity: EntityRef,
pub components: Vec<(String, Value)>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Snapshot {
pub version: Version,
pub entities: Vec<SnapshotEntity>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Checksum {
pub version: Version,
pub digest: u64,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum Delta {
Changed {
entity: EntityRef,
component: String,
value: Value,
origin: Option<CorrelationId>,
},
Added {
entity: EntityRef,
component: String,
value: Value,
origin: Option<CorrelationId>,
},
Removed {
entity: EntityRef,
component: String,
origin: Option<CorrelationId>,
},
Spawned {
entity: EntityRef,
components: Vec<(String, Value)>,
origin: Option<CorrelationId>,
},
Despawned {
entity: EntityRef,
origin: Option<CorrelationId>,
},
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct DeltaBatch {
pub base_version: Version,
pub target_version: Version,
pub deltas: Vec<Delta>,
pub checksum: Option<Checksum>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum AgentResponse {
ComponentTypes {
correlation_id: CorrelationId,
components: Vec<ComponentInfo>,
},
QueryResult {
correlation_id: CorrelationId,
entities: Vec<EntityRef>,
},
GetResult {
correlation_id: CorrelationId,
result: GetResult,
},
CommandApplied {
correlation_id: CorrelationId,
version: Version,
},
Loaded {
correlation_id: CorrelationId,
version: Version,
roots: Vec<EntityRef>,
},
CommandFailed {
correlation_id: CorrelationId,
error: String,
},
CommandProgress {
correlation_id: CorrelationId,
stage: String,
},
Subscribed {
correlation_id: CorrelationId,
subscription_id: SubscriptionId,
snapshot: Snapshot,
},
Unsubscribed {
correlation_id: CorrelationId,
subscription_id: SubscriptionId,
},
EditorState {
correlation_id: CorrelationId,
state: Value,
},
Materials {
correlation_id: CorrelationId,
materials: Value,
},
Assets {
correlation_id: CorrelationId,
assets: Value,
},
Screenshot {
correlation_id: CorrelationId,
width: u32,
height: u32,
png_base64: String,
},
Batch { batch: DeltaBatch },
Replay {
subscription_id: SubscriptionId,
batches: Vec<DeltaBatch>,
},
Resnapshot {
subscription_id: SubscriptionId,
snapshot: Snapshot,
},
}