pre-refactor

This commit is contained in:
Lillian Vixe 2024-04-28 14:04:24 -07:00
parent e2b9aa3313
commit 640987b9b8
5 changed files with 54 additions and 10 deletions

View file

@ -7,7 +7,7 @@ use crate::vvlib::oct_asset::{self, OctAssetMarker, OctTreeAsset};
mod editor_bevy_input_shim; mod editor_bevy_input_shim;
pub mod editor_ui; pub mod editor_ui;
mod orbit_camera; mod orbit_camera;
pub mod ui_extensions; pub mod string_tree;
pub fn setup(app: &mut App) -> &mut App { pub fn setup(app: &mut App) -> &mut App {
app.add_plugins(DefaultPlugins.set(WindowPlugin { app.add_plugins(DefaultPlugins.set(WindowPlugin {

View file

@ -37,7 +37,7 @@ use crate::{
use super::{ use super::{
editor_bevy_input_shim::setup_inputs, editor_bevy_input_shim::setup_inputs,
orbit_camera::orbit_camera::{pan_orbit_camera, spawn_camera}, orbit_camera::orbit_camera::{pan_orbit_camera, spawn_camera},
ui_extensions::{StringTree, StringTreeElement}, string_tree::{StringTree, StringTreeElement},
}; };
use std::fmt::Write; use std::fmt::Write;
@ -48,13 +48,26 @@ pub struct AssetEditData {
has_changed_since_last_save: bool, has_changed_since_last_save: bool,
} }
#[derive(Default, Resource)] #[derive(Resource)]
pub struct EditWindowUIState { pub struct EditWindowUIState {
brush_color: Hsva, brush_color: Hsva,
meshes: Vec<AssetEditData>, meshes: Vec<AssetEditData>,
structure: StringTree, structure: StringTree,
egui: EditWindowEguiState, egui: EditWindowEguiState,
popup: PopupWindowData, popup: PopupWindowData,
selected_structure_element: String,
}
impl Default for EditWindowUIState {
fn default() -> Self {
Self {
brush_color: Default::default(),
meshes: Default::default(),
structure: Default::default(),
egui: Default::default(),
popup: Default::default(),
selected_structure_element: "".into(),
}
}
} }
#[derive(Default)] #[derive(Default)]
pub enum PopupWindowData { pub enum PopupWindowData {
@ -489,7 +502,6 @@ pub fn edit_window_ui(
}); });
show_editable_stringtree(ui, &mut shared_ui_state); show_editable_stringtree(ui, &mut shared_ui_state);
if ui.button("Save Any Changes").clicked() { if ui.button("Save Any Changes").clicked() {
//save all files.
for each in &mut shared_ui_state.meshes { for each in &mut shared_ui_state.meshes {
if each.has_changed_since_last_save { if each.has_changed_since_last_save {
let handle = each.id.clone(); let handle = each.id.clone();
@ -573,15 +585,17 @@ pub fn show_popup(state: &mut EditWindowUIState, contexts: &mut EguiContexts) {
} }
pub fn show_editable_stringtree(ui: &mut egui::Ui, state: &mut EditWindowUIState) { pub fn show_editable_stringtree(ui: &mut egui::Ui, state: &mut EditWindowUIState) {
let mut string_selected = state.selected_structure_element.clone();
ui.collapsing("Model Structure", |ui| { ui.collapsing("Model Structure", |ui| {
ui.vertical(|ui| { ui.vertical(|ui| {
for each in &state.structure.root { for each in &state.structure.root {
match each { match each {
super::ui_extensions::StringTreeElement::None => {} super::string_tree::StringTreeElement::None => {}
super::ui_extensions::StringTreeElement::Element(name, children) => { super::string_tree::StringTreeElement::Element(name, children) => {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.label(">".to_owned()); ui.label(">".to_owned());
ui.label(name.clone()); //ui.label(name.clone());
ui.radio_value(&mut string_selected, name.clone(), name.clone());
let but = egui::Button::new("..."); let but = egui::Button::new("...");
if ui.add_enabled(true, but).clicked() { if ui.add_enabled(true, but).clicked() {
@ -599,19 +613,21 @@ pub fn show_editable_stringtree(ui: &mut egui::Ui, state: &mut EditWindowUIState
} }
}); });
for each in children.as_ref() { for each in children.as_ref() {
show_child(ui, each, 1, &mut state.popup); show_child(ui, each, 1, &mut state.popup, &mut string_selected);
} }
} }
} }
} }
}); });
}); });
state.selected_structure_element = string_selected;
} }
pub fn show_child( pub fn show_child(
ui: &mut egui::Ui, ui: &mut egui::Ui,
subject: &StringTreeElement, subject: &StringTreeElement,
depth: usize, depth: usize,
state: &mut PopupWindowData, state: &mut PopupWindowData,
selection: &mut String,
) { ) {
match subject { match subject {
StringTreeElement::None => {} StringTreeElement::None => {}
@ -627,7 +643,8 @@ pub fn show_child(
prec = prec + ">"; prec = prec + ">";
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.label(prec); ui.label(prec);
ui.label(name.clone()); //ui.label(name.clone());
ui.radio_value(selection, name.clone(), name.clone());
if ui.button("...").clicked() { if ui.button("...").clicked() {
let mut should_close = false; let mut should_close = false;
if let PopupWindowData::StructureElement(val) = state { if let PopupWindowData::StructureElement(val) = state {
@ -643,7 +660,7 @@ pub fn show_child(
} }
}); });
for each in children.as_ref() { for each in children.as_ref() {
show_child(ui, each, depth + 1, state); show_child(ui, each, depth + 1, state, selection);
} }
} }
} }

View file

@ -341,6 +341,7 @@ impl StringTree {
return list; return list;
} }
} }
#[test] #[test]
pub fn test_string_tree() { pub fn test_string_tree() {
let parent = &String::from("parent1"); let parent = &String::from("parent1");

View file

@ -6,6 +6,7 @@ pub mod intersections;
pub mod obb; pub mod obb;
pub mod oct_asset; pub mod oct_asset;
pub mod octtree; pub mod octtree;
pub mod structure_asset;
pub const RANDOM_SPACE: f32 = 5.; // size of the random possibility space. pub const RANDOM_SPACE: f32 = 5.; // size of the random possibility space.
pub const INTERVAL: f32 = 0.3; // how often to add ^ that many and remove ^ that many random locations pub const INTERVAL: f32 = 0.3; // how often to add ^ that many and remove ^ that many random locations

View file

@ -0,0 +1,25 @@
use bevy::{
math::{Quat, Vec3},
transform::components::Transform,
};
pub struct StructureElement {
euler: Vec3,
translation: Vec3,
scale: Vec3,
}
pub enum StructureOptions {
None,
}
impl StructureElement {
pub fn into_transform(&self) -> Transform {
Transform::from_rotation(
Quat::from_rotation_x(self.euler.x)
+ Quat::from_rotation_y(self.euler.y)
+ Quat::from_rotation_z(self.euler.z),
) * Transform::from_scale(self.scale)
* Transform::from_translation(self.translation)
}
}
pub struct StructureAsset {}