This commit is contained in:
Robin Appelman 2023-06-08 19:55:19 +02:00
commit 809c68d94a
9 changed files with 198 additions and 66 deletions

View file

@ -41,7 +41,7 @@ fn model_to_mesh(model: Handle<vbsp::data::Model>) -> CpuMesh {
.map(Either::Left)
.unwrap_or_else(|| Either::Right(face.triangulate().flatten()))
})
.map(|c| map_coords(c).into())
.map(map_coords)
.collect();
let mut mesh = CpuMesh {
@ -61,7 +61,7 @@ fn load_props<'a, I: Iterator<Item = Handle<'a, StaticPropLump>>>(
merge_models(props.map(|prop| {
let model = load_prop(loader, prop.model())?;
let transform =
Mat4::from_translation(map_coords(prop.origin).into()) * Mat4::from(prop.rotation());
Mat4::from_translation(map_coords(prop.origin)) * Mat4::from(prop.rotation());
Ok(ModelData { model, transform })
}))
}

View file

@ -115,15 +115,12 @@ impl Control for DebugToggle {
_accumulated_time: f64,
) -> bool {
for event in events.iter_mut() {
match event {
Event::Text(text) => {
if text == "`" {
self.enabled = !self.enabled;
return true;
}
if let Event::Text(text) = event {
if text == "`" {
self.enabled = !self.enabled;
return true;
}
_ => {}
};
}
}
false
@ -161,19 +158,16 @@ impl Control for DemoCamera {
) -> bool {
let mut change = false;
for event in events.iter_mut() {
match event {
Event::Text(text) => {
if text == "p" {
change = true;
self.playing = !self.playing;
if self.playing {
self.playback_start_time = accumulated_time;
} else {
self.start_tick = self.demo_tick(accumulated_time);
}
if let Event::Text(text) = event {
if text == "p" {
change = true;
self.playing = !self.playing;
if self.playing {
self.playback_start_time = accumulated_time;
} else {
self.start_tick = self.demo_tick(accumulated_time);
}
}
_ => {}
};
}

View file

@ -112,34 +112,36 @@ impl<C: Control> Renderer<C> {
.map(|gm| &gm.geometry);
match self.gui.debug_type {
DebugType::NORMAL => target.render_with_material(
DebugType::Normal => target.render_with_material(
&NormalMaterial::default(),
&self.camera,
geometries,
lights,
),
DebugType::DEPTH => {
let mut depth_material = DepthMaterial::default();
depth_material.max_distance = Some(self.gui.depth_max);
DebugType::Depth => {
let depth_material = DepthMaterial {
max_distance: Some(self.gui.depth_max),
..DepthMaterial::default()
};
target.render_with_material(&depth_material, &self.camera, geometries, lights)
}
DebugType::ORM => target.render_with_material(
DebugType::Orm => target.render_with_material(
&ORMMaterial::default(),
&self.camera,
geometries,
lights,
),
DebugType::POSITION => {
DebugType::Position => {
let position_material = PositionMaterial::default();
target.render_with_material(&position_material, &self.camera, geometries, lights)
}
DebugType::COLOR => target.render_with_material(
DebugType::Color => target.render_with_material(
&ColorMaterial::default(),
&self.camera,
geometries,
lights,
),
DebugType::NONE => target.render(
DebugType::None => target.render(
&self.camera,
self.models.iter().flat_map(|model| model.iter()),
lights,

View file

@ -5,12 +5,12 @@ use three_d::{Camera, Context, FrameInput, GUI};
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[allow(missing_docs)]
pub enum DebugType {
POSITION,
NORMAL,
COLOR,
DEPTH,
ORM,
NONE,
Position,
Normal,
Color,
Depth,
Orm,
None,
}
pub struct DebugUI {
@ -32,7 +32,7 @@ impl DebugUI {
ambient_intensity: 0.2,
depth_max: 30.0,
fov: 60.0,
debug_type: DebugType::NORMAL,
debug_type: DebugType::Normal,
}
}
@ -65,12 +65,12 @@ impl DebugUI {
ui.checkbox(&mut self.shadows_enabled, "Shadows");
ui.label("Debug options");
ui.radio_value(&mut self.debug_type, DebugType::NONE, "None");
ui.radio_value(&mut self.debug_type, DebugType::POSITION, "Position");
ui.radio_value(&mut self.debug_type, DebugType::NORMAL, "Normal");
ui.radio_value(&mut self.debug_type, DebugType::COLOR, "Color");
ui.radio_value(&mut self.debug_type, DebugType::DEPTH, "Depth");
ui.radio_value(&mut self.debug_type, DebugType::ORM, "ORM");
ui.radio_value(&mut self.debug_type, DebugType::None, "None");
ui.radio_value(&mut self.debug_type, DebugType::Position, "Position");
ui.radio_value(&mut self.debug_type, DebugType::Normal, "Normal");
ui.radio_value(&mut self.debug_type, DebugType::Color, "Color");
ui.radio_value(&mut self.debug_type, DebugType::Depth, "Depth");
ui.radio_value(&mut self.debug_type, DebugType::Orm, "ORM");
ui.label("View options");
ui.add(Slider::new(&mut self.depth_max, 1.0..=30.0).text("Depth max"));
@ -90,7 +90,7 @@ impl DebugUI {
(change, panel_width)
}
pub fn render(&mut self) -> () {
pub fn render(&mut self) {
self.ui.render()
}
}