Skip to content

Commit 4c01b01

Browse files
committed
fix floors being gone
1 parent 28368d1 commit 4c01b01

File tree

6 files changed

+120
-43
lines changed

6 files changed

+120
-43
lines changed

Cargo.lock

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bspeater/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ flume = { version = "0.11.1", default-features = false }
2323
bonsai-bt = "0.10.0"
2424
indexmap = "2.11.4"
2525
rustc-hash = "2.1.1"
26+
hexasphere = "16.0.0"

bspeater/src/debug.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bevy::{input::common_conditions::input_just_pressed, prelude::*};
22
use bevy_fly_camera::FlyCamera;
33
use oktree::prelude::*;
4-
use std::{iter, ops::BitAnd, sync::Arc};
4+
use std::{ops::BitAnd, sync::Arc};
55

66
use crate::{
77
ATTRIBUTE_PRIMATIVE_TYPE, ATTRIBUTE_UNIQUE_CONTENTS, CELL_SIZE, ChunkCells, DebugAmount,
@@ -248,7 +248,7 @@ fn debug_contents(
248248
) -> Result<(), BevyError> {
249249
let Transform {
250250
translation,
251-
rotation,
251+
rotation: _,
252252
scale: _,
253253
} = *camera.single()?;
254254

bspeater/src/geoset_loader.rs

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
use crate::*;
2-
use avian3d::math::PI;
3-
use bevy::math::{Affine3A, DVec3};
2+
use bevy::math::DVec3;
3+
4+
const EXTRA_FLAGS: &[(&str, [(i32, i32); 3])] = &[(
5+
"mp_black_water_canal",
6+
[(0, 0), (0, Contents::WINDOW_NO_COLLIDE as i32), (0, 0)],
7+
)];
48

59
pub fn geoset_to_meshes(
610
BSPData {
@@ -17,7 +21,14 @@ pub fn geoset_to_meshes(
1721
props,
1822
model_data,
1923
}: BSPData,
24+
map_name: &str,
2025
) -> Vec<Mesh> {
26+
let extra_flags = EXTRA_FLAGS
27+
.iter()
28+
.find_map(|(name, rest)| (*name == map_name).then_some(rest))
29+
.copied()
30+
.unwrap_or_default();
31+
2132
geo_sets
2233
.into_iter()
2334
.flat_map(|geoset| {
@@ -30,17 +41,36 @@ pub fn geoset_to_meshes(
3041
.chain(geoset.prim_count.eq(&1).then_some(geoset.prim_start))
3142
})
3243
.filter_map(|primative| {
33-
let flag = Contents::SOLID as i32 | Contents::PLAYER_CLIP as i32;
34-
let no_flag = Contents::WINDOW_NO_COLLIDE as i32;
44+
let ty =
45+
PrimitiveType::try_from((primative >> 29) & 0x7).expect("invalid primative type");
46+
let (flag, no_flag) = match ty {
47+
PrimitiveType::Brush => (
48+
Contents::SOLID as i32 | Contents::PLAYER_CLIP as i32,
49+
Contents::WINDOW_NO_COLLIDE as i32,
50+
),
51+
PrimitiveType::Tricoll => (
52+
Contents::SOLID as i32
53+
| Contents::PLAYER_CLIP as i32
54+
| Contents::BULLET_CLIP as i32,
55+
0,
56+
),
57+
PrimitiveType::Prop => (Contents::SOLID as i32 | Contents::PLAYER_CLIP as i32, 0),
58+
};
59+
60+
let extra_flags = extra_flags
61+
.get((ty as usize).saturating_sub(1))
62+
.copied()
63+
.unwrap_or_default();
64+
let (flag, no_flag) = (flag | extra_flags.0, no_flag | extra_flags.1);
65+
3566
// if it doesn't contain any
3667
if unique_contents[primative as usize & 0xFF] & flag == 0
3768
|| unique_contents[primative as usize & 0xFF] & no_flag != 0
3869
{
3970
None
4071
} else {
4172
Some((
42-
PrimitiveType::try_from((primative >> 29) & 0x7)
43-
.expect("invalid primative type"),
73+
ty,
4474
((primative >> 8) & 0x1FFFFF) as usize,
4575
unique_contents[primative as usize & 0xFF],
4676
))
@@ -180,7 +210,7 @@ fn prop_to_mesh(
180210
let static_prop = props[index];
181211
let transform = Transform::from_translation(static_prop.origin.xzy())
182212
.with_rotation(Quat::from_euler(
183-
EulerRot::XYZEx,
213+
EulerRot::XYZ,
184214
static_prop.angles.x.to_radians(),
185215
static_prop.angles.y.to_radians(),
186216
static_prop.angles.z.to_radians(),
@@ -191,6 +221,8 @@ fn prop_to_mesh(
191221
if let Some(model_data) = model_data
192222
.get(static_prop.model_index as usize)
193223
.and_then(|o| o.as_ref())
224+
.cloned()
225+
// .or_else(|| Some(ico(Sphere::new(static_prop.scale * 3.), 3)))
194226
.filter(|_| static_prop.solid == 6)
195227
// figure what this actually is ^ rigth vphysics stuff I rember
196228
{
@@ -268,3 +300,32 @@ fn calculate_intersection_point(planes: [&Vec4; 3]) -> Option<DVec3> {
268300

269301
Some(DVec3::new(d.dot(u), m3.dot(v), -m2.dot(v)) / denom)
270302
}
303+
304+
// pub fn ico(sphere: Sphere, subdivisions: u32) -> (Vec<Vec3>, Vec<u32>) {
305+
// use hexasphere::shapes::IcoSphere;
306+
// let generated = IcoSphere::new(subdivisions as usize, |point| {
307+
// let inclination = ops::acos(point.y);
308+
// let azimuth = ops::atan2(point.z, point.x);
309+
310+
// let norm_inclination = inclination / PI;
311+
// let norm_azimuth = 0.5 - (azimuth / core::f32::consts::TAU);
312+
313+
// [norm_azimuth, norm_inclination]
314+
// });
315+
316+
// let raw_points = generated.raw_points();
317+
318+
// let points = raw_points
319+
// .iter()
320+
// .map(|&p| (p * sphere.radius).into())
321+
// .map(Vec3::from_array)
322+
// .collect::<Vec<Vec3>>();
323+
324+
// let mut indices = Vec::with_capacity(generated.indices_per_main_triangle() * 20);
325+
326+
// for i in 0..20 {
327+
// generated.get_indices(i, &mut indices);
328+
// }
329+
330+
// (points, indices)
331+
// }

bspeater/src/main.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use anyhow::Context;
55
use avian3d::prelude::*;
66
use bevy::{
77
asset::RenderAssetUsages,
8-
pbr::wireframe::WireframeConfig,
8+
pbr::wireframe::{WireframeConfig, WireframePlugin},
99
prelude::*,
1010
render::{
1111
RenderPlugin,
@@ -272,20 +272,23 @@ fn main() -> anyhow::Result<()> {
272272
println!("vertices {:#?}", vertices.len());
273273
println!("normals {:#?}", normals.len());
274274

275-
let meshes = geoset_loader::geoset_to_meshes(BSPData {
276-
vertices,
277-
tricoll_headers,
278-
tricoll_triangles,
279-
geo_sets,
280-
col_primatives,
281-
unique_contents,
282-
brushes,
283-
brush_side_plane_offsets,
284-
brush_planes,
285-
grid,
286-
props,
287-
model_data,
288-
});
275+
let meshes = geoset_loader::geoset_to_meshes(
276+
BSPData {
277+
vertices,
278+
tricoll_headers,
279+
tricoll_triangles,
280+
geo_sets,
281+
col_primatives,
282+
unique_contents,
283+
brushes,
284+
brush_side_plane_offsets,
285+
brush_planes,
286+
grid,
287+
props,
288+
model_data,
289+
},
290+
&map_name,
291+
);
289292
// let meshes = model_data
290293
// .iter()
291294
// .flatten()
@@ -336,8 +339,8 @@ fn main() -> anyhow::Result<()> {
336339
}),
337340
FlyCameraPlugin,
338341
PhysicsPlugins::default(),
339-
PhysicsDebugPlugin::default(),
340-
// WireframePlugin::default(),
342+
// PhysicsDebugPlugin::default(),
343+
WireframePlugin::default(),
341344
))
342345
.init_resource::<WireframeConfig>()
343346
.init_resource::<ChunkCells>()

bspeater/src/mdl_loader.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,23 @@ fn extract_mdl_physics(reader: &mut dyn SeekRead) -> anyhow::Result<(Vec<Vec3>,
103103

104104
let tri_offset = phy_header_offset + offset_of!(section, PhySection, tri);
105105
let indicies = Vec::from_iter(
106-
(0..(section.ledge.n_triangles as usize).min(phy.len()))
106+
(0..(section.ledge.n_triangles as usize))
107107
.map(|i| {
108108
tri_offset + size_of::<Compacttriangle>() * i
109109
..tri_offset + size_of::<Compacttriangle>() * (i + 1)
110110
})
111-
.filter_map(|range| {
112-
Some(
113-
*bytemuck::try_from_bytes::<Compacttriangle>(phy.get(range)?)
114-
.expect("out of range maybe for compact tri"),
111+
.map(|range| {
112+
*bytemuck::try_from_bytes::<Compacttriangle>(
113+
phy.get(range).expect("out of range maybe for compact tri"),
115114
)
115+
.expect("couldn't get tri")
116+
})
117+
.flat_map(|triangle| {
118+
[triangle.edge1(), triangle.edge2(), triangle.edge3()]
119+
.into_iter()
120+
.rev()
116121
})
117-
.flat_map(|triangle| [triangle.edge1(), triangle.edge2(), triangle.edge3()])
118122
.map(|edge| edge.start_point_index() as u32)
119-
.rev()
120123
.collect::<Vec<u32>>(),
121124
);
122125

@@ -125,19 +128,16 @@ fn extract_mdl_physics(reader: &mut dyn SeekRead) -> anyhow::Result<(Vec<Vec3>,
125128
+ section.ledge.c_point_offset as usize;
126129

127130
let vertices = Vec::from_iter(
128-
(0..indicies
129-
.iter()
130-
.copied()
131-
.max()
132-
.unwrap_or(0)
133-
.min(phy.len() as u32) as usize
134-
+ 1)
131+
(0..indicies.iter().copied().max().unwrap_or(0) as usize + 1)
135132
.map(|i| {
136133
phys_vertex_offset + size_of::<PhyVertex>() * i
137134
..phys_vertex_offset + size_of::<PhyVertex>() * (i + 1)
138135
})
139-
.filter_map(|range| {
140-
Some(*bytemuck::try_from_bytes::<PhyVertex>(phy.get(range)?).ok()?)
136+
.map(|range| {
137+
*bytemuck::try_from_bytes::<PhyVertex>(
138+
phy.get(range).expect("out of range maybe for phyvertex"),
139+
)
140+
.expect("couldn't get phy")
141141
}),
142142
)
143143
.iter()

0 commit comments

Comments
 (0)