quick and messy voxel palettes in editor

This commit is contained in:
Lillian Vixe 2024-04-19 04:58:02 -07:00
parent f764cd14c3
commit c15da5e333
2 changed files with 60 additions and 10 deletions

View file

@ -1,9 +1,16 @@
version 1
0 0 0|1 0 0
0 0 1|1 0 0.77999973
0 0 2|0.0800004 0 1
0 0 3|0 0.7600002 1
0 0 4|0 1 0.3399999
0 0 5|0.5 1 0
0 0 6|1 0.8399999 0
0 0 7|1 0.4200003 0
0 2 -1|1 0.6600001 0
0 3 -1|1 0.6600001 0
0 -1 0|1 0.6600001 0
0 0 0|1 0.6600001 0
0 1 0|1 0.6600001 0
0 -1 5|1 0.6600001 0
0 -1 6|1 0.6600001 0
0 0 4|1 0.6600001 0
0 1 4|1 0.6600001 0
0 0 7|1 0.6600001 0
0 1 7|1 0.6600001 0
0 2 1|1 0.6600001 0
0 3 1|1 0.6600001 0
0 2 5|1 0.6600001 0
0 2 6|1 0.6600001 0

View file

@ -287,8 +287,8 @@ pub fn edit_window_ui(
shared_ui_state.window = pos;
}
}
response.show(contexts.ctx_mut(), |ui| {
//ui.ctx().set_pixels_per_point(0.1);
let mut label = String::from("Pre-Alpha");
use std::fmt::Write;
writeln!(label, " Controls:").ok();
@ -301,6 +301,48 @@ pub fn edit_window_ui(
color_picker::Alpha::Opaque,
);
ui.label(label);
let mut color_to_set: Option<Color> = None;
for each in &shared_ui_state.meshes {
ui.horizontal_wrapped(|ui| {
//color palette clickables.
let handle = each.id.clone();
let asset = oct_assets.get(handle);
if asset.is_some() {
let list = asset.unwrap().model.collect_voxels();
let mut count: Vec<(Color, usize)> = Vec::new();
fn eq(c1: &Color, c2: &mut Color) -> bool {
c1.r() == c2.r() && c1.g() == c2.g() && c1.b() == c2.b()
}
for (_, _, color) in &list {
let mut is_committed = false;
for (each_col, each_count) in &mut count {
if eq(color, each_col) {
*each_count += 1;
is_committed = true;
break;
}
}
if !is_committed {
count.push((color.clone(), 1));
}
}
count.sort_by(|a, b| b.1.cmp(&a.1));
if !count.is_empty() {
ui.label(each.path.clone());
for (color, count) in count {
let button =
egui::Button::new(count.to_string()).fill(egui_color_from(color));
if ui.add(button).clicked() {
color_to_set = Some(color);
}
}
}
}
});
}
if let Some(color) = color_to_set {
shared_ui_state.brush_color = egui_color_from(color);
}
if ui.button("Add Origin Voxel").clicked() {
//
for pair in &mut pairs.handles {
@ -315,7 +357,7 @@ pub fn edit_window_ui(
}
if ui.button("Save Any Changes").clicked() {
//save all files.
for each in &shared_ui_state.meshes {
for each in &mut shared_ui_state.meshes {
if each.has_changed_since_last_save {
let handle = each.id.clone();
let path = each.path.clone() + ".vvg";
@ -327,6 +369,7 @@ pub fn edit_window_ui(
asset.unwrap(),
);
if result {
each.has_changed_since_last_save = false;
println!("{} saved to disk.", &path);
}
}