pub fn jsonseq_file_to_obj(
path: impl AsRef<Path>,
output_path: impl AsRef<Path>,
) -> Result<()>Expand description
Examples found in repository?
examples/obj_convert_seq.rs (line 25)
4fn main() -> std::io::Result<()> {
5 // Path to the sample CityJSONSeq file
6 let file_path = Path::new("data/3dbag_b2.city.jsonl");
7
8 // Ensure the file exists
9 if !file_path.exists() {
10 println!("Sample file not found: {:?}", file_path);
11 println!("Available files in data directory:");
12 for entry in std::fs::read_dir("data")? {
13 let entry = entry?;
14 println!(" {:?}", entry.path());
15 }
16 return Ok(());
17 }
18
19 println!("Converting {} to OBJ format...", file_path.display());
20
21 // Output file path
22 let output_path = "output_seq.obj";
23
24 // Convert to OBJ and save to file
25 obj::jsonseq_file_to_obj(file_path, output_path)?;
26
27 println!("Conversion complete. OBJ file saved to: {}", output_path);
28
29 // Print some stats about the OBJ file
30 let metadata = std::fs::metadata(output_path)?;
31 println!("OBJ file size: {} bytes", metadata.len());
32
33 // Count number of vertices and faces in the OBJ file
34 let obj_contents = std::fs::read_to_string(output_path)?;
35 let vertex_count = obj_contents
36 .lines()
37 .filter(|line| line.starts_with("v "))
38 .count();
39 let face_count = obj_contents
40 .lines()
41 .filter(|line| line.starts_with("f "))
42 .count();
43
44 println!("OBJ statistics:");
45 println!(" Vertices: {}", vertex_count);
46 println!(" Faces: {}", face_count);
47
48 Ok(())
49}