Skip to content

Commit e8afd85

Browse files
committed
update rust version, and some minor bspeater improvements
1 parent 1b85d42 commit e8afd85

File tree

14 files changed

+2634
-808
lines changed

14 files changed

+2634
-808
lines changed

Cargo.lock

Lines changed: 2423 additions & 677 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bp_ort/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "bp_ort"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55
license = "Apache-2.0"
66

77
[dependencies]

bspeater/Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ edition = "2024"
55
license = "Apache-2.0"
66

77
[dependencies]
8-
# sourcepak = { version = "0.3.0", features = ["revpk"] }
9-
avian3d = { version = "0.3.*", features = ["simd", "debug-plugin"] }
10-
bevy = { version = "0.16.*", features = ["wayland", "x11"] }
11-
bevy_fly_camera = "0.16.*"
12-
bevy_gltf_export = { git = "https://github.com/luca-della-vedova/bevy_gltf_export.git", version = "0.1.0" }
8+
avian3d = { version = "0.5.*", features = ["simd", "parry-f32", "bevy_picking", "parallel", "f32", "3d", "collider-from-mesh"], default-features = false }
9+
bevy = { version = "0.18.*", features = ["wayland", "x11", "3d"], default-features = false }
1310
clap = { version = "4.5.39", features = ["derive"] }
1411
itertools = { workspace = true }
1512
modular-bitfield = "0.12.0"
@@ -24,3 +21,7 @@ bonsai-bt = "0.10.0"
2421
indexmap = "2.11.4"
2522
rustc-hash = "2.1.1"
2623
hexasphere = "16.0.0"
24+
25+
[features]
26+
default = ["graphics"]
27+
graphics = ["oktree/bevy", "bevy/wayland", "bevy/wayland", "bevy/free_camera", "avian3d/debug-plugin"]

bspeater/src/cli.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ pub struct BspeaterCli {
2222
#[arg(long, short = 't', default_value_t = false, action = clap::ArgAction::SetTrue)]
2323
pub show_octtree: bool,
2424

25+
#[arg(long, short = 'g', default_value_t = false, action = clap::ArgAction::SetTrue)]
26+
pub show_grid_octtree: bool,
27+
2528
#[arg(long, short = 'o', default_value = "output")]
2629
pub output: PathBuf,
2730
}

bspeater/src/debug.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
use bevy::{input::common_conditions::input_just_pressed, prelude::*};
2-
use bevy_fly_camera::FlyCamera;
1+
use bevy::{
2+
camera_controller::free_camera::FreeCamera, input::common_conditions::input_just_pressed,
3+
prelude::*,
4+
};
35
use oktree::prelude::*;
46
use std::{ops::BitAnd, sync::Arc};
57

@@ -141,13 +143,17 @@ fn update_pos_text(
141143
}
142144

