adk_surface/genui/scene.rs
1//! 3D scenes and depth effects an extension component's home view draws (spec 3.3 §6.1
2//! `genui`, extension catalogs): the home's own elements, like [`DrawnChart`], so the home and
3//! any host drawing with `DrawnView` show them natively, and the terminal and the phone show
4//! their words.
5//!
6//! A [`DrawnScene`] is a bounded, declarative scene: shapes, lines, instanced bars and points,
7//! a height grid, a globe and labels. Its colours are the home's palette and state tokens,
8//! never colours the agent picks. It has no textures, models, fonts, shaders or links, and
9//! every string in it is checked by rule 5. Picking an object fills a choice field the drawing
10//! shows; it never sends anything ([`SceneSelect`]).
11//!
12//! A [`DrawnDepth`] presents the components a home view holds with CSS 3D, without WebGL: a
13//! card that tilts or flips, stacked layers, a carousel, a curved wall or an orbitable stage.
14//!
15//! [`DrawnChart`]: super::DrawnChart
16
17use schemars::JsonSchema;
18use serde::{Deserialize, Serialize};
19use serde_json::Number;
20
21/// A point or a size in a scene, `[x, y, z]`; `y` is up.
22pub type Xyz = [Number; 3];
23
24fn origin() -> Xyz {
25 [Number::from(0), Number::from(0), Number::from(0)]
26}
27
28/// A 3D scene a home view draws, as `HomeNode::Scene`.
29///
30/// # Example
31///
32/// ```rust
33/// use adk_surface::genui::{DrawnScene, SceneKind, SceneObject, SceneShape};
34///
35/// let scene = DrawnScene {
36/// objects: vec![SceneObject::new(
37/// "dock-3",
38/// SceneShape::Box { size: [2.into(), 1.into(), 4.into()] },
39/// )
40/// .labelled("Dock 3")],
41/// ..DrawnScene::new(SceneKind::Space)
42/// };
43/// let wire = serde_json::to_value(&scene).unwrap();
44/// assert_eq!(wire["objects"][0]["shape"]["type"], "box");
45/// assert_eq!(wire["camera"]["preset"], "fit");
46/// ```
47#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
48#[serde(rename_all = "camelCase")]
49pub struct DrawnScene {
50 /// What the scene is, for its summary and default camera.
51 pub kind: SceneKind,
52 /// Its objects, parents before children.
53 pub objects: Vec<SceneObject>,
54 /// Where it is seen from.
55 #[serde(default)]
56 pub camera: SceneCamera,
57 /// How it is lit: a preset whose soft light always stays, so nothing goes dark.
58 #[serde(default)]
59 pub lighting: SceneLighting,
60 /// Up to three more lights.
61 #[serde(default, skip_serializing_if = "Vec::is_empty")]
62 pub lights: Vec<SceneLight>,
63 /// Named axes, ticks and a floor grid.
64 #[serde(default, skip_serializing_if = "Option::is_none")]
65 pub axes: Option<SceneAxes>,
66 /// Objects that move.
67 #[serde(default, skip_serializing_if = "Vec::is_empty")]
68 pub motion: Vec<SceneMotion>,
69 /// Picking an object fills this field.
70 #[serde(default, skip_serializing_if = "Option::is_none")]
71 pub select: Option<SceneSelect>,
72 /// Its height in CSS pixels, 200 to 960; the home picks one when it is not given.
73 #[serde(default, skip_serializing_if = "Option::is_none")]
74 pub height: Option<u16>,
75 /// What bar and grid heights stand for in the data's own numbers, for the summary and the
76 /// home's readouts; heights are the data's numbers when not given.
77 #[serde(default, skip_serializing_if = "Option::is_none")]
78 pub values: Option<SceneValues>,
79 /// One sentence that says what the scene shows, for screen readers and the terminal,
80 /// written by the server: "3D bar chart of Revenue, 24 bars, from 3 to 98".
81 #[serde(default)]
82 pub summary: String,
83 /// The held components shown beside objects: written by the server, each the key of one
84 /// of the node's children.
85 #[serde(default, skip_serializing_if = "Vec::is_empty")]
86 pub panels: Vec<ScenePanel>,
87 /// The key of the node's child that says in words what the scene shows, written by the
88 /// server: shown by "Show as text", where WebGL is missing, and in the terminal.
89 #[serde(default, skip_serializing_if = "Option::is_none")]
90 pub text_view: Option<String>,
91}
92
93impl DrawnScene {
94 /// An empty scene of `kind`, seen to fit, in the studio light.
95 pub fn new(kind: SceneKind) -> Self {
96 Self {
97 kind,
98 objects: Vec::new(),
99 camera: SceneCamera::default(),
100 lighting: SceneLighting::default(),
101 lights: Vec::new(),
102 axes: None,
103 motion: Vec::new(),
104 select: None,
105 height: None,
106 values: None,
107 summary: String::new(),
108 panels: Vec::new(),
109 text_view: None,
110 }
111 }
112}
113
114/// How a scene's heights map to the data's numbers: a height `h` stands for
115/// `h * scale + offset`.
116#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
117#[serde(rename_all = "camelCase")]
118pub struct SceneValues {
119 /// What one unit of height stands for; above 0.
120 pub scale: Number,
121 /// What a height of 0 stands for.
122 #[serde(default = "zero")]
123 pub offset: Number,
124}
125
126fn zero() -> Number {
127 Number::from(0)
128}
129
130impl SceneValues {
131 /// The data's number a height stands for.
132 pub fn value(&self, height: f64) -> f64 {
133 height * self.scale.as_f64().unwrap_or(1.0) + self.offset.as_f64().unwrap_or(0.0)
134 }
135}
136
137/// What a scene is.
138#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
139#[serde(rename_all = "camelCase")]
140pub enum SceneKind {
141 /// Objects laid out in space: a floor plan, a rack, a machine.
142 Space,
143 /// Bars over two categories.
144 Bars,
145 /// Points over three measures.
146 Points,
147 /// A value over a grid.
148 Surface,
149 /// Nodes and the links between them.
150 Network,
151 /// Places on a globe and the routes between them.
152 Globe,
153}
154
155/// One object of a scene.
156#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
157#[serde(rename_all = "camelCase")]
158pub struct SceneObject {
159 /// Unique within the scene: what parents, panels, motion and picking name it by.
160 pub id: String,
161 /// The group it belongs to: it moves, turns and scales with it.
162 #[serde(default, skip_serializing_if = "Option::is_none")]
163 pub parent: Option<String>,
164 /// What it is called, shown beside it as page text.
165 #[serde(default, skip_serializing_if = "Option::is_none")]
166 pub label: Option<String>,
167 /// Its shape.
168 pub shape: SceneShape,
169 /// Where it is, in its parent's space.
170 #[serde(default = "origin")]
171 pub at: Xyz,
172 /// How it is turned about each axis, in degrees.
173 #[serde(default, skip_serializing_if = "Option::is_none")]
174 pub turn: Option<Xyz>,
175 /// How it is scaled along each axis.
176 #[serde(default, skip_serializing_if = "Option::is_none")]
177 pub scale: Option<Xyz>,
178 /// How it looks.
179 #[serde(default)]
180 pub look: SceneLook,
181 /// A state it is in, drawn in the state's colour beside its label's word; an object with
182 /// a state has a label, so colour is never the only sign.
183 #[serde(default, skip_serializing_if = "Option::is_none")]
184 pub state: Option<SceneState>,
185 /// The option value picking it chooses (see [`SceneSelect`]); an object with one has a
186 /// label, so the person sees what they pick.
187 #[serde(default, skip_serializing_if = "Option::is_none")]
188 pub value: Option<String>,
189}
190
191impl SceneObject {
192 /// An object `id` of `shape`, at the origin, in the first chart colour.
193 pub fn new(id: impl Into<String>, shape: SceneShape) -> Self {
194 Self {
195 id: id.into(),
196 parent: None,
197 label: None,
198 shape,
199 at: origin(),
200 turn: None,
201 scale: None,
202 look: SceneLook::default(),
203 state: None,
204 value: None,
205 }
206 }
207
208 /// With `label`.
209 #[must_use]
210 pub fn labelled(mut self, label: impl Into<String>) -> Self {
211 self.label = Some(label.into());
212 self
213 }
214
215 /// At `at`.
216 #[must_use]
217 pub fn at(mut self, at: Xyz) -> Self {
218 self.at = at;
219 self
220 }
221}
222
223/// A scene object's shape. Flat number lists hold one point after another.
224#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
225#[serde(tag = "type", rename_all = "camelCase", rename_all_fields = "camelCase")]
226pub enum SceneShape {
227 /// No shape of its own: it holds the objects whose parent it is.
228 Group,
229 /// A box.
230 Box {
231 /// Width, height and depth.
232 size: Xyz,
233 },
234 /// A sphere.
235 Sphere {
236 /// Its radius.
237 radius: Number,
238 },
239 /// A cylinder; a cone has a top radius of 0.
240 Cylinder {
241 /// The top's radius.
242 radius_top: Number,
243 /// The bottom's radius.
244 radius_bottom: Number,
245 /// Its height.
246 height: Number,
247 },
248 /// A ring.
249 Torus {
250 /// From the centre to the middle of the tube.
251 radius: Number,
252 /// The tube's radius.
253 tube: Number,
254 },
255 /// A flat rectangle on the ground.
256 Plane {
257 /// Along x.
258 width: Number,
259 /// Along z.
260 depth: Number,
261 },
262 /// A line through points, `x, y, z` after one another.
263 Line {
264 /// The points, flat.
265 points: Vec<Number>,
266 /// Separate segments, each a pair of points, rather than one line through them all.
267 #[serde(default)]
268 segments: bool,
269 /// A smooth curve through the points.
270 #[serde(default)]
271 smooth: bool,
272 /// Arrowheads.
273 #[serde(default)]
274 arrow: LineEnds,
275 /// Dashed.
276 #[serde(default)]
277 dashed: bool,
278 },
279 /// Bars standing on the ground, one per `x, z` pair.
280 Bars {
281 /// Where each bar stands, `x, z` flat.
282 at: Vec<Number>,
283 /// Each bar's height.
284 heights: Vec<Number>,
285 /// Each bar's width and depth.
286 width: Number,
287 /// Each bar's series, 0 to 7, drawn in that chart colour; empty for the object's own.
288 #[serde(default, skip_serializing_if = "Vec::is_empty")]
289 series: Vec<u8>,
290 },
291 /// Points, `x, y, z` flat.
292 Points {
293 /// Where each point is, flat.
294 at: Vec<Number>,
295 /// Each point's radius.
296 size: Number,
297 /// Each point's series, 0 to 7, drawn in that chart colour; empty for the object's own.
298 #[serde(default, skip_serializing_if = "Vec::is_empty")]
299 series: Vec<u8>,
300 },
301 /// A surface over a grid of heights, row after row, coloured by height.
302 Grid {
303 /// Points along x.
304 columns: u16,
305 /// Points along z.
306 rows: u16,
307 /// One height per point, row after row.
308 heights: Vec<Number>,
309 /// Along x.
310 width: Number,
311 /// Along z.
312 depth: Number,
313 },
314 /// A globe with lines of latitude and longitude.
315 Globe {
316 /// Its radius.
317 radius: Number,
318 },
319 /// Text facing the viewer, as page text.
320 Label {
321 /// What it reads.
322 text: String,
323 /// How large.
324 #[serde(default)]
325 size: LabelSize,
326 },
327}
328
329/// A line's arrowheads.
330#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
331#[serde(rename_all = "camelCase")]
332pub enum LineEnds {
333 /// None.
334 #[default]
335 None,
336 /// At the last point.
337 End,
338 /// At both ends.
339 Both,
340}
341
342/// How large a label is.
343#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
344#[serde(rename_all = "camelCase")]
345pub enum LabelSize {
346 /// A caption.
347 Small,
348 /// Body text.
349 #[default]
350 Medium,
351 /// A heading.
352 Large,
353}
354
355/// How an object looks: the home's colours, never one the agent picks.
356#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
357#[serde(rename_all = "camelCase")]
358pub struct SceneLook {
359 /// Its colour.
360 #[serde(default)]
361 pub color: SceneColor,
362 /// How opaque, 0.15 to 1; 1 when not given.
363 #[serde(default, skip_serializing_if = "Option::is_none")]
364 pub opacity: Option<Number>,
365 /// Drawn as edges only.
366 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
367 pub wireframe: bool,
368 /// Its surface.
369 #[serde(default)]
370 pub finish: SceneFinish,
371}
372
373/// A colour of the home's palette.
374#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
375#[serde(rename_all = "camelCase")]
376pub enum SceneColor {
377 /// The first chart colour.
378 #[default]
379 Chart1,
380 /// The second chart colour.
381 Chart2,
382 /// The third chart colour.
383 Chart3,
384 /// The fourth chart colour.
385 Chart4,
386 /// The fifth chart colour.
387 Chart5,
388 /// The sixth chart colour.
389 Chart6,
390 /// The seventh chart colour.
391 Chart7,
392 /// The eighth chart colour.
393 Chart8,
394 /// The text colour.
395 Ink,
396 /// A plain grey.
397 Neutral,
398 /// A faint grey.
399 Muted,
400 /// By height, low to high (a grid).
401 Ramp,
402}
403
404impl SceneColor {
405 /// The chart colour of series `index`, 0 to 7.
406 pub fn chart(index: u8) -> Self {
407 match index % 8 {
408 0 => Self::Chart1,
409 1 => Self::Chart2,
410 2 => Self::Chart3,
411 3 => Self::Chart4,
412 4 => Self::Chart5,
413 5 => Self::Chart6,
414 6 => Self::Chart7,
415 _ => Self::Chart8,
416 }
417 }
418}
419
420/// An object's surface.
421#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
422#[serde(rename_all = "camelCase")]
423pub enum SceneFinish {
424 /// Soft.
425 #[default]
426 Matte,
427 /// Shiny.
428 Glossy,
429 /// Unlit, one flat colour.
430 Flat,
431}
432
433/// A state an object is in.
434#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
435#[serde(rename_all = "camelCase")]
436pub enum SceneState {
437 /// Fine.
438 Ok,
439 /// Needs a look.
440 Warning,
441 /// Broken or at risk.
442 Critical,
443 /// Worth knowing.
444 Info,
445}
446
447/// Where a scene is seen from.
448#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
449#[serde(rename_all = "camelCase")]
450pub struct SceneCamera {
451 /// A view the home frames to fit the scene.
452 #[serde(default)]
453 pub preset: CameraPreset,
454 /// Where the camera is, in place of the preset's.
455 #[serde(default, skip_serializing_if = "Option::is_none")]
456 pub at: Option<Xyz>,
457 /// What it looks at, in place of the scene's centre.
458 #[serde(default, skip_serializing_if = "Option::is_none")]
459 pub target: Option<Xyz>,
460 /// Its vertical field of view, 15 to 90 degrees.
461 #[serde(default, skip_serializing_if = "Option::is_none")]
462 pub fov: Option<Number>,
463 /// The person can't turn or zoom it.
464 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
465 pub fixed: bool,
466 /// It turns slowly about the scene, until the person turns it.
467 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
468 pub spin: bool,
469}
470
471/// A camera view.
472#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
473#[serde(rename_all = "camelCase")]
474pub enum CameraPreset {
475 /// From above and to the side, framing everything.
476 #[default]
477 Fit,
478 /// From the front.
479 Front,
480 /// From above.
481 Top,
482 /// From the side.
483 Side,
484 /// Isometric.
485 Iso,
486}
487
488/// A lighting preset.
489#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
490#[serde(rename_all = "camelCase")]
491pub enum SceneLighting {
492 /// A key light, a fill and a soft sky.
493 #[default]
494 Studio,
495 /// Soft from every side.
496 Soft,
497 /// Even, no shading.
498 Flat,
499}
500
501/// A light added to the preset.
502#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
503#[serde(rename_all = "camelCase")]
504pub struct SceneLight {
505 /// What kind.
506 pub kind: LightKind,
507 /// Where it is; a directional light shines from there towards the centre.
508 pub at: Xyz,
509 /// Its colour; white when not given.
510 #[serde(default, skip_serializing_if = "Option::is_none")]
511 pub color: Option<SceneColor>,
512 /// How bright, 0 to 2.
513 pub intensity: Number,
514}
515
516/// A kind of light.
517#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
518#[serde(rename_all = "camelCase")]
519pub enum LightKind {
520 /// Shines every way from a point.
521 Point,
522 /// A cone from a point towards the centre.
523 Spot,
524 /// Parallel rays, like the sun.
525 Directional,
526}
527
528/// A scene's axes.
529#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
530#[serde(rename_all = "camelCase")]
531pub struct SceneAxes {
532 /// The x axis's name.
533 #[serde(default, skip_serializing_if = "Option::is_none")]
534 pub x: Option<String>,
535 /// The y axis's name: up.
536 #[serde(default, skip_serializing_if = "Option::is_none")]
537 pub y: Option<String>,
538 /// The z axis's name.
539 #[serde(default, skip_serializing_if = "Option::is_none")]
540 pub z: Option<String>,
541 /// Labelled points along them.
542 #[serde(default, skip_serializing_if = "Vec::is_empty")]
543 pub ticks: Vec<SceneTick>,
544 /// A grid on the ground.
545 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
546 pub floor: bool,
547}
548
549/// A labelled point on an axis.
550#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
551#[serde(rename_all = "camelCase")]
552pub struct SceneTick {
553 /// Which axis.
554 pub axis: Axis,
555 /// Where along it.
556 pub at: Number,
557 /// What it reads.
558 pub text: String,
559}
560
561/// An axis.
562#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
563#[serde(rename_all = "camelCase")]
564pub enum Axis {
565 /// Across.
566 X,
567 /// Up.
568 #[default]
569 Y,
570 /// Towards the viewer.
571 Z,
572}
573
574/// An object that moves. Under reduced motion nothing moves; the person can pause any motion.
575#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
576#[serde(rename_all = "camelCase")]
577pub struct SceneMotion {
578 /// The object.
579 pub target: String,
580 /// How it moves.
581 pub kind: MotionKind,
582 /// The axis it turns or moves along.
583 #[serde(default)]
584 pub axis: Axis,
585 /// How long one turn, swing or trip takes, 0.2 to 120.
586 pub seconds: Number,
587 /// How far it swings or how much it grows: 0 to 100 for `bob`, 0 to 1 for `pulse`.
588 #[serde(default, skip_serializing_if = "Option::is_none")]
589 pub amount: Option<Number>,
590 /// Seconds before it starts, 0 to 30.
591 #[serde(default, skip_serializing_if = "Option::is_none")]
592 pub delay: Option<Number>,
593 /// How many times, 1 to 100; it goes on when not given.
594 #[serde(default, skip_serializing_if = "Option::is_none")]
595 pub repeat: Option<u8>,
596 /// The points a `path` motion follows, `x, y, z` flat, in its parent's space.
597 #[serde(default, skip_serializing_if = "Vec::is_empty")]
598 pub path: Vec<Number>,
599}
600
601/// How an object moves.
602#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
603#[serde(rename_all = "camelCase")]
604pub enum MotionKind {
605 /// Turns about its axis.
606 Spin,
607 /// Swings up and down along its axis.
608 Bob,
609 /// Grows and shrinks.
610 Pulse,
611 /// Circles its parent's centre about its axis.
612 Orbit,
613 /// Follows its path.
614 Path,
615}
616
617/// Picking an object fills a choice field the drawing shows, with the object's `value`
618/// (spec 3.3 §7.4 rule 5: a scene's pick fills a shown choice field; it never sends). The
619/// field stays the way to choose by keyboard and screen reader, and a form's Send still asks.
620#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
621#[serde(rename_all = "camelCase")]
622pub struct SceneSelect {
623 /// The data model path of the choice field it fills, absolute.
624 pub path: String,
625 /// What picking does, in words, written by the server: "Picking one fills Dock. Nothing
626 /// is sent."
627 #[serde(default)]
628 pub note: String,
629}
630
631/// A held component shown beside an object.
632#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
633#[serde(rename_all = "camelCase")]
634pub struct ScenePanel {
635 /// The object it is shown beside.
636 pub anchor: String,
637 /// The key of the node's child it shows.
638 pub key: String,
639}
640
641/// Components a home view holds, presented with CSS 3D, as `HomeNode::Depth`.
642///
643/// # Example
644///
645/// ```rust
646/// use adk_surface::genui::{DepthEffect, DrawnDepth};
647///
648/// let flip = DrawnDepth { effect: DepthEffect::Flip, titles: Vec::new() };
649/// assert_eq!(serde_json::to_value(&flip).unwrap()["effect"], "flip");
650/// ```
651#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
652#[serde(rename_all = "camelCase")]
653pub struct DrawnDepth {
654 /// How the children are presented.
655 pub effect: DepthEffect,
656 /// A title for each child, for a carousel, wall or stage's controls and the terminal.
657 #[serde(default, skip_serializing_if = "Vec::is_empty")]
658 pub titles: Vec<String>,
659}
660
661/// A depth effect.
662#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
663#[serde(rename_all = "camelCase")]
664pub enum DepthEffect {
665 /// One child that tilts towards the pointer.
666 Tilt,
667 /// Two children, front and back; the home's own button turns it over.
668 Flip,
669 /// Children stacked in depth, the first in front.
670 Layers,
671 /// Children on a turning ring, one in front at a time.
672 Carousel,
673 /// Children on a curved wall.
674 Wall,
675 /// Children on a stage the person can turn.
676 Stage,
677}
678
679impl DepthEffect {
680 /// Whether its children may hold only what shows: a wall or a stage moves them under the
681 /// pointer, so they hold no button or field.
682 pub fn shows_only(self) -> bool {
683 matches!(self, Self::Wall | Self::Stage)
684 }
685}
686
687#[cfg(test)]
688mod tests {
689 use super::*;
690 use serde_json::json;
691
692 #[test]
693 fn a_scene_round_trips_with_its_defaults() {
694 let wire = json!({
695 "kind": "bars",
696 "objects": [{
697 "id": "bars",
698 "shape": { "type": "bars", "at": [0, 0, 1, 0], "heights": [3, 5], "width": 0.6,
699 "series": [0, 1] },
700 "look": { "color": "chart2" }
701 }],
702 "motion": [{ "target": "bars", "kind": "pulse", "seconds": 2 }]
703 });
704 let scene: DrawnScene = serde_json::from_value(wire).unwrap();
705 assert_eq!(scene.camera.preset, CameraPreset::Fit);
706 assert_eq!(scene.lighting, SceneLighting::Studio);
707 assert_eq!(scene.objects[0].at, origin());
708 assert_eq!(scene.objects[0].look.color, SceneColor::Chart2);
709 let again = serde_json::to_value(&scene).unwrap();
710 assert_eq!(again["objects"][0]["shape"]["heights"], json!([3, 5]));
711 assert_eq!(again["motion"][0]["axis"], "y");
712 }
713
714 #[test]
715 fn shape_fields_are_camel_case() {
716 let cone = SceneShape::Cylinder {
717 radius_top: 0.into(),
718 radius_bottom: 1.into(),
719 height: 2.into(),
720 };
721 let wire = serde_json::to_value(&cone).unwrap();
722 assert_eq!(
723 wire,
724 json!({ "type": "cylinder", "radiusTop": 0, "radiusBottom": 1, "height": 2 })
725 );
726 }
727}