Compare commits

...

2 Commits

Author SHA1 Message Date
Milk.H ecdcf00b0f
i learned my lesson, i will be less lazy from now on 2023-03-23 12:37:29 +01:00
Milk.H e5101f6c7d
Working on letting debug interact with scene while being a seperate
module
currently buggy and for some reason debug only returns model
2023-03-23 12:17:21 +01:00
3 changed files with 124 additions and 36 deletions

View File

@ -6,21 +6,34 @@ use sdl2::event::Event;
const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/models/TestCarModel/CarW1.obj",
"resources/models/TestCarModel/CarW0.obj"];
mod info;
pub enum dEvent
{
loadModel(i32),
setTest(f32, i32),
exit,
}
pub enum Callback
{
ModelInfo(info::ModelI),
TestWind(info::testI),
}
#[derive(Clone)]
pub enum OpenWindows {
ModelInfo,
TestWind,
}
pub struct Debug {
imgui: imgui::Context,
renderer: AutoRenderer,
platform: SdlPlatform,
selectedModel: i32
pub windows: Vec<OpenWindows>,
}
@ -44,7 +57,7 @@ impl Debug {
imgui,
renderer,
platform,
selectedModel: 0,
windows: vec![OpenWindows::TestWind, OpenWindows::ModelInfo],
}
}
@ -52,42 +65,30 @@ impl Debug {
{
self.platform.handle_event(&mut self.imgui, event);
}
pub fn windows(self) -> Vec<OpenWindows>
{
let ret = self.windows.clone();
ret
}
pub fn drawImgui(&mut self, events_loop: &sdl2::EventPump, window: &sdl2::video::Window,
tempData: &mut crate::scene::tempData, Car: &crate::model::Model) -> Vec<dEvent>
callback: Vec<Callback>) -> Vec<dEvent>
{
self.platform.prepare_frame(&mut self.imgui, &window, &events_loop );
let ui = self.imgui.new_frame();
let mut ret = Vec::<dEvent>::new();
let mut ret = Vec::new();
for call in callback
{
match call {
Callback::ModelInfo(a) =>
{
Debug::displayModel(ui, &a)
},
Callback::TestWind(mut a) =>
ret = Debug::displayTest(ui, &mut a),
}
}
ui.window("POLY I WILL FUCKING")
.size([500.0, 100.0], imgui::Condition::FirstUseEver)
.build(|| {
ui.text("you serve no purpose in life");
ui.text("Your Purpose in life is to suck my dick");
ui.slider("The Spin Speed", 0.1, 10.0, &mut tempData.spinSpeed);
if ui
.button("Quit") {
ret.push(dEvent::exit);
}
if ui.list_box("Select Model to Load", &mut self.selectedModel, &MODELS, 5) {
ret.push(dEvent::loadModel(self.selectedModel));
}
});
ui.window("Stats")
.size([300.0,500.0], imgui::Condition::Always)
.build(|| {
ui.text("Model Information");
ui.separator();
ui.text(format!("count meshes: {}", Car.meshes.len()));
for i in 0..Car.meshes.len()
{
ui.text(format!("Mesh Number: {}",i ));
ui.text(format!("count vertices: {}", Car.meshes[i].vertices.len()));
ui.separator();
}
});
let draw_data = self.imgui.render();
@ -97,4 +98,65 @@ impl Debug {
ret
}
fn displayTest(ui: &mut imgui::Ui, testI: &mut info::testI) -> Vec<dEvent>
{
let mut ret = Vec::new();
ui.window("POLY I WILL FUCKING")
.size([500.0, 100.0], imgui::Condition::FirstUseEver)
.build(|| {
ui.text("you serve no purpose in life");
ui.text("Your Purpose in life is to suck my dick");
ui.slider("The Spin Speed", 0.1, 10.0, &mut testI.spinSpeed);
if ui
.button("Quit") {
ret.push(dEvent::exit);
}
if ui.list_box("Select Model to Load", &mut testI.selectedModel, &MODELS, 5) {
ret.push(dEvent::loadModel(testI.selectedModel));
}
});
ret
}
fn displayModel(ui: &mut imgui::Ui ,model: &info::ModelI)
{
ui.window("Stats")
.size([300.0, 500.0], imgui::Condition::Always)
.build(|| {
ui.text("Model Information");
ui.text(format!("count meshes: {}", model.meshesCount));
ui.separator();
for i in 0..model.meshesCount
{
ui.text(format!("Mesh Number {}", i));
ui.text(format!("count Vertices: {}", model.vertCount[i]));
ui.separator();
}
});
}
}
use crate::model;
pub fn ModelInfo(model: &model::Model) -> Callback
{
let mut vertCount = Vec::new();
let meshesCount = model.meshes.len();
for i in 0..model.meshes.len() {
vertCount.push(model.meshes[i].vertices.len());
}
Callback::ModelInfo(info::ModelI {
meshesCount,
vertCount
})
}
pub fn TestWind(spinSpeed: f32, selectedModel: i32) -> Callback
{
Callback::TestWind(info::testI {
spinSpeed,
selectedModel,
})
}

12
src/debug/info.rs Normal file
View File

@ -0,0 +1,12 @@
pub struct ModelI
{
pub meshesCount: usize,
pub vertCount: Vec<usize>
}
pub struct testI
{
pub spinSpeed: f32,
pub selectedModel: i32,
}

View File

@ -8,7 +8,7 @@ use glow::*;
use imgui_glow_renderer::AutoRenderer;
use imgui_sdl2_support::SdlPlatform;
use crate::debug;
use cgmath::{Matrix4, vec3, Point3, Deg, perspective};
use cgmath::prelude::*;
@ -31,6 +31,7 @@ pub struct tempData {
pub deltaTime: f32,
pub lastFrame: f32,
DebugMode: bool,
selectedModel: i32
}
use crate::debug::Debug;
@ -73,7 +74,8 @@ impl Scene{
currentFrame: 0.0,
deltaTime: 0.0,
lastFrame: 0.0,
DebugMode: false,
DebugMode: true,
selectedModel: 0,
};
@ -116,7 +118,19 @@ impl Scene{
self.Car.Draw(&self.shaders[0]);
if self.tempData.DebugMode{
for command in self.debug.drawImgui(&events_loop, &window, &mut self.tempData, &self.Car)
let mut Callbacks = Vec::new();
let windows = self.debug.windows.clone();
for window in windows
{
match window {
debug::OpenWindows::ModelInfo => Callbacks.push(debug::ModelInfo(&self.Car)),
debug::OpenWindows::TestWind => Callbacks.push(debug::TestWind(self.tempData.spinSpeed, self.tempData.selectedModel)),
}
}
for command in self.debug.drawImgui(&events_loop, &window, Callbacks)
{
use crate::debug::dEvent;
match command