143145
fn debug_world(
144-
camera: Query<&Transform, (With<FlyCamera>, Without<WireMe>)>,
146+
camera: Query<&Transform, (With<FreeCamera>, Without<WireMe>)>,
145147
debug_amount: Res<DebugAmount>,
146148
cells: Res<ChunkCells>,
147149
mut gizmos: Gizmos,
148150
) -> Result<(), BevyError> {
149151
let origin = camera.single()?.translation;
150152

153+
if !debug_amount.grid {
154+
return Ok(());
155+
}
156+
151157
for pos in cells
152158
.collied_vec
153159
.iter()
@@ -157,7 +163,7 @@ fn debug_world(
157163
})
158164
.filter(|pos| pos.distance(origin) < 500.)
159165
{
160-
gizmos.cuboid(
166+
gizmos.cube(
161167
Transform::from_translation(pos).with_scale(Vec3::splat(CELL_SIZE)),
162168
Color::srgba_u8(255, 0, 0, 255),
163169
);
@@ -181,7 +187,7 @@ fn debug_world(
181187
})
182188
.filter(|(center, _)| center.distance(origin) < 500.)
183189
{
184-
gizmos.cuboid(
190+
gizmos.cube(
185191
Transform::from_translation(center).with_scale(scale),
186192
Color::srgba_u8(255, 255, 0, 255),
187193
);
@@ -206,7 +212,7 @@ fn debug_pathfinding(
206212
}
207213

208214
fn add_pathfinding_points(
209-
camera: Query<&Transform, (With<FlyCamera>, Without<WireMe>)>,
215+
camera: Query<&Transform, (With<FreeCamera>, Without<WireMe>)>,
210216
mut points: ResMut<PathfindingPoints>,
211217
) -> Result<(), BevyError> {
212218
let origin = camera.single()?.translation.trunc();
@@ -239,8 +245,8 @@ fn add_navmesh_resource(mut commands: Commands, cells: Res<ChunkCells>) {
239245

240246
fn debug_contents(
241247
mut ray_cast: MeshRayCast,
242-
camera: Query<&Transform, (With<FlyCamera>, Without<WorldMesh>)>,
243-
world_meshes: Query<&Mesh3d, (With<WorldMesh>, Without<FlyCamera>)>,
248+
camera: Query<&Transform, (With<FreeCamera>, Without<WorldMesh>)>,
249+
world_meshes: Query<&Mesh3d, (With<WorldMesh>, Without<FreeCamera>)>,
244250
meshes: Res<Assets<Mesh>>,
245251
mut text: Query<Entity, With<MeshInfoText>>,
246252
mut writer: TextUiWriter,

bspeater/src/export.rs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// sligtly modified version of export.rs from https://github.com/mrclputra/bevy_WeaverGen_V3
2+
3+
// saves the model as an obj file
4+
// by iterating through all the meshes
5+
6+
use bevy::prelude::*;
7+
use std::fs::File;
8+
use std::io::{BufWriter, Write};
9+
use std::path::Path;
10+
11+
use crate::{ProcessingStep, WorldName};
12+
13+
// export all meshes in scene
14+
pub fn export_obj<'a>(
15+
mesh_entities: impl Iterator<Item = &'a Mesh>,
16+
filename: &Path,
17+
) -> Result<(), Box<dyn std::error::Error>> {
18+
let file = File::create(filename)?;
19+
let mut writer = BufWriter::new(file);
20+
21+
// OBJ header
22+
writeln!(writer, "# Exported from Slum Generator")?;
23+
writeln!(writer, "Written by Marcel Putra 2025")?;
24+
25+
// OBJ format indices start at 1, dont ask why :)
26+
let mut vertex_offset = 1;
27+
let mut mesh_count = 0;
28+
29+
// export all mesh entities
30+
for mesh in mesh_entities {
31+
writeln!(writer, "# Mesh {}", mesh_count)?;
32+
writeln!(writer, "o Mesh_{}", mesh_count)?;
33+
34+
// extract vertices from the mesh
35+
if let Some(positions) = mesh.attribute(Mesh::ATTRIBUTE_POSITION)
36+
&& let bevy::mesh::VertexAttributeValues::Float32x3(vertices) = positions
37+
{
38+
// write vertices
39+
for vertex in vertices {
40+
writeln!(writer, "v {} {} {}", vertex[0], vertex[1], vertex[2])?;
41+
}
42+
43+
// write faces using the mesh indices
44+
if let Some(indices) = mesh.indices() {
45+
match indices {
46+
bevy::mesh::Indices::U16(indices) => {
47+
for chunk in indices.chunks(3) {
48+
if chunk.len() == 3 {
49+
writeln!(
50+
writer,
51+
"f {} {} {}",
52+
vertex_offset + chunk[0] as u32,
53+
vertex_offset + chunk[1] as u32,
54+
vertex_offset + chunk[2] as u32
55+
)?;
56+
}
57+
}
58+
}
59+
bevy::mesh::Indices::U32(indices) => {
60+
for chunk in indices.chunks(3) {
61+
if chunk.len() == 3 {
62+
writeln!(
63+
writer,
64+
"f {} {} {}",
65+
vertex_offset + chunk[0],
66+
vertex_offset + chunk[1],
67+
vertex_offset + chunk[2]
68+
)?;
69+
}
70+
}
71+
}
72+
}
73+
}
74+
75+
vertex_offset += vertices.len() as u32;
76+
writeln!(writer)?;
77+
mesh_count += 1;
78+
}
79+
}
80+
81+
writer.flush()?;
82+
bevy::log::info!("Exported {} meshes to {}", mesh_count, filename.display());
83+
84+
Ok(())
85+
}
86+
87+
pub fn save_meshes(
88+
meshes_assets: Res<Assets<Mesh>>,
89+
map_name: Res<WorldName>,
90+
mut next_state: ResMut<NextState<ProcessingStep>>,
91+
) {
92+
bevy::log::info!("trying to save meshes");
93+
94+
match export_obj(
95+
meshes_assets.iter().map(|(_, mesh)| mesh),
96+
&map_name
97+
.output
98+
.join(&map_name.map_name)
99+
.with_extension("obj"),
100+
) {
101+
Err(err) => {
102+
bevy::log::error!("coudln't save meshes {err:?}");
103+
}
104+
Ok(_) => {
105+
bevy::log::info!("saved meshes");
106+
}
107+
}
108+
109+
next_state.set(ProcessingStep::Exit);
110+
}

bspeater/src/geoset_loader.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub fn geoset_to_meshes(
167167

168168
Some(
169169
Mesh::new(
170-
bevy::render::mesh::PrimitiveTopology::TriangleList,
170+
bevy::mesh::PrimitiveTopology::TriangleList,
171171
RenderAssetUsages::all(),
172172
)
173173
.with_inserted_attribute(
@@ -187,7 +187,7 @@ pub fn geoset_to_meshes(
187187
vec![ty as u32; pushing_vertices.len()],
188188
)
189189
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, pushing_vertices)
190-
.with_inserted_indices(bevy::render::mesh::Indices::U32(indices)),
190+
.with_inserted_indices(bevy::mesh::Indices::U32(indices)),
191191
)
192192
})
193193
.collect::<Vec<Mesh>>()
@@ -219,7 +219,7 @@ fn brush_to_mesh(
219219
];
220220

221221
let transform = Transform::from_translation(brush.origin)
222-
.compute_matrix()
222+
.to_matrix()
223223
.inverse()
224224
.transpose();
225225
let planes = planes
@@ -273,7 +273,7 @@ fn prop_to_mesh(
273273
static_prop.angles.z.to_radians(),
274274
))
275275
.with_scale(Vec3::splat(static_prop.scale))
276-
.compute_matrix();
276+
.to_matrix();
277277

278278
if let Some(model_data) = model_data
279279
.get(static_prop.model_index as usize)

0 commit comments

Comments
 (0)