11use std:: {
2+ collections:: BTreeMap ,
23 ops:: Range ,
34 time:: { Duration , SystemTime } ,
45} ;
56
67use booster:: {
78 ButtonEventMsg , FallDownState , LowCommand , LowState , RemoteControllerState , TransformMessage ,
89} ;
9- use pyo3:: pyclass;
10+ use pyo3:: { pyclass, pymethods } ;
1011use serde:: { Deserialize , Serialize } ;
1112use zed:: RGBDSensors ;
1213
1314#[ derive( Clone , Debug , Serialize , Deserialize ) ]
14- pub struct SimulationMessage < T > {
15+ pub struct SimulatorMessage < T > {
1516 pub time : SystemTime ,
1617 pub payload : T ,
1718}
@@ -24,6 +25,8 @@ pub enum ServerMessageKind {
2425 RemoteControllerState ( RemoteControllerState ) ,
2526 TransformMessage ( TransformMessage ) ,
2627 RGBDSensors ( Box < RGBDSensors > ) ,
28+ SceneUpdate ( SceneUpdate ) ,
29+ SceneDescription ( SceneDescription ) ,
2730}
2831
2932#[ derive( Clone , Debug , Serialize , Deserialize ) ]
@@ -44,6 +47,137 @@ pub enum TaskName {
4447 RequestSceneDescription ,
4548}
4649
50+ #[ pyclass( frozen) ]
51+ #[ derive( Clone , Debug , Serialize , Deserialize ) ]
52+ pub struct SceneDescription {
53+ pub meshes : BTreeMap < String , SceneMesh > ,
54+ pub lights : Vec < Light > ,
55+ pub bodies : BTreeMap < String , Body > ,
56+ }
57+
58+ #[ pymethods]
59+ impl SceneDescription {
60+ #[ new]
61+ pub fn new (
62+ meshes : BTreeMap < String , SceneMesh > ,
63+ lights : Vec < Light > ,
64+ bodies : BTreeMap < String , Body > ,
65+ ) -> Self {
66+ Self {
67+ meshes,
68+ lights,
69+ bodies,
70+ }
71+ }
72+ }
73+
74+ #[ pyclass( frozen) ]
75+ #[ derive( Clone , Debug , Serialize , Deserialize ) ]
76+ pub struct SceneMesh {
77+ pub vertices : Vec < [ f32 ; 3 ] > ,
78+ pub faces : Vec < [ u32 ; 3 ] > ,
79+ }
80+
81+ #[ pymethods]
82+ impl SceneMesh {
83+ #[ new]
84+ pub fn new ( vertices : Vec < [ f32 ; 3 ] > , faces : Vec < [ u32 ; 3 ] > ) -> Self {
85+ Self { vertices, faces }
86+ }
87+ }
88+
89+ #[ pyclass( frozen) ]
90+ #[ derive( Clone , Debug , Serialize , Deserialize ) ]
91+ pub struct Light {
92+ pub name : Option < String > ,
93+ pub pos : [ f32 ; 3 ] ,
94+ pub dir : [ f32 ; 3 ] ,
95+ }
96+
97+ #[ pymethods]
98+ impl Light {
99+ #[ new]
100+ pub fn new ( name : Option < String > , pos : [ f32 ; 3 ] , dir : [ f32 ; 3 ] ) -> Self {
101+ Self { name, pos, dir }
102+ }
103+ }
104+
105+ #[ pyclass( frozen) ]
106+ #[ derive( Clone , Debug , Serialize , Deserialize ) ]
107+ pub struct Body {
108+ pub id : i64 ,
109+ pub parent : Option < String > ,
110+ pub geoms : Vec < Geom > ,
111+ }
112+
113+ #[ pymethods]
114+ impl Body {
115+ #[ new]
116+ pub fn new ( id : i64 , parent : Option < String > , geoms : Vec < Geom > ) -> Self {
117+ Self { id, parent, geoms }
118+ }
119+ }
120+
121+ #[ pyclass( frozen) ]
122+ #[ derive( Clone , Debug , Serialize , Deserialize ) ]
123+ pub struct Geom {
124+ pub name : Option < String > ,
125+ pub mesh : Option < String > ,
126+ pub rgba : [ f32 ; 4 ] ,
127+ pub pos : [ f32 ; 3 ] ,
128+ pub quat : [ f32 ; 4 ] ,
129+ }
130+
131+ #[ pymethods]
132+ impl Geom {
133+ #[ new]
134+ pub fn new (
135+ name : Option < String > ,
136+ mesh : Option < String > ,
137+ rgba : [ f32 ; 4 ] ,
138+ pos : [ f32 ; 3 ] ,
139+ quat : [ f32 ; 4 ] ,
140+ ) -> Self {
141+ Self {
142+ name,
143+ mesh,
144+ rgba,
145+ pos,
146+ quat,
147+ }
148+ }
149+ }
150+
151+ #[ pyclass( frozen) ]
152+ #[ derive( Clone , Debug , Serialize , Deserialize ) ]
153+ pub struct SceneUpdate {
154+ pub time : f32 ,
155+ pub bodies : BTreeMap < String , BodyUpdate > ,
156+ }
157+
158+ #[ pymethods]
159+ impl SceneUpdate {
160+ #[ new]
161+ pub fn new ( time : f32 , bodies : BTreeMap < String , BodyUpdate > ) -> Self {
162+ Self { time, bodies }
163+ }
164+ }
165+
166+ #[ pyclass( frozen) ]
167+ #[ derive( Clone , Debug , Serialize , Deserialize ) ]
168+ pub struct BodyUpdate {
169+ pub pos : [ f32 ; 3 ] ,
170+ pub quat : [ f32 ; 4 ] ,
171+ }
172+
173+ #[ pymethods]
174+ impl BodyUpdate {
175+ #[ new]
176+ pub fn new ( pos : [ f32 ; 3 ] , quat : [ f32 ; 4 ] ) -> Self {
177+ Self { pos, quat }
178+ }
179+ }
180+
47181#[ derive( Debug , Serialize , Deserialize ) ]
48182pub struct ConnectionInfo {
49183 pub schedule : Vec < TaskSchedule > ,
0 commit comments