custom/
custom.rs

1// Copyright 2025 Jordan Johnson
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3
4use glam::DVec3;
5use lib_curveball::map::{
6    entity::SimpleWorldspawn,
7    geometry::Brush,
8    qmap::{QEntity, QMap},
9};
10
11fn brushes_to_string(brushes: Vec<Brush>) -> String {
12    let simple_worldspawn = SimpleWorldspawn::new(brushes);
13    let entity = QEntity::from(simple_worldspawn);
14    let map = QMap::new(vec![entity]).with_tb_neverball_metadata();
15    String::from(format!("{map}"))
16}
17
18fn main() {
19    // Let's create two brushes (cube and triangular prism) and
20    // form it into a map.
21
22    let cube_vertices = [
23        DVec3 {
24            x: 0.0,
25            y: 0.0,
26            z: 0.0,
27        },
28        DVec3 {
29            x: 0.0,
30            y: 0.0,
31            z: 128.0,
32        },
33        DVec3 {
34            x: 0.0,
35            y: 128.0,
36            z: 0.0,
37        },
38        DVec3 {
39            x: 0.0,
40            y: 128.0,
41            z: 128.0,
42        },
43        DVec3 {
44            x: 128.0,
45            y: 0.0,
46            z: 0.0,
47        },
48        DVec3 {
49            x: 128.0,
50            y: 0.0,
51            z: 128.0,
52        },
53        DVec3 {
54            x: 128.0,
55            y: 128.0,
56            z: 0.0,
57        },
58        DVec3 {
59            x: 128.0,
60            y: 128.0,
61            z: 128.0,
62        },
63    ];
64    let cube = Brush::try_from_vertices(&cube_vertices, None).unwrap();
65
66    let pyramid_vertices = [
67        DVec3 {
68            x: 256.0,
69            y: 256.0,
70            z: 0.0,
71        },
72        DVec3 {
73            x: 256.0,
74            y: 512.0,
75            z: 0.0,
76        },
77        DVec3 {
78            x: 512.0,
79            y: 256.0,
80            z: 0.0,
81        },
82        DVec3 {
83            x: 256.0,
84            y: 256.0,
85            z: 256.0,
86        },
87    ];
88    let pyramid = Brush::try_from_vertices(&pyramid_vertices, None).unwrap();
89
90    let brushes = vec![cube, pyramid];
91    let string = brushes_to_string(brushes);
92
93    println!("{}", string);
94}