1use std::collections::HashMap;
2use std::error::Error;
3use webots_proto::{
4 Proto, ProtoExt, RenderContext, RenderOptions, RenderWebotsVersion, TemplateField,
5};
6
7fn main() -> Result<(), Box<dyn Error>> {
8 let input = r#"#VRML_SIM R2025a utf8
9
10PROTO ContextAwareBox [
11 field SFInt32 count 2
12 field SFString label "default-label"
13]
14{
15 Group {
16 children [
17 WorldInfo { title "%<= fields.label.value >%|%<= fields.label.defaultValue >%|%<= context.os >%" }
18 %< for (let i = 0; i < fields.count.value; ++i) { >%
19 Transform {
20 translation %<= i >% 0 0
21 children [ Box { size 0.5 0.5 0.5 } ]
22 }
23 %< } >%
24 ]
25 }
26}
27"#;
28
29 let document: Proto = input.parse()?;
30 let diagnostics = document.validate()?;
31 println!("diagnostics: {}", diagnostics.len());
32
33 let mut field_overrides = HashMap::new();
34 field_overrides.insert("count".to_string(), TemplateField::SFInt32(3));
35 field_overrides.insert(
36 "label".to_string(),
37 TemplateField::SFString("override-label".to_string()),
38 );
39
40 let context = RenderContext::default()
41 .with_os("linux")
42 .with_world("/workspace/worlds/example.wbt")
43 .with_webots_version(RenderWebotsVersion::new(
44 "R2025a".to_string(),
45 "0".to_string(),
46 ));
47
48 let options = RenderOptions::default()
49 .with_field_overrides(field_overrides)
50 .with_context(context);
51
52 let rendered = document.render(&options)?;
53 println!("{rendered}");
54
55 Ok(())
56